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