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