blob: 9ab36a6c2f62a52f189a1827d13abd74cf3f1665 [file] [log] [blame]
Soby Mathew7b754182016-07-11 14:15:27 +01001/*
Manish V Badarkhe86854e72022-03-15 16:05:58 +00002 * Copyright (c) 2016-2022, Arm Limited and Contributors. All rights reserved.
Soby Mathew7b754182016-07-11 14:15:27 +01003 *
dp-armfa3cf0b2017-05-03 09:38:09 +01004 * SPDX-License-Identifier: BSD-3-Clause
Soby Mathew7b754182016-07-11 14:15:27 +01005 */
6
Madhukar Pappireddyae9677b2020-01-27 13:37:51 -06007#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 Badarkhe86854e72022-03-15 16:05:58 +000012#include <lib/fconf/fconf_dyn_cfg_getter.h>
Antonio Nino Diazbd7b7402019-01-25 14:30:04 +000013#include <plat/arm/common/plat_arm.h>
14
Soby Mathew7b754182016-07-11 14:15:27 +010015#include "../fvp_private.h"
16
Soby Mathew6d07e672018-03-01 10:53:33 +000017void plat_arm_sp_min_early_platform_setup(u_register_t arg0, u_register_t arg1,
Soby Mathew7d5a2e72018-01-10 15:59:31 +000018 u_register_t arg2, u_register_t arg3)
Soby Mathew7b754182016-07-11 14:15:27 +010019{
Manish V Badarkhe86854e72022-03-15 16:05:58 +000020 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
25#if !RESET_TO_SP_MIN && !BL2_AT_EL3
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 }
35#endif /* !RESET_TO_SP_MIN && !BL2_AT_EL3 */
36
Soby Mathew7d5a2e72018-01-10 15:59:31 +000037 arm_sp_min_early_platform_setup((void *)arg0, arg1, arg2, (void *)arg3);
Soby Mathew7b754182016-07-11 14:15:27 +010038
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 Pappireddyae9677b2020-01-27 13:37:51 -060056}
57
58void sp_min_plat_arch_setup(void)
59{
Manish V Badarkhe86854e72022-03-15 16:05:58 +000060 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 Pappireddyae9677b2020-01-27 13:37:51 -060065 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.
71 * Also, BL2 skips loading HW_CONFIG dtb for BL2_AT_EL3 builds.
Manish V Badarkhe86854e72022-03-15 16:05:58 +000072 * The code below relies on dynamic mapping capability, which is not
73 * supported by xlat tables lib V1.
74 * TODO: remove the ARM_XLAT_TABLES_LIB_V1 check when its support
75 * gets deprecated.
Madhukar Pappireddyae9677b2020-01-27 13:37:51 -060076 */
Manish V Badarkhe86854e72022-03-15 16:05:58 +000077#if !RESET_TO_SP_MIN && !BL2_AT_EL3 && !ARM_XLAT_TABLES_LIB_V1
78 hw_config_info = FCONF_GET_PROPERTY(dyn_cfg, dtb, HW_CONFIG_ID);
79 assert(hw_config_info != NULL);
80 assert(hw_config_info->config_addr != 0UL);
81
82 INFO("SP_MIN FCONF: HW_CONFIG address = %p\n",
83 (void *)hw_config_info->config_addr);
84
85 /*
86 * Preferrably we expect this address and size are page aligned,
87 * but if they are not then align it.
88 */
89 hw_config_base_align = page_align(hw_config_info->config_addr, DOWN);
90 mapped_size_align = page_align(hw_config_info->config_max_size, UP);
91
92 if ((hw_config_info->config_addr != hw_config_base_align) &&
93 (hw_config_info->config_max_size == mapped_size_align)) {
94 mapped_size_align += PAGE_SIZE;
95 }
96
97 /*
98 * map dynamically HW config region with its aligned base address and
99 * size
100 */
101 rc = mmap_add_dynamic_region((unsigned long long)hw_config_base_align,
102 hw_config_base_align,
103 mapped_size_align,
104 MT_RO_DATA);
105 if (rc != 0) {
106 ERROR("Error while mapping HW_CONFIG device tree (%d).\n", rc);
107 panic();
108 }
109
110 /* Populate HW_CONFIG device tree with the mapped address */
111 fconf_populate("HW_CONFIG", hw_config_info->config_addr);
Madhukar Pappireddyae9677b2020-01-27 13:37:51 -0600112
Manish V Badarkhe86854e72022-03-15 16:05:58 +0000113 /* unmap the HW_CONFIG memory region */
114 rc = mmap_remove_dynamic_region(hw_config_base_align, mapped_size_align);
115 if (rc != 0) {
116 ERROR("Error while unmapping HW_CONFIG device tree (%d).\n",
117 rc);
118 panic();
119 }
120#endif /* !RESET_TO_SP_MIN && !BL2_AT_EL3 && !ARM_XLAT_TABLES_LIB_V1 */
Soby Mathew7b754182016-07-11 14:15:27 +0100121}