Home | History | Annotate | Line # | Download | only in dev
cgfour.c revision 1.14
      1  1.14   thorpej /*	$NetBSD: cgfour.c,v 1.14 1997/10/05 18:24:33 thorpej 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  * 3. All advertising materials mentioning features or use of this software
     19  1.14   thorpej  *    must display the following acknowledgement:
     20  1.14   thorpej  *	This product includes software developed by the NetBSD
     21  1.14   thorpej  *	Foundation, Inc. and its contributors.
     22  1.14   thorpej  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23  1.14   thorpej  *    contributors may be used to endorse or promote products derived
     24  1.14   thorpej  *    from this software without specific prior written permission.
     25  1.14   thorpej  *
     26  1.14   thorpej  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27  1.14   thorpej  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28  1.14   thorpej  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29  1.14   thorpej  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30  1.14   thorpej  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31  1.14   thorpej  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32  1.14   thorpej  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33  1.14   thorpej  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34  1.14   thorpej  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35  1.14   thorpej  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36  1.14   thorpej  * POSSIBILITY OF SUCH DAMAGE.
     37  1.14   thorpej  */
     38   1.1   thorpej 
     39   1.1   thorpej /*
     40   1.1   thorpej  * Copyright (c) 1995 Theo de Raadt.  All rights reserved.
     41   1.1   thorpej  * Copyright (c) 1992, 1993
     42   1.1   thorpej  *	The Regents of the University of California.  All rights reserved.
     43   1.1   thorpej  *
     44   1.1   thorpej  * All advertising materials mentioning features or use of this software
     45   1.1   thorpej  * must display the following acknowledgement:
     46   1.1   thorpej  *	This product includes software developed by Theo de Raadt.
     47   1.1   thorpej  *
     48   1.1   thorpej  * This software was developed by the Computer Systems Engineering group
     49   1.1   thorpej  * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
     50   1.1   thorpej  * contributed to Berkeley.
     51   1.1   thorpej  *
     52   1.1   thorpej  * All advertising materials mentioning features or use of this software
     53   1.1   thorpej  * must display the following acknowledgement:
     54   1.1   thorpej  *	This product includes software developed by the University of
     55   1.1   thorpej  *	California, Lawrence Berkeley Laboratory.
     56   1.1   thorpej  *
     57   1.1   thorpej  * Redistribution and use in source and binary forms, with or without
     58   1.1   thorpej  * modification, are permitted provided that the following conditions
     59   1.1   thorpej  * are met:
     60   1.1   thorpej  * 1. Redistributions of source code must retain the above copyright
     61   1.1   thorpej  *    notice, this list of conditions and the following disclaimer.
     62   1.1   thorpej  * 2. Redistributions in binary form must reproduce the above copyright
     63   1.1   thorpej  *    notice, this list of conditions and the following disclaimer in the
     64   1.1   thorpej  *    documentation and/or other materials provided with the distribution.
     65   1.1   thorpej  * 3. All advertising materials mentioning features or use of this software
     66   1.1   thorpej  *    must display the following acknowledgement:
     67   1.1   thorpej  *	This product includes software developed by the University of
     68   1.1   thorpej  *	California, Berkeley and its contributors.
     69   1.1   thorpej  * 4. Neither the name of the University nor the names of its contributors
     70   1.1   thorpej  *    may be used to endorse or promote products derived from this software
     71   1.1   thorpej  *    without specific prior written permission.
     72   1.1   thorpej  *
     73   1.1   thorpej  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     74   1.1   thorpej  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     75   1.1   thorpej  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     76   1.1   thorpej  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     77   1.1   thorpej  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     78   1.1   thorpej  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     79   1.1   thorpej  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     80   1.1   thorpej  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     81   1.1   thorpej  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     82   1.1   thorpej  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     83   1.1   thorpej  * SUCH DAMAGE.
     84   1.1   thorpej  *
     85   1.1   thorpej  *	from @(#)cgthree.c	8.2 (Berkeley) 10/30/93
     86   1.1   thorpej  */
     87   1.1   thorpej 
     88   1.1   thorpej /*
     89   1.1   thorpej  * color display (cgfour) driver.
     90   1.1   thorpej  *
     91   1.1   thorpej  * Does not handle interrupts, even though they can occur.
     92   1.1   thorpej  *
     93   1.1   thorpej  * XXX should defer colormap updates to vertical retrace interrupts
     94   1.1   thorpej  */
     95   1.1   thorpej 
     96   1.1   thorpej #include <sys/param.h>
     97   1.4  christos #include <sys/systm.h>
     98   1.1   thorpej #include <sys/buf.h>
     99   1.1   thorpej #include <sys/device.h>
    100   1.1   thorpej #include <sys/ioctl.h>
    101   1.1   thorpej #include <sys/malloc.h>
    102   1.1   thorpej #include <sys/mman.h>
    103   1.1   thorpej #include <sys/tty.h>
    104   1.7  christos #include <sys/conf.h>
    105   1.1   thorpej 
    106   1.1   thorpej #include <vm/vm.h>
    107   1.1   thorpej 
    108   1.1   thorpej #include <machine/fbio.h>
    109   1.1   thorpej #include <machine/autoconf.h>
    110   1.1   thorpej #include <machine/pmap.h>
    111   1.1   thorpej #include <machine/fbvar.h>
    112   1.1   thorpej #include <machine/eeprom.h>
    113   1.7  christos #include <machine/conf.h>
    114   1.1   thorpej 
    115   1.1   thorpej #include <sparc/dev/btreg.h>
    116   1.1   thorpej #include <sparc/dev/btvar.h>
    117   1.1   thorpej #include <sparc/dev/pfourreg.h>
    118   1.1   thorpej 
    119   1.1   thorpej /* per-display variables */
    120   1.1   thorpej struct cgfour_softc {
    121   1.1   thorpej 	struct	device sc_dev;		/* base device */
    122   1.1   thorpej 	struct	fbdevice sc_fb;		/* frame buffer device */
    123   1.1   thorpej 	struct rom_reg	sc_phys;	/* display RAM (phys addr) */
    124   1.1   thorpej 	volatile struct fbcontrol *sc_fbc;	/* Brooktree registers */
    125   1.1   thorpej 	int	sc_bustype;		/* type of bus we live on */
    126   1.1   thorpej 	union	bt_cmap sc_cmap;	/* Brooktree color map */
    127   1.1   thorpej };
    128   1.1   thorpej 
    129   1.1   thorpej /* autoconfiguration driver */
    130   1.1   thorpej static void	cgfourattach __P((struct device *, struct device *, void *));
    131  1.12        pk static int	cgfourmatch __P((struct device *, struct cfdata *, void *));
    132   1.6        pk #if defined(SUN4)
    133   1.1   thorpej static void	cgfourunblank __P((struct device *));
    134   1.6        pk #endif
    135   1.1   thorpej 
    136   1.9   thorpej /* cdevsw prototypes */
    137   1.9   thorpej cdev_decl(cgfour);
    138   1.9   thorpej 
    139   1.5   thorpej struct cfattach cgfour_ca = {
    140   1.5   thorpej 	sizeof(struct cgfour_softc), cgfourmatch, cgfourattach
    141   1.5   thorpej };
    142   1.5   thorpej 
    143   1.5   thorpej struct cfdriver cgfour_cd = {
    144   1.5   thorpej 	NULL, "cgfour", DV_DULL
    145   1.1   thorpej };
    146   1.1   thorpej 
    147   1.6        pk #if defined(SUN4)
    148   1.1   thorpej /* frame buffer generic driver */
    149   1.1   thorpej static struct fbdriver cgfourfbdriver = {
    150   1.9   thorpej 	cgfourunblank, cgfouropen, cgfourclose, cgfourioctl, cgfourpoll,
    151   1.9   thorpej 	cgfourmmap
    152   1.1   thorpej };
    153   1.1   thorpej 
    154   1.1   thorpej extern int fbnode;
    155   1.1   thorpej extern struct tty *fbconstty;
    156   1.1   thorpej 
    157   1.1   thorpej static void cgfourloadcmap __P((struct cgfour_softc *, int, int));
    158   1.1   thorpej static int cgfour_get_video __P((struct cgfour_softc *));
    159   1.1   thorpej static void cgfour_set_video __P((struct cgfour_softc *, int));
    160   1.6        pk #endif
    161   1.1   thorpej 
    162   1.1   thorpej /*
    163   1.1   thorpej  * Match a cgfour.
    164   1.1   thorpej  */
    165   1.1   thorpej int
    166  1.12        pk cgfourmatch(parent, cf, aux)
    167   1.1   thorpej 	struct device *parent;
    168  1.12        pk 	struct cfdata *cf;
    169  1.12        pk 	void *aux;
    170   1.1   thorpej {
    171   1.1   thorpej 	struct confargs *ca = aux;
    172   1.1   thorpej 	struct romaux *ra = &ca->ca_ra;
    173   1.1   thorpej 
    174   1.1   thorpej 	if (strcmp(cf->cf_driver->cd_name, ra->ra_name))
    175   1.1   thorpej 		return (0);
    176   1.1   thorpej 
    177   1.1   thorpej 	/*
    178   1.1   thorpej 	 * Mask out invalid flags from the user.
    179   1.1   thorpej 	 */
    180   1.1   thorpej 	cf->cf_flags &= FB_USERMASK;
    181   1.1   thorpej 
    182   1.1   thorpej 	/*
    183   1.1   thorpej 	 * Only exists on a sun4.
    184   1.1   thorpej 	 */
    185   1.2   thorpej 	if (!CPU_ISSUN4)
    186   1.1   thorpej 		return (0);
    187   1.1   thorpej 
    188   1.1   thorpej 	/*
    189   1.1   thorpej 	 * Only exists on obio.
    190   1.1   thorpej 	 */
    191   1.1   thorpej 	if (ca->ca_bustype != BUS_OBIO)
    192   1.1   thorpej 		return (0);
    193   1.1   thorpej 
    194   1.1   thorpej 	/*
    195   1.1   thorpej 	 * Make sure there's hardware there.
    196   1.1   thorpej 	 */
    197   1.1   thorpej 	if (probeget(ra->ra_vaddr, 4) == -1)
    198   1.1   thorpej 		return (0);
    199   1.1   thorpej 
    200   1.1   thorpej #if defined(SUN4)
    201   1.1   thorpej 	/*
    202   1.1   thorpej 	 * Check the pfour register.
    203   1.1   thorpej 	 */
    204   1.1   thorpej 	if (fb_pfour_id(ra->ra_vaddr) == PFOUR_ID_COLOR8P1) {
    205   1.1   thorpej 		cf->cf_flags |= FB_PFOUR;
    206   1.1   thorpej 		return (1);
    207   1.1   thorpej 	}
    208   1.1   thorpej #endif
    209   1.1   thorpej 
    210   1.1   thorpej 	return (0);
    211   1.1   thorpej }
    212   1.1   thorpej 
    213   1.1   thorpej /*
    214   1.1   thorpej  * Attach a display.  We need to notice if it is the console, too.
    215   1.1   thorpej  */
    216   1.1   thorpej void
    217   1.1   thorpej cgfourattach(parent, self, args)
    218   1.1   thorpej 	struct device *parent, *self;
    219   1.1   thorpej 	void *args;
    220   1.1   thorpej {
    221   1.6        pk #if defined(SUN4)
    222   1.1   thorpej 	register struct cgfour_softc *sc = (struct cgfour_softc *)self;
    223   1.1   thorpej 	register struct confargs *ca = args;
    224   1.1   thorpej 	register int node = 0, ramsize, i;
    225   1.1   thorpej 	register volatile struct bt_regs *bt;
    226   1.1   thorpej 	struct fbdevice *fb = &sc->sc_fb;
    227   1.1   thorpej 	int isconsole;
    228   1.1   thorpej 
    229   1.1   thorpej 	fb->fb_driver = &cgfourfbdriver;
    230   1.1   thorpej 	fb->fb_device = &sc->sc_dev;
    231   1.1   thorpej 	fb->fb_type.fb_type = FBTYPE_SUN4COLOR;
    232   1.1   thorpej 	fb->fb_flags = sc->sc_dev.dv_cfdata->cf_flags;
    233   1.1   thorpej 
    234   1.1   thorpej 	/*
    235   1.1   thorpej 	 * Only pfour cgfours, thank you...
    236   1.1   thorpej 	 */
    237   1.1   thorpej 	if ((ca->ca_bustype != BUS_OBIO) ||
    238   1.1   thorpej 	    ((fb->fb_flags & FB_PFOUR) == 0)) {
    239  1.11  christos 		printf("%s: ignoring; not a pfour\n", sc->sc_dev.dv_xname);
    240   1.1   thorpej 		return;
    241   1.1   thorpej 	}
    242   1.1   thorpej 
    243   1.1   thorpej 	/* Map the pfour register. */
    244  1.13        pk 	fb->fb_pfour = (volatile u_int32_t *)
    245  1.13        pk 		mapiodev(ca->ca_ra.ra_reg, 0, sizeof(u_int32_t));
    246   1.1   thorpej 
    247   1.1   thorpej 	ramsize = PFOUR_COLOR_OFF_END - PFOUR_COLOR_OFF_OVERLAY;
    248   1.1   thorpej 
    249   1.1   thorpej 	fb->fb_type.fb_depth = 8;
    250   1.1   thorpej 	fb_setsize(fb, fb->fb_type.fb_depth, 1152, 900, node, ca->ca_bustype);
    251   1.1   thorpej 
    252   1.1   thorpej 	fb->fb_type.fb_cmsize = 256;
    253   1.1   thorpej 	fb->fb_type.fb_size = ramsize;
    254  1.11  christos 	printf(": cgfour/p4, %d x %d", fb->fb_type.fb_width,
    255   1.1   thorpej 	    fb->fb_type.fb_height);
    256   1.1   thorpej 
    257   1.1   thorpej 	isconsole = 0;
    258   1.1   thorpej 
    259   1.6        pk 	if (CPU_ISSUN4) {
    260   1.1   thorpej 		struct eeprom *eep = (struct eeprom *)eeprom_va;
    261   1.1   thorpej 
    262   1.1   thorpej 		/*
    263   1.1   thorpej 		 * Assume this is the console if there's no eeprom info
    264   1.1   thorpej 		 * to be found.
    265   1.1   thorpej 		 */
    266   1.1   thorpej 		if (eep == NULL || eep->eeConsole == EE_CONS_P4OPT)
    267   1.6        pk 			isconsole = (fbconstty != NULL);
    268   1.1   thorpej 	}
    269   1.1   thorpej 
    270   1.1   thorpej #if 0
    271   1.1   thorpej 	/*
    272   1.1   thorpej 	 * We don't do any of the console handling here.  Instead,
    273   1.1   thorpej 	 * we let the bwtwo driver pick up the overlay plane and
    274   1.1   thorpej 	 * use it instead.  Rconsole should have better performance
    275   1.1   thorpej 	 * with the 1-bit depth.
    276   1.1   thorpej 	 *	-- Jason R. Thorpe <thorpej (at) NetBSD.ORG>
    277   1.1   thorpej 	 */
    278   1.1   thorpej 
    279   1.1   thorpej 	/*
    280   1.1   thorpej 	 * When the ROM has mapped in a cgfour display, the address
    281   1.1   thorpej 	 * maps only the video RAM, so in any case we have to map the
    282   1.1   thorpej 	 * registers ourselves.  We only need the video RAM if we are
    283   1.1   thorpej 	 * going to print characters via rconsole.
    284   1.1   thorpej 	 */
    285   1.1   thorpej 
    286   1.1   thorpej 	if (isconsole) {
    287   1.1   thorpej 		/* XXX this is kind of a waste */
    288   1.1   thorpej 		fb->fb_pixels = mapiodev(ca->ca_ra.ra_reg,
    289  1.13        pk 					 PFOUR_COLOR_OFF_OVERLAY, ramsize);
    290   1.1   thorpej 	}
    291   1.1   thorpej #endif
    292   1.1   thorpej 
    293   1.1   thorpej 	/* Map the Brooktree. */
    294  1.13        pk 	sc->sc_fbc = (volatile struct fbcontrol *)
    295  1.13        pk 		mapiodev(ca->ca_ra.ra_reg,
    296  1.13        pk 			 PFOUR_COLOR_OFF_CMAP, sizeof(struct fbcontrol));
    297   1.1   thorpej 
    298   1.1   thorpej 	sc->sc_phys = ca->ca_ra.ra_reg[0];
    299   1.1   thorpej 	sc->sc_bustype = ca->ca_bustype;
    300   1.1   thorpej 
    301   1.1   thorpej 	/* grab initial (current) color map */
    302   1.1   thorpej 	bt = &sc->sc_fbc->fbc_dac;
    303   1.1   thorpej 	bt->bt_addr = 0;
    304   1.1   thorpej 	for (i = 0; i < 256 * 3 / 4; i++)
    305   1.1   thorpej 		((char *)&sc->sc_cmap)[i] = bt->bt_cmap >> 24;
    306   1.1   thorpej 
    307   1.1   thorpej 	BT_INIT(bt, 24);
    308   1.1   thorpej 
    309   1.1   thorpej #if 0	/* See above. */
    310   1.1   thorpej 	if (isconsole) {
    311  1.11  christos 		printf(" (console)\n");
    312   1.1   thorpej #if defined(RASTERCONSOLE) && 0	/* XXX been told it doesn't work well. */
    313   1.1   thorpej 		fbrcons_init(fb);
    314   1.1   thorpej #endif
    315   1.1   thorpej 	} else
    316   1.1   thorpej #endif /* 0 */
    317  1.11  christos 		printf("\n");
    318   1.1   thorpej 
    319   1.1   thorpej 	/*
    320   1.1   thorpej 	 * Even though we're not using rconsole, we'd still like
    321   1.1   thorpej 	 * to notice if we're the console framebuffer.
    322   1.1   thorpej 	 */
    323   1.1   thorpej 	fb_attach(fb, isconsole);
    324   1.6        pk #endif
    325   1.1   thorpej }
    326   1.1   thorpej 
    327   1.1   thorpej int
    328   1.1   thorpej cgfouropen(dev, flags, mode, p)
    329   1.1   thorpej 	dev_t dev;
    330   1.1   thorpej 	int flags, mode;
    331   1.1   thorpej 	struct proc *p;
    332   1.1   thorpej {
    333   1.1   thorpej 	int unit = minor(dev);
    334   1.1   thorpej 
    335   1.5   thorpej 	if (unit >= cgfour_cd.cd_ndevs || cgfour_cd.cd_devs[unit] == NULL)
    336   1.1   thorpej 		return (ENXIO);
    337   1.1   thorpej 	return (0);
    338   1.1   thorpej }
    339   1.1   thorpej 
    340   1.1   thorpej int
    341   1.1   thorpej cgfourclose(dev, flags, mode, p)
    342   1.1   thorpej 	dev_t dev;
    343   1.1   thorpej 	int flags, mode;
    344   1.1   thorpej 	struct proc *p;
    345   1.1   thorpej {
    346   1.1   thorpej 
    347   1.1   thorpej 	return (0);
    348   1.1   thorpej }
    349   1.1   thorpej 
    350   1.1   thorpej int
    351   1.1   thorpej cgfourioctl(dev, cmd, data, flags, p)
    352   1.1   thorpej 	dev_t dev;
    353   1.1   thorpej 	u_long cmd;
    354   1.1   thorpej 	register caddr_t data;
    355   1.1   thorpej 	int flags;
    356   1.1   thorpej 	struct proc *p;
    357   1.1   thorpej {
    358   1.6        pk #if defined(SUN4)
    359   1.5   thorpej 	register struct cgfour_softc *sc = cgfour_cd.cd_devs[minor(dev)];
    360   1.1   thorpej 	register struct fbgattr *fba;
    361   1.1   thorpej 	int error;
    362   1.1   thorpej 
    363   1.1   thorpej 	switch (cmd) {
    364   1.1   thorpej 
    365   1.1   thorpej 	case FBIOGTYPE:
    366   1.1   thorpej 		*(struct fbtype *)data = sc->sc_fb.fb_type;
    367   1.1   thorpej 		break;
    368   1.1   thorpej 
    369   1.1   thorpej 	case FBIOGATTR:
    370   1.1   thorpej 		fba = (struct fbgattr *)data;
    371   1.1   thorpej 		fba->real_type = sc->sc_fb.fb_type.fb_type;
    372   1.1   thorpej 		fba->owner = 0;		/* XXX ??? */
    373   1.1   thorpej 		fba->fbtype = sc->sc_fb.fb_type;
    374   1.1   thorpej 		fba->sattr.flags = 0;
    375   1.1   thorpej 		fba->sattr.emu_type = sc->sc_fb.fb_type.fb_type;
    376   1.1   thorpej 		fba->sattr.dev_specific[0] = -1;
    377   1.1   thorpej 		fba->emu_types[0] = sc->sc_fb.fb_type.fb_type;
    378   1.1   thorpej 		fba->emu_types[1] = -1;
    379   1.1   thorpej 		break;
    380   1.1   thorpej 
    381   1.1   thorpej 	case FBIOGETCMAP:
    382   1.1   thorpej 		return (bt_getcmap((struct fbcmap *)data, &sc->sc_cmap, 256));
    383   1.1   thorpej 
    384   1.1   thorpej 	case FBIOPUTCMAP:
    385   1.1   thorpej 		/* copy to software map */
    386   1.1   thorpej #define p ((struct fbcmap *)data)
    387   1.1   thorpej 		error = bt_putcmap(p, &sc->sc_cmap, 256);
    388   1.1   thorpej 		if (error)
    389   1.1   thorpej 			return (error);
    390   1.1   thorpej 		/* now blast them into the chip */
    391   1.1   thorpej 		/* XXX should use retrace interrupt */
    392   1.1   thorpej 		cgfourloadcmap(sc, p->index, p->count);
    393   1.1   thorpej #undef p
    394   1.1   thorpej 		break;
    395   1.1   thorpej 
    396   1.1   thorpej 	case FBIOGVIDEO:
    397   1.1   thorpej 		*(int *)data = cgfour_get_video(sc);
    398   1.1   thorpej 		break;
    399   1.1   thorpej 
    400   1.1   thorpej 	case FBIOSVIDEO:
    401   1.1   thorpej 		cgfour_set_video(sc, *(int *)data);
    402   1.1   thorpej 		break;
    403   1.1   thorpej 
    404   1.1   thorpej 	default:
    405   1.1   thorpej 		return (ENOTTY);
    406   1.1   thorpej 	}
    407   1.6        pk #endif
    408   1.1   thorpej 	return (0);
    409   1.9   thorpej }
    410   1.9   thorpej 
    411   1.9   thorpej int
    412   1.9   thorpej cgfourpoll(dev, events, p)
    413   1.9   thorpej 	dev_t dev;
    414   1.9   thorpej 	int events;
    415   1.9   thorpej 	struct proc *p;
    416   1.9   thorpej {
    417   1.9   thorpej 
    418   1.9   thorpej 	return (seltrue(dev, events, p));
    419   1.1   thorpej }
    420   1.1   thorpej 
    421   1.1   thorpej /*
    422   1.1   thorpej  * Return the address that would map the given device at the given
    423   1.1   thorpej  * offset, allowing for the given protection, or return -1 for error.
    424   1.1   thorpej  *
    425   1.1   thorpej  * the cg4 maps it's overlay plane for 128K, followed by the enable
    426   1.1   thorpej  * plane for 128K, followed by the colour plane (for as much colour
    427   1.1   thorpej  * as their is.)
    428   1.6        pk  *
    429   1.1   thorpej  * As well, mapping at an offset of 0x04000000 causes the cg4 to map
    430   1.1   thorpej  * only it's colour plane, at 0.
    431   1.1   thorpej  */
    432   1.1   thorpej int
    433   1.1   thorpej cgfourmmap(dev, off, prot)
    434   1.1   thorpej 	dev_t dev;
    435   1.1   thorpej 	int off, prot;
    436   1.1   thorpej {
    437   1.5   thorpej 	register struct cgfour_softc *sc = cgfour_cd.cd_devs[minor(dev)];
    438   1.1   thorpej 	int poff;
    439   1.1   thorpej 
    440   1.1   thorpej #define START_ENABLE	(128*1024)
    441   1.1   thorpej #define START_COLOR	((128*1024) + (128*1024))
    442   1.1   thorpej #define COLOR_SIZE	(sc->sc_fb.fb_type.fb_width * \
    443   1.1   thorpej 			    sc->sc_fb.fb_type.fb_height)
    444   1.1   thorpej #define END_COLOR	(START_COLOR + COLOR_SIZE)
    445   1.1   thorpej #define NOOVERLAY	(0x04000000)
    446   1.1   thorpej 
    447   1.1   thorpej 	if (off & PGOFSET)
    448   1.1   thorpej 		panic("cgfourmap");
    449   1.1   thorpej 
    450   1.1   thorpej 	if ((u_int)off >= NOOVERLAY) {
    451   1.8   thorpej 		off -= NOOVERLAY;
    452   1.1   thorpej 
    453   1.1   thorpej 		/*
    454   1.1   thorpej 		 * X11 maps a huge chunk of the frame buffer; far more than
    455   1.1   thorpej 		 * there really is. We compensate by double-mapping the
    456   1.1   thorpej 		 * first page for as many other pages as it wants
    457   1.1   thorpej 		 */
    458   1.1   thorpej 		while (off >= COLOR_SIZE)
    459   1.1   thorpej 			off -= COLOR_SIZE;	/* XXX thorpej ??? */
    460   1.1   thorpej 
    461   1.1   thorpej 		poff = off + PFOUR_COLOR_OFF_COLOR;
    462   1.1   thorpej 	} else if ((u_int)off < START_ENABLE) {
    463   1.1   thorpej 		/*
    464   1.1   thorpej 		 * in overlay plane
    465   1.1   thorpej 		 */
    466   1.1   thorpej 		poff = PFOUR_COLOR_OFF_OVERLAY + off;
    467   1.1   thorpej 	} else if ((u_int)off < START_COLOR) {
    468   1.1   thorpej 		/*
    469   1.1   thorpej 		 * in enable plane
    470   1.1   thorpej 		 */
    471   1.1   thorpej 		poff = (off - START_ENABLE) + PFOUR_COLOR_OFF_ENABLE;
    472   1.8   thorpej 	} else if ((u_int)off < sc->sc_fb.fb_type.fb_size) {
    473   1.1   thorpej 		/*
    474   1.1   thorpej 		 * in colour plane
    475   1.6        pk 		 */
    476   1.1   thorpej 		poff = (off - START_COLOR) + PFOUR_COLOR_OFF_COLOR;
    477   1.1   thorpej 	} else
    478   1.1   thorpej 		return (-1);
    479   1.1   thorpej 
    480  1.13        pk 	return (REG2PHYS(&sc->sc_phys, poff) | PMAP_NC);
    481   1.1   thorpej }
    482   1.1   thorpej 
    483   1.6        pk #if defined(SUN4)
    484   1.6        pk /*
    485   1.6        pk  * Undo the effect of an FBIOSVIDEO that turns the video off.
    486   1.6        pk  */
    487   1.6        pk static void
    488   1.6        pk cgfourunblank(dev)
    489   1.6        pk 	struct device *dev;
    490   1.6        pk {
    491   1.6        pk 
    492   1.6        pk 	cgfour_set_video((struct cgfour_softc *)dev, 1);
    493   1.6        pk }
    494   1.6        pk 
    495   1.1   thorpej static int
    496   1.1   thorpej cgfour_get_video(sc)
    497   1.1   thorpej 	struct cgfour_softc *sc;
    498   1.1   thorpej {
    499   1.1   thorpej 
    500   1.1   thorpej 	return (fb_pfour_get_video(&sc->sc_fb));
    501   1.1   thorpej }
    502   1.1   thorpej 
    503   1.1   thorpej static void
    504   1.1   thorpej cgfour_set_video(sc, enable)
    505   1.1   thorpej 	struct cgfour_softc *sc;
    506   1.1   thorpej 	int enable;
    507   1.1   thorpej {
    508   1.1   thorpej 
    509   1.1   thorpej 	fb_pfour_set_video(&sc->sc_fb, enable);
    510   1.1   thorpej }
    511   1.6        pk 
    512   1.6        pk /*
    513   1.6        pk  * Load a subset of the current (new) colormap into the Brooktree DAC.
    514   1.6        pk  */
    515   1.6        pk static void
    516   1.6        pk cgfourloadcmap(sc, start, ncolors)
    517   1.6        pk 	register struct cgfour_softc *sc;
    518   1.6        pk 	register int start, ncolors;
    519   1.6        pk {
    520   1.6        pk 	register volatile struct bt_regs *bt;
    521   1.6        pk 	register u_int *ip, i;
    522   1.6        pk 	register int count;
    523   1.6        pk 
    524   1.6        pk 	ip = &sc->sc_cmap.cm_chip[BT_D4M3(start)];	/* start/4 * 3 */
    525   1.6        pk 	count = BT_D4M3(start + ncolors - 1) - BT_D4M3(start) + 3;
    526   1.6        pk 	bt = &sc->sc_fbc->fbc_dac;
    527   1.6        pk 	bt->bt_addr = BT_D4M4(start) << 24;
    528   1.6        pk 	while (--count >= 0) {
    529   1.6        pk 		i = *ip++;
    530   1.6        pk 		/* hardware that makes one want to pound boards with hammers */
    531   1.6        pk 		bt->bt_cmap = i;
    532   1.6        pk 		bt->bt_cmap = i << 8;
    533   1.6        pk 		bt->bt_cmap = i << 16;
    534   1.6        pk 		bt->bt_cmap = i << 24;
    535   1.6        pk 	}
    536   1.6        pk }
    537   1.6        pk #endif
    538