bl2_plat_setup.c 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. /*
  2. * Copyright (c) 2017-2021, ARM Limited and Contributors. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #include <assert.h>
  7. #include <errno.h>
  8. #include <string.h>
  9. #include <arch_helpers.h>
  10. #include <common/bl_common.h>
  11. #include <common/debug.h>
  12. #include <common/desc_image_load.h>
  13. #include <drivers/arm/pl011.h>
  14. #include <drivers/generic_delay_timer.h>
  15. #include <drivers/partition/partition.h>
  16. #include <drivers/synopsys/dw_mmc.h>
  17. #include <drivers/mmc.h>
  18. #include <lib/mmio.h>
  19. #include <lib/optee_utils.h>
  20. #include <plat/common/platform.h>
  21. #include "hi3798cv200.h"
  22. #include "plat_private.h"
  23. static meminfo_t bl2_tzram_layout __aligned(CACHE_WRITEBACK_GRANULE);
  24. static console_t console;
  25. #if !POPLAR_RECOVERY
  26. static struct mmc_device_info mmc_info;
  27. #endif
  28. /*******************************************************************************
  29. * Transfer SCP_BL2 from Trusted RAM using the SCP Download protocol.
  30. * Return 0 on success, -1 otherwise.
  31. ******************************************************************************/
  32. int plat_poplar_bl2_handle_scp_bl2(image_info_t *scp_bl2_image_info)
  33. {
  34. /*
  35. * This platform has no SCP_BL2 yet
  36. */
  37. return 0;
  38. }
  39. /*******************************************************************************
  40. * Gets SPSR for BL32 entry
  41. ******************************************************************************/
  42. uint32_t poplar_get_spsr_for_bl32_entry(void)
  43. {
  44. /*
  45. * The Secure Payload Dispatcher service is responsible for
  46. * setting the SPSR prior to entry into the BL3-2 image.
  47. */
  48. return 0;
  49. }
  50. /*******************************************************************************
  51. * Gets SPSR for BL33 entry
  52. ******************************************************************************/
  53. #ifdef __aarch64__
  54. uint32_t poplar_get_spsr_for_bl33_entry(void)
  55. {
  56. unsigned long el_status;
  57. unsigned int mode;
  58. uint32_t spsr;
  59. /* Figure out what mode we enter the non-secure world in */
  60. el_status = read_id_aa64pfr0_el1() >> ID_AA64PFR0_EL2_SHIFT;
  61. el_status &= ID_AA64PFR0_ELX_MASK;
  62. mode = (el_status) ? MODE_EL2 : MODE_EL1;
  63. /*
  64. * TODO: Consider the possibility of specifying the SPSR in
  65. * the FIP ToC and allowing the platform to have a say as
  66. * well.
  67. */
  68. spsr = SPSR_64(mode, MODE_SP_ELX, DISABLE_ALL_EXCEPTIONS);
  69. return spsr;
  70. }
  71. #else
  72. uint32_t poplar_get_spsr_for_bl33_entry(void)
  73. {
  74. unsigned int hyp_status, mode, spsr;
  75. hyp_status = GET_VIRT_EXT(read_id_pfr1());
  76. mode = (hyp_status) ? MODE32_hyp : MODE32_svc;
  77. /*
  78. * TODO: Consider the possibility of specifying the SPSR in
  79. * the FIP ToC and allowing the platform to have a say as
  80. * well.
  81. */
  82. spsr = SPSR_MODE32(mode, plat_get_ns_image_entrypoint() & 0x1,
  83. SPSR_E_LITTLE, DISABLE_ALL_EXCEPTIONS);
  84. return spsr;
  85. }
  86. #endif /* __aarch64__ */
  87. int poplar_bl2_handle_post_image_load(unsigned int image_id)
  88. {
  89. int err = 0;
  90. bl_mem_params_node_t *bl_mem_params = get_bl_mem_params_node(image_id);
  91. #ifdef SPD_opteed
  92. bl_mem_params_node_t *pager_mem_params = NULL;
  93. bl_mem_params_node_t *paged_mem_params = NULL;
  94. #endif
  95. assert(bl_mem_params);
  96. switch (image_id) {
  97. #ifdef __aarch64__
  98. case BL32_IMAGE_ID:
  99. #ifdef SPD_opteed
  100. pager_mem_params = get_bl_mem_params_node(BL32_EXTRA1_IMAGE_ID);
  101. assert(pager_mem_params);
  102. paged_mem_params = get_bl_mem_params_node(BL32_EXTRA2_IMAGE_ID);
  103. assert(paged_mem_params);
  104. err = parse_optee_header(&bl_mem_params->ep_info,
  105. &pager_mem_params->image_info,
  106. &paged_mem_params->image_info);
  107. if (err != 0) {
  108. WARN("OPTEE header parse error.\n");
  109. }
  110. /*
  111. * OP-TEE expect to receive DTB address in x2.
  112. * This will be copied into x2 by dispatcher.
  113. * Set this (arg3) if necessary
  114. */
  115. /* bl_mem_params->ep_info.args.arg3 = PLAT_HIKEY_DT_BASE; */
  116. #endif
  117. bl_mem_params->ep_info.spsr = poplar_get_spsr_for_bl32_entry();
  118. break;
  119. #endif
  120. case BL33_IMAGE_ID:
  121. /* BL33 expects to receive the primary CPU MPID (through r0) */
  122. bl_mem_params->ep_info.args.arg0 = 0xffff & read_mpidr();
  123. bl_mem_params->ep_info.spsr = poplar_get_spsr_for_bl33_entry();
  124. break;
  125. #ifdef SCP_BL2_BASE
  126. case SCP_BL2_IMAGE_ID:
  127. /* The subsequent handling of SCP_BL2 is platform specific */
  128. err = plat_poplar_bl2_handle_scp_bl2(&bl_mem_params->image_info);
  129. if (err) {
  130. WARN("Failure in platform-specific handling of SCP_BL2 image.\n");
  131. }
  132. break;
  133. #endif
  134. default:
  135. /* Do nothing in default case */
  136. break;
  137. }
  138. return err;
  139. }
  140. /*******************************************************************************
  141. * This function can be used by the platforms to update/use image
  142. * information for given `image_id`.
  143. ******************************************************************************/
  144. int bl2_plat_handle_post_image_load(unsigned int image_id)
  145. {
  146. return poplar_bl2_handle_post_image_load(image_id);
  147. }
  148. void bl2_early_platform_setup2(u_register_t arg0, u_register_t arg1,
  149. u_register_t arg2, u_register_t arg3)
  150. {
  151. struct meminfo *mem_layout = (struct meminfo *)arg1;
  152. #if !POPLAR_RECOVERY
  153. dw_mmc_params_t params = EMMC_INIT_PARAMS(POPLAR_EMMC_DESC_BASE);
  154. #endif
  155. console_pl011_register(PL011_UART0_BASE, PL011_UART0_CLK_IN_HZ,
  156. PL011_BAUDRATE, &console);
  157. /* Enable arch timer */
  158. generic_delay_timer_init();
  159. bl2_tzram_layout = *mem_layout;
  160. #if !POPLAR_RECOVERY
  161. /* SoC-specific emmc register are initialized/configured by bootrom */
  162. INFO("BL2: initializing emmc\n");
  163. mmc_info.mmc_dev_type = MMC_IS_EMMC;
  164. dw_mmc_init(&params, &mmc_info);
  165. #endif
  166. plat_io_setup();
  167. }
  168. void bl2_plat_arch_setup(void)
  169. {
  170. plat_configure_mmu_el1(bl2_tzram_layout.total_base,
  171. bl2_tzram_layout.total_size,
  172. BL_CODE_BASE,
  173. BL_CODE_END,
  174. BL_COHERENT_RAM_BASE,
  175. BL_COHERENT_RAM_END);
  176. }
  177. void bl2_platform_setup(void)
  178. {
  179. }
  180. uintptr_t plat_get_ns_image_entrypoint(void)
  181. {
  182. #ifdef PRELOADED_BL33_BASE
  183. return PRELOADED_BL33_BASE;
  184. #else
  185. return PLAT_POPLAR_NS_IMAGE_OFFSET;
  186. #endif
  187. }