ofw_irqhandler.c revision 1.1.14.2 1 1.1.14.2 jdolecek /* $NetBSD: ofw_irqhandler.c,v 1.1.14.2 2002/06/23 17:34:55 jdolecek Exp $ */
2 1.1.14.2 jdolecek
3 1.1.14.2 jdolecek /*
4 1.1.14.2 jdolecek * Copyright (c) 1994-1998 Mark Brinicombe.
5 1.1.14.2 jdolecek * Copyright (c) 1994 Brini.
6 1.1.14.2 jdolecek * All rights reserved.
7 1.1.14.2 jdolecek *
8 1.1.14.2 jdolecek * This code is derived from software written for Brini by Mark Brinicombe
9 1.1.14.2 jdolecek *
10 1.1.14.2 jdolecek * Redistribution and use in source and binary forms, with or without
11 1.1.14.2 jdolecek * modification, are permitted provided that the following conditions
12 1.1.14.2 jdolecek * are met:
13 1.1.14.2 jdolecek * 1. Redistributions of source code must retain the above copyright
14 1.1.14.2 jdolecek * notice, this list of conditions and the following disclaimer.
15 1.1.14.2 jdolecek * 2. Redistributions in binary form must reproduce the above copyright
16 1.1.14.2 jdolecek * notice, this list of conditions and the following disclaimer in the
17 1.1.14.2 jdolecek * documentation and/or other materials provided with the distribution.
18 1.1.14.2 jdolecek * 3. All advertising materials mentioning features or use of this software
19 1.1.14.2 jdolecek * must display the following acknowledgement:
20 1.1.14.2 jdolecek * This product includes software developed by Mark Brinicombe
21 1.1.14.2 jdolecek * for the NetBSD Project.
22 1.1.14.2 jdolecek * 4. The name of the company nor the name of the author may be used to
23 1.1.14.2 jdolecek * endorse or promote products derived from this software without specific
24 1.1.14.2 jdolecek * prior written permission.
25 1.1.14.2 jdolecek *
26 1.1.14.2 jdolecek * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
27 1.1.14.2 jdolecek * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
28 1.1.14.2 jdolecek * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
29 1.1.14.2 jdolecek * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
30 1.1.14.2 jdolecek * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
31 1.1.14.2 jdolecek * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32 1.1.14.2 jdolecek * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
33 1.1.14.2 jdolecek * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34 1.1.14.2 jdolecek * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
35 1.1.14.2 jdolecek * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 1.1.14.2 jdolecek *
37 1.1.14.2 jdolecek * from: irqhandler.c
38 1.1.14.2 jdolecek *
39 1.1.14.2 jdolecek * IRQ/FIQ initialisation, claim, release and handler routines
40 1.1.14.2 jdolecek *
41 1.1.14.2 jdolecek * Created : 30/09/94
42 1.1.14.2 jdolecek */
43 1.1.14.2 jdolecek
44 1.1.14.2 jdolecek #include "opt_irqstats.h"
45 1.1.14.2 jdolecek
46 1.1.14.2 jdolecek #include <sys/param.h>
47 1.1.14.2 jdolecek #include <sys/systm.h>
48 1.1.14.2 jdolecek #include <sys/syslog.h>
49 1.1.14.2 jdolecek #include <sys/malloc.h>
50 1.1.14.2 jdolecek
51 1.1.14.2 jdolecek #include <uvm/uvm_extern.h>
52 1.1.14.2 jdolecek
53 1.1.14.2 jdolecek #include <machine/intr.h>
54 1.1.14.2 jdolecek #include <machine/cpu.h>
55 1.1.14.2 jdolecek
56 1.1.14.2 jdolecek irqhandler_t *irqhandlers[NIRQS];
57 1.1.14.2 jdolecek
58 1.1.14.2 jdolecek int current_intr_depth;
59 1.1.14.2 jdolecek u_int current_mask;
60 1.1.14.2 jdolecek u_int actual_mask;
61 1.1.14.2 jdolecek u_int disabled_mask;
62 1.1.14.2 jdolecek u_int spl_mask;
63 1.1.14.2 jdolecek u_int irqmasks[IPL_LEVELS];
64 1.1.14.2 jdolecek u_int irqblock[NIRQS];
65 1.1.14.2 jdolecek extern u_int intrcnt[];
66 1.1.14.2 jdolecek
67 1.1.14.2 jdolecek extern u_int soft_interrupts; /* Only so we can initialise it */
68 1.1.14.2 jdolecek
69 1.1.14.2 jdolecek extern char *_intrnames;
70 1.1.14.2 jdolecek
71 1.1.14.2 jdolecek /* Prototypes */
72 1.1.14.2 jdolecek
73 1.1.14.2 jdolecek int podule_irqhandler __P((void));
74 1.1.14.2 jdolecek extern void set_spl_masks __P((void));
75 1.1.14.2 jdolecek
76 1.1.14.2 jdolecek /*
77 1.1.14.2 jdolecek * void irq_init(void)
78 1.1.14.2 jdolecek *
79 1.1.14.2 jdolecek * Initialise the IRQ/FIQ sub system
80 1.1.14.2 jdolecek */
81 1.1.14.2 jdolecek
82 1.1.14.2 jdolecek void
83 1.1.14.2 jdolecek irq_init()
84 1.1.14.2 jdolecek {
85 1.1.14.2 jdolecek int loop;
86 1.1.14.2 jdolecek
87 1.1.14.2 jdolecek /* Clear all the IRQ handlers and the irq block masks */
88 1.1.14.2 jdolecek for (loop = 0; loop < NIRQS; ++loop) {
89 1.1.14.2 jdolecek irqhandlers[loop] = NULL;
90 1.1.14.2 jdolecek irqblock[loop] = 0;
91 1.1.14.2 jdolecek }
92 1.1.14.2 jdolecek
93 1.1.14.2 jdolecek /*
94 1.1.14.2 jdolecek * Setup the irqmasks for the different Interrupt Priority Levels
95 1.1.14.2 jdolecek * We will start with no bits set and these will be updated as handlers
96 1.1.14.2 jdolecek * are installed at different IPL's.
97 1.1.14.2 jdolecek */
98 1.1.14.2 jdolecek for (loop = 0; loop < IPL_LEVELS; ++loop)
99 1.1.14.2 jdolecek irqmasks[loop] = 0;
100 1.1.14.2 jdolecek
101 1.1.14.2 jdolecek current_intr_depth = 0;
102 1.1.14.2 jdolecek current_mask = 0x00000000;
103 1.1.14.2 jdolecek disabled_mask = 0x00000000;
104 1.1.14.2 jdolecek actual_mask = 0x00000000;
105 1.1.14.2 jdolecek spl_mask = 0x00000000;
106 1.1.14.2 jdolecek soft_interrupts = 0x00000000;
107 1.1.14.2 jdolecek
108 1.1.14.2 jdolecek set_spl_masks();
109 1.1.14.2 jdolecek
110 1.1.14.2 jdolecek /* Enable IRQ's and FIQ's */
111 1.1.14.2 jdolecek enable_interrupts(I32_bit | F32_bit);
112 1.1.14.2 jdolecek }
113 1.1.14.2 jdolecek
114 1.1.14.2 jdolecek
115 1.1.14.2 jdolecek /*
116 1.1.14.2 jdolecek * int irq_claim(int irq, irqhandler_t *handler)
117 1.1.14.2 jdolecek *
118 1.1.14.2 jdolecek * Enable an IRQ and install a handler for it.
119 1.1.14.2 jdolecek */
120 1.1.14.2 jdolecek
121 1.1.14.2 jdolecek int
122 1.1.14.2 jdolecek irq_claim(irq, handler)
123 1.1.14.2 jdolecek int irq;
124 1.1.14.2 jdolecek irqhandler_t *handler;
125 1.1.14.2 jdolecek {
126 1.1.14.2 jdolecek int level;
127 1.1.14.2 jdolecek int loop;
128 1.1.14.2 jdolecek
129 1.1.14.2 jdolecek #ifdef DIAGNOSTIC
130 1.1.14.2 jdolecek /* Sanity check */
131 1.1.14.2 jdolecek if (handler == NULL)
132 1.1.14.2 jdolecek panic("NULL interrupt handler\n");
133 1.1.14.2 jdolecek if (handler->ih_func == NULL)
134 1.1.14.2 jdolecek panic("Interrupt handler does not have a function\n");
135 1.1.14.2 jdolecek #endif /* DIAGNOSTIC */
136 1.1.14.2 jdolecek
137 1.1.14.2 jdolecek /*
138 1.1.14.2 jdolecek * IRQ_INSTRUCT indicates that we should get the irq number
139 1.1.14.2 jdolecek * from the irq structure
140 1.1.14.2 jdolecek */
141 1.1.14.2 jdolecek if (irq == IRQ_INSTRUCT)
142 1.1.14.2 jdolecek irq = handler->ih_num;
143 1.1.14.2 jdolecek
144 1.1.14.2 jdolecek /* Make sure the irq number is valid */
145 1.1.14.2 jdolecek if (irq < 0 || irq >= NIRQS)
146 1.1.14.2 jdolecek return(-1);
147 1.1.14.2 jdolecek
148 1.1.14.2 jdolecek /* Make sure the level is valid */
149 1.1.14.2 jdolecek if (handler->ih_level < 0 || handler->ih_level >= IPL_LEVELS)
150 1.1.14.2 jdolecek return(-1);
151 1.1.14.2 jdolecek
152 1.1.14.2 jdolecek /* Attach handler at top of chain */
153 1.1.14.2 jdolecek handler->ih_next = irqhandlers[irq];
154 1.1.14.2 jdolecek irqhandlers[irq] = handler;
155 1.1.14.2 jdolecek
156 1.1.14.2 jdolecek /*
157 1.1.14.2 jdolecek * Reset the flags for this handler.
158 1.1.14.2 jdolecek * As the handler is now in the chain mark it as active.
159 1.1.14.2 jdolecek */
160 1.1.14.2 jdolecek handler->ih_flags = 0 | IRQ_FLAG_ACTIVE;
161 1.1.14.2 jdolecek
162 1.1.14.2 jdolecek /*
163 1.1.14.2 jdolecek * Record the interrupt number for accounting.
164 1.1.14.2 jdolecek * Done here as the accounting number may not be the same as the
165 1.1.14.2 jdolecek * IRQ number though for the moment they are
166 1.1.14.2 jdolecek */
167 1.1.14.2 jdolecek handler->ih_num = irq;
168 1.1.14.2 jdolecek
169 1.1.14.2 jdolecek #ifdef IRQSTATS
170 1.1.14.2 jdolecek /* Get the interrupt name from the head of the list */
171 1.1.14.2 jdolecek if (handler->ih_name) {
172 1.1.14.2 jdolecek char *ptr = _intrnames + (irq * 14);
173 1.1.14.2 jdolecek strcpy(ptr, " ");
174 1.1.14.2 jdolecek strncpy(ptr, handler->ih_name,
175 1.1.14.2 jdolecek min(strlen(handler->ih_name), 13));
176 1.1.14.2 jdolecek } else {
177 1.1.14.2 jdolecek char *ptr = _intrnames + (irq * 14);
178 1.1.14.2 jdolecek sprintf(ptr, "irq %2d ", irq);
179 1.1.14.2 jdolecek }
180 1.1.14.2 jdolecek #endif /* IRQSTATS */
181 1.1.14.2 jdolecek
182 1.1.14.2 jdolecek /*
183 1.1.14.2 jdolecek * Update the irq masks.
184 1.1.14.2 jdolecek * Find the lowest interrupt priority on the irq chain.
185 1.1.14.2 jdolecek * Interrupt is allowable at priorities lower than this.
186 1.1.14.2 jdolecek * If ih_level is out of range then don't bother to update
187 1.1.14.2 jdolecek * the masks.
188 1.1.14.2 jdolecek */
189 1.1.14.2 jdolecek if (handler->ih_level >= 0 && handler->ih_level < IPL_LEVELS) {
190 1.1.14.2 jdolecek irqhandler_t *ptr;
191 1.1.14.2 jdolecek
192 1.1.14.2 jdolecek /*
193 1.1.14.2 jdolecek * Find the lowest interrupt priority on the irq chain.
194 1.1.14.2 jdolecek * Interrupt is allowable at priorities lower than this.
195 1.1.14.2 jdolecek */
196 1.1.14.2 jdolecek ptr = irqhandlers[irq];
197 1.1.14.2 jdolecek if (ptr) {
198 1.1.14.2 jdolecek level = ptr->ih_level - 1;
199 1.1.14.2 jdolecek while (ptr) {
200 1.1.14.2 jdolecek if (ptr->ih_level - 1 < level)
201 1.1.14.2 jdolecek level = ptr->ih_level - 1;
202 1.1.14.2 jdolecek ptr = ptr->ih_next;
203 1.1.14.2 jdolecek }
204 1.1.14.2 jdolecek while (level >= 0) {
205 1.1.14.2 jdolecek irqmasks[level] |= (1 << irq);
206 1.1.14.2 jdolecek --level;
207 1.1.14.2 jdolecek }
208 1.1.14.2 jdolecek }
209 1.1.14.2 jdolecek
210 1.1.14.2 jdolecek #include "sl.h"
211 1.1.14.2 jdolecek #include "ppp.h"
212 1.1.14.2 jdolecek #if NSL > 0 || NPPP > 0
213 1.1.14.2 jdolecek /* In the presence of SLIP or PPP, splimp > spltty. */
214 1.1.14.2 jdolecek irqmasks[IPL_NET] &= irqmasks[IPL_TTY];
215 1.1.14.2 jdolecek #endif
216 1.1.14.2 jdolecek }
217 1.1.14.2 jdolecek
218 1.1.14.2 jdolecek /*
219 1.1.14.2 jdolecek * We now need to update the irqblock array. This array indicates
220 1.1.14.2 jdolecek * what other interrupts should be blocked when interrupt is asserted
221 1.1.14.2 jdolecek * This basically emulates hardware interrupt priorities e.g. by
222 1.1.14.2 jdolecek * blocking all other IPL_BIO interrupts with an IPL_BIO interrupt
223 1.1.14.2 jdolecek * is asserted. For each interrupt we find the highest IPL and set
224 1.1.14.2 jdolecek * the block mask to the interrupt mask for that level.
225 1.1.14.2 jdolecek */
226 1.1.14.2 jdolecek
227 1.1.14.2 jdolecek for (loop = 0; loop < NIRQS; ++loop) {
228 1.1.14.2 jdolecek irqhandler_t *ptr;
229 1.1.14.2 jdolecek
230 1.1.14.2 jdolecek ptr = irqhandlers[loop];
231 1.1.14.2 jdolecek if (ptr) {
232 1.1.14.2 jdolecek /* There is at least 1 handler so scan the chain */
233 1.1.14.2 jdolecek level = ptr->ih_level;
234 1.1.14.2 jdolecek while (ptr) {
235 1.1.14.2 jdolecek if (ptr->ih_level > level)
236 1.1.14.2 jdolecek level = ptr->ih_level;
237 1.1.14.2 jdolecek ptr = ptr->ih_next;
238 1.1.14.2 jdolecek }
239 1.1.14.2 jdolecek irqblock[loop] = ~irqmasks[level];
240 1.1.14.2 jdolecek } else
241 1.1.14.2 jdolecek /* No handlers for this irq so nothing to block */
242 1.1.14.2 jdolecek irqblock[loop] = 0;
243 1.1.14.2 jdolecek }
244 1.1.14.2 jdolecek
245 1.1.14.2 jdolecek enable_irq(irq);
246 1.1.14.2 jdolecek set_spl_masks();
247 1.1.14.2 jdolecek
248 1.1.14.2 jdolecek return(0);
249 1.1.14.2 jdolecek }
250 1.1.14.2 jdolecek
251 1.1.14.2 jdolecek
252 1.1.14.2 jdolecek /*
253 1.1.14.2 jdolecek * int irq_release(int irq, irqhandler_t *handler)
254 1.1.14.2 jdolecek *
255 1.1.14.2 jdolecek * Disable an IRQ and remove a handler for it.
256 1.1.14.2 jdolecek */
257 1.1.14.2 jdolecek
258 1.1.14.2 jdolecek int
259 1.1.14.2 jdolecek irq_release(irq, handler)
260 1.1.14.2 jdolecek int irq;
261 1.1.14.2 jdolecek irqhandler_t *handler;
262 1.1.14.2 jdolecek {
263 1.1.14.2 jdolecek int level;
264 1.1.14.2 jdolecek int loop;
265 1.1.14.2 jdolecek irqhandler_t *irqhand;
266 1.1.14.2 jdolecek irqhandler_t **prehand;
267 1.1.14.2 jdolecek extern char *_intrnames;
268 1.1.14.2 jdolecek
269 1.1.14.2 jdolecek /*
270 1.1.14.2 jdolecek * IRQ_INSTRUCT indicates that we should get the irq number
271 1.1.14.2 jdolecek * from the irq structure
272 1.1.14.2 jdolecek */
273 1.1.14.2 jdolecek if (irq == IRQ_INSTRUCT)
274 1.1.14.2 jdolecek irq = handler->ih_num;
275 1.1.14.2 jdolecek
276 1.1.14.2 jdolecek /* Make sure the irq number is valid */
277 1.1.14.2 jdolecek if (irq < 0 || irq >= NIRQS)
278 1.1.14.2 jdolecek return(-1);
279 1.1.14.2 jdolecek
280 1.1.14.2 jdolecek /* Locate the handler */
281 1.1.14.2 jdolecek irqhand = irqhandlers[irq];
282 1.1.14.2 jdolecek prehand = &irqhandlers[irq];
283 1.1.14.2 jdolecek
284 1.1.14.2 jdolecek while (irqhand && handler != irqhand) {
285 1.1.14.2 jdolecek prehand = &irqhand;
286 1.1.14.2 jdolecek irqhand = irqhand->ih_next;
287 1.1.14.2 jdolecek }
288 1.1.14.2 jdolecek
289 1.1.14.2 jdolecek /* Remove the handler if located */
290 1.1.14.2 jdolecek if (irqhand)
291 1.1.14.2 jdolecek *prehand = irqhand->ih_next;
292 1.1.14.2 jdolecek else
293 1.1.14.2 jdolecek return(-1);
294 1.1.14.2 jdolecek
295 1.1.14.2 jdolecek /* Now the handler has been removed from the chain mark is as inactive */
296 1.1.14.2 jdolecek irqhand->ih_flags &= ~IRQ_FLAG_ACTIVE;
297 1.1.14.2 jdolecek
298 1.1.14.2 jdolecek /* Make sure the head of the handler list is active */
299 1.1.14.2 jdolecek if (irqhandlers[irq])
300 1.1.14.2 jdolecek irqhandlers[irq]->ih_flags |= IRQ_FLAG_ACTIVE;
301 1.1.14.2 jdolecek
302 1.1.14.2 jdolecek #ifdef IRQSTATS
303 1.1.14.2 jdolecek /* Get the interrupt name from the head of the list */
304 1.1.14.2 jdolecek if (irqhandlers[irq] && irqhandlers[irq]->ih_name) {
305 1.1.14.2 jdolecek char *ptr = _intrnames + (irq * 14);
306 1.1.14.2 jdolecek strcpy(ptr, " ");
307 1.1.14.2 jdolecek strncpy(ptr, irqhandlers[irq]->ih_name,
308 1.1.14.2 jdolecek min(strlen(irqhandlers[irq]->ih_name), 13));
309 1.1.14.2 jdolecek } else {
310 1.1.14.2 jdolecek char *ptr = _intrnames + (irq * 14);
311 1.1.14.2 jdolecek sprintf(ptr, "irq %2d ", irq);
312 1.1.14.2 jdolecek }
313 1.1.14.2 jdolecek #endif /* IRQSTATS */
314 1.1.14.2 jdolecek
315 1.1.14.2 jdolecek /*
316 1.1.14.2 jdolecek * Update the irq masks.
317 1.1.14.2 jdolecek * If ih_level is out of range then don't bother to update
318 1.1.14.2 jdolecek * the masks.
319 1.1.14.2 jdolecek */
320 1.1.14.2 jdolecek if (handler->ih_level >= 0 && handler->ih_level < IPL_LEVELS) {
321 1.1.14.2 jdolecek irqhandler_t *ptr;
322 1.1.14.2 jdolecek
323 1.1.14.2 jdolecek /* Clean the bit from all the masks */
324 1.1.14.2 jdolecek for (level = 0; level < IPL_LEVELS; ++level)
325 1.1.14.2 jdolecek irqmasks[level] &= ~(1 << irq);
326 1.1.14.2 jdolecek
327 1.1.14.2 jdolecek /*
328 1.1.14.2 jdolecek * Find the lowest interrupt priority on the irq chain.
329 1.1.14.2 jdolecek * Interrupt is allowable at priorities lower than this.
330 1.1.14.2 jdolecek */
331 1.1.14.2 jdolecek ptr = irqhandlers[irq];
332 1.1.14.2 jdolecek if (ptr) {
333 1.1.14.2 jdolecek level = ptr->ih_level - 1;
334 1.1.14.2 jdolecek while (ptr) {
335 1.1.14.2 jdolecek if (ptr->ih_level - 1 < level)
336 1.1.14.2 jdolecek level = ptr->ih_level - 1;
337 1.1.14.2 jdolecek ptr = ptr->ih_next;
338 1.1.14.2 jdolecek }
339 1.1.14.2 jdolecek while (level >= 0) {
340 1.1.14.2 jdolecek irqmasks[level] |= (1 << irq);
341 1.1.14.2 jdolecek --level;
342 1.1.14.2 jdolecek }
343 1.1.14.2 jdolecek }
344 1.1.14.2 jdolecek }
345 1.1.14.2 jdolecek
346 1.1.14.2 jdolecek /*
347 1.1.14.2 jdolecek * We now need to update the irqblock array. This array indicates
348 1.1.14.2 jdolecek * what other interrupts should be blocked when interrupt is asserted
349 1.1.14.2 jdolecek * This basically emulates hardware interrupt priorities e.g. by
350 1.1.14.2 jdolecek * blocking all other IPL_BIO interrupts with an IPL_BIO interrupt
351 1.1.14.2 jdolecek * is asserted. For each interrupt we find the highest IPL and set
352 1.1.14.2 jdolecek * the block mask to the interrupt mask for that level.
353 1.1.14.2 jdolecek */
354 1.1.14.2 jdolecek for (loop = 0; loop < NIRQS; ++loop) {
355 1.1.14.2 jdolecek irqhandler_t *ptr;
356 1.1.14.2 jdolecek
357 1.1.14.2 jdolecek ptr = irqhandlers[loop];
358 1.1.14.2 jdolecek if (ptr) {
359 1.1.14.2 jdolecek /* There is at least 1 handler so scan the chain */
360 1.1.14.2 jdolecek level = ptr->ih_level;
361 1.1.14.2 jdolecek while (ptr) {
362 1.1.14.2 jdolecek if (ptr->ih_level > level)
363 1.1.14.2 jdolecek level = ptr->ih_level;
364 1.1.14.2 jdolecek ptr = ptr->ih_next;
365 1.1.14.2 jdolecek }
366 1.1.14.2 jdolecek irqblock[loop] = ~irqmasks[level];
367 1.1.14.2 jdolecek } else
368 1.1.14.2 jdolecek /* No handlers for this irq so nothing to block */
369 1.1.14.2 jdolecek irqblock[loop] = 0;
370 1.1.14.2 jdolecek }
371 1.1.14.2 jdolecek
372 1.1.14.2 jdolecek /*
373 1.1.14.2 jdolecek * Disable the appropriate mask bit if there are no handlers left for
374 1.1.14.2 jdolecek * this IRQ.
375 1.1.14.2 jdolecek */
376 1.1.14.2 jdolecek if (irqhandlers[irq] == NULL)
377 1.1.14.2 jdolecek disable_irq(irq);
378 1.1.14.2 jdolecek
379 1.1.14.2 jdolecek set_spl_masks();
380 1.1.14.2 jdolecek
381 1.1.14.2 jdolecek return(0);
382 1.1.14.2 jdolecek }
383 1.1.14.2 jdolecek
384 1.1.14.2 jdolecek
385 1.1.14.2 jdolecek void *
386 1.1.14.2 jdolecek intr_claim(irq, level, name, ih_func, ih_arg)
387 1.1.14.2 jdolecek int irq;
388 1.1.14.2 jdolecek int level;
389 1.1.14.2 jdolecek const char *name;
390 1.1.14.2 jdolecek int (*ih_func) __P((void *));
391 1.1.14.2 jdolecek void *ih_arg;
392 1.1.14.2 jdolecek {
393 1.1.14.2 jdolecek irqhandler_t *ih;
394 1.1.14.2 jdolecek
395 1.1.14.2 jdolecek ih = malloc(sizeof(*ih), M_DEVBUF, M_NOWAIT);
396 1.1.14.2 jdolecek if (!ih)
397 1.1.14.2 jdolecek panic("intr_claim(): Cannot malloc handler memory\n");
398 1.1.14.2 jdolecek
399 1.1.14.2 jdolecek ih->ih_level = level;
400 1.1.14.2 jdolecek ih->ih_name = name;
401 1.1.14.2 jdolecek ih->ih_func = ih_func;
402 1.1.14.2 jdolecek ih->ih_arg = ih_arg;
403 1.1.14.2 jdolecek ih->ih_flags = 0;
404 1.1.14.2 jdolecek
405 1.1.14.2 jdolecek if (irq_claim(irq, ih) != 0)
406 1.1.14.2 jdolecek return(NULL);
407 1.1.14.2 jdolecek return(ih);
408 1.1.14.2 jdolecek }
409 1.1.14.2 jdolecek
410 1.1.14.2 jdolecek
411 1.1.14.2 jdolecek int
412 1.1.14.2 jdolecek intr_release(arg)
413 1.1.14.2 jdolecek void *arg;
414 1.1.14.2 jdolecek {
415 1.1.14.2 jdolecek irqhandler_t *ih = (irqhandler_t *)arg;
416 1.1.14.2 jdolecek
417 1.1.14.2 jdolecek if (irq_release(ih->ih_num, ih) == 0) {
418 1.1.14.2 jdolecek free(ih, M_DEVBUF);
419 1.1.14.2 jdolecek return(0);
420 1.1.14.2 jdolecek }
421 1.1.14.2 jdolecek return(1);
422 1.1.14.2 jdolecek }
423 1.1.14.2 jdolecek
424 1.1.14.2 jdolecek
425 1.1.14.2 jdolecek /*
426 1.1.14.2 jdolecek * void disable_irq(int irq)
427 1.1.14.2 jdolecek *
428 1.1.14.2 jdolecek * Disables a specific irq. The irq is removed from the master irq mask
429 1.1.14.2 jdolecek */
430 1.1.14.2 jdolecek
431 1.1.14.2 jdolecek void
432 1.1.14.2 jdolecek disable_irq(irq)
433 1.1.14.2 jdolecek int irq;
434 1.1.14.2 jdolecek {
435 1.1.14.2 jdolecek register int oldirqstate;
436 1.1.14.2 jdolecek
437 1.1.14.2 jdolecek oldirqstate = disable_interrupts(I32_bit);
438 1.1.14.2 jdolecek current_mask &= ~(1 << irq);
439 1.1.14.2 jdolecek irq_setmasks();
440 1.1.14.2 jdolecek restore_interrupts(oldirqstate);
441 1.1.14.2 jdolecek }
442 1.1.14.2 jdolecek
443 1.1.14.2 jdolecek
444 1.1.14.2 jdolecek /*
445 1.1.14.2 jdolecek * void enable_irq(int irq)
446 1.1.14.2 jdolecek *
447 1.1.14.2 jdolecek * Enables a specific irq. The irq is added to the master irq mask
448 1.1.14.2 jdolecek * This routine should be used with caution. A handler should already
449 1.1.14.2 jdolecek * be installed.
450 1.1.14.2 jdolecek */
451 1.1.14.2 jdolecek
452 1.1.14.2 jdolecek void
453 1.1.14.2 jdolecek enable_irq(irq)
454 1.1.14.2 jdolecek int irq;
455 1.1.14.2 jdolecek {
456 1.1.14.2 jdolecek register u_int oldirqstate;
457 1.1.14.2 jdolecek
458 1.1.14.2 jdolecek oldirqstate = disable_interrupts(I32_bit);
459 1.1.14.2 jdolecek current_mask |= (1 << irq);
460 1.1.14.2 jdolecek irq_setmasks();
461 1.1.14.2 jdolecek restore_interrupts(oldirqstate);
462 1.1.14.2 jdolecek }
463 1.1.14.2 jdolecek
464 1.1.14.2 jdolecek
465 1.1.14.2 jdolecek /*
466 1.1.14.2 jdolecek * void stray_irqhandler(u_int mask)
467 1.1.14.2 jdolecek *
468 1.1.14.2 jdolecek * Handler for stray interrupts. This gets called if a handler cannot be
469 1.1.14.2 jdolecek * found for an interrupt.
470 1.1.14.2 jdolecek */
471 1.1.14.2 jdolecek
472 1.1.14.2 jdolecek void
473 1.1.14.2 jdolecek stray_irqhandler(mask)
474 1.1.14.2 jdolecek u_int mask;
475 1.1.14.2 jdolecek {
476 1.1.14.2 jdolecek static u_int stray_irqs = 0;
477 1.1.14.2 jdolecek
478 1.1.14.2 jdolecek if (++stray_irqs <= 8)
479 1.1.14.2 jdolecek log(LOG_ERR, "Stray interrupt %08x%s\n", mask,
480 1.1.14.2 jdolecek stray_irqs >= 8 ? ": stopped logging" : "");
481 1.1.14.2 jdolecek }
482