bl31_plat_setup.c 4.7 KB

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