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 */
88 /* Apply ARM core specific erratas */
92 * Cache/BPB/TLB Invalidate
93 * i-cache is invalidated before enabled in icache_enable()
94 * tlb is invalidated before mmu is enabled in dcache_enable()
95 * d-cache is invalidated before enabled in dcache_enable()
98 /* Processor specific initialization */
101 #if defined(CONFIG_ARMV8_SPIN_TABLE) && !defined(CONFIG_SPL_BUILD)
102 branch_if_master x0, x1, master_cpu
103 b spin_table_secondary_jump
105 #elif defined(CONFIG_ARMV8_MULTIENTRY)
106 branch_if_master x0, x1, master_cpu
113 ldr x1, =CPU_RELEASE_ADDR
116 br x0 /* branch to the given address */
117 #endif /* CONFIG_ARMV8_MULTIENTRY */
121 #ifdef CONFIG_SYS_RESET_SCTRL
123 switch_el x1, 3f, 2f, 1f
137 switch_el x1, 6f, 5f, 4f
150 b __asm_invalidate_tlb_all
154 /*-----------------------------------------------------------------------*/
156 WEAK(apply_core_errata)
158 mov x29, lr /* Save LR */
159 /* For now, we support Cortex-A57 specific errata only */
161 /* Check if we are running on a Cortex-A57 core */
162 branch_if_a57_core x0, apply_a57_core_errata
164 mov lr, x29 /* Restore LR */
167 apply_a57_core_errata:
169 #ifdef CONFIG_ARM_ERRATA_828024
170 mrs x0, S3_1_c15_c2_0 /* cpuactlr_el1 */
171 /* Disable non-allocate hint of w-b-n-a memory type */
173 /* Disable write streaming no L1-allocate threshold */
175 /* Disable write streaming no-allocate threshold */
177 msr S3_1_c15_c2_0, x0 /* cpuactlr_el1 */
180 #ifdef CONFIG_ARM_ERRATA_826974
181 mrs x0, S3_1_c15_c2_0 /* cpuactlr_el1 */
182 /* Disable speculative load execution ahead of a DMB */
184 msr S3_1_c15_c2_0, x0 /* cpuactlr_el1 */
187 #ifdef CONFIG_ARM_ERRATA_833471
188 mrs x0, S3_1_c15_c2_0 /* cpuactlr_el1 */
189 /* FPSCR write flush.
190 * Note that in some cases where a flush is unnecessary this
191 could impact performance. */
193 msr S3_1_c15_c2_0, x0 /* cpuactlr_el1 */
196 #ifdef CONFIG_ARM_ERRATA_829520
197 mrs x0, S3_1_c15_c2_0 /* cpuactlr_el1 */
198 /* Disable Indirect Predictor bit will prevent this erratum
200 * Note that in some cases where a flush is unnecessary this
201 could impact performance. */
203 msr S3_1_c15_c2_0, x0 /* cpuactlr_el1 */
206 #ifdef CONFIG_ARM_ERRATA_833069
207 mrs x0, S3_1_c15_c2_0 /* cpuactlr_el1 */
208 /* Disable Enable Invalidates of BTB bit */
210 msr S3_1_c15_c2_0, x0 /* cpuactlr_el1 */
213 ENDPROC(apply_core_errata)
215 /*-----------------------------------------------------------------------*/
218 mov x29, lr /* Save LR */
220 #if defined(CONFIG_GICV2) || defined(CONFIG_GICV3)
221 branch_if_slave x0, 1f
225 #if defined(CONFIG_GICV3)
227 bl gic_init_secure_percpu
228 #elif defined(CONFIG_GICV2)
231 bl gic_init_secure_percpu
235 #ifdef CONFIG_ARMV8_MULTIENTRY
236 branch_if_master x0, x1, 2f
239 * Slave should wait for master clearing spin table.
240 * This sync prevent salves observing incorrect
241 * value of spin table and jumping to wrong place.
243 #if defined(CONFIG_GICV2) || defined(CONFIG_GICV3)
247 bl gic_wait_for_interrupt
251 * All slaves will enter EL2 and optionally EL1.
253 adr x3, lowlevel_in_el2
254 ldr x4, =ES_TO_AARCH64
255 bl armv8_switch_to_el2
258 #ifdef CONFIG_ARMV8_SWITCH_TO_EL1
259 adr x3, lowlevel_in_el1
260 ldr x4, =ES_TO_AARCH64
261 bl armv8_switch_to_el1
266 #endif /* CONFIG_ARMV8_MULTIENTRY */
269 mov lr, x29 /* Restore LR */
271 ENDPROC(lowlevel_init)
273 WEAK(smp_kick_all_cpus)
274 /* Kick secondary cpus up by SGI 0 interrupt */
275 #if defined(CONFIG_GICV2) || defined(CONFIG_GICV3)
277 b gic_kick_secondary_cpus
280 ENDPROC(smp_kick_all_cpus)
282 /*-----------------------------------------------------------------------*/
284 ENTRY(c_runtime_cpu_setup)
287 switch_el x1, 3f, 2f, 1f
296 ENDPROC(c_runtime_cpu_setup)
298 WEAK(save_boot_params)
299 b save_boot_params_ret /* back to my caller */
300 ENDPROC(save_boot_params)