Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions arch/arm/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,16 @@
observed on some SoCs caused by a memory access following WFI/WFE
instructions.

config ARCH_PM_S2RAM_RESUME
bool "Include PM S2RAM resume jump"
depends on ARCH_HAS_SUSPEND_TO_RAM && !PM_S2RAM

Check warning on line 149 in arch/arm/Kconfig

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

LEADING_SPACE

arch/arm/Kconfig:149 please, no spaces at the start of a line
depends on CPU_CORTEX_M
help
This option enables suspend-to-RAM (S2RAM) resume intermediary support.
It is dedicated for the bootloader use case where the bootloader is the first stage
and its role (in S2RAM flow) is just to mediate in resuming the application from
the suspension.

rsource "core/Kconfig"
rsource "core/Kconfig.vfp"

Expand Down
1 change: 1 addition & 0 deletions arch/arm/core/cortex_m/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ zephyr_library_sources_ifdef(CONFIG_DEBUG_COREDUMP coredump.c)
zephyr_library_sources_ifdef(CONFIG_THREAD_LOCAL_STORAGE __aeabi_read_tp.S)
zephyr_library_sources_ifdef(CONFIG_SEMIHOST semihost.c)
zephyr_library_sources_ifdef(CONFIG_PM_S2RAM pm_s2ram.c pm_s2ram.S)
zephyr_library_sources_ifdef(CONFIG_ARCH_PM_S2RAM_RESUME pm_s2ram_intermediary.S)
zephyr_library_sources_ifdef(CONFIG_ARCH_CACHE cache.c)
zephyr_library_sources_ifdef(CONFIG_SW_VECTOR_RELAY irq_relay.S)

Expand Down
28 changes: 28 additions & 0 deletions arch/arm/core/cortex_m/pm_s2ram_intermediary.S
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this just a trampoline to redirect reset.S's bl arch_pm_s2ram_resume to pm_s2ram_mark_check_and_mediate? If so, we don't need assembly for that (and indeed @wearyzen's proposal of a platform hook instead is better)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is not a part of PM_S2RAM feature compiled in the zephyr-rtos instance. Bootloader should use config CONFIG_ARCH_PM_S2RAM_RESUME and Not CONFIG_PM_S2RAM while the application just the opposite way.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The key point of my comment was that we don't need a new ASM file for a call trampoline - either inline it in reset.S (i.e., soc_resume_hook which is what we're going towards) or implement it in a C file.

(the former solution is probably better)

Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright (c) 2025, Nordic Semiconductor ASA
*
* SPDX-License-Identifier: Apache-2.0
*/

/**
* @file
* @brief ARM Cortex-M suspend-to-RAM resume intermediary code (S2RAM)
*/

#include <zephyr/toolchain.h>
#include <zephyr/arch/cpu.h>
#include <zephyr/arch/common/pm_s2ram.h>

GTEXT(pm_s2ram_mark_check_and_mediate)

GTEXT(arch_pm_s2ram_resume)
SECTION_FUNC(TEXT, arch_pm_s2ram_resume)
/*
* Check if reset occurred after suspending to RAM.
* Store LR to ensure we can continue boot when we are not suspended
* to RAM. In addition to LR, R0 is pushed too, to ensure "SP mod 8 = 0",
* as stated by ARM rule 6.2.1.2 for AAPCS32.
*/
push {r0, lr}
bl pm_s2ram_mark_check_and_mediate
pop {r0, pc}
2 changes: 1 addition & 1 deletion arch/arm/core/cortex_m/reset.S
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ SECTION_SUBSEC_FUNC(TEXT,_reset_section,__start)

#endif /* CONFIG_INIT_ARCH_HW_AT_BOOT */

#if defined(CONFIG_PM_S2RAM)
#if defined(CONFIG_PM_S2RAM) || defined(CONFIG_ARCH_PM_S2RAM_RESUME)
/*
* Temporarily set MSP to interrupt stack so that arch_pm_s2ram_resume can
* use stack for calling pm_s2ram_mark_check_and_clear.
Expand Down
13 changes: 13 additions & 0 deletions include/zephyr/arch/common/pm_s2ram.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*

Check warning on line 1 in include/zephyr/arch/common/pm_s2ram.h

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

License missing

include/zephyr/arch/common/pm_s2ram.h:1 File has no SPDX-License-Identifier header, consider adding one.
* Copyright (c) 2022, Carlo Caione <ccaione@baylibre.com>
*/

Expand Down Expand Up @@ -81,6 +81,19 @@
* @retval false if marking is not found which indicates standard boot.
*/
bool pm_s2ram_mark_check_and_clear(void);

/**
* @brief Check suspend-to-RAM marking and does mediation.
*
* Function does resume mediation if determines resuming after suspend-to-RAM
* or return so standard boot will be executed.
*
* Implementation is up to given application - usually a bootloader. The function is expected
* to do mediation needed for resuming the application from S2AM state, which usually means no
* return to caller. Usage of this API implementation shall be enabled using
* CONFIG_ARCH_PM_S2RAM_RESUME.
Comment on lines +86 to +94
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the purpose of pm_s2ram_mark_check_and_mediate? What does resume mediation mean? I don't really understand what an implementation is supposed to do with just this description.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is expected to do anything what is needed to boot the device from S2RAM sleep. Usually it should jump to the reset vector of the application. This reset vector is known for the bootloader - it is up to bootloader to make this operation reliable.

*/
void pm_s2ram_mark_check_and_mediate(void);
/**
* @}
*/
Expand Down
Loading