Merge branch 'feat/mmu_configurable_page_size_s31' into 'master'

mmu: supported configurable page size on s31

See merge request espressif/esp-idf!47193
This commit is contained in:
Armando (Dou Yiwen)
2026-04-21 03:31:16 +00:00
33 changed files with 288 additions and 64 deletions
@@ -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
@@ -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
*----------------------------------------------------------------------------*/
+47 -5
View File
@@ -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;
+7 -5
View File
@@ -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;
/**
+5 -23
View File
@@ -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
+7
View File
@@ -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
+18
View File
@@ -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
+7
View File
@@ -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
+7
View File
@@ -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
+22
View File
@@ -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
@@ -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
@@ -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 */
+22
View File
@@ -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
@@ -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
@@ -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 */
+22
View File
@@ -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
@@ -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
@@ -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 */
+22
View File
@@ -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
@@ -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
@@ -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 */
+22
View File
@@ -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
@@ -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
@@ -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 */
+7
View File
@@ -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
+7
View File
@@ -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
+7
View File
@@ -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
+26
View File
@@ -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
@@ -547,6 +547,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
@@ -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
@@ -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 */
+7
View File
@@ -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
@@ -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