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