blob: 7fa48648d9dcc97af30cf39cfcb891e7080d6ea0 [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
Venkatesh Yadav Abbarapuda023da2024-03-06 16:54:41 +0530952:
96#if defined(CONFIG_GICV3_SUPPORT_GIC600)
97 mov w10, #0x0 /* Power on redistributor */
98 str w10, [x9, GICR_PWRR]
995: ldr w10, [x9, GICR_PWRR] /* Wait until the power on state is reflected */
100 tbnz w10, #1, 5b /* If RDPD == 0 then powered on */
101#endif
102
David Feng79bbde02014-03-14 14:26:27 +0800103 /* x9: ReDistributor Base Address of Current CPU */
Venkatesh Yadav Abbarapuda023da2024-03-06 16:54:41 +0530104 mov w10, #~0x2
David Feng79bbde02014-03-14 14:26:27 +0800105 ldr w11, [x9, GICR_WAKER]
106 and w11, w11, w10 /* Clear ProcessorSleep */
107 str w11, [x9, GICR_WAKER]
108 dsb st
109 isb
1103: ldr w10, [x9, GICR_WAKER]
111 tbnz w10, #2, 3b /* Wait Children be Alive */
112
113 add x10, x9, #(1 << 16) /* SGI_Base */
114 mov w11, #~0
115 str w11, [x10, GICR_IGROUPRn]
116 str wzr, [x10, GICR_IGROUPMODRn] /* SGIs|PPIs Group1NS */
117 mov w11, #0x1 /* Enable SGI 0 */
118 str w11, [x10, GICR_ISENABLERn]
119
Michal Simek1d10cc62017-09-07 09:20:32 +0200120 switch_el x10, 3f, 2f, 1f
1213:
David Feng79bbde02014-03-14 14:26:27 +0800122 /* Initialize Cpu Interface */
123 mrs x10, ICC_SRE_EL3
124 orr x10, x10, #0xf /* SRE & Disable IRQ/FIQ Bypass & */
125 /* Allow EL2 access to ICC_SRE_EL2 */
126 msr ICC_SRE_EL3, x10
127 isb
128
David Feng79bbde02014-03-14 14:26:27 +0800129 mov x10, #0x3 /* EnableGrp1NS | EnableGrp1S */
130 msr ICC_IGRPEN1_EL3, x10
131 isb
132
133 msr ICC_CTLR_EL3, xzr
134 isb
Michal Simek1d10cc62017-09-07 09:20:32 +02001352:
136 mrs x10, ICC_SRE_EL2
137 orr x10, x10, #0xf /* SRE & Disable IRQ/FIQ Bypass & */
138 /* Allow EL1 access to ICC_SRE_EL1 */
139 msr ICC_SRE_EL2, x10
140 isb
1411:
David Feng79bbde02014-03-14 14:26:27 +0800142 msr ICC_CTLR_EL1, xzr /* NonSecure ICC_CTLR_EL1 */
143 isb
144
145 mov x10, #0x1 << 7 /* Non-Secure access to ICC_PMR_EL1 */
146 msr ICC_PMR_EL1, x10
147 isb
148#elif defined(CONFIG_GICV2)
149 /*
150 * Initialize SGIs and PPIs
151 * x0: Distributor Base
152 * x1: Cpu Interface Base
153 */
Sai Pavan Boddubd3fd0c2022-05-11 10:39:07 +0200154 switch_el x2, 4f, 5f, 5f
1554:
David Feng79bbde02014-03-14 14:26:27 +0800156 mov w9, #~0 /* Config SGIs and PPIs as Grp1 */
157 str w9, [x0, GICD_IGROUPRn] /* GICD_IGROUPR0 */
158 mov w9, #0x1 /* Enable SGI 0 */
159 str w9, [x0, GICD_ISENABLERn]
160
161 /* Initialize Cpu Interface */
162 mov w9, #0x1e7 /* Disable IRQ/FIQ Bypass & */
163 /* Enable Ack Group1 Interrupt & */
164 /* EnableGrp0 & EnableGrp1 */
165 str w9, [x1, GICC_CTLR] /* Secure GICC_CTLR */
166
167 mov w9, #0x1 << 7 /* Non-Secure access to GICC_PMR */
168 str w9, [x1, GICC_PMR]
169#endif
Sai Pavan Boddubd3fd0c2022-05-11 10:39:07 +02001705:
David Feng79bbde02014-03-14 14:26:27 +0800171 ret
172ENDPROC(gic_init_secure_percpu)
173
174
175/*************************************************************************
176 * For Gicv2:
177 * void gic_kick_secondary_cpus(DistributorBase);
178 * For Gicv3:
179 * void gic_kick_secondary_cpus(void);
180 *
181 *************************************************************************/
182ENTRY(gic_kick_secondary_cpus)
183#if defined(CONFIG_GICV3)
184 mov x9, #(1 << 40)
185 msr ICC_ASGI1R_EL1, x9
186 isb
187#elif defined(CONFIG_GICV2)
188 mov w9, #0x8000
189 movk w9, #0x100, lsl #16
190 str w9, [x0, GICD_SGIR]
191#endif
192 ret
193ENDPROC(gic_kick_secondary_cpus)
194
195
196/*************************************************************************
197 * For Gicv2:
198 * void gic_wait_for_interrupt(CpuInterfaceBase);
199 * For Gicv3:
200 * void gic_wait_for_interrupt(void);
201 *
202 * Wait for SGI 0 from master.
203 *
204 *************************************************************************/
205ENTRY(gic_wait_for_interrupt)
David Feng79bbde02014-03-14 14:26:27 +0800206#if defined(CONFIG_GICV3)
York Sun56cc3db2014-09-08 12:20:00 -0700207 gic_wait_for_interrupt_m x9
David Feng79bbde02014-03-14 14:26:27 +0800208#elif defined(CONFIG_GICV2)
York Sun56cc3db2014-09-08 12:20:00 -0700209 gic_wait_for_interrupt_m x0, w9
David Feng79bbde02014-03-14 14:26:27 +0800210#endif
David Feng79bbde02014-03-14 14:26:27 +0800211 ret
212ENDPROC(gic_wait_for_interrupt)