Skip to content

Commit a1ea5dd

Browse files
committed
Introduced an API to support scenarios where FPU sharing across threads
is required. This API is a replacement of the original API whose purpose has been changed (see below). This API also allows applications to disable FP sharing mode and use unshared FP registers, assuming that FP instructions are only issued within a single, designated thread. Currently, there is no known usage of this API, as the FPU context is automatically preserved across threads by hardware on Cortex-M (via the FPCCR.ASPEN register field). The original API has been modified to always perform FPU context save/restore, as its name implies. Conditional compilation on CONFIG_FPU is necessary to avoid build errors when the FPU is not enabled in the configuration. The primary use case is preserving FPU context during suspend-to-RAM transitions. TFM code was updated to retain its original behavior. However, it is unclear whether FPU context save/restore should happen unconditionally, regardless of CONFIG_PM_SHARING. Signed-off-by: Michele Sardo <msmttchr@gmail.com>
1 parent 4a47084 commit a1ea5dd

File tree

3 files changed

+20
-4
lines changed
  • arch/arm/core/cortex_m
  • include/zephyr/arch/arm/cortex_m
  • modules/trusted-firmware-m/interface

3 files changed

+20
-4
lines changed

arch/arm/core/cortex_m/fpu.c

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
void z_arm_save_fp_context(struct fpu_ctx_full *buffer)
1818
{
19-
#if defined(CONFIG_FPU_SHARING)
19+
#if defined(CONFIG_FPU)
2020
__ASSERT_NO_MSG(buffer != NULL);
2121

2222
uint32_t CONTROL = __get_CONTROL();
@@ -44,7 +44,7 @@ void z_arm_save_fp_context(struct fpu_ctx_full *buffer)
4444

4545
void z_arm_restore_fp_context(const struct fpu_ctx_full *buffer)
4646
{
47-
#if defined(CONFIG_FPU_SHARING)
47+
#if defined(CONFIG_FPU)
4848
if (buffer->ctx_saved) {
4949
/* Set FPCA first so it is set even if an interrupt happens
5050
* during restoration.
@@ -61,3 +61,17 @@ void z_arm_restore_fp_context(const struct fpu_ctx_full *buffer)
6161
}
6262
#endif
6363
}
64+
65+
void z_arm_save_shared_fp_context(struct fpu_ctx_full *buffer)
66+
{
67+
#if defined(CONFIG_FPU_SHARING)
68+
z_arm_save_fp_context(buffer);
69+
#endif
70+
}
71+
72+
void z_arm_restore_shared_fp_context(struct fpu_ctx_full *buffer)
73+
{
74+
#if defined(CONFIG_FPU_SHARING)
75+
z_arm_restore_fp_context(buffer);
76+
#endif
77+
}

include/zephyr/arch/arm/cortex_m/fpu.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,7 @@ struct fpu_ctx_full {
1919

2020
void z_arm_save_fp_context(struct fpu_ctx_full *buffer);
2121
void z_arm_restore_fp_context(const struct fpu_ctx_full *buffer);
22+
void z_arm_save_shared_fp_context(struct fpu_ctx_full *buffer)
23+
void z_arm_restore_shared_fp_context(const struct fpu_ctx_full *buffer);
2224

2325
#endif /* ZEPHYR_INCLUDE_ARCH_ARM_CORTEX_M_FPU_H_ */

modules/trusted-firmware-m/interface/interface.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,11 @@ int32_t tfm_ns_interface_dispatch(veneer_fn fn,
5555

5656
struct fpu_ctx_full context_buffer;
5757

58-
z_arm_save_fp_context(&context_buffer);
58+
z_arm_save_shared_fp_context(&context_buffer);
5959

6060
result = fn(arg0, arg1, arg2, arg3);
6161

62-
z_arm_restore_fp_context(&context_buffer);
62+
z_arm_restore_shared_fp_context(&context_buffer);
6363

6464
if (!isr_mode) {
6565
#if !defined(CONFIG_ARM_NONSECURE_PREEMPTIBLE_SECURE_CALLS)

0 commit comments

Comments
 (0)