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_833069
172 mrs x0, S3_1_c15_c2_0 /* cpuactlr_el1 */
173 /* Disable Enable Invalidates of BTB bit */
175 msr S3_1_c15_c2_0, x0 /* cpuactlr_el1 */
178 ENDPROC(apply_core_errata)
180 /*-----------------------------------------------------------------------*/
183 mov x29, lr /* Save LR */
185 #ifndef CONFIG_ARMV8_MULTIENTRY
187 * For single-entry systems the lowlevel init is very simple.
192 #else /* CONFIG_ARMV8_MULTIENTRY is set */
194 #if defined(CONFIG_GICV2) || defined(CONFIG_GICV3)
195 branch_if_slave x0, 1f
199 #if defined(CONFIG_GICV3)
201 bl gic_init_secure_percpu
202 #elif defined(CONFIG_GICV2)
205 bl gic_init_secure_percpu
209 branch_if_master x0, x1, 2f
212 * Slave should wait for master clearing spin table.
213 * This sync prevent salves observing incorrect
214 * value of spin table and jumping to wrong place.
216 #if defined(CONFIG_GICV2) || defined(CONFIG_GICV3)
220 bl gic_wait_for_interrupt
224 * All slaves will enter EL2 and optionally EL1.
226 bl armv8_switch_to_el2
227 #ifdef CONFIG_ARMV8_SWITCH_TO_EL1
228 bl armv8_switch_to_el1
231 #endif /* CONFIG_ARMV8_MULTIENTRY */
234 mov lr, x29 /* Restore LR */
236 ENDPROC(lowlevel_init)
238 WEAK(smp_kick_all_cpus)
239 /* Kick secondary cpus up by SGI 0 interrupt */
240 mov x29, lr /* Save LR */
241 #if defined(CONFIG_GICV2) || defined(CONFIG_GICV3)
243 bl gic_kick_secondary_cpus
245 mov lr, x29 /* Restore LR */
247 ENDPROC(smp_kick_all_cpus)
249 /*-----------------------------------------------------------------------*/
251 ENTRY(c_runtime_cpu_setup)
254 switch_el x1, 3f, 2f, 1f
263 ENDPROC(c_runtime_cpu_setup)