blob: 869830d41433fbeefa3b0f111ed66352cb03ddb5 [file] [log] [blame]
Roberto Vargas52207802017-11-17 13:22:18 +00001/*
Divin Rajaad650e2024-04-04 10:16:14 +01002 * Copyright (c) 2017-2024, ARM Limited and Contributors. All rights reserved.
Roberto Vargas52207802017-11-17 13:22:18 +00003 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
Antonio Nino Diaze0f90632018-12-14 00:18:21 +00006
Daniel Boulby45a2c9e2018-07-06 16:54:44 +01007#include <assert.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +00008
9#include <drivers/generic_delay_timer.h>
Harsimran Singh Tungaldc16c8f2023-10-20 11:24:07 +010010#include <drivers/partition/partition.h>
Divin Rajaad650e2024-04-04 10:16:14 +010011#include <lib/fconf/fconf.h>
12#include <lib/fconf/fconf_dyn_cfg_getter.h>
Antonio Nino Diazbd7b7402019-01-25 14:30:04 +000013#include <plat/arm/common/plat_arm.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000014#include <plat/common/platform.h>
Antonio Nino Diaza320ecd2019-01-15 14:19:50 +000015#include <platform_def.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000016
Roberto Vargas52207802017-11-17 13:22:18 +000017#pragma weak bl2_el3_early_platform_setup
18#pragma weak bl2_el3_plat_arch_setup
19#pragma weak bl2_el3_plat_prepare_exit
20
Daniel Boulby45a2c9e2018-07-06 16:54:44 +010021#define MAP_BL2_EL3_TOTAL MAP_REGION_FLAT( \
22 bl2_el3_tzram_layout.total_base, \
23 bl2_el3_tzram_layout.total_size, \
24 MT_MEMORY | MT_RW | MT_SECURE)
25
Roberto Vargas52207802017-11-17 13:22:18 +000026static meminfo_t bl2_el3_tzram_layout;
27
28/*
29 * Perform arm specific early platform setup. At this moment we only initialize
30 * the console and the memory layout.
31 */
32void arm_bl2_el3_early_platform_setup(void)
33{
34 /* Initialize the console to provide early debug support */
Antonio Nino Diaz23ede6a2018-06-19 09:29:36 +010035 arm_console_boot_init();
Roberto Vargas52207802017-11-17 13:22:18 +000036
37 /*
38 * Allow BL2 to see the whole Trusted RAM. This is determined
39 * statically since we cannot rely on BL1 passing this information
Arvind Ram Prakash11b9b492022-11-22 14:41:00 -060040 * in the RESET_TO_BL2 case.
Roberto Vargas52207802017-11-17 13:22:18 +000041 */
42 bl2_el3_tzram_layout.total_base = ARM_BL_RAM_BASE;
43 bl2_el3_tzram_layout.total_size = ARM_BL_RAM_SIZE;
44
45 /* Initialise the IO layer and register platform IO devices */
46 plat_arm_io_setup();
47}
48
49void bl2_el3_early_platform_setup(u_register_t arg0 __unused,
50 u_register_t arg1 __unused,
51 u_register_t arg2 __unused,
52 u_register_t arg3 __unused)
53{
54 arm_bl2_el3_early_platform_setup();
55
56 /*
57 * Initialize Interconnect for this cluster during cold boot.
58 * No need for locks as no other CPU is active.
59 */
60 plat_arm_interconnect_init();
61 /*
62 * Enable Interconnect coherency for the primary CPU's cluster.
63 */
64 plat_arm_interconnect_enter_coherency();
65
66 generic_delay_timer_init();
67}
68
Divin Rajaad650e2024-04-04 10:16:14 +010069#if ARM_FW_CONFIG_LOAD_ENABLE
70/*************************************************************************************
71 * FW CONFIG load function for BL2 when RESET_TO_BL2=1 && ARM_FW_CONFIG_LOAD_ENABLE=1
72 *************************************************************************************/
73void arm_bl2_el3_plat_config_load(void)
74{
75 int ret;
76 const struct dyn_cfg_dtb_info_t *fw_config_info;
77
78 /* Set global DTB info for fixed fw_config information */
79 set_config_info(PLAT_FW_CONFIG_BASE, ~0UL, PLAT_FW_CONFIG_MAX_SIZE, FW_CONFIG_ID);
80
81 /* Fill the device tree information struct with the info from the config dtb */
82 ret = fconf_load_config(FW_CONFIG_ID);
83 if (ret < 0) {
84 ERROR("Loading of FW_CONFIG failed %d\n", ret);
85 plat_error_handler(ret);
86 }
87
88 /*
89 * FW_CONFIG loaded successfully. Check the FW_CONFIG device tree parsing
90 * is successful.
91 */
92 fw_config_info = FCONF_GET_PROPERTY(dyn_cfg, dtb, FW_CONFIG_ID);
93 if (fw_config_info == NULL) {
94 ret = -1;
95 ERROR("Invalid FW_CONFIG address\n");
96 plat_error_handler(ret);
97 }
98 ret = fconf_populate_dtb_registry(fw_config_info->config_addr);
99 if (ret < 0) {
100 ERROR("Parsing of FW_CONFIG failed %d\n", ret);
101 plat_error_handler(ret);
102 }
103}
104#endif /* ARM_FW_CONFIG_LOAD_ENABLE */
105
Roberto Vargas52207802017-11-17 13:22:18 +0000106/*******************************************************************************
107 * Perform the very early platform specific architectural setup here. At the
108 * moment this is only initializes the mmu in a quick and dirty way.
109 ******************************************************************************/
110void arm_bl2_el3_plat_arch_setup(void)
111{
Daniel Boulby45a2c9e2018-07-06 16:54:44 +0100112
Roberto Vargas52207802017-11-17 13:22:18 +0000113#if USE_COHERENT_MEM
Arvind Ram Prakash11b9b492022-11-22 14:41:00 -0600114 /* Ensure ARM platforms dont use coherent memory
115 * in RESET_TO_BL2
116 */
Daniel Boulby45a2c9e2018-07-06 16:54:44 +0100117 assert(BL_COHERENT_RAM_END - BL_COHERENT_RAM_BASE == 0U);
Roberto Vargas52207802017-11-17 13:22:18 +0000118#endif
Daniel Boulby45a2c9e2018-07-06 16:54:44 +0100119
120 const mmap_region_t bl_regions[] = {
121 MAP_BL2_EL3_TOTAL,
Daniel Boulby4e97abd2018-07-16 14:09:15 +0100122 ARM_MAP_BL_RO,
Daniel Boulby45a2c9e2018-07-06 16:54:44 +0100123 {0}
124 };
125
Roberto Vargas344ff022018-10-19 16:44:18 +0100126 setup_page_tables(bl_regions, plat_arm_get_mmap());
Roberto Vargas52207802017-11-17 13:22:18 +0000127
Julius Werner8e0ef0f2019-07-09 14:02:43 -0700128#ifdef __aarch64__
Roberto Vargas52207802017-11-17 13:22:18 +0000129 enable_mmu_el3(0);
Julius Werner8e0ef0f2019-07-09 14:02:43 -0700130#else
131 enable_mmu_svc_mon(0);
Roberto Vargas52207802017-11-17 13:22:18 +0000132#endif
133}
134
135void bl2_el3_plat_arch_setup(void)
136{
Harsimran Singh Tungaldc16c8f2023-10-20 11:24:07 +0100137 int __maybe_unused ret;
Roberto Vargas52207802017-11-17 13:22:18 +0000138 arm_bl2_el3_plat_arch_setup();
Harsimran Singh Tungaldc16c8f2023-10-20 11:24:07 +0100139#if ARM_GPT_SUPPORT
140 ret = gpt_partition_init();
141 if (ret != 0) {
142 ERROR("GPT partition initialisation failed!\n");
143 panic();
144 }
145#endif /* ARM_GPT_SUPPORT */
Roberto Vargas52207802017-11-17 13:22:18 +0000146}
147
148void bl2_el3_plat_prepare_exit(void)
149{
150}