Home | History | Annotate | Line # | Download | only in iomd
vidcvideo.c revision 1.5
      1 /* $NetBSD: vidcvideo.c,v 1.5 2002/03/17 19:40:33 atatat Exp $ */
      2 
      3 /*
      4  * Copyright (c) 2001 Reinoud Zandijk
      5  * Copyright (c) 1998, 1999 Tohru Nishimura.  All rights reserved.
      6  *
      7  * Redistribution and use in source and binary forms, with or without
      8  * modification, are permitted provided that the following conditions
      9  * are met:
     10  * 1. Redistributions of source code must retain the above copyright
     11  *    notice, this list of conditions and the following disclaimer.
     12  * 2. Redistributions in binary form must reproduce the above copyright
     13  *    notice, this list of conditions and the following disclaimer in the
     14  *    documentation and/or other materials provided with the distribution.
     15  * 3. All advertising materials mentioning features or use of this software
     16  *    must display the following acknowledgement:
     17  *      This product includes software developed by Tohru Nishimura
     18  *	and Reinoud Zandijk for the NetBSD Project.
     19  * 4. The name of the author may not be used to endorse or promote products
     20  *    derived from this software without specific prior written permission
     21  *
     22  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     23  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     24  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     25  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     26  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     27  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     28  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     29  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     30  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     31  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     32  *
     33  * Created vidcvideo.c from /dev/tc/cfb.c to fit the Acorn/ARM VIDC1 and VIDC20 chips
     34  *
     35  */
     36 
     37 #include <sys/cdefs.h>			/* RCS ID & Copyright macro defns */
     38 
     39 __KERNEL_RCSID(0, "$NetBSD: vidcvideo.c,v 1.5 2002/03/17 19:40:33 atatat Exp $");
     40 
     41 #include <sys/param.h>
     42 #include <sys/systm.h>
     43 #include <sys/kernel.h>
     44 #include <sys/device.h>
     45 #include <sys/malloc.h>
     46 #include <sys/buf.h>
     47 #include <sys/ioctl.h>
     48 
     49 #include <arm/mainbus/mainbus.h>
     50 #include <machine/bus.h>
     51 #include <machine/intr.h>
     52 
     53 #include <dev/wscons/wsconsio.h>
     54 #include <dev/wscons/wsdisplayvar.h>
     55 
     56 #include <dev/rasops/rasops.h>
     57 #include <dev/wsfont/wsfont.h>
     58 
     59 #include <uvm/uvm_extern.h>
     60 #include <arm/arm32/pmap.h>
     61 #include <machine/intr.h>
     62 
     63 /* for vidc_mode ... needs to be MI indepenent one day */
     64 #include <arm/iomd/vidc.h>
     65 #include <arm/iomd/vidc20config.h>
     66 #include <machine/bootconfig.h>
     67 extern videomemory_t videomemory;
     68 
     69 #define machine_btop(x) arm_byte_to_page(x)
     70 #define MACHINE_KSEG0_TO_PHYS(x) vtophys(x)
     71 
     72 /* FOR DEBUG */
     73 extern videomemory_t videomemory;
     74 
     75 struct fb_devconfig {
     76 	vaddr_t dc_vaddr;		/* memory space virtual base address */
     77 	paddr_t dc_paddr;		/* memory space physical base address */
     78 	vsize_t dc_size;		/* size of slot memory */
     79 	int	dc_wid;			/* width of frame buffer */
     80 	int	dc_ht;			/* height of frame buffer */
     81 	int	dc_log2_depth;		/* log2 of bits per pixel */
     82 	int	dc_depth;		/* depth, bits per pixel */
     83 	int	dc_rowbytes;		/* bytes in a FB scan line */
     84 	vaddr_t	dc_videobase;		/* base of flat frame buffer */
     85 	int	dc_blanked;		/* currently has video disabled */
     86 	void   *dc_hwscroll_cookie;	/* cookie for hardware scroll */
     87 
     88 	struct vidc_mode   mode_info;
     89 	struct rasops_info rinfo;
     90 };
     91 
     92 
     93 struct hwcmap256 {
     94 #define	CMAP_SIZE	256	/* 256 R/G/B entries */
     95 	u_int8_t r[CMAP_SIZE];
     96 	u_int8_t g[CMAP_SIZE];
     97 	u_int8_t b[CMAP_SIZE];
     98 };
     99 
    100 
    101 /* XXX for CURSOR_MAX_WIDTH = 32 */
    102 struct hwcursor32 {
    103 	struct wsdisplay_curpos cc_pos;
    104 	struct wsdisplay_curpos cc_hot;
    105 	struct wsdisplay_curpos cc_size;
    106 	struct wsdisplay_curpos cc_magic;
    107 	u_int8_t cc_color[6];		/* how many? */
    108 	u_int32_t cc_image[(CURSOR_MAX_WIDTH/4) * CURSOR_MAX_HEIGHT];
    109 	u_int32_t cc_mask[(CURSOR_MAX_WIDTH/4) * CURSOR_MAX_HEIGHT];
    110 };
    111 
    112 
    113 struct vidcvideo_softc {
    114 	struct device sc_dev;
    115 	struct fb_devconfig *sc_dc;	/* device configuration */
    116 	struct hwcmap256 sc_cmap;	/* software copy of colormap */
    117 	struct hwcursor32 sc_cursor;	/* software copy of cursor */
    118 	int sc_curenb;			/* cursor sprite enabled */
    119 	int sc_changed;			/* need update of hardware */
    120 #define	WSDISPLAY_CMAP_DOLUT	0x20
    121 #define WSDISPLAY_VIDEO_ONOFF	0x40
    122 	int nscreens;
    123 };
    124 
    125 
    126 /* XXX has to go XXX */
    127 #define	CX_MAGIC_X	220
    128 #define	CX_MAGIC_Y 	35
    129 #define	CX_FB_OFFSET	0x000000
    130 #define	CX_FB_SIZE	0x100000
    131 #define	CX_BT459_OFFSET	0x200000
    132 #define	CX_OFFSET_IREQ	0x300000	/* Interrupt req. control */
    133 /* XXX till here XXX */
    134 
    135 
    136 /* Function prototypes for glue */
    137 static int  vidcvideo_match __P((struct device *, struct cfdata *, void *));
    138 static void vidcvideo_attach __P((struct device *, struct device *, void *));
    139 
    140 
    141 /* config glue */
    142 const struct cfattach vidcvideo_ca = {
    143 	sizeof(struct vidcvideo_softc), vidcvideo_match, vidcvideo_attach,
    144 };
    145 
    146 
    147 static struct fb_devconfig vidcvideo_console_dc;
    148 static int vidcvideo_is_console;
    149 
    150 
    151 static struct wsscreen_descr vidcvideo_stdscreen = {
    152 	"std", 0, 0,
    153 	0, /* textops */
    154 	0, 0,
    155 	WSSCREEN_REVERSE
    156 };
    157 
    158 static const struct wsscreen_descr *_vidcvideo_scrlist[] = {
    159 	&vidcvideo_stdscreen,
    160 };
    161 
    162 static const struct wsscreen_list vidcvideo_screenlist = {
    163 	sizeof(_vidcvideo_scrlist) / sizeof(struct wsscreen_descr *), _vidcvideo_scrlist
    164 };
    165 
    166 static int	vidcvideoioctl __P((void *, u_long, caddr_t, int, struct proc *));
    167 static paddr_t	vidcvideommap __P((void *, off_t, int));
    168 
    169 static int	vidcvideo_alloc_screen __P((void *, const struct wsscreen_descr *,
    170 				      void **, int *, int *, long *));
    171 static void	vidcvideo_free_screen __P((void *, void *));
    172 static int	vidcvideo_show_screen __P((void *, void *, int,
    173 				     void (*) (void *, int, int), void *));
    174 
    175 static const struct wsdisplay_accessops vidcvideo_accessops = {
    176 	vidcvideoioctl,
    177 	vidcvideommap,
    178 	vidcvideo_alloc_screen,
    179 	vidcvideo_free_screen,
    180 	vidcvideo_show_screen,
    181 	0 /* load_font */
    182 };
    183 
    184 /* Function prototypes */
    185 int         vidcvideo_cnattach __P((vaddr_t));
    186 static void vidcvideo_colourmap_and_cursor_init __P((struct fb_devconfig *));
    187 
    188 static int  get_cmap __P((struct vidcvideo_softc *, struct wsdisplay_cmap *));
    189 static int  set_cmap __P((struct vidcvideo_softc *, struct wsdisplay_cmap *));
    190 static int  set_cursor __P((struct vidcvideo_softc *, struct wsdisplay_cursor *));
    191 static int  get_cursor __P((struct vidcvideo_softc *, struct wsdisplay_cursor *));
    192 static void set_curpos __P((struct vidcvideo_softc *, struct wsdisplay_curpos *));
    193 static void vidcvideo_getdevconfig __P((vaddr_t, struct fb_devconfig *));
    194 
    195 static int  vidcvideointr __P((void *));
    196 static void vidcvideo_config_wscons __P((struct fb_devconfig *));
    197 
    198 /* Acceleration function prototypes */
    199 static void vv_copyrows __P((void *, int, int, int));
    200 static void vv_eraserows __P((void *, int, int, long));
    201 
    202 
    203 static int
    204 vidcvideo_match(parent, match, aux)
    205 	struct device *parent;
    206 	struct cfdata *match;
    207 	void *aux;
    208 {
    209 	/* Can't probe AFAIK ; how ? */
    210 	return (1);
    211 }
    212 
    213 
    214 static void
    215 vidcvideo_getdevconfig(dense_addr, dc)
    216 	vaddr_t dense_addr;
    217 	struct fb_devconfig *dc;
    218 {
    219 	dc->dc_vaddr = dense_addr;
    220 	dc->dc_paddr = MACHINE_KSEG0_TO_PHYS(dc->dc_vaddr);
    221 
    222 	vidcvideo_getmode(&dc->mode_info);
    223 
    224 	dc->dc_wid = dc->mode_info.hder;
    225 	dc->dc_ht = dc->mode_info.vder;
    226 	dc->dc_log2_depth = dc->mode_info.log2_bpp;
    227 	dc->dc_depth = 1 << dc->dc_log2_depth;
    228 	dc->dc_videobase = dc->dc_vaddr;
    229 	dc->dc_blanked = 0;
    230 
    231 	/* this should/could be done somewhat more elegant! */
    232 	switch (dc->dc_depth) {
    233 		case 1:
    234 			dc->dc_rowbytes = dc->dc_wid / 8;
    235 			break;
    236 		case 2:
    237 			dc->dc_rowbytes = dc->dc_wid / 4;
    238 			break;
    239 		case 4:
    240 			dc->dc_rowbytes = dc->dc_wid / 2;
    241 			break;
    242 		case 8:
    243 			dc->dc_rowbytes = dc->dc_wid;
    244 			break;
    245 		case 16:
    246 			dc->dc_rowbytes = dc->dc_wid * 2;
    247 			break;
    248 		case 32:
    249 			dc->dc_rowbytes = dc->dc_wid * 4;
    250 			break;
    251 		default:
    252 			printf("Unknown colour depth %d ... what to do ?", dc->dc_depth);
    253 			break;
    254 	};
    255 
    256 	/* euhm... correct ? i.e. not complete VIDC memory */
    257 	dc->dc_size = dc->mode_info.vder * dc->dc_rowbytes;
    258 
    259 	/* initialize colormap and cursor resource */
    260 	vidcvideo_colourmap_and_cursor_init(dc);
    261 
    262 	dc->rinfo.ri_flg    = 0; /* RI_CENTER; */
    263 	dc->rinfo.ri_depth  = dc->dc_depth;
    264 	dc->rinfo.ri_bits   = (void *) dc->dc_videobase;
    265 	dc->rinfo.ri_width  = dc->dc_wid;
    266 	dc->rinfo.ri_height = dc->dc_ht;
    267 	dc->rinfo.ri_stride = dc->dc_rowbytes;
    268 	dc->rinfo.ri_hw	    = NULL;
    269 }
    270 
    271 
    272 static void
    273 vidcvideo_config_wscons(dc)
    274 	struct fb_devconfig *dc;
    275 {
    276 	int i, cookie, font_not_locked;
    277 
    278 	/* clear the screen ; why not a memset ? - it was this way so keep it for now */
    279 	for (i = 0; i < dc->dc_ht * dc->dc_rowbytes; i += sizeof(u_int32_t))
    280 		*(u_int32_t *)(dc->dc_videobase + i) = 0x0;
    281 
    282 	wsfont_init();
    283 
    284 	/* prefer 8 pixel wide font */
    285 	cookie = wsfont_find(NULL, 8, 0, 0, WSDISPLAY_FONTORDER_L2R,
    286 	    WSDISPLAY_FONTORDER_L2R);
    287 	if (cookie <= 0)
    288 		cookie = wsfont_find(NULL, 0, 0, 0, WSDISPLAY_FONTORDER_L2R,
    289 		    WSDISPLAY_FONTORDER_L2R);
    290 
    291 	if (cookie < 0) {
    292 		/* Can I even print here ? */
    293 		printf("Font table empty! exiting\n");
    294 		return;
    295 	};
    296 
    297 	font_not_locked = wsfont_lock(cookie, &dc->rinfo.ri_font);
    298 
    299 	dc->rinfo.ri_wsfcookie = cookie;
    300 
    301 	rasops_init(&dc->rinfo,
    302 		dc->rinfo.ri_height / dc->rinfo.ri_font->fontheight,
    303 		dc->rinfo.ri_width / dc->rinfo.ri_font->fontwidth
    304 	);
    305 
    306 	/* XXX add our accelerated functions */
    307 	dc->rinfo.ri_ops.eraserows = vv_eraserows;
    308 	dc->rinfo.ri_ops.copyrows  = vv_copyrows;
    309 
    310 	/* XXX shouldn't be global */
    311 	vidcvideo_stdscreen.nrows = dc->rinfo.ri_rows;
    312 	vidcvideo_stdscreen.ncols = dc->rinfo.ri_cols;
    313 	vidcvideo_stdscreen.textops = &dc->rinfo.ri_ops;
    314 	vidcvideo_stdscreen.capabilities = dc->rinfo.ri_caps;
    315 
    316 	if (font_not_locked) {
    317 		printf(" warning ... couldn't lock font! ");
    318 	};
    319 }
    320 
    321 
    322 static void
    323 vidcvideo_attach(parent, self, aux)
    324 	struct device *parent, *self;
    325 	void *aux;
    326 {
    327 	struct vidcvideo_softc *sc = (struct vidcvideo_softc *)self;
    328 	struct wsemuldisplaydev_attach_args waa;
    329 	struct hwcmap256 *cm;
    330 	const u_int8_t *p;
    331 	int index;
    332 
    333 	vidcvideo_init();
    334 	if (sc->nscreens == 0) {
    335 		if (vidcvideo_is_console) {
    336 			sc->sc_dc = &vidcvideo_console_dc;
    337 		} else {
    338 			printf(" : non console vidcvideo fb ... can't cope with this\n");
    339 			return;
    340 			/*
    341 			 * sc->sc_dc = (struct fb_devconfig *)
    342 			 *	   malloc(sizeof(struct fb_devconfig), M_DEVBUF, M_WAITOK);
    343 			 * vidcvideo_getdevconfig(videomemory.vidm_vbase, sc->sc_dc);
    344 			 */
    345 		};
    346 		sc->nscreens = 1;
    347 	} else {
    348 			printf(": allready attached ... can't cope with this\n");
    349 			return;
    350 	};
    351 
    352 	vidcvideo_printdetails();
    353 	printf(": using %d x %d, %dbpp\n", sc->sc_dc->dc_wid, sc->sc_dc->dc_ht,
    354 	    sc->sc_dc->dc_depth);
    355 
    356 	/* initialise rasops */
    357 	cm = &sc->sc_cmap;
    358 	p = rasops_cmap;
    359 	for (index = 0; index < CMAP_SIZE; index++, p += 3) {
    360 		cm->r[index] = p[0];
    361 		cm->g[index] = p[1];
    362 		cm->b[index] = p[2];
    363 	}
    364 
    365 	/* what does these do ? */
    366 	sc->sc_cursor.cc_magic.x = CX_MAGIC_X;
    367 	sc->sc_cursor.cc_magic.y = CX_MAGIC_Y;
    368 
    369 	/* set up interrupt flags */
    370 	sc->sc_changed |= WSDISPLAY_CMAP_DOLUT;
    371 
    372 	/* set up a link in the rasops structure to our softc for acceleration stuff */
    373 	sc->sc_dc->rinfo.ri_hw = sc;
    374 
    375 	/* Establish an interrupt handler, and clear any pending interrupts */
    376 	intr_claim(IRQ_FLYBACK, IPL_TTY, "vblank", vidcvideointr, sc);
    377 
    378 	waa.console = (vidcvideo_is_console ? 1 : 0);
    379 	waa.scrdata = &vidcvideo_screenlist;
    380 	waa.accessops = &vidcvideo_accessops;
    381 	waa.accesscookie = sc;
    382 
    383 	config_found(self, &waa, wsemuldisplaydevprint);
    384 }
    385 
    386 
    387 static int
    388 vidcvideoioctl(v, cmd, data, flag, p)
    389 	void *v;
    390 	u_long cmd;
    391 	caddr_t data;
    392 	int flag;
    393 	struct proc *p;
    394 {
    395 	struct vidcvideo_softc *sc = v;
    396 	struct fb_devconfig *dc = sc->sc_dc;
    397 	int state;
    398 
    399 	switch (cmd) {
    400 	case WSDISPLAYIO_GTYPE:
    401 		*(u_int *)data = WSDISPLAY_TYPE_VIDC;
    402 		return (0);
    403 
    404 	case WSDISPLAYIO_GINFO:
    405 #define	wsd_fbip ((struct wsdisplay_fbinfo *)data)
    406 		wsd_fbip->height = sc->sc_dc->dc_ht;
    407 		wsd_fbip->width = sc->sc_dc->dc_wid;
    408 		wsd_fbip->depth = sc->sc_dc->dc_depth;
    409 		wsd_fbip->cmsize = CMAP_SIZE;
    410 #undef fbt
    411 		return (0);
    412 
    413 	case WSDISPLAYIO_GETCMAP:
    414 		return get_cmap(sc, (struct wsdisplay_cmap *)data);
    415 
    416 	case WSDISPLAYIO_PUTCMAP:
    417 		return set_cmap(sc, (struct wsdisplay_cmap *)data);
    418 
    419 	case WSDISPLAYIO_SVIDEO:
    420 		state = *(int *)data;
    421 		dc->dc_blanked = (state == WSDISPLAYIO_VIDEO_OFF);
    422 		sc->sc_changed |= WSDISPLAY_VIDEO_ONOFF;
    423 		/* done on video blank */
    424 		return (0);
    425 
    426 	case WSDISPLAYIO_GVIDEO:
    427 		*(u_int *)data = dc->dc_blanked ?
    428 		    WSDISPLAYIO_VIDEO_OFF : WSDISPLAYIO_VIDEO_ON;
    429 		return (0);
    430 
    431 	case WSDISPLAYIO_GCURPOS:
    432 		*(struct wsdisplay_curpos *)data = sc->sc_cursor.cc_pos;
    433 		return (0);
    434 
    435 	case WSDISPLAYIO_SCURPOS:
    436 		set_curpos(sc, (struct wsdisplay_curpos *)data);
    437 		sc->sc_changed |= WSDISPLAY_CURSOR_DOPOS;
    438 		return (0);
    439 
    440 	case WSDISPLAYIO_GCURMAX:
    441 		((struct wsdisplay_curpos *)data)->x = CURSOR_MAX_WIDTH;
    442 		((struct wsdisplay_curpos *)data)->y = CURSOR_MAX_HEIGHT;
    443 		return (0);
    444 
    445 	case WSDISPLAYIO_GCURSOR:
    446 		return get_cursor(sc, (struct wsdisplay_cursor *)data);
    447 
    448 	case WSDISPLAYIO_SCURSOR:
    449 		return set_cursor(sc, (struct wsdisplay_cursor *)data);
    450 
    451 	case WSDISPLAYIO_SMODE:
    452 		state = *(int *)data;
    453 		if (state == WSDISPLAYIO_MODE_MAPPED) {
    454 			dc->dc_hwscroll_cookie = vidcvideo_hwscroll_reset();
    455 		};
    456 		if (state == WSDISPLAYIO_MODE_EMUL) {
    457 			vidcvideo_hwscroll_back(dc->dc_hwscroll_cookie);
    458 		};
    459 		vidcvideo_progr_scroll();
    460 		return (0);
    461 	}
    462 	return EPASSTHROUGH;
    463 }
    464 
    465 
    466 paddr_t
    467 vidcvideommap(v, offset, prot)
    468 	void *v;
    469 	off_t offset;
    470 	int prot;
    471 {
    472 	struct vidcvideo_softc *sc = v;
    473 
    474 	if (offset >= sc->sc_dc->dc_size || offset < 0)
    475 		return (-1);
    476 	return machine_btop(sc->sc_dc->dc_paddr + offset);
    477 }
    478 
    479 
    480 static int
    481 vidcvideo_alloc_screen(v, type, cookiep, curxp, curyp, attrp)
    482 	void *v;
    483 	const struct wsscreen_descr *type;
    484 	void **cookiep;
    485 	int *curxp, *curyp;
    486 	long *attrp;
    487 {
    488 	struct vidcvideo_softc *sc = v;
    489 	long defattr;
    490 
    491 	if (sc->nscreens > 0)
    492 		return (ENOMEM);
    493 
    494 	*cookiep = &sc->sc_dc->rinfo; /* one and only for now */
    495 	*curxp = 0;
    496 	*curyp = 0;
    497 	(*sc->sc_dc->rinfo.ri_ops.alloc_attr)(&sc->sc_dc->rinfo, 0, 0, 0, &defattr);
    498 	*attrp = defattr;
    499 	sc->nscreens++;
    500 	return (0);
    501 }
    502 
    503 
    504 static void
    505 vidcvideo_free_screen(v, cookie)
    506 	void *v;
    507 	void *cookie;
    508 {
    509 	struct vidcvideo_softc *sc = v;
    510 
    511 	if (sc->sc_dc == &vidcvideo_console_dc)
    512 		panic("vidcvideo_free_screen: console");
    513 
    514 	sc->nscreens--;
    515 }
    516 
    517 
    518 static int
    519 vidcvideo_show_screen(v, cookie, waitok, cb, cbarg)
    520 	void *v;
    521 	void *cookie;
    522 	int waitok;
    523 	void (*cb) __P((void *, int, int));
    524 	void *cbarg;
    525 {
    526 
    527 	return (0);
    528 }
    529 
    530 
    531 /* EXPORT */ int
    532 vidcvideo_cnattach(addr)
    533 	vaddr_t addr;
    534 {
    535 	struct fb_devconfig *dcp = &vidcvideo_console_dc;
    536 	long defattr;
    537 
    538 	vidcvideo_init();
    539 	vidcvideo_getdevconfig(addr, dcp);
    540 	vidcvideo_config_wscons(dcp);
    541 	(*dcp->rinfo.ri_ops.alloc_attr)(&dcp->rinfo, 0, 0, 0, &defattr);
    542 	wsdisplay_cnattach(&vidcvideo_stdscreen, &dcp->rinfo, 0, 0, defattr);
    543 
    544 	vidcvideo_is_console = 1;
    545 	return(0);
    546 }
    547 
    548 
    549 static int
    550 vidcvideointr(arg)
    551 	void *arg;
    552 {
    553 	struct vidcvideo_softc *sc = arg;
    554 	int v;
    555 
    556 	v = sc->sc_changed;
    557 	if (v == 0)
    558 		return (1);
    559 
    560 	if (v & WSDISPLAY_CMAP_DOLUT) {
    561 		struct hwcmap256 *cm = &sc->sc_cmap;
    562 		int index;
    563 
    564 		if (sc->sc_dc->dc_depth == 4) {
    565 			/* palette for 4 bpp is different from 8bpp */
    566 			vidcvideo_write(VIDC_PALREG, 0x00000000);
    567 			for (index=0; index < 1<<sc->sc_dc->dc_depth; index++)
    568 				vidcvideo_write(VIDC_PALETTE,
    569 					VIDC_COL(cm->r[index],
    570 						 cm->g[index],
    571 						 cm->b[index]));
    572 			;
    573 		};
    574 
    575 		if (sc->sc_dc->dc_depth == 8) {
    576 			/* XXX dunno what to do in less than 8bpp */
    577 			/* palettes only make sense in 8bpp and less modes on VIDC */
    578 			vidcvideo_write(VIDC_PALREG, 0x00000000);
    579 			for (index = 0; index < CMAP_SIZE; index++) {
    580 				vidcvideo_write(VIDC_PALETTE,
    581 					VIDC_COL(cm->r[index], cm->g[index], cm->b[index])
    582 		 		);
    583 			};
    584 		};
    585 	}
    586 
    587 	if (v & WSDISPLAY_VIDEO_ONOFF) {
    588 		vidcvideo_blank(sc->sc_dc->dc_blanked);
    589 	};
    590 
    591 	if (v & (WSDISPLAY_CURSOR_DOPOS | WSDISPLAY_CURSOR_DOHOT)) {
    592 		int x, y;
    593 		x = sc->sc_cursor.cc_pos.x - sc->sc_cursor.cc_hot.x;
    594 		y = sc->sc_cursor.cc_pos.y - sc->sc_cursor.cc_hot.y;
    595 
    596 		vidcvideo_updatecursor(x, y);
    597 	};
    598 
    599 	if (v & WSDISPLAY_CURSOR_DOCUR) {
    600 		vidcvideo_enablecursor(sc->sc_curenb);
    601 	};
    602 
    603 
    604 #if 0	/* XXX snip XXX */
    605 	/* XXX kept here as an archive for now XXX */
    606 
    607 	vdac = vidcvideobase + CX_BT459_OFFSET;
    608 	v = sc->sc_changed;
    609 	if (v & WSDISPLAY_CURSOR_DOCUR) {
    610 		SELECT(vdac, BT459_IREG_CCR);
    611 		REG(vdac, bt_reg) = (sc->sc_curenb) ? 0xc0 : 0x00;
    612 	}
    613 	if (v & (WSDISPLAY_CURSOR_DOPOS | WSDISPLAY_CURSOR_DOHOT)) {
    614 		int x, y;
    615 
    616 		x = sc->sc_cursor.cc_pos.x - sc->sc_cursor.cc_hot.x;
    617 		y = sc->sc_cursor.cc_pos.y - sc->sc_cursor.cc_hot.y;
    618 
    619 		x += sc->sc_cursor.cc_magic.x;
    620 		y += sc->sc_cursor.cc_magic.y;
    621 
    622 		SELECT(vdac, BT459_IREG_CURSOR_X_LOW);
    623 		REG(vdac, bt_reg) = x;		tc_wmb();
    624 		REG(vdac, bt_reg) = x >> 8;	tc_wmb();
    625 		REG(vdac, bt_reg) = y;		tc_wmb();
    626 		REG(vdac, bt_reg) = y >> 8;	tc_wmb();
    627 	}
    628 	if (v & WSDISPLAY_CURSOR_DOCMAP) {
    629 		u_int8_t *cp = sc->sc_cursor.cc_color;
    630 
    631 		SELECT(vdac, BT459_IREG_CCOLOR_2);
    632 		REG(vdac, bt_reg) = cp[1];	tc_wmb();
    633 		REG(vdac, bt_reg) = cp[3];	tc_wmb();
    634 		REG(vdac, bt_reg) = cp[5];	tc_wmb();
    635 
    636 		REG(vdac, bt_reg) = cp[0];	tc_wmb();
    637 		REG(vdac, bt_reg) = cp[2];	tc_wmb();
    638 		REG(vdac, bt_reg) = cp[4];	tc_wmb();
    639 	}
    640 	if (v & WSDISPLAY_CURSOR_DOSHAPE) {
    641 		u_int8_t *ip, *mp, img, msk;
    642 		u_int8_t u;
    643 		int bcnt;
    644 
    645 		ip = (u_int8_t *)sc->sc_cursor.cc_image;
    646 		mp = (u_int8_t *)(sc->sc_cursor.cc_image + CURSOR_MAX_HEIGHT);
    647 
    648 		bcnt = 0;
    649 		SELECT(vdac, BT459_IREG_CRAM_BASE+0);
    650 		/* 64 pixel scan line is consisted with 16 byte cursor ram */
    651 		while (bcnt < sc->sc_cursor.cc_size.y * 16) {
    652 			/* pad right half 32 pixel when smaller than 33 */
    653 			if ((bcnt & 0x8) && sc->sc_cursor.cc_size.x < 33) {
    654 				REG(vdac, bt_reg) = 0; tc_wmb();
    655 				REG(vdac, bt_reg) = 0; tc_wmb();
    656 			}
    657 			else {
    658 				img = *ip++;
    659 				msk = *mp++;
    660 				img &= msk;	/* cookie off image */
    661 				u = (msk & 0x0f) << 4 | (img & 0x0f);
    662 				REG(vdac, bt_reg) = shuffle[u];	tc_wmb();
    663 				u = (msk & 0xf0) | (img & 0xf0) >> 4;
    664 				REG(vdac, bt_reg) = shuffle[u];	tc_wmb();
    665 			}
    666 			bcnt += 2;
    667 		}
    668 		/* pad unoccupied scan lines */
    669 		while (bcnt < CURSOR_MAX_HEIGHT * 16) {
    670 			REG(vdac, bt_reg) = 0; tc_wmb();
    671 			REG(vdac, bt_reg) = 0; tc_wmb();
    672 			bcnt += 2;
    673 		}
    674 	}
    675 #endif /* XXX snip XXX */
    676 
    677 	sc->sc_changed = 0;
    678 	return (1);
    679 }
    680 
    681 
    682 static u_char ri_col_data[6][6] = {
    683 	{ 0,  0,  0,   0,  0,  0},	/*  1 bpp */
    684 	{ 0,  0,  0,   0,  0,  0},	/*  2 bpp */
    685 	{ 0,  0,  0,   0,  0,  0},	/*  4 bpp */
    686 	{ 0,  0,  0,   0,  0,  0},	/*  8 bpp */
    687 	{ 5,  5,  5,   0,  5, 10},	/* 16 bpp */
    688 	{ 8,  8,  8,   0,  8, 16},	/* 32 bpp */
    689 };
    690 
    691 static void
    692 vidcvideo_colourmap_and_cursor_init(dc)
    693 	struct fb_devconfig *dc;
    694 {
    695 	struct rasops_info *ri = &dc->rinfo;
    696 	u_char *rgbdat;
    697 
    698 	/* Whatever we do later... just make sure we have a
    699 	 * sane palette to start with
    700 	 */
    701 	vidcvideo_stdpalette();
    702 
    703 	/* set up rgb bit pattern values for rasops_init */
    704 	rgbdat = ri_col_data[dc->dc_log2_depth];
    705 	ri->ri_rnum = rgbdat[0];
    706 	ri->ri_gnum = rgbdat[1];
    707 	ri->ri_bnum = rgbdat[2];
    708 	ri->ri_rpos = rgbdat[3];
    709 	ri->ri_gpos = rgbdat[4];
    710 	ri->ri_bpos = rgbdat[5];
    711 
    712 }
    713 
    714 
    715 static int
    716 get_cmap(sc, p)
    717 	struct vidcvideo_softc *sc;
    718 	struct wsdisplay_cmap *p;
    719 {
    720 	u_int index = p->index, count = p->count;
    721 
    722 	if (index >= CMAP_SIZE || (index + count) > CMAP_SIZE)
    723 		return (EINVAL);
    724 
    725 	if (!uvm_useracc(p->red, count, B_WRITE) ||
    726 	    !uvm_useracc(p->green, count, B_WRITE) ||
    727 	    !uvm_useracc(p->blue, count, B_WRITE))
    728 		return (EFAULT);
    729 
    730 	copyout(&sc->sc_cmap.r[index], p->red, count);
    731 	copyout(&sc->sc_cmap.g[index], p->green, count);
    732 	copyout(&sc->sc_cmap.b[index], p->blue, count);
    733 
    734 	return (0);
    735 }
    736 
    737 
    738 static int
    739 set_cmap(sc, p)
    740 	struct vidcvideo_softc *sc;
    741 	struct wsdisplay_cmap *p;
    742 {
    743 	u_int index = p->index, count = p->count;
    744 
    745 	if (index >= CMAP_SIZE || (index + count) > CMAP_SIZE)
    746 		return (EINVAL);
    747 
    748 	if (!uvm_useracc(p->red, count, B_READ) ||
    749 	    !uvm_useracc(p->green, count, B_READ) ||
    750 	    !uvm_useracc(p->blue, count, B_READ))
    751 		return (EFAULT);
    752 
    753 	copyin(p->red, &sc->sc_cmap.r[index], count);
    754 	copyin(p->green, &sc->sc_cmap.g[index], count);
    755 	copyin(p->blue, &sc->sc_cmap.b[index], count);
    756 	sc->sc_changed |= WSDISPLAY_CMAP_DOLUT;
    757 	return (0);
    758 }
    759 
    760 
    761 static int
    762 set_cursor(sc, p)
    763 	struct vidcvideo_softc *sc;
    764 	struct wsdisplay_cursor *p;
    765 {
    766 #define	cc (&sc->sc_cursor)
    767 	u_int v, index, count, icount;
    768 
    769 	v = p->which;
    770 	if (v & WSDISPLAY_CURSOR_DOCMAP) {
    771 		index = p->cmap.index;
    772 		count = p->cmap.count;
    773 		if (index >= CURSOR_MAX_COLOURS || (index + count) > CURSOR_MAX_COLOURS)
    774 			return (EINVAL);
    775 		if (!uvm_useracc(p->cmap.red, count, B_READ) ||
    776 		    !uvm_useracc(p->cmap.green, count, B_READ) ||
    777 		    !uvm_useracc(p->cmap.blue, count, B_READ))
    778 			return (EFAULT);
    779 	}
    780 	if (v & WSDISPLAY_CURSOR_DOSHAPE) {
    781 		if (p->size.x > CURSOR_MAX_WIDTH || p->size.y > CURSOR_MAX_HEIGHT)
    782 			return (EINVAL);
    783 		icount = sizeof(u_int32_t) * p->size.y;
    784 		if (!uvm_useracc(p->image, icount, B_READ) ||
    785 		    !uvm_useracc(p->mask, icount, B_READ))
    786 			return (EFAULT);
    787 	}
    788 
    789 	if (v & WSDISPLAY_CURSOR_DOCUR)
    790 		sc->sc_curenb = p->enable;
    791 	if (v & WSDISPLAY_CURSOR_DOPOS)
    792 		set_curpos(sc, &p->pos);
    793 	if (v & WSDISPLAY_CURSOR_DOHOT)
    794 		cc->cc_hot = p->hot;
    795 	if (v & WSDISPLAY_CURSOR_DOCMAP) {
    796 		copyin(p->cmap.red, &cc->cc_color[index], count);
    797 		copyin(p->cmap.green, &cc->cc_color[index + 2], count);
    798 		copyin(p->cmap.blue, &cc->cc_color[index + 4], count);
    799 	}
    800 	if (v & WSDISPLAY_CURSOR_DOSHAPE) {
    801 		cc->cc_size = p->size;
    802 		memset(cc->cc_image, 0, sizeof cc->cc_image);
    803 		memset(cc->cc_mask, 0, sizeof cc->cc_mask);
    804 		copyin(p->image, cc->cc_image, icount);
    805 		copyin(p->mask, cc->cc_mask, icount);
    806 	}
    807 	sc->sc_changed |= v;
    808 
    809 	return (0);
    810 #undef cc
    811 }
    812 
    813 
    814 static int
    815 get_cursor(sc, p)
    816 	struct vidcvideo_softc *sc;
    817 	struct wsdisplay_cursor *p;
    818 {
    819 	return (EPASSTHROUGH); /* XXX */
    820 }
    821 
    822 
    823 static void
    824 set_curpos(sc, curpos)
    825 	struct vidcvideo_softc *sc;
    826 	struct wsdisplay_curpos *curpos;
    827 {
    828 	struct fb_devconfig *dc = sc->sc_dc;
    829 	int x = curpos->x, y = curpos->y;
    830 
    831 	if (y < 0)
    832 		y = 0;
    833 	else if (y > dc->dc_ht)
    834 		y = dc->dc_ht;
    835 	if (x < 0)
    836 		x = 0;
    837 	else if (x > dc->dc_wid)
    838 		x = dc->dc_wid;
    839 	sc->sc_cursor.cc_pos.x = x;
    840 	sc->sc_cursor.cc_pos.y = y;
    841 }
    842 
    843 
    844 static void vv_copyrows(id, srcrow, dstrow, nrows)
    845 	void *id;
    846 	int srcrow, dstrow, nrows;
    847 {
    848 	struct rasops_info *ri = id;
    849 	int height, offset, size;
    850 	int scrollup, scrolldown;
    851 	unsigned char *src, *dst;
    852 
    853 	/* All movements are done in multiples of character heigths */
    854 	height = ri->ri_font->fontheight * nrows;
    855 	offset = (srcrow - dstrow) * ri->ri_yscale;
    856 	size   = height * ri->ri_stride;
    857 
    858 	/* check if we are full screen scrolling */
    859 	scrollup   = (srcrow + nrows >= ri->ri_rows);
    860 	scrolldown = (dstrow + nrows >= ri->ri_rows);
    861 
    862 	if ((scrollup || scrolldown) && (videomemory.vidm_type == VIDEOMEM_TYPE_VRAM)) {
    863 		ri->ri_bits = vidcvideo_hwscroll(offset);
    864 		vidcvideo_progr_scroll();	/* sadistic ; shouldnt this be on vsync? */
    865 
    866 		/* wipe out remains of the screen if nessisary */
    867 		if (ri->ri_emuheight != ri->ri_height) vv_eraserows(id, ri->ri_rows, 1, NULL);
    868 		return;
    869 	};
    870 
    871 	/* Else we just copy the area : we're braindead for now
    872 	 * Note: we can't use hardware scrolling when the softc isnt known yet...
    873 	 * if its not known we dont have interrupts and we can't change the display
    874 	 * address reliable other than in a Vsync
    875 	 */
    876 
    877 	src = ri->ri_bits + srcrow * ri->ri_font->fontheight * ri->ri_stride;
    878 	dst = ri->ri_bits + dstrow * ri->ri_font->fontheight * ri->ri_stride;
    879 
    880 	bcopy(src, dst, size);
    881 }
    882 
    883 
    884 static void vv_eraserows(id, startrow, nrows, attr)
    885 	void *id;
    886 	int startrow, nrows;
    887 	long attr;
    888 {
    889 	struct rasops_info *ri = id;
    890 	int height;
    891 	unsigned char *src;
    892 
    893 	/* we're braindead for now */
    894 	height = ri->ri_font->fontheight * nrows * ri->ri_stride;
    895 
    896 	src = ri->ri_bits + startrow * ri->ri_font->fontheight * ri->ri_stride;
    897 
    898 	bzero(src, height);
    899 }
    900 
    901