Home | History | Annotate | Line # | Download | only in malta
malta_intr.c revision 1.4.2.2
      1  1.4.2.2  nathanw /*	$NetBSD: malta_intr.c,v 1.4.2.2 2002/09/17 21:14:23 nathanw Exp $	*/
      2  1.4.2.2  nathanw 
      3  1.4.2.2  nathanw /*
      4  1.4.2.2  nathanw  * Copyright 2001, 2002 Wasabi Systems, Inc.
      5  1.4.2.2  nathanw  * All rights reserved.
      6  1.4.2.2  nathanw  *
      7  1.4.2.2  nathanw  * Written by Jason R. Thorpe and Simon Burge for Wasabi Systems, Inc.
      8  1.4.2.2  nathanw  *
      9  1.4.2.2  nathanw  * Redistribution and use in source and binary forms, with or without
     10  1.4.2.2  nathanw  * modification, are permitted provided that the following conditions
     11  1.4.2.2  nathanw  * are met:
     12  1.4.2.2  nathanw  * 1. Redistributions of source code must retain the above copyright
     13  1.4.2.2  nathanw  *    notice, this list of conditions and the following disclaimer.
     14  1.4.2.2  nathanw  * 2. Redistributions in binary form must reproduce the above copyright
     15  1.4.2.2  nathanw  *    notice, this list of conditions and the following disclaimer in the
     16  1.4.2.2  nathanw  *    documentation and/or other materials provided with the distribution.
     17  1.4.2.2  nathanw  * 3. All advertising materials mentioning features or use of this software
     18  1.4.2.2  nathanw  *    must display the following acknowledgement:
     19  1.4.2.2  nathanw  *      This product includes software developed for the NetBSD Project by
     20  1.4.2.2  nathanw  *      Wasabi Systems, Inc.
     21  1.4.2.2  nathanw  * 4. The name of Wasabi Systems, Inc. may not be used to endorse
     22  1.4.2.2  nathanw  *    or promote products derived from this software without specific prior
     23  1.4.2.2  nathanw  *    written permission.
     24  1.4.2.2  nathanw  *
     25  1.4.2.2  nathanw  * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
     26  1.4.2.2  nathanw  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     27  1.4.2.2  nathanw  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     28  1.4.2.2  nathanw  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL WASABI SYSTEMS, INC
     29  1.4.2.2  nathanw  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     30  1.4.2.2  nathanw  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     31  1.4.2.2  nathanw  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     32  1.4.2.2  nathanw  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     33  1.4.2.2  nathanw  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     34  1.4.2.2  nathanw  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     35  1.4.2.2  nathanw  * POSSIBILITY OF SUCH DAMAGE.
     36  1.4.2.2  nathanw  */
     37  1.4.2.2  nathanw 
     38  1.4.2.2  nathanw /*
     39  1.4.2.2  nathanw  * Platform-specific interrupt support for the MIPS Malta.
     40  1.4.2.2  nathanw  */
     41  1.4.2.2  nathanw 
     42  1.4.2.2  nathanw 
     43  1.4.2.2  nathanw #include <sys/param.h>
     44  1.4.2.2  nathanw #include <sys/device.h>
     45  1.4.2.2  nathanw #include <sys/kernel.h>
     46  1.4.2.2  nathanw #include <sys/malloc.h>
     47  1.4.2.2  nathanw 
     48  1.4.2.2  nathanw #include <mips/locore.h>
     49  1.4.2.2  nathanw 
     50  1.4.2.2  nathanw #include <evbmips/evbmips/clockvar.h>
     51  1.4.2.2  nathanw 
     52  1.4.2.2  nathanw #include <evbmips/malta/maltavar.h>
     53  1.4.2.2  nathanw #include <evbmips/malta/pci/pcibvar.h>
     54  1.4.2.2  nathanw 
     55  1.4.2.2  nathanw #include <dev/ic/mc146818reg.h>		/* for malta_cal_timer() */
     56  1.4.2.2  nathanw 
     57  1.4.2.2  nathanw #include <dev/isa/isavar.h>
     58  1.4.2.2  nathanw #include <dev/pci/pciidereg.h>
     59  1.4.2.2  nathanw 
     60  1.4.2.2  nathanw /*
     61  1.4.2.2  nathanw  * This is a mask of bits to clear in the SR when we go to a
     62  1.4.2.2  nathanw  * given hardware interrupt priority level.
     63  1.4.2.2  nathanw  */
     64  1.4.2.2  nathanw const u_int32_t ipl_sr_bits[_IPL_N] = {
     65  1.4.2.2  nathanw 	0,					/*  0: IPL_NONE */
     66  1.4.2.2  nathanw 
     67  1.4.2.2  nathanw 	MIPS_SOFT_INT_MASK_0,			/*  1: IPL_SOFT */
     68  1.4.2.2  nathanw 
     69  1.4.2.2  nathanw 	MIPS_SOFT_INT_MASK_0,			/*  2: IPL_SOFTCLOCK */
     70  1.4.2.2  nathanw 
     71  1.4.2.2  nathanw 	MIPS_SOFT_INT_MASK_0|
     72  1.4.2.2  nathanw 		MIPS_SOFT_INT_MASK_1,		/*  3: IPL_SOFTNET */
     73  1.4.2.2  nathanw 
     74  1.4.2.2  nathanw 	MIPS_SOFT_INT_MASK_0|
     75  1.4.2.2  nathanw 		MIPS_SOFT_INT_MASK_1,		/*  4: IPL_SOFTSERIAL */
     76  1.4.2.2  nathanw 
     77  1.4.2.2  nathanw 	MIPS_SOFT_INT_MASK_0|
     78  1.4.2.2  nathanw 		MIPS_SOFT_INT_MASK_1|
     79  1.4.2.2  nathanw 		MIPS_INT_MASK_0,		/*  5: IPL_BIO */
     80  1.4.2.2  nathanw 
     81  1.4.2.2  nathanw 	MIPS_SOFT_INT_MASK_0|
     82  1.4.2.2  nathanw 		MIPS_SOFT_INT_MASK_1|
     83  1.4.2.2  nathanw 		MIPS_INT_MASK_0,		/*  6: IPL_NET */
     84  1.4.2.2  nathanw 
     85  1.4.2.2  nathanw 	MIPS_SOFT_INT_MASK_0|
     86  1.4.2.2  nathanw 		MIPS_SOFT_INT_MASK_1|
     87  1.4.2.2  nathanw 		MIPS_INT_MASK_0,		/*  7: IPL_{TTY,SERIAL} */
     88  1.4.2.2  nathanw 
     89  1.4.2.2  nathanw 	MIPS_SOFT_INT_MASK_0|
     90  1.4.2.2  nathanw 		MIPS_SOFT_INT_MASK_1|
     91  1.4.2.2  nathanw 		MIPS_INT_MASK_0|
     92  1.4.2.2  nathanw 		MIPS_INT_MASK_1|
     93  1.4.2.2  nathanw 		MIPS_INT_MASK_2|
     94  1.4.2.2  nathanw 		MIPS_INT_MASK_3|
     95  1.4.2.2  nathanw 		MIPS_INT_MASK_4|
     96  1.4.2.2  nathanw 		MIPS_INT_MASK_5,		/*  8: IPL_{CLOCK,HIGH} */
     97  1.4.2.2  nathanw };
     98  1.4.2.2  nathanw 
     99  1.4.2.2  nathanw /*
    100  1.4.2.2  nathanw  * This is a mask of bits to clear in the SR when we go to a
    101  1.4.2.2  nathanw  * given software interrupt priority level.
    102  1.4.2.2  nathanw  * Hardware ipls are port/board specific.
    103  1.4.2.2  nathanw  */
    104  1.4.2.2  nathanw const u_int32_t ipl_si_to_sr[_IPL_NSOFT] = {
    105  1.4.2.2  nathanw 	MIPS_SOFT_INT_MASK_0,			/* IPL_SOFT */
    106  1.4.2.2  nathanw 	MIPS_SOFT_INT_MASK_0,			/* IPL_SOFTCLOCK */
    107  1.4.2.2  nathanw 	MIPS_SOFT_INT_MASK_1,			/* IPL_SOFTNET */
    108  1.4.2.2  nathanw 	MIPS_SOFT_INT_MASK_1,			/* IPL_SOFTSERIAL */
    109  1.4.2.2  nathanw };
    110  1.4.2.2  nathanw 
    111  1.4.2.2  nathanw struct malta_cpuintr {
    112  1.4.2.2  nathanw 	LIST_HEAD(, evbmips_intrhand) cintr_list;
    113  1.4.2.2  nathanw 	struct evcnt cintr_count;
    114  1.4.2.2  nathanw };
    115  1.4.2.2  nathanw #define	NINTRS		5	/* MIPS INT0 - INT4 */
    116  1.4.2.2  nathanw 
    117  1.4.2.2  nathanw struct malta_cpuintr malta_cpuintrs[NINTRS];
    118  1.4.2.2  nathanw const char *malta_cpuintrnames[NINTRS] = {
    119  1.4.2.2  nathanw 	"int 0 (piix4)",
    120  1.4.2.2  nathanw 	"int 1 (smi)",
    121  1.4.2.2  nathanw 	"int 2 (uart)",
    122  1.4.2.2  nathanw 	"int 3 (core hi/gt64120)",
    123  1.4.2.2  nathanw 	"int 4 (core lo)",
    124  1.4.2.2  nathanw };
    125  1.4.2.2  nathanw 
    126  1.4.2.2  nathanw static int	malta_pci_intr_map(struct pci_attach_args *, pci_intr_handle_t *);
    127  1.4.2.2  nathanw static const char
    128  1.4.2.2  nathanw 		*malta_pci_intr_string(void *, pci_intr_handle_t);
    129  1.4.2.2  nathanw static const struct evcnt
    130  1.4.2.2  nathanw 		*malta_pci_intr_evcnt(void *, pci_intr_handle_t);
    131  1.4.2.2  nathanw static void	*malta_pci_intr_establish(void *, pci_intr_handle_t, int,
    132  1.4.2.2  nathanw 		    int (*)(void *), void *);
    133  1.4.2.2  nathanw static void	malta_pci_intr_disestablish(void *, void *);
    134  1.4.2.2  nathanw static void	malta_pci_conf_interrupt(void *, int, int, int, int, int *);
    135  1.4.2.2  nathanw static void	*malta_pciide_compat_intr_establish(void *, struct device *,
    136  1.4.2.2  nathanw 		    struct pci_attach_args *, int, int (*)(void *), void *);
    137  1.4.2.2  nathanw 
    138  1.4.2.2  nathanw void
    139  1.4.2.2  nathanw evbmips_intr_init(void)
    140  1.4.2.2  nathanw {
    141  1.4.2.2  nathanw 	struct malta_config *mcp = &malta_configuration;
    142  1.4.2.2  nathanw 	int i;
    143  1.4.2.2  nathanw 
    144  1.4.2.2  nathanw 	for (i = 0; i < NINTRS; i++) {
    145  1.4.2.2  nathanw 		LIST_INIT(&malta_cpuintrs[i].cintr_list);
    146  1.4.2.2  nathanw 		evcnt_attach_dynamic(&malta_cpuintrs[i].cintr_count,
    147  1.4.2.2  nathanw 		    EVCNT_TYPE_INTR, NULL, "mips", malta_cpuintrnames[i]);
    148  1.4.2.2  nathanw 	}
    149  1.4.2.2  nathanw 
    150  1.4.2.2  nathanw 	evcnt_attach_static(&mips_int5_evcnt);
    151  1.4.2.2  nathanw 
    152  1.4.2.2  nathanw 	mcp->mc_pc.pc_intr_v = NULL;
    153  1.4.2.2  nathanw 	mcp->mc_pc.pc_intr_map = malta_pci_intr_map;
    154  1.4.2.2  nathanw 	mcp->mc_pc.pc_intr_string = malta_pci_intr_string;
    155  1.4.2.2  nathanw 	mcp->mc_pc.pc_intr_evcnt = malta_pci_intr_evcnt;
    156  1.4.2.2  nathanw 	mcp->mc_pc.pc_intr_establish = malta_pci_intr_establish;
    157  1.4.2.2  nathanw 	mcp->mc_pc.pc_intr_disestablish = malta_pci_intr_disestablish;
    158  1.4.2.2  nathanw 	mcp->mc_pc.pc_conf_interrupt = malta_pci_conf_interrupt;
    159  1.4.2.2  nathanw 	mcp->mc_pc.pc_pciide_compat_intr_establish =
    160  1.4.2.2  nathanw 	    malta_pciide_compat_intr_establish;
    161  1.4.2.2  nathanw }
    162  1.4.2.2  nathanw 
    163  1.4.2.2  nathanw void
    164  1.4.2.2  nathanw malta_cal_timer(bus_space_tag_t st, bus_space_handle_t sh)
    165  1.4.2.2  nathanw {
    166  1.4.2.2  nathanw 	uint32_t ctrdiff[4], startctr, endctr;
    167  1.4.2.2  nathanw 	u_int8_t regc;
    168  1.4.2.2  nathanw 	int i;
    169  1.4.2.2  nathanw 
    170  1.4.2.2  nathanw 	/* Disable interrupts first. */
    171  1.4.2.2  nathanw 	bus_space_write_1(st, sh, 0, MC_REGB);
    172  1.4.2.2  nathanw 	bus_space_write_1(st, sh, 1, MC_REGB_SQWE | MC_REGB_BINARY |
    173  1.4.2.2  nathanw 	    MC_REGB_24HR);
    174  1.4.2.2  nathanw 
    175  1.4.2.2  nathanw 	/* Initialize for 16Hz. */
    176  1.4.2.2  nathanw 	bus_space_write_1(st, sh, 0, MC_REGA);
    177  1.4.2.2  nathanw 	bus_space_write_1(st, sh, 1, MC_BASE_32_KHz | MC_RATE_16_Hz);
    178  1.4.2.2  nathanw 
    179  1.4.2.2  nathanw 	/* Run the loop an extra time to prime the cache. */
    180  1.4.2.2  nathanw 	for (i = 0; i < 4; i++) {
    181  1.4.2.2  nathanw 		// led_display('h', 'z', '0' + i, ' ');
    182  1.4.2.2  nathanw 
    183  1.4.2.2  nathanw 		/* Enable the interrupt. */
    184  1.4.2.2  nathanw 		bus_space_write_1(st, sh, 0, MC_REGB);
    185  1.4.2.2  nathanw 		bus_space_write_1(st, sh, 1, MC_REGB_PIE | MC_REGB_SQWE |
    186  1.4.2.2  nathanw 		    MC_REGB_BINARY | MC_REGB_24HR);
    187  1.4.2.2  nathanw 
    188  1.4.2.2  nathanw 		/* Go to REGC. */
    189  1.4.2.2  nathanw 		bus_space_write_1(st, sh, 0, MC_REGC);
    190  1.4.2.2  nathanw 
    191  1.4.2.2  nathanw 		/* Wait for it to happen. */
    192  1.4.2.2  nathanw 		startctr = mips3_cp0_count_read();
    193  1.4.2.2  nathanw 		do {
    194  1.4.2.2  nathanw 			regc = bus_space_read_1(st, sh, 1);
    195  1.4.2.2  nathanw 			endctr = mips3_cp0_count_read();
    196  1.4.2.2  nathanw 		} while ((regc & MC_REGC_IRQF) == 0);
    197  1.4.2.2  nathanw 
    198  1.4.2.2  nathanw 		/* Already ACK'd. */
    199  1.4.2.2  nathanw 
    200  1.4.2.2  nathanw 		/* Disable. */
    201  1.4.2.2  nathanw 		bus_space_write_1(st, sh, 0, MC_REGB);
    202  1.4.2.2  nathanw 		bus_space_write_1(st, sh, 1, MC_REGB_SQWE | MC_REGB_BINARY |
    203  1.4.2.2  nathanw 		    MC_REGB_24HR);
    204  1.4.2.2  nathanw 
    205  1.4.2.2  nathanw 		ctrdiff[i] = endctr - startctr;
    206  1.4.2.2  nathanw 	}
    207  1.4.2.2  nathanw 
    208  1.4.2.2  nathanw 	/* Compute the number of cycles per second. */
    209  1.4.2.2  nathanw 	curcpu()->ci_cpu_freq = ((ctrdiff[2] + ctrdiff[3]) / 2) * 16/*Hz*/;
    210  1.4.2.2  nathanw 
    211  1.4.2.2  nathanw 	/* Compute the number of ticks for hz. */
    212  1.4.2.2  nathanw 	curcpu()->ci_cycles_per_hz = (curcpu()->ci_cpu_freq + hz / 2) / hz;
    213  1.4.2.2  nathanw 
    214  1.4.2.2  nathanw 	/* Compute the delay divisor and reciprical. */
    215  1.4.2.2  nathanw 	curcpu()->ci_divisor_delay =
    216  1.4.2.2  nathanw 	    ((curcpu()->ci_cpu_freq + 500000) / 1000000);
    217  1.4.2.2  nathanw 	MIPS_SET_CI_RECIPRICAL(curcpu());
    218  1.4.2.2  nathanw 
    219  1.4.2.2  nathanw 	/*
    220  1.4.2.2  nathanw 	 * Get correct cpu frequency if the CPU runs at twice the
    221  1.4.2.2  nathanw 	 * external/cp0-count frequency.
    222  1.4.2.2  nathanw 	 */
    223  1.4.2.2  nathanw 	if (mips_cpu_flags & CPU_MIPS_DOUBLE_COUNT)
    224  1.4.2.2  nathanw 		curcpu()->ci_cpu_freq *= 2;
    225  1.4.2.2  nathanw 
    226  1.4.2.2  nathanw #ifdef DEBUG
    227  1.4.2.2  nathanw 	printf("Timer calibration: %lu cycles/sec [(%u, %u) * 16]\n",
    228  1.4.2.2  nathanw 	    curcpu()->ci_cpu_freq, ctrdiff[2], ctrdiff[3]);
    229  1.4.2.2  nathanw #endif
    230  1.4.2.2  nathanw }
    231  1.4.2.2  nathanw 
    232  1.4.2.2  nathanw void *
    233  1.4.2.2  nathanw evbmips_intr_establish(int irq, int (*func)(void *), void *arg)
    234  1.4.2.2  nathanw {
    235  1.4.2.2  nathanw 	struct evbmips_intrhand *ih;
    236  1.4.2.2  nathanw 	int s;
    237  1.4.2.2  nathanw 
    238  1.4.2.2  nathanw 	ih = malloc(sizeof(*ih), M_DEVBUF, M_NOWAIT);
    239  1.4.2.2  nathanw 	if (ih == NULL)
    240  1.4.2.2  nathanw 		return (NULL);
    241  1.4.2.2  nathanw 
    242  1.4.2.2  nathanw 	ih->ih_func = func;
    243  1.4.2.2  nathanw 	ih->ih_arg = arg;
    244  1.4.2.2  nathanw 
    245  1.4.2.2  nathanw 	s = splhigh();
    246  1.4.2.2  nathanw 
    247  1.4.2.2  nathanw 	/*
    248  1.4.2.2  nathanw 	 * Link it into the tables.
    249  1.4.2.2  nathanw 	 */
    250  1.4.2.2  nathanw 	LIST_INSERT_HEAD(&malta_cpuintrs[0].cintr_list, ih, ih_q);
    251  1.4.2.2  nathanw 
    252  1.4.2.2  nathanw 	/* XXX - should check that MIPS_INT_MASK_0 is set... */
    253  1.4.2.2  nathanw 
    254  1.4.2.2  nathanw 	splx(s);
    255  1.4.2.2  nathanw 
    256  1.4.2.2  nathanw 	return (ih);
    257  1.4.2.2  nathanw }
    258  1.4.2.2  nathanw 
    259  1.4.2.2  nathanw void
    260  1.4.2.2  nathanw evbmips_intr_disestablish(void *arg)
    261  1.4.2.2  nathanw {
    262  1.4.2.2  nathanw 	struct evbmips_intrhand *ih = arg;
    263  1.4.2.2  nathanw 	int s;
    264  1.4.2.2  nathanw 
    265  1.4.2.2  nathanw 	s = splhigh();
    266  1.4.2.2  nathanw 
    267  1.4.2.2  nathanw 	/*
    268  1.4.2.2  nathanw 	 * First, remove it from the table.
    269  1.4.2.2  nathanw 	 */
    270  1.4.2.2  nathanw 	LIST_REMOVE(ih, ih_q);
    271  1.4.2.2  nathanw 
    272  1.4.2.2  nathanw 	/* XXX - disable MIPS_INT_MASK_0 if list is empty? */
    273  1.4.2.2  nathanw 
    274  1.4.2.2  nathanw 	splx(s);
    275  1.4.2.2  nathanw 
    276  1.4.2.2  nathanw 	free(ih, M_DEVBUF);
    277  1.4.2.2  nathanw }
    278  1.4.2.2  nathanw 
    279  1.4.2.2  nathanw void
    280  1.4.2.2  nathanw evbmips_iointr(uint32_t status, uint32_t cause, uint32_t pc, uint32_t ipending)
    281  1.4.2.2  nathanw {
    282  1.4.2.2  nathanw 	struct evbmips_intrhand *ih;
    283  1.4.2.2  nathanw 
    284  1.4.2.2  nathanw 	/* Check for error interrupts (SMI, GT64120) */
    285  1.4.2.2  nathanw 	if (ipending & (MIPS_INT_MASK_1 | MIPS_INT_MASK_3)) {
    286  1.4.2.2  nathanw 		if (ipending & MIPS_INT_MASK_1)
    287  1.4.2.2  nathanw 			panic("piix4 SMI interrupt");
    288  1.4.2.2  nathanw 		if (ipending & MIPS_INT_MASK_3)
    289  1.4.2.2  nathanw 			panic("gt64120 error interrupt");
    290  1.4.2.2  nathanw 	}
    291  1.4.2.2  nathanw 
    292  1.4.2.2  nathanw 	/*
    293  1.4.2.2  nathanw 	 * Read the interrupt pending registers, mask them with the
    294  1.4.2.2  nathanw 	 * ones we have enabled, and service them in order of decreasing
    295  1.4.2.2  nathanw 	 * priority.
    296  1.4.2.2  nathanw 	 */
    297  1.4.2.2  nathanw 	if (ipending & MIPS_INT_MASK_0) {
    298  1.4.2.2  nathanw 		/* All interrupts are gated through MIPS HW interrupt 0 */
    299  1.4.2.2  nathanw 		malta_cpuintrs[0].cintr_count.ev_count++;
    300  1.4.2.2  nathanw 		LIST_FOREACH(ih, &malta_cpuintrs[0].cintr_list, ih_q)
    301  1.4.2.2  nathanw 			(*ih->ih_func)(ih->ih_arg);
    302  1.4.2.2  nathanw 		cause &= ~MIPS_INT_MASK_0;
    303  1.4.2.2  nathanw 	}
    304  1.4.2.2  nathanw 
    305  1.4.2.2  nathanw 	/* Re-enable anything that we have processed. */
    306  1.4.2.2  nathanw 	_splset(MIPS_SR_INT_IE | ((status & ~cause) & MIPS_HARD_INT_MASK));
    307  1.4.2.2  nathanw }
    308  1.4.2.2  nathanw 
    309  1.4.2.2  nathanw /*
    310  1.4.2.2  nathanw  * YAMON configures pa_intrline correctly (so far), so we trust it to DTRT
    311  1.4.2.2  nathanw  * in the future...
    312  1.4.2.2  nathanw  */
    313  1.4.2.2  nathanw #undef YAMON_IRQ_MAP_BAD
    314  1.4.2.2  nathanw 
    315  1.4.2.2  nathanw /*
    316  1.4.2.2  nathanw  * PCI interrupt support
    317  1.4.2.2  nathanw  */
    318  1.4.2.2  nathanw static int
    319  1.4.2.2  nathanw malta_pci_intr_map(struct pci_attach_args *pa, pci_intr_handle_t *ihp)
    320  1.4.2.2  nathanw {
    321  1.4.2.2  nathanw #ifdef YAMON_IRQ_MAP_BAD
    322  1.4.2.2  nathanw 	static const int pciirqmap[13/*device*/][4/*pin*/] = {
    323  1.4.2.2  nathanw 		{ -1, -1, -1, 11 },	/* 10: USB */
    324  1.4.2.2  nathanw 		{ 10, -1, -1, -1 },	/* 11: Ethernet */
    325  1.4.2.2  nathanw 		{ 11, -1, -1, -1 },	/* 12: Audio */
    326  1.4.2.2  nathanw 		{ -1, -1, -1, -1 },	/* 13: not used */
    327  1.4.2.2  nathanw 		{ -1, -1, -1, -1 },	/* 14: not used */
    328  1.4.2.2  nathanw 		{ -1, -1, -1, -1 },	/* 15: not used */
    329  1.4.2.2  nathanw 		{ -1, -1, -1, -1 },	/* 16: not used */
    330  1.4.2.2  nathanw 		{ -1, -1, -1, -1 },	/* 17: Core card(?) */
    331  1.4.2.2  nathanw 		{ 10, 10, 11, 11 },	/* 18: PCI Slot 1 */
    332  1.4.2.2  nathanw 		{ 10, 11, 11, 10 },	/* 19: PCI Slot 2 */
    333  1.4.2.2  nathanw 		{ 11, 11, 10, 10 },	/* 20: PCI Slot 3 */
    334  1.4.2.2  nathanw 		{ 11, 10, 10, 11 },	/* 21: PCI Slot 4 */
    335  1.4.2.2  nathanw 	};
    336  1.4.2.2  nathanw 	int buspin, device, irq;
    337  1.4.2.2  nathanw #else	/* !YAMON_IRQ_MAP_BAD */
    338  1.4.2.2  nathanw 	int buspin;
    339  1.4.2.2  nathanw #endif	/* !YAMON_IRQ_MAP_BAD */
    340  1.4.2.2  nathanw 
    341  1.4.2.2  nathanw 	buspin = pa->pa_intrpin;
    342  1.4.2.2  nathanw 
    343  1.4.2.2  nathanw 	if (buspin == 0) {
    344  1.4.2.2  nathanw 		/* No IRQ used. */
    345  1.4.2.2  nathanw 		return (1);
    346  1.4.2.2  nathanw 	}
    347  1.4.2.2  nathanw 
    348  1.4.2.2  nathanw 	if (buspin > 4) {
    349  1.4.2.2  nathanw 		printf("malta_pci_intr_map: bad interrupt pin %d\n", buspin);
    350  1.4.2.2  nathanw 		return (1);
    351  1.4.2.2  nathanw 	}
    352  1.4.2.2  nathanw 
    353  1.4.2.2  nathanw #ifdef YAMON_IRQ_MAP_BAD
    354  1.4.2.2  nathanw 	pci_decompose_tag(pa->pa_pc, pa->pa_intrtag, NULL, &device, NULL);
    355  1.4.2.2  nathanw 
    356  1.4.2.2  nathanw 	if (device < 10 || device > 21) {
    357  1.4.2.2  nathanw 		printf("malta_pci_intr_map: bad device %d\n", device);
    358  1.4.2.2  nathanw 		return (1);
    359  1.4.2.2  nathanw 	}
    360  1.4.2.2  nathanw 
    361  1.4.2.2  nathanw 	irq = pciirqmap[device - 10][buspin - 1];
    362  1.4.2.2  nathanw 	if (irq == -1) {
    363  1.4.2.2  nathanw 		printf("malta_pci_intr_map: no mapping for device %d pin %d\n",
    364  1.4.2.2  nathanw 		    device, buspin);
    365  1.4.2.2  nathanw 		return (1);
    366  1.4.2.2  nathanw 	}
    367  1.4.2.2  nathanw 
    368  1.4.2.2  nathanw 	*ihp = irq;
    369  1.4.2.2  nathanw #else	/* !YAMON_IRQ_MAP_BAD */
    370  1.4.2.2  nathanw 	*ihp = pa->pa_intrline;
    371  1.4.2.2  nathanw #endif	/* !YAMON_IRQ_MAP_BAD */
    372  1.4.2.2  nathanw 	return (0);
    373  1.4.2.2  nathanw }
    374  1.4.2.2  nathanw 
    375  1.4.2.2  nathanw static const char *
    376  1.4.2.2  nathanw malta_pci_intr_string(void *v, pci_intr_handle_t irq)
    377  1.4.2.2  nathanw {
    378  1.4.2.2  nathanw 
    379  1.4.2.2  nathanw 	return (isa_intr_string(pcib_ic, irq));
    380  1.4.2.2  nathanw }
    381  1.4.2.2  nathanw 
    382  1.4.2.2  nathanw static const struct evcnt *
    383  1.4.2.2  nathanw malta_pci_intr_evcnt(void *v, pci_intr_handle_t irq)
    384  1.4.2.2  nathanw {
    385  1.4.2.2  nathanw 
    386  1.4.2.2  nathanw 	return (isa_intr_evcnt(pcib_ic, irq));
    387  1.4.2.2  nathanw }
    388  1.4.2.2  nathanw 
    389  1.4.2.2  nathanw static void *
    390  1.4.2.2  nathanw malta_pci_intr_establish(void *v, pci_intr_handle_t irq, int level,
    391  1.4.2.2  nathanw     int (*func)(void *), void *arg)
    392  1.4.2.2  nathanw {
    393  1.4.2.2  nathanw 
    394  1.4.2.2  nathanw 	return (isa_intr_establish(pcib_ic, irq, IST_LEVEL, level, func, arg));
    395  1.4.2.2  nathanw }
    396  1.4.2.2  nathanw 
    397  1.4.2.2  nathanw static void
    398  1.4.2.2  nathanw malta_pci_intr_disestablish(void *v, void *arg)
    399  1.4.2.2  nathanw {
    400  1.4.2.2  nathanw 
    401  1.4.2.2  nathanw 	return (isa_intr_disestablish(pcib_ic, arg));
    402  1.4.2.2  nathanw }
    403  1.4.2.2  nathanw 
    404  1.4.2.2  nathanw static void
    405  1.4.2.2  nathanw malta_pci_conf_interrupt(void *v, int bus, int dev, int func, int swiz,
    406  1.4.2.2  nathanw     int *iline)
    407  1.4.2.2  nathanw {
    408  1.4.2.2  nathanw 
    409  1.4.2.2  nathanw 	/*
    410  1.4.2.2  nathanw 	 * We actually don't need to do anything; everything is handled
    411  1.4.2.2  nathanw 	 * in pci_intr_map().
    412  1.4.2.2  nathanw 	 */
    413  1.4.2.2  nathanw 	*iline = 0;
    414  1.4.2.2  nathanw }
    415  1.4.2.2  nathanw 
    416  1.4.2.2  nathanw void *
    417  1.4.2.2  nathanw malta_pciide_compat_intr_establish(void *v, struct device *dev,
    418  1.4.2.2  nathanw     struct pci_attach_args *pa, int chan, int (*func)(void *), void *arg)
    419  1.4.2.2  nathanw {
    420  1.4.2.2  nathanw 	pci_chipset_tag_t pc = pa->pa_pc;
    421  1.4.2.2  nathanw 	void *cookie;
    422  1.4.2.2  nathanw 	int bus, irq;
    423  1.4.2.2  nathanw 
    424  1.4.2.2  nathanw 	pci_decompose_tag(pc, pa->pa_tag, &bus, NULL, NULL);
    425  1.4.2.2  nathanw 
    426  1.4.2.2  nathanw 	/*
    427  1.4.2.2  nathanw 	 * If this isn't PCI bus #0, all bets are off.
    428  1.4.2.2  nathanw 	 */
    429  1.4.2.2  nathanw 	if (bus != 0)
    430  1.4.2.2  nathanw 		return (NULL);
    431  1.4.2.2  nathanw 
    432  1.4.2.2  nathanw 	irq = PCIIDE_COMPAT_IRQ(chan);
    433  1.4.2.2  nathanw 	cookie = isa_intr_establish(pcib_ic, irq, IST_EDGE, IPL_BIO, func, arg);
    434  1.4.2.2  nathanw 	if (cookie == NULL)
    435  1.4.2.2  nathanw 		return (NULL);
    436  1.4.2.2  nathanw 	printf("%s: %s channel interrupting at %s\n", dev->dv_xname,
    437  1.4.2.2  nathanw 	    PCIIDE_CHANNEL_NAME(chan), malta_pci_intr_string(v, irq));
    438  1.4.2.2  nathanw 	return (cookie);
    439  1.4.2.2  nathanw }
    440