soc_memory_layout.c 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. // Copyright 2010-2016 Espressif Systems (Shanghai) PTE LTD
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. // http://www.apache.org/licenses/LICENSE-2.0
  7. //
  8. // Unless required by applicable law or agreed to in writing, software
  9. // distributed under the License is distributed on an "AS IS" BASIS,
  10. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. // See the License for the specific language governing permissions and
  12. // limitations under the License.
  13. #ifndef BOOTLOADER_BUILD
  14. #include <stdlib.h>
  15. #include <stdint.h>
  16. #include "soc/soc.h"
  17. #include "soc/soc_memory_layout.h"
  18. #include "esp_heap_caps.h"
  19. #include "sdkconfig.h"
  20. /* Memory layout for ESP32 SoC */
  21. /*
  22. Memory type descriptors. These describe the capabilities of a type of memory in the SoC. Each type of memory
  23. map consist of one or more regions in the address space.
  24. Each type contains an array of prioritised capabilities; types with later entries are only taken if earlier
  25. ones can't fulfill the memory request.
  26. The prioritised capabilities work roughly like this:
  27. - For a normal malloc (MALLOC_CAP_DEFAULT), give away the DRAM-only memory first, then pass off any dual-use IRAM regions,
  28. finally eat into the application memory.
  29. - For a malloc where 32-bit-aligned-only access is okay, first allocate IRAM, then DRAM, finally application IRAM.
  30. - Application mallocs (PIDx) will allocate IRAM first, if possible, then DRAM.
  31. - Most other malloc caps only fit in one region anyway.
  32. */
  33. const soc_memory_type_desc_t soc_memory_types[] = {
  34. //Type 0: DRAM
  35. { "DRAM", { MALLOC_CAP_8BIT|MALLOC_CAP_DEFAULT, MALLOC_CAP_INTERNAL|MALLOC_CAP_DMA|MALLOC_CAP_32BIT, 0 }, false, false},
  36. // Type 1: DRAM used for startup stacks
  37. { "DRAM", { MALLOC_CAP_8BIT|MALLOC_CAP_DEFAULT, MALLOC_CAP_INTERNAL|MALLOC_CAP_DMA|MALLOC_CAP_32BIT, 0 }, false, true},
  38. //Type 2: DRAM which has an alias on the I-port
  39. { "D/IRAM", { 0, MALLOC_CAP_DMA|MALLOC_CAP_8BIT|MALLOC_CAP_INTERNAL|MALLOC_CAP_DEFAULT, MALLOC_CAP_32BIT|MALLOC_CAP_EXEC }, true, false},
  40. //Type 3: IRAM
  41. //In ESP32S2beta, All IRAM region are available by D-port (D/IRAM).
  42. { "IRAM", { MALLOC_CAP_EXEC|MALLOC_CAP_32BIT|MALLOC_CAP_INTERNAL, 0, 0 }, false, false},
  43. //Type 4: SPI SRAM data
  44. //TODO, in fact, part of them support EDMA, to be supported.
  45. { "SPIRAM", { MALLOC_CAP_SPIRAM|MALLOC_CAP_DEFAULT, 0, MALLOC_CAP_8BIT|MALLOC_CAP_32BIT}, false, false},
  46. //Type 5: SPI SRAM data from AHB DBUS3, slower than normal
  47. //TODO, add a bit to control the access of it
  48. #if CONFIG_USE_AHB_DBUS3_ACCESS_SPIRAM
  49. { "SPIRAM(Slow)", { MALLOC_CAP_SPIRAM|MALLOC_CAP_DEFAULT, 0, MALLOC_CAP_8BIT|MALLOC_CAP_32BIT}, false, false},
  50. #endif
  51. };
  52. const size_t soc_memory_type_count = sizeof(soc_memory_types)/sizeof(soc_memory_type_desc_t);
  53. /*
  54. Region descriptors. These describe all regions of memory available, and map them to a type in the above type.
  55. Because of requirements in the coalescing code which merges adjacent regions, this list should always be sorted
  56. from low to high start address.
  57. */
  58. const soc_memory_region_t soc_memory_regions[] = {
  59. #ifdef CONFIG_SPIRAM
  60. { SOC_EXTRAM_DATA_LOW, SOC_EXTRAM_DATA_HIGH - SOC_EXTRAM_DATA_LOW, 4, 0}, //SPI SRAM, if available
  61. #if CONFIG_USE_AHB_DBUS3_ACCESS_SPIRAM
  62. { SOC_SLOW_EXTRAM_DATA_LOW, SOC_SLOW_EXTRAM_DATA_HIGH - SOC_SLOW_EXTRAM_DATA_LOW, 5, 0}, //SPI SRAM, if available
  63. #endif
  64. #endif
  65. #if CONFIG_ESP32S2_INSTRUCTION_CACHE_8KB
  66. #if CONFIG_ESP32S2_DATA_CACHE_0KB
  67. { 0x3FFB2000, 0x2000, 2, 0x40022000}, //Block 1, can be use as I/D cache memory
  68. { 0x3FFB4000, 0x2000, 2, 0x40024000}, //Block 2, can be use as D cache memory
  69. { 0x3FFB6000, 0x2000, 2, 0x40026000}, //Block 3, can be use as D cache memory
  70. #elif CONFIG_ESP32S2_DATA_CACHE_8KB
  71. { 0x3FFB4000, 0x2000, 2, 0x40024000}, //Block 2, can be use as D cache memory
  72. { 0x3FFB6000, 0x2000, 2, 0x40026000}, //Block 3, can be use as D cache memory
  73. #else
  74. { 0x3FFB6000, 0x2000, 2, 0x40026000}, //Block 3, can be use as D cache memory
  75. #endif
  76. #else
  77. #if CONFIG_ESP32S2_DATA_CACHE_0KB
  78. { 0x3FFB4000, 0x2000, 2, 0x40024000}, //Block 2, can be use as D cache memory
  79. { 0x3FFB6000, 0x2000, 2, 0x40026000}, //Block 3, can be use as D cache memory
  80. #elif CONFIG_ESP32S2_DATA_CACHE_8KB
  81. { 0x3FFB6000, 0x2000, 2, 0x40026000}, //Block 3, can be use as D cache memory
  82. #endif
  83. #endif
  84. { 0x3FFB8000, 0x4000, 2, 0x40028000}, //Block 4, can be remapped to ROM, can be used as trace memory
  85. { 0x3FFBC000, 0x4000, 2, 0x4002C000}, //Block 5, can be remapped to ROM, can be used as trace memory
  86. { 0x3FFC0000, 0x4000, 2, 0x40030000}, //Block 6, can be used as trace memory
  87. { 0x3FFC4000, 0x4000, 2, 0x40034000}, //Block 7, can be used as trace memory
  88. { 0x3FFC8000, 0x4000, 2, 0x40038000}, //Block 8, can be used as trace memory
  89. { 0x3FFCC000, 0x4000, 2, 0x4003C000}, //Block 9, can be used as trace memory
  90. { 0x3FFD0000, 0x4000, 2, 0x40040000}, //Block 10, can be used as trace memory
  91. { 0x3FFD4000, 0x4000, 2, 0x40044000}, //Block 11, can be used as trace memory
  92. { 0x3FFD8000, 0x4000, 2, 0x40048000}, //Block 12, can be used as trace memory
  93. { 0x3FFDC000, 0x4000, 2, 0x4004C000}, //Block 13, can be used as trace memory
  94. { 0x3FFE0000, 0x4000, 2, 0x40050000}, //Block 14, can be used as trace memory
  95. { 0x3FFE4000, 0x4000, 2, 0x40054000}, //Block 15, can be used as trace memory
  96. { 0x3FFE8000, 0x4000, 2, 0x40058000}, //Block 16, can be used as trace memory
  97. { 0x3FFEC000, 0x4000, 2, 0x4005C000}, //Block 17, can be used as trace memory
  98. { 0x3FFF0000, 0x4000, 2, 0x40060000}, //Block 18, can be used for MAC dump, can be used as trace memory
  99. { 0x3FFF4000, 0x4000, 2, 0x40064000}, //Block 19, can be used for MAC dump, can be used as trace memory
  100. { 0x3FFF8000, 0x4000, 2, 0x40068000}, //Block 20, can be used for MAC dump, can be used as trace memory
  101. { 0x3FFFC000, 0x4000, 1, 0x4006C000}, //Block 21, can be used for MAC dump, can be used as trace memory, used for startup stack
  102. };
  103. const size_t soc_memory_region_count = sizeof(soc_memory_regions)/sizeof(soc_memory_region_t);
  104. extern int _data_start_xtos;
  105. /* Reserved memory regions
  106. These are removed from the soc_memory_regions array when heaps are created.
  107. */
  108. //ROM data region
  109. SOC_RESERVE_MEMORY_REGION(0x3fffc000, (intptr_t)&_data_start_xtos, rom_data_region);
  110. // TODO: soc_memory_layout: handle trace memory regions - IDF-750
  111. #ifdef CONFIG_SPIRAM
  112. 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
  113. #if CONFIG_USE_AHB_DBUS3_ACCESS_SPIRAM
  114. SOC_RESERVE_MEMORY_REGION( SOC_SLOW_EXTRAM_DATA_LOW, SOC_SLOW_EXTRAM_DATA_HIGH, extram_slow_data_region); //SPI RAM(Slow) gets added later if needed, in spiram.c; reserve it for now
  115. #endif
  116. #endif
  117. #endif