2 * SPDX-License-Identifier: BSD-3-Clause
4 * Copyright (c) 1999 Kazutaka YOKOTA <yokota@zodiac.mech.utsunomiya-u.ac.jp>
5 * Copyright (c) 1992-1998 Søren Schmidt
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer as
13 * the first lines of this file unmodified.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 * 3. The name of the author may not be used to endorse or promote products
18 * derived from this software without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
21 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
22 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
23 * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
24 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
25 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
29 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 #include <sys/cdefs.h>
34 __FBSDID("$FreeBSD$");
41 #include "opt_syscons.h" /* should be removed in the future, XXX */
43 #include <sys/param.h>
44 #include <sys/systm.h>
45 #include <sys/kernel.h>
47 #include <sys/fcntl.h>
48 #include <sys/malloc.h>
52 #include <vm/vm_param.h>
55 #include <machine/md_var.h>
56 #if defined(__i386__) || defined(__amd64__)
57 #include <machine/pc/bios.h>
59 #include <machine/bus.h>
61 #include <dev/fb/fbreg.h>
62 #include <dev/fb/vgareg.h>
64 #include <isa/isareg.h>
70 /* XXX machine/pc/bios.h has got too much i386-specific stuff in it */
71 #ifndef BIOS_PADDRTOVADDR
72 #define BIOS_PADDRTOVADDR(x) (x)
76 vga_probe_unit(int unit, video_adapter_t *buf, int flags)
82 sw = vid_get_switch(VGA_DRIVER_NAME);
85 error = (*sw->probe)(unit, &adp, NULL, flags);
88 bcopy(adp, buf, sizeof(*buf));
93 vga_attach_unit(int unit, vga_softc_t *sc, int flags)
98 sw = vid_get_switch(VGA_DRIVER_NAME);
102 error = (*sw->probe)(unit, &sc->adp, NULL, flags);
105 return (*sw->init)(unit, sc->adp, flags);
112 #include <dev/fb/vesa.h>
115 #define probe_done(adp) ((adp)->va_flags & V_ADP_PROBED)
116 #define init_done(adp) ((adp)->va_flags & V_ADP_INITIALIZED)
117 #define config_done(adp) ((adp)->va_flags & V_ADP_REGISTERED)
119 /* for compatibility with old kernel options */
120 #ifdef SC_ALT_SEQACCESS
121 #undef SC_ALT_SEQACCESS
122 #undef VGA_ALT_SEQACCESS
123 #define VGA_ALT_SEQACCESS 1
128 #undef VGA_SLOW_IOACCESS
129 #define VGA_SLOW_IOACCESS
132 /* architecture dependent option */
133 #if !defined(__i386__) && !defined(__amd64__)
134 #define VGA_NO_BIOS 1
137 /* this should really be in `rtc.h' */
138 #define RTC_EQUIPMENT 0x14
141 #define V_MODE_MAP_SIZE (M_VGA_CG320 + 1)
142 #define V_MODE_PARAM_SIZE 64
144 /* video adapter state buffer */
147 #define V_STATE_SIG 0x736f6962
148 u_char regs[V_MODE_PARAM_SIZE];
150 typedef struct adp_state adp_state_t;
152 /* video adapter information */
156 #define DCC_EGAMONO 3
161 * NOTE: `va_window' should have a virtual address, but is initialized
162 * with a physical address in the following table, as verify_adapter()
163 * will perform address conversion at run-time.
165 static video_adapter_t adapter_init_value[] = {
167 { 0, KD_MONO, "mda", 0, 0, 0, IO_MDA, IO_MDASIZE, MONO_CRTC,
168 MDA_BUF_BASE, MDA_BUF_SIZE, MDA_BUF_BASE, MDA_BUF_SIZE, MDA_BUF_SIZE,
171 { 0, KD_CGA, "cga", 0, 0, V_ADP_COLOR, IO_CGA, IO_CGASIZE, COLOR_CRTC,
172 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE,
175 { 0, KD_CGA, "cga", 0, 0, V_ADP_COLOR, IO_CGA, IO_CGASIZE, COLOR_CRTC,
176 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE,
179 { 0, KD_EGA, "ega", 0, 0, 0, IO_MDA, 48, MONO_CRTC,
180 EGA_BUF_BASE, EGA_BUF_SIZE, MDA_BUF_BASE, MDA_BUF_SIZE, MDA_BUF_SIZE,
183 { 0, KD_EGA, "ega", 0, 0, V_ADP_COLOR, IO_MDA, 48, COLOR_CRTC,
184 EGA_BUF_BASE, EGA_BUF_SIZE, CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE,
187 { 0, KD_EGA, "ega", 0, 0, V_ADP_COLOR, IO_MDA, 48, COLOR_CRTC,
188 EGA_BUF_BASE, EGA_BUF_SIZE, CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE,
192 static video_adapter_t biosadapter[2];
193 static int biosadapters = 0;
195 /* video driver declarations */
196 static int vga_configure(int flags);
197 int (*vga_sub_configure)(int flags);
199 static int vga_nop(void);
201 static int vga_error(void);
202 static vi_probe_t vga_probe;
203 static vi_init_t vga_init;
204 static vi_get_info_t vga_get_info;
205 static vi_query_mode_t vga_query_mode;
206 static vi_set_mode_t vga_set_mode;
207 static vi_save_font_t vga_save_font;
208 static vi_load_font_t vga_load_font;
209 static vi_show_font_t vga_show_font;
210 static vi_save_palette_t vga_save_palette;
211 static vi_load_palette_t vga_load_palette;
212 static vi_set_border_t vga_set_border;
213 static vi_save_state_t vga_save_state;
214 static vi_load_state_t vga_load_state;
215 static vi_set_win_org_t vga_set_origin;
216 static vi_read_hw_cursor_t vga_read_hw_cursor;
217 static vi_set_hw_cursor_t vga_set_hw_cursor;
218 static vi_set_hw_cursor_shape_t vga_set_hw_cursor_shape;
219 static vi_blank_display_t vga_blank_display;
220 static vi_mmap_t vga_mmap_buf;
221 static vi_ioctl_t vga_dev_ioctl;
222 #ifndef VGA_NO_MODE_CHANGE
223 static vi_clear_t vga_clear;
224 static vi_fill_rect_t vga_fill_rect;
225 static vi_bitblt_t vga_bitblt;
226 #else /* VGA_NO_MODE_CHANGE */
227 #define vga_clear (vi_clear_t *)vga_error
228 #define vga_fill_rect (vi_fill_rect_t *)vga_error
229 #define vga_bitblt (vi_bitblt_t *)vga_error
231 static vi_diag_t vga_diag;
233 static video_switch_t vgavidsw = {
250 vga_set_hw_cursor_shape,
262 VIDEO_DRIVER(mda, vgavidsw, NULL);
263 VIDEO_DRIVER(cga, vgavidsw, NULL);
264 VIDEO_DRIVER(ega, vgavidsw, NULL);
265 VIDEO_DRIVER(vga, vgavidsw, vga_configure);
267 /* VGA BIOS standard video modes */
271 static video_info_t bios_vmode[] = {
273 { M_B40x25, V_INFO_COLOR, 40, 25, 8, 8, 2, 1,
274 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
275 { M_C40x25, V_INFO_COLOR, 40, 25, 8, 8, 4, 1,
276 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
277 { M_B80x25, V_INFO_COLOR, 80, 25, 8, 8, 2, 1,
278 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
279 { M_C80x25, V_INFO_COLOR, 80, 25, 8, 8, 4, 1,
280 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
282 { M_ENH_B40x25, V_INFO_COLOR, 40, 25, 8, 14, 2, 1,
283 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
284 { M_ENH_C40x25, V_INFO_COLOR, 40, 25, 8, 14, 4, 1,
285 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
286 { M_ENH_B80x25, V_INFO_COLOR, 80, 25, 8, 14, 2, 1,
287 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
288 { M_ENH_C80x25, V_INFO_COLOR, 80, 25, 8, 14, 4, 1,
289 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
291 { M_VGA_C40x25, V_INFO_COLOR, 40, 25, 8, 16, 4, 1,
292 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
293 { M_VGA_M80x25, 0, 80, 25, 8, 16, 2, 1,
294 MDA_BUF_BASE, MDA_BUF_SIZE, MDA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
295 { M_VGA_C80x25, V_INFO_COLOR, 80, 25, 8, 16, 4, 1,
296 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
298 { M_EGAMONO80x25, 0, 80, 25, 8, 14, 2, 1,
299 MDA_BUF_BASE, MDA_BUF_SIZE, MDA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
301 { M_ENH_B80x43, V_INFO_COLOR, 80, 43, 8, 8, 2, 1,
302 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
303 { M_ENH_C80x43, V_INFO_COLOR, 80, 43, 8, 8, 4, 1,
304 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
306 { M_VGA_M80x30, 0, 80, 30, 8, 16, 2, 1,
307 MDA_BUF_BASE, MDA_BUF_SIZE, MDA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
308 { M_VGA_C80x30, V_INFO_COLOR, 80, 30, 8, 16, 4, 1,
309 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
310 { M_VGA_M80x50, 0, 80, 50, 8, 8, 2, 1,
311 MDA_BUF_BASE, MDA_BUF_SIZE, MDA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
312 { M_VGA_C80x50, V_INFO_COLOR, 80, 50, 8, 8, 4, 1,
313 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
314 { M_VGA_M80x60, 0, 80, 60, 8, 8, 2, 1,
315 MDA_BUF_BASE, MDA_BUF_SIZE, MDA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
316 { M_VGA_C80x60, V_INFO_COLOR, 80, 60, 8, 8, 4, 1,
317 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
319 #ifndef VGA_NO_MODE_CHANGE
322 { M_VGA_M90x25, 0, 90, 25, 8, 16, 2, 1,
323 MDA_BUF_BASE, MDA_BUF_SIZE, MDA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
324 { M_VGA_C90x25, V_INFO_COLOR, 90, 25, 8, 16, 4, 1,
325 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
326 { M_VGA_M90x30, 0, 90, 30, 8, 16, 2, 1,
327 MDA_BUF_BASE, MDA_BUF_SIZE, MDA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
328 { M_VGA_C90x30, V_INFO_COLOR, 90, 30, 8, 16, 4, 1,
329 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
330 { M_VGA_M90x43, 0, 90, 43, 8, 8, 2, 1,
331 MDA_BUF_BASE, MDA_BUF_SIZE, MDA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
332 { M_VGA_C90x43, V_INFO_COLOR, 90, 43, 8, 8, 4, 1,
333 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
334 { M_VGA_M90x50, 0, 90, 50, 8, 8, 2, 1,
335 MDA_BUF_BASE, MDA_BUF_SIZE, MDA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
336 { M_VGA_C90x50, V_INFO_COLOR, 90, 50, 8, 8, 4, 1,
337 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
338 { M_VGA_M90x60, 0, 90, 60, 8, 8, 2, 1,
339 MDA_BUF_BASE, MDA_BUF_SIZE, MDA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
340 { M_VGA_C90x60, V_INFO_COLOR, 90, 60, 8, 8, 4, 1,
341 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
342 #endif /* VGA_WIDTH90 */
345 { M_BG320, V_INFO_COLOR | V_INFO_GRAPHICS, 320, 200, 8, 8, 2, 1,
346 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_CGA },
347 { M_CG320, V_INFO_COLOR | V_INFO_GRAPHICS, 320, 200, 8, 8, 2, 1,
348 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_CGA },
349 { M_BG640, V_INFO_COLOR | V_INFO_GRAPHICS, 640, 200, 8, 8, 1, 1,
350 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_CGA },
352 { M_CG320_D, V_INFO_COLOR | V_INFO_GRAPHICS, 320, 200, 8, 8, 4, 4,
353 GRAPHICS_BUF_BASE, GRAPHICS_BUF_SIZE, GRAPHICS_BUF_SIZE, 0, 0,
355 { M_CG640_E, V_INFO_COLOR | V_INFO_GRAPHICS, 640, 200, 8, 8, 4, 4,
356 GRAPHICS_BUF_BASE, GRAPHICS_BUF_SIZE, GRAPHICS_BUF_SIZE, 0, 0 ,
358 { M_EGAMONOAPA, V_INFO_GRAPHICS, 640, 350, 8, 14, 4, 4,
359 GRAPHICS_BUF_BASE, GRAPHICS_BUF_SIZE, 64*1024, 0, 0 ,
361 { M_ENHMONOAPA2,V_INFO_GRAPHICS, 640, 350, 8, 14, 4, 4,
362 GRAPHICS_BUF_BASE, GRAPHICS_BUF_SIZE, GRAPHICS_BUF_SIZE, 0, 0 ,
364 { M_CG640x350, V_INFO_COLOR | V_INFO_GRAPHICS, 640, 350, 8, 14, 2, 2,
365 GRAPHICS_BUF_BASE, GRAPHICS_BUF_SIZE, GRAPHICS_BUF_SIZE, 0, 0 ,
367 { M_ENH_CG640, V_INFO_COLOR | V_INFO_GRAPHICS, 640, 350, 8, 14, 4, 4,
368 GRAPHICS_BUF_BASE, GRAPHICS_BUF_SIZE, GRAPHICS_BUF_SIZE, 0, 0 ,
371 { M_BG640x480, V_INFO_COLOR | V_INFO_GRAPHICS, 640, 480, 8, 16, 4, 4,
372 GRAPHICS_BUF_BASE, GRAPHICS_BUF_SIZE, GRAPHICS_BUF_SIZE, 0, 0 ,
374 { M_CG640x480, V_INFO_COLOR | V_INFO_GRAPHICS, 640, 480, 8, 16, 4, 4,
375 GRAPHICS_BUF_BASE, GRAPHICS_BUF_SIZE, GRAPHICS_BUF_SIZE, 0, 0 ,
377 { M_VGA_CG320, V_INFO_COLOR | V_INFO_GRAPHICS, 320, 200, 8, 8, 8, 1,
378 GRAPHICS_BUF_BASE, GRAPHICS_BUF_SIZE, GRAPHICS_BUF_SIZE, 0, 0,
379 V_INFO_MM_PACKED, 1 },
380 { M_VGA_MODEX, V_INFO_COLOR | V_INFO_GRAPHICS, 320, 240, 8, 8, 8, 4,
381 GRAPHICS_BUF_BASE, GRAPHICS_BUF_SIZE, GRAPHICS_BUF_SIZE, 0, 0,
383 #endif /* VGA_NO_MODE_CHANGE */
388 static int vga_init_done = FALSE;
389 #if !defined(VGA_NO_BIOS) && !defined(VGA_NO_MODE_CHANGE)
390 static u_char *video_mode_ptr = NULL; /* EGA/VGA */
391 static u_char *video_mode_ptr2 = NULL; /* CGA/MDA */
393 static u_char *mode_map[V_MODE_MAP_SIZE];
394 static adp_state_t adpstate;
395 static adp_state_t adpstate2;
396 static int rows_offset = 1;
398 /* local macros and functions */
399 #define BIOS_SADDRTOLADDR(p) ((((p) & 0xffff0000) >> 12) + ((p) & 0x0000ffff))
401 #if !defined(VGA_NO_BIOS) && !defined(VGA_NO_MODE_CHANGE)
402 static void map_mode_table(u_char *map[], u_char *table, int max);
404 static void clear_mode_map(video_adapter_t *adp, u_char *map[], int max,
406 #if !defined(VGA_NO_BIOS) && !defined(VGA_NO_MODE_CHANGE)
407 static int map_mode_num(int mode);
409 static int map_gen_mode_num(int type, int color, int mode);
410 static int map_bios_mode_num(int type, int color, int bios_mode);
411 static u_char *get_mode_param(int mode);
413 static void fill_adapter_param(int code, video_adapter_t *adp);
415 static int verify_adapter(video_adapter_t *adp);
416 static void update_adapter_info(video_adapter_t *adp, video_info_t *info);
417 #if !defined(VGA_NO_BIOS) && !defined(VGA_NO_MODE_CHANGE)
418 #define COMP_IDENTICAL 0
419 #define COMP_SIMILAR 1
420 #define COMP_DIFFERENT 2
421 static int comp_adpregs(u_char *buf1, u_char *buf2);
423 static int probe_adapters(void);
424 static int set_line_length(video_adapter_t *adp, int pixel);
425 static int set_display_start(video_adapter_t *adp, int x, int y);
427 #ifndef VGA_NO_MODE_CHANGE
429 static void set_width90(adp_state_t *params);
431 #endif /* !VGA_NO_MODE_CHANGE */
433 #ifndef VGA_NO_FONT_LOADING
434 #define PARAM_BUFSIZE 6
435 static void set_font_mode(video_adapter_t *adp, u_char *buf);
436 static void set_normal_mode(video_adapter_t *adp, u_char *buf);
439 #ifndef VGA_NO_MODE_CHANGE
440 static void filll_io(int val, vm_offset_t d, size_t size);
441 static void planar_fill(video_adapter_t *adp, int val);
442 static void packed_fill(video_adapter_t *adp, int val);
443 static void direct_fill(video_adapter_t *adp, int val);
445 static void planar_fill_rect(video_adapter_t *adp, int val, int x, int y,
447 static void packed_fill_rect(video_adapter_t *adp, int val, int x, int y,
449 static void direct_fill_rect16(video_adapter_t *adp, int val, int x, int y,
451 static void direct_fill_rect24(video_adapter_t *adp, int val, int x, int y,
453 static void direct_fill_rect32(video_adapter_t *adp, int val, int x, int y,
456 #endif /* !VGA_NO_MODE_CHANGE */
458 static void dump_buffer(u_char *buf, size_t len);
460 #define ISMAPPED(pa, width) \
461 (((pa) <= (u_long)0x1000 - (width)) \
462 || ((pa) >= ISA_HOLE_START && (pa) <= 0x100000 - (width)))
464 #define prologue(adp, flag, err) \
465 if (!vga_init_done || !((adp)->va_flags & (flag))) \
468 /* a backdoor for the console driver */
470 vga_configure(int flags)
475 for (i = 0; i < biosadapters; ++i) {
476 if (!probe_done(&biosadapter[i]))
478 biosadapter[i].va_flags |= V_ADP_INITIALIZED;
479 if (!config_done(&biosadapter[i])) {
480 if (vid_register(&biosadapter[i]) < 0)
482 biosadapter[i].va_flags |= V_ADP_REGISTERED;
485 if (vga_sub_configure != NULL)
486 (*vga_sub_configure)(flags);
491 /* local subroutines */
493 #if !defined(VGA_NO_BIOS) && !defined(VGA_NO_MODE_CHANGE)
494 /* construct the mode parameter map */
496 map_mode_table(u_char *map[], u_char *table, int max)
500 for(i = 0; i < max; ++i)
501 map[i] = table + i*V_MODE_PARAM_SIZE;
502 for(; i < V_MODE_MAP_SIZE; ++i)
505 #endif /* !VGA_NO_BIOS && !VGA_NO_MODE_CHANGE */
508 clear_mode_map(video_adapter_t *adp, u_char *map[], int max, int color)
514 * NOTE: we don't touch `bios_vmode[]' because it is shared
517 for(i = 0; i < max; ++i) {
518 if (vga_get_info(adp, i, &info))
520 if ((info.vi_flags & V_INFO_COLOR) != color)
525 #if !defined(VGA_NO_BIOS) && !defined(VGA_NO_MODE_CHANGE)
526 /* map the non-standard video mode to a known mode number */
528 map_mode_num(int mode)
534 { M_ENH_B80x43, M_ENH_B80x25 },
535 { M_ENH_C80x43, M_ENH_C80x25 },
536 { M_VGA_M80x30, M_VGA_M80x25 },
537 { M_VGA_C80x30, M_VGA_C80x25 },
538 { M_VGA_M80x50, M_VGA_M80x25 },
539 { M_VGA_C80x50, M_VGA_C80x25 },
540 { M_VGA_M80x60, M_VGA_M80x25 },
541 { M_VGA_C80x60, M_VGA_C80x25 },
543 { M_VGA_M90x25, M_VGA_M80x25 },
544 { M_VGA_C90x25, M_VGA_C80x25 },
545 { M_VGA_M90x30, M_VGA_M80x25 },
546 { M_VGA_C90x30, M_VGA_C80x25 },
547 { M_VGA_M90x43, M_VGA_M80x25 },
548 { M_VGA_C90x43, M_ENH_C80x25 },
549 { M_VGA_M90x50, M_VGA_M80x25 },
550 { M_VGA_C90x50, M_VGA_C80x25 },
551 { M_VGA_M90x60, M_VGA_M80x25 },
552 { M_VGA_C90x60, M_VGA_C80x25 },
554 { M_VGA_MODEX, M_VGA_CG320 },
558 for (i = 0; i < nitems(mode_map); ++i) {
559 if (mode_map[i].from == mode)
560 return mode_map[i].to;
564 #endif /* !VGA_NO_BIOS && !VGA_NO_MODE_CHANGE */
566 /* map a generic video mode to a known mode number */
568 map_gen_mode_num(int type, int color, int mode)
575 { M_TEXT_80x30, M_VGA_C80x30, M_VGA_M80x30, },
576 { M_TEXT_80x43, M_ENH_C80x43, M_ENH_B80x43, },
577 { M_TEXT_80x50, M_VGA_C80x50, M_VGA_M80x50, },
578 { M_TEXT_80x60, M_VGA_C80x60, M_VGA_M80x60, },
582 if (mode == M_TEXT_80x25) {
596 return M_EGAMONO80x25;
604 return M_EGAMONO80x25; /* XXX: this name is confusing */
611 for (i = 0; i < nitems(mode_map); ++i) {
612 if (mode_map[i].from == mode)
613 return ((color) ? mode_map[i].to_color : mode_map[i].to_mono);
618 /* turn the BIOS video number into our video mode number */
620 map_bios_mode_num(int type, int color, int bios_mode)
622 static int cga_modes[7] = {
623 M_B40x25, M_C40x25, /* 0, 1 */
624 M_B80x25, M_C80x25, /* 2, 3 */
628 static int ega_modes[17] = {
629 M_ENH_B40x25, M_ENH_C40x25, /* 0, 1 */
630 M_ENH_B80x25, M_ENH_C80x25, /* 2, 3 */
633 M_EGAMONO80x25, /* 7 */
637 M_ENHMONOAPA2, /* XXX: video momery > 64K */
638 M_ENH_CG640, /* XXX: video momery > 64K */
640 static int vga_modes[20] = {
641 M_VGA_C40x25, M_VGA_C40x25, /* 0, 1 */
642 M_VGA_C80x25, M_VGA_C80x25, /* 2, 3 */
645 M_VGA_M80x25, /* 7 */
651 M_BG640x480, M_CG640x480,
658 if (bios_mode < nitems(vga_modes))
659 return vga_modes[bios_mode];
667 if (bios_mode < nitems(ega_modes))
668 return ega_modes[bios_mode];
672 return M_EGAMONO80x25;
676 if (bios_mode < nitems(cga_modes))
677 return cga_modes[bios_mode];
684 return M_EGAMONO80x25; /* XXX: this name is confusing */
692 /* look up a parameter table entry */
694 *get_mode_param(int mode)
696 #if !defined(VGA_NO_BIOS) && !defined(VGA_NO_MODE_CHANGE)
697 if (mode >= V_MODE_MAP_SIZE)
698 mode = map_mode_num(mode);
700 if ((mode >= 0) && (mode < V_MODE_MAP_SIZE))
701 return mode_map[mode];
708 fill_adapter_param(int code, video_adapter_t *adp)
714 { DCC_MONO, DCC_EGA40 /* CGA monitor */ },
715 { DCC_MONO, DCC_EGA80 /* CGA monitor */ },
716 { DCC_MONO, DCC_EGA80 },
717 { DCC_MONO, DCC_EGA80 },
718 { DCC_CGA40, DCC_EGAMONO },
719 { DCC_CGA80, DCC_EGAMONO },
720 { DCC_EGA40 /* CGA monitor */, DCC_MONO},
721 { DCC_EGA80 /* CGA monitor */, DCC_MONO},
722 { DCC_EGA80, DCC_MONO },
723 { DCC_EGA80, DCC_MONO },
724 { DCC_EGAMONO, DCC_CGA40 },
725 { DCC_EGAMONO, DCC_CGA80 },
728 if ((code < 0) || (code >= nitems(dcc))) {
729 adp[V_ADP_PRIMARY] = adapter_init_value[DCC_MONO];
730 adp[V_ADP_SECONDARY] = adapter_init_value[DCC_CGA80];
732 adp[V_ADP_PRIMARY] = adapter_init_value[dcc[code].primary];
733 adp[V_ADP_SECONDARY] = adapter_init_value[dcc[code].secondary];
736 #endif /* VGA_NO_BIOS */
739 verify_adapter(video_adapter_t *adp)
743 #if !defined(VGA_NO_BIOS) && !defined(VGA_NO_MODE_CHANGE)
747 buf = BIOS_PADDRTOVADDR(adp->va_window);
750 if (readw(buf) != 0xA55A)
754 switch (adp->va_type) {
757 outb(adp->va_crtc_addr, 7);
758 if (inb(adp->va_crtc_addr) == 7) {
759 adp->va_type = KD_VGA;
760 adp->va_name = "vga";
761 adp->va_flags |= V_ADP_STATESAVE | V_ADP_PALETTE;
763 adp->va_flags |= V_ADP_STATELOAD | V_ADP_BORDER;
764 /* the color adapter may be in the 40x25 mode... XXX */
766 #if !defined(VGA_NO_BIOS) && !defined(VGA_NO_MODE_CHANGE)
767 /* get the BIOS video mode pointer */
768 p = *(u_int32_t *)BIOS_PADDRTOVADDR(0x4a8);
769 p = BIOS_SADDRTOLADDR(p);
770 if (ISMAPPED(p, sizeof(u_int32_t))) {
771 p = *(u_int32_t *)BIOS_PADDRTOVADDR(p);
772 p = BIOS_SADDRTOLADDR(p);
773 if (ISMAPPED(p, V_MODE_PARAM_SIZE))
774 video_mode_ptr = (u_char *)BIOS_PADDRTOVADDR(p);
780 adp->va_flags |= V_ADP_COLOR | V_ADP_BORDER;
781 /* may be in the 40x25 mode... XXX */
782 #if !defined(VGA_NO_BIOS) && !defined(VGA_NO_MODE_CHANGE)
783 /* get the BIOS video mode pointer */
784 p = *(u_int32_t *)BIOS_PADDRTOVADDR(0x1d*4);
785 p = BIOS_SADDRTOLADDR(p);
786 video_mode_ptr2 = (u_char *)BIOS_PADDRTOVADDR(p);
791 #if !defined(VGA_NO_BIOS) && !defined(VGA_NO_MODE_CHANGE)
792 /* get the BIOS video mode pointer */
793 p = *(u_int32_t *)BIOS_PADDRTOVADDR(0x1d*4);
794 p = BIOS_SADDRTOLADDR(p);
795 video_mode_ptr2 = (u_char *)BIOS_PADDRTOVADDR(p);
804 update_adapter_info(video_adapter_t *adp, video_info_t *info)
806 adp->va_flags &= ~V_ADP_COLOR;
808 (info->vi_flags & V_INFO_COLOR) ? V_ADP_COLOR : 0;
810 (adp->va_flags & V_ADP_COLOR) ? COLOR_CRTC : MONO_CRTC;
811 adp->va_window = BIOS_PADDRTOVADDR(info->vi_window);
812 adp->va_window_size = info->vi_window_size;
813 adp->va_window_gran = info->vi_window_gran;
814 adp->va_window_orig = 0;
816 adp->va_buffer = info->vi_buffer;
817 adp->va_buffer_size = info->vi_buffer_size;
818 adp->va_flags &= ~V_ADP_CWIDTH9;
819 if (info->vi_flags & V_INFO_CWIDTH9)
820 adp->va_flags |= V_ADP_CWIDTH9;
821 if (info->vi_mem_model == V_INFO_MM_VGAX) {
822 adp->va_line_width = info->vi_width/2;
823 } else if (info->vi_flags & V_INFO_GRAPHICS) {
824 switch (info->vi_depth/info->vi_planes) {
826 adp->va_line_width = info->vi_width/8;
829 adp->va_line_width = info->vi_width/4;
832 adp->va_line_width = info->vi_width/2;
835 default: /* shouldn't happen */
836 adp->va_line_width = info->vi_width;
840 adp->va_line_width = info->vi_width;
842 adp->va_disp_start.x = 0;
843 adp->va_disp_start.y = 0;
844 bcopy(info, &adp->va_info, sizeof(adp->va_info));
847 #if !defined(VGA_NO_BIOS) && !defined(VGA_NO_MODE_CHANGE)
848 /* compare two parameter table entries */
850 comp_adpregs(u_char *buf1, u_char *buf2)
854 } params[V_MODE_PARAM_SIZE] = {
855 {0xff}, {0x00}, {0xff}, /* COLS}, ROWS}, POINTS */
856 {0x00}, {0x00}, /* page length */
857 {0xfe}, {0xff}, {0xff}, {0xff}, /* sequencer registers */
858 {0xf3}, /* misc register */
859 {0xff}, {0xff}, {0xff}, {0x7f}, {0xff}, /* CRTC */
860 {0xff}, {0xff}, {0xff}, {0x7f}, {0xff},
861 {0x00}, {0x00}, {0x00}, {0x00}, {0x00},
862 {0x00}, {0xff}, {0x7f}, {0xff}, {0xff},
863 {0x7f}, {0xff}, {0xff}, {0xef}, {0xff},
864 {0xff}, {0xff}, {0xff}, {0xff}, {0xff}, /* attribute controller regs */
865 {0xff}, {0xff}, {0xff}, {0xff}, {0xff},
866 {0xff}, {0xff}, {0xff}, {0xff}, {0xff},
867 {0xff}, {0xff}, {0xff}, {0xff}, {0xf0},
868 {0xff}, {0xff}, {0xff}, {0xff}, {0xff}, /* GDC register */
869 {0xff}, {0xff}, {0xff}, {0xff},
871 int identical = TRUE;
874 if ((buf1 == NULL) || (buf2 == NULL))
875 return COMP_DIFFERENT;
877 for (i = 0; i < nitems(params); ++i) {
878 if (params[i].mask == 0) /* don't care */
880 if ((buf1[i] & params[i].mask) != (buf2[i] & params[i].mask))
881 return COMP_DIFFERENT;
882 if (buf1[i] != buf2[i])
885 return (identical) ? COMP_IDENTICAL : COMP_SIMILAR;
887 #endif /* !VGA_NO_BIOS && !VGA_NO_MODE_CHANGE */
889 /* probe video adapters and return the number of detected adapters */
893 video_adapter_t *adp;
895 #if !defined(VGA_NO_BIOS) && !defined(VGA_NO_MODE_CHANGE)
898 int height, i, width;
900 /* do this test only once */
903 vga_init_done = TRUE;
906 * Locate display adapters.
907 * The AT architecture supports up to two adapters. `syscons' allows
908 * the following combinations of adapters:
910 * 2) MDA + EGA/VGA color
911 * 3) CGA + EGA/VGA mono
912 * Note that `syscons' doesn't bother with MCGA as it is only
913 * avaiable for low end PS/2 models which has 80286 or earlier CPUs,
914 * thus, they are not running FreeBSD!
915 * When there are two adapaters in the system, one becomes `primary'
916 * and the other `secondary'. The EGA adapter has a set of DIP
917 * switches on board for this information and the EGA BIOS copies
918 * it in the BIOS data area BIOSDATA_VIDEOSWITCH (40:88).
919 * The VGA BIOS has more sophisticated mechanism and has this
920 * information in BIOSDATA_DCCINDEX (40:8a), but it also maintains
921 * compatibility with the EGA BIOS by updating BIOSDATA_VIDEOSWITCH.
925 * Check rtc and BIOS data area.
926 * XXX: we don't use BIOSDATA_EQUIPMENT, since it is not a dead
927 * copy of RTC_EQUIPMENT. Bits 4 and 5 of ETC_EQUIPMENT are
928 * zeros for EGA and VGA. However, the EGA/VGA BIOS sets
929 * these bits in BIOSDATA_EQUIPMENT according to the monitor
933 if (*(u_int32_t *)BIOS_PADDRTOVADDR(0x4a8)) {
934 /* EGA/VGA BIOS is present */
935 fill_adapter_param(readb(BIOS_PADDRTOVADDR(0x488)) & 0x0f,
938 switch ((rtcin(RTC_EQUIPMENT) >> 4) & 3) { /* bit 4 and 5 */
940 /* EGA/VGA: shouldn't be happening */
941 fill_adapter_param(readb(BIOS_PADDRTOVADDR(0x488)) & 0x0f,
946 /* FIXME: switch to the 80x25 mode? XXX */
947 biosadapter[V_ADP_PRIMARY] = adapter_init_value[DCC_CGA40];
948 biosadapter[V_ADP_SECONDARY] = adapter_init_value[DCC_MONO];
952 biosadapter[V_ADP_PRIMARY] = adapter_init_value[DCC_CGA80];
953 biosadapter[V_ADP_SECONDARY] = adapter_init_value[DCC_MONO];
957 biosadapter[V_ADP_PRIMARY] = adapter_init_value[DCC_MONO];
958 biosadapter[V_ADP_SECONDARY] = adapter_init_value[DCC_CGA80];
963 /* assume EGA/VGA? XXX */
964 biosadapter[V_ADP_PRIMARY] = adapter_init_value[DCC_EGA80];
965 biosadapter[V_ADP_SECONDARY] = adapter_init_value[DCC_MONO];
966 #endif /* VGA_NO_BIOS */
969 if (verify_adapter(&biosadapter[V_ADP_SECONDARY]) == 0) {
971 biosadapter[V_ADP_SECONDARY].va_flags |= V_ADP_PROBED;
972 biosadapter[V_ADP_SECONDARY].va_mode =
973 biosadapter[V_ADP_SECONDARY].va_initial_mode =
974 map_bios_mode_num(biosadapter[V_ADP_SECONDARY].va_type,
975 biosadapter[V_ADP_SECONDARY].va_flags
977 biosadapter[V_ADP_SECONDARY].va_initial_bios_mode);
979 biosadapter[V_ADP_SECONDARY].va_type = -1;
981 if (verify_adapter(&biosadapter[V_ADP_PRIMARY]) == 0) {
983 biosadapter[V_ADP_PRIMARY].va_flags |= V_ADP_PROBED;
985 biosadapter[V_ADP_PRIMARY].va_initial_bios_mode =
986 readb(BIOS_PADDRTOVADDR(0x449));
988 biosadapter[V_ADP_PRIMARY].va_initial_bios_mode = 3; /* XXX */
990 biosadapter[V_ADP_PRIMARY].va_mode =
991 biosadapter[V_ADP_PRIMARY].va_initial_mode =
992 map_bios_mode_num(biosadapter[V_ADP_PRIMARY].va_type,
993 biosadapter[V_ADP_PRIMARY].va_flags & V_ADP_COLOR,
994 biosadapter[V_ADP_PRIMARY].va_initial_bios_mode);
996 biosadapter[V_ADP_PRIMARY] = biosadapter[V_ADP_SECONDARY];
997 biosadapter[V_ADP_SECONDARY].va_type = -1;
999 if (biosadapters == 0)
1000 return biosadapters;
1001 biosadapter[V_ADP_PRIMARY].va_unit = V_ADP_PRIMARY;
1002 biosadapter[V_ADP_SECONDARY].va_unit = V_ADP_SECONDARY;
1004 #if 0 /* we don't need these... */
1005 fb_init_struct(&biosadapter[V_ADP_PRIMARY], ...);
1006 fb_init_struct(&biosadapter[V_ADP_SECONDARY], ...);
1011 * We cannot have two video adapter of the same type; there must be
1012 * only one of color or mono adapter, or one each of them.
1014 if (biosadapters > 1) {
1015 if (!((biosadapter[0].va_flags ^ biosadapter[1].va_flags)
1017 /* we have two mono or color adapters!! */
1018 return (biosadapters = 0);
1023 * Ensure a zero start address. The registers are w/o
1024 * for old hardware so it's too hard to relocate the active screen
1026 * This must be done before vga_save_state() for VGA.
1028 outb(biosadapter[V_ADP_PRIMARY].va_crtc_addr, 12);
1029 outb(biosadapter[V_ADP_PRIMARY].va_crtc_addr + 1, 0);
1030 outb(biosadapter[V_ADP_PRIMARY].va_crtc_addr, 13);
1031 outb(biosadapter[V_ADP_PRIMARY].va_crtc_addr + 1, 0);
1033 /* the video mode parameter table in EGA/VGA BIOS */
1034 /* NOTE: there can be only one EGA/VGA, wheather color or mono,
1035 * recognized by the video BIOS.
1037 if ((biosadapter[V_ADP_PRIMARY].va_type == KD_EGA) ||
1038 (biosadapter[V_ADP_PRIMARY].va_type == KD_VGA)) {
1039 adp = &biosadapter[V_ADP_PRIMARY];
1040 } else if ((biosadapter[V_ADP_SECONDARY].va_type == KD_EGA) ||
1041 (biosadapter[V_ADP_SECONDARY].va_type == KD_VGA)) {
1042 adp = &biosadapter[V_ADP_SECONDARY];
1046 bzero(mode_map, sizeof(mode_map));
1048 if (adp->va_type == KD_VGA) {
1049 vga_save_state(adp, &adpstate, sizeof(adpstate));
1050 #if defined(VGA_NO_BIOS) || defined(VGA_NO_MODE_CHANGE)
1051 mode_map[adp->va_initial_mode] = adpstate.regs;
1053 #else /* VGA_NO_BIOS || VGA_NO_MODE_CHANGE */
1054 if (video_mode_ptr == NULL) {
1055 mode_map[adp->va_initial_mode] = adpstate.regs;
1058 /* discard the table if we are not familiar with it... */
1059 map_mode_table(mode_map, video_mode_ptr, M_VGA_CG320 + 1);
1060 mp = get_mode_param(adp->va_initial_mode);
1062 bcopy(mp, adpstate2.regs, sizeof(adpstate2.regs));
1063 switch (comp_adpregs(adpstate.regs, mp)) {
1064 case COMP_IDENTICAL:
1066 * OK, this parameter table looks reasonably familiar
1070 * This is a kludge for Toshiba DynaBook SS433
1071 * whose BIOS video mode table entry has the actual #
1072 * of rows at the offset 1; BIOSes from other
1073 * manufacturers store the # of rows - 1 there. XXX
1075 rows_offset = adpstate.regs[1] + 1 - mp[1];
1080 * Not exactly the same, but similar enough to be
1081 * trusted. However, use the saved register values
1082 * for the initial mode and other modes which are
1083 * based on the initial mode.
1085 mode_map[adp->va_initial_mode] = adpstate.regs;
1086 rows_offset = adpstate.regs[1] + 1 - mp[1];
1087 adpstate.regs[1] -= rows_offset - 1;
1090 case COMP_DIFFERENT:
1093 * Don't use the parameter table in the BIOS, since
1094 * even the BIOS doesn't use it for the initial mode.
1095 * Restrict the tweaked modes to (in practice) 80x50
1096 * from 80x25 with 400 scan lines, since the only safe
1097 * tweak is changing the characters from 8x16 to 8x8.
1099 video_mode_ptr = NULL;
1100 bzero(mode_map, sizeof(mode_map));
1101 mode_map[adp->va_initial_mode] = adpstate.regs;
1104 width = height = -1;
1105 for (i = 0; i < nitems(bios_vmode); ++i) {
1106 if (bios_vmode[i].vi_mode == adp->va_initial_mode) {
1107 width = bios_vmode[i].vi_width;
1108 height = bios_vmode[i].vi_height;
1112 for (i = 0; i < nitems(bios_vmode); ++i) {
1113 if (bios_vmode[i].vi_mode != adp->va_initial_mode &&
1114 map_mode_num(bios_vmode[i].vi_mode) ==
1115 adp->va_initial_mode &&
1116 (bios_vmode[i].vi_width != width ||
1117 bios_vmode[i].vi_height != 2 * height)) {
1118 bios_vmode[i].vi_mode = NA;
1124 #endif /* VGA_NO_BIOS || VGA_NO_MODE_CHANGE */
1126 #ifndef VGA_NO_MODE_CHANGE
1127 adp->va_flags |= V_ADP_MODECHANGE;
1129 #ifndef VGA_NO_FONT_LOADING
1130 adp->va_flags |= V_ADP_FONT;
1132 } else if (adp->va_type == KD_EGA) {
1133 #if defined(VGA_NO_BIOS) || defined(VGA_NO_MODE_CHANGE)
1135 #else /* VGA_NO_BIOS || VGA_NO_MODE_CHANGE */
1136 if (video_mode_ptr == NULL) {
1139 map_mode_table(mode_map, video_mode_ptr, M_ENH_C80x25 + 1);
1140 /* XXX how can one validate the EGA table... */
1141 mp = get_mode_param(adp->va_initial_mode);
1143 adp->va_flags |= V_ADP_MODECHANGE;
1144 #ifndef VGA_NO_FONT_LOADING
1145 adp->va_flags |= V_ADP_FONT;
1150 * This is serious. We will not be able to switch video
1153 video_mode_ptr = NULL;
1154 bzero(mode_map, sizeof(mode_map));
1158 #endif /* VGA_NO_BIOS || VGA_NO_MODE_CHANGE */
1162 /* remove conflicting modes if we have more than one adapter */
1163 if (biosadapters > 0) {
1164 for (i = 0; i < biosadapters; ++i) {
1165 if (!(biosadapter[i].va_flags & V_ADP_MODECHANGE))
1167 clear_mode_map(&biosadapter[i], mode_map, M_VGA_CG320 + 1,
1168 (biosadapter[i].va_flags & V_ADP_COLOR) ?
1170 if ((biosadapter[i].va_type == KD_VGA)
1171 || (biosadapter[i].va_type == KD_EGA)) {
1172 biosadapter[i].va_io_base =
1173 (biosadapter[i].va_flags & V_ADP_COLOR) ?
1175 biosadapter[i].va_io_size = 32;
1180 #if !defined(VGA_NO_BIOS) && !defined(VGA_NO_MODE_CHANGE)
1182 * Attempt to determine the real character width for each mode. 9 wide
1183 * is supposed to be standard for EGA mono mode and most VGA text modes,
1184 * but some hardware doesn't support it, so dynamic configuration is
1185 * needed. Bit 0 in sequencer register 1 is supposed control the width
1186 * (set = 8), but this is unreliable too. Trust that 0 in the sequencer
1187 * bit means 9 wide after verifying that 9 is consistent with some CRTC
1188 * timing. The ratio (Horizontal Total) / (Horizontal Displayed) is
1189 * about 1.2 in all standard 9-wide modes and should be about 9/8 larger
1190 * again in similar 8-wide modes; in practice it is usually about 1.4
1193 for (i = 0; i < nitems(bios_vmode); ++i) {
1194 if (bios_vmode[i].vi_mem_model == V_INFO_MM_TEXT &&
1195 bios_vmode[i].vi_width != 90) {
1196 mp = get_mode_param(map_mode_num(bios_vmode[i].vi_mode));
1197 if (mp != NULL && !(mp[5] & 1) && mp[10] <= mp[11] * 125 / 100)
1198 bios_vmode[i].vi_flags |= V_INFO_CWIDTH9;
1203 /* buffer address */
1204 vga_get_info(&biosadapter[V_ADP_PRIMARY],
1205 biosadapter[V_ADP_PRIMARY].va_initial_mode, &info);
1206 info.vi_flags &= ~V_INFO_LINEAR; /* XXX */
1207 update_adapter_info(&biosadapter[V_ADP_PRIMARY], &info);
1209 if (biosadapters > 1) {
1210 vga_get_info(&biosadapter[V_ADP_SECONDARY],
1211 biosadapter[V_ADP_SECONDARY].va_initial_mode, &info);
1212 info.vi_flags &= ~V_INFO_LINEAR; /* XXX */
1213 update_adapter_info(&biosadapter[V_ADP_SECONDARY], &info);
1217 * XXX: we should verify the following values for the primary adapter...
1218 * crtc I/O port address: *(u_int16_t *)BIOS_PADDRTOVADDR(0x463);
1219 * color/mono display: (*(u_int8_t *)BIOS_PADDRTOVADDR(0x487) & 0x02)
1220 * ? 0 : V_ADP_COLOR;
1221 * columns: *(u_int8_t *)BIOS_PADDRTOVADDR(0x44a);
1222 * rows: *(u_int8_t *)BIOS_PADDRTOVADDR(0x484);
1223 * font size: *(u_int8_t *)BIOS_PADDRTOVADDR(0x485);
1224 * buffer size: *(u_int16_t *)BIOS_PADDRTOVADDR(0x44c);
1227 return biosadapters;
1230 /* set the scan line length in pixel */
1232 set_line_length(video_adapter_t *adp, int pixel)
1235 int ppw; /* pixels per word */
1236 int bpl; /* bytes per line */
1239 if ((adp->va_type != KD_VGA) && (adp->va_type != KD_EGA))
1241 mp = get_mode_param(adp->va_mode);
1245 switch (adp->va_info.vi_mem_model) {
1246 case V_INFO_MM_PLANAR:
1247 ppw = 16/(adp->va_info.vi_depth/adp->va_info.vi_planes);
1248 count = howmany(pixel, ppw)/2;
1249 bpl = (howmany(pixel, ppw)/2)*4;
1251 case V_INFO_MM_PACKED:
1252 count = (pixel + 7)/8;
1253 bpl = rounddown(pixel + 7, 8);
1255 case V_INFO_MM_TEXT:
1256 count = (pixel + 7)/8; /* columns */
1257 bpl = (pixel + 7)/8; /* columns */
1263 if (mp[10 + 0x17] & 0x40) /* CRTC mode control reg */
1264 count *= 2; /* byte mode */
1265 outb(adp->va_crtc_addr, 0x13);
1266 outb(adp->va_crtc_addr + 1, count);
1267 adp->va_line_width = bpl;
1273 set_display_start(video_adapter_t *adp, int x, int y)
1275 int off; /* byte offset (graphics mode)/word offset (text mode) */
1276 int poff; /* pixel offset */
1277 int roff; /* row offset */
1278 int ppb; /* pixels per byte */
1280 if ((adp->va_type != KD_VGA) && (adp->va_type != KD_EGA))
1282 if (adp->va_info.vi_flags & V_INFO_GRAPHICS) {
1283 ppb = 8/(adp->va_info.vi_depth/adp->va_info.vi_planes);
1284 off = y*adp->va_line_width + x/ppb;
1288 if ((adp->va_type == KD_VGA) || (adp->va_type == KD_EGA)) {
1297 off = y/adp->va_info.vi_cheight*adp->va_line_width + x/ppb;
1298 roff = y%adp->va_info.vi_cheight;
1299 /* FIXME: is this correct? XXX */
1307 outb(adp->va_crtc_addr, 0xc); /* high */
1308 outb(adp->va_crtc_addr + 1, off >> 8);
1309 outb(adp->va_crtc_addr, 0xd); /* low */
1310 outb(adp->va_crtc_addr + 1, off & 0xff);
1312 /* horizontal pel pan */
1313 if ((adp->va_type == KD_VGA) || (adp->va_type == KD_EGA)) {
1314 inb(adp->va_crtc_addr + 6);
1315 outb(ATC, 0x13 | 0x20);
1317 inb(adp->va_crtc_addr + 6);
1321 /* preset raw scan */
1322 outb(adp->va_crtc_addr, 8);
1323 outb(adp->va_crtc_addr + 1, roff);
1325 adp->va_disp_start.x = x;
1326 adp->va_disp_start.y = y;
1330 #ifndef VGA_NO_MODE_CHANGE
1331 #if defined(__i386__) || defined(__amd64__) /* XXX */
1333 fill(int val, void *d, size_t size)
1340 #endif /* __i386__ */
1343 filll_io(int val, vm_offset_t d, size_t size)
1345 while (size-- > 0) {
1347 d += sizeof(u_int32_t);
1350 #endif /* !VGA_NO_MODE_CHANGE */
1369 vga_probe(int unit, video_adapter_t **adpp, void *arg, int flags)
1372 if (unit >= biosadapters)
1375 *adpp = &biosadapter[unit];
1381 vga_init(int unit, video_adapter_t *adp, int flags)
1383 if ((unit >= biosadapters) || (adp == NULL) || !probe_done(adp))
1386 if (!init_done(adp)) {
1387 /* nothing to do really... */
1388 adp->va_flags |= V_ADP_INITIALIZED;
1391 if (!config_done(adp)) {
1392 if (vid_register(adp) < 0)
1394 adp->va_flags |= V_ADP_REGISTERED;
1396 if (vga_sub_configure != NULL)
1397 (*vga_sub_configure)(0);
1404 * Return the video_info structure of the requested video mode.
1409 vga_get_info(video_adapter_t *adp, int mode, video_info_t *info)
1416 mode = map_gen_mode_num(adp->va_type, adp->va_flags & V_ADP_COLOR, mode);
1417 #ifndef VGA_NO_MODE_CHANGE
1418 if (adp->va_flags & V_ADP_MODECHANGE) {
1420 * If the parameter table entry for this mode is not found,
1421 * the mode is not supported...
1423 if (get_mode_param(mode) == NULL)
1426 #endif /* VGA_NO_MODE_CHANGE */
1429 * Even if we don't support video mode switching on this adapter,
1430 * the information on the initial (thus current) video mode
1431 * should be made available.
1433 if (mode != adp->va_initial_mode)
1437 for (i = 0; bios_vmode[i].vi_mode != EOT; ++i) {
1438 if (bios_vmode[i].vi_mode == NA)
1440 if (mode == bios_vmode[i].vi_mode) {
1441 *info = bios_vmode[i];
1443 info->vi_buffer_size = info->vi_window_size*info->vi_planes;
1452 * Find a video mode matching the requested parameters.
1453 * Fields filled with 0 are considered "don't care" fields and
1459 vga_query_mode(video_adapter_t *adp, video_info_t *info)
1466 for (i = 0; bios_vmode[i].vi_mode != EOT; ++i) {
1467 if (bios_vmode[i].vi_mode == NA)
1470 if ((info->vi_width != 0)
1471 && (info->vi_width != bios_vmode[i].vi_width))
1473 if ((info->vi_height != 0)
1474 && (info->vi_height != bios_vmode[i].vi_height))
1476 if ((info->vi_cwidth != 0)
1477 && (info->vi_cwidth != bios_vmode[i].vi_cwidth))
1479 if ((info->vi_cheight != 0)
1480 && (info->vi_cheight != bios_vmode[i].vi_cheight))
1482 if ((info->vi_depth != 0)
1483 && (info->vi_depth != bios_vmode[i].vi_depth))
1485 if ((info->vi_planes != 0)
1486 && (info->vi_planes != bios_vmode[i].vi_planes))
1488 /* XXX: should check pixel format, memory model */
1489 if ((info->vi_flags != 0)
1490 && (info->vi_flags != bios_vmode[i].vi_flags))
1493 /* verify if this mode is supported on this adapter */
1494 if (vga_get_info(adp, bios_vmode[i].vi_mode, info))
1503 * Change the video mode.
1508 #ifndef VGA_NO_MODE_CHANGE
1511 set_width90(adp_state_t *params)
1514 * Based on code submitted by Kelly Yancey (kbyanc@freedomnet.com)
1515 * and alexv@sui.gda.itesm.mx.
1517 params->regs[5] |= 1; /* toggle 8 pixel wide fonts */
1518 params->regs[10+0x0] = 0x6b;
1519 params->regs[10+0x1] = 0x59;
1520 params->regs[10+0x2] = 0x5a;
1521 params->regs[10+0x3] = 0x8e;
1522 params->regs[10+0x4] = 0x5e;
1523 params->regs[10+0x5] = 0x8a;
1524 params->regs[10+0x13] = 45;
1525 params->regs[35+0x13] = 0;
1527 #endif /* VGA_WIDTH90 */
1528 #endif /* !VGA_NO_MODE_CHANGE */
1531 vga_set_mode(video_adapter_t *adp, int mode)
1533 #ifndef VGA_NO_MODE_CHANGE
1537 prologue(adp, V_ADP_MODECHANGE, ENODEV);
1539 mode = map_gen_mode_num(adp->va_type,
1540 adp->va_flags & V_ADP_COLOR, mode);
1541 if (vga_get_info(adp, mode, &info))
1545 printf("vga_set_mode(): setting mode %d\n", mode);
1548 params.sig = V_STATE_SIG;
1549 bcopy(get_mode_param(mode), params.regs, sizeof(params.regs));
1553 case M_VGA_C90x60: case M_VGA_M90x60:
1554 set_width90(¶ms);
1557 case M_VGA_C80x60: case M_VGA_M80x60:
1558 params.regs[2] = 0x08;
1559 params.regs[19] = 0x47;
1563 case M_VGA_C90x30: case M_VGA_M90x30:
1564 set_width90(¶ms);
1567 case M_VGA_C80x30: case M_VGA_M80x30:
1568 params.regs[19] = 0x4f;
1570 params.regs[9] |= 0xc0;
1571 params.regs[16] = 0x08;
1572 params.regs[17] = 0x3e;
1573 params.regs[26] = 0xea;
1574 params.regs[28] = 0xdf;
1575 params.regs[31] = 0xe7;
1576 params.regs[32] = 0x04;
1580 case M_VGA_C90x43: case M_VGA_M90x43:
1581 set_width90(¶ms);
1584 case M_ENH_C80x43: case M_ENH_B80x43:
1585 params.regs[28] = 87;
1589 case M_VGA_C90x50: case M_VGA_M90x50:
1590 set_width90(¶ms);
1593 case M_VGA_C80x50: case M_VGA_M80x50:
1596 params.regs[19] = 7;
1600 case M_VGA_C90x25: case M_VGA_M90x25:
1601 set_width90(¶ms);
1604 case M_VGA_C40x25: case M_VGA_C80x25:
1606 case M_B40x25: case M_C40x25:
1607 case M_B80x25: case M_C80x25:
1608 case M_ENH_B40x25: case M_ENH_C40x25:
1609 case M_ENH_B80x25: case M_ENH_C80x25:
1610 case M_EGAMONO80x25:
1613 vga_load_state(adp, ¶ms);
1617 /* "unchain" the VGA mode */
1618 params.regs[5-1+0x04] &= 0xf7;
1619 params.regs[5-1+0x04] |= 0x04;
1620 /* turn off doubleword mode */
1621 params.regs[10+0x14] &= 0xbf;
1622 /* turn off word addressing */
1623 params.regs[10+0x17] |= 0x40;
1624 /* set logical screen width */
1625 params.regs[10+0x13] = 80;
1627 params.regs[10+0x11] = 0x2c;
1628 params.regs[10+0x06] = 0x0d;
1629 params.regs[10+0x07] = 0x3e;
1630 params.regs[10+0x10] = 0xea;
1631 params.regs[10+0x11] = 0xac;
1632 params.regs[10+0x12] = 0xdf;
1633 params.regs[10+0x15] = 0xe7;
1634 params.regs[10+0x16] = 0x06;
1635 /* set vertical sync polarity to reflect aspect ratio */
1636 params.regs[9] = 0xe3;
1639 case M_BG320: case M_CG320: case M_BG640:
1640 case M_CG320_D: case M_CG640_E:
1641 case M_CG640x350: case M_ENH_CG640:
1642 case M_BG640x480: case M_CG640x480: case M_VGA_CG320:
1645 vga_load_state(adp, ¶ms);
1652 adp->va_mode = mode;
1653 info.vi_flags &= ~V_INFO_LINEAR; /* XXX */
1654 update_adapter_info(adp, &info);
1656 /* move hardware cursor out of the way */
1657 vidd_set_hw_cursor(adp, -1, -1);
1660 #else /* VGA_NO_MODE_CHANGE */
1662 #endif /* VGA_NO_MODE_CHANGE */
1665 #ifndef VGA_NO_FONT_LOADING
1668 set_font_mode(video_adapter_t *adp, u_char *buf)
1675 /* save register values */
1676 if (adp->va_type == KD_VGA) {
1677 outb(TSIDX, 0x02); buf[0] = inb(TSREG);
1678 outb(TSIDX, 0x04); buf[1] = inb(TSREG);
1679 outb(GDCIDX, 0x04); buf[2] = inb(GDCREG);
1680 outb(GDCIDX, 0x05); buf[3] = inb(GDCREG);
1681 outb(GDCIDX, 0x06); buf[4] = inb(GDCREG);
1682 inb(adp->va_crtc_addr + 6);
1683 outb(ATC, 0x10); buf[5] = inb(ATC + 1);
1684 } else /* if (adp->va_type == KD_EGA) */ {
1686 * EGA cannot be read; copy parameters from the mode parameter
1689 mp = get_mode_param(adp->va_mode);
1690 buf[0] = mp[5 + 0x02 - 1];
1691 buf[1] = mp[5 + 0x04 - 1];
1692 buf[2] = mp[55 + 0x04];
1693 buf[3] = mp[55 + 0x05];
1694 buf[4] = mp[55 + 0x06];
1695 buf[5] = mp[35 + 0x10];
1698 /* setup vga for loading fonts */
1699 inb(adp->va_crtc_addr + 6); /* reset flip-flop */
1700 outb(ATC, 0x10); outb(ATC, buf[5] & ~0x01);
1701 inb(adp->va_crtc_addr + 6); /* reset flip-flop */
1702 outb(ATC, 0x20); /* enable palette */
1704 #ifdef VGA_SLOW_IOACCESS
1705 #ifdef VGA_ALT_SEQACCESS
1706 outb(TSIDX, 0x00); outb(TSREG, 0x01);
1708 outb(TSIDX, 0x02); outb(TSREG, 0x04);
1709 outb(TSIDX, 0x04); outb(TSREG, 0x07);
1710 #ifdef VGA_ALT_SEQACCESS
1711 outb(TSIDX, 0x00); outb(TSREG, 0x03);
1713 outb(GDCIDX, 0x04); outb(GDCREG, 0x02);
1714 outb(GDCIDX, 0x05); outb(GDCREG, 0x00);
1715 outb(GDCIDX, 0x06); outb(GDCREG, 0x04);
1716 #else /* VGA_SLOW_IOACCESS */
1717 #ifdef VGA_ALT_SEQACCESS
1718 outw(TSIDX, 0x0100);
1720 outw(TSIDX, 0x0402);
1721 outw(TSIDX, 0x0704);
1722 #ifdef VGA_ALT_SEQACCESS
1723 outw(TSIDX, 0x0300);
1725 outw(GDCIDX, 0x0204);
1726 outw(GDCIDX, 0x0005);
1727 outw(GDCIDX, 0x0406); /* addr = a0000, 64kb */
1728 #endif /* VGA_SLOW_IOACCESS */
1734 set_normal_mode(video_adapter_t *adp, u_char *buf)
1740 /* setup vga for normal operation mode again */
1741 inb(adp->va_crtc_addr + 6); /* reset flip-flop */
1742 outb(ATC, 0x10); outb(ATC, buf[5]);
1743 inb(adp->va_crtc_addr + 6); /* reset flip-flop */
1744 outb(ATC, 0x20); /* enable palette */
1746 #ifdef VGA_SLOW_IOACCESS
1747 #ifdef VGA_ALT_SEQACCESS
1748 outb(TSIDX, 0x00); outb(TSREG, 0x01);
1750 outb(TSIDX, 0x02); outb(TSREG, buf[0]);
1751 outb(TSIDX, 0x04); outb(TSREG, buf[1]);
1752 #ifdef VGA_ALT_SEQACCESS
1753 outb(TSIDX, 0x00); outb(TSREG, 0x03);
1755 outb(GDCIDX, 0x04); outb(GDCREG, buf[2]);
1756 outb(GDCIDX, 0x05); outb(GDCREG, buf[3]);
1757 if (adp->va_crtc_addr == MONO_CRTC) {
1758 outb(GDCIDX, 0x06); outb(GDCREG,(buf[4] & 0x03) | 0x08);
1760 outb(GDCIDX, 0x06); outb(GDCREG,(buf[4] & 0x03) | 0x0c);
1762 #else /* VGA_SLOW_IOACCESS */
1763 #ifdef VGA_ALT_SEQACCESS
1764 outw(TSIDX, 0x0100);
1766 outw(TSIDX, 0x0002 | (buf[0] << 8));
1767 outw(TSIDX, 0x0004 | (buf[1] << 8));
1768 #ifdef VGA_ALT_SEQACCESS
1769 outw(TSIDX, 0x0300);
1771 outw(GDCIDX, 0x0004 | (buf[2] << 8));
1772 outw(GDCIDX, 0x0005 | (buf[3] << 8));
1773 if (adp->va_crtc_addr == MONO_CRTC)
1774 outw(GDCIDX, 0x0006 | (((buf[4] & 0x03) | 0x08)<<8));
1776 outw(GDCIDX, 0x0006 | (((buf[4] & 0x03) | 0x0c)<<8));
1777 #endif /* VGA_SLOW_IOACCESS */
1782 #endif /* VGA_NO_FONT_LOADING */
1786 * Read the font data in the requested font page from the video adapter.
1791 vga_save_font(video_adapter_t *adp, int page, int fontsize, int fontwidth,
1792 u_char *data, int ch, int count)
1794 #ifndef VGA_NO_FONT_LOADING
1795 u_char buf[PARAM_BUFSIZE];
1796 vm_offset_t segment;
1798 #ifdef VGA_ALT_SEQACCESS
1803 prologue(adp, V_ADP_FONT, ENODEV);
1805 if (fontsize < 14) {
1808 } else if (fontsize >= 32) {
1810 } else if (fontsize >= 16) {
1818 if (page < 0 || page >= 8 || fontwidth != 8)
1820 segment = FONT_BUF + 0x4000*page;
1824 #ifdef VGA_ALT_SEQACCESS
1825 if (adp->va_type == KD_VGA) { /* what about EGA? XXX */
1827 outb(TSIDX, 0x00); outb(TSREG, 0x01);
1828 outb(TSIDX, 0x01); val = inb(TSREG); /* disable screen */
1829 outb(TSIDX, 0x01); outb(TSREG, val | 0x20);
1830 outb(TSIDX, 0x00); outb(TSREG, 0x03);
1835 set_font_mode(adp, buf);
1836 if (fontsize == 32) {
1837 bcopy_fromio((uintptr_t)segment + ch*32, data, fontsize*count);
1839 for (c = ch; count > 0; ++c, --count) {
1840 bcopy_fromio((uintptr_t)segment + c*32, data, fontsize);
1844 set_normal_mode(adp, buf);
1846 #ifdef VGA_ALT_SEQACCESS
1847 if (adp->va_type == KD_VGA) {
1849 outb(TSIDX, 0x00); outb(TSREG, 0x01);
1850 outb(TSIDX, 0x01); outb(TSREG, val & 0xdf); /* enable screen */
1851 outb(TSIDX, 0x00); outb(TSREG, 0x03);
1857 #else /* VGA_NO_FONT_LOADING */
1859 #endif /* VGA_NO_FONT_LOADING */
1864 * Set the font data in the requested font page.
1865 * NOTE: it appears that some recent video adapters do not support
1866 * the font page other than 0... XXX
1871 vga_load_font(video_adapter_t *adp, int page, int fontsize, int fontwidth,
1872 u_char *data, int ch, int count)
1874 #ifndef VGA_NO_FONT_LOADING
1875 u_char buf[PARAM_BUFSIZE];
1876 vm_offset_t segment;
1878 #ifdef VGA_ALT_SEQACCESS
1883 prologue(adp, V_ADP_FONT, ENODEV);
1885 if (fontsize < 14) {
1888 } else if (fontsize >= 32) {
1890 } else if (fontsize >= 16) {
1898 if (page < 0 || page >= 8 || fontwidth != 8)
1900 segment = FONT_BUF + 0x4000*page;
1904 #ifdef VGA_ALT_SEQACCESS
1905 if (adp->va_type == KD_VGA) { /* what about EGA? XXX */
1907 outb(TSIDX, 0x00); outb(TSREG, 0x01);
1908 outb(TSIDX, 0x01); val = inb(TSREG); /* disable screen */
1909 outb(TSIDX, 0x01); outb(TSREG, val | 0x20);
1910 outb(TSIDX, 0x00); outb(TSREG, 0x03);
1915 set_font_mode(adp, buf);
1916 if (fontsize == 32) {
1917 bcopy_toio(data, (uintptr_t)segment + ch*32, fontsize*count);
1919 for (c = ch; count > 0; ++c, --count) {
1920 bcopy_toio(data, (uintptr_t)segment + c*32, fontsize);
1924 set_normal_mode(adp, buf);
1926 #ifdef VGA_ALT_SEQACCESS
1927 if (adp->va_type == KD_VGA) {
1929 outb(TSIDX, 0x00); outb(TSREG, 0x01);
1930 outb(TSIDX, 0x01); outb(TSREG, val & 0xdf); /* enable screen */
1931 outb(TSIDX, 0x00); outb(TSREG, 0x03);
1937 #else /* VGA_NO_FONT_LOADING */
1939 #endif /* VGA_NO_FONT_LOADING */
1944 * Activate the requested font page.
1945 * NOTE: it appears that some recent video adapters do not support
1946 * the font page other than 0... XXX
1951 vga_show_font(video_adapter_t *adp, int page)
1953 #ifndef VGA_NO_FONT_LOADING
1954 static u_char cg[] = { 0x00, 0x05, 0x0a, 0x0f, 0x30, 0x35, 0x3a, 0x3f };
1957 prologue(adp, V_ADP_FONT, ENODEV);
1958 if (page < 0 || page >= 8)
1962 outb(TSIDX, 0x03); outb(TSREG, cg[page]);
1966 #else /* VGA_NO_FONT_LOADING */
1968 #endif /* VGA_NO_FONT_LOADING */
1973 * Read DAC values. The values have expressed in 8 bits.
1978 vga_save_palette(video_adapter_t *adp, u_char *palette)
1983 prologue(adp, V_ADP_PALETTE, ENODEV);
1986 * We store 8 bit values in the palette buffer, while the standard
1987 * VGA has 6 bit DAC .
1989 outb(PALRADR, 0x00);
1990 bits = (adp->va_flags & V_ADP_DAC8) != 0 ? 0 : 2;
1991 for (i = 0; i < 256*3; ++i)
1992 palette[i] = inb(PALDATA) << bits;
1993 inb(adp->va_crtc_addr + 6); /* reset flip/flop */
1998 vga_save_palette2(video_adapter_t *adp, int base, int count,
1999 u_char *r, u_char *g, u_char *b)
2004 prologue(adp, V_ADP_PALETTE, ENODEV);
2006 outb(PALRADR, base);
2007 bits = (adp->va_flags & V_ADP_DAC8) != 0 ? 0 : 2;
2008 for (i = 0; i < count; ++i) {
2009 r[i] = inb(PALDATA) << bits;
2010 g[i] = inb(PALDATA) << bits;
2011 b[i] = inb(PALDATA) << bits;
2013 inb(adp->va_crtc_addr + 6); /* reset flip/flop */
2024 vga_load_palette(video_adapter_t *adp, u_char *palette)
2029 prologue(adp, V_ADP_PALETTE, ENODEV);
2031 outb(PIXMASK, 0xff); /* no pixelmask */
2032 outb(PALWADR, 0x00);
2033 bits = (adp->va_flags & V_ADP_DAC8) != 0 ? 0 : 2;
2034 for (i = 0; i < 256*3; ++i)
2035 outb(PALDATA, palette[i] >> bits);
2036 inb(adp->va_crtc_addr + 6); /* reset flip/flop */
2037 outb(ATC, 0x20); /* enable palette */
2042 vga_load_palette2(video_adapter_t *adp, int base, int count,
2043 u_char *r, u_char *g, u_char *b)
2048 prologue(adp, V_ADP_PALETTE, ENODEV);
2050 outb(PIXMASK, 0xff); /* no pixelmask */
2051 outb(PALWADR, base);
2052 bits = (adp->va_flags & V_ADP_DAC8) != 0 ? 0 : 2;
2053 for (i = 0; i < count; ++i) {
2054 outb(PALDATA, r[i] >> bits);
2055 outb(PALDATA, g[i] >> bits);
2056 outb(PALDATA, b[i] >> bits);
2058 inb(adp->va_crtc_addr + 6); /* reset flip/flop */
2059 outb(ATC, 0x20); /* enable palette */
2065 * Change the border color.
2070 vga_set_border(video_adapter_t *adp, int color)
2072 prologue(adp, V_ADP_BORDER, ENODEV);
2074 switch (adp->va_type) {
2077 inb(adp->va_crtc_addr + 6); /* reset flip-flop */
2078 outb(ATC, 0x31); outb(ATC, color & 0xff);
2081 outb(adp->va_crtc_addr + 5, color & 0x0f); /* color select register */
2093 * Read video register values.
2094 * NOTE: this function only reads the standard EGA/VGA registers.
2095 * any extra/extended registers of SVGA adapters are not saved.
2100 vga_save_state(video_adapter_t *adp, void *p, size_t size)
2109 /* return the required buffer size */
2110 prologue(adp, V_ADP_STATESAVE, 0);
2111 return sizeof(adp_state_t);
2113 prologue(adp, V_ADP_STATESAVE, ENODEV);
2114 if (size < sizeof(adp_state_t))
2118 ((adp_state_t *)p)->sig = V_STATE_SIG;
2119 buf = ((adp_state_t *)p)->regs;
2120 bzero(buf, V_MODE_PARAM_SIZE);
2121 crtc_addr = adp->va_crtc_addr;
2125 outb(TSIDX, 0x00); outb(TSREG, 0x01); /* stop sequencer */
2126 for (i = 0, j = 5; i < 4; i++) {
2128 buf[j++] = inb(TSREG);
2130 buf[9] = inb(MISC + 10); /* dot-clock */
2131 outb(TSIDX, 0x00); outb(TSREG, 0x03); /* start sequencer */
2133 for (i = 0, j = 10; i < 25; i++) { /* crtc */
2135 buf[j++] = inb(crtc_addr + 1);
2137 for (i = 0, j = 35; i < 20; i++) { /* attribute ctrl */
2138 inb(crtc_addr + 6); /* reset flip-flop */
2140 buf[j++] = inb(ATC + 1);
2142 for (i = 0, j = 55; i < 9; i++) { /* graph data ctrl */
2144 buf[j++] = inb(GDCREG);
2146 inb(crtc_addr + 6); /* reset flip-flop */
2147 outb(ATC, 0x20); /* enable palette */
2152 if (vga_get_info(adp, adp->va_mode, &info) == 0) {
2153 if (info.vi_flags & V_INFO_GRAPHICS) {
2154 buf[0] = info.vi_width/info.vi_cwidth; /* COLS */
2155 buf[1] = info.vi_height/info.vi_cheight - 1; /* ROWS */
2157 buf[0] = info.vi_width; /* COLS */
2158 buf[1] = info.vi_height - 1; /* ROWS */
2160 buf[2] = info.vi_cheight; /* POINTS */
2163 buf[0] = readb(BIOS_PADDRTOVADDR(0x44a)); /* COLS */
2164 buf[1] = readb(BIOS_PADDRTOVADDR(0x484)); /* ROWS */
2165 buf[2] = readb(BIOS_PADDRTOVADDR(0x485)); /* POINTS */
2166 buf[3] = readb(BIOS_PADDRTOVADDR(0x44c));
2167 buf[4] = readb(BIOS_PADDRTOVADDR(0x44d));
2175 * Set video registers at once.
2176 * NOTE: this function only updates the standard EGA/VGA registers.
2177 * any extra/extended registers of SVGA adapters are not changed.
2182 vga_load_state(video_adapter_t *adp, void *p)
2189 prologue(adp, V_ADP_STATELOAD, ENODEV);
2190 if (((adp_state_t *)p)->sig != V_STATE_SIG)
2193 buf = ((adp_state_t *)p)->regs;
2194 crtc_addr = adp->va_crtc_addr;
2197 dump_buffer(buf, V_MODE_PARAM_SIZE);
2202 outb(TSIDX, 0x00); outb(TSREG, 0x01); /* stop sequencer */
2203 for (i = 0; i < 4; ++i) { /* program sequencer */
2205 outb(TSREG, buf[i + 5]);
2207 outb(MISC, buf[9]); /* set dot-clock */
2208 outb(TSIDX, 0x00); outb(TSREG, 0x03); /* start sequencer */
2209 outb(crtc_addr, 0x11);
2210 outb(crtc_addr + 1, inb(crtc_addr + 1) & 0x7F);
2211 for (i = 0; i < 25; ++i) { /* program crtc */
2213 outb(crtc_addr + 1, buf[i + 10]);
2215 inb(crtc_addr+6); /* reset flip-flop */
2216 for (i = 0; i < 20; ++i) { /* program attribute ctrl */
2218 outb(ATC, buf[i + 35]);
2220 for (i = 0; i < 9; ++i) { /* program graph data ctrl */
2222 outb(GDCREG, buf[i + 55]);
2224 inb(crtc_addr + 6); /* reset flip-flop */
2225 outb(ATC, 0x20); /* enable palette */
2227 #ifdef notyet /* a temporary workaround for kernel panic, XXX */
2229 if (adp->va_unit == V_ADP_PRIMARY) {
2230 writeb(BIOS_PADDRTOVADDR(0x44a), buf[0]); /* COLS */
2231 writeb(BIOS_PADDRTOVADDR(0x484), buf[1] + rows_offset - 1); /* ROWS */
2232 writeb(BIOS_PADDRTOVADDR(0x485), buf[2]); /* POINTS */
2234 writeb(BIOS_PADDRTOVADDR(0x44c), buf[3]);
2235 writeb(BIOS_PADDRTOVADDR(0x44d), buf[4]);
2238 #endif /* VGA_NO_BIOS */
2247 * Change the origin (window mapping) of the banked frame buffer.
2250 vga_set_origin(video_adapter_t *adp, off_t offset)
2253 * The standard video modes do not require window mapping;
2254 * always return error.
2261 * Read the position of the hardware text cursor.
2266 vga_read_hw_cursor(video_adapter_t *adp, int *col, int *row)
2274 if (adp->va_info.vi_flags & V_INFO_GRAPHICS)
2278 outb(adp->va_crtc_addr, 14);
2279 off = inb(adp->va_crtc_addr + 1);
2280 outb(adp->va_crtc_addr, 15);
2281 off = (off << 8) | inb(adp->va_crtc_addr + 1);
2284 *row = off / adp->va_info.vi_width;
2285 *col = off % adp->va_info.vi_width;
2292 * Move the hardware text cursor. If col and row are both -1,
2293 * the cursor won't be shown.
2298 vga_set_hw_cursor(video_adapter_t *adp, int col, int row)
2306 if ((col == -1) && (row == -1)) {
2309 if (adp->va_info.vi_flags & V_INFO_GRAPHICS)
2311 off = row*adp->va_info.vi_width + col;
2315 outb(adp->va_crtc_addr, 14);
2316 outb(adp->va_crtc_addr + 1, off >> 8);
2317 outb(adp->va_crtc_addr, 15);
2318 outb(adp->va_crtc_addr + 1, off & 0x00ff);
2325 * set_hw_cursor_shape():
2326 * Change the shape of the hardware text cursor. If the height is
2327 * zero or negative, the cursor won't be shown.
2332 vga_set_hw_cursor_shape(video_adapter_t *adp, int base, int height,
2333 int celsize, int blink)
2341 switch (adp->va_type) {
2348 /* make the cursor invisible */
2349 outb(adp->va_crtc_addr, 10);
2350 outb(adp->va_crtc_addr + 1, 32);
2351 outb(adp->va_crtc_addr, 11);
2352 outb(adp->va_crtc_addr + 1, 0);
2354 outb(adp->va_crtc_addr, 10);
2355 outb(adp->va_crtc_addr + 1, celsize - base - height);
2356 outb(adp->va_crtc_addr, 11);
2357 outb(adp->va_crtc_addr + 1, celsize - base - 1);
2362 /* make the cursor invisible */
2363 outb(adp->va_crtc_addr, 10);
2364 outb(adp->va_crtc_addr + 1, celsize);
2365 outb(adp->va_crtc_addr, 11);
2366 outb(adp->va_crtc_addr + 1, 0);
2368 outb(adp->va_crtc_addr, 10);
2369 outb(adp->va_crtc_addr + 1, celsize - base - height);
2370 outb(adp->va_crtc_addr, 11);
2371 outb(adp->va_crtc_addr + 1, celsize - base);
2382 * Put the display in power save/power off mode.
2387 vga_blank_display(video_adapter_t *adp, int mode)
2393 switch (adp->va_type) {
2396 case V_DISPLAY_SUSPEND:
2397 case V_DISPLAY_STAND_BY:
2401 outb(TSREG, val | 0x20);
2402 outb(adp->va_crtc_addr, 0x17);
2403 val = inb(adp->va_crtc_addr + 1);
2404 outb(adp->va_crtc_addr + 1, val & ~0x80);
2406 case V_DISPLAY_BLANK:
2410 outb(TSREG, val | 0x20);
2416 outb(TSREG, val & 0xDF);
2417 outb(adp->va_crtc_addr, 0x17);
2418 val = inb(adp->va_crtc_addr + 1);
2419 outb(adp->va_crtc_addr + 1, val | 0x80);
2425 /* no support yet */
2431 case V_DISPLAY_SUSPEND:
2432 case V_DISPLAY_STAND_BY:
2433 case V_DISPLAY_BLANK:
2434 outb(adp->va_crtc_addr + 4, 0x25);
2437 outb(adp->va_crtc_addr + 4, 0x2d);
2445 case V_DISPLAY_SUSPEND:
2446 case V_DISPLAY_STAND_BY:
2447 case V_DISPLAY_BLANK:
2448 outb(adp->va_crtc_addr + 4, 0x21);
2451 outb(adp->va_crtc_addr + 4, 0x29);
2465 * Mmap frame buffer.
2470 vga_mmap_buf(video_adapter_t *adp, vm_ooffset_t offset, vm_paddr_t *paddr,
2471 int prot, vm_memattr_t *memattr)
2473 if (adp->va_info.vi_flags & V_INFO_LINEAR)
2477 printf("vga_mmap_buf(): window:0x%jx, offset:0x%jx\n",
2478 (uintmax_t)adp->va_info.vi_window, (uintmax_t)offset);
2481 /* XXX: is this correct? */
2482 if (offset > adp->va_window_size - PAGE_SIZE)
2485 *paddr = adp->va_info.vi_window + offset;
2489 #ifndef VGA_NO_MODE_CHANGE
2492 planar_fill(video_adapter_t *adp, int val)
2495 int at; /* position in the frame buffer */
2498 outw(GDCIDX, 0x0005); /* read mode 0, write mode 0 */
2499 outw(GDCIDX, 0x0003); /* data rotate/function select */
2500 outw(GDCIDX, 0x0f01); /* set/reset enable */
2501 outw(GDCIDX, 0xff08); /* bit mask */
2502 outw(GDCIDX, (val << 8) | 0x00); /* set/reset */
2504 length = adp->va_line_width*adp->va_info.vi_height;
2505 while (length > 0) {
2506 l = imin(length, adp->va_window_size);
2507 vidd_set_win_org(adp, at);
2508 bzero_io(adp->va_window, l);
2512 outw(GDCIDX, 0x0000); /* set/reset */
2513 outw(GDCIDX, 0x0001); /* set/reset enable */
2517 packed_fill(video_adapter_t *adp, int val)
2520 int at; /* position in the frame buffer */
2524 length = adp->va_line_width*adp->va_info.vi_height;
2525 while (length > 0) {
2526 l = imin(length, adp->va_window_size);
2527 vidd_set_win_org(adp, at);
2528 fill_io(val, adp->va_window, l);
2535 direct_fill(video_adapter_t *adp, int val)
2538 int at; /* position in the frame buffer */
2542 length = adp->va_line_width*adp->va_info.vi_height;
2543 while (length > 0) {
2544 l = imin(length, adp->va_window_size);
2545 vidd_set_win_org(adp, at);
2546 switch (adp->va_info.vi_pixel_size) {
2547 case sizeof(u_int16_t):
2548 fillw_io(val, adp->va_window, l/sizeof(u_int16_t));
2553 case sizeof(u_int32_t):
2554 filll_io(val, adp->va_window, l/sizeof(u_int32_t));
2563 vga_clear(video_adapter_t *adp)
2565 switch (adp->va_info.vi_mem_model) {
2566 case V_INFO_MM_TEXT:
2567 /* do nothing? XXX */
2569 case V_INFO_MM_PLANAR:
2570 planar_fill(adp, 0);
2572 case V_INFO_MM_PACKED:
2573 packed_fill(adp, 0);
2575 case V_INFO_MM_DIRECT:
2576 direct_fill(adp, 0);
2584 planar_fill_rect(video_adapter_t *adp, int val, int x, int y, int cx, int cy)
2589 int offset; /* offset within window */
2593 outw(GDCIDX, 0x0005); /* read mode 0, write mode 0 */
2594 outw(GDCIDX, 0x0003); /* data rotate/function select */
2595 outw(GDCIDX, 0x0f01); /* set/reset enable */
2596 outw(GDCIDX, 0xff08); /* bit mask */
2597 outw(GDCIDX, (val << 8) | 0x00); /* set/reset */
2599 banksize = adp->va_window_size;
2602 pos = adp->va_line_width*y + x/8;
2603 if (bank != pos/banksize) {
2604 vidd_set_win_org(adp, pos);
2605 bank = pos/banksize;
2607 offset = pos%banksize;
2608 bx = (x + cx)/8 - x/8;
2610 outw(GDCIDX, ((0xff00 >> (x % 8)) & 0xff00) | 0x08);
2611 writeb(adp->va_window + offset, 0);
2614 if (offset >= banksize) {
2616 ++bank; /* next bank */
2617 vidd_set_win_org(adp, bank*banksize);
2619 outw(GDCIDX, 0xff08); /* bit mask */
2622 l = imin(bx, banksize);
2623 bzero_io(adp->va_window + offset, l);
2626 if (offset >= banksize) {
2628 ++bank; /* next bank */
2629 vidd_set_win_org(adp, bank*banksize);
2633 outw(GDCIDX, (~(0xff00 >> ((x + cx) % 8)) & 0xff00) | 0x08);
2634 writeb(adp->va_window + offset, 0);
2636 if (offset >= banksize) {
2638 ++bank; /* next bank */
2639 vidd_set_win_org(adp, bank*banksize);
2641 outw(GDCIDX, 0xff08); /* bit mask */
2647 outw(GDCIDX, 0xff08); /* bit mask */
2648 outw(GDCIDX, 0x0000); /* set/reset */
2649 outw(GDCIDX, 0x0001); /* set/reset enable */
2653 packed_fill_rect(video_adapter_t *adp, int val, int x, int y, int cx, int cy)
2658 int offset; /* offset within window */
2661 banksize = adp->va_window_size;
2663 cx *= adp->va_info.vi_pixel_size;
2665 pos = adp->va_line_width*y + x*adp->va_info.vi_pixel_size;
2666 if (bank != pos/banksize) {
2667 vidd_set_win_org(adp, pos);
2668 bank = pos/banksize;
2670 offset = pos%banksize;
2671 end = imin(offset + cx, banksize);
2672 fill_io(val, adp->va_window + offset,
2673 (end - offset)/adp->va_info.vi_pixel_size);
2674 /* the line may cross the window boundary */
2675 if (offset + cx > banksize) {
2676 ++bank; /* next bank */
2677 vidd_set_win_org(adp, bank*banksize);
2678 end = offset + cx - banksize;
2679 fill_io(val, adp->va_window, end/adp->va_info.vi_pixel_size);
2687 direct_fill_rect16(video_adapter_t *adp, int val, int x, int y, int cx, int cy)
2692 int offset; /* offset within window */
2696 * XXX: the function assumes that banksize is a muliple of
2697 * sizeof(u_int16_t).
2699 banksize = adp->va_window_size;
2701 cx *= sizeof(u_int16_t);
2703 pos = adp->va_line_width*y + x*sizeof(u_int16_t);
2704 if (bank != pos/banksize) {
2705 vidd_set_win_org(adp, pos);
2706 bank = pos/banksize;
2708 offset = pos%banksize;
2709 end = imin(offset + cx, banksize);
2710 fillw_io(val, adp->va_window + offset,
2711 (end - offset)/sizeof(u_int16_t));
2712 /* the line may cross the window boundary */
2713 if (offset + cx > banksize) {
2714 ++bank; /* next bank */
2715 vidd_set_win_org(adp, bank*banksize);
2716 end = offset + cx - banksize;
2717 fillw_io(val, adp->va_window, end/sizeof(u_int16_t));
2725 direct_fill_rect24(video_adapter_t *adp, int val, int x, int y, int cx, int cy)
2730 int offset; /* offset within window */
2736 b[0] = val & 0x0000ff;
2737 b[1] = (val >> 8) & 0x0000ff;
2738 b[2] = (val >> 16) & 0x0000ff;
2739 banksize = adp->va_window_size;
2743 pos = adp->va_line_width*y + x*3;
2744 if (bank != pos/banksize) {
2745 vidd_set_win_org(adp, pos);
2746 bank = pos/banksize;
2748 offset = pos%banksize;
2749 end = imin(offset + cx, banksize);
2750 for (i = 0, j = offset; j < end; i = (++i)%3, ++j) {
2751 writeb(adp->va_window + j, b[i]);
2753 /* the line may cross the window boundary */
2754 if (offset + cx >= banksize) {
2755 ++bank; /* next bank */
2756 vidd_set_win_org(adp, bank*banksize);
2758 end = offset + cx - banksize;
2759 for (; j < end; i = (++i)%3, ++j) {
2760 writeb(adp->va_window + j, b[i]);
2769 direct_fill_rect32(video_adapter_t *adp, int val, int x, int y, int cx, int cy)
2774 int offset; /* offset within window */
2778 * XXX: the function assumes that banksize is a muliple of
2779 * sizeof(u_int32_t).
2781 banksize = adp->va_window_size;
2783 cx *= sizeof(u_int32_t);
2785 pos = adp->va_line_width*y + x*sizeof(u_int32_t);
2786 if (bank != pos/banksize) {
2787 vidd_set_win_org(adp, pos);
2788 bank = pos/banksize;
2790 offset = pos%banksize;
2791 end = imin(offset + cx, banksize);
2792 filll_io(val, adp->va_window + offset,
2793 (end - offset)/sizeof(u_int32_t));
2794 /* the line may cross the window boundary */
2795 if (offset + cx > banksize) {
2796 ++bank; /* next bank */
2797 vidd_set_win_org(adp, bank*banksize);
2798 end = offset + cx - banksize;
2799 filll_io(val, adp->va_window, end/sizeof(u_int32_t));
2807 vga_fill_rect(video_adapter_t *adp, int val, int x, int y, int cx, int cy)
2809 switch (adp->va_info.vi_mem_model) {
2810 case V_INFO_MM_TEXT:
2811 /* do nothing? XXX */
2813 case V_INFO_MM_PLANAR:
2814 planar_fill_rect(adp, val, x, y, cx, cy);
2816 case V_INFO_MM_PACKED:
2817 packed_fill_rect(adp, val, x, y, cx, cy);
2819 case V_INFO_MM_DIRECT:
2820 switch (adp->va_info.vi_pixel_size) {
2821 case sizeof(u_int16_t):
2822 direct_fill_rect16(adp, val, x, y, cx, cy);
2825 direct_fill_rect24(adp, val, x, y, cx, cy);
2827 case sizeof(u_int32_t):
2828 direct_fill_rect32(adp, val, x, y, cx, cy);
2837 vga_fill_rect(video_adapter_t *adp, int val, int x, int y, int cx, int cy)
2844 vga_bitblt(video_adapter_t *adp,...)
2850 #endif /* !VGA_NO_MODE_CHANGE */
2853 get_palette(video_adapter_t *adp, int base, int count,
2854 u_char *red, u_char *green, u_char *blue, u_char *trans)
2860 if (count < 0 || base < 0 || count > 256 || base > 256 ||
2864 r = malloc(count*3, M_DEVBUF, M_WAITOK);
2867 if (vga_save_palette2(adp, base, count, r, g, b)) {
2871 copyout(r, red, count);
2872 copyout(g, green, count);
2873 copyout(b, blue, count);
2874 if (trans != NULL) {
2876 copyout(r, trans, count);
2884 set_palette(video_adapter_t *adp, int base, int count,
2885 u_char *red, u_char *green, u_char *blue, u_char *trans)
2892 if (count < 0 || base < 0 || count > 256 || base > 256 ||
2896 r = malloc(count*3, M_DEVBUF, M_WAITOK);
2899 err = copyin(red, r, count);
2901 err = copyin(green, g, count);
2903 err = copyin(blue, b, count);
2905 err = vga_load_palette2(adp, base, count, r, g, b);
2908 return (err ? ENODEV : 0);
2912 vga_dev_ioctl(video_adapter_t *adp, u_long cmd, caddr_t arg)
2915 case FBIO_GETWINORG: /* get frame buffer window origin */
2919 case FBIO_SETWINORG: /* set frame buffer window origin */
2922 case FBIO_SETDISPSTART: /* set display start address */
2923 return (set_display_start(adp,
2924 ((video_display_start_t *)arg)->x,
2925 ((video_display_start_t *)arg)->y)
2928 case FBIO_SETLINEWIDTH: /* set scan line length in pixel */
2929 return (set_line_length(adp, *(u_int *)arg) ? ENODEV : 0);
2931 case FBIO_GETPALETTE: /* get color palette */
2932 return get_palette(adp, ((video_color_palette_t *)arg)->index,
2933 ((video_color_palette_t *)arg)->count,
2934 ((video_color_palette_t *)arg)->red,
2935 ((video_color_palette_t *)arg)->green,
2936 ((video_color_palette_t *)arg)->blue,
2937 ((video_color_palette_t *)arg)->transparent);
2939 case FBIO_SETPALETTE: /* set color palette */
2940 return set_palette(adp, ((video_color_palette_t *)arg)->index,
2941 ((video_color_palette_t *)arg)->count,
2942 ((video_color_palette_t *)arg)->red,
2943 ((video_color_palette_t *)arg)->green,
2944 ((video_color_palette_t *)arg)->blue,
2945 ((video_color_palette_t *)arg)->transparent);
2947 case FBIOGTYPE: /* get frame buffer type info. */
2948 ((struct fbtype *)arg)->fb_type = fb_type(adp->va_type);
2949 ((struct fbtype *)arg)->fb_height = adp->va_info.vi_height;
2950 ((struct fbtype *)arg)->fb_width = adp->va_info.vi_width;
2951 ((struct fbtype *)arg)->fb_depth = adp->va_info.vi_depth;
2952 if ((adp->va_info.vi_depth <= 1) || (adp->va_info.vi_depth > 8))
2953 ((struct fbtype *)arg)->fb_cmsize = 0;
2955 ((struct fbtype *)arg)->fb_cmsize = 1 << adp->va_info.vi_depth;
2956 ((struct fbtype *)arg)->fb_size = adp->va_buffer_size;
2959 case FBIOGETCMAP: /* get color palette */
2960 return get_palette(adp, ((struct fbcmap *)arg)->index,
2961 ((struct fbcmap *)arg)->count,
2962 ((struct fbcmap *)arg)->red,
2963 ((struct fbcmap *)arg)->green,
2964 ((struct fbcmap *)arg)->blue, NULL);
2966 case FBIOPUTCMAP: /* set color palette */
2967 return set_palette(adp, ((struct fbcmap *)arg)->index,
2968 ((struct fbcmap *)arg)->count,
2969 ((struct fbcmap *)arg)->red,
2970 ((struct fbcmap *)arg)->green,
2971 ((struct fbcmap *)arg)->blue, NULL);
2974 return fb_commonioctl(adp, cmd, arg);
2979 dump_buffer(u_char *buf, size_t len)
2983 for(i = 0; i < len;) {
2984 printf("%02x ", buf[i]);
2985 if ((++i % 16) == 0)
2992 * Print some information about the video adapter and video modes,
2993 * with requested level of details.
2998 vga_diag(video_adapter_t *adp, int level)
3011 printf("vga: RTC equip. code:0x%02x, DCC code:0x%02x\n",
3012 rtcin(RTC_EQUIPMENT), readb(BIOS_PADDRTOVADDR(0x488)));
3013 printf("vga: CRTC:0x%x, video option:0x%02x, ",
3014 readw(BIOS_PADDRTOVADDR(0x463)),
3015 readb(BIOS_PADDRTOVADDR(0x487)));
3016 printf("rows:%d, cols:%d, font height:%d\n",
3017 readb(BIOS_PADDRTOVADDR(0x44a)),
3018 readb(BIOS_PADDRTOVADDR(0x484)) + 1,
3019 readb(BIOS_PADDRTOVADDR(0x485)));
3020 #endif /* VGA_NO_BIOS */
3021 #if !defined(VGA_NO_BIOS) && !defined(VGA_NO_MODE_CHANGE)
3022 printf("vga: param table EGA/VGA:%p", video_mode_ptr);
3023 printf(", CGA/MDA:%p\n", video_mode_ptr2);
3024 printf("vga: rows_offset:%d\n", rows_offset);
3026 #endif /* FB_DEBUG > 1 */
3028 fb_dump_adp_info(VGA_DRIVER_NAME, adp, level);
3031 if (adp->va_flags & V_ADP_MODECHANGE) {
3032 for (i = 0; bios_vmode[i].vi_mode != EOT; ++i) {
3033 if (bios_vmode[i].vi_mode == NA)
3035 if (get_mode_param(bios_vmode[i].vi_mode) == NULL)
3037 fb_dump_mode_info(VGA_DRIVER_NAME, adp, &bios_vmode[i], level);
3040 vga_get_info(adp, adp->va_initial_mode, &info); /* shouldn't fail */
3041 fb_dump_mode_info(VGA_DRIVER_NAME, adp, &info, level);
3043 #endif /* FB_DEBUG > 1 */
3045 if ((adp->va_type != KD_EGA) && (adp->va_type != KD_VGA))
3047 #if !defined(VGA_NO_BIOS) && !defined(VGA_NO_MODE_CHANGE)
3048 if (video_mode_ptr == NULL)
3049 printf("vga%d: %s: WARNING: video mode switching is not "
3050 "fully supported on this adapter\n",
3051 adp->va_unit, adp->va_name);
3056 if (adp->va_type == KD_VGA) {
3057 printf("VGA parameters upon power-up\n");
3058 dump_buffer(adpstate.regs, sizeof(adpstate.regs));
3059 printf("VGA parameters in BIOS for mode %d\n", adp->va_initial_mode);
3060 dump_buffer(adpstate2.regs, sizeof(adpstate2.regs));
3063 mp = get_mode_param(adp->va_initial_mode);
3064 if (mp == NULL) /* this shouldn't be happening */
3066 printf("EGA/VGA parameters to be used for mode %d\n", adp->va_initial_mode);
3067 dump_buffer(mp, V_MODE_PARAM_SIZE);