platform_def.h 11 KB

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