blob: 2ee60d60f123b9e5f86729c16088a225b086a4fa [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
24 .align 3
25
26.globl _TEXT_BASE
27_TEXT_BASE:
28 .quad CONFIG_SYS_TEXT_BASE
29
30/*
31 * These are defined in the linker script.
32 */
33.globl _end_ofs
34_end_ofs:
35 .quad _end - _start
36
37.globl _bss_start_ofs
38_bss_start_ofs:
39 .quad __bss_start - _start
40
41.globl _bss_end_ofs
42_bss_end_ofs:
43 .quad __bss_end - _start
44
45reset:
Sergey Temerkhanov94f7ff32015-10-14 09:55:45 -070046#ifdef CONFIG_SYS_RESET_SCTRL
47 bl reset_sctrl
48#endif
David Feng0ae76532013-12-14 11:47:35 +080049 /*
50 * Could be EL3/EL2/EL1, Initial State:
51 * Little Endian, MMU Disabled, i/dCache Disabled
52 */
53 adr x0, vectors
54 switch_el x1, 3f, 2f, 1f
David Feng1277bac2014-04-19 09:45:21 +0800553: msr vbar_el3, x0
56 mrs x0, scr_el3
David Fengc71645a2014-03-14 14:26:27 +080057 orr x0, x0, #0xf /* SCR_EL3.NS|IRQ|FIQ|EA */
58 msr scr_el3, x0
David Feng0ae76532013-12-14 11:47:35 +080059 msr cptr_el3, xzr /* Enable FP/SIMD */
Thierry Reding70bcb432015-08-20 11:42:18 +020060#ifdef COUNTER_FREQUENCY
David Feng0ae76532013-12-14 11:47:35 +080061 ldr x0, =COUNTER_FREQUENCY
62 msr cntfrq_el0, x0 /* Initialize CNTFRQ */
Thierry Reding70bcb432015-08-20 11:42:18 +020063#endif
David Feng0ae76532013-12-14 11:47:35 +080064 b 0f
652: msr vbar_el2, x0
66 mov x0, #0x33ff
67 msr cptr_el2, x0 /* Enable FP/SIMD */
68 b 0f
691: msr vbar_el1, x0
70 mov x0, #3 << 20
71 msr cpacr_el1, x0 /* Enable FP/SIMD */
720:
73
Bhupesh Sharma37118fb2015-01-23 15:50:04 +053074 /* Apply ARM core specific erratas */
75 bl apply_core_errata
76
York Sun1e6ad552014-02-26 13:26:04 -080077 /*
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()
82 */
David Feng0ae76532013-12-14 11:47:35 +080083
84 /* Processor specific initialization */
85 bl lowlevel_init
86
Linus Walleij23b58772015-03-09 10:53:21 +010087#ifdef CONFIG_ARMV8_MULTIENTRY
David Feng0ae76532013-12-14 11:47:35 +080088 branch_if_master x0, x1, master_cpu
89
90 /*
91 * Slave CPUs
92 */
93slave_cpu:
94 wfe
95 ldr x1, =CPU_RELEASE_ADDR
96 ldr x0, [x1]
97 cbz x0, slave_cpu
98 br x0 /* branch to the given address */
David Feng0ae76532013-12-14 11:47:35 +080099master_cpu:
Linus Walleij23b58772015-03-09 10:53:21 +0100100 /* On the master CPU */
101#endif /* CONFIG_ARMV8_MULTIENTRY */
102
David Feng0ae76532013-12-14 11:47:35 +0800103 bl _main
104
Sergey Temerkhanov94f7ff32015-10-14 09:55:45 -0700105#ifdef CONFIG_SYS_RESET_SCTRL
106reset_sctrl:
107 switch_el x1, 3f, 2f, 1f
1083:
109 mrs x0, sctlr_el3
110 b 0f
1112:
112 mrs x0, sctlr_el2
113 b 0f
1141:
115 mrs x0, sctlr_el1
116
1170:
118 ldr x1, =0xfdfffffa
119 and x0, x0, x1
120
121 switch_el x1, 6f, 5f, 4f
1226:
123 msr sctlr_el3, x0
124 b 7f
1255:
126 msr sctlr_el2, x0
127 b 7f
1284:
129 msr sctlr_el1, x0
130
1317:
132 dsb sy
133 isb
134 b __asm_invalidate_tlb_all
135 ret
136#endif
137
David Feng0ae76532013-12-14 11:47:35 +0800138/*-----------------------------------------------------------------------*/
139
Bhupesh Sharma37118fb2015-01-23 15:50:04 +0530140WEAK(apply_core_errata)
141
142 mov x29, lr /* Save LR */
143 /* For now, we support Cortex-A57 specific errata only */
144
145 /* Check if we are running on a Cortex-A57 core */
146 branch_if_a57_core x0, apply_a57_core_errata
1470:
148 mov lr, x29 /* Restore LR */
149 ret
150
151apply_a57_core_errata:
152
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 */
Bhupesh Sharmaf299b5b2015-05-28 14:54:13 +0530156 orr x0, x0, #1 << 49
Bhupesh Sharma37118fb2015-01-23 15:50:04 +0530157 /* Disable write streaming no L1-allocate threshold */
Bhupesh Sharmaf299b5b2015-05-28 14:54:13 +0530158 orr x0, x0, #3 << 25
Bhupesh Sharma37118fb2015-01-23 15:50:04 +0530159 /* Disable write streaming no-allocate threshold */
Bhupesh Sharmaf299b5b2015-05-28 14:54:13 +0530160 orr x0, x0, #3 << 27
Bhupesh Sharma37118fb2015-01-23 15:50:04 +0530161 msr S3_1_c15_c2_0, x0 /* cpuactlr_el1 */
162#endif
163
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 */
Bhupesh Sharmaf299b5b2015-05-28 14:54:13 +0530167 orr x0, x0, #1 << 59
Bhupesh Sharma37118fb2015-01-23 15:50:04 +0530168 msr S3_1_c15_c2_0, x0 /* cpuactlr_el1 */
169#endif
170
171#ifdef CONFIG_ARM_ERRATA_833069
172 mrs x0, S3_1_c15_c2_0 /* cpuactlr_el1 */
173 /* Disable Enable Invalidates of BTB bit */
174 and x0, x0, #0xE
175 msr S3_1_c15_c2_0, x0 /* cpuactlr_el1 */
176#endif
177 b 0b
178ENDPROC(apply_core_errata)
179
180/*-----------------------------------------------------------------------*/
181
David Feng0ae76532013-12-14 11:47:35 +0800182WEAK(lowlevel_init)
David Feng0ae76532013-12-14 11:47:35 +0800183 mov x29, lr /* Save LR */
David Feng0ae76532013-12-14 11:47:35 +0800184
Linus Walleij23b58772015-03-09 10:53:21 +0100185#ifndef CONFIG_ARMV8_MULTIENTRY
186 /*
187 * For single-entry systems the lowlevel init is very simple.
188 */
189 ldr x0, =GICD_BASE
190 bl gic_init_secure
191
192#else /* CONFIG_ARMV8_MULTIENTRY is set */
193
David Fengc71645a2014-03-14 14:26:27 +0800194#if defined(CONFIG_GICV2) || defined(CONFIG_GICV3)
195 branch_if_slave x0, 1f
196 ldr x0, =GICD_BASE
197 bl gic_init_secure
1981:
199#if defined(CONFIG_GICV3)
200 ldr x0, =GICR_BASE
201 bl gic_init_secure_percpu
202#elif defined(CONFIG_GICV2)
203 ldr x0, =GICD_BASE
204 ldr x1, =GICC_BASE
205 bl gic_init_secure_percpu
206#endif
207#endif
208
209 branch_if_master x0, x1, 2f
David Feng0ae76532013-12-14 11:47:35 +0800210
211 /*
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.
215 */
David Fengc71645a2014-03-14 14:26:27 +0800216#if defined(CONFIG_GICV2) || defined(CONFIG_GICV3)
217#ifdef CONFIG_GICV2
218 ldr x0, =GICC_BASE
219#endif
220 bl gic_wait_for_interrupt
221#endif
David Feng0ae76532013-12-14 11:47:35 +0800222
223 /*
David Fengc71645a2014-03-14 14:26:27 +0800224 * All slaves will enter EL2 and optionally EL1.
David Feng0ae76532013-12-14 11:47:35 +0800225 */
226 bl armv8_switch_to_el2
227#ifdef CONFIG_ARMV8_SWITCH_TO_EL1
228 bl armv8_switch_to_el1
229#endif
230
Linus Walleij23b58772015-03-09 10:53:21 +0100231#endif /* CONFIG_ARMV8_MULTIENTRY */
232
David Fengc71645a2014-03-14 14:26:27 +08002332:
David Feng0ae76532013-12-14 11:47:35 +0800234 mov lr, x29 /* Restore LR */
235 ret
236ENDPROC(lowlevel_init)
237
David Fengc71645a2014-03-14 14:26:27 +0800238WEAK(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)
242 ldr x0, =GICD_BASE
243 bl gic_kick_secondary_cpus
244#endif
245 mov lr, x29 /* Restore LR */
246 ret
247ENDPROC(smp_kick_all_cpus)
248
David Feng0ae76532013-12-14 11:47:35 +0800249/*-----------------------------------------------------------------------*/
250
251ENTRY(c_runtime_cpu_setup)
David Feng0ae76532013-12-14 11:47:35 +0800252 /* Relocate vBAR */
253 adr x0, vectors
254 switch_el x1, 3f, 2f, 1f
2553: msr vbar_el3, x0
256 b 0f
2572: msr vbar_el2, x0
258 b 0f
2591: msr vbar_el1, x0
2600:
261
262 ret
263ENDPROC(c_runtime_cpu_setup)