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