3 * David Feng <fenghua@phytium.com.cn>
5 * SPDX-License-Identifier: GPL-2.0+
8 #include <asm-offsets.h>
10 #include <linux/linkage.h>
11 #include <asm/macro.h>
12 #include <asm/armv8/mmu.h>
14 /*************************************************************************
16 * Startup Code (reset vector)
18 *************************************************************************/
24 #ifdef CONFIG_ENABLE_ARM_SOC_BOOT0_HOOK
26 * Various SoCs need something special and SoC-specific up front in
27 * order to boot, allow them to set that in their boot0.h file and then
30 #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 #ifdef CONFIG_SYS_RESET_SCTRL
60 * Could be EL3/EL2/EL1, Initial State:
61 * Little Endian, MMU Disabled, i/dCache Disabled
64 switch_el x1, 3f, 2f, 1f
67 orr x0, x0, #0xf /* SCR_EL3.NS|IRQ|FIQ|EA */
69 msr cptr_el3, xzr /* Enable FP/SIMD */
70 #ifdef COUNTER_FREQUENCY
71 ldr x0, =COUNTER_FREQUENCY
72 msr cntfrq_el0, x0 /* Initialize CNTFRQ */
77 msr cptr_el2, x0 /* Enable FP/SIMD */
81 msr cpacr_el1, x0 /* Enable FP/SIMD */
84 /* Apply ARM core specific erratas */
88 * Cache/BPB/TLB Invalidate
89 * i-cache is invalidated before enabled in icache_enable()
90 * tlb is invalidated before mmu is enabled in dcache_enable()
91 * d-cache is invalidated before enabled in dcache_enable()
94 /* Processor specific initialization */
97 #ifdef CONFIG_ARMV8_MULTIENTRY
98 branch_if_master x0, x1, master_cpu
105 ldr x1, =CPU_RELEASE_ADDR
108 br x0 /* branch to the given address */
110 /* On the master CPU */
111 #endif /* CONFIG_ARMV8_MULTIENTRY */
115 #ifdef CONFIG_SYS_RESET_SCTRL
117 switch_el x1, 3f, 2f, 1f
131 switch_el x1, 6f, 5f, 4f
144 b __asm_invalidate_tlb_all
148 /*-----------------------------------------------------------------------*/
150 WEAK(apply_core_errata)
152 mov x29, lr /* Save LR */
153 /* For now, we support Cortex-A57 specific errata only */
155 /* Check if we are running on a Cortex-A57 core */
156 branch_if_a57_core x0, apply_a57_core_errata
158 mov lr, x29 /* Restore LR */
161 apply_a57_core_errata:
163 #ifdef CONFIG_ARM_ERRATA_828024
164 mrs x0, S3_1_c15_c2_0 /* cpuactlr_el1 */
165 /* Disable non-allocate hint of w-b-n-a memory type */
167 /* Disable write streaming no L1-allocate threshold */
169 /* Disable write streaming no-allocate threshold */
171 msr S3_1_c15_c2_0, x0 /* cpuactlr_el1 */
174 #ifdef CONFIG_ARM_ERRATA_826974
175 mrs x0, S3_1_c15_c2_0 /* cpuactlr_el1 */
176 /* Disable speculative load execution ahead of a DMB */
178 msr S3_1_c15_c2_0, x0 /* cpuactlr_el1 */
181 #ifdef CONFIG_ARM_ERRATA_833471
182 mrs x0, S3_1_c15_c2_0 /* cpuactlr_el1 */
183 /* FPSCR write flush.
184 * Note that in some cases where a flush is unnecessary this
185 could impact performance. */
187 msr S3_1_c15_c2_0, x0 /* cpuactlr_el1 */
190 #ifdef CONFIG_ARM_ERRATA_829520
191 mrs x0, S3_1_c15_c2_0 /* cpuactlr_el1 */
192 /* Disable Indirect Predictor bit will prevent this erratum
194 * Note that in some cases where a flush is unnecessary this
195 could impact performance. */
197 msr S3_1_c15_c2_0, x0 /* cpuactlr_el1 */
200 #ifdef CONFIG_ARM_ERRATA_833069
201 mrs x0, S3_1_c15_c2_0 /* cpuactlr_el1 */
202 /* Disable Enable Invalidates of BTB bit */
204 msr S3_1_c15_c2_0, x0 /* cpuactlr_el1 */
207 ENDPROC(apply_core_errata)
209 /*-----------------------------------------------------------------------*/
212 mov x29, lr /* Save LR */
214 #if defined(CONFIG_GICV2) || defined(CONFIG_GICV3)
215 branch_if_slave x0, 1f
219 #if defined(CONFIG_GICV3)
221 bl gic_init_secure_percpu
222 #elif defined(CONFIG_GICV2)
225 bl gic_init_secure_percpu
229 #ifdef CONFIG_ARMV8_MULTIENTRY
230 branch_if_master x0, x1, 2f
233 * Slave should wait for master clearing spin table.
234 * This sync prevent salves observing incorrect
235 * value of spin table and jumping to wrong place.
237 #if defined(CONFIG_GICV2) || defined(CONFIG_GICV3)
241 bl gic_wait_for_interrupt
245 * All slaves will enter EL2 and optionally EL1.
247 bl armv8_switch_to_el2
248 #ifdef CONFIG_ARMV8_SWITCH_TO_EL1
249 bl armv8_switch_to_el1
252 #endif /* CONFIG_ARMV8_MULTIENTRY */
255 mov lr, x29 /* Restore LR */
257 ENDPROC(lowlevel_init)
259 WEAK(smp_kick_all_cpus)
260 /* Kick secondary cpus up by SGI 0 interrupt */
261 #if defined(CONFIG_GICV2) || defined(CONFIG_GICV3)
263 b gic_kick_secondary_cpus
266 ENDPROC(smp_kick_all_cpus)
268 /*-----------------------------------------------------------------------*/
270 ENTRY(c_runtime_cpu_setup)
273 switch_el x1, 3f, 2f, 1f
282 ENDPROC(c_runtime_cpu_setup)