blob: 19c771dba3abc2dad0971474d2f9d7773119f771 [file] [log] [blame]
David Feng0ae76532013-12-14 11:47:35 +08001/*
2 * (C) Copyright 2013
3 * David Feng <fenghua@phytium.com.cn>
4 *
5 * SPDX-License-Identifier: GPL-2.0+
6 */
7
8#include <asm-offsets.h>
9#include <config.h>
David Feng0ae76532013-12-14 11:47:35 +080010#include <linux/linkage.h>
11#include <asm/macro.h>
12#include <asm/armv8/mmu.h>
13
14/*************************************************************************
15 *
16 * Startup Code (reset vector)
17 *
18 *************************************************************************/
19
20.globl _start
21_start:
22 b reset
23
Andre Przywaracdaa6332016-05-31 10:45:06 -070024#ifdef CONFIG_ENABLE_ARM_SOC_BOOT0_HOOK
25/*
26 * Various SoCs need something special and SoC-specific up front in
27 * order to boot, allow them to set that in their boot0.h file and then
28 * use it here.
29 */
30#include <asm/arch/boot0.h>
31ARM_SOC_BOOT0_HOOK
32#endif
33
David Feng0ae76532013-12-14 11:47:35 +080034 .align 3
35
36.globl _TEXT_BASE
37_TEXT_BASE:
38 .quad CONFIG_SYS_TEXT_BASE
39
40/*
41 * These are defined in the linker script.
42 */
43.globl _end_ofs
44_end_ofs:
45 .quad _end - _start
46
47.globl _bss_start_ofs
48_bss_start_ofs:
49 .quad __bss_start - _start
50
51.globl _bss_end_ofs
52_bss_end_ofs:
53 .quad __bss_end - _start
54
55reset:
Stephen Warren0e2b5352016-07-18 17:01:50 -060056 /* Allow the board to save important registers */
57 b save_boot_params
58.globl save_boot_params_ret
59save_boot_params_ret:
60
Sergey Temerkhanov94f7ff32015-10-14 09:55:45 -070061#ifdef CONFIG_SYS_RESET_SCTRL
62 bl reset_sctrl
63#endif
David Feng0ae76532013-12-14 11:47:35 +080064 /*
65 * Could be EL3/EL2/EL1, Initial State:
66 * Little Endian, MMU Disabled, i/dCache Disabled
67 */
68 adr x0, vectors
69 switch_el x1, 3f, 2f, 1f
David Feng1277bac2014-04-19 09:45:21 +0800703: msr vbar_el3, x0
71 mrs x0, scr_el3
David Fengc71645a2014-03-14 14:26:27 +080072 orr x0, x0, #0xf /* SCR_EL3.NS|IRQ|FIQ|EA */
73 msr scr_el3, x0
David Feng0ae76532013-12-14 11:47:35 +080074 msr cptr_el3, xzr /* Enable FP/SIMD */
Thierry Reding70bcb432015-08-20 11:42:18 +020075#ifdef COUNTER_FREQUENCY
David Feng0ae76532013-12-14 11:47:35 +080076 ldr x0, =COUNTER_FREQUENCY
77 msr cntfrq_el0, x0 /* Initialize CNTFRQ */
Thierry Reding70bcb432015-08-20 11:42:18 +020078#endif
David Feng0ae76532013-12-14 11:47:35 +080079 b 0f
802: msr vbar_el2, x0
81 mov x0, #0x33ff
82 msr cptr_el2, x0 /* Enable FP/SIMD */
83 b 0f
841: msr vbar_el1, x0
85 mov x0, #3 << 20
86 msr cpacr_el1, x0 /* Enable FP/SIMD */
870:
88
Bhupesh Sharma37118fb2015-01-23 15:50:04 +053089 /* Apply ARM core specific erratas */
90 bl apply_core_errata
91
York Sun1e6ad552014-02-26 13:26:04 -080092 /*
93 * Cache/BPB/TLB Invalidate
94 * i-cache is invalidated before enabled in icache_enable()
95 * tlb is invalidated before mmu is enabled in dcache_enable()
96 * d-cache is invalidated before enabled in dcache_enable()
97 */
David Feng0ae76532013-12-14 11:47:35 +080098
99 /* Processor specific initialization */
100 bl lowlevel_init
101
Masahiro Yamada6b6024e2016-06-27 19:31:05 +0900102#if CONFIG_IS_ENABLED(ARMV8_SPIN_TABLE)
103 branch_if_master x0, x1, master_cpu
104 b spin_table_secondary_jump
105 /* never return */
106#elif defined(CONFIG_ARMV8_MULTIENTRY)
David Feng0ae76532013-12-14 11:47:35 +0800107 branch_if_master x0, x1, master_cpu
108
109 /*
110 * Slave CPUs
111 */
112slave_cpu:
113 wfe
114 ldr x1, =CPU_RELEASE_ADDR
115 ldr x0, [x1]
116 cbz x0, slave_cpu
117 br x0 /* branch to the given address */
Linus Walleij23b58772015-03-09 10:53:21 +0100118#endif /* CONFIG_ARMV8_MULTIENTRY */
Masahiro Yamada6b6024e2016-06-27 19:31:05 +0900119master_cpu:
David Feng0ae76532013-12-14 11:47:35 +0800120 bl _main
121
Sergey Temerkhanov94f7ff32015-10-14 09:55:45 -0700122#ifdef CONFIG_SYS_RESET_SCTRL
123reset_sctrl:
124 switch_el x1, 3f, 2f, 1f
1253:
126 mrs x0, sctlr_el3
127 b 0f
1282:
129 mrs x0, sctlr_el2
130 b 0f
1311:
132 mrs x0, sctlr_el1
133
1340:
135 ldr x1, =0xfdfffffa
136 and x0, x0, x1
137
138 switch_el x1, 6f, 5f, 4f
1396:
140 msr sctlr_el3, x0
141 b 7f
1425:
143 msr sctlr_el2, x0
144 b 7f
1454:
146 msr sctlr_el1, x0
147
1487:
149 dsb sy
150 isb
151 b __asm_invalidate_tlb_all
152 ret
153#endif
154
David Feng0ae76532013-12-14 11:47:35 +0800155/*-----------------------------------------------------------------------*/
156
Bhupesh Sharma37118fb2015-01-23 15:50:04 +0530157WEAK(apply_core_errata)
158
159 mov x29, lr /* Save LR */
160 /* For now, we support Cortex-A57 specific errata only */
161
162 /* Check if we are running on a Cortex-A57 core */
163 branch_if_a57_core x0, apply_a57_core_errata
1640:
165 mov lr, x29 /* Restore LR */
166 ret
167
168apply_a57_core_errata:
169
170#ifdef CONFIG_ARM_ERRATA_828024
171 mrs x0, S3_1_c15_c2_0 /* cpuactlr_el1 */
172 /* Disable non-allocate hint of w-b-n-a memory type */
Bhupesh Sharmaf299b5b2015-05-28 14:54:13 +0530173 orr x0, x0, #1 << 49
Bhupesh Sharma37118fb2015-01-23 15:50:04 +0530174 /* Disable write streaming no L1-allocate threshold */
Bhupesh Sharmaf299b5b2015-05-28 14:54:13 +0530175 orr x0, x0, #3 << 25
Bhupesh Sharma37118fb2015-01-23 15:50:04 +0530176 /* Disable write streaming no-allocate threshold */
Bhupesh Sharmaf299b5b2015-05-28 14:54:13 +0530177 orr x0, x0, #3 << 27
Bhupesh Sharma37118fb2015-01-23 15:50:04 +0530178 msr S3_1_c15_c2_0, x0 /* cpuactlr_el1 */
179#endif
180
181#ifdef CONFIG_ARM_ERRATA_826974
182 mrs x0, S3_1_c15_c2_0 /* cpuactlr_el1 */
183 /* Disable speculative load execution ahead of a DMB */
Bhupesh Sharmaf299b5b2015-05-28 14:54:13 +0530184 orr x0, x0, #1 << 59
Bhupesh Sharma37118fb2015-01-23 15:50:04 +0530185 msr S3_1_c15_c2_0, x0 /* cpuactlr_el1 */
186#endif
187
Ashish kumar2ea3a442016-01-27 18:09:32 +0530188#ifdef CONFIG_ARM_ERRATA_833471
189 mrs x0, S3_1_c15_c2_0 /* cpuactlr_el1 */
190 /* FPSCR write flush.
191 * Note that in some cases where a flush is unnecessary this
192 could impact performance. */
193 orr x0, x0, #1 << 38
194 msr S3_1_c15_c2_0, x0 /* cpuactlr_el1 */
195#endif
196
197#ifdef CONFIG_ARM_ERRATA_829520
198 mrs x0, S3_1_c15_c2_0 /* cpuactlr_el1 */
199 /* Disable Indirect Predictor bit will prevent this erratum
200 from occurring
201 * Note that in some cases where a flush is unnecessary this
202 could impact performance. */
203 orr x0, x0, #1 << 4
204 msr S3_1_c15_c2_0, x0 /* cpuactlr_el1 */
205#endif
206
Bhupesh Sharma37118fb2015-01-23 15:50:04 +0530207#ifdef CONFIG_ARM_ERRATA_833069
208 mrs x0, S3_1_c15_c2_0 /* cpuactlr_el1 */
209 /* Disable Enable Invalidates of BTB bit */
210 and x0, x0, #0xE
211 msr S3_1_c15_c2_0, x0 /* cpuactlr_el1 */
212#endif
213 b 0b
214ENDPROC(apply_core_errata)
215
216/*-----------------------------------------------------------------------*/
217
David Feng0ae76532013-12-14 11:47:35 +0800218WEAK(lowlevel_init)
David Feng0ae76532013-12-14 11:47:35 +0800219 mov x29, lr /* Save LR */
David Feng0ae76532013-12-14 11:47:35 +0800220
David Fengc71645a2014-03-14 14:26:27 +0800221#if defined(CONFIG_GICV2) || defined(CONFIG_GICV3)
222 branch_if_slave x0, 1f
223 ldr x0, =GICD_BASE
224 bl gic_init_secure
2251:
226#if defined(CONFIG_GICV3)
227 ldr x0, =GICR_BASE
228 bl gic_init_secure_percpu
229#elif defined(CONFIG_GICV2)
230 ldr x0, =GICD_BASE
231 ldr x1, =GICC_BASE
232 bl gic_init_secure_percpu
233#endif
Stephen Warren11661192016-04-28 12:45:44 -0600234#endif
David Fengc71645a2014-03-14 14:26:27 +0800235
Masahiro Yamadad38fca42016-05-20 12:13:10 +0900236#ifdef CONFIG_ARMV8_MULTIENTRY
David Fengc71645a2014-03-14 14:26:27 +0800237 branch_if_master x0, x1, 2f
David Feng0ae76532013-12-14 11:47:35 +0800238
239 /*
240 * Slave should wait for master clearing spin table.
241 * This sync prevent salves observing incorrect
242 * value of spin table and jumping to wrong place.
243 */
David Fengc71645a2014-03-14 14:26:27 +0800244#if defined(CONFIG_GICV2) || defined(CONFIG_GICV3)
245#ifdef CONFIG_GICV2
246 ldr x0, =GICC_BASE
247#endif
248 bl gic_wait_for_interrupt
249#endif
David Feng0ae76532013-12-14 11:47:35 +0800250
251 /*
David Fengc71645a2014-03-14 14:26:27 +0800252 * All slaves will enter EL2 and optionally EL1.
David Feng0ae76532013-12-14 11:47:35 +0800253 */
254 bl armv8_switch_to_el2
255#ifdef CONFIG_ARMV8_SWITCH_TO_EL1
256 bl armv8_switch_to_el1
257#endif
258
Linus Walleij23b58772015-03-09 10:53:21 +0100259#endif /* CONFIG_ARMV8_MULTIENTRY */
260
David Fengc71645a2014-03-14 14:26:27 +08002612:
David Feng0ae76532013-12-14 11:47:35 +0800262 mov lr, x29 /* Restore LR */
263 ret
264ENDPROC(lowlevel_init)
265
David Fengc71645a2014-03-14 14:26:27 +0800266WEAK(smp_kick_all_cpus)
267 /* Kick secondary cpus up by SGI 0 interrupt */
David Fengc71645a2014-03-14 14:26:27 +0800268#if defined(CONFIG_GICV2) || defined(CONFIG_GICV3)
269 ldr x0, =GICD_BASE
Masahiro Yamadaafedf542016-06-17 18:32:47 +0900270 b gic_kick_secondary_cpus
David Fengc71645a2014-03-14 14:26:27 +0800271#endif
David Fengc71645a2014-03-14 14:26:27 +0800272 ret
273ENDPROC(smp_kick_all_cpus)
274
David Feng0ae76532013-12-14 11:47:35 +0800275/*-----------------------------------------------------------------------*/
276
277ENTRY(c_runtime_cpu_setup)
David Feng0ae76532013-12-14 11:47:35 +0800278 /* Relocate vBAR */
279 adr x0, vectors
280 switch_el x1, 3f, 2f, 1f
2813: msr vbar_el3, x0
282 b 0f
2832: msr vbar_el2, x0
284 b 0f
2851: msr vbar_el1, x0
2860:
287
288 ret
289ENDPROC(c_runtime_cpu_setup)
Stephen Warren0e2b5352016-07-18 17:01:50 -0600290
291WEAK(save_boot_params)
292 b save_boot_params_ret /* back to my caller */
293ENDPROC(save_boot_params)