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