gicv3_fdt.c revision 1.2.2.3 1 1.2.2.3 pgoyette /* $NetBSD: gicv3_fdt.c,v 1.2.2.3 2018/09/30 01:45:38 pgoyette Exp $ */
2 1.2.2.2 pgoyette
3 1.2.2.2 pgoyette /*-
4 1.2.2.2 pgoyette * Copyright (c) 2015-2018 Jared McNeill <jmcneill (at) invisible.ca>
5 1.2.2.2 pgoyette * All rights reserved.
6 1.2.2.2 pgoyette *
7 1.2.2.2 pgoyette * Redistribution and use in source and binary forms, with or without
8 1.2.2.2 pgoyette * modification, are permitted provided that the following conditions
9 1.2.2.2 pgoyette * are met:
10 1.2.2.2 pgoyette * 1. Redistributions of source code must retain the above copyright
11 1.2.2.2 pgoyette * notice, this list of conditions and the following disclaimer.
12 1.2.2.2 pgoyette * 2. Redistributions in binary form must reproduce the above copyright
13 1.2.2.2 pgoyette * notice, this list of conditions and the following disclaimer in the
14 1.2.2.2 pgoyette * documentation and/or other materials provided with the distribution.
15 1.2.2.2 pgoyette *
16 1.2.2.2 pgoyette * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 1.2.2.2 pgoyette * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 1.2.2.2 pgoyette * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 1.2.2.2 pgoyette * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 1.2.2.2 pgoyette * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
21 1.2.2.2 pgoyette * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 1.2.2.2 pgoyette * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
23 1.2.2.2 pgoyette * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24 1.2.2.2 pgoyette * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 1.2.2.2 pgoyette * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 1.2.2.2 pgoyette * SUCH DAMAGE.
27 1.2.2.2 pgoyette */
28 1.2.2.2 pgoyette
29 1.2.2.2 pgoyette #define _INTR_PRIVATE
30 1.2.2.2 pgoyette
31 1.2.2.2 pgoyette #include <sys/cdefs.h>
32 1.2.2.3 pgoyette __KERNEL_RCSID(0, "$NetBSD: gicv3_fdt.c,v 1.2.2.3 2018/09/30 01:45:38 pgoyette Exp $");
33 1.2.2.2 pgoyette
34 1.2.2.2 pgoyette #include <sys/param.h>
35 1.2.2.2 pgoyette #include <sys/bus.h>
36 1.2.2.2 pgoyette #include <sys/device.h>
37 1.2.2.2 pgoyette #include <sys/intr.h>
38 1.2.2.2 pgoyette #include <sys/systm.h>
39 1.2.2.2 pgoyette #include <sys/kernel.h>
40 1.2.2.2 pgoyette #include <sys/lwp.h>
41 1.2.2.2 pgoyette #include <sys/kmem.h>
42 1.2.2.2 pgoyette #include <sys/queue.h>
43 1.2.2.2 pgoyette
44 1.2.2.2 pgoyette #include <dev/fdt/fdtvar.h>
45 1.2.2.2 pgoyette
46 1.2.2.2 pgoyette #include <arm/cortex/gicv3.h>
47 1.2.2.3 pgoyette #include <arm/cortex/gic_reg.h>
48 1.2.2.2 pgoyette
49 1.2.2.2 pgoyette #define GICV3_MAXIRQ 1020
50 1.2.2.2 pgoyette
51 1.2.2.2 pgoyette #define IRQ_PPI(n) ((n) + 16)
52 1.2.2.2 pgoyette #define IRQ_SPI(n) ((n) + 32)
53 1.2.2.2 pgoyette
54 1.2.2.2 pgoyette struct gicv3_fdt_softc;
55 1.2.2.2 pgoyette struct gicv3_fdt_irq;
56 1.2.2.2 pgoyette
57 1.2.2.2 pgoyette static int gicv3_fdt_match(device_t, cfdata_t, void *);
58 1.2.2.2 pgoyette static void gicv3_fdt_attach(device_t, device_t, void *);
59 1.2.2.2 pgoyette
60 1.2.2.2 pgoyette static int gicv3_fdt_map_registers(struct gicv3_fdt_softc *);
61 1.2.2.2 pgoyette
62 1.2.2.2 pgoyette static int gicv3_fdt_intr(void *);
63 1.2.2.2 pgoyette
64 1.2.2.2 pgoyette static void * gicv3_fdt_establish(device_t, u_int *, int, int,
65 1.2.2.2 pgoyette int (*)(void *), void *);
66 1.2.2.2 pgoyette static void gicv3_fdt_disestablish(device_t, void *);
67 1.2.2.2 pgoyette static bool gicv3_fdt_intrstr(device_t, u_int *, char *, size_t);
68 1.2.2.2 pgoyette
69 1.2.2.2 pgoyette struct fdtbus_interrupt_controller_func gicv3_fdt_funcs = {
70 1.2.2.2 pgoyette .establish = gicv3_fdt_establish,
71 1.2.2.2 pgoyette .disestablish = gicv3_fdt_disestablish,
72 1.2.2.2 pgoyette .intrstr = gicv3_fdt_intrstr
73 1.2.2.2 pgoyette };
74 1.2.2.2 pgoyette
75 1.2.2.2 pgoyette struct gicv3_fdt_irqhandler {
76 1.2.2.2 pgoyette struct gicv3_fdt_irq *ih_irq;
77 1.2.2.2 pgoyette int (*ih_fn)(void *);
78 1.2.2.2 pgoyette void *ih_arg;
79 1.2.2.2 pgoyette bool ih_mpsafe;
80 1.2.2.2 pgoyette TAILQ_ENTRY(gicv3_fdt_irqhandler) ih_next;
81 1.2.2.2 pgoyette };
82 1.2.2.2 pgoyette
83 1.2.2.2 pgoyette struct gicv3_fdt_irq {
84 1.2.2.2 pgoyette struct gicv3_fdt_softc *intr_sc;
85 1.2.2.2 pgoyette void *intr_ih;
86 1.2.2.2 pgoyette void *intr_arg;
87 1.2.2.2 pgoyette int intr_refcnt;
88 1.2.2.2 pgoyette int intr_ipl;
89 1.2.2.2 pgoyette int intr_level;
90 1.2.2.2 pgoyette int intr_mpsafe;
91 1.2.2.2 pgoyette TAILQ_HEAD(, gicv3_fdt_irqhandler) intr_handlers;
92 1.2.2.2 pgoyette int intr_irq;
93 1.2.2.2 pgoyette };
94 1.2.2.2 pgoyette
95 1.2.2.2 pgoyette struct gicv3_fdt_softc {
96 1.2.2.2 pgoyette struct gicv3_softc sc_gic;
97 1.2.2.2 pgoyette int sc_phandle;
98 1.2.2.2 pgoyette
99 1.2.2.2 pgoyette struct gicv3_fdt_irq *sc_irq[GICV3_MAXIRQ];
100 1.2.2.2 pgoyette };
101 1.2.2.2 pgoyette
102 1.2.2.2 pgoyette CFATTACH_DECL_NEW(gicv3_fdt, sizeof(struct gicv3_fdt_softc),
103 1.2.2.2 pgoyette gicv3_fdt_match, gicv3_fdt_attach, NULL, NULL);
104 1.2.2.2 pgoyette
105 1.2.2.2 pgoyette static int
106 1.2.2.2 pgoyette gicv3_fdt_match(device_t parent, cfdata_t cf, void *aux)
107 1.2.2.2 pgoyette {
108 1.2.2.2 pgoyette const char * const compatible[] = {
109 1.2.2.2 pgoyette "arm,gic-v3",
110 1.2.2.2 pgoyette NULL
111 1.2.2.2 pgoyette };
112 1.2.2.2 pgoyette struct fdt_attach_args * const faa = aux;
113 1.2.2.2 pgoyette const int phandle = faa->faa_phandle;
114 1.2.2.2 pgoyette
115 1.2.2.2 pgoyette return of_match_compatible(phandle, compatible);
116 1.2.2.2 pgoyette }
117 1.2.2.2 pgoyette
118 1.2.2.2 pgoyette static void
119 1.2.2.2 pgoyette gicv3_fdt_attach(device_t parent, device_t self, void *aux)
120 1.2.2.2 pgoyette {
121 1.2.2.2 pgoyette struct gicv3_fdt_softc * const sc = device_private(self);
122 1.2.2.2 pgoyette struct fdt_attach_args * const faa = aux;
123 1.2.2.2 pgoyette const int phandle = faa->faa_phandle;
124 1.2.2.2 pgoyette int error;
125 1.2.2.2 pgoyette
126 1.2.2.2 pgoyette error = fdtbus_register_interrupt_controller(self, phandle,
127 1.2.2.2 pgoyette &gicv3_fdt_funcs);
128 1.2.2.2 pgoyette if (error) {
129 1.2.2.2 pgoyette aprint_error(": couldn't register with fdtbus: %d\n", error);
130 1.2.2.2 pgoyette return;
131 1.2.2.2 pgoyette }
132 1.2.2.2 pgoyette
133 1.2.2.2 pgoyette aprint_naive("\n");
134 1.2.2.2 pgoyette aprint_normal(": GICv3\n");
135 1.2.2.2 pgoyette
136 1.2.2.2 pgoyette sc->sc_phandle = phandle;
137 1.2.2.2 pgoyette sc->sc_gic.sc_dev = self;
138 1.2.2.2 pgoyette sc->sc_gic.sc_bst = faa->faa_bst;
139 1.2.2.2 pgoyette
140 1.2.2.2 pgoyette error = gicv3_fdt_map_registers(sc);
141 1.2.2.2 pgoyette if (error) {
142 1.2.2.2 pgoyette aprint_error_dev(self, "couldn't map registers\n");
143 1.2.2.2 pgoyette return;
144 1.2.2.2 pgoyette }
145 1.2.2.2 pgoyette
146 1.2.2.2 pgoyette aprint_debug_dev(self, "%d redistributors\n", sc->sc_gic.sc_bsh_r_count);
147 1.2.2.2 pgoyette
148 1.2.2.2 pgoyette error = gicv3_init(&sc->sc_gic);
149 1.2.2.2 pgoyette if (error) {
150 1.2.2.2 pgoyette aprint_error_dev(self, "failed to initialize GIC: %d\n", error);
151 1.2.2.2 pgoyette return;
152 1.2.2.2 pgoyette }
153 1.2.2.2 pgoyette
154 1.2.2.2 pgoyette arm_fdt_irq_set_handler(gicv3_irq_handler);
155 1.2.2.2 pgoyette }
156 1.2.2.2 pgoyette
157 1.2.2.2 pgoyette static int
158 1.2.2.2 pgoyette gicv3_fdt_map_registers(struct gicv3_fdt_softc *sc)
159 1.2.2.2 pgoyette {
160 1.2.2.2 pgoyette struct gicv3_softc *gic = &sc->sc_gic;
161 1.2.2.2 pgoyette const int phandle = sc->sc_phandle;
162 1.2.2.2 pgoyette u_int redistributor_regions, redistributor_stride;
163 1.2.2.2 pgoyette bus_space_handle_t bsh;
164 1.2.2.2 pgoyette bus_size_t size, region_off;
165 1.2.2.2 pgoyette bus_addr_t addr;
166 1.2.2.2 pgoyette size_t reg_off;
167 1.2.2.3 pgoyette int n, r, max_redist, redist;
168 1.2.2.2 pgoyette
169 1.2.2.2 pgoyette if (of_getprop_uint32(phandle, "#redistributor-regions", &redistributor_regions))
170 1.2.2.2 pgoyette redistributor_regions = 1;
171 1.2.2.2 pgoyette if (of_getprop_uint32(phandle, "redistributor-stride", &redistributor_stride))
172 1.2.2.2 pgoyette redistributor_stride = 0x20000;
173 1.2.2.2 pgoyette
174 1.2.2.2 pgoyette /*
175 1.2.2.2 pgoyette * Map GIC Distributor interface (GICD)
176 1.2.2.2 pgoyette */
177 1.2.2.2 pgoyette if (fdtbus_get_reg(phandle, 0, &addr, &size) != 0) {
178 1.2.2.2 pgoyette aprint_error_dev(gic->sc_dev, "couldn't get distributor registers\n");
179 1.2.2.2 pgoyette return ENXIO;
180 1.2.2.2 pgoyette }
181 1.2.2.2 pgoyette if (bus_space_map(sc->sc_gic.sc_bst, addr, size, 0, &sc->sc_gic.sc_bsh_d) != 0) {
182 1.2.2.2 pgoyette aprint_error_dev(gic->sc_dev, "couldn't map distributor registers\n");
183 1.2.2.2 pgoyette return ENXIO;
184 1.2.2.2 pgoyette }
185 1.2.2.2 pgoyette
186 1.2.2.2 pgoyette /*
187 1.2.2.2 pgoyette * GIC Redistributors (GICR)
188 1.2.2.2 pgoyette */
189 1.2.2.3 pgoyette for (reg_off = 1, max_redist = 0, n = 0; n < redistributor_regions; n++, reg_off++) {
190 1.2.2.2 pgoyette if (fdtbus_get_reg(phandle, reg_off, NULL, &size) != 0) {
191 1.2.2.2 pgoyette aprint_error_dev(gic->sc_dev, "couldn't get redistributor registers\n");
192 1.2.2.2 pgoyette return ENXIO;
193 1.2.2.2 pgoyette }
194 1.2.2.3 pgoyette max_redist += howmany(size, redistributor_stride);
195 1.2.2.2 pgoyette }
196 1.2.2.3 pgoyette gic->sc_bsh_r = kmem_alloc(sizeof(bus_space_handle_t) * max_redist, KM_SLEEP);
197 1.2.2.3 pgoyette for (reg_off = 1, redist = 0, n = 0; n < redistributor_regions; n++, reg_off++) {
198 1.2.2.2 pgoyette if (fdtbus_get_reg(phandle, reg_off, &addr, &size) != 0) {
199 1.2.2.2 pgoyette aprint_error_dev(gic->sc_dev, "couldn't get redistributor registers\n");
200 1.2.2.2 pgoyette return ENXIO;
201 1.2.2.2 pgoyette }
202 1.2.2.2 pgoyette if (bus_space_map(sc->sc_gic.sc_bst, addr, size, 0, &bsh) != 0) {
203 1.2.2.2 pgoyette aprint_error_dev(gic->sc_dev, "couldn't map redistributor registers\n");
204 1.2.2.2 pgoyette return ENXIO;
205 1.2.2.2 pgoyette }
206 1.2.2.2 pgoyette const int count = howmany(size, redistributor_stride);
207 1.2.2.2 pgoyette for (r = 0, region_off = 0; r < count; r++, region_off += redistributor_stride) {
208 1.2.2.3 pgoyette if (bus_space_subregion(sc->sc_gic.sc_bst, bsh, region_off, redistributor_stride, &gic->sc_bsh_r[redist++]) != 0) {
209 1.2.2.2 pgoyette aprint_error_dev(gic->sc_dev, "couldn't subregion redistributor registers\n");
210 1.2.2.2 pgoyette return ENXIO;
211 1.2.2.2 pgoyette }
212 1.2.2.3 pgoyette
213 1.2.2.3 pgoyette /* If this is the last redist in this region, skip to the next one */
214 1.2.2.3 pgoyette const uint32_t typer = bus_space_read_4(sc->sc_gic.sc_bst, gic->sc_bsh_r[redist - 1], GICR_TYPER);
215 1.2.2.3 pgoyette if (typer & GICR_TYPER_Last)
216 1.2.2.3 pgoyette break;
217 1.2.2.2 pgoyette }
218 1.2.2.2 pgoyette }
219 1.2.2.3 pgoyette gic->sc_bsh_r_count = redist;
220 1.2.2.2 pgoyette
221 1.2.2.2 pgoyette return 0;
222 1.2.2.2 pgoyette }
223 1.2.2.2 pgoyette
224 1.2.2.2 pgoyette static void *
225 1.2.2.2 pgoyette gicv3_fdt_establish(device_t dev, u_int *specifier, int ipl, int flags,
226 1.2.2.2 pgoyette int (*func)(void *), void *arg)
227 1.2.2.2 pgoyette {
228 1.2.2.2 pgoyette struct gicv3_fdt_softc * const sc = device_private(dev);
229 1.2.2.2 pgoyette struct gicv3_fdt_irq *firq;
230 1.2.2.2 pgoyette struct gicv3_fdt_irqhandler *firqh;
231 1.2.2.2 pgoyette
232 1.2.2.2 pgoyette /* 1st cell is the interrupt type; 0 is SPI, 1 is PPI */
233 1.2.2.2 pgoyette /* 2nd cell is the interrupt number */
234 1.2.2.2 pgoyette /* 3rd cell is flags */
235 1.2.2.2 pgoyette /* 4th cell is affinity */
236 1.2.2.2 pgoyette
237 1.2.2.2 pgoyette const u_int type = be32toh(specifier[0]);
238 1.2.2.2 pgoyette const u_int intr = be32toh(specifier[1]);
239 1.2.2.2 pgoyette const u_int irq = type == 0 ? IRQ_SPI(intr) : IRQ_PPI(intr);
240 1.2.2.2 pgoyette const u_int trig = be32toh(specifier[2]) & 0xf;
241 1.2.2.2 pgoyette const u_int level = (trig & 0x3) ? IST_EDGE : IST_LEVEL;
242 1.2.2.2 pgoyette
243 1.2.2.2 pgoyette const u_int mpsafe = (flags & FDT_INTR_MPSAFE) ? IST_MPSAFE : 0;
244 1.2.2.2 pgoyette
245 1.2.2.2 pgoyette firq = sc->sc_irq[irq];
246 1.2.2.2 pgoyette if (firq == NULL) {
247 1.2.2.2 pgoyette firq = kmem_alloc(sizeof(*firq), KM_SLEEP);
248 1.2.2.2 pgoyette firq->intr_sc = sc;
249 1.2.2.2 pgoyette firq->intr_refcnt = 0;
250 1.2.2.2 pgoyette firq->intr_arg = arg;
251 1.2.2.2 pgoyette firq->intr_ipl = ipl;
252 1.2.2.2 pgoyette firq->intr_level = level;
253 1.2.2.2 pgoyette firq->intr_mpsafe = mpsafe;
254 1.2.2.2 pgoyette TAILQ_INIT(&firq->intr_handlers);
255 1.2.2.2 pgoyette firq->intr_irq = irq;
256 1.2.2.2 pgoyette if (arg == NULL) {
257 1.2.2.2 pgoyette firq->intr_ih = intr_establish(irq, ipl, level | mpsafe,
258 1.2.2.2 pgoyette func, NULL);
259 1.2.2.2 pgoyette } else {
260 1.2.2.2 pgoyette firq->intr_ih = intr_establish(irq, ipl, level | mpsafe,
261 1.2.2.2 pgoyette gicv3_fdt_intr, firq);
262 1.2.2.2 pgoyette }
263 1.2.2.2 pgoyette if (firq->intr_ih == NULL) {
264 1.2.2.2 pgoyette kmem_free(firq, sizeof(*firq));
265 1.2.2.2 pgoyette return NULL;
266 1.2.2.2 pgoyette }
267 1.2.2.2 pgoyette sc->sc_irq[irq] = firq;
268 1.2.2.2 pgoyette } else {
269 1.2.2.2 pgoyette if (firq->intr_arg == NULL && arg != NULL) {
270 1.2.2.2 pgoyette device_printf(dev, "cannot share irq with NULL arg\n");
271 1.2.2.2 pgoyette return NULL;
272 1.2.2.2 pgoyette }
273 1.2.2.2 pgoyette if (firq->intr_ipl != ipl) {
274 1.2.2.2 pgoyette device_printf(dev, "cannot share irq with different "
275 1.2.2.2 pgoyette "ipl\n");
276 1.2.2.2 pgoyette return NULL;
277 1.2.2.2 pgoyette }
278 1.2.2.2 pgoyette if (firq->intr_level != level) {
279 1.2.2.2 pgoyette device_printf(dev, "cannot share edge and level "
280 1.2.2.2 pgoyette "interrupts\n");
281 1.2.2.2 pgoyette return NULL;
282 1.2.2.2 pgoyette }
283 1.2.2.2 pgoyette if (firq->intr_mpsafe != mpsafe) {
284 1.2.2.2 pgoyette device_printf(dev, "cannot share between "
285 1.2.2.2 pgoyette "mpsafe/non-mpsafe\n");
286 1.2.2.2 pgoyette return NULL;
287 1.2.2.2 pgoyette }
288 1.2.2.2 pgoyette }
289 1.2.2.2 pgoyette
290 1.2.2.2 pgoyette firq->intr_refcnt++;
291 1.2.2.2 pgoyette
292 1.2.2.2 pgoyette firqh = kmem_alloc(sizeof(*firqh), KM_SLEEP);
293 1.2.2.2 pgoyette firqh->ih_mpsafe = (flags & FDT_INTR_MPSAFE) != 0;
294 1.2.2.2 pgoyette firqh->ih_irq = firq;
295 1.2.2.2 pgoyette firqh->ih_fn = func;
296 1.2.2.2 pgoyette firqh->ih_arg = arg;
297 1.2.2.2 pgoyette TAILQ_INSERT_TAIL(&firq->intr_handlers, firqh, ih_next);
298 1.2.2.2 pgoyette
299 1.2.2.2 pgoyette return firq->intr_ih;
300 1.2.2.2 pgoyette }
301 1.2.2.2 pgoyette
302 1.2.2.2 pgoyette static void
303 1.2.2.2 pgoyette gicv3_fdt_disestablish(device_t dev, void *ih)
304 1.2.2.2 pgoyette {
305 1.2.2.2 pgoyette struct gicv3_fdt_softc * const sc = device_private(dev);
306 1.2.2.2 pgoyette struct gicv3_fdt_irqhandler *firqh;
307 1.2.2.2 pgoyette struct gicv3_fdt_irq *firq;
308 1.2.2.2 pgoyette u_int n;
309 1.2.2.2 pgoyette
310 1.2.2.2 pgoyette for (n = 0; n < GICV3_MAXIRQ; n++) {
311 1.2.2.2 pgoyette firq = sc->sc_irq[n];
312 1.2.2.2 pgoyette if (firq->intr_ih != ih)
313 1.2.2.2 pgoyette continue;
314 1.2.2.2 pgoyette
315 1.2.2.2 pgoyette KASSERT(firq->intr_refcnt > 0);
316 1.2.2.2 pgoyette
317 1.2.2.2 pgoyette if (firq->intr_refcnt > 1)
318 1.2.2.2 pgoyette panic("%s: cannot disestablish shared irq", __func__);
319 1.2.2.2 pgoyette
320 1.2.2.2 pgoyette firqh = TAILQ_FIRST(&firq->intr_handlers);
321 1.2.2.2 pgoyette kmem_free(firqh, sizeof(*firqh));
322 1.2.2.2 pgoyette intr_disestablish(firq->intr_ih);
323 1.2.2.2 pgoyette kmem_free(firq, sizeof(*firq));
324 1.2.2.2 pgoyette sc->sc_irq[n] = NULL;
325 1.2.2.2 pgoyette return;
326 1.2.2.2 pgoyette }
327 1.2.2.2 pgoyette
328 1.2.2.2 pgoyette panic("%s: interrupt not established", __func__);
329 1.2.2.2 pgoyette }
330 1.2.2.2 pgoyette
331 1.2.2.2 pgoyette static int
332 1.2.2.2 pgoyette gicv3_fdt_intr(void *priv)
333 1.2.2.2 pgoyette {
334 1.2.2.2 pgoyette struct gicv3_fdt_irq *firq = priv;
335 1.2.2.2 pgoyette struct gicv3_fdt_irqhandler *firqh;
336 1.2.2.2 pgoyette int handled = 0;
337 1.2.2.2 pgoyette
338 1.2.2.2 pgoyette TAILQ_FOREACH(firqh, &firq->intr_handlers, ih_next)
339 1.2.2.2 pgoyette handled += firqh->ih_fn(firqh->ih_arg);
340 1.2.2.2 pgoyette
341 1.2.2.2 pgoyette return handled;
342 1.2.2.2 pgoyette }
343 1.2.2.2 pgoyette
344 1.2.2.2 pgoyette static bool
345 1.2.2.2 pgoyette gicv3_fdt_intrstr(device_t dev, u_int *specifier, char *buf, size_t buflen)
346 1.2.2.2 pgoyette {
347 1.2.2.2 pgoyette /* 1st cell is the interrupt type; 0 is SPI, 1 is PPI */
348 1.2.2.2 pgoyette /* 2nd cell is the interrupt number */
349 1.2.2.2 pgoyette /* 3rd cell is flags */
350 1.2.2.2 pgoyette /* 4th cell is affinity */
351 1.2.2.2 pgoyette
352 1.2.2.2 pgoyette if (!specifier)
353 1.2.2.2 pgoyette return false;
354 1.2.2.2 pgoyette const u_int type = be32toh(specifier[0]);
355 1.2.2.2 pgoyette const u_int intr = be32toh(specifier[1]);
356 1.2.2.2 pgoyette const u_int irq = type == 0 ? IRQ_SPI(intr) : IRQ_PPI(intr);
357 1.2.2.2 pgoyette
358 1.2.2.2 pgoyette snprintf(buf, buflen, "GICv3 irq %d", irq);
359 1.2.2.2 pgoyette
360 1.2.2.2 pgoyette return true;
361 1.2.2.2 pgoyette }
362