xref: /openbsd-src/sys/dev/ic/vga.c (revision 99fd087599a8791921855f21bd7e36130f39aadc)
1 /* $OpenBSD: vga.c,v 1.69 2017/06/17 19:20:30 fcambus Exp $ */
2 /* $NetBSD: vga.c,v 1.28.2.1 2000/06/30 16:27:47 simonb Exp $ */
3 
4 /*-
5   * Copyright (c) 1999 Kazutaka YOKOTA <yokota@zodiac.mech.utsunomiya-u.ac.jp>
6   * Copyright (c) 1992-1998 S�ren Schmidt
7   * All rights reserved.
8   *
9   * Redistribution and use in source and binary forms, with or without
10   * modification, are permitted provided that the following conditions
11   * are met:
12   * 1. Redistributions of source code must retain the above copyright
13   *    notice, this list of conditions and the following disclaimer as
14   *    the first lines of this file unmodified.
15   * 2. Redistributions in binary form must reproduce the above copyright
16   *    notice, this list of conditions and the following disclaimer in the
17   *    documentation and/or other materials provided with the distribution.
18   * 3. 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 AUTHORS ``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 AUTHORS 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 /*
34  * Copyright (c) 1995, 1996 Carnegie-Mellon University.
35  * All rights reserved.
36  *
37  * Author: Chris G. Demetriou
38  *
39  * Permission to use, copy, modify and distribute this software and
40  * its documentation is hereby granted, provided that both the copyright
41  * notice and this permission notice appear in all copies of the
42  * software, derivative works or modified versions, and any portions
43  * thereof, and that both notices appear in supporting documentation.
44  *
45  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
46  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
47  * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
48  *
49  * Carnegie Mellon requests users of this software to return to
50  *
51  *  Software Distribution Coordinator  or  Software.Distribution@CS.CMU.EDU
52  *  School of Computer Science
53  *  Carnegie Mellon University
54  *  Pittsburgh PA 15213-3890
55  *
56  * any improvements or extensions that they make and grant Carnegie the
57  * rights to redistribute these changes.
58  */
59 
60 #include "vga.h"
61 
62 #include <sys/param.h>
63 #include <sys/systm.h>
64 #include <sys/kernel.h>
65 #include <sys/device.h>
66 #include <sys/malloc.h>
67 #include <sys/queue.h>
68 #include <machine/bus.h>
69 
70 #include <dev/ic/mc6845reg.h>
71 #include <dev/ic/pcdisplayvar.h>
72 #include <dev/ic/vgareg.h>
73 
74 #include <dev/wscons/wsdisplayvar.h>
75 #include <dev/wscons/wsconsio.h>
76 #include <dev/wscons/unicode.h>
77 
78 #include <dev/ic/vgavar.h>
79 #include <dev/ic/pcdisplay.h>
80 
81 static struct vgafont {
82 	char name[WSFONT_NAME_SIZE];
83 	int height;
84 	int encoding;
85 #ifdef notyet
86 	int firstchar, numchars;
87 #endif
88 	int slot;
89 	void *fontdata;
90 } vga_builtinfont = {
91 	.name = "builtin",
92 	.height = 16,
93 	.encoding = WSDISPLAY_FONTENC_IBM,
94 #ifdef notyet
95 	.firstchar = 0,
96 	.numchars = 256,
97 #endif
98 	.slot = 0,
99 	.fontdata = NULL
100 };
101 
102 int vgaconsole, vga_console_type, vga_console_attached;
103 struct vgascreen vga_console_screen;
104 struct vga_config vga_console_vc;
105 
106 int	vga_selectfont(struct vga_config *, struct vgascreen *,
107     const char *, const char *);
108 void	vga_init_screen(struct vga_config *, struct vgascreen *,
109     const struct wsscreen_descr *, int, long *);
110 void	vga_init(struct vga_config *, bus_space_tag_t, bus_space_tag_t);
111 void	vga_setfont(struct vga_config *, struct vgascreen *);
112 void	vga_pick_monitor_type(struct vga_config *);
113 
114 int	vga_mapchar(void *, int, unsigned int *);
115 int	vga_putchar(void *, int, int, u_int, long);
116 int	vga_alloc_attr(void *, int, int, int, long *);
117 int	vga_copyrows(void *, int, int, int);
118 void	vga_unpack_attr(void *, long, int *, int *, int *);
119 
120 static const struct wsdisplay_emulops vga_emulops = {
121 	pcdisplay_cursor,
122 	vga_mapchar,
123 	vga_putchar,
124 	pcdisplay_copycols,
125 	pcdisplay_erasecols,
126 	vga_copyrows,
127 	pcdisplay_eraserows,
128 	vga_alloc_attr,
129 	vga_unpack_attr
130 };
131 
132 /*
133  * translate WS(=ANSI) color codes to standard pc ones
134  */
135 static const unsigned char fgansitopc[] = {
136 #ifdef __alpha__
137 	/*
138 	 * XXX DEC HAS SWITCHED THE CODES FOR BLUE AND RED!!!
139 	 * XXX We should probably not bother with this
140 	 * XXX (reinitialize the palette registers).
141 	 */
142 	FG_BLACK, FG_BLUE, FG_GREEN, FG_CYAN, FG_RED,
143 	FG_MAGENTA, FG_BROWN, FG_LIGHTGREY
144 #else
145 	FG_BLACK, FG_RED, FG_GREEN, FG_BROWN, FG_BLUE,
146 	FG_MAGENTA, FG_CYAN, FG_LIGHTGREY
147 #endif
148 }, bgansitopc[] = {
149 #ifdef __alpha__
150 	BG_BLACK, BG_BLUE, BG_GREEN, BG_CYAN, BG_RED,
151 	BG_MAGENTA, BG_BROWN, BG_LIGHTGREY
152 #else
153 	BG_BLACK, BG_RED, BG_GREEN, BG_BROWN, BG_BLUE,
154 	BG_MAGENTA, BG_CYAN, BG_LIGHTGREY
155 #endif
156 };
157 
158 /*
159  * translate standard pc color codes to WS(=ANSI) ones
160  */
161 static const u_int8_t pctoansi[] = {
162 #ifdef __alpha__
163 	WSCOL_BLACK, WSCOL_RED, WSCOL_GREEN, WSCOL_BROWN,
164 	WSCOL_BLUE, WSCOL_MAGENTA, WSCOL_CYAN, WSCOL_WHITE
165 #else
166 	WSCOL_BLACK, WSCOL_BLUE, WSCOL_GREEN, WSCOL_CYAN,
167 	WSCOL_RED, WSCOL_MAGENTA, WSCOL_BROWN, WSCOL_WHITE
168 #endif
169 };
170 
171 
172 const struct wsscreen_descr vga_stdscreen = {
173 	"80x25", 80, 25,
174 	&vga_emulops,
175 	8, 16,
176 	WSSCREEN_WSCOLORS | WSSCREEN_HILIT | WSSCREEN_BLINK
177 }, vga_stdscreen_mono = {
178 	"80x25", 80, 25,
179 	&vga_emulops,
180 	8, 16,
181 	WSSCREEN_HILIT | WSSCREEN_UNDERLINE | WSSCREEN_BLINK | WSSCREEN_REVERSE
182 }, vga_stdscreen_bf = {
183 	"80x25bf", 80, 25,
184 	&vga_emulops,
185 	8, 16,
186 	WSSCREEN_WSCOLORS | WSSCREEN_BLINK
187 }, vga_40lscreen = {
188 	"80x40", 80, 40,
189 	&vga_emulops,
190 	8, 10,
191 	WSSCREEN_WSCOLORS | WSSCREEN_HILIT | WSSCREEN_BLINK
192 }, vga_40lscreen_mono = {
193 	"80x40", 80, 40,
194 	&vga_emulops,
195 	8, 10,
196 	WSSCREEN_HILIT | WSSCREEN_UNDERLINE | WSSCREEN_BLINK | WSSCREEN_REVERSE
197 }, vga_40lscreen_bf = {
198 	"80x40bf", 80, 40,
199 	&vga_emulops,
200 	8, 10,
201 	WSSCREEN_WSCOLORS | WSSCREEN_BLINK
202 }, vga_50lscreen = {
203 	"80x50", 80, 50,
204 	&vga_emulops,
205 	8, 8,
206 	WSSCREEN_WSCOLORS | WSSCREEN_HILIT | WSSCREEN_BLINK
207 }, vga_50lscreen_mono = {
208 	"80x50", 80, 50,
209 	&vga_emulops,
210 	8, 8,
211 	WSSCREEN_HILIT | WSSCREEN_UNDERLINE | WSSCREEN_BLINK | WSSCREEN_REVERSE
212 }, vga_50lscreen_bf = {
213 	"80x50bf", 80, 50,
214 	&vga_emulops,
215 	8, 8,
216 	WSSCREEN_WSCOLORS | WSSCREEN_BLINK
217 };
218 
219 #define VGA_SCREEN_CANTWOFONTS(type) (!((type)->capabilities & WSSCREEN_HILIT))
220 
221 const struct wsscreen_descr *_vga_scrlist[] = {
222 	&vga_stdscreen,
223 	&vga_stdscreen_bf,
224 	&vga_40lscreen,
225 	&vga_40lscreen_bf,
226 	&vga_50lscreen,
227 	&vga_50lscreen_bf,
228 	/* XXX other formats, graphics screen? */
229 }, *_vga_scrlist_mono[] = {
230 	&vga_stdscreen_mono,
231 	&vga_40lscreen_mono,
232 	&vga_50lscreen_mono,
233 	/* XXX other formats, graphics screen? */
234 };
235 
236 const struct wsscreen_list vga_screenlist = {
237 	sizeof(_vga_scrlist) / sizeof(struct wsscreen_descr *),
238 	_vga_scrlist
239 }, vga_screenlist_mono = {
240 	sizeof(_vga_scrlist_mono) / sizeof(struct wsscreen_descr *),
241 	_vga_scrlist_mono
242 };
243 
244 int	vga_ioctl(void *, u_long, caddr_t, int, struct proc *);
245 paddr_t	vga_mmap(void *, off_t, int);
246 int	vga_alloc_screen(void *, const struct wsscreen_descr *,
247 			 void **, int *, int *, long *);
248 void	vga_free_screen(void *, void *);
249 int	vga_show_screen(void *, void *, int,
250 			void (*) (void *, int, int), void *);
251 int	vga_load_font(void *, void *, struct wsdisplay_font *);
252 int	vga_list_font(void *, struct wsdisplay_font *);
253 void	vga_scrollback(void *, void *, int);
254 void	vga_burner(void *v, u_int on, u_int flags);
255 int	vga_getchar(void *, int, int, struct wsdisplay_charcell *);
256 
257 void vga_doswitch(struct vga_config *);
258 
259 const struct wsdisplay_accessops vga_accessops = {
260 	.ioctl = vga_ioctl,
261 	.mmap = vga_mmap,
262 	.alloc_screen = vga_alloc_screen,
263 	.free_screen = vga_free_screen,
264 	.show_screen = vga_show_screen,
265 	.load_font = vga_load_font,
266 	.list_font = vga_list_font,
267 	.scrollback = vga_scrollback,
268 	.getchar = vga_getchar,
269 	.burn_screen = vga_burner
270 };
271 
272 /*
273  * The following functions implement back-end configuration grabbing
274  * and attachment.
275  */
276 int
277 vga_common_probe(bus_space_tag_t iot, bus_space_tag_t memt)
278 {
279 	bus_space_handle_t ioh_vga, ioh_6845, memh;
280 	u_int8_t regval;
281 	u_int16_t vgadata;
282 	int gotio_vga, gotio_6845, gotmem, mono, rv;
283 	int dispoffset;
284 
285 	gotio_vga = gotio_6845 = gotmem = rv = 0;
286 
287 	if (bus_space_map(iot, 0x3c0, 0x10, 0, &ioh_vga))
288 		goto bad;
289 	gotio_vga = 1;
290 
291 	/* read "misc output register" */
292 	regval = bus_space_read_1(iot, ioh_vga, 0xc);
293 	mono = !(regval & 1);
294 
295 	if (bus_space_map(iot, (mono ? 0x3b0 : 0x3d0), 0x10, 0, &ioh_6845))
296 		goto bad;
297 	gotio_6845 = 1;
298 
299 	if (bus_space_map(memt, 0xa0000, 0x20000, 0, &memh))
300 		goto bad;
301 	gotmem = 1;
302 
303 	dispoffset = (mono ? 0x10000 : 0x18000);
304 
305 	vgadata = bus_space_read_2(memt, memh, dispoffset);
306 	bus_space_write_2(memt, memh, dispoffset, 0xa55a);
307 	if (bus_space_read_2(memt, memh, dispoffset) != 0xa55a)
308 		goto bad;
309 	bus_space_write_2(memt, memh, dispoffset, vgadata);
310 
311 	/*
312 	 * check if this is really a VGA
313 	 * (try to write "Color Select" register as XFree86 does)
314 	 * XXX check before if at least EGA?
315 	 */
316 	/* reset state */
317 	(void) bus_space_read_1(iot, ioh_6845, 10);
318 	bus_space_write_1(iot, ioh_vga, VGA_ATC_INDEX,
319 			  20 | 0x20); /* colselect | enable */
320 	regval = bus_space_read_1(iot, ioh_vga, VGA_ATC_DATAR);
321 	/* toggle the implemented bits */
322 	bus_space_write_1(iot, ioh_vga, VGA_ATC_DATAW, regval ^ 0x0f);
323 	bus_space_write_1(iot, ioh_vga, VGA_ATC_INDEX,
324 			  20 | 0x20);
325 	/* read back */
326 	if (bus_space_read_1(iot, ioh_vga, VGA_ATC_DATAR) != (regval ^ 0x0f))
327 		goto bad;
328 	/* restore contents */
329 	bus_space_write_1(iot, ioh_vga, VGA_ATC_DATAW, regval);
330 
331 	rv = 1;
332 bad:
333 	if (gotio_vga)
334 		bus_space_unmap(iot, ioh_vga, 0x10);
335 	if (gotio_6845)
336 		bus_space_unmap(iot, ioh_6845, 0x10);
337 	if (gotmem)
338 		bus_space_unmap(memt, memh, 0x20000);
339 
340 	return (rv);
341 }
342 
343 /*
344  * We want at least ASCII 32..127 be present in the
345  * first font slot.
346  */
347 int
348 vga_selectfont(struct vga_config *vc, struct vgascreen *scr, const char *name1,
349     const char *name2) /* NULL: take first found */
350 {
351 	const struct wsscreen_descr *type = scr->pcs.type;
352 	struct vgafont *f1, *f2;
353 	int i;
354 
355 	f1 = f2 = 0;
356 
357 	for (i = 0; i < VGA_MAXFONT; i++) {
358 		struct vgafont *f = vc->vc_fonts[i];
359 		if (!f || f->height != type->fontheight)
360 			continue;
361 		if (!f1 && (!name1 || !*name1 ||
362 		     !strncmp(name1, f->name, WSFONT_NAME_SIZE))) {
363 			f1 = f;
364 			continue;
365 		}
366 		if (!f2 &&
367 		    VGA_SCREEN_CANTWOFONTS(type) &&
368 		    (!name2 || !*name2 ||
369 		     !strncmp(name2, f->name, WSFONT_NAME_SIZE))) {
370 			f2 = f;
371 			continue;
372 		}
373 	}
374 
375 	/*
376 	 * The request fails if no primary font was found,
377 	 * or if a second font was requested but not found.
378 	 */
379 	if (f1 && (!name2 || !*name2 || f2)) {
380 #ifdef VGAFONTDEBUG
381 		if (scr != &vga_console_screen || vga_console_attached) {
382 			printf("vga (%s): font1=%s (slot %d)", type->name,
383 			       f1->name, f1->slot);
384 			if (f2)
385 				printf(", font2=%s (slot %d)",
386 				       f2->name, f2->slot);
387 			printf("\n");
388 		}
389 #endif
390 		scr->fontset1 = f1;
391 		scr->fontset2 = f2;
392 		return (0);
393 	}
394 	return (ENXIO);
395 }
396 
397 void
398 vga_init_screen(struct vga_config *vc, struct vgascreen *scr,
399     const struct wsscreen_descr *type, int existing, long *attrp)
400 {
401 	int cpos;
402 	int res;
403 
404 	scr->cfg = vc;
405 	scr->pcs.hdl = (struct pcdisplay_handle *)&vc->hdl;
406 	scr->pcs.type = type;
407 	scr->pcs.active = 0;
408 	scr->mindispoffset = 0;
409 	scr->maxdispoffset = 0x8000 - type->nrows * type->ncols * 2;
410 
411 	if (existing) {
412 		cpos = vga_6845_read(&vc->hdl, cursorh) << 8;
413 		cpos |= vga_6845_read(&vc->hdl, cursorl);
414 
415 		/* make sure we have a valid cursor position */
416 		if (cpos < 0 || cpos >= type->nrows * type->ncols)
417 			cpos = 0;
418 
419 		scr->pcs.dispoffset = vga_6845_read(&vc->hdl, startadrh) << 9;
420 		scr->pcs.dispoffset |= vga_6845_read(&vc->hdl, startadrl) << 1;
421 
422 		/* make sure we have a valid memory offset */
423 		if (scr->pcs.dispoffset < scr->mindispoffset ||
424 		    scr->pcs.dispoffset > scr->maxdispoffset)
425 			scr->pcs.dispoffset = scr->mindispoffset;
426 	} else {
427 		cpos = 0;
428 		scr->pcs.dispoffset = scr->mindispoffset;
429 	}
430 	scr->pcs.visibleoffset = scr->pcs.dispoffset;
431 	scr->vga_rollover = 0;
432 
433 	scr->pcs.vc_crow = cpos / type->ncols;
434 	scr->pcs.vc_ccol = cpos % type->ncols;
435 	pcdisplay_cursor_init(&scr->pcs, existing);
436 
437 #ifdef __alpha__
438 	if (!vc->hdl.vh_mono)
439 		/*
440 		 * DEC firmware uses a blue background.
441 		 */
442 		res = vga_alloc_attr(scr, WSCOL_WHITE, WSCOL_BLUE,
443 				     WSATTR_WSCOLORS, attrp);
444 	else
445 #endif
446 	res = vga_alloc_attr(scr, 0, 0, 0, attrp);
447 #ifdef DIAGNOSTIC
448 	if (res)
449 		panic("vga_init_screen: attribute botch");
450 #endif
451 
452 	scr->pcs.mem = NULL;
453 
454 	scr->fontset1 = scr->fontset2 = 0;
455 	if (vga_selectfont(vc, scr, 0, 0)) {
456 		if (scr == &vga_console_screen)
457 			panic("vga_init_screen: no font");
458 		else
459 			printf("vga_init_screen: no font\n");
460 	}
461 
462 	vc->nscreens++;
463 	LIST_INSERT_HEAD(&vc->screens, scr, next);
464 }
465 
466 void
467 vga_init(struct vga_config *vc, bus_space_tag_t iot, bus_space_tag_t memt)
468 {
469 	struct vga_handle *vh = &vc->hdl;
470 	u_int8_t mor;
471 	int i;
472 
473         vh->vh_iot = iot;
474         vh->vh_memt = memt;
475 
476         if (bus_space_map(vh->vh_iot, 0x3c0, 0x10, 0, &vh->vh_ioh_vga))
477                 panic("vga_common_setup: can't map vga i/o");
478 
479 	/* read "misc output register" */
480 	mor = bus_space_read_1(vh->vh_iot, vh->vh_ioh_vga, 0xc);
481 	vh->vh_mono = !(mor & 1);
482 
483 	if (bus_space_map(vh->vh_iot, (vh->vh_mono ? 0x3b0 : 0x3d0), 0x10, 0,
484 			  &vh->vh_ioh_6845))
485                 panic("vga_common_setup: can't map 6845 i/o");
486 
487         if (bus_space_map(vh->vh_memt, 0xa0000, 0x20000, 0, &vh->vh_allmemh))
488                 panic("vga_common_setup: can't map mem space");
489 
490         if (bus_space_subregion(vh->vh_memt, vh->vh_allmemh,
491 				(vh->vh_mono ? 0x10000 : 0x18000), 0x8000,
492 				&vh->vh_memh))
493                 panic("vga_common_setup: mem subrange failed");
494 
495 #ifdef __alpha__
496 	vga_pick_monitor_type(vc);
497 #endif
498 
499 	vc->nscreens = 0;
500 	LIST_INIT(&vc->screens);
501 	vc->active = NULL;
502 #ifdef __alpha__
503 	if (vc->custom_list.screens != NULL)
504 		vc->currenttype = vc->custom_list.screens[0];
505 	else
506 #endif
507 		vc->currenttype =
508 		    vh->vh_mono ? &vga_stdscreen_mono : &vga_stdscreen;
509 
510 	vc->vc_fonts[0] = &vga_builtinfont;
511 	for (i = 1; i < VGA_MAXFONT; i++)
512 		vc->vc_fonts[i] = NULL;
513 
514 	vc->currentfontset1 = vc->currentfontset2 = 0;
515 
516 	vga_save_palette(vc);
517 }
518 
519 struct vga_config *
520 vga_common_attach(struct device *self, bus_space_tag_t iot,
521     bus_space_tag_t memt, int type)
522 {
523 	return vga_extended_attach(self, iot, memt, type, NULL);
524 }
525 
526 struct vga_config *
527 vga_extended_attach(struct device *self, bus_space_tag_t iot,
528     bus_space_tag_t memt, int type, paddr_t (*map)(void *, off_t, int))
529 {
530 	int console;
531 	struct vga_config *vc;
532 	struct wsemuldisplaydev_attach_args aa;
533 
534 	console = vga_is_console(iot, type);
535 	if (console)
536 		vga_console_attached = 1;
537 
538 	if (type == -1)
539 		return NULL;
540 
541 	if (console) {
542 		vc = &vga_console_vc;
543 	} else {
544 		vc = malloc(sizeof(*vc), M_DEVBUF, M_NOWAIT | M_ZERO);
545 		if (vc == NULL)
546 			return NULL;
547 		vga_init(vc, iot, memt);
548 	}
549 
550 	vc->vc_softc = self;
551 	vc->vc_type = type;
552 	vc->vc_mmap = map;
553 
554 	aa.console = console;
555 #ifdef __alpha__
556 	if (vc->custom_list.screens != NULL)
557 		aa.scrdata = &vc->custom_list;
558 	else
559 #endif
560 		aa.scrdata =
561 		    vc->hdl.vh_mono ? &vga_screenlist_mono : &vga_screenlist;
562 
563 	aa.accessops = &vga_accessops;
564 	aa.accesscookie = vc;
565 	aa.defaultscreens = 0;
566 
567         config_found_sm(self, &aa, wsemuldisplaydevprint,
568 	    wsemuldisplaydevsubmatch);
569 
570 	return vc;
571 }
572 
573 int
574 vga_cnattach(bus_space_tag_t iot, bus_space_tag_t memt, int type, int check)
575 {
576 	long defattr;
577 	const struct wsscreen_descr *scr;
578 
579 	if (check && !vga_common_probe(iot, memt))
580 		return (ENXIO);
581 
582 	/* set up bus-independent VGA configuration */
583 	vga_init(&vga_console_vc, iot, memt);
584 	scr = vga_console_vc.currenttype;
585 	vga_init_screen(&vga_console_vc, &vga_console_screen, scr, 1, &defattr);
586 
587 	vga_console_screen.pcs.active = 1;
588 	vga_console_vc.active = &vga_console_screen;
589 
590 	wsdisplay_cnattach(scr, &vga_console_screen,
591 			   vga_console_screen.pcs.vc_ccol,
592 			   vga_console_screen.pcs.vc_crow,
593 			   defattr);
594 
595 	vgaconsole = 1;
596 	vga_console_type = type;
597 	return (0);
598 }
599 
600 int
601 vga_is_console(bus_space_tag_t iot, int type)
602 {
603 	if (vgaconsole &&
604 	    !vga_console_attached &&
605 	    iot == vga_console_vc.hdl.vh_iot &&
606 	    (vga_console_type == -1 || (type == vga_console_type)))
607 		return (1);
608 	return (0);
609 }
610 
611 int
612 vga_ioctl(void *v, u_long cmd, caddr_t data, int flag, struct proc *p)
613 {
614 	struct vga_config *vc = v;
615 	int mode;
616 #if NVGA_PCI > 0
617 	int error;
618 
619 	if (vc->vc_type == WSDISPLAY_TYPE_PCIVGA &&
620 	    (error = vga_pci_ioctl(v, cmd, data, flag, p)) != ENOTTY)
621 		return (error);
622 #endif
623 
624 	switch (cmd) {
625 	case WSDISPLAYIO_GTYPE:
626 		*(int *)data = vc->vc_type;
627 		/* XXX should get detailed hardware information here */
628 		break;
629 
630 	case WSDISPLAYIO_SMODE:
631 		mode = *(u_int *)data;
632 		if (mode == WSDISPLAYIO_MODE_EMUL) {
633 			vga_restore_fonts(vc);
634 			vga_restore_palette(vc);
635 		}
636 		break;
637 
638 	case WSDISPLAYIO_GVIDEO:
639 	case WSDISPLAYIO_SVIDEO:
640 		break;
641 
642 	case WSDISPLAYIO_GINFO:
643 	case WSDISPLAYIO_GETCMAP:
644 	case WSDISPLAYIO_PUTCMAP:
645 	case WSDISPLAYIO_GCURPOS:
646 	case WSDISPLAYIO_SCURPOS:
647 	case WSDISPLAYIO_GCURMAX:
648 	case WSDISPLAYIO_GCURSOR:
649 	case WSDISPLAYIO_SCURSOR:
650 	default:
651 		/* NONE of these operations are by the generic VGA driver. */
652 		return ENOTTY;
653 	}
654 
655 	return (0);
656 }
657 
658 paddr_t
659 vga_mmap(void *v, off_t offset, int prot)
660 {
661 	struct vga_config *vc = v;
662 
663 	if (vc->vc_mmap != NULL)
664 		return (*vc->vc_mmap)(v, offset, prot);
665 
666 	return (paddr_t)-1;
667 }
668 
669 int
670 vga_alloc_screen(void *v, const struct wsscreen_descr *type, void **cookiep,
671     int *curxp, int *curyp, long *defattrp)
672 {
673 	struct vga_config *vc = v;
674 	struct vgascreen *scr;
675 
676 	if (vc->nscreens == 1) {
677 		/*
678 		 * When allocating the second screen, get backing store
679 		 * for the first one too.
680 		 * XXX We could be more clever and use video RAM.
681 		 */
682 		scr = LIST_FIRST(&vc->screens);
683 		scr->pcs.mem = mallocarray(scr->pcs.type->ncols,
684 		    scr->pcs.type->nrows * 2, M_DEVBUF, M_WAITOK);
685 	}
686 
687 	scr = malloc(sizeof(struct vgascreen), M_DEVBUF, M_WAITOK);
688 	vga_init_screen(vc, scr, type, vc->nscreens == 0, defattrp);
689 
690 	if (vc->nscreens == 1) {
691 		scr->pcs.active = 1;
692 		vc->active = scr;
693 		vc->currenttype = type;
694 	} else {
695 		scr->pcs.mem = mallocarray(type->ncols,
696 		    type->nrows * 2, M_DEVBUF, M_WAITOK);
697 		pcdisplay_eraserows(&scr->pcs, 0, type->nrows, *defattrp);
698 	}
699 
700 	*cookiep = scr;
701 	*curxp = scr->pcs.vc_ccol;
702 	*curyp = scr->pcs.vc_crow;
703 
704 	return (0);
705 }
706 
707 void
708 vga_free_screen(void *v, void *cookie)
709 {
710 	struct vgascreen *vs = cookie;
711 	struct vga_config *vc = vs->cfg;
712 
713 	LIST_REMOVE(vs, next);
714 	vc->nscreens--;
715 	if (vs != &vga_console_screen) {
716 		/*
717 		 * deallocating the one but last screen
718 		 * removes backing store for the last one
719 		 */
720 		if (vc->nscreens == 1)
721 			free(LIST_FIRST(&vc->screens)->pcs.mem, M_DEVBUF, 0);
722 
723 		/* Last screen has no backing store */
724 		if (vc->nscreens != 0)
725 			free(vs->pcs.mem, M_DEVBUF, 0);
726 
727 		free(vs, M_DEVBUF, sizeof *vs);
728 	} else
729 		panic("vga_free_screen: console");
730 
731 	if (vc->active == vs)
732 		vc->active = NULL;
733 }
734 
735 void
736 vga_setfont(struct vga_config *vc, struct vgascreen *scr)
737 {
738 	int fontslot1, fontslot2;
739 
740 	fontslot1 = (scr->fontset1 ? scr->fontset1->slot : 0);
741 	fontslot2 = (scr->fontset2 ? scr->fontset2->slot : fontslot1);
742 	if (vc->currentfontset1 != fontslot1 ||
743 	    vc->currentfontset2 != fontslot2) {
744 		vga_setfontset(&vc->hdl, fontslot1, fontslot2);
745 		vc->currentfontset1 = fontslot1;
746 		vc->currentfontset2 = fontslot2;
747 	}
748 }
749 
750 int
751 vga_show_screen(void *v, void *cookie, int waitok, void (*cb)(void *, int, int),
752     void *cbarg)
753 {
754 	struct vgascreen *scr = cookie, *oldscr;
755 	struct vga_config *vc = scr->cfg;
756 
757 	oldscr = vc->active; /* can be NULL! */
758 	if (scr == oldscr) {
759 		return (0);
760 	}
761 
762 	vc->wantedscreen = cookie;
763 	vc->switchcb = cb;
764 	vc->switchcbarg = cbarg;
765 	if (cb) {
766 		timeout_set(&vc->vc_switch_timeout,
767 		    (void(*)(void *))vga_doswitch, vc);
768 		timeout_add(&vc->vc_switch_timeout, 0);
769 		return (EAGAIN);
770 	}
771 
772 	vga_doswitch(vc);
773 	return (0);
774 }
775 
776 void
777 vga_doswitch(struct vga_config *vc)
778 {
779 	struct vgascreen *scr, *oldscr;
780 	struct vga_handle *vh = &vc->hdl;
781 	const struct wsscreen_descr *type;
782 	int s;
783 
784 	scr = vc->wantedscreen;
785 	if (!scr) {
786 		printf("vga_doswitch: disappeared\n");
787 		(*vc->switchcb)(vc->switchcbarg, EIO, 0);
788 		return;
789 	}
790 
791 	type = scr->pcs.type;
792 	oldscr = vc->active; /* can be NULL! */
793 	if (scr == oldscr)
794 		return;
795 	s = spltty();
796 #ifdef DIAGNOSTIC
797 	if (oldscr) {
798 		if (!oldscr->pcs.active)
799 			panic("vga_show_screen: not active");
800 		if (oldscr->pcs.type != vc->currenttype)
801 			panic("vga_show_screen: bad type");
802 	}
803 	if (scr->pcs.active)
804 		panic("vga_show_screen: active");
805 #endif
806 
807 	scr->vga_rollover = 0;
808 
809 	if (oldscr) {
810 		const struct wsscreen_descr *oldtype = oldscr->pcs.type;
811 
812 		oldscr->pcs.active = 0;
813 		bus_space_read_region_2(vh->vh_memt, vh->vh_memh,
814 					oldscr->pcs.dispoffset, oldscr->pcs.mem,
815 					oldtype->ncols * oldtype->nrows);
816 	}
817 
818 	if (vc->currenttype != type) {
819 		vga_setscreentype(vh, type);
820 		vc->currenttype = type;
821 	}
822 
823 	vga_setfont(vc, scr);
824 	vga_restore_palette(vc);
825 
826 	scr->pcs.visibleoffset = scr->pcs.dispoffset = scr->mindispoffset;
827 	if (!oldscr || (scr->pcs.dispoffset != oldscr->pcs.dispoffset)) {
828 		vga_6845_write(vh, startadrh, scr->pcs.dispoffset >> 9);
829 		vga_6845_write(vh, startadrl, scr->pcs.dispoffset >> 1);
830 	}
831 
832 	bus_space_write_region_2(vh->vh_memt, vh->vh_memh,
833 				scr->pcs.dispoffset, scr->pcs.mem,
834 				type->ncols * type->nrows);
835 	scr->pcs.active = 1;
836 	splx(s);
837 
838 	vc->active = scr;
839 
840 	pcdisplay_cursor_reset(&scr->pcs);
841 	pcdisplay_cursor(&scr->pcs, scr->pcs.cursoron,
842 			 scr->pcs.vc_crow, scr->pcs.vc_ccol);
843 
844 	vc->wantedscreen = 0;
845 	if (vc->switchcb)
846 		(*vc->switchcb)(vc->switchcbarg, 0, 0);
847 }
848 
849 int
850 vga_load_font(void *v, void *cookie, struct wsdisplay_font *data)
851 {
852 	struct vga_config *vc = v;
853 	struct vgascreen *scr = cookie;
854 	char *name2;
855 	int res, slot;
856 	struct vgafont *f;
857 
858 	if (data->data == NULL) {
859 		if (scr == NULL)
860 			return EINVAL;
861 
862 		if ((name2 = data->name) != NULL) {
863 			while (*name2 && *name2 != ',')
864 				name2++;
865 			if (*name2)
866 				*name2++ = '\0';
867 		}
868 		res = vga_selectfont(vc, scr, data->name, name2);
869 		if (res == 0)
870 			vga_setfont(vc, scr);
871 		return (res);
872 	}
873 
874 	if (data->fontwidth != 8 || data->stride != 1)
875 		return (EINVAL); /* XXX 1 byte per line */
876 	if (data->firstchar != 0 || data->numchars != 256)
877 		return (EINVAL);
878 
879 	if (data->index < 0) {
880 		for (slot = 0; slot < VGA_MAXFONT; slot++)
881 			if (!vc->vc_fonts[slot])
882 				break;
883 	} else
884 		slot = data->index;
885 
886 	if (slot >= VGA_MAXFONT)
887 		return (ENOSPC);
888 
889 	if (vc->vc_fonts[slot] != NULL)
890 		return (EEXIST);
891 	f = malloc(sizeof(struct vgafont), M_DEVBUF, M_WAITOK | M_CANFAIL);
892 	if (f == NULL)
893 		return (ENOMEM);
894 	strlcpy(f->name, data->name, sizeof(f->name));
895 	f->height = data->fontheight;
896 	f->encoding = data->encoding;
897 #ifdef notyet
898 	f->firstchar = data->firstchar;
899 	f->numchars = data->numchars;
900 #endif
901 #ifdef VGAFONTDEBUG
902 	printf("vga: load %s (8x%d, enc %d) font to slot %d\n", f->name,
903 	       f->height, f->encoding, slot);
904 #endif
905 	vga_loadchars(&vc->hdl, slot, 0, 256, f->height, data->data);
906 	f->slot = slot;
907 	f->fontdata = data->data;
908 	vc->vc_fonts[slot] = f;
909 	data->cookie = f;
910 	data->index = slot;
911 
912 	return (0);
913 }
914 
915 int
916 vga_list_font(void *v, struct wsdisplay_font *data)
917 {
918 	struct vga_config *vc = v;
919 	struct vgafont *f;
920 
921 	if (data->index < 0 || data->index >= VGA_MAXFONT)
922 		return EINVAL;
923 
924 	if ((f = vc->vc_fonts[data->index]) == NULL)
925 		return EINVAL;
926 
927 	strlcpy(data->name, f->name, sizeof data->name);
928 #ifdef notyet
929 	data->firstchar = f->firstchar;
930 	data->numchars = f->numchars;
931 #else
932 	data->firstchar = 0;
933 	data->numchars = 256;
934 #endif
935 	data->encoding = f->encoding;
936 	data->fontwidth = 8;
937 	data->fontheight = f->height;
938 	data->stride = 1;
939 	data->bitorder = data->byteorder = WSDISPLAY_FONTORDER_L2R;
940 
941 	return (0);
942 }
943 
944 void
945 vga_scrollback(void *v, void *cookie, int lines)
946 {
947 	struct vga_config *vc = v;
948 	struct vgascreen *scr = cookie;
949 	struct vga_handle *vh = &vc->hdl;
950 
951 	if (lines == 0) {
952 		if (scr->pcs.visibleoffset == scr->pcs.dispoffset)
953 			return;
954 
955 		scr->pcs.visibleoffset = scr->pcs.dispoffset;	/* reset */
956 	}
957 	else {
958 		int vga_scr_end;
959 		int margin = scr->pcs.type->ncols * 2;
960 		int ul, we, p, st;
961 
962 		vga_scr_end = (scr->pcs.dispoffset + scr->pcs.type->ncols *
963 		    scr->pcs.type->nrows * 2);
964 		if (scr->vga_rollover > vga_scr_end + margin) {
965 			ul = vga_scr_end;
966 			we = scr->vga_rollover + scr->pcs.type->ncols * 2;
967 		} else {
968 			ul = 0;
969 			we = 0x8000;
970 		}
971 		p = (scr->pcs.visibleoffset - ul + we) % we + lines *
972 		    (scr->pcs.type->ncols * 2);
973 		st = (scr->pcs.dispoffset - ul + we) % we;
974 		if (p < margin)
975 			p = 0;
976 		if (p > st - margin)
977 			p = st;
978 		scr->pcs.visibleoffset = (p + ul) % we;
979 	}
980 
981 	/* update visible position */
982 	vga_6845_write(vh, startadrh, scr->pcs.visibleoffset >> 9);
983 	vga_6845_write(vh, startadrl, scr->pcs.visibleoffset >> 1);
984 }
985 
986 int
987 vga_alloc_attr(void *id, int fg, int bg, int flags, long *attrp)
988 {
989 	struct vgascreen *scr = id;
990 	struct vga_config *vc = scr->cfg;
991 
992 	if (vc->hdl.vh_mono) {
993 		if (flags & WSATTR_WSCOLORS)
994 			return (EINVAL);
995 		if (flags & WSATTR_REVERSE)
996 			*attrp = 0x70;
997 		else
998 			*attrp = 0x07;
999 		if (flags & WSATTR_UNDERLINE)
1000 			*attrp |= FG_UNDERLINE;
1001 		if (flags & WSATTR_HILIT)
1002 			*attrp |= FG_INTENSE;
1003 	} else {
1004 		if (flags & (WSATTR_UNDERLINE | WSATTR_REVERSE))
1005 			return (EINVAL);
1006 		if (flags & WSATTR_WSCOLORS)
1007 			*attrp = fgansitopc[fg & 7] | bgansitopc[bg & 7];
1008 		else
1009 			*attrp = 7;
1010 		if ((flags & WSATTR_HILIT) || (fg & 8) || (bg & 8))
1011 			*attrp += 8;
1012 	}
1013 	if (flags & WSATTR_BLINK)
1014 		*attrp |= FG_BLINK;
1015 	return (0);
1016 }
1017 
1018 void
1019 vga_unpack_attr(void *id, long attr, int *fg, int *bg, int *ul)
1020 {
1021 	struct vgascreen *scr = id;
1022 	struct vga_config *vc = scr->cfg;
1023 
1024 	if (vc->hdl.vh_mono) {
1025 		*fg = (attr & 0x07) == 0x07 ? WSCOL_WHITE : WSCOL_BLACK;
1026 		*bg = attr & 0x70 ? WSCOL_WHITE : WSCOL_BLACK;
1027 		if (ul != NULL)
1028 			*ul = *fg != WSCOL_WHITE && (attr & 0x01) ? 1 : 0;
1029 	} else {
1030 		*fg = pctoansi[attr & 0x07];
1031 		*bg = pctoansi[(attr & 0x70) >> 4];
1032 		if (ul != NULL)
1033 			*ul = 0;
1034 	}
1035 	if (attr & FG_INTENSE)
1036 		*fg += 8;
1037 }
1038 
1039 int
1040 vga_copyrows(void *id, int srcrow, int dstrow, int nrows)
1041 {
1042 	struct vgascreen *scr = id;
1043 	bus_space_tag_t memt = scr->pcs.hdl->ph_memt;
1044 	bus_space_handle_t memh = scr->pcs.hdl->ph_memh;
1045 	int ncols = scr->pcs.type->ncols;
1046 	bus_size_t srcoff, dstoff;
1047 	int s;
1048 
1049 	srcoff = srcrow * ncols + 0;
1050 	dstoff = dstrow * ncols + 0;
1051 
1052 	s = spltty();
1053 	if (scr->pcs.active) {
1054 		if (dstrow == 0 && (srcrow + nrows == scr->pcs.type->nrows)) {
1055 #ifdef PCDISPLAY_SOFTCURSOR
1056 			int cursoron = scr->pcs.cursoron;
1057 
1058 			/* NOTE this assumes pcdisplay_cursor() never fails */
1059 			if (cursoron)
1060 				pcdisplay_cursor(&scr->pcs, 0,
1061 				    scr->pcs.vc_crow, scr->pcs.vc_ccol);
1062 #endif
1063 			/* scroll up whole screen */
1064 			if ((scr->pcs.dispoffset + srcrow * ncols * 2)
1065 			    <= scr->maxdispoffset) {
1066 				scr->pcs.dispoffset += srcrow * ncols * 2;
1067 			} else {
1068 				bus_space_copy_2(memt, memh,
1069 					scr->pcs.dispoffset + srcoff * 2,
1070 					memh, scr->mindispoffset,
1071 					nrows * ncols);
1072 				scr->vga_rollover = scr->pcs.dispoffset;
1073 				scr->pcs.dispoffset = scr->mindispoffset;
1074 			}
1075 			scr->pcs.visibleoffset = scr->pcs.dispoffset;
1076 			vga_6845_write(&scr->cfg->hdl, startadrh,
1077 				       scr->pcs.dispoffset >> 9);
1078 			vga_6845_write(&scr->cfg->hdl, startadrl,
1079 				       scr->pcs.dispoffset >> 1);
1080 #ifdef PCDISPLAY_SOFTCURSOR
1081 			/* NOTE this assumes pcdisplay_cursor() never fails */
1082 			if (cursoron)
1083 				pcdisplay_cursor(&scr->pcs, 1,
1084 				    scr->pcs.vc_crow, scr->pcs.vc_ccol);
1085 #endif
1086 		} else {
1087 			bus_space_copy_2(memt, memh,
1088 					scr->pcs.dispoffset + srcoff * 2,
1089 					memh, scr->pcs.dispoffset + dstoff * 2,
1090 					nrows * ncols);
1091 		}
1092 	} else
1093 		bcopy(&scr->pcs.mem[srcoff], &scr->pcs.mem[dstoff],
1094 		      nrows * ncols * 2);
1095 	splx(s);
1096 
1097 	return 0;
1098 }
1099 
1100 int _vga_mapchar(void *, struct vgafont *, int, unsigned int *);
1101 
1102 int
1103 _vga_mapchar(void *id, struct vgafont *font, int uni, unsigned int *index)
1104 {
1105 
1106 	switch (font->encoding) {
1107 	case WSDISPLAY_FONTENC_ISO:
1108 		if (uni < 256) {
1109 			*index = uni;
1110 			return (5);
1111 		} else {
1112 			*index = '?';
1113 			return (0);
1114 		}
1115 		break;
1116 	case WSDISPLAY_FONTENC_IBM:
1117 		return (pcdisplay_mapchar(id, uni, index));
1118 	default:
1119 #ifdef VGAFONTDEBUG
1120 		printf("_vga_mapchar: encoding=%d\n", font->encoding);
1121 #endif
1122 		*index = '?';
1123 		return (0);
1124 	}
1125 }
1126 
1127 int
1128 vga_mapchar(void *id, int uni, unsigned int *index)
1129 {
1130 	struct vgascreen *scr = id;
1131 	unsigned int idx1, idx2;
1132 	int res1, res2;
1133 
1134 	res1 = 0;
1135 	idx1 = ' '; /* space */
1136 	if (scr->fontset1)
1137 		res1 = _vga_mapchar(id, scr->fontset1, uni, &idx1);
1138 	res2 = -1;
1139 	if (scr->fontset2) {
1140 		KASSERT(VGA_SCREEN_CANTWOFONTS(scr->pcs.type));
1141 		res2 = _vga_mapchar(id, scr->fontset2, uni, &idx2);
1142 	}
1143 	if (res2 >= res1) {
1144 		*index = idx2 | 0x0800; /* attribute bit 3 */
1145 		return (res2);
1146 	}
1147 	*index = idx1;
1148 	return (res1);
1149 }
1150 
1151 int
1152 vga_putchar(void *c, int row, int col, u_int uc, long attr)
1153 {
1154 	struct vgascreen *scr = c;
1155 	int rc;
1156 	int s;
1157 
1158 	s = spltty();
1159 	if (scr->pcs.active && scr->pcs.visibleoffset != scr->pcs.dispoffset)
1160 		vga_scrollback(scr->cfg, scr, 0);
1161 	rc = pcdisplay_putchar(c, row, col, uc, attr);
1162 	splx(s);
1163 
1164 	return rc;
1165 }
1166 
1167 void
1168 vga_burner(void *v, u_int on, u_int flags)
1169 {
1170 	struct vga_config *vc = v;
1171 	struct vga_handle *vh = &vc->hdl;
1172 	u_int8_t r;
1173 	int s;
1174 
1175 	s = splhigh();
1176 	vga_ts_write(vh, syncreset, 0x01);
1177 	if (on) {
1178 		vga_ts_write(vh, mode, (vga_ts_read(vh, mode) & ~0x20));
1179 		r = vga_6845_read(vh, mode) | 0x80;
1180 		DELAY(10000);
1181 		vga_6845_write(vh, mode, r);
1182 	} else {
1183 		vga_ts_write(vh, mode, (vga_ts_read(vh, mode) | 0x20));
1184 		if (flags & WSDISPLAY_BURN_VBLANK) {
1185 			r = vga_6845_read(vh, mode) & ~0x80;
1186 			DELAY(10000);
1187 			vga_6845_write(vh, mode, r);
1188 		}
1189 	}
1190 	vga_ts_write(vh, syncreset, 0x03);
1191 	splx(s);
1192 }
1193 
1194 int
1195 vga_getchar(void *c, int row, int col, struct wsdisplay_charcell *cell)
1196 {
1197 	struct vga_config *vc = c;
1198 
1199 	return (pcdisplay_getchar(vc->active, row, col, cell));
1200 }
1201 
1202 void
1203 vga_save_palette(struct vga_config *vc)
1204 {
1205 	struct vga_handle *vh = &vc->hdl;
1206 	uint i;
1207 	uint8_t *palette = vc->vc_palette;
1208 
1209 	if (vh->vh_mono)
1210 		return;
1211 
1212 	vga_raw_write(vh, VGA_DAC_MASK, 0xff);
1213 	vga_raw_write(vh, VGA_DAC_READ, 0x00);
1214 	for (i = 0; i < 3 * 256; i++)
1215 		*palette++ = vga_raw_read(vh, VGA_DAC_DATA);
1216 
1217 	vga_raw_read(vh, 0x0a);			/* reset flip/flop */
1218 }
1219 
1220 void
1221 vga_restore_palette(struct vga_config *vc)
1222 {
1223 	struct vga_handle *vh = &vc->hdl;
1224 	uint i;
1225 	uint8_t *palette = vc->vc_palette;
1226 
1227 	if (vh->vh_mono)
1228 		return;
1229 
1230 	vga_raw_write(vh, VGA_DAC_MASK, 0xff);
1231 	vga_raw_write(vh, VGA_DAC_WRITE, 0x00);
1232 	for (i = 0; i < 3 * 256; i++)
1233 		vga_raw_write(vh, VGA_DAC_DATA, *palette++);
1234 
1235 	vga_raw_read(vh, 0x0a);			/* reset flip/flop */
1236 
1237 	vga_enable(vh);
1238 }
1239 
1240 void
1241 vga_restore_fonts(struct vga_config *vc)
1242 {
1243 	int slot;
1244 	struct vgafont *f;
1245 
1246 	for (slot = 0; slot < VGA_MAXFONT; slot++) {
1247 		f = vc->vc_fonts[slot];
1248 		if (f == NULL || f->fontdata == NULL)
1249 			continue;
1250 
1251 		vga_loadchars(&vc->hdl, slot, 0, 256, f->height, f->fontdata);
1252 	}
1253 }
1254 
1255 #ifdef __alpha__
1256 void
1257 vga_pick_monitor_type(struct vga_config *vc)
1258 {
1259 	struct vga_handle *vh = &vc->hdl;
1260 
1261 	/*
1262 	 * The Tadpole Alphabook1 uses a 800x600 flat panel in text mode,
1263 	 * causing the display console to really be 100x37 instead of the
1264 	 * usual 80x25.
1265 	 * We attempt to detect this here by checking the CRTC registers.
1266 	 */
1267 	unsigned int hend, oflow, vend;
1268 	unsigned int width, height;
1269 
1270 	hend = vga_6845_read(vh, hdisple);
1271 	oflow = vga_6845_read(vh, overfll);
1272 	vend = vga_6845_read(vh, vde);
1273 	if (oflow & 0x02)
1274 		vend |= 0x100;
1275 	if (oflow & 0x40)
1276 		vend |= 0x200;
1277 
1278 	width = hend + 1;
1279 	height = (vend + 1) / 16;
1280 
1281 	/* check that the values sound plausible */
1282 	if ((width > 80 && width <= 128) && (height > 25 && height <= 50)) {
1283 		snprintf(vc->custom_scr.name, sizeof(vc->custom_scr.name),
1284 		    "%ux%u", width, height);
1285 		vc->custom_scr.ncols = width;
1286 		vc->custom_scr.nrows = height;
1287 		vc->custom_scr.textops = &vga_emulops;
1288 		vc->custom_scr.fontwidth = 8;
1289 		vc->custom_scr.fontheight = 16;
1290 		vc->custom_scr.capabilities =
1291 		    WSSCREEN_WSCOLORS | WSSCREEN_HILIT | WSSCREEN_BLINK;
1292 		vc->custom_scrlist[0] = &vc->custom_scr;
1293 		vc->custom_list.nscreens = 1;
1294 		vc->custom_list.screens =
1295 		    (const struct wsscreen_descr **)vc->custom_scrlist;
1296 	}
1297 }
1298 #endif
1299 
1300 struct cfdriver vga_cd = {
1301 	NULL, "vga", DV_DULL
1302 };
1303