Home | History | Annotate | Line # | Download | only in pci
sio.c revision 1.50
      1 /* $NetBSD: sio.c,v 1.50 2011/06/14 15:34:22 matt 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.50 2011/06/14 15:34:22 matt 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 	device_t	sc_dev;
     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(device_t, cfdata_t, void *);
    109 void	sioattach(device_t, device_t, void *);
    110 
    111 CFATTACH_DECL_NEW(sio, sizeof(struct sio_softc),
    112     siomatch, sioattach, NULL, NULL);
    113 
    114 #if NPCEB > 0
    115 int	pcebmatch(device_t, cfdata_t, void *);
    116 
    117 CFATTACH_DECL_NEW(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(device_t, device_t,
    127 	    struct isabus_attach_args *);
    128 void	sio_isa_detach_hook(isa_chipset_tag_t, device_t);
    129 #if NPCEB > 0
    130 void	sio_eisa_attach_hook(device_t, device_t,
    131 	    struct eisabus_attach_args *);
    132 int	sio_eisa_maxslots(void *);
    133 int	sio_eisa_intr_map(void *, u_int, eisa_intr_handle_t *);
    134 #endif
    135 
    136 void	sio_bridge_callback(device_t);
    137 
    138 int
    139 siomatch(device_t parent, cfdata_t match, void *aux)
    140 {
    141 	struct pci_attach_args *pa = aux;
    142 
    143 	/*
    144 	 * The Cypress 82C693 is more-or-less an SIO, but with
    145 	 * indirect register access.  (XXX for everything, or
    146 	 * just the ELCR?)
    147 	 */
    148 	if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_CONTAQ &&
    149 	    PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_CONTAQ_82C693 &&
    150 	    pa->pa_function == 0)
    151 		return (1);
    152 
    153 	if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_INTEL &&
    154 	    PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_INTEL_SIO)
    155 		return (1);
    156 
    157 	if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_ALI &&
    158 	    PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_ALI_M1533)
    159 		return (1);
    160 
    161 	return (0);
    162 }
    163 
    164 #if NPCEB > 0
    165 int
    166 pcebmatch(device_t parent, cfdata_t match, void *aux)
    167 {
    168 	struct pci_attach_args *pa = aux;
    169 
    170 	if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_INTEL &&
    171 	    PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_INTEL_PCEB)
    172 		return (1);
    173 
    174 	return (0);
    175 }
    176 #endif
    177 
    178 void
    179 sioattach(device_t parent, device_t self, void *aux)
    180 {
    181 	struct sio_softc *sc = device_private(self);
    182 	struct pci_attach_args *pa = aux;
    183 	char devinfo[256];
    184 
    185 	pci_devinfo(pa->pa_id, pa->pa_class, 0, devinfo, sizeof(devinfo));
    186 	aprint_normal(": %s (rev. 0x%02x)\n", devinfo,
    187 	    PCI_REVISION(pa->pa_class));
    188 
    189 	sc->sc_dev = self;
    190 	sc->sc_pc = pa->pa_pc;
    191 	sc->sc_iot = pa->pa_iot;
    192 	sc->sc_memt = pa->pa_memt;
    193 	sc->sc_parent_dmat = pa->pa_dmat;
    194 #if NPCEB > 0
    195 	sc->sc_haseisa = (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_INTEL &&
    196 	    PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_INTEL_PCEB);
    197 #endif
    198 	sc->sc_is82c693 = (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_CONTAQ &&
    199 	    PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_CONTAQ_82C693);
    200 
    201 	config_defer(self, sio_bridge_callback);
    202 }
    203 
    204 void
    205 sio_bridge_callback(device_t self)
    206 {
    207 	struct sio_softc *sc = device_private(self);
    208 	union sio_attach_args sa;
    209 #if NPCEB > 0
    210 	struct alpha_eisa_chipset ec;
    211 
    212 	if (sc->sc_haseisa) {
    213 		ec.ec_v = NULL;
    214 		ec.ec_attach_hook = sio_eisa_attach_hook;
    215 		ec.ec_maxslots = sio_eisa_maxslots;
    216 
    217 		/*
    218 		 * Deal with platforms that hook EISA interrupts
    219 		 * up differently.
    220 		 */
    221 		switch (cputype) {
    222 #if defined(DEC_2100_A500) || defined(DEC_2100A_A500)
    223 		case ST_DEC_2100_A500:
    224 		case ST_DEC_2100A_A500:
    225 			pci_2100_a500_eisa_pickintr(sc->sc_pc, &ec);
    226 			break;
    227 #endif
    228 		default:
    229 			ec.ec_intr_map = sio_eisa_intr_map;
    230 			ec.ec_intr_string = sio_intr_string;
    231 			ec.ec_intr_evcnt = sio_intr_evcnt;
    232 			ec.ec_intr_establish = sio_intr_establish;
    233 			ec.ec_intr_disestablish = sio_intr_disestablish;
    234 		}
    235 
    236 		sa.sa_eba.eba_iot = sc->sc_iot;
    237 		sa.sa_eba.eba_memt = sc->sc_memt;
    238 		sa.sa_eba.eba_dmat =
    239 		    alphabus_dma_get_tag(sc->sc_parent_dmat, ALPHA_BUS_EISA);
    240 		sa.sa_eba.eba_ec = &ec;
    241 		config_found_ia(sc->sc_dev, "eisabus", &sa.sa_eba,
    242 				eisabusprint);
    243 	}
    244 #endif /* NPCEB */
    245 
    246 	/*
    247 	 * Deal with platforms which have Odd ISA DMA needs.
    248 	 */
    249 	switch (cputype) {
    250 #if defined(DEC_2100_A500) || defined(DEC_2100A_A500)
    251 	case ST_DEC_2100_A500:
    252 	case ST_DEC_2100A_A500:
    253 		sc->sc_ic = sableio_pickisa();
    254 		break;
    255 #endif
    256 	default:
    257 		sc->sc_ic = malloc(sizeof(*sc->sc_ic), M_DEVBUF, M_WAITOK);
    258 		memset(sc->sc_ic, 0, sizeof(*sc->sc_ic));
    259 	}
    260 
    261 	sc->sc_ic->ic_v = NULL;
    262 	sc->sc_ic->ic_attach_hook = sio_isa_attach_hook;
    263 	sc->sc_ic->ic_detach_hook = sio_isa_detach_hook;
    264 
    265 	/*
    266 	 * Deal with platforms that hook up ISA interrupts differently.
    267 	 */
    268 	switch (cputype) {
    269 #if defined(DEC_2100_A500) || defined(DEC_2100A_A500)
    270 	case ST_DEC_2100_A500:
    271 	case ST_DEC_2100A_A500:
    272 		pci_2100_a500_isa_pickintr(sc->sc_pc, sc->sc_ic);
    273 		break;
    274 #endif
    275 	default:
    276 		sc->sc_ic->ic_intr_evcnt = sio_intr_evcnt;
    277 		sc->sc_ic->ic_intr_establish = sio_intr_establish;
    278 		sc->sc_ic->ic_intr_disestablish = sio_intr_disestablish;
    279 		sc->sc_ic->ic_intr_alloc = sio_intr_alloc;
    280 	}
    281 
    282 	sa.sa_iba.iba_iot = sc->sc_iot;
    283 	sa.sa_iba.iba_memt = sc->sc_memt;
    284 	sa.sa_iba.iba_dmat =
    285 	    alphabus_dma_get_tag(sc->sc_parent_dmat, ALPHA_BUS_ISA);
    286 	sa.sa_iba.iba_ic = sc->sc_ic;
    287 	config_found_ia(sc->sc_dev, "isabus", &sa.sa_iba, isabusprint);
    288 }
    289 
    290 void
    291 sio_isa_attach_hook(device_t parent, device_t self, struct isabus_attach_args *iba)
    292 {
    293 
    294 	/* Nothing to do. */
    295 }
    296 
    297 void
    298 sio_isa_detach_hook(isa_chipset_tag_t ic, device_t self)
    299 {
    300 
    301 	/* Nothing to do. */
    302 }
    303 
    304 #if NPCEB > 0
    305 
    306 void
    307 sio_eisa_attach_hook(device_t parent, device_t self, struct eisabus_attach_args *eba)
    308 {
    309 
    310 #if NEISA > 0
    311 	eisa_init(eba->eba_ec);
    312 #endif
    313 }
    314 
    315 int
    316 sio_eisa_maxslots(void *v)
    317 {
    318 
    319 	return 16;		/* as good a number as any.  only 8, maybe? */
    320 }
    321 
    322 int
    323 sio_eisa_intr_map(void *v, u_int irq, eisa_intr_handle_t *ihp)
    324 {
    325 
    326 #define	ICU_LEN		16	/* number of ISA IRQs (XXX) */
    327 
    328 	if (irq >= ICU_LEN) {
    329 		printf("sio_eisa_intr_map: bad IRQ %d\n", irq);
    330 		*ihp = -1;
    331 		return 1;
    332 	}
    333 	if (irq == 2) {
    334 		printf("sio_eisa_intr_map: changed IRQ 2 to IRQ 9\n");
    335 		irq = 9;
    336 	}
    337 
    338 	*ihp = irq;
    339 	return 0;
    340 }
    341 
    342 #endif /* NPCEB */
    343