arm_bl2_el3_setup.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. /*
  2. * Copyright (c) 2017-2024, ARM Limited and Contributors. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #include <assert.h>
  7. #include <drivers/generic_delay_timer.h>
  8. #include <drivers/partition/partition.h>
  9. #include <lib/fconf/fconf.h>
  10. #include <lib/fconf/fconf_dyn_cfg_getter.h>
  11. #include <plat/arm/common/plat_arm.h>
  12. #include <plat/common/platform.h>
  13. #include <platform_def.h>
  14. #pragma weak bl2_el3_early_platform_setup
  15. #pragma weak bl2_el3_plat_arch_setup
  16. #pragma weak bl2_el3_plat_prepare_exit
  17. #define MAP_BL2_EL3_TOTAL MAP_REGION_FLAT( \
  18. bl2_el3_tzram_layout.total_base, \
  19. bl2_el3_tzram_layout.total_size, \
  20. MT_MEMORY | MT_RW | MT_SECURE)
  21. static meminfo_t bl2_el3_tzram_layout;
  22. /*
  23. * Perform arm specific early platform setup. At this moment we only initialize
  24. * the console and the memory layout.
  25. */
  26. void arm_bl2_el3_early_platform_setup(void)
  27. {
  28. /* Initialize the console to provide early debug support */
  29. arm_console_boot_init();
  30. /*
  31. * Allow BL2 to see the whole Trusted RAM. This is determined
  32. * statically since we cannot rely on BL1 passing this information
  33. * in the RESET_TO_BL2 case.
  34. */
  35. bl2_el3_tzram_layout.total_base = ARM_BL_RAM_BASE;
  36. bl2_el3_tzram_layout.total_size = ARM_BL_RAM_SIZE;
  37. /* Initialise the IO layer and register platform IO devices */
  38. plat_arm_io_setup();
  39. }
  40. void bl2_el3_early_platform_setup(u_register_t arg0 __unused,
  41. u_register_t arg1 __unused,
  42. u_register_t arg2 __unused,
  43. u_register_t arg3 __unused)
  44. {
  45. arm_bl2_el3_early_platform_setup();
  46. /*
  47. * Initialize Interconnect for this cluster during cold boot.
  48. * No need for locks as no other CPU is active.
  49. */
  50. plat_arm_interconnect_init();
  51. /*
  52. * Enable Interconnect coherency for the primary CPU's cluster.
  53. */
  54. plat_arm_interconnect_enter_coherency();
  55. generic_delay_timer_init();
  56. }
  57. #if ARM_FW_CONFIG_LOAD_ENABLE
  58. /*************************************************************************************
  59. * FW CONFIG load function for BL2 when RESET_TO_BL2=1 && ARM_FW_CONFIG_LOAD_ENABLE=1
  60. *************************************************************************************/
  61. void arm_bl2_el3_plat_config_load(void)
  62. {
  63. int ret;
  64. const struct dyn_cfg_dtb_info_t *fw_config_info;
  65. /* Set global DTB info for fixed fw_config information */
  66. set_config_info(PLAT_FW_CONFIG_BASE, ~0UL, PLAT_FW_CONFIG_MAX_SIZE, FW_CONFIG_ID);
  67. /* Fill the device tree information struct with the info from the config dtb */
  68. ret = fconf_load_config(FW_CONFIG_ID);
  69. if (ret < 0) {
  70. ERROR("Loading of FW_CONFIG failed %d\n", ret);
  71. plat_error_handler(ret);
  72. }
  73. /*
  74. * FW_CONFIG loaded successfully. Check the FW_CONFIG device tree parsing
  75. * is successful.
  76. */
  77. fw_config_info = FCONF_GET_PROPERTY(dyn_cfg, dtb, FW_CONFIG_ID);
  78. if (fw_config_info == NULL) {
  79. ret = -1;
  80. ERROR("Invalid FW_CONFIG address\n");
  81. plat_error_handler(ret);
  82. }
  83. ret = fconf_populate_dtb_registry(fw_config_info->config_addr);
  84. if (ret < 0) {
  85. ERROR("Parsing of FW_CONFIG failed %d\n", ret);
  86. plat_error_handler(ret);
  87. }
  88. }
  89. #endif /* ARM_FW_CONFIG_LOAD_ENABLE */
  90. /*******************************************************************************
  91. * Perform the very early platform specific architectural setup here. At the
  92. * moment this is only initializes the mmu in a quick and dirty way.
  93. ******************************************************************************/
  94. void arm_bl2_el3_plat_arch_setup(void)
  95. {
  96. #if USE_COHERENT_MEM
  97. /* Ensure ARM platforms dont use coherent memory
  98. * in RESET_TO_BL2
  99. */
  100. assert(BL_COHERENT_RAM_END - BL_COHERENT_RAM_BASE == 0U);
  101. #endif
  102. const mmap_region_t bl_regions[] = {
  103. MAP_BL2_EL3_TOTAL,
  104. ARM_MAP_BL_RO,
  105. {0}
  106. };
  107. setup_page_tables(bl_regions, plat_arm_get_mmap());
  108. #ifdef __aarch64__
  109. enable_mmu_el3(0);
  110. #else
  111. enable_mmu_svc_mon(0);
  112. #endif
  113. }
  114. void bl2_el3_plat_arch_setup(void)
  115. {
  116. int __maybe_unused ret;
  117. arm_bl2_el3_plat_arch_setup();
  118. #if ARM_GPT_SUPPORT
  119. ret = gpt_partition_init();
  120. if (ret != 0) {
  121. ERROR("GPT partition initialisation failed!\n");
  122. panic();
  123. }
  124. #endif /* ARM_GPT_SUPPORT */
  125. }
  126. void bl2_el3_plat_prepare_exit(void)
  127. {
  128. }