2 * GIC Initialization Routines.
5 * David Feng <fenghua@phytium.com.cn>
7 * SPDX-License-Identifier: GPL-2.0+
10 #include <asm-offsets.h>
12 #include <linux/linkage.h>
14 #include <asm/macro.h>
17 /*************************************************************************
19 * void gic_init_secure(DistributorBase);
21 * Initialize secure copy of GIC at EL3.
23 *************************************************************************/
24 ENTRY(gic_init_secure)
26 * Initialize Distributor
27 * x0: Distributor Base
29 #if defined(CONFIG_GICV3)
30 mov w9, #0x37 /* EnableGrp0 | EnableGrp1NS */
31 /* EnableGrp1S | ARE_S | ARE_NS */
32 str w9, [x0, GICD_CTLR] /* Secure GICD_CTLR */
33 ldr w9, [x0, GICD_TYPER]
34 and w10, w9, #0x1f /* ITLinesNumber */
35 cbz w10, 1f /* No SPIs */
36 add x11, x0, (GICD_IGROUPRn + 4)
37 add x12, x0, (GICD_IGROUPMODRn + 4)
39 0: str w9, [x11], #0x4
40 str wzr, [x12], #0x4 /* Config SPIs as Group1NS */
43 #elif defined(CONFIG_GICV2)
44 mov w9, #0x3 /* EnableGrp0 | EnableGrp1 */
45 str w9, [x0, GICD_CTLR] /* Secure GICD_CTLR */
46 ldr w9, [x0, GICD_TYPER]
47 and w10, w9, #0x1f /* ITLinesNumber */
48 cbz w10, 1f /* No SPIs */
49 add x11, x0, GICD_IGROUPRn
50 mov w9, #~0 /* Config SPIs as Grp1 */
52 0: str w9, [x11], #0x4
56 ldr x1, =GICC_BASE /* GICC_CTLR */
57 mov w0, #3 /* EnableGrp0 | EnableGrp1 */
60 mov w0, #1 << 7 /* allow NS access to GICC_PMR */
61 str w0, [x1, #4] /* GICC_PMR */
65 ENDPROC(gic_init_secure)
68 /*************************************************************************
70 * void gic_init_secure_percpu(DistributorBase, CpuInterfaceBase);
72 * void gic_init_secure_percpu(ReDistributorBase);
74 * Initialize secure copy of GIC at EL3.
76 *************************************************************************/
77 ENTRY(gic_init_secure_percpu)
78 #if defined(CONFIG_GICV3)
80 * Initialize ReDistributor
81 * x0: ReDistributor Base
85 bfi x10, x9, #24, #8 /* w10 is aff3:aff2:aff1:aff0 */
87 1: ldr x11, [x9, GICR_TYPER]
88 lsr x11, x11, #32 /* w11 is aff3:aff2:aff1:aff0 */
91 add x9, x9, #(2 << 16)
94 /* x9: ReDistributor Base Address of Current CPU */
96 ldr w11, [x9, GICR_WAKER]
97 and w11, w11, w10 /* Clear ProcessorSleep */
98 str w11, [x9, GICR_WAKER]
101 3: ldr w10, [x9, GICR_WAKER]
102 tbnz w10, #2, 3b /* Wait Children be Alive */
104 add x10, x9, #(1 << 16) /* SGI_Base */
106 str w11, [x10, GICR_IGROUPRn]
107 str wzr, [x10, GICR_IGROUPMODRn] /* SGIs|PPIs Group1NS */
108 mov w11, #0x1 /* Enable SGI 0 */
109 str w11, [x10, GICR_ISENABLERn]
111 /* Initialize Cpu Interface */
113 orr x10, x10, #0xf /* SRE & Disable IRQ/FIQ Bypass & */
114 /* Allow EL2 access to ICC_SRE_EL2 */
119 orr x10, x10, #0xf /* SRE & Disable IRQ/FIQ Bypass & */
120 /* Allow EL1 access to ICC_SRE_EL1 */
124 mov x10, #0x3 /* EnableGrp1NS | EnableGrp1S */
125 msr ICC_IGRPEN1_EL3, x10
128 msr ICC_CTLR_EL3, xzr
131 msr ICC_CTLR_EL1, xzr /* NonSecure ICC_CTLR_EL1 */
134 mov x10, #0x1 << 7 /* Non-Secure access to ICC_PMR_EL1 */
137 #elif defined(CONFIG_GICV2)
139 * Initialize SGIs and PPIs
140 * x0: Distributor Base
141 * x1: Cpu Interface Base
143 mov w9, #~0 /* Config SGIs and PPIs as Grp1 */
144 str w9, [x0, GICD_IGROUPRn] /* GICD_IGROUPR0 */
145 mov w9, #0x1 /* Enable SGI 0 */
146 str w9, [x0, GICD_ISENABLERn]
148 /* Initialize Cpu Interface */
149 mov w9, #0x1e7 /* Disable IRQ/FIQ Bypass & */
150 /* Enable Ack Group1 Interrupt & */
151 /* EnableGrp0 & EnableGrp1 */
152 str w9, [x1, GICC_CTLR] /* Secure GICC_CTLR */
154 mov w9, #0x1 << 7 /* Non-Secure access to GICC_PMR */
155 str w9, [x1, GICC_PMR]
158 ENDPROC(gic_init_secure_percpu)
161 /*************************************************************************
163 * void gic_kick_secondary_cpus(DistributorBase);
165 * void gic_kick_secondary_cpus(void);
167 *************************************************************************/
168 ENTRY(gic_kick_secondary_cpus)
169 #if defined(CONFIG_GICV3)
171 msr ICC_ASGI1R_EL1, x9
173 #elif defined(CONFIG_GICV2)
175 movk w9, #0x100, lsl #16
176 str w9, [x0, GICD_SGIR]
179 ENDPROC(gic_kick_secondary_cpus)
182 /*************************************************************************
184 * void gic_wait_for_interrupt(CpuInterfaceBase);
186 * void gic_wait_for_interrupt(void);
188 * Wait for SGI 0 from master.
190 *************************************************************************/
191 ENTRY(gic_wait_for_interrupt)
192 #if defined(CONFIG_GICV3)
193 gic_wait_for_interrupt_m x9
194 #elif defined(CONFIG_GICV2)
195 gic_wait_for_interrupt_m x0, w9
198 ENDPROC(gic_wait_for_interrupt)