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.10 2005/02/14 23:05:30 swildner 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);
460 #ifndef VGA_NO_MODE_CHANGE
461 static void filll_io(int val, vm_offset_t d, size_t size);
464 #ifndef VGA_NO_MODE_CHANGE
466 static void set_width90(adp_state_t *params);
468 #endif /* !VGA_NO_MODE_CHANGE */
470 #ifndef VGA_NO_FONT_LOADING
471 #define PARAM_BUFSIZE 6
472 static void set_font_mode(video_adapter_t *adp, u_char *buf);
473 static void set_normal_mode(video_adapter_t *adp, u_char *buf);
476 #ifndef VGA_NO_MODE_CHANGE
477 static void planar_fill(video_adapter_t *adp, int val);
478 static void packed_fill(video_adapter_t *adp, int val);
479 static void direct_fill(video_adapter_t *adp, int val);
481 static void planar_fill_rect(video_adapter_t *adp, int val, int x, int y,
483 static void packed_fill_rect(video_adapter_t *adp, int val, int x, int y,
485 static void direct_fill_rect16(video_adapter_t *adp, int val, int x, int y,
487 static void direct_fill_rect24(video_adapter_t *adp, int val, int x, int y,
489 static void direct_fill_rect32(video_adapter_t *adp, int val, int x, int y,
492 #endif /* !VGA_NO_MODE_CHANGE */
494 static void dump_buffer(u_char *buf, size_t len);
496 #define ISMAPPED(pa, width) \
497 (((pa) <= (u_long)0x1000 - (width)) \
498 || ((pa) >= ISA_HOLE_START && (pa) <= 0x100000 - (width)))
500 #define prologue(adp, flag, err) \
501 if (!vga_init_done || !((adp)->va_flags & (flag))) \
504 /* a backdoor for the console driver */
506 vga_configure(int flags)
511 for (i = 0; i < biosadapters; ++i) {
512 if (!probe_done(&biosadapter[i]))
514 biosadapter[i].va_flags |= V_ADP_INITIALIZED;
515 if (!config_done(&biosadapter[i])) {
516 if (vid_register(&biosadapter[i]) < 0)
518 biosadapter[i].va_flags |= V_ADP_REGISTERED;
521 if (vga_sub_configure != NULL)
522 (*vga_sub_configure)(flags);
527 /* local subroutines */
529 #if !defined(VGA_NO_BIOS) && !defined(VGA_NO_MODE_CHANGE)
530 /* construct the mode parameter map */
532 map_mode_table(u_char *map[], u_char *table, int max)
536 for(i = 0; i < max; ++i)
537 map[i] = table + i*V_MODE_PARAM_SIZE;
538 for(; i < V_MODE_MAP_SIZE; ++i)
541 #endif /* !VGA_NO_BIOS && !VGA_NO_MODE_CHANGE */
544 clear_mode_map(video_adapter_t *adp, u_char *map[], int max, int color)
550 * NOTE: we don't touch `bios_vmode[]' because it is shared
553 for(i = 0; i < max; ++i) {
554 if (vga_get_info(adp, i, &info))
556 if ((info.vi_flags & V_INFO_COLOR) != color)
561 #if !defined(VGA_NO_BIOS) && !defined(VGA_NO_MODE_CHANGE)
562 /* map the non-standard video mode to a known mode number */
564 map_mode_num(int mode)
570 { M_ENH_B80x43, M_ENH_B80x25 },
571 { M_ENH_C80x43, M_ENH_C80x25 },
572 { M_VGA_M80x30, M_VGA_M80x25 },
573 { M_VGA_C80x30, M_VGA_C80x25 },
574 { M_VGA_M80x50, M_VGA_M80x25 },
575 { M_VGA_C80x50, M_VGA_C80x25 },
576 { M_VGA_M80x60, M_VGA_M80x25 },
577 { M_VGA_C80x60, M_VGA_C80x25 },
579 { M_VGA_M90x25, M_VGA_M80x25 },
580 { M_VGA_C90x25, M_VGA_C80x25 },
581 { M_VGA_M90x30, M_VGA_M80x25 },
582 { M_VGA_C90x30, M_VGA_C80x25 },
583 { M_VGA_M90x43, M_ENH_B80x25 },
584 { M_VGA_C90x43, M_ENH_C80x25 },
585 { M_VGA_M90x50, M_VGA_M80x25 },
586 { M_VGA_C90x50, M_VGA_C80x25 },
587 { M_VGA_M90x60, M_VGA_M80x25 },
588 { M_VGA_C90x60, M_VGA_C80x25 },
590 { M_VGA_MODEX, M_VGA_CG320 },
594 for (i = 0; i < sizeof(mode_map)/sizeof(mode_map[0]); ++i) {
595 if (mode_map[i].from == mode)
596 return mode_map[i].to;
600 #endif /* !VGA_NO_BIOS && !VGA_NO_MODE_CHANGE */
602 /* map a generic video mode to a known mode number */
604 map_gen_mode_num(int type, int color, int mode)
611 { M_TEXT_80x30, M_VGA_C80x30, M_VGA_M80x30, },
612 { M_TEXT_80x43, M_ENH_C80x43, M_ENH_B80x43, },
613 { M_TEXT_80x50, M_VGA_C80x50, M_VGA_M80x50, },
614 { M_TEXT_80x60, M_VGA_C80x60, M_VGA_M80x60, },
618 if (mode == M_TEXT_80x25) {
632 return M_EGAMONO80x25;
640 return M_EGAMONO80x25; /* XXX: this name is confusing */
647 for (i = 0; i < sizeof(mode_map)/sizeof(mode_map[0]); ++i) {
648 if (mode_map[i].from == mode)
649 return ((color) ? mode_map[i].to_color : mode_map[i].to_mono);
654 /* turn the BIOS video number into our video mode number */
656 map_bios_mode_num(int type, int color, int bios_mode)
658 static int cga_modes[7] = {
659 M_B40x25, M_C40x25, /* 0, 1 */
660 M_B80x25, M_C80x25, /* 2, 3 */
664 static int ega_modes[17] = {
665 M_ENH_B40x25, M_ENH_C40x25, /* 0, 1 */
666 M_ENH_B80x25, M_ENH_C80x25, /* 2, 3 */
669 M_EGAMONO80x25, /* 7 */
673 M_ENHMONOAPA2, /* XXX: video momery > 64K */
674 M_ENH_CG640, /* XXX: video momery > 64K */
676 static int vga_modes[20] = {
677 M_VGA_C40x25, M_VGA_C40x25, /* 0, 1 */
678 M_VGA_C80x25, M_VGA_C80x25, /* 2, 3 */
681 M_VGA_M80x25, /* 7 */
687 M_BG640x480, M_CG640x480,
694 if (bios_mode < sizeof(vga_modes)/sizeof(vga_modes[0]))
695 return vga_modes[bios_mode];
703 if (bios_mode < sizeof(ega_modes)/sizeof(ega_modes[0]))
704 return ega_modes[bios_mode];
708 return M_EGAMONO80x25;
712 if (bios_mode < sizeof(cga_modes)/sizeof(cga_modes[0]))
713 return cga_modes[bios_mode];
720 return M_EGAMONO80x25; /* XXX: this name is confusing */
728 /* look up a parameter table entry */
730 *get_mode_param(int mode)
732 #if !defined(VGA_NO_BIOS) && !defined(VGA_NO_MODE_CHANGE)
733 if (mode >= V_MODE_MAP_SIZE)
734 mode = map_mode_num(mode);
736 if ((mode >= 0) && (mode < V_MODE_MAP_SIZE))
737 return mode_map[mode];
744 fill_adapter_param(int code, video_adapter_t *adp)
750 { DCC_MONO, DCC_EGA40 /* CGA monitor */ },
751 { DCC_MONO, DCC_EGA80 /* CGA monitor */ },
752 { DCC_MONO, DCC_EGA80 },
753 { DCC_MONO, DCC_EGA80 },
754 { DCC_CGA40, DCC_EGAMONO },
755 { DCC_CGA80, DCC_EGAMONO },
756 { DCC_EGA40 /* CGA monitor */, DCC_MONO},
757 { DCC_EGA80 /* CGA monitor */, DCC_MONO},
758 { DCC_EGA80, DCC_MONO },
759 { DCC_EGA80, DCC_MONO },
760 { DCC_EGAMONO, DCC_CGA40 },
761 { DCC_EGAMONO, DCC_CGA80 },
764 if ((code < 0) || (code >= sizeof(dcc)/sizeof(dcc[0]))) {
765 adp[V_ADP_PRIMARY] = adapter_init_value[DCC_MONO];
766 adp[V_ADP_SECONDARY] = adapter_init_value[DCC_CGA80];
768 adp[V_ADP_PRIMARY] = adapter_init_value[dcc[code].primary];
769 adp[V_ADP_SECONDARY] = adapter_init_value[dcc[code].secondary];
772 #endif /* VGA_NO_BIOS */
775 verify_adapter(video_adapter_t *adp)
779 #if !defined(VGA_NO_BIOS) && !defined(VGA_NO_MODE_CHANGE)
783 buf = BIOS_PADDRTOVADDR(adp->va_window);
786 if (readw(buf) != 0xA55A)
790 switch (adp->va_type) {
793 outb(adp->va_crtc_addr, 7);
794 if (inb(adp->va_crtc_addr) == 7) {
795 adp->va_type = KD_VGA;
796 adp->va_name = "vga";
797 adp->va_flags |= V_ADP_STATESAVE | V_ADP_PALETTE;
799 adp->va_flags |= V_ADP_STATELOAD | V_ADP_BORDER;
800 /* the color adapter may be in the 40x25 mode... XXX */
802 #if !defined(VGA_NO_BIOS) && !defined(VGA_NO_MODE_CHANGE)
803 /* get the BIOS video mode pointer */
804 p = *(u_int32_t *)BIOS_PADDRTOVADDR(0x4a8);
805 p = BIOS_SADDRTOLADDR(p);
806 if (ISMAPPED(p, sizeof(u_int32_t))) {
807 p = *(u_int32_t *)BIOS_PADDRTOVADDR(p);
808 p = BIOS_SADDRTOLADDR(p);
809 if (ISMAPPED(p, V_MODE_PARAM_SIZE))
810 video_mode_ptr = (u_char *)BIOS_PADDRTOVADDR(p);
816 adp->va_flags |= V_ADP_COLOR | V_ADP_BORDER;
817 /* may be in the 40x25 mode... XXX */
818 #if !defined(VGA_NO_BIOS) && !defined(VGA_NO_MODE_CHANGE)
819 /* get the BIOS video mode pointer */
820 p = *(u_int32_t *)BIOS_PADDRTOVADDR(0x1d*4);
821 p = BIOS_SADDRTOLADDR(p);
822 video_mode_ptr2 = (u_char *)BIOS_PADDRTOVADDR(p);
827 #if !defined(VGA_NO_BIOS) && !defined(VGA_NO_MODE_CHANGE)
828 /* get the BIOS video mode pointer */
829 p = *(u_int32_t *)BIOS_PADDRTOVADDR(0x1d*4);
830 p = BIOS_SADDRTOLADDR(p);
831 video_mode_ptr2 = (u_char *)BIOS_PADDRTOVADDR(p);
840 update_adapter_info(video_adapter_t *adp, video_info_t *info)
842 adp->va_flags &= ~V_ADP_COLOR;
844 (info->vi_flags & V_INFO_COLOR) ? V_ADP_COLOR : 0;
846 (adp->va_flags & V_ADP_COLOR) ? COLOR_CRTC : MONO_CRTC;
847 adp->va_window = BIOS_PADDRTOVADDR(info->vi_window);
848 adp->va_window_size = info->vi_window_size;
849 adp->va_window_gran = info->vi_window_gran;
850 adp->va_window_orig = 0;
852 adp->va_buffer = info->vi_buffer;
853 adp->va_buffer_size = info->vi_buffer_size;
854 if (info->vi_mem_model == V_INFO_MM_VGAX) {
855 adp->va_line_width = info->vi_width/2;
856 } else if (info->vi_flags & V_INFO_GRAPHICS) {
857 switch (info->vi_depth/info->vi_planes) {
859 adp->va_line_width = info->vi_width/8;
862 adp->va_line_width = info->vi_width/4;
865 adp->va_line_width = info->vi_width/2;
868 default: /* shouldn't happen */
869 adp->va_line_width = info->vi_width;
873 adp->va_line_width = info->vi_width;
875 adp->va_disp_start.x = 0;
876 adp->va_disp_start.y = 0;
877 bcopy(info, &adp->va_info, sizeof(adp->va_info));
880 #if !defined(VGA_NO_BIOS) && !defined(VGA_NO_MODE_CHANGE)
881 /* compare two parameter table entries */
883 comp_adpregs(u_char *buf1, u_char *buf2)
887 } params[V_MODE_PARAM_SIZE] = {
888 {0xff}, {0x00}, {0xff}, /* COLS}, ROWS}, POINTS */
889 {0x00}, {0x00}, /* page length */
890 {0xfe}, {0xff}, {0xff}, {0xff}, /* sequencer registers */
891 {0xf3}, /* misc register */
892 {0xff}, {0xff}, {0xff}, {0x7f}, {0xff}, /* CRTC */
893 {0xff}, {0xff}, {0xff}, {0x7f}, {0xff},
894 {0x00}, {0x00}, {0x00}, {0x00}, {0x00},
895 {0x00}, {0xff}, {0x7f}, {0xff}, {0xff},
896 {0x7f}, {0xff}, {0xff}, {0xef}, {0xff},
897 {0xff}, {0xff}, {0xff}, {0xff}, {0xff}, /* attribute controller regs */
898 {0xff}, {0xff}, {0xff}, {0xff}, {0xff},
899 {0xff}, {0xff}, {0xff}, {0xff}, {0xff},
900 {0xff}, {0xff}, {0xff}, {0xff}, {0xf0},
901 {0xff}, {0xff}, {0xff}, {0xff}, {0xff}, /* GDC register */
902 {0xff}, {0xff}, {0xff}, {0xff},
904 int identical = TRUE;
907 if ((buf1 == NULL) || (buf2 == NULL))
908 return COMP_DIFFERENT;
910 for (i = 0; i < sizeof(params)/sizeof(params[0]); ++i) {
911 if (params[i].mask == 0) /* don't care */
913 if ((buf1[i] & params[i].mask) != (buf2[i] & params[i].mask))
914 return COMP_DIFFERENT;
915 if (buf1[i] != buf2[i])
918 return (identical) ? COMP_IDENTICAL : COMP_SIMILAR;
920 #endif /* !VGA_NO_BIOS && !VGA_NO_MODE_CHANGE */
922 /* probe video adapters and return the number of detected adapters */
926 video_adapter_t *adp;
928 #if !defined(VGA_NO_BIOS) && !defined(VGA_NO_MODE_CHANGE)
933 /* do this test only once */
936 vga_init_done = TRUE;
939 * Locate display adapters.
940 * The AT architecture supports upto two adapters. `syscons' allows
941 * the following combinations of adapters:
943 * 2) MDA + EGA/VGA color
944 * 3) CGA + EGA/VGA mono
945 * Note that `syscons' doesn't bother with MCGA as it is only
946 * avaiable for low end PS/2 models which has 80286 or earlier CPUs,
947 * thus, they are not running FreeBSD!
948 * When there are two adapaters in the system, one becomes `primary'
949 * and the other `secondary'. The EGA adapter has a set of DIP
950 * switches on board for this information and the EGA BIOS copies
951 * it in the BIOS data area BIOSDATA_VIDEOSWITCH (40:88).
952 * The VGA BIOS has more sophisticated mechanism and has this
953 * information in BIOSDATA_DCCINDEX (40:8a), but it also maintains
954 * compatibility with the EGA BIOS by updating BIOSDATA_VIDEOSWITCH.
958 * Check rtc and BIOS data area.
959 * XXX: we don't use BIOSDATA_EQUIPMENT, since it is not a dead
960 * copy of RTC_EQUIPMENT. Bits 4 and 5 of ETC_EQUIPMENT are
961 * zeros for EGA and VGA. However, the EGA/VGA BIOS sets
962 * these bits in BIOSDATA_EQUIPMENT according to the monitor
966 if (*(u_int32_t *)BIOS_PADDRTOVADDR(0x4a8)) {
967 /* EGA/VGA BIOS is present */
968 fill_adapter_param(readb(BIOS_PADDRTOVADDR(0x488)) & 0x0f,
971 switch ((rtcin(RTC_EQUIPMENT) >> 4) & 3) { /* bit 4 and 5 */
973 /* EGA/VGA: shouldn't be happening */
974 fill_adapter_param(readb(BIOS_PADDRTOVADDR(0x488)) & 0x0f,
979 /* FIXME: switch to the 80x25 mode? XXX */
980 biosadapter[V_ADP_PRIMARY] = adapter_init_value[DCC_CGA40];
981 biosadapter[V_ADP_SECONDARY] = adapter_init_value[DCC_MONO];
985 biosadapter[V_ADP_PRIMARY] = adapter_init_value[DCC_CGA80];
986 biosadapter[V_ADP_SECONDARY] = adapter_init_value[DCC_MONO];
990 biosadapter[V_ADP_PRIMARY] = adapter_init_value[DCC_MONO];
991 biosadapter[V_ADP_SECONDARY] = adapter_init_value[DCC_CGA80];
996 /* assume EGA/VGA? XXX */
997 biosadapter[V_ADP_PRIMARY] = adapter_init_value[DCC_EGA80];
998 biosadapter[V_ADP_SECONDARY] = adapter_init_value[DCC_MONO];
999 #endif /* VGA_NO_BIOS */
1002 if (verify_adapter(&biosadapter[V_ADP_SECONDARY]) == 0) {
1004 biosadapter[V_ADP_SECONDARY].va_flags |= V_ADP_PROBED;
1005 biosadapter[V_ADP_SECONDARY].va_mode =
1006 biosadapter[V_ADP_SECONDARY].va_initial_mode =
1007 map_bios_mode_num(biosadapter[V_ADP_SECONDARY].va_type,
1008 biosadapter[V_ADP_SECONDARY].va_flags
1010 biosadapter[V_ADP_SECONDARY].va_initial_bios_mode);
1012 biosadapter[V_ADP_SECONDARY].va_type = -1;
1014 if (verify_adapter(&biosadapter[V_ADP_PRIMARY]) == 0) {
1016 biosadapter[V_ADP_PRIMARY].va_flags |= V_ADP_PROBED;
1018 biosadapter[V_ADP_PRIMARY].va_initial_bios_mode =
1019 readb(BIOS_PADDRTOVADDR(0x449));
1021 biosadapter[V_ADP_PRIMARY].va_initial_bios_mode = 3; /* XXX */
1023 biosadapter[V_ADP_PRIMARY].va_mode =
1024 biosadapter[V_ADP_PRIMARY].va_initial_mode =
1025 map_bios_mode_num(biosadapter[V_ADP_PRIMARY].va_type,
1026 biosadapter[V_ADP_PRIMARY].va_flags & V_ADP_COLOR,
1027 biosadapter[V_ADP_PRIMARY].va_initial_bios_mode);
1029 biosadapter[V_ADP_PRIMARY] = biosadapter[V_ADP_SECONDARY];
1030 biosadapter[V_ADP_SECONDARY].va_type = -1;
1032 if (biosadapters == 0)
1033 return biosadapters;
1034 biosadapter[V_ADP_PRIMARY].va_unit = V_ADP_PRIMARY;
1035 biosadapter[V_ADP_SECONDARY].va_unit = V_ADP_SECONDARY;
1037 #if 0 /* we don't need these... */
1038 fb_init_struct(&biosadapter[V_ADP_PRIMARY], ...);
1039 fb_init_struct(&biosadapter[V_ADP_SECONDARY], ...);
1044 * We cannot have two video adapter of the same type; there must be
1045 * only one of color or mono adapter, or one each of them.
1047 if (biosadapters > 1) {
1048 if (!((biosadapter[0].va_flags ^ biosadapter[1].va_flags)
1050 /* we have two mono or color adapters!! */
1051 return (biosadapters = 0);
1056 * Ensure a zero start address. This is mainly to recover after
1057 * switching from pcvt using userconfig(). The registers are w/o
1058 * for old hardware so it's too hard to relocate the active screen
1060 * This must be done before vga_save_state() for VGA.
1062 outb(biosadapter[V_ADP_PRIMARY].va_crtc_addr, 12);
1063 outb(biosadapter[V_ADP_PRIMARY].va_crtc_addr + 1, 0);
1064 outb(biosadapter[V_ADP_PRIMARY].va_crtc_addr, 13);
1065 outb(biosadapter[V_ADP_PRIMARY].va_crtc_addr + 1, 0);
1067 /* the video mode parameter table in EGA/VGA BIOS */
1068 /* NOTE: there can be only one EGA/VGA, wheather color or mono,
1069 * recognized by the video BIOS.
1071 if ((biosadapter[V_ADP_PRIMARY].va_type == KD_EGA) ||
1072 (biosadapter[V_ADP_PRIMARY].va_type == KD_VGA)) {
1073 adp = &biosadapter[V_ADP_PRIMARY];
1074 } else if ((biosadapter[V_ADP_SECONDARY].va_type == KD_EGA) ||
1075 (biosadapter[V_ADP_SECONDARY].va_type == KD_VGA)) {
1076 adp = &biosadapter[V_ADP_SECONDARY];
1080 bzero(mode_map, sizeof(mode_map));
1082 if (adp->va_type == KD_VGA) {
1083 vga_save_state(adp, &adpstate, sizeof(adpstate));
1084 for(i = 0; i < 16; i++)
1085 adp->va_palette_regs[i] = adpstate.regs[35 + i];
1086 #if defined(VGA_NO_BIOS) || defined(VGA_NO_MODE_CHANGE)
1087 mode_map[adp->va_initial_mode] = adpstate.regs;
1089 #else /* VGA_NO_BIOS || VGA_NO_MODE_CHANGE */
1090 if (video_mode_ptr == NULL) {
1091 mode_map[adp->va_initial_mode] = adpstate.regs;
1094 /* discard the table if we are not familiar with it... */
1095 map_mode_table(mode_map, video_mode_ptr, M_VGA_CG320 + 1);
1096 mp = get_mode_param(adp->va_initial_mode);
1098 bcopy(mp, adpstate2.regs, sizeof(adpstate2.regs));
1099 switch (comp_adpregs(adpstate.regs, mp)) {
1100 case COMP_IDENTICAL:
1102 * OK, this parameter table looks reasonably familiar
1106 * This is a kludge for Toshiba DynaBook SS433
1107 * whose BIOS video mode table entry has the actual #
1108 * of rows at the offset 1; BIOSes from other
1109 * manufacturers store the # of rows - 1 there. XXX
1111 rows_offset = adpstate.regs[1] + 1 - mp[1];
1116 * Not exactly the same, but similar enough to be
1117 * trusted. However, use the saved register values
1118 * for the initial mode and other modes which are
1119 * based on the initial mode.
1121 mode_map[adp->va_initial_mode] = adpstate.regs;
1122 rows_offset = adpstate.regs[1] + 1 - mp[1];
1123 adpstate.regs[1] -= rows_offset - 1;
1126 case COMP_DIFFERENT:
1129 * Don't use the paramter table in BIOS. It doesn't
1130 * look familiar to us. Video mode switching is allowed
1131 * only if the new mode is the same as or based on
1134 video_mode_ptr = NULL;
1135 bzero(mode_map, sizeof(mode_map));
1136 mode_map[adp->va_initial_mode] = adpstate.regs;
1141 #endif /* VGA_NO_BIOS || VGA_NO_MODE_CHANGE */
1143 #ifndef VGA_NO_MODE_CHANGE
1144 adp->va_flags |= V_ADP_MODECHANGE;
1146 #ifndef VGA_NO_FONT_LOADING
1147 adp->va_flags |= V_ADP_FONT;
1149 } else if (adp->va_type == KD_EGA) {
1150 #if defined(VGA_NO_BIOS) || defined(VGA_NO_MODE_CHANGE)
1152 #else /* VGA_NO_BIOS || VGA_NO_MODE_CHANGE */
1153 if (video_mode_ptr == NULL) {
1156 map_mode_table(mode_map, video_mode_ptr, M_ENH_C80x25 + 1);
1157 /* XXX how can one validate the EGA table... */
1158 mp = get_mode_param(adp->va_initial_mode);
1160 adp->va_flags |= V_ADP_MODECHANGE;
1161 #ifndef VGA_NO_FONT_LOADING
1162 adp->va_flags |= V_ADP_FONT;
1167 * This is serious. We will not be able to switch video
1170 video_mode_ptr = NULL;
1171 bzero(mode_map, sizeof(mode_map));
1175 #endif /* VGA_NO_BIOS || VGA_NO_MODE_CHANGE */
1179 /* remove conflicting modes if we have more than one adapter */
1180 if (biosadapters > 0) {
1181 for (i = 0; i < biosadapters; ++i) {
1182 if (!(biosadapter[i].va_flags & V_ADP_MODECHANGE))
1184 clear_mode_map(&biosadapter[i], mode_map, M_VGA_CG320 + 1,
1185 (biosadapter[i].va_flags & V_ADP_COLOR) ?
1187 if ((biosadapter[i].va_type == KD_VGA)
1188 || (biosadapter[i].va_type == KD_EGA)) {
1189 biosadapter[i].va_io_base =
1190 (biosadapter[i].va_flags & V_ADP_COLOR) ?
1192 biosadapter[i].va_io_size = 32;
1197 /* buffer address */
1198 vga_get_info(&biosadapter[V_ADP_PRIMARY],
1199 biosadapter[V_ADP_PRIMARY].va_initial_mode, &info);
1200 info.vi_flags &= ~V_INFO_LINEAR; /* XXX */
1201 update_adapter_info(&biosadapter[V_ADP_PRIMARY], &info);
1203 if (biosadapters > 1) {
1204 vga_get_info(&biosadapter[V_ADP_SECONDARY],
1205 biosadapter[V_ADP_SECONDARY].va_initial_mode, &info);
1206 info.vi_flags &= ~V_INFO_LINEAR; /* XXX */
1207 update_adapter_info(&biosadapter[V_ADP_SECONDARY], &info);
1211 * XXX: we should verify the following values for the primary adapter...
1212 * crtc I/O port address: *(u_int16_t *)BIOS_PADDRTOVADDR(0x463);
1213 * color/mono display: (*(u_int8_t *)BIOS_PADDRTOVADDR(0x487) & 0x02)
1214 * ? 0 : V_ADP_COLOR;
1215 * columns: *(u_int8_t *)BIOS_PADDRTOVADDR(0x44a);
1216 * rows: *(u_int8_t *)BIOS_PADDRTOVADDR(0x484);
1217 * font size: *(u_int8_t *)BIOS_PADDRTOVADDR(0x485);
1218 * buffer size: *(u_int16_t *)BIOS_PADDRTOVADDR(0x44c);
1221 return biosadapters;
1224 /* set the scan line length in pixel */
1226 set_line_length(video_adapter_t *adp, int pixel)
1229 int ppw; /* pixels per word */
1230 int bpl; /* bytes per line */
1233 if ((adp->va_type != KD_VGA) && (adp->va_type != KD_EGA))
1235 mp = get_mode_param(adp->va_mode);
1239 switch (adp->va_info.vi_mem_model) {
1240 case V_INFO_MM_PLANAR:
1241 ppw = 16/(adp->va_info.vi_depth/adp->va_info.vi_planes);
1242 count = (pixel + ppw - 1)/ppw/2;
1243 bpl = ((pixel + ppw - 1)/ppw/2)*4;
1245 case V_INFO_MM_PACKED:
1246 count = (pixel + 7)/8;
1247 bpl = ((pixel + 7)/8)*8;
1249 case V_INFO_MM_TEXT:
1250 count = (pixel + 7)/8; /* columns */
1251 bpl = (pixel + 7)/8; /* columns */
1257 if (mp[10 + 0x17] & 0x40) /* CRTC mode control reg */
1258 count *= 2; /* byte mode */
1259 outb(adp->va_crtc_addr, 0x13);
1260 outb(adp->va_crtc_addr + 1, count);
1261 adp->va_line_width = bpl;
1267 set_display_start(video_adapter_t *adp, int x, int y)
1269 int off; /* byte offset (graphics mode)/word offset (text mode) */
1270 int poff; /* pixel offset */
1271 int roff; /* row offset */
1272 int ppb; /* pixels per byte */
1274 if ((adp->va_type != KD_VGA) && (adp->va_type != KD_EGA))
1276 if (adp->va_info.vi_flags & V_INFO_GRAPHICS) {
1277 ppb = 8/(adp->va_info.vi_depth/adp->va_info.vi_planes);
1278 off = y*adp->va_line_width + x/ppb;
1282 if ((adp->va_type == KD_VGA) || (adp->va_type == KD_EGA)) {
1291 off = y/adp->va_info.vi_cheight*adp->va_line_width + x/ppb;
1292 roff = y%adp->va_info.vi_cheight;
1293 /* FIXME: is this correct? XXX */
1301 outb(adp->va_crtc_addr, 0xc); /* high */
1302 outb(adp->va_crtc_addr + 1, off >> 8);
1303 outb(adp->va_crtc_addr, 0xd); /* low */
1304 outb(adp->va_crtc_addr + 1, off & 0xff);
1306 /* horizontal pel pan */
1307 if ((adp->va_type == KD_VGA) || (adp->va_type == KD_EGA)) {
1308 inb(adp->va_crtc_addr + 6);
1309 outb(ATC, 0x13 | 0x20);
1311 inb(adp->va_crtc_addr + 6);
1315 /* preset raw scan */
1316 outb(adp->va_crtc_addr, 8);
1317 outb(adp->va_crtc_addr + 1, roff);
1319 adp->va_disp_start.x = x;
1320 adp->va_disp_start.y = y;
1324 #ifndef VGA_NO_MODE_CHANGE
1325 #ifdef __i386__ /* XXX */
1327 fill(int val, void *d, size_t size)
1334 #endif /* __i386__ */
1337 filll_io(int val, vm_offset_t d, size_t size)
1339 while (size-- > 0) {
1341 d += sizeof(u_int32_t);
1344 #endif /* VGA_NO_MODE_CHANGE */
1363 vga_probe(int unit, video_adapter_t **adpp, void *arg, int flags)
1366 if (unit >= biosadapters)
1369 *adpp = &biosadapter[unit];
1375 vga_init(int unit, video_adapter_t *adp, int flags)
1377 if ((unit >= biosadapters) || (adp == NULL) || !probe_done(adp))
1380 if (!init_done(adp)) {
1381 /* nothing to do really... */
1382 adp->va_flags |= V_ADP_INITIALIZED;
1385 if (!config_done(adp)) {
1386 if (vid_register(adp) < 0)
1388 adp->va_flags |= V_ADP_REGISTERED;
1390 if (vga_sub_configure != NULL)
1391 (*vga_sub_configure)(0);
1398 * Return the video_info structure of the requested video mode.
1403 vga_get_info(video_adapter_t *adp, int mode, video_info_t *info)
1410 mode = map_gen_mode_num(adp->va_type, adp->va_flags & V_ADP_COLOR, mode);
1411 #ifndef VGA_NO_MODE_CHANGE
1412 if (adp->va_flags & V_ADP_MODECHANGE) {
1414 * If the parameter table entry for this mode is not found,
1415 * the mode is not supported...
1417 if (get_mode_param(mode) == NULL)
1420 #endif /* VGA_NO_MODE_CHANGE */
1423 * Even if we don't support video mode switching on this adapter,
1424 * the information on the initial (thus current) video mode
1425 * should be made available.
1427 if (mode != adp->va_initial_mode)
1431 for (i = 0; bios_vmode[i].vi_mode != EOT; ++i) {
1432 if (bios_vmode[i].vi_mode == NA)
1434 if (mode == bios_vmode[i].vi_mode) {
1435 *info = bios_vmode[i];
1437 info->vi_buffer_size = info->vi_window_size*info->vi_planes;
1446 * Find a video mode matching the requested parameters.
1447 * Fields filled with 0 are considered "don't care" fields and
1453 vga_query_mode(video_adapter_t *adp, video_info_t *info)
1460 for (i = 0; bios_vmode[i].vi_mode != EOT; ++i) {
1461 if (bios_vmode[i].vi_mode == NA)
1464 if ((info->vi_width != 0)
1465 && (info->vi_width != bios_vmode[i].vi_width))
1467 if ((info->vi_height != 0)
1468 && (info->vi_height != bios_vmode[i].vi_height))
1470 if ((info->vi_cwidth != 0)
1471 && (info->vi_cwidth != bios_vmode[i].vi_cwidth))
1473 if ((info->vi_cheight != 0)
1474 && (info->vi_cheight != bios_vmode[i].vi_cheight))
1476 if ((info->vi_depth != 0)
1477 && (info->vi_depth != bios_vmode[i].vi_depth))
1479 if ((info->vi_planes != 0)
1480 && (info->vi_planes != bios_vmode[i].vi_planes))
1482 /* XXX: should check pixel format, memory model */
1483 if ((info->vi_flags != 0)
1484 && (info->vi_flags != bios_vmode[i].vi_flags))
1487 /* verify if this mode is supported on this adapter */
1488 if (vga_get_info(adp, bios_vmode[i].vi_mode, info))
1497 * Change the video mode.
1502 #ifndef VGA_NO_MODE_CHANGE
1505 set_width90(adp_state_t *params)
1508 * Based on code submitted by Kelly Yancey (kbyanc@freedomnet.com)
1509 * and alexv@sui.gda.itesm.mx.
1511 params->regs[5] |= 1; /* toggle 8 pixel wide fonts */
1512 params->regs[10+0x0] = 0x6b;
1513 params->regs[10+0x1] = 0x59;
1514 params->regs[10+0x2] = 0x5a;
1515 params->regs[10+0x3] = 0x8e;
1516 params->regs[10+0x4] = 0x5e;
1517 params->regs[10+0x5] = 0x8a;
1518 params->regs[10+0x13] = 45;
1519 params->regs[35+0x13] = 0;
1521 #endif /* VGA_WIDTH90 */
1522 #endif /* !VGA_NO_MODE_CHANGE */
1525 vga_set_mode(video_adapter_t *adp, int mode)
1527 #ifndef VGA_NO_MODE_CHANGE
1531 prologue(adp, V_ADP_MODECHANGE, ENODEV);
1533 mode = map_gen_mode_num(adp->va_type,
1534 adp->va_flags & V_ADP_COLOR, mode);
1535 if (vga_get_info(adp, mode, &info))
1539 printf("vga_set_mode(): setting mode %d\n", mode);
1542 params.sig = V_STATE_SIG;
1543 bcopy(get_mode_param(mode), params.regs, sizeof(params.regs));
1547 case M_VGA_C90x60: case M_VGA_M90x60:
1548 set_width90(¶ms);
1551 case M_VGA_C80x60: case M_VGA_M80x60:
1552 params.regs[2] = 0x08;
1553 params.regs[19] = 0x47;
1557 case M_VGA_C90x30: case M_VGA_M90x30:
1558 set_width90(¶ms);
1561 case M_VGA_C80x30: case M_VGA_M80x30:
1562 params.regs[19] = 0x4f;
1564 params.regs[9] |= 0xc0;
1565 params.regs[16] = 0x08;
1566 params.regs[17] = 0x3e;
1567 params.regs[26] = 0xea;
1568 params.regs[28] = 0xdf;
1569 params.regs[31] = 0xe7;
1570 params.regs[32] = 0x04;
1574 case M_VGA_C90x43: case M_VGA_M90x43:
1575 set_width90(¶ms);
1578 case M_ENH_C80x43: case M_ENH_B80x43:
1579 params.regs[28] = 87;
1583 case M_VGA_C90x50: case M_VGA_M90x50:
1584 set_width90(¶ms);
1587 case M_VGA_C80x50: case M_VGA_M80x50:
1590 params.regs[19] = 7;
1594 case M_VGA_C90x25: case M_VGA_M90x25:
1595 set_width90(¶ms);
1598 case M_VGA_C40x25: case M_VGA_C80x25:
1600 case M_B40x25: case M_C40x25:
1601 case M_B80x25: case M_C80x25:
1602 case M_ENH_B40x25: case M_ENH_C40x25:
1603 case M_ENH_B80x25: case M_ENH_C80x25:
1604 case M_EGAMONO80x25:
1607 vga_load_state(adp, ¶ms);
1611 /* "unchain" the VGA mode */
1612 params.regs[5-1+0x04] &= 0xf7;
1613 params.regs[5-1+0x04] |= 0x04;
1614 /* turn off doubleword mode */
1615 params.regs[10+0x14] &= 0xbf;
1616 /* turn off word adressing */
1617 params.regs[10+0x17] |= 0x40;
1618 /* set logical screen width */
1619 params.regs[10+0x13] = 80;
1621 params.regs[10+0x11] = 0x2c;
1622 params.regs[10+0x06] = 0x0d;
1623 params.regs[10+0x07] = 0x3e;
1624 params.regs[10+0x10] = 0xea;
1625 params.regs[10+0x11] = 0xac;
1626 params.regs[10+0x12] = 0xdf;
1627 params.regs[10+0x15] = 0xe7;
1628 params.regs[10+0x16] = 0x06;
1629 /* set vertical sync polarity to reflect aspect ratio */
1630 params.regs[9] = 0xe3;
1633 case M_BG320: case M_CG320: case M_BG640:
1634 case M_CG320_D: case M_CG640_E:
1635 case M_CG640x350: case M_ENH_CG640:
1636 case M_BG640x480: case M_CG640x480: case M_VGA_CG320:
1639 vga_load_state(adp, ¶ms);
1646 adp->va_mode = mode;
1647 info.vi_flags &= ~V_INFO_LINEAR; /* XXX */
1648 update_adapter_info(adp, &info);
1650 /* move hardware cursor out of the way */
1651 (*vidsw[adp->va_index]->set_hw_cursor)(adp, -1, -1);
1654 #else /* VGA_NO_MODE_CHANGE */
1656 #endif /* VGA_NO_MODE_CHANGE */
1659 #ifndef VGA_NO_FONT_LOADING
1662 set_font_mode(video_adapter_t *adp, u_char *buf)
1669 /* save register values */
1670 if (adp->va_type == KD_VGA) {
1671 outb(TSIDX, 0x02); buf[0] = inb(TSREG);
1672 outb(TSIDX, 0x04); buf[1] = inb(TSREG);
1673 outb(GDCIDX, 0x04); buf[2] = inb(GDCREG);
1674 outb(GDCIDX, 0x05); buf[3] = inb(GDCREG);
1675 outb(GDCIDX, 0x06); buf[4] = inb(GDCREG);
1676 inb(adp->va_crtc_addr + 6);
1677 outb(ATC, 0x10); buf[5] = inb(ATC + 1);
1678 } else /* if (adp->va_type == KD_EGA) */ {
1680 * EGA cannot be read; copy parameters from the mode parameter
1683 mp = get_mode_param(adp->va_mode);
1684 buf[0] = mp[5 + 0x02 - 1];
1685 buf[1] = mp[5 + 0x04 - 1];
1686 buf[2] = mp[55 + 0x04];
1687 buf[3] = mp[55 + 0x05];
1688 buf[4] = mp[55 + 0x06];
1689 buf[5] = mp[35 + 0x10];
1692 /* setup vga for loading fonts */
1693 inb(adp->va_crtc_addr + 6); /* reset flip-flop */
1694 outb(ATC, 0x10); outb(ATC, buf[5] & ~0x01);
1695 inb(adp->va_crtc_addr + 6); /* reset flip-flop */
1696 outb(ATC, 0x20); /* enable palette */
1698 #if VGA_SLOW_IOACCESS
1699 #ifdef VGA_ALT_SEQACCESS
1700 outb(TSIDX, 0x00); outb(TSREG, 0x01);
1702 outb(TSIDX, 0x02); outb(TSREG, 0x04);
1703 outb(TSIDX, 0x04); outb(TSREG, 0x07);
1704 #ifdef VGA_ALT_SEQACCESS
1705 outb(TSIDX, 0x00); outb(TSREG, 0x03);
1707 outb(GDCIDX, 0x04); outb(GDCREG, 0x02);
1708 outb(GDCIDX, 0x05); outb(GDCREG, 0x00);
1709 outb(GDCIDX, 0x06); outb(GDCREG, 0x04);
1710 #else /* VGA_SLOW_IOACCESS */
1711 #ifdef VGA_ALT_SEQACCESS
1712 outw(TSIDX, 0x0100);
1714 outw(TSIDX, 0x0402);
1715 outw(TSIDX, 0x0704);
1716 #ifdef VGA_ALT_SEQACCESS
1717 outw(TSIDX, 0x0300);
1719 outw(GDCIDX, 0x0204);
1720 outw(GDCIDX, 0x0005);
1721 outw(GDCIDX, 0x0406); /* addr = a0000, 64kb */
1722 #endif /* VGA_SLOW_IOACCESS */
1728 set_normal_mode(video_adapter_t *adp, u_char *buf)
1734 /* setup vga for normal operation mode again */
1735 inb(adp->va_crtc_addr + 6); /* reset flip-flop */
1736 outb(ATC, 0x10); outb(ATC, buf[5]);
1737 inb(adp->va_crtc_addr + 6); /* reset flip-flop */
1738 outb(ATC, 0x20); /* enable palette */
1740 #if VGA_SLOW_IOACCESS
1741 #ifdef VGA_ALT_SEQACCESS
1742 outb(TSIDX, 0x00); outb(TSREG, 0x01);
1744 outb(TSIDX, 0x02); outb(TSREG, buf[0]);
1745 outb(TSIDX, 0x04); outb(TSREG, buf[1]);
1746 #ifdef VGA_ALT_SEQACCESS
1747 outb(TSIDX, 0x00); outb(TSREG, 0x03);
1749 outb(GDCIDX, 0x04); outb(GDCREG, buf[2]);
1750 outb(GDCIDX, 0x05); outb(GDCREG, buf[3]);
1751 if (adp->va_crtc_addr == MONO_CRTC) {
1752 outb(GDCIDX, 0x06); outb(GDCREG,(buf[4] & 0x03) | 0x08);
1754 outb(GDCIDX, 0x06); outb(GDCREG,(buf[4] & 0x03) | 0x0c);
1756 #else /* VGA_SLOW_IOACCESS */
1757 #ifdef VGA_ALT_SEQACCESS
1758 outw(TSIDX, 0x0100);
1760 outw(TSIDX, 0x0002 | (buf[0] << 8));
1761 outw(TSIDX, 0x0004 | (buf[1] << 8));
1762 #ifdef VGA_ALT_SEQACCESS
1763 outw(TSIDX, 0x0300);
1765 outw(GDCIDX, 0x0004 | (buf[2] << 8));
1766 outw(GDCIDX, 0x0005 | (buf[3] << 8));
1767 if (adp->va_crtc_addr == MONO_CRTC)
1768 outw(GDCIDX, 0x0006 | (((buf[4] & 0x03) | 0x08)<<8));
1770 outw(GDCIDX, 0x0006 | (((buf[4] & 0x03) | 0x0c)<<8));
1771 #endif /* VGA_SLOW_IOACCESS */
1776 #endif /* VGA_NO_FONT_LOADING */
1780 * Read the font data in the requested font page from the video adapter.
1785 vga_save_font(video_adapter_t *adp, int page, int fontsize, u_char *data,
1788 #ifndef VGA_NO_FONT_LOADING
1789 u_char buf[PARAM_BUFSIZE];
1792 #ifdef VGA_ALT_SEQACCESS
1797 prologue(adp, V_ADP_FONT, ENODEV);
1799 if (fontsize < 14) {
1802 } else if (fontsize >= 32) {
1804 } else if (fontsize >= 16) {
1812 if (page < 0 || page >= 8)
1814 segment = FONT_BUF + 0x4000*page;
1818 #ifdef VGA_ALT_SEQACCESS
1819 if (adp->va_type == KD_VGA) { /* what about EGA? XXX */
1821 outb(TSIDX, 0x00); outb(TSREG, 0x01);
1822 outb(TSIDX, 0x01); val = inb(TSREG); /* disable screen */
1823 outb(TSIDX, 0x01); outb(TSREG, val | 0x20);
1824 outb(TSIDX, 0x00); outb(TSREG, 0x03);
1829 set_font_mode(adp, buf);
1830 if (fontsize == 32) {
1831 bcopy_fromio(segment + ch*32, data, fontsize*count);
1833 for (c = ch; count > 0; ++c, --count) {
1834 bcopy_fromio(segment + c*32, data, fontsize);
1838 set_normal_mode(adp, buf);
1840 #ifdef VGA_ALT_SEQACCESS
1841 if (adp->va_type == KD_VGA) {
1843 outb(TSIDX, 0x00); outb(TSREG, 0x01);
1844 outb(TSIDX, 0x01); outb(TSREG, val & 0xdf); /* enable screen */
1845 outb(TSIDX, 0x00); outb(TSREG, 0x03);
1851 #else /* VGA_NO_FONT_LOADING */
1853 #endif /* VGA_NO_FONT_LOADING */
1858 * Set the font data in the requested font page.
1859 * NOTE: it appears that some recent video adapters do not support
1860 * the font page other than 0... XXX
1865 vga_load_font(video_adapter_t *adp, int page, int fontsize, u_char *data,
1868 #ifndef VGA_NO_FONT_LOADING
1869 u_char buf[PARAM_BUFSIZE];
1872 #ifdef VGA_ALT_SEQACCESS
1877 prologue(adp, V_ADP_FONT, ENODEV);
1879 if (fontsize < 14) {
1882 } else if (fontsize >= 32) {
1884 } else if (fontsize >= 16) {
1892 if (page < 0 || page >= 8)
1894 segment = FONT_BUF + 0x4000*page;
1898 #ifdef VGA_ALT_SEQACCESS
1899 if (adp->va_type == KD_VGA) { /* what about EGA? XXX */
1901 outb(TSIDX, 0x00); outb(TSREG, 0x01);
1902 outb(TSIDX, 0x01); val = inb(TSREG); /* disable screen */
1903 outb(TSIDX, 0x01); outb(TSREG, val | 0x20);
1904 outb(TSIDX, 0x00); outb(TSREG, 0x03);
1909 set_font_mode(adp, buf);
1910 if (fontsize == 32) {
1911 bcopy_toio(data, segment + ch*32, fontsize*count);
1913 for (c = ch; count > 0; ++c, --count) {
1914 bcopy_toio(data, segment + c*32, fontsize);
1918 set_normal_mode(adp, buf);
1920 #ifdef VGA_ALT_SEQACCESS
1921 if (adp->va_type == KD_VGA) {
1923 outb(TSIDX, 0x00); outb(TSREG, 0x01);
1924 outb(TSIDX, 0x01); outb(TSREG, val & 0xdf); /* enable screen */
1925 outb(TSIDX, 0x00); outb(TSREG, 0x03);
1931 #else /* VGA_NO_FONT_LOADING */
1933 #endif /* VGA_NO_FONT_LOADING */
1938 * Activate the requested font page.
1939 * NOTE: it appears that some recent video adapters do not support
1940 * the font page other than 0... XXX
1945 vga_show_font(video_adapter_t *adp, int page)
1947 #ifndef VGA_NO_FONT_LOADING
1948 static u_char cg[] = { 0x00, 0x05, 0x0a, 0x0f, 0x30, 0x35, 0x3a, 0x3f };
1951 prologue(adp, V_ADP_FONT, ENODEV);
1952 if (page < 0 || page >= 8)
1956 outb(TSIDX, 0x03); outb(TSREG, cg[page]);
1960 #else /* VGA_NO_FONT_LOADING */
1962 #endif /* VGA_NO_FONT_LOADING */
1967 * Read DAC values. The values have expressed in 8 bits.
1972 vga_save_palette(video_adapter_t *adp, u_char *palette)
1976 prologue(adp, V_ADP_PALETTE, ENODEV);
1979 * We store 8 bit values in the palette buffer, while the standard
1980 * VGA has 6 bit DAC .
1982 outb(PALRADR, 0x00);
1983 for (i = 0; i < 256*3; ++i)
1984 palette[i] = inb(PALDATA) << 2;
1985 inb(adp->va_crtc_addr + 6); /* reset flip/flop */
1990 vga_save_palette2(video_adapter_t *adp, int base, int count,
1991 u_char *r, u_char *g, u_char *b)
1995 prologue(adp, V_ADP_PALETTE, ENODEV);
1997 outb(PALRADR, base);
1998 for (i = 0; i < count; ++i) {
1999 r[i] = inb(PALDATA) << 2;
2000 g[i] = inb(PALDATA) << 2;
2001 b[i] = inb(PALDATA) << 2;
2003 inb(adp->va_crtc_addr + 6); /* reset flip/flop */
2014 vga_load_palette(video_adapter_t *adp, const u_char *palette)
2018 prologue(adp, V_ADP_PALETTE, ENODEV);
2020 outb(PIXMASK, 0xff); /* no pixelmask */
2021 outb(PALWADR, 0x00);
2022 for (i = 0; i < 256*3; ++i)
2023 outb(PALDATA, palette[i] >> 2);
2024 inb(adp->va_crtc_addr + 6); /* reset flip/flop */
2025 outb(ATC, 0x20); /* enable palette */
2030 vga_load_palette2(video_adapter_t *adp, int base, int count,
2031 u_char *r, u_char *g, u_char *b)
2035 prologue(adp, V_ADP_PALETTE, ENODEV);
2037 outb(PIXMASK, 0xff); /* no pixelmask */
2038 outb(PALWADR, base);
2039 for (i = 0; i < count; ++i) {
2040 outb(PALDATA, r[i] >> 2);
2041 outb(PALDATA, g[i] >> 2);
2042 outb(PALDATA, b[i] >> 2);
2044 inb(adp->va_crtc_addr + 6); /* reset flip/flop */
2045 outb(ATC, 0x20); /* enable palette */
2051 * Change the border color.
2056 vga_set_border(video_adapter_t *adp, int color)
2058 prologue(adp, V_ADP_BORDER, ENODEV);
2060 switch (adp->va_type) {
2063 inb(adp->va_crtc_addr + 6); /* reset flip-flop */
2064 outb(ATC, 0x31); outb(ATC, color & 0xff);
2067 outb(adp->va_crtc_addr + 5, color & 0x0f); /* color select register */
2079 * Read video register values.
2080 * NOTE: this function only reads the standard EGA/VGA registers.
2081 * any extra/extended registers of SVGA adapters are not saved.
2086 vga_save_state(video_adapter_t *adp, void *p, size_t size)
2095 /* return the required buffer size */
2096 prologue(adp, V_ADP_STATESAVE, 0);
2097 return sizeof(adp_state_t);
2099 prologue(adp, V_ADP_STATESAVE, ENODEV);
2100 if (size < sizeof(adp_state_t))
2104 ((adp_state_t *)p)->sig = V_STATE_SIG;
2105 buf = ((adp_state_t *)p)->regs;
2106 bzero(buf, V_MODE_PARAM_SIZE);
2107 crtc_addr = adp->va_crtc_addr;
2111 outb(TSIDX, 0x00); outb(TSREG, 0x01); /* stop sequencer */
2112 for (i = 0, j = 5; i < 4; i++) {
2114 buf[j++] = inb(TSREG);
2116 buf[9] = inb(MISC + 10); /* dot-clock */
2117 outb(TSIDX, 0x00); outb(TSREG, 0x03); /* start sequencer */
2119 for (i = 0, j = 10; i < 25; i++) { /* crtc */
2121 buf[j++] = inb(crtc_addr + 1);
2123 for (i = 0, j = 35; i < 20; i++) { /* attribute ctrl */
2124 inb(crtc_addr + 6); /* reset flip-flop */
2126 buf[j++] = inb(ATC + 1);
2128 for (i = 0, j = 55; i < 9; i++) { /* graph data ctrl */
2130 buf[j++] = inb(GDCREG);
2132 inb(crtc_addr + 6); /* reset flip-flop */
2133 outb(ATC, 0x20); /* enable palette */
2138 if (vga_get_info(adp, adp->va_mode, &info) == 0) {
2139 if (info.vi_flags & V_INFO_GRAPHICS) {
2140 buf[0] = info.vi_width/info.vi_cwidth; /* COLS */
2141 buf[1] = info.vi_height/info.vi_cheight - 1; /* ROWS */
2143 buf[0] = info.vi_width; /* COLS */
2144 buf[1] = info.vi_height - 1; /* ROWS */
2146 buf[2] = info.vi_cheight; /* POINTS */
2148 /* XXX: shouldn't be happening... */
2149 printf("vga%d: %s: failed to obtain mode info. (vga_save_state())\n",
2150 adp->va_unit, adp->va_name);
2153 buf[0] = readb(BIOS_PADDRTOVADDR(0x44a)); /* COLS */
2154 buf[1] = readb(BIOS_PADDRTOVADDR(0x484)); /* ROWS */
2155 buf[2] = readb(BIOS_PADDRTOVADDR(0x485)); /* POINTS */
2156 buf[3] = readb(BIOS_PADDRTOVADDR(0x44c));
2157 buf[4] = readb(BIOS_PADDRTOVADDR(0x44d));
2165 * Set video registers at once.
2166 * NOTE: this function only updates the standard EGA/VGA registers.
2167 * any extra/extended registers of SVGA adapters are not changed.
2172 vga_load_state(video_adapter_t *adp, void *p)
2179 prologue(adp, V_ADP_STATELOAD, ENODEV);
2180 if (((adp_state_t *)p)->sig != V_STATE_SIG)
2183 buf = ((adp_state_t *)p)->regs;
2184 crtc_addr = adp->va_crtc_addr;
2187 dump_buffer(buf, V_MODE_PARAM_SIZE);
2192 outb(TSIDX, 0x00); outb(TSREG, 0x01); /* stop sequencer */
2193 for (i = 0; i < 4; ++i) { /* program sequencer */
2195 outb(TSREG, buf[i + 5]);
2197 outb(MISC, buf[9]); /* set dot-clock */
2198 outb(TSIDX, 0x00); outb(TSREG, 0x03); /* start sequencer */
2199 outb(crtc_addr, 0x11);
2200 outb(crtc_addr + 1, inb(crtc_addr + 1) & 0x7F);
2201 for (i = 0; i < 25; ++i) { /* program crtc */
2203 outb(crtc_addr + 1, buf[i + 10]);
2205 inb(crtc_addr+6); /* reset flip-flop */
2206 for (i = 0; i < 20; ++i) { /* program attribute ctrl */
2208 outb(ATC, buf[i + 35]);
2210 for (i = 0; i < 9; ++i) { /* program graph data ctrl */
2212 outb(GDCREG, buf[i + 55]);
2214 inb(crtc_addr + 6); /* reset flip-flop */
2215 outb(ATC, 0x20); /* enable palette */
2217 #if notyet /* a temporary workaround for kernel panic, XXX */
2219 if (adp->va_unit == V_ADP_PRIMARY) {
2220 writeb(BIOS_PADDRTOVADDR(0x44a), buf[0]); /* COLS */
2221 writeb(BIOS_PADDRTOVADDR(0x484), buf[1] + rows_offset - 1); /* ROWS */
2222 writeb(BIOS_PADDRTOVADDR(0x485), buf[2]); /* POINTS */
2224 writeb(BIOS_PADDRTOVADDR(0x44c), buf[3]);
2225 writeb(BIOS_PADDRTOVADDR(0x44d), buf[4]);
2228 #endif /* VGA_NO_BIOS */
2237 * Change the origin (window mapping) of the banked frame buffer.
2240 vga_set_origin(video_adapter_t *adp, off_t offset)
2243 * The standard video modes do not require window mapping;
2244 * always return error.
2251 * Read the position of the hardware text cursor.
2256 vga_read_hw_cursor(video_adapter_t *adp, int *col, int *row)
2264 if (adp->va_info.vi_flags & V_INFO_GRAPHICS)
2268 outb(adp->va_crtc_addr, 14);
2269 off = inb(adp->va_crtc_addr + 1);
2270 outb(adp->va_crtc_addr, 15);
2271 off = (off << 8) | inb(adp->va_crtc_addr + 1);
2274 *row = off / adp->va_info.vi_width;
2275 *col = off % adp->va_info.vi_width;
2282 * Move the hardware text cursor. If col and row are both -1,
2283 * the cursor won't be shown.
2288 vga_set_hw_cursor(video_adapter_t *adp, int col, int row)
2296 if ((col == -1) && (row == -1)) {
2299 if (adp->va_info.vi_flags & V_INFO_GRAPHICS)
2301 off = row*adp->va_info.vi_width + col;
2305 outb(adp->va_crtc_addr, 14);
2306 outb(adp->va_crtc_addr + 1, off >> 8);
2307 outb(adp->va_crtc_addr, 15);
2308 outb(adp->va_crtc_addr + 1, off & 0x00ff);
2315 * set_hw_cursor_shape():
2316 * Change the shape of the hardware text cursor. If the height is
2317 * zero or negative, the cursor won't be shown.
2322 vga_set_hw_cursor_shape(video_adapter_t *adp, int base, int height,
2323 int celsize, int blink)
2331 switch (adp->va_type) {
2338 /* make the cursor invisible */
2339 outb(adp->va_crtc_addr, 10);
2340 outb(adp->va_crtc_addr + 1, 32);
2341 outb(adp->va_crtc_addr, 11);
2342 outb(adp->va_crtc_addr + 1, 0);
2344 outb(adp->va_crtc_addr, 10);
2345 outb(adp->va_crtc_addr + 1, celsize - base - height);
2346 outb(adp->va_crtc_addr, 11);
2347 outb(adp->va_crtc_addr + 1, celsize - base - 1);
2352 /* make the cursor invisible */
2353 outb(adp->va_crtc_addr, 10);
2354 outb(adp->va_crtc_addr + 1, celsize);
2355 outb(adp->va_crtc_addr, 11);
2356 outb(adp->va_crtc_addr + 1, 0);
2358 outb(adp->va_crtc_addr, 10);
2359 outb(adp->va_crtc_addr + 1, celsize - base - height);
2360 outb(adp->va_crtc_addr, 11);
2361 outb(adp->va_crtc_addr + 1, celsize - base);
2372 * Put the display in power save/power off mode.
2377 vga_blank_display(video_adapter_t *adp, int mode)
2383 switch (adp->va_type) {
2386 case V_DISPLAY_SUSPEND:
2387 case V_DISPLAY_STAND_BY:
2391 outb(TSREG, val | 0x20);
2392 outb(adp->va_crtc_addr, 0x17);
2393 val = inb(adp->va_crtc_addr + 1);
2394 outb(adp->va_crtc_addr + 1, val & ~0x80);
2396 case V_DISPLAY_BLANK:
2400 outb(TSREG, val | 0x20);
2406 outb(TSREG, val & 0xDF);
2407 outb(adp->va_crtc_addr, 0x17);
2408 val = inb(adp->va_crtc_addr + 1);
2409 outb(adp->va_crtc_addr + 1, val | 0x80);
2415 /* no support yet */
2421 case V_DISPLAY_SUSPEND:
2422 case V_DISPLAY_STAND_BY:
2423 case V_DISPLAY_BLANK:
2424 outb(adp->va_crtc_addr + 4, 0x25);
2427 outb(adp->va_crtc_addr + 4, 0x2d);
2435 case V_DISPLAY_SUSPEND:
2436 case V_DISPLAY_STAND_BY:
2437 case V_DISPLAY_BLANK:
2438 outb(adp->va_crtc_addr + 4, 0x21);
2441 outb(adp->va_crtc_addr + 4, 0x29);
2455 * Mmap frame buffer.
2460 vga_mmap_buf(video_adapter_t *adp, vm_offset_t offset, int prot)
2462 if (adp->va_info.vi_flags & V_INFO_LINEAR)
2466 printf("vga_mmap_buf(): window:0x%x, offset:0x%x\n",
2467 adp->va_info.vi_window, offset);
2470 /* XXX: is this correct? */
2471 if (offset > adp->va_window_size - PAGE_SIZE)
2475 return i386_btop(adp->va_info.vi_window + offset);
2478 return alpha_btop(adp->va_info.vi_window + offset);
2482 #ifndef VGA_NO_MODE_CHANGE
2485 planar_fill(video_adapter_t *adp, int val)
2488 int at; /* position in the frame buffer */
2491 outw(GDCIDX, 0x0005); /* read mode 0, write mode 0 */
2492 outw(GDCIDX, 0x0003); /* data rotate/function select */
2493 outw(GDCIDX, 0x0f01); /* set/reset enable */
2494 outw(GDCIDX, 0xff08); /* bit mask */
2495 outw(GDCIDX, (val << 8) | 0x00); /* set/reset */
2497 length = adp->va_line_width*adp->va_info.vi_height;
2498 while (length > 0) {
2499 l = imin(length, adp->va_window_size);
2500 (*vidsw[adp->va_index]->set_win_org)(adp, at);
2501 bzero_io(adp->va_window, l);
2505 outw(GDCIDX, 0x0000); /* set/reset */
2506 outw(GDCIDX, 0x0001); /* set/reset enable */
2510 packed_fill(video_adapter_t *adp, int val)
2513 int at; /* position in the frame buffer */
2517 length = adp->va_line_width*adp->va_info.vi_height;
2518 while (length > 0) {
2519 l = imin(length, adp->va_window_size);
2520 (*vidsw[adp->va_index]->set_win_org)(adp, at);
2521 fill_io(val, adp->va_window, l);
2528 direct_fill(video_adapter_t *adp, int val)
2531 int at; /* position in the frame buffer */
2535 length = adp->va_line_width*adp->va_info.vi_height;
2536 while (length > 0) {
2537 l = imin(length, adp->va_window_size);
2538 (*vidsw[adp->va_index]->set_win_org)(adp, at);
2539 switch (adp->va_info.vi_pixel_size) {
2540 case sizeof(u_int16_t):
2541 fillw_io(val, adp->va_window, l/sizeof(u_int16_t));
2546 case sizeof(u_int32_t):
2547 filll_io(val, adp->va_window, l/sizeof(u_int32_t));
2556 vga_clear(video_adapter_t *adp)
2558 switch (adp->va_info.vi_mem_model) {
2559 case V_INFO_MM_TEXT:
2560 /* do nothing? XXX */
2562 case V_INFO_MM_PLANAR:
2563 planar_fill(adp, 0);
2565 case V_INFO_MM_PACKED:
2566 packed_fill(adp, 0);
2568 case V_INFO_MM_DIRECT:
2569 direct_fill(adp, 0);
2577 planar_fill_rect(video_adapter_t *adp, int val, int x, int y, int cx, int cy)
2582 int offset; /* offset within window */
2586 outw(GDCIDX, 0x0005); /* read mode 0, write mode 0 */
2587 outw(GDCIDX, 0x0003); /* data rotate/function select */
2588 outw(GDCIDX, 0x0f01); /* set/reset enable */
2589 outw(GDCIDX, 0xff08); /* bit mask */
2590 outw(GDCIDX, (val << 8) | 0x00); /* set/reset */
2592 banksize = adp->va_window_size;
2595 pos = adp->va_line_width*y + x/8;
2596 if (bank != pos/banksize) {
2597 (*vidsw[adp->va_index]->set_win_org)(adp, pos);
2598 bank = pos/banksize;
2600 offset = pos%banksize;
2601 bx = (x + cx)/8 - x/8;
2603 outw(GDCIDX, ((0xff00 >> (x % 8)) & 0xff00) | 0x08);
2604 writeb(adp->va_window + offset, 0);
2607 if (offset >= banksize) {
2609 ++bank; /* next bank */
2610 (*vidsw[adp->va_index]->set_win_org)(adp, bank*banksize);
2612 outw(GDCIDX, 0xff08); /* bit mask */
2615 l = imin(bx, banksize);
2616 bzero_io(adp->va_window + offset, l);
2619 if (offset >= banksize) {
2621 ++bank; /* next bank */
2622 (*vidsw[adp->va_index]->set_win_org)(adp, bank*banksize);
2626 outw(GDCIDX, (~(0xff00 >> ((x + cx) % 8)) & 0xff00) | 0x08);
2627 writeb(adp->va_window + offset, 0);
2629 if (offset >= banksize) {
2631 ++bank; /* next bank */
2632 (*vidsw[adp->va_index]->set_win_org)(adp, bank*banksize);
2634 outw(GDCIDX, 0xff08); /* bit mask */
2640 outw(GDCIDX, 0xff08); /* bit mask */
2641 outw(GDCIDX, 0x0000); /* set/reset */
2642 outw(GDCIDX, 0x0001); /* set/reset enable */
2646 packed_fill_rect(video_adapter_t *adp, int val, int x, int y, int cx, int cy)
2651 int offset; /* offset within window */
2654 banksize = adp->va_window_size;
2656 cx *= adp->va_info.vi_pixel_size;
2658 pos = adp->va_line_width*y + x*adp->va_info.vi_pixel_size;
2659 if (bank != pos/banksize) {
2660 (*vidsw[adp->va_index]->set_win_org)(adp, pos);
2661 bank = pos/banksize;
2663 offset = pos%banksize;
2664 end = imin(offset + cx, banksize);
2665 fill_io(val, adp->va_window + offset,
2666 (end - offset)/adp->va_info.vi_pixel_size);
2667 /* the line may cross the window boundary */
2668 if (offset + cx > banksize) {
2669 ++bank; /* next bank */
2670 (*vidsw[adp->va_index]->set_win_org)(adp, bank*banksize);
2671 end = offset + cx - banksize;
2672 fill_io(val, adp->va_window, end/adp->va_info.vi_pixel_size);
2680 direct_fill_rect16(video_adapter_t *adp, int val, int x, int y, int cx, int cy)
2685 int offset; /* offset within window */
2689 * XXX: the function assumes that banksize is a muliple of
2690 * sizeof(u_int16_t).
2692 banksize = adp->va_window_size;
2694 cx *= sizeof(u_int16_t);
2696 pos = adp->va_line_width*y + x*sizeof(u_int16_t);
2697 if (bank != pos/banksize) {
2698 (*vidsw[adp->va_index]->set_win_org)(adp, pos);
2699 bank = pos/banksize;
2701 offset = pos%banksize;
2702 end = imin(offset + cx, banksize);
2703 fillw_io(val, adp->va_window + offset,
2704 (end - offset)/sizeof(u_int16_t));
2705 /* the line may cross the window boundary */
2706 if (offset + cx > banksize) {
2707 ++bank; /* next bank */
2708 (*vidsw[adp->va_index]->set_win_org)(adp, bank*banksize);
2709 end = offset + cx - banksize;
2710 fillw_io(val, adp->va_window, end/sizeof(u_int16_t));
2718 direct_fill_rect24(video_adapter_t *adp, int val, int x, int y, int cx, int cy)
2723 int offset; /* offset within window */
2729 b[0] = val & 0x0000ff;
2730 b[1] = (val >> 8) & 0x0000ff;
2731 b[2] = (val >> 16) & 0x0000ff;
2732 banksize = adp->va_window_size;
2736 pos = adp->va_line_width*y + x*3;
2737 if (bank != pos/banksize) {
2738 (*vidsw[adp->va_index]->set_win_org)(adp, pos);
2739 bank = pos/banksize;
2741 offset = pos%banksize;
2742 end = imin(offset + cx, banksize);
2743 for (i = 0, j = offset; j < end; i = (++i)%3, ++j) {
2744 writeb(adp->va_window + j, b[i]);
2746 /* the line may cross the window boundary */
2747 if (offset + cx >= banksize) {
2748 ++bank; /* next bank */
2749 (*vidsw[adp->va_index]->set_win_org)(adp, bank*banksize);
2751 end = offset + cx - banksize;
2752 for (; j < end; i = (++i)%3, ++j) {
2753 writeb(adp->va_window + j, b[i]);
2762 direct_fill_rect32(video_adapter_t *adp, int val, int x, int y, int cx, int cy)
2767 int offset; /* offset within window */
2771 * XXX: the function assumes that banksize is a muliple of
2772 * sizeof(u_int32_t).
2774 banksize = adp->va_window_size;
2776 cx *= sizeof(u_int32_t);
2778 pos = adp->va_line_width*y + x*sizeof(u_int32_t);
2779 if (bank != pos/banksize) {
2780 (*vidsw[adp->va_index]->set_win_org)(adp, pos);
2781 bank = pos/banksize;
2783 offset = pos%banksize;
2784 end = imin(offset + cx, banksize);
2785 filll_io(val, adp->va_window + offset,
2786 (end - offset)/sizeof(u_int32_t));
2787 /* the line may cross the window boundary */
2788 if (offset + cx > banksize) {
2789 ++bank; /* next bank */
2790 (*vidsw[adp->va_index]->set_win_org)(adp, bank*banksize);
2791 end = offset + cx - banksize;
2792 filll_io(val, adp->va_window, end/sizeof(u_int32_t));
2800 vga_fill_rect(video_adapter_t *adp, int val, int x, int y, int cx, int cy)
2802 switch (adp->va_info.vi_mem_model) {
2803 case V_INFO_MM_TEXT:
2804 /* do nothing? XXX */
2806 case V_INFO_MM_PLANAR:
2807 planar_fill_rect(adp, val, x, y, cx, cy);
2809 case V_INFO_MM_PACKED:
2810 packed_fill_rect(adp, val, x, y, cx, cy);
2812 case V_INFO_MM_DIRECT:
2813 switch (adp->va_info.vi_pixel_size) {
2814 case sizeof(u_int16_t):
2815 direct_fill_rect16(adp, val, x, y, cx, cy);
2818 direct_fill_rect24(adp, val, x, y, cx, cy);
2820 case sizeof(u_int32_t):
2821 direct_fill_rect32(adp, val, x, y, cx, cy);
2830 vga_fill_rect(video_adapter_t *adp, int val, int x, int y, int cx, int cy)
2837 vga_bitblt(video_adapter_t *adp,...)
2843 #endif /* !VGA_NO_MODE_CHANGE */
2846 get_palette(video_adapter_t *adp, int base, int count,
2847 u_char *red, u_char *green, u_char *blue, u_char *trans)
2853 if (base < 0 || base >= 256 || count < 0 || (u_int)(base + count) > 256)
2856 r = malloc(count*3, M_DEVBUF, M_WAITOK);
2859 if (vga_save_palette2(adp, base, count, r, g, b))
2861 copyout(r, red, count);
2862 copyout(g, green, count);
2863 copyout(b, blue, count);
2864 if (trans != NULL) {
2866 copyout(r, trans, count);
2874 set_palette(video_adapter_t *adp, int base, int count,
2875 u_char *red, u_char *green, u_char *blue, u_char *trans)
2882 if (base < 0 || base >= 256 || count < 0 || (u_int)(base + count) > 256)
2885 r = malloc(count*3, M_DEVBUF, M_WAITOK);
2888 copyin(red, r, count);
2889 copyin(green, g, count);
2890 copyin(blue, b, count);
2891 err = vga_load_palette2(adp, base, count, r, g, b);
2894 return (err ? ENODEV : 0);
2898 vga_dev_ioctl(video_adapter_t *adp, u_long cmd, caddr_t arg)
2901 case FBIO_GETWINORG: /* get frame buffer window origin */
2905 case FBIO_SETWINORG: /* set frame buffer window origin */
2908 case FBIO_SETDISPSTART: /* set display start address */
2909 return (set_display_start(adp,
2910 ((video_display_start_t *)arg)->x,
2911 ((video_display_start_t *)arg)->y)
2914 case FBIO_SETLINEWIDTH: /* set scan line length in pixel */
2915 return (set_line_length(adp, *(u_int *)arg) ? ENODEV : 0);
2917 case FBIO_GETPALETTE: /* get color palette */
2918 return get_palette(adp, ((video_color_palette_t *)arg)->index,
2919 ((video_color_palette_t *)arg)->count,
2920 ((video_color_palette_t *)arg)->red,
2921 ((video_color_palette_t *)arg)->green,
2922 ((video_color_palette_t *)arg)->blue,
2923 ((video_color_palette_t *)arg)->transparent);
2925 case FBIO_SETPALETTE: /* set color palette */
2926 return set_palette(adp, ((video_color_palette_t *)arg)->index,
2927 ((video_color_palette_t *)arg)->count,
2928 ((video_color_palette_t *)arg)->red,
2929 ((video_color_palette_t *)arg)->green,
2930 ((video_color_palette_t *)arg)->blue,
2931 ((video_color_palette_t *)arg)->transparent);
2933 case FBIOGTYPE: /* get frame buffer type info. */
2934 ((struct fbtype *)arg)->fb_type = fb_type(adp->va_type);
2935 ((struct fbtype *)arg)->fb_height = adp->va_info.vi_height;
2936 ((struct fbtype *)arg)->fb_width = adp->va_info.vi_width;
2937 ((struct fbtype *)arg)->fb_depth = adp->va_info.vi_depth;
2938 if ((adp->va_info.vi_depth <= 1) || (adp->va_info.vi_depth > 8))
2939 ((struct fbtype *)arg)->fb_cmsize = 0;
2941 ((struct fbtype *)arg)->fb_cmsize = 1 << adp->va_info.vi_depth;
2942 ((struct fbtype *)arg)->fb_size = adp->va_buffer_size;
2945 case FBIOGETCMAP: /* get color palette */
2946 return get_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);
2952 case FBIOPUTCMAP: /* set color palette */
2953 return set_palette(adp, ((struct fbcmap *)arg)->index,
2954 ((struct fbcmap *)arg)->count,
2955 ((struct fbcmap *)arg)->red,
2956 ((struct fbcmap *)arg)->green,
2957 ((struct fbcmap *)arg)->blue, NULL);
2960 return fb_commonioctl(adp, cmd, arg);
2965 dump_buffer(u_char *buf, size_t len)
2969 for(i = 0; i < len;) {
2970 printf("%02x ", buf[i]);
2971 if ((++i % 16) == 0)
2978 * Print some information about the video adapter and video modes,
2979 * with requested level of details.
2984 vga_diag(video_adapter_t *adp, int level)
2997 printf("vga: RTC equip. code:0x%02x, DCC code:0x%02x\n",
2998 rtcin(RTC_EQUIPMENT), readb(BIOS_PADDRTOVADDR(0x488)));
2999 printf("vga: CRTC:0x%x, video option:0x%02x, ",
3000 readw(BIOS_PADDRTOVADDR(0x463)),
3001 readb(BIOS_PADDRTOVADDR(0x487)));
3002 printf("rows:%d, cols:%d, font height:%d\n",
3003 readb(BIOS_PADDRTOVADDR(0x44a)),
3004 readb(BIOS_PADDRTOVADDR(0x484)) + 1,
3005 readb(BIOS_PADDRTOVADDR(0x485)));
3006 #endif /* VGA_NO_BIOS */
3007 #if !defined(VGA_NO_BIOS) && !defined(VGA_NO_MODE_CHANGE)
3008 printf("vga: param table EGA/VGA:%p", video_mode_ptr);
3009 printf(", CGA/MDA:%p\n", video_mode_ptr2);
3010 printf("vga: rows_offset:%d\n", rows_offset);
3012 #endif /* FB_DEBUG > 1 */
3014 fb_dump_adp_info(VGA_DRIVER_NAME, adp, level);
3017 if (adp->va_flags & V_ADP_MODECHANGE) {
3018 for (i = 0; bios_vmode[i].vi_mode != EOT; ++i) {
3019 if (bios_vmode[i].vi_mode == NA)
3021 if (get_mode_param(bios_vmode[i].vi_mode) == NULL)
3023 fb_dump_mode_info(VGA_DRIVER_NAME, adp, &bios_vmode[i], level);
3026 vga_get_info(adp, adp->va_initial_mode, &info); /* shouldn't fail */
3027 fb_dump_mode_info(VGA_DRIVER_NAME, adp, &info, level);
3029 #endif /* FB_DEBUG > 1 */
3031 if ((adp->va_type != KD_EGA) && (adp->va_type != KD_VGA))
3033 #if !defined(VGA_NO_BIOS) && !defined(VGA_NO_MODE_CHANGE)
3034 if (video_mode_ptr == NULL)
3035 printf("vga%d: %s: WARNING: video mode switching is not "
3036 "fully supported on this adapter\n",
3037 adp->va_unit, adp->va_name);
3042 if (adp->va_type == KD_VGA) {
3043 printf("VGA parameters upon power-up\n");
3044 dump_buffer(adpstate.regs, sizeof(adpstate.regs));
3045 printf("VGA parameters in BIOS for mode %d\n", adp->va_initial_mode);
3046 dump_buffer(adpstate2.regs, sizeof(adpstate2.regs));
3049 mp = get_mode_param(adp->va_initial_mode);
3050 if (mp == NULL) /* this shouldn't be happening */
3052 printf("EGA/VGA parameters to be used for mode %d\n", adp->va_initial_mode);
3053 dump_buffer(mp, V_MODE_PARAM_SIZE);