soc: move reserved regions out of memory_layout_utils.c

These definitions have ended up being chip specific. Moving them into
respective soc_memory_layout.c makes the whole picture of memory
regions easier to see, and also makes adding support for new chips
easier.
This commit is contained in:
Ivan Grokhotkov 2020-01-21 18:52:59 +01:00
parent 81f0e7d90f
commit 354ce68dce
3 changed files with 21 additions and 33 deletions

View file

@ -177,4 +177,13 @@ SOC_RESERVE_MEMORY_REGION(0x3fffc000, 0x40000000, trace_mem); //Reserve trace me
SOC_RESERVE_MEMORY_REGION(SOC_EXTRAM_DATA_LOW, SOC_EXTRAM_DATA_LOW + RESERVE_SPIRAM_SIZE, spi_ram); //SPI RAM gets added later if needed, in spiram.c; reserve it for now
#endif
extern int _data_start, _heap_start, _iram_start, _iram_end;
// Static data region. DRAM used by data+bss and possibly rodata
SOC_RESERVE_MEMORY_REGION((intptr_t)&_data_start, (intptr_t)&_heap_start, dram_data);
// IRAM code region
// ESP32 has an IRAM-only region 0x4008_0000 - 0x4009_FFFF, reserve the used part
SOC_RESERVE_MEMORY_REGION((intptr_t)&_iram_start, (intptr_t)&_iram_end, iram_code);
#endif /* BOOTLOADER_BUILD */

View file

@ -109,6 +109,8 @@ const size_t soc_memory_region_count = sizeof(soc_memory_regions)/sizeof(soc_mem
extern int _dram0_rtos_reserved_start;
extern int _data_start, _heap_start, _iram_start, _iram_end;
/* Reserved memory regions
These are removed from the soc_memory_regions array when heaps are created.
@ -116,7 +118,13 @@ extern int _dram0_rtos_reserved_start;
//ROM data region
SOC_RESERVE_MEMORY_REGION((intptr_t)&_dram0_rtos_reserved_start, SOC_BYTE_ACCESSIBLE_HIGH, rom_data_region);
// TODO: soc_memory_layout: handle trace memory regions - IDF-750
// Static data region. DRAM used by data+bss and possibly rodata
SOC_RESERVE_MEMORY_REGION((intptr_t)&_data_start, (intptr_t)&_heap_start, dram_data);
// ESP32S2 has a big D/IRAM region, the part used by code is reserved
// The address of the D/I bus are in the same order, directly shift IRAM address to get reserved DRAM address
#define I_D_OFFSET (SOC_IRAM_LOW - SOC_DRAM_LOW)
SOC_RESERVE_MEMORY_REGION((intptr_t)&_iram_start - I_D_OFFSET, (intptr_t)&_iram_end - I_D_OFFSET, iram_code);
#ifdef CONFIG_SPIRAM
SOC_RESERVE_MEMORY_REGION( SOC_EXTRAM_DATA_LOW, SOC_EXTRAM_DATA_HIGH, extram_data_region); //SPI RAM gets added later if needed, in spiram.c; reserve it for now

View file

@ -26,20 +26,10 @@ static const char *TAG = "memory_layout";
extern soc_reserved_region_t soc_reserved_memory_region_start;
extern soc_reserved_region_t soc_reserved_memory_region_end;
/*
These variables have the start and end of the data and static IRAM
area used by the program. Defined in the linker script.
*/
extern int _data_start, _heap_start, _iram_start, _iram_end;
/* static DRAM & IRAM chunks */
static const size_t EXTRA_RESERVED_REGIONS = 2;
static size_t s_get_num_reserved_regions(void)
{
return ( ( &soc_reserved_memory_region_end
- &soc_reserved_memory_region_start ) +
EXTRA_RESERVED_REGIONS );
return ( &soc_reserved_memory_region_end
- &soc_reserved_memory_region_start );
}
size_t soc_get_available_memory_region_max_count(void)
@ -63,26 +53,7 @@ static int s_compare_reserved_regions(const void *a, const void *b)
*/
static void s_prepare_reserved_regions(soc_reserved_region_t *reserved, size_t count)
{
memcpy(reserved + EXTRA_RESERVED_REGIONS,
&soc_reserved_memory_region_start,
(count - EXTRA_RESERVED_REGIONS) * sizeof(soc_reserved_region_t));
/* Add the EXTRA_RESERVED_REGIONS at the beginning */
reserved[0].start = (intptr_t)&_data_start; /* DRAM used by data+bss and possibly rodata */
reserved[0].end = (intptr_t)&_heap_start;
#if CONFIG_IDF_TARGET_ESP32
//ESP32 has a IRAM-only region 0x4008_0000 - 0x4009_FFFF, protect the used part
reserved[1].start = (intptr_t)&_iram_start; /* IRAM used by code */
reserved[1].end = (intptr_t)&_iram_end;
#elif CONFIG_IDF_TARGET_ESP32S2
//ESP32S2 has a big D/IRAM region, the part used by code is reserved
//The address of the D/I bus are in the same order, directly shift IRAM address to get reserved DRAM address
const uint32_t i_d_offset = SOC_IRAM_LOW - SOC_DRAM_LOW;
reserved[1].start = (intptr_t)&_iram_start - i_d_offset; /* IRAM used by code */
reserved[1].end = (intptr_t)&_iram_end - i_d_offset;
#else
# error chip not implemented!
#endif
memcpy(reserved, &soc_reserved_memory_region_start, count * sizeof(soc_reserved_region_t));
/* Sort by starting address */
qsort(reserved, count, sizeof(soc_reserved_region_t), s_compare_reserved_regions);