bl31_plat_setup.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. /*
  2. * Copyright (c) 2023-2024, STMicroelectronics - All Rights Reserved
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #include <assert.h>
  7. #include <stdint.h>
  8. #include <common/bl_common.h>
  9. #include <drivers/generic_delay_timer.h>
  10. #include <drivers/st/stm32_console.h>
  11. #include <lib/xlat_tables/xlat_tables_v2.h>
  12. #include <plat/common/platform.h>
  13. #include <platform_def.h>
  14. static entry_point_info_t bl32_image_ep_info;
  15. static entry_point_info_t bl33_image_ep_info;
  16. void bl31_early_platform_setup2(u_register_t arg0, u_register_t arg1,
  17. u_register_t arg2, u_register_t arg3)
  18. {
  19. bl_params_t *params_from_bl2;
  20. int ret;
  21. /*
  22. * Invalidate remaining data from second half of SYSRAM (used by BL2) as this area will
  23. * be later used as non-secure.
  24. */
  25. inv_dcache_range(STM32MP_SYSRAM_BASE + STM32MP_SYSRAM_SIZE / 2U,
  26. STM32MP_SYSRAM_SIZE / 2U);
  27. mmap_add_region(BL_CODE_BASE, BL_CODE_BASE,
  28. BL_CODE_END - BL_CODE_BASE,
  29. MT_CODE | MT_SECURE);
  30. /*
  31. * Map soc_fw_config device tree with secure property, i.e. default region.
  32. * DDR region definitions will be finalized at BL32 level.
  33. */
  34. mmap_add_region(arg1, arg1, STM32MP_SOC_FW_CONFIG_MAX_SIZE, MT_RO_DATA | MT_SECURE);
  35. #if USE_COHERENT_MEM
  36. /* Map coherent memory */
  37. mmap_add_region(BL_COHERENT_RAM_BASE, BL_COHERENT_RAM_BASE,
  38. BL_COHERENT_RAM_END - BL_COHERENT_RAM_BASE,
  39. MT_DEVICE | MT_RW | MT_SECURE);
  40. #endif
  41. configure_mmu();
  42. ret = dt_open_and_check(arg1);
  43. if (ret < 0) {
  44. EARLY_ERROR("%s: failed to open DT (%d)\n", __func__, ret);
  45. panic();
  46. }
  47. ret = stm32mp2_clk_init();
  48. if (ret < 0) {
  49. EARLY_ERROR("%s: failed init clocks (%d)\n", __func__, ret);
  50. panic();
  51. }
  52. generic_delay_timer_init();
  53. (void)stm32mp_uart_console_setup();
  54. /*
  55. * Map upper SYSRAM where bl_params_t are stored in BL2
  56. */
  57. ret = mmap_add_dynamic_region(STM32MP_SYSRAM_BASE + STM32MP_SYSRAM_SIZE / 2U,
  58. STM32MP_SYSRAM_BASE + STM32MP_SYSRAM_SIZE / 2U,
  59. STM32MP_SYSRAM_SIZE / 2U, MT_RO_DATA | MT_SECURE);
  60. if (ret < 0) {
  61. ERROR("BL2 params area mapping: %d\n", ret);
  62. panic();
  63. }
  64. assert(arg0 != 0UL);
  65. params_from_bl2 = (bl_params_t *)arg0;
  66. assert(params_from_bl2 != NULL);
  67. assert(params_from_bl2->h.type == PARAM_BL_PARAMS);
  68. assert(params_from_bl2->h.version >= VERSION_2);
  69. bl_params_node_t *bl_params = params_from_bl2->head;
  70. while (bl_params != NULL) {
  71. /*
  72. * Copy BL33 entry point information.
  73. * They are stored in Secure RAM, in BL2's address space.
  74. */
  75. if (bl_params->image_id == BL33_IMAGE_ID) {
  76. bl33_image_ep_info = *bl_params->ep_info;
  77. /*
  78. * Check if hw_configuration is given to BL32 and
  79. * share it to BL33
  80. */
  81. if (arg2 != 0U) {
  82. bl33_image_ep_info.args.arg0 = 0U;
  83. bl33_image_ep_info.args.arg1 = 0U;
  84. bl33_image_ep_info.args.arg2 = arg2;
  85. }
  86. }
  87. if (bl_params->image_id == BL32_IMAGE_ID) {
  88. bl32_image_ep_info = *bl_params->ep_info;
  89. if (arg2 != 0U) {
  90. bl32_image_ep_info.args.arg3 = arg2;
  91. }
  92. }
  93. bl_params = bl_params->next_params_info;
  94. }
  95. ret = mmap_remove_dynamic_region(STM32MP_SYSRAM_BASE + STM32MP_SYSRAM_SIZE / 2U,
  96. STM32MP_SYSRAM_SIZE / 2U);
  97. if (ret < 0) {
  98. ERROR("BL2 params area unmapping: %d\n", ret);
  99. panic();
  100. }
  101. }
  102. void bl31_plat_arch_setup(void)
  103. {
  104. stm32mp_gic_init();
  105. }
  106. void bl31_platform_setup(void)
  107. {
  108. }
  109. entry_point_info_t *bl31_plat_get_next_image_ep_info(unsigned int type)
  110. {
  111. entry_point_info_t *next_image_info = NULL;
  112. assert(sec_state_is_valid(type));
  113. switch (type) {
  114. case NON_SECURE:
  115. next_image_info = &bl33_image_ep_info;
  116. break;
  117. case SECURE:
  118. next_image_info = &bl32_image_ep_info;
  119. break;
  120. default:
  121. break;
  122. }
  123. /* None of the next images on ST platforms can have 0x0 as the entrypoint */
  124. if ((next_image_info == NULL) || (next_image_info->pc == 0UL)) {
  125. return NULL;
  126. }
  127. return next_image_info;
  128. }