Home | History | Annotate | Line # | Download | only in sableio
sableio.c revision 1.6
      1  1.6  thorpej /* $NetBSD: sableio.c,v 1.6 2003/01/01 00:39:20 thorpej Exp $ */
      2  1.1  thorpej 
      3  1.1  thorpej /*-
      4  1.1  thorpej  * Copyright (c) 1999, 2000 The NetBSD Foundation, Inc.
      5  1.1  thorpej  * All rights reserved.
      6  1.1  thorpej  *
      7  1.1  thorpej  * This code is derived from software contributed to The NetBSD Foundation
      8  1.1  thorpej  * by Jason R. Thorpe.
      9  1.1  thorpej  *
     10  1.1  thorpej  * Redistribution and use in source and binary forms, with or without
     11  1.1  thorpej  * modification, are permitted provided that the following conditions
     12  1.1  thorpej  * are met:
     13  1.1  thorpej  * 1. Redistributions of source code must retain the above copyright
     14  1.1  thorpej  *    notice, this list of conditions and the following disclaimer.
     15  1.1  thorpej  * 2. Redistributions in binary form must reproduce the above copyright
     16  1.1  thorpej  *    notice, this list of conditions and the following disclaimer in the
     17  1.1  thorpej  *    documentation and/or other materials provided with the distribution.
     18  1.1  thorpej  * 3. All advertising materials mentioning features or use of this software
     19  1.1  thorpej  *    must display the following acknowledgement:
     20  1.1  thorpej  *	This product includes software developed by the NetBSD
     21  1.1  thorpej  *	Foundation, Inc. and its contributors.
     22  1.1  thorpej  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23  1.1  thorpej  *    contributors may be used to endorse or promote products derived
     24  1.1  thorpej  *    from this software without specific prior written permission.
     25  1.1  thorpej  *
     26  1.1  thorpej  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27  1.1  thorpej  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28  1.1  thorpej  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29  1.1  thorpej  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30  1.1  thorpej  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31  1.1  thorpej  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32  1.1  thorpej  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33  1.1  thorpej  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34  1.1  thorpej  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35  1.1  thorpej  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36  1.1  thorpej  * POSSIBILITY OF SUCH DAMAGE.
     37  1.1  thorpej  */
     38  1.1  thorpej 
     39  1.1  thorpej /*
     40  1.1  thorpej  * Driver glue for the Sable STDIO module.
     41  1.1  thorpej  *
     42  1.1  thorpej  * This is kind of a hack.  The STDIO is really a junk I/O module with
     43  1.1  thorpej  * your regular ISA junk peripherals and their regular ISA I/O addresses.
     44  1.1  thorpej  * However, the main issue we have here is *interrupts*.  Not only are
     45  1.1  thorpej  * devices IRQs strange (i.e. not what you would expect to find if they
     46  1.1  thorpej  * were attached to a real ISA) IRQs, the keyboard controller isn't even
     47  1.1  thorpej  * connected to the (E)ISA IRQ space at all!
     48  1.1  thorpej  *
     49  1.1  thorpej  * In short, we're gluing together the following things:
     50  1.1  thorpej  *
     51  1.1  thorpej  *	- Standard ISA junk I/O chip
     52  1.1  thorpej  *	- ISA DMA
     53  1.1  thorpej  *	- Pre-mapped "PCI" interrupts that are *edge triggered*
     54  1.1  thorpej  */
     55  1.1  thorpej 
     56  1.1  thorpej #include <sys/cdefs.h>			/* RCS ID & Copyright macro defns */
     57  1.1  thorpej 
     58  1.6  thorpej __KERNEL_RCSID(0, "$NetBSD: sableio.c,v 1.6 2003/01/01 00:39:20 thorpej Exp $");
     59  1.1  thorpej 
     60  1.1  thorpej #include "isadma.h"
     61  1.1  thorpej 
     62  1.1  thorpej #include <sys/param.h>
     63  1.1  thorpej #include <sys/systm.h>
     64  1.1  thorpej #include <sys/device.h>
     65  1.1  thorpej 
     66  1.1  thorpej #include <dev/isa/isareg.h>
     67  1.1  thorpej #include <dev/isa/isavar.h>
     68  1.1  thorpej #include <dev/isa/isadmavar.h>
     69  1.1  thorpej 
     70  1.1  thorpej #include <dev/pci/pcivar.h>
     71  1.1  thorpej 
     72  1.1  thorpej #include <alpha/sableio/sableiovar.h>
     73  1.1  thorpej 
     74  1.1  thorpej /*
     75  1.1  thorpej  * The devices built-in to the Sable STDIO module.
     76  1.1  thorpej  */
     77  1.1  thorpej const struct sableio_dev {
     78  1.1  thorpej 	const char *sd_name;		/* device name */
     79  1.1  thorpej 	bus_addr_t sd_ioaddr;		/* I/O space address */
     80  1.1  thorpej 	int sd_sableirq[2];		/* Sable IRQs */
     81  1.1  thorpej 	int sd_drq;			/* ISA DRQ */
     82  1.1  thorpej } sableio_devs[] = {
     83  1.1  thorpej 	/*
     84  1.1  thorpej 	 * See alpha/pci/pci_2100_a500.c for interrupt information.
     85  1.1  thorpej 	 */
     86  1.1  thorpej 	{ "pckbc",	IO_KBD,		{ 6, 3 },	-1 },
     87  1.1  thorpej 	{ "fdc",	IO_FD1,		{ 7, -1 },	2 },
     88  1.1  thorpej 	{ "com",	IO_COM1,	{ 15, -1 },	-1 },
     89  1.1  thorpej 	{ "com",	IO_COM2,	{ 8, -1 },	-1 },
     90  1.1  thorpej 	{ "lpt",	IO_LPT3,	{ 9, -1 },	-1 },
     91  1.1  thorpej 	{ NULL,		0,		{ -1, -1 },	-1 },
     92  1.1  thorpej };
     93  1.1  thorpej 
     94  1.1  thorpej struct sableio_softc {
     95  1.1  thorpej 	struct device	sc_dev;		/* base device */
     96  1.1  thorpej 
     97  1.1  thorpej 	/*
     98  1.1  thorpej 	 * We have to deal with ISA DMA, so that means we have to
     99  1.1  thorpej 	 * hold the ISA chipset, since we attach STDIO devices
    100  1.1  thorpej 	 * before we attach the PCI (and thus EISA) bus.
    101  1.1  thorpej 	 */
    102  1.1  thorpej 	struct alpha_isa_chipset sc_isa_chipset;
    103  1.1  thorpej };
    104  1.1  thorpej 
    105  1.1  thorpej int	sableio_match(struct device *, struct cfdata *, void *);
    106  1.1  thorpej void	sableio_attach(struct device *, struct device *, void *);
    107  1.1  thorpej 
    108  1.5  thorpej CFATTACH_DECL(sableio, sizeof(struct sableio_softc),
    109  1.5  thorpej     sableio_match, sableio_attach, NULL, NULL);
    110  1.1  thorpej 
    111  1.1  thorpej int	sableio_print(void *, const char *);
    112  1.1  thorpej int	sableio_submatch(struct device *, struct cfdata *, void *);
    113  1.1  thorpej 
    114  1.1  thorpej struct sableio_softc *sableio_attached;
    115  1.1  thorpej 
    116  1.1  thorpej int
    117  1.1  thorpej sableio_match(struct device *parent, struct cfdata *cf, void *aux)
    118  1.1  thorpej {
    119  1.1  thorpej 	struct pcibus_attach_args *pba = aux;
    120  1.1  thorpej 
    121  1.2  thorpej 	if (strcmp(pba->pba_busname, cf->cf_name) != 0)
    122  1.1  thorpej 		return (0);
    123  1.1  thorpej 
    124  1.1  thorpej 	/*
    125  1.1  thorpej 	 * These are really ISA devices, and thus must be on
    126  1.1  thorpej 	 * PCI bus 0.
    127  1.1  thorpej 	 */
    128  1.1  thorpej 	if (cf->pcibuscf_bus != PCIBUS_UNK_BUS &&
    129  1.1  thorpej 	    cf->pcibuscf_bus != pba->pba_bus)
    130  1.1  thorpej 		return (0);
    131  1.1  thorpej 
    132  1.1  thorpej 	/* sanity */
    133  1.1  thorpej 	if (pba->pba_bus != 0)
    134  1.1  thorpej 		return (0);
    135  1.1  thorpej 
    136  1.1  thorpej 	/* There can be only one. */
    137  1.1  thorpej 	if (sableio_attached != NULL)
    138  1.1  thorpej 		return (0);
    139  1.1  thorpej 
    140  1.1  thorpej 	return (1);
    141  1.1  thorpej }
    142  1.1  thorpej 
    143  1.1  thorpej void
    144  1.1  thorpej sableio_attach(struct device *parent, struct device *self, void *aux)
    145  1.1  thorpej {
    146  1.1  thorpej 	struct sableio_softc *sc = (void *) self;
    147  1.1  thorpej 	struct pcibus_attach_args *pba = aux;
    148  1.1  thorpej 	struct sableio_attach_args sa;
    149  1.1  thorpej 	bus_dma_tag_t dmat;
    150  1.1  thorpej 	int i;
    151  1.1  thorpej 
    152  1.1  thorpej 	printf(": Sable STDIO module\n");
    153  1.1  thorpej 
    154  1.1  thorpej 	sableio_attached = sc;
    155  1.1  thorpej 
    156  1.1  thorpej 	dmat = alphabus_dma_get_tag(pba->pba_dmat, ALPHA_BUS_ISA);
    157  1.1  thorpej 
    158  1.1  thorpej #if NISADMA > 0
    159  1.1  thorpej 	/*
    160  1.1  thorpej 	 * Initialize our DMA state.
    161  1.1  thorpej 	 */
    162  1.1  thorpej 	isa_dmainit(&sc->sc_isa_chipset, pba->pba_iot, dmat, self);
    163  1.1  thorpej #endif
    164  1.1  thorpej 
    165  1.1  thorpej 	for (i = 0; sableio_devs[i].sd_name != NULL; i++) {
    166  1.1  thorpej 		sa.sa_name = sableio_devs[i].sd_name;
    167  1.1  thorpej 		sa.sa_ioaddr = sableio_devs[i].sd_ioaddr;
    168  1.1  thorpej 		sa.sa_sableirq[0] = sableio_devs[i].sd_sableirq[0];
    169  1.1  thorpej 		sa.sa_sableirq[1] = sableio_devs[i].sd_sableirq[1];
    170  1.1  thorpej 		sa.sa_drq = sableio_devs[i].sd_drq;
    171  1.1  thorpej 
    172  1.1  thorpej 		sa.sa_iot = pba->pba_iot;
    173  1.1  thorpej 		sa.sa_dmat = dmat;
    174  1.1  thorpej 		sa.sa_ic = &sc->sc_isa_chipset;
    175  1.1  thorpej 		sa.sa_pc = pba->pba_pc;
    176  1.1  thorpej 
    177  1.1  thorpej 		(void) config_found_sm(self, &sa, sableio_print,
    178  1.1  thorpej 		    sableio_submatch);
    179  1.1  thorpej 	}
    180  1.1  thorpej }
    181  1.1  thorpej 
    182  1.1  thorpej int
    183  1.1  thorpej sableio_submatch(struct device *parent, struct cfdata *cf, void *aux)
    184  1.1  thorpej {
    185  1.1  thorpej 	struct sableio_attach_args *sa = aux;
    186  1.1  thorpej 
    187  1.1  thorpej 	if (cf->cf_loc[SABLEIOCF_PORT] != SABLEIOCF_PORT_DEFAULT &&
    188  1.1  thorpej 	    cf->cf_loc[SABLEIOCF_PORT] != sa->sa_ioaddr)
    189  1.1  thorpej 		return (0);
    190  1.1  thorpej 
    191  1.3  thorpej 	return (config_match(parent, cf, aux));
    192  1.1  thorpej }
    193  1.1  thorpej 
    194  1.1  thorpej int
    195  1.1  thorpej sableio_print(void *aux, const char *pnp)
    196  1.1  thorpej {
    197  1.1  thorpej 	struct sableio_attach_args *sa = aux;
    198  1.1  thorpej 
    199  1.1  thorpej 	if (pnp != NULL)
    200  1.6  thorpej 		aprint_normal("%s at %s", sa->sa_name, pnp);
    201  1.1  thorpej 
    202  1.6  thorpej 	aprint_normal(" port 0x%lx", sa->sa_ioaddr);
    203  1.1  thorpej 	return (UNCONF);
    204  1.1  thorpej }
    205  1.1  thorpej 
    206  1.1  thorpej isa_chipset_tag_t
    207  1.1  thorpej sableio_pickisa(void)
    208  1.1  thorpej {
    209  1.1  thorpej 
    210  1.1  thorpej 	if (sableio_attached == NULL)
    211  1.1  thorpej 		panic("sableio_pickisa");
    212  1.1  thorpej 
    213  1.1  thorpej 	return (&sableio_attached->sc_isa_chipset);
    214  1.1  thorpej }
    215