2 * Copyright (c) 2006 Oleksandr Tymoshenko
3 * Copyright (c) 2002-2004 Juli Mallett <jmallett@FreeBSD.org>
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions, and the following disclaimer,
11 * without modification, immediately at the beginning of the file.
12 * 2. The name of the author may not be used to endorse or promote products
13 * derived from this software without specific prior written permission.
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
19 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 #include <sys/cdefs.h>
30 __FBSDID("$FreeBSD$");
32 #include <sys/param.h>
33 #include <sys/systm.h>
35 #include <sys/interrupt.h>
37 #include <machine/clock.h>
38 #include <machine/cpu.h>
39 #include <machine/cpufunc.h>
40 #include <machine/cpuinfo.h>
41 #include <machine/cpuregs.h>
42 #include <machine/frame.h>
43 #include <machine/intr_machdep.h>
44 #include <machine/md_var.h>
45 #include <machine/trap.h>
47 static struct intr_event *hardintr_events[NHARD_IRQS];
48 static struct intr_event *softintr_events[NSOFT_IRQS];
51 static int intrcnt_tab[NHARD_IRQS + NSOFT_IRQS];
52 static int intrcnt_index = 0;
53 static int last_printed = 0;
69 cpu_establish_hardintr(const char *name, driver_filter_t *filt,
70 void (*handler)(void*), void *arg, int irq, int flags, void **cookiep)
72 struct intr_event *event;
75 printf("Establish HARD IRQ %d: filt %p handler %p arg %p\n",
76 irq, filt, handler, arg);
78 * We have 6 levels, but thats 0 - 5 (not including 6)
80 if (irq < 0 || irq >= NHARD_IRQS)
81 panic("%s called for unknown hard intr %d", __func__, irq);
83 event = hardintr_events[irq];
85 error = intr_event_create(&event, (void *)irq, 0, irq,
86 (mask_fn)mips_mask_irq, (mask_fn)mips_unmask_irq,
87 NULL, NULL, "hard intr%d:", irq);
90 hardintr_events[irq] = event;
92 last_printed += snprintf(intrnames + last_printed,
93 MAXCOMLEN + 1, "hard irq%d: %s", irq, name);
95 intrcnt_tab[irq] = intrcnt_index;
101 intr_event_add_handler(event, name, filt, handler, arg,
102 intr_priority(flags), flags, cookiep);
104 mips_wr_status(mips_rd_status() | (((1 << irq) << 8) << 2));
108 cpu_establish_softintr(const char *name, driver_filter_t *filt,
109 void (*handler)(void*), void *arg, int irq, int flags,
112 struct intr_event *event;
115 printf("Establish SOFT IRQ %d: filt %p handler %p arg %p\n",
116 irq, filt, handler, arg);
117 if (irq < 0 || irq > NSOFT_IRQS)
118 panic("%s called for unknown hard intr %d", __func__, irq);
120 event = softintr_events[irq];
122 error = intr_event_create(&event, (void *)irq, 0, irq,
123 (mask_fn)mips_mask_irq, (mask_fn)mips_unmask_irq,
124 NULL, NULL, "intr%d:", irq);
127 softintr_events[irq] = event;
130 intr_event_add_handler(event, name, filt, handler, arg,
131 intr_priority(flags), flags, cookiep);
133 mips_wr_status(mips_rd_status() | (((1<< irq) << 8)));
137 cpu_intr(struct trapframe *tf)
139 struct intr_event *event;
145 cause = mips_rd_cause();
146 intr = (cause & MIPS_INT_MASK) >> 8;
147 cause &= ~MIPS_INT_MASK;
148 mips_wr_cause(cause);
149 while ((i = fls(intr)) != 0) {
150 intr &= ~(1 << (i - 1));
153 /* Software interrupt. */
154 i--; /* Get a 0-offset interrupt. */
156 event = softintr_events[i];
159 /* Hardware interrupt. */
160 i -= 2; /* Trim software interrupt bits. */
161 i--; /* Get a 0-offset interrupt. */
163 event = hardintr_events[i];
167 if (!event || TAILQ_EMPTY(&event->ie_handlers)) {
168 printf("stray %s interrupt %d\n",
169 hard ? "hard" : "soft", i);
173 if (intr_event_handle(event, tf) != 0) {
174 printf("stray %s interrupt %d\n",
175 hard ? "hard" : "soft", i);
179 KASSERT(i == 0, ("all interrupts handled"));