blob: 340445922d7e5a809dd6f88b369599f59f0e414b [file] [log] [blame]
York Suna84cd722014-06-23 15:15:54 -07001/*
Mingkai Hu0e58b512015-10-26 19:47:50 +08002 * (C) Copyright 2014-2015 Freescale Semiconductor
York Suna84cd722014-06-23 15:15:54 -07003 *
4 * SPDX-License-Identifier: GPL-2.0+
5 *
6 * 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>
Mingkai Hu0e58b512015-10-26 19:47:50 +080013#ifdef CONFIG_MP
14#include <asm/arch/mp.h>
15#endif
Priyanka Jain96b001f2016-11-17 12:29:51 +053016#ifdef CONFIG_FSL_LSCH3
17#include <asm/arch-fsl-layerscape/immap_lsch3.h>
Priyanka Jain583943b2016-11-17 12:29:54 +053018#include <asm/arch-fsl-layerscape/soc.h>
Priyanka Jain96b001f2016-11-17 12:29:51 +053019#endif
Alison Wang73818d52016-11-10 10:49:03 +080020#include <asm/u-boot.h>
York Suna84cd722014-06-23 15:15:54 -070021
22ENTRY(lowlevel_init)
23 mov x29, lr /* Save LR */
24
Mingkai Hu0e58b512015-10-26 19:47:50 +080025#ifdef CONFIG_FSL_LSCH3
Prabhakar Kushwahaedbbd252016-01-25 12:08:45 +053026
27 /* Set Wuo bit for RN-I 20 */
York Suncbe8e1c2016-04-04 11:41:26 -070028#ifdef CONFIG_LS2080A
Prabhakar Kushwahaedbbd252016-01-25 12:08:45 +053029 ldr x0, =CCI_AUX_CONTROL_BASE(20)
30 ldr x1, =0x00000010
31 bl ccn504_set_aux
Priyanka Jain60850792016-11-09 12:27:54 +053032
33 /*
34 * Set forced-order mode in RNI-6, RNI-20
35 * This is required for performance optimization on LS2088A
36 * LS2080A family does not support setting forced-order mode,
37 * so skip this operation for LS2080A family
38 */
39 bl get_svr
40 lsr w0, w0, #16
41 ldr w1, =SVR_DEV_LS2080A
42 cmp w0, w1
43 b.eq 1f
44
45 ldr x0, =CCI_AUX_CONTROL_BASE(6)
46 ldr x1, =0x00000020
47 bl ccn504_set_aux
48 ldr x0, =CCI_AUX_CONTROL_BASE(20)
49 ldr x1, =0x00000020
50 bl ccn504_set_aux
511:
Prabhakar Kushwahaedbbd252016-01-25 12:08:45 +053052#endif
53
Scott Wooda814e662015-03-20 19:28:10 -070054 /* Add fully-coherent masters to DVM domain */
Bhupesh Sharma8238f342015-07-01 09:58:03 +053055 ldr x0, =CCI_MN_BASE
56 ldr x1, =CCI_MN_RNF_NODEID_LIST
57 ldr x2, =CCI_MN_DVM_DOMAIN_CTL_SET
58 bl ccn504_add_masters_to_dvm
59
60 /* Set all RN-I ports to QoS of 15 */
61 ldr x0, =CCI_S0_QOS_CONTROL_BASE(0)
62 ldr x1, =0x00FF000C
63 bl ccn504_set_qos
64 ldr x0, =CCI_S1_QOS_CONTROL_BASE(0)
65 ldr x1, =0x00FF000C
66 bl ccn504_set_qos
67 ldr x0, =CCI_S2_QOS_CONTROL_BASE(0)
68 ldr x1, =0x00FF000C
69 bl ccn504_set_qos
70
71 ldr x0, =CCI_S0_QOS_CONTROL_BASE(2)
72 ldr x1, =0x00FF000C
73 bl ccn504_set_qos
74 ldr x0, =CCI_S1_QOS_CONTROL_BASE(2)
75 ldr x1, =0x00FF000C
76 bl ccn504_set_qos
77 ldr x0, =CCI_S2_QOS_CONTROL_BASE(2)
78 ldr x1, =0x00FF000C
79 bl ccn504_set_qos
80
81 ldr x0, =CCI_S0_QOS_CONTROL_BASE(6)
82 ldr x1, =0x00FF000C
83 bl ccn504_set_qos
84 ldr x0, =CCI_S1_QOS_CONTROL_BASE(6)
85 ldr x1, =0x00FF000C
86 bl ccn504_set_qos
87 ldr x0, =CCI_S2_QOS_CONTROL_BASE(6)
88 ldr x1, =0x00FF000C
89 bl ccn504_set_qos
90
91 ldr x0, =CCI_S0_QOS_CONTROL_BASE(12)
92 ldr x1, =0x00FF000C
93 bl ccn504_set_qos
94 ldr x0, =CCI_S1_QOS_CONTROL_BASE(12)
95 ldr x1, =0x00FF000C
96 bl ccn504_set_qos
97 ldr x0, =CCI_S2_QOS_CONTROL_BASE(12)
98 ldr x1, =0x00FF000C
99 bl ccn504_set_qos
100
101 ldr x0, =CCI_S0_QOS_CONTROL_BASE(16)
102 ldr x1, =0x00FF000C
103 bl ccn504_set_qos
104 ldr x0, =CCI_S1_QOS_CONTROL_BASE(16)
105 ldr x1, =0x00FF000C
106 bl ccn504_set_qos
107 ldr x0, =CCI_S2_QOS_CONTROL_BASE(16)
108 ldr x1, =0x00FF000C
109 bl ccn504_set_qos
110
111 ldr x0, =CCI_S0_QOS_CONTROL_BASE(20)
112 ldr x1, =0x00FF000C
113 bl ccn504_set_qos
114 ldr x0, =CCI_S1_QOS_CONTROL_BASE(20)
115 ldr x1, =0x00FF000C
116 bl ccn504_set_qos
117 ldr x0, =CCI_S2_QOS_CONTROL_BASE(20)
118 ldr x1, =0x00FF000C
119 bl ccn504_set_qos
Mingkai Hu0e58b512015-10-26 19:47:50 +0800120#endif
Scott Wooda814e662015-03-20 19:28:10 -0700121
Prabhakar Kushwahaae17df22016-06-03 18:41:26 +0530122#ifdef SMMU_BASE
York Suna84cd722014-06-23 15:15:54 -0700123 /* Set the SMMU page size in the sACR register */
124 ldr x1, =SMMU_BASE
125 ldr w0, [x1, #0x10]
126 orr w0, w0, #1 << 16 /* set sACR.pagesize to indicate 64K page */
127 str w0, [x1, #0x10]
Prabhakar Kushwahaae17df22016-06-03 18:41:26 +0530128#endif
York Suna84cd722014-06-23 15:15:54 -0700129
130 /* Initialize GIC Secure Bank Status */
131#if defined(CONFIG_GICV2) || defined(CONFIG_GICV3)
132 branch_if_slave x0, 1f
133 ldr x0, =GICD_BASE
134 bl gic_init_secure
1351:
136#ifdef CONFIG_GICV3
137 ldr x0, =GICR_BASE
138 bl gic_init_secure_percpu
139#elif defined(CONFIG_GICV2)
140 ldr x0, =GICD_BASE
141 ldr x1, =GICC_BASE
142 bl gic_init_secure_percpu
143#endif
144#endif
145
York Sun56cc3db2014-09-08 12:20:00 -0700146 branch_if_master x0, x1, 2f
York Suna84cd722014-06-23 15:15:54 -0700147
Mingkai Hu0e58b512015-10-26 19:47:50 +0800148#if defined(CONFIG_MP) && defined(CONFIG_ARMV8_MULTIENTRY)
York Sun56cc3db2014-09-08 12:20:00 -0700149 ldr x0, =secondary_boot_func
150 blr x0
Mingkai Hu0e58b512015-10-26 19:47:50 +0800151#endif
Bhupesh Sharmaa0c00ff2015-01-06 13:11:21 -0800152
Mingkai Hu0e58b512015-10-26 19:47:50 +08001532:
Bhupesh Sharmaa0c00ff2015-01-06 13:11:21 -0800154#ifdef CONFIG_FSL_TZPC_BP147
155 /* Set Non Secure access for all devices protected via TZPC */
156 ldr x1, =TZPCDECPROT_0_SET_BASE /* Decode Protection-0 Set Reg */
157 orr w0, w0, #1 << 3 /* DCFG_RESET is accessible from NS world */
158 str w0, [x1]
159
160 isb
161 dsb sy
162#endif
163
164#ifdef CONFIG_FSL_TZASC_400
Priyanka Jain583943b2016-11-17 12:29:54 +0530165 /*
166 * LS2080 and its personalities does not support TZASC
167 * So skip TZASC related operations
168 */
169 bl get_svr
170 lsr w0, w0, #16
171 ldr w1, =SVR_DEV_LS2080A
172 cmp w0, w1
173 b.eq 1f
174
Bhupesh Sharmaa0c00ff2015-01-06 13:11:21 -0800175 /* Set TZASC so that:
176 * a. We use only Region0 whose global secure write/read is EN
177 * b. We use only Region0 whose NSAID write/read is EN
178 *
179 * NOTE: As per the CCSR map doc, TZASC 3 and TZASC 4 are just
180 * placeholders.
181 */
182 ldr x1, =TZASC_GATE_KEEPER(0)
Priyanka Jain784269d2016-11-17 12:29:53 +0530183 ldr w0, [x1] /* Filter 0 Gate Keeper Register */
184 orr w0, w0, #1 << 0 /* Set open_request for Filter 0 */
185 str w0, [x1]
Bhupesh Sharmaa0c00ff2015-01-06 13:11:21 -0800186
187 ldr x1, =TZASC_GATE_KEEPER(1)
Priyanka Jain784269d2016-11-17 12:29:53 +0530188 ldr w0, [x1] /* Filter 0 Gate Keeper Register */
189 orr w0, w0, #1 << 0 /* Set open_request for Filter 0 */
190 str w0, [x1]
Bhupesh Sharmaa0c00ff2015-01-06 13:11:21 -0800191
192 ldr x1, =TZASC_REGION_ATTRIBUTES_0(0)
Priyanka Jain784269d2016-11-17 12:29:53 +0530193 ldr w0, [x1] /* Region-0 Attributes Register */
194 orr w0, w0, #1 << 31 /* Set Sec global write en, Bit[31] */
195 orr w0, w0, #1 << 30 /* Set Sec global read en, Bit[30] */
196 str w0, [x1]
Bhupesh Sharmaa0c00ff2015-01-06 13:11:21 -0800197
198 ldr x1, =TZASC_REGION_ATTRIBUTES_0(1)
Priyanka Jain784269d2016-11-17 12:29:53 +0530199 ldr w0, [x1] /* Region-1 Attributes Register */
200 orr w0, w0, #1 << 31 /* Set Sec global write en, Bit[31] */
201 orr w0, w0, #1 << 30 /* Set Sec global read en, Bit[30] */
202 str w0, [x1]
Bhupesh Sharmaa0c00ff2015-01-06 13:11:21 -0800203
204 ldr x1, =TZASC_REGION_ID_ACCESS_0(0)
205 ldr w0, [x1] /* Region-0 Access Register */
206 mov w0, #0xFFFFFFFF /* Set nsaid_wr_en and nsaid_rd_en */
207 str w0, [x1]
208
209 ldr x1, =TZASC_REGION_ID_ACCESS_0(1)
210 ldr w0, [x1] /* Region-1 Attributes Register */
211 mov w0, #0xFFFFFFFF /* Set nsaid_wr_en and nsaid_rd_en */
212 str w0, [x1]
213
214 isb
215 dsb sy
216#endif
Priyanka Jain583943b2016-11-17 12:29:54 +05302171:
York Sunbad49842016-09-26 08:09:24 -0700218#ifdef CONFIG_ARCH_LS1046A
Mingkai Hu48ddbe82016-09-07 17:56:08 +0800219 /* Initialize the L2 RAM latency */
220 mrs x1, S3_1_c11_c0_2
221 mov x0, #0x1C7
222 /* Clear L2 Tag RAM latency and L2 Data RAM latency */
223 bic x1, x1, x0
224 /* Set L2 data ram latency bits [2:0] */
225 orr x1, x1, #0x2
226 /* set L2 tag ram latency bits [8:6] */
227 orr x1, x1, #0x80
228 msr S3_1_c11_c0_2, x1
229 isb
230#endif
231
York Sun56cc3db2014-09-08 12:20:00 -0700232 mov lr, x29 /* Restore LR */
233 ret
234ENDPROC(lowlevel_init)
235
Prabhakar Kushwahad169ebe2016-06-03 18:41:31 +0530236#ifdef CONFIG_FSL_LSCH3
Priyanka Jain96b001f2016-11-17 12:29:51 +0530237 .globl get_svr
238get_svr:
239 ldr x1, =FSL_LSCH3_SVR
240 ldr w0, [x1]
241 ret
242
York Sun1ce575f2015-01-06 13:18:42 -0800243hnf_pstate_poll:
244 /* x0 has the desired status, return 0 for success, 1 for timeout
245 * clobber x1, x2, x3, x4, x6, x7
246 */
247 mov x1, x0
248 mov x7, #0 /* flag for timeout */
249 mrs x3, cntpct_el0 /* read timer */
250 add x3, x3, #1200 /* timeout after 100 microseconds */
251 mov x0, #0x18
252 movk x0, #0x420, lsl #16 /* HNF0_PSTATE_STATUS */
253 mov w6, #8 /* HN-F node count */
2541:
255 ldr x2, [x0]
256 cmp x2, x1 /* check status */
257 b.eq 2f
258 mrs x4, cntpct_el0
259 cmp x4, x3
260 b.ls 1b
261 mov x7, #1 /* timeout */
262 b 3f
2632:
264 add x0, x0, #0x10000 /* move to next node */
265 subs w6, w6, #1
266 cbnz w6, 1b
2673:
268 mov x0, x7
269 ret
270
271hnf_set_pstate:
272 /* x0 has the desired state, clobber x1, x2, x6 */
273 mov x1, x0
274 /* power state to SFONLY */
275 mov w6, #8 /* HN-F node count */
276 mov x0, #0x10
277 movk x0, #0x420, lsl #16 /* HNF0_PSTATE_REQ */
2781: /* set pstate to sfonly */
279 ldr x2, [x0]
280 and x2, x2, #0xfffffffffffffffc /* & HNFPSTAT_MASK */
281 orr x2, x2, x1
282 str x2, [x0]
283 add x0, x0, #0x10000 /* move to next node */
284 subs w6, w6, #1
285 cbnz w6, 1b
286
287 ret
288
Stephen Warrenddb0f632016-10-19 15:18:46 -0600289ENTRY(__asm_flush_l3_dcache)
York Sun1ce575f2015-01-06 13:18:42 -0800290 /*
291 * Return status in x0
292 * success 0
293 * tmeout 1 for setting SFONLY, 2 for FAM, 3 for both
294 */
295 mov x29, lr
296 mov x8, #0
297
298 dsb sy
299 mov x0, #0x1 /* HNFPSTAT_SFONLY */
300 bl hnf_set_pstate
301
302 mov x0, #0x4 /* SFONLY status */
303 bl hnf_pstate_poll
304 cbz x0, 1f
305 mov x8, #1 /* timeout */
3061:
307 dsb sy
308 mov x0, #0x3 /* HNFPSTAT_FAM */
309 bl hnf_set_pstate
310
311 mov x0, #0xc /* FAM status */
312 bl hnf_pstate_poll
313 cbz x0, 1f
314 add x8, x8, #0x2
3151:
316 mov x0, x8
317 mov lr, x29
318 ret
Stephen Warrenddb0f632016-10-19 15:18:46 -0600319ENDPROC(__asm_flush_l3_dcache)
Prabhakar Kushwahad169ebe2016-06-03 18:41:31 +0530320#endif
York Sun1ce575f2015-01-06 13:18:42 -0800321
Mingkai Hu0e58b512015-10-26 19:47:50 +0800322#ifdef CONFIG_MP
York Sun56cc3db2014-09-08 12:20:00 -0700323 /* Keep literals not used by the secondary boot code outside it */
324 .ltorg
325
326 /* Using 64 bit alignment since the spin table is accessed as data */
327 .align 4
328 .global secondary_boot_code
329 /* Secondary Boot Code starts here */
330secondary_boot_code:
331 .global __spin_table
332__spin_table:
333 .space CONFIG_MAX_CPUS*SPIN_TABLE_ELEM_SIZE
334
335 .align 2
336ENTRY(secondary_boot_func)
York Suna84cd722014-06-23 15:15:54 -0700337 /*
York Sun56cc3db2014-09-08 12:20:00 -0700338 * MPIDR_EL1 Fields:
339 * MPIDR[1:0] = AFF0_CPUID <- Core ID (0,1)
340 * MPIDR[7:2] = AFF0_RES
341 * MPIDR[15:8] = AFF1_CLUSTERID <- Cluster ID (0,1,2,3)
342 * MPIDR[23:16] = AFF2_CLUSTERID
343 * MPIDR[24] = MT
344 * MPIDR[29:25] = RES0
345 * MPIDR[30] = U
346 * MPIDR[31] = ME
347 * MPIDR[39:32] = AFF3
348 *
349 * Linear Processor ID (LPID) calculation from MPIDR_EL1:
350 * (We only use AFF0_CPUID and AFF1_CLUSTERID for now
351 * until AFF2_CLUSTERID and AFF3 have non-zero values)
352 *
353 * LPID = MPIDR[15:8] | MPIDR[1:0]
York Suna84cd722014-06-23 15:15:54 -0700354 */
York Sun56cc3db2014-09-08 12:20:00 -0700355 mrs x0, mpidr_el1
356 ubfm x1, x0, #8, #15
357 ubfm x2, x0, #0, #1
358 orr x10, x2, x1, lsl #2 /* x10 has LPID */
359 ubfm x9, x0, #0, #15 /* x9 contains MPIDR[15:0] */
York Suna84cd722014-06-23 15:15:54 -0700360 /*
York Sun56cc3db2014-09-08 12:20:00 -0700361 * offset of the spin table element for this core from start of spin
362 * table (each elem is padded to 64 bytes)
York Suna84cd722014-06-23 15:15:54 -0700363 */
York Sun56cc3db2014-09-08 12:20:00 -0700364 lsl x1, x10, #6
365 ldr x0, =__spin_table
366 /* physical address of this cpus spin table element */
367 add x11, x1, x0
368
York Sun77a10972015-03-20 19:28:08 -0700369 ldr x0, =__real_cntfrq
370 ldr x0, [x0]
371 msr cntfrq_el0, x0 /* set with real frequency */
York Sun56cc3db2014-09-08 12:20:00 -0700372 str x9, [x11, #16] /* LPID */
373 mov x4, #1
374 str x4, [x11, #8] /* STATUS */
375 dsb sy
376#if defined(CONFIG_GICV3)
377 gic_wait_for_interrupt_m x0
378#elif defined(CONFIG_GICV2)
379 ldr x0, =GICC_BASE
380 gic_wait_for_interrupt_m x0, w1
381#endif
382
York Sun56cc3db2014-09-08 12:20:00 -0700383slave_cpu:
384 wfe
385 ldr x0, [x11]
386 cbz x0, slave_cpu
387#ifndef CONFIG_ARMV8_SWITCH_TO_EL1
388 mrs x1, sctlr_el2
389#else
390 mrs x1, sctlr_el1
391#endif
392 tbz x1, #25, cpu_is_le
393 rev x0, x0 /* BE to LE conversion */
394cpu_is_le:
Alison Wang73818d52016-11-10 10:49:03 +0800395 ldr x5, [x11, #24]
396 ldr x6, =IH_ARCH_DEFAULT
397 cmp x6, x5
398 b.eq 1f
399
400#ifdef CONFIG_ARMV8_SWITCH_TO_EL1
401 adr x3, secondary_switch_to_el1
402 ldr x4, =ES_TO_AARCH64
403#else
404 ldr x3, [x11]
405 ldr x4, =ES_TO_AARCH32
406#endif
407 bl secondary_switch_to_el2
408
4091:
410#ifdef CONFIG_ARMV8_SWITCH_TO_EL1
411 adr x3, secondary_switch_to_el1
412#else
413 ldr x3, [x11]
414#endif
415 ldr x4, =ES_TO_AARCH64
416 bl secondary_switch_to_el2
417
York Sun56cc3db2014-09-08 12:20:00 -0700418ENDPROC(secondary_boot_func)
419
420ENTRY(secondary_switch_to_el2)
Alison Wang73818d52016-11-10 10:49:03 +0800421 switch_el x5, 1f, 0f, 0f
York Sun56cc3db2014-09-08 12:20:00 -07004220: ret
Alison Wang73818d52016-11-10 10:49:03 +08004231: armv8_switch_to_el2_m x3, x4, x5
York Sun56cc3db2014-09-08 12:20:00 -0700424ENDPROC(secondary_switch_to_el2)
425
426ENTRY(secondary_switch_to_el1)
Alison Wang73818d52016-11-10 10:49:03 +0800427 mrs x0, mpidr_el1
428 ubfm x1, x0, #8, #15
429 ubfm x2, x0, #0, #1
430 orr x10, x2, x1, lsl #2 /* x10 has LPID */
431
432 lsl x1, x10, #6
433 ldr x0, =__spin_table
434 /* physical address of this cpus spin table element */
435 add x11, x1, x0
436
437 ldr x3, [x11]
438
439 ldr x5, [x11, #24]
440 ldr x6, =IH_ARCH_DEFAULT
441 cmp x6, x5
442 b.eq 2f
443
444 ldr x4, =ES_TO_AARCH32
445 bl switch_to_el1
446
4472: ldr x4, =ES_TO_AARCH64
448
449switch_to_el1:
450 switch_el x5, 0f, 1f, 0f
York Sun56cc3db2014-09-08 12:20:00 -07004510: ret
Alison Wang73818d52016-11-10 10:49:03 +08004521: armv8_switch_to_el1_m x3, x4, x5
York Sun56cc3db2014-09-08 12:20:00 -0700453ENDPROC(secondary_switch_to_el1)
454
455 /* Ensure that the literals used by the secondary boot code are
456 * assembled within it (this is required so that we can protect
457 * this area with a single memreserve region
458 */
459 .ltorg
460
461 /* 64 bit alignment for elements accessed as data */
462 .align 4
York Sun77a10972015-03-20 19:28:08 -0700463 .global __real_cntfrq
464__real_cntfrq:
465 .quad COUNTER_FREQUENCY
York Sun56cc3db2014-09-08 12:20:00 -0700466 .globl __secondary_boot_code_size
467 .type __secondary_boot_code_size, %object
468 /* Secondary Boot Code ends here */
469__secondary_boot_code_size:
470 .quad .-secondary_boot_code
Mingkai Hu0e58b512015-10-26 19:47:50 +0800471#endif