Home | History | Annotate | Line # | Download | only in pci
tga.c revision 1.12
      1 /* $NetBSD: tga.c,v 1.12 1999/01/11 22:11:36 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 
    112 struct wsdisplay_accessops tga_accessops = {
    113 	tga_ioctl,
    114 	tga_mmap,
    115 	tga_alloc_screen,
    116 	tga_free_screen,
    117 	tga_show_screen,
    118 	0 /* load_font */
    119 };
    120 
    121 void	tga_blank __P((struct tga_devconfig *));
    122 void	tga_unblank __P((struct tga_devconfig *));
    123 
    124 int
    125 tgamatch(parent, match, aux)
    126 	struct device *parent;
    127 	struct cfdata *match;
    128 	void *aux;
    129 {
    130 	struct pci_attach_args *pa = aux;
    131 
    132 	if (PCI_VENDOR(pa->pa_id) != PCI_VENDOR_DEC ||
    133 	    PCI_PRODUCT(pa->pa_id) != PCI_PRODUCT_DEC_21030)
    134 		return (0);
    135 
    136 	return (10);
    137 }
    138 
    139 void
    140 tga_getdevconfig(memt, pc, tag, dc)
    141 	bus_space_tag_t memt;
    142 	pci_chipset_tag_t pc;
    143 	pcitag_t tag;
    144 	struct tga_devconfig *dc;
    145 {
    146 	const struct tga_conf *tgac;
    147 	const struct tga_ramdac_conf *tgar;
    148 	struct raster *rap;
    149 	struct rcons *rcp;
    150 	bus_size_t pcisize;
    151 	int i, flags;
    152 
    153 	dc->dc_memt = memt;
    154 	dc->dc_pc = pc;
    155 
    156 	dc->dc_pcitag = tag;
    157 
    158 	/* XXX magic number */
    159 	if (pci_mapreg_info(pc, tag, 0x10,
    160 	    PCI_MAPREG_TYPE_MEM | PCI_MAPREG_MEM_TYPE_32BIT,
    161 	    &dc->dc_pcipaddr, &pcisize, &flags))
    162 		return;
    163 	if ((flags & BUS_SPACE_MAP_CACHEABLE) == 0)		/* XXX */
    164 		panic("tga memory not cacheable");
    165 
    166 	if (bus_space_map(memt, dc->dc_pcipaddr, pcisize,
    167 	    BUS_SPACE_MAP_CACHEABLE | BUS_SPACE_MAP_LINEAR, &dc->dc_vaddr))
    168 		return;
    169 #ifdef __alpha__
    170 	dc->dc_paddr = ALPHA_K0SEG_TO_PHYS(dc->dc_vaddr);	/* XXX */
    171 #endif
    172 
    173 	dc->dc_regs = (tga_reg_t *)(dc->dc_vaddr + TGA_MEM_CREGS);
    174 	dc->dc_tga_type = tga_identify(dc->dc_regs);
    175 	tgac = dc->dc_tgaconf = tga_getconf(dc->dc_tga_type);
    176 	if (tgac == NULL)
    177 		return;
    178 
    179 #if 0
    180 	/* XXX on the Alpha, pcisize = 4 * cspace_size. */
    181 	if (tgac->tgac_cspace_size != pcisize)			/* sanity */
    182 		panic("tga_getdevconfig: memory size mismatch?");
    183 #endif
    184 
    185 	tgar = tgac->tgac_ramdac;
    186 
    187 	switch (dc->dc_regs[TGA_REG_VHCR] & 0x1ff) {		/* XXX */
    188 	case 0:
    189 		dc->dc_wid = 8192;
    190 		break;
    191 
    192 	case 1:
    193 		dc->dc_wid = 8196;
    194 		break;
    195 
    196 	default:
    197 		dc->dc_wid = (dc->dc_regs[TGA_REG_VHCR] & 0x1ff) * 4; /* XXX */
    198 		break;
    199 	}
    200 
    201 	dc->dc_rowbytes = dc->dc_wid * (dc->dc_tgaconf->tgac_phys_depth / 8);
    202 
    203 	if ((dc->dc_regs[TGA_REG_VHCR] & 0x00000001) != 0 &&	/* XXX */
    204 	    (dc->dc_regs[TGA_REG_VHCR] & 0x80000000) != 0) {	/* XXX */
    205 		dc->dc_wid -= 4;
    206 		/*
    207 		 * XXX XXX turning off 'odd' shouldn't be necesssary,
    208 		 * XXX XXX but i can't make X work with the weird size.
    209 		 */
    210 		dc->dc_regs[TGA_REG_VHCR] &= ~0x80000001;
    211 		dc->dc_rowbytes =
    212 		    dc->dc_wid * (dc->dc_tgaconf->tgac_phys_depth / 8);
    213 	}
    214 
    215 	dc->dc_ht = (dc->dc_regs[TGA_REG_VVCR] & 0x7ff);	/* XXX */
    216 
    217 	/* XXX this seems to be what DEC does */
    218 	dc->dc_regs[TGA_REG_CCBR] = 0;
    219 	dc->dc_regs[TGA_REG_VVBR] = 1;
    220 	dc->dc_videobase = dc->dc_vaddr + tgac->tgac_dbuf[0] +
    221 	    1 * tgac->tgac_vvbr_units;
    222 	dc->dc_blanked = 1;
    223 	tga_unblank(dc);
    224 
    225 	/*
    226 	 * Set all bits in the pixel mask, to enable writes to all pixels.
    227 	 * It seems that the console firmware clears some of them
    228 	 * under some circumstances, which causes cute vertical stripes.
    229 	 */
    230 	dc->dc_regs[TGA_REG_GPXR_P] = 0xffffffff;
    231 
    232 	/* clear the screen */
    233 	for (i = 0; i < dc->dc_ht * dc->dc_rowbytes; i += sizeof(u_int32_t))
    234 		*(u_int32_t *)(dc->dc_videobase + i) = 0;
    235 
    236 	/* initialize the raster */
    237 	rap = &dc->dc_raster;
    238 	rap->width = dc->dc_wid;
    239 	rap->height = dc->dc_ht;
    240 	rap->depth = tgac->tgac_phys_depth;
    241 	rap->linelongs = dc->dc_rowbytes / sizeof(u_int32_t);
    242 	rap->pixels = (u_int32_t *)dc->dc_videobase;
    243 
    244 	/* initialize the raster console blitter */
    245 	rcp = &dc->dc_rcons;
    246 	rcp->rc_sp = rap;
    247 	rcp->rc_crow = rcp->rc_ccol = -1;
    248 	rcp->rc_crowp = &rcp->rc_crow;
    249 	rcp->rc_ccolp = &rcp->rc_ccol;
    250 	rcons_init(rcp, 34, 80);
    251 
    252 	tga_stdscreen.nrows = dc->dc_rcons.rc_maxrow;
    253 	tga_stdscreen.ncols = dc->dc_rcons.rc_maxcol;
    254 }
    255 
    256 void
    257 tgaattach(parent, self, aux)
    258 	struct device *parent, *self;
    259 	void *aux;
    260 {
    261 	struct pci_attach_args *pa = aux;
    262 	struct tga_softc *sc = (struct tga_softc *)self;
    263 	struct wsemuldisplaydev_attach_args aa;
    264 	pci_intr_handle_t intrh;
    265 	const char *intrstr;
    266 	u_int8_t rev;
    267 	int console;
    268 
    269 #ifdef __alpha__
    270 	console = (pa->pa_tag == tga_console_dc.dc_pcitag);
    271 #else
    272 	console = 0;
    273 #endif
    274 	if (console) {
    275 		sc->sc_dc = &tga_console_dc;
    276 		sc->nscreens = 1;
    277 	} else {
    278 		sc->sc_dc = (struct tga_devconfig *)
    279 		    malloc(sizeof(struct tga_devconfig), M_DEVBUF, M_WAITOK);
    280 		bzero(sc->sc_dc, sizeof(struct tga_devconfig));
    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 wsd_fbip
    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_SVIDEO:
    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_GVIDEO:
    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 || offset < 0)
    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 int
    483 tga_cnattach(iot, memt, pc, bus, device, function)
    484 	bus_space_tag_t iot, memt;
    485 	pci_chipset_tag_t pc;
    486 	int bus, device, function;
    487 {
    488 	struct tga_devconfig *dcp = &tga_console_dc;
    489 	long defattr;
    490 
    491 	tga_getdevconfig(memt, pc,
    492 	    pci_make_tag(pc, bus, device, function), dcp);
    493 
    494 	/* sanity checks */
    495 	if (dcp->dc_vaddr == NULL)
    496 		panic("tga_console(%d, %d): couldn't map memory space",
    497 		    device, function);
    498 	if (dcp->dc_tgaconf == NULL)
    499 		panic("tga_console(%d, %d): unknown board configuration",
    500 		    device, function);
    501 
    502 	/*
    503 	 * Initialize the RAMDAC but DO NOT allocate any private storage.
    504 	 * Initialization includes disabling cursor, setting a sane
    505 	 * colormap, etc.  It will be reinitialized in tgaattach().
    506 	 */
    507 	(*dcp->dc_tgaconf->tgac_ramdac->tgar_init)(dcp, 0);
    508 
    509 	rcons_alloc_attr(&dcp->dc_rcons, 0, 0, 0, &defattr);
    510 
    511 	wsdisplay_cnattach(&tga_stdscreen, &dcp->dc_rcons,
    512 			   0, 0, defattr);
    513 
    514 	return(0);
    515 }
    516 
    517 /*
    518  * Functions to blank and unblank the display.
    519  */
    520 void
    521 tga_blank(dc)
    522 	struct tga_devconfig *dc;
    523 {
    524 
    525 	if (!dc->dc_blanked) {
    526 		dc->dc_blanked = 1;
    527 		dc->dc_regs[TGA_REG_VVVR] |= VVR_BLANK;		/* XXX */
    528 	}
    529 }
    530 
    531 void
    532 tga_unblank(dc)
    533 	struct tga_devconfig *dc;
    534 {
    535 
    536 	if (dc->dc_blanked) {
    537 		dc->dc_blanked = 0;
    538 		dc->dc_regs[TGA_REG_VVVR] &= ~VVR_BLANK;	/* XXX */
    539 	}
    540 }
    541 
    542 /*
    543  * Functions to manipulate the built-in cursor handing hardware.
    544  */
    545 int
    546 tga_builtin_set_cursor(dc, cursorp)
    547 	struct tga_devconfig *dc;
    548 	struct wsdisplay_cursor *cursorp;
    549 {
    550 	int count, error, v;
    551 
    552 	v = cursorp->which;
    553 	if (v & WSDISPLAY_CURSOR_DOCMAP) {
    554 		error = (*dc->dc_tgaconf->tgac_ramdac->tgar_check_curcmap)(dc,
    555 		    cursorp);
    556 		if (error)
    557 			return (error);
    558 	}
    559 	if (v & WSDISPLAY_CURSOR_DOSHAPE) {
    560 		if ((u_int)cursorp->size.x != 64 ||
    561 		    (u_int)cursorp->size.y > 64)
    562 			return (EINVAL);
    563 		/* The cursor is 2 bits deep, and there is no mask */
    564 		count = (cursorp->size.y * 64 * 2) / NBBY;
    565 #if defined(UVM)
    566 		if (!uvm_useracc(cursorp->image, count, B_READ))
    567 			return (EFAULT);
    568 #else
    569 		if (!useracc(cursorp->image, count, B_READ))
    570 			return (EFAULT);
    571 #endif
    572 	}
    573 	if (v & WSDISPLAY_CURSOR_DOHOT)		/* not supported */
    574 		return EINVAL;
    575 
    576 	/* parameters are OK; do it */
    577 	if (v & WSDISPLAY_CURSOR_DOCUR) {
    578 		if (cursorp->enable)
    579 			dc->dc_regs[TGA_REG_VVVR] |= 0x04;	/* XXX */
    580 		else
    581 			dc->dc_regs[TGA_REG_VVVR] &= ~0x04;	/* XXX */
    582 	}
    583 	if (v & WSDISPLAY_CURSOR_DOPOS) {
    584 		dc->dc_regs[TGA_REG_CXYR] = ((cursorp->pos.y & 0xfff) << 12) |
    585 		    (cursorp->pos.x & 0xfff);
    586 	}
    587 	if (v & WSDISPLAY_CURSOR_DOCMAP) {
    588 		/* can't fail. */
    589 		(*dc->dc_tgaconf->tgac_ramdac->tgar_set_curcmap)(dc, cursorp);
    590 	}
    591 	if (v & WSDISPLAY_CURSOR_DOSHAPE) {
    592 		count = ((64 * 2) / NBBY) * cursorp->size.y;
    593 		dc->dc_regs[TGA_REG_CCBR] =
    594 		    (dc->dc_regs[TGA_REG_CCBR] & ~0xfc00) |
    595 		    (cursorp->size.y << 10);
    596 		copyin(cursorp->image, (char *)(dc->dc_vaddr +
    597 		    (dc->dc_regs[TGA_REG_CCBR] & 0x3ff)),
    598 		    count);				/* can't fail. */
    599 	}
    600 	return (0);
    601 }
    602 
    603 int
    604 tga_builtin_get_cursor(dc, cursorp)
    605 	struct tga_devconfig *dc;
    606 	struct wsdisplay_cursor *cursorp;
    607 {
    608 	int count, error;
    609 
    610 	cursorp->which = WSDISPLAY_CURSOR_DOALL &
    611 	    ~(WSDISPLAY_CURSOR_DOHOT | WSDISPLAY_CURSOR_DOCMAP);
    612 	cursorp->enable = (dc->dc_regs[TGA_REG_VVVR] & 0x04) != 0;
    613 	cursorp->pos.x = dc->dc_regs[TGA_REG_CXYR] & 0xfff;
    614 	cursorp->pos.y = (dc->dc_regs[TGA_REG_CXYR] >> 12) & 0xfff;
    615 	cursorp->size.x = 64;
    616 	cursorp->size.y = (dc->dc_regs[TGA_REG_CCBR] >> 10) & 0x3f;
    617 
    618 	if (cursorp->image != NULL) {
    619 		count = (cursorp->size.y * 64 * 2) / NBBY;
    620 		error = copyout((char *)(dc->dc_vaddr +
    621 		      (dc->dc_regs[TGA_REG_CCBR] & 0x3ff)),
    622 		    cursorp->image, count);
    623 		if (error)
    624 			return (error);
    625 		/* No mask */
    626 	}
    627 	error = (*dc->dc_tgaconf->tgac_ramdac->tgar_get_curcmap)(dc, cursorp);
    628 	return (error);
    629 }
    630 
    631 int
    632 tga_builtin_set_curpos(dc, curposp)
    633 	struct tga_devconfig *dc;
    634 	struct wsdisplay_curpos *curposp;
    635 {
    636 
    637 	dc->dc_regs[TGA_REG_CXYR] =
    638 	    ((curposp->y & 0xfff) << 12) | (curposp->x & 0xfff);
    639 	return (0);
    640 }
    641 
    642 int
    643 tga_builtin_get_curpos(dc, curposp)
    644 	struct tga_devconfig *dc;
    645 	struct wsdisplay_curpos *curposp;
    646 {
    647 
    648 	curposp->x = dc->dc_regs[TGA_REG_CXYR] & 0xfff;
    649 	curposp->y = (dc->dc_regs[TGA_REG_CXYR] >> 12) & 0xfff;
    650 	return (0);
    651 }
    652 
    653 int
    654 tga_builtin_get_curmax(dc, curposp)
    655 	struct tga_devconfig *dc;
    656 	struct wsdisplay_curpos *curposp;
    657 {
    658 
    659 	curposp->x = curposp->y = 64;
    660 	return (0);
    661 }
    662