2 * Copyright (c) 1991 The Regents of the University of California.
5 * This code is derived from software contributed to Berkeley by
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 4. Neither the name of the University nor the names of its contributors
17 * may be used to endorse or promote products derived from this software
18 * without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 * Copyright (c) 2002 Benno Rice.
34 * All rights reserved.
36 * Redistribution and use in source and binary forms, with or without
37 * modification, are permitted provided that the following conditions
39 * 1. Redistributions of source code must retain the above copyright
40 * notice, this list of conditions and the following disclaimer.
41 * 2. Redistributions in binary form must reproduce the above copyright
42 * notice, this list of conditions and the following disclaimer in the
43 * documentation and/or other materials provided with the distribution.
45 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
46 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
47 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
48 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
49 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
50 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
51 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
52 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
53 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
54 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
57 * from: @(#)isa.c 7.2 (Berkeley) 5/13/91
58 * form: src/sys/i386/isa/intr_machdep.c,v 1.57 2001/07/20
63 #include <sys/param.h>
64 #include <sys/systm.h>
65 #include <sys/kernel.h>
66 #include <sys/queue.h>
68 #include <sys/interrupt.h>
71 #include <sys/malloc.h>
72 #include <sys/mutex.h>
74 #include <sys/syslog.h>
75 #include <sys/vmmeter.h>
78 #include <machine/frame.h>
79 #include <machine/intr_machdep.h>
80 #include <machine/md_var.h>
81 #include <machine/trap.h>
85 #define MAX_STRAY_LOG 5
87 MALLOC_DEFINE(M_INTR, "intr", "interrupt handler data");
90 struct intr_event *event;
95 static struct powerpc_intr *powerpc_intrs[INTR_VECTORS];
96 static u_int nvectors; /* Allocated vectors */
97 static u_int stray_count;
102 intrcnt_setname(const char *name, int index)
104 snprintf(intrnames + (MAXCOMLEN + 1) * index, MAXCOMLEN + 1, "%-*s",
110 powerpc_intr_eoi(void *arg)
112 u_int irq = (uintptr_t)arg;
118 powerpc_intr_mask(void *arg)
120 u_int irq = (uintptr_t)arg;
127 powerpc_intr_unmask(void *arg)
129 u_int irq = (uintptr_t)arg;
131 PIC_UNMASK(pic, irq);
135 powerpc_register_pic(device_t dev)
142 powerpc_enable_intr(void)
144 struct powerpc_intr *i;
147 for (vector = 0; vector < nvectors; vector++) {
148 i = powerpc_intrs[vector];
152 PIC_ENABLE(pic, i->irq, vector);
159 powerpc_setup_intr(const char *name, u_int irq, driver_filter_t filter,
160 driver_intr_t handler, void *arg, enum intr_type flags, void **cookiep)
162 struct powerpc_intr *i;
169 for (vector = 0; vector < nvectors; vector++) {
170 i = powerpc_intrs[vector];
179 if (nvectors >= INTR_VECTORS) {
184 i = malloc(sizeof(*i), M_INTR, M_NOWAIT);
189 error = intr_event_create(&i->event, (void *)irq, 0,
192 powerpc_intr_eoi, powerpc_intr_mask,
194 NULL, "irq%u:", irq);
202 powerpc_intrs[vector] = i;
208 i->cntp = &intrcnt[vector];
209 intrcnt_setname(i->event->ie_fullname, vector);
212 PIC_ENABLE(pic, i->irq, vector);
217 error = intr_event_add_handler(i->event, name, filter, handler, arg,
218 intr_priority(flags), flags, cookiep);
220 intrcnt_setname(i->event->ie_fullname, vector);
225 powerpc_teardown_intr(void *cookie)
228 return (intr_event_remove_handler(cookie));
232 powerpc_dispatch_intr(u_int vector, struct trapframe *tf)
234 struct powerpc_intr *i;
235 struct intr_event *ie;
237 struct intr_handler *ih;
238 int error, sched, ret;
241 i = powerpc_intrs[vector];
248 KASSERT(ie != NULL, ("%s: interrupt without an event", __func__));
251 if (intr_event_handle(ie, tf) != 0) {
252 PIC_MASK(pic, i->irq);
253 log(LOG_ERR, "stray irq%u\n", i->irq);
256 if (TAILQ_EMPTY(&ie->ie_handlers))
260 * Execute all fast interrupt handlers directly without Giant. Note
261 * that this means that any fast interrupt handler must be MP safe.
266 TAILQ_FOREACH(ih, &ie->ie_handlers, ih_next) {
267 if (ih->ih_filter == NULL) {
271 CTR4(KTR_INTR, "%s: exec %p(%p) for %s", __func__,
272 ih->ih_filter, ih->ih_argument, ih->ih_name);
273 ret = ih->ih_filter(ih->ih_argument);
275 * Wrapper handler special case: see
276 * i386/intr_machdep.c::intr_execute_handlers()
279 if (ret == FILTER_SCHEDULE_THREAD)
285 PIC_MASK(pic, i->irq);
286 error = intr_event_schedule_thread(ie);
287 KASSERT(error == 0, ("%s: impossible stray interrupt",
290 PIC_EOI(pic, i->irq);
297 if (stray_count <= MAX_STRAY_LOG) {
298 printf("stray irq %d\n", i->irq);
299 if (stray_count >= MAX_STRAY_LOG) {
300 printf("got %d stray interrupts, not logging anymore\n",
305 PIC_MASK(pic, i->irq);