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>
20 #include <asm/u-boot.h>
23 mov x29, lr /* Save LR */
25 #ifdef CONFIG_FSL_LSCH3
27 /* Set Wuo bit for RN-I 20 */
29 ldr x0, =CCI_AUX_CONTROL_BASE(20)
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
41 ldr w1, =SVR_DEV_LS2080A
45 ldr x0, =CCI_AUX_CONTROL_BASE(6)
48 ldr x0, =CCI_AUX_CONTROL_BASE(20)
54 /* Add fully-coherent masters to DVM domain */
56 ldr x1, =CCI_MN_RNF_NODEID_LIST
57 ldr x2, =CCI_MN_DVM_DOMAIN_CTL_SET
58 bl ccn504_add_masters_to_dvm
60 /* Set all RN-I ports to QoS of 15 */
61 ldr x0, =CCI_S0_QOS_CONTROL_BASE(0)
64 ldr x0, =CCI_S1_QOS_CONTROL_BASE(0)
67 ldr x0, =CCI_S2_QOS_CONTROL_BASE(0)
71 ldr x0, =CCI_S0_QOS_CONTROL_BASE(2)
74 ldr x0, =CCI_S1_QOS_CONTROL_BASE(2)
77 ldr x0, =CCI_S2_QOS_CONTROL_BASE(2)
81 ldr x0, =CCI_S0_QOS_CONTROL_BASE(6)
84 ldr x0, =CCI_S1_QOS_CONTROL_BASE(6)
87 ldr x0, =CCI_S2_QOS_CONTROL_BASE(6)
91 ldr x0, =CCI_S0_QOS_CONTROL_BASE(12)
94 ldr x0, =CCI_S1_QOS_CONTROL_BASE(12)
97 ldr x0, =CCI_S2_QOS_CONTROL_BASE(12)
101 ldr x0, =CCI_S0_QOS_CONTROL_BASE(16)
104 ldr x0, =CCI_S1_QOS_CONTROL_BASE(16)
107 ldr x0, =CCI_S2_QOS_CONTROL_BASE(16)
111 ldr x0, =CCI_S0_QOS_CONTROL_BASE(20)
114 ldr x0, =CCI_S1_QOS_CONTROL_BASE(20)
117 ldr x0, =CCI_S2_QOS_CONTROL_BASE(20)
123 /* Set the SMMU page size in the sACR register */
126 orr w0, w0, #1 << 16 /* set sACR.pagesize to indicate 64K page */
130 /* Initialize GIC Secure Bank Status */
131 #if defined(CONFIG_GICV2) || defined(CONFIG_GICV3)
132 branch_if_slave x0, 1f
138 bl gic_init_secure_percpu
139 #elif defined(CONFIG_GICV2)
142 bl gic_init_secure_percpu
146 branch_if_master x0, x1, 2f
148 #if defined(CONFIG_MP) && defined(CONFIG_ARMV8_MULTIENTRY)
149 ldr x0, =secondary_boot_func
154 #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 */
164 #ifdef CONFIG_FSL_TZASC_400
166 * LS2080 and its personalities does not support TZASC
167 * So skip TZASC related operations
171 ldr w1, =SVR_DEV_LS2080A
175 /* 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
179 * NOTE: As per the CCSR map doc, TZASC 3 and TZASC 4 are just
182 ldr x1, =TZASC_GATE_KEEPER(0)
183 ldr w0, [x1] /* Filter 0 Gate Keeper Register */
184 orr w0, w0, #1 << 0 /* Set open_request for Filter 0 */
187 ldr x1, =TZASC_GATE_KEEPER(1)
188 ldr w0, [x1] /* Filter 0 Gate Keeper Register */
189 orr w0, w0, #1 << 0 /* Set open_request for Filter 0 */
192 ldr x1, =TZASC_REGION_ATTRIBUTES_0(0)
193 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] */
198 ldr x1, =TZASC_REGION_ATTRIBUTES_0(1)
199 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] */
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 */
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 */
218 #ifdef CONFIG_ARCH_LS1046A
219 /* Initialize the L2 RAM latency */
220 mrs x1, S3_1_c11_c0_2
222 /* Clear L2 Tag RAM latency and L2 Data RAM latency */
224 /* Set L2 data ram latency bits [2:0] */
226 /* set L2 tag ram latency bits [8:6] */
228 msr S3_1_c11_c0_2, x1
232 mov lr, x29 /* Restore LR */
234 ENDPROC(lowlevel_init)
236 #ifdef CONFIG_FSL_LSCH3
239 ldr x1, =FSL_LSCH3_SVR
244 /* x0 has the desired status, return 0 for success, 1 for timeout
245 * clobber x1, x2, x3, x4, x6, x7
248 mov x7, #0 /* flag for timeout */
249 mrs x3, cntpct_el0 /* read timer */
250 add x3, x3, #1200 /* timeout after 100 microseconds */
252 movk x0, #0x420, lsl #16 /* HNF0_PSTATE_STATUS */
253 mov w6, #8 /* HN-F node count */
256 cmp x2, x1 /* check status */
261 mov x7, #1 /* timeout */
264 add x0, x0, #0x10000 /* move to next node */
272 /* x0 has the desired state, clobber x1, x2, x6 */
274 /* power state to SFONLY */
275 mov w6, #8 /* HN-F node count */
277 movk x0, #0x420, lsl #16 /* HNF0_PSTATE_REQ */
278 1: /* set pstate to sfonly */
280 and x2, x2, #0xfffffffffffffffc /* & HNFPSTAT_MASK */
283 add x0, x0, #0x10000 /* move to next node */
289 ENTRY(__asm_flush_l3_dcache)
291 * Return status in x0
293 * tmeout 1 for setting SFONLY, 2 for FAM, 3 for both
299 mov x0, #0x1 /* HNFPSTAT_SFONLY */
302 mov x0, #0x4 /* SFONLY status */
305 mov x8, #1 /* timeout */
308 mov x0, #0x3 /* HNFPSTAT_FAM */
311 mov x0, #0xc /* FAM status */
319 ENDPROC(__asm_flush_l3_dcache)
323 /* Keep literals not used by the secondary boot code outside it */
326 /* Using 64 bit alignment since the spin table is accessed as data */
328 .global secondary_boot_code
329 /* Secondary Boot Code starts here */
333 .space CONFIG_MAX_CPUS*SPIN_TABLE_ELEM_SIZE
336 ENTRY(secondary_boot_func)
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
344 * MPIDR[29:25] = RES0
347 * MPIDR[39:32] = AFF3
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)
353 * LPID = MPIDR[15:8] | MPIDR[1:0]
358 orr x10, x2, x1, lsl #2 /* x10 has LPID */
359 ubfm x9, x0, #0, #15 /* x9 contains MPIDR[15:0] */
361 * offset of the spin table element for this core from start of spin
362 * table (each elem is padded to 64 bytes)
365 ldr x0, =__spin_table
366 /* physical address of this cpus spin table element */
369 ldr x0, =__real_cntfrq
371 msr cntfrq_el0, x0 /* set with real frequency */
372 str x9, [x11, #16] /* LPID */
374 str x4, [x11, #8] /* STATUS */
376 #if defined(CONFIG_GICV3)
377 gic_wait_for_interrupt_m x0
378 #elif defined(CONFIG_GICV2)
380 gic_wait_for_interrupt_m x0, w1
387 #ifndef CONFIG_ARMV8_SWITCH_TO_EL1
392 tbz x1, #25, cpu_is_le
393 rev x0, x0 /* BE to LE conversion */
396 ldr x6, =IH_ARCH_DEFAULT
400 #ifdef CONFIG_ARMV8_SWITCH_TO_EL1
401 adr x3, secondary_switch_to_el1
402 ldr x4, =ES_TO_AARCH64
405 ldr x4, =ES_TO_AARCH32
407 bl secondary_switch_to_el2
410 #ifdef CONFIG_ARMV8_SWITCH_TO_EL1
411 adr x3, secondary_switch_to_el1
415 ldr x4, =ES_TO_AARCH64
416 bl secondary_switch_to_el2
418 ENDPROC(secondary_boot_func)
420 ENTRY(secondary_switch_to_el2)
421 switch_el x5, 1f, 0f, 0f
423 1: armv8_switch_to_el2_m x3, x4, x5
424 ENDPROC(secondary_switch_to_el2)
426 ENTRY(secondary_switch_to_el1)
430 orr x10, x2, x1, lsl #2 /* x10 has LPID */
433 ldr x0, =__spin_table
434 /* physical address of this cpus spin table element */
440 ldr x6, =IH_ARCH_DEFAULT
444 ldr x4, =ES_TO_AARCH32
447 2: ldr x4, =ES_TO_AARCH64
450 switch_el x5, 0f, 1f, 0f
452 1: armv8_switch_to_el1_m x3, x4, x5
453 ENDPROC(secondary_switch_to_el1)
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
461 /* 64 bit alignment for elements accessed as data */
463 .global __real_cntfrq
465 .quad COUNTER_FREQUENCY
466 .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