1997-06-02 08:19:06 +00:00
|
|
|
/*-
|
|
|
|
* Copyright (c) 1991 The Regents of the University of California.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This code is derived from software contributed to Berkeley by
|
|
|
|
* William Jolitz.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed by the University of
|
|
|
|
* California, Berkeley and its contributors.
|
|
|
|
* 4. Neither the name of the University nor the names of its contributors
|
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
* from: @(#)isa.c 7.2 (Berkeley) 5/13/91
|
1999-08-28 01:08:13 +00:00
|
|
|
* $FreeBSD$
|
1999-04-21 07:26:30 +00:00
|
|
|
*/
|
1997-06-02 08:19:06 +00:00
|
|
|
|
2001-01-29 09:38:39 +00:00
|
|
|
#include "opt_isa.h"
|
1999-12-26 16:21:19 +00:00
|
|
|
|
1997-06-02 08:19:06 +00:00
|
|
|
#include <sys/param.h>
|
2001-05-01 08:13:21 +00:00
|
|
|
#include <sys/bus.h>
|
|
|
|
#include <sys/errno.h>
|
|
|
|
#include <sys/interrupt.h>
|
2000-06-23 07:44:33 +00:00
|
|
|
#include <sys/kernel.h>
|
2000-09-07 01:33:02 +00:00
|
|
|
#include <sys/kthread.h>
|
2001-05-01 08:13:21 +00:00
|
|
|
#include <sys/lock.h>
|
1999-04-21 07:26:30 +00:00
|
|
|
#include <sys/malloc.h>
|
2000-06-23 07:44:33 +00:00
|
|
|
#include <sys/module.h>
|
2000-10-20 07:46:12 +00:00
|
|
|
#include <sys/mutex.h>
|
2001-05-01 08:13:21 +00:00
|
|
|
#include <sys/proc.h>
|
|
|
|
#include <sys/syslog.h>
|
|
|
|
#include <sys/systm.h>
|
2000-09-07 01:33:02 +00:00
|
|
|
#include <sys/unistd.h>
|
2001-05-01 08:13:21 +00:00
|
|
|
|
1997-06-02 08:19:06 +00:00
|
|
|
#include <machine/md_var.h>
|
|
|
|
#include <machine/segments.h>
|
1999-04-21 07:26:30 +00:00
|
|
|
|
2003-05-01 01:05:25 +00:00
|
|
|
#include <amd64/isa/isa.h>
|
|
|
|
#include <amd64/isa/icu.h>
|
1997-06-02 08:19:06 +00:00
|
|
|
|
2001-01-29 09:38:39 +00:00
|
|
|
#ifdef DEV_ISA
|
1999-04-21 07:26:30 +00:00
|
|
|
#include <isa/isavar.h>
|
1999-12-26 16:21:19 +00:00
|
|
|
#endif
|
2003-05-01 01:05:25 +00:00
|
|
|
#include <amd64/isa/intr_machdep.h>
|
1997-06-02 08:19:06 +00:00
|
|
|
#include <sys/interrupt.h>
|
1999-09-03 02:04:28 +00:00
|
|
|
|
1997-06-02 08:19:06 +00:00
|
|
|
/*
|
2000-10-05 23:09:57 +00:00
|
|
|
* Per-interrupt data.
|
1997-06-02 08:19:06 +00:00
|
|
|
*/
|
2000-10-05 23:09:57 +00:00
|
|
|
u_long *intr_countp[ICU_LEN]; /* pointers to interrupt counters */
|
2001-02-09 17:47:44 +00:00
|
|
|
driver_intr_t *intr_handler[ICU_LEN]; /* first level interrupt handler */
|
|
|
|
struct ithd *ithds[ICU_LEN]; /* real interrupt handler */
|
2000-10-05 23:09:57 +00:00
|
|
|
void *intr_unit[ICU_LEN];
|
1997-06-02 08:19:06 +00:00
|
|
|
|
2001-02-09 17:47:44 +00:00
|
|
|
static struct mtx ithds_table_lock; /* protect the ithds table */
|
|
|
|
|
1997-06-02 08:19:06 +00:00
|
|
|
static inthand_t *fastintr[ICU_LEN] = {
|
2002-10-20 18:02:46 +00:00
|
|
|
IDTVEC(fastintr0), IDTVEC(fastintr1),
|
|
|
|
IDTVEC(fastintr2), IDTVEC(fastintr3),
|
|
|
|
IDTVEC(fastintr4), IDTVEC(fastintr5),
|
|
|
|
IDTVEC(fastintr6), IDTVEC(fastintr7),
|
|
|
|
IDTVEC(fastintr8), IDTVEC(fastintr9),
|
|
|
|
IDTVEC(fastintr10), IDTVEC(fastintr11),
|
|
|
|
IDTVEC(fastintr12), IDTVEC(fastintr13),
|
|
|
|
IDTVEC(fastintr14), IDTVEC(fastintr15),
|
2002-03-27 05:39:23 +00:00
|
|
|
};
|
|
|
|
|
1997-06-02 08:19:06 +00:00
|
|
|
static inthand_t *slowintr[ICU_LEN] = {
|
2002-10-20 18:02:46 +00:00
|
|
|
IDTVEC(intr0), IDTVEC(intr1), IDTVEC(intr2), IDTVEC(intr3),
|
|
|
|
IDTVEC(intr4), IDTVEC(intr5), IDTVEC(intr6), IDTVEC(intr7),
|
|
|
|
IDTVEC(intr8), IDTVEC(intr9), IDTVEC(intr10), IDTVEC(intr11),
|
|
|
|
IDTVEC(intr12), IDTVEC(intr13), IDTVEC(intr14), IDTVEC(intr15),
|
1997-06-02 08:19:06 +00:00
|
|
|
};
|
|
|
|
|
2000-09-13 18:33:25 +00:00
|
|
|
static driver_intr_t isa_strayintr;
|
1997-06-02 08:19:06 +00:00
|
|
|
|
2001-02-09 17:47:44 +00:00
|
|
|
static void ithds_init(void *dummy);
|
|
|
|
static void ithread_enable(int vector);
|
|
|
|
static void ithread_disable(int vector);
|
2001-07-20 06:07:34 +00:00
|
|
|
static void init_i8259(void);
|
2001-02-09 17:47:44 +00:00
|
|
|
|
1997-06-02 08:19:06 +00:00
|
|
|
#define NMI_PARITY (1 << 7)
|
|
|
|
#define NMI_IOCHAN (1 << 6)
|
|
|
|
#define ENMI_WATCHDOG (1 << 7)
|
|
|
|
#define ENMI_BUSTIMER (1 << 6)
|
|
|
|
#define ENMI_IOSTATUS (1 << 5)
|
|
|
|
|
2002-01-30 12:41:12 +00:00
|
|
|
#ifdef DEV_ISA
|
2000-06-23 07:44:33 +00:00
|
|
|
/*
|
|
|
|
* Bus attachment for the ISA PIC.
|
|
|
|
*/
|
|
|
|
static struct isa_pnp_id atpic_ids[] = {
|
|
|
|
{ 0x0000d041 /* PNP0000 */, "AT interrupt controller" },
|
|
|
|
{ 0 }
|
|
|
|
};
|
|
|
|
|
|
|
|
static int
|
|
|
|
atpic_probe(device_t dev)
|
|
|
|
{
|
|
|
|
int result;
|
|
|
|
|
|
|
|
if ((result = ISA_PNP_PROBE(device_get_parent(dev), dev, atpic_ids)) <= 0)
|
|
|
|
device_quiet(dev);
|
|
|
|
return(result);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The generic ISA attachment code will handle allocating any other resources
|
|
|
|
* that we don't explicitly claim here.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
atpic_attach(device_t dev)
|
|
|
|
{
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static device_method_t atpic_methods[] = {
|
|
|
|
/* Device interface */
|
|
|
|
DEVMETHOD(device_probe, atpic_probe),
|
|
|
|
DEVMETHOD(device_attach, atpic_attach),
|
|
|
|
DEVMETHOD(device_detach, bus_generic_detach),
|
|
|
|
DEVMETHOD(device_shutdown, bus_generic_shutdown),
|
|
|
|
DEVMETHOD(device_suspend, bus_generic_suspend),
|
|
|
|
DEVMETHOD(device_resume, bus_generic_resume),
|
|
|
|
{ 0, 0 }
|
|
|
|
};
|
|
|
|
|
|
|
|
static driver_t atpic_driver = {
|
|
|
|
"atpic",
|
|
|
|
atpic_methods,
|
|
|
|
1, /* no softc */
|
|
|
|
};
|
|
|
|
|
|
|
|
static devclass_t atpic_devclass;
|
|
|
|
|
|
|
|
DRIVER_MODULE(atpic, isa, atpic_driver, atpic_devclass, 0, 0);
|
2001-08-30 09:17:03 +00:00
|
|
|
DRIVER_MODULE(atpic, acpi, atpic_driver, atpic_devclass, 0, 0);
|
2002-01-30 12:41:12 +00:00
|
|
|
#endif /* DEV_ISA */
|
2000-06-23 07:44:33 +00:00
|
|
|
|
1997-06-02 08:19:06 +00:00
|
|
|
/*
|
|
|
|
* Handle a NMI, possibly a machine check.
|
|
|
|
* return true to panic system, false to ignore.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
isa_nmi(cd)
|
|
|
|
int cd;
|
|
|
|
{
|
2000-08-06 14:17:21 +00:00
|
|
|
int retval = 0;
|
1997-06-02 08:19:06 +00:00
|
|
|
int isa_port = inb(0x61);
|
1997-09-28 15:48:34 +00:00
|
|
|
|
2003-05-01 01:05:25 +00:00
|
|
|
log(LOG_CRIT, "NMI ISA STATUS 0x%02x", isa_port);
|
1999-09-03 02:04:28 +00:00
|
|
|
|
2000-08-06 14:17:21 +00:00
|
|
|
if (isa_port & NMI_PARITY) {
|
|
|
|
log(LOG_CRIT, "RAM parity error, likely hardware failure.");
|
|
|
|
retval = 1;
|
|
|
|
}
|
1997-09-28 15:48:34 +00:00
|
|
|
|
2000-08-06 14:17:21 +00:00
|
|
|
if (isa_port & NMI_IOCHAN) {
|
|
|
|
log(LOG_CRIT, "I/O channel check, likely hardware failure.");
|
|
|
|
retval = 1;
|
|
|
|
}
|
1997-09-28 15:48:34 +00:00
|
|
|
|
2003-05-01 01:05:25 +00:00
|
|
|
return (retval);
|
1997-06-02 08:19:06 +00:00
|
|
|
}
|
|
|
|
|
2001-07-20 06:07:34 +00:00
|
|
|
/*
|
|
|
|
* ICU reinitialize when ICU configuration has lost.
|
|
|
|
*/
|
|
|
|
void icu_reinit()
|
|
|
|
{
|
|
|
|
int i;
|
2002-03-27 05:39:23 +00:00
|
|
|
register_t crit;
|
2001-12-20 23:48:31 +00:00
|
|
|
|
2002-03-27 05:39:23 +00:00
|
|
|
crit = intr_disable();
|
2001-12-20 23:48:31 +00:00
|
|
|
mtx_lock_spin(&icu_lock);
|
2001-07-20 06:07:34 +00:00
|
|
|
init_i8259();
|
|
|
|
for(i=0;i<ICU_LEN;i++)
|
|
|
|
if(intr_handler[i] != isa_strayintr)
|
|
|
|
INTREN(1<<i);
|
2001-12-20 23:48:31 +00:00
|
|
|
mtx_unlock_spin(&icu_lock);
|
2002-03-27 05:39:23 +00:00
|
|
|
intr_restore(crit);
|
2001-07-20 06:07:34 +00:00
|
|
|
}
|
|
|
|
|
1997-06-02 08:19:06 +00:00
|
|
|
/*
|
2000-09-07 01:33:02 +00:00
|
|
|
* Create a default interrupt table to avoid problems caused by
|
|
|
|
* spurious interrupts during configuration of kernel, then setup
|
|
|
|
* interrupt control unit.
|
1997-06-02 08:19:06 +00:00
|
|
|
*/
|
|
|
|
void
|
|
|
|
isa_defaultirq()
|
|
|
|
{
|
|
|
|
int i;
|
2002-03-27 05:39:23 +00:00
|
|
|
register_t crit;
|
1997-06-02 08:19:06 +00:00
|
|
|
|
|
|
|
/* icu vectors */
|
|
|
|
for (i = 0; i < ICU_LEN; i++)
|
2000-09-13 18:33:25 +00:00
|
|
|
icu_unset(i, (driver_intr_t *)NULL);
|
2002-03-27 05:39:23 +00:00
|
|
|
crit = intr_disable();
|
2001-12-20 23:48:31 +00:00
|
|
|
mtx_lock_spin(&icu_lock);
|
2001-07-20 06:07:34 +00:00
|
|
|
init_i8259();
|
2001-12-20 23:48:31 +00:00
|
|
|
mtx_unlock_spin(&icu_lock);
|
2002-03-27 05:39:23 +00:00
|
|
|
intr_restore(crit);
|
2001-07-20 06:07:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
*initialize 8259's
|
|
|
|
*/
|
|
|
|
static void init_i8259()
|
|
|
|
{
|
1997-06-02 08:19:06 +00:00
|
|
|
|
2003-05-01 01:05:25 +00:00
|
|
|
outb(IO_ICU1, ICW1_RESET | ICW1_IC4); /* reset; program device, four bytes */
|
1997-06-02 15:28:10 +00:00
|
|
|
|
|
|
|
outb(IO_ICU1+ICU_IMR_OFFSET, NRSVIDT); /* starting at this vector index */
|
2003-05-01 01:05:25 +00:00
|
|
|
outb(IO_ICU1+ICU_IMR_OFFSET, IRQ_SLAVE);/* slave on line 2 */
|
|
|
|
outb(IO_ICU1+ICU_IMR_OFFSET, ICW4_8086);/* 8086 mode */
|
|
|
|
outb(IO_ICU1+ICU_IMR_OFFSET, 0xff); /* leave interrupts masked */
|
|
|
|
outb(IO_ICU1, OCW3_SEL | OCW3_RIS); /* default to IRR on read */
|
|
|
|
outb(IO_ICU1, ICU_SETPRI | 0x2);/* pri order 3-7, 0-2 (com2 first) */
|
|
|
|
|
|
|
|
outb(IO_ICU2, ICW1_RESET | ICW1_IC4); /* reset; program device, four bytes */
|
1999-09-03 02:04:28 +00:00
|
|
|
|
1997-06-02 15:28:10 +00:00
|
|
|
outb(IO_ICU2+ICU_IMR_OFFSET, NRSVIDT+8); /* staring at this vector index */
|
2003-05-01 01:05:25 +00:00
|
|
|
outb(IO_ICU2+ICU_IMR_OFFSET, ICU_SLAVEID); /* my slave id is 2 */
|
|
|
|
outb(IO_ICU2+ICU_IMR_OFFSET, ICW4_8086); /* 8086 mode */
|
|
|
|
outb(IO_ICU2+ICU_IMR_OFFSET, 0xff); /* leave interrupts masked */
|
|
|
|
outb(IO_ICU2, OCW3_SEL | OCW3_RIS); /* default to IRR on read */
|
1997-06-02 08:19:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Caught a stray interrupt, notify
|
|
|
|
*/
|
2003-05-01 01:05:25 +00:00
|
|
|
static int isaglitch7;
|
|
|
|
static int isaglitch15;
|
|
|
|
|
1997-06-02 08:19:06 +00:00
|
|
|
static void
|
1998-06-18 16:08:46 +00:00
|
|
|
isa_strayintr(vcookiep)
|
|
|
|
void *vcookiep;
|
1997-06-02 08:19:06 +00:00
|
|
|
{
|
1998-06-18 16:08:46 +00:00
|
|
|
int intr = (void **)vcookiep - &intr_unit[0];
|
2003-05-01 01:05:25 +00:00
|
|
|
int isr;
|
|
|
|
|
|
|
|
/* Determine if it is a stray interrupt or simply a glitch */
|
|
|
|
if (intr == 7) {
|
|
|
|
outb(IO_ICU1, OCW3_SEL); /* select IS register */
|
|
|
|
isr = inb(IO_ICU1);
|
|
|
|
outb(IO_ICU1, OCW3_SEL | OCW3_RIS); /* reselect IIR */
|
|
|
|
if ((isr & 0x80) == 0) {
|
|
|
|
isaglitch7++;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (intr == 15) {
|
|
|
|
outb(IO_ICU2, OCW3_SEL); /* select IS register */
|
|
|
|
isr = inb(IO_ICU2);
|
|
|
|
outb(IO_ICU2, OCW3_SEL | OCW3_RIS); /* reselect IIR */
|
|
|
|
if ((isr & 0x80) == 0) {
|
|
|
|
isaglitch15++;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
1999-04-14 14:26:36 +00:00
|
|
|
if (intrcnt[1 + intr] <= 5)
|
1998-06-18 16:08:46 +00:00
|
|
|
log(LOG_ERR, "stray irq %d\n", intr);
|
1999-04-14 14:26:36 +00:00
|
|
|
if (intrcnt[1 + intr] == 5)
|
1997-06-02 08:19:06 +00:00
|
|
|
log(LOG_CRIT,
|
1998-06-18 16:08:46 +00:00
|
|
|
"too many stray irq %d's; not logging any more\n", intr);
|
1997-06-02 08:19:06 +00:00
|
|
|
}
|
|
|
|
|
2001-01-29 09:38:39 +00:00
|
|
|
#ifdef DEV_ISA
|
1997-06-02 08:19:06 +00:00
|
|
|
/*
|
1998-05-31 10:53:55 +00:00
|
|
|
* Return a bitmap of the current interrupt requests. This is 8259-specific
|
|
|
|
* and is only suitable for use at probe time.
|
1997-06-02 08:19:06 +00:00
|
|
|
*/
|
1998-05-31 10:53:55 +00:00
|
|
|
intrmask_t
|
|
|
|
isa_irq_pending()
|
1997-06-02 08:19:06 +00:00
|
|
|
{
|
1998-05-31 10:53:55 +00:00
|
|
|
u_char irr1;
|
|
|
|
u_char irr2;
|
1997-06-02 08:19:06 +00:00
|
|
|
|
1998-05-31 10:53:55 +00:00
|
|
|
irr1 = inb(IO_ICU1);
|
|
|
|
irr2 = inb(IO_ICU2);
|
|
|
|
return ((irr2 << 8) | irr1);
|
1997-06-02 08:19:06 +00:00
|
|
|
}
|
1999-12-26 16:21:19 +00:00
|
|
|
#endif
|
1997-06-02 08:19:06 +00:00
|
|
|
|
2000-09-07 01:33:02 +00:00
|
|
|
/*
|
|
|
|
* Update intrnames array with the specified name. This is used by
|
|
|
|
* vmstat(8) and the like.
|
|
|
|
*/
|
1999-04-21 07:26:30 +00:00
|
|
|
static void
|
2001-02-09 17:47:44 +00:00
|
|
|
update_intrname(int intr, const char *name)
|
1997-06-02 08:19:06 +00:00
|
|
|
{
|
1999-04-14 14:26:36 +00:00
|
|
|
char buf[32];
|
|
|
|
char *cp;
|
|
|
|
int name_index, off, strayintr;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Initialise strings for bitbucket and stray interrupt counters.
|
|
|
|
* These have statically allocated indices 0 and 1 through ICU_LEN.
|
|
|
|
*/
|
|
|
|
if (intrnames[0] == '\0') {
|
|
|
|
off = sprintf(intrnames, "???") + 1;
|
|
|
|
for (strayintr = 0; strayintr < ICU_LEN; strayintr++)
|
|
|
|
off += sprintf(intrnames + off, "stray irq%d",
|
|
|
|
strayintr) + 1;
|
|
|
|
}
|
|
|
|
|
1999-04-21 07:26:30 +00:00
|
|
|
if (name == NULL)
|
|
|
|
name = "???";
|
1999-04-14 14:26:36 +00:00
|
|
|
if (snprintf(buf, sizeof(buf), "%s irq%d", name, intr) >= sizeof(buf))
|
|
|
|
goto use_bitbucket;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Search for `buf' in `intrnames'. In the usual case when it is
|
|
|
|
* not found, append it to the end if there is enough space (the \0
|
|
|
|
* terminator for the previous string, if any, becomes a separator).
|
|
|
|
*/
|
|
|
|
for (cp = intrnames, name_index = 0;
|
|
|
|
cp != eintrnames && name_index < NR_INTRNAMES;
|
|
|
|
cp += strlen(cp) + 1, name_index++) {
|
|
|
|
if (*cp == '\0') {
|
|
|
|
if (strlen(buf) >= eintrnames - cp)
|
|
|
|
break;
|
|
|
|
strcpy(cp, buf);
|
|
|
|
goto found;
|
|
|
|
}
|
|
|
|
if (strcmp(cp, buf) == 0)
|
|
|
|
goto found;
|
1997-06-02 08:19:06 +00:00
|
|
|
}
|
|
|
|
|
1999-04-14 14:26:36 +00:00
|
|
|
use_bitbucket:
|
|
|
|
printf("update_intrname: counting %s irq%d as %s\n", name, intr,
|
|
|
|
intrnames);
|
|
|
|
name_index = 0;
|
|
|
|
found:
|
|
|
|
intr_countp[intr] = &intrcnt[name_index];
|
|
|
|
}
|
1997-06-02 08:19:06 +00:00
|
|
|
|
|
|
|
int
|
2000-09-13 18:33:25 +00:00
|
|
|
icu_setup(int intr, driver_intr_t *handler, void *arg, int flags)
|
1997-06-02 08:19:06 +00:00
|
|
|
{
|
2002-03-27 05:39:23 +00:00
|
|
|
register_t crit;
|
1997-06-02 08:19:06 +00:00
|
|
|
|
1997-06-02 15:28:10 +00:00
|
|
|
if ((u_int)intr >= ICU_LEN || intr == ICU_SLAVEID)
|
2001-09-27 02:46:47 +00:00
|
|
|
return (EINVAL);
|
2001-09-27 19:03:52 +00:00
|
|
|
#if 0
|
1997-06-02 08:19:06 +00:00
|
|
|
if (intr_handler[intr] != isa_strayintr)
|
|
|
|
return (EBUSY);
|
2001-09-27 19:03:52 +00:00
|
|
|
#endif
|
1997-06-02 08:19:06 +00:00
|
|
|
|
2002-03-27 05:39:23 +00:00
|
|
|
crit = intr_disable();
|
2001-12-20 23:48:31 +00:00
|
|
|
mtx_lock_spin(&icu_lock);
|
1997-06-02 08:19:06 +00:00
|
|
|
intr_handler[intr] = handler;
|
1998-06-18 15:32:09 +00:00
|
|
|
intr_unit[intr] = arg;
|
1997-06-02 08:19:06 +00:00
|
|
|
setidt(ICU_OFFSET + intr,
|
|
|
|
flags & INTR_FAST ? fastintr[intr] : slowintr[intr],
|
2003-05-01 01:05:25 +00:00
|
|
|
SDT_SYSIGT, SEL_KPL, 0);
|
1997-06-02 08:19:06 +00:00
|
|
|
INTREN(1 << intr);
|
2001-12-20 23:48:31 +00:00
|
|
|
mtx_unlock_spin(&icu_lock);
|
2002-03-27 05:39:23 +00:00
|
|
|
intr_restore(crit);
|
1997-06-02 08:19:06 +00:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2000-09-07 01:33:02 +00:00
|
|
|
/*
|
|
|
|
* Dissociate an interrupt handler from an IRQ and set the handler to
|
|
|
|
* the stray interrupt handler. The 'handler' parameter is used only
|
|
|
|
* for consistency checking.
|
|
|
|
*/
|
1997-06-02 08:19:06 +00:00
|
|
|
int
|
|
|
|
icu_unset(intr, handler)
|
|
|
|
int intr;
|
2000-09-13 18:33:25 +00:00
|
|
|
driver_intr_t *handler;
|
1997-06-02 08:19:06 +00:00
|
|
|
{
|
2002-03-27 05:39:23 +00:00
|
|
|
register_t crit;
|
1997-06-02 08:19:06 +00:00
|
|
|
|
|
|
|
if ((u_int)intr >= ICU_LEN || handler != intr_handler[intr])
|
|
|
|
return (EINVAL);
|
|
|
|
|
2002-03-27 05:39:23 +00:00
|
|
|
crit = intr_disable();
|
2001-12-20 23:48:31 +00:00
|
|
|
mtx_lock_spin(&icu_lock);
|
1997-06-02 08:19:06 +00:00
|
|
|
INTRDIS(1 << intr);
|
1999-04-14 14:26:36 +00:00
|
|
|
intr_countp[intr] = &intrcnt[1 + intr];
|
1997-06-02 08:19:06 +00:00
|
|
|
intr_handler[intr] = isa_strayintr;
|
1998-06-18 16:08:46 +00:00
|
|
|
intr_unit[intr] = &intr_unit[intr];
|
2003-05-01 01:05:25 +00:00
|
|
|
setidt(ICU_OFFSET + intr, slowintr[intr], SDT_SYSIGT, SEL_KPL, 0);
|
2001-12-20 23:48:31 +00:00
|
|
|
mtx_unlock_spin(&icu_lock);
|
2002-03-27 05:39:23 +00:00
|
|
|
intr_restore(crit);
|
1997-06-02 08:19:06 +00:00
|
|
|
return (0);
|
|
|
|
}
|
1999-04-21 07:26:30 +00:00
|
|
|
|
2001-02-09 17:47:44 +00:00
|
|
|
static void
|
|
|
|
ithds_init(void *dummy)
|
|
|
|
{
|
|
|
|
|
2002-04-04 21:03:38 +00:00
|
|
|
mtx_init(&ithds_table_lock, "ithread table lock", NULL, MTX_SPIN);
|
2001-02-09 17:47:44 +00:00
|
|
|
}
|
|
|
|
SYSINIT(ithds_init, SI_SUB_INTR, SI_ORDER_SECOND, ithds_init, NULL);
|
|
|
|
|
|
|
|
static void
|
|
|
|
ithread_enable(int vector)
|
|
|
|
{
|
2002-03-27 05:39:23 +00:00
|
|
|
register_t crit;
|
2001-02-09 17:47:44 +00:00
|
|
|
|
2002-03-27 05:39:23 +00:00
|
|
|
crit = intr_disable();
|
2001-12-20 23:48:31 +00:00
|
|
|
mtx_lock_spin(&icu_lock);
|
2001-02-09 17:47:44 +00:00
|
|
|
INTREN(1 << vector);
|
2001-12-20 23:48:31 +00:00
|
|
|
mtx_unlock_spin(&icu_lock);
|
2002-03-27 05:39:23 +00:00
|
|
|
intr_restore(crit);
|
2001-02-09 17:47:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
ithread_disable(int vector)
|
|
|
|
{
|
2002-03-27 05:39:23 +00:00
|
|
|
register_t crit;
|
2001-02-09 17:47:44 +00:00
|
|
|
|
2002-03-27 05:39:23 +00:00
|
|
|
crit = intr_disable();
|
2001-12-20 23:48:31 +00:00
|
|
|
mtx_lock_spin(&icu_lock);
|
2001-02-09 17:47:44 +00:00
|
|
|
INTRDIS(1 << vector);
|
2001-12-20 23:48:31 +00:00
|
|
|
mtx_unlock_spin(&icu_lock);
|
2002-03-27 05:39:23 +00:00
|
|
|
intr_restore(crit);
|
2001-02-09 17:47:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2000-09-13 18:33:25 +00:00
|
|
|
inthand_add(const char *name, int irq, driver_intr_t handler, void *arg,
|
2001-02-09 17:47:44 +00:00
|
|
|
enum intr_type flags, void **cookiep)
|
1999-04-21 07:26:30 +00:00
|
|
|
{
|
2001-02-09 17:47:44 +00:00
|
|
|
struct ithd *ithd; /* descriptor for the IRQ */
|
2000-09-07 01:33:02 +00:00
|
|
|
int errcode = 0;
|
2001-02-09 17:47:44 +00:00
|
|
|
int created_ithd = 0;
|
1999-04-21 07:26:30 +00:00
|
|
|
|
2001-02-09 17:47:44 +00:00
|
|
|
/*
|
|
|
|
* Work around a race where more than one CPU may be registering
|
|
|
|
* handlers on the same IRQ at the same time.
|
|
|
|
*/
|
|
|
|
mtx_lock_spin(&ithds_table_lock);
|
|
|
|
ithd = ithds[irq];
|
|
|
|
mtx_unlock_spin(&ithds_table_lock);
|
|
|
|
if (ithd == NULL) {
|
|
|
|
errcode = ithread_create(&ithd, irq, 0, ithread_disable,
|
|
|
|
ithread_enable, "irq%d:", irq);
|
|
|
|
if (errcode)
|
|
|
|
return (errcode);
|
|
|
|
mtx_lock_spin(&ithds_table_lock);
|
|
|
|
if (ithds[irq] == NULL) {
|
2000-09-07 01:33:02 +00:00
|
|
|
ithds[irq] = ithd;
|
2001-02-09 17:47:44 +00:00
|
|
|
created_ithd++;
|
|
|
|
mtx_unlock_spin(&ithds_table_lock);
|
|
|
|
} else {
|
|
|
|
struct ithd *orphan;
|
|
|
|
|
|
|
|
orphan = ithd;
|
|
|
|
ithd = ithds[irq];
|
|
|
|
mtx_unlock_spin(&ithds_table_lock);
|
|
|
|
ithread_destroy(orphan);
|
1999-04-21 07:26:30 +00:00
|
|
|
}
|
2001-02-09 17:47:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
errcode = ithread_add_handler(ithd, name, handler, arg,
|
|
|
|
ithread_priority(flags), flags, cookiep);
|
|
|
|
|
|
|
|
if ((flags & INTR_FAST) == 0 || errcode)
|
2000-09-07 01:33:02 +00:00
|
|
|
/*
|
2001-02-09 17:47:44 +00:00
|
|
|
* The interrupt process must be in place, but
|
|
|
|
* not necessarily schedulable, before we
|
|
|
|
* initialize the ICU, since it may cause an
|
|
|
|
* immediate interrupt.
|
2000-09-07 01:33:02 +00:00
|
|
|
*/
|
2002-10-20 18:02:46 +00:00
|
|
|
if (icu_setup(irq, sched_ithd, arg, flags) != 0)
|
2001-02-09 17:47:44 +00:00
|
|
|
panic("inthand_add: Can't initialize ICU");
|
1999-04-21 07:26:30 +00:00
|
|
|
|
2001-02-09 17:47:44 +00:00
|
|
|
if (errcode)
|
|
|
|
return (errcode);
|
|
|
|
|
|
|
|
if (flags & INTR_FAST) {
|
|
|
|
errcode = icu_setup(irq, handler, arg, flags);
|
|
|
|
if (errcode && bootverbose)
|
2000-10-27 21:45:50 +00:00
|
|
|
printf("\tinthand_add(irq%d) failed, result=%d\n",
|
1999-04-21 07:26:30 +00:00
|
|
|
irq, errcode);
|
2001-02-09 17:47:44 +00:00
|
|
|
if (errcode)
|
|
|
|
return (errcode);
|
1999-04-21 07:26:30 +00:00
|
|
|
}
|
2001-02-09 17:47:44 +00:00
|
|
|
|
|
|
|
update_intrname(irq, name);
|
|
|
|
return (0);
|
1999-04-21 07:26:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2000-09-07 01:33:02 +00:00
|
|
|
* Deactivate and remove linked list the interrupt handler descriptor
|
|
|
|
* data connected created by an earlier call of inthand_add(), then
|
|
|
|
* adjust the interrupt masks if necessary.
|
1999-04-21 07:26:30 +00:00
|
|
|
*
|
2000-09-07 01:33:02 +00:00
|
|
|
* Return the memory held by the interrupt handler descriptor data
|
|
|
|
* structure to the system. First ensure the handler is not actively
|
|
|
|
* in use.
|
1999-04-21 07:26:30 +00:00
|
|
|
*/
|
|
|
|
int
|
2001-02-09 17:47:44 +00:00
|
|
|
inthand_remove(void *cookie)
|
1999-04-21 07:26:30 +00:00
|
|
|
{
|
|
|
|
|
2001-02-09 17:47:44 +00:00
|
|
|
return (ithread_remove_handler(cookie));
|
1999-04-21 07:26:30 +00:00
|
|
|
}
|