Home | History | Annotate | Line # | Download | only in iq80310
iq80310_pci.c revision 1.2.6.4
      1  1.2.6.4  jdolecek /*	$NetBSD: iq80310_pci.c,v 1.2.6.4 2002/03/16 15:57:28 jdolecek Exp $	*/
      2  1.2.6.2   thorpej 
      3  1.2.6.2   thorpej /*
      4  1.2.6.4  jdolecek  * Copyright (c) 2001, 2002 Wasabi Systems, Inc.
      5  1.2.6.2   thorpej  * All rights reserved.
      6  1.2.6.2   thorpej  *
      7  1.2.6.2   thorpej  * Written by Jason R. Thorpe for Wasabi Systems, Inc.
      8  1.2.6.2   thorpej  *
      9  1.2.6.2   thorpej  * Redistribution and use in source and binary forms, with or without
     10  1.2.6.2   thorpej  * modification, are permitted provided that the following conditions
     11  1.2.6.2   thorpej  * are met:
     12  1.2.6.2   thorpej  * 1. Redistributions of source code must retain the above copyright
     13  1.2.6.2   thorpej  *    notice, this list of conditions and the following disclaimer.
     14  1.2.6.2   thorpej  * 2. Redistributions in binary form must reproduce the above copyright
     15  1.2.6.2   thorpej  *    notice, this list of conditions and the following disclaimer in the
     16  1.2.6.2   thorpej  *    documentation and/or other materials provided with the distribution.
     17  1.2.6.2   thorpej  * 3. All advertising materials mentioning features or use of this software
     18  1.2.6.2   thorpej  *    must display the following acknowledgement:
     19  1.2.6.2   thorpej  *	This product includes software developed for the NetBSD Project by
     20  1.2.6.2   thorpej  *	Wasabi Systems, Inc.
     21  1.2.6.2   thorpej  * 4. The name of Wasabi Systems, Inc. may not be used to endorse
     22  1.2.6.2   thorpej  *    or promote products derived from this software without specific prior
     23  1.2.6.2   thorpej  *    written permission.
     24  1.2.6.2   thorpej  *
     25  1.2.6.2   thorpej  * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
     26  1.2.6.2   thorpej  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     27  1.2.6.2   thorpej  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     28  1.2.6.2   thorpej  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL WASABI SYSTEMS, INC
     29  1.2.6.2   thorpej  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     30  1.2.6.2   thorpej  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     31  1.2.6.2   thorpej  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     32  1.2.6.2   thorpej  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     33  1.2.6.2   thorpej  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     34  1.2.6.2   thorpej  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     35  1.2.6.2   thorpej  * POSSIBILITY OF SUCH DAMAGE.
     36  1.2.6.2   thorpej  */
     37  1.2.6.2   thorpej 
     38  1.2.6.2   thorpej /*
     39  1.2.6.2   thorpej  * IQ80310 PCI interrupt support, using he i80312 Companion I/O chip.
     40  1.2.6.2   thorpej  */
     41  1.2.6.2   thorpej 
     42  1.2.6.2   thorpej #include <sys/param.h>
     43  1.2.6.2   thorpej #include <sys/systm.h>
     44  1.2.6.2   thorpej #include <sys/device.h>
     45  1.2.6.2   thorpej 
     46  1.2.6.2   thorpej #include <machine/autoconf.h>
     47  1.2.6.2   thorpej #include <machine/bus.h>
     48  1.2.6.2   thorpej 
     49  1.2.6.2   thorpej #include <evbarm/iq80310/iq80310reg.h>
     50  1.2.6.2   thorpej #include <evbarm/iq80310/iq80310var.h>
     51  1.2.6.2   thorpej 
     52  1.2.6.2   thorpej #include <arm/xscale/i80312reg.h>
     53  1.2.6.2   thorpej #include <arm/xscale/i80312var.h>
     54  1.2.6.2   thorpej 
     55  1.2.6.2   thorpej #include <dev/pci/pcidevs.h>
     56  1.2.6.2   thorpej #include <dev/pci/ppbreg.h>
     57  1.2.6.2   thorpej 
     58  1.2.6.2   thorpej int	iq80310_pci_intr_map(struct pci_attach_args *, pci_intr_handle_t *);
     59  1.2.6.2   thorpej const char *iq80310_pci_intr_string(void *, pci_intr_handle_t);
     60  1.2.6.2   thorpej const struct evcnt *iq80310_pci_intr_evcnt(void *, pci_intr_handle_t);
     61  1.2.6.2   thorpej void	*iq80310_pci_intr_establish(void *, pci_intr_handle_t,
     62  1.2.6.2   thorpej 	    int, int (*func)(void *), void *);
     63  1.2.6.2   thorpej void	iq80310_pci_intr_disestablish(void *, void *);
     64  1.2.6.2   thorpej 
     65  1.2.6.2   thorpej void
     66  1.2.6.2   thorpej iq80310_pci_init(pci_chipset_tag_t pc, void *cookie)
     67  1.2.6.2   thorpej {
     68  1.2.6.2   thorpej 
     69  1.2.6.2   thorpej 	pc->pc_intr_v = cookie;		/* the i80312 softc */
     70  1.2.6.2   thorpej 	pc->pc_intr_map = iq80310_pci_intr_map;
     71  1.2.6.2   thorpej 	pc->pc_intr_string = iq80310_pci_intr_string;
     72  1.2.6.2   thorpej 	pc->pc_intr_evcnt = iq80310_pci_intr_evcnt;
     73  1.2.6.2   thorpej 	pc->pc_intr_establish = iq80310_pci_intr_establish;
     74  1.2.6.2   thorpej 	pc->pc_intr_disestablish = iq80310_pci_intr_disestablish;
     75  1.2.6.2   thorpej }
     76  1.2.6.2   thorpej 
     77  1.2.6.4  jdolecek #if defined(IOP310_TEAMASA_NPWR)
     78  1.2.6.4  jdolecek int
     79  1.2.6.4  jdolecek iq80310_pci_intr_map(struct pci_attach_args *pa, pci_intr_handle_t *ihp)
     80  1.2.6.4  jdolecek {
     81  1.2.6.4  jdolecek 	struct i80312_softc *sc = pa->pa_pc->pc_intr_v;
     82  1.2.6.4  jdolecek 	pcireg_t reg;
     83  1.2.6.4  jdolecek 	int sbus;
     84  1.2.6.4  jdolecek 
     85  1.2.6.4  jdolecek 	/*
     86  1.2.6.4  jdolecek 	 * The Npwr routes #INTA of the on-board PCI devices directly
     87  1.2.6.4  jdolecek 	 * through the CPLD.  There is no PCI-PCI bridge and no PCI
     88  1.2.6.4  jdolecek 	 * slots on the Npwr.
     89  1.2.6.4  jdolecek 	 *
     90  1.2.6.4  jdolecek 	 * We also expect the devices to be on the Secondary side of
     91  1.2.6.4  jdolecek 	 * the i80312.
     92  1.2.6.4  jdolecek 	 */
     93  1.2.6.4  jdolecek 
     94  1.2.6.4  jdolecek 	reg = bus_space_read_4(sc->sc_st, sc->sc_ppb_sh, PPB_REG_BUSINFO);
     95  1.2.6.4  jdolecek 	sbus = PPB_BUSINFO_SECONDARY(reg);
     96  1.2.6.4  jdolecek 
     97  1.2.6.4  jdolecek 	if (pa->pa_bus != sbus) {
     98  1.2.6.4  jdolecek 		printf("iq80310_pci_intr_map: %d/%d/%d not on Secondary bus\n",
     99  1.2.6.4  jdolecek 		    pa->pa_bus, pa->pa_device, pa->pa_function);
    100  1.2.6.4  jdolecek 		return (1);
    101  1.2.6.4  jdolecek 	}
    102  1.2.6.4  jdolecek 
    103  1.2.6.4  jdolecek 	switch (pa->pa_device) {
    104  1.2.6.4  jdolecek 	case 5:		/* LSI 53c1010 SCSI */
    105  1.2.6.4  jdolecek 		*ihp = XINT3_IRQ(2);
    106  1.2.6.4  jdolecek 		break;
    107  1.2.6.4  jdolecek 	case 6:		/* Intel i82544GC Gig-E #1 */
    108  1.2.6.4  jdolecek 		*ihp = XINT3_IRQ(1);
    109  1.2.6.4  jdolecek 		break;
    110  1.2.6.4  jdolecek 	case 7:		/* Intel i82544GC Gig-E #2 */
    111  1.2.6.4  jdolecek 		*ihp = XINT3_IRQ(4);
    112  1.2.6.4  jdolecek 		break;
    113  1.2.6.4  jdolecek 	default:
    114  1.2.6.4  jdolecek 		printf("iq80310_pci_intr_map: no mapping for %d/%d/%d\n",
    115  1.2.6.4  jdolecek 		    pa->pa_bus, pa->pa_device, pa->pa_function);
    116  1.2.6.4  jdolecek 		return (1);
    117  1.2.6.4  jdolecek 	}
    118  1.2.6.4  jdolecek 
    119  1.2.6.4  jdolecek 	return (0);
    120  1.2.6.4  jdolecek }
    121  1.2.6.4  jdolecek #else /* Default to stock IQ80310 */
    122  1.2.6.2   thorpej int
    123  1.2.6.2   thorpej iq80310_pci_intr_map(struct pci_attach_args *pa, pci_intr_handle_t *ihp)
    124  1.2.6.2   thorpej {
    125  1.2.6.2   thorpej 	struct i80312_softc *sc = pa->pa_pc->pc_intr_v;
    126  1.2.6.2   thorpej 	pcitag_t tag;
    127  1.2.6.2   thorpej 	pcireg_t reg;
    128  1.2.6.2   thorpej 	int sbus, pbus;
    129  1.2.6.2   thorpej 
    130  1.2.6.2   thorpej 	/*
    131  1.2.6.2   thorpej 	 * Mapping of PCI interrupts on the IQ80310 is pretty easy; there
    132  1.2.6.2   thorpej 	 * is a single interrupt line for all PCI devices on pre-F boards,
    133  1.2.6.2   thorpej 	 * and an interrupt line for each INTx# signal on F and later boards.
    134  1.2.6.2   thorpej 	 *
    135  1.2.6.2   thorpej 	 * The only exception is the on-board Ethernet; this devices has
    136  1.2.6.2   thorpej 	 * its own dedicated interrupt line.  The location of this device
    137  1.2.6.2   thorpej 	 * looks like this:
    138  1.2.6.2   thorpej 	 *
    139  1.2.6.2   thorpej 	 *	80312 Secondary -> PPB at dev #7 -> i82559 at dev #0
    140  1.2.6.2   thorpej 	 *
    141  1.2.6.2   thorpej 	 * In order to determine if we're mapping the interrupt for the
    142  1.2.6.2   thorpej 	 * on-board Ethernet, we must read the Secondary Bus # of the
    143  1.2.6.2   thorpej 	 * i80312, then use that to read the Secondary Bus # of the
    144  1.2.6.2   thorpej 	 * 21154 PPB.  At that point, we know that b/d/f of the i82559,
    145  1.2.6.2   thorpej 	 * and can determine if we're looking at that device.
    146  1.2.6.2   thorpej 	 */
    147  1.2.6.2   thorpej 
    148  1.2.6.2   thorpej 	reg = bus_space_read_4(sc->sc_st, sc->sc_ppb_sh, PPB_REG_BUSINFO);
    149  1.2.6.2   thorpej 	pbus = PPB_BUSINFO_PRIMARY(reg);
    150  1.2.6.2   thorpej 	sbus = PPB_BUSINFO_SECONDARY(reg);
    151  1.2.6.2   thorpej 
    152  1.2.6.2   thorpej 	/*
    153  1.2.6.2   thorpej 	 * XXX We don't know how to map interrupts on the Primary
    154  1.2.6.2   thorpej 	 * XXX PCI bus right now.
    155  1.2.6.2   thorpej 	 */
    156  1.2.6.2   thorpej 	if (pa->pa_bus == pbus) {
    157  1.2.6.2   thorpej 		printf("iq80310_pci_intr_map: can't map interrupts on "
    158  1.2.6.2   thorpej 		    "Primary bus\n");
    159  1.2.6.2   thorpej 		return (1);
    160  1.2.6.2   thorpej 	}
    161  1.2.6.2   thorpej 
    162  1.2.6.2   thorpej 	tag = pci_make_tag(pa->pa_pc, sbus, 7, 0);
    163  1.2.6.2   thorpej 
    164  1.2.6.2   thorpej 	/* Make sure the PPB is there. */
    165  1.2.6.2   thorpej 	reg = pci_conf_read(pa->pa_pc, tag, PCI_ID_REG);
    166  1.2.6.2   thorpej 	if (PCI_VENDOR(reg) == PCI_VENDOR_INVALID ||
    167  1.2.6.2   thorpej 	    PCI_VENDOR(reg) == 0) {
    168  1.2.6.2   thorpej 		/*
    169  1.2.6.2   thorpej 		 * That's odd... no PPB there?  Oh well, issue a warning
    170  1.2.6.2   thorpej 		 * and continue on.
    171  1.2.6.2   thorpej 		 */
    172  1.2.6.2   thorpej 		printf("iq80310_pci_intr_map: PPB not found at %d/%d/%d ??\n",
    173  1.2.6.2   thorpej 		    sbus, 7, 0);
    174  1.2.6.2   thorpej 		goto pinmap;
    175  1.2.6.2   thorpej 	}
    176  1.2.6.2   thorpej 
    177  1.2.6.2   thorpej 	/* Make sure the device that's there is a PPB. */
    178  1.2.6.2   thorpej 	reg = pci_conf_read(pa->pa_pc, tag, PCI_CLASS_REG);
    179  1.2.6.2   thorpej 	if (PCI_CLASS(reg) != PCI_CLASS_BRIDGE ||
    180  1.2.6.2   thorpej 	    PCI_SUBCLASS(reg) != PCI_SUBCLASS_BRIDGE_PCI) {
    181  1.2.6.2   thorpej 		/*
    182  1.2.6.2   thorpej 		 * That's odd... the device that's there isn't a PPB.
    183  1.2.6.2   thorpej 		 * Oh well, issue a warning and continue on.
    184  1.2.6.2   thorpej 		 */
    185  1.2.6.2   thorpej 		printf("iq80310_pci_intr_map: %d/%d/%d isn't a PPB ??\n",
    186  1.2.6.2   thorpej 		    sbus, 7, 0);
    187  1.2.6.2   thorpej 		goto pinmap;
    188  1.2.6.2   thorpej 	}
    189  1.2.6.2   thorpej 
    190  1.2.6.2   thorpej 	/* Now read the PPB's secondary bus number. */
    191  1.2.6.2   thorpej 	reg = pci_conf_read(pa->pa_pc, tag, PPB_REG_BUSINFO);
    192  1.2.6.2   thorpej 	sbus = PPB_BUSINFO_SECONDARY(reg);
    193  1.2.6.2   thorpej 
    194  1.2.6.2   thorpej 	if (pa->pa_bus == sbus && pa->pa_device == 0 &&
    195  1.2.6.2   thorpej 	    pa->pa_function == 0) {
    196  1.2.6.2   thorpej 		/* On-board i82559 Ethernet! */
    197  1.2.6.2   thorpej 		*ihp = XINT3_IRQ(XINT3_ETHERNET);
    198  1.2.6.2   thorpej 		return (0);
    199  1.2.6.2   thorpej 	}
    200  1.2.6.2   thorpej 
    201  1.2.6.2   thorpej  pinmap:
    202  1.2.6.2   thorpej 	if (pa->pa_intrpin == 0) {
    203  1.2.6.2   thorpej 		/* No IRQ used. */
    204  1.2.6.2   thorpej 		return (1);
    205  1.2.6.2   thorpej 	}
    206  1.2.6.2   thorpej 	if (pa->pa_intrpin > 4) {
    207  1.2.6.2   thorpej 		printf("iq80310_pci_intr_map: bad interrupt pin %d\n",
    208  1.2.6.2   thorpej 		    pa->pa_intrpin);
    209  1.2.6.2   thorpej 		return (1);
    210  1.2.6.2   thorpej 	}
    211  1.2.6.2   thorpej 
    212  1.2.6.2   thorpej 	/* INTD# is always in XINT3. */
    213  1.2.6.2   thorpej 	if (pa->pa_intrpin == 4) {
    214  1.2.6.2   thorpej 		*ihp = XINT3_IRQ(XINT3_SINTD);
    215  1.2.6.2   thorpej 		return (0);
    216  1.2.6.2   thorpej 	}
    217  1.2.6.2   thorpej 
    218  1.2.6.2   thorpej 	/* On pre-F boards, ALL of them are on XINT3. */
    219  1.2.6.2   thorpej 	if (/*pre-F*/0)
    220  1.2.6.2   thorpej 		*ihp = XINT3_IRQ(XINT3_SINTD);
    221  1.2.6.2   thorpej 	else
    222  1.2.6.2   thorpej 		*ihp = XINT0_IRQ(pa->pa_intrpin - 1);
    223  1.2.6.2   thorpej 
    224  1.2.6.2   thorpej 	return (0);
    225  1.2.6.2   thorpej }
    226  1.2.6.4  jdolecek #endif /* list of IQ80310-based designs */
    227  1.2.6.2   thorpej 
    228  1.2.6.2   thorpej const char *
    229  1.2.6.2   thorpej iq80310_pci_intr_string(void *v, pci_intr_handle_t ih)
    230  1.2.6.2   thorpej {
    231  1.2.6.3  jdolecek 	static char irqstr[IRQNAMESIZE];
    232  1.2.6.2   thorpej 
    233  1.2.6.3  jdolecek 	sprintf(irqstr, "iq80310 irq %ld", ih);
    234  1.2.6.2   thorpej 	return (irqstr);
    235  1.2.6.2   thorpej }
    236  1.2.6.2   thorpej 
    237  1.2.6.2   thorpej const struct evcnt *
    238  1.2.6.2   thorpej iq80310_pci_intr_evcnt(void *v, pci_intr_handle_t ih)
    239  1.2.6.2   thorpej {
    240  1.2.6.2   thorpej 
    241  1.2.6.2   thorpej 	/* XXX For now. */
    242  1.2.6.2   thorpej 	return (NULL);
    243  1.2.6.2   thorpej }
    244  1.2.6.2   thorpej 
    245  1.2.6.2   thorpej void *
    246  1.2.6.2   thorpej iq80310_pci_intr_establish(void *v, pci_intr_handle_t ih, int ipl,
    247  1.2.6.2   thorpej     int (*func)(void *), void *arg)
    248  1.2.6.2   thorpej {
    249  1.2.6.2   thorpej 
    250  1.2.6.2   thorpej 	return (iq80310_intr_establish(ih, ipl, func, arg));
    251  1.2.6.2   thorpej }
    252  1.2.6.2   thorpej 
    253  1.2.6.2   thorpej void
    254  1.2.6.2   thorpej iq80310_pci_intr_disestablish(void *v, void *cookie)
    255  1.2.6.2   thorpej {
    256  1.2.6.2   thorpej 
    257  1.2.6.2   thorpej 	iq80310_intr_disestablish(cookie);
    258  1.2.6.2   thorpej }
    259