Home | History | Annotate | Line # | Download | only in dev
cgfourteen.c revision 1.77
      1 /*	$NetBSD: cgfourteen.c,v 1.77 2014/03/16 05:20:25 dholland Exp $ */
      2 
      3 /*
      4  * Copyright (c) 1996
      5  *	The President and Fellows of Harvard College. All rights reserved.
      6  * Copyright (c) 1992, 1993
      7  *	The Regents of the University of California.  All rights reserved.
      8  *
      9  * This software was developed by the Computer Systems Engineering group
     10  * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
     11  * contributed to Berkeley.
     12  *
     13  * All advertising materials mentioning features or use of this software
     14  * must display the following acknowledgement:
     15  *	This product includes software developed by Harvard University.
     16  *	This product includes software developed by the University of
     17  *	California, Lawrence Berkeley Laboratory.
     18  *
     19  * Redistribution and use in source and binary forms, with or without
     20  * modification, are permitted provided that the following conditions
     21  * are met:
     22  * 1. Redistributions of source code must retain the above copyright
     23  *    notice, this list of conditions and the following disclaimer.
     24  * 2. Redistributions in binary form must reproduce the above copyright
     25  *    notice, this list of conditions and the following disclaimer in the
     26  *    documentation and/or other materials provided with the distribution.
     27  * 3. All advertising materials mentioning features or use of this software
     28  *    must display the following acknowledgement:
     29  *	This product includes software developed by the University of
     30  *	California, Berkeley and its contributors.
     31  *	This product includes software developed by Harvard University and
     32  *	its contributors.
     33  * 4. Neither the name of the University nor the names of its contributors
     34  *    may be used to endorse or promote products derived from this software
     35  *    without specific prior written permission.
     36  *
     37  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     38  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     39  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     40  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     41  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     42  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     43  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     44  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     45  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     46  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     47  * SUCH DAMAGE.
     48  *
     49  *   Based on:
     50  *	NetBSD: cgthree.c,v 1.28 1996/05/31 09:59:22 pk Exp
     51  *	NetBSD: cgsix.c,v 1.25 1996/04/01 17:30:00 christos Exp
     52  */
     53 
     54 /*
     55  * Driver for Campus-II on-board mbus-based video (cgfourteen).
     56  *
     57  * Does not handle interrupts, even though they can occur.
     58  *
     59  * XXX should defer colormap updates to vertical retrace interrupts
     60  */
     61 
     62 /*
     63  * The following is for debugging only; it opens up a security hole
     64  * enabled by allowing any user to map the control registers for the
     65  * cg14 into their space.
     66  */
     67 #undef CG14_MAP_REGS
     68 
     69 #include "opt_wsemul.h"
     70 #include "sx.h"
     71 
     72 #include <sys/param.h>
     73 #include <sys/systm.h>
     74 #include <sys/buf.h>
     75 #include <sys/device.h>
     76 #include <sys/ioctl.h>
     77 #include <sys/malloc.h>
     78 #include <sys/kmem.h>
     79 #include <sys/mman.h>
     80 #include <sys/tty.h>
     81 #include <sys/conf.h>
     82 #include <dev/pci/pciio.h>
     83 
     84 #include <uvm/uvm_extern.h>
     85 
     86 #include <dev/sun/fbio.h>
     87 #include <machine/autoconf.h>
     88 #include <machine/pmap.h>
     89 #include <dev/sun/fbvar.h>
     90 #include <machine/cpu.h>
     91 #include <dev/sbus/sbusvar.h>
     92 
     93 #include "wsdisplay.h"
     94 #include <dev/wscons/wsconsio.h>
     95 #include <dev/wsfont/wsfont.h>
     96 #include <dev/rasops/rasops.h>
     97 
     98 #include <dev/wscons/wsdisplay_vconsvar.h>
     99 
    100 #include <sparc/sparc/asm.h>
    101 #include <sparc/dev/cgfourteenreg.h>
    102 #include <sparc/dev/cgfourteenvar.h>
    103 #include <sparc/dev/sxreg.h>
    104 #include <sparc/dev/sxvar.h>
    105 
    106 /* autoconfiguration driver */
    107 static int	cgfourteenmatch(device_t, struct cfdata *, void *);
    108 static void	cgfourteenattach(device_t, device_t, void *);
    109 static void	cgfourteenunblank(device_t);
    110 
    111 CFATTACH_DECL_NEW(cgfourteen, sizeof(struct cgfourteen_softc),
    112     cgfourteenmatch, cgfourteenattach, NULL, NULL);
    113 
    114 extern struct cfdriver cgfourteen_cd;
    115 
    116 dev_type_open(cgfourteenopen);
    117 dev_type_close(cgfourteenclose);
    118 dev_type_ioctl(cgfourteenioctl);
    119 dev_type_mmap(cgfourteenmmap);
    120 dev_type_poll(cgfourteenpoll);
    121 
    122 const struct cdevsw cgfourteen_cdevsw = {
    123         .d_open = cgfourteenopen,
    124 	.d_close = cgfourteenclose,
    125 	.d_read = noread,
    126 	.d_write = nowrite,
    127 	.d_ioctl = cgfourteenioctl,
    128         .d_stop = nostop,
    129 	.d_tty = notty,
    130 	.d_poll = cgfourteenpoll,
    131 	.d_mmap = cgfourteenmmap,
    132 	.d_kqfilter = nokqfilter,
    133 	.d_flag = 0
    134 };
    135 
    136 /* frame buffer generic driver */
    137 static struct fbdriver cgfourteenfbdriver = {
    138 	cgfourteenunblank, cgfourteenopen, cgfourteenclose, cgfourteenioctl,
    139 	cgfourteenpoll, cgfourteenmmap, nokqfilter
    140 };
    141 
    142 static void cg14_set_video(struct cgfourteen_softc *, int);
    143 static int  cg14_get_video(struct cgfourteen_softc *);
    144 static int  cg14_get_cmap(struct fbcmap *, union cg14cmap *, int);
    145 static int  cg14_put_cmap(struct fbcmap *, union cg14cmap *, int);
    146 static void cg14_load_hwcmap(struct cgfourteen_softc *, int, int);
    147 static void cg14_init(struct cgfourteen_softc *);
    148 static void cg14_reset(struct cgfourteen_softc *);
    149 
    150 #if NWSDISPLAY > 0
    151 static void cg14_setup_wsdisplay(struct cgfourteen_softc *, int);
    152 static void cg14_init_cmap(struct cgfourteen_softc *);
    153 static int  cg14_putcmap(struct cgfourteen_softc *, struct wsdisplay_cmap *);
    154 static int  cg14_getcmap(struct cgfourteen_softc *, struct wsdisplay_cmap *);
    155 static void cg14_set_depth(struct cgfourteen_softc *, int);
    156 static void cg14_move_cursor(struct cgfourteen_softc *, int, int);
    157 static int  cg14_do_cursor(struct cgfourteen_softc *,
    158                            struct wsdisplay_cursor *);
    159 
    160 #if NSX > 0
    161 static void cg14_wait_idle(struct cgfourteen_softc *);
    162 static void cg14_rectfill(struct cgfourteen_softc *, int, int, int, int,
    163     uint32_t);
    164 static void cg14_invert(struct cgfourteen_softc *, int, int, int, int);
    165 static void cg14_bitblt(void *, int, int, int, int, int, int, int);
    166 
    167 #if 0
    168 static void cg14_putchar_aa(void *, int, int, u_int, long);
    169 #endif
    170 static void cg14_cursor(void *, int, int, int);
    171 static void cg14_putchar(void *, int, int, u_int, long);
    172 static void cg14_copycols(void *, int, int, int, int);
    173 static void cg14_erasecols(void *, int, int, int, long);
    174 static void cg14_copyrows(void *, int, int, int);
    175 static void cg14_eraserows(void *, int, int, long);
    176 #endif /* NSX > 0 */
    177 
    178 #endif
    179 
    180 /*
    181  * Match a cgfourteen.
    182  */
    183 int
    184 cgfourteenmatch(device_t parent, struct cfdata *cf, void *aux)
    185 {
    186 	union obio_attach_args *uoba = aux;
    187 	struct sbus_attach_args *sa = &uoba->uoba_sbus;
    188 
    189 	/*
    190 	 * The cgfourteen is a local-bus video adaptor, accessed directly
    191 	 * via the processor, and not through device space or an external
    192 	 * bus. Thus we look _only_ at the obio bus.
    193 	 * Additionally, these things exist only on the Sun4m.
    194 	 */
    195 
    196 	if (uoba->uoba_isobio4 != 0 || !CPU_ISSUN4M)
    197 		return (0);
    198 
    199 	/* Check driver name */
    200 	return (strcmp(cf->cf_name, sa->sa_name) == 0);
    201 }
    202 
    203 #if NWSDISPLAY > 0
    204 static int	cg14_ioctl(void *, void *, u_long, void *, int, struct lwp *);
    205 static paddr_t	cg14_mmap(void *, void *, off_t, int);
    206 static void	cg14_init_screen(void *, struct vcons_screen *, int, long *);
    207 
    208 
    209 struct wsdisplay_accessops cg14_accessops = {
    210 	cg14_ioctl,
    211 	cg14_mmap,
    212 	NULL,	/* alloc_screen */
    213 	NULL,	/* free_screen */
    214 	NULL,	/* show_screen */
    215 	NULL, 	/* load_font */
    216 	NULL,	/* pollc */
    217 	NULL	/* scroll */
    218 };
    219 #endif
    220 
    221 /*
    222  * Attach a display.  We need to notice if it is the console, too.
    223  */
    224 void
    225 cgfourteenattach(device_t parent, device_t self, void *aux)
    226 {
    227 	union obio_attach_args *uoba = aux;
    228 	struct sbus_attach_args *sa = &uoba->uoba_sbus;
    229 	struct cgfourteen_softc *sc = device_private(self);
    230 	struct fbdevice *fb = &sc->sc_fb;
    231 	bus_space_handle_t bh;
    232 	int node;
    233 	volatile uint32_t *lut;
    234 	int i, isconsole, items;
    235 	uint32_t fbva[2] = {0, 0};
    236 	uint32_t *ptr = fbva;
    237 #if NSX > 0
    238 	device_t dv;
    239 	deviter_t di;
    240 #endif
    241 
    242 	sc->sc_dev = self;
    243 	sc->sc_opens = 0;
    244 	node = sa->sa_node;
    245 
    246 	/* Remember cookies for cgfourteenmmap() */
    247 	sc->sc_bustag = sa->sa_bustag;
    248 
    249 	fb->fb_driver = &cgfourteenfbdriver;
    250 	fb->fb_device = sc->sc_dev;
    251 	/* Mask out invalid flags from the user. */
    252 	fb->fb_flags = device_cfdata(sc->sc_dev)->cf_flags & FB_USERMASK;
    253 
    254 	fb->fb_type.fb_type = FBTYPE_MDICOLOR;
    255 	fb->fb_type.fb_depth = 32;
    256 
    257 	fb_setsize_obp(fb, sc->sc_fb.fb_type.fb_depth, 1152, 900, node);
    258 
    259 	fb->fb_type.fb_cmsize = CG14_CLUT_SIZE;
    260 
    261 	if (sa->sa_nreg < 2) {
    262 		printf("%s: only %d register sets\n",
    263 			device_xname(self), sa->sa_nreg);
    264 		return;
    265 	}
    266 	memcpy(sc->sc_physadr, sa->sa_reg,
    267 	      sa->sa_nreg * sizeof(struct sbus_reg));
    268 
    269 	sc->sc_vramsize = sc->sc_physadr[CG14_PXL_IDX].sbr_size;
    270 	fb->fb_type.fb_size = sc->sc_vramsize;
    271 
    272 	printf(": %d MB VRAM", (uint32_t)(sc->sc_vramsize >> 20));
    273 	/*
    274 	 * Now map in the 8 useful pages of registers
    275 	 */
    276 	if (sa->sa_size < 0x10000) {
    277 #ifdef DIAGNOSTIC
    278 		printf("warning: can't find all cgfourteen registers...\n");
    279 #endif
    280 		sa->sa_size = 0x10000;
    281 	}
    282 	if (sbus_bus_map(sa->sa_bustag, sa->sa_slot,
    283 			 sa->sa_offset,
    284 			 sa->sa_size,
    285 			 0 /*BUS_SPACE_MAP_LINEAR*/,
    286 			 &bh) != 0) {
    287 		printf("%s: cannot map control registers\n",
    288 		    device_xname(self));
    289 		return;
    290 	}
    291 	sc->sc_regh = bh;
    292 	sc->sc_regaddr = BUS_ADDR(sa->sa_slot, sa->sa_offset);
    293 	sc->sc_fbaddr = BUS_ADDR(sc->sc_physadr[CG14_PXL_IDX].sbr_slot,
    294 				sc->sc_physadr[CG14_PXL_IDX].sbr_offset);
    295 
    296 	sc->sc_ctl   = (struct cg14ctl  *) (bh);
    297 	sc->sc_hwc   = (struct cg14curs *) (bh + CG14_OFFSET_CURS);
    298 	sc->sc_dac   = (struct cg14dac  *) (bh + CG14_OFFSET_DAC);
    299 	sc->sc_xlut  = (struct cg14xlut *) (bh + CG14_OFFSET_XLUT);
    300 	sc->sc_clut1 = (struct cg14clut *) (bh + CG14_OFFSET_CLUT1);
    301 	sc->sc_clut2 = (struct cg14clut *) (bh + CG14_OFFSET_CLUT2);
    302 	sc->sc_clut3 = (struct cg14clut *) (bh + CG14_OFFSET_CLUT3);
    303 	sc->sc_clutincr =        (u_int *) (bh + CG14_OFFSET_CLUTINCR);
    304 
    305 	/*
    306 	 * Let the user know that we're here
    307 	 */
    308 	printf(": %dx%d",
    309 		fb->fb_type.fb_width, fb->fb_type.fb_height);
    310 
    311 	/*
    312 	 * Enable the video.
    313 	 */
    314 	cg14_set_video(sc, 1);
    315 
    316 	/*
    317 	 * Grab the initial colormap
    318 	 */
    319 	lut = sc->sc_clut1->clut_lut;
    320 	for (i = 0; i < CG14_CLUT_SIZE; i++)
    321 		sc->sc_cmap.cm_chip[i] = lut[i];
    322 
    323 	/* See if we're the console */
    324         isconsole = fb_is_console(node);
    325 
    326 #if NWSDISPLAY > 0
    327 	prom_getprop(sa->sa_node, "address", 4, &items, &ptr);
    328 	if (fbva[1] == 0) {
    329 		if (sbus_bus_map( sc->sc_bustag,
    330 		    sc->sc_physadr[CG14_PXL_IDX].sbr_slot,
    331 		    sc->sc_physadr[CG14_PXL_IDX].sbr_offset,
    332 		    sc->sc_vramsize, BUS_SPACE_MAP_LINEAR | BUS_SPACE_MAP_LARGE,
    333 		    &bh) != 0) {
    334 			printf("%s: cannot map pixels\n",
    335 				device_xname(sc->sc_dev));
    336 			return;
    337 		}
    338 		sc->sc_fb.fb_pixels = bus_space_vaddr(sc->sc_bustag, bh);
    339 	} else {
    340 		sc->sc_fb.fb_pixels = (void *)fbva[1];
    341 	}
    342 
    343 	if (isconsole)
    344 		printf(" (console)\n");
    345 	else
    346 		printf("\n");
    347 
    348 	sc->sc_depth = 8;
    349 
    350 #if NSX > 0
    351 	/* see if we've got an SX to help us */
    352 	sc->sc_sx = NULL;
    353 	for (dv = deviter_first(&di, DEVITER_F_ROOT_FIRST);
    354 	    dv != NULL;
    355 	    dv = deviter_next(&di)) {
    356 		if (device_is_a(dv, "sx")) {
    357 			sc->sc_sx = device_private(dv);
    358 		}
    359 	}
    360 	deviter_release(&di);
    361 	if (sc->sc_sx != NULL) {
    362 		sc->sc_fb_paddr = bus_space_mmap(sc->sc_bustag,
    363 		    sc->sc_fbaddr, 0, 0, 0) & 0xfffff000;
    364 		aprint_normal_dev(sc->sc_dev, "using %s\n",
    365 		    device_xname(sc->sc_sx->sc_dev));
    366 		aprint_debug_dev(sc->sc_dev, "fb paddr: %08x\n",
    367 		    sc->sc_fb_paddr);
    368 		sx_write(sc->sc_sx, SX_PAGE_BOUND_LOWER, sc->sc_fb_paddr);
    369 		sx_write(sc->sc_sx, SX_PAGE_BOUND_UPPER,
    370 		    sc->sc_fb_paddr + 0x03ffffff);
    371 	}
    372 	cg14_wait_idle(sc);
    373 #endif
    374 	cg14_setup_wsdisplay(sc, isconsole);
    375 #endif
    376 
    377 	/* Attach to /dev/fb */
    378 	fb_attach(&sc->sc_fb, isconsole);
    379 }
    380 
    381 /*
    382  * Keep track of the number of opens made. In the 24-bit driver, we need to
    383  * switch to 24-bit mode on the first open, and switch back to 8-bit on
    384  * the last close. This kind of nonsense is needed to give screenblank
    385  * a fighting chance of working.
    386  */
    387 
    388 int
    389 cgfourteenopen(dev_t dev, int flags, int mode, struct lwp *l)
    390 {
    391 	struct cgfourteen_softc *sc;
    392 	int oldopens;
    393 
    394 	sc = device_lookup_private(&cgfourteen_cd, minor(dev));
    395 	if (sc == NULL)
    396 		return(ENXIO);
    397 	oldopens = sc->sc_opens++;
    398 
    399 	/* Setup the cg14 as we want it, and save the original PROM state */
    400 	if (oldopens == 0)	/* first open only, to make screenblank work */
    401 		cg14_init(sc);
    402 
    403 	return (0);
    404 }
    405 
    406 int
    407 cgfourteenclose(dev_t dev, int flags, int mode, struct lwp *l)
    408 {
    409 	struct cgfourteen_softc *sc =
    410 	    device_lookup_private(&cgfourteen_cd, minor(dev));
    411 	int opens;
    412 
    413 	opens = --sc->sc_opens;
    414 	if (sc->sc_opens < 0)
    415 		opens = sc->sc_opens = 0;
    416 
    417 	/*
    418 	 * Restore video state to make the PROM happy, on last close.
    419 	 */
    420 	if (opens == 0)
    421 		cg14_reset(sc);
    422 
    423 	return (0);
    424 }
    425 
    426 int
    427 cgfourteenioctl(dev_t dev, u_long cmd, void *data, int flags, struct lwp *l)
    428 {
    429 	struct cgfourteen_softc *sc =
    430 	    device_lookup_private(&cgfourteen_cd, minor(dev));
    431 	struct fbgattr *fba;
    432 	int error;
    433 
    434 	switch (cmd) {
    435 
    436 	case FBIOGTYPE:
    437 		*(struct fbtype *)data = sc->sc_fb.fb_type;
    438 		break;
    439 
    440 	case FBIOGATTR:
    441 		fba = (struct fbgattr *)data;
    442 		fba->real_type = FBTYPE_MDICOLOR;
    443 		fba->owner = 0;		/* XXX ??? */
    444 		fba->fbtype = sc->sc_fb.fb_type;
    445 		fba->sattr.flags = 0;
    446 		fba->sattr.emu_type = sc->sc_fb.fb_type.fb_type;
    447 		fba->sattr.dev_specific[0] = -1;
    448 		fba->emu_types[0] = sc->sc_fb.fb_type.fb_type;
    449 		fba->emu_types[1] = -1;
    450 		break;
    451 
    452 	case FBIOGETCMAP:
    453 		return(cg14_get_cmap((struct fbcmap *)data, &sc->sc_cmap,
    454 				     CG14_CLUT_SIZE));
    455 
    456 	case FBIOPUTCMAP:
    457 		/* copy to software map */
    458 #define p ((struct fbcmap *)data)
    459 		error = cg14_put_cmap(p, &sc->sc_cmap, CG14_CLUT_SIZE);
    460 		if (error)
    461 			return (error);
    462 		/* now blast them into the chip */
    463 		/* XXX should use retrace interrupt */
    464 		cg14_load_hwcmap(sc, p->index, p->count);
    465 #undef p
    466 		break;
    467 
    468 	case FBIOGVIDEO:
    469 		*(int *)data = cg14_get_video(sc);
    470 		break;
    471 
    472 	case FBIOSVIDEO:
    473 		cg14_set_video(sc, *(int *)data);
    474 		break;
    475 
    476 	case CG14_SET_PIXELMODE: {
    477 		int depth = *(int *)data;
    478 
    479 		if (sc->sc_mode == WSDISPLAYIO_MODE_EMUL)
    480 			return EINVAL;
    481 
    482 		cg14_set_depth(sc, depth);
    483 		}
    484 		break;
    485 	default:
    486 		return (ENOTTY);
    487 	}
    488 	return (0);
    489 }
    490 
    491 /*
    492  * Undo the effect of an FBIOSVIDEO that turns the video off.
    493  */
    494 static void
    495 cgfourteenunblank(device_t dev)
    496 {
    497 	struct cgfourteen_softc *sc = device_private(dev);
    498 
    499 	cg14_set_video(sc, 1);
    500 #if NWSDISPLAY > 0
    501 	if (sc->sc_mode != WSDISPLAYIO_MODE_EMUL) {
    502 		cg14_set_depth(sc, 8);
    503 		cg14_init_cmap(sc);
    504 		vcons_redraw_screen(sc->sc_vd.active);
    505 		sc->sc_mode = WSDISPLAYIO_MODE_EMUL;
    506 	}
    507 #endif
    508 }
    509 
    510 /*
    511  * Return the address that would map the given device at the given
    512  * offset, allowing for the given protection, or return -1 for error.
    513   */
    514 paddr_t
    515 cgfourteenmmap(dev_t dev, off_t off, int prot)
    516 {
    517 	struct cgfourteen_softc *sc =
    518 	    device_lookup_private(&cgfourteen_cd, minor(dev));
    519 	off_t offset = -1;
    520 
    521 	if (off & PGOFSET)
    522 		panic("cgfourteenmmap");
    523 
    524 	if (off < 0)
    525 		return (-1);
    526 
    527 	if (off >= 0 && off < 0x10000) {
    528 		offset = sc->sc_regaddr;
    529 	} else if (off >= CG14_CURSOR_VOFF &&
    530 		   off < (CG14_CURSOR_VOFF + 0x1000)) {
    531 		offset = sc->sc_regaddr + CG14_OFFSET_CURS;
    532 		off -= CG14_CURSOR_VOFF;
    533 	} else if (off >= CG14_DIRECT_VOFF &&
    534 		   off < (CG14_DIRECT_VOFF + sc->sc_vramsize)) {
    535 		offset = sc->sc_fbaddr + CG14_FB_VRAM;
    536 		off -= CG14_DIRECT_VOFF;
    537 	} else if (off >= CG14_BGR_VOFF &&
    538 		   off < (CG14_BGR_VOFF + sc->sc_vramsize)) {
    539 		offset = sc->sc_fbaddr + CG14_FB_CBGR;
    540 		off -= CG14_BGR_VOFF;
    541 	} else if (off >= CG14_X32_VOFF &&
    542 		   off < (CG14_X32_VOFF + (sc->sc_vramsize >> 2))) {
    543 		offset = sc->sc_fbaddr + CG14_FB_PX32;
    544 		off -= CG14_X32_VOFF;
    545 	} else if (off >= CG14_B32_VOFF &&
    546 		   off < (CG14_B32_VOFF + (sc->sc_vramsize >> 2))) {
    547 		offset = sc->sc_fbaddr + CG14_FB_PB32;
    548 		off -= CG14_B32_VOFF;
    549 	} else if (off >= CG14_G32_VOFF &&
    550 		   off < (CG14_G32_VOFF + (sc->sc_vramsize >> 2))) {
    551 		offset = sc->sc_fbaddr + CG14_FB_PG32;
    552 		off -= CG14_G32_VOFF;
    553 	} else if (off >= CG14_R32_VOFF &&
    554 		   off < CG14_R32_VOFF + (sc->sc_vramsize >> 2)) {
    555 		offset = sc->sc_fbaddr + CG14_FB_PR32;
    556 		off -= CG14_R32_VOFF;
    557 #if NSX > 0
    558 	/*
    559 	 * for convenience we also map the SX ranges here:
    560 	 * - one page userland registers
    561 	 * - CG14-sized IO space at 0x800000000 ( not a typo, it's above 4GB )
    562 	 */
    563 	} else if (sc->sc_sx == NULL) {
    564 		return -1;
    565 	} else if (off >= CG14_SXREG_VOFF &&
    566 		   off < (CG14_SXREG_VOFF + 0x400)) {
    567 		return (bus_space_mmap(sc->sc_sx->sc_tag, sc->sc_sx->sc_uregs,
    568 			0, prot, BUS_SPACE_MAP_LINEAR));
    569 	} else if (off >= CG14_SXIO_VOFF &&
    570 		   off < (CG14_SXIO_VOFF + 0x03ffffff)) {
    571 		return (bus_space_mmap(sc->sc_sx->sc_tag, 0x800000000LL,
    572 			sc->sc_fb_paddr + (off - CG14_SXIO_VOFF),
    573 			prot, BUS_SPACE_MAP_LINEAR));
    574 #endif
    575 	} else
    576 		return -1;
    577 
    578 	return (bus_space_mmap(sc->sc_bustag, offset, off, prot,
    579 		    BUS_SPACE_MAP_LINEAR));
    580 }
    581 
    582 int
    583 cgfourteenpoll(dev_t dev, int events, struct lwp *l)
    584 {
    585 
    586 	return (seltrue(dev, events, l));
    587 }
    588 
    589 /*
    590  * Miscellaneous helper functions
    591  */
    592 
    593 /* Initialize the framebuffer, storing away useful state for later reset */
    594 static void
    595 cg14_init(struct cgfourteen_softc *sc)
    596 {
    597 #if 0
    598 	volatile uint32_t *clut;
    599 	volatile uint8_t  *xlut;
    600 	int i;
    601 
    602 	/*
    603 	 * We stash away the following to restore on close:
    604 	 *
    605 	 * 	color look-up table 1 	(sc->sc_saveclut)
    606 	 *	x look-up table		(sc->sc_savexlut)
    607 	 *	control register	(sc->sc_savectl)
    608 	 *	cursor control register (sc->sc_savehwc)
    609 	 */
    610 	sc->sc_savectl = sc->sc_ctl->ctl_mctl;
    611 	sc->sc_savehwc = sc->sc_hwc->curs_ctl;
    612 
    613 	clut = (volatile uint32_t *) sc->sc_clut1->clut_lut;
    614 	xlut = (volatile uint8_t *) sc->sc_xlut->xlut_lut;
    615 	for (i = 0; i < CG14_CLUT_SIZE; i++) {
    616 		sc->sc_saveclut.cm_chip[i] = clut[i];
    617 		sc->sc_savexlut[i] = xlut[i];
    618 	}
    619 
    620 	/*
    621 	 * Enable the video and put it in 8 bit mode
    622 	 */
    623 	sc->sc_ctl->ctl_mctl = CG14_MCTL_ENABLEVID | CG14_MCTL_PIXMODE_8 |
    624 		CG14_MCTL_POWERCTL;
    625 #else
    626 	cg14_set_depth(sc, 32);
    627 #endif
    628 }
    629 
    630 static void
    631 /* Restore the state saved on cg14_init */
    632 cg14_reset(struct cgfourteen_softc *sc)
    633 {
    634 #if 0
    635 	volatile uint32_t *clut;
    636 	volatile uint8_t  *xlut;
    637 	int i;
    638 
    639 	/*
    640 	 * We restore the following, saved in cg14_init:
    641 	 *
    642 	 * 	color look-up table 1 	(sc->sc_saveclut)
    643 	 *	x look-up table		(sc->sc_savexlut)
    644 	 *	control register	(sc->sc_savectl)
    645 	 *	cursor control register (sc->sc_savehwc)
    646 	 *
    647 	 * Note that we don't touch the video enable bits in the
    648 	 * control register; otherwise, screenblank wouldn't work.
    649 	 */
    650 	sc->sc_ctl->ctl_mctl = (sc->sc_ctl->ctl_mctl & (CG14_MCTL_ENABLEVID |
    651 							CG14_MCTL_POWERCTL)) |
    652 				(sc->sc_savectl & ~(CG14_MCTL_ENABLEVID |
    653 						    CG14_MCTL_POWERCTL));
    654 	sc->sc_hwc->curs_ctl = sc->sc_savehwc;
    655 
    656 	clut = sc->sc_clut1->clut_lut;
    657 	xlut = sc->sc_xlut->xlut_lut;
    658 	for (i = 0; i < CG14_CLUT_SIZE; i++) {
    659 		clut[i] = sc->sc_saveclut.cm_chip[i];
    660 		xlut[i] = sc->sc_savexlut[i];
    661 	}
    662 #else
    663 	cg14_set_depth(sc, 8);
    664 #endif
    665 }
    666 
    667 /* Enable/disable video display; power down monitor if DPMS-capable */
    668 static void
    669 cg14_set_video(struct cgfourteen_softc *sc, int enable)
    670 {
    671 	/*
    672 	 * We can only use DPMS to power down the display if the chip revision
    673 	 * is greater than 0.
    674 	 */
    675 	if (enable) {
    676 		if ((sc->sc_ctl->ctl_rsr & CG14_RSR_REVMASK) > 0)
    677 			sc->sc_ctl->ctl_mctl |= (CG14_MCTL_ENABLEVID |
    678 						 CG14_MCTL_POWERCTL);
    679 		else
    680 			sc->sc_ctl->ctl_mctl |= CG14_MCTL_ENABLEVID;
    681 	} else {
    682 		if ((sc->sc_ctl->ctl_rsr & CG14_RSR_REVMASK) > 0)
    683 			sc->sc_ctl->ctl_mctl &= ~(CG14_MCTL_ENABLEVID |
    684 						  CG14_MCTL_POWERCTL);
    685 		else
    686 			sc->sc_ctl->ctl_mctl &= ~CG14_MCTL_ENABLEVID;
    687 	}
    688 }
    689 
    690 /* Get status of video display */
    691 static int
    692 cg14_get_video(struct cgfourteen_softc *sc)
    693 {
    694 	return ((sc->sc_ctl->ctl_mctl & CG14_MCTL_ENABLEVID) != 0);
    695 }
    696 
    697 /* Read the software shadow colormap */
    698 static int
    699 cg14_get_cmap(struct fbcmap *p, union cg14cmap *cm, int cmsize)
    700 {
    701         u_int i, start, count;
    702         u_char *cp;
    703         int error;
    704 
    705         start = p->index;
    706         count = p->count;
    707         if (start >= cmsize || count > cmsize - start)
    708                 return (EINVAL);
    709 
    710         for (cp = &cm->cm_map[start][0], i = 0; i < count; cp += 4, i++) {
    711                 error = copyout(&cp[3], &p->red[i], 1);
    712                 if (error)
    713                         return error;
    714                 error = copyout(&cp[2], &p->green[i], 1);
    715                 if (error)
    716                         return error;
    717                 error = copyout(&cp[1], &p->blue[i], 1);
    718                 if (error)
    719                         return error;
    720         }
    721         return (0);
    722 }
    723 
    724 /* Write the software shadow colormap */
    725 static int
    726 cg14_put_cmap(struct fbcmap *p, union cg14cmap *cm, int cmsize)
    727 {
    728         u_int i, start, count;
    729         u_char *cp;
    730         u_char cmap[256][4];
    731         int error;
    732 
    733         start = p->index;
    734         count = p->count;
    735         if (start >= cmsize || count > cmsize - start)
    736                 return (EINVAL);
    737 
    738         memcpy(&cmap, &cm->cm_map, sizeof cmap);
    739         for (cp = &cmap[start][0], i = 0; i < count; cp += 4, i++) {
    740                 error = copyin(&p->red[i], &cp[3], 1);
    741                 if (error)
    742                         return error;
    743                 error = copyin(&p->green[i], &cp[2], 1);
    744                 if (error)
    745                         return error;
    746                 error = copyin(&p->blue[i], &cp[1], 1);
    747                 if (error)
    748                         return error;
    749                 cp[0] = 0;      /* no alpha channel */
    750         }
    751         memcpy(&cm->cm_map, &cmap, sizeof cmap);
    752         return (0);
    753 }
    754 
    755 static void
    756 cg14_load_hwcmap(struct cgfourteen_softc *sc, int start, int ncolors)
    757 {
    758 	/* XXX switch to auto-increment, and on retrace intr */
    759 
    760 	/* Setup pointers to source and dest */
    761 	uint32_t *colp = &sc->sc_cmap.cm_chip[start];
    762 	volatile uint32_t *lutp = &sc->sc_clut1->clut_lut[start];
    763 
    764 	/* Copy by words */
    765 	while (--ncolors >= 0)
    766 		*lutp++ = *colp++;
    767 }
    768 
    769 #if NWSDISPLAY > 0
    770 static void
    771 cg14_setup_wsdisplay(struct cgfourteen_softc *sc, int is_cons)
    772 {
    773 	struct wsemuldisplaydev_attach_args aa;
    774 	struct rasops_info *ri;
    775 	long defattr;
    776 
    777  	sc->sc_defaultscreen_descr = (struct wsscreen_descr){
    778 		"default",
    779 		0, 0,
    780 		NULL,
    781 		8, 16,
    782 		WSSCREEN_WSCOLORS | WSSCREEN_HILIT,
    783 		NULL
    784 	};
    785 	sc->sc_screens[0] = &sc->sc_defaultscreen_descr;
    786 	sc->sc_screenlist = (struct wsscreen_list){1, sc->sc_screens};
    787 	sc->sc_mode = WSDISPLAYIO_MODE_EMUL;
    788 	vcons_init(&sc->sc_vd, sc, &sc->sc_defaultscreen_descr,
    789 	    &cg14_accessops);
    790 	sc->sc_vd.init_screen = cg14_init_screen;
    791 
    792 	ri = &sc->sc_console_screen.scr_ri;
    793 
    794 	if (is_cons) {
    795 		vcons_init_screen(&sc->sc_vd, &sc->sc_console_screen, 1,
    796 		    &defattr);
    797 
    798 		/* clear the screen with the default background colour */
    799 		memset(sc->sc_fb.fb_pixels,
    800 		       (defattr >> 16) & 0xff,
    801 		       ri->ri_stride * ri->ri_height);
    802 		sc->sc_console_screen.scr_flags |= VCONS_SCREEN_IS_STATIC;
    803 
    804 		sc->sc_defaultscreen_descr.textops = &ri->ri_ops;
    805 		sc->sc_defaultscreen_descr.capabilities = ri->ri_caps;
    806 		sc->sc_defaultscreen_descr.nrows = ri->ri_rows;
    807 		sc->sc_defaultscreen_descr.ncols = ri->ri_cols;
    808 		wsdisplay_cnattach(&sc->sc_defaultscreen_descr, ri, 0, 0,
    809 		    defattr);
    810 		vcons_replay_msgbuf(&sc->sc_console_screen);
    811 	} else {
    812 		/*
    813 		 * since we're not the console we can postpone the rest
    814 		 * until someone actually allocates a screen for us
    815 		 */
    816 	}
    817 
    818 	cg14_init_cmap(sc);
    819 
    820 	aa.console = is_cons;
    821 	aa.scrdata = &sc->sc_screenlist;
    822 	aa.accessops = &cg14_accessops;
    823 	aa.accesscookie = &sc->sc_vd;
    824 
    825 	config_found(sc->sc_dev, &aa, wsemuldisplaydevprint);
    826 }
    827 
    828 static void
    829 cg14_init_cmap(struct cgfourteen_softc *sc)
    830 {
    831 	int i, j = 0;
    832 
    833 	for (i = 0; i < 256; i++) {
    834 
    835 		sc->sc_cmap.cm_map[i][3] = rasops_cmap[j];
    836 		sc->sc_cmap.cm_map[i][2] = rasops_cmap[j + 1];
    837 		sc->sc_cmap.cm_map[i][1] = rasops_cmap[j + 2];
    838 		j += 3;
    839 	}
    840 	cg14_load_hwcmap(sc, 0, 256);
    841 }
    842 
    843 static int
    844 cg14_putcmap(struct cgfourteen_softc *sc, struct wsdisplay_cmap *cm)
    845 {
    846 	u_int index = cm->index;
    847 	u_int count = cm->count;
    848 	int i, error;
    849 	u_char rbuf[256], gbuf[256], bbuf[256];
    850 
    851 	if (cm->index >= 256 || cm->count > 256 ||
    852 	    (cm->index + cm->count) > 256)
    853 		return EINVAL;
    854 	error = copyin(cm->red, &rbuf[index], count);
    855 	if (error)
    856 		return error;
    857 	error = copyin(cm->green, &gbuf[index], count);
    858 	if (error)
    859 		return error;
    860 	error = copyin(cm->blue, &bbuf[index], count);
    861 	if (error)
    862 		return error;
    863 
    864 	for (i = 0; i < count; i++) {
    865 		sc->sc_cmap.cm_map[index][3] = rbuf[index];
    866 		sc->sc_cmap.cm_map[index][2] = gbuf[index];
    867 		sc->sc_cmap.cm_map[index][1] = bbuf[index];
    868 
    869 		index++;
    870 	}
    871 	cg14_load_hwcmap(sc, 0, 256);
    872 	return 0;
    873 }
    874 
    875 static int
    876 cg14_getcmap(struct cgfourteen_softc *sc, struct wsdisplay_cmap *cm)
    877 {
    878 	uint8_t rbuf[256], gbuf[256], bbuf[256];
    879 	u_int index = cm->index;
    880 	u_int count = cm->count;
    881 	int error, i;
    882 
    883 	if (index >= 255 || count > 256 || index + count > 256)
    884 		return EINVAL;
    885 
    886 
    887 	for (i = 0; i < count; i++) {
    888 		rbuf[i] = sc->sc_cmap.cm_map[index][3];
    889 		gbuf[i] = sc->sc_cmap.cm_map[index][2];
    890 		bbuf[i] = sc->sc_cmap.cm_map[index][1];
    891 
    892 		index++;
    893 	}
    894 	error = copyout(rbuf,   cm->red,   count);
    895 	if (error)
    896 		return error;
    897 	error = copyout(gbuf, cm->green, count);
    898 	if (error)
    899 		return error;
    900 	error = copyout(bbuf,  cm->blue,  count);
    901 	if (error)
    902 		return error;
    903 
    904 	return 0;
    905 }
    906 
    907 static int
    908 cg14_ioctl(void *v, void *vs, u_long cmd, void *data, int flag,
    909 	struct lwp *l)
    910 {
    911 	struct vcons_data *vd = v;
    912 	struct cgfourteen_softc *sc = vd->cookie;
    913 	struct wsdisplay_fbinfo *wdf;
    914 	struct vcons_screen *ms = vd->active;
    915 
    916 	switch (cmd) {
    917 
    918 		case WSDISPLAYIO_GTYPE:
    919 			*(uint32_t *)data = WSDISPLAY_TYPE_SUNCG14;
    920 			return 0;
    921 
    922 		case WSDISPLAYIO_GINFO:
    923 			wdf = (void *)data;
    924 			wdf->height = ms->scr_ri.ri_height;
    925 			wdf->width = ms->scr_ri.ri_width;
    926 			wdf->depth = 32;
    927 			wdf->cmsize = 256;
    928 			return 0;
    929 
    930 		case WSDISPLAYIO_GETCMAP:
    931 			return cg14_getcmap(sc,
    932 			    (struct wsdisplay_cmap *)data);
    933 
    934 		case WSDISPLAYIO_PUTCMAP:
    935 			return cg14_putcmap(sc,
    936 			    (struct wsdisplay_cmap *)data);
    937 
    938 		case WSDISPLAYIO_LINEBYTES:
    939 			*(u_int *)data = ms->scr_ri.ri_stride << 2;
    940 			return 0;
    941 
    942 		case WSDISPLAYIO_SMODE:
    943 			{
    944 				int new_mode = *(int*)data;
    945 				if (new_mode != sc->sc_mode) {
    946 					sc->sc_mode = new_mode;
    947 					if(new_mode == WSDISPLAYIO_MODE_EMUL) {
    948 						bus_space_write_1(sc->sc_bustag,
    949 						    sc->sc_regh,
    950 						    CG14_CURSOR_CONTROL, 0);
    951 
    952 						cg14_set_depth(sc, 8);
    953 						cg14_init_cmap(sc);
    954 						vcons_redraw_screen(ms);
    955 					} else {
    956 
    957 						cg14_set_depth(sc, 32);
    958 					}
    959 				}
    960 			}
    961 			return 0;
    962 		case WSDISPLAYIO_SVIDEO:
    963 			cg14_set_video(sc, *(int *)data);
    964 			return 0;
    965 		case WSDISPLAYIO_GVIDEO:
    966 			return cg14_get_video(sc) ?
    967 			    WSDISPLAYIO_VIDEO_ON : WSDISPLAYIO_VIDEO_OFF;
    968 		case WSDISPLAYIO_GCURPOS:
    969 			{
    970 				struct wsdisplay_curpos *cp = (void *)data;
    971 
    972 				cp->x = sc->sc_cursor.cc_pos.x;
    973 				cp->y = sc->sc_cursor.cc_pos.y;
    974 			}
    975 			return 0;
    976 		case WSDISPLAYIO_SCURPOS:
    977 			{
    978 				struct wsdisplay_curpos *cp = (void *)data;
    979 
    980 				cg14_move_cursor(sc, cp->x, cp->y);
    981 			}
    982 			return 0;
    983 		case WSDISPLAYIO_GCURMAX:
    984 			{
    985 				struct wsdisplay_curpos *cp = (void *)data;
    986 
    987 				cp->x = 32;
    988 				cp->y = 32;
    989 			}
    990 			return 0;
    991 		case WSDISPLAYIO_SCURSOR:
    992 			{
    993 				struct wsdisplay_cursor *cursor = (void *)data;
    994 
    995 				return cg14_do_cursor(sc, cursor);
    996 			}
    997 		case PCI_IOC_CFGREAD:
    998 		case PCI_IOC_CFGWRITE:
    999 			return EINVAL;
   1000 
   1001 	}
   1002 	return EPASSTHROUGH;
   1003 }
   1004 
   1005 static paddr_t
   1006 cg14_mmap(void *v, void *vs, off_t offset, int prot)
   1007 {
   1008 	struct vcons_data *vd = v;
   1009 	struct cgfourteen_softc *sc = vd->cookie;
   1010 
   1011 	/* allow mmap()ing the full framebuffer, not just what we use */
   1012 	if (offset < sc->sc_vramsize)
   1013 		return bus_space_mmap(sc->sc_bustag,
   1014 		    BUS_ADDR(sc->sc_physadr[CG14_PXL_IDX].sbr_slot,
   1015 		      sc->sc_physadr[CG14_PXL_IDX].sbr_offset),
   1016 		    offset + CG14_FB_CBGR, prot, BUS_SPACE_MAP_LINEAR);
   1017 
   1018 	return -1;
   1019 }
   1020 
   1021 static void
   1022 cg14_init_screen(void *cookie, struct vcons_screen *scr,
   1023     int existing, long *defattr)
   1024 {
   1025 	struct cgfourteen_softc *sc = cookie;
   1026 	struct rasops_info *ri = &scr->scr_ri;
   1027 
   1028 	ri->ri_depth = 8;
   1029 	ri->ri_width = sc->sc_fb.fb_type.fb_width;
   1030 	ri->ri_height = sc->sc_fb.fb_type.fb_height;
   1031 	ri->ri_stride = ri->ri_width;
   1032 	ri->ri_flg = RI_CENTER | RI_FULLCLEAR;
   1033 
   1034 	ri->ri_bits = (char *)sc->sc_fb.fb_pixels;
   1035 #if NSX > 0
   1036 	/*
   1037 	 * unaligned copies with horizontal overlap are slow, so don't bother
   1038 	 * handling them in cg14_bitblt() and use putchar() instead
   1039 	 */
   1040 	if (sc->sc_sx != NULL) {
   1041 		scr->scr_flags |= VCONS_NO_COPYCOLS;
   1042 	} else
   1043 #endif
   1044 	scr->scr_flags |= VCONS_DONT_READ;
   1045 
   1046 	if (existing) {
   1047 		ri->ri_flg |= RI_CLEAR;
   1048 	}
   1049 
   1050 	rasops_init(ri, 0, 0);
   1051 	ri->ri_caps = WSSCREEN_WSCOLORS;
   1052 
   1053 	rasops_reconfig(ri,
   1054 	    sc->sc_fb.fb_type.fb_height / ri->ri_font->fontheight,
   1055 	    sc->sc_fb.fb_type.fb_width / ri->ri_font->fontwidth);
   1056 
   1057 	ri->ri_hw = scr;
   1058 #if NSX > 0
   1059 	if (sc->sc_sx != NULL) {
   1060 		ri->ri_ops.copyrows = cg14_copyrows;
   1061 		ri->ri_ops.copycols = cg14_copycols;
   1062 		ri->ri_ops.eraserows = cg14_eraserows;
   1063 		ri->ri_ops.erasecols = cg14_erasecols;
   1064 		ri->ri_ops.cursor = cg14_cursor;
   1065 #if 0
   1066 		if (FONT_IS_ALPHA(ri->ri_font)) {
   1067 			ri->ri_ops.putchar = cg14_putchar_aa;
   1068 		} else
   1069 #endif
   1070 			ri->ri_ops.putchar = cg14_putchar;
   1071 	}
   1072 #endif /* NSX > 0 */
   1073 }
   1074 
   1075 static void
   1076 cg14_set_depth(struct cgfourteen_softc *sc, int depth)
   1077 {
   1078 	int i;
   1079 
   1080 	if (sc->sc_depth == depth)
   1081 		return;
   1082 
   1083 	switch (depth) {
   1084 		case 8:
   1085 			bus_space_write_1(sc->sc_bustag, sc->sc_regh,
   1086 			    CG14_MCTL, CG14_MCTL_ENABLEVID |
   1087 			    CG14_MCTL_PIXMODE_8 | CG14_MCTL_POWERCTL);
   1088 			sc->sc_depth = 8;
   1089 			/* everything is CLUT1 */
   1090 			for (i = 0; i < CG14_CLUT_SIZE; i++)
   1091 			     sc->sc_xlut->xlut_lut[i] = 0;
   1092 			break;
   1093 		case 32:
   1094 			bus_space_write_1(sc->sc_bustag, sc->sc_regh,
   1095 			    CG14_MCTL, CG14_MCTL_ENABLEVID |
   1096 			    CG14_MCTL_PIXMODE_32 | CG14_MCTL_POWERCTL);
   1097 			sc->sc_depth = 32;
   1098 			for (i = 0; i < CG14_CLUT_SIZE; i++)
   1099 			     sc->sc_xlut->xlut_lut[i] = 0;
   1100 			break;
   1101 		default:
   1102 			printf("%s: can't change to depth %d\n",
   1103 			    device_xname(sc->sc_dev), depth);
   1104 	}
   1105 }
   1106 
   1107 static void
   1108 cg14_move_cursor(struct cgfourteen_softc *sc, int x, int y)
   1109 {
   1110 	uint32_t pos;
   1111 
   1112 	sc->sc_cursor.cc_pos.x = x;
   1113 	sc->sc_cursor.cc_pos.y = y;
   1114 	pos = ((sc->sc_cursor.cc_pos.x - sc->sc_cursor.cc_hot.x ) << 16) |
   1115 	      ((sc->sc_cursor.cc_pos.y - sc->sc_cursor.cc_hot.y ) & 0xffff);
   1116 	bus_space_write_4(sc->sc_bustag, sc->sc_regh, CG14_CURSOR_X, pos);
   1117 }
   1118 
   1119 static int
   1120 cg14_do_cursor(struct cgfourteen_softc *sc, struct wsdisplay_cursor *cur)
   1121 {
   1122 	if (cur->which & WSDISPLAY_CURSOR_DOCUR) {
   1123 
   1124 		bus_space_write_1(sc->sc_bustag, sc->sc_regh,
   1125 		    CG14_CURSOR_CONTROL, cur->enable ? CG14_CRSR_ENABLE : 0);
   1126 	}
   1127 	if (cur->which & WSDISPLAY_CURSOR_DOHOT) {
   1128 
   1129 		sc->sc_cursor.cc_hot.x = cur->hot.x;
   1130 		sc->sc_cursor.cc_hot.y = cur->hot.y;
   1131 		cur->which |= WSDISPLAY_CURSOR_DOPOS;
   1132 	}
   1133 	if (cur->which & WSDISPLAY_CURSOR_DOPOS) {
   1134 
   1135 		cg14_move_cursor(sc, cur->pos.x, cur->pos.y);
   1136 	}
   1137 	if (cur->which & WSDISPLAY_CURSOR_DOCMAP) {
   1138 		int i;
   1139 		uint32_t val;
   1140 
   1141 		for (i = 0; i < min(cur->cmap.count, 3); i++) {
   1142 			val = (cur->cmap.red[i] ) |
   1143 			      (cur->cmap.green[i] << 8) |
   1144 			      (cur->cmap.blue[i] << 16);
   1145 			bus_space_write_4(sc->sc_bustag, sc->sc_regh,
   1146 			    CG14_CURSOR_COLOR1 + ((i + cur->cmap.index) << 2),
   1147 			    val);
   1148 		}
   1149 	}
   1150 	if (cur->which & WSDISPLAY_CURSOR_DOSHAPE) {
   1151 		uint32_t buffer[32], latch, tmp;
   1152 		int i;
   1153 
   1154 		copyin(cur->mask, buffer, 128);
   1155 		for (i = 0; i < 32; i++) {
   1156 			latch = 0;
   1157 			tmp = buffer[i] & 0x80808080;
   1158 			latch |= tmp >> 7;
   1159 			tmp = buffer[i] & 0x40404040;
   1160 			latch |= tmp >> 5;
   1161 			tmp = buffer[i] & 0x20202020;
   1162 			latch |= tmp >> 3;
   1163 			tmp = buffer[i] & 0x10101010;
   1164 			latch |= tmp >> 1;
   1165 			tmp = buffer[i] & 0x08080808;
   1166 			latch |= tmp << 1;
   1167 			tmp = buffer[i] & 0x04040404;
   1168 			latch |= tmp << 3;
   1169 			tmp = buffer[i] & 0x02020202;
   1170 			latch |= tmp << 5;
   1171 			tmp = buffer[i] & 0x01010101;
   1172 			latch |= tmp << 7;
   1173 			bus_space_write_4(sc->sc_bustag, sc->sc_regh,
   1174 			    CG14_CURSOR_PLANE0 + (i << 2), latch);
   1175 		}
   1176 		copyin(cur->image, buffer, 128);
   1177 		for (i = 0; i < 32; i++) {
   1178 			latch = 0;
   1179 			tmp = buffer[i] & 0x80808080;
   1180 			latch |= tmp >> 7;
   1181 			tmp = buffer[i] & 0x40404040;
   1182 			latch |= tmp >> 5;
   1183 			tmp = buffer[i] & 0x20202020;
   1184 			latch |= tmp >> 3;
   1185 			tmp = buffer[i] & 0x10101010;
   1186 			latch |= tmp >> 1;
   1187 			tmp = buffer[i] & 0x08080808;
   1188 			latch |= tmp << 1;
   1189 			tmp = buffer[i] & 0x04040404;
   1190 			latch |= tmp << 3;
   1191 			tmp = buffer[i] & 0x02020202;
   1192 			latch |= tmp << 5;
   1193 			tmp = buffer[i] & 0x01010101;
   1194 			latch |= tmp << 7;
   1195 			bus_space_write_4(sc->sc_bustag, sc->sc_regh,
   1196 			    CG14_CURSOR_PLANE1 + (i << 2), latch);
   1197 		}
   1198 	}
   1199 	return 0;
   1200 }
   1201 
   1202 #if NSX > 0
   1203 
   1204 static void
   1205 cg14_wait_idle(struct cgfourteen_softc *sc)
   1206 {
   1207 }
   1208 
   1209 static void
   1210 cg14_rectfill(struct cgfourteen_softc *sc, int x, int y, int wi, int he,
   1211      uint32_t colour)
   1212 {
   1213 	uint32_t addr, pptr;
   1214 	int line, cnt, pre, words;
   1215 	int stride = sc->sc_fb.fb_type.fb_width;
   1216 
   1217 	addr = sc->sc_fb_paddr + x + stride * y;
   1218 	sx_write(sc->sc_sx, SX_QUEUED(8), colour);
   1219 	sx_write(sc->sc_sx, SX_QUEUED(9), colour);
   1220 	/*
   1221 	 * Calculate the number of pixels we need to do one by one
   1222 	 * until we're 32bit aligned, then do the rest in 32bit
   1223 	 * mode. Assumes that stride is always a multiple of 4.
   1224 	 */
   1225 	/* TODO: use 32bit writes with byte mask instead */
   1226 	pre = addr & 3;
   1227 	if (pre != 0) pre = 4 - pre;
   1228 	for (line = 0; line < he; line++) {
   1229 		pptr = addr;
   1230 		cnt = wi;
   1231 		if (pre) {
   1232 			sta(pptr, ASI_SX, SX_STBS(8, pre - 1, pptr & 7));
   1233 			pptr += pre;
   1234 			cnt -= pre;
   1235 		}
   1236 		/* now do the aligned pixels in 32bit chunks */
   1237 		while(cnt > 31) {
   1238 			words = min(32, cnt >> 2);
   1239 			sta(pptr, ASI_SX, SX_STS(8, words - 1, pptr & 7));
   1240 			pptr += words << 2;
   1241 			cnt -= words << 2;
   1242 		}
   1243 		/* do any remaining pixels byte-wise again */
   1244 		if (cnt > 0)
   1245 			sta(pptr, ASI_SX, SX_STBS(8, cnt - 1, pptr & 7));
   1246 		addr += stride;
   1247 	}
   1248 }
   1249 
   1250 static void
   1251 cg14_invert(struct cgfourteen_softc *sc, int x, int y, int wi, int he)
   1252 {
   1253 	uint32_t addr, pptr;
   1254 	int line, cnt, pre, words;
   1255 	int stride = sc->sc_fb.fb_type.fb_width;
   1256 
   1257 	addr = sc->sc_fb_paddr + x + stride * y;
   1258 	sx_write(sc->sc_sx, SX_ROP_CONTROL, 0x33); /* ~src a */
   1259 	/*
   1260 	 * Calculate the number of pixels we need to do one by one
   1261 	 * until we're 32bit aligned, then do the rest in 32bit
   1262 	 * mode. Assumes that stride is always a multiple of 4.
   1263 	 */
   1264 	/* TODO: use 32bit writes with byte mask instead */
   1265 	pre = addr & 3;
   1266 	if (pre != 0) pre = 4 - pre;
   1267 	for (line = 0; line < he; line++) {
   1268 		pptr = addr;
   1269 		cnt = wi;
   1270 		if (pre) {
   1271 			sta(pptr, ASI_SX, SX_LDB(8, pre - 1, pptr & 7));
   1272 			sx_write(sc->sc_sx, SX_INSTRUCTIONS,
   1273 			    SX_ROP(8, 8, 32, pre - 1));
   1274 			sta(pptr, ASI_SX, SX_STB(32, pre - 1, pptr & 7));
   1275 			pptr += pre;
   1276 			cnt -= pre;
   1277 		}
   1278 		/* now do the aligned pixels in 32bit chunks */
   1279 		while(cnt > 15) {
   1280 			words = min(16, cnt >> 2);
   1281 			sta(pptr, ASI_SX, SX_LD(8, words - 1, pptr & 7));
   1282 			sx_write(sc->sc_sx, SX_INSTRUCTIONS,
   1283 			    SX_ROP(8, 8, 32, words - 1));
   1284 			sta(pptr, ASI_SX, SX_ST(32, words - 1, pptr & 7));
   1285 			pptr += words << 2;
   1286 			cnt -= words << 2;
   1287 		}
   1288 		/* do any remaining pixels byte-wise again */
   1289 		if (cnt > 0)
   1290 			sta(pptr, ASI_SX, SX_LDB(8, cnt - 1, pptr & 7));
   1291 			sx_write(sc->sc_sx, SX_INSTRUCTIONS,
   1292 			    SX_ROP(8, 8, 32, cnt - 1));
   1293 			sta(pptr, ASI_SX, SX_STB(32, cnt - 1, pptr & 7));
   1294 		addr += stride;
   1295 	}
   1296 }
   1297 
   1298 static inline void
   1299 cg14_slurp(int reg, uint32_t addr, int cnt)
   1300 {
   1301 	int num;
   1302 	while (cnt > 0) {
   1303 		num = min(32, cnt);
   1304 		sta(addr, ASI_SX, SX_LD(reg, num - 1, addr & 7));
   1305 		cnt -= num;
   1306 		reg += num;
   1307 		addr += (num << 2);
   1308 	}
   1309 }
   1310 
   1311 static inline void
   1312 cg14_spit(int reg, uint32_t addr, int cnt)
   1313 {
   1314 	int num;
   1315 	while (cnt > 0) {
   1316 		num = min(32, cnt);
   1317 		sta(addr, ASI_SX, SX_ST(reg, num - 1, addr & 7));
   1318 		cnt -= num;
   1319 		reg += num;
   1320 		addr += (num << 2);
   1321 	}
   1322 }
   1323 
   1324 static void
   1325 cg14_bitblt(void *cookie, int xs, int ys, int xd, int yd,
   1326     int wi, int he, int rop)
   1327 {
   1328 	struct cgfourteen_softc *sc = cookie;
   1329 	uint32_t saddr, daddr, sptr, dptr;
   1330 	int line, cnt, stride = sc->sc_fb.fb_type.fb_width;
   1331 	int num, words, skip;
   1332 
   1333 	if (ys < yd) {
   1334 		/* need to go bottom-up */
   1335 		saddr = sc->sc_fb_paddr + xs + stride * (ys + he - 1);
   1336 		daddr = sc->sc_fb_paddr + xd + stride * (yd + he - 1);
   1337 		skip = -stride;
   1338 	} else {
   1339 		saddr = sc->sc_fb_paddr + xs + stride * ys;
   1340 		daddr = sc->sc_fb_paddr + xd + stride * yd;
   1341 		skip = stride;
   1342 	}
   1343 
   1344 	if ((saddr & 3) == (daddr & 3)) {
   1345 		int pre = saddr & 3;	/* pixels to copy byte-wise */
   1346 		if (pre != 0) pre = 4 - pre;
   1347 		for (line = 0; line < he; line++) {
   1348 			sptr = saddr;
   1349 			dptr = daddr;
   1350 			cnt = wi;
   1351 			if (pre > 0) {
   1352 				sta(sptr, ASI_SX,
   1353 				    SX_LDB(32, pre - 1, sptr & 7));
   1354 				sta(dptr, ASI_SX,
   1355 				    SX_STB(32, pre - 1, dptr & 7));
   1356 				cnt -= pre;
   1357 				sptr += pre;
   1358 				dptr += pre;
   1359 			}
   1360 			words = cnt >> 2;
   1361 			while(cnt > 3) {
   1362 				num = min(120, words);
   1363 				cg14_slurp(8, sptr, num);
   1364 				cg14_spit(8, dptr, num);
   1365 				sptr += num << 2;
   1366 				dptr += num << 2;
   1367 				cnt -= num << 2;
   1368 			}
   1369 			if (cnt > 0) {
   1370 				sta(sptr, ASI_SX,
   1371 				    SX_LDB(32, cnt - 1, sptr & 7));
   1372 				sta(dptr, ASI_SX,
   1373 				    SX_STB(32, cnt - 1, dptr & 7));
   1374 			}
   1375 			saddr += skip;
   1376 			daddr += skip;
   1377 		}
   1378 	} else {
   1379 		/* unaligned, have to use byte mode */
   1380 		/* funnel shifter & byte mask trickery? */
   1381 		for (line = 0; line < he; line++) {
   1382 			sptr = saddr;
   1383 			dptr = daddr;
   1384 			cnt = wi;
   1385 			while(cnt > 31) {
   1386 				sta(sptr, ASI_SX, SX_LDB(32, 31, sptr & 7));
   1387 				sta(dptr, ASI_SX, SX_STB(32, 31, dptr & 7));
   1388 				sptr += 32;
   1389 				dptr += 32;
   1390 				cnt -= 32;
   1391 			}
   1392 			if (cnt > 0) {
   1393 				sta(sptr, ASI_SX,
   1394 				    SX_LDB(32, cnt - 1, sptr & 7));
   1395 				sta(dptr, ASI_SX,
   1396 				    SX_STB(32, cnt - 1, dptr & 7));
   1397 			}
   1398 			saddr += skip;
   1399 			daddr += skip;
   1400 		}
   1401 	}
   1402 }
   1403 
   1404 
   1405 static void
   1406 cg14_putchar(void *cookie, int row, int col, u_int c, long attr)
   1407 {
   1408 	struct rasops_info *ri = cookie;
   1409 	struct wsdisplay_font *font = PICK_FONT(ri, c);
   1410 	struct vcons_screen *scr = ri->ri_hw;
   1411 	struct cgfourteen_softc *sc = scr->scr_cookie;
   1412 	void *data;
   1413 	uint32_t fg, bg;
   1414 	int i, x, y, wi, he;
   1415 	uint32_t addr;
   1416 	int stride = sc->sc_fb.fb_type.fb_width;
   1417 
   1418 	if (sc->sc_mode != WSDISPLAYIO_MODE_EMUL)
   1419 		return;
   1420 
   1421 	if (!CHAR_IN_FONT(c, font))
   1422 		return;
   1423 
   1424 	wi = font->fontwidth;
   1425 	he = font->fontheight;
   1426 
   1427 	bg = ri->ri_devcmap[(attr >> 16) & 0xf];
   1428 	fg = ri->ri_devcmap[(attr >> 24) & 0xf];
   1429 	sx_write(sc->sc_sx, SX_QUEUED(8), bg);
   1430 	sx_write(sc->sc_sx, SX_QUEUED(9), fg);
   1431 
   1432 	x = ri->ri_xorigin + col * wi;
   1433 	y = ri->ri_yorigin + row * he;
   1434 
   1435 	if (c == 0x20) {
   1436 		cg14_rectfill(sc, x, y, wi, he, bg);
   1437 		return;
   1438 	}
   1439 
   1440 	data = WSFONT_GLYPH(c, font);
   1441 	addr = sc->sc_fb_paddr + x + stride * y;
   1442 
   1443 	switch (font->stride) {
   1444 		case 1: {
   1445 			uint8_t *data8 = data;
   1446 			uint32_t reg;
   1447 			for (i = 0; i < he; i++) {
   1448 				reg = *data8;
   1449 				sx_write(sc->sc_sx, SX_QUEUED(R_MASK),
   1450 				    reg << 24);
   1451 				sta(addr, ASI_SX, SX_STBS(8, wi - 1, addr & 7));
   1452 				data8++;
   1453 				addr += stride;
   1454 			}
   1455 			break;
   1456 		}
   1457 		case 2: {
   1458 			uint16_t *data16 = data;
   1459 			uint32_t reg;
   1460 			for (i = 0; i < he; i++) {
   1461 				reg = *data16;
   1462 				sx_write(sc->sc_sx, SX_QUEUED(R_MASK),
   1463 				    reg << 16);
   1464 				sta(addr, ASI_SX, SX_STBS(8, wi - 1, addr & 7));
   1465 				data16++;
   1466 				addr += stride;
   1467 			}
   1468 			break;
   1469 		}
   1470 	}
   1471 }
   1472 
   1473 static void
   1474 cg14_cursor(void *cookie, int on, int row, int col)
   1475 {
   1476 	struct rasops_info *ri = cookie;
   1477 	struct vcons_screen *scr = ri->ri_hw;
   1478 	struct cgfourteen_softc *sc = scr->scr_cookie;
   1479 	int x, y, wi, he;
   1480 
   1481 	wi = ri->ri_font->fontwidth;
   1482 	he = ri->ri_font->fontheight;
   1483 
   1484 	if (sc->sc_mode == WSDISPLAYIO_MODE_EMUL) {
   1485 		x = ri->ri_ccol * wi + ri->ri_xorigin;
   1486 		y = ri->ri_crow * he + ri->ri_yorigin;
   1487 		if (ri->ri_flg & RI_CURSOR) {
   1488 			cg14_invert(sc, x, y, wi, he);
   1489 			ri->ri_flg &= ~RI_CURSOR;
   1490 		}
   1491 		ri->ri_crow = row;
   1492 		ri->ri_ccol = col;
   1493 		if (on) {
   1494 			x = ri->ri_ccol * wi + ri->ri_xorigin;
   1495 			y = ri->ri_crow * he + ri->ri_yorigin;
   1496 			cg14_invert(sc, x, y, wi, he);
   1497 			ri->ri_flg |= RI_CURSOR;
   1498 		}
   1499 	} else {
   1500 		scr->scr_ri.ri_crow = row;
   1501 		scr->scr_ri.ri_ccol = col;
   1502 		scr->scr_ri.ri_flg &= ~RI_CURSOR;
   1503 	}
   1504 
   1505 }
   1506 
   1507 #if 0
   1508 static void
   1509 r128fb_putchar_aa(void *cookie, int row, int col, u_int c, long attr)
   1510 {
   1511 	struct rasops_info *ri = cookie;
   1512 	struct wsdisplay_font *font = PICK_FONT(ri, c);
   1513 	struct vcons_screen *scr = ri->ri_hw;
   1514 	struct r128fb_softc *sc = scr->scr_cookie;
   1515 	uint32_t bg, latch = 0, bg8, fg8, pixel;
   1516 	int i, x, y, wi, he, r, g, b, aval;
   1517 	int r1, g1, b1, r0, g0, b0, fgo, bgo;
   1518 	uint8_t *data8;
   1519 	int rv, cnt = 0;
   1520 
   1521 	if (sc->sc_mode != WSDISPLAYIO_MODE_EMUL)
   1522 		return;
   1523 
   1524 	if (!CHAR_IN_FONT(c, font))
   1525 		return;
   1526 
   1527 	wi = font->fontwidth;
   1528 	he = font->fontheight;
   1529 
   1530 	bg = ri->ri_devcmap[(attr >> 16) & 0xf];
   1531 	x = ri->ri_xorigin + col * wi;
   1532 	y = ri->ri_yorigin + row * he;
   1533 	if (c == 0x20) {
   1534 		r128fb_rectfill(sc, x, y, wi, he, bg);
   1535 		return;
   1536 	}
   1537 
   1538 	rv = glyphcache_try(&sc->sc_gc, c, x, y, attr);
   1539 	if (rv == GC_OK)
   1540 		return;
   1541 
   1542 	data8 = WSFONT_GLYPH(c, font);
   1543 
   1544 	r128fb_wait(sc, 5);
   1545 	bus_space_write_4(sc->sc_memt, sc->sc_regh,
   1546 	    R128_DP_GUI_MASTER_CNTL,
   1547 	    R128_GMC_BRUSH_SOLID_COLOR |
   1548 	    R128_GMC_SRC_DATATYPE_COLOR |
   1549 	    R128_ROP3_S |
   1550 	    R128_DP_SRC_SOURCE_HOST_DATA |
   1551 	    sc->sc_master_cntl);
   1552 
   1553 	bus_space_write_4(sc->sc_memt, sc->sc_regh,
   1554 	    R128_DP_CNTL,
   1555 	    R128_DST_Y_TOP_TO_BOTTOM |
   1556 	    R128_DST_X_LEFT_TO_RIGHT);
   1557 
   1558 	/* needed? */
   1559 	bus_space_write_4(sc->sc_memt, sc->sc_regh, R128_SRC_X_Y, 0);
   1560 	bus_space_write_4(sc->sc_memt, sc->sc_regh, R128_DST_X_Y,
   1561 	    (x << 16) | y);
   1562 	bus_space_write_4(sc->sc_memt, sc->sc_regh, R128_DST_WIDTH_HEIGHT,
   1563 	    (wi << 16) | he);
   1564 
   1565 	/*
   1566 	 * we need the RGB colours here, so get offsets into rasops_cmap
   1567 	 */
   1568 	fgo = ((attr >> 24) & 0xf) * 3;
   1569 	bgo = ((attr >> 16) & 0xf) * 3;
   1570 
   1571 	r0 = rasops_cmap[bgo];
   1572 	r1 = rasops_cmap[fgo];
   1573 	g0 = rasops_cmap[bgo + 1];
   1574 	g1 = rasops_cmap[fgo + 1];
   1575 	b0 = rasops_cmap[bgo + 2];
   1576 	b1 = rasops_cmap[fgo + 2];
   1577 #define R3G3B2(r, g, b) ((r & 0xe0) | ((g >> 3) & 0x1c) | (b >> 6))
   1578 	bg8 = R3G3B2(r0, g0, b0);
   1579 	fg8 = R3G3B2(r1, g1, b1);
   1580 
   1581 	r128fb_wait(sc, 16);
   1582 
   1583 	for (i = 0; i < ri->ri_fontscale; i++) {
   1584 		aval = *data8;
   1585 		if (aval == 0) {
   1586 			pixel = bg8;
   1587 		} else if (aval == 255) {
   1588 			pixel = fg8;
   1589 		} else {
   1590 			r = aval * r1 + (255 - aval) * r0;
   1591 			g = aval * g1 + (255 - aval) * g0;
   1592 			b = aval * b1 + (255 - aval) * b0;
   1593 			pixel = ((r & 0xe000) >> 8) |
   1594 				((g & 0xe000) >> 11) |
   1595 				((b & 0xc000) >> 14);
   1596 		}
   1597 		latch = (latch << 8) | pixel;
   1598 		/* write in 32bit chunks */
   1599 		if ((i & 3) == 3) {
   1600 			bus_space_write_stream_4(sc->sc_memt, sc->sc_regh,
   1601 			    R128_HOST_DATA0, latch);
   1602 			/*
   1603 			 * not strictly necessary, old data should be shifted
   1604 			 * out
   1605 			 */
   1606 			latch = 0;
   1607 			cnt++;
   1608 			if (cnt > 15) {
   1609 				r128fb_wait(sc, 16);
   1610 				cnt = 0;
   1611 			}
   1612 		}
   1613 		data8++;
   1614 	}
   1615 	/* if we have pixels left in latch write them out */
   1616 	if ((i & 3) != 0) {
   1617 		latch = latch << ((4 - (i & 3)) << 3);
   1618 		bus_space_write_stream_4(sc->sc_memt, sc->sc_regh,
   1619 				    R128_HOST_DATA0, latch);
   1620 	}
   1621 	if (rv == GC_ADD) {
   1622 		glyphcache_add(&sc->sc_gc, c, x, y);
   1623 	}
   1624 }
   1625 #endif
   1626 
   1627 static void
   1628 cg14_copycols(void *cookie, int row, int srccol, int dstcol, int ncols)
   1629 {
   1630 	struct rasops_info *ri = cookie;
   1631 	struct vcons_screen *scr = ri->ri_hw;
   1632 	struct cgfourteen_softc *sc = scr->scr_cookie;
   1633 	int32_t xs, xd, y, width, height;
   1634 
   1635 	if (sc->sc_mode == WSDISPLAYIO_MODE_EMUL) {
   1636 		xs = ri->ri_xorigin + ri->ri_font->fontwidth * srccol;
   1637 		xd = ri->ri_xorigin + ri->ri_font->fontwidth * dstcol;
   1638 		y = ri->ri_yorigin + ri->ri_font->fontheight * row;
   1639 		width = ri->ri_font->fontwidth * ncols;
   1640 		height = ri->ri_font->fontheight;
   1641 		cg14_bitblt(sc, xs, y, xd, y, width, height, 0x0c);
   1642 	}
   1643 }
   1644 
   1645 static void
   1646 cg14_erasecols(void *cookie, int row, int startcol, int ncols, long fillattr)
   1647 {
   1648 	struct rasops_info *ri = cookie;
   1649 	struct vcons_screen *scr = ri->ri_hw;
   1650 	struct cgfourteen_softc *sc = scr->scr_cookie;
   1651 	int32_t x, y, width, height, fg, bg, ul;
   1652 
   1653 	if (sc->sc_mode == WSDISPLAYIO_MODE_EMUL) {
   1654 		x = ri->ri_xorigin + ri->ri_font->fontwidth * startcol;
   1655 		y = ri->ri_yorigin + ri->ri_font->fontheight * row;
   1656 		width = ri->ri_font->fontwidth * ncols;
   1657 		height = ri->ri_font->fontheight;
   1658 		rasops_unpack_attr(fillattr, &fg, &bg, &ul);
   1659 
   1660 		cg14_rectfill(sc, x, y, width, height, ri->ri_devcmap[bg]);
   1661 	}
   1662 }
   1663 
   1664 static void
   1665 cg14_copyrows(void *cookie, int srcrow, int dstrow, int nrows)
   1666 {
   1667 	struct rasops_info *ri = cookie;
   1668 	struct vcons_screen *scr = ri->ri_hw;
   1669 	struct cgfourteen_softc *sc = scr->scr_cookie;
   1670 	int32_t x, ys, yd, width, height;
   1671 
   1672 	if (sc->sc_mode == WSDISPLAYIO_MODE_EMUL) {
   1673 		x = ri->ri_xorigin;
   1674 		ys = ri->ri_yorigin + ri->ri_font->fontheight * srcrow;
   1675 		yd = ri->ri_yorigin + ri->ri_font->fontheight * dstrow;
   1676 		width = ri->ri_emuwidth;
   1677 		height = ri->ri_font->fontheight * nrows;
   1678 		cg14_bitblt(sc, x, ys, x, yd, width, height, 0x0c);
   1679 	}
   1680 }
   1681 
   1682 static void
   1683 cg14_eraserows(void *cookie, int row, int nrows, long fillattr)
   1684 {
   1685 	struct rasops_info *ri = cookie;
   1686 	struct vcons_screen *scr = ri->ri_hw;
   1687 	struct cgfourteen_softc *sc = scr->scr_cookie;
   1688 	int32_t x, y, width, height, fg, bg, ul;
   1689 
   1690 	if (sc->sc_mode == WSDISPLAYIO_MODE_EMUL) {
   1691 		x = ri->ri_xorigin;
   1692 		y = ri->ri_yorigin + ri->ri_font->fontheight * row;
   1693 		width = ri->ri_emuwidth;
   1694 		height = ri->ri_font->fontheight * nrows;
   1695 		rasops_unpack_attr(fillattr, &fg, &bg, &ul);
   1696 
   1697 		cg14_rectfill(sc, x, y, width, height, ri->ri_devcmap[bg]);
   1698 	}
   1699 }
   1700 
   1701 #endif /* NSX > 0 */
   1702 
   1703 #endif
   1704