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.17 2006/09/05 00:55:44 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>
41 #include <sys/fcntl.h>
42 #include <sys/malloc.h>
44 #include <sys/thread2.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
102 vga_open(dev_t dev, vga_softc_t *sc, int flag, int mode, struct ucred *cred)
106 if (mode & (O_CREAT | O_APPEND | O_TRUNC))
109 return genfbopen(&sc->gensc, sc->adp, flag, mode, cred);
113 vga_close(dev_t dev, vga_softc_t *sc, int flag, int mode)
115 return genfbclose(&sc->gensc, sc->adp, flag, mode);
119 vga_read(dev_t dev, vga_softc_t *sc, struct uio *uio, int flag)
121 return genfbread(&sc->gensc, sc->adp, uio, flag);
125 vga_write(dev_t dev, vga_softc_t *sc, struct uio *uio, int flag)
127 return genfbread(&sc->gensc, sc->adp, uio, flag);
131 vga_ioctl(dev_t dev, vga_softc_t *sc, u_long cmd, caddr_t arg, int flag,
134 return genfbioctl(&sc->gensc, sc->adp, cmd, arg, flag, cred);
138 vga_mmap(dev_t dev, vga_softc_t *sc, vm_offset_t offset, int prot)
140 return genfbmmap(&sc->gensc, sc->adp, offset, prot);
143 #endif /* FB_INSTALL_CDEV */
147 #include <machine/clock.h>
148 #include <machine/pc/vesa.h>
150 #define probe_done(adp) ((adp)->va_flags & V_ADP_PROBED)
151 #define init_done(adp) ((adp)->va_flags & V_ADP_INITIALIZED)
152 #define config_done(adp) ((adp)->va_flags & V_ADP_REGISTERED)
154 /* for compatibility with old kernel options */
155 #ifdef SC_ALT_SEQACCESS
156 #undef SC_ALT_SEQACCESS
157 #undef VGA_ALT_SEQACCESS
158 #define VGA_ALT_SEQACCESS 1
163 #undef VGA_SLOW_IOACCESS
164 #define VGA_SLOW_IOACCESS 1
167 /* this should really be in `rtc.h' */
168 #define RTC_EQUIPMENT 0x14
171 #define V_MODE_MAP_SIZE (M_VGA_CG320 + 1)
172 #define V_MODE_PARAM_SIZE 64
174 /* video adapter state buffer */
177 #define V_STATE_SIG 0x736f6962
178 u_char regs[V_MODE_PARAM_SIZE];
180 typedef struct adp_state adp_state_t;
182 /* video adapter information */
186 #define DCC_EGAMONO 3
191 * NOTE: `va_window' should have a virtual address, but is initialized
192 * with a physical address in the following table, as verify_adapter()
193 * will perform address conversion at run-time.
195 static video_adapter_t adapter_init_value[] = {
197 { 0, KD_MONO, "mda", 0, 0, 0, IO_MDA, IO_MDASIZE, MONO_CRTC,
198 MDA_BUF_BASE, MDA_BUF_SIZE, MDA_BUF_BASE, MDA_BUF_SIZE, MDA_BUF_SIZE,
201 { 0, KD_CGA, "cga", 0, 0, V_ADP_COLOR, IO_CGA, IO_CGASIZE, COLOR_CRTC,
202 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE,
205 { 0, KD_CGA, "cga", 0, 0, V_ADP_COLOR, IO_CGA, IO_CGASIZE, COLOR_CRTC,
206 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE,
209 { 0, KD_EGA, "ega", 0, 0, 0, IO_MDA, 48, MONO_CRTC,
210 EGA_BUF_BASE, EGA_BUF_SIZE, MDA_BUF_BASE, MDA_BUF_SIZE, MDA_BUF_SIZE,
213 { 0, KD_EGA, "ega", 0, 0, V_ADP_COLOR, IO_MDA, 48, COLOR_CRTC,
214 EGA_BUF_BASE, EGA_BUF_SIZE, CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE,
217 { 0, KD_EGA, "ega", 0, 0, V_ADP_COLOR, IO_MDA, 48, COLOR_CRTC,
218 EGA_BUF_BASE, EGA_BUF_SIZE, CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE,
222 static video_adapter_t biosadapter[2];
223 static int biosadapters = 0;
225 /* video driver declarations */
226 static int vga_configure(int flags);
227 int (*vga_sub_configure)(int flags);
229 static int vga_nop(void);
231 static int vga_error(void);
232 static vi_probe_t vga_probe;
233 static vi_init_t vga_init;
234 static vi_get_info_t vga_get_info;
235 static vi_query_mode_t vga_query_mode;
236 static vi_set_mode_t vga_set_mode;
237 static vi_save_font_t vga_save_font;
238 static vi_load_font_t vga_load_font;
239 static vi_show_font_t vga_show_font;
240 static vi_save_palette_t vga_save_palette;
241 static vi_load_palette_t vga_load_palette;
242 static vi_set_border_t vga_set_border;
243 static vi_save_state_t vga_save_state;
244 static vi_load_state_t vga_load_state;
245 static vi_set_win_org_t vga_set_origin;
246 static vi_read_hw_cursor_t vga_read_hw_cursor;
247 static vi_set_hw_cursor_t vga_set_hw_cursor;
248 static vi_set_hw_cursor_shape_t vga_set_hw_cursor_shape;
249 static vi_blank_display_t vga_blank_display;
250 static vi_mmap_t vga_mmap_buf;
251 static vi_ioctl_t vga_dev_ioctl;
252 #ifndef VGA_NO_MODE_CHANGE
253 static vi_clear_t vga_clear;
254 static vi_fill_rect_t vga_fill_rect;
255 static vi_bitblt_t vga_bitblt;
256 #else /* VGA_NO_MODE_CHANGE */
257 #define vga_clear (vi_clear_t *)vga_error
258 #define vga_fill_rect (vi_fill_rect_t *)vga_error
259 #define vga_bitblt (vi_bitblt_t *)vga_error
261 static vi_diag_t vga_diag;
263 static video_switch_t vgavidsw = {
280 vga_set_hw_cursor_shape,
292 VIDEO_DRIVER(mda, vgavidsw, NULL);
293 VIDEO_DRIVER(cga, vgavidsw, NULL);
294 VIDEO_DRIVER(ega, vgavidsw, NULL);
295 VIDEO_DRIVER(vga, vgavidsw, vga_configure);
297 /* VGA BIOS standard video modes */
301 static video_info_t bios_vmode[] = {
303 { M_B40x25, V_INFO_COLOR, 40, 25, 8, 8, 2, 1,
304 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
305 { M_C40x25, V_INFO_COLOR, 40, 25, 8, 8, 4, 1,
306 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
307 { M_B80x25, V_INFO_COLOR, 80, 25, 8, 8, 2, 1,
308 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
309 { M_C80x25, V_INFO_COLOR, 80, 25, 8, 8, 4, 1,
310 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
312 { M_ENH_B40x25, V_INFO_COLOR, 40, 25, 8, 14, 2, 1,
313 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
314 { M_ENH_C40x25, V_INFO_COLOR, 40, 25, 8, 14, 4, 1,
315 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
316 { M_ENH_B80x25, V_INFO_COLOR, 80, 25, 8, 14, 2, 1,
317 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
318 { M_ENH_C80x25, V_INFO_COLOR, 80, 25, 8, 14, 4, 1,
319 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
321 { M_VGA_C40x25, V_INFO_COLOR, 40, 25, 8, 16, 4, 1,
322 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
323 { M_VGA_M80x25, 0, 80, 25, 8, 16, 2, 1,
324 MDA_BUF_BASE, MDA_BUF_SIZE, MDA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
325 { M_VGA_C80x25, V_INFO_COLOR, 80, 25, 8, 16, 4, 1,
326 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
328 { M_EGAMONO80x25, 0, 80, 25, 8, 14, 2, 1,
329 MDA_BUF_BASE, MDA_BUF_SIZE, MDA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
331 { M_ENH_B80x43, 0, 80, 43, 8, 8, 2, 1,
332 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
333 { M_ENH_C80x43, V_INFO_COLOR, 80, 43, 8, 8, 4, 1,
334 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
336 { M_VGA_M80x30, 0, 80, 30, 8, 16, 2, 1,
337 MDA_BUF_BASE, MDA_BUF_SIZE, MDA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
338 { M_VGA_C80x30, V_INFO_COLOR, 80, 30, 8, 16, 4, 1,
339 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
340 { M_VGA_M80x50, 0, 80, 50, 8, 8, 2, 1,
341 MDA_BUF_BASE, MDA_BUF_SIZE, MDA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
342 { M_VGA_C80x50, V_INFO_COLOR, 80, 50, 8, 8, 4, 1,
343 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
344 { M_VGA_M80x60, 0, 80, 60, 8, 8, 2, 1,
345 MDA_BUF_BASE, MDA_BUF_SIZE, MDA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
346 { M_VGA_C80x60, V_INFO_COLOR, 80, 60, 8, 8, 4, 1,
347 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
349 #ifndef VGA_NO_MODE_CHANGE
352 { M_VGA_M90x25, 0, 90, 25, 8, 16, 2, 1,
353 MDA_BUF_BASE, MDA_BUF_SIZE, MDA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
354 { M_VGA_C90x25, V_INFO_COLOR, 90, 25, 8, 16, 4, 1,
355 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
356 { M_VGA_M90x30, 0, 90, 30, 8, 16, 2, 1,
357 MDA_BUF_BASE, MDA_BUF_SIZE, MDA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
358 { M_VGA_C90x30, V_INFO_COLOR, 90, 30, 8, 16, 4, 1,
359 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
360 { M_VGA_M90x43, 0, 90, 43, 8, 8, 2, 1,
361 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
362 { M_VGA_C90x43, V_INFO_COLOR, 90, 43, 8, 8, 4, 1,
363 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
364 { M_VGA_M90x50, 0, 90, 50, 8, 8, 2, 1,
365 MDA_BUF_BASE, MDA_BUF_SIZE, MDA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
366 { M_VGA_C90x50, V_INFO_COLOR, 90, 50, 8, 8, 4, 1,
367 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
368 { M_VGA_M90x60, 0, 90, 60, 8, 8, 2, 1,
369 MDA_BUF_BASE, MDA_BUF_SIZE, MDA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
370 { M_VGA_C90x60, V_INFO_COLOR, 90, 60, 8, 8, 4, 1,
371 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
372 #endif /* VGA_WIDTH90 */
375 { M_BG320, V_INFO_COLOR | V_INFO_GRAPHICS, 320, 200, 8, 8, 2, 1,
376 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_CGA },
377 { M_CG320, 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_BG640, V_INFO_COLOR | V_INFO_GRAPHICS, 640, 200, 8, 8, 1, 1,
380 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_CGA },
382 { M_CG320_D, V_INFO_COLOR | V_INFO_GRAPHICS, 320, 200, 8, 8, 4, 4,
383 GRAPHICS_BUF_BASE, GRAPHICS_BUF_SIZE, GRAPHICS_BUF_SIZE, 0, 0,
385 { M_CG640_E, V_INFO_COLOR | V_INFO_GRAPHICS, 640, 200, 8, 8, 4, 4,
386 GRAPHICS_BUF_BASE, GRAPHICS_BUF_SIZE, GRAPHICS_BUF_SIZE, 0, 0 ,
388 { M_EGAMONOAPA, V_INFO_GRAPHICS, 640, 350, 8, 14, 4, 4,
389 GRAPHICS_BUF_BASE, GRAPHICS_BUF_SIZE, 64*1024, 0, 0 ,
391 { M_ENHMONOAPA2,V_INFO_GRAPHICS, 640, 350, 8, 14, 4, 4,
392 GRAPHICS_BUF_BASE, GRAPHICS_BUF_SIZE, GRAPHICS_BUF_SIZE, 0, 0 ,
394 { M_CG640x350, V_INFO_COLOR | V_INFO_GRAPHICS, 640, 350, 8, 14, 2, 2,
395 GRAPHICS_BUF_BASE, GRAPHICS_BUF_SIZE, GRAPHICS_BUF_SIZE, 0, 0 ,
397 { M_ENH_CG640, V_INFO_COLOR | V_INFO_GRAPHICS, 640, 350, 8, 14, 4, 4,
398 GRAPHICS_BUF_BASE, GRAPHICS_BUF_SIZE, GRAPHICS_BUF_SIZE, 0, 0 ,
401 { M_BG640x480, V_INFO_COLOR | V_INFO_GRAPHICS, 640, 480, 8, 16, 4, 4,
402 GRAPHICS_BUF_BASE, GRAPHICS_BUF_SIZE, GRAPHICS_BUF_SIZE, 0, 0 ,
404 { M_CG640x480, 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_VGA_CG320, V_INFO_COLOR | V_INFO_GRAPHICS, 320, 200, 8, 8, 8, 1,
408 GRAPHICS_BUF_BASE, GRAPHICS_BUF_SIZE, GRAPHICS_BUF_SIZE, 0, 0,
409 V_INFO_MM_PACKED, 1 },
410 { M_VGA_MODEX, V_INFO_COLOR | V_INFO_GRAPHICS, 320, 240, 8, 8, 8, 4,
411 GRAPHICS_BUF_BASE, GRAPHICS_BUF_SIZE, GRAPHICS_BUF_SIZE, 0, 0,
413 #endif /* VGA_NO_MODE_CHANGE */
418 static int vga_init_done = FALSE;
419 #if !defined(VGA_NO_BIOS) && !defined(VGA_NO_MODE_CHANGE)
420 static u_char *video_mode_ptr = NULL; /* EGA/VGA */
421 static u_char *video_mode_ptr2 = NULL; /* CGA/MDA */
423 static u_char *mode_map[V_MODE_MAP_SIZE];
424 static adp_state_t adpstate;
425 static adp_state_t adpstate2;
426 static int rows_offset = 1;
428 /* local macros and functions */
429 #define BIOS_SADDRTOLADDR(p) ((((p) & 0xffff0000) >> 12) + ((p) & 0x0000ffff))
431 #if !defined(VGA_NO_BIOS) && !defined(VGA_NO_MODE_CHANGE)
432 static void map_mode_table(u_char **, u_char *, int);
434 static void clear_mode_map(video_adapter_t *, u_char **, int, int);
435 #if !defined(VGA_NO_BIOS) && !defined(VGA_NO_MODE_CHANGE)
436 static int map_mode_num(int);
438 static int map_gen_mode_num(int, int, int);
439 static int map_bios_mode_num(int, int, int);
440 static u_char *get_mode_param(int);
442 static void fill_adapter_param(int, video_adapter_t *);
444 static int verify_adapter(video_adapter_t *);
445 static void update_adapter_info(video_adapter_t *, video_info_t *);
446 #if !defined(VGA_NO_BIOS) && !defined(VGA_NO_MODE_CHANGE)
447 #define COMP_IDENTICAL 0
448 #define COMP_SIMILAR 1
449 #define COMP_DIFFERENT 2
450 static int comp_adpregs(u_char *, u_char *);
452 static int probe_adapters(void);
453 static int set_line_length(video_adapter_t *, int);
454 static int set_display_start(video_adapter_t *, int, int);
456 #ifndef VGA_NO_MODE_CHANGE
458 static void set_width90(adp_state_t *);
460 #endif /* !VGA_NO_MODE_CHANGE */
462 #ifndef VGA_NO_FONT_LOADING
463 #define PARAM_BUFSIZE 6
464 static void set_font_mode(video_adapter_t *, u_char *);
465 static void set_normal_mode(video_adapter_t *, u_char *);
468 #ifndef VGA_NO_MODE_CHANGE
469 static void filll_io(int, vm_offset_t, size_t);
470 static void planar_fill(video_adapter_t *, int);
471 static void packed_fill(video_adapter_t *, int);
472 static void direct_fill(video_adapter_t *, int);
474 static void planar_fill_rect(video_adapter_t *, int, int, int, int, int);
475 static void packed_fill_rect(video_adapter_t *, int, int, int, int, int);
476 static void direct_fill_rect16(video_adapter_t *, int, int, int, int, int);
477 static void direct_fill_rect24(video_adapter_t *, int, int, int, int, int);
478 static void direct_fill_rect32(video_adapter_t *, int, int, int, int, int);
480 #endif /* !VGA_NO_MODE_CHANGE */
482 static void dump_buffer(u_char *, size_t);
484 #define ISMAPPED(pa, width) \
485 (((pa) <= (u_long)0x1000 - (width)) \
486 || ((pa) >= ISA_HOLE_START && (pa) <= 0x100000 - (width)))
488 #define prologue(adp, flag, err) \
489 if (!vga_init_done || !((adp)->va_flags & (flag))) \
492 /* a backdoor for the console driver */
494 vga_configure(int flags)
499 for (i = 0; i < biosadapters; ++i) {
500 if (!probe_done(&biosadapter[i]))
502 biosadapter[i].va_flags |= V_ADP_INITIALIZED;
503 if (!config_done(&biosadapter[i])) {
504 if (vid_register(&biosadapter[i]) < 0)
506 biosadapter[i].va_flags |= V_ADP_REGISTERED;
509 if (vga_sub_configure != NULL)
510 (*vga_sub_configure)(flags);
515 /* local subroutines */
517 #if !defined(VGA_NO_BIOS) && !defined(VGA_NO_MODE_CHANGE)
518 /* construct the mode parameter map */
520 map_mode_table(u_char *map[], u_char *table, int max)
524 for(i = 0; i < max; ++i)
525 map[i] = table + i*V_MODE_PARAM_SIZE;
526 for(; i < V_MODE_MAP_SIZE; ++i)
529 #endif /* !VGA_NO_BIOS && !VGA_NO_MODE_CHANGE */
532 clear_mode_map(video_adapter_t *adp, u_char *map[], int max, int color)
538 * NOTE: we don't touch `bios_vmode[]' because it is shared
541 for(i = 0; i < max; ++i) {
542 if (vga_get_info(adp, i, &info))
544 if ((info.vi_flags & V_INFO_COLOR) != color)
549 #if !defined(VGA_NO_BIOS) && !defined(VGA_NO_MODE_CHANGE)
550 /* map the non-standard video mode to a known mode number */
552 map_mode_num(int mode)
558 { M_ENH_B80x43, M_ENH_B80x25 },
559 { M_ENH_C80x43, M_ENH_C80x25 },
560 { M_VGA_M80x30, M_VGA_M80x25 },
561 { M_VGA_C80x30, M_VGA_C80x25 },
562 { M_VGA_M80x50, M_VGA_M80x25 },
563 { M_VGA_C80x50, M_VGA_C80x25 },
564 { M_VGA_M80x60, M_VGA_M80x25 },
565 { M_VGA_C80x60, M_VGA_C80x25 },
567 { M_VGA_M90x25, M_VGA_M80x25 },
568 { M_VGA_C90x25, M_VGA_C80x25 },
569 { M_VGA_M90x30, M_VGA_M80x25 },
570 { M_VGA_C90x30, M_VGA_C80x25 },
571 { M_VGA_M90x43, M_ENH_B80x25 },
572 { M_VGA_C90x43, M_ENH_C80x25 },
573 { M_VGA_M90x50, M_VGA_M80x25 },
574 { M_VGA_C90x50, M_VGA_C80x25 },
575 { M_VGA_M90x60, M_VGA_M80x25 },
576 { M_VGA_C90x60, M_VGA_C80x25 },
578 { M_VGA_MODEX, M_VGA_CG320 },
582 for (i = 0; i < sizeof(mode_map)/sizeof(mode_map[0]); ++i) {
583 if (mode_map[i].from == mode)
584 return mode_map[i].to;
588 #endif /* !VGA_NO_BIOS && !VGA_NO_MODE_CHANGE */
590 /* map a generic video mode to a known mode number */
592 map_gen_mode_num(int type, int color, int mode)
599 { M_TEXT_80x30, M_VGA_C80x30, M_VGA_M80x30, },
600 { M_TEXT_80x43, M_ENH_C80x43, M_ENH_B80x43, },
601 { M_TEXT_80x50, M_VGA_C80x50, M_VGA_M80x50, },
602 { M_TEXT_80x60, M_VGA_C80x60, M_VGA_M80x60, },
606 if (mode == M_TEXT_80x25) {
620 return M_EGAMONO80x25;
628 return M_EGAMONO80x25; /* XXX: this name is confusing */
635 for (i = 0; i < sizeof(mode_map)/sizeof(mode_map[0]); ++i) {
636 if (mode_map[i].from == mode)
637 return ((color) ? mode_map[i].to_color : mode_map[i].to_mono);
642 /* turn the BIOS video number into our video mode number */
644 map_bios_mode_num(int type, int color, int bios_mode)
646 static int cga_modes[7] = {
647 M_B40x25, M_C40x25, /* 0, 1 */
648 M_B80x25, M_C80x25, /* 2, 3 */
652 static int ega_modes[17] = {
653 M_ENH_B40x25, M_ENH_C40x25, /* 0, 1 */
654 M_ENH_B80x25, M_ENH_C80x25, /* 2, 3 */
657 M_EGAMONO80x25, /* 7 */
661 M_ENHMONOAPA2, /* XXX: video momery > 64K */
662 M_ENH_CG640, /* XXX: video momery > 64K */
664 static int vga_modes[20] = {
665 M_VGA_C40x25, M_VGA_C40x25, /* 0, 1 */
666 M_VGA_C80x25, M_VGA_C80x25, /* 2, 3 */
669 M_VGA_M80x25, /* 7 */
675 M_BG640x480, M_CG640x480,
682 if (bios_mode < sizeof(vga_modes)/sizeof(vga_modes[0]))
683 return vga_modes[bios_mode];
691 if (bios_mode < sizeof(ega_modes)/sizeof(ega_modes[0]))
692 return ega_modes[bios_mode];
696 return M_EGAMONO80x25;
700 if (bios_mode < sizeof(cga_modes)/sizeof(cga_modes[0]))
701 return cga_modes[bios_mode];
708 return M_EGAMONO80x25; /* XXX: this name is confusing */
716 /* look up a parameter table entry */
718 get_mode_param(int mode)
720 #if !defined(VGA_NO_BIOS) && !defined(VGA_NO_MODE_CHANGE)
721 if (mode >= V_MODE_MAP_SIZE)
722 mode = map_mode_num(mode);
724 if ((mode >= 0) && (mode < V_MODE_MAP_SIZE))
725 return mode_map[mode];
732 fill_adapter_param(int code, video_adapter_t *adp)
738 { DCC_MONO, DCC_EGA40 /* CGA monitor */ },
739 { DCC_MONO, DCC_EGA80 /* CGA monitor */ },
740 { DCC_MONO, DCC_EGA80 },
741 { DCC_MONO, DCC_EGA80 },
742 { DCC_CGA40, DCC_EGAMONO },
743 { DCC_CGA80, DCC_EGAMONO },
744 { DCC_EGA40 /* CGA monitor */, DCC_MONO},
745 { DCC_EGA80 /* CGA monitor */, DCC_MONO},
746 { DCC_EGA80, DCC_MONO },
747 { DCC_EGA80, DCC_MONO },
748 { DCC_EGAMONO, DCC_CGA40 },
749 { DCC_EGAMONO, DCC_CGA80 },
752 if ((code < 0) || (code >= sizeof(dcc)/sizeof(dcc[0]))) {
753 adp[V_ADP_PRIMARY] = adapter_init_value[DCC_MONO];
754 adp[V_ADP_SECONDARY] = adapter_init_value[DCC_CGA80];
756 adp[V_ADP_PRIMARY] = adapter_init_value[dcc[code].primary];
757 adp[V_ADP_SECONDARY] = adapter_init_value[dcc[code].secondary];
760 #endif /* VGA_NO_BIOS */
763 verify_adapter(video_adapter_t *adp)
767 #if !defined(VGA_NO_BIOS) && !defined(VGA_NO_MODE_CHANGE)
771 buf = BIOS_PADDRTOVADDR(adp->va_window);
774 if (readw(buf) != 0xA55A)
778 switch (adp->va_type) {
781 outb(adp->va_crtc_addr, 7);
782 if (inb(adp->va_crtc_addr) == 7) {
783 adp->va_type = KD_VGA;
784 adp->va_name = "vga";
785 adp->va_flags |= V_ADP_STATESAVE | V_ADP_PALETTE;
787 adp->va_flags |= V_ADP_STATELOAD | V_ADP_BORDER;
788 /* the color adapter may be in the 40x25 mode... XXX */
790 #if !defined(VGA_NO_BIOS) && !defined(VGA_NO_MODE_CHANGE)
791 /* get the BIOS video mode pointer */
792 p = *(u_int32_t *)BIOS_PADDRTOVADDR(0x4a8);
793 p = BIOS_SADDRTOLADDR(p);
794 if (ISMAPPED(p, sizeof(u_int32_t))) {
795 p = *(u_int32_t *)BIOS_PADDRTOVADDR(p);
796 p = BIOS_SADDRTOLADDR(p);
797 if (ISMAPPED(p, V_MODE_PARAM_SIZE))
798 video_mode_ptr = (u_char *)BIOS_PADDRTOVADDR(p);
804 adp->va_flags |= V_ADP_COLOR | V_ADP_BORDER;
805 /* may be in the 40x25 mode... XXX */
806 #if !defined(VGA_NO_BIOS) && !defined(VGA_NO_MODE_CHANGE)
807 /* get the BIOS video mode pointer */
808 p = *(u_int32_t *)BIOS_PADDRTOVADDR(0x1d*4);
809 p = BIOS_SADDRTOLADDR(p);
810 video_mode_ptr2 = (u_char *)BIOS_PADDRTOVADDR(p);
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);
828 update_adapter_info(video_adapter_t *adp, video_info_t *info)
830 adp->va_flags &= ~V_ADP_COLOR;
832 (info->vi_flags & V_INFO_COLOR) ? V_ADP_COLOR : 0;
834 (adp->va_flags & V_ADP_COLOR) ? COLOR_CRTC : MONO_CRTC;
835 adp->va_window = BIOS_PADDRTOVADDR(info->vi_window);
836 adp->va_window_size = info->vi_window_size;
837 adp->va_window_gran = info->vi_window_gran;
838 adp->va_window_orig = 0;
840 adp->va_buffer = info->vi_buffer;
841 adp->va_buffer_size = info->vi_buffer_size;
842 if (info->vi_mem_model == V_INFO_MM_VGAX) {
843 adp->va_line_width = info->vi_width/2;
844 } else if (info->vi_flags & V_INFO_GRAPHICS) {
845 switch (info->vi_depth/info->vi_planes) {
847 adp->va_line_width = info->vi_width/8;
850 adp->va_line_width = info->vi_width/4;
853 adp->va_line_width = info->vi_width/2;
856 default: /* shouldn't happen */
857 adp->va_line_width = info->vi_width;
861 adp->va_line_width = info->vi_width;
863 adp->va_disp_start.x = 0;
864 adp->va_disp_start.y = 0;
865 bcopy(info, &adp->va_info, sizeof(adp->va_info));
868 #if !defined(VGA_NO_BIOS) && !defined(VGA_NO_MODE_CHANGE)
869 /* compare two parameter table entries */
871 comp_adpregs(u_char *buf1, u_char *buf2)
875 } params[V_MODE_PARAM_SIZE] = {
876 {0xff}, {0x00}, {0xff}, /* COLS}, ROWS}, POINTS */
877 {0x00}, {0x00}, /* page length */
878 {0xfe}, {0xff}, {0xff}, {0xff}, /* sequencer registers */
879 {0xf3}, /* misc register */
880 {0xff}, {0xff}, {0xff}, {0x7f}, {0xff}, /* CRTC */
881 {0xff}, {0xff}, {0xff}, {0x7f}, {0xff},
882 {0x00}, {0x00}, {0x00}, {0x00}, {0x00},
883 {0x00}, {0xff}, {0x7f}, {0xff}, {0xff},
884 {0x7f}, {0xff}, {0xff}, {0xef}, {0xff},
885 {0xff}, {0xff}, {0xff}, {0xff}, {0xff}, /* attribute controller regs */
886 {0xff}, {0xff}, {0xff}, {0xff}, {0xff},
887 {0xff}, {0xff}, {0xff}, {0xff}, {0xff},
888 {0xff}, {0xff}, {0xff}, {0xff}, {0xf0},
889 {0xff}, {0xff}, {0xff}, {0xff}, {0xff}, /* GDC register */
890 {0xff}, {0xff}, {0xff}, {0xff},
892 int identical = TRUE;
895 if ((buf1 == NULL) || (buf2 == NULL))
896 return COMP_DIFFERENT;
898 for (i = 0; i < sizeof(params)/sizeof(params[0]); ++i) {
899 if (params[i].mask == 0) /* don't care */
901 if ((buf1[i] & params[i].mask) != (buf2[i] & params[i].mask))
902 return COMP_DIFFERENT;
903 if (buf1[i] != buf2[i])
906 return (identical) ? COMP_IDENTICAL : COMP_SIMILAR;
908 #endif /* !VGA_NO_BIOS && !VGA_NO_MODE_CHANGE */
910 /* probe video adapters and return the number of detected adapters */
914 video_adapter_t *adp;
916 #if !defined(VGA_NO_BIOS) && !defined(VGA_NO_MODE_CHANGE)
921 /* do this test only once */
924 vga_init_done = TRUE;
927 * Locate display adapters.
928 * The AT architecture supports upto two adapters. `syscons' allows
929 * the following combinations of adapters:
931 * 2) MDA + EGA/VGA color
932 * 3) CGA + EGA/VGA mono
933 * Note that `syscons' doesn't bother with MCGA as it is only
934 * avaiable for low end PS/2 models which has 80286 or earlier CPUs,
935 * thus, they are not running FreeBSD!
936 * When there are two adapaters in the system, one becomes `primary'
937 * and the other `secondary'. The EGA adapter has a set of DIP
938 * switches on board for this information and the EGA BIOS copies
939 * it in the BIOS data area BIOSDATA_VIDEOSWITCH (40:88).
940 * The VGA BIOS has more sophisticated mechanism and has this
941 * information in BIOSDATA_DCCINDEX (40:8a), but it also maintains
942 * compatibility with the EGA BIOS by updating BIOSDATA_VIDEOSWITCH.
946 * Check rtc and BIOS data area.
947 * XXX: we don't use BIOSDATA_EQUIPMENT, since it is not a dead
948 * copy of RTC_EQUIPMENT. Bits 4 and 5 of ETC_EQUIPMENT are
949 * zeros for EGA and VGA. However, the EGA/VGA BIOS sets
950 * these bits in BIOSDATA_EQUIPMENT according to the monitor
954 if (*(u_int32_t *)BIOS_PADDRTOVADDR(0x4a8)) {
955 /* EGA/VGA BIOS is present */
956 fill_adapter_param(readb(BIOS_PADDRTOVADDR(0x488)) & 0x0f,
959 switch ((rtcin(RTC_EQUIPMENT) >> 4) & 3) { /* bit 4 and 5 */
961 /* EGA/VGA: shouldn't be happening */
962 fill_adapter_param(readb(BIOS_PADDRTOVADDR(0x488)) & 0x0f,
967 /* FIXME: switch to the 80x25 mode? XXX */
968 biosadapter[V_ADP_PRIMARY] = adapter_init_value[DCC_CGA40];
969 biosadapter[V_ADP_SECONDARY] = adapter_init_value[DCC_MONO];
973 biosadapter[V_ADP_PRIMARY] = adapter_init_value[DCC_CGA80];
974 biosadapter[V_ADP_SECONDARY] = adapter_init_value[DCC_MONO];
978 biosadapter[V_ADP_PRIMARY] = adapter_init_value[DCC_MONO];
979 biosadapter[V_ADP_SECONDARY] = adapter_init_value[DCC_CGA80];
984 /* assume EGA/VGA? XXX */
985 biosadapter[V_ADP_PRIMARY] = adapter_init_value[DCC_EGA80];
986 biosadapter[V_ADP_SECONDARY] = adapter_init_value[DCC_MONO];
987 #endif /* VGA_NO_BIOS */
990 if (verify_adapter(&biosadapter[V_ADP_SECONDARY]) == 0) {
992 biosadapter[V_ADP_SECONDARY].va_flags |= V_ADP_PROBED;
993 biosadapter[V_ADP_SECONDARY].va_mode =
994 biosadapter[V_ADP_SECONDARY].va_initial_mode =
995 map_bios_mode_num(biosadapter[V_ADP_SECONDARY].va_type,
996 biosadapter[V_ADP_SECONDARY].va_flags
998 biosadapter[V_ADP_SECONDARY].va_initial_bios_mode);
1000 biosadapter[V_ADP_SECONDARY].va_type = -1;
1002 if (verify_adapter(&biosadapter[V_ADP_PRIMARY]) == 0) {
1004 biosadapter[V_ADP_PRIMARY].va_flags |= V_ADP_PROBED;
1006 biosadapter[V_ADP_PRIMARY].va_initial_bios_mode =
1007 readb(BIOS_PADDRTOVADDR(0x449));
1009 biosadapter[V_ADP_PRIMARY].va_initial_bios_mode = 3; /* XXX */
1011 biosadapter[V_ADP_PRIMARY].va_mode =
1012 biosadapter[V_ADP_PRIMARY].va_initial_mode =
1013 map_bios_mode_num(biosadapter[V_ADP_PRIMARY].va_type,
1014 biosadapter[V_ADP_PRIMARY].va_flags & V_ADP_COLOR,
1015 biosadapter[V_ADP_PRIMARY].va_initial_bios_mode);
1017 biosadapter[V_ADP_PRIMARY] = biosadapter[V_ADP_SECONDARY];
1018 biosadapter[V_ADP_SECONDARY].va_type = -1;
1020 if (biosadapters == 0)
1021 return biosadapters;
1022 biosadapter[V_ADP_PRIMARY].va_unit = V_ADP_PRIMARY;
1023 biosadapter[V_ADP_SECONDARY].va_unit = V_ADP_SECONDARY;
1025 #if 0 /* we don't need these... */
1026 fb_init_struct(&biosadapter[V_ADP_PRIMARY], ...);
1027 fb_init_struct(&biosadapter[V_ADP_SECONDARY], ...);
1032 * We cannot have two video adapter of the same type; there must be
1033 * only one of color or mono adapter, or one each of them.
1035 if (biosadapters > 1) {
1036 if (!((biosadapter[0].va_flags ^ biosadapter[1].va_flags)
1038 /* we have two mono or color adapters!! */
1039 return (biosadapters = 0);
1044 * Ensure a zero start address. This is mainly to recover after
1045 * switching from pcvt using userconfig(). The registers are w/o
1046 * for old hardware so it's too hard to relocate the active screen
1048 * This must be done before vga_save_state() for VGA.
1050 outb(biosadapter[V_ADP_PRIMARY].va_crtc_addr, 12);
1051 outb(biosadapter[V_ADP_PRIMARY].va_crtc_addr + 1, 0);
1052 outb(biosadapter[V_ADP_PRIMARY].va_crtc_addr, 13);
1053 outb(biosadapter[V_ADP_PRIMARY].va_crtc_addr + 1, 0);
1055 /* the video mode parameter table in EGA/VGA BIOS */
1056 /* NOTE: there can be only one EGA/VGA, wheather color or mono,
1057 * recognized by the video BIOS.
1059 if ((biosadapter[V_ADP_PRIMARY].va_type == KD_EGA) ||
1060 (biosadapter[V_ADP_PRIMARY].va_type == KD_VGA)) {
1061 adp = &biosadapter[V_ADP_PRIMARY];
1062 } else if ((biosadapter[V_ADP_SECONDARY].va_type == KD_EGA) ||
1063 (biosadapter[V_ADP_SECONDARY].va_type == KD_VGA)) {
1064 adp = &biosadapter[V_ADP_SECONDARY];
1068 bzero(mode_map, sizeof(mode_map));
1070 if (adp->va_type == KD_VGA) {
1071 vga_save_state(adp, &adpstate, sizeof(adpstate));
1072 for(i = 0; i < 16; i++)
1073 adp->va_palette_regs[i] = adpstate.regs[35 + i];
1074 #if defined(VGA_NO_BIOS) || defined(VGA_NO_MODE_CHANGE)
1075 mode_map[adp->va_initial_mode] = adpstate.regs;
1077 #else /* VGA_NO_BIOS || VGA_NO_MODE_CHANGE */
1078 if (video_mode_ptr == NULL) {
1079 mode_map[adp->va_initial_mode] = adpstate.regs;
1082 /* discard the table if we are not familiar with it... */
1083 map_mode_table(mode_map, video_mode_ptr, M_VGA_CG320 + 1);
1084 mp = get_mode_param(adp->va_initial_mode);
1086 bcopy(mp, adpstate2.regs, sizeof(adpstate2.regs));
1087 switch (comp_adpregs(adpstate.regs, mp)) {
1088 case COMP_IDENTICAL:
1090 * OK, this parameter table looks reasonably familiar
1094 * This is a kludge for Toshiba DynaBook SS433
1095 * whose BIOS video mode table entry has the actual #
1096 * of rows at the offset 1; BIOSes from other
1097 * manufacturers store the # of rows - 1 there. XXX
1099 rows_offset = adpstate.regs[1] + 1 - mp[1];
1104 * Not exactly the same, but similar enough to be
1105 * trusted. However, use the saved register values
1106 * for the initial mode and other modes which are
1107 * based on the initial mode.
1109 mode_map[adp->va_initial_mode] = adpstate.regs;
1110 rows_offset = adpstate.regs[1] + 1 - mp[1];
1111 adpstate.regs[1] -= rows_offset - 1;
1114 case COMP_DIFFERENT:
1117 * Don't use the paramter table in BIOS. It doesn't
1118 * look familiar to us. Video mode switching is allowed
1119 * only if the new mode is the same as or based on
1122 video_mode_ptr = NULL;
1123 bzero(mode_map, sizeof(mode_map));
1124 mode_map[adp->va_initial_mode] = adpstate.regs;
1129 #endif /* VGA_NO_BIOS || VGA_NO_MODE_CHANGE */
1131 #ifndef VGA_NO_MODE_CHANGE
1132 adp->va_flags |= V_ADP_MODECHANGE;
1134 #ifndef VGA_NO_FONT_LOADING
1135 adp->va_flags |= V_ADP_FONT;
1137 } else if (adp->va_type == KD_EGA) {
1138 #if defined(VGA_NO_BIOS) || defined(VGA_NO_MODE_CHANGE)
1140 #else /* VGA_NO_BIOS || VGA_NO_MODE_CHANGE */
1141 if (video_mode_ptr == NULL) {
1144 map_mode_table(mode_map, video_mode_ptr, M_ENH_C80x25 + 1);
1145 /* XXX how can one validate the EGA table... */
1146 mp = get_mode_param(adp->va_initial_mode);
1148 adp->va_flags |= V_ADP_MODECHANGE;
1149 #ifndef VGA_NO_FONT_LOADING
1150 adp->va_flags |= V_ADP_FONT;
1155 * This is serious. We will not be able to switch video
1158 video_mode_ptr = NULL;
1159 bzero(mode_map, sizeof(mode_map));
1163 #endif /* VGA_NO_BIOS || VGA_NO_MODE_CHANGE */
1167 /* remove conflicting modes if we have more than one adapter */
1168 if (biosadapters > 0) {
1169 for (i = 0; i < biosadapters; ++i) {
1170 if (!(biosadapter[i].va_flags & V_ADP_MODECHANGE))
1172 clear_mode_map(&biosadapter[i], mode_map, M_VGA_CG320 + 1,
1173 (biosadapter[i].va_flags & V_ADP_COLOR) ?
1175 if ((biosadapter[i].va_type == KD_VGA)
1176 || (biosadapter[i].va_type == KD_EGA)) {
1177 biosadapter[i].va_io_base =
1178 (biosadapter[i].va_flags & V_ADP_COLOR) ?
1180 biosadapter[i].va_io_size = 32;
1185 /* buffer address */
1186 vga_get_info(&biosadapter[V_ADP_PRIMARY],
1187 biosadapter[V_ADP_PRIMARY].va_initial_mode, &info);
1188 info.vi_flags &= ~V_INFO_LINEAR; /* XXX */
1189 update_adapter_info(&biosadapter[V_ADP_PRIMARY], &info);
1191 if (biosadapters > 1) {
1192 vga_get_info(&biosadapter[V_ADP_SECONDARY],
1193 biosadapter[V_ADP_SECONDARY].va_initial_mode, &info);
1194 info.vi_flags &= ~V_INFO_LINEAR; /* XXX */
1195 update_adapter_info(&biosadapter[V_ADP_SECONDARY], &info);
1199 * XXX: we should verify the following values for the primary adapter...
1200 * crtc I/O port address: *(u_int16_t *)BIOS_PADDRTOVADDR(0x463);
1201 * color/mono display: (*(u_int8_t *)BIOS_PADDRTOVADDR(0x487) & 0x02)
1202 * ? 0 : V_ADP_COLOR;
1203 * columns: *(u_int8_t *)BIOS_PADDRTOVADDR(0x44a);
1204 * rows: *(u_int8_t *)BIOS_PADDRTOVADDR(0x484);
1205 * font size: *(u_int8_t *)BIOS_PADDRTOVADDR(0x485);
1206 * buffer size: *(u_int16_t *)BIOS_PADDRTOVADDR(0x44c);
1209 return biosadapters;
1212 /* set the scan line length in pixel */
1214 set_line_length(video_adapter_t *adp, int pixel)
1217 int ppw; /* pixels per word */
1218 int bpl; /* bytes per line */
1221 if ((adp->va_type != KD_VGA) && (adp->va_type != KD_EGA))
1223 mp = get_mode_param(adp->va_mode);
1227 switch (adp->va_info.vi_mem_model) {
1228 case V_INFO_MM_PLANAR:
1229 ppw = 16/(adp->va_info.vi_depth/adp->va_info.vi_planes);
1230 count = (pixel + ppw - 1)/ppw/2;
1231 bpl = ((pixel + ppw - 1)/ppw/2)*4;
1233 case V_INFO_MM_PACKED:
1234 count = (pixel + 7)/8;
1235 bpl = ((pixel + 7)/8)*8;
1237 case V_INFO_MM_TEXT:
1238 count = (pixel + 7)/8; /* columns */
1239 bpl = (pixel + 7)/8; /* columns */
1245 if (mp[10 + 0x17] & 0x40) /* CRTC mode control reg */
1246 count *= 2; /* byte mode */
1247 outb(adp->va_crtc_addr, 0x13);
1248 outb(adp->va_crtc_addr + 1, count);
1249 adp->va_line_width = bpl;
1255 set_display_start(video_adapter_t *adp, int x, int y)
1257 int off; /* byte offset (graphics mode)/word offset (text mode) */
1258 int poff; /* pixel offset */
1259 int roff; /* row offset */
1260 int ppb; /* pixels per byte */
1262 if ((adp->va_type != KD_VGA) && (adp->va_type != KD_EGA))
1264 if (adp->va_info.vi_flags & V_INFO_GRAPHICS) {
1265 ppb = 8/(adp->va_info.vi_depth/adp->va_info.vi_planes);
1266 off = y*adp->va_line_width + x/ppb;
1270 if ((adp->va_type == KD_VGA) || (adp->va_type == KD_EGA)) {
1279 off = y/adp->va_info.vi_cheight*adp->va_line_width + x/ppb;
1280 roff = y%adp->va_info.vi_cheight;
1281 /* FIXME: is this correct? XXX */
1289 outb(adp->va_crtc_addr, 0xc); /* high */
1290 outb(adp->va_crtc_addr + 1, off >> 8);
1291 outb(adp->va_crtc_addr, 0xd); /* low */
1292 outb(adp->va_crtc_addr + 1, off & 0xff);
1294 /* horizontal pel pan */
1295 if ((adp->va_type == KD_VGA) || (adp->va_type == KD_EGA)) {
1296 inb(adp->va_crtc_addr + 6);
1297 outb(ATC, 0x13 | 0x20);
1299 inb(adp->va_crtc_addr + 6);
1303 /* preset raw scan */
1304 outb(adp->va_crtc_addr, 8);
1305 outb(adp->va_crtc_addr + 1, roff);
1307 adp->va_disp_start.x = x;
1308 adp->va_disp_start.y = y;
1312 #ifndef VGA_NO_MODE_CHANGE
1313 #ifdef __i386__ /* XXX */
1315 fill(int val, void *d, size_t size)
1322 #endif /* __i386__ */
1325 filll_io(int val, vm_offset_t d, size_t size)
1327 while (size-- > 0) {
1329 d += sizeof(u_int32_t);
1332 #endif /* !VGA_NO_MODE_CHANGE */
1351 vga_probe(int unit, video_adapter_t **adpp, void *arg, int flags)
1354 if (unit >= biosadapters)
1357 *adpp = &biosadapter[unit];
1363 vga_init(int unit, video_adapter_t *adp, int flags)
1365 if ((unit >= biosadapters) || (adp == NULL) || !probe_done(adp))
1368 if (!init_done(adp)) {
1369 /* nothing to do really... */
1370 adp->va_flags |= V_ADP_INITIALIZED;
1373 if (!config_done(adp)) {
1374 if (vid_register(adp) < 0)
1376 adp->va_flags |= V_ADP_REGISTERED;
1378 if (vga_sub_configure != NULL)
1379 (*vga_sub_configure)(0);
1386 * Return the video_info structure of the requested video mode.
1391 vga_get_info(video_adapter_t *adp, int mode, video_info_t *info)
1398 mode = map_gen_mode_num(adp->va_type, adp->va_flags & V_ADP_COLOR, mode);
1399 #ifndef VGA_NO_MODE_CHANGE
1400 if (adp->va_flags & V_ADP_MODECHANGE) {
1402 * If the parameter table entry for this mode is not found,
1403 * the mode is not supported...
1405 if (get_mode_param(mode) == NULL)
1408 #endif /* VGA_NO_MODE_CHANGE */
1411 * Even if we don't support video mode switching on this adapter,
1412 * the information on the initial (thus current) video mode
1413 * should be made available.
1415 if (mode != adp->va_initial_mode)
1419 for (i = 0; bios_vmode[i].vi_mode != EOT; ++i) {
1420 if (bios_vmode[i].vi_mode == NA)
1422 if (mode == bios_vmode[i].vi_mode) {
1423 *info = bios_vmode[i];
1425 info->vi_buffer_size = info->vi_window_size*info->vi_planes;
1434 * Find a video mode matching the requested parameters.
1435 * Fields filled with 0 are considered "don't care" fields and
1441 vga_query_mode(video_adapter_t *adp, video_info_t *info)
1448 for (i = 0; bios_vmode[i].vi_mode != EOT; ++i) {
1449 if (bios_vmode[i].vi_mode == NA)
1452 if ((info->vi_width != 0)
1453 && (info->vi_width != bios_vmode[i].vi_width))
1455 if ((info->vi_height != 0)
1456 && (info->vi_height != bios_vmode[i].vi_height))
1458 if ((info->vi_cwidth != 0)
1459 && (info->vi_cwidth != bios_vmode[i].vi_cwidth))
1461 if ((info->vi_cheight != 0)
1462 && (info->vi_cheight != bios_vmode[i].vi_cheight))
1464 if ((info->vi_depth != 0)
1465 && (info->vi_depth != bios_vmode[i].vi_depth))
1467 if ((info->vi_planes != 0)
1468 && (info->vi_planes != bios_vmode[i].vi_planes))
1470 /* XXX: should check pixel format, memory model */
1471 if ((info->vi_flags != 0)
1472 && (info->vi_flags != bios_vmode[i].vi_flags))
1475 /* verify if this mode is supported on this adapter */
1476 if (vga_get_info(adp, bios_vmode[i].vi_mode, info))
1485 * Change the video mode.
1490 #ifndef VGA_NO_MODE_CHANGE
1493 set_width90(adp_state_t *params)
1496 * Based on code submitted by Kelly Yancey (kbyanc@freedomnet.com)
1497 * and alexv@sui.gda.itesm.mx.
1499 params->regs[5] |= 1; /* toggle 8 pixel wide fonts */
1500 params->regs[10+0x0] = 0x6b;
1501 params->regs[10+0x1] = 0x59;
1502 params->regs[10+0x2] = 0x5a;
1503 params->regs[10+0x3] = 0x8e;
1504 params->regs[10+0x4] = 0x5e;
1505 params->regs[10+0x5] = 0x8a;
1506 params->regs[10+0x13] = 45;
1507 params->regs[35+0x13] = 0;
1509 #endif /* VGA_WIDTH90 */
1510 #endif /* !VGA_NO_MODE_CHANGE */
1513 vga_set_mode(video_adapter_t *adp, int mode)
1515 #ifndef VGA_NO_MODE_CHANGE
1519 prologue(adp, V_ADP_MODECHANGE, ENODEV);
1521 mode = map_gen_mode_num(adp->va_type,
1522 adp->va_flags & V_ADP_COLOR, mode);
1523 if (vga_get_info(adp, mode, &info))
1527 printf("vga_set_mode(): setting mode %d\n", mode);
1530 params.sig = V_STATE_SIG;
1531 bcopy(get_mode_param(mode), params.regs, sizeof(params.regs));
1535 case M_VGA_C90x60: case M_VGA_M90x60:
1536 set_width90(¶ms);
1539 case M_VGA_C80x60: case M_VGA_M80x60:
1540 params.regs[2] = 0x08;
1541 params.regs[19] = 0x47;
1545 case M_VGA_C90x30: case M_VGA_M90x30:
1546 set_width90(¶ms);
1549 case M_VGA_C80x30: case M_VGA_M80x30:
1550 params.regs[19] = 0x4f;
1552 params.regs[9] |= 0xc0;
1553 params.regs[16] = 0x08;
1554 params.regs[17] = 0x3e;
1555 params.regs[26] = 0xea;
1556 params.regs[28] = 0xdf;
1557 params.regs[31] = 0xe7;
1558 params.regs[32] = 0x04;
1562 case M_VGA_C90x43: case M_VGA_M90x43:
1563 set_width90(¶ms);
1566 case M_ENH_C80x43: case M_ENH_B80x43:
1567 params.regs[28] = 87;
1571 case M_VGA_C90x50: case M_VGA_M90x50:
1572 set_width90(¶ms);
1575 case M_VGA_C80x50: case M_VGA_M80x50:
1578 params.regs[19] = 7;
1582 case M_VGA_C90x25: case M_VGA_M90x25:
1583 set_width90(¶ms);
1586 case M_VGA_C40x25: case M_VGA_C80x25:
1588 case M_B40x25: case M_C40x25:
1589 case M_B80x25: case M_C80x25:
1590 case M_ENH_B40x25: case M_ENH_C40x25:
1591 case M_ENH_B80x25: case M_ENH_C80x25:
1592 case M_EGAMONO80x25:
1595 vga_load_state(adp, ¶ms);
1599 /* "unchain" the VGA mode */
1600 params.regs[5-1+0x04] &= 0xf7;
1601 params.regs[5-1+0x04] |= 0x04;
1602 /* turn off doubleword mode */
1603 params.regs[10+0x14] &= 0xbf;
1604 /* turn off word addressing */
1605 params.regs[10+0x17] |= 0x40;
1606 /* set logical screen width */
1607 params.regs[10+0x13] = 80;
1609 params.regs[10+0x11] = 0x2c;
1610 params.regs[10+0x06] = 0x0d;
1611 params.regs[10+0x07] = 0x3e;
1612 params.regs[10+0x10] = 0xea;
1613 params.regs[10+0x11] = 0xac;
1614 params.regs[10+0x12] = 0xdf;
1615 params.regs[10+0x15] = 0xe7;
1616 params.regs[10+0x16] = 0x06;
1617 /* set vertical sync polarity to reflect aspect ratio */
1618 params.regs[9] = 0xe3;
1621 case M_BG320: case M_CG320: case M_BG640:
1622 case M_CG320_D: case M_CG640_E:
1623 case M_CG640x350: case M_ENH_CG640:
1624 case M_BG640x480: case M_CG640x480: case M_VGA_CG320:
1627 vga_load_state(adp, ¶ms);
1634 adp->va_mode = mode;
1635 info.vi_flags &= ~V_INFO_LINEAR; /* XXX */
1636 update_adapter_info(adp, &info);
1638 /* move hardware cursor out of the way */
1639 (*vidsw[adp->va_index]->set_hw_cursor)(adp, -1, -1);
1642 #else /* VGA_NO_MODE_CHANGE */
1644 #endif /* VGA_NO_MODE_CHANGE */
1647 #ifndef VGA_NO_FONT_LOADING
1650 set_font_mode(video_adapter_t *adp, u_char *buf)
1656 /* save register values */
1657 if (adp->va_type == KD_VGA) {
1658 outb(TSIDX, 0x02); buf[0] = inb(TSREG);
1659 outb(TSIDX, 0x04); buf[1] = inb(TSREG);
1660 outb(GDCIDX, 0x04); buf[2] = inb(GDCREG);
1661 outb(GDCIDX, 0x05); buf[3] = inb(GDCREG);
1662 outb(GDCIDX, 0x06); buf[4] = inb(GDCREG);
1663 inb(adp->va_crtc_addr + 6);
1664 outb(ATC, 0x10); buf[5] = inb(ATC + 1);
1665 } else /* if (adp->va_type == KD_EGA) */ {
1667 * EGA cannot be read; copy parameters from the mode parameter
1670 mp = get_mode_param(adp->va_mode);
1671 buf[0] = mp[5 + 0x02 - 1];
1672 buf[1] = mp[5 + 0x04 - 1];
1673 buf[2] = mp[55 + 0x04];
1674 buf[3] = mp[55 + 0x05];
1675 buf[4] = mp[55 + 0x06];
1676 buf[5] = mp[35 + 0x10];
1679 /* setup vga for loading fonts */
1680 inb(adp->va_crtc_addr + 6); /* reset flip-flop */
1681 outb(ATC, 0x10); outb(ATC, buf[5] & ~0x01);
1682 inb(adp->va_crtc_addr + 6); /* reset flip-flop */
1683 outb(ATC, 0x20); /* enable palette */
1685 #if VGA_SLOW_IOACCESS
1686 #ifdef VGA_ALT_SEQACCESS
1687 outb(TSIDX, 0x00); outb(TSREG, 0x01);
1689 outb(TSIDX, 0x02); outb(TSREG, 0x04);
1690 outb(TSIDX, 0x04); outb(TSREG, 0x07);
1691 #ifdef VGA_ALT_SEQACCESS
1692 outb(TSIDX, 0x00); outb(TSREG, 0x03);
1694 outb(GDCIDX, 0x04); outb(GDCREG, 0x02);
1695 outb(GDCIDX, 0x05); outb(GDCREG, 0x00);
1696 outb(GDCIDX, 0x06); outb(GDCREG, 0x04);
1697 #else /* VGA_SLOW_IOACCESS */
1698 #ifdef VGA_ALT_SEQACCESS
1699 outw(TSIDX, 0x0100);
1701 outw(TSIDX, 0x0402);
1702 outw(TSIDX, 0x0704);
1703 #ifdef VGA_ALT_SEQACCESS
1704 outw(TSIDX, 0x0300);
1706 outw(GDCIDX, 0x0204);
1707 outw(GDCIDX, 0x0005);
1708 outw(GDCIDX, 0x0406); /* addr = a0000, 64kb */
1709 #endif /* VGA_SLOW_IOACCESS */
1715 set_normal_mode(video_adapter_t *adp, u_char *buf)
1719 /* setup vga for normal operation mode again */
1720 inb(adp->va_crtc_addr + 6); /* reset flip-flop */
1721 outb(ATC, 0x10); outb(ATC, buf[5]);
1722 inb(adp->va_crtc_addr + 6); /* reset flip-flop */
1723 outb(ATC, 0x20); /* enable palette */
1725 #if VGA_SLOW_IOACCESS
1726 #ifdef VGA_ALT_SEQACCESS
1727 outb(TSIDX, 0x00); outb(TSREG, 0x01);
1729 outb(TSIDX, 0x02); outb(TSREG, buf[0]);
1730 outb(TSIDX, 0x04); outb(TSREG, buf[1]);
1731 #ifdef VGA_ALT_SEQACCESS
1732 outb(TSIDX, 0x00); outb(TSREG, 0x03);
1734 outb(GDCIDX, 0x04); outb(GDCREG, buf[2]);
1735 outb(GDCIDX, 0x05); outb(GDCREG, buf[3]);
1736 if (adp->va_crtc_addr == MONO_CRTC) {
1737 outb(GDCIDX, 0x06); outb(GDCREG,(buf[4] & 0x03) | 0x08);
1739 outb(GDCIDX, 0x06); outb(GDCREG,(buf[4] & 0x03) | 0x0c);
1741 #else /* VGA_SLOW_IOACCESS */
1742 #ifdef VGA_ALT_SEQACCESS
1743 outw(TSIDX, 0x0100);
1745 outw(TSIDX, 0x0002 | (buf[0] << 8));
1746 outw(TSIDX, 0x0004 | (buf[1] << 8));
1747 #ifdef VGA_ALT_SEQACCESS
1748 outw(TSIDX, 0x0300);
1750 outw(GDCIDX, 0x0004 | (buf[2] << 8));
1751 outw(GDCIDX, 0x0005 | (buf[3] << 8));
1752 if (adp->va_crtc_addr == MONO_CRTC)
1753 outw(GDCIDX, 0x0006 | (((buf[4] & 0x03) | 0x08)<<8));
1755 outw(GDCIDX, 0x0006 | (((buf[4] & 0x03) | 0x0c)<<8));
1756 #endif /* VGA_SLOW_IOACCESS */
1761 #endif /* VGA_NO_FONT_LOADING */
1765 * Read the font data in the requested font page from the video adapter.
1770 vga_save_font(video_adapter_t *adp, int page, int fontsize, u_char *data,
1773 #ifndef VGA_NO_FONT_LOADING
1774 u_char buf[PARAM_BUFSIZE];
1777 #ifdef VGA_ALT_SEQACCESS
1781 prologue(adp, V_ADP_FONT, ENODEV);
1783 if (fontsize < 14) {
1786 } else if (fontsize >= 32) {
1788 } else if (fontsize >= 16) {
1796 if (page < 0 || page >= 8)
1798 segment = FONT_BUF + 0x4000*page;
1802 #ifdef VGA_ALT_SEQACCESS
1803 if (adp->va_type == KD_VGA) { /* what about EGA? XXX */
1805 outb(TSIDX, 0x00); outb(TSREG, 0x01);
1806 outb(TSIDX, 0x01); val = inb(TSREG); /* disable screen */
1807 outb(TSIDX, 0x01); outb(TSREG, val | 0x20);
1808 outb(TSIDX, 0x00); outb(TSREG, 0x03);
1813 set_font_mode(adp, buf);
1814 if (fontsize == 32) {
1815 bcopy_fromio(segment + ch*32, data, fontsize*count);
1817 for (c = ch; count > 0; ++c, --count) {
1818 bcopy_fromio(segment + c*32, data, fontsize);
1822 set_normal_mode(adp, buf);
1824 #ifdef VGA_ALT_SEQACCESS
1825 if (adp->va_type == KD_VGA) {
1827 outb(TSIDX, 0x00); outb(TSREG, 0x01);
1828 outb(TSIDX, 0x01); outb(TSREG, val & 0xdf); /* enable screen */
1829 outb(TSIDX, 0x00); outb(TSREG, 0x03);
1835 #else /* VGA_NO_FONT_LOADING */
1837 #endif /* VGA_NO_FONT_LOADING */
1842 * Set the font data in the requested font page.
1843 * NOTE: it appears that some recent video adapters do not support
1844 * the font page other than 0... XXX
1849 vga_load_font(video_adapter_t *adp, int page, int fontsize, u_char *data,
1852 #ifndef VGA_NO_FONT_LOADING
1853 u_char buf[PARAM_BUFSIZE];
1856 #ifdef VGA_ALT_SEQACCESS
1860 prologue(adp, V_ADP_FONT, ENODEV);
1862 if (fontsize < 14) {
1865 } else if (fontsize >= 32) {
1867 } else if (fontsize >= 16) {
1875 if (page < 0 || page >= 8)
1877 segment = FONT_BUF + 0x4000*page;
1881 #ifdef VGA_ALT_SEQACCESS
1882 if (adp->va_type == KD_VGA) { /* what about EGA? XXX */
1884 outb(TSIDX, 0x00); outb(TSREG, 0x01);
1885 outb(TSIDX, 0x01); val = inb(TSREG); /* disable screen */
1886 outb(TSIDX, 0x01); outb(TSREG, val | 0x20);
1887 outb(TSIDX, 0x00); outb(TSREG, 0x03);
1892 set_font_mode(adp, buf);
1893 if (fontsize == 32) {
1894 bcopy_toio(data, segment + ch*32, fontsize*count);
1896 for (c = ch; count > 0; ++c, --count) {
1897 bcopy_toio(data, segment + c*32, fontsize);
1901 set_normal_mode(adp, buf);
1903 #ifdef VGA_ALT_SEQACCESS
1904 if (adp->va_type == KD_VGA) {
1906 outb(TSIDX, 0x00); outb(TSREG, 0x01);
1907 outb(TSIDX, 0x01); outb(TSREG, val & 0xdf); /* enable screen */
1908 outb(TSIDX, 0x00); outb(TSREG, 0x03);
1914 #else /* VGA_NO_FONT_LOADING */
1916 #endif /* VGA_NO_FONT_LOADING */
1921 * Activate the requested font page.
1922 * NOTE: it appears that some recent video adapters do not support
1923 * the font page other than 0... XXX
1928 vga_show_font(video_adapter_t *adp, int page)
1930 #ifndef VGA_NO_FONT_LOADING
1931 static u_char cg[] = { 0x00, 0x05, 0x0a, 0x0f, 0x30, 0x35, 0x3a, 0x3f };
1933 prologue(adp, V_ADP_FONT, ENODEV);
1934 if (page < 0 || page >= 8)
1938 outb(TSIDX, 0x03); outb(TSREG, cg[page]);
1942 #else /* VGA_NO_FONT_LOADING */
1944 #endif /* VGA_NO_FONT_LOADING */
1949 * Read DAC values. The values have expressed in 8 bits.
1954 vga_save_palette(video_adapter_t *adp, u_char *palette)
1958 prologue(adp, V_ADP_PALETTE, ENODEV);
1961 * We store 8 bit values in the palette buffer, while the standard
1962 * VGA has 6 bit DAC .
1964 outb(PALRADR, 0x00);
1965 for (i = 0; i < 256*3; ++i)
1966 palette[i] = inb(PALDATA) << 2;
1967 inb(adp->va_crtc_addr + 6); /* reset flip/flop */
1972 vga_save_palette2(video_adapter_t *adp, int base, int count,
1973 u_char *r, u_char *g, u_char *b)
1977 prologue(adp, V_ADP_PALETTE, ENODEV);
1979 outb(PALRADR, base);
1980 for (i = 0; i < count; ++i) {
1981 r[i] = inb(PALDATA) << 2;
1982 g[i] = inb(PALDATA) << 2;
1983 b[i] = inb(PALDATA) << 2;
1985 inb(adp->va_crtc_addr + 6); /* reset flip/flop */
1996 vga_load_palette(video_adapter_t *adp, const u_char *palette)
2000 prologue(adp, V_ADP_PALETTE, ENODEV);
2002 outb(PIXMASK, 0xff); /* no pixelmask */
2003 outb(PALWADR, 0x00);
2004 for (i = 0; i < 256*3; ++i)
2005 outb(PALDATA, palette[i] >> 2);
2006 inb(adp->va_crtc_addr + 6); /* reset flip/flop */
2007 outb(ATC, 0x20); /* enable palette */
2012 vga_load_palette2(video_adapter_t *adp, int base, int count,
2013 u_char *r, u_char *g, u_char *b)
2017 prologue(adp, V_ADP_PALETTE, ENODEV);
2019 outb(PIXMASK, 0xff); /* no pixelmask */
2020 outb(PALWADR, base);
2021 for (i = 0; i < count; ++i) {
2022 outb(PALDATA, r[i] >> 2);
2023 outb(PALDATA, g[i] >> 2);
2024 outb(PALDATA, b[i] >> 2);
2026 inb(adp->va_crtc_addr + 6); /* reset flip/flop */
2027 outb(ATC, 0x20); /* enable palette */
2033 * Change the border color.
2038 vga_set_border(video_adapter_t *adp, int color)
2040 prologue(adp, V_ADP_BORDER, ENODEV);
2042 switch (adp->va_type) {
2045 inb(adp->va_crtc_addr + 6); /* reset flip-flop */
2046 outb(ATC, 0x31); outb(ATC, color & 0xff);
2049 outb(adp->va_crtc_addr + 5, color & 0x0f); /* color select register */
2061 * Read video register values.
2062 * NOTE: this function only reads the standard EGA/VGA registers.
2063 * any extra/extended registers of SVGA adapters are not saved.
2068 vga_save_state(video_adapter_t *adp, void *p, size_t size)
2076 /* return the required buffer size */
2077 prologue(adp, V_ADP_STATESAVE, 0);
2078 return sizeof(adp_state_t);
2080 prologue(adp, V_ADP_STATESAVE, ENODEV);
2081 if (size < sizeof(adp_state_t))
2085 ((adp_state_t *)p)->sig = V_STATE_SIG;
2086 buf = ((adp_state_t *)p)->regs;
2087 bzero(buf, V_MODE_PARAM_SIZE);
2088 crtc_addr = adp->va_crtc_addr;
2092 outb(TSIDX, 0x00); outb(TSREG, 0x01); /* stop sequencer */
2093 for (i = 0, j = 5; i < 4; i++) {
2095 buf[j++] = inb(TSREG);
2097 buf[9] = inb(MISC + 10); /* dot-clock */
2098 outb(TSIDX, 0x00); outb(TSREG, 0x03); /* start sequencer */
2100 for (i = 0, j = 10; i < 25; i++) { /* crtc */
2102 buf[j++] = inb(crtc_addr + 1);
2104 for (i = 0, j = 35; i < 20; i++) { /* attribute ctrl */
2105 inb(crtc_addr + 6); /* reset flip-flop */
2107 buf[j++] = inb(ATC + 1);
2109 for (i = 0, j = 55; i < 9; i++) { /* graph data ctrl */
2111 buf[j++] = inb(GDCREG);
2113 inb(crtc_addr + 6); /* reset flip-flop */
2114 outb(ATC, 0x20); /* enable palette */
2119 if (vga_get_info(adp, adp->va_mode, &info) == 0) {
2120 if (info.vi_flags & V_INFO_GRAPHICS) {
2121 buf[0] = info.vi_width/info.vi_cwidth; /* COLS */
2122 buf[1] = info.vi_height/info.vi_cheight - 1; /* ROWS */
2124 buf[0] = info.vi_width; /* COLS */
2125 buf[1] = info.vi_height - 1; /* ROWS */
2127 buf[2] = info.vi_cheight; /* POINTS */
2129 /* XXX: shouldn't be happening... */
2130 printf("vga%d: %s: failed to obtain mode info. (vga_save_state())\n",
2131 adp->va_unit, adp->va_name);
2134 buf[0] = readb(BIOS_PADDRTOVADDR(0x44a)); /* COLS */
2135 buf[1] = readb(BIOS_PADDRTOVADDR(0x484)); /* ROWS */
2136 buf[2] = readb(BIOS_PADDRTOVADDR(0x485)); /* POINTS */
2137 buf[3] = readb(BIOS_PADDRTOVADDR(0x44c));
2138 buf[4] = readb(BIOS_PADDRTOVADDR(0x44d));
2146 * Set video registers at once.
2147 * NOTE: this function only updates the standard EGA/VGA registers.
2148 * any extra/extended registers of SVGA adapters are not changed.
2153 vga_load_state(video_adapter_t *adp, void *p)
2159 prologue(adp, V_ADP_STATELOAD, ENODEV);
2160 if (((adp_state_t *)p)->sig != V_STATE_SIG)
2163 buf = ((adp_state_t *)p)->regs;
2164 crtc_addr = adp->va_crtc_addr;
2167 dump_buffer(buf, V_MODE_PARAM_SIZE);
2172 outb(TSIDX, 0x00); outb(TSREG, 0x01); /* stop sequencer */
2173 for (i = 0; i < 4; ++i) { /* program sequencer */
2175 outb(TSREG, buf[i + 5]);
2177 outb(MISC, buf[9]); /* set dot-clock */
2178 outb(TSIDX, 0x00); outb(TSREG, 0x03); /* start sequencer */
2179 outb(crtc_addr, 0x11);
2180 outb(crtc_addr + 1, inb(crtc_addr + 1) & 0x7F);
2181 for (i = 0; i < 25; ++i) { /* program crtc */
2183 outb(crtc_addr + 1, buf[i + 10]);
2185 inb(crtc_addr+6); /* reset flip-flop */
2186 for (i = 0; i < 20; ++i) { /* program attribute ctrl */
2188 outb(ATC, buf[i + 35]);
2190 for (i = 0; i < 9; ++i) { /* program graph data ctrl */
2192 outb(GDCREG, buf[i + 55]);
2194 inb(crtc_addr + 6); /* reset flip-flop */
2195 outb(ATC, 0x20); /* enable palette */
2197 #if notyet /* a temporary workaround for kernel panic, XXX */
2199 if (adp->va_unit == V_ADP_PRIMARY) {
2200 writeb(BIOS_PADDRTOVADDR(0x44a), buf[0]); /* COLS */
2201 writeb(BIOS_PADDRTOVADDR(0x484), buf[1] + rows_offset - 1); /* ROWS */
2202 writeb(BIOS_PADDRTOVADDR(0x485), buf[2]); /* POINTS */
2204 writeb(BIOS_PADDRTOVADDR(0x44c), buf[3]);
2205 writeb(BIOS_PADDRTOVADDR(0x44d), buf[4]);
2208 #endif /* VGA_NO_BIOS */
2217 * Change the origin (window mapping) of the banked frame buffer.
2220 vga_set_origin(video_adapter_t *adp, off_t offset)
2223 * The standard video modes do not require window mapping;
2224 * always return error.
2231 * Read the position of the hardware text cursor.
2236 vga_read_hw_cursor(video_adapter_t *adp, int *col, int *row)
2243 if (adp->va_info.vi_flags & V_INFO_GRAPHICS)
2247 outb(adp->va_crtc_addr, 14);
2248 off = inb(adp->va_crtc_addr + 1);
2249 outb(adp->va_crtc_addr, 15);
2250 off = (off << 8) | inb(adp->va_crtc_addr + 1);
2253 *row = off / adp->va_info.vi_width;
2254 *col = off % adp->va_info.vi_width;
2261 * Move the hardware text cursor. If col and row are both -1,
2262 * the cursor won't be shown.
2267 vga_set_hw_cursor(video_adapter_t *adp, int col, int row)
2274 if ((col == -1) && (row == -1)) {
2277 if (adp->va_info.vi_flags & V_INFO_GRAPHICS)
2279 off = row*adp->va_info.vi_width + col;
2283 outb(adp->va_crtc_addr, 14);
2284 outb(adp->va_crtc_addr + 1, off >> 8);
2285 outb(adp->va_crtc_addr, 15);
2286 outb(adp->va_crtc_addr + 1, off & 0x00ff);
2293 * set_hw_cursor_shape():
2294 * Change the shape of the hardware text cursor. If the height is
2295 * zero or negative, the cursor won't be shown.
2300 vga_set_hw_cursor_shape(video_adapter_t *adp, int base, int height,
2301 int celsize, int blink)
2307 switch (adp->va_type) {
2314 /* make the cursor invisible */
2315 outb(adp->va_crtc_addr, 10);
2316 outb(adp->va_crtc_addr + 1, 32);
2317 outb(adp->va_crtc_addr, 11);
2318 outb(adp->va_crtc_addr + 1, 0);
2320 outb(adp->va_crtc_addr, 10);
2321 outb(adp->va_crtc_addr + 1, celsize - base - height);
2322 outb(adp->va_crtc_addr, 11);
2323 outb(adp->va_crtc_addr + 1, celsize - base - 1);
2328 /* make the cursor invisible */
2329 outb(adp->va_crtc_addr, 10);
2330 outb(adp->va_crtc_addr + 1, celsize);
2331 outb(adp->va_crtc_addr, 11);
2332 outb(adp->va_crtc_addr + 1, 0);
2334 outb(adp->va_crtc_addr, 10);
2335 outb(adp->va_crtc_addr + 1, celsize - base - height);
2336 outb(adp->va_crtc_addr, 11);
2337 outb(adp->va_crtc_addr + 1, celsize - base);
2348 * Put the display in power save/power off mode.
2353 vga_blank_display(video_adapter_t *adp, int mode)
2358 switch (adp->va_type) {
2361 case V_DISPLAY_SUSPEND:
2362 case V_DISPLAY_STAND_BY:
2366 outb(TSREG, val | 0x20);
2367 outb(adp->va_crtc_addr, 0x17);
2368 val = inb(adp->va_crtc_addr + 1);
2369 outb(adp->va_crtc_addr + 1, val & ~0x80);
2371 case V_DISPLAY_BLANK:
2375 outb(TSREG, val | 0x20);
2381 outb(TSREG, val & 0xDF);
2382 outb(adp->va_crtc_addr, 0x17);
2383 val = inb(adp->va_crtc_addr + 1);
2384 outb(adp->va_crtc_addr + 1, val | 0x80);
2390 /* no support yet */
2396 case V_DISPLAY_SUSPEND:
2397 case V_DISPLAY_STAND_BY:
2398 case V_DISPLAY_BLANK:
2399 outb(adp->va_crtc_addr + 4, 0x25);
2402 outb(adp->va_crtc_addr + 4, 0x2d);
2410 case V_DISPLAY_SUSPEND:
2411 case V_DISPLAY_STAND_BY:
2412 case V_DISPLAY_BLANK:
2413 outb(adp->va_crtc_addr + 4, 0x21);
2416 outb(adp->va_crtc_addr + 4, 0x29);
2430 * Mmap frame buffer.
2435 vga_mmap_buf(video_adapter_t *adp, vm_offset_t offset, int prot)
2437 if (adp->va_info.vi_flags & V_INFO_LINEAR)
2441 printf("vga_mmap_buf(): window:0x%x, offset:0x%x\n",
2442 adp->va_info.vi_window, offset);
2445 /* XXX: is this correct? */
2446 if (offset > adp->va_window_size - PAGE_SIZE)
2450 return i386_btop(adp->va_info.vi_window + offset);
2454 #ifndef VGA_NO_MODE_CHANGE
2457 planar_fill(video_adapter_t *adp, int val)
2460 int at; /* position in the frame buffer */
2463 outw(GDCIDX, 0x0005); /* read mode 0, write mode 0 */
2464 outw(GDCIDX, 0x0003); /* data rotate/function select */
2465 outw(GDCIDX, 0x0f01); /* set/reset enable */
2466 outw(GDCIDX, 0xff08); /* bit mask */
2467 outw(GDCIDX, (val << 8) | 0x00); /* set/reset */
2469 length = adp->va_line_width*adp->va_info.vi_height;
2470 while (length > 0) {
2471 l = imin(length, adp->va_window_size);
2472 (*vidsw[adp->va_index]->set_win_org)(adp, at);
2473 bzero_io(adp->va_window, l);
2477 outw(GDCIDX, 0x0000); /* set/reset */
2478 outw(GDCIDX, 0x0001); /* set/reset enable */
2482 packed_fill(video_adapter_t *adp, int val)
2485 int at; /* position in the frame buffer */
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 fill_io(val, adp->va_window, l);
2500 direct_fill(video_adapter_t *adp, int val)
2503 int at; /* position in the frame buffer */
2507 length = adp->va_line_width*adp->va_info.vi_height;
2508 while (length > 0) {
2509 l = imin(length, adp->va_window_size);
2510 (*vidsw[adp->va_index]->set_win_org)(adp, at);
2511 switch (adp->va_info.vi_pixel_size) {
2512 case sizeof(u_int16_t):
2513 fillw_io(val, adp->va_window, l/sizeof(u_int16_t));
2518 case sizeof(u_int32_t):
2519 filll_io(val, adp->va_window, l/sizeof(u_int32_t));
2528 vga_clear(video_adapter_t *adp)
2530 switch (adp->va_info.vi_mem_model) {
2531 case V_INFO_MM_TEXT:
2532 /* do nothing? XXX */
2534 case V_INFO_MM_PLANAR:
2535 planar_fill(adp, 0);
2537 case V_INFO_MM_PACKED:
2538 packed_fill(adp, 0);
2540 case V_INFO_MM_DIRECT:
2541 direct_fill(adp, 0);
2549 planar_fill_rect(video_adapter_t *adp, int val, int x, int y, int cx, int cy)
2554 int offset; /* offset within window */
2558 outw(GDCIDX, 0x0005); /* read mode 0, write mode 0 */
2559 outw(GDCIDX, 0x0003); /* data rotate/function select */
2560 outw(GDCIDX, 0x0f01); /* set/reset enable */
2561 outw(GDCIDX, 0xff08); /* bit mask */
2562 outw(GDCIDX, (val << 8) | 0x00); /* set/reset */
2564 banksize = adp->va_window_size;
2567 pos = adp->va_line_width*y + x/8;
2568 if (bank != pos/banksize) {
2569 (*vidsw[adp->va_index]->set_win_org)(adp, pos);
2570 bank = pos/banksize;
2572 offset = pos%banksize;
2573 bx = (x + cx)/8 - x/8;
2575 outw(GDCIDX, ((0xff00 >> (x % 8)) & 0xff00) | 0x08);
2576 writeb(adp->va_window + offset, 0);
2579 if (offset >= banksize) {
2581 ++bank; /* next bank */
2582 (*vidsw[adp->va_index]->set_win_org)(adp, bank*banksize);
2584 outw(GDCIDX, 0xff08); /* bit mask */
2587 l = imin(bx, banksize);
2588 bzero_io(adp->va_window + offset, l);
2591 if (offset >= banksize) {
2593 ++bank; /* next bank */
2594 (*vidsw[adp->va_index]->set_win_org)(adp, bank*banksize);
2598 outw(GDCIDX, (~(0xff00 >> ((x + cx) % 8)) & 0xff00) | 0x08);
2599 writeb(adp->va_window + offset, 0);
2601 if (offset >= banksize) {
2603 ++bank; /* next bank */
2604 (*vidsw[adp->va_index]->set_win_org)(adp, bank*banksize);
2606 outw(GDCIDX, 0xff08); /* bit mask */
2612 outw(GDCIDX, 0xff08); /* bit mask */
2613 outw(GDCIDX, 0x0000); /* set/reset */
2614 outw(GDCIDX, 0x0001); /* set/reset enable */
2618 packed_fill_rect(video_adapter_t *adp, int val, int x, int y, int cx, int cy)
2623 int offset; /* offset within window */
2626 banksize = adp->va_window_size;
2628 cx *= adp->va_info.vi_pixel_size;
2630 pos = adp->va_line_width*y + x*adp->va_info.vi_pixel_size;
2631 if (bank != pos/banksize) {
2632 (*vidsw[adp->va_index]->set_win_org)(adp, pos);
2633 bank = pos/banksize;
2635 offset = pos%banksize;
2636 end = imin(offset + cx, banksize);
2637 fill_io(val, adp->va_window + offset,
2638 (end - offset)/adp->va_info.vi_pixel_size);
2639 /* the line may cross the window boundary */
2640 if (offset + cx > banksize) {
2641 ++bank; /* next bank */
2642 (*vidsw[adp->va_index]->set_win_org)(adp, bank*banksize);
2643 end = offset + cx - banksize;
2644 fill_io(val, adp->va_window, end/adp->va_info.vi_pixel_size);
2652 direct_fill_rect16(video_adapter_t *adp, int val, int x, int y, int cx, int cy)
2657 int offset; /* offset within window */
2661 * XXX: the function assumes that banksize is a muliple of
2662 * sizeof(u_int16_t).
2664 banksize = adp->va_window_size;
2666 cx *= sizeof(u_int16_t);
2668 pos = adp->va_line_width*y + x*sizeof(u_int16_t);
2669 if (bank != pos/banksize) {
2670 (*vidsw[adp->va_index]->set_win_org)(adp, pos);
2671 bank = pos/banksize;
2673 offset = pos%banksize;
2674 end = imin(offset + cx, banksize);
2675 fillw_io(val, adp->va_window + offset,
2676 (end - offset)/sizeof(u_int16_t));
2677 /* the line may cross the window boundary */
2678 if (offset + cx > banksize) {
2679 ++bank; /* next bank */
2680 (*vidsw[adp->va_index]->set_win_org)(adp, bank*banksize);
2681 end = offset + cx - banksize;
2682 fillw_io(val, adp->va_window, end/sizeof(u_int16_t));
2690 direct_fill_rect24(video_adapter_t *adp, int val, int x, int y, int cx, int cy)
2695 int offset; /* offset within window */
2701 b[0] = val & 0x0000ff;
2702 b[1] = (val >> 8) & 0x0000ff;
2703 b[2] = (val >> 16) & 0x0000ff;
2704 banksize = adp->va_window_size;
2708 pos = adp->va_line_width*y + x*3;
2709 if (bank != pos/banksize) {
2710 (*vidsw[adp->va_index]->set_win_org)(adp, pos);
2711 bank = pos/banksize;
2713 offset = pos%banksize;
2714 end = imin(offset + cx, banksize);
2715 for (i = 0, j = offset; j < end; i = (++i)%3, ++j) {
2716 writeb(adp->va_window + j, b[i]);
2718 /* the line may cross the window boundary */
2719 if (offset + cx >= banksize) {
2720 ++bank; /* next bank */
2721 (*vidsw[adp->va_index]->set_win_org)(adp, bank*banksize);
2723 end = offset + cx - banksize;
2724 for (; j < end; i = (++i)%3, ++j) {
2725 writeb(adp->va_window + j, b[i]);
2734 direct_fill_rect32(video_adapter_t *adp, int val, int x, int y, int cx, int cy)
2739 int offset; /* offset within window */
2743 * XXX: the function assumes that banksize is a muliple of
2744 * sizeof(u_int32_t).
2746 banksize = adp->va_window_size;
2748 cx *= sizeof(u_int32_t);
2750 pos = adp->va_line_width*y + x*sizeof(u_int32_t);
2751 if (bank != pos/banksize) {
2752 (*vidsw[adp->va_index]->set_win_org)(adp, pos);
2753 bank = pos/banksize;
2755 offset = pos%banksize;
2756 end = imin(offset + cx, banksize);
2757 filll_io(val, adp->va_window + offset,
2758 (end - offset)/sizeof(u_int32_t));
2759 /* the line may cross the window boundary */
2760 if (offset + cx > banksize) {
2761 ++bank; /* next bank */
2762 (*vidsw[adp->va_index]->set_win_org)(adp, bank*banksize);
2763 end = offset + cx - banksize;
2764 filll_io(val, adp->va_window, end/sizeof(u_int32_t));
2772 vga_fill_rect(video_adapter_t *adp, int val, int x, int y, int cx, int cy)
2774 switch (adp->va_info.vi_mem_model) {
2775 case V_INFO_MM_TEXT:
2776 /* do nothing? XXX */
2778 case V_INFO_MM_PLANAR:
2779 planar_fill_rect(adp, val, x, y, cx, cy);
2781 case V_INFO_MM_PACKED:
2782 packed_fill_rect(adp, val, x, y, cx, cy);
2784 case V_INFO_MM_DIRECT:
2785 switch (adp->va_info.vi_pixel_size) {
2786 case sizeof(u_int16_t):
2787 direct_fill_rect16(adp, val, x, y, cx, cy);
2790 direct_fill_rect24(adp, val, x, y, cx, cy);
2792 case sizeof(u_int32_t):
2793 direct_fill_rect32(adp, val, x, y, cx, cy);
2802 vga_fill_rect(video_adapter_t *adp, int val, int x, int y, int cx, int cy)
2809 vga_bitblt(video_adapter_t *adp,...)
2815 #endif /* !VGA_NO_MODE_CHANGE */
2818 get_palette(video_adapter_t *adp, int base, int count,
2819 u_char *red, u_char *green, u_char *blue, u_char *trans)
2825 if (count < 0 || base < 0 || count > 256 || base > 256 ||
2829 r = kmalloc(count*3, M_DEVBUF, M_WAITOK);
2832 if (vga_save_palette2(adp, base, count, r, g, b)) {
2836 copyout(r, red, count);
2837 copyout(g, green, count);
2838 copyout(b, blue, count);
2839 if (trans != NULL) {
2841 copyout(r, trans, count);
2849 set_palette(video_adapter_t *adp, int base, int count,
2850 u_char *red, u_char *green, u_char *blue, u_char *trans)
2857 if (count < 0 || base < 0 || count > 256 || base > 256 ||
2861 r = kmalloc(count*3, M_DEVBUF, M_WAITOK);
2864 err = copyin(red, r, count);
2866 err = copyin(green, g, count);
2868 err = copyin(blue, b, count);
2870 err = vga_load_palette2(adp, base, count, r, g, b);
2873 return (err ? ENODEV : 0);
2877 vga_dev_ioctl(video_adapter_t *adp, u_long cmd, caddr_t arg)
2880 case FBIO_GETWINORG: /* get frame buffer window origin */
2884 case FBIO_SETWINORG: /* set frame buffer window origin */
2887 case FBIO_SETDISPSTART: /* set display start address */
2888 return (set_display_start(adp,
2889 ((video_display_start_t *)arg)->x,
2890 ((video_display_start_t *)arg)->y)
2893 case FBIO_SETLINEWIDTH: /* set scan line length in pixel */
2894 return (set_line_length(adp, *(u_int *)arg) ? ENODEV : 0);
2896 case FBIO_GETPALETTE: /* get color palette */
2897 return get_palette(adp, ((video_color_palette_t *)arg)->index,
2898 ((video_color_palette_t *)arg)->count,
2899 ((video_color_palette_t *)arg)->red,
2900 ((video_color_palette_t *)arg)->green,
2901 ((video_color_palette_t *)arg)->blue,
2902 ((video_color_palette_t *)arg)->transparent);
2904 case FBIO_SETPALETTE: /* set color palette */
2905 return set_palette(adp, ((video_color_palette_t *)arg)->index,
2906 ((video_color_palette_t *)arg)->count,
2907 ((video_color_palette_t *)arg)->red,
2908 ((video_color_palette_t *)arg)->green,
2909 ((video_color_palette_t *)arg)->blue,
2910 ((video_color_palette_t *)arg)->transparent);
2912 case FBIOGTYPE: /* get frame buffer type info. */
2913 ((struct fbtype *)arg)->fb_type = fb_type(adp->va_type);
2914 ((struct fbtype *)arg)->fb_height = adp->va_info.vi_height;
2915 ((struct fbtype *)arg)->fb_width = adp->va_info.vi_width;
2916 ((struct fbtype *)arg)->fb_depth = adp->va_info.vi_depth;
2917 if ((adp->va_info.vi_depth <= 1) || (adp->va_info.vi_depth > 8))
2918 ((struct fbtype *)arg)->fb_cmsize = 0;
2920 ((struct fbtype *)arg)->fb_cmsize = 1 << adp->va_info.vi_depth;
2921 ((struct fbtype *)arg)->fb_size = adp->va_buffer_size;
2924 case FBIOGETCMAP: /* get color palette */
2925 return get_palette(adp, ((struct fbcmap *)arg)->index,
2926 ((struct fbcmap *)arg)->count,
2927 ((struct fbcmap *)arg)->red,
2928 ((struct fbcmap *)arg)->green,
2929 ((struct fbcmap *)arg)->blue, NULL);
2931 case FBIOPUTCMAP: /* set color palette */
2932 return set_palette(adp, ((struct fbcmap *)arg)->index,
2933 ((struct fbcmap *)arg)->count,
2934 ((struct fbcmap *)arg)->red,
2935 ((struct fbcmap *)arg)->green,
2936 ((struct fbcmap *)arg)->blue, NULL);
2939 return fb_commonioctl(adp, cmd, arg);
2944 dump_buffer(u_char *buf, size_t len)
2948 for(i = 0; i < len;) {
2949 printf("%02x ", buf[i]);
2950 if ((++i % 16) == 0)
2957 * Print some information about the video adapter and video modes,
2958 * with requested level of details.
2963 vga_diag(video_adapter_t *adp, int level)
2976 printf("vga: RTC equip. code:0x%02x, DCC code:0x%02x\n",
2977 rtcin(RTC_EQUIPMENT), readb(BIOS_PADDRTOVADDR(0x488)));
2978 printf("vga: CRTC:0x%x, video option:0x%02x, ",
2979 readw(BIOS_PADDRTOVADDR(0x463)),
2980 readb(BIOS_PADDRTOVADDR(0x487)));
2981 printf("rows:%d, cols:%d, font height:%d\n",
2982 readb(BIOS_PADDRTOVADDR(0x44a)),
2983 readb(BIOS_PADDRTOVADDR(0x484)) + 1,
2984 readb(BIOS_PADDRTOVADDR(0x485)));
2985 #endif /* VGA_NO_BIOS */
2986 #if !defined(VGA_NO_BIOS) && !defined(VGA_NO_MODE_CHANGE)
2987 printf("vga: param table EGA/VGA:%p", video_mode_ptr);
2988 printf(", CGA/MDA:%p\n", video_mode_ptr2);
2989 printf("vga: rows_offset:%d\n", rows_offset);
2991 #endif /* FB_DEBUG > 1 */
2993 fb_dump_adp_info(VGA_DRIVER_NAME, adp, level);
2996 if (adp->va_flags & V_ADP_MODECHANGE) {
2997 for (i = 0; bios_vmode[i].vi_mode != EOT; ++i) {
2998 if (bios_vmode[i].vi_mode == NA)
3000 if (get_mode_param(bios_vmode[i].vi_mode) == NULL)
3002 fb_dump_mode_info(VGA_DRIVER_NAME, adp, &bios_vmode[i], level);
3005 vga_get_info(adp, adp->va_initial_mode, &info); /* shouldn't fail */
3006 fb_dump_mode_info(VGA_DRIVER_NAME, adp, &info, level);
3008 #endif /* FB_DEBUG > 1 */
3010 if ((adp->va_type != KD_EGA) && (adp->va_type != KD_VGA))
3012 #if !defined(VGA_NO_BIOS) && !defined(VGA_NO_MODE_CHANGE)
3013 if (video_mode_ptr == NULL)
3014 printf("vga%d: %s: WARNING: video mode switching is not "
3015 "fully supported on this adapter\n",
3016 adp->va_unit, adp->va_name);
3021 if (adp->va_type == KD_VGA) {
3022 printf("VGA parameters upon power-up\n");
3023 dump_buffer(adpstate.regs, sizeof(adpstate.regs));
3024 printf("VGA parameters in BIOS for mode %d\n", adp->va_initial_mode);
3025 dump_buffer(adpstate2.regs, sizeof(adpstate2.regs));
3028 mp = get_mode_param(adp->va_initial_mode);
3029 if (mp == NULL) /* this shouldn't be happening */
3031 printf("EGA/VGA parameters to be used for mode %d\n", adp->va_initial_mode);
3032 dump_buffer(mp, V_MODE_PARAM_SIZE);