Home | History | Annotate | Line # | Download | only in jensenio
jensenio.c revision 1.22
      1 /* $NetBSD: jensenio.c,v 1.22 2021/08/07 16:18:40 thorpej 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  *
     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  * Driver for the Jensen I/O bus.
     34  *
     35  * The Jensen I/O `bus' is comprised of two things:
     36  *
     37  *	- VLSI VL82C106 junk I/O chip
     38  *	- Intel EISA bus interface
     39  *
     40  * Access to the 82C106 is different than to the rest of EISA space, even
     41  * though it is a single address space.
     42  */
     43 
     44 #include <sys/cdefs.h>			/* RCS ID & Copyright macro defns */
     45 
     46 __KERNEL_RCSID(0, "$NetBSD: jensenio.c,v 1.22 2021/08/07 16:18:40 thorpej Exp $");
     47 
     48 #include <sys/param.h>
     49 #include <sys/systm.h>
     50 #include <sys/device.h>
     51 
     52 #include <machine/autoconf.h>
     53 
     54 #include <dev/eisa/eisavar.h>
     55 
     56 #include <dev/isa/isareg.h>
     57 #include <dev/isa/isavar.h>
     58 
     59 #include <alpha/jensenio/jensenioreg.h>
     60 #include <alpha/jensenio/jenseniovar.h>
     61 
     62 #include "locators.h"
     63 
     64 #include "eisa.h"
     65 
     66 /*
     67  * The devices built-in to the VLSI VL82C106 junk I/O chip.
     68  */
     69 static const struct jensenio_dev {
     70 	const char *jd_name;		/* device name */
     71 	bus_addr_t jd_ioaddr;		/* I/O space address */
     72 	int jd_irq[2];			/* Jensen IRQs */
     73 } jensenio_devs[] = {
     74 	{ "pckbc",	IO_KBD,		{ 0x980, 0x990 } },
     75 	{ "com",	IO_COM1,	{ 0x900, -1 } },
     76 	{ "com",	IO_COM2,	{ 0x920, -1 } },
     77 	{ "lpt",	IO_LPT3,	{ 1, -1 } },
     78 	{ "mcclock",	0x170,		{ -1, -1 } },
     79 	{ NULL,		0,		{ -1, -1 } },
     80 };
     81 
     82 static int	jensenio_match(device_t, cfdata_t, void *);
     83 static void	jensenio_attach(device_t, device_t, void *);
     84 
     85 CFATTACH_DECL_NEW(jensenio, 0, jensenio_match, jensenio_attach, NULL, NULL);
     86 
     87 static int	jensenio_print(void *, const char *);
     88 
     89 static int	jensenio_attached;
     90 
     91 struct jensenio_config jensenio_configuration;
     92 
     93 static void	jensenio_eisa_attach_hook(device_t, device_t,
     94 		    struct eisabus_attach_args *);
     95 static int	jensenio_eisa_maxslots(void *);
     96 
     97 static void	jensenio_isa_attach_hook(device_t, device_t,
     98 		    struct isabus_attach_args *);
     99 
    100 static void	jensenio_isa_detach_hook(isa_chipset_tag_t, device_t);
    101 
    102 /*
    103  * Set up the Jensen's function pointers.
    104  */
    105 void
    106 jensenio_init(struct jensenio_config *jcp, int mallocsafe)
    107 {
    108 
    109 	/*
    110 	 * Initialize the Host Address Extension register to 0
    111 	 * (the firmware should have already done this).  We will
    112 	 * disallow mapping of any device who's address would
    113 	 * require a non-0 HAE.  This should be safe as the final
    114 	 * draft of the Jensen system specification states that
    115 	 * applications should follow this little rule.
    116 	 *
    117 	 * There's a good reason for this; actually using HAE would
    118 	 * require a mutex around *every* EISA cycle!  Gross!
    119 	 */
    120 	REGVAL(JENSEN_HAE) = 0;
    121 	alpha_mb();
    122 
    123 	if (jcp->jc_initted == 0) {
    124 		/* don't do these twice since they set up extents */
    125 		jensenio_bus_io_init(&jcp->jc_eisa_iot, jcp);
    126 		jensenio_bus_intio_init(&jcp->jc_internal_iot, jcp);
    127 		jensenio_bus_mem_init(&jcp->jc_eisa_memt, jcp);
    128 	}
    129 	jcp->jc_mallocsafe = mallocsafe;
    130 }
    131 
    132 static int
    133 jensenio_match(device_t parent, cfdata_t cf, void *aux)
    134 {
    135 	struct mainbus_attach_args *ma = aux;
    136 
    137 	if (strcmp(ma->ma_name, cf->cf_name) != 0)
    138 		return (0);
    139 
    140 	/* There can be only one. */
    141 	if (jensenio_attached)
    142 		return (0);
    143 
    144 	return (1);
    145 }
    146 
    147 static void
    148 jensenio_attach(device_t parent, device_t self, void *aux)
    149 {
    150 	struct jensenio_attach_args ja;
    151 	struct jensenio_config *jcp = &jensenio_configuration;
    152 	int i;
    153 	int locs[JENSENIOCF_NLOCS];
    154 
    155 	printf("\n");
    156 
    157 	jensenio_attached = 1;
    158 
    159 	/*
    160 	 * Done once at console init time, but we might need to do
    161 	 * additional work this time.
    162 	 */
    163 	jensenio_init(jcp, 1);
    164 
    165 	/*
    166 	 * Initialize DMA.
    167 	 */
    168 	jensenio_dma_init(jcp);
    169 
    170 	/*
    171 	 * Initialize interrupts.
    172 	 */
    173 	jensenio_intr_init(jcp);
    174 
    175 	/*
    176 	 * First attach all of the built-in devices.
    177 	 */
    178 	for (i = 0; jensenio_devs[i].jd_name != NULL; i++) {
    179 		ja.ja_name = jensenio_devs[i].jd_name;
    180 		ja.ja_ioaddr = jensenio_devs[i].jd_ioaddr;
    181 		ja.ja_irq[0] = jensenio_devs[i].jd_irq[0];
    182 		ja.ja_irq[1] = jensenio_devs[i].jd_irq[1];
    183 
    184 		ja.ja_iot = &jcp->jc_internal_iot;
    185 		ja.ja_ec = &jcp->jc_ec;
    186 
    187 		locs[JENSENIOCF_PORT] = jensenio_devs[i].jd_ioaddr;
    188 		config_found(self, &ja, jensenio_print,
    189 		    CFARGS(.submatch = config_stdsubmatch,
    190 			   .iattr = "jensenio",
    191 			   .locators = locs));
    192 	}
    193 
    194 	/*
    195 	 * Attach the EISA bus.
    196 	 */
    197 	jcp->jc_ec.ec_attach_hook = jensenio_eisa_attach_hook;
    198 	jcp->jc_ec.ec_maxslots = jensenio_eisa_maxslots;
    199 
    200 	ja.ja_eisa.eba_iot = &jcp->jc_eisa_iot;
    201 	ja.ja_eisa.eba_memt = &jcp->jc_eisa_memt;
    202 	ja.ja_eisa.eba_dmat = &jcp->jc_dmat_eisa;
    203 	ja.ja_eisa.eba_ec = &jcp->jc_ec;
    204 	config_found(self, &ja.ja_eisa, eisabusprint,
    205 	    CFARGS(.iattr = "eisabus"));
    206 
    207 	/*
    208 	 * Attach the ISA bus.
    209 	 */
    210 	jcp->jc_ic.ic_attach_hook = jensenio_isa_attach_hook;
    211 	jcp->jc_ic.ic_detach_hook = jensenio_isa_detach_hook;
    212 
    213 	ja.ja_isa.iba_iot = &jcp->jc_eisa_iot;
    214 	ja.ja_isa.iba_memt = &jcp->jc_eisa_memt;
    215 	ja.ja_isa.iba_dmat = &jcp->jc_dmat_isa;
    216 	ja.ja_isa.iba_ic = &jcp->jc_ic;
    217 	config_found(self, &ja.ja_isa, isabusprint,
    218 	    CFARGS(.iattr = "eisabus"));
    219 }
    220 
    221 static int
    222 jensenio_print(void *aux, const char *pnp)
    223 {
    224 	struct jensenio_attach_args *ja = aux;
    225 
    226 	if (pnp != NULL)
    227 		aprint_normal("%s at %s", ja->ja_name, pnp);
    228 
    229 	aprint_normal(" port 0x%lx", ja->ja_ioaddr);
    230 
    231 	return (UNCONF);
    232 }
    233 
    234 static void
    235 jensenio_eisa_attach_hook(device_t parent, device_t self,
    236     struct eisabus_attach_args *eba)
    237 {
    238 
    239 #if NEISA > 0
    240 	/*
    241 	 * Jensen's EISA config info is sparse, and is mapped at a
    242 	 * different location that on other EISA systems.
    243 	 */
    244 	eisa_config_stride = 0x200;
    245 	eisa_config_addr = JENSEN_FEPROM1;
    246 	eisa_init(eba->eba_ec);
    247 #endif
    248 }
    249 
    250 static int
    251 jensenio_eisa_maxslots(void *v)
    252 {
    253 
    254 	return (8);	/* jensen seems to have only 8 valid slots */
    255 }
    256 
    257 static void
    258 jensenio_isa_attach_hook(device_t parent, device_t self,
    259     struct isabus_attach_args *iba)
    260 {
    261 
    262 	/* Nothing to do. */
    263 }
    264 
    265 static void
    266 jensenio_isa_detach_hook(isa_chipset_tag_t ic, device_t self)
    267 {
    268 
    269 	/* Nothing to do. */
    270 }
    271