blob: 5f01416d812ccb0370bf4b1fe606018dfb21e02d [file] [log] [blame]
Varun Wadekarb316e242015-05-19 16:48:04 +05301/*
Ambroise Vincent09a22e72019-05-29 14:04:16 +01002 * Copyright (c) 2015-2019, ARM Limited and Contributors. All rights reserved.
Varun Wadekarc9bd0aa2018-06-07 11:21:02 -07003 * Copyright (c) 2020, NVIDIA Corporation. All rights reserved.
Varun Wadekarb316e242015-05-19 16:48:04 +05304 *
dp-armfa3cf0b2017-05-03 09:38:09 +01005 * SPDX-License-Identifier: BSD-3-Clause
Varun Wadekarb316e242015-05-19 16:48:04 +05306 */
7#include <arch.h>
8#include <asm_macros.S>
9#include <assert_macros.S>
10#include <cpu_macros.S>
Varun Wadekarb316e242015-05-19 16:48:04 +053011#include <cortex_a53.h>
Isla Mitchelle3631462017-07-14 10:46:32 +010012#include <cortex_a57.h>
Varun Wadekar25e658e2016-04-26 11:38:38 -070013#include <platform_def.h>
Varun Wadekarb316e242015-05-19 16:48:04 +053014#include <tegra_def.h>
Harvey Hsieh6dc0d762017-04-24 19:35:51 +080015#include <tegra_platform.h>
Varun Wadekarb316e242015-05-19 16:48:04 +053016
Varun Wadekarb24dea92015-09-22 13:33:56 +053017#define MIDR_PN_CORTEX_A57 0xD07
18
19/*******************************************************************************
20 * Implementation defined ACTLR_EL3 bit definitions
21 ******************************************************************************/
Varun Wadekarc9bd0aa2018-06-07 11:21:02 -070022#define ACTLR_ELx_L2ACTLR_BIT (U(1) << 6)
23#define ACTLR_ELx_L2ECTLR_BIT (U(1) << 5)
24#define ACTLR_ELx_L2CTLR_BIT (U(1) << 4)
25#define ACTLR_ELx_CPUECTLR_BIT (U(1) << 1)
26#define ACTLR_ELx_CPUACTLR_BIT (U(1) << 0)
27#define ACTLR_ELx_ENABLE_ALL_ACCESS (ACTLR_ELx_L2ACTLR_BIT | \
28 ACTLR_ELx_L2ECTLR_BIT | \
29 ACTLR_ELx_L2CTLR_BIT | \
30 ACTLR_ELx_CPUECTLR_BIT | \
31 ACTLR_ELx_CPUACTLR_BIT)
Varun Wadekarb24dea92015-09-22 13:33:56 +053032
Varun Wadekarb316e242015-05-19 16:48:04 +053033 /* Global functions */
Varun Wadekara78bb1b2015-08-07 10:03:00 +053034 .globl plat_is_my_cpu_primary
35 .globl plat_my_core_pos
36 .globl plat_get_my_entrypoint
Varun Wadekarb316e242015-05-19 16:48:04 +053037 .globl plat_secondary_cold_boot_setup
38 .globl platform_mem_init
39 .globl plat_crash_console_init
40 .globl plat_crash_console_putc
Antonio Nino Diaz1eb64a12018-10-17 15:29:34 +010041 .globl plat_crash_console_flush
Varun Wadekarad2d5f32018-11-27 15:47:26 -080042 .weak plat_core_pos_by_mpidr
Varun Wadekarb316e242015-05-19 16:48:04 +053043 .globl tegra_secure_entrypoint
44 .globl plat_reset_handler
45
46 /* Global variables */
Varun Wadekara78bb1b2015-08-07 10:03:00 +053047 .globl tegra_sec_entry_point
Varun Wadekarb316e242015-05-19 16:48:04 +053048 .globl ns_image_entrypoint
49 .globl tegra_bl31_phys_base
Varun Wadekard2014c62015-10-29 10:37:28 +053050 .globl tegra_console_base
Varun Wadekarb316e242015-05-19 16:48:04 +053051
52 /* ---------------------
53 * Common CPU init code
54 * ---------------------
55 */
56.macro cpu_init_common
57
Varun Wadekarb24dea92015-09-22 13:33:56 +053058 /* ------------------------------------------------
Varun Wadekar69ce1012016-05-12 13:43:33 -070059 * We enable procesor retention, L2/CPUECTLR NS
60 * access and ECC/Parity protection for A57 CPUs
Varun Wadekarb24dea92015-09-22 13:33:56 +053061 * ------------------------------------------------
62 */
63 mrs x0, midr_el1
64 mov x1, #(MIDR_PN_MASK << MIDR_PN_SHIFT)
65 and x0, x0, x1
66 lsr x0, x0, #MIDR_PN_SHIFT
67 cmp x0, #MIDR_PN_CORTEX_A57
68 b.ne 1f
69
Varun Wadekar4e9c2312015-08-21 15:56:02 +053070 /* ---------------------------
71 * Enable processor retention
72 * ---------------------------
Varun Wadekar69ce1012016-05-12 13:43:33 -070073 */
Varun Wadekar1384a162017-06-05 14:54:46 -070074 mrs x0, CORTEX_A57_L2ECTLR_EL1
75 mov x1, #RETENTION_ENTRY_TICKS_512
76 bic x0, x0, #CORTEX_A57_L2ECTLR_RET_CTRL_MASK
Varun Wadekar4e9c2312015-08-21 15:56:02 +053077 orr x0, x0, x1
Varun Wadekar1384a162017-06-05 14:54:46 -070078 msr CORTEX_A57_L2ECTLR_EL1, x0
Varun Wadekar4e9c2312015-08-21 15:56:02 +053079 isb
Varun Wadekar4e9c2312015-08-21 15:56:02 +053080
Varun Wadekar1384a162017-06-05 14:54:46 -070081 mrs x0, CORTEX_A57_ECTLR_EL1
82 mov x1, #RETENTION_ENTRY_TICKS_512
83 bic x0, x0, #CORTEX_A57_ECTLR_CPU_RET_CTRL_MASK
Varun Wadekar4e9c2312015-08-21 15:56:02 +053084 orr x0, x0, x1
Varun Wadekar1384a162017-06-05 14:54:46 -070085 msr CORTEX_A57_ECTLR_EL1, x0
Varun Wadekar4e9c2312015-08-21 15:56:02 +053086 isb
Varun Wadekar4e9c2312015-08-21 15:56:02 +053087
Varun Wadekarb316e242015-05-19 16:48:04 +053088 /* -------------------------------------------------------
89 * Enable L2 and CPU ECTLR RW access from non-secure world
90 * -------------------------------------------------------
Varun Wadekar69ce1012016-05-12 13:43:33 -070091 */
Steven Kaod417cea2017-06-14 14:02:23 +080092 mrs x0, actlr_el3
Varun Wadekarc9bd0aa2018-06-07 11:21:02 -070093 mov x1, #ACTLR_ELx_ENABLE_ALL_ACCESS
Steven Kaod417cea2017-06-14 14:02:23 +080094 orr x0, x0, x1
Varun Wadekarb316e242015-05-19 16:48:04 +053095 msr actlr_el3, x0
Steven Kaod417cea2017-06-14 14:02:23 +080096 mrs x0, actlr_el2
Varun Wadekarc9bd0aa2018-06-07 11:21:02 -070097 mov x1, #ACTLR_ELx_ENABLE_ALL_ACCESS
Steven Kaod417cea2017-06-14 14:02:23 +080098 orr x0, x0, x1
Varun Wadekarb316e242015-05-19 16:48:04 +053099 msr actlr_el2, x0
100 isb
Varun Wadekarb316e242015-05-19 16:48:04 +0530101
102 /* --------------------------------
103 * Enable the cycle count register
104 * --------------------------------
105 */
Varun Wadekarb24dea92015-09-22 13:33:56 +05301061: mrs x0, pmcr_el0
Varun Wadekarb316e242015-05-19 16:48:04 +0530107 ubfx x0, x0, #11, #5 // read PMCR.N field
108 mov x1, #1
109 lsl x0, x1, x0
110 sub x0, x0, #1 // mask of event counters
111 orr x0, x0, #0x80000000 // disable overflow intrs
112 msr pmintenclr_el1, x0
113 msr pmuserenr_el0, x1 // enable user mode access
114
115 /* ----------------------------------------------------------------
116 * Allow non-privileged access to CNTVCT: Set CNTKCTL (Kernel Count
117 * register), bit 1 (EL0VCTEN) to enable access to CNTVCT/CNTFRQ
118 * registers from EL0.
119 * ----------------------------------------------------------------
120 */
121 mrs x0, cntkctl_el1
122 orr x0, x0, #EL0VCTEN_BIT
123 msr cntkctl_el1, x0
124.endm
125
126 /* -----------------------------------------------------
Varun Wadekara78bb1b2015-08-07 10:03:00 +0530127 * unsigned int plat_is_my_cpu_primary(void);
Varun Wadekarb316e242015-05-19 16:48:04 +0530128 *
129 * This function checks if this is the Primary CPU
130 * -----------------------------------------------------
131 */
Varun Wadekara78bb1b2015-08-07 10:03:00 +0530132func plat_is_my_cpu_primary
133 mrs x0, mpidr_el1
Varun Wadekarb316e242015-05-19 16:48:04 +0530134 and x0, x0, #(MPIDR_CLUSTER_MASK | MPIDR_CPU_MASK)
135 cmp x0, #TEGRA_PRIMARY_CPU
136 cset x0, eq
137 ret
Varun Wadekara78bb1b2015-08-07 10:03:00 +0530138endfunc plat_is_my_cpu_primary
Varun Wadekarb316e242015-05-19 16:48:04 +0530139
Varun Wadekarfa99b222017-08-23 16:02:06 -0700140 /* ----------------------------------------------------------
Varun Wadekara78bb1b2015-08-07 10:03:00 +0530141 * unsigned int plat_my_core_pos(void);
142 *
Varun Wadekarfa99b222017-08-23 16:02:06 -0700143 * result: CorePos = CoreId + (ClusterId * cpus per cluster)
Kalyani Chidambaram7f8d8482018-10-03 17:00:17 -0700144 * Registers clobbered: x0, x8
Varun Wadekarfa99b222017-08-23 16:02:06 -0700145 * ----------------------------------------------------------
Varun Wadekara78bb1b2015-08-07 10:03:00 +0530146 */
147func plat_my_core_pos
Kalyani Chidambaram7f8d8482018-10-03 17:00:17 -0700148 mov x8, x30
Varun Wadekara78bb1b2015-08-07 10:03:00 +0530149 mrs x0, mpidr_el1
Kalyani Chidambaram7f8d8482018-10-03 17:00:17 -0700150 bl plat_core_pos_by_mpidr
151 ret x8
Varun Wadekara78bb1b2015-08-07 10:03:00 +0530152endfunc plat_my_core_pos
153
154 /* -----------------------------------------------------
155 * unsigned long plat_get_my_entrypoint (void);
156 *
157 * Main job of this routine is to distinguish between
158 * a cold and warm boot. If the tegra_sec_entry_point for
159 * this CPU is present, then it's a warm boot.
Varun Wadekarb316e242015-05-19 16:48:04 +0530160 *
Varun Wadekarb316e242015-05-19 16:48:04 +0530161 * -----------------------------------------------------
162 */
Varun Wadekara78bb1b2015-08-07 10:03:00 +0530163func plat_get_my_entrypoint
164 adr x1, tegra_sec_entry_point
165 ldr x0, [x1]
Varun Wadekarb316e242015-05-19 16:48:04 +0530166 ret
Varun Wadekara78bb1b2015-08-07 10:03:00 +0530167endfunc plat_get_my_entrypoint
Varun Wadekarb316e242015-05-19 16:48:04 +0530168
169 /* -----------------------------------------------------
Varun Wadekar39f87d12015-09-22 13:45:07 +0530170 * int platform_get_core_pos(int mpidr);
171 *
Varun Wadekarfa99b222017-08-23 16:02:06 -0700172 * result: CorePos = (ClusterId * cpus per cluster) +
173 * CoreId
Varun Wadekar39f87d12015-09-22 13:45:07 +0530174 * -----------------------------------------------------
175 */
176func platform_get_core_pos
177 and x1, x0, #MPIDR_CPU_MASK
178 and x0, x0, #MPIDR_CLUSTER_MASK
Varun Wadekarfa99b222017-08-23 16:02:06 -0700179 lsr x0, x0, #MPIDR_AFFINITY_BITS
180 mov x2, #PLATFORM_MAX_CPUS_PER_CLUSTER
181 mul x0, x0, x2
182 add x0, x1, x0
Varun Wadekar39f87d12015-09-22 13:45:07 +0530183 ret
184endfunc platform_get_core_pos
185
186 /* -----------------------------------------------------
Varun Wadekarb316e242015-05-19 16:48:04 +0530187 * void plat_secondary_cold_boot_setup (void);
188 *
189 * This function performs any platform specific actions
190 * needed for a secondary cpu after a cold reset. Right
191 * now this is a stub function.
192 * -----------------------------------------------------
193 */
194func plat_secondary_cold_boot_setup
195 mov x0, #0
196 ret
197endfunc plat_secondary_cold_boot_setup
198
Varun Wadekarb316e242015-05-19 16:48:04 +0530199 /* --------------------------------------------------------
200 * void platform_mem_init (void);
201 *
202 * Any memory init, relocation to be done before the
203 * platform boots. Called very early in the boot process.
204 * --------------------------------------------------------
205 */
206func platform_mem_init
207 mov x0, #0
208 ret
209endfunc platform_mem_init
210
Varun Wadekarb316e242015-05-19 16:48:04 +0530211 /* ---------------------------------------------------
212 * Function to handle a platform reset and store
213 * input parameters passed by BL2.
214 * ---------------------------------------------------
215 */
216func plat_reset_handler
217
Varun Wadekar1ec441e2016-03-24 15:34:24 -0700218 /* ----------------------------------------------------
219 * Verify if we are running from BL31_BASE address
220 * ----------------------------------------------------
221 */
222 adr x18, bl31_entrypoint
223 mov x17, #BL31_BASE
224 cmp x18, x17
225 b.eq 1f
226
227 /* ----------------------------------------------------
228 * Copy the entire BL31 code to BL31_BASE if we are not
229 * running from it already
230 * ----------------------------------------------------
231 */
232 mov x0, x17
233 mov x1, x18
234 mov x2, #BL31_SIZE
235_loop16:
236 cmp x2, #16
Douglas Raillard2bb9f472017-03-20 10:38:29 +0000237 b.lo _loop1
Varun Wadekar1ec441e2016-03-24 15:34:24 -0700238 ldp x3, x4, [x1], #16
239 stp x3, x4, [x0], #16
240 sub x2, x2, #16
241 b _loop16
242 /* copy byte per byte */
243_loop1:
244 cbz x2, _end
245 ldrb w3, [x1], #1
246 strb w3, [x0], #1
247 subs x2, x2, #1
248 b.ne _loop1
249
250 /* ----------------------------------------------------
251 * Jump to BL31_BASE and start execution again
252 * ----------------------------------------------------
253 */
254_end: mov x0, x20
255 mov x1, x21
256 br x17
2571:
258
Varun Wadekarb316e242015-05-19 16:48:04 +0530259 /* -----------------------------------
260 * derive and save the phys_base addr
261 * -----------------------------------
262 */
263 adr x17, tegra_bl31_phys_base
264 ldr x18, [x17]
265 cbnz x18, 1f
266 adr x18, bl31_entrypoint
267 str x18, [x17]
268
2691: cpu_init_common
270
271 ret
272endfunc plat_reset_handler
273
Varun Wadekarad2d5f32018-11-27 15:47:26 -0800274 /* ------------------------------------------------------
275 * int32_t plat_core_pos_by_mpidr(u_register_t mpidr)
276 *
277 * This function implements a part of the critical
278 * interface between the psci generic layer and the
279 * platform that allows the former to query the platform
280 * to convert an MPIDR to a unique linear index. An error
281 * code (-1) is returned in case the MPIDR is invalid.
282 *
283 * Clobbers: x0-x3
284 * ------------------------------------------------------
285 */
286func plat_core_pos_by_mpidr
287 lsr x1, x0, #MPIDR_AFF0_SHIFT
288 and x1, x1, #MPIDR_AFFLVL_MASK /* core id */
289 lsr x2, x0, #MPIDR_AFF1_SHIFT
290 and x2, x2, #MPIDR_AFFLVL_MASK /* cluster id */
291
292 /* core_id >= PLATFORM_MAX_CPUS_PER_CLUSTER */
293 mov x0, #-1
294 cmp x1, #(PLATFORM_MAX_CPUS_PER_CLUSTER - 1)
295 b.gt 1f
296
297 /* cluster_id >= PLATFORM_CLUSTER_COUNT */
298 cmp x2, #(PLATFORM_CLUSTER_COUNT - 1)
299 b.gt 1f
300
301 /* CorePos = CoreId + (ClusterId * cpus per cluster) */
302 mov x3, #PLATFORM_MAX_CPUS_PER_CLUSTER
303 mul x3, x3, x2
304 add x0, x1, x3
305
3061:
307 ret
308endfunc plat_core_pos_by_mpidr
309
Varun Wadekarb316e242015-05-19 16:48:04 +0530310 /* ----------------------------------------
311 * Secure entrypoint function for CPU boot
312 * ----------------------------------------
313 */
Julius Wernerb4c75e92017-08-01 15:16:36 -0700314func tegra_secure_entrypoint _align=6
Varun Wadekarb316e242015-05-19 16:48:04 +0530315
316#if ERRATA_TEGRA_INVALIDATE_BTB_AT_BOOT
317
Harvey Hsieh6dc0d762017-04-24 19:35:51 +0800318 /* --------------------------------------------------------
319 * Skip the invalidate BTB workaround for Tegra210B01 SKUs.
320 * --------------------------------------------------------
321 */
322 mov x0, #TEGRA_MISC_BASE
323 add x0, x0, #HARDWARE_REVISION_OFFSET
324 ldr w1, [x0]
325 lsr w1, w1, #CHIP_ID_SHIFT
326 and w1, w1, #CHIP_ID_MASK
327 cmp w1, #TEGRA_CHIPID_TEGRA21 /* T210? */
328 b.ne 2f
329 ldr w1, [x0]
330 lsr w1, w1, #MAJOR_VERSION_SHIFT
331 and w1, w1, #MAJOR_VERSION_MASK
332 cmp w1, #0x02 /* T210 B01? */
333 b.eq 2f
334
Varun Wadekarb316e242015-05-19 16:48:04 +0530335 /* -------------------------------------------------------
336 * Invalidate BTB along with I$ to remove any stale
337 * entries from the branch predictor array.
338 * -------------------------------------------------------
339 */
Eleanor Bonnici91b11c32017-08-10 14:46:26 +0100340 mrs x0, CORTEX_A57_CPUACTLR_EL1
Varun Wadekarb316e242015-05-19 16:48:04 +0530341 orr x0, x0, #1
Eleanor Bonnici91b11c32017-08-10 14:46:26 +0100342 msr CORTEX_A57_CPUACTLR_EL1, x0 /* invalidate BTB and I$ together */
Varun Wadekarb316e242015-05-19 16:48:04 +0530343 dsb sy
344 isb
345 ic iallu /* actual invalidate */
346 dsb sy
347 isb
348
Eleanor Bonnici91b11c32017-08-10 14:46:26 +0100349 mrs x0, CORTEX_A57_CPUACTLR_EL1
Varun Wadekarb316e242015-05-19 16:48:04 +0530350 bic x0, x0, #1
Eleanor Bonnici91b11c32017-08-10 14:46:26 +0100351 msr CORTEX_A57_CPUACTLR_EL1, X0 /* restore original CPUACTLR_EL1 */
Varun Wadekarb316e242015-05-19 16:48:04 +0530352 dsb sy
353 isb
354
355 .rept 7
356 nop /* wait */
357 .endr
358
359 /* -----------------------------------------------
360 * Extract OSLK bit and check if it is '1'. This
361 * bit remains '0' for A53 on warm-resets. If '1',
362 * turn off regional clock gating and request warm
363 * reset.
364 * -----------------------------------------------
365 */
366 mrs x0, oslsr_el1
367 and x0, x0, #2
368 mrs x1, mpidr_el1
369 bics xzr, x0, x1, lsr #7 /* 0 = slow cluster or warm reset */
370 b.eq restore_oslock
371 mov x0, xzr
372 msr oslar_el1, x0 /* os lock stays 0 across warm reset */
373 mov x3, #3
374 movz x4, #0x8000, lsl #48
Eleanor Bonnici91b11c32017-08-10 14:46:26 +0100375 msr CORTEX_A57_CPUACTLR_EL1, x4 /* turn off RCG */
Varun Wadekarb316e242015-05-19 16:48:04 +0530376 isb
377 msr rmr_el3, x3 /* request warm reset */
378 isb
379 dsb sy
3801: wfi
381 b 1b
382
383 /* --------------------------------------------------
384 * These nops are here so that speculative execution
385 * won't harm us before we are done with warm reset.
386 * --------------------------------------------------
387 */
388 .rept 65
389 nop
390 .endr
Harvey Hsieh6dc0d762017-04-24 19:35:51 +08003912:
Varun Wadekarb316e242015-05-19 16:48:04 +0530392 /* --------------------------------------------------
393 * Do not insert instructions here
394 * --------------------------------------------------
395 */
396#endif
397
398 /* --------------------------------------------------
399 * Restore OS Lock bit
400 * --------------------------------------------------
401 */
402restore_oslock:
403 mov x0, #1
404 msr oslar_el1, x0
405
Varun Wadekarb316e242015-05-19 16:48:04 +0530406 /* --------------------------------------------------
407 * Get secure world's entry point and jump to it
408 * --------------------------------------------------
409 */
Varun Wadekara78bb1b2015-08-07 10:03:00 +0530410 bl plat_get_my_entrypoint
Varun Wadekarb316e242015-05-19 16:48:04 +0530411 br x0
412endfunc tegra_secure_entrypoint
413
414 .data
415 .align 3
416
417 /* --------------------------------------------------
Varun Wadekara78bb1b2015-08-07 10:03:00 +0530418 * CPU Secure entry point - resume from suspend
Varun Wadekarb316e242015-05-19 16:48:04 +0530419 * --------------------------------------------------
420 */
Varun Wadekara78bb1b2015-08-07 10:03:00 +0530421tegra_sec_entry_point:
Varun Wadekarb316e242015-05-19 16:48:04 +0530422 .quad 0
Varun Wadekarb316e242015-05-19 16:48:04 +0530423
424 /* --------------------------------------------------
425 * NS world's cold boot entry point
426 * --------------------------------------------------
427 */
428ns_image_entrypoint:
429 .quad 0
430
431 /* --------------------------------------------------
432 * BL31's physical base address
433 * --------------------------------------------------
434 */
435tegra_bl31_phys_base:
436 .quad 0
Varun Wadekard2014c62015-10-29 10:37:28 +0530437
438 /* --------------------------------------------------
439 * UART controller base for console init
440 * --------------------------------------------------
441 */
442tegra_console_base:
443 .quad 0