Skip to content

Commit

Permalink
[nrf fromlist] soc: nordic: s2ram: Align s2ram marking procedures
Browse files Browse the repository at this point in the history
Rework Nordic specific S2RAM marking procedures.
The S2RAM marking procedures must not disrupt the stack due to
the TLS pointer not yet being initialized during their execution.

Upstream PR: zephyrproject-rtos/zephyr#80039

Signed-off-by: Adam Kondraciuk <[email protected]>
  • Loading branch information
adamkondraciuk committed Oct 18, 2024
1 parent d90712a commit 19a78cd
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 23 deletions.
1 change: 1 addition & 0 deletions soc/nordic/common/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ endif()
zephyr_library_sources_ifdef(CONFIG_POWEROFF poweroff.c)
if(CONFIG_ARM)
zephyr_library_sources_ifdef(CONFIG_NRF_PLATFORM_HALTIUM soc_lrcconf.c)
zephyr_library_sources_ifdef(CONFIG_PM_S2RAM_CUSTOM_MARKING pm_s2ram.S)
endif()

if((CONFIG_SOC_SERIES_NRF54HX OR CONFIG_SOC_SERIES_NRF92X) AND CONFIG_CPU_HAS_CUSTOM_FIXED_SOC_MPU_REGIONS)
Expand Down
73 changes: 73 additions & 0 deletions soc/nordic/common/pm_s2ram.S
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*
* Copyright (c) 2024 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: Apache-2.0
*/

/**
* @file
* @brief Nordic suspend-to-RAM code (S2RAM)
*/

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


GTEXT(pm_s2ram_mark_set)
SECTION_FUNC(TEXT, pm_s2ram_mark_set)
/*
* Restore the PC and continue
*/
mov r15, r1

GTEXT(pm_s2ram_mark_check_and_clear)
SECTION_FUNC(TEXT, pm_s2ram_mark_check_and_clear)
/*
* Set return value to 0
*/
mov r0, #0

/*
* Load check RESETREAS register
*/
ldr r2, =CONFIG_NRF_RESETINFO_PERIPH_ADDRESS
ldr r5, =CONFIG_NRF_RESETREAS_LOCAL_REG_OFFSET
ldr r3, [r5, r2]
ldr r6, =CONFIG_NRF_RESETREAS_LOCAL_UNRETAINEDWAKE_FIELD
cmp r3, r6

bne exit

/*
* Clear RESETREAS
*/
str r0, [r5, r2]

/*
* Load RESTOREVALID register
*/
ldr r5, =CONFIG_NRF_RESTOREVALID_REG_OFFSET
ldr r3, [r5, r2]

/*
* Clear RESTOREVALID
*/
str r0, [r5, r2]

/*
* Check RESTOREVALID register
*/
ldr r5, =CONFIG_NRF_RESTOREVALID_PRESENT_FIELD
cmp r3, r5
bne exit

/*
* Set return value to 1
*/
mov r0, #1
exit:
/*
* Restore the PC and continue
*/
mov r15, r1
20 changes: 20 additions & 0 deletions soc/nordic/nrf54h/Kconfig.defconfig.nrf54h20_cpuapp
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,24 @@ config NRF_REGTOOL_GENERATE_UICR
config NRF_REGTOOL_GENERATE_BICR
default y

config NRF_RESETINFO_PERIPH_ADDRESS
hex
default 0x5201E000

config NRF_RESETREAS_LOCAL_REG_OFFSET
hex
default 0x4A4

config NRF_RESTOREVALID_REG_OFFSET
hex
default 0x4C0

config NRF_RESETREAS_LOCAL_UNRETAINEDWAKE_FIELD
hex
default 0x10

config NRF_RESTOREVALID_PRESENT_FIELD
hex
default 0x1

endif # SOC_NRF54H20_CPUAPP || SOC_NRF54H20_ENGB_CPUAPP
23 changes: 0 additions & 23 deletions soc/nordic/nrf54h/pm_s2ram.c
Original file line number Diff line number Diff line change
Expand Up @@ -126,26 +126,3 @@ int soc_s2ram_suspend(pm_s2ram_system_off_fn_t system_off)

return ret;
}

void pm_s2ram_mark_set(void)
{
/* empty */
}

bool pm_s2ram_mark_check_and_clear(void)
{
bool unretained_wake;
bool restore_valid;
uint32_t reset_reason = nrf_resetinfo_resetreas_local_get(NRF_RESETINFO);

if (reset_reason != NRF_RESETINFO_RESETREAS_LOCAL_UNRETAINED_MASK) {
return false;
}
unretained_wake = reset_reason & NRF_RESETINFO_RESETREAS_LOCAL_UNRETAINED_MASK;
nrf_resetinfo_resetreas_local_set(NRF_RESETINFO, 0);

restore_valid = nrf_resetinfo_restore_valid_check(NRF_RESETINFO);
nrf_resetinfo_restore_valid_set(NRF_RESETINFO, false);

return (unretained_wake & restore_valid) ? true : false;
}

0 comments on commit 19a78cd

Please sign in to comment.