From 3a4560ed40356a14fa6f3ed26774083f79fdf423 Mon Sep 17 00:00:00 2001 From: YAMAMOTO Takashi Date: Mon, 13 May 2024 20:42:14 +0900 Subject: [PATCH] esp32s3: make textheap return i-bus address consistently Perform I-D translation for extram as well. Also, use macros from soc.h. --- arch/xtensa/src/esp32s3/esp32s3_textheap.c | 44 ++++++++++++++++++++-- 1 file changed, 40 insertions(+), 4 deletions(-) diff --git a/arch/xtensa/src/esp32s3/esp32s3_textheap.c b/arch/xtensa/src/esp32s3/esp32s3_textheap.c index e7a0967f6e..728749ee14 100644 --- a/arch/xtensa/src/esp32s3/esp32s3_textheap.c +++ b/arch/xtensa/src/esp32s3/esp32s3_textheap.c @@ -45,7 +45,7 @@ #error "No suitable heap available. Enable ESP32S3_RTC_HEAP." #endif -#define D_I_BUS_OFFSET 0x6f0000 +#define EXTRAM_D_I_BUS_OFFSET 0x6000000 /**************************************************************************** * Public Functions @@ -92,7 +92,19 @@ void *up_textheap_memalign(size_t align, size_t size) * can access it from the Instruction bus. */ - ret += D_I_BUS_OFFSET; + uintptr_t addr = (uintptr_t)ret; + if (SOC_DIRAM_DRAM_LOW <= addr && addr <= SOC_DIRAM_DRAM_HIGH) + { + addr = MAP_DRAM_TO_IRAM(addr); + } + else + { + /* extram */ + + addr += EXTRAM_D_I_BUS_OFFSET; + } + + ret = (void *)addr; } } @@ -122,7 +134,19 @@ void up_textheap_free(void *p) else #endif { - p -= D_I_BUS_OFFSET; + uintptr_t addr = (uintptr_t)p; + if (SOC_DIRAM_IRAM_LOW <= addr && addr <= SOC_DIRAM_IRAM_HIGH) + { + addr = MAP_IRAM_TO_DRAM(addr); + } + else + { + /* extram */ + + addr -= EXTRAM_D_I_BUS_OFFSET; + } + + p = (void *)addr; kmm_free(p); } } @@ -156,6 +180,18 @@ bool up_textheap_heapmember(void *p) } #endif - p -= D_I_BUS_OFFSET; + uintptr_t addr = (uintptr_t)p; + if (SOC_DIRAM_IRAM_LOW <= addr && addr <= SOC_DIRAM_IRAM_HIGH) + { + addr = MAP_IRAM_TO_DRAM(addr); + } + else + { + /* extram */ + + addr -= EXTRAM_D_I_BUS_OFFSET; + } + + p = (void *)addr; return kmm_heapmember(p); }