blob: 705ec384c5432b46c09a4b769bf683810723a396 [file] [log] [blame]
Soby Mathew7b754182016-07-11 14:15:27 +01001/*
Arvind Ram Prakash11b9b492022-11-22 14:41:00 -06002 * Copyright (c) 2016-2023, 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
Arvind Ram Prakash11b9b492022-11-22 14:41:00 -060025#if !RESET_TO_SP_MIN && !RESET_TO_BL2
Manish V Badarkhe86854e72022-03-15 16:05:58 +000026
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 Prakash11b9b492022-11-22 14:41:00 -060035#endif /* !RESET_TO_SP_MIN && !RESET_TO_BL2 */
Manish V Badarkhe86854e72022-03-15 16:05:58 +000036
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.
Arvind Ram Prakash11b9b492022-11-22 14:41:00 -060071 * 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 Badarkhe86854e72022-03-15 16:05:58 +000075 * TODO: remove the ARM_XLAT_TABLES_LIB_V1 check when its support
76 * gets deprecated.
Madhukar Pappireddyae9677b2020-01-27 13:37:51 -060077 */
Arvind Ram Prakash11b9b492022-11-22 14:41:00 -060078#if !RESET_TO_SP_MIN && !RESET_TO_BL2 && !ARM_XLAT_TABLES_LIB_V1
Manish V Badarkhe86854e72022-03-15 16:05:58 +000079 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 Haouas2be03c02023-02-13 09:14:48 +010087 * Preferably we expect this address and size are page aligned,
Manish V Badarkhe86854e72022-03-15 16:05:58 +000088 * 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 Pappireddyae9677b2020-01-27 13:37:51 -0600113
Manish V Badarkhe86854e72022-03-15 16:05:58 +0000114 /* 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 Prakash11b9b492022-11-22 14:41:00 -0600121#endif /*!RESET_TO_SP_MIN && !RESET_TO_BL2 && !ARM_XLAT_TABLES_LIB_V1*/
Soby Mathew7b754182016-07-11 14:15:27 +0100122}