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 #if CONFIG_IS_ENABLED(ARMV8_SPIN_TABLE)
98 branch_if_master x0, x1, master_cpu
99 b spin_table_secondary_jump
101 #elif defined(CONFIG_ARMV8_MULTIENTRY)
102 branch_if_master x0, x1, master_cpu
109 ldr x1, =CPU_RELEASE_ADDR
112 br x0 /* branch to the given address */
113 #endif /* CONFIG_ARMV8_MULTIENTRY */
117 #ifdef CONFIG_SYS_RESET_SCTRL
119 switch_el x1, 3f, 2f, 1f
133 switch_el x1, 6f, 5f, 4f
146 b __asm_invalidate_tlb_all
150 /*-----------------------------------------------------------------------*/
152 WEAK(apply_core_errata)
154 mov x29, lr /* Save LR */
155 /* For now, we support Cortex-A57 specific errata only */
157 /* Check if we are running on a Cortex-A57 core */
158 branch_if_a57_core x0, apply_a57_core_errata
160 mov lr, x29 /* Restore LR */
163 apply_a57_core_errata:
165 #ifdef CONFIG_ARM_ERRATA_828024
166 mrs x0, S3_1_c15_c2_0 /* cpuactlr_el1 */
167 /* Disable non-allocate hint of w-b-n-a memory type */
169 /* Disable write streaming no L1-allocate threshold */
171 /* Disable write streaming no-allocate threshold */
173 msr S3_1_c15_c2_0, x0 /* cpuactlr_el1 */
176 #ifdef CONFIG_ARM_ERRATA_826974
177 mrs x0, S3_1_c15_c2_0 /* cpuactlr_el1 */
178 /* Disable speculative load execution ahead of a DMB */
180 msr S3_1_c15_c2_0, x0 /* cpuactlr_el1 */
183 #ifdef CONFIG_ARM_ERRATA_833471
184 mrs x0, S3_1_c15_c2_0 /* cpuactlr_el1 */
185 /* FPSCR write flush.
186 * Note that in some cases where a flush is unnecessary this
187 could impact performance. */
189 msr S3_1_c15_c2_0, x0 /* cpuactlr_el1 */
192 #ifdef CONFIG_ARM_ERRATA_829520
193 mrs x0, S3_1_c15_c2_0 /* cpuactlr_el1 */
194 /* Disable Indirect Predictor bit will prevent this erratum
196 * Note that in some cases where a flush is unnecessary this
197 could impact performance. */
199 msr S3_1_c15_c2_0, x0 /* cpuactlr_el1 */
202 #ifdef CONFIG_ARM_ERRATA_833069
203 mrs x0, S3_1_c15_c2_0 /* cpuactlr_el1 */
204 /* Disable Enable Invalidates of BTB bit */
206 msr S3_1_c15_c2_0, x0 /* cpuactlr_el1 */
209 ENDPROC(apply_core_errata)
211 /*-----------------------------------------------------------------------*/
214 mov x29, lr /* Save LR */
216 #if defined(CONFIG_GICV2) || defined(CONFIG_GICV3)
217 branch_if_slave x0, 1f
221 #if defined(CONFIG_GICV3)
223 bl gic_init_secure_percpu
224 #elif defined(CONFIG_GICV2)
227 bl gic_init_secure_percpu
231 #ifdef CONFIG_ARMV8_MULTIENTRY
232 branch_if_master x0, x1, 2f
235 * Slave should wait for master clearing spin table.
236 * This sync prevent salves observing incorrect
237 * value of spin table and jumping to wrong place.
239 #if defined(CONFIG_GICV2) || defined(CONFIG_GICV3)
243 bl gic_wait_for_interrupt
247 * All slaves will enter EL2 and optionally EL1.
249 bl armv8_switch_to_el2
250 #ifdef CONFIG_ARMV8_SWITCH_TO_EL1
251 bl armv8_switch_to_el1
254 #endif /* CONFIG_ARMV8_MULTIENTRY */
257 mov lr, x29 /* Restore LR */
259 ENDPROC(lowlevel_init)
261 WEAK(smp_kick_all_cpus)
262 /* Kick secondary cpus up by SGI 0 interrupt */
263 #if defined(CONFIG_GICV2) || defined(CONFIG_GICV3)
265 b gic_kick_secondary_cpus
268 ENDPROC(smp_kick_all_cpus)
270 /*-----------------------------------------------------------------------*/
272 ENTRY(c_runtime_cpu_setup)
275 switch_el x1, 3f, 2f, 1f
284 ENDPROC(c_runtime_cpu_setup)