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