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