imx93_bl31_setup.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. /*
  2. * Copyright 2022-2023 NXP
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #include <assert.h>
  7. #include <stdbool.h>
  8. #include <arch_helpers.h>
  9. #include <common/bl_common.h>
  10. #include <common/debug.h>
  11. #include <context.h>
  12. #include <drivers/console.h>
  13. #include <drivers/generic_delay_timer.h>
  14. #include <drivers/nxp/trdc/imx_trdc.h>
  15. #include <lib/el3_runtime/context_mgmt.h>
  16. #include <lib/mmio.h>
  17. #include <lib/xlat_tables/xlat_tables_v2.h>
  18. #include <plat/common/platform.h>
  19. #include <imx8_lpuart.h>
  20. #include <plat_common.h>
  21. #include <plat_imx8.h>
  22. #include <platform_def.h>
  23. #define MAP_BL31_TOTAL \
  24. MAP_REGION_FLAT(BL31_BASE, BL31_LIMIT - BL31_BASE, MT_MEMORY | MT_RW | MT_SECURE)
  25. #define MAP_BL31_RO \
  26. MAP_REGION_FLAT(BL_CODE_BASE, BL_CODE_END - BL_CODE_BASE, MT_MEMORY | MT_RO | MT_SECURE)
  27. static const mmap_region_t imx_mmap[] = {
  28. AIPS1_MAP, AIPS2_MAP, AIPS4_MAP, GIC_MAP,
  29. TRDC_A_MAP, TRDC_W_MAP, TRDC_M_MAP,
  30. TRDC_N_MAP,
  31. {0},
  32. };
  33. static entry_point_info_t bl32_image_ep_info;
  34. static entry_point_info_t bl33_image_ep_info;
  35. /* get SPSR for BL33 entry */
  36. static uint32_t get_spsr_for_bl33_entry(void)
  37. {
  38. unsigned long el_status;
  39. unsigned long mode;
  40. uint32_t spsr;
  41. /* figure out what mode we enter the non-secure world */
  42. el_status = read_id_aa64pfr0_el1() >> ID_AA64PFR0_EL2_SHIFT;
  43. el_status &= ID_AA64PFR0_ELX_MASK;
  44. mode = (el_status) ? MODE_EL2 : MODE_EL1;
  45. spsr = SPSR_64(mode, MODE_SP_ELX, DISABLE_ALL_EXCEPTIONS);
  46. return spsr;
  47. }
  48. void bl31_early_platform_setup2(u_register_t arg0, u_register_t arg1,
  49. u_register_t arg2, u_register_t arg3)
  50. {
  51. static console_t console;
  52. console_lpuart_register(IMX_LPUART_BASE, IMX_BOOT_UART_CLK_IN_HZ,
  53. IMX_CONSOLE_BAUDRATE, &console);
  54. /* This console is only used for boot stage */
  55. console_set_scope(&console, CONSOLE_FLAG_BOOT);
  56. /*
  57. * tell BL3-1 where the non-secure software image is located
  58. * and the entry state information.
  59. */
  60. bl33_image_ep_info.pc = PLAT_NS_IMAGE_OFFSET;
  61. bl33_image_ep_info.spsr = get_spsr_for_bl33_entry();
  62. SET_SECURITY_STATE(bl33_image_ep_info.h.attr, NON_SECURE);
  63. #if defined(SPD_opteed)
  64. /* Populate entry point information for BL32 */
  65. SET_PARAM_HEAD(&bl32_image_ep_info, PARAM_EP, VERSION_1, 0);
  66. SET_SECURITY_STATE(bl32_image_ep_info.h.attr, SECURE);
  67. bl32_image_ep_info.pc = BL32_BASE;
  68. bl32_image_ep_info.spsr = 0;
  69. /* Pass TEE base and size to bl33 */
  70. bl33_image_ep_info.args.arg1 = BL32_BASE;
  71. bl33_image_ep_info.args.arg2 = BL32_SIZE;
  72. /* Make sure memory is clean */
  73. mmio_write_32(BL32_FDT_OVERLAY_ADDR, 0);
  74. bl33_image_ep_info.args.arg3 = BL32_FDT_OVERLAY_ADDR;
  75. bl32_image_ep_info.args.arg3 = BL32_FDT_OVERLAY_ADDR;
  76. #endif
  77. imx_bl31_params_parse(arg0, OCRAM_BASE, OCRAM_SIZE,
  78. &bl32_image_ep_info, &bl33_image_ep_info);
  79. }
  80. void bl31_plat_arch_setup(void)
  81. {
  82. /* no coherence memory support on i.MX9 */
  83. const mmap_region_t bl_regions[] = {
  84. MAP_BL31_TOTAL,
  85. MAP_BL31_RO,
  86. };
  87. /* Assign all the GPIO pins to non-secure world by default */
  88. mmio_write_32(GPIO2_BASE + 0x10, 0xffffffff);
  89. mmio_write_32(GPIO2_BASE + 0x14, 0x3);
  90. mmio_write_32(GPIO2_BASE + 0x18, 0xffffffff);
  91. mmio_write_32(GPIO2_BASE + 0x1c, 0x3);
  92. mmio_write_32(GPIO3_BASE + 0x10, 0xffffffff);
  93. mmio_write_32(GPIO3_BASE + 0x14, 0x3);
  94. mmio_write_32(GPIO3_BASE + 0x18, 0xffffffff);
  95. mmio_write_32(GPIO3_BASE + 0x1c, 0x3);
  96. mmio_write_32(GPIO4_BASE + 0x10, 0xffffffff);
  97. mmio_write_32(GPIO4_BASE + 0x14, 0x3);
  98. mmio_write_32(GPIO4_BASE + 0x18, 0xffffffff);
  99. mmio_write_32(GPIO4_BASE + 0x1c, 0x3);
  100. mmio_write_32(GPIO1_BASE + 0x10, 0xffffffff);
  101. mmio_write_32(GPIO1_BASE + 0x14, 0x3);
  102. mmio_write_32(GPIO1_BASE + 0x18, 0xffffffff);
  103. mmio_write_32(GPIO1_BASE + 0x1c, 0x3);
  104. setup_page_tables(bl_regions, imx_mmap);
  105. enable_mmu_el3(0);
  106. /* trdc must be initialized */
  107. trdc_config();
  108. }
  109. void bl31_platform_setup(void)
  110. {
  111. generic_delay_timer_init();
  112. plat_gic_driver_init();
  113. plat_gic_init();
  114. }
  115. entry_point_info_t *bl31_plat_get_next_image_ep_info(unsigned int type)
  116. {
  117. if (type == NON_SECURE) {
  118. return &bl33_image_ep_info;
  119. }
  120. if (type == SECURE) {
  121. return &bl32_image_ep_info;
  122. }
  123. return NULL;
  124. }
  125. unsigned int plat_get_syscnt_freq2(void)
  126. {
  127. return COUNTER_FREQUENCY;
  128. }