platform_def.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  1. /*
  2. * Copyright (c) 2015-2023, ARM Limited and Contributors. All rights reserved.
  3. *
  4. * Copyright (c) 2017-2023 Nuvoton Technology Corp.
  5. *
  6. * SPDX-License-Identifier: BSD-3-Clause
  7. */
  8. #ifndef PLATFORM_DEF_H
  9. #define PLATFORM_DEF_H
  10. #include <arch.h>
  11. #include <common/interrupt_props.h>
  12. #include <common/tbbr/tbbr_img_def.h>
  13. #include <drivers/arm/gic_common.h>
  14. #include <lib/utils_def.h>
  15. #include <lib/xlat_tables/xlat_tables_defs.h>
  16. #include <npcm845x_arm_def.h>
  17. #include <plat/arm/common/smccc_def.h>
  18. #include <plat/common/common_def.h>
  19. #define VALUE_TO_STRING(x) #x
  20. #define VALUE(x) VALUE_TO_STRING(x)
  21. #define VAR_NAME_VALUE(var) #var "=" VALUE(var)
  22. #define PLATFORM_LINKER_FORMAT "elf64-littleaarch64"
  23. #define PLATFORM_LINKER_ARCH aarch64
  24. #define PLATFORM_STACK_SIZE 0x400
  25. #define PLATFORM_CORE_COUNT NPCM845x_PLATFORM_CORE_COUNT
  26. #define PLATFORM_CLUSTER_COUNT NPCM845x_CLUSTER_COUNT
  27. #define PLATFORM_MAX_CPU_PER_CLUSTER NPCM845x_MAX_CPU_PER_CLUSTER
  28. #define PLAT_PRIMARY_CPU NPCM845x_PLAT_PRIMARY_CPU
  29. #define PLATFORM_SYSTEM_COUNT NPCM845x_SYSTEM_COUNT
  30. /* Local power state for power domains in Run state. */
  31. #define PLAT_LOCAL_STATE_RUN U(0)
  32. /* Local power state for retention. Valid only for CPU power domains */
  33. #define PLAT_LOCAL_STATE_RET U(1)
  34. /*
  35. * Local power state for OFF/power-down. Valid for CPU and cluster power
  36. * domains.
  37. */
  38. #define PLAT_LOCAL_STATE_OFF U(2)
  39. /*
  40. * This macro defines the deepest power down states possible. Any state ID
  41. * higher than this is invalid.
  42. */
  43. #define PLAT_MAX_OFF_STATE PLAT_LOCAL_STATE_OFF
  44. #define PLAT_MAX_RET_STATE PLAT_LOCAL_STATE_RET
  45. #define PLAT_NUM_PWR_DOMAINS (PLATFORM_CLUSTER_COUNT + PLATFORM_CORE_COUNT)
  46. #define NPCM845x_MAX_PWR_LVL ARM_PWR_LVL1
  47. /*
  48. * Macros used to parse state information from State-ID if it is using the
  49. * recommended encoding for State-ID.
  50. */
  51. #define PLAT_LOCAL_PSTATE_WIDTH 4
  52. #define PLAT_LOCAL_PSTATE_MASK ((1 << PLAT_LOCAL_PSTATE_WIDTH) - 1)
  53. /*
  54. * Required ARM standard platform porting definitions
  55. */
  56. #define PLAT_ARM_CLUSTER_COUNT PLATFORM_CLUSTER_COUNT
  57. #define PLAT_NUM_PWR_DOMAINS (PLATFORM_CLUSTER_COUNT + PLATFORM_CORE_COUNT)
  58. #define PLAT_MAX_PWR_LVL NPCM845x_MAX_PWR_LVL
  59. #define PLAT_LOCAL_PSTATE_WIDTH 4
  60. #define PLAT_LOCAL_PSTATE_MASK ((1 << PLAT_LOCAL_PSTATE_WIDTH) - 1)
  61. #ifdef BL32_BASE
  62. #ifndef CONFIG_TARGET_ARBEL_PALLADIUM
  63. #define PLAT_ARM_TRUSTED_DRAM_BASE BL32_BASE
  64. #else
  65. #define PLAT_ARM_TRUSTED_DRAM_BASE BL32_BASE
  66. #endif /* CONFIG_TARGET_ARBEL_PALLADIUM */
  67. #define PLAT_ARM_TRUSTED_DRAM_SIZE UL(0x02000000) /* 32 MB */
  68. #endif /* BL32_BASE */
  69. #define PWR_DOMAIN_AT_MAX_LVL U(1)
  70. #define PLAT_VIRT_ADDR_SPACE_SIZE (1ull << 32)
  71. #define PLAT_PHY_ADDR_SPACE_SIZE (1ull << 32)
  72. #define MAX_XLAT_TABLES 16
  73. #define PLAT_ARM_MMAP_ENTRIES 17
  74. #ifdef NPCM845X_DEBUG
  75. #define MAX_MMAP_REGIONS 8
  76. #define NPCM845X_TZ1_BASE 0xFFFB0000
  77. #endif /* NPCM845X_DEBUG */
  78. #define FIQ_SMP_CALL_SGI 10
  79. /* (0x00040000) 128 KB, the rest 128K if it is non secured */
  80. #define PLAT_ARM_TRUSTED_SRAM_SIZE UL(0x00020000)
  81. #define ARM_SHARED_RAM_SIZE UL(0x00001000) /* 4 KB */
  82. /* UL(0xfffCE000) add calc ARM_TRUSTED_SRAM_BASE */
  83. #define ARM_SHARED_RAM_BASE (BL31_BASE + 0x00020000 - ARM_SHARED_RAM_SIZE)
  84. /* The remaining Trusted SRAM is used to load the BL images */
  85. #define ARM_BL_RAM_BASE (ARM_SHARED_RAM_BASE + ARM_SHARED_RAM_SIZE)
  86. /*
  87. * PLAT_ARM_TRUSTED_SRAM_SIZE is taken from platform_def.h 0x20000
  88. * because only half is secured in this specific implementation
  89. */
  90. #define ARM_BL_RAM_SIZE (PLAT_ARM_TRUSTED_SRAM_SIZE - ARM_SHARED_RAM_SIZE)
  91. #if RESET_TO_BL31
  92. /* Size of Trusted SRAM - the first 4KB of shared memory */
  93. #define PLAT_ARM_MAX_BL31_SIZE \
  94. (PLAT_ARM_TRUSTED_SRAM_SIZE - ARM_SHARED_RAM_SIZE)
  95. #else
  96. /*
  97. * Since BL31 NOBITS overlays BL2 and BL1-RW, PLAT_ARM_MAX_BL31_SIZE
  98. * is calculated using the current BL31 PROGBITS debug size plus the sizes
  99. * of BL2 and BL1-RW
  100. */
  101. #define PLAT_ARM_MAX_BL31_SIZE \
  102. (PLAT_ARM_TRUSTED_SRAM_SIZE - ARM_SHARED_RAM_SIZE)
  103. #endif /* RESET_TO_BL31 */
  104. /*
  105. * Load address of BL33 for this platform port
  106. */
  107. #define PLAT_ARM_NS_IMAGE_BASE (ARM_DRAM1_BASE + UL(0x6208000))
  108. #define PLAT_ARM_NSTIMER_FRAME_ID U(1)
  109. /* GIC parameters */
  110. /* Base compatible GIC memory map */
  111. #define NT_GIC_BASE (0xDFFF8000)
  112. #define BASE_GICD_BASE (NT_GIC_BASE + 0x1000)
  113. #define BASE_GICC_BASE (NT_GIC_BASE + 0x2000)
  114. #define BASE_GICR_BASE (NT_GIC_BASE + 0x200000)
  115. #define BASE_GICH_BASE (NT_GIC_BASE + 0x4000)
  116. #define BASE_GICV_BASE (NT_GIC_BASE + 0x6000)
  117. #define DEVICE1_BASE BASE_GICD_BASE
  118. #define DEVICE1_SIZE 0x7000
  119. #ifdef NPCM845X_DEBUG
  120. /* ((BASE_GICR_BASE - BASE_GICD_BASE) + (PLATFORM_CORE_COUNT * 0x20000)) */
  121. #define ARM_CPU_START_ADDRESS(m) UL(0xf0800e00 + 0x10 + m * 4)
  122. #endif /* NPCM845X_DEBUG */
  123. #define PLAT_REG_BASE NPCM845x_REG_BASE
  124. #define PLAT_REG_SIZE NPCM845x_REG_SIZE
  125. /* MMU entry for internal (register) space access */
  126. #define MAP_DEVICE0 \
  127. MAP_REGION_FLAT(PLAT_REG_BASE, PLAT_REG_SIZE, \
  128. MT_DEVICE | MT_RW | MT_SECURE)
  129. #define MAP_DEVICE1 \
  130. MAP_REGION_FLAT(DEVICE1_BASE, DEVICE1_SIZE, \
  131. MT_DEVICE | MT_RW | MT_SECURE)
  132. /*
  133. * Define a list of Group 1 Secure and Group 0 interrupt properties
  134. * as per GICv3 terminology. On a GICv2 system or mode,
  135. * the lists will be merged and treated as Group 0 interrupts.
  136. */
  137. #define PLAT_ARM_GICD_BASE BASE_GICD_BASE
  138. #define PLAT_ARM_GICC_BASE BASE_GICC_BASE
  139. #define PLAT_ARM_G1S_IRQ_PROPS(grp) \
  140. INTR_PROP_DESC(ARM_IRQ_SEC_PHY_TIMER, GIC_HIGHEST_SEC_PRIORITY, grp, \
  141. GIC_INTR_CFG_LEVEL), \
  142. INTR_PROP_DESC(ARM_IRQ_SEC_SGI_0, GIC_HIGHEST_SEC_PRIORITY, \
  143. grp, GIC_INTR_CFG_EDGE), \
  144. INTR_PROP_DESC(ARM_IRQ_SEC_SGI_1, GIC_HIGHEST_SEC_PRIORITY, \
  145. grp, GIC_INTR_CFG_EDGE), \
  146. INTR_PROP_DESC(ARM_IRQ_SEC_SGI_2, GIC_HIGHEST_SEC_PRIORITY, \
  147. grp, GIC_INTR_CFG_EDGE), \
  148. INTR_PROP_DESC(ARM_IRQ_SEC_SGI_3, GIC_HIGHEST_SEC_PRIORITY, \
  149. grp, GIC_INTR_CFG_EDGE), \
  150. INTR_PROP_DESC(ARM_IRQ_SEC_SGI_4, GIC_HIGHEST_SEC_PRIORITY, \
  151. grp, GIC_INTR_CFG_EDGE), \
  152. INTR_PROP_DESC(ARM_IRQ_SEC_SGI_5, GIC_HIGHEST_SEC_PRIORITY, \
  153. grp, GIC_INTR_CFG_EDGE), \
  154. INTR_PROP_DESC(ARM_IRQ_SEC_SGI_6, GIC_HIGHEST_SEC_PRIORITY, \
  155. grp, GIC_INTR_CFG_EDGE), \
  156. INTR_PROP_DESC(ARM_IRQ_SEC_SGI_7, GIC_HIGHEST_SEC_PRIORITY, \
  157. grp, GIC_INTR_CFG_EDGE)
  158. #define PLAT_ARM_G0_IRQ_PROPS(grp)
  159. /* Required for compilation: */
  160. /*
  161. * PLAT_ARM_MAX_BL1_RW_SIZE is calculated using the current BL1 RW debug size
  162. * plus a little space for growth.
  163. */
  164. #define PLAT_ARM_MAX_BL1_RW_SIZE 0 /* UL(0xB000) */
  165. #if USE_ROMLIB
  166. #define PLAT_ARM_MAX_ROMLIB_RW_SIZE UL(0x1000)
  167. #define PLAT_ARM_MAX_ROMLIB_RO_SIZE UL(0xe000)
  168. #define FVP_BL2_ROMLIB_OPTIMIZATION UL(0x6000)
  169. #else
  170. #define PLAT_ARM_MAX_ROMLIB_RW_SIZE UL(0)
  171. #define PLAT_ARM_MAX_ROMLIB_RO_SIZE UL(0)
  172. #define FVP_BL2_ROMLIB_OPTIMIZATION UL(0)
  173. #endif /* USE_ROMLIB */
  174. /*
  175. * PLAT_ARM_MAX_BL2_SIZE is calculated using the current BL2 debug size
  176. * plus a little space for growth.
  177. */
  178. #if TRUSTED_BOARD_BOOT
  179. #define PLAT_ARM_MAX_BL2_SIZE (UL(0x1D000) * FVP_BL2_ROMLIB_OPTIMIZATION)
  180. #else
  181. /* (UL(0x13000) - FVP_BL2_ROMLIB_OPTIMIZATION) */
  182. #define PLAT_ARM_MAX_BL2_SIZE 0
  183. #endif /* TRUSTED_BOARD_BOOT */
  184. #undef NPCM_PRINT_ONCE
  185. #ifdef NPCM_PRINT_ONCE
  186. #define PRINT_ONLY_ONCE
  187. #pragma message(VAR_NAME_VALUE(ARM_AP_TZC_DRAM1_BASE))
  188. #pragma message(VAR_NAME_VALUE(BL31_BASE))
  189. #pragma message(VAR_NAME_VALUE(BL31_LIMIT))
  190. #pragma message(VAR_NAME_VALUE(PLAT_ARM_MAX_BL31_SIZE))
  191. #pragma message(VAR_NAME_VALUE(BL32_BASE))
  192. #pragma message(VAR_NAME_VALUE(BL32_LIMIT))
  193. #pragma message(VAR_NAME_VALUE(PLAT_ARM_MAX_BL32_SIZE)
  194. #pragma message(VAR_NAME_VALUE(SPMD_SPM_AT_SEL2_KKO))
  195. #endif /* NPCM_PRINT_ONCE */
  196. #define MAX_IO_DEVICES 4
  197. #define MAX_IO_HANDLES 4
  198. #define PLAT_ARM_FIP_BASE 0x0
  199. #define PLAT_ARM_FIP_MAX_SIZE PLAT_ARM_MAX_BL31_SIZE
  200. #define PLAT_ARM_BOOT_UART_BASE 0xF0000000
  201. #define PLAT_ARM_BOOT_UART_CLK_IN_HZ 115200
  202. #define PLAT_ARM_RUN_UART_BASE 0xF0000000
  203. #define PLAT_ARM_RUN_UART_CLK_IN_HZ 115200
  204. #define PLAT_ARM_CRASH_UART_BASE 0xF0000000
  205. #define PLAT_ARM_CRASH_UART_CLK_IN_HZ 115200
  206. /*
  207. * Mailbox to control the secondary cores.All secondary cores are held in a wait
  208. * loop in cold boot. To release them perform the following steps (plus any
  209. * additional barriers that may be needed):
  210. *
  211. * uint64_t *entrypoint = (uint64_t *)PLAT_NPCM_TM_ENTRYPOINT;
  212. * *entrypoint = ADDRESS_TO_JUMP_TO;
  213. *
  214. * uint64_t *mbox_entry = (uint64_t *)PLAT_NPCM_TM_HOLD_BASE;
  215. * mbox_entry[cpu_id] = PLAT_NPCM_TM_HOLD_BASE;
  216. *
  217. * sev();
  218. */
  219. #define PLAT_NPCM_TRUSTED_MAILBOX_BASE ARM_SHARED_RAM_BASE
  220. /* The secure entry point to be used on warm reset by all CPUs. */
  221. #define PLAT_NPCM_TM_ENTRYPOINT PLAT_NPCM_TRUSTED_MAILBOX_BASE
  222. #define PLAT_NPCM_TM_ENTRYPOINT_SIZE ULL(8)
  223. /* Hold entries for each CPU. */
  224. #define PLAT_NPCM_TM_HOLD_BASE \
  225. (PLAT_NPCM_TM_ENTRYPOINT + PLAT_NPCM_TM_ENTRYPOINT_SIZE)
  226. #define PLAT_NPCM_TM_HOLD_ENTRY_SIZE ULL(8)
  227. #define PLAT_NPCM_TM_HOLD_SIZE \
  228. (PLAT_NPCM_TM_HOLD_ENTRY_SIZE * PLATFORM_CORE_COUNT)
  229. #define PLAT_NPCM_TRUSTED_NOTIFICATION_BASE \
  230. (PLAT_NPCM_TM_ENTRYPOINT_SIZE + PLAT_NPCM_TM_HOLD_SIZE)
  231. #define PLAT_NPCM_TRUSTED_NOTIFICATION_ENTRY_SIZE ULL(8)
  232. #define PLAT_NPCM_TRUSTED_NOTIFICATION_SIZE \
  233. (PLAT_NPCM_TRUSTED_NOTIFICATION_ENTRY_SIZE * PLATFORM_CORE_COUNT)
  234. #define PLAT_NPCM_TRUSTED_MAILBOX_SIZE \
  235. (PLAT_NPCM_TM_ENTRYPOINT_SIZE + PLAT_NPCM_TM_HOLD_SIZE + \
  236. PLAT_NPCM_TRUSTED_NOTIFICATION_ENTRY_SIZE)
  237. #define PLAT_NPCM_TM_HOLD_STATE_WAIT ULL(0)
  238. #define PLAT_NPCM_TM_HOLD_STATE_GO ULL(1)
  239. #define PLAT_NPCM_TM_HOLD_STATE_BSP_OFF ULL(2)
  240. #define PLAT_NPCM_TM_NOTIFICATION_START ULL(0xAA)
  241. #define PLAT_NPCM_TM_NOTIFICATION_BR ULL(0xCC)
  242. #ifdef NPCM845X_DEBUG
  243. #define PLAT_ARM_TRUSTED_MAILBOX_BASE 0xfffB0000
  244. #endif /* NPCM845X_DEBUG */
  245. #endif /* PLATFORM_DEF_H */