qemu_common.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. /*
  2. * Copyright (c) 2015-2022, ARM Limited and Contributors. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #include <platform_def.h>
  7. #include <arch_helpers.h>
  8. #include <common/bl_common.h>
  9. #include <lib/xlat_tables/xlat_tables_v2.h>
  10. #include <plat/common/platform.h>
  11. #include "qemu_private.h"
  12. #define MAP_DEVICE0 MAP_REGION_FLAT(DEVICE0_BASE, \
  13. DEVICE0_SIZE, \
  14. MT_DEVICE | MT_RW | MT_SECURE)
  15. #ifdef DEVICE1_BASE
  16. #define MAP_DEVICE1 MAP_REGION_FLAT(DEVICE1_BASE, \
  17. DEVICE1_SIZE, \
  18. MT_DEVICE | MT_RW | MT_SECURE)
  19. #endif
  20. #ifdef DEVICE2_BASE
  21. #define MAP_DEVICE2 MAP_REGION_FLAT(DEVICE2_BASE, \
  22. DEVICE2_SIZE, \
  23. MT_DEVICE | MT_RW | MT_SECURE)
  24. #endif
  25. #define MAP_SHARED_RAM MAP_REGION_FLAT(SHARED_RAM_BASE, \
  26. SHARED_RAM_SIZE, \
  27. MT_DEVICE | MT_RW | MT_SECURE)
  28. #define MAP_BL32_MEM MAP_REGION_FLAT(BL32_MEM_BASE, BL32_MEM_SIZE, \
  29. MT_MEMORY | MT_RW | MT_SECURE)
  30. #define MAP_NS_DRAM0 MAP_REGION_FLAT(NS_DRAM0_BASE, NS_DRAM0_SIZE, \
  31. MT_MEMORY | MT_RW | MT_NS)
  32. #define MAP_FLASH0 MAP_REGION_FLAT(QEMU_FLASH0_BASE, QEMU_FLASH0_SIZE, \
  33. MT_MEMORY | MT_RO | MT_SECURE)
  34. #define MAP_FLASH1 MAP_REGION_FLAT(QEMU_FLASH1_BASE, QEMU_FLASH1_SIZE, \
  35. MT_MEMORY | MT_RO | MT_SECURE)
  36. /*
  37. * Table of regions for various BL stages to map using the MMU.
  38. * This doesn't include TZRAM as the 'mem_layout' argument passed to
  39. * arm_configure_mmu_elx() will give the available subset of that,
  40. */
  41. #ifdef IMAGE_BL1
  42. static const mmap_region_t plat_qemu_mmap[] = {
  43. MAP_FLASH0,
  44. MAP_FLASH1,
  45. MAP_SHARED_RAM,
  46. MAP_DEVICE0,
  47. #ifdef MAP_DEVICE1
  48. MAP_DEVICE1,
  49. #endif
  50. #ifdef MAP_DEVICE2
  51. MAP_DEVICE2,
  52. #endif
  53. {0}
  54. };
  55. #endif
  56. #ifdef IMAGE_BL2
  57. static const mmap_region_t plat_qemu_mmap[] = {
  58. MAP_FLASH0,
  59. MAP_FLASH1,
  60. MAP_SHARED_RAM,
  61. MAP_DEVICE0,
  62. #ifdef MAP_DEVICE1
  63. MAP_DEVICE1,
  64. #endif
  65. #ifdef MAP_DEVICE2
  66. MAP_DEVICE2,
  67. #endif
  68. MAP_NS_DRAM0,
  69. #if SPM_MM
  70. QEMU_SP_IMAGE_MMAP,
  71. #else
  72. MAP_BL32_MEM,
  73. #endif
  74. {0}
  75. };
  76. #endif
  77. #ifdef IMAGE_BL31
  78. static const mmap_region_t plat_qemu_mmap[] = {
  79. MAP_SHARED_RAM,
  80. MAP_DEVICE0,
  81. #ifdef MAP_DEVICE1
  82. MAP_DEVICE1,
  83. #endif
  84. #ifdef MAP_DEVICE2
  85. MAP_DEVICE2,
  86. #endif
  87. #if SPM_MM
  88. MAP_NS_DRAM0,
  89. QEMU_SPM_BUF_EL3_MMAP,
  90. #else
  91. MAP_BL32_MEM,
  92. #endif
  93. {0}
  94. };
  95. #endif
  96. #ifdef IMAGE_BL32
  97. static const mmap_region_t plat_qemu_mmap[] = {
  98. MAP_SHARED_RAM,
  99. MAP_DEVICE0,
  100. #ifdef MAP_DEVICE1
  101. MAP_DEVICE1,
  102. #endif
  103. #ifdef MAP_DEVICE2
  104. MAP_DEVICE2,
  105. #endif
  106. {0}
  107. };
  108. #endif
  109. /*******************************************************************************
  110. * Macro generating the code for the function setting up the pagetables as per
  111. * the platform memory map & initialize the mmu, for the given exception level
  112. ******************************************************************************/
  113. #define DEFINE_CONFIGURE_MMU_EL(_el) \
  114. void qemu_configure_mmu_##_el(unsigned long total_base, \
  115. unsigned long total_size, \
  116. unsigned long code_start, \
  117. unsigned long code_limit, \
  118. unsigned long ro_start, \
  119. unsigned long ro_limit, \
  120. unsigned long coh_start, \
  121. unsigned long coh_limit) \
  122. { \
  123. mmap_add_region(total_base, total_base, \
  124. total_size, \
  125. MT_MEMORY | MT_RW | MT_SECURE); \
  126. mmap_add_region(code_start, code_start, \
  127. code_limit - code_start, \
  128. MT_CODE | MT_SECURE); \
  129. mmap_add_region(ro_start, ro_start, \
  130. ro_limit - ro_start, \
  131. MT_RO_DATA | MT_SECURE); \
  132. mmap_add_region(coh_start, coh_start, \
  133. coh_limit - coh_start, \
  134. MT_DEVICE | MT_RW | MT_SECURE); \
  135. mmap_add(plat_qemu_mmap); \
  136. init_xlat_tables(); \
  137. \
  138. enable_mmu_##_el(0); \
  139. }
  140. /* Define EL1 and EL3 variants of the function initialising the MMU */
  141. #ifdef __aarch64__
  142. DEFINE_CONFIGURE_MMU_EL(el1)
  143. DEFINE_CONFIGURE_MMU_EL(el3)
  144. #else
  145. DEFINE_CONFIGURE_MMU_EL(svc_mon)
  146. #endif
  147. #if MEASURED_BOOT || TRUSTED_BOARD_BOOT
  148. int plat_get_mbedtls_heap(void **heap_addr, size_t *heap_size)
  149. {
  150. return get_mbedtls_heap_helper(heap_addr, heap_size);
  151. }
  152. #endif