Skip to content

Commit 597eaa8

Browse files
nordic-krchbjarki-andreasen
authored andcommitted
[nrf fromtree] soc: nordic: nrf54h: power: Enable cache as early as possible
Add nrf_cache_power_up and nrf_cache_power_down functions. In case of s2ram power up cache as early as possible, before restoring ARM core registers. It improves restore time from 180 us to 33 us. As a minor optimization nrf_memconf_ramblock_control_mask_enable_set is used which allows to control ram blocks for icache and dcache in a single register write. Signed-off-by: Krzysztof Chruściński <[email protected]> (cherry picked from commit a36b154) (cherry picked from commit da14f33) (cherry picked from commit 70ad1b9)
1 parent ea2fb45 commit 597eaa8

File tree

3 files changed

+43
-26
lines changed

3 files changed

+43
-26
lines changed

soc/nordic/nrf54h/pm_s2ram.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <zephyr/sys/util.h>
1010
#include <hal/nrf_resetinfo.h>
1111
#include "pm_s2ram.h"
12+
#include "power.h"
1213

1314
#include <cmsis_core.h>
1415

@@ -170,6 +171,8 @@ int soc_s2ram_suspend(pm_s2ram_system_off_fn_t system_off)
170171
return ret;
171172
}
172173

174+
nrf_power_up_cache();
175+
173176
mpu_resume(&backup_data.mpu_context);
174177
nvic_resume(&backup_data.nvic_context);
175178
scb_resume(&backup_data.scb_context);

soc/nordic/nrf54h/power.c

Lines changed: 35 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -18,42 +18,50 @@
1818

1919
extern sys_snode_t soc_node;
2020

21-
static void common_suspend(void)
21+
static void nrf_power_down_cache(void)
2222
{
23-
if (IS_ENABLED(CONFIG_DCACHE)) {
24-
/* Flush, disable and power down DCACHE */
25-
sys_cache_data_flush_all();
26-
sys_cache_data_disable();
27-
nrf_memconf_ramblock_control_enable_set(NRF_MEMCONF, RAMBLOCK_POWER_ID,
28-
RAMBLOCK_CONTROL_BIT_DCACHE, false);
29-
}
23+
static const uint32_t msk =
24+
(IS_ENABLED(CONFIG_DCACHE) ? BIT(RAMBLOCK_CONTROL_BIT_DCACHE) : 0) |
25+
(IS_ENABLED(CONFIG_ICACHE) ? BIT(RAMBLOCK_CONTROL_BIT_ICACHE) : 0);
3026

31-
if (IS_ENABLED(CONFIG_ICACHE)) {
32-
/* Disable and power down ICACHE */
33-
sys_cache_instr_disable();
34-
nrf_memconf_ramblock_control_enable_set(NRF_MEMCONF, RAMBLOCK_POWER_ID,
35-
RAMBLOCK_CONTROL_BIT_ICACHE, false);
27+
if (msk == 0) {
28+
return;
3629
}
3730

38-
soc_lrcconf_poweron_release(&soc_node, NRF_LRCCONF_POWER_DOMAIN_0);
31+
/* Functions are non-empty only if cache is enabled.
32+
* Data cache disabling include flushing.
33+
*/
34+
sys_cache_data_disable();
35+
sys_cache_instr_disable();
36+
nrf_memconf_ramblock_control_mask_enable_set(NRF_MEMCONF, RAMBLOCK_POWER_ID, msk, false);
3937
}
4038

41-
static void common_resume(void)
39+
void nrf_power_up_cache(void)
4240
{
43-
if (IS_ENABLED(CONFIG_ICACHE)) {
44-
/* Power up and re-enable ICACHE */
45-
nrf_memconf_ramblock_control_enable_set(NRF_MEMCONF, RAMBLOCK_POWER_ID,
46-
RAMBLOCK_CONTROL_BIT_ICACHE, true);
47-
sys_cache_instr_enable();
48-
}
41+
static const uint32_t msk =
42+
(IS_ENABLED(CONFIG_DCACHE) ? BIT(RAMBLOCK_CONTROL_BIT_DCACHE) : 0) |
43+
(IS_ENABLED(CONFIG_ICACHE) ? BIT(RAMBLOCK_CONTROL_BIT_ICACHE) : 0);
4944

50-
if (IS_ENABLED(CONFIG_DCACHE)) {
51-
/* Power up and re-enable DCACHE */
52-
nrf_memconf_ramblock_control_enable_set(NRF_MEMCONF, RAMBLOCK_POWER_ID,
53-
RAMBLOCK_CONTROL_BIT_DCACHE, true);
54-
sys_cache_data_enable();
45+
if (msk == 0) {
46+
return;
5547
}
5648

49+
nrf_memconf_ramblock_control_mask_enable_set(NRF_MEMCONF, RAMBLOCK_POWER_ID, msk, true);
50+
sys_cache_instr_enable();
51+
sys_cache_data_enable();
52+
}
53+
54+
static void common_suspend(void)
55+
{
56+
soc_lrcconf_poweron_release(&soc_node, NRF_LRCCONF_POWER_DOMAIN_0);
57+
nrf_power_down_cache();
58+
}
59+
60+
static void common_resume(void)
61+
{
62+
/* Common part does not include cache enabling. In case of s2ram it is done
63+
* as early as possible to speed up the process.
64+
*/
5765
soc_lrcconf_poweron_request(&soc_node, NRF_LRCCONF_POWER_DOMAIN_0);
5866
}
5967

@@ -112,6 +120,7 @@ static void s2idle_exit(uint8_t substate_id)
112120
case 1: /* Substate for idle with cache retained - not implemented yet. */
113121
break;
114122
case 2: /* Substate for idle with cache disabled. */
123+
nrf_power_up_cache();
115124
common_resume();
116125
#if !defined(CONFIG_SOC_NRF54H20_CPURAD)
117126
soc_lrcconf_poweron_release(&soc_node, NRF_LRCCONF_POWER_MAIN);

soc/nordic/nrf54h/power.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,9 @@
1717
*/
1818
void nrf_poweroff(void);
1919

20+
/**
21+
* @brief Power up and enable instruction and data cache.
22+
*/
23+
void nrf_power_up_cache(void);
24+
2025
#endif /* _ZEPHYR_SOC_ARM_NORDIC_NRF_POWER_H_ */

0 commit comments

Comments
 (0)