From ab026ecc01907d40cc38e45fce355b4de3ffd9bc Mon Sep 17 00:00:00 2001 From: armando Date: Wed, 1 Apr 2026 10:09:22 +0800 Subject: [PATCH 1/2] feat(mmu): configurable page size s31 support --- components/esp_psram/system_layer/esp_psram.c | 4 ++ components/hal/esp32s31/include/hal/mmu_ll.h | 52 +++++++++++++++++-- components/hal/include/hal/mmu_types.h | 12 +++-- components/soc/Kconfig | 28 ++-------- components/soc/esp32/Kconfig.mmu | 7 +++ components/soc/esp32c2/Kconfig.mmu | 18 +++++++ components/soc/esp32c3/Kconfig.mmu | 7 +++ components/soc/esp32c5/Kconfig.mmu | 7 +++ components/soc/esp32c6/Kconfig.mmu | 22 ++++++++ .../esp32c6/include/soc/Kconfig.soc_caps.in | 4 -- components/soc/esp32c6/include/soc/soc_caps.h | 1 - components/soc/esp32c61/Kconfig.mmu | 22 ++++++++ .../esp32c61/include/soc/Kconfig.soc_caps.in | 4 -- .../soc/esp32c61/include/soc/soc_caps.h | 1 - components/soc/esp32h2/Kconfig.mmu | 22 ++++++++ .../esp32h2/include/soc/Kconfig.soc_caps.in | 4 -- components/soc/esp32h2/include/soc/soc_caps.h | 1 - components/soc/esp32h21/Kconfig.mmu | 22 ++++++++ .../esp32h21/include/soc/Kconfig.soc_caps.in | 4 -- .../soc/esp32h21/include/soc/soc_caps.h | 1 - components/soc/esp32h4/Kconfig.mmu | 22 ++++++++ .../esp32h4/include/soc/Kconfig.soc_caps.in | 4 -- components/soc/esp32h4/include/soc/soc_caps.h | 1 - components/soc/esp32p4/Kconfig.mmu | 7 +++ components/soc/esp32s2/Kconfig.mmu | 7 +++ components/soc/esp32s3/Kconfig.mmu | 7 +++ components/soc/esp32s31/Kconfig.mmu | 26 ++++++++++ .../esp32s31/include/soc/Kconfig.soc_caps.in | 4 ++ .../soc/esp32s31/include/soc/ext_mem_defs.h | 4 +- .../soc/esp32s31/include/soc/soc_caps.h | 1 + components/soc/linux/Kconfig.mmu | 7 +++ 31 files changed, 273 insertions(+), 60 deletions(-) create mode 100644 components/soc/esp32/Kconfig.mmu create mode 100644 components/soc/esp32c2/Kconfig.mmu create mode 100644 components/soc/esp32c3/Kconfig.mmu create mode 100644 components/soc/esp32c5/Kconfig.mmu create mode 100644 components/soc/esp32c6/Kconfig.mmu create mode 100644 components/soc/esp32c61/Kconfig.mmu create mode 100644 components/soc/esp32h2/Kconfig.mmu create mode 100644 components/soc/esp32h21/Kconfig.mmu create mode 100644 components/soc/esp32h4/Kconfig.mmu create mode 100644 components/soc/esp32p4/Kconfig.mmu create mode 100644 components/soc/esp32s2/Kconfig.mmu create mode 100644 components/soc/esp32s3/Kconfig.mmu create mode 100644 components/soc/esp32s31/Kconfig.mmu create mode 100644 components/soc/linux/Kconfig.mmu diff --git a/components/esp_psram/system_layer/esp_psram.c b/components/esp_psram/system_layer/esp_psram.c index 3147eb596a..285b0dfec6 100644 --- a/components/esp_psram/system_layer/esp_psram.c +++ b/components/esp_psram/system_layer/esp_psram.c @@ -436,6 +436,10 @@ esp_err_t esp_psram_init(void) ret = esp_psram_impl_get_available_size(&psram_available_size); assert(ret == ESP_OK); +#if SOC_MMU_PER_EXT_MEM_TARGET + //set PSRAM dedicated MMU + mmu_ll_set_page_size(1, CONFIG_MMU_PAGE_SIZE); +#endif /** * `start_page` is the psram physical address in MMU page size. * MMU page size on ESP32S2 is 64KB diff --git a/components/hal/esp32s31/include/hal/mmu_ll.h b/components/hal/esp32s31/include/hal/mmu_ll.h index ecca76e596..f41b35f413 100644 --- a/components/hal/esp32s31/include/hal/mmu_ll.h +++ b/components/hal/esp32s31/include/hal/mmu_ll.h @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2025-2026 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -124,8 +124,26 @@ __attribute__((always_inline)) static inline bool mmu_ll_cache_encryption_enable __attribute__((always_inline)) static inline mmu_page_size_t mmu_ll_get_page_size(uint32_t mmu_id) { - (void)mmu_id; - return MMU_PAGE_64KB; + uint32_t page_size_code = 0; + mmu_page_size_t page_size = MMU_PAGE_64KB; + + if (mmu_id == MMU_LL_FLASH_MMU_ID) { + page_size_code = REG_GET_FIELD(SPI_MEM_C_MMU_POWER_CTRL_REG, SPI_MMU_PAGE_SIZE); + page_size = (page_size_code == 0) ? MMU_PAGE_256KB : \ + (page_size_code == 1) ? MMU_PAGE_128KB : \ + (page_size_code == 2) ? MMU_PAGE_64KB : \ + MMU_PAGE_32KB; + } else if (mmu_id == MMU_LL_PSRAM_MMU_ID) { + page_size_code = REG_GET_FIELD(SPI_MEM_S_MMU_POWER_CTRL_REG, SPI_MMU_PAGE_SIZE); + page_size = (page_size_code == 0) ? MMU_PAGE_64KB : \ + (page_size_code == 1) ? MMU_PAGE_32KB : \ + (page_size_code == 2) ? MMU_PAGE_16KB : \ + MMU_PAGE_8KB; + } else { + HAL_ASSERT(false); + } + + return page_size; } /** @@ -136,9 +154,21 @@ static inline mmu_page_size_t mmu_ll_get_page_size(uint32_t mmu_id) __attribute__((always_inline)) static inline void mmu_ll_set_page_size(uint32_t mmu_id, uint32_t size) { - HAL_ASSERT(size == MMU_PAGE_64KB); + uint8_t reg_val = 0; if (mmu_id == MMU_LL_FLASH_MMU_ID) { - REG_SET_FIELD(SPI_MEM_C_MMU_POWER_CTRL_REG, SPI_MMU_PAGE_SIZE, 2); + reg_val = (size == MMU_PAGE_256KB) ? 0 : \ + (size == MMU_PAGE_128KB) ? 1 : \ + (size == MMU_PAGE_64KB) ? 2 : \ + (size == MMU_PAGE_32KB) ? 3 : 0; + REG_SET_FIELD(SPI_MEM_C_MMU_POWER_CTRL_REG, SPI_MMU_PAGE_SIZE, reg_val); + } else if (mmu_id == MMU_LL_PSRAM_MMU_ID) { + reg_val = (size == MMU_PAGE_64KB) ? 0 : \ + (size == MMU_PAGE_32KB) ? 1 : \ + (size == MMU_PAGE_16KB) ? 2 : \ + (size == MMU_PAGE_8KB) ? 3 : 0; + REG_SET_FIELD(SPI_MEM_S_MMU_POWER_CTRL_REG, SPI_MMU_PAGE_SIZE, reg_val); + } else { + HAL_ASSERT(false); } } @@ -203,6 +233,12 @@ static inline uint32_t mmu_ll_get_entry_id(uint32_t mmu_id, uint32_t vaddr) mmu_page_size_t page_size = mmu_ll_get_page_size(mmu_id); uint32_t shift_code = 0; switch (page_size) { + case MMU_PAGE_256KB: + shift_code = 18; + break; + case MMU_PAGE_128KB: + shift_code = 17; + break; case MMU_PAGE_64KB: shift_code = 16; break; @@ -238,6 +274,12 @@ static inline uint32_t mmu_ll_format_paddr(uint32_t mmu_id, uint32_t paddr, mmu_ mmu_page_size_t page_size = mmu_ll_get_page_size(mmu_id); uint32_t shift_code = 0; switch (page_size) { + case MMU_PAGE_256KB: + shift_code = 18; + break; + case MMU_PAGE_128KB: + shift_code = 17; + break; case MMU_PAGE_64KB: shift_code = 16; break; diff --git a/components/hal/include/hal/mmu_types.h b/components/hal/include/hal/mmu_types.h index ee42bd5632..d056fcd417 100644 --- a/components/hal/include/hal/mmu_types.h +++ b/components/hal/include/hal/mmu_types.h @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2010-2023 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2010-2026 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -24,10 +24,12 @@ typedef enum { * MMU Page size */ typedef enum { - MMU_PAGE_8KB = 0x2000, - MMU_PAGE_16KB = 0x4000, - MMU_PAGE_32KB = 0x8000, - MMU_PAGE_64KB = 0x10000, + MMU_PAGE_8KB = 0x2000, + MMU_PAGE_16KB = 0x4000, + MMU_PAGE_32KB = 0x8000, + MMU_PAGE_64KB = 0x10000, + MMU_PAGE_128KB = 0x20000, + MMU_PAGE_256KB = 0x40000, } mmu_page_size_t; /** diff --git a/components/soc/Kconfig b/components/soc/Kconfig index dcc3e39da3..e3a1cb2077 100644 --- a/components/soc/Kconfig +++ b/components/soc/Kconfig @@ -3,35 +3,15 @@ menu "SoC Settings" visible if 0 menu "MMU Config" - # This Config is used for configure the MMU. - # Be configured based on flash size selection. - # Invisible to users. - - config MMU_PAGE_SIZE_8KB - bool - depends on SOC_MMU_PAGE_SIZE_8KB_SUPPORTED - default n - - config MMU_PAGE_SIZE_16KB - bool - default y if SOC_MMU_PAGE_SIZE_CONFIGURABLE && ESPTOOLPY_FLASHSIZE_1MB - default n - - config MMU_PAGE_SIZE_32KB - bool - default y if SOC_MMU_PAGE_SIZE_CONFIGURABLE && ESPTOOLPY_FLASHSIZE_2MB - default n - - config MMU_PAGE_SIZE_64KB - bool - default y if !MMU_PAGE_SIZE_32KB && !MMU_PAGE_SIZE_16KB - default n + orsource "$IDF_TARGET/Kconfig.mmu" config MMU_PAGE_MODE string default "8KB" if MMU_PAGE_SIZE_8KB default "16KB" if MMU_PAGE_SIZE_16KB default "32KB" if MMU_PAGE_SIZE_32KB + default "128KB" if MMU_PAGE_SIZE_128KB + default "256KB" if MMU_PAGE_SIZE_256KB default "64KB" if MMU_PAGE_SIZE_64KB config MMU_PAGE_SIZE @@ -45,6 +25,8 @@ menu "SoC Settings" default 0x4000 if MMU_PAGE_SIZE_16KB default 0x8000 if MMU_PAGE_SIZE_32KB default 0x10000 if MMU_PAGE_SIZE_64KB + default 0x20000 if MMU_PAGE_SIZE_128KB + default 0x40000 if MMU_PAGE_SIZE_256KB endmenu endmenu diff --git a/components/soc/esp32/Kconfig.mmu b/components/soc/esp32/Kconfig.mmu new file mode 100644 index 0000000000..6359517cec --- /dev/null +++ b/components/soc/esp32/Kconfig.mmu @@ -0,0 +1,7 @@ +# This Config is used for configure the MMU. +# Be configured based on flash size selection. +# Invisible to users. + +config MMU_PAGE_SIZE_64KB + bool + default y diff --git a/components/soc/esp32c2/Kconfig.mmu b/components/soc/esp32c2/Kconfig.mmu new file mode 100644 index 0000000000..bc1e5c16bf --- /dev/null +++ b/components/soc/esp32c2/Kconfig.mmu @@ -0,0 +1,18 @@ +# This Config is used for configure the MMU. +# Be configured based on flash size selection. +# Invisible to users. + +config MMU_PAGE_SIZE_16KB + bool + default y if ESPTOOLPY_FLASHSIZE_1MB + default n + +config MMU_PAGE_SIZE_32KB + bool + default y if ESPTOOLPY_FLASHSIZE_2MB + default n + +config MMU_PAGE_SIZE_64KB + bool + default y if !MMU_PAGE_SIZE_32KB && !MMU_PAGE_SIZE_16KB + default n diff --git a/components/soc/esp32c3/Kconfig.mmu b/components/soc/esp32c3/Kconfig.mmu new file mode 100644 index 0000000000..6359517cec --- /dev/null +++ b/components/soc/esp32c3/Kconfig.mmu @@ -0,0 +1,7 @@ +# This Config is used for configure the MMU. +# Be configured based on flash size selection. +# Invisible to users. + +config MMU_PAGE_SIZE_64KB + bool + default y diff --git a/components/soc/esp32c5/Kconfig.mmu b/components/soc/esp32c5/Kconfig.mmu new file mode 100644 index 0000000000..6359517cec --- /dev/null +++ b/components/soc/esp32c5/Kconfig.mmu @@ -0,0 +1,7 @@ +# This Config is used for configure the MMU. +# Be configured based on flash size selection. +# Invisible to users. + +config MMU_PAGE_SIZE_64KB + bool + default y diff --git a/components/soc/esp32c6/Kconfig.mmu b/components/soc/esp32c6/Kconfig.mmu new file mode 100644 index 0000000000..607c8ca7aa --- /dev/null +++ b/components/soc/esp32c6/Kconfig.mmu @@ -0,0 +1,22 @@ +# This Config is used for configure the MMU. +# Be configured based on flash size selection. +# Invisible to users. + +config MMU_PAGE_SIZE_8KB + bool + default n + +config MMU_PAGE_SIZE_16KB + bool + default y if ESPTOOLPY_FLASHSIZE_1MB + default n + +config MMU_PAGE_SIZE_32KB + bool + default y if ESPTOOLPY_FLASHSIZE_2MB + default n + +config MMU_PAGE_SIZE_64KB + bool + default y if !MMU_PAGE_SIZE_32KB && !MMU_PAGE_SIZE_16KB && !MMU_PAGE_SIZE_8KB + default n diff --git a/components/soc/esp32c6/include/soc/Kconfig.soc_caps.in b/components/soc/esp32c6/include/soc/Kconfig.soc_caps.in index 0b268501ba..e107c6741c 100644 --- a/components/soc/esp32c6/include/soc/Kconfig.soc_caps.in +++ b/components/soc/esp32c6/include/soc/Kconfig.soc_caps.in @@ -687,10 +687,6 @@ config SOC_MMU_PAGE_SIZE_CONFIGURABLE bool default y -config SOC_MMU_PAGE_SIZE_8KB_SUPPORTED - bool - default y - config SOC_MMU_PERIPH_NUM int default 1 diff --git a/components/soc/esp32c6/include/soc/soc_caps.h b/components/soc/esp32c6/include/soc/soc_caps.h index b0c8199530..8a3121fe68 100644 --- a/components/soc/esp32c6/include/soc/soc_caps.h +++ b/components/soc/esp32c6/include/soc/soc_caps.h @@ -281,7 +281,6 @@ /*-------------------------- MMU CAPS ----------------------------------------*/ #define SOC_MMU_PAGE_SIZE_CONFIGURABLE (1) -#define SOC_MMU_PAGE_SIZE_8KB_SUPPORTED (1) #define SOC_MMU_PERIPH_NUM (1U) #define SOC_MMU_LINEAR_ADDRESS_REGION_NUM (1U) #define SOC_MMU_DI_VADDR_SHARED (1) /*!< D/I vaddr are shared */ diff --git a/components/soc/esp32c61/Kconfig.mmu b/components/soc/esp32c61/Kconfig.mmu new file mode 100644 index 0000000000..607c8ca7aa --- /dev/null +++ b/components/soc/esp32c61/Kconfig.mmu @@ -0,0 +1,22 @@ +# This Config is used for configure the MMU. +# Be configured based on flash size selection. +# Invisible to users. + +config MMU_PAGE_SIZE_8KB + bool + default n + +config MMU_PAGE_SIZE_16KB + bool + default y if ESPTOOLPY_FLASHSIZE_1MB + default n + +config MMU_PAGE_SIZE_32KB + bool + default y if ESPTOOLPY_FLASHSIZE_2MB + default n + +config MMU_PAGE_SIZE_64KB + bool + default y if !MMU_PAGE_SIZE_32KB && !MMU_PAGE_SIZE_16KB && !MMU_PAGE_SIZE_8KB + default n diff --git a/components/soc/esp32c61/include/soc/Kconfig.soc_caps.in b/components/soc/esp32c61/include/soc/Kconfig.soc_caps.in index c11837055b..1481f3204e 100644 --- a/components/soc/esp32c61/include/soc/Kconfig.soc_caps.in +++ b/components/soc/esp32c61/include/soc/Kconfig.soc_caps.in @@ -635,10 +635,6 @@ config SOC_MMU_PAGE_SIZE_CONFIGURABLE bool default y -config SOC_MMU_PAGE_SIZE_8KB_SUPPORTED - bool - default y - config SOC_MMU_PERIPH_NUM int default 1 diff --git a/components/soc/esp32c61/include/soc/soc_caps.h b/components/soc/esp32c61/include/soc/soc_caps.h index f842a0169f..cc7c7408de 100644 --- a/components/soc/esp32c61/include/soc/soc_caps.h +++ b/components/soc/esp32c61/include/soc/soc_caps.h @@ -260,7 +260,6 @@ /*-------------------------- MMU CAPS ----------------------------------------*/ #define SOC_MMU_PAGE_SIZE_CONFIGURABLE (1) -#define SOC_MMU_PAGE_SIZE_8KB_SUPPORTED (1) #define SOC_MMU_PERIPH_NUM (1U) #define SOC_MMU_LINEAR_ADDRESS_REGION_NUM (1U) #define SOC_MMU_DI_VADDR_SHARED (1) /*!< D/I vaddr are shared */ diff --git a/components/soc/esp32h2/Kconfig.mmu b/components/soc/esp32h2/Kconfig.mmu new file mode 100644 index 0000000000..607c8ca7aa --- /dev/null +++ b/components/soc/esp32h2/Kconfig.mmu @@ -0,0 +1,22 @@ +# This Config is used for configure the MMU. +# Be configured based on flash size selection. +# Invisible to users. + +config MMU_PAGE_SIZE_8KB + bool + default n + +config MMU_PAGE_SIZE_16KB + bool + default y if ESPTOOLPY_FLASHSIZE_1MB + default n + +config MMU_PAGE_SIZE_32KB + bool + default y if ESPTOOLPY_FLASHSIZE_2MB + default n + +config MMU_PAGE_SIZE_64KB + bool + default y if !MMU_PAGE_SIZE_32KB && !MMU_PAGE_SIZE_16KB && !MMU_PAGE_SIZE_8KB + default n diff --git a/components/soc/esp32h2/include/soc/Kconfig.soc_caps.in b/components/soc/esp32h2/include/soc/Kconfig.soc_caps.in index 0f529c8638..b271bf933c 100644 --- a/components/soc/esp32h2/include/soc/Kconfig.soc_caps.in +++ b/components/soc/esp32h2/include/soc/Kconfig.soc_caps.in @@ -451,10 +451,6 @@ config SOC_MMU_PAGE_SIZE_CONFIGURABLE bool default y -config SOC_MMU_PAGE_SIZE_8KB_SUPPORTED - bool - default y - config SOC_MMU_PERIPH_NUM int default 1 diff --git a/components/soc/esp32h2/include/soc/soc_caps.h b/components/soc/esp32h2/include/soc/soc_caps.h index 66d7f68926..adcdb5f21b 100644 --- a/components/soc/esp32h2/include/soc/soc_caps.h +++ b/components/soc/esp32h2/include/soc/soc_caps.h @@ -189,7 +189,6 @@ /*-------------------------- MMU CAPS ----------------------------------------*/ #define SOC_MMU_PAGE_SIZE_CONFIGURABLE (1) -#define SOC_MMU_PAGE_SIZE_8KB_SUPPORTED (1) #define SOC_MMU_PERIPH_NUM (1U) #define SOC_MMU_LINEAR_ADDRESS_REGION_NUM (1U) #define SOC_MMU_DI_VADDR_SHARED (1) /*!< D/I vaddr are shared */ diff --git a/components/soc/esp32h21/Kconfig.mmu b/components/soc/esp32h21/Kconfig.mmu new file mode 100644 index 0000000000..607c8ca7aa --- /dev/null +++ b/components/soc/esp32h21/Kconfig.mmu @@ -0,0 +1,22 @@ +# This Config is used for configure the MMU. +# Be configured based on flash size selection. +# Invisible to users. + +config MMU_PAGE_SIZE_8KB + bool + default n + +config MMU_PAGE_SIZE_16KB + bool + default y if ESPTOOLPY_FLASHSIZE_1MB + default n + +config MMU_PAGE_SIZE_32KB + bool + default y if ESPTOOLPY_FLASHSIZE_2MB + default n + +config MMU_PAGE_SIZE_64KB + bool + default y if !MMU_PAGE_SIZE_32KB && !MMU_PAGE_SIZE_16KB && !MMU_PAGE_SIZE_8KB + default n diff --git a/components/soc/esp32h21/include/soc/Kconfig.soc_caps.in b/components/soc/esp32h21/include/soc/Kconfig.soc_caps.in index 0be8b044b0..33b4217b36 100644 --- a/components/soc/esp32h21/include/soc/Kconfig.soc_caps.in +++ b/components/soc/esp32h21/include/soc/Kconfig.soc_caps.in @@ -355,10 +355,6 @@ config SOC_MMU_PAGE_SIZE_CONFIGURABLE bool default y -config SOC_MMU_PAGE_SIZE_8KB_SUPPORTED - bool - default y - config SOC_MMU_PERIPH_NUM int default 1 diff --git a/components/soc/esp32h21/include/soc/soc_caps.h b/components/soc/esp32h21/include/soc/soc_caps.h index 07da7d3d9c..013a772d23 100644 --- a/components/soc/esp32h21/include/soc/soc_caps.h +++ b/components/soc/esp32h21/include/soc/soc_caps.h @@ -171,7 +171,6 @@ /*-------------------------- MMU CAPS ----------------------------------------*/ #define SOC_MMU_PAGE_SIZE_CONFIGURABLE (1) -#define SOC_MMU_PAGE_SIZE_8KB_SUPPORTED (1) #define SOC_MMU_PERIPH_NUM (1U) #define SOC_MMU_LINEAR_ADDRESS_REGION_NUM (1U) #define SOC_MMU_DI_VADDR_SHARED (1) /*!< D/I vaddr are shared */ diff --git a/components/soc/esp32h4/Kconfig.mmu b/components/soc/esp32h4/Kconfig.mmu new file mode 100644 index 0000000000..607c8ca7aa --- /dev/null +++ b/components/soc/esp32h4/Kconfig.mmu @@ -0,0 +1,22 @@ +# This Config is used for configure the MMU. +# Be configured based on flash size selection. +# Invisible to users. + +config MMU_PAGE_SIZE_8KB + bool + default n + +config MMU_PAGE_SIZE_16KB + bool + default y if ESPTOOLPY_FLASHSIZE_1MB + default n + +config MMU_PAGE_SIZE_32KB + bool + default y if ESPTOOLPY_FLASHSIZE_2MB + default n + +config MMU_PAGE_SIZE_64KB + bool + default y if !MMU_PAGE_SIZE_32KB && !MMU_PAGE_SIZE_16KB && !MMU_PAGE_SIZE_8KB + default n diff --git a/components/soc/esp32h4/include/soc/Kconfig.soc_caps.in b/components/soc/esp32h4/include/soc/Kconfig.soc_caps.in index 67834651fc..3441e12bdc 100644 --- a/components/soc/esp32h4/include/soc/Kconfig.soc_caps.in +++ b/components/soc/esp32h4/include/soc/Kconfig.soc_caps.in @@ -663,10 +663,6 @@ config SOC_MMU_PAGE_SIZE_CONFIGURABLE bool default y -config SOC_MMU_PAGE_SIZE_8KB_SUPPORTED - bool - default y - config SOC_MMU_PERIPH_NUM int default 1 diff --git a/components/soc/esp32h4/include/soc/soc_caps.h b/components/soc/esp32h4/include/soc/soc_caps.h index e02a3f537c..865cd1f365 100644 --- a/components/soc/esp32h4/include/soc/soc_caps.h +++ b/components/soc/esp32h4/include/soc/soc_caps.h @@ -291,7 +291,6 @@ /*-------------------------- MMU CAPS ----------------------------------------*/ #define SOC_MMU_PAGE_SIZE_CONFIGURABLE (1) -#define SOC_MMU_PAGE_SIZE_8KB_SUPPORTED (1) #define SOC_MMU_PERIPH_NUM (1U) #define SOC_MMU_LINEAR_ADDRESS_REGION_NUM (1U) #define SOC_MMU_DI_VADDR_SHARED (1) /*!< D/I vaddr are shared */ diff --git a/components/soc/esp32p4/Kconfig.mmu b/components/soc/esp32p4/Kconfig.mmu new file mode 100644 index 0000000000..6359517cec --- /dev/null +++ b/components/soc/esp32p4/Kconfig.mmu @@ -0,0 +1,7 @@ +# This Config is used for configure the MMU. +# Be configured based on flash size selection. +# Invisible to users. + +config MMU_PAGE_SIZE_64KB + bool + default y diff --git a/components/soc/esp32s2/Kconfig.mmu b/components/soc/esp32s2/Kconfig.mmu new file mode 100644 index 0000000000..6359517cec --- /dev/null +++ b/components/soc/esp32s2/Kconfig.mmu @@ -0,0 +1,7 @@ +# This Config is used for configure the MMU. +# Be configured based on flash size selection. +# Invisible to users. + +config MMU_PAGE_SIZE_64KB + bool + default y diff --git a/components/soc/esp32s3/Kconfig.mmu b/components/soc/esp32s3/Kconfig.mmu new file mode 100644 index 0000000000..6359517cec --- /dev/null +++ b/components/soc/esp32s3/Kconfig.mmu @@ -0,0 +1,7 @@ +# This Config is used for configure the MMU. +# Be configured based on flash size selection. +# Invisible to users. + +config MMU_PAGE_SIZE_64KB + bool + default y diff --git a/components/soc/esp32s31/Kconfig.mmu b/components/soc/esp32s31/Kconfig.mmu new file mode 100644 index 0000000000..7842bb8401 --- /dev/null +++ b/components/soc/esp32s31/Kconfig.mmu @@ -0,0 +1,26 @@ +# This Config is used for configure the MMU. +# Be configured based on flash size selection. +# Invisible to users. + +config MMU_PAGE_SIZE_16KB + bool + default y if ESPTOOLPY_FLASHSIZE_1MB + default n + +config MMU_PAGE_SIZE_32KB + bool + default y if ESPTOOLPY_FLASHSIZE_2MB + default n + +config MMU_PAGE_SIZE_64KB + bool + default y if !MMU_PAGE_SIZE_32KB && !MMU_PAGE_SIZE_16KB + default n + +config MMU_PAGE_SIZE_128KB + bool "128KB page size" + default n + +config MMU_PAGE_SIZE_256KB + bool "256KB page size" + default n diff --git a/components/soc/esp32s31/include/soc/Kconfig.soc_caps.in b/components/soc/esp32s31/include/soc/Kconfig.soc_caps.in index a6aa0963b8..64dfd0b625 100644 --- a/components/soc/esp32s31/include/soc/Kconfig.soc_caps.in +++ b/components/soc/esp32s31/include/soc/Kconfig.soc_caps.in @@ -539,6 +539,10 @@ config SOC_I2C_SUPPORT_SLEEP_RETENTION bool default y +config SOC_MMU_PAGE_SIZE_CONFIGURABLE + bool + default y + config SOC_MMU_PERIPH_NUM int default 2 diff --git a/components/soc/esp32s31/include/soc/ext_mem_defs.h b/components/soc/esp32s31/include/soc/ext_mem_defs.h index f936e724ed..ce40d9ce3f 100644 --- a/components/soc/esp32s31/include/soc/ext_mem_defs.h +++ b/components/soc/esp32s31/include/soc/ext_mem_defs.h @@ -32,13 +32,13 @@ extern "C" { #define SOC_DRAM0_CACHE_ADDRESS_HIGH SOC_IRAM0_CACHE_ADDRESS_HIGH //I/D share the same vaddr range #define SOC_IRAM_FLASH_ADDRESS_LOW 0x40000000 -#define SOC_IRAM_FLASH_ADDRESS_HIGH 0x44000000 +#define SOC_IRAM_FLASH_ADDRESS_HIGH (SOC_IRAM_FLASH_ADDRESS_LOW + ((SOC_MMU_PAGE_SIZE) * SOC_MMU_ENTRY_NUM)) //max 0x44000000 for nor, 0x50000000 for nand #define SOC_DRAM_FLASH_ADDRESS_LOW SOC_IRAM_FLASH_ADDRESS_LOW #define SOC_DRAM_FLASH_ADDRESS_HIGH SOC_IRAM_FLASH_ADDRESS_HIGH #define SOC_IRAM_PSRAM_ADDRESS_LOW 0x50000000 -#define SOC_IRAM_PSRAM_ADDRESS_HIGH 0x54000000 +#define SOC_IRAM_PSRAM_ADDRESS_HIGH (SOC_IRAM_PSRAM_ADDRESS_LOW + ((SOC_MMU_PAGE_SIZE) * SOC_MMU_ENTRY_NUM)) //max 0x54000000 for psram #define SOC_DRAM_PSRAM_ADDRESS_LOW SOC_IRAM_PSRAM_ADDRESS_LOW #define SOC_DRAM_PSRAM_ADDRESS_HIGH SOC_IRAM_PSRAM_ADDRESS_HIGH diff --git a/components/soc/esp32s31/include/soc/soc_caps.h b/components/soc/esp32s31/include/soc/soc_caps.h index 8d7b19677d..4f24105727 100644 --- a/components/soc/esp32s31/include/soc/soc_caps.h +++ b/components/soc/esp32s31/include/soc/soc_caps.h @@ -256,6 +256,7 @@ #define SOC_I2C_SUPPORT_SLEEP_RETENTION (1) /*-------------------------- MMU CAPS ----------------------------------------*/ +#define SOC_MMU_PAGE_SIZE_CONFIGURABLE (1) #define SOC_MMU_PERIPH_NUM (2U) #define SOC_MMU_LINEAR_ADDRESS_REGION_NUM (2U) #define SOC_MMU_DI_VADDR_SHARED (1) /*!< D/I vaddr are shared */ diff --git a/components/soc/linux/Kconfig.mmu b/components/soc/linux/Kconfig.mmu new file mode 100644 index 0000000000..6359517cec --- /dev/null +++ b/components/soc/linux/Kconfig.mmu @@ -0,0 +1,7 @@ +# This Config is used for configure the MMU. +# Be configured based on flash size selection. +# Invisible to users. + +config MMU_PAGE_SIZE_64KB + bool + default y From 8fc4f9c108fac4b9a9426b9add00ebb6272aeae2 Mon Sep 17 00:00:00 2001 From: armando Date: Mon, 20 Apr 2026 15:05:34 +0800 Subject: [PATCH 2/2] feat(cache): added cache invalidate all --- components/hal/esp32s31/include/hal/cache_ll.h | 15 +++++++++++++++ .../test_flash_utils/test_flash_utils.c | 4 ---- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/components/hal/esp32s31/include/hal/cache_ll.h b/components/hal/esp32s31/include/hal/cache_ll.h index 9fdd44413e..ea4100ea1c 100644 --- a/components/hal/esp32s31/include/hal/cache_ll.h +++ b/components/hal/esp32s31/include/hal/cache_ll.h @@ -460,6 +460,21 @@ static inline void cache_ll_invalidate_addr(uint32_t cache_level, cache_type_t t } } +/** + * @brief Invalidate all cache + * + * Invalidate all cache + * + * @param cache_level level of the cache + * @param type see `cache_type_t` + * @param cache_id id of the cache in this type and level + */ +__attribute__((always_inline)) +static inline void cache_ll_invalidate_all(uint32_t cache_level, cache_type_t type, uint32_t cache_id) +{ + Cache_Invalidate_All(CACHE_MAP_MASK); +} + /*------------------------------------------------------------------------------ * Writeback *----------------------------------------------------------------------------*/ diff --git a/components/spi_flash/test_apps/components/test_flash_utils/test_flash_utils.c b/components/spi_flash/test_apps/components/test_flash_utils/test_flash_utils.c index fac7dbbece..af643720b1 100644 --- a/components/spi_flash/test_apps/components/test_flash_utils/test_flash_utils.c +++ b/components/spi_flash/test_apps/components/test_flash_utils/test_flash_utils.c @@ -138,11 +138,7 @@ esp_err_t spi_flash_suspend_test_deinit(flash_test_handle_t *handle) void spi_flash_suspend_test_invalidate_cache(void) { -#if CONFIG_IDF_TARGET_ESP32S31 - Cache_Invalidate_All(CACHE_MAP_MASK); -#else cache_ll_invalidate_all(CACHE_LL_LEVEL_ALL, CACHE_TYPE_ALL, CACHE_LL_ID_ALL); -#endif } #endif // SOC_SPI_MEM_SUPPORT_AUTO_SUSPEND