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