bl31_plat_setup.c 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. /*
  2. * Copyright (c) 2019-2020, 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 <drivers/arm/gicv2.h>
  12. #include <drivers/ti/uart/uart_16550.h>
  13. #include <lib/xlat_tables/xlat_tables.h>
  14. #include <lib/mmio.h>
  15. #include <plat/common/platform.h>
  16. #include <platform_def.h>
  17. #include "socfpga_mailbox.h"
  18. #include "socfpga_noc.h"
  19. #include "socfpga_private.h"
  20. #include "socfpga_reset_manager.h"
  21. #include "socfpga_system_manager.h"
  22. #include "s10_memory_controller.h"
  23. #include "s10_pinmux.h"
  24. #include "s10_clock_manager.h"
  25. static entry_point_info_t bl32_image_ep_info;
  26. static entry_point_info_t bl33_image_ep_info;
  27. entry_point_info_t *bl31_plat_get_next_image_ep_info(uint32_t type)
  28. {
  29. entry_point_info_t *next_image_info;
  30. next_image_info = (type == NON_SECURE) ?
  31. &bl33_image_ep_info : &bl32_image_ep_info;
  32. /* None of the images on this platform can have 0x0 as the entrypoint */
  33. if (next_image_info->pc)
  34. return next_image_info;
  35. else
  36. return NULL;
  37. }
  38. void bl31_early_platform_setup2(u_register_t arg0, u_register_t arg1,
  39. u_register_t arg2, u_register_t arg3)
  40. {
  41. static console_t console;
  42. mmio_write_64(PLAT_SEC_ENTRY, PLAT_SEC_WARM_ENTRY);
  43. console_16550_register(PLAT_INTEL_UART_BASE, PLAT_UART_CLOCK,
  44. PLAT_BAUDRATE, &console);
  45. /*
  46. * Check params passed from BL31 should not be NULL,
  47. */
  48. void *from_bl2 = (void *) arg0;
  49. bl_params_t *params_from_bl2 = (bl_params_t *)from_bl2;
  50. assert(params_from_bl2 != NULL);
  51. /*
  52. * Copy BL32 (if populated by BL31) and BL33 entry point information.
  53. * They are stored in Secure RAM, in BL31's address space.
  54. */
  55. if (params_from_bl2->h.type == PARAM_BL_PARAMS &&
  56. params_from_bl2->h.version >= VERSION_2) {
  57. bl_params_node_t *bl_params = params_from_bl2->head;
  58. while (bl_params) {
  59. if (bl_params->image_id == BL33_IMAGE_ID)
  60. bl33_image_ep_info = *bl_params->ep_info;
  61. bl_params = bl_params->next_params_info;
  62. }
  63. } else {
  64. struct socfpga_bl31_params *arg_from_bl2 =
  65. (struct socfpga_bl31_params *) from_bl2;
  66. assert(arg_from_bl2->h.type == PARAM_BL31);
  67. assert(arg_from_bl2->h.version >= VERSION_1);
  68. bl32_image_ep_info = *arg_from_bl2->bl32_ep_info;
  69. bl33_image_ep_info = *arg_from_bl2->bl33_ep_info;
  70. }
  71. SET_SECURITY_STATE(bl33_image_ep_info.h.attr, NON_SECURE);
  72. }
  73. static const interrupt_prop_t s10_interrupt_props[] = {
  74. PLAT_INTEL_SOCFPGA_G1S_IRQ_PROPS(GICV2_INTR_GROUP0),
  75. PLAT_INTEL_SOCFPGA_G0_IRQ_PROPS(GICV2_INTR_GROUP0)
  76. };
  77. static unsigned int target_mask_array[PLATFORM_CORE_COUNT];
  78. static const gicv2_driver_data_t plat_gicv2_gic_data = {
  79. .gicd_base = PLAT_INTEL_SOCFPGA_GICD_BASE,
  80. .gicc_base = PLAT_INTEL_SOCFPGA_GICC_BASE,
  81. .interrupt_props = s10_interrupt_props,
  82. .interrupt_props_num = ARRAY_SIZE(s10_interrupt_props),
  83. .target_masks = target_mask_array,
  84. .target_masks_num = ARRAY_SIZE(target_mask_array),
  85. };
  86. /*******************************************************************************
  87. * Perform any BL3-1 platform setup code
  88. ******************************************************************************/
  89. void bl31_platform_setup(void)
  90. {
  91. socfpga_delay_timer_init();
  92. /* Initialize the gic cpu and distributor interfaces */
  93. gicv2_driver_init(&plat_gicv2_gic_data);
  94. gicv2_distif_init();
  95. gicv2_pcpu_distif_init();
  96. gicv2_cpuif_enable();
  97. /* Signal secondary CPUs to jump to BL31 (BL2 = U-boot SPL) */
  98. mmio_write_64(PLAT_CPU_RELEASE_ADDR,
  99. (uint64_t)plat_secondary_cpus_bl31_entry);
  100. mailbox_hps_stage_notify(HPS_EXECUTION_STATE_SSBL);
  101. }
  102. const mmap_region_t plat_stratix10_mmap[] = {
  103. MAP_REGION_FLAT(DRAM_BASE, DRAM_SIZE,
  104. MT_MEMORY | MT_RW | MT_NS),
  105. MAP_REGION_FLAT(DEVICE1_BASE, DEVICE1_SIZE,
  106. MT_DEVICE | MT_RW | MT_NS),
  107. MAP_REGION_FLAT(DEVICE2_BASE, DEVICE2_SIZE,
  108. MT_DEVICE | MT_RW | MT_SECURE),
  109. MAP_REGION_FLAT(OCRAM_BASE, OCRAM_SIZE,
  110. MT_NON_CACHEABLE | MT_RW | MT_SECURE),
  111. MAP_REGION_FLAT(DEVICE3_BASE, DEVICE3_SIZE,
  112. MT_DEVICE | MT_RW | MT_SECURE),
  113. MAP_REGION_FLAT(MEM64_BASE, MEM64_SIZE,
  114. MT_DEVICE | MT_RW | MT_NS),
  115. MAP_REGION_FLAT(DEVICE4_BASE, DEVICE4_SIZE,
  116. MT_DEVICE | MT_RW | MT_NS),
  117. {0}
  118. };
  119. /*******************************************************************************
  120. * Perform the very early platform specific architectural setup here. At the
  121. * moment this is only initializes the mmu in a quick and dirty way.
  122. ******************************************************************************/
  123. void bl31_plat_arch_setup(void)
  124. {
  125. const mmap_region_t bl_regions[] = {
  126. MAP_REGION_FLAT(BL31_BASE, BL31_END - BL31_BASE,
  127. MT_MEMORY | MT_RW | MT_SECURE),
  128. MAP_REGION_FLAT(BL_CODE_BASE, BL_CODE_END - BL_CODE_BASE,
  129. MT_CODE | MT_SECURE),
  130. MAP_REGION_FLAT(BL_RO_DATA_BASE,
  131. BL_RO_DATA_END - BL_RO_DATA_BASE,
  132. MT_RO_DATA | MT_SECURE),
  133. #if USE_COHERENT_MEM
  134. MAP_REGION_FLAT(BL_COHERENT_RAM_BASE,
  135. BL_COHERENT_RAM_END - BL_COHERENT_RAM_BASE,
  136. MT_DEVICE | MT_RW | MT_SECURE),
  137. #endif
  138. {0}
  139. };
  140. setup_page_tables(bl_regions, plat_stratix10_mmap);
  141. enable_mmu_el3(0);
  142. }