arm_def.h 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784
  1. /*
  2. * Copyright (c) 2015-2023, ARM Limited and Contributors. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #ifndef ARM_DEF_H
  7. #define ARM_DEF_H
  8. #include <arch.h>
  9. #include <common/interrupt_props.h>
  10. #include <common/tbbr/tbbr_img_def.h>
  11. #include <drivers/arm/gic_common.h>
  12. #include <lib/utils_def.h>
  13. #include <lib/xlat_tables/xlat_tables_defs.h>
  14. #include <plat/arm/common/smccc_def.h>
  15. #include <plat/common/common_def.h>
  16. /******************************************************************************
  17. * Definitions common to all ARM standard platforms
  18. *****************************************************************************/
  19. /*
  20. * Root of trust key lengths
  21. */
  22. #define ARM_ROTPK_HEADER_LEN 19
  23. #define ARM_ROTPK_HASH_LEN 32
  24. /* ARM_ROTPK_KEY_LEN includes DER header + raw key material */
  25. #define ARM_ROTPK_KEY_LEN 294
  26. /* Special value used to verify platform parameters from BL2 to BL31 */
  27. #define ARM_BL31_PLAT_PARAM_VAL ULL(0x0f1e2d3c4b5a6978)
  28. #define ARM_SYSTEM_COUNT U(1)
  29. #define ARM_CACHE_WRITEBACK_SHIFT 6
  30. /*
  31. * Macros mapping the MPIDR Affinity levels to ARM Platform Power levels. The
  32. * power levels have a 1:1 mapping with the MPIDR affinity levels.
  33. */
  34. #define ARM_PWR_LVL0 MPIDR_AFFLVL0
  35. #define ARM_PWR_LVL1 MPIDR_AFFLVL1
  36. #define ARM_PWR_LVL2 MPIDR_AFFLVL2
  37. #define ARM_PWR_LVL3 MPIDR_AFFLVL3
  38. /*
  39. * Macros for local power states in ARM platforms encoded by State-ID field
  40. * within the power-state parameter.
  41. */
  42. /* Local power state for power domains in Run state. */
  43. #define ARM_LOCAL_STATE_RUN U(0)
  44. /* Local power state for retention. Valid only for CPU power domains */
  45. #define ARM_LOCAL_STATE_RET U(1)
  46. /* Local power state for OFF/power-down. Valid for CPU and cluster power
  47. domains */
  48. #define ARM_LOCAL_STATE_OFF U(2)
  49. /* Memory location options for TSP */
  50. #define ARM_TRUSTED_SRAM_ID 0
  51. #define ARM_TRUSTED_DRAM_ID 1
  52. #define ARM_DRAM_ID 2
  53. #ifdef PLAT_ARM_TRUSTED_SRAM_BASE
  54. #define ARM_TRUSTED_SRAM_BASE PLAT_ARM_TRUSTED_SRAM_BASE
  55. #else
  56. #define ARM_TRUSTED_SRAM_BASE UL(0x04000000)
  57. #endif /* PLAT_ARM_TRUSTED_SRAM_BASE */
  58. #define ARM_SHARED_RAM_BASE ARM_TRUSTED_SRAM_BASE
  59. #define ARM_SHARED_RAM_SIZE UL(0x00001000) /* 4 KB */
  60. /* The remaining Trusted SRAM is used to load the BL images */
  61. #define ARM_BL_RAM_BASE (ARM_SHARED_RAM_BASE + \
  62. ARM_SHARED_RAM_SIZE)
  63. #define ARM_BL_RAM_SIZE (PLAT_ARM_TRUSTED_SRAM_SIZE - \
  64. ARM_SHARED_RAM_SIZE)
  65. /*
  66. * The top 16MB (or 64MB if RME is enabled) of DRAM1 is configured as
  67. * follows:
  68. * - SCP TZC DRAM: If present, DRAM reserved for SCP use
  69. * - L1 GPT DRAM: Reserved for L1 GPT if RME is enabled
  70. * - REALM DRAM: Reserved for Realm world if RME is enabled
  71. * - TF-A <-> RMM SHARED: Area shared for communication between TF-A and RMM
  72. * - AP TZC DRAM: The remaining TZC secured DRAM reserved for AP use
  73. *
  74. * RME enabled(64MB) RME not enabled(16MB)
  75. * -------------------- -------------------
  76. * | | | |
  77. * | AP TZC (~28MB) | | AP TZC (~14MB) |
  78. * -------------------- -------------------
  79. * | | | |
  80. * | REALM (RMM) | | EL3 TZC (2MB) |
  81. * | (32MB - 4KB) | -------------------
  82. * -------------------- | |
  83. * | | | SCP TZC |
  84. * | TF-A <-> RMM | 0xFFFF_FFFF-------------------
  85. * | SHARED (4KB) |
  86. * --------------------
  87. * | |
  88. * | EL3 TZC (3MB) |
  89. * --------------------
  90. * | L1 GPT + SCP TZC |
  91. * | (~1MB) |
  92. * 0xFFFF_FFFF --------------------
  93. */
  94. #if ENABLE_RME
  95. #define ARM_TZC_DRAM1_SIZE UL(0x04000000) /* 64MB */
  96. /*
  97. * Define a region within the TZC secured DRAM for use by EL3 runtime
  98. * firmware. This region is meant to be NOLOAD and will not be zero
  99. * initialized. Data sections with the attribute `.arm_el3_tzc_dram` will be
  100. * placed here. 3MB region is reserved if RME is enabled, 2MB otherwise.
  101. */
  102. #define ARM_EL3_TZC_DRAM1_SIZE UL(0x00300000) /* 3MB */
  103. #define ARM_L1_GPT_SIZE UL(0x00100000) /* 1MB */
  104. /* 32MB - ARM_EL3_RMM_SHARED_SIZE */
  105. #define ARM_REALM_SIZE (UL(0x02000000) - \
  106. ARM_EL3_RMM_SHARED_SIZE)
  107. #define ARM_EL3_RMM_SHARED_SIZE (PAGE_SIZE) /* 4KB */
  108. #else
  109. #define ARM_TZC_DRAM1_SIZE UL(0x01000000) /* 16MB */
  110. #define ARM_EL3_TZC_DRAM1_SIZE UL(0x00200000) /* 2MB */
  111. #define ARM_L1_GPT_SIZE UL(0)
  112. #define ARM_REALM_SIZE UL(0)
  113. #define ARM_EL3_RMM_SHARED_SIZE UL(0)
  114. #endif /* ENABLE_RME */
  115. #define ARM_SCP_TZC_DRAM1_BASE (ARM_DRAM1_BASE + \
  116. ARM_DRAM1_SIZE - \
  117. (ARM_SCP_TZC_DRAM1_SIZE + \
  118. ARM_L1_GPT_SIZE))
  119. #define ARM_SCP_TZC_DRAM1_SIZE PLAT_ARM_SCP_TZC_DRAM1_SIZE
  120. #define ARM_SCP_TZC_DRAM1_END (ARM_SCP_TZC_DRAM1_BASE + \
  121. ARM_SCP_TZC_DRAM1_SIZE - 1U)
  122. #if ENABLE_RME
  123. #define ARM_L1_GPT_ADDR_BASE (ARM_DRAM1_BASE + \
  124. ARM_DRAM1_SIZE - \
  125. ARM_L1_GPT_SIZE)
  126. #define ARM_L1_GPT_END (ARM_L1_GPT_ADDR_BASE + \
  127. ARM_L1_GPT_SIZE - 1U)
  128. #define ARM_REALM_BASE (ARM_EL3_RMM_SHARED_BASE - \
  129. ARM_REALM_SIZE)
  130. #define ARM_REALM_END (ARM_REALM_BASE + ARM_REALM_SIZE - 1U)
  131. #define ARM_EL3_RMM_SHARED_BASE (ARM_DRAM1_BASE + \
  132. ARM_DRAM1_SIZE - \
  133. (ARM_SCP_TZC_DRAM1_SIZE + \
  134. ARM_L1_GPT_SIZE + \
  135. ARM_EL3_RMM_SHARED_SIZE + \
  136. ARM_EL3_TZC_DRAM1_SIZE))
  137. #define ARM_EL3_RMM_SHARED_END (ARM_EL3_RMM_SHARED_BASE + \
  138. ARM_EL3_RMM_SHARED_SIZE - 1U)
  139. #endif /* ENABLE_RME */
  140. #define ARM_EL3_TZC_DRAM1_BASE (ARM_SCP_TZC_DRAM1_BASE - \
  141. ARM_EL3_TZC_DRAM1_SIZE)
  142. #define ARM_EL3_TZC_DRAM1_END (ARM_EL3_TZC_DRAM1_BASE + \
  143. ARM_EL3_TZC_DRAM1_SIZE - 1U)
  144. #define ARM_AP_TZC_DRAM1_BASE (ARM_DRAM1_BASE + \
  145. ARM_DRAM1_SIZE - \
  146. ARM_TZC_DRAM1_SIZE)
  147. #define ARM_AP_TZC_DRAM1_SIZE (ARM_TZC_DRAM1_SIZE - \
  148. (ARM_SCP_TZC_DRAM1_SIZE + \
  149. ARM_EL3_TZC_DRAM1_SIZE + \
  150. ARM_EL3_RMM_SHARED_SIZE + \
  151. ARM_REALM_SIZE + \
  152. ARM_L1_GPT_SIZE))
  153. #define ARM_AP_TZC_DRAM1_END (ARM_AP_TZC_DRAM1_BASE + \
  154. ARM_AP_TZC_DRAM1_SIZE - 1U)
  155. /* Define the Access permissions for Secure peripherals to NS_DRAM */
  156. #if ARM_CRYPTOCELL_INTEG
  157. /*
  158. * Allow Secure peripheral to read NS DRAM when integrated with CryptoCell.
  159. * This is required by CryptoCell to authenticate BL33 which is loaded
  160. * into the Non Secure DDR.
  161. */
  162. #define ARM_TZC_NS_DRAM_S_ACCESS TZC_REGION_S_RD
  163. #else
  164. #define ARM_TZC_NS_DRAM_S_ACCESS TZC_REGION_S_NONE
  165. #endif
  166. #ifdef SPD_opteed
  167. /*
  168. * BL2 needs to map 4MB at the end of TZC_DRAM1 in order to
  169. * load/authenticate the trusted os extra image. The first 512KB of
  170. * TZC_DRAM1 are reserved for trusted os (OPTEE). The extra image loading
  171. * for OPTEE is paged image which only include the paging part using
  172. * virtual memory but without "init" data. OPTEE will copy the "init" data
  173. * (from pager image) to the first 512KB of TZC_DRAM, and then copy the
  174. * extra image behind the "init" data.
  175. */
  176. #define ARM_OPTEE_PAGEABLE_LOAD_BASE (ARM_AP_TZC_DRAM1_BASE + \
  177. ARM_AP_TZC_DRAM1_SIZE - \
  178. ARM_OPTEE_PAGEABLE_LOAD_SIZE)
  179. #define ARM_OPTEE_PAGEABLE_LOAD_SIZE UL(0x400000)
  180. #define ARM_OPTEE_PAGEABLE_LOAD_MEM MAP_REGION_FLAT( \
  181. ARM_OPTEE_PAGEABLE_LOAD_BASE, \
  182. ARM_OPTEE_PAGEABLE_LOAD_SIZE, \
  183. MT_MEMORY | MT_RW | MT_SECURE)
  184. /*
  185. * Map the memory for the OP-TEE core (also known as OP-TEE pager when paging
  186. * support is enabled).
  187. */
  188. #define ARM_MAP_OPTEE_CORE_MEM MAP_REGION_FLAT( \
  189. BL32_BASE, \
  190. BL32_LIMIT - BL32_BASE, \
  191. MT_MEMORY | MT_RW | MT_SECURE)
  192. #endif /* SPD_opteed */
  193. #define ARM_NS_DRAM1_BASE ARM_DRAM1_BASE
  194. #define ARM_NS_DRAM1_SIZE (ARM_DRAM1_SIZE - \
  195. ARM_TZC_DRAM1_SIZE)
  196. #define ARM_NS_DRAM1_END (ARM_NS_DRAM1_BASE + \
  197. ARM_NS_DRAM1_SIZE - 1U)
  198. #ifdef PLAT_ARM_DRAM1_BASE
  199. #define ARM_DRAM1_BASE PLAT_ARM_DRAM1_BASE
  200. #else
  201. #define ARM_DRAM1_BASE ULL(0x80000000)
  202. #endif /* PLAT_ARM_DRAM1_BASE */
  203. #define ARM_DRAM1_SIZE ULL(0x80000000)
  204. #define ARM_DRAM1_END (ARM_DRAM1_BASE + \
  205. ARM_DRAM1_SIZE - 1U)
  206. #define ARM_DRAM2_BASE PLAT_ARM_DRAM2_BASE
  207. #define ARM_DRAM2_SIZE PLAT_ARM_DRAM2_SIZE
  208. #define ARM_DRAM2_END (ARM_DRAM2_BASE + \
  209. ARM_DRAM2_SIZE - 1U)
  210. /* Number of DRAM banks */
  211. #define ARM_DRAM_NUM_BANKS 2UL
  212. #define ARM_IRQ_SEC_PHY_TIMER 29
  213. #define ARM_IRQ_SEC_SGI_0 8
  214. #define ARM_IRQ_SEC_SGI_1 9
  215. #define ARM_IRQ_SEC_SGI_2 10
  216. #define ARM_IRQ_SEC_SGI_3 11
  217. #define ARM_IRQ_SEC_SGI_4 12
  218. #define ARM_IRQ_SEC_SGI_5 13
  219. #define ARM_IRQ_SEC_SGI_6 14
  220. #define ARM_IRQ_SEC_SGI_7 15
  221. /*
  222. * Define a list of Group 1 Secure and Group 0 interrupt properties as per GICv3
  223. * terminology. On a GICv2 system or mode, the lists will be merged and treated
  224. * as Group 0 interrupts.
  225. */
  226. #define ARM_G1S_IRQ_PROPS(grp) \
  227. INTR_PROP_DESC(ARM_IRQ_SEC_PHY_TIMER, GIC_HIGHEST_SEC_PRIORITY, (grp), \
  228. GIC_INTR_CFG_LEVEL), \
  229. INTR_PROP_DESC(ARM_IRQ_SEC_SGI_1, GIC_HIGHEST_SEC_PRIORITY, (grp), \
  230. GIC_INTR_CFG_EDGE), \
  231. INTR_PROP_DESC(ARM_IRQ_SEC_SGI_2, GIC_HIGHEST_SEC_PRIORITY, (grp), \
  232. GIC_INTR_CFG_EDGE), \
  233. INTR_PROP_DESC(ARM_IRQ_SEC_SGI_3, GIC_HIGHEST_SEC_PRIORITY, (grp), \
  234. GIC_INTR_CFG_EDGE), \
  235. INTR_PROP_DESC(ARM_IRQ_SEC_SGI_4, GIC_HIGHEST_SEC_PRIORITY, (grp), \
  236. GIC_INTR_CFG_EDGE), \
  237. INTR_PROP_DESC(ARM_IRQ_SEC_SGI_5, GIC_HIGHEST_SEC_PRIORITY, (grp), \
  238. GIC_INTR_CFG_EDGE), \
  239. INTR_PROP_DESC(ARM_IRQ_SEC_SGI_7, GIC_HIGHEST_SEC_PRIORITY, (grp), \
  240. GIC_INTR_CFG_EDGE)
  241. #define ARM_G0_IRQ_PROPS(grp) \
  242. INTR_PROP_DESC(ARM_IRQ_SEC_SGI_0, PLAT_SDEI_NORMAL_PRI, (grp), \
  243. GIC_INTR_CFG_EDGE), \
  244. INTR_PROP_DESC(ARM_IRQ_SEC_SGI_6, GIC_HIGHEST_SEC_PRIORITY, (grp), \
  245. GIC_INTR_CFG_EDGE)
  246. #define ARM_MAP_SHARED_RAM MAP_REGION_FLAT( \
  247. ARM_SHARED_RAM_BASE, \
  248. ARM_SHARED_RAM_SIZE, \
  249. MT_DEVICE | MT_RW | EL3_PAS)
  250. #define ARM_MAP_NS_DRAM1 MAP_REGION_FLAT( \
  251. ARM_NS_DRAM1_BASE, \
  252. ARM_NS_DRAM1_SIZE, \
  253. MT_MEMORY | MT_RW | MT_NS)
  254. #define ARM_MAP_DRAM2 MAP_REGION_FLAT( \
  255. ARM_DRAM2_BASE, \
  256. ARM_DRAM2_SIZE, \
  257. MT_MEMORY | MT_RW | MT_NS)
  258. #define ARM_MAP_TSP_SEC_MEM MAP_REGION_FLAT( \
  259. TSP_SEC_MEM_BASE, \
  260. TSP_SEC_MEM_SIZE, \
  261. MT_MEMORY | MT_RW | MT_SECURE)
  262. #if ARM_BL31_IN_DRAM
  263. #define ARM_MAP_BL31_SEC_DRAM MAP_REGION_FLAT( \
  264. BL31_BASE, \
  265. PLAT_ARM_MAX_BL31_SIZE, \
  266. MT_MEMORY | MT_RW | MT_SECURE)
  267. #endif
  268. #define ARM_MAP_EL3_TZC_DRAM MAP_REGION_FLAT( \
  269. ARM_EL3_TZC_DRAM1_BASE, \
  270. ARM_EL3_TZC_DRAM1_SIZE, \
  271. MT_MEMORY | MT_RW | EL3_PAS)
  272. #define ARM_MAP_TRUSTED_DRAM MAP_REGION_FLAT( \
  273. PLAT_ARM_TRUSTED_DRAM_BASE, \
  274. PLAT_ARM_TRUSTED_DRAM_SIZE, \
  275. MT_MEMORY | MT_RW | MT_SECURE)
  276. #if ENABLE_RME
  277. /*
  278. * We add the EL3_RMM_SHARED size to RMM mapping to map the region as a block.
  279. * Else we end up requiring more pagetables in BL2 for ROMLIB build.
  280. */
  281. #define ARM_MAP_RMM_DRAM MAP_REGION_FLAT( \
  282. PLAT_ARM_RMM_BASE, \
  283. (PLAT_ARM_RMM_SIZE + \
  284. ARM_EL3_RMM_SHARED_SIZE), \
  285. MT_MEMORY | MT_RW | MT_REALM)
  286. #define ARM_MAP_GPT_L1_DRAM MAP_REGION_FLAT( \
  287. ARM_L1_GPT_ADDR_BASE, \
  288. ARM_L1_GPT_SIZE, \
  289. MT_MEMORY | MT_RW | EL3_PAS)
  290. #define ARM_MAP_EL3_RMM_SHARED_MEM \
  291. MAP_REGION_FLAT( \
  292. ARM_EL3_RMM_SHARED_BASE, \
  293. ARM_EL3_RMM_SHARED_SIZE, \
  294. MT_MEMORY | MT_RW | MT_REALM)
  295. #endif /* ENABLE_RME */
  296. /*
  297. * Mapping for the BL1 RW region. This mapping is needed by BL2 in order to
  298. * share the Mbed TLS heap. Since the heap is allocated inside BL1, it resides
  299. * in the BL1 RW region. Hence, BL2 needs access to the BL1 RW region in order
  300. * to be able to access the heap.
  301. */
  302. #define ARM_MAP_BL1_RW MAP_REGION_FLAT( \
  303. BL1_RW_BASE, \
  304. BL1_RW_LIMIT - BL1_RW_BASE, \
  305. MT_MEMORY | MT_RW | EL3_PAS)
  306. /*
  307. * If SEPARATE_CODE_AND_RODATA=1 we define a region for each section
  308. * otherwise one region is defined containing both.
  309. */
  310. #if SEPARATE_CODE_AND_RODATA
  311. #define ARM_MAP_BL_RO MAP_REGION_FLAT( \
  312. BL_CODE_BASE, \
  313. BL_CODE_END - BL_CODE_BASE, \
  314. MT_CODE | EL3_PAS), \
  315. MAP_REGION_FLAT( \
  316. BL_RO_DATA_BASE, \
  317. BL_RO_DATA_END \
  318. - BL_RO_DATA_BASE, \
  319. MT_RO_DATA | EL3_PAS)
  320. #else
  321. #define ARM_MAP_BL_RO MAP_REGION_FLAT( \
  322. BL_CODE_BASE, \
  323. BL_CODE_END - BL_CODE_BASE, \
  324. MT_CODE | EL3_PAS)
  325. #endif
  326. #if USE_COHERENT_MEM
  327. #define ARM_MAP_BL_COHERENT_RAM MAP_REGION_FLAT( \
  328. BL_COHERENT_RAM_BASE, \
  329. BL_COHERENT_RAM_END \
  330. - BL_COHERENT_RAM_BASE, \
  331. MT_DEVICE | MT_RW | EL3_PAS)
  332. #endif
  333. #if USE_ROMLIB
  334. #define ARM_MAP_ROMLIB_CODE MAP_REGION_FLAT( \
  335. ROMLIB_RO_BASE, \
  336. ROMLIB_RO_LIMIT - ROMLIB_RO_BASE,\
  337. MT_CODE | EL3_PAS)
  338. #define ARM_MAP_ROMLIB_DATA MAP_REGION_FLAT( \
  339. ROMLIB_RW_BASE, \
  340. ROMLIB_RW_END - ROMLIB_RW_BASE,\
  341. MT_MEMORY | MT_RW | EL3_PAS)
  342. #endif
  343. /*
  344. * Map mem_protect flash region with read and write permissions
  345. */
  346. #define ARM_V2M_MAP_MEM_PROTECT MAP_REGION_FLAT(PLAT_ARM_MEM_PROT_ADDR, \
  347. V2M_FLASH_BLOCK_SIZE, \
  348. MT_DEVICE | MT_RW | MT_SECURE)
  349. /*
  350. * Map the region for device tree configuration with read and write permissions
  351. */
  352. #define ARM_MAP_BL_CONFIG_REGION MAP_REGION_FLAT(ARM_BL_RAM_BASE, \
  353. (ARM_FW_CONFIGS_LIMIT \
  354. - ARM_BL_RAM_BASE), \
  355. MT_MEMORY | MT_RW | EL3_PAS)
  356. /*
  357. * Map L0_GPT with read and write permissions
  358. */
  359. #if ENABLE_RME
  360. #define ARM_MAP_L0_GPT_REGION MAP_REGION_FLAT(ARM_L0_GPT_ADDR_BASE, \
  361. ARM_L0_GPT_SIZE, \
  362. MT_MEMORY | MT_RW | MT_ROOT)
  363. #endif
  364. /*
  365. * The max number of regions like RO(code), coherent and data required by
  366. * different BL stages which need to be mapped in the MMU.
  367. */
  368. #define ARM_BL_REGIONS 7
  369. #define MAX_MMAP_REGIONS (PLAT_ARM_MMAP_ENTRIES + \
  370. ARM_BL_REGIONS)
  371. /* Memory mapped Generic timer interfaces */
  372. #ifdef PLAT_ARM_SYS_CNTCTL_BASE
  373. #define ARM_SYS_CNTCTL_BASE PLAT_ARM_SYS_CNTCTL_BASE
  374. #else
  375. #define ARM_SYS_CNTCTL_BASE UL(0x2a430000)
  376. #endif
  377. #ifdef PLAT_ARM_SYS_CNTREAD_BASE
  378. #define ARM_SYS_CNTREAD_BASE PLAT_ARM_SYS_CNTREAD_BASE
  379. #else
  380. #define ARM_SYS_CNTREAD_BASE UL(0x2a800000)
  381. #endif
  382. #ifdef PLAT_ARM_SYS_TIMCTL_BASE
  383. #define ARM_SYS_TIMCTL_BASE PLAT_ARM_SYS_TIMCTL_BASE
  384. #else
  385. #define ARM_SYS_TIMCTL_BASE UL(0x2a810000)
  386. #endif
  387. #ifdef PLAT_ARM_SYS_CNT_BASE_S
  388. #define ARM_SYS_CNT_BASE_S PLAT_ARM_SYS_CNT_BASE_S
  389. #else
  390. #define ARM_SYS_CNT_BASE_S UL(0x2a820000)
  391. #endif
  392. #ifdef PLAT_ARM_SYS_CNT_BASE_NS
  393. #define ARM_SYS_CNT_BASE_NS PLAT_ARM_SYS_CNT_BASE_NS
  394. #else
  395. #define ARM_SYS_CNT_BASE_NS UL(0x2a830000)
  396. #endif
  397. #define ARM_CONSOLE_BAUDRATE 115200
  398. /* Trusted Watchdog constants */
  399. #ifdef PLAT_ARM_SP805_TWDG_BASE
  400. #define ARM_SP805_TWDG_BASE PLAT_ARM_SP805_TWDG_BASE
  401. #else
  402. #define ARM_SP805_TWDG_BASE UL(0x2a490000)
  403. #endif
  404. #define ARM_SP805_TWDG_CLK_HZ 32768
  405. /* The TBBR document specifies a watchdog timeout of 256 seconds. SP805
  406. * asserts reset after two consecutive countdowns (2 x 128 = 256 sec) */
  407. #define ARM_TWDG_TIMEOUT_SEC 128
  408. #define ARM_TWDG_LOAD_VAL (ARM_SP805_TWDG_CLK_HZ * \
  409. ARM_TWDG_TIMEOUT_SEC)
  410. /******************************************************************************
  411. * Required platform porting definitions common to all ARM standard platforms
  412. *****************************************************************************/
  413. /*
  414. * This macro defines the deepest retention state possible. A higher state
  415. * id will represent an invalid or a power down state.
  416. */
  417. #define PLAT_MAX_RET_STATE ARM_LOCAL_STATE_RET
  418. /*
  419. * This macro defines the deepest power down states possible. Any state ID
  420. * higher than this is invalid.
  421. */
  422. #define PLAT_MAX_OFF_STATE ARM_LOCAL_STATE_OFF
  423. /*
  424. * Some data must be aligned on the biggest cache line size in the platform.
  425. * This is known only to the platform as it might have a combination of
  426. * integrated and external caches.
  427. */
  428. #define CACHE_WRITEBACK_GRANULE (U(1) << ARM_CACHE_WRITEBACK_SHIFT)
  429. /*
  430. * To enable FW_CONFIG to be loaded by BL1, define the corresponding base
  431. * and limit. Leave enough space of BL2 meminfo.
  432. */
  433. #define ARM_FW_CONFIG_BASE (ARM_BL_RAM_BASE + sizeof(meminfo_t))
  434. #define ARM_FW_CONFIG_LIMIT ((ARM_BL_RAM_BASE + PAGE_SIZE) \
  435. + (PAGE_SIZE / 2U))
  436. /*
  437. * Boot parameters passed from BL2 to BL31/BL32 are stored here
  438. */
  439. #define ARM_BL2_MEM_DESC_BASE (ARM_FW_CONFIG_LIMIT)
  440. #define ARM_BL2_MEM_DESC_LIMIT (ARM_BL2_MEM_DESC_BASE \
  441. + (PAGE_SIZE / 2U))
  442. /*
  443. * Define limit of firmware configuration memory:
  444. * ARM_FW_CONFIG + ARM_BL2_MEM_DESC memory
  445. */
  446. #define ARM_FW_CONFIGS_LIMIT (ARM_BL_RAM_BASE + (PAGE_SIZE * 2))
  447. #if ENABLE_RME
  448. /*
  449. * Store the L0 GPT on Trusted SRAM next to firmware
  450. * configuration memory, 4KB aligned.
  451. */
  452. #define ARM_L0_GPT_SIZE (PAGE_SIZE)
  453. #define ARM_L0_GPT_ADDR_BASE (ARM_FW_CONFIGS_LIMIT)
  454. #define ARM_L0_GPT_LIMIT (ARM_L0_GPT_ADDR_BASE + ARM_L0_GPT_SIZE)
  455. #else
  456. #define ARM_L0_GPT_SIZE U(0)
  457. #endif
  458. /*******************************************************************************
  459. * BL1 specific defines.
  460. * BL1 RW data is relocated from ROM to RAM at runtime so we need 2 sets of
  461. * addresses.
  462. ******************************************************************************/
  463. #define BL1_RO_BASE PLAT_ARM_TRUSTED_ROM_BASE
  464. #ifdef PLAT_BL1_RO_LIMIT
  465. #define BL1_RO_LIMIT PLAT_BL1_RO_LIMIT
  466. #else
  467. #define BL1_RO_LIMIT (PLAT_ARM_TRUSTED_ROM_BASE \
  468. + (PLAT_ARM_TRUSTED_ROM_SIZE - \
  469. PLAT_ARM_MAX_ROMLIB_RO_SIZE))
  470. #endif
  471. /*
  472. * Put BL1 RW at the top of the Trusted SRAM.
  473. */
  474. #define BL1_RW_BASE (ARM_BL_RAM_BASE + \
  475. ARM_BL_RAM_SIZE - \
  476. (PLAT_ARM_MAX_BL1_RW_SIZE +\
  477. PLAT_ARM_MAX_ROMLIB_RW_SIZE))
  478. #define BL1_RW_LIMIT (ARM_BL_RAM_BASE + \
  479. (ARM_BL_RAM_SIZE - PLAT_ARM_MAX_ROMLIB_RW_SIZE))
  480. #define ROMLIB_RO_BASE BL1_RO_LIMIT
  481. #define ROMLIB_RO_LIMIT (PLAT_ARM_TRUSTED_ROM_BASE + PLAT_ARM_TRUSTED_ROM_SIZE)
  482. #define ROMLIB_RW_BASE (BL1_RW_BASE + PLAT_ARM_MAX_BL1_RW_SIZE)
  483. #define ROMLIB_RW_END (ROMLIB_RW_BASE + PLAT_ARM_MAX_ROMLIB_RW_SIZE)
  484. /*******************************************************************************
  485. * BL2 specific defines.
  486. ******************************************************************************/
  487. #if BL2_AT_EL3
  488. #if ENABLE_PIE
  489. /*
  490. * As the BL31 image size appears to be increased when built with the ENABLE_PIE
  491. * option, set BL2 base address to have enough space for BL31 in Trusted SRAM.
  492. */
  493. #define BL2_BASE (ARM_TRUSTED_SRAM_BASE + \
  494. (PLAT_ARM_TRUSTED_SRAM_SIZE >> 1) + \
  495. 0x3000)
  496. #else
  497. /* Put BL2 towards the middle of the Trusted SRAM */
  498. #define BL2_BASE (ARM_TRUSTED_SRAM_BASE + \
  499. (PLAT_ARM_TRUSTED_SRAM_SIZE >> 1) + \
  500. 0x2000)
  501. #endif /* ENABLE_PIE */
  502. #define BL2_LIMIT (ARM_BL_RAM_BASE + ARM_BL_RAM_SIZE)
  503. #else
  504. /*
  505. * Put BL2 just below BL1.
  506. */
  507. #define BL2_BASE (BL1_RW_BASE - PLAT_ARM_MAX_BL2_SIZE)
  508. #define BL2_LIMIT BL1_RW_BASE
  509. #endif
  510. /*******************************************************************************
  511. * BL31 specific defines.
  512. ******************************************************************************/
  513. #if ARM_BL31_IN_DRAM || SEPARATE_NOBITS_REGION
  514. /*
  515. * Put BL31 at the bottom of TZC secured DRAM
  516. */
  517. #define BL31_BASE ARM_AP_TZC_DRAM1_BASE
  518. #define BL31_LIMIT (ARM_AP_TZC_DRAM1_BASE + \
  519. PLAT_ARM_MAX_BL31_SIZE)
  520. /*
  521. * For SEPARATE_NOBITS_REGION, BL31 PROGBITS are loaded in TZC secured DRAM.
  522. * And BL31 NOBITS are loaded in Trusted SRAM such that BL2 is overwritten.
  523. */
  524. #if SEPARATE_NOBITS_REGION
  525. #define BL31_NOBITS_BASE BL2_BASE
  526. #define BL31_NOBITS_LIMIT BL2_LIMIT
  527. #endif /* SEPARATE_NOBITS_REGION */
  528. #elif (RESET_TO_BL31)
  529. /* Ensure Position Independent support (PIE) is enabled for this config.*/
  530. # if !ENABLE_PIE
  531. # error "BL31 must be a PIE if RESET_TO_BL31=1."
  532. #endif
  533. /*
  534. * Since this is PIE, we can define BL31_BASE to 0x0 since this macro is solely
  535. * used for building BL31 and not used for loading BL31.
  536. */
  537. # define BL31_BASE 0x0
  538. # define BL31_LIMIT PLAT_ARM_MAX_BL31_SIZE
  539. #else
  540. /* Put BL31 below BL2 in the Trusted SRAM.*/
  541. #define BL31_BASE ((ARM_BL_RAM_BASE + ARM_BL_RAM_SIZE)\
  542. - PLAT_ARM_MAX_BL31_SIZE)
  543. #define BL31_PROGBITS_LIMIT BL2_BASE
  544. /*
  545. * For BL2_AT_EL3 make sure the BL31 can grow up until BL2_BASE. This is
  546. * because in the BL2_AT_EL3 configuration, BL2 is always resident.
  547. */
  548. #if BL2_AT_EL3
  549. #define BL31_LIMIT BL2_BASE
  550. #else
  551. #define BL31_LIMIT (ARM_BL_RAM_BASE + ARM_BL_RAM_SIZE)
  552. #endif
  553. #endif
  554. /******************************************************************************
  555. * RMM specific defines
  556. *****************************************************************************/
  557. #if ENABLE_RME
  558. #define RMM_BASE (ARM_REALM_BASE)
  559. #define RMM_LIMIT (RMM_BASE + ARM_REALM_SIZE)
  560. #define RMM_SHARED_BASE (ARM_EL3_RMM_SHARED_BASE)
  561. #define RMM_SHARED_SIZE (ARM_EL3_RMM_SHARED_SIZE)
  562. #endif
  563. #if !defined(__aarch64__) || JUNO_AARCH32_EL3_RUNTIME
  564. /*******************************************************************************
  565. * BL32 specific defines for EL3 runtime in AArch32 mode
  566. ******************************************************************************/
  567. # if RESET_TO_SP_MIN && !JUNO_AARCH32_EL3_RUNTIME
  568. /* Ensure Position Independent support (PIE) is enabled for this config.*/
  569. # if !ENABLE_PIE
  570. # error "BL32 must be a PIE if RESET_TO_SP_MIN=1."
  571. #endif
  572. /*
  573. * Since this is PIE, we can define BL32_BASE to 0x0 since this macro is solely
  574. * used for building BL32 and not used for loading BL32.
  575. */
  576. # define BL32_BASE 0x0
  577. # define BL32_LIMIT PLAT_ARM_MAX_BL32_SIZE
  578. # else
  579. /* Put BL32 below BL2 in the Trusted SRAM.*/
  580. # define BL32_BASE ((ARM_BL_RAM_BASE + ARM_BL_RAM_SIZE)\
  581. - PLAT_ARM_MAX_BL32_SIZE)
  582. # define BL32_PROGBITS_LIMIT BL2_BASE
  583. # define BL32_LIMIT (ARM_BL_RAM_BASE + ARM_BL_RAM_SIZE)
  584. # endif /* RESET_TO_SP_MIN && !JUNO_AARCH32_EL3_RUNTIME */
  585. #else
  586. /*******************************************************************************
  587. * BL32 specific defines for EL3 runtime in AArch64 mode
  588. ******************************************************************************/
  589. /*
  590. * On ARM standard platforms, the TSP can execute from Trusted SRAM,
  591. * Trusted DRAM (if available) or the DRAM region secured by the TrustZone
  592. * controller.
  593. */
  594. # if SPM_MM || SPMC_AT_EL3
  595. # define TSP_SEC_MEM_BASE (ARM_AP_TZC_DRAM1_BASE + ULL(0x200000))
  596. # define TSP_SEC_MEM_SIZE (ARM_AP_TZC_DRAM1_SIZE - ULL(0x200000))
  597. # define BL32_BASE (ARM_AP_TZC_DRAM1_BASE + ULL(0x200000))
  598. # define BL32_LIMIT (ARM_AP_TZC_DRAM1_BASE + \
  599. ARM_AP_TZC_DRAM1_SIZE)
  600. # elif defined(SPD_spmd)
  601. # define TSP_SEC_MEM_BASE (ARM_AP_TZC_DRAM1_BASE + ULL(0x200000))
  602. # define TSP_SEC_MEM_SIZE (ARM_AP_TZC_DRAM1_SIZE - ULL(0x200000))
  603. # define BL32_BASE PLAT_ARM_SPMC_BASE
  604. # define BL32_LIMIT (PLAT_ARM_SPMC_BASE + \
  605. PLAT_ARM_SPMC_SIZE)
  606. # elif ARM_BL31_IN_DRAM
  607. # define TSP_SEC_MEM_BASE (ARM_AP_TZC_DRAM1_BASE + \
  608. PLAT_ARM_MAX_BL31_SIZE)
  609. # define TSP_SEC_MEM_SIZE (ARM_AP_TZC_DRAM1_SIZE - \
  610. PLAT_ARM_MAX_BL31_SIZE)
  611. # define BL32_BASE (ARM_AP_TZC_DRAM1_BASE + \
  612. PLAT_ARM_MAX_BL31_SIZE)
  613. # define BL32_LIMIT (ARM_AP_TZC_DRAM1_BASE + \
  614. ARM_AP_TZC_DRAM1_SIZE)
  615. # elif ARM_TSP_RAM_LOCATION_ID == ARM_TRUSTED_SRAM_ID
  616. # define TSP_SEC_MEM_BASE ARM_BL_RAM_BASE
  617. # define TSP_SEC_MEM_SIZE ARM_BL_RAM_SIZE
  618. # define TSP_PROGBITS_LIMIT BL31_BASE
  619. # define BL32_BASE ARM_FW_CONFIGS_LIMIT
  620. # define BL32_LIMIT BL31_BASE
  621. # elif ARM_TSP_RAM_LOCATION_ID == ARM_TRUSTED_DRAM_ID
  622. # define TSP_SEC_MEM_BASE PLAT_ARM_TRUSTED_DRAM_BASE
  623. # define TSP_SEC_MEM_SIZE PLAT_ARM_TRUSTED_DRAM_SIZE
  624. # define BL32_BASE PLAT_ARM_TRUSTED_DRAM_BASE
  625. # define BL32_LIMIT (PLAT_ARM_TRUSTED_DRAM_BASE \
  626. + (UL(1) << 21))
  627. # elif ARM_TSP_RAM_LOCATION_ID == ARM_DRAM_ID
  628. # define TSP_SEC_MEM_BASE ARM_AP_TZC_DRAM1_BASE
  629. # define TSP_SEC_MEM_SIZE ARM_AP_TZC_DRAM1_SIZE
  630. # define BL32_BASE ARM_AP_TZC_DRAM1_BASE
  631. # define BL32_LIMIT (ARM_AP_TZC_DRAM1_BASE + \
  632. ARM_AP_TZC_DRAM1_SIZE)
  633. # else
  634. # error "Unsupported ARM_TSP_RAM_LOCATION_ID value"
  635. # endif
  636. #endif /* !__aarch64__ || JUNO_AARCH32_EL3_RUNTIME */
  637. /*
  638. * BL32 is mandatory in AArch32. In AArch64, undefine BL32_BASE if there is no
  639. * SPD and no SPM-MM and no SPMC-AT-EL3, as they are the only ones that can be
  640. * used as BL32.
  641. */
  642. #if defined(__aarch64__) && !JUNO_AARCH32_EL3_RUNTIME
  643. # if defined(SPD_none) && !SPM_MM && !SPMC_AT_EL3
  644. # undef BL32_BASE
  645. # endif /* defined(SPD_none) && !SPM_MM || !SPMC_AT_EL3 */
  646. #endif /* defined(__aarch64__) && !JUNO_AARCH32_EL3_RUNTIME */
  647. /*******************************************************************************
  648. * FWU Images: NS_BL1U, BL2U & NS_BL2U defines.
  649. ******************************************************************************/
  650. #define BL2U_BASE BL2_BASE
  651. #define BL2U_LIMIT BL2_LIMIT
  652. #define NS_BL2U_BASE ARM_NS_DRAM1_BASE
  653. #define NS_BL1U_BASE (PLAT_ARM_NVM_BASE + UL(0x03EB8000))
  654. /*
  655. * ID of the secure physical generic timer interrupt used by the TSP.
  656. */
  657. #define TSP_IRQ_SEC_PHY_TIMER ARM_IRQ_SEC_PHY_TIMER
  658. /*
  659. * One cache line needed for bakery locks on ARM platforms
  660. */
  661. #define PLAT_PERCPU_BAKERY_LOCK_SIZE (1 * CACHE_WRITEBACK_GRANULE)
  662. /* Priority levels for ARM platforms */
  663. #define PLAT_RAS_PRI 0x10
  664. #define PLAT_SDEI_CRITICAL_PRI 0x60
  665. #define PLAT_SDEI_NORMAL_PRI 0x70
  666. /* ARM platforms use 3 upper bits of secure interrupt priority */
  667. #define PLAT_PRI_BITS 3
  668. /* SGI used for SDEI signalling */
  669. #define ARM_SDEI_SGI ARM_IRQ_SEC_SGI_0
  670. #if SDEI_IN_FCONF
  671. /* ARM SDEI dynamic private event max count */
  672. #define ARM_SDEI_DP_EVENT_MAX_CNT 3
  673. /* ARM SDEI dynamic shared event max count */
  674. #define ARM_SDEI_DS_EVENT_MAX_CNT 3
  675. #else
  676. /* ARM SDEI dynamic private event numbers */
  677. #define ARM_SDEI_DP_EVENT_0 1000
  678. #define ARM_SDEI_DP_EVENT_1 1001
  679. #define ARM_SDEI_DP_EVENT_2 1002
  680. /* ARM SDEI dynamic shared event numbers */
  681. #define ARM_SDEI_DS_EVENT_0 2000
  682. #define ARM_SDEI_DS_EVENT_1 2001
  683. #define ARM_SDEI_DS_EVENT_2 2002
  684. #define ARM_SDEI_PRIVATE_EVENTS \
  685. SDEI_DEFINE_EVENT_0(ARM_SDEI_SGI), \
  686. SDEI_PRIVATE_EVENT(ARM_SDEI_DP_EVENT_0, SDEI_DYN_IRQ, SDEI_MAPF_DYNAMIC), \
  687. SDEI_PRIVATE_EVENT(ARM_SDEI_DP_EVENT_1, SDEI_DYN_IRQ, SDEI_MAPF_DYNAMIC), \
  688. SDEI_PRIVATE_EVENT(ARM_SDEI_DP_EVENT_2, SDEI_DYN_IRQ, SDEI_MAPF_DYNAMIC)
  689. #define ARM_SDEI_SHARED_EVENTS \
  690. SDEI_SHARED_EVENT(ARM_SDEI_DS_EVENT_0, SDEI_DYN_IRQ, SDEI_MAPF_DYNAMIC), \
  691. SDEI_SHARED_EVENT(ARM_SDEI_DS_EVENT_1, SDEI_DYN_IRQ, SDEI_MAPF_DYNAMIC), \
  692. SDEI_SHARED_EVENT(ARM_SDEI_DS_EVENT_2, SDEI_DYN_IRQ, SDEI_MAPF_DYNAMIC)
  693. #endif /* SDEI_IN_FCONF */
  694. #endif /* ARM_DEF_H */