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