2 * Copyright (c) 1999 Kazutaka YOKOTA <yokota@zodiac.mech.utsunomiya-u.ac.jp>
3 * Copyright (c) 1992-1998 Søren Schmidt
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer as
11 * the first lines of this file unmodified.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. The name of the author may not be used to endorse or promote products
16 * derived from this software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 * $FreeBSD: src/sys/dev/fb/vga.c,v 1.9.2.1 2001/08/11 02:58:44 yokota Exp $
34 #include "opt_syscons.h" /* should be removed in the future, XXX */
36 #include <sys/param.h>
37 #include <sys/systm.h>
38 #include <sys/kernel.h>
41 #include <sys/fcntl.h>
42 #include <sys/malloc.h>
46 #include <vm/vm_param.h>
49 #include <machine/md_var.h>
50 #include <machine/pc/bios.h>
52 #include <dev/fb/fbreg.h>
53 #include <dev/fb/vgareg.h>
55 #include <isa/isareg.h>
62 vga_probe_unit(int unit, video_adapter_t *buf, int flags)
68 sw = vid_get_switch(VGA_DRIVER_NAME);
71 error = (*sw->probe)(unit, &adp, NULL, flags);
74 bcopy(adp, buf, sizeof(*buf));
79 vga_attach_unit(int unit, vga_softc_t *sc, int flags)
84 sw = vid_get_switch(VGA_DRIVER_NAME);
88 error = (*sw->probe)(unit, &sc->adp, NULL, flags);
91 return (*sw->init)(unit, sc->adp, flags);
94 /* cdev driver functions */
96 #ifdef FB_INSTALL_CDEV
99 vga_open(dev_t dev, vga_softc_t *sc, int flag, int mode, struct proc *p)
103 if (mode & (O_CREAT | O_APPEND | O_TRUNC))
106 return genfbopen(&sc->gensc, sc->adp, flag, mode, p);
110 vga_close(dev_t dev, vga_softc_t *sc, int flag, int mode, struct proc *p)
112 return genfbclose(&sc->gensc, sc->adp, flag, mode, p);
116 vga_read(dev_t dev, vga_softc_t *sc, struct uio *uio, int flag)
118 return genfbread(&sc->gensc, sc->adp, uio, flag);
122 vga_write(dev_t dev, vga_softc_t *sc, struct uio *uio, int flag)
124 return genfbread(&sc->gensc, sc->adp, uio, flag);
128 vga_ioctl(dev_t dev, vga_softc_t *sc, u_long cmd, caddr_t arg, int flag,
131 return genfbioctl(&sc->gensc, sc->adp, cmd, arg, flag, p);
135 vga_mmap(dev_t dev, vga_softc_t *sc, vm_offset_t offset, int prot)
137 return genfbmmap(&sc->gensc, sc->adp, offset, prot);
140 #endif /* FB_INSTALL_CDEV */
144 #include <machine/clock.h>
145 #include <machine/pc/vesa.h>
147 #define probe_done(adp) ((adp)->va_flags & V_ADP_PROBED)
148 #define init_done(adp) ((adp)->va_flags & V_ADP_INITIALIZED)
149 #define config_done(adp) ((adp)->va_flags & V_ADP_REGISTERED)
151 /* for compatibility with old kernel options */
152 #ifdef SC_ALT_SEQACCESS
153 #undef SC_ALT_SEQACCESS
154 #undef VGA_ALT_SEQACCESS
155 #define VGA_ALT_SEQACCESS 1
160 #undef VGA_SLOW_IOACCESS
161 #define VGA_SLOW_IOACCESS 1
164 /* architecture dependent option */
166 #define VGA_NO_BIOS 1
169 /* this should really be in `rtc.h' */
170 #define RTC_EQUIPMENT 0x14
173 #define V_MODE_MAP_SIZE (M_VGA_CG320 + 1)
174 #define V_MODE_PARAM_SIZE 64
176 /* video adapter state buffer */
179 #define V_STATE_SIG 0x736f6962
180 u_char regs[V_MODE_PARAM_SIZE];
182 typedef struct adp_state adp_state_t;
184 /* video adapter information */
188 #define DCC_EGAMONO 3
193 * NOTE: `va_window' should have a virtual address, but is initialized
194 * with a physical address in the following table, as verify_adapter()
195 * will perform address conversion at run-time.
197 static video_adapter_t adapter_init_value[] = {
199 { 0, KD_MONO, "mda", 0, 0, 0, IO_MDA, IO_MDASIZE, MONO_CRTC,
200 MDA_BUF_BASE, MDA_BUF_SIZE, MDA_BUF_BASE, MDA_BUF_SIZE, MDA_BUF_SIZE,
203 { 0, KD_CGA, "cga", 0, 0, V_ADP_COLOR, IO_CGA, IO_CGASIZE, COLOR_CRTC,
204 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE,
207 { 0, KD_CGA, "cga", 0, 0, V_ADP_COLOR, IO_CGA, IO_CGASIZE, COLOR_CRTC,
208 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE,
211 { 0, KD_EGA, "ega", 0, 0, 0, IO_MDA, 48, MONO_CRTC,
212 EGA_BUF_BASE, EGA_BUF_SIZE, MDA_BUF_BASE, MDA_BUF_SIZE, MDA_BUF_SIZE,
215 { 0, KD_EGA, "ega", 0, 0, V_ADP_COLOR, IO_MDA, 48, COLOR_CRTC,
216 EGA_BUF_BASE, EGA_BUF_SIZE, CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE,
219 { 0, KD_EGA, "ega", 0, 0, V_ADP_COLOR, IO_MDA, 48, COLOR_CRTC,
220 EGA_BUF_BASE, EGA_BUF_SIZE, CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE,
224 static video_adapter_t biosadapter[2];
225 static int biosadapters = 0;
227 /* video driver declarations */
228 static int vga_configure(int flags);
229 int (*vga_sub_configure)(int flags);
231 static int vga_nop(void);
233 static int vga_error(void);
234 static vi_probe_t vga_probe;
235 static vi_init_t vga_init;
236 static vi_get_info_t vga_get_info;
237 static vi_query_mode_t vga_query_mode;
238 static vi_set_mode_t vga_set_mode;
239 static vi_save_font_t vga_save_font;
240 static vi_load_font_t vga_load_font;
241 static vi_show_font_t vga_show_font;
242 static vi_save_palette_t vga_save_palette;
243 static vi_load_palette_t vga_load_palette;
244 static vi_set_border_t vga_set_border;
245 static vi_save_state_t vga_save_state;
246 static vi_load_state_t vga_load_state;
247 static vi_set_win_org_t vga_set_origin;
248 static vi_read_hw_cursor_t vga_read_hw_cursor;
249 static vi_set_hw_cursor_t vga_set_hw_cursor;
250 static vi_set_hw_cursor_shape_t vga_set_hw_cursor_shape;
251 static vi_blank_display_t vga_blank_display;
252 static vi_mmap_t vga_mmap_buf;
253 static vi_ioctl_t vga_dev_ioctl;
254 #ifndef VGA_NO_MODE_CHANGE
255 static vi_clear_t vga_clear;
256 static vi_fill_rect_t vga_fill_rect;
257 static vi_bitblt_t vga_bitblt;
258 #else /* VGA_NO_MODE_CHANGE */
259 #define vga_clear (vi_clear_t *)vga_error
260 #define vga_fill_rect (vi_fill_rect_t *)vga_error
261 #define vga_bitblt (vi_bitblt_t *)vga_error
263 static vi_diag_t vga_diag;
265 static video_switch_t vgavidsw = {
282 vga_set_hw_cursor_shape,
294 VIDEO_DRIVER(mda, vgavidsw, NULL);
295 VIDEO_DRIVER(cga, vgavidsw, NULL);
296 VIDEO_DRIVER(ega, vgavidsw, NULL);
297 VIDEO_DRIVER(vga, vgavidsw, vga_configure);
299 /* VGA BIOS standard video modes */
303 static video_info_t bios_vmode[] = {
305 { M_B40x25, V_INFO_COLOR, 40, 25, 8, 8, 2, 1,
306 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
307 { M_C40x25, V_INFO_COLOR, 40, 25, 8, 8, 4, 1,
308 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
309 { M_B80x25, V_INFO_COLOR, 80, 25, 8, 8, 2, 1,
310 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
311 { M_C80x25, V_INFO_COLOR, 80, 25, 8, 8, 4, 1,
312 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
314 { M_ENH_B40x25, V_INFO_COLOR, 40, 25, 8, 14, 2, 1,
315 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
316 { M_ENH_C40x25, V_INFO_COLOR, 40, 25, 8, 14, 4, 1,
317 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
318 { M_ENH_B80x25, V_INFO_COLOR, 80, 25, 8, 14, 2, 1,
319 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
320 { M_ENH_C80x25, V_INFO_COLOR, 80, 25, 8, 14, 4, 1,
321 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
323 { M_VGA_C40x25, V_INFO_COLOR, 40, 25, 8, 16, 4, 1,
324 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
325 { M_VGA_M80x25, 0, 80, 25, 8, 16, 2, 1,
326 MDA_BUF_BASE, MDA_BUF_SIZE, MDA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
327 { M_VGA_C80x25, V_INFO_COLOR, 80, 25, 8, 16, 4, 1,
328 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
330 { M_EGAMONO80x25, 0, 80, 25, 8, 14, 2, 1,
331 MDA_BUF_BASE, MDA_BUF_SIZE, MDA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
333 { M_ENH_B80x43, 0, 80, 43, 8, 8, 2, 1,
334 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
335 { M_ENH_C80x43, V_INFO_COLOR, 80, 43, 8, 8, 4, 1,
336 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
338 { M_VGA_M80x30, 0, 80, 30, 8, 16, 2, 1,
339 MDA_BUF_BASE, MDA_BUF_SIZE, MDA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
340 { M_VGA_C80x30, V_INFO_COLOR, 80, 30, 8, 16, 4, 1,
341 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
342 { M_VGA_M80x50, 0, 80, 50, 8, 8, 2, 1,
343 MDA_BUF_BASE, MDA_BUF_SIZE, MDA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
344 { M_VGA_C80x50, V_INFO_COLOR, 80, 50, 8, 8, 4, 1,
345 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
346 { M_VGA_M80x60, 0, 80, 60, 8, 8, 2, 1,
347 MDA_BUF_BASE, MDA_BUF_SIZE, MDA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
348 { M_VGA_C80x60, V_INFO_COLOR, 80, 60, 8, 8, 4, 1,
349 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
351 #ifndef VGA_NO_MODE_CHANGE
354 { M_VGA_M90x25, 0, 90, 25, 8, 16, 2, 1,
355 MDA_BUF_BASE, MDA_BUF_SIZE, MDA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
356 { M_VGA_C90x25, V_INFO_COLOR, 90, 25, 8, 16, 4, 1,
357 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
358 { M_VGA_M90x30, 0, 90, 30, 8, 16, 2, 1,
359 MDA_BUF_BASE, MDA_BUF_SIZE, MDA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
360 { M_VGA_C90x30, V_INFO_COLOR, 90, 30, 8, 16, 4, 1,
361 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
362 { M_VGA_M90x43, 0, 90, 43, 8, 8, 2, 1,
363 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
364 { M_VGA_C90x43, V_INFO_COLOR, 90, 43, 8, 8, 4, 1,
365 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
366 { M_VGA_M90x50, 0, 90, 50, 8, 8, 2, 1,
367 MDA_BUF_BASE, MDA_BUF_SIZE, MDA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
368 { M_VGA_C90x50, V_INFO_COLOR, 90, 50, 8, 8, 4, 1,
369 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
370 { M_VGA_M90x60, 0, 90, 60, 8, 8, 2, 1,
371 MDA_BUF_BASE, MDA_BUF_SIZE, MDA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
372 { M_VGA_C90x60, V_INFO_COLOR, 90, 60, 8, 8, 4, 1,
373 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
374 #endif /* VGA_WIDTH90 */
377 { M_BG320, V_INFO_COLOR | V_INFO_GRAPHICS, 320, 200, 8, 8, 2, 1,
378 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_CGA },
379 { M_CG320, V_INFO_COLOR | V_INFO_GRAPHICS, 320, 200, 8, 8, 2, 1,
380 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_CGA },
381 { M_BG640, V_INFO_COLOR | V_INFO_GRAPHICS, 640, 200, 8, 8, 1, 1,
382 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_CGA },
384 { M_CG320_D, V_INFO_COLOR | V_INFO_GRAPHICS, 320, 200, 8, 8, 4, 4,
385 GRAPHICS_BUF_BASE, GRAPHICS_BUF_SIZE, GRAPHICS_BUF_SIZE, 0, 0,
387 { M_CG640_E, V_INFO_COLOR | V_INFO_GRAPHICS, 640, 200, 8, 8, 4, 4,
388 GRAPHICS_BUF_BASE, GRAPHICS_BUF_SIZE, GRAPHICS_BUF_SIZE, 0, 0 ,
390 { M_EGAMONOAPA, V_INFO_GRAPHICS, 640, 350, 8, 14, 4, 4,
391 GRAPHICS_BUF_BASE, GRAPHICS_BUF_SIZE, 64*1024, 0, 0 ,
393 { M_ENHMONOAPA2,V_INFO_GRAPHICS, 640, 350, 8, 14, 4, 4,
394 GRAPHICS_BUF_BASE, GRAPHICS_BUF_SIZE, GRAPHICS_BUF_SIZE, 0, 0 ,
396 { M_CG640x350, V_INFO_COLOR | V_INFO_GRAPHICS, 640, 350, 8, 14, 2, 2,
397 GRAPHICS_BUF_BASE, GRAPHICS_BUF_SIZE, GRAPHICS_BUF_SIZE, 0, 0 ,
399 { M_ENH_CG640, V_INFO_COLOR | V_INFO_GRAPHICS, 640, 350, 8, 14, 4, 4,
400 GRAPHICS_BUF_BASE, GRAPHICS_BUF_SIZE, GRAPHICS_BUF_SIZE, 0, 0 ,
403 { M_BG640x480, V_INFO_COLOR | V_INFO_GRAPHICS, 640, 480, 8, 16, 4, 4,
404 GRAPHICS_BUF_BASE, GRAPHICS_BUF_SIZE, GRAPHICS_BUF_SIZE, 0, 0 ,
406 { M_CG640x480, V_INFO_COLOR | V_INFO_GRAPHICS, 640, 480, 8, 16, 4, 4,
407 GRAPHICS_BUF_BASE, GRAPHICS_BUF_SIZE, GRAPHICS_BUF_SIZE, 0, 0 ,
409 { M_VGA_CG320, V_INFO_COLOR | V_INFO_GRAPHICS, 320, 200, 8, 8, 8, 1,
410 GRAPHICS_BUF_BASE, GRAPHICS_BUF_SIZE, GRAPHICS_BUF_SIZE, 0, 0,
411 V_INFO_MM_PACKED, 1 },
412 { M_VGA_MODEX, V_INFO_COLOR | V_INFO_GRAPHICS, 320, 240, 8, 8, 8, 4,
413 GRAPHICS_BUF_BASE, GRAPHICS_BUF_SIZE, GRAPHICS_BUF_SIZE, 0, 0,
415 #endif /* VGA_NO_MODE_CHANGE */
420 static int vga_init_done = FALSE;
421 #if !defined(VGA_NO_BIOS) && !defined(VGA_NO_MODE_CHANGE)
422 static u_char *video_mode_ptr = NULL; /* EGA/VGA */
423 static u_char *video_mode_ptr2 = NULL; /* CGA/MDA */
425 static u_char *mode_map[V_MODE_MAP_SIZE];
426 static adp_state_t adpstate;
427 static adp_state_t adpstate2;
428 static int rows_offset = 1;
430 /* local macros and functions */
431 #define BIOS_SADDRTOLADDR(p) ((((p) & 0xffff0000) >> 12) + ((p) & 0x0000ffff))
433 #if !defined(VGA_NO_BIOS) && !defined(VGA_NO_MODE_CHANGE)
434 static void map_mode_table(u_char *map[], u_char *table, int max);
436 static void clear_mode_map(video_adapter_t *adp, u_char *map[], int max,
438 #if !defined(VGA_NO_BIOS) && !defined(VGA_NO_MODE_CHANGE)
439 static int map_mode_num(int mode);
441 static int map_gen_mode_num(int type, int color, int mode);
442 static int map_bios_mode_num(int type, int color, int bios_mode);
443 static u_char *get_mode_param(int mode);
445 static void fill_adapter_param(int code, video_adapter_t *adp);
447 static int verify_adapter(video_adapter_t *adp);
448 static void update_adapter_info(video_adapter_t *adp, video_info_t *info);
449 #if !defined(VGA_NO_BIOS) && !defined(VGA_NO_MODE_CHANGE)
450 #define COMP_IDENTICAL 0
451 #define COMP_SIMILAR 1
452 #define COMP_DIFFERENT 2
453 static int comp_adpregs(u_char *buf1, u_char *buf2);
455 static int probe_adapters(void);
456 static int set_line_length(video_adapter_t *adp, int pixel);
457 static int set_display_start(video_adapter_t *adp, int x, int y);
458 static void filll_io(int val, vm_offset_t d, size_t size);
460 #ifndef VGA_NO_MODE_CHANGE
462 static void set_width90(adp_state_t *params);
464 #endif /* !VGA_NO_MODE_CHANGE */
466 #ifndef VGA_NO_FONT_LOADING
467 #define PARAM_BUFSIZE 6
468 static void set_font_mode(video_adapter_t *adp, u_char *buf);
469 static void set_normal_mode(video_adapter_t *adp, u_char *buf);
472 #ifndef VGA_NO_MODE_CHANGE
473 static void planar_fill(video_adapter_t *adp, int val);
474 static void packed_fill(video_adapter_t *adp, int val);
475 static void direct_fill(video_adapter_t *adp, int val);
477 static void planar_fill_rect(video_adapter_t *adp, int val, int x, int y,
479 static void packed_fill_rect(video_adapter_t *adp, int val, int x, int y,
481 static void direct_fill_rect16(video_adapter_t *adp, int val, int x, int y,
483 static void direct_fill_rect24(video_adapter_t *adp, int val, int x, int y,
485 static void direct_fill_rect32(video_adapter_t *adp, int val, int x, int y,
488 #endif /* !VGA_NO_MODE_CHANGE */
490 static void dump_buffer(u_char *buf, size_t len);
492 #define ISMAPPED(pa, width) \
493 (((pa) <= (u_long)0x1000 - (width)) \
494 || ((pa) >= ISA_HOLE_START && (pa) <= 0x100000 - (width)))
496 #define prologue(adp, flag, err) \
497 if (!vga_init_done || !((adp)->va_flags & (flag))) \
500 /* a backdoor for the console driver */
502 vga_configure(int flags)
507 for (i = 0; i < biosadapters; ++i) {
508 if (!probe_done(&biosadapter[i]))
510 biosadapter[i].va_flags |= V_ADP_INITIALIZED;
511 if (!config_done(&biosadapter[i])) {
512 if (vid_register(&biosadapter[i]) < 0)
514 biosadapter[i].va_flags |= V_ADP_REGISTERED;
517 if (vga_sub_configure != NULL)
518 (*vga_sub_configure)(flags);
523 /* local subroutines */
525 #if !defined(VGA_NO_BIOS) && !defined(VGA_NO_MODE_CHANGE)
526 /* construct the mode parameter map */
528 map_mode_table(u_char *map[], u_char *table, int max)
532 for(i = 0; i < max; ++i)
533 map[i] = table + i*V_MODE_PARAM_SIZE;
534 for(; i < V_MODE_MAP_SIZE; ++i)
537 #endif /* !VGA_NO_BIOS && !VGA_NO_MODE_CHANGE */
540 clear_mode_map(video_adapter_t *adp, u_char *map[], int max, int color)
546 * NOTE: we don't touch `bios_vmode[]' because it is shared
549 for(i = 0; i < max; ++i) {
550 if (vga_get_info(adp, i, &info))
552 if ((info.vi_flags & V_INFO_COLOR) != color)
557 #if !defined(VGA_NO_BIOS) && !defined(VGA_NO_MODE_CHANGE)
558 /* map the non-standard video mode to a known mode number */
560 map_mode_num(int mode)
566 { M_ENH_B80x43, M_ENH_B80x25 },
567 { M_ENH_C80x43, M_ENH_C80x25 },
568 { M_VGA_M80x30, M_VGA_M80x25 },
569 { M_VGA_C80x30, M_VGA_C80x25 },
570 { M_VGA_M80x50, M_VGA_M80x25 },
571 { M_VGA_C80x50, M_VGA_C80x25 },
572 { M_VGA_M80x60, M_VGA_M80x25 },
573 { M_VGA_C80x60, M_VGA_C80x25 },
575 { M_VGA_M90x25, M_VGA_M80x25 },
576 { M_VGA_C90x25, M_VGA_C80x25 },
577 { M_VGA_M90x30, M_VGA_M80x25 },
578 { M_VGA_C90x30, M_VGA_C80x25 },
579 { M_VGA_M90x43, M_ENH_B80x25 },
580 { M_VGA_C90x43, M_ENH_C80x25 },
581 { M_VGA_M90x50, M_VGA_M80x25 },
582 { M_VGA_C90x50, M_VGA_C80x25 },
583 { M_VGA_M90x60, M_VGA_M80x25 },
584 { M_VGA_C90x60, M_VGA_C80x25 },
586 { M_VGA_MODEX, M_VGA_CG320 },
590 for (i = 0; i < sizeof(mode_map)/sizeof(mode_map[0]); ++i) {
591 if (mode_map[i].from == mode)
592 return mode_map[i].to;
596 #endif /* !VGA_NO_BIOS && !VGA_NO_MODE_CHANGE */
598 /* map a generic video mode to a known mode number */
600 map_gen_mode_num(int type, int color, int mode)
607 { M_TEXT_80x30, M_VGA_C80x30, M_VGA_M80x30, },
608 { M_TEXT_80x43, M_ENH_C80x43, M_ENH_B80x43, },
609 { M_TEXT_80x50, M_VGA_C80x50, M_VGA_M80x50, },
610 { M_TEXT_80x60, M_VGA_C80x60, M_VGA_M80x60, },
614 if (mode == M_TEXT_80x25) {
628 return M_EGAMONO80x25;
636 return M_EGAMONO80x25; /* XXX: this name is confusing */
643 for (i = 0; i < sizeof(mode_map)/sizeof(mode_map[0]); ++i) {
644 if (mode_map[i].from == mode)
645 return ((color) ? mode_map[i].to_color : mode_map[i].to_mono);
650 /* turn the BIOS video number into our video mode number */
652 map_bios_mode_num(int type, int color, int bios_mode)
654 static int cga_modes[7] = {
655 M_B40x25, M_C40x25, /* 0, 1 */
656 M_B80x25, M_C80x25, /* 2, 3 */
660 static int ega_modes[17] = {
661 M_ENH_B40x25, M_ENH_C40x25, /* 0, 1 */
662 M_ENH_B80x25, M_ENH_C80x25, /* 2, 3 */
665 M_EGAMONO80x25, /* 7 */
669 M_ENHMONOAPA2, /* XXX: video momery > 64K */
670 M_ENH_CG640, /* XXX: video momery > 64K */
672 static int vga_modes[20] = {
673 M_VGA_C40x25, M_VGA_C40x25, /* 0, 1 */
674 M_VGA_C80x25, M_VGA_C80x25, /* 2, 3 */
677 M_VGA_M80x25, /* 7 */
683 M_BG640x480, M_CG640x480,
690 if (bios_mode < sizeof(vga_modes)/sizeof(vga_modes[0]))
691 return vga_modes[bios_mode];
699 if (bios_mode < sizeof(ega_modes)/sizeof(ega_modes[0]))
700 return ega_modes[bios_mode];
704 return M_EGAMONO80x25;
708 if (bios_mode < sizeof(cga_modes)/sizeof(cga_modes[0]))
709 return cga_modes[bios_mode];
716 return M_EGAMONO80x25; /* XXX: this name is confusing */
724 /* look up a parameter table entry */
726 *get_mode_param(int mode)
728 #if !defined(VGA_NO_BIOS) && !defined(VGA_NO_MODE_CHANGE)
729 if (mode >= V_MODE_MAP_SIZE)
730 mode = map_mode_num(mode);
732 if ((mode >= 0) && (mode < V_MODE_MAP_SIZE))
733 return mode_map[mode];
740 fill_adapter_param(int code, video_adapter_t *adp)
746 { DCC_MONO, DCC_EGA40 /* CGA monitor */ },
747 { DCC_MONO, DCC_EGA80 /* CGA monitor */ },
748 { DCC_MONO, DCC_EGA80 },
749 { DCC_MONO, DCC_EGA80 },
750 { DCC_CGA40, DCC_EGAMONO },
751 { DCC_CGA80, DCC_EGAMONO },
752 { DCC_EGA40 /* CGA monitor */, DCC_MONO},
753 { DCC_EGA80 /* CGA monitor */, DCC_MONO},
754 { DCC_EGA80, DCC_MONO },
755 { DCC_EGA80, DCC_MONO },
756 { DCC_EGAMONO, DCC_CGA40 },
757 { DCC_EGAMONO, DCC_CGA80 },
760 if ((code < 0) || (code >= sizeof(dcc)/sizeof(dcc[0]))) {
761 adp[V_ADP_PRIMARY] = adapter_init_value[DCC_MONO];
762 adp[V_ADP_SECONDARY] = adapter_init_value[DCC_CGA80];
764 adp[V_ADP_PRIMARY] = adapter_init_value[dcc[code].primary];
765 adp[V_ADP_SECONDARY] = adapter_init_value[dcc[code].secondary];
768 #endif /* VGA_NO_BIOS */
771 verify_adapter(video_adapter_t *adp)
775 #if !defined(VGA_NO_BIOS) && !defined(VGA_NO_MODE_CHANGE)
779 buf = BIOS_PADDRTOVADDR(adp->va_window);
782 if (readw(buf) != 0xA55A)
786 switch (adp->va_type) {
789 outb(adp->va_crtc_addr, 7);
790 if (inb(adp->va_crtc_addr) == 7) {
791 adp->va_type = KD_VGA;
792 adp->va_name = "vga";
793 adp->va_flags |= V_ADP_STATESAVE | V_ADP_PALETTE;
795 adp->va_flags |= V_ADP_STATELOAD | V_ADP_BORDER;
796 /* the color adapter may be in the 40x25 mode... XXX */
798 #if !defined(VGA_NO_BIOS) && !defined(VGA_NO_MODE_CHANGE)
799 /* get the BIOS video mode pointer */
800 p = *(u_int32_t *)BIOS_PADDRTOVADDR(0x4a8);
801 p = BIOS_SADDRTOLADDR(p);
802 if (ISMAPPED(p, sizeof(u_int32_t))) {
803 p = *(u_int32_t *)BIOS_PADDRTOVADDR(p);
804 p = BIOS_SADDRTOLADDR(p);
805 if (ISMAPPED(p, V_MODE_PARAM_SIZE))
806 video_mode_ptr = (u_char *)BIOS_PADDRTOVADDR(p);
812 adp->va_flags |= V_ADP_COLOR | V_ADP_BORDER;
813 /* may be in the 40x25 mode... XXX */
814 #if !defined(VGA_NO_BIOS) && !defined(VGA_NO_MODE_CHANGE)
815 /* get the BIOS video mode pointer */
816 p = *(u_int32_t *)BIOS_PADDRTOVADDR(0x1d*4);
817 p = BIOS_SADDRTOLADDR(p);
818 video_mode_ptr2 = (u_char *)BIOS_PADDRTOVADDR(p);
823 #if !defined(VGA_NO_BIOS) && !defined(VGA_NO_MODE_CHANGE)
824 /* get the BIOS video mode pointer */
825 p = *(u_int32_t *)BIOS_PADDRTOVADDR(0x1d*4);
826 p = BIOS_SADDRTOLADDR(p);
827 video_mode_ptr2 = (u_char *)BIOS_PADDRTOVADDR(p);
836 update_adapter_info(video_adapter_t *adp, video_info_t *info)
838 adp->va_flags &= ~V_ADP_COLOR;
840 (info->vi_flags & V_INFO_COLOR) ? V_ADP_COLOR : 0;
842 (adp->va_flags & V_ADP_COLOR) ? COLOR_CRTC : MONO_CRTC;
843 adp->va_window = BIOS_PADDRTOVADDR(info->vi_window);
844 adp->va_window_size = info->vi_window_size;
845 adp->va_window_gran = info->vi_window_gran;
846 adp->va_window_orig = 0;
848 adp->va_buffer = info->vi_buffer;
849 adp->va_buffer_size = info->vi_buffer_size;
850 if (info->vi_mem_model == V_INFO_MM_VGAX) {
851 adp->va_line_width = info->vi_width/2;
852 } else if (info->vi_flags & V_INFO_GRAPHICS) {
853 switch (info->vi_depth/info->vi_planes) {
855 adp->va_line_width = info->vi_width/8;
858 adp->va_line_width = info->vi_width/4;
861 adp->va_line_width = info->vi_width/2;
864 default: /* shouldn't happen */
865 adp->va_line_width = info->vi_width;
869 adp->va_line_width = info->vi_width;
871 adp->va_disp_start.x = 0;
872 adp->va_disp_start.y = 0;
873 bcopy(info, &adp->va_info, sizeof(adp->va_info));
876 #if !defined(VGA_NO_BIOS) && !defined(VGA_NO_MODE_CHANGE)
877 /* compare two parameter table entries */
879 comp_adpregs(u_char *buf1, u_char *buf2)
883 } params[V_MODE_PARAM_SIZE] = {
884 {0xff}, {0x00}, {0xff}, /* COLS}, ROWS}, POINTS */
885 {0x00}, {0x00}, /* page length */
886 {0xfe}, {0xff}, {0xff}, {0xff}, /* sequencer registers */
887 {0xf3}, /* misc register */
888 {0xff}, {0xff}, {0xff}, {0x7f}, {0xff}, /* CRTC */
889 {0xff}, {0xff}, {0xff}, {0x7f}, {0xff},
890 {0x00}, {0x00}, {0x00}, {0x00}, {0x00},
891 {0x00}, {0xff}, {0x7f}, {0xff}, {0xff},
892 {0x7f}, {0xff}, {0xff}, {0xef}, {0xff},
893 {0xff}, {0xff}, {0xff}, {0xff}, {0xff}, /* attribute controller regs */
894 {0xff}, {0xff}, {0xff}, {0xff}, {0xff},
895 {0xff}, {0xff}, {0xff}, {0xff}, {0xff},
896 {0xff}, {0xff}, {0xff}, {0xff}, {0xf0},
897 {0xff}, {0xff}, {0xff}, {0xff}, {0xff}, /* GDC register */
898 {0xff}, {0xff}, {0xff}, {0xff},
900 int identical = TRUE;
903 if ((buf1 == NULL) || (buf2 == NULL))
904 return COMP_DIFFERENT;
906 for (i = 0; i < sizeof(params)/sizeof(params[0]); ++i) {
907 if (params[i].mask == 0) /* don't care */
909 if ((buf1[i] & params[i].mask) != (buf2[i] & params[i].mask))
910 return COMP_DIFFERENT;
911 if (buf1[i] != buf2[i])
914 return (identical) ? COMP_IDENTICAL : COMP_SIMILAR;
916 #endif /* !VGA_NO_BIOS && !VGA_NO_MODE_CHANGE */
918 /* probe video adapters and return the number of detected adapters */
922 video_adapter_t *adp;
924 #if !defined(VGA_NO_BIOS) && !defined(VGA_NO_MODE_CHANGE)
929 /* do this test only once */
932 vga_init_done = TRUE;
935 * Locate display adapters.
936 * The AT architecture supports upto two adapters. `syscons' allows
937 * the following combinations of adapters:
939 * 2) MDA + EGA/VGA color
940 * 3) CGA + EGA/VGA mono
941 * Note that `syscons' doesn't bother with MCGA as it is only
942 * avaiable for low end PS/2 models which has 80286 or earlier CPUs,
943 * thus, they are not running FreeBSD!
944 * When there are two adapaters in the system, one becomes `primary'
945 * and the other `secondary'. The EGA adapter has a set of DIP
946 * switches on board for this information and the EGA BIOS copies
947 * it in the BIOS data area BIOSDATA_VIDEOSWITCH (40:88).
948 * The VGA BIOS has more sophisticated mechanism and has this
949 * information in BIOSDATA_DCCINDEX (40:8a), but it also maintains
950 * compatibility with the EGA BIOS by updating BIOSDATA_VIDEOSWITCH.
954 * Check rtc and BIOS data area.
955 * XXX: we don't use BIOSDATA_EQUIPMENT, since it is not a dead
956 * copy of RTC_EQUIPMENT. Bits 4 and 5 of ETC_EQUIPMENT are
957 * zeros for EGA and VGA. However, the EGA/VGA BIOS sets
958 * these bits in BIOSDATA_EQUIPMENT according to the monitor
962 if (*(u_int32_t *)BIOS_PADDRTOVADDR(0x4a8)) {
963 /* EGA/VGA BIOS is present */
964 fill_adapter_param(readb(BIOS_PADDRTOVADDR(0x488)) & 0x0f,
967 switch ((rtcin(RTC_EQUIPMENT) >> 4) & 3) { /* bit 4 and 5 */
969 /* EGA/VGA: shouldn't be happening */
970 fill_adapter_param(readb(BIOS_PADDRTOVADDR(0x488)) & 0x0f,
975 /* FIXME: switch to the 80x25 mode? XXX */
976 biosadapter[V_ADP_PRIMARY] = adapter_init_value[DCC_CGA40];
977 biosadapter[V_ADP_SECONDARY] = adapter_init_value[DCC_MONO];
981 biosadapter[V_ADP_PRIMARY] = adapter_init_value[DCC_CGA80];
982 biosadapter[V_ADP_SECONDARY] = adapter_init_value[DCC_MONO];
986 biosadapter[V_ADP_PRIMARY] = adapter_init_value[DCC_MONO];
987 biosadapter[V_ADP_SECONDARY] = adapter_init_value[DCC_CGA80];
992 /* assume EGA/VGA? XXX */
993 biosadapter[V_ADP_PRIMARY] = adapter_init_value[DCC_EGA80];
994 biosadapter[V_ADP_SECONDARY] = adapter_init_value[DCC_MONO];
995 #endif /* VGA_NO_BIOS */
998 if (verify_adapter(&biosadapter[V_ADP_SECONDARY]) == 0) {
1000 biosadapter[V_ADP_SECONDARY].va_flags |= V_ADP_PROBED;
1001 biosadapter[V_ADP_SECONDARY].va_mode =
1002 biosadapter[V_ADP_SECONDARY].va_initial_mode =
1003 map_bios_mode_num(biosadapter[V_ADP_SECONDARY].va_type,
1004 biosadapter[V_ADP_SECONDARY].va_flags
1006 biosadapter[V_ADP_SECONDARY].va_initial_bios_mode);
1008 biosadapter[V_ADP_SECONDARY].va_type = -1;
1010 if (verify_adapter(&biosadapter[V_ADP_PRIMARY]) == 0) {
1012 biosadapter[V_ADP_PRIMARY].va_flags |= V_ADP_PROBED;
1014 biosadapter[V_ADP_PRIMARY].va_initial_bios_mode =
1015 readb(BIOS_PADDRTOVADDR(0x449));
1017 biosadapter[V_ADP_PRIMARY].va_initial_bios_mode = 3; /* XXX */
1019 biosadapter[V_ADP_PRIMARY].va_mode =
1020 biosadapter[V_ADP_PRIMARY].va_initial_mode =
1021 map_bios_mode_num(biosadapter[V_ADP_PRIMARY].va_type,
1022 biosadapter[V_ADP_PRIMARY].va_flags & V_ADP_COLOR,
1023 biosadapter[V_ADP_PRIMARY].va_initial_bios_mode);
1025 biosadapter[V_ADP_PRIMARY] = biosadapter[V_ADP_SECONDARY];
1026 biosadapter[V_ADP_SECONDARY].va_type = -1;
1028 if (biosadapters == 0)
1029 return biosadapters;
1030 biosadapter[V_ADP_PRIMARY].va_unit = V_ADP_PRIMARY;
1031 biosadapter[V_ADP_SECONDARY].va_unit = V_ADP_SECONDARY;
1033 #if 0 /* we don't need these... */
1034 fb_init_struct(&biosadapter[V_ADP_PRIMARY], ...);
1035 fb_init_struct(&biosadapter[V_ADP_SECONDARY], ...);
1040 * We cannot have two video adapter of the same type; there must be
1041 * only one of color or mono adapter, or one each of them.
1043 if (biosadapters > 1) {
1044 if (!((biosadapter[0].va_flags ^ biosadapter[1].va_flags)
1046 /* we have two mono or color adapters!! */
1047 return (biosadapters = 0);
1052 * Ensure a zero start address. This is mainly to recover after
1053 * switching from pcvt using userconfig(). The registers are w/o
1054 * for old hardware so it's too hard to relocate the active screen
1056 * This must be done before vga_save_state() for VGA.
1058 outb(biosadapter[V_ADP_PRIMARY].va_crtc_addr, 12);
1059 outb(biosadapter[V_ADP_PRIMARY].va_crtc_addr + 1, 0);
1060 outb(biosadapter[V_ADP_PRIMARY].va_crtc_addr, 13);
1061 outb(biosadapter[V_ADP_PRIMARY].va_crtc_addr + 1, 0);
1063 /* the video mode parameter table in EGA/VGA BIOS */
1064 /* NOTE: there can be only one EGA/VGA, wheather color or mono,
1065 * recognized by the video BIOS.
1067 if ((biosadapter[V_ADP_PRIMARY].va_type == KD_EGA) ||
1068 (biosadapter[V_ADP_PRIMARY].va_type == KD_VGA)) {
1069 adp = &biosadapter[V_ADP_PRIMARY];
1070 } else if ((biosadapter[V_ADP_SECONDARY].va_type == KD_EGA) ||
1071 (biosadapter[V_ADP_SECONDARY].va_type == KD_VGA)) {
1072 adp = &biosadapter[V_ADP_SECONDARY];
1076 bzero(mode_map, sizeof(mode_map));
1078 if (adp->va_type == KD_VGA) {
1079 vga_save_state(adp, &adpstate, sizeof(adpstate));
1080 #if defined(VGA_NO_BIOS) || defined(VGA_NO_MODE_CHANGE)
1081 mode_map[adp->va_initial_mode] = adpstate.regs;
1083 #else /* VGA_NO_BIOS || VGA_NO_MODE_CHANGE */
1084 if (video_mode_ptr == NULL) {
1085 mode_map[adp->va_initial_mode] = adpstate.regs;
1088 /* discard the table if we are not familiar with it... */
1089 map_mode_table(mode_map, video_mode_ptr, M_VGA_CG320 + 1);
1090 mp = get_mode_param(adp->va_initial_mode);
1092 bcopy(mp, adpstate2.regs, sizeof(adpstate2.regs));
1093 switch (comp_adpregs(adpstate.regs, mp)) {
1094 case COMP_IDENTICAL:
1096 * OK, this parameter table looks reasonably familiar
1100 * This is a kludge for Toshiba DynaBook SS433
1101 * whose BIOS video mode table entry has the actual #
1102 * of rows at the offset 1; BIOSes from other
1103 * manufacturers store the # of rows - 1 there. XXX
1105 rows_offset = adpstate.regs[1] + 1 - mp[1];
1110 * Not exactly the same, but similar enough to be
1111 * trusted. However, use the saved register values
1112 * for the initial mode and other modes which are
1113 * based on the initial mode.
1115 mode_map[adp->va_initial_mode] = adpstate.regs;
1116 rows_offset = adpstate.regs[1] + 1 - mp[1];
1117 adpstate.regs[1] -= rows_offset - 1;
1120 case COMP_DIFFERENT:
1123 * Don't use the paramter table in BIOS. It doesn't
1124 * look familiar to us. Video mode switching is allowed
1125 * only if the new mode is the same as or based on
1128 video_mode_ptr = NULL;
1129 bzero(mode_map, sizeof(mode_map));
1130 mode_map[adp->va_initial_mode] = adpstate.regs;
1135 #endif /* VGA_NO_BIOS || VGA_NO_MODE_CHANGE */
1137 #ifndef VGA_NO_MODE_CHANGE
1138 adp->va_flags |= V_ADP_MODECHANGE;
1140 #ifndef VGA_NO_FONT_LOADING
1141 adp->va_flags |= V_ADP_FONT;
1143 } else if (adp->va_type == KD_EGA) {
1144 #if defined(VGA_NO_BIOS) || defined(VGA_NO_MODE_CHANGE)
1146 #else /* VGA_NO_BIOS || VGA_NO_MODE_CHANGE */
1147 if (video_mode_ptr == NULL) {
1150 map_mode_table(mode_map, video_mode_ptr, M_ENH_C80x25 + 1);
1151 /* XXX how can one validate the EGA table... */
1152 mp = get_mode_param(adp->va_initial_mode);
1154 adp->va_flags |= V_ADP_MODECHANGE;
1155 #ifndef VGA_NO_FONT_LOADING
1156 adp->va_flags |= V_ADP_FONT;
1161 * This is serious. We will not be able to switch video
1164 video_mode_ptr = NULL;
1165 bzero(mode_map, sizeof(mode_map));
1169 #endif /* VGA_NO_BIOS || VGA_NO_MODE_CHANGE */
1173 /* remove conflicting modes if we have more than one adapter */
1174 if (biosadapters > 0) {
1175 for (i = 0; i < biosadapters; ++i) {
1176 if (!(biosadapter[i].va_flags & V_ADP_MODECHANGE))
1178 clear_mode_map(&biosadapter[i], mode_map, M_VGA_CG320 + 1,
1179 (biosadapter[i].va_flags & V_ADP_COLOR) ?
1181 if ((biosadapter[i].va_type == KD_VGA)
1182 || (biosadapter[i].va_type == KD_EGA)) {
1183 biosadapter[i].va_io_base =
1184 (biosadapter[i].va_flags & V_ADP_COLOR) ?
1186 biosadapter[i].va_io_size = 32;
1191 /* buffer address */
1192 vga_get_info(&biosadapter[V_ADP_PRIMARY],
1193 biosadapter[V_ADP_PRIMARY].va_initial_mode, &info);
1194 info.vi_flags &= ~V_INFO_LINEAR; /* XXX */
1195 update_adapter_info(&biosadapter[V_ADP_PRIMARY], &info);
1197 if (biosadapters > 1) {
1198 vga_get_info(&biosadapter[V_ADP_SECONDARY],
1199 biosadapter[V_ADP_SECONDARY].va_initial_mode, &info);
1200 info.vi_flags &= ~V_INFO_LINEAR; /* XXX */
1201 update_adapter_info(&biosadapter[V_ADP_SECONDARY], &info);
1205 * XXX: we should verify the following values for the primary adapter...
1206 * crtc I/O port address: *(u_int16_t *)BIOS_PADDRTOVADDR(0x463);
1207 * color/mono display: (*(u_int8_t *)BIOS_PADDRTOVADDR(0x487) & 0x02)
1208 * ? 0 : V_ADP_COLOR;
1209 * columns: *(u_int8_t *)BIOS_PADDRTOVADDR(0x44a);
1210 * rows: *(u_int8_t *)BIOS_PADDRTOVADDR(0x484);
1211 * font size: *(u_int8_t *)BIOS_PADDRTOVADDR(0x485);
1212 * buffer size: *(u_int16_t *)BIOS_PADDRTOVADDR(0x44c);
1215 return biosadapters;
1218 /* set the scan line length in pixel */
1220 set_line_length(video_adapter_t *adp, int pixel)
1223 int ppw; /* pixels per word */
1224 int bpl; /* bytes per line */
1227 if ((adp->va_type != KD_VGA) && (adp->va_type != KD_EGA))
1229 mp = get_mode_param(adp->va_mode);
1233 switch (adp->va_info.vi_mem_model) {
1234 case V_INFO_MM_PLANAR:
1235 ppw = 16/(adp->va_info.vi_depth/adp->va_info.vi_planes);
1236 count = (pixel + ppw - 1)/ppw/2;
1237 bpl = ((pixel + ppw - 1)/ppw/2)*4;
1239 case V_INFO_MM_PACKED:
1240 count = (pixel + 7)/8;
1241 bpl = ((pixel + 7)/8)*8;
1243 case V_INFO_MM_TEXT:
1244 count = (pixel + 7)/8; /* columns */
1245 bpl = (pixel + 7)/8; /* columns */
1251 if (mp[10 + 0x17] & 0x40) /* CRTC mode control reg */
1252 count *= 2; /* byte mode */
1253 outb(adp->va_crtc_addr, 0x13);
1254 outb(adp->va_crtc_addr + 1, count);
1255 adp->va_line_width = bpl;
1261 set_display_start(video_adapter_t *adp, int x, int y)
1263 int off; /* byte offset (graphics mode)/word offset (text mode) */
1264 int poff; /* pixel offset */
1265 int roff; /* row offset */
1266 int ppb; /* pixels per byte */
1268 if ((adp->va_type != KD_VGA) && (adp->va_type != KD_EGA))
1270 if (adp->va_info.vi_flags & V_INFO_GRAPHICS) {
1271 ppb = 8/(adp->va_info.vi_depth/adp->va_info.vi_planes);
1272 off = y*adp->va_line_width + x/ppb;
1276 if ((adp->va_type == KD_VGA) || (adp->va_type == KD_EGA)) {
1285 off = y/adp->va_info.vi_cheight*adp->va_line_width + x/ppb;
1286 roff = y%adp->va_info.vi_cheight;
1287 /* FIXME: is this correct? XXX */
1295 outb(adp->va_crtc_addr, 0xc); /* high */
1296 outb(adp->va_crtc_addr + 1, off >> 8);
1297 outb(adp->va_crtc_addr, 0xd); /* low */
1298 outb(adp->va_crtc_addr + 1, off & 0xff);
1300 /* horizontal pel pan */
1301 if ((adp->va_type == KD_VGA) || (adp->va_type == KD_EGA)) {
1302 inb(adp->va_crtc_addr + 6);
1303 outb(ATC, 0x13 | 0x20);
1305 inb(adp->va_crtc_addr + 6);
1309 /* preset raw scan */
1310 outb(adp->va_crtc_addr, 8);
1311 outb(adp->va_crtc_addr + 1, roff);
1313 adp->va_disp_start.x = x;
1314 adp->va_disp_start.y = y;
1318 #ifdef __i386__ /* XXX */
1320 fill(int val, void *d, size_t size)
1327 #endif /* __i386__ */
1330 filll_io(int val, vm_offset_t d, size_t size)
1332 while (size-- > 0) {
1334 d += sizeof(u_int32_t);
1355 vga_probe(int unit, video_adapter_t **adpp, void *arg, int flags)
1358 if (unit >= biosadapters)
1361 *adpp = &biosadapter[unit];
1367 vga_init(int unit, video_adapter_t *adp, int flags)
1369 if ((unit >= biosadapters) || (adp == NULL) || !probe_done(adp))
1372 if (!init_done(adp)) {
1373 /* nothing to do really... */
1374 adp->va_flags |= V_ADP_INITIALIZED;
1377 if (!config_done(adp)) {
1378 if (vid_register(adp) < 0)
1380 adp->va_flags |= V_ADP_REGISTERED;
1382 if (vga_sub_configure != NULL)
1383 (*vga_sub_configure)(0);
1390 * Return the video_info structure of the requested video mode.
1395 vga_get_info(video_adapter_t *adp, int mode, video_info_t *info)
1402 mode = map_gen_mode_num(adp->va_type, adp->va_flags & V_ADP_COLOR, mode);
1403 #ifndef VGA_NO_MODE_CHANGE
1404 if (adp->va_flags & V_ADP_MODECHANGE) {
1406 * If the parameter table entry for this mode is not found,
1407 * the mode is not supported...
1409 if (get_mode_param(mode) == NULL)
1412 #endif /* VGA_NO_MODE_CHANGE */
1415 * Even if we don't support video mode switching on this adapter,
1416 * the information on the initial (thus current) video mode
1417 * should be made available.
1419 if (mode != adp->va_initial_mode)
1423 for (i = 0; bios_vmode[i].vi_mode != EOT; ++i) {
1424 if (bios_vmode[i].vi_mode == NA)
1426 if (mode == bios_vmode[i].vi_mode) {
1427 *info = bios_vmode[i];
1429 info->vi_buffer_size = info->vi_window_size*info->vi_planes;
1438 * Find a video mode matching the requested parameters.
1439 * Fields filled with 0 are considered "don't care" fields and
1445 vga_query_mode(video_adapter_t *adp, video_info_t *info)
1452 for (i = 0; bios_vmode[i].vi_mode != EOT; ++i) {
1453 if (bios_vmode[i].vi_mode == NA)
1456 if ((info->vi_width != 0)
1457 && (info->vi_width != bios_vmode[i].vi_width))
1459 if ((info->vi_height != 0)
1460 && (info->vi_height != bios_vmode[i].vi_height))
1462 if ((info->vi_cwidth != 0)
1463 && (info->vi_cwidth != bios_vmode[i].vi_cwidth))
1465 if ((info->vi_cheight != 0)
1466 && (info->vi_cheight != bios_vmode[i].vi_cheight))
1468 if ((info->vi_depth != 0)
1469 && (info->vi_depth != bios_vmode[i].vi_depth))
1471 if ((info->vi_planes != 0)
1472 && (info->vi_planes != bios_vmode[i].vi_planes))
1474 /* XXX: should check pixel format, memory model */
1475 if ((info->vi_flags != 0)
1476 && (info->vi_flags != bios_vmode[i].vi_flags))
1479 /* verify if this mode is supported on this adapter */
1480 if (vga_get_info(adp, bios_vmode[i].vi_mode, info))
1489 * Change the video mode.
1494 #ifndef VGA_NO_MODE_CHANGE
1497 set_width90(adp_state_t *params)
1500 * Based on code submitted by Kelly Yancey (kbyanc@freedomnet.com)
1501 * and alexv@sui.gda.itesm.mx.
1503 params->regs[5] |= 1; /* toggle 8 pixel wide fonts */
1504 params->regs[10+0x0] = 0x6b;
1505 params->regs[10+0x1] = 0x59;
1506 params->regs[10+0x2] = 0x5a;
1507 params->regs[10+0x3] = 0x8e;
1508 params->regs[10+0x4] = 0x5e;
1509 params->regs[10+0x5] = 0x8a;
1510 params->regs[10+0x13] = 45;
1511 params->regs[35+0x13] = 0;
1513 #endif /* VGA_WIDTH90 */
1514 #endif /* !VGA_NO_MODE_CHANGE */
1517 vga_set_mode(video_adapter_t *adp, int mode)
1519 #ifndef VGA_NO_MODE_CHANGE
1523 prologue(adp, V_ADP_MODECHANGE, ENODEV);
1525 mode = map_gen_mode_num(adp->va_type,
1526 adp->va_flags & V_ADP_COLOR, mode);
1527 if (vga_get_info(adp, mode, &info))
1531 printf("vga_set_mode(): setting mode %d\n", mode);
1534 params.sig = V_STATE_SIG;
1535 bcopy(get_mode_param(mode), params.regs, sizeof(params.regs));
1539 case M_VGA_C90x60: case M_VGA_M90x60:
1540 set_width90(¶ms);
1543 case M_VGA_C80x60: case M_VGA_M80x60:
1544 params.regs[2] = 0x08;
1545 params.regs[19] = 0x47;
1549 case M_VGA_C90x30: case M_VGA_M90x30:
1550 set_width90(¶ms);
1553 case M_VGA_C80x30: case M_VGA_M80x30:
1554 params.regs[19] = 0x4f;
1556 params.regs[9] |= 0xc0;
1557 params.regs[16] = 0x08;
1558 params.regs[17] = 0x3e;
1559 params.regs[26] = 0xea;
1560 params.regs[28] = 0xdf;
1561 params.regs[31] = 0xe7;
1562 params.regs[32] = 0x04;
1566 case M_VGA_C90x43: case M_VGA_M90x43:
1567 set_width90(¶ms);
1570 case M_ENH_C80x43: case M_ENH_B80x43:
1571 params.regs[28] = 87;
1575 case M_VGA_C90x50: case M_VGA_M90x50:
1576 set_width90(¶ms);
1579 case M_VGA_C80x50: case M_VGA_M80x50:
1582 params.regs[19] = 7;
1586 case M_VGA_C90x25: case M_VGA_M90x25:
1587 set_width90(¶ms);
1590 case M_VGA_C40x25: case M_VGA_C80x25:
1592 case M_B40x25: case M_C40x25:
1593 case M_B80x25: case M_C80x25:
1594 case M_ENH_B40x25: case M_ENH_C40x25:
1595 case M_ENH_B80x25: case M_ENH_C80x25:
1596 case M_EGAMONO80x25:
1599 vga_load_state(adp, ¶ms);
1603 /* "unchain" the VGA mode */
1604 params.regs[5-1+0x04] &= 0xf7;
1605 params.regs[5-1+0x04] |= 0x04;
1606 /* turn off doubleword mode */
1607 params.regs[10+0x14] &= 0xbf;
1608 /* turn off word adressing */
1609 params.regs[10+0x17] |= 0x40;
1610 /* set logical screen width */
1611 params.regs[10+0x13] = 80;
1613 params.regs[10+0x11] = 0x2c;
1614 params.regs[10+0x06] = 0x0d;
1615 params.regs[10+0x07] = 0x3e;
1616 params.regs[10+0x10] = 0xea;
1617 params.regs[10+0x11] = 0xac;
1618 params.regs[10+0x12] = 0xdf;
1619 params.regs[10+0x15] = 0xe7;
1620 params.regs[10+0x16] = 0x06;
1621 /* set vertical sync polarity to reflect aspect ratio */
1622 params.regs[9] = 0xe3;
1625 case M_BG320: case M_CG320: case M_BG640:
1626 case M_CG320_D: case M_CG640_E:
1627 case M_CG640x350: case M_ENH_CG640:
1628 case M_BG640x480: case M_CG640x480: case M_VGA_CG320:
1631 vga_load_state(adp, ¶ms);
1638 adp->va_mode = mode;
1639 info.vi_flags &= ~V_INFO_LINEAR; /* XXX */
1640 update_adapter_info(adp, &info);
1642 /* move hardware cursor out of the way */
1643 (*vidsw[adp->va_index]->set_hw_cursor)(adp, -1, -1);
1646 #else /* VGA_NO_MODE_CHANGE */
1648 #endif /* VGA_NO_MODE_CHANGE */
1651 #ifndef VGA_NO_FONT_LOADING
1654 set_font_mode(video_adapter_t *adp, u_char *buf)
1661 /* save register values */
1662 if (adp->va_type == KD_VGA) {
1663 outb(TSIDX, 0x02); buf[0] = inb(TSREG);
1664 outb(TSIDX, 0x04); buf[1] = inb(TSREG);
1665 outb(GDCIDX, 0x04); buf[2] = inb(GDCREG);
1666 outb(GDCIDX, 0x05); buf[3] = inb(GDCREG);
1667 outb(GDCIDX, 0x06); buf[4] = inb(GDCREG);
1668 inb(adp->va_crtc_addr + 6);
1669 outb(ATC, 0x10); buf[5] = inb(ATC + 1);
1670 } else /* if (adp->va_type == KD_EGA) */ {
1672 * EGA cannot be read; copy parameters from the mode parameter
1675 mp = get_mode_param(adp->va_mode);
1676 buf[0] = mp[5 + 0x02 - 1];
1677 buf[1] = mp[5 + 0x04 - 1];
1678 buf[2] = mp[55 + 0x04];
1679 buf[3] = mp[55 + 0x05];
1680 buf[4] = mp[55 + 0x06];
1681 buf[5] = mp[35 + 0x10];
1684 /* setup vga for loading fonts */
1685 inb(adp->va_crtc_addr + 6); /* reset flip-flop */
1686 outb(ATC, 0x10); outb(ATC, buf[5] & ~0x01);
1687 inb(adp->va_crtc_addr + 6); /* reset flip-flop */
1688 outb(ATC, 0x20); /* enable palette */
1690 #if VGA_SLOW_IOACCESS
1691 #ifdef VGA_ALT_SEQACCESS
1692 outb(TSIDX, 0x00); outb(TSREG, 0x01);
1694 outb(TSIDX, 0x02); outb(TSREG, 0x04);
1695 outb(TSIDX, 0x04); outb(TSREG, 0x07);
1696 #ifdef VGA_ALT_SEQACCESS
1697 outb(TSIDX, 0x00); outb(TSREG, 0x03);
1699 outb(GDCIDX, 0x04); outb(GDCREG, 0x02);
1700 outb(GDCIDX, 0x05); outb(GDCREG, 0x00);
1701 outb(GDCIDX, 0x06); outb(GDCREG, 0x04);
1702 #else /* VGA_SLOW_IOACCESS */
1703 #ifdef VGA_ALT_SEQACCESS
1704 outw(TSIDX, 0x0100);
1706 outw(TSIDX, 0x0402);
1707 outw(TSIDX, 0x0704);
1708 #ifdef VGA_ALT_SEQACCESS
1709 outw(TSIDX, 0x0300);
1711 outw(GDCIDX, 0x0204);
1712 outw(GDCIDX, 0x0005);
1713 outw(GDCIDX, 0x0406); /* addr = a0000, 64kb */
1714 #endif /* VGA_SLOW_IOACCESS */
1720 set_normal_mode(video_adapter_t *adp, u_char *buf)
1726 /* setup vga for normal operation mode again */
1727 inb(adp->va_crtc_addr + 6); /* reset flip-flop */
1728 outb(ATC, 0x10); outb(ATC, buf[5]);
1729 inb(adp->va_crtc_addr + 6); /* reset flip-flop */
1730 outb(ATC, 0x20); /* enable palette */
1732 #if VGA_SLOW_IOACCESS
1733 #ifdef VGA_ALT_SEQACCESS
1734 outb(TSIDX, 0x00); outb(TSREG, 0x01);
1736 outb(TSIDX, 0x02); outb(TSREG, buf[0]);
1737 outb(TSIDX, 0x04); outb(TSREG, buf[1]);
1738 #ifdef VGA_ALT_SEQACCESS
1739 outb(TSIDX, 0x00); outb(TSREG, 0x03);
1741 outb(GDCIDX, 0x04); outb(GDCREG, buf[2]);
1742 outb(GDCIDX, 0x05); outb(GDCREG, buf[3]);
1743 if (adp->va_crtc_addr == MONO_CRTC) {
1744 outb(GDCIDX, 0x06); outb(GDCREG,(buf[4] & 0x03) | 0x08);
1746 outb(GDCIDX, 0x06); outb(GDCREG,(buf[4] & 0x03) | 0x0c);
1748 #else /* VGA_SLOW_IOACCESS */
1749 #ifdef VGA_ALT_SEQACCESS
1750 outw(TSIDX, 0x0100);
1752 outw(TSIDX, 0x0002 | (buf[0] << 8));
1753 outw(TSIDX, 0x0004 | (buf[1] << 8));
1754 #ifdef VGA_ALT_SEQACCESS
1755 outw(TSIDX, 0x0300);
1757 outw(GDCIDX, 0x0004 | (buf[2] << 8));
1758 outw(GDCIDX, 0x0005 | (buf[3] << 8));
1759 if (adp->va_crtc_addr == MONO_CRTC)
1760 outw(GDCIDX, 0x0006 | (((buf[4] & 0x03) | 0x08)<<8));
1762 outw(GDCIDX, 0x0006 | (((buf[4] & 0x03) | 0x0c)<<8));
1763 #endif /* VGA_SLOW_IOACCESS */
1768 #endif /* VGA_NO_FONT_LOADING */
1772 * Read the font data in the requested font page from the video adapter.
1777 vga_save_font(video_adapter_t *adp, int page, int fontsize, u_char *data,
1780 #ifndef VGA_NO_FONT_LOADING
1781 u_char buf[PARAM_BUFSIZE];
1784 #ifdef VGA_ALT_SEQACCESS
1789 prologue(adp, V_ADP_FONT, ENODEV);
1791 if (fontsize < 14) {
1794 } else if (fontsize >= 32) {
1796 } else if (fontsize >= 16) {
1804 if (page < 0 || page >= 8)
1806 segment = FONT_BUF + 0x4000*page;
1810 #ifdef VGA_ALT_SEQACCESS
1811 if (adp->va_type == KD_VGA) { /* what about EGA? XXX */
1813 outb(TSIDX, 0x00); outb(TSREG, 0x01);
1814 outb(TSIDX, 0x01); val = inb(TSREG); /* disable screen */
1815 outb(TSIDX, 0x01); outb(TSREG, val | 0x20);
1816 outb(TSIDX, 0x00); outb(TSREG, 0x03);
1821 set_font_mode(adp, buf);
1822 if (fontsize == 32) {
1823 bcopy_fromio(segment + ch*32, data, fontsize*count);
1825 for (c = ch; count > 0; ++c, --count) {
1826 bcopy_fromio(segment + c*32, data, fontsize);
1830 set_normal_mode(adp, buf);
1832 #ifdef VGA_ALT_SEQACCESS
1833 if (adp->va_type == KD_VGA) {
1835 outb(TSIDX, 0x00); outb(TSREG, 0x01);
1836 outb(TSIDX, 0x01); outb(TSREG, val & 0xdf); /* enable screen */
1837 outb(TSIDX, 0x00); outb(TSREG, 0x03);
1843 #else /* VGA_NO_FONT_LOADING */
1845 #endif /* VGA_NO_FONT_LOADING */
1850 * Set the font data in the requested font page.
1851 * NOTE: it appears that some recent video adapters do not support
1852 * the font page other than 0... XXX
1857 vga_load_font(video_adapter_t *adp, int page, int fontsize, u_char *data,
1860 #ifndef VGA_NO_FONT_LOADING
1861 u_char buf[PARAM_BUFSIZE];
1864 #ifdef VGA_ALT_SEQACCESS
1869 prologue(adp, V_ADP_FONT, ENODEV);
1871 if (fontsize < 14) {
1874 } else if (fontsize >= 32) {
1876 } else if (fontsize >= 16) {
1884 if (page < 0 || page >= 8)
1886 segment = FONT_BUF + 0x4000*page;
1890 #ifdef VGA_ALT_SEQACCESS
1891 if (adp->va_type == KD_VGA) { /* what about EGA? XXX */
1893 outb(TSIDX, 0x00); outb(TSREG, 0x01);
1894 outb(TSIDX, 0x01); val = inb(TSREG); /* disable screen */
1895 outb(TSIDX, 0x01); outb(TSREG, val | 0x20);
1896 outb(TSIDX, 0x00); outb(TSREG, 0x03);
1901 set_font_mode(adp, buf);
1902 if (fontsize == 32) {
1903 bcopy_toio(data, segment + ch*32, fontsize*count);
1905 for (c = ch; count > 0; ++c, --count) {
1906 bcopy_toio(data, segment + c*32, fontsize);
1910 set_normal_mode(adp, buf);
1912 #ifdef VGA_ALT_SEQACCESS
1913 if (adp->va_type == KD_VGA) {
1915 outb(TSIDX, 0x00); outb(TSREG, 0x01);
1916 outb(TSIDX, 0x01); outb(TSREG, val & 0xdf); /* enable screen */
1917 outb(TSIDX, 0x00); outb(TSREG, 0x03);
1923 #else /* VGA_NO_FONT_LOADING */
1925 #endif /* VGA_NO_FONT_LOADING */
1930 * Activate the requested font page.
1931 * NOTE: it appears that some recent video adapters do not support
1932 * the font page other than 0... XXX
1937 vga_show_font(video_adapter_t *adp, int page)
1939 #ifndef VGA_NO_FONT_LOADING
1940 static u_char cg[] = { 0x00, 0x05, 0x0a, 0x0f, 0x30, 0x35, 0x3a, 0x3f };
1943 prologue(adp, V_ADP_FONT, ENODEV);
1944 if (page < 0 || page >= 8)
1948 outb(TSIDX, 0x03); outb(TSREG, cg[page]);
1952 #else /* VGA_NO_FONT_LOADING */
1954 #endif /* VGA_NO_FONT_LOADING */
1959 * Read DAC values. The values have expressed in 8 bits.
1964 vga_save_palette(video_adapter_t *adp, u_char *palette)
1968 prologue(adp, V_ADP_PALETTE, ENODEV);
1971 * We store 8 bit values in the palette buffer, while the standard
1972 * VGA has 6 bit DAC .
1974 outb(PALRADR, 0x00);
1975 for (i = 0; i < 256*3; ++i)
1976 palette[i] = inb(PALDATA) << 2;
1977 inb(adp->va_crtc_addr + 6); /* reset flip/flop */
1982 vga_save_palette2(video_adapter_t *adp, int base, int count,
1983 u_char *r, u_char *g, u_char *b)
1987 prologue(adp, V_ADP_PALETTE, ENODEV);
1989 outb(PALRADR, base);
1990 for (i = 0; i < count; ++i) {
1991 r[i] = inb(PALDATA) << 2;
1992 g[i] = inb(PALDATA) << 2;
1993 b[i] = inb(PALDATA) << 2;
1995 inb(adp->va_crtc_addr + 6); /* reset flip/flop */
2006 vga_load_palette(video_adapter_t *adp, u_char *palette)
2010 prologue(adp, V_ADP_PALETTE, ENODEV);
2012 outb(PIXMASK, 0xff); /* no pixelmask */
2013 outb(PALWADR, 0x00);
2014 for (i = 0; i < 256*3; ++i)
2015 outb(PALDATA, palette[i] >> 2);
2016 inb(adp->va_crtc_addr + 6); /* reset flip/flop */
2017 outb(ATC, 0x20); /* enable palette */
2022 vga_load_palette2(video_adapter_t *adp, int base, int count,
2023 u_char *r, u_char *g, u_char *b)
2027 prologue(adp, V_ADP_PALETTE, ENODEV);
2029 outb(PIXMASK, 0xff); /* no pixelmask */
2030 outb(PALWADR, base);
2031 for (i = 0; i < count; ++i) {
2032 outb(PALDATA, r[i] >> 2);
2033 outb(PALDATA, g[i] >> 2);
2034 outb(PALDATA, b[i] >> 2);
2036 inb(adp->va_crtc_addr + 6); /* reset flip/flop */
2037 outb(ATC, 0x20); /* enable palette */
2043 * Change the border color.
2048 vga_set_border(video_adapter_t *adp, int color)
2050 prologue(adp, V_ADP_BORDER, ENODEV);
2052 switch (adp->va_type) {
2055 inb(adp->va_crtc_addr + 6); /* reset flip-flop */
2056 outb(ATC, 0x31); outb(ATC, color & 0xff);
2059 outb(adp->va_crtc_addr + 5, color & 0x0f); /* color select register */
2071 * Read video register values.
2072 * NOTE: this function only reads the standard EGA/VGA registers.
2073 * any extra/extended registers of SVGA adapters are not saved.
2078 vga_save_state(video_adapter_t *adp, void *p, size_t size)
2087 /* return the required buffer size */
2088 prologue(adp, V_ADP_STATESAVE, 0);
2089 return sizeof(adp_state_t);
2091 prologue(adp, V_ADP_STATESAVE, ENODEV);
2092 if (size < sizeof(adp_state_t))
2096 ((adp_state_t *)p)->sig = V_STATE_SIG;
2097 buf = ((adp_state_t *)p)->regs;
2098 bzero(buf, V_MODE_PARAM_SIZE);
2099 crtc_addr = adp->va_crtc_addr;
2103 outb(TSIDX, 0x00); outb(TSREG, 0x01); /* stop sequencer */
2104 for (i = 0, j = 5; i < 4; i++) {
2106 buf[j++] = inb(TSREG);
2108 buf[9] = inb(MISC + 10); /* dot-clock */
2109 outb(TSIDX, 0x00); outb(TSREG, 0x03); /* start sequencer */
2111 for (i = 0, j = 10; i < 25; i++) { /* crtc */
2113 buf[j++] = inb(crtc_addr + 1);
2115 for (i = 0, j = 35; i < 20; i++) { /* attribute ctrl */
2116 inb(crtc_addr + 6); /* reset flip-flop */
2118 buf[j++] = inb(ATC + 1);
2120 for (i = 0, j = 55; i < 9; i++) { /* graph data ctrl */
2122 buf[j++] = inb(GDCREG);
2124 inb(crtc_addr + 6); /* reset flip-flop */
2125 outb(ATC, 0x20); /* enable palette */
2130 if (vga_get_info(adp, adp->va_mode, &info) == 0) {
2131 if (info.vi_flags & V_INFO_GRAPHICS) {
2132 buf[0] = info.vi_width/info.vi_cwidth; /* COLS */
2133 buf[1] = info.vi_height/info.vi_cheight - 1; /* ROWS */
2135 buf[0] = info.vi_width; /* COLS */
2136 buf[1] = info.vi_height - 1; /* ROWS */
2138 buf[2] = info.vi_cheight; /* POINTS */
2140 /* XXX: shouldn't be happening... */
2141 printf("vga%d: %s: failed to obtain mode info. (vga_save_state())\n",
2142 adp->va_unit, adp->va_name);
2145 buf[0] = readb(BIOS_PADDRTOVADDR(0x44a)); /* COLS */
2146 buf[1] = readb(BIOS_PADDRTOVADDR(0x484)); /* ROWS */
2147 buf[2] = readb(BIOS_PADDRTOVADDR(0x485)); /* POINTS */
2148 buf[3] = readb(BIOS_PADDRTOVADDR(0x44c));
2149 buf[4] = readb(BIOS_PADDRTOVADDR(0x44d));
2157 * Set video registers at once.
2158 * NOTE: this function only updates the standard EGA/VGA registers.
2159 * any extra/extended registers of SVGA adapters are not changed.
2164 vga_load_state(video_adapter_t *adp, void *p)
2171 prologue(adp, V_ADP_STATELOAD, ENODEV);
2172 if (((adp_state_t *)p)->sig != V_STATE_SIG)
2175 buf = ((adp_state_t *)p)->regs;
2176 crtc_addr = adp->va_crtc_addr;
2179 dump_buffer(buf, V_MODE_PARAM_SIZE);
2184 outb(TSIDX, 0x00); outb(TSREG, 0x01); /* stop sequencer */
2185 for (i = 0; i < 4; ++i) { /* program sequencer */
2187 outb(TSREG, buf[i + 5]);
2189 outb(MISC, buf[9]); /* set dot-clock */
2190 outb(TSIDX, 0x00); outb(TSREG, 0x03); /* start sequencer */
2191 outb(crtc_addr, 0x11);
2192 outb(crtc_addr + 1, inb(crtc_addr + 1) & 0x7F);
2193 for (i = 0; i < 25; ++i) { /* program crtc */
2195 outb(crtc_addr + 1, buf[i + 10]);
2197 inb(crtc_addr+6); /* reset flip-flop */
2198 for (i = 0; i < 20; ++i) { /* program attribute ctrl */
2200 outb(ATC, buf[i + 35]);
2202 for (i = 0; i < 9; ++i) { /* program graph data ctrl */
2204 outb(GDCREG, buf[i + 55]);
2206 inb(crtc_addr + 6); /* reset flip-flop */
2207 outb(ATC, 0x20); /* enable palette */
2209 #if notyet /* a temporary workaround for kernel panic, XXX */
2211 if (adp->va_unit == V_ADP_PRIMARY) {
2212 writeb(BIOS_PADDRTOVADDR(0x44a), buf[0]); /* COLS */
2213 writeb(BIOS_PADDRTOVADDR(0x484), buf[1] + rows_offset - 1); /* ROWS */
2214 writeb(BIOS_PADDRTOVADDR(0x485), buf[2]); /* POINTS */
2216 writeb(BIOS_PADDRTOVADDR(0x44c), buf[3]);
2217 writeb(BIOS_PADDRTOVADDR(0x44d), buf[4]);
2220 #endif /* VGA_NO_BIOS */
2229 * Change the origin (window mapping) of the banked frame buffer.
2232 vga_set_origin(video_adapter_t *adp, off_t offset)
2235 * The standard video modes do not require window mapping;
2236 * always return error.
2243 * Read the position of the hardware text cursor.
2248 vga_read_hw_cursor(video_adapter_t *adp, int *col, int *row)
2256 if (adp->va_info.vi_flags & V_INFO_GRAPHICS)
2260 outb(adp->va_crtc_addr, 14);
2261 off = inb(adp->va_crtc_addr + 1);
2262 outb(adp->va_crtc_addr, 15);
2263 off = (off << 8) | inb(adp->va_crtc_addr + 1);
2266 *row = off / adp->va_info.vi_width;
2267 *col = off % adp->va_info.vi_width;
2274 * Move the hardware text cursor. If col and row are both -1,
2275 * the cursor won't be shown.
2280 vga_set_hw_cursor(video_adapter_t *adp, int col, int row)
2288 if ((col == -1) && (row == -1)) {
2291 if (adp->va_info.vi_flags & V_INFO_GRAPHICS)
2293 off = row*adp->va_info.vi_width + col;
2297 outb(adp->va_crtc_addr, 14);
2298 outb(adp->va_crtc_addr + 1, off >> 8);
2299 outb(adp->va_crtc_addr, 15);
2300 outb(adp->va_crtc_addr + 1, off & 0x00ff);
2307 * set_hw_cursor_shape():
2308 * Change the shape of the hardware text cursor. If the height is
2309 * zero or negative, the cursor won't be shown.
2314 vga_set_hw_cursor_shape(video_adapter_t *adp, int base, int height,
2315 int celsize, int blink)
2323 switch (adp->va_type) {
2330 /* make the cursor invisible */
2331 outb(adp->va_crtc_addr, 10);
2332 outb(adp->va_crtc_addr + 1, 32);
2333 outb(adp->va_crtc_addr, 11);
2334 outb(adp->va_crtc_addr + 1, 0);
2336 outb(adp->va_crtc_addr, 10);
2337 outb(adp->va_crtc_addr + 1, celsize - base - height);
2338 outb(adp->va_crtc_addr, 11);
2339 outb(adp->va_crtc_addr + 1, celsize - base - 1);
2344 /* make the cursor invisible */
2345 outb(adp->va_crtc_addr, 10);
2346 outb(adp->va_crtc_addr + 1, celsize);
2347 outb(adp->va_crtc_addr, 11);
2348 outb(adp->va_crtc_addr + 1, 0);
2350 outb(adp->va_crtc_addr, 10);
2351 outb(adp->va_crtc_addr + 1, celsize - base - height);
2352 outb(adp->va_crtc_addr, 11);
2353 outb(adp->va_crtc_addr + 1, celsize - base);
2364 * Put the display in power save/power off mode.
2369 vga_blank_display(video_adapter_t *adp, int mode)
2375 switch (adp->va_type) {
2378 case V_DISPLAY_SUSPEND:
2379 case V_DISPLAY_STAND_BY:
2383 outb(TSREG, val | 0x20);
2384 outb(adp->va_crtc_addr, 0x17);
2385 val = inb(adp->va_crtc_addr + 1);
2386 outb(adp->va_crtc_addr + 1, val & ~0x80);
2388 case V_DISPLAY_BLANK:
2392 outb(TSREG, val | 0x20);
2398 outb(TSREG, val & 0xDF);
2399 outb(adp->va_crtc_addr, 0x17);
2400 val = inb(adp->va_crtc_addr + 1);
2401 outb(adp->va_crtc_addr + 1, val | 0x80);
2407 /* no support yet */
2413 case V_DISPLAY_SUSPEND:
2414 case V_DISPLAY_STAND_BY:
2415 case V_DISPLAY_BLANK:
2416 outb(adp->va_crtc_addr + 4, 0x25);
2419 outb(adp->va_crtc_addr + 4, 0x2d);
2427 case V_DISPLAY_SUSPEND:
2428 case V_DISPLAY_STAND_BY:
2429 case V_DISPLAY_BLANK:
2430 outb(adp->va_crtc_addr + 4, 0x21);
2433 outb(adp->va_crtc_addr + 4, 0x29);
2447 * Mmap frame buffer.
2452 vga_mmap_buf(video_adapter_t *adp, vm_offset_t offset, int prot)
2454 if (adp->va_info.vi_flags & V_INFO_LINEAR)
2458 printf("vga_mmap_buf(): window:0x%x, offset:0x%x\n",
2459 adp->va_info.vi_window, offset);
2462 /* XXX: is this correct? */
2463 if (offset > adp->va_window_size - PAGE_SIZE)
2467 return i386_btop(adp->va_info.vi_window + offset);
2470 return alpha_btop(adp->va_info.vi_window + offset);
2474 #ifndef VGA_NO_MODE_CHANGE
2477 planar_fill(video_adapter_t *adp, int val)
2480 int at; /* position in the frame buffer */
2483 outw(GDCIDX, 0x0005); /* read mode 0, write mode 0 */
2484 outw(GDCIDX, 0x0003); /* data rotate/function select */
2485 outw(GDCIDX, 0x0f01); /* set/reset enable */
2486 outw(GDCIDX, 0xff08); /* bit mask */
2487 outw(GDCIDX, (val << 8) | 0x00); /* set/reset */
2489 length = adp->va_line_width*adp->va_info.vi_height;
2490 while (length > 0) {
2491 l = imin(length, adp->va_window_size);
2492 (*vidsw[adp->va_index]->set_win_org)(adp, at);
2493 bzero_io(adp->va_window, l);
2497 outw(GDCIDX, 0x0000); /* set/reset */
2498 outw(GDCIDX, 0x0001); /* set/reset enable */
2502 packed_fill(video_adapter_t *adp, int val)
2505 int at; /* position in the frame buffer */
2509 length = adp->va_line_width*adp->va_info.vi_height;
2510 while (length > 0) {
2511 l = imin(length, adp->va_window_size);
2512 (*vidsw[adp->va_index]->set_win_org)(adp, at);
2513 fill_io(val, adp->va_window, l);
2520 direct_fill(video_adapter_t *adp, int val)
2523 int at; /* position in the frame buffer */
2527 length = adp->va_line_width*adp->va_info.vi_height;
2528 while (length > 0) {
2529 l = imin(length, adp->va_window_size);
2530 (*vidsw[adp->va_index]->set_win_org)(adp, at);
2531 switch (adp->va_info.vi_pixel_size) {
2532 case sizeof(u_int16_t):
2533 fillw_io(val, adp->va_window, l/sizeof(u_int16_t));
2538 case sizeof(u_int32_t):
2539 filll_io(val, adp->va_window, l/sizeof(u_int32_t));
2548 vga_clear(video_adapter_t *adp)
2550 switch (adp->va_info.vi_mem_model) {
2551 case V_INFO_MM_TEXT:
2552 /* do nothing? XXX */
2554 case V_INFO_MM_PLANAR:
2555 planar_fill(adp, 0);
2557 case V_INFO_MM_PACKED:
2558 packed_fill(adp, 0);
2560 case V_INFO_MM_DIRECT:
2561 direct_fill(adp, 0);
2569 planar_fill_rect(video_adapter_t *adp, int val, int x, int y, int cx, int cy)
2574 int offset; /* offset within window */
2578 outw(GDCIDX, 0x0005); /* read mode 0, write mode 0 */
2579 outw(GDCIDX, 0x0003); /* data rotate/function select */
2580 outw(GDCIDX, 0x0f01); /* set/reset enable */
2581 outw(GDCIDX, 0xff08); /* bit mask */
2582 outw(GDCIDX, (val << 8) | 0x00); /* set/reset */
2584 banksize = adp->va_window_size;
2587 pos = adp->va_line_width*y + x/8;
2588 if (bank != pos/banksize) {
2589 (*vidsw[adp->va_index]->set_win_org)(adp, pos);
2590 bank = pos/banksize;
2592 offset = pos%banksize;
2593 bx = (x + cx)/8 - x/8;
2595 outw(GDCIDX, ((0xff00 >> (x % 8)) & 0xff00) | 0x08);
2596 writeb(adp->va_window + offset, 0);
2599 if (offset >= banksize) {
2601 ++bank; /* next bank */
2602 (*vidsw[adp->va_index]->set_win_org)(adp, bank*banksize);
2604 outw(GDCIDX, 0xff08); /* bit mask */
2607 l = imin(bx, banksize);
2608 bzero_io(adp->va_window + offset, l);
2611 if (offset >= banksize) {
2613 ++bank; /* next bank */
2614 (*vidsw[adp->va_index]->set_win_org)(adp, bank*banksize);
2618 outw(GDCIDX, (~(0xff00 >> ((x + cx) % 8)) & 0xff00) | 0x08);
2619 writeb(adp->va_window + offset, 0);
2621 if (offset >= banksize) {
2623 ++bank; /* next bank */
2624 (*vidsw[adp->va_index]->set_win_org)(adp, bank*banksize);
2626 outw(GDCIDX, 0xff08); /* bit mask */
2632 outw(GDCIDX, 0xff08); /* bit mask */
2633 outw(GDCIDX, 0x0000); /* set/reset */
2634 outw(GDCIDX, 0x0001); /* set/reset enable */
2638 packed_fill_rect(video_adapter_t *adp, int val, int x, int y, int cx, int cy)
2643 int offset; /* offset within window */
2646 banksize = adp->va_window_size;
2648 cx *= adp->va_info.vi_pixel_size;
2650 pos = adp->va_line_width*y + x*adp->va_info.vi_pixel_size;
2651 if (bank != pos/banksize) {
2652 (*vidsw[adp->va_index]->set_win_org)(adp, pos);
2653 bank = pos/banksize;
2655 offset = pos%banksize;
2656 end = imin(offset + cx, banksize);
2657 fill_io(val, adp->va_window + offset,
2658 (end - offset)/adp->va_info.vi_pixel_size);
2659 /* the line may cross the window boundary */
2660 if (offset + cx > banksize) {
2661 ++bank; /* next bank */
2662 (*vidsw[adp->va_index]->set_win_org)(adp, bank*banksize);
2663 end = offset + cx - banksize;
2664 fill_io(val, adp->va_window, end/adp->va_info.vi_pixel_size);
2672 direct_fill_rect16(video_adapter_t *adp, int val, int x, int y, int cx, int cy)
2677 int offset; /* offset within window */
2681 * XXX: the function assumes that banksize is a muliple of
2682 * sizeof(u_int16_t).
2684 banksize = adp->va_window_size;
2686 cx *= sizeof(u_int16_t);
2688 pos = adp->va_line_width*y + x*sizeof(u_int16_t);
2689 if (bank != pos/banksize) {
2690 (*vidsw[adp->va_index]->set_win_org)(adp, pos);
2691 bank = pos/banksize;
2693 offset = pos%banksize;
2694 end = imin(offset + cx, banksize);
2695 fillw_io(val, adp->va_window + offset,
2696 (end - offset)/sizeof(u_int16_t));
2697 /* the line may cross the window boundary */
2698 if (offset + cx > banksize) {
2699 ++bank; /* next bank */
2700 (*vidsw[adp->va_index]->set_win_org)(adp, bank*banksize);
2701 end = offset + cx - banksize;
2702 fillw_io(val, adp->va_window, end/sizeof(u_int16_t));
2710 direct_fill_rect24(video_adapter_t *adp, int val, int x, int y, int cx, int cy)
2715 int offset; /* offset within window */
2721 b[0] = val & 0x0000ff;
2722 b[1] = (val >> 8) & 0x0000ff;
2723 b[2] = (val >> 16) & 0x0000ff;
2724 banksize = adp->va_window_size;
2728 pos = adp->va_line_width*y + x*3;
2729 if (bank != pos/banksize) {
2730 (*vidsw[adp->va_index]->set_win_org)(adp, pos);
2731 bank = pos/banksize;
2733 offset = pos%banksize;
2734 end = imin(offset + cx, banksize);
2735 for (i = 0, j = offset; j < end; i = (++i)%3, ++j) {
2736 writeb(adp->va_window + j, b[i]);
2738 /* the line may cross the window boundary */
2739 if (offset + cx >= banksize) {
2740 ++bank; /* next bank */
2741 (*vidsw[adp->va_index]->set_win_org)(adp, bank*banksize);
2743 end = offset + cx - banksize;
2744 for (; j < end; i = (++i)%3, ++j) {
2745 writeb(adp->va_window + j, b[i]);
2754 direct_fill_rect32(video_adapter_t *adp, int val, int x, int y, int cx, int cy)
2759 int offset; /* offset within window */
2763 * XXX: the function assumes that banksize is a muliple of
2764 * sizeof(u_int32_t).
2766 banksize = adp->va_window_size;
2768 cx *= sizeof(u_int32_t);
2770 pos = adp->va_line_width*y + x*sizeof(u_int32_t);
2771 if (bank != pos/banksize) {
2772 (*vidsw[adp->va_index]->set_win_org)(adp, pos);
2773 bank = pos/banksize;
2775 offset = pos%banksize;
2776 end = imin(offset + cx, banksize);
2777 filll_io(val, adp->va_window + offset,
2778 (end - offset)/sizeof(u_int32_t));
2779 /* the line may cross the window boundary */
2780 if (offset + cx > banksize) {
2781 ++bank; /* next bank */
2782 (*vidsw[adp->va_index]->set_win_org)(adp, bank*banksize);
2783 end = offset + cx - banksize;
2784 filll_io(val, adp->va_window, end/sizeof(u_int32_t));
2792 vga_fill_rect(video_adapter_t *adp, int val, int x, int y, int cx, int cy)
2794 switch (adp->va_info.vi_mem_model) {
2795 case V_INFO_MM_TEXT:
2796 /* do nothing? XXX */
2798 case V_INFO_MM_PLANAR:
2799 planar_fill_rect(adp, val, x, y, cx, cy);
2801 case V_INFO_MM_PACKED:
2802 packed_fill_rect(adp, val, x, y, cx, cy);
2804 case V_INFO_MM_DIRECT:
2805 switch (adp->va_info.vi_pixel_size) {
2806 case sizeof(u_int16_t):
2807 direct_fill_rect16(adp, val, x, y, cx, cy);
2810 direct_fill_rect24(adp, val, x, y, cx, cy);
2812 case sizeof(u_int32_t):
2813 direct_fill_rect32(adp, val, x, y, cx, cy);
2822 vga_fill_rect(video_adapter_t *adp, int val, int x, int y, int cx, int cy)
2829 vga_bitblt(video_adapter_t *adp,...)
2835 #endif /* !VGA_NO_MODE_CHANGE */
2838 get_palette(video_adapter_t *adp, int base, int count,
2839 u_char *red, u_char *green, u_char *blue, u_char *trans)
2845 if ((base < 0) || (base >= 256) || (base + count > 256))
2848 r = malloc(count*3, M_DEVBUF, M_WAITOK);
2851 if (vga_save_palette2(adp, base, count, r, g, b))
2853 copyout(r, red, count);
2854 copyout(g, green, count);
2855 copyout(b, blue, count);
2856 if (trans != NULL) {
2858 copyout(r, trans, count);
2866 set_palette(video_adapter_t *adp, int base, int count,
2867 u_char *red, u_char *green, u_char *blue, u_char *trans)
2874 if ((base < 0) || (base >= 256) || (base + count > 256))
2877 r = malloc(count*3, M_DEVBUF, M_WAITOK);
2880 copyin(red, r, count);
2881 copyin(green, g, count);
2882 copyin(blue, b, count);
2883 err = vga_load_palette2(adp, base, count, r, g, b);
2886 return (err ? ENODEV : 0);
2890 vga_dev_ioctl(video_adapter_t *adp, u_long cmd, caddr_t arg)
2893 case FBIO_GETWINORG: /* get frame buffer window origin */
2897 case FBIO_SETWINORG: /* set frame buffer window origin */
2900 case FBIO_SETDISPSTART: /* set display start address */
2901 return (set_display_start(adp,
2902 ((video_display_start_t *)arg)->x,
2903 ((video_display_start_t *)arg)->y)
2906 case FBIO_SETLINEWIDTH: /* set scan line length in pixel */
2907 return (set_line_length(adp, *(u_int *)arg) ? ENODEV : 0);
2909 case FBIO_GETPALETTE: /* get color palette */
2910 return get_palette(adp, ((video_color_palette_t *)arg)->index,
2911 ((video_color_palette_t *)arg)->count,
2912 ((video_color_palette_t *)arg)->red,
2913 ((video_color_palette_t *)arg)->green,
2914 ((video_color_palette_t *)arg)->blue,
2915 ((video_color_palette_t *)arg)->transparent);
2917 case FBIO_SETPALETTE: /* set color palette */
2918 return set_palette(adp, ((video_color_palette_t *)arg)->index,
2919 ((video_color_palette_t *)arg)->count,
2920 ((video_color_palette_t *)arg)->red,
2921 ((video_color_palette_t *)arg)->green,
2922 ((video_color_palette_t *)arg)->blue,
2923 ((video_color_palette_t *)arg)->transparent);
2925 case FBIOGTYPE: /* get frame buffer type info. */
2926 ((struct fbtype *)arg)->fb_type = fb_type(adp->va_type);
2927 ((struct fbtype *)arg)->fb_height = adp->va_info.vi_height;
2928 ((struct fbtype *)arg)->fb_width = adp->va_info.vi_width;
2929 ((struct fbtype *)arg)->fb_depth = adp->va_info.vi_depth;
2930 if ((adp->va_info.vi_depth <= 1) || (adp->va_info.vi_depth > 8))
2931 ((struct fbtype *)arg)->fb_cmsize = 0;
2933 ((struct fbtype *)arg)->fb_cmsize = 1 << adp->va_info.vi_depth;
2934 ((struct fbtype *)arg)->fb_size = adp->va_buffer_size;
2937 case FBIOGETCMAP: /* get color palette */
2938 return get_palette(adp, ((struct fbcmap *)arg)->index,
2939 ((struct fbcmap *)arg)->count,
2940 ((struct fbcmap *)arg)->red,
2941 ((struct fbcmap *)arg)->green,
2942 ((struct fbcmap *)arg)->blue, NULL);
2944 case FBIOPUTCMAP: /* set color palette */
2945 return set_palette(adp, ((struct fbcmap *)arg)->index,
2946 ((struct fbcmap *)arg)->count,
2947 ((struct fbcmap *)arg)->red,
2948 ((struct fbcmap *)arg)->green,
2949 ((struct fbcmap *)arg)->blue, NULL);
2952 return fb_commonioctl(adp, cmd, arg);
2957 dump_buffer(u_char *buf, size_t len)
2961 for(i = 0; i < len;) {
2962 printf("%02x ", buf[i]);
2963 if ((++i % 16) == 0)
2970 * Print some information about the video adapter and video modes,
2971 * with requested level of details.
2976 vga_diag(video_adapter_t *adp, int level)
2989 printf("vga: RTC equip. code:0x%02x, DCC code:0x%02x\n",
2990 rtcin(RTC_EQUIPMENT), readb(BIOS_PADDRTOVADDR(0x488)));
2991 printf("vga: CRTC:0x%x, video option:0x%02x, ",
2992 readw(BIOS_PADDRTOVADDR(0x463)),
2993 readb(BIOS_PADDRTOVADDR(0x487)));
2994 printf("rows:%d, cols:%d, font height:%d\n",
2995 readb(BIOS_PADDRTOVADDR(0x44a)),
2996 readb(BIOS_PADDRTOVADDR(0x484)) + 1,
2997 readb(BIOS_PADDRTOVADDR(0x485)));
2998 #endif /* VGA_NO_BIOS */
2999 #if !defined(VGA_NO_BIOS) && !defined(VGA_NO_MODE_CHANGE)
3000 printf("vga: param table EGA/VGA:%p", video_mode_ptr);
3001 printf(", CGA/MDA:%p\n", video_mode_ptr2);
3002 printf("vga: rows_offset:%d\n", rows_offset);
3004 #endif /* FB_DEBUG > 1 */
3006 fb_dump_adp_info(VGA_DRIVER_NAME, adp, level);
3009 if (adp->va_flags & V_ADP_MODECHANGE) {
3010 for (i = 0; bios_vmode[i].vi_mode != EOT; ++i) {
3011 if (bios_vmode[i].vi_mode == NA)
3013 if (get_mode_param(bios_vmode[i].vi_mode) == NULL)
3015 fb_dump_mode_info(VGA_DRIVER_NAME, adp, &bios_vmode[i], level);
3018 vga_get_info(adp, adp->va_initial_mode, &info); /* shouldn't fail */
3019 fb_dump_mode_info(VGA_DRIVER_NAME, adp, &info, level);
3021 #endif /* FB_DEBUG > 1 */
3023 if ((adp->va_type != KD_EGA) && (adp->va_type != KD_VGA))
3025 #if !defined(VGA_NO_BIOS) && !defined(VGA_NO_MODE_CHANGE)
3026 if (video_mode_ptr == NULL)
3027 printf("vga%d: %s: WARNING: video mode switching is not "
3028 "fully supported on this adapter\n",
3029 adp->va_unit, adp->va_name);
3034 if (adp->va_type == KD_VGA) {
3035 printf("VGA parameters upon power-up\n");
3036 dump_buffer(adpstate.regs, sizeof(adpstate.regs));
3037 printf("VGA parameters in BIOS for mode %d\n", adp->va_initial_mode);
3038 dump_buffer(adpstate2.regs, sizeof(adpstate2.regs));
3041 mp = get_mode_param(adp->va_initial_mode);
3042 if (mp == NULL) /* this shouldn't be happening */
3044 printf("EGA/VGA parameters to be used for mode %d\n", adp->va_initial_mode);
3045 dump_buffer(mp, V_MODE_PARAM_SIZE);