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 mrs x0, S3_1_c15_c2_1 /* cpuectlr_el1 */
99 /* Apply ARM core specific erratas */
103 * Cache/BPB/TLB Invalidate
104 * i-cache is invalidated before enabled in icache_enable()
105 * tlb is invalidated before mmu is enabled in dcache_enable()
106 * d-cache is invalidated before enabled in dcache_enable()
109 /* Processor specific initialization */
112 #if defined(CONFIG_ARMV8_SPIN_TABLE) && !defined(CONFIG_SPL_BUILD)
113 branch_if_master x0, x1, master_cpu
114 b spin_table_secondary_jump
116 #elif defined(CONFIG_ARMV8_MULTIENTRY)
117 branch_if_master x0, x1, master_cpu
124 ldr x1, =CPU_RELEASE_ADDR
127 br x0 /* branch to the given address */
128 #endif /* CONFIG_ARMV8_MULTIENTRY */
132 #ifdef CONFIG_SYS_RESET_SCTRL
134 switch_el x1, 3f, 2f, 1f
148 switch_el x1, 6f, 5f, 4f
161 b __asm_invalidate_tlb_all
165 /*-----------------------------------------------------------------------*/
167 WEAK(apply_core_errata)
169 mov x29, lr /* Save LR */
170 /* For now, we support Cortex-A57 specific errata only */
172 /* Check if we are running on a Cortex-A57 core */
173 branch_if_a57_core x0, apply_a57_core_errata
175 mov lr, x29 /* Restore LR */
178 apply_a57_core_errata:
180 #ifdef CONFIG_ARM_ERRATA_828024
181 mrs x0, S3_1_c15_c2_0 /* cpuactlr_el1 */
182 /* Disable non-allocate hint of w-b-n-a memory type */
184 /* Disable write streaming no L1-allocate threshold */
186 /* Disable write streaming no-allocate threshold */
188 msr S3_1_c15_c2_0, x0 /* cpuactlr_el1 */
191 #ifdef CONFIG_ARM_ERRATA_826974
192 mrs x0, S3_1_c15_c2_0 /* cpuactlr_el1 */
193 /* Disable speculative load execution ahead of a DMB */
195 msr S3_1_c15_c2_0, x0 /* cpuactlr_el1 */
198 #ifdef CONFIG_ARM_ERRATA_833471
199 mrs x0, S3_1_c15_c2_0 /* cpuactlr_el1 */
200 /* FPSCR write flush.
201 * Note that in some cases where a flush is unnecessary this
202 could impact performance. */
204 msr S3_1_c15_c2_0, x0 /* cpuactlr_el1 */
207 #ifdef CONFIG_ARM_ERRATA_829520
208 mrs x0, S3_1_c15_c2_0 /* cpuactlr_el1 */
209 /* Disable Indirect Predictor bit will prevent this erratum
211 * Note that in some cases where a flush is unnecessary this
212 could impact performance. */
214 msr S3_1_c15_c2_0, x0 /* cpuactlr_el1 */
217 #ifdef CONFIG_ARM_ERRATA_833069
218 mrs x0, S3_1_c15_c2_0 /* cpuactlr_el1 */
219 /* Disable Enable Invalidates of BTB bit */
221 msr S3_1_c15_c2_0, x0 /* cpuactlr_el1 */
224 ENDPROC(apply_core_errata)
226 /*-----------------------------------------------------------------------*/
229 mov x29, lr /* Save LR */
231 #if defined(CONFIG_GICV2) || defined(CONFIG_GICV3)
232 branch_if_slave x0, 1f
236 #if defined(CONFIG_GICV3)
238 bl gic_init_secure_percpu
239 #elif defined(CONFIG_GICV2)
242 bl gic_init_secure_percpu
246 #ifdef CONFIG_ARMV8_MULTIENTRY
247 branch_if_master x0, x1, 2f
250 * Slave should wait for master clearing spin table.
251 * This sync prevent salves observing incorrect
252 * value of spin table and jumping to wrong place.
254 #if defined(CONFIG_GICV2) || defined(CONFIG_GICV3)
258 bl gic_wait_for_interrupt
262 * All slaves will enter EL2 and optionally EL1.
264 adr x4, lowlevel_in_el2
265 ldr x5, =ES_TO_AARCH64
266 bl armv8_switch_to_el2
269 #ifdef CONFIG_ARMV8_SWITCH_TO_EL1
270 adr x4, lowlevel_in_el1
271 ldr x5, =ES_TO_AARCH64
272 bl armv8_switch_to_el1
277 #endif /* CONFIG_ARMV8_MULTIENTRY */
280 mov lr, x29 /* Restore LR */
282 ENDPROC(lowlevel_init)
284 WEAK(smp_kick_all_cpus)
285 /* Kick secondary cpus up by SGI 0 interrupt */
286 #if defined(CONFIG_GICV2) || defined(CONFIG_GICV3)
288 b gic_kick_secondary_cpus
291 ENDPROC(smp_kick_all_cpus)
293 /*-----------------------------------------------------------------------*/
295 ENTRY(c_runtime_cpu_setup)
298 switch_el x1, 3f, 2f, 1f
307 ENDPROC(c_runtime_cpu_setup)
309 WEAK(save_boot_params)
310 b save_boot_params_ret /* back to my caller */
311 ENDPROC(save_boot_params)