blob: d75013eb9c8dd800f909e0cc5b6c34568bb0d44d [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001/* SPDX-License-Identifier: GPL-2.0+ */
York Suna84cd722014-06-23 15:15:54 -07002/*
Mingkai Hu0e58b512015-10-26 19:47:50 +08003 * (C) Copyright 2014-2015 Freescale Semiconductor
Meenakshi Aggarwal4470aeb2019-05-28 21:37:58 +05304 * Copyright 2019 NXP
York Suna84cd722014-06-23 15:15:54 -07005 *
York Suna84cd722014-06-23 15:15:54 -07006 * Extracted from armv8/start.S
7 */
8
9#include <config.h>
10#include <linux/linkage.h>
York Sun56cc3db2014-09-08 12:20:00 -070011#include <asm/gic.h>
York Suna84cd722014-06-23 15:15:54 -070012#include <asm/macro.h>
Wenbin Songa8f57a92017-01-17 18:31:15 +080013#include <asm/arch-fsl-layerscape/soc.h>
Mingkai Hu0e58b512015-10-26 19:47:50 +080014#ifdef CONFIG_MP
15#include <asm/arch/mp.h>
16#endif
Priyanka Jain96b001f2016-11-17 12:29:51 +053017#ifdef CONFIG_FSL_LSCH3
18#include <asm/arch-fsl-layerscape/immap_lsch3.h>
19#endif
Alison Wang73818d52016-11-10 10:49:03 +080020#include <asm/u-boot.h>
York Suna84cd722014-06-23 15:15:54 -070021
Wenbin Songa8f57a92017-01-17 18:31:15 +080022/* Get GIC offset
23* For LS1043a rev1.0, GIC base address align with 4k.
24* For LS1043a rev1.1, if DCFG_GIC400_ALIGN[GIC_ADDR_BIT]
25* is set, GIC base address align with 4K, or else align
26* with 64k.
27* output:
28* x0: the base address of GICD
29* x1: the base address of GICC
30*/
31ENTRY(get_gic_offset)
32 ldr x0, =GICD_BASE
33#ifdef CONFIG_GICV2
34 ldr x1, =GICC_BASE
35#endif
36#ifdef CONFIG_HAS_FEATURE_GIC64K_ALIGN
37 ldr x2, =DCFG_CCSR_SVR
38 ldr w2, [x2]
39 rev w2, w2
Wenbin song5d8a61c2017-12-04 12:18:28 +080040 lsr w3, w2, #16
41 ldr w4, =SVR_DEV(SVR_LS1043A)
Wenbin Songa8f57a92017-01-17 18:31:15 +080042 cmp w3, w4
43 b.ne 1f
44 ands w2, w2, #0xff
45 cmp w2, #REV1_0
46 b.eq 1f
47 ldr x2, =SCFG_GIC400_ALIGN
48 ldr w2, [x2]
49 rev w2, w2
50 tbnz w2, #GIC_ADDR_BIT, 1f
51 ldr x0, =GICD_BASE_64K
52#ifdef CONFIG_GICV2
53 ldr x1, =GICC_BASE_64K
54#endif
551:
56#endif
57 ret
58ENDPROC(get_gic_offset)
59
60ENTRY(smp_kick_all_cpus)
61 /* Kick secondary cpus up by SGI 0 interrupt */
62#if defined(CONFIG_GICV2) || defined(CONFIG_GICV3)
63 mov x29, lr /* Save LR */
64 bl get_gic_offset
65 bl gic_kick_secondary_cpus
66 mov lr, x29 /* Restore LR */
67#endif
68 ret
69ENDPROC(smp_kick_all_cpus)
70
71
York Suna84cd722014-06-23 15:15:54 -070072ENTRY(lowlevel_init)
73 mov x29, lr /* Save LR */
74
York Sunab4e7892018-11-05 18:01:23 +000075 /* unmask SError and abort */
76 msr daifclr, #4
77
78 /* Set HCR_EL2[AMO] so SError @EL2 is taken */
79 mrs x0, hcr_el2
80 orr x0, x0, #0x20 /* AMO */
81 msr hcr_el2, x0
82 isb
83
York Sune6b871e2017-05-15 08:51:59 -070084 switch_el x1, 1f, 100f, 100f /* skip if not in EL3 */
851:
86
Ashish Kumar97393d62017-08-18 10:54:36 +053087#if defined (CONFIG_SYS_FSL_HAS_CCN504)
Prabhakar Kushwahaedbbd252016-01-25 12:08:45 +053088
89 /* Set Wuo bit for RN-I 20 */
York Sun4ce6fbf2017-03-27 11:41:01 -070090#ifdef CONFIG_ARCH_LS2080A
Prabhakar Kushwahaedbbd252016-01-25 12:08:45 +053091 ldr x0, =CCI_AUX_CONTROL_BASE(20)
92 ldr x1, =0x00000010
93 bl ccn504_set_aux
Priyanka Jain60850792016-11-09 12:27:54 +053094
95 /*
96 * Set forced-order mode in RNI-6, RNI-20
97 * This is required for performance optimization on LS2088A
98 * LS2080A family does not support setting forced-order mode,
99 * so skip this operation for LS2080A family
100 */
101 bl get_svr
102 lsr w0, w0, #16
Wenbin song5d8a61c2017-12-04 12:18:28 +0800103 ldr w1, =SVR_DEV(SVR_LS2080A)
Priyanka Jain60850792016-11-09 12:27:54 +0530104 cmp w0, w1
105 b.eq 1f
106
107 ldr x0, =CCI_AUX_CONTROL_BASE(6)
108 ldr x1, =0x00000020
109 bl ccn504_set_aux
110 ldr x0, =CCI_AUX_CONTROL_BASE(20)
111 ldr x1, =0x00000020
112 bl ccn504_set_aux
1131:
Prabhakar Kushwahaedbbd252016-01-25 12:08:45 +0530114#endif
115
Scott Wooda814e662015-03-20 19:28:10 -0700116 /* Add fully-coherent masters to DVM domain */
Bhupesh Sharma8238f342015-07-01 09:58:03 +0530117 ldr x0, =CCI_MN_BASE
118 ldr x1, =CCI_MN_RNF_NODEID_LIST
119 ldr x2, =CCI_MN_DVM_DOMAIN_CTL_SET
120 bl ccn504_add_masters_to_dvm
121
122 /* Set all RN-I ports to QoS of 15 */
123 ldr x0, =CCI_S0_QOS_CONTROL_BASE(0)
124 ldr x1, =0x00FF000C
125 bl ccn504_set_qos
126 ldr x0, =CCI_S1_QOS_CONTROL_BASE(0)
127 ldr x1, =0x00FF000C
128 bl ccn504_set_qos
129 ldr x0, =CCI_S2_QOS_CONTROL_BASE(0)
130 ldr x1, =0x00FF000C
131 bl ccn504_set_qos
132
133 ldr x0, =CCI_S0_QOS_CONTROL_BASE(2)
134 ldr x1, =0x00FF000C
135 bl ccn504_set_qos
136 ldr x0, =CCI_S1_QOS_CONTROL_BASE(2)
137 ldr x1, =0x00FF000C
138 bl ccn504_set_qos
139 ldr x0, =CCI_S2_QOS_CONTROL_BASE(2)
140 ldr x1, =0x00FF000C
141 bl ccn504_set_qos
142
143 ldr x0, =CCI_S0_QOS_CONTROL_BASE(6)
144 ldr x1, =0x00FF000C
145 bl ccn504_set_qos
146 ldr x0, =CCI_S1_QOS_CONTROL_BASE(6)
147 ldr x1, =0x00FF000C
148 bl ccn504_set_qos
149 ldr x0, =CCI_S2_QOS_CONTROL_BASE(6)
150 ldr x1, =0x00FF000C
151 bl ccn504_set_qos
152
153 ldr x0, =CCI_S0_QOS_CONTROL_BASE(12)
154 ldr x1, =0x00FF000C
155 bl ccn504_set_qos
156 ldr x0, =CCI_S1_QOS_CONTROL_BASE(12)
157 ldr x1, =0x00FF000C
158 bl ccn504_set_qos
159 ldr x0, =CCI_S2_QOS_CONTROL_BASE(12)
160 ldr x1, =0x00FF000C
161 bl ccn504_set_qos
162
163 ldr x0, =CCI_S0_QOS_CONTROL_BASE(16)
164 ldr x1, =0x00FF000C
165 bl ccn504_set_qos
166 ldr x0, =CCI_S1_QOS_CONTROL_BASE(16)
167 ldr x1, =0x00FF000C
168 bl ccn504_set_qos
169 ldr x0, =CCI_S2_QOS_CONTROL_BASE(16)
170 ldr x1, =0x00FF000C
171 bl ccn504_set_qos
172
173 ldr x0, =CCI_S0_QOS_CONTROL_BASE(20)
174 ldr x1, =0x00FF000C
175 bl ccn504_set_qos
176 ldr x0, =CCI_S1_QOS_CONTROL_BASE(20)
177 ldr x1, =0x00FF000C
178 bl ccn504_set_qos
179 ldr x0, =CCI_S2_QOS_CONTROL_BASE(20)
180 ldr x1, =0x00FF000C
181 bl ccn504_set_qos
Ashish Kumar97393d62017-08-18 10:54:36 +0530182#endif /* CONFIG_SYS_FSL_HAS_CCN504 */
Scott Wooda814e662015-03-20 19:28:10 -0700183
Prabhakar Kushwahaae17df22016-06-03 18:41:26 +0530184#ifdef SMMU_BASE
York Suna84cd722014-06-23 15:15:54 -0700185 /* Set the SMMU page size in the sACR register */
186 ldr x1, =SMMU_BASE
187 ldr w0, [x1, #0x10]
188 orr w0, w0, #1 << 16 /* set sACR.pagesize to indicate 64K page */
189 str w0, [x1, #0x10]
Prabhakar Kushwahaae17df22016-06-03 18:41:26 +0530190#endif
York Suna84cd722014-06-23 15:15:54 -0700191
192 /* Initialize GIC Secure Bank Status */
193#if defined(CONFIG_GICV2) || defined(CONFIG_GICV3)
194 branch_if_slave x0, 1f
Wenbin Songa8f57a92017-01-17 18:31:15 +0800195 bl get_gic_offset
York Suna84cd722014-06-23 15:15:54 -0700196 bl gic_init_secure
1971:
198#ifdef CONFIG_GICV3
199 ldr x0, =GICR_BASE
200 bl gic_init_secure_percpu
201#elif defined(CONFIG_GICV2)
Wenbin Songa8f57a92017-01-17 18:31:15 +0800202 bl get_gic_offset
York Suna84cd722014-06-23 15:15:54 -0700203 bl gic_init_secure_percpu
204#endif
205#endif
206
York Sune6b871e2017-05-15 08:51:59 -0700207100:
York Sun56cc3db2014-09-08 12:20:00 -0700208 branch_if_master x0, x1, 2f
York Suna84cd722014-06-23 15:15:54 -0700209
Mingkai Hu0e58b512015-10-26 19:47:50 +0800210#if defined(CONFIG_MP) && defined(CONFIG_ARMV8_MULTIENTRY)
Michael Wallef056e0f2020-06-01 21:53:26 +0200211 /*
212 * Formerly, here was a jump to secondary_boot_func, but we just
213 * return early here and let the generic code in start.S handle
214 * the jump to secondary_boot_func.
215 */
216 mov lr, x29 /* Restore LR */
217 ret
Mingkai Hu0e58b512015-10-26 19:47:50 +0800218#endif
Bhupesh Sharmaa0c00ff2015-01-06 13:11:21 -0800219
Mingkai Hu0e58b512015-10-26 19:47:50 +08002202:
York Sune6b871e2017-05-15 08:51:59 -0700221 switch_el x1, 1f, 100f, 100f /* skip if not in EL3 */
2221:
Bhupesh Sharmaa0c00ff2015-01-06 13:11:21 -0800223#ifdef CONFIG_FSL_TZPC_BP147
224 /* Set Non Secure access for all devices protected via TZPC */
225 ldr x1, =TZPCDECPROT_0_SET_BASE /* Decode Protection-0 Set Reg */
226 orr w0, w0, #1 << 3 /* DCFG_RESET is accessible from NS world */
227 str w0, [x1]
228
229 isb
230 dsb sy
231#endif
232
233#ifdef CONFIG_FSL_TZASC_400
Priyanka Jain583943b2016-11-17 12:29:54 +0530234 /*
235 * LS2080 and its personalities does not support TZASC
236 * So skip TZASC related operations
237 */
238 bl get_svr
239 lsr w0, w0, #16
Wenbin song5d8a61c2017-12-04 12:18:28 +0800240 ldr w1, =SVR_DEV(SVR_LS2080A)
Priyanka Jain583943b2016-11-17 12:29:54 +0530241 cmp w0, w1
242 b.eq 1f
243
Bhupesh Sharmaa0c00ff2015-01-06 13:11:21 -0800244 /* Set TZASC so that:
245 * a. We use only Region0 whose global secure write/read is EN
246 * b. We use only Region0 whose NSAID write/read is EN
247 *
248 * NOTE: As per the CCSR map doc, TZASC 3 and TZASC 4 are just
249 * placeholders.
250 */
Sriram Dash0a7a7c32018-03-26 14:22:43 +0530251
252.macro tzasc_prog, xreg
253
254 mov x12, TZASC1_BASE
255 mov x16, #0x10000
256 mul x14, \xreg, x16
257 add x14, x14,x12
258 mov x1, #0x8
259 add x1, x1, x14
260
261 ldr w0, [x1] /* Filter 0 Gate Keeper Register */
262 orr w0, w0, #1 << 0 /* Set open_request for Filter 0 */
263 str w0, [x1]
264
265 mov x1, #0x110
266 add x1, x1, x14
Bhupesh Sharmaa0c00ff2015-01-06 13:11:21 -0800267
Sriram Dash0a7a7c32018-03-26 14:22:43 +0530268 ldr w0, [x1] /* Region-0 Attributes Register */
269 orr w0, w0, #1 << 31 /* Set Sec global write en, Bit[31] */
270 orr w0, w0, #1 << 30 /* Set Sec global read en, Bit[30] */
271 str w0, [x1]
Bhupesh Sharmaa0c00ff2015-01-06 13:11:21 -0800272
Sriram Dash0a7a7c32018-03-26 14:22:43 +0530273 mov x1, #0x114
274 add x1, x1, x14
275
276 ldr w0, [x1] /* Region-0 Access Register */
277 mov w0, #0xFFFFFFFF /* Set nsaid_wr_en and nsaid_rd_en */
278 str w0, [x1]
279.endm
280
281#ifdef CONFIG_FSL_TZASC_1
282 mov x13, #0
283 tzasc_prog x13
284
Ashish kumar76bd6ce2017-04-07 11:40:32 +0530285#endif
286#ifdef CONFIG_FSL_TZASC_2
Sriram Dash0a7a7c32018-03-26 14:22:43 +0530287 mov x13, #1
288 tzasc_prog x13
Bhupesh Sharmaa0c00ff2015-01-06 13:11:21 -0800289
Ashish kumar76bd6ce2017-04-07 11:40:32 +0530290#endif
Bhupesh Sharmaa0c00ff2015-01-06 13:11:21 -0800291 isb
292 dsb sy
293#endif
York Sune6b871e2017-05-15 08:51:59 -0700294100:
Priyanka Jain583943b2016-11-17 12:29:54 +05302951:
York Sunbad49842016-09-26 08:09:24 -0700296#ifdef CONFIG_ARCH_LS1046A
York Sune6b871e2017-05-15 08:51:59 -0700297 switch_el x1, 1f, 100f, 100f /* skip if not in EL3 */
2981:
Mingkai Hu48ddbe82016-09-07 17:56:08 +0800299 /* Initialize the L2 RAM latency */
300 mrs x1, S3_1_c11_c0_2
301 mov x0, #0x1C7
302 /* Clear L2 Tag RAM latency and L2 Data RAM latency */
303 bic x1, x1, x0
304 /* Set L2 data ram latency bits [2:0] */
305 orr x1, x1, #0x2
306 /* set L2 tag ram latency bits [8:6] */
307 orr x1, x1, #0x80
308 msr S3_1_c11_c0_2, x1
309 isb
York Sune6b871e2017-05-15 08:51:59 -0700310100:
Mingkai Hu48ddbe82016-09-07 17:56:08 +0800311#endif
312
Rajesh Bhagat541f8eb2018-11-05 18:02:05 +0000313#if !defined(CONFIG_TFABOOT) && \
314 (defined(CONFIG_FSL_LSCH2) && !defined(CONFIG_SPL_BUILD))
Hou Zhiqiangc4797802016-12-16 17:15:46 +0800315 bl fsl_ocram_init
316#endif
317
York Sun56cc3db2014-09-08 12:20:00 -0700318 mov lr, x29 /* Restore LR */
319 ret
320ENDPROC(lowlevel_init)
321
Hou Zhiqiangc4797802016-12-16 17:15:46 +0800322#if defined(CONFIG_FSL_LSCH2) && !defined(CONFIG_SPL_BUILD)
323ENTRY(fsl_ocram_init)
324 mov x28, lr /* Save LR */
325 bl fsl_clear_ocram
326 bl fsl_ocram_clear_ecc_err
327 mov lr, x28 /* Restore LR */
328 ret
329ENDPROC(fsl_ocram_init)
330
331ENTRY(fsl_clear_ocram)
332/* Clear OCRAM */
333 ldr x0, =CONFIG_SYS_FSL_OCRAM_BASE
334 ldr x1, =(CONFIG_SYS_FSL_OCRAM_BASE + CONFIG_SYS_FSL_OCRAM_SIZE)
335 mov x2, #0
336clear_loop:
337 str x2, [x0]
338 add x0, x0, #8
339 cmp x0, x1
340 b.lo clear_loop
341 ret
342ENDPROC(fsl_clear_ocram)
343
344ENTRY(fsl_ocram_clear_ecc_err)
345 /* OCRAM1/2 ECC status bit */
346 mov w1, #0x60
347 ldr x0, =DCSR_DCFG_SBEESR2
348 str w1, [x0]
349 ldr x0, =DCSR_DCFG_MBEESR2
350 str w1, [x0]
351 ret
352ENDPROC(fsl_ocram_init)
353#endif
354
Prabhakar Kushwahad169ebe2016-06-03 18:41:31 +0530355#ifdef CONFIG_FSL_LSCH3
Priyanka Jain96b001f2016-11-17 12:29:51 +0530356 .globl get_svr
357get_svr:
358 ldr x1, =FSL_LSCH3_SVR
359 ldr w0, [x1]
360 ret
Ashish Kumar97393d62017-08-18 10:54:36 +0530361#endif
Priyanka Jain96b001f2016-11-17 12:29:51 +0530362
Priyanka Jainef76b2e2018-10-29 09:17:09 +0000363#if defined(CONFIG_SYS_FSL_HAS_CCN504) || defined(CONFIG_SYS_FSL_HAS_CCN508)
York Sun1ce575f2015-01-06 13:18:42 -0800364hnf_pstate_poll:
Meenakshi Aggarwal4470aeb2019-05-28 21:37:58 +0530365 /* x0 has the desired status, return only if operation succeed
366 * clobber x1, x2, x6
York Sun1ce575f2015-01-06 13:18:42 -0800367 */
368 mov x1, x0
Meenakshi Aggarwal4470aeb2019-05-28 21:37:58 +0530369 mov w6, #8 /* HN-F node count */
York Sun1ce575f2015-01-06 13:18:42 -0800370 mov x0, #0x18
371 movk x0, #0x420, lsl #16 /* HNF0_PSTATE_STATUS */
York Sun1ce575f2015-01-06 13:18:42 -08003721:
373 ldr x2, [x0]
374 cmp x2, x1 /* check status */
375 b.eq 2f
Meenakshi Aggarwal4470aeb2019-05-28 21:37:58 +0530376 b 1b
York Sun1ce575f2015-01-06 13:18:42 -08003772:
378 add x0, x0, #0x10000 /* move to next node */
379 subs w6, w6, #1
380 cbnz w6, 1b
York Sun1ce575f2015-01-06 13:18:42 -0800381 ret
382
383hnf_set_pstate:
384 /* x0 has the desired state, clobber x1, x2, x6 */
385 mov x1, x0
386 /* power state to SFONLY */
387 mov w6, #8 /* HN-F node count */
388 mov x0, #0x10
389 movk x0, #0x420, lsl #16 /* HNF0_PSTATE_REQ */
3901: /* set pstate to sfonly */
391 ldr x2, [x0]
392 and x2, x2, #0xfffffffffffffffc /* & HNFPSTAT_MASK */
393 orr x2, x2, x1
394 str x2, [x0]
395 add x0, x0, #0x10000 /* move to next node */
396 subs w6, w6, #1
397 cbnz w6, 1b
398
399 ret
400
Stephen Warrenddb0f632016-10-19 15:18:46 -0600401ENTRY(__asm_flush_l3_dcache)
York Sun1ce575f2015-01-06 13:18:42 -0800402 /*
403 * Return status in x0
404 * success 0
York Sun1ce575f2015-01-06 13:18:42 -0800405 */
406 mov x29, lr
York Sun1ce575f2015-01-06 13:18:42 -0800407
408 dsb sy
409 mov x0, #0x1 /* HNFPSTAT_SFONLY */
410 bl hnf_set_pstate
411
412 mov x0, #0x4 /* SFONLY status */
413 bl hnf_pstate_poll
Meenakshi Aggarwal4470aeb2019-05-28 21:37:58 +0530414
York Sun1ce575f2015-01-06 13:18:42 -0800415 dsb sy
416 mov x0, #0x3 /* HNFPSTAT_FAM */
417 bl hnf_set_pstate
418
419 mov x0, #0xc /* FAM status */
420 bl hnf_pstate_poll
Meenakshi Aggarwal4470aeb2019-05-28 21:37:58 +0530421
422 mov x0, #0
York Sun1ce575f2015-01-06 13:18:42 -0800423 mov lr, x29
424 ret
Stephen Warrenddb0f632016-10-19 15:18:46 -0600425ENDPROC(__asm_flush_l3_dcache)
Ashish Kumar97393d62017-08-18 10:54:36 +0530426#endif /* CONFIG_SYS_FSL_HAS_CCN504 */
York Sun1ce575f2015-01-06 13:18:42 -0800427
Mingkai Hu0e58b512015-10-26 19:47:50 +0800428#ifdef CONFIG_MP
Michael Wallef056e0f2020-06-01 21:53:26 +0200429 .align 3
430 .global secondary_boot_addr
431secondary_boot_addr:
432 .quad secondary_boot_func
433
York Sun56cc3db2014-09-08 12:20:00 -0700434 /* Keep literals not used by the secondary boot code outside it */
435 .ltorg
436
437 /* Using 64 bit alignment since the spin table is accessed as data */
438 .align 4
439 .global secondary_boot_code
440 /* Secondary Boot Code starts here */
441secondary_boot_code:
442 .global __spin_table
443__spin_table:
444 .space CONFIG_MAX_CPUS*SPIN_TABLE_ELEM_SIZE
445
446 .align 2
447ENTRY(secondary_boot_func)
York Suna84cd722014-06-23 15:15:54 -0700448 /*
York Sun56cc3db2014-09-08 12:20:00 -0700449 * MPIDR_EL1 Fields:
450 * MPIDR[1:0] = AFF0_CPUID <- Core ID (0,1)
451 * MPIDR[7:2] = AFF0_RES
452 * MPIDR[15:8] = AFF1_CLUSTERID <- Cluster ID (0,1,2,3)
453 * MPIDR[23:16] = AFF2_CLUSTERID
454 * MPIDR[24] = MT
455 * MPIDR[29:25] = RES0
456 * MPIDR[30] = U
457 * MPIDR[31] = ME
458 * MPIDR[39:32] = AFF3
459 *
460 * Linear Processor ID (LPID) calculation from MPIDR_EL1:
461 * (We only use AFF0_CPUID and AFF1_CLUSTERID for now
462 * until AFF2_CLUSTERID and AFF3 have non-zero values)
463 *
464 * LPID = MPIDR[15:8] | MPIDR[1:0]
York Suna84cd722014-06-23 15:15:54 -0700465 */
York Sun56cc3db2014-09-08 12:20:00 -0700466 mrs x0, mpidr_el1
467 ubfm x1, x0, #8, #15
468 ubfm x2, x0, #0, #1
469 orr x10, x2, x1, lsl #2 /* x10 has LPID */
470 ubfm x9, x0, #0, #15 /* x9 contains MPIDR[15:0] */
York Suna84cd722014-06-23 15:15:54 -0700471 /*
York Sun56cc3db2014-09-08 12:20:00 -0700472 * offset of the spin table element for this core from start of spin
473 * table (each elem is padded to 64 bytes)
York Suna84cd722014-06-23 15:15:54 -0700474 */
York Sun56cc3db2014-09-08 12:20:00 -0700475 lsl x1, x10, #6
476 ldr x0, =__spin_table
477 /* physical address of this cpus spin table element */
478 add x11, x1, x0
479
York Sun77a10972015-03-20 19:28:08 -0700480 ldr x0, =__real_cntfrq
481 ldr x0, [x0]
482 msr cntfrq_el0, x0 /* set with real frequency */
York Sun56cc3db2014-09-08 12:20:00 -0700483 str x9, [x11, #16] /* LPID */
484 mov x4, #1
485 str x4, [x11, #8] /* STATUS */
486 dsb sy
York Sun56cc3db2014-09-08 12:20:00 -0700487
York Sun56cc3db2014-09-08 12:20:00 -0700488slave_cpu:
489 wfe
490 ldr x0, [x11]
491 cbz x0, slave_cpu
492#ifndef CONFIG_ARMV8_SWITCH_TO_EL1
493 mrs x1, sctlr_el2
494#else
495 mrs x1, sctlr_el1
496#endif
497 tbz x1, #25, cpu_is_le
498 rev x0, x0 /* BE to LE conversion */
499cpu_is_le:
Alison Wang73818d52016-11-10 10:49:03 +0800500 ldr x5, [x11, #24]
Alison Wanga6231fe2017-06-08 16:15:14 +0800501 cbz x5, 1f
Alison Wang73818d52016-11-10 10:49:03 +0800502
503#ifdef CONFIG_ARMV8_SWITCH_TO_EL1
Alison Wangeb2088d2017-01-17 09:39:17 +0800504 adr x4, secondary_switch_to_el1
505 ldr x5, =ES_TO_AARCH64
Alison Wang73818d52016-11-10 10:49:03 +0800506#else
Alison Wangeb2088d2017-01-17 09:39:17 +0800507 ldr x4, [x11]
508 ldr x5, =ES_TO_AARCH32
Alison Wang73818d52016-11-10 10:49:03 +0800509#endif
510 bl secondary_switch_to_el2
511
5121:
513#ifdef CONFIG_ARMV8_SWITCH_TO_EL1
Alison Wangeb2088d2017-01-17 09:39:17 +0800514 adr x4, secondary_switch_to_el1
Alison Wang73818d52016-11-10 10:49:03 +0800515#else
Alison Wangeb2088d2017-01-17 09:39:17 +0800516 ldr x4, [x11]
Alison Wang73818d52016-11-10 10:49:03 +0800517#endif
Alison Wangeb2088d2017-01-17 09:39:17 +0800518 ldr x5, =ES_TO_AARCH64
Alison Wang73818d52016-11-10 10:49:03 +0800519 bl secondary_switch_to_el2
520
York Sun56cc3db2014-09-08 12:20:00 -0700521ENDPROC(secondary_boot_func)
522
523ENTRY(secondary_switch_to_el2)
Alison Wangeb2088d2017-01-17 09:39:17 +0800524 switch_el x6, 1f, 0f, 0f
York Sun56cc3db2014-09-08 12:20:00 -07005250: ret
Alison Wangeb2088d2017-01-17 09:39:17 +08005261: armv8_switch_to_el2_m x4, x5, x6
York Sun56cc3db2014-09-08 12:20:00 -0700527ENDPROC(secondary_switch_to_el2)
528
529ENTRY(secondary_switch_to_el1)
Alison Wang73818d52016-11-10 10:49:03 +0800530 mrs x0, mpidr_el1
531 ubfm x1, x0, #8, #15
532 ubfm x2, x0, #0, #1
533 orr x10, x2, x1, lsl #2 /* x10 has LPID */
534
535 lsl x1, x10, #6
536 ldr x0, =__spin_table
537 /* physical address of this cpus spin table element */
538 add x11, x1, x0
539
Alison Wangeb2088d2017-01-17 09:39:17 +0800540 ldr x4, [x11]
Alison Wang73818d52016-11-10 10:49:03 +0800541
542 ldr x5, [x11, #24]
Alison Wanga6231fe2017-06-08 16:15:14 +0800543 cbz x5, 2f
Alison Wang73818d52016-11-10 10:49:03 +0800544
Alison Wangeb2088d2017-01-17 09:39:17 +0800545 ldr x5, =ES_TO_AARCH32
Alison Wang73818d52016-11-10 10:49:03 +0800546 bl switch_to_el1
547
Alison Wangeb2088d2017-01-17 09:39:17 +08005482: ldr x5, =ES_TO_AARCH64
Alison Wang73818d52016-11-10 10:49:03 +0800549
550switch_to_el1:
Alison Wangeb2088d2017-01-17 09:39:17 +0800551 switch_el x6, 0f, 1f, 0f
York Sun56cc3db2014-09-08 12:20:00 -07005520: ret
Alison Wangeb2088d2017-01-17 09:39:17 +08005531: armv8_switch_to_el1_m x4, x5, x6
York Sun56cc3db2014-09-08 12:20:00 -0700554ENDPROC(secondary_switch_to_el1)
555
556 /* Ensure that the literals used by the secondary boot code are
557 * assembled within it (this is required so that we can protect
558 * this area with a single memreserve region
559 */
560 .ltorg
561
562 /* 64 bit alignment for elements accessed as data */
563 .align 4
York Sun77a10972015-03-20 19:28:08 -0700564 .global __real_cntfrq
565__real_cntfrq:
566 .quad COUNTER_FREQUENCY
York Sun56cc3db2014-09-08 12:20:00 -0700567 .globl __secondary_boot_code_size
568 .type __secondary_boot_code_size, %object
569 /* Secondary Boot Code ends here */
570__secondary_boot_code_size:
571 .quad .-secondary_boot_code
Mingkai Hu0e58b512015-10-26 19:47:50 +0800572#endif