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 *************************************************************************/
22 #ifdef CONFIG_ENABLE_ARM_SOC_BOOT0_HOOK
24 * Various SoCs need something special and SoC-specific up front in
25 * order to boot, allow them to set that in their boot0.h file and then
28 #include <asm/arch/boot0.h>
37 .quad CONFIG_SYS_TEXT_BASE
40 * These are defined in the linker script.
48 .quad __bss_start - _start
52 .quad __bss_end - _start
55 /* Allow the board to save important registers */
57 .globl save_boot_params_ret
60 #ifdef CONFIG_SYS_RESET_SCTRL
64 * Could be EL3/EL2/EL1, Initial State:
65 * Little Endian, MMU Disabled, i/dCache Disabled
68 switch_el x1, 3f, 2f, 1f
71 orr x0, x0, #0xf /* SCR_EL3.NS|IRQ|FIQ|EA */
73 msr cptr_el3, xzr /* Enable FP/SIMD */
74 #ifdef COUNTER_FREQUENCY
75 ldr x0, =COUNTER_FREQUENCY
76 msr cntfrq_el0, x0 /* Initialize CNTFRQ */
81 msr cptr_el2, x0 /* Enable FP/SIMD */
85 msr cpacr_el1, x0 /* Enable FP/SIMD */
89 * Enable SMPEN bit for coherency.
90 * This register is not architectural but at the moment
91 * this bit should be set for A53/A57/A72.
93 #ifdef CONFIG_ARMV8_SET_SMPEN
94 switch_el x1, 3f, 1f, 1f
96 mrs x0, S3_1_c15_c2_1 /* cpuectlr_el1 */
102 /* Apply ARM core specific erratas */
106 * Cache/BPB/TLB Invalidate
107 * i-cache is invalidated before enabled in icache_enable()
108 * tlb is invalidated before mmu is enabled in dcache_enable()
109 * d-cache is invalidated before enabled in dcache_enable()
112 /* Processor specific initialization */
115 #if defined(CONFIG_ARMV8_SPIN_TABLE) && !defined(CONFIG_SPL_BUILD)
116 branch_if_master x0, x1, master_cpu
117 b spin_table_secondary_jump
119 #elif defined(CONFIG_ARMV8_MULTIENTRY)
120 branch_if_master x0, x1, master_cpu
127 ldr x1, =CPU_RELEASE_ADDR
130 br x0 /* branch to the given address */
131 #endif /* CONFIG_ARMV8_MULTIENTRY */
135 #ifdef CONFIG_SYS_RESET_SCTRL
137 switch_el x1, 3f, 2f, 1f
151 switch_el x1, 6f, 5f, 4f
164 b __asm_invalidate_tlb_all
168 /*-----------------------------------------------------------------------*/
170 WEAK(apply_core_errata)
172 mov x29, lr /* Save LR */
173 /* For now, we support Cortex-A57 specific errata only */
175 /* Check if we are running on a Cortex-A57 core */
176 branch_if_a57_core x0, apply_a57_core_errata
178 mov lr, x29 /* Restore LR */
181 apply_a57_core_errata:
183 #ifdef CONFIG_ARM_ERRATA_828024
184 mrs x0, S3_1_c15_c2_0 /* cpuactlr_el1 */
185 /* Disable non-allocate hint of w-b-n-a memory type */
187 /* Disable write streaming no L1-allocate threshold */
189 /* Disable write streaming no-allocate threshold */
191 msr S3_1_c15_c2_0, x0 /* cpuactlr_el1 */
194 #ifdef CONFIG_ARM_ERRATA_826974
195 mrs x0, S3_1_c15_c2_0 /* cpuactlr_el1 */
196 /* Disable speculative load execution ahead of a DMB */
198 msr S3_1_c15_c2_0, x0 /* cpuactlr_el1 */
201 #ifdef CONFIG_ARM_ERRATA_833471
202 mrs x0, S3_1_c15_c2_0 /* cpuactlr_el1 */
203 /* FPSCR write flush.
204 * Note that in some cases where a flush is unnecessary this
205 could impact performance. */
207 msr S3_1_c15_c2_0, x0 /* cpuactlr_el1 */
210 #ifdef CONFIG_ARM_ERRATA_829520
211 mrs x0, S3_1_c15_c2_0 /* cpuactlr_el1 */
212 /* Disable Indirect Predictor bit will prevent this erratum
214 * Note that in some cases where a flush is unnecessary this
215 could impact performance. */
217 msr S3_1_c15_c2_0, x0 /* cpuactlr_el1 */
220 #ifdef CONFIG_ARM_ERRATA_833069
221 mrs x0, S3_1_c15_c2_0 /* cpuactlr_el1 */
222 /* Disable Enable Invalidates of BTB bit */
224 msr S3_1_c15_c2_0, x0 /* cpuactlr_el1 */
227 ENDPROC(apply_core_errata)
229 /*-----------------------------------------------------------------------*/
232 mov x29, lr /* Save LR */
234 #if defined(CONFIG_GICV2) || defined(CONFIG_GICV3)
235 branch_if_slave x0, 1f
239 #if defined(CONFIG_GICV3)
241 bl gic_init_secure_percpu
242 #elif defined(CONFIG_GICV2)
245 bl gic_init_secure_percpu
249 #ifdef CONFIG_ARMV8_MULTIENTRY
250 branch_if_master x0, x1, 2f
253 * Slave should wait for master clearing spin table.
254 * This sync prevent salves observing incorrect
255 * value of spin table and jumping to wrong place.
257 #if defined(CONFIG_GICV2) || defined(CONFIG_GICV3)
261 bl gic_wait_for_interrupt
265 * All slaves will enter EL2 and optionally EL1.
267 adr x4, lowlevel_in_el2
268 ldr x5, =ES_TO_AARCH64
269 bl armv8_switch_to_el2
272 #ifdef CONFIG_ARMV8_SWITCH_TO_EL1
273 adr x4, lowlevel_in_el1
274 ldr x5, =ES_TO_AARCH64
275 bl armv8_switch_to_el1
280 #endif /* CONFIG_ARMV8_MULTIENTRY */
283 mov lr, x29 /* Restore LR */
285 ENDPROC(lowlevel_init)
287 WEAK(smp_kick_all_cpus)
288 /* Kick secondary cpus up by SGI 0 interrupt */
289 #if defined(CONFIG_GICV2) || defined(CONFIG_GICV3)
291 b gic_kick_secondary_cpus
294 ENDPROC(smp_kick_all_cpus)
296 /*-----------------------------------------------------------------------*/
298 ENTRY(c_runtime_cpu_setup)
301 switch_el x1, 3f, 2f, 1f
310 ENDPROC(c_runtime_cpu_setup)
312 WEAK(save_boot_params)
313 b save_boot_params_ret /* back to my caller */
314 ENDPROC(save_boot_params)