Home | History | Annotate | Line # | Download | only in pci
tga.c revision 1.8
      1 /* $NetBSD: tga.c,v 1.8 1998/08/18 08:40:39 thorpej Exp $ */
      2 
      3 /*
      4  * Copyright (c) 1995, 1996 Carnegie-Mellon University.
      5  * All rights reserved.
      6  *
      7  * Author: Chris G. Demetriou
      8  *
      9  * Permission to use, copy, modify and distribute this software and
     10  * its documentation is hereby granted, provided that both the copyright
     11  * notice and this permission notice appear in all copies of the
     12  * software, derivative works or modified versions, and any portions
     13  * thereof, and that both notices appear in supporting documentation.
     14  *
     15  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
     16  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
     17  * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
     18  *
     19  * Carnegie Mellon requests users of this software to return to
     20  *
     21  *  Software Distribution Coordinator  or  Software.Distribution (at) CS.CMU.EDU
     22  *  School of Computer Science
     23  *  Carnegie Mellon University
     24  *  Pittsburgh PA 15213-3890
     25  *
     26  * any improvements or extensions that they make and grant Carnegie the
     27  * rights to redistribute these changes.
     28  */
     29 
     30 #include "opt_uvm.h"
     31 
     32 #include <sys/param.h>
     33 #include <sys/systm.h>
     34 #include <sys/kernel.h>
     35 #include <sys/device.h>
     36 #include <sys/conf.h>
     37 #include <sys/malloc.h>
     38 #include <sys/buf.h>
     39 #include <sys/ioctl.h>
     40 
     41 #include <vm/vm.h>
     42 
     43 #include <machine/bus.h>
     44 #include <machine/intr.h>
     45 
     46 #include <dev/pci/pcireg.h>
     47 #include <dev/pci/pcivar.h>
     48 #include <dev/pci/pcidevs.h>
     49 #include <dev/pci/tgareg.h>
     50 #include <dev/pci/tgavar.h>
     51 #include <dev/ic/bt485reg.h>
     52 
     53 #include <dev/rcons/raster.h>
     54 #include <dev/wscons/wsconsio.h>
     55 #include <dev/wscons/wscons_raster.h>
     56 #include <dev/wscons/wsdisplayvar.h>
     57 
     58 #ifdef __alpha__
     59 #include <machine/pte.h>
     60 #endif
     61 
     62 int	tgamatch __P((struct device *, struct cfdata *, void *));
     63 void	tgaattach __P((struct device *, struct device *, void *));
     64 int	tgaprint __P((void *, const char *));
     65 
     66 struct cfattach tga_ca = {
     67 	sizeof(struct tga_softc), tgamatch, tgaattach,
     68 };
     69 
     70 int	tga_identify __P((tga_reg_t *));
     71 const struct tga_conf *tga_getconf __P((int));
     72 void	tga_getdevconfig __P((bus_space_tag_t memt, pci_chipset_tag_t pc,
     73 	    pcitag_t tag, struct tga_devconfig *dc));
     74 
     75 struct tga_devconfig tga_console_dc;
     76 
     77 struct wsdisplay_emulops tga_emulops = {
     78 	rcons_cursor,			/* could use hardware cursor; punt */
     79 	rcons_mapchar,
     80 	rcons_putchar,
     81 	rcons_copycols,
     82 	rcons_erasecols,
     83 	rcons_copyrows,
     84 	rcons_eraserows,
     85 	rcons_alloc_attr
     86 };
     87 
     88 struct wsscreen_descr tga_stdscreen = {
     89 	"std",
     90 	0, 0,	/* will be filled in -- XXX shouldn't, it's global */
     91 	&tga_emulops,
     92 	0, 0,
     93 	WSSCREEN_REVERSE
     94 };
     95 
     96 const struct wsscreen_descr *_tga_scrlist[] = {
     97 	&tga_stdscreen,
     98 	/* XXX other formats, graphics screen? */
     99 };
    100 
    101 struct wsscreen_list tga_screenlist = {
    102 	sizeof(_tga_scrlist) / sizeof(struct wsscreen_descr *), _tga_scrlist
    103 };
    104 
    105 int	tga_ioctl __P((void *, u_long, caddr_t, int, struct proc *));
    106 int	tga_mmap __P((void *, off_t, int));
    107 static int	tga_alloc_screen __P((void *, const struct wsscreen_descr *,
    108 				      void **, int *, int *, long *));
    109 static void	tga_free_screen __P((void *, void *));
    110 static void	tga_show_screen __P((void *, void *));
    111 static int	tga_load_font __P((void *, void *, int, int, int, void *));
    112 
    113 struct wsdisplay_accessops tga_accessops = {
    114 	tga_ioctl,
    115 	tga_mmap,
    116 	tga_alloc_screen,
    117 	tga_free_screen,
    118 	tga_show_screen,
    119 	tga_load_font
    120 };
    121 
    122 void	tga_blank __P((struct tga_devconfig *));
    123 void	tga_unblank __P((struct tga_devconfig *));
    124 
    125 int
    126 tgamatch(parent, match, aux)
    127 	struct device *parent;
    128 	struct cfdata *match;
    129 	void *aux;
    130 {
    131 	struct pci_attach_args *pa = aux;
    132 
    133 	if (PCI_VENDOR(pa->pa_id) != PCI_VENDOR_DEC ||
    134 	    PCI_PRODUCT(pa->pa_id) != PCI_PRODUCT_DEC_21030)
    135 		return (0);
    136 
    137 	return (10);
    138 }
    139 
    140 void
    141 tga_getdevconfig(memt, pc, tag, dc)
    142 	bus_space_tag_t memt;
    143 	pci_chipset_tag_t pc;
    144 	pcitag_t tag;
    145 	struct tga_devconfig *dc;
    146 {
    147 	const struct tga_conf *tgac;
    148 	const struct tga_ramdac_conf *tgar;
    149 	struct raster *rap;
    150 	struct rcons *rcp;
    151 	bus_size_t pcisize;
    152 	int i, flags;
    153 
    154 	dc->dc_memt = memt;
    155 	dc->dc_pc = pc;
    156 
    157 	dc->dc_pcitag = tag;
    158 
    159 	/* XXX magic number */
    160 	if (pci_mapreg_info(pc, tag, 0x10,
    161 	    PCI_MAPREG_TYPE_MEM | PCI_MAPREG_MEM_TYPE_32BIT,
    162 	    &dc->dc_pcipaddr, &pcisize, &flags))
    163 		return;
    164 	if ((flags & BUS_SPACE_MAP_CACHEABLE) == 0)		/* XXX */
    165 		panic("tga memory not cacheable");
    166 
    167 	if (bus_space_map(memt, dc->dc_pcipaddr, pcisize,
    168 	    BUS_SPACE_MAP_CACHEABLE | BUS_SPACE_MAP_LINEAR, &dc->dc_vaddr))
    169 		return;
    170 #ifdef __alpha__
    171 	dc->dc_paddr = ALPHA_K0SEG_TO_PHYS(dc->dc_vaddr);	/* XXX */
    172 #endif
    173 
    174 	dc->dc_regs = (tga_reg_t *)(dc->dc_vaddr + TGA_MEM_CREGS);
    175 	dc->dc_tga_type = tga_identify(dc->dc_regs);
    176 	tgac = dc->dc_tgaconf = tga_getconf(dc->dc_tga_type);
    177 	if (tgac == NULL)
    178 		return;
    179 
    180 #if 0
    181 	/* XXX on the Alpha, pcisize = 4 * cspace_size. */
    182 	if (tgac->tgac_cspace_size != pcisize)			/* sanity */
    183 		panic("tga_getdevconfig: memory size mismatch?");
    184 #endif
    185 
    186 	tgar = tgac->tgac_ramdac;
    187 
    188 	switch (dc->dc_regs[TGA_REG_VHCR] & 0x1ff) {		/* XXX */
    189 	case 0:
    190 		dc->dc_wid = 8192;
    191 		break;
    192 
    193 	case 1:
    194 		dc->dc_wid = 8196;
    195 		break;
    196 
    197 	default:
    198 		dc->dc_wid = (dc->dc_regs[TGA_REG_VHCR] & 0x1ff) * 4; /* XXX */
    199 		break;
    200 	}
    201 
    202 	dc->dc_rowbytes = dc->dc_wid * (dc->dc_tgaconf->tgac_phys_depth / 8);
    203 
    204 	if ((dc->dc_regs[TGA_REG_VHCR] & 0x00000001) != 0 &&	/* XXX */
    205 	    (dc->dc_regs[TGA_REG_VHCR] & 0x80000000) != 0) {	/* XXX */
    206 		dc->dc_wid -= 4;
    207 		/*
    208 		 * XXX XXX turning off 'odd' shouldn't be necesssary,
    209 		 * XXX XXX but i can't make X work with the weird size.
    210 		 */
    211 		dc->dc_regs[TGA_REG_VHCR] &= ~0x80000001;
    212 		dc->dc_rowbytes =
    213 		    dc->dc_wid * (dc->dc_tgaconf->tgac_phys_depth / 8);
    214 	}
    215 
    216 	dc->dc_ht = (dc->dc_regs[TGA_REG_VVCR] & 0x7ff);	/* XXX */
    217 
    218 	/* XXX this seems to be what DEC does */
    219 	dc->dc_regs[TGA_REG_CCBR] = 0;
    220 	dc->dc_regs[TGA_REG_VVBR] = 1;
    221 	dc->dc_videobase = dc->dc_vaddr + tgac->tgac_dbuf[0] +
    222 	    1 * tgac->tgac_vvbr_units;
    223 	dc->dc_blanked = 1;
    224 	tga_unblank(dc);
    225 
    226 	/*
    227 	 * Set all bits in the pixel mask, to enable writes to all pixels.
    228 	 * It seems that the console firmware clears some of them
    229 	 * under some circumstances, which causes cute vertical stripes.
    230 	 */
    231 	dc->dc_regs[TGA_REG_GPXR_P] = 0xffffffff;
    232 
    233 	/* clear the screen */
    234 	for (i = 0; i < dc->dc_ht * dc->dc_rowbytes; i += sizeof(u_int32_t))
    235 		*(u_int32_t *)(dc->dc_videobase + i) = 0;
    236 
    237 	/* initialize the raster */
    238 	rap = &dc->dc_raster;
    239 	rap->width = dc->dc_wid;
    240 	rap->height = dc->dc_ht;
    241 	rap->depth = tgac->tgac_phys_depth;
    242 	rap->linelongs = dc->dc_rowbytes / sizeof(u_int32_t);
    243 	rap->pixels = (u_int32_t *)dc->dc_videobase;
    244 
    245 	/* initialize the raster console blitter */
    246 	rcp = &dc->dc_rcons;
    247 	rcp->rc_sp = rap;
    248 	rcp->rc_crow = rcp->rc_ccol = -1;
    249 	rcp->rc_crowp = &rcp->rc_crow;
    250 	rcp->rc_ccolp = &rcp->rc_ccol;
    251 	rcons_init(rcp, 34, 80);
    252 
    253 	tga_stdscreen.nrows = dc->dc_rcons.rc_maxrow;
    254 	tga_stdscreen.ncols = dc->dc_rcons.rc_maxcol;
    255 }
    256 
    257 void
    258 tgaattach(parent, self, aux)
    259 	struct device *parent, *self;
    260 	void *aux;
    261 {
    262 	struct pci_attach_args *pa = aux;
    263 	struct tga_softc *sc = (struct tga_softc *)self;
    264 	struct wsemuldisplaydev_attach_args aa;
    265 	pci_intr_handle_t intrh;
    266 	const char *intrstr;
    267 	u_int8_t rev;
    268 	int console;
    269 
    270 #ifdef __alpha__
    271 	console = (pa->pa_tag == tga_console_dc.dc_pcitag);
    272 #else
    273 	console = 0;
    274 #endif
    275 	if (console) {
    276 		sc->sc_dc = &tga_console_dc;
    277 		sc->nscreens = 1;
    278 	} else {
    279 		sc->sc_dc = (struct tga_devconfig *)
    280 		    malloc(sizeof(struct tga_devconfig), M_DEVBUF, M_WAITOK);
    281 		tga_getdevconfig(pa->pa_memt, pa->pa_pc, pa->pa_tag, sc->sc_dc);
    282 	}
    283 	if (sc->sc_dc->dc_vaddr == NULL) {
    284 		printf(": couldn't map memory space; punt!\n");
    285 		return;
    286 	}
    287 
    288 	/* XXX say what's going on. */
    289 	intrstr = NULL;
    290 	if (sc->sc_dc->dc_tgaconf->tgac_ramdac->tgar_intr != NULL) {
    291 		if (pci_intr_map(pa->pa_pc, pa->pa_intrtag, pa->pa_intrpin,
    292 		    pa->pa_intrline, &intrh)) {
    293 			printf(": couldn't map interrupt");
    294 			return;
    295 		}
    296 		intrstr = pci_intr_string(pa->pa_pc, intrh);
    297 		sc->sc_intr = pci_intr_establish(pa->pa_pc, intrh, IPL_TTY,
    298 		    sc->sc_dc->dc_tgaconf->tgac_ramdac->tgar_intr, sc->sc_dc);
    299 		if (sc->sc_intr == NULL) {
    300 			printf(": couldn't establish interrupt");
    301 			if (intrstr != NULL)
    302 				printf("at %s", intrstr);
    303 			printf("\n");
    304 			return;
    305 		}
    306 	}
    307 
    308 	/*
    309 	 * Initialize the RAMDAC and allocate any private storage it needs.
    310 	 * Initialization includes disabling cursor, setting a sane
    311 	 * colormap, etc.
    312 	 */
    313 	(*sc->sc_dc->dc_tgaconf->tgac_ramdac->tgar_init)(sc->sc_dc, 1);
    314 
    315 	printf(": DC21030 ");
    316 	rev = PCI_REVISION(pa->pa_class);
    317 	switch (rev) {
    318 	case 1: case 2: case 3:
    319 		printf("step %c", 'A' + rev - 1);
    320 		break;
    321 
    322 	default:
    323 		printf("unknown stepping (0x%x)", rev);
    324 		break;
    325 	}
    326 	printf(", ");
    327 
    328 	if (sc->sc_dc->dc_tgaconf == NULL) {
    329 		printf("unknown board configuration\n");
    330 		return;
    331 	}
    332 	printf("board type %s\n", sc->sc_dc->dc_tgaconf->tgac_name);
    333 	printf("%s: %d x %d, %dbpp, %s RAMDAC\n", sc->sc_dev.dv_xname,
    334 	    sc->sc_dc->dc_wid, sc->sc_dc->dc_ht,
    335 	    sc->sc_dc->dc_tgaconf->tgac_phys_depth,
    336 	    sc->sc_dc->dc_tgaconf->tgac_ramdac->tgar_name);
    337 
    338 	if (intrstr != NULL)
    339 		printf("%s: interrupting at %s\n", sc->sc_dev.dv_xname,
    340 		    intrstr);
    341 
    342 	aa.console = console;
    343 	aa.scrdata = &tga_screenlist;
    344 	aa.accessops = &tga_accessops;
    345 	aa.accesscookie = sc;
    346 
    347 	config_found(self, &aa, wsemuldisplaydevprint);
    348 }
    349 
    350 int
    351 tga_ioctl(v, cmd, data, flag, p)
    352 	void *v;
    353 	u_long cmd;
    354 	caddr_t data;
    355 	int flag;
    356 	struct proc *p;
    357 {
    358 	struct tga_softc *sc = v;
    359 	struct tga_devconfig *dc = sc->sc_dc;
    360 	const struct tga_ramdac_conf *tgar = dc->dc_tgaconf->tgac_ramdac;
    361 
    362 	switch (cmd) {
    363 	case WSDISPLAYIO_GTYPE:
    364 		*(u_int *)data = WSDISPLAY_TYPE_TGA;
    365 		return (0);
    366 
    367 	case WSDISPLAYIO_GINFO:
    368 #define	wsd_fbip ((struct wsdisplay_fbinfo *)data)
    369 		wsd_fbip->height = sc->sc_dc->dc_ht;
    370 		wsd_fbip->width = sc->sc_dc->dc_wid;
    371 		wsd_fbip->depth = sc->sc_dc->dc_tgaconf->tgac_phys_depth;
    372 		wsd_fbip->cmsize = 256;		/* XXX ??? */
    373 #undef fbt
    374 		return (0);
    375 
    376 	case WSDISPLAYIO_GETCMAP:
    377 		return (*tgar->tgar_get_cmap)(dc,
    378 		    (struct wsdisplay_cmap *)data);
    379 
    380 	case WSDISPLAYIO_PUTCMAP:
    381 		return (*tgar->tgar_set_cmap)(dc,
    382 		    (struct wsdisplay_cmap *)data);
    383 
    384 	case WSDISPLAYIO_GVIDEO:
    385 		if (*(u_int *)data == WSDISPLAYIO_VIDEO_OFF)
    386 			tga_blank(sc->sc_dc);
    387 		else
    388 			tga_unblank(sc->sc_dc);
    389 		return (0);
    390 
    391 	case WSDISPLAYIO_SVIDEO:
    392 		*(u_int *)data = dc->dc_blanked ?
    393 		    WSDISPLAYIO_VIDEO_OFF : WSDISPLAYIO_VIDEO_ON;
    394 		return (0);
    395 
    396 	case WSDISPLAYIO_GCURPOS:
    397 		return (*tgar->tgar_get_curpos)(dc,
    398 		    (struct wsdisplay_curpos *)data);
    399 
    400 	case WSDISPLAYIO_SCURPOS:
    401 		return (*tgar->tgar_set_curpos)(dc,
    402 		    (struct wsdisplay_curpos *)data);
    403 
    404 	case WSDISPLAYIO_GCURMAX:
    405 		return (*tgar->tgar_get_curmax)(dc,
    406 		    (struct wsdisplay_curpos *)data);
    407 
    408 	case WSDISPLAYIO_GCURSOR:
    409 		return (*tgar->tgar_get_cursor)(dc,
    410 		    (struct wsdisplay_cursor *)data);
    411 
    412 	case WSDISPLAYIO_SCURSOR:
    413 		return (*tgar->tgar_set_cursor)(dc,
    414 		    (struct wsdisplay_cursor *)data);
    415 	}
    416 	return (-1);
    417 }
    418 
    419 int
    420 tga_mmap(v, offset, prot)
    421 	void *v;
    422 	off_t offset;
    423 	int prot;
    424 {
    425 
    426 	/* XXX NEW MAPPING CODE... */
    427 
    428 #ifdef __alpha__
    429 	struct tga_softc *sc = v;
    430 
    431 	if (offset > sc->sc_dc->dc_tgaconf->tgac_cspace_size)
    432 		return -1;
    433 	return alpha_btop(sc->sc_dc->dc_paddr + offset);
    434 #else
    435 	return (-1);
    436 #endif
    437 }
    438 
    439 int
    440 tga_alloc_screen(v, type, cookiep, curxp, curyp, attrp)
    441 	void *v;
    442 	const struct wsscreen_descr *type;
    443 	void **cookiep;
    444 	int *curxp, *curyp;
    445 	long *attrp;
    446 {
    447 	struct tga_softc *sc = v;
    448 	long defattr;
    449 
    450 	if (sc->nscreens > 0)
    451 		return (ENOMEM);
    452 
    453 	*cookiep = &sc->sc_dc->dc_rcons; /* one and only for now */
    454 	*curxp = 0;
    455 	*curyp = 0;
    456 	rcons_alloc_attr(&sc->sc_dc->dc_rcons, 0, 0, 0, &defattr);
    457 	*attrp = defattr;
    458 	sc->nscreens++;
    459 	return (0);
    460 }
    461 
    462 void
    463 tga_free_screen(v, cookie)
    464 	void *v;
    465 	void *cookie;
    466 {
    467 	struct tga_softc *sc = v;
    468 
    469 	if (sc->sc_dc == &tga_console_dc)
    470 		panic("tga_free_screen: console");
    471 
    472 	sc->nscreens--;
    473 }
    474 
    475 void
    476 tga_show_screen(v, cookie)
    477 	void *v;
    478 	void *cookie;
    479 {
    480 }
    481 
    482 static int
    483 tga_load_font(v, cookie, first, num, stride, data)
    484 	void *v;
    485 	void *cookie;
    486 	int first, num, stride;
    487 	void *data;
    488 {
    489 	return (EINVAL);
    490 }
    491 
    492 int
    493 tga_cnattach(iot, memt, pc, bus, device, function)
    494 	bus_space_tag_t iot, memt;
    495 	pci_chipset_tag_t pc;
    496 	int bus, device, function;
    497 {
    498 	struct tga_devconfig *dcp = &tga_console_dc;
    499 	long defattr;
    500 
    501 	tga_getdevconfig(memt, pc,
    502 	    pci_make_tag(pc, bus, device, function), dcp);
    503 
    504 	/* sanity checks */
    505 	if (dcp->dc_vaddr == NULL)
    506 		panic("tga_console(%d, %d): couldn't map memory space",
    507 		    device, function);
    508 	if (dcp->dc_tgaconf == NULL)
    509 		panic("tga_console(%d, %d): unknown board configuration",
    510 		    device, function);
    511 
    512 	/*
    513 	 * Initialize the RAMDAC but DO NOT allocate any private storage.
    514 	 * Initialization includes disabling cursor, setting a sane
    515 	 * colormap, etc.  It will be reinitialized in tgaattach().
    516 	 */
    517 	(*dcp->dc_tgaconf->tgac_ramdac->tgar_init)(dcp, 0);
    518 
    519 	rcons_alloc_attr(&dcp->dc_rcons, 0, 0, 0, &defattr);
    520 
    521 	wsdisplay_cnattach(&tga_stdscreen, &dcp->dc_rcons,
    522 			   0, 0, defattr);
    523 
    524 	return(0);
    525 }
    526 
    527 /*
    528  * Functions to blank and unblank the display.
    529  */
    530 void
    531 tga_blank(dc)
    532 	struct tga_devconfig *dc;
    533 {
    534 
    535 	if (!dc->dc_blanked) {
    536 		dc->dc_blanked = 1;
    537 		dc->dc_regs[TGA_REG_VVVR] |= VVR_BLANK;		/* XXX */
    538 	}
    539 }
    540 
    541 void
    542 tga_unblank(dc)
    543 	struct tga_devconfig *dc;
    544 {
    545 
    546 	if (dc->dc_blanked) {
    547 		dc->dc_blanked = 0;
    548 		dc->dc_regs[TGA_REG_VVVR] &= ~VVR_BLANK;	/* XXX */
    549 	}
    550 }
    551 
    552 /*
    553  * Functions to manipulate the built-in cursor handing hardware.
    554  */
    555 int
    556 tga_builtin_set_cursor(dc, cursorp)
    557 	struct tga_devconfig *dc;
    558 	struct wsdisplay_cursor *cursorp;
    559 {
    560 	int count, error, v;
    561 
    562 	v = cursorp->which;
    563 	if (v & WSDISPLAY_CURSOR_DOCMAP) {
    564 		error = (*dc->dc_tgaconf->tgac_ramdac->tgar_check_curcmap)(dc,
    565 		    cursorp);
    566 		if (error)
    567 			return (error);
    568 	}
    569 	if (v & WSDISPLAY_CURSOR_DOSHAPE) {
    570 		if ((u_int)cursorp->size.x != 64 ||
    571 		    (u_int)cursorp->size.y > 64)
    572 			return (EINVAL);
    573 		/* The cursor is 2 bits deep, and there is no mask */
    574 		count = (cursorp->size.y * 64 * 2) / NBBY;
    575 #if defined(UVM)
    576 		if (!uvm_useracc(cursorp->image, count, B_READ))
    577 			return (EFAULT);
    578 #else
    579 		if (!useracc(cursorp->image, count, B_READ))
    580 			return (EFAULT);
    581 #endif
    582 	}
    583 	if (v & WSDISPLAY_CURSOR_DOHOT)		/* not supported */
    584 		return EINVAL;
    585 
    586 	/* parameters are OK; do it */
    587 	if (v & WSDISPLAY_CURSOR_DOCUR) {
    588 		if (cursorp->enable)
    589 			dc->dc_regs[TGA_REG_VVVR] |= 0x04;	/* XXX */
    590 		else
    591 			dc->dc_regs[TGA_REG_VVVR] &= ~0x04;	/* XXX */
    592 	}
    593 	if (v & WSDISPLAY_CURSOR_DOPOS) {
    594 		dc->dc_regs[TGA_REG_CXYR] = ((cursorp->pos.y & 0xfff) << 12) |
    595 		    (cursorp->pos.x & 0xfff);
    596 	}
    597 	if (v & WSDISPLAY_CURSOR_DOCMAP) {
    598 		/* can't fail. */
    599 		(*dc->dc_tgaconf->tgac_ramdac->tgar_set_curcmap)(dc, cursorp);
    600 	}
    601 	if (v & WSDISPLAY_CURSOR_DOSHAPE) {
    602 		count = ((64 * 2) / NBBY) * cursorp->size.y;
    603 		dc->dc_regs[TGA_REG_CCBR] =
    604 		    (dc->dc_regs[TGA_REG_CCBR] & ~0xfc00) |
    605 		    (cursorp->size.y << 10);
    606 		copyin(cursorp->image, (char *)(dc->dc_vaddr +
    607 		    (dc->dc_regs[TGA_REG_CCBR] & 0x3ff)),
    608 		    count);				/* can't fail. */
    609 	}
    610 	return (0);
    611 }
    612 
    613 int
    614 tga_builtin_get_cursor(dc, cursorp)
    615 	struct tga_devconfig *dc;
    616 	struct wsdisplay_cursor *cursorp;
    617 {
    618 	int count, error;
    619 
    620 	cursorp->which = WSDISPLAY_CURSOR_DOALL &
    621 	    ~(WSDISPLAY_CURSOR_DOHOT | WSDISPLAY_CURSOR_DOCMAP);
    622 	cursorp->enable = (dc->dc_regs[TGA_REG_VVVR] & 0x04) != 0;
    623 	cursorp->pos.x = dc->dc_regs[TGA_REG_CXYR] & 0xfff;
    624 	cursorp->pos.y = (dc->dc_regs[TGA_REG_CXYR] >> 12) & 0xfff;
    625 	cursorp->size.x = 64;
    626 	cursorp->size.y = (dc->dc_regs[TGA_REG_CCBR] >> 10) & 0x3f;
    627 
    628 	if (cursorp->image != NULL) {
    629 		count = (cursorp->size.y * 64 * 2) / NBBY;
    630 		error = copyout((char *)(dc->dc_vaddr +
    631 		      (dc->dc_regs[TGA_REG_CCBR] & 0x3ff)),
    632 		    cursorp->image, count);
    633 		if (error)
    634 			return (error);
    635 		/* No mask */
    636 	}
    637 	error = (*dc->dc_tgaconf->tgac_ramdac->tgar_get_curcmap)(dc, cursorp);
    638 	return (error);
    639 }
    640 
    641 int
    642 tga_builtin_set_curpos(dc, curposp)
    643 	struct tga_devconfig *dc;
    644 	struct wsdisplay_curpos *curposp;
    645 {
    646 
    647 	dc->dc_regs[TGA_REG_CXYR] =
    648 	    ((curposp->y & 0xfff) << 12) | (curposp->x & 0xfff);
    649 	return (0);
    650 }
    651 
    652 int
    653 tga_builtin_get_curpos(dc, curposp)
    654 	struct tga_devconfig *dc;
    655 	struct wsdisplay_curpos *curposp;
    656 {
    657 
    658 	curposp->x = dc->dc_regs[TGA_REG_CXYR] & 0xfff;
    659 	curposp->y = (dc->dc_regs[TGA_REG_CXYR] >> 12) & 0xfff;
    660 	return (0);
    661 }
    662 
    663 int
    664 tga_builtin_get_curmax(dc, curposp)
    665 	struct tga_devconfig *dc;
    666 	struct wsdisplay_curpos *curposp;
    667 {
    668 
    669 	curposp->x = curposp->y = 64;
    670 	return (0);
    671 }
    672