2019-12-26 07:25:24 +00:00
// Copyright 2010-2019 Espressif Systems (Shanghai) PTE LTD
2019-04-03 09:08:02 +00:00
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
# ifndef BOOTLOADER_BUILD
# include <stdlib.h>
# include <stdint.h>
2019-12-26 07:25:24 +00:00
# include "sdkconfig.h"
2019-04-03 09:08:02 +00:00
# include "soc/soc.h"
# include "soc/soc_memory_layout.h"
# include "esp_heap_caps.h"
/* Memory layout for ESP32 SoC */
/*
Memory type descriptors . These describe the capabilities of a type of memory in the SoC . Each type of memory
map consist of one or more regions in the address space .
Each type contains an array of prioritised capabilities ; types with later entries are only taken if earlier
ones can ' t fulfill the memory request .
The prioritised capabilities work roughly like this :
- For a normal malloc ( MALLOC_CAP_DEFAULT ) , give away the DRAM - only memory first , then pass off any dual - use IRAM regions ,
finally eat into the application memory .
- For a malloc where 32 - bit - aligned - only access is okay , first allocate IRAM , then DRAM , finally application IRAM .
- Application mallocs ( PIDx ) will allocate IRAM first , if possible , then DRAM .
- Most other malloc caps only fit in one region anyway .
*/
const soc_memory_type_desc_t soc_memory_types [ ] = {
//Type 0: DRAM
{ " DRAM " , { MALLOC_CAP_8BIT | MALLOC_CAP_DEFAULT , MALLOC_CAP_INTERNAL | MALLOC_CAP_DMA | MALLOC_CAP_32BIT , 0 } , false , false } ,
// Type 1: DRAM used for startup stacks
{ " DRAM " , { MALLOC_CAP_8BIT | MALLOC_CAP_DEFAULT , MALLOC_CAP_INTERNAL | MALLOC_CAP_DMA | MALLOC_CAP_32BIT , 0 } , false , true } ,
//Type 2: DRAM which has an alias on the I-port
2019-09-11 10:27:10 +00:00
{ " D/IRAM " , { 0 , MALLOC_CAP_DMA | MALLOC_CAP_8BIT | MALLOC_CAP_INTERNAL | MALLOC_CAP_DEFAULT , MALLOC_CAP_32BIT | MALLOC_CAP_EXEC } , true , false } ,
2019-04-03 09:08:02 +00:00
//Type 3: IRAM
2020-01-17 03:47:08 +00:00
//In ESP32S2, All IRAM region are available by D-port (D/IRAM).
2019-04-03 09:08:02 +00:00
{ " IRAM " , { MALLOC_CAP_EXEC | MALLOC_CAP_32BIT | MALLOC_CAP_INTERNAL , 0 , 0 } , false , false } ,
//Type 4: SPI SRAM data
//TODO, in fact, part of them support EDMA, to be supported.
{ " SPIRAM " , { MALLOC_CAP_SPIRAM | MALLOC_CAP_DEFAULT , 0 , MALLOC_CAP_8BIT | MALLOC_CAP_32BIT } , false , false } ,
} ;
const size_t soc_memory_type_count = sizeof ( soc_memory_types ) / sizeof ( soc_memory_type_desc_t ) ;
/*
Region descriptors . These describe all regions of memory available , and map them to a type in the above type .
Because of requirements in the coalescing code which merges adjacent regions , this list should always be sorted
from low to high start address .
*/
const soc_memory_region_t soc_memory_regions [ ] = {
2019-06-05 04:34:19 +00:00
# ifdef CONFIG_SPIRAM
2019-04-03 09:08:02 +00:00
{ SOC_EXTRAM_DATA_LOW , SOC_EXTRAM_DATA_HIGH - SOC_EXTRAM_DATA_LOW , 4 , 0 } , //SPI SRAM, if available
# endif
2019-06-10 07:07:12 +00:00
# if CONFIG_ESP32S2_INSTRUCTION_CACHE_8KB
# if CONFIG_ESP32S2_DATA_CACHE_0KB
2019-09-11 10:27:10 +00:00
{ 0x3FFB2000 , 0x2000 , 2 , 0x40022000 } , //Block 1, can be use as I/D cache memory
{ 0x3FFB4000 , 0x2000 , 2 , 0x40024000 } , //Block 2, can be use as D cache memory
{ 0x3FFB6000 , 0x2000 , 2 , 0x40026000 } , //Block 3, can be use as D cache memory
2019-06-10 07:07:12 +00:00
# elif CONFIG_ESP32S2_DATA_CACHE_8KB
2019-09-11 10:27:10 +00:00
{ 0x3FFB4000 , 0x2000 , 2 , 0x40024000 } , //Block 2, can be use as D cache memory
{ 0x3FFB6000 , 0x2000 , 2 , 0x40026000 } , //Block 3, can be use as D cache memory
2019-04-03 09:08:02 +00:00
# else
2019-09-11 10:27:10 +00:00
{ 0x3FFB6000 , 0x2000 , 2 , 0x40026000 } , //Block 3, can be use as D cache memory
2019-04-03 09:08:02 +00:00
# endif
# else
2019-06-10 07:07:12 +00:00
# if CONFIG_ESP32S2_DATA_CACHE_0KB
2019-09-11 10:27:10 +00:00
{ 0x3FFB4000 , 0x2000 , 2 , 0x40024000 } , //Block 2, can be use as D cache memory
{ 0x3FFB6000 , 0x2000 , 2 , 0x40026000 } , //Block 3, can be use as D cache memory
2019-06-10 07:07:12 +00:00
# elif CONFIG_ESP32S2_DATA_CACHE_8KB
2019-09-11 10:27:10 +00:00
{ 0x3FFB6000 , 0x2000 , 2 , 0x40026000 } , //Block 3, can be use as D cache memory
2019-04-03 09:08:02 +00:00
# endif
# endif
2019-09-11 10:27:10 +00:00
{ 0x3FFB8000 , 0x4000 , 2 , 0x40028000 } , //Block 4, can be remapped to ROM, can be used as trace memory
{ 0x3FFBC000 , 0x4000 , 2 , 0x4002C000 } , //Block 5, can be remapped to ROM, can be used as trace memory
{ 0x3FFC0000 , 0x4000 , 2 , 0x40030000 } , //Block 6, can be used as trace memory
{ 0x3FFC4000 , 0x4000 , 2 , 0x40034000 } , //Block 7, can be used as trace memory
{ 0x3FFC8000 , 0x4000 , 2 , 0x40038000 } , //Block 8, can be used as trace memory
{ 0x3FFCC000 , 0x4000 , 2 , 0x4003C000 } , //Block 9, can be used as trace memory
2019-04-03 09:08:02 +00:00
2019-09-11 10:27:10 +00:00
{ 0x3FFD0000 , 0x4000 , 2 , 0x40040000 } , //Block 10, can be used as trace memory
{ 0x3FFD4000 , 0x4000 , 2 , 0x40044000 } , //Block 11, can be used as trace memory
{ 0x3FFD8000 , 0x4000 , 2 , 0x40048000 } , //Block 12, can be used as trace memory
{ 0x3FFDC000 , 0x4000 , 2 , 0x4004C000 } , //Block 13, can be used as trace memory
{ 0x3FFE0000 , 0x4000 , 2 , 0x40050000 } , //Block 14, can be used as trace memory
{ 0x3FFE4000 , 0x4000 , 2 , 0x40054000 } , //Block 15, can be used as trace memory
{ 0x3FFE8000 , 0x4000 , 2 , 0x40058000 } , //Block 16, can be used as trace memory
{ 0x3FFEC000 , 0x4000 , 2 , 0x4005C000 } , //Block 17, can be used as trace memory
{ 0x3FFF0000 , 0x4000 , 2 , 0x40060000 } , //Block 18, can be used for MAC dump, can be used as trace memory
{ 0x3FFF4000 , 0x4000 , 2 , 0x40064000 } , //Block 19, can be used for MAC dump, can be used as trace memory
{ 0x3FFF8000 , 0x4000 , 2 , 0x40068000 } , //Block 20, can be used for MAC dump, can be used as trace memory
2019-04-03 09:08:02 +00:00
{ 0x3FFFC000 , 0x4000 , 1 , 0x4006C000 } , //Block 21, can be used for MAC dump, can be used as trace memory, used for startup stack
} ;
const size_t soc_memory_region_count = sizeof ( soc_memory_regions ) / sizeof ( soc_memory_region_t ) ;
2019-12-26 07:25:24 +00:00
extern int _dram0_rtos_reserved_start ;
2020-01-21 17:52:59 +00:00
extern int _data_start , _heap_start , _iram_start , _iram_end ;
2019-04-03 09:08:02 +00:00
/* Reserved memory regions
These are removed from the soc_memory_regions array when heaps are created .
*/
2019-06-12 17:34:54 +00:00
//ROM data region
2019-12-26 07:25:24 +00:00
SOC_RESERVE_MEMORY_REGION ( ( intptr_t ) & _dram0_rtos_reserved_start , SOC_BYTE_ACCESSIBLE_HIGH , rom_data_region ) ;
2019-04-03 09:08:02 +00:00
2020-01-21 17:52:59 +00:00
// 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 ) ;
2019-04-03 09:08:02 +00:00
2019-06-05 04:34:19 +00:00
# ifdef CONFIG_SPIRAM
2019-06-12 17:34:54 +00:00
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
2019-04-03 09:08:02 +00:00
# endif
2020-01-22 12:40:57 +00:00
// Blocks 19 and 20 may be reserved for the trace memory
# if CONFIG_ESP32S2_TRACEMEM_RESERVE_DRAM > 0
SOC_RESERVE_MEMORY_REGION ( 0x3fffc000 - CONFIG_ESP32S2_TRACEMEM_RESERVE_DRAM , 0x3fffc000 , trace_mem ) ;
2019-04-03 09:08:02 +00:00
# endif
2020-01-22 12:40:57 +00:00
# endif // BOOTLOADER_BUILD