bl2_plat_setup.c 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. /*
  2. * Copyright (c) 2019-2021, ARM Limited and Contributors. All rights reserved.
  3. * Copyright (c) 2019-2023, Intel Corporation. All rights reserved.
  4. * Copyright (c) 2024, Altera Corporation. All rights reserved.
  5. *
  6. * SPDX-License-Identifier: BSD-3-Clause
  7. */
  8. #include <assert.h>
  9. #include <arch.h>
  10. #include <arch_helpers.h>
  11. #include <common/bl_common.h>
  12. #include <common/debug.h>
  13. #include <common/desc_image_load.h>
  14. #include <drivers/cadence/cdns_sdmmc.h>
  15. #include <drivers/generic_delay_timer.h>
  16. #include <drivers/synopsys/dw_mmc.h>
  17. #include <drivers/ti/uart/uart_16550.h>
  18. #include <lib/mmio.h>
  19. #include <lib/xlat_tables/xlat_tables_v2.h>
  20. #include "agilex5_clock_manager.h"
  21. #include "agilex5_ddr.h"
  22. #include "agilex5_memory_controller.h"
  23. #include "agilex5_mmc.h"
  24. #include "agilex5_pinmux.h"
  25. #include "agilex5_power_manager.h"
  26. #include "agilex5_system_manager.h"
  27. #include "ccu/ncore_ccu.h"
  28. #include "combophy/combophy.h"
  29. #include "nand/nand.h"
  30. #include "qspi/cadence_qspi.h"
  31. #include "sdmmc/sdmmc.h"
  32. #include "socfpga_emac.h"
  33. #include "socfpga_f2sdram_manager.h"
  34. #include "socfpga_handoff.h"
  35. #include "socfpga_mailbox.h"
  36. #include "socfpga_private.h"
  37. #include "socfpga_reset_manager.h"
  38. #include "socfpga_ros.h"
  39. #include "socfpga_vab.h"
  40. #include "wdt/watchdog.h"
  41. /* Declare mmc_info */
  42. static struct mmc_device_info mmc_info;
  43. /* Declare cadence idmac descriptor */
  44. extern struct cdns_idmac_desc cdns_desc[8] __aligned(32);
  45. const mmap_region_t agilex_plat_mmap[] = {
  46. MAP_REGION_FLAT(DRAM_BASE, DRAM_SIZE,
  47. MT_MEMORY | MT_RW | MT_NS),
  48. MAP_REGION_FLAT(PSS_BASE, PSS_SIZE,
  49. MT_DEVICE | MT_RW | MT_NS),
  50. MAP_REGION_FLAT(MPFE_BASE, MPFE_SIZE,
  51. MT_DEVICE | MT_RW | MT_SECURE),
  52. MAP_REGION_FLAT(OCRAM_BASE, OCRAM_SIZE,
  53. MT_NON_CACHEABLE | MT_RW | MT_SECURE),
  54. MAP_REGION_FLAT(CCU_BASE, CCU_SIZE,
  55. MT_DEVICE | MT_RW | MT_SECURE),
  56. MAP_REGION_FLAT(MEM64_BASE, MEM64_SIZE,
  57. MT_DEVICE | MT_RW | MT_NS),
  58. MAP_REGION_FLAT(GIC_BASE, GIC_SIZE,
  59. MT_DEVICE | MT_RW | MT_SECURE),
  60. {0},
  61. };
  62. boot_source_type boot_source = BOOT_SOURCE;
  63. void bl2_el3_early_platform_setup(u_register_t x0 __unused,
  64. u_register_t x1 __unused,
  65. u_register_t x2 __unused,
  66. u_register_t x3 __unused)
  67. {
  68. static console_t console;
  69. handoff reverse_handoff_ptr;
  70. /* Enable nonsecure access for peripherals and other misc components */
  71. enable_nonsecure_access();
  72. /* Bring all the required peripherals out of reset */
  73. deassert_peripheral_reset();
  74. /*
  75. * Initialize the UART console early in BL2 EL3 boot flow to get
  76. * the error/notice messages wherever required.
  77. */
  78. console_16550_register(PLAT_INTEL_UART_BASE, PLAT_UART_CLOCK,
  79. PLAT_BAUDRATE, &console);
  80. /* Generic delay timer init */
  81. generic_delay_timer_init();
  82. socfpga_delay_timer_init();
  83. /* Get the handoff data */
  84. if ((socfpga_get_handoff(&reverse_handoff_ptr)) != 0) {
  85. ERROR("SOCFPGA: Failed to get the correct handoff data\n");
  86. panic();
  87. }
  88. /* Configure the pinmux */
  89. config_pinmux(&reverse_handoff_ptr);
  90. /* Configure OCRAM to NON SECURE ACCESS */
  91. mmio_write_32(OCRAM_REGION_0_REG_BASE, OCRAM_NON_SECURE_ENABLE);
  92. mmio_write_32(SOCFPGA_L4_PER_SCR_REG_BASE + SOCFPGA_SDMMC_SECU_BIT,
  93. SOCFPGA_SDMMC_SECU_BIT_ENABLE);
  94. mmio_write_32(SOCFPGA_L4_SYS_SCR_REG_BASE + SOCFPGA_SDMMC_SECU_BIT,
  95. SOCFPGA_SDMMC_SECU_BIT_ENABLE);
  96. mmio_write_32(SOCFPGA_LWSOC2FPGA_SCR_REG_BASE,
  97. SOCFPGA_LWSOC2FPGA_ENABLE);
  98. /* Configure the clock manager */
  99. if ((config_clkmgr_handoff(&reverse_handoff_ptr)) != 0) {
  100. ERROR("SOCFPGA: Failed to initialize the clock manager\n");
  101. panic();
  102. }
  103. /* Configure power manager PSS SRAM power gate */
  104. config_pwrmgr_handoff(&reverse_handoff_ptr);
  105. /* Initialize the mailbox to enable communication between HPS and SDM */
  106. mailbox_init();
  107. /* Perform a handshake with certain peripherals before issuing a reset */
  108. config_hps_hs_before_warm_reset();
  109. /* TODO: watchdog init */
  110. //watchdog_init(clkmgr_get_rate(CLKMGR_WDT_CLK_ID));
  111. /* Initialize the CCU module for hardware cache coherency */
  112. init_ncore_ccu();
  113. socfpga_emac_init();
  114. /* DDR and IOSSM driver init */
  115. agilex5_ddr_init(&reverse_handoff_ptr);
  116. if (combo_phy_init(&reverse_handoff_ptr) != 0) {
  117. ERROR("SOCFPGA: Combo Phy initialization failed\n");
  118. }
  119. /* Enable FPGA bridges as required */
  120. if (!intel_mailbox_is_fpga_not_ready()) {
  121. socfpga_bridges_enable(SOC2FPGA_MASK | LWHPS2FPGA_MASK |
  122. FPGA2SOC_MASK | F2SDRAM0_MASK);
  123. }
  124. }
  125. void bl2_el3_plat_arch_setup(void)
  126. {
  127. handoff reverse_handoff_ptr;
  128. unsigned long offset = 0;
  129. struct cdns_sdmmc_params params = EMMC_INIT_PARAMS((uintptr_t) &cdns_desc,
  130. clkmgr_get_rate(CLKMGR_SDMMC_CLK_ID));
  131. mmc_info.mmc_dev_type = MMC_DEVICE_TYPE;
  132. mmc_info.ocr_voltage = OCR_3_3_3_4 | OCR_3_2_3_3;
  133. /* Request ownership and direct access to QSPI */
  134. mailbox_hps_qspi_enable();
  135. switch (boot_source) {
  136. case BOOT_SOURCE_SDMMC:
  137. NOTICE("SDMMC boot\n");
  138. cdns_mmc_init(&params, &mmc_info);
  139. socfpga_io_setup(boot_source, PLAT_SDMMC_DATA_BASE);
  140. break;
  141. case BOOT_SOURCE_QSPI:
  142. NOTICE("QSPI boot\n");
  143. cad_qspi_init(0, QSPI_CONFIG_CPHA, QSPI_CONFIG_CPOL,
  144. QSPI_CONFIG_CSDA, QSPI_CONFIG_CSDADS,
  145. QSPI_CONFIG_CSEOT, QSPI_CONFIG_CSSOT, 0);
  146. if (ros_qspi_get_ssbl_offset(&offset) != ROS_RET_OK) {
  147. offset = PLAT_QSPI_DATA_BASE;
  148. }
  149. socfpga_io_setup(boot_source, offset);
  150. break;
  151. case BOOT_SOURCE_NAND:
  152. NOTICE("NAND boot\n");
  153. nand_init(&reverse_handoff_ptr);
  154. socfpga_io_setup(boot_source, PLAT_NAND_DATA_BASE);
  155. break;
  156. default:
  157. ERROR("Unsupported boot source\n");
  158. panic();
  159. break;
  160. }
  161. }
  162. uint32_t get_spsr_for_bl33_entry(void)
  163. {
  164. unsigned long el_status;
  165. unsigned int mode;
  166. uint32_t spsr;
  167. /* Figure out what mode we enter the non-secure world in */
  168. el_status = read_id_aa64pfr0_el1() >> ID_AA64PFR0_EL2_SHIFT;
  169. el_status &= ID_AA64PFR0_ELX_MASK;
  170. mode = (el_status) ? MODE_EL2 : MODE_EL1;
  171. /*
  172. * TODO: Consider the possibility of specifying the SPSR in
  173. * the FIP ToC and allowing the platform to have a say as
  174. * well.
  175. */
  176. spsr = SPSR_64(mode, MODE_SP_ELX, DISABLE_ALL_EXCEPTIONS);
  177. return spsr;
  178. }
  179. int bl2_plat_handle_post_image_load(unsigned int image_id)
  180. {
  181. bl_mem_params_node_t *bl_mem_params = get_bl_mem_params_node(image_id);
  182. assert(bl_mem_params);
  183. #if SOCFPGA_SECURE_VAB_AUTH
  184. /*
  185. * VAB Authentication start here.
  186. * If failed to authenticate, shall not proceed to process BL31 and hang.
  187. */
  188. int ret = 0;
  189. ret = socfpga_vab_init(image_id);
  190. if (ret < 0) {
  191. ERROR("SOCFPGA VAB Authentication failed\n");
  192. wfi();
  193. }
  194. #endif
  195. switch (image_id) {
  196. case BL33_IMAGE_ID:
  197. bl_mem_params->ep_info.args.arg0 = 0xffff & read_mpidr();
  198. bl_mem_params->ep_info.spsr = get_spsr_for_bl33_entry();
  199. break;
  200. default:
  201. break;
  202. }
  203. return 0;
  204. }
  205. /*******************************************************************************
  206. * Perform any BL3-1 platform setup code
  207. ******************************************************************************/
  208. void bl2_platform_setup(void)
  209. {
  210. }