Skip to content

arch: arm: cortex_m: Update APIs to save and restore FPU context #93057

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

msmttchr
Copy link
Contributor

@msmttchr msmttchr commented Jul 12, 2025

Update API to save and restore FPU context to address suspend to ram use case.

The API is updated as follow:

  • Existing APIs z_arm_save_fp_context and z_arm_restore_fp_context have been changed to always save/restore FPU context regardless of FPU_SHARING setting
  • A new set APIs is introduced (z_arm_save_shared_fp_context and z_arm_restore_shared_fp_context) to address FPU_SHARING use cases (See https://docs.zephyrproject.org/latest/kconfig.html#!%5ECONFIG_FPU_SHARING$)
  • The only use case of the original API has been updated

The existing API z_arm_save_fp_context and z_arm_restore_fp_context were used only in TFM code, but I believe that in this use case we need to save/restore FPU context regardless of FPU_SHARING setting. Please feedback on this point.

I also noticed by reading code and ARM documentation that the FPU context is preserved across threads by hardware on Cortex-M devices (via the FPCCR.ASPEN register field), so it seems to me that this new API (which mimic existing API) is not needed (except for the doubtful TFM case above). If this is the case, this PR can be simplified.

See also #90001, #92847 (comment)

msmttchr added 2 commits July 12, 2025 19:27
Signed-off-by: Michele Sardo <msmttchr@gmail.com>
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>
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: Architectures area: ARM ARM (32-bit) Architecture area: TF-M ARM Trusted Firmware-M (TF-M)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants