imx8ulp_bl31_setup.c 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. /*
  2. * Copyright 2021-2024 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 <lib/el3_runtime/context_mgmt.h>
  15. #include <lib/mmio.h>
  16. #include <lib/xlat_tables/xlat_tables_v2.h>
  17. #include <plat/common/platform.h>
  18. #include <platform_def.h>
  19. #include <dram.h>
  20. #include <imx8_lpuart.h>
  21. #include <imx8ulp_caam.h>
  22. #include <imx_plat_common.h>
  23. #include <plat_imx8.h>
  24. #include <upower_api.h>
  25. #include <xrdc.h>
  26. #define MAP_BL31_TOTAL \
  27. MAP_REGION_FLAT(BL31_BASE, BL31_LIMIT - BL31_BASE, MT_MEMORY | MT_RW | MT_SECURE)
  28. #define MAP_BL31_RO \
  29. MAP_REGION_FLAT(BL_CODE_BASE, BL_CODE_END - BL_CODE_BASE, MT_MEMORY | MT_RO | MT_SECURE)
  30. #define MAP_BL32_TOTAL MAP_REGION_FLAT(BL32_BASE, BL32_SIZE, MT_MEMORY | MT_RW)
  31. #define MAP_COHERENT_MEM \
  32. MAP_REGION_FLAT(BL_COHERENT_RAM_BASE, (BL_COHERENT_RAM_END - BL_COHERENT_RAM_BASE), \
  33. MT_DEVICE | MT_RW | MT_SECURE)
  34. #define TRUSTY_PARAMS_LEN_BYTES (4096*2)
  35. static const mmap_region_t imx_mmap[] = {
  36. DEVICE0_MAP, DEVICE1_MAP, DEVICE2_MAP,
  37. ELE_MAP, SEC_SIM_MAP, SRAM0_MAP,
  38. {0}
  39. };
  40. extern uint32_t upower_init(void);
  41. extern void imx8ulp_init_scmi_server(void);
  42. static entry_point_info_t bl32_image_ep_info;
  43. static entry_point_info_t bl33_image_ep_info;
  44. void bl31_early_platform_setup2(u_register_t arg0, u_register_t arg1,
  45. u_register_t arg2, u_register_t arg3)
  46. {
  47. static console_t console;
  48. /* config the TPM5 clock */
  49. mmio_write_32(IMX_PCC3_BASE + 0xd0, 0x92000000);
  50. mmio_write_32(IMX_PCC3_BASE + 0xd0, 0xd2000000);
  51. /* enable the GPIO D,E,F non-secure access by default */
  52. mmio_write_32(IMX_PCC4_BASE + 0x78, 0xc0000000);
  53. mmio_write_32(IMX_PCC4_BASE + 0x7c, 0xc0000000);
  54. mmio_write_32(IMX_PCC5_BASE + 0x114, 0xc0000000);
  55. mmio_write_32(IMX_GPIOE_BASE + 0x10, 0xffffffff);
  56. mmio_write_32(IMX_GPIOE_BASE + 0x14, 0x3);
  57. mmio_write_32(IMX_GPIOE_BASE + 0x18, 0xffffffff);
  58. mmio_write_32(IMX_GPIOE_BASE + 0x1c, 0x3);
  59. mmio_write_32(IMX_GPIOF_BASE + 0x10, 0xffffffff);
  60. mmio_write_32(IMX_GPIOF_BASE + 0x14, 0x3);
  61. mmio_write_32(IMX_GPIOF_BASE + 0x18, 0xffffffff);
  62. mmio_write_32(IMX_GPIOF_BASE + 0x1c, 0x3);
  63. mmio_write_32(IMX_GPIOD_BASE + 0x10, 0xffffffff);
  64. mmio_write_32(IMX_GPIOD_BASE + 0x14, 0x3);
  65. mmio_write_32(IMX_GPIOD_BASE + 0x18, 0xffffffff);
  66. mmio_write_32(IMX_GPIOD_BASE + 0x1c, 0x3);
  67. console_lpuart_register(IMX_LPUART_BASE, IMX_BOOT_UART_CLK_IN_HZ,
  68. IMX_CONSOLE_BAUDRATE, &console);
  69. /* This console is only used for boot stage */
  70. console_set_scope(&console, CONSOLE_FLAG_BOOT | CONSOLE_FLAG_RUNTIME);
  71. bl33_image_ep_info.pc = PLAT_NS_IMAGE_OFFSET;
  72. bl33_image_ep_info.spsr = plat_get_spsr_for_bl33_entry();
  73. SET_SECURITY_STATE(bl33_image_ep_info.h.attr, NON_SECURE);
  74. #if defined(SPD_opteed) || defined(SPD_trusty)
  75. /* Populate entry point information for BL32 */
  76. SET_PARAM_HEAD(&bl32_image_ep_info, PARAM_EP, VERSION_1, 0);
  77. SET_SECURITY_STATE(bl32_image_ep_info.h.attr, SECURE);
  78. bl32_image_ep_info.pc = BL32_BASE;
  79. bl32_image_ep_info.spsr = 0;
  80. /* Pass TEE base and size to bl33 */
  81. bl33_image_ep_info.args.arg1 = BL32_BASE;
  82. bl33_image_ep_info.args.arg2 = BL32_SIZE;
  83. #ifdef SPD_trusty
  84. bl32_image_ep_info.args.arg0 = BL32_SIZE;
  85. bl32_image_ep_info.args.arg1 = BL32_BASE;
  86. #else
  87. /* Make sure memory is clean */
  88. mmio_write_32(BL32_FDT_OVERLAY_ADDR, 0);
  89. bl33_image_ep_info.args.arg3 = BL32_FDT_OVERLAY_ADDR;
  90. bl32_image_ep_info.args.arg3 = BL32_FDT_OVERLAY_ADDR;
  91. #endif
  92. #endif
  93. }
  94. void bl31_plat_arch_setup(void)
  95. {
  96. const mmap_region_t bl_regions[] = {
  97. MAP_BL31_TOTAL,
  98. MAP_BL31_RO,
  99. #if USE_COHERENT_MEM
  100. MAP_COHERENT_MEM,
  101. #endif
  102. #if defined(SPD_opteed) || defined(SPD_trusty)
  103. MAP_BL32_TOTAL,
  104. #endif
  105. {0},
  106. };
  107. setup_page_tables(bl_regions, imx_mmap);
  108. enable_mmu_el3(0);
  109. /* TODO: Hack, refine this piece, scmi channel free */
  110. mmio_write_32(SRAM0_BASE + 0x4, 1);
  111. /* Allow M core to reset A core */
  112. mmio_clrbits_32(IMX_MU0B_BASE + 0x10, BIT(2));
  113. }
  114. void bl31_platform_setup(void)
  115. {
  116. /* select the arch timer source */
  117. mmio_setbits_32(IMX_SIM1_BASE + 0x30, 0x8000000);
  118. generic_delay_timer_init();
  119. plat_gic_driver_init();
  120. plat_gic_init();
  121. imx8ulp_init_scmi_server();
  122. upower_init();
  123. xrdc_apply_apd_config();
  124. xrdc_apply_lpav_config();
  125. xrdc_enable();
  126. imx8ulp_caam_init();
  127. dram_init();
  128. }
  129. entry_point_info_t *bl31_plat_get_next_image_ep_info(unsigned int type)
  130. {
  131. if (type == NON_SECURE) {
  132. return &bl33_image_ep_info;
  133. } else {
  134. return &bl32_image_ep_info;
  135. }
  136. }
  137. unsigned int plat_get_syscnt_freq2(void)
  138. {
  139. return COUNTER_FREQUENCY;
  140. }
  141. void bl31_plat_runtime_setup(void)
  142. {
  143. }
  144. #ifdef SPD_trusty
  145. void plat_trusty_set_boot_args(aapcs64_params_t *args)
  146. {
  147. args->arg0 = BL32_SIZE;
  148. args->arg1 = BL32_BASE;
  149. args->arg2 = TRUSTY_PARAMS_LEN_BYTES;
  150. }
  151. #endif