blob: e8283517dd19639544af8af2ba1293625ec1be3b [file] [log] [blame]
Varun Wadekar08438e22015-05-19 16:48:04 +05301/*
Madhukar Pappireddyca661a02019-12-23 14:49:52 -06002 * Copyright (c) 2015-2020, ARM Limited and Contributors. All rights reserved.
Varun Wadekaree212812018-06-20 13:43:43 -07003 * Copyright (c) 2020, NVIDIA Corporation. All rights reserved.
Varun Wadekar08438e22015-05-19 16:48:04 +05304 *
dp-arm82cb2c12017-05-03 09:38:09 +01005 * SPDX-License-Identifier: BSD-3-Clause
Varun Wadekar08438e22015-05-19 16:48:04 +05306 */
7
Varun Wadekar08438e22015-05-19 16:48:04 +05308#include <assert.h>
Varun Wadekar9a964512015-06-10 14:04:32 +05309#include <errno.h>
Varun Wadekar08438e22015-05-19 16:48:04 +053010#include <stddef.h>
Varun Wadekarda3849e2016-05-23 15:56:14 -070011#include <string.h>
Antonio Nino Diaz09d40e02018-12-14 00:18:21 +000012
13#include <platform_def.h>
14
15#include <arch.h>
16#include <arch_helpers.h>
17#include <bl31/bl31.h>
18#include <common/bl_common.h>
19#include <common/debug.h>
20#include <cortex_a53.h>
21#include <cortex_a57.h>
22#include <denver.h>
23#include <drivers/console.h>
24#include <lib/mmio.h>
25#include <lib/utils.h>
26#include <lib/utils_def.h>
27#include <plat/common/platform.h>
28
29#include <memctrl.h>
Varun Wadekar087cf682017-07-21 13:34:16 -070030#include <profiler.h>
Varun Wadekar06b19d52015-12-30 15:06:41 -080031#include <tegra_def.h>
Harvey Hsieh322e7c32017-04-10 16:20:32 +080032#include <tegra_platform.h>
Varun Wadekar08438e22015-05-19 16:48:04 +053033#include <tegra_private.h>
34
Arve Hjønnevåg06ff2512018-02-21 17:36:44 -080035/* length of Trusty's input parameters (in bytes) */
36#define TRUSTY_PARAMS_LEN_BYTES (4096*2)
37
Antonio Nino Diaz93c78ed2018-08-16 16:52:57 +010038extern void memcpy16(void *dest, const void *src, unsigned int length);
Varun Wadekarda3849e2016-05-23 15:56:14 -070039
Varun Wadekar08438e22015-05-19 16:48:04 +053040/*******************************************************************************
41 * Declarations of linker defined symbols which will help us find the layout
42 * of trusted SRAM
43 ******************************************************************************/
Joel Hutton9f85f9e2018-03-21 11:40:57 +000044
Varun Wadekarfcf23a12019-01-02 10:48:18 -080045IMPORT_SYM(uint64_t, __RW_START__, BL31_RW_START);
Madhukar Pappireddyca661a02019-12-23 14:49:52 -060046
47static const uint64_t BL31_RW_END = BL_END;
48static const uint64_t BL31_RODATA_BASE = BL_RO_DATA_BASE;
49static const uint64_t BL31_RODATA_END = BL_RO_DATA_END;
50static const uint64_t TEXT_START = BL_CODE_BASE;
51static const uint64_t TEXT_END = BL_CODE_END;
Varun Wadekar08438e22015-05-19 16:48:04 +053052
Varun Wadekar08438e22015-05-19 16:48:04 +053053extern uint64_t tegra_bl31_phys_base;
54
Varun Wadekardc7fdad2015-06-05 12:57:27 +053055static entry_point_info_t bl33_image_ep_info, bl32_image_ep_info;
Varun Wadekar08438e22015-05-19 16:48:04 +053056static plat_params_from_bl2_t plat_bl31_params_from_bl2 = {
Varun Wadekarfcf23a12019-01-02 10:48:18 -080057 .tzdram_size = TZDRAM_SIZE
Varun Wadekar08438e22015-05-19 16:48:04 +053058};
Varun Wadekar27832052019-12-17 21:23:24 -080059#ifdef SPD_trusty
60static aapcs64_params_t bl32_args;
61#endif
Varun Wadekar08438e22015-05-19 16:48:04 +053062
63/*******************************************************************************
64 * This variable holds the non-secure image entry address
65 ******************************************************************************/
66extern uint64_t ns_image_entrypoint;
67
68/*******************************************************************************
69 * Return a pointer to the 'entry_point_info' structure of the next image for
70 * security state specified. BL33 corresponds to the non-secure image type
71 * while BL32 corresponds to the secure image type.
72 ******************************************************************************/
73entry_point_info_t *bl31_plat_get_next_image_ep_info(uint32_t type)
74{
Varun Wadekarfcf23a12019-01-02 10:48:18 -080075 entry_point_info_t *ep = NULL;
Varun Wadekar08438e22015-05-19 16:48:04 +053076
Varun Wadekar4ce9a182016-06-06 10:46:28 -070077 /* return BL32 entry point info if it is valid */
Varun Wadekarfcf23a12019-01-02 10:48:18 -080078 if (type == NON_SECURE) {
79 ep = &bl33_image_ep_info;
80 } else if ((type == SECURE) && (bl32_image_ep_info.pc != 0U)) {
81 ep = &bl32_image_ep_info;
82 }
Varun Wadekardc7fdad2015-06-05 12:57:27 +053083
Varun Wadekarfcf23a12019-01-02 10:48:18 -080084 return ep;
Varun Wadekar08438e22015-05-19 16:48:04 +053085}
86
87/*******************************************************************************
88 * Return a pointer to the 'plat_params_from_bl2_t' structure. The BL2 image
89 * passes this platform specific information.
90 ******************************************************************************/
91plat_params_from_bl2_t *bl31_get_plat_params(void)
92{
93 return &plat_bl31_params_from_bl2;
94}
95
96/*******************************************************************************
97 * Perform any BL31 specific platform actions. Populate the BL33 and BL32 image
98 * info.
99 ******************************************************************************/
Antonio Nino Diazfdcc1122018-09-24 17:16:05 +0100100void bl31_early_platform_setup2(u_register_t arg0, u_register_t arg1,
101 u_register_t arg2, u_register_t arg3)
Varun Wadekar08438e22015-05-19 16:48:04 +0530102{
Antonio Nino Diazfdcc1122018-09-24 17:16:05 +0100103 struct tegra_bl31_params *arg_from_bl2 = (struct tegra_bl31_params *) arg0;
104 plat_params_from_bl2_t *plat_params = (plat_params_from_bl2_t *)arg1;
Varun Wadekarda3849e2016-05-23 15:56:14 -0700105 image_info_t bl32_img_info = { {0} };
Varun Wadekar087cf682017-07-21 13:34:16 -0700106 int32_t ret;
Varun Wadekar08cefa92015-09-22 15:00:06 +0530107
Varun Wadekar08438e22015-05-19 16:48:04 +0530108 /*
Varun Wadekar8ab06d22016-05-23 11:41:07 -0700109 * For RESET_TO_BL31 systems, BL31 is the first bootloader to run so
110 * there's no argument to relay from a previous bootloader. Platforms
Varun Wadekar39171cd2018-05-17 09:36:38 -0700111 * might use custom ways to get arguments.
Varun Wadekar8ab06d22016-05-23 11:41:07 -0700112 */
Varun Wadekarfcf23a12019-01-02 10:48:18 -0800113 if (arg_from_bl2 == NULL) {
Antonio Nino Diazfdcc1122018-09-24 17:16:05 +0100114 arg_from_bl2 = plat_get_bl31_params();
Varun Wadekarfcf23a12019-01-02 10:48:18 -0800115 }
116 if (plat_params == NULL) {
Varun Wadekar8ab06d22016-05-23 11:41:07 -0700117 plat_params = plat_get_bl31_plat_params();
Varun Wadekarfcf23a12019-01-02 10:48:18 -0800118 }
Varun Wadekar8ab06d22016-05-23 11:41:07 -0700119
120 /*
Varun Wadekardc7fdad2015-06-05 12:57:27 +0530121 * Copy BL3-3, BL3-2 entry point information.
Varun Wadekar08438e22015-05-19 16:48:04 +0530122 * They are stored in Secure RAM, in BL2's address space.
123 */
Anthony Zhou4c994002017-07-07 14:29:51 +0800124 assert(arg_from_bl2 != NULL);
125 assert(arg_from_bl2->bl33_ep_info != NULL);
Antonio Nino Diazfdcc1122018-09-24 17:16:05 +0100126 bl33_image_ep_info = *arg_from_bl2->bl33_ep_info;
Varun Wadekar08cefa92015-09-22 15:00:06 +0530127
Varun Wadekarfcf23a12019-01-02 10:48:18 -0800128 if (arg_from_bl2->bl32_ep_info != NULL) {
Antonio Nino Diazfdcc1122018-09-24 17:16:05 +0100129 bl32_image_ep_info = *arg_from_bl2->bl32_ep_info;
Varun Wadekar27832052019-12-17 21:23:24 -0800130#ifdef SPD_trusty
131 /* save BL32 boot parameters */
132 memcpy(&bl32_args, &arg_from_bl2->bl32_ep_info->args, sizeof(bl32_args));
133#endif
Arve Hjønnevåg06ff2512018-02-21 17:36:44 -0800134 }
Varun Wadekar08438e22015-05-19 16:48:04 +0530135
136 /*
Varun Wadekar3ca3c272018-02-27 14:33:57 -0800137 * Parse platform specific parameters
Varun Wadekar08438e22015-05-19 16:48:04 +0530138 */
Anthony Zhou4c994002017-07-07 14:29:51 +0800139 assert(plat_params != NULL);
Varun Wadekare0d41582015-10-06 12:49:31 +0530140 plat_bl31_params_from_bl2.tzdram_base = plat_params->tzdram_base;
141 plat_bl31_params_from_bl2.tzdram_size = plat_params->tzdram_size;
Varun Wadekare1084212015-10-29 10:37:28 +0530142 plat_bl31_params_from_bl2.uart_id = plat_params->uart_id;
Harvey Hsiehb4957912016-11-23 19:13:08 +0800143 plat_bl31_params_from_bl2.l2_ecc_parity_prot_dis = plat_params->l2_ecc_parity_prot_dis;
Varun Wadekar3ca3c272018-02-27 14:33:57 -0800144 plat_bl31_params_from_bl2.sc7entry_fw_size = plat_params->sc7entry_fw_size;
145 plat_bl31_params_from_bl2.sc7entry_fw_base = plat_params->sc7entry_fw_base;
Varun Wadekare1084212015-10-29 10:37:28 +0530146
147 /*
Varun Wadekar939dcf22016-03-24 15:34:24 -0700148 * It is very important that we run either from TZDRAM or TZSRAM base.
149 * Add an explicit check here.
150 */
Varun Wadekarfcf23a12019-01-02 10:48:18 -0800151 if ((plat_bl31_params_from_bl2.tzdram_base != (uint64_t)BL31_BASE) &&
152 (TEGRA_TZRAM_BASE != BL31_BASE)) {
Varun Wadekar939dcf22016-03-24 15:34:24 -0700153 panic();
Varun Wadekarfcf23a12019-01-02 10:48:18 -0800154 }
Varun Wadekar939dcf22016-03-24 15:34:24 -0700155
156 /*
Varun Wadekar117dbe62019-08-21 14:01:31 -0700157 * Enable console for the platform
Harvey Hsieh322e7c32017-04-10 16:20:32 +0800158 */
Varun Wadekar117dbe62019-08-21 14:01:31 -0700159 plat_enable_console(plat_params->uart_id);
Varun Wadekare1084212015-10-29 10:37:28 +0530160
Varun Wadekar08012f42016-06-04 22:08:50 -0700161 /*
Varun Wadekar087cf682017-07-21 13:34:16 -0700162 * The previous bootloader passes the base address of the shared memory
163 * location to store the boot profiler logs. Sanity check the
Andreas Färber9d74bc32019-06-17 00:06:43 +0200164 * address and initialise the profiler library, if it looks ok.
Varun Wadekar087cf682017-07-21 13:34:16 -0700165 */
Varun Wadekaree212812018-06-20 13:43:43 -0700166 ret = bl31_check_ns_address(plat_params->boot_profiler_shmem_base,
167 PROFILER_SIZE_BYTES);
168 if (ret == (int32_t)0) {
Varun Wadekar087cf682017-07-21 13:34:16 -0700169
Varun Wadekaree212812018-06-20 13:43:43 -0700170 /* store the membase for the profiler lib */
171 plat_bl31_params_from_bl2.boot_profiler_shmem_base =
172 plat_params->boot_profiler_shmem_base;
Varun Wadekar087cf682017-07-21 13:34:16 -0700173
Varun Wadekaree212812018-06-20 13:43:43 -0700174 /* initialise the profiler library */
175 boot_profiler_init(plat_params->boot_profiler_shmem_base,
176 TEGRA_TMRUS_BASE);
Varun Wadekar087cf682017-07-21 13:34:16 -0700177 }
178
179 /*
180 * Add timestamp for platform early setup entry.
181 */
182 boot_profiler_add_record("[TF] early setup entry");
183
184 /*
Steven Kaod29d96f2016-10-21 14:16:59 +0800185 * Initialize delay timer
186 */
187 tegra_delay_timer_init();
188
Varun Wadekar01da3bd2017-09-20 15:09:38 -0700189 /* Early platform setup for Tegra SoCs */
190 plat_early_platform_setup();
191
Steven Kaod29d96f2016-10-21 14:16:59 +0800192 /*
Varun Wadekar08012f42016-06-04 22:08:50 -0700193 * Do initial security configuration to allow DRAM/device access.
194 */
195 tegra_memctrl_tzdram_setup(plat_bl31_params_from_bl2.tzdram_base,
Varun Wadekarfcf23a12019-01-02 10:48:18 -0800196 (uint32_t)plat_bl31_params_from_bl2.tzdram_size);
Varun Wadekar08012f42016-06-04 22:08:50 -0700197
Varun Wadekarda3849e2016-05-23 15:56:14 -0700198 /*
199 * The previous bootloader might not have placed the BL32 image
200 * inside the TZDRAM. We check the BL32 image info to find out
201 * the base/PC values and relocate the image if necessary.
202 */
Varun Wadekarfcf23a12019-01-02 10:48:18 -0800203 if (arg_from_bl2->bl32_image_info != NULL) {
Varun Wadekarda3849e2016-05-23 15:56:14 -0700204
Varun Wadekaree212812018-06-20 13:43:43 -0700205 uint64_t tzdram_start, tzdram_end, bl32_start, bl32_end;
Antonio Nino Diazfdcc1122018-09-24 17:16:05 +0100206 bl32_img_info = *arg_from_bl2->bl32_image_info;
Varun Wadekarda3849e2016-05-23 15:56:14 -0700207
208 /* Relocate BL32 if it resides outside of the TZDRAM */
209 tzdram_start = plat_bl31_params_from_bl2.tzdram_base;
210 tzdram_end = plat_bl31_params_from_bl2.tzdram_base +
211 plat_bl31_params_from_bl2.tzdram_size;
212 bl32_start = bl32_img_info.image_base;
213 bl32_end = bl32_img_info.image_base + bl32_img_info.image_size;
214
215 assert(tzdram_end > tzdram_start);
216 assert(bl32_end > bl32_start);
217 assert(bl32_image_ep_info.pc > tzdram_start);
218 assert(bl32_image_ep_info.pc < tzdram_end);
219
220 /* relocate BL32 */
Varun Wadekarfcf23a12019-01-02 10:48:18 -0800221 if ((bl32_start >= tzdram_end) || (bl32_end <= tzdram_start)) {
Varun Wadekarda3849e2016-05-23 15:56:14 -0700222
223 INFO("Relocate BL32 to TZDRAM\n");
224
Varun Wadekarfcf23a12019-01-02 10:48:18 -0800225 (void)memcpy16((void *)(uintptr_t)bl32_image_ep_info.pc,
Varun Wadekarda3849e2016-05-23 15:56:14 -0700226 (void *)(uintptr_t)bl32_start,
227 bl32_img_info.image_size);
228
229 /* clean up non-secure intermediate buffer */
Antonio Nino Diazfdcc1122018-09-24 17:16:05 +0100230 zeromem((void *)(uintptr_t)bl32_start,
Varun Wadekarda3849e2016-05-23 15:56:14 -0700231 bl32_img_info.image_size);
232 }
233 }
234
Varun Wadekar087cf682017-07-21 13:34:16 -0700235 /*
236 * Add timestamp for platform early setup exit.
237 */
238 boot_profiler_add_record("[TF] early setup exit");
239
Sandrine Bailleuxc426fd72018-06-21 11:41:43 +0200240 INFO("BL3-1: Boot CPU: %s Processor [%lx]\n",
241 (((read_midr() >> MIDR_IMPL_SHIFT) & MIDR_IMPL_MASK)
242 == DENVER_IMPL) ? "Denver" : "ARM", read_mpidr());
Varun Wadekar08438e22015-05-19 16:48:04 +0530243}
244
Arve Hjønnevåg06ff2512018-02-21 17:36:44 -0800245#ifdef SPD_trusty
246void plat_trusty_set_boot_args(aapcs64_params_t *args)
247{
Varun Wadekar27832052019-12-17 21:23:24 -0800248 /*
249 * arg0 = TZDRAM aperture available for BL32
250 * arg1 = BL32 boot params
251 * arg2 = EKS Blob Length
252 * arg3 = Boot Profiler Carveout Base
253 */
254 args->arg0 = bl32_args.arg0;
255 args->arg1 = bl32_args.arg2;
Varun Wadekar47b83ad2018-12-28 13:50:20 -0800256
257 /* update EKS size */
Varun Wadekar27832052019-12-17 21:23:24 -0800258 args->arg2 = bl32_args.arg4;
Varun Wadekardb82b612019-01-02 16:30:01 -0800259
260 /* Profiler Carveout Base */
Varun Wadekar27832052019-12-17 21:23:24 -0800261 args->arg3 = bl32_args.arg5;
Arve Hjønnevåg06ff2512018-02-21 17:36:44 -0800262}
263#endif
264
Varun Wadekar08438e22015-05-19 16:48:04 +0530265/*******************************************************************************
266 * Initialize the gic, configure the SCR.
267 ******************************************************************************/
268void bl31_platform_setup(void)
269{
Varun Wadekar087cf682017-07-21 13:34:16 -0700270 /*
271 * Add timestamp for platform setup entry.
272 */
273 boot_profiler_add_record("[TF] plat setup entry");
274
Varun Wadekard3360302015-12-28 14:55:41 -0800275 /* Initialize the gic cpu and distributor interfaces */
276 plat_gic_setup();
277
Varun Wadekar08438e22015-05-19 16:48:04 +0530278 /*
279 * Setup secondary CPU POR infrastructure.
280 */
281 plat_secondary_setup();
282
283 /*
284 * Initial Memory Controller configuration.
285 */
286 tegra_memctrl_setup();
287
288 /*
Varun Wadekar06b19d52015-12-30 15:06:41 -0800289 * Set up the TZRAM memory aperture to allow only secure world
290 * access
291 */
292 tegra_memctrl_tzram_setup(TEGRA_TZRAM_BASE, TEGRA_TZRAM_SIZE);
293
Varun Wadekar087cf682017-07-21 13:34:16 -0700294 /*
Dilan Lee3e1923d2017-10-27 09:51:09 +0800295 * Late setup handler to allow platforms to performs additional
296 * functionality.
297 * This handler gets called with MMU enabled.
298 */
299 plat_late_platform_setup();
300
301 /*
Varun Wadekar087cf682017-07-21 13:34:16 -0700302 * Add timestamp for platform setup exit.
303 */
304 boot_profiler_add_record("[TF] plat setup exit");
305
Varun Wadekar08cefa92015-09-22 15:00:06 +0530306 INFO("BL3-1: Tegra platform setup complete\n");
Varun Wadekar08438e22015-05-19 16:48:04 +0530307}
308
309/*******************************************************************************
Varun Wadekar25caa162016-01-08 17:48:42 -0800310 * Perform any BL3-1 platform runtime setup prior to BL3-1 cold boot exit
311 ******************************************************************************/
312void bl31_plat_runtime_setup(void)
313{
Varun Wadekar0c2276e2017-03-29 14:57:29 -0700314 /*
Harvey Hsieh650d9c52017-08-21 15:01:53 +0800315 * During cold boot, it is observed that the arbitration
316 * bit is set in the Memory controller leading to false
317 * error interrupts in the non-secure world. To avoid
318 * this, clean the interrupt status register before
319 * booting into the non-secure world
320 */
321 tegra_memctrl_clear_pending_interrupts();
322
323 /*
Varun Wadekar0c2276e2017-03-29 14:57:29 -0700324 * During boot, USB3 and flash media (SDMMC/SATA) devices need
325 * access to IRAM. Because these clients connect to the MC and
326 * do not have a direct path to the IRAM, the MC implements AHB
327 * redirection during boot to allow path to IRAM. In this mode
328 * accesses to a programmed memory address aperture are directed
329 * to the AHB bus, allowing access to the IRAM. This mode must be
330 * disabled before we jump to the non-secure world.
331 */
332 tegra_memctrl_disable_ahb_redirection();
Varun Wadekar087cf682017-07-21 13:34:16 -0700333
334 /*
335 * Add final timestamp before exiting BL31.
336 */
337 boot_profiler_add_record("[TF] bl31 exit");
338 boot_profiler_deinit();
Varun Wadekar25caa162016-01-08 17:48:42 -0800339}
340
341/*******************************************************************************
Varun Wadekar08438e22015-05-19 16:48:04 +0530342 * Perform the very early platform specific architectural setup here. At the
343 * moment this only intializes the mmu in a quick and dirty way.
344 ******************************************************************************/
345void bl31_plat_arch_setup(void)
346{
Varun Wadekarfcf23a12019-01-02 10:48:18 -0800347 uint64_t rw_start = BL31_RW_START;
348 uint64_t rw_size = BL31_RW_END - BL31_RW_START;
349 uint64_t rodata_start = BL31_RODATA_BASE;
350 uint64_t rodata_size = BL31_RODATA_END - BL31_RODATA_BASE;
351 uint64_t code_base = TEXT_START;
352 uint64_t code_size = TEXT_END - TEXT_START;
Varun Wadekar08438e22015-05-19 16:48:04 +0530353 const mmap_region_t *plat_mmio_map = NULL;
Varun Wadekar08438e22015-05-19 16:48:04 +0530354#if USE_COHERENT_MEM
Varun Wadekarfcf23a12019-01-02 10:48:18 -0800355 uint32_t coh_start, coh_size;
Varun Wadekar08438e22015-05-19 16:48:04 +0530356#endif
Varun Wadekarfcf23a12019-01-02 10:48:18 -0800357 const plat_params_from_bl2_t *params_from_bl2 = bl31_get_plat_params();
Varun Wadekar08438e22015-05-19 16:48:04 +0530358
Varun Wadekar087cf682017-07-21 13:34:16 -0700359 /*
360 * Add timestamp for arch setup entry.
361 */
362 boot_profiler_add_record("[TF] arch setup entry");
363
Varun Wadekar26cf0842018-01-23 14:38:51 -0800364 /* add MMIO space */
365 plat_mmio_map = plat_get_mmio_map();
366 if (plat_mmio_map != NULL) {
367 mmap_add(plat_mmio_map);
368 } else {
369 WARN("MMIO map not available\n");
370 }
371
Varun Wadekar08438e22015-05-19 16:48:04 +0530372 /* add memory regions */
Varun Wadekarbc0a0be2017-02-28 08:23:59 -0800373 mmap_add_region(rw_start, rw_start,
374 rw_size,
Varun Wadekar08438e22015-05-19 16:48:04 +0530375 MT_MEMORY | MT_RW | MT_SECURE);
Varun Wadekarbc0a0be2017-02-28 08:23:59 -0800376 mmap_add_region(rodata_start, rodata_start,
377 rodata_size,
378 MT_RO_DATA | MT_SECURE);
379 mmap_add_region(code_base, code_base,
380 code_size,
381 MT_CODE | MT_SECURE);
Varun Wadekar68e2a642015-07-08 12:57:50 +0530382
Varun Wadekar08438e22015-05-19 16:48:04 +0530383#if USE_COHERENT_MEM
Masahiro Yamada47497052016-12-28 16:11:41 +0900384 coh_start = total_base + (BL_COHERENT_RAM_BASE - BL31_RO_BASE);
385 coh_size = BL_COHERENT_RAM_END - BL_COHERENT_RAM_BASE;
Varun Wadekar68e2a642015-07-08 12:57:50 +0530386
Varun Wadekar08438e22015-05-19 16:48:04 +0530387 mmap_add_region(coh_start, coh_start,
388 coh_size,
Varun Wadekarfcf23a12019-01-02 10:48:18 -0800389 (uint8_t)MT_DEVICE | (uint8_t)MT_RW | (uint8_t)MT_SECURE);
Varun Wadekar08438e22015-05-19 16:48:04 +0530390#endif
391
Varun Wadekar26cf0842018-01-23 14:38:51 -0800392 /* map TZDRAM used by BL31 as coherent memory */
393 if (TEGRA_TZRAM_BASE == tegra_bl31_phys_base) {
394 mmap_add_region(params_from_bl2->tzdram_base,
395 params_from_bl2->tzdram_base,
396 BL31_SIZE,
397 MT_DEVICE | MT_RW | MT_SECURE);
Varun Wadekarfcf23a12019-01-02 10:48:18 -0800398 }
Varun Wadekar08438e22015-05-19 16:48:04 +0530399
400 /* set up translation tables */
401 init_xlat_tables();
402
403 /* enable the MMU */
404 enable_mmu_el3(0);
Varun Wadekar08cefa92015-09-22 15:00:06 +0530405
Varun Wadekar087cf682017-07-21 13:34:16 -0700406 /*
407 * Add timestamp for arch setup exit.
408 */
409 boot_profiler_add_record("[TF] arch setup exit");
410
Varun Wadekar08cefa92015-09-22 15:00:06 +0530411 INFO("BL3-1: Tegra: MMU enabled\n");
Varun Wadekar08438e22015-05-19 16:48:04 +0530412}
Varun Wadekar9a964512015-06-10 14:04:32 +0530413
414/*******************************************************************************
415 * Check if the given NS DRAM range is valid
416 ******************************************************************************/
Varun Wadekarfcf23a12019-01-02 10:48:18 -0800417int32_t bl31_check_ns_address(uint64_t base, uint64_t size_in_bytes)
Varun Wadekar9a964512015-06-10 14:04:32 +0530418{
Varun Wadekar6460ed72017-07-20 09:43:28 -0700419 uint64_t end = base + size_in_bytes - U(1);
Varun Wadekarfcf23a12019-01-02 10:48:18 -0800420 int32_t ret = 0;
Varun Wadekar9a964512015-06-10 14:04:32 +0530421
422 /*
423 * Check if the NS DRAM address is valid
424 */
Varun Wadekar6460ed72017-07-20 09:43:28 -0700425 if ((base < TEGRA_DRAM_BASE) || (base >= TEGRA_DRAM_END) ||
426 (end > TEGRA_DRAM_END)) {
427
Andreas Färber055b7e92019-06-16 23:32:20 +0200428 ERROR("NS address 0x%llx is out-of-bounds!\n", base);
Varun Wadekarfcf23a12019-01-02 10:48:18 -0800429 ret = -EFAULT;
Varun Wadekar9a964512015-06-10 14:04:32 +0530430 }
431
432 /*
433 * TZDRAM aperture contains the BL31 and BL32 images, so we need
434 * to check if the NS DRAM range overlaps the TZDRAM aperture.
435 */
Varun Wadekar6460ed72017-07-20 09:43:28 -0700436 if ((base < (uint64_t)TZDRAM_END) && (end > tegra_bl31_phys_base)) {
Andreas Färber055b7e92019-06-16 23:32:20 +0200437 ERROR("NS address 0x%llx overlaps TZDRAM!\n", base);
Varun Wadekarfcf23a12019-01-02 10:48:18 -0800438 ret = -ENOTSUP;
Varun Wadekar9a964512015-06-10 14:04:32 +0530439 }
440
441 /* valid NS address */
Varun Wadekarfcf23a12019-01-02 10:48:18 -0800442 return ret;
Varun Wadekar9a964512015-06-10 14:04:32 +0530443}