isa.c revision 2056
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 *	$Id: isa.c,v 1.19 1994/08/10 04:39:52 wollman Exp $
38 */
39
40/*
41 * code to manage AT bus
42 *
43 * 92/08/18  Frank P. MacLachlan (fpm@crash.cts.com):
44 * Fixed uninitialized variable problem and added code to deal
45 * with DMA page boundaries in isa_dmarangecheck().  Fixed word
46 * mode DMA count compution and reorganized DMA setup code in
47 * isa_dmastart()
48 */
49
50#include <sys/param.h>
51#include <sys/systm.h>		/* isn't it a joy */
52#include <sys/kernel.h>		/* to have three of these */
53#include <sys/conf.h>
54#include <sys/file.h>
55#include <sys/buf.h>
56#include <sys/uio.h>
57#include <sys/syslog.h>
58#include <sys/malloc.h>
59#include <sys/rlist.h>
60#include <machine/segments.h>
61#include <vm/vm.h>
62#include <machine/spl.h>
63#include <i386/isa/isa_device.h>
64#include <i386/isa/isa.h>
65#include <i386/isa/icu.h>
66#include <i386/isa/ic/i8237.h>
67#include <i386/isa/ic/i8042.h>
68
69/*
70**  Register definitions for DMA controller 1 (channels 0..3):
71*/
72#define	DMA1_CHN(c)	(IO_DMA1 + 1*(2*(c)))	/* addr reg for channel c */
73#define	DMA1_SMSK	(IO_DMA1 + 1*10)	/* single mask register */
74#define	DMA1_MODE	(IO_DMA1 + 1*11)	/* mode register */
75#define	DMA1_FFC	(IO_DMA1 + 1*12)	/* clear first/last FF */
76
77/*
78**  Register definitions for DMA controller 2 (channels 4..7):
79*/
80#define	DMA2_CHN(c)	(IO_DMA2 + 2*(2*(c)))	/* addr reg for channel c */
81#define	DMA2_SMSK	(IO_DMA2 + 2*10)	/* single mask register */
82#define	DMA2_MODE	(IO_DMA2 + 2*11)	/* mode register */
83#define	DMA2_FFC	(IO_DMA2 + 2*12)	/* clear first/last FF */
84
85void config_isadev __P((struct isa_device *, u_int *));
86
87/*
88 * print a conflict message
89 */
90void
91conflict(dvp, tmpdvp, item, reason, format)
92	struct isa_device	*dvp, *tmpdvp;
93	int			item;
94	char			*reason;
95	char			*format;
96{
97	printf("%s%d not probed due to %s conflict with %s%d at ",
98		dvp->id_driver->name, dvp->id_unit, reason,
99		tmpdvp->id_driver->name, tmpdvp->id_unit);
100	printf(format, item);
101	printf("\n");
102}
103
104/*
105 * Check to see if things are alread in use, like IRQ's, I/O addresses
106 * and Memory addresses.
107 */
108int
109haveseen(dvp, tmpdvp)
110	struct	isa_device *dvp, *tmpdvp;
111{
112	int	status = 0;
113
114	/*
115	 * Only check against devices that have already been found
116	 */
117	if (tmpdvp->id_alive) {
118		/*
119		 * Check for I/O address conflict.  We can only check the
120		 * starting address of the device against the range of the
121		 * device that has already been probed since we do not
122		 * know how many I/O addresses this device uses.
123		 */
124		if (tmpdvp->id_alive != -1) {
125			if ((dvp->id_iobase >= tmpdvp->id_iobase) &&
126			    (dvp->id_iobase <=
127				  (tmpdvp->id_iobase + tmpdvp->id_alive - 1))) {
128				conflict(dvp, tmpdvp, dvp->id_iobase,
129					 "I/O address", "0x%x");
130				status = 1;
131			}
132		}
133		/*
134		 * Check for Memory address conflict.  We can check for
135		 * range overlap, but it will not catch all cases since the
136		 * driver may adjust the msize paramater during probe, for
137		 * now we just check that the starting address does not
138		 * fall within any allocated region.
139		 * XXX could add a second check after the probe for overlap,
140		 * since at that time we would know the full range.
141		 * XXX KERNBASE is a hack, we should have vaddr in the table!
142		 */
143		if(tmpdvp->id_maddr) {
144			if((KERNBASE + dvp->id_maddr >= tmpdvp->id_maddr) &&
145			   (KERNBASE + dvp->id_maddr <=
146			   (tmpdvp->id_maddr + tmpdvp->id_msize - 1))) {
147				conflict(dvp, tmpdvp, dvp->id_maddr, "maddr",
148					"0x%x");
149				status = 1;
150			}
151		}
152#ifndef COM_MULTIPORT
153		/*
154		 * Check for IRQ conflicts.
155		 */
156		if(tmpdvp->id_irq) {
157			if (tmpdvp->id_irq == dvp->id_irq) {
158				conflict(dvp, tmpdvp, ffs(dvp->id_irq) - 1,
159					"irq", "%d");
160				status = 1;
161			}
162		}
163#endif
164		/*
165		 * Check for DRQ conflicts.
166		 */
167		if(tmpdvp->id_drq != -1) {
168			if (tmpdvp->id_drq == dvp->id_drq) {
169				conflict(dvp, tmpdvp, dvp->id_drq,
170					"drq", "%d");
171				status = 1;
172			}
173		}
174	}
175	return (status);
176}
177
178/*
179 * Search through all the isa_devtab_* tables looking for anything that
180 * conflicts with the current device.
181 */
182int
183haveseen_isadev(dvp)
184	struct isa_device *dvp;
185{
186	struct isa_device *tmpdvp;
187	int	status = 0;
188
189	for (tmpdvp = isa_devtab_tty; tmpdvp->id_driver; tmpdvp++) {
190		status |= haveseen(dvp, tmpdvp);
191	}
192	for (tmpdvp = isa_devtab_bio; tmpdvp->id_driver; tmpdvp++) {
193		status |= haveseen(dvp, tmpdvp);
194	}
195	for (tmpdvp = isa_devtab_net; tmpdvp->id_driver; tmpdvp++) {
196		status |= haveseen(dvp, tmpdvp);
197	}
198	for (tmpdvp = isa_devtab_null; tmpdvp->id_driver; tmpdvp++) {
199		status |= haveseen(dvp, tmpdvp);
200	}
201	return(status);
202}
203
204/*
205 * Configure all ISA devices
206 */
207void
208isa_configure() {
209	struct isa_device *dvp;
210
211	enable_intr();
212	splhigh();
213	INTREN(IRQ_SLAVE);
214	printf("Probing for devices on the ISA bus:\n");
215	for (dvp = isa_devtab_tty; dvp->id_driver; dvp++) {
216		if (!haveseen_isadev(dvp))
217			config_isadev(dvp,&tty_imask);
218	}
219	for (dvp = isa_devtab_bio; dvp->id_driver; dvp++) {
220		if (!haveseen_isadev(dvp))
221			config_isadev(dvp,&bio_imask);
222	}
223	for (dvp = isa_devtab_net; dvp->id_driver; dvp++) {
224		if (!haveseen_isadev(dvp))
225			config_isadev(dvp,&net_imask);
226	}
227	for (dvp = isa_devtab_null; dvp->id_driver; dvp++) {
228		if (!haveseen_isadev(dvp))
229			config_isadev(dvp,(u_int *) NULL);
230	}
231	bio_imask |= SWI_CLOCK_MASK;
232	net_imask |= SWI_NET_MASK;
233	tty_imask |= SWI_TTY_MASK;
234
235/*
236 * XXX we should really add the tty device to net_imask when the line is
237 * switched to SLIPDISC, and then remove it when it is switched away from
238 * SLIPDISC.  No need to block out ALL ttys during a splimp when only one
239 * of them is running slip.
240 *
241 * XXX actually, blocking all ttys during a splimp doesn't matter so much
242 * with sio because the serial interrupt layer doesn't use tty_imask.  Only
243 * non-serial ttys suffer.  It's more stupid that ALL 'net's are blocked
244 * during spltty.
245 */
246#include "sl.h"
247#if NSL > 0
248	net_imask |= tty_imask;
249	tty_imask = net_imask;
250#endif
251	/* bio_imask |= tty_imask ;  can some tty devices use buffers? */
252#ifdef DIAGNOSTIC
253	printf("bio_imask %x tty_imask %x net_imask %x\n",
254	       bio_imask, tty_imask, net_imask);
255#endif
256	splnone();
257}
258
259/*
260 * Configure an ISA device.
261 */
262void
263config_isadev(isdp, mp)
264	struct isa_device *isdp;
265	u_int *mp;
266{
267	struct isa_driver *dp = isdp->id_driver;
268
269	if (isdp->id_maddr) {
270		extern u_int atdevbase;
271
272		isdp->id_maddr -= 0xa0000; /* XXX should be a define */
273		isdp->id_maddr += atdevbase;
274	}
275	isdp->id_alive = (*dp->probe)(isdp);
276	if (isdp->id_alive) {
277		/*
278		 * Only print the I/O address range if id_alive != -1
279		 * Right now this is a temporary fix just for the new
280		 * NPX code so that if it finds a 486 that can use trap
281		 * 16 it will not report I/O addresses.
282		 * Rod Grimes 04/26/94
283		 */
284		printf("%s%d", dp->name, isdp->id_unit);
285		if (isdp->id_alive != -1) {
286 			printf(" at 0x%x", isdp->id_iobase);
287 			if ((isdp->id_iobase + isdp->id_alive - 1) !=
288 			     isdp->id_iobase) {
289 				printf("-0x%x",
290				       isdp->id_iobase +
291				       isdp->id_alive - 1);
292			}
293		}
294		if(isdp->id_irq)
295			printf(" irq %d", ffs(isdp->id_irq) - 1);
296		if (isdp->id_drq != -1)
297			printf(" drq %d", isdp->id_drq);
298		if (isdp->id_maddr)
299			printf(" maddr 0x%x", kvtop(isdp->id_maddr));
300		if (isdp->id_msize)
301			printf(" msize %d", isdp->id_msize);
302		if (isdp->id_flags)
303			printf(" flags 0x%x", isdp->id_flags);
304		if (isdp->id_iobase) {
305			if (isdp->id_iobase < 0x100) {
306				printf(" on motherboard\n");
307			} else {
308				if (isdp->id_iobase >= 0x1000) {
309					printf (" on eisa\n");
310				} else {
311					printf (" on isa\n");
312				}
313			}
314		}
315
316		(*dp->attach)(isdp);
317
318		if(isdp->id_irq) {
319			int intrno;
320
321			intrno = ffs(isdp->id_irq)-1;
322			setidt(ICU_OFFSET+intrno, isdp->id_intr,
323				 SDT_SYS386IGT, SEL_KPL);
324			if(mp) {
325				INTRMASK(*mp,isdp->id_irq);
326			}
327			INTREN(isdp->id_irq);
328		}
329	} else {
330		printf("%s%d not found", dp->name, isdp->id_unit);
331		if (isdp->id_iobase) {
332			printf(" at 0x%x", isdp->id_iobase);
333		}
334		printf("\n");
335	}
336}
337
338#define	IDTVEC(name)	__CONCAT(X,name)
339/* default interrupt vector table entries */
340typedef void inthand_t();
341typedef void (*inthand_func_t)();
342extern inthand_t
343	IDTVEC(intr0), IDTVEC(intr1), IDTVEC(intr2), IDTVEC(intr3),
344	IDTVEC(intr4), IDTVEC(intr5), IDTVEC(intr6), IDTVEC(intr7),
345	IDTVEC(intr8), IDTVEC(intr9), IDTVEC(intr10), IDTVEC(intr11),
346	IDTVEC(intr12), IDTVEC(intr13), IDTVEC(intr14), IDTVEC(intr15);
347
348static inthand_func_t defvec[ICU_LEN] = {
349	&IDTVEC(intr0), &IDTVEC(intr1), &IDTVEC(intr2), &IDTVEC(intr3),
350	&IDTVEC(intr4), &IDTVEC(intr5), &IDTVEC(intr6), &IDTVEC(intr7),
351	&IDTVEC(intr8), &IDTVEC(intr9), &IDTVEC(intr10), &IDTVEC(intr11),
352	&IDTVEC(intr12), &IDTVEC(intr13), &IDTVEC(intr14), &IDTVEC(intr15) };
353
354/*
355 * Fill in default interrupt table (in case of spuruious interrupt
356 * during configuration of kernel, setup interrupt control unit
357 */
358void
359isa_defaultirq()
360{
361	int i;
362
363	/* icu vectors */
364	for (i = 0; i < ICU_LEN; i++)
365		setidt(ICU_OFFSET + i, defvec[i], SDT_SYS386IGT, SEL_KPL);
366
367	/* initialize 8259's */
368	outb(IO_ICU1, 0x11);		/* reset; program device, four bytes */
369	outb(IO_ICU1+1, NRSVIDT);	/* starting at this vector index */
370	outb(IO_ICU1+1, 1<<2);		/* slave on line 2 */
371#ifdef AUTO_EOI_1
372	outb(IO_ICU1+1, 2 | 1);		/* auto EOI, 8086 mode */
373#else
374	outb(IO_ICU1+1, 1);		/* 8086 mode */
375#endif
376	outb(IO_ICU1+1, 0xff);		/* leave interrupts masked */
377	outb(IO_ICU1, 0x0a);		/* default to IRR on read */
378	outb(IO_ICU1, 0xc0 | (3 - 1));	/* pri order 3-7, 0-2 (com2 first) */
379
380	outb(IO_ICU2, 0x11);		/* reset; program device, four bytes */
381	outb(IO_ICU2+1, NRSVIDT+8);	/* staring at this vector index */
382	outb(IO_ICU2+1,2);		/* my slave id is 2 */
383#ifdef AUTO_EOI_2
384	outb(IO_ICU2+1, 2 | 1);		/* auto EOI, 8086 mode */
385#else
386	outb(IO_ICU2+1,1);		/* 8086 mode */
387#endif
388	outb(IO_ICU2+1, 0xff);		/* leave interrupts masked */
389	outb(IO_ICU2, 0x0a);		/* default to IRR on read */
390}
391
392/* region of physical memory known to be contiguous */
393vm_offset_t isaphysmem;
394static caddr_t dma_bounce[8];		/* XXX */
395static char bounced[8];		/* XXX */
396#define MAXDMASZ 512		/* XXX */
397
398/* high byte of address is stored in this port for i-th dma channel */
399static short dmapageport[8] =
400	{ 0x87, 0x83, 0x81, 0x82, 0x8f, 0x8b, 0x89, 0x8a };
401
402/*
403 * isa_dmacascade(): program 8237 DMA controller channel to accept
404 * external dma control by a board.
405 */
406void isa_dmacascade(unsigned chan)
407{
408	if (chan > 7)
409		panic("isa_dmacascade: impossible request");
410
411	/* set dma channel mode, and set dma channel mode */
412	if ((chan & 4) == 0) {
413		outb(DMA1_MODE, DMA37MD_CASCADE | chan);
414		outb(DMA1_SMSK, chan);
415	} else {
416		outb(DMA2_MODE, DMA37MD_CASCADE | (chan & 3));
417		outb(DMA2_SMSK, chan & 3);
418	}
419}
420
421/*
422 * isa_dmastart(): program 8237 DMA controller channel, avoid page alignment
423 * problems by using a bounce buffer.
424 */
425void isa_dmastart(int flags, caddr_t addr, unsigned nbytes, unsigned chan)
426{	vm_offset_t phys;
427	int waport;
428	caddr_t newaddr;
429
430	if (    chan > 7
431	    || (chan < 4 && nbytes > (1<<16))
432	    || (chan >= 4 && (nbytes > (1<<17) || (u_int)addr & 1)))
433		panic("isa_dmastart: impossible request");
434
435	if (isa_dmarangecheck(addr, nbytes, chan)) {
436		if (dma_bounce[chan] == 0)
437			dma_bounce[chan] =
438				/*(caddr_t)malloc(MAXDMASZ, M_TEMP, M_WAITOK);*/
439				(caddr_t) isaphysmem + NBPG*chan;
440		bounced[chan] = 1;
441		newaddr = dma_bounce[chan];
442		*(int *) newaddr = 0;	/* XXX */
443
444		/* copy bounce buffer on write */
445		if (!(flags & B_READ))
446			bcopy(addr, newaddr, nbytes);
447		addr = newaddr;
448	}
449
450	/* translate to physical */
451	phys = pmap_extract(pmap_kernel(), (vm_offset_t)addr);
452
453	if ((chan & 4) == 0) {
454		/*
455		 * Program one of DMA channels 0..3.  These are
456		 * byte mode channels.
457		 */
458		/* set dma channel mode, and reset address ff */
459		if (flags & B_READ)
460			outb(DMA1_MODE, DMA37MD_SINGLE|DMA37MD_WRITE|chan);
461		else
462			outb(DMA1_MODE, DMA37MD_SINGLE|DMA37MD_READ|chan);
463		outb(DMA1_FFC, 0);
464
465		/* send start address */
466		waport =  DMA1_CHN(chan);
467		outb(waport, phys);
468		outb(waport, phys>>8);
469		outb(dmapageport[chan], phys>>16);
470
471		/* send count */
472		outb(waport + 1, --nbytes);
473		outb(waport + 1, nbytes>>8);
474
475		/* unmask channel */
476		outb(DMA1_SMSK, chan);
477	} else {
478		/*
479		 * Program one of DMA channels 4..7.  These are
480		 * word mode channels.
481		 */
482		/* set dma channel mode, and reset address ff */
483		if (flags & B_READ)
484			outb(DMA2_MODE, DMA37MD_SINGLE|DMA37MD_WRITE|(chan&3));
485		else
486			outb(DMA2_MODE, DMA37MD_SINGLE|DMA37MD_READ|(chan&3));
487		outb(DMA2_FFC, 0);
488
489		/* send start address */
490		waport = DMA2_CHN(chan - 4);
491		outb(waport, phys>>1);
492		outb(waport, phys>>9);
493		outb(dmapageport[chan], phys>>16);
494
495		/* send count */
496		nbytes >>= 1;
497		outb(waport + 2, --nbytes);
498		outb(waport + 2, nbytes>>8);
499
500		/* unmask channel */
501		outb(DMA2_SMSK, chan & 3);
502	}
503}
504
505void isa_dmadone(int flags, caddr_t addr, int nbytes, int chan)
506{
507
508	/* copy bounce buffer on read */
509	/*if ((flags & (B_PHYS|B_READ)) == (B_PHYS|B_READ))*/
510	if (bounced[chan]) {
511		bcopy(dma_bounce[chan], addr, nbytes);
512		bounced[chan] = 0;
513	}
514}
515
516/*
517 * Check for problems with the address range of a DMA transfer
518 * (non-contiguous physical pages, outside of bus address space,
519 * crossing DMA page boundaries).
520 * Return true if special handling needed.
521 */
522
523int
524isa_dmarangecheck(caddr_t va, unsigned length, unsigned chan) {
525	vm_offset_t phys, priorpage = 0, endva;
526	u_int dma_pgmsk = (chan & 4) ?  ~(128*1024-1) : ~(64*1024-1);
527
528	endva = (vm_offset_t)round_page(va + length);
529	for (; va < (caddr_t) endva ; va += NBPG) {
530		phys = trunc_page(pmap_extract(pmap_kernel(), (vm_offset_t)va));
531#define ISARAM_END	RAM_END
532		if (phys == 0)
533			panic("isa_dmacheck: no physical page present");
534		if (phys >= ISARAM_END)
535			return (1);
536		if (priorpage) {
537			if (priorpage + NBPG != phys)
538				return (1);
539			/* check if crossing a DMA page boundary */
540			if (((u_int)priorpage ^ (u_int)phys) & dma_pgmsk)
541				return (1);
542		}
543		priorpage = phys;
544	}
545	return (0);
546}
547
548/* head of queue waiting for physmem to become available */
549struct buf isa_physmemq;
550
551/* blocked waiting for resource to become free for exclusive use */
552static isaphysmemflag;
553/* if waited for and call requested when free (B_CALL) */
554static void (*isaphysmemunblock)(); /* needs to be a list */
555
556/*
557 * Allocate contiguous physical memory for transfer, returning
558 * a *virtual* address to region. May block waiting for resource.
559 * (assumed to be called at splbio())
560 */
561caddr_t
562isa_allocphysmem(caddr_t va, unsigned length, void (*func)()) {
563
564	isaphysmemunblock = func;
565	while (isaphysmemflag & B_BUSY) {
566		isaphysmemflag |= B_WANTED;
567		tsleep((caddr_t)&isaphysmemflag, PRIBIO, "isaphys", 0);
568	}
569	isaphysmemflag |= B_BUSY;
570
571	return((caddr_t)isaphysmem);
572}
573
574/*
575 * Free contiguous physical memory used for transfer.
576 * (assumed to be called at splbio())
577 */
578void
579isa_freephysmem(caddr_t va, unsigned length) {
580
581	isaphysmemflag &= ~B_BUSY;
582	if (isaphysmemflag & B_WANTED) {
583		isaphysmemflag &= B_WANTED;
584		wakeup((caddr_t)&isaphysmemflag);
585		if (isaphysmemunblock)
586			(*isaphysmemunblock)();
587	}
588}
589
590#define NMI_PARITY (1 << 7)
591#define NMI_IOCHAN (1 << 6)
592#define ENMI_WATCHDOG (1 << 7)
593#define ENMI_BUSTIMER (1 << 6)
594#define ENMI_IOSTATUS (1 << 5)
595
596/*
597 * Handle a NMI, possibly a machine check.
598 * return true to panic system, false to ignore.
599 */
600int
601isa_nmi(cd)
602	int cd;
603{
604	int isa_port = inb(0x61);
605	int eisa_port = inb(0x461);
606	if(isa_port & NMI_PARITY) {
607		panic("RAM parity error, likely hardware failure.");
608	} else if(isa_port & NMI_IOCHAN) {
609		panic("I/O channel check, likely hardware failure.");
610	} else if(eisa_port & ENMI_WATCHDOG) {
611		panic("EISA watchdog timer expired, likely hardware failure.");
612	} else if(eisa_port & ENMI_BUSTIMER) {
613		panic("EISA bus timeout, likely hardware failure.");
614	} else if(eisa_port & ENMI_IOSTATUS) {
615		panic("EISA I/O port status error.");
616	} else {
617		printf("\nNMI ISA %x, EISA %x\n", isa_port, eisa_port);
618		return(0);
619	}
620}
621
622/*
623 * Caught a stray interrupt, notify
624 */
625void
626isa_strayintr(d)
627	int d;
628{
629
630	/* DON'T BOTHER FOR NOW! */
631	/* for some reason, we get bursts of intr #7, even if not enabled! */
632	/*
633	 * Well the reason you got bursts of intr #7 is because someone
634	 * raised an interrupt line and dropped it before the 8259 could
635	 * prioritize it.  This is documented in the intel data book.  This
636	 * means you have BAD hardware!  I have changed this so that only
637	 * the first 5 get logged, then it quits logging them, and puts
638	 * out a special message. rgrimes 3/25/1993
639	 */
640	extern u_long intrcnt_stray;
641
642	intrcnt_stray++;
643	if (intrcnt_stray <= 5)
644		log(LOG_ERR,"ISA strayintr %x\n", d);
645	if (intrcnt_stray == 5)
646		log(LOG_CRIT,"Too many ISA strayintr not logging any more\n");
647}
648
649/*
650 * find an ISA device in a given isa_devtab_* table, given
651 * the table to search, the expected id_driver entry, and the unit number.
652 *
653 * this function is defined in isa_device.h, and this location is debatable;
654 * i put it there because it's useless w/o, and directly operates on
655 * the other stuff in that file.
656 *
657 */
658
659struct isa_device *find_isadev(table, driverp, unit)
660     struct isa_device *table;
661     struct isa_driver *driverp;
662     int unit;
663{
664  if (driverp == NULL) /* sanity check */
665    return NULL;
666
667  while ((table->id_driver != driverp) || (table->id_unit != unit)) {
668    if (table->id_driver == 0)
669      return NULL;
670
671    table++;
672  }
673
674  return table;
675}
676
677/*
678 * Return nonzero if a (masked) irq is pending for a given device.
679 */
680int
681isa_irq_pending(dvp)
682	struct isa_device *dvp;
683{
684	unsigned id_irq;
685
686	id_irq = (unsigned short) dvp->id_irq;	/* XXX silly type in struct */
687	if (id_irq & 0xff)
688		return (inb(IO_ICU1) & id_irq);
689	return (inb(IO_ICU2) & (id_irq >> 8));
690}
691