blob: 6b19d36f115fce5d5647ff3edd9db98a6781e608 [file] [log] [blame]
York Suna84cd722014-06-23 15:15:54 -07001/*
2 * (C) Copyright 2014 Freescale Semiconductor
3 *
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>
York Sun56cc3db2014-09-08 12:20:00 -070013#include "mp.h"
York Suna84cd722014-06-23 15:15:54 -070014
15ENTRY(lowlevel_init)
16 mov x29, lr /* Save LR */
17
Scott Wooda814e662015-03-20 19:28:10 -070018 /* Add fully-coherent masters to DVM domain */
Bhupesh Sharma8238f342015-07-01 09:58:03 +053019 ldr x0, =CCI_MN_BASE
20 ldr x1, =CCI_MN_RNF_NODEID_LIST
21 ldr x2, =CCI_MN_DVM_DOMAIN_CTL_SET
22 bl ccn504_add_masters_to_dvm
23
24 /* Set all RN-I ports to QoS of 15 */
25 ldr x0, =CCI_S0_QOS_CONTROL_BASE(0)
26 ldr x1, =0x00FF000C
27 bl ccn504_set_qos
28 ldr x0, =CCI_S1_QOS_CONTROL_BASE(0)
29 ldr x1, =0x00FF000C
30 bl ccn504_set_qos
31 ldr x0, =CCI_S2_QOS_CONTROL_BASE(0)
32 ldr x1, =0x00FF000C
33 bl ccn504_set_qos
34
35 ldr x0, =CCI_S0_QOS_CONTROL_BASE(2)
36 ldr x1, =0x00FF000C
37 bl ccn504_set_qos
38 ldr x0, =CCI_S1_QOS_CONTROL_BASE(2)
39 ldr x1, =0x00FF000C
40 bl ccn504_set_qos
41 ldr x0, =CCI_S2_QOS_CONTROL_BASE(2)
42 ldr x1, =0x00FF000C
43 bl ccn504_set_qos
44
45 ldr x0, =CCI_S0_QOS_CONTROL_BASE(6)
46 ldr x1, =0x00FF000C
47 bl ccn504_set_qos
48 ldr x0, =CCI_S1_QOS_CONTROL_BASE(6)
49 ldr x1, =0x00FF000C
50 bl ccn504_set_qos
51 ldr x0, =CCI_S2_QOS_CONTROL_BASE(6)
52 ldr x1, =0x00FF000C
53 bl ccn504_set_qos
54
55 ldr x0, =CCI_S0_QOS_CONTROL_BASE(12)
56 ldr x1, =0x00FF000C
57 bl ccn504_set_qos
58 ldr x0, =CCI_S1_QOS_CONTROL_BASE(12)
59 ldr x1, =0x00FF000C
60 bl ccn504_set_qos
61 ldr x0, =CCI_S2_QOS_CONTROL_BASE(12)
62 ldr x1, =0x00FF000C
63 bl ccn504_set_qos
64
65 ldr x0, =CCI_S0_QOS_CONTROL_BASE(16)
66 ldr x1, =0x00FF000C
67 bl ccn504_set_qos
68 ldr x0, =CCI_S1_QOS_CONTROL_BASE(16)
69 ldr x1, =0x00FF000C
70 bl ccn504_set_qos
71 ldr x0, =CCI_S2_QOS_CONTROL_BASE(16)
72 ldr x1, =0x00FF000C
73 bl ccn504_set_qos
74
75 ldr x0, =CCI_S0_QOS_CONTROL_BASE(20)
76 ldr x1, =0x00FF000C
77 bl ccn504_set_qos
78 ldr x0, =CCI_S1_QOS_CONTROL_BASE(20)
79 ldr x1, =0x00FF000C
80 bl ccn504_set_qos
81 ldr x0, =CCI_S2_QOS_CONTROL_BASE(20)
82 ldr x1, =0x00FF000C
83 bl ccn504_set_qos
Scott Wooda814e662015-03-20 19:28:10 -070084
York Suna84cd722014-06-23 15:15:54 -070085 /* Set the SMMU page size in the sACR register */
86 ldr x1, =SMMU_BASE
87 ldr w0, [x1, #0x10]
88 orr w0, w0, #1 << 16 /* set sACR.pagesize to indicate 64K page */
89 str w0, [x1, #0x10]
90
91 /* Initialize GIC Secure Bank Status */
92#if defined(CONFIG_GICV2) || defined(CONFIG_GICV3)
93 branch_if_slave x0, 1f
94 ldr x0, =GICD_BASE
95 bl gic_init_secure
961:
97#ifdef CONFIG_GICV3
98 ldr x0, =GICR_BASE
99 bl gic_init_secure_percpu
100#elif defined(CONFIG_GICV2)
101 ldr x0, =GICD_BASE
102 ldr x1, =GICC_BASE
103 bl gic_init_secure_percpu
104#endif
105#endif
106
York Sun56cc3db2014-09-08 12:20:00 -0700107 branch_if_master x0, x1, 2f
York Suna84cd722014-06-23 15:15:54 -0700108
York Sun56cc3db2014-09-08 12:20:00 -0700109 ldr x0, =secondary_boot_func
110 blr x0
1112:
Bhupesh Sharmaa0c00ff2015-01-06 13:11:21 -0800112
113#ifdef CONFIG_FSL_TZPC_BP147
114 /* Set Non Secure access for all devices protected via TZPC */
115 ldr x1, =TZPCDECPROT_0_SET_BASE /* Decode Protection-0 Set Reg */
116 orr w0, w0, #1 << 3 /* DCFG_RESET is accessible from NS world */
117 str w0, [x1]
118
119 isb
120 dsb sy
121#endif
122
123#ifdef CONFIG_FSL_TZASC_400
124 /* Set TZASC so that:
125 * a. We use only Region0 whose global secure write/read is EN
126 * b. We use only Region0 whose NSAID write/read is EN
127 *
128 * NOTE: As per the CCSR map doc, TZASC 3 and TZASC 4 are just
129 * placeholders.
130 */
131 ldr x1, =TZASC_GATE_KEEPER(0)
132 ldr x0, [x1] /* Filter 0 Gate Keeper Register */
133 orr x0, x0, #1 << 0 /* Set open_request for Filter 0 */
134 str x0, [x1]
135
136 ldr x1, =TZASC_GATE_KEEPER(1)
137 ldr x0, [x1] /* Filter 0 Gate Keeper Register */
138 orr x0, x0, #1 << 0 /* Set open_request for Filter 0 */
139 str x0, [x1]
140
141 ldr x1, =TZASC_REGION_ATTRIBUTES_0(0)
142 ldr x0, [x1] /* Region-0 Attributes Register */
143 orr x0, x0, #1 << 31 /* Set Sec global write en, Bit[31] */
144 orr x0, x0, #1 << 30 /* Set Sec global read en, Bit[30] */
145 str x0, [x1]
146
147 ldr x1, =TZASC_REGION_ATTRIBUTES_0(1)
148 ldr x0, [x1] /* Region-1 Attributes Register */
149 orr x0, x0, #1 << 31 /* Set Sec global write en, Bit[31] */
150 orr x0, x0, #1 << 30 /* Set Sec global read en, Bit[30] */
151 str x0, [x1]
152
153 ldr x1, =TZASC_REGION_ID_ACCESS_0(0)
154 ldr w0, [x1] /* Region-0 Access Register */
155 mov w0, #0xFFFFFFFF /* Set nsaid_wr_en and nsaid_rd_en */
156 str w0, [x1]
157
158 ldr x1, =TZASC_REGION_ID_ACCESS_0(1)
159 ldr w0, [x1] /* Region-1 Attributes Register */
160 mov w0, #0xFFFFFFFF /* Set nsaid_wr_en and nsaid_rd_en */
161 str w0, [x1]
162
163 isb
164 dsb sy
165#endif
York Sun56cc3db2014-09-08 12:20:00 -0700166 mov lr, x29 /* Restore LR */
167 ret
168ENDPROC(lowlevel_init)
169
York Sun1ce575f2015-01-06 13:18:42 -0800170hnf_pstate_poll:
171 /* x0 has the desired status, return 0 for success, 1 for timeout
172 * clobber x1, x2, x3, x4, x6, x7
173 */
174 mov x1, x0
175 mov x7, #0 /* flag for timeout */
176 mrs x3, cntpct_el0 /* read timer */
177 add x3, x3, #1200 /* timeout after 100 microseconds */
178 mov x0, #0x18
179 movk x0, #0x420, lsl #16 /* HNF0_PSTATE_STATUS */
180 mov w6, #8 /* HN-F node count */
1811:
182 ldr x2, [x0]
183 cmp x2, x1 /* check status */
184 b.eq 2f
185 mrs x4, cntpct_el0
186 cmp x4, x3
187 b.ls 1b
188 mov x7, #1 /* timeout */
189 b 3f
1902:
191 add x0, x0, #0x10000 /* move to next node */
192 subs w6, w6, #1
193 cbnz w6, 1b
1943:
195 mov x0, x7
196 ret
197
198hnf_set_pstate:
199 /* x0 has the desired state, clobber x1, x2, x6 */
200 mov x1, x0
201 /* power state to SFONLY */
202 mov w6, #8 /* HN-F node count */
203 mov x0, #0x10
204 movk x0, #0x420, lsl #16 /* HNF0_PSTATE_REQ */
2051: /* set pstate to sfonly */
206 ldr x2, [x0]
207 and x2, x2, #0xfffffffffffffffc /* & HNFPSTAT_MASK */
208 orr x2, x2, x1
209 str x2, [x0]
210 add x0, x0, #0x10000 /* move to next node */
211 subs w6, w6, #1
212 cbnz w6, 1b
213
214 ret
215
216ENTRY(__asm_flush_l3_cache)
217 /*
218 * Return status in x0
219 * success 0
220 * tmeout 1 for setting SFONLY, 2 for FAM, 3 for both
221 */
222 mov x29, lr
223 mov x8, #0
224
225 dsb sy
226 mov x0, #0x1 /* HNFPSTAT_SFONLY */
227 bl hnf_set_pstate
228
229 mov x0, #0x4 /* SFONLY status */
230 bl hnf_pstate_poll
231 cbz x0, 1f
232 mov x8, #1 /* timeout */
2331:
234 dsb sy
235 mov x0, #0x3 /* HNFPSTAT_FAM */
236 bl hnf_set_pstate
237
238 mov x0, #0xc /* FAM status */
239 bl hnf_pstate_poll
240 cbz x0, 1f
241 add x8, x8, #0x2
2421:
243 mov x0, x8
244 mov lr, x29
245 ret
246ENDPROC(__asm_flush_l3_cache)
247
York Sun56cc3db2014-09-08 12:20:00 -0700248 /* Keep literals not used by the secondary boot code outside it */
249 .ltorg
250
251 /* Using 64 bit alignment since the spin table is accessed as data */
252 .align 4
253 .global secondary_boot_code
254 /* Secondary Boot Code starts here */
255secondary_boot_code:
256 .global __spin_table
257__spin_table:
258 .space CONFIG_MAX_CPUS*SPIN_TABLE_ELEM_SIZE
259
260 .align 2
261ENTRY(secondary_boot_func)
York Suna84cd722014-06-23 15:15:54 -0700262 /*
York Sun56cc3db2014-09-08 12:20:00 -0700263 * MPIDR_EL1 Fields:
264 * MPIDR[1:0] = AFF0_CPUID <- Core ID (0,1)
265 * MPIDR[7:2] = AFF0_RES
266 * MPIDR[15:8] = AFF1_CLUSTERID <- Cluster ID (0,1,2,3)
267 * MPIDR[23:16] = AFF2_CLUSTERID
268 * MPIDR[24] = MT
269 * MPIDR[29:25] = RES0
270 * MPIDR[30] = U
271 * MPIDR[31] = ME
272 * MPIDR[39:32] = AFF3
273 *
274 * Linear Processor ID (LPID) calculation from MPIDR_EL1:
275 * (We only use AFF0_CPUID and AFF1_CLUSTERID for now
276 * until AFF2_CLUSTERID and AFF3 have non-zero values)
277 *
278 * LPID = MPIDR[15:8] | MPIDR[1:0]
York Suna84cd722014-06-23 15:15:54 -0700279 */
York Sun56cc3db2014-09-08 12:20:00 -0700280 mrs x0, mpidr_el1
281 ubfm x1, x0, #8, #15
282 ubfm x2, x0, #0, #1
283 orr x10, x2, x1, lsl #2 /* x10 has LPID */
284 ubfm x9, x0, #0, #15 /* x9 contains MPIDR[15:0] */
York Suna84cd722014-06-23 15:15:54 -0700285 /*
York Sun56cc3db2014-09-08 12:20:00 -0700286 * offset of the spin table element for this core from start of spin
287 * table (each elem is padded to 64 bytes)
York Suna84cd722014-06-23 15:15:54 -0700288 */
York Sun56cc3db2014-09-08 12:20:00 -0700289 lsl x1, x10, #6
290 ldr x0, =__spin_table
291 /* physical address of this cpus spin table element */
292 add x11, x1, x0
293
York Sun77a10972015-03-20 19:28:08 -0700294 ldr x0, =__real_cntfrq
295 ldr x0, [x0]
296 msr cntfrq_el0, x0 /* set with real frequency */
York Sun56cc3db2014-09-08 12:20:00 -0700297 str x9, [x11, #16] /* LPID */
298 mov x4, #1
299 str x4, [x11, #8] /* STATUS */
300 dsb sy
301#if defined(CONFIG_GICV3)
302 gic_wait_for_interrupt_m x0
303#elif defined(CONFIG_GICV2)
304 ldr x0, =GICC_BASE
305 gic_wait_for_interrupt_m x0, w1
306#endif
307
308 bl secondary_switch_to_el2
York Suna84cd722014-06-23 15:15:54 -0700309#ifdef CONFIG_ARMV8_SWITCH_TO_EL1
York Sun56cc3db2014-09-08 12:20:00 -0700310 bl secondary_switch_to_el1
York Suna84cd722014-06-23 15:15:54 -0700311#endif
York Suna84cd722014-06-23 15:15:54 -0700312
York Sun56cc3db2014-09-08 12:20:00 -0700313slave_cpu:
314 wfe
315 ldr x0, [x11]
316 cbz x0, slave_cpu
317#ifndef CONFIG_ARMV8_SWITCH_TO_EL1
318 mrs x1, sctlr_el2
319#else
320 mrs x1, sctlr_el1
321#endif
322 tbz x1, #25, cpu_is_le
323 rev x0, x0 /* BE to LE conversion */
324cpu_is_le:
325 br x0 /* branch to the given address */
326ENDPROC(secondary_boot_func)
327
328ENTRY(secondary_switch_to_el2)
329 switch_el x0, 1f, 0f, 0f
3300: ret
3311: armv8_switch_to_el2_m x0
332ENDPROC(secondary_switch_to_el2)
333
334ENTRY(secondary_switch_to_el1)
335 switch_el x0, 0f, 1f, 0f
3360: ret
3371: armv8_switch_to_el1_m x0, x1
338ENDPROC(secondary_switch_to_el1)
339
340 /* Ensure that the literals used by the secondary boot code are
341 * assembled within it (this is required so that we can protect
342 * this area with a single memreserve region
343 */
344 .ltorg
345
346 /* 64 bit alignment for elements accessed as data */
347 .align 4
York Sun77a10972015-03-20 19:28:08 -0700348 .global __real_cntfrq
349__real_cntfrq:
350 .quad COUNTER_FREQUENCY
York Sun56cc3db2014-09-08 12:20:00 -0700351 .globl __secondary_boot_code_size
352 .type __secondary_boot_code_size, %object
353 /* Secondary Boot Code ends here */
354__secondary_boot_code_size:
355 .quad .-secondary_boot_code