Home | History | Annotate | Line # | Download | only in dev
cgeight.c revision 1.50
      1  1.50       snj /*	$NetBSD: cgeight.c,v 1.50 2014/10/18 08:33:26 snj Exp $	*/
      2  1.14   thorpej 
      3  1.14   thorpej /*-
      4  1.14   thorpej  * Copyright (c) 1996, 1997 The NetBSD Foundation, Inc.
      5  1.14   thorpej  * All rights reserved.
      6  1.14   thorpej  *
      7  1.14   thorpej  * This code is derived from software contributed to The NetBSD Foundation
      8  1.14   thorpej  * by Jason R. Thorpe.
      9  1.14   thorpej  *
     10  1.14   thorpej  * Redistribution and use in source and binary forms, with or without
     11  1.14   thorpej  * modification, are permitted provided that the following conditions
     12  1.14   thorpej  * are met:
     13  1.14   thorpej  * 1. Redistributions of source code must retain the above copyright
     14  1.14   thorpej  *    notice, this list of conditions and the following disclaimer.
     15  1.14   thorpej  * 2. Redistributions in binary form must reproduce the above copyright
     16  1.14   thorpej  *    notice, this list of conditions and the following disclaimer in the
     17  1.14   thorpej  *    documentation and/or other materials provided with the distribution.
     18  1.14   thorpej  *
     19  1.14   thorpej  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20  1.14   thorpej  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21  1.14   thorpej  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22  1.14   thorpej  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23  1.14   thorpej  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24  1.14   thorpej  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25  1.14   thorpej  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26  1.14   thorpej  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27  1.14   thorpej  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28  1.14   thorpej  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29  1.14   thorpej  * POSSIBILITY OF SUCH DAMAGE.
     30  1.14   thorpej  */
     31   1.1   thorpej 
     32   1.1   thorpej /*
     33   1.1   thorpej  * Copyright (c) 1992, 1993
     34   1.1   thorpej  *	The Regents of the University of California.  All rights reserved.
     35   1.1   thorpej  *
     36   1.1   thorpej  * This software was developed by the Computer Systems Engineering group
     37   1.1   thorpej  * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
     38   1.1   thorpej  * contributed to Berkeley.
     39   1.1   thorpej  *
     40   1.1   thorpej  * All advertising materials mentioning features or use of this software
     41   1.1   thorpej  * must display the following acknowledgement:
     42   1.1   thorpej  *	This product includes software developed by the University of
     43   1.1   thorpej  *	California, Lawrence Berkeley Laboratory.
     44   1.1   thorpej  *
     45   1.1   thorpej  * Redistribution and use in source and binary forms, with or without
     46   1.1   thorpej  * modification, are permitted provided that the following conditions
     47   1.1   thorpej  * are met:
     48   1.1   thorpej  * 1. Redistributions of source code must retain the above copyright
     49   1.1   thorpej  *    notice, this list of conditions and the following disclaimer.
     50   1.1   thorpej  * 2. Redistributions in binary form must reproduce the above copyright
     51   1.1   thorpej  *    notice, this list of conditions and the following disclaimer in the
     52   1.1   thorpej  *    documentation and/or other materials provided with the distribution.
     53  1.36       agc  * 3. Neither the name of the University nor the names of its contributors
     54  1.36       agc  *    may be used to endorse or promote products derived from this software
     55  1.36       agc  *    without specific prior written permission.
     56  1.36       agc  *
     57  1.36       agc  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     58  1.36       agc  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     59  1.36       agc  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     60  1.36       agc  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     61  1.36       agc  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     62  1.36       agc  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     63  1.36       agc  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     64  1.36       agc  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     65  1.36       agc  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     66  1.36       agc  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     67  1.36       agc  * SUCH DAMAGE.
     68  1.36       agc  *
     69  1.36       agc  *	from @(#)cgthree.c	8.2 (Berkeley) 10/30/93
     70  1.36       agc  */
     71  1.36       agc 
     72  1.36       agc /*
     73  1.40       agc  * Copyright (c) 1995 Theo de Raadt.  All rights reserved.
     74  1.36       agc  *
     75  1.36       agc  * Redistribution and use in source and binary forms, with or without
     76  1.36       agc  * modification, are permitted provided that the following conditions
     77  1.36       agc  * are met:
     78  1.36       agc  * 1. Redistributions of source code must retain the above copyright
     79  1.36       agc  *    notice, this list of conditions and the following disclaimer.
     80  1.36       agc  * 2. Redistributions in binary form must reproduce the above copyright
     81  1.36       agc  *    notice, this list of conditions and the following disclaimer in the
     82  1.36       agc  *    documentation and/or other materials provided with the distribution.
     83   1.1   thorpej  *
     84  1.40       agc  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     85  1.40       agc  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     86  1.40       agc  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     87  1.40       agc  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     88  1.40       agc  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     89  1.40       agc  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     90  1.40       agc  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     91  1.40       agc  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     92  1.40       agc  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     93  1.40       agc  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     94   1.1   thorpej  */
     95   1.1   thorpej 
     96   1.1   thorpej /*
     97   1.1   thorpej  * color display (cgeight) driver.
     98   1.1   thorpej  *
     99   1.1   thorpej  * Does not handle interrupts, even though they can occur.
    100   1.1   thorpej  *
    101   1.1   thorpej  * XXX should defer colormap updates to vertical retrace interrupts
    102   1.1   thorpej  */
    103  1.35     lukem 
    104  1.35     lukem #include <sys/cdefs.h>
    105  1.50       snj __KERNEL_RCSID(0, "$NetBSD: cgeight.c,v 1.50 2014/10/18 08:33:26 snj Exp $");
    106   1.1   thorpej 
    107   1.1   thorpej #include <sys/param.h>
    108   1.4  christos #include <sys/systm.h>
    109   1.1   thorpej #include <sys/buf.h>
    110   1.1   thorpej #include <sys/device.h>
    111   1.1   thorpej #include <sys/ioctl.h>
    112   1.1   thorpej #include <sys/malloc.h>
    113   1.1   thorpej #include <sys/mman.h>
    114   1.1   thorpej #include <sys/tty.h>
    115   1.7  christos #include <sys/conf.h>
    116   1.1   thorpej 
    117  1.32   thorpej #include <uvm/uvm_extern.h>
    118   1.1   thorpej 
    119   1.1   thorpej #include <machine/autoconf.h>
    120   1.1   thorpej #include <machine/eeprom.h>
    121   1.1   thorpej 
    122  1.24        pk #include <dev/sun/fbio.h>
    123  1.24        pk #include <dev/sun/fbvar.h>
    124  1.24        pk #include <dev/sun/btreg.h>
    125  1.24        pk #include <dev/sun/btvar.h>
    126  1.24        pk #include <dev/sun/pfourreg.h>
    127   1.1   thorpej 
    128   1.1   thorpej /* per-display variables */
    129   1.1   thorpej struct cgeight_softc {
    130  1.16        pk 	struct fbdevice	sc_fb;		/* frame buffer device */
    131  1.16        pk 	bus_space_tag_t	sc_bustag;
    132  1.26        pk 	bus_addr_t	sc_paddr;	/* phys address for device mmap() */
    133  1.16        pk 
    134   1.1   thorpej 	volatile struct fbcontrol *sc_fbc;	/* Brooktree registers */
    135  1.16        pk 	union bt_cmap	sc_cmap;	/* Brooktree color map */
    136   1.1   thorpej };
    137   1.1   thorpej 
    138   1.1   thorpej /* autoconfiguration driver */
    139  1.47       mrg static void	cgeightattach(device_t, device_t, void *);
    140  1.47       mrg static int	cgeightmatch(device_t, cfdata_t, void *);
    141   1.6        pk #if defined(SUN4)
    142  1.47       mrg static void	cgeightunblank(device_t);
    143   1.6        pk #endif
    144   1.1   thorpej 
    145  1.41       uwe static int	cg8_pfour_probe(void *, void *);
    146  1.16        pk 
    147  1.47       mrg CFATTACH_DECL_NEW(cgeight, sizeof(struct cgeight_softc),
    148  1.30   thorpej     cgeightmatch, cgeightattach, NULL, NULL);
    149   1.5   thorpej 
    150  1.15   thorpej extern struct cfdriver cgeight_cd;
    151   1.1   thorpej 
    152  1.27   gehenna dev_type_open(cgeightopen);
    153  1.27   gehenna dev_type_ioctl(cgeightioctl);
    154  1.27   gehenna dev_type_mmap(cgeightmmap);
    155  1.27   gehenna 
    156  1.27   gehenna const struct cdevsw cgeight_cdevsw = {
    157  1.48  dholland 	.d_open = cgeightopen,
    158  1.48  dholland 	.d_close = nullclose,
    159  1.48  dholland 	.d_read = noread,
    160  1.48  dholland 	.d_write = nowrite,
    161  1.48  dholland 	.d_ioctl = cgeightioctl,
    162  1.48  dholland 	.d_stop = nostop,
    163  1.48  dholland 	.d_tty = notty,
    164  1.48  dholland 	.d_poll = nopoll,
    165  1.48  dholland 	.d_mmap = cgeightmmap,
    166  1.48  dholland 	.d_kqfilter = nokqfilter,
    167  1.49  dholland 	.d_discard = nodiscard,
    168  1.48  dholland 	.d_flag = 0
    169  1.27   gehenna };
    170  1.27   gehenna 
    171   1.6        pk #if defined(SUN4)
    172   1.1   thorpej /* frame buffer generic driver */
    173   1.1   thorpej static struct fbdriver cgeightfbdriver = {
    174  1.41       uwe 	cgeightunblank, cgeightopen, nullclose, cgeightioctl,
    175  1.31  jdolecek 	nopoll, cgeightmmap, nokqfilter
    176   1.1   thorpej };
    177   1.1   thorpej 
    178  1.41       uwe static void cgeightloadcmap(struct cgeight_softc *, int, int);
    179  1.41       uwe static int cgeight_get_video(struct cgeight_softc *);
    180  1.41       uwe static void cgeight_set_video(struct cgeight_softc *, int);
    181   1.6        pk #endif
    182   1.1   thorpej 
    183   1.1   thorpej /*
    184   1.1   thorpej  * Match a cgeight.
    185   1.1   thorpej  */
    186  1.41       uwe static int
    187  1.47       mrg cgeightmatch(device_t parent, cfdata_t cf, void *aux)
    188   1.1   thorpej {
    189  1.16        pk 	union obio_attach_args *uoba = aux;
    190  1.16        pk 	struct obio4_attach_args *oba;
    191   1.1   thorpej 
    192  1.16        pk 	if (uoba->uoba_isobio4 == 0)
    193   1.1   thorpej 		return (0);
    194   1.1   thorpej 
    195  1.16        pk 	oba = &uoba->uoba_oba4;
    196  1.26        pk 	return (bus_space_probe(oba->oba_bustag, oba->oba_paddr,
    197  1.17        pk 				4,	/* probe size */
    198  1.17        pk 				0,	/* offset */
    199  1.17        pk 				0,	/* flags */
    200  1.17        pk 				cg8_pfour_probe, NULL));
    201  1.16        pk }
    202   1.1   thorpej 
    203  1.41       uwe static int
    204  1.41       uwe cg8_pfour_probe(void *vaddr, void *arg)
    205  1.16        pk {
    206   1.1   thorpej 
    207  1.16        pk 	return (fb_pfour_id(vaddr) == PFOUR_ID_COLOR24);
    208   1.1   thorpej }
    209   1.1   thorpej 
    210   1.1   thorpej /*
    211   1.1   thorpej  * Attach a display.  We need to notice if it is the console, too.
    212   1.1   thorpej  */
    213  1.41       uwe static void
    214  1.47       mrg cgeightattach(device_t parent, device_t self, void *aux)
    215   1.1   thorpej {
    216   1.6        pk #if defined(SUN4)
    217  1.16        pk 	union obio_attach_args *uoba = aux;
    218  1.16        pk 	struct obio4_attach_args *oba = &uoba->uoba_oba4;
    219  1.46  drochner 	struct cgeight_softc *sc = device_private(self);
    220   1.4  christos 	struct fbdevice *fb = &sc->sc_fb;
    221  1.16        pk 	bus_space_handle_t bh;
    222  1.16        pk 	volatile struct bt_regs *bt;
    223  1.16        pk 	int ramsize, i, isconsole;
    224  1.16        pk 
    225  1.16        pk 	sc->sc_bustag = oba->oba_bustag;
    226  1.16        pk 	sc->sc_paddr = (bus_addr_t)oba->oba_paddr;
    227  1.16        pk 
    228  1.16        pk 	/* Map the pfour register. */
    229  1.26        pk 	if (bus_space_map(oba->oba_bustag, oba->oba_paddr,
    230  1.41       uwe 			  sizeof(uint32_t),
    231  1.26        pk 			  BUS_SPACE_MAP_LINEAR,
    232  1.26        pk 			  &bh) != 0) {
    233  1.47       mrg 		printf("%s: cannot map pfour register\n",
    234  1.47       mrg 			device_xname(self));
    235  1.16        pk 		return;
    236  1.16        pk 	}
    237  1.41       uwe 	fb->fb_pfour = (volatile uint32_t *)bh;
    238   1.1   thorpej 
    239   1.1   thorpej 	fb->fb_driver = &cgeightfbdriver;
    240  1.47       mrg 	fb->fb_device = self;
    241   1.1   thorpej 	fb->fb_type.fb_type = FBTYPE_MEMCOLOR;
    242  1.47       mrg 	fb->fb_flags = device_cfdata(self)->cf_flags & FB_USERMASK;
    243  1.16        pk 	fb->fb_flags |= FB_PFOUR;
    244   1.1   thorpej 
    245   1.1   thorpej 	ramsize = PFOUR_COLOR_OFF_END - PFOUR_COLOR_OFF_OVERLAY;
    246   1.1   thorpej 
    247   1.1   thorpej 	fb->fb_type.fb_depth = 24;
    248  1.16        pk 	fb_setsize_eeprom(fb, fb->fb_type.fb_depth, 1152, 900);
    249   1.1   thorpej 
    250   1.1   thorpej 	sc->sc_fb.fb_type.fb_cmsize = 256;
    251   1.1   thorpej 	sc->sc_fb.fb_type.fb_size = ramsize;
    252  1.16        pk 	printf(": cgeight/p4, %d x %d",
    253  1.16        pk 		fb->fb_type.fb_width,
    254  1.16        pk 		fb->fb_type.fb_height);
    255   1.1   thorpej 
    256   1.1   thorpej 	isconsole = 0;
    257   1.1   thorpej 
    258  1.16        pk 	if (CPU_ISSUN4) {
    259   1.1   thorpej 		struct eeprom *eep = (struct eeprom *)eeprom_va;
    260   1.1   thorpej 
    261   1.1   thorpej 		/*
    262   1.1   thorpej 		 * Assume this is the console if there's no eeprom info
    263   1.1   thorpej 		 * to be found.
    264   1.1   thorpej 		 */
    265   1.1   thorpej 		if (eep == NULL || eep->eeConsole == EE_CONS_P4OPT)
    266  1.20        pk 			isconsole = fb_is_console(0);
    267   1.1   thorpej 	}
    268   1.1   thorpej 
    269   1.1   thorpej #if 0
    270   1.1   thorpej 	/*
    271   1.1   thorpej 	 * We don't do any of the console handling here.  Instead,
    272   1.1   thorpej 	 * we let the bwtwo driver pick up the overlay plane and
    273   1.1   thorpej 	 * use it instead.  Rconsole should have better performance
    274   1.1   thorpej 	 * with the 1-bit depth.
    275  1.39    keihan 	 *      -- Jason R. Thorpe <thorpej (at) NetBSD.org>
    276   1.1   thorpej 	 */
    277   1.1   thorpej 
    278   1.1   thorpej 	/*
    279   1.1   thorpej 	 * When the ROM has mapped in a cgfour display, the address
    280   1.1   thorpej 	 * maps only the video RAM, so in any case we have to map the
    281   1.1   thorpej 	 * registers ourselves.  We only need the video RAM if we are
    282   1.1   thorpej 	 * going to print characters via rconsole.
    283   1.1   thorpej 	 */
    284   1.1   thorpej 
    285   1.1   thorpej 	if (isconsole) {
    286   1.1   thorpej 		/* XXX this is kind of a waste */
    287   1.1   thorpej 		fb->fb_pixels = mapiodev(ca->ca_ra.ra_reg,
    288  1.13        pk 					 PFOUR_COLOR_OFF_OVERLAY, ramsize);
    289   1.1   thorpej 	}
    290   1.1   thorpej #endif
    291   1.1   thorpej 
    292   1.1   thorpej 	/* Map the Brooktree. */
    293  1.26        pk 	if (bus_space_map(oba->oba_bustag,
    294  1.26        pk 			  oba->oba_paddr + PFOUR_COLOR_OFF_CMAP,
    295  1.26        pk 			  sizeof(struct fbcontrol),
    296  1.26        pk 			  BUS_SPACE_MAP_LINEAR,
    297  1.26        pk 			  &bh) != 0) {
    298  1.47       mrg 		printf("%s: cannot map control registers\n",
    299  1.47       mrg 			device_xname(self));
    300  1.16        pk 		return;
    301  1.16        pk 	}
    302  1.16        pk 	sc->sc_fbc = (volatile struct fbcontrol *)bh;
    303   1.1   thorpej 
    304   1.1   thorpej #if 0	/* XXX thorpej ??? */
    305   1.1   thorpej 	/* tell the enable plane to look at the mono image */
    306   1.1   thorpej 	memset(ca->ca_ra.ra_vaddr, 0xff,
    307   1.1   thorpej 	    sc->sc_fb.fb_type.fb_width * sc->sc_fb.fb_type.fb_height / 8);
    308   1.1   thorpej #endif
    309   1.1   thorpej 
    310   1.1   thorpej 	/* grab initial (current) color map */
    311   1.1   thorpej 	bt = &sc->sc_fbc->fbc_dac;
    312   1.1   thorpej 	bt->bt_addr = 0;
    313   1.1   thorpej 	for (i = 0; i < 256 * 3 / 4; i++)
    314   1.1   thorpej 		sc->sc_cmap.cm_chip[i] = bt->bt_cmap;
    315   1.1   thorpej 
    316   1.1   thorpej 	BT_INIT(bt, 0);
    317   1.1   thorpej 
    318   1.1   thorpej #if 0	/* see above */
    319   1.1   thorpej 	if (isconsole) {
    320  1.11  christos 		printf(" (console)\n");
    321   1.1   thorpej #if defined(RASTERCONSOLE) && 0	/* XXX been told it doesn't work well. */
    322   1.1   thorpej 		fbrcons_init(fb);
    323   1.1   thorpej #endif
    324   1.1   thorpej 	} else
    325   1.1   thorpej #endif /* 0 */
    326  1.11  christos 		printf("\n");
    327   1.1   thorpej 
    328   1.1   thorpej 	/*
    329   1.1   thorpej 	 * Even though we're not using rconsole, we'd still like
    330   1.1   thorpej 	 * to notice if we're the console framebuffer.
    331   1.1   thorpej 	 */
    332   1.1   thorpej 	fb_attach(&sc->sc_fb, isconsole);
    333   1.6        pk #endif
    334   1.1   thorpej }
    335   1.1   thorpej 
    336   1.1   thorpej int
    337  1.42  christos cgeightopen(dev_t dev, int flags, int mode, struct lwp *l)
    338   1.1   thorpej {
    339   1.1   thorpej 	int unit = minor(dev);
    340   1.1   thorpej 
    341  1.46  drochner 	if (device_lookup(&cgeight_cd, unit) == NULL)
    342   1.1   thorpej 		return (ENXIO);
    343   1.1   thorpej 	return (0);
    344   1.1   thorpej }
    345   1.1   thorpej 
    346   1.1   thorpej int
    347  1.44  christos cgeightioctl(dev_t dev, u_long cmd, void *data, int flags, struct lwp *l)
    348   1.1   thorpej {
    349   1.6        pk #if defined(SUN4)
    350  1.46  drochner 	struct cgeight_softc *sc = device_lookup_private(&cgeight_cd,
    351  1.46  drochner 							 minor(dev));
    352  1.18        pk 	struct fbgattr *fba;
    353   1.1   thorpej 	int error;
    354   1.1   thorpej 
    355   1.1   thorpej 	switch (cmd) {
    356   1.1   thorpej 
    357   1.1   thorpej 	case FBIOGTYPE:
    358   1.1   thorpej 		*(struct fbtype *)data = sc->sc_fb.fb_type;
    359   1.1   thorpej 		break;
    360   1.1   thorpej 
    361   1.1   thorpej 	case FBIOGATTR:
    362   1.1   thorpej 		fba = (struct fbgattr *)data;
    363   1.1   thorpej 		fba->real_type = sc->sc_fb.fb_type.fb_type;
    364   1.1   thorpej 		fba->owner = 0;		/* XXX ??? */
    365   1.1   thorpej 		fba->fbtype = sc->sc_fb.fb_type;
    366   1.1   thorpej 		fba->sattr.flags = 0;
    367   1.1   thorpej 		fba->sattr.emu_type = sc->sc_fb.fb_type.fb_type;
    368   1.1   thorpej 		fba->sattr.dev_specific[0] = -1;
    369   1.1   thorpej 		fba->emu_types[0] = sc->sc_fb.fb_type.fb_type;
    370   1.1   thorpej 		fba->emu_types[1] = -1;
    371   1.1   thorpej 		break;
    372   1.1   thorpej 
    373   1.1   thorpej 	case FBIOGETCMAP:
    374  1.21        pk #define p ((struct fbcmap *)data)
    375  1.21        pk 		return (bt_getcmap(p, &sc->sc_cmap, 256, 1));
    376   1.1   thorpej 
    377   1.1   thorpej 	case FBIOPUTCMAP:
    378   1.1   thorpej 		/* copy to software map */
    379  1.21        pk 		error = bt_putcmap(p, &sc->sc_cmap, 256, 1);
    380   1.1   thorpej 		if (error)
    381   1.1   thorpej 			return (error);
    382   1.1   thorpej 		/* now blast them into the chip */
    383   1.1   thorpej 		/* XXX should use retrace interrupt */
    384   1.1   thorpej 		cgeightloadcmap(sc, p->index, p->count);
    385   1.1   thorpej #undef p
    386   1.1   thorpej 		break;
    387   1.1   thorpej 
    388   1.1   thorpej 	case FBIOGVIDEO:
    389   1.1   thorpej 		*(int *)data = cgeight_get_video(sc);
    390   1.1   thorpej 		break;
    391   1.1   thorpej 
    392   1.1   thorpej 	case FBIOSVIDEO:
    393   1.1   thorpej 		cgeight_set_video(sc, *(int *)data);
    394   1.1   thorpej 		break;
    395   1.1   thorpej 
    396   1.1   thorpej 	default:
    397   1.1   thorpej 		return (ENOTTY);
    398   1.1   thorpej 	}
    399  1.41       uwe #endif /* SUN4 */
    400  1.41       uwe 
    401   1.1   thorpej 	return (0);
    402   1.1   thorpej }
    403   1.1   thorpej 
    404   1.1   thorpej /*
    405   1.1   thorpej  * Return the address that would map the given device at the given
    406   1.1   thorpej  * offset, allowing for the given protection, or return -1 for error.
    407   1.1   thorpej  *
    408  1.50       snj  * The cg8 maps its overlay plane at 0 for 128K, followed by the
    409   1.1   thorpej  * enable plane for 128K, followed by the colour for as long as it
    410  1.32   thorpej  * goes. Starting at 8MB, it maps the ramdac for PAGE_SIZE, then the p4
    411  1.32   thorpej  * register for PAGE_SIZE, then the bootrom for 0x40000.
    412   1.1   thorpej  */
    413  1.22    simonb paddr_t
    414  1.41       uwe cgeightmmap(dev_t dev, off_t off, int prot)
    415   1.1   thorpej {
    416  1.46  drochner 	struct cgeight_softc *sc = device_lookup_private(&cgeight_cd,
    417  1.46  drochner 							 minor(dev));
    418  1.22    simonb 	off_t poff;
    419   1.1   thorpej 
    420   1.1   thorpej #define START_ENABLE	(128*1024)
    421   1.1   thorpej #define START_COLOR	((128*1024) + (128*1024))
    422   1.1   thorpej #define COLOR_SIZE	(sc->sc_fb.fb_type.fb_width * \
    423   1.1   thorpej 			    sc->sc_fb.fb_type.fb_height * 3)
    424   1.1   thorpej #define END_COLOR	(START_COLOR + COLOR_SIZE)
    425   1.1   thorpej #define START_SPECIAL	0x800000
    426   1.1   thorpej #define PROMSIZE	0x40000
    427   1.1   thorpej #define NOOVERLAY	(0x04000000)
    428   1.1   thorpej 
    429   1.1   thorpej 	if (off & PGOFSET)
    430   1.1   thorpej 		panic("cgeightmap");
    431   1.1   thorpej 
    432  1.19       mrg 	if (off < 0)
    433  1.19       mrg 		return (-1);
    434  1.19       mrg 	else if ((u_int)off >= NOOVERLAY) {
    435   1.8   thorpej 		off -= NOOVERLAY;
    436   1.1   thorpej 
    437   1.1   thorpej 		/*
    438   1.1   thorpej 		 * X11 maps a huge chunk of the frame buffer; far more than
    439   1.1   thorpej 		 * there really is. We compensate by double-mapping the
    440   1.1   thorpej 		 * first page for as many other pages as it wants
    441   1.1   thorpej 		 */
    442  1.19       mrg 		while ((u_int)off >= COLOR_SIZE)
    443   1.1   thorpej 			off -= COLOR_SIZE;	/* XXX thorpej ??? */
    444   1.1   thorpej 
    445   1.1   thorpej 		poff = off + PFOUR_COLOR_OFF_COLOR;
    446   1.1   thorpej 	} else if ((u_int)off < START_ENABLE) {
    447   1.1   thorpej 		/*
    448   1.1   thorpej 		 * in overlay plane
    449   1.1   thorpej 		 */
    450   1.1   thorpej 		poff = PFOUR_COLOR_OFF_OVERLAY + off;
    451   1.1   thorpej 	} else if ((u_int)off < START_COLOR) {
    452   1.1   thorpej 		/*
    453   1.1   thorpej 		 * in enable plane
    454   1.1   thorpej 		 */
    455   1.1   thorpej 		poff = (off - START_ENABLE) + PFOUR_COLOR_OFF_ENABLE;
    456   1.8   thorpej 	} else if ((u_int)off < sc->sc_fb.fb_type.fb_size) {
    457   1.1   thorpej 		/*
    458   1.1   thorpej 		 * in colour plane
    459   1.6        pk 		 */
    460   1.1   thorpej 		poff = (off - START_COLOR) + PFOUR_COLOR_OFF_COLOR;
    461   1.1   thorpej 	} else if ((u_int)off < START_SPECIAL) {
    462   1.1   thorpej 		/*
    463   1.1   thorpej 		 * hole
    464   1.1   thorpej 		 */
    465   1.1   thorpej 		poff = 0;	/* XXX */
    466   1.1   thorpej 	} else if ((u_int)off == START_SPECIAL) {
    467   1.1   thorpej 		/*
    468   1.1   thorpej 		 * colour map (Brooktree)
    469   1.1   thorpej 		 */
    470   1.1   thorpej 		poff = PFOUR_COLOR_OFF_CMAP;
    471  1.32   thorpej 	} else if ((u_int)off == START_SPECIAL + PAGE_SIZE) {
    472   1.1   thorpej 		/*
    473   1.1   thorpej 		 * p4 register
    474   1.1   thorpej 		 */
    475   1.1   thorpej 		poff = 0;
    476  1.32   thorpej 	} else if ((u_int)off > (START_SPECIAL + (PAGE_SIZE * 2)) &&
    477  1.32   thorpej 	    (u_int) off < (START_SPECIAL + (PAGE_SIZE * 2) + PROMSIZE)) {
    478   1.1   thorpej 		/*
    479   1.1   thorpej 		 * rom
    480   1.1   thorpej 		 */
    481  1.32   thorpej 		poff = 0x8000 + (off - (START_SPECIAL + (PAGE_SIZE * 2)));
    482   1.1   thorpej 	} else
    483   1.1   thorpej 		return (-1);
    484  1.16        pk 
    485  1.25       eeh 	return (bus_space_mmap(sc->sc_bustag,
    486  1.25       eeh 		sc->sc_paddr, poff,
    487  1.25       eeh 		prot, BUS_SPACE_MAP_LINEAR));
    488   1.1   thorpej }
    489   1.1   thorpej 
    490   1.6        pk #if defined(SUN4)
    491   1.6        pk /*
    492   1.6        pk  * Undo the effect of an FBIOSVIDEO that turns the video off.
    493   1.6        pk  */
    494   1.6        pk static void
    495  1.47       mrg cgeightunblank(device_t dev)
    496   1.6        pk {
    497   1.6        pk 
    498  1.46  drochner 	cgeight_set_video(device_private(dev), 1);
    499   1.6        pk }
    500   1.6        pk 
    501   1.1   thorpej static int
    502  1.41       uwe cgeight_get_video(struct cgeight_softc *sc)
    503   1.1   thorpej {
    504   1.1   thorpej 
    505   1.1   thorpej 	return (fb_pfour_get_video(&sc->sc_fb));
    506   1.1   thorpej }
    507   1.1   thorpej 
    508   1.1   thorpej static void
    509  1.41       uwe cgeight_set_video(struct cgeight_softc *sc, int enable)
    510   1.1   thorpej {
    511   1.1   thorpej 
    512   1.1   thorpej 	fb_pfour_set_video(&sc->sc_fb, enable);
    513   1.1   thorpej }
    514   1.6        pk 
    515   1.6        pk /*
    516   1.6        pk  * Load a subset of the current (new) colormap into the Brooktree DAC.
    517   1.6        pk  */
    518   1.6        pk static void
    519  1.41       uwe cgeightloadcmap(struct cgeight_softc *sc, int start, int ncolors)
    520   1.6        pk {
    521  1.18        pk 	volatile struct bt_regs *bt;
    522  1.18        pk 	u_int *ip;
    523  1.18        pk 	int count;
    524   1.6        pk 
    525   1.6        pk 	ip = &sc->sc_cmap.cm_chip[BT_D4M3(start)];	/* start/4 * 3 */
    526   1.6        pk 	count = BT_D4M3(start + ncolors - 1) - BT_D4M3(start) + 3;
    527   1.6        pk 	bt = &sc->sc_fbc->fbc_dac;
    528   1.6        pk 	bt->bt_addr = BT_D4M4(start);
    529   1.6        pk 	while (--count >= 0)
    530   1.6        pk 		bt->bt_cmap = *ip++;
    531   1.6        pk }
    532  1.41       uwe #endif /* SUN4 */
    533