Home | History | Annotate | Line # | Download | only in vsa
smg.c revision 1.47
      1 /*	$NetBSD: smg.c,v 1.47 2008/03/11 05:34:03 matt Exp $ */
      2 /*
      3  * Copyright (c) 1998 Ludd, University of Lule}, Sweden.
      4  * All rights reserved.
      5  *
      6  * Redistribution and use in source and binary forms, with or without
      7  * modification, are permitted provided that the following conditions
      8  * are met:
      9  * 1. Redistributions of source code must retain the above copyright
     10  *    notice, this list of conditions and the following disclaimer.
     11  * 2. Redistributions in binary form must reproduce the above copyright
     12  *    notice, this list of conditions and the following disclaimer in the
     13  *    documentation and/or other materials provided with the distribution.
     14  * 3. All advertising materials mentioning features or use of this software
     15  *    must display the following acknowledgement:
     16  *	This product includes software developed at Ludd, University of
     17  *	Lule}, Sweden and its contributors.
     18  * 4. The name of the author may not be used to endorse or promote products
     19  *    derived from this software without specific prior written permission
     20  *
     21  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     22  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     23  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     24  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     25  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     26  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     27  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     28  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     29  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     30  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     31  */
     32 
     33 #include <sys/cdefs.h>
     34 __KERNEL_RCSID(0, "$NetBSD: smg.c,v 1.47 2008/03/11 05:34:03 matt Exp $");
     35 
     36 #include <sys/param.h>
     37 #include <sys/device.h>
     38 #include <sys/systm.h>
     39 #include <sys/callout.h>
     40 #include <sys/time.h>
     41 #include <sys/malloc.h>
     42 #include <sys/conf.h>
     43 #include <sys/kernel.h>
     44 
     45 #include <machine/vsbus.h>
     46 #include <machine/sid.h>
     47 #include <machine/cpu.h>
     48 #include <machine/ka420.h>
     49 
     50 #include <dev/cons.h>
     51 
     52 #include <dev/dec/dzreg.h>
     53 #include <dev/dec/dzvar.h>
     54 #include <dev/dec/dzkbdvar.h>
     55 
     56 #include <dev/wscons/wsdisplayvar.h>
     57 #include <dev/wscons/wsconsio.h>
     58 #include <dev/wscons/wscons_callbacks.h>
     59 #include <dev/wsfont/wsfont.h>
     60 
     61 #include "dzkbd.h"
     62 #include "opt_wsfont.h"
     63 
     64 /* Screen hardware defs */
     65 #define SM_COLS		128	/* char width of screen */
     66 #define SM_ROWS		57	/* rows of char on screen */
     67 #define SM_CHEIGHT	15	/* lines a char consists of */
     68 #define SM_NEXTROW	(SM_COLS * SM_CHEIGHT)
     69 #define	SM_YWIDTH	864
     70 #define SM_XWIDTH	1024
     71 
     72 /* Cursor register definitions */
     73 #define	CUR_CMD		0
     74 #define	CUR_XPOS	4
     75 #define CUR_YPOS	8
     76 #define CUR_XMIN_1	12
     77 #define CUR_XMAX_1	16
     78 #define CUR_YMIN_1	20
     79 #define CUR_YMAX_1	24
     80 #define CUR_XMIN_2	28
     81 #define CUR_XMAX_2	32
     82 #define CUR_YMIN_2	36
     83 #define CUR_YMAX_2	40
     84 #define CUR_LOAD	44
     85 
     86 #define CUR_CMD_TEST	0x8000
     87 #define CUR_CMD_HSHI	0x4000
     88 #define CUR_CMD_VBHI	0x2000
     89 #define CUR_CMD_LODSA	0x1000
     90 #define CUR_CMD_FORG2	0x0800
     91 #define CUR_CMD_ENRG2	0x0400
     92 #define CUR_CMD_FORG1	0x0200
     93 #define CUR_CMD_ENRG1	0x0100
     94 #define CUR_CMD_XHWID	0x0080
     95 #define CUR_CMD_XHCL1	0x0040
     96 #define CUR_CMD_XHCLP	0x0020
     97 #define CUR_CMD_XHAIR	0x0010
     98 #define CUR_CMD_FOPB	0x0008
     99 #define CUR_CMD_ENPB	0x0004
    100 #define CUR_CMD_FOPA	0x0002
    101 #define CUR_CMD_ENPA	0x0001
    102 
    103 #define CUR_XBIAS	216	/* Add to cursor position */
    104 #define	CUR_YBIAS	33
    105 
    106 #define	WRITECUR(addr, val)	*(volatile uint16_t *)(curaddr + (addr)) = (val)
    107 static	char *curaddr;
    108 static	uint16_t curcmd, curx, cury, hotX, hotY;
    109 static	int bgmask, fgmask;
    110 
    111 static	int smg_match(device_t, cfdata_t, void *);
    112 static	void smg_attach(device_t, device_t, void *);
    113 
    114 struct	smg_softc {
    115 	struct	device ss_dev;
    116 };
    117 
    118 CFATTACH_DECL(smg, sizeof(struct smg_softc),
    119     smg_match, smg_attach, NULL, NULL);
    120 
    121 static void	smg_cursor(void *, int, int, int);
    122 static int	smg_mapchar(void *, int, unsigned int *);
    123 static void	smg_putchar(void *, int, int, u_int, long);
    124 static void	smg_copycols(void *, int, int, int,int);
    125 static void	smg_erasecols(void *, int, int, int, long);
    126 static void	smg_copyrows(void *, int, int, int);
    127 static void	smg_eraserows(void *, int, int, long);
    128 static int	smg_allocattr(void *, int, int, int, long *);
    129 
    130 const struct wsdisplay_emulops smg_emulops = {
    131 	.cursor = smg_cursor,
    132 	.mapchar = smg_mapchar,
    133 	.putchar = smg_putchar,
    134 	.copycols = smg_copycols,
    135 	.erasecols = smg_erasecols,
    136 	.copyrows = smg_copyrows,
    137 	.eraserows = smg_eraserows,
    138 	.allocattr = smg_allocattr
    139 };
    140 
    141 const struct wsscreen_descr smg_stdscreen = {
    142 	.name = "128x57",
    143 	.ncols = SM_COLS,
    144 	.nrows = SM_ROWS,
    145 	.textops = &smg_emulops,
    146 	.fontwidth = 8,
    147 	.fontheight = SM_CHEIGHT,
    148 	.capabilities = WSSCREEN_UNDERLINE|WSSCREEN_REVERSE,
    149 };
    150 
    151 const struct wsscreen_descr *_smg_scrlist[] = {
    152 	&smg_stdscreen,
    153 };
    154 
    155 const struct wsscreen_list smg_screenlist = {
    156 	.nscreens = __arraycount(_smg_scrlist),
    157 	.screens = _smg_scrlist,
    158 };
    159 
    160 static	char *sm_addr;
    161 
    162 static  u_char *qf;
    163 
    164 #define QCHAR(c) (c < 32 ? 32 : (c > 127 ? c - 66 : c - 32))
    165 #define QFONT(c,line)	qf[QCHAR(c) * 15 + line]
    166 #define	SM_ADDR(row, col, line) \
    167 	sm_addr[col + (row * SM_CHEIGHT * SM_COLS) + line * SM_COLS]
    168 
    169 
    170 static int	smg_ioctl(void *, void *, u_long, void *, int, struct lwp *);
    171 static paddr_t	smg_mmap(void *, void *, off_t, int);
    172 static int	smg_alloc_screen(void *, const struct wsscreen_descr *,
    173 				      void **, int *, int *, long *);
    174 static void	smg_free_screen(void *, void *);
    175 static int	smg_show_screen(void *, void *, int,
    176 				     void (*) (void *, int, int), void *);
    177 static void	smg_crsr_blink(void *);
    178 
    179 const struct wsdisplay_accessops smg_accessops = {
    180 	.ioctl = smg_ioctl,
    181 	.mmap = smg_mmap,
    182 	.alloc_screen = smg_alloc_screen,
    183 	.free_screen = smg_free_screen,
    184 	.show_screen = smg_show_screen,
    185 };
    186 
    187 struct	smg_screen {
    188 	int	ss_curx;
    189 	int	ss_cury;
    190 	u_char	ss_image[SM_ROWS][SM_COLS];	/* Image of current screen */
    191 	u_char	ss_attr[SM_ROWS][SM_COLS];	/* Reversed etc... */
    192 };
    193 
    194 static	struct smg_screen smg_conscreen;
    195 static	struct smg_screen *curscr;
    196 
    197 static	callout_t smg_cursor_ch;
    198 
    199 int
    200 smg_match(device_t parent, cfdata_t match, void *aux)
    201 {
    202 	struct vsbus_attach_args * const va = aux;
    203 	volatile uint16_t *ccmd;
    204 	volatile uint16_t *cfgtst;
    205 	uint16_t tmp, tmp2;
    206 
    207 	if (vax_boardtype == VAX_BTYP_49 || vax_boardtype == VAX_BTYP_53)
    208 		return 0;
    209 
    210 	ccmd = (uint16_t *)va->va_addr;
    211 	cfgtst = (uint16_t *)vax_map_physmem(VS_CFGTST, 1);
    212 	/*
    213 	 * Try to find the cursor chip by testing the flip-flop.
    214 	 * If nonexistent, no glass tty.
    215 	 */
    216 	ccmd[0] = CUR_CMD_HSHI|CUR_CMD_FOPB;
    217 	DELAY(300000);
    218 	tmp = cfgtst[0];
    219 	ccmd[0] = CUR_CMD_TEST|CUR_CMD_HSHI;
    220 	DELAY(300000);
    221 	tmp2 = cfgtst[0];
    222 	vax_unmap_physmem((vaddr_t)cfgtst, 1);
    223 
    224 	if (tmp2 != tmp)
    225 		return 20; /* Using periodic interrupt */
    226 	else
    227 		return 0;
    228 }
    229 
    230 void
    231 smg_attach(device_t parent, device_t self, void *aux)
    232 {
    233 	struct wsemuldisplaydev_attach_args aa;
    234 	struct wsdisplay_font *console_font;
    235 	int fcookie;
    236 
    237 	aprint_normal("\n");
    238 	sm_addr = (void *)vax_map_physmem(SMADDR, (SMSIZE/VAX_NBPG));
    239 	curaddr = (void *)vax_map_physmem(KA420_CUR_BASE, 1);
    240 	if (sm_addr == 0) {
    241 		aprint_error_dev(self, "Couldn't alloc graphics memory.\n");
    242 		return;
    243 	}
    244 	if (curscr == NULL)
    245 		callout_init(&smg_cursor_ch, 0);
    246 	curscr = &smg_conscreen;
    247 	aa.console = (vax_confdata & (KA420_CFG_L3CON|KA420_CFG_MULTU)) == 0;
    248 
    249 	aa.scrdata = &smg_screenlist;
    250 	aa.accessops = &smg_accessops;
    251 	callout_reset(&smg_cursor_ch, hz / 2, smg_crsr_blink, NULL);
    252 	curcmd = CUR_CMD_HSHI;
    253 	WRITECUR(CUR_CMD, curcmd);
    254 	if ((fcookie = wsfont_find(NULL, 8, 15, 0,
    255 		WSDISPLAY_FONTORDER_R2L, WSDISPLAY_FONTORDER_L2R)) < 0) {
    256 		aprint_error_dev(self, "could not find 8x15 font\n");
    257 		return;
    258 	}
    259 	if (wsfont_lock(fcookie, &console_font) != 0) {
    260 		aprint_error_dev(self, "could not lock 8x15 font\n");
    261 		return;
    262 	}
    263 	qf = console_font->data;
    264 
    265 	config_found(self, &aa, wsemuldisplaydevprint);
    266 }
    267 
    268 static	u_char *cursor;
    269 static	int cur_on;
    270 
    271 static void
    272 smg_crsr_blink(void *arg)
    273 {
    274 	if (cur_on)
    275 		*cursor ^= 255;
    276 	callout_reset(&smg_cursor_ch, hz / 2, smg_crsr_blink, NULL);
    277 }
    278 
    279 void
    280 smg_cursor(void *id, int on, int row, int col)
    281 {
    282 	struct smg_screen * const ss = id;
    283 
    284 	if (ss == curscr) {
    285 		SM_ADDR(ss->ss_cury, ss->ss_curx, 14) =
    286 		    QFONT(ss->ss_image[ss->ss_cury][ss->ss_curx], 14);
    287 		cursor = &SM_ADDR(row, col, 14);
    288 		if ((cur_on = on))
    289 			*cursor ^= 255;
    290 	}
    291 	ss->ss_curx = col;
    292 	ss->ss_cury = row;
    293 }
    294 
    295 int
    296 smg_mapchar(void *id, int uni, unsigned int *index)
    297 {
    298 	if (uni < 256) {
    299 		*index = uni;
    300 		return (5);
    301 	}
    302 	*index = ' ';
    303 	return (0);
    304 }
    305 
    306 static void
    307 smg_putchar(void *id, int row, int col, u_int c, long attr)
    308 {
    309 	struct smg_screen * const ss = id;
    310 	int i;
    311 
    312 	c &= 0xff;
    313 
    314 	ss->ss_image[row][col] = c;
    315 	ss->ss_attr[row][col] = attr;
    316 	if (ss != curscr)
    317 		return;
    318 	for (i = 0; i < 15; i++) {
    319 		unsigned char ch = QFONT(c, i);
    320 
    321 		SM_ADDR(row, col, i) = (attr & WSATTR_REVERSE ? ~ch : ch);
    322 
    323 	}
    324 	if (attr & WSATTR_UNDERLINE)
    325 		SM_ADDR(row, col, 14) ^= SM_ADDR(row, col, 14);
    326 }
    327 
    328 /*
    329  * copies columns inside a row.
    330  */
    331 static void
    332 smg_copycols(void *id, int row, int srccol, int dstcol, int ncols)
    333 {
    334 	struct smg_screen * const ss = id;
    335 	int i;
    336 
    337 	bcopy(&ss->ss_image[row][srccol], &ss->ss_image[row][dstcol], ncols);
    338 	bcopy(&ss->ss_attr[row][srccol], &ss->ss_attr[row][dstcol], ncols);
    339 	if (ss != curscr)
    340 		return;
    341 	for (i = 0; i < SM_CHEIGHT; i++)
    342 		bcopy(&SM_ADDR(row,srccol, i), &SM_ADDR(row, dstcol, i),ncols);
    343 }
    344 
    345 /*
    346  * Erases a bunch of chars inside one row.
    347  */
    348 static void
    349 smg_erasecols(void *id, int row, int startcol, int ncols, long fillattr)
    350 {
    351 	struct smg_screen * const ss = id;
    352 	int i;
    353 
    354 	bzero(&ss->ss_image[row][startcol], ncols);
    355 	bzero(&ss->ss_attr[row][startcol], ncols);
    356 	if (ss != curscr)
    357 		return;
    358 	for (i = 0; i < SM_CHEIGHT; i++)
    359 		bzero(&SM_ADDR(row, startcol, i), ncols);
    360 }
    361 
    362 static void
    363 smg_copyrows(void *id, int srcrow, int dstrow, int nrows)
    364 {
    365 	struct smg_screen * const ss = id;
    366 	int frows;
    367 
    368 	bcopy(&ss->ss_image[srcrow][0], &ss->ss_image[dstrow][0],
    369 	    nrows * SM_COLS);
    370 	bcopy(&ss->ss_attr[srcrow][0], &ss->ss_attr[dstrow][0],
    371 	    nrows * SM_COLS);
    372 	if (ss != curscr)
    373 		return;
    374 	if (nrows > 25) {
    375 		frows = nrows >> 1;
    376 		if (srcrow > dstrow) {
    377 			bcopy(&sm_addr[(srcrow * SM_NEXTROW)],
    378 			    &sm_addr[(dstrow * SM_NEXTROW)],
    379 			    frows * SM_NEXTROW);
    380 			bcopy(&sm_addr[((srcrow + frows) * SM_NEXTROW)],
    381 			    &sm_addr[((dstrow + frows) * SM_NEXTROW)],
    382 			    (nrows - frows) * SM_NEXTROW);
    383 		} else {
    384 			bcopy(&sm_addr[((srcrow + frows) * SM_NEXTROW)],
    385 			    &sm_addr[((dstrow + frows) * SM_NEXTROW)],
    386 			    (nrows - frows) * SM_NEXTROW);
    387 			bcopy(&sm_addr[(srcrow * SM_NEXTROW)],
    388 			    &sm_addr[(dstrow * SM_NEXTROW)],
    389 			    frows * SM_NEXTROW);
    390 		}
    391 	} else
    392 		bcopy(&sm_addr[(srcrow * SM_NEXTROW)],
    393 		    &sm_addr[(dstrow * SM_NEXTROW)], nrows * SM_NEXTROW);
    394 }
    395 
    396 static void
    397 smg_eraserows(void *id, int startrow, int nrows, long fillattr)
    398 {
    399 	struct smg_screen * const ss = id;
    400 	int frows;
    401 
    402 	bzero(&ss->ss_image[startrow][0], nrows * SM_COLS);
    403 	bzero(&ss->ss_attr[startrow][0], nrows * SM_COLS);
    404 	if (ss != curscr)
    405 		return;
    406 	if (nrows > 25) {
    407 		frows = nrows >> 1;
    408 		bzero(&sm_addr[(startrow * SM_NEXTROW)], frows * SM_NEXTROW);
    409 		bzero(&sm_addr[((startrow + frows) * SM_NEXTROW)],
    410 		    (nrows - frows) * SM_NEXTROW);
    411 	} else
    412 		bzero(&sm_addr[(startrow * SM_NEXTROW)], nrows * SM_NEXTROW);
    413 }
    414 
    415 static int
    416 smg_allocattr(void *id, int fg, int bg, int flags, long *attrp)
    417 {
    418 	*attrp = flags;
    419 	return 0;
    420 }
    421 
    422 static void
    423 setcursor(struct wsdisplay_cursor *v)
    424 {
    425 	uint16_t red, green, blue;
    426 	uint32_t curfg[16], curmask[16];
    427 	int i;
    428 
    429 	/* Enable cursor */
    430 	if (v->which & WSDISPLAY_CURSOR_DOCUR) {
    431 		if (v->enable)
    432 			curcmd |= CUR_CMD_ENPB|CUR_CMD_ENPA;
    433 		else
    434 			curcmd &= ~(CUR_CMD_ENPB|CUR_CMD_ENPA);
    435 		WRITECUR(CUR_CMD, curcmd);
    436 	}
    437 	if (v->which & WSDISPLAY_CURSOR_DOHOT) {
    438 		hotX = v->hot.x;
    439 		hotY = v->hot.y;
    440 	}
    441 	if (v->which & WSDISPLAY_CURSOR_DOCMAP) {
    442 		/* First background */
    443 		red = fusword(v->cmap.red);
    444 		green = fusword(v->cmap.green);
    445 		blue = fusword(v->cmap.blue);
    446 		bgmask = (((30L * red + 59L * green + 11L * blue) >> 8) >=
    447 		    (((1<<8)-1)*50)) ? ~0 : 0;
    448 		red = fusword(v->cmap.red+2);
    449 		green = fusword(v->cmap.green+2);
    450 		blue = fusword(v->cmap.blue+2);
    451 		fgmask = (((30L * red + 59L * green + 11L * blue) >> 8) >=
    452 		    (((1<<8)-1)*50)) ? ~0 : 0;
    453 	}
    454 	if (v->which & WSDISPLAY_CURSOR_DOSHAPE) {
    455 		WRITECUR(CUR_CMD, curcmd | CUR_CMD_LODSA);
    456 		copyin(v->image, curfg, sizeof(curfg));
    457 		copyin(v->mask, curmask, sizeof(curmask));
    458 		for (i = 0; i < sizeof(curfg)/sizeof(curfg[0]); i++) {
    459 			WRITECUR(CUR_LOAD, ((uint16_t)curfg[i] & fgmask) |
    460 			    (((uint16_t)curmask[i] & (uint16_t)~curfg[i])
    461 			    & bgmask));
    462 		}
    463 		for (i = 0; i < sizeof(curmask)/sizeof(curmask[0]); i++) {
    464 			WRITECUR(CUR_LOAD, (uint16_t)curmask[i]);
    465 		}
    466 		WRITECUR(CUR_CMD, curcmd);
    467 	}
    468 }
    469 
    470 int
    471 smg_ioctl(void *v, void *vs, u_long cmd, void *data, int flag, struct lwp *l)
    472 {
    473 	struct wsdisplay_fbinfo *fb = (void *)data;
    474 	static uint16_t curc;
    475 
    476 	switch (cmd) {
    477 	case WSDISPLAYIO_GTYPE:
    478 		*(u_int *)data = WSDISPLAY_TYPE_VAX_MONO;
    479 		break;
    480 
    481 	case WSDISPLAYIO_GINFO:
    482 		fb->height = SM_YWIDTH;
    483 		fb->width = SM_XWIDTH;
    484 		fb->depth = 1;
    485 		fb->cmsize = 2;
    486 		break;
    487 
    488 	case WSDISPLAYIO_SVIDEO:
    489 		if (*(u_int *)data == WSDISPLAYIO_VIDEO_ON) {
    490 			curcmd = curc;
    491 		} else {
    492 			curc = curcmd;
    493 			curcmd &= ~(CUR_CMD_FOPA|CUR_CMD_ENPA);
    494 			curcmd |= CUR_CMD_FOPB;
    495 		}
    496 		WRITECUR(CUR_CMD, curcmd);
    497 		break;
    498 
    499 	case WSDISPLAYIO_GVIDEO:
    500 		*(u_int *)data = (curcmd & CUR_CMD_FOPB ?
    501 		    WSDISPLAYIO_VIDEO_OFF : WSDISPLAYIO_VIDEO_ON);
    502 		break;
    503 
    504 	case WSDISPLAYIO_SCURSOR:
    505 		setcursor((struct wsdisplay_cursor *)data);
    506 		break;
    507 
    508 	case WSDISPLAYIO_SCURPOS:
    509 		curx = ((struct wsdisplay_curpos *)data)->x;
    510 		cury = ((struct wsdisplay_curpos *)data)->y;
    511 		WRITECUR(CUR_XPOS, curx + CUR_XBIAS);
    512 		WRITECUR(CUR_YPOS, cury + CUR_YBIAS);
    513 		break;
    514 
    515 	case WSDISPLAYIO_GCURPOS:
    516 		((struct wsdisplay_curpos *)data)->x = curx;
    517 		((struct wsdisplay_curpos *)data)->y = cury;
    518 		break;
    519 
    520 	case WSDISPLAYIO_GCURMAX:
    521 		((struct wsdisplay_curpos *)data)->x = 16;
    522 		((struct wsdisplay_curpos *)data)->y = 16;
    523 		break;
    524 
    525 	default:
    526 		return EPASSTHROUGH;
    527 	}
    528 	return 0;
    529 }
    530 
    531 static paddr_t
    532 smg_mmap(void *v, void *vs, off_t offset, int prot)
    533 {
    534 	if (offset >= SMSIZE || offset < 0)
    535 		return -1;
    536 	return (SMADDR + offset) >> PGSHIFT;
    537 }
    538 
    539 int
    540 smg_alloc_screen(void *v, const struct wsscreen_descr *type, void **cookiep,
    541     int *curxp, int *curyp, long *defattrp)
    542 {
    543 	*cookiep = malloc(sizeof(struct smg_screen), M_DEVBUF, M_WAITOK);
    544 	bzero(*cookiep, sizeof(struct smg_screen));
    545 	*curxp = *curyp = *defattrp = 0;
    546 	return 0;
    547 }
    548 
    549 void
    550 smg_free_screen(void *v, void *cookie)
    551 {
    552 }
    553 
    554 int
    555 smg_show_screen(void *v, void *cookie, int waitok,
    556     void (*cb)(void *, int, int), void *cbarg)
    557 {
    558 	struct smg_screen *ss = cookie;
    559 	int row, col, line;
    560 
    561 	if (ss == curscr)
    562 		return (0);
    563 
    564 	for (row = 0; row < SM_ROWS; row++)
    565 		for (line = 0; line < SM_CHEIGHT; line++) {
    566 			for (col = 0; col < SM_COLS; col++) {
    567 				u_char s, c = ss->ss_image[row][col];
    568 
    569 				if (c < 32)
    570 					c = 32;
    571 				s = QFONT(c, line);
    572 				if (ss->ss_attr[row][col] & WSATTR_REVERSE)
    573 					s ^= 255;
    574 				SM_ADDR(row, col, line) = s;
    575 				if (ss->ss_attr[row][col] & WSATTR_UNDERLINE)
    576 					SM_ADDR(row, col, line) = 255;
    577 			}
    578 		}
    579 	cursor = &sm_addr[(ss->ss_cury * SM_CHEIGHT * SM_COLS) + ss->ss_curx +
    580 	    ((SM_CHEIGHT - 1) * SM_COLS)];
    581 	curscr = ss;
    582 	return (0);
    583 }
    584 
    585 cons_decl(smg);
    586 
    587 void
    588 smgcninit(struct consdev *cndev)
    589 {
    590 	int fcookie;
    591 	struct wsdisplay_font *console_font;
    592 	extern void lkccninit(struct consdev *);
    593 	extern int lkccngetc(dev_t);
    594 	extern int dz_vsbus_lk201_cnattach(int);
    595 	/* Clear screen */
    596 	memset(sm_addr, 0, 128*864);
    597 
    598 	callout_init(&smg_cursor_ch, 0);
    599 
    600 	curscr = &smg_conscreen;
    601 	wsdisplay_cnattach(&smg_stdscreen, &smg_conscreen, 0, 0, 0);
    602 	cn_tab->cn_pri = CN_INTERNAL;
    603 	if ((fcookie = wsfont_find(NULL, 8, 15, 0,
    604 		WSDISPLAY_FONTORDER_R2L, WSDISPLAY_FONTORDER_L2R)) < 0)
    605 	{
    606 		printf("smg: could not find 8x15 font\n");
    607 		return;
    608 	}
    609 	if (wsfont_lock(fcookie, &console_font) != 0) {
    610 		printf("smg: could not lock 8x15 font\n");
    611 		return;
    612 	}
    613 	qf = console_font->data;
    614 
    615 #if NDZKBD > 0
    616 	dzkbd_cnattach(0); /* Connect keyboard and screen together */
    617 #endif
    618 }
    619 
    620 /*
    621  * Called very early to setup the glass tty as console.
    622  * Because it's called before the VM system is inited, virtual memory
    623  * for the framebuffer can be stolen directly without disturbing anything.
    624  */
    625 void
    626 smgcnprobe(struct consdev *cndev)
    627 {
    628 	extern vaddr_t virtual_avail;
    629 	extern const struct cdevsw wsdisplay_cdevsw;
    630 
    631 	switch (vax_boardtype) {
    632 	case VAX_BTYP_410:
    633 	case VAX_BTYP_420:
    634 	case VAX_BTYP_43:
    635 		if ((vax_confdata & KA420_CFG_L3CON) ||
    636 		    (vax_confdata & KA420_CFG_MULTU))
    637 			break; /* doesn't use graphics console */
    638 		sm_addr = (void *)virtual_avail;
    639 		virtual_avail += SMSIZE;
    640 		ioaccess((vaddr_t)sm_addr, SMADDR, (SMSIZE/VAX_NBPG));
    641 		cndev->cn_pri = CN_INTERNAL;
    642 		cndev->cn_dev = makedev(cdevsw_lookup_major(&wsdisplay_cdevsw),
    643 					0);
    644 		break;
    645 
    646 	default:
    647 		break;
    648 	}
    649 }
    650