2 * Copyright (c) 1997, Stefan Esser <se@freebsd.org>
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice unmodified, this list of conditions, and the following
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 * $FreeBSD: src/sys/kern/kern_intr.c,v 1.24.2.1 2001/10/14 20:05:50 luigi Exp $
27 * $DragonFly: src/sys/kern/kern_intr.c,v 1.2 2003/06/17 04:28:41 dillon Exp $
32 #include <sys/param.h>
33 #include <sys/systm.h>
34 #include <sys/malloc.h>
35 #include <sys/kernel.h>
36 #include <sys/sysctl.h>
38 #include <machine/ipl.h>
40 #include <sys/interrupt.h>
43 swihand_t *sl_handler;
44 struct swilist *sl_next;
47 static struct swilist swilists[NSWI];
50 register_swi(intr, handler)
54 struct swilist *slp, *slq;
57 if (intr < NHWI || intr >= NHWI + NSWI)
58 panic("register_swi: bad intr %d", intr);
59 if (handler == swi_generic || handler == swi_null)
60 panic("register_swi: bad handler %p", (void *)handler);
61 slp = &swilists[intr - NHWI];
63 if (ihandlers[intr] == swi_null)
64 ihandlers[intr] = handler;
66 if (slp->sl_next == NULL) {
67 slp->sl_handler = ihandlers[intr];
68 ihandlers[intr] = swi_generic;
70 slq = malloc(sizeof(*slq), M_DEVBUF, M_NOWAIT);
72 panic("register_swi: malloc failed");
73 slq->sl_handler = handler;
75 while (slp->sl_next != NULL)
88 slp = &swilists[intr - NHWI];
92 } while (slp != NULL);
96 unregister_swi(intr, handler)
100 struct swilist *slfoundpred, *slp, *slq;
103 if (intr < NHWI || intr >= NHWI + NSWI)
104 panic("unregister_swi: bad intr %d", intr);
105 if (handler == swi_generic || handler == swi_null)
106 panic("unregister_swi: bad handler %p", (void *)handler);
107 slp = &swilists[intr - NHWI];
109 if (ihandlers[intr] == handler)
110 ihandlers[intr] = swi_null;
111 else if (slp->sl_next != NULL) {
113 for (slq = slp->sl_next; slq != NULL;
114 slp = slq, slq = slp->sl_next)
115 if (slq->sl_handler == handler)
117 slp = &swilists[intr - NHWI];
118 if (slfoundpred != NULL) {
119 slq = slfoundpred->sl_next;
120 slfoundpred->sl_next = slq->sl_next;
122 } else if (slp->sl_handler == handler) {
124 slp->sl_next = slq->sl_next;
125 slp->sl_handler = slq->sl_handler;
128 if (slp->sl_next == NULL)
129 ihandlers[intr] = slp->sl_handler;
135 * Sysctls used by systat and others: hw.intrnames and hw.intrcnt.
136 * The data for this machine dependent, and the declarations are in machine
137 * dependent code. The layout of intrnames and intrcnt however is machine
140 * We do not know the length of intrcnt and intrnames at compile time, so
141 * calculate things at run time.
144 sysctl_intrnames(SYSCTL_HANDLER_ARGS)
146 return (sysctl_handle_opaque(oidp, intrnames, eintrnames - intrnames,
150 SYSCTL_PROC(_hw, OID_AUTO, intrnames, CTLTYPE_OPAQUE | CTLFLAG_RD,
151 NULL, 0, sysctl_intrnames, "", "Interrupt Names");
154 sysctl_intrcnt(SYSCTL_HANDLER_ARGS)
156 return (sysctl_handle_opaque(oidp, intrcnt,
157 (char *)eintrcnt - (char *)intrcnt, req));
160 SYSCTL_PROC(_hw, OID_AUTO, intrcnt, CTLTYPE_OPAQUE | CTLFLAG_RD,
161 NULL, 0, sysctl_intrcnt, "", "Interrupt Counts");