Varun Wadekar | b316e24 | 2015-05-19 16:48:04 +0530 | [diff] [blame] | 1 | /* |
Joel Hutton | 5cc3bc8 | 2018-03-21 11:40:57 +0000 | [diff] [blame] | 2 | * Copyright (c) 2015-2018, ARM Limited and Contributors. All rights reserved. |
Varun Wadekar | b316e24 | 2015-05-19 16:48:04 +0530 | [diff] [blame] | 3 | * |
dp-arm | fa3cf0b | 2017-05-03 09:38:09 +0100 | [diff] [blame] | 4 | * SPDX-License-Identifier: BSD-3-Clause |
Varun Wadekar | b316e24 | 2015-05-19 16:48:04 +0530 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #include <arch.h> |
| 8 | #include <arch_helpers.h> |
| 9 | #include <assert.h> |
| 10 | #include <bl31.h> |
| 11 | #include <bl_common.h> |
| 12 | #include <console.h> |
Varun Wadekar | b316e24 | 2015-05-19 16:48:04 +0530 | [diff] [blame] | 13 | #include <cortex_a53.h> |
Isla Mitchell | e363146 | 2017-07-14 10:46:32 +0100 | [diff] [blame] | 14 | #include <cortex_a57.h> |
Varun Wadekar | b316e24 | 2015-05-19 16:48:04 +0530 | [diff] [blame] | 15 | #include <debug.h> |
Varun Wadekar | baf903e | 2015-09-22 15:00:06 +0530 | [diff] [blame] | 16 | #include <denver.h> |
Varun Wadekar | 7a269e2 | 2015-06-10 14:04:32 +0530 | [diff] [blame] | 17 | #include <errno.h> |
Varun Wadekar | b316e24 | 2015-05-19 16:48:04 +0530 | [diff] [blame] | 18 | #include <memctrl.h> |
| 19 | #include <mmio.h> |
| 20 | #include <platform.h> |
| 21 | #include <platform_def.h> |
| 22 | #include <stddef.h> |
Varun Wadekar | b41a414 | 2016-05-23 15:56:14 -0700 | [diff] [blame] | 23 | #include <string.h> |
Varun Wadekar | 0dc9181 | 2015-12-30 15:06:41 -0800 | [diff] [blame] | 24 | #include <tegra_def.h> |
Varun Wadekar | b316e24 | 2015-05-19 16:48:04 +0530 | [diff] [blame] | 25 | #include <tegra_private.h> |
Joel Hutton | 5cc3bc8 | 2018-03-21 11:40:57 +0000 | [diff] [blame] | 26 | #include <utils_def.h> |
Varun Wadekar | b316e24 | 2015-05-19 16:48:04 +0530 | [diff] [blame] | 27 | |
Arve Hjønnevåg | 8f53949 | 2018-02-21 17:36:44 -0800 | [diff] [blame] | 28 | /* length of Trusty's input parameters (in bytes) */ |
| 29 | #define TRUSTY_PARAMS_LEN_BYTES (4096*2) |
| 30 | |
Varun Wadekar | b41a414 | 2016-05-23 15:56:14 -0700 | [diff] [blame] | 31 | extern void zeromem16(void *mem, unsigned int length); |
| 32 | |
Varun Wadekar | b316e24 | 2015-05-19 16:48:04 +0530 | [diff] [blame] | 33 | /******************************************************************************* |
| 34 | * Declarations of linker defined symbols which will help us find the layout |
| 35 | * of trusted SRAM |
| 36 | ******************************************************************************/ |
Joel Hutton | 5cc3bc8 | 2018-03-21 11:40:57 +0000 | [diff] [blame] | 37 | |
| 38 | IMPORT_SYM(unsigned long, __RW_START__, BL31_RW_START); |
| 39 | IMPORT_SYM(unsigned long, __RW_END__, BL31_RW_END); |
| 40 | IMPORT_SYM(unsigned long, __RODATA_START__, BL31_RODATA_BASE); |
| 41 | IMPORT_SYM(unsigned long, __RODATA_END__, BL31_RODATA_END); |
| 42 | IMPORT_SYM(unsigned long, __TEXT_START__, TEXT_START); |
| 43 | IMPORT_SYM(unsigned long, __TEXT_END__, TEXT_END); |
Varun Wadekar | b316e24 | 2015-05-19 16:48:04 +0530 | [diff] [blame] | 44 | |
Varun Wadekar | b316e24 | 2015-05-19 16:48:04 +0530 | [diff] [blame] | 45 | extern uint64_t tegra_bl31_phys_base; |
Varun Wadekar | d2014c6 | 2015-10-29 10:37:28 +0530 | [diff] [blame] | 46 | extern uint64_t tegra_console_base; |
Varun Wadekar | b316e24 | 2015-05-19 16:48:04 +0530 | [diff] [blame] | 47 | |
Varun Wadekar | b316e24 | 2015-05-19 16:48:04 +0530 | [diff] [blame] | 48 | |
Varun Wadekar | 52a1598 | 2015-06-05 12:57:27 +0530 | [diff] [blame] | 49 | static entry_point_info_t bl33_image_ep_info, bl32_image_ep_info; |
Varun Wadekar | b316e24 | 2015-05-19 16:48:04 +0530 | [diff] [blame] | 50 | static plat_params_from_bl2_t plat_bl31_params_from_bl2 = { |
Varun Wadekar | c8bfe2e | 2015-07-31 10:03:01 +0530 | [diff] [blame] | 51 | .tzdram_size = (uint64_t)TZDRAM_SIZE |
Varun Wadekar | b316e24 | 2015-05-19 16:48:04 +0530 | [diff] [blame] | 52 | }; |
Arve Hjønnevåg | 8f53949 | 2018-02-21 17:36:44 -0800 | [diff] [blame] | 53 | static unsigned long bl32_mem_size; |
| 54 | static unsigned long bl32_boot_params; |
Varun Wadekar | b316e24 | 2015-05-19 16:48:04 +0530 | [diff] [blame] | 55 | |
| 56 | /******************************************************************************* |
| 57 | * This variable holds the non-secure image entry address |
| 58 | ******************************************************************************/ |
| 59 | extern uint64_t ns_image_entrypoint; |
| 60 | |
| 61 | /******************************************************************************* |
Varun Wadekar | 3f0a8ad | 2016-03-28 15:56:47 -0700 | [diff] [blame] | 62 | * The following platform setup functions are weakly defined. They |
| 63 | * provide typical implementations that will be overridden by a SoC. |
| 64 | ******************************************************************************/ |
| 65 | #pragma weak plat_early_platform_setup |
Varun Wadekar | d22d4ad | 2016-05-23 11:41:07 -0700 | [diff] [blame] | 66 | #pragma weak plat_get_bl31_params |
| 67 | #pragma weak plat_get_bl31_plat_params |
Varun Wadekar | 3f0a8ad | 2016-03-28 15:56:47 -0700 | [diff] [blame] | 68 | |
| 69 | void plat_early_platform_setup(void) |
| 70 | { |
| 71 | ; /* do nothing */ |
| 72 | } |
| 73 | |
Varun Wadekar | d22d4ad | 2016-05-23 11:41:07 -0700 | [diff] [blame] | 74 | bl31_params_t *plat_get_bl31_params(void) |
| 75 | { |
| 76 | return NULL; |
| 77 | } |
| 78 | |
| 79 | plat_params_from_bl2_t *plat_get_bl31_plat_params(void) |
| 80 | { |
| 81 | return NULL; |
| 82 | } |
| 83 | |
Varun Wadekar | 3f0a8ad | 2016-03-28 15:56:47 -0700 | [diff] [blame] | 84 | /******************************************************************************* |
Varun Wadekar | b316e24 | 2015-05-19 16:48:04 +0530 | [diff] [blame] | 85 | * Return a pointer to the 'entry_point_info' structure of the next image for |
| 86 | * security state specified. BL33 corresponds to the non-secure image type |
| 87 | * while BL32 corresponds to the secure image type. |
| 88 | ******************************************************************************/ |
| 89 | entry_point_info_t *bl31_plat_get_next_image_ep_info(uint32_t type) |
| 90 | { |
| 91 | if (type == NON_SECURE) |
| 92 | return &bl33_image_ep_info; |
| 93 | |
Varun Wadekar | 197a75f | 2016-06-06 10:46:28 -0700 | [diff] [blame] | 94 | /* return BL32 entry point info if it is valid */ |
| 95 | if (type == SECURE && bl32_image_ep_info.pc) |
Varun Wadekar | 52a1598 | 2015-06-05 12:57:27 +0530 | [diff] [blame] | 96 | return &bl32_image_ep_info; |
| 97 | |
Varun Wadekar | b316e24 | 2015-05-19 16:48:04 +0530 | [diff] [blame] | 98 | return NULL; |
| 99 | } |
| 100 | |
| 101 | /******************************************************************************* |
| 102 | * Return a pointer to the 'plat_params_from_bl2_t' structure. The BL2 image |
| 103 | * passes this platform specific information. |
| 104 | ******************************************************************************/ |
| 105 | plat_params_from_bl2_t *bl31_get_plat_params(void) |
| 106 | { |
| 107 | return &plat_bl31_params_from_bl2; |
| 108 | } |
| 109 | |
| 110 | /******************************************************************************* |
| 111 | * Perform any BL31 specific platform actions. Populate the BL33 and BL32 image |
| 112 | * info. |
| 113 | ******************************************************************************/ |
| 114 | void bl31_early_platform_setup(bl31_params_t *from_bl2, |
| 115 | void *plat_params_from_bl2) |
| 116 | { |
| 117 | plat_params_from_bl2_t *plat_params = |
| 118 | (plat_params_from_bl2_t *)plat_params_from_bl2; |
Soren Brinkmann | f9ce0f0 | 2017-06-07 09:51:26 -0700 | [diff] [blame] | 119 | #if LOG_LEVEL >= LOG_LEVEL_INFO |
Varun Wadekar | baf903e | 2015-09-22 15:00:06 +0530 | [diff] [blame] | 120 | int impl = (read_midr() >> MIDR_IMPL_SHIFT) & MIDR_IMPL_MASK; |
| 121 | #endif |
Varun Wadekar | b41a414 | 2016-05-23 15:56:14 -0700 | [diff] [blame] | 122 | image_info_t bl32_img_info = { {0} }; |
| 123 | uint64_t tzdram_start, tzdram_end, bl32_start, bl32_end; |
Varun Wadekar | baf903e | 2015-09-22 15:00:06 +0530 | [diff] [blame] | 124 | |
Varun Wadekar | b316e24 | 2015-05-19 16:48:04 +0530 | [diff] [blame] | 125 | /* |
Varun Wadekar | d22d4ad | 2016-05-23 11:41:07 -0700 | [diff] [blame] | 126 | * For RESET_TO_BL31 systems, BL31 is the first bootloader to run so |
| 127 | * there's no argument to relay from a previous bootloader. Platforms |
| 128 | * might use custom ways to get arguments, so provide handlers which |
| 129 | * they can override. |
| 130 | */ |
| 131 | if (from_bl2 == NULL) |
| 132 | from_bl2 = plat_get_bl31_params(); |
| 133 | if (plat_params == NULL) |
| 134 | plat_params = plat_get_bl31_plat_params(); |
| 135 | |
| 136 | /* |
Varun Wadekar | 52a1598 | 2015-06-05 12:57:27 +0530 | [diff] [blame] | 137 | * Copy BL3-3, BL3-2 entry point information. |
Varun Wadekar | b316e24 | 2015-05-19 16:48:04 +0530 | [diff] [blame] | 138 | * They are stored in Secure RAM, in BL2's address space. |
| 139 | */ |
Varun Wadekar | d22d4ad | 2016-05-23 11:41:07 -0700 | [diff] [blame] | 140 | assert(from_bl2); |
Varun Wadekar | 6bb6246 | 2015-10-06 12:49:31 +0530 | [diff] [blame] | 141 | assert(from_bl2->bl33_ep_info); |
| 142 | bl33_image_ep_info = *from_bl2->bl33_ep_info; |
Varun Wadekar | baf903e | 2015-09-22 15:00:06 +0530 | [diff] [blame] | 143 | |
Arve Hjønnevåg | 8f53949 | 2018-02-21 17:36:44 -0800 | [diff] [blame] | 144 | if (from_bl2->bl32_ep_info) { |
Varun Wadekar | baf903e | 2015-09-22 15:00:06 +0530 | [diff] [blame] | 145 | bl32_image_ep_info = *from_bl2->bl32_ep_info; |
Arve Hjønnevåg | 8f53949 | 2018-02-21 17:36:44 -0800 | [diff] [blame] | 146 | bl32_mem_size = from_bl2->bl32_ep_info->args.arg0; |
| 147 | bl32_boot_params = from_bl2->bl32_ep_info->args.arg2; |
| 148 | } |
Varun Wadekar | b316e24 | 2015-05-19 16:48:04 +0530 | [diff] [blame] | 149 | |
| 150 | /* |
Varun Wadekar | 6bb6246 | 2015-10-06 12:49:31 +0530 | [diff] [blame] | 151 | * Parse platform specific parameters - TZDRAM aperture base and size |
Varun Wadekar | b316e24 | 2015-05-19 16:48:04 +0530 | [diff] [blame] | 152 | */ |
Varun Wadekar | 6bb6246 | 2015-10-06 12:49:31 +0530 | [diff] [blame] | 153 | assert(plat_params); |
| 154 | plat_bl31_params_from_bl2.tzdram_base = plat_params->tzdram_base; |
| 155 | plat_bl31_params_from_bl2.tzdram_size = plat_params->tzdram_size; |
Varun Wadekar | d2014c6 | 2015-10-29 10:37:28 +0530 | [diff] [blame] | 156 | plat_bl31_params_from_bl2.uart_id = plat_params->uart_id; |
| 157 | |
| 158 | /* |
Varun Wadekar | 1ec441e | 2016-03-24 15:34:24 -0700 | [diff] [blame] | 159 | * It is very important that we run either from TZDRAM or TZSRAM base. |
| 160 | * Add an explicit check here. |
| 161 | */ |
| 162 | if ((plat_bl31_params_from_bl2.tzdram_base != BL31_BASE) && |
| 163 | (TEGRA_TZRAM_BASE != BL31_BASE)) |
| 164 | panic(); |
| 165 | |
| 166 | /* |
Varun Wadekar | d2014c6 | 2015-10-29 10:37:28 +0530 | [diff] [blame] | 167 | * Get the base address of the UART controller to be used for the |
| 168 | * console |
| 169 | */ |
Varun Wadekar | d2014c6 | 2015-10-29 10:37:28 +0530 | [diff] [blame] | 170 | tegra_console_base = plat_get_console_from_id(plat_params->uart_id); |
| 171 | |
Damon Duan | 777baa5 | 2016-11-07 19:37:50 +0800 | [diff] [blame] | 172 | if (tegra_console_base != (uint64_t)0) { |
| 173 | /* |
| 174 | * Configure the UART port to be used as the console |
| 175 | */ |
| 176 | console_init(tegra_console_base, TEGRA_BOOT_UART_CLK_IN_HZ, |
| 177 | TEGRA_CONSOLE_BAUDRATE); |
Damon Duan | 777baa5 | 2016-11-07 19:37:50 +0800 | [diff] [blame] | 178 | } |
Varun Wadekar | d2014c6 | 2015-10-29 10:37:28 +0530 | [diff] [blame] | 179 | |
Varun Wadekar | 5118b53 | 2016-06-04 22:08:50 -0700 | [diff] [blame] | 180 | /* |
Steven Kao | 27e6431 | 2016-10-21 14:16:59 +0800 | [diff] [blame] | 181 | * Initialize delay timer |
| 182 | */ |
| 183 | tegra_delay_timer_init(); |
| 184 | |
| 185 | /* |
Varun Wadekar | 5118b53 | 2016-06-04 22:08:50 -0700 | [diff] [blame] | 186 | * Do initial security configuration to allow DRAM/device access. |
| 187 | */ |
| 188 | tegra_memctrl_tzdram_setup(plat_bl31_params_from_bl2.tzdram_base, |
| 189 | plat_bl31_params_from_bl2.tzdram_size); |
| 190 | |
Varun Wadekar | b41a414 | 2016-05-23 15:56:14 -0700 | [diff] [blame] | 191 | /* |
| 192 | * The previous bootloader might not have placed the BL32 image |
| 193 | * inside the TZDRAM. We check the BL32 image info to find out |
| 194 | * the base/PC values and relocate the image if necessary. |
| 195 | */ |
| 196 | if (from_bl2->bl32_image_info) { |
| 197 | |
| 198 | bl32_img_info = *from_bl2->bl32_image_info; |
| 199 | |
| 200 | /* Relocate BL32 if it resides outside of the TZDRAM */ |
| 201 | tzdram_start = plat_bl31_params_from_bl2.tzdram_base; |
| 202 | tzdram_end = plat_bl31_params_from_bl2.tzdram_base + |
| 203 | plat_bl31_params_from_bl2.tzdram_size; |
| 204 | bl32_start = bl32_img_info.image_base; |
| 205 | bl32_end = bl32_img_info.image_base + bl32_img_info.image_size; |
| 206 | |
| 207 | assert(tzdram_end > tzdram_start); |
| 208 | assert(bl32_end > bl32_start); |
| 209 | assert(bl32_image_ep_info.pc > tzdram_start); |
| 210 | assert(bl32_image_ep_info.pc < tzdram_end); |
| 211 | |
| 212 | /* relocate BL32 */ |
| 213 | if (bl32_start >= tzdram_end || bl32_end <= tzdram_start) { |
| 214 | |
| 215 | INFO("Relocate BL32 to TZDRAM\n"); |
| 216 | |
| 217 | memcpy16((void *)(uintptr_t)bl32_image_ep_info.pc, |
| 218 | (void *)(uintptr_t)bl32_start, |
| 219 | bl32_img_info.image_size); |
| 220 | |
| 221 | /* clean up non-secure intermediate buffer */ |
| 222 | zeromem16((void *)(uintptr_t)bl32_start, |
| 223 | bl32_img_info.image_size); |
| 224 | } |
| 225 | } |
| 226 | |
Varun Wadekar | 3f0a8ad | 2016-03-28 15:56:47 -0700 | [diff] [blame] | 227 | /* Early platform setup for Tegra SoCs */ |
| 228 | plat_early_platform_setup(); |
| 229 | |
Varun Wadekar | d2014c6 | 2015-10-29 10:37:28 +0530 | [diff] [blame] | 230 | INFO("BL3-1: Boot CPU: %s Processor [%lx]\n", (impl == DENVER_IMPL) ? |
| 231 | "Denver" : "ARM", read_mpidr()); |
Varun Wadekar | b316e24 | 2015-05-19 16:48:04 +0530 | [diff] [blame] | 232 | } |
Arve Hjønnevåg | 8f53949 | 2018-02-21 17:36:44 -0800 | [diff] [blame] | 233 | |
| 234 | #ifdef SPD_trusty |
| 235 | void plat_trusty_set_boot_args(aapcs64_params_t *args) |
| 236 | { |
| 237 | args->arg0 = bl32_mem_size; |
| 238 | args->arg1 = bl32_boot_params; |
| 239 | args->arg2 = TRUSTY_PARAMS_LEN_BYTES; |
| 240 | } |
| 241 | #endif |
Varun Wadekar | b316e24 | 2015-05-19 16:48:04 +0530 | [diff] [blame] | 242 | |
| 243 | /******************************************************************************* |
| 244 | * Initialize the gic, configure the SCR. |
| 245 | ******************************************************************************/ |
| 246 | void bl31_platform_setup(void) |
| 247 | { |
| 248 | uint32_t tmp_reg; |
| 249 | |
Varun Wadekar | b7b4575 | 2015-12-28 14:55:41 -0800 | [diff] [blame] | 250 | /* Initialize the gic cpu and distributor interfaces */ |
| 251 | plat_gic_setup(); |
| 252 | |
Varun Wadekar | b316e24 | 2015-05-19 16:48:04 +0530 | [diff] [blame] | 253 | /* |
| 254 | * Setup secondary CPU POR infrastructure. |
| 255 | */ |
| 256 | plat_secondary_setup(); |
| 257 | |
| 258 | /* |
| 259 | * Initial Memory Controller configuration. |
| 260 | */ |
| 261 | tegra_memctrl_setup(); |
| 262 | |
| 263 | /* |
Varun Wadekar | 0dc9181 | 2015-12-30 15:06:41 -0800 | [diff] [blame] | 264 | * Set up the TZRAM memory aperture to allow only secure world |
| 265 | * access |
| 266 | */ |
| 267 | tegra_memctrl_tzram_setup(TEGRA_TZRAM_BASE, TEGRA_TZRAM_SIZE); |
| 268 | |
Varun Wadekar | b316e24 | 2015-05-19 16:48:04 +0530 | [diff] [blame] | 269 | /* Set the next EL to be AArch64 */ |
| 270 | tmp_reg = SCR_RES1_BITS | SCR_RW_BIT; |
| 271 | write_scr(tmp_reg); |
| 272 | |
Varun Wadekar | baf903e | 2015-09-22 15:00:06 +0530 | [diff] [blame] | 273 | INFO("BL3-1: Tegra platform setup complete\n"); |
Varun Wadekar | b316e24 | 2015-05-19 16:48:04 +0530 | [diff] [blame] | 274 | } |
| 275 | |
| 276 | /******************************************************************************* |
Varun Wadekar | 1dcffa9 | 2016-01-08 17:48:42 -0800 | [diff] [blame] | 277 | * Perform any BL3-1 platform runtime setup prior to BL3-1 cold boot exit |
| 278 | ******************************************************************************/ |
| 279 | void bl31_plat_runtime_setup(void) |
| 280 | { |
Varun Wadekar | c92050b | 2017-03-29 14:57:29 -0700 | [diff] [blame] | 281 | /* |
| 282 | * During boot, USB3 and flash media (SDMMC/SATA) devices need |
| 283 | * access to IRAM. Because these clients connect to the MC and |
| 284 | * do not have a direct path to the IRAM, the MC implements AHB |
| 285 | * redirection during boot to allow path to IRAM. In this mode |
| 286 | * accesses to a programmed memory address aperture are directed |
| 287 | * to the AHB bus, allowing access to the IRAM. This mode must be |
| 288 | * disabled before we jump to the non-secure world. |
| 289 | */ |
| 290 | tegra_memctrl_disable_ahb_redirection(); |
Varun Wadekar | 1dcffa9 | 2016-01-08 17:48:42 -0800 | [diff] [blame] | 291 | } |
| 292 | |
| 293 | /******************************************************************************* |
Varun Wadekar | b316e24 | 2015-05-19 16:48:04 +0530 | [diff] [blame] | 294 | * Perform the very early platform specific architectural setup here. At the |
| 295 | * moment this only intializes the mmu in a quick and dirty way. |
| 296 | ******************************************************************************/ |
| 297 | void bl31_plat_arch_setup(void) |
| 298 | { |
Varun Wadekar | 3fb854f | 2017-02-28 08:23:59 -0800 | [diff] [blame] | 299 | unsigned long rw_start = BL31_RW_START; |
| 300 | unsigned long rw_size = BL31_RW_END - BL31_RW_START; |
| 301 | unsigned long rodata_start = BL31_RODATA_BASE; |
| 302 | unsigned long rodata_size = BL31_RODATA_END - BL31_RODATA_BASE; |
Joel Hutton | 5cc3bc8 | 2018-03-21 11:40:57 +0000 | [diff] [blame] | 303 | unsigned long code_base = TEXT_START; |
| 304 | unsigned long code_size = TEXT_END - TEXT_START; |
Varun Wadekar | b316e24 | 2015-05-19 16:48:04 +0530 | [diff] [blame] | 305 | const mmap_region_t *plat_mmio_map = NULL; |
Varun Wadekar | b316e24 | 2015-05-19 16:48:04 +0530 | [diff] [blame] | 306 | #if USE_COHERENT_MEM |
Varun Wadekar | 207cc73 | 2015-07-08 12:57:50 +0530 | [diff] [blame] | 307 | unsigned long coh_start, coh_size; |
Varun Wadekar | b316e24 | 2015-05-19 16:48:04 +0530 | [diff] [blame] | 308 | #endif |
Varun Wadekar | d151363 | 2016-03-18 13:01:12 -0700 | [diff] [blame] | 309 | plat_params_from_bl2_t *params_from_bl2 = bl31_get_plat_params(); |
Varun Wadekar | b316e24 | 2015-05-19 16:48:04 +0530 | [diff] [blame] | 310 | |
| 311 | /* add memory regions */ |
Varun Wadekar | 3fb854f | 2017-02-28 08:23:59 -0800 | [diff] [blame] | 312 | mmap_add_region(rw_start, rw_start, |
| 313 | rw_size, |
Varun Wadekar | b316e24 | 2015-05-19 16:48:04 +0530 | [diff] [blame] | 314 | MT_MEMORY | MT_RW | MT_SECURE); |
Varun Wadekar | 3fb854f | 2017-02-28 08:23:59 -0800 | [diff] [blame] | 315 | mmap_add_region(rodata_start, rodata_start, |
| 316 | rodata_size, |
| 317 | MT_RO_DATA | MT_SECURE); |
| 318 | mmap_add_region(code_base, code_base, |
| 319 | code_size, |
| 320 | MT_CODE | MT_SECURE); |
Varun Wadekar | 207cc73 | 2015-07-08 12:57:50 +0530 | [diff] [blame] | 321 | |
Varun Wadekar | d151363 | 2016-03-18 13:01:12 -0700 | [diff] [blame] | 322 | /* map TZDRAM used by BL31 as coherent memory */ |
| 323 | if (TEGRA_TZRAM_BASE == tegra_bl31_phys_base) { |
| 324 | mmap_add_region(params_from_bl2->tzdram_base, |
| 325 | params_from_bl2->tzdram_base, |
| 326 | BL31_SIZE, |
| 327 | MT_DEVICE | MT_RW | MT_SECURE); |
| 328 | } |
| 329 | |
Varun Wadekar | b316e24 | 2015-05-19 16:48:04 +0530 | [diff] [blame] | 330 | #if USE_COHERENT_MEM |
Masahiro Yamada | 0fac5af | 2016-12-28 16:11:41 +0900 | [diff] [blame] | 331 | coh_start = total_base + (BL_COHERENT_RAM_BASE - BL31_RO_BASE); |
| 332 | coh_size = BL_COHERENT_RAM_END - BL_COHERENT_RAM_BASE; |
Varun Wadekar | 207cc73 | 2015-07-08 12:57:50 +0530 | [diff] [blame] | 333 | |
Varun Wadekar | b316e24 | 2015-05-19 16:48:04 +0530 | [diff] [blame] | 334 | mmap_add_region(coh_start, coh_start, |
| 335 | coh_size, |
| 336 | MT_DEVICE | MT_RW | MT_SECURE); |
| 337 | #endif |
| 338 | |
Steven Kao | 4d160ac | 2016-12-23 16:05:13 +0800 | [diff] [blame] | 339 | /* map on-chip free running uS timer */ |
| 340 | mmap_add_region(page_align((uint64_t)TEGRA_TMRUS_BASE, 0), |
| 341 | page_align((uint64_t)TEGRA_TMRUS_BASE, 0), |
| 342 | (uint64_t)TEGRA_TMRUS_SIZE, |
| 343 | MT_DEVICE | MT_RO | MT_SECURE); |
| 344 | |
Varun Wadekar | b316e24 | 2015-05-19 16:48:04 +0530 | [diff] [blame] | 345 | /* add MMIO space */ |
| 346 | plat_mmio_map = plat_get_mmio_map(); |
| 347 | if (plat_mmio_map) |
| 348 | mmap_add(plat_mmio_map); |
| 349 | else |
| 350 | WARN("MMIO map not available\n"); |
| 351 | |
| 352 | /* set up translation tables */ |
| 353 | init_xlat_tables(); |
| 354 | |
| 355 | /* enable the MMU */ |
| 356 | enable_mmu_el3(0); |
Varun Wadekar | baf903e | 2015-09-22 15:00:06 +0530 | [diff] [blame] | 357 | |
| 358 | INFO("BL3-1: Tegra: MMU enabled\n"); |
Varun Wadekar | b316e24 | 2015-05-19 16:48:04 +0530 | [diff] [blame] | 359 | } |
Varun Wadekar | 7a269e2 | 2015-06-10 14:04:32 +0530 | [diff] [blame] | 360 | |
| 361 | /******************************************************************************* |
| 362 | * Check if the given NS DRAM range is valid |
| 363 | ******************************************************************************/ |
| 364 | int bl31_check_ns_address(uint64_t base, uint64_t size_in_bytes) |
| 365 | { |
Varun Wadekar | 5590298 | 2017-01-25 13:35:27 -0800 | [diff] [blame] | 366 | uint64_t end = base + size_in_bytes; |
Varun Wadekar | 7a269e2 | 2015-06-10 14:04:32 +0530 | [diff] [blame] | 367 | |
| 368 | /* |
| 369 | * Check if the NS DRAM address is valid |
| 370 | */ |
Varun Wadekar | 5590298 | 2017-01-25 13:35:27 -0800 | [diff] [blame] | 371 | if ((base < TEGRA_DRAM_BASE) || (end > TEGRA_DRAM_END)) { |
Varun Wadekar | 7a269e2 | 2015-06-10 14:04:32 +0530 | [diff] [blame] | 372 | ERROR("NS address is out-of-bounds!\n"); |
| 373 | return -EFAULT; |
| 374 | } |
| 375 | |
| 376 | /* |
| 377 | * TZDRAM aperture contains the BL31 and BL32 images, so we need |
| 378 | * to check if the NS DRAM range overlaps the TZDRAM aperture. |
| 379 | */ |
| 380 | if ((base < TZDRAM_END) && (end > tegra_bl31_phys_base)) { |
| 381 | ERROR("NS address overlaps TZDRAM!\n"); |
| 382 | return -ENOTSUP; |
| 383 | } |
| 384 | |
| 385 | /* valid NS address */ |
| 386 | return 0; |
| 387 | } |