rmixl_intr.c revision 1.8 1 1.8 jym /* $NetBSD: rmixl_intr.c,v 1.8 2011/09/27 01:02:34 jym Exp $ */
2 1.2 matt
3 1.2 matt /*-
4 1.2 matt * Copyright (c) 2007 Ruslan Ermilov and Vsevolod Lobko.
5 1.2 matt * All rights reserved.
6 1.2 matt *
7 1.2 matt * Redistribution and use in source and binary forms, with or
8 1.2 matt * without modification, are permitted provided that the following
9 1.2 matt * conditions are met:
10 1.2 matt * 1. Redistributions of source code must retain the above copyright
11 1.2 matt * notice, this list of conditions and the following disclaimer.
12 1.2 matt * 2. Redistributions in binary form must reproduce the above
13 1.2 matt * copyright notice, this list of conditions and the following
14 1.2 matt * disclaimer in the documentation and/or other materials provided
15 1.2 matt * with the distribution.
16 1.2 matt * 3. The names of the authors may not be used to endorse or promote
17 1.2 matt * products derived from this software without specific prior
18 1.2 matt * written permission.
19 1.2 matt *
20 1.2 matt * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY
21 1.2 matt * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22 1.2 matt * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
23 1.2 matt * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS
24 1.2 matt * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
25 1.2 matt * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26 1.2 matt * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
27 1.2 matt * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 1.2 matt * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
29 1.2 matt * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
30 1.2 matt * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
31 1.2 matt * OF SUCH DAMAGE.
32 1.2 matt */
33 1.2 matt /*-
34 1.2 matt * Copyright (c) 2001 The NetBSD Foundation, Inc.
35 1.2 matt * All rights reserved.
36 1.2 matt *
37 1.2 matt * This code is derived from software contributed to The NetBSD Foundation
38 1.2 matt * by Jason R. Thorpe.
39 1.2 matt *
40 1.2 matt * Redistribution and use in source and binary forms, with or without
41 1.2 matt * modification, are permitted provided that the following conditions
42 1.2 matt * are met:
43 1.2 matt * 1. Redistributions of source code must retain the above copyright
44 1.2 matt * notice, this list of conditions and the following disclaimer.
45 1.2 matt * 2. Redistributions in binary form must reproduce the above copyright
46 1.2 matt * notice, this list of conditions and the following disclaimer in the
47 1.2 matt * documentation and/or other materials provided with the distribution.
48 1.2 matt *
49 1.2 matt * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
50 1.2 matt * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
51 1.2 matt * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
52 1.2 matt * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
53 1.2 matt * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
54 1.2 matt * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
55 1.2 matt * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
56 1.2 matt * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
57 1.2 matt * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
58 1.2 matt * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
59 1.2 matt * POSSIBILITY OF SUCH DAMAGE.
60 1.2 matt */
61 1.2 matt
62 1.2 matt /*
63 1.2 matt * Platform-specific interrupt support for the RMI XLP, XLR, XLS
64 1.2 matt */
65 1.2 matt
66 1.2 matt #include <sys/cdefs.h>
67 1.8 jym __KERNEL_RCSID(0, "$NetBSD: rmixl_intr.c,v 1.8 2011/09/27 01:02:34 jym Exp $");
68 1.2 matt
69 1.2 matt #include "opt_ddb.h"
70 1.3 matt #include "opt_multiprocessor.h"
71 1.3 matt #define __INTR_PRIVATE
72 1.2 matt
73 1.2 matt #include <sys/param.h>
74 1.7 matt #include <sys/atomic.h>
75 1.7 matt #include <sys/bus.h>
76 1.7 matt #include <sys/cpu.h>
77 1.2 matt #include <sys/device.h>
78 1.7 matt #include <sys/intr.h>
79 1.2 matt #include <sys/kernel.h>
80 1.7 matt #include <sys/malloc.h>
81 1.3 matt #include <sys/mutex.h>
82 1.7 matt #include <sys/systm.h>
83 1.2 matt
84 1.3 matt #include <mips/cpuset.h>
85 1.2 matt #include <mips/locore.h>
86 1.2 matt
87 1.2 matt #include <mips/rmi/rmixlreg.h>
88 1.2 matt #include <mips/rmi/rmixlvar.h>
89 1.2 matt
90 1.3 matt #include <mips/rmi/rmixl_cpuvar.h>
91 1.3 matt #include <mips/rmi/rmixl_intr.h>
92 1.3 matt
93 1.2 matt #include <dev/pci/pcireg.h>
94 1.2 matt #include <dev/pci/pcivar.h>
95 1.2 matt
96 1.3 matt //#define IOINTR_DEBUG 1
97 1.2 matt #ifdef IOINTR_DEBUG
98 1.2 matt int iointr_debug = IOINTR_DEBUG;
99 1.2 matt # define DPRINTF(x) do { if (iointr_debug) printf x ; } while(0)
100 1.2 matt #else
101 1.2 matt # define DPRINTF(x)
102 1.2 matt #endif
103 1.2 matt
104 1.2 matt #define RMIXL_PICREG_READ(off) \
105 1.2 matt RMIXL_IOREG_READ(RMIXL_IO_DEV_PIC + (off))
106 1.2 matt #define RMIXL_PICREG_WRITE(off, val) \
107 1.2 matt RMIXL_IOREG_WRITE(RMIXL_IO_DEV_PIC + (off), (val))
108 1.2 matt
109 1.2 matt /*
110 1.3 matt * do not clear these when acking EIRR
111 1.3 matt * (otherwise they get lost)
112 1.2 matt */
113 1.3 matt #define RMIXL_EIRR_PRESERVE_MASK \
114 1.3 matt ((MIPS_INT_MASK_5|MIPS_SOFT_INT_MASK) >> 8)
115 1.2 matt
116 1.2 matt /*
117 1.3 matt * IRT assignments depends on the RMI chip family
118 1.3 matt * (XLS1xx vs. XLS2xx vs. XLS3xx vs. XLS6xx)
119 1.3 matt * use the right display string table for the CPU that's running.
120 1.3 matt */
121 1.2 matt
122 1.2 matt /*
123 1.3 matt * rmixl_irtnames_xlrxxx
124 1.3 matt * - use for XLRxxx
125 1.2 matt */
126 1.3 matt static const char * const rmixl_irtnames_xlrxxx[NIRTS] = {
127 1.3 matt "pic int 0 (watchdog)", /* 0 */
128 1.3 matt "pic int 1 (timer0)", /* 1 */
129 1.3 matt "pic int 2 (timer1)", /* 2 */
130 1.3 matt "pic int 3 (timer2)", /* 3 */
131 1.3 matt "pic int 4 (timer3)", /* 4 */
132 1.3 matt "pic int 5 (timer4)", /* 5 */
133 1.3 matt "pic int 6 (timer5)", /* 6 */
134 1.3 matt "pic int 7 (timer6)", /* 7 */
135 1.3 matt "pic int 8 (timer7)", /* 8 */
136 1.3 matt "pic int 9 (uart0)", /* 9 */
137 1.3 matt "pic int 10 (uart1)", /* 10 */
138 1.3 matt "pic int 11 (i2c0)", /* 11 */
139 1.3 matt "pic int 12 (i2c1)", /* 12 */
140 1.3 matt "pic int 13 (pcmcia)", /* 13 */
141 1.3 matt "pic int 14 (gpio)", /* 14 */
142 1.3 matt "pic int 15 (hyper)", /* 15 */
143 1.3 matt "pic int 16 (pcix)", /* 16 */
144 1.3 matt "pic int 17 (gmac0)", /* 17 */
145 1.3 matt "pic int 18 (gmac1)", /* 18 */
146 1.3 matt "pic int 19 (gmac2)", /* 19 */
147 1.3 matt "pic int 20 (gmac3)", /* 20 */
148 1.3 matt "pic int 21 (xgs0)", /* 21 */
149 1.3 matt "pic int 22 (xgs1)", /* 22 */
150 1.3 matt "pic int 23 (irq23)", /* 23 */
151 1.3 matt "pic int 24 (hyper_fatal)", /* 24 */
152 1.3 matt "pic int 25 (bridge_aerr)", /* 25 */
153 1.3 matt "pic int 26 (bridge_berr)", /* 26 */
154 1.3 matt "pic int 27 (bridge_tb)", /* 27 */
155 1.3 matt "pic int 28 (bridge_nmi)", /* 28 */
156 1.3 matt "pic int 29 (bridge_sram_derr)",/* 29 */
157 1.3 matt "pic int 30 (gpio_fatal)", /* 30 */
158 1.3 matt "pic int 31 (reserved)", /* 31 */
159 1.2 matt };
160 1.2 matt
161 1.2 matt /*
162 1.3 matt * rmixl_irtnames_xls2xx
163 1.3 matt * - use for XLS2xx
164 1.2 matt */
165 1.3 matt static const char * const rmixl_irtnames_xls2xx[NIRTS] = {
166 1.3 matt "pic int 0 (watchdog)", /* 0 */
167 1.3 matt "pic int 1 (timer0)", /* 1 */
168 1.3 matt "pic int 2 (timer1)", /* 2 */
169 1.3 matt "pic int 3 (timer2)", /* 3 */
170 1.3 matt "pic int 4 (timer3)", /* 4 */
171 1.3 matt "pic int 5 (timer4)", /* 5 */
172 1.3 matt "pic int 6 (timer5)", /* 6 */
173 1.3 matt "pic int 7 (timer6)", /* 7 */
174 1.3 matt "pic int 8 (timer7)", /* 8 */
175 1.3 matt "pic int 9 (uart0)", /* 9 */
176 1.3 matt "pic int 10 (uart1)", /* 10 */
177 1.3 matt "pic int 11 (i2c0)", /* 11 */
178 1.3 matt "pic int 12 (i2c1)", /* 12 */
179 1.3 matt "pic int 13 (pcmcia)", /* 13 */
180 1.3 matt "pic int 14 (gpio_a)", /* 14 */
181 1.3 matt "pic int 15 (irq15)", /* 15 */
182 1.3 matt "pic int 16 (bridge_tb)", /* 16 */
183 1.3 matt "pic int 17 (gmac0)", /* 17 */
184 1.3 matt "pic int 18 (gmac1)", /* 18 */
185 1.3 matt "pic int 19 (gmac2)", /* 19 */
186 1.3 matt "pic int 20 (gmac3)", /* 20 */
187 1.3 matt "pic int 21 (irq21)", /* 21 */
188 1.3 matt "pic int 22 (irq22)", /* 22 */
189 1.3 matt "pic int 23 (pcie_link2)", /* 23 */
190 1.3 matt "pic int 24 (pcie_link3)", /* 24 */
191 1.3 matt "pic int 25 (bridge_err)", /* 25 */
192 1.3 matt "pic int 26 (pcie_link0)", /* 26 */
193 1.3 matt "pic int 27 (pcie_link1)", /* 27 */
194 1.3 matt "pic int 28 (irq28)", /* 28 */
195 1.3 matt "pic int 29 (pcie_err)", /* 29 */
196 1.3 matt "pic int 30 (gpio_b)", /* 30 */
197 1.3 matt "pic int 31 (usb)", /* 31 */
198 1.2 matt };
199 1.2 matt
200 1.2 matt /*
201 1.3 matt * rmixl_irtnames_xls1xx
202 1.3 matt * - use for XLS1xx, XLS4xx-Lite
203 1.2 matt */
204 1.3 matt static const char * const rmixl_irtnames_xls1xx[NIRTS] = {
205 1.3 matt "pic int 0 (watchdog)", /* 0 */
206 1.3 matt "pic int 1 (timer0)", /* 1 */
207 1.3 matt "pic int 2 (timer1)", /* 2 */
208 1.3 matt "pic int 3 (timer2)", /* 3 */
209 1.3 matt "pic int 4 (timer3)", /* 4 */
210 1.3 matt "pic int 5 (timer4)", /* 5 */
211 1.3 matt "pic int 6 (timer5)", /* 6 */
212 1.3 matt "pic int 7 (timer6)", /* 7 */
213 1.3 matt "pic int 8 (timer7)", /* 8 */
214 1.3 matt "pic int 9 (uart0)", /* 9 */
215 1.3 matt "pic int 10 (uart1)", /* 10 */
216 1.3 matt "pic int 11 (i2c0)", /* 11 */
217 1.3 matt "pic int 12 (i2c1)", /* 12 */
218 1.3 matt "pic int 13 (pcmcia)", /* 13 */
219 1.3 matt "pic int 14 (gpio_a)", /* 14 */
220 1.3 matt "pic int 15 (irq15)", /* 15 */
221 1.3 matt "pic int 16 (bridge_tb)", /* 16 */
222 1.3 matt "pic int 17 (gmac0)", /* 17 */
223 1.3 matt "pic int 18 (gmac1)", /* 18 */
224 1.3 matt "pic int 19 (gmac2)", /* 19 */
225 1.3 matt "pic int 20 (gmac3)", /* 20 */
226 1.3 matt "pic int 21 (irq21)", /* 21 */
227 1.3 matt "pic int 22 (irq22)", /* 22 */
228 1.3 matt "pic int 23 (irq23)", /* 23 */
229 1.3 matt "pic int 24 (irq24)", /* 24 */
230 1.3 matt "pic int 25 (bridge_err)", /* 25 */
231 1.3 matt "pic int 26 (pcie_link0)", /* 26 */
232 1.3 matt "pic int 27 (pcie_link1)", /* 27 */
233 1.3 matt "pic int 28 (irq28)", /* 28 */
234 1.3 matt "pic int 29 (pcie_err)", /* 29 */
235 1.3 matt "pic int 30 (gpio_b)", /* 30 */
236 1.3 matt "pic int 31 (usb)", /* 31 */
237 1.2 matt };
238 1.2 matt
239 1.2 matt /*
240 1.3 matt * rmixl_irtnames_xls4xx:
241 1.3 matt * - use for XLS4xx, XLS6xx
242 1.2 matt */
243 1.3 matt static const char * const rmixl_irtnames_xls4xx[NIRTS] = {
244 1.3 matt "pic int 0 (watchdog)", /* 0 */
245 1.3 matt "pic int 1 (timer0)", /* 1 */
246 1.3 matt "pic int 2 (timer1)", /* 2 */
247 1.3 matt "pic int 3 (timer2)", /* 3 */
248 1.3 matt "pic int 4 (timer3)", /* 4 */
249 1.3 matt "pic int 5 (timer4)", /* 5 */
250 1.3 matt "pic int 6 (timer5)", /* 6 */
251 1.3 matt "pic int 7 (timer6)", /* 7 */
252 1.3 matt "pic int 8 (timer7)", /* 8 */
253 1.3 matt "pic int 9 (uart0)", /* 9 */
254 1.3 matt "pic int 10 (uart1)", /* 10 */
255 1.3 matt "pic int 11 (i2c0)", /* 11 */
256 1.3 matt "pic int 12 (i2c1)", /* 12 */
257 1.3 matt "pic int 13 (pcmcia)", /* 13 */
258 1.3 matt "pic int 14 (gpio_a)", /* 14 */
259 1.3 matt "pic int 15 (irq15)", /* 15 */
260 1.3 matt "pic int 16 (bridge_tb)", /* 16 */
261 1.3 matt "pic int 17 (gmac0)", /* 17 */
262 1.3 matt "pic int 18 (gmac1)", /* 18 */
263 1.3 matt "pic int 19 (gmac2)", /* 19 */
264 1.3 matt "pic int 20 (gmac3)", /* 20 */
265 1.3 matt "pic int 21 (irq21)", /* 21 */
266 1.3 matt "pic int 22 (irq22)", /* 22 */
267 1.3 matt "pic int 23 (irq23)", /* 23 */
268 1.3 matt "pic int 24 (irq24)", /* 24 */
269 1.3 matt "pic int 25 (bridge_err)", /* 25 */
270 1.3 matt "pic int 26 (pcie_link0)", /* 26 */
271 1.3 matt "pic int 27 (pcie_link1)", /* 27 */
272 1.3 matt "pic int 28 (pcie_link2)", /* 28 */
273 1.3 matt "pic int 29 (pcie_link3)", /* 29 */
274 1.3 matt "pic int 30 (gpio_b)", /* 30 */
275 1.3 matt "pic int 31 (usb)", /* 31 */
276 1.3 matt };
277 1.2 matt
278 1.2 matt /*
279 1.3 matt * rmixl_vecnames_common:
280 1.3 matt * - use for unknown cpu implementation
281 1.3 matt * - covers all vectors, not just IRT intrs
282 1.2 matt */
283 1.3 matt static const char * const rmixl_vecnames_common[NINTRVECS] = {
284 1.3 matt "vec 0", /* 0 */
285 1.3 matt "vec 1", /* 1 */
286 1.3 matt "vec 2", /* 2 */
287 1.3 matt "vec 3", /* 3 */
288 1.3 matt "vec 4", /* 4 */
289 1.3 matt "vec 5", /* 5 */
290 1.3 matt "vec 6", /* 6 */
291 1.3 matt "vec 7", /* 7 */
292 1.4 cliff "vec 8 (ipi 0)", /* 8 */
293 1.4 cliff "vec 9 (ipi 1)", /* 9 */
294 1.4 cliff "vec 10 (ipi 2)", /* 10 */
295 1.4 cliff "vec 11 (ipi 3)", /* 11 */
296 1.4 cliff "vec 12 (ipi 4)", /* 12 */
297 1.4 cliff "vec 13 (ipi 5)", /* 13 */
298 1.4 cliff "vec 14 (ipi 6)", /* 14 */
299 1.4 cliff "vec 15 (fmn)", /* 15 */
300 1.4 cliff "vec 16", /* 16 */
301 1.3 matt "vec 17", /* 17 */
302 1.3 matt "vec 18", /* 18 */
303 1.3 matt "vec 19", /* 19 */
304 1.3 matt "vec 20", /* 20 */
305 1.3 matt "vec 21", /* 21 */
306 1.3 matt "vec 22", /* 22 */
307 1.3 matt "vec 23", /* 23 */
308 1.3 matt "vec 24", /* 24 */
309 1.3 matt "vec 25", /* 25 */
310 1.3 matt "vec 26", /* 26 */
311 1.3 matt "vec 27", /* 27 */
312 1.3 matt "vec 28", /* 28 */
313 1.3 matt "vec 29", /* 29 */
314 1.3 matt "vec 30", /* 30 */
315 1.3 matt "vec 31", /* 31 */
316 1.3 matt "vec 32", /* 32 */
317 1.3 matt "vec 33", /* 33 */
318 1.3 matt "vec 34", /* 34 */
319 1.3 matt "vec 35", /* 35 */
320 1.3 matt "vec 36", /* 36 */
321 1.3 matt "vec 37", /* 37 */
322 1.3 matt "vec 38", /* 38 */
323 1.3 matt "vec 39", /* 39 */
324 1.3 matt "vec 40", /* 40 */
325 1.3 matt "vec 41", /* 41 */
326 1.3 matt "vec 42", /* 42 */
327 1.3 matt "vec 43", /* 43 */
328 1.3 matt "vec 44", /* 44 */
329 1.3 matt "vec 45", /* 45 */
330 1.3 matt "vec 46", /* 46 */
331 1.3 matt "vec 47", /* 47 */
332 1.3 matt "vec 48", /* 48 */
333 1.3 matt "vec 49", /* 49 */
334 1.3 matt "vec 50", /* 50 */
335 1.3 matt "vec 51", /* 51 */
336 1.3 matt "vec 52", /* 52 */
337 1.3 matt "vec 53", /* 53 */
338 1.3 matt "vec 54", /* 54 */
339 1.3 matt "vec 55", /* 55 */
340 1.3 matt "vec 56", /* 56 */
341 1.3 matt "vec 57", /* 57 */
342 1.3 matt "vec 58", /* 58 */
343 1.3 matt "vec 59", /* 59 */
344 1.3 matt "vec 60", /* 60 */
345 1.3 matt "vec 61", /* 61 */
346 1.3 matt "vec 62", /* 63 */
347 1.3 matt "vec 63", /* 63 */
348 1.2 matt };
349 1.2 matt
350 1.2 matt /*
351 1.3 matt * mask of CPUs attached
352 1.3 matt * once they are attached, this var is read-only so mp safe
353 1.2 matt */
354 1.3 matt static uint32_t cpu_present_mask;
355 1.3 matt
356 1.3 matt kmutex_t rmixl_ipi_lock __cacheline_aligned;
357 1.3 matt /* covers RMIXL_PIC_IPIBASE */
358 1.3 matt kmutex_t rmixl_intr_lock __cacheline_aligned;
359 1.3 matt /* covers rest of PIC, and rmixl_intrhand[] */
360 1.3 matt rmixl_intrhand_t rmixl_intrhand[NINTRVECS];
361 1.2 matt
362 1.2 matt #ifdef DIAGNOSTIC
363 1.3 matt static int rmixl_pic_init_done;
364 1.2 matt #endif
365 1.2 matt
366 1.2 matt
367 1.3 matt static const char *rmixl_intr_string_xlr(int);
368 1.3 matt static const char *rmixl_intr_string_xls(int);
369 1.3 matt static uint32_t rmixl_irt_thread_mask(int);
370 1.3 matt static void rmixl_irt_init(int);
371 1.3 matt static void rmixl_irt_disestablish(int);
372 1.3 matt static void rmixl_irt_establish(int, int, int,
373 1.3 matt rmixl_intr_trigger_t, rmixl_intr_polarity_t);
374 1.3 matt
375 1.3 matt #ifdef MULTIPROCESSOR
376 1.3 matt static int rmixl_send_ipi(struct cpu_info *, int);
377 1.3 matt static int rmixl_ipi_intr(void *);
378 1.3 matt #endif
379 1.3 matt
380 1.3 matt #if defined(DIAGNOSTIC) || defined(IOINTR_DEBUG) || defined(DDB)
381 1.3 matt int rmixl_intrhand_print_subr(int);
382 1.3 matt int rmixl_intrhand_print(void);
383 1.3 matt int rmixl_irt_print(void);
384 1.3 matt void rmixl_ipl_eimr_map_print(void);
385 1.3 matt #endif
386 1.2 matt
387 1.2 matt
388 1.3 matt static inline u_int
389 1.3 matt dclz(uint64_t val)
390 1.2 matt {
391 1.3 matt int nlz;
392 1.2 matt
393 1.3 matt asm volatile("dclz %0, %1;"
394 1.3 matt : "=r"(nlz) : "r"(val));
395 1.3 matt
396 1.3 matt return nlz;
397 1.2 matt }
398 1.2 matt
399 1.2 matt void
400 1.2 matt evbmips_intr_init(void)
401 1.2 matt {
402 1.2 matt uint32_t r;
403 1.2 matt
404 1.3 matt KASSERT(cpu_rmixlr(mips_options.mips_cpu)
405 1.3 matt || cpu_rmixls(mips_options.mips_cpu));
406 1.3 matt
407 1.2 matt
408 1.2 matt #ifdef DIAGNOSTIC
409 1.3 matt if (rmixl_pic_init_done != 0)
410 1.3 matt panic("%s: rmixl_pic_init_done %d",
411 1.3 matt __func__, rmixl_pic_init_done);
412 1.2 matt #endif
413 1.2 matt
414 1.3 matt mutex_init(&rmixl_ipi_lock, MUTEX_DEFAULT, IPL_HIGH);
415 1.3 matt mutex_init(&rmixl_intr_lock, MUTEX_DEFAULT, IPL_HIGH);
416 1.3 matt
417 1.3 matt mutex_enter(&rmixl_intr_lock);
418 1.2 matt
419 1.3 matt /*
420 1.3 matt * initialize (zero) all IRT Entries in the PIC
421 1.3 matt */
422 1.3 matt for (u_int i = 0; i < NIRTS; i++) {
423 1.3 matt rmixl_irt_init(i);
424 1.2 matt }
425 1.2 matt
426 1.2 matt /*
427 1.2 matt * disable watchdog NMI, timers
428 1.2 matt *
429 1.2 matt * XXX
430 1.2 matt * WATCHDOG_ENB is preserved because clearing it causes
431 1.2 matt * hang on the XLS616 (but not on the XLS408)
432 1.2 matt */
433 1.2 matt r = RMIXL_PICREG_READ(RMIXL_PIC_CONTROL);
434 1.2 matt r &= RMIXL_PIC_CONTROL_RESV|RMIXL_PIC_CONTROL_WATCHDOG_ENB;
435 1.2 matt RMIXL_PICREG_WRITE(RMIXL_PIC_CONTROL, r);
436 1.2 matt
437 1.3 matt #ifdef DIAGNOSTIC
438 1.3 matt rmixl_pic_init_done = 1;
439 1.3 matt #endif
440 1.3 matt mutex_exit(&rmixl_intr_lock);
441 1.3 matt
442 1.3 matt }
443 1.3 matt
444 1.3 matt /*
445 1.3 matt * establish vector for mips3 count/compare clock interrupt
446 1.3 matt * this ensures we enable in EIRR,
447 1.3 matt * even though cpu_intr() handles the interrupt
448 1.3 matt * note the 'mpsafe' arg here is a placeholder only
449 1.3 matt */
450 1.3 matt void
451 1.3 matt rmixl_intr_init_clk(void)
452 1.3 matt {
453 1.3 matt const int vec = ffs(MIPS_INT_MASK_5 >> MIPS_INT_MASK_SHIFT) - 1;
454 1.3 matt
455 1.3 matt mutex_enter(&rmixl_intr_lock);
456 1.3 matt
457 1.3 matt void *ih = rmixl_vec_establish(vec, 0, IPL_SCHED, NULL, NULL, false);
458 1.3 matt if (ih == NULL)
459 1.3 matt panic("%s: establish vec %d failed", __func__, vec);
460 1.3 matt
461 1.3 matt mutex_exit(&rmixl_intr_lock);
462 1.3 matt }
463 1.3 matt
464 1.3 matt #ifdef MULTIPROCESSOR
465 1.3 matt /*
466 1.3 matt * establish IPI interrupt and send function
467 1.3 matt */
468 1.3 matt void
469 1.3 matt rmixl_intr_init_ipi(void)
470 1.3 matt {
471 1.3 matt mutex_enter(&rmixl_intr_lock);
472 1.3 matt
473 1.3 matt for (u_int ipi = 0; ipi < NIPIS; ipi++) {
474 1.3 matt const u_int vec = RMIXL_INTRVEC_IPI + ipi;
475 1.3 matt void * const ih = rmixl_vec_establish(vec, -1, IPL_SCHED,
476 1.3 matt rmixl_ipi_intr, (void *)(uintptr_t)ipi, true);
477 1.3 matt if (ih == NULL)
478 1.3 matt panic("%s: establish ipi %d at vec %d failed",
479 1.3 matt __func__, ipi, vec);
480 1.3 matt }
481 1.5 matt
482 1.3 matt mips_locoresw.lsw_send_ipi = rmixl_send_ipi;
483 1.5 matt
484 1.3 matt mutex_exit(&rmixl_intr_lock);
485 1.3 matt }
486 1.3 matt #endif /* MULTIPROCESSOR */
487 1.3 matt
488 1.3 matt /*
489 1.3 matt * initialize per-cpu interrupt stuff in softc
490 1.3 matt * accumulate per-cpu bits in 'cpu_present_mask'
491 1.3 matt */
492 1.3 matt void
493 1.3 matt rmixl_intr_init_cpu(struct cpu_info *ci)
494 1.3 matt {
495 1.3 matt struct rmixl_cpu_softc *sc = (void *)ci->ci_softc;
496 1.3 matt
497 1.3 matt KASSERT(sc != NULL);
498 1.2 matt
499 1.3 matt for (int vec=0; vec < NINTRVECS; vec++)
500 1.3 matt evcnt_attach_dynamic(&sc->sc_vec_evcnts[vec],
501 1.3 matt EVCNT_TYPE_INTR, NULL,
502 1.3 matt device_xname(sc->sc_dev),
503 1.3 matt rmixl_intr_string(vec));
504 1.2 matt
505 1.3 matt KASSERT(cpu_index(ci) < (sizeof(cpu_present_mask) * 8));
506 1.3 matt atomic_or_32((volatile uint32_t *)&cpu_present_mask, 1 << cpu_index(ci));
507 1.2 matt }
508 1.2 matt
509 1.3 matt /*
510 1.3 matt * rmixl_intr_string - return pointer to display name of a PIC-based interrupt
511 1.3 matt */
512 1.2 matt const char *
513 1.3 matt rmixl_intr_string(int vec)
514 1.3 matt {
515 1.3 matt int irt;
516 1.3 matt
517 1.3 matt if (vec < 0 || vec >= NINTRVECS)
518 1.3 matt panic("%s: vec index %d out of range, max %d",
519 1.3 matt __func__, vec, NINTRVECS - 1);
520 1.3 matt
521 1.3 matt if (! RMIXL_VECTOR_IS_IRT(vec))
522 1.3 matt return rmixl_vecnames_common[vec];
523 1.3 matt
524 1.3 matt irt = RMIXL_VECTOR_IRT(vec);
525 1.3 matt switch(cpu_rmixl_chip_type(mips_options.mips_cpu)) {
526 1.3 matt case CIDFL_RMI_TYPE_XLR:
527 1.3 matt return rmixl_intr_string_xlr(irt);
528 1.3 matt case CIDFL_RMI_TYPE_XLS:
529 1.3 matt return rmixl_intr_string_xls(irt);
530 1.3 matt case CIDFL_RMI_TYPE_XLP:
531 1.3 matt panic("%s: RMI XLP not yet supported", __func__);
532 1.3 matt }
533 1.3 matt
534 1.3 matt return "undefined"; /* appease gcc */
535 1.3 matt }
536 1.3 matt
537 1.3 matt static const char *
538 1.3 matt rmixl_intr_string_xlr(int irt)
539 1.3 matt {
540 1.3 matt return rmixl_irtnames_xlrxxx[irt];
541 1.3 matt }
542 1.3 matt
543 1.3 matt static const char *
544 1.3 matt rmixl_intr_string_xls(int irt)
545 1.2 matt {
546 1.2 matt const char *name;
547 1.2 matt
548 1.3 matt switch (MIPS_PRID_IMPL(mips_options.mips_cpu_id)) {
549 1.2 matt case MIPS_XLS104:
550 1.2 matt case MIPS_XLS108:
551 1.3 matt case MIPS_XLS404LITE:
552 1.3 matt case MIPS_XLS408LITE:
553 1.3 matt name = rmixl_irtnames_xls1xx[irt];
554 1.3 matt break;
555 1.2 matt case MIPS_XLS204:
556 1.2 matt case MIPS_XLS208:
557 1.3 matt name = rmixl_irtnames_xls2xx[irt];
558 1.3 matt break;
559 1.3 matt case MIPS_XLS404:
560 1.3 matt case MIPS_XLS408:
561 1.3 matt case MIPS_XLS416:
562 1.3 matt case MIPS_XLS608:
563 1.3 matt case MIPS_XLS616:
564 1.3 matt name = rmixl_irtnames_xls4xx[irt];
565 1.3 matt break;
566 1.3 matt default:
567 1.3 matt name = rmixl_vecnames_common[RMIXL_IRT_VECTOR(irt)];
568 1.3 matt break;
569 1.3 matt }
570 1.3 matt
571 1.3 matt return name;
572 1.3 matt }
573 1.3 matt
574 1.3 matt /*
575 1.3 matt * rmixl_irt_thread_mask
576 1.3 matt *
577 1.3 matt * given a bitmask of cpus, return a, IRT thread mask
578 1.3 matt */
579 1.3 matt static uint32_t
580 1.3 matt rmixl_irt_thread_mask(int cpumask)
581 1.3 matt {
582 1.3 matt uint32_t irtc0;
583 1.3 matt
584 1.3 matt #if defined(MULTIPROCESSOR)
585 1.3 matt #ifndef NOTYET
586 1.3 matt if (cpumask == -1)
587 1.3 matt return 1; /* XXX TMP FIXME */
588 1.3 matt #endif
589 1.3 matt
590 1.3 matt /*
591 1.3 matt * discount cpus not present
592 1.3 matt */
593 1.3 matt cpumask &= cpu_present_mask;
594 1.3 matt
595 1.3 matt switch (MIPS_PRID_IMPL(mips_options.mips_cpu_id)) {
596 1.3 matt case MIPS_XLS104:
597 1.3 matt case MIPS_XLS204:
598 1.3 matt case MIPS_XLS404:
599 1.2 matt case MIPS_XLS404LITE:
600 1.3 matt irtc0 = ((cpumask >> 2) << 4) | (cpumask & __BITS(1,0));
601 1.3 matt irtc0 &= (__BITS(5,4) | __BITS(1,0));
602 1.3 matt break;
603 1.3 matt case MIPS_XLS108:
604 1.3 matt case MIPS_XLS208:
605 1.3 matt case MIPS_XLS408:
606 1.2 matt case MIPS_XLS408LITE:
607 1.3 matt case MIPS_XLS608:
608 1.3 matt irtc0 = cpumask & __BITS(7,0);
609 1.2 matt break;
610 1.3 matt case MIPS_XLS416:
611 1.3 matt case MIPS_XLS616:
612 1.3 matt irtc0 = cpumask & __BITS(15,0);
613 1.2 matt break;
614 1.2 matt default:
615 1.3 matt panic("%s: unknown cpu ID %#x\n", __func__,
616 1.3 matt mips_options.mips_cpu_id);
617 1.2 matt }
618 1.3 matt #else
619 1.3 matt irtc0 = 1;
620 1.3 matt #endif /* MULTIPROCESSOR */
621 1.2 matt
622 1.3 matt return irtc0;
623 1.2 matt }
624 1.2 matt
625 1.2 matt /*
626 1.3 matt * rmixl_irt_init
627 1.3 matt * - initialize IRT Entry for given index
628 1.2 matt * - unmask Thread#0 in low word (assume we only have 1 thread)
629 1.2 matt */
630 1.2 matt static void
631 1.3 matt rmixl_irt_init(int irt)
632 1.2 matt {
633 1.3 matt KASSERT(irt < NIRTS);
634 1.3 matt RMIXL_PICREG_WRITE(RMIXL_PIC_IRTENTRYC1(irt), 0); /* high word */
635 1.3 matt RMIXL_PICREG_WRITE(RMIXL_PIC_IRTENTRYC0(irt), 0); /* low word */
636 1.2 matt }
637 1.2 matt
638 1.2 matt /*
639 1.3 matt * rmixl_irt_disestablish
640 1.3 matt * - invalidate IRT Entry for given index
641 1.2 matt */
642 1.2 matt static void
643 1.3 matt rmixl_irt_disestablish(int irt)
644 1.2 matt {
645 1.3 matt KASSERT(mutex_owned(&rmixl_intr_lock));
646 1.3 matt DPRINTF(("%s: irt %d, irtc1 %#x\n", __func__, irt, 0));
647 1.3 matt rmixl_irt_init(irt);
648 1.2 matt }
649 1.2 matt
650 1.2 matt /*
651 1.3 matt * rmixl_irt_establish
652 1.3 matt * - construct an IRT Entry for irt and write to PIC
653 1.2 matt */
654 1.2 matt static void
655 1.3 matt rmixl_irt_establish(int irt, int vec, int cpumask, rmixl_intr_trigger_t trigger,
656 1.3 matt rmixl_intr_polarity_t polarity)
657 1.2 matt {
658 1.2 matt uint32_t irtc1;
659 1.3 matt uint32_t irtc0;
660 1.3 matt
661 1.3 matt KASSERT(mutex_owned(&rmixl_intr_lock));
662 1.3 matt
663 1.3 matt if (irt >= NIRTS)
664 1.3 matt panic("%s: bad irt %d\n", __func__, irt);
665 1.3 matt
666 1.3 matt if (! RMIXL_VECTOR_IS_IRT(vec))
667 1.3 matt panic("%s: bad vec %d\n", __func__, vec);
668 1.3 matt
669 1.3 matt switch (trigger) {
670 1.3 matt case RMIXL_TRIG_EDGE:
671 1.3 matt case RMIXL_TRIG_LEVEL:
672 1.3 matt break;
673 1.3 matt default:
674 1.3 matt panic("%s: bad trigger %d\n", __func__, trigger);
675 1.3 matt }
676 1.3 matt
677 1.3 matt switch (polarity) {
678 1.3 matt case RMIXL_POLR_RISING:
679 1.3 matt case RMIXL_POLR_HIGH:
680 1.3 matt case RMIXL_POLR_FALLING:
681 1.3 matt case RMIXL_POLR_LOW:
682 1.3 matt break;
683 1.3 matt default:
684 1.3 matt panic("%s: bad polarity %d\n", __func__, polarity);
685 1.3 matt }
686 1.3 matt
687 1.3 matt /*
688 1.3 matt * XXX IRT entries are not shared
689 1.3 matt */
690 1.3 matt KASSERT(RMIXL_PICREG_READ(RMIXL_PIC_IRTENTRYC0(irt)) == 0);
691 1.3 matt KASSERT(RMIXL_PICREG_READ(RMIXL_PIC_IRTENTRYC1(irt)) == 0);
692 1.3 matt
693 1.3 matt irtc0 = rmixl_irt_thread_mask(cpumask);
694 1.2 matt
695 1.2 matt irtc1 = RMIXL_PIC_IRTENTRYC1_VALID;
696 1.2 matt irtc1 |= RMIXL_PIC_IRTENTRYC1_GL; /* local */
697 1.3 matt KASSERT((irtc1 & RMIXL_PIC_IRTENTRYC1_NMI) == 0);
698 1.2 matt
699 1.3 matt if (trigger == RMIXL_TRIG_LEVEL)
700 1.2 matt irtc1 |= RMIXL_PIC_IRTENTRYC1_TRG;
701 1.3 matt KASSERT((irtc1 & RMIXL_PIC_IRTENTRYC1_NMI) == 0);
702 1.2 matt
703 1.3 matt if ((polarity == RMIXL_POLR_FALLING) || (polarity == RMIXL_POLR_LOW))
704 1.2 matt irtc1 |= RMIXL_PIC_IRTENTRYC1_P;
705 1.3 matt KASSERT((irtc1 & RMIXL_PIC_IRTENTRYC1_NMI) == 0);
706 1.2 matt
707 1.3 matt irtc1 |= vec; /* vector in EIRR */
708 1.3 matt KASSERT((irtc1 & RMIXL_PIC_IRTENTRYC1_NMI) == 0);
709 1.2 matt
710 1.2 matt /*
711 1.3 matt * write IRT Entry to PIC
712 1.2 matt */
713 1.3 matt DPRINTF(("%s: vec %d (%#x), irt %d, irtc0 %#x, irtc1 %#x\n",
714 1.3 matt __func__, vec, vec, irt, irtc0, irtc1));
715 1.3 matt RMIXL_PICREG_WRITE(RMIXL_PIC_IRTENTRYC0(irt), irtc0); /* low word */
716 1.3 matt RMIXL_PICREG_WRITE(RMIXL_PIC_IRTENTRYC1(irt), irtc1); /* high word */
717 1.2 matt }
718 1.2 matt
719 1.2 matt void *
720 1.3 matt rmixl_vec_establish(int vec, int cpumask, int ipl,
721 1.3 matt int (*func)(void *), void *arg, bool mpsafe)
722 1.2 matt {
723 1.3 matt rmixl_intrhand_t *ih;
724 1.3 matt uint64_t eimr_bit;
725 1.2 matt int s;
726 1.2 matt
727 1.3 matt KASSERT(mutex_owned(&rmixl_intr_lock));
728 1.3 matt
729 1.5 matt DPRINTF(("%s: vec %d cpumask %#x ipl %d func %p arg %p mpsafe %d\n",
730 1.3 matt __func__, vec, cpumask, ipl, func, arg, mpsafe));
731 1.2 matt #ifdef DIAGNOSTIC
732 1.3 matt if (rmixl_pic_init_done == 0)
733 1.2 matt panic("%s: called before evbmips_intr_init", __func__);
734 1.2 matt #endif
735 1.2 matt
736 1.2 matt /*
737 1.3 matt * check args
738 1.2 matt */
739 1.3 matt if (vec < 0 || vec >= NINTRVECS)
740 1.3 matt panic("%s: vec %d out of range, max %d",
741 1.3 matt __func__, vec, NINTRVECS - 1);
742 1.2 matt if (ipl <= 0 || ipl >= _IPL_N)
743 1.2 matt panic("%s: ipl %d out of range, min %d, max %d",
744 1.2 matt __func__, ipl, 1, _IPL_N - 1);
745 1.2 matt
746 1.3 matt s = splhigh();
747 1.3 matt
748 1.3 matt ih = &rmixl_intrhand[vec];
749 1.3 matt if (ih->ih_func != NULL) {
750 1.3 matt #ifdef DIAGNOSTIC
751 1.3 matt printf("%s: intrhand[%d] busy\n", __func__, vec);
752 1.3 matt #endif
753 1.3 matt splx(s);
754 1.3 matt return NULL;
755 1.2 matt }
756 1.2 matt
757 1.3 matt ih->ih_arg = arg;
758 1.3 matt ih->ih_mpsafe = mpsafe;
759 1.3 matt ih->ih_vec = vec;
760 1.3 matt ih->ih_ipl = ipl;
761 1.3 matt ih->ih_cpumask = cpumask;
762 1.3 matt
763 1.3 matt eimr_bit = (uint64_t)1 << vec;
764 1.3 matt for (int i=ih->ih_ipl; --i >= 0; ) {
765 1.3 matt KASSERT((ipl_eimr_map[i] & eimr_bit) == 0);
766 1.3 matt ipl_eimr_map[i] |= eimr_bit;
767 1.2 matt }
768 1.2 matt
769 1.3 matt ih->ih_func = func; /* do this last */
770 1.3 matt
771 1.3 matt splx(s);
772 1.3 matt
773 1.3 matt return ih;
774 1.3 matt }
775 1.2 matt
776 1.3 matt /*
777 1.3 matt * rmixl_intr_establish
778 1.3 matt * - used to establish an IRT-based interrupt only
779 1.3 matt */
780 1.3 matt void *
781 1.3 matt rmixl_intr_establish(int irt, int cpumask, int ipl,
782 1.3 matt rmixl_intr_trigger_t trigger, rmixl_intr_polarity_t polarity,
783 1.3 matt int (*func)(void *), void *arg, bool mpsafe)
784 1.3 matt {
785 1.3 matt rmixl_intrhand_t *ih;
786 1.3 matt int vec;
787 1.2 matt
788 1.2 matt #ifdef DIAGNOSTIC
789 1.3 matt if (rmixl_pic_init_done == 0)
790 1.3 matt panic("%s: called before rmixl_pic_init_done", __func__);
791 1.2 matt #endif
792 1.2 matt
793 1.2 matt /*
794 1.3 matt * check args
795 1.2 matt */
796 1.3 matt if (irt < 0 || irt >= NIRTS)
797 1.3 matt panic("%s: irt %d out of range, max %d",
798 1.3 matt __func__, irt, NIRTS - 1);
799 1.3 matt if (ipl <= 0 || ipl >= _IPL_N)
800 1.3 matt panic("%s: ipl %d out of range, min %d, max %d",
801 1.3 matt __func__, ipl, 1, _IPL_N - 1);
802 1.3 matt
803 1.3 matt vec = RMIXL_IRT_VECTOR(irt);
804 1.2 matt
805 1.3 matt DPRINTF(("%s: irt %d, vec %d, ipl %d\n", __func__, irt, vec, ipl));
806 1.2 matt
807 1.3 matt mutex_enter(&rmixl_intr_lock);
808 1.2 matt
809 1.2 matt /*
810 1.3 matt * establish vector
811 1.2 matt */
812 1.3 matt ih = rmixl_vec_establish(vec, cpumask, ipl, func, arg, mpsafe);
813 1.2 matt
814 1.2 matt /*
815 1.2 matt * establish IRT Entry
816 1.2 matt */
817 1.3 matt rmixl_irt_establish(irt, vec, cpumask, trigger, polarity);
818 1.2 matt
819 1.3 matt mutex_exit(&rmixl_intr_lock);
820 1.2 matt
821 1.2 matt return ih;
822 1.2 matt }
823 1.2 matt
824 1.2 matt void
825 1.3 matt rmixl_vec_disestablish(void *cookie)
826 1.3 matt {
827 1.3 matt rmixl_intrhand_t *ih = cookie;
828 1.3 matt uint64_t eimr_bit;
829 1.3 matt
830 1.3 matt KASSERT(mutex_owned(&rmixl_intr_lock));
831 1.3 matt KASSERT(ih->ih_vec < NINTRVECS);
832 1.3 matt KASSERT(ih == &rmixl_intrhand[ih->ih_vec]);
833 1.3 matt
834 1.3 matt ih->ih_func = NULL; /* do this first */
835 1.3 matt
836 1.3 matt eimr_bit = (uint64_t)1 << ih->ih_vec;
837 1.3 matt for (int i=ih->ih_ipl; --i >= 0; ) {
838 1.3 matt KASSERT((ipl_eimr_map[i] & eimr_bit) != 0);
839 1.3 matt ipl_eimr_map[i] ^= eimr_bit;
840 1.3 matt }
841 1.3 matt }
842 1.3 matt
843 1.3 matt void
844 1.2 matt rmixl_intr_disestablish(void *cookie)
845 1.2 matt {
846 1.3 matt rmixl_intrhand_t *ih = cookie;
847 1.5 matt const int vec = ih->ih_vec;
848 1.3 matt
849 1.3 matt KASSERT(vec < NINTRVECS);
850 1.3 matt KASSERT(ih == &rmixl_intrhand[vec]);
851 1.2 matt
852 1.3 matt mutex_enter(&rmixl_intr_lock);
853 1.2 matt
854 1.2 matt /*
855 1.3 matt * disable/invalidate the IRT Entry if needed
856 1.2 matt */
857 1.3 matt if (RMIXL_VECTOR_IS_IRT(vec))
858 1.3 matt rmixl_irt_disestablish(vec);
859 1.2 matt
860 1.2 matt /*
861 1.3 matt * disasociate from vector and free the handle
862 1.2 matt */
863 1.3 matt rmixl_vec_disestablish(cookie);
864 1.3 matt
865 1.3 matt mutex_exit(&rmixl_intr_lock);
866 1.3 matt }
867 1.3 matt
868 1.3 matt void
869 1.3 matt evbmips_iointr(int ipl, vaddr_t pc, uint32_t pending)
870 1.3 matt {
871 1.3 matt struct rmixl_cpu_softc *sc = (void *)curcpu()->ci_softc;
872 1.2 matt
873 1.5 matt DPRINTF(("%s: cpu%u: ipl %d, pc %#"PRIxVADDR", pending %#x\n",
874 1.3 matt __func__, cpu_number(), ipl, pc, pending));
875 1.3 matt
876 1.3 matt /*
877 1.3 matt * 'pending' arg is a summary that there is something to do
878 1.3 matt * the real pending status is obtained from EIRR
879 1.2 matt */
880 1.3 matt KASSERT(pending == MIPS_INT_MASK_1);
881 1.2 matt
882 1.3 matt for (;;) {
883 1.3 matt rmixl_intrhand_t *ih;
884 1.3 matt uint64_t eirr;
885 1.3 matt uint64_t eimr;
886 1.3 matt uint64_t vecbit;
887 1.3 matt int vec;
888 1.3 matt
889 1.3 matt asm volatile("dmfc0 %0, $9, 6;" : "=r"(eirr));
890 1.3 matt asm volatile("dmfc0 %0, $9, 7;" : "=r"(eimr));
891 1.3 matt
892 1.3 matt #ifdef IOINTR_DEBUG
893 1.5 matt printf("%s: cpu%u: eirr %#"PRIx64", eimr %#"PRIx64", mask %#"PRIx64"\n",
894 1.3 matt __func__, cpu_number(), eirr, eimr, ipl_eimr_map[ipl-1]);
895 1.3 matt #endif /* IOINTR_DEBUG */
896 1.3 matt
897 1.3 matt /*
898 1.3 matt * reduce eirr to
899 1.3 matt * - ints that are enabled at or below this ipl
900 1.3 matt * - exclude count/compare clock and soft ints
901 1.3 matt * they are handled elsewhere
902 1.3 matt */
903 1.3 matt eirr &= ipl_eimr_map[ipl-1];
904 1.3 matt eirr &= ~ipl_eimr_map[ipl];
905 1.3 matt eirr &= ~((MIPS_INT_MASK_5 | MIPS_SOFT_INT_MASK) >> 8);
906 1.3 matt if (eirr == 0)
907 1.3 matt break;
908 1.3 matt
909 1.3 matt vec = 63 - dclz(eirr);
910 1.3 matt ih = &rmixl_intrhand[vec];
911 1.3 matt vecbit = 1ULL << vec;
912 1.3 matt KASSERT (ih->ih_ipl == ipl);
913 1.3 matt KASSERT ((vecbit & eimr) == 0);
914 1.3 matt KASSERT ((vecbit & RMIXL_EIRR_PRESERVE_MASK) == 0);
915 1.3 matt
916 1.3 matt /*
917 1.4 cliff * ack in EIRR, and in PIC if needed,
918 1.4 cliff * the irq we are about to handle
919 1.3 matt */
920 1.4 cliff rmixl_eirr_ack(eimr, vecbit, RMIXL_EIRR_PRESERVE_MASK);
921 1.3 matt if (RMIXL_VECTOR_IS_IRT(vec))
922 1.3 matt RMIXL_PICREG_WRITE(RMIXL_PIC_INTRACK,
923 1.3 matt 1 << RMIXL_VECTOR_IRT(vec));
924 1.2 matt
925 1.3 matt if (ih->ih_func != NULL) {
926 1.3 matt #ifdef MULTIPROCESSOR
927 1.3 matt if (ih->ih_mpsafe) {
928 1.3 matt (void)(*ih->ih_func)(ih->ih_arg);
929 1.3 matt } else {
930 1.3 matt KASSERTMSG(ipl == IPL_VM,
931 1.8 jym "%s: %s: ipl (%d) != IPL_VM for KERNEL_LOCK",
932 1.3 matt __func__, sc->sc_vec_evcnts[vec].ev_name,
933 1.8 jym ipl);
934 1.3 matt KERNEL_LOCK(1, NULL);
935 1.3 matt (void)(*ih->ih_func)(ih->ih_arg);
936 1.3 matt KERNEL_UNLOCK_ONE(NULL);
937 1.3 matt }
938 1.3 matt #else
939 1.3 matt (void)(*ih->ih_func)(ih->ih_arg);
940 1.3 matt #endif /* MULTIPROCESSOR */
941 1.3 matt }
942 1.3 matt KASSERT(ipl == ih->ih_ipl);
943 1.3 matt KASSERTMSG(curcpu()->ci_cpl >= ipl,
944 1.8 jym "%s: after %s: cpl (%d) < ipl %d",
945 1.3 matt __func__, sc->sc_vec_evcnts[vec].ev_name,
946 1.8 jym ipl, curcpu()->ci_cpl);
947 1.3 matt sc->sc_vec_evcnts[vec].ev_count++;
948 1.3 matt }
949 1.2 matt }
950 1.2 matt
951 1.3 matt #ifdef MULTIPROCESSOR
952 1.3 matt static int
953 1.3 matt rmixl_send_ipi(struct cpu_info *ci, int tag)
954 1.2 matt {
955 1.3 matt const cpuid_t cpuid = ci->ci_cpuid;
956 1.3 matt uint32_t core = (uint32_t)(cpuid >> 2);
957 1.3 matt uint32_t thread = (uint32_t)(cpuid & __BITS(1,0));
958 1.3 matt uint64_t req = 1 << tag;
959 1.2 matt uint32_t r;
960 1.3 matt
961 1.3 matt if (! CPUSET_HAS_P(cpus_running, cpu_index(ci)))
962 1.3 matt return -1;
963 1.3 matt
964 1.3 matt KASSERT((tag >= 0) && (tag < NIPIS));
965 1.3 matt
966 1.3 matt r = (thread << RMIXL_PIC_IPIBASE_ID_THREAD_SHIFT)
967 1.3 matt | (core << RMIXL_PIC_IPIBASE_ID_CORE_SHIFT)
968 1.3 matt | (RMIXL_INTRVEC_IPI + tag);
969 1.3 matt
970 1.3 matt mutex_enter(&rmixl_ipi_lock);
971 1.3 matt atomic_or_64(&ci->ci_request_ipis, req);
972 1.3 matt RMIXL_PICREG_WRITE(RMIXL_PIC_IPIBASE, r);
973 1.3 matt mutex_exit(&rmixl_ipi_lock);
974 1.3 matt
975 1.3 matt return 0;
976 1.2 matt }
977 1.2 matt
978 1.3 matt static int
979 1.3 matt rmixl_ipi_intr(void *arg)
980 1.2 matt {
981 1.3 matt struct cpu_info * const ci = curcpu();
982 1.4 cliff const uint64_t ipi_mask = 1 << (uintptr_t)arg;
983 1.2 matt
984 1.3 matt KASSERT(ci->ci_cpl >= IPL_SCHED);
985 1.4 cliff KASSERT((uintptr_t)arg < NIPIS);
986 1.2 matt
987 1.4 cliff /* if the request is clear, it was previously processed */
988 1.4 cliff if ((ci->ci_request_ipis & ipi_mask) == 0)
989 1.4 cliff return 0;
990 1.2 matt
991 1.3 matt atomic_or_64(&ci->ci_active_ipis, ipi_mask);
992 1.3 matt atomic_and_64(&ci->ci_request_ipis, ~ipi_mask);
993 1.2 matt
994 1.3 matt ipi_process(ci, ipi_mask);
995 1.2 matt
996 1.3 matt atomic_and_64(&ci->ci_active_ipis, ~ipi_mask);
997 1.2 matt
998 1.3 matt return 1;
999 1.3 matt }
1000 1.3 matt #endif /* MULTIPROCESSOR */
1001 1.2 matt
1002 1.3 matt #if defined(DIAGNOSTIC) || defined(IOINTR_DEBUG) || defined(DDB)
1003 1.3 matt int
1004 1.3 matt rmixl_intrhand_print_subr(int vec)
1005 1.3 matt {
1006 1.3 matt rmixl_intrhand_t *ih = &rmixl_intrhand[vec];
1007 1.3 matt printf("vec %d: func %p, arg %p, vec %d, ipl %d, mask %#x\n",
1008 1.3 matt vec, ih->ih_func, ih->ih_arg, ih->ih_vec, ih->ih_ipl,
1009 1.3 matt ih->ih_cpumask);
1010 1.3 matt return 0;
1011 1.3 matt }
1012 1.3 matt int
1013 1.3 matt rmixl_intrhand_print(void)
1014 1.3 matt {
1015 1.3 matt for (int vec=0; vec < NINTRVECS ; vec++)
1016 1.3 matt rmixl_intrhand_print_subr(vec);
1017 1.3 matt return 0;
1018 1.3 matt }
1019 1.2 matt
1020 1.3 matt static inline void
1021 1.3 matt rmixl_irt_entry_print(u_int irt)
1022 1.3 matt {
1023 1.3 matt uint32_t c0, c1;
1024 1.2 matt
1025 1.3 matt if ((irt < 0) || (irt > NIRTS))
1026 1.3 matt return;
1027 1.3 matt c0 = RMIXL_PICREG_READ(RMIXL_PIC_IRTENTRYC0(irt));
1028 1.3 matt c1 = RMIXL_PICREG_READ(RMIXL_PIC_IRTENTRYC1(irt));
1029 1.3 matt printf("irt[%d]: %#x, %#x\n", irt, c0, c1);
1030 1.2 matt }
1031 1.2 matt
1032 1.2 matt int
1033 1.3 matt rmixl_irt_print(void)
1034 1.2 matt {
1035 1.3 matt printf("%s:\n", __func__);
1036 1.3 matt for (int irt=0; irt < NIRTS ; irt++)
1037 1.3 matt rmixl_irt_entry_print(irt);
1038 1.3 matt return 0;
1039 1.3 matt }
1040 1.2 matt
1041 1.3 matt void
1042 1.3 matt rmixl_ipl_eimr_map_print(void)
1043 1.3 matt {
1044 1.3 matt printf("IPL_NONE=%d, mask %#"PRIx64"\n",
1045 1.3 matt IPL_NONE, ipl_eimr_map[IPL_NONE]);
1046 1.3 matt printf("IPL_SOFTCLOCK=%d, mask %#"PRIx64"\n",
1047 1.3 matt IPL_SOFTCLOCK, ipl_eimr_map[IPL_SOFTCLOCK]);
1048 1.3 matt printf("IPL_SOFTNET=%d, mask %#"PRIx64"\n",
1049 1.3 matt IPL_SOFTNET, ipl_eimr_map[IPL_SOFTNET]);
1050 1.3 matt printf("IPL_VM=%d, mask %#"PRIx64"\n",
1051 1.3 matt IPL_VM, ipl_eimr_map[IPL_VM]);
1052 1.3 matt printf("IPL_SCHED=%d, mask %#"PRIx64"\n",
1053 1.3 matt IPL_SCHED, ipl_eimr_map[IPL_SCHED]);
1054 1.3 matt printf("IPL_DDB=%d, mask %#"PRIx64"\n",
1055 1.3 matt IPL_DDB, ipl_eimr_map[IPL_DDB]);
1056 1.3 matt printf("IPL_HIGH=%d, mask %#"PRIx64"\n",
1057 1.3 matt IPL_HIGH, ipl_eimr_map[IPL_HIGH]);
1058 1.2 matt }
1059 1.3 matt
1060 1.2 matt #endif
1061