Home | History | Annotate | Line # | Download | only in obio
grf_obio.c revision 1.58.38.1
      1  1.58.38.1    martin /*	$NetBSD: grf_obio.c,v 1.58.38.1 2020/04/13 08:03:58 martin Exp $	*/
      2        1.1    briggs 
      3        1.1    briggs /*
      4       1.36    scottr  * Copyright (C) 1998 Scott Reynolds
      5       1.36    scottr  * All rights reserved.
      6       1.36    scottr  *
      7       1.36    scottr  * Redistribution and use in source and binary forms, with or without
      8       1.36    scottr  * modification, are permitted provided that the following conditions
      9       1.36    scottr  * are met:
     10       1.36    scottr  * 1. Redistributions of source code must retain the above copyright
     11       1.36    scottr  *    notice, this list of conditions and the following disclaimer.
     12       1.36    scottr  * 2. Redistributions in binary form must reproduce the above copyright
     13       1.36    scottr  *    notice, this list of conditions and the following disclaimer in the
     14       1.36    scottr  *    documentation and/or other materials provided with the distribution.
     15       1.36    scottr  * 3. The name of the author may not be used to endorse or promote products
     16       1.36    scottr  *    derived from this software without specific prior written permission.
     17       1.36    scottr  *
     18       1.36    scottr  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     19       1.36    scottr  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     20       1.36    scottr  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     21       1.36    scottr  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     22       1.36    scottr  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     23       1.36    scottr  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     24       1.36    scottr  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     25       1.36    scottr  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     26       1.36    scottr  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     27       1.36    scottr  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     28       1.36    scottr  */
     29       1.36    scottr /*
     30        1.1    briggs  * Copyright (c) 1995 Allen Briggs.  All rights reserved.
     31        1.1    briggs  *
     32        1.1    briggs  * Redistribution and use in source and binary forms, with or without
     33        1.1    briggs  * modification, are permitted provided that the following conditions
     34        1.1    briggs  * are met:
     35        1.1    briggs  * 1. Redistributions of source code must retain the above copyright
     36        1.1    briggs  *    notice, this list of conditions and the following disclaimer.
     37        1.1    briggs  * 2. Redistributions in binary form must reproduce the above copyright
     38        1.1    briggs  *    notice, this list of conditions and the following disclaimer in the
     39        1.1    briggs  *    documentation and/or other materials provided with the distribution.
     40        1.1    briggs  * 3. All advertising materials mentioning features or use of this software
     41        1.1    briggs  *    must display the following acknowledgement:
     42        1.1    briggs  *	This product includes software developed by Allen Briggs.
     43        1.1    briggs  * 4. The name of the author may not be used to endorse or promote products
     44        1.1    briggs  *    derived from this software without specific prior written permission.
     45        1.1    briggs  *
     46        1.1    briggs  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     47        1.1    briggs  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     48        1.1    briggs  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     49        1.1    briggs  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     50        1.1    briggs  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     51        1.1    briggs  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     52        1.1    briggs  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     53        1.1    briggs  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     54        1.1    briggs  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     55        1.1    briggs  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     56        1.1    briggs  */
     57        1.1    briggs /*
     58        1.1    briggs  * Graphics display driver for the Macintosh internal video for machines
     59        1.1    briggs  * that don't map it into a fake nubus card.
     60        1.1    briggs  */
     61       1.50     lukem 
     62       1.50     lukem #include <sys/cdefs.h>
     63  1.58.38.1    martin __KERNEL_RCSID(0, "$NetBSD: grf_obio.c,v 1.58.38.1 2020/04/13 08:03:58 martin Exp $");
     64       1.35    scottr 
     65        1.1    briggs #include <sys/param.h>
     66        1.1    briggs #include <sys/device.h>
     67        1.1    briggs #include <sys/ioctl.h>
     68  1.58.38.1    martin #include <sys/kmem.h>
     69        1.1    briggs #include <sys/file.h>
     70        1.1    briggs #include <sys/mman.h>
     71        1.1    briggs #include <sys/proc.h>
     72       1.11    briggs #include <sys/systm.h>
     73        1.1    briggs 
     74       1.18    briggs #include <machine/autoconf.h>
     75       1.17    scottr #include <machine/bus.h>
     76       1.17    scottr #include <machine/cpu.h>
     77        1.1    briggs #include <machine/grfioctl.h>
     78       1.18    briggs #include <machine/viareg.h>
     79       1.55      jmmv #include <machine/video.h>
     80        1.1    briggs 
     81       1.32    scottr #include <mac68k/nubus/nubus.h>
     82  1.58.38.1    martin #include <mac68k/obio/grf_obioreg.h>
     83       1.32    scottr #include <mac68k/obio/obiovar.h>
     84       1.22    scottr #include <mac68k/dev/grfvar.h>
     85        1.1    briggs 
     86       1.51       chs static int	grfiv_mode(struct grf_softc *, int, void *);
     87       1.58       chs static int	grfiv_match(device_t, cfdata_t, void *);
     88       1.58       chs static void	grfiv_attach(device_t, device_t, void *);
     89       1.12    scottr 
     90  1.58.38.1    martin static void	dafb_set_mapreg(void *, int, int, int, int);
     91  1.58.38.1    martin static void	civic_set_mapreg(void *, int, int, int, int);
     92  1.58.38.1    martin static void	valkyrie_set_mapreg(void *, int, int, int, int);
     93  1.58.38.1    martin static void	rbv_set_mapreg(void *, int, int, int, int);
     94  1.58.38.1    martin 
     95       1.58       chs CFATTACH_DECL_NEW(intvid, sizeof(struct grfbus_softc),
     96       1.49   thorpej     grfiv_match, grfiv_attach, NULL, NULL);
     97       1.11    briggs 
     98       1.11    briggs static int
     99       1.58       chs grfiv_match(device_t parent, cfdata_t cf, void *aux)
    100        1.1    briggs {
    101       1.22    scottr 	struct obio_attach_args *oa = (struct obio_attach_args *)aux;
    102       1.22    scottr 	bus_space_handle_t bsh;
    103       1.34    scottr 	int found;
    104       1.27    scottr 	u_int base;
    105       1.18    briggs 
    106       1.18    briggs 	found = 1;
    107       1.18    briggs 
    108       1.27    scottr 	switch (current_mac_model->class) {
    109       1.36    scottr 	case MACH_CLASSQ2:
    110       1.36    scottr 		if (current_mac_model->machineid != MACH_MACLC575) {
    111       1.36    scottr 			base = VALKYRIE_CONTROL_BASE;
    112       1.36    scottr 
    113       1.36    scottr 			if (bus_space_map(oa->oa_tag, base, 0x40, 0, &bsh))
    114       1.36    scottr 				return 0;
    115       1.36    scottr 
    116       1.36    scottr 			/* Disable interrupts */
    117       1.36    scottr 			bus_space_write_1(oa->oa_tag, bsh, 0x18, 0x1);
    118       1.47    scottr 
    119       1.47    scottr 			bus_space_unmap(oa->oa_tag, bsh, 0x40);
    120       1.39    scottr 			break;
    121       1.36    scottr 		}
    122       1.36    scottr 		/*
    123       1.36    scottr 		 * Note:  the only system in this class that does not have
    124       1.36    scottr 		 * the Valkyrie chip -- at least, that we know of -- is
    125       1.36    scottr 		 * the Performa/LC 57x series.  This system has a version
    126       1.36    scottr 		 * of the DAFB controller, instead.
    127       1.36    scottr 		 *
    128       1.36    scottr 		 * If this assumption proves false, we'll have to be more
    129       1.36    scottr 		 * intelligent here.
    130       1.36    scottr 		 */
    131       1.36    scottr 		/*FALLTHROUGH*/
    132       1.20    briggs 	case MACH_CLASSQ:
    133       1.20    briggs 		/*
    134       1.20    briggs 		 * Assume DAFB for all of these, unless we can't
    135       1.20    briggs 		 * access the memory.
    136       1.20    briggs 		 */
    137       1.36    scottr 		base = DAFB_CONTROL_BASE;
    138       1.18    briggs 
    139       1.46    scottr 		if (bus_space_map(oa->oa_tag, base, 0x20, 0, &bsh))
    140       1.36    scottr 			return 0;
    141       1.18    briggs 
    142       1.36    scottr 		if (mac68k_bus_space_probe(oa->oa_tag, bsh, 0x1c, 4) == 0) {
    143       1.46    scottr 			bus_space_unmap(oa->oa_tag, bsh, 0x20);
    144       1.36    scottr 			return 0;
    145       1.20    briggs 		}
    146       1.20    briggs 
    147       1.46    scottr 		bus_space_unmap(oa->oa_tag, bsh, 0x20);
    148       1.46    scottr 
    149       1.46    scottr 		if (bus_space_map(oa->oa_tag, base + 0x100, 0x20, 0, &bsh))
    150       1.46    scottr 			return 0;
    151       1.46    scottr 
    152       1.46    scottr 		if (mac68k_bus_space_probe(oa->oa_tag, bsh, 0x04, 4) == 0) {
    153       1.46    scottr 			bus_space_unmap(oa->oa_tag, bsh, 0x20);
    154       1.46    scottr 			return 0;
    155       1.46    scottr 		}
    156        1.1    briggs 
    157       1.18    briggs 		/* Disable interrupts */
    158       1.46    scottr 		bus_space_write_4(oa->oa_tag, bsh, 0x04, 0);
    159       1.18    briggs 
    160       1.18    briggs 		/* Clear any interrupts */
    161       1.46    scottr 		bus_space_write_4(oa->oa_tag, bsh, 0x0C, 0);
    162       1.46    scottr 		bus_space_write_4(oa->oa_tag, bsh, 0x10, 0);
    163       1.46    scottr 		bus_space_write_4(oa->oa_tag, bsh, 0x14, 0);
    164       1.18    briggs 
    165       1.46    scottr 		bus_space_unmap(oa->oa_tag, bsh, 0x20);
    166       1.18    briggs 		break;
    167       1.27    scottr 	case MACH_CLASSAV:
    168       1.26    briggs 		base = CIVIC_CONTROL_BASE;
    169       1.26    briggs 
    170       1.36    scottr 		if (bus_space_map(oa->oa_tag, base, 0x1000, 0, &bsh))
    171       1.36    scottr 			return 0;
    172       1.27    scottr 
    173       1.25    briggs 		/* Disable interrupts */
    174       1.25    briggs 		bus_space_write_1(oa->oa_tag, bsh, 0x120, 0);
    175       1.26    briggs 
    176       1.25    briggs 		bus_space_unmap(oa->oa_tag, bsh, 0x1000);
    177       1.25    briggs 		break;
    178       1.41    scottr 	case MACH_CLASSIIci:
    179       1.41    scottr 	case MACH_CLASSIIsi:
    180       1.56      jmmv 		if (mac68k_video.mv_len == 0 ||
    181       1.41    scottr 		    (via2_reg(rMonitor) & RBVMonitorMask) == RBVMonIDNone)
    182       1.41    scottr 			found = 0;
    183       1.41    scottr 		break;
    184       1.18    briggs 	default:
    185       1.56      jmmv 		if (mac68k_video.mv_len == 0)
    186       1.18    briggs 			found = 0;
    187       1.18    briggs 		break;
    188        1.2    briggs 	}
    189        1.7    briggs 
    190       1.18    briggs 	return found;
    191        1.1    briggs }
    192        1.1    briggs 
    193       1.11    briggs static void
    194       1.58       chs grfiv_attach(device_t parent, device_t self, void *aux)
    195        1.1    briggs {
    196       1.22    scottr 	struct obio_attach_args *oa = (struct obio_attach_args *)aux;
    197       1.22    scottr 	struct grfbus_softc *sc;
    198       1.22    scottr 	struct grfmode *gm;
    199       1.36    scottr 	u_long base, length;
    200       1.36    scottr 	u_int32_t vbase1, vbase2;
    201       1.11    briggs 
    202       1.58       chs 	sc = device_private(self);
    203       1.58       chs 	sc->sc_dev = self;
    204        1.1    briggs 
    205        1.1    briggs 	sc->card_id = 0;
    206        1.1    briggs 
    207       1.27    scottr 	switch (current_mac_model->class) {
    208       1.36    scottr 	case MACH_CLASSQ2:
    209       1.39    scottr 		if (current_mac_model->machineid != MACH_MACLC575) {
    210  1.58.38.1    martin 			sc->sc_basepa = VALKYRIE_FB_BASE;
    211       1.36    scottr 			length = 0x00100000;		/* 1MB */
    212       1.36    scottr 
    213       1.56      jmmv 			if (sc->sc_basepa <= mac68k_video.mv_phys &&
    214       1.56      jmmv 			    mac68k_video.mv_phys < (sc->sc_basepa + length)) {
    215       1.56      jmmv 				sc->sc_fbofs =
    216       1.56      jmmv 				    mac68k_video.mv_phys - sc->sc_basepa;
    217       1.44    scottr 			} else {
    218       1.56      jmmv 				sc->sc_basepa =
    219       1.56      jmmv 				    m68k_trunc_page(mac68k_video.mv_phys);
    220       1.56      jmmv 				sc->sc_fbofs =
    221       1.56      jmmv 				    m68k_page_offset(mac68k_video.mv_phys);
    222       1.56      jmmv 				length = mac68k_video.mv_len + sc->sc_fbofs;
    223       1.44    scottr 			}
    224       1.36    scottr 
    225  1.58.38.1    martin 			if (bus_space_map(sc->sc_tag, VALKYRIE_CMAP_BASE,
    226  1.58.38.1    martin 			    VALKYRIE_CMAP_LEN, 0, &sc->sc_cmh) == 0)
    227  1.58.38.1    martin 				sc->sc_set_mapreg = valkyrie_set_mapreg;
    228  1.58.38.1    martin 
    229       1.36    scottr 			printf(" @ %lx: Valkyrie video subsystem\n",
    230       1.36    scottr 			    sc->sc_basepa + sc->sc_fbofs);
    231       1.36    scottr 			break;
    232       1.36    scottr 		}
    233       1.36    scottr 		/* See note in grfiv_match() */
    234       1.36    scottr 		/*FALLTHROUGH*/
    235       1.27    scottr 	case MACH_CLASSQ:
    236       1.36    scottr 		base = DAFB_CONTROL_BASE;
    237       1.18    briggs 		sc->sc_tag = oa->oa_tag;
    238       1.46    scottr 		if (bus_space_map(sc->sc_tag, base, 0x20, 0, &sc->sc_regh)) {
    239       1.36    scottr 			printf(": failed to map DAFB register space\n");
    240       1.36    scottr 			return;
    241       1.18    briggs 		}
    242       1.36    scottr 
    243  1.58.38.1    martin 		sc->sc_basepa = DAFB_FB_BASE;
    244       1.36    scottr 		length = 0x00100000;		/* 1MB */
    245       1.36    scottr 
    246       1.36    scottr 		/* Compute the current frame buffer offset */
    247       1.36    scottr 		vbase1 = bus_space_read_4(sc->sc_tag, sc->sc_regh, 0x0) & 0xfff;
    248       1.38    scottr #if 1
    249       1.38    scottr 		/*
    250       1.42    scottr 		 * XXX The following exists because the DAFB v7 in these
    251       1.42    scottr 		 * systems doesn't return reasonable values to use for fbofs.
    252       1.42    scottr 		 * Ken'ichi Ishizaka gets credit for this hack.  (sar 19990426)
    253       1.42    scottr 		 * (Does this get us the correct result for _all_ DAFB-
    254       1.42    scottr 		 * equipped systems and monitor combinations?  It seems
    255       1.42    scottr 		 * possible, if not likely...)
    256       1.38    scottr 		 */
    257       1.38    scottr 		switch (current_mac_model->machineid) {
    258       1.38    scottr 		case MACH_MACLC475:
    259       1.38    scottr 		case MACH_MACLC475_33:
    260       1.38    scottr 		case MACH_MACLC575:
    261       1.43    scottr 		case MACH_MACQ605:
    262       1.43    scottr 		case MACH_MACQ605_33:
    263       1.42    scottr 			vbase1 &= 0x3f;
    264       1.38    scottr 			break;
    265       1.38    scottr 		}
    266       1.38    scottr #endif
    267       1.42    scottr 		vbase2 = bus_space_read_4(sc->sc_tag, sc->sc_regh, 0x4) & 0xf;
    268       1.42    scottr 		sc->sc_fbofs = (vbase1 << 9) | (vbase2 << 5);
    269       1.36    scottr 
    270  1.58.38.1    martin 		if (bus_space_map(sc->sc_tag, DAFB_CMAP_BASE, DAFB_CMAP_LEN,
    271  1.58.38.1    martin 		    0, &sc->sc_cmh) == 0) {
    272  1.58.38.1    martin 			uint8_t *buf = kmem_zalloc(256 * 3, KM_SLEEP);
    273  1.58.38.1    martin 			sc->sc_cmap.red = buf;
    274  1.58.38.1    martin 			sc->sc_cmap.green = buf + 256;
    275  1.58.38.1    martin 			sc->sc_cmap.blue = buf + 256 * 2;
    276  1.58.38.1    martin 			sc->sc_set_mapreg = dafb_set_mapreg;
    277  1.58.38.1    martin 		}
    278  1.58.38.1    martin 
    279       1.36    scottr 		printf(" @ %lx: DAFB video subsystem, monitor sense %x\n",
    280       1.36    scottr 		    sc->sc_basepa + sc->sc_fbofs,
    281       1.36    scottr 		    (bus_space_read_4(sc->sc_tag, sc->sc_regh, 0x1c) & 0x7));
    282       1.36    scottr 
    283       1.46    scottr 		bus_space_unmap(sc->sc_tag, sc->sc_regh, 0x20);
    284       1.18    briggs 		break;
    285       1.27    scottr 	case MACH_CLASSAV:
    286  1.58.38.1    martin 		sc->sc_basepa = CIVIC_FB_BASE;
    287       1.36    scottr 		length = 0x00200000;		/* 2MB */
    288       1.56      jmmv 		if (mac68k_video.mv_phys >= sc->sc_basepa &&
    289       1.56      jmmv 		    mac68k_video.mv_phys < (sc->sc_basepa + length)) {
    290       1.56      jmmv 			sc->sc_fbofs = mac68k_video.mv_phys - sc->sc_basepa;
    291       1.44    scottr 		} else {
    292       1.56      jmmv 			sc->sc_basepa = m68k_trunc_page(mac68k_video.mv_phys);
    293       1.56      jmmv 			sc->sc_fbofs = m68k_page_offset(mac68k_video.mv_phys);
    294       1.56      jmmv 			length = mac68k_video.mv_len + sc->sc_fbofs;
    295       1.44    scottr 		}
    296       1.36    scottr 
    297  1.58.38.1    martin 		if (bus_space_map(sc->sc_tag, CIVIC_CMAP_BASE, CIVIC_CMAP_LEN,
    298  1.58.38.1    martin 		    0, &sc->sc_cmh) == 0)
    299  1.58.38.1    martin 			sc->sc_set_mapreg = civic_set_mapreg;
    300  1.58.38.1    martin 
    301       1.44    scottr 		printf(" @ %lx: CIVIC video subsystem\n",
    302       1.36    scottr 		    sc->sc_basepa + sc->sc_fbofs);
    303       1.41    scottr 		break;
    304       1.41    scottr 	case MACH_CLASSIIci:
    305       1.41    scottr 	case MACH_CLASSIIsi:
    306       1.56      jmmv 		sc->sc_basepa = m68k_trunc_page(mac68k_video.mv_phys);
    307       1.56      jmmv 		sc->sc_fbofs = m68k_page_offset(mac68k_video.mv_phys);
    308       1.56      jmmv 		length = mac68k_video.mv_len + sc->sc_fbofs;
    309       1.41    scottr 
    310  1.58.38.1    martin 		if (bus_space_map(sc->sc_tag, RBV_CMAP_BASE, RBV_CMAP_LEN,
    311  1.58.38.1    martin 		    0, &sc->sc_cmh) == 0)
    312  1.58.38.1    martin 			sc->sc_set_mapreg = rbv_set_mapreg;
    313  1.58.38.1    martin 
    314       1.41    scottr 		printf(" @ %lx: RBV video subsystem, ",
    315       1.41    scottr 		    sc->sc_basepa + sc->sc_fbofs);
    316       1.41    scottr 		switch (via2_reg(rMonitor) & RBVMonitorMask) {
    317       1.41    scottr 		case RBVMonIDBWP:
    318       1.41    scottr 			printf("15\" monochrome portrait");
    319       1.41    scottr 			break;
    320       1.41    scottr 		case RBVMonIDRGB12:
    321       1.41    scottr 			printf("12\" color");
    322       1.41    scottr 			break;
    323       1.41    scottr 		case RBVMonIDRGB15:
    324       1.41    scottr 			printf("15\" color");
    325       1.41    scottr 			break;
    326       1.41    scottr 		case RBVMonIDStd:
    327       1.41    scottr 			printf("Macintosh II");
    328       1.41    scottr 			break;
    329       1.41    scottr 		default:
    330       1.41    scottr 			printf("unrecognized");
    331       1.41    scottr 			break;
    332       1.41    scottr 		}
    333       1.41    scottr 		printf(" display\n");
    334       1.41    scottr 
    335       1.36    scottr 		break;
    336       1.18    briggs 	default:
    337       1.56      jmmv 		sc->sc_basepa = m68k_trunc_page(mac68k_video.mv_phys);
    338       1.56      jmmv 		sc->sc_fbofs = m68k_page_offset(mac68k_video.mv_phys);
    339       1.56      jmmv 		length = mac68k_video.mv_len + sc->sc_fbofs;
    340       1.36    scottr 
    341  1.58.38.1    martin 		/* XXX setpalette? */
    342  1.58.38.1    martin 
    343       1.36    scottr 		printf(" @ %lx: On-board video\n",
    344       1.36    scottr 		    sc->sc_basepa + sc->sc_fbofs);
    345       1.18    briggs 		break;
    346       1.18    briggs 	}
    347        1.1    briggs 
    348       1.36    scottr 	if (bus_space_map(sc->sc_tag, sc->sc_basepa, length, 0,
    349       1.36    scottr 	    &sc->sc_handle)) {
    350       1.58       chs 		printf("%s: failed to map video RAM\n", device_xname(sc->sc_dev));
    351       1.36    scottr 		return;
    352       1.36    scottr 	}
    353       1.36    scottr 
    354       1.56      jmmv 	if (sc->sc_basepa <= mac68k_video.mv_phys &&
    355       1.56      jmmv 	    mac68k_video.mv_phys < (sc->sc_basepa + length)) {
    356       1.56      jmmv 		/* XXX Hack */
    357       1.56      jmmv 		mac68k_video.mv_kvaddr = sc->sc_handle.base + sc->sc_fbofs;
    358       1.56      jmmv 	}
    359       1.36    scottr 
    360        1.1    briggs 	gm = &(sc->curr_mode);
    361        1.1    briggs 	gm->mode_id = 0;
    362       1.56      jmmv 	gm->psize = mac68k_video.mv_depth;
    363        1.1    briggs 	gm->ptype = 0;
    364       1.56      jmmv 	gm->width = mac68k_video.mv_width;
    365       1.56      jmmv 	gm->height = mac68k_video.mv_height;
    366       1.56      jmmv 	gm->rowbytes = mac68k_video.mv_stride;
    367       1.36    scottr 	gm->hres = 80;				/* XXX hack */
    368       1.36    scottr 	gm->vres = 80;				/* XXX hack */
    369       1.36    scottr 	gm->fbsize = gm->height * gm->rowbytes;
    370       1.53  christos 	gm->fbbase = (void *)sc->sc_handle.base; /* XXX yet another hack */
    371       1.36    scottr 	gm->fboff = sc->sc_fbofs;
    372        1.1    briggs 
    373       1.12    scottr 	/* Perform common video attachment. */
    374       1.33    scottr 	grf_establish(sc, NULL, grfiv_mode);
    375        1.1    briggs }
    376        1.1    briggs 
    377       1.11    briggs static int
    378       1.51       chs grfiv_mode(struct grf_softc *sc, int cmd, void *arg)
    379        1.1    briggs {
    380        1.4    briggs 	switch (cmd) {
    381        1.4    briggs 	case GM_GRFON:
    382        1.4    briggs 	case GM_GRFOFF:
    383        1.4    briggs 		return 0;
    384        1.4    briggs 	case GM_CURRMODE:
    385        1.4    briggs 		break;
    386        1.4    briggs 	case GM_NEWMODE:
    387        1.4    briggs 		break;
    388        1.4    briggs 	case GM_LISTMODES:
    389        1.4    briggs 		break;
    390        1.4    briggs 	}
    391        1.4    briggs 	return EINVAL;
    392        1.1    briggs }
    393  1.58.38.1    martin 
    394  1.58.38.1    martin #define	CHECK_INDEX(index)						\
    395  1.58.38.1    martin 	do {								\
    396  1.58.38.1    martin 		size_t depth = mac68k_video.mv_depth;			\
    397  1.58.38.1    martin 		if (depth == 1 || depth > 8 || (index) >= (1 << depth))	\
    398  1.58.38.1    martin 			return;						\
    399  1.58.38.1    martin 	} while (0 /* CONSTCOND */)
    400  1.58.38.1    martin 
    401  1.58.38.1    martin static void
    402  1.58.38.1    martin dafb_set_mapreg(void *cookie, int index, int r, int g, int b)
    403  1.58.38.1    martin {
    404  1.58.38.1    martin 	struct grfbus_softc *sc = (struct grfbus_softc *)cookie;
    405  1.58.38.1    martin 	static int last = -2;
    406  1.58.38.1    martin 
    407  1.58.38.1    martin 	CHECK_INDEX(index);
    408  1.58.38.1    martin 
    409  1.58.38.1    martin #define	dafb_write_lut(val)	\
    410  1.58.38.1    martin     bus_space_write_1(sc->sc_tag, sc->sc_cmh, DAFB_CMAP_LUT, val)
    411  1.58.38.1    martin 
    412  1.58.38.1    martin 	if (index != last + 1) {
    413  1.58.38.1    martin 		bus_space_write_4(sc->sc_tag, sc->sc_cmh, DAFB_CMAP_RESET, 0);
    414  1.58.38.1    martin 		for (int i = 0; i < index; i++) {
    415  1.58.38.1    martin 			dafb_write_lut(sc->sc_cmap.red[i]);
    416  1.58.38.1    martin 			dafb_write_lut(sc->sc_cmap.green[i]);
    417  1.58.38.1    martin 			dafb_write_lut(sc->sc_cmap.blue[i]);
    418  1.58.38.1    martin 		}
    419  1.58.38.1    martin 	}
    420  1.58.38.1    martin 
    421  1.58.38.1    martin 	dafb_write_lut(r);
    422  1.58.38.1    martin 	dafb_write_lut(g);
    423  1.58.38.1    martin 	dafb_write_lut(b);
    424  1.58.38.1    martin 
    425  1.58.38.1    martin 	last = index;
    426  1.58.38.1    martin 	sc->sc_cmap.red[index] = r;
    427  1.58.38.1    martin 	sc->sc_cmap.green[index] = g;
    428  1.58.38.1    martin 	sc->sc_cmap.blue[index] = b;
    429  1.58.38.1    martin 
    430  1.58.38.1    martin #undef	dafb_write_lut
    431  1.58.38.1    martin 
    432  1.58.38.1    martin }
    433  1.58.38.1    martin 
    434  1.58.38.1    martin static void
    435  1.58.38.1    martin civic_set_mapreg(void *cookie, int index, int r, int g, int b)
    436  1.58.38.1    martin {
    437  1.58.38.1    martin 	struct grfbus_softc *sc = (struct grfbus_softc *)cookie;
    438  1.58.38.1    martin 	uint8_t status, junk = 0;
    439  1.58.38.1    martin 
    440  1.58.38.1    martin 	CHECK_INDEX(index);
    441  1.58.38.1    martin 
    442  1.58.38.1    martin #define	civic_read_lut		\
    443  1.58.38.1    martin     bus_space_read_1(sc->sc_tag, sc->sc_cmh, CIVIC_CMAP_LUT)
    444  1.58.38.1    martin #define	civic_write_lut(val)	\
    445  1.58.38.1    martin     bus_space_write_1(sc->sc_tag, sc->sc_cmh, CIVIC_CMAP_LUT, val)
    446  1.58.38.1    martin 
    447  1.58.38.1    martin 	bus_space_write_1(sc->sc_tag, sc->sc_cmh, CIVIC_CMAP_ADDR, index);
    448  1.58.38.1    martin 	status = bus_space_read_1(sc->sc_tag, sc->sc_cmh, CIVIC_CMAP_STATUS2);
    449  1.58.38.1    martin 	if (status & 0x08) {
    450  1.58.38.1    martin 		junk = civic_read_lut;
    451  1.58.38.1    martin 		junk = civic_read_lut;
    452  1.58.38.1    martin 		junk = civic_read_lut;
    453  1.58.38.1    martin 		junk = civic_read_lut;
    454  1.58.38.1    martin 		if (status & 0x0d) {
    455  1.58.38.1    martin 			civic_write_lut(0);
    456  1.58.38.1    martin 			civic_write_lut(0);
    457  1.58.38.1    martin 		}
    458  1.58.38.1    martin 	}
    459  1.58.38.1    martin 	civic_write_lut(r);
    460  1.58.38.1    martin 	civic_write_lut(g);
    461  1.58.38.1    martin 	civic_write_lut(b);
    462  1.58.38.1    martin 	civic_write_lut(junk);
    463  1.58.38.1    martin 
    464  1.58.38.1    martin #undef	civic_read_lut
    465  1.58.38.1    martin #undef	civic_write_lut
    466  1.58.38.1    martin 
    467  1.58.38.1    martin }
    468  1.58.38.1    martin 
    469  1.58.38.1    martin static void
    470  1.58.38.1    martin valkyrie_set_mapreg(void *cookie, int index, int r, int g, int b)
    471  1.58.38.1    martin {
    472  1.58.38.1    martin 	struct grfbus_softc *sc = (struct grfbus_softc *)cookie;
    473  1.58.38.1    martin 
    474  1.58.38.1    martin 	CHECK_INDEX(index);
    475  1.58.38.1    martin 
    476  1.58.38.1    martin #define	valkyrie_write_lut(val)	\
    477  1.58.38.1    martin     bus_space_write_1(sc->sc_tag, sc->sc_cmh, VALKYRIE_CMAP_LUT, val)
    478  1.58.38.1    martin 
    479  1.58.38.1    martin 	bus_space_write_1(sc->sc_tag, sc->sc_cmh, VALKYRIE_CMAP_ADDR, index);
    480  1.58.38.1    martin 	delay(1);
    481  1.58.38.1    martin 	valkyrie_write_lut(r);
    482  1.58.38.1    martin 	valkyrie_write_lut(g);
    483  1.58.38.1    martin 	valkyrie_write_lut(b);
    484  1.58.38.1    martin 
    485  1.58.38.1    martin #undef	valkyrie_write_lut
    486  1.58.38.1    martin 
    487  1.58.38.1    martin }
    488  1.58.38.1    martin 
    489  1.58.38.1    martin static void
    490  1.58.38.1    martin rbv_set_mapreg(void *cookie, int index, int r, int g, int b)
    491  1.58.38.1    martin {
    492  1.58.38.1    martin 	struct grfbus_softc *sc = (struct grfbus_softc *)cookie;
    493  1.58.38.1    martin 
    494  1.58.38.1    martin 	CHECK_INDEX(index);
    495  1.58.38.1    martin 
    496  1.58.38.1    martin #define	rbv_write_lut(val)	\
    497  1.58.38.1    martin     bus_space_write_1(sc->sc_tag, sc->sc_cmh, RBV_CMAP_LUT, val)
    498  1.58.38.1    martin 
    499  1.58.38.1    martin 	index += 256 - (1 << mac68k_video.mv_depth);
    500  1.58.38.1    martin 	bus_space_write_1(sc->sc_tag, sc->sc_cmh, RBV_CMAP_CNTL, 0xff);
    501  1.58.38.1    martin 	bus_space_write_1(sc->sc_tag, sc->sc_cmh, RBV_CMAP_ADDR, index);
    502  1.58.38.1    martin 	rbv_write_lut(r);
    503  1.58.38.1    martin 	rbv_write_lut(g);
    504  1.58.38.1    martin 	rbv_write_lut(b);
    505  1.58.38.1    martin 
    506  1.58.38.1    martin #undef	rbv_write_lut
    507  1.58.38.1    martin 
    508  1.58.38.1    martin }
    509  1.58.38.1    martin 
    510  1.58.38.1    martin #undef	CHECK_INDEX
    511