armv8: fsl-layerscape, ccn504: Set forced-order mode in RNI-6, RNI-20
[oweals/u-boot.git] / arch / arm / cpu / armv8 / fsl-layerscape / lowlevel.S
1 /*
2  * (C) Copyright 2014-2015 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>
11 #include <asm/gic.h>
12 #include <asm/macro.h>
13 #ifdef CONFIG_MP
14 #include <asm/arch/mp.h>
15 #endif
16 #ifdef CONFIG_FSL_LSCH3
17 #include <asm/arch-fsl-layerscape/immap_lsch3.h>
18 #include <asm/arch-fsl-layerscape/soc.h>
19 #endif
20 #include <asm/u-boot.h>
21
22 ENTRY(lowlevel_init)
23         mov     x29, lr                 /* Save LR */
24
25 #ifdef CONFIG_FSL_LSCH3
26
27         /* Set Wuo bit for RN-I 20 */
28 #ifdef CONFIG_LS2080A
29         ldr     x0, =CCI_AUX_CONTROL_BASE(20)
30         ldr     x1, =0x00000010
31         bl      ccn504_set_aux
32
33         /*
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
38          */
39         bl      get_svr
40         lsr     w0, w0, #16
41         ldr     w1, =SVR_DEV_LS2080A
42         cmp     w0, w1
43         b.eq    1f
44
45         ldr     x0, =CCI_AUX_CONTROL_BASE(6)
46         ldr     x1, =0x00000020
47         bl      ccn504_set_aux
48         ldr     x0, =CCI_AUX_CONTROL_BASE(20)
49         ldr     x1, =0x00000020
50         bl      ccn504_set_aux
51 1:
52 #endif
53
54         /* Add fully-coherent masters to DVM domain */
55         ldr     x0, =CCI_MN_BASE
56         ldr     x1, =CCI_MN_RNF_NODEID_LIST
57         ldr     x2, =CCI_MN_DVM_DOMAIN_CTL_SET
58         bl      ccn504_add_masters_to_dvm
59
60         /* Set all RN-I ports to QoS of 15 */
61         ldr     x0, =CCI_S0_QOS_CONTROL_BASE(0)
62         ldr     x1, =0x00FF000C
63         bl      ccn504_set_qos
64         ldr     x0, =CCI_S1_QOS_CONTROL_BASE(0)
65         ldr     x1, =0x00FF000C
66         bl      ccn504_set_qos
67         ldr     x0, =CCI_S2_QOS_CONTROL_BASE(0)
68         ldr     x1, =0x00FF000C
69         bl      ccn504_set_qos
70
71         ldr     x0, =CCI_S0_QOS_CONTROL_BASE(2)
72         ldr     x1, =0x00FF000C
73         bl      ccn504_set_qos
74         ldr     x0, =CCI_S1_QOS_CONTROL_BASE(2)
75         ldr     x1, =0x00FF000C
76         bl      ccn504_set_qos
77         ldr     x0, =CCI_S2_QOS_CONTROL_BASE(2)
78         ldr     x1, =0x00FF000C
79         bl      ccn504_set_qos
80
81         ldr     x0, =CCI_S0_QOS_CONTROL_BASE(6)
82         ldr     x1, =0x00FF000C
83         bl      ccn504_set_qos
84         ldr     x0, =CCI_S1_QOS_CONTROL_BASE(6)
85         ldr     x1, =0x00FF000C
86         bl      ccn504_set_qos
87         ldr     x0, =CCI_S2_QOS_CONTROL_BASE(6)
88         ldr     x1, =0x00FF000C
89         bl      ccn504_set_qos
90
91         ldr     x0, =CCI_S0_QOS_CONTROL_BASE(12)
92         ldr     x1, =0x00FF000C
93         bl      ccn504_set_qos
94         ldr     x0, =CCI_S1_QOS_CONTROL_BASE(12)
95         ldr     x1, =0x00FF000C
96         bl      ccn504_set_qos
97         ldr     x0, =CCI_S2_QOS_CONTROL_BASE(12)
98         ldr     x1, =0x00FF000C
99         bl      ccn504_set_qos
100
101         ldr     x0, =CCI_S0_QOS_CONTROL_BASE(16)
102         ldr     x1, =0x00FF000C
103         bl      ccn504_set_qos
104         ldr     x0, =CCI_S1_QOS_CONTROL_BASE(16)
105         ldr     x1, =0x00FF000C
106         bl      ccn504_set_qos
107         ldr     x0, =CCI_S2_QOS_CONTROL_BASE(16)
108         ldr     x1, =0x00FF000C
109         bl      ccn504_set_qos
110
111         ldr     x0, =CCI_S0_QOS_CONTROL_BASE(20)
112         ldr     x1, =0x00FF000C
113         bl      ccn504_set_qos
114         ldr     x0, =CCI_S1_QOS_CONTROL_BASE(20)
115         ldr     x1, =0x00FF000C
116         bl      ccn504_set_qos
117         ldr     x0, =CCI_S2_QOS_CONTROL_BASE(20)
118         ldr     x1, =0x00FF000C
119         bl      ccn504_set_qos
120 #endif
121
122 #ifdef SMMU_BASE
123         /* Set the SMMU page size in the sACR register */
124         ldr     x1, =SMMU_BASE
125         ldr     w0, [x1, #0x10]
126         orr     w0, w0, #1 << 16  /* set sACR.pagesize to indicate 64K page */
127         str     w0, [x1, #0x10]
128 #endif
129
130         /* Initialize GIC Secure Bank Status */
131 #if defined(CONFIG_GICV2) || defined(CONFIG_GICV3)
132         branch_if_slave x0, 1f
133         ldr     x0, =GICD_BASE
134         bl      gic_init_secure
135 1:
136 #ifdef CONFIG_GICV3
137         ldr     x0, =GICR_BASE
138         bl      gic_init_secure_percpu
139 #elif defined(CONFIG_GICV2)
140         ldr     x0, =GICD_BASE
141         ldr     x1, =GICC_BASE
142         bl      gic_init_secure_percpu
143 #endif
144 #endif
145
146         branch_if_master x0, x1, 2f
147
148 #if defined(CONFIG_MP) && defined(CONFIG_ARMV8_MULTIENTRY)
149         ldr     x0, =secondary_boot_func
150         blr     x0
151 #endif
152
153 2:
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 */
158         str     w0, [x1]
159
160         isb
161         dsb     sy
162 #endif
163
164 #ifdef CONFIG_FSL_TZASC_400
165         /*
166          * LS2080 and its personalities does not support TZASC
167          * So skip TZASC related operations
168          */
169         bl      get_svr
170         lsr     w0, w0, #16
171         ldr     w1, =SVR_DEV_LS2080A
172         cmp     w0, w1
173         b.eq    1f
174
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
178          *
179          * NOTE: As per the CCSR map doc, TZASC 3 and TZASC 4 are just
180          *       placeholders.
181          */
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 */
185         str     w0, [x1]
186
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 */
190         str     w0, [x1]
191
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] */
196         str     w0, [x1]
197
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] */
202         str     w0, [x1]
203
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 */
207         str     w0, [x1]
208
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 */
212         str     w0, [x1]
213
214         isb
215         dsb     sy
216 #endif
217 1:
218 #ifdef CONFIG_ARCH_LS1046A
219         /* Initialize the L2 RAM latency */
220         mrs   x1, S3_1_c11_c0_2
221         mov   x0, #0x1C7
222         /* Clear L2 Tag RAM latency and L2 Data RAM latency */
223         bic   x1, x1, x0
224         /* Set L2 data ram latency bits [2:0] */
225         orr   x1, x1, #0x2
226         /* set L2 tag ram latency bits [8:6] */
227         orr   x1,  x1, #0x80
228         msr   S3_1_c11_c0_2, x1
229         isb
230 #endif
231
232         mov     lr, x29                 /* Restore LR */
233         ret
234 ENDPROC(lowlevel_init)
235
236 #ifdef CONFIG_FSL_LSCH3
237         .globl get_svr
238 get_svr:
239         ldr     x1, =FSL_LSCH3_SVR
240         ldr     w0, [x1]
241         ret
242
243 hnf_pstate_poll:
244         /* x0 has the desired status, return 0 for success, 1 for timeout
245          * clobber x1, x2, x3, x4, x6, x7
246          */
247         mov     x1, x0
248         mov     x7, #0                  /* flag for timeout */
249         mrs     x3, cntpct_el0          /* read timer */
250         add     x3, x3, #1200           /* timeout after 100 microseconds */
251         mov     x0, #0x18
252         movk    x0, #0x420, lsl #16     /* HNF0_PSTATE_STATUS */
253         mov     w6, #8                  /* HN-F node count */
254 1:
255         ldr     x2, [x0]
256         cmp     x2, x1                  /* check status */
257         b.eq    2f
258         mrs     x4, cntpct_el0
259         cmp     x4, x3
260         b.ls    1b
261         mov     x7, #1                  /* timeout */
262         b       3f
263 2:
264         add     x0, x0, #0x10000        /* move to next node */
265         subs    w6, w6, #1
266         cbnz    w6, 1b
267 3:
268         mov     x0, x7
269         ret
270
271 hnf_set_pstate:
272         /* x0 has the desired state, clobber x1, x2, x6 */
273         mov     x1, x0
274         /* power state to SFONLY */
275         mov     w6, #8                  /* HN-F node count */
276         mov     x0, #0x10
277         movk    x0, #0x420, lsl #16     /* HNF0_PSTATE_REQ */
278 1:      /* set pstate to sfonly */
279         ldr     x2, [x0]
280         and     x2, x2, #0xfffffffffffffffc     /* & HNFPSTAT_MASK */
281         orr     x2, x2, x1
282         str     x2, [x0]
283         add     x0, x0, #0x10000        /* move to next node */
284         subs    w6, w6, #1
285         cbnz    w6, 1b
286
287         ret
288
289 ENTRY(__asm_flush_l3_dcache)
290         /*
291          * Return status in x0
292          *    success 0
293          *    tmeout 1 for setting SFONLY, 2 for FAM, 3 for both
294          */
295         mov     x29, lr
296         mov     x8, #0
297
298         dsb     sy
299         mov     x0, #0x1                /* HNFPSTAT_SFONLY */
300         bl      hnf_set_pstate
301
302         mov     x0, #0x4                /* SFONLY status */
303         bl      hnf_pstate_poll
304         cbz     x0, 1f
305         mov     x8, #1                  /* timeout */
306 1:
307         dsb     sy
308         mov     x0, #0x3                /* HNFPSTAT_FAM */
309         bl      hnf_set_pstate
310
311         mov     x0, #0xc                /* FAM status */
312         bl      hnf_pstate_poll
313         cbz     x0, 1f
314         add     x8, x8, #0x2
315 1:
316         mov     x0, x8
317         mov     lr, x29
318         ret
319 ENDPROC(__asm_flush_l3_dcache)
320 #endif
321
322 #ifdef CONFIG_MP
323         /* Keep literals not used by the secondary boot code outside it */
324         .ltorg
325
326         /* Using 64 bit alignment since the spin table is accessed as data */
327         .align 4
328         .global secondary_boot_code
329         /* Secondary Boot Code starts here */
330 secondary_boot_code:
331         .global __spin_table
332 __spin_table:
333         .space CONFIG_MAX_CPUS*SPIN_TABLE_ELEM_SIZE
334
335         .align 2
336 ENTRY(secondary_boot_func)
337         /*
338          * MPIDR_EL1 Fields:
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
343          * MPIDR[24] = MT
344          * MPIDR[29:25] = RES0
345          * MPIDR[30] = U
346          * MPIDR[31] = ME
347          * MPIDR[39:32] = AFF3
348          *
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)
352          *
353          * LPID = MPIDR[15:8] | MPIDR[1:0]
354          */
355         mrs     x0, mpidr_el1
356         ubfm    x1, x0, #8, #15
357         ubfm    x2, x0, #0, #1
358         orr     x10, x2, x1, lsl #2     /* x10 has LPID */
359         ubfm    x9, x0, #0, #15         /* x9 contains MPIDR[15:0] */
360         /*
361          * offset of the spin table element for this core from start of spin
362          * table (each elem is padded to 64 bytes)
363          */
364         lsl     x1, x10, #6
365         ldr     x0, =__spin_table
366         /* physical address of this cpus spin table element */
367         add     x11, x1, x0
368
369         ldr     x0, =__real_cntfrq
370         ldr     x0, [x0]
371         msr     cntfrq_el0, x0  /* set with real frequency */
372         str     x9, [x11, #16]  /* LPID */
373         mov     x4, #1
374         str     x4, [x11, #8]   /* STATUS */
375         dsb     sy
376 #if defined(CONFIG_GICV3)
377         gic_wait_for_interrupt_m x0
378 #elif defined(CONFIG_GICV2)
379         ldr     x0, =GICC_BASE
380         gic_wait_for_interrupt_m x0, w1
381 #endif
382
383 slave_cpu:
384         wfe
385         ldr     x0, [x11]
386         cbz     x0, slave_cpu
387 #ifndef CONFIG_ARMV8_SWITCH_TO_EL1
388         mrs     x1, sctlr_el2
389 #else
390         mrs     x1, sctlr_el1
391 #endif
392         tbz     x1, #25, cpu_is_le
393         rev     x0, x0                  /* BE to LE conversion */
394 cpu_is_le:
395         ldr     x5, [x11, #24]
396         ldr     x6, =IH_ARCH_DEFAULT
397         cmp     x6, x5
398         b.eq    1f
399
400 #ifdef CONFIG_ARMV8_SWITCH_TO_EL1
401         adr     x3, secondary_switch_to_el1
402         ldr     x4, =ES_TO_AARCH64
403 #else
404         ldr     x3, [x11]
405         ldr     x4, =ES_TO_AARCH32
406 #endif
407         bl      secondary_switch_to_el2
408
409 1:
410 #ifdef CONFIG_ARMV8_SWITCH_TO_EL1
411         adr     x3, secondary_switch_to_el1
412 #else
413         ldr     x3, [x11]
414 #endif
415         ldr     x4, =ES_TO_AARCH64
416         bl      secondary_switch_to_el2
417
418 ENDPROC(secondary_boot_func)
419
420 ENTRY(secondary_switch_to_el2)
421         switch_el x5, 1f, 0f, 0f
422 0:      ret
423 1:      armv8_switch_to_el2_m x3, x4, x5
424 ENDPROC(secondary_switch_to_el2)
425
426 ENTRY(secondary_switch_to_el1)
427         mrs     x0, mpidr_el1
428         ubfm    x1, x0, #8, #15
429         ubfm    x2, x0, #0, #1
430         orr     x10, x2, x1, lsl #2     /* x10 has LPID */
431
432         lsl     x1, x10, #6
433         ldr     x0, =__spin_table
434         /* physical address of this cpus spin table element */
435         add     x11, x1, x0
436
437         ldr     x3, [x11]
438
439         ldr     x5, [x11, #24]
440         ldr     x6, =IH_ARCH_DEFAULT
441         cmp     x6, x5
442         b.eq    2f
443
444         ldr     x4, =ES_TO_AARCH32
445         bl      switch_to_el1
446
447 2:      ldr     x4, =ES_TO_AARCH64
448
449 switch_to_el1:
450         switch_el x5, 0f, 1f, 0f
451 0:      ret
452 1:      armv8_switch_to_el1_m x3, x4, x5
453 ENDPROC(secondary_switch_to_el1)
454
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
458          */
459         .ltorg
460
461         /* 64 bit alignment for elements accessed as data */
462         .align 4
463         .global __real_cntfrq
464 __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
471 #endif