blob: 86cd882fc75908088d72a2263e4df2b5cda199fa [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001/* SPDX-License-Identifier: GPL-2.0+ */
David Feng79bbde02014-03-14 14:26:27 +08002/*
3 * GIC Initialization Routines.
4 *
5 * (C) Copyright 2013
6 * David Feng <fenghua@phytium.com.cn>
David Feng79bbde02014-03-14 14:26:27 +08007 */
8
9#include <asm-offsets.h>
10#include <config.h>
11#include <linux/linkage.h>
David Feng79bbde02014-03-14 14:26:27 +080012#include <asm/gic.h>
York Sun56cc3db2014-09-08 12:20:00 -070013#include <asm/macro.h>
David Feng79bbde02014-03-14 14:26:27 +080014
15
16/*************************************************************************
17 *
18 * void gic_init_secure(DistributorBase);
19 *
20 * Initialize secure copy of GIC at EL3.
21 *
22 *************************************************************************/
23ENTRY(gic_init_secure)
24 /*
25 * Initialize Distributor
26 * x0: Distributor Base
27 */
28#if defined(CONFIG_GICV3)
29 mov w9, #0x37 /* EnableGrp0 | EnableGrp1NS */
30 /* EnableGrp1S | ARE_S | ARE_NS */
31 str w9, [x0, GICD_CTLR] /* Secure GICD_CTLR */
32 ldr w9, [x0, GICD_TYPER]
33 and w10, w9, #0x1f /* ITLinesNumber */
34 cbz w10, 1f /* No SPIs */
35 add x11, x0, (GICD_IGROUPRn + 4)
36 add x12, x0, (GICD_IGROUPMODRn + 4)
37 mov w9, #~0
380: str w9, [x11], #0x4
39 str wzr, [x12], #0x4 /* Config SPIs as Group1NS */
40 sub w10, w10, #0x1
41 cbnz w10, 0b
42#elif defined(CONFIG_GICV2)
Sai Pavan Boddubd3fd0c2022-05-11 10:39:07 +020043 switch_el x1, 2f, 1f, 1f
442:
David Feng79bbde02014-03-14 14:26:27 +080045 mov w9, #0x3 /* EnableGrp0 | EnableGrp1 */
46 str w9, [x0, GICD_CTLR] /* Secure GICD_CTLR */
47 ldr w9, [x0, GICD_TYPER]
48 and w10, w9, #0x1f /* ITLinesNumber */
49 cbz w10, 1f /* No SPIs */
Thierry Redingda1a9042015-08-20 11:52:15 +020050 add x11, x0, GICD_IGROUPRn
David Feng79bbde02014-03-14 14:26:27 +080051 mov w9, #~0 /* Config SPIs as Grp1 */
Thierry Redingda1a9042015-08-20 11:52:15 +020052 str w9, [x11], #0x4
David Feng79bbde02014-03-14 14:26:27 +0800530: str w9, [x11], #0x4
54 sub w10, w10, #0x1
55 cbnz w10, 0b
Thierry Redingda1a9042015-08-20 11:52:15 +020056
57 ldr x1, =GICC_BASE /* GICC_CTLR */
58 mov w0, #3 /* EnableGrp0 | EnableGrp1 */
59 str w0, [x1]
60
61 mov w0, #1 << 7 /* allow NS access to GICC_PMR */
62 str w0, [x1, #4] /* GICC_PMR */
David Feng79bbde02014-03-14 14:26:27 +080063#endif
641:
65 ret
66ENDPROC(gic_init_secure)
67
68
69/*************************************************************************
70 * For Gicv2:
71 * void gic_init_secure_percpu(DistributorBase, CpuInterfaceBase);
72 * For Gicv3:
73 * void gic_init_secure_percpu(ReDistributorBase);
74 *
75 * Initialize secure copy of GIC at EL3.
76 *
77 *************************************************************************/
78ENTRY(gic_init_secure_percpu)
79#if defined(CONFIG_GICV3)
80 /*
81 * Initialize ReDistributor
82 * x0: ReDistributor Base
83 */
84 mrs x10, mpidr_el1
85 lsr x9, x10, #32
86 bfi x10, x9, #24, #8 /* w10 is aff3:aff2:aff1:aff0 */
87 mov x9, x0
881: ldr x11, [x9, GICR_TYPER]
89 lsr x11, x11, #32 /* w11 is aff3:aff2:aff1:aff0 */
90 cmp w10, w11
91 b.eq 2f
92 add x9, x9, #(2 << 16)
93 b 1b
94
95 /* x9: ReDistributor Base Address of Current CPU */
962: mov w10, #~0x2
97 ldr w11, [x9, GICR_WAKER]
98 and w11, w11, w10 /* Clear ProcessorSleep */
99 str w11, [x9, GICR_WAKER]
100 dsb st
101 isb
1023: ldr w10, [x9, GICR_WAKER]
103 tbnz w10, #2, 3b /* Wait Children be Alive */
104
105 add x10, x9, #(1 << 16) /* SGI_Base */
106 mov w11, #~0
107 str w11, [x10, GICR_IGROUPRn]
108 str wzr, [x10, GICR_IGROUPMODRn] /* SGIs|PPIs Group1NS */
109 mov w11, #0x1 /* Enable SGI 0 */
110 str w11, [x10, GICR_ISENABLERn]
111
Michal Simek1d10cc62017-09-07 09:20:32 +0200112 switch_el x10, 3f, 2f, 1f
1133:
David Feng79bbde02014-03-14 14:26:27 +0800114 /* Initialize Cpu Interface */
115 mrs x10, ICC_SRE_EL3
116 orr x10, x10, #0xf /* SRE & Disable IRQ/FIQ Bypass & */
117 /* Allow EL2 access to ICC_SRE_EL2 */
118 msr ICC_SRE_EL3, x10
119 isb
120
David Feng79bbde02014-03-14 14:26:27 +0800121 mov x10, #0x3 /* EnableGrp1NS | EnableGrp1S */
122 msr ICC_IGRPEN1_EL3, x10
123 isb
124
125 msr ICC_CTLR_EL3, xzr
126 isb
Michal Simek1d10cc62017-09-07 09:20:32 +02001272:
128 mrs x10, ICC_SRE_EL2
129 orr x10, x10, #0xf /* SRE & Disable IRQ/FIQ Bypass & */
130 /* Allow EL1 access to ICC_SRE_EL1 */
131 msr ICC_SRE_EL2, x10
132 isb
1331:
David Feng79bbde02014-03-14 14:26:27 +0800134 msr ICC_CTLR_EL1, xzr /* NonSecure ICC_CTLR_EL1 */
135 isb
136
137 mov x10, #0x1 << 7 /* Non-Secure access to ICC_PMR_EL1 */
138 msr ICC_PMR_EL1, x10
139 isb
140#elif defined(CONFIG_GICV2)
141 /*
142 * Initialize SGIs and PPIs
143 * x0: Distributor Base
144 * x1: Cpu Interface Base
145 */
Sai Pavan Boddubd3fd0c2022-05-11 10:39:07 +0200146 switch_el x2, 4f, 5f, 5f
1474:
David Feng79bbde02014-03-14 14:26:27 +0800148 mov w9, #~0 /* Config SGIs and PPIs as Grp1 */
149 str w9, [x0, GICD_IGROUPRn] /* GICD_IGROUPR0 */
150 mov w9, #0x1 /* Enable SGI 0 */
151 str w9, [x0, GICD_ISENABLERn]
152
153 /* Initialize Cpu Interface */
154 mov w9, #0x1e7 /* Disable IRQ/FIQ Bypass & */
155 /* Enable Ack Group1 Interrupt & */
156 /* EnableGrp0 & EnableGrp1 */
157 str w9, [x1, GICC_CTLR] /* Secure GICC_CTLR */
158
159 mov w9, #0x1 << 7 /* Non-Secure access to GICC_PMR */
160 str w9, [x1, GICC_PMR]
161#endif
Sai Pavan Boddubd3fd0c2022-05-11 10:39:07 +02001625:
David Feng79bbde02014-03-14 14:26:27 +0800163 ret
164ENDPROC(gic_init_secure_percpu)
165
166
167/*************************************************************************
168 * For Gicv2:
169 * void gic_kick_secondary_cpus(DistributorBase);
170 * For Gicv3:
171 * void gic_kick_secondary_cpus(void);
172 *
173 *************************************************************************/
174ENTRY(gic_kick_secondary_cpus)
175#if defined(CONFIG_GICV3)
176 mov x9, #(1 << 40)
177 msr ICC_ASGI1R_EL1, x9
178 isb
179#elif defined(CONFIG_GICV2)
180 mov w9, #0x8000
181 movk w9, #0x100, lsl #16
182 str w9, [x0, GICD_SGIR]
183#endif
184 ret
185ENDPROC(gic_kick_secondary_cpus)
186
187
188/*************************************************************************
189 * For Gicv2:
190 * void gic_wait_for_interrupt(CpuInterfaceBase);
191 * For Gicv3:
192 * void gic_wait_for_interrupt(void);
193 *
194 * Wait for SGI 0 from master.
195 *
196 *************************************************************************/
197ENTRY(gic_wait_for_interrupt)
David Feng79bbde02014-03-14 14:26:27 +0800198#if defined(CONFIG_GICV3)
York Sun56cc3db2014-09-08 12:20:00 -0700199 gic_wait_for_interrupt_m x9
David Feng79bbde02014-03-14 14:26:27 +0800200#elif defined(CONFIG_GICV2)
York Sun56cc3db2014-09-08 12:20:00 -0700201 gic_wait_for_interrupt_m x0, w9
David Feng79bbde02014-03-14 14:26:27 +0800202#endif
David Feng79bbde02014-03-14 14:26:27 +0800203 ret
204ENDPROC(gic_wait_for_interrupt)