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