blob: 87410c73a920160afc27fa1fea07fedce9fe84bd [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
Yuantian Tang67a5c282022-03-09 15:37:22 +08004 * Copyright 2019-2022 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>
Priyanka Jain96b001f2016-11-17 12:29:51 +053014#ifdef CONFIG_FSL_LSCH3
15#include <asm/arch-fsl-layerscape/immap_lsch3.h>
16#endif
Alison Wang73818d52016-11-10 10:49:03 +080017#include <asm/u-boot.h>
York Suna84cd722014-06-23 15:15:54 -070018
Michael Walle53ec9992020-06-01 21:53:27 +020019 .align 3
20 .weak secondary_boot_addr
21secondary_boot_addr:
22 .quad 0
23
Wenbin Songa8f57a92017-01-17 18:31:15 +080024/* Get GIC offset
25* For LS1043a rev1.0, GIC base address align with 4k.
26* For LS1043a rev1.1, if DCFG_GIC400_ALIGN[GIC_ADDR_BIT]
27* is set, GIC base address align with 4K, or else align
28* with 64k.
29* output:
30* x0: the base address of GICD
31* x1: the base address of GICC
32*/
33ENTRY(get_gic_offset)
34 ldr x0, =GICD_BASE
35#ifdef CONFIG_GICV2
36 ldr x1, =GICC_BASE
37#endif
38#ifdef CONFIG_HAS_FEATURE_GIC64K_ALIGN
39 ldr x2, =DCFG_CCSR_SVR
40 ldr w2, [x2]
41 rev w2, w2
Wenbin song5d8a61c2017-12-04 12:18:28 +080042 lsr w3, w2, #16
43 ldr w4, =SVR_DEV(SVR_LS1043A)
Wenbin Songa8f57a92017-01-17 18:31:15 +080044 cmp w3, w4
45 b.ne 1f
46 ands w2, w2, #0xff
47 cmp w2, #REV1_0
48 b.eq 1f
49 ldr x2, =SCFG_GIC400_ALIGN
50 ldr w2, [x2]
51 rev w2, w2
52 tbnz w2, #GIC_ADDR_BIT, 1f
53 ldr x0, =GICD_BASE_64K
54#ifdef CONFIG_GICV2
55 ldr x1, =GICC_BASE_64K
56#endif
571:
58#endif
59 ret
60ENDPROC(get_gic_offset)
61
62ENTRY(smp_kick_all_cpus)
63 /* Kick secondary cpus up by SGI 0 interrupt */
64#if defined(CONFIG_GICV2) || defined(CONFIG_GICV3)
65 mov x29, lr /* Save LR */
66 bl get_gic_offset
67 bl gic_kick_secondary_cpus
68 mov lr, x29 /* Restore LR */
69#endif
70 ret
71ENDPROC(smp_kick_all_cpus)
72
73
York Suna84cd722014-06-23 15:15:54 -070074ENTRY(lowlevel_init)
75 mov x29, lr /* Save LR */
76
York Sune6b871e2017-05-15 08:51:59 -070077 switch_el x1, 1f, 100f, 100f /* skip if not in EL3 */
781:
79
Ashish Kumar97393d62017-08-18 10:54:36 +053080#if defined (CONFIG_SYS_FSL_HAS_CCN504)
Prabhakar Kushwahaedbbd252016-01-25 12:08:45 +053081
82 /* Set Wuo bit for RN-I 20 */
York Sun4ce6fbf2017-03-27 11:41:01 -070083#ifdef CONFIG_ARCH_LS2080A
Prabhakar Kushwahaedbbd252016-01-25 12:08:45 +053084 ldr x0, =CCI_AUX_CONTROL_BASE(20)
85 ldr x1, =0x00000010
86 bl ccn504_set_aux
Priyanka Jain60850792016-11-09 12:27:54 +053087
88 /*
89 * Set forced-order mode in RNI-6, RNI-20
90 * This is required for performance optimization on LS2088A
91 * LS2080A family does not support setting forced-order mode,
92 * so skip this operation for LS2080A family
93 */
94 bl get_svr
95 lsr w0, w0, #16
Wenbin song5d8a61c2017-12-04 12:18:28 +080096 ldr w1, =SVR_DEV(SVR_LS2080A)
Priyanka Jain60850792016-11-09 12:27:54 +053097 cmp w0, w1
98 b.eq 1f
99
100 ldr x0, =CCI_AUX_CONTROL_BASE(6)
101 ldr x1, =0x00000020
102 bl ccn504_set_aux
103 ldr x0, =CCI_AUX_CONTROL_BASE(20)
104 ldr x1, =0x00000020
105 bl ccn504_set_aux
1061:
Prabhakar Kushwahaedbbd252016-01-25 12:08:45 +0530107#endif
108
Scott Wooda814e662015-03-20 19:28:10 -0700109 /* Add fully-coherent masters to DVM domain */
Bhupesh Sharma8238f342015-07-01 09:58:03 +0530110 ldr x0, =CCI_MN_BASE
111 ldr x1, =CCI_MN_RNF_NODEID_LIST
112 ldr x2, =CCI_MN_DVM_DOMAIN_CTL_SET
113 bl ccn504_add_masters_to_dvm
114
115 /* Set all RN-I ports to QoS of 15 */
116 ldr x0, =CCI_S0_QOS_CONTROL_BASE(0)
117 ldr x1, =0x00FF000C
118 bl ccn504_set_qos
119 ldr x0, =CCI_S1_QOS_CONTROL_BASE(0)
120 ldr x1, =0x00FF000C
121 bl ccn504_set_qos
122 ldr x0, =CCI_S2_QOS_CONTROL_BASE(0)
123 ldr x1, =0x00FF000C
124 bl ccn504_set_qos
125
126 ldr x0, =CCI_S0_QOS_CONTROL_BASE(2)
127 ldr x1, =0x00FF000C
128 bl ccn504_set_qos
129 ldr x0, =CCI_S1_QOS_CONTROL_BASE(2)
130 ldr x1, =0x00FF000C
131 bl ccn504_set_qos
132 ldr x0, =CCI_S2_QOS_CONTROL_BASE(2)
133 ldr x1, =0x00FF000C
134 bl ccn504_set_qos
135
136 ldr x0, =CCI_S0_QOS_CONTROL_BASE(6)
137 ldr x1, =0x00FF000C
138 bl ccn504_set_qos
139 ldr x0, =CCI_S1_QOS_CONTROL_BASE(6)
140 ldr x1, =0x00FF000C
141 bl ccn504_set_qos
142 ldr x0, =CCI_S2_QOS_CONTROL_BASE(6)
143 ldr x1, =0x00FF000C
144 bl ccn504_set_qos
145
146 ldr x0, =CCI_S0_QOS_CONTROL_BASE(12)
147 ldr x1, =0x00FF000C
148 bl ccn504_set_qos
149 ldr x0, =CCI_S1_QOS_CONTROL_BASE(12)
150 ldr x1, =0x00FF000C
151 bl ccn504_set_qos
152 ldr x0, =CCI_S2_QOS_CONTROL_BASE(12)
153 ldr x1, =0x00FF000C
154 bl ccn504_set_qos
155
156 ldr x0, =CCI_S0_QOS_CONTROL_BASE(16)
157 ldr x1, =0x00FF000C
158 bl ccn504_set_qos
159 ldr x0, =CCI_S1_QOS_CONTROL_BASE(16)
160 ldr x1, =0x00FF000C
161 bl ccn504_set_qos
162 ldr x0, =CCI_S2_QOS_CONTROL_BASE(16)
163 ldr x1, =0x00FF000C
164 bl ccn504_set_qos
165
166 ldr x0, =CCI_S0_QOS_CONTROL_BASE(20)
167 ldr x1, =0x00FF000C
168 bl ccn504_set_qos
169 ldr x0, =CCI_S1_QOS_CONTROL_BASE(20)
170 ldr x1, =0x00FF000C
171 bl ccn504_set_qos
172 ldr x0, =CCI_S2_QOS_CONTROL_BASE(20)
173 ldr x1, =0x00FF000C
174 bl ccn504_set_qos
Ashish Kumar97393d62017-08-18 10:54:36 +0530175#endif /* CONFIG_SYS_FSL_HAS_CCN504 */
Scott Wooda814e662015-03-20 19:28:10 -0700176
Prabhakar Kushwahaae17df22016-06-03 18:41:26 +0530177#ifdef SMMU_BASE
York Suna84cd722014-06-23 15:15:54 -0700178 /* Set the SMMU page size in the sACR register */
179 ldr x1, =SMMU_BASE
180 ldr w0, [x1, #0x10]
181 orr w0, w0, #1 << 16 /* set sACR.pagesize to indicate 64K page */
182 str w0, [x1, #0x10]
Prabhakar Kushwahaae17df22016-06-03 18:41:26 +0530183#endif
York Suna84cd722014-06-23 15:15:54 -0700184
185 /* Initialize GIC Secure Bank Status */
Michael Walle3ab80622020-11-18 17:45:59 +0100186#if !defined(CONFIG_SPL_BUILD)
York Suna84cd722014-06-23 15:15:54 -0700187#if defined(CONFIG_GICV2) || defined(CONFIG_GICV3)
188 branch_if_slave x0, 1f
Wenbin Songa8f57a92017-01-17 18:31:15 +0800189 bl get_gic_offset
York Suna84cd722014-06-23 15:15:54 -0700190 bl gic_init_secure
1911:
192#ifdef CONFIG_GICV3
193 ldr x0, =GICR_BASE
194 bl gic_init_secure_percpu
195#elif defined(CONFIG_GICV2)
Wenbin Songa8f57a92017-01-17 18:31:15 +0800196 bl get_gic_offset
York Suna84cd722014-06-23 15:15:54 -0700197 bl gic_init_secure_percpu
198#endif
199#endif
Michael Walle3ab80622020-11-18 17:45:59 +0100200#endif
York Suna84cd722014-06-23 15:15:54 -0700201
York Sune6b871e2017-05-15 08:51:59 -0700202100:
Andre Przywara93b9ce72022-02-11 11:29:39 +0000203 branch_if_master x0, 2f
York Suna84cd722014-06-23 15:15:54 -0700204
Mingkai Hu0e58b512015-10-26 19:47:50 +0800205#if defined(CONFIG_MP) && defined(CONFIG_ARMV8_MULTIENTRY)
Michael Wallef056e0f2020-06-01 21:53:26 +0200206 /*
207 * Formerly, here was a jump to secondary_boot_func, but we just
208 * return early here and let the generic code in start.S handle
209 * the jump to secondary_boot_func.
210 */
211 mov lr, x29 /* Restore LR */
212 ret
Mingkai Hu0e58b512015-10-26 19:47:50 +0800213#endif
Bhupesh Sharmaa0c00ff2015-01-06 13:11:21 -0800214
Mingkai Hu0e58b512015-10-26 19:47:50 +08002152:
York Sune6b871e2017-05-15 08:51:59 -0700216 switch_el x1, 1f, 100f, 100f /* skip if not in EL3 */
2171:
Bhupesh Sharmaa0c00ff2015-01-06 13:11:21 -0800218#ifdef CONFIG_FSL_TZPC_BP147
219 /* Set Non Secure access for all devices protected via TZPC */
220 ldr x1, =TZPCDECPROT_0_SET_BASE /* Decode Protection-0 Set Reg */
221 orr w0, w0, #1 << 3 /* DCFG_RESET is accessible from NS world */
222 str w0, [x1]
223
224 isb
225 dsb sy
226#endif
227
228#ifdef CONFIG_FSL_TZASC_400
Priyanka Jain583943b2016-11-17 12:29:54 +0530229 /*
230 * LS2080 and its personalities does not support TZASC
231 * So skip TZASC related operations
232 */
233 bl get_svr
234 lsr w0, w0, #16
Wenbin song5d8a61c2017-12-04 12:18:28 +0800235 ldr w1, =SVR_DEV(SVR_LS2080A)
Priyanka Jain583943b2016-11-17 12:29:54 +0530236 cmp w0, w1
237 b.eq 1f
238
Bhupesh Sharmaa0c00ff2015-01-06 13:11:21 -0800239 /* Set TZASC so that:
240 * a. We use only Region0 whose global secure write/read is EN
241 * b. We use only Region0 whose NSAID write/read is EN
242 *
243 * NOTE: As per the CCSR map doc, TZASC 3 and TZASC 4 are just
Wolfgang Denk62fb2b42021-09-27 17:42:39 +0200244 * placeholders.
Bhupesh Sharmaa0c00ff2015-01-06 13:11:21 -0800245 */
Sriram Dash0a7a7c32018-03-26 14:22:43 +0530246
247.macro tzasc_prog, xreg
248
249 mov x12, TZASC1_BASE
250 mov x16, #0x10000
251 mul x14, \xreg, x16
252 add x14, x14,x12
Wolfgang Denk62fb2b42021-09-27 17:42:39 +0200253 mov x1, #0x8
Sriram Dash0a7a7c32018-03-26 14:22:43 +0530254 add x1, x1, x14
255
256 ldr w0, [x1] /* Filter 0 Gate Keeper Register */
257 orr w0, w0, #1 << 0 /* Set open_request for Filter 0 */
258 str w0, [x1]
259
260 mov x1, #0x110
261 add x1, x1, x14
Bhupesh Sharmaa0c00ff2015-01-06 13:11:21 -0800262
Sriram Dash0a7a7c32018-03-26 14:22:43 +0530263 ldr w0, [x1] /* Region-0 Attributes Register */
264 orr w0, w0, #1 << 31 /* Set Sec global write en, Bit[31] */
265 orr w0, w0, #1 << 30 /* Set Sec global read en, Bit[30] */
266 str w0, [x1]
Bhupesh Sharmaa0c00ff2015-01-06 13:11:21 -0800267
Sriram Dash0a7a7c32018-03-26 14:22:43 +0530268 mov x1, #0x114
269 add x1, x1, x14
270
271 ldr w0, [x1] /* Region-0 Access Register */
272 mov w0, #0xFFFFFFFF /* Set nsaid_wr_en and nsaid_rd_en */
273 str w0, [x1]
274.endm
275
276#ifdef CONFIG_FSL_TZASC_1
277 mov x13, #0
278 tzasc_prog x13
279
Ashish kumar76bd6ce2017-04-07 11:40:32 +0530280#endif
281#ifdef CONFIG_FSL_TZASC_2
Sriram Dash0a7a7c32018-03-26 14:22:43 +0530282 mov x13, #1
283 tzasc_prog x13
Bhupesh Sharmaa0c00ff2015-01-06 13:11:21 -0800284
Ashish kumar76bd6ce2017-04-07 11:40:32 +0530285#endif
Bhupesh Sharmaa0c00ff2015-01-06 13:11:21 -0800286 isb
287 dsb sy
288#endif
York Sune6b871e2017-05-15 08:51:59 -0700289100:
Priyanka Jain583943b2016-11-17 12:29:54 +05302901:
York Sunbad49842016-09-26 08:09:24 -0700291#ifdef CONFIG_ARCH_LS1046A
York Sune6b871e2017-05-15 08:51:59 -0700292 switch_el x1, 1f, 100f, 100f /* skip if not in EL3 */
2931:
Mingkai Hu48ddbe82016-09-07 17:56:08 +0800294 /* Initialize the L2 RAM latency */
295 mrs x1, S3_1_c11_c0_2
296 mov x0, #0x1C7
297 /* Clear L2 Tag RAM latency and L2 Data RAM latency */
298 bic x1, x1, x0
299 /* Set L2 data ram latency bits [2:0] */
300 orr x1, x1, #0x2
301 /* set L2 tag ram latency bits [8:6] */
302 orr x1, x1, #0x80
303 msr S3_1_c11_c0_2, x1
304 isb
York Sune6b871e2017-05-15 08:51:59 -0700305100:
Mingkai Hu48ddbe82016-09-07 17:56:08 +0800306#endif
307
Rajesh Bhagat541f8eb2018-11-05 18:02:05 +0000308#if !defined(CONFIG_TFABOOT) && \
309 (defined(CONFIG_FSL_LSCH2) && !defined(CONFIG_SPL_BUILD))
Hou Zhiqiangc4797802016-12-16 17:15:46 +0800310 bl fsl_ocram_init
311#endif
312
York Sun56cc3db2014-09-08 12:20:00 -0700313 mov lr, x29 /* Restore LR */
314 ret
315ENDPROC(lowlevel_init)
316
Hou Zhiqiangc4797802016-12-16 17:15:46 +0800317#if defined(CONFIG_FSL_LSCH2) && !defined(CONFIG_SPL_BUILD)
318ENTRY(fsl_ocram_init)
319 mov x28, lr /* Save LR */
320 bl fsl_clear_ocram
321 bl fsl_ocram_clear_ecc_err
322 mov lr, x28 /* Restore LR */
323 ret
324ENDPROC(fsl_ocram_init)
325
326ENTRY(fsl_clear_ocram)
327/* Clear OCRAM */
328 ldr x0, =CONFIG_SYS_FSL_OCRAM_BASE
329 ldr x1, =(CONFIG_SYS_FSL_OCRAM_BASE + CONFIG_SYS_FSL_OCRAM_SIZE)
330 mov x2, #0
331clear_loop:
332 str x2, [x0]
333 add x0, x0, #8
334 cmp x0, x1
335 b.lo clear_loop
336 ret
337ENDPROC(fsl_clear_ocram)
338
339ENTRY(fsl_ocram_clear_ecc_err)
340 /* OCRAM1/2 ECC status bit */
341 mov w1, #0x60
342 ldr x0, =DCSR_DCFG_SBEESR2
343 str w1, [x0]
344 ldr x0, =DCSR_DCFG_MBEESR2
345 str w1, [x0]
346 ret
Yuantian Tang67a5c282022-03-09 15:37:22 +0800347ENDPROC(fsl_ocram_clear_ecc_err)
Hou Zhiqiangc4797802016-12-16 17:15:46 +0800348#endif
349
Prabhakar Kushwahad169ebe2016-06-03 18:41:31 +0530350#ifdef CONFIG_FSL_LSCH3
Priyanka Jain96b001f2016-11-17 12:29:51 +0530351 .globl get_svr
352get_svr:
353 ldr x1, =FSL_LSCH3_SVR
354 ldr w0, [x1]
355 ret
Ashish Kumar97393d62017-08-18 10:54:36 +0530356#endif
Priyanka Jain96b001f2016-11-17 12:29:51 +0530357
Priyanka Jainef76b2e2018-10-29 09:17:09 +0000358#if defined(CONFIG_SYS_FSL_HAS_CCN504) || defined(CONFIG_SYS_FSL_HAS_CCN508)
York Sun1ce575f2015-01-06 13:18:42 -0800359hnf_pstate_poll:
Meenakshi Aggarwal4470aeb2019-05-28 21:37:58 +0530360 /* x0 has the desired status, return only if operation succeed
361 * clobber x1, x2, x6
York Sun1ce575f2015-01-06 13:18:42 -0800362 */
363 mov x1, x0
Meenakshi Aggarwal4470aeb2019-05-28 21:37:58 +0530364 mov w6, #8 /* HN-F node count */
York Sun1ce575f2015-01-06 13:18:42 -0800365 mov x0, #0x18
366 movk x0, #0x420, lsl #16 /* HNF0_PSTATE_STATUS */
York Sun1ce575f2015-01-06 13:18:42 -08003671:
368 ldr x2, [x0]
369 cmp x2, x1 /* check status */
370 b.eq 2f
Meenakshi Aggarwal4470aeb2019-05-28 21:37:58 +0530371 b 1b
York Sun1ce575f2015-01-06 13:18:42 -08003722:
373 add x0, x0, #0x10000 /* move to next node */
374 subs w6, w6, #1
375 cbnz w6, 1b
York Sun1ce575f2015-01-06 13:18:42 -0800376 ret
377
378hnf_set_pstate:
379 /* x0 has the desired state, clobber x1, x2, x6 */
380 mov x1, x0
381 /* power state to SFONLY */
382 mov w6, #8 /* HN-F node count */
383 mov x0, #0x10
384 movk x0, #0x420, lsl #16 /* HNF0_PSTATE_REQ */
3851: /* set pstate to sfonly */
386 ldr x2, [x0]
387 and x2, x2, #0xfffffffffffffffc /* & HNFPSTAT_MASK */
388 orr x2, x2, x1
389 str x2, [x0]
390 add x0, x0, #0x10000 /* move to next node */
391 subs w6, w6, #1
392 cbnz w6, 1b
393
394 ret
395
Stephen Warrenddb0f632016-10-19 15:18:46 -0600396ENTRY(__asm_flush_l3_dcache)
York Sun1ce575f2015-01-06 13:18:42 -0800397 /*
398 * Return status in x0
399 * success 0
York Sun1ce575f2015-01-06 13:18:42 -0800400 */
401 mov x29, lr
York Sun1ce575f2015-01-06 13:18:42 -0800402
403 dsb sy
404 mov x0, #0x1 /* HNFPSTAT_SFONLY */
405 bl hnf_set_pstate
406
407 mov x0, #0x4 /* SFONLY status */
408 bl hnf_pstate_poll
Meenakshi Aggarwal4470aeb2019-05-28 21:37:58 +0530409
York Sun1ce575f2015-01-06 13:18:42 -0800410 dsb sy
411 mov x0, #0x3 /* HNFPSTAT_FAM */
412 bl hnf_set_pstate
413
414 mov x0, #0xc /* FAM status */
415 bl hnf_pstate_poll
Meenakshi Aggarwal4470aeb2019-05-28 21:37:58 +0530416
417 mov x0, #0
York Sun1ce575f2015-01-06 13:18:42 -0800418 mov lr, x29
419 ret
Stephen Warrenddb0f632016-10-19 15:18:46 -0600420ENDPROC(__asm_flush_l3_dcache)
Ashish Kumar97393d62017-08-18 10:54:36 +0530421#endif /* CONFIG_SYS_FSL_HAS_CCN504 */