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