bl2_plat_setup.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. /*
  2. * Copyright (c) 2019-2022, ARM Limited and Contributors. All rights reserved.
  3. * Copyright (c) 2019-2022, Intel Corporation. All rights reserved.
  4. *
  5. * SPDX-License-Identifier: BSD-3-Clause
  6. */
  7. #include <arch.h>
  8. #include <arch_helpers.h>
  9. #include <assert.h>
  10. #include <common/bl_common.h>
  11. #include <common/debug.h>
  12. #include <common/desc_image_load.h>
  13. #include <drivers/generic_delay_timer.h>
  14. #include <drivers/synopsys/dw_mmc.h>
  15. #include <drivers/ti/uart/uart_16550.h>
  16. #include <lib/xlat_tables/xlat_tables.h>
  17. #include "qspi/cadence_qspi.h"
  18. #include "socfpga_emac.h"
  19. #include "socfpga_f2sdram_manager.h"
  20. #include "socfpga_handoff.h"
  21. #include "socfpga_mailbox.h"
  22. #include "socfpga_private.h"
  23. #include "socfpga_reset_manager.h"
  24. #include "socfpga_system_manager.h"
  25. #include "s10_clock_manager.h"
  26. #include "s10_memory_controller.h"
  27. #include "s10_mmc.h"
  28. #include "s10_pinmux.h"
  29. #include "wdt/watchdog.h"
  30. static struct mmc_device_info mmc_info;
  31. const mmap_region_t plat_stratix10_mmap[] = {
  32. MAP_REGION_FLAT(DRAM_BASE, DRAM_SIZE,
  33. MT_MEMORY | MT_RW | MT_NS),
  34. MAP_REGION_FLAT(DEVICE1_BASE, DEVICE1_SIZE,
  35. MT_DEVICE | MT_RW | MT_NS),
  36. MAP_REGION_FLAT(DEVICE2_BASE, DEVICE2_SIZE,
  37. MT_DEVICE | MT_RW | MT_SECURE),
  38. MAP_REGION_FLAT(OCRAM_BASE, OCRAM_SIZE,
  39. MT_NON_CACHEABLE | MT_RW | MT_SECURE),
  40. MAP_REGION_FLAT(DEVICE3_BASE, DEVICE3_SIZE,
  41. MT_DEVICE | MT_RW | MT_SECURE),
  42. MAP_REGION_FLAT(MEM64_BASE, MEM64_SIZE,
  43. MT_DEVICE | MT_RW | MT_NS),
  44. MAP_REGION_FLAT(DEVICE4_BASE, DEVICE4_SIZE,
  45. MT_DEVICE | MT_RW | MT_NS),
  46. {0},
  47. };
  48. boot_source_type boot_source = BOOT_SOURCE;
  49. void bl2_el3_early_platform_setup(u_register_t x0, u_register_t x1,
  50. u_register_t x2, u_register_t x4)
  51. {
  52. static console_t console;
  53. handoff reverse_handoff_ptr;
  54. generic_delay_timer_init();
  55. if (socfpga_get_handoff(&reverse_handoff_ptr))
  56. return;
  57. config_pinmux(&reverse_handoff_ptr);
  58. config_clkmgr_handoff(&reverse_handoff_ptr);
  59. enable_nonsecure_access();
  60. deassert_peripheral_reset();
  61. config_hps_hs_before_warm_reset();
  62. watchdog_init(get_wdt_clk());
  63. console_16550_register(PLAT_INTEL_UART_BASE, get_uart_clk(),
  64. PLAT_BAUDRATE, &console);
  65. socfpga_emac_init();
  66. socfpga_delay_timer_init();
  67. init_hard_memory_controller();
  68. mailbox_init();
  69. s10_mmc_init();
  70. if (!intel_mailbox_is_fpga_not_ready()) {
  71. socfpga_bridges_enable(SOC2FPGA_MASK | LWHPS2FPGA_MASK |
  72. FPGA2SOC_MASK | F2SDRAM0_MASK | F2SDRAM1_MASK |
  73. F2SDRAM2_MASK);
  74. }
  75. }
  76. void bl2_el3_plat_arch_setup(void)
  77. {
  78. const mmap_region_t bl_regions[] = {
  79. MAP_REGION_FLAT(BL2_BASE, BL2_END - BL2_BASE,
  80. MT_MEMORY | MT_RW | MT_SECURE),
  81. MAP_REGION_FLAT(BL_CODE_BASE, BL_CODE_END - BL_CODE_BASE,
  82. MT_CODE | MT_SECURE),
  83. MAP_REGION_FLAT(BL_RO_DATA_BASE,
  84. BL_RO_DATA_END - BL_RO_DATA_BASE,
  85. MT_RO_DATA | MT_SECURE),
  86. #if USE_COHERENT_MEM_BAR
  87. MAP_REGION_FLAT(BL_COHERENT_RAM_BASE,
  88. BL_COHERENT_RAM_END - BL_COHERENT_RAM_BASE,
  89. MT_DEVICE | MT_RW | MT_SECURE),
  90. #endif
  91. {0},
  92. };
  93. setup_page_tables(bl_regions, plat_stratix10_mmap);
  94. enable_mmu_el3(0);
  95. dw_mmc_params_t params = EMMC_INIT_PARAMS(0x100000, get_mmc_clk());
  96. mmc_info.mmc_dev_type = MMC_IS_SD;
  97. mmc_info.ocr_voltage = OCR_3_3_3_4 | OCR_3_2_3_3;
  98. /* Request ownership and direct access to QSPI */
  99. mailbox_hps_qspi_enable();
  100. switch (boot_source) {
  101. case BOOT_SOURCE_SDMMC:
  102. dw_mmc_init(&params, &mmc_info);
  103. socfpga_io_setup(boot_source, PLAT_SDMMC_DATA_BASE);
  104. break;
  105. case BOOT_SOURCE_QSPI:
  106. cad_qspi_init(0, QSPI_CONFIG_CPHA, QSPI_CONFIG_CPOL,
  107. QSPI_CONFIG_CSDA, QSPI_CONFIG_CSDADS,
  108. QSPI_CONFIG_CSEOT, QSPI_CONFIG_CSSOT, 0);
  109. socfpga_io_setup(boot_source, PLAT_QSPI_DATA_BASE);
  110. break;
  111. default:
  112. ERROR("Unsupported boot source\n");
  113. panic();
  114. break;
  115. }
  116. }
  117. uint32_t get_spsr_for_bl33_entry(void)
  118. {
  119. unsigned long el_status;
  120. unsigned int mode;
  121. uint32_t spsr;
  122. /* Figure out what mode we enter the non-secure world in */
  123. el_status = read_id_aa64pfr0_el1() >> ID_AA64PFR0_EL2_SHIFT;
  124. el_status &= ID_AA64PFR0_ELX_MASK;
  125. mode = (el_status) ? MODE_EL2 : MODE_EL1;
  126. /*
  127. * TODO: Consider the possibility of specifying the SPSR in
  128. * the FIP ToC and allowing the platform to have a say as
  129. * well.
  130. */
  131. spsr = SPSR_64(mode, MODE_SP_ELX, DISABLE_ALL_EXCEPTIONS);
  132. return spsr;
  133. }
  134. int bl2_plat_handle_post_image_load(unsigned int image_id)
  135. {
  136. bl_mem_params_node_t *bl_mem_params = get_bl_mem_params_node(image_id);
  137. assert(bl_mem_params);
  138. switch (image_id) {
  139. case BL33_IMAGE_ID:
  140. bl_mem_params->ep_info.args.arg0 = 0xffff & read_mpidr();
  141. bl_mem_params->ep_info.spsr = get_spsr_for_bl33_entry();
  142. break;
  143. default:
  144. break;
  145. }
  146. return 0;
  147. }
  148. /*******************************************************************************
  149. * Perform any BL3-1 platform setup code
  150. ******************************************************************************/
  151. void bl2_platform_setup(void)
  152. {
  153. }