Home | History | Annotate | Line # | Download | only in sun
cgthree.c revision 1.14.16.3
      1  1.14.16.1       mjf /*	$NetBSD: cgthree.c,v 1.14.16.3 2009/01/17 13:29:08 mjf 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.14.16.1       mjf __KERNEL_RCSID(0, "$NetBSD: cgthree.c,v 1.14.16.3 2009/01/17 13:29:08 mjf 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.14.16.3       mjf #include "wsdisplay.h"
     60  1.14.16.3       mjf #if NWSDISPLAY > 0
     61  1.14.16.3       mjf #include <dev/wscons/wsconsio.h>
     62  1.14.16.3       mjf #include <dev/wsfont/wsfont.h>
     63  1.14.16.3       mjf #include <dev/rasops/rasops.h>
     64  1.14.16.3       mjf #include <dev/wscons/wsdisplay_vconsvar.h>
     65  1.14.16.3       mjf 
     66  1.14.16.3       mjf #include "opt_wsemul.h"
     67  1.14.16.3       mjf #endif
     68  1.14.16.3       mjf 
     69        1.1        pk #include <dev/sun/btreg.h>
     70        1.1        pk #include <dev/sun/btvar.h>
     71        1.1        pk #include <dev/sun/cgthreereg.h>
     72        1.1        pk #include <dev/sun/cgthreevar.h>
     73        1.1        pk 
     74        1.2        pk static void	cgthreeunblank(struct device *);
     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 extern struct cfdriver cgthree_cd;
     80        1.1        pk 
     81        1.5   gehenna dev_type_open(cgthreeopen);
     82        1.5   gehenna dev_type_ioctl(cgthreeioctl);
     83        1.5   gehenna dev_type_mmap(cgthreemmap);
     84        1.5   gehenna 
     85        1.5   gehenna const struct cdevsw cgthree_cdevsw = {
     86        1.5   gehenna 	cgthreeopen, nullclose, noread, nowrite, cgthreeioctl,
     87        1.6  jdolecek 	nostop, notty, nopoll, cgthreemmap, nokqfilter
     88        1.5   gehenna };
     89        1.1        pk 
     90        1.1        pk /* frame buffer generic driver */
     91        1.1        pk static struct fbdriver cgthreefbdriver = {
     92        1.5   gehenna 	cgthreeunblank, cgthreeopen, nullclose, cgthreeioctl, nopoll,
     93        1.6  jdolecek 	cgthreemmap, nokqfilter
     94        1.1        pk };
     95        1.1        pk 
     96        1.1        pk /* Video control parameters */
     97        1.1        pk struct cg3_videoctrl {
     98        1.1        pk 	unsigned char	sense;		/* Monitor sense value */
     99        1.1        pk 	unsigned char	vctrl[12];
    100        1.1        pk } cg3_videoctrl[] = {
    101        1.1        pk /* Missing entries: sense 0x10, 0x30, 0x50 */
    102        1.1        pk 	{ 0x40, /* this happens to be my 19'' 1152x900 gray-scale monitor */
    103        1.1        pk 	   {0xbb, 0x2b, 0x3, 0xb, 0xb3, 0x3, 0xaf, 0x2b, 0x2, 0xa, 0xff, 0x1}
    104        1.1        pk 	},
    105        1.1        pk 	{ 0x00, /* default? must be last */
    106        1.1        pk 	   {0xbb, 0x2b, 0x3, 0xb, 0xb3, 0x3, 0xaf, 0x2b, 0x2, 0xa, 0xff, 0x1}
    107        1.1        pk 	}
    108        1.1        pk };
    109        1.1        pk 
    110  1.14.16.3       mjf #if NWSDISPLAY > 0
    111  1.14.16.3       mjf #ifdef RASTERCONSOLE
    112  1.14.16.3       mjf #error RASTERCONSOLE and wsdisplay are mutually exclusive
    113  1.14.16.3       mjf #endif
    114  1.14.16.3       mjf 
    115  1.14.16.3       mjf static void cg3_setup_palette(struct cgthree_softc *);
    116  1.14.16.3       mjf 
    117  1.14.16.3       mjf struct wsscreen_descr cgthree_defaultscreen = {
    118  1.14.16.3       mjf 	"std",
    119  1.14.16.3       mjf 	0, 0,	/* will be filled in -- XXX shouldn't, it's global */
    120  1.14.16.3       mjf 	NULL,		/* textops */
    121  1.14.16.3       mjf 	8, 16,	/* font width/height */
    122  1.14.16.3       mjf 	WSSCREEN_WSCOLORS,	/* capabilities */
    123  1.14.16.3       mjf 	NULL	/* modecookie */
    124  1.14.16.3       mjf };
    125  1.14.16.3       mjf 
    126  1.14.16.3       mjf static int 	cgthree_ioctl(void *, void *, u_long, void *, int, struct lwp *);
    127  1.14.16.3       mjf static paddr_t	cgthree_mmap(void *, void *, off_t, int);
    128  1.14.16.3       mjf static void	cgthree_init_screen(void *, struct vcons_screen *, int, long *);
    129  1.14.16.3       mjf 
    130  1.14.16.3       mjf int	cgthree_putcmap(struct cgthree_softc *, struct wsdisplay_cmap *);
    131  1.14.16.3       mjf int	cgthree_getcmap(struct cgthree_softc *, struct wsdisplay_cmap *);
    132  1.14.16.3       mjf 
    133  1.14.16.3       mjf struct wsdisplay_accessops cgthree_accessops = {
    134  1.14.16.3       mjf 	cgthree_ioctl,
    135  1.14.16.3       mjf 	cgthree_mmap,
    136  1.14.16.3       mjf 	NULL,	/* alloc_screen */
    137  1.14.16.3       mjf 	NULL,	/* free_screen */
    138  1.14.16.3       mjf 	NULL,	/* show_screen */
    139  1.14.16.3       mjf 	NULL, 	/* load_font */
    140  1.14.16.3       mjf 	NULL,	/* pollc */
    141  1.14.16.3       mjf 	NULL	/* scroll */
    142  1.14.16.3       mjf };
    143  1.14.16.3       mjf 
    144  1.14.16.3       mjf const struct wsscreen_descr *_cgthree_scrlist[] = {
    145  1.14.16.3       mjf 	&cgthree_defaultscreen
    146  1.14.16.3       mjf };
    147  1.14.16.3       mjf 
    148  1.14.16.3       mjf struct wsscreen_list cgthree_screenlist = {
    149  1.14.16.3       mjf 	sizeof(_cgthree_scrlist) / sizeof(struct wsscreen_descr *),
    150  1.14.16.3       mjf 	_cgthree_scrlist
    151  1.14.16.3       mjf };
    152  1.14.16.3       mjf 
    153  1.14.16.3       mjf 
    154  1.14.16.3       mjf extern const u_char rasops_cmap[768];
    155  1.14.16.3       mjf 
    156  1.14.16.3       mjf static struct vcons_screen cg3_console_screen;
    157  1.14.16.3       mjf #endif /* NWSDISPLAY > 0 */
    158        1.1        pk 
    159        1.1        pk void
    160        1.1        pk cgthreeattach(sc, name, isconsole)
    161        1.1        pk 	struct cgthree_softc *sc;
    162       1.11   tsutsui 	const char *name;
    163        1.1        pk 	int isconsole;
    164        1.1        pk {
    165        1.1        pk 	int i;
    166        1.1        pk 	struct fbdevice *fb = &sc->sc_fb;
    167  1.14.16.3       mjf #if NWSDISPLAY > 0
    168  1.14.16.3       mjf 	struct wsemuldisplaydev_attach_args aa;
    169  1.14.16.3       mjf 	struct rasops_info *ri = &cg3_console_screen.scr_ri;
    170  1.14.16.3       mjf 	unsigned long defattr;
    171  1.14.16.3       mjf #endif
    172        1.1        pk 	volatile struct fbcontrol *fbc = sc->sc_fbc;
    173        1.1        pk 	volatile struct bt_regs *bt = &fbc->fbc_dac;
    174        1.1        pk 
    175        1.1        pk 	fb->fb_driver = &cgthreefbdriver;
    176        1.1        pk 	fb->fb_type.fb_cmsize = 256;
    177        1.1        pk 	fb->fb_type.fb_size = fb->fb_type.fb_height * fb->fb_linebytes;
    178        1.1        pk 	printf(": %s, %d x %d", name,
    179        1.1        pk 		fb->fb_type.fb_width, fb->fb_type.fb_height);
    180        1.1        pk 
    181        1.1        pk 	/* Transfer video magic to board, if it's not running */
    182        1.1        pk 	if ((fbc->fbc_ctrl & FBC_TIMING) == 0) {
    183        1.1        pk 		int sense = (fbc->fbc_status & FBS_MSENSE);
    184        1.1        pk 		/* Search table for video timings fitting this monitor */
    185        1.1        pk 		for (i = 0; i < sizeof(cg3_videoctrl)/sizeof(cg3_videoctrl[0]);
    186        1.1        pk 		     i++) {
    187        1.1        pk 			int j;
    188        1.1        pk 			if (sense != cg3_videoctrl[i].sense)
    189        1.1        pk 				continue;
    190        1.1        pk 
    191        1.1        pk 			printf(" setting video ctrl");
    192        1.1        pk 			for (j = 0; j < 12; j++)
    193        1.1        pk 				fbc->fbc_vcontrol[j] =
    194        1.1        pk 					cg3_videoctrl[i].vctrl[j];
    195        1.1        pk 			fbc->fbc_ctrl |= FBC_TIMING;
    196        1.1        pk 			break;
    197        1.1        pk 		}
    198        1.1        pk 	}
    199        1.1        pk 
    200        1.1        pk 	/* make sure we are not blanked */
    201        1.1        pk 	cgthree_set_video(sc, 1);
    202        1.1        pk 	BT_INIT(bt, 0);
    203        1.1        pk 
    204        1.1        pk 	if (isconsole) {
    205        1.1        pk 		printf(" (console)\n");
    206        1.1        pk #ifdef RASTERCONSOLE
    207        1.1        pk 		fbrcons_init(fb);
    208        1.1        pk #endif
    209        1.1        pk 	} else
    210        1.1        pk 		printf("\n");
    211        1.1        pk 
    212        1.1        pk 	fb_attach(fb, isconsole);
    213  1.14.16.3       mjf 
    214  1.14.16.3       mjf #if NWSDISPLAY > 0
    215  1.14.16.3       mjf 	sc->sc_width = fb->fb_type.fb_width;
    216  1.14.16.3       mjf 	sc->sc_stride = fb->fb_type.fb_width;
    217  1.14.16.3       mjf 	sc->sc_height = fb->fb_type.fb_height;
    218  1.14.16.3       mjf 
    219  1.14.16.3       mjf 	/* setup rasops and so on for wsdisplay */
    220  1.14.16.3       mjf 	sc->sc_mode = WSDISPLAYIO_MODE_EMUL;
    221  1.14.16.3       mjf 
    222  1.14.16.3       mjf 	vcons_init(&sc->vd, sc, &cgthree_defaultscreen, &cgthree_accessops);
    223  1.14.16.3       mjf 	sc->vd.init_screen = cgthree_init_screen;
    224  1.14.16.3       mjf 
    225  1.14.16.3       mjf 	if(isconsole) {
    226  1.14.16.3       mjf 		/* we mess with cg3_console_screen only once */
    227  1.14.16.3       mjf 		vcons_init_screen(&sc->vd, &cg3_console_screen, 1,
    228  1.14.16.3       mjf 		    &defattr);
    229  1.14.16.3       mjf 		cg3_console_screen.scr_flags |= VCONS_SCREEN_IS_STATIC;
    230  1.14.16.3       mjf 
    231  1.14.16.3       mjf 		cgthree_defaultscreen.textops = &ri->ri_ops;
    232  1.14.16.3       mjf 		cgthree_defaultscreen.capabilities = ri->ri_caps;
    233  1.14.16.3       mjf 		cgthree_defaultscreen.nrows = ri->ri_rows;
    234  1.14.16.3       mjf 		cgthree_defaultscreen.ncols = ri->ri_cols;
    235  1.14.16.3       mjf 		sc->vd.active = &cg3_console_screen;
    236  1.14.16.3       mjf 		wsdisplay_cnattach(&cgthree_defaultscreen, ri, 0, 0, defattr);
    237  1.14.16.3       mjf 	} else {
    238  1.14.16.3       mjf 		/*
    239  1.14.16.3       mjf 		 * we're not the console so we just clear the screen and don't
    240  1.14.16.3       mjf 		 * set up any sort of text display
    241  1.14.16.3       mjf 		 */
    242  1.14.16.3       mjf 		if (cgthree_defaultscreen.textops == NULL) {
    243  1.14.16.3       mjf 			/*
    244  1.14.16.3       mjf 			 * ugly, but...
    245  1.14.16.3       mjf 			 * we want the console settings to win, so we only
    246  1.14.16.3       mjf 			 * touch anything when we find an untouched screen
    247  1.14.16.3       mjf 			 * definition. In this case we fill it from fb to
    248  1.14.16.3       mjf 			 * avoid problems in case no cgthree is the console
    249  1.14.16.3       mjf 			 */
    250  1.14.16.3       mjf 			ri = &sc->sc_fb.fb_rinfo;
    251  1.14.16.3       mjf 			cgthree_defaultscreen.textops = &ri->ri_ops;
    252  1.14.16.3       mjf 			cgthree_defaultscreen.capabilities = ri->ri_caps;
    253  1.14.16.3       mjf 			cgthree_defaultscreen.nrows = ri->ri_rows;
    254  1.14.16.3       mjf 			cgthree_defaultscreen.ncols = ri->ri_cols;
    255  1.14.16.3       mjf 		}
    256  1.14.16.3       mjf 	}
    257  1.14.16.3       mjf 
    258  1.14.16.3       mjf 	/* Initialize the default color map. */
    259  1.14.16.3       mjf 	cg3_setup_palette(sc);
    260  1.14.16.3       mjf 
    261  1.14.16.3       mjf 	aa.scrdata = &cgthree_screenlist;
    262  1.14.16.3       mjf 	aa.console = isconsole;
    263  1.14.16.3       mjf 	aa.accessops = &cgthree_accessops;
    264  1.14.16.3       mjf 	aa.accesscookie = &sc->vd;
    265  1.14.16.3       mjf 	config_found(&sc->sc_dev, &aa, wsemuldisplaydevprint);
    266  1.14.16.3       mjf #else
    267  1.14.16.3       mjf 	/* Initialize the default color map. */
    268  1.14.16.3       mjf 	bt_initcmap(&sc->sc_cmap, 256);
    269  1.14.16.3       mjf 	cgthreeloadcmap(sc, 0, 256);
    270  1.14.16.3       mjf #endif
    271  1.14.16.3       mjf 
    272        1.1        pk }
    273        1.1        pk 
    274        1.1        pk 
    275        1.1        pk int
    276       1.12  christos cgthreeopen(dev, flags, mode, l)
    277        1.1        pk 	dev_t dev;
    278        1.1        pk 	int flags, mode;
    279       1.12  christos 	struct lwp *l;
    280        1.1        pk {
    281        1.1        pk 	int unit = minor(dev);
    282        1.1        pk 
    283  1.14.16.2       mjf 	if (device_lookup(&cgthree_cd, unit) == NULL)
    284        1.1        pk 		return (ENXIO);
    285        1.1        pk 	return (0);
    286        1.1        pk }
    287        1.1        pk 
    288        1.1        pk int
    289       1.12  christos cgthreeioctl(dev, cmd, data, flags, l)
    290        1.1        pk 	dev_t dev;
    291        1.1        pk 	u_long cmd;
    292       1.13  christos 	void *data;
    293        1.1        pk 	int flags;
    294       1.12  christos 	struct lwp *l;
    295        1.1        pk {
    296  1.14.16.2       mjf 	struct cgthree_softc *sc = device_lookup_private(&cgthree_cd,
    297  1.14.16.2       mjf 							 minor(dev));
    298        1.1        pk 	struct fbgattr *fba;
    299        1.1        pk 	int error;
    300        1.1        pk 
    301        1.1        pk 	switch (cmd) {
    302        1.1        pk 
    303        1.1        pk 	case FBIOGTYPE:
    304        1.1        pk 		*(struct fbtype *)data = sc->sc_fb.fb_type;
    305        1.1        pk 		break;
    306        1.1        pk 
    307        1.1        pk 	case FBIOGATTR:
    308        1.1        pk 		fba = (struct fbgattr *)data;
    309        1.1        pk 		fba->real_type = sc->sc_fb.fb_type.fb_type;
    310        1.1        pk 		fba->owner = 0;		/* XXX ??? */
    311        1.1        pk 		fba->fbtype = sc->sc_fb.fb_type;
    312        1.1        pk 		fba->sattr.flags = 0;
    313        1.1        pk 		fba->sattr.emu_type = sc->sc_fb.fb_type.fb_type;
    314        1.1        pk 		fba->sattr.dev_specific[0] = -1;
    315        1.1        pk 		fba->emu_types[0] = sc->sc_fb.fb_type.fb_type;
    316        1.1        pk 		fba->emu_types[1] = -1;
    317        1.1        pk 		break;
    318        1.1        pk 
    319        1.1        pk 	case FBIOGETCMAP:
    320        1.1        pk #define p ((struct fbcmap *)data)
    321        1.1        pk 		return (bt_getcmap(p, &sc->sc_cmap, 256, 1));
    322        1.1        pk 
    323        1.1        pk 	case FBIOPUTCMAP:
    324        1.1        pk 		/* copy to software map */
    325        1.1        pk 		error = bt_putcmap(p, &sc->sc_cmap, 256, 1);
    326        1.1        pk 		if (error)
    327        1.1        pk 			return (error);
    328        1.1        pk 		/* now blast them into the chip */
    329        1.1        pk 		/* XXX should use retrace interrupt */
    330        1.1        pk 		cgthreeloadcmap(sc, p->index, p->count);
    331        1.1        pk #undef p
    332        1.1        pk 		break;
    333        1.1        pk 
    334        1.1        pk 	case FBIOGVIDEO:
    335        1.1        pk 		*(int *)data = cgthree_get_video(sc);
    336        1.1        pk 		break;
    337        1.1        pk 
    338        1.1        pk 	case FBIOSVIDEO:
    339        1.1        pk 		cgthree_set_video(sc, *(int *)data);
    340        1.1        pk 		break;
    341        1.1        pk 
    342        1.1        pk 	default:
    343        1.1        pk 		return (ENOTTY);
    344        1.1        pk 	}
    345        1.1        pk 	return (0);
    346        1.1        pk }
    347        1.1        pk 
    348        1.1        pk /*
    349        1.1        pk  * Undo the effect of an FBIOSVIDEO that turns the video off.
    350        1.1        pk  */
    351        1.1        pk static void
    352        1.1        pk cgthreeunblank(dev)
    353        1.1        pk 	struct device *dev;
    354        1.1        pk {
    355        1.1        pk 
    356  1.14.16.2       mjf 	cgthree_set_video(device_private(dev), 1);
    357        1.1        pk }
    358        1.1        pk 
    359        1.1        pk static void
    360        1.1        pk cgthree_set_video(sc, enable)
    361        1.1        pk 	struct cgthree_softc *sc;
    362        1.1        pk 	int enable;
    363        1.1        pk {
    364        1.1        pk 
    365        1.1        pk 	if (enable)
    366        1.1        pk 		sc->sc_fbc->fbc_ctrl |= FBC_VENAB;
    367        1.1        pk 	else
    368        1.1        pk 		sc->sc_fbc->fbc_ctrl &= ~FBC_VENAB;
    369        1.1        pk }
    370        1.1        pk 
    371        1.1        pk static int
    372        1.1        pk cgthree_get_video(sc)
    373        1.1        pk 	struct cgthree_softc *sc;
    374        1.1        pk {
    375        1.1        pk 
    376        1.1        pk 	return ((sc->sc_fbc->fbc_ctrl & FBC_VENAB) != 0);
    377        1.1        pk }
    378        1.1        pk 
    379        1.1        pk /*
    380        1.1        pk  * Load a subset of the current (new) colormap into the Brooktree DAC.
    381        1.1        pk  */
    382        1.1        pk static void
    383        1.1        pk cgthreeloadcmap(sc, start, ncolors)
    384        1.1        pk 	struct cgthree_softc *sc;
    385        1.1        pk 	int start, ncolors;
    386        1.1        pk {
    387        1.1        pk 	volatile struct bt_regs *bt;
    388        1.1        pk 	u_int *ip;
    389        1.1        pk 	int count;
    390        1.1        pk 
    391        1.1        pk 	ip = &sc->sc_cmap.cm_chip[BT_D4M3(start)];	/* start/4 * 3 */
    392        1.1        pk 	count = BT_D4M3(start + ncolors - 1) - BT_D4M3(start) + 3;
    393        1.1        pk 	bt = &sc->sc_fbc->fbc_dac;
    394        1.1        pk 	bt->bt_addr = BT_D4M4(start);
    395        1.1        pk 	while (--count >= 0)
    396        1.1        pk 		bt->bt_cmap = *ip++;
    397        1.1        pk }
    398        1.1        pk 
    399        1.1        pk /*
    400        1.1        pk  * Return the address that would map the given device at the given
    401        1.1        pk  * offset, allowing for the given protection, or return -1 for error.
    402        1.1        pk  *
    403        1.1        pk  * The cg3 is mapped starting at 256KB, for pseudo-compatibility with
    404        1.1        pk  * the cg4 (which had an overlay plane in the first 128K and an enable
    405        1.1        pk  * plane in the next 128K).  X11 uses only 256k+ region but tries to
    406        1.1        pk  * map the whole thing, so we repeatedly map the first 256K to the
    407        1.1        pk  * first page of the color screen.  If someone tries to use the overlay
    408        1.1        pk  * and enable regions, they will get a surprise....
    409        1.1        pk  *
    410        1.1        pk  * As well, mapping at an offset of 0x04000000 causes the cg3 to be
    411        1.1        pk  * mapped in flat mode without the cg4 emulation.
    412        1.1        pk  */
    413        1.1        pk paddr_t
    414        1.1        pk cgthreemmap(dev, off, prot)
    415        1.1        pk 	dev_t dev;
    416        1.1        pk 	off_t off;
    417        1.1        pk 	int prot;
    418        1.1        pk {
    419  1.14.16.2       mjf 	struct cgthree_softc *sc = device_lookup_private(&cgthree_cd,
    420  1.14.16.2       mjf 							 minor(dev));
    421        1.1        pk 
    422        1.1        pk #define START		(128*1024 + 128*1024)
    423        1.1        pk #define NOOVERLAY	(0x04000000)
    424        1.1        pk 
    425        1.1        pk 	if (off & PGOFSET)
    426        1.1        pk 		panic("cgthreemmap");
    427        1.1        pk 	if (off < 0)
    428        1.1        pk 		return (-1);
    429        1.1        pk 	if ((u_int)off >= NOOVERLAY)
    430        1.1        pk 		off -= NOOVERLAY;
    431        1.1        pk 	else if ((u_int)off >= START)
    432        1.1        pk 		off -= START;
    433        1.1        pk 	else
    434        1.1        pk 		off = 0;
    435        1.1        pk 
    436        1.1        pk 	if (off >= sc->sc_fb.fb_type.fb_size)
    437        1.1        pk 		return (-1);
    438        1.1        pk 
    439        1.3       eeh 	return (bus_space_mmap(sc->sc_bustag,
    440        1.3       eeh 		sc->sc_paddr, CG3REG_MEM + off,
    441        1.3       eeh 		prot, BUS_SPACE_MAP_LINEAR));
    442        1.1        pk }
    443  1.14.16.3       mjf 
    444  1.14.16.3       mjf #if NWSDISPLAY > 0
    445  1.14.16.3       mjf 
    446  1.14.16.3       mjf static void
    447  1.14.16.3       mjf cg3_setup_palette(struct cgthree_softc *sc)
    448  1.14.16.3       mjf {
    449  1.14.16.3       mjf 	int i, j;
    450  1.14.16.3       mjf 
    451  1.14.16.3       mjf 	j = 0;
    452  1.14.16.3       mjf 	for (i = 0; i < 256; i++) {
    453  1.14.16.3       mjf 		sc->sc_cmap.cm_map[i][0] = rasops_cmap[j];
    454  1.14.16.3       mjf 		j++;
    455  1.14.16.3       mjf 		sc->sc_cmap.cm_map[i][1] = rasops_cmap[j];
    456  1.14.16.3       mjf 		j++;
    457  1.14.16.3       mjf 		sc->sc_cmap.cm_map[i][2] = rasops_cmap[j];
    458  1.14.16.3       mjf 		j++;
    459  1.14.16.3       mjf 	}
    460  1.14.16.3       mjf 	cgthreeloadcmap(sc, 0, 256);
    461  1.14.16.3       mjf }
    462  1.14.16.3       mjf 
    463  1.14.16.3       mjf int
    464  1.14.16.3       mjf cgthree_ioctl(void *v, void *vs, u_long cmd, void *data, int flag,
    465  1.14.16.3       mjf 	struct lwp *l)
    466  1.14.16.3       mjf {
    467  1.14.16.3       mjf 	/* we'll probably need to add more stuff here */
    468  1.14.16.3       mjf 	struct vcons_data *vd = v;
    469  1.14.16.3       mjf 	struct cgthree_softc *sc = vd->cookie;
    470  1.14.16.3       mjf 	struct wsdisplay_fbinfo *wdf;
    471  1.14.16.3       mjf 	struct rasops_info *ri = &sc->sc_fb.fb_rinfo;
    472  1.14.16.3       mjf 	struct vcons_screen *ms = sc->vd.active;
    473  1.14.16.3       mjf 	switch (cmd) {
    474  1.14.16.3       mjf 		case WSDISPLAYIO_GTYPE:
    475  1.14.16.3       mjf 			*(u_int *)data = WSDISPLAY_TYPE_SUNTCX;
    476  1.14.16.3       mjf 			return 0;
    477  1.14.16.3       mjf 		case WSDISPLAYIO_GINFO:
    478  1.14.16.3       mjf 			wdf = (void *)data;
    479  1.14.16.3       mjf 			wdf->height = ri->ri_height;
    480  1.14.16.3       mjf 			wdf->width = ri->ri_width;
    481  1.14.16.3       mjf 			wdf->depth = ri->ri_depth;
    482  1.14.16.3       mjf 			wdf->cmsize = 256;
    483  1.14.16.3       mjf 			return 0;
    484  1.14.16.3       mjf 
    485  1.14.16.3       mjf 		case WSDISPLAYIO_GETCMAP:
    486  1.14.16.3       mjf 			return cgthree_getcmap(sc,
    487  1.14.16.3       mjf 			    (struct wsdisplay_cmap *)data);
    488  1.14.16.3       mjf 		case WSDISPLAYIO_PUTCMAP:
    489  1.14.16.3       mjf 			return cgthree_putcmap(sc,
    490  1.14.16.3       mjf 			    (struct wsdisplay_cmap *)data);
    491  1.14.16.3       mjf 
    492  1.14.16.3       mjf 		case WSDISPLAYIO_SMODE:
    493  1.14.16.3       mjf 			{
    494  1.14.16.3       mjf 				int new_mode = *(int*)data;
    495  1.14.16.3       mjf 				if (new_mode != sc->sc_mode)
    496  1.14.16.3       mjf 				{
    497  1.14.16.3       mjf 					sc->sc_mode = new_mode;
    498  1.14.16.3       mjf 					if(new_mode == WSDISPLAYIO_MODE_EMUL)
    499  1.14.16.3       mjf 					{
    500  1.14.16.3       mjf 						cg3_setup_palette(sc);
    501  1.14.16.3       mjf 						vcons_redraw_screen(ms);
    502  1.14.16.3       mjf 					}
    503  1.14.16.3       mjf 				}
    504  1.14.16.3       mjf 			}
    505  1.14.16.3       mjf 	}
    506  1.14.16.3       mjf 	return EPASSTHROUGH;
    507  1.14.16.3       mjf }
    508  1.14.16.3       mjf 
    509  1.14.16.3       mjf paddr_t
    510  1.14.16.3       mjf cgthree_mmap(void *v, void *vs, off_t offset, int prot)
    511  1.14.16.3       mjf {
    512  1.14.16.3       mjf 	/* I'm not at all sure this is the right thing to do */
    513  1.14.16.3       mjf 	return cgthreemmap(0, offset, prot); /* assume minor dev 0 for now */
    514  1.14.16.3       mjf }
    515  1.14.16.3       mjf 
    516  1.14.16.3       mjf int
    517  1.14.16.3       mjf cgthree_putcmap(struct cgthree_softc *sc, struct wsdisplay_cmap *cm)
    518  1.14.16.3       mjf {
    519  1.14.16.3       mjf 	u_int index = cm->index;
    520  1.14.16.3       mjf 	u_int count = cm->count;
    521  1.14.16.3       mjf 	int error,i;
    522  1.14.16.3       mjf 	if (index >= 256 || count > 256 || index + count > 256)
    523  1.14.16.3       mjf 		return EINVAL;
    524  1.14.16.3       mjf 
    525  1.14.16.3       mjf 	for (i = 0; i < count; i++)
    526  1.14.16.3       mjf 	{
    527  1.14.16.3       mjf 		error = copyin(&cm->red[i],
    528  1.14.16.3       mjf 		    &sc->sc_cmap.cm_map[index + i][0], 1);
    529  1.14.16.3       mjf 		if (error)
    530  1.14.16.3       mjf 			return error;
    531  1.14.16.3       mjf 		error = copyin(&cm->green[i],
    532  1.14.16.3       mjf 		    &sc->sc_cmap.cm_map[index + i][1],
    533  1.14.16.3       mjf 		    1);
    534  1.14.16.3       mjf 		if (error)
    535  1.14.16.3       mjf 			return error;
    536  1.14.16.3       mjf 		error = copyin(&cm->blue[i],
    537  1.14.16.3       mjf 		    &sc->sc_cmap.cm_map[index + i][2], 1);
    538  1.14.16.3       mjf 		if (error)
    539  1.14.16.3       mjf 			return error;
    540  1.14.16.3       mjf 	}
    541  1.14.16.3       mjf 	cgthreeloadcmap(sc, index, count);
    542  1.14.16.3       mjf 
    543  1.14.16.3       mjf 	return 0;
    544  1.14.16.3       mjf }
    545  1.14.16.3       mjf 
    546  1.14.16.3       mjf int
    547  1.14.16.3       mjf cgthree_getcmap(struct cgthree_softc *sc, struct wsdisplay_cmap *cm)
    548  1.14.16.3       mjf {
    549  1.14.16.3       mjf 	u_int index = cm->index;
    550  1.14.16.3       mjf 	u_int count = cm->count;
    551  1.14.16.3       mjf 	int error,i;
    552  1.14.16.3       mjf 
    553  1.14.16.3       mjf 	if (index >= 256 || count > 256 || index + count > 256)
    554  1.14.16.3       mjf 		return EINVAL;
    555  1.14.16.3       mjf 
    556  1.14.16.3       mjf 	for (i = 0; i < count; i++)
    557  1.14.16.3       mjf 	{
    558  1.14.16.3       mjf 		error = copyout(&sc->sc_cmap.cm_map[index + i][0],
    559  1.14.16.3       mjf 		    &cm->red[i], 1);
    560  1.14.16.3       mjf 		if (error)
    561  1.14.16.3       mjf 			return error;
    562  1.14.16.3       mjf 		error = copyout(&sc->sc_cmap.cm_map[index + i][1],
    563  1.14.16.3       mjf 		    &cm->green[i], 1);
    564  1.14.16.3       mjf 		if (error)
    565  1.14.16.3       mjf 			return error;
    566  1.14.16.3       mjf 		error = copyout(&sc->sc_cmap.cm_map[index + i][2],
    567  1.14.16.3       mjf 		    &cm->blue[i], 1);
    568  1.14.16.3       mjf 		if (error)
    569  1.14.16.3       mjf 			return error;
    570  1.14.16.3       mjf 	}
    571  1.14.16.3       mjf 
    572  1.14.16.3       mjf 	return 0;
    573  1.14.16.3       mjf }
    574  1.14.16.3       mjf 
    575  1.14.16.3       mjf void
    576  1.14.16.3       mjf cgthree_init_screen(void *cookie, struct vcons_screen *scr,
    577  1.14.16.3       mjf     int existing, long *defattr)
    578  1.14.16.3       mjf {
    579  1.14.16.3       mjf 	struct cgthree_softc *sc = cookie;
    580  1.14.16.3       mjf 	struct rasops_info *ri = &scr->scr_ri;
    581  1.14.16.3       mjf 
    582  1.14.16.3       mjf 	ri->ri_depth = 8;
    583  1.14.16.3       mjf 	ri->ri_width = sc->sc_width;
    584  1.14.16.3       mjf 	ri->ri_height = sc->sc_height;
    585  1.14.16.3       mjf 	ri->ri_stride = sc->sc_stride;
    586  1.14.16.3       mjf 	ri->ri_flg = RI_CENTER;
    587  1.14.16.3       mjf 
    588  1.14.16.3       mjf 	ri->ri_bits = sc->sc_fb.fb_pixels;
    589  1.14.16.3       mjf 
    590  1.14.16.3       mjf 	memset(sc->sc_fb.fb_pixels, (*defattr >> 16) & 0xff,
    591  1.14.16.3       mjf 	    sc->sc_stride * sc->sc_height);
    592  1.14.16.3       mjf 	rasops_init(ri, sc->sc_height/8, sc->sc_width/8);
    593  1.14.16.3       mjf 	ri->ri_caps = WSSCREEN_WSCOLORS | WSSCREEN_REVERSE;
    594  1.14.16.3       mjf 	rasops_reconfig(ri, sc->sc_height / ri->ri_font->fontheight,
    595  1.14.16.3       mjf 		    sc->sc_width / ri->ri_font->fontwidth);
    596  1.14.16.3       mjf 
    597  1.14.16.3       mjf 	ri->ri_hw = scr;
    598  1.14.16.3       mjf }
    599  1.14.16.3       mjf 
    600  1.14.16.3       mjf #endif /* NWSDISPLAY > 0 */
    601