blob: f15c13791f07e5a0280bd18ebcb8ee9989621922 [file] [log] [blame]
Soby Mathew7b754182016-07-11 14:15:27 +01001/*
Zelalem87675d42020-02-03 14:56:42 -06002 * Copyright (c) 2016-2020, 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
7#include <assert.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +00008
Soby Mathew7b754182016-07-11 14:15:27 +01009#include <platform_def.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000010
11#include <bl32/sp_min/platform_sp_min.h>
12#include <common/bl_common.h>
13#include <common/debug.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000014#include <drivers/console.h>
15#include <lib/mmio.h>
Antonio Nino Diazbd7b7402019-01-25 14:30:04 +000016#include <plat/arm/common/plat_arm.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000017#include <plat/common/platform.h>
18
Soby Mathew7b754182016-07-11 14:15:27 +010019static entry_point_info_t bl33_image_ep_info;
20
21/* Weak definitions may be overridden in specific ARM standard platform */
Soby Mathew7b754182016-07-11 14:15:27 +010022#pragma weak sp_min_platform_setup
23#pragma weak sp_min_plat_arch_setup
Soby Mathew6d07e672018-03-01 10:53:33 +000024#pragma weak plat_arm_sp_min_early_platform_setup
Soby Mathew7b754182016-07-11 14:15:27 +010025
Daniel Boulby45a2c9e2018-07-06 16:54:44 +010026#define MAP_BL_SP_MIN_TOTAL MAP_REGION_FLAT( \
27 BL32_BASE, \
28 BL32_END - BL32_BASE, \
29 MT_MEMORY | MT_RW | MT_SECURE)
30
Soby Mathewaf14b462018-06-01 16:53:38 +010031/*
Manish V Badarkhe1da211a2020-05-31 10:17:59 +010032 * Check that BL32_BASE is above ARM_FW_CONFIG_LIMIT. The reserved page
Soby Mathewaf14b462018-06-01 16:53:38 +010033 * is required for SOC_FW_CONFIG/TOS_FW_CONFIG passed from BL2.
34 */
Manish Pandey928da862021-06-10 15:22:48 +010035#if !RESET_TO_SP_MIN
Manish V Badarkhe1da211a2020-05-31 10:17:59 +010036CASSERT(BL32_BASE >= ARM_FW_CONFIG_LIMIT, assert_bl32_base_overflows);
Manish Pandey928da862021-06-10 15:22:48 +010037#endif
Soby Mathew7b754182016-07-11 14:15:27 +010038
39/*******************************************************************************
40 * Return a pointer to the 'entry_point_info' structure of the next image for the
41 * security state specified. BL33 corresponds to the non-secure image type
42 * while BL32 corresponds to the secure image type. A NULL pointer is returned
43 * if the image does not exist.
44 ******************************************************************************/
45entry_point_info_t *sp_min_plat_get_bl33_ep_info(void)
46{
47 entry_point_info_t *next_image_info;
48
49 next_image_info = &bl33_image_ep_info;
50
51 /*
52 * None of the images on the ARM development platforms can have 0x0
53 * as the entrypoint
54 */
55 if (next_image_info->pc)
56 return next_image_info;
57 else
58 return NULL;
59}
60
61/*******************************************************************************
Soby Mathew6d07e672018-03-01 10:53:33 +000062 * Utility function to perform early platform setup.
Soby Mathew7b754182016-07-11 14:15:27 +010063 ******************************************************************************/
Soby Mathew7d5a2e72018-01-10 15:59:31 +000064void arm_sp_min_early_platform_setup(void *from_bl2, uintptr_t tos_fw_config,
65 uintptr_t hw_config, void *plat_params_from_bl2)
Soby Mathew7b754182016-07-11 14:15:27 +010066{
67 /* Initialize the console to provide early debug support */
Daniel Boulby05e7f562018-09-19 13:58:20 +010068 arm_console_boot_init();
Soby Mathew7b754182016-07-11 14:15:27 +010069
Yatharth Kochar1c16a4c2016-06-30 14:50:58 +010070#if RESET_TO_SP_MIN
71 /* There are no parameters from BL2 if SP_MIN is a reset vector */
72 assert(from_bl2 == NULL);
73 assert(plat_params_from_bl2 == NULL);
74
Soby Mathew7b754182016-07-11 14:15:27 +010075 /* Populate entry point information for BL33 */
76 SET_PARAM_HEAD(&bl33_image_ep_info,
77 PARAM_EP,
78 VERSION_1,
79 0);
80 /*
81 * Tell SP_MIN where the non-trusted software image
82 * is located and the entry state information
83 */
Soby Mathew7b754182016-07-11 14:15:27 +010084 bl33_image_ep_info.pc = plat_get_ns_image_entrypoint();
Soby Mathew7b754182016-07-11 14:15:27 +010085 bl33_image_ep_info.spsr = arm_get_spsr_for_bl33_entry();
86 SET_SECURITY_STATE(bl33_image_ep_info.h.attr, NON_SECURE);
Yatharth Kochar1c16a4c2016-06-30 14:50:58 +010087
Manish Pandey37c4ec22018-11-02 13:28:25 +000088# if ARM_LINUX_KERNEL_AS_BL33
89 /*
90 * According to the file ``Documentation/arm/Booting`` of the Linux
91 * kernel tree, Linux expects:
92 * r0 = 0
93 * r1 = machine type number, optional in DT-only platforms (~0 if so)
94 * r2 = Physical address of the device tree blob
95 */
96 bl33_image_ep_info.args.arg0 = 0U;
97 bl33_image_ep_info.args.arg1 = ~0U;
98 bl33_image_ep_info.args.arg2 = (u_register_t)ARM_PRELOADED_DTB_BASE;
99# endif
100
Yatharth Kochar1c16a4c2016-06-30 14:50:58 +0100101#else /* RESET_TO_SP_MIN */
102
103 /*
104 * Check params passed from BL2 should not be NULL,
105 */
106 bl_params_t *params_from_bl2 = (bl_params_t *)from_bl2;
107 assert(params_from_bl2 != NULL);
108 assert(params_from_bl2->h.type == PARAM_BL_PARAMS);
109 assert(params_from_bl2->h.version >= VERSION_2);
110
111 bl_params_node_t *bl_params = params_from_bl2->head;
112
113 /*
114 * Copy BL33 entry point information.
115 * They are stored in Secure RAM, in BL2's address space.
116 */
117 while (bl_params) {
118 if (bl_params->image_id == BL33_IMAGE_ID) {
119 bl33_image_ep_info = *bl_params->ep_info;
120 break;
121 }
122
123 bl_params = bl_params->next_params_info;
124 }
125
126 if (bl33_image_ep_info.pc == 0)
127 panic();
128
129#endif /* RESET_TO_SP_MIN */
130
Soby Mathew7b754182016-07-11 14:15:27 +0100131}
132
Soby Mathew6d07e672018-03-01 10:53:33 +0000133/*******************************************************************************
134 * Default implementation for sp_min_platform_setup2() for ARM platforms
135 ******************************************************************************/
136void plat_arm_sp_min_early_platform_setup(u_register_t arg0, u_register_t arg1,
Soby Mathew7d5a2e72018-01-10 15:59:31 +0000137 u_register_t arg2, u_register_t arg3)
Soby Mathew7b754182016-07-11 14:15:27 +0100138{
Soby Mathew7d5a2e72018-01-10 15:59:31 +0000139 arm_sp_min_early_platform_setup((void *)arg0, arg1, arg2, (void *)arg3);
Soby Mathew7b754182016-07-11 14:15:27 +0100140
141 /*
142 * Initialize Interconnect for this cluster during cold boot.
143 * No need for locks as no other CPU is active.
144 */
145 plat_arm_interconnect_init();
146
147 /*
148 * Enable Interconnect coherency for the primary CPU's cluster.
149 * Earlier bootloader stages might already do this (e.g. Trusted
150 * Firmware's BL1 does it) but we can't assume so. There is no harm in
151 * executing this code twice anyway.
152 * Platform specific PSCI code will enable coherency for other
153 * clusters.
154 */
155 plat_arm_interconnect_enter_coherency();
156}
157
Soby Mathew6d07e672018-03-01 10:53:33 +0000158void sp_min_early_platform_setup2(u_register_t arg0, u_register_t arg1,
159 u_register_t arg2, u_register_t arg3)
160{
161 plat_arm_sp_min_early_platform_setup(arg0, arg1, arg2, arg3);
162}
163
Soby Mathew7b754182016-07-11 14:15:27 +0100164/*******************************************************************************
Dimitris Papastamos52323b02017-06-07 13:45:41 +0100165 * Perform any SP_MIN platform runtime setup prior to SP_MIN exit.
166 * Common to ARM standard platforms.
167 ******************************************************************************/
168void arm_sp_min_plat_runtime_setup(void)
169{
170 /* Initialize the runtime console */
Daniel Boulby05e7f562018-09-19 13:58:20 +0100171 arm_console_runtime_init();
Petre-Ionut Tudore5a6fef2019-11-07 15:18:03 +0000172
173#if PLAT_RO_XLAT_TABLES
174 arm_xlat_make_tables_readonly();
175#endif
Dimitris Papastamos52323b02017-06-07 13:45:41 +0100176}
177
178/*******************************************************************************
Soby Mathew7b754182016-07-11 14:15:27 +0100179 * Perform platform specific setup for SP_MIN
180 ******************************************************************************/
181void sp_min_platform_setup(void)
182{
183 /* Initialize the GIC driver, cpu and distributor interfaces */
184 plat_arm_gic_driver_init();
185 plat_arm_gic_init();
186
187 /*
188 * Do initial security configuration to allow DRAM/device access
189 * (if earlier BL has not already done so).
Soby Mathew7b754182016-07-11 14:15:27 +0100190 */
Manish V Badarkhec00b4822020-08-27 13:16:21 +0100191#if RESET_TO_SP_MIN && !JUNO_AARCH32_EL3_RUNTIME
Soby Mathew7b754182016-07-11 14:15:27 +0100192 plat_arm_security_setup();
Roberto Vargas550eb082018-01-05 16:00:05 +0000193
194#if defined(PLAT_ARM_MEM_PROT_ADDR)
195 arm_nor_psci_do_dyn_mem_protect();
196#endif /* PLAT_ARM_MEM_PROT_ADDR */
197
Yatharth Kochar1c16a4c2016-06-30 14:50:58 +0100198#endif
Soby Mathew7b754182016-07-11 14:15:27 +0100199
200 /* Enable and initialize the System level generic timer */
Usama Arife97998f2018-11-30 15:43:56 +0000201#ifdef ARM_SYS_CNTCTL_BASE
Soby Mathew7b754182016-07-11 14:15:27 +0100202 mmio_write_32(ARM_SYS_CNTCTL_BASE + CNTCR_OFF,
Antonio Nino Diaze0b757d2018-08-24 16:30:29 +0100203 CNTCR_FCREQ(0U) | CNTCR_EN);
Usama Arife97998f2018-11-30 15:43:56 +0000204#endif
205#ifdef ARM_SYS_TIMCTL_BASE
Soby Mathew7b754182016-07-11 14:15:27 +0100206 /* Allow access to the System counter timer module */
207 arm_configure_sys_timer();
Usama Arife97998f2018-11-30 15:43:56 +0000208#endif
Soby Mathew7b754182016-07-11 14:15:27 +0100209 /* Initialize power controller before setting up topology */
210 plat_arm_pwrc_setup();
211}
212
Dimitris Papastamos52323b02017-06-07 13:45:41 +0100213void sp_min_plat_runtime_setup(void)
214{
215 arm_sp_min_plat_runtime_setup();
216}
217
Soby Mathew7b754182016-07-11 14:15:27 +0100218/*******************************************************************************
219 * Perform the very early platform specific architectural setup here. At the
220 * moment this only initializes the MMU
221 ******************************************************************************/
Madhukar Pappireddyae9677b2020-01-27 13:37:51 -0600222void arm_sp_min_plat_arch_setup(void)
Soby Mathew7b754182016-07-11 14:15:27 +0100223{
Daniel Boulby45a2c9e2018-07-06 16:54:44 +0100224 const mmap_region_t bl_regions[] = {
225 MAP_BL_SP_MIN_TOTAL,
Daniel Boulby4e97abd2018-07-16 14:09:15 +0100226 ARM_MAP_BL_RO,
Soby Mathew7b754182016-07-11 14:15:27 +0100227#if USE_COHERENT_MEM
Daniel Boulby45a2c9e2018-07-06 16:54:44 +0100228 ARM_MAP_BL_COHERENT_RAM,
Soby Mathew7b754182016-07-11 14:15:27 +0100229#endif
Daniel Boulby45a2c9e2018-07-06 16:54:44 +0100230 {0}
231 };
232
Roberto Vargas344ff022018-10-19 16:44:18 +0100233 setup_page_tables(bl_regions, plat_arm_get_mmap());
Soby Mathew7b754182016-07-11 14:15:27 +0100234
Antonio Nino Diaz533d3a82018-08-07 16:35:19 +0100235 enable_mmu_svc_mon(0);
Soby Mathew7b754182016-07-11 14:15:27 +0100236}
Madhukar Pappireddyae9677b2020-01-27 13:37:51 -0600237
238void sp_min_plat_arch_setup(void)
239{
240 arm_sp_min_plat_arch_setup();
241}