From 4a47084554d16883e1c0094ef06d2ca150400c89 Mon Sep 17 00:00:00 2001 From: Michele Sardo Date: Sat, 12 Jul 2025 19:27:17 +0200 Subject: [PATCH 1/2] Added missing #includes for used types Signed-off-by: Michele Sardo --- include/zephyr/arch/arm/cortex_m/fpu.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/include/zephyr/arch/arm/cortex_m/fpu.h b/include/zephyr/arch/arm/cortex_m/fpu.h index cf01fddf4f93..225a4005bb15 100644 --- a/include/zephyr/arch/arm/cortex_m/fpu.h +++ b/include/zephyr/arch/arm/cortex_m/fpu.h @@ -7,6 +7,9 @@ #ifndef ZEPHYR_INCLUDE_ARCH_ARM_CORTEX_M_FPU_H_ #define ZEPHYR_INCLUDE_ARCH_ARM_CORTEX_M_FPU_H_ +#include +#include + struct fpu_ctx_full { uint32_t caller_saved[16]; uint32_t callee_saved[16]; From a1ea5ddc2b07109fca90c6deed423cd07bc6c474 Mon Sep 17 00:00:00 2001 From: Michele Sardo Date: Sat, 12 Jul 2025 19:54:49 +0200 Subject: [PATCH 2/2] 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 --- arch/arm/core/cortex_m/fpu.c | 18 ++++++++++++++++-- include/zephyr/arch/arm/cortex_m/fpu.h | 2 ++ .../trusted-firmware-m/interface/interface.c | 4 ++-- 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/arch/arm/core/cortex_m/fpu.c b/arch/arm/core/cortex_m/fpu.c index b937d725c283..2b11487e448b 100644 --- a/arch/arm/core/cortex_m/fpu.c +++ b/arch/arm/core/cortex_m/fpu.c @@ -16,7 +16,7 @@ void z_arm_save_fp_context(struct fpu_ctx_full *buffer) { -#if defined(CONFIG_FPU_SHARING) +#if defined(CONFIG_FPU) __ASSERT_NO_MSG(buffer != NULL); uint32_t CONTROL = __get_CONTROL(); @@ -44,7 +44,7 @@ void z_arm_save_fp_context(struct fpu_ctx_full *buffer) void z_arm_restore_fp_context(const struct fpu_ctx_full *buffer) { -#if defined(CONFIG_FPU_SHARING) +#if defined(CONFIG_FPU) if (buffer->ctx_saved) { /* Set FPCA first so it is set even if an interrupt happens * during restoration. @@ -61,3 +61,17 @@ void z_arm_restore_fp_context(const struct fpu_ctx_full *buffer) } #endif } + +void z_arm_save_shared_fp_context(struct fpu_ctx_full *buffer) +{ +#if defined(CONFIG_FPU_SHARING) + z_arm_save_fp_context(buffer); +#endif +} + +void z_arm_restore_shared_fp_context(struct fpu_ctx_full *buffer) +{ +#if defined(CONFIG_FPU_SHARING) + z_arm_restore_fp_context(buffer); +#endif +} diff --git a/include/zephyr/arch/arm/cortex_m/fpu.h b/include/zephyr/arch/arm/cortex_m/fpu.h index 225a4005bb15..e5b9ade31ed6 100644 --- a/include/zephyr/arch/arm/cortex_m/fpu.h +++ b/include/zephyr/arch/arm/cortex_m/fpu.h @@ -19,5 +19,7 @@ struct fpu_ctx_full { void z_arm_save_fp_context(struct fpu_ctx_full *buffer); void z_arm_restore_fp_context(const struct fpu_ctx_full *buffer); +void z_arm_save_shared_fp_context(struct fpu_ctx_full *buffer) +void z_arm_restore_shared_fp_context(const struct fpu_ctx_full *buffer); #endif /* ZEPHYR_INCLUDE_ARCH_ARM_CORTEX_M_FPU_H_ */ diff --git a/modules/trusted-firmware-m/interface/interface.c b/modules/trusted-firmware-m/interface/interface.c index abff7efdc72f..564579222087 100644 --- a/modules/trusted-firmware-m/interface/interface.c +++ b/modules/trusted-firmware-m/interface/interface.c @@ -55,11 +55,11 @@ int32_t tfm_ns_interface_dispatch(veneer_fn fn, struct fpu_ctx_full context_buffer; - z_arm_save_fp_context(&context_buffer); + z_arm_save_shared_fp_context(&context_buffer); result = fn(arg0, arg1, arg2, arg3); - z_arm_restore_fp_context(&context_buffer); + z_arm_restore_shared_fp_context(&context_buffer); if (!isr_mode) { #if !defined(CONFIG_ARM_NONSECURE_PREEMPTIBLE_SECURE_CALLS)