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