brcm_bl31_setup.c 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  1. /*
  2. * Copyright (c) 2015-2024, ARM Limited and Contributors. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #include <assert.h>
  7. #include <arch.h>
  8. #include <arch_helpers.h>
  9. #include <common/bl_common.h>
  10. #include <common/debug.h>
  11. #include <drivers/arm/sp804_delay_timer.h>
  12. #include <lib/utils.h>
  13. #include <plat/common/platform.h>
  14. #include <bcm_console.h>
  15. #include <plat_brcm.h>
  16. #include <platform_def.h>
  17. #ifdef BL33_SHARED_DDR_BASE
  18. struct bl33_info *bl33_info = (struct bl33_info *)BL33_SHARED_DDR_BASE;
  19. #endif
  20. /*
  21. * Placeholder variables for copying the arguments that have been passed to
  22. * BL31 from BL2.
  23. */
  24. static entry_point_info_t bl32_image_ep_info;
  25. static entry_point_info_t bl33_image_ep_info;
  26. /* Weak definitions may be overridden in specific BRCM platform */
  27. #pragma weak plat_bcm_bl31_early_platform_setup
  28. #pragma weak plat_brcm_pwrc_setup
  29. #pragma weak plat_brcm_security_setup
  30. void plat_brcm_security_setup(void)
  31. {
  32. }
  33. void plat_brcm_pwrc_setup(void)
  34. {
  35. }
  36. void plat_bcm_bl31_early_platform_setup(void *from_bl2,
  37. bl_params_t *plat_params_from_bl2)
  38. {
  39. }
  40. /*******************************************************************************
  41. * Return a pointer to the 'entry_point_info' structure of the next image for
  42. * the security state specified. BL33 corresponds to the non-secure image type
  43. * while BL32 corresponds to the secure image type. A NULL pointer is returned
  44. * if the image does not exist.
  45. ******************************************************************************/
  46. struct entry_point_info *bl31_plat_get_next_image_ep_info(uint32_t type)
  47. {
  48. entry_point_info_t *next_image_info;
  49. assert(sec_state_is_valid(type));
  50. next_image_info = (type == NON_SECURE)
  51. ? &bl33_image_ep_info : &bl32_image_ep_info;
  52. /*
  53. * None of the images on the ARM development platforms can have 0x0
  54. * as the entrypoint
  55. */
  56. if (next_image_info->pc)
  57. return next_image_info;
  58. else
  59. return NULL;
  60. }
  61. /*******************************************************************************
  62. * Perform any BL31 early platform setup common to ARM standard platforms.
  63. * Here is an opportunity to copy parameters passed by the calling EL (S-EL1
  64. * in BL2 & EL3 in BL1) before they are lost (potentially). This needs to be
  65. * done before the MMU is initialized so that the memory layout can be used
  66. * while creating page tables. BL2 has flushed this information to memory, so
  67. * we are guaranteed to pick up good data.
  68. ******************************************************************************/
  69. void __init brcm_bl31_early_platform_setup(void *from_bl2,
  70. uintptr_t soc_fw_config,
  71. uintptr_t hw_config,
  72. void *plat_params_from_bl2)
  73. {
  74. /* Initialize the console to provide early debug support */
  75. bcm_console_boot_init();
  76. /* Initialize delay timer driver using SP804 dual timer 0 */
  77. sp804_timer_init(SP804_TIMER0_BASE,
  78. SP804_TIMER0_CLKMULT, SP804_TIMER0_CLKDIV);
  79. #if RESET_TO_BL31
  80. /* There are no parameters from BL2 if BL31 is a reset vector */
  81. assert(from_bl2 == NULL);
  82. assert(plat_params_from_bl2 == NULL);
  83. # ifdef BL32_BASE
  84. /* Populate entry point information for BL32 */
  85. SET_PARAM_HEAD(&bl32_image_ep_info,
  86. PARAM_EP,
  87. VERSION_1,
  88. 0);
  89. SET_SECURITY_STATE(bl32_image_ep_info.h.attr, SECURE);
  90. bl32_image_ep_info.pc = BL32_BASE;
  91. bl32_image_ep_info.spsr = brcm_get_spsr_for_bl32_entry();
  92. # endif /* BL32_BASE */
  93. /* Populate entry point information for BL33 */
  94. SET_PARAM_HEAD(&bl33_image_ep_info,
  95. PARAM_EP,
  96. VERSION_1,
  97. 0);
  98. /*
  99. * Tell BL31 where the non-trusted software image
  100. * is located and the entry state information
  101. */
  102. bl33_image_ep_info.pc = plat_get_ns_image_entrypoint();
  103. bl33_image_ep_info.spsr = brcm_get_spsr_for_bl33_entry();
  104. SET_SECURITY_STATE(bl33_image_ep_info.h.attr, NON_SECURE);
  105. # if ARM_LINUX_KERNEL_AS_BL33
  106. /*
  107. * According to the file ``Documentation/arm64/booting.txt`` of the
  108. * Linux kernel tree, Linux expects the physical address of the device
  109. * tree blob (DTB) in x0, while x1-x3 are reserved for future use and
  110. * must be 0.
  111. */
  112. bl33_image_ep_info.args.arg0 = (u_register_t)PRELOADED_DTB_BASE;
  113. bl33_image_ep_info.args.arg1 = 0U;
  114. bl33_image_ep_info.args.arg2 = 0U;
  115. bl33_image_ep_info.args.arg3 = 0U;
  116. # endif
  117. #else /* RESET_TO_BL31 */
  118. /*
  119. * In debug builds, we pass a special value in 'plat_params_from_bl2'
  120. * to verify platform parameters from BL2 to BL31.
  121. * In release builds, it's not used.
  122. */
  123. assert(((unsigned long long)plat_params_from_bl2) ==
  124. BRCM_BL31_PLAT_PARAM_VAL);
  125. /*
  126. * Check params passed from BL2 should not be NULL
  127. */
  128. bl_params_t *params_from_bl2 = (bl_params_t *)from_bl2;
  129. assert(params_from_bl2 != NULL);
  130. assert(params_from_bl2->h.type == PARAM_BL_PARAMS);
  131. assert(params_from_bl2->h.version >= VERSION_2);
  132. bl_params_node_t *bl_params = params_from_bl2->head;
  133. /*
  134. * Copy BL33 and BL32 (if present), entry point information.
  135. * They are stored in Secure RAM, in BL2's address space.
  136. */
  137. while (bl_params != NULL) {
  138. if (bl_params->image_id == BL32_IMAGE_ID &&
  139. bl_params->image_info->h.attr != IMAGE_ATTRIB_SKIP_LOADING)
  140. bl32_image_ep_info = *bl_params->ep_info;
  141. if (bl_params->image_id == BL33_IMAGE_ID)
  142. bl33_image_ep_info = *bl_params->ep_info;
  143. bl_params = bl_params->next_params_info;
  144. }
  145. if (bl33_image_ep_info.pc == 0U)
  146. panic();
  147. #endif /* RESET_TO_BL31 */
  148. #ifdef BL33_SHARED_DDR_BASE
  149. /* Pass information to BL33 thorugh x0 */
  150. bl33_image_ep_info.args.arg0 = (u_register_t)BL33_SHARED_DDR_BASE;
  151. bl33_image_ep_info.args.arg1 = 0ULL;
  152. bl33_image_ep_info.args.arg2 = 0ULL;
  153. bl33_image_ep_info.args.arg3 = 0ULL;
  154. #endif
  155. }
  156. void bl31_early_platform_setup2(u_register_t arg0, u_register_t arg1,
  157. u_register_t arg2, u_register_t arg3)
  158. {
  159. #ifdef BL31_LOG_LEVEL
  160. SET_LOG_LEVEL(BL31_LOG_LEVEL);
  161. #endif
  162. brcm_bl31_early_platform_setup((void *)arg0, arg1, arg2, (void *)arg3);
  163. plat_bcm_bl31_early_platform_setup((void *)arg0, (void *)arg3);
  164. #ifdef DRIVER_CC_ENABLE
  165. /*
  166. * Initialize Interconnect for this cluster during cold boot.
  167. * No need for locks as no other CPU is active.
  168. */
  169. plat_brcm_interconnect_init();
  170. /*
  171. * Enable Interconnect coherency for the primary CPU's cluster.
  172. * Earlier bootloader stages might already do this (e.g. Trusted
  173. * Firmware's BL1 does it) but we can't assume so. There is no harm in
  174. * executing this code twice anyway.
  175. * Platform specific PSCI code will enable coherency for other
  176. * clusters.
  177. */
  178. plat_brcm_interconnect_enter_coherency();
  179. #endif
  180. }
  181. /*******************************************************************************
  182. * Perform any BL31 platform setup common to ARM standard platforms
  183. ******************************************************************************/
  184. void brcm_bl31_platform_setup(void)
  185. {
  186. /* Initialize the GIC driver, cpu and distributor interfaces */
  187. plat_brcm_gic_driver_init();
  188. plat_brcm_gic_init();
  189. /* Initialize power controller before setting up topology */
  190. plat_brcm_pwrc_setup();
  191. }
  192. /*******************************************************************************
  193. * Perform any BL31 platform runtime setup prior to BL31 exit common to ARM
  194. * standard platforms
  195. * Perform BL31 platform setup
  196. ******************************************************************************/
  197. void brcm_bl31_plat_runtime_setup(void)
  198. {
  199. /* Initialize the runtime console */
  200. bcm_console_runtime_init();
  201. }
  202. void bl31_platform_setup(void)
  203. {
  204. brcm_bl31_platform_setup();
  205. /* Initialize the secure environment */
  206. plat_brcm_security_setup();
  207. }
  208. void bl31_plat_runtime_setup(void)
  209. {
  210. brcm_bl31_plat_runtime_setup();
  211. }
  212. /*******************************************************************************
  213. * Perform the very early platform specific architectural setup shared between
  214. * ARM standard platforms. This only does basic initialization. Later
  215. * architectural setup (bl31_arch_setup()) does not do anything platform
  216. * specific.
  217. ******************************************************************************/
  218. void __init brcm_bl31_plat_arch_setup(void)
  219. {
  220. #ifndef MMU_DISABLED
  221. const mmap_region_t bl_regions[] = {
  222. MAP_REGION_FLAT(BL31_BASE, BL31_END - BL31_BASE,
  223. MT_MEMORY | MT_RW | MT_SECURE),
  224. MAP_REGION_FLAT(BL_CODE_BASE, BL_CODE_END - BL_CODE_BASE,
  225. MT_CODE | MT_SECURE),
  226. MAP_REGION_FLAT(BL_RO_DATA_BASE,
  227. BL_RO_DATA_END - BL_RO_DATA_BASE,
  228. MT_RO_DATA | MT_SECURE),
  229. #if USE_COHERENT_MEM
  230. MAP_REGION_FLAT(BL_COHERENT_RAM_BASE,
  231. BL_COHERENT_RAM_END - BL_COHERENT_RAM_BASE,
  232. MT_DEVICE | MT_RW | MT_SECURE),
  233. #endif
  234. {0}
  235. };
  236. setup_page_tables(bl_regions, plat_brcm_get_mmap());
  237. enable_mmu_el3(0);
  238. #endif
  239. }
  240. void __init bl31_plat_arch_setup(void)
  241. {
  242. brcm_bl31_plat_arch_setup();
  243. }