platform_common.c 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  1. /*
  2. * Copyright (c) 2013-2014, ARM Limited and Contributors. All rights reserved.
  3. * Copyright (c) 2015-2023, Renesas Electronics Corporation. All rights reserved.
  4. *
  5. * SPDX-License-Identifier: BSD-3-Clause
  6. */
  7. #include <platform_def.h>
  8. #include <arch.h>
  9. #include <arch_helpers.h>
  10. #include <common/bl_common.h>
  11. #include <common/debug.h>
  12. #include <common/interrupt_props.h>
  13. #include <drivers/arm/gicv2.h>
  14. #include <drivers/arm/gic_common.h>
  15. #include <lib/mmio.h>
  16. #include <lib/xlat_tables/xlat_tables_v2.h>
  17. #include <plat/common/platform.h>
  18. #include "rcar_def.h"
  19. #include "rcar_private.h"
  20. #include "rcar_version.h"
  21. #if (IMAGE_BL2)
  22. extern void rcar_read_certificate(uint64_t cert, uint32_t *len, uintptr_t *p);
  23. extern int32_t rcar_get_certificate(const int32_t name, uint32_t *cert);
  24. #endif
  25. const uint8_t version_of_renesas[VERSION_OF_RENESAS_MAXLEN]
  26. __attribute__ ((__section__(".ro"))) = VERSION_OF_RENESAS;
  27. #if (IMAGE_BL2) && (RCAR_BL2_DCACHE != 1)
  28. #define RCAR_DCACHE MT_NON_CACHEABLE
  29. #else
  30. #define RCAR_DCACHE MT_MEMORY
  31. #endif
  32. #define MAP_SHARED_RAM MAP_REGION_FLAT(RCAR_SHARED_MEM_BASE, \
  33. RCAR_SHARED_MEM_SIZE, \
  34. MT_MEMORY | MT_RW | MT_SECURE)
  35. #define MAP_FLASH0 MAP_REGION_FLAT(FLASH0_BASE, \
  36. FLASH0_SIZE, \
  37. RCAR_DCACHE | MT_RO | MT_SECURE)
  38. #define MAP_DRAM1_NS MAP_REGION_FLAT(DRAM1_NS_BASE, \
  39. DRAM1_NS_SIZE, \
  40. MT_MEMORY | MT_RW | MT_NS)
  41. #define MAP_DEVICE_RCAR MAP_REGION_FLAT(DEVICE_RCAR_BASE, \
  42. DEVICE_RCAR_SIZE, \
  43. MT_DEVICE | MT_RW | MT_SECURE)
  44. #define MAP_DEVICE_RCAR2 MAP_REGION_FLAT(DEVICE_RCAR_BASE2, \
  45. DEVICE_RCAR_SIZE2, \
  46. MT_DEVICE | MT_RW | MT_SECURE)
  47. #define MAP_SRAM MAP_REGION_FLAT(DEVICE_SRAM_BASE, \
  48. DEVICE_SRAM_SIZE, \
  49. MT_MEMORY | MT_RO | MT_SECURE)
  50. #define MAP_SRAM_STACK MAP_REGION_FLAT(DEVICE_SRAM_STACK_BASE, \
  51. DEVICE_SRAM_STACK_SIZE, \
  52. MT_MEMORY | MT_RW | MT_SECURE)
  53. #define MAP_ATFW_CRASH MAP_REGION_FLAT(RCAR_BL31_CRASH_BASE, \
  54. RCAR_BL31_CRASH_SIZE, \
  55. MT_MEMORY | MT_RW | MT_SECURE)
  56. #define MAP_ATFW_LOG MAP_REGION_FLAT(RCAR_BL31_LOG_BASE, \
  57. RCAR_BL31_LOG_SIZE, \
  58. MT_DEVICE | MT_RW | MT_SECURE)
  59. #if IMAGE_BL2
  60. #define MAP_DRAM0 MAP_REGION_FLAT(DRAM1_BASE, \
  61. DRAM1_SIZE, \
  62. RCAR_DCACHE | MT_RW | MT_SECURE)
  63. #define MAP_REG0 MAP_REGION_FLAT(DEVICE_RCAR_BASE, \
  64. DEVICE_RCAR_SIZE, \
  65. MT_DEVICE | MT_RW | MT_SECURE)
  66. #define MAP_RAM0 MAP_REGION_FLAT(RCAR_SYSRAM_BASE, \
  67. RCAR_SYSRAM_SIZE, \
  68. RCAR_DCACHE | MT_RW | MT_SECURE)
  69. #define MAP_REG1 MAP_REGION_FLAT(REG1_BASE, \
  70. REG1_SIZE, \
  71. MT_DEVICE | MT_RW | MT_SECURE)
  72. #define MAP_ROM MAP_REGION_FLAT(ROM0_BASE, \
  73. ROM0_SIZE, \
  74. RCAR_DCACHE | MT_RO | MT_SECURE)
  75. #define MAP_REG2 MAP_REGION_FLAT(REG2_BASE, \
  76. REG2_SIZE, \
  77. MT_DEVICE | MT_RW | MT_SECURE)
  78. #define MAP_DRAM1 MAP_REGION_FLAT(DRAM_40BIT_BASE, \
  79. DRAM_40BIT_SIZE, \
  80. RCAR_DCACHE | MT_RW | MT_SECURE)
  81. #endif
  82. #ifdef BL32_BASE
  83. #define MAP_BL32_MEM MAP_REGION_FLAT(BL32_BASE, \
  84. BL32_LIMIT - BL32_BASE, \
  85. MT_MEMORY | MT_RW | MT_SECURE)
  86. #endif
  87. #if IMAGE_BL2
  88. static const mmap_region_t rcar_mmap[] = {
  89. MAP_FLASH0, /* 0x08000000 - 0x0BFFFFFF RPC area */
  90. MAP_DRAM0, /* 0x40000000 - 0xBFFFFFFF DRAM area(Legacy) */
  91. MAP_REG0, /* 0xE6000000 - 0xE62FFFFF SoC register area */
  92. MAP_RAM0, /* 0xE6300000 - 0xE6303FFF System RAM area */
  93. MAP_REG1, /* 0xE6400000 - 0xEAFFFFFF SoC register area */
  94. MAP_ROM, /* 0xEB100000 - 0xEB127FFF boot ROM area */
  95. MAP_REG2, /* 0xEC000000 - 0xFFFFFFFF SoC register area */
  96. MAP_DRAM1, /* 0x0400000000 - 0x07FFFFFFFF DRAM area(4GB over) */
  97. {0}
  98. };
  99. #endif
  100. #if IMAGE_BL31
  101. static const mmap_region_t rcar_mmap[] = {
  102. MAP_SHARED_RAM,
  103. MAP_ATFW_CRASH,
  104. MAP_ATFW_LOG,
  105. MAP_DEVICE_RCAR,
  106. MAP_DEVICE_RCAR2,
  107. MAP_SRAM,
  108. MAP_SRAM_STACK,
  109. {0}
  110. };
  111. #endif
  112. #if IMAGE_BL32
  113. static const mmap_region_t rcar_mmap[] = {
  114. MAP_DEVICE0,
  115. MAP_DEVICE1,
  116. {0}
  117. };
  118. #endif
  119. CASSERT(ARRAY_SIZE(rcar_mmap) + RCAR_BL_REGIONS
  120. <= MAX_MMAP_REGIONS, assert_max_mmap_regions);
  121. /*
  122. * Macro generating the code for the function setting up the pagetables as per
  123. * the platform memory map & initialize the mmu, for the given exception level
  124. */
  125. #if USE_COHERENT_MEM
  126. void rcar_configure_mmu_el3(unsigned long total_base,
  127. unsigned long total_size,
  128. unsigned long ro_start,
  129. unsigned long ro_limit,
  130. unsigned long coh_start,
  131. unsigned long coh_limit)
  132. {
  133. mmap_add_region(total_base, total_base, total_size,
  134. RCAR_DCACHE | MT_RW | MT_SECURE);
  135. mmap_add_region(ro_start, ro_start, ro_limit - ro_start,
  136. RCAR_DCACHE | MT_RO | MT_SECURE);
  137. mmap_add_region(coh_start, coh_start, coh_limit - coh_start,
  138. MT_DEVICE | MT_RW | MT_SECURE);
  139. mmap_add(rcar_mmap);
  140. init_xlat_tables();
  141. enable_mmu_el3(0);
  142. }
  143. #else
  144. void rcar_configure_mmu_el3(unsigned long total_base,
  145. unsigned long total_size,
  146. unsigned long ro_start,
  147. unsigned long ro_limit)
  148. {
  149. mmap_add_region(total_base, total_base, total_size,
  150. RCAR_DCACHE | MT_RW | MT_SECURE);
  151. mmap_add_region(ro_start, ro_start, ro_limit - ro_start,
  152. RCAR_DCACHE | MT_RO | MT_SECURE);
  153. mmap_add(rcar_mmap);
  154. init_xlat_tables();
  155. enable_mmu_el3(0);
  156. }
  157. #endif
  158. uintptr_t plat_get_ns_image_entrypoint(void)
  159. {
  160. #if (IMAGE_BL2)
  161. uint32_t cert, len;
  162. uintptr_t dst;
  163. int32_t ret;
  164. ret = rcar_get_certificate(NON_TRUSTED_FW_CONTENT_CERT_ID, &cert);
  165. if (ret) {
  166. ERROR("%s : cert file load error", __func__);
  167. return NS_IMAGE_OFFSET;
  168. }
  169. rcar_read_certificate((uint64_t) cert, &len, &dst);
  170. return dst;
  171. #else
  172. return NS_IMAGE_OFFSET;
  173. #endif
  174. }
  175. unsigned int plat_get_syscnt_freq2(void)
  176. {
  177. unsigned int freq;
  178. freq = mmio_read_32(ARM_SYS_CNTCTL_BASE + CNTFID_OFF);
  179. if (freq == 0)
  180. panic();
  181. return freq;
  182. }
  183. void plat_rcar_gic_init(void)
  184. {
  185. gicv2_distif_init();
  186. gicv2_pcpu_distif_init();
  187. gicv2_cpuif_enable();
  188. }
  189. static const interrupt_prop_t interrupt_props[] = {
  190. #if IMAGE_BL2
  191. INTR_PROP_DESC(ARM_IRQ_SEC_WDT, GIC_HIGHEST_SEC_PRIORITY,
  192. GICV2_INTR_GROUP0, GIC_INTR_CFG_LEVEL),
  193. #else
  194. INTR_PROP_DESC(ARM_IRQ_SEC_PHY_TIMER, GIC_HIGHEST_SEC_PRIORITY,
  195. GICV2_INTR_GROUP0, GIC_INTR_CFG_LEVEL),
  196. INTR_PROP_DESC(ARM_IRQ_SEC_SGI_0, GIC_HIGHEST_SEC_PRIORITY,
  197. GICV2_INTR_GROUP0, GIC_INTR_CFG_EDGE),
  198. INTR_PROP_DESC(ARM_IRQ_SEC_SGI_1, GIC_HIGHEST_SEC_PRIORITY,
  199. GICV2_INTR_GROUP0, GIC_INTR_CFG_EDGE),
  200. INTR_PROP_DESC(ARM_IRQ_SEC_SGI_2, GIC_HIGHEST_SEC_PRIORITY,
  201. GICV2_INTR_GROUP0, GIC_INTR_CFG_EDGE),
  202. INTR_PROP_DESC(ARM_IRQ_SEC_SGI_3, GIC_HIGHEST_SEC_PRIORITY,
  203. GICV2_INTR_GROUP0, GIC_INTR_CFG_EDGE),
  204. INTR_PROP_DESC(ARM_IRQ_SEC_SGI_4, GIC_HIGHEST_SEC_PRIORITY,
  205. GICV2_INTR_GROUP0, GIC_INTR_CFG_EDGE),
  206. INTR_PROP_DESC(ARM_IRQ_SEC_SGI_5, GIC_HIGHEST_SEC_PRIORITY,
  207. GICV2_INTR_GROUP0, GIC_INTR_CFG_EDGE),
  208. INTR_PROP_DESC(ARM_IRQ_SEC_SGI_6, GIC_HIGHEST_SEC_PRIORITY,
  209. GICV2_INTR_GROUP0, GIC_INTR_CFG_EDGE),
  210. INTR_PROP_DESC(ARM_IRQ_SEC_SGI_7, GIC_HIGHEST_SEC_PRIORITY,
  211. GICV2_INTR_GROUP0, GIC_INTR_CFG_EDGE),
  212. INTR_PROP_DESC(ARM_IRQ_SEC_RPC, GIC_HIGHEST_SEC_PRIORITY,
  213. GICV2_INTR_GROUP0, GIC_INTR_CFG_LEVEL),
  214. INTR_PROP_DESC(ARM_IRQ_SEC_TIMER, GIC_HIGHEST_SEC_PRIORITY,
  215. GICV2_INTR_GROUP0, GIC_INTR_CFG_LEVEL),
  216. INTR_PROP_DESC(ARM_IRQ_SEC_TIMER_UP, GIC_HIGHEST_SEC_PRIORITY,
  217. GICV2_INTR_GROUP0, GIC_INTR_CFG_LEVEL),
  218. INTR_PROP_DESC(ARM_IRQ_SEC_WDT, GIC_HIGHEST_SEC_PRIORITY,
  219. GICV2_INTR_GROUP0, GIC_INTR_CFG_LEVEL),
  220. INTR_PROP_DESC(ARM_IRQ_SEC_CRYPT, GIC_HIGHEST_SEC_PRIORITY,
  221. GICV2_INTR_GROUP0, GIC_INTR_CFG_LEVEL),
  222. INTR_PROP_DESC(ARM_IRQ_SEC_CRYPT_SecPKA, GIC_HIGHEST_SEC_PRIORITY,
  223. GICV2_INTR_GROUP0, GIC_INTR_CFG_LEVEL),
  224. INTR_PROP_DESC(ARM_IRQ_SEC_CRYPT_PubPKA, GIC_HIGHEST_SEC_PRIORITY,
  225. GICV2_INTR_GROUP0, GIC_INTR_CFG_LEVEL),
  226. #endif
  227. };
  228. static const gicv2_driver_data_t plat_gicv2_driver_data = {
  229. .interrupt_props = interrupt_props,
  230. .interrupt_props_num = (uint32_t) ARRAY_SIZE(interrupt_props),
  231. .gicd_base = RCAR_GICD_BASE,
  232. .gicc_base = RCAR_GICC_BASE,
  233. };
  234. void plat_rcar_gic_driver_init(void)
  235. {
  236. gicv2_driver_init(&plat_gicv2_driver_data);
  237. }