Home | History | Annotate | Line # | Download | only in vme
      1  1.29   thorpej /*	$NetBSD: et4000.c,v 1.29 2023/12/20 00:40:43 thorpej Exp $	*/
      2   1.1       leo /*-
      3   1.1       leo  * Copyright (c) 1998 The NetBSD Foundation, Inc.
      4   1.1       leo  * All rights reserved.
      5   1.1       leo  *
      6   1.1       leo  * This code is derived from software contributed to The NetBSD Foundation
      7   1.1       leo  * by Julian Coleman.
      8   1.1       leo  *
      9   1.1       leo  * Redistribution and use in source and binary forms, with or without
     10   1.1       leo  * modification, are permitted provided that the following conditions
     11   1.1       leo  * are met:
     12   1.1       leo  * 1. Redistributions of source code must retain the above copyright
     13   1.1       leo  *    notice, this list of conditions and the following disclaimer.
     14   1.1       leo  * 2. Redistributions in binary form must reproduce the above copyright
     15   1.1       leo  *    notice, this list of conditions and the following disclaimer in the
     16   1.1       leo  *    documentation and/or other materials provided with the distribution.
     17   1.1       leo  *
     18   1.1       leo  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     19   1.1       leo  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     20   1.1       leo  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     21   1.1       leo  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     22   1.1       leo  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     23   1.1       leo  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     24   1.1       leo  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     25   1.1       leo  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     26   1.1       leo  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     27   1.1       leo  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     28   1.1       leo  * POSSIBILITY OF SUCH DAMAGE.
     29   1.1       leo  */
     30   1.1       leo 
     31   1.1       leo /*
     32   1.1       leo  * Thanks to:
     33   1.1       leo  *	Leo Weppelman
     34   1.1       leo  *	'Maximum Entropy'
     35   1.1       leo  *	Thomas Gerner
     36   1.1       leo  *	Juergen Orscheidt
     37   1.1       leo  * for their help and for code that I could refer to when writing this driver.
     38   1.3       leo  *
     39   1.3       leo  * Defining DEBUG_ET4000 will cause the driver to *always* attach.  Use for
     40   1.3       leo  * debugging register settings.
     41   1.1       leo  */
     42   1.1       leo 
     43   1.1       leo /*
     44   1.1       leo #define DEBUG_ET4000
     45   1.1       leo */
     46  1.11     lukem 
     47  1.11     lukem #include <sys/cdefs.h>
     48  1.29   thorpej __KERNEL_RCSID(0, "$NetBSD: et4000.c,v 1.29 2023/12/20 00:40:43 thorpej Exp $");
     49   1.1       leo 
     50   1.1       leo #include <sys/param.h>
     51   1.1       leo #include <sys/ioctl.h>
     52   1.1       leo #include <sys/queue.h>
     53   1.1       leo #include <sys/device.h>
     54   1.1       leo #include <sys/systm.h>
     55   1.1       leo #include <sys/conf.h>
     56  1.10  jdolecek #include <sys/event.h>
     57   1.1       leo #include <atari/vme/vmevar.h>
     58   1.1       leo 
     59   1.1       leo #include <machine/iomap.h>
     60   1.1       leo #include <machine/video.h>
     61   1.1       leo #include <machine/mfp.h>
     62   1.1       leo #include <machine/cpu.h>
     63   1.1       leo #include <atari/atari/device.h>
     64   1.1       leo #include <atari/dev/grfioctl.h>
     65   1.1       leo #include <atari/dev/grf_etreg.h>
     66   1.1       leo 
     67  1.21   tsutsui #include "ioconf.h"
     68  1.21   tsutsui 
     69   1.1       leo /*
     70   1.1       leo  * Allow a 8Kb io-region and a 1MB frame buffer to be mapped. This
     71   1.3       leo  * is more or less required by the XFree server.  The X server also
     72   1.3       leo  * requires that the frame buffer be mapped above 0x3fffff.
     73   1.1       leo  */
     74   1.3       leo #define REG_MAPPABLE	(8 * 1024)		/* 0x2000 */
     75   1.3       leo #define FRAME_MAPPABLE	(1 * 1024 * 1024)	/* 0x100000 */
     76   1.3       leo #define FRAME_BASE	(4 * 1024 * 1024)	/* 0x400000 */
     77   1.3       leo #define VGA_MAPPABLE	(128 * 1024)		/* 0x20000 */
     78   1.3       leo #define VGA_BASE	0xa0000
     79   1.1       leo 
     80  1.24   tsutsui static int	et4k_vme_match(device_t, cfdata_t, void *);
     81  1.24   tsutsui static void	et4k_vme_attach(device_t, device_t, void *);
     82  1.23   tsutsui static int	et4k_probe_addresses(struct vme_attach_args *);
     83  1.23   tsutsui static void	et4k_start(bus_space_tag_t *, bus_space_handle_t *, int *,
     84  1.16       dsl 		    u_char *);
     85  1.23   tsutsui static void	et4k_stop(bus_space_tag_t *, bus_space_handle_t *, int *,
     86  1.16       dsl 		    u_char *);
     87  1.23   tsutsui static int	et4k_detect(bus_space_tag_t *, bus_space_tag_t *,
     88  1.16       dsl 		    bus_space_handle_t *, bus_space_handle_t *, u_int);
     89   1.1       leo 
     90  1.23   tsutsui int		et4kon(dev_t);
     91  1.23   tsutsui int		et4koff(dev_t);
     92   1.1       leo 
     93   1.1       leo /* Register and screen memory addresses for ET4000 based VME cards */
     94  1.23   tsutsui static struct et4k_addresses {
     95   1.1       leo 	u_long io_addr;
     96   1.1       leo 	u_long io_size;
     97   1.1       leo 	u_long mem_addr;
     98   1.1       leo 	u_long mem_size;
     99  1.23   tsutsui } et4kstd[] = {
    100   1.1       leo 	{ 0xfebf0000, REG_MAPPABLE, 0xfec00000, FRAME_MAPPABLE }, /* Crazy Dots VME & II */
    101   1.1       leo 	{ 0xfed00000, REG_MAPPABLE, 0xfec00000, FRAME_MAPPABLE }, /* Spektrum I & HC */
    102   1.1       leo 	{ 0xfed80000, REG_MAPPABLE, 0xfec00000, FRAME_MAPPABLE }  /* Spektrum TC */
    103   1.1       leo };
    104   1.1       leo 
    105  1.23   tsutsui #define NET4KSTD (sizeof(et4kstd) / sizeof(et4kstd[0]))
    106   1.1       leo 
    107  1.23   tsutsui struct grfabs_et4k_priv {
    108  1.13  christos 	volatile void *	regkva;
    109  1.13  christos 	volatile void *	memkva;
    110   1.1       leo 	int			regsz;
    111   1.1       leo 	int			memsz;
    112  1.23   tsutsui } et4k_priv;
    113   1.1       leo 
    114  1.23   tsutsui struct et4k_softc {
    115  1.24   tsutsui 	device_t sc_dev;
    116   1.1       leo 	bus_space_tag_t sc_iot;
    117   1.1       leo 	bus_space_tag_t sc_memt;
    118   1.1       leo 	bus_space_handle_t sc_ioh;
    119   1.1       leo 	bus_space_handle_t sc_memh;
    120   1.1       leo 	int sc_flags;
    121   1.1       leo 	int sc_iobase;
    122   1.1       leo 	int sc_maddr;
    123   1.1       leo 	int sc_iosize;
    124   1.1       leo 	int sc_msize;
    125   1.1       leo };
    126   1.1       leo 
    127   1.1       leo #define ET_SC_FLAGS_INUSE 1
    128   1.1       leo 
    129  1.24   tsutsui CFATTACH_DECL_NEW(et4k, sizeof(struct et4k_softc),
    130  1.23   tsutsui     et4k_vme_match, et4k_vme_attach, NULL, NULL);
    131   1.1       leo 
    132  1.27   tsutsui static dev_type_open(et4kopen);
    133  1.27   tsutsui static dev_type_close(et4kclose);
    134  1.27   tsutsui static dev_type_read(et4kread);
    135  1.27   tsutsui static dev_type_write(et4kwrite);
    136  1.27   tsutsui static dev_type_ioctl(et4kioctl);
    137  1.27   tsutsui static dev_type_mmap(et4kmmap);
    138  1.23   tsutsui 
    139  1.23   tsutsui const struct cdevsw et4k_cdevsw = {
    140  1.25  dholland 	.d_open = et4kopen,
    141  1.25  dholland 	.d_close = et4kclose,
    142  1.25  dholland 	.d_read = et4kread,
    143  1.25  dholland 	.d_write = et4kwrite,
    144  1.25  dholland 	.d_ioctl = et4kioctl,
    145  1.25  dholland 	.d_stop = nostop,
    146  1.25  dholland 	.d_tty = notty,
    147  1.25  dholland 	.d_poll = nopoll,
    148  1.25  dholland 	.d_mmap = et4kmmap,
    149  1.25  dholland 	.d_kqfilter = nokqfilter,
    150  1.26  dholland 	.d_discard = nodiscard,
    151  1.25  dholland 	.d_flag = 0
    152   1.6   gehenna };
    153   1.1       leo 
    154   1.1       leo /*
    155   1.1       leo  * Look for a ET4000 (Crazy Dots) card on the VME bus.  We might
    156   1.1       leo  * match Spektrum cards too (untested).
    157   1.1       leo  */
    158  1.28   tsutsui int
    159  1.24   tsutsui et4k_vme_match(device_t parent, cfdata_t cf, void *aux)
    160   1.1       leo {
    161  1.24   tsutsui 	struct vme_attach_args *va = aux;
    162   1.1       leo 
    163  1.23   tsutsui 	return et4k_probe_addresses(va);
    164   1.1       leo }
    165   1.1       leo 
    166   1.1       leo static int
    167  1.23   tsutsui et4k_probe_addresses(struct vme_attach_args *va)
    168   1.1       leo {
    169   1.1       leo 	int i, found = 0;
    170   1.1       leo 	bus_space_tag_t iot;
    171   1.1       leo 	bus_space_tag_t memt;
    172   1.1       leo 	bus_space_handle_t ioh;
    173   1.1       leo 	bus_space_handle_t memh;
    174   1.1       leo 
    175   1.1       leo 	iot = va->va_iot;
    176   1.1       leo 	memt = va->va_memt;
    177   1.1       leo 
    178   1.1       leo /* Loop around our possible addresses looking for a match */
    179  1.23   tsutsui 	for (i = 0; i < NET4KSTD; i++) {
    180  1.23   tsutsui 		struct et4k_addresses *et4k_ap = &et4kstd[i];
    181   1.1       leo 		struct vme_attach_args vat = *va;
    182   1.1       leo 
    183   1.1       leo 		if (vat.va_irq != VMECF_IRQ_DEFAULT) {
    184  1.23   tsutsui 			printf("%s: config error: no irq support\n", __func__);
    185  1.22   tsutsui 			return 0;
    186   1.1       leo 		}
    187   1.1       leo 		if (vat.va_iobase == VMECF_IOPORT_DEFAULT)
    188  1.23   tsutsui 			vat.va_iobase = et4k_ap->io_addr;
    189   1.1       leo 		if (vat.va_maddr == VMECF_MEM_DEFAULT)
    190  1.23   tsutsui 			vat.va_maddr = et4k_ap->mem_addr;
    191   1.1       leo 		if (vat.va_iosize == VMECF_IOSIZE_DEFAULT)
    192  1.23   tsutsui 			vat.va_iosize = et4k_ap->io_size;
    193   1.1       leo 		if (vat.va_msize == VMECF_MEMSIZ_DEFAULT)
    194  1.23   tsutsui 			vat.va_msize = et4k_ap->mem_size;
    195   1.1       leo 		if (bus_space_map(iot, vat.va_iobase, vat.va_iosize, 0,
    196   1.1       leo 				  &ioh)) {
    197  1.23   tsutsui 			printf("%s: cannot map io area\n", __func__);
    198  1.22   tsutsui 			return 0;
    199   1.1       leo 		}
    200   1.1       leo 		if (bus_space_map(memt, vat.va_maddr, vat.va_msize,
    201  1.28   tsutsui 				  BUS_SPACE_MAP_LINEAR|BUS_SPACE_MAP_CACHEABLE,
    202  1.28   tsutsui 				  &memh)) {
    203   1.4       leo 			bus_space_unmap(iot, ioh, vat.va_iosize);
    204  1.23   tsutsui 			printf("%s: cannot map memory area\n", __func__);
    205  1.22   tsutsui 			return 0;
    206   1.1       leo 		}
    207  1.23   tsutsui 		found = et4k_detect(&iot, &memt, &ioh, &memh, vat.va_msize);
    208   1.4       leo 		bus_space_unmap(iot, ioh, vat.va_iosize);
    209   1.4       leo 		bus_space_unmap(memt, memh, vat.va_msize);
    210   1.1       leo 		if (found) {
    211   1.1       leo 			*va = vat;
    212  1.22   tsutsui 			return 1;
    213   1.1       leo 		}
    214   1.1       leo 	}
    215  1.22   tsutsui 	return 0;
    216   1.1       leo }
    217   1.1       leo 
    218   1.1       leo static void
    219  1.23   tsutsui et4k_start(bus_space_tag_t *iot, bus_space_handle_t *ioh, int *vgabase, u_char *saved)
    220   1.1       leo {
    221   1.1       leo 	/* Enable VGA */
    222   1.1       leo 	bus_space_write_1(*iot, *ioh, GREG_VIDEOSYSENABLE, 0x01);
    223   1.1       leo 	/* Check whether colour (base = 3d0) or mono (base = 3b0) mode */
    224   1.1       leo 	*vgabase = (bus_space_read_1(*iot, *ioh, GREG_MISC_OUTPUT_R) & 0x01)
    225   1.1       leo 	    ? 0x3d0 : 0x3b0;
    226   1.1       leo 	/* Enable 'Tseng Extensions' - writes to CRTC and ATC[16] */
    227   1.1       leo 	bus_space_write_1(*iot, *ioh, GREG_HERCULESCOMPAT, 0x03);
    228   1.1       leo 	bus_space_write_1(*iot, *ioh, *vgabase + 0x08, 0xa0);
    229   1.1       leo 	/* Set up 16 bit I/O, memory, Tseng addressing and linear mapping */
    230   1.1       leo 	bus_space_write_1(*iot, *ioh, *vgabase + 0x04, 0x36);
    231   1.1       leo 	bus_space_write_1(*iot, *ioh, *vgabase + 0x05, 0xf0);
    232   1.1       leo 	/* Enable writes to CRTC[0..7] */
    233   1.1       leo 	bus_space_write_1(*iot, *ioh, *vgabase + 0x04, 0x11);
    234   1.1       leo 	*saved = bus_space_read_1(*iot, *ioh, *vgabase + 0x05);
    235   1.1       leo 	bus_space_write_1(*iot, *ioh, *vgabase + 0x05, *saved & 0x7f);
    236   1.1       leo 	/* Map all memory for video modes */
    237   1.1       leo 	bus_space_write_1(*iot, *ioh, 0x3ce, 0x06);
    238   1.1       leo 	bus_space_write_1(*iot, *ioh, 0x3cf, 0x01);
    239   1.1       leo }
    240   1.1       leo 
    241   1.1       leo static void
    242  1.23   tsutsui et4k_stop(bus_space_tag_t *iot, bus_space_handle_t *ioh, int *vgabase, u_char *saved)
    243   1.1       leo {
    244   1.1       leo 	/* Restore writes to CRTC[0..7] */
    245   1.1       leo 	bus_space_write_1(*iot, *ioh, *vgabase + 0x04, 0x11);
    246   1.1       leo 	*saved = bus_space_read_1(*iot, *ioh, *vgabase + 0x05);
    247   1.1       leo 	bus_space_write_1(*iot, *ioh, *vgabase + 0x05, *saved | 0x80);
    248   1.1       leo 	/* Disable 'Tseng Extensions' */
    249   1.1       leo 	bus_space_write_1(*iot, *ioh, *vgabase + 0x08, 0x00);
    250   1.1       leo 	bus_space_write_1(*iot, *ioh, GREG_DISPMODECONTROL, 0x29);
    251   1.1       leo 	bus_space_write_1(*iot, *ioh, GREG_HERCULESCOMPAT, 0x01);
    252   1.1       leo }
    253   1.1       leo 
    254   1.1       leo static int
    255  1.23   tsutsui et4k_detect(bus_space_tag_t *iot, bus_space_tag_t *memt, bus_space_handle_t *ioh, bus_space_handle_t *memh, u_int memsize)
    256   1.1       leo {
    257   1.1       leo 	u_char orig, new, saved;
    258   1.1       leo 	int vgabase;
    259   1.1       leo 
    260   1.1       leo 	/* Test accessibility of registers and memory */
    261  1.22   tsutsui 	if (!bus_space_peek_1(*iot, *ioh, GREG_STATUS1_R))
    262  1.22   tsutsui 		return 0;
    263  1.22   tsutsui 	if (!bus_space_peek_1(*memt, *memh, 0))
    264  1.22   tsutsui 		return 0;
    265   1.1       leo 
    266  1.23   tsutsui 	et4k_start(iot, ioh, &vgabase, &saved);
    267   1.1       leo 
    268   1.1       leo 	/* Is the card a Tseng card?  Check read/write of ATC[16] */
    269   1.1       leo 	(void)bus_space_read_1(*iot, *ioh, vgabase + 0x0a);
    270   1.1       leo 	bus_space_write_1(*iot, *ioh, ACT_ADDRESS, 0x16 | 0x20);
    271   1.1       leo 	orig = bus_space_read_1(*iot, *ioh, ACT_ADDRESS_R);
    272   1.1       leo 	bus_space_write_1(*iot, *ioh, ACT_ADDRESS_W, (orig ^ 0x10));
    273   1.1       leo 	bus_space_write_1(*iot, *ioh, ACT_ADDRESS, 0x16 | 0x20);
    274   1.1       leo 	new = bus_space_read_1(*iot, *ioh, ACT_ADDRESS_R);
    275   1.1       leo 	bus_space_write_1(*iot, *ioh, ACT_ADDRESS, orig);
    276   1.1       leo 	if (new != (orig ^ 0x10)) {
    277   1.1       leo #ifdef DEBUG_ET4000
    278   1.1       leo 		printf("et4000: ATC[16] failed (%x != %x)\n",
    279   1.1       leo 		    new, (orig ^ 0x10));
    280   1.3       leo #else
    281  1.23   tsutsui 		et4k_stop(iot, ioh, &vgabase, &saved);
    282  1.22   tsutsui 		return 0;
    283   1.3       leo #endif
    284   1.1       leo 	}
    285   1.1       leo 	/* Is the card and ET4000?  Check read/write of CRTC[33] */
    286   1.1       leo 	bus_space_write_1(*iot, *ioh, vgabase + 0x04, 0x33);
    287   1.1       leo 	orig = bus_space_read_1(*iot, *ioh, vgabase + 0x05);
    288   1.1       leo 	bus_space_write_1(*iot, *ioh, vgabase + 0x05, (orig ^ 0x0f));
    289   1.1       leo 	new = bus_space_read_1(*iot, *ioh, vgabase + 0x05);
    290   1.1       leo 	bus_space_write_1(*iot, *ioh, vgabase + 0x05, orig);
    291   1.1       leo 	if (new != (orig ^ 0x0f)) {
    292   1.1       leo #ifdef DEBUG_ET4000
    293   1.1       leo 		printf("et4000: CRTC[33] failed (%x != %x)\n",
    294   1.1       leo 		    new, (orig ^ 0x0f));
    295   1.3       leo #else
    296  1.23   tsutsui 		et4k_stop(iot, ioh, &vgabase, &saved);
    297  1.22   tsutsui 		return 0;
    298   1.3       leo #endif
    299   1.1       leo 	}
    300   1.1       leo 
    301   1.2       leo 	/* Set up video memory so we can read & write it */
    302   1.2       leo 	bus_space_write_1(*iot, *ioh, 0x3c4, 0x04);
    303   1.3       leo 	bus_space_write_1(*iot, *ioh, 0x3c5, 0x06);
    304   1.3       leo 	bus_space_write_1(*iot, *ioh, 0x3c4, 0x07);
    305   1.3       leo 	bus_space_write_1(*iot, *ioh, 0x3c5, 0xa8);
    306   1.2       leo 	bus_space_write_1(*iot, *ioh, 0x3ce, 0x01);
    307   1.2       leo 	bus_space_write_1(*iot, *ioh, 0x3cf, 0x00);
    308   1.2       leo 	bus_space_write_1(*iot, *ioh, 0x3ce, 0x03);
    309   1.2       leo 	bus_space_write_1(*iot, *ioh, 0x3cf, 0x00);
    310   1.2       leo 	bus_space_write_1(*iot, *ioh, 0x3ce, 0x05);
    311   1.2       leo 	bus_space_write_1(*iot, *ioh, 0x3cf, 0x40);
    312   1.2       leo 
    313   1.1       leo #define TEST_PATTERN 0xa5a5a5a5
    314   1.1       leo 
    315   1.1       leo 	bus_space_write_4(*memt, *memh, 0x0, TEST_PATTERN);
    316   1.1       leo 	if (bus_space_read_4(*memt, *memh, 0x0) != TEST_PATTERN)
    317   1.1       leo 	{
    318   1.1       leo #ifdef DEBUG_ET4000
    319   1.2       leo 		printf("et4000: Video base write/read failed\n");
    320   1.3       leo #else
    321  1.23   tsutsui 		et4k_stop(iot, ioh, &vgabase, &saved);
    322  1.22   tsutsui 		return 0;
    323   1.3       leo #endif
    324   1.1       leo 	}
    325   1.1       leo 	bus_space_write_4(*memt, *memh, memsize - 4, TEST_PATTERN);
    326   1.1       leo 	if (bus_space_read_4(*memt, *memh, memsize - 4) != TEST_PATTERN)
    327   1.1       leo 	{
    328   1.1       leo #ifdef DEBUG_ET4000
    329   1.2       leo 		printf("et4000: Video top write/read failed\n");
    330   1.3       leo #else
    331  1.23   tsutsui 		et4k_stop(iot, ioh, &vgabase, &saved);
    332  1.22   tsutsui 		return 0;
    333   1.3       leo #endif
    334   1.1       leo 	}
    335   1.1       leo 
    336  1.23   tsutsui 	et4k_stop(iot, ioh, &vgabase, &saved);
    337  1.22   tsutsui 	return 1;
    338   1.1       leo }
    339   1.1       leo 
    340   1.1       leo static void
    341  1.24   tsutsui et4k_vme_attach(device_t parent, device_t self, void *aux)
    342   1.1       leo {
    343  1.24   tsutsui 	struct et4k_softc *sc = device_private(self);
    344   1.1       leo 	struct vme_attach_args *va = aux;
    345   1.1       leo 	bus_space_handle_t ioh;
    346   1.1       leo 	bus_space_handle_t memh;
    347   1.1       leo 
    348  1.24   tsutsui 	sc->sc_dev = self;
    349  1.24   tsutsui 
    350   1.1       leo 	printf("\n");
    351   1.1       leo 
    352   1.1       leo 	if (bus_space_map(va->va_iot, va->va_iobase, va->va_iosize, 0, &ioh))
    353  1.23   tsutsui 		panic("%s: cannot map io area", __func__);
    354   1.1       leo 	if (bus_space_map(va->va_memt, va->va_maddr, va->va_msize, 0, &memh))
    355  1.23   tsutsui 		panic("%s: cannot map mem area", __func__);
    356   1.1       leo 
    357   1.1       leo 	sc->sc_iot = va->va_iot;
    358   1.1       leo 	sc->sc_ioh = ioh;
    359   1.1       leo 	sc->sc_memt = va->va_memt;
    360   1.1       leo 	sc->sc_memh = memh;
    361   1.1       leo 	sc->sc_flags = 0;
    362   1.1       leo 	sc->sc_iobase = va->va_iobase;
    363   1.1       leo 	sc->sc_maddr = va->va_maddr;
    364   1.1       leo 	sc->sc_iosize = va->va_iosize;
    365   1.1       leo 	sc->sc_msize = va->va_msize;
    366   1.1       leo 
    367  1.23   tsutsui 	et4k_priv.regkva = (volatile void *)ioh;
    368  1.23   tsutsui 	et4k_priv.memkva = (volatile void *)memh;
    369  1.23   tsutsui 	et4k_priv.regsz = va->va_iosize;
    370  1.23   tsutsui 	et4k_priv.memsz = va->va_msize;
    371   1.1       leo }
    372   1.1       leo 
    373   1.1       leo int
    374  1.23   tsutsui et4kopen(dev_t dev, int flags, int devtype, struct lwp *l)
    375   1.1       leo {
    376  1.23   tsutsui 	struct et4k_softc *sc;
    377   1.1       leo 
    378  1.23   tsutsui 	sc = device_lookup_private(&et4k_cd, minor(dev));
    379  1.15   tsutsui 	if (sc == NULL)
    380  1.22   tsutsui 		return ENXIO;
    381   1.1       leo 	if (sc->sc_flags & ET_SC_FLAGS_INUSE)
    382  1.22   tsutsui 		return EBUSY;
    383   1.1       leo 	sc->sc_flags |= ET_SC_FLAGS_INUSE;
    384  1.22   tsutsui 	return 0;
    385   1.1       leo }
    386   1.1       leo 
    387   1.1       leo int
    388  1.23   tsutsui et4kclose(dev_t dev, int flags, int devtype, struct lwp *l)
    389   1.1       leo {
    390  1.23   tsutsui 	struct et4k_softc *sc;
    391   1.1       leo 
    392   1.1       leo 	/*
    393   1.1       leo 	 * XXX: Should we reset to a default mode?
    394   1.1       leo 	 */
    395  1.23   tsutsui 	sc = device_lookup_private(&et4k_cd, minor(dev));
    396   1.1       leo 	sc->sc_flags &= ~ET_SC_FLAGS_INUSE;
    397  1.22   tsutsui 	return 0;
    398   1.1       leo }
    399   1.1       leo 
    400   1.1       leo int
    401  1.23   tsutsui et4kread(dev_t dev, struct uio *uio, int flags)
    402   1.1       leo {
    403  1.22   tsutsui 
    404  1.22   tsutsui 	return EINVAL;
    405   1.1       leo }
    406   1.1       leo 
    407   1.1       leo int
    408  1.23   tsutsui et4kwrite(dev_t dev, struct uio *uio, int flags)
    409   1.1       leo {
    410  1.22   tsutsui 
    411  1.22   tsutsui 	return EINVAL;
    412   1.1       leo }
    413   1.1       leo 
    414   1.1       leo int
    415  1.23   tsutsui et4kioctl(dev_t dev, u_long cmd, void *data, int flags, struct lwp *l)
    416   1.1       leo {
    417   1.1       leo 	struct grfinfo g_display;
    418  1.23   tsutsui 	struct et4k_softc *sc;
    419   1.1       leo 
    420  1.23   tsutsui 	sc = device_lookup_private(&et4k_cd, minor(dev));
    421   1.1       leo 	switch (cmd) {
    422   1.1       leo 	case GRFIOCON:
    423  1.22   tsutsui 		return 0;
    424   1.1       leo 		break;
    425   1.1       leo 	case GRFIOCOFF:
    426  1.22   tsutsui 		return 0;
    427   1.1       leo 		break;
    428   1.1       leo 	case GRFIOCGINFO:
    429  1.13  christos 		g_display.gd_fbaddr = (void *) (sc->sc_maddr);
    430   1.1       leo 		g_display.gd_fbsize = sc->sc_msize;
    431   1.3       leo 		g_display.gd_linbase = FRAME_BASE;
    432  1.13  christos 		g_display.gd_regaddr = (void *) (sc->sc_iobase);
    433   1.1       leo 		g_display.gd_regsize = sc->sc_iosize;
    434  1.13  christos 		g_display.gd_vgaaddr = (void *) (sc->sc_maddr);
    435   1.3       leo 		g_display.gd_vgasize = VGA_MAPPABLE;
    436   1.3       leo 		g_display.gd_vgabase = VGA_BASE;
    437   1.1       leo 		g_display.gd_colors = 16;
    438   1.1       leo 		g_display.gd_planes = 4;
    439   1.1       leo 		g_display.gd_fbwidth = 640;	/* XXX: should be 'unknown' */
    440   1.1       leo 		g_display.gd_fbheight = 400;	/* XXX: should be 'unknown' */
    441   1.1       leo 		g_display.gd_fbx = 0;
    442   1.1       leo 		g_display.gd_fby = 0;
    443   1.1       leo 		g_display.gd_dwidth = 0;
    444   1.1       leo 		g_display.gd_dheight = 0;
    445   1.1       leo 		g_display.gd_dx = 0;
    446   1.1       leo 		g_display.gd_dy = 0;
    447   1.1       leo 		g_display.gd_bank_size = 0;
    448  1.20   tsutsui 		memcpy(data, (void *)&g_display, sizeof(struct grfinfo));
    449   1.1       leo 		break;
    450   1.1       leo 	case GRFIOCMAP:
    451  1.22   tsutsui 		return EINVAL;
    452   1.1       leo 		break;
    453   1.1       leo 	case GRFIOCUNMAP:
    454  1.22   tsutsui 		return EINVAL;
    455   1.1       leo 		break;
    456   1.1       leo 	default:
    457  1.22   tsutsui 		return EINVAL;
    458   1.1       leo 		break;
    459   1.1       leo 	}
    460  1.22   tsutsui 	return 0;
    461   1.1       leo }
    462   1.1       leo 
    463   1.5    simonb paddr_t
    464  1.23   tsutsui et4kmmap(dev_t dev, off_t offset, int prot)
    465   1.1       leo {
    466  1.23   tsutsui 	struct et4k_softc *sc;
    467   1.1       leo 
    468  1.23   tsutsui 	sc = device_lookup_private(&et4k_cd, minor(dev));
    469   1.1       leo 
    470  1.28   tsutsui 	/*
    471   1.1       leo 	 * control registers
    472   1.1       leo 	 * mapped from offset 0x0 to REG_MAPPABLE
    473   1.1       leo 	 */
    474   1.1       leo 	if (offset >= 0 && offset <= sc->sc_iosize)
    475  1.22   tsutsui 		return m68k_btop(sc->sc_iobase + offset);
    476   1.1       leo 
    477   1.1       leo 	/*
    478   1.3       leo 	 * VGA memory
    479   1.3       leo 	 * mapped from offset 0xa0000 to 0xc0000
    480   1.3       leo 	 */
    481   1.3       leo 	if (offset >= VGA_BASE && offset < (VGA_MAPPABLE + VGA_BASE))
    482  1.22   tsutsui 		return m68k_btop(sc->sc_maddr + offset - VGA_BASE);
    483   1.3       leo 
    484   1.3       leo 	/*
    485   1.1       leo 	 * frame buffer
    486   1.3       leo 	 * mapped from offset 0x400000 to 0x4fffff
    487   1.1       leo 	 */
    488   1.3       leo 	if (offset >= FRAME_BASE && offset < sc->sc_msize + FRAME_BASE)
    489  1.22   tsutsui 		return m68k_btop(sc->sc_maddr + offset - FRAME_BASE);
    490   1.1       leo 
    491  1.22   tsutsui 	return -1;
    492   1.1       leo }
    493   1.1       leo 
    494  1.28   tsutsui int
    495  1.23   tsutsui et4kon(dev_t dev)
    496   1.1       leo {
    497  1.23   tsutsui 	struct et4k_softc *sc;
    498   1.1       leo 
    499  1.23   tsutsui 	if (minor(dev) >= et4k_cd.cd_ndevs)
    500  1.22   tsutsui 		return ENXIO;
    501  1.23   tsutsui 	sc = device_lookup_private(&et4k_cd, minor(dev));
    502  1.15   tsutsui 	if (sc == NULL)
    503  1.22   tsutsui 		return ENXIO;
    504  1.22   tsutsui 	return 0;
    505   1.1       leo }
    506   1.1       leo 
    507  1.28   tsutsui int
    508  1.23   tsutsui et4koff(dev_t dev)
    509   1.1       leo {
    510  1.22   tsutsui 
    511  1.22   tsutsui 	return 0;
    512   1.1       leo }
    513   1.1       leo 
    514