Home | History | Annotate | Line # | Download | only in pci
sio.c revision 1.17
      1 /* $NetBSD: sio.c,v 1.17 1997/04/07 02:01:28 cgd Exp $ */
      2 
      3 /*
      4  * Copyright (c) 1995, 1996 Carnegie-Mellon University.
      5  * All rights reserved.
      6  *
      7  * Author: Chris G. Demetriou
      8  *
      9  * Permission to use, copy, modify and distribute this software and
     10  * its documentation is hereby granted, provided that both the copyright
     11  * notice and this permission notice appear in all copies of the
     12  * software, derivative works or modified versions, and any portions
     13  * thereof, and that both notices appear in supporting documentation.
     14  *
     15  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
     16  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
     17  * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
     18  *
     19  * Carnegie Mellon requests users of this software to return to
     20  *
     21  *  Software Distribution Coordinator  or  Software.Distribution (at) CS.CMU.EDU
     22  *  School of Computer Science
     23  *  Carnegie Mellon University
     24  *  Pittsburgh PA 15213-3890
     25  *
     26  * any improvements or extensions that they make and grant Carnegie the
     27  * rights to redistribute these changes.
     28  */
     29 
     30 #include <machine/options.h>		/* Pull in config options headers */
     31 
     32 #include <sys/param.h>
     33 #include <sys/systm.h>
     34 #include <sys/kernel.h>
     35 #include <sys/device.h>
     36 
     37 #include <machine/intr.h>
     38 #include <machine/bus.h>
     39 
     40 #include <dev/isa/isavar.h>
     41 #include <dev/eisa/eisavar.h>
     42 
     43 #include <dev/pci/pcireg.h>
     44 #include <dev/pci/pcivar.h>
     45 #include <dev/pci/pcidevs.h>
     46 
     47 #include <alpha/pci/siovar.h>
     48 
     49 struct sio_softc {
     50 	struct device	sc_dv;
     51 
     52 	bus_space_tag_t sc_iot, sc_memt;
     53 	int		sc_haseisa;
     54 };
     55 
     56 int	siomatch __P((struct device *, struct cfdata *, void *));
     57 void	sioattach __P((struct device *, struct device *, void *));
     58 
     59 struct cfattach sio_ca = {
     60 	sizeof(struct sio_softc), siomatch, sioattach,
     61 };
     62 
     63 struct cfdriver sio_cd = {
     64 	NULL, "sio", DV_DULL,
     65 };
     66 
     67 int	pcebmatch __P((struct device *, struct cfdata *, void *));
     68 
     69 struct cfattach pceb_ca = {
     70 	sizeof(struct device), pcebmatch, sioattach,
     71 };
     72 
     73 struct cfdriver pceb_cd = {
     74 	NULL, "pceb", DV_DULL,
     75 };
     76 
     77 union sio_attach_args {
     78 	const char *sa_name;			/* XXX should be common */
     79 	struct isabus_attach_args sa_iba;
     80 	struct eisabus_attach_args sa_eba;
     81 };
     82 
     83 int	sioprint __P((void *, const char *pnp));
     84 void	sio_isa_attach_hook __P((struct device *, struct device *,
     85 	    struct isabus_attach_args *));
     86 void	sio_eisa_attach_hook __P((struct device *, struct device *,
     87 	    struct eisabus_attach_args *));
     88 int	sio_eisa_maxslots __P((void *));
     89 int	sio_eisa_intr_map __P((void *, u_int, eisa_intr_handle_t *));
     90 
     91 void	sio_bridge_callback __P((void *));
     92 
     93 int
     94 siomatch(parent, match, aux)
     95 	struct device *parent;
     96 	struct cfdata *match;
     97 	void *aux;
     98 {
     99 	struct pci_attach_args *pa = aux;
    100 
    101 	if (PCI_VENDOR(pa->pa_id) != PCI_VENDOR_INTEL ||
    102 	    PCI_PRODUCT(pa->pa_id) != PCI_PRODUCT_INTEL_SIO)
    103 		return (0);
    104 
    105 	return (1);
    106 }
    107 
    108 int
    109 pcebmatch(parent, match, aux)
    110 	struct device *parent;
    111 	struct cfdata *match;
    112 	void *aux;
    113 {
    114 	struct pci_attach_args *pa = aux;
    115 
    116 	if (PCI_VENDOR(pa->pa_id) != PCI_VENDOR_INTEL ||
    117 	    PCI_PRODUCT(pa->pa_id) != PCI_PRODUCT_INTEL_PCEB)
    118 		return (0);
    119 
    120 	return (1);
    121 }
    122 
    123 void
    124 sioattach(parent, self, aux)
    125 	struct device *parent, *self;
    126 	void *aux;
    127 {
    128 	struct sio_softc *sc = (struct sio_softc *)self;
    129 	struct pci_attach_args *pa = aux;
    130 	char devinfo[256];
    131 
    132 	pci_devinfo(pa->pa_id, pa->pa_class, 0, devinfo);
    133 	printf(": %s (rev. 0x%02x)\n", devinfo,
    134 	    PCI_REVISION(pa->pa_class));
    135 
    136 	sc->sc_iot = pa->pa_iot;
    137 	sc->sc_memt = pa->pa_memt;
    138 	sc->sc_haseisa = (PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_INTEL_PCEB);
    139 
    140 #ifdef EVCNT_COUNTERS
    141 	evcnt_attach(&sc->sc_dv, "intr", &sio_intr_evcnt);
    142 #endif
    143 
    144 	set_pci_isa_bridge_callback(sio_bridge_callback, sc);
    145 }
    146 
    147 void
    148 sio_bridge_callback(v)
    149 	void *v;
    150 {
    151 	struct sio_softc *sc = v;
    152 	struct alpha_eisa_chipset ec;
    153 	struct alpha_isa_chipset ic;
    154 	union sio_attach_args sa;
    155 
    156 	if (sc->sc_haseisa) {
    157 		ec.ec_v = NULL;
    158 		ec.ec_attach_hook = sio_eisa_attach_hook;
    159 		ec.ec_maxslots = sio_eisa_maxslots;
    160 		ec.ec_intr_map = sio_eisa_intr_map;
    161 		ec.ec_intr_string = sio_intr_string;
    162 		ec.ec_intr_establish = sio_intr_establish;
    163 		ec.ec_intr_disestablish = sio_intr_disestablish;
    164 
    165 		sa.sa_eba.eba_busname = "eisa";
    166 		sa.sa_eba.eba_iot = sc->sc_iot;
    167 		sa.sa_eba.eba_memt = sc->sc_memt;
    168 		sa.sa_eba.eba_ec = &ec;
    169 		config_found(&sc->sc_dv, &sa.sa_eba, sioprint);
    170 	}
    171 
    172 	ic.ic_v = NULL;
    173 	ic.ic_attach_hook = sio_isa_attach_hook;
    174 	ic.ic_intr_establish = sio_intr_establish;
    175 	ic.ic_intr_disestablish = sio_intr_disestablish;
    176 
    177 	sa.sa_iba.iba_busname = "isa";
    178 	sa.sa_iba.iba_iot = sc->sc_iot;
    179 	sa.sa_iba.iba_memt = sc->sc_memt;
    180 	sa.sa_iba.iba_ic = &ic;
    181 	config_found(&sc->sc_dv, &sa.sa_iba, sioprint);
    182 }
    183 
    184 int
    185 sioprint(aux, pnp)
    186 	void *aux;
    187 	const char *pnp;
    188 {
    189         register union sio_attach_args *sa = aux;
    190 
    191         if (pnp)
    192                 printf("%s at %s", sa->sa_name, pnp);
    193         return (UNCONF);
    194 }
    195 
    196 void
    197 sio_isa_attach_hook(parent, self, iba)
    198 	struct device *parent, *self;
    199 	struct isabus_attach_args *iba;
    200 {
    201 
    202 	/* Nothing to do. */
    203 }
    204 
    205 void
    206 sio_eisa_attach_hook(parent, self, eba)
    207 	struct device *parent, *self;
    208 	struct eisabus_attach_args *eba;
    209 {
    210 
    211 	/* Nothing to do. */
    212 }
    213 
    214 int
    215 sio_eisa_maxslots(v)
    216 	void *v;
    217 {
    218 
    219 	return 16;		/* as good a number as any.  only 8, maybe? */
    220 }
    221 
    222 int
    223 sio_eisa_intr_map(v, irq, ihp)
    224 	void *v;
    225 	u_int irq;
    226 	eisa_intr_handle_t *ihp;
    227 {
    228 
    229 #define	ICU_LEN		16	/* number of ISA IRQs (XXX) */
    230 
    231 	if (irq >= ICU_LEN) {
    232 		printf("sio_eisa_intr_map: bad IRQ %d\n", irq);
    233 		*ihp = -1;
    234 		return 1;
    235 	}
    236 	if (irq == 2) {
    237 		printf("sio_eisa_intr_map: changed IRQ 2 to IRQ 9\n");
    238 		irq = 9;
    239 	}
    240 
    241 	*ihp = irq;
    242 	return 0;
    243 }
    244