platform_def.h 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. /*
  2. * Copyright (c) 2015-2024, Arm Limited and Contributors. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #ifndef PLATFORM_DEF_H
  7. #define PLATFORM_DEF_H
  8. #include <arch.h>
  9. #include <common/tbbr/tbbr_img_def.h>
  10. #include <lib/utils_def.h>
  11. #include <plat/common/common_def.h>
  12. #include "rpi_hw.h"
  13. /* Special value used to verify platform parameters from BL2 to BL31 */
  14. #define RPI3_BL31_PLAT_PARAM_VAL ULL(0x0F1E2D3C4B5A6978)
  15. #define PLATFORM_STACK_SIZE ULL(0x1000)
  16. #define PLATFORM_MAX_CPUS_PER_CLUSTER U(4)
  17. #define PLATFORM_CLUSTER_COUNT U(1)
  18. #define PLATFORM_CLUSTER0_CORE_COUNT PLATFORM_MAX_CPUS_PER_CLUSTER
  19. #define PLATFORM_CORE_COUNT PLATFORM_CLUSTER0_CORE_COUNT
  20. #define RPI_PRIMARY_CPU U(0)
  21. #define PLAT_MAX_PWR_LVL MPIDR_AFFLVL1
  22. #define PLAT_NUM_PWR_DOMAINS (PLATFORM_CLUSTER_COUNT + \
  23. PLATFORM_CORE_COUNT)
  24. #define PLAT_MAX_RET_STATE U(1)
  25. #define PLAT_MAX_OFF_STATE U(2)
  26. /* Local power state for power domains in Run state. */
  27. #define PLAT_LOCAL_STATE_RUN U(0)
  28. /* Local power state for retention. Valid only for CPU power domains */
  29. #define PLAT_LOCAL_STATE_RET U(1)
  30. /*
  31. * Local power state for OFF/power-down. Valid for CPU and cluster power
  32. * domains.
  33. */
  34. #define PLAT_LOCAL_STATE_OFF U(2)
  35. /*
  36. * Macros used to parse state information from State-ID if it is using the
  37. * recommended encoding for State-ID.
  38. */
  39. #define PLAT_LOCAL_PSTATE_WIDTH U(4)
  40. #define PLAT_LOCAL_PSTATE_MASK ((U(1) << PLAT_LOCAL_PSTATE_WIDTH) - 1)
  41. /*
  42. * Some data must be aligned on the biggest cache line size in the platform.
  43. * This is known only to the platform as it might have a combination of
  44. * integrated and external caches.
  45. */
  46. #define CACHE_WRITEBACK_SHIFT U(6)
  47. #define CACHE_WRITEBACK_GRANULE (U(1) << CACHE_WRITEBACK_SHIFT)
  48. /*
  49. * Partition memory into secure ROM, non-secure DRAM, secure "SRAM", and
  50. * secure DRAM. Note that this is all actually DRAM with different names,
  51. * there is no Secure RAM in the Raspberry Pi 3.
  52. */
  53. #if RPI3_USE_UEFI_MAP
  54. #define SEC_ROM_BASE ULL(0x00000000)
  55. #define SEC_ROM_SIZE ULL(0x00010000)
  56. /* FIP placed after ROM to append it to BL1 with very little padding. */
  57. #define PLAT_RPI3_FIP_BASE ULL(0x00020000)
  58. #define PLAT_RPI3_FIP_MAX_SIZE ULL(0x00010000)
  59. /* Reserve 2M of secure SRAM and DRAM, starting at 2M */
  60. #define SEC_SRAM_BASE ULL(0x00200000)
  61. #define SEC_SRAM_SIZE ULL(0x00100000)
  62. #define SEC_DRAM0_BASE ULL(0x00300000)
  63. #define SEC_DRAM0_SIZE ULL(0x00100000)
  64. /* Windows on ARM requires some RAM at 4M */
  65. #define NS_DRAM0_BASE ULL(0x00400000)
  66. #define NS_DRAM0_SIZE ULL(0x00C00000)
  67. #else
  68. #define SEC_ROM_BASE ULL(0x00000000)
  69. #define SEC_ROM_SIZE ULL(0x00020000)
  70. /* FIP placed after ROM to append it to BL1 with very little padding. */
  71. #define PLAT_RPI3_FIP_BASE ULL(0x00020000)
  72. #define PLAT_RPI3_FIP_MAX_SIZE ULL(0x001E0000)
  73. /* We have 16M of memory reserved starting at 256M */
  74. #define SEC_SRAM_BASE ULL(0x10000000)
  75. #define SEC_SRAM_SIZE ULL(0x00100000)
  76. #define SEC_DRAM0_BASE ULL(0x10100000)
  77. #define SEC_DRAM0_SIZE ULL(0x00F00000)
  78. /* End of reserved memory */
  79. #define NS_DRAM0_BASE ULL(0x11000000)
  80. #define NS_DRAM0_SIZE ULL(0x01000000)
  81. #endif /* RPI3_USE_UEFI_MAP */
  82. /*
  83. * BL33 entrypoint.
  84. */
  85. #define PLAT_RPI3_NS_IMAGE_OFFSET NS_DRAM0_BASE
  86. #define PLAT_RPI3_NS_IMAGE_MAX_SIZE NS_DRAM0_SIZE
  87. /*
  88. * I/O registers.
  89. */
  90. #define DEVICE0_BASE RPI_IO_BASE
  91. #define DEVICE0_SIZE RPI_IO_SIZE
  92. /*
  93. * Arm TF lives in SRAM, partition it here
  94. */
  95. #define SHARED_RAM_BASE SEC_SRAM_BASE
  96. #define SHARED_RAM_SIZE ULL(0x00001000)
  97. #define BL_RAM_BASE (SHARED_RAM_BASE + SHARED_RAM_SIZE)
  98. #define BL_RAM_SIZE (SEC_SRAM_SIZE - SHARED_RAM_SIZE)
  99. /*
  100. * Mailbox to control the secondary cores.All secondary cores are held in a wait
  101. * loop in cold boot. To release them perform the following steps (plus any
  102. * additional barriers that may be needed):
  103. *
  104. * uint64_t *entrypoint = (uint64_t *)PLAT_RPI3_TM_ENTRYPOINT;
  105. * *entrypoint = ADDRESS_TO_JUMP_TO;
  106. *
  107. * uint64_t *mbox_entry = (uint64_t *)PLAT_RPI3_TM_HOLD_BASE;
  108. * mbox_entry[cpu_id] = PLAT_RPI3_TM_HOLD_STATE_GO;
  109. *
  110. * sev();
  111. */
  112. #define PLAT_RPI3_TRUSTED_MAILBOX_BASE SHARED_RAM_BASE
  113. /* The secure entry point to be used on warm reset by all CPUs. */
  114. #define PLAT_RPI3_TM_ENTRYPOINT PLAT_RPI3_TRUSTED_MAILBOX_BASE
  115. #define PLAT_RPI3_TM_ENTRYPOINT_SIZE ULL(8)
  116. /* Hold entries for each CPU. */
  117. #define PLAT_RPI3_TM_HOLD_BASE (PLAT_RPI3_TM_ENTRYPOINT + \
  118. PLAT_RPI3_TM_ENTRYPOINT_SIZE)
  119. #define PLAT_RPI3_TM_HOLD_ENTRY_SIZE ULL(8)
  120. #define PLAT_RPI3_TM_HOLD_SIZE (PLAT_RPI3_TM_HOLD_ENTRY_SIZE * \
  121. PLATFORM_CORE_COUNT)
  122. #define PLAT_RPI3_TRUSTED_MAILBOX_SIZE (PLAT_RPI3_TM_ENTRYPOINT_SIZE + \
  123. PLAT_RPI3_TM_HOLD_SIZE)
  124. #define PLAT_RPI3_TM_HOLD_STATE_WAIT ULL(0)
  125. #define PLAT_RPI3_TM_HOLD_STATE_GO ULL(1)
  126. #define PLAT_RPI3_TM_HOLD_STATE_BSP_OFF ULL(2)
  127. /*
  128. * BL1 specific defines.
  129. *
  130. * BL1 RW data is relocated from ROM to RAM at runtime so we need 2 sets of
  131. * addresses.
  132. *
  133. * Put BL1 RW at the top of the Secure SRAM. BL1_RW_BASE is calculated using
  134. * the current BL1 RW debug size plus a little space for growth.
  135. */
  136. #define PLAT_MAX_BL1_RW_SIZE ULL(0x12000)
  137. #define BL1_RO_BASE SEC_ROM_BASE
  138. #define BL1_RO_LIMIT (SEC_ROM_BASE + SEC_ROM_SIZE)
  139. #define BL1_RW_BASE (BL1_RW_LIMIT - PLAT_MAX_BL1_RW_SIZE)
  140. #define BL1_RW_LIMIT (BL_RAM_BASE + BL_RAM_SIZE)
  141. /*
  142. * BL2 specific defines.
  143. *
  144. * Put BL2 just below BL31. BL2_BASE is calculated using the current BL2 debug
  145. * size plus a little space for growth.
  146. */
  147. #define PLAT_MAX_BL2_SIZE ULL(0x2C000)
  148. #define BL2_BASE (BL2_LIMIT - PLAT_MAX_BL2_SIZE)
  149. #define BL2_LIMIT BL31_BASE
  150. /*
  151. * BL31 specific defines.
  152. *
  153. * Put BL31 at the top of the Trusted SRAM. BL31_BASE is calculated using the
  154. * current BL31 debug size plus a little space for growth.
  155. */
  156. #define PLAT_MAX_BL31_SIZE ULL(0x20000)
  157. #define BL31_BASE (BL31_LIMIT - PLAT_MAX_BL31_SIZE)
  158. #define BL31_LIMIT (BL_RAM_BASE + BL_RAM_SIZE)
  159. #define BL31_PROGBITS_LIMIT BL1_RW_BASE
  160. /*
  161. * BL32 specific defines.
  162. *
  163. * BL32 can execute from Secure SRAM or Secure DRAM.
  164. */
  165. #define BL32_SRAM_BASE BL_RAM_BASE
  166. #define BL32_SRAM_LIMIT BL31_BASE
  167. #define BL32_DRAM_BASE SEC_DRAM0_BASE
  168. #define BL32_DRAM_LIMIT (SEC_DRAM0_BASE + SEC_DRAM0_SIZE)
  169. #ifdef SPD_opteed
  170. /* Load pageable part of OP-TEE at end of allocated DRAM space for BL32 */
  171. #define RPI3_OPTEE_PAGEABLE_LOAD_SIZE 0x080000 /* 512KB */
  172. #define RPI3_OPTEE_PAGEABLE_LOAD_BASE (BL32_DRAM_LIMIT - \
  173. RPI3_OPTEE_PAGEABLE_LOAD_SIZE)
  174. #endif
  175. #define SEC_SRAM_ID 0
  176. #define SEC_DRAM_ID 1
  177. #if RPI3_BL32_RAM_LOCATION_ID == SEC_SRAM_ID
  178. # define BL32_MEM_BASE BL_RAM_BASE
  179. # define BL32_MEM_SIZE BL_RAM_SIZE
  180. # define BL32_BASE BL32_SRAM_BASE
  181. # define BL32_LIMIT BL32_SRAM_LIMIT
  182. #elif RPI3_BL32_RAM_LOCATION_ID == SEC_DRAM_ID
  183. # define BL32_MEM_BASE SEC_DRAM0_BASE
  184. # define BL32_MEM_SIZE SEC_DRAM0_SIZE
  185. # define BL32_BASE BL32_DRAM_BASE
  186. # define BL32_LIMIT BL32_DRAM_LIMIT
  187. #else
  188. # error "Unsupported RPI3_BL32_RAM_LOCATION_ID value"
  189. #endif
  190. #define BL32_SIZE (BL32_LIMIT - BL32_BASE)
  191. #ifdef SPD_none
  192. #undef BL32_BASE
  193. #endif /* SPD_none */
  194. /*
  195. * Other memory-related defines.
  196. */
  197. #define PLAT_PHY_ADDR_SPACE_SIZE (ULL(1) << 32)
  198. #define PLAT_VIRT_ADDR_SPACE_SIZE (ULL(1) << 32)
  199. #define MAX_MMAP_REGIONS 8
  200. #define MAX_XLAT_TABLES 4
  201. #define MAX_IO_DEVICES U(3)
  202. #define MAX_IO_HANDLES U(4)
  203. #define MAX_IO_BLOCK_DEVICES U(1)
  204. /*
  205. * Serial-related constants.
  206. */
  207. #define PLAT_RPI_MINI_UART_BASE RPI3_MINI_UART_BASE
  208. #define PLAT_RPI_PL011_UART_BASE RPI3_PL011_UART_BASE
  209. #define PLAT_RPI_PL011_UART_CLOCK RPI3_PL011_UART_CLOCK
  210. #define PLAT_RPI_UART_BAUDRATE ULL(115200)
  211. #define PLAT_RPI_CRASH_UART_BASE PLAT_RPI_MINI_UART_BASE
  212. /*
  213. * System counter
  214. */
  215. #define SYS_COUNTER_FREQ_IN_TICKS ULL(19200000)
  216. #endif /* PLATFORM_DEF_H */