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