Home | History | Annotate | Line # | Download | only in sableio
      1  1.16   thorpej /* $NetBSD: sableio.c,v 1.16 2021/08/07 16:18:41 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  *
     19   1.1   thorpej  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20   1.1   thorpej  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21   1.1   thorpej  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22   1.1   thorpej  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23   1.1   thorpej  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24   1.1   thorpej  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25   1.1   thorpej  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26   1.1   thorpej  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27   1.1   thorpej  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28   1.1   thorpej  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29   1.1   thorpej  * POSSIBILITY OF SUCH DAMAGE.
     30   1.1   thorpej  */
     31   1.1   thorpej 
     32   1.1   thorpej /*
     33   1.1   thorpej  * Driver glue for the Sable STDIO module.
     34   1.1   thorpej  *
     35   1.1   thorpej  * This is kind of a hack.  The STDIO is really a junk I/O module with
     36   1.1   thorpej  * your regular ISA junk peripherals and their regular ISA I/O addresses.
     37   1.1   thorpej  * However, the main issue we have here is *interrupts*.  Not only are
     38   1.1   thorpej  * devices IRQs strange (i.e. not what you would expect to find if they
     39   1.1   thorpej  * were attached to a real ISA) IRQs, the keyboard controller isn't even
     40   1.1   thorpej  * connected to the (E)ISA IRQ space at all!
     41   1.1   thorpej  *
     42   1.1   thorpej  * In short, we're gluing together the following things:
     43   1.1   thorpej  *
     44   1.1   thorpej  *	- Standard ISA junk I/O chip
     45   1.1   thorpej  *	- ISA DMA
     46   1.1   thorpej  *	- Pre-mapped "PCI" interrupts that are *edge triggered*
     47   1.1   thorpej  */
     48   1.1   thorpej 
     49   1.1   thorpej #include <sys/cdefs.h>			/* RCS ID & Copyright macro defns */
     50   1.1   thorpej 
     51  1.16   thorpej __KERNEL_RCSID(0, "$NetBSD: sableio.c,v 1.16 2021/08/07 16:18:41 thorpej Exp $");
     52   1.1   thorpej 
     53   1.1   thorpej #include "isadma.h"
     54   1.1   thorpej 
     55   1.1   thorpej #include <sys/param.h>
     56   1.1   thorpej #include <sys/systm.h>
     57   1.1   thorpej #include <sys/device.h>
     58   1.1   thorpej 
     59   1.1   thorpej #include <dev/isa/isareg.h>
     60   1.1   thorpej #include <dev/isa/isavar.h>
     61   1.1   thorpej #include <dev/isa/isadmavar.h>
     62   1.1   thorpej 
     63   1.1   thorpej #include <dev/pci/pcivar.h>
     64   1.1   thorpej 
     65   1.1   thorpej #include <alpha/sableio/sableiovar.h>
     66   1.1   thorpej 
     67   1.8  drochner #include "locators.h"
     68   1.8  drochner 
     69   1.1   thorpej /*
     70   1.1   thorpej  * The devices built-in to the Sable STDIO module.
     71   1.1   thorpej  */
     72  1.15   thorpej static const struct sableio_dev {
     73   1.1   thorpej 	const char *sd_name;		/* device name */
     74   1.1   thorpej 	bus_addr_t sd_ioaddr;		/* I/O space address */
     75   1.1   thorpej 	int sd_sableirq[2];		/* Sable IRQs */
     76   1.1   thorpej 	int sd_drq;			/* ISA DRQ */
     77   1.1   thorpej } sableio_devs[] = {
     78   1.1   thorpej 	/*
     79   1.1   thorpej 	 * See alpha/pci/pci_2100_a500.c for interrupt information.
     80   1.1   thorpej 	 */
     81   1.1   thorpej 	{ "pckbc",	IO_KBD,		{ 6, 3 },	-1 },
     82   1.1   thorpej 	{ "fdc",	IO_FD1,		{ 7, -1 },	2 },
     83   1.1   thorpej 	{ "com",	IO_COM1,	{ 15, -1 },	-1 },
     84   1.1   thorpej 	{ "com",	IO_COM2,	{ 8, -1 },	-1 },
     85   1.1   thorpej 	{ "lpt",	IO_LPT3,	{ 9, -1 },	-1 },
     86   1.1   thorpej 	{ NULL,		0,		{ -1, -1 },	-1 },
     87   1.1   thorpej };
     88   1.1   thorpej 
     89   1.1   thorpej struct sableio_softc {
     90  1.13      matt 	device_t	sc_dev;		/* base device */
     91   1.1   thorpej 
     92   1.1   thorpej 	/*
     93   1.1   thorpej 	 * We have to deal with ISA DMA, so that means we have to
     94   1.1   thorpej 	 * hold the ISA chipset, since we attach STDIO devices
     95   1.1   thorpej 	 * before we attach the PCI (and thus EISA) bus.
     96   1.1   thorpej 	 */
     97   1.1   thorpej 	struct alpha_isa_chipset sc_isa_chipset;
     98   1.1   thorpej };
     99   1.1   thorpej 
    100  1.15   thorpej static int	sableio_match(device_t, cfdata_t, void *);
    101  1.15   thorpej static void	sableio_attach(device_t, device_t, void *);
    102   1.1   thorpej 
    103  1.13      matt CFATTACH_DECL_NEW(sableio, sizeof(struct sableio_softc),
    104   1.5   thorpej     sableio_match, sableio_attach, NULL, NULL);
    105   1.1   thorpej 
    106  1.15   thorpej static int	sableio_print(void *, const char *);
    107   1.1   thorpej 
    108  1.15   thorpej static struct sableio_softc *sableio_attached;
    109   1.1   thorpej 
    110  1.15   thorpej static int
    111  1.13      matt sableio_match(device_t parent, cfdata_t cf, void *aux)
    112   1.1   thorpej {
    113   1.1   thorpej 	struct pcibus_attach_args *pba = aux;
    114   1.1   thorpej 
    115   1.1   thorpej 	/*
    116   1.1   thorpej 	 * These are really ISA devices, and thus must be on
    117   1.1   thorpej 	 * PCI bus 0.
    118   1.1   thorpej 	 */
    119   1.8  drochner 	if (cf->cf_loc[SABLEIOBUSCF_BUS] != SABLEIOBUSCF_BUS_DEFAULT &&
    120   1.8  drochner 	    cf->cf_loc[SABLEIOBUSCF_BUS] != pba->pba_bus)
    121   1.1   thorpej 		return (0);
    122   1.1   thorpej 
    123   1.1   thorpej 	/* sanity */
    124   1.1   thorpej 	if (pba->pba_bus != 0)
    125   1.1   thorpej 		return (0);
    126   1.1   thorpej 
    127   1.1   thorpej 	/* There can be only one. */
    128   1.1   thorpej 	if (sableio_attached != NULL)
    129   1.1   thorpej 		return (0);
    130   1.1   thorpej 
    131   1.1   thorpej 	return (1);
    132   1.1   thorpej }
    133   1.1   thorpej 
    134  1.15   thorpej static void
    135  1.13      matt sableio_attach(device_t parent, device_t self, void *aux)
    136   1.1   thorpej {
    137  1.13      matt 	struct sableio_softc *sc = device_private(self);
    138   1.1   thorpej 	struct pcibus_attach_args *pba = aux;
    139   1.1   thorpej 	struct sableio_attach_args sa;
    140   1.1   thorpej 	bus_dma_tag_t dmat;
    141   1.1   thorpej 	int i;
    142   1.9  drochner 	int locs[SABLEIOCF_NLOCS];
    143   1.1   thorpej 
    144  1.13      matt 	aprint_normal(": Sable STDIO module\n");
    145   1.1   thorpej 
    146   1.1   thorpej 	sableio_attached = sc;
    147  1.13      matt 	sc->sc_dev = self;
    148   1.1   thorpej 
    149   1.1   thorpej 	dmat = alphabus_dma_get_tag(pba->pba_dmat, ALPHA_BUS_ISA);
    150   1.1   thorpej 
    151   1.1   thorpej #if NISADMA > 0
    152   1.1   thorpej 	/*
    153   1.1   thorpej 	 * Initialize our DMA state.
    154   1.1   thorpej 	 */
    155   1.1   thorpej 	isa_dmainit(&sc->sc_isa_chipset, pba->pba_iot, dmat, self);
    156   1.1   thorpej #endif
    157   1.1   thorpej 
    158   1.1   thorpej 	for (i = 0; sableio_devs[i].sd_name != NULL; i++) {
    159   1.1   thorpej 		sa.sa_name = sableio_devs[i].sd_name;
    160   1.1   thorpej 		sa.sa_ioaddr = sableio_devs[i].sd_ioaddr;
    161   1.1   thorpej 		sa.sa_sableirq[0] = sableio_devs[i].sd_sableirq[0];
    162   1.1   thorpej 		sa.sa_sableirq[1] = sableio_devs[i].sd_sableirq[1];
    163   1.1   thorpej 		sa.sa_drq = sableio_devs[i].sd_drq;
    164   1.1   thorpej 
    165   1.1   thorpej 		sa.sa_iot = pba->pba_iot;
    166   1.1   thorpej 		sa.sa_dmat = dmat;
    167   1.1   thorpej 		sa.sa_ic = &sc->sc_isa_chipset;
    168   1.1   thorpej 		sa.sa_pc = pba->pba_pc;
    169   1.1   thorpej 
    170   1.9  drochner 		locs[SABLEIOCF_PORT] = sableio_devs[i].sd_ioaddr;
    171   1.8  drochner 
    172  1.14   thorpej 		config_found(self, &sa, sableio_print,
    173  1.16   thorpej 		    CFARGS(.submatch = config_stdsubmatch,
    174  1.16   thorpej 			   .locators = locs));
    175   1.1   thorpej 	}
    176   1.1   thorpej }
    177   1.1   thorpej 
    178  1.15   thorpej static int
    179   1.1   thorpej sableio_print(void *aux, const char *pnp)
    180   1.1   thorpej {
    181   1.1   thorpej 	struct sableio_attach_args *sa = aux;
    182   1.1   thorpej 
    183   1.1   thorpej 	if (pnp != NULL)
    184   1.6   thorpej 		aprint_normal("%s at %s", sa->sa_name, pnp);
    185   1.1   thorpej 
    186   1.6   thorpej 	aprint_normal(" port 0x%lx", sa->sa_ioaddr);
    187   1.1   thorpej 	return (UNCONF);
    188   1.1   thorpej }
    189   1.1   thorpej 
    190   1.1   thorpej isa_chipset_tag_t
    191   1.1   thorpej sableio_pickisa(void)
    192   1.1   thorpej {
    193   1.1   thorpej 
    194   1.1   thorpej 	if (sableio_attached == NULL)
    195   1.1   thorpej 		panic("sableio_pickisa");
    196   1.1   thorpej 
    197   1.1   thorpej 	return (&sableio_attached->sc_isa_chipset);
    198   1.1   thorpej }
    199