Home | History | Annotate | Line # | Download | only in sableio
sableio.c revision 1.9
      1 /* $NetBSD: sableio.c,v 1.9 2005/08/25 18:35:38 drochner Exp $ */
      2 
      3 /*-
      4  * Copyright (c) 1999, 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  * Driver glue for the Sable STDIO module.
     41  *
     42  * This is kind of a hack.  The STDIO is really a junk I/O module with
     43  * your regular ISA junk peripherals and their regular ISA I/O addresses.
     44  * However, the main issue we have here is *interrupts*.  Not only are
     45  * devices IRQs strange (i.e. not what you would expect to find if they
     46  * were attached to a real ISA) IRQs, the keyboard controller isn't even
     47  * connected to the (E)ISA IRQ space at all!
     48  *
     49  * In short, we're gluing together the following things:
     50  *
     51  *	- Standard ISA junk I/O chip
     52  *	- ISA DMA
     53  *	- Pre-mapped "PCI" interrupts that are *edge triggered*
     54  */
     55 
     56 #include <sys/cdefs.h>			/* RCS ID & Copyright macro defns */
     57 
     58 __KERNEL_RCSID(0, "$NetBSD: sableio.c,v 1.9 2005/08/25 18:35:38 drochner Exp $");
     59 
     60 #include "isadma.h"
     61 
     62 #include <sys/param.h>
     63 #include <sys/systm.h>
     64 #include <sys/device.h>
     65 
     66 #include <dev/isa/isareg.h>
     67 #include <dev/isa/isavar.h>
     68 #include <dev/isa/isadmavar.h>
     69 
     70 #include <dev/pci/pcivar.h>
     71 
     72 #include <alpha/sableio/sableiovar.h>
     73 
     74 #include "locators.h"
     75 
     76 /*
     77  * The devices built-in to the Sable STDIO module.
     78  */
     79 const struct sableio_dev {
     80 	const char *sd_name;		/* device name */
     81 	bus_addr_t sd_ioaddr;		/* I/O space address */
     82 	int sd_sableirq[2];		/* Sable IRQs */
     83 	int sd_drq;			/* ISA DRQ */
     84 } sableio_devs[] = {
     85 	/*
     86 	 * See alpha/pci/pci_2100_a500.c for interrupt information.
     87 	 */
     88 	{ "pckbc",	IO_KBD,		{ 6, 3 },	-1 },
     89 	{ "fdc",	IO_FD1,		{ 7, -1 },	2 },
     90 	{ "com",	IO_COM1,	{ 15, -1 },	-1 },
     91 	{ "com",	IO_COM2,	{ 8, -1 },	-1 },
     92 	{ "lpt",	IO_LPT3,	{ 9, -1 },	-1 },
     93 	{ NULL,		0,		{ -1, -1 },	-1 },
     94 };
     95 
     96 struct sableio_softc {
     97 	struct device	sc_dev;		/* base device */
     98 
     99 	/*
    100 	 * We have to deal with ISA DMA, so that means we have to
    101 	 * hold the ISA chipset, since we attach STDIO devices
    102 	 * before we attach the PCI (and thus EISA) bus.
    103 	 */
    104 	struct alpha_isa_chipset sc_isa_chipset;
    105 };
    106 
    107 int	sableio_match(struct device *, struct cfdata *, void *);
    108 void	sableio_attach(struct device *, struct device *, void *);
    109 
    110 CFATTACH_DECL(sableio, sizeof(struct sableio_softc),
    111     sableio_match, sableio_attach, NULL, NULL);
    112 
    113 int	sableio_print(void *, const char *);
    114 int	sableio_submatch(struct device *, struct cfdata *,
    115 			 const locdesc_t *, void *);
    116 
    117 struct sableio_softc *sableio_attached;
    118 
    119 int
    120 sableio_match(struct device *parent, struct cfdata *cf, void *aux)
    121 {
    122 	struct pcibus_attach_args *pba = aux;
    123 
    124 	/*
    125 	 * These are really ISA devices, and thus must be on
    126 	 * PCI bus 0.
    127 	 */
    128 	if (cf->cf_loc[SABLEIOBUSCF_BUS] != SABLEIOBUSCF_BUS_DEFAULT &&
    129 	    cf->cf_loc[SABLEIOBUSCF_BUS] != pba->pba_bus)
    130 		return (0);
    131 
    132 	/* sanity */
    133 	if (pba->pba_bus != 0)
    134 		return (0);
    135 
    136 	/* There can be only one. */
    137 	if (sableio_attached != NULL)
    138 		return (0);
    139 
    140 	return (1);
    141 }
    142 
    143 void
    144 sableio_attach(struct device *parent, struct device *self, void *aux)
    145 {
    146 	struct sableio_softc *sc = (void *) self;
    147 	struct pcibus_attach_args *pba = aux;
    148 	struct sableio_attach_args sa;
    149 	bus_dma_tag_t dmat;
    150 	int i;
    151 	int locs[SABLEIOCF_NLOCS];
    152 
    153 	printf(": Sable STDIO module\n");
    154 
    155 	sableio_attached = sc;
    156 
    157 	dmat = alphabus_dma_get_tag(pba->pba_dmat, ALPHA_BUS_ISA);
    158 
    159 #if NISADMA > 0
    160 	/*
    161 	 * Initialize our DMA state.
    162 	 */
    163 	isa_dmainit(&sc->sc_isa_chipset, pba->pba_iot, dmat, self);
    164 #endif
    165 
    166 	for (i = 0; sableio_devs[i].sd_name != NULL; i++) {
    167 		sa.sa_name = sableio_devs[i].sd_name;
    168 		sa.sa_ioaddr = sableio_devs[i].sd_ioaddr;
    169 		sa.sa_sableirq[0] = sableio_devs[i].sd_sableirq[0];
    170 		sa.sa_sableirq[1] = sableio_devs[i].sd_sableirq[1];
    171 		sa.sa_drq = sableio_devs[i].sd_drq;
    172 
    173 		sa.sa_iot = pba->pba_iot;
    174 		sa.sa_dmat = dmat;
    175 		sa.sa_ic = &sc->sc_isa_chipset;
    176 		sa.sa_pc = pba->pba_pc;
    177 
    178 		locs[SABLEIOCF_PORT] = sableio_devs[i].sd_ioaddr;
    179 
    180 		(void) config_found_sm_loc(self, "sableio", locs, &sa,
    181 					   sableio_print, sableio_submatch);
    182 	}
    183 }
    184 
    185 int
    186 sableio_submatch(struct device *parent, struct cfdata *cf,
    187 		 const locdesc_t *locs, void *aux)
    188 {
    189 
    190 	if (cf->cf_loc[SABLEIOCF_PORT] != SABLEIOCF_PORT_DEFAULT &&
    191 	    cf->cf_loc[SABLEIOCF_PORT] != locs[SABLEIOCF_PORT])
    192 		return (0);
    193 
    194 	return (config_match(parent, cf, aux));
    195 }
    196 
    197 int
    198 sableio_print(void *aux, const char *pnp)
    199 {
    200 	struct sableio_attach_args *sa = aux;
    201 
    202 	if (pnp != NULL)
    203 		aprint_normal("%s at %s", sa->sa_name, pnp);
    204 
    205 	aprint_normal(" port 0x%lx", sa->sa_ioaddr);
    206 	return (UNCONF);
    207 }
    208 
    209 isa_chipset_tag_t
    210 sableio_pickisa(void)
    211 {
    212 
    213 	if (sableio_attached == NULL)
    214 		panic("sableio_pickisa");
    215 
    216 	return (&sableio_attached->sc_isa_chipset);
    217 }
    218