blob: 85baebc5f78ea8438d125e3b5f45dba321f11a3c [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001/* SPDX-License-Identifier: GPL-2.0+ */
David Feng85fd5f12013-12-14 11:47:35 +08002/*
3 * (C) Copyright 2013
4 * David Feng <fenghua@phytium.com.cn>
David Feng85fd5f12013-12-14 11:47:35 +08005 */
6
7#include <asm-offsets.h>
8#include <config.h>
David Feng85fd5f12013-12-14 11:47:35 +08009#include <linux/linkage.h>
10#include <asm/macro.h>
11#include <asm/armv8/mmu.h>
12
13/*************************************************************************
14 *
15 * Startup Code (reset vector)
16 *
17 *************************************************************************/
18
19.globl _start
20_start:
Mian Yousaf Kaukaba0dcfc52019-06-13 14:46:44 +020021#if defined(CONFIG_LINUX_KERNEL_IMAGE_HEADER)
Stephen Warren80a93652018-01-03 14:31:51 -070022#include <asm/boot0-linux-kernel-header.h>
23#elif defined(CONFIG_ENABLE_ARM_SOC_BOOT0_HOOK)
Andre Przywara48321ba2016-05-31 10:45:06 -070024/*
25 * Various SoCs need something special and SoC-specific up front in
26 * order to boot, allow them to set that in their boot0.h file and then
27 * use it here.
28 */
29#include <asm/arch/boot0.h>
Andre Przywara313a5782017-01-02 11:48:33 +000030#else
31 b reset
Andre Przywara48321ba2016-05-31 10:45:06 -070032#endif
33
David Feng85fd5f12013-12-14 11:47:35 +080034 .align 3
35
36.globl _TEXT_BASE
37_TEXT_BASE:
38 .quad CONFIG_SYS_TEXT_BASE
39
40/*
41 * These are defined in the linker script.
42 */
43.globl _end_ofs
44_end_ofs:
45 .quad _end - _start
46
47.globl _bss_start_ofs
48_bss_start_ofs:
49 .quad __bss_start - _start
50
51.globl _bss_end_ofs
52_bss_end_ofs:
53 .quad __bss_end - _start
54
55reset:
Stephen Warren100a4792016-07-18 17:01:50 -060056 /* Allow the board to save important registers */
57 b save_boot_params
58.globl save_boot_params_ret
59save_boot_params_ret:
60
Stephen Warren81c21372017-11-02 18:11:27 -060061#if CONFIG_POSITION_INDEPENDENT
Edgar E. Iglesias67c9c932020-09-09 19:07:25 +020062 /* Verify that we're 4K aligned. */
63 adr x0, _start
64 ands x0, x0, #0xfff
65 b.eq 1f
660:
67 /*
68 * FATAL, can't continue.
69 * U-Boot needs to be loaded at a 4K aligned address.
70 *
71 * We use ADRP and ADD to load some symbol addresses during startup.
72 * The ADD uses an absolute (non pc-relative) lo12 relocation
73 * thus requiring 4K alignment.
74 */
75 wfi
76 b 0b
771:
78
Stephen Warren81c21372017-11-02 18:11:27 -060079 /*
80 * Fix .rela.dyn relocations. This allows U-Boot to be loaded to and
81 * executed at a different address than it was linked at.
82 */
83pie_fixup:
84 adr x0, _start /* x0 <- Runtime value of _start */
85 ldr x1, _TEXT_BASE /* x1 <- Linked value of _start */
86 sub x9, x0, x1 /* x9 <- Run-vs-link offset */
87 adr x2, __rel_dyn_start /* x2 <- Runtime &__rel_dyn_start */
88 adr x3, __rel_dyn_end /* x3 <- Runtime &__rel_dyn_end */
89pie_fix_loop:
90 ldp x0, x1, [x2], #16 /* (x0, x1) <- (Link location, fixup) */
91 ldr x4, [x2], #8 /* x4 <- addend */
92 cmp w1, #1027 /* relative fixup? */
93 bne pie_skip_reloc
94 /* relative fix: store addend plus offset at dest location */
95 add x0, x0, x9
96 add x4, x4, x9
97 str x4, [x0]
98pie_skip_reloc:
99 cmp x2, x3
100 b.lo pie_fix_loop
101pie_fixup_done:
102#endif
103
Sergey Temerkhanov78eaa492015-10-14 09:55:45 -0700104#ifdef CONFIG_SYS_RESET_SCTRL
105 bl reset_sctrl
106#endif
Andre Przywara4eecab72018-07-25 00:57:01 +0100107
Alexander Grafb3e9dc62019-02-20 17:14:49 +0100108#if defined(CONFIG_ARMV8_SPL_EXCEPTION_VECTORS) || !defined(CONFIG_SPL_BUILD)
Andre Przywara4eecab72018-07-25 00:57:01 +0100109.macro set_vbar, regname, reg
110 msr \regname, \reg
111.endm
112 adr x0, vectors
113#else
114.macro set_vbar, regname, reg
115.endm
116#endif
David Feng85fd5f12013-12-14 11:47:35 +0800117 /*
118 * Could be EL3/EL2/EL1, Initial State:
119 * Little Endian, MMU Disabled, i/dCache Disabled
120 */
David Feng85fd5f12013-12-14 11:47:35 +0800121 switch_el x1, 3f, 2f, 1f
Andre Przywara4eecab72018-07-25 00:57:01 +01001223: set_vbar vbar_el3, x0
David Feng7c5eca72014-04-19 09:45:21 +0800123 mrs x0, scr_el3
David Feng79bbde02014-03-14 14:26:27 +0800124 orr x0, x0, #0xf /* SCR_EL3.NS|IRQ|FIQ|EA */
125 msr scr_el3, x0
David Feng85fd5f12013-12-14 11:47:35 +0800126 msr cptr_el3, xzr /* Enable FP/SIMD */
Thierry Reding25657922015-08-20 11:42:18 +0200127#ifdef COUNTER_FREQUENCY
David Feng85fd5f12013-12-14 11:47:35 +0800128 ldr x0, =COUNTER_FREQUENCY
129 msr cntfrq_el0, x0 /* Initialize CNTFRQ */
Thierry Reding25657922015-08-20 11:42:18 +0200130#endif
David Feng85fd5f12013-12-14 11:47:35 +0800131 b 0f
Andre Przywara4eecab72018-07-25 00:57:01 +01001322: set_vbar vbar_el2, x0
David Feng85fd5f12013-12-14 11:47:35 +0800133 mov x0, #0x33ff
134 msr cptr_el2, x0 /* Enable FP/SIMD */
135 b 0f
Andre Przywara4eecab72018-07-25 00:57:01 +01001361: set_vbar vbar_el1, x0
David Feng85fd5f12013-12-14 11:47:35 +0800137 mov x0, #3 << 20
138 msr cpacr_el1, x0 /* Enable FP/SIMD */
1390:
Volodymyr Babchukb2b52252020-06-24 01:05:19 +0000140 isb
David Feng85fd5f12013-12-14 11:47:35 +0800141
Mingkai Hu553d4052017-01-06 17:41:10 +0800142 /*
Dinh Nguyenc3e970a2017-04-26 23:36:03 -0500143 * Enable SMPEN bit for coherency.
Mingkai Hu553d4052017-01-06 17:41:10 +0800144 * This register is not architectural but at the moment
145 * this bit should be set for A53/A57/A72.
146 */
147#ifdef CONFIG_ARMV8_SET_SMPEN
York Sune6b871e2017-05-15 08:51:59 -0700148 switch_el x1, 3f, 1f, 1f
1493:
Dinh Nguyenc3e970a2017-04-26 23:36:03 -0500150 mrs x0, S3_1_c15_c2_1 /* cpuectlr_el1 */
Mingkai Hu553d4052017-01-06 17:41:10 +0800151 orr x0, x0, #0x40
152 msr S3_1_c15_c2_1, x0
Volodymyr Babchukb2b52252020-06-24 01:05:19 +0000153 isb
York Sune6b871e2017-05-15 08:51:59 -07001541:
Mingkai Hu553d4052017-01-06 17:41:10 +0800155#endif
156
Bhupesh Sharma80a7e352015-01-23 15:50:04 +0530157 /* Apply ARM core specific erratas */
158 bl apply_core_errata
159
York Sunef042012014-02-26 13:26:04 -0800160 /*
161 * Cache/BPB/TLB Invalidate
162 * i-cache is invalidated before enabled in icache_enable()
163 * tlb is invalidated before mmu is enabled in dcache_enable()
164 * d-cache is invalidated before enabled in dcache_enable()
165 */
David Feng85fd5f12013-12-14 11:47:35 +0800166
167 /* Processor specific initialization */
168 bl lowlevel_init
169
Oded Gabbay97a8d652016-12-27 11:19:43 +0200170#if defined(CONFIG_ARMV8_SPIN_TABLE) && !defined(CONFIG_SPL_BUILD)
Masahiro Yamada2663cd62016-06-27 19:31:05 +0900171 branch_if_master x0, x1, master_cpu
172 b spin_table_secondary_jump
173 /* never return */
174#elif defined(CONFIG_ARMV8_MULTIENTRY)
David Feng85fd5f12013-12-14 11:47:35 +0800175 branch_if_master x0, x1, master_cpu
176
177 /*
178 * Slave CPUs
179 */
180slave_cpu:
181 wfe
182 ldr x1, =CPU_RELEASE_ADDR
183 ldr x0, [x1]
184 cbz x0, slave_cpu
185 br x0 /* branch to the given address */
Linus Walleij74771392015-03-09 10:53:21 +0100186#endif /* CONFIG_ARMV8_MULTIENTRY */
Masahiro Yamada2663cd62016-06-27 19:31:05 +0900187master_cpu:
David Feng85fd5f12013-12-14 11:47:35 +0800188 bl _main
189
Sergey Temerkhanov78eaa492015-10-14 09:55:45 -0700190#ifdef CONFIG_SYS_RESET_SCTRL
191reset_sctrl:
192 switch_el x1, 3f, 2f, 1f
1933:
194 mrs x0, sctlr_el3
195 b 0f
1962:
197 mrs x0, sctlr_el2
198 b 0f
1991:
200 mrs x0, sctlr_el1
201
2020:
203 ldr x1, =0xfdfffffa
204 and x0, x0, x1
205
206 switch_el x1, 6f, 5f, 4f
2076:
208 msr sctlr_el3, x0
209 b 7f
2105:
211 msr sctlr_el2, x0
212 b 7f
2134:
214 msr sctlr_el1, x0
215
2167:
217 dsb sy
218 isb
219 b __asm_invalidate_tlb_all
220 ret
221#endif
222
David Feng85fd5f12013-12-14 11:47:35 +0800223/*-----------------------------------------------------------------------*/
224
Bhupesh Sharma80a7e352015-01-23 15:50:04 +0530225WEAK(apply_core_errata)
226
227 mov x29, lr /* Save LR */
Alison Wangc1293872017-12-28 13:00:55 +0800228 /* For now, we support Cortex-A53, Cortex-A57 specific errata */
229
230 /* Check if we are running on a Cortex-A53 core */
231 branch_if_a53_core x0, apply_a53_core_errata
Bhupesh Sharma80a7e352015-01-23 15:50:04 +0530232
233 /* Check if we are running on a Cortex-A57 core */
234 branch_if_a57_core x0, apply_a57_core_errata
2350:
236 mov lr, x29 /* Restore LR */
237 ret
238
Alison Wangc1293872017-12-28 13:00:55 +0800239apply_a53_core_errata:
240
241#ifdef CONFIG_ARM_ERRATA_855873
242 mrs x0, midr_el1
243 tst x0, #(0xf << 20)
244 b.ne 0b
245
246 mrs x0, midr_el1
247 and x0, x0, #0xf
248 cmp x0, #3
249 b.lt 0b
250
251 mrs x0, S3_1_c15_c2_0 /* cpuactlr_el1 */
252 /* Enable data cache clean as data cache clean/invalidate */
253 orr x0, x0, #1 << 44
254 msr S3_1_c15_c2_0, x0 /* cpuactlr_el1 */
Volodymyr Babchukb2b52252020-06-24 01:05:19 +0000255 isb
Alison Wangc1293872017-12-28 13:00:55 +0800256#endif
257 b 0b
258
Bhupesh Sharma80a7e352015-01-23 15:50:04 +0530259apply_a57_core_errata:
260
261#ifdef CONFIG_ARM_ERRATA_828024
262 mrs x0, S3_1_c15_c2_0 /* cpuactlr_el1 */
263 /* Disable non-allocate hint of w-b-n-a memory type */
Bhupesh Sharma06a0f1d2015-05-28 14:54:13 +0530264 orr x0, x0, #1 << 49
Bhupesh Sharma80a7e352015-01-23 15:50:04 +0530265 /* Disable write streaming no L1-allocate threshold */
Bhupesh Sharma06a0f1d2015-05-28 14:54:13 +0530266 orr x0, x0, #3 << 25
Bhupesh Sharma80a7e352015-01-23 15:50:04 +0530267 /* Disable write streaming no-allocate threshold */
Bhupesh Sharma06a0f1d2015-05-28 14:54:13 +0530268 orr x0, x0, #3 << 27
Bhupesh Sharma80a7e352015-01-23 15:50:04 +0530269 msr S3_1_c15_c2_0, x0 /* cpuactlr_el1 */
Volodymyr Babchukb2b52252020-06-24 01:05:19 +0000270 isb
Bhupesh Sharma80a7e352015-01-23 15:50:04 +0530271#endif
272
273#ifdef CONFIG_ARM_ERRATA_826974
274 mrs x0, S3_1_c15_c2_0 /* cpuactlr_el1 */
275 /* Disable speculative load execution ahead of a DMB */
Bhupesh Sharma06a0f1d2015-05-28 14:54:13 +0530276 orr x0, x0, #1 << 59
Bhupesh Sharma80a7e352015-01-23 15:50:04 +0530277 msr S3_1_c15_c2_0, x0 /* cpuactlr_el1 */
Volodymyr Babchukb2b52252020-06-24 01:05:19 +0000278 isb
Bhupesh Sharma80a7e352015-01-23 15:50:04 +0530279#endif
280
Ashish kumar9c6d33c2016-01-27 18:09:32 +0530281#ifdef CONFIG_ARM_ERRATA_833471
282 mrs x0, S3_1_c15_c2_0 /* cpuactlr_el1 */
283 /* FPSCR write flush.
284 * Note that in some cases where a flush is unnecessary this
285 could impact performance. */
286 orr x0, x0, #1 << 38
287 msr S3_1_c15_c2_0, x0 /* cpuactlr_el1 */
Volodymyr Babchukb2b52252020-06-24 01:05:19 +0000288 isb
Ashish kumar9c6d33c2016-01-27 18:09:32 +0530289#endif
290
291#ifdef CONFIG_ARM_ERRATA_829520
292 mrs x0, S3_1_c15_c2_0 /* cpuactlr_el1 */
293 /* Disable Indirect Predictor bit will prevent this erratum
294 from occurring
295 * Note that in some cases where a flush is unnecessary this
296 could impact performance. */
297 orr x0, x0, #1 << 4
298 msr S3_1_c15_c2_0, x0 /* cpuactlr_el1 */
Volodymyr Babchukb2b52252020-06-24 01:05:19 +0000299 isb
Ashish kumar9c6d33c2016-01-27 18:09:32 +0530300#endif
301
Bhupesh Sharma80a7e352015-01-23 15:50:04 +0530302#ifdef CONFIG_ARM_ERRATA_833069
303 mrs x0, S3_1_c15_c2_0 /* cpuactlr_el1 */
304 /* Disable Enable Invalidates of BTB bit */
305 and x0, x0, #0xE
306 msr S3_1_c15_c2_0, x0 /* cpuactlr_el1 */
Volodymyr Babchukb2b52252020-06-24 01:05:19 +0000307 isb
Bhupesh Sharma80a7e352015-01-23 15:50:04 +0530308#endif
309 b 0b
310ENDPROC(apply_core_errata)
311
312/*-----------------------------------------------------------------------*/
313
David Feng85fd5f12013-12-14 11:47:35 +0800314WEAK(lowlevel_init)
David Feng85fd5f12013-12-14 11:47:35 +0800315 mov x29, lr /* Save LR */
David Feng85fd5f12013-12-14 11:47:35 +0800316
David Feng79bbde02014-03-14 14:26:27 +0800317#if defined(CONFIG_GICV2) || defined(CONFIG_GICV3)
318 branch_if_slave x0, 1f
319 ldr x0, =GICD_BASE
320 bl gic_init_secure
3211:
322#if defined(CONFIG_GICV3)
323 ldr x0, =GICR_BASE
324 bl gic_init_secure_percpu
325#elif defined(CONFIG_GICV2)
326 ldr x0, =GICD_BASE
327 ldr x1, =GICC_BASE
328 bl gic_init_secure_percpu
329#endif
Stephen Warren73f47af2016-04-28 12:45:44 -0600330#endif
David Feng79bbde02014-03-14 14:26:27 +0800331
Masahiro Yamadae4ce25f2016-05-20 12:13:10 +0900332#ifdef CONFIG_ARMV8_MULTIENTRY
David Feng79bbde02014-03-14 14:26:27 +0800333 branch_if_master x0, x1, 2f
David Feng85fd5f12013-12-14 11:47:35 +0800334
335 /*
336 * Slave should wait for master clearing spin table.
337 * This sync prevent salves observing incorrect
338 * value of spin table and jumping to wrong place.
339 */
David Feng79bbde02014-03-14 14:26:27 +0800340#if defined(CONFIG_GICV2) || defined(CONFIG_GICV3)
341#ifdef CONFIG_GICV2
342 ldr x0, =GICC_BASE
343#endif
344 bl gic_wait_for_interrupt
345#endif
David Feng85fd5f12013-12-14 11:47:35 +0800346
347 /*
David Feng79bbde02014-03-14 14:26:27 +0800348 * All slaves will enter EL2 and optionally EL1.
David Feng85fd5f12013-12-14 11:47:35 +0800349 */
Alison Wangeb2088d2017-01-17 09:39:17 +0800350 adr x4, lowlevel_in_el2
351 ldr x5, =ES_TO_AARCH64
David Feng85fd5f12013-12-14 11:47:35 +0800352 bl armv8_switch_to_el2
Alison Wang73818d52016-11-10 10:49:03 +0800353
354lowlevel_in_el2:
David Feng85fd5f12013-12-14 11:47:35 +0800355#ifdef CONFIG_ARMV8_SWITCH_TO_EL1
Alison Wangeb2088d2017-01-17 09:39:17 +0800356 adr x4, lowlevel_in_el1
357 ldr x5, =ES_TO_AARCH64
David Feng85fd5f12013-12-14 11:47:35 +0800358 bl armv8_switch_to_el1
Alison Wang73818d52016-11-10 10:49:03 +0800359
360lowlevel_in_el1:
David Feng85fd5f12013-12-14 11:47:35 +0800361#endif
362
Linus Walleij74771392015-03-09 10:53:21 +0100363#endif /* CONFIG_ARMV8_MULTIENTRY */
364
David Feng79bbde02014-03-14 14:26:27 +08003652:
David Feng85fd5f12013-12-14 11:47:35 +0800366 mov lr, x29 /* Restore LR */
367 ret
368ENDPROC(lowlevel_init)
369
David Feng79bbde02014-03-14 14:26:27 +0800370WEAK(smp_kick_all_cpus)
371 /* Kick secondary cpus up by SGI 0 interrupt */
David Feng79bbde02014-03-14 14:26:27 +0800372#if defined(CONFIG_GICV2) || defined(CONFIG_GICV3)
373 ldr x0, =GICD_BASE
Masahiro Yamadab9140092016-06-17 18:32:47 +0900374 b gic_kick_secondary_cpus
David Feng79bbde02014-03-14 14:26:27 +0800375#endif
David Feng79bbde02014-03-14 14:26:27 +0800376 ret
377ENDPROC(smp_kick_all_cpus)
378
David Feng85fd5f12013-12-14 11:47:35 +0800379/*-----------------------------------------------------------------------*/
380
381ENTRY(c_runtime_cpu_setup)
Alexander Grafb3e9dc62019-02-20 17:14:49 +0100382#if defined(CONFIG_ARMV8_SPL_EXCEPTION_VECTORS) || !defined(CONFIG_SPL_BUILD)
David Feng85fd5f12013-12-14 11:47:35 +0800383 /* Relocate vBAR */
384 adr x0, vectors
385 switch_el x1, 3f, 2f, 1f
3863: msr vbar_el3, x0
387 b 0f
3882: msr vbar_el2, x0
389 b 0f
3901: msr vbar_el1, x0
3910:
Andre Przywara4eecab72018-07-25 00:57:01 +0100392#endif
David Feng85fd5f12013-12-14 11:47:35 +0800393
394 ret
395ENDPROC(c_runtime_cpu_setup)
Stephen Warren100a4792016-07-18 17:01:50 -0600396
397WEAK(save_boot_params)
398 b save_boot_params_ret /* back to my caller */
399ENDPROC(save_boot_params)