fvp_sp_min_setup.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /*
  2. * Copyright (c) 2016-2023, Arm Limited and Contributors. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #include <assert.h>
  7. #include <bl32/sp_min/platform_sp_min.h>
  8. #include <common/debug.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 "../fvp_private.h"
  13. void plat_arm_sp_min_early_platform_setup(u_register_t arg0, u_register_t arg1,
  14. u_register_t arg2, u_register_t arg3)
  15. {
  16. const struct dyn_cfg_dtb_info_t *tos_fw_config_info __unused;
  17. /* Initialize the console to provide early debug support */
  18. arm_console_boot_init();
  19. #if !RESET_TO_SP_MIN && !RESET_TO_BL2
  20. INFO("SP_MIN FCONF: FW_CONFIG address = %lx\n", (uintptr_t)arg1);
  21. /* Fill the properties struct with the info from the config dtb */
  22. fconf_populate("FW_CONFIG", arg1);
  23. tos_fw_config_info = FCONF_GET_PROPERTY(dyn_cfg, dtb, TOS_FW_CONFIG_ID);
  24. if (tos_fw_config_info != NULL) {
  25. arg1 = tos_fw_config_info->config_addr;
  26. }
  27. #endif /* !RESET_TO_SP_MIN && !RESET_TO_BL2 */
  28. arm_sp_min_early_platform_setup((void *)arg0, arg1, arg2, (void *)arg3);
  29. /* Initialize the platform config for future decision making */
  30. fvp_config_setup();
  31. /*
  32. * Initialize the correct interconnect for this cluster during cold
  33. * boot. No need for locks as no other CPU is active.
  34. */
  35. fvp_interconnect_init();
  36. /*
  37. * Enable coherency in interconnect for the primary CPU's cluster.
  38. * Earlier bootloader stages might already do this (e.g. Trusted
  39. * Firmware's BL1 does it) but we can't assume so. There is no harm in
  40. * executing this code twice anyway.
  41. * FVP PSCI code will enable coherency for other clusters.
  42. */
  43. fvp_interconnect_enable();
  44. }
  45. void sp_min_plat_arch_setup(void)
  46. {
  47. int rc __unused;
  48. const struct dyn_cfg_dtb_info_t *hw_config_info __unused;
  49. uintptr_t hw_config_base_align __unused;
  50. size_t mapped_size_align __unused;
  51. arm_sp_min_plat_arch_setup();
  52. /*
  53. * For RESET_TO_SP_MIN systems, SP_MIN(BL32) is the first bootloader
  54. * to run. So there is no BL2 to load the HW_CONFIG dtb into memory
  55. * before control is passed to SP_MIN.
  56. * Also, BL2 skips loading HW_CONFIG dtb for
  57. * RESET_TO_BL2 builds.
  58. * The code below relies on dynamic mapping capability,
  59. * which is not supported by xlat tables lib V1.
  60. * TODO: remove the ARM_XLAT_TABLES_LIB_V1 check when its support
  61. * gets deprecated.
  62. */
  63. #if !RESET_TO_SP_MIN && !RESET_TO_BL2 && !ARM_XLAT_TABLES_LIB_V1
  64. hw_config_info = FCONF_GET_PROPERTY(dyn_cfg, dtb, HW_CONFIG_ID);
  65. assert(hw_config_info != NULL);
  66. assert(hw_config_info->config_addr != 0UL);
  67. INFO("SP_MIN FCONF: HW_CONFIG address = %p\n",
  68. (void *)hw_config_info->config_addr);
  69. /*
  70. * Preferably we expect this address and size are page aligned,
  71. * but if they are not then align it.
  72. */
  73. hw_config_base_align = page_align(hw_config_info->config_addr, DOWN);
  74. mapped_size_align = page_align(hw_config_info->config_max_size, UP);
  75. if ((hw_config_info->config_addr != hw_config_base_align) &&
  76. (hw_config_info->config_max_size == mapped_size_align)) {
  77. mapped_size_align += PAGE_SIZE;
  78. }
  79. /*
  80. * map dynamically HW config region with its aligned base address and
  81. * size
  82. */
  83. rc = mmap_add_dynamic_region((unsigned long long)hw_config_base_align,
  84. hw_config_base_align,
  85. mapped_size_align,
  86. MT_RO_DATA);
  87. if (rc != 0) {
  88. ERROR("Error while mapping HW_CONFIG device tree (%d).\n", rc);
  89. panic();
  90. }
  91. /* Populate HW_CONFIG device tree with the mapped address */
  92. fconf_populate("HW_CONFIG", hw_config_info->config_addr);
  93. /* unmap the HW_CONFIG memory region */
  94. rc = mmap_remove_dynamic_region(hw_config_base_align, mapped_size_align);
  95. if (rc != 0) {
  96. ERROR("Error while unmapping HW_CONFIG device tree (%d).\n",
  97. rc);
  98. panic();
  99. }
  100. #endif /*!RESET_TO_SP_MIN && !RESET_TO_BL2 && !ARM_XLAT_TABLES_LIB_V1*/
  101. }