Home | History | Annotate | Line # | Download | only in vsa
lcg.c revision 1.3
      1  1.3  dholland /*	$NetBSD: lcg.c,v 1.3 2018/02/08 09:05:18 dholland Exp $ */
      2  1.1     jklos /*
      3  1.1     jklos  * LCG accelerated framebuffer driver
      4  1.1     jklos  * Copyright (c) 2003, 2004 Blaz Antonic
      5  1.1     jklos  * All rights reserved.
      6  1.1     jklos  *
      7  1.1     jklos  * Redistribution and use in source and binary forms, with or without
      8  1.1     jklos  * modification, are permitted provided that the following conditions
      9  1.1     jklos  * are met:
     10  1.1     jklos  * 1. Redistributions of source code must retain the above copyright
     11  1.1     jklos  *    notice, this list of conditions and the following disclaimer.
     12  1.1     jklos  * 2. Redistributions in binary form must reproduce the above copyright
     13  1.1     jklos  *    notice, this list of conditions and the following disclaimer in the
     14  1.1     jklos  *    documentation and/or other materials provided with the distribution.
     15  1.1     jklos  * 3. All advertising materials mentioning features or use of this software
     16  1.1     jklos  *    must display the abovementioned copyrights
     17  1.1     jklos  * 4. The name of the author may not be used to endorse or promote products
     18  1.1     jklos  *    derived from this software without specific prior written permission
     19  1.1     jklos  *
     20  1.1     jklos  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     21  1.1     jklos  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     22  1.1     jklos  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     23  1.1     jklos  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     24  1.1     jklos  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     25  1.1     jklos  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     26  1.1     jklos  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     27  1.1     jklos  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     28  1.1     jklos  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     29  1.1     jklos  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     30  1.1     jklos  */
     31  1.1     jklos /*
     32  1.1     jklos  * Resurrection and dumb framebuffer mode by Bjrn Johannesson
     33  1.1     jklos  * rherdware (at) yahoo.com in December 2014
     34  1.1     jklos  */
     35  1.1     jklos 
     36  1.1     jklos #include <sys/cdefs.h>
     37  1.3  dholland __KERNEL_RCSID(0, "$NetBSD: lcg.c,v 1.3 2018/02/08 09:05:18 dholland Exp $");
     38  1.1     jklos 
     39  1.1     jklos #define LCG_NO_ACCEL
     40  1.1     jklos 
     41  1.1     jklos #include <sys/param.h>
     42  1.1     jklos #include <sys/device.h>
     43  1.1     jklos #include <sys/systm.h>
     44  1.1     jklos #include <sys/callout.h>
     45  1.1     jklos #include <sys/time.h>
     46  1.1     jklos #include <sys/malloc.h>
     47  1.1     jklos #include <sys/conf.h>
     48  1.1     jklos #include <sys/kernel.h>
     49  1.1     jklos #include <sys/systm.h>
     50  1.1     jklos 
     51  1.1     jklos #include <machine/vsbus.h>
     52  1.1     jklos #include <machine/sid.h>
     53  1.1     jklos #include <machine/cpu.h>
     54  1.1     jklos #include <machine/lcgreg.h>
     55  1.1     jklos 
     56  1.1     jklos #include <dev/cons.h>
     57  1.1     jklos 
     58  1.1     jklos #include <dev/dec/dzreg.h>
     59  1.1     jklos #include <dev/dec/dzvar.h>
     60  1.1     jklos #include <dev/dec/dzkbdvar.h>
     61  1.1     jklos 
     62  1.1     jklos #include <dev/wscons/wsdisplayvar.h>
     63  1.1     jklos #include <dev/wscons/wsconsio.h>
     64  1.1     jklos #include <dev/wscons/wscons_callbacks.h>
     65  1.1     jklos #include <dev/wsfont/wsfont.h>
     66  1.1     jklos 
     67  1.1     jklos #include "machine/scb.h"
     68  1.1     jklos 
     69  1.1     jklos #include "dzkbd.h"
     70  1.1     jklos 
     71  1.1     jklos /* Screen hardware defs */
     72  1.1     jklos 
     73  1.1     jklos #define	LCG_FB_ADDR		0x21801000	/* Frame buffer */
     74  1.1     jklos 
     75  1.1     jklos /* FIFO defines */
     76  1.1     jklos #define LCG_FIFO_SIZE		0x10000	/* 64 KB */
     77  1.1     jklos #define LCG_FIFO_WIN_ADDR	0x20180000
     78  1.1     jklos #define LCG_FIFO_WIN_SIZE	VAX_NBPG
     79  1.1     jklos #define LCG_FIFO_ALIGN		0x10000
     80  1.1     jklos 
     81  1.1     jklos /* font rendering defines */
     82  1.1     jklos #define LCG_FONT_ADDR		(LCG_FB_ADDR + lcg_fb_size)
     83  1.3  dholland #define LCG_FONT_STORAGE_SIZE	0x40000	/* 16 KB, enough to accommodate 16x32 font bitmaps */
     84  1.1     jklos 
     85  1.1     jklos /* register space defines */
     86  1.1     jklos #define LCG_REG_ADDR	0x20100000	/* LCG registers */
     87  1.1     jklos #define LCG_REG_SIZE	0x4000		/* 16384 bytes */
     88  1.1     jklos #define LCG_REG(reg) regaddr[(reg / 4)]
     89  1.1     jklos 
     90  1.1     jklos /* LUT defines */
     91  1.1     jklos #define LCG_LUT_ADDR	0x21800800	/* LUT right before onscreen FB */
     92  1.1     jklos #define LCG_LUT_OFFSET	0x00000800
     93  1.1     jklos #define LCG_LUT_SIZE	0x800		/* 2048 bytes */
     94  1.1     jklos 
     95  1.1     jklos #define	LCG_BG_COLOR	WSCOL_BLACK
     96  1.1     jklos #define	LCG_FG_COLOR	WSCOL_WHITE
     97  1.1     jklos 
     98  1.1     jklos #define	LCG_CONFIG	0x200f0010	/* LCG model information */
     99  1.1     jklos 
    100  1.1     jklos /* implement sanity checks at certain points to ensure safer operation */
    101  1.1     jklos #define LCG_SAFE
    102  1.1     jklos //#define LCG_DEBUG
    103  1.1     jklos 
    104  1.1     jklos static	int lcg_match(struct device *, struct cfdata *, void *);
    105  1.1     jklos static	void lcg_attach(struct device *, struct device *, void *);
    106  1.1     jklos 
    107  1.1     jklos struct	lcg_softc {
    108  1.1     jklos 	struct	device ss_dev;
    109  1.1     jklos 	bus_dmamap_t sc_dm;
    110  1.1     jklos };
    111  1.1     jklos 
    112  1.1     jklos CFATTACH_DECL_NEW(lcg, sizeof(struct lcg_softc),
    113  1.1     jklos     lcg_match, lcg_attach, NULL, NULL);
    114  1.1     jklos 
    115  1.1     jklos static void	lcg_cursor(void *, int, int, int);
    116  1.1     jklos static int	lcg_mapchar(void *, int, unsigned int *);
    117  1.1     jklos static void	lcg_putchar(void *, int, int, u_int, long);
    118  1.1     jklos static void	lcg_copycols(void *, int, int, int,int);
    119  1.1     jklos static void	lcg_erasecols(void *, int, int, int, long);
    120  1.1     jklos static void	lcg_copyrows(void *, int, int, int);
    121  1.1     jklos static void	lcg_eraserows(void *, int, int, long);
    122  1.1     jklos static int	lcg_allocattr(void *, int, int, int, long *);
    123  1.1     jklos static int	lcg_get_cmap(struct wsdisplay_cmap *);
    124  1.1     jklos static int	lcg_set_cmap(struct wsdisplay_cmap *);
    125  1.1     jklos static void	lcg_init_common(struct device *, struct vsbus_attach_args *);
    126  1.1     jklos 
    127  1.1     jklos const struct wsdisplay_emulops lcg_emulops = {
    128  1.1     jklos 	lcg_cursor,
    129  1.1     jklos 	lcg_mapchar,
    130  1.1     jklos 	lcg_putchar,
    131  1.1     jklos 	lcg_copycols,
    132  1.1     jklos 	lcg_erasecols,
    133  1.1     jklos 	lcg_copyrows,
    134  1.1     jklos 	lcg_eraserows,
    135  1.1     jklos 	lcg_allocattr
    136  1.1     jklos };
    137  1.1     jklos 
    138  1.1     jklos static char lcg_stdscreen_name[10] = "160x68";
    139  1.1     jklos struct wsscreen_descr lcg_stdscreen = {
    140  1.1     jklos 	lcg_stdscreen_name, 160, 68,		/* dynamically set */
    141  1.1     jklos 	&lcg_emulops,
    142  1.1     jklos 	8, 15,					/* dynamically set */
    143  1.1     jklos 	WSSCREEN_UNDERLINE|WSSCREEN_REVERSE|WSSCREEN_WSCOLORS,
    144  1.1     jklos };
    145  1.1     jklos 
    146  1.1     jklos const struct wsscreen_descr *_lcg_scrlist[] = {
    147  1.1     jklos 	&lcg_stdscreen,
    148  1.1     jklos };
    149  1.1     jklos 
    150  1.1     jklos const struct wsscreen_list lcg_screenlist = {
    151  1.1     jklos 	sizeof(_lcg_scrlist) / sizeof(struct wsscreen_descr *),
    152  1.1     jklos 	_lcg_scrlist,
    153  1.1     jklos };
    154  1.1     jklos 
    155  1.1     jklos static	char *lcgaddr;
    156  1.1     jklos static	char *lutaddr;
    157  1.1     jklos static	volatile long *regaddr;
    158  1.1     jklos static	volatile long *fifoaddr;
    159  1.1     jklos #ifndef LCG_NO_ACCEL
    160  1.1     jklos static	char *fontaddr;
    161  1.1     jklos #endif
    162  1.1     jklos 
    163  1.1     jklos static int	lcg_xsize;
    164  1.1     jklos static int	lcg_ysize;
    165  1.1     jklos static int	lcg_depth;
    166  1.1     jklos static int	lcg_cols;
    167  1.1     jklos static int	lcg_rows;
    168  1.1     jklos static int	lcg_onerow;
    169  1.1     jklos static int	lcg_fb_size;
    170  1.1     jklos static int	lcg_glyph_size; /* bitmap size in bits */
    171  1.1     jklos 
    172  1.1     jklos static	char *cursor;
    173  1.1     jklos 
    174  1.1     jklos static	int cur_on;
    175  1.1     jklos 
    176  1.1     jklos static	int cur_fg, cur_bg;
    177  1.1     jklos 
    178  1.1     jklos 
    179  1.1     jklos /* Our current hardware colormap */
    180  1.1     jklos static struct hwcmap256 {
    181  1.1     jklos #define	CMAP_SIZE	256	/* 256 R/G/B entries */
    182  1.1     jklos 	u_int8_t r[CMAP_SIZE];
    183  1.1     jklos 	u_int8_t g[CMAP_SIZE];
    184  1.1     jklos 	u_int8_t b[CMAP_SIZE];
    185  1.1     jklos } lcg_cmap;
    186  1.1     jklos 
    187  1.1     jklos /* The default colormap */
    188  1.1     jklos static struct {
    189  1.1     jklos 	u_int8_t r[8];
    190  1.1     jklos 	u_int8_t g[8];
    191  1.1     jklos 	u_int8_t b[8];
    192  1.1     jklos } lcg_default_cmap = {
    193  1.1     jklos 	{ 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff },
    194  1.1     jklos 	{ 0x00, 0x00, 0xff, 0x7f, 0x00, 0x00, 0xff, 0xff },
    195  1.1     jklos 	{ 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff }
    196  1.1     jklos };
    197  1.1     jklos 
    198  1.1     jklos struct wsdisplay_font lcg_font;
    199  1.1     jklos static u_char *qf;
    200  1.1     jklos static u_short *qf2;
    201  1.1     jklos 
    202  1.1     jklos #define QCHAR(c) (c < lcg_font.firstchar ? 0 : \
    203  1.1     jklos 	(c >= (lcg_font.firstchar + lcg_font.numchars) ? 0 : c - lcg_font.firstchar))
    204  1.1     jklos #define QFONT(c,line)	((lcg_font.stride == 2 ? \
    205  1.1     jklos 	qf2[QCHAR(c) * lcg_font.fontheight + line] : \
    206  1.1     jklos 	qf[QCHAR(c) * lcg_font.fontheight + line]))
    207  1.1     jklos #define	LCG_ADDR(row, col, line, dot) \
    208  1.1     jklos 	lcgaddr[((col) * lcg_font.fontwidth) + ((row) * lcg_font.fontheight * lcg_xsize) + \
    209  1.1     jklos 	    (line) * lcg_xsize + dot]
    210  1.1     jklos 
    211  1.1     jklos 
    212  1.1     jklos static int	lcg_ioctl(void *, void *, u_long, void *, int, struct lwp *);
    213  1.1     jklos static paddr_t	lcg_mmap(void *, void *, off_t, int);
    214  1.1     jklos static int	lcg_alloc_screen(void *, const struct wsscreen_descr *,
    215  1.1     jklos 				      void **, int *, int *, long *);
    216  1.1     jklos static void	lcg_free_screen(void *, void *);
    217  1.1     jklos static int	lcg_show_screen(void *, void *, int,
    218  1.1     jklos 				     void (*) (void *, int, int), void *);
    219  1.1     jklos static void	lcg_crsr_blink(void *);
    220  1.1     jklos 
    221  1.1     jklos /* LCG HW accel functions */
    222  1.1     jklos #ifndef LCG_NO_ACCEL
    223  1.1     jklos static void	fifo_put(long data);
    224  1.1     jklos static int	fifo_fill(int iterations);
    225  1.1     jklos static u_char	fifo_counter = 0;
    226  1.1     jklos 
    227  1.1     jklos static void	blkcpy(long source, long dest, int xdim, int ydim);
    228  1.1     jklos static void	blkset(long dest, int xdim, int ydim, char color);
    229  1.1     jklos static void	renderchar(long source, long dest, int xdim, int ydim, char fg, char bg);
    230  1.1     jklos #endif /* LCG_NO_ACCEL */
    231  1.1     jklos 
    232  1.1     jklos const struct wsdisplay_accessops lcg_accessops = {
    233  1.1     jklos 	lcg_ioctl,
    234  1.1     jklos 	lcg_mmap,
    235  1.1     jklos 	lcg_alloc_screen,
    236  1.1     jklos 	lcg_free_screen,
    237  1.1     jklos 	lcg_show_screen,
    238  1.1     jklos 	0 /* load_font */
    239  1.1     jklos };
    240  1.1     jklos 
    241  1.1     jklos /* TODO allocate ss_image dynamically for consoles beyond first one */
    242  1.1     jklos struct	lcg_screen {
    243  1.1     jklos 	int	ss_curx;
    244  1.1     jklos 	int	ss_cury;
    245  1.1     jklos 	int	ss_cur_fg;
    246  1.1     jklos 	int	ss_cur_bg;
    247  1.1     jklos 	struct {
    248  1.1     jklos 		u_char	data;			/* Image character */
    249  1.1     jklos 		u_char	attr;			/* Attribute: 80/70/08/07 */
    250  1.1     jklos 	} ss_image[160 * 128];			/* allow for maximum possible cell matrix */
    251  1.1     jklos };
    252  1.1     jklos #define	LCG_ATTR_UNDERLINE	0x80
    253  1.1     jklos #define	LCG_BG_MASK		0x70
    254  1.1     jklos #define	LCG_ATTR_REVERSE	0x08
    255  1.1     jklos #define	LCG_FG_MASK		0x07
    256  1.1     jklos 
    257  1.1     jklos static	struct lcg_screen lcg_conscreen;
    258  1.1     jklos static	struct lcg_screen *curscr;
    259  1.1     jklos static	struct lcg_screen *savescr;
    260  1.1     jklos 
    261  1.1     jklos static	callout_t lcg_cursor_ch;
    262  1.1     jklos 
    263  1.1     jklos #ifndef LCG_NO_ACCEL
    264  1.1     jklos void fifo_put(long data)
    265  1.1     jklos {
    266  1.1     jklos 	fifo_counter &= 0x3;
    267  1.1     jklos 	fifoaddr[fifo_counter] = data;
    268  1.1     jklos 	fifo_counter++;
    269  1.1     jklos }
    270  1.1     jklos 
    271  1.1     jklos int fifo_fill(int iterations)
    272  1.1     jklos {
    273  1.1     jklos 	long status;
    274  1.1     jklos 	int counter = 0;;
    275  1.1     jklos 
    276  1.1     jklos 	while (fifo_counter % 4)
    277  1.1     jklos 		fifo_put(0);
    278  1.1     jklos 
    279  1.1     jklos #ifdef LCG_SAFE
    280  1.1     jklos 	status = LCG_REG(LCG_REG_GRAPHICS_SUB_STATUS);
    281  1.1     jklos 	while ((counter < iterations) && ((status & 0x80000000) == 0x80000000)) {
    282  1.1     jklos 		delay(1000);
    283  1.1     jklos 		status = LCG_REG(LCG_REG_GRAPHICS_SUB_STATUS);
    284  1.1     jklos 		counter++;
    285  1.1     jklos 	}
    286  1.1     jklos #endif
    287  1.1     jklos 
    288  1.1     jklos 	if (counter == 0)
    289  1.1     jklos 		return 0;
    290  1.1     jklos 	else
    291  1.1     jklos 		return 1;
    292  1.1     jklos }
    293  1.1     jklos 
    294  1.1     jklos void blkcpy(long source, long dest, int xdim, int ydim)
    295  1.1     jklos {
    296  1.1     jklos 	int err;
    297  1.1     jklos 
    298  1.1     jklos #ifdef LCG_SAFE
    299  1.1     jklos 	if ((source < LCG_FB_ADDR) || (source > LCG_FB_ADDR + lcg_fb_size)) {
    300  1.1     jklos 		printf("lcg: blkcpy: invalid source 0x%lx\n", source);
    301  1.1     jklos 		return;
    302  1.1     jklos 	}
    303  1.1     jklos 	if ((dest < LCG_FB_ADDR) || (dest > LCG_FB_ADDR + lcg_fb_size)) {
    304  1.1     jklos 		printf("lcg: blkcpy: invalid destination 0x%lx\n", dest);
    305  1.1     jklos 		return;
    306  1.1     jklos 	}
    307  1.1     jklos #endif
    308  1.1     jklos 
    309  1.1     jklos #ifdef LCG_SAFE
    310  1.1     jklos 	fifo_put(0x0c010000 | (cur_fg & 0xff));
    311  1.1     jklos #endif
    312  1.1     jklos 	fifo_put(0x01020006);
    313  1.1     jklos 
    314  1.1     jklos 	fifo_put(0x06800000);
    315  1.1     jklos 	fifo_put(source);
    316  1.1     jklos 	fifo_put(lcg_xsize);
    317  1.1     jklos 
    318  1.1     jklos 	fifo_put(0x05800000);
    319  1.1     jklos 	fifo_put(dest);
    320  1.1     jklos 	fifo_put(lcg_xsize);
    321  1.1     jklos 
    322  1.1     jklos 	fifo_put(0x03400000);
    323  1.1     jklos 	fifo_put(0xff);
    324  1.1     jklos 
    325  1.1     jklos 	fifo_put(0x02000003);
    326  1.1     jklos 
    327  1.1     jklos #ifdef LCG_SAFE
    328  1.1     jklos 	fifo_put(0x04c00000);
    329  1.1     jklos 	fifo_put(0);
    330  1.1     jklos 	fifo_put(lcg_xsize);
    331  1.1     jklos 	fifo_put(lcg_fb_size - (dest - LCG_FB_ADDR));
    332  1.1     jklos #endif
    333  1.1     jklos 
    334  1.1     jklos 	fifo_put(0x09c00000);
    335  1.1     jklos 	fifo_put(((ydim & 0xffff) << 16) | xdim);
    336  1.1     jklos 	fifo_put(0);
    337  1.1     jklos 	fifo_put(0);
    338  1.1     jklos 
    339  1.1     jklos 	err = fifo_fill(200);
    340  1.1     jklos 	if (err)
    341  1.1     jklos 		printf("lcg: AG still busy after 200 msec\n");
    342  1.1     jklos }
    343  1.1     jklos 
    344  1.1     jklos void blkset(long dest, int xdim, int ydim, char color)
    345  1.1     jklos {
    346  1.1     jklos 	int err;
    347  1.1     jklos 
    348  1.1     jklos #ifdef LCG_SAFE
    349  1.1     jklos 	if ((dest < LCG_FB_ADDR) || (dest > LCG_FB_ADDR + lcg_fb_size)) {
    350  1.1     jklos 		printf("lcg: blkset: invalid destination 0x%lx\n", dest);
    351  1.1     jklos 		return;
    352  1.1     jklos 	}
    353  1.1     jklos #endif
    354  1.1     jklos 
    355  1.1     jklos 	fifo_put(0x0c010000 | (color & 0xff));
    356  1.1     jklos 
    357  1.1     jklos 	fifo_put(0x01000000);
    358  1.1     jklos 
    359  1.1     jklos 	fifo_put(0x05800000);
    360  1.1     jklos 	fifo_put(dest);
    361  1.1     jklos 	fifo_put(lcg_xsize);
    362  1.1     jklos 
    363  1.1     jklos 	fifo_put(0x03400000);
    364  1.1     jklos 	fifo_put(0xff);
    365  1.1     jklos 
    366  1.1     jklos 	fifo_put(0x02000003);
    367  1.1     jklos 
    368  1.1     jklos #ifdef LCG_SAFE
    369  1.1     jklos 	fifo_put(0x04c00000);
    370  1.1     jklos 	fifo_put(0);
    371  1.1     jklos 	fifo_put(lcg_xsize);
    372  1.1     jklos 	fifo_put(lcg_fb_size - (dest - LCG_FB_ADDR));
    373  1.1     jklos #endif
    374  1.1     jklos 
    375  1.1     jklos 	fifo_put(0x09c00000);
    376  1.1     jklos 	fifo_put(((ydim & 0xffff) << 16) | xdim);
    377  1.1     jklos 	fifo_put(0);
    378  1.1     jklos 	fifo_put(0);
    379  1.1     jklos 
    380  1.1     jklos 	err = fifo_fill(200);
    381  1.1     jklos 	if (err)
    382  1.1     jklos 		printf("lcg: AG still busy after 200 msec\n");
    383  1.1     jklos }
    384  1.1     jklos 
    385  1.1     jklos void renderchar(long source, long dest, int xdim, int ydim, char fg, char bg)
    386  1.1     jklos {
    387  1.1     jklos 	int err;
    388  1.1     jklos #ifdef LCG_SAFE
    389  1.1     jklos 	if ((dest < LCG_FB_ADDR) || (dest > LCG_FB_ADDR + lcg_fb_size)) {
    390  1.1     jklos 		printf("lcg: blkset: invalid destination 0x%lx\n", dest);
    391  1.1     jklos 		return;
    392  1.1     jklos 	}
    393  1.1     jklos #endif
    394  1.1     jklos 
    395  1.1     jklos 	fifo_put(0x0c050000 | (bg & 0xff));
    396  1.1     jklos 	fifo_put(0x0c010000 | (fg & 0xff));
    397  1.1     jklos 
    398  1.1     jklos 	fifo_put(0x01030008);
    399  1.1     jklos 
    400  1.1     jklos 	fifo_put(0x06800000);
    401  1.1     jklos 	fifo_put(source);
    402  1.1     jklos 	//fifo_put(lcg_xsize);
    403  1.1     jklos 	fifo_put(lcg_font.stride);
    404  1.1     jklos 
    405  1.1     jklos 	fifo_put(0x05800000);
    406  1.1     jklos 	fifo_put(dest);
    407  1.1     jklos 	fifo_put(lcg_xsize);
    408  1.1     jklos 
    409  1.1     jklos 	fifo_put(0x03400000);
    410  1.1     jklos 	fifo_put(0xff);
    411  1.1     jklos 
    412  1.1     jklos 	fifo_put(0x02000003);
    413  1.1     jklos 
    414  1.1     jklos #ifdef LCG_SAFE
    415  1.1     jklos 	fifo_put(0x04c00000);
    416  1.1     jklos 	fifo_put(0);
    417  1.1     jklos 	fifo_put(lcg_xsize);
    418  1.1     jklos 	fifo_put(lcg_fb_size - (dest - LCG_FB_ADDR));
    419  1.1     jklos #endif
    420  1.1     jklos 
    421  1.1     jklos 	fifo_put(0x09c00000);
    422  1.1     jklos 	fifo_put(((ydim & 0xffff) << 16) | (xdim & 0xffff));
    423  1.1     jklos 	fifo_put(0);
    424  1.1     jklos 	fifo_put(0);
    425  1.1     jklos 
    426  1.1     jklos 	err = fifo_fill(200);
    427  1.1     jklos 	if (err)
    428  1.1     jklos 		printf("lcg: AG still busy after 200 msec\n");
    429  1.1     jklos }
    430  1.1     jklos #endif /* LCG_NO_ACCEL */
    431  1.1     jklos 
    432  1.1     jklos int
    433  1.1     jklos lcg_match(struct device *parent, struct cfdata *match, void *aux)
    434  1.1     jklos {
    435  1.1     jklos 	struct vsbus_softc *sc = device_private(parent);
    436  1.1     jklos 	struct vsbus_attach_args *va = aux;
    437  1.1     jklos 	char *ch = (char *)va->va_addr;
    438  1.1     jklos 
    439  1.1     jklos 	if ((vax_boardtype != VAX_BTYP_46) && (vax_boardtype != VAX_BTYP_48))
    440  1.1     jklos 		return 0;
    441  1.1     jklos 
    442  1.1     jklos 	*ch = 1;
    443  1.1     jklos 	if ((*ch & 1) == 0)
    444  1.1     jklos 		return 0;
    445  1.1     jklos 	*ch = 0;
    446  1.1     jklos 	if ((*ch & 1) != 0)
    447  1.1     jklos 		return 0;
    448  1.1     jklos 
    449  1.1     jklos 	/* XXX use vertical interrupt? */
    450  1.1     jklos 	sc->sc_mask = 0x04; /* XXX - should be generated */
    451  1.1     jklos 	scb_fake(0x120, 0x15);
    452  1.1     jklos 	return 20;
    453  1.1     jklos }
    454  1.1     jklos 
    455  1.1     jklos void
    456  1.1     jklos lcg_attach(struct device *parent, struct device *self, void *aux)
    457  1.1     jklos {
    458  1.1     jklos 	struct vsbus_attach_args *va = aux;
    459  1.1     jklos 	struct wsemuldisplaydev_attach_args aa;
    460  1.1     jklos 
    461  1.1     jklos 	printf("\n");
    462  1.1     jklos 	aa.console = lcgaddr != NULL;
    463  1.1     jklos 
    464  1.1     jklos 	lcg_init_common(self, va);
    465  1.1     jklos 
    466  1.1     jklos 	curscr = &lcg_conscreen;
    467  1.1     jklos 
    468  1.1     jklos 	aa.scrdata = &lcg_screenlist;
    469  1.1     jklos 	aa.accessops = &lcg_accessops;
    470  1.1     jklos 
    471  1.1     jklos 	/* enable software cursor */
    472  1.1     jklos 	callout_init(&lcg_cursor_ch, 0);
    473  1.1     jklos 	callout_reset(&lcg_cursor_ch, hz / 2, lcg_crsr_blink, NULL);
    474  1.1     jklos 
    475  1.1     jklos 	config_found(self, &aa, wsemuldisplaydevprint);
    476  1.1     jklos }
    477  1.1     jklos 
    478  1.1     jklos static void
    479  1.1     jklos lcg_crsr_blink(void *arg)
    480  1.1     jklos {
    481  1.1     jklos 	int dot;
    482  1.1     jklos 
    483  1.1     jklos 	if (cur_on && curscr != NULL)
    484  1.1     jklos 		for (dot = 0; dot < lcg_font.fontwidth; dot++)
    485  1.1     jklos 			cursor[dot] = ((cursor[dot] & 0x0f) == cur_fg) ? cur_bg : cur_fg;
    486  1.1     jklos 
    487  1.1     jklos 	callout_reset(&lcg_cursor_ch, hz / 2, lcg_crsr_blink, NULL);
    488  1.1     jklos }
    489  1.1     jklos 
    490  1.1     jklos void
    491  1.1     jklos lcg_cursor(void *id, int on, int row, int col)
    492  1.1     jklos {
    493  1.1     jklos 	struct lcg_screen *ss = id;
    494  1.1     jklos 	int dot, attr;
    495  1.1     jklos 
    496  1.1     jklos 	attr = ss->ss_image[row * lcg_cols + col].attr;
    497  1.1     jklos 	if (ss == curscr) {
    498  1.1     jklos 		if (cursor != NULL) {
    499  1.1     jklos 			int ch = QFONT(ss->ss_image[ss->ss_cury * lcg_cols +
    500  1.1     jklos 			    ss->ss_curx].data, lcg_font.fontheight - 1);
    501  1.1     jklos 			attr = ss->ss_image[ss->ss_cury * lcg_cols +
    502  1.1     jklos 			    ss->ss_curx].attr;
    503  1.1     jklos 
    504  1.1     jklos 			if (attr & LCG_ATTR_REVERSE) {
    505  1.1     jklos 				cur_bg = attr & LCG_FG_MASK;
    506  1.1     jklos 				cur_fg = (attr & LCG_BG_MASK) >> 4;
    507  1.1     jklos 			} else {
    508  1.1     jklos 				cur_fg = attr & LCG_FG_MASK;
    509  1.1     jklos 				cur_bg = (attr & LCG_BG_MASK) >> 4;
    510  1.1     jklos 			}
    511  1.1     jklos 			for (dot = 0; dot < lcg_font.fontwidth; dot++)
    512  1.1     jklos 				cursor[dot] =  (ch & (1 << dot)) ?
    513  1.1     jklos 				    cur_fg : cur_bg;
    514  1.1     jklos 		}
    515  1.1     jklos 
    516  1.1     jklos 		cursor = &LCG_ADDR(row, col, lcg_font.fontheight - 1, 0);
    517  1.1     jklos 		cur_on = on;
    518  1.1     jklos 		if (attr & LCG_ATTR_REVERSE) {
    519  1.1     jklos 			cur_bg = attr & LCG_FG_MASK;
    520  1.1     jklos 			cur_fg = (attr & LCG_BG_MASK) >> 4;
    521  1.1     jklos 		} else {
    522  1.1     jklos 			cur_fg = attr & LCG_FG_MASK;
    523  1.1     jklos 			cur_bg = (attr & LCG_BG_MASK) >> 4;
    524  1.1     jklos 		}
    525  1.1     jklos 	}
    526  1.1     jklos 	ss->ss_curx = col;
    527  1.1     jklos 	ss->ss_cury = row;
    528  1.1     jklos 	if (attr & LCG_ATTR_REVERSE) {
    529  1.1     jklos 		ss->ss_cur_bg = attr & LCG_FG_MASK;
    530  1.1     jklos 		ss->ss_cur_fg = (attr & LCG_BG_MASK) >> 4;
    531  1.1     jklos 	} else {
    532  1.1     jklos 		ss->ss_cur_fg = attr & LCG_FG_MASK;
    533  1.1     jklos 		ss->ss_cur_bg = (attr & LCG_BG_MASK) >> 4;
    534  1.1     jklos 	}
    535  1.1     jklos }
    536  1.1     jklos 
    537  1.1     jklos int
    538  1.1     jklos lcg_mapchar(void *id, int uni, unsigned int *index)
    539  1.1     jklos {
    540  1.1     jklos 	if (uni < 256) {
    541  1.1     jklos 		*index = uni;
    542  1.1     jklos 		return (5);
    543  1.1     jklos 	}
    544  1.1     jklos 	*index = ' ';
    545  1.1     jklos 	return (0);
    546  1.1     jklos }
    547  1.1     jklos 
    548  1.1     jklos static void
    549  1.1     jklos lcg_putchar(void *id, int row, int col, u_int c, long attr)
    550  1.1     jklos {
    551  1.1     jklos 	struct lcg_screen *ss = id;
    552  1.1     jklos 	int i;
    553  1.1     jklos 	char dot_fg, dot_bg;
    554  1.1     jklos 
    555  1.1     jklos 	c &= 0xff;
    556  1.1     jklos 
    557  1.1     jklos 	ss->ss_image[row * lcg_cols + col].data = c;
    558  1.1     jklos 	ss->ss_image[row * lcg_cols + col].attr = attr;
    559  1.1     jklos 	if (ss != curscr)
    560  1.1     jklos 		return;
    561  1.1     jklos 
    562  1.1     jklos 	dot_fg = attr & LCG_FG_MASK;
    563  1.1     jklos 	dot_bg = (attr & LCG_BG_MASK) >> 4;
    564  1.1     jklos 	if (attr & LCG_ATTR_REVERSE) {
    565  1.1     jklos 		dot_fg = (attr & LCG_BG_MASK) >> 4;
    566  1.1     jklos 		dot_bg = attr & LCG_FG_MASK;
    567  1.1     jklos 	}
    568  1.1     jklos 
    569  1.1     jklos #ifndef LCG_NO_ACCEL
    570  1.1     jklos 	renderchar(LCG_FONT_ADDR + (c * lcg_glyph_size),
    571  1.1     jklos 		   LCG_FB_ADDR + (row * lcg_onerow) + (col * lcg_font.fontwidth),
    572  1.1     jklos 		   lcg_font.fontwidth, lcg_font.fontheight, dot_fg, dot_bg);
    573  1.1     jklos #else
    574  1.1     jklos 	for (i = 0; i < lcg_font.fontheight; i++) {
    575  1.1     jklos 		unsigned char ch = QFONT(c,i);
    576  1.1     jklos 		for (int j = 0; j < lcg_font.fontwidth; j++) {
    577  1.1     jklos 			LCG_ADDR(row, col, i, j) = ((ch >> j) & 1) ? dot_fg : dot_bg;
    578  1.1     jklos 		}
    579  1.1     jklos 	}
    580  1.1     jklos #endif /* LCG_NO_ACCEL */
    581  1.1     jklos 	if (attr & LCG_ATTR_UNDERLINE) {
    582  1.1     jklos 		char *p = &LCG_ADDR(row, col, lcg_font.fontheight - 1, 0);
    583  1.1     jklos 		for (i = 0; i < lcg_font.fontwidth; i++)
    584  1.1     jklos 			p[i] = ~p[i];
    585  1.1     jklos 	}
    586  1.1     jklos }
    587  1.1     jklos 
    588  1.1     jklos 
    589  1.1     jklos 
    590  1.1     jklos /*
    591  1.1     jklos  * copies columns inside a row.
    592  1.1     jklos  */
    593  1.1     jklos static void
    594  1.1     jklos lcg_copycols(void *id, int row, int srccol, int dstcol, int ncols)
    595  1.1     jklos {
    596  1.1     jklos 	struct lcg_screen *ss = id;
    597  1.1     jklos #ifdef LCG_NO_ACCEL
    598  1.1     jklos 	int i = 0;
    599  1.1     jklos #endif
    600  1.1     jklos 
    601  1.1     jklos 	bcopy(&ss->ss_image[row * lcg_cols + srccol], &ss->ss_image[row *
    602  1.1     jklos 	    lcg_cols + dstcol], ncols * sizeof(ss->ss_image[0]));
    603  1.1     jklos 	if (ss != curscr)
    604  1.1     jklos 		return;
    605  1.1     jklos #ifdef LCG_NO_ACCEL
    606  1.1     jklos 	for (i = 0; i < lcg_font.fontheight; i++)
    607  1.1     jklos 		memcpy(&LCG_ADDR(row, dstcol, i, 0),
    608  1.1     jklos 		&LCG_ADDR(row,srccol, i, 0), ncols * lcg_font.fontwidth);
    609  1.1     jklos 
    610  1.1     jklos #else
    611  1.1     jklos 	blkcpy(LCG_FB_ADDR + (row * lcg_onerow) + (srccol * lcg_font.fontwidth),
    612  1.1     jklos 	       LCG_FB_ADDR + (row * lcg_onerow) + (dstcol * lcg_font.fontwidth),
    613  1.1     jklos 	       (ncols * lcg_font.fontwidth), lcg_font.fontheight);
    614  1.1     jklos #endif
    615  1.1     jklos }
    616  1.1     jklos 
    617  1.1     jklos /*
    618  1.1     jklos  * Erases a bunch of chars inside one row.
    619  1.1     jklos  */
    620  1.1     jklos static void
    621  1.1     jklos lcg_erasecols(void *id, int row, int startcol, int ncols, long fillattr)
    622  1.1     jklos {
    623  1.1     jklos 	struct lcg_screen *ss = id;
    624  1.1     jklos 	int i;
    625  1.1     jklos 
    626  1.1     jklos 	bzero(&ss->ss_image[row * lcg_cols + startcol], ncols * sizeof(ss->ss_image[0]));
    627  1.1     jklos 	for (i = row * lcg_cols + startcol; i < row * lcg_cols + startcol + ncols; ++i)
    628  1.1     jklos 		ss->ss_image[i].attr = fillattr;
    629  1.1     jklos 	if (ss != curscr)
    630  1.1     jklos 		return;
    631  1.1     jklos #ifdef LCG_NO_ACCEL
    632  1.1     jklos 	for (i = 0; i < lcg_font.fontheight; i++)
    633  1.1     jklos                 memset(&LCG_ADDR(row, startcol, i, 0), 0, ncols * lcg_font.fontwidth);
    634  1.1     jklos #else
    635  1.1     jklos 	blkset(LCG_FB_ADDR + (row * lcg_onerow) + (startcol * lcg_font.fontwidth),
    636  1.1     jklos 		(ncols * lcg_font.fontwidth), lcg_font.fontheight, (fillattr & LCG_BG_MASK) >> 4);
    637  1.1     jklos #endif
    638  1.1     jklos }
    639  1.1     jklos 
    640  1.1     jklos static void
    641  1.1     jklos lcg_copyrows(void *id, int srcrow, int dstrow, int nrows)
    642  1.1     jklos {
    643  1.1     jklos 	struct lcg_screen *ss = id;
    644  1.1     jklos 
    645  1.1     jklos 	bcopy(&ss->ss_image[srcrow * lcg_cols], &ss->ss_image[dstrow * lcg_cols],
    646  1.1     jklos 	    nrows * lcg_cols * sizeof(ss->ss_image[0]));
    647  1.1     jklos 	if (ss != curscr)
    648  1.1     jklos 		return;
    649  1.1     jklos #ifdef LCG_NO_ACCEL
    650  1.1     jklos 	memcpy(&lcgaddr[dstrow * lcg_onerow],
    651  1.1     jklos             &lcgaddr[srcrow * lcg_onerow], nrows * lcg_onerow);
    652  1.1     jklos #else
    653  1.1     jklos 	blkcpy(LCG_FB_ADDR + (srcrow * lcg_onerow), LCG_FB_ADDR + (dstrow * lcg_onerow),
    654  1.1     jklos 		(lcg_cols * lcg_font.fontwidth), (nrows * lcg_font.fontheight));
    655  1.1     jklos #endif
    656  1.1     jklos }
    657  1.1     jklos 
    658  1.1     jklos static void
    659  1.1     jklos lcg_eraserows(void *id, int startrow, int nrows, long fillattr)
    660  1.1     jklos {
    661  1.1     jklos 	struct lcg_screen *ss = id;
    662  1.1     jklos 	int i;
    663  1.1     jklos 
    664  1.1     jklos 	bzero(&ss->ss_image[startrow * lcg_cols], nrows * lcg_cols *
    665  1.1     jklos 	    sizeof(ss->ss_image[0]));
    666  1.1     jklos 	for (i = startrow * lcg_cols; i < (startrow + nrows) * lcg_cols; ++i)
    667  1.1     jklos 		ss->ss_image[i].attr = fillattr;
    668  1.1     jklos 	if (ss != curscr)
    669  1.1     jklos 		return;
    670  1.1     jklos #ifdef LCG_NO_ACCEL
    671  1.1     jklos 	memset(&lcgaddr[startrow * lcg_onerow], 0, nrows * lcg_onerow);
    672  1.1     jklos #else
    673  1.1     jklos 	blkset(LCG_FB_ADDR + (startrow * lcg_onerow), (lcg_cols * lcg_font.fontwidth),
    674  1.1     jklos 		(nrows * lcg_font.fontheight), (fillattr & LCG_BG_MASK) >> 4);
    675  1.1     jklos #endif
    676  1.1     jklos }
    677  1.1     jklos 
    678  1.1     jklos static int
    679  1.1     jklos lcg_allocattr(void *id, int fg, int bg, int flags, long *attrp)
    680  1.1     jklos {
    681  1.1     jklos 	long myattr;
    682  1.1     jklos 
    683  1.1     jklos 	if (flags & WSATTR_WSCOLORS)
    684  1.1     jklos 		myattr = (fg & LCG_FG_MASK) | ((bg << 4) & LCG_BG_MASK);
    685  1.1     jklos 	else
    686  1.1     jklos 		myattr = WSCOL_WHITE << 4;	/* XXXX */
    687  1.1     jklos 	if (flags & WSATTR_REVERSE)
    688  1.1     jklos 		myattr |= LCG_ATTR_REVERSE;
    689  1.1     jklos 	if (flags & WSATTR_UNDERLINE)
    690  1.1     jklos 		myattr |= LCG_ATTR_UNDERLINE;
    691  1.1     jklos 	*attrp = myattr;
    692  1.1     jklos 	return 0;
    693  1.1     jklos }
    694  1.1     jklos 
    695  1.1     jklos static int
    696  1.1     jklos lcg_ioctl(void *v, void *vs, u_long cmd, void *data, int flag, struct lwp *l)
    697  1.1     jklos {
    698  1.1     jklos 	struct wsdisplay_fbinfo *fb = (void *)data;
    699  1.1     jklos 	int i;
    700  1.1     jklos 
    701  1.1     jklos 	switch (cmd) {
    702  1.1     jklos 	case WSDISPLAYIO_GTYPE:
    703  1.1     jklos 		*(u_int *)data = WSDISPLAY_TYPE_LCG;
    704  1.1     jklos 		break;
    705  1.1     jklos 
    706  1.1     jklos 	case WSDISPLAYIO_GINFO:
    707  1.1     jklos 		fb->height = lcg_ysize;
    708  1.1     jklos 		fb->width = lcg_xsize;
    709  1.1     jklos 		fb->depth = lcg_depth;
    710  1.1     jklos 		fb->cmsize = 1 << lcg_depth;
    711  1.1     jklos 		break;
    712  1.1     jklos 
    713  1.2     jklos 	case WSDISPLAYIO_LINEBYTES:
    714  1.2     jklos 		*(u_int *)data = lcg_xsize;
    715  1.2     jklos 		break;
    716  1.2     jklos 
    717  1.1     jklos 	case WSDISPLAYIO_GETCMAP:
    718  1.1     jklos 		return lcg_get_cmap((struct wsdisplay_cmap *)data);
    719  1.1     jklos 
    720  1.1     jklos 	case WSDISPLAYIO_PUTCMAP:
    721  1.1     jklos 		return lcg_set_cmap((struct wsdisplay_cmap *)data);
    722  1.1     jklos 
    723  1.1     jklos 	case WSDISPLAYIO_GMODE:
    724  1.1     jklos 		return EPASSTHROUGH;
    725  1.1     jklos 
    726  1.1     jklos 	case WSDISPLAYIO_SMODE:
    727  1.1     jklos 		/* if setting WSDISPLAYIO_MODE_EMUL, restore console cmap, current screen */
    728  1.1     jklos 		if (*(u_int *)data == WSDISPLAYIO_MODE_EMUL) {
    729  1.1     jklos 			/* FIXME: if this is meant to reset palette LUT reload has to be triggered too */
    730  1.1     jklos 			bzero(lutaddr, LCG_LUT_SIZE);
    731  1.1     jklos 			for (i = 0; i < 8; ++i) {
    732  1.1     jklos 				lcg_cmap.r[i] = lcg_default_cmap.r[i];
    733  1.1     jklos 				lcg_cmap.g[i] = lcg_default_cmap.g[i];
    734  1.1     jklos 				lcg_cmap.b[i] = lcg_default_cmap.b[i];
    735  1.1     jklos 				lutaddr[i * 8 + 1] = i;
    736  1.1     jklos 				lutaddr[i * 8 + 2] = 1;
    737  1.1     jklos 				lutaddr[i * 8 + 3] = lcg_cmap.r[i] >> (lcg_depth & 7);
    738  1.1     jklos 				lutaddr[i * 8 + 4] = 1;
    739  1.1     jklos 				lutaddr[i * 8 + 5] = lcg_cmap.g[i] >> (lcg_depth & 7);
    740  1.1     jklos 				lutaddr[i * 8 + 6] = 1;
    741  1.1     jklos 				lutaddr[i * 8 + 7] = lcg_cmap.b[i] >> (lcg_depth & 7);
    742  1.1     jklos 			}
    743  1.1     jklos 			if (savescr != NULL)
    744  1.1     jklos 				lcg_show_screen(NULL, savescr, 0, NULL, NULL);
    745  1.1     jklos 			savescr = NULL;
    746  1.1     jklos 		} else {		/* WSDISPLAYIO_MODE_MAPPED */
    747  1.1     jklos 			savescr = curscr;
    748  1.1     jklos 			curscr = NULL;
    749  1.1     jklos 			/* clear screen? */
    750  1.1     jklos 		}
    751  1.1     jklos 
    752  1.1     jklos 		return EPASSTHROUGH;
    753  1.1     jklos #if 0
    754  1.1     jklos 	case WSDISPLAYIO_SVIDEO:
    755  1.1     jklos 		if (*(u_int *)data == WSDISPLAYIO_VIDEO_ON) {
    756  1.1     jklos 			curcmd = curc;
    757  1.1     jklos 		} else {
    758  1.1     jklos 			curc = curcmd;
    759  1.1     jklos 			curcmd &= ~(CUR_CMD_FOPA|CUR_CMD_ENPA);
    760  1.1     jklos 			curcmd |= CUR_CMD_FOPB;
    761  1.1     jklos 		}
    762  1.1     jklos 		WRITECUR(CUR_CMD, curcmd);
    763  1.1     jklos 		break;
    764  1.1     jklos 
    765  1.1     jklos 	case WSDISPLAYIO_GVIDEO:
    766  1.1     jklos 		*(u_int *)data = (curcmd & CUR_CMD_FOPB ?
    767  1.1     jklos 		    WSDISPLAYIO_VIDEO_OFF : WSDISPLAYIO_VIDEO_ON);
    768  1.1     jklos 		break;
    769  1.1     jklos 
    770  1.1     jklos #endif
    771  1.1     jklos 	default:
    772  1.1     jklos 		return EPASSTHROUGH;
    773  1.1     jklos 	}
    774  1.1     jklos 	return 0;
    775  1.1     jklos }
    776  1.1     jklos 
    777  1.1     jklos static paddr_t
    778  1.1     jklos lcg_mmap(void *v, void *vs, off_t offset, int prot)
    779  1.1     jklos {
    780  1.1     jklos 	if (offset >= lcg_fb_size || offset < 0)
    781  1.1     jklos 		return -1;
    782  1.1     jklos 	return (LCG_FB_ADDR + offset) >> PGSHIFT;
    783  1.1     jklos }
    784  1.1     jklos 
    785  1.1     jklos int
    786  1.1     jklos lcg_alloc_screen(void *v, const struct wsscreen_descr *type, void **cookiep,
    787  1.1     jklos     int *curxp, int *curyp, long *defattrp)
    788  1.1     jklos {
    789  1.1     jklos 	int i;
    790  1.1     jklos 	struct lcg_screen *ss;
    791  1.1     jklos 
    792  1.1     jklos 	*cookiep = malloc(sizeof(struct lcg_screen), M_DEVBUF, M_WAITOK);
    793  1.1     jklos 	bzero(*cookiep, sizeof(struct lcg_screen));
    794  1.1     jklos 	*curxp = *curyp = 0;
    795  1.1     jklos 	*defattrp = (LCG_BG_COLOR << 4) | LCG_FG_COLOR;
    796  1.1     jklos 	ss = *cookiep;
    797  1.1     jklos 	for (i = 0; i < lcg_cols * lcg_rows; ++i)
    798  1.1     jklos 		ss->ss_image[i].attr = (LCG_BG_COLOR << 4) | LCG_FG_COLOR;
    799  1.1     jklos 	return 0;
    800  1.1     jklos }
    801  1.1     jklos 
    802  1.1     jklos void
    803  1.1     jklos lcg_free_screen(void *v, void *cookie)
    804  1.1     jklos {
    805  1.1     jklos }
    806  1.1     jklos 
    807  1.1     jklos int
    808  1.1     jklos lcg_show_screen(void *v, void *cookie, int waitok,
    809  1.1     jklos     void (*cb)(void *, int, int), void *cbarg)
    810  1.1     jklos {
    811  1.1     jklos 	struct lcg_screen *ss = cookie;
    812  1.1     jklos 	int row, col, dot_fg, dot_bg, j, attr;
    813  1.1     jklos #ifdef LCG_NO_ACCEL
    814  1.1     jklos 	int iter, jter;
    815  1.1     jklos 	unsigned char ch;
    816  1.1     jklos #endif
    817  1.1     jklos 
    818  1.1     jklos 	if (ss == curscr)
    819  1.1     jklos 		return (0);
    820  1.1     jklos #ifdef LCG_NO_ACCEL
    821  1.1     jklos 	memset(lcgaddr, LCG_BG_COLOR, lcg_xsize * lcg_ysize);
    822  1.1     jklos #endif
    823  1.1     jklos 
    824  1.1     jklos 	for (row = 0; row < lcg_rows; row++)
    825  1.1     jklos 		for (col = 0; col < lcg_cols; col++) {
    826  1.1     jklos 			attr = ss->ss_image[row * lcg_cols + col].attr;
    827  1.1     jklos 			if (attr & LCG_ATTR_REVERSE) {
    828  1.1     jklos 				dot_fg = (attr & LCG_BG_MASK) >> 4;
    829  1.1     jklos 				dot_bg = attr & LCG_FG_MASK;
    830  1.1     jklos 			} else {
    831  1.1     jklos 				dot_fg = attr & LCG_FG_MASK;
    832  1.1     jklos 				dot_bg = (attr & LCG_BG_MASK) >> 4;
    833  1.1     jklos 			}
    834  1.1     jklos 			u_char c = ss->ss_image[row * lcg_cols + col].data;
    835  1.1     jklos 
    836  1.1     jklos 			if (c < 32)
    837  1.1     jklos 				c = 32;
    838  1.1     jklos #ifndef LCG_NO_ACCEL
    839  1.1     jklos 			renderchar(LCG_FONT_ADDR + (c * lcg_glyph_size),
    840  1.1     jklos 				   LCG_FB_ADDR + (row * lcg_onerow) + (col * lcg_font.fontwidth),
    841  1.1     jklos 				   lcg_font.fontwidth, lcg_font.fontheight, dot_fg, dot_bg);
    842  1.1     jklos #else
    843  1.1     jklos 			for (iter = 0; iter < lcg_font.fontheight; iter++) {
    844  1.1     jklos 				ch = QFONT(c,iter);
    845  1.1     jklos 				for (jter = 0; jter < lcg_font.fontwidth; jter++) {
    846  1.1     jklos 					LCG_ADDR(row, col, iter, jter) = ((ch >> jter) & 1) ? dot_fg : dot_bg;
    847  1.1     jklos 				}
    848  1.1     jklos 			}
    849  1.1     jklos #endif
    850  1.1     jklos 			if (attr & LCG_ATTR_UNDERLINE)
    851  1.1     jklos 				for (j = 0; j < lcg_font.fontwidth; j++)
    852  1.1     jklos 					LCG_ADDR(row, col,
    853  1.1     jklos 					    lcg_font.fontheight - 1, j) = dot_fg;
    854  1.1     jklos 		}
    855  1.1     jklos 
    856  1.1     jklos 	cursor = &lcgaddr[(ss->ss_cury * lcg_onerow) +
    857  1.1     jklos 		((lcg_font.fontheight - 1) * lcg_xsize) +
    858  1.1     jklos 			(ss->ss_curx * lcg_font.fontwidth)];
    859  1.1     jklos 	cur_fg = ss->ss_cur_fg;
    860  1.1     jklos 	cur_bg = ss->ss_cur_bg;
    861  1.1     jklos 
    862  1.1     jklos 	curscr = ss;
    863  1.1     jklos 	return (0);
    864  1.1     jklos }
    865  1.1     jklos 
    866  1.1     jklos static int
    867  1.1     jklos lcg_get_cmap(struct wsdisplay_cmap *p)
    868  1.1     jklos {
    869  1.1     jklos 	u_int index = p->index, count = p->count;
    870  1.1     jklos 	int error;
    871  1.1     jklos 
    872  1.1     jklos 	if (index >= (1 << lcg_depth) || count > (1 << lcg_depth) - index)
    873  1.1     jklos 		return (EINVAL);
    874  1.1     jklos 
    875  1.1     jklos 	error = copyout(&lcg_cmap.r[index], p->red, count);
    876  1.1     jklos 	if (error)
    877  1.1     jklos 		return error;
    878  1.1     jklos 	error = copyout(&lcg_cmap.g[index], p->green, count);
    879  1.1     jklos 	if (error)
    880  1.1     jklos 		return error;
    881  1.1     jklos 	error = copyout(&lcg_cmap.b[index], p->blue, count);
    882  1.1     jklos 	return error;
    883  1.1     jklos }
    884  1.1     jklos 
    885  1.1     jklos static int
    886  1.1     jklos lcg_set_cmap(struct wsdisplay_cmap *p)
    887  1.1     jklos {
    888  1.1     jklos 	u_int index = p->index, count = p->count;
    889  1.1     jklos 	int error, s;
    890  1.1     jklos 
    891  1.1     jklos 	if (index >= (1 << lcg_depth) || count > (1 << lcg_depth) - index)
    892  1.1     jklos 		return (EINVAL);
    893  1.1     jklos 
    894  1.1     jklos 	error = copyin(p->red, &lcg_cmap.r[index], count);
    895  1.1     jklos 	if (error)
    896  1.1     jklos 		return error;
    897  1.1     jklos 	error = copyin(p->green, &lcg_cmap.g[index], count);
    898  1.1     jklos 	if (error)
    899  1.1     jklos 		return error;
    900  1.1     jklos 	error = copyin(p->blue, &lcg_cmap.b[index], count);
    901  1.1     jklos 	if (error)
    902  1.1     jklos 		return error;
    903  1.1     jklos 
    904  1.1     jklos 	s = spltty();
    905  1.1     jklos 	/* FIXME: if this is meant to set palette LUT reload has to be triggered too */
    906  1.1     jklos 	while (count-- > 0) {
    907  1.1     jklos 		lutaddr[index * 8 + 0] = 0;
    908  1.1     jklos 		lutaddr[index * 8 + 1] = index;
    909  1.1     jklos 		lutaddr[index * 8 + 2] = 1;
    910  1.1     jklos 		lutaddr[index * 8 + 3] = lcg_cmap.r[index] >> (lcg_depth & 7);
    911  1.1     jklos 		lutaddr[index * 8 + 4] = 1;
    912  1.1     jklos 		lutaddr[index * 8 + 5] = lcg_cmap.g[index] >> (lcg_depth & 7);
    913  1.1     jklos 		lutaddr[index * 8 + 6] = 1;
    914  1.1     jklos 		lutaddr[index * 8 + 7] = lcg_cmap.b[index] >> (lcg_depth & 7);
    915  1.1     jklos 		++index;
    916  1.1     jklos 	}
    917  1.1     jklos 	splx(s);
    918  1.1     jklos 	return (0);
    919  1.1     jklos }
    920  1.1     jklos 
    921  1.1     jklos cons_decl(lcg);
    922  1.1     jklos 
    923  1.1     jklos void
    924  1.1     jklos lcgcninit(struct consdev *cndev)
    925  1.1     jklos {
    926  1.1     jklos 	int i;
    927  1.1     jklos 	/* Clear screen */
    928  1.1     jklos 	memset(lcgaddr, LCG_BG_COLOR, lcg_xsize * lcg_ysize);
    929  1.1     jklos 
    930  1.1     jklos 	curscr = &lcg_conscreen;
    931  1.1     jklos 	for (i = 0; i < lcg_cols * lcg_rows; ++i)
    932  1.1     jklos 		lcg_conscreen.ss_image[i].attr =
    933  1.1     jklos 		    (LCG_BG_COLOR << 4) | LCG_FG_COLOR;
    934  1.1     jklos 	wsdisplay_cnattach(&lcg_stdscreen, &lcg_conscreen, 0, 0,
    935  1.1     jklos 	    (LCG_BG_COLOR << 4) | LCG_FG_COLOR);
    936  1.1     jklos 	cn_tab->cn_pri = CN_INTERNAL;
    937  1.1     jklos 
    938  1.1     jklos 
    939  1.1     jklos #if NDZKBD > 0
    940  1.1     jklos 	dzkbd_cnattach(0); /* Connect keyboard and screen together */
    941  1.1     jklos #endif
    942  1.1     jklos }
    943  1.1     jklos 
    944  1.1     jklos /*
    945  1.1     jklos  * Called very early to setup the glass tty as console.
    946  1.1     jklos  * Because it's called before the VM system is inited, virtual memory
    947  1.1     jklos  * for the framebuffer can be stolen directly without disturbing anything.
    948  1.1     jklos  */
    949  1.1     jklos void
    950  1.1     jklos lcgcnprobe(struct consdev *cndev)
    951  1.1     jklos {
    952  1.1     jklos 	extern const struct cdevsw wsdisplay_cdevsw;
    953  1.1     jklos 
    954  1.1     jklos 	if ((vax_boardtype != VAX_BTYP_46) && (vax_boardtype != VAX_BTYP_48))
    955  1.1     jklos 		return; /* Only for VS 4000/60 and VLC */
    956  1.1     jklos 
    957  1.1     jklos 	if (vax_confdata & 0x100)
    958  1.1     jklos 		return; /* Diagnostic console */
    959  1.1     jklos 
    960  1.1     jklos 	lcg_init_common(NULL, NULL);
    961  1.1     jklos 
    962  1.1     jklos 	/* Set up default LUT */
    963  1.1     jklos 
    964  1.1     jklos 	cndev->cn_pri = CN_INTERNAL;
    965  1.1     jklos 	cndev->cn_dev = makedev(cdevsw_lookup_major(&wsdisplay_cdevsw), 0);
    966  1.1     jklos }
    967  1.1     jklos 
    968  1.1     jklos void
    969  1.1     jklos lcg_init_common(struct device *self, struct vsbus_attach_args *va)
    970  1.1     jklos {
    971  1.1     jklos 	u_int magic, *lcg_config;
    972  1.1     jklos 	int i;
    973  1.1     jklos 	extern vaddr_t virtual_avail;
    974  1.1     jklos 	long video_conf;
    975  1.1     jklos 	int cookie;
    976  1.1     jklos 	struct wsdisplay_font *wf;
    977  1.1     jklos 
    978  1.1     jklos 	struct lcg_softc *sc = (void *)self;
    979  1.1     jklos 	bus_dma_segment_t seg;
    980  1.1     jklos 	int rseg, err;
    981  1.1     jklos 	void *fifo_mem_vaddr;
    982  1.1     jklos #ifndef LCG_NO_ACCEL
    983  1.1     jklos 	u_char line;
    984  1.1     jklos 	u_int ch, temp;
    985  1.1     jklos #endif
    986  1.1     jklos 
    987  1.1     jklos 	if (regaddr != NULL)
    988  1.1     jklos 		return;
    989  1.1     jklos 
    990  1.1     jklos 	/* map LCG registers first */
    991  1.1     jklos 	if (self != NULL) {
    992  1.1     jklos 		regaddr = (long*)vax_map_physmem(LCG_REG_ADDR, (LCG_REG_SIZE/VAX_NBPG));
    993  1.1     jklos 		if (regaddr == 0) {
    994  1.1     jklos 			printf("%s: Couldn't allocate register memory.\n", self->dv_xname);
    995  1.1     jklos 			return;
    996  1.1     jklos 		}
    997  1.1     jklos 	} else {
    998  1.1     jklos 		regaddr = (long*)virtual_avail;
    999  1.1     jklos 		virtual_avail += LCG_REG_SIZE;
   1000  1.1     jklos 		ioaccess((vaddr_t)regaddr, LCG_REG_ADDR, (LCG_REG_SIZE/VAX_NBPG));
   1001  1.1     jklos 	}
   1002  1.1     jklos 
   1003  1.1     jklos 	/*
   1004  1.1     jklos 	 * v = *0x200f0010 & VLC ? 0x07 : 0xf0;
   1005  1.1     jklos 	 * switch(v) {
   1006  1.1     jklos 	 * 0x05: 1280x1024
   1007  1.1     jklos 	 * 0x06: conf & 0x80 ? 1024x768 : 640x480
   1008  1.1     jklos 	 * 0x07: conf & 0x80 ? 1024x768 ? 1024x864
   1009  1.1     jklos 	 * 0x20: 1024x864
   1010  1.1     jklos 	 * 0x40: 1024x768
   1011  1.1     jklos 	 * 0x60: 1024x864
   1012  1.1     jklos 	 * 0x80: 1280x1024 4BPN
   1013  1.1     jklos 	 * 0x90: 1280x1024 8BPN
   1014  1.1     jklos 	 * 0xb0: 1280x1024 8BPN 2HD
   1015  1.1     jklos 	 */
   1016  1.1     jklos 	if (self != NULL) {
   1017  1.1     jklos 		lcg_config = (u_int *)vax_map_physmem(LCG_CONFIG, 1);
   1018  1.1     jklos 	} else {
   1019  1.1     jklos 		lcg_config = (u_int *)virtual_avail;
   1020  1.1     jklos 		ioaccess((vaddr_t)lcg_config, LCG_CONFIG, 1);
   1021  1.1     jklos 	}
   1022  1.1     jklos 	magic = *lcg_config & (vax_boardtype == VAX_BTYP_46 ? 0xf0 : 0x07);
   1023  1.1     jklos 	if (self != NULL) {
   1024  1.1     jklos 		vax_unmap_physmem((vaddr_t)lcg_config, 1);
   1025  1.1     jklos 	} else {
   1026  1.1     jklos 		iounaccess((vaddr_t)lcg_config, 1);
   1027  1.1     jklos 	}
   1028  1.1     jklos 	lcg_depth = 8;
   1029  1.1     jklos 	switch(magic) {
   1030  1.1     jklos 	case 0x80:		/* KA46 HR 1280x1024 4BPLN */
   1031  1.1     jklos 		lcg_depth = 4;
   1032  1.1     jklos 	case 0x05:		/* KA48 HR 1280x1024 8BPLN */
   1033  1.1     jklos 	case 0x90:		/* KA46 HR 1280x1024 8BPLN */
   1034  1.1     jklos 	case 0xb0:		/* KA46 HR 1280x1024 8BPLN 2HD */
   1035  1.1     jklos 		lcg_xsize = 1280;
   1036  1.1     jklos 		lcg_ysize = 1024;
   1037  1.1     jklos 		break;
   1038  1.1     jklos 	case 0x06:		/* KA48 1024x768 or 640x480 */
   1039  1.1     jklos 		if (vax_confdata & 0x80) {
   1040  1.1     jklos 			lcg_xsize = 1024;
   1041  1.1     jklos 			lcg_ysize = 768;
   1042  1.1     jklos 		} else {
   1043  1.1     jklos 			lcg_xsize = 640;
   1044  1.1     jklos 			lcg_ysize = 480;
   1045  1.1     jklos 		}
   1046  1.1     jklos 		break;
   1047  1.1     jklos 	case 0x07:		/* KA48 1024x768 or 1024x864 */
   1048  1.1     jklos 		lcg_xsize = 1024;
   1049  1.1     jklos 		lcg_ysize = (vax_confdata & 0x80) ? 768 : 864;
   1050  1.1     jklos 		break;
   1051  1.1     jklos 	case 0x20:		/* KA46 1024x864 */
   1052  1.1     jklos 	case 0x60:		/* KA46 1024x864 */
   1053  1.1     jklos 		lcg_xsize = 1024;
   1054  1.1     jklos 		lcg_ysize = 864;
   1055  1.1     jklos 		break;
   1056  1.1     jklos 	case 0x40:		/* KA46 1024x768 */
   1057  1.1     jklos 		lcg_xsize = 1024;
   1058  1.1     jklos 		lcg_ysize = 768;
   1059  1.1     jklos 		break;
   1060  1.1     jklos 	default:
   1061  1.1     jklos 		panic("LCG model not supported");
   1062  1.1     jklos 	}
   1063  1.1     jklos 	if (self != NULL)
   1064  1.1     jklos 		aprint_normal("%s: framebuffer size %dx%d, depth %d (magic 0x%x)\n",
   1065  1.1     jklos 			self->dv_xname, lcg_xsize, lcg_ysize, lcg_depth, magic);
   1066  1.1     jklos 
   1067  1.1     jklos 	wsfont_init();
   1068  1.1     jklos 	cookie = wsfont_find(NULL, 12, 22, 0, WSDISPLAY_FONTORDER_R2L,
   1069  1.1     jklos 	    WSDISPLAY_FONTORDER_L2R, WSFONT_FIND_BITMAP);
   1070  1.1     jklos 	if (cookie == -1)
   1071  1.1     jklos 		cookie = wsfont_find(NULL, 8, 0, 0, WSDISPLAY_FONTORDER_R2L, 0,
   1072  1.1     jklos 				WSFONT_FIND_BITMAP);
   1073  1.1     jklos 	if (cookie == -1)
   1074  1.1     jklos 		cookie = wsfont_find(NULL, 0, 0, 0, WSDISPLAY_FONTORDER_R2L,
   1075  1.1     jklos 		    WSDISPLAY_FONTORDER_L2R, WSFONT_FIND_BITMAP);
   1076  1.1     jklos 	if (cookie == -1 || wsfont_lock(cookie, &wf))
   1077  1.1     jklos 		panic("lcg_common_init: can't load console font");
   1078  1.1     jklos 	lcg_font = *wf;
   1079  1.1     jklos 	lcg_cols = lcg_xsize / lcg_font.fontwidth;
   1080  1.1     jklos 	lcg_rows = lcg_ysize / lcg_font.fontheight;
   1081  1.1     jklos 	if (self != NULL) {
   1082  1.1     jklos 		aprint_normal("%s: using font %s (%dx%d), ", self->dv_xname, lcg_font.name,
   1083  1.1     jklos 				lcg_font.fontwidth, lcg_font.fontheight);
   1084  1.1     jklos 		aprint_normal("console size: %dx%d\n", lcg_cols, lcg_rows);
   1085  1.1     jklos 	}
   1086  1.1     jklos 	lcg_onerow = lcg_xsize * lcg_font.fontheight;
   1087  1.1     jklos 	lcg_fb_size = lcg_xsize * lcg_ysize;
   1088  1.1     jklos 	lcg_stdscreen.ncols = lcg_cols;
   1089  1.1     jklos 	lcg_stdscreen.nrows = lcg_rows;
   1090  1.1     jklos 	lcg_stdscreen.fontwidth = lcg_font.fontwidth;
   1091  1.1     jklos 	lcg_stdscreen.fontheight = lcg_font.fontheight;
   1092  1.1     jklos 	lcg_glyph_size = lcg_font.stride * lcg_font.fontheight;
   1093  1.1     jklos 	snprintf(lcg_stdscreen_name, sizeof(lcg_stdscreen_name), "%dx%d", lcg_cols, lcg_rows);
   1094  1.1     jklos 	qf = lcg_font.data;
   1095  1.1     jklos 	qf2 = (u_short *)lcg_font.data;
   1096  1.1     jklos 
   1097  1.1     jklos 	if (self != NULL) {
   1098  1.1     jklos 		lcgaddr = (void *)vax_map_physmem(va->va_paddr,
   1099  1.1     jklos 					((lcg_fb_size + LCG_FONT_STORAGE_SIZE)/VAX_NBPG));
   1100  1.1     jklos 		if (lcgaddr == 0) {
   1101  1.1     jklos 			printf("%s: unable to allocate framebuffer memory.\n", self->dv_xname);
   1102  1.1     jklos 			return;
   1103  1.1     jklos 		}
   1104  1.1     jklos #ifndef LCG_NO_ACCEL
   1105  1.1     jklos 		fontaddr = lcgaddr + lcg_fb_size;
   1106  1.1     jklos 
   1107  1.1     jklos 		/* copy font bitmaps */
   1108  1.1     jklos 		for (ch = 0; ch < 256; ch++)
   1109  1.1     jklos 			for (line = 0; line < lcg_font.fontheight; line++) {
   1110  1.1     jklos 				temp = QFONT(ch, line);
   1111  1.1     jklos 				if (lcg_font.stride == 1)
   1112  1.1     jklos 					fontaddr[(ch * lcg_font.fontheight) + line] = temp;
   1113  1.1     jklos 				else {
   1114  1.1     jklos 					/* stride == 2 */
   1115  1.1     jklos 					fontaddr[(ch * lcg_font.stride * lcg_font.fontheight) + line] = temp & 0xff;
   1116  1.1     jklos 					fontaddr[(ch * lcg_font.stride * lcg_font.fontheight) + line + 1] = (temp >> 16) & 0xff;
   1117  1.1     jklos 				}
   1118  1.1     jklos 			}
   1119  1.1     jklos #endif
   1120  1.1     jklos 
   1121  1.1     jklos 		lutaddr = (void *)vax_map_physmem(LCG_LUT_ADDR, (LCG_LUT_SIZE/VAX_NBPG));
   1122  1.1     jklos 		if (lutaddr == 0) {
   1123  1.1     jklos 			printf("%s: unable to allocate LUT memory.\n", self->dv_xname);
   1124  1.1     jklos 			return;
   1125  1.1     jklos 		}
   1126  1.1     jklos 		fifoaddr = (long*)vax_map_physmem(LCG_FIFO_WIN_ADDR, (LCG_FIFO_WIN_SIZE/VAX_NBPG));
   1127  1.1     jklos 		if (regaddr == 0) {
   1128  1.1     jklos 			printf("%s: unable to map FIFO window\n", self->dv_xname);
   1129  1.1     jklos 			return;
   1130  1.1     jklos 		}
   1131  1.1     jklos 
   1132  1.1     jklos 		/* allocate contiguous physical memory block for FIFO */
   1133  1.1     jklos 		err = bus_dmamem_alloc(va->va_dmat, LCG_FIFO_SIZE,
   1134  1.1     jklos 			LCG_FIFO_ALIGN, 0, &seg, 1, &rseg, BUS_DMA_NOWAIT);
   1135  1.1     jklos 		if (err) {
   1136  1.1     jklos 			printf("%s: unable to allocate FIFO memory block, err = %d\n",
   1137  1.1     jklos 				self->dv_xname, err);
   1138  1.1     jklos 			return;
   1139  1.1     jklos 		}
   1140  1.1     jklos 
   1141  1.1     jklos 		err = bus_dmamem_map(va->va_dmat, &seg, rseg, LCG_FIFO_SIZE,
   1142  1.1     jklos 			&fifo_mem_vaddr, BUS_DMA_NOWAIT);
   1143  1.1     jklos 		if (err) {
   1144  1.1     jklos 			printf("%s: unable to map FIFO memory block, err = %d\n",
   1145  1.1     jklos 				self->dv_xname, err);
   1146  1.1     jklos 			bus_dmamem_free(va->va_dmat, &seg, rseg);
   1147  1.1     jklos 			return;
   1148  1.1     jklos 		}
   1149  1.1     jklos 
   1150  1.1     jklos 		err = bus_dmamap_create(va->va_dmat, LCG_FIFO_SIZE, rseg,
   1151  1.1     jklos 			LCG_FIFO_SIZE, 0, BUS_DMA_NOWAIT, &sc->sc_dm);
   1152  1.1     jklos 		if (err) {
   1153  1.1     jklos 			printf("%s: unable to create DMA map, err = %d\n", self->dv_xname, err);
   1154  1.1     jklos 			bus_dmamem_unmap(va->va_dmat, fifo_mem_vaddr, LCG_FIFO_SIZE);
   1155  1.1     jklos 			bus_dmamem_free(va->va_dmat, &seg, rseg);
   1156  1.1     jklos 			return;
   1157  1.1     jklos 		}
   1158  1.1     jklos 
   1159  1.1     jklos 		err = bus_dmamap_load(va->va_dmat, sc->sc_dm, fifo_mem_vaddr,
   1160  1.1     jklos 			LCG_FIFO_SIZE, NULL, BUS_DMA_NOWAIT);
   1161  1.1     jklos 		if (err) {
   1162  1.1     jklos 			printf("%s: unable to load DMA map, err = %d\n", self->dv_xname, err);
   1163  1.1     jklos 			bus_dmamap_destroy(va->va_dmat, sc->sc_dm);
   1164  1.1     jklos 			bus_dmamem_unmap(va->va_dmat, fifo_mem_vaddr, LCG_FIFO_SIZE);
   1165  1.1     jklos 			bus_dmamem_free(va->va_dmat, &seg, rseg);
   1166  1.1     jklos 			return;
   1167  1.1     jklos 		}
   1168  1.1     jklos 
   1169  1.1     jklos 		/* initialize LCG hardware */
   1170  1.1     jklos 		LCG_REG(LCG_REG_GRAPHICS_CONTROL) = 0xd8000000; /* gfx reset, FIFO and AG enable */
   1171  1.1     jklos //		LCG_REG(LCG_REG_WRITE_PROTECT_LOW_HIGH) = (((LCG_FB_ADDR + lcg_fb_size) & 0xffff0000) | (LCG_FB_ADDR >> 16));
   1172  1.1     jklos 		LCG_REG(LCG_REG_WRITE_PROTECT_LOW_HIGH) = 0xffff0000;
   1173  1.1     jklos 		LCG_REG(LCG_REG_FIFO_BASE) = sc->sc_dm->dm_segs[0].ds_addr;
   1174  1.1     jklos 		LCG_REG(LCG_REG_FIFO_BASE2) = sc->sc_dm->dm_segs[0].ds_addr;
   1175  1.1     jklos 		LCG_REG(LCG_REG_FIFO_MASKS) = 0xffff;
   1176  1.1     jklos 		LCG_REG(LCG_REG_FIFO_SAVE_HEAD_OFFSET) = sc->sc_dm->dm_segs[0].ds_addr;
   1177  1.1     jklos //		LCG_REG(LCG_REG_GRAPHICS_INT_STATUS) = 0;
   1178  1.1     jklos //		LCG_REG(LCG_REG_GRAPHICS_CONTROL) = 0x50000000; /* FIFO and AG enable */
   1179  1.1     jklos 		LCG_REG(LCG_REG_GRAPHICS_INT_STATUS) = 0xffffffff;
   1180  1.1     jklos 		LCG_REG(LCG_REG_GRAPHICS_INT_SET_ENABLE) = 0;
   1181  1.1     jklos 		LCG_REG(LCG_REG_GRAPHICS_INT_CLR_ENABLE) = 0xffffffff;
   1182  1.1     jklos 		LCG_REG(LCG_REG_LCG_GO) = 3; /* FIFO and AG go */
   1183  1.1     jklos //		LCG_REG(LCG_REG_BREAKPT_ADDRESS) = 0x2fffffff;
   1184  1.1     jklos 
   1185  1.1     jklos 	} else {
   1186  1.1     jklos 		lcgaddr = (void *)virtual_avail;
   1187  1.1     jklos 		virtual_avail += lcg_fb_size + LCG_FONT_STORAGE_SIZE;
   1188  1.1     jklos 		ioaccess((vaddr_t)lcgaddr, LCG_FB_ADDR, (lcg_fb_size/VAX_NBPG));
   1189  1.1     jklos 
   1190  1.1     jklos 		lutaddr = (void *)virtual_avail;
   1191  1.1     jklos 		virtual_avail += LCG_LUT_SIZE;
   1192  1.1     jklos 		ioaccess((vaddr_t)lutaddr, LCG_LUT_ADDR, (LCG_LUT_SIZE/VAX_NBPG));
   1193  1.1     jklos 
   1194  1.1     jklos 		fifoaddr = (long*)virtual_avail;
   1195  1.1     jklos 		virtual_avail += LCG_FIFO_WIN_SIZE;
   1196  1.1     jklos 		ioaccess((vaddr_t)fifoaddr, LCG_FIFO_WIN_ADDR, (LCG_FIFO_WIN_SIZE/VAX_NBPG));
   1197  1.1     jklos 	}
   1198  1.1     jklos 
   1199  1.1     jklos 	bzero(lutaddr, LCG_LUT_SIZE);
   1200  1.1     jklos 	for (i = 0; i < 8; ++i) {
   1201  1.1     jklos 		lcg_cmap.r[i] = lcg_default_cmap.r[i];
   1202  1.1     jklos 		lcg_cmap.g[i] = lcg_default_cmap.g[i];
   1203  1.1     jklos 		lcg_cmap.b[i] = lcg_default_cmap.b[i];
   1204  1.1     jklos 		lutaddr[i * 8 + 1] = i;
   1205  1.1     jklos 		lutaddr[i * 8 + 2] = 1;
   1206  1.1     jklos 		lutaddr[i * 8 + 3] = lcg_cmap.r[i] >> (lcg_depth & 7);
   1207  1.1     jklos 		lutaddr[i * 8 + 4] = 1;
   1208  1.1     jklos 		lutaddr[i * 8 + 5] = lcg_cmap.g[i] >> (lcg_depth & 7);
   1209  1.1     jklos 		lutaddr[i * 8 + 6] = 1;
   1210  1.1     jklos 		lutaddr[i * 8 + 7] = lcg_cmap.b[i] >> (lcg_depth & 7);
   1211  1.1     jklos 	}
   1212  1.1     jklos 
   1213  1.1     jklos 	/*
   1214  1.1     jklos 	 * 0xf100165b 4000/60
   1215  1.1     jklos 	 * 1111 0001 0000 0000 0001 0110 0101 1011
   1216  1.1     jklos 	 * vvvv vvvv vvvv vvvv vvvv vvvv vvvv vvvv
   1217  1.1     jklos 	 * 3322 2222 2222 1111 1111 11
   1218  1.1     jklos 	 * 1098 7654 3210 9876 5432 1098 7654 3210
   1219  1.1     jklos 	 *
   1220  1.1     jklos  	 * 0xf1001d7b 4000/VLC
   1221  1.1     jklos 	 * 1111 0001 0000 0000 0001 1101 0111 1011
   1222  1.1     jklos 	 * vvvv vvvv vvvv vvvv vvvv vvvv vvvv vvvv
   1223  1.1     jklos 	 * 3322 2222 2222 1111 1111 11
   1224  1.1     jklos 	 * 1098 7654 3210 9876 5432 1098 7654 3210
   1225  1.1     jklos 	 *
   1226  1.1     jklos 	 * 31-30     11 Vertical state
   1227  1.1     jklos 	 * 29-38     11 Horizontal state
   1228  1.1     jklos 	 * 27-26     00
   1229  1.1     jklos 	 * 25         0 console LUT select
   1230  1.1     jklos 	 * 24         1 control LUT select
   1231  1.1     jklos 	 * 23         0
   1232  1.1     jklos 	 * 22         0 cursor active
   1233  1.1     jklos 	 * 21-16 000000
   1234  1.1     jklos 	 * 15         0 video subsystem reset
   1235  1.1     jklos 	 * 14         0
   1236  1.1     jklos 	 * 13         0 LUT load size 2KB
   1237  1.1     jklos 	 * 12         1 enable H sync
   1238  1.1     jklos 	 * 11         0 Full LUT load		 1
   1239  1.1     jklos 	 * 10         1 video clock select
   1240  1.1     jklos 	 *  9- 8     10 memory refresh rate	01
   1241  1.1     jklos 	 *  7- 6     01 video refresh rate
   1242  1.1     jklos 	 *  5         0 load select		 1
   1243  1.1     jklos 	 *  4         1 read cursor output
   1244  1.1     jklos 	 *  3         1 LUT load enable
   1245  1.1     jklos 	 *  2         0 cursor enable
   1246  1.1     jklos 	 *  1         1 video enable
   1247  1.1     jklos 	 *  0         1 refresh clock enable
   1248  1.1     jklos 	 */
   1249  1.1     jklos 	/* prepare video_config reg for LUT relaod */
   1250  1.1     jklos 	video_conf
   1251  1.1     jklos 		 = (3 << 30) /* vertical state */
   1252  1.1     jklos 		 | (3 << 28) /* horizontal state */
   1253  1.1     jklos 		 | (0 << 26) /* unused */
   1254  1.1     jklos 		 | (0 << 25) /* console LUT select */
   1255  1.1     jklos 		 | (0 << 24) /* control LUT select */
   1256  1.1     jklos 		 | (0 << 23) /* unused */
   1257  1.1     jklos 		 | (0 << 22) /* cursor active */
   1258  1.1     jklos 		 | (0 << 16) /* current cursor scanline showing */
   1259  1.1     jklos 		 | (0 << 15) /* video subsystem reset */
   1260  1.1     jklos 		 | (0 << 14) /* unused */
   1261  1.1     jklos 		 | (1 << 13) /* LUT load size 2 KB */
   1262  1.1     jklos 		 | (1 << 12) /* enable horizontal sync */
   1263  1.1     jklos 		 | (1 << 10) /* video clock select */
   1264  1.1     jklos 		 | (1 << 6) /* video refresh select */
   1265  1.1     jklos 		 | (1 << 4) /* read curosr output */
   1266  1.1     jklos 		 | (1 << 3) /* LUT load enable */
   1267  1.1     jklos 		 | (0 << 2) /* cursor enable */
   1268  1.1     jklos 		 | (1 << 1) /* video enable */
   1269  1.1     jklos 		 | (1 << 0); /* refresh clock enable */
   1270  1.1     jklos 	/* FIXME needs updating for all supported models */
   1271  1.1     jklos 	if (lcg_xsize == 1280) {		/* 4000/60 HR 4PLN */
   1272  1.1     jklos 		video_conf |= (0 << 11); /* split LUT load */
   1273  1.1     jklos 		video_conf |= (2 << 8); /* memory refresh select */
   1274  1.1     jklos 		video_conf |= (0 << 5); /* split shift register load */
   1275  1.1     jklos 	} else {				/* 4000/VLC LR 8PLN */
   1276  1.1     jklos 		video_conf |= (1 << 11); /* Full LUT load */
   1277  1.1     jklos 		video_conf |= (1 << 8); /* memory refresh select */
   1278  1.1     jklos 		video_conf |= (1 << 5); /* split shift register load */
   1279  1.1     jklos 	}
   1280  1.1     jklos 
   1281  1.1     jklos 	LCG_REG(LCG_REG_VIDEO_CONFIG) = video_conf;
   1282  1.1     jklos 	/* vital !!! */
   1283  1.1     jklos 	LCG_REG(LCG_REG_LUT_CONSOLE_SEL) = 1;
   1284  1.1     jklos 	LCG_REG(LCG_REG_LUT_COLOR_BASE_W) = LCG_LUT_OFFSET;
   1285  1.1     jklos 
   1286  1.1     jklos 	delay(1000);
   1287  1.1     jklos 	LCG_REG(LCG_REG_LUT_CONSOLE_SEL) = 0;
   1288  1.1     jklos 
   1289  1.1     jklos #ifdef LCG_DEBUG
   1290  1.1     jklos 	if (self != NULL)
   1291  1.1     jklos 		printf("%s: video config register set 0x%08lx\n", video_conf, self->dv_xname);
   1292  1.1     jklos #endif
   1293  1.1     jklos }
   1294