Home | History | Annotate | Line # | Download | only in pci
sio.c revision 1.31
      1 /* $NetBSD: sio.c,v 1.31 2000/07/12 20:50:00 thorpej Exp $ */
      2 
      3 /*-
      4  * Copyright (c) 2000 The NetBSD Foundation, Inc.
      5  * All rights reserved.
      6  *
      7  * This code is derived from software contributed to The NetBSD Foundation
      8  * by Jason R. Thorpe.
      9  *
     10  * Redistribution and use in source and binary forms, with or without
     11  * modification, are permitted provided that the following conditions
     12  * are met:
     13  * 1. Redistributions of source code must retain the above copyright
     14  *    notice, this list of conditions and the following disclaimer.
     15  * 2. Redistributions in binary form must reproduce the above copyright
     16  *    notice, this list of conditions and the following disclaimer in the
     17  *    documentation and/or other materials provided with the distribution.
     18  * 3. All advertising materials mentioning features or use of this software
     19  *    must display the following acknowledgement:
     20  *	This product includes software developed by the NetBSD
     21  *	Foundation, Inc. and its contributors.
     22  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23  *    contributors may be used to endorse or promote products derived
     24  *    from this software without specific prior written permission.
     25  *
     26  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36  * POSSIBILITY OF SUCH DAMAGE.
     37  */
     38 
     39 /*
     40  * Copyright (c) 1995, 1996 Carnegie-Mellon University.
     41  * All rights reserved.
     42  *
     43  * Author: Chris G. Demetriou
     44  *
     45  * Permission to use, copy, modify and distribute this software and
     46  * its documentation is hereby granted, provided that both the copyright
     47  * notice and this permission notice appear in all copies of the
     48  * software, derivative works or modified versions, and any portions
     49  * thereof, and that both notices appear in supporting documentation.
     50  *
     51  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
     52  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
     53  * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
     54  *
     55  * Carnegie Mellon requests users of this software to return to
     56  *
     57  *  Software Distribution Coordinator  or  Software.Distribution (at) CS.CMU.EDU
     58  *  School of Computer Science
     59  *  Carnegie Mellon University
     60  *  Pittsburgh PA 15213-3890
     61  *
     62  * any improvements or extensions that they make and grant Carnegie the
     63  * rights to redistribute these changes.
     64  */
     65 
     66 #include "opt_dec_2100_a500.h"
     67 #include "opt_dec_2100a_a500.h"
     68 
     69 #include <sys/cdefs.h>			/* RCS ID & Copyright macro defns */
     70 
     71 __KERNEL_RCSID(0, "$NetBSD: sio.c,v 1.31 2000/07/12 20:50:00 thorpej Exp $");
     72 
     73 #include <sys/param.h>
     74 #include <sys/systm.h>
     75 #include <sys/kernel.h>
     76 #include <sys/device.h>
     77 #include <sys/malloc.h>
     78 
     79 #include <machine/intr.h>
     80 #include <machine/bus.h>
     81 #include <machine/rpb.h>
     82 
     83 #include <dev/isa/isavar.h>
     84 #include <dev/eisa/eisavar.h>
     85 
     86 #include <dev/pci/pcireg.h>
     87 #include <dev/pci/pcivar.h>
     88 #include <dev/pci/pcidevs.h>
     89 
     90 #include <alpha/pci/siovar.h>
     91 
     92 #if defined(DEC_2100_A500) || defined(DEC_2100A_A500)
     93 #include <alpha/pci/pci_2100_a500.h>
     94 #include <alpha/sableio/sableiovar.h>
     95 #endif
     96 
     97 struct sio_softc {
     98 	struct device	sc_dv;
     99 
    100 	pci_chipset_tag_t sc_pc;
    101 
    102 	bus_space_tag_t sc_iot, sc_memt;
    103 	bus_dma_tag_t	sc_parent_dmat;
    104 	int		sc_haseisa;
    105 	int		sc_is82c693;
    106 
    107 	/* ISA chipset must persist; it's used after autoconfig. */
    108 	isa_chipset_tag_t sc_ic;
    109 };
    110 
    111 int	siomatch __P((struct device *, struct cfdata *, void *));
    112 void	sioattach __P((struct device *, struct device *, void *));
    113 
    114 struct cfattach sio_ca = {
    115 	sizeof(struct sio_softc), siomatch, sioattach,
    116 };
    117 
    118 int	pcebmatch __P((struct device *, struct cfdata *, void *));
    119 
    120 struct cfattach pceb_ca = {
    121 	sizeof(struct sio_softc), pcebmatch, sioattach,
    122 };
    123 
    124 union sio_attach_args {
    125 	const char *sa_name;			/* XXX should be common */
    126 	struct isabus_attach_args sa_iba;
    127 	struct eisabus_attach_args sa_eba;
    128 };
    129 
    130 int	sioprint __P((void *, const char *pnp));
    131 void	sio_isa_attach_hook __P((struct device *, struct device *,
    132 	    struct isabus_attach_args *));
    133 void	sio_eisa_attach_hook __P((struct device *, struct device *,
    134 	    struct eisabus_attach_args *));
    135 int	sio_eisa_maxslots __P((void *));
    136 int	sio_eisa_intr_map __P((void *, u_int, eisa_intr_handle_t *));
    137 
    138 void	sio_bridge_callback __P((struct device *));
    139 
    140 int
    141 siomatch(parent, match, aux)
    142 	struct device *parent;
    143 	struct cfdata *match;
    144 	void *aux;
    145 {
    146 	struct pci_attach_args *pa = aux;
    147 
    148 	/*
    149 	 * The Cypress 82C693 is more-or-less an SIO, but with
    150 	 * indirect register access.  (XXX for everything, or
    151 	 * just the ELCR?)
    152 	 */
    153 	if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_CONTAQ &&
    154 	    PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_CONTAQ_82C693 &&
    155 	    pa->pa_function == 0)
    156 		return (1);
    157 
    158 	if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_INTEL &&
    159 	    PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_INTEL_SIO)
    160 		return (1);
    161 
    162 	if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_ALI &&
    163 	    PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_ALI_M1543)
    164 		return (1);
    165 
    166 	return (0);
    167 }
    168 
    169 int
    170 pcebmatch(parent, match, aux)
    171 	struct device *parent;
    172 	struct cfdata *match;
    173 	void *aux;
    174 {
    175 	struct pci_attach_args *pa = aux;
    176 
    177 	if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_INTEL &&
    178 	    PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_INTEL_PCEB)
    179 		return (1);
    180 
    181 	return (0);
    182 }
    183 
    184 void
    185 sioattach(parent, self, aux)
    186 	struct device *parent, *self;
    187 	void *aux;
    188 {
    189 	struct sio_softc *sc = (struct sio_softc *)self;
    190 	struct pci_attach_args *pa = aux;
    191 	char devinfo[256];
    192 
    193 	pci_devinfo(pa->pa_id, pa->pa_class, 0, devinfo);
    194 	printf(": %s (rev. 0x%02x)\n", devinfo,
    195 	    PCI_REVISION(pa->pa_class));
    196 
    197 	sc->sc_pc = pa->pa_pc;
    198 	sc->sc_iot = pa->pa_iot;
    199 	sc->sc_memt = pa->pa_memt;
    200 	sc->sc_parent_dmat = pa->pa_dmat;
    201 	sc->sc_haseisa = (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_INTEL &&
    202 	    PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_INTEL_PCEB);
    203 	sc->sc_is82c693 = (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_CONTAQ &&
    204 	    PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_CONTAQ_82C693);
    205 
    206 	config_defer(self, sio_bridge_callback);
    207 }
    208 
    209 void
    210 sio_bridge_callback(self)
    211 	struct device *self;
    212 {
    213 	struct sio_softc *sc = (struct sio_softc *)self;
    214 	struct alpha_eisa_chipset ec;
    215 	union sio_attach_args sa;
    216 
    217 	if (sc->sc_haseisa) {
    218 		ec.ec_v = NULL;
    219 		ec.ec_attach_hook = sio_eisa_attach_hook;
    220 		ec.ec_maxslots = sio_eisa_maxslots;
    221 
    222 		/*
    223 		 * Deal with platforms that hook EISA interrupts
    224 		 * up differently.
    225 		 */
    226 		switch (cputype) {
    227 #if defined(DEC_2100_A500) || defined(DEC_2100A_A500)
    228 		case ST_DEC_2100_A500:
    229 		case ST_DEC_2100A_A500:
    230 			pci_2100_a500_eisa_pickintr(sc->sc_pc, &ec);
    231 			break;
    232 #endif
    233 		default:
    234 			ec.ec_intr_map = sio_eisa_intr_map;
    235 			ec.ec_intr_string = sio_intr_string;
    236 			ec.ec_intr_evcnt = sio_intr_evcnt;
    237 			ec.ec_intr_establish = sio_intr_establish;
    238 			ec.ec_intr_disestablish = sio_intr_disestablish;
    239 		}
    240 
    241 		sa.sa_eba.eba_busname = "eisa";
    242 		sa.sa_eba.eba_iot = sc->sc_iot;
    243 		sa.sa_eba.eba_memt = sc->sc_memt;
    244 		sa.sa_eba.eba_dmat =
    245 		    alphabus_dma_get_tag(sc->sc_parent_dmat, ALPHA_BUS_EISA);
    246 		sa.sa_eba.eba_ec = &ec;
    247 		config_found(&sc->sc_dv, &sa.sa_eba, sioprint);
    248 	}
    249 
    250 	/*
    251 	 * Deal with platforms which have Odd ISA DMA needs.
    252 	 */
    253 	switch (cputype) {
    254 #ifdef DEC_2100_A500
    255 	case ST_DEC_2100_A500:
    256 		sc->sc_ic = sableio_pickisa();
    257 		break;
    258 #endif
    259 	default:
    260 		sc->sc_ic = malloc(sizeof(*sc->sc_ic), M_DEVBUF, M_WAITOK);
    261 		memset(sc->sc_ic, 0, sizeof(*sc->sc_ic));
    262 	}
    263 
    264 	sc->sc_ic->ic_v = NULL;
    265 	sc->sc_ic->ic_attach_hook = sio_isa_attach_hook;
    266 
    267 	/*
    268 	 * Deal with platforms that hook up ISA interrupts differently.
    269 	 */
    270 	switch (cputype) {
    271 #ifdef DEC_2100_A500
    272 	case ST_DEC_2100_A500:
    273 		pci_2100_a500_isa_pickintr(sc->sc_pc, sc->sc_ic);
    274 		break;
    275 #endif
    276 	default:
    277 		sc->sc_ic->ic_intr_evcnt = sio_intr_evcnt;
    278 		sc->sc_ic->ic_intr_establish = sio_intr_establish;
    279 		sc->sc_ic->ic_intr_disestablish = sio_intr_disestablish;
    280 		sc->sc_ic->ic_intr_alloc = sio_intr_alloc;
    281 	}
    282 
    283 	sa.sa_iba.iba_busname = "isa";
    284 	sa.sa_iba.iba_iot = sc->sc_iot;
    285 	sa.sa_iba.iba_memt = sc->sc_memt;
    286 	sa.sa_iba.iba_dmat =
    287 	    alphabus_dma_get_tag(sc->sc_parent_dmat, ALPHA_BUS_ISA);
    288 	sa.sa_iba.iba_ic = sc->sc_ic;
    289 	config_found(&sc->sc_dv, &sa.sa_iba, sioprint);
    290 }
    291 
    292 int
    293 sioprint(aux, pnp)
    294 	void *aux;
    295 	const char *pnp;
    296 {
    297         register union sio_attach_args *sa = aux;
    298 
    299         if (pnp)
    300                 printf("%s at %s", sa->sa_name, pnp);
    301         return (UNCONF);
    302 }
    303 
    304 void
    305 sio_isa_attach_hook(parent, self, iba)
    306 	struct device *parent, *self;
    307 	struct isabus_attach_args *iba;
    308 {
    309 
    310 	/* Nothing to do. */
    311 }
    312 
    313 void
    314 sio_eisa_attach_hook(parent, self, eba)
    315 	struct device *parent, *self;
    316 	struct eisabus_attach_args *eba;
    317 {
    318 
    319 	/* Nothing to do. */
    320 }
    321 
    322 int
    323 sio_eisa_maxslots(v)
    324 	void *v;
    325 {
    326 
    327 	return 16;		/* as good a number as any.  only 8, maybe? */
    328 }
    329 
    330 int
    331 sio_eisa_intr_map(v, irq, ihp)
    332 	void *v;
    333 	u_int irq;
    334 	eisa_intr_handle_t *ihp;
    335 {
    336 
    337 #define	ICU_LEN		16	/* number of ISA IRQs (XXX) */
    338 
    339 	if (irq >= ICU_LEN) {
    340 		printf("sio_eisa_intr_map: bad IRQ %d\n", irq);
    341 		*ihp = -1;
    342 		return 1;
    343 	}
    344 	if (irq == 2) {
    345 		printf("sio_eisa_intr_map: changed IRQ 2 to IRQ 9\n");
    346 		irq = 9;
    347 	}
    348 
    349 	*ihp = irq;
    350 	return 0;
    351 }
    352