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 *************************************************************************/
28 .quad CONFIG_SYS_TEXT_BASE
31 * These are defined in the linker script.
39 .quad __bss_start - _start
43 .quad __bss_end - _start
46 #ifdef CONFIG_SYS_RESET_SCTRL
50 * Could be EL3/EL2/EL1, Initial State:
51 * Little Endian, MMU Disabled, i/dCache Disabled
54 switch_el x1, 3f, 2f, 1f
57 orr x0, x0, #0xf /* SCR_EL3.NS|IRQ|FIQ|EA */
59 msr cptr_el3, xzr /* Enable FP/SIMD */
60 #ifdef COUNTER_FREQUENCY
61 ldr x0, =COUNTER_FREQUENCY
62 msr cntfrq_el0, x0 /* Initialize CNTFRQ */
67 msr cptr_el2, x0 /* Enable FP/SIMD */
71 msr cpacr_el1, x0 /* Enable FP/SIMD */
74 /* Apply ARM core specific erratas */
78 * Cache/BPB/TLB Invalidate
79 * i-cache is invalidated before enabled in icache_enable()
80 * tlb is invalidated before mmu is enabled in dcache_enable()
81 * d-cache is invalidated before enabled in dcache_enable()
84 /* Processor specific initialization */
87 #ifdef CONFIG_ARMV8_MULTIENTRY
88 branch_if_master x0, x1, master_cpu
95 ldr x1, =CPU_RELEASE_ADDR
98 br x0 /* branch to the given address */
100 /* On the master CPU */
101 #endif /* CONFIG_ARMV8_MULTIENTRY */
105 #ifdef CONFIG_SYS_RESET_SCTRL
107 switch_el x1, 3f, 2f, 1f
121 switch_el x1, 6f, 5f, 4f
134 b __asm_invalidate_tlb_all
138 /*-----------------------------------------------------------------------*/
140 WEAK(apply_core_errata)
142 mov x29, lr /* Save LR */
143 /* For now, we support Cortex-A57 specific errata only */
145 /* Check if we are running on a Cortex-A57 core */
146 branch_if_a57_core x0, apply_a57_core_errata
148 mov lr, x29 /* Restore LR */
151 apply_a57_core_errata:
153 #ifdef CONFIG_ARM_ERRATA_828024
154 mrs x0, S3_1_c15_c2_0 /* cpuactlr_el1 */
155 /* Disable non-allocate hint of w-b-n-a memory type */
157 /* Disable write streaming no L1-allocate threshold */
159 /* Disable write streaming no-allocate threshold */
161 msr S3_1_c15_c2_0, x0 /* cpuactlr_el1 */
164 #ifdef CONFIG_ARM_ERRATA_826974
165 mrs x0, S3_1_c15_c2_0 /* cpuactlr_el1 */
166 /* Disable speculative load execution ahead of a DMB */
168 msr S3_1_c15_c2_0, x0 /* cpuactlr_el1 */
171 #ifdef CONFIG_ARM_ERRATA_833471
172 mrs x0, S3_1_c15_c2_0 /* cpuactlr_el1 */
173 /* FPSCR write flush.
174 * Note that in some cases where a flush is unnecessary this
175 could impact performance. */
177 msr S3_1_c15_c2_0, x0 /* cpuactlr_el1 */
180 #ifdef CONFIG_ARM_ERRATA_829520
181 mrs x0, S3_1_c15_c2_0 /* cpuactlr_el1 */
182 /* Disable Indirect Predictor bit will prevent this erratum
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_833069
191 mrs x0, S3_1_c15_c2_0 /* cpuactlr_el1 */
192 /* Disable Enable Invalidates of BTB bit */
194 msr S3_1_c15_c2_0, x0 /* cpuactlr_el1 */
197 ENDPROC(apply_core_errata)
199 /*-----------------------------------------------------------------------*/
202 mov x29, lr /* Save LR */
204 #if defined(CONFIG_GICV2) || defined(CONFIG_GICV3)
205 branch_if_slave x0, 1f
209 #if defined(CONFIG_GICV3)
211 bl gic_init_secure_percpu
212 #elif defined(CONFIG_GICV2)
215 bl gic_init_secure_percpu
219 #ifndef CONFIG_ARMV8_MULTIENTRY
220 branch_if_master x0, x1, 2f
223 * Slave should wait for master clearing spin table.
224 * This sync prevent salves observing incorrect
225 * value of spin table and jumping to wrong place.
227 #if defined(CONFIG_GICV2) || defined(CONFIG_GICV3)
231 bl gic_wait_for_interrupt
235 * All slaves will enter EL2 and optionally EL1.
237 bl armv8_switch_to_el2
238 #ifdef CONFIG_ARMV8_SWITCH_TO_EL1
239 bl armv8_switch_to_el1
242 #endif /* CONFIG_ARMV8_MULTIENTRY */
245 mov lr, x29 /* Restore LR */
247 ENDPROC(lowlevel_init)
249 WEAK(smp_kick_all_cpus)
250 /* Kick secondary cpus up by SGI 0 interrupt */
251 mov x29, lr /* Save LR */
252 #if defined(CONFIG_GICV2) || defined(CONFIG_GICV3)
254 bl gic_kick_secondary_cpus
256 mov lr, x29 /* Restore LR */
258 ENDPROC(smp_kick_all_cpus)
260 /*-----------------------------------------------------------------------*/
262 ENTRY(c_runtime_cpu_setup)
265 switch_el x1, 3f, 2f, 1f
274 ENDPROC(c_runtime_cpu_setup)