sp_min_setup.c 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. /*
  2. * Copyright (c) 2015-2024, ARM Limited and Contributors. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #include <assert.h>
  7. #include <string.h>
  8. #include <arch_helpers.h>
  9. #include <bl32/sp_min/platform_sp_min.h>
  10. #include <common/bl_common.h>
  11. #include <common/debug.h>
  12. #include <context.h>
  13. #include <drivers/arm/gicv2.h>
  14. #include <drivers/arm/tzc400.h>
  15. #include <drivers/generic_delay_timer.h>
  16. #include <drivers/st/bsec.h>
  17. #include <drivers/st/etzpc.h>
  18. #include <drivers/st/stm32_gpio.h>
  19. #include <drivers/st/stm32_iwdg.h>
  20. #include <drivers/st/stm32mp1_clk.h>
  21. #include <dt-bindings/clock/stm32mp1-clks.h>
  22. #include <lib/el3_runtime/context_mgmt.h>
  23. #include <lib/mmio.h>
  24. #include <lib/xlat_tables/xlat_tables_v2.h>
  25. #include <plat/common/platform.h>
  26. #include <platform_def.h>
  27. /******************************************************************************
  28. * Placeholder variables for copying the arguments that have been passed to
  29. * BL32 from BL2.
  30. ******************************************************************************/
  31. static entry_point_info_t bl33_image_ep_info;
  32. /*******************************************************************************
  33. * Interrupt handler for FIQ (secure IRQ)
  34. ******************************************************************************/
  35. void sp_min_plat_fiq_handler(uint32_t id)
  36. {
  37. (void)plat_crash_console_init();
  38. switch (id & INT_ID_MASK) {
  39. case STM32MP1_IRQ_TZC400:
  40. tzc400_init(STM32MP1_TZC_BASE);
  41. (void)tzc400_it_handler();
  42. panic();
  43. break;
  44. case STM32MP1_IRQ_AXIERRIRQ:
  45. ERROR("STM32MP1_IRQ_AXIERRIRQ generated\n");
  46. panic();
  47. break;
  48. default:
  49. ERROR("SECURE IT handler not define for it : %u\n", id);
  50. break;
  51. }
  52. }
  53. /*******************************************************************************
  54. * Return a pointer to the 'entry_point_info' structure of the next image for
  55. * the security state specified. BL33 corresponds to the non-secure image type
  56. * while BL32 corresponds to the secure image type. A NULL pointer is returned
  57. * if the image does not exist.
  58. ******************************************************************************/
  59. entry_point_info_t *sp_min_plat_get_bl33_ep_info(void)
  60. {
  61. entry_point_info_t *next_image_info;
  62. next_image_info = &bl33_image_ep_info;
  63. if (next_image_info->pc == 0U) {
  64. return NULL;
  65. }
  66. return next_image_info;
  67. }
  68. CASSERT((STM32MP_SEC_SYSRAM_BASE == STM32MP_SYSRAM_BASE) &&
  69. ((STM32MP_SEC_SYSRAM_BASE + STM32MP_SEC_SYSRAM_SIZE) <=
  70. (STM32MP_SYSRAM_BASE + STM32MP_SYSRAM_SIZE)),
  71. assert_secure_sysram_fits_at_begining_of_sysram);
  72. #ifdef STM32MP_NS_SYSRAM_BASE
  73. CASSERT((STM32MP_NS_SYSRAM_BASE >= STM32MP_SEC_SYSRAM_BASE) &&
  74. ((STM32MP_NS_SYSRAM_BASE + STM32MP_NS_SYSRAM_SIZE) ==
  75. (STM32MP_SYSRAM_BASE + STM32MP_SYSRAM_SIZE)),
  76. assert_non_secure_sysram_fits_at_end_of_sysram);
  77. CASSERT((STM32MP_NS_SYSRAM_BASE & (PAGE_SIZE_4KB - U(1))) == 0U,
  78. assert_non_secure_sysram_base_is_4kbyte_aligned);
  79. #define TZMA1_SECURE_RANGE \
  80. (((STM32MP_NS_SYSRAM_BASE - STM32MP_SYSRAM_BASE) >> FOUR_KB_SHIFT) - 1U)
  81. #else
  82. #define TZMA1_SECURE_RANGE STM32MP1_ETZPC_TZMA_ALL_SECURE
  83. #endif /* STM32MP_NS_SYSRAM_BASE */
  84. #define TZMA0_SECURE_RANGE STM32MP1_ETZPC_TZMA_ALL_SECURE
  85. static void stm32mp1_etzpc_early_setup(void)
  86. {
  87. if (etzpc_init() != 0) {
  88. panic();
  89. }
  90. etzpc_configure_tzma(STM32MP1_ETZPC_TZMA_ROM, TZMA0_SECURE_RANGE);
  91. etzpc_configure_tzma(STM32MP1_ETZPC_TZMA_SYSRAM, TZMA1_SECURE_RANGE);
  92. }
  93. /*******************************************************************************
  94. * Perform any BL32 specific platform actions.
  95. ******************************************************************************/
  96. void sp_min_early_platform_setup2(u_register_t arg0, u_register_t arg1,
  97. u_register_t arg2, u_register_t arg3)
  98. {
  99. bl_params_t *params_from_bl2 = (bl_params_t *)arg0;
  100. uintptr_t dt_addr = arg1;
  101. /* Imprecise aborts can be masked in NonSecure */
  102. write_scr(read_scr() | SCR_AW_BIT);
  103. mmap_add_region(BL_CODE_BASE, BL_CODE_BASE,
  104. BL_CODE_END - BL_CODE_BASE,
  105. MT_CODE | MT_SECURE);
  106. configure_mmu();
  107. assert(params_from_bl2 != NULL);
  108. assert(params_from_bl2->h.type == PARAM_BL_PARAMS);
  109. assert(params_from_bl2->h.version >= VERSION_2);
  110. bl_params_node_t *bl_params = params_from_bl2->head;
  111. /*
  112. * Copy BL33 entry point information.
  113. * They are stored in Secure RAM, in BL2's address space.
  114. */
  115. while (bl_params != NULL) {
  116. if (bl_params->image_id == BL33_IMAGE_ID) {
  117. bl33_image_ep_info = *bl_params->ep_info;
  118. /*
  119. * Check if hw_configuration is given to BL32 and
  120. * share it to BL33.
  121. */
  122. if (arg2 != 0U) {
  123. bl33_image_ep_info.args.arg0 = 0U;
  124. bl33_image_ep_info.args.arg1 = 0U;
  125. bl33_image_ep_info.args.arg2 = arg2;
  126. }
  127. break;
  128. }
  129. bl_params = bl_params->next_params_info;
  130. }
  131. if (dt_open_and_check(dt_addr) < 0) {
  132. panic();
  133. }
  134. if (bsec_probe() != 0) {
  135. panic();
  136. }
  137. if (stm32mp1_clk_probe() < 0) {
  138. panic();
  139. }
  140. (void)stm32mp_uart_console_setup();
  141. stm32mp1_etzpc_early_setup();
  142. }
  143. /*******************************************************************************
  144. * Initialize the MMU, security and the GIC.
  145. ******************************************************************************/
  146. void sp_min_platform_setup(void)
  147. {
  148. generic_delay_timer_init();
  149. stm32mp_gic_init();
  150. /* Disable MCU subsystem protection */
  151. stm32mp1_clk_mcuss_protect(false);
  152. if (stm32_iwdg_init() < 0) {
  153. panic();
  154. }
  155. stm32mp_lock_periph_registering();
  156. stm32mp1_init_scmi_server();
  157. }
  158. void sp_min_plat_arch_setup(void)
  159. {
  160. }