Home | History | Annotate | Line # | Download | only in tc
stic.c revision 1.11
      1  1.11        ad /*	$NetBSD: stic.c,v 1.11 2001/09/18 19:51:23 ad Exp $	*/
      2   1.4        ad 
      3   1.4        ad /*-
      4   1.7        ad  * Copyright (c) 1999, 2000, 2001 The NetBSD Foundation, Inc.
      5   1.4        ad  * All rights reserved.
      6   1.4        ad  *
      7   1.4        ad  * This code is derived from software contributed to The NetBSD Foundation
      8   1.4        ad  * by Andrew Doran.
      9   1.4        ad  *
     10   1.4        ad  * Redistribution and use in source and binary forms, with or without
     11   1.4        ad  * modification, are permitted provided that the following conditions
     12   1.4        ad  * are met:
     13   1.4        ad  * 1. Redistributions of source code must retain the above copyright
     14   1.4        ad  *    notice, this list of conditions and the following disclaimer.
     15   1.4        ad  * 2. Redistributions in binary form must reproduce the above copyright
     16   1.4        ad  *    notice, this list of conditions and the following disclaimer in the
     17   1.4        ad  *    documentation and/or other materials provided with the distribution.
     18   1.4        ad  * 3. All advertising materials mentioning features or use of this software
     19   1.4        ad  *    must display the following acknowledgement:
     20   1.4        ad  *	This product includes software developed by the NetBSD
     21   1.4        ad  *	Foundation, Inc. and its contributors.
     22   1.4        ad  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23   1.4        ad  *    contributors may be used to endorse or promote products derived
     24   1.4        ad  *    from this software without specific prior written permission.
     25   1.4        ad  *
     26   1.4        ad  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27   1.4        ad  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28   1.4        ad  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29   1.4        ad  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30   1.4        ad  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31   1.4        ad  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32   1.4        ad  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33   1.4        ad  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34   1.4        ad  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35   1.4        ad  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36   1.4        ad  * POSSIBILITY OF SUCH DAMAGE.
     37   1.4        ad  */
     38   1.1  jonathan 
     39   1.1  jonathan /*
     40   1.4        ad  * Copyright (c) 1998, 1999 Tohru Nishimura.  All rights reserved.
     41   1.1  jonathan  *
     42   1.1  jonathan  * Redistribution and use in source and binary forms, with or without
     43   1.1  jonathan  * modification, are permitted provided that the following conditions
     44   1.1  jonathan  * are met:
     45   1.1  jonathan  * 1. Redistributions of source code must retain the above copyright
     46   1.1  jonathan  *    notice, this list of conditions and the following disclaimer.
     47   1.1  jonathan  * 2. Redistributions in binary form must reproduce the above copyright
     48   1.1  jonathan  *    notice, this list of conditions and the following disclaimer in the
     49   1.1  jonathan  *    documentation and/or other materials provided with the distribution.
     50   1.1  jonathan  * 3. All advertising materials mentioning features or use of this software
     51   1.1  jonathan  *    must display the following acknowledgement:
     52   1.4        ad  *      This product includes software developed by Tohru Nishimura
     53   1.4        ad  *	for the NetBSD Project.
     54   1.1  jonathan  * 4. The name of the author may not be used to endorse or promote products
     55   1.4        ad  *    derived from this software without specific prior written permission
     56   1.1  jonathan  *
     57   1.1  jonathan  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     58   1.1  jonathan  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     59   1.1  jonathan  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     60   1.1  jonathan  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     61   1.1  jonathan  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     62   1.1  jonathan  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     63   1.1  jonathan  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     64   1.1  jonathan  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     65   1.1  jonathan  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     66   1.1  jonathan  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     67   1.1  jonathan  */
     68   1.1  jonathan 
     69   1.1  jonathan /*
     70   1.4        ad  * Driver for the DEC PixelStamp interface chip (STIC).
     71   1.4        ad  *
     72   1.4        ad  * XXX The bt459 interface shouldn't be replicated here.
     73   1.1  jonathan  */
     74   1.1  jonathan 
     75   1.4        ad #include <sys/param.h>
     76   1.4        ad #include <sys/systm.h>
     77   1.4        ad #include <sys/kernel.h>
     78   1.4        ad #include <sys/device.h>
     79   1.4        ad #include <sys/malloc.h>
     80   1.4        ad #include <sys/buf.h>
     81   1.4        ad #include <sys/ioctl.h>
     82   1.4        ad #include <sys/callout.h>
     83  1.11        ad #include <sys/conf.h>
     84   1.4        ad 
     85   1.4        ad #include <uvm/uvm_extern.h>
     86   1.4        ad 
     87   1.4        ad #if defined(pmax)
     88   1.4        ad #include <mips/cpuregs.h>
     89   1.4        ad #elif defined(alpha)
     90   1.4        ad #include <alpha/alpha_cpu.h>
     91   1.4        ad #endif
     92   1.4        ad 
     93   1.7        ad #include <machine/vmparam.h>
     94   1.4        ad #include <machine/bus.h>
     95   1.4        ad #include <machine/intr.h>
     96   1.4        ad 
     97   1.4        ad #include <dev/wscons/wsconsio.h>
     98   1.4        ad #include <dev/wscons/wsdisplayvar.h>
     99   1.4        ad 
    100   1.4        ad #include <dev/wsfont/wsfont.h>
    101   1.4        ad 
    102   1.4        ad #include <dev/ic/bt459reg.h>
    103   1.4        ad 
    104   1.4        ad #include <dev/tc/tcvar.h>
    105   1.4        ad #include <dev/tc/sticreg.h>
    106  1.11        ad #include <dev/tc/sticio.h>
    107   1.4        ad #include <dev/tc/sticvar.h>
    108   1.4        ad 
    109   1.4        ad #define DUPBYTE0(x) ((((x)&0xff)<<16) | (((x)&0xff)<<8) | ((x)&0xff))
    110   1.4        ad #define DUPBYTE1(x) ((((x)<<8)&0xff0000) | ((x)&0xff00) | (((x)>>8)&0xff))
    111   1.4        ad #define DUPBYTE2(x) (((x)&0xff0000) | (((x)>>8)&0xff00) | (((x)>>16)&0xff))
    112   1.4        ad 
    113   1.4        ad #define PACK(p, o) ((p)[(o)] | ((p)[(o)+1] << 16))
    114   1.4        ad 
    115   1.4        ad #if defined(pmax)
    116   1.4        ad #define	machine_btop(x)		mips_btop(x)
    117   1.4        ad #elif defined(alpha)
    118   1.4        ad #define machine_btop(x)		alpha_btop(x)
    119   1.4        ad #endif
    120   1.4        ad 
    121   1.1  jonathan /*
    122   1.4        ad  * N.B., Bt459 registers are 8bit width.  Some of TC framebuffers have
    123   1.4        ad  * obscure register layout such as 2nd and 3rd Bt459 registers are
    124   1.4        ad  * adjacent each other in a word, i.e.,
    125   1.4        ad  *	struct bt459triplet {
    126   1.4        ad  * 		struct {
    127   1.4        ad  *			u_int8_t u0;
    128   1.4        ad  *			u_int8_t u1;
    129   1.4        ad  *			u_int8_t u2;
    130   1.4        ad  *			unsigned :8;
    131   1.4        ad  *		} bt_lo;
    132   1.4        ad  *		struct {
    133   1.1  jonathan  *
    134   1.4        ad  * Although HX has single Bt459, 32bit R/W can be done w/o any trouble.
    135   1.4        ad  *	struct bt459reg {
    136   1.4        ad  *		   u_int32_t	   bt_lo;
    137   1.4        ad  *		   u_int32_t	   bt_hi;
    138   1.4        ad  *		   u_int32_t	   bt_reg;
    139   1.4        ad  *		   u_int32_t	   bt_cmap;
    140   1.4        ad  *	};
    141   1.1  jonathan  *
    142   1.1  jonathan  */
    143   1.1  jonathan 
    144   1.4        ad /* Bt459 hardware registers */
    145   1.4        ad #define bt_lo	0
    146   1.4        ad #define bt_hi	1
    147   1.4        ad #define bt_reg	2
    148   1.4        ad #define bt_cmap 3
    149   1.4        ad 
    150   1.4        ad #define REG(base, index)	*((u_int32_t *)(base) + (index))
    151   1.4        ad #define SELECT(vdac, regno) do {		\
    152   1.4        ad 	REG(vdac, bt_lo) = DUPBYTE0(regno);	\
    153   1.4        ad 	REG(vdac, bt_hi) = DUPBYTE1(regno);	\
    154   1.4        ad 	tc_wmb();				\
    155   1.4        ad    } while (0)
    156   1.4        ad 
    157  1.11        ad int	sticioctl(void *, u_long, caddr_t, int, struct proc *);
    158  1.11        ad int	stic_alloc_screen(void *, const struct wsscreen_descr *, void **,
    159  1.11        ad 			  int *, int *, long *);
    160  1.11        ad void	stic_free_screen(void *, void *);
    161  1.11        ad int	stic_show_screen(void *, void *, int, void (*)(void *, int, int),
    162  1.11        ad 			 void *);
    163  1.11        ad 
    164  1.11        ad int	sticopen(dev_t, int, int, struct proc *);
    165  1.11        ad int	sticclose(dev_t, int, int, struct proc *);
    166  1.11        ad paddr_t	sticmmap(dev_t, off_t, int);
    167  1.11        ad 
    168  1.11        ad void	stic_do_switch(void *);
    169  1.11        ad void	stic_setup_backing(struct stic_info *, struct stic_screen *);
    170  1.11        ad void	stic_setup_vdac(struct stic_info *);
    171  1.11        ad void	stic_clear_screen(struct stic_info *);
    172  1.11        ad 
    173  1.11        ad int	stic_get_cmap(struct stic_info *, struct wsdisplay_cmap *);
    174  1.11        ad int	stic_set_cmap(struct stic_info *, struct wsdisplay_cmap *);
    175  1.11        ad int	stic_set_cursor(struct stic_info *, struct wsdisplay_cursor *);
    176  1.11        ad int	stic_get_cursor(struct stic_info *, struct wsdisplay_cursor *);
    177  1.11        ad void	stic_set_curpos(struct stic_info *, struct wsdisplay_curpos *);
    178  1.11        ad void	stic_set_hwcurpos(struct stic_info *);
    179  1.11        ad 
    180  1.11        ad void	stic_cursor(void *, int, int, int);
    181  1.11        ad void	stic_copycols(void *, int, int, int, int);
    182  1.11        ad void	stic_copyrows(void *, int, int, int);
    183  1.11        ad void	stic_erasecols(void *, int, int, int, long);
    184  1.11        ad void	stic_eraserows(void *, int, int, long);
    185  1.11        ad int	stic_mapchar(void *, int, u_int *);
    186  1.11        ad void	stic_putchar(void *, int, int, u_int, long);
    187  1.11        ad int	stic_alloc_attr(void *, int, int, int, long *);
    188   1.4        ad 
    189   1.4        ad /* Colormap for wscons, matching WSCOL_*. Upper 8 are high-intensity. */
    190   1.4        ad static const u_int8_t stic_cmap[16*3] = {
    191   1.4        ad 	0x00, 0x00, 0x00, /* black */
    192   1.4        ad 	0x7f, 0x00, 0x00, /* red */
    193   1.4        ad 	0x00, 0x7f, 0x00, /* green */
    194   1.4        ad 	0x7f, 0x7f, 0x00, /* brown */
    195   1.4        ad 	0x00, 0x00, 0x7f, /* blue */
    196   1.4        ad 	0x7f, 0x00, 0x7f, /* magenta */
    197   1.4        ad 	0x00, 0x7f, 0x7f, /* cyan */
    198   1.4        ad 	0xc7, 0xc7, 0xc7, /* white */
    199   1.4        ad 
    200   1.4        ad 	0x7f, 0x7f, 0x7f, /* black */
    201   1.4        ad 	0xff, 0x00, 0x00, /* red */
    202   1.4        ad 	0x00, 0xff, 0x00, /* green */
    203   1.4        ad 	0xff, 0xff, 0x00, /* brown */
    204   1.4        ad 	0x00, 0x00, 0xff, /* blue */
    205   1.4        ad 	0xff, 0x00, 0xff, /* magenta */
    206   1.4        ad 	0x00, 0xff, 0xff, /* cyan */
    207   1.4        ad 	0xff, 0xff, 0xff, /* white */
    208   1.4        ad };
    209   1.1  jonathan 
    210   1.1  jonathan /*
    211   1.4        ad  * Compose 2 bit/pixel cursor image.  Bit order will be reversed.
    212   1.4        ad  *   M M M M I I I I		M I M I M I M I
    213   1.4        ad  *	[ before ]		   [ after ]
    214   1.4        ad  *   3 2 1 0 3 2 1 0		0 0 1 1 2 2 3 3
    215   1.4        ad  *   7 6 5 4 7 6 5 4		4 4 5 5 6 6 7 7
    216   1.1  jonathan  */
    217   1.4        ad static const u_int8_t shuffle[256] = {
    218   1.4        ad 	0x00, 0x40, 0x10, 0x50, 0x04, 0x44, 0x14, 0x54,
    219   1.4        ad 	0x01, 0x41, 0x11, 0x51, 0x05, 0x45, 0x15, 0x55,
    220   1.4        ad 	0x80, 0xc0, 0x90, 0xd0, 0x84, 0xc4, 0x94, 0xd4,
    221   1.4        ad 	0x81, 0xc1, 0x91, 0xd1, 0x85, 0xc5, 0x95, 0xd5,
    222   1.4        ad 	0x20, 0x60, 0x30, 0x70, 0x24, 0x64, 0x34, 0x74,
    223   1.4        ad 	0x21, 0x61, 0x31, 0x71, 0x25, 0x65, 0x35, 0x75,
    224   1.4        ad 	0xa0, 0xe0, 0xb0, 0xf0, 0xa4, 0xe4, 0xb4, 0xf4,
    225   1.4        ad 	0xa1, 0xe1, 0xb1, 0xf1, 0xa5, 0xe5, 0xb5, 0xf5,
    226   1.4        ad 	0x08, 0x48, 0x18, 0x58, 0x0c, 0x4c, 0x1c, 0x5c,
    227   1.4        ad 	0x09, 0x49, 0x19, 0x59, 0x0d, 0x4d, 0x1d, 0x5d,
    228   1.4        ad 	0x88, 0xc8, 0x98, 0xd8, 0x8c, 0xcc, 0x9c, 0xdc,
    229   1.4        ad 	0x89, 0xc9, 0x99, 0xd9, 0x8d, 0xcd, 0x9d, 0xdd,
    230   1.4        ad 	0x28, 0x68, 0x38, 0x78, 0x2c, 0x6c, 0x3c, 0x7c,
    231   1.4        ad 	0x29, 0x69, 0x39, 0x79, 0x2d, 0x6d, 0x3d, 0x7d,
    232   1.4        ad 	0xa8, 0xe8, 0xb8, 0xf8, 0xac, 0xec, 0xbc, 0xfc,
    233   1.4        ad 	0xa9, 0xe9, 0xb9, 0xf9, 0xad, 0xed, 0xbd, 0xfd,
    234   1.4        ad 	0x02, 0x42, 0x12, 0x52, 0x06, 0x46, 0x16, 0x56,
    235   1.4        ad 	0x03, 0x43, 0x13, 0x53, 0x07, 0x47, 0x17, 0x57,
    236   1.4        ad 	0x82, 0xc2, 0x92, 0xd2, 0x86, 0xc6, 0x96, 0xd6,
    237   1.4        ad 	0x83, 0xc3, 0x93, 0xd3, 0x87, 0xc7, 0x97, 0xd7,
    238   1.4        ad 	0x22, 0x62, 0x32, 0x72, 0x26, 0x66, 0x36, 0x76,
    239   1.4        ad 	0x23, 0x63, 0x33, 0x73, 0x27, 0x67, 0x37, 0x77,
    240   1.4        ad 	0xa2, 0xe2, 0xb2, 0xf2, 0xa6, 0xe6, 0xb6, 0xf6,
    241   1.4        ad 	0xa3, 0xe3, 0xb3, 0xf3, 0xa7, 0xe7, 0xb7, 0xf7,
    242   1.4        ad 	0x0a, 0x4a, 0x1a, 0x5a, 0x0e, 0x4e, 0x1e, 0x5e,
    243   1.4        ad 	0x0b, 0x4b, 0x1b, 0x5b, 0x0f, 0x4f, 0x1f, 0x5f,
    244   1.4        ad 	0x8a, 0xca, 0x9a, 0xda, 0x8e, 0xce, 0x9e, 0xde,
    245   1.4        ad 	0x8b, 0xcb, 0x9b, 0xdb, 0x8f, 0xcf, 0x9f, 0xdf,
    246   1.4        ad 	0x2a, 0x6a, 0x3a, 0x7a, 0x2e, 0x6e, 0x3e, 0x7e,
    247   1.4        ad 	0x2b, 0x6b, 0x3b, 0x7b, 0x2f, 0x6f, 0x3f, 0x7f,
    248   1.4        ad 	0xaa, 0xea, 0xba, 0xfa, 0xae, 0xee, 0xbe, 0xfe,
    249   1.4        ad 	0xab, 0xeb, 0xbb, 0xfb, 0xaf, 0xef, 0xbf, 0xff,
    250   1.4        ad };
    251   1.4        ad 
    252   1.4        ad static const struct wsdisplay_accessops stic_accessops = {
    253   1.4        ad 	sticioctl,
    254  1.11        ad 	NULL,			/* mmap */
    255   1.4        ad 	stic_alloc_screen,
    256   1.4        ad 	stic_free_screen,
    257   1.4        ad 	stic_show_screen,
    258  1.11        ad 	NULL,			/* load_font */
    259   1.4        ad };
    260   1.4        ad 
    261   1.4        ad static const struct wsdisplay_emulops stic_emulops = {
    262   1.4        ad 	stic_cursor,
    263   1.4        ad 	stic_mapchar,
    264   1.4        ad 	stic_putchar,
    265   1.4        ad 	stic_copycols,
    266   1.4        ad 	stic_erasecols,
    267   1.4        ad 	stic_copyrows,
    268   1.4        ad 	stic_eraserows,
    269   1.4        ad 	stic_alloc_attr
    270   1.4        ad };
    271   1.4        ad 
    272   1.4        ad static struct wsscreen_descr stic_stdscreen = {
    273   1.4        ad 	"std",
    274   1.4        ad 	0, 0,
    275   1.4        ad 	&stic_emulops,
    276   1.4        ad 	0, 0,
    277   1.8        ad 	WSSCREEN_WSCOLORS | WSSCREEN_HILIT
    278   1.4        ad };
    279   1.4        ad 
    280   1.4        ad static const struct wsscreen_descr *_stic_scrlist[] = {
    281   1.4        ad 	&stic_stdscreen,
    282   1.4        ad };
    283   1.4        ad 
    284   1.4        ad static const struct wsscreen_list stic_screenlist = {
    285   1.4        ad 	sizeof(_stic_scrlist) / sizeof(struct wsscreen_descr *), _stic_scrlist
    286   1.4        ad };
    287   1.1  jonathan 
    288   1.4        ad struct	stic_info stic_consinfo;
    289   1.4        ad static struct	stic_screen stic_consscr;
    290  1.11        ad static struct	stic_info *stic_info[STIC_MAXDV];
    291  1.11        ad static int	stic_unit;
    292   1.1  jonathan 
    293   1.4        ad void
    294   1.4        ad stic_init(struct stic_info *si)
    295   1.4        ad {
    296   1.4        ad 	volatile u_int32_t *vdac;
    297   1.4        ad 	int i, cookie;
    298   1.1  jonathan 
    299   1.4        ad 	/* Reset the STIC & stamp(s). */
    300   1.4        ad 	stic_reset(si);
    301   1.4        ad 	vdac = si->si_vdac;
    302   1.4        ad 
    303   1.4        ad 	/* Hit it... */
    304   1.4        ad 	SELECT(vdac, BT459_IREG_COMMAND_0);
    305   1.8        ad 	REG(vdac, bt_reg) = 0x00c0c0c0; tc_wmb();
    306   1.4        ad 
    307   1.4        ad 	/* Now reset the VDAC. */
    308   1.4        ad 	*si->si_vdac_reset = 0;
    309   1.8        ad 	tc_wmb();
    310   1.4        ad 	tc_syncbus();
    311   1.4        ad 	DELAY(1000);
    312   1.4        ad 
    313  1.10       wiz 	/* Finish the initialization. */
    314   1.4        ad 	SELECT(vdac, BT459_IREG_COMMAND_1);
    315   1.4        ad 	REG(vdac, bt_reg) = 0x00000000; tc_wmb();
    316   1.4        ad 	REG(vdac, bt_reg) = 0x00c2c2c2; tc_wmb();
    317   1.4        ad 	REG(vdac, bt_reg) = 0x00ffffff; tc_wmb();
    318   1.4        ad 
    319   1.4        ad 	for (i = 0; i < 7; i++) {
    320   1.4        ad 		REG(vdac, bt_reg) = 0x00000000;
    321   1.4        ad 		tc_wmb();
    322   1.4        ad 	}
    323   1.1  jonathan 
    324   1.4        ad 	/* Set cursor colormap. */
    325   1.4        ad 	SELECT(vdac, BT459_IREG_CCOLOR_1);
    326   1.4        ad 	REG(vdac, bt_reg) = 0x00ffffff; tc_wmb();
    327   1.4        ad 	REG(vdac, bt_reg) = 0x00ffffff; tc_wmb();
    328   1.4        ad 	REG(vdac, bt_reg) = 0x00ffffff; tc_wmb();
    329   1.4        ad 	REG(vdac, bt_reg) = 0x00000000; tc_wmb();
    330   1.4        ad 	REG(vdac, bt_reg) = 0x00000000; tc_wmb();
    331   1.4        ad 	REG(vdac, bt_reg) = 0x00000000; tc_wmb();
    332   1.4        ad 	REG(vdac, bt_reg) = 0x00ffffff; tc_wmb();
    333   1.4        ad 	REG(vdac, bt_reg) = 0x00ffffff; tc_wmb();
    334   1.4        ad 	REG(vdac, bt_reg) = 0x00ffffff; tc_wmb();
    335   1.4        ad 
    336   1.4        ad 	/* Get a font and set up screen metrics. */
    337   1.4        ad 	wsfont_init();
    338   1.4        ad 	cookie = wsfont_find(NULL, 0, 0, 0);
    339   1.4        ad 
    340   1.4        ad 	if (wsfont_lock(cookie, &si->si_font,
    341   1.4        ad 	    WSDISPLAY_FONTORDER_R2L, WSDISPLAY_FONTORDER_L2R) <= 0)
    342   1.4        ad 		panic("stic_init: couldn't lock font\n");
    343   1.4        ad 
    344   1.6        ad 	si->si_fontw = si->si_font->fontwidth;
    345   1.4        ad 	si->si_fonth = si->si_font->fontheight;
    346   1.6        ad 	si->si_consw = (1280 / si->si_fontw) & ~1;
    347   1.4        ad 	si->si_consh = 1024 / si->si_fonth;
    348   1.6        ad 	stic_stdscreen.ncols = si->si_consw;
    349   1.4        ad 	stic_stdscreen.nrows = si->si_consh;
    350   1.4        ad 
    351   1.4        ad #ifdef DIAGNOSTIC
    352   1.4        ad 	if ((u_int)si->si_fonth > 32 || (u_int)si->si_fontw > 16)
    353   1.4        ad 		panic("stic_init: unusable font");
    354   1.4        ad #endif
    355   1.7        ad 
    356   1.7        ad 	stic_setup_vdac(si);
    357  1.11        ad 	stic_clear_screen(si);
    358  1.11        ad 	si->si_dispmode = WSDISPLAYIO_MODE_EMUL;
    359   1.4        ad }
    360   1.1  jonathan 
    361   1.4        ad void
    362   1.4        ad stic_reset(struct stic_info *si)
    363   1.1  jonathan {
    364   1.1  jonathan 	int modtype, xconfig, yconfig, config;
    365   1.4        ad 	volatile struct stic_regs *sr;
    366   1.4        ad 
    367   1.4        ad 	sr = si->si_stic;
    368   1.1  jonathan 
    369   1.1  jonathan 	/*
    370   1.4        ad 	 * Initialize the interface chip registers.
    371   1.1  jonathan 	 */
    372   1.4        ad 	sr->sr_sticsr = 0x00000030;	/* Get the STIC's attention. */
    373   1.8        ad 	tc_wmb();
    374   1.4        ad 	tc_syncbus();
    375  1.11        ad 	DELAY(2000);			/* wait 2ms for STIC to respond. */
    376   1.4        ad 	sr->sr_sticsr = 0x00000000;	/* Hit the STIC's csr again... */
    377   1.8        ad 	tc_wmb();
    378   1.4        ad 	sr->sr_buscsr = 0xffffffff;	/* and bash its bus-acess csr. */
    379   1.8        ad 	tc_wmb();
    380   1.4        ad 	tc_syncbus();			/* Blam! */
    381   1.1  jonathan 	DELAY(20000);			/* wait until the stic recovers... */
    382   1.1  jonathan 
    383   1.4        ad 	modtype = sr->sr_modcl;
    384   1.4        ad 	xconfig = (modtype & 0x800) >> 11;
    385   1.4        ad 	yconfig = (modtype & 0x600) >> 9;
    386   1.4        ad 	config = (yconfig << 1) | xconfig;
    387   1.4        ad 	si->si_stampw = (xconfig ? 5 : 4);
    388   1.4        ad 	si->si_stamph = (1 << yconfig);
    389   1.1  jonathan #ifdef notyet
    390   1.4        ad 	si->si_option = (char)((modtype >> 12) & 3);
    391   1.1  jonathan #endif
    392   1.1  jonathan 
    393   1.4        ad 	/* First PixelStamp */
    394   1.4        ad 	si->si_stamp[0x000b0] = config;
    395   1.4        ad 	si->si_stamp[0x000b4] = 0x0;
    396   1.4        ad 
    397   1.4        ad 	/* Second PixelStamp */
    398   1.4        ad 	if (yconfig > 0) {
    399   1.4        ad 		si->si_stamp[0x100b0] = config | 8;
    400   1.4        ad 		si->si_stamp[0x100b4] = 0;
    401   1.4        ad 	}
    402   1.4        ad 
    403   1.1  jonathan 	/*
    404  1.11        ad 	 * Initialize STIC video registers.  Enable error and vertical
    405  1.11        ad 	 * retrace interrupts.  Set the packet done flag so the Xserver will
    406  1.11        ad 	 * not time-out on the first packet submitted.
    407   1.1  jonathan 	 */
    408   1.4        ad 	sr->sr_vblank = (1024 << 16) | 1063;
    409   1.4        ad 	sr->sr_vsync = (1027 << 16) | 1030;
    410   1.4        ad 	sr->sr_hblank = (255 << 16) | 340;
    411   1.4        ad 	sr->sr_hsync2 = 245;
    412   1.4        ad 	sr->sr_hsync = (261 << 16) | 293;
    413  1.11        ad 	sr->sr_ipdvint =
    414  1.11        ad 	    STIC_INT_WE | STIC_INT_P | STIC_INT_E_EN | STIC_INT_V_EN;
    415   1.4        ad 	sr->sr_sticsr = 8;
    416   1.4        ad 	tc_wmb();
    417   1.8        ad 	tc_syncbus();
    418   1.4        ad }
    419   1.4        ad 
    420   1.4        ad void
    421   1.4        ad stic_attach(struct device *self, struct stic_info *si, int console)
    422   1.4        ad {
    423   1.4        ad 	struct wsemuldisplaydev_attach_args waa;
    424   1.4        ad 
    425  1.11        ad 	if (stic_unit < STIC_MAXDV) {
    426  1.11        ad 		stic_info[stic_unit] = si;
    427  1.11        ad 		si->si_unit = stic_unit++;
    428  1.11        ad 	} else
    429  1.11        ad 		si->si_unit = -1;
    430  1.11        ad 
    431   1.4        ad 	callout_init(&si->si_switch_callout);
    432   1.1  jonathan 
    433   1.1  jonathan 	/*
    434   1.4        ad 	 * Allocate backing for the console.  We could trawl back through
    435   1.4        ad 	 * msgbuf and and fill the backing, but it's not worth the hassle.
    436   1.4        ad 	 * We could also grab backing using pmap_steal_memory() early on,
    437   1.4        ad 	 * but that's a little ugly.
    438   1.1  jonathan 	 */
    439   1.4        ad 	if (console)
    440   1.6        ad 		stic_setup_backing(si, &stic_consscr);
    441   1.4        ad 
    442   1.4        ad 	waa.console = console;
    443   1.4        ad 	waa.scrdata = &stic_screenlist;
    444   1.4        ad 	waa.accessops = &stic_accessops;
    445   1.4        ad 	waa.accesscookie = si;
    446  1.11        ad 
    447   1.4        ad 	config_found(self, &waa, wsemuldisplaydevprint);
    448   1.4        ad }
    449   1.4        ad 
    450   1.4        ad void
    451   1.4        ad stic_cnattach(struct stic_info *si)
    452   1.4        ad {
    453   1.4        ad 	struct stic_screen *ss;
    454   1.4        ad 	long defattr;
    455   1.4        ad 
    456   1.4        ad 	ss = &stic_consscr;
    457   1.4        ad 	si->si_curscreen = ss;
    458   1.8        ad 	ss->ss_flags = SS_ALLOCED | SS_ACTIVE | SS_CURENB;
    459   1.4        ad 	ss->ss_si = si;
    460   1.4        ad 
    461   1.8        ad 	si->si_flags |= SI_CURENB_CHANGED;
    462   1.4        ad 	stic_flush(si);
    463   1.4        ad 
    464   1.8        ad 	stic_alloc_attr(ss, 0, 0, 0, &defattr);
    465   1.7        ad 	stic_eraserows(ss, 0, si->si_consh, 0);
    466   1.4        ad 	wsdisplay_cnattach(&stic_stdscreen, ss, 0, 0, defattr);
    467   1.4        ad }
    468   1.4        ad 
    469  1.11        ad void
    470   1.7        ad stic_setup_vdac(struct stic_info *si)
    471   1.4        ad {
    472   1.4        ad 	u_int8_t *ip, *mp;
    473  1.11        ad 	int r, c, o, b, i, s;
    474  1.11        ad 
    475  1.11        ad 	s = spltty();
    476   1.4        ad 
    477   1.7        ad 	ip = (u_int8_t *)si->si_cursor.cc_image;
    478   1.7        ad 	mp = ip + (sizeof(si->si_cursor.cc_image) >> 1);
    479   1.7        ad 	memset(ip, 0, sizeof(si->si_cursor.cc_image));
    480   1.4        ad 
    481   1.4        ad 	for (r = 0; r < si->si_fonth; r++) {
    482  1.11        ad 		for (c = r & 1; c < si->si_fontw; c += 2) {
    483   1.4        ad 			o = c >> 3;
    484   1.4        ad 			b = 1 << (c & 7);
    485   1.4        ad 			ip[o] |= b;
    486   1.4        ad 			mp[o] |= b;
    487   1.4        ad 		}
    488   1.4        ad 
    489  1.11        ad 		ip += 8;
    490  1.11        ad 		mp += 8;
    491   1.4        ad 	}
    492   1.4        ad 
    493   1.7        ad 	si->si_cursor.cc_size.x = 64;
    494   1.7        ad 	si->si_cursor.cc_size.y = si->si_fonth;
    495   1.7        ad 	si->si_cursor.cc_hot.x = 0;
    496   1.7        ad 	si->si_cursor.cc_hot.y = 0;
    497   1.7        ad 
    498   1.7        ad 	si->si_cursor.cc_color[0] = 0xff;
    499   1.7        ad 	si->si_cursor.cc_color[2] = 0xff;
    500   1.7        ad 	si->si_cursor.cc_color[4] = 0xff;
    501   1.7        ad 	si->si_cursor.cc_color[1] = 0x00;
    502   1.7        ad 	si->si_cursor.cc_color[3] = 0x00;
    503   1.7        ad 	si->si_cursor.cc_color[5] = 0x00;
    504   1.4        ad 
    505   1.7        ad 	memset(&si->si_cmap, 0, sizeof(si->si_cmap));
    506   1.7        ad 	for (i = 0; i < 16; i++) {
    507   1.7        ad 		si->si_cmap.r[i] = stic_cmap[i*3 + 0];
    508   1.7        ad 		si->si_cmap.g[i] = stic_cmap[i*3 + 1];
    509   1.7        ad 		si->si_cmap.b[i] = stic_cmap[i*3 + 2];
    510   1.7        ad 	}
    511   1.7        ad 
    512   1.7        ad 	si->si_flags |= SI_CMAP_CHANGED | SI_CURSHAPE_CHANGED |
    513   1.7        ad 	    SI_CURCMAP_CHANGED;
    514  1.11        ad 
    515  1.11        ad 	splx(s);
    516   1.4        ad }
    517   1.4        ad 
    518  1.11        ad void
    519  1.11        ad stic_clear_screen(struct stic_info *si)
    520  1.11        ad {
    521  1.11        ad 	u_int32_t *pb;
    522  1.11        ad 	int i;
    523  1.11        ad 
    524  1.11        ad 	/*
    525  1.11        ad 	 * Do this twice, since the first packet after a reset may be
    526  1.11        ad 	 * silently ignored.
    527  1.11        ad 	 */
    528  1.11        ad 	for (i = 0; i < 2; i++) {
    529  1.11        ad 		pb = (*si->si_pbuf_get)(si);
    530  1.11        ad 
    531  1.11        ad 		pb[0] = STAMP_CMD_LINES | STAMP_RGB_CONST | STAMP_LW_PERPACKET;
    532  1.11        ad 		pb[1] = 0x01ffffff;
    533  1.11        ad 		pb[2] = 0;
    534  1.11        ad 		pb[3] = STAMP_UPDATE_ENABLE | STAMP_METHOD_COPY;
    535  1.11        ad 		pb[4] = (1024 << 2) - 1;
    536  1.11        ad 		pb[5] = 0;
    537  1.11        ad 		pb[6] = 0;
    538  1.11        ad 		pb[7] = (1280 << 19) | ((1024 << 3) + pb[4]);
    539  1.11        ad 
    540  1.11        ad 		(*si->si_pbuf_post)(si, pb);
    541  1.11        ad 	}
    542  1.11        ad }
    543  1.11        ad 
    544  1.11        ad int
    545   1.4        ad sticioctl(void *v, u_long cmd, caddr_t data, int flag, struct proc *p)
    546   1.4        ad {
    547   1.4        ad 	struct stic_info *si;
    548   1.4        ad 
    549   1.7        ad 	si = v;
    550   1.4        ad 
    551   1.4        ad 	switch (cmd) {
    552   1.4        ad 	case WSDISPLAYIO_GTYPE:
    553   1.4        ad 		*(u_int *)data = si->si_disptype;
    554   1.4        ad 		return (0);
    555   1.4        ad 
    556   1.4        ad 	case WSDISPLAYIO_GINFO:
    557   1.4        ad #define	wsd_fbip ((struct wsdisplay_fbinfo *)data)
    558   1.4        ad 		wsd_fbip->height = 1024;
    559   1.4        ad 		wsd_fbip->width = 1280;
    560   1.7        ad 		wsd_fbip->depth = si->si_depth == 8 ? 8 : 32;
    561   1.4        ad 		wsd_fbip->cmsize = CMAP_SIZE;
    562   1.4        ad #undef fbt
    563   1.4        ad 		return (0);
    564   1.4        ad 
    565   1.4        ad 	case WSDISPLAYIO_GETCMAP:
    566   1.7        ad 		return (stic_get_cmap(si, (struct wsdisplay_cmap *)data));
    567   1.4        ad 
    568   1.4        ad 	case WSDISPLAYIO_PUTCMAP:
    569   1.7        ad 		return (stic_set_cmap(si, (struct wsdisplay_cmap *)data));
    570   1.4        ad 
    571   1.4        ad 	case WSDISPLAYIO_SVIDEO:
    572   1.4        ad #if 0 /* XXX later */
    573   1.4        ad 		turnoff = *(int *)data == WSDISPLAYIO_VIDEO_OFF;
    574   1.4        ad 		if ((si->si_blanked == 0) ^ turnoff)
    575   1.4        ad 			si->si_blanked = turnoff;
    576   1.4        ad #endif
    577   1.4        ad 		return (0);
    578   1.4        ad 
    579   1.4        ad 	case WSDISPLAYIO_GVIDEO:
    580   1.4        ad #if 0 /* XXX later */
    581   1.4        ad 		*(u_int *)data = si->si_blanked ?
    582   1.4        ad 		    WSDISPLAYIO_VIDEO_OFF : WSDISPLAYIO_VIDEO_ON;
    583   1.4        ad #endif
    584   1.4        ad 		return (0);
    585   1.4        ad 
    586   1.4        ad 	case WSDISPLAYIO_GCURPOS:
    587   1.7        ad 		*(struct wsdisplay_curpos *)data = si->si_cursor.cc_pos;
    588   1.4        ad 		return (0);
    589   1.4        ad 
    590   1.4        ad 	case WSDISPLAYIO_SCURPOS:
    591   1.7        ad 		stic_set_curpos(si, (struct wsdisplay_curpos *)data);
    592   1.4        ad 		return (0);
    593   1.4        ad 
    594   1.4        ad 	case WSDISPLAYIO_GCURMAX:
    595   1.4        ad 		((struct wsdisplay_curpos *)data)->x =
    596   1.4        ad 		((struct wsdisplay_curpos *)data)->y = CURSOR_MAX_SIZE;
    597   1.4        ad 		return (0);
    598   1.4        ad 
    599   1.4        ad 	case WSDISPLAYIO_GCURSOR:
    600   1.7        ad 		return (stic_get_cursor(si, (struct wsdisplay_cursor *)data));
    601   1.4        ad 
    602   1.4        ad 	case WSDISPLAYIO_SCURSOR:
    603   1.7        ad 		return (stic_set_cursor(si, (struct wsdisplay_cursor *)data));
    604   1.7        ad 
    605   1.8        ad 	case WSDISPLAYIO_SMODE:
    606  1.11        ad 		si->si_dispmode = *(int *)data;
    607  1.11        ad 		if (si->si_dispmode == WSDISPLAYIO_MODE_EMUL) {
    608  1.11        ad 			(*si->si_ioctl)(si, STICIO_STOPQ, NULL, flag, p);
    609   1.8        ad 			stic_setup_vdac(si);
    610   1.8        ad 			stic_flush(si);
    611  1.11        ad 			stic_clear_screen(si);
    612   1.8        ad 			stic_do_switch(si->si_curscreen);
    613   1.8        ad 		}
    614   1.8        ad 		return (0);
    615   1.8        ad 
    616   1.7        ad 	case STICIO_RESET:
    617   1.7        ad 		stic_reset(si);
    618   1.7        ad 		return (0);
    619   1.4        ad 	}
    620   1.4        ad 
    621   1.6        ad 	if (si->si_ioctl != NULL)
    622   1.6        ad 		return ((*si->si_ioctl)(si, cmd, data, flag, p));
    623   1.8        ad 
    624   1.4        ad 	return (ENOTTY);
    625   1.4        ad }
    626   1.4        ad 
    627  1.11        ad void
    628   1.6        ad stic_setup_backing(struct stic_info *si, struct stic_screen *ss)
    629   1.4        ad {
    630   1.4        ad 	int size;
    631   1.4        ad 
    632   1.4        ad 	size = si->si_consw * si->si_consh * sizeof(*ss->ss_backing);
    633   1.6        ad 	ss->ss_backing = malloc(size, M_DEVBUF, M_NOWAIT);
    634   1.4        ad 	memset(ss->ss_backing, 0, size);
    635   1.4        ad }
    636   1.4        ad 
    637  1.11        ad int
    638   1.4        ad stic_alloc_screen(void *v, const struct wsscreen_descr *type, void **cookiep,
    639   1.4        ad 		  int *curxp, int *curyp, long *attrp)
    640   1.4        ad {
    641   1.4        ad 	struct stic_info *si;
    642   1.4        ad 	struct stic_screen *ss;
    643   1.4        ad 
    644   1.4        ad 	si = (struct stic_info *)v;
    645   1.6        ad 
    646   1.6        ad 	if ((stic_consscr.ss_flags & SS_ALLOCED) == 0)
    647   1.4        ad 		ss = &stic_consscr;
    648   1.6        ad 	else {
    649   1.6        ad 		ss = malloc(sizeof(*ss), M_DEVBUF, M_WAITOK);
    650   1.4        ad 		memset(ss, 0, sizeof(*ss));
    651   1.4        ad 	}
    652   1.6        ad 	stic_setup_backing(si, ss);
    653   1.4        ad 
    654   1.4        ad 	ss->ss_si = si;
    655   1.8        ad 	ss->ss_flags = SS_ALLOCED | SS_CURENB;
    656   1.4        ad 
    657   1.4        ad 	*cookiep = ss;
    658   1.4        ad 	*curxp = 0;
    659   1.4        ad 	*curyp = 0;
    660   1.4        ad 
    661   1.8        ad 	stic_alloc_attr(ss, 0, 0, 0, attrp);
    662   1.4        ad 	return (0);
    663   1.4        ad }
    664   1.4        ad 
    665  1.11        ad void
    666   1.4        ad stic_free_screen(void *v, void *cookie)
    667   1.4        ad {
    668   1.4        ad 	struct stic_screen *ss;
    669   1.4        ad 
    670   1.4        ad 	ss = cookie;
    671   1.4        ad 
    672   1.4        ad #ifdef DIAGNOSTIC
    673   1.4        ad 	if (ss == &stic_consscr)
    674   1.4        ad 		panic("stic_free_screen: console");
    675   1.4        ad 	if (ss == ((struct stic_info *)v)->si_curscreen)
    676   1.4        ad 		panic("stic_free_screen: freeing current screen");
    677   1.4        ad #endif
    678   1.4        ad 
    679   1.4        ad 	free(ss->ss_backing, M_DEVBUF);
    680   1.4        ad 	free(ss, M_DEVBUF);
    681   1.4        ad }
    682   1.4        ad 
    683  1.11        ad int
    684   1.4        ad stic_show_screen(void *v, void *cookie, int waitok,
    685   1.4        ad 		 void (*cb)(void *, int, int), void *cbarg)
    686   1.4        ad {
    687   1.4        ad 	struct stic_info *si;
    688   1.4        ad 
    689   1.4        ad 	si = (struct stic_info *)v;
    690   1.4        ad 	if (si->si_switchcbarg != NULL)
    691   1.4        ad 		return (EAGAIN);
    692   1.4        ad 	si->si_switchcb = cb;
    693   1.4        ad 	si->si_switchcbarg = cbarg;
    694   1.4        ad 
    695   1.4        ad 	if (cb != NULL) {
    696   1.4        ad 		callout_reset(&si->si_switch_callout, 0, stic_do_switch,
    697   1.4        ad 		    cookie);
    698   1.4        ad 		return (EAGAIN);
    699   1.4        ad 	}
    700   1.4        ad 
    701   1.4        ad 	stic_do_switch(cookie);
    702   1.4        ad 	return (0);
    703   1.4        ad }
    704   1.4        ad 
    705  1.11        ad void
    706   1.4        ad stic_do_switch(void *cookie)
    707   1.4        ad {
    708   1.4        ad 	struct stic_screen *ss;
    709   1.4        ad 	struct stic_info *si;
    710   1.4        ad 	u_int r, c, nr, nc;
    711   1.4        ad 	u_int16_t *p, *sp;
    712   1.4        ad 
    713   1.4        ad 	ss = cookie;
    714   1.4        ad 	si = ss->ss_si;
    715   1.4        ad 
    716   1.4        ad #ifdef DIAGNOSTIC
    717   1.4        ad 	if (ss->ss_backing == NULL)
    718   1.4        ad 		panic("stic_do_switch: screen not backed");
    719   1.4        ad #endif
    720   1.4        ad 
    721   1.4        ad 	/* Swap in the new screen, and temporarily disable its backing. */
    722  1.11        ad 	if (si->si_curscreen != NULL)
    723  1.11        ad 		si->si_curscreen->ss_flags ^= SS_ACTIVE;
    724   1.4        ad 	si->si_curscreen = ss;
    725   1.4        ad 	ss->ss_flags |= SS_ACTIVE;
    726   1.4        ad 	sp = ss->ss_backing;
    727   1.4        ad 	ss->ss_backing = NULL;
    728   1.4        ad 
    729   1.4        ad 	/*
    730   1.4        ad 	 * We assume that most of the screen is blank and blast it with
    731   1.4        ad 	 * eraserows(), because eraserows() is cheap.
    732   1.4        ad 	 */
    733   1.4        ad 	nr = si->si_consh;
    734   1.4        ad 	stic_eraserows(ss, 0, nr, 0);
    735   1.4        ad 
    736   1.4        ad 	nc = si->si_consw;
    737   1.4        ad 	p = sp;
    738   1.4        ad 	for (r = 0; r < nr; r++)
    739   1.4        ad 		for (c = 0; c < nc; c += 2, p += 2) {
    740   1.4        ad 			if ((p[0] & 0xfff0) != 0)
    741   1.4        ad 				stic_putchar(ss, r, c, p[0] >> 8,
    742   1.4        ad 				    p[0] & 0x00ff);
    743   1.4        ad 			if ((p[1] & 0xfff0) != 0)
    744   1.7        ad 				stic_putchar(ss, r, c + 1, p[1] >> 8,
    745   1.4        ad 				    p[1] & 0x00ff);
    746   1.4        ad 		}
    747   1.4        ad 
    748   1.7        ad 	/*
    749   1.7        ad 	 * Re-enable the screen's backing, and move the cursor to the
    750   1.7        ad 	 * correct spot.
    751   1.7        ad 	 */
    752   1.4        ad 	ss->ss_backing = sp;
    753   1.7        ad 	si->si_cursor.cc_pos.x = ss->ss_curx;
    754   1.7        ad 	si->si_cursor.cc_pos.y = ss->ss_cury;
    755   1.7        ad 	stic_set_hwcurpos(si);
    756   1.8        ad 	si->si_flags |= SI_CURENB_CHANGED;
    757   1.8        ad 
    758   1.8        ad 	/*
    759   1.8        ad 	 * XXX Since we don't yet receive vblank interrupts from the
    760   1.8        ad 	 * PXG, we must flush immediatley.
    761   1.8        ad 	 */
    762   1.8        ad 	if (si->si_disptype == WSDISPLAY_TYPE_PXG)
    763   1.8        ad 		stic_flush(si);
    764   1.4        ad 
    765   1.4        ad 	/* Tell wscons that we're done. */
    766   1.4        ad 	if (si->si_switchcbarg != NULL) {
    767   1.4        ad 		cookie = si->si_switchcbarg;
    768   1.4        ad 		si->si_switchcbarg = NULL;
    769   1.4        ad 		(*si->si_switchcb)(cookie, 0, 0);
    770   1.4        ad 	}
    771   1.4        ad }
    772   1.4        ad 
    773  1.11        ad int
    774   1.4        ad stic_alloc_attr(void *cookie, int fg, int bg, int flags, long *attr)
    775   1.4        ad {
    776   1.4        ad 	long tmp;
    777   1.4        ad 
    778   1.4        ad 	if ((flags & (WSATTR_BLINK | WSATTR_UNDERLINE)) != 0)
    779   1.4        ad 		return (EINVAL);
    780   1.4        ad 
    781   1.8        ad 	if ((flags & WSATTR_WSCOLORS) == 0) {
    782   1.8        ad 		fg = 7;
    783   1.8        ad 		bg = 0;
    784   1.8        ad 	}
    785   1.8        ad 
    786   1.4        ad 	if ((flags & WSATTR_HILIT) != 0)
    787   1.4        ad 		fg += 8;
    788   1.4        ad 
    789   1.4        ad 	tmp = fg | (bg << 4);
    790   1.4        ad 	*attr = tmp | (tmp << 16);
    791   1.4        ad 	return (0);
    792   1.4        ad }
    793   1.4        ad 
    794  1.11        ad void
    795   1.4        ad stic_erasecols(void *cookie, int row, int col, int num, long attr)
    796   1.4        ad {
    797   1.4        ad 	struct stic_info *si;
    798   1.4        ad 	struct stic_screen *ss;
    799   1.4        ad 	u_int32_t *pb;
    800   1.4        ad 	u_int i, linewidth;
    801   1.4        ad 	u_int16_t *p;
    802   1.4        ad 
    803   1.4        ad 	ss = cookie;
    804   1.4        ad 	si = ss->ss_si;
    805   1.4        ad 
    806   1.4        ad 	if (ss->ss_backing != NULL) {
    807   1.4        ad 		p = ss->ss_backing + row * si->si_consw + col;
    808   1.4        ad 		for (i = num; i != 0; i--)
    809   1.4        ad 			*p++ = (u_int16_t)attr;
    810   1.4        ad 	}
    811   1.4        ad 	if ((ss->ss_flags & SS_ACTIVE) == 0)
    812   1.4        ad 		return;
    813   1.4        ad 
    814   1.4        ad 	col = (col * si->si_fontw) << 19;
    815   1.4        ad 	num = (num * si->si_fontw) << 19;
    816   1.4        ad 	row = row * si->si_fonth;
    817   1.4        ad 	attr = (attr & 0xf0) >> 4;
    818   1.8        ad 	linewidth = (si->si_fonth << 2) - 1;
    819   1.8        ad 	row = (row << 3) + linewidth;
    820   1.4        ad 
    821   1.4        ad 	pb = (*si->si_pbuf_get)(si);
    822   1.4        ad 
    823   1.4        ad 	pb[0] = STAMP_CMD_LINES | STAMP_RGB_CONST | STAMP_LW_PERPACKET;
    824   1.4        ad 	pb[1] = 0x01ffffff;
    825   1.4        ad 	pb[2] = 0;
    826   1.4        ad 	pb[3] = STAMP_UPDATE_ENABLE | STAMP_METHOD_COPY;
    827   1.4        ad 	pb[4] = linewidth;
    828   1.4        ad 	pb[5] = DUPBYTE0(attr);
    829   1.4        ad 	pb[6] = col | row;
    830   1.4        ad 	pb[7] = (col + num) | row;
    831   1.4        ad 
    832   1.4        ad 	(*si->si_pbuf_post)(si, pb);
    833   1.4        ad }
    834   1.4        ad 
    835  1.11        ad void
    836   1.4        ad stic_eraserows(void *cookie, int row, int num, long attr)
    837   1.4        ad {
    838   1.4        ad 	struct stic_info *si;
    839   1.4        ad 	struct stic_screen *ss;
    840   1.4        ad 	u_int linewidth, i;
    841   1.4        ad 	u_int32_t *pb;
    842   1.4        ad 
    843   1.4        ad 	ss = cookie;
    844   1.4        ad 	si = ss->ss_si;
    845   1.4        ad 
    846   1.4        ad 	if (ss->ss_backing != NULL) {
    847   1.4        ad 		pb = (u_int32_t *)(ss->ss_backing + row * si->si_consw);
    848   1.6        ad 		for (i = si->si_consw * num; i > 0; i -= 2)
    849   1.4        ad 			*pb++ = (u_int32_t)attr;
    850   1.4        ad 	}
    851   1.4        ad 	if ((ss->ss_flags & SS_ACTIVE) == 0)
    852   1.4        ad 		return;
    853   1.4        ad 
    854   1.4        ad 	row *= si->si_fonth;
    855   1.4        ad 	num *= si->si_fonth;
    856   1.4        ad 	attr = (attr & 0xf0) >> 4;
    857   1.8        ad 	linewidth = (num << 2) - 1;
    858   1.8        ad 	row = (row << 3) + linewidth;
    859   1.4        ad 
    860   1.4        ad 	pb = (*si->si_pbuf_get)(si);
    861   1.4        ad 
    862   1.4        ad 	pb[0] = STAMP_CMD_LINES | STAMP_RGB_CONST | STAMP_LW_PERPACKET;
    863   1.4        ad 	pb[1] = 0x01ffffff;
    864   1.4        ad 	pb[2] = 0;
    865   1.4        ad 	pb[3] = STAMP_UPDATE_ENABLE | STAMP_METHOD_COPY;
    866   1.4        ad 	pb[4] = linewidth;
    867   1.4        ad 	pb[5] = DUPBYTE0(attr);
    868   1.4        ad 	pb[6] = row;
    869   1.4        ad 	pb[7] = (1280 << 19) | row;
    870   1.4        ad 
    871   1.4        ad 	(*si->si_pbuf_post)(si, pb);
    872   1.4        ad }
    873   1.4        ad 
    874  1.11        ad void
    875   1.4        ad stic_copyrows(void *cookie, int src, int dst, int height)
    876   1.4        ad {
    877   1.4        ad 	struct stic_info *si;
    878   1.4        ad 	struct stic_screen *ss;
    879   1.4        ad 	u_int32_t *pb, *pbs;
    880   1.4        ad 	u_int num, inc, adj;
    881   1.4        ad 
    882   1.4        ad 	ss = cookie;
    883   1.4        ad 	si = ss->ss_si;
    884   1.4        ad 
    885   1.4        ad 	if (ss->ss_backing != NULL)
    886   1.4        ad 		bcopy(ss->ss_backing + src * si->si_consw,
    887   1.4        ad 		    ss->ss_backing + dst * si->si_consw,
    888   1.4        ad 		    si->si_consw * sizeof(*ss->ss_backing) * height);
    889   1.4        ad 	if ((ss->ss_flags & SS_ACTIVE) == 0)
    890   1.4        ad 		return;
    891   1.4        ad 
    892   1.4        ad 	/*
    893   1.4        ad 	 * We need to do this in reverse if the destination row is below
    894   1.4        ad 	 * the source.
    895   1.4        ad 	 */
    896   1.4        ad 	if (dst > src) {
    897   1.4        ad 		src += height;
    898   1.4        ad 		dst += height;
    899   1.4        ad 		inc = -8;
    900   1.4        ad 		adj = -1;
    901   1.4        ad 	} else {
    902   1.4        ad 		inc = 8;
    903   1.4        ad 		adj = 0;
    904   1.4        ad 	}
    905   1.4        ad 
    906   1.4        ad 	src = (src * si->si_fonth + adj) << 3;
    907   1.4        ad 	dst = (dst * si->si_fonth + adj) << 3;
    908   1.4        ad 	height *= si->si_fonth;
    909   1.4        ad 
    910   1.4        ad 	while (height > 0) {
    911   1.4        ad 		num = (height < 255 ? height : 255);
    912   1.4        ad 		height -= num;
    913   1.4        ad 
    914   1.4        ad 		pbs = (*si->si_pbuf_get)(si);
    915   1.4        ad 		pb = pbs;
    916   1.4        ad 
    917   1.4        ad 		pb[0] = STAMP_CMD_COPYSPANS | STAMP_LW_PERPACKET;
    918   1.4        ad 		pb[1] = (num << 24) | 0xffffff;
    919   1.4        ad 		pb[2] = 0x0;
    920   1.4        ad 		pb[3] = STAMP_UPDATE_ENABLE | STAMP_METHOD_COPY | STAMP_SPAN |
    921   1.4        ad 		    STAMP_COPYSPAN_ALIGNED;
    922   1.4        ad 		pb[4] = 1; /* linewidth */
    923   1.4        ad 
    924   1.4        ad 		for (; num != 0; num--, src += inc, dst += inc, pb += 3) {
    925   1.4        ad 			pb[5] = 1280 << 3;
    926   1.4        ad 			pb[6] = src;
    927   1.4        ad 			pb[7] = dst;
    928   1.4        ad 		}
    929   1.4        ad 
    930   1.4        ad 	    	(*si->si_pbuf_post)(si, pbs);
    931   1.4        ad 	}
    932   1.4        ad }
    933   1.4        ad 
    934  1.11        ad void
    935   1.4        ad stic_copycols(void *cookie, int row, int src, int dst, int num)
    936   1.4        ad {
    937   1.4        ad 	struct stic_info *si;
    938   1.4        ad 	struct stic_screen *ss;
    939   1.4        ad 	u_int height, updword;
    940   1.4        ad 	u_int32_t *pb, *pbs;
    941   1.4        ad 
    942   1.4        ad 	ss = cookie;
    943   1.4        ad 	si = ss->ss_si;
    944   1.4        ad 
    945   1.4        ad 	if (ss->ss_backing != NULL)
    946   1.4        ad 		bcopy(ss->ss_backing + row * si->si_consw + src,
    947   1.4        ad 		    ss->ss_backing + row * si->si_consw + dst,
    948   1.4        ad 		    num * sizeof(*ss->ss_backing));
    949   1.4        ad 	if ((ss->ss_flags & SS_ACTIVE) == 0)
    950   1.4        ad 		return;
    951   1.4        ad 
    952   1.4        ad 	/*
    953   1.4        ad 	 * The stamp reads and writes left -> right only, so we need to
    954   1.4        ad 	 * buffer the span if the source and destination regions overlap
    955   1.4        ad 	 * and the source is left of the destination.
    956   1.4        ad 	 */
    957   1.4        ad 	updword = STAMP_UPDATE_ENABLE | STAMP_METHOD_COPY | STAMP_SPAN;
    958   1.4        ad 
    959   1.4        ad 	if (src < dst && src + num > dst)
    960   1.4        ad 		updword |= STAMP_HALF_BUFF;
    961   1.4        ad 
    962   1.4        ad 	row = (row * si->si_fonth) << 3;
    963   1.4        ad 	num = (num * si->si_fontw) << 3;
    964   1.4        ad 	src = row | ((src * si->si_fontw) << 19);
    965   1.4        ad 	dst = row | ((dst * si->si_fontw) << 19);
    966   1.4        ad 	height = si->si_fonth;
    967   1.4        ad 
    968   1.4        ad 	pbs = (*si->si_pbuf_get)(si);
    969   1.4        ad 	pb = pbs;
    970   1.4        ad 
    971   1.4        ad 	pb[0] = STAMP_CMD_COPYSPANS | STAMP_LW_PERPACKET;
    972   1.4        ad 	pb[1] = (height << 24) | 0xffffff;
    973   1.4        ad 	pb[2] = 0x0;
    974   1.4        ad 	pb[3] = updword;
    975   1.4        ad 	pb[4] = 1; /* linewidth */
    976   1.4        ad 
    977   1.4        ad 	for ( ; height != 0; height--, src += 8, dst += 8, pb += 3) {
    978   1.4        ad 		pb[5] = num;
    979   1.4        ad 		pb[6] = src;
    980   1.4        ad 		pb[7] = dst;
    981   1.4        ad 	}
    982   1.4        ad 
    983   1.4        ad 	(*si->si_pbuf_post)(si, pbs);
    984   1.4        ad }
    985   1.4        ad 
    986  1.11        ad void
    987   1.4        ad stic_putchar(void *cookie, int r, int c, u_int uc, long attr)
    988   1.4        ad {
    989   1.4        ad 	struct wsdisplay_font *font;
    990   1.4        ad 	struct stic_screen *ss;
    991   1.4        ad 	struct stic_info *si;
    992   1.4        ad 	u_int i, bgcolor, fgcolor;
    993   1.4        ad 	u_int *pb, v1, v2, xya;
    994   1.4        ad 	u_short *fr;
    995   1.4        ad 
    996   1.4        ad 	ss = cookie;
    997   1.4        ad 	si = ss->ss_si;
    998   1.4        ad 
    999   1.4        ad 	/* It's cheaper to use erasecols() to blit blanks. */
   1000   1.4        ad 	if (uc == 0) {
   1001   1.4        ad 		stic_erasecols(cookie, r, c, 1, attr);
   1002   1.4        ad 		return;
   1003   1.4        ad 	}
   1004   1.4        ad 
   1005   1.4        ad 	if (ss->ss_backing != NULL)
   1006   1.4        ad 		ss->ss_backing[r * si->si_consw + c] =
   1007   1.8        ad 		    (u_short)((attr & 0xff) | (uc << 8));
   1008   1.4        ad 	if ((ss->ss_flags & SS_ACTIVE) == 0)
   1009   1.4        ad 		return;
   1010   1.4        ad 
   1011   1.4        ad 	font = si->si_font;
   1012   1.4        ad 	pb = (*si->si_pbuf_get)(si);
   1013   1.4        ad 
   1014   1.4        ad 	/*
   1015   1.4        ad 	 * Create a mask from the glyph.  Squeeze the foreground color
   1016   1.4        ad 	 * through the mask, and then squeeze the background color through
   1017   1.4        ad 	 * the inverted mask.  We may well read outside the glyph when
   1018   1.4        ad 	 * creating the mask, but it's bounded by the hardware so it
   1019   1.4        ad 	 * shouldn't matter a great deal...
   1020   1.4        ad 	 */
   1021   1.4        ad 	pb[0] = STAMP_CMD_LINES | STAMP_RGB_FLAT | STAMP_XY_PERPRIMATIVE |
   1022   1.4        ad 	    STAMP_LW_PERPRIMATIVE;
   1023   1.4        ad 	pb[1] = font->fontheight > 16 ? 0x04ffffff : 0x02ffffff;
   1024   1.4        ad 	pb[2] = 0x0;
   1025   1.4        ad 	pb[3] = STAMP_UPDATE_ENABLE | STAMP_WE_XYMASK | STAMP_METHOD_COPY;
   1026   1.4        ad 
   1027   1.4        ad 	r *= font->fontheight;
   1028   1.4        ad 	c *= font->fontwidth;
   1029   1.4        ad 	uc = (uc - font->firstchar) * font->stride * font->fontheight;
   1030   1.4        ad 	fr = (u_short *)((caddr_t)font->data + uc);
   1031   1.8        ad 	bgcolor = DUPBYTE0((attr & 0xf0) >> 4);
   1032   1.4        ad 	fgcolor = DUPBYTE0(attr & 0x0f);
   1033   1.4        ad 
   1034   1.4        ad 	i = ((font->fontheight > 16 ? 16 : font->fontheight) << 2) - 1;
   1035   1.4        ad 	v1 = (c << 19) | ((r << 3) + i);
   1036   1.4        ad 	v2 = ((c + font->fontwidth) << 19) | (v1 & 0xffff);
   1037   1.4        ad 	xya = XYMASKADDR(si->si_stampw, si->si_stamph, c, r, 0, 0);
   1038   1.4        ad 
   1039   1.4        ad 	pb[4] = PACK(fr, 0);
   1040   1.4        ad 	pb[5] = PACK(fr, 2);
   1041   1.4        ad 	pb[6] = PACK(fr, 4);
   1042   1.4        ad 	pb[7] = PACK(fr, 6);
   1043   1.4        ad 	pb[8] = PACK(fr, 8);
   1044   1.4        ad 	pb[9] = PACK(fr, 10);
   1045   1.4        ad 	pb[10] = PACK(fr, 12);
   1046   1.4        ad 	pb[11] = PACK(fr, 14);
   1047   1.4        ad 	pb[12] = xya;
   1048   1.4        ad 	pb[13] = v1;
   1049   1.4        ad 	pb[14] = v2;
   1050   1.4        ad 	pb[15] = i;
   1051   1.4        ad 	pb[16] = fgcolor;
   1052   1.4        ad 
   1053   1.4        ad 	pb[17] = ~pb[4];
   1054   1.4        ad 	pb[18] = ~pb[5];
   1055   1.4        ad 	pb[19] = ~pb[6];
   1056   1.4        ad 	pb[20] = ~pb[7];
   1057   1.4        ad 	pb[21] = ~pb[8];
   1058   1.4        ad 	pb[22] = ~pb[9];
   1059   1.4        ad 	pb[23] = ~pb[10];
   1060   1.4        ad 	pb[24] = ~pb[11];
   1061   1.4        ad 	pb[25] = xya;
   1062   1.4        ad 	pb[26] = v1;
   1063   1.4        ad 	pb[27] = v2;
   1064   1.4        ad 	pb[28] = i;
   1065   1.4        ad 	pb[29] = bgcolor;
   1066   1.4        ad 
   1067   1.4        ad 	/* Two more squeezes for the lower part of the character. */
   1068   1.4        ad 	if (font->fontheight > 16) {
   1069   1.4        ad 		i = ((font->fontheight - 16) << 2) - 1;
   1070   1.4        ad 		r += 16;
   1071   1.4        ad 		v1 = (c << 19) | ((r << 3) + i);
   1072   1.4        ad 		v2 = ((c + font->fontwidth) << 19) | (v1 & 0xffff);
   1073   1.4        ad 
   1074   1.4        ad 		pb[30] = PACK(fr, 16);
   1075   1.4        ad 		pb[31] = PACK(fr, 18);
   1076   1.4        ad 		pb[32] = PACK(fr, 20);
   1077   1.4        ad 		pb[33] = PACK(fr, 22);
   1078   1.4        ad 		pb[34] = PACK(fr, 24);
   1079   1.4        ad 		pb[35] = PACK(fr, 26);
   1080   1.4        ad 		pb[36] = PACK(fr, 28);
   1081   1.4        ad 		pb[37] = PACK(fr, 30);
   1082   1.4        ad 		pb[38] = xya;
   1083   1.4        ad 		pb[39] = v1;
   1084   1.4        ad 		pb[40] = v2;
   1085   1.4        ad 		pb[41] = i;
   1086   1.4        ad 		pb[42] = fgcolor;
   1087   1.4        ad 
   1088   1.4        ad 		pb[43] = ~pb[30];
   1089   1.4        ad 		pb[44] = ~pb[31];
   1090   1.4        ad 		pb[45] = ~pb[32];
   1091   1.4        ad 		pb[46] = ~pb[33];
   1092   1.4        ad 		pb[47] = ~pb[34];
   1093   1.4        ad 		pb[48] = ~pb[35];
   1094   1.4        ad 		pb[49] = ~pb[36];
   1095   1.4        ad 		pb[50] = ~pb[37];
   1096   1.4        ad 		pb[51] = xya;
   1097   1.4        ad 		pb[52] = v1;
   1098   1.4        ad 		pb[53] = v2;
   1099   1.4        ad 		pb[54] = i;
   1100   1.4        ad 		pb[55] = bgcolor;
   1101   1.4        ad 	}
   1102   1.4        ad 
   1103   1.4        ad 	(*si->si_pbuf_post)(si, pb);
   1104   1.4        ad }
   1105   1.4        ad 
   1106  1.11        ad int
   1107   1.4        ad stic_mapchar(void *cookie, int c, u_int *cp)
   1108   1.4        ad {
   1109   1.4        ad 	struct stic_info *si;
   1110   1.4        ad 
   1111   1.4        ad 	si = ((struct stic_screen *)cookie)->ss_si;
   1112   1.4        ad 
   1113   1.4        ad 	if (c < si->si_font->firstchar || c == ' ') {
   1114   1.4        ad 		*cp = 0;
   1115   1.4        ad 		return (0);
   1116   1.4        ad 	}
   1117   1.4        ad 
   1118   1.4        ad 	if (c - si->si_font->firstchar >= si->si_font->numchars) {
   1119   1.4        ad 		*cp = 0;
   1120   1.4        ad 		return (0);
   1121   1.4        ad 	}
   1122   1.4        ad 
   1123   1.4        ad 	*cp = c;
   1124   1.4        ad 	return (5);
   1125   1.4        ad }
   1126   1.4        ad 
   1127  1.11        ad void
   1128   1.4        ad stic_cursor(void *cookie, int on, int row, int col)
   1129   1.4        ad {
   1130   1.4        ad 	struct stic_screen *ss;
   1131   1.7        ad 	struct stic_info *si;
   1132  1.11        ad 	int s;
   1133   1.4        ad 
   1134   1.4        ad 	ss = cookie;
   1135   1.7        ad 	si = ss->ss_si;
   1136   1.4        ad 
   1137   1.7        ad 	ss->ss_curx = col * si->si_fontw;
   1138   1.7        ad 	ss->ss_cury = row * si->si_fonth;
   1139   1.7        ad 
   1140  1.11        ad 	s = spltty();
   1141  1.11        ad 
   1142   1.8        ad 	if (on)
   1143   1.8        ad 		ss->ss_flags |= SS_CURENB;
   1144   1.8        ad 	else
   1145   1.8        ad 		ss->ss_flags &= ~SS_CURENB;
   1146   1.8        ad 
   1147   1.7        ad 	if ((ss->ss_flags & SS_ACTIVE) != 0) {
   1148   1.7        ad 		si->si_cursor.cc_pos.x = ss->ss_curx;
   1149   1.7        ad 		si->si_cursor.cc_pos.y = ss->ss_cury;
   1150   1.8        ad 		si->si_flags |= SI_CURENB_CHANGED;
   1151   1.7        ad 		stic_set_hwcurpos(si);
   1152   1.8        ad 
   1153   1.8        ad 		/*
   1154   1.8        ad 		 * XXX Since we don't yet receive vblank interrupts from the
   1155   1.8        ad 		 * PXG, we must flush immediatley.
   1156   1.8        ad 		 */
   1157   1.8        ad 		if (si->si_disptype == WSDISPLAY_TYPE_PXG)
   1158   1.8        ad 			stic_flush(si);
   1159   1.7        ad 	}
   1160  1.11        ad 
   1161  1.11        ad 	splx(s);
   1162   1.4        ad }
   1163   1.4        ad 
   1164   1.4        ad void
   1165   1.4        ad stic_flush(struct stic_info *si)
   1166   1.4        ad {
   1167   1.4        ad 	volatile u_int32_t *vdac;
   1168   1.4        ad 	int v;
   1169   1.4        ad 
   1170   1.7        ad 	if ((si->si_flags & SI_ALL_CHANGED) == 0)
   1171   1.4        ad 		return;
   1172   1.4        ad 
   1173   1.4        ad 	vdac = si->si_vdac;
   1174   1.7        ad 	v = si->si_flags;
   1175   1.7        ad 	si->si_flags &= ~SI_ALL_CHANGED;
   1176   1.4        ad 
   1177   1.7        ad 	if ((v & SI_CURENB_CHANGED) != 0) {
   1178   1.4        ad 		SELECT(vdac, BT459_IREG_CCR);
   1179   1.8        ad 		if ((si->si_curscreen->ss_flags & SS_CURENB) != 0)
   1180   1.7        ad 			REG(vdac, bt_reg) = 0x00c0c0c0;
   1181   1.7        ad 		else
   1182   1.4        ad 			REG(vdac, bt_reg) = 0x00000000;
   1183   1.4        ad 		tc_wmb();
   1184   1.4        ad 	}
   1185   1.1  jonathan 
   1186   1.7        ad 	if ((v & SI_CURCMAP_CHANGED) != 0) {
   1187   1.4        ad 		u_int8_t *cp;
   1188   1.7        ad 
   1189   1.7        ad 		cp = si->si_cursor.cc_color;
   1190   1.4        ad 
   1191   1.4        ad 		SELECT(vdac, BT459_IREG_CCOLOR_2);
   1192   1.7        ad 		REG(vdac, bt_reg) = DUPBYTE0(cp[1]);	tc_wmb();
   1193   1.7        ad 		REG(vdac, bt_reg) = DUPBYTE0(cp[3]);	tc_wmb();
   1194   1.7        ad 		REG(vdac, bt_reg) = DUPBYTE0(cp[5]);	tc_wmb();
   1195   1.7        ad 		REG(vdac, bt_reg) = DUPBYTE0(cp[0]);	tc_wmb();
   1196   1.7        ad 		REG(vdac, bt_reg) = DUPBYTE0(cp[2]);	tc_wmb();
   1197   1.7        ad 		REG(vdac, bt_reg) = DUPBYTE0(cp[4]);	tc_wmb();
   1198   1.4        ad 	}
   1199   1.1  jonathan 
   1200   1.7        ad 	if ((v & SI_CURSHAPE_CHANGED) != 0) {
   1201   1.4        ad 		u_int8_t *ip, *mp, img, msk;
   1202   1.4        ad 		u_int8_t u;
   1203   1.4        ad 		int bcnt;
   1204   1.4        ad 
   1205   1.7        ad 		ip = (u_int8_t *)si->si_cursor.cc_image;
   1206   1.7        ad 		mp = (u_int8_t *)(si->si_cursor.cc_image + CURSOR_MAX_SIZE);
   1207   1.4        ad 
   1208   1.4        ad 		bcnt = 0;
   1209  1.11        ad 		SELECT(vdac, BT459_IREG_CRAM_BASE);
   1210   1.4        ad 		/* 64 pixel scan line is consisted with 16 byte cursor ram */
   1211   1.4        ad 		while (bcnt < CURSOR_MAX_SIZE * 16) {
   1212  1.11        ad 			img = *ip++;
   1213  1.11        ad 			msk = *mp++;
   1214  1.11        ad 			img &= msk;	/* cookie off image */
   1215  1.11        ad 			u = (msk & 0x0f) << 4 | (img & 0x0f);
   1216  1.11        ad 			REG(vdac, bt_reg) = DUPBYTE0(shuffle[u]);
   1217  1.11        ad 			tc_wmb();
   1218  1.11        ad 			u = (msk & 0xf0) | (img & 0xf0) >> 4;
   1219  1.11        ad 			REG(vdac, bt_reg) = DUPBYTE0(shuffle[u]);
   1220  1.11        ad 			tc_wmb();
   1221   1.4        ad 			bcnt += 2;
   1222   1.4        ad 		}
   1223   1.4        ad 	}
   1224   1.4        ad 
   1225   1.7        ad 	if ((v & SI_CMAP_CHANGED) != 0) {
   1226   1.4        ad 		struct stic_hwcmap256 *cm;
   1227   1.4        ad 		int index;
   1228   1.4        ad 
   1229   1.7        ad 		cm = &si->si_cmap;
   1230   1.4        ad 
   1231   1.4        ad 		SELECT(vdac, 0);
   1232   1.4        ad 		SELECT(vdac, 0);
   1233   1.7        ad 		for (index = 0; index < CMAP_SIZE; index++) {
   1234   1.7        ad 			REG(vdac, bt_cmap) = DUPBYTE0(cm->r[index]);
   1235   1.7        ad 			tc_wmb();
   1236   1.7        ad 			REG(vdac, bt_cmap) = DUPBYTE0(cm->g[index]);
   1237   1.7        ad 			tc_wmb();
   1238   1.7        ad 			REG(vdac, bt_cmap) = DUPBYTE0(cm->b[index]);
   1239   1.7        ad 			tc_wmb();
   1240   1.1  jonathan 		}
   1241   1.1  jonathan 	}
   1242   1.4        ad }
   1243   1.4        ad 
   1244  1.11        ad int
   1245   1.7        ad stic_get_cmap(struct stic_info *si, struct wsdisplay_cmap *p)
   1246   1.4        ad {
   1247   1.4        ad 	u_int index, count;
   1248   1.4        ad 
   1249   1.4        ad 	index = p->index;
   1250   1.4        ad 	count = p->count;
   1251   1.4        ad 
   1252   1.4        ad 	if (index >= CMAP_SIZE || (index + count) > CMAP_SIZE)
   1253   1.4        ad 		return (EINVAL);
   1254   1.4        ad 
   1255   1.4        ad 	if (!uvm_useracc(p->red, count, B_WRITE) ||
   1256   1.4        ad 	    !uvm_useracc(p->green, count, B_WRITE) ||
   1257   1.4        ad 	    !uvm_useracc(p->blue, count, B_WRITE))
   1258   1.4        ad 		return (EFAULT);
   1259   1.4        ad 
   1260   1.7        ad 	copyout(&si->si_cmap.r[index], p->red, count);
   1261   1.7        ad 	copyout(&si->si_cmap.g[index], p->green, count);
   1262   1.7        ad 	copyout(&si->si_cmap.b[index], p->blue, count);
   1263   1.4        ad 	return (0);
   1264   1.4        ad }
   1265   1.4        ad 
   1266  1.11        ad int
   1267   1.7        ad stic_set_cmap(struct stic_info *si, struct wsdisplay_cmap *p)
   1268   1.4        ad {
   1269   1.4        ad 	u_int index, count;
   1270  1.11        ad 	int s;
   1271   1.4        ad 
   1272   1.4        ad 	index = p->index;
   1273   1.4        ad 	count = p->count;
   1274   1.4        ad 
   1275   1.7        ad 	if ((index + count) > CMAP_SIZE)
   1276   1.4        ad 		return (EINVAL);
   1277   1.4        ad 
   1278   1.4        ad 	if (!uvm_useracc(p->red, count, B_READ) ||
   1279   1.4        ad 	    !uvm_useracc(p->green, count, B_READ) ||
   1280   1.4        ad 	    !uvm_useracc(p->blue, count, B_READ))
   1281   1.4        ad 		return (EFAULT);
   1282   1.4        ad 
   1283  1.11        ad 	s = spltty();
   1284   1.7        ad 	copyin(p->red, &si->si_cmap.r[index], count);
   1285   1.7        ad 	copyin(p->green, &si->si_cmap.g[index], count);
   1286   1.7        ad 	copyin(p->blue, &si->si_cmap.b[index], count);
   1287   1.7        ad 	si->si_flags |= SI_CMAP_CHANGED;
   1288  1.11        ad 	splx(s);
   1289   1.4        ad 
   1290   1.4        ad 	/*
   1291   1.4        ad 	 * XXX Since we don't yet receive vblank interrupts from the PXG, we
   1292   1.4        ad 	 * must flush immediatley.
   1293   1.4        ad 	 */
   1294   1.7        ad 	if (si->si_disptype == WSDISPLAY_TYPE_PXG)
   1295   1.7        ad 		stic_flush(si);
   1296   1.4        ad 
   1297   1.4        ad 	return (0);
   1298   1.4        ad }
   1299   1.4        ad 
   1300  1.11        ad int
   1301   1.7        ad stic_set_cursor(struct stic_info *si, struct wsdisplay_cursor *p)
   1302   1.4        ad {
   1303   1.7        ad #define	cc (&si->si_cursor)
   1304   1.9  jdolecek 	u_int v, index, count, icount;
   1305   1.8        ad 	struct stic_screen *ss;
   1306  1.11        ad 	int s;
   1307   1.4        ad 
   1308   1.4        ad 	v = p->which;
   1309   1.8        ad 	ss = si->si_curscreen;
   1310   1.4        ad 
   1311   1.4        ad 	if ((v & WSDISPLAY_CURSOR_DOCMAP) != 0) {
   1312   1.4        ad 		index = p->cmap.index;
   1313   1.4        ad 		count = p->cmap.count;
   1314  1.11        ad 		if (index >= 2 || (index + count) > 2)
   1315   1.4        ad 			return (EINVAL);
   1316   1.4        ad 		if (!uvm_useracc(p->cmap.red, count, B_READ) ||
   1317   1.4        ad 		    !uvm_useracc(p->cmap.green, count, B_READ) ||
   1318   1.4        ad 		    !uvm_useracc(p->cmap.blue, count, B_READ))
   1319   1.4        ad 			return (EFAULT);
   1320   1.4        ad 	}
   1321   1.4        ad 
   1322   1.4        ad 	if ((v & WSDISPLAY_CURSOR_DOSHAPE) != 0) {
   1323   1.4        ad 		if (p->size.x > CURSOR_MAX_SIZE || p->size.y > CURSOR_MAX_SIZE)
   1324   1.4        ad 			return (EINVAL);
   1325   1.4        ad 		icount = ((p->size.x < 33) ? 4 : 8) * p->size.y;
   1326   1.4        ad 		if (!uvm_useracc(p->image, icount, B_READ) ||
   1327   1.4        ad 		    !uvm_useracc(p->mask, icount, B_READ))
   1328   1.4        ad 			return (EFAULT);
   1329   1.4        ad 	}
   1330   1.4        ad 
   1331   1.4        ad 	if ((v & (WSDISPLAY_CURSOR_DOPOS | WSDISPLAY_CURSOR_DOCUR)) != 0) {
   1332   1.4        ad 		if (v & WSDISPLAY_CURSOR_DOCUR)
   1333   1.4        ad 			cc->cc_hot = p->hot;
   1334   1.4        ad 		if (v & WSDISPLAY_CURSOR_DOPOS)
   1335   1.7        ad 			stic_set_curpos(si, &p->pos);
   1336   1.4        ad 	}
   1337   1.4        ad 
   1338  1.11        ad 	s = spltty();
   1339  1.11        ad 
   1340   1.4        ad 	if ((v & WSDISPLAY_CURSOR_DOCUR) != 0) {
   1341   1.4        ad 		if (p->enable)
   1342   1.8        ad 			ss->ss_flags |= SS_CURENB;
   1343   1.4        ad 		else
   1344   1.8        ad 			ss->ss_flags &= ~SS_CURENB;
   1345   1.7        ad 		si->si_flags |= SI_CURENB_CHANGED;
   1346   1.4        ad 	}
   1347   1.4        ad 
   1348   1.4        ad 	if ((v & WSDISPLAY_CURSOR_DOCMAP) != 0) {
   1349   1.4        ad 		copyin(p->cmap.red, &cc->cc_color[index], count);
   1350   1.4        ad 		copyin(p->cmap.green, &cc->cc_color[index + 2], count);
   1351   1.4        ad 		copyin(p->cmap.blue, &cc->cc_color[index + 4], count);
   1352   1.7        ad 		si->si_flags |= SI_CURCMAP_CHANGED;
   1353   1.4        ad 	}
   1354   1.1  jonathan 
   1355   1.4        ad 	if ((v & WSDISPLAY_CURSOR_DOSHAPE) != 0) {
   1356  1.11        ad 		memset(cc->cc_image, 0, sizeof(cc->cc_image));
   1357   1.4        ad 		copyin(p->image, cc->cc_image, icount);
   1358  1.11        ad 		copyin(p->mask, cc->cc_image + CURSOR_MAX_SIZE, icount);
   1359   1.7        ad 		si->si_flags |= SI_CURSHAPE_CHANGED;
   1360   1.4        ad 	}
   1361   1.4        ad 
   1362  1.11        ad 	splx(s);
   1363  1.11        ad 
   1364   1.4        ad 	/*
   1365   1.4        ad 	 * XXX Since we don't yet receive vblank interrupts from the PXG, we
   1366   1.4        ad 	 * must flush immediatley.
   1367   1.4        ad 	 */
   1368   1.7        ad 	if (si->si_disptype == WSDISPLAY_TYPE_PXG)
   1369   1.7        ad 		stic_flush(si);
   1370   1.4        ad 
   1371   1.4        ad 	return (0);
   1372   1.4        ad #undef cc
   1373   1.4        ad }
   1374   1.4        ad 
   1375  1.11        ad int
   1376   1.7        ad stic_get_cursor(struct stic_info *si, struct wsdisplay_cursor *p)
   1377   1.4        ad {
   1378   1.4        ad 
   1379   1.7        ad 	/* XXX */
   1380   1.4        ad 	return (ENOTTY);
   1381   1.4        ad }
   1382   1.4        ad 
   1383  1.11        ad void
   1384   1.7        ad stic_set_curpos(struct stic_info *si, struct wsdisplay_curpos *curpos)
   1385   1.4        ad {
   1386   1.4        ad 	int x, y;
   1387   1.4        ad 
   1388   1.4        ad 	x = curpos->x;
   1389   1.4        ad 	y = curpos->y;
   1390   1.4        ad 
   1391   1.4        ad 	if (y < 0)
   1392   1.4        ad 		y = 0;
   1393   1.4        ad 	else if (y > 1023)
   1394   1.4        ad 		y = 1023;
   1395   1.4        ad 	if (x < 0)
   1396   1.4        ad 		x = 0;
   1397   1.4        ad 	else if (x > 1279)
   1398   1.4        ad 		x = 1279;
   1399   1.4        ad 
   1400   1.7        ad 	si->si_cursor.cc_pos.x = x;
   1401   1.7        ad 	si->si_cursor.cc_pos.y = y;
   1402   1.7        ad 	stic_set_hwcurpos(si);
   1403   1.4        ad }
   1404   1.4        ad 
   1405  1.11        ad void
   1406   1.7        ad stic_set_hwcurpos(struct stic_info *si)
   1407   1.4        ad {
   1408   1.4        ad 	volatile u_int32_t *vdac;
   1409   1.4        ad 	int x, y, s;
   1410   1.4        ad 
   1411   1.4        ad 	vdac = si->si_vdac;
   1412   1.4        ad 
   1413   1.7        ad 	x = si->si_cursor.cc_pos.x - si->si_cursor.cc_hot.x;
   1414   1.7        ad 	y = si->si_cursor.cc_pos.y - si->si_cursor.cc_hot.y;
   1415   1.4        ad 	x += STIC_MAGIC_X;
   1416   1.4        ad 	y += STIC_MAGIC_Y;
   1417   1.4        ad 
   1418   1.4        ad 	s = spltty();
   1419   1.4        ad 	SELECT(vdac, BT459_IREG_CURSOR_X_LOW);
   1420   1.4        ad 	REG(vdac, bt_reg) = DUPBYTE0(x); tc_wmb();
   1421   1.4        ad 	REG(vdac, bt_reg) = DUPBYTE1(x); tc_wmb();
   1422   1.4        ad 	REG(vdac, bt_reg) = DUPBYTE0(y); tc_wmb();
   1423   1.4        ad 	REG(vdac, bt_reg) = DUPBYTE1(y); tc_wmb();
   1424   1.4        ad 	splx(s);
   1425  1.11        ad }
   1426  1.11        ad 
   1427  1.11        ad /*
   1428  1.11        ad  * STIC control inteface.  We have a seperate device for mapping the board,
   1429  1.11        ad  * because access to the DMA engine means that it's possible to circumvent
   1430  1.11        ad  * the securelevel mechanism.  Given the way devices work in the BSD kernel,
   1431  1.11        ad  * and given the unfortunate design of the mmap() call it's near impossible
   1432  1.11        ad  * to protect against this using a shared device (i.e. wsdisplay).
   1433  1.11        ad  *
   1434  1.11        ad  * This is a gross hack... Hopefully not too many other devices will need
   1435  1.11        ad  * it.
   1436  1.11        ad  */
   1437  1.11        ad int
   1438  1.11        ad sticopen(dev_t dev, int flag, int mode, struct proc *p)
   1439  1.11        ad {
   1440  1.11        ad 	struct stic_info *si;
   1441  1.11        ad 	int s;
   1442  1.11        ad 
   1443  1.11        ad 	if (securelevel > 0)
   1444  1.11        ad 		return (EPERM);
   1445  1.11        ad 	if (minor(dev) >= STIC_MAXDV)
   1446  1.11        ad 		return (ENXIO);
   1447  1.11        ad 	if ((si = stic_info[minor(dev)]) == NULL)
   1448  1.11        ad 		return (ENXIO);
   1449  1.11        ad 
   1450  1.11        ad 	s = spltty();
   1451  1.11        ad 	if ((si->si_flags & SI_DVOPEN) != 0) {
   1452  1.11        ad 		splx(s);
   1453  1.11        ad 		return (EBUSY);
   1454  1.11        ad 	}
   1455  1.11        ad 	si->si_flags |= SI_DVOPEN;
   1456  1.11        ad 	splx(s);
   1457  1.11        ad 
   1458  1.11        ad 	return (0);
   1459  1.11        ad }
   1460  1.11        ad 
   1461  1.11        ad int
   1462  1.11        ad sticclose(dev_t dev, int flag, int mode, struct proc *p)
   1463  1.11        ad {
   1464  1.11        ad 	struct stic_info *si;
   1465  1.11        ad 	int s;
   1466  1.11        ad 
   1467  1.11        ad 	si = stic_info[minor(dev)];
   1468  1.11        ad 	s = spltty();
   1469  1.11        ad 	si->si_flags &= ~SI_DVOPEN;
   1470  1.11        ad 	splx(s);
   1471  1.11        ad 
   1472  1.11        ad 	return (0);
   1473  1.11        ad }
   1474  1.11        ad 
   1475  1.11        ad paddr_t
   1476  1.11        ad sticmmap(dev_t dev, off_t offset, int prot)
   1477  1.11        ad {
   1478  1.11        ad 	struct stic_info *si;
   1479  1.11        ad 	struct stic_xmap *sxm;
   1480  1.11        ad 	paddr_t pa;
   1481  1.11        ad 
   1482  1.11        ad 	si = stic_info[minor(dev)];
   1483  1.11        ad 	sxm = NULL;
   1484  1.11        ad 
   1485  1.11        ad 	if (securelevel > 0)
   1486  1.11        ad 		return (-1L);
   1487  1.11        ad 	if (si->si_dispmode != WSDISPLAYIO_MODE_MAPPED)
   1488  1.11        ad 		return (-1L);
   1489  1.11        ad 
   1490  1.11        ad 	if (offset < 0)
   1491  1.11        ad 		return ((paddr_t)-1L);
   1492  1.11        ad 
   1493  1.11        ad 	if (offset < sizeof(sxm->sxm_stic)) {
   1494  1.11        ad 		pa = STIC_KSEG_TO_PHYS(si->si_stic);
   1495  1.11        ad 		return (machine_btop(pa + offset));
   1496  1.11        ad 	}
   1497  1.11        ad 	offset -= sizeof(sxm->sxm_stic);
   1498  1.11        ad 
   1499  1.11        ad 	if (offset < sizeof(sxm->sxm_poll)) {
   1500  1.11        ad 		pa = STIC_KSEG_TO_PHYS(si->si_slotbase);
   1501  1.11        ad 		return (machine_btop(pa + offset));
   1502  1.11        ad 	}
   1503  1.11        ad 	offset -= sizeof(sxm->sxm_poll);
   1504  1.11        ad 
   1505  1.11        ad 	if (offset < si->si_buf_size)
   1506  1.11        ad 		return (machine_btop(si->si_buf_phys + offset));
   1507  1.11        ad 
   1508  1.11        ad 	return ((paddr_t)-1L);
   1509   1.1  jonathan }
   1510