platform_def.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380
  1. /* SPDX-License-Identifier: BSD-3-Clause
  2. *
  3. * Copyright (c) 2019-2020, Linaro Limited and Contributors.
  4. * All rights reserved.
  5. */
  6. #ifndef PLATFORM_DEF_H
  7. #define PLATFORM_DEF_H
  8. #include <arch.h>
  9. #include <plat/common/common_def.h>
  10. #include <tbbr_img_def.h>
  11. /* Special value used to verify platform parameters from BL2 to BL3-1 */
  12. #define QEMU_BL31_PLAT_PARAM_VAL 0x0f1e2d3c4b5a6978ULL
  13. #define PLATFORM_STACK_SIZE 0x1000
  14. #define PLATFORM_MAX_CPUS_PER_CLUSTER U(8)
  15. /*
  16. * Define the number of cores per cluster used in calculating core position.
  17. * The cluster number is shifted by this value and added to the core ID,
  18. * so its value represents log2(cores/cluster).
  19. * Default is 2**(3) = 8 cores per cluster.
  20. */
  21. #define PLATFORM_CPU_PER_CLUSTER_SHIFT U(3)
  22. #define PLATFORM_CLUSTER_COUNT U(64)
  23. #define PLATFORM_CORE_COUNT (PLATFORM_CLUSTER_COUNT * \
  24. PLATFORM_MAX_CPUS_PER_CLUSTER)
  25. #define QEMU_PRIMARY_CPU U(0)
  26. #define PLAT_NUM_PWR_DOMAINS (PLATFORM_CLUSTER_COUNT + \
  27. PLATFORM_CORE_COUNT)
  28. #define PLAT_MAX_PWR_LVL MPIDR_AFFLVL1
  29. #define PLAT_MAX_RET_STATE 1
  30. #define PLAT_MAX_OFF_STATE 2
  31. /* Local power state for power domains in Run state. */
  32. #define PLAT_LOCAL_STATE_RUN 0
  33. /* Local power state for retention. Valid only for CPU power domains */
  34. #define PLAT_LOCAL_STATE_RET 1
  35. /*
  36. * Local power state for OFF/power-down. Valid for CPU and cluster power
  37. * domains.
  38. */
  39. #define PLAT_LOCAL_STATE_OFF 2
  40. /*
  41. * Macros used to parse state information from State-ID if it is using the
  42. * recommended encoding for State-ID.
  43. */
  44. #define PLAT_LOCAL_PSTATE_WIDTH 4
  45. #define PLAT_LOCAL_PSTATE_MASK ((1 << PLAT_LOCAL_PSTATE_WIDTH) - 1)
  46. /*
  47. * Some data must be aligned on the biggest cache line size in the platform.
  48. * This is known only to the platform as it might have a combination of
  49. * integrated and external caches.
  50. */
  51. #define CACHE_WRITEBACK_SHIFT 6
  52. #define CACHE_WRITEBACK_GRANULE (1 << CACHE_WRITEBACK_SHIFT)
  53. /*
  54. * Define the max number of memory nodes.
  55. */
  56. #define PLAT_MAX_MEM_NODES 128
  57. /*
  58. * Partition memory into secure ROM, non-secure DRAM, secure "SRAM",
  59. * and secure DRAM.
  60. */
  61. #define SEC_ROM_BASE 0x00000000
  62. #define SEC_ROM_SIZE 0x00020000
  63. #define NS_DRAM0_BASE 0x10000000000ULL
  64. #define NS_DRAM0_SIZE 0x00020000000
  65. #define SEC_SRAM_BASE 0x20000000
  66. #define SEC_SRAM_SIZE 0x20000000
  67. /*
  68. * RAD just placeholders, need to be chosen after finalizing mem map
  69. */
  70. #define SEC_DRAM_BASE 0x1000
  71. #define SEC_DRAM_SIZE 0x1000
  72. /* Load pageable part of OP-TEE 2MB above secure DRAM base */
  73. #define QEMU_OPTEE_PAGEABLE_LOAD_BASE (SEC_DRAM_BASE + 0x00200000)
  74. #define QEMU_OPTEE_PAGEABLE_LOAD_SIZE 0x00400000
  75. /*
  76. * ARM-TF lives in SRAM, partition it here
  77. */
  78. #define SHARED_RAM_BASE SEC_SRAM_BASE
  79. #define SHARED_RAM_SIZE 0x00002000
  80. #define PLAT_QEMU_TRUSTED_MAILBOX_BASE SHARED_RAM_BASE
  81. #define PLAT_QEMU_TRUSTED_MAILBOX_SIZE (8 + PLAT_QEMU_HOLD_SIZE)
  82. #define PLAT_QEMU_HOLD_BASE (PLAT_QEMU_TRUSTED_MAILBOX_BASE + 8)
  83. #define PLAT_QEMU_HOLD_SIZE (PLATFORM_CORE_COUNT * \
  84. PLAT_QEMU_HOLD_ENTRY_SIZE)
  85. #define PLAT_QEMU_HOLD_ENTRY_SHIFT 3
  86. #define PLAT_QEMU_HOLD_ENTRY_SIZE (1 << PLAT_QEMU_HOLD_ENTRY_SHIFT)
  87. #define PLAT_QEMU_HOLD_STATE_WAIT 0
  88. #define PLAT_QEMU_HOLD_STATE_GO 1
  89. #define BL_RAM_BASE (SHARED_RAM_BASE + SHARED_RAM_SIZE)
  90. #define BL_RAM_SIZE (SEC_SRAM_SIZE - SHARED_RAM_SIZE)
  91. /*
  92. * BL1 specific defines.
  93. *
  94. * BL1 RW data is relocated from ROM to RAM at runtime so we need 2 sets of
  95. * addresses.
  96. * Put BL1 RW at the top of the Secure SRAM. BL1_RW_BASE is calculated using
  97. * the current BL1 RW debug size plus a little space for growth.
  98. */
  99. #define BL1_SIZE 0x12000
  100. #define BL1_RO_BASE SEC_ROM_BASE
  101. #define BL1_RO_LIMIT (SEC_ROM_BASE + SEC_ROM_SIZE)
  102. #define BL1_RW_BASE (BL1_RW_LIMIT - BL1_SIZE)
  103. #define BL1_RW_LIMIT (BL_RAM_BASE + BL_RAM_SIZE)
  104. /*
  105. * BL2 specific defines.
  106. *
  107. * Put BL2 just below BL3-1. BL2_BASE is calculated using the current BL2 debug
  108. * size plus a little space for growth.
  109. */
  110. #define BL2_SIZE 0x1D000
  111. #define BL2_BASE (BL31_BASE - BL2_SIZE)
  112. #define BL2_LIMIT BL31_BASE
  113. /*
  114. * BL3-1 specific defines.
  115. *
  116. * Put BL3-1 at the top of the Trusted SRAM. BL31_BASE is calculated using the
  117. * current BL3-1 debug size plus a little space for growth.
  118. */
  119. #define BL31_SIZE 0x300000
  120. #define BL31_BASE (BL31_LIMIT - BL31_SIZE)
  121. #define BL31_LIMIT (BL1_RW_BASE)
  122. #define BL31_PROGBITS_LIMIT BL1_RW_BASE
  123. /*
  124. * BL3-2 specific defines.
  125. *
  126. * BL3-2 can execute from Secure SRAM, or Secure DRAM.
  127. */
  128. #define BL32_SRAM_BASE BL_RAM_BASE
  129. #define BL32_SRAM_LIMIT BL2_BASE
  130. #define BL32_MEM_BASE BL_RAM_BASE
  131. #define BL32_MEM_SIZE (BL_RAM_SIZE - BL1_SIZE - \
  132. BL2_SIZE - BL31_SIZE)
  133. #define BL32_BASE BL32_SRAM_BASE
  134. #define BL32_LIMIT BL32_SRAM_LIMIT
  135. #define NS_IMAGE_OFFSET (NS_DRAM0_BASE + 0x20000000)
  136. #define NS_IMAGE_MAX_SIZE (NS_DRAM0_SIZE - 0x20000000)
  137. #define PLAT_PHY_ADDR_SPACE_SIZE (1ull << 42)
  138. #define PLAT_VIRT_ADDR_SPACE_SIZE (1ull << 42)
  139. #if SPM_MM
  140. #define MAX_MMAP_REGIONS 12
  141. #define MAX_XLAT_TABLES 12
  142. #else
  143. #define MAX_MMAP_REGIONS 11
  144. #define MAX_XLAT_TABLES 11
  145. #endif
  146. #define MAX_IO_DEVICES 3
  147. #define MAX_IO_HANDLES 4
  148. #if SPM_MM && defined(IMAGE_BL31)
  149. # define PLAT_SP_IMAGE_MMAP_REGIONS 30
  150. # define PLAT_SP_IMAGE_MAX_XLAT_TABLES 50
  151. #endif
  152. /*
  153. * PL011 related constants
  154. */
  155. #define UART0_BASE 0x60000000
  156. #define UART1_BASE 0x60030000
  157. #define UART0_CLK_IN_HZ 1
  158. #define UART1_CLK_IN_HZ 1
  159. /* Secure UART */
  160. #define UART2_BASE 0x60040000
  161. #define UART2_CLK_IN_HZ 1
  162. #define PLAT_QEMU_BOOT_UART_BASE UART0_BASE
  163. #define PLAT_QEMU_BOOT_UART_CLK_IN_HZ UART0_CLK_IN_HZ
  164. #define PLAT_QEMU_CRASH_UART_BASE UART1_BASE
  165. #define PLAT_QEMU_CRASH_UART_CLK_IN_HZ UART1_CLK_IN_HZ
  166. #define PLAT_QEMU_CONSOLE_BAUDRATE 115200
  167. #define QEMU_FLASH0_BASE 0x00000000
  168. #define QEMU_FLASH0_SIZE 0x10000000
  169. #define QEMU_FLASH1_BASE 0x10000000
  170. #define QEMU_FLASH1_SIZE 0x10000000
  171. #define PLAT_QEMU_FIP_BASE BL1_SIZE
  172. #define PLAT_QEMU_FIP_MAX_SIZE 0x00400000
  173. /* This is map from GIC_DIST up to last CPU (255) GIC_REDISTR */
  174. #define DEVICE0_BASE 0x40000000
  175. #define DEVICE0_SIZE 0x04080000
  176. /* This is map from NORMAL_UART up to SECURE_UART_MM */
  177. #define DEVICE1_BASE 0x60000000
  178. #define DEVICE1_SIZE 0x10041000
  179. /* This is a map for SECURE_EC */
  180. #define DEVICE2_BASE 0x50000000
  181. #define DEVICE2_SIZE 0x00001000
  182. /*
  183. * GIC related constants
  184. * We use GICv3 where CPU Interface registers are not memory mapped
  185. *
  186. * Legacy values - on platform version 0.1+ they are read from DT
  187. */
  188. #define GICD_BASE 0x40060000
  189. #define GICR_BASE 0x40080000
  190. #define GICC_BASE 0x0
  191. #define QEMU_IRQ_SEC_SGI_0 8
  192. #define QEMU_IRQ_SEC_SGI_1 9
  193. #define QEMU_IRQ_SEC_SGI_2 10
  194. #define QEMU_IRQ_SEC_SGI_3 11
  195. #define QEMU_IRQ_SEC_SGI_4 12
  196. #define QEMU_IRQ_SEC_SGI_5 13
  197. #define QEMU_IRQ_SEC_SGI_6 14
  198. #define QEMU_IRQ_SEC_SGI_7 15
  199. /******************************************************************************
  200. * On a GICv2 system, the Group 1 secure interrupts are treated as Group 0
  201. * interrupts.
  202. *****************************************************************************/
  203. #define PLATFORM_G1S_PROPS(grp) \
  204. INTR_PROP_DESC(QEMU_IRQ_SEC_SGI_0, GIC_HIGHEST_SEC_PRIORITY, \
  205. grp, GIC_INTR_CFG_EDGE), \
  206. INTR_PROP_DESC(QEMU_IRQ_SEC_SGI_1, GIC_HIGHEST_SEC_PRIORITY, \
  207. grp, GIC_INTR_CFG_EDGE), \
  208. INTR_PROP_DESC(QEMU_IRQ_SEC_SGI_2, GIC_HIGHEST_SEC_PRIORITY, \
  209. grp, GIC_INTR_CFG_EDGE), \
  210. INTR_PROP_DESC(QEMU_IRQ_SEC_SGI_3, GIC_HIGHEST_SEC_PRIORITY, \
  211. grp, GIC_INTR_CFG_EDGE), \
  212. INTR_PROP_DESC(QEMU_IRQ_SEC_SGI_4, GIC_HIGHEST_SEC_PRIORITY, \
  213. grp, GIC_INTR_CFG_EDGE), \
  214. INTR_PROP_DESC(QEMU_IRQ_SEC_SGI_5, GIC_HIGHEST_SEC_PRIORITY, \
  215. grp, GIC_INTR_CFG_EDGE), \
  216. INTR_PROP_DESC(QEMU_IRQ_SEC_SGI_6, GIC_HIGHEST_SEC_PRIORITY, \
  217. grp, GIC_INTR_CFG_EDGE), \
  218. INTR_PROP_DESC(QEMU_IRQ_SEC_SGI_7, GIC_HIGHEST_SEC_PRIORITY, \
  219. grp, GIC_INTR_CFG_EDGE)
  220. #define PLATFORM_G0_PROPS(grp)
  221. /*
  222. * DT related constants
  223. */
  224. #define PLAT_QEMU_DT_BASE NS_DRAM0_BASE
  225. #define PLAT_QEMU_DT_MAX_SIZE 0x100000
  226. #if SPM_MM
  227. #define PLAT_QEMU_SP_IMAGE_BASE BL_RAM_BASE
  228. #define PLAT_QEMU_SP_IMAGE_SIZE ULL(0x300000)
  229. #ifdef IMAGE_BL2
  230. /* In BL2 all memory allocated to the SPM Payload image is marked as RW. */
  231. # define QEMU_SP_IMAGE_MMAP MAP_REGION_FLAT( \
  232. PLAT_QEMU_SP_IMAGE_BASE, \
  233. PLAT_QEMU_SP_IMAGE_SIZE, \
  234. MT_MEMORY | MT_RW | \
  235. MT_SECURE)
  236. #elif IMAGE_BL31
  237. /* All SPM Payload memory is marked as code in S-EL0 */
  238. # define QEMU_SP_IMAGE_MMAP MAP_REGION2(PLAT_QEMU_SP_IMAGE_BASE, \
  239. PLAT_QEMU_SP_IMAGE_BASE, \
  240. PLAT_QEMU_SP_IMAGE_SIZE, \
  241. MT_CODE | MT_SECURE | \
  242. MT_USER, \
  243. PAGE_SIZE)
  244. #endif
  245. /*
  246. * EL3 -> S-EL0 secure shared memory
  247. */
  248. #define PLAT_SPM_BUF_PCPU_SIZE ULL(0x10000)
  249. #define PLAT_SPM_BUF_SIZE (PLATFORM_CORE_COUNT * \
  250. PLAT_SPM_BUF_PCPU_SIZE)
  251. #define PLAT_SPM_BUF_BASE (BL32_LIMIT - PLAT_SPM_BUF_SIZE)
  252. #define QEMU_SPM_BUF_EL3_MMAP MAP_REGION_FLAT(PLAT_SPM_BUF_BASE, \
  253. PLAT_SPM_BUF_SIZE, \
  254. MT_RW_DATA | MT_SECURE)
  255. #define QEMU_SPM_BUF_EL0_MMAP MAP_REGION2(PLAT_SPM_BUF_BASE, \
  256. PLAT_SPM_BUF_BASE, \
  257. PLAT_SPM_BUF_SIZE, \
  258. MT_RO_DATA | MT_SECURE | \
  259. MT_USER, \
  260. PAGE_SIZE)
  261. /*
  262. * Shared memory between Normal world and S-EL0 for
  263. * passing data during service requests. It will be marked as RW and NS.
  264. * This buffer is allocated at the top of NS_DRAM, the base address is
  265. * overridden in SPM initialization.
  266. */
  267. #define PLAT_QEMU_SP_IMAGE_NS_BUF_BASE (PLAT_QEMU_DT_BASE + \
  268. PLAT_QEMU_DT_MAX_SIZE)
  269. #define PLAT_QEMU_SP_IMAGE_NS_BUF_SIZE ULL(0x200000)
  270. #define QEMU_SP_IMAGE_NS_BUF_MMAP MAP_REGION2( \
  271. PLAT_QEMU_SP_IMAGE_NS_BUF_BASE, \
  272. PLAT_QEMU_SP_IMAGE_NS_BUF_BASE, \
  273. PLAT_QEMU_SP_IMAGE_NS_BUF_SIZE, \
  274. MT_RW_DATA | MT_NS | \
  275. MT_USER, \
  276. PAGE_SIZE)
  277. #define PLAT_SP_IMAGE_NS_BUF_BASE PLAT_QEMU_SP_IMAGE_NS_BUF_BASE
  278. #define PLAT_SP_IMAGE_NS_BUF_SIZE PLAT_QEMU_SP_IMAGE_NS_BUF_SIZE
  279. #define PLAT_QEMU_SP_IMAGE_HEAP_BASE (PLAT_QEMU_SP_IMAGE_BASE + \
  280. PLAT_QEMU_SP_IMAGE_SIZE)
  281. #define PLAT_QEMU_SP_IMAGE_HEAP_SIZE ULL(0x800000)
  282. #define PLAT_SP_IMAGE_STACK_BASE (PLAT_QEMU_SP_IMAGE_HEAP_BASE + \
  283. PLAT_QEMU_SP_IMAGE_HEAP_SIZE)
  284. #define PLAT_SP_IMAGE_STACK_PCPU_SIZE ULL(0x10000)
  285. #define QEMU_SP_IMAGE_STACK_TOTAL_SIZE (PLATFORM_CORE_COUNT * \
  286. PLAT_SP_IMAGE_STACK_PCPU_SIZE)
  287. #define QEMU_SP_IMAGE_RW_MMAP MAP_REGION2( \
  288. PLAT_QEMU_SP_IMAGE_HEAP_BASE, \
  289. PLAT_QEMU_SP_IMAGE_HEAP_BASE, \
  290. (QEMU_SP_IMAGE_STACK_TOTAL_SIZE + \
  291. PLAT_QEMU_SP_IMAGE_HEAP_SIZE), \
  292. MT_RW_DATA | MT_SECURE | \
  293. MT_USER, \
  294. PAGE_SIZE)
  295. /*
  296. * Secure variable storage is located at Secure Flash.
  297. */
  298. #if SPM_MM
  299. #define QEMU_SECURE_VARSTORE_BASE 0x01000000
  300. #define QEMU_SECURE_VARSTORE_SIZE 0x00100000
  301. #define MAP_SECURE_VARSTORE MAP_REGION_FLAT( \
  302. QEMU_SECURE_VARSTORE_BASE, \
  303. QEMU_SECURE_VARSTORE_SIZE, \
  304. MT_DEVICE | MT_RW | \
  305. MT_SECURE | MT_USER)
  306. #endif
  307. /* Total number of memory regions with distinct properties */
  308. #define PLAT_QEMU_SP_IMAGE_NUM_MEM_REGIONS 6
  309. /*
  310. * Name of the section to put the translation tables used by the S-EL1/S-EL0
  311. * context of a Secure Partition.
  312. */
  313. #define PLAT_SP_IMAGE_XLAT_SECTION_NAME ".qemu_sp_xlat_table"
  314. #define PLAT_SP_IMAGE_BASE_XLAT_SECTION_NAME ".qemu_sp_xlat_table"
  315. /* Cookies passed to the Secure Partition at boot. Not used by QEMU platforms.*/
  316. #define PLAT_SPM_COOKIE_0 ULL(0)
  317. #define PLAT_SPM_COOKIE_1 ULL(0)
  318. #endif
  319. #define QEMU_PRI_BITS 2
  320. #define PLAT_SP_PRI 0x20
  321. #endif /* PLATFORM_DEF_H */