Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a few optional text heap APIs to support esp32s3 #12355

Merged
merged 2 commits into from
May 20, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions arch/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,18 @@ config ARCH_HAVE_TEXT_HEAP
---help---
Special memory region for dynamic code loading

config ARCH_TEXT_HEAP_SEPARATE_DATA_ADDRESS
xiaoxiang781216 marked this conversation as resolved.
Show resolved Hide resolved
bool
default n
---help---
Textheap might have separate instruction/data mappings

config ARCH_TEXT_HEAP_WORD_ALIGNED_READ
xiaoxiang781216 marked this conversation as resolved.
Show resolved Hide resolved
bool
default n
---help---
Loads from the instruction mapping of textheap need to be word-aligned

config ARCH_HAVE_DATA_HEAP
bool
default n
Expand Down
2 changes: 2 additions & 0 deletions arch/xtensa/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ config ARCH_CHIP_ESP32S3
select ARCH_HAVE_MULTICPU
select ARCH_HAVE_RESET
select ARCH_HAVE_TEXT_HEAP
select ARCH_TEXT_HEAP_SEPARATE_DATA_ADDRESS
select ARCH_TEXT_HEAP_WORD_ALIGNED_READ
select ARCH_HAVE_TESTSET
select ARCH_VECNOTIRQ
select LIBC_PREVENT_STRING_KERNEL
Expand Down
70 changes: 54 additions & 16 deletions arch/xtensa/src/esp32s3/esp32s3_textheap.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,13 @@
#include <debug.h>
#include <nuttx/kmalloc.h>

#include "hal/cache_hal.h"
#include "hardware/esp32s3_soc.h"

#ifdef CONFIG_ESP32S3_RTC_HEAP
# include "esp32s3_rtcheap.h"
#endif
#include "esp32s3_spiram.h"

/****************************************************************************
* Pre-processor Definitions
Expand All @@ -45,6 +47,9 @@
#error "No suitable heap available. Enable ESP32S3_RTC_HEAP."
#endif

#define EXTRAM_INSTRUCTION_BUS_LOW 0x42000000
#define EXTRAM_INSTRUCTION_BUS_HIGH 0x44000000

#define EXTRAM_D_I_BUS_OFFSET 0x6000000

/****************************************************************************
Expand Down Expand Up @@ -134,19 +139,7 @@ void up_textheap_free(void *p)
else
#endif
{
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;
p = up_textheap_data_address(p);
kmm_free(p);
}
}
Expand Down Expand Up @@ -180,18 +173,63 @@ bool up_textheap_heapmember(void *p)
}
#endif

p = up_textheap_data_address(p);
return kmm_heapmember(p);
}

/****************************************************************************
* Name: up_textheap_data_address
*
* Description:
* If an instruction bus address is specified, return the corresponding
* data bus address. Otherwise, return the given address as it is.
*
* For some platforms, up_textheap_memalign() might return memory regions
* with separate instruction/data bus mappings. In that case,
* up_textheap_memalign() returns the address of the instruction bus
* mapping.
* The instruction bus mapping might provide only limited data access.
* (For example, only read-only, word-aligned access.)
* You can use up_textheap_data_address() to query the corresponding data
* bus mapping.
*
****************************************************************************/

FAR void *up_textheap_data_address(FAR void *p)
{
uintptr_t addr = (uintptr_t)p;
if (SOC_DIRAM_IRAM_LOW <= addr && addr < SOC_DIRAM_IRAM_HIGH)
{
addr = MAP_IRAM_TO_DRAM(addr);
}
else
else if (EXTRAM_INSTRUCTION_BUS_LOW <= addr &&
addr < EXTRAM_INSTRUCTION_BUS_HIGH)
{
/* extram */

addr -= EXTRAM_D_I_BUS_OFFSET;
}

p = (void *)addr;
return kmm_heapmember(p);
return (FAR void *)addr;
}

/****************************************************************************
* Name: up_textheap_data_sync
*
* Description:
* Ensure modifications made on the data bus addresses (the addresses
* returned by up_textheap_data_address) fully visible on the corresponding
* instruction bus addresses.
*
****************************************************************************/

IRAM_ATTR void up_textheap_data_sync(void)
{
irqstate_t flags = enter_critical_section();

esp_spiram_writeback_cache();
cache_hal_disable(CACHE_TYPE_INSTRUCTION);
cache_hal_enable(CACHE_TYPE_INSTRUCTION);

leave_critical_section(flags);
}
44 changes: 44 additions & 0 deletions include/nuttx/arch.h
Original file line number Diff line number Diff line change
Expand Up @@ -781,6 +781,50 @@ void up_textheap_free(FAR void *p);
bool up_textheap_heapmember(FAR void *p);
#endif

/****************************************************************************
* Name: up_textheap_data_address
*
* Description:
* If an instruction bus address is specified, return the corresponding
* data bus address. Otherwise, return the given address as it is.
*
* For some platforms, up_textheap_memalign() might return memory regions
* with separate instruction/data bus mappings. In that case,
* up_textheap_memalign() returns the address of the instruction bus
* mapping.
* The instruction bus mapping might provide only limited data access.
* (For example, only read-only, word-aligned access.)
* You can use up_textheap_data_address() to query the corresponding data
* bus mapping.
*
****************************************************************************/

#if defined(CONFIG_ARCH_USE_TEXT_HEAP)
#if defined(CONFIG_ARCH_TEXT_HEAP_SEPARATE_DATA_ADDRESS)
FAR void *up_textheap_data_address(FAR void *p);
#else
#define up_textheap_data_address(p) ((FAR void *)p)
#endif
#endif

/****************************************************************************
* Name: up_textheap_data_sync
*
* Description:
* Ensure modifications made on the data bus addresses (the addresses
* returned by up_textheap_data_address) fully visible on the corresponding
* instruction bus addresses.
*
****************************************************************************/

#if defined(CONFIG_ARCH_USE_TEXT_HEAP)
#if defined(CONFIG_ARCH_TEXT_HEAP_SEPARATE_DATA_ADDRESS)
void up_textheap_data_sync(void);
#else
#define up_textheap_data_sync() do {} while (0)
#endif
#endif

/****************************************************************************
* Name: up_dataheap_memalign
*
Expand Down
Loading