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 $
30 * $DragonFly: src/sys/dev/video/fb/vga.c,v 1.6 2003/08/07 21:17:16 dillon Exp $
35 #include "opt_syscons.h" /* should be removed in the future, XXX */
37 #include <sys/param.h>
38 #include <sys/systm.h>
39 #include <sys/kernel.h>
42 #include <sys/fcntl.h>
43 #include <sys/malloc.h>
47 #include <vm/vm_param.h>
50 #include <machine/md_var.h>
51 #include <machine/pc/bios.h>
56 #include <bus/isa/isareg.h>
63 vga_probe_unit(int unit, video_adapter_t *buf, int flags)
69 sw = vid_get_switch(VGA_DRIVER_NAME);
72 error = (*sw->probe)(unit, &adp, NULL, flags);
75 bcopy(adp, buf, sizeof(*buf));
80 vga_attach_unit(int unit, vga_softc_t *sc, int flags)
85 sw = vid_get_switch(VGA_DRIVER_NAME);
89 error = (*sw->probe)(unit, &sc->adp, NULL, flags);
92 return (*sw->init)(unit, sc->adp, flags);
95 /* cdev driver functions */
97 #ifdef FB_INSTALL_CDEV
100 vga_open(dev_t dev, vga_softc_t *sc, int flag, int mode, struct thread *td)
104 if (mode & (O_CREAT | O_APPEND | O_TRUNC))
107 return genfbopen(&sc->gensc, sc->adp, flag, mode, td);
111 vga_close(dev_t dev, vga_softc_t *sc, int flag, int mode, struct thread *td)
113 return genfbclose(&sc->gensc, sc->adp, flag, mode, td);
117 vga_read(dev_t dev, vga_softc_t *sc, struct uio *uio, int flag)
119 return genfbread(&sc->gensc, sc->adp, uio, flag);
123 vga_write(dev_t dev, vga_softc_t *sc, struct uio *uio, int flag)
125 return genfbread(&sc->gensc, sc->adp, uio, flag);
129 vga_ioctl(dev_t dev, vga_softc_t *sc, u_long cmd, caddr_t arg, int flag,
132 return genfbioctl(&sc->gensc, sc->adp, cmd, arg, flag, td);
136 vga_mmap(dev_t dev, vga_softc_t *sc, vm_offset_t offset, int prot)
138 return genfbmmap(&sc->gensc, sc->adp, offset, prot);
141 #endif /* FB_INSTALL_CDEV */
145 #include <machine/clock.h>
146 #include <machine/pc/vesa.h>
148 #define probe_done(adp) ((adp)->va_flags & V_ADP_PROBED)
149 #define init_done(adp) ((adp)->va_flags & V_ADP_INITIALIZED)
150 #define config_done(adp) ((adp)->va_flags & V_ADP_REGISTERED)
152 /* for compatibility with old kernel options */
153 #ifdef SC_ALT_SEQACCESS
154 #undef SC_ALT_SEQACCESS
155 #undef VGA_ALT_SEQACCESS
156 #define VGA_ALT_SEQACCESS 1
161 #undef VGA_SLOW_IOACCESS
162 #define VGA_SLOW_IOACCESS 1
165 /* architecture dependent option */
167 #define VGA_NO_BIOS 1
170 /* this should really be in `rtc.h' */
171 #define RTC_EQUIPMENT 0x14
174 #define V_MODE_MAP_SIZE (M_VGA_CG320 + 1)
175 #define V_MODE_PARAM_SIZE 64
177 /* video adapter state buffer */
180 #define V_STATE_SIG 0x736f6962
181 u_char regs[V_MODE_PARAM_SIZE];
183 typedef struct adp_state adp_state_t;
185 /* video adapter information */
189 #define DCC_EGAMONO 3
194 * NOTE: `va_window' should have a virtual address, but is initialized
195 * with a physical address in the following table, as verify_adapter()
196 * will perform address conversion at run-time.
198 static video_adapter_t adapter_init_value[] = {
200 { 0, KD_MONO, "mda", 0, 0, 0, IO_MDA, IO_MDASIZE, MONO_CRTC,
201 MDA_BUF_BASE, MDA_BUF_SIZE, MDA_BUF_BASE, MDA_BUF_SIZE, MDA_BUF_SIZE,
204 { 0, KD_CGA, "cga", 0, 0, V_ADP_COLOR, IO_CGA, IO_CGASIZE, COLOR_CRTC,
205 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE,
208 { 0, KD_CGA, "cga", 0, 0, V_ADP_COLOR, IO_CGA, IO_CGASIZE, COLOR_CRTC,
209 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE,
212 { 0, KD_EGA, "ega", 0, 0, 0, IO_MDA, 48, MONO_CRTC,
213 EGA_BUF_BASE, EGA_BUF_SIZE, MDA_BUF_BASE, MDA_BUF_SIZE, MDA_BUF_SIZE,
216 { 0, KD_EGA, "ega", 0, 0, V_ADP_COLOR, IO_MDA, 48, COLOR_CRTC,
217 EGA_BUF_BASE, EGA_BUF_SIZE, CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE,
220 { 0, KD_EGA, "ega", 0, 0, V_ADP_COLOR, IO_MDA, 48, COLOR_CRTC,
221 EGA_BUF_BASE, EGA_BUF_SIZE, CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE,
225 static video_adapter_t biosadapter[2];
226 static int biosadapters = 0;
228 /* video driver declarations */
229 static int vga_configure(int flags);
230 int (*vga_sub_configure)(int flags);
232 static int vga_nop(void);
234 static int vga_error(void);
235 static vi_probe_t vga_probe;
236 static vi_init_t vga_init;
237 static vi_get_info_t vga_get_info;
238 static vi_query_mode_t vga_query_mode;
239 static vi_set_mode_t vga_set_mode;
240 static vi_save_font_t vga_save_font;
241 static vi_load_font_t vga_load_font;
242 static vi_show_font_t vga_show_font;
243 static vi_save_palette_t vga_save_palette;
244 static vi_load_palette_t vga_load_palette;
245 static vi_set_border_t vga_set_border;
246 static vi_save_state_t vga_save_state;
247 static vi_load_state_t vga_load_state;
248 static vi_set_win_org_t vga_set_origin;
249 static vi_read_hw_cursor_t vga_read_hw_cursor;
250 static vi_set_hw_cursor_t vga_set_hw_cursor;
251 static vi_set_hw_cursor_shape_t vga_set_hw_cursor_shape;
252 static vi_blank_display_t vga_blank_display;
253 static vi_mmap_t vga_mmap_buf;
254 static vi_ioctl_t vga_dev_ioctl;
255 #ifndef VGA_NO_MODE_CHANGE
256 static vi_clear_t vga_clear;
257 static vi_fill_rect_t vga_fill_rect;
258 static vi_bitblt_t vga_bitblt;
259 #else /* VGA_NO_MODE_CHANGE */
260 #define vga_clear (vi_clear_t *)vga_error
261 #define vga_fill_rect (vi_fill_rect_t *)vga_error
262 #define vga_bitblt (vi_bitblt_t *)vga_error
264 static vi_diag_t vga_diag;
266 static video_switch_t vgavidsw = {
283 vga_set_hw_cursor_shape,
295 VIDEO_DRIVER(mda, vgavidsw, NULL);
296 VIDEO_DRIVER(cga, vgavidsw, NULL);
297 VIDEO_DRIVER(ega, vgavidsw, NULL);
298 VIDEO_DRIVER(vga, vgavidsw, vga_configure);
300 /* VGA BIOS standard video modes */
304 static video_info_t bios_vmode[] = {
306 { M_B40x25, V_INFO_COLOR, 40, 25, 8, 8, 2, 1,
307 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
308 { M_C40x25, V_INFO_COLOR, 40, 25, 8, 8, 4, 1,
309 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
310 { M_B80x25, V_INFO_COLOR, 80, 25, 8, 8, 2, 1,
311 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
312 { M_C80x25, V_INFO_COLOR, 80, 25, 8, 8, 4, 1,
313 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
315 { M_ENH_B40x25, V_INFO_COLOR, 40, 25, 8, 14, 2, 1,
316 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
317 { M_ENH_C40x25, V_INFO_COLOR, 40, 25, 8, 14, 4, 1,
318 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
319 { M_ENH_B80x25, V_INFO_COLOR, 80, 25, 8, 14, 2, 1,
320 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
321 { M_ENH_C80x25, V_INFO_COLOR, 80, 25, 8, 14, 4, 1,
322 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
324 { M_VGA_C40x25, V_INFO_COLOR, 40, 25, 8, 16, 4, 1,
325 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
326 { M_VGA_M80x25, 0, 80, 25, 8, 16, 2, 1,
327 MDA_BUF_BASE, MDA_BUF_SIZE, MDA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
328 { M_VGA_C80x25, V_INFO_COLOR, 80, 25, 8, 16, 4, 1,
329 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
331 { M_EGAMONO80x25, 0, 80, 25, 8, 14, 2, 1,
332 MDA_BUF_BASE, MDA_BUF_SIZE, MDA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
334 { M_ENH_B80x43, 0, 80, 43, 8, 8, 2, 1,
335 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
336 { M_ENH_C80x43, V_INFO_COLOR, 80, 43, 8, 8, 4, 1,
337 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
339 { M_VGA_M80x30, 0, 80, 30, 8, 16, 2, 1,
340 MDA_BUF_BASE, MDA_BUF_SIZE, MDA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
341 { M_VGA_C80x30, V_INFO_COLOR, 80, 30, 8, 16, 4, 1,
342 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
343 { M_VGA_M80x50, 0, 80, 50, 8, 8, 2, 1,
344 MDA_BUF_BASE, MDA_BUF_SIZE, MDA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
345 { M_VGA_C80x50, V_INFO_COLOR, 80, 50, 8, 8, 4, 1,
346 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
347 { M_VGA_M80x60, 0, 80, 60, 8, 8, 2, 1,
348 MDA_BUF_BASE, MDA_BUF_SIZE, MDA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
349 { M_VGA_C80x60, V_INFO_COLOR, 80, 60, 8, 8, 4, 1,
350 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
352 #ifndef VGA_NO_MODE_CHANGE
355 { M_VGA_M90x25, 0, 90, 25, 8, 16, 2, 1,
356 MDA_BUF_BASE, MDA_BUF_SIZE, MDA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
357 { M_VGA_C90x25, V_INFO_COLOR, 90, 25, 8, 16, 4, 1,
358 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
359 { M_VGA_M90x30, 0, 90, 30, 8, 16, 2, 1,
360 MDA_BUF_BASE, MDA_BUF_SIZE, MDA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
361 { M_VGA_C90x30, V_INFO_COLOR, 90, 30, 8, 16, 4, 1,
362 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
363 { M_VGA_M90x43, 0, 90, 43, 8, 8, 2, 1,
364 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
365 { M_VGA_C90x43, V_INFO_COLOR, 90, 43, 8, 8, 4, 1,
366 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
367 { M_VGA_M90x50, 0, 90, 50, 8, 8, 2, 1,
368 MDA_BUF_BASE, MDA_BUF_SIZE, MDA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
369 { M_VGA_C90x50, V_INFO_COLOR, 90, 50, 8, 8, 4, 1,
370 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
371 { M_VGA_M90x60, 0, 90, 60, 8, 8, 2, 1,
372 MDA_BUF_BASE, MDA_BUF_SIZE, MDA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
373 { M_VGA_C90x60, V_INFO_COLOR, 90, 60, 8, 8, 4, 1,
374 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
375 #endif /* VGA_WIDTH90 */
378 { M_BG320, V_INFO_COLOR | V_INFO_GRAPHICS, 320, 200, 8, 8, 2, 1,
379 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_CGA },
380 { M_CG320, V_INFO_COLOR | V_INFO_GRAPHICS, 320, 200, 8, 8, 2, 1,
381 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_CGA },
382 { M_BG640, V_INFO_COLOR | V_INFO_GRAPHICS, 640, 200, 8, 8, 1, 1,
383 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_CGA },
385 { M_CG320_D, V_INFO_COLOR | V_INFO_GRAPHICS, 320, 200, 8, 8, 4, 4,
386 GRAPHICS_BUF_BASE, GRAPHICS_BUF_SIZE, GRAPHICS_BUF_SIZE, 0, 0,
388 { M_CG640_E, V_INFO_COLOR | V_INFO_GRAPHICS, 640, 200, 8, 8, 4, 4,
389 GRAPHICS_BUF_BASE, GRAPHICS_BUF_SIZE, GRAPHICS_BUF_SIZE, 0, 0 ,
391 { M_EGAMONOAPA, V_INFO_GRAPHICS, 640, 350, 8, 14, 4, 4,
392 GRAPHICS_BUF_BASE, GRAPHICS_BUF_SIZE, 64*1024, 0, 0 ,
394 { M_ENHMONOAPA2,V_INFO_GRAPHICS, 640, 350, 8, 14, 4, 4,
395 GRAPHICS_BUF_BASE, GRAPHICS_BUF_SIZE, GRAPHICS_BUF_SIZE, 0, 0 ,
397 { M_CG640x350, V_INFO_COLOR | V_INFO_GRAPHICS, 640, 350, 8, 14, 2, 2,
398 GRAPHICS_BUF_BASE, GRAPHICS_BUF_SIZE, GRAPHICS_BUF_SIZE, 0, 0 ,
400 { M_ENH_CG640, V_INFO_COLOR | V_INFO_GRAPHICS, 640, 350, 8, 14, 4, 4,
401 GRAPHICS_BUF_BASE, GRAPHICS_BUF_SIZE, GRAPHICS_BUF_SIZE, 0, 0 ,
404 { M_BG640x480, V_INFO_COLOR | V_INFO_GRAPHICS, 640, 480, 8, 16, 4, 4,
405 GRAPHICS_BUF_BASE, GRAPHICS_BUF_SIZE, GRAPHICS_BUF_SIZE, 0, 0 ,
407 { M_CG640x480, V_INFO_COLOR | V_INFO_GRAPHICS, 640, 480, 8, 16, 4, 4,
408 GRAPHICS_BUF_BASE, GRAPHICS_BUF_SIZE, GRAPHICS_BUF_SIZE, 0, 0 ,
410 { M_VGA_CG320, V_INFO_COLOR | V_INFO_GRAPHICS, 320, 200, 8, 8, 8, 1,
411 GRAPHICS_BUF_BASE, GRAPHICS_BUF_SIZE, GRAPHICS_BUF_SIZE, 0, 0,
412 V_INFO_MM_PACKED, 1 },
413 { M_VGA_MODEX, V_INFO_COLOR | V_INFO_GRAPHICS, 320, 240, 8, 8, 8, 4,
414 GRAPHICS_BUF_BASE, GRAPHICS_BUF_SIZE, GRAPHICS_BUF_SIZE, 0, 0,
416 #endif /* VGA_NO_MODE_CHANGE */
421 static int vga_init_done = FALSE;
422 #if !defined(VGA_NO_BIOS) && !defined(VGA_NO_MODE_CHANGE)
423 static u_char *video_mode_ptr = NULL; /* EGA/VGA */
424 static u_char *video_mode_ptr2 = NULL; /* CGA/MDA */
426 static u_char *mode_map[V_MODE_MAP_SIZE];
427 static adp_state_t adpstate;
428 static adp_state_t adpstate2;
429 static int rows_offset = 1;
431 /* local macros and functions */
432 #define BIOS_SADDRTOLADDR(p) ((((p) & 0xffff0000) >> 12) + ((p) & 0x0000ffff))
434 #if !defined(VGA_NO_BIOS) && !defined(VGA_NO_MODE_CHANGE)
435 static void map_mode_table(u_char *map[], u_char *table, int max);
437 static void clear_mode_map(video_adapter_t *adp, u_char *map[], int max,
439 #if !defined(VGA_NO_BIOS) && !defined(VGA_NO_MODE_CHANGE)
440 static int map_mode_num(int mode);
442 static int map_gen_mode_num(int type, int color, int mode);
443 static int map_bios_mode_num(int type, int color, int bios_mode);
444 static u_char *get_mode_param(int mode);
446 static void fill_adapter_param(int code, video_adapter_t *adp);
448 static int verify_adapter(video_adapter_t *adp);
449 static void update_adapter_info(video_adapter_t *adp, video_info_t *info);
450 #if !defined(VGA_NO_BIOS) && !defined(VGA_NO_MODE_CHANGE)
451 #define COMP_IDENTICAL 0
452 #define COMP_SIMILAR 1
453 #define COMP_DIFFERENT 2
454 static int comp_adpregs(u_char *buf1, u_char *buf2);
456 static int probe_adapters(void);
457 static int set_line_length(video_adapter_t *adp, int pixel);
458 static int set_display_start(video_adapter_t *adp, int x, int y);
459 static void filll_io(int val, vm_offset_t d, size_t size);
461 #ifndef VGA_NO_MODE_CHANGE
463 static void set_width90(adp_state_t *params);
465 #endif /* !VGA_NO_MODE_CHANGE */
467 #ifndef VGA_NO_FONT_LOADING
468 #define PARAM_BUFSIZE 6
469 static void set_font_mode(video_adapter_t *adp, u_char *buf);
470 static void set_normal_mode(video_adapter_t *adp, u_char *buf);
473 #ifndef VGA_NO_MODE_CHANGE
474 static void planar_fill(video_adapter_t *adp, int val);
475 static void packed_fill(video_adapter_t *adp, int val);
476 static void direct_fill(video_adapter_t *adp, int val);
478 static void planar_fill_rect(video_adapter_t *adp, int val, int x, int y,
480 static void packed_fill_rect(video_adapter_t *adp, int val, int x, int y,
482 static void direct_fill_rect16(video_adapter_t *adp, int val, int x, int y,
484 static void direct_fill_rect24(video_adapter_t *adp, int val, int x, int y,
486 static void direct_fill_rect32(video_adapter_t *adp, int val, int x, int y,
489 #endif /* !VGA_NO_MODE_CHANGE */
491 static void dump_buffer(u_char *buf, size_t len);
493 #define ISMAPPED(pa, width) \
494 (((pa) <= (u_long)0x1000 - (width)) \
495 || ((pa) >= ISA_HOLE_START && (pa) <= 0x100000 - (width)))
497 #define prologue(adp, flag, err) \
498 if (!vga_init_done || !((adp)->va_flags & (flag))) \
501 /* a backdoor for the console driver */
503 vga_configure(int flags)
508 for (i = 0; i < biosadapters; ++i) {
509 if (!probe_done(&biosadapter[i]))
511 biosadapter[i].va_flags |= V_ADP_INITIALIZED;
512 if (!config_done(&biosadapter[i])) {
513 if (vid_register(&biosadapter[i]) < 0)
515 biosadapter[i].va_flags |= V_ADP_REGISTERED;
518 if (vga_sub_configure != NULL)
519 (*vga_sub_configure)(flags);
524 /* local subroutines */
526 #if !defined(VGA_NO_BIOS) && !defined(VGA_NO_MODE_CHANGE)
527 /* construct the mode parameter map */
529 map_mode_table(u_char *map[], u_char *table, int max)
533 for(i = 0; i < max; ++i)
534 map[i] = table + i*V_MODE_PARAM_SIZE;
535 for(; i < V_MODE_MAP_SIZE; ++i)
538 #endif /* !VGA_NO_BIOS && !VGA_NO_MODE_CHANGE */
541 clear_mode_map(video_adapter_t *adp, u_char *map[], int max, int color)
547 * NOTE: we don't touch `bios_vmode[]' because it is shared
550 for(i = 0; i < max; ++i) {
551 if (vga_get_info(adp, i, &info))
553 if ((info.vi_flags & V_INFO_COLOR) != color)
558 #if !defined(VGA_NO_BIOS) && !defined(VGA_NO_MODE_CHANGE)
559 /* map the non-standard video mode to a known mode number */
561 map_mode_num(int mode)
567 { M_ENH_B80x43, M_ENH_B80x25 },
568 { M_ENH_C80x43, M_ENH_C80x25 },
569 { M_VGA_M80x30, M_VGA_M80x25 },
570 { M_VGA_C80x30, M_VGA_C80x25 },
571 { M_VGA_M80x50, M_VGA_M80x25 },
572 { M_VGA_C80x50, M_VGA_C80x25 },
573 { M_VGA_M80x60, M_VGA_M80x25 },
574 { M_VGA_C80x60, M_VGA_C80x25 },
576 { M_VGA_M90x25, M_VGA_M80x25 },
577 { M_VGA_C90x25, M_VGA_C80x25 },
578 { M_VGA_M90x30, M_VGA_M80x25 },
579 { M_VGA_C90x30, M_VGA_C80x25 },
580 { M_VGA_M90x43, M_ENH_B80x25 },
581 { M_VGA_C90x43, M_ENH_C80x25 },
582 { M_VGA_M90x50, M_VGA_M80x25 },
583 { M_VGA_C90x50, M_VGA_C80x25 },
584 { M_VGA_M90x60, M_VGA_M80x25 },
585 { M_VGA_C90x60, M_VGA_C80x25 },
587 { M_VGA_MODEX, M_VGA_CG320 },
591 for (i = 0; i < sizeof(mode_map)/sizeof(mode_map[0]); ++i) {
592 if (mode_map[i].from == mode)
593 return mode_map[i].to;
597 #endif /* !VGA_NO_BIOS && !VGA_NO_MODE_CHANGE */
599 /* map a generic video mode to a known mode number */
601 map_gen_mode_num(int type, int color, int mode)
608 { M_TEXT_80x30, M_VGA_C80x30, M_VGA_M80x30, },
609 { M_TEXT_80x43, M_ENH_C80x43, M_ENH_B80x43, },
610 { M_TEXT_80x50, M_VGA_C80x50, M_VGA_M80x50, },
611 { M_TEXT_80x60, M_VGA_C80x60, M_VGA_M80x60, },
615 if (mode == M_TEXT_80x25) {
629 return M_EGAMONO80x25;
637 return M_EGAMONO80x25; /* XXX: this name is confusing */
644 for (i = 0; i < sizeof(mode_map)/sizeof(mode_map[0]); ++i) {
645 if (mode_map[i].from == mode)
646 return ((color) ? mode_map[i].to_color : mode_map[i].to_mono);
651 /* turn the BIOS video number into our video mode number */
653 map_bios_mode_num(int type, int color, int bios_mode)
655 static int cga_modes[7] = {
656 M_B40x25, M_C40x25, /* 0, 1 */
657 M_B80x25, M_C80x25, /* 2, 3 */
661 static int ega_modes[17] = {
662 M_ENH_B40x25, M_ENH_C40x25, /* 0, 1 */
663 M_ENH_B80x25, M_ENH_C80x25, /* 2, 3 */
666 M_EGAMONO80x25, /* 7 */
670 M_ENHMONOAPA2, /* XXX: video momery > 64K */
671 M_ENH_CG640, /* XXX: video momery > 64K */
673 static int vga_modes[20] = {
674 M_VGA_C40x25, M_VGA_C40x25, /* 0, 1 */
675 M_VGA_C80x25, M_VGA_C80x25, /* 2, 3 */
678 M_VGA_M80x25, /* 7 */
684 M_BG640x480, M_CG640x480,
691 if (bios_mode < sizeof(vga_modes)/sizeof(vga_modes[0]))
692 return vga_modes[bios_mode];
700 if (bios_mode < sizeof(ega_modes)/sizeof(ega_modes[0]))
701 return ega_modes[bios_mode];
705 return M_EGAMONO80x25;
709 if (bios_mode < sizeof(cga_modes)/sizeof(cga_modes[0]))
710 return cga_modes[bios_mode];
717 return M_EGAMONO80x25; /* XXX: this name is confusing */
725 /* look up a parameter table entry */
727 *get_mode_param(int mode)
729 #if !defined(VGA_NO_BIOS) && !defined(VGA_NO_MODE_CHANGE)
730 if (mode >= V_MODE_MAP_SIZE)
731 mode = map_mode_num(mode);
733 if ((mode >= 0) && (mode < V_MODE_MAP_SIZE))
734 return mode_map[mode];
741 fill_adapter_param(int code, video_adapter_t *adp)
747 { DCC_MONO, DCC_EGA40 /* CGA monitor */ },
748 { DCC_MONO, DCC_EGA80 /* CGA monitor */ },
749 { DCC_MONO, DCC_EGA80 },
750 { DCC_MONO, DCC_EGA80 },
751 { DCC_CGA40, DCC_EGAMONO },
752 { DCC_CGA80, DCC_EGAMONO },
753 { DCC_EGA40 /* CGA monitor */, DCC_MONO},
754 { DCC_EGA80 /* CGA monitor */, DCC_MONO},
755 { DCC_EGA80, DCC_MONO },
756 { DCC_EGA80, DCC_MONO },
757 { DCC_EGAMONO, DCC_CGA40 },
758 { DCC_EGAMONO, DCC_CGA80 },
761 if ((code < 0) || (code >= sizeof(dcc)/sizeof(dcc[0]))) {
762 adp[V_ADP_PRIMARY] = adapter_init_value[DCC_MONO];
763 adp[V_ADP_SECONDARY] = adapter_init_value[DCC_CGA80];
765 adp[V_ADP_PRIMARY] = adapter_init_value[dcc[code].primary];
766 adp[V_ADP_SECONDARY] = adapter_init_value[dcc[code].secondary];
769 #endif /* VGA_NO_BIOS */
772 verify_adapter(video_adapter_t *adp)
776 #if !defined(VGA_NO_BIOS) && !defined(VGA_NO_MODE_CHANGE)
780 buf = BIOS_PADDRTOVADDR(adp->va_window);
783 if (readw(buf) != 0xA55A)
787 switch (adp->va_type) {
790 outb(adp->va_crtc_addr, 7);
791 if (inb(adp->va_crtc_addr) == 7) {
792 adp->va_type = KD_VGA;
793 adp->va_name = "vga";
794 adp->va_flags |= V_ADP_STATESAVE | V_ADP_PALETTE;
796 adp->va_flags |= V_ADP_STATELOAD | V_ADP_BORDER;
797 /* the color adapter may be in the 40x25 mode... XXX */
799 #if !defined(VGA_NO_BIOS) && !defined(VGA_NO_MODE_CHANGE)
800 /* get the BIOS video mode pointer */
801 p = *(u_int32_t *)BIOS_PADDRTOVADDR(0x4a8);
802 p = BIOS_SADDRTOLADDR(p);
803 if (ISMAPPED(p, sizeof(u_int32_t))) {
804 p = *(u_int32_t *)BIOS_PADDRTOVADDR(p);
805 p = BIOS_SADDRTOLADDR(p);
806 if (ISMAPPED(p, V_MODE_PARAM_SIZE))
807 video_mode_ptr = (u_char *)BIOS_PADDRTOVADDR(p);
813 adp->va_flags |= V_ADP_COLOR | V_ADP_BORDER;
814 /* may be in the 40x25 mode... XXX */
815 #if !defined(VGA_NO_BIOS) && !defined(VGA_NO_MODE_CHANGE)
816 /* get the BIOS video mode pointer */
817 p = *(u_int32_t *)BIOS_PADDRTOVADDR(0x1d*4);
818 p = BIOS_SADDRTOLADDR(p);
819 video_mode_ptr2 = (u_char *)BIOS_PADDRTOVADDR(p);
824 #if !defined(VGA_NO_BIOS) && !defined(VGA_NO_MODE_CHANGE)
825 /* get the BIOS video mode pointer */
826 p = *(u_int32_t *)BIOS_PADDRTOVADDR(0x1d*4);
827 p = BIOS_SADDRTOLADDR(p);
828 video_mode_ptr2 = (u_char *)BIOS_PADDRTOVADDR(p);
837 update_adapter_info(video_adapter_t *adp, video_info_t *info)
839 adp->va_flags &= ~V_ADP_COLOR;
841 (info->vi_flags & V_INFO_COLOR) ? V_ADP_COLOR : 0;
843 (adp->va_flags & V_ADP_COLOR) ? COLOR_CRTC : MONO_CRTC;
844 adp->va_window = BIOS_PADDRTOVADDR(info->vi_window);
845 adp->va_window_size = info->vi_window_size;
846 adp->va_window_gran = info->vi_window_gran;
847 adp->va_window_orig = 0;
849 adp->va_buffer = info->vi_buffer;
850 adp->va_buffer_size = info->vi_buffer_size;
851 if (info->vi_mem_model == V_INFO_MM_VGAX) {
852 adp->va_line_width = info->vi_width/2;
853 } else if (info->vi_flags & V_INFO_GRAPHICS) {
854 switch (info->vi_depth/info->vi_planes) {
856 adp->va_line_width = info->vi_width/8;
859 adp->va_line_width = info->vi_width/4;
862 adp->va_line_width = info->vi_width/2;
865 default: /* shouldn't happen */
866 adp->va_line_width = info->vi_width;
870 adp->va_line_width = info->vi_width;
872 adp->va_disp_start.x = 0;
873 adp->va_disp_start.y = 0;
874 bcopy(info, &adp->va_info, sizeof(adp->va_info));
877 #if !defined(VGA_NO_BIOS) && !defined(VGA_NO_MODE_CHANGE)
878 /* compare two parameter table entries */
880 comp_adpregs(u_char *buf1, u_char *buf2)
884 } params[V_MODE_PARAM_SIZE] = {
885 {0xff}, {0x00}, {0xff}, /* COLS}, ROWS}, POINTS */
886 {0x00}, {0x00}, /* page length */
887 {0xfe}, {0xff}, {0xff}, {0xff}, /* sequencer registers */
888 {0xf3}, /* misc register */
889 {0xff}, {0xff}, {0xff}, {0x7f}, {0xff}, /* CRTC */
890 {0xff}, {0xff}, {0xff}, {0x7f}, {0xff},
891 {0x00}, {0x00}, {0x00}, {0x00}, {0x00},
892 {0x00}, {0xff}, {0x7f}, {0xff}, {0xff},
893 {0x7f}, {0xff}, {0xff}, {0xef}, {0xff},
894 {0xff}, {0xff}, {0xff}, {0xff}, {0xff}, /* attribute controller regs */
895 {0xff}, {0xff}, {0xff}, {0xff}, {0xff},
896 {0xff}, {0xff}, {0xff}, {0xff}, {0xff},
897 {0xff}, {0xff}, {0xff}, {0xff}, {0xf0},
898 {0xff}, {0xff}, {0xff}, {0xff}, {0xff}, /* GDC register */
899 {0xff}, {0xff}, {0xff}, {0xff},
901 int identical = TRUE;
904 if ((buf1 == NULL) || (buf2 == NULL))
905 return COMP_DIFFERENT;
907 for (i = 0; i < sizeof(params)/sizeof(params[0]); ++i) {
908 if (params[i].mask == 0) /* don't care */
910 if ((buf1[i] & params[i].mask) != (buf2[i] & params[i].mask))
911 return COMP_DIFFERENT;
912 if (buf1[i] != buf2[i])
915 return (identical) ? COMP_IDENTICAL : COMP_SIMILAR;
917 #endif /* !VGA_NO_BIOS && !VGA_NO_MODE_CHANGE */
919 /* probe video adapters and return the number of detected adapters */
923 video_adapter_t *adp;
925 #if !defined(VGA_NO_BIOS) && !defined(VGA_NO_MODE_CHANGE)
930 /* do this test only once */
933 vga_init_done = TRUE;
936 * Locate display adapters.
937 * The AT architecture supports upto two adapters. `syscons' allows
938 * the following combinations of adapters:
940 * 2) MDA + EGA/VGA color
941 * 3) CGA + EGA/VGA mono
942 * Note that `syscons' doesn't bother with MCGA as it is only
943 * avaiable for low end PS/2 models which has 80286 or earlier CPUs,
944 * thus, they are not running FreeBSD!
945 * When there are two adapaters in the system, one becomes `primary'
946 * and the other `secondary'. The EGA adapter has a set of DIP
947 * switches on board for this information and the EGA BIOS copies
948 * it in the BIOS data area BIOSDATA_VIDEOSWITCH (40:88).
949 * The VGA BIOS has more sophisticated mechanism and has this
950 * information in BIOSDATA_DCCINDEX (40:8a), but it also maintains
951 * compatibility with the EGA BIOS by updating BIOSDATA_VIDEOSWITCH.
955 * Check rtc and BIOS data area.
956 * XXX: we don't use BIOSDATA_EQUIPMENT, since it is not a dead
957 * copy of RTC_EQUIPMENT. Bits 4 and 5 of ETC_EQUIPMENT are
958 * zeros for EGA and VGA. However, the EGA/VGA BIOS sets
959 * these bits in BIOSDATA_EQUIPMENT according to the monitor
963 if (*(u_int32_t *)BIOS_PADDRTOVADDR(0x4a8)) {
964 /* EGA/VGA BIOS is present */
965 fill_adapter_param(readb(BIOS_PADDRTOVADDR(0x488)) & 0x0f,
968 switch ((rtcin(RTC_EQUIPMENT) >> 4) & 3) { /* bit 4 and 5 */
970 /* EGA/VGA: shouldn't be happening */
971 fill_adapter_param(readb(BIOS_PADDRTOVADDR(0x488)) & 0x0f,
976 /* FIXME: switch to the 80x25 mode? XXX */
977 biosadapter[V_ADP_PRIMARY] = adapter_init_value[DCC_CGA40];
978 biosadapter[V_ADP_SECONDARY] = adapter_init_value[DCC_MONO];
982 biosadapter[V_ADP_PRIMARY] = adapter_init_value[DCC_CGA80];
983 biosadapter[V_ADP_SECONDARY] = adapter_init_value[DCC_MONO];
987 biosadapter[V_ADP_PRIMARY] = adapter_init_value[DCC_MONO];
988 biosadapter[V_ADP_SECONDARY] = adapter_init_value[DCC_CGA80];
993 /* assume EGA/VGA? XXX */
994 biosadapter[V_ADP_PRIMARY] = adapter_init_value[DCC_EGA80];
995 biosadapter[V_ADP_SECONDARY] = adapter_init_value[DCC_MONO];
996 #endif /* VGA_NO_BIOS */
999 if (verify_adapter(&biosadapter[V_ADP_SECONDARY]) == 0) {
1001 biosadapter[V_ADP_SECONDARY].va_flags |= V_ADP_PROBED;
1002 biosadapter[V_ADP_SECONDARY].va_mode =
1003 biosadapter[V_ADP_SECONDARY].va_initial_mode =
1004 map_bios_mode_num(biosadapter[V_ADP_SECONDARY].va_type,
1005 biosadapter[V_ADP_SECONDARY].va_flags
1007 biosadapter[V_ADP_SECONDARY].va_initial_bios_mode);
1009 biosadapter[V_ADP_SECONDARY].va_type = -1;
1011 if (verify_adapter(&biosadapter[V_ADP_PRIMARY]) == 0) {
1013 biosadapter[V_ADP_PRIMARY].va_flags |= V_ADP_PROBED;
1015 biosadapter[V_ADP_PRIMARY].va_initial_bios_mode =
1016 readb(BIOS_PADDRTOVADDR(0x449));
1018 biosadapter[V_ADP_PRIMARY].va_initial_bios_mode = 3; /* XXX */
1020 biosadapter[V_ADP_PRIMARY].va_mode =
1021 biosadapter[V_ADP_PRIMARY].va_initial_mode =
1022 map_bios_mode_num(biosadapter[V_ADP_PRIMARY].va_type,
1023 biosadapter[V_ADP_PRIMARY].va_flags & V_ADP_COLOR,
1024 biosadapter[V_ADP_PRIMARY].va_initial_bios_mode);
1026 biosadapter[V_ADP_PRIMARY] = biosadapter[V_ADP_SECONDARY];
1027 biosadapter[V_ADP_SECONDARY].va_type = -1;
1029 if (biosadapters == 0)
1030 return biosadapters;
1031 biosadapter[V_ADP_PRIMARY].va_unit = V_ADP_PRIMARY;
1032 biosadapter[V_ADP_SECONDARY].va_unit = V_ADP_SECONDARY;
1034 #if 0 /* we don't need these... */
1035 fb_init_struct(&biosadapter[V_ADP_PRIMARY], ...);
1036 fb_init_struct(&biosadapter[V_ADP_SECONDARY], ...);
1041 * We cannot have two video adapter of the same type; there must be
1042 * only one of color or mono adapter, or one each of them.
1044 if (biosadapters > 1) {
1045 if (!((biosadapter[0].va_flags ^ biosadapter[1].va_flags)
1047 /* we have two mono or color adapters!! */
1048 return (biosadapters = 0);
1053 * Ensure a zero start address. This is mainly to recover after
1054 * switching from pcvt using userconfig(). The registers are w/o
1055 * for old hardware so it's too hard to relocate the active screen
1057 * This must be done before vga_save_state() for VGA.
1059 outb(biosadapter[V_ADP_PRIMARY].va_crtc_addr, 12);
1060 outb(biosadapter[V_ADP_PRIMARY].va_crtc_addr + 1, 0);
1061 outb(biosadapter[V_ADP_PRIMARY].va_crtc_addr, 13);
1062 outb(biosadapter[V_ADP_PRIMARY].va_crtc_addr + 1, 0);
1064 /* the video mode parameter table in EGA/VGA BIOS */
1065 /* NOTE: there can be only one EGA/VGA, wheather color or mono,
1066 * recognized by the video BIOS.
1068 if ((biosadapter[V_ADP_PRIMARY].va_type == KD_EGA) ||
1069 (biosadapter[V_ADP_PRIMARY].va_type == KD_VGA)) {
1070 adp = &biosadapter[V_ADP_PRIMARY];
1071 } else if ((biosadapter[V_ADP_SECONDARY].va_type == KD_EGA) ||
1072 (biosadapter[V_ADP_SECONDARY].va_type == KD_VGA)) {
1073 adp = &biosadapter[V_ADP_SECONDARY];
1077 bzero(mode_map, sizeof(mode_map));
1079 if (adp->va_type == KD_VGA) {
1080 vga_save_state(adp, &adpstate, sizeof(adpstate));
1081 #if defined(VGA_NO_BIOS) || defined(VGA_NO_MODE_CHANGE)
1082 mode_map[adp->va_initial_mode] = adpstate.regs;
1084 #else /* VGA_NO_BIOS || VGA_NO_MODE_CHANGE */
1085 if (video_mode_ptr == NULL) {
1086 mode_map[adp->va_initial_mode] = adpstate.regs;
1089 /* discard the table if we are not familiar with it... */
1090 map_mode_table(mode_map, video_mode_ptr, M_VGA_CG320 + 1);
1091 mp = get_mode_param(adp->va_initial_mode);
1093 bcopy(mp, adpstate2.regs, sizeof(adpstate2.regs));
1094 switch (comp_adpregs(adpstate.regs, mp)) {
1095 case COMP_IDENTICAL:
1097 * OK, this parameter table looks reasonably familiar
1101 * This is a kludge for Toshiba DynaBook SS433
1102 * whose BIOS video mode table entry has the actual #
1103 * of rows at the offset 1; BIOSes from other
1104 * manufacturers store the # of rows - 1 there. XXX
1106 rows_offset = adpstate.regs[1] + 1 - mp[1];
1111 * Not exactly the same, but similar enough to be
1112 * trusted. However, use the saved register values
1113 * for the initial mode and other modes which are
1114 * based on the initial mode.
1116 mode_map[adp->va_initial_mode] = adpstate.regs;
1117 rows_offset = adpstate.regs[1] + 1 - mp[1];
1118 adpstate.regs[1] -= rows_offset - 1;
1121 case COMP_DIFFERENT:
1124 * Don't use the paramter table in BIOS. It doesn't
1125 * look familiar to us. Video mode switching is allowed
1126 * only if the new mode is the same as or based on
1129 video_mode_ptr = NULL;
1130 bzero(mode_map, sizeof(mode_map));
1131 mode_map[adp->va_initial_mode] = adpstate.regs;
1136 #endif /* VGA_NO_BIOS || VGA_NO_MODE_CHANGE */
1138 #ifndef VGA_NO_MODE_CHANGE
1139 adp->va_flags |= V_ADP_MODECHANGE;
1141 #ifndef VGA_NO_FONT_LOADING
1142 adp->va_flags |= V_ADP_FONT;
1144 } else if (adp->va_type == KD_EGA) {
1145 #if defined(VGA_NO_BIOS) || defined(VGA_NO_MODE_CHANGE)
1147 #else /* VGA_NO_BIOS || VGA_NO_MODE_CHANGE */
1148 if (video_mode_ptr == NULL) {
1151 map_mode_table(mode_map, video_mode_ptr, M_ENH_C80x25 + 1);
1152 /* XXX how can one validate the EGA table... */
1153 mp = get_mode_param(adp->va_initial_mode);
1155 adp->va_flags |= V_ADP_MODECHANGE;
1156 #ifndef VGA_NO_FONT_LOADING
1157 adp->va_flags |= V_ADP_FONT;
1162 * This is serious. We will not be able to switch video
1165 video_mode_ptr = NULL;
1166 bzero(mode_map, sizeof(mode_map));
1170 #endif /* VGA_NO_BIOS || VGA_NO_MODE_CHANGE */
1174 /* remove conflicting modes if we have more than one adapter */
1175 if (biosadapters > 0) {
1176 for (i = 0; i < biosadapters; ++i) {
1177 if (!(biosadapter[i].va_flags & V_ADP_MODECHANGE))
1179 clear_mode_map(&biosadapter[i], mode_map, M_VGA_CG320 + 1,
1180 (biosadapter[i].va_flags & V_ADP_COLOR) ?
1182 if ((biosadapter[i].va_type == KD_VGA)
1183 || (biosadapter[i].va_type == KD_EGA)) {
1184 biosadapter[i].va_io_base =
1185 (biosadapter[i].va_flags & V_ADP_COLOR) ?
1187 biosadapter[i].va_io_size = 32;
1192 /* buffer address */
1193 vga_get_info(&biosadapter[V_ADP_PRIMARY],
1194 biosadapter[V_ADP_PRIMARY].va_initial_mode, &info);
1195 info.vi_flags &= ~V_INFO_LINEAR; /* XXX */
1196 update_adapter_info(&biosadapter[V_ADP_PRIMARY], &info);
1198 if (biosadapters > 1) {
1199 vga_get_info(&biosadapter[V_ADP_SECONDARY],
1200 biosadapter[V_ADP_SECONDARY].va_initial_mode, &info);
1201 info.vi_flags &= ~V_INFO_LINEAR; /* XXX */
1202 update_adapter_info(&biosadapter[V_ADP_SECONDARY], &info);
1206 * XXX: we should verify the following values for the primary adapter...
1207 * crtc I/O port address: *(u_int16_t *)BIOS_PADDRTOVADDR(0x463);
1208 * color/mono display: (*(u_int8_t *)BIOS_PADDRTOVADDR(0x487) & 0x02)
1209 * ? 0 : V_ADP_COLOR;
1210 * columns: *(u_int8_t *)BIOS_PADDRTOVADDR(0x44a);
1211 * rows: *(u_int8_t *)BIOS_PADDRTOVADDR(0x484);
1212 * font size: *(u_int8_t *)BIOS_PADDRTOVADDR(0x485);
1213 * buffer size: *(u_int16_t *)BIOS_PADDRTOVADDR(0x44c);
1216 return biosadapters;
1219 /* set the scan line length in pixel */
1221 set_line_length(video_adapter_t *adp, int pixel)
1224 int ppw; /* pixels per word */
1225 int bpl; /* bytes per line */
1228 if ((adp->va_type != KD_VGA) && (adp->va_type != KD_EGA))
1230 mp = get_mode_param(adp->va_mode);
1234 switch (adp->va_info.vi_mem_model) {
1235 case V_INFO_MM_PLANAR:
1236 ppw = 16/(adp->va_info.vi_depth/adp->va_info.vi_planes);
1237 count = (pixel + ppw - 1)/ppw/2;
1238 bpl = ((pixel + ppw - 1)/ppw/2)*4;
1240 case V_INFO_MM_PACKED:
1241 count = (pixel + 7)/8;
1242 bpl = ((pixel + 7)/8)*8;
1244 case V_INFO_MM_TEXT:
1245 count = (pixel + 7)/8; /* columns */
1246 bpl = (pixel + 7)/8; /* columns */
1252 if (mp[10 + 0x17] & 0x40) /* CRTC mode control reg */
1253 count *= 2; /* byte mode */
1254 outb(adp->va_crtc_addr, 0x13);
1255 outb(adp->va_crtc_addr + 1, count);
1256 adp->va_line_width = bpl;
1262 set_display_start(video_adapter_t *adp, int x, int y)
1264 int off; /* byte offset (graphics mode)/word offset (text mode) */
1265 int poff; /* pixel offset */
1266 int roff; /* row offset */
1267 int ppb; /* pixels per byte */
1269 if ((adp->va_type != KD_VGA) && (adp->va_type != KD_EGA))
1271 if (adp->va_info.vi_flags & V_INFO_GRAPHICS) {
1272 ppb = 8/(adp->va_info.vi_depth/adp->va_info.vi_planes);
1273 off = y*adp->va_line_width + x/ppb;
1277 if ((adp->va_type == KD_VGA) || (adp->va_type == KD_EGA)) {
1286 off = y/adp->va_info.vi_cheight*adp->va_line_width + x/ppb;
1287 roff = y%adp->va_info.vi_cheight;
1288 /* FIXME: is this correct? XXX */
1296 outb(adp->va_crtc_addr, 0xc); /* high */
1297 outb(adp->va_crtc_addr + 1, off >> 8);
1298 outb(adp->va_crtc_addr, 0xd); /* low */
1299 outb(adp->va_crtc_addr + 1, off & 0xff);
1301 /* horizontal pel pan */
1302 if ((adp->va_type == KD_VGA) || (adp->va_type == KD_EGA)) {
1303 inb(adp->va_crtc_addr + 6);
1304 outb(ATC, 0x13 | 0x20);
1306 inb(adp->va_crtc_addr + 6);
1310 /* preset raw scan */
1311 outb(adp->va_crtc_addr, 8);
1312 outb(adp->va_crtc_addr + 1, roff);
1314 adp->va_disp_start.x = x;
1315 adp->va_disp_start.y = y;
1319 #ifdef __i386__ /* XXX */
1321 fill(int val, void *d, size_t size)
1328 #endif /* __i386__ */
1331 filll_io(int val, vm_offset_t d, size_t size)
1333 while (size-- > 0) {
1335 d += sizeof(u_int32_t);
1356 vga_probe(int unit, video_adapter_t **adpp, void *arg, int flags)
1359 if (unit >= biosadapters)
1362 *adpp = &biosadapter[unit];
1368 vga_init(int unit, video_adapter_t *adp, int flags)
1370 if ((unit >= biosadapters) || (adp == NULL) || !probe_done(adp))
1373 if (!init_done(adp)) {
1374 /* nothing to do really... */
1375 adp->va_flags |= V_ADP_INITIALIZED;
1378 if (!config_done(adp)) {
1379 if (vid_register(adp) < 0)
1381 adp->va_flags |= V_ADP_REGISTERED;
1383 if (vga_sub_configure != NULL)
1384 (*vga_sub_configure)(0);
1391 * Return the video_info structure of the requested video mode.
1396 vga_get_info(video_adapter_t *adp, int mode, video_info_t *info)
1403 mode = map_gen_mode_num(adp->va_type, adp->va_flags & V_ADP_COLOR, mode);
1404 #ifndef VGA_NO_MODE_CHANGE
1405 if (adp->va_flags & V_ADP_MODECHANGE) {
1407 * If the parameter table entry for this mode is not found,
1408 * the mode is not supported...
1410 if (get_mode_param(mode) == NULL)
1413 #endif /* VGA_NO_MODE_CHANGE */
1416 * Even if we don't support video mode switching on this adapter,
1417 * the information on the initial (thus current) video mode
1418 * should be made available.
1420 if (mode != adp->va_initial_mode)
1424 for (i = 0; bios_vmode[i].vi_mode != EOT; ++i) {
1425 if (bios_vmode[i].vi_mode == NA)
1427 if (mode == bios_vmode[i].vi_mode) {
1428 *info = bios_vmode[i];
1430 info->vi_buffer_size = info->vi_window_size*info->vi_planes;
1439 * Find a video mode matching the requested parameters.
1440 * Fields filled with 0 are considered "don't care" fields and
1446 vga_query_mode(video_adapter_t *adp, video_info_t *info)
1453 for (i = 0; bios_vmode[i].vi_mode != EOT; ++i) {
1454 if (bios_vmode[i].vi_mode == NA)
1457 if ((info->vi_width != 0)
1458 && (info->vi_width != bios_vmode[i].vi_width))
1460 if ((info->vi_height != 0)
1461 && (info->vi_height != bios_vmode[i].vi_height))
1463 if ((info->vi_cwidth != 0)
1464 && (info->vi_cwidth != bios_vmode[i].vi_cwidth))
1466 if ((info->vi_cheight != 0)
1467 && (info->vi_cheight != bios_vmode[i].vi_cheight))
1469 if ((info->vi_depth != 0)
1470 && (info->vi_depth != bios_vmode[i].vi_depth))
1472 if ((info->vi_planes != 0)
1473 && (info->vi_planes != bios_vmode[i].vi_planes))
1475 /* XXX: should check pixel format, memory model */
1476 if ((info->vi_flags != 0)
1477 && (info->vi_flags != bios_vmode[i].vi_flags))
1480 /* verify if this mode is supported on this adapter */
1481 if (vga_get_info(adp, bios_vmode[i].vi_mode, info))
1490 * Change the video mode.
1495 #ifndef VGA_NO_MODE_CHANGE
1498 set_width90(adp_state_t *params)
1501 * Based on code submitted by Kelly Yancey (kbyanc@freedomnet.com)
1502 * and alexv@sui.gda.itesm.mx.
1504 params->regs[5] |= 1; /* toggle 8 pixel wide fonts */
1505 params->regs[10+0x0] = 0x6b;
1506 params->regs[10+0x1] = 0x59;
1507 params->regs[10+0x2] = 0x5a;
1508 params->regs[10+0x3] = 0x8e;
1509 params->regs[10+0x4] = 0x5e;
1510 params->regs[10+0x5] = 0x8a;
1511 params->regs[10+0x13] = 45;
1512 params->regs[35+0x13] = 0;
1514 #endif /* VGA_WIDTH90 */
1515 #endif /* !VGA_NO_MODE_CHANGE */
1518 vga_set_mode(video_adapter_t *adp, int mode)
1520 #ifndef VGA_NO_MODE_CHANGE
1524 prologue(adp, V_ADP_MODECHANGE, ENODEV);
1526 mode = map_gen_mode_num(adp->va_type,
1527 adp->va_flags & V_ADP_COLOR, mode);
1528 if (vga_get_info(adp, mode, &info))
1532 printf("vga_set_mode(): setting mode %d\n", mode);
1535 params.sig = V_STATE_SIG;
1536 bcopy(get_mode_param(mode), params.regs, sizeof(params.regs));
1540 case M_VGA_C90x60: case M_VGA_M90x60:
1541 set_width90(¶ms);
1544 case M_VGA_C80x60: case M_VGA_M80x60:
1545 params.regs[2] = 0x08;
1546 params.regs[19] = 0x47;
1550 case M_VGA_C90x30: case M_VGA_M90x30:
1551 set_width90(¶ms);
1554 case M_VGA_C80x30: case M_VGA_M80x30:
1555 params.regs[19] = 0x4f;
1557 params.regs[9] |= 0xc0;
1558 params.regs[16] = 0x08;
1559 params.regs[17] = 0x3e;
1560 params.regs[26] = 0xea;
1561 params.regs[28] = 0xdf;
1562 params.regs[31] = 0xe7;
1563 params.regs[32] = 0x04;
1567 case M_VGA_C90x43: case M_VGA_M90x43:
1568 set_width90(¶ms);
1571 case M_ENH_C80x43: case M_ENH_B80x43:
1572 params.regs[28] = 87;
1576 case M_VGA_C90x50: case M_VGA_M90x50:
1577 set_width90(¶ms);
1580 case M_VGA_C80x50: case M_VGA_M80x50:
1583 params.regs[19] = 7;
1587 case M_VGA_C90x25: case M_VGA_M90x25:
1588 set_width90(¶ms);
1591 case M_VGA_C40x25: case M_VGA_C80x25:
1593 case M_B40x25: case M_C40x25:
1594 case M_B80x25: case M_C80x25:
1595 case M_ENH_B40x25: case M_ENH_C40x25:
1596 case M_ENH_B80x25: case M_ENH_C80x25:
1597 case M_EGAMONO80x25:
1600 vga_load_state(adp, ¶ms);
1604 /* "unchain" the VGA mode */
1605 params.regs[5-1+0x04] &= 0xf7;
1606 params.regs[5-1+0x04] |= 0x04;
1607 /* turn off doubleword mode */
1608 params.regs[10+0x14] &= 0xbf;
1609 /* turn off word adressing */
1610 params.regs[10+0x17] |= 0x40;
1611 /* set logical screen width */
1612 params.regs[10+0x13] = 80;
1614 params.regs[10+0x11] = 0x2c;
1615 params.regs[10+0x06] = 0x0d;
1616 params.regs[10+0x07] = 0x3e;
1617 params.regs[10+0x10] = 0xea;
1618 params.regs[10+0x11] = 0xac;
1619 params.regs[10+0x12] = 0xdf;
1620 params.regs[10+0x15] = 0xe7;
1621 params.regs[10+0x16] = 0x06;
1622 /* set vertical sync polarity to reflect aspect ratio */
1623 params.regs[9] = 0xe3;
1626 case M_BG320: case M_CG320: case M_BG640:
1627 case M_CG320_D: case M_CG640_E:
1628 case M_CG640x350: case M_ENH_CG640:
1629 case M_BG640x480: case M_CG640x480: case M_VGA_CG320:
1632 vga_load_state(adp, ¶ms);
1639 adp->va_mode = mode;
1640 info.vi_flags &= ~V_INFO_LINEAR; /* XXX */
1641 update_adapter_info(adp, &info);
1643 /* move hardware cursor out of the way */
1644 (*vidsw[adp->va_index]->set_hw_cursor)(adp, -1, -1);
1647 #else /* VGA_NO_MODE_CHANGE */
1649 #endif /* VGA_NO_MODE_CHANGE */
1652 #ifndef VGA_NO_FONT_LOADING
1655 set_font_mode(video_adapter_t *adp, u_char *buf)
1662 /* save register values */
1663 if (adp->va_type == KD_VGA) {
1664 outb(TSIDX, 0x02); buf[0] = inb(TSREG);
1665 outb(TSIDX, 0x04); buf[1] = inb(TSREG);
1666 outb(GDCIDX, 0x04); buf[2] = inb(GDCREG);
1667 outb(GDCIDX, 0x05); buf[3] = inb(GDCREG);
1668 outb(GDCIDX, 0x06); buf[4] = inb(GDCREG);
1669 inb(adp->va_crtc_addr + 6);
1670 outb(ATC, 0x10); buf[5] = inb(ATC + 1);
1671 } else /* if (adp->va_type == KD_EGA) */ {
1673 * EGA cannot be read; copy parameters from the mode parameter
1676 mp = get_mode_param(adp->va_mode);
1677 buf[0] = mp[5 + 0x02 - 1];
1678 buf[1] = mp[5 + 0x04 - 1];
1679 buf[2] = mp[55 + 0x04];
1680 buf[3] = mp[55 + 0x05];
1681 buf[4] = mp[55 + 0x06];
1682 buf[5] = mp[35 + 0x10];
1685 /* setup vga for loading fonts */
1686 inb(adp->va_crtc_addr + 6); /* reset flip-flop */
1687 outb(ATC, 0x10); outb(ATC, buf[5] & ~0x01);
1688 inb(adp->va_crtc_addr + 6); /* reset flip-flop */
1689 outb(ATC, 0x20); /* enable palette */
1691 #if VGA_SLOW_IOACCESS
1692 #ifdef VGA_ALT_SEQACCESS
1693 outb(TSIDX, 0x00); outb(TSREG, 0x01);
1695 outb(TSIDX, 0x02); outb(TSREG, 0x04);
1696 outb(TSIDX, 0x04); outb(TSREG, 0x07);
1697 #ifdef VGA_ALT_SEQACCESS
1698 outb(TSIDX, 0x00); outb(TSREG, 0x03);
1700 outb(GDCIDX, 0x04); outb(GDCREG, 0x02);
1701 outb(GDCIDX, 0x05); outb(GDCREG, 0x00);
1702 outb(GDCIDX, 0x06); outb(GDCREG, 0x04);
1703 #else /* VGA_SLOW_IOACCESS */
1704 #ifdef VGA_ALT_SEQACCESS
1705 outw(TSIDX, 0x0100);
1707 outw(TSIDX, 0x0402);
1708 outw(TSIDX, 0x0704);
1709 #ifdef VGA_ALT_SEQACCESS
1710 outw(TSIDX, 0x0300);
1712 outw(GDCIDX, 0x0204);
1713 outw(GDCIDX, 0x0005);
1714 outw(GDCIDX, 0x0406); /* addr = a0000, 64kb */
1715 #endif /* VGA_SLOW_IOACCESS */
1721 set_normal_mode(video_adapter_t *adp, u_char *buf)
1727 /* setup vga for normal operation mode again */
1728 inb(adp->va_crtc_addr + 6); /* reset flip-flop */
1729 outb(ATC, 0x10); outb(ATC, buf[5]);
1730 inb(adp->va_crtc_addr + 6); /* reset flip-flop */
1731 outb(ATC, 0x20); /* enable palette */
1733 #if VGA_SLOW_IOACCESS
1734 #ifdef VGA_ALT_SEQACCESS
1735 outb(TSIDX, 0x00); outb(TSREG, 0x01);
1737 outb(TSIDX, 0x02); outb(TSREG, buf[0]);
1738 outb(TSIDX, 0x04); outb(TSREG, buf[1]);
1739 #ifdef VGA_ALT_SEQACCESS
1740 outb(TSIDX, 0x00); outb(TSREG, 0x03);
1742 outb(GDCIDX, 0x04); outb(GDCREG, buf[2]);
1743 outb(GDCIDX, 0x05); outb(GDCREG, buf[3]);
1744 if (adp->va_crtc_addr == MONO_CRTC) {
1745 outb(GDCIDX, 0x06); outb(GDCREG,(buf[4] & 0x03) | 0x08);
1747 outb(GDCIDX, 0x06); outb(GDCREG,(buf[4] & 0x03) | 0x0c);
1749 #else /* VGA_SLOW_IOACCESS */
1750 #ifdef VGA_ALT_SEQACCESS
1751 outw(TSIDX, 0x0100);
1753 outw(TSIDX, 0x0002 | (buf[0] << 8));
1754 outw(TSIDX, 0x0004 | (buf[1] << 8));
1755 #ifdef VGA_ALT_SEQACCESS
1756 outw(TSIDX, 0x0300);
1758 outw(GDCIDX, 0x0004 | (buf[2] << 8));
1759 outw(GDCIDX, 0x0005 | (buf[3] << 8));
1760 if (adp->va_crtc_addr == MONO_CRTC)
1761 outw(GDCIDX, 0x0006 | (((buf[4] & 0x03) | 0x08)<<8));
1763 outw(GDCIDX, 0x0006 | (((buf[4] & 0x03) | 0x0c)<<8));
1764 #endif /* VGA_SLOW_IOACCESS */
1769 #endif /* VGA_NO_FONT_LOADING */
1773 * Read the font data in the requested font page from the video adapter.
1778 vga_save_font(video_adapter_t *adp, int page, int fontsize, u_char *data,
1781 #ifndef VGA_NO_FONT_LOADING
1782 u_char buf[PARAM_BUFSIZE];
1785 #ifdef VGA_ALT_SEQACCESS
1790 prologue(adp, V_ADP_FONT, ENODEV);
1792 if (fontsize < 14) {
1795 } else if (fontsize >= 32) {
1797 } else if (fontsize >= 16) {
1805 if (page < 0 || page >= 8)
1807 segment = FONT_BUF + 0x4000*page;
1811 #ifdef VGA_ALT_SEQACCESS
1812 if (adp->va_type == KD_VGA) { /* what about EGA? XXX */
1814 outb(TSIDX, 0x00); outb(TSREG, 0x01);
1815 outb(TSIDX, 0x01); val = inb(TSREG); /* disable screen */
1816 outb(TSIDX, 0x01); outb(TSREG, val | 0x20);
1817 outb(TSIDX, 0x00); outb(TSREG, 0x03);
1822 set_font_mode(adp, buf);
1823 if (fontsize == 32) {
1824 bcopy_fromio(segment + ch*32, data, fontsize*count);
1826 for (c = ch; count > 0; ++c, --count) {
1827 bcopy_fromio(segment + c*32, data, fontsize);
1831 set_normal_mode(adp, buf);
1833 #ifdef VGA_ALT_SEQACCESS
1834 if (adp->va_type == KD_VGA) {
1836 outb(TSIDX, 0x00); outb(TSREG, 0x01);
1837 outb(TSIDX, 0x01); outb(TSREG, val & 0xdf); /* enable screen */
1838 outb(TSIDX, 0x00); outb(TSREG, 0x03);
1844 #else /* VGA_NO_FONT_LOADING */
1846 #endif /* VGA_NO_FONT_LOADING */
1851 * Set the font data in the requested font page.
1852 * NOTE: it appears that some recent video adapters do not support
1853 * the font page other than 0... XXX
1858 vga_load_font(video_adapter_t *adp, int page, int fontsize, u_char *data,
1861 #ifndef VGA_NO_FONT_LOADING
1862 u_char buf[PARAM_BUFSIZE];
1865 #ifdef VGA_ALT_SEQACCESS
1870 prologue(adp, V_ADP_FONT, ENODEV);
1872 if (fontsize < 14) {
1875 } else if (fontsize >= 32) {
1877 } else if (fontsize >= 16) {
1885 if (page < 0 || page >= 8)
1887 segment = FONT_BUF + 0x4000*page;
1891 #ifdef VGA_ALT_SEQACCESS
1892 if (adp->va_type == KD_VGA) { /* what about EGA? XXX */
1894 outb(TSIDX, 0x00); outb(TSREG, 0x01);
1895 outb(TSIDX, 0x01); val = inb(TSREG); /* disable screen */
1896 outb(TSIDX, 0x01); outb(TSREG, val | 0x20);
1897 outb(TSIDX, 0x00); outb(TSREG, 0x03);
1902 set_font_mode(adp, buf);
1903 if (fontsize == 32) {
1904 bcopy_toio(data, segment + ch*32, fontsize*count);
1906 for (c = ch; count > 0; ++c, --count) {
1907 bcopy_toio(data, segment + c*32, fontsize);
1911 set_normal_mode(adp, buf);
1913 #ifdef VGA_ALT_SEQACCESS
1914 if (adp->va_type == KD_VGA) {
1916 outb(TSIDX, 0x00); outb(TSREG, 0x01);
1917 outb(TSIDX, 0x01); outb(TSREG, val & 0xdf); /* enable screen */
1918 outb(TSIDX, 0x00); outb(TSREG, 0x03);
1924 #else /* VGA_NO_FONT_LOADING */
1926 #endif /* VGA_NO_FONT_LOADING */
1931 * Activate the requested font page.
1932 * NOTE: it appears that some recent video adapters do not support
1933 * the font page other than 0... XXX
1938 vga_show_font(video_adapter_t *adp, int page)
1940 #ifndef VGA_NO_FONT_LOADING
1941 static u_char cg[] = { 0x00, 0x05, 0x0a, 0x0f, 0x30, 0x35, 0x3a, 0x3f };
1944 prologue(adp, V_ADP_FONT, ENODEV);
1945 if (page < 0 || page >= 8)
1949 outb(TSIDX, 0x03); outb(TSREG, cg[page]);
1953 #else /* VGA_NO_FONT_LOADING */
1955 #endif /* VGA_NO_FONT_LOADING */
1960 * Read DAC values. The values have expressed in 8 bits.
1965 vga_save_palette(video_adapter_t *adp, u_char *palette)
1969 prologue(adp, V_ADP_PALETTE, ENODEV);
1972 * We store 8 bit values in the palette buffer, while the standard
1973 * VGA has 6 bit DAC .
1975 outb(PALRADR, 0x00);
1976 for (i = 0; i < 256*3; ++i)
1977 palette[i] = inb(PALDATA) << 2;
1978 inb(adp->va_crtc_addr + 6); /* reset flip/flop */
1983 vga_save_palette2(video_adapter_t *adp, int base, int count,
1984 u_char *r, u_char *g, u_char *b)
1988 prologue(adp, V_ADP_PALETTE, ENODEV);
1990 outb(PALRADR, base);
1991 for (i = 0; i < count; ++i) {
1992 r[i] = inb(PALDATA) << 2;
1993 g[i] = inb(PALDATA) << 2;
1994 b[i] = inb(PALDATA) << 2;
1996 inb(adp->va_crtc_addr + 6); /* reset flip/flop */
2007 vga_load_palette(video_adapter_t *adp, u_char *palette)
2011 prologue(adp, V_ADP_PALETTE, ENODEV);
2013 outb(PIXMASK, 0xff); /* no pixelmask */
2014 outb(PALWADR, 0x00);
2015 for (i = 0; i < 256*3; ++i)
2016 outb(PALDATA, palette[i] >> 2);
2017 inb(adp->va_crtc_addr + 6); /* reset flip/flop */
2018 outb(ATC, 0x20); /* enable palette */
2023 vga_load_palette2(video_adapter_t *adp, int base, int count,
2024 u_char *r, u_char *g, u_char *b)
2028 prologue(adp, V_ADP_PALETTE, ENODEV);
2030 outb(PIXMASK, 0xff); /* no pixelmask */
2031 outb(PALWADR, base);
2032 for (i = 0; i < count; ++i) {
2033 outb(PALDATA, r[i] >> 2);
2034 outb(PALDATA, g[i] >> 2);
2035 outb(PALDATA, b[i] >> 2);
2037 inb(adp->va_crtc_addr + 6); /* reset flip/flop */
2038 outb(ATC, 0x20); /* enable palette */
2044 * Change the border color.
2049 vga_set_border(video_adapter_t *adp, int color)
2051 prologue(adp, V_ADP_BORDER, ENODEV);
2053 switch (adp->va_type) {
2056 inb(adp->va_crtc_addr + 6); /* reset flip-flop */
2057 outb(ATC, 0x31); outb(ATC, color & 0xff);
2060 outb(adp->va_crtc_addr + 5, color & 0x0f); /* color select register */
2072 * Read video register values.
2073 * NOTE: this function only reads the standard EGA/VGA registers.
2074 * any extra/extended registers of SVGA adapters are not saved.
2079 vga_save_state(video_adapter_t *adp, void *p, size_t size)
2088 /* return the required buffer size */
2089 prologue(adp, V_ADP_STATESAVE, 0);
2090 return sizeof(adp_state_t);
2092 prologue(adp, V_ADP_STATESAVE, ENODEV);
2093 if (size < sizeof(adp_state_t))
2097 ((adp_state_t *)p)->sig = V_STATE_SIG;
2098 buf = ((adp_state_t *)p)->regs;
2099 bzero(buf, V_MODE_PARAM_SIZE);
2100 crtc_addr = adp->va_crtc_addr;
2104 outb(TSIDX, 0x00); outb(TSREG, 0x01); /* stop sequencer */
2105 for (i = 0, j = 5; i < 4; i++) {
2107 buf[j++] = inb(TSREG);
2109 buf[9] = inb(MISC + 10); /* dot-clock */
2110 outb(TSIDX, 0x00); outb(TSREG, 0x03); /* start sequencer */
2112 for (i = 0, j = 10; i < 25; i++) { /* crtc */
2114 buf[j++] = inb(crtc_addr + 1);
2116 for (i = 0, j = 35; i < 20; i++) { /* attribute ctrl */
2117 inb(crtc_addr + 6); /* reset flip-flop */
2119 buf[j++] = inb(ATC + 1);
2121 for (i = 0, j = 55; i < 9; i++) { /* graph data ctrl */
2123 buf[j++] = inb(GDCREG);
2125 inb(crtc_addr + 6); /* reset flip-flop */
2126 outb(ATC, 0x20); /* enable palette */
2131 if (vga_get_info(adp, adp->va_mode, &info) == 0) {
2132 if (info.vi_flags & V_INFO_GRAPHICS) {
2133 buf[0] = info.vi_width/info.vi_cwidth; /* COLS */
2134 buf[1] = info.vi_height/info.vi_cheight - 1; /* ROWS */
2136 buf[0] = info.vi_width; /* COLS */
2137 buf[1] = info.vi_height - 1; /* ROWS */
2139 buf[2] = info.vi_cheight; /* POINTS */
2141 /* XXX: shouldn't be happening... */
2142 printf("vga%d: %s: failed to obtain mode info. (vga_save_state())\n",
2143 adp->va_unit, adp->va_name);
2146 buf[0] = readb(BIOS_PADDRTOVADDR(0x44a)); /* COLS */
2147 buf[1] = readb(BIOS_PADDRTOVADDR(0x484)); /* ROWS */
2148 buf[2] = readb(BIOS_PADDRTOVADDR(0x485)); /* POINTS */
2149 buf[3] = readb(BIOS_PADDRTOVADDR(0x44c));
2150 buf[4] = readb(BIOS_PADDRTOVADDR(0x44d));
2158 * Set video registers at once.
2159 * NOTE: this function only updates the standard EGA/VGA registers.
2160 * any extra/extended registers of SVGA adapters are not changed.
2165 vga_load_state(video_adapter_t *adp, void *p)
2172 prologue(adp, V_ADP_STATELOAD, ENODEV);
2173 if (((adp_state_t *)p)->sig != V_STATE_SIG)
2176 buf = ((adp_state_t *)p)->regs;
2177 crtc_addr = adp->va_crtc_addr;
2180 dump_buffer(buf, V_MODE_PARAM_SIZE);
2185 outb(TSIDX, 0x00); outb(TSREG, 0x01); /* stop sequencer */
2186 for (i = 0; i < 4; ++i) { /* program sequencer */
2188 outb(TSREG, buf[i + 5]);
2190 outb(MISC, buf[9]); /* set dot-clock */
2191 outb(TSIDX, 0x00); outb(TSREG, 0x03); /* start sequencer */
2192 outb(crtc_addr, 0x11);
2193 outb(crtc_addr + 1, inb(crtc_addr + 1) & 0x7F);
2194 for (i = 0; i < 25; ++i) { /* program crtc */
2196 outb(crtc_addr + 1, buf[i + 10]);
2198 inb(crtc_addr+6); /* reset flip-flop */
2199 for (i = 0; i < 20; ++i) { /* program attribute ctrl */
2201 outb(ATC, buf[i + 35]);
2203 for (i = 0; i < 9; ++i) { /* program graph data ctrl */
2205 outb(GDCREG, buf[i + 55]);
2207 inb(crtc_addr + 6); /* reset flip-flop */
2208 outb(ATC, 0x20); /* enable palette */
2210 #if notyet /* a temporary workaround for kernel panic, XXX */
2212 if (adp->va_unit == V_ADP_PRIMARY) {
2213 writeb(BIOS_PADDRTOVADDR(0x44a), buf[0]); /* COLS */
2214 writeb(BIOS_PADDRTOVADDR(0x484), buf[1] + rows_offset - 1); /* ROWS */
2215 writeb(BIOS_PADDRTOVADDR(0x485), buf[2]); /* POINTS */
2217 writeb(BIOS_PADDRTOVADDR(0x44c), buf[3]);
2218 writeb(BIOS_PADDRTOVADDR(0x44d), buf[4]);
2221 #endif /* VGA_NO_BIOS */
2230 * Change the origin (window mapping) of the banked frame buffer.
2233 vga_set_origin(video_adapter_t *adp, off_t offset)
2236 * The standard video modes do not require window mapping;
2237 * always return error.
2244 * Read the position of the hardware text cursor.
2249 vga_read_hw_cursor(video_adapter_t *adp, int *col, int *row)
2257 if (adp->va_info.vi_flags & V_INFO_GRAPHICS)
2261 outb(adp->va_crtc_addr, 14);
2262 off = inb(adp->va_crtc_addr + 1);
2263 outb(adp->va_crtc_addr, 15);
2264 off = (off << 8) | inb(adp->va_crtc_addr + 1);
2267 *row = off / adp->va_info.vi_width;
2268 *col = off % adp->va_info.vi_width;
2275 * Move the hardware text cursor. If col and row are both -1,
2276 * the cursor won't be shown.
2281 vga_set_hw_cursor(video_adapter_t *adp, int col, int row)
2289 if ((col == -1) && (row == -1)) {
2292 if (adp->va_info.vi_flags & V_INFO_GRAPHICS)
2294 off = row*adp->va_info.vi_width + col;
2298 outb(adp->va_crtc_addr, 14);
2299 outb(adp->va_crtc_addr + 1, off >> 8);
2300 outb(adp->va_crtc_addr, 15);
2301 outb(adp->va_crtc_addr + 1, off & 0x00ff);
2308 * set_hw_cursor_shape():
2309 * Change the shape of the hardware text cursor. If the height is
2310 * zero or negative, the cursor won't be shown.
2315 vga_set_hw_cursor_shape(video_adapter_t *adp, int base, int height,
2316 int celsize, int blink)
2324 switch (adp->va_type) {
2331 /* make the cursor invisible */
2332 outb(adp->va_crtc_addr, 10);
2333 outb(adp->va_crtc_addr + 1, 32);
2334 outb(adp->va_crtc_addr, 11);
2335 outb(adp->va_crtc_addr + 1, 0);
2337 outb(adp->va_crtc_addr, 10);
2338 outb(adp->va_crtc_addr + 1, celsize - base - height);
2339 outb(adp->va_crtc_addr, 11);
2340 outb(adp->va_crtc_addr + 1, celsize - base - 1);
2345 /* make the cursor invisible */
2346 outb(adp->va_crtc_addr, 10);
2347 outb(adp->va_crtc_addr + 1, celsize);
2348 outb(adp->va_crtc_addr, 11);
2349 outb(adp->va_crtc_addr + 1, 0);
2351 outb(adp->va_crtc_addr, 10);
2352 outb(adp->va_crtc_addr + 1, celsize - base - height);
2353 outb(adp->va_crtc_addr, 11);
2354 outb(adp->va_crtc_addr + 1, celsize - base);
2365 * Put the display in power save/power off mode.
2370 vga_blank_display(video_adapter_t *adp, int mode)
2376 switch (adp->va_type) {
2379 case V_DISPLAY_SUSPEND:
2380 case V_DISPLAY_STAND_BY:
2384 outb(TSREG, val | 0x20);
2385 outb(adp->va_crtc_addr, 0x17);
2386 val = inb(adp->va_crtc_addr + 1);
2387 outb(adp->va_crtc_addr + 1, val & ~0x80);
2389 case V_DISPLAY_BLANK:
2393 outb(TSREG, val | 0x20);
2399 outb(TSREG, val & 0xDF);
2400 outb(adp->va_crtc_addr, 0x17);
2401 val = inb(adp->va_crtc_addr + 1);
2402 outb(adp->va_crtc_addr + 1, val | 0x80);
2408 /* no support yet */
2414 case V_DISPLAY_SUSPEND:
2415 case V_DISPLAY_STAND_BY:
2416 case V_DISPLAY_BLANK:
2417 outb(adp->va_crtc_addr + 4, 0x25);
2420 outb(adp->va_crtc_addr + 4, 0x2d);
2428 case V_DISPLAY_SUSPEND:
2429 case V_DISPLAY_STAND_BY:
2430 case V_DISPLAY_BLANK:
2431 outb(adp->va_crtc_addr + 4, 0x21);
2434 outb(adp->va_crtc_addr + 4, 0x29);
2448 * Mmap frame buffer.
2453 vga_mmap_buf(video_adapter_t *adp, vm_offset_t offset, int prot)
2455 if (adp->va_info.vi_flags & V_INFO_LINEAR)
2459 printf("vga_mmap_buf(): window:0x%x, offset:0x%x\n",
2460 adp->va_info.vi_window, offset);
2463 /* XXX: is this correct? */
2464 if (offset > adp->va_window_size - PAGE_SIZE)
2468 return i386_btop(adp->va_info.vi_window + offset);
2471 return alpha_btop(adp->va_info.vi_window + offset);
2475 #ifndef VGA_NO_MODE_CHANGE
2478 planar_fill(video_adapter_t *adp, int val)
2481 int at; /* position in the frame buffer */
2484 outw(GDCIDX, 0x0005); /* read mode 0, write mode 0 */
2485 outw(GDCIDX, 0x0003); /* data rotate/function select */
2486 outw(GDCIDX, 0x0f01); /* set/reset enable */
2487 outw(GDCIDX, 0xff08); /* bit mask */
2488 outw(GDCIDX, (val << 8) | 0x00); /* set/reset */
2490 length = adp->va_line_width*adp->va_info.vi_height;
2491 while (length > 0) {
2492 l = imin(length, adp->va_window_size);
2493 (*vidsw[adp->va_index]->set_win_org)(adp, at);
2494 bzero_io(adp->va_window, l);
2498 outw(GDCIDX, 0x0000); /* set/reset */
2499 outw(GDCIDX, 0x0001); /* set/reset enable */
2503 packed_fill(video_adapter_t *adp, int val)
2506 int at; /* position in the frame buffer */
2510 length = adp->va_line_width*adp->va_info.vi_height;
2511 while (length > 0) {
2512 l = imin(length, adp->va_window_size);
2513 (*vidsw[adp->va_index]->set_win_org)(adp, at);
2514 fill_io(val, adp->va_window, l);
2521 direct_fill(video_adapter_t *adp, int val)
2524 int at; /* position in the frame buffer */
2528 length = adp->va_line_width*adp->va_info.vi_height;
2529 while (length > 0) {
2530 l = imin(length, adp->va_window_size);
2531 (*vidsw[adp->va_index]->set_win_org)(adp, at);
2532 switch (adp->va_info.vi_pixel_size) {
2533 case sizeof(u_int16_t):
2534 fillw_io(val, adp->va_window, l/sizeof(u_int16_t));
2539 case sizeof(u_int32_t):
2540 filll_io(val, adp->va_window, l/sizeof(u_int32_t));
2549 vga_clear(video_adapter_t *adp)
2551 switch (adp->va_info.vi_mem_model) {
2552 case V_INFO_MM_TEXT:
2553 /* do nothing? XXX */
2555 case V_INFO_MM_PLANAR:
2556 planar_fill(adp, 0);
2558 case V_INFO_MM_PACKED:
2559 packed_fill(adp, 0);
2561 case V_INFO_MM_DIRECT:
2562 direct_fill(adp, 0);
2570 planar_fill_rect(video_adapter_t *adp, int val, int x, int y, int cx, int cy)
2575 int offset; /* offset within window */
2579 outw(GDCIDX, 0x0005); /* read mode 0, write mode 0 */
2580 outw(GDCIDX, 0x0003); /* data rotate/function select */
2581 outw(GDCIDX, 0x0f01); /* set/reset enable */
2582 outw(GDCIDX, 0xff08); /* bit mask */
2583 outw(GDCIDX, (val << 8) | 0x00); /* set/reset */
2585 banksize = adp->va_window_size;
2588 pos = adp->va_line_width*y + x/8;
2589 if (bank != pos/banksize) {
2590 (*vidsw[adp->va_index]->set_win_org)(adp, pos);
2591 bank = pos/banksize;
2593 offset = pos%banksize;
2594 bx = (x + cx)/8 - x/8;
2596 outw(GDCIDX, ((0xff00 >> (x % 8)) & 0xff00) | 0x08);
2597 writeb(adp->va_window + offset, 0);
2600 if (offset >= banksize) {
2602 ++bank; /* next bank */
2603 (*vidsw[adp->va_index]->set_win_org)(adp, bank*banksize);
2605 outw(GDCIDX, 0xff08); /* bit mask */
2608 l = imin(bx, banksize);
2609 bzero_io(adp->va_window + offset, l);
2612 if (offset >= banksize) {
2614 ++bank; /* next bank */
2615 (*vidsw[adp->va_index]->set_win_org)(adp, bank*banksize);
2619 outw(GDCIDX, (~(0xff00 >> ((x + cx) % 8)) & 0xff00) | 0x08);
2620 writeb(adp->va_window + offset, 0);
2622 if (offset >= banksize) {
2624 ++bank; /* next bank */
2625 (*vidsw[adp->va_index]->set_win_org)(adp, bank*banksize);
2627 outw(GDCIDX, 0xff08); /* bit mask */
2633 outw(GDCIDX, 0xff08); /* bit mask */
2634 outw(GDCIDX, 0x0000); /* set/reset */
2635 outw(GDCIDX, 0x0001); /* set/reset enable */
2639 packed_fill_rect(video_adapter_t *adp, int val, int x, int y, int cx, int cy)
2644 int offset; /* offset within window */
2647 banksize = adp->va_window_size;
2649 cx *= adp->va_info.vi_pixel_size;
2651 pos = adp->va_line_width*y + x*adp->va_info.vi_pixel_size;
2652 if (bank != pos/banksize) {
2653 (*vidsw[adp->va_index]->set_win_org)(adp, pos);
2654 bank = pos/banksize;
2656 offset = pos%banksize;
2657 end = imin(offset + cx, banksize);
2658 fill_io(val, adp->va_window + offset,
2659 (end - offset)/adp->va_info.vi_pixel_size);
2660 /* the line may cross the window boundary */
2661 if (offset + cx > banksize) {
2662 ++bank; /* next bank */
2663 (*vidsw[adp->va_index]->set_win_org)(adp, bank*banksize);
2664 end = offset + cx - banksize;
2665 fill_io(val, adp->va_window, end/adp->va_info.vi_pixel_size);
2673 direct_fill_rect16(video_adapter_t *adp, int val, int x, int y, int cx, int cy)
2678 int offset; /* offset within window */
2682 * XXX: the function assumes that banksize is a muliple of
2683 * sizeof(u_int16_t).
2685 banksize = adp->va_window_size;
2687 cx *= sizeof(u_int16_t);
2689 pos = adp->va_line_width*y + x*sizeof(u_int16_t);
2690 if (bank != pos/banksize) {
2691 (*vidsw[adp->va_index]->set_win_org)(adp, pos);
2692 bank = pos/banksize;
2694 offset = pos%banksize;
2695 end = imin(offset + cx, banksize);
2696 fillw_io(val, adp->va_window + offset,
2697 (end - offset)/sizeof(u_int16_t));
2698 /* the line may cross the window boundary */
2699 if (offset + cx > banksize) {
2700 ++bank; /* next bank */
2701 (*vidsw[adp->va_index]->set_win_org)(adp, bank*banksize);
2702 end = offset + cx - banksize;
2703 fillw_io(val, adp->va_window, end/sizeof(u_int16_t));
2711 direct_fill_rect24(video_adapter_t *adp, int val, int x, int y, int cx, int cy)
2716 int offset; /* offset within window */
2722 b[0] = val & 0x0000ff;
2723 b[1] = (val >> 8) & 0x0000ff;
2724 b[2] = (val >> 16) & 0x0000ff;
2725 banksize = adp->va_window_size;
2729 pos = adp->va_line_width*y + x*3;
2730 if (bank != pos/banksize) {
2731 (*vidsw[adp->va_index]->set_win_org)(adp, pos);
2732 bank = pos/banksize;
2734 offset = pos%banksize;
2735 end = imin(offset + cx, banksize);
2736 for (i = 0, j = offset; j < end; i = (++i)%3, ++j) {
2737 writeb(adp->va_window + j, b[i]);
2739 /* the line may cross the window boundary */
2740 if (offset + cx >= banksize) {
2741 ++bank; /* next bank */
2742 (*vidsw[adp->va_index]->set_win_org)(adp, bank*banksize);
2744 end = offset + cx - banksize;
2745 for (; j < end; i = (++i)%3, ++j) {
2746 writeb(adp->va_window + j, b[i]);
2755 direct_fill_rect32(video_adapter_t *adp, int val, int x, int y, int cx, int cy)
2760 int offset; /* offset within window */
2764 * XXX: the function assumes that banksize is a muliple of
2765 * sizeof(u_int32_t).
2767 banksize = adp->va_window_size;
2769 cx *= sizeof(u_int32_t);
2771 pos = adp->va_line_width*y + x*sizeof(u_int32_t);
2772 if (bank != pos/banksize) {
2773 (*vidsw[adp->va_index]->set_win_org)(adp, pos);
2774 bank = pos/banksize;
2776 offset = pos%banksize;
2777 end = imin(offset + cx, banksize);
2778 filll_io(val, adp->va_window + offset,
2779 (end - offset)/sizeof(u_int32_t));
2780 /* the line may cross the window boundary */
2781 if (offset + cx > banksize) {
2782 ++bank; /* next bank */
2783 (*vidsw[adp->va_index]->set_win_org)(adp, bank*banksize);
2784 end = offset + cx - banksize;
2785 filll_io(val, adp->va_window, end/sizeof(u_int32_t));
2793 vga_fill_rect(video_adapter_t *adp, int val, int x, int y, int cx, int cy)
2795 switch (adp->va_info.vi_mem_model) {
2796 case V_INFO_MM_TEXT:
2797 /* do nothing? XXX */
2799 case V_INFO_MM_PLANAR:
2800 planar_fill_rect(adp, val, x, y, cx, cy);
2802 case V_INFO_MM_PACKED:
2803 packed_fill_rect(adp, val, x, y, cx, cy);
2805 case V_INFO_MM_DIRECT:
2806 switch (adp->va_info.vi_pixel_size) {
2807 case sizeof(u_int16_t):
2808 direct_fill_rect16(adp, val, x, y, cx, cy);
2811 direct_fill_rect24(adp, val, x, y, cx, cy);
2813 case sizeof(u_int32_t):
2814 direct_fill_rect32(adp, val, x, y, cx, cy);
2823 vga_fill_rect(video_adapter_t *adp, int val, int x, int y, int cx, int cy)
2830 vga_bitblt(video_adapter_t *adp,...)
2836 #endif /* !VGA_NO_MODE_CHANGE */
2839 get_palette(video_adapter_t *adp, int base, int count,
2840 u_char *red, u_char *green, u_char *blue, u_char *trans)
2846 if ((base < 0) || (base >= 256) || (base + count > 256))
2849 r = malloc(count*3, M_DEVBUF, M_WAITOK);
2852 if (vga_save_palette2(adp, base, count, r, g, b))
2854 copyout(r, red, count);
2855 copyout(g, green, count);
2856 copyout(b, blue, count);
2857 if (trans != NULL) {
2859 copyout(r, trans, count);
2867 set_palette(video_adapter_t *adp, int base, int count,
2868 u_char *red, u_char *green, u_char *blue, u_char *trans)
2875 if ((base < 0) || (base >= 256) || (base + count > 256))
2878 r = malloc(count*3, M_DEVBUF, M_WAITOK);
2881 copyin(red, r, count);
2882 copyin(green, g, count);
2883 copyin(blue, b, count);
2884 err = vga_load_palette2(adp, base, count, r, g, b);
2887 return (err ? ENODEV : 0);
2891 vga_dev_ioctl(video_adapter_t *adp, u_long cmd, caddr_t arg)
2894 case FBIO_GETWINORG: /* get frame buffer window origin */
2898 case FBIO_SETWINORG: /* set frame buffer window origin */
2901 case FBIO_SETDISPSTART: /* set display start address */
2902 return (set_display_start(adp,
2903 ((video_display_start_t *)arg)->x,
2904 ((video_display_start_t *)arg)->y)
2907 case FBIO_SETLINEWIDTH: /* set scan line length in pixel */
2908 return (set_line_length(adp, *(u_int *)arg) ? ENODEV : 0);
2910 case FBIO_GETPALETTE: /* get color palette */
2911 return get_palette(adp, ((video_color_palette_t *)arg)->index,
2912 ((video_color_palette_t *)arg)->count,
2913 ((video_color_palette_t *)arg)->red,
2914 ((video_color_palette_t *)arg)->green,
2915 ((video_color_palette_t *)arg)->blue,
2916 ((video_color_palette_t *)arg)->transparent);
2918 case FBIO_SETPALETTE: /* set color palette */
2919 return set_palette(adp, ((video_color_palette_t *)arg)->index,
2920 ((video_color_palette_t *)arg)->count,
2921 ((video_color_palette_t *)arg)->red,
2922 ((video_color_palette_t *)arg)->green,
2923 ((video_color_palette_t *)arg)->blue,
2924 ((video_color_palette_t *)arg)->transparent);
2926 case FBIOGTYPE: /* get frame buffer type info. */
2927 ((struct fbtype *)arg)->fb_type = fb_type(adp->va_type);
2928 ((struct fbtype *)arg)->fb_height = adp->va_info.vi_height;
2929 ((struct fbtype *)arg)->fb_width = adp->va_info.vi_width;
2930 ((struct fbtype *)arg)->fb_depth = adp->va_info.vi_depth;
2931 if ((adp->va_info.vi_depth <= 1) || (adp->va_info.vi_depth > 8))
2932 ((struct fbtype *)arg)->fb_cmsize = 0;
2934 ((struct fbtype *)arg)->fb_cmsize = 1 << adp->va_info.vi_depth;
2935 ((struct fbtype *)arg)->fb_size = adp->va_buffer_size;
2938 case FBIOGETCMAP: /* get color palette */
2939 return get_palette(adp, ((struct fbcmap *)arg)->index,
2940 ((struct fbcmap *)arg)->count,
2941 ((struct fbcmap *)arg)->red,
2942 ((struct fbcmap *)arg)->green,
2943 ((struct fbcmap *)arg)->blue, NULL);
2945 case FBIOPUTCMAP: /* set color palette */
2946 return set_palette(adp, ((struct fbcmap *)arg)->index,
2947 ((struct fbcmap *)arg)->count,
2948 ((struct fbcmap *)arg)->red,
2949 ((struct fbcmap *)arg)->green,
2950 ((struct fbcmap *)arg)->blue, NULL);
2953 return fb_commonioctl(adp, cmd, arg);
2958 dump_buffer(u_char *buf, size_t len)
2962 for(i = 0; i < len;) {
2963 printf("%02x ", buf[i]);
2964 if ((++i % 16) == 0)
2971 * Print some information about the video adapter and video modes,
2972 * with requested level of details.
2977 vga_diag(video_adapter_t *adp, int level)
2990 printf("vga: RTC equip. code:0x%02x, DCC code:0x%02x\n",
2991 rtcin(RTC_EQUIPMENT), readb(BIOS_PADDRTOVADDR(0x488)));
2992 printf("vga: CRTC:0x%x, video option:0x%02x, ",
2993 readw(BIOS_PADDRTOVADDR(0x463)),
2994 readb(BIOS_PADDRTOVADDR(0x487)));
2995 printf("rows:%d, cols:%d, font height:%d\n",
2996 readb(BIOS_PADDRTOVADDR(0x44a)),
2997 readb(BIOS_PADDRTOVADDR(0x484)) + 1,
2998 readb(BIOS_PADDRTOVADDR(0x485)));
2999 #endif /* VGA_NO_BIOS */
3000 #if !defined(VGA_NO_BIOS) && !defined(VGA_NO_MODE_CHANGE)
3001 printf("vga: param table EGA/VGA:%p", video_mode_ptr);
3002 printf(", CGA/MDA:%p\n", video_mode_ptr2);
3003 printf("vga: rows_offset:%d\n", rows_offset);
3005 #endif /* FB_DEBUG > 1 */
3007 fb_dump_adp_info(VGA_DRIVER_NAME, adp, level);
3010 if (adp->va_flags & V_ADP_MODECHANGE) {
3011 for (i = 0; bios_vmode[i].vi_mode != EOT; ++i) {
3012 if (bios_vmode[i].vi_mode == NA)
3014 if (get_mode_param(bios_vmode[i].vi_mode) == NULL)
3016 fb_dump_mode_info(VGA_DRIVER_NAME, adp, &bios_vmode[i], level);
3019 vga_get_info(adp, adp->va_initial_mode, &info); /* shouldn't fail */
3020 fb_dump_mode_info(VGA_DRIVER_NAME, adp, &info, level);
3022 #endif /* FB_DEBUG > 1 */
3024 if ((adp->va_type != KD_EGA) && (adp->va_type != KD_VGA))
3026 #if !defined(VGA_NO_BIOS) && !defined(VGA_NO_MODE_CHANGE)
3027 if (video_mode_ptr == NULL)
3028 printf("vga%d: %s: WARNING: video mode switching is not "
3029 "fully supported on this adapter\n",
3030 adp->va_unit, adp->va_name);
3035 if (adp->va_type == KD_VGA) {
3036 printf("VGA parameters upon power-up\n");
3037 dump_buffer(adpstate.regs, sizeof(adpstate.regs));
3038 printf("VGA parameters in BIOS for mode %d\n", adp->va_initial_mode);
3039 dump_buffer(adpstate2.regs, sizeof(adpstate2.regs));
3042 mp = get_mode_param(adp->va_initial_mode);
3043 if (mp == NULL) /* this shouldn't be happening */
3045 printf("EGA/VGA parameters to be used for mode %d\n", adp->va_initial_mode);
3046 dump_buffer(mp, V_MODE_PARAM_SIZE);