blob: b6622c7f12fa314619db898621e388cb4c699c24 [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 Wadekar08438e22015-05-19 16:48:04 +053042 .globl tegra_secure_entrypoint
43 .globl plat_reset_handler
44
45 /* Global variables */
Varun Wadekar71cb26e2015-08-07 10:03:00 +053046 .globl tegra_sec_entry_point
Varun Wadekar08438e22015-05-19 16:48:04 +053047 .globl ns_image_entrypoint
48 .globl tegra_bl31_phys_base
Varun Wadekare1084212015-10-29 10:37:28 +053049 .globl tegra_console_base
Varun Wadekar08438e22015-05-19 16:48:04 +053050
51 /* ---------------------
52 * Common CPU init code
53 * ---------------------
54 */
55.macro cpu_init_common
56
Varun Wadekar0cd61382015-09-22 13:33:56 +053057 /* ------------------------------------------------
Varun Wadekar018b8482016-05-12 13:43:33 -070058 * We enable procesor retention, L2/CPUECTLR NS
59 * access and ECC/Parity protection for A57 CPUs
Varun Wadekar0cd61382015-09-22 13:33:56 +053060 * ------------------------------------------------
61 */
62 mrs x0, midr_el1
63 mov x1, #(MIDR_PN_MASK << MIDR_PN_SHIFT)
64 and x0, x0, x1
65 lsr x0, x0, #MIDR_PN_SHIFT
66 cmp x0, #MIDR_PN_CORTEX_A57
67 b.ne 1f
68
Varun Wadekarb42192b2015-08-21 15:56:02 +053069 /* ---------------------------
70 * Enable processor retention
71 * ---------------------------
Varun Wadekar018b8482016-05-12 13:43:33 -070072 */
Varun Wadekarfb7d32e2017-06-05 14:54:46 -070073 mrs x0, CORTEX_A57_L2ECTLR_EL1
74 mov x1, #RETENTION_ENTRY_TICKS_512
75 bic x0, x0, #CORTEX_A57_L2ECTLR_RET_CTRL_MASK
Varun Wadekarb42192b2015-08-21 15:56:02 +053076 orr x0, x0, x1
Varun Wadekarfb7d32e2017-06-05 14:54:46 -070077 msr CORTEX_A57_L2ECTLR_EL1, x0
Varun Wadekarb42192b2015-08-21 15:56:02 +053078 isb
Varun Wadekarb42192b2015-08-21 15:56:02 +053079
Varun Wadekarfb7d32e2017-06-05 14:54:46 -070080 mrs x0, CORTEX_A57_ECTLR_EL1
81 mov x1, #RETENTION_ENTRY_TICKS_512
82 bic x0, x0, #CORTEX_A57_ECTLR_CPU_RET_CTRL_MASK
Varun Wadekarb42192b2015-08-21 15:56:02 +053083 orr x0, x0, x1
Varun Wadekarfb7d32e2017-06-05 14:54:46 -070084 msr CORTEX_A57_ECTLR_EL1, x0
Varun Wadekarb42192b2015-08-21 15:56:02 +053085 isb
Varun Wadekarb42192b2015-08-21 15:56:02 +053086
Varun Wadekar08438e22015-05-19 16:48:04 +053087 /* -------------------------------------------------------
88 * Enable L2 and CPU ECTLR RW access from non-secure world
89 * -------------------------------------------------------
Varun Wadekar018b8482016-05-12 13:43:33 -070090 */
Steven Kao75516c32017-06-14 14:02:23 +080091 mrs x0, actlr_el3
Varun Wadekarb1481cf2018-06-07 11:21:02 -070092 mov x1, #ACTLR_ELx_ENABLE_ALL_ACCESS
Steven Kao75516c32017-06-14 14:02:23 +080093 orr x0, x0, x1
Varun Wadekar08438e22015-05-19 16:48:04 +053094 msr actlr_el3, x0
Steven Kao75516c32017-06-14 14:02:23 +080095 mrs x0, actlr_el2
Varun Wadekarb1481cf2018-06-07 11:21:02 -070096 mov x1, #ACTLR_ELx_ENABLE_ALL_ACCESS
Steven Kao75516c32017-06-14 14:02:23 +080097 orr x0, x0, x1
Varun Wadekar08438e22015-05-19 16:48:04 +053098 msr actlr_el2, x0
99 isb
Varun Wadekar08438e22015-05-19 16:48:04 +0530100
101 /* --------------------------------
102 * Enable the cycle count register
103 * --------------------------------
104 */
Varun Wadekar0cd61382015-09-22 13:33:56 +05301051: mrs x0, pmcr_el0
Varun Wadekar08438e22015-05-19 16:48:04 +0530106 ubfx x0, x0, #11, #5 // read PMCR.N field
107 mov x1, #1
108 lsl x0, x1, x0
109 sub x0, x0, #1 // mask of event counters
110 orr x0, x0, #0x80000000 // disable overflow intrs
111 msr pmintenclr_el1, x0
112 msr pmuserenr_el0, x1 // enable user mode access
113
114 /* ----------------------------------------------------------------
115 * Allow non-privileged access to CNTVCT: Set CNTKCTL (Kernel Count
116 * register), bit 1 (EL0VCTEN) to enable access to CNTVCT/CNTFRQ
117 * registers from EL0.
118 * ----------------------------------------------------------------
119 */
120 mrs x0, cntkctl_el1
121 orr x0, x0, #EL0VCTEN_BIT
122 msr cntkctl_el1, x0
123.endm
124
125 /* -----------------------------------------------------
Varun Wadekar71cb26e2015-08-07 10:03:00 +0530126 * unsigned int plat_is_my_cpu_primary(void);
Varun Wadekar08438e22015-05-19 16:48:04 +0530127 *
128 * This function checks if this is the Primary CPU
129 * -----------------------------------------------------
130 */
Varun Wadekar71cb26e2015-08-07 10:03:00 +0530131func plat_is_my_cpu_primary
132 mrs x0, mpidr_el1
Varun Wadekar08438e22015-05-19 16:48:04 +0530133 and x0, x0, #(MPIDR_CLUSTER_MASK | MPIDR_CPU_MASK)
134 cmp x0, #TEGRA_PRIMARY_CPU
135 cset x0, eq
136 ret
Varun Wadekar71cb26e2015-08-07 10:03:00 +0530137endfunc plat_is_my_cpu_primary
Varun Wadekar08438e22015-05-19 16:48:04 +0530138
Varun Wadekarb627d082017-08-23 16:02:06 -0700139 /* ----------------------------------------------------------
Varun Wadekar71cb26e2015-08-07 10:03:00 +0530140 * unsigned int plat_my_core_pos(void);
Varun Wadekar08438e22015-05-19 16:48:04 +0530141 *
Varun Wadekarb627d082017-08-23 16:02:06 -0700142 * result: CorePos = CoreId + (ClusterId * cpus per cluster)
Kalyani Chidambaram3bab03e2018-10-03 17:00:17 -0700143 * Registers clobbered: x0, x8
Varun Wadekarb627d082017-08-23 16:02:06 -0700144 * ----------------------------------------------------------
Varun Wadekar08438e22015-05-19 16:48:04 +0530145 */
Varun Wadekar71cb26e2015-08-07 10:03:00 +0530146func plat_my_core_pos
Kalyani Chidambaram3bab03e2018-10-03 17:00:17 -0700147 mov x8, x30
Varun Wadekar71cb26e2015-08-07 10:03:00 +0530148 mrs x0, mpidr_el1
Kalyani Chidambaram3bab03e2018-10-03 17:00:17 -0700149 bl plat_core_pos_by_mpidr
150 ret x8
Varun Wadekar71cb26e2015-08-07 10:03:00 +0530151endfunc plat_my_core_pos
152
153 /* -----------------------------------------------------
154 * unsigned long plat_get_my_entrypoint (void);
155 *
156 * Main job of this routine is to distinguish between
157 * a cold and warm boot. If the tegra_sec_entry_point for
158 * this CPU is present, then it's a warm boot.
159 *
160 * -----------------------------------------------------
161 */
162func plat_get_my_entrypoint
163 adr x1, tegra_sec_entry_point
164 ldr x0, [x1]
165 ret
166endfunc plat_get_my_entrypoint
Varun Wadekar08438e22015-05-19 16:48:04 +0530167
168 /* -----------------------------------------------------
Varun Wadekarbde81dc2015-09-22 13:45:07 +0530169 * int platform_get_core_pos(int mpidr);
170 *
Varun Wadekarb627d082017-08-23 16:02:06 -0700171 * result: CorePos = (ClusterId * cpus per cluster) +
172 * CoreId
Varun Wadekarbde81dc2015-09-22 13:45:07 +0530173 * -----------------------------------------------------
174 */
175func platform_get_core_pos
176 and x1, x0, #MPIDR_CPU_MASK
177 and x0, x0, #MPIDR_CLUSTER_MASK
Varun Wadekarb627d082017-08-23 16:02:06 -0700178 lsr x0, x0, #MPIDR_AFFINITY_BITS
179 mov x2, #PLATFORM_MAX_CPUS_PER_CLUSTER
180 mul x0, x0, x2
181 add x0, x1, x0
Varun Wadekarbde81dc2015-09-22 13:45:07 +0530182 ret
183endfunc platform_get_core_pos
184
185 /* -----------------------------------------------------
Varun Wadekar08438e22015-05-19 16:48:04 +0530186 * void plat_secondary_cold_boot_setup (void);
187 *
188 * This function performs any platform specific actions
189 * needed for a secondary cpu after a cold reset. Right
190 * now this is a stub function.
191 * -----------------------------------------------------
192 */
193func plat_secondary_cold_boot_setup
194 mov x0, #0
195 ret
196endfunc plat_secondary_cold_boot_setup
197
Varun Wadekar08438e22015-05-19 16:48:04 +0530198 /* --------------------------------------------------------
199 * void platform_mem_init (void);
200 *
201 * Any memory init, relocation to be done before the
202 * platform boots. Called very early in the boot process.
203 * --------------------------------------------------------
204 */
205func platform_mem_init
206 mov x0, #0
207 ret
208endfunc platform_mem_init
209
Varun Wadekar08438e22015-05-19 16:48:04 +0530210 /* ---------------------------------------------------
211 * Function to handle a platform reset and store
212 * input parameters passed by BL2.
213 * ---------------------------------------------------
214 */
215func plat_reset_handler
216
Varun Wadekar939dcf22016-03-24 15:34:24 -0700217 /* ----------------------------------------------------
218 * Verify if we are running from BL31_BASE address
219 * ----------------------------------------------------
220 */
221 adr x18, bl31_entrypoint
222 mov x17, #BL31_BASE
223 cmp x18, x17
224 b.eq 1f
225
226 /* ----------------------------------------------------
227 * Copy the entire BL31 code to BL31_BASE if we are not
228 * running from it already
229 * ----------------------------------------------------
230 */
231 mov x0, x17
232 mov x1, x18
233 mov x2, #BL31_SIZE
234_loop16:
235 cmp x2, #16
Douglas Raillard768baf62017-03-20 10:38:29 +0000236 b.lo _loop1
Varun Wadekar939dcf22016-03-24 15:34:24 -0700237 ldp x3, x4, [x1], #16
238 stp x3, x4, [x0], #16
239 sub x2, x2, #16
240 b _loop16
241 /* copy byte per byte */
242_loop1:
243 cbz x2, _end
244 ldrb w3, [x1], #1
245 strb w3, [x0], #1
246 subs x2, x2, #1
247 b.ne _loop1
248
249 /* ----------------------------------------------------
250 * Jump to BL31_BASE and start execution again
251 * ----------------------------------------------------
252 */
253_end: mov x0, x20
254 mov x1, x21
255 br x17
2561:
257
Varun Wadekar08438e22015-05-19 16:48:04 +0530258 /* -----------------------------------
259 * derive and save the phys_base addr
260 * -----------------------------------
261 */
262 adr x17, tegra_bl31_phys_base
263 ldr x18, [x17]
264 cbnz x18, 1f
265 adr x18, bl31_entrypoint
266 str x18, [x17]
267
2681: cpu_init_common
269
270 ret
271endfunc plat_reset_handler
272
273 /* ----------------------------------------
274 * Secure entrypoint function for CPU boot
275 * ----------------------------------------
276 */
Julius Werner64726e62017-08-01 15:16:36 -0700277func tegra_secure_entrypoint _align=6
Varun Wadekar08438e22015-05-19 16:48:04 +0530278
279#if ERRATA_TEGRA_INVALIDATE_BTB_AT_BOOT
280
Harvey Hsiehc195fec2017-04-24 19:35:51 +0800281 /* --------------------------------------------------------
282 * Skip the invalidate BTB workaround for Tegra210B01 SKUs.
283 * --------------------------------------------------------
284 */
285 mov x0, #TEGRA_MISC_BASE
286 add x0, x0, #HARDWARE_REVISION_OFFSET
287 ldr w1, [x0]
288 lsr w1, w1, #CHIP_ID_SHIFT
289 and w1, w1, #CHIP_ID_MASK
290 cmp w1, #TEGRA_CHIPID_TEGRA21 /* T210? */
291 b.ne 2f
292 ldr w1, [x0]
293 lsr w1, w1, #MAJOR_VERSION_SHIFT
294 and w1, w1, #MAJOR_VERSION_MASK
295 cmp w1, #0x02 /* T210 B01? */
296 b.eq 2f
297
Varun Wadekar08438e22015-05-19 16:48:04 +0530298 /* -------------------------------------------------------
299 * Invalidate BTB along with I$ to remove any stale
300 * entries from the branch predictor array.
301 * -------------------------------------------------------
302 */
Eleanor Bonnicid0e10942017-08-10 14:46:26 +0100303 mrs x0, CORTEX_A57_CPUACTLR_EL1
Varun Wadekar08438e22015-05-19 16:48:04 +0530304 orr x0, x0, #1
Eleanor Bonnicid0e10942017-08-10 14:46:26 +0100305 msr CORTEX_A57_CPUACTLR_EL1, x0 /* invalidate BTB and I$ together */
Varun Wadekar08438e22015-05-19 16:48:04 +0530306 dsb sy
307 isb
308 ic iallu /* actual invalidate */
309 dsb sy
310 isb
311
Eleanor Bonnicid0e10942017-08-10 14:46:26 +0100312 mrs x0, CORTEX_A57_CPUACTLR_EL1
Varun Wadekar08438e22015-05-19 16:48:04 +0530313 bic x0, x0, #1
Eleanor Bonnicid0e10942017-08-10 14:46:26 +0100314 msr CORTEX_A57_CPUACTLR_EL1, X0 /* restore original CPUACTLR_EL1 */
Varun Wadekar08438e22015-05-19 16:48:04 +0530315 dsb sy
316 isb
317
318 .rept 7
319 nop /* wait */
320 .endr
321
322 /* -----------------------------------------------
323 * Extract OSLK bit and check if it is '1'. This
324 * bit remains '0' for A53 on warm-resets. If '1',
325 * turn off regional clock gating and request warm
326 * reset.
327 * -----------------------------------------------
328 */
329 mrs x0, oslsr_el1
330 and x0, x0, #2
331 mrs x1, mpidr_el1
332 bics xzr, x0, x1, lsr #7 /* 0 = slow cluster or warm reset */
333 b.eq restore_oslock
334 mov x0, xzr
335 msr oslar_el1, x0 /* os lock stays 0 across warm reset */
336 mov x3, #3
337 movz x4, #0x8000, lsl #48
Eleanor Bonnicid0e10942017-08-10 14:46:26 +0100338 msr CORTEX_A57_CPUACTLR_EL1, x4 /* turn off RCG */
Varun Wadekar08438e22015-05-19 16:48:04 +0530339 isb
340 msr rmr_el3, x3 /* request warm reset */
341 isb
342 dsb sy
3431: wfi
344 b 1b
345
346 /* --------------------------------------------------
347 * These nops are here so that speculative execution
348 * won't harm us before we are done with warm reset.
349 * --------------------------------------------------
350 */
351 .rept 65
352 nop
353 .endr
Harvey Hsiehc195fec2017-04-24 19:35:51 +08003542:
Varun Wadekar08438e22015-05-19 16:48:04 +0530355 /* --------------------------------------------------
356 * Do not insert instructions here
357 * --------------------------------------------------
358 */
359#endif
360
361 /* --------------------------------------------------
362 * Restore OS Lock bit
363 * --------------------------------------------------
364 */
365restore_oslock:
366 mov x0, #1
367 msr oslar_el1, x0
368
Varun Wadekar08438e22015-05-19 16:48:04 +0530369 /* --------------------------------------------------
370 * Get secure world's entry point and jump to it
371 * --------------------------------------------------
372 */
Varun Wadekar71cb26e2015-08-07 10:03:00 +0530373 bl plat_get_my_entrypoint
Varun Wadekar08438e22015-05-19 16:48:04 +0530374 br x0
375endfunc tegra_secure_entrypoint
376
377 .data
378 .align 3
379
380 /* --------------------------------------------------
Varun Wadekar71cb26e2015-08-07 10:03:00 +0530381 * CPU Secure entry point - resume from suspend
Varun Wadekar08438e22015-05-19 16:48:04 +0530382 * --------------------------------------------------
383 */
Varun Wadekar71cb26e2015-08-07 10:03:00 +0530384tegra_sec_entry_point:
Varun Wadekar08438e22015-05-19 16:48:04 +0530385 .quad 0
Varun Wadekar08438e22015-05-19 16:48:04 +0530386
387 /* --------------------------------------------------
388 * NS world's cold boot entry point
389 * --------------------------------------------------
390 */
391ns_image_entrypoint:
392 .quad 0
393
394 /* --------------------------------------------------
395 * BL31's physical base address
396 * --------------------------------------------------
397 */
398tegra_bl31_phys_base:
399 .quad 0
Varun Wadekare1084212015-10-29 10:37:28 +0530400
401 /* --------------------------------------------------
402 * UART controller base for console init
403 * --------------------------------------------------
404 */
405tegra_console_base:
406 .quad 0