blob: f7b49cb9fe6fbca308396ed1a338590eee8e3983 [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
York Suna84cd722014-06-23 15:15:54 -070020
21ENTRY(lowlevel_init)
22 mov x29, lr /* Save LR */
23
Mingkai Hu0e58b512015-10-26 19:47:50 +080024#ifdef CONFIG_FSL_LSCH3
Prabhakar Kushwahaedbbd252016-01-25 12:08:45 +053025
26 /* Set Wuo bit for RN-I 20 */
York Suncbe8e1c2016-04-04 11:41:26 -070027#ifdef CONFIG_LS2080A
Prabhakar Kushwahaedbbd252016-01-25 12:08:45 +053028 ldr x0, =CCI_AUX_CONTROL_BASE(20)
29 ldr x1, =0x00000010
30 bl ccn504_set_aux
31#endif
32
Scott Wooda814e662015-03-20 19:28:10 -070033 /* Add fully-coherent masters to DVM domain */
Bhupesh Sharma8238f342015-07-01 09:58:03 +053034 ldr x0, =CCI_MN_BASE
35 ldr x1, =CCI_MN_RNF_NODEID_LIST
36 ldr x2, =CCI_MN_DVM_DOMAIN_CTL_SET
37 bl ccn504_add_masters_to_dvm
38
39 /* Set all RN-I ports to QoS of 15 */
40 ldr x0, =CCI_S0_QOS_CONTROL_BASE(0)
41 ldr x1, =0x00FF000C
42 bl ccn504_set_qos
43 ldr x0, =CCI_S1_QOS_CONTROL_BASE(0)
44 ldr x1, =0x00FF000C
45 bl ccn504_set_qos
46 ldr x0, =CCI_S2_QOS_CONTROL_BASE(0)
47 ldr x1, =0x00FF000C
48 bl ccn504_set_qos
49
50 ldr x0, =CCI_S0_QOS_CONTROL_BASE(2)
51 ldr x1, =0x00FF000C
52 bl ccn504_set_qos
53 ldr x0, =CCI_S1_QOS_CONTROL_BASE(2)
54 ldr x1, =0x00FF000C
55 bl ccn504_set_qos
56 ldr x0, =CCI_S2_QOS_CONTROL_BASE(2)
57 ldr x1, =0x00FF000C
58 bl ccn504_set_qos
59
60 ldr x0, =CCI_S0_QOS_CONTROL_BASE(6)
61 ldr x1, =0x00FF000C
62 bl ccn504_set_qos
63 ldr x0, =CCI_S1_QOS_CONTROL_BASE(6)
64 ldr x1, =0x00FF000C
65 bl ccn504_set_qos
66 ldr x0, =CCI_S2_QOS_CONTROL_BASE(6)
67 ldr x1, =0x00FF000C
68 bl ccn504_set_qos
69
70 ldr x0, =CCI_S0_QOS_CONTROL_BASE(12)
71 ldr x1, =0x00FF000C
72 bl ccn504_set_qos
73 ldr x0, =CCI_S1_QOS_CONTROL_BASE(12)
74 ldr x1, =0x00FF000C
75 bl ccn504_set_qos
76 ldr x0, =CCI_S2_QOS_CONTROL_BASE(12)
77 ldr x1, =0x00FF000C
78 bl ccn504_set_qos
79
80 ldr x0, =CCI_S0_QOS_CONTROL_BASE(16)
81 ldr x1, =0x00FF000C
82 bl ccn504_set_qos
83 ldr x0, =CCI_S1_QOS_CONTROL_BASE(16)
84 ldr x1, =0x00FF000C
85 bl ccn504_set_qos
86 ldr x0, =CCI_S2_QOS_CONTROL_BASE(16)
87 ldr x1, =0x00FF000C
88 bl ccn504_set_qos
89
90 ldr x0, =CCI_S0_QOS_CONTROL_BASE(20)
91 ldr x1, =0x00FF000C
92 bl ccn504_set_qos
93 ldr x0, =CCI_S1_QOS_CONTROL_BASE(20)
94 ldr x1, =0x00FF000C
95 bl ccn504_set_qos
96 ldr x0, =CCI_S2_QOS_CONTROL_BASE(20)
97 ldr x1, =0x00FF000C
98 bl ccn504_set_qos
Mingkai Hu0e58b512015-10-26 19:47:50 +080099#endif
Scott Wooda814e662015-03-20 19:28:10 -0700100
Prabhakar Kushwahaae17df22016-06-03 18:41:26 +0530101#ifdef SMMU_BASE
York Suna84cd722014-06-23 15:15:54 -0700102 /* Set the SMMU page size in the sACR register */
103 ldr x1, =SMMU_BASE
104 ldr w0, [x1, #0x10]
105 orr w0, w0, #1 << 16 /* set sACR.pagesize to indicate 64K page */
106 str w0, [x1, #0x10]
Prabhakar Kushwahaae17df22016-06-03 18:41:26 +0530107#endif
York Suna84cd722014-06-23 15:15:54 -0700108
109 /* Initialize GIC Secure Bank Status */
110#if defined(CONFIG_GICV2) || defined(CONFIG_GICV3)
111 branch_if_slave x0, 1f
112 ldr x0, =GICD_BASE
113 bl gic_init_secure
1141:
115#ifdef CONFIG_GICV3
116 ldr x0, =GICR_BASE
117 bl gic_init_secure_percpu
118#elif defined(CONFIG_GICV2)
119 ldr x0, =GICD_BASE
120 ldr x1, =GICC_BASE
121 bl gic_init_secure_percpu
122#endif
123#endif
124
York Sun56cc3db2014-09-08 12:20:00 -0700125 branch_if_master x0, x1, 2f
York Suna84cd722014-06-23 15:15:54 -0700126
Mingkai Hu0e58b512015-10-26 19:47:50 +0800127#if defined(CONFIG_MP) && defined(CONFIG_ARMV8_MULTIENTRY)
York Sun56cc3db2014-09-08 12:20:00 -0700128 ldr x0, =secondary_boot_func
129 blr x0
Mingkai Hu0e58b512015-10-26 19:47:50 +0800130#endif
Bhupesh Sharmaa0c00ff2015-01-06 13:11:21 -0800131
Mingkai Hu0e58b512015-10-26 19:47:50 +08001322:
Bhupesh Sharmaa0c00ff2015-01-06 13:11:21 -0800133#ifdef CONFIG_FSL_TZPC_BP147
134 /* Set Non Secure access for all devices protected via TZPC */
135 ldr x1, =TZPCDECPROT_0_SET_BASE /* Decode Protection-0 Set Reg */
136 orr w0, w0, #1 << 3 /* DCFG_RESET is accessible from NS world */
137 str w0, [x1]
138
139 isb
140 dsb sy
141#endif
142
143#ifdef CONFIG_FSL_TZASC_400
Priyanka Jain583943b2016-11-17 12:29:54 +0530144 /*
145 * LS2080 and its personalities does not support TZASC
146 * So skip TZASC related operations
147 */
148 bl get_svr
149 lsr w0, w0, #16
150 ldr w1, =SVR_DEV_LS2080A
151 cmp w0, w1
152 b.eq 1f
153
Bhupesh Sharmaa0c00ff2015-01-06 13:11:21 -0800154 /* Set TZASC so that:
155 * a. We use only Region0 whose global secure write/read is EN
156 * b. We use only Region0 whose NSAID write/read is EN
157 *
158 * NOTE: As per the CCSR map doc, TZASC 3 and TZASC 4 are just
159 * placeholders.
160 */
161 ldr x1, =TZASC_GATE_KEEPER(0)
Priyanka Jain784269d2016-11-17 12:29:53 +0530162 ldr w0, [x1] /* Filter 0 Gate Keeper Register */
163 orr w0, w0, #1 << 0 /* Set open_request for Filter 0 */
164 str w0, [x1]
Bhupesh Sharmaa0c00ff2015-01-06 13:11:21 -0800165
166 ldr x1, =TZASC_GATE_KEEPER(1)
Priyanka Jain784269d2016-11-17 12:29:53 +0530167 ldr w0, [x1] /* Filter 0 Gate Keeper Register */
168 orr w0, w0, #1 << 0 /* Set open_request for Filter 0 */
169 str w0, [x1]
Bhupesh Sharmaa0c00ff2015-01-06 13:11:21 -0800170
171 ldr x1, =TZASC_REGION_ATTRIBUTES_0(0)
Priyanka Jain784269d2016-11-17 12:29:53 +0530172 ldr w0, [x1] /* Region-0 Attributes Register */
173 orr w0, w0, #1 << 31 /* Set Sec global write en, Bit[31] */
174 orr w0, w0, #1 << 30 /* Set Sec global read en, Bit[30] */
175 str w0, [x1]
Bhupesh Sharmaa0c00ff2015-01-06 13:11:21 -0800176
177 ldr x1, =TZASC_REGION_ATTRIBUTES_0(1)
Priyanka Jain784269d2016-11-17 12:29:53 +0530178 ldr w0, [x1] /* Region-1 Attributes Register */
179 orr w0, w0, #1 << 31 /* Set Sec global write en, Bit[31] */
180 orr w0, w0, #1 << 30 /* Set Sec global read en, Bit[30] */
181 str w0, [x1]
Bhupesh Sharmaa0c00ff2015-01-06 13:11:21 -0800182
183 ldr x1, =TZASC_REGION_ID_ACCESS_0(0)
184 ldr w0, [x1] /* Region-0 Access Register */
185 mov w0, #0xFFFFFFFF /* Set nsaid_wr_en and nsaid_rd_en */
186 str w0, [x1]
187
188 ldr x1, =TZASC_REGION_ID_ACCESS_0(1)
189 ldr w0, [x1] /* Region-1 Attributes Register */
190 mov w0, #0xFFFFFFFF /* Set nsaid_wr_en and nsaid_rd_en */
191 str w0, [x1]
192
193 isb
194 dsb sy
195#endif
Priyanka Jain583943b2016-11-17 12:29:54 +05301961:
York Sunbad49842016-09-26 08:09:24 -0700197#ifdef CONFIG_ARCH_LS1046A
Mingkai Hu48ddbe82016-09-07 17:56:08 +0800198 /* Initialize the L2 RAM latency */
199 mrs x1, S3_1_c11_c0_2
200 mov x0, #0x1C7
201 /* Clear L2 Tag RAM latency and L2 Data RAM latency */
202 bic x1, x1, x0
203 /* Set L2 data ram latency bits [2:0] */
204 orr x1, x1, #0x2
205 /* set L2 tag ram latency bits [8:6] */
206 orr x1, x1, #0x80
207 msr S3_1_c11_c0_2, x1
208 isb
209#endif
210
York Sun56cc3db2014-09-08 12:20:00 -0700211 mov lr, x29 /* Restore LR */
212 ret
213ENDPROC(lowlevel_init)
214
Prabhakar Kushwahad169ebe2016-06-03 18:41:31 +0530215#ifdef CONFIG_FSL_LSCH3
Priyanka Jain96b001f2016-11-17 12:29:51 +0530216 .globl get_svr
217get_svr:
218 ldr x1, =FSL_LSCH3_SVR
219 ldr w0, [x1]
220 ret
221
York Sun1ce575f2015-01-06 13:18:42 -0800222hnf_pstate_poll:
223 /* x0 has the desired status, return 0 for success, 1 for timeout
224 * clobber x1, x2, x3, x4, x6, x7
225 */
226 mov x1, x0
227 mov x7, #0 /* flag for timeout */
228 mrs x3, cntpct_el0 /* read timer */
229 add x3, x3, #1200 /* timeout after 100 microseconds */
230 mov x0, #0x18
231 movk x0, #0x420, lsl #16 /* HNF0_PSTATE_STATUS */
232 mov w6, #8 /* HN-F node count */
2331:
234 ldr x2, [x0]
235 cmp x2, x1 /* check status */
236 b.eq 2f
237 mrs x4, cntpct_el0
238 cmp x4, x3
239 b.ls 1b
240 mov x7, #1 /* timeout */
241 b 3f
2422:
243 add x0, x0, #0x10000 /* move to next node */
244 subs w6, w6, #1
245 cbnz w6, 1b
2463:
247 mov x0, x7
248 ret
249
250hnf_set_pstate:
251 /* x0 has the desired state, clobber x1, x2, x6 */
252 mov x1, x0
253 /* power state to SFONLY */
254 mov w6, #8 /* HN-F node count */
255 mov x0, #0x10
256 movk x0, #0x420, lsl #16 /* HNF0_PSTATE_REQ */
2571: /* set pstate to sfonly */
258 ldr x2, [x0]
259 and x2, x2, #0xfffffffffffffffc /* & HNFPSTAT_MASK */
260 orr x2, x2, x1
261 str x2, [x0]
262 add x0, x0, #0x10000 /* move to next node */
263 subs w6, w6, #1
264 cbnz w6, 1b
265
266 ret
267
Stephen Warrenddb0f632016-10-19 15:18:46 -0600268ENTRY(__asm_flush_l3_dcache)
York Sun1ce575f2015-01-06 13:18:42 -0800269 /*
270 * Return status in x0
271 * success 0
272 * tmeout 1 for setting SFONLY, 2 for FAM, 3 for both
273 */
274 mov x29, lr
275 mov x8, #0
276
277 dsb sy
278 mov x0, #0x1 /* HNFPSTAT_SFONLY */
279 bl hnf_set_pstate
280
281 mov x0, #0x4 /* SFONLY status */
282 bl hnf_pstate_poll
283 cbz x0, 1f
284 mov x8, #1 /* timeout */
2851:
286 dsb sy
287 mov x0, #0x3 /* HNFPSTAT_FAM */
288 bl hnf_set_pstate
289
290 mov x0, #0xc /* FAM status */
291 bl hnf_pstate_poll
292 cbz x0, 1f
293 add x8, x8, #0x2
2941:
295 mov x0, x8
296 mov lr, x29
297 ret
Stephen Warrenddb0f632016-10-19 15:18:46 -0600298ENDPROC(__asm_flush_l3_dcache)
Prabhakar Kushwahad169ebe2016-06-03 18:41:31 +0530299#endif
York Sun1ce575f2015-01-06 13:18:42 -0800300
Mingkai Hu0e58b512015-10-26 19:47:50 +0800301#ifdef CONFIG_MP
York Sun56cc3db2014-09-08 12:20:00 -0700302 /* Keep literals not used by the secondary boot code outside it */
303 .ltorg
304
305 /* Using 64 bit alignment since the spin table is accessed as data */
306 .align 4
307 .global secondary_boot_code
308 /* Secondary Boot Code starts here */
309secondary_boot_code:
310 .global __spin_table
311__spin_table:
312 .space CONFIG_MAX_CPUS*SPIN_TABLE_ELEM_SIZE
313
314 .align 2
315ENTRY(secondary_boot_func)
York Suna84cd722014-06-23 15:15:54 -0700316 /*
York Sun56cc3db2014-09-08 12:20:00 -0700317 * MPIDR_EL1 Fields:
318 * MPIDR[1:0] = AFF0_CPUID <- Core ID (0,1)
319 * MPIDR[7:2] = AFF0_RES
320 * MPIDR[15:8] = AFF1_CLUSTERID <- Cluster ID (0,1,2,3)
321 * MPIDR[23:16] = AFF2_CLUSTERID
322 * MPIDR[24] = MT
323 * MPIDR[29:25] = RES0
324 * MPIDR[30] = U
325 * MPIDR[31] = ME
326 * MPIDR[39:32] = AFF3
327 *
328 * Linear Processor ID (LPID) calculation from MPIDR_EL1:
329 * (We only use AFF0_CPUID and AFF1_CLUSTERID for now
330 * until AFF2_CLUSTERID and AFF3 have non-zero values)
331 *
332 * LPID = MPIDR[15:8] | MPIDR[1:0]
York Suna84cd722014-06-23 15:15:54 -0700333 */
York Sun56cc3db2014-09-08 12:20:00 -0700334 mrs x0, mpidr_el1
335 ubfm x1, x0, #8, #15
336 ubfm x2, x0, #0, #1
337 orr x10, x2, x1, lsl #2 /* x10 has LPID */
338 ubfm x9, x0, #0, #15 /* x9 contains MPIDR[15:0] */
York Suna84cd722014-06-23 15:15:54 -0700339 /*
York Sun56cc3db2014-09-08 12:20:00 -0700340 * offset of the spin table element for this core from start of spin
341 * table (each elem is padded to 64 bytes)
York Suna84cd722014-06-23 15:15:54 -0700342 */
York Sun56cc3db2014-09-08 12:20:00 -0700343 lsl x1, x10, #6
344 ldr x0, =__spin_table
345 /* physical address of this cpus spin table element */
346 add x11, x1, x0
347
York Sun77a10972015-03-20 19:28:08 -0700348 ldr x0, =__real_cntfrq
349 ldr x0, [x0]
350 msr cntfrq_el0, x0 /* set with real frequency */
York Sun56cc3db2014-09-08 12:20:00 -0700351 str x9, [x11, #16] /* LPID */
352 mov x4, #1
353 str x4, [x11, #8] /* STATUS */
354 dsb sy
355#if defined(CONFIG_GICV3)
356 gic_wait_for_interrupt_m x0
357#elif defined(CONFIG_GICV2)
358 ldr x0, =GICC_BASE
359 gic_wait_for_interrupt_m x0, w1
360#endif
361
362 bl secondary_switch_to_el2
York Suna84cd722014-06-23 15:15:54 -0700363#ifdef CONFIG_ARMV8_SWITCH_TO_EL1
York Sun56cc3db2014-09-08 12:20:00 -0700364 bl secondary_switch_to_el1
York Suna84cd722014-06-23 15:15:54 -0700365#endif
York Suna84cd722014-06-23 15:15:54 -0700366
York Sun56cc3db2014-09-08 12:20:00 -0700367slave_cpu:
368 wfe
369 ldr x0, [x11]
370 cbz x0, slave_cpu
371#ifndef CONFIG_ARMV8_SWITCH_TO_EL1
372 mrs x1, sctlr_el2
373#else
374 mrs x1, sctlr_el1
375#endif
376 tbz x1, #25, cpu_is_le
377 rev x0, x0 /* BE to LE conversion */
378cpu_is_le:
379 br x0 /* branch to the given address */
380ENDPROC(secondary_boot_func)
381
382ENTRY(secondary_switch_to_el2)
383 switch_el x0, 1f, 0f, 0f
3840: ret
3851: armv8_switch_to_el2_m x0
386ENDPROC(secondary_switch_to_el2)
387
388ENTRY(secondary_switch_to_el1)
389 switch_el x0, 0f, 1f, 0f
3900: ret
3911: armv8_switch_to_el1_m x0, x1
392ENDPROC(secondary_switch_to_el1)
393
394 /* Ensure that the literals used by the secondary boot code are
395 * assembled within it (this is required so that we can protect
396 * this area with a single memreserve region
397 */
398 .ltorg
399
400 /* 64 bit alignment for elements accessed as data */
401 .align 4
York Sun77a10972015-03-20 19:28:08 -0700402 .global __real_cntfrq
403__real_cntfrq:
404 .quad COUNTER_FREQUENCY
York Sun56cc3db2014-09-08 12:20:00 -0700405 .globl __secondary_boot_code_size
406 .type __secondary_boot_code_size, %object
407 /* Secondary Boot Code ends here */
408__secondary_boot_code_size:
409 .quad .-secondary_boot_code
Mingkai Hu0e58b512015-10-26 19:47:50 +0800410#endif