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 #if defined(CONFIG_FSL_LSCH2) && !defined(CONFIG_SPL_BUILD)
236 mov lr, x29 /* Restore LR */
238 ENDPROC(lowlevel_init)
240 #if defined(CONFIG_FSL_LSCH2) && !defined(CONFIG_SPL_BUILD)
241 ENTRY(fsl_ocram_init)
242 mov x28, lr /* Save LR */
244 bl fsl_ocram_clear_ecc_err
245 mov lr, x28 /* Restore LR */
247 ENDPROC(fsl_ocram_init)
249 ENTRY(fsl_clear_ocram)
251 ldr x0, =CONFIG_SYS_FSL_OCRAM_BASE
252 ldr x1, =(CONFIG_SYS_FSL_OCRAM_BASE + CONFIG_SYS_FSL_OCRAM_SIZE)
260 ENDPROC(fsl_clear_ocram)
262 ENTRY(fsl_ocram_clear_ecc_err)
263 /* OCRAM1/2 ECC status bit */
265 ldr x0, =DCSR_DCFG_SBEESR2
267 ldr x0, =DCSR_DCFG_MBEESR2
270 ENDPROC(fsl_ocram_init)
273 #ifdef CONFIG_FSL_LSCH3
276 ldr x1, =FSL_LSCH3_SVR
281 /* x0 has the desired status, return 0 for success, 1 for timeout
282 * clobber x1, x2, x3, x4, x6, x7
285 mov x7, #0 /* flag for timeout */
286 mrs x3, cntpct_el0 /* read timer */
287 add x3, x3, #1200 /* timeout after 100 microseconds */
289 movk x0, #0x420, lsl #16 /* HNF0_PSTATE_STATUS */
290 mov w6, #8 /* HN-F node count */
293 cmp x2, x1 /* check status */
298 mov x7, #1 /* timeout */
301 add x0, x0, #0x10000 /* move to next node */
309 /* x0 has the desired state, clobber x1, x2, x6 */
311 /* power state to SFONLY */
312 mov w6, #8 /* HN-F node count */
314 movk x0, #0x420, lsl #16 /* HNF0_PSTATE_REQ */
315 1: /* set pstate to sfonly */
317 and x2, x2, #0xfffffffffffffffc /* & HNFPSTAT_MASK */
320 add x0, x0, #0x10000 /* move to next node */
326 ENTRY(__asm_flush_l3_dcache)
328 * Return status in x0
330 * tmeout 1 for setting SFONLY, 2 for FAM, 3 for both
336 mov x0, #0x1 /* HNFPSTAT_SFONLY */
339 mov x0, #0x4 /* SFONLY status */
342 mov x8, #1 /* timeout */
345 mov x0, #0x3 /* HNFPSTAT_FAM */
348 mov x0, #0xc /* FAM status */
356 ENDPROC(__asm_flush_l3_dcache)
360 /* Keep literals not used by the secondary boot code outside it */
363 /* Using 64 bit alignment since the spin table is accessed as data */
365 .global secondary_boot_code
366 /* Secondary Boot Code starts here */
370 .space CONFIG_MAX_CPUS*SPIN_TABLE_ELEM_SIZE
373 ENTRY(secondary_boot_func)
376 * MPIDR[1:0] = AFF0_CPUID <- Core ID (0,1)
377 * MPIDR[7:2] = AFF0_RES
378 * MPIDR[15:8] = AFF1_CLUSTERID <- Cluster ID (0,1,2,3)
379 * MPIDR[23:16] = AFF2_CLUSTERID
381 * MPIDR[29:25] = RES0
384 * MPIDR[39:32] = AFF3
386 * Linear Processor ID (LPID) calculation from MPIDR_EL1:
387 * (We only use AFF0_CPUID and AFF1_CLUSTERID for now
388 * until AFF2_CLUSTERID and AFF3 have non-zero values)
390 * LPID = MPIDR[15:8] | MPIDR[1:0]
395 orr x10, x2, x1, lsl #2 /* x10 has LPID */
396 ubfm x9, x0, #0, #15 /* x9 contains MPIDR[15:0] */
398 * offset of the spin table element for this core from start of spin
399 * table (each elem is padded to 64 bytes)
402 ldr x0, =__spin_table
403 /* physical address of this cpus spin table element */
406 ldr x0, =__real_cntfrq
408 msr cntfrq_el0, x0 /* set with real frequency */
409 str x9, [x11, #16] /* LPID */
411 str x4, [x11, #8] /* STATUS */
413 #if defined(CONFIG_GICV3)
414 gic_wait_for_interrupt_m x0
415 #elif defined(CONFIG_GICV2)
417 gic_wait_for_interrupt_m x0, w1
424 #ifndef CONFIG_ARMV8_SWITCH_TO_EL1
429 tbz x1, #25, cpu_is_le
430 rev x0, x0 /* BE to LE conversion */
433 ldr x6, =IH_ARCH_DEFAULT
437 #ifdef CONFIG_ARMV8_SWITCH_TO_EL1
438 adr x3, secondary_switch_to_el1
439 ldr x4, =ES_TO_AARCH64
442 ldr x4, =ES_TO_AARCH32
444 bl secondary_switch_to_el2
447 #ifdef CONFIG_ARMV8_SWITCH_TO_EL1
448 adr x3, secondary_switch_to_el1
452 ldr x4, =ES_TO_AARCH64
453 bl secondary_switch_to_el2
455 ENDPROC(secondary_boot_func)
457 ENTRY(secondary_switch_to_el2)
458 switch_el x5, 1f, 0f, 0f
460 1: armv8_switch_to_el2_m x3, x4, x5
461 ENDPROC(secondary_switch_to_el2)
463 ENTRY(secondary_switch_to_el1)
467 orr x10, x2, x1, lsl #2 /* x10 has LPID */
470 ldr x0, =__spin_table
471 /* physical address of this cpus spin table element */
477 ldr x6, =IH_ARCH_DEFAULT
481 ldr x4, =ES_TO_AARCH32
484 2: ldr x4, =ES_TO_AARCH64
487 switch_el x5, 0f, 1f, 0f
489 1: armv8_switch_to_el1_m x3, x4, x5
490 ENDPROC(secondary_switch_to_el1)
492 /* Ensure that the literals used by the secondary boot code are
493 * assembled within it (this is required so that we can protect
494 * this area with a single memreserve region
498 /* 64 bit alignment for elements accessed as data */
500 .global __real_cntfrq
502 .quad COUNTER_FREQUENCY
503 .globl __secondary_boot_code_size
504 .type __secondary_boot_code_size, %object
505 /* Secondary Boot Code ends here */
506 __secondary_boot_code_size:
507 .quad .-secondary_boot_code