Home | History | Annotate | Line # | Download | only in sbus
tcx.c revision 1.37
      1 /*	$NetBSD: tcx.c,v 1.37 2009/08/20 00:59:28 macallan Exp $ */
      2 
      3 /*
      4  *  Copyright (c) 1996, 1998, 2009 The NetBSD Foundation, Inc.
      5  *  All rights reserved.
      6  *
      7  *  This code is derived from software contributed to The NetBSD Foundation
      8  *  by Paul Kranenburg and Michael Lorenz.
      9  *
     10  *  Redistribution and use in source and binary forms, with or without
     11  *  modification, are permitted provided that the following conditions
     12  *  are met:
     13  *  1. Redistributions of source code must retain the above copyright
     14  *     notice, this list of conditions and the following disclaimer.
     15  *  2. Redistributions in binary form must reproduce the above copyright
     16  *     notice, this list of conditions and the following disclaimer in the
     17  *     documentation and/or other materials provided with the distribution.
     18  *
     19  *  THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20  *  ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21  *  TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22  *  PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23  *  BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24  *  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25  *  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26  *  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27  *  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28  *  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29  *  POSSIBILITY OF SUCH DAMAGE.
     30  */
     31 
     32 /*
     33  * color display (TCX) driver.
     34  *
     35  * Does not handle interrupts, even though they can occur.
     36  *
     37  * XXX should defer colormap updates to vertical retrace interrupts
     38  */
     39 
     40 #include <sys/cdefs.h>
     41 __KERNEL_RCSID(0, "$NetBSD: tcx.c,v 1.37 2009/08/20 00:59:28 macallan Exp $");
     42 
     43 /*
     44  * define for cg8 emulation on S24 (24-bit version of tcx) for the SS5;
     45  * it is bypassed on the 8-bit version (onboard framebuffer for SS4)
     46  */
     47 #undef TCX_CG8
     48 
     49 #include <sys/param.h>
     50 #include <sys/systm.h>
     51 #include <sys/buf.h>
     52 #include <sys/device.h>
     53 #include <sys/ioctl.h>
     54 #include <sys/malloc.h>
     55 #include <sys/mman.h>
     56 #include <sys/tty.h>
     57 #include <sys/conf.h>
     58 
     59 #ifdef DEBUG
     60 #include <sys/proc.h>
     61 #include <sys/syslog.h>
     62 #endif
     63 
     64 #include <sys/bus.h>
     65 #include <machine/autoconf.h>
     66 
     67 #include <dev/sun/fbio.h>
     68 #include <dev/sun/fbvar.h>
     69 #include <dev/sun/btreg.h>
     70 #include <dev/sun/btvar.h>
     71 
     72 #include <dev/sbus/sbusvar.h>
     73 #include <dev/sbus/tcxreg.h>
     74 
     75 #include <dev/wscons/wsdisplayvar.h>
     76 #include <dev/wscons/wsconsio.h>
     77 #include <dev/wsfont/wsfont.h>
     78 #include <dev/rasops/rasops.h>
     79 
     80 #include <dev/wscons/wsdisplay_vconsvar.h>
     81 
     82 #include "opt_wsemul.h"
     83 
     84 /* per-display variables */
     85 struct tcx_softc {
     86 	device_t	sc_dev;		/* base device */
     87 	struct sbusdev	sc_sd;		/* sbus device */
     88 	struct fbdevice	sc_fb;		/* frame buffer device */
     89 	bus_space_tag_t	sc_bustag;
     90 	struct openprom_addr sc_physaddr[TCX_NREG];/* phys addr of h/w */
     91 
     92 	bus_space_handle_t sc_bt;	/* Brooktree registers */
     93 	bus_space_handle_t sc_thc;	/* THC registers */
     94 	uint8_t *sc_fbaddr;		/* framebuffer */
     95 	uint64_t *sc_rblit;		/* blitspace */
     96 	uint64_t *sc_rstip;		/* stipple space */
     97 
     98 	short	sc_8bit;		/* true if 8-bit hardware */
     99 	short	sc_blanked;		/* true if blanked */
    100 	u_char	sc_cmap_red[256];
    101 	u_char	sc_cmap_green[256];
    102 	u_char	sc_cmap_blue[256];
    103 	int 	sc_mode, sc_bg;
    104 	int	sc_cursor_x, sc_cursor_y;
    105 	int	sc_hotspot_x, sc_hotspot_y;
    106 	struct vcons_data vd;
    107 };
    108 
    109 static struct vcons_screen tcx_console_screen;
    110 
    111 extern const u_char rasops_cmap[768];
    112 
    113 struct wsscreen_descr tcx_defscreendesc = {
    114 	"default",
    115 	0, 0,
    116 	NULL,
    117 	8, 16,
    118 	WSSCREEN_WSCOLORS,
    119 };
    120 
    121 const struct wsscreen_descr *_tcx_scrlist[] = {
    122 	&tcx_defscreendesc,
    123 	/* XXX other formats, graphics screen? */
    124 };
    125 
    126 struct wsscreen_list tcx_screenlist = {
    127 	sizeof(_tcx_scrlist) / sizeof(struct wsscreen_descr *),
    128 	_tcx_scrlist
    129 };
    130 
    131 /*
    132  * The S24 provides the framebuffer RAM mapped in three ways:
    133  * 26 bits per pixel, in 32-bit words; the low-order 24 bits are
    134  * blue, green, and red values, and the other two bits select the
    135  * display modes, per pixel);
    136  * 24 bits per pixel, in 32-bit words; the high-order byte reads as
    137  * zero, and is ignored on writes (so the mode bits cannot be altered);
    138  * 8 bits per pixel, unpadded; writes to this space do not modify the
    139  * other 18 bits.
    140  */
    141 #define TCX_CTL_8_MAPPED	0x00000000	/* 8 bits, uses color map */
    142 #define TCX_CTL_24_MAPPED	0x01000000	/* 24 bits, uses color map */
    143 #define TCX_CTL_24_LEVEL	0x03000000	/* 24 bits, ignores color map */
    144 #define TCX_CTL_PIXELMASK	0x00FFFFFF	/* mask for index/level */
    145 
    146 /* autoconfiguration driver */
    147 static void	tcxattach(device_t, device_t, void *);
    148 static int	tcxmatch(device_t, cfdata_t, void *);
    149 static void	tcx_unblank(device_t);
    150 
    151 CFATTACH_DECL_NEW(tcx, sizeof(struct tcx_softc),
    152     tcxmatch, tcxattach, NULL, NULL);
    153 
    154 extern struct cfdriver tcx_cd;
    155 
    156 dev_type_open(tcxopen);
    157 dev_type_close(tcxclose);
    158 dev_type_ioctl(tcxioctl);
    159 dev_type_mmap(tcxmmap);
    160 
    161 const struct cdevsw tcx_cdevsw = {
    162 	tcxopen, tcxclose, noread, nowrite, tcxioctl,
    163 	nostop, notty, nopoll, tcxmmap, nokqfilter,
    164 };
    165 
    166 /* frame buffer generic driver */
    167 static struct fbdriver tcx_fbdriver = {
    168 	tcx_unblank, tcxopen, tcxclose, tcxioctl, nopoll, tcxmmap,
    169 	nokqfilter
    170 };
    171 
    172 static void tcx_reset(struct tcx_softc *);
    173 static void tcx_loadcmap(struct tcx_softc *, int, int);
    174 
    175 static int	tcx_ioctl(void *, void *, u_long, void *, int, struct lwp *);
    176 static paddr_t	tcx_mmap(void *, void *, off_t, int);
    177 
    178 static void	tcx_init_screen(void *, struct vcons_screen *, int, long *);
    179 static void	tcx_clearscreen(struct tcx_softc *, int);
    180 static void	tcx_copyrows(void *, int, int, int);
    181 static void	tcx_eraserows(void *, int, int, long);
    182 static void	tcx_putchar(void *, int, int, u_int, long);
    183 static void	tcx_set_video(struct tcx_softc *, int);
    184 static int	tcx_do_cursor(struct tcx_softc *, struct wsdisplay_cursor *);
    185 static void	tcx_set_cursor(struct tcx_softc *);
    186 
    187 struct wsdisplay_accessops tcx_accessops = {
    188 	tcx_ioctl,
    189 	tcx_mmap,
    190 	NULL,	/* vcons_alloc_screen */
    191 	NULL,	/* vcons_free_screen */
    192 	NULL,	/* vcons_show_screen */
    193 	NULL,	/* load_font */
    194 	NULL,	/* polls */
    195 	NULL,	/* scroll */
    196 };
    197 
    198 #define OBPNAME	"SUNW,tcx"
    199 
    200 #ifdef TCX_CG8
    201 /*
    202  * For CG8 emulation, we map the 32-bit-deep framebuffer at an offset of
    203  * 256K; the cg8 space begins with a mono overlay plane and an overlay
    204  * enable plane (128K bytes each, 1 bit per pixel), immediately followed
    205  * by the color planes, 32 bits per pixel.  We also map just the 32-bit
    206  * framebuffer at 0x04000000 (TCX_USER_RAM_COMPAT), for compatibility
    207  * with the cg8 driver.
    208  */
    209 #define	TCX_CG8OVERLAY	(256 * 1024)
    210 #define	TCX_SIZE_DFB32	(1152 * 900 * 4) /* max size of the framebuffer */
    211 #endif
    212 
    213 /*
    214  * Match a tcx.
    215  */
    216 int
    217 tcxmatch(device_t parent, cfdata_t cf, void *aux)
    218 {
    219 	struct sbus_attach_args *sa = aux;
    220 
    221 	return (strcmp(sa->sa_name, OBPNAME) == 0);
    222 }
    223 
    224 /*
    225  * Attach a display.
    226  */
    227 void
    228 tcxattach(device_t parent, device_t self, void *args)
    229 {
    230 	struct tcx_softc *sc = device_private(self);
    231 	struct sbus_attach_args *sa = args;
    232 	struct wsemuldisplaydev_attach_args aa;
    233 	struct rasops_info *ri;
    234 	unsigned long defattr;
    235 	int node, ramsize;
    236 	struct fbdevice *fb = &sc->sc_fb;
    237 	bus_space_handle_t bh;
    238 	int isconsole, i, j;
    239 	uint32_t confreg;
    240 
    241 	sc->sc_dev = self;
    242 	sc->sc_bustag = sa->sa_bustag;
    243 	node = sa->sa_node;
    244 
    245 	sc->sc_cursor_x = 0x7fff;
    246 	sc->sc_cursor_y = 0x7fff;
    247 	sc->sc_hotspot_x = 0;
    248 	sc->sc_hotspot_y = 0;
    249 
    250 	fb->fb_driver = &tcx_fbdriver;
    251 	fb->fb_device = sc->sc_dev;
    252 	/* Mask out invalid flags from the user. */
    253 	fb->fb_flags = device_cfdata(sc->sc_dev)->cf_flags & FB_USERMASK;
    254 	/*
    255 	 * The onboard framebuffer on the SS4 supports only 8-bit mode;
    256 	 * it can be distinguished from the S24 card for the SS5 by the
    257 	 * presence of the "tcx-8-bit" attribute on the SS4 version.
    258 	 */
    259 	sc->sc_8bit = node_has_property(node, "tcx-8-bit");
    260 	fb->fb_type.fb_depth = 8;
    261 	fb_setsize_obp(fb, fb->fb_type.fb_depth, 1152, 900, node);
    262 
    263 	if (sc->sc_8bit) {
    264 		printf(" (8bit only TCX)");
    265 		ramsize = 1024 * 1024;
    266 		/* XXX - fix THC and TEC offsets */
    267 		sc->sc_physaddr[TCX_REG_TEC].oa_base += 0x1000;
    268 		sc->sc_physaddr[TCX_REG_THC].oa_base += 0x1000;
    269 	} else {
    270 		printf(" (S24)\n");
    271 		ramsize = 4 * 1024 * 1024;
    272 	}
    273 
    274 	fb->fb_type.fb_cmsize = 256;
    275 	fb->fb_type.fb_size = ramsize;
    276 	printf(": %s, %d x %d", OBPNAME,
    277 		fb->fb_type.fb_width,
    278 		fb->fb_type.fb_height);
    279 
    280 	fb->fb_type.fb_type = FBTYPE_SUNTCX;
    281 
    282 
    283 	if (sa->sa_nreg != TCX_NREG) {
    284 		printf("%s: only %d register sets\n",
    285 			device_xname(self), sa->sa_nreg);
    286 		return;
    287 	}
    288 	memcpy(sc->sc_physaddr, sa->sa_reg,
    289 	      sa->sa_nreg * sizeof(struct openprom_addr));
    290 
    291 	/* Map the register banks we care about */
    292 	if (sbus_bus_map(sa->sa_bustag,
    293 			 sc->sc_physaddr[TCX_REG_THC].oa_space,
    294 			 sc->sc_physaddr[TCX_REG_THC].oa_base,
    295 			 0x1000,
    296 			 BUS_SPACE_MAP_LINEAR, &sc->sc_thc) != 0) {
    297 		printf("tcxattach: cannot map thc registers\n");
    298 		return;
    299 	}
    300 
    301 	if (sbus_bus_map(sa->sa_bustag,
    302 			 sc->sc_physaddr[TCX_REG_CMAP].oa_space,
    303 			 sc->sc_physaddr[TCX_REG_CMAP].oa_base,
    304 			 0x1000,
    305 			 BUS_SPACE_MAP_LINEAR, &sc->sc_bt) != 0) {
    306 		printf("tcxattach: cannot map bt registers\n");
    307 		return;
    308 	}
    309 
    310 	/* map the 8bit dumb FB for the console */
    311 	if (sbus_bus_map(sa->sa_bustag,
    312 		 sc->sc_physaddr[TCX_REG_DFB8].oa_space,
    313 		 sc->sc_physaddr[TCX_REG_DFB8].oa_base,
    314 			 1024 * 1024,
    315 			 BUS_SPACE_MAP_LINEAR,
    316 			 &bh) != 0) {
    317 		printf("tcxattach: cannot map framebuffer\n");
    318 		return;
    319 	}
    320 	sc->sc_fbaddr = bus_space_vaddr(sa->sa_bustag, bh);
    321 
    322 	/* RBLIT space */
    323 	if (sbus_bus_map(sa->sa_bustag,
    324 		 sc->sc_physaddr[TCX_REG_RBLIT].oa_space,
    325 		 sc->sc_physaddr[TCX_REG_RBLIT].oa_base,
    326 			 8 * 1024 * 1024,
    327 			 BUS_SPACE_MAP_LINEAR | BUS_SPACE_MAP_LARGE,
    328 			 &bh) != 0) {
    329 		printf("tcxattach: cannot map RBLIT space\n");
    330 		return;
    331 	}
    332 	sc->sc_rblit = bus_space_vaddr(sa->sa_bustag, bh);
    333 
    334 	/* RSTIP space */
    335 	if (sbus_bus_map(sa->sa_bustag,
    336 		 sc->sc_physaddr[TCX_REG_RSTIP].oa_space,
    337 		 sc->sc_physaddr[TCX_REG_RSTIP].oa_base,
    338 			 8 * 1024 * 1024,
    339 			 BUS_SPACE_MAP_LINEAR | BUS_SPACE_MAP_LARGE,
    340 			 &bh) != 0) {
    341 		printf("tcxattach: cannot map RSTIP space\n");
    342 		return;
    343 	}
    344 	sc->sc_rstip = bus_space_vaddr(sa->sa_bustag, bh);
    345 
    346 	isconsole = fb_is_console(node);
    347 
    348 	confreg = bus_space_read_4(sa->sa_bustag, sc->sc_thc, THC_CONFIG);
    349 	printf(", id %d, rev %d, sense %d",
    350 		(confreg & THC_CFG_FBID) >> THC_CFG_FBID_SHIFT,
    351 		(confreg & THC_CFG_REV) >> THC_CFG_REV_SHIFT,
    352 		(confreg & THC_CFG_SENSE) >> THC_CFG_SENSE_SHIFT
    353 	);
    354 
    355 	/* reset cursor & frame buffer controls */
    356 	tcx_reset(sc);
    357 
    358 	/* Initialize the default color map. */
    359 	j = 0;
    360 	for (i = 0; i < 256; i++) {
    361 
    362 		sc->sc_cmap_red[i] = rasops_cmap[j];
    363 		sc->sc_cmap_green[i] = rasops_cmap[j + 1];
    364 		sc->sc_cmap_blue[i] = rasops_cmap[j + 2];
    365 		j += 3;
    366 	}
    367 	tcx_loadcmap(sc, 0, 256);
    368 
    369 	tcx_set_cursor(sc);
    370 	/* enable video */
    371 	confreg = bus_space_read_4(sa->sa_bustag, sc->sc_thc, THC_MISC);
    372 	confreg |= THC_MISC_VIDEN;
    373 	bus_space_write_4(sa->sa_bustag, sc->sc_thc, THC_MISC, confreg);
    374 
    375 	if (isconsole) {
    376 		printf(" (console)\n");
    377 	} else
    378 		printf("\n");
    379 
    380 	sbus_establish(&sc->sc_sd, sc->sc_dev);
    381 	fb_attach(&sc->sc_fb, isconsole);
    382 
    383 	sc->sc_mode = WSDISPLAYIO_MODE_EMUL;
    384 	wsfont_init();
    385 
    386 	vcons_init(&sc->vd, sc, &tcx_defscreendesc, &tcx_accessops);
    387 	sc->vd.init_screen = tcx_init_screen;
    388 
    389 	vcons_init_screen(&sc->vd, &tcx_console_screen, 1, &defattr);
    390 	tcx_console_screen.scr_flags |= VCONS_SCREEN_IS_STATIC;
    391 
    392 	sc->sc_bg = (defattr >> 16) & 0xff;
    393 	tcx_clearscreen(sc, 0);
    394 
    395 	ri = &tcx_console_screen.scr_ri;
    396 
    397 	tcx_defscreendesc.nrows = ri->ri_rows;
    398 	tcx_defscreendesc.ncols = ri->ri_cols;
    399 	tcx_defscreendesc.textops = &ri->ri_ops;
    400 	tcx_defscreendesc.capabilities = ri->ri_caps;
    401 
    402 	if(isconsole) {
    403 		wsdisplay_cnattach(&tcx_defscreendesc, ri, 0, 0, defattr);
    404 	}
    405 
    406 	aa.console = isconsole;
    407 	aa.scrdata = &tcx_screenlist;
    408 	aa.accessops = &tcx_accessops;
    409 	aa.accesscookie = &sc->vd;
    410 
    411 	config_found(self, &aa, wsemuldisplaydevprint);
    412 	/*
    413 	 * we need to do this again - something overwrites a handful
    414 	 * palette registers and we end up with white in reg. 0
    415 	 */
    416 	tcx_loadcmap(sc, 0, 256);
    417 }
    418 
    419 int
    420 tcxopen(dev_t dev, int flags, int mode, struct lwp *l)
    421 {
    422 	return (0);
    423 }
    424 
    425 int
    426 tcxclose(dev_t dev, int flags, int mode, struct lwp *l)
    427 {
    428 	struct tcx_softc *sc = device_lookup_private(&tcx_cd, minor(dev));
    429 
    430 	tcx_reset(sc);
    431 	/* we may want to clear and redraw the console here */
    432 	return (0);
    433 }
    434 
    435 int
    436 tcxioctl(dev_t dev, u_long cmd, void *data, int flags, struct lwp *l)
    437 {
    438 	struct tcx_softc *sc = device_lookup_private(&tcx_cd, minor(dev));
    439 
    440 	switch (cmd) {
    441 
    442 	case FBIOGTYPE:
    443 		*(struct fbtype *)data = sc->sc_fb.fb_type;
    444 		break;
    445 
    446 	case FBIOGATTR:
    447 #define fba ((struct fbgattr *)data)
    448 		fba->real_type = sc->sc_fb.fb_type.fb_type;
    449 		fba->owner = 0;		/* XXX ??? */
    450 		fba->fbtype = sc->sc_fb.fb_type;
    451 		fba->sattr.flags = 0;
    452 		fba->sattr.emu_type = sc->sc_fb.fb_type.fb_type;
    453 		fba->sattr.dev_specific[0] = -1;
    454 		fba->emu_types[0] = sc->sc_fb.fb_type.fb_type;
    455 		fba->emu_types[1] = FBTYPE_SUN3COLOR;
    456 		fba->emu_types[2] = -1;
    457 #undef fba
    458 		break;
    459 
    460 	case FBIOGETCMAP:
    461 #define	p ((struct fbcmap *)data)
    462 		if (copyout(&sc->sc_cmap_red[p->index], p->red, p->count) != 0)
    463 			return EINVAL;
    464 		if (copyout(&sc->sc_cmap_green[p->index], p->green, p->count)
    465 		    != 0)
    466 			return EINVAL;
    467 		if (copyout(&sc->sc_cmap_blue[p->index], p->blue, p->count)
    468 		    != 0)
    469 			return EINVAL;
    470 		return 0;
    471 
    472 	case FBIOPUTCMAP:
    473 		/* copy to software map */
    474 		if (copyin(p->red, &sc->sc_cmap_red[p->index], p->count) != 0)
    475 			return EINVAL;
    476 		if (copyin(p->green, &sc->sc_cmap_green[p->index], p->count)
    477 		    != 0)
    478 			return EINVAL;
    479 		if (copyin(p->blue, &sc->sc_cmap_blue[p->index], p->count) != 0)
    480 			return EINVAL;
    481 		tcx_loadcmap(sc, p->index, p->count);
    482 #undef p
    483 		break;
    484 	case FBIOGVIDEO:
    485 		*(int *)data = sc->sc_blanked;
    486 		break;
    487 
    488 	case FBIOSVIDEO:
    489 		tcx_set_video(sc, *(int *)data);
    490 		break;
    491 
    492 	default:
    493 #ifdef DEBUG
    494 		log(LOG_NOTICE, "tcxioctl(0x%lx) (%s[%d])\n", cmd,
    495 		    l->l_proc->p_comm, l->l_proc->p_pid);
    496 #endif
    497 		return (ENOTTY);
    498 	}
    499 	return (0);
    500 }
    501 
    502 /*
    503  * Clean up hardware state (e.g., after bootup or after X crashes).
    504  */
    505 static void
    506 tcx_reset(struct tcx_softc *sc)
    507 {
    508 	uint32_t reg;
    509 
    510 	reg = bus_space_read_4(sc->sc_bustag, sc->sc_thc, THC_MISC);
    511 	reg |= THC_MISC_CURSRES;
    512 	bus_space_write_4(sc->sc_bustag, sc->sc_thc, THC_MISC, reg);
    513 }
    514 
    515 static void
    516 tcx_loadcmap(struct tcx_softc *sc, int start, int ncolors)
    517 {
    518 	int i;
    519 
    520 	for (i = 0; i < ncolors; i++) {
    521 		bus_space_write_4(sc->sc_bustag, sc->sc_bt, DAC_ADDRESS,
    522 		    (start + i) << 24);
    523 		bus_space_write_4(sc->sc_bustag, sc->sc_bt, DAC_FB_LUT,
    524 		    sc->sc_cmap_red[i + start] << 24);
    525 		bus_space_write_4(sc->sc_bustag, sc->sc_bt, DAC_FB_LUT,
    526 		    sc->sc_cmap_green[i + start] << 24);
    527 		bus_space_write_4(sc->sc_bustag, sc->sc_bt, DAC_FB_LUT,
    528 		    sc->sc_cmap_blue[i + start] << 24);
    529 	}
    530 	bus_space_write_4(sc->sc_bustag, sc->sc_bt, DAC_ADDRESS, 0);
    531 }
    532 
    533 static void
    534 tcx_unblank(device_t dev)
    535 {
    536 	struct tcx_softc *sc = device_private(dev);
    537 
    538 	if (sc->sc_blanked) {
    539 		uint32_t reg;
    540 		sc->sc_blanked = 0;
    541 		reg = bus_space_read_4(sc->sc_bustag, sc->sc_thc, THC_MISC);
    542 		reg &= ~THC_MISC_VSYNC_DISABLE;
    543 		reg &= ~THC_MISC_HSYNC_DISABLE;
    544 		reg |= THC_MISC_VIDEN;
    545 		bus_space_write_4(sc->sc_bustag, sc->sc_thc, THC_MISC, reg);
    546 	}
    547 }
    548 
    549 static void
    550 tcx_set_video(struct tcx_softc *sc, int unblank)
    551 {
    552 	uint32_t reg;
    553 	if (unblank) {
    554 		sc->sc_blanked = 0;
    555 		reg = bus_space_read_4(sc->sc_bustag, sc->sc_thc, THC_MISC);
    556 		reg &= ~THC_MISC_VSYNC_DISABLE;
    557 		reg &= ~THC_MISC_HSYNC_DISABLE;
    558 		reg |= THC_MISC_VIDEN;
    559 		bus_space_write_4(sc->sc_bustag, sc->sc_thc, THC_MISC, reg);
    560 	} else {
    561 		sc->sc_blanked = 1;
    562 		reg = bus_space_read_4(sc->sc_bustag, sc->sc_thc, THC_MISC);
    563 		reg |= THC_MISC_VSYNC_DISABLE;
    564 		reg |= THC_MISC_HSYNC_DISABLE;
    565 		reg &= ~THC_MISC_VIDEN;
    566 		bus_space_write_4(sc->sc_bustag, sc->sc_thc, THC_MISC, reg);
    567 	}
    568 }
    569 
    570 /*
    571  * Base addresses at which users can mmap() the various pieces of a tcx.
    572  */
    573 #define	TCX_USER_RAM	0x00000000
    574 #define	TCX_USER_RAM24	0x01000000
    575 #define	TCX_USER_RAM_COMPAT	0x04000000	/* cg3 emulation */
    576 #define	TCX_USER_STIP	0x10000000
    577 #define	TCX_USER_BLIT	0x20000000
    578 #define	TCX_USER_RDFB32	0x28000000
    579 #define	TCX_USER_RSTIP	0x30000000
    580 #define	TCX_USER_RBLIT	0x38000000
    581 #define	TCX_USER_TEC	0x70001000
    582 #define	TCX_USER_BTREGS	0x70002000
    583 #define	TCX_USER_THC	0x70004000
    584 #define	TCX_USER_DHC	0x70008000
    585 #define	TCX_USER_ALT	0x7000a000
    586 #define	TCX_USER_UART	0x7000c000
    587 #define	TCX_USER_VRT	0x7000e000
    588 #define	TCX_USER_ROM	0x70010000
    589 
    590 struct mmo {
    591 	u_int	mo_uaddr;	/* user (virtual) address */
    592 	u_int	mo_size;	/* size, or 0 for video ram size */
    593 	u_int	mo_bank;	/* register bank number */
    594 };
    595 
    596 /*
    597  * Return the address that would map the given device at the given
    598  * offset, allowing for the given protection, or return -1 for error.
    599  *
    600  * XXX	needs testing against `demanding' applications (e.g., aviator)
    601  */
    602 paddr_t
    603 tcxmmap(dev_t dev, off_t off, int prot)
    604 {
    605 	struct tcx_softc *sc = device_lookup_private(&tcx_cd, minor(dev));
    606 	struct openprom_addr *rr = sc->sc_physaddr;
    607 	struct mmo *mo, *mo_end;
    608 	u_int u, sz;
    609 	static struct mmo mmo[] = {
    610 		{ TCX_USER_RAM, 0, TCX_REG_DFB8 },
    611 		{ TCX_USER_RAM24, 0, TCX_REG_DFB24 },
    612 		{ TCX_USER_RAM_COMPAT, 0, TCX_REG_DFB8 },
    613 
    614 		{ TCX_USER_STIP, 1, TCX_REG_STIP },
    615 		{ TCX_USER_BLIT, 1, TCX_REG_BLIT },
    616 		{ TCX_USER_RDFB32, 0, TCX_REG_RDFB32 },
    617 		{ TCX_USER_RSTIP, 1, TCX_REG_RSTIP },
    618 		{ TCX_USER_RBLIT, 1, TCX_REG_RBLIT },
    619 		{ TCX_USER_TEC, 1, TCX_REG_TEC },
    620 		{ TCX_USER_BTREGS, 8192 /* XXX */, TCX_REG_CMAP },
    621 		{ TCX_USER_THC, 0x1000, TCX_REG_THC },
    622 		{ TCX_USER_DHC, 1, TCX_REG_DHC },
    623 		{ TCX_USER_ALT, 1, TCX_REG_ALT },
    624 		{ TCX_USER_ROM, 65536, TCX_REG_ROM },
    625 	};
    626 #define NMMO (sizeof mmo / sizeof *mmo)
    627 
    628 	if (off & PGOFSET)
    629 		panic("tcxmmap");
    630 
    631 	/*
    632 	 * Entries with size 0 map video RAM (i.e., the size in fb data).
    633 	 * Entries that map 32-bit deep regions are adjusted for their
    634 	 * depth (fb_size gives the size of the 8-bit-deep region).
    635 	 *
    636 	 * Since we work in pages, the fact that the map offset table's
    637 	 * sizes are sometimes bizarre (e.g., 1) is effectively ignored:
    638 	 * one byte is as good as one page.
    639 	 */
    640 
    641 	mo = mmo;
    642 	mo_end = &mmo[NMMO];
    643 
    644 	for (; mo < mo_end; mo++) {
    645 		if ((u_int)off < mo->mo_uaddr)
    646 			continue;
    647 		u = off - mo->mo_uaddr;
    648 		sz = mo->mo_size;
    649 		if (sz == 0) {
    650 			sz = sc->sc_fb.fb_type.fb_size;
    651 			/*
    652 			 * check for the 32-bit-deep regions and adjust
    653 			 * accordingly
    654 			 */
    655 			if (mo->mo_uaddr == TCX_USER_RAM24 ||
    656 			    mo->mo_uaddr == TCX_USER_RDFB32) {
    657 				if (sc->sc_8bit) {
    658 					/*
    659 					 * not present on 8-bit hardware
    660 					 */
    661 					continue;
    662 				}
    663 				sz *= 4;
    664 			}
    665 		}
    666 		if (u < sz) {
    667 			return (bus_space_mmap(sc->sc_bustag,
    668 				BUS_ADDR(rr[mo->mo_bank].oa_space,
    669 					 rr[mo->mo_bank].oa_base),
    670 				u,
    671 				prot,
    672 				BUS_SPACE_MAP_LINEAR));
    673 		}
    674 	}
    675 	return (-1);
    676 }
    677 
    678 int
    679 tcx_ioctl(void *v, void *vs, u_long cmd, void *data, int flag,
    680 	struct lwp *l)
    681 {
    682 	struct vcons_data *vd = v;
    683 	struct tcx_softc *sc = vd->cookie;
    684 	struct wsdisplay_fbinfo *wdf;
    685 	struct vcons_screen *ms = vd->active;
    686 
    687 	switch (cmd) {
    688 		case WSDISPLAYIO_GTYPE:
    689 			*(u_int *)data = WSDISPLAY_TYPE_SUNTCX;
    690 			return 0;
    691 
    692 		case FBIOGVIDEO:
    693 		case WSDISPLAYIO_GVIDEO:
    694 			*(int *)data = !sc->sc_blanked;
    695 			return 0;
    696 
    697 		case WSDISPLAYIO_SVIDEO:
    698 		case FBIOSVIDEO:
    699 			tcx_set_video(sc, *(int *)data);
    700 			return 0;
    701 
    702 		case WSDISPLAYIO_GINFO:
    703 			wdf = (void *)data;
    704 			wdf->height = ms->scr_ri.ri_height;
    705 			wdf->width = ms->scr_ri.ri_width;
    706 			if (sc->sc_8bit) {
    707 				wdf->depth = 8;
    708 			} else {
    709 				wdf->depth = 32;
    710 			}
    711 			wdf->cmsize = 256;
    712 			return 0;
    713 		case WSDISPLAYIO_LINEBYTES:
    714 			{
    715 				int *ret = (int *)data;
    716 				*ret = sc->sc_8bit ? ms->scr_ri.ri_width :
    717 				    ms->scr_ri.ri_width << 2;
    718 			}
    719 			return 0;
    720 #if 0
    721 		case WSDISPLAYIO_GETCMAP:
    722 			return tcx_getcmap(sc, (struct wsdisplay_cmap *)data);
    723 
    724 		case WSDISPLAYIO_PUTCMAP:
    725 			return tcx_putcmap(sc, (struct wsdisplay_cmap *)data);
    726 #endif
    727 		case WSDISPLAYIO_SMODE:
    728 			{
    729 				int new_mode = *(int*)data;
    730 				if (new_mode != sc->sc_mode)
    731 				{
    732 					sc->sc_mode = new_mode;
    733 					if (new_mode == WSDISPLAYIO_MODE_EMUL)
    734 					{
    735 						tcx_loadcmap(sc, 0, 256);
    736 						tcx_clearscreen(sc, 0);
    737 						vcons_redraw_screen(ms);
    738 					} else if (!sc->sc_8bit)
    739 						tcx_clearscreen(sc, 3);
    740 				}
    741 			}
    742 		case WSDISPLAYIO_GCURPOS:
    743 			{
    744 				struct wsdisplay_curpos *cp = (void *)data;
    745 
    746 				cp->x = sc->sc_cursor_x;
    747 				cp->y = sc->sc_cursor_y;
    748 			}
    749 			return 0;
    750 
    751 		case WSDISPLAYIO_SCURPOS:
    752 			{
    753 				struct wsdisplay_curpos *cp = (void *)data;
    754 
    755 				sc->sc_cursor_x = cp->x;
    756 				sc->sc_cursor_y = cp->y;
    757 				tcx_set_cursor(sc);
    758 			}
    759 			return 0;
    760 
    761 		case WSDISPLAYIO_GCURMAX:
    762 			{
    763 				struct wsdisplay_curpos *cp = (void *)data;
    764 
    765 				cp->x = 32;
    766 				cp->y = 32;
    767 			}
    768 			return 0;
    769 
    770 		case WSDISPLAYIO_SCURSOR:
    771 			{
    772 				struct wsdisplay_cursor *cursor = (void *)data;
    773 
    774 				return tcx_do_cursor(sc, cursor);
    775 			}
    776 	}
    777 	return EPASSTHROUGH;
    778 }
    779 
    780 static paddr_t
    781 tcx_mmap(void *v, void *vs, off_t offset, int prot)
    782 {
    783 	struct vcons_data *vd = v;
    784 	struct tcx_softc *sc = vd->cookie;
    785 
    786 	/* 'regular' framebuffer mmap()ing */
    787 	if (sc->sc_8bit) {
    788 		/* on 8Bit boards hand over the 8 bit aperture */
    789 		if (offset > 1024 * 1024)
    790 			return -1;
    791 		return bus_space_mmap(sc->sc_bustag,
    792 		    sc->sc_physaddr[TCX_REG_DFB8].oa_base + offset, 0, prot,
    793 		    BUS_SPACE_MAP_LINEAR);
    794 	} else {
    795 		/* ... but if we have a 24bit aperture we use it */
    796 		if (offset > 1024 * 1024 * 4)
    797 			return -1;
    798 		return bus_space_mmap(sc->sc_bustag,
    799 		    sc->sc_physaddr[TCX_REG_DFB24].oa_base + offset, 0, prot,
    800 		    BUS_SPACE_MAP_LINEAR);
    801 	}
    802 	return -1;
    803 }
    804 
    805 static void
    806 tcx_init_screen(void *cookie, struct vcons_screen *scr,
    807     int existing, long *defattr)
    808 {
    809 	struct tcx_softc *sc = cookie;
    810 	struct rasops_info *ri = &scr->scr_ri;
    811 
    812 	ri->ri_depth = 8;
    813 	ri->ri_width = sc->sc_fb.fb_type.fb_width;
    814 	ri->ri_height = sc->sc_fb.fb_type.fb_height;
    815 	ri->ri_stride = sc->sc_fb.fb_linebytes;
    816 	ri->ri_flg = RI_CENTER | RI_FULLCLEAR;
    817 
    818 	ri->ri_bits = sc->sc_fbaddr;
    819 
    820 	rasops_init(ri, ri->ri_height/8, ri->ri_width/8);
    821 	ri->ri_caps = WSSCREEN_WSCOLORS;
    822 	rasops_reconfig(ri, ri->ri_height / ri->ri_font->fontheight,
    823 		    ri->ri_width / ri->ri_font->fontwidth);
    824 
    825 	/* enable acceleration */
    826 	ri->ri_ops.copyrows  = tcx_copyrows;
    827 	ri->ri_ops.eraserows = tcx_eraserows;
    828 	ri->ri_ops.putchar   = tcx_putchar;
    829 #if 0
    830 	ri->ri_ops.cursor    = tcx_cursor;
    831 	ri->ri_ops.copycols  = tcx_copycols;
    832 	ri->ri_ops.erasecols = tcx_erasecols;
    833 #endif
    834 }
    835 
    836 static void
    837 tcx_clearscreen(struct tcx_softc *sc, int spc)
    838 {
    839 	uint64_t bg = ((uint64_t)sc->sc_bg << 32) | 0xffffffffLL;
    840 	uint64_t spc64;
    841 	int i;
    842 
    843 	spc64 = spc & 3;
    844 	spc64 = spc64 << 56;
    845 
    846 	for (i = 0; i < 1024 * 1024; i += 32)
    847 		sc->sc_rstip[i] = bg | spc64;
    848 }
    849 
    850 static void
    851 tcx_copyrows(void *cookie, int srcrow, int dstrow, int nrows)
    852 {
    853 	struct rasops_info *ri = cookie;
    854 	struct vcons_screen *scr = ri->ri_hw;
    855 	struct tcx_softc *sc = scr->scr_cookie;
    856 	int i, last, first, len, dest, leftover;
    857 
    858 	i = ri->ri_width * ri->ri_font->fontheight * nrows;
    859 	len = i & 0xffffe0;
    860 	leftover = i & 0x1f;
    861 	if (srcrow < dstrow) {
    862 		/* we must go bottom to top */
    863 		first = ri->ri_width *
    864 		    (ri->ri_font->fontheight * srcrow + ri->ri_yorigin);
    865 		last = first + len;
    866 		dest = ri->ri_width *
    867 		    (ri->ri_font->fontheight * dstrow + ri->ri_yorigin) + len;
    868 		if (leftover > 0) {
    869 			sc->sc_rblit[dest + 32] =
    870 			    (uint64_t)((leftover - 1) << 24) |
    871 			    (uint64_t)(i + 32);
    872 		}
    873 		for (i = last; i >= first; i -= 32) {
    874 			sc->sc_rblit[dest] = 0x300000001f000000LL | (uint64_t)i;
    875 			dest -= 32;
    876 		}
    877 	} else {
    878 		/* top to bottom */
    879 		first = ri->ri_width *
    880 		    (ri->ri_font->fontheight * srcrow + ri->ri_yorigin);
    881 		dest = ri->ri_width *
    882 		    (ri->ri_font->fontheight * dstrow + ri->ri_yorigin);
    883 		last = first + len;
    884 		for (i = first; i <= last; i+= 32) {
    885 			sc->sc_rblit[dest] = 0x300000001f000000LL | (uint64_t)i;
    886 			dest += 32;
    887 		}
    888 		if (leftover > 0) {
    889 			sc->sc_rblit[dest] =
    890 			    (uint64_t)((leftover - 1) << 24) | (uint64_t)i;
    891 		}
    892 	}
    893 }
    894 
    895 static void
    896 tcx_eraserows(void *cookie, int start, int nrows, long attr)
    897 {
    898 	struct rasops_info *ri = cookie;
    899 	struct vcons_screen *scr = ri->ri_hw;
    900 	struct tcx_softc *sc = scr->scr_cookie;
    901 	uint64_t temp;
    902 	int i, last, first, len, leftover;
    903 
    904 	i = ri->ri_width * ri->ri_font->fontheight * nrows;
    905 	len = i & 0xffffe0;
    906 	leftover = i & 0x1f;
    907 	first = ri->ri_width *
    908 	    (ri->ri_font->fontheight * start + ri->ri_yorigin);
    909 	last = first + len;
    910 	temp = 0x30000000ffffffffLL |
    911 	    ((uint64_t)ri->ri_devcmap[(attr >> 16) & 0xff] << 32);
    912 
    913 	for (i = first; i <= last; i+= 32)
    914 		sc->sc_rblit[i] = temp;
    915 
    916 	if (leftover > 0) {
    917 		temp &= 0xffffffffffffffffLL << (32 - leftover);
    918 		sc->sc_rblit[i] = temp;
    919 	}
    920 }
    921 /*
    922  * The stipple engine is 100% retarded. All drawing operations have to start
    923  * at 32 pixel boundaries so we'll have to deal with characters being split.
    924  */
    925 
    926 static void
    927 tcx_putchar(void *cookie, int row, int col, u_int c, long attr)
    928 {
    929 	struct rasops_info *ri = cookie;
    930 	struct vcons_screen *scr = ri->ri_hw;
    931 	struct tcx_softc *sc = scr->scr_cookie;
    932 	uint64_t bg, fg, temp, mask;
    933 	int addr, i, uc, shift;
    934 	uint32_t fmask;
    935 	uint8_t *cdata;
    936 	uint16_t *wdata;
    937 
    938 	addr = ri->ri_xorigin +
    939 	    col * ri->ri_font->fontwidth +
    940 	    (ri->ri_yorigin + row * ri->ri_font->fontheight) * ri->ri_width;
    941 
    942 	/* check if the character is crossing a 32 pixel boundary */
    943 	if ((addr & 0xffffe0) ==
    944 	    ((addr + ri->ri_font->fontwidth - 1) & 0xffffe0)) {
    945 		/* phew, not split */
    946 		shift = addr & 0x1f;
    947 		addr &= 0xffffe0;
    948 		fmask = 0xffffffff >> (32 - ri->ri_font->fontwidth);
    949 		fmask = fmask << (32 - ri->ri_font->fontwidth - shift);
    950 		mask = fmask;
    951 		bg = 0x3000000000000000LL |
    952 		    ((uint64_t)ri->ri_devcmap[(attr >> 16) & 0xff] &
    953 		      0xff) << 32;
    954 		bg |= mask;
    955 		temp = 0x3000000000000000LL |
    956 		    ((uint64_t)ri->ri_devcmap[(attr >> 24) & 0xff] & 0xff) <<
    957 		    	32;
    958 		uc = c - ri->ri_font->firstchar;
    959 		cdata = (uint8_t *)ri->ri_font->data + uc * ri->ri_fontscale;
    960 
    961 		if (ri->ri_font->fontwidth < 9) {
    962 			/* byte by byte */
    963 			for (i = 0; i < ri->ri_font->fontheight; i++) {
    964 				sc->sc_rstip[addr] = bg;
    965 				if (*cdata != 0) {
    966 					if (shift > 24) {
    967 						fg = (uint64_t)*cdata >>
    968 					  	  (shift - 24);
    969 					} else {
    970 						fg = (uint64_t)*cdata <<
    971 					  	  (24 - shift);
    972 					}
    973 					sc->sc_rstip[addr] = fg | temp;
    974 				}
    975 				cdata++;
    976 				addr += ri->ri_width;
    977 			}
    978 		} else if (ri->ri_font->fontwidth < 17) {
    979 			/* short by short */
    980 			wdata = (uint16_t *)cdata;
    981 			for (i = 0; i < ri->ri_font->fontheight; i++) {
    982 				sc->sc_rstip[addr] = bg;
    983 				if (*wdata != 0) {
    984 					if (shift > 16) {
    985 						fg = temp | (uint64_t)*wdata >>
    986 					  	  (shift - 16);
    987 					} else {
    988 						fg = temp | (uint64_t)*wdata <<
    989 					  	  (16 - shift);
    990 					}
    991 					sc->sc_rstip[addr] = fg;
    992 				}
    993 				wdata++;
    994 				addr += ri->ri_width;
    995 			}
    996 		}
    997 	} else {
    998 		/* and now the split case ( man this hardware is dumb ) */
    999 		uint64_t bgr, maskr, fgr;
   1000 		uint32_t bork;
   1001 
   1002 		shift = addr & 0x1f;
   1003 		addr &= 0xffffe0;
   1004 		mask = 0xffffffff >> shift;
   1005 		maskr = (uint64_t)(0xffffffffUL <<
   1006 		    (32 - (ri->ri_font->fontwidth + shift - 32)));
   1007 		bg = 0x3000000000000000LL |
   1008 		    ((uint64_t)ri->ri_devcmap[(attr >> 16) & 0xff] &
   1009 		      0xff) << 32;
   1010 		bgr = bg | maskr;
   1011 		bg |= mask;
   1012 		temp = 0x3000000000000000LL |
   1013 		    ((uint64_t)ri->ri_devcmap[(attr >> 24) & 0xff] & 0xff) <<
   1014 		      32;
   1015 
   1016 		uc = c - ri->ri_font->firstchar;
   1017 		cdata = (uint8_t *)ri->ri_font->data + uc * ri->ri_fontscale;
   1018 
   1019 		if (ri->ri_font->fontwidth < 9) {
   1020 			/* byte by byte */
   1021 			for (i = 0; i < ri->ri_font->fontheight; i++) {
   1022 				sc->sc_rstip[addr] = bg;
   1023 				sc->sc_rstip[addr + 32] = bgr;
   1024 				bork = *cdata;
   1025 				if (bork != 0) {
   1026 					fg = (uint64_t)bork >> (shift - 24);
   1027 					sc->sc_rstip[addr] = fg | temp;
   1028 					fgr = (uint64_t)(bork << (52 - shift));
   1029 					sc->sc_rstip[addr] = fgr | temp;
   1030 				}
   1031 				cdata++;
   1032 				addr += ri->ri_width;
   1033 			}
   1034 		} else if (ri->ri_font->fontwidth < 17) {
   1035 			/* short by short */
   1036 			wdata = (uint16_t *)cdata;
   1037 			for (i = 0; i < ri->ri_font->fontheight; i++) {
   1038 				sc->sc_rstip[addr] = bg;
   1039 				sc->sc_rstip[addr + 32] = bgr;
   1040 				bork = *wdata;
   1041 				if (bork != 0) {
   1042 					fg = (uint64_t)bork >> (shift - 16);
   1043 					sc->sc_rstip[addr] = fg | temp;
   1044 					fgr = (uint64_t)(bork << (48 - shift));
   1045 					sc->sc_rstip[addr + 32] = fgr | temp;
   1046 				}
   1047 				wdata++;
   1048 				addr += ri->ri_width;
   1049 			}
   1050 		}
   1051 
   1052 	}
   1053 }
   1054 
   1055 static int
   1056 tcx_do_cursor(struct tcx_softc *sc, struct wsdisplay_cursor *cur)
   1057 {
   1058 	if (cur->which & WSDISPLAY_CURSOR_DOCUR) {
   1059 
   1060 		if (cur->enable) {
   1061 			tcx_set_cursor(sc);
   1062 		} else {
   1063 			/* move the cursor out of sight */
   1064 			bus_space_write_4(sc->sc_bustag, sc->sc_thc,
   1065 			    THC_CURSOR_POS, 0x7fff7fff);
   1066 		}
   1067 	}
   1068 	if (cur->which & WSDISPLAY_CURSOR_DOHOT) {
   1069 
   1070 		sc->sc_hotspot_x = cur->hot.x;
   1071 		sc->sc_hotspot_y = cur->hot.y;
   1072 		tcx_set_cursor(sc);
   1073 	}
   1074 	if (cur->which & WSDISPLAY_CURSOR_DOPOS) {
   1075 
   1076 		sc->sc_cursor_x = cur->pos.x;
   1077 		sc->sc_cursor_y = cur->pos.y;
   1078 		tcx_set_cursor(sc);
   1079 	}
   1080 	if (cur->which & WSDISPLAY_CURSOR_DOCMAP) {
   1081 #if 0
   1082 		int i;
   1083 
   1084 		for (i = 0; i < cur->cmap.count; i++) {
   1085 			bus_space_write_4(sc->sc_bustag, sc->sc_bt, DAC_ADDRESS,
   1086 			    (cur->cmap.index + i + 2) << 24);
   1087 			bus_space_write_4(sc->sc_bustag, sc->sc_bt,
   1088 			    DAC_CURSOR_LUT, cur->cmap.red[i] << 24);
   1089 			bus_space_write_4(sc->sc_bustag, sc->sc_bt,
   1090 			    DAC_CURSOR_LUT, cur->cmap.green[i] << 24);
   1091 			bus_space_write_4(sc->sc_bustag, sc->sc_bt,
   1092 			    DAC_CURSOR_LUT, cur->cmap.blue[i] << 24);
   1093 		}
   1094 #endif
   1095 	}
   1096 	if (cur->which & WSDISPLAY_CURSOR_DOSHAPE) {
   1097 #if 1
   1098 		int i;
   1099 		uint32_t temp, poof;
   1100 
   1101 		for (i = 0; i < 128; i += 4) {
   1102 			memcpy(&temp, &cur->mask[i], 4);
   1103 			printf("%08x -> ", temp);
   1104 			poof = ((temp & 0x80808080) >> 7) |
   1105 			       ((temp & 0x40404040) >> 5) |
   1106 			       ((temp & 0x20202020) >> 3) |
   1107 			       ((temp & 0x10101010) >> 1) |
   1108 			       ((temp & 0x08080808) << 1) |
   1109 			       ((temp & 0x04040404) << 3) |
   1110 			       ((temp & 0x02020202) << 5) |
   1111 			       ((temp & 0x01010101) << 7);
   1112 			printf("%08x\n", poof);
   1113 			bus_space_write_4(sc->sc_bustag, sc->sc_thc,
   1114 			    THC_CURSOR_1 + i, poof);
   1115 			memcpy(&temp, &cur->image[i], 4);
   1116 			poof = ((temp & 0x80808080) >> 7) |
   1117 			       ((temp & 0x40404040) >> 5) |
   1118 			       ((temp & 0x20202020) >> 3) |
   1119 			       ((temp & 0x10101010) >> 1) |
   1120 			       ((temp & 0x08080808) << 1) |
   1121 			       ((temp & 0x04040404) << 3) |
   1122 			       ((temp & 0x02020202) << 5) |
   1123 			       ((temp & 0x01010101) << 7);
   1124 			bus_space_write_4(sc->sc_bustag, sc->sc_thc,
   1125 			    THC_CURSOR_0 + i, poof);
   1126 		}
   1127 	}
   1128 #endif
   1129 	return 0;
   1130 }
   1131 
   1132 static void
   1133 tcx_set_cursor(struct tcx_softc *sc)
   1134 {
   1135 	uint32_t reg;
   1136 
   1137 	reg = (sc->sc_cursor_x - sc->sc_hotspot_x) << 16 |
   1138 	     ((sc->sc_cursor_y - sc->sc_hotspot_y) & 0xffff);
   1139 	bus_space_write_4(sc->sc_bustag, sc->sc_thc, THC_CURSOR_POS, reg);
   1140 }
   1141 
   1142