ls_bl31_setup.c 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. /*
  2. * Copyright 2018-2020 NXP
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. *
  6. */
  7. #include <assert.h>
  8. #include <inttypes.h>
  9. #include <stdint.h>
  10. #ifdef LS_EL3_INTERRUPT_HANDLER
  11. #include <ls_interrupt_mgmt.h>
  12. #endif
  13. #include <mmu_def.h>
  14. #include <plat_common.h>
  15. /*
  16. * Placeholder variables for copying the arguments that have been passed to
  17. * BL31 from BL2.
  18. */
  19. #ifdef TEST_BL31
  20. #define SPSR_FOR_EL2H 0x3C9
  21. #define SPSR_FOR_EL1H 0x3C5
  22. #else
  23. static entry_point_info_t bl31_image_ep_info;
  24. #endif
  25. static entry_point_info_t bl32_image_ep_info;
  26. static entry_point_info_t bl33_image_ep_info;
  27. static dram_regions_info_t dram_regions_info = {0};
  28. static uint64_t rcw_porsr1;
  29. /* Return the pointer to the 'dram_regions_info structure of the DRAM.
  30. * This structure is populated after init_ddr().
  31. */
  32. dram_regions_info_t *get_dram_regions_info(void)
  33. {
  34. return &dram_regions_info;
  35. }
  36. /* Return the RCW.PORSR1 value which was passed in from BL2
  37. */
  38. uint64_t bl31_get_porsr1(void)
  39. {
  40. return rcw_porsr1;
  41. }
  42. /*
  43. * Return pointer to the 'entry_point_info' structure of the next image for the
  44. * security state specified:
  45. * - BL33 corresponds to the non-secure image type; while
  46. * - BL32 corresponds to the secure image type.
  47. * - A NULL pointer is returned, if the image does not exist.
  48. */
  49. entry_point_info_t *bl31_plat_get_next_image_ep_info(uint32_t type)
  50. {
  51. entry_point_info_t *next_image_info;
  52. assert(sec_state_is_valid(type));
  53. next_image_info = (type == NON_SECURE)
  54. ? &bl33_image_ep_info : &bl32_image_ep_info;
  55. #ifdef TEST_BL31
  56. next_image_info->pc = _get_test_entry();
  57. next_image_info->spsr = SPSR_FOR_EL2H;
  58. next_image_info->h.attr = NON_SECURE;
  59. #endif
  60. if (next_image_info->pc != 0U) {
  61. return next_image_info;
  62. } else {
  63. return NULL;
  64. }
  65. }
  66. /*
  67. * Perform any BL31 early platform setup common to NXP platforms.
  68. * - Here is an opportunity to copy parameters passed by the calling EL (S-EL1
  69. * in BL2 & S-EL3 in BL1) before they are lost (potentially).
  70. * - This needs to be done before the MMU is initialized so that the
  71. * memory layout can be used while creating page tables.
  72. * - BL2 has flushed this information to memory, in order to fetch latest data.
  73. */
  74. void bl31_early_platform_setup2(u_register_t arg0, u_register_t arg1,
  75. u_register_t arg2, u_register_t arg3)
  76. {
  77. #ifndef TEST_BL31
  78. int i = 0;
  79. void *from_bl2 = (void *)arg0;
  80. #endif
  81. soc_early_platform_setup2();
  82. #ifdef TEST_BL31
  83. dram_regions_info.num_dram_regions = 2;
  84. dram_regions_info.total_dram_size = 0x100000000;
  85. dram_regions_info.region[0].addr = 0x80000000;
  86. dram_regions_info.region[0].size = 0x80000000;
  87. dram_regions_info.region[1].addr = 0x880000000;
  88. dram_regions_info.region[1].size = 0x80000000;
  89. bl33_image_ep_info.pc = _get_test_entry();
  90. #else
  91. /*
  92. * Check params passed from BL2 should not be NULL,
  93. */
  94. bl_params_t *params_from_bl2 = (bl_params_t *)from_bl2;
  95. assert(params_from_bl2 != NULL);
  96. assert(params_from_bl2->h.type == PARAM_BL_PARAMS);
  97. assert(params_from_bl2->h.version >= VERSION_2);
  98. bl_params_node_t *bl_params = params_from_bl2->head;
  99. /*
  100. * Copy BL33 and BL32 (if present), entry point information.
  101. * They are stored in Secure RAM, in BL2's address space.
  102. */
  103. while (bl_params != NULL) {
  104. if (bl_params->image_id == BL31_IMAGE_ID) {
  105. bl31_image_ep_info = *bl_params->ep_info;
  106. dram_regions_info_t *loc_dram_regions_info =
  107. (dram_regions_info_t *) bl31_image_ep_info.args.arg3;
  108. dram_regions_info.num_dram_regions =
  109. loc_dram_regions_info->num_dram_regions;
  110. dram_regions_info.total_dram_size =
  111. loc_dram_regions_info->total_dram_size;
  112. VERBOSE("Number of DRAM Regions = %" PRIx64 "\n",
  113. dram_regions_info.num_dram_regions);
  114. for (i = 0; i < dram_regions_info.num_dram_regions;
  115. i++) {
  116. dram_regions_info.region[i].addr =
  117. loc_dram_regions_info->region[i].addr;
  118. dram_regions_info.region[i].size =
  119. loc_dram_regions_info->region[i].size;
  120. VERBOSE("DRAM%d Size = %" PRIx64 "\n", i,
  121. dram_regions_info.region[i].size);
  122. }
  123. rcw_porsr1 = bl31_image_ep_info.args.arg4;
  124. }
  125. if (bl_params->image_id == BL32_IMAGE_ID) {
  126. bl32_image_ep_info = *bl_params->ep_info;
  127. }
  128. if (bl_params->image_id == BL33_IMAGE_ID) {
  129. bl33_image_ep_info = *bl_params->ep_info;
  130. }
  131. bl_params = bl_params->next_params_info;
  132. }
  133. #endif /* TEST_BL31 */
  134. if (bl33_image_ep_info.pc == 0) {
  135. panic();
  136. }
  137. /*
  138. * perform basic initialization on the soc
  139. */
  140. soc_init();
  141. }
  142. /*******************************************************************************
  143. * Perform any BL31 platform setup common to ARM standard platforms
  144. ******************************************************************************/
  145. void bl31_platform_setup(void)
  146. {
  147. NOTICE("Welcome to %s BL31 Phase\n", BOARD);
  148. soc_platform_setup();
  149. /* Console logs gone missing as part going to
  150. * EL1 for initializing Bl32 if present.
  151. * console flush is necessary to avoid it.
  152. */
  153. (void)console_flush();
  154. }
  155. void bl31_plat_runtime_setup(void)
  156. {
  157. #ifdef LS_EL3_INTERRUPT_HANDLER
  158. ls_el3_interrupt_config();
  159. #endif
  160. soc_runtime_setup();
  161. }
  162. /*******************************************************************************
  163. * Perform the very early platform specific architectural setup shared between
  164. * ARM standard platforms. This only does basic initialization. Later
  165. * architectural setup (bl31_arch_setup()) does not do anything platform
  166. * specific.
  167. ******************************************************************************/
  168. void bl31_plat_arch_setup(void)
  169. {
  170. ls_setup_page_tables(BL31_BASE,
  171. BL31_END - BL31_BASE,
  172. BL_CODE_BASE,
  173. BL_CODE_END,
  174. BL_RO_DATA_BASE,
  175. BL_RO_DATA_END
  176. #if USE_COHERENT_MEM
  177. , BL_COHERENT_RAM_BASE,
  178. BL_COHERENT_RAM_END
  179. #endif
  180. );
  181. enable_mmu_el3(0);
  182. }