Home | History | Annotate | Line # | Download | only in pci
tga.c revision 1.56
      1 /* $NetBSD: tga.c,v 1.56 2003/10/29 04:43:18 mycroft 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 <sys/cdefs.h>
     31 __KERNEL_RCSID(0, "$NetBSD: tga.c,v 1.56 2003/10/29 04:43:18 mycroft Exp $");
     32 
     33 #include <sys/param.h>
     34 #include <sys/systm.h>
     35 #include <sys/kernel.h>
     36 #include <sys/device.h>
     37 #include <sys/conf.h>
     38 #include <sys/malloc.h>
     39 #include <sys/buf.h>
     40 #include <sys/ioctl.h>
     41 
     42 #include <machine/bus.h>
     43 #include <machine/intr.h>
     44 
     45 #include <dev/pci/pcireg.h>
     46 #include <dev/pci/pcivar.h>
     47 #include <dev/pci/pcidevs.h>
     48 #include <dev/pci/tgareg.h>
     49 #include <dev/pci/tgavar.h>
     50 #include <dev/ic/bt485reg.h>
     51 #include <dev/ic/bt485var.h>
     52 #include <dev/ic/bt463reg.h>
     53 #include <dev/ic/bt463var.h>
     54 #include <dev/ic/ibm561var.h>
     55 
     56 #include <dev/wscons/wsconsio.h>
     57 #include <dev/wscons/wscons_raster.h>
     58 #include <dev/rasops/rasops.h>
     59 #include <dev/wsfont/wsfont.h>
     60 #include <uvm/uvm_extern.h>
     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 CFATTACH_DECL(tga, sizeof(struct tga_softc),
     67     tgamatch, tgaattach, NULL, NULL);
     68 
     69 int	tga_identify __P((struct tga_devconfig *));
     70 const struct tga_conf *tga_getconf __P((int));
     71 static void	tga_init __P((bus_space_tag_t memt, pci_chipset_tag_t pc,
     72 	    pcitag_t tag, struct tga_devconfig *dc));
     73 
     74 static int tga_matchcommon __P((bus_space_tag_t, pci_chipset_tag_t, pcitag_t));
     75 static void tga_mapaddrs __P((bus_space_tag_t memt, pci_chipset_tag_t pc,
     76 	pcitag_t, bus_size_t *pcisize, struct tga_devconfig *dc));
     77 unsigned tga_getdotclock __P((struct tga_devconfig *dc));
     78 
     79 struct tga_devconfig tga_console_dc;
     80 
     81 int tga_ioctl __P((void *, u_long, caddr_t, int, struct proc *));
     82 paddr_t tga_mmap __P((void *, off_t, int));
     83 static void tga_copyrows __P((void *, int, int, int));
     84 static void tga_copycols __P((void *, int, int, int, int));
     85 static int tga_alloc_screen __P((void *, const struct wsscreen_descr *,
     86 				      void **, int *, int *, long *));
     87 static void tga_free_screen __P((void *, void *));
     88 static int tga_show_screen __P((void *, void *, int,
     89 				void (*) (void *, int, int), void *));
     90 static int tga_rop __P((struct rasops_info *, int, int, int, int, int,
     91 	struct rasops_info *, int, int));
     92 static int tga_rop_vtov __P((struct rasops_info *, int, int, int, int,
     93 	int, struct rasops_info *, int, int ));
     94 static void tga_putchar __P((void *c, int row, int col,
     95 				u_int uc, long attr));
     96 static void tga_eraserows __P((void *, int, int, long));
     97 static void	tga_erasecols __P((void *, int, int, int, long));
     98 void tga2_init __P((struct tga_devconfig *));
     99 
    100 static void tga_config_interrupts __P((struct device *));
    101 
    102 /* RAMDAC interface functions */
    103 static int		tga_sched_update __P((void *, void (*)(void *)));
    104 static void		tga_ramdac_wr __P((void *, u_int, u_int8_t));
    105 static u_int8_t	tga_ramdac_rd __P((void *, u_int));
    106 static void		tga_bt463_wr __P((void *, u_int, u_int8_t));
    107 static u_int8_t	tga_bt463_rd __P((void *, u_int));
    108 static void		tga2_ramdac_wr __P((void *, u_int, u_int8_t));
    109 static u_int8_t	tga2_ramdac_rd __P((void *, u_int));
    110 
    111 /* Interrupt handler */
    112 static int	tga_intr __P((void *));
    113 
    114 /* The NULL entries will get filled in by rasops_init().
    115  * XXX and the non-NULL ones will be overwritten; reset after calling it.
    116  */
    117 struct wsdisplay_emulops tga_emulops = {
    118 	NULL,
    119 	NULL,
    120 	tga_putchar,
    121 	tga_copycols,
    122 	tga_erasecols,
    123 	tga_copyrows,
    124 	tga_eraserows,
    125 	NULL,
    126 };
    127 
    128 struct wsscreen_descr tga_stdscreen = {
    129 	"std",
    130 	0, 0,	/* will be filled in -- XXX shouldn't, it's global */
    131 	&tga_emulops,
    132 	0, 0,
    133 	WSSCREEN_REVERSE
    134 };
    135 
    136 const struct wsscreen_descr *_tga_scrlist[] = {
    137 	&tga_stdscreen,
    138 	/* XXX other formats, graphics screen? */
    139 };
    140 
    141 struct wsscreen_list tga_screenlist = {
    142 	sizeof(_tga_scrlist) / sizeof(struct wsscreen_descr *), _tga_scrlist
    143 };
    144 
    145 struct wsdisplay_accessops tga_accessops = {
    146 	tga_ioctl,
    147 	tga_mmap,
    148 	tga_alloc_screen,
    149 	tga_free_screen,
    150 	tga_show_screen,
    151 	0 /* load_font */
    152 };
    153 
    154 static void	tga_blank __P((struct tga_devconfig *));
    155 static void	tga_unblank __P((struct tga_devconfig *));
    156 
    157 int
    158 tga_cnmatch(iot, memt, pc, tag)
    159 	bus_space_tag_t iot, memt;
    160 	pci_chipset_tag_t pc;
    161 	pcitag_t tag;
    162 {
    163 	return tga_matchcommon(memt, pc, tag);
    164 }
    165 
    166 int
    167 tgamatch(parent, match, aux)
    168 	struct device *parent;
    169 	struct cfdata *match;
    170 	void *aux;
    171 {
    172 	struct pci_attach_args *pa = aux;
    173 
    174 	if (PCI_VENDOR(pa->pa_id) != PCI_VENDOR_DEC)
    175 		return (0);
    176 
    177 	switch (PCI_PRODUCT(pa->pa_id)) {
    178 	case PCI_PRODUCT_DEC_21030:
    179 	case PCI_PRODUCT_DEC_PBXGB:
    180 		break;
    181 	default:
    182 		return 0;
    183 	}
    184 
    185 	/* short-circuit the following test, as we
    186 	 * already have the memory mapped and hence
    187 	 * cannot perform it---and we are the console
    188 	 * anyway.
    189 	 */
    190 	if (pa->pa_tag == tga_console_dc.dc_pcitag)
    191 		return 10;
    192 
    193 	return tga_matchcommon(pa->pa_memt, pa->pa_pc, pa->pa_tag);
    194 }
    195 
    196 static int
    197 tga_matchcommon(memt, pc, tag)
    198 	bus_space_tag_t memt;
    199 	pci_chipset_tag_t pc;
    200 	pcitag_t tag;
    201 {
    202 	struct tga_devconfig tmp_dc;
    203 	struct tga_devconfig *dc = &tmp_dc;
    204 	bus_size_t pcisize;
    205 
    206 	tga_mapaddrs(memt, pc, tag, &pcisize, dc);
    207 	dc->dc_tga_type = tga_identify(dc);
    208 
    209 	dc->dc_tgaconf = tga_getconf(dc->dc_tga_type);
    210 	bus_space_unmap(memt, dc->dc_memh, pcisize);
    211 	if (dc->dc_tgaconf)
    212 		return 10;
    213 	return 0;
    214 }
    215 
    216 static void
    217 tga_mapaddrs(memt, pc, tag, pcisize, dc)
    218 	bus_space_tag_t memt;
    219 	pci_chipset_tag_t pc;
    220 	pcitag_t tag;
    221 	bus_size_t *pcisize;
    222 	struct tga_devconfig *dc;
    223 {
    224 	int flags;
    225 
    226 	dc->dc_memt = memt;
    227 	dc->dc_tgaconf = NULL;
    228 
    229 	/* XXX magic number */
    230 	if (pci_mapreg_info(pc, tag, 0x10,
    231 	    PCI_MAPREG_TYPE_MEM | PCI_MAPREG_MEM_TYPE_32BIT,
    232 	    &dc->dc_pcipaddr, pcisize, &flags))
    233 		panic("tga_mapaddrs: pci_mapreg_info() failed");
    234 	if ((flags & BUS_SPACE_MAP_PREFETCHABLE) == 0)		/* XXX */
    235 		panic("tga memory not prefetchable");
    236 
    237 	if (bus_space_map(memt, dc->dc_pcipaddr, *pcisize,
    238 	    BUS_SPACE_MAP_PREFETCHABLE | BUS_SPACE_MAP_LINEAR, &dc->dc_memh))
    239 		panic("tga_mapaddrs: could not map TGA address space");
    240 	dc->dc_vaddr = (vaddr_t) bus_space_vaddr(memt, dc->dc_memh);
    241 
    242 	bus_space_subregion(dc->dc_memt, dc->dc_memh,
    243 						TGA_MEM_CREGS, TGA_CREGS_SIZE,
    244 						&dc->dc_regs);
    245 }
    246 
    247 static void
    248 tga_init(memt, pc, tag, dc)
    249 	bus_space_tag_t memt;
    250 	pci_chipset_tag_t pc;
    251 	pcitag_t tag;
    252 	struct tga_devconfig *dc;
    253 {
    254 	const struct tga_conf *tgac;
    255 	struct rasops_info *rip;
    256 	int cookie;
    257 	bus_size_t pcisize;
    258 	int i;
    259 
    260 	dc->dc_pcitag = tag;
    261 	tga_mapaddrs(memt, pc, tag, &pcisize, dc);
    262 	dc->dc_tga_type = tga_identify(dc);
    263 	tgac = dc->dc_tgaconf = tga_getconf(dc->dc_tga_type);
    264 #if 0
    265 	/* XXX on the Alpha, pcisize = 4 * cspace_size. */
    266 	if (tgac->tgac_cspace_size != pcisize)			/* sanity */
    267 		panic("tga_init: memory size mismatch?");
    268 #endif
    269 
    270 	switch (TGARREG(dc, TGA_REG_GREV) & 0xff) {
    271 	case 0x01:
    272 	case 0x02:
    273 	case 0x03:
    274 	case 0x04:
    275 		dc->dc_tga2 = 0;
    276 		break;
    277 	case 0x20:
    278 	case 0x21:
    279 	case 0x22:
    280 		dc->dc_tga2 = 1;
    281 		break;
    282 	default:
    283 		panic("tga_init: TGA Revision not recognized");
    284 	}
    285 
    286 	if (dc->dc_tga2)
    287 		tga2_init(dc);
    288 
    289 	switch (TGARREG(dc, TGA_REG_VHCR) & 0x1ff) {		/* XXX */
    290 	case 0:
    291 		dc->dc_wid = 8192;
    292 		break;
    293 
    294 	case 1:
    295 		dc->dc_wid = 8196;
    296 		break;
    297 
    298 	default:
    299 		dc->dc_wid = (TGARREG(dc, TGA_REG_VHCR) & 0x1ff) * 4; /* XXX */
    300 		break;
    301 	}
    302 
    303 	/*
    304 	 * XXX XXX Turning off "odd" shouldn't be necessary,
    305 	 * XXX XXX but I can't make X work with the weird size.
    306 	 */
    307 	if ((TGARREG(dc, TGA_REG_VHCR) & 0x00000001) != 0 &&	/* XXX */
    308 	    (TGARREG(dc, TGA_REG_VHCR) & 0x80000000) != 0) {	/* XXX */
    309 		TGAWREG(dc, TGA_REG_VHCR,
    310 		    (TGARREG(dc, TGA_REG_VHCR) & ~0x80000001));
    311 		dc->dc_wid -= 4;
    312 	}
    313 
    314 	dc->dc_rowbytes = dc->dc_wid * (dc->dc_tgaconf->tgac_phys_depth / 8);
    315 	dc->dc_ht = (TGARREG(dc, TGA_REG_VVCR) & 0x7ff);	/* XXX */
    316 
    317 	/* XXX this seems to be what DEC does */
    318 	TGAWREG(dc, TGA_REG_CCBR, 0);
    319 	TGAWREG(dc, TGA_REG_VVBR, 1);
    320 	dc->dc_videobase = dc->dc_vaddr + tgac->tgac_dbuf[0] +
    321 	    1 * tgac->tgac_vvbr_units;
    322 	dc->dc_blanked = 1;
    323 	tga_unblank(dc);
    324 
    325 	/*
    326 	 * Set all bits in the pixel mask, to enable writes to all pixels.
    327 	 * It seems that the console firmware clears some of them
    328 	 * under some circumstances, which causes cute vertical stripes.
    329 	 */
    330 	TGAWREG(dc, TGA_REG_GPXR_P, 0xffffffff);
    331 
    332 	/* clear the screen */
    333 	for (i = 0; i < dc->dc_ht * dc->dc_rowbytes; i += sizeof(u_int32_t))
    334 		*(u_int32_t *)(dc->dc_videobase + i) = 0;
    335 
    336 	/* Initialize rasops descriptor */
    337 	rip = &dc->dc_rinfo;
    338 	rip->ri_flg = RI_CENTER;
    339 	rip->ri_depth = tgac->tgac_phys_depth;
    340 	rip->ri_bits = (void *)dc->dc_videobase;
    341 	rip->ri_width = dc->dc_wid;
    342 	rip->ri_height = dc->dc_ht;
    343 	rip->ri_stride = dc->dc_rowbytes;
    344 	rip->ri_hw = dc;
    345 
    346 	if (tgac->tgac_phys_depth == 32) {
    347 		rip->ri_rnum = 8;
    348 		rip->ri_gnum = 8;
    349 		rip->ri_bnum = 8;
    350 		rip->ri_rpos = 16;
    351 		rip->ri_gpos = 8;
    352 		rip->ri_bpos = 0;
    353 	}
    354 
    355 	wsfont_init();
    356 	/* prefer 8 pixel wide font */
    357 	cookie = wsfont_find(NULL, 8, 0, 0, WSDISPLAY_FONTORDER_R2L,
    358 	    WSDISPLAY_FONTORDER_L2R);
    359 	if (cookie <= 0)
    360 		cookie = wsfont_find(NULL, 0, 0, 0, WSDISPLAY_FONTORDER_R2L,
    361 		    WSDISPLAY_FONTORDER_L2R);
    362 	if (cookie <= 0) {
    363 		printf("tga: no appropriate fonts.\n");
    364 		return;
    365 	}
    366 
    367 	/* the accelerated tga_putchar() needs LSbit left */
    368 	if (wsfont_lock(cookie, &dc->dc_rinfo.ri_font)) {
    369 		printf("tga: couldn't lock font\n");
    370 		return;
    371 	}
    372 	dc->dc_rinfo.ri_wsfcookie = cookie;
    373 
    374 	rasops_init(rip, 34, 80);
    375 
    376 	/* add our accelerated functions */
    377 	/* XXX shouldn't have to do this; rasops should leave non-NULL
    378 	 * XXX entries alone.
    379 	 */
    380 	dc->dc_rinfo.ri_ops.copyrows = tga_copyrows;
    381 	dc->dc_rinfo.ri_ops.eraserows = tga_eraserows;
    382 	dc->dc_rinfo.ri_ops.erasecols = tga_erasecols;
    383 	dc->dc_rinfo.ri_ops.copycols = tga_copycols;
    384 	dc->dc_rinfo.ri_ops.putchar = tga_putchar;
    385 
    386 	tga_stdscreen.nrows = dc->dc_rinfo.ri_rows;
    387 	tga_stdscreen.ncols = dc->dc_rinfo.ri_cols;
    388 	tga_stdscreen.textops = &dc->dc_rinfo.ri_ops;
    389 	tga_stdscreen.capabilities = dc->dc_rinfo.ri_caps;
    390 
    391 
    392 	dc->dc_intrenabled = 0;
    393 }
    394 
    395 void
    396 tgaattach(parent, self, aux)
    397 	struct device *parent, *self;
    398 	void *aux;
    399 {
    400 	struct pci_attach_args *pa = aux;
    401 	struct tga_softc *sc = (struct tga_softc *)self;
    402 	struct wsemuldisplaydev_attach_args aa;
    403 	pci_intr_handle_t intrh;
    404 	const char *intrstr;
    405 	u_int8_t rev;
    406 	int console;
    407 
    408 #if defined(__alpha__) || defined(arc)
    409 	console = (pa->pa_tag == tga_console_dc.dc_pcitag);
    410 #else
    411 	console = 0;
    412 #endif
    413 	if (console) {
    414 		sc->sc_dc = &tga_console_dc;
    415 		sc->nscreens = 1;
    416 	} else {
    417 		sc->sc_dc = (struct tga_devconfig *)
    418 		    malloc(sizeof(struct tga_devconfig), M_DEVBUF,
    419 		    M_WAITOK|M_ZERO);
    420 		tga_init(pa->pa_memt, pa->pa_pc, pa->pa_tag, sc->sc_dc);
    421 	}
    422 	if (sc->sc_dc->dc_vaddr == 0) {
    423 		printf(": couldn't map memory space; punt!\n");
    424 		return;
    425 	}
    426 
    427 	/* XXX say what's going on. */
    428 	intrstr = NULL;
    429 	if (pci_intr_map(pa, &intrh)) {
    430 		printf(": couldn't map interrupt");
    431 		return;
    432 	}
    433 	intrstr = pci_intr_string(pa->pa_pc, intrh);
    434 	sc->sc_intr = pci_intr_establish(pa->pa_pc, intrh, IPL_TTY, tga_intr,
    435 	    sc->sc_dc);
    436 	if (sc->sc_intr == NULL) {
    437 		printf(": couldn't establish interrupt");
    438 		if (intrstr != NULL)
    439 			printf("at %s", intrstr);
    440 		printf("\n");
    441 		return;
    442 	}
    443 
    444 	rev = PCI_REVISION(pa->pa_class);
    445 	switch (rev) {
    446 	case 0x1:
    447 	case 0x2:
    448 	case 0x3:
    449 		printf(": DC21030 step %c", 'A' + rev - 1);
    450 		break;
    451 	case 0x20:
    452 		printf(": TGA2 abstract software model");
    453 		break;
    454 	case 0x21:
    455 	case 0x22:
    456 		printf(": TGA2 pass %d", rev - 0x20);
    457 		break;
    458 
    459 	default:
    460 		printf("unknown stepping (0x%x)", rev);
    461 		break;
    462 	}
    463 	printf(", ");
    464 
    465 	/*
    466 	 * Get RAMDAC function vectors and call the RAMDAC functions
    467 	 * to allocate its private storage and pass that back to us.
    468 	 */
    469 
    470 	sc->sc_dc->dc_ramdac_funcs = sc->sc_dc->dc_tgaconf->ramdac_funcs();
    471 	if (!sc->sc_dc->dc_tga2) {
    472 	    if (sc->sc_dc->dc_tgaconf->ramdac_funcs == bt485_funcs)
    473 		  sc->sc_dc->dc_ramdac_cookie =
    474 			sc->sc_dc->dc_ramdac_funcs->ramdac_register(sc->sc_dc,
    475 		    tga_sched_update, tga_ramdac_wr, tga_ramdac_rd);
    476 		else
    477 		  sc->sc_dc->dc_ramdac_cookie =
    478 			sc->sc_dc->dc_ramdac_funcs->ramdac_register(sc->sc_dc,
    479 		    tga_sched_update, tga_bt463_wr, tga_bt463_rd);
    480 	} else {
    481 		sc->sc_dc->dc_ramdac_cookie =
    482 			sc->sc_dc->dc_ramdac_funcs->ramdac_register(sc->sc_dc,
    483 			tga_sched_update, tga2_ramdac_wr, tga2_ramdac_rd);
    484 
    485 		/* XXX this is a bit of a hack, setting the dotclock here */
    486 		if (sc->sc_dc->dc_tgaconf->ramdac_funcs != bt485_funcs)
    487 			(*sc->sc_dc->dc_ramdac_funcs->ramdac_set_dotclock)
    488 			    (sc->sc_dc->dc_ramdac_cookie,
    489 			    tga_getdotclock(sc->sc_dc));
    490 	}
    491 
    492 	/*
    493 	 * Initialize the RAMDAC.  Initialization includes disabling
    494 	 * cursor, setting a sane colormap, etc.  We presume that we've
    495 	 * filled in the necessary dot clock for PowerStorm 4d20.
    496 	 */
    497 	(*sc->sc_dc->dc_ramdac_funcs->ramdac_init)(sc->sc_dc->dc_ramdac_cookie);
    498 	TGAWREG(sc->sc_dc, TGA_REG_SISR, 0x00000001); /* XXX */
    499 
    500 	if (sc->sc_dc->dc_tgaconf == NULL) {
    501 		printf("unknown board configuration\n");
    502 		return;
    503 	}
    504 	printf("board type %s\n", sc->sc_dc->dc_tgaconf->tgac_name);
    505 	printf("%s: %d x %d, %dbpp, %s RAMDAC\n", sc->sc_dev.dv_xname,
    506 	    sc->sc_dc->dc_wid, sc->sc_dc->dc_ht,
    507 	    sc->sc_dc->dc_tgaconf->tgac_phys_depth,
    508 	    sc->sc_dc->dc_ramdac_funcs->ramdac_name);
    509 
    510 	if (intrstr != NULL)
    511 		printf("%s: interrupting at %s\n", sc->sc_dev.dv_xname,
    512 		    intrstr);
    513 
    514 	aa.console = console;
    515 	aa.scrdata = &tga_screenlist;
    516 	aa.accessops = &tga_accessops;
    517 	aa.accesscookie = sc;
    518 
    519 	config_found(self, &aa, wsemuldisplaydevprint);
    520 
    521 	config_interrupts(self, tga_config_interrupts);
    522 }
    523 
    524 static void
    525 tga_config_interrupts (d)
    526 	struct device *d;
    527 {
    528 	struct tga_softc *sc = (struct tga_softc *)d;
    529 	sc->sc_dc->dc_intrenabled = 1;
    530 }
    531 
    532 int
    533 tga_ioctl(v, cmd, data, flag, p)
    534 	void *v;
    535 	u_long cmd;
    536 	caddr_t data;
    537 	int flag;
    538 	struct proc *p;
    539 {
    540 	struct tga_softc *sc = v;
    541 	struct tga_devconfig *dc = sc->sc_dc;
    542 	struct ramdac_funcs *dcrf = dc->dc_ramdac_funcs;
    543 	struct ramdac_cookie *dcrc = dc->dc_ramdac_cookie;
    544 
    545 	switch (cmd) {
    546 	case WSDISPLAYIO_GTYPE:
    547 		*(u_int *)data = WSDISPLAY_TYPE_TGA;
    548 		return (0);
    549 
    550 	case WSDISPLAYIO_GINFO:
    551 #define	wsd_fbip ((struct wsdisplay_fbinfo *)data)
    552 		wsd_fbip->height = sc->sc_dc->dc_ht;
    553 		wsd_fbip->width = sc->sc_dc->dc_wid;
    554 		wsd_fbip->depth = sc->sc_dc->dc_tgaconf->tgac_phys_depth;
    555 #if 0
    556 		wsd_fbip->cmsize = 256;		/* XXX ??? */
    557 #else
    558 		wsd_fbip->cmsize = 1024;	/* XXX ??? */
    559 #endif
    560 #undef wsd_fbip
    561 		return (0);
    562 
    563 	case WSDISPLAYIO_GETCMAP:
    564 		return (*dcrf->ramdac_get_cmap)(dcrc,
    565 		    (struct wsdisplay_cmap *)data);
    566 
    567 	case WSDISPLAYIO_PUTCMAP:
    568 		return (*dcrf->ramdac_set_cmap)(dcrc,
    569 		    (struct wsdisplay_cmap *)data);
    570 
    571 	case WSDISPLAYIO_SVIDEO:
    572 		if (*(u_int *)data == WSDISPLAYIO_VIDEO_OFF)
    573 			tga_blank(sc->sc_dc);
    574 		else
    575 			tga_unblank(sc->sc_dc);
    576 		return (0);
    577 
    578 	case WSDISPLAYIO_GVIDEO:
    579 		*(u_int *)data = dc->dc_blanked ?
    580 		    WSDISPLAYIO_VIDEO_OFF : WSDISPLAYIO_VIDEO_ON;
    581 		return (0);
    582 
    583 	case WSDISPLAYIO_GCURPOS:
    584 		return (*dcrf->ramdac_get_curpos)(dcrc,
    585 		    (struct wsdisplay_curpos *)data);
    586 
    587 	case WSDISPLAYIO_SCURPOS:
    588 		return (*dcrf->ramdac_set_curpos)(dcrc,
    589 		    (struct wsdisplay_curpos *)data);
    590 
    591 	case WSDISPLAYIO_GCURMAX:
    592 		return (*dcrf->ramdac_get_curmax)(dcrc,
    593 		    (struct wsdisplay_curpos *)data);
    594 
    595 	case WSDISPLAYIO_GCURSOR:
    596 		return (*dcrf->ramdac_get_cursor)(dcrc,
    597 		    (struct wsdisplay_cursor *)data);
    598 
    599 	case WSDISPLAYIO_SCURSOR:
    600 		return (*dcrf->ramdac_set_cursor)(dcrc,
    601 		    (struct wsdisplay_cursor *)data);
    602 	}
    603 	return (EPASSTHROUGH);
    604 }
    605 
    606 static int
    607 tga_sched_update(v, f)
    608 	void	*v;
    609 	void	(*f) __P((void *));
    610 {
    611 	struct tga_devconfig *dc = v;
    612 
    613 	if (dc->dc_intrenabled) {
    614 		/* Arrange for f to be called at the next end-of-frame interrupt */
    615 		dc->dc_ramdac_intr = f;
    616 		TGAWREG(dc, TGA_REG_SISR, 0x00010000);
    617 	} else {
    618 		/* Spin until the end-of-frame, then call f */
    619 		TGAWREG(dc, TGA_REG_SISR, 0x00010001);
    620 		TGAREGWB(dc, TGA_REG_SISR, 1);
    621 		while ((TGARREG(dc, TGA_REG_SISR) & 0x00000001) == 0)
    622 			;
    623 		f(dc->dc_ramdac_cookie);
    624 		TGAWREG(dc, TGA_REG_SISR, 0x00000001);
    625 		TGAREGWB(dc, TGA_REG_SISR, 1);
    626 	}
    627 
    628 	return 0;
    629 }
    630 
    631 static int
    632 tga_intr(v)
    633 	void *v;
    634 {
    635 	struct tga_devconfig *dc = v;
    636 	struct ramdac_cookie *dcrc= dc->dc_ramdac_cookie;
    637 
    638 	u_int32_t reg;
    639 
    640 	reg = TGARREG(dc, TGA_REG_SISR);
    641 	if (( reg & 0x00010001) != 0x00010001) {
    642 		/* Odd. We never set any of the other interrupt enables. */
    643 		if ((reg & 0x1f) != 0) {
    644 			/* Clear the mysterious pending interrupts. */
    645 			TGAWREG(dc, TGA_REG_SISR, (reg & 0x1f));
    646 			TGAREGWB(dc, TGA_REG_SISR, 1);
    647 			/* This was our interrupt, even if we're puzzled as to why
    648 			 * we got it.  Don't make the interrupt handler think it
    649 			 * was a stray.
    650 			 */
    651 			return -1;
    652 		} else {
    653 			return 0;
    654 		}
    655 	}
    656 	/* if we have something to do, do it */
    657 	if (dc->dc_ramdac_intr) {
    658 		dc->dc_ramdac_intr(dcrc);
    659 		dc->dc_ramdac_intr = NULL;
    660 	}
    661 	TGAWREG(dc, TGA_REG_SISR, 0x00000001);
    662 	TGAREGWB(dc, TGA_REG_SISR, 1);
    663 	return (1);
    664 }
    665 
    666 paddr_t
    667 tga_mmap(v, offset, prot)
    668 	void *v;
    669 	off_t offset;
    670 	int prot;
    671 {
    672 	struct tga_softc *sc = v;
    673 
    674 	if (offset >= sc->sc_dc->dc_tgaconf->tgac_cspace_size || offset < 0)
    675 		return -1;
    676 
    677 	return (bus_space_mmap(sc->sc_dc->dc_memt, sc->sc_dc->dc_pcipaddr,
    678 	    offset, prot, BUS_SPACE_MAP_LINEAR));
    679 }
    680 
    681 static int
    682 tga_alloc_screen(v, type, cookiep, curxp, curyp, attrp)
    683 	void *v;
    684 	const struct wsscreen_descr *type;
    685 	void **cookiep;
    686 	int *curxp, *curyp;
    687 	long *attrp;
    688 {
    689 	struct tga_softc *sc = v;
    690 	long defattr;
    691 
    692 	if (sc->nscreens > 0)
    693 		return (ENOMEM);
    694 
    695 	*cookiep = &sc->sc_dc->dc_rinfo; /* one and only for now */
    696 	*curxp = 0;
    697 	*curyp = 0;
    698 	sc->sc_dc->dc_rinfo.ri_ops.allocattr(&sc->sc_dc->dc_rinfo,
    699 		0, 0, 0, &defattr);
    700 	*attrp = defattr;
    701 	sc->nscreens++;
    702 	return (0);
    703 }
    704 
    705 static void
    706 tga_free_screen(v, cookie)
    707 	void *v;
    708 	void *cookie;
    709 {
    710 	struct tga_softc *sc = v;
    711 
    712 	if (sc->sc_dc == &tga_console_dc)
    713 		panic("tga_free_screen: console");
    714 
    715 	sc->nscreens--;
    716 }
    717 
    718 static int
    719 tga_show_screen(v, cookie, waitok, cb, cbarg)
    720 	void *v;
    721 	void *cookie;
    722 	int waitok;
    723 	void (*cb) __P((void *, int, int));
    724 	void *cbarg;
    725 {
    726 
    727 	return (0);
    728 }
    729 
    730 int
    731 tga_cnattach(iot, memt, pc, bus, device, function)
    732 	bus_space_tag_t iot, memt;
    733 	pci_chipset_tag_t pc;
    734 	int bus, device, function;
    735 {
    736 	struct tga_devconfig *dcp = &tga_console_dc;
    737 	long defattr;
    738 
    739 	tga_init(memt, pc, pci_make_tag(pc, bus, device, function), dcp);
    740 
    741 	/* sanity checks */
    742 	if (dcp->dc_vaddr == 0)
    743 		panic("tga_console(%d, %d): couldn't map memory space",
    744 		    device, function);
    745 	if (dcp->dc_tgaconf == NULL)
    746 		panic("tga_console(%d, %d): unknown board configuration",
    747 		    device, function);
    748 
    749 	/*
    750 	 * Initialize the RAMDAC but DO NOT allocate any private storage.
    751 	 * Initialization includes disabling cursor, setting a sane
    752 	 * colormap, etc.  It will be reinitialized in tgaattach().
    753 	 */
    754 	if (dcp->dc_tga2) {
    755 		if (dcp->dc_tgaconf->ramdac_funcs == bt485_funcs)
    756 			bt485_cninit(dcp, tga_sched_update, tga2_ramdac_wr,
    757 			    tga2_ramdac_rd);
    758 		else
    759 			ibm561_cninit(dcp, tga_sched_update, tga2_ramdac_wr,
    760 			    tga2_ramdac_rd, tga_getdotclock(dcp));
    761 	} else {
    762 		if (dcp->dc_tgaconf->ramdac_funcs == bt485_funcs)
    763 			bt485_cninit(dcp, tga_sched_update, tga_ramdac_wr,
    764 				tga_ramdac_rd);
    765 		else {
    766 			bt463_cninit(dcp, tga_sched_update, tga_bt463_wr,
    767 				tga_bt463_rd);
    768 		}
    769 	}
    770 	dcp->dc_rinfo.ri_ops.allocattr(&dcp->dc_rinfo, 0, 0, 0, &defattr);
    771 	wsdisplay_cnattach(&tga_stdscreen, &dcp->dc_rinfo, 0, 0, defattr);
    772 
    773 	return(0);
    774 }
    775 
    776 /*
    777  * Functions to blank and unblank the display.
    778  */
    779 static void
    780 tga_blank(dc)
    781 	struct tga_devconfig *dc;
    782 {
    783 
    784 	if (!dc->dc_blanked) {
    785 		dc->dc_blanked = 1;
    786 		/* XXX */
    787 		TGAWREG(dc, TGA_REG_VVVR, TGARREG(dc, TGA_REG_VVVR) | VVR_BLANK);
    788 	}
    789 }
    790 
    791 static void
    792 tga_unblank(dc)
    793 	struct tga_devconfig *dc;
    794 {
    795 
    796 	if (dc->dc_blanked) {
    797 		dc->dc_blanked = 0;
    798 		/* XXX */
    799 		TGAWREG(dc, TGA_REG_VVVR, TGARREG(dc, TGA_REG_VVVR) & ~VVR_BLANK);
    800 	}
    801 }
    802 
    803 /*
    804  * Functions to manipulate the built-in cursor handing hardware.
    805  */
    806 int
    807 tga_builtin_set_cursor(dc, cursorp)
    808 	struct tga_devconfig *dc;
    809 	struct wsdisplay_cursor *cursorp;
    810 {
    811 	struct ramdac_funcs *dcrf = dc->dc_ramdac_funcs;
    812 	struct ramdac_cookie *dcrc = dc->dc_ramdac_cookie;
    813 	u_int count, v;
    814 	int error;
    815 
    816 	v = cursorp->which;
    817 	if (v & WSDISPLAY_CURSOR_DOCMAP) {
    818 		error = dcrf->ramdac_check_curcmap(dcrc, cursorp);
    819 		if (error)
    820 			return (error);
    821 	}
    822 	if (v & WSDISPLAY_CURSOR_DOSHAPE) {
    823 		if ((u_int)cursorp->size.x != 64 ||
    824 		    (u_int)cursorp->size.y > 64)
    825 			return (EINVAL);
    826 		/* The cursor is 2 bits deep, and there is no mask */
    827 		count = (cursorp->size.y * 64 * 2) / NBBY;
    828 		if (!uvm_useracc(cursorp->image, count, B_READ))
    829 			return (EFAULT);
    830 	}
    831 	if (v & WSDISPLAY_CURSOR_DOHOT)		/* not supported */
    832 		return EINVAL;
    833 
    834 	/* parameters are OK; do it */
    835 	if (v & WSDISPLAY_CURSOR_DOCUR) {
    836 		if (cursorp->enable)
    837 			/* XXX */
    838 			TGAWREG(dc, TGA_REG_VVVR, TGARREG(dc, TGA_REG_VVVR) | 0x04);
    839 		else
    840 			/* XXX */
    841 			TGAWREG(dc, TGA_REG_VVVR, TGARREG(dc, TGA_REG_VVVR) & ~0x04);
    842 	}
    843 	if (v & WSDISPLAY_CURSOR_DOPOS) {
    844 		TGAWREG(dc, TGA_REG_CXYR,
    845 				((cursorp->pos.y & 0xfff) << 12) | (cursorp->pos.x & 0xfff));
    846 	}
    847 	if (v & WSDISPLAY_CURSOR_DOCMAP) {
    848 		/* can't fail. */
    849 		dcrf->ramdac_set_curcmap(dcrc, cursorp);
    850 	}
    851 	if (v & WSDISPLAY_CURSOR_DOSHAPE) {
    852 		count = ((64 * 2) / NBBY) * cursorp->size.y;
    853 		TGAWREG(dc, TGA_REG_CCBR,
    854 		    (TGARREG(dc, TGA_REG_CCBR) & ~0xfc00) | (cursorp->size.y << 10));
    855 		copyin(cursorp->image, (char *)(dc->dc_vaddr +
    856 		    (TGARREG(dc, TGA_REG_CCBR) & 0x3ff)),
    857 		    count);				/* can't fail. */
    858 	}
    859 	return (0);
    860 }
    861 
    862 int
    863 tga_builtin_get_cursor(dc, cursorp)
    864 	struct tga_devconfig *dc;
    865 	struct wsdisplay_cursor *cursorp;
    866 {
    867 	struct ramdac_funcs *dcrf = dc->dc_ramdac_funcs;
    868 	struct ramdac_cookie *dcrc = dc->dc_ramdac_cookie;
    869 	int count, error;
    870 
    871 	cursorp->which = WSDISPLAY_CURSOR_DOALL &
    872 	    ~(WSDISPLAY_CURSOR_DOHOT | WSDISPLAY_CURSOR_DOCMAP);
    873 	cursorp->enable = (TGARREG(dc, TGA_REG_VVVR) & 0x04) != 0;
    874 	cursorp->pos.x = TGARREG(dc, TGA_REG_CXYR) & 0xfff;
    875 	cursorp->pos.y = (TGARREG(dc, TGA_REG_CXYR) >> 12) & 0xfff;
    876 	cursorp->size.x = 64;
    877 	cursorp->size.y = (TGARREG(dc, TGA_REG_CCBR) >> 10) & 0x3f;
    878 
    879 	if (cursorp->image != NULL) {
    880 		count = (cursorp->size.y * 64 * 2) / NBBY;
    881 		error = copyout((char *)(dc->dc_vaddr +
    882 		      (TGARREG(dc, TGA_REG_CCBR) & 0x3ff)),
    883 		    cursorp->image, count);
    884 		if (error)
    885 			return (error);
    886 		/* No mask */
    887 	}
    888 	error = dcrf->ramdac_get_curcmap(dcrc, cursorp);
    889 	return (error);
    890 }
    891 
    892 int
    893 tga_builtin_set_curpos(dc, curposp)
    894 	struct tga_devconfig *dc;
    895 	struct wsdisplay_curpos *curposp;
    896 {
    897 
    898 	TGAWREG(dc, TGA_REG_CXYR,
    899 	    ((curposp->y & 0xfff) << 12) | (curposp->x & 0xfff));
    900 	return (0);
    901 }
    902 
    903 int
    904 tga_builtin_get_curpos(dc, curposp)
    905 	struct tga_devconfig *dc;
    906 	struct wsdisplay_curpos *curposp;
    907 {
    908 
    909 	curposp->x = TGARREG(dc, TGA_REG_CXYR) & 0xfff;
    910 	curposp->y = (TGARREG(dc, TGA_REG_CXYR) >> 12) & 0xfff;
    911 	return (0);
    912 }
    913 
    914 int
    915 tga_builtin_get_curmax(dc, curposp)
    916 	struct tga_devconfig *dc;
    917 	struct wsdisplay_curpos *curposp;
    918 {
    919 
    920 	curposp->x = curposp->y = 64;
    921 	return (0);
    922 }
    923 
    924 /*
    925  * Copy columns (characters) in a row (line).
    926  */
    927 static void
    928 tga_copycols(id, row, srccol, dstcol, ncols)
    929 	void *id;
    930 	int row, srccol, dstcol, ncols;
    931 {
    932 	struct rasops_info *ri = id;
    933 	int y, srcx, dstx, nx;
    934 
    935 	y = ri->ri_font->fontheight * row;
    936 	srcx = ri->ri_font->fontwidth * srccol;
    937 	dstx = ri->ri_font->fontwidth * dstcol;
    938 	nx = ri->ri_font->fontwidth * ncols;
    939 
    940 	tga_rop(ri, dstx, y,
    941 	    nx, ri->ri_font->fontheight, RAS_SRC,
    942 	    ri, srcx, y);
    943 }
    944 
    945 /*
    946  * Copy rows (lines).
    947  */
    948 static void
    949 tga_copyrows(id, srcrow, dstrow, nrows)
    950 	void *id;
    951 	int srcrow, dstrow, nrows;
    952 {
    953 	struct rasops_info *ri = id;
    954 	int srcy, dsty, ny;
    955 
    956 	srcy = ri->ri_font->fontheight * srcrow;
    957 	dsty = ri->ri_font->fontheight * dstrow;
    958 	ny = ri->ri_font->fontheight * nrows;
    959 
    960 	tga_rop(ri, 0, dsty,
    961 	    ri->ri_emuwidth, ny, RAS_SRC,
    962 	    ri, 0, srcy);
    963 }
    964 
    965 /* Do we need the src? */
    966 static int needsrc[16] = { 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0 };
    967 
    968 /* A mapping between our API and the TGA card */
    969 static int map_rop[16] = { 0x0, 0x8, 0x4, 0xc, 0x2, 0xa, 0x6,
    970 	0xe, 0x1, 0x9, 0x5, 0xd, 0x3, 0xb, 0x7, 0xf
    971 };
    972 
    973 /*
    974  *  Generic TGA raster op.
    975  *   This covers all possible raster ops, and
    976  *   clips the sizes and all of that.
    977  */
    978 static int
    979 tga_rop(dst, dx, dy, w, h, rop, src, sx, sy)
    980 	struct rasops_info *dst;
    981 	int dx, dy, w, h, rop;
    982 	struct rasops_info *src;
    983 	int sx, sy;
    984 {
    985 	if (!dst)
    986 		return -1;
    987 	if (needsrc[RAS_GETOP(rop)]) {
    988 		if (src == NULL)
    989 			return -1;	/* We want a src */
    990 		/* Clip against src */
    991 		if (sx < 0) {
    992 			w += sx;
    993 			sx = 0;
    994 		}
    995 		if (sy < 0) {
    996 			h += sy;
    997 			sy = 0;
    998 		}
    999 		if (sx + w > src->ri_emuwidth)
   1000 			w = src->ri_emuwidth - sx;
   1001 		if (sy + h > src->ri_emuheight)
   1002 			h = src->ri_emuheight - sy;
   1003 	} else {
   1004 		if (src != NULL)
   1005 			return -1;	/* We need no src */
   1006 	}
   1007 	/* Clip against dst.  We modify src regardless of using it,
   1008 	 * since it really doesn't matter.
   1009 	 */
   1010 	if (dx < 0) {
   1011 		w += dx;
   1012 		sx -= dx;
   1013 		dx = 0;
   1014 	}
   1015 	if (dy < 0) {
   1016 		h += dy;
   1017 		sy -= dy;
   1018 		dy = 0;
   1019 	}
   1020 	if (dx + w > dst->ri_emuwidth)
   1021 		w = dst->ri_emuwidth - dx;
   1022 	if (dy + h > dst->ri_emuheight)
   1023 		h = dst->ri_emuheight - dy;
   1024 	if (w <= 0 || h <= 0)
   1025 		return 0;	/* Vacuously true; */
   1026 	if (!src) {
   1027 		/* XXX Punt! */
   1028 		return -1;
   1029 	}
   1030 	return tga_rop_vtov(dst, dx, dy, w, h, rop, src, sx, sy);
   1031 }
   1032 
   1033 
   1034 
   1035 /*
   1036  * Video to Video raster ops.
   1037  * This function deals with all raster ops that have a src and dst
   1038  * that are on the card.
   1039  */
   1040 static int
   1041 tga_rop_vtov(dst, dx, dy, w, h, rop, src, sx, sy)
   1042 	struct rasops_info *dst;
   1043 	int dx, dy, w, h, rop;
   1044 	struct rasops_info *src;
   1045 	int sx, sy;
   1046 {
   1047 	struct tga_devconfig *dc = (struct tga_devconfig *)dst->ri_hw;
   1048 	int srcb, dstb, tga_srcb, tga_dstb;
   1049 	int x, y, wb;
   1050 	int xstart, xend, xdir;
   1051 	int ystart, yend, ydir, yinc;
   1052 	int xleft, lastx, lastleft;
   1053 	int offset = 1 * dc->dc_tgaconf->tgac_vvbr_units;
   1054 
   1055 	/*
   1056 	 * I don't yet want to deal with unaligned guys, really.  And we don't
   1057 	 * deal with copies from one card to another.
   1058 	 */
   1059 	if (dx % 8 != 0 || sx % 8 != 0 || src != dst) {
   1060 		/* XXX Punt! */
   1061 		/* XXX should never happen, since it's only being used to
   1062 		 * XXX copy 8-pixel-wide characters.
   1063 		 */
   1064 		return -1;
   1065 	}
   1066 
   1067 	srcb = sy * src->ri_stride + sx * (src->ri_depth/8);
   1068 	dstb = dy * dst->ri_stride + dx * (dst->ri_depth/8);
   1069 	tga_srcb = offset + (sy + src->ri_yorigin) * src->ri_stride +
   1070 		(sx + src->ri_xorigin) * (src->ri_depth/8);
   1071 	tga_dstb = offset + (dy + dst->ri_yorigin) * dst->ri_stride +
   1072 		(dx + dst->ri_xorigin) * (dst->ri_depth/8);
   1073 
   1074 	if (sy >= dy) {
   1075 		ystart = 0;
   1076 		yend = (h - 1) * dst->ri_stride;
   1077 		ydir = 1;
   1078 	} else {
   1079 		ystart = (h - 1) * dst->ri_stride;
   1080 		yend = 0;
   1081 		ydir = -1;
   1082 	}
   1083 	yinc = ydir * dst->ri_stride;
   1084 
   1085         wb = w * (dst->ri_depth / 8);
   1086 	if (sx >= dx || (sx + w) <= dx) {	/* copy forwards */
   1087 		xstart = 0;
   1088 		xend = wb;
   1089 		xdir = 1;
   1090 	} else {				/* copy backwards */
   1091 		xstart = wb;
   1092 		xend = 0;
   1093 		xdir = -1;
   1094 	}
   1095 
   1096 	TGAWALREG(dc, TGA_REG_GMOR, 3, 0x0007);		/* Copy mode */
   1097 	TGAWALREG(dc, TGA_REG_GOPR, 3, map_rop[rop]);   /* Set up the op */
   1098 	TGAWALREG(dc, TGA_REG_GPSR, 3, 0);		/* No shift */
   1099 
   1100 	/*
   1101 	 * we have 3 sizes of pixels to move in X direction:
   1102 	 * 4 * 64   (unrolled TGA ops)
   1103 	 *     64   (single TGA op)
   1104 	 *      4   (CPU, using long word)
   1105 	 */
   1106 
   1107 	if (xdir == 1) {   /* move to the left */
   1108 
   1109 		if (wb & ~63)
   1110 		for (y = ystart; (ydir * y) <= (ydir * yend); y += yinc) {
   1111 			/* 4*64 byte chunks */
   1112 			for (xleft = wb, x = xstart; xleft >= 4*64;
   1113 			     x += 4*64, xleft -= 4*64) {
   1114 
   1115 				/* XXX XXX Eight writes to different addresses should fill
   1116 				 * XXX XXX up the write buffers on 21064 and 21164 chips,
   1117 				 * XXX XXX but later CPUs might have larger write buffers which
   1118 				 * XXX XXX require further unrolling of this loop, or the
   1119 				 * XXX XXX insertion of memory barriers.
   1120 				 */
   1121 				TGAWALREG(dc, TGA_REG_GCSR, 0, tga_srcb + y + x + 0 * 64);
   1122 				TGAWALREG(dc, TGA_REG_GCDR, 0, tga_dstb + y + x + 0 * 64);
   1123 				TGAWALREG(dc, TGA_REG_GCSR, 1, tga_srcb + y + x + 1 * 64);
   1124 				TGAWALREG(dc, TGA_REG_GCDR, 1, tga_dstb + y + x + 1 * 64);
   1125 				TGAWALREG(dc, TGA_REG_GCSR, 2, tga_srcb + y + x + 2 * 64);
   1126 				TGAWALREG(dc, TGA_REG_GCDR, 2, tga_dstb + y + x + 2 * 64);
   1127 				TGAWALREG(dc, TGA_REG_GCSR, 3, tga_srcb + y + x + 3 * 64);
   1128 				TGAWALREG(dc, TGA_REG_GCDR, 3, tga_dstb + y + x + 3 * 64);
   1129 			}
   1130 
   1131 			/* 64 byte chunks */
   1132 			for (; xleft >= 64; x += 64, xleft -= 64) {
   1133 				TGAWALREG(dc, TGA_REG_GCSR, 0, tga_srcb + y + x + 0 * 64);
   1134 				TGAWALREG(dc, TGA_REG_GCDR, 0, tga_dstb + y + x + 0 * 64);
   1135 			}
   1136 		}
   1137 
   1138 		TGAWALREG(dc, TGA_REG_GOPR, 0, 0x0003); /* op -> dst = src */
   1139 		TGAWALREG(dc, TGA_REG_GMOR, 0, 0x0000); /* Simple mode */
   1140 
   1141 		lastleft = wb & 63;
   1142 		if (lastleft) {
   1143 			lastx = xstart + (wb & ~63);
   1144 			for (y = ystart; (ydir * y) <= (ydir * yend); y += yinc) {
   1145 				/* 4 byte granularity */
   1146 				for (x = lastx, xleft = lastleft; xleft >= 4;
   1147 				     x += 4, xleft -= 4) {
   1148 					*(uint32_t *)(dst->ri_bits + dstb + y + x + 0 * 4) =
   1149 						*(uint32_t *)(dst->ri_bits + srcb + y + x + 0 * 4);
   1150 				}
   1151 			}
   1152 		}
   1153 	}
   1154 	else {    /* above move to the left, below move to the right */
   1155 
   1156 		if (wb & ~63)
   1157 		for (y = ystart; (ydir * y) <= (ydir * yend); y += yinc) {
   1158 			/* 4*64 byte chunks */
   1159 			for (xleft = wb, x = xstart; xleft >= 4*64;
   1160 			     x -= 4*64, xleft -= 4*64) {
   1161 
   1162 				/* XXX XXX Eight writes to different addresses should fill
   1163 				 * XXX XXX up the write buffers on 21064 and 21164 chips,
   1164 				 * XXX XXX but later CPUs might have larger write buffers which
   1165 				 * XXX XXX require further unrolling of this loop, or the
   1166 				 * XXX XXX insertion of memory barriers.
   1167 				 */
   1168 				TGAWALREG(dc, TGA_REG_GCSR, 0, tga_srcb + y + x - 1 * 64);
   1169 				TGAWALREG(dc, TGA_REG_GCDR, 0, tga_dstb + y + x - 1 * 64);
   1170 				TGAWALREG(dc, TGA_REG_GCSR, 1, tga_srcb + y + x - 2 * 64);
   1171 				TGAWALREG(dc, TGA_REG_GCDR, 1, tga_dstb + y + x - 2 * 64);
   1172 				TGAWALREG(dc, TGA_REG_GCSR, 2, tga_srcb + y + x - 3 * 64);
   1173 				TGAWALREG(dc, TGA_REG_GCDR, 2, tga_dstb + y + x - 3 * 64);
   1174 				TGAWALREG(dc, TGA_REG_GCSR, 3, tga_srcb + y + x - 4 * 64);
   1175 				TGAWALREG(dc, TGA_REG_GCDR, 3, tga_dstb + y + x - 4 * 64);
   1176 			}
   1177 
   1178 			/* 64 byte chunks */
   1179 			for (; xleft >= 64; x -= 64, xleft -= 64) {
   1180 				TGAWALREG(dc, TGA_REG_GCSR, 0, tga_srcb + y + x - 1 * 64);
   1181 				TGAWALREG(dc, TGA_REG_GCDR, 0, tga_dstb + y + x - 1 * 64);
   1182 			}
   1183 		}
   1184 
   1185 		TGAWALREG(dc, TGA_REG_GOPR, 0, 0x0003); /* op -> dst = src */
   1186 		TGAWALREG(dc, TGA_REG_GMOR, 0, 0x0000); /* Simple mode */
   1187 
   1188 		lastleft = wb & 63;
   1189 		if (lastleft) {
   1190 			lastx = xstart - (wb & ~63);
   1191 			for (y = ystart; (ydir * y) <= (ydir * yend); y += yinc) {
   1192 				/* 4 byte granularity */
   1193 				for (x = lastx, xleft = lastleft; xleft >= 4;
   1194 				     x -= 4, xleft -= 4) {
   1195 					*(uint32_t *)(dst->ri_bits + dstb + y + x - 1 * 4) =
   1196 						*(uint32_t *)(dst->ri_bits + srcb + y + x - 1 * 4);
   1197 				}
   1198 			}
   1199 		}
   1200 	}
   1201 	return 0;
   1202 }
   1203 
   1204 
   1205 void tga_putchar (c, row, col, uc, attr)
   1206 	void *c;
   1207 	int row, col;
   1208 	u_int uc;
   1209 	long attr;
   1210 {
   1211 	struct rasops_info *ri = c;
   1212 	struct tga_devconfig *dc = ri->ri_hw;
   1213 	int fs, height, width;
   1214 	u_char *fr;
   1215 	int32_t *rp;
   1216 
   1217 	rp = (int32_t *)(ri->ri_bits + row*ri->ri_yscale + col*ri->ri_xscale);
   1218 
   1219 	height = ri->ri_font->fontheight;
   1220 	width = ri->ri_font->fontwidth;
   1221 
   1222 	uc -= ri->ri_font->firstchar;
   1223 	fr = (u_char *)ri->ri_font->data + uc * ri->ri_fontscale;
   1224 	fs = ri->ri_font->stride;
   1225 
   1226 	/* Set foreground and background color. XXX memoize this somehow?
   1227 	 * The rasops code has already expanded the color entry to 32 bits
   1228 	 * for us, even for 8-bit displays, so we don't have to do anything.
   1229 	 */
   1230 	TGAWREG(dc, TGA_REG_GFGR, ri->ri_devcmap[(attr >> 24) & 15]);
   1231 	TGAWREG(dc, TGA_REG_GBGR, ri->ri_devcmap[(attr >> 16) & 15]);
   1232 
   1233 	/* Set raster operation to "copy"... */
   1234 	if (ri->ri_depth == 8)
   1235 		TGAWREG(dc, TGA_REG_GOPR, 0x3);
   1236 	else /* ... and in 24-bit mode, set the destination bitmap to 24-bit. */
   1237 		TGAWREG(dc, TGA_REG_GOPR, 0x3 | (0x3 << 8));
   1238 
   1239 	/* Set which pixels we're drawing (of a possible 32). */
   1240 	TGAWREG(dc, TGA_REG_GPXR_P, (1 << width) - 1);
   1241 
   1242 	/* Set drawing mode to opaque stipple. */
   1243 	TGAWREG(dc, TGA_REG_GMOR, 0x1);
   1244 
   1245 	/* Insert write barrier before actually sending data */
   1246 	/* XXX Abuses the fact that there is only one write barrier on Alphas */
   1247 	TGAREGWB(dc, TGA_REG_GMOR, 1);
   1248 
   1249 	while(height--) {
   1250 		/* The actual stipple write */
   1251 		*rp = fr[0] | (fr[1] << 8) | (fr[2] << 16) | (fr[3] << 24);
   1252 
   1253 		fr += fs;
   1254 		rp = (int32_t *)((caddr_t)rp + ri->ri_stride);
   1255 	}
   1256 
   1257 	/* Do underline */
   1258 	if ((attr & 1) != 0) {
   1259 		rp = (int32_t *)((caddr_t)rp - (ri->ri_stride << 1));
   1260 		*rp = 0xffffffff;
   1261 	}
   1262 
   1263 	/* Set grapics mode back to normal. */
   1264 	TGAWREG(dc, TGA_REG_GMOR, 0);
   1265 	TGAWREG(dc, TGA_REG_GPXR_P, 0xffffffff);
   1266 
   1267 }
   1268 
   1269 static void
   1270 tga_eraserows(c, row, num, attr)
   1271 	void *c;
   1272 	int row, num;
   1273 	long attr;
   1274 {
   1275 	struct rasops_info *ri = c;
   1276 	struct tga_devconfig *dc = ri->ri_hw;
   1277 	int32_t color, lines, pixels;
   1278 	int32_t *rp;
   1279 
   1280 	color = ri->ri_devcmap[(attr >> 16) & 15];
   1281 	rp = (int32_t *)(ri->ri_bits + row*ri->ri_yscale);
   1282 	lines = num * ri->ri_font->fontheight;
   1283 	pixels = ri->ri_emuwidth - 1;
   1284 
   1285 	/* Set fill color in block-color registers */
   1286 	TGAWREG(dc, TGA_REG_GBCR0, color);
   1287 	TGAWREG(dc, TGA_REG_GBCR1, color);
   1288 	if (ri->ri_depth != 8) {
   1289 		TGAWREG(dc, TGA_REG_GBCR2, color);
   1290 		TGAWREG(dc, TGA_REG_GBCR3, color);
   1291 		TGAWREG(dc, TGA_REG_GBCR4, color);
   1292 		TGAWREG(dc, TGA_REG_GBCR5, color);
   1293 		TGAWREG(dc, TGA_REG_GBCR6, color);
   1294 		TGAWREG(dc, TGA_REG_GBCR7, color);
   1295 	}
   1296 
   1297 	/* Set raster operation to "copy"... */
   1298 	if (ri->ri_depth == 8)
   1299 		TGAWREG(dc, TGA_REG_GOPR, 0x3);
   1300 	else /* ... and in 24-bit mode, set the destination bitmap to 24-bit. */
   1301 		TGAWREG(dc, TGA_REG_GOPR, 0x3 | (0x3 << 8));
   1302 
   1303 	/* Set which pixels we're drawing (of a possible 32). */
   1304 	TGAWREG(dc, TGA_REG_GDAR, 0xffffffff);
   1305 
   1306 	/* Set drawing mode to block fill. */
   1307 	TGAWREG(dc, TGA_REG_GMOR, 0x2d);
   1308 
   1309 	/* Insert write barrier before actually sending data */
   1310 	/* XXX Abuses the fact that there is only one write barrier on Alphas */
   1311 	TGAREGWB(dc, TGA_REG_GMOR, 1);
   1312 
   1313 	while (lines--) {
   1314 		*rp = pixels;
   1315 		rp = (int32_t *)((caddr_t)rp + ri->ri_stride);
   1316 	}
   1317 
   1318 	/* Set grapics mode back to normal. */
   1319 	TGAWREG(dc, TGA_REG_GMOR, 0);
   1320 
   1321 }
   1322 
   1323 static void
   1324 tga_erasecols (c, row, col, num, attr)
   1325 void *c;
   1326 int row, col, num;
   1327 long attr;
   1328 {
   1329 	struct rasops_info *ri = c;
   1330 	struct tga_devconfig *dc = ri->ri_hw;
   1331 	int32_t color, lines, pixels;
   1332 	int32_t *rp;
   1333 
   1334 	color = ri->ri_devcmap[(attr >> 16) & 15];
   1335 	rp = (int32_t *)(ri->ri_bits + row*ri->ri_yscale + col*ri->ri_xscale);
   1336 	lines = ri->ri_font->fontheight;
   1337 	pixels = (num * ri->ri_font->fontwidth) - 1;
   1338 
   1339 	/* Set fill color in block-color registers */
   1340 	TGAWREG(dc, TGA_REG_GBCR0, color);
   1341 	TGAWREG(dc, TGA_REG_GBCR1, color);
   1342 	if (ri->ri_depth != 8) {
   1343 		TGAWREG(dc, TGA_REG_GBCR2, color);
   1344 		TGAWREG(dc, TGA_REG_GBCR3, color);
   1345 		TGAWREG(dc, TGA_REG_GBCR4, color);
   1346 		TGAWREG(dc, TGA_REG_GBCR5, color);
   1347 		TGAWREG(dc, TGA_REG_GBCR6, color);
   1348 		TGAWREG(dc, TGA_REG_GBCR7, color);
   1349 	}
   1350 
   1351 	/* Set raster operation to "copy"... */
   1352 	if (ri->ri_depth == 8)
   1353 		TGAWREG(dc, TGA_REG_GOPR, 0x3);
   1354 	else /* ... and in 24-bit mode, set the destination bitmap to 24-bit. */
   1355 		TGAWREG(dc, TGA_REG_GOPR, 0x3 | (0x3 << 8));
   1356 
   1357 	/* Set which pixels we're drawing (of a possible 32). */
   1358 	TGAWREG(dc, TGA_REG_GDAR, 0xffffffff);
   1359 
   1360 	/* Set drawing mode to block fill. */
   1361 	TGAWREG(dc, TGA_REG_GMOR, 0x2d);
   1362 
   1363 	/* Insert write barrier before actually sending data */
   1364 	/* XXX Abuses the fact that there is only one write barrier on Alphas */
   1365 	TGAREGWB(dc, TGA_REG_GMOR, 1);
   1366 
   1367 	while (lines--) {
   1368 		*rp = pixels;
   1369 		rp = (int32_t *)((caddr_t)rp + ri->ri_stride);
   1370 	}
   1371 
   1372 	/* Set grapics mode back to normal. */
   1373 	TGAWREG(dc, TGA_REG_GMOR, 0);
   1374 }
   1375 
   1376 
   1377 static void
   1378 tga_ramdac_wr(v, btreg, val)
   1379 	void *v;
   1380 	u_int btreg;
   1381 	u_int8_t val;
   1382 {
   1383 	struct tga_devconfig *dc = v;
   1384 
   1385 	if (btreg > BT485_REG_MAX)
   1386 		panic("tga_ramdac_wr: reg %d out of range", btreg);
   1387 
   1388 	TGAWREG(dc, TGA_REG_EPDR, (btreg << 9) | (0 << 8 ) | val); /* XXX */
   1389 	TGAREGWB(dc, TGA_REG_EPDR, 1);
   1390 }
   1391 
   1392 static void
   1393 tga2_ramdac_wr(v, btreg, val)
   1394 	void *v;
   1395 	u_int btreg;
   1396 	u_int8_t val;
   1397 {
   1398 	struct tga_devconfig *dc = v;
   1399 	bus_space_handle_t ramdac;
   1400 
   1401 	if (btreg > BT485_REG_MAX)
   1402 		panic("tga_ramdac_wr: reg %d out of range", btreg);
   1403 
   1404 	bus_space_subregion(dc->dc_memt, dc->dc_memh, TGA2_MEM_RAMDAC +
   1405 		(0xe << 12) + (btreg << 8), 4, &ramdac);
   1406 	bus_space_write_4(dc->dc_memt, ramdac, 0, val & 0xff);
   1407 	bus_space_barrier(dc->dc_memt, ramdac, 0, 4, BUS_SPACE_BARRIER_WRITE);
   1408 }
   1409 
   1410 static u_int8_t
   1411 tga_bt463_rd(v, btreg)
   1412 	void *v;
   1413 	u_int btreg;
   1414 {
   1415 	struct tga_devconfig *dc = v;
   1416 	tga_reg_t rdval;
   1417 
   1418 	/*
   1419 	 * Strobe CE# (high->low->high) since status and data are latched on
   1420 	 * the falling and rising edges (repsectively) of this active-low signal.
   1421 	 */
   1422 
   1423 	TGAREGWB(dc, TGA_REG_EPSR, 1);
   1424 	TGAWREG(dc, TGA_REG_EPSR, (btreg << 2) | 2 | 1);
   1425 	TGAREGWB(dc, TGA_REG_EPSR, 1);
   1426 	TGAWREG(dc, TGA_REG_EPSR, (btreg << 2) | 2 | 0);
   1427 
   1428 	TGAREGRB(dc, TGA_REG_EPSR, 1);
   1429 
   1430 	rdval = TGARREG(dc, TGA_REG_EPDR);
   1431 	TGAREGWB(dc, TGA_REG_EPSR, 1);
   1432 	TGAWREG(dc, TGA_REG_EPSR, (btreg << 2) | 2 | 1);
   1433 
   1434 	return (rdval >> 16) & 0xff;
   1435 }
   1436 
   1437 static void
   1438 tga_bt463_wr(v, btreg, val)
   1439 	void *v;
   1440 	u_int btreg;
   1441 	u_int8_t val;
   1442 {
   1443 	struct tga_devconfig *dc = v;
   1444 
   1445 	/*
   1446 	 * In spite of the 21030 documentation, to set the MPU bus bits for
   1447 	 * a write, you set them in the upper bits of EPDR, not EPSR.
   1448 	 */
   1449 
   1450 	/*
   1451 	 * Strobe CE# (high->low->high) since status and data are latched on
   1452 	 * the falling and rising edges of this active-low signal.
   1453 	 */
   1454 
   1455 	TGAREGWB(dc, TGA_REG_EPDR, 1);
   1456 	TGAWREG(dc, TGA_REG_EPDR, (btreg << 10) | 0x100 | val);
   1457 	TGAREGWB(dc, TGA_REG_EPDR, 1);
   1458 	TGAWREG(dc, TGA_REG_EPDR, (btreg << 10) | 0x000 | val);
   1459 	TGAREGWB(dc, TGA_REG_EPDR, 1);
   1460 	TGAWREG(dc, TGA_REG_EPDR, (btreg << 10) | 0x100 | val);
   1461 
   1462 }
   1463 
   1464 static u_int8_t
   1465 tga_ramdac_rd(v, btreg)
   1466 	void *v;
   1467 	u_int btreg;
   1468 {
   1469 	struct tga_devconfig *dc = v;
   1470 	tga_reg_t rdval;
   1471 
   1472 	if (btreg > BT485_REG_MAX)
   1473 		panic("tga_ramdac_rd: reg %d out of range", btreg);
   1474 
   1475 	TGAWREG(dc, TGA_REG_EPSR, (btreg << 1) | 0x1); /* XXX */
   1476 	TGAREGWB(dc, TGA_REG_EPSR, 1);
   1477 
   1478 	rdval = TGARREG(dc, TGA_REG_EPDR);
   1479 	return (rdval >> 16) & 0xff;				/* XXX */
   1480 }
   1481 
   1482 static u_int8_t
   1483 tga2_ramdac_rd(v, btreg)
   1484 	void *v;
   1485 	u_int btreg;
   1486 {
   1487 	struct tga_devconfig *dc = v;
   1488 	bus_space_handle_t ramdac;
   1489 	u_int8_t retval;
   1490 
   1491 	if (btreg > BT485_REG_MAX)
   1492 		panic("tga_ramdac_rd: reg %d out of range", btreg);
   1493 
   1494 	bus_space_subregion(dc->dc_memt, dc->dc_memh, TGA2_MEM_RAMDAC +
   1495 		(0xe << 12) + (btreg << 8), 4, &ramdac);
   1496 	retval = bus_space_read_4(dc->dc_memt, ramdac, 0) & 0xff;
   1497 	bus_space_barrier(dc->dc_memt, ramdac, 0, 4, BUS_SPACE_BARRIER_READ);
   1498 	return retval;
   1499 }
   1500 
   1501 #include <dev/ic/decmonitors.c>
   1502 void tga2_ics9110_wr __P((
   1503 	struct tga_devconfig *dc,
   1504 	int dotclock
   1505 ));
   1506 
   1507 struct monitor *tga_getmonitor __P((struct tga_devconfig *dc));
   1508 
   1509 void
   1510 tga2_init(dc)
   1511 	struct tga_devconfig *dc;
   1512 {
   1513 	struct	monitor *m = tga_getmonitor(dc);
   1514 
   1515 	/* Deal with the dot clocks.
   1516 	 */
   1517 	if (dc->dc_tga_type == TGA_TYPE_POWERSTORM_4D20) {
   1518 		/* Set this up as a reference clock for the
   1519 		 * ibm561's PLL.
   1520 		 */
   1521 		tga2_ics9110_wr(dc, 14300000);
   1522 		/* XXX Can't set up the dotclock properly, until such time
   1523 		 * as the RAMDAC is configured.
   1524 		 */
   1525 	} else {
   1526 		/* otherwise the ics9110 is our clock. */
   1527 		tga2_ics9110_wr(dc, m->dotclock);
   1528 	}
   1529 #if 0
   1530 	TGAWREG(dc, TGA_REG_VHCR,
   1531 	     ((m->hbp / 4) << 21) |
   1532 	     ((m->hsync / 4) << 14) |
   1533 	    (((m->hfp - 4) / 4) << 9) |
   1534 	     ((m->cols + 4) / 4));
   1535 #else
   1536 	TGAWREG(dc, TGA_REG_VHCR,
   1537 	     ((m->hbp / 4) << 21) |
   1538 	     ((m->hsync / 4) << 14) |
   1539 	    (((m->hfp) / 4) << 9) |
   1540 	     ((m->cols) / 4));
   1541 #endif
   1542 	TGAWREG(dc, TGA_REG_VVCR,
   1543 	    (m->vbp << 22) |
   1544 	    (m->vsync << 16) |
   1545 	    (m->vfp << 11) |
   1546 	    (m->rows));
   1547 	TGAWREG(dc, TGA_REG_VVBR, 1);
   1548 	TGAREGRWB(dc, TGA_REG_VHCR, 3);
   1549 	TGAWREG(dc, TGA_REG_VVVR, TGARREG(dc, TGA_REG_VVVR) | 1);
   1550 	TGAREGRWB(dc, TGA_REG_VVVR, 1);
   1551 	TGAWREG(dc, TGA_REG_GPMR, 0xffffffff);
   1552 	TGAREGRWB(dc, TGA_REG_GPMR, 1);
   1553 }
   1554 
   1555 void
   1556 tga2_ics9110_wr(dc, dotclock)
   1557 	struct tga_devconfig *dc;
   1558 	int dotclock;
   1559 {
   1560 	bus_space_handle_t clock;
   1561 	u_int32_t valU;
   1562 	int N, M, R, V, X;
   1563 	int i;
   1564 
   1565 	switch (dotclock) {
   1566 	case 130808000:
   1567 		N = 0x40; M = 0x7; V = 0x0; X = 0x1; R = 0x1; break;
   1568 	case 119840000:
   1569 		N = 0x2d; M = 0x2b; V = 0x1; X = 0x1; R = 0x1; break;
   1570 	case 108180000:
   1571 		N = 0x11; M = 0x9; V = 0x1; X = 0x1; R = 0x2; break;
   1572 	case 103994000:
   1573 		N = 0x6d; M = 0xf; V = 0x0; X = 0x1; R = 0x1; break;
   1574 	case 175000000:
   1575 		N = 0x5F; M = 0x3E; V = 0x1; X = 0x1; R = 0x1; break;
   1576 	case  75000000:
   1577 		N = 0x6e; M = 0x15; V = 0x0; X = 0x1; R = 0x1; break;
   1578 	case  74000000:
   1579 		N = 0x2a; M = 0x41; V = 0x1; X = 0x1; R = 0x1; break;
   1580 	case  69000000:
   1581 		N = 0x35; M = 0xb; V = 0x0; X = 0x1; R = 0x1; break;
   1582 	case  65000000:
   1583 		N = 0x6d; M = 0x0c; V = 0x0; X = 0x1; R = 0x2; break;
   1584 	case  50000000:
   1585 		N = 0x37; M = 0x3f; V = 0x1; X = 0x1; R = 0x2; break;
   1586 	case  40000000:
   1587 		N = 0x5f; M = 0x11; V = 0x0; X = 0x1; R = 0x2; break;
   1588 	case  31500000:
   1589 		N = 0x16; M = 0x05; V = 0x0; X = 0x1; R = 0x2; break;
   1590 	case  25175000:
   1591 		N = 0x66; M = 0x1d; V = 0x0; X = 0x1; R = 0x2; break;
   1592 	case 135000000:
   1593 		N = 0x42; M = 0x07; V = 0x0; X = 0x1; R = 0x1; break;
   1594 	case 110000000:
   1595 		N = 0x60; M = 0x32; V = 0x1; X = 0x1; R = 0x2; break;
   1596 	case 202500000:
   1597 		N = 0x60; M = 0x32; V = 0x1; X = 0x1; R = 0x2; break;
   1598 	case  14300000:		/* this one is just a ref clock */
   1599 		N = 0x03; M = 0x03; V = 0x1; X = 0x1; R = 0x3; break;
   1600 	default:
   1601 		panic("unrecognized clock rate %d", dotclock);
   1602 	}
   1603 
   1604 	/* XXX -- hard coded, bad */
   1605 	valU  = N | ( M << 7 ) | (V << 14);
   1606 	valU |= (X << 15) | (R << 17);
   1607 	valU |= 0x17 << 19;
   1608 
   1609 	bus_space_subregion(dc->dc_memt, dc->dc_memh, TGA2_MEM_EXTDEV +
   1610 	    TGA2_MEM_CLOCK + (0xe << 12), 4, &clock); /* XXX */
   1611 
   1612 	for (i=24; i>0; i--) {
   1613 		u_int32_t       writeval;
   1614 
   1615 		writeval = valU & 0x1;
   1616 		if (i == 1)
   1617 			writeval |= 0x2;
   1618 		valU >>= 1;
   1619 		bus_space_write_4(dc->dc_memt, clock, 0, writeval);
   1620 		bus_space_barrier(dc->dc_memt, clock, 0, 4, BUS_SPACE_BARRIER_WRITE);
   1621         }
   1622 	bus_space_subregion(dc->dc_memt, dc->dc_memh, TGA2_MEM_EXTDEV +
   1623 	    TGA2_MEM_CLOCK + (0xe << 12) + (0x1 << 11) + (0x1 << 11), 4,
   1624 		&clock); /* XXX */
   1625 	bus_space_write_4(dc->dc_memt, clock, 0, 0x0);
   1626 	bus_space_barrier(dc->dc_memt, clock, 0, 0, BUS_SPACE_BARRIER_WRITE);
   1627 }
   1628 
   1629 struct monitor *
   1630 tga_getmonitor(dc)
   1631 	struct tga_devconfig *dc;
   1632 {
   1633 	return &decmonitors[(~TGARREG(dc, TGA_REG_GREV) >> 16) & 0x0f];
   1634 }
   1635 
   1636 unsigned
   1637 tga_getdotclock(dc)
   1638 	struct tga_devconfig *dc;
   1639 {
   1640 	return tga_getmonitor(dc)->dotclock;
   1641 }
   1642