]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/i386/isa/intr_machdep.c
Use the MI ithread helper functions in the x86 interrupt code.
[FreeBSD/FreeBSD.git] / sys / i386 / isa / intr_machdep.c
1 /*-
2  * Copyright (c) 1991 The Regents of the University of California.
3  * All rights reserved.
4  *
5  * This code is derived from software contributed to Berkeley by
6  * William Jolitz.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
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  * 3. All advertising materials mentioning features or use of this software
17  *    must display the following acknowledgement:
18  *      This product includes software developed by the University of
19  *      California, Berkeley and its contributors.
20  * 4. Neither the name of the University nor the names of its contributors
21  *    may be used to endorse or promote products derived from this software
22  *    without specific prior written permission.
23  *
24  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34  * SUCH DAMAGE.
35  *
36  *      from: @(#)isa.c 7.2 (Berkeley) 5/13/91
37  * $FreeBSD$
38  */
39
40 #include "opt_auto_eoi.h"
41 #include "opt_isa.h"
42 #include "opt_mca.h"
43
44 #include <sys/param.h>
45 #include <sys/bus.h>
46 #ifndef SMP
47 #include <machine/lock.h>
48 #endif
49 #include <sys/proc.h>
50 #include <sys/systm.h>
51 #include <sys/syslog.h>
52 #include <sys/ipl.h>
53 #include <sys/kernel.h>
54 #include <sys/kthread.h>
55 #include <sys/malloc.h>
56 #include <sys/module.h>
57 #include <sys/mutex.h>
58 #include <sys/unistd.h>
59 #include <sys/errno.h>
60 #include <sys/interrupt.h>
61 #include <machine/md_var.h>
62 #include <machine/segments.h>
63 #include <sys/bus.h> 
64
65 #if defined(APIC_IO)
66 #include <machine/smptests.h>                   /** FAST_HI */
67 #include <machine/smp.h>
68 #include <machine/resource.h>
69 #endif /* APIC_IO */
70 #ifdef PC98
71 #include <pc98/pc98/pc98.h>
72 #include <pc98/pc98/pc98_machdep.h>
73 #include <pc98/pc98/epsonio.h>
74 #else
75 #include <i386/isa/isa.h>
76 #endif
77 #include <i386/isa/icu.h>
78
79 #ifdef DEV_ISA
80 #include <isa/isavar.h>
81 #endif
82 #include <i386/isa/intr_machdep.h>
83 #include <sys/interrupt.h>
84 #ifdef APIC_IO
85 #include <machine/clock.h>
86 #endif
87
88 #ifdef DEV_MCA
89 #include <i386/isa/mca_machdep.h>
90 #endif
91
92 /*
93  * Per-interrupt data.
94  */
95 u_long  *intr_countp[ICU_LEN];          /* pointers to interrupt counters */
96 driver_intr_t   *intr_handler[ICU_LEN]; /* first level interrupt handler */
97 struct   ithd *ithds[ICU_LEN];          /* real interrupt handler */
98 void    *intr_unit[ICU_LEN];
99
100 static struct   mtx ithds_table_lock;   /* protect the ithds table */
101
102 static inthand_t *fastintr[ICU_LEN] = {
103         &IDTVEC(fastintr0), &IDTVEC(fastintr1),
104         &IDTVEC(fastintr2), &IDTVEC(fastintr3),
105         &IDTVEC(fastintr4), &IDTVEC(fastintr5),
106         &IDTVEC(fastintr6), &IDTVEC(fastintr7),
107         &IDTVEC(fastintr8), &IDTVEC(fastintr9),
108         &IDTVEC(fastintr10), &IDTVEC(fastintr11),
109         &IDTVEC(fastintr12), &IDTVEC(fastintr13),
110         &IDTVEC(fastintr14), &IDTVEC(fastintr15),
111 #if defined(APIC_IO)
112         &IDTVEC(fastintr16), &IDTVEC(fastintr17),
113         &IDTVEC(fastintr18), &IDTVEC(fastintr19),
114         &IDTVEC(fastintr20), &IDTVEC(fastintr21),
115         &IDTVEC(fastintr22), &IDTVEC(fastintr23),
116         &IDTVEC(fastintr24), &IDTVEC(fastintr25),
117         &IDTVEC(fastintr26), &IDTVEC(fastintr27),
118         &IDTVEC(fastintr28), &IDTVEC(fastintr29),
119         &IDTVEC(fastintr30), &IDTVEC(fastintr31),
120 #endif /* APIC_IO */
121 };
122
123 static inthand_t *slowintr[ICU_LEN] = {
124         &IDTVEC(intr0), &IDTVEC(intr1), &IDTVEC(intr2), &IDTVEC(intr3),
125         &IDTVEC(intr4), &IDTVEC(intr5), &IDTVEC(intr6), &IDTVEC(intr7),
126         &IDTVEC(intr8), &IDTVEC(intr9), &IDTVEC(intr10), &IDTVEC(intr11),
127         &IDTVEC(intr12), &IDTVEC(intr13), &IDTVEC(intr14), &IDTVEC(intr15),
128 #if defined(APIC_IO)
129         &IDTVEC(intr16), &IDTVEC(intr17), &IDTVEC(intr18), &IDTVEC(intr19),
130         &IDTVEC(intr20), &IDTVEC(intr21), &IDTVEC(intr22), &IDTVEC(intr23),
131         &IDTVEC(intr24), &IDTVEC(intr25), &IDTVEC(intr26), &IDTVEC(intr27),
132         &IDTVEC(intr28), &IDTVEC(intr29), &IDTVEC(intr30), &IDTVEC(intr31),
133 #endif /* APIC_IO */
134 };
135
136 static driver_intr_t isa_strayintr;
137
138 static void     ithds_init(void *dummy);
139 static void     ithread_enable(int vector);
140 static void     ithread_disable(int vector);
141
142 #ifdef PC98
143 #define NMI_PARITY 0x04
144 #define NMI_EPARITY 0x02
145 #else
146 #define NMI_PARITY (1 << 7)
147 #define NMI_IOCHAN (1 << 6)
148 #define ENMI_WATCHDOG (1 << 7)
149 #define ENMI_BUSTIMER (1 << 6)
150 #define ENMI_IOSTATUS (1 << 5)
151 #endif
152
153 /*
154  * Bus attachment for the ISA PIC.
155  */
156 static struct isa_pnp_id atpic_ids[] = {
157         { 0x0000d041 /* PNP0000 */, "AT interrupt controller" },
158         { 0 }
159 };
160
161 static int
162 atpic_probe(device_t dev)
163 {
164         int result;
165         
166         if ((result = ISA_PNP_PROBE(device_get_parent(dev), dev, atpic_ids)) <= 0)
167                 device_quiet(dev);
168         return(result);
169 }
170
171 /*
172  * In the APIC_IO case we might be granted IRQ 2, as this is typically
173  * consumed by chaining between the two PIC components.  If we're using
174  * the APIC, however, this may not be the case, and as such we should
175  * free the resource.  (XXX untested)
176  *
177  * The generic ISA attachment code will handle allocating any other resources
178  * that we don't explicitly claim here.
179  */
180 static int
181 atpic_attach(device_t dev)
182 {
183 #ifdef APIC_IO
184         int             rid;
185         struct resource *res;
186
187         /* try to allocate our IRQ and then free it */
188         rid = 0;
189         res = bus_alloc_resource(dev, SYS_RES_IRQ, &rid, 0, ~0, 1, 0);
190         if (res != NULL)
191                 bus_release_resource(dev, SYS_RES_IRQ, rid, res);
192 #endif
193         return(0);
194 }
195
196 static device_method_t atpic_methods[] = {
197         /* Device interface */
198         DEVMETHOD(device_probe,         atpic_probe),
199         DEVMETHOD(device_attach,        atpic_attach),
200         DEVMETHOD(device_detach,        bus_generic_detach),
201         DEVMETHOD(device_shutdown,      bus_generic_shutdown),
202         DEVMETHOD(device_suspend,       bus_generic_suspend),
203         DEVMETHOD(device_resume,        bus_generic_resume),
204         { 0, 0 }
205 };
206
207 static driver_t atpic_driver = {
208         "atpic",
209         atpic_methods,
210         1,              /* no softc */
211 };
212
213 static devclass_t atpic_devclass;
214
215 DRIVER_MODULE(atpic, isa, atpic_driver, atpic_devclass, 0, 0);
216
217 /*
218  * Handle a NMI, possibly a machine check.
219  * return true to panic system, false to ignore.
220  */
221 int
222 isa_nmi(cd)
223         int cd;
224 {
225         int retval = 0;
226 #ifdef PC98
227         int port = inb(0x33);
228
229         log(LOG_CRIT, "NMI PC98 port = %x\n", port);
230         if (epson_machine_id == 0x20)
231                 epson_outb(0xc16, epson_inb(0xc16) | 0x1);
232         if (port & NMI_PARITY) {
233                 log(LOG_CRIT, "BASE RAM parity error, likely hardware failure.");
234                 retval = 1;
235         } else if (port & NMI_EPARITY) {
236                 log(LOG_CRIT, "EXTENDED RAM parity error, likely hardware failure.");
237                 retval = 1;
238         } else {
239                 log(LOG_CRIT, "\nNMI Resume ??\n");
240         }
241 #else /* IBM-PC */
242         int isa_port = inb(0x61);
243         int eisa_port = inb(0x461);
244
245         log(LOG_CRIT, "NMI ISA %x, EISA %x\n", isa_port, eisa_port);
246 #ifdef DEV_MCA
247         if (MCA_system && mca_bus_nmi())
248                 return(0);
249 #endif
250         
251         if (isa_port & NMI_PARITY) {
252                 log(LOG_CRIT, "RAM parity error, likely hardware failure.");
253                 retval = 1;
254         }
255
256         if (isa_port & NMI_IOCHAN) {
257                 log(LOG_CRIT, "I/O channel check, likely hardware failure.");
258                 retval = 1;
259         }
260
261         /*
262          * On a real EISA machine, this will never happen.  However it can
263          * happen on ISA machines which implement XT style floating point
264          * error handling (very rare).  Save them from a meaningless panic.
265          */
266         if (eisa_port == 0xff)
267                 return(retval);
268
269         if (eisa_port & ENMI_WATCHDOG) {
270                 log(LOG_CRIT, "EISA watchdog timer expired, likely hardware failure.");
271                 retval = 1;
272         }
273
274         if (eisa_port & ENMI_BUSTIMER) {
275                 log(LOG_CRIT, "EISA bus timeout, likely hardware failure.");
276                 retval = 1;
277         }
278
279         if (eisa_port & ENMI_IOSTATUS) {
280                 log(LOG_CRIT, "EISA I/O port status error.");
281                 retval = 1;
282         }
283 #endif
284         return(retval);
285 }
286
287 /*
288  * Create a default interrupt table to avoid problems caused by
289  * spurious interrupts during configuration of kernel, then setup
290  * interrupt control unit.
291  */
292 void
293 isa_defaultirq()
294 {
295         int i;
296
297         /* icu vectors */
298         for (i = 0; i < ICU_LEN; i++)
299                 icu_unset(i, (driver_intr_t *)NULL);
300
301         /* initialize 8259's */
302 #ifdef DEV_MCA
303         if (MCA_system)
304                 outb(IO_ICU1, 0x19);            /* reset; program device, four bytes */
305         else
306 #endif
307                 outb(IO_ICU1, 0x11);            /* reset; program device, four bytes */
308
309         outb(IO_ICU1+ICU_IMR_OFFSET, NRSVIDT);  /* starting at this vector index */
310         outb(IO_ICU1+ICU_IMR_OFFSET, IRQ_SLAVE);                /* slave on line 7 */
311 #ifdef PC98
312 #ifdef AUTO_EOI_1
313         outb(IO_ICU1+ICU_IMR_OFFSET, 0x1f);             /* (master) auto EOI, 8086 mode */
314 #else
315         outb(IO_ICU1+ICU_IMR_OFFSET, 0x1d);             /* (master) 8086 mode */
316 #endif
317 #else /* IBM-PC */
318 #ifdef AUTO_EOI_1
319         outb(IO_ICU1+ICU_IMR_OFFSET, 2 | 1);            /* auto EOI, 8086 mode */
320 #else
321         outb(IO_ICU1+ICU_IMR_OFFSET, 1);                /* 8086 mode */
322 #endif
323 #endif /* PC98 */
324         outb(IO_ICU1+ICU_IMR_OFFSET, 0xff);             /* leave interrupts masked */
325         outb(IO_ICU1, 0x0a);            /* default to IRR on read */
326 #ifndef PC98
327         outb(IO_ICU1, 0xc0 | (3 - 1));  /* pri order 3-7, 0-2 (com2 first) */
328 #endif /* !PC98 */
329
330 #ifdef DEV_MCA
331         if (MCA_system)
332                 outb(IO_ICU2, 0x19);            /* reset; program device, four bytes */
333         else
334 #endif
335                 outb(IO_ICU2, 0x11);            /* reset; program device, four bytes */
336
337         outb(IO_ICU2+ICU_IMR_OFFSET, NRSVIDT+8); /* staring at this vector index */
338         outb(IO_ICU2+ICU_IMR_OFFSET, ICU_SLAVEID);         /* my slave id is 7 */
339 #ifdef PC98
340         outb(IO_ICU2+ICU_IMR_OFFSET,9);              /* 8086 mode */
341 #else /* IBM-PC */
342 #ifdef AUTO_EOI_2
343         outb(IO_ICU2+ICU_IMR_OFFSET, 2 | 1);            /* auto EOI, 8086 mode */
344 #else
345         outb(IO_ICU2+ICU_IMR_OFFSET,1);         /* 8086 mode */
346 #endif
347 #endif /* PC98 */
348         outb(IO_ICU2+ICU_IMR_OFFSET, 0xff);          /* leave interrupts masked */
349         outb(IO_ICU2, 0x0a);            /* default to IRR on read */
350 }
351
352 /*
353  * Caught a stray interrupt, notify
354  */
355 static void
356 isa_strayintr(vcookiep)
357         void *vcookiep;
358 {
359         int intr = (void **)vcookiep - &intr_unit[0];
360
361         /*
362          * XXX TODO print a different message for #7 if it is for a
363          * glitch.  Glitches can be distinguished from real #7's by
364          * testing that the in-service bit is _not_ set.  The test
365          * must be done before sending an EOI so it can't be done if
366          * we are using AUTO_EOI_1.
367          */
368         if (intrcnt[1 + intr] <= 5)
369                 log(LOG_ERR, "stray irq %d\n", intr);
370         if (intrcnt[1 + intr] == 5)
371                 log(LOG_CRIT,
372                     "too many stray irq %d's; not logging any more\n", intr);
373 }
374
375 #ifdef DEV_ISA
376 /*
377  * Return a bitmap of the current interrupt requests.  This is 8259-specific
378  * and is only suitable for use at probe time.
379  */
380 intrmask_t
381 isa_irq_pending()
382 {
383         u_char irr1;
384         u_char irr2;
385
386         irr1 = inb(IO_ICU1);
387         irr2 = inb(IO_ICU2);
388         return ((irr2 << 8) | irr1);
389 }
390 #endif
391
392 /*
393  * Update intrnames array with the specified name.  This is used by
394  * vmstat(8) and the like.
395  */
396 static void
397 update_intrname(int intr, const char *name)
398 {
399         char buf[32];
400         char *cp;
401         int name_index, off, strayintr;
402
403         /*
404          * Initialise strings for bitbucket and stray interrupt counters.
405          * These have statically allocated indices 0 and 1 through ICU_LEN.
406          */
407         if (intrnames[0] == '\0') {
408                 off = sprintf(intrnames, "???") + 1;
409                 for (strayintr = 0; strayintr < ICU_LEN; strayintr++)
410                         off += sprintf(intrnames + off, "stray irq%d",
411                             strayintr) + 1;
412         }
413
414         if (name == NULL)
415                 name = "???";
416         if (snprintf(buf, sizeof(buf), "%s irq%d", name, intr) >= sizeof(buf))
417                 goto use_bitbucket;
418
419         /*
420          * Search for `buf' in `intrnames'.  In the usual case when it is
421          * not found, append it to the end if there is enough space (the \0
422          * terminator for the previous string, if any, becomes a separator).
423          */
424         for (cp = intrnames, name_index = 0;
425             cp != eintrnames && name_index < NR_INTRNAMES;
426             cp += strlen(cp) + 1, name_index++) {
427                 if (*cp == '\0') {
428                         if (strlen(buf) >= eintrnames - cp)
429                                 break;
430                         strcpy(cp, buf);
431                         goto found;
432                 }
433                 if (strcmp(cp, buf) == 0)
434                         goto found;
435         }
436
437 use_bitbucket:
438         printf("update_intrname: counting %s irq%d as %s\n", name, intr,
439             intrnames);
440         name_index = 0;
441 found:
442         intr_countp[intr] = &intrcnt[name_index];
443 }
444
445 int
446 icu_setup(int intr, driver_intr_t *handler, void *arg, int flags)
447 {
448 #ifdef FAST_HI
449         int             select;         /* the select register is 8 bits */
450         int             vector;
451         u_int32_t       value;          /* the window register is 32 bits */
452 #endif /* FAST_HI */
453         u_long  ef;
454
455 #if defined(APIC_IO)
456         if ((u_int)intr >= ICU_LEN)     /* no 8259 SLAVE to ignore */
457 #else
458         if ((u_int)intr >= ICU_LEN || intr == ICU_SLAVEID)
459 #endif /* APIC_IO */
460         if (intr_handler[intr] != isa_strayintr)
461                 return (EBUSY);
462
463         ef = read_eflags();
464         disable_intr();
465         intr_handler[intr] = handler;
466         intr_unit[intr] = arg;
467 #ifdef FAST_HI
468         if (flags & INTR_FAST) {
469                 vector = TPR_FAST_INTS + intr;
470                 setidt(vector, fastintr[intr],
471                        SDT_SYS386IGT, SEL_KPL, GSEL(GCODE_SEL, SEL_KPL));
472         }
473         else {
474                 vector = TPR_SLOW_INTS + intr;
475 #ifdef APIC_INTR_REORDER
476 #ifdef APIC_INTR_HIGHPRI_CLOCK
477                 /* XXX: Hack (kludge?) for more accurate clock. */
478                 if (intr == apic_8254_intr || intr == 8) {
479                         vector = TPR_FAST_INTS + intr;
480                 }
481 #endif
482 #endif
483                 setidt(vector, slowintr[intr],
484                        SDT_SYS386IGT, SEL_KPL, GSEL(GCODE_SEL, SEL_KPL));
485         }
486 #ifdef APIC_INTR_REORDER
487         set_lapic_isrloc(intr, vector);
488 #endif
489         /*
490          * Reprogram the vector in the IO APIC.
491          */
492         if (int_to_apicintpin[intr].ioapic >= 0) {
493                 select = int_to_apicintpin[intr].redirindex;
494                 value = io_apic_read(int_to_apicintpin[intr].ioapic, 
495                                      select) & ~IOART_INTVEC;
496                 io_apic_write(int_to_apicintpin[intr].ioapic, 
497                               select, value | vector);
498         }
499 #else
500         setidt(ICU_OFFSET + intr,
501                flags & INTR_FAST ? fastintr[intr] : slowintr[intr],
502                SDT_SYS386IGT, SEL_KPL, GSEL(GCODE_SEL, SEL_KPL));
503 #endif /* FAST_HI */
504         INTREN(1 << intr);
505         write_eflags(ef);
506         return (0);
507 }
508
509 /*
510  * Dissociate an interrupt handler from an IRQ and set the handler to
511  * the stray interrupt handler.  The 'handler' parameter is used only
512  * for consistency checking.
513  */
514 int
515 icu_unset(intr, handler)
516         int     intr;
517         driver_intr_t *handler;
518 {
519         u_long  ef;
520
521         if ((u_int)intr >= ICU_LEN || handler != intr_handler[intr])
522                 return (EINVAL);
523
524         INTRDIS(1 << intr);
525         ef = read_eflags();
526         disable_intr();
527         intr_countp[intr] = &intrcnt[1 + intr];
528         intr_handler[intr] = isa_strayintr;
529         intr_unit[intr] = &intr_unit[intr];
530 #ifdef FAST_HI_XXX
531         /* XXX how do I re-create dvp here? */
532         setidt(flags & INTR_FAST ? TPR_FAST_INTS + intr : TPR_SLOW_INTS + intr,
533             slowintr[intr], SDT_SYS386IGT, SEL_KPL, GSEL(GCODE_SEL, SEL_KPL));
534 #else /* FAST_HI */
535 #ifdef APIC_INTR_REORDER
536         set_lapic_isrloc(intr, ICU_OFFSET + intr);
537 #endif
538         setidt(ICU_OFFSET + intr, slowintr[intr], SDT_SYS386IGT, SEL_KPL,
539             GSEL(GCODE_SEL, SEL_KPL));
540 #endif /* FAST_HI */
541         write_eflags(ef);
542         return (0);
543 }
544
545 static void
546 ithds_init(void *dummy)
547 {
548
549         mtx_init(&ithds_table_lock, "ithread table lock", MTX_SPIN);
550 }
551 SYSINIT(ithds_init, SI_SUB_INTR, SI_ORDER_SECOND, ithds_init, NULL);
552
553 static void
554 ithread_enable(int vector)
555 {
556
557         INTREN(1 << vector);
558 }
559
560 static void
561 ithread_disable(int vector)
562 {
563
564         INTRDIS(1 << vector);
565 }
566
567 int
568 inthand_add(const char *name, int irq, driver_intr_t handler, void *arg,
569     enum intr_type flags, void **cookiep)
570 {
571         struct ithd *ithd;              /* descriptor for the IRQ */
572         int errcode = 0;
573         int created_ithd = 0;
574
575         /*
576          * Work around a race where more than one CPU may be registering
577          * handlers on the same IRQ at the same time.
578          */
579         mtx_lock_spin(&ithds_table_lock);
580         ithd = ithds[irq];
581         mtx_unlock_spin(&ithds_table_lock);
582         if (ithd == NULL) {
583                 errcode = ithread_create(&ithd, irq, 0, ithread_disable,
584                     ithread_enable, "irq%d:", irq);
585                 if (errcode)
586                         return (errcode);
587                 mtx_lock_spin(&ithds_table_lock);
588                 if (ithds[irq] == NULL) {
589                         ithds[irq] = ithd;
590                         created_ithd++;
591                         mtx_unlock_spin(&ithds_table_lock);
592                 } else {
593                         struct ithd *orphan;
594
595                         orphan = ithd;
596                         ithd = ithds[irq];
597                         mtx_unlock_spin(&ithds_table_lock);
598                         ithread_destroy(orphan);
599                 }
600         }
601
602         errcode = ithread_add_handler(ithd, name, handler, arg,
603             ithread_priority(flags), flags, cookiep);
604         
605         if ((flags & INTR_FAST) == 0 || errcode)
606                 /*
607                  * The interrupt process must be in place, but
608                  * not necessarily schedulable, before we
609                  * initialize the ICU, since it may cause an
610                  * immediate interrupt.
611                  */
612                 if (icu_setup(irq, &sched_ithd, arg, flags) != 0)
613                         panic("inthand_add: Can't initialize ICU");
614
615         if (errcode)
616                 return (errcode);
617         
618         if (flags & INTR_FAST) {
619                 errcode = icu_setup(irq, handler, arg, flags);
620                 if (errcode && bootverbose)
621                         printf("\tinthand_add(irq%d) failed, result=%d\n", 
622                                irq, errcode);
623                 if (errcode)
624                         return (errcode);
625         }
626
627         update_intrname(irq, name);
628         return (0);
629 }
630
631 /*
632  * Deactivate and remove linked list the interrupt handler descriptor
633  * data connected created by an earlier call of inthand_add(), then
634  * adjust the interrupt masks if necessary.
635  *
636  * Return the memory held by the interrupt handler descriptor data
637  * structure to the system.  First ensure the handler is not actively
638  * in use.
639  */
640 int
641 inthand_remove(void *cookie)
642 {
643
644         return (ithread_remove_handler(cookie));
645 }