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>
13 #include <asm/arch-fsl-layerscape/soc.h>
15 #include <asm/arch/mp.h>
17 #ifdef CONFIG_FSL_LSCH3
18 #include <asm/arch-fsl-layerscape/immap_lsch3.h>
20 #include <asm/u-boot.h>
23 * For LS1043a rev1.0, GIC base address align with 4k.
24 * For LS1043a rev1.1, if DCFG_GIC400_ALIGN[GIC_ADDR_BIT]
25 * is set, GIC base address align with 4K, or else align
28 * x0: the base address of GICD
29 * x1: the base address of GICC
36 #ifdef CONFIG_HAS_FEATURE_GIC64K_ALIGN
37 ldr x2, =DCFG_CCSR_SVR
41 ands w3, w3, #SVR_WO_E << 8
42 mov w4, #SVR_LS1043A << 8
48 ldr x2, =SCFG_GIC400_ALIGN
51 tbnz w2, #GIC_ADDR_BIT, 1f
52 ldr x0, =GICD_BASE_64K
54 ldr x1, =GICC_BASE_64K
59 ENDPROC(get_gic_offset)
61 ENTRY(smp_kick_all_cpus)
62 /* Kick secondary cpus up by SGI 0 interrupt */
63 #if defined(CONFIG_GICV2) || defined(CONFIG_GICV3)
64 mov x29, lr /* Save LR */
66 bl gic_kick_secondary_cpus
67 mov lr, x29 /* Restore LR */
70 ENDPROC(smp_kick_all_cpus)
74 mov x29, lr /* Save LR */
76 switch_el x1, 1f, 100f, 100f /* skip if not in EL3 */
79 #if defined (CONFIG_SYS_FSL_HAS_CCN504)
81 /* Set Wuo bit for RN-I 20 */
82 #ifdef CONFIG_ARCH_LS2080A
83 ldr x0, =CCI_AUX_CONTROL_BASE(20)
88 * Set forced-order mode in RNI-6, RNI-20
89 * This is required for performance optimization on LS2088A
90 * LS2080A family does not support setting forced-order mode,
91 * so skip this operation for LS2080A family
95 ldr w1, =SVR_DEV_LS2080A
99 ldr x0, =CCI_AUX_CONTROL_BASE(6)
102 ldr x0, =CCI_AUX_CONTROL_BASE(20)
108 /* Add fully-coherent masters to DVM domain */
110 ldr x1, =CCI_MN_RNF_NODEID_LIST
111 ldr x2, =CCI_MN_DVM_DOMAIN_CTL_SET
112 bl ccn504_add_masters_to_dvm
114 /* Set all RN-I ports to QoS of 15 */
115 ldr x0, =CCI_S0_QOS_CONTROL_BASE(0)
118 ldr x0, =CCI_S1_QOS_CONTROL_BASE(0)
121 ldr x0, =CCI_S2_QOS_CONTROL_BASE(0)
125 ldr x0, =CCI_S0_QOS_CONTROL_BASE(2)
128 ldr x0, =CCI_S1_QOS_CONTROL_BASE(2)
131 ldr x0, =CCI_S2_QOS_CONTROL_BASE(2)
135 ldr x0, =CCI_S0_QOS_CONTROL_BASE(6)
138 ldr x0, =CCI_S1_QOS_CONTROL_BASE(6)
141 ldr x0, =CCI_S2_QOS_CONTROL_BASE(6)
145 ldr x0, =CCI_S0_QOS_CONTROL_BASE(12)
148 ldr x0, =CCI_S1_QOS_CONTROL_BASE(12)
151 ldr x0, =CCI_S2_QOS_CONTROL_BASE(12)
155 ldr x0, =CCI_S0_QOS_CONTROL_BASE(16)
158 ldr x0, =CCI_S1_QOS_CONTROL_BASE(16)
161 ldr x0, =CCI_S2_QOS_CONTROL_BASE(16)
165 ldr x0, =CCI_S0_QOS_CONTROL_BASE(20)
168 ldr x0, =CCI_S1_QOS_CONTROL_BASE(20)
171 ldr x0, =CCI_S2_QOS_CONTROL_BASE(20)
174 #endif /* CONFIG_SYS_FSL_HAS_CCN504 */
177 /* Set the SMMU page size in the sACR register */
180 orr w0, w0, #1 << 16 /* set sACR.pagesize to indicate 64K page */
184 /* Initialize GIC Secure Bank Status */
185 #if defined(CONFIG_GICV2) || defined(CONFIG_GICV3)
186 branch_if_slave x0, 1f
192 bl gic_init_secure_percpu
193 #elif defined(CONFIG_GICV2)
195 bl gic_init_secure_percpu
200 branch_if_master x0, x1, 2f
202 #if defined(CONFIG_MP) && defined(CONFIG_ARMV8_MULTIENTRY)
203 ldr x0, =secondary_boot_func
208 switch_el x1, 1f, 100f, 100f /* skip if not in EL3 */
210 #ifdef CONFIG_FSL_TZPC_BP147
211 /* Set Non Secure access for all devices protected via TZPC */
212 ldr x1, =TZPCDECPROT_0_SET_BASE /* Decode Protection-0 Set Reg */
213 orr w0, w0, #1 << 3 /* DCFG_RESET is accessible from NS world */
220 #ifdef CONFIG_FSL_TZASC_400
222 * LS2080 and its personalities does not support TZASC
223 * So skip TZASC related operations
227 ldr w1, =SVR_DEV_LS2080A
231 /* Set TZASC so that:
232 * a. We use only Region0 whose global secure write/read is EN
233 * b. We use only Region0 whose NSAID write/read is EN
235 * NOTE: As per the CCSR map doc, TZASC 3 and TZASC 4 are just
238 #ifdef CONFIG_FSL_TZASC_1
239 ldr x1, =TZASC_GATE_KEEPER(0)
240 ldr w0, [x1] /* Filter 0 Gate Keeper Register */
241 orr w0, w0, #1 << 0 /* Set open_request for Filter 0 */
244 ldr x1, =TZASC_REGION_ATTRIBUTES_0(0)
245 ldr w0, [x1] /* Region-0 Attributes Register */
246 orr w0, w0, #1 << 31 /* Set Sec global write en, Bit[31] */
247 orr w0, w0, #1 << 30 /* Set Sec global read en, Bit[30] */
250 ldr x1, =TZASC_REGION_ID_ACCESS_0(0)
251 ldr w0, [x1] /* Region-0 Access Register */
252 mov w0, #0xFFFFFFFF /* Set nsaid_wr_en and nsaid_rd_en */
255 #ifdef CONFIG_FSL_TZASC_2
256 ldr x1, =TZASC_GATE_KEEPER(1)
257 ldr w0, [x1] /* Filter 0 Gate Keeper Register */
258 orr w0, w0, #1 << 0 /* Set open_request for Filter 0 */
261 ldr x1, =TZASC_REGION_ATTRIBUTES_0(1)
262 ldr w0, [x1] /* Region-1 Attributes Register */
263 orr w0, w0, #1 << 31 /* Set Sec global write en, Bit[31] */
264 orr w0, w0, #1 << 30 /* Set Sec global read en, Bit[30] */
267 ldr x1, =TZASC_REGION_ID_ACCESS_0(1)
268 ldr w0, [x1] /* Region-1 Attributes Register */
269 mov w0, #0xFFFFFFFF /* Set nsaid_wr_en and nsaid_rd_en */
277 #ifdef CONFIG_ARCH_LS1046A
278 switch_el x1, 1f, 100f, 100f /* skip if not in EL3 */
280 /* Initialize the L2 RAM latency */
281 mrs x1, S3_1_c11_c0_2
283 /* Clear L2 Tag RAM latency and L2 Data RAM latency */
285 /* Set L2 data ram latency bits [2:0] */
287 /* set L2 tag ram latency bits [8:6] */
289 msr S3_1_c11_c0_2, x1
294 #if defined(CONFIG_FSL_LSCH2) && !defined(CONFIG_SPL_BUILD)
298 mov lr, x29 /* Restore LR */
300 ENDPROC(lowlevel_init)
302 #if defined(CONFIG_FSL_LSCH2) && !defined(CONFIG_SPL_BUILD)
303 ENTRY(fsl_ocram_init)
304 mov x28, lr /* Save LR */
306 bl fsl_ocram_clear_ecc_err
307 mov lr, x28 /* Restore LR */
309 ENDPROC(fsl_ocram_init)
311 ENTRY(fsl_clear_ocram)
313 ldr x0, =CONFIG_SYS_FSL_OCRAM_BASE
314 ldr x1, =(CONFIG_SYS_FSL_OCRAM_BASE + CONFIG_SYS_FSL_OCRAM_SIZE)
322 ENDPROC(fsl_clear_ocram)
324 ENTRY(fsl_ocram_clear_ecc_err)
325 /* OCRAM1/2 ECC status bit */
327 ldr x0, =DCSR_DCFG_SBEESR2
329 ldr x0, =DCSR_DCFG_MBEESR2
332 ENDPROC(fsl_ocram_init)
335 #ifdef CONFIG_FSL_LSCH3
338 ldr x1, =FSL_LSCH3_SVR
343 #ifdef CONFIG_SYS_FSL_HAS_CCN504
345 /* x0 has the desired status, return 0 for success, 1 for timeout
346 * clobber x1, x2, x3, x4, x6, x7
349 mov x7, #0 /* flag for timeout */
350 mrs x3, cntpct_el0 /* read timer */
351 add x3, x3, #1200 /* timeout after 100 microseconds */
353 movk x0, #0x420, lsl #16 /* HNF0_PSTATE_STATUS */
354 mov w6, #8 /* HN-F node count */
357 cmp x2, x1 /* check status */
362 mov x7, #1 /* timeout */
365 add x0, x0, #0x10000 /* move to next node */
373 /* x0 has the desired state, clobber x1, x2, x6 */
375 /* power state to SFONLY */
376 mov w6, #8 /* HN-F node count */
378 movk x0, #0x420, lsl #16 /* HNF0_PSTATE_REQ */
379 1: /* set pstate to sfonly */
381 and x2, x2, #0xfffffffffffffffc /* & HNFPSTAT_MASK */
384 add x0, x0, #0x10000 /* move to next node */
390 ENTRY(__asm_flush_l3_dcache)
392 * Return status in x0
394 * timeout 1 for setting SFONLY, 2 for FAM, 3 for both
399 switch_el x0, 1f, 100f, 100f /* skip if not in EL3 */
403 mov x0, #0x1 /* HNFPSTAT_SFONLY */
406 mov x0, #0x4 /* SFONLY status */
409 mov x8, #1 /* timeout */
412 mov x0, #0x3 /* HNFPSTAT_FAM */
415 mov x0, #0xc /* FAM status */
424 ENDPROC(__asm_flush_l3_dcache)
425 #endif /* CONFIG_SYS_FSL_HAS_CCN504 */
428 /* Keep literals not used by the secondary boot code outside it */
431 /* Using 64 bit alignment since the spin table is accessed as data */
433 .global secondary_boot_code
434 /* Secondary Boot Code starts here */
438 .space CONFIG_MAX_CPUS*SPIN_TABLE_ELEM_SIZE
441 ENTRY(secondary_boot_func)
444 * MPIDR[1:0] = AFF0_CPUID <- Core ID (0,1)
445 * MPIDR[7:2] = AFF0_RES
446 * MPIDR[15:8] = AFF1_CLUSTERID <- Cluster ID (0,1,2,3)
447 * MPIDR[23:16] = AFF2_CLUSTERID
449 * MPIDR[29:25] = RES0
452 * MPIDR[39:32] = AFF3
454 * Linear Processor ID (LPID) calculation from MPIDR_EL1:
455 * (We only use AFF0_CPUID and AFF1_CLUSTERID for now
456 * until AFF2_CLUSTERID and AFF3 have non-zero values)
458 * LPID = MPIDR[15:8] | MPIDR[1:0]
463 orr x10, x2, x1, lsl #2 /* x10 has LPID */
464 ubfm x9, x0, #0, #15 /* x9 contains MPIDR[15:0] */
466 * offset of the spin table element for this core from start of spin
467 * table (each elem is padded to 64 bytes)
470 ldr x0, =__spin_table
471 /* physical address of this cpus spin table element */
474 ldr x0, =__real_cntfrq
476 msr cntfrq_el0, x0 /* set with real frequency */
477 str x9, [x11, #16] /* LPID */
479 str x4, [x11, #8] /* STATUS */
481 #if defined(CONFIG_GICV3)
482 gic_wait_for_interrupt_m x0
483 #elif defined(CONFIG_GICV2)
486 gic_wait_for_interrupt_m x0, w1
493 #ifndef CONFIG_ARMV8_SWITCH_TO_EL1
498 tbz x1, #25, cpu_is_le
499 rev x0, x0 /* BE to LE conversion */
504 #ifdef CONFIG_ARMV8_SWITCH_TO_EL1
505 adr x4, secondary_switch_to_el1
506 ldr x5, =ES_TO_AARCH64
509 ldr x5, =ES_TO_AARCH32
511 bl secondary_switch_to_el2
514 #ifdef CONFIG_ARMV8_SWITCH_TO_EL1
515 adr x4, secondary_switch_to_el1
519 ldr x5, =ES_TO_AARCH64
520 bl secondary_switch_to_el2
522 ENDPROC(secondary_boot_func)
524 ENTRY(secondary_switch_to_el2)
525 switch_el x6, 1f, 0f, 0f
527 1: armv8_switch_to_el2_m x4, x5, x6
528 ENDPROC(secondary_switch_to_el2)
530 ENTRY(secondary_switch_to_el1)
534 orr x10, x2, x1, lsl #2 /* x10 has LPID */
537 ldr x0, =__spin_table
538 /* physical address of this cpus spin table element */
546 ldr x5, =ES_TO_AARCH32
549 2: ldr x5, =ES_TO_AARCH64
552 switch_el x6, 0f, 1f, 0f
554 1: armv8_switch_to_el1_m x4, x5, x6
555 ENDPROC(secondary_switch_to_el1)
557 /* Ensure that the literals used by the secondary boot code are
558 * assembled within it (this is required so that we can protect
559 * this area with a single memreserve region
563 /* 64 bit alignment for elements accessed as data */
565 .global __real_cntfrq
567 .quad COUNTER_FREQUENCY
568 .globl __secondary_boot_code_size
569 .type __secondary_boot_code_size, %object
570 /* Secondary Boot Code ends here */
571 __secondary_boot_code_size:
572 .quad .-secondary_boot_code