interrupt.c revision 1.3 1 1.3 tsutsui /* $NetBSD: interrupt.c,v 1.3 2008/05/14 13:29:27 tsutsui Exp $ */
2 1.1 tsutsui
3 1.3 tsutsui /*-
4 1.3 tsutsui * Copyright (c) 2006 Izumi Tsutsui. All rights reserved.
5 1.1 tsutsui *
6 1.1 tsutsui * Redistribution and use in source and binary forms, with or without
7 1.1 tsutsui * modification, are permitted provided that the following conditions
8 1.1 tsutsui * are met:
9 1.1 tsutsui * 1. Redistributions of source code must retain the above copyright
10 1.1 tsutsui * notice, this list of conditions and the following disclaimer.
11 1.1 tsutsui * 2. Redistributions in binary form must reproduce the above copyright
12 1.1 tsutsui * notice, this list of conditions and the following disclaimer in the
13 1.1 tsutsui * documentation and/or other materials provided with the distribution.
14 1.1 tsutsui *
15 1.1 tsutsui * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16 1.1 tsutsui * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17 1.1 tsutsui * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18 1.1 tsutsui * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19 1.1 tsutsui * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20 1.1 tsutsui * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 1.1 tsutsui * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 1.1 tsutsui * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 1.1 tsutsui * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 1.1 tsutsui * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 1.1 tsutsui */
26 1.1 tsutsui
27 1.1 tsutsui /*-
28 1.1 tsutsui * Copyright (c) 2001 The NetBSD Foundation, Inc.
29 1.1 tsutsui * All rights reserved.
30 1.1 tsutsui *
31 1.1 tsutsui * This code is derived from software contributed to The NetBSD Foundation
32 1.1 tsutsui * by Jason R. Thorpe.
33 1.1 tsutsui *
34 1.1 tsutsui * Redistribution and use in source and binary forms, with or without
35 1.1 tsutsui * modification, are permitted provided that the following conditions
36 1.1 tsutsui * are met:
37 1.1 tsutsui * 1. Redistributions of source code must retain the above copyright
38 1.1 tsutsui * notice, this list of conditions and the following disclaimer.
39 1.1 tsutsui * 2. Redistributions in binary form must reproduce the above copyright
40 1.1 tsutsui * notice, this list of conditions and the following disclaimer in the
41 1.1 tsutsui * documentation and/or other materials provided with the distribution.
42 1.1 tsutsui *
43 1.1 tsutsui * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
44 1.1 tsutsui * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
45 1.1 tsutsui * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
46 1.1 tsutsui * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
47 1.1 tsutsui * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
48 1.1 tsutsui * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
49 1.1 tsutsui * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
50 1.1 tsutsui * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
51 1.1 tsutsui * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
52 1.1 tsutsui * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
53 1.1 tsutsui * POSSIBILITY OF SUCH DAMAGE.
54 1.1 tsutsui */
55 1.1 tsutsui
56 1.1 tsutsui /*
57 1.1 tsutsui * Copyright (c) 2000 Soren S. Jorvang. All rights reserved.
58 1.1 tsutsui *
59 1.1 tsutsui * Redistribution and use in source and binary forms, with or without
60 1.1 tsutsui * modification, are permitted provided that the following conditions
61 1.1 tsutsui * are met:
62 1.1 tsutsui * 1. Redistributions of source code must retain the above copyright
63 1.1 tsutsui * notice, this list of conditions, and the following disclaimer.
64 1.1 tsutsui * 2. Redistributions in binary form must reproduce the above copyright
65 1.1 tsutsui * notice, this list of conditions and the following disclaimer in the
66 1.1 tsutsui * documentation and/or other materials provided with the distribution.
67 1.1 tsutsui *
68 1.1 tsutsui * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
69 1.1 tsutsui * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
70 1.1 tsutsui * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
71 1.1 tsutsui * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
72 1.1 tsutsui * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
73 1.1 tsutsui * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
74 1.1 tsutsui * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
75 1.1 tsutsui * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
76 1.1 tsutsui * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
77 1.1 tsutsui * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
78 1.1 tsutsui * SUCH DAMAGE.
79 1.1 tsutsui */
80 1.1 tsutsui
81 1.1 tsutsui #include <sys/cdefs.h>
82 1.3 tsutsui __KERNEL_RCSID(0, "$NetBSD: interrupt.c,v 1.3 2008/05/14 13:29:27 tsutsui Exp $");
83 1.1 tsutsui
84 1.1 tsutsui #include <sys/param.h>
85 1.1 tsutsui #include <sys/malloc.h>
86 1.1 tsutsui #include <sys/cpu.h>
87 1.1 tsutsui #include <sys/intr.h>
88 1.1 tsutsui
89 1.1 tsutsui #include <uvm/uvm_extern.h>
90 1.1 tsutsui
91 1.1 tsutsui #include <mips/mips3_clock.h>
92 1.1 tsutsui #include <machine/bus.h>
93 1.1 tsutsui
94 1.1 tsutsui #include <dev/ic/i8259reg.h>
95 1.1 tsutsui #include <dev/isa/isareg.h>
96 1.1 tsutsui
97 1.1 tsutsui #include <cobalt/dev/gtreg.h>
98 1.1 tsutsui
99 1.1 tsutsui #define ICU_LEVEL 4
100 1.1 tsutsui #define IRQ_SLAVE 2
101 1.1 tsutsui
102 1.1 tsutsui #define IO_ELCR 0x4d0
103 1.1 tsutsui #define IO_ELCRSIZE 2
104 1.1 tsutsui #define ELCR0 0
105 1.1 tsutsui #define ELCR1 1
106 1.1 tsutsui
107 1.1 tsutsui #define ICU1_READ(reg) \
108 1.1 tsutsui bus_space_read_1(icu_bst, icu1_bsh, (reg))
109 1.1 tsutsui #define ICU1_WRITE(reg, val) \
110 1.1 tsutsui bus_space_write_1(icu_bst, icu1_bsh, (reg), (val))
111 1.1 tsutsui #define ICU2_READ(reg) \
112 1.1 tsutsui bus_space_read_1(icu_bst, icu2_bsh, (reg))
113 1.1 tsutsui #define ICU2_WRITE(reg, val) \
114 1.1 tsutsui bus_space_write_1(icu_bst, icu2_bsh, (reg), (val))
115 1.1 tsutsui #define ELCR_READ(reg) \
116 1.1 tsutsui bus_space_read_1(icu_bst, elcr_bsh, (reg))
117 1.1 tsutsui #define ELCR_WRITE(reg, val) \
118 1.1 tsutsui bus_space_write_1(icu_bst, elcr_bsh, (reg), (val))
119 1.1 tsutsui
120 1.1 tsutsui static u_int icu_imask, icu_elcr;
121 1.1 tsutsui static bus_space_tag_t icu_bst;
122 1.1 tsutsui static bus_space_handle_t icu1_bsh, icu2_bsh, elcr_bsh;
123 1.1 tsutsui
124 1.1 tsutsui struct icu_intrhead {
125 1.1 tsutsui LIST_HEAD(, cobalt_intrhand) intr_q;
126 1.1 tsutsui int intr_type;
127 1.1 tsutsui struct evcnt intr_evcnt;
128 1.1 tsutsui char intr_evname[32];
129 1.1 tsutsui };
130 1.1 tsutsui static struct icu_intrhead icu_intrtab[NICU_INT];
131 1.1 tsutsui
132 1.1 tsutsui struct cpu_intrhead {
133 1.1 tsutsui struct cobalt_intrhand intr_ih;
134 1.1 tsutsui struct evcnt intr_evcnt;
135 1.1 tsutsui char intr_evname[32];
136 1.1 tsutsui };
137 1.1 tsutsui static struct cpu_intrhead cpu_intrtab[NCPU_INT];
138 1.1 tsutsui
139 1.1 tsutsui static int icu_intr(void *);
140 1.1 tsutsui static void icu_set(void);
141 1.1 tsutsui
142 1.1 tsutsui void
143 1.1 tsutsui intr_init(void)
144 1.1 tsutsui {
145 1.1 tsutsui int i;
146 1.1 tsutsui
147 1.1 tsutsui /*
148 1.1 tsutsui * Initialize CPU interrupts.
149 1.1 tsutsui */
150 1.1 tsutsui for (i = 0; i < NCPU_INT; i++) {
151 1.1 tsutsui snprintf(cpu_intrtab[i].intr_evname,
152 1.1 tsutsui sizeof(cpu_intrtab[i].intr_evname), "int %d", i);
153 1.1 tsutsui evcnt_attach_dynamic(&cpu_intrtab[i].intr_evcnt,
154 1.1 tsutsui EVCNT_TYPE_INTR, NULL, "mips", cpu_intrtab[i].intr_evname);
155 1.1 tsutsui }
156 1.1 tsutsui
157 1.1 tsutsui /*
158 1.1 tsutsui * Initialize ICU interrupts.
159 1.1 tsutsui */
160 1.1 tsutsui icu_bst = 0; /* XXX unused on cobalt */
161 1.1 tsutsui bus_space_map(icu_bst, PCIB_BASE + IO_ICU1, IO_ICUSIZE, 0, &icu1_bsh);
162 1.1 tsutsui bus_space_map(icu_bst, PCIB_BASE + IO_ICU2, IO_ICUSIZE, 0, &icu2_bsh);
163 1.1 tsutsui bus_space_map(icu_bst, PCIB_BASE + IO_ELCR, IO_ELCRSIZE, 0, &elcr_bsh);
164 1.1 tsutsui
165 1.1 tsutsui /* All interrupts default to "masked off". */
166 1.1 tsutsui icu_imask = 0xffff;
167 1.1 tsutsui
168 1.1 tsutsui /* All interrupts default to edge-triggered. */
169 1.1 tsutsui icu_elcr = 0;
170 1.1 tsutsui
171 1.1 tsutsui /* Initialize master PIC */
172 1.1 tsutsui
173 1.1 tsutsui /* reset; program device, four bytes */
174 1.1 tsutsui ICU1_WRITE(PIC_ICW1, ICW1_SELECT | ICW1_IC4);
175 1.1 tsutsui /* starting at this vector index */
176 1.1 tsutsui ICU1_WRITE(PIC_ICW2, 0); /* XXX */
177 1.1 tsutsui /* slave on line 2 */
178 1.1 tsutsui ICU1_WRITE(PIC_ICW3, ICW3_CASCADE(IRQ_SLAVE));
179 1.1 tsutsui /* special fully nested mode, 8086 mode */
180 1.1 tsutsui ICU1_WRITE(PIC_ICW4, ICW4_SFNM | ICW4_8086);
181 1.1 tsutsui /* mask all interrupts */
182 1.1 tsutsui ICU1_WRITE(PIC_OCW1, icu_imask & 0xff);
183 1.1 tsutsui /* special mask mode */
184 1.1 tsutsui ICU1_WRITE(PIC_OCW3, OCW3_SELECT | OCW3_SSMM | OCW3_SMM);
185 1.1 tsutsui /* read IRR by default */
186 1.1 tsutsui ICU1_WRITE(PIC_OCW3, OCW3_SELECT | OCW3_RR);
187 1.1 tsutsui
188 1.1 tsutsui /* Initialize slave PIC */
189 1.1 tsutsui
190 1.1 tsutsui /* reset; program device, four bytes */
191 1.1 tsutsui ICU2_WRITE(PIC_ICW1, ICW1_SELECT | ICW1_IC4);
192 1.1 tsutsui /* starting at this vector index */
193 1.1 tsutsui ICU2_WRITE(PIC_ICW2, 8); /* XXX */
194 1.1 tsutsui /* slave connected to line 2 of master */
195 1.1 tsutsui ICU2_WRITE(PIC_ICW3, ICW3_SIC(IRQ_SLAVE));
196 1.1 tsutsui /* special fully nested mode, 8086 mode */
197 1.1 tsutsui ICU2_WRITE(PIC_ICW4, ICW4_SFNM | ICW4_8086);
198 1.1 tsutsui /* mask all interrupts */
199 1.1 tsutsui ICU1_WRITE(PIC_OCW1, (icu_imask >> 8) & 0xff);
200 1.1 tsutsui /* special mask mode */
201 1.1 tsutsui ICU2_WRITE(PIC_OCW3, OCW3_SELECT | OCW3_SSMM | OCW3_SMM);
202 1.1 tsutsui /* read IRR by default */
203 1.1 tsutsui ICU2_WRITE(PIC_OCW3, OCW3_SELECT | OCW3_RR);
204 1.1 tsutsui
205 1.1 tsutsui /* default to edge-triggered */
206 1.1 tsutsui ELCR_WRITE(ELCR0, icu_elcr & 0xff);
207 1.1 tsutsui ELCR_WRITE(ELCR1, (icu_elcr >> 8) & 0xff);
208 1.1 tsutsui
209 1.1 tsutsui wbflush();
210 1.1 tsutsui
211 1.1 tsutsui /* Initialize our interrupt table. */
212 1.1 tsutsui for (i = 0; i < NICU_INT; i++) {
213 1.1 tsutsui LIST_INIT(&icu_intrtab[i].intr_q);
214 1.1 tsutsui snprintf(icu_intrtab[i].intr_evname,
215 1.1 tsutsui sizeof(icu_intrtab[i].intr_evname), "irq %d", i);
216 1.1 tsutsui evcnt_attach_dynamic(&icu_intrtab[i].intr_evcnt,
217 1.1 tsutsui EVCNT_TYPE_INTR, &cpu_intrtab[ICU_LEVEL].intr_evcnt,
218 1.1 tsutsui "icu", icu_intrtab[i].intr_evname);
219 1.1 tsutsui icu_intrtab[i].intr_type = IST_NONE;
220 1.1 tsutsui }
221 1.1 tsutsui
222 1.1 tsutsui cpu_intr_establish(ICU_LEVEL, IPL_NONE, icu_intr, NULL);
223 1.1 tsutsui }
224 1.1 tsutsui
225 1.1 tsutsui void *
226 1.1 tsutsui icu_intr_establish(int irq, int type, int ipl, int (*func)(void *), void *arg)
227 1.1 tsutsui {
228 1.1 tsutsui struct cobalt_intrhand *ih;
229 1.1 tsutsui int s;
230 1.1 tsutsui
231 1.1 tsutsui if (irq >= NICU_INT || irq == IRQ_SLAVE || type == IST_NONE)
232 1.1 tsutsui panic("%s: bad irq or type", __func__);
233 1.1 tsutsui
234 1.1 tsutsui switch (icu_intrtab[irq].intr_type) {
235 1.1 tsutsui case IST_NONE:
236 1.1 tsutsui icu_intrtab[irq].intr_type = type;
237 1.1 tsutsui break;
238 1.1 tsutsui
239 1.1 tsutsui case IST_EDGE:
240 1.1 tsutsui case IST_LEVEL:
241 1.1 tsutsui if (type == icu_intrtab[irq].intr_type)
242 1.1 tsutsui break;
243 1.1 tsutsui /* FALLTHROUGH */
244 1.1 tsutsui case IST_PULSE:
245 1.1 tsutsui /*
246 1.1 tsutsui * We can't share interrupts in this case.
247 1.1 tsutsui */
248 1.1 tsutsui return NULL;
249 1.1 tsutsui }
250 1.1 tsutsui
251 1.1 tsutsui ih = malloc(sizeof(*ih), M_DEVBUF, M_NOWAIT);
252 1.1 tsutsui if (ih == NULL)
253 1.1 tsutsui return NULL;
254 1.1 tsutsui
255 1.1 tsutsui ih->ih_func = func;
256 1.1 tsutsui ih->ih_arg = arg;
257 1.1 tsutsui ih->ih_irq = irq;
258 1.1 tsutsui ih->ih_cookie_type = COBALT_COOKIE_TYPE_ICU;
259 1.1 tsutsui
260 1.1 tsutsui s = splhigh();
261 1.1 tsutsui
262 1.1 tsutsui /* Insert the handler into the table. */
263 1.1 tsutsui LIST_INSERT_HEAD(&icu_intrtab[irq].intr_q, ih, ih_q);
264 1.1 tsutsui
265 1.1 tsutsui /* Enable it, set trigger mode. */
266 1.1 tsutsui icu_imask &= ~(1U << irq);
267 1.1 tsutsui if (icu_intrtab[irq].intr_type == IST_LEVEL)
268 1.1 tsutsui icu_elcr |= (1U << irq);
269 1.1 tsutsui else
270 1.1 tsutsui icu_elcr &= ~(1U << irq);
271 1.1 tsutsui
272 1.1 tsutsui icu_set();
273 1.1 tsutsui
274 1.1 tsutsui splx(s);
275 1.1 tsutsui
276 1.1 tsutsui return ih;
277 1.1 tsutsui }
278 1.1 tsutsui
279 1.1 tsutsui void
280 1.1 tsutsui icu_intr_disestablish(void *cookie)
281 1.1 tsutsui {
282 1.1 tsutsui struct cobalt_intrhand *ih = cookie;
283 1.1 tsutsui int s;
284 1.1 tsutsui
285 1.1 tsutsui if (ih->ih_cookie_type == COBALT_COOKIE_TYPE_ICU) {
286 1.1 tsutsui s = splhigh();
287 1.1 tsutsui
288 1.1 tsutsui LIST_REMOVE(ih, ih_q);
289 1.1 tsutsui
290 1.1 tsutsui if (LIST_FIRST(&icu_intrtab[ih->ih_irq].intr_q) == NULL) {
291 1.1 tsutsui icu_imask |= (1U << ih->ih_irq);
292 1.1 tsutsui icu_set();
293 1.1 tsutsui }
294 1.1 tsutsui splx(s);
295 1.1 tsutsui free(ih, M_DEVBUF);
296 1.1 tsutsui }
297 1.1 tsutsui }
298 1.1 tsutsui
299 1.1 tsutsui void
300 1.1 tsutsui icu_set(void)
301 1.1 tsutsui {
302 1.1 tsutsui
303 1.1 tsutsui if ((icu_imask & 0xff00) != 0xff00)
304 1.1 tsutsui icu_imask &= ~(1U << IRQ_SLAVE);
305 1.1 tsutsui else
306 1.1 tsutsui icu_imask |= (1U << IRQ_SLAVE);
307 1.1 tsutsui
308 1.1 tsutsui ICU1_WRITE(PIC_OCW1, icu_imask);
309 1.1 tsutsui ICU2_WRITE(PIC_OCW1, icu_imask >> 8);
310 1.1 tsutsui
311 1.1 tsutsui ELCR_WRITE(ELCR0, icu_elcr);
312 1.1 tsutsui ELCR_WRITE(ELCR1, icu_elcr >> 8);
313 1.1 tsutsui }
314 1.1 tsutsui
315 1.1 tsutsui int
316 1.1 tsutsui icu_intr(void *arg)
317 1.1 tsutsui {
318 1.1 tsutsui struct cobalt_intrhand *ih;
319 1.1 tsutsui int irq, handled;
320 1.1 tsutsui
321 1.1 tsutsui handled = 0;
322 1.1 tsutsui
323 1.1 tsutsui for (;;) {
324 1.1 tsutsui /* check requested irq */
325 1.1 tsutsui ICU1_WRITE(PIC_OCW3, OCW3_SELECT | OCW3_POLL);
326 1.1 tsutsui irq = ICU1_READ(PIC_OCW3);
327 1.1 tsutsui if ((irq & OCW3_POLL_PENDING) == 0)
328 1.1 tsutsui return handled;
329 1.1 tsutsui
330 1.1 tsutsui irq = OCW3_POLL_IRQ(irq);
331 1.1 tsutsui if (irq == IRQ_SLAVE) {
332 1.1 tsutsui ICU2_WRITE(PIC_OCW3, OCW3_SELECT | OCW3_POLL);
333 1.1 tsutsui irq = OCW3_POLL_IRQ(ICU2_READ(PIC_OCW3)) + 8;
334 1.1 tsutsui }
335 1.1 tsutsui
336 1.1 tsutsui icu_intrtab[irq].intr_evcnt.ev_count++;
337 1.1 tsutsui LIST_FOREACH(ih, &icu_intrtab[irq].intr_q, ih_q) {
338 1.1 tsutsui if (__predict_false(ih->ih_func == NULL))
339 1.1 tsutsui printf("%s: spurious interrupt (irq = %d)\n",
340 1.1 tsutsui __func__, irq);
341 1.1 tsutsui else if (__predict_true((*ih->ih_func)(ih->ih_arg))) {
342 1.1 tsutsui handled = 1;
343 1.1 tsutsui }
344 1.1 tsutsui }
345 1.1 tsutsui
346 1.1 tsutsui /* issue EOI to ack */
347 1.1 tsutsui if (irq >= 8) {
348 1.1 tsutsui ICU2_WRITE(PIC_OCW2,
349 1.1 tsutsui OCW2_SELECT | OCW2_SL | OCW2_EOI |
350 1.1 tsutsui OCW2_ILS(irq - 8));
351 1.1 tsutsui irq = IRQ_SLAVE;
352 1.1 tsutsui }
353 1.1 tsutsui ICU1_WRITE(PIC_OCW2,
354 1.1 tsutsui OCW2_SELECT | OCW2_SL | OCW2_EOI | OCW2_ILS(irq));
355 1.1 tsutsui }
356 1.1 tsutsui }
357 1.1 tsutsui
358 1.1 tsutsui void *
359 1.1 tsutsui cpu_intr_establish(int level, int ipl, int (*func)(void *), void *arg)
360 1.1 tsutsui {
361 1.1 tsutsui struct cobalt_intrhand *ih;
362 1.1 tsutsui
363 1.1 tsutsui if (level < 0 || level >= NCPU_INT)
364 1.1 tsutsui panic("invalid interrupt level");
365 1.1 tsutsui
366 1.1 tsutsui ih = &cpu_intrtab[level].intr_ih;
367 1.1 tsutsui
368 1.1 tsutsui if (ih->ih_func != NULL)
369 1.1 tsutsui panic("cannot share CPU interrupts");
370 1.1 tsutsui
371 1.1 tsutsui ih->ih_cookie_type = COBALT_COOKIE_TYPE_CPU;
372 1.1 tsutsui ih->ih_func = func;
373 1.1 tsutsui ih->ih_arg = arg;
374 1.1 tsutsui ih->ih_irq = NICU_INT + level;
375 1.1 tsutsui
376 1.1 tsutsui return ih;
377 1.1 tsutsui }
378 1.1 tsutsui
379 1.1 tsutsui void
380 1.1 tsutsui cpu_intr_disestablish(void *cookie)
381 1.1 tsutsui {
382 1.1 tsutsui struct cobalt_intrhand *ih = cookie;
383 1.1 tsutsui
384 1.1 tsutsui if (ih->ih_cookie_type == COBALT_COOKIE_TYPE_CPU) {
385 1.1 tsutsui ih->ih_func = NULL;
386 1.1 tsutsui ih->ih_arg = NULL;
387 1.1 tsutsui ih->ih_cookie_type = 0;
388 1.1 tsutsui }
389 1.1 tsutsui }
390 1.1 tsutsui
391 1.1 tsutsui void
392 1.1 tsutsui cpu_intr(uint32_t status, uint32_t cause, uint32_t pc, uint32_t ipending)
393 1.1 tsutsui {
394 1.1 tsutsui struct clockframe cf;
395 1.1 tsutsui struct cobalt_intrhand *ih;
396 1.1 tsutsui struct cpu_info *ci;
397 1.1 tsutsui uint32_t handled;
398 1.1 tsutsui
399 1.1 tsutsui handled = 0;
400 1.1 tsutsui ci = curcpu();
401 1.1 tsutsui ci->ci_idepth++;
402 1.1 tsutsui uvmexp.intrs++;
403 1.1 tsutsui
404 1.1 tsutsui if (ipending & MIPS_INT_MASK_5) {
405 1.1 tsutsui /* call the common MIPS3 clock interrupt handler */
406 1.1 tsutsui cf.pc = pc;
407 1.1 tsutsui cf.sr = status;
408 1.1 tsutsui mips3_clockintr(&cf);
409 1.1 tsutsui
410 1.1 tsutsui handled |= MIPS_INT_MASK_5;
411 1.1 tsutsui }
412 1.1 tsutsui _splset((status & handled) | MIPS_SR_INT_IE);
413 1.1 tsutsui
414 1.1 tsutsui if (__predict_false(ipending & MIPS_INT_MASK_0)) {
415 1.1 tsutsui /* GT64x11 timer0 */
416 1.1 tsutsui volatile uint32_t *irq_src =
417 1.1 tsutsui (uint32_t *)MIPS_PHYS_TO_KSEG1(GT_BASE + GT_INTR_CAUSE);
418 1.1 tsutsui
419 1.1 tsutsui if (__predict_true((*irq_src & T0EXP) != 0)) {
420 1.1 tsutsui /* GT64x11 timer is no longer used for hardclock(9) */
421 1.1 tsutsui *irq_src = 0;
422 1.1 tsutsui }
423 1.1 tsutsui handled |= MIPS_INT_MASK_0;
424 1.1 tsutsui }
425 1.1 tsutsui
426 1.1 tsutsui if (ipending & MIPS_INT_MASK_3) {
427 1.1 tsutsui /* 16650 serial */
428 1.1 tsutsui ih = &cpu_intrtab[3].intr_ih;
429 1.1 tsutsui if (__predict_true(ih->ih_func != NULL)) {
430 1.1 tsutsui if (__predict_true((*ih->ih_func)(ih->ih_arg))) {
431 1.1 tsutsui cpu_intrtab[3].intr_evcnt.ev_count++;
432 1.1 tsutsui }
433 1.1 tsutsui }
434 1.1 tsutsui handled |= MIPS_INT_MASK_3;
435 1.1 tsutsui }
436 1.1 tsutsui _splset((status & handled) | MIPS_SR_INT_IE);
437 1.1 tsutsui
438 1.1 tsutsui if (ipending & MIPS_INT_MASK_1) {
439 1.1 tsutsui /* tulip primary */
440 1.1 tsutsui ih = &cpu_intrtab[1].intr_ih;
441 1.1 tsutsui if (__predict_true(ih->ih_func != NULL)) {
442 1.1 tsutsui if (__predict_true((*ih->ih_func)(ih->ih_arg))) {
443 1.1 tsutsui cpu_intrtab[1].intr_evcnt.ev_count++;
444 1.1 tsutsui }
445 1.1 tsutsui }
446 1.1 tsutsui handled |= MIPS_INT_MASK_1;
447 1.1 tsutsui }
448 1.1 tsutsui if (ipending & MIPS_INT_MASK_2) {
449 1.1 tsutsui /* tulip secondary */
450 1.1 tsutsui ih = &cpu_intrtab[2].intr_ih;
451 1.1 tsutsui if (__predict_true(ih->ih_func != NULL)) {
452 1.1 tsutsui if (__predict_true((*ih->ih_func)(ih->ih_arg))) {
453 1.1 tsutsui cpu_intrtab[2].intr_evcnt.ev_count++;
454 1.1 tsutsui }
455 1.1 tsutsui }
456 1.1 tsutsui handled |= MIPS_INT_MASK_2;
457 1.1 tsutsui }
458 1.1 tsutsui
459 1.1 tsutsui if (ipending & MIPS_INT_MASK_4) {
460 1.1 tsutsui /* ICU interrupts */
461 1.1 tsutsui ih = &cpu_intrtab[4].intr_ih;
462 1.1 tsutsui if (__predict_true(ih->ih_func != NULL)) {
463 1.1 tsutsui if (__predict_true((*ih->ih_func)(ih->ih_arg))) {
464 1.1 tsutsui cpu_intrtab[4].intr_evcnt.ev_count++;
465 1.1 tsutsui }
466 1.1 tsutsui }
467 1.1 tsutsui handled |= MIPS_INT_MASK_4;
468 1.1 tsutsui }
469 1.1 tsutsui cause &= ~handled;
470 1.1 tsutsui _splset((status & ~cause & MIPS_HARD_INT_MASK) | MIPS_SR_INT_IE);
471 1.1 tsutsui ci->ci_idepth--;
472 1.1 tsutsui
473 1.1 tsutsui #ifdef __HAVE_FAST_SOFTINTS
474 1.1 tsutsui /* software interrupt */
475 1.1 tsutsui ipending &= (MIPS_SOFT_INT_MASK_1|MIPS_SOFT_INT_MASK_0);
476 1.1 tsutsui if (ipending == 0)
477 1.1 tsutsui return;
478 1.1 tsutsui _clrsoftintr(ipending);
479 1.1 tsutsui softintr_dispatch(ipending);
480 1.1 tsutsui #endif
481 1.1 tsutsui }
482 1.1 tsutsui
483 1.1 tsutsui
484 1.1 tsutsui static const int ipl2spl_table[] = {
485 1.1 tsutsui [IPL_NONE] = 0,
486 1.1 tsutsui [IPL_SOFTCLOCK] = MIPS_SOFT_INT_MASK_0,
487 1.1 tsutsui [IPL_SOFTNET] = MIPS_SOFT_INT_MASK_0|MIPS_SOFT_INT_MASK_1,
488 1.1 tsutsui [IPL_VM] = SPLVM,
489 1.1 tsutsui [IPL_SCHED] = SPLSCHED,
490 1.1 tsutsui };
491 1.1 tsutsui
492 1.1 tsutsui ipl_cookie_t
493 1.1 tsutsui makeiplcookie(ipl_t ipl)
494 1.1 tsutsui {
495 1.1 tsutsui
496 1.1 tsutsui return (ipl_cookie_t){._spl = ipl2spl_table[ipl]};
497 1.1 tsutsui }
498