Skip to content

Commit c1b8a79

Browse files
rugeGerritsenadamkondraciuk
authored andcommitted
[nrf fromlist] soc: nordic: nrf54h: s2ram: Use ARM SCB save/restore funcs
This reduced the amount of duplicate code and unifies the code with other platforms. With this change fewer registers are stored and restored. See also comment in scb.h for scb_context stating that only essential registers are stored and restored. No longer stored: - ICSR - SCR - CFSR - HFSR - DFSR - MMFAR - BFAR - AFSR No longer used: - SHPR[3..12]. This backup register was declared in the wrong way. In core_cm33.h and core_cm4.h this is declared as an array of 12 uint8_t's. That is 3 uint32_t's. Orignal SCB retention was added in 2055f7d. Upstream PR #: 97073 Signed-off-by: Rubin Gerritsen <[email protected]>
1 parent 12463ab commit c1b8a79

File tree

1 file changed

+4
-58
lines changed

1 file changed

+4
-58
lines changed

soc/nordic/nrf54h/pm_s2ram.c

Lines changed: 4 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
#include <zephyr/arch/cpu.h>
77
#include <zephyr/arch/arm/mpu/arm_mpu.h>
8+
#include <zephyr/arch/arm/cortex_m/scb.h>
89
#include <zephyr/arch/common/pm_s2ram.h>
910
#include <zephyr/linker/sections.h>
1011
#include <zephyr/sys/util.h>
@@ -17,8 +18,6 @@
1718
#define NVIC_MEMBER_SIZE(member) ARRAY_SIZE(((NVIC_Type *)0)->member)
1819

1920
/* Coprocessor Power Control Register Definitions */
20-
#define SCnSCB_CPPWR_SU11_Pos 22U /*!< CPPWR: SU11 Position */
21-
#define SCnSCB_CPPWR_SU11_Msk (1UL << SCnSCB_CPPWR_SU11_Pos) /*!< CPPWR: SU11 Mask */
2221

2322
#define SCnSCB_CPPWR_SU10_Pos 20U /*!< CPPWR: SU10 Position */
2423
#define SCnSCB_CPPWR_SU10_Msk (1UL << SCnSCB_CPPWR_SU10_Pos) /*!< CPPWR: SU10 Mask */
@@ -30,23 +29,6 @@ typedef struct {
3029
uint8_t IPR[NVIC_MEMBER_SIZE(IPR)];
3130
} _nvic_context_t;
3231

33-
typedef struct {
34-
uint32_t ICSR;
35-
uint32_t VTOR;
36-
uint32_t AIRCR;
37-
uint32_t SCR;
38-
uint32_t CCR;
39-
uint32_t SHPR[12U];
40-
uint32_t SHCSR;
41-
uint32_t CFSR;
42-
uint32_t HFSR;
43-
uint32_t DFSR;
44-
uint32_t MMFAR;
45-
uint32_t BFAR;
46-
uint32_t AFSR;
47-
uint32_t CPACR;
48-
} _scb_context_t;
49-
5032
#if defined(CONFIG_FPU) && !defined(CONFIG_FPU_SHARING)
5133
typedef struct {
5234
uint32_t FPCCR;
@@ -61,7 +43,7 @@ struct backup {
6143
#if defined(CONFIG_ARM_MPU)
6244
struct z_mpu_context_retained mpu_context;
6345
#endif
64-
_scb_context_t scb_context;
46+
struct scb_context scb_context;
6547
#if defined(CONFIG_FPU) && !defined(CONFIG_FPU_SHARING)
6648
_fpu_context_t fpu_context;
6749
#endif
@@ -83,42 +65,6 @@ static void nvic_restore(_nvic_context_t *backup)
8365
memcpy((uint32_t *)NVIC->IPR, backup->IPR, sizeof(NVIC->IPR));
8466
}
8567

86-
static void scb_save(_scb_context_t *backup)
87-
{
88-
backup->ICSR = SCB->ICSR;
89-
backup->VTOR = SCB->VTOR;
90-
backup->AIRCR = SCB->AIRCR;
91-
backup->SCR = SCB->SCR;
92-
backup->CCR = SCB->CCR;
93-
memcpy(backup->SHPR, (uint32_t *)SCB->SHPR, sizeof(SCB->SHPR));
94-
backup->SHCSR = SCB->SHCSR;
95-
backup->CFSR = SCB->CFSR;
96-
backup->HFSR = SCB->HFSR;
97-
backup->DFSR = SCB->DFSR;
98-
backup->MMFAR = SCB->MMFAR;
99-
backup->BFAR = SCB->BFAR;
100-
backup->AFSR = SCB->AFSR;
101-
backup->CPACR = SCB->CPACR;
102-
}
103-
104-
static void scb_restore(_scb_context_t *backup)
105-
{
106-
SCB->ICSR = backup->ICSR;
107-
SCB->VTOR = backup->VTOR;
108-
SCB->AIRCR = backup->AIRCR;
109-
SCB->SCR = backup->SCR;
110-
SCB->CCR = backup->CCR;
111-
memcpy((uint32_t *)SCB->SHPR, backup->SHPR, sizeof(SCB->SHPR));
112-
SCB->SHCSR = backup->SHCSR;
113-
SCB->CFSR = backup->CFSR;
114-
SCB->HFSR = backup->HFSR;
115-
SCB->DFSR = backup->DFSR;
116-
SCB->MMFAR = backup->MMFAR;
117-
SCB->BFAR = backup->BFAR;
118-
SCB->AFSR = backup->AFSR;
119-
SCB->CPACR = backup->CPACR;
120-
}
121-
12268
#if defined(CONFIG_FPU)
12369
static void fpu_power_down(void)
12470
{
@@ -175,7 +121,7 @@ int soc_s2ram_suspend(pm_s2ram_system_off_fn_t system_off)
175121
int ret;
176122

177123
SET_MCUBOOT_RESUME_MAGIC();
178-
scb_save(&backup_data.scb_context);
124+
z_arm_save_scb_context(&backup_data.scb_context);
179125
#if defined(CONFIG_FPU)
180126
#if !defined(CONFIG_FPU_SHARING)
181127
fpu_save(&backup_data.fpu_context);
@@ -204,7 +150,7 @@ int soc_s2ram_suspend(pm_s2ram_system_off_fn_t system_off)
204150
z_arm_restore_mpu_context(&backup_data.mpu_context);
205151
#endif
206152
nvic_restore(&backup_data.nvic_context);
207-
scb_restore(&backup_data.scb_context);
153+
z_arm_restore_scb_context(&backup_data.scb_context);
208154

209155
return ret;
210156
}

0 commit comments

Comments
 (0)