1996-05-03 23:14:50 +04:00
|
|
|
/* $NetBSD: isa_machdep.c,v 1.13 1996/05/03 19:14:55 christos Exp $ */
|
1995-04-17 16:06:30 +04:00
|
|
|
|
|
|
|
/*-
|
|
|
|
* Copyright (c) 1993, 1994 Charles Hannum.
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* @(#)isa.c 7.2 (Berkeley) 5/13/91
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
1996-05-03 23:14:50 +04:00
|
|
|
#include <sys/systm.h>
|
1995-04-17 16:06:30 +04:00
|
|
|
#include <sys/syslog.h>
|
|
|
|
#include <sys/device.h>
|
|
|
|
#include <sys/malloc.h>
|
|
|
|
|
|
|
|
#include <machine/pio.h>
|
|
|
|
#include <machine/cpufunc.h>
|
|
|
|
|
|
|
|
#include <dev/isa/isareg.h>
|
|
|
|
#include <dev/isa/isavar.h>
|
|
|
|
#include <i386/isa/isa_machdep.h>
|
|
|
|
#include <i386/isa/icu.h>
|
|
|
|
|
|
|
|
#define IDTVEC(name) __CONCAT(X,name)
|
|
|
|
/* default interrupt vector table entries */
|
1996-05-03 23:14:50 +04:00
|
|
|
typedef (*vector) __P((void));
|
1995-10-09 09:34:11 +03:00
|
|
|
extern vector IDTVEC(intr)[], IDTVEC(fast)[];
|
1995-04-17 16:06:30 +04:00
|
|
|
extern struct gate_descriptor idt[];
|
1996-05-03 23:14:50 +04:00
|
|
|
void isa_strayintr __P((int));
|
|
|
|
void intr_calculatemasks __P((void));
|
|
|
|
int fakeintr __P((void *));
|
1995-04-17 16:06:30 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Fill in default interrupt table (in case of spuruious interrupt
|
|
|
|
* during configuration of kernel, setup interrupt control unit
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
isa_defaultirq()
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
/* icu vectors */
|
|
|
|
for (i = 0; i < ICU_LEN; i++)
|
|
|
|
setgate(&idt[ICU_OFFSET + i], IDTVEC(intr)[i], 0, SDT_SYS386IGT,
|
|
|
|
SEL_KPL);
|
|
|
|
|
|
|
|
/* initialize 8259's */
|
|
|
|
outb(IO_ICU1, 0x11); /* reset; program device, four bytes */
|
|
|
|
outb(IO_ICU1+1, ICU_OFFSET); /* starting at this vector index */
|
|
|
|
outb(IO_ICU1+1, 1 << IRQ_SLAVE); /* slave on line 2 */
|
|
|
|
#ifdef AUTO_EOI_1
|
|
|
|
outb(IO_ICU1+1, 2 | 1); /* auto EOI, 8086 mode */
|
|
|
|
#else
|
|
|
|
outb(IO_ICU1+1, 1); /* 8086 mode */
|
|
|
|
#endif
|
|
|
|
outb(IO_ICU1+1, 0xff); /* leave interrupts masked */
|
|
|
|
outb(IO_ICU1, 0x68); /* special mask mode (if available) */
|
|
|
|
outb(IO_ICU1, 0x0a); /* Read IRR by default. */
|
|
|
|
#ifdef REORDER_IRQ
|
|
|
|
outb(IO_ICU1, 0xc0 | (3 - 1)); /* pri order 3-7, 0-2 (com2 first) */
|
|
|
|
#endif
|
|
|
|
|
|
|
|
outb(IO_ICU2, 0x11); /* reset; program device, four bytes */
|
|
|
|
outb(IO_ICU2+1, ICU_OFFSET+8); /* staring at this vector index */
|
|
|
|
outb(IO_ICU2+1, IRQ_SLAVE);
|
|
|
|
#ifdef AUTO_EOI_2
|
|
|
|
outb(IO_ICU2+1, 2 | 1); /* auto EOI, 8086 mode */
|
|
|
|
#else
|
|
|
|
outb(IO_ICU2+1, 1); /* 8086 mode */
|
|
|
|
#endif
|
|
|
|
outb(IO_ICU2+1, 0xff); /* leave interrupts masked */
|
|
|
|
outb(IO_ICU2, 0x68); /* special mask mode (if available) */
|
|
|
|
outb(IO_ICU2, 0x0a); /* Read IRR by default. */
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Handle a NMI, possibly a machine check.
|
|
|
|
* return true to panic system, false to ignore.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
isa_nmi()
|
|
|
|
{
|
|
|
|
|
|
|
|
log(LOG_CRIT, "NMI port 61 %x, port 70 %x\n", inb(0x61), inb(0x70));
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Caught a stray interrupt, notify
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
isa_strayintr(irq)
|
|
|
|
int irq;
|
|
|
|
{
|
|
|
|
static u_long strays;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Stray interrupts on irq 7 occur when an interrupt line is raised
|
|
|
|
* and then lowered before the CPU acknowledges it. This generally
|
|
|
|
* means either the device is screwed or something is cli'ing too
|
|
|
|
* long and it's timing out.
|
|
|
|
*/
|
|
|
|
if (++strays <= 5)
|
|
|
|
log(LOG_ERR, "stray interrupt %d%s\n", irq,
|
|
|
|
strays >= 5 ? "; stopped logging" : "");
|
|
|
|
}
|
|
|
|
|
|
|
|
int fastvec;
|
|
|
|
int intrtype[ICU_LEN], intrmask[ICU_LEN], intrlevel[ICU_LEN];
|
|
|
|
struct intrhand *intrhand[ICU_LEN];
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Recalculate the interrupt masks from scratch.
|
|
|
|
* We could code special registry and deregistry versions of this function that
|
|
|
|
* would be faster, but the code would be nastier, and we don't expect this to
|
|
|
|
* happen very much anyway.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
intr_calculatemasks()
|
|
|
|
{
|
|
|
|
int irq, level;
|
|
|
|
struct intrhand *q;
|
|
|
|
|
|
|
|
/* First, figure out which levels each IRQ uses. */
|
|
|
|
for (irq = 0; irq < ICU_LEN; irq++) {
|
|
|
|
register int levels = 0;
|
|
|
|
for (q = intrhand[irq]; q; q = q->ih_next)
|
|
|
|
if (q->ih_level != IPL_NONE)
|
|
|
|
levels |= 1 << q->ih_level;
|
|
|
|
intrlevel[irq] = levels;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Then figure out which IRQs use each level. */
|
1995-06-04 12:32:24 +04:00
|
|
|
for (level = 0; level < 5; level++) {
|
1995-04-17 16:06:30 +04:00
|
|
|
register int irqs = 0;
|
|
|
|
for (irq = 0; irq < ICU_LEN; irq++)
|
|
|
|
if (intrlevel[irq] & (1 << level))
|
|
|
|
irqs |= 1 << irq;
|
1995-08-09 05:47:37 +04:00
|
|
|
imask[level] = irqs | SIR_ALLMASK;
|
1995-04-17 16:06:30 +04:00
|
|
|
}
|
|
|
|
|
1996-02-09 05:26:00 +03:00
|
|
|
/*
|
|
|
|
* There are tty, network and disk drivers that use free() at interrupt
|
|
|
|
* time, so imp > (tty | net | bio).
|
|
|
|
*/
|
|
|
|
imask[IPL_IMP] |= imask[IPL_TTY] | imask[IPL_NET] | imask[IPL_BIO];
|
1995-04-17 16:06:30 +04:00
|
|
|
|
1995-06-04 12:32:24 +04:00
|
|
|
/*
|
1996-02-09 05:26:00 +03:00
|
|
|
* Enforce a hierarchy that gives slow devices a better chance at not
|
|
|
|
* dropping data.
|
1995-06-04 12:32:24 +04:00
|
|
|
*/
|
1996-02-09 05:26:00 +03:00
|
|
|
imask[IPL_TTY] |= imask[IPL_NET] | imask[IPL_BIO];
|
|
|
|
imask[IPL_NET] |= imask[IPL_BIO];
|
1995-06-04 12:32:24 +04:00
|
|
|
|
1995-04-17 16:06:30 +04:00
|
|
|
/* And eventually calculate the complete masks. */
|
|
|
|
for (irq = 0; irq < ICU_LEN; irq++) {
|
|
|
|
register int irqs = 1 << irq;
|
|
|
|
for (q = intrhand[irq]; q; q = q->ih_next)
|
|
|
|
if (q->ih_level != IPL_NONE)
|
|
|
|
irqs |= imask[q->ih_level];
|
1995-07-04 11:09:53 +04:00
|
|
|
intrmask[irq] = irqs | SIR_ALLMASK;
|
1995-04-17 16:06:30 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Lastly, determine which IRQs are actually in use. */
|
|
|
|
{
|
|
|
|
register int irqs = 0;
|
|
|
|
for (irq = 0; irq < ICU_LEN; irq++)
|
|
|
|
if (intrhand[irq])
|
|
|
|
irqs |= 1 << irq;
|
|
|
|
if (irqs >= 0x100) /* any IRQs >= 8 in use */
|
|
|
|
irqs |= 1 << IRQ_SLAVE;
|
|
|
|
imen = ~irqs;
|
|
|
|
SET_ICUS();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
fakeintr(arg)
|
|
|
|
void *arg;
|
|
|
|
{
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
1995-12-24 05:29:35 +03:00
|
|
|
#define LEGAL_IRQ(x) ((x) >= 0 && (x) < ICU_LEN && (x) != 2)
|
|
|
|
|
1995-04-17 16:06:30 +04:00
|
|
|
/*
|
|
|
|
* Set up an interrupt handler to start being called.
|
|
|
|
* XXX PRONE TO RACE CONDITIONS, UGLY, 'INTERESTING' INSERTION ALGORITHM.
|
|
|
|
*/
|
|
|
|
void *
|
1996-04-12 02:11:32 +04:00
|
|
|
isa_intr_establish(ic, irq, type, level, ih_fun, ih_arg)
|
|
|
|
isa_chipset_tag_t ic;
|
1995-04-17 16:06:30 +04:00
|
|
|
int irq;
|
1995-12-24 05:29:35 +03:00
|
|
|
int type;
|
|
|
|
int level;
|
1995-04-17 16:06:30 +04:00
|
|
|
int (*ih_fun) __P((void *));
|
|
|
|
void *ih_arg;
|
|
|
|
{
|
|
|
|
struct intrhand **p, *q, *ih;
|
|
|
|
static struct intrhand fakehand = {fakeintr};
|
|
|
|
extern int cold;
|
|
|
|
|
|
|
|
/* no point in sleeping unless someone can free memory. */
|
|
|
|
ih = malloc(sizeof *ih, M_DEVBUF, cold ? M_NOWAIT : M_WAITOK);
|
|
|
|
if (ih == NULL)
|
|
|
|
panic("isa_intr_establish: can't malloc handler info");
|
|
|
|
|
1995-12-24 05:29:35 +03:00
|
|
|
if (!LEGAL_IRQ(irq) || type == IST_NONE)
|
1995-04-17 16:06:30 +04:00
|
|
|
panic("intr_establish: bogus irq or type");
|
|
|
|
|
|
|
|
switch (intrtype[irq]) {
|
1995-12-24 05:29:35 +03:00
|
|
|
case IST_EDGE:
|
|
|
|
case IST_LEVEL:
|
1995-04-17 16:06:30 +04:00
|
|
|
if (type == intrtype[irq])
|
|
|
|
break;
|
1995-12-24 05:29:35 +03:00
|
|
|
case IST_PULSE:
|
|
|
|
if (type != IST_NONE)
|
1995-04-17 16:06:30 +04:00
|
|
|
panic("intr_establish: can't share %s with %s",
|
|
|
|
isa_intr_typename(intrtype[irq]),
|
|
|
|
isa_intr_typename(type));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Figure out where to put the handler.
|
|
|
|
* This is O(N^2), but we want to preserve the order, and N is
|
|
|
|
* generally small.
|
|
|
|
*/
|
|
|
|
for (p = &intrhand[irq]; (q = *p) != NULL; p = &q->ih_next)
|
|
|
|
;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Actually install a fake handler momentarily, since we might be doing
|
|
|
|
* this with interrupts enabled and don't want the real routine called
|
|
|
|
* until masking is set up.
|
|
|
|
*/
|
1995-12-24 05:29:35 +03:00
|
|
|
fakehand.ih_level = level;
|
1995-04-17 16:06:30 +04:00
|
|
|
*p = &fakehand;
|
|
|
|
|
|
|
|
intr_calculatemasks();
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Poke the real handler in now.
|
|
|
|
*/
|
|
|
|
ih->ih_fun = ih_fun;
|
|
|
|
ih->ih_arg = ih_arg;
|
|
|
|
ih->ih_count = 0;
|
|
|
|
ih->ih_next = NULL;
|
1995-12-24 05:29:35 +03:00
|
|
|
ih->ih_level = level;
|
1995-04-17 16:06:30 +04:00
|
|
|
ih->ih_irq = irq;
|
|
|
|
*p = ih;
|
|
|
|
|
|
|
|
return (ih);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Deregister an interrupt handler.
|
|
|
|
*/
|
|
|
|
void
|
1996-04-12 02:11:32 +04:00
|
|
|
isa_intr_disestablish(ic, arg)
|
|
|
|
isa_chipset_tag_t ic;
|
1995-04-19 10:14:13 +04:00
|
|
|
void *arg;
|
1995-04-17 16:06:30 +04:00
|
|
|
{
|
1995-04-19 10:14:13 +04:00
|
|
|
struct intrhand *ih = arg;
|
1995-12-24 05:29:35 +03:00
|
|
|
int irq = ih->ih_irq;
|
1995-04-17 16:06:30 +04:00
|
|
|
struct intrhand **p, *q;
|
|
|
|
|
1995-12-24 05:29:35 +03:00
|
|
|
if (!LEGAL_IRQ(irq))
|
1995-04-17 16:06:30 +04:00
|
|
|
panic("intr_disestablish: bogus irq");
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Remove the handler from the chain.
|
|
|
|
* This is O(n^2), too.
|
|
|
|
*/
|
|
|
|
for (p = &intrhand[irq]; (q = *p) != NULL && q != ih; p = &q->ih_next)
|
|
|
|
;
|
|
|
|
if (q)
|
|
|
|
*p = q->ih_next;
|
|
|
|
else
|
|
|
|
panic("intr_disestablish: handler not registered");
|
|
|
|
free(ih, M_DEVBUF);
|
|
|
|
|
|
|
|
intr_calculatemasks();
|
|
|
|
|
|
|
|
if (intrhand[irq] == NULL)
|
1995-12-24 05:29:35 +03:00
|
|
|
intrtype[irq] = IST_NONE;
|
1995-04-17 16:06:30 +04:00
|
|
|
}
|
1996-04-12 02:11:32 +04:00
|
|
|
|
|
|
|
void
|
|
|
|
isa_attach_hook(parent, self, iba)
|
|
|
|
struct device *parent, *self;
|
|
|
|
struct isabus_attach_args *iba;
|
|
|
|
{
|
|
|
|
|
|
|
|
/* Nothing to do. */
|
|
|
|
}
|