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

@@ -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);