Skip to content

Commit 4ceb55a

Browse files
rugeGerritsenadamkondraciuk
authored andcommitted
[nrf fromlist] soc: nordic: nrf54h: s2ram: Use ARM FPU save/restore funcs
This reduced the amount of duplicate code and unifies the code with other platforms. With this change the caller and callee status registers are stored separately. Also, a different set of status registers are stored: - FPSCR instead of FPDSCR. FPDSCR contains the default values to be assigned to FPSCR when a new floating-point context is created. It therefore seems more correct to store the FPSCR. - FPCCR and FPCAR are no longer stored. FPU retention was originally added in: 8a5365c. Upstream PR #: 97073 Signed-off-by: Rubin Gerritsen <[email protected]>
1 parent ee1acf1 commit 4ceb55a

File tree

1 file changed

+4
-32
lines changed

1 file changed

+4
-32
lines changed

soc/nordic/nrf54h/pm_s2ram.c

Lines changed: 4 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include <zephyr/arch/cpu.h>
77
#include <zephyr/arch/arm/mpu/arm_mpu.h>
88
#include <zephyr/arch/arm/cortex_m/scb.h>
9+
#include <zephyr/arch/arm/cortex_m/fpu.h>
910
#include <zephyr/arch/common/pm_s2ram.h>
1011
#include <zephyr/linker/sections.h>
1112
#include <zephyr/sys/util.h>
@@ -31,23 +32,14 @@ typedef struct {
3132
uint8_t IPR[NVIC_MEMBER_SIZE(IPR)];
3233
} _nvic_context_t;
3334

34-
#if defined(CONFIG_FPU) && !defined(CONFIG_FPU_SHARING)
35-
typedef struct {
36-
uint32_t FPCCR;
37-
uint32_t FPCAR;
38-
uint32_t FPDSCR;
39-
uint32_t S[32];
40-
} _fpu_context_t;
41-
#endif
42-
4335
struct backup {
4436
_nvic_context_t nvic_context;
4537
#if defined(CONFIG_ARM_MPU)
4638
struct z_mpu_context_retained mpu_context;
4739
#endif
4840
struct scb_context scb_context;
4941
#if defined(CONFIG_FPU) && !defined(CONFIG_FPU_SHARING)
50-
_fpu_context_t fpu_context;
42+
struct fpu_ctx_full fpu_context;
5143
#endif
5244
};
5345

@@ -83,26 +75,6 @@ static void fpu_power_up(void)
8375
__DSB();
8476
__ISB();
8577
}
86-
87-
#if !defined(CONFIG_FPU_SHARING)
88-
static void fpu_save(_fpu_context_t *backup)
89-
{
90-
backup->FPCCR = FPU->FPCCR;
91-
backup->FPCAR = FPU->FPCAR;
92-
backup->FPDSCR = FPU->FPDSCR;
93-
94-
__asm__ volatile("vstmia %0, {s0-s31}\n" : : "r"(backup->S) : "memory");
95-
}
96-
97-
static void fpu_restore(_fpu_context_t *backup)
98-
{
99-
FPU->FPCCR = backup->FPCCR;
100-
FPU->FPCAR = backup->FPCAR;
101-
FPU->FPDSCR = backup->FPDSCR;
102-
103-
__asm__ volatile("vldmia %0, {s0-s31}\n" : : "r"(backup->S) : "memory");
104-
}
105-
#endif /* !defined(CONFIG_FPU_SHARING) */
10678
#endif /* defined(CONFIG_FPU) */
10779

10880
#if DT_NODE_EXISTS(DT_NODELABEL(mcuboot_s2ram)) &&\
@@ -126,7 +98,7 @@ int soc_s2ram_suspend(pm_s2ram_system_off_fn_t system_off)
12698
z_arm_save_scb_context(&backup_data.scb_context);
12799
#if defined(CONFIG_FPU)
128100
#if !defined(CONFIG_FPU_SHARING)
129-
fpu_save(&backup_data.fpu_context);
101+
z_arm_save_fp_context(&backup_data.fpu_context);
130102
#endif
131103
fpu_power_down();
132104
#endif
@@ -141,7 +113,7 @@ int soc_s2ram_suspend(pm_s2ram_system_off_fn_t system_off)
141113
fpu_power_up();
142114
#if !defined(CONFIG_FPU_SHARING)
143115
/* Also the FPU content might be lost. */
144-
fpu_restore(&backup_data.fpu_context);
116+
z_arm_restore_fp_context(&backup_data.fpu_context);
145117
#endif
146118
#endif
147119
if (ret < 0) {

0 commit comments

Comments
 (0)