blob: bd2bebb40657c94840e84604faf4f04241d82289 [file] [log] [blame]
Varun Wadekar08438e22015-05-19 16:48:04 +05301/*
Ambroise Vincent544c0922019-05-29 14:04:16 +01002 * Copyright (c) 2015-2019, ARM Limited and Contributors. All rights reserved.
Varun Wadekarb1481cf2018-06-07 11:21:02 -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#include <arch.h>
8#include <asm_macros.S>
9#include <assert_macros.S>
10#include <cpu_macros.S>
Varun Wadekar08438e22015-05-19 16:48:04 +053011#include <cortex_a53.h>
Isla Mitchellee1ebbd2017-07-14 10:46:32 +010012#include <cortex_a57.h>
Varun Wadekar11bd24b2016-04-26 11:38:38 -070013#include <platform_def.h>
Varun Wadekar08438e22015-05-19 16:48:04 +053014#include <tegra_def.h>
Harvey Hsiehc195fec2017-04-24 19:35:51 +080015#include <tegra_platform.h>
Varun Wadekar08438e22015-05-19 16:48:04 +053016
Varun Wadekar0cd61382015-09-22 13:33:56 +053017#define MIDR_PN_CORTEX_A57 0xD07
18
19/*******************************************************************************
20 * Implementation defined ACTLR_EL3 bit definitions
21 ******************************************************************************/
Varun Wadekarb1481cf2018-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 Wadekar0cd61382015-09-22 13:33:56 +053032
Varun Wadekar08438e22015-05-19 16:48:04 +053033 /* Global functions */
Varun Wadekar71cb26e2015-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 Wadekar08438e22015-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 Diaz9c675b32018-10-17 15:29:34 +010041 .globl plat_crash_console_flush
Varun Wadekar0ac1bf72018-11-27 15:47:26 -080042 .weak plat_core_pos_by_mpidr
Varun Wadekar08438e22015-05-19 16:48:04 +053043 .globl tegra_secure_entrypoint
44 .globl plat_reset_handler
45
46 /* Global variables */
Varun Wadekar71cb26e2015-08-07 10:03:00 +053047 .globl tegra_sec_entry_point
Varun Wadekar08438e22015-05-19 16:48:04 +053048 .globl ns_image_entrypoint
49 .globl tegra_bl31_phys_base
Varun Wadekare1084212015-10-29 10:37:28 +053050 .globl tegra_console_base
Varun Wadekar08438e22015-05-19 16:48:04 +053051
52 /* ---------------------
53 * Common CPU init code
54 * ---------------------
55 */
56.macro cpu_init_common
57
Varun Wadekar0cd61382015-09-22 13:33:56 +053058 /* ------------------------------------------------
Varun Wadekar018b8482016-05-12 13:43:33 -070059 * We enable procesor retention, L2/CPUECTLR NS
60 * access and ECC/Parity protection for A57 CPUs
Varun Wadekar0cd61382015-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 Wadekarb42192b2015-08-21 15:56:02 +053070 /* ---------------------------
71 * Enable processor retention
72 * ---------------------------
Varun Wadekar018b8482016-05-12 13:43:33 -070073 */
Varun Wadekarfb7d32e2017-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 Wadekarb42192b2015-08-21 15:56:02 +053077 orr x0, x0, x1
Varun Wadekarfb7d32e2017-06-05 14:54:46 -070078 msr CORTEX_A57_L2ECTLR_EL1, x0
Varun Wadekarb42192b2015-08-21 15:56:02 +053079 isb
Varun Wadekarb42192b2015-08-21 15:56:02 +053080
Varun Wadekarfb7d32e2017-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 Wadekarb42192b2015-08-21 15:56:02 +053084 orr x0, x0, x1
Varun Wadekarfb7d32e2017-06-05 14:54:46 -070085 msr CORTEX_A57_ECTLR_EL1, x0
Varun Wadekarb42192b2015-08-21 15:56:02 +053086 isb
Varun Wadekarb42192b2015-08-21 15:56:02 +053087
Varun Wadekar08438e22015-05-19 16:48:04 +053088 /* -------------------------------------------------------
89 * Enable L2 and CPU ECTLR RW access from non-secure world
90 * -------------------------------------------------------
Varun Wadekar018b8482016-05-12 13:43:33 -070091 */
Steven Kao75516c32017-06-14 14:02:23 +080092 mrs x0, actlr_el3
Varun Wadekarb1481cf2018-06-07 11:21:02 -070093 mov x1, #ACTLR_ELx_ENABLE_ALL_ACCESS
Steven Kao75516c32017-06-14 14:02:23 +080094 orr x0, x0, x1
Varun Wadekar08438e22015-05-19 16:48:04 +053095 msr actlr_el3, x0
Steven Kao75516c32017-06-14 14:02:23 +080096 mrs x0, actlr_el2
Varun Wadekarb1481cf2018-06-07 11:21:02 -070097 mov x1, #ACTLR_ELx_ENABLE_ALL_ACCESS
Steven Kao75516c32017-06-14 14:02:23 +080098 orr x0, x0, x1
Varun Wadekar08438e22015-05-19 16:48:04 +053099 msr actlr_el2, x0
100 isb
Varun Wadekar08438e22015-05-19 16:48:04 +0530101
102 /* --------------------------------
103 * Enable the cycle count register
104 * --------------------------------
105 */
Varun Wadekar0cd61382015-09-22 13:33:56 +05301061: mrs x0, pmcr_el0
Varun Wadekar08438e22015-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 Wadekar71cb26e2015-08-07 10:03:00 +0530127 * unsigned int plat_is_my_cpu_primary(void);
Varun Wadekar08438e22015-05-19 16:48:04 +0530128 *
129 * This function checks if this is the Primary CPU
130 * -----------------------------------------------------
131 */
Varun Wadekar71cb26e2015-08-07 10:03:00 +0530132func plat_is_my_cpu_primary
133 mrs x0, mpidr_el1
Varun Wadekar08438e22015-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 Wadekar71cb26e2015-08-07 10:03:00 +0530138endfunc plat_is_my_cpu_primary
Varun Wadekar08438e22015-05-19 16:48:04 +0530139
Varun Wadekarb627d082017-08-23 16:02:06 -0700140 /* ----------------------------------------------------------
Varun Wadekar71cb26e2015-08-07 10:03:00 +0530141 * unsigned int plat_my_core_pos(void);
Varun Wadekar08438e22015-05-19 16:48:04 +0530142 *
Varun Wadekarb627d082017-08-23 16:02:06 -0700143 * result: CorePos = CoreId + (ClusterId * cpus per cluster)
Kalyani Chidambaram3bab03e2018-10-03 17:00:17 -0700144 * Registers clobbered: x0, x8
Varun Wadekarb627d082017-08-23 16:02:06 -0700145 * ----------------------------------------------------------
Varun Wadekar08438e22015-05-19 16:48:04 +0530146 */
Varun Wadekar71cb26e2015-08-07 10:03:00 +0530147func plat_my_core_pos
Kalyani Chidambaram3bab03e2018-10-03 17:00:17 -0700148 mov x8, x30
Varun Wadekar71cb26e2015-08-07 10:03:00 +0530149 mrs x0, mpidr_el1
Kalyani Chidambaram3bab03e2018-10-03 17:00:17 -0700150 bl plat_core_pos_by_mpidr
151 ret x8
Varun Wadekar71cb26e2015-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.
160 *
161 * -----------------------------------------------------
162 */
163func plat_get_my_entrypoint
164 adr x1, tegra_sec_entry_point
165 ldr x0, [x1]
166 ret
167endfunc plat_get_my_entrypoint
Varun Wadekar08438e22015-05-19 16:48:04 +0530168
169 /* -----------------------------------------------------
170 * void plat_secondary_cold_boot_setup (void);
171 *
172 * This function performs any platform specific actions
173 * needed for a secondary cpu after a cold reset. Right
174 * now this is a stub function.
175 * -----------------------------------------------------
176 */
177func plat_secondary_cold_boot_setup
178 mov x0, #0
179 ret
180endfunc plat_secondary_cold_boot_setup
181
Varun Wadekar08438e22015-05-19 16:48:04 +0530182 /* --------------------------------------------------------
183 * void platform_mem_init (void);
184 *
185 * Any memory init, relocation to be done before the
186 * platform boots. Called very early in the boot process.
187 * --------------------------------------------------------
188 */
189func platform_mem_init
190 mov x0, #0
191 ret
192endfunc platform_mem_init
193
Varun Wadekar08438e22015-05-19 16:48:04 +0530194 /* ---------------------------------------------------
195 * Function to handle a platform reset and store
196 * input parameters passed by BL2.
197 * ---------------------------------------------------
198 */
199func plat_reset_handler
200
Varun Wadekar939dcf22016-03-24 15:34:24 -0700201 /* ----------------------------------------------------
202 * Verify if we are running from BL31_BASE address
203 * ----------------------------------------------------
204 */
205 adr x18, bl31_entrypoint
206 mov x17, #BL31_BASE
207 cmp x18, x17
208 b.eq 1f
209
210 /* ----------------------------------------------------
211 * Copy the entire BL31 code to BL31_BASE if we are not
212 * running from it already
213 * ----------------------------------------------------
214 */
215 mov x0, x17
216 mov x1, x18
217 mov x2, #BL31_SIZE
218_loop16:
219 cmp x2, #16
Douglas Raillard768baf62017-03-20 10:38:29 +0000220 b.lo _loop1
Varun Wadekar939dcf22016-03-24 15:34:24 -0700221 ldp x3, x4, [x1], #16
222 stp x3, x4, [x0], #16
223 sub x2, x2, #16
224 b _loop16
225 /* copy byte per byte */
226_loop1:
227 cbz x2, _end
228 ldrb w3, [x1], #1
229 strb w3, [x0], #1
230 subs x2, x2, #1
231 b.ne _loop1
232
233 /* ----------------------------------------------------
234 * Jump to BL31_BASE and start execution again
235 * ----------------------------------------------------
236 */
237_end: mov x0, x20
238 mov x1, x21
239 br x17
2401:
241
Varun Wadekar08438e22015-05-19 16:48:04 +0530242 /* -----------------------------------
243 * derive and save the phys_base addr
244 * -----------------------------------
245 */
246 adr x17, tegra_bl31_phys_base
247 ldr x18, [x17]
248 cbnz x18, 1f
249 adr x18, bl31_entrypoint
250 str x18, [x17]
251
2521: cpu_init_common
253
254 ret
255endfunc plat_reset_handler
256
Varun Wadekar0ac1bf72018-11-27 15:47:26 -0800257 /* ------------------------------------------------------
258 * int32_t plat_core_pos_by_mpidr(u_register_t mpidr)
259 *
260 * This function implements a part of the critical
261 * interface between the psci generic layer and the
262 * platform that allows the former to query the platform
263 * to convert an MPIDR to a unique linear index. An error
264 * code (-1) is returned in case the MPIDR is invalid.
265 *
266 * Clobbers: x0-x3
267 * ------------------------------------------------------
268 */
269func plat_core_pos_by_mpidr
270 lsr x1, x0, #MPIDR_AFF0_SHIFT
271 and x1, x1, #MPIDR_AFFLVL_MASK /* core id */
272 lsr x2, x0, #MPIDR_AFF1_SHIFT
273 and x2, x2, #MPIDR_AFFLVL_MASK /* cluster id */
274
275 /* core_id >= PLATFORM_MAX_CPUS_PER_CLUSTER */
276 mov x0, #-1
277 cmp x1, #(PLATFORM_MAX_CPUS_PER_CLUSTER - 1)
278 b.gt 1f
279
280 /* cluster_id >= PLATFORM_CLUSTER_COUNT */
281 cmp x2, #(PLATFORM_CLUSTER_COUNT - 1)
282 b.gt 1f
283
284 /* CorePos = CoreId + (ClusterId * cpus per cluster) */
285 mov x3, #PLATFORM_MAX_CPUS_PER_CLUSTER
286 mul x3, x3, x2
287 add x0, x1, x3
288
2891:
290 ret
291endfunc plat_core_pos_by_mpidr
292
Varun Wadekar08438e22015-05-19 16:48:04 +0530293 /* ----------------------------------------
294 * Secure entrypoint function for CPU boot
295 * ----------------------------------------
296 */
Julius Werner64726e62017-08-01 15:16:36 -0700297func tegra_secure_entrypoint _align=6
Varun Wadekar08438e22015-05-19 16:48:04 +0530298
299#if ERRATA_TEGRA_INVALIDATE_BTB_AT_BOOT
300
Harvey Hsiehc195fec2017-04-24 19:35:51 +0800301 /* --------------------------------------------------------
302 * Skip the invalidate BTB workaround for Tegra210B01 SKUs.
303 * --------------------------------------------------------
304 */
305 mov x0, #TEGRA_MISC_BASE
306 add x0, x0, #HARDWARE_REVISION_OFFSET
307 ldr w1, [x0]
308 lsr w1, w1, #CHIP_ID_SHIFT
309 and w1, w1, #CHIP_ID_MASK
310 cmp w1, #TEGRA_CHIPID_TEGRA21 /* T210? */
311 b.ne 2f
312 ldr w1, [x0]
313 lsr w1, w1, #MAJOR_VERSION_SHIFT
314 and w1, w1, #MAJOR_VERSION_MASK
315 cmp w1, #0x02 /* T210 B01? */
316 b.eq 2f
317
Varun Wadekar08438e22015-05-19 16:48:04 +0530318 /* -------------------------------------------------------
319 * Invalidate BTB along with I$ to remove any stale
320 * entries from the branch predictor array.
321 * -------------------------------------------------------
322 */
Eleanor Bonnicid0e10942017-08-10 14:46:26 +0100323 mrs x0, CORTEX_A57_CPUACTLR_EL1
Varun Wadekar08438e22015-05-19 16:48:04 +0530324 orr x0, x0, #1
Eleanor Bonnicid0e10942017-08-10 14:46:26 +0100325 msr CORTEX_A57_CPUACTLR_EL1, x0 /* invalidate BTB and I$ together */
Varun Wadekar08438e22015-05-19 16:48:04 +0530326 dsb sy
327 isb
328 ic iallu /* actual invalidate */
329 dsb sy
330 isb
331
Eleanor Bonnicid0e10942017-08-10 14:46:26 +0100332 mrs x0, CORTEX_A57_CPUACTLR_EL1
Varun Wadekar08438e22015-05-19 16:48:04 +0530333 bic x0, x0, #1
Eleanor Bonnicid0e10942017-08-10 14:46:26 +0100334 msr CORTEX_A57_CPUACTLR_EL1, X0 /* restore original CPUACTLR_EL1 */
Varun Wadekar08438e22015-05-19 16:48:04 +0530335 dsb sy
336 isb
337
338 .rept 7
339 nop /* wait */
340 .endr
341
342 /* -----------------------------------------------
343 * Extract OSLK bit and check if it is '1'. This
344 * bit remains '0' for A53 on warm-resets. If '1',
345 * turn off regional clock gating and request warm
346 * reset.
347 * -----------------------------------------------
348 */
349 mrs x0, oslsr_el1
350 and x0, x0, #2
351 mrs x1, mpidr_el1
352 bics xzr, x0, x1, lsr #7 /* 0 = slow cluster or warm reset */
353 b.eq restore_oslock
354 mov x0, xzr
355 msr oslar_el1, x0 /* os lock stays 0 across warm reset */
356 mov x3, #3
357 movz x4, #0x8000, lsl #48
Eleanor Bonnicid0e10942017-08-10 14:46:26 +0100358 msr CORTEX_A57_CPUACTLR_EL1, x4 /* turn off RCG */
Varun Wadekar08438e22015-05-19 16:48:04 +0530359 isb
360 msr rmr_el3, x3 /* request warm reset */
361 isb
362 dsb sy
3631: wfi
364 b 1b
365
366 /* --------------------------------------------------
367 * These nops are here so that speculative execution
368 * won't harm us before we are done with warm reset.
369 * --------------------------------------------------
370 */
371 .rept 65
372 nop
373 .endr
Harvey Hsiehc195fec2017-04-24 19:35:51 +08003742:
Varun Wadekar08438e22015-05-19 16:48:04 +0530375 /* --------------------------------------------------
376 * Do not insert instructions here
377 * --------------------------------------------------
378 */
379#endif
380
381 /* --------------------------------------------------
382 * Restore OS Lock bit
383 * --------------------------------------------------
384 */
385restore_oslock:
386 mov x0, #1
387 msr oslar_el1, x0
388
Varun Wadekar08438e22015-05-19 16:48:04 +0530389 /* --------------------------------------------------
390 * Get secure world's entry point and jump to it
391 * --------------------------------------------------
392 */
Varun Wadekar71cb26e2015-08-07 10:03:00 +0530393 bl plat_get_my_entrypoint
Varun Wadekar08438e22015-05-19 16:48:04 +0530394 br x0
395endfunc tegra_secure_entrypoint
396
397 .data
398 .align 3
399
400 /* --------------------------------------------------
Varun Wadekar71cb26e2015-08-07 10:03:00 +0530401 * CPU Secure entry point - resume from suspend
Varun Wadekar08438e22015-05-19 16:48:04 +0530402 * --------------------------------------------------
403 */
Varun Wadekar71cb26e2015-08-07 10:03:00 +0530404tegra_sec_entry_point:
Varun Wadekar08438e22015-05-19 16:48:04 +0530405 .quad 0
Varun Wadekar08438e22015-05-19 16:48:04 +0530406
407 /* --------------------------------------------------
408 * NS world's cold boot entry point
409 * --------------------------------------------------
410 */
411ns_image_entrypoint:
412 .quad 0
413
414 /* --------------------------------------------------
415 * BL31's physical base address
416 * --------------------------------------------------
417 */
418tegra_bl31_phys_base:
419 .quad 0
Varun Wadekare1084212015-10-29 10:37:28 +0530420
421 /* --------------------------------------------------
422 * UART controller base for console init
423 * --------------------------------------------------
424 */
425tegra_console_base:
426 .quad 0