Home | History | Annotate | Line # | Download | only in iomd
vidcvideo.c revision 1.28.2.1
      1 /* $NetBSD: vidcvideo.c,v 1.28.2.1 2006/11/18 21:29:07 ad 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.28.2.1 2006/11/18 21:29:07 ad 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 <arm/cpufunc.h>
     62 #include <machine/intr.h>
     63 
     64 /* for vidc_mode ... needs to be MI indepenent one day */
     65 #include <arm/iomd/vidc.h>
     66 #include <arm/iomd/vidc20config.h>
     67 #include <arm/iomd/vidcvideo.h>
     68 #include <machine/bootconfig.h>
     69 
     70 /* FOR DEBUG */
     71 extern videomemory_t videomemory;
     72 
     73 struct hwcmap256 {
     74 #define	CMAP_SIZE	256	/* 256 R/G/B entries */
     75 	u_int8_t r[CMAP_SIZE];
     76 	u_int8_t g[CMAP_SIZE];
     77 	u_int8_t b[CMAP_SIZE];
     78 };
     79 
     80 
     81 /* XXX for CURSOR_MAX_WIDTH = 32 */
     82 struct hwcursor32 {
     83 	struct wsdisplay_curpos cc_pos;
     84 	struct wsdisplay_curpos cc_hot;
     85 	struct wsdisplay_curpos cc_size;
     86 	u_int8_t cc_color[6];		/* how many? */
     87 	u_int32_t cc_image[(CURSOR_MAX_WIDTH/4) * CURSOR_MAX_HEIGHT];
     88 	u_int32_t cc_mask[(CURSOR_MAX_WIDTH/4) * CURSOR_MAX_HEIGHT];
     89 };
     90 
     91 
     92 struct fb_devconfig {
     93 	vaddr_t dc_vaddr;		/* memory space virtual base address */
     94 	paddr_t dc_paddr;		/* memory space physical base address */
     95 	vsize_t dc_size;		/* size of slot memory */
     96 	int	dc_wid;			/* width of frame buffer */
     97 	int	dc_ht;			/* height of frame buffer */
     98 	int	dc_log2_depth;		/* log2 of bits per pixel */
     99 	int	dc_depth;		/* depth, bits per pixel */
    100 	int	dc_rowbytes;		/* bytes in a FB scan line */
    101 	vaddr_t	dc_videobase;		/* base of flat frame buffer */
    102 	int	dc_blanked;		/* currently has video disabled */
    103 	void   *dc_hwscroll_cookie;	/* cookie for hardware scroll */
    104 
    105 	int	dc_curenb;		/* is cursor sprite enabled ?	*/
    106 	int	dc_changed;		/* need update of hardware	*/
    107 	int	dc_writeback_delay;	/* Screenarea write back vsync counter */
    108 #define	WSDISPLAY_CMAP_DOLUT	0x20
    109 #define WSDISPLAY_VIDEO_ONOFF	0x40
    110 #define WSDISPLAY_WB_COUNTER	0x80
    111 
    112 	struct hwcmap256	dc_cmap;/* software copy of colormap	*/
    113 	struct hwcursor32	dc_cursor;/* software copy of cursor	*/
    114 
    115 	struct vidc_mode	mode_info;
    116 	struct rasops_info	rinfo;
    117 
    118 	struct wsdisplay_emulops orig_ri_ops;	/* Rasops functions for deligation */
    119 };
    120 
    121 
    122 struct vidcvideo_softc {
    123 	struct device sc_dev;
    124 	struct fb_devconfig *sc_dc;	/* device configuration		*/
    125 	int nscreens;			/* number of screens configured */
    126 };
    127 
    128 
    129 /* Function prototypes for glue */
    130 static int  vidcvideo_match(struct device *, struct cfdata *, void *);
    131 static void vidcvideo_attach(struct device *, struct device *, void *);
    132 
    133 
    134 /* config glue */
    135 CFATTACH_DECL(vidcvideo, sizeof(struct vidcvideo_softc),
    136     vidcvideo_match, vidcvideo_attach, NULL, NULL);
    137 
    138 static struct fb_devconfig vidcvideo_console_dc;
    139 static int vidcvideo_is_console;
    140 
    141 
    142 static struct wsscreen_descr vidcvideo_stdscreen = {
    143 	"std", 0, 0,
    144 	0, /* textops */
    145 	0, 0,
    146 	WSSCREEN_REVERSE
    147 };
    148 
    149 static const struct wsscreen_descr *_vidcvideo_scrlist[] = {
    150 	&vidcvideo_stdscreen,
    151 };
    152 
    153 static const struct wsscreen_list vidcvideo_screenlist = {
    154 	sizeof(_vidcvideo_scrlist) / sizeof(struct wsscreen_descr *),
    155 	_vidcvideo_scrlist
    156 };
    157 
    158 static int	vidcvideoioctl(void *, void *, u_long, caddr_t, int,
    159     struct lwp *);
    160 static paddr_t	vidcvideommap(void *, void *, off_t, int);
    161 
    162 static int	vidcvideo_alloc_screen(void *, const struct wsscreen_descr *,
    163     void **, int *, int *, long *);
    164 static void	vidcvideo_free_screen(void *, void *);
    165 static int	vidcvideo_show_screen(void *, void *, int,
    166 				     void (*) (void *, int, int), void *);
    167 
    168 static const struct wsdisplay_accessops vidcvideo_accessops = {
    169 	vidcvideoioctl,
    170 	vidcvideommap,
    171 	vidcvideo_alloc_screen,
    172 	vidcvideo_free_screen,
    173 	vidcvideo_show_screen,
    174 	NULL, /* load_font	*/
    175 	NULL  /* pollc		*/
    176 };
    177 
    178 
    179 /* Function prototypes */
    180 int         vidcvideo_cnattach(vaddr_t);
    181 static void vidcvideo_colourmap_and_cursor_init(struct fb_devconfig *);
    182 
    183 static int  get_cmap(struct vidcvideo_softc *, struct wsdisplay_cmap *);
    184 static int  set_cmap(struct vidcvideo_softc *, struct wsdisplay_cmap *);
    185 static int  set_cursor(struct vidcvideo_softc *, struct wsdisplay_cursor *);
    186 static int  get_cursor(struct vidcvideo_softc *, struct wsdisplay_cursor *);
    187 static void set_curpos(struct vidcvideo_softc *, struct wsdisplay_curpos *);
    188 static void vidcvideo_getdevconfig(vaddr_t, struct fb_devconfig *);
    189 
    190 static int  vidcvideointr(void *);
    191 static void vidcvideo_config_wscons(struct fb_devconfig *);
    192 
    193 
    194 /* Acceleration function prototypes */
    195 static void vv_copyrows(void *, int, int, int);
    196 static void vv_eraserows(void *, int, int, long);
    197 static void vv_putchar(void *c, int row, int col, u_int uc, long attr);
    198 
    199 
    200 static int
    201 vidcvideo_match(parent, match, aux)
    202 	struct device *parent;
    203 	struct cfdata *match;
    204 	void *aux;
    205 {
    206 
    207 	/* Can't probe AFAIK ; how ? */
    208 	return 1;
    209 }
    210 
    211 
    212 static void
    213 vidcvideo_getdevconfig(vaddr_t dense_addr, struct fb_devconfig *dc)
    214 {
    215 
    216 	dc->dc_vaddr = dense_addr;
    217 	(void) pmap_extract(pmap_kernel(), dc->dc_vaddr, &(dc->dc_paddr));
    218 
    219 	vidcvideo_getmode(&dc->mode_info);
    220 
    221 	dc->dc_wid = dc->mode_info.timings.hdisplay;
    222 	dc->dc_ht = dc->mode_info.timings.vdisplay;
    223 	dc->dc_log2_depth = dc->mode_info.log2_bpp;
    224 	dc->dc_depth = 1 << dc->dc_log2_depth;
    225 	dc->dc_videobase = dc->dc_vaddr;
    226 	dc->dc_blanked = 0;
    227 
    228 	/* this should/could be done somewhat more elegant! */
    229 	switch (dc->dc_depth) {
    230 		case 1:
    231 			dc->dc_rowbytes = dc->dc_wid / 8;
    232 			break;
    233 		case 2:
    234 			dc->dc_rowbytes = dc->dc_wid / 4;
    235 			break;
    236 		case 4:
    237 			dc->dc_rowbytes = dc->dc_wid / 2;
    238 			break;
    239 		case 8:
    240 			dc->dc_rowbytes = dc->dc_wid;
    241 			break;
    242 		case 16:
    243 			dc->dc_rowbytes = dc->dc_wid * 2;
    244 			break;
    245 		case 32:
    246 			dc->dc_rowbytes = dc->dc_wid * 4;
    247 			break;
    248 		default:
    249 			printf("Unknown colour depth %d ... what to do ?", dc->dc_depth);
    250 			break;
    251 	}
    252 
    253 	/* euhm... correct ? i.e. not complete VIDC memory */
    254 	dc->dc_size = dc->mode_info.timings.vdisplay * dc->dc_rowbytes;
    255 
    256 	/* initialize colormap and cursor resource */
    257 	vidcvideo_colourmap_and_cursor_init(dc);
    258 
    259 	dc->rinfo.ri_flg    = 0; /* RI_CENTER; */
    260 	dc->rinfo.ri_depth  = dc->dc_depth;
    261 	dc->rinfo.ri_bits   = (void *) dc->dc_videobase;
    262 	dc->rinfo.ri_width  = dc->dc_wid;
    263 	dc->rinfo.ri_height = dc->dc_ht;
    264 	dc->rinfo.ri_stride = dc->dc_rowbytes;
    265 	dc->rinfo.ri_hw	    = dc;		/* link back */
    266 
    267 	/* intitialise miscelanious */
    268 	dc->dc_writeback_delay = 0;
    269 }
    270 
    271 
    272 static void
    273 vidcvideo_config_wscons(struct fb_devconfig *dc)
    274 {
    275 	int i, cookie, font_not_locked;
    276 
    277 	/*
    278 	 * clear the screen ; why not a memset ? - it was this way so
    279 	 * keep it for now
    280 	 */
    281 	for (i = 0; i < dc->dc_ht * dc->dc_rowbytes; i += sizeof(u_int32_t))
    282 		*(u_int32_t *)(dc->dc_videobase + i) = 0x0;
    283 
    284 	wsfont_init();
    285 
    286 	/* prefer 8 pixel wide font */
    287 	cookie = wsfont_find(NULL, 8, 0, 0, WSDISPLAY_FONTORDER_L2R,
    288 	    WSDISPLAY_FONTORDER_L2R);
    289 	if (cookie <= 0)
    290 		cookie = wsfont_find(NULL, 0, 0, 0, WSDISPLAY_FONTORDER_L2R,
    291 		    WSDISPLAY_FONTORDER_L2R);
    292 
    293 	if (cookie < 0) {
    294 		/* Can I even print here ? */
    295 		printf("Font table empty! exiting\n");
    296 		return;
    297 	}
    298 
    299 	font_not_locked = wsfont_lock(cookie, &dc->rinfo.ri_font);
    300 
    301 	dc->rinfo.ri_wsfcookie = cookie;
    302 
    303 	rasops_init(&dc->rinfo,
    304 	    dc->rinfo.ri_height / dc->rinfo.ri_font->fontheight,
    305 	    dc->rinfo.ri_width / dc->rinfo.ri_font->fontwidth);
    306 
    307 	/*
    308 	 * Provide a hook for the acceleration functions and make a copy of the
    309 	 * original rasops functions for passing on calls
    310 	 */
    311 	dc->rinfo.ri_hw = dc;
    312 	memcpy(&(dc->orig_ri_ops), &(dc->rinfo.ri_ops),
    313 	    sizeof(struct wsdisplay_emulops));
    314 
    315 	/* add our accelerated functions */
    316 	dc->rinfo.ri_ops.eraserows = vv_eraserows;
    317 	dc->rinfo.ri_ops.copyrows  = vv_copyrows;
    318 
    319 	/* add the extra activity measuring functions; they just delegate on */
    320 	dc->rinfo.ri_ops.putchar   = vv_putchar;
    321 
    322 	/* XXX shouldn't be global */
    323 	vidcvideo_stdscreen.nrows = dc->rinfo.ri_rows;
    324 	vidcvideo_stdscreen.ncols = dc->rinfo.ri_cols;
    325 	vidcvideo_stdscreen.textops = &dc->rinfo.ri_ops;
    326 	vidcvideo_stdscreen.capabilities = dc->rinfo.ri_caps;
    327 
    328 	if (font_not_locked)
    329 		printf(" warning ... couldn't lock font! ");
    330 }
    331 
    332 
    333 static void
    334 vidcvideo_attach(struct device *parent, struct device *self, void *aux)
    335 {
    336 	struct vidcvideo_softc *sc = (struct vidcvideo_softc *)self;
    337 	struct fb_devconfig *dc;
    338 	struct wsemuldisplaydev_attach_args waa;
    339 	struct hwcmap256 *cm;
    340 	const u_int8_t *p;
    341 	long defattr;
    342 	int index;
    343 
    344 	vidcvideo_init();
    345 	if (sc->nscreens == 0) {
    346 		sc->sc_dc = &vidcvideo_console_dc;
    347 		if (!vidcvideo_is_console) {
    348 			printf(" : non console (no kbd yet) ");
    349 			vidcvideo_getdevconfig(videomemory.vidm_vbase, sc->sc_dc);
    350 			vidcvideo_config_wscons(sc->sc_dc);
    351 			(*sc->sc_dc->rinfo.ri_ops.allocattr)(&sc->sc_dc->rinfo, 0, 0, 0, &defattr);
    352 		}
    353 		sc->nscreens = 1;
    354 	} else {
    355 			printf(": already attached ... can't cope with this\n");
    356 			return;
    357 	}
    358 
    359 	dc = sc->sc_dc;
    360 
    361 	vidcvideo_printdetails();
    362 	printf(": mode %s, %dbpp\n", dc->mode_info.timings.name,
    363 	    dc->dc_depth);
    364 
    365 	/* initialise rasops */
    366 	cm = &dc->dc_cmap;
    367 	p = rasops_cmap;
    368 	for (index = 0; index < CMAP_SIZE; index++, p += 3) {
    369 		cm->r[index] = p[0];
    370 		cm->g[index] = p[1];
    371 		cm->b[index] = p[2];
    372 	}
    373 
    374 	/* set up interrupt flags */
    375 	dc->dc_changed |= WSDISPLAY_CMAP_DOLUT;
    376 
    377 	/*
    378 	 * Set up a link in the rasops structure to our device config
    379 	 * for acceleration stuff
    380 	 */
    381 	dc->rinfo.ri_hw = sc->sc_dc;
    382 
    383 	/* Establish an interrupt handler, and clear any pending interrupts */
    384 	intr_claim(IRQ_FLYBACK, IPL_TTY, "vblank", vidcvideointr, dc);
    385 
    386 	waa.console = (vidcvideo_is_console ? 1 : 0);
    387 	waa.scrdata = &vidcvideo_screenlist;
    388 	waa.accessops = &vidcvideo_accessops;
    389 	waa.accesscookie = sc;
    390 
    391 	config_found(self, &waa, wsemuldisplaydevprint);
    392 }
    393 
    394 
    395 static int
    396 vidcvideoioctl(void *v, void *vs, u_long cmd, caddr_t data, int flag,
    397     struct lwp *l)
    398 {
    399 	struct vidcvideo_softc *sc = v;
    400 	struct fb_devconfig *dc = sc->sc_dc;
    401 	int state;
    402 
    403 	switch (cmd) {
    404 	case WSDISPLAYIO_GTYPE:
    405 		*(u_int *)data = WSDISPLAY_TYPE_VIDC;
    406 		return 0;
    407 
    408 	case WSDISPLAYIO_GINFO:
    409 #define	wsd_fbip ((struct wsdisplay_fbinfo *)data)
    410 		wsd_fbip->height = dc->dc_ht;
    411 		wsd_fbip->width  = dc->dc_wid;
    412 		wsd_fbip->depth  = dc->dc_depth;
    413 		wsd_fbip->cmsize = CMAP_SIZE;
    414 #undef fbt
    415 		return 0;
    416 
    417 	case WSDISPLAYIO_GETCMAP:
    418 		return get_cmap(sc, (struct wsdisplay_cmap *)data);
    419 
    420 	case WSDISPLAYIO_PUTCMAP:
    421 		return set_cmap(sc, (struct wsdisplay_cmap *)data);
    422 
    423 	case WSDISPLAYIO_SVIDEO:
    424 		state = *(int *)data;
    425 		dc->dc_blanked = (state == WSDISPLAYIO_VIDEO_OFF);
    426 		dc->dc_changed |= WSDISPLAY_VIDEO_ONOFF;
    427 		/* done on video blank */
    428 		return 0;
    429 
    430 	case WSDISPLAYIO_GVIDEO:
    431 		*(u_int *)data = dc->dc_blanked ?
    432 		    WSDISPLAYIO_VIDEO_OFF : WSDISPLAYIO_VIDEO_ON;
    433 		return 0;
    434 
    435 	case WSDISPLAYIO_GCURPOS:
    436 		*(struct wsdisplay_curpos *)data = dc->dc_cursor.cc_pos;
    437 		return 0;
    438 
    439 	case WSDISPLAYIO_SCURPOS:
    440 		set_curpos(sc, (struct wsdisplay_curpos *)data);
    441 		dc->dc_changed |= WSDISPLAY_CURSOR_DOPOS;
    442 		return 0;
    443 
    444 	case WSDISPLAYIO_GCURMAX:
    445 		((struct wsdisplay_curpos *)data)->x = CURSOR_MAX_WIDTH;
    446 		((struct wsdisplay_curpos *)data)->y = CURSOR_MAX_HEIGHT;
    447 		return 0;
    448 
    449 	case WSDISPLAYIO_GCURSOR:
    450 		return get_cursor(sc, (struct wsdisplay_cursor *)data);
    451 
    452 	case WSDISPLAYIO_SCURSOR:
    453 		return set_cursor(sc, (struct wsdisplay_cursor *)data);
    454 
    455 	case WSDISPLAYIO_SMODE:
    456 		state = *(int *)data;
    457 		if (state == WSDISPLAYIO_MODE_MAPPED)
    458 			dc->dc_hwscroll_cookie = vidcvideo_hwscroll_reset();
    459 		if (state == WSDISPLAYIO_MODE_EMUL)
    460 			vidcvideo_hwscroll_back(dc->dc_hwscroll_cookie);
    461 		vidcvideo_progr_scroll();
    462 
    463 		return 0;
    464 	}
    465 	return EPASSTHROUGH;
    466 }
    467 
    468 
    469 paddr_t
    470 vidcvideommap(void *v, void *vs, off_t offset, int prot)
    471 {
    472 	struct vidcvideo_softc *sc = v;
    473 
    474 	if (offset >= sc->sc_dc->dc_size || offset < 0)
    475 		return -1;
    476 
    477 	return arm_btop(sc->sc_dc->dc_paddr + offset);
    478 }
    479 
    480 
    481 static int
    482 vidcvideo_alloc_screen(void *v, const struct wsscreen_descr *type,
    483     void **cookiep, int *curxp, int *curyp, long *attrp)
    484 {
    485 	struct vidcvideo_softc *sc = v;
    486 	struct fb_devconfig *dc = sc->sc_dc;
    487 	long defattr;
    488 
    489 	/*
    490 	 * One and just only one for now :( ... if the vidcconsole is not the
    491 	 * console then this makes one wsconsole screen free for use !
    492 	 */
    493 	if ((sc->nscreens > 1) || vidcvideo_is_console)
    494 		return ENOMEM;
    495 
    496 	/* Add the screen to wscons to control */
    497 	*cookiep = &dc->rinfo;
    498 	*curxp = 0;
    499 	*curyp = 0;
    500 	vidcvideo_getdevconfig(videomemory.vidm_vbase, dc);
    501 	vidcvideo_config_wscons(dc);
    502 	(*dc->rinfo.ri_ops.allocattr)(&dc->rinfo, 0, 0, 0, &defattr);
    503 	*attrp = defattr;
    504 	sc->nscreens++;
    505 
    506 	return 0;
    507 }
    508 
    509 
    510 static void
    511 vidcvideo_free_screen(void *v, void *cookie)
    512 {
    513 	struct vidcvideo_softc *sc = v;
    514 
    515 	if (sc->sc_dc == &vidcvideo_console_dc)
    516 		panic("vidcvideo_free_screen: console");
    517 
    518 	sc->nscreens--;
    519 }
    520 
    521 
    522 static int
    523 vidcvideo_show_screen(void *v, void *cookie, int waitok,
    524     void (*cb)(void *, int, int), void *cbarg)
    525 {
    526 
    527 	return 0;
    528 }
    529 
    530 
    531 /* EXPORT */ int
    532 vidcvideo_cnattach(vaddr_t addr)
    533 {
    534 	struct fb_devconfig *dcp = &vidcvideo_console_dc;
    535 	long defattr;
    536 
    537 	vidcvideo_init();
    538 	vidcvideo_getdevconfig(addr, dcp);
    539 	vidcvideo_config_wscons(dcp);
    540 	(*dcp->rinfo.ri_ops.allocattr)(&dcp->rinfo, 0, 0, 0, &defattr);
    541 	wsdisplay_cnattach(&vidcvideo_stdscreen, &dcp->rinfo, 0, 0, defattr);
    542 
    543 	vidcvideo_is_console = 1;
    544 	return 0;
    545 }
    546 
    547 
    548 static int
    549 vidcvideointr(void *arg)
    550 {
    551 	struct fb_devconfig *dc = arg;
    552 	int v, cleared = 0;
    553 
    554 	v = dc->dc_changed;
    555 	if (v == 0)
    556 		return 1;
    557 
    558 	if (v & WSDISPLAY_WB_COUNTER) {
    559 	    	dc->dc_writeback_delay--;
    560 		if (dc->dc_writeback_delay == 0) {
    561 		    	cpu_dcache_wb_range(dc->dc_vaddr, dc->dc_size);
    562 			cleared |= WSDISPLAY_WB_COUNTER;
    563 		}
    564 	}
    565 
    566 	if (v & WSDISPLAY_CMAP_DOLUT) {
    567 		struct hwcmap256 *cm = &dc->dc_cmap;
    568 		int index;
    569 
    570 		if (dc->dc_depth == 4) {
    571 			/* palette for 4 bpp is different from 8bpp */
    572 			vidcvideo_write(VIDC_PALREG, 0x00000000);
    573 			for (index=0; index < (1 << dc->dc_depth); index++)
    574 				vidcvideo_write(VIDC_PALETTE,
    575 					VIDC_COL(cm->r[index],
    576 						 cm->g[index],
    577 						 cm->b[index]));
    578 		}
    579 
    580 		if (dc->dc_depth == 8) {
    581 			/*
    582 			 * dunno what to do in more than 8bpp
    583 			 * palettes only make sense in 8bpp and less modes
    584 			 * on VIDC
    585 			 */
    586 			vidcvideo_write(VIDC_PALREG, 0x00000000);
    587 			for (index = 0; index < CMAP_SIZE; index++) {
    588 				vidcvideo_write(VIDC_PALETTE,
    589 					VIDC_COL(cm->r[index], cm->g[index],
    590 					    cm->b[index]));
    591 			}
    592 		}
    593 		cleared |= WSDISPLAY_CMAP_DOLUT;
    594 	}
    595 
    596 	if (v & WSDISPLAY_VIDEO_ONOFF) {
    597 		vidcvideo_blank(dc->dc_blanked);
    598 		cleared |= WSDISPLAY_VIDEO_ONOFF;
    599 	}
    600 
    601 	if (v & (WSDISPLAY_CURSOR_DOPOS | WSDISPLAY_CURSOR_DOHOT)) {
    602 		int x, y;
    603 		x = dc->dc_cursor.cc_pos.x - dc->dc_cursor.cc_hot.x;
    604 		y = dc->dc_cursor.cc_pos.y - dc->dc_cursor.cc_hot.y;
    605 
    606 		vidcvideo_updatecursor(x, y);
    607 		cleared |= WSDISPLAY_CURSOR_DOPOS | WSDISPLAY_CURSOR_DOHOT;
    608 	}
    609 
    610 	if (v & WSDISPLAY_CURSOR_DOCUR) {
    611 		vidcvideo_enablecursor(dc->dc_curenb);
    612 		cleared |= WSDISPLAY_CURSOR_DOCUR;
    613 	}
    614 
    615 	dc->dc_changed ^= cleared;
    616 
    617 	return 1;
    618 }
    619 
    620 
    621 static u_char ri_col_data[6][6] = {
    622 	{ 0,  0,  0,   0,  0,  0},	/*  1 bpp */
    623 	{ 0,  0,  0,   0,  0,  0},	/*  2 bpp */
    624 	{ 0,  0,  0,   0,  0,  0},	/*  4 bpp */
    625 	{ 0,  0,  0,   0,  0,  0},	/*  8 bpp */
    626 	{ 6,  5,  5,   0,  6, 11},	/* 16 bpp */
    627 	{ 8,  8,  8,   0,  8, 16},	/* 32 bpp */
    628 };
    629 
    630 static void
    631 vidcvideo_colourmap_and_cursor_init(struct fb_devconfig *dc)
    632 {
    633 	struct rasops_info *ri = &dc->rinfo;
    634 	u_char *rgbdat;
    635 
    636 	/* Whatever we do later... just make sure we have a
    637 	 * sane palette to start with
    638 	 */
    639 	vidcvideo_stdpalette();
    640 
    641 	/* set up rgb bit pattern values for rasops_init */
    642 	rgbdat = ri_col_data[dc->dc_log2_depth];
    643 	ri->ri_rnum = rgbdat[0];
    644 	ri->ri_gnum = rgbdat[1];
    645 	ri->ri_bnum = rgbdat[2];
    646 	ri->ri_rpos = rgbdat[3];
    647 	ri->ri_gpos = rgbdat[4];
    648 	ri->ri_bpos = rgbdat[5];
    649 }
    650 
    651 
    652 static int
    653 get_cmap(struct vidcvideo_softc *sc, struct wsdisplay_cmap *p)
    654 {
    655 	u_int index = p->index, count = p->count;
    656 	int error;
    657 
    658 	if (index >= CMAP_SIZE || count > CMAP_SIZE - index)
    659 		return EINVAL;
    660 
    661 	error = copyout(&sc->sc_dc->dc_cmap.r[index], p->red, count);
    662 	if (error)
    663 		return error;
    664 	error = copyout(&sc->sc_dc->dc_cmap.g[index], p->green, count);
    665 	if (error)
    666 		return error;
    667 	error = copyout(&sc->sc_dc->dc_cmap.b[index], p->blue, count);
    668 	return error;
    669 }
    670 
    671 
    672 static int
    673 set_cmap(struct vidcvideo_softc *sc, struct wsdisplay_cmap *p)
    674 {
    675     	struct fb_devconfig *dc = sc->sc_dc;
    676 	struct hwcmap256 cmap;
    677 	u_int index = p->index, count = p->count;
    678 	int error;
    679 
    680 	if (index >= CMAP_SIZE || (index + count) > CMAP_SIZE)
    681 		return EINVAL;
    682 
    683 	error = copyin(p->red, &cmap.r[index], count);
    684 	if (error)
    685 		return error;
    686 	error = copyin(p->green, &cmap.g[index], count);
    687 	if (error)
    688 		return error;
    689 	error = copyin(p->blue, &cmap.b[index], count);
    690 	if (error)
    691 		return error;
    692 	memcpy(&dc->dc_cmap.r[index], &cmap.r[index], count);
    693 	memcpy(&dc->dc_cmap.g[index], &cmap.g[index], count);
    694 	memcpy(&dc->dc_cmap.b[index], &cmap.b[index], count);
    695 	dc->dc_changed |= WSDISPLAY_CMAP_DOLUT;
    696 	return 0;
    697 }
    698 
    699 
    700 static int
    701 set_cursor(struct vidcvideo_softc *sc, struct wsdisplay_cursor *p)
    702 {
    703 #define	cc (&dc->dc_cursor)
    704     	struct fb_devconfig *dc = sc->sc_dc;
    705 	u_int v, index = 0, count = 0, icount = 0;
    706 	uint8_t r[2], g[2], b[2], image[512], mask[512];
    707 	int error;
    708 
    709 	/* XXX gcc does not detect identical conditions */
    710 	index = count = icount = 0;
    711 
    712 	v = p->which;
    713 	if (v & WSDISPLAY_CURSOR_DOCMAP) {
    714 		index = p->cmap.index;
    715 		count = p->cmap.count;
    716 		if (index >= CURSOR_MAX_COLOURS ||
    717 		    (index + count) > CURSOR_MAX_COLOURS)
    718 			return EINVAL;
    719 		error = copyin(p->cmap.red, &r[index], count);
    720 		if (error)
    721 			return error;
    722 		error = copyin(p->cmap.green, &g[index], count);
    723 		if (error)
    724 			return error;
    725 		error = copyin(p->cmap.blue, &b[index], count);
    726 		if (error)
    727 			return error;
    728 	}
    729 	if (v & WSDISPLAY_CURSOR_DOSHAPE) {
    730 		if (p->size.x > CURSOR_MAX_WIDTH ||
    731 		    p->size.y > CURSOR_MAX_HEIGHT)
    732 			return EINVAL;
    733 		icount = sizeof(u_int32_t) * p->size.y;
    734 		error = copyin(p->image, &image, icount);
    735 		if (error)
    736 			return error;
    737 		error = copyin(p->mask, &mask, icount);
    738 		if (error)
    739 			return error;
    740 	}
    741 
    742 	if (v & WSDISPLAY_CURSOR_DOCUR)
    743 		dc->dc_curenb = p->enable;
    744 	if (v & WSDISPLAY_CURSOR_DOPOS)
    745 		set_curpos(sc, &p->pos);
    746 	if (v & WSDISPLAY_CURSOR_DOHOT)
    747 		cc->cc_hot = p->hot;
    748 	if (v & WSDISPLAY_CURSOR_DOCMAP) {
    749 		memcpy(&cc->cc_color[index], &r[index], count);
    750 		memcpy(&cc->cc_color[index + 2], &g[index], count);
    751 		memcpy(&cc->cc_color[index + 4], &b[index], count);
    752 	}
    753 	if (v & WSDISPLAY_CURSOR_DOSHAPE) {
    754 		cc->cc_size = p->size;
    755 		memset(cc->cc_image, 0, sizeof cc->cc_image);
    756 		memcpy(cc->cc_image, image, icount);
    757 		memset(cc->cc_mask, 0, sizeof cc->cc_mask);
    758 		memcpy(cc->cc_mask, mask, icount);
    759 	}
    760 	dc->dc_changed |= v;
    761 
    762 	return 0;
    763 #undef cc
    764 }
    765 
    766 
    767 static int
    768 get_cursor(struct vidcvideo_softc *sc, struct wsdisplay_cursor *p)
    769 {
    770 
    771 	return EPASSTHROUGH; /* XXX */
    772 }
    773 
    774 
    775 static void
    776 set_curpos(struct vidcvideo_softc *sc, struct wsdisplay_curpos *curpos)
    777 {
    778 	struct fb_devconfig *dc = sc->sc_dc;
    779 	int x = curpos->x, y = curpos->y;
    780 
    781 	if (y < 0)
    782 		y = 0;
    783 	else if (y > dc->dc_ht)
    784 		y = dc->dc_ht;
    785 	if (x < 0)
    786 		x = 0;
    787 	else if (x > dc->dc_wid)
    788 		x = dc->dc_wid;
    789 	dc->dc_cursor.cc_pos.x = x;
    790 	dc->dc_cursor.cc_pos.y = y;
    791 }
    792 
    793 
    794 static void vv_copyrows(void *id, int srcrow, int dstrow, int nrows)
    795 {
    796 	struct rasops_info *ri = id;
    797 	int height, offset, size;
    798 	int scrollup, scrolldown;
    799 	unsigned char *src, *dst;
    800 
    801 	/* All movements are done in multiples of character heigths */
    802 	height = ri->ri_font->fontheight * nrows;
    803 	offset = (srcrow - dstrow) * ri->ri_yscale;
    804 	size   = height * ri->ri_stride;
    805 
    806 	/* check if we are full screen scrolling */
    807 	scrollup   = (srcrow + nrows >= ri->ri_rows);
    808 	scrolldown = (dstrow + nrows >= ri->ri_rows);
    809 
    810 	if ((scrollup || scrolldown) &&
    811 	    (videomemory.vidm_type == VIDEOMEM_TYPE_VRAM)) {
    812 		ri->ri_bits = vidcvideo_hwscroll(offset);
    813 		vidcvideo_progr_scroll();	/* sadistic ; shouldnt this be on vsync? */
    814 
    815 		/* wipe out remains of the screen if nessisary */
    816 		if (ri->ri_emuheight != ri->ri_height)
    817 			vv_eraserows(id, ri->ri_rows, 1, 0);
    818 		return;
    819 	}
    820 
    821 	/*
    822 	 * Else we just copy the area : we're braindead for now
    823 	 * Note: we can't use hardware scrolling when the softc isnt
    824 	 * known yet...  if its not known we dont have interrupts and
    825 	 * we can't change the display address reliable other than in
    826 	 * a Vsync
    827 	 */
    828 
    829 	src = ri->ri_bits + srcrow * ri->ri_font->fontheight * ri->ri_stride;
    830 	dst = ri->ri_bits + dstrow * ri->ri_font->fontheight * ri->ri_stride;
    831 
    832 	memcpy(dst, src, size);
    833 }
    834 
    835 
    836 static void vv_eraserows(void *id, int startrow, int nrows, long attr)
    837 {
    838 	struct rasops_info *ri = id;
    839 	int height;
    840 	unsigned char *src;
    841 
    842 	/* we're braindead for now */
    843 	height = ri->ri_font->fontheight * nrows * ri->ri_stride;
    844 
    845 	src = ri->ri_bits + startrow * ri->ri_font->fontheight * ri->ri_stride;
    846 
    847 	memset(src, 0, height);
    848 }
    849 
    850 
    851 static void vv_putchar(void *id, int row, int col, u_int uc, long attr)
    852 {
    853     	struct rasops_info *ri = id;
    854 	struct fb_devconfig *dc = (struct fb_devconfig *) (ri->ri_hw);
    855 
    856 	/* delay the write back operation of the screen area */
    857 	dc->dc_writeback_delay = SCREEN_WRITE_BACK_DELAY;
    858 	dc->dc_changed |= WSDISPLAY_WB_COUNTER;
    859 
    860 	/* just delegate */
    861 	dc->orig_ri_ops.putchar(id, row, col, uc, attr);
    862 }
    863