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