Home | History | Annotate | Line # | Download | only in gdium
gdium_intr.c revision 1.1
      1  1.1  matt /*	$NetBSD: gdium_intr.c,v 1.1 2009/08/06 00:50:26 matt Exp $	*/
      2  1.1  matt 
      3  1.1  matt /*-
      4  1.1  matt  * Copyright (c) 2001 The NetBSD Foundation, Inc.
      5  1.1  matt  * All rights reserved.
      6  1.1  matt  *
      7  1.1  matt  * This code is derived from software contributed to The NetBSD Foundation
      8  1.1  matt  * by Jason R. Thorpe.
      9  1.1  matt  *
     10  1.1  matt  * Redistribution and use in source and binary forms, with or without
     11  1.1  matt  * modification, are permitted provided that the following conditions
     12  1.1  matt  * are met:
     13  1.1  matt  * 1. Redistributions of source code must retain the above copyright
     14  1.1  matt  *    notice, this list of conditions and the following disclaimer.
     15  1.1  matt  * 2. Redistributions in binary form must reproduce the above copyright
     16  1.1  matt  *    notice, this list of conditions and the following disclaimer in the
     17  1.1  matt  *    documentation and/or other materials provided with the distribution.
     18  1.1  matt  *
     19  1.1  matt  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20  1.1  matt  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21  1.1  matt  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22  1.1  matt  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23  1.1  matt  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24  1.1  matt  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25  1.1  matt  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26  1.1  matt  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27  1.1  matt  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28  1.1  matt  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29  1.1  matt  * POSSIBILITY OF SUCH DAMAGE.
     30  1.1  matt  */
     31  1.1  matt 
     32  1.1  matt /*
     33  1.1  matt  * Platform-specific interrupt support for the Algorithmics P-6032.
     34  1.1  matt  *
     35  1.1  matt  * The Algorithmics P-6032's interrupts are wired to GPIO pins
     36  1.1  matt  * on the BONITO system controller.
     37  1.1  matt  */
     38  1.1  matt 
     39  1.1  matt #include <sys/cdefs.h>
     40  1.1  matt __KERNEL_RCSID(0, "$NetBSD: gdium_intr.c,v 1.1 2009/08/06 00:50:26 matt Exp $");
     41  1.1  matt 
     42  1.1  matt #include "opt_ddb.h"
     43  1.1  matt 
     44  1.1  matt #include <sys/param.h>
     45  1.1  matt #include <sys/queue.h>
     46  1.1  matt #include <sys/malloc.h>
     47  1.1  matt #include <sys/systm.h>
     48  1.1  matt #include <sys/device.h>
     49  1.1  matt #include <sys/kernel.h>
     50  1.1  matt #include <sys/cpu.h>
     51  1.1  matt 
     52  1.1  matt #include <machine/bus.h>
     53  1.1  matt #include <machine/intr.h>
     54  1.1  matt 
     55  1.1  matt #include <mips/locore.h>
     56  1.1  matt 
     57  1.1  matt // #include <dev/ic/mc146818reg.h>
     58  1.1  matt 
     59  1.1  matt #include <mips/bonito/bonitoreg.h>
     60  1.1  matt #include <evbmips/gdium/gdiumvar.h>
     61  1.1  matt 
     62  1.1  matt #include <dev/pci/pcireg.h>
     63  1.1  matt #include <dev/pci/pcivar.h>
     64  1.1  matt 
     65  1.1  matt /*
     66  1.1  matt  * The GDIUM interrupts are wired up in the following way:
     67  1.1  matt  *
     68  1.1  matt  *	GPIN0		ISA_NMI		(in)
     69  1.1  matt  *	GPIN1		ISA_INTR	(in)
     70  1.1  matt  *	GPIN2		ETH_INT~	(in)
     71  1.1  matt  *	GPIN3		BONIDE_INT	(in)
     72  1.1  matt  *
     73  1.1  matt  *	PCI_INTA
     74  1.1  matt  *	GPIN4		ISA IRQ3	(in, also on piix4)
     75  1.1  matt  *	GPIN5		ISA IRQ4	(in, also on piix4)
     76  1.1  matt  *
     77  1.1  matt  *	GPIO0		PIRQ A~		(in)
     78  1.1  matt  *	GPIO1		PIRQ B~		(in)
     79  1.1  matt  *	GPIO2		PIRQ C~		(in)
     80  1.1  matt  *	GPIO3		PIRQ D~		(in)
     81  1.1  matt  */
     82  1.1  matt 
     83  1.1  matt struct gdium_irqmap {
     84  1.1  matt 	const char *name;
     85  1.1  matt 	uint8_t	irqidx;
     86  1.1  matt 	uint8_t	flags;
     87  1.1  matt };
     88  1.1  matt 
     89  1.1  matt #define	IRQ_F_INVERT	0x80	/* invert polarity */
     90  1.1  matt #define	IRQ_F_EDGE	0x40	/* edge trigger */
     91  1.1  matt #define	IRQ_F_INT0	0x00	/* INT0 */
     92  1.1  matt #define	IRQ_F_INT1	0x01	/* INT1 */
     93  1.1  matt #define	IRQ_F_INT2	0x02	/* INT2 */
     94  1.1  matt #define	IRQ_F_INT3	0x03	/* INT3 */
     95  1.1  matt #define	IRQ_F_INTMASK	0x07	/* INT mask */
     96  1.1  matt 
     97  1.1  matt const struct gdium_irqmap gdium_irqmap[] = {
     98  1.1  matt 	{ "gpio0",	GDIUM_IRQ_GPIO0,	IRQ_F_INT0 },
     99  1.1  matt 	{ "gpio1",	GDIUM_IRQ_GPIO1,	IRQ_F_INT0 },
    100  1.1  matt 	{ "gpio2",	GDIUM_IRQ_GPIO2,	IRQ_F_INT0 },
    101  1.1  matt 	{ "gpio3",	GDIUM_IRQ_GPIO3,	IRQ_F_INT0 },
    102  1.1  matt 
    103  1.1  matt 	{ "pci inta",	GDIUM_IRQ_PCI_INTA,	IRQ_F_INT0 },
    104  1.1  matt 	{ "pci intb",	GDIUM_IRQ_PCI_INTB,	IRQ_F_INT0 },
    105  1.1  matt 	{ "pci intc",	GDIUM_IRQ_PCI_INTC,	IRQ_F_INT0 },
    106  1.1  matt 	{ "pci intd",	GDIUM_IRQ_PCI_INTD,	IRQ_F_INT0 },
    107  1.1  matt 
    108  1.1  matt 	{ "pci perr",	GDIUM_IRQ_PCI_PERR,	IRQ_F_EDGE|IRQ_F_INT1 },
    109  1.1  matt 	{ "pci serr",	GDIUM_IRQ_PCI_SERR,	IRQ_F_EDGE|IRQ_F_INT1 },
    110  1.1  matt 
    111  1.1  matt 	{ "denali",	GDIUM_IRQ_DENALI,	IRQ_F_INT1 },
    112  1.1  matt 
    113  1.1  matt 	{ "int0",	GDIUM_IRQ_INT0,		IRQ_F_INT0 },
    114  1.1  matt 	{ "int1",	GDIUM_IRQ_INT1,		IRQ_F_INT1 },
    115  1.1  matt 	{ "int2",	GDIUM_IRQ_INT2,		IRQ_F_INT2 },
    116  1.1  matt 	{ "int3",	GDIUM_IRQ_INT3,		IRQ_F_INT3 },
    117  1.1  matt };
    118  1.1  matt 
    119  1.1  matt struct gdium_intrhead {
    120  1.1  matt 	struct evcnt intr_count;
    121  1.1  matt 	int intr_refcnt;
    122  1.1  matt };
    123  1.1  matt struct gdium_intrhead gdium_intrtab[__arraycount(gdium_irqmap)];
    124  1.1  matt 
    125  1.1  matt #define	NINTRS			2	/* MIPS INT0 - INT1 */
    126  1.1  matt 
    127  1.1  matt struct gdium_cpuintr {
    128  1.1  matt 	LIST_HEAD(, evbmips_intrhand) cintr_list;
    129  1.1  matt 	struct evcnt cintr_count;
    130  1.1  matt };
    131  1.1  matt 
    132  1.1  matt struct gdium_cpuintr gdium_cpuintrs[NINTRS];
    133  1.1  matt const char *gdium_cpuintrnames[NINTRS] = {
    134  1.1  matt 	"int 0 (pci)",
    135  1.1  matt 	"int 1 (?)",
    136  1.1  matt };
    137  1.1  matt 
    138  1.1  matt /*
    139  1.1  matt  * This is a mask of bits to clear in the SR when we go to a
    140  1.1  matt  * given hardware interrupt priority level.
    141  1.1  matt  */
    142  1.1  matt const uint32_t ipl_sr_bits[_IPL_N] = {
    143  1.1  matt 	[IPL_NONE] = 0,
    144  1.1  matt 	[IPL_SOFTCLOCK] =
    145  1.1  matt 	    MIPS_SOFT_INT_MASK_0,
    146  1.1  matt 	[IPL_SOFTNET] =
    147  1.1  matt 	    MIPS_SOFT_INT_MASK_0 | MIPS_SOFT_INT_MASK_1,
    148  1.1  matt 	[IPL_VM] =
    149  1.1  matt 	    MIPS_SOFT_INT_MASK_0 | MIPS_SOFT_INT_MASK_1 |
    150  1.1  matt 	    MIPS_INT_MASK_0,
    151  1.1  matt 	[IPL_SCHED] =
    152  1.1  matt 	    MIPS_SOFT_INT_MASK_0 | MIPS_SOFT_INT_MASK_1 |
    153  1.1  matt 	    MIPS_INT_MASK_0 |
    154  1.1  matt 	    MIPS_INT_MASK_1 |
    155  1.1  matt 	    MIPS_INT_MASK_2 |
    156  1.1  matt 	    MIPS_INT_MASK_3 |
    157  1.1  matt 	    MIPS_INT_MASK_4 |
    158  1.1  matt 	    MIPS_INT_MASK_5,
    159  1.1  matt };
    160  1.1  matt 
    161  1.1  matt /*
    162  1.1  matt  * This is a mask of bits to clear in the SR when we go to a
    163  1.1  matt  * given software interrupt priority level.
    164  1.1  matt  * Hardware ipls are port/board specific.
    165  1.1  matt  */
    166  1.1  matt const uint32_t mips_ipl_si_to_sr[2] = {
    167  1.1  matt 	MIPS_SOFT_INT_MASK_0,
    168  1.1  matt 	MIPS_SOFT_INT_MASK_1, /* XXX is this right with the new softints? */
    169  1.1  matt };
    170  1.1  matt 
    171  1.1  matt void	*gdium_intr_establish(int, int (*)(void *), void *);
    172  1.1  matt void	gdium_intr_disestablish(void *);
    173  1.1  matt 
    174  1.1  matt int	gdium_pci_intr_map(struct pci_attach_args *, pci_intr_handle_t *);
    175  1.1  matt const char *gdium_pci_intr_string(void *, pci_intr_handle_t);
    176  1.1  matt const struct evcnt *gdium_pci_intr_evcnt(void *, pci_intr_handle_t);
    177  1.1  matt void	*gdium_pci_intr_establish(void *, pci_intr_handle_t, int,
    178  1.1  matt 	    int (*)(void *), void *);
    179  1.1  matt void	gdium_pci_intr_disestablish(void *, void *);
    180  1.1  matt void	gdium_pci_conf_interrupt(void *, int, int, int, int, int *);
    181  1.1  matt 
    182  1.1  matt void
    183  1.1  matt evbmips_intr_init(void)
    184  1.1  matt {
    185  1.1  matt 	struct gdium_config *gc = &gdium_configuration;
    186  1.1  matt 	struct bonito_config *bc = &gc->gc_bonito;
    187  1.1  matt 	const struct gdium_irqmap *irqmap;
    188  1.1  matt 	uint32_t intbit;
    189  1.1  matt 	int i;
    190  1.1  matt 
    191  1.1  matt 	for (i = 0; i < NINTRS; i++) {
    192  1.1  matt 		LIST_INIT(&gdium_cpuintrs[i].cintr_list);
    193  1.1  matt 		evcnt_attach_dynamic(&gdium_cpuintrs[i].cintr_count,
    194  1.1  matt 		    EVCNT_TYPE_INTR, NULL, "mips", gdium_cpuintrnames[i]);
    195  1.1  matt 	}
    196  1.1  matt 	//evcnt_attach_static(&mips_int5_evcnt);
    197  1.1  matt 
    198  1.1  matt 	for (i = 0; i < __arraycount(gdium_irqmap); i++) {
    199  1.1  matt 		irqmap = &gdium_irqmap[i];
    200  1.1  matt 		intbit = 1 << irqmap->irqidx;
    201  1.1  matt 
    202  1.1  matt 		evcnt_attach_dynamic(&gdium_intrtab[i].intr_count,
    203  1.1  matt 		    EVCNT_TYPE_INTR, NULL, "bonito", irqmap->name);
    204  1.1  matt 
    205  1.1  matt 		if (irqmap->irqidx < 4)
    206  1.1  matt 			bc->bc_gpioIE |= intbit;
    207  1.1  matt 		if (irqmap->flags & IRQ_F_INVERT)
    208  1.1  matt 			bc->bc_intPol |= intbit;
    209  1.1  matt 		if (irqmap->flags & IRQ_F_EDGE)
    210  1.1  matt 			bc->bc_intEdge |= intbit;
    211  1.1  matt 		if ((irqmap->flags & IRQ_F_INTMASK) == IRQ_F_INT1)
    212  1.1  matt 			bc->bc_intSteer |= intbit;
    213  1.1  matt 
    214  1.1  matt 		REGVAL(BONITO_INTENCLR) = intbit;
    215  1.1  matt 	}
    216  1.1  matt 
    217  1.1  matt 	REGVAL(BONITO_GPIOIE) = bc->bc_gpioIE;
    218  1.1  matt 	REGVAL(BONITO_INTEDGE) = bc->bc_intEdge;
    219  1.1  matt 	REGVAL(BONITO_INTSTEER) = bc->bc_intSteer;
    220  1.1  matt 	REGVAL(BONITO_INTPOL) = bc->bc_intPol;
    221  1.1  matt 
    222  1.1  matt 	gc->gc_pc.pc_intr_v = NULL;
    223  1.1  matt 	gc->gc_pc.pc_intr_map = gdium_pci_intr_map;
    224  1.1  matt 	gc->gc_pc.pc_intr_string = gdium_pci_intr_string;
    225  1.1  matt 	gc->gc_pc.pc_intr_evcnt = gdium_pci_intr_evcnt;
    226  1.1  matt 	gc->gc_pc.pc_intr_establish = gdium_pci_intr_establish;
    227  1.1  matt 	gc->gc_pc.pc_intr_disestablish = gdium_pci_intr_disestablish;
    228  1.1  matt 	gc->gc_pc.pc_conf_interrupt = gdium_pci_conf_interrupt;
    229  1.1  matt 
    230  1.1  matt 	/* We let the PCI-ISA bridge code handle this. */
    231  1.1  matt 	gc->gc_pc.pc_pciide_compat_intr_establish = NULL;
    232  1.1  matt 
    233  1.1  matt 	//intr_establish = gdium_intr_establish;
    234  1.1  matt 	//intr_disestablish = gdium_intr_disestablish;
    235  1.1  matt }
    236  1.1  matt 
    237  1.1  matt #if 0
    238  1.1  matt void
    239  1.1  matt gdium_cal_timer(bus_space_tag_t st, bus_space_handle_t sh)
    240  1.1  matt {
    241  1.1  matt 	u_long ctrdiff[4], startctr, endctr, cps;
    242  1.1  matt 	u_int8_t regc;
    243  1.1  matt 	int i;
    244  1.1  matt 
    245  1.1  matt 	/* Disable interrupts first. */
    246  1.1  matt 	bus_space_write_1(st, sh, 0, MC_REGB);
    247  1.1  matt 	bus_space_write_1(st, sh, 1, MC_REGB_SQWE | MC_REGB_BINARY |
    248  1.1  matt 	    MC_REGB_24HR);
    249  1.1  matt 
    250  1.1  matt 	/* Initialize for 16Hz. */
    251  1.1  matt 	bus_space_write_1(st, sh, 0, MC_REGA);
    252  1.1  matt 	bus_space_write_1(st, sh, 1, MC_BASE_32_KHz | MC_RATE_16_Hz);
    253  1.1  matt 
    254  1.1  matt 	/* Run the loop an extra time to prime the cache. */
    255  1.1  matt 	for (i = 0; i < 4; i++) {
    256  1.1  matt 		led_display('h', 'z', '0' + i, ' ');
    257  1.1  matt 
    258  1.1  matt 		/* Enable the interrupt. */
    259  1.1  matt 		bus_space_write_1(st, sh, 0, MC_REGB);
    260  1.1  matt 		bus_space_write_1(st, sh, 1, MC_REGB_PIE | MC_REGB_SQWE |
    261  1.1  matt 		    MC_REGB_BINARY | MC_REGB_24HR);
    262  1.1  matt 
    263  1.1  matt 		/* Go to REGC. */
    264  1.1  matt 		bus_space_write_1(st, sh, 0, MC_REGC);
    265  1.1  matt 
    266  1.1  matt 		/* Wait for it to happen. */
    267  1.1  matt 		startctr = mips3_cp0_count_read();
    268  1.1  matt 		do {
    269  1.1  matt 			regc = bus_space_read_1(st, sh, 1);
    270  1.1  matt 			endctr = mips3_cp0_count_read();
    271  1.1  matt 		} while ((regc & MC_REGC_IRQF) == 0);
    272  1.1  matt 
    273  1.1  matt 		/* Already ACK'd. */
    274  1.1  matt 
    275  1.1  matt 		/* Disable. */
    276  1.1  matt 		bus_space_write_1(st, sh, 0, MC_REGB);
    277  1.1  matt 		bus_space_write_1(st, sh, 1, MC_REGB_SQWE | MC_REGB_BINARY |
    278  1.1  matt 		    MC_REGB_24HR);
    279  1.1  matt 
    280  1.1  matt 		ctrdiff[i] = endctr - startctr;
    281  1.1  matt 	}
    282  1.1  matt 
    283  1.1  matt 	/* Update CPU frequency values */
    284  1.1  matt 	cps = ((ctrdiff[2] + ctrdiff[3]) / 2) * 16;
    285  1.1  matt 	/* XXX mips_cpu_flags isn't set here; assume CPU_MIPS_DOUBLE_COUNT */
    286  1.1  matt 	curcpu()->ci_cpu_freq = cps * 2;
    287  1.1  matt 	curcpu()->ci_cycles_per_hz = (curcpu()->ci_cpu_freq + hz / 2) / hz;
    288  1.1  matt 	curcpu()->ci_divisor_delay =
    289  1.1  matt 	    ((curcpu()->ci_cpu_freq + (1000000 / 2)) / 1000000);
    290  1.1  matt 	/* XXX assume CPU_MIPS_DOUBLE_COUNT */
    291  1.1  matt 	curcpu()->ci_cycles_per_hz /= 2;
    292  1.1  matt 	curcpu()->ci_divisor_delay /= 2;
    293  1.1  matt 
    294  1.1  matt 	printf("Timer calibration: %lu cycles/sec [(%lu, %lu) * 16]\n",
    295  1.1  matt 	    cps, ctrdiff[2], ctrdiff[3]);
    296  1.1  matt 	printf("CPU clock speed = %lu.%02luMHz "
    297  1.1  matt 	    "(hz cycles = %lu, delay divisor = %lu)\n",
    298  1.1  matt 	    curcpu()->ci_cpu_freq / 1000000,
    299  1.1  matt 	    (curcpu()->ci_cpu_freq % 1000000) / 10000,
    300  1.1  matt 	    curcpu()->ci_cycles_per_hz, curcpu()->ci_divisor_delay);
    301  1.1  matt }
    302  1.1  matt #endif
    303  1.1  matt 
    304  1.1  matt void *
    305  1.1  matt gdium_intr_establish(int irq, int (*func)(void *), void *arg)
    306  1.1  matt {
    307  1.1  matt 	const struct gdium_irqmap *irqmap;
    308  1.1  matt 	struct evbmips_intrhand *ih;
    309  1.1  matt 	int s;
    310  1.1  matt 
    311  1.1  matt 	irqmap = &gdium_irqmap[irq];
    312  1.1  matt 	KASSERT(irq < __arraycount(gdium_irqmap));
    313  1.1  matt 
    314  1.1  matt 	KASSERT(irq == irqmap->irqidx);
    315  1.1  matt 
    316  1.1  matt 	ih = malloc(sizeof(*ih), M_DEVBUF, M_NOWAIT|M_ZERO);
    317  1.1  matt 	if (ih == NULL)
    318  1.1  matt 		return (NULL);
    319  1.1  matt 
    320  1.1  matt 	ih->ih_func = func;
    321  1.1  matt 	ih->ih_arg = arg;
    322  1.1  matt 	ih->ih_irq = irq;
    323  1.1  matt 
    324  1.1  matt 	s = splhigh();
    325  1.1  matt 
    326  1.1  matt 	/*
    327  1.1  matt 	 * First, link it into the tables.
    328  1.1  matt 	 */
    329  1.1  matt 	if (irqmap->flags & IRQ_F_INT1)
    330  1.1  matt 		LIST_INSERT_HEAD(&gdium_cpuintrs[1].cintr_list, ih, ih_q);
    331  1.1  matt 	else
    332  1.1  matt 		LIST_INSERT_HEAD(&gdium_cpuintrs[0].cintr_list, ih, ih_q);
    333  1.1  matt 
    334  1.1  matt 	/*
    335  1.1  matt 	 * Now enable it.
    336  1.1  matt 	 */
    337  1.1  matt 	if (gdium_intrtab[irqmap->irqidx].intr_refcnt++ == 0)
    338  1.1  matt 		REGVAL(BONITO_INTENSET) = (1 << irqmap->irqidx);
    339  1.1  matt 
    340  1.1  matt 	splx(s);
    341  1.1  matt 
    342  1.1  matt 	return (ih);
    343  1.1  matt }
    344  1.1  matt 
    345  1.1  matt void
    346  1.1  matt gdium_intr_disestablish(void *cookie)
    347  1.1  matt {
    348  1.1  matt 	const struct gdium_irqmap *irqmap;
    349  1.1  matt 	struct evbmips_intrhand *ih = cookie;
    350  1.1  matt 	int s;
    351  1.1  matt 
    352  1.1  matt 	irqmap = &gdium_irqmap[ih->ih_irq];
    353  1.1  matt 
    354  1.1  matt 	s = splhigh();
    355  1.1  matt 
    356  1.1  matt 	/*
    357  1.1  matt 	 * First, remove it from the table.
    358  1.1  matt 	 */
    359  1.1  matt 	LIST_REMOVE(ih, ih_q);
    360  1.1  matt 
    361  1.1  matt 	/*
    362  1.1  matt 	 * Now, disable it, if there is nothing remaining on the
    363  1.1  matt 	 * list.
    364  1.1  matt 	 */
    365  1.1  matt 	if (gdium_intrtab[irqmap->irqidx].intr_refcnt-- == 1)
    366  1.1  matt 		REGVAL(BONITO_INTENCLR) = (1 << irqmap->irqidx);
    367  1.1  matt 
    368  1.1  matt 	splx(s);
    369  1.1  matt 
    370  1.1  matt 	free(ih, M_DEVBUF);
    371  1.1  matt }
    372  1.1  matt 
    373  1.1  matt void
    374  1.1  matt evbmips_iointr(uint32_t status, uint32_t cause, uint32_t pc,
    375  1.1  matt 	uint32_t ipending)
    376  1.1  matt {
    377  1.1  matt 	const struct gdium_irqmap *irqmap;
    378  1.1  matt 	struct evbmips_intrhand *ih;
    379  1.1  matt 	int level;
    380  1.1  matt 	uint32_t isr;
    381  1.1  matt 
    382  1.1  matt 	/*
    383  1.1  matt 	 * Read the interrupt pending registers, mask them with the
    384  1.1  matt 	 * ones we have enabled, and service them in order of decreasing
    385  1.1  matt 	 * priority.
    386  1.1  matt 	 */
    387  1.1  matt 	isr = REGVAL(BONITO_INTISR) & REGVAL(BONITO_INTEN);
    388  1.1  matt 
    389  1.1  matt 	for (level = 1; level >= 0; level--) {
    390  1.1  matt 		if ((ipending & (MIPS_INT_MASK_0 << level)) == 0)
    391  1.1  matt 			continue;
    392  1.1  matt 		gdium_cpuintrs[level].cintr_count.ev_count++;
    393  1.1  matt 		for (ih = LIST_FIRST(&gdium_cpuintrs[level].cintr_list);
    394  1.1  matt 		     ih != NULL; ih = LIST_NEXT(ih, ih_q)) {
    395  1.1  matt 			irqmap = &gdium_irqmap[ih->ih_irq];
    396  1.1  matt 			if (isr & (1 << ih->ih_irq)) {
    397  1.1  matt 				gdium_intrtab[ih->ih_irq].intr_count.ev_count++;
    398  1.1  matt 				(*ih->ih_func)(ih->ih_arg);
    399  1.1  matt 			}
    400  1.1  matt 		}
    401  1.1  matt 		cause &= ~(MIPS_INT_MASK_0 << level);
    402  1.1  matt 	}
    403  1.1  matt 
    404  1.1  matt 	/* Re-enable anything that we have processed. */
    405  1.1  matt 	_splset(MIPS_SR_INT_IE | ((status & ~cause) & MIPS_HARD_INT_MASK));
    406  1.1  matt }
    407  1.1  matt 
    408  1.1  matt /*****************************************************************************
    409  1.1  matt  * PCI interrupt support
    410  1.1  matt  *****************************************************************************/
    411  1.1  matt 
    412  1.1  matt int
    413  1.1  matt gdium_pci_intr_map(struct pci_attach_args *pa,
    414  1.1  matt     pci_intr_handle_t *ihp)
    415  1.1  matt {
    416  1.1  matt 	static const int8_t pciirqmap[5/*device*/] = {
    417  1.1  matt 	    GDIUM_IRQ_PCI_INTC, /* 13: PCI 802.11 */
    418  1.1  matt 	    GDIUM_IRQ_PCI_INTA, /* 14: SM501 */
    419  1.1  matt 	    GDIUM_IRQ_PCI_INTB, /* 15: NEC USB (2 func) */
    420  1.1  matt 	    GDIUM_IRQ_PCI_INTD, /* 16: Ethernet */
    421  1.1  matt 	    GDIUM_IRQ_PCI_INTC, /* 17: NEC USB (2 func) */
    422  1.1  matt 	};
    423  1.1  matt 	pcitag_t bustag = pa->pa_intrtag;
    424  1.1  matt 	int buspin = pa->pa_intrpin;
    425  1.1  matt 	pci_chipset_tag_t pc = pa->pa_pc;
    426  1.1  matt 	int device;
    427  1.1  matt 
    428  1.1  matt 	if (buspin == 0) {
    429  1.1  matt 		/* No IRQ used. */
    430  1.1  matt 		return (1);
    431  1.1  matt 	}
    432  1.1  matt 
    433  1.1  matt 	if (buspin > 4) {
    434  1.1  matt 		printf("gdium_pci_intr_map: bad interrupt pin %d\n",
    435  1.1  matt 		    buspin);
    436  1.1  matt 		return (1);
    437  1.1  matt 	}
    438  1.1  matt 
    439  1.1  matt 	pci_decompose_tag(pc, bustag, NULL, &device, NULL);
    440  1.1  matt 	if (device < 13 || device > 17) {
    441  1.1  matt 		printf("gdium_pci_intr_map: bad device %d\n",
    442  1.1  matt 		    device);
    443  1.1  matt 		return (1);
    444  1.1  matt 	}
    445  1.1  matt 
    446  1.1  matt 	*ihp = pciirqmap[device - 13];
    447  1.1  matt 	return (0);
    448  1.1  matt }
    449  1.1  matt 
    450  1.1  matt const char *
    451  1.1  matt gdium_pci_intr_string(void *v, pci_intr_handle_t ih)
    452  1.1  matt {
    453  1.1  matt 
    454  1.1  matt 	if (ih >= __arraycount(gdium_irqmap))
    455  1.1  matt 		panic("gdium_intr_string: bogus IRQ %ld", ih);
    456  1.1  matt 
    457  1.1  matt 	return gdium_irqmap[ih].name;
    458  1.1  matt }
    459  1.1  matt 
    460  1.1  matt const struct evcnt *
    461  1.1  matt gdium_pci_intr_evcnt(void *v, pci_intr_handle_t ih)
    462  1.1  matt {
    463  1.1  matt 
    464  1.1  matt 	return &gdium_intrtab[ih].intr_count;
    465  1.1  matt }
    466  1.1  matt 
    467  1.1  matt void *
    468  1.1  matt gdium_pci_intr_establish(void *v, pci_intr_handle_t ih, int level,
    469  1.1  matt     int (*func)(void *), void *arg)
    470  1.1  matt {
    471  1.1  matt 
    472  1.1  matt 	if (ih >= __arraycount(gdium_irqmap))
    473  1.1  matt 		panic("gdium_intr_establish: bogus IRQ %ld", ih);
    474  1.1  matt 
    475  1.1  matt 	return gdium_intr_establish(ih, func, arg);
    476  1.1  matt }
    477  1.1  matt 
    478  1.1  matt void
    479  1.1  matt gdium_pci_intr_disestablish(void *v, void *cookie)
    480  1.1  matt {
    481  1.1  matt 
    482  1.1  matt 	return (gdium_intr_disestablish(cookie));
    483  1.1  matt }
    484  1.1  matt 
    485  1.1  matt void
    486  1.1  matt gdium_pci_conf_interrupt(void *v, int bus, int dev, int pin, int swiz,
    487  1.1  matt     int *iline)
    488  1.1  matt {
    489  1.1  matt 
    490  1.1  matt 	/*
    491  1.1  matt 	 * We actually don't need to do anything; everything is handled
    492  1.1  matt 	 * in pci_intr_map().
    493  1.1  matt 	 */
    494  1.1  matt 	*iline = 0;
    495  1.1  matt }
    496