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