1 /* SPDX-License-Identifier: GPL-2.0+ */
4 * David Feng <fenghua@phytium.com.cn>
7 #include <asm-offsets.h>
9 #include <linux/linkage.h>
10 #include <asm/macro.h>
11 #include <asm/armv8/mmu.h>
13 /*************************************************************************
15 * Startup Code (reset vector)
17 *************************************************************************/
21 #if defined(CONFIG_LINUX_KERNEL_IMAGE_HEADER)
22 #include <asm/boot0-linux-kernel-header.h>
23 #elif defined(CONFIG_ENABLE_ARM_SOC_BOOT0_HOOK)
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
29 #include <asm/arch/boot0.h>
38 .quad CONFIG_SYS_TEXT_BASE
41 * These are defined in the linker script.
49 .quad __bss_start - _start
53 .quad __bss_end - _start
56 /* Allow the board to save important registers */
58 .globl save_boot_params_ret
61 #if CONFIG_POSITION_INDEPENDENT
62 /* Verify that we're 4K aligned. */
68 * FATAL, can't continue.
69 * U-Boot needs to be loaded at a 4K aligned address.
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.
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.
84 adr x0, _start /* x0 <- Runtime value of _start */
85 ldr x1, _TEXT_BASE /* x1 <- Linked value of _start */
86 subs x9, x0, x1 /* x9 <- Run-vs-link offset */
88 adrp x2, __rel_dyn_start /* x2 <- Runtime &__rel_dyn_start */
89 add x2, x2, #:lo12:__rel_dyn_start
90 adrp x3, __rel_dyn_end /* x3 <- Runtime &__rel_dyn_end */
91 add x3, x3, #:lo12:__rel_dyn_end
93 ldp x0, x1, [x2], #16 /* (x0, x1) <- (Link location, fixup) */
94 ldr x4, [x2], #8 /* x4 <- addend */
95 cmp w1, #1027 /* relative fixup? */
97 /* relative fix: store addend plus offset at dest location */
107 #if defined(CONFIG_ARMV8_SPL_EXCEPTION_VECTORS) || !defined(CONFIG_SPL_BUILD)
108 .macro set_vbar, regname, reg
113 .macro set_vbar, regname, reg
117 * Could be EL3/EL2/EL1, Initial State:
118 * Little Endian, MMU Disabled, i/dCache Disabled
120 switch_el x1, 3f, 2f, 1f
121 3: set_vbar vbar_el3, x0
123 orr x0, x0, #0xf /* SCR_EL3.NS|IRQ|FIQ|EA */
125 msr cptr_el3, xzr /* Enable FP/SIMD */
128 tbnz x1, #34, 1f /* HCR_EL2.E2H */
129 orr x1, x1, #HCR_EL2_AMO_EL2 /* Route SErrors to EL2 */
131 set_vbar vbar_el2, x0
133 msr cptr_el2, x0 /* Enable FP/SIMD */
135 1: set_vbar vbar_el1, x0
137 msr cpacr_el1, x0 /* Enable FP/SIMD */
139 msr daifclr, #0x4 /* Unmask SError interrupts */
141 #if CONFIG_COUNTER_FREQUENCY
142 branch_if_not_highest_el x0, 4f
143 ldr x0, =CONFIG_COUNTER_FREQUENCY
144 msr cntfrq_el0, x0 /* Initialize CNTFRQ */
150 * Enable SMPEN bit for coherency.
151 * This register is not architectural but at the moment
152 * this bit should be set for A53/A57/A72.
154 #ifdef CONFIG_ARMV8_SET_SMPEN
155 switch_el x1, 3f, 1f, 1f
157 mrs x0, S3_1_c15_c2_1 /* cpuectlr_el1 */
159 msr S3_1_c15_c2_1, x0
164 /* Apply ARM core specific erratas */
168 * Cache/BPB/TLB Invalidate
169 * i-cache is invalidated before enabled in icache_enable()
170 * tlb is invalidated before mmu is enabled in dcache_enable()
171 * d-cache is invalidated before enabled in dcache_enable()
174 /* Processor specific initialization */
177 #if defined(CONFIG_ARMV8_SPIN_TABLE) && !defined(CONFIG_SPL_BUILD)
178 branch_if_master x0, master_cpu
179 b spin_table_secondary_jump
181 #elif defined(CONFIG_ARMV8_MULTIENTRY)
182 branch_if_master x0, master_cpu
189 ldr x1, =CPU_RELEASE_ADDR
192 br x0 /* branch to the given address */
193 #endif /* CONFIG_ARMV8_MULTIENTRY */
195 msr SPSel, #1 /* make sure we use SP_ELx */
198 /*-----------------------------------------------------------------------*/
200 WEAK(apply_core_errata)
202 mov x29, lr /* Save LR */
203 /* For now, we support Cortex-A53, Cortex-A57 specific errata */
205 /* Check if we are running on a Cortex-A53 core */
206 branch_if_a53_core x0, apply_a53_core_errata
208 /* Check if we are running on a Cortex-A57 core */
209 branch_if_a57_core x0, apply_a57_core_errata
211 mov lr, x29 /* Restore LR */
214 apply_a53_core_errata:
216 #ifdef CONFIG_ARM_ERRATA_855873
226 mrs x0, S3_1_c15_c2_0 /* cpuactlr_el1 */
227 /* Enable data cache clean as data cache clean/invalidate */
229 msr S3_1_c15_c2_0, x0 /* cpuactlr_el1 */
234 apply_a57_core_errata:
236 #ifdef CONFIG_ARM_ERRATA_828024
237 mrs x0, S3_1_c15_c2_0 /* cpuactlr_el1 */
238 /* Disable non-allocate hint of w-b-n-a memory type */
240 /* Disable write streaming no L1-allocate threshold */
242 /* Disable write streaming no-allocate threshold */
244 msr S3_1_c15_c2_0, x0 /* cpuactlr_el1 */
248 #ifdef CONFIG_ARM_ERRATA_826974
249 mrs x0, S3_1_c15_c2_0 /* cpuactlr_el1 */
250 /* Disable speculative load execution ahead of a DMB */
252 msr S3_1_c15_c2_0, x0 /* cpuactlr_el1 */
256 #ifdef CONFIG_ARM_ERRATA_833471
257 mrs x0, S3_1_c15_c2_0 /* cpuactlr_el1 */
258 /* FPSCR write flush.
259 * Note that in some cases where a flush is unnecessary this
260 could impact performance. */
262 msr S3_1_c15_c2_0, x0 /* cpuactlr_el1 */
266 #ifdef CONFIG_ARM_ERRATA_829520
267 mrs x0, S3_1_c15_c2_0 /* cpuactlr_el1 */
268 /* Disable Indirect Predictor bit will prevent this erratum
270 * Note that in some cases where a flush is unnecessary this
271 could impact performance. */
273 msr S3_1_c15_c2_0, x0 /* cpuactlr_el1 */
277 #ifdef CONFIG_ARM_ERRATA_833069
278 mrs x0, S3_1_c15_c2_0 /* cpuactlr_el1 */
279 /* Disable Enable Invalidates of BTB bit */
281 msr S3_1_c15_c2_0, x0 /* cpuactlr_el1 */
285 ENDPROC(apply_core_errata)
287 /*-----------------------------------------------------------------------*/
290 mov x29, lr /* Save LR */
292 #if defined(CONFIG_GICV2) || defined(CONFIG_GICV3)
293 branch_if_slave x0, 1f
297 #if defined(CONFIG_GICV3)
299 bl gic_init_secure_percpu
300 #elif defined(CONFIG_GICV2)
303 bl gic_init_secure_percpu
307 #ifdef CONFIG_ARMV8_MULTIENTRY
308 branch_if_master x0, 2f
311 * Slave should wait for master clearing spin table.
312 * This sync prevent salves observing incorrect
313 * value of spin table and jumping to wrong place.
315 #if defined(CONFIG_GICV2) || defined(CONFIG_GICV3)
319 bl gic_wait_for_interrupt
323 * All slaves will enter EL2 and optionally EL1.
325 adr x4, lowlevel_in_el2
326 ldr x5, =ES_TO_AARCH64
327 bl armv8_switch_to_el2
330 #ifdef CONFIG_ARMV8_SWITCH_TO_EL1
331 adr x4, lowlevel_in_el1
332 ldr x5, =ES_TO_AARCH64
333 bl armv8_switch_to_el1
338 #endif /* CONFIG_ARMV8_MULTIENTRY */
341 mov lr, x29 /* Restore LR */
343 ENDPROC(lowlevel_init)
345 WEAK(smp_kick_all_cpus)
346 /* Kick secondary cpus up by SGI 0 interrupt */
347 #if defined(CONFIG_GICV2) || defined(CONFIG_GICV3)
349 b gic_kick_secondary_cpus
352 ENDPROC(smp_kick_all_cpus)
354 /*-----------------------------------------------------------------------*/
356 ENTRY(c_runtime_cpu_setup)
357 #if defined(CONFIG_ARMV8_SPL_EXCEPTION_VECTORS) || !defined(CONFIG_SPL_BUILD)
360 switch_el x1, 3f, 2f, 1f
370 ENDPROC(c_runtime_cpu_setup)
372 WEAK(save_boot_params)
373 b save_boot_params_ret /* back to my caller */
374 ENDPROC(save_boot_params)