bl31_plat_setup.c 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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/mmio.h>
  14. #include <lib/xlat_tables/xlat_tables.h>
  15. #include "ccu/ncore_ccu.h"
  16. #include "socfpga_mailbox.h"
  17. #include "socfpga_private.h"
  18. static entry_point_info_t bl32_image_ep_info;
  19. static entry_point_info_t bl33_image_ep_info;
  20. entry_point_info_t *bl31_plat_get_next_image_ep_info(uint32_t type)
  21. {
  22. entry_point_info_t *next_image_info;
  23. next_image_info = (type == NON_SECURE) ?
  24. &bl33_image_ep_info : &bl32_image_ep_info;
  25. /* None of the images on this platform can have 0x0 as the entrypoint */
  26. if (next_image_info->pc)
  27. return next_image_info;
  28. else
  29. return NULL;
  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, PLAT_SEC_WARM_ENTRY);
  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) {
  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. ncore_enable_ocram_firewall();
  95. }
  96. const mmap_region_t plat_agilex_mmap[] = {
  97. MAP_REGION_FLAT(DRAM_BASE, DRAM_SIZE, MT_MEMORY | MT_RW | MT_NS),
  98. MAP_REGION_FLAT(DEVICE1_BASE, DEVICE1_SIZE, MT_DEVICE | MT_RW | MT_NS),
  99. MAP_REGION_FLAT(DEVICE2_BASE, DEVICE2_SIZE, MT_DEVICE | MT_RW | MT_SECURE),
  100. MAP_REGION_FLAT(OCRAM_BASE, OCRAM_SIZE,
  101. MT_NON_CACHEABLE | MT_RW | MT_SECURE),
  102. MAP_REGION_FLAT(DEVICE3_BASE, DEVICE3_SIZE,
  103. MT_DEVICE | MT_RW | MT_SECURE),
  104. MAP_REGION_FLAT(MEM64_BASE, MEM64_SIZE, MT_DEVICE | MT_RW | MT_NS),
  105. MAP_REGION_FLAT(DEVICE4_BASE, DEVICE4_SIZE, MT_DEVICE | MT_RW | MT_NS),
  106. {0}
  107. };
  108. /*******************************************************************************
  109. * Perform the very early platform specific architectural setup here. At the
  110. * moment this is only intializes the mmu in a quick and dirty way.
  111. ******************************************************************************/
  112. void bl31_plat_arch_setup(void)
  113. {
  114. const mmap_region_t bl_regions[] = {
  115. MAP_REGION_FLAT(BL31_BASE, BL31_END - BL31_BASE,
  116. MT_MEMORY | MT_RW | MT_SECURE),
  117. MAP_REGION_FLAT(BL_CODE_BASE, BL_CODE_END - BL_CODE_BASE,
  118. MT_CODE | MT_SECURE),
  119. MAP_REGION_FLAT(BL_RO_DATA_BASE,
  120. BL_RO_DATA_END - BL_RO_DATA_BASE,
  121. MT_RO_DATA | MT_SECURE),
  122. #if USE_COHERENT_MEM
  123. MAP_REGION_FLAT(BL_COHERENT_RAM_BASE,
  124. BL_COHERENT_RAM_END - BL_COHERENT_RAM_BASE,
  125. MT_DEVICE | MT_RW | MT_SECURE),
  126. #endif
  127. {0}
  128. };
  129. setup_page_tables(bl_regions, plat_agilex_mmap);
  130. enable_mmu_el3(0);
  131. }