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