marvell_bl31_setup.c 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. /*
  2. * Copyright (C) 2018-2024 Marvell International Ltd.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. * https://spdx.org/licenses
  6. */
  7. #include <assert.h>
  8. #include <arch.h>
  9. #include <common/bl_common.h>
  10. #include <common/debug.h>
  11. #ifdef USE_CCI
  12. #include <drivers/arm/cci.h>
  13. #endif
  14. #include <drivers/console.h>
  15. #include <plat/common/platform.h>
  16. #include <marvell_def.h>
  17. #include <marvell_plat_priv.h>
  18. #include <plat_marvell.h>
  19. /*
  20. * Placeholder variables for copying the arguments that have been passed to
  21. * BL31 from BL2.
  22. */
  23. static entry_point_info_t bl32_image_ep_info;
  24. static entry_point_info_t bl33_image_ep_info;
  25. /* Weak definitions may be overridden in specific ARM standard platform */
  26. #pragma weak bl31_early_platform_setup2
  27. #pragma weak bl31_platform_setup
  28. #pragma weak bl31_plat_arch_setup
  29. #pragma weak bl31_plat_get_next_image_ep_info
  30. #pragma weak plat_get_syscnt_freq2
  31. /*****************************************************************************
  32. * Return a pointer to the 'entry_point_info' structure of the next image for
  33. * the security state specified. BL33 corresponds to the non-secure image type
  34. * while BL32 corresponds to the secure image type. A NULL pointer is returned
  35. * if the image does not exist.
  36. *****************************************************************************
  37. */
  38. entry_point_info_t *bl31_plat_get_next_image_ep_info(uint32_t type)
  39. {
  40. entry_point_info_t *next_image_info;
  41. assert(sec_state_is_valid(type));
  42. next_image_info = (type == NON_SECURE)
  43. ? &bl33_image_ep_info : &bl32_image_ep_info;
  44. return next_image_info;
  45. }
  46. /*****************************************************************************
  47. * Perform any BL31 early platform setup common to ARM standard platforms.
  48. * Here is an opportunity to copy parameters passed by the calling EL (S-EL1
  49. * in BL2 & EL3 in BL1) before they are lost (potentially). This needs to be
  50. * done before the MMU is initialized so that the memory layout can be used
  51. * while creating page tables. BL2 has flushed this information to memory, so
  52. * we are guaranteed to pick up good data.
  53. *****************************************************************************
  54. */
  55. void marvell_bl31_early_platform_setup(void *from_bl2,
  56. uintptr_t soc_fw_config,
  57. uintptr_t hw_config,
  58. void *plat_params_from_bl2)
  59. {
  60. /* Initialize the console to provide early debug support */
  61. marvell_console_boot_init();
  62. #if RESET_TO_BL31
  63. /* There are no parameters from BL2 if BL31 is a reset vector */
  64. assert(from_bl2 == NULL);
  65. assert(plat_params_from_bl2 == NULL);
  66. #ifdef BL32_BASE
  67. /* Populate entry point information for BL32 */
  68. SET_PARAM_HEAD(&bl32_image_ep_info,
  69. PARAM_EP,
  70. VERSION_1,
  71. 0);
  72. SET_SECURITY_STATE(bl32_image_ep_info.h.attr, SECURE);
  73. bl32_image_ep_info.pc = BL32_BASE;
  74. bl32_image_ep_info.spsr = marvell_get_spsr_for_bl32_entry();
  75. #endif /* BL32_BASE */
  76. /* Populate entry point information for BL33 */
  77. SET_PARAM_HEAD(&bl33_image_ep_info,
  78. PARAM_EP,
  79. VERSION_1,
  80. 0);
  81. /*
  82. * Tell BL31 where the non-trusted software image
  83. * is located and the entry state information
  84. */
  85. bl33_image_ep_info.pc = plat_get_ns_image_entrypoint();
  86. bl33_image_ep_info.spsr = marvell_get_spsr_for_bl33_entry();
  87. SET_SECURITY_STATE(bl33_image_ep_info.h.attr, NON_SECURE);
  88. #else
  89. /*
  90. * In debug builds, we pass a special value in 'plat_params_from_bl2'
  91. * to verify platform parameters from BL2 to BL31.
  92. * In release builds, it's not used.
  93. */
  94. assert(((unsigned long long)plat_params_from_bl2) ==
  95. MARVELL_BL31_PLAT_PARAM_VAL);
  96. /*
  97. * Check params passed from BL2 should not be NULL,
  98. */
  99. bl_params_t *params_from_bl2 = (bl_params_t *)from_bl2;
  100. assert(params_from_bl2 != NULL);
  101. assert(params_from_bl2->h.type == PARAM_BL_PARAMS);
  102. assert(params_from_bl2->h.version >= VERSION_2);
  103. bl_params_node_t *bl_params = params_from_bl2->head;
  104. /*
  105. * Copy BL33 and BL32 (if present), entry point information.
  106. * They are stored in Secure RAM, in BL2's address space.
  107. */
  108. while (bl_params != NULL) {
  109. if (bl_params->image_id == BL32_IMAGE_ID)
  110. bl32_image_ep_info = *bl_params->ep_info;
  111. if (bl_params->image_id == BL33_IMAGE_ID)
  112. bl33_image_ep_info = *bl_params->ep_info;
  113. bl_params = bl_params->next_params_info;
  114. }
  115. #endif
  116. }
  117. void bl31_early_platform_setup2(u_register_t arg0, u_register_t arg1,
  118. u_register_t arg2, u_register_t arg3)
  119. {
  120. marvell_bl31_early_platform_setup((void *)arg0, arg1, arg2,
  121. (void *)arg3);
  122. #ifdef USE_CCI
  123. /*
  124. * Initialize CCI for this cluster during cold boot.
  125. * No need for locks as no other CPU is active.
  126. */
  127. plat_marvell_interconnect_init();
  128. /*
  129. * Enable CCI coherency for the primary CPU's cluster.
  130. * Platform specific PSCI code will enable coherency for other
  131. * clusters.
  132. */
  133. plat_marvell_interconnect_enter_coherency();
  134. #endif
  135. }
  136. /*****************************************************************************
  137. * Perform any BL31 platform setup common to ARM standard platforms
  138. *****************************************************************************
  139. */
  140. void marvell_bl31_platform_setup(void)
  141. {
  142. /* Initialize the GIC driver, cpu and distributor interfaces */
  143. plat_marvell_gic_driver_init();
  144. plat_marvell_gic_init();
  145. /* For Armada-8k-plus family, the SoC includes more than
  146. * a single AP die, but the default die that boots is AP #0.
  147. * For other families there is only one die (#0).
  148. * Initialize psci arch from die 0
  149. */
  150. marvell_psci_arch_init(0);
  151. }
  152. /*****************************************************************************
  153. * Perform any BL31 platform runtime setup prior to BL31 exit common to ARM
  154. * standard platforms
  155. *****************************************************************************
  156. */
  157. void marvell_bl31_plat_runtime_setup(void)
  158. {
  159. /* Initialize the runtime console */
  160. marvell_console_runtime_init();
  161. }
  162. void bl31_platform_setup(void)
  163. {
  164. marvell_bl31_platform_setup();
  165. }
  166. void bl31_plat_runtime_setup(void)
  167. {
  168. marvell_bl31_plat_runtime_setup();
  169. }
  170. /*****************************************************************************
  171. * Perform the very early platform specific architectural setup shared between
  172. * ARM standard platforms. This only does basic initialization. Later
  173. * architectural setup (bl31_arch_setup()) does not do anything platform
  174. * specific.
  175. *****************************************************************************
  176. */
  177. void marvell_bl31_plat_arch_setup(void)
  178. {
  179. marvell_setup_page_tables(BL31_BASE,
  180. BL31_END - BL31_BASE,
  181. BL_CODE_BASE,
  182. BL_CODE_END,
  183. BL_RO_DATA_BASE,
  184. BL_RO_DATA_END
  185. #if USE_COHERENT_MEM
  186. , BL_COHERENT_RAM_BASE,
  187. BL_COHERENT_RAM_END
  188. #endif
  189. );
  190. #if BL31_CACHE_DISABLE
  191. enable_mmu_el3(DISABLE_DCACHE);
  192. INFO("Cache is disabled in BL3\n");
  193. #else
  194. enable_mmu_el3(0);
  195. #endif
  196. }
  197. void bl31_plat_arch_setup(void)
  198. {
  199. marvell_bl31_plat_arch_setup();
  200. }
  201. unsigned int plat_get_syscnt_freq2(void)
  202. {
  203. return PLAT_REF_CLK_IN_HZ;
  204. }