Home | History | Annotate | Line # | Download | only in isa
isa_machdep.c revision 1.2
      1  1.2  chris /*	$NetBSD: isa_machdep.c,v 1.2 2002/11/03 21:43:31 chris Exp $	*/
      2  1.1  chris 
      3  1.1  chris /*-
      4  1.1  chris  * Copyright (c) 1996-1998 The NetBSD Foundation, Inc.
      5  1.1  chris  * All rights reserved.
      6  1.1  chris  *
      7  1.1  chris  * This code is derived from software contributed to The NetBSD Foundation
      8  1.1  chris  * by Mark Brinicombe, Charles M. Hannum and by Jason R. Thorpe of the
      9  1.1  chris  * Numerical Aerospace Simulation Facility, NASA Ames Research Center.
     10  1.1  chris  *
     11  1.1  chris  * Redistribution and use in source and binary forms, with or without
     12  1.1  chris  * modification, are permitted provided that the following conditions
     13  1.1  chris  * are met:
     14  1.1  chris  * 1. Redistributions of source code must retain the above copyright
     15  1.1  chris  *    notice, this list of conditions and the following disclaimer.
     16  1.1  chris  * 2. Redistributions in binary form must reproduce the above copyright
     17  1.1  chris  *    notice, this list of conditions and the following disclaimer in the
     18  1.1  chris  *    documentation and/or other materials provided with the distribution.
     19  1.1  chris  * 3. All advertising materials mentioning features or use of this software
     20  1.1  chris  *    must display the following acknowledgement:
     21  1.1  chris  *	This product includes software developed by the NetBSD
     22  1.1  chris  *	Foundation, Inc. and its contributors.
     23  1.1  chris  * 4. Neither the name of The NetBSD Foundation nor the names of its
     24  1.1  chris  *    contributors may be used to endorse or promote products derived
     25  1.1  chris  *    from this software without specific prior written permission.
     26  1.1  chris  *
     27  1.1  chris  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     28  1.1  chris  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     29  1.1  chris  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     30  1.1  chris  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     31  1.1  chris  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     32  1.1  chris  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     33  1.1  chris  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     34  1.1  chris  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     35  1.1  chris  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     36  1.1  chris  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     37  1.1  chris  * POSSIBILITY OF SUCH DAMAGE.
     38  1.1  chris  */
     39  1.1  chris 
     40  1.1  chris /*-
     41  1.1  chris  * Copyright (c) 1991 The Regents of the University of California.
     42  1.1  chris  * All rights reserved.
     43  1.1  chris  *
     44  1.1  chris  * This code is derived from software contributed to Berkeley by
     45  1.1  chris  * William Jolitz.
     46  1.1  chris  *
     47  1.1  chris  * Redistribution and use in source and binary forms, with or without
     48  1.1  chris  * modification, are permitted provided that the following conditions
     49  1.1  chris  * are met:
     50  1.1  chris  * 1. Redistributions of source code must retain the above copyright
     51  1.1  chris  *    notice, this list of conditions and the following disclaimer.
     52  1.1  chris  * 2. Redistributions in binary form must reproduce the above copyright
     53  1.1  chris  *    notice, this list of conditions and the following disclaimer in the
     54  1.1  chris  *    documentation and/or other materials provided with the distribution.
     55  1.1  chris  * 3. All advertising materials mentioning features or use of this software
     56  1.1  chris  *    must display the following acknowledgement:
     57  1.1  chris  *	This product includes software developed by the University of
     58  1.1  chris  *	California, Berkeley and its contributors.
     59  1.1  chris  * 4. Neither the name of the University nor the names of its contributors
     60  1.1  chris  *    may be used to endorse or promote products derived from this software
     61  1.1  chris  *    without specific prior written permission.
     62  1.1  chris  *
     63  1.1  chris  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     64  1.1  chris  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     65  1.1  chris  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     66  1.1  chris  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     67  1.1  chris  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     68  1.1  chris  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     69  1.1  chris  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     70  1.1  chris  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     71  1.1  chris  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     72  1.1  chris  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     73  1.1  chris  * SUCH DAMAGE.
     74  1.1  chris  *
     75  1.1  chris  *	@(#)isa.c	7.2 (Berkeley) 5/13/91
     76  1.1  chris  */
     77  1.1  chris 
     78  1.1  chris #include "opt_irqstats.h"
     79  1.1  chris 
     80  1.1  chris #include <sys/param.h>
     81  1.1  chris #include <sys/systm.h>
     82  1.1  chris #include <sys/kernel.h>
     83  1.1  chris #include <sys/syslog.h>
     84  1.1  chris #include <sys/device.h>
     85  1.1  chris #include <sys/malloc.h>
     86  1.1  chris #include <sys/proc.h>
     87  1.1  chris 
     88  1.1  chris #define _ARM32_BUS_DMA_PRIVATE
     89  1.1  chris #include <machine/bus.h>
     90  1.1  chris 
     91  1.1  chris #include <machine/intr.h>
     92  1.1  chris #include <machine/pio.h>
     93  1.1  chris #include <machine/bootconfig.h>
     94  1.1  chris #include <machine/isa_machdep.h>
     95  1.1  chris 
     96  1.1  chris #include <dev/isa/isareg.h>
     97  1.1  chris #include <dev/isa/isavar.h>
     98  1.1  chris #include <dev/isa/isadmareg.h>
     99  1.1  chris #include <dev/isa/isadmavar.h>
    100  1.1  chris #include <arm/footbridge/isa/icu.h>
    101  1.1  chris #include <arm/footbridge/dc21285reg.h>
    102  1.1  chris #include <arm/footbridge/dc21285mem.h>
    103  1.1  chris 
    104  1.1  chris #include <uvm/uvm_extern.h>
    105  1.1  chris 
    106  1.1  chris #include "isadma.h"
    107  1.1  chris 
    108  1.1  chris /* prototypes */
    109  1.1  chris static void isa_icu_init __P((void));
    110  1.1  chris 
    111  1.1  chris struct arm32_isa_chipset isa_chipset_tag;
    112  1.1  chris 
    113  1.1  chris void isa_strayintr __P((int));
    114  1.1  chris void intr_calculatemasks __P((void));
    115  1.1  chris int fakeintr __P((void *));
    116  1.1  chris 
    117  1.1  chris int isa_irqdispatch __P((void *arg));
    118  1.1  chris 
    119  1.2  chris u_int imask[NIPL];
    120  1.1  chris unsigned imen;
    121  1.1  chris 
    122  1.1  chris #define AUTO_EOI_1
    123  1.1  chris #define AUTO_EOI_2
    124  1.1  chris 
    125  1.1  chris /*
    126  1.1  chris  * Fill in default interrupt table (in case of spuruious interrupt
    127  1.1  chris  * during configuration of kernel, setup interrupt control unit
    128  1.1  chris  */
    129  1.1  chris static void
    130  1.1  chris isa_icu_init(void)
    131  1.1  chris {
    132  1.1  chris 	/* initialize 8259's */
    133  1.1  chris 	outb(IO_ICU1, 0x11);		/* reset; program device, four bytes */
    134  1.1  chris 	outb(IO_ICU1+1, ICU_OFFSET);	/* starting at this vector index */
    135  1.1  chris 	outb(IO_ICU1+1, 1 << IRQ_SLAVE);	/* slave on line 2 */
    136  1.1  chris #ifdef AUTO_EOI_1
    137  1.1  chris 	outb(IO_ICU1+1, 2 | 1);		/* auto EOI, 8086 mode */
    138  1.1  chris #else
    139  1.1  chris 	outb(IO_ICU1+1, 1);			/* 8086 mode */
    140  1.1  chris #endif
    141  1.1  chris 	outb(IO_ICU1+1, 0xff);		/* leave interrupts masked */
    142  1.1  chris 	outb(IO_ICU1, 0x68);		/* special mask mode (if available) */
    143  1.1  chris 	outb(IO_ICU1, 0x0a);		/* Read IRR by default. */
    144  1.1  chris #ifdef REORDER_IRQ
    145  1.1  chris 	outb(IO_ICU1, 0xc0 | (3 - 1));	/* pri order 3-7, 0-2 (com2 first) */
    146  1.1  chris #endif
    147  1.1  chris 
    148  1.1  chris 	outb(IO_ICU2, 0x11);		/* reset; program device, four bytes */
    149  1.1  chris 	outb(IO_ICU2+1, ICU_OFFSET+8);	/* staring at this vector index */
    150  1.1  chris 	outb(IO_ICU2+1, IRQ_SLAVE);
    151  1.1  chris #ifdef AUTO_EOI_2
    152  1.1  chris 	outb(IO_ICU2+1, 2 | 1);		/* auto EOI, 8086 mode */
    153  1.1  chris #else
    154  1.1  chris 	outb(IO_ICU2+1, 1);			/* 8086 mode */
    155  1.1  chris #endif
    156  1.1  chris 	outb(IO_ICU2+1, 0xff);		/* leave interrupts masked */
    157  1.1  chris 	outb(IO_ICU2, 0x68);		/* special mask mode (if available) */
    158  1.1  chris 	outb(IO_ICU2, 0x0a);		/* Read IRR by default. */
    159  1.1  chris }
    160  1.1  chris 
    161  1.1  chris /*
    162  1.1  chris  * Caught a stray interrupt, notify
    163  1.1  chris  */
    164  1.1  chris void
    165  1.1  chris isa_strayintr(irq)
    166  1.1  chris 	int irq;
    167  1.1  chris {
    168  1.1  chris 	static u_long strays;
    169  1.1  chris 
    170  1.1  chris         /*
    171  1.1  chris          * Stray interrupts on irq 7 occur when an interrupt line is raised
    172  1.1  chris          * and then lowered before the CPU acknowledges it.  This generally
    173  1.1  chris          * means either the device is screwed or something is cli'ing too
    174  1.1  chris          * long and it's timing out.
    175  1.1  chris          */
    176  1.1  chris 	if (++strays <= 5)
    177  1.1  chris 		log(LOG_ERR, "stray interrupt %d%s\n", irq,
    178  1.1  chris 		    strays >= 5 ? "; stopped logging" : "");
    179  1.1  chris }
    180  1.1  chris 
    181  1.2  chris static struct intrq isa_intrq[ICU_LEN];
    182  1.1  chris 
    183  1.1  chris /*
    184  1.1  chris  * Recalculate the interrupt masks from scratch.
    185  1.1  chris  * We could code special registry and deregistry versions of this function that
    186  1.1  chris  * would be faster, but the code would be nastier, and we don't expect this to
    187  1.1  chris  * happen very much anyway.
    188  1.1  chris  */
    189  1.1  chris void
    190  1.1  chris intr_calculatemasks()
    191  1.1  chris {
    192  1.1  chris 	int irq, level;
    193  1.2  chris 	struct intrq *iq;
    194  1.2  chris 	struct intrhand *ih;
    195  1.1  chris 
    196  1.1  chris 	/* First, figure out which levels each IRQ uses. */
    197  1.1  chris 	for (irq = 0; irq < ICU_LEN; irq++) {
    198  1.1  chris 		int levels = 0;
    199  1.2  chris 		iq = &isa_intrq[irq];
    200  1.2  chris 		for (ih = TAILQ_FIRST(&iq->iq_list); ih != NULL;
    201  1.2  chris 			ih = TAILQ_NEXT(ih, ih_list))
    202  1.2  chris 			levels |= (1U << ih->ih_ipl);
    203  1.2  chris 		iq->iq_levels = levels;
    204  1.1  chris 	}
    205  1.1  chris 
    206  1.1  chris 	/* Then figure out which IRQs use each level. */
    207  1.2  chris 	for (level = 0; level < NIPL; level++) {
    208  1.1  chris 		int irqs = 0;
    209  1.1  chris 		for (irq = 0; irq < ICU_LEN; irq++)
    210  1.2  chris 			if (isa_intrq[irq].iq_levels & (1U << level))
    211  1.2  chris 				irqs |= (1U << irq);
    212  1.1  chris 		imask[level] = irqs;
    213  1.1  chris 	}
    214  1.1  chris 
    215  1.1  chris 	/*
    216  1.1  chris 	 * IPL_NONE is used for hardware interrupts that are never blocked,
    217  1.1  chris 	 * and do not block anything else.
    218  1.1  chris 	 */
    219  1.1  chris 	imask[IPL_NONE] = 0;
    220  1.1  chris 
    221  1.2  chris 	imask[IPL_SOFT] |= imask[IPL_NONE];
    222  1.2  chris 	imask[IPL_SOFTCLOCK] |= imask[IPL_SOFT];
    223  1.2  chris 	imask[IPL_SOFTNET] |= imask[IPL_SOFTCLOCK];
    224  1.2  chris 
    225  1.1  chris 	/*
    226  1.1  chris 	 * Enforce a hierarchy that gives slow devices a better chance at not
    227  1.1  chris 	 * dropping data.
    228  1.1  chris 	 */
    229  1.2  chris 	imask[IPL_BIO] |= imask[IPL_SOFTCLOCK];
    230  1.1  chris 	imask[IPL_NET] |= imask[IPL_BIO];
    231  1.2  chris 	imask[IPL_SOFTSERIAL] |= imask[IPL_NET];
    232  1.1  chris 	imask[IPL_TTY] |= imask[IPL_NET];
    233  1.1  chris 	/*
    234  1.1  chris 	 * There are tty, network and disk drivers that use free() at interrupt
    235  1.1  chris 	 * time, so imp > (tty | net | bio).
    236  1.1  chris 	 */
    237  1.1  chris 	imask[IPL_IMP] |= imask[IPL_TTY];
    238  1.1  chris 	imask[IPL_AUDIO] |= imask[IPL_IMP];
    239  1.1  chris 
    240  1.1  chris 	/*
    241  1.1  chris 	 * Since run queues may be manipulated by both the statclock and tty,
    242  1.1  chris 	 * network, and disk drivers, clock > imp.
    243  1.1  chris 	 */
    244  1.1  chris 	imask[IPL_CLOCK] |= imask[IPL_IMP];
    245  1.2  chris 	imask[IPL_STATCLOCK] |= imask[IPL_CLOCK];
    246  1.1  chris 
    247  1.1  chris 	/*
    248  1.1  chris 	 * IPL_HIGH must block everything that can manipulate a run queue.
    249  1.1  chris 	 */
    250  1.2  chris 	imask[IPL_HIGH] |= imask[IPL_STATCLOCK];
    251  1.1  chris 
    252  1.1  chris 	/*
    253  1.1  chris 	 * We need serial drivers to run at the absolute highest priority to
    254  1.1  chris 	 * avoid overruns, so serial > high.
    255  1.1  chris 	 */
    256  1.1  chris 	imask[IPL_SERIAL] |= imask[IPL_HIGH];
    257  1.1  chris 
    258  1.1  chris 	/* And eventually calculate the complete masks. */
    259  1.1  chris 	for (irq = 0; irq < ICU_LEN; irq++) {
    260  1.1  chris 		int irqs = 1 << irq;
    261  1.2  chris 		iq = &isa_intrq[irq];
    262  1.2  chris 		for (ih = TAILQ_FIRST(&iq->iq_list); ih != NULL;
    263  1.2  chris 			ih = TAILQ_NEXT(ih, ih_list))
    264  1.2  chris 			irqs |= imask[ih->ih_ipl];
    265  1.2  chris 		iq->iq_mask = irqs;
    266  1.1  chris 	}
    267  1.1  chris 
    268  1.1  chris 	/* Lastly, determine which IRQs are actually in use. */
    269  1.1  chris 	{
    270  1.1  chris 		int irqs = 0;
    271  1.1  chris 		for (irq = 0; irq < ICU_LEN; irq++)
    272  1.2  chris 			if (!TAILQ_EMPTY(&isa_intrq[irq].iq_list))
    273  1.2  chris 				irqs |= (1U << irq);
    274  1.1  chris 		if (irqs >= 0x100) /* any IRQs >= 8 in use */
    275  1.1  chris 			irqs |= 1 << IRQ_SLAVE;
    276  1.1  chris 		imen = ~irqs;
    277  1.1  chris 		SET_ICUS();
    278  1.1  chris 	}
    279  1.1  chris #if 0
    280  1.1  chris 	printf("type\tmask\tlevel\thand\n");
    281  1.1  chris 	for (irq = 0; irq < ICU_LEN; irq++) {
    282  1.1  chris 		printf("%x\t%04x\t%x\t%p\n", intrtype[irq], intrmask[irq],
    283  1.1  chris 		intrlevel[irq], intrhand[irq]);
    284  1.1  chris 	}
    285  1.1  chris 	for (level = 0; level < IPL_LEVELS; ++level)
    286  1.1  chris 		printf("%d: %08x\n", level, imask[level]);
    287  1.1  chris #endif
    288  1.1  chris }
    289  1.1  chris 
    290  1.1  chris int
    291  1.1  chris fakeintr(arg)
    292  1.1  chris 	void *arg;
    293  1.1  chris {
    294  1.1  chris 
    295  1.1  chris 	return 0;
    296  1.1  chris }
    297  1.1  chris 
    298  1.1  chris #define	LEGAL_IRQ(x)	((x) >= 0 && (x) < ICU_LEN && (x) != 2)
    299  1.1  chris 
    300  1.1  chris int
    301  1.1  chris isa_intr_alloc(ic, mask, type, irq)
    302  1.1  chris 	isa_chipset_tag_t ic;
    303  1.1  chris 	int mask;
    304  1.1  chris 	int type;
    305  1.1  chris 	int *irq;
    306  1.1  chris {
    307  1.1  chris 	int i, tmp, bestirq, count;
    308  1.2  chris 	struct intrq *iq;
    309  1.2  chris 	struct intrhand *ih;
    310  1.1  chris 
    311  1.1  chris 	if (type == IST_NONE)
    312  1.1  chris 		panic("intr_alloc: bogus type");
    313  1.1  chris 
    314  1.1  chris 	bestirq = -1;
    315  1.1  chris 	count = -1;
    316  1.1  chris 
    317  1.1  chris 	/* some interrupts should never be dynamically allocated */
    318  1.1  chris 	mask &= 0xdef8;
    319  1.1  chris 
    320  1.1  chris 	/*
    321  1.1  chris 	 * XXX some interrupts will be used later (6 for fdc, 12 for pms).
    322  1.1  chris 	 * the right answer is to do "breadth-first" searching of devices.
    323  1.1  chris 	 */
    324  1.1  chris 	mask &= 0xefbf;
    325  1.1  chris 
    326  1.1  chris 	for (i = 0; i < ICU_LEN; i++) {
    327  1.1  chris 		if (LEGAL_IRQ(i) == 0 || (mask & (1<<i)) == 0)
    328  1.1  chris 			continue;
    329  1.2  chris 
    330  1.2  chris 		iq = &isa_intrq[i];
    331  1.2  chris 		switch(iq->iq_ist) {
    332  1.1  chris 		case IST_NONE:
    333  1.1  chris 			/*
    334  1.1  chris 			 * if nothing's using the irq, just return it
    335  1.1  chris 			 */
    336  1.1  chris 			*irq = i;
    337  1.1  chris 			return (0);
    338  1.1  chris 
    339  1.1  chris 		case IST_EDGE:
    340  1.1  chris 		case IST_LEVEL:
    341  1.2  chris 			if (type != iq->iq_ist)
    342  1.1  chris 				continue;
    343  1.1  chris 			/*
    344  1.1  chris 			 * if the irq is shareable, count the number of other
    345  1.1  chris 			 * handlers, and if it's smaller than the last irq like
    346  1.1  chris 			 * this, remember it
    347  1.1  chris 			 *
    348  1.1  chris 			 * XXX We should probably also consider the
    349  1.1  chris 			 * interrupt level and stick IPL_TTY with other
    350  1.1  chris 			 * IPL_TTY, etc.
    351  1.1  chris 			 */
    352  1.2  chris 			tmp = 0;
    353  1.2  chris 			TAILQ_FOREACH(ih, &(iq->iq_list), ih_list)
    354  1.2  chris 			     tmp++;
    355  1.1  chris 			if ((bestirq == -1) || (count > tmp)) {
    356  1.1  chris 				bestirq = i;
    357  1.1  chris 				count = tmp;
    358  1.1  chris 			}
    359  1.1  chris 			break;
    360  1.1  chris 
    361  1.1  chris 		case IST_PULSE:
    362  1.1  chris 			/* this just isn't shareable */
    363  1.1  chris 			continue;
    364  1.1  chris 		}
    365  1.1  chris 	}
    366  1.1  chris 
    367  1.1  chris 	if (bestirq == -1)
    368  1.1  chris 		return (1);
    369  1.1  chris 
    370  1.1  chris 	*irq = bestirq;
    371  1.1  chris 
    372  1.1  chris 	return (0);
    373  1.1  chris }
    374  1.1  chris 
    375  1.1  chris const struct evcnt *
    376  1.1  chris isa_intr_evcnt(isa_chipset_tag_t ic, int irq)
    377  1.1  chris {
    378  1.2  chris     return &isa_intrq[irq].iq_ev;
    379  1.1  chris }
    380  1.1  chris 
    381  1.1  chris /*
    382  1.1  chris  * Set up an interrupt handler to start being called.
    383  1.1  chris  * XXX PRONE TO RACE CONDITIONS, UGLY, 'INTERESTING' INSERTION ALGORITHM.
    384  1.1  chris  */
    385  1.1  chris void *
    386  1.1  chris isa_intr_establish(ic, irq, type, level, ih_fun, ih_arg)
    387  1.1  chris 	isa_chipset_tag_t ic;
    388  1.1  chris 	int irq;
    389  1.1  chris 	int type;
    390  1.1  chris 	int level;
    391  1.1  chris 	int (*ih_fun) __P((void *));
    392  1.1  chris 	void *ih_arg;
    393  1.1  chris {
    394  1.2  chris     	struct intrq *iq;
    395  1.2  chris 	struct intrhand *ih;
    396  1.2  chris 	u_int oldirqstate;
    397  1.1  chris 
    398  1.2  chris #if 0
    399  1.2  chris 	printf("isa_intr_establish(%d, %d, %d)\n", irq, type, level);
    400  1.2  chris #endif
    401  1.1  chris 	/* no point in sleeping unless someone can free memory. */
    402  1.1  chris 	ih = malloc(sizeof *ih, M_DEVBUF, cold ? M_NOWAIT : M_WAITOK);
    403  1.1  chris 	if (ih == NULL)
    404  1.2  chris 	    return (NULL);
    405  1.1  chris 
    406  1.1  chris 	if (!LEGAL_IRQ(irq) || type == IST_NONE)
    407  1.1  chris 		panic("intr_establish: bogus irq or type");
    408  1.1  chris 
    409  1.2  chris 	iq = &isa_intrq[irq];
    410  1.2  chris 
    411  1.2  chris 	switch (iq->iq_ist) {
    412  1.1  chris 	case IST_NONE:
    413  1.2  chris 		iq->iq_ist = type;
    414  1.2  chris #if 0
    415  1.2  chris 		printf("Setting irq %d to type %d - ", irq, type);
    416  1.2  chris #endif
    417  1.1  chris 		if (irq < 8) {
    418  1.1  chris 			outb(0x4d0, (inb(0x4d0) & ~(1 << irq))
    419  1.1  chris 			    | ((type == IST_LEVEL) ? (1 << irq) : 0));
    420  1.1  chris /*			printf("%02x\n", inb(0x4d0));*/
    421  1.1  chris 		} else {
    422  1.1  chris 			outb(0x4d1, (inb(0x4d1) & ~(1 << irq))
    423  1.1  chris 			    | ((type == IST_LEVEL) ? (1 << irq) : 0));
    424  1.1  chris /*			printf("%02x\n", inb(0x4d1));*/
    425  1.1  chris 		}
    426  1.1  chris 		break;
    427  1.1  chris 	case IST_EDGE:
    428  1.1  chris 	case IST_LEVEL:
    429  1.2  chris 		if (iq->iq_ist == type)
    430  1.1  chris 			break;
    431  1.1  chris 	case IST_PULSE:
    432  1.1  chris 		if (type != IST_NONE)
    433  1.1  chris 			panic("intr_establish: can't share %s with %s",
    434  1.2  chris 			    isa_intr_typename(iq->iq_ist),
    435  1.1  chris 			    isa_intr_typename(type));
    436  1.1  chris 		break;
    437  1.1  chris 	}
    438  1.1  chris 
    439  1.2  chris 	ih->ih_func = ih_fun;
    440  1.2  chris 	ih->ih_arg = ih_arg;
    441  1.2  chris 	ih->ih_ipl = level;
    442  1.2  chris 	ih->ih_irq = irq;
    443  1.1  chris 
    444  1.2  chris 	/* do not stop us */
    445  1.2  chris 	oldirqstate = disable_interrupts(I32_bit);
    446  1.2  chris 
    447  1.2  chris 	TAILQ_INSERT_TAIL(&iq->iq_list, ih, ih_list);
    448  1.1  chris 
    449  1.1  chris 	intr_calculatemasks();
    450  1.2  chris 	restore_interrupts(oldirqstate);
    451  1.2  chris 
    452  1.1  chris 	return (ih);
    453  1.1  chris }
    454  1.1  chris 
    455  1.1  chris /*
    456  1.1  chris  * Deregister an interrupt handler.
    457  1.1  chris  */
    458  1.1  chris void
    459  1.1  chris isa_intr_disestablish(ic, arg)
    460  1.1  chris 	isa_chipset_tag_t ic;
    461  1.1  chris 	void *arg;
    462  1.1  chris {
    463  1.2  chris 	struct intrhand *ih = arg;
    464  1.2  chris 	struct intrq *iq = &isa_intrq[ih->ih_irq];
    465  1.2  chris 	int irq = ih->ih_irq;
    466  1.2  chris 	u_int oldirqstate;
    467  1.2  chris 
    468  1.1  chris 	if (!LEGAL_IRQ(irq))
    469  1.1  chris 		panic("intr_disestablish: bogus irq");
    470  1.1  chris 
    471  1.2  chris 	oldirqstate = disable_interrupts(I32_bit);
    472  1.2  chris 
    473  1.2  chris 	TAILQ_REMOVE(&iq->iq_list, ih, ih_list);
    474  1.1  chris 
    475  1.1  chris 	intr_calculatemasks();
    476  1.1  chris 
    477  1.2  chris 	restore_interrupts(oldirqstate);
    478  1.2  chris 
    479  1.2  chris 	free(ih, M_DEVBUF);
    480  1.2  chris 
    481  1.2  chris 	if (TAILQ_EMPTY(&(iq->iq_list)))
    482  1.2  chris 		iq->iq_ist = IST_NONE;
    483  1.1  chris }
    484  1.1  chris 
    485  1.1  chris /*
    486  1.1  chris  * isa_intr_init()
    487  1.1  chris  *
    488  1.1  chris  * Initialise the ISA ICU and attach an ISA interrupt handler to the
    489  1.1  chris  * ISA interrupt line on the footbridge.
    490  1.1  chris  */
    491  1.1  chris void
    492  1.1  chris isa_intr_init(void)
    493  1.1  chris {
    494  1.1  chris 	static void *isa_ih;
    495  1.2  chris  	struct intrq *iq;
    496  1.2  chris  	int i;
    497  1.2  chris 
    498  1.2  chris  	/*
    499  1.2  chris  	 * should get the parent here, but initialisation order being so
    500  1.2  chris  	 * strange I need to check if it's available
    501  1.2  chris  	 */
    502  1.2  chris  	for (i = 0; i < ICU_LEN; i++) {
    503  1.2  chris  		iq = &isa_intrq[i];
    504  1.2  chris  		TAILQ_INIT(&iq->iq_list);
    505  1.2  chris 
    506  1.2  chris  		sprintf(iq->iq_name, "irq %d", i);
    507  1.2  chris  		evcnt_attach_dynamic(&iq->iq_ev, EVCNT_TYPE_INTR,
    508  1.2  chris  		    NULL, "isa", iq->iq_name);
    509  1.2  chris  	}
    510  1.2  chris 
    511  1.1  chris 	isa_icu_init();
    512  1.2  chris 	intr_calculatemasks();
    513  1.2  chris 	/* something to break the build in an informative way */
    514  1.1  chris #ifndef ISA_FOOTBRIDGE_IRQ
    515  1.1  chris #warning Before using isa with footbridge you must define ISA_FOOTBRIDGE_IRQ
    516  1.1  chris #endif
    517  1.2  chris 	isa_ih = footbridge_intr_claim(ISA_FOOTBRIDGE_IRQ, IPL_BIO, "isabus",
    518  1.1  chris 	    isa_irqdispatch, NULL);
    519  1.1  chris 
    520  1.1  chris }
    521  1.1  chris 
    522  1.1  chris /* Static array of ISA DMA segments. We only have one on CATS */
    523  1.1  chris #if NISADMA > 0
    524  1.1  chris struct arm32_dma_range machdep_isa_dma_ranges[1];
    525  1.1  chris #endif
    526  1.1  chris 
    527  1.1  chris void
    528  1.1  chris isa_footbridge_init(iobase, membase)
    529  1.1  chris 	u_int iobase, membase;
    530  1.1  chris {
    531  1.1  chris #if NISADMA > 0
    532  1.1  chris 	extern struct arm32_dma_range *footbridge_isa_dma_ranges;
    533  1.1  chris 	extern int footbridge_isa_dma_nranges;
    534  1.1  chris 
    535  1.1  chris 	machdep_isa_dma_ranges[0].dr_sysbase = bootconfig.dram[0].address;
    536  1.1  chris 	machdep_isa_dma_ranges[0].dr_busbase = bootconfig.dram[0].address;
    537  1.1  chris 	machdep_isa_dma_ranges[0].dr_len = (16 * 1024 * 1024);
    538  1.1  chris 
    539  1.1  chris 	footbridge_isa_dma_ranges = machdep_isa_dma_ranges;
    540  1.1  chris 	footbridge_isa_dma_nranges = 1;
    541  1.1  chris #endif
    542  1.1  chris 
    543  1.1  chris 	isa_io_init(iobase, membase);
    544  1.1  chris }
    545  1.1  chris 
    546  1.1  chris void
    547  1.1  chris isa_attach_hook(parent, self, iba)
    548  1.1  chris 	struct device *parent, *self;
    549  1.1  chris 	struct isabus_attach_args *iba;
    550  1.1  chris {
    551  1.1  chris 	/*
    552  1.1  chris 	 * Since we can only have one ISA bus, we just use a single
    553  1.1  chris 	 * statically allocated ISA chipset structure.  Pass it up
    554  1.1  chris 	 * now.
    555  1.1  chris 	 */
    556  1.1  chris 	iba->iba_ic = &isa_chipset_tag;
    557  1.1  chris #if NISADMA > 0
    558  1.1  chris 	isa_dma_init();
    559  1.1  chris #endif
    560  1.1  chris }
    561  1.1  chris 
    562  1.1  chris int
    563  1.1  chris isa_irqdispatch(arg)
    564  1.1  chris 	void *arg;
    565  1.1  chris {
    566  1.2  chris 	struct clockframe *frame = arg;
    567  1.1  chris 	int irq;
    568  1.2  chris 	struct intrq *iq;
    569  1.2  chris 	struct intrhand *ih;
    570  1.1  chris 	u_int iack;
    571  1.2  chris 	int res = 0;
    572  1.1  chris 
    573  1.1  chris 	iack = *((u_int *)(DC21285_PCI_IACK_VBASE));
    574  1.1  chris 	iack &= 0xff;
    575  1.1  chris 	if (iack < 0x20 || iack > 0x2f) {
    576  1.1  chris 		printf("isa_irqdispatch: %x\n", iack);
    577  1.1  chris 		return(0);
    578  1.1  chris 	}
    579  1.1  chris 
    580  1.1  chris 	irq = iack & 0x0f;
    581  1.2  chris 	iq = &isa_intrq[irq];
    582  1.2  chris 	iq->iq_ev.ev_count++;
    583  1.2  chris 	for (ih = TAILQ_FIRST(&iq->iq_list); res != 1 && ih != NULL;
    584  1.2  chris 		     ih = TAILQ_NEXT(ih, ih_list)) {
    585  1.2  chris 		res = (*ih->ih_func)(ih->ih_arg ? ih->ih_arg : frame);
    586  1.1  chris 	}
    587  1.2  chris 	return res;
    588  1.1  chris }
    589  1.1  chris 
    590  1.1  chris 
    591  1.1  chris void
    592  1.1  chris isa_fillw(val, addr, len)
    593  1.1  chris 	u_int val;
    594  1.1  chris 	void *addr;
    595  1.1  chris 	size_t len;
    596  1.1  chris {
    597  1.1  chris 	if ((u_int)addr >= isa_mem_data_vaddr()
    598  1.1  chris 	    && (u_int)addr < isa_mem_data_vaddr() + 0x100000) {
    599  1.1  chris 		bus_size_t offset = ((u_int)addr) & 0xfffff;
    600  1.1  chris 		bus_space_set_region_2(&isa_mem_bs_tag,
    601  1.1  chris 		    (bus_space_handle_t)isa_mem_bs_tag.bs_cookie, offset,
    602  1.1  chris 		    val, len);
    603  1.1  chris 	} else {
    604  1.1  chris 		u_short *ptr = addr;
    605  1.1  chris 
    606  1.1  chris 		while (len > 0) {
    607  1.1  chris 			*ptr++ = val;
    608  1.1  chris 			--len;
    609  1.1  chris 		}
    610  1.1  chris 	}
    611  1.1  chris }
    612