2 * (C) Copyright 2014-2015 Freescale Semiconductor
4 * SPDX-License-Identifier: GPL-2.0+
6 * Extracted from armv8/start.S
10 #include <linux/linkage.h>
12 #include <asm/macro.h>
14 #include <asm/arch/mp.h>
16 #ifdef CONFIG_FSL_LSCH3
17 #include <asm/arch-fsl-layerscape/immap_lsch3.h>
18 #include <asm/arch-fsl-layerscape/soc.h>
22 mov x29, lr /* Save LR */
24 #ifdef CONFIG_FSL_LSCH3
26 /* Set Wuo bit for RN-I 20 */
28 ldr x0, =CCI_AUX_CONTROL_BASE(20)
33 /* Add fully-coherent masters to DVM domain */
35 ldr x1, =CCI_MN_RNF_NODEID_LIST
36 ldr x2, =CCI_MN_DVM_DOMAIN_CTL_SET
37 bl ccn504_add_masters_to_dvm
39 /* Set all RN-I ports to QoS of 15 */
40 ldr x0, =CCI_S0_QOS_CONTROL_BASE(0)
43 ldr x0, =CCI_S1_QOS_CONTROL_BASE(0)
46 ldr x0, =CCI_S2_QOS_CONTROL_BASE(0)
50 ldr x0, =CCI_S0_QOS_CONTROL_BASE(2)
53 ldr x0, =CCI_S1_QOS_CONTROL_BASE(2)
56 ldr x0, =CCI_S2_QOS_CONTROL_BASE(2)
60 ldr x0, =CCI_S0_QOS_CONTROL_BASE(6)
63 ldr x0, =CCI_S1_QOS_CONTROL_BASE(6)
66 ldr x0, =CCI_S2_QOS_CONTROL_BASE(6)
70 ldr x0, =CCI_S0_QOS_CONTROL_BASE(12)
73 ldr x0, =CCI_S1_QOS_CONTROL_BASE(12)
76 ldr x0, =CCI_S2_QOS_CONTROL_BASE(12)
80 ldr x0, =CCI_S0_QOS_CONTROL_BASE(16)
83 ldr x0, =CCI_S1_QOS_CONTROL_BASE(16)
86 ldr x0, =CCI_S2_QOS_CONTROL_BASE(16)
90 ldr x0, =CCI_S0_QOS_CONTROL_BASE(20)
93 ldr x0, =CCI_S1_QOS_CONTROL_BASE(20)
96 ldr x0, =CCI_S2_QOS_CONTROL_BASE(20)
102 /* Set the SMMU page size in the sACR register */
105 orr w0, w0, #1 << 16 /* set sACR.pagesize to indicate 64K page */
109 /* Initialize GIC Secure Bank Status */
110 #if defined(CONFIG_GICV2) || defined(CONFIG_GICV3)
111 branch_if_slave x0, 1f
117 bl gic_init_secure_percpu
118 #elif defined(CONFIG_GICV2)
121 bl gic_init_secure_percpu
125 branch_if_master x0, x1, 2f
127 #if defined(CONFIG_MP) && defined(CONFIG_ARMV8_MULTIENTRY)
128 ldr x0, =secondary_boot_func
133 #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 */
143 #ifdef CONFIG_FSL_TZASC_400
145 * LS2080 and its personalities does not support TZASC
146 * So skip TZASC related operations
150 ldr w1, =SVR_DEV_LS2080A
154 /* 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
158 * NOTE: As per the CCSR map doc, TZASC 3 and TZASC 4 are just
161 ldr x1, =TZASC_GATE_KEEPER(0)
162 ldr w0, [x1] /* Filter 0 Gate Keeper Register */
163 orr w0, w0, #1 << 0 /* Set open_request for Filter 0 */
166 ldr x1, =TZASC_GATE_KEEPER(1)
167 ldr w0, [x1] /* Filter 0 Gate Keeper Register */
168 orr w0, w0, #1 << 0 /* Set open_request for Filter 0 */
171 ldr x1, =TZASC_REGION_ATTRIBUTES_0(0)
172 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] */
177 ldr x1, =TZASC_REGION_ATTRIBUTES_0(1)
178 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] */
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 */
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 */
197 #ifdef CONFIG_ARCH_LS1046A
198 /* Initialize the L2 RAM latency */
199 mrs x1, S3_1_c11_c0_2
201 /* Clear L2 Tag RAM latency and L2 Data RAM latency */
203 /* Set L2 data ram latency bits [2:0] */
205 /* set L2 tag ram latency bits [8:6] */
207 msr S3_1_c11_c0_2, x1
211 mov lr, x29 /* Restore LR */
213 ENDPROC(lowlevel_init)
215 #ifdef CONFIG_FSL_LSCH3
218 ldr x1, =FSL_LSCH3_SVR
223 /* x0 has the desired status, return 0 for success, 1 for timeout
224 * clobber x1, x2, x3, x4, x6, x7
227 mov x7, #0 /* flag for timeout */
228 mrs x3, cntpct_el0 /* read timer */
229 add x3, x3, #1200 /* timeout after 100 microseconds */
231 movk x0, #0x420, lsl #16 /* HNF0_PSTATE_STATUS */
232 mov w6, #8 /* HN-F node count */
235 cmp x2, x1 /* check status */
240 mov x7, #1 /* timeout */
243 add x0, x0, #0x10000 /* move to next node */
251 /* x0 has the desired state, clobber x1, x2, x6 */
253 /* power state to SFONLY */
254 mov w6, #8 /* HN-F node count */
256 movk x0, #0x420, lsl #16 /* HNF0_PSTATE_REQ */
257 1: /* set pstate to sfonly */
259 and x2, x2, #0xfffffffffffffffc /* & HNFPSTAT_MASK */
262 add x0, x0, #0x10000 /* move to next node */
268 ENTRY(__asm_flush_l3_dcache)
270 * Return status in x0
272 * tmeout 1 for setting SFONLY, 2 for FAM, 3 for both
278 mov x0, #0x1 /* HNFPSTAT_SFONLY */
281 mov x0, #0x4 /* SFONLY status */
284 mov x8, #1 /* timeout */
287 mov x0, #0x3 /* HNFPSTAT_FAM */
290 mov x0, #0xc /* FAM status */
298 ENDPROC(__asm_flush_l3_dcache)
302 /* Keep literals not used by the secondary boot code outside it */
305 /* Using 64 bit alignment since the spin table is accessed as data */
307 .global secondary_boot_code
308 /* Secondary Boot Code starts here */
312 .space CONFIG_MAX_CPUS*SPIN_TABLE_ELEM_SIZE
315 ENTRY(secondary_boot_func)
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
323 * MPIDR[29:25] = RES0
326 * MPIDR[39:32] = AFF3
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)
332 * LPID = MPIDR[15:8] | MPIDR[1:0]
337 orr x10, x2, x1, lsl #2 /* x10 has LPID */
338 ubfm x9, x0, #0, #15 /* x9 contains MPIDR[15:0] */
340 * offset of the spin table element for this core from start of spin
341 * table (each elem is padded to 64 bytes)
344 ldr x0, =__spin_table
345 /* physical address of this cpus spin table element */
348 ldr x0, =__real_cntfrq
350 msr cntfrq_el0, x0 /* set with real frequency */
351 str x9, [x11, #16] /* LPID */
353 str x4, [x11, #8] /* STATUS */
355 #if defined(CONFIG_GICV3)
356 gic_wait_for_interrupt_m x0
357 #elif defined(CONFIG_GICV2)
359 gic_wait_for_interrupt_m x0, w1
362 bl secondary_switch_to_el2
363 #ifdef CONFIG_ARMV8_SWITCH_TO_EL1
364 bl secondary_switch_to_el1
371 #ifndef CONFIG_ARMV8_SWITCH_TO_EL1
376 tbz x1, #25, cpu_is_le
377 rev x0, x0 /* BE to LE conversion */
379 br x0 /* branch to the given address */
380 ENDPROC(secondary_boot_func)
382 ENTRY(secondary_switch_to_el2)
383 switch_el x0, 1f, 0f, 0f
385 1: armv8_switch_to_el2_m x0
386 ENDPROC(secondary_switch_to_el2)
388 ENTRY(secondary_switch_to_el1)
389 switch_el x0, 0f, 1f, 0f
391 1: armv8_switch_to_el1_m x0, x1
392 ENDPROC(secondary_switch_to_el1)
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
400 /* 64 bit alignment for elements accessed as data */
402 .global __real_cntfrq
404 .quad COUNTER_FREQUENCY
405 .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