diff --git a/components/esp_hw_support/include/esp_private/sleep_retention.h b/components/esp_hw_support/include/esp_private/sleep_retention.h index 7290c165443..375cfeb8cee 100644 --- a/components/esp_hw_support/include/esp_private/sleep_retention.h +++ b/components/esp_hw_support/include/esp_private/sleep_retention.h @@ -17,7 +17,7 @@ extern "C" { #include "esp_regdma.h" #include "soc/retention_periph_defs.h" -#define SLEEP_RETENTION_MODULE_BITMAP_SZ ((SLEEP_RETENTION_MODULE_MAX >> 5) + 1) +#define SLEEP_RETENTION_MODULE_BITMAP_SZ (((SLEEP_RETENTION_MODULE_MAX - 1) >> 5) + 1) /** * @file sleep_retention.h diff --git a/components/esp_hw_support/sleep_retention.c b/components/esp_hw_support/sleep_retention.c index ecb0c28f0c6..81e6a2c753e 100644 --- a/components/esp_hw_support/sleep_retention.c +++ b/components/esp_hw_support/sleep_retention.c @@ -184,7 +184,7 @@ typedef struct { #define SLEEP_RETENTION_REGDMA_LINK_NR_PRIORITIES (8u) #define SLEEP_RETENTION_REGDMA_LINK_HIGHEST_PRIORITY (0) #define SLEEP_RETENTION_REGDMA_LINK_LOWEST_PRIORITY (SLEEP_RETENTION_REGDMA_LINK_NR_PRIORITIES - 1) -#define SLEEP_RETENTION_MODULE_INVALID ((sleep_retention_module_t)(-1)) /* the final node does not belong to any module */ +#define SLEEP_RETENTION_MODULE_INVALID ((sleep_retention_module_t)(SLEEP_RETENTION_MODULE_MAX)) /* the final node does not belong to any module */ struct { sleep_retention_entries_t entries; uint32_t entries_bitmap: REGDMA_LINK_ENTRY_NUM; @@ -199,7 +199,7 @@ typedef struct { sleep_retention_module_bitmap_t inited_modules; sleep_retention_module_bitmap_t created_modules; - struct sleep_retention_module_object instance[SLEEP_RETENTION_MODULE_MAX + 1]; + struct sleep_retention_module_object instance[SLEEP_RETENTION_MODULE_MAX]; #define EXTRA_LINK_NUM (REGDMA_LINK_ENTRY_NUM - 1) } sleep_retention_t; @@ -325,7 +325,7 @@ static void sleep_retention_entries_stats(void) void sleep_retention_dump_modules(FILE *out) { - for (int i = SLEEP_RETENTION_MODULE_MIN; i <= SLEEP_RETENTION_MODULE_MAX; i++) { + for (int i = SLEEP_RETENTION_MODULE_MIN; i < SLEEP_RETENTION_MODULE_MAX; i++) { bool inited = sleep_retention_is_module_inited(i); bool created = sleep_retention_is_module_created(i); bool is_top = is_top_domain_module(i); @@ -489,13 +489,17 @@ static void sleep_retention_entries_all_destroy_wrapper(sleep_retention_module_t priority++; } } while (priority < SLEEP_RETENTION_REGDMA_LINK_NR_PRIORITIES); - s_retention.created_modules.bitmap[module >> 5] &= ~BIT(module % 32); + /* INVALID (== MAX) is a non-module sentinel; skip bitmap updates. */ + if (module < SLEEP_RETENTION_MODULE_MAX) { + s_retention.created_modules.bitmap[module >> 5] &= ~BIT(module % 32); + } _lock_release_recursive(&s_retention.lock); } static void sleep_retention_entries_do_destroy(sleep_retention_module_t module) { - assert(SLEEP_RETENTION_MODULE_MIN <= module && module <= SLEEP_RETENTION_MODULE_MAX); + /* Allow SLEEP_RETENTION_MODULE_INVALID for final-default rollback. */ + assert(SLEEP_RETENTION_MODULE_MIN <= module && module <= SLEEP_RETENTION_MODULE_INVALID); _lock_acquire_recursive(&s_retention.lock); sleep_retention_entries_join(); sleep_retention_entries_stats(); @@ -505,7 +509,7 @@ static void sleep_retention_entries_do_destroy(sleep_retention_module_t module) static void sleep_retention_entries_destroy(sleep_retention_module_t module) { - assert(SLEEP_RETENTION_MODULE_MIN <= module && module <= SLEEP_RETENTION_MODULE_MAX); + assert(SLEEP_RETENTION_MODULE_MIN <= module && module < SLEEP_RETENTION_MODULE_MAX); _lock_acquire_recursive(&s_retention.lock); sleep_retention_entries_do_destroy(module); uint32_t created_modules = 0; @@ -634,7 +638,7 @@ esp_err_t sleep_retention_entries_create(const sleep_retention_entries_config_t if (priority >= SLEEP_RETENTION_REGDMA_LINK_NR_PRIORITIES) { return ESP_ERR_INVALID_ARG; } - if (module < SLEEP_RETENTION_MODULE_MIN || module > SLEEP_RETENTION_MODULE_MAX) { + if (module < SLEEP_RETENTION_MODULE_MIN || module >= SLEEP_RETENTION_MODULE_MAX) { return ESP_ERR_INVALID_ARG; } esp_err_t err = sleep_retention_entries_check_and_create_final_default(); @@ -671,7 +675,7 @@ sleep_retention_module_bitmap_t IRAM_ATTR sleep_retention_get_created_modules(vo bool sleep_retention_is_module_inited(sleep_retention_module_t module) { - if (module < SLEEP_RETENTION_MODULE_MIN || module > SLEEP_RETENTION_MODULE_MAX) { + if (module < SLEEP_RETENTION_MODULE_MIN || module >= SLEEP_RETENTION_MODULE_MAX) { return false; } _lock_acquire_recursive(&s_retention.lock); @@ -682,7 +686,7 @@ bool sleep_retention_is_module_inited(sleep_retention_module_t module) bool sleep_retention_is_module_created(sleep_retention_module_t module) { - if (module < SLEEP_RETENTION_MODULE_MIN || module > SLEEP_RETENTION_MODULE_MAX) { + if (module < SLEEP_RETENTION_MODULE_MIN || module >= SLEEP_RETENTION_MODULE_MAX) { return false; } _lock_acquire_recursive(&s_retention.lock); @@ -727,7 +731,7 @@ bool IRAM_ATTR sleep_retention_module_bitmap_eq(sleep_retention_module_bitmap_t esp_err_t sleep_retention_module_init(sleep_retention_module_t module, sleep_retention_module_init_param_t *param) { - if (module < SLEEP_RETENTION_MODULE_MIN || module > SLEEP_RETENTION_MODULE_MAX) { + if (module < SLEEP_RETENTION_MODULE_MIN || module >= SLEEP_RETENTION_MODULE_MAX) { return ESP_ERR_INVALID_ARG; } if (param == NULL || param->cbs.create.handle == NULL) { @@ -760,7 +764,7 @@ esp_err_t sleep_retention_module_init(sleep_retention_module_t module, sleep_ret esp_err_t sleep_retention_module_deinit(sleep_retention_module_t module) { - if (module < SLEEP_RETENTION_MODULE_MIN || module > SLEEP_RETENTION_MODULE_MAX) { + if (module < SLEEP_RETENTION_MODULE_MIN || module >= SLEEP_RETENTION_MODULE_MAX) { return ESP_ERR_INVALID_ARG; } @@ -791,7 +795,7 @@ esp_err_t sleep_retention_module_deinit(sleep_retention_module_t module) static esp_err_t sleep_retention_passive_module_allocate(sleep_retention_module_t module) { - assert(module >= SLEEP_RETENTION_MODULE_MIN && module <= SLEEP_RETENTION_MODULE_MAX); + assert(module >= SLEEP_RETENTION_MODULE_MIN && module < SLEEP_RETENTION_MODULE_MAX); esp_err_t err = ESP_OK; _lock_acquire_recursive(&s_retention.lock); @@ -821,7 +825,7 @@ static esp_err_t sleep_retention_passive_module_allocate(sleep_retention_module_ esp_err_t sleep_retention_module_allocate(sleep_retention_module_t module) { - if (module < SLEEP_RETENTION_MODULE_MIN || module > SLEEP_RETENTION_MODULE_MAX) { + if (module < SLEEP_RETENTION_MODULE_MIN || module >= SLEEP_RETENTION_MODULE_MAX) { return ESP_ERR_INVALID_ARG; } @@ -859,7 +863,7 @@ esp_err_t sleep_retention_module_allocate(sleep_retention_module_t module) static esp_err_t sleep_retention_passive_module_free(sleep_retention_module_t module) { - assert(module >= SLEEP_RETENTION_MODULE_MIN && module <= SLEEP_RETENTION_MODULE_MAX); + assert(module >= SLEEP_RETENTION_MODULE_MIN && module < SLEEP_RETENTION_MODULE_MAX); esp_err_t err = ESP_OK; _lock_acquire_recursive(&s_retention.lock); @@ -887,7 +891,7 @@ static esp_err_t sleep_retention_passive_module_free(sleep_retention_module_t mo esp_err_t sleep_retention_module_free(sleep_retention_module_t module) { - if (module < SLEEP_RETENTION_MODULE_MIN || module > SLEEP_RETENTION_MODULE_MAX) { + if (module < SLEEP_RETENTION_MODULE_MIN || module >= SLEEP_RETENTION_MODULE_MAX) { return ESP_ERR_INVALID_ARG; } diff --git a/components/soc/esp32c5/include/soc/Kconfig.soc_caps.in b/components/soc/esp32c5/include/soc/Kconfig.soc_caps.in index b720ab1c1d7..b0b14a32b3e 100644 --- a/components/soc/esp32c5/include/soc/Kconfig.soc_caps.in +++ b/components/soc/esp32c5/include/soc/Kconfig.soc_caps.in @@ -1415,10 +1415,6 @@ config SOC_PM_PMU_MIN_SLP_SLOW_CLK_CYCLE_FIXED bool default y -config SOC_PM_RETENTION_MODULE_NUM - int - default 32 - config SOC_CLK_RC_FAST_SUPPORT_CALIBRATION bool default y diff --git a/components/soc/esp32c5/include/soc/retention_periph_defs.h b/components/soc/esp32c5/include/soc/retention_periph_defs.h index 0f021d3a913..36134f48076 100644 --- a/components/soc/esp32c5/include/soc/retention_periph_defs.h +++ b/components/soc/esp32c5/include/soc/retention_periph_defs.h @@ -7,7 +7,6 @@ #pragma once #include -#include "soc_caps.h" #ifdef __cplusplus extern "C" { @@ -54,7 +53,7 @@ typedef enum periph_retention_module { SLEEP_RETENTION_MODULE_802154_MAC = 30, SLEEP_RETENTION_MODULE_MODEM_PHY = 31, - SLEEP_RETENTION_MODULE_MAX = SOC_PM_RETENTION_MODULE_NUM - 1 + SLEEP_RETENTION_MODULE_MAX, } periph_retention_module_t; #define is_top_domain_module(m) \ diff --git a/components/soc/esp32c5/include/soc/soc_caps.h b/components/soc/esp32c5/include/soc/soc_caps.h index 03ce4f17ea6..200c7f46d36 100644 --- a/components/soc/esp32c5/include/soc/soc_caps.h +++ b/components/soc/esp32c5/include/soc/soc_caps.h @@ -591,7 +591,6 @@ #define SOC_PM_PAU_REGDMA_UPDATE_CACHE_BEFORE_WAIT_COMPARE (1) #define SOC_PM_PMU_MIN_SLP_SLOW_CLK_CYCLE_FIXED (1) -#define SOC_PM_RETENTION_MODULE_NUM (32) /*-------------------------- CLOCK SUBSYSTEM CAPS ----------------------------------------*/ #define SOC_CLK_RC_FAST_SUPPORT_CALIBRATION (1) diff --git a/components/soc/esp32c6/include/soc/Kconfig.soc_caps.in b/components/soc/esp32c6/include/soc/Kconfig.soc_caps.in index 232f8eb1f88..b37df3d2668 100644 --- a/components/soc/esp32c6/include/soc/Kconfig.soc_caps.in +++ b/components/soc/esp32c6/include/soc/Kconfig.soc_caps.in @@ -1475,10 +1475,6 @@ config SOC_PM_PMU_MIN_SLP_SLOW_CLK_CYCLE_FIXED bool default y -config SOC_PM_RETENTION_MODULE_NUM - int - default 32 - config SOC_CLK_RC_FAST_SUPPORT_CALIBRATION bool default y diff --git a/components/soc/esp32c6/include/soc/retention_periph_defs.h b/components/soc/esp32c6/include/soc/retention_periph_defs.h index ad485f09998..4b3bfa3a663 100644 --- a/components/soc/esp32c6/include/soc/retention_periph_defs.h +++ b/components/soc/esp32c6/include/soc/retention_periph_defs.h @@ -7,7 +7,6 @@ #pragma once #include -#include "soc_caps.h" #ifdef __cplusplus extern "C" { @@ -56,7 +55,7 @@ typedef enum periph_retention_module { SLEEP_RETENTION_MODULE_802154_MAC = 30, SLEEP_RETENTION_MODULE_PHY_FE = 31, - SLEEP_RETENTION_MODULE_MAX = SOC_PM_RETENTION_MODULE_NUM - 1 + SLEEP_RETENTION_MODULE_MAX, } periph_retention_module_t; #define is_top_domain_module(m) \ diff --git a/components/soc/esp32c6/include/soc/soc_caps.h b/components/soc/esp32c6/include/soc/soc_caps.h index 2d998d465fd..82b0e1a0766 100644 --- a/components/soc/esp32c6/include/soc/soc_caps.h +++ b/components/soc/esp32c6/include/soc/soc_caps.h @@ -575,7 +575,6 @@ #define SOC_PM_PAU_REGDMA_UPDATE_CACHE_BEFORE_WAIT_COMPARE (1) #define SOC_PM_PMU_MIN_SLP_SLOW_CLK_CYCLE_FIXED (1) -#define SOC_PM_RETENTION_MODULE_NUM (32) /*-------------------------- CLOCK SUBSYSTEM CAPS ----------------------------------------*/ #define SOC_CLK_RC_FAST_SUPPORT_CALIBRATION (1) diff --git a/components/soc/esp32c61/include/soc/Kconfig.soc_caps.in b/components/soc/esp32c61/include/soc/Kconfig.soc_caps.in index 7b535111908..fe1671550a9 100644 --- a/components/soc/esp32c61/include/soc/Kconfig.soc_caps.in +++ b/components/soc/esp32c61/include/soc/Kconfig.soc_caps.in @@ -1015,10 +1015,6 @@ config SOC_PM_PMU_MIN_SLP_SLOW_CLK_CYCLE_FIXED bool default y -config SOC_PM_RETENTION_MODULE_NUM - int - default 32 - config SOC_CLK_RC_FAST_SUPPORT_CALIBRATION bool default y diff --git a/components/soc/esp32c61/include/soc/retention_periph_defs.h b/components/soc/esp32c61/include/soc/retention_periph_defs.h index c64b243b6e9..d0923a33a39 100644 --- a/components/soc/esp32c61/include/soc/retention_periph_defs.h +++ b/components/soc/esp32c61/include/soc/retention_periph_defs.h @@ -7,7 +7,6 @@ #pragma once #include -#include "soc_caps.h" #ifdef __cplusplus extern "C" { @@ -47,7 +46,7 @@ typedef enum periph_retention_module { SLEEP_RETENTION_MODULE_BT_BB = 29, SLEEP_RETENTION_MODULE_802154_MAC = 30, - SLEEP_RETENTION_MODULE_MAX = SOC_PM_RETENTION_MODULE_NUM - 1 + SLEEP_RETENTION_MODULE_MAX, } periph_retention_module_t; #define is_top_domain_module(m) \ diff --git a/components/soc/esp32c61/include/soc/soc_caps.h b/components/soc/esp32c61/include/soc/soc_caps.h index 371722a67b7..beaafc07315 100644 --- a/components/soc/esp32c61/include/soc/soc_caps.h +++ b/components/soc/esp32c61/include/soc/soc_caps.h @@ -458,7 +458,6 @@ #define SOC_PM_PAU_REGDMA_UPDATE_CACHE_BEFORE_WAIT_COMPARE (1) #define SOC_PM_PMU_MIN_SLP_SLOW_CLK_CYCLE_FIXED (1) -#define SOC_PM_RETENTION_MODULE_NUM (32) /*-------------------------- CLOCK SUBSYSTEM CAPS ----------------------------------------*/ #define SOC_CLK_RC_FAST_SUPPORT_CALIBRATION (1) diff --git a/components/soc/esp32h2/include/soc/Kconfig.soc_caps.in b/components/soc/esp32h2/include/soc/Kconfig.soc_caps.in index e9455a8a01b..8be698fb681 100644 --- a/components/soc/esp32h2/include/soc/Kconfig.soc_caps.in +++ b/components/soc/esp32h2/include/soc/Kconfig.soc_caps.in @@ -1423,10 +1423,6 @@ config SOC_PM_PAU_REGDMA_UPDATE_CACHE_BEFORE_WAIT_COMPARE bool default y -config SOC_PM_RETENTION_MODULE_NUM - int - default 32 - config SOC_EXT_MEM_CACHE_TAG_IN_CPU_DOMAIN bool default y diff --git a/components/soc/esp32h2/include/soc/retention_periph_defs.h b/components/soc/esp32h2/include/soc/retention_periph_defs.h index cb32eff66c0..ba48fef0941 100644 --- a/components/soc/esp32h2/include/soc/retention_periph_defs.h +++ b/components/soc/esp32h2/include/soc/retention_periph_defs.h @@ -7,7 +7,6 @@ #pragma once #include -#include "soc_caps.h" #ifdef __cplusplus extern "C" { @@ -53,7 +52,7 @@ typedef enum periph_retention_module { SLEEP_RETENTION_MODULE_BT_BB = 29, SLEEP_RETENTION_MODULE_802154_MAC = 30, - SLEEP_RETENTION_MODULE_MAX = SOC_PM_RETENTION_MODULE_NUM - 1 + SLEEP_RETENTION_MODULE_MAX, } periph_retention_module_t; #define is_top_domain_module(m) \ diff --git a/components/soc/esp32h2/include/soc/soc_caps.h b/components/soc/esp32h2/include/soc/soc_caps.h index ce6be19ed0d..f170e737464 100644 --- a/components/soc/esp32h2/include/soc/soc_caps.h +++ b/components/soc/esp32h2/include/soc/soc_caps.h @@ -574,8 +574,6 @@ #define SOC_PM_PAU_REGDMA_UPDATE_CACHE_BEFORE_WAIT_COMPARE (1) -#define SOC_PM_RETENTION_MODULE_NUM (32) - #define SOC_EXT_MEM_CACHE_TAG_IN_CPU_DOMAIN (1) #define SOC_PM_CPU_RETENTION_BY_SW (1) #define SOC_PM_MODEM_RETENTION_BY_REGDMA (1) diff --git a/components/soc/esp32p4/include/soc/Kconfig.soc_caps.in b/components/soc/esp32p4/include/soc/Kconfig.soc_caps.in index d84e79e68a2..b2d6761021d 100644 --- a/components/soc/esp32p4/include/soc/Kconfig.soc_caps.in +++ b/components/soc/esp32p4/include/soc/Kconfig.soc_caps.in @@ -2051,10 +2051,6 @@ config SOC_SLEEP_TGWDT_STOP_WORKAROUND bool default y -config SOC_PM_RETENTION_MODULE_NUM - int - default 64 - config SOC_PSRAM_VDD_POWER_MPLL bool default y diff --git a/components/soc/esp32p4/include/soc/retention_periph_defs.h b/components/soc/esp32p4/include/soc/retention_periph_defs.h index c35e5effa79..973334d3ed0 100644 --- a/components/soc/esp32p4/include/soc/retention_periph_defs.h +++ b/components/soc/esp32p4/include/soc/retention_periph_defs.h @@ -7,7 +7,6 @@ #pragma once #include -#include "soc_caps.h" #ifdef __cplusplus extern "C" { @@ -63,7 +62,7 @@ typedef enum periph_retention_module { SLEEP_RETENTION_MODULE_DMA2D = 41, SLEEP_RETENTION_MODULE_PPA = 42, - SLEEP_RETENTION_MODULE_MAX = SOC_PM_RETENTION_MODULE_NUM - 1 + SLEEP_RETENTION_MODULE_MAX, } periph_retention_module_t; #define is_top_domain_module(m) \ diff --git a/components/soc/esp32p4/include/soc/soc_caps.h b/components/soc/esp32p4/include/soc/soc_caps.h index 7751e8ba02b..b7b002e2eee 100644 --- a/components/soc/esp32p4/include/soc/soc_caps.h +++ b/components/soc/esp32p4/include/soc/soc_caps.h @@ -757,7 +757,6 @@ #define SOC_SLEEP_SYSTIMER_STALL_WORKAROUND 1 //TODO IDF-11381: replace with all xtal field clk gate control #define SOC_SLEEP_TGWDT_STOP_WORKAROUND 1 //TODO IDF-11381: replace with all xtal field clk gate control -#define SOC_PM_RETENTION_MODULE_NUM (64) /*-------------------------- PSRAM CAPS ----------------------------*/ #define SOC_PSRAM_VDD_POWER_MPLL (1) diff --git a/components/soc/include/soc/regdma.h b/components/soc/include/soc/regdma.h index cc0a322f159..1c3d6c4d90e 100644 --- a/components/soc/include/soc/regdma.h +++ b/components/soc/include/soc/regdma.h @@ -18,6 +18,8 @@ extern "C" { #if SOC_PAU_SUPPORTED +#include "soc/retention_periph_defs.h" + #define REGDMA_LINK_ENTRY_NUM (SOC_PM_PAU_LINK_NUM) /* Maximum number of REG DMA linked list entries */ #ifndef ARRAY_SIZE @@ -179,15 +181,15 @@ typedef struct regdma_link_branch_write_wait_body { volatile uint32_t mask; } regdma_link_branch_write_wait_body_t; -ESP_STATIC_ASSERT(REGDMA_LINK_ENTRY_NUM <= 16, "regdma link entry number should equal to and less than 16"); +ESP_STATIC_ASSERT(REGDMA_LINK_ENTRY_NUM < 16, "regdma link entry number must be less than 16 to pack module into stats"); typedef struct regdma_link_stats { volatile uint32_t ref: REGDMA_LINK_ENTRY_NUM, /* a bitmap, identifies which entry has referenced the current link */ -#if REGDMA_LINK_ENTRY_NUM < 16 - reserve: 16-REGDMA_LINK_ENTRY_NUM, -#endif + module: 16 - REGDMA_LINK_ENTRY_NUM, /* module id; width leaves room beside ref within the low 16 bits */ id: 16; /* REGDMA linked list node unique identifier */ - volatile int module; /* a number used to identify the module to which the current node belongs */ } regdma_link_stats_t; +ESP_STATIC_ASSERT(sizeof(regdma_link_stats_t) == 4, "regdma_link_stats_t must be 4 bytes"); +ESP_STATIC_ASSERT(SLEEP_RETENTION_MODULE_MAX < (1u << (16 - REGDMA_LINK_ENTRY_NUM)), + "module id exceeds bitfield width"); typedef struct regdma_link_continuous { regdma_link_stats_t stat;