Home | History | Annotate | Line # | Download | only in sun
cgthree.c revision 1.29.10.1
      1  1.29.10.1     rmind /*	$NetBSD: cgthree.c,v 1.29.10.1 2014/05/18 17:45:47 rmind Exp $ */
      2        1.1        pk 
      3        1.1        pk /*-
      4        1.1        pk  * Copyright (c) 1998 The NetBSD Foundation, Inc.
      5        1.1        pk  * All rights reserved.
      6        1.1        pk  *
      7        1.1        pk  * This code is derived from software contributed to The NetBSD Foundation
      8        1.1        pk  * by Paul Kranenburg.
      9        1.1        pk  *
     10        1.1        pk  * Redistribution and use in source and binary forms, with or without
     11        1.1        pk  * modification, are permitted provided that the following conditions
     12        1.1        pk  * are met:
     13        1.1        pk  * 1. Redistributions of source code must retain the above copyright
     14        1.1        pk  *    notice, this list of conditions and the following disclaimer.
     15        1.1        pk  * 2. Redistributions in binary form must reproduce the above copyright
     16        1.1        pk  *    notice, this list of conditions and the following disclaimer in the
     17        1.1        pk  *    documentation and/or other materials provided with the distribution.
     18        1.1        pk  *
     19        1.1        pk  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20        1.1        pk  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21        1.1        pk  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22        1.1        pk  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23        1.1        pk  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24        1.1        pk  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25        1.1        pk  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26        1.1        pk  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27        1.1        pk  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28        1.1        pk  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29        1.1        pk  * POSSIBILITY OF SUCH DAMAGE.
     30        1.1        pk  */
     31        1.1        pk 
     32        1.1        pk /*
     33        1.1        pk  * color display (cgthree) driver.
     34        1.1        pk  *
     35        1.1        pk  * Does not handle interrupts, even though they can occur.
     36        1.1        pk  *
     37        1.1        pk  * XXX should defer colormap updates to vertical retrace interrupts
     38        1.1        pk  */
     39        1.4     lukem 
     40        1.4     lukem #include <sys/cdefs.h>
     41  1.29.10.1     rmind __KERNEL_RCSID(0, "$NetBSD: cgthree.c,v 1.29.10.1 2014/05/18 17:45:47 rmind Exp $");
     42        1.1        pk 
     43        1.1        pk #include <sys/param.h>
     44        1.1        pk #include <sys/systm.h>
     45        1.1        pk #include <sys/buf.h>
     46        1.1        pk #include <sys/device.h>
     47        1.1        pk #include <sys/ioctl.h>
     48        1.1        pk #include <sys/malloc.h>
     49        1.1        pk #include <sys/mman.h>
     50        1.1        pk #include <sys/tty.h>
     51        1.1        pk #include <sys/conf.h>
     52        1.1        pk 
     53       1.14        ad #include <sys/bus.h>
     54        1.1        pk #include <machine/autoconf.h>
     55        1.1        pk 
     56        1.1        pk #include <dev/sun/fbio.h>
     57        1.1        pk #include <dev/sun/fbvar.h>
     58        1.1        pk 
     59       1.20       jdc #include <dev/sun/btreg.h>
     60       1.20       jdc #include <dev/sun/btvar.h>
     61       1.20       jdc #include <dev/sun/cgthreereg.h>
     62       1.20       jdc #include <dev/sun/cgthreevar.h>
     63       1.20       jdc 
     64       1.17       jdc #if NWSDISPLAY > 0
     65       1.17       jdc #include <dev/wscons/wsconsio.h>
     66       1.17       jdc #include <dev/wsfont/wsfont.h>
     67       1.17       jdc #include <dev/rasops/rasops.h>
     68       1.17       jdc 
     69       1.17       jdc #include "opt_wsemul.h"
     70       1.17       jdc #endif
     71       1.17       jdc 
     72       1.25   tsutsui #include "ioconf.h"
     73       1.25   tsutsui 
     74       1.23    cegger static void	cgthreeunblank(device_t);
     75        1.2        pk static void	cgthreeloadcmap(struct cgthree_softc *, int, int);
     76        1.2        pk static void	cgthree_set_video(struct cgthree_softc *, int);
     77        1.2        pk static int	cgthree_get_video(struct cgthree_softc *);
     78        1.2        pk 
     79        1.5   gehenna dev_type_open(cgthreeopen);
     80        1.5   gehenna dev_type_ioctl(cgthreeioctl);
     81        1.5   gehenna dev_type_mmap(cgthreemmap);
     82        1.5   gehenna 
     83        1.5   gehenna const struct cdevsw cgthree_cdevsw = {
     84  1.29.10.1     rmind 	.d_open = cgthreeopen,
     85  1.29.10.1     rmind 	.d_close = nullclose,
     86  1.29.10.1     rmind 	.d_read = noread,
     87  1.29.10.1     rmind 	.d_write = nowrite,
     88  1.29.10.1     rmind 	.d_ioctl = cgthreeioctl,
     89  1.29.10.1     rmind 	.d_stop = nostop,
     90  1.29.10.1     rmind 	.d_tty = notty,
     91  1.29.10.1     rmind 	.d_poll = nopoll,
     92  1.29.10.1     rmind 	.d_mmap = cgthreemmap,
     93  1.29.10.1     rmind 	.d_kqfilter = nokqfilter,
     94  1.29.10.1     rmind 	.d_flag = D_OTHER
     95        1.5   gehenna };
     96        1.1        pk 
     97        1.1        pk /* frame buffer generic driver */
     98        1.1        pk static struct fbdriver cgthreefbdriver = {
     99        1.5   gehenna 	cgthreeunblank, cgthreeopen, nullclose, cgthreeioctl, nopoll,
    100        1.6  jdolecek 	cgthreemmap, nokqfilter
    101        1.1        pk };
    102        1.1        pk 
    103        1.1        pk /* Video control parameters */
    104        1.1        pk struct cg3_videoctrl {
    105        1.1        pk 	unsigned char	sense;		/* Monitor sense value */
    106        1.1        pk 	unsigned char	vctrl[12];
    107        1.1        pk } cg3_videoctrl[] = {
    108        1.1        pk /* Missing entries: sense 0x10, 0x30, 0x50 */
    109        1.1        pk 	{ 0x40, /* this happens to be my 19'' 1152x900 gray-scale monitor */
    110        1.1        pk 	   {0xbb, 0x2b, 0x3, 0xb, 0xb3, 0x3, 0xaf, 0x2b, 0x2, 0xa, 0xff, 0x1}
    111        1.1        pk 	},
    112        1.1        pk 	{ 0x00, /* default? must be last */
    113        1.1        pk 	   {0xbb, 0x2b, 0x3, 0xb, 0xb3, 0x3, 0xaf, 0x2b, 0x2, 0xa, 0xff, 0x1}
    114        1.1        pk 	}
    115        1.1        pk };
    116        1.1        pk 
    117       1.17       jdc #if NWSDISPLAY > 0
    118       1.17       jdc #ifdef RASTERCONSOLE
    119       1.17       jdc #error RASTERCONSOLE and wsdisplay are mutually exclusive
    120       1.17       jdc #endif
    121       1.17       jdc 
    122       1.17       jdc static void cg3_setup_palette(struct cgthree_softc *);
    123       1.17       jdc 
    124       1.17       jdc struct wsscreen_descr cgthree_defaultscreen = {
    125       1.17       jdc 	"std",
    126       1.17       jdc 	0, 0,	/* will be filled in -- XXX shouldn't, it's global */
    127       1.17       jdc 	NULL,		/* textops */
    128       1.17       jdc 	8, 16,	/* font width/height */
    129       1.17       jdc 	WSSCREEN_WSCOLORS,	/* capabilities */
    130       1.17       jdc 	NULL	/* modecookie */
    131       1.17       jdc };
    132       1.17       jdc 
    133       1.17       jdc static int 	cgthree_ioctl(void *, void *, u_long, void *, int, struct lwp *);
    134       1.17       jdc static paddr_t	cgthree_mmap(void *, void *, off_t, int);
    135       1.17       jdc static void	cgthree_init_screen(void *, struct vcons_screen *, int, long *);
    136       1.17       jdc 
    137       1.17       jdc int	cgthree_putcmap(struct cgthree_softc *, struct wsdisplay_cmap *);
    138       1.17       jdc int	cgthree_getcmap(struct cgthree_softc *, struct wsdisplay_cmap *);
    139       1.17       jdc 
    140       1.17       jdc struct wsdisplay_accessops cgthree_accessops = {
    141       1.17       jdc 	cgthree_ioctl,
    142       1.17       jdc 	cgthree_mmap,
    143       1.17       jdc 	NULL,	/* alloc_screen */
    144       1.17       jdc 	NULL,	/* free_screen */
    145       1.17       jdc 	NULL,	/* show_screen */
    146       1.17       jdc 	NULL, 	/* load_font */
    147       1.17       jdc 	NULL,	/* pollc */
    148       1.17       jdc 	NULL	/* scroll */
    149       1.17       jdc };
    150       1.17       jdc 
    151       1.17       jdc const struct wsscreen_descr *_cgthree_scrlist[] = {
    152       1.17       jdc 	&cgthree_defaultscreen
    153       1.17       jdc };
    154       1.17       jdc 
    155       1.17       jdc struct wsscreen_list cgthree_screenlist = {
    156       1.17       jdc 	sizeof(_cgthree_scrlist) / sizeof(struct wsscreen_descr *),
    157       1.17       jdc 	_cgthree_scrlist
    158       1.17       jdc };
    159       1.17       jdc 
    160       1.17       jdc 
    161       1.17       jdc extern const u_char rasops_cmap[768];
    162       1.17       jdc 
    163       1.17       jdc static struct vcons_screen cg3_console_screen;
    164       1.17       jdc #endif /* NWSDISPLAY > 0 */
    165        1.1        pk 
    166        1.1        pk void
    167       1.21       dsl cgthreeattach(struct cgthree_softc *sc, const char *name, int isconsole)
    168        1.1        pk {
    169        1.1        pk 	int i;
    170        1.1        pk 	struct fbdevice *fb = &sc->sc_fb;
    171       1.17       jdc #if NWSDISPLAY > 0
    172       1.17       jdc 	struct wsemuldisplaydev_attach_args aa;
    173       1.17       jdc 	struct rasops_info *ri = &cg3_console_screen.scr_ri;
    174       1.17       jdc 	unsigned long defattr;
    175       1.17       jdc #endif
    176        1.1        pk 	volatile struct fbcontrol *fbc = sc->sc_fbc;
    177        1.1        pk 	volatile struct bt_regs *bt = &fbc->fbc_dac;
    178        1.1        pk 
    179        1.1        pk 	fb->fb_driver = &cgthreefbdriver;
    180        1.1        pk 	fb->fb_type.fb_cmsize = 256;
    181        1.1        pk 	fb->fb_type.fb_size = fb->fb_type.fb_height * fb->fb_linebytes;
    182        1.1        pk 	printf(": %s, %d x %d", name,
    183        1.1        pk 		fb->fb_type.fb_width, fb->fb_type.fb_height);
    184        1.1        pk 
    185        1.1        pk 	/* Transfer video magic to board, if it's not running */
    186        1.1        pk 	if ((fbc->fbc_ctrl & FBC_TIMING) == 0) {
    187        1.1        pk 		int sense = (fbc->fbc_status & FBS_MSENSE);
    188        1.1        pk 		/* Search table for video timings fitting this monitor */
    189        1.1        pk 		for (i = 0; i < sizeof(cg3_videoctrl)/sizeof(cg3_videoctrl[0]);
    190        1.1        pk 		     i++) {
    191        1.1        pk 			int j;
    192        1.1        pk 			if (sense != cg3_videoctrl[i].sense)
    193        1.1        pk 				continue;
    194        1.1        pk 
    195        1.1        pk 			printf(" setting video ctrl");
    196        1.1        pk 			for (j = 0; j < 12; j++)
    197        1.1        pk 				fbc->fbc_vcontrol[j] =
    198        1.1        pk 					cg3_videoctrl[i].vctrl[j];
    199        1.1        pk 			fbc->fbc_ctrl |= FBC_TIMING;
    200        1.1        pk 			break;
    201        1.1        pk 		}
    202        1.1        pk 	}
    203        1.1        pk 
    204        1.1        pk 	/* make sure we are not blanked */
    205        1.1        pk 	cgthree_set_video(sc, 1);
    206        1.1        pk 	BT_INIT(bt, 0);
    207        1.1        pk 
    208        1.1        pk 	if (isconsole) {
    209        1.1        pk 		printf(" (console)\n");
    210        1.1        pk #ifdef RASTERCONSOLE
    211        1.1        pk 		fbrcons_init(fb);
    212        1.1        pk #endif
    213        1.1        pk 	} else
    214        1.1        pk 		printf("\n");
    215        1.1        pk 
    216        1.1        pk 	fb_attach(fb, isconsole);
    217       1.17       jdc 
    218       1.17       jdc #if NWSDISPLAY > 0
    219       1.17       jdc 	sc->sc_width = fb->fb_type.fb_width;
    220       1.17       jdc 	sc->sc_stride = fb->fb_type.fb_width;
    221       1.17       jdc 	sc->sc_height = fb->fb_type.fb_height;
    222       1.17       jdc 
    223       1.17       jdc 	/* setup rasops and so on for wsdisplay */
    224       1.17       jdc 	sc->sc_mode = WSDISPLAYIO_MODE_EMUL;
    225       1.17       jdc 
    226       1.17       jdc 	vcons_init(&sc->vd, sc, &cgthree_defaultscreen, &cgthree_accessops);
    227       1.17       jdc 	sc->vd.init_screen = cgthree_init_screen;
    228       1.17       jdc 
    229       1.17       jdc 	if(isconsole) {
    230       1.17       jdc 		/* we mess with cg3_console_screen only once */
    231       1.17       jdc 		vcons_init_screen(&sc->vd, &cg3_console_screen, 1,
    232       1.17       jdc 		    &defattr);
    233       1.28  macallan 		memset(sc->sc_fb.fb_pixels, (defattr >> 16) & 0xff,
    234       1.28  macallan 		    sc->sc_stride * sc->sc_height);
    235       1.17       jdc 		cg3_console_screen.scr_flags |= VCONS_SCREEN_IS_STATIC;
    236       1.19       jdc 
    237       1.17       jdc 		cgthree_defaultscreen.textops = &ri->ri_ops;
    238       1.17       jdc 		cgthree_defaultscreen.capabilities = ri->ri_caps;
    239       1.17       jdc 		cgthree_defaultscreen.nrows = ri->ri_rows;
    240       1.17       jdc 		cgthree_defaultscreen.ncols = ri->ri_cols;
    241       1.17       jdc 		sc->vd.active = &cg3_console_screen;
    242       1.19       jdc 		wsdisplay_cnattach(&cgthree_defaultscreen, ri, 0, 0, defattr);
    243       1.28  macallan 		vcons_replay_msgbuf(&cg3_console_screen);
    244       1.17       jdc 	} else {
    245       1.17       jdc 		/*
    246       1.17       jdc 		 * we're not the console so we just clear the screen and don't
    247       1.17       jdc 		 * set up any sort of text display
    248       1.17       jdc 		 */
    249       1.17       jdc 	}
    250       1.17       jdc 
    251       1.17       jdc 	/* Initialize the default color map. */
    252       1.17       jdc 	cg3_setup_palette(sc);
    253       1.19       jdc 
    254       1.17       jdc 	aa.scrdata = &cgthree_screenlist;
    255       1.17       jdc 	aa.console = isconsole;
    256       1.17       jdc 	aa.accessops = &cgthree_accessops;
    257       1.17       jdc 	aa.accesscookie = &sc->vd;
    258       1.24   tsutsui 	config_found(sc->sc_dev, &aa, wsemuldisplaydevprint);
    259       1.17       jdc #else
    260       1.17       jdc 	/* Initialize the default color map. */
    261       1.17       jdc 	bt_initcmap(&sc->sc_cmap, 256);
    262       1.17       jdc 	cgthreeloadcmap(sc, 0, 256);
    263       1.17       jdc #endif
    264       1.17       jdc 
    265        1.1        pk }
    266        1.1        pk 
    267        1.1        pk 
    268        1.1        pk int
    269       1.22       dsl cgthreeopen(dev_t dev, int flags, int mode, struct lwp *l)
    270        1.1        pk {
    271        1.1        pk 	int unit = minor(dev);
    272        1.1        pk 
    273       1.16  drochner 	if (device_lookup(&cgthree_cd, unit) == NULL)
    274        1.1        pk 		return (ENXIO);
    275        1.1        pk 	return (0);
    276        1.1        pk }
    277        1.1        pk 
    278        1.1        pk int
    279       1.21       dsl cgthreeioctl(dev_t dev, u_long cmd, void *data, int flags, struct lwp *l)
    280        1.1        pk {
    281       1.16  drochner 	struct cgthree_softc *sc = device_lookup_private(&cgthree_cd,
    282       1.16  drochner 							 minor(dev));
    283        1.1        pk 	struct fbgattr *fba;
    284        1.1        pk 	int error;
    285        1.1        pk 
    286        1.1        pk 	switch (cmd) {
    287        1.1        pk 
    288        1.1        pk 	case FBIOGTYPE:
    289        1.1        pk 		*(struct fbtype *)data = sc->sc_fb.fb_type;
    290        1.1        pk 		break;
    291        1.1        pk 
    292        1.1        pk 	case FBIOGATTR:
    293        1.1        pk 		fba = (struct fbgattr *)data;
    294        1.1        pk 		fba->real_type = sc->sc_fb.fb_type.fb_type;
    295        1.1        pk 		fba->owner = 0;		/* XXX ??? */
    296        1.1        pk 		fba->fbtype = sc->sc_fb.fb_type;
    297        1.1        pk 		fba->sattr.flags = 0;
    298        1.1        pk 		fba->sattr.emu_type = sc->sc_fb.fb_type.fb_type;
    299        1.1        pk 		fba->sattr.dev_specific[0] = -1;
    300        1.1        pk 		fba->emu_types[0] = sc->sc_fb.fb_type.fb_type;
    301        1.1        pk 		fba->emu_types[1] = -1;
    302        1.1        pk 		break;
    303        1.1        pk 
    304        1.1        pk 	case FBIOGETCMAP:
    305        1.1        pk #define p ((struct fbcmap *)data)
    306        1.1        pk 		return (bt_getcmap(p, &sc->sc_cmap, 256, 1));
    307        1.1        pk 
    308        1.1        pk 	case FBIOPUTCMAP:
    309        1.1        pk 		/* copy to software map */
    310        1.1        pk 		error = bt_putcmap(p, &sc->sc_cmap, 256, 1);
    311        1.1        pk 		if (error)
    312        1.1        pk 			return (error);
    313        1.1        pk 		/* now blast them into the chip */
    314        1.1        pk 		/* XXX should use retrace interrupt */
    315        1.1        pk 		cgthreeloadcmap(sc, p->index, p->count);
    316        1.1        pk #undef p
    317        1.1        pk 		break;
    318        1.1        pk 
    319        1.1        pk 	case FBIOGVIDEO:
    320        1.1        pk 		*(int *)data = cgthree_get_video(sc);
    321        1.1        pk 		break;
    322        1.1        pk 
    323        1.1        pk 	case FBIOSVIDEO:
    324        1.1        pk 		cgthree_set_video(sc, *(int *)data);
    325        1.1        pk 		break;
    326        1.1        pk 
    327        1.1        pk 	default:
    328        1.1        pk 		return (ENOTTY);
    329        1.1        pk 	}
    330        1.1        pk 	return (0);
    331        1.1        pk }
    332        1.1        pk 
    333        1.1        pk /*
    334        1.1        pk  * Undo the effect of an FBIOSVIDEO that turns the video off.
    335        1.1        pk  */
    336        1.1        pk static void
    337       1.24   tsutsui cgthreeunblank(device_t self)
    338        1.1        pk {
    339       1.24   tsutsui 	struct cgthree_softc *sc = device_private(self);
    340        1.1        pk 
    341       1.24   tsutsui 	cgthree_set_video(sc, 1);
    342        1.1        pk }
    343        1.1        pk 
    344        1.1        pk static void
    345       1.21       dsl cgthree_set_video(struct cgthree_softc *sc, int enable)
    346        1.1        pk {
    347        1.1        pk 
    348        1.1        pk 	if (enable)
    349        1.1        pk 		sc->sc_fbc->fbc_ctrl |= FBC_VENAB;
    350        1.1        pk 	else
    351        1.1        pk 		sc->sc_fbc->fbc_ctrl &= ~FBC_VENAB;
    352        1.1        pk }
    353        1.1        pk 
    354        1.1        pk static int
    355       1.21       dsl cgthree_get_video(struct cgthree_softc *sc)
    356        1.1        pk {
    357        1.1        pk 
    358        1.1        pk 	return ((sc->sc_fbc->fbc_ctrl & FBC_VENAB) != 0);
    359        1.1        pk }
    360        1.1        pk 
    361        1.1        pk /*
    362        1.1        pk  * Load a subset of the current (new) colormap into the Brooktree DAC.
    363        1.1        pk  */
    364        1.1        pk static void
    365       1.22       dsl cgthreeloadcmap(struct cgthree_softc *sc, int start, int ncolors)
    366        1.1        pk {
    367        1.1        pk 	volatile struct bt_regs *bt;
    368        1.1        pk 	u_int *ip;
    369        1.1        pk 	int count;
    370        1.1        pk 
    371        1.1        pk 	ip = &sc->sc_cmap.cm_chip[BT_D4M3(start)];	/* start/4 * 3 */
    372        1.1        pk 	count = BT_D4M3(start + ncolors - 1) - BT_D4M3(start) + 3;
    373        1.1        pk 	bt = &sc->sc_fbc->fbc_dac;
    374        1.1        pk 	bt->bt_addr = BT_D4M4(start);
    375        1.1        pk 	while (--count >= 0)
    376        1.1        pk 		bt->bt_cmap = *ip++;
    377        1.1        pk }
    378        1.1        pk 
    379        1.1        pk /*
    380        1.1        pk  * Return the address that would map the given device at the given
    381        1.1        pk  * offset, allowing for the given protection, or return -1 for error.
    382        1.1        pk  *
    383        1.1        pk  * The cg3 is mapped starting at 256KB, for pseudo-compatibility with
    384        1.1        pk  * the cg4 (which had an overlay plane in the first 128K and an enable
    385        1.1        pk  * plane in the next 128K).  X11 uses only 256k+ region but tries to
    386        1.1        pk  * map the whole thing, so we repeatedly map the first 256K to the
    387        1.1        pk  * first page of the color screen.  If someone tries to use the overlay
    388        1.1        pk  * and enable regions, they will get a surprise....
    389        1.1        pk  *
    390        1.1        pk  * As well, mapping at an offset of 0x04000000 causes the cg3 to be
    391        1.1        pk  * mapped in flat mode without the cg4 emulation.
    392        1.1        pk  */
    393        1.1        pk paddr_t
    394       1.21       dsl cgthreemmap(dev_t dev, off_t off, int prot)
    395        1.1        pk {
    396       1.16  drochner 	struct cgthree_softc *sc = device_lookup_private(&cgthree_cd,
    397       1.16  drochner 							 minor(dev));
    398        1.1        pk 
    399        1.1        pk #define START		(128*1024 + 128*1024)
    400        1.1        pk #define NOOVERLAY	(0x04000000)
    401        1.1        pk 
    402        1.1        pk 	if (off & PGOFSET)
    403        1.1        pk 		panic("cgthreemmap");
    404        1.1        pk 	if (off < 0)
    405        1.1        pk 		return (-1);
    406        1.1        pk 	if ((u_int)off >= NOOVERLAY)
    407        1.1        pk 		off -= NOOVERLAY;
    408        1.1        pk 	else if ((u_int)off >= START)
    409        1.1        pk 		off -= START;
    410        1.1        pk 	else
    411        1.1        pk 		off = 0;
    412        1.1        pk 
    413        1.1        pk 	if (off >= sc->sc_fb.fb_type.fb_size)
    414        1.1        pk 		return (-1);
    415        1.1        pk 
    416        1.3       eeh 	return (bus_space_mmap(sc->sc_bustag,
    417        1.3       eeh 		sc->sc_paddr, CG3REG_MEM + off,
    418        1.3       eeh 		prot, BUS_SPACE_MAP_LINEAR));
    419        1.1        pk }
    420       1.17       jdc 
    421       1.17       jdc #if NWSDISPLAY > 0
    422       1.17       jdc 
    423       1.17       jdc static void
    424       1.17       jdc cg3_setup_palette(struct cgthree_softc *sc)
    425       1.17       jdc {
    426       1.17       jdc 	int i, j;
    427       1.19       jdc 
    428       1.17       jdc 	j = 0;
    429       1.17       jdc 	for (i = 0; i < 256; i++) {
    430       1.17       jdc 		sc->sc_cmap.cm_map[i][0] = rasops_cmap[j];
    431       1.17       jdc 		j++;
    432       1.17       jdc 		sc->sc_cmap.cm_map[i][1] = rasops_cmap[j];
    433       1.17       jdc 		j++;
    434       1.17       jdc 		sc->sc_cmap.cm_map[i][2] = rasops_cmap[j];
    435       1.17       jdc 		j++;
    436       1.17       jdc 	}
    437       1.17       jdc 	cgthreeloadcmap(sc, 0, 256);
    438       1.17       jdc }
    439       1.17       jdc 
    440       1.17       jdc int
    441       1.17       jdc cgthree_ioctl(void *v, void *vs, u_long cmd, void *data, int flag,
    442       1.17       jdc 	struct lwp *l)
    443       1.17       jdc {
    444       1.17       jdc 	/* we'll probably need to add more stuff here */
    445       1.17       jdc 	struct vcons_data *vd = v;
    446       1.17       jdc 	struct cgthree_softc *sc = vd->cookie;
    447       1.17       jdc 	struct wsdisplay_fbinfo *wdf;
    448       1.17       jdc 	struct rasops_info *ri = &sc->sc_fb.fb_rinfo;
    449       1.17       jdc 	struct vcons_screen *ms = sc->vd.active;
    450       1.17       jdc 	switch (cmd) {
    451       1.17       jdc 		case WSDISPLAYIO_GTYPE:
    452       1.17       jdc 			*(u_int *)data = WSDISPLAY_TYPE_SUNTCX;
    453       1.17       jdc 			return 0;
    454       1.17       jdc 		case WSDISPLAYIO_GINFO:
    455       1.17       jdc 			wdf = (void *)data;
    456       1.17       jdc 			wdf->height = ri->ri_height;
    457       1.17       jdc 			wdf->width = ri->ri_width;
    458       1.17       jdc 			wdf->depth = ri->ri_depth;
    459       1.17       jdc 			wdf->cmsize = 256;
    460       1.17       jdc 			return 0;
    461       1.17       jdc 
    462       1.17       jdc 		case WSDISPLAYIO_GETCMAP:
    463       1.17       jdc 			return cgthree_getcmap(sc,
    464       1.17       jdc 			    (struct wsdisplay_cmap *)data);
    465       1.17       jdc 		case WSDISPLAYIO_PUTCMAP:
    466       1.17       jdc 			return cgthree_putcmap(sc,
    467       1.17       jdc 			    (struct wsdisplay_cmap *)data);
    468       1.17       jdc 
    469       1.17       jdc 		case WSDISPLAYIO_SMODE:
    470       1.17       jdc 			{
    471       1.17       jdc 				int new_mode = *(int*)data;
    472       1.17       jdc 				if (new_mode != sc->sc_mode)
    473       1.17       jdc 				{
    474       1.17       jdc 					sc->sc_mode = new_mode;
    475       1.17       jdc 					if(new_mode == WSDISPLAYIO_MODE_EMUL)
    476       1.17       jdc 					{
    477       1.17       jdc 						cg3_setup_palette(sc);
    478       1.17       jdc 						vcons_redraw_screen(ms);
    479       1.17       jdc 					}
    480       1.17       jdc 				}
    481       1.17       jdc 			}
    482       1.17       jdc 	}
    483       1.17       jdc 	return EPASSTHROUGH;
    484       1.17       jdc }
    485       1.17       jdc 
    486       1.17       jdc paddr_t
    487       1.17       jdc cgthree_mmap(void *v, void *vs, off_t offset, int prot)
    488       1.17       jdc {
    489       1.17       jdc 	/* I'm not at all sure this is the right thing to do */
    490       1.17       jdc 	return cgthreemmap(0, offset, prot); /* assume minor dev 0 for now */
    491       1.17       jdc }
    492       1.17       jdc 
    493       1.17       jdc int
    494       1.17       jdc cgthree_putcmap(struct cgthree_softc *sc, struct wsdisplay_cmap *cm)
    495       1.17       jdc {
    496       1.17       jdc 	u_int index = cm->index;
    497       1.17       jdc 	u_int count = cm->count;
    498       1.17       jdc 	int error,i;
    499       1.17       jdc 	if (index >= 256 || count > 256 || index + count > 256)
    500       1.17       jdc 		return EINVAL;
    501       1.17       jdc 
    502       1.17       jdc 	for (i = 0; i < count; i++)
    503       1.17       jdc 	{
    504       1.17       jdc 		error = copyin(&cm->red[i],
    505       1.17       jdc 		    &sc->sc_cmap.cm_map[index + i][0], 1);
    506       1.17       jdc 		if (error)
    507       1.17       jdc 			return error;
    508       1.17       jdc 		error = copyin(&cm->green[i],
    509       1.17       jdc 		    &sc->sc_cmap.cm_map[index + i][1],
    510       1.17       jdc 		    1);
    511       1.17       jdc 		if (error)
    512       1.17       jdc 			return error;
    513       1.17       jdc 		error = copyin(&cm->blue[i],
    514       1.17       jdc 		    &sc->sc_cmap.cm_map[index + i][2], 1);
    515       1.17       jdc 		if (error)
    516       1.17       jdc 			return error;
    517       1.17       jdc 	}
    518       1.17       jdc 	cgthreeloadcmap(sc, index, count);
    519       1.17       jdc 
    520       1.17       jdc 	return 0;
    521       1.17       jdc }
    522       1.17       jdc 
    523       1.17       jdc int
    524       1.17       jdc cgthree_getcmap(struct cgthree_softc *sc, struct wsdisplay_cmap *cm)
    525       1.17       jdc {
    526       1.17       jdc 	u_int index = cm->index;
    527       1.17       jdc 	u_int count = cm->count;
    528       1.17       jdc 	int error,i;
    529       1.17       jdc 
    530       1.17       jdc 	if (index >= 256 || count > 256 || index + count > 256)
    531       1.17       jdc 		return EINVAL;
    532       1.17       jdc 
    533       1.17       jdc 	for (i = 0; i < count; i++)
    534       1.17       jdc 	{
    535       1.17       jdc 		error = copyout(&sc->sc_cmap.cm_map[index + i][0],
    536       1.17       jdc 		    &cm->red[i], 1);
    537       1.17       jdc 		if (error)
    538       1.17       jdc 			return error;
    539       1.17       jdc 		error = copyout(&sc->sc_cmap.cm_map[index + i][1],
    540       1.17       jdc 		    &cm->green[i], 1);
    541       1.17       jdc 		if (error)
    542       1.17       jdc 			return error;
    543       1.17       jdc 		error = copyout(&sc->sc_cmap.cm_map[index + i][2],
    544       1.17       jdc 		    &cm->blue[i], 1);
    545       1.17       jdc 		if (error)
    546       1.17       jdc 			return error;
    547       1.17       jdc 	}
    548       1.17       jdc 
    549       1.17       jdc 	return 0;
    550       1.17       jdc }
    551       1.17       jdc 
    552       1.17       jdc void
    553       1.17       jdc cgthree_init_screen(void *cookie, struct vcons_screen *scr,
    554       1.17       jdc     int existing, long *defattr)
    555       1.17       jdc {
    556       1.17       jdc 	struct cgthree_softc *sc = cookie;
    557       1.17       jdc 	struct rasops_info *ri = &scr->scr_ri;
    558       1.17       jdc 
    559       1.27  macallan 	scr->scr_flags |= VCONS_DONT_READ;
    560       1.27  macallan 
    561       1.17       jdc 	ri->ri_depth = 8;
    562       1.17       jdc 	ri->ri_width = sc->sc_width;
    563       1.17       jdc 	ri->ri_height = sc->sc_height;
    564       1.17       jdc 	ri->ri_stride = sc->sc_stride;
    565       1.19       jdc 	ri->ri_flg = RI_CENTER;
    566       1.17       jdc 
    567       1.17       jdc 	ri->ri_bits = sc->sc_fb.fb_pixels;
    568       1.19       jdc 
    569       1.29  macallan 	rasops_init(ri, 0, 0);
    570       1.17       jdc 	ri->ri_caps = WSSCREEN_WSCOLORS | WSSCREEN_REVERSE;
    571       1.17       jdc 	rasops_reconfig(ri, sc->sc_height / ri->ri_font->fontheight,
    572       1.17       jdc 		    sc->sc_width / ri->ri_font->fontwidth);
    573       1.17       jdc 
    574       1.17       jdc 	ri->ri_hw = scr;
    575       1.17       jdc }
    576       1.17       jdc 
    577       1.17       jdc #endif /* NWSDISPLAY > 0 */
    578