Home | History | Annotate | Line # | Download | only in ic
bt463.c revision 1.3.4.5
      1 /* $NetBSD: bt463.c,v 1.3.4.5 2002/08/13 02:19:23 nathanw Exp $ */
      2 
      3 /*-
      4  * Copyright (c) 1998 The NetBSD Foundation, Inc.
      5  * All rights reserved.
      6  *
      7  * This code is derived from software contributed to The NetBSD Foundation
      8  * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
      9  * NASA Ames Research Center.
     10  *
     11  * Redistribution and use in source and binary forms, with or without
     12  * modification, are permitted provided that the following conditions
     13  * are met:
     14  * 1. Redistributions of source code must retain the above copyright
     15  *    notice, this list of conditions and the following disclaimer.
     16  * 2. Redistributions in binary form must reproduce the above copyright
     17  *    notice, this list of conditions and the following disclaimer in the
     18  *    documentation and/or other materials provided with the distribution.
     19  * 3. All advertising materials mentioning features or use of this software
     20  *    must display the following acknowledgement:
     21  *	This product includes software developed by the NetBSD
     22  *	Foundation, Inc. and its contributors.
     23  * 4. Neither the name of The NetBSD Foundation nor the names of its
     24  *    contributors may be used to endorse or promote products derived
     25  *    from this software without specific prior written permission.
     26  *
     27  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     28  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     29  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     30  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     31  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     32  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     33  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     34  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     35  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     36  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     37  * POSSIBILITY OF SUCH DAMAGE.
     38  */
     39 
     40 /*
     41  * Copyright (c) 1995, 1996 Carnegie-Mellon University.
     42  * All rights reserved.
     43  *
     44  * Author: Chris G. Demetriou
     45  *
     46  * Permission to use, copy, modify and distribute this software and
     47  * its documentation is hereby granted, provided that both the copyright
     48  * notice and this permission notice appear in all copies of the
     49  * software, derivative works or modified versions, and any portions
     50  * thereof, and that both notices appear in supporting documentation.
     51  *
     52  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
     53  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
     54  * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
     55  *
     56  * Carnegie Mellon requests users of this software to return to
     57  *
     58  *  Software Distribution Coordinator  or  Software.Distribution (at) CS.CMU.EDU
     59  *  School of Computer Science
     60  *  Carnegie Mellon University
     61  *  Pittsburgh PA 15213-3890
     62  *
     63  * any improvements or extensions that they make and grant Carnegie the
     64  * rights to redistribute these changes.
     65  */
     66 
     67  /* This code was derived from and originally located in sys/dev/pci/
     68   *	 NetBSD: tga_bt463.c,v 1.5 2000/03/04 10:27:59 elric Exp
     69   */
     70 
     71 #include <sys/cdefs.h>
     72 __KERNEL_RCSID(0, "$NetBSD: bt463.c,v 1.3.4.5 2002/08/13 02:19:23 nathanw Exp $");
     73 
     74 #include <sys/param.h>
     75 #include <sys/systm.h>
     76 #include <sys/device.h>
     77 #include <sys/buf.h>
     78 #include <sys/kernel.h>
     79 #include <sys/malloc.h>
     80 
     81 #include <uvm/uvm_extern.h>
     82 
     83 #include <dev/pci/pcivar.h>
     84 #include <dev/pci/tgareg.h>
     85 #include <dev/pci/tgavar.h>
     86 #include <dev/ic/bt463reg.h>
     87 #include <dev/ic/bt463var.h>
     88 
     89 #include <dev/wscons/wsconsio.h>
     90 
     91 /*
     92  * Functions exported via the RAMDAC configuration table.
     93  */
     94 void	bt463_init __P((struct ramdac_cookie *));
     95 int	bt463_set_cmap __P((struct ramdac_cookie *,
     96 	    struct wsdisplay_cmap *));
     97 int	bt463_get_cmap __P((struct ramdac_cookie *,
     98 	    struct wsdisplay_cmap *));
     99 int	bt463_set_cursor __P((struct ramdac_cookie *,
    100 	    struct wsdisplay_cursor *));
    101 int	bt463_get_cursor __P((struct ramdac_cookie *,
    102 	    struct wsdisplay_cursor *));
    103 int	bt463_set_curpos __P((struct ramdac_cookie *,
    104 	    struct wsdisplay_curpos *));
    105 int	bt463_get_curpos __P((struct ramdac_cookie *,
    106 	    struct wsdisplay_curpos *));
    107 int	bt463_get_curmax __P((struct ramdac_cookie *,
    108 	    struct wsdisplay_curpos *));
    109 int	bt463_check_curcmap __P((struct ramdac_cookie *,
    110 	    struct wsdisplay_cursor *cursorp));
    111 void	bt463_set_curcmap __P((struct ramdac_cookie *,
    112 	    struct wsdisplay_cursor *cursorp));
    113 int	bt463_get_curcmap __P((struct ramdac_cookie *,
    114 	    struct wsdisplay_cursor *cursorp));
    115 
    116 #ifdef BT463_DEBUG
    117 int bt463_store __P((void *));
    118 int bt463_debug __P((void *));
    119 int bt463_readback __P((void *));
    120 void	bt463_copyback __P((void *));
    121 #endif
    122 
    123 struct ramdac_funcs bt463_funcsstruct = {
    124 	"Bt463",
    125 	bt463_register,
    126 	bt463_init,
    127 	bt463_set_cmap,
    128 	bt463_get_cmap,
    129 	bt463_set_cursor,
    130 	bt463_get_cursor,
    131 	bt463_set_curpos,
    132 	bt463_get_curpos,
    133 	bt463_get_curmax,
    134 	bt463_check_curcmap,
    135 	bt463_set_curcmap,
    136 	bt463_get_curcmap,
    137 	NULL,
    138 };
    139 
    140 /*
    141  * Private data.
    142  */
    143 struct bt463data {
    144 	void            *cookie;        /* This is what is passed
    145 					 * around, and is probably
    146 					 * struct tga_devconfig *
    147 					 */
    148 
    149 	int             (*ramdac_sched_update) __P((void *, void (*)(void *)));
    150 	void            (*ramdac_wr) __P((void *, u_int, u_int8_t));
    151 	u_int8_t        (*ramdac_rd) __P((void *, u_int));
    152 
    153 	int	changed;			/* what changed; see below */
    154 	char curcmap_r[2];			/* cursor colormap */
    155 	char curcmap_g[2];
    156 	char curcmap_b[2];
    157 	char cmap_r[BT463_NCMAP_ENTRIES];	/* colormap */
    158 	char cmap_g[BT463_NCMAP_ENTRIES];
    159 	char cmap_b[BT463_NCMAP_ENTRIES];
    160 	int window_type[16]; /* 16 24-bit window type table entries */
    161 };
    162 
    163 /* When we're doing console initialization, there's no
    164  * way to get our cookie back to the video card's softc
    165  * before we call sched_update. So we stash it here,
    166  * and bt463_update will look for it here first.
    167  */
    168 static struct bt463data *console_data;
    169 
    170 
    171 #define BTWREG(data, addr, val) do { bt463_wraddr((data), (addr)); \
    172 	(data)->ramdac_wr((data)->cookie, BT463_REG_IREG_DATA, (val)); } while (0)
    173 #define BTWNREG(data, val) (data)->ramdac_wr((data)->cookie, \
    174 	BT463_REG_IREG_DATA, (val))
    175 #define BTRREG(data, addr) (bt463_wraddr((data), (addr)), \
    176 	(data)->ramdac_rd((data)->cookie, BT463_REG_IREG_DATA))
    177 #define BTRNREG(data) ((data)->ramdac_rd((data)->cookie, BT463_REG_IREG_DATA))
    178 
    179 #define	DATA_CURCMAP_CHANGED	0x01	/* cursor colormap changed */
    180 #define	DATA_CMAP_CHANGED	0x02	/* colormap changed */
    181 #define	DATA_WTYPE_CHANGED	0x04	/* window type table changed */
    182 #define	DATA_ALL_CHANGED	0x07
    183 
    184 /*
    185  * Internal functions.
    186  */
    187 inline void bt463_wraddr __P((struct bt463data *, u_int16_t));
    188 
    189 void	bt463_update __P((void *));
    190 
    191 
    192 /*****************************************************************************/
    193 
    194 /*
    195  * Functions exported via the RAMDAC configuration table.
    196  */
    197 
    198 struct ramdac_funcs *
    199 bt463_funcs(void)
    200 {
    201 	return &bt463_funcsstruct;
    202 }
    203 
    204 struct ramdac_cookie *
    205 bt463_register(v, sched_update, wr, rd)
    206 	void *v;
    207 	int (*sched_update)(void *, void (*)(void *));
    208 	void (*wr)(void *, u_int, u_int8_t);
    209 	u_int8_t (*rd)(void *, u_int);
    210 {
    211 	struct bt463data *data;
    212 	/*
    213 	 * XXX -- comment out of date.  rcd.
    214 	 * If we should allocate a new private info struct, do so.
    215 	 * Otherwise, use the one we have (if it's there), or
    216 	 * use the temporary one on the stack.
    217 	 */
    218 	data = malloc(sizeof *data, M_DEVBUF, M_WAITOK);
    219 	/* XXX -- if !data */
    220 	data->cookie = v;
    221 	data->ramdac_sched_update = sched_update;
    222 	data->ramdac_wr = wr;
    223 	data->ramdac_rd = rd;
    224 	return (struct ramdac_cookie *)data;
    225 }
    226 
    227 /*
    228  * This function exists solely to provide a means to init
    229  * the RAMDAC without first registering.  It is useful for
    230  * initializing the console early on.
    231  */
    232 void
    233 bt463_cninit(v, sched_update, wr, rd)
    234 	void *v;
    235 	int (*sched_update)(void *, void (*)(void *));
    236 	void (*wr)(void *, u_int, u_int8_t);
    237 	u_int8_t (*rd)(void *, u_int);
    238 {
    239 	struct bt463data tmp, *data = &tmp;
    240 	data->cookie = v;
    241 	data->ramdac_sched_update = sched_update;
    242 	data->ramdac_wr = wr;
    243 	data->ramdac_rd = rd;
    244 	/* Set up console_data so that when bt463_update is called back,
    245 	 * it can use the right information.
    246 	 */
    247 	console_data = data;
    248 	bt463_init((struct ramdac_cookie *)data);
    249 	console_data = NULL;
    250 }
    251 
    252 void
    253 bt463_init(rc)
    254 	struct ramdac_cookie *rc;
    255 {
    256 	struct bt463data *data = (struct bt463data *)rc;
    257 
    258 	int i;
    259 
    260 	/*
    261 	 * Init the BT463 for normal operation.
    262 	 */
    263 
    264 
    265 	/*
    266 	 * Setup:
    267 	 * reg 0: 4:1 multiplexing, 25/75 blink.
    268 	 * reg 1: Overlay mapping: mapped to common palette,
    269 	 *        14 window type entries, 24-plane configuration mode,
    270 	 *        4 overlay planes, underlays disabled, no cursor.
    271 	 * reg 2: sync-on-green enabled, pedestal enabled.
    272 	 */
    273 
    274 	BTWREG(data, BT463_IREG_COMMAND_0, 0x40);
    275 	BTWREG(data, BT463_IREG_COMMAND_1, 0x48);
    276 	BTWREG(data, BT463_IREG_COMMAND_2, 0x40);
    277 
    278 	/*
    279 	 * Initialize the read mask.
    280 	 */
    281 	bt463_wraddr(data, BT463_IREG_READ_MASK_P0_P7);
    282 	for (i = 0; i < 4; i++)
    283 		BTWNREG(data, 0xff);
    284 
    285 	/*
    286 	 * Initialize the blink mask.
    287 	 */
    288 	bt463_wraddr(data, BT463_IREG_BLINK_MASK_P0_P7);
    289 	for (i = 0; i < 4; i++)
    290 		BTWNREG(data, 0);
    291 
    292 
    293 	/*
    294 	 * Clear test register
    295 	 */
    296 	BTWREG(data, BT463_IREG_TEST, 0);
    297 
    298 	/*
    299 	 * Initialize the RAMDAC info struct to hold all of our
    300 	 * data, and fill it in.
    301 	 */
    302 	data->changed = DATA_ALL_CHANGED;
    303 
    304 	/* initial cursor colormap: 0 is black, 1 is white */
    305 	data->curcmap_r[0] = data->curcmap_g[0] = data->curcmap_b[0] = 0;
    306 	data->curcmap_r[1] = data->curcmap_g[1] = data->curcmap_b[1] = 0xff;
    307 
    308 	/* Initial colormap: 0 is black, everything else is white */
    309 	data->cmap_r[0] = data->cmap_g[0] = data->cmap_b[0] = 0;
    310 	for (i = 1; i < 256; i++)
    311 		data->cmap_r[i] = data->cmap_g[i] = data->cmap_b[i] = 255;
    312 
    313 
    314 	/* Initialize the window type table:
    315 	 *
    316 	 * Entry 0: 24-plane truecolor, overlays enabled, bypassed.
    317 	 *
    318 	 *  Lookup table bypass:      yes (    1 << 23 & 0x800000)  800000
    319 	 *  Colormap address:       0x000 (0x000 << 17 & 0x7e0000)       0
    320 	 *  Overlay mask:             0xf (  0xf << 13 & 0x01e000)   1e000
    321 	 *  Overlay location:    P<27:24> (    0 << 12 & 0x001000)       0
    322 	 *  Display mode:       Truecolor (    0 <<  9 & 0x000e00)     000
    323 	 *  Number of planes:           8 (    8 <<  5 & 0x0001e0)     100
    324 	 *  Plane shift:                0 (    0 <<  0 & 0x00001f)       0
    325 	 *                                                        --------
    326 	 *                                                        0x81e100
    327 	 */
    328 	data->window_type[0] = 0x81e100;
    329 
    330 	/* Entry 1: 8-plane pseudocolor in the bottom 8 bits,
    331 	 *          overlays enabled, colormap starting at 0.
    332 	 *
    333 	 *  Lookup table bypass:       no (    0 << 23 & 0x800000)       0
    334 	 *  Colormap address:       0x000 (0x000 << 17 & 0x7e0000)       0
    335 	 *  Overlay mask:             0xf (  0xf << 13 & 0x01e000) 0x1e000
    336 	 *  Overlay location:    P<27:24> (    0 << 12 & 0x001000)       0
    337 	 *  Display mode:     Pseudocolor (    1 <<  9 & 0x000e00)   0x200
    338 	 *  Number of planes:           8 (    8 <<  5 & 0x0001e0)   0x100
    339 	 *  Plane shift:               16 ( 0x10 <<  0 & 0x00001f)      10
    340 	 *                                                        --------
    341 	 *                                                        0x01e310
    342 	 */
    343 	data->window_type[1] = 0x01e310;
    344 
    345 	/* The colormap interface to the world only supports one colormap,
    346 	 * so having an entry for the 'alternate' colormap in the bt463
    347 	 * probably isn't useful.
    348 	 */
    349 
    350 	/* Fill the remaining table entries with clones of entry 0 until we
    351 	 * figure out a better use for them.
    352 	 */
    353 
    354 	for (i = 2; i < BT463_NWTYPE_ENTRIES; i++) {
    355 		data->window_type[i] = 0x81e100;
    356 	}
    357 
    358 	data->ramdac_sched_update(data->cookie, bt463_update);
    359 
    360 }
    361 
    362 int
    363 bt463_set_cmap(rc, cmapp)
    364 	struct ramdac_cookie *rc;
    365 	struct wsdisplay_cmap *cmapp;
    366 {
    367 	struct bt463data *data = (struct bt463data *)rc;
    368 	u_int count, index;
    369 	int s;
    370 
    371 	if (cmapp->index >= BT463_NCMAP_ENTRIES ||
    372 	    cmapp->count > BT463_NCMAP_ENTRIES - cmapp->index)
    373 		return (EINVAL);
    374 	if (!uvm_useracc(cmapp->red, cmapp->count, B_READ) ||
    375 	    !uvm_useracc(cmapp->green, cmapp->count, B_READ) ||
    376 	    !uvm_useracc(cmapp->blue, cmapp->count, B_READ))
    377 		return (EFAULT);
    378 
    379 	s = spltty();
    380 
    381 	index = cmapp->index;
    382 	count = cmapp->count;
    383 	copyin(cmapp->red, &data->cmap_r[index], count);
    384 	copyin(cmapp->green, &data->cmap_g[index], count);
    385 	copyin(cmapp->blue, &data->cmap_b[index], count);
    386 
    387 	data->changed |= DATA_CMAP_CHANGED;
    388 
    389 	data->ramdac_sched_update(data->cookie, bt463_update);
    390 	splx(s);
    391 
    392 	return (0);
    393 }
    394 
    395 int
    396 bt463_get_cmap(rc, cmapp)
    397 	struct ramdac_cookie *rc;
    398 	struct wsdisplay_cmap *cmapp;
    399 {
    400 	struct bt463data *data = (struct bt463data *)rc;
    401 	u_int count, index;
    402 	int error;
    403 
    404 	if (cmapp->index >= BT463_NCMAP_ENTRIES ||
    405 	    cmapp->count > BT463_NCMAP_ENTRIES - cmapp->index)
    406 		return (EINVAL);
    407 
    408 	count = cmapp->count;
    409 	index = cmapp->index;
    410 
    411 	error = copyout(&data->cmap_r[index], cmapp->red, count);
    412 	if (error)
    413 		return (error);
    414 	error = copyout(&data->cmap_g[index], cmapp->green, count);
    415 	if (error)
    416 		return (error);
    417 	error = copyout(&data->cmap_b[index], cmapp->blue, count);
    418 	return (error);
    419 }
    420 
    421 int
    422 bt463_check_curcmap(rc, cursorp)
    423 	struct ramdac_cookie *rc;
    424 	struct wsdisplay_cursor *cursorp;
    425 {
    426 	int count;
    427 
    428 	if ((u_int)cursorp->cmap.index > 2 ||
    429 	    ((u_int)cursorp->cmap.index +
    430 	     (u_int)cursorp->cmap.count) > 2)
    431 		return (EINVAL);
    432 	count = cursorp->cmap.count;
    433 	if (!uvm_useracc(cursorp->cmap.red, count, B_READ) ||
    434 	    !uvm_useracc(cursorp->cmap.green, count, B_READ) ||
    435 	    !uvm_useracc(cursorp->cmap.blue, count, B_READ))
    436 		return (EFAULT);
    437 	return (0);
    438 }
    439 
    440 void
    441 bt463_set_curcmap(rc, cursorp)
    442 	struct ramdac_cookie *rc;
    443 	struct wsdisplay_cursor *cursorp;
    444 {
    445 	struct bt463data *data = (struct bt463data *)rc;
    446 	int count, index;
    447 
    448 	/* can't fail; parameters have already been checked. */
    449 	count = cursorp->cmap.count;
    450 	index = cursorp->cmap.index;
    451 	copyin(cursorp->cmap.red, &data->curcmap_r[index], count);
    452 	copyin(cursorp->cmap.green, &data->curcmap_g[index], count);
    453 	copyin(cursorp->cmap.blue, &data->curcmap_b[index], count);
    454 	data->changed |= DATA_CURCMAP_CHANGED;
    455 	data->ramdac_sched_update(data->cookie, bt463_update);
    456 }
    457 
    458 int
    459 bt463_get_curcmap(rc, cursorp)
    460 	struct ramdac_cookie *rc;
    461 	struct wsdisplay_cursor *cursorp;
    462 {
    463 	struct bt463data *data = (struct bt463data *)rc;
    464 	int error;
    465 
    466 	cursorp->cmap.index = 0;	/* DOCMAP */
    467 	cursorp->cmap.count = 2;
    468 	if (cursorp->cmap.red != NULL) {
    469 		error = copyout(data->curcmap_r, cursorp->cmap.red, 2);
    470 		if (error)
    471 			return (error);
    472 	}
    473 	if (cursorp->cmap.green != NULL) {
    474 		error = copyout(data->curcmap_g, cursorp->cmap.green, 2);
    475 		if (error)
    476 			return (error);
    477 	}
    478 	if (cursorp->cmap.blue != NULL) {
    479 		error = copyout(data->curcmap_b, cursorp->cmap.blue, 2);
    480 		if (error)
    481 			return (error);
    482 	}
    483 	return (0);
    484 }
    485 
    486 
    487 /*****************************************************************************/
    488 
    489 /*
    490  * Internal functions.
    491  */
    492 
    493 #ifdef BT463_DEBUG
    494 int bt463_store(void *v)
    495 {
    496 	struct bt463data *data = (struct bt463data *)v;
    497 
    498 	data->changed = DATA_ALL_CHANGED;
    499 	data->ramdac_sched_update(data->cookie, bt463_update);
    500 	printf("Scheduled bt463 store\n");
    501 
    502 	return 0;
    503 }
    504 
    505 
    506 int bt463_readback(void *v)
    507 {
    508 	struct bt463data *data = (struct bt463data *)v;
    509 
    510 	data->ramdac_sched_update(data->cookie, bt463_copyback);
    511 	printf("Scheduled bt463 copyback\n");
    512 	return 0;
    513 }
    514 
    515 int
    516 bt463_debug(v)
    517 	void *v;
    518 {
    519 	struct bt463data *data = (struct bt463data *)v;
    520 	int i;
    521 	u_int8_t val;
    522 
    523 	printf("BT463 main regs:\n");
    524 	for (i = 0x200; i < 0x20F; i ++) {
    525 	  val = BTRREG(data, i);
    526 	  printf("  $%04x %02x\n", i, val);
    527 	}
    528 
    529 	printf("BT463 revision register:\n");
    530 	  val = BTRREG(data, 0x220);
    531 	  printf("  $%04x %02x\n", 0x220, val);
    532 
    533 	printf("BT463 window type table (from softc):\n");
    534 
    535 	for (i = 0; i < BT463_NWTYPE_ENTRIES; i++) {
    536 	  printf("%02x %06x\n", i, data->window_type[i]);
    537 	}
    538 
    539 	return 0;
    540 }
    541 
    542 void
    543 bt463_copyback(p)
    544 	 void *p;
    545 {
    546 	struct bt463data *data = (struct bt463data *)p;
    547 	int i;
    548 
    549 		for (i = 0; i < BT463_NWTYPE_ENTRIES; i++) {
    550 			bt463_wraddr(data, BT463_IREG_WINDOW_TYPE_TABLE + i);
    551 			data->window_type[i] = (BTRNREG(data) & 0xff);        /* B0-7   */
    552 			data->window_type[i] |= (BTRNREG(data) & 0xff) << 8;  /* B8-15  */
    553 			data->window_type[i] |= (BTRNREG(data) & 0xff) << 16; /* B16-23 */
    554 		}
    555 }
    556 #endif
    557 
    558 inline void
    559 bt463_wraddr(data, ireg)
    560 	struct bt463data *data;
    561 	u_int16_t ireg;
    562 {
    563 	data->ramdac_wr(data->cookie, BT463_REG_ADDR_LOW, ireg & 0xff);
    564 	data->ramdac_wr(data->cookie, BT463_REG_ADDR_HIGH, (ireg >> 8) & 0xff);
    565 }
    566 
    567 void
    568 bt463_update(p)
    569 	void *p;
    570 {
    571 	struct bt463data *data = (struct bt463data *)p;
    572 	int i, v;
    573 
    574 	if (console_data != NULL) {
    575 		/* The cookie passed in from sched_update is incorrect. Use the
    576 		 * right one.
    577 		 */
    578 		data = console_data;
    579 	}
    580 
    581 	v = data->changed;
    582 
    583 	/* The Bt463 won't accept window type data except during a blanking
    584 	 * interval, so we do this early in the interrupt.
    585 	 * Blanking the screen might also be a good idea, but it can cause
    586 	 * unpleasant flashing and is hard to do from this side of the
    587 	 * ramdac interface.
    588 	 */
    589 	if (v & DATA_WTYPE_CHANGED) {
    590 		/* spit out the window type data */
    591 		for (i = 0; i < BT463_NWTYPE_ENTRIES; i++) {
    592 			bt463_wraddr(data, BT463_IREG_WINDOW_TYPE_TABLE + i);
    593 			BTWNREG(data, (data->window_type[i]) & 0xff);       /* B0-7   */
    594 			BTWNREG(data, (data->window_type[i] >> 8) & 0xff);  /* B8-15   */
    595 			BTWNREG(data, (data->window_type[i] >> 16) & 0xff); /* B16-23  */
    596 		}
    597 	}
    598 
    599 	if (v & DATA_CURCMAP_CHANGED) {
    600 		bt463_wraddr(data, BT463_IREG_CURSOR_COLOR_0);
    601 		/* spit out the cursor data */
    602 		for (i = 0; i < 2; i++) {
    603 			BTWNREG(data, data->curcmap_r[i]);
    604 			BTWNREG(data, data->curcmap_g[i]);
    605 			BTWNREG(data, data->curcmap_b[i]);
    606 		}
    607 	}
    608 
    609 	if (v & DATA_CMAP_CHANGED) {
    610 		bt463_wraddr(data, BT463_IREG_CPALETTE_RAM);
    611 		/* spit out the colormap data */
    612 		for (i = 0; i < BT463_NCMAP_ENTRIES; i++) {
    613 			data->ramdac_wr(data->cookie, BT463_REG_CMAP_DATA,
    614 				data->cmap_r[i]);
    615 			data->ramdac_wr(data->cookie, BT463_REG_CMAP_DATA,
    616 				data->cmap_g[i]);
    617 			data->ramdac_wr(data->cookie, BT463_REG_CMAP_DATA,
    618 				data->cmap_b[i]);
    619 		}
    620 	}
    621 
    622 	data->changed = 0;
    623 }
    624 
    625 int	bt463_set_cursor (rc, cur)
    626 	struct ramdac_cookie *rc;
    627 	struct wsdisplay_cursor *cur;
    628 {
    629 	struct bt463data *data = (struct bt463data *)rc;
    630 	return tga_builtin_set_cursor(data->cookie, cur);
    631 }
    632 
    633 int	bt463_get_cursor (rc, cur)
    634 	struct ramdac_cookie *rc;
    635 	struct wsdisplay_cursor *cur;
    636 {
    637 	struct bt463data *data = (struct bt463data *)rc;
    638 	return tga_builtin_get_cursor(data->cookie, cur);
    639 }
    640 
    641 int	bt463_set_curpos (rc, cur)
    642 	struct ramdac_cookie *rc;
    643 	struct wsdisplay_curpos *cur;
    644 {
    645 	struct bt463data *data = (struct bt463data *)rc;
    646 	return tga_builtin_set_curpos(data->cookie, cur);
    647 }
    648 
    649 int	bt463_get_curpos (rc, cur)
    650 	struct ramdac_cookie *rc;
    651 	struct wsdisplay_curpos *cur;
    652 {
    653 	struct bt463data *data = (struct bt463data *)rc;
    654 	return tga_builtin_get_curpos(data->cookie, cur);
    655 }
    656 
    657 int	bt463_get_curmax (rc, cur)
    658 	struct ramdac_cookie *rc;
    659 	struct wsdisplay_curpos *cur;
    660 {
    661 	struct bt463data *data = (struct bt463data *)rc;
    662 	return tga_builtin_get_curmax(data->cookie, cur);
    663 }
    664