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 $
35 #include <sys/param.h>
36 #include <sys/systm.h>
37 #include <sys/kernel.h>
39 #include <sys/fcntl.h>
40 #include <sys/malloc.h>
42 #include <sys/thread2.h>
44 #include <bus/isa/isareg.h>
46 #include <machine/clock.h>
47 #include <machine/md_var.h>
49 #include <machine/pc/bios.h>
53 #include <vm/vm_param.h>
63 /* machine/pc/bios.h has got too much i386-specific stuff in it */
64 #ifndef BIOS_PADDRTOVADDR
65 #define BIOS_PADDRTOVADDR(x) (((x) - ISA_HOLE_START) + atdevbase)
68 vga_probe_unit(int unit, video_adapter_t *buf, int flags)
74 sw = vid_get_switch(VGA_DRIVER_NAME);
77 error = (*sw->probe)(unit, &adp, NULL, flags);
80 bcopy(adp, buf, sizeof(*buf));
85 vga_attach_unit(int unit, vga_softc_t *sc, int flags)
90 sw = vid_get_switch(VGA_DRIVER_NAME);
94 error = (*sw->probe)(unit, &sc->adp, NULL, flags);
97 return (*sw->init)(unit, sc->adp, flags);
100 /* cdev driver functions */
102 #ifdef FB_INSTALL_CDEV
107 vga_open(cdev_t dev, vga_softc_t *sc, int flag, int mode, struct ucred *cred)
111 if (mode & (O_CREAT | O_APPEND | O_TRUNC))
114 return genfbopen(&sc->gensc, sc->adp, flag, mode, cred);
118 vga_close(cdev_t dev, vga_softc_t *sc, int flag, int mode)
120 return genfbclose(&sc->gensc, sc->adp, flag, mode);
124 vga_read(cdev_t dev, vga_softc_t *sc, struct uio *uio, int flag)
126 return genfbread(&sc->gensc, sc->adp, uio, flag);
130 vga_write(cdev_t dev, vga_softc_t *sc, struct uio *uio, int flag)
132 return genfbread(&sc->gensc, sc->adp, uio, flag);
136 vga_ioctl(cdev_t dev, vga_softc_t *sc, u_long cmd, caddr_t arg, int flag,
139 return genfbioctl(&sc->gensc, sc->adp, cmd, arg, flag, cred);
143 vga_mmap(cdev_t dev, vga_softc_t *sc, vm_offset_t offset, int prot)
145 return genfbmmap(&sc->gensc, sc->adp, offset, prot);
148 #endif /* FB_INSTALL_CDEV */
152 #define probe_done(adp) ((adp)->va_flags & V_ADP_PROBED)
153 #define init_done(adp) ((adp)->va_flags & V_ADP_INITIALIZED)
154 #define config_done(adp) ((adp)->va_flags & V_ADP_REGISTERED)
157 #define V_MODE_MAP_SIZE (M_VGA_CG320 + 1)
158 #define V_MODE_PARAM_SIZE 64
160 /* video adapter state buffer */
163 #define V_STATE_SIG 0x736f6962
164 u_char regs[V_MODE_PARAM_SIZE];
166 typedef struct adp_state adp_state_t;
169 * NOTE: `va_window' should have a virtual address, but is initialized
170 * with a physical address in the following table, as verify_adapter()
171 * will perform address conversion at run-time.
173 static video_adapter_t biosadapter = {
174 0, KD_VGA, VGA_DRIVER_NAME, 0, 0, V_ADP_COLOR, IO_VGA, 32,
175 EGA_BUF_BASE, EGA_BUF_SIZE, CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE,
176 0, 0, 0, M_VGA_C80x25, M_C80x25, M_VGA_C80x25
179 /* video driver declarations */
180 static int vga_configure(int flags);
181 int (*vga_sub_configure)(int flags);
183 static int vga_nop(void);
185 static int vga_error(void);
186 static vi_probe_t vga_probe;
187 static vi_init_t vga_init;
188 static vi_get_info_t vga_get_info;
189 static vi_query_mode_t vga_query_mode;
190 static vi_set_mode_t vga_set_mode;
191 static vi_save_font_t vga_save_font;
192 static vi_load_font_t vga_load_font;
193 static vi_show_font_t vga_show_font;
194 static vi_save_palette_t vga_save_palette;
195 static vi_load_palette_t vga_load_palette;
196 static vi_set_border_t vga_set_border;
197 static vi_save_state_t vga_save_state;
198 static vi_load_state_t vga_load_state;
199 static vi_set_win_org_t vga_set_origin;
200 static vi_read_hw_cursor_t vga_read_hw_cursor;
201 static vi_set_hw_cursor_t vga_set_hw_cursor;
202 static vi_set_hw_cursor_shape_t vga_set_hw_cursor_shape;
203 static vi_blank_display_t vga_blank_display;
204 static vi_mmap_t vga_mmap_buf;
205 static vi_ioctl_t vga_dev_ioctl;
206 #ifndef VGA_NO_MODE_CHANGE
207 static vi_clear_t vga_clear;
208 static vi_fill_rect_t vga_fill_rect;
209 static vi_bitblt_t vga_bitblt;
210 #else /* VGA_NO_MODE_CHANGE */
211 #define vga_clear (vi_clear_t *)vga_error
212 #define vga_fill_rect (vi_fill_rect_t *)vga_error
213 #define vga_bitblt (vi_bitblt_t *)vga_error
215 static vi_diag_t vga_diag;
217 static video_switch_t vgavidsw = {
234 vga_set_hw_cursor_shape,
246 VIDEO_DRIVER(vga, vgavidsw, vga_configure);
248 /* VGA BIOS standard video modes */
252 static video_info_t bios_vmode[] = {
254 { M_B40x25, V_INFO_COLOR, 40, 25, 8, 8, 2, 1,
255 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
256 { M_C40x25, V_INFO_COLOR, 40, 25, 8, 8, 4, 1,
257 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
258 { M_B80x25, V_INFO_COLOR, 80, 25, 8, 8, 2, 1,
259 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
260 { M_C80x25, V_INFO_COLOR, 80, 25, 8, 8, 4, 1,
261 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
263 { M_ENH_B40x25, V_INFO_COLOR, 40, 25, 8, 14, 2, 1,
264 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
265 { M_ENH_C40x25, V_INFO_COLOR, 40, 25, 8, 14, 4, 1,
266 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
267 { M_ENH_B80x25, V_INFO_COLOR, 80, 25, 8, 14, 2, 1,
268 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
269 { M_ENH_C80x25, V_INFO_COLOR, 80, 25, 8, 14, 4, 1,
270 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
272 { M_VGA_C40x25, V_INFO_COLOR, 40, 25, 8, 16, 4, 1,
273 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
274 { M_VGA_M80x25, 0, 80, 25, 8, 16, 2, 1,
275 MDA_BUF_BASE, MDA_BUF_SIZE, MDA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
276 { M_VGA_C80x25, V_INFO_COLOR, 80, 25, 8, 16, 4, 1,
277 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
279 { M_EGAMONO80x25, 0, 80, 25, 8, 14, 2, 1,
280 MDA_BUF_BASE, MDA_BUF_SIZE, MDA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
282 { M_ENH_B80x43, 0, 80, 43, 8, 8, 2, 1,
283 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
284 { M_ENH_C80x43, V_INFO_COLOR, 80, 43, 8, 8, 4, 1,
285 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
287 { M_VGA_M80x30, 0, 80, 30, 8, 16, 2, 1,
288 MDA_BUF_BASE, MDA_BUF_SIZE, MDA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
289 { M_VGA_C80x30, V_INFO_COLOR, 80, 30, 8, 16, 4, 1,
290 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
291 { M_VGA_M80x50, 0, 80, 50, 8, 8, 2, 1,
292 MDA_BUF_BASE, MDA_BUF_SIZE, MDA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
293 { M_VGA_C80x50, V_INFO_COLOR, 80, 50, 8, 8, 4, 1,
294 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
295 { M_VGA_M80x60, 0, 80, 60, 8, 8, 2, 1,
296 MDA_BUF_BASE, MDA_BUF_SIZE, MDA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
297 { M_VGA_C80x60, V_INFO_COLOR, 80, 60, 8, 8, 4, 1,
298 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
300 #ifndef VGA_NO_MODE_CHANGE
303 { M_VGA_M90x25, 0, 90, 25, 8, 16, 2, 1,
304 MDA_BUF_BASE, MDA_BUF_SIZE, MDA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
305 { M_VGA_C90x25, V_INFO_COLOR, 90, 25, 8, 16, 4, 1,
306 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
307 { M_VGA_M90x30, 0, 90, 30, 8, 16, 2, 1,
308 MDA_BUF_BASE, MDA_BUF_SIZE, MDA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
309 { M_VGA_C90x30, V_INFO_COLOR, 90, 30, 8, 16, 4, 1,
310 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
311 { M_VGA_M90x43, 0, 90, 43, 8, 8, 2, 1,
312 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
313 { M_VGA_C90x43, V_INFO_COLOR, 90, 43, 8, 8, 4, 1,
314 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
315 { M_VGA_M90x50, 0, 90, 50, 8, 8, 2, 1,
316 MDA_BUF_BASE, MDA_BUF_SIZE, MDA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
317 { M_VGA_C90x50, V_INFO_COLOR, 90, 50, 8, 8, 4, 1,
318 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
319 { M_VGA_M90x60, 0, 90, 60, 8, 8, 2, 1,
320 MDA_BUF_BASE, MDA_BUF_SIZE, MDA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
321 { M_VGA_C90x60, V_INFO_COLOR, 90, 60, 8, 8, 4, 1,
322 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
323 #endif /* VGA_WIDTH90 */
326 { M_BG320, V_INFO_COLOR | V_INFO_GRAPHICS, 320, 200, 8, 8, 2, 1,
327 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_CGA },
328 { M_CG320, V_INFO_COLOR | V_INFO_GRAPHICS, 320, 200, 8, 8, 2, 1,
329 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_CGA },
330 { M_BG640, V_INFO_COLOR | V_INFO_GRAPHICS, 640, 200, 8, 8, 1, 1,
331 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_CGA },
333 { M_CG320_D, V_INFO_COLOR | V_INFO_GRAPHICS, 320, 200, 8, 8, 4, 4,
334 GRAPHICS_BUF_BASE, GRAPHICS_BUF_SIZE, GRAPHICS_BUF_SIZE, 0, 0,
336 { M_CG640_E, V_INFO_COLOR | V_INFO_GRAPHICS, 640, 200, 8, 8, 4, 4,
337 GRAPHICS_BUF_BASE, GRAPHICS_BUF_SIZE, GRAPHICS_BUF_SIZE, 0, 0 ,
339 { M_EGAMONOAPA, V_INFO_GRAPHICS, 640, 350, 8, 14, 4, 4,
340 GRAPHICS_BUF_BASE, GRAPHICS_BUF_SIZE, 64*1024, 0, 0 ,
342 { M_ENHMONOAPA2,V_INFO_GRAPHICS, 640, 350, 8, 14, 4, 4,
343 GRAPHICS_BUF_BASE, GRAPHICS_BUF_SIZE, GRAPHICS_BUF_SIZE, 0, 0 ,
345 { M_CG640x350, V_INFO_COLOR | V_INFO_GRAPHICS, 640, 350, 8, 14, 2, 2,
346 GRAPHICS_BUF_BASE, GRAPHICS_BUF_SIZE, GRAPHICS_BUF_SIZE, 0, 0 ,
348 { M_ENH_CG640, V_INFO_COLOR | V_INFO_GRAPHICS, 640, 350, 8, 14, 4, 4,
349 GRAPHICS_BUF_BASE, GRAPHICS_BUF_SIZE, GRAPHICS_BUF_SIZE, 0, 0 ,
352 { M_BG640x480, V_INFO_COLOR | V_INFO_GRAPHICS, 640, 480, 8, 16, 4, 4,
353 GRAPHICS_BUF_BASE, GRAPHICS_BUF_SIZE, GRAPHICS_BUF_SIZE, 0, 0 ,
355 { M_CG640x480, V_INFO_COLOR | V_INFO_GRAPHICS, 640, 480, 8, 16, 4, 4,
356 GRAPHICS_BUF_BASE, GRAPHICS_BUF_SIZE, GRAPHICS_BUF_SIZE, 0, 0 ,
358 { M_VGA_CG320, V_INFO_COLOR | V_INFO_GRAPHICS, 320, 200, 8, 8, 8, 1,
359 GRAPHICS_BUF_BASE, GRAPHICS_BUF_SIZE, GRAPHICS_BUF_SIZE, 0, 0,
360 V_INFO_MM_PACKED, 1 },
361 { M_VGA_MODEX, V_INFO_COLOR | V_INFO_GRAPHICS, 320, 240, 8, 8, 8, 4,
362 GRAPHICS_BUF_BASE, GRAPHICS_BUF_SIZE, GRAPHICS_BUF_SIZE, 0, 0,
364 #endif /* VGA_NO_MODE_CHANGE */
369 static int vga_init_done = FALSE;
370 #if !defined(VGA_NO_BIOS) && !defined(VGA_NO_MODE_CHANGE)
371 static u_char *video_mode_ptr = NULL;
373 static u_char *mode_map[V_MODE_MAP_SIZE];
374 static adp_state_t adpstate;
375 static adp_state_t adpstate2;
376 static int rows_offset = 1;
378 /* local macros and functions */
379 #define BIOS_SADDRTOLADDR(p) ((((p) & 0xffff0000) >> 12) + ((p) & 0x0000ffff))
381 #if !defined(VGA_NO_BIOS) && !defined(VGA_NO_MODE_CHANGE)
382 static void map_mode_table(u_char **, u_char *);
383 static int map_mode_num(int);
385 static int map_bios_mode_num(int);
386 static u_char *get_mode_param(int);
387 static int verify_adapter(video_adapter_t *);
388 static void update_adapter_info(video_adapter_t *, video_info_t *);
389 static int probe_adapters(void);
390 static int set_line_length(video_adapter_t *, int);
391 static int set_display_start(video_adapter_t *, int, int);
393 #ifndef VGA_NO_MODE_CHANGE
395 static void set_width90(adp_state_t *);
397 #endif /* !VGA_NO_MODE_CHANGE */
399 #ifndef VGA_NO_FONT_LOADING
400 #define PARAM_BUFSIZE 6
401 static void set_font_mode(video_adapter_t *, u_char *);
402 static void set_normal_mode(video_adapter_t *, u_char *);
405 #ifndef VGA_NO_MODE_CHANGE
406 static void filll_io(int, vm_offset_t, size_t);
407 static void planar_fill(video_adapter_t *, int);
408 static void packed_fill(video_adapter_t *, int);
409 static void direct_fill(video_adapter_t *, int);
411 static void planar_fill_rect(video_adapter_t *, int, int, int, int, int);
412 static void packed_fill_rect(video_adapter_t *, int, int, int, int, int);
413 static void direct_fill_rect16(video_adapter_t *, int, int, int, int, int);
414 static void direct_fill_rect24(video_adapter_t *, int, int, int, int, int);
415 static void direct_fill_rect32(video_adapter_t *, int, int, int, int, int);
417 #endif /* !VGA_NO_MODE_CHANGE */
419 static void dump_buffer(u_char *, size_t);
421 #define ISMAPPED(pa, width) \
422 (((pa) <= (u_long)0x1000 - (width)) \
423 || ((pa) >= ISA_HOLE_START && (pa) <= 0x100000 - (width)))
425 #define prologue(adp, flag, err) \
426 if (!vga_init_done || !((adp)->va_flags & (flag))) \
429 /* a backdoor for the console driver */
431 vga_configure(int flags)
434 if (probe_done(&biosadapter)) {
435 biosadapter.va_flags |= V_ADP_INITIALIZED;
436 if (!config_done(&biosadapter) && !(vid_register(&biosadapter) < 0))
437 biosadapter.va_flags |= V_ADP_REGISTERED;
439 if (vga_sub_configure != NULL)
440 (*vga_sub_configure)(flags);
445 /* local subroutines */
447 #if !defined(VGA_NO_BIOS) && !defined(VGA_NO_MODE_CHANGE)
448 /* construct the mode parameter map (accept 40x25, 80x25 and 80x30 modes) */
450 map_mode_table(u_char *map[], u_char *table)
454 for(i = 0; i < V_MODE_MAP_SIZE; ++i) {
455 map[i] = table + i*V_MODE_PARAM_SIZE;
457 if ((map[i][0] == 40 && map[i][1] == 24) ||
458 (map[i][0] == 80 && (map[i][1] == 24 || map[i][1] == 29)))
464 #endif /* !VGA_NO_BIOS && !VGA_NO_MODE_CHANGE */
466 #if !defined(VGA_NO_BIOS) && !defined(VGA_NO_MODE_CHANGE)
467 /* map the non-standard video mode to a known mode number */
469 map_mode_num(int mode)
475 { M_ENH_B80x43, M_ENH_B80x25 },
476 { M_ENH_C80x43, M_ENH_C80x25 },
477 { M_VGA_M80x30, M_VGA_M80x25 },
478 { M_VGA_C80x30, M_VGA_C80x25 },
479 { M_VGA_M80x50, M_VGA_M80x25 },
480 { M_VGA_C80x50, M_VGA_C80x25 },
481 { M_VGA_M80x60, M_VGA_M80x25 },
482 { M_VGA_C80x60, M_VGA_C80x25 },
484 { M_VGA_M90x25, M_VGA_M80x25 },
485 { M_VGA_C90x25, M_VGA_C80x25 },
486 { M_VGA_M90x30, M_VGA_M80x25 },
487 { M_VGA_C90x30, M_VGA_C80x25 },
488 { M_VGA_M90x43, M_ENH_B80x25 },
489 { M_VGA_C90x43, M_ENH_C80x25 },
490 { M_VGA_M90x50, M_VGA_M80x25 },
491 { M_VGA_C90x50, M_VGA_C80x25 },
492 { M_VGA_M90x60, M_VGA_M80x25 },
493 { M_VGA_C90x60, M_VGA_C80x25 },
495 { M_VGA_MODEX, M_VGA_CG320 },
499 for (i = 0; i < sizeof(mode_map)/sizeof(mode_map[0]); ++i) {
500 if (mode_map[i].from == mode)
501 return mode_map[i].to;
505 #endif /* !VGA_NO_BIOS && !VGA_NO_MODE_CHANGE */
507 /* turn the BIOS video number into our video mode number */
509 map_bios_mode_num(int bios_mode)
511 static int vga_modes[20] = {
512 M_VGA_C40x25, M_VGA_C40x25, /* 0, 1 */
513 M_VGA_C80x25, M_VGA_C80x25, /* 2, 3 */
516 M_VGA_M80x25, /* 7 */
522 M_BG640x480, M_CG640x480,
526 if (bios_mode < sizeof(vga_modes)/sizeof(vga_modes[0]))
527 return vga_modes[bios_mode];
532 /* look up a parameter table entry */
534 get_mode_param(int mode)
536 #if !defined(VGA_NO_BIOS) && !defined(VGA_NO_MODE_CHANGE)
537 if (mode >= V_MODE_MAP_SIZE)
538 mode = map_mode_num(mode);
540 if ((mode >= 0) && (mode < V_MODE_MAP_SIZE))
541 return mode_map[mode];
547 verify_adapter(video_adapter_t *adp)
551 #if !defined(VGA_NO_BIOS) && !defined(VGA_NO_MODE_CHANGE)
555 buf = BIOS_PADDRTOVADDR(adp->va_window);
558 if (readw(buf) != 0xA55A)
566 adp->va_flags |= V_ADP_STATELOAD | V_ADP_STATESAVE | V_ADP_PALETTE |
569 #if !defined(VGA_NO_BIOS) && !defined(VGA_NO_MODE_CHANGE)
570 /* get the BIOS video mode pointer */
571 p = *(u_int32_t *)BIOS_PADDRTOVADDR(0x4a8);
572 p = BIOS_SADDRTOLADDR(p);
573 if (ISMAPPED(p, sizeof(u_int32_t))) {
574 p = *(u_int32_t *)BIOS_PADDRTOVADDR(p);
575 p = BIOS_SADDRTOLADDR(p);
576 if (ISMAPPED(p, V_MODE_PARAM_SIZE))
577 video_mode_ptr = (u_char *)BIOS_PADDRTOVADDR(p);
585 update_adapter_info(video_adapter_t *adp, video_info_t *info)
587 adp->va_flags |= V_ADP_COLOR;
588 adp->va_window = BIOS_PADDRTOVADDR(info->vi_window);
589 adp->va_window_size = info->vi_window_size;
590 adp->va_window_gran = info->vi_window_gran;
591 adp->va_window_orig = 0;
593 adp->va_buffer = info->vi_buffer;
594 adp->va_buffer_size = info->vi_buffer_size;
595 if (info->vi_mem_model == V_INFO_MM_VGAX) {
596 adp->va_line_width = info->vi_width/2;
597 } else if (info->vi_flags & V_INFO_GRAPHICS) {
598 switch (info->vi_depth/info->vi_planes) {
600 adp->va_line_width = info->vi_width/8;
603 adp->va_line_width = info->vi_width/4;
606 adp->va_line_width = info->vi_width/2;
609 default: /* shouldn't happen */
610 adp->va_line_width = info->vi_width;
614 adp->va_line_width = info->vi_width;
616 adp->va_disp_start.x = 0;
617 adp->va_disp_start.y = 0;
618 bcopy(info, &adp->va_info, sizeof(adp->va_info));
621 /* probe video adapters and return the number of detected adapters */
625 video_adapter_t *adp;
627 #if !defined(VGA_NO_BIOS) && !defined(VGA_NO_MODE_CHANGE)
632 /* do this test only once */
635 vga_init_done = TRUE;
638 * Check BIOS data area.
639 * The VGA BIOS has more sophisticated mechanism and has this
640 * information in BIOSDATA_DCCINDEX (40:8a), but it also maintains
641 * compatibility with the EGA BIOS by updating BIOSDATA_VIDEOSWITCH.
645 * XXX: we don't use BIOSDATA_EQUIPMENT, since it is not a dead
646 * copy of RTC_EQUIPMENT. Bits 4 and 5 of ETC_EQUIPMENT are
647 * zeros for VGA. However, VGA BIOS sets these bits in
648 * BIOSDATA_EQUIPMENT according to the monitor type detected.
651 if ((readb(BIOS_PADDRTOVADDR(0x488)) & 0x0f) != 0x09)
653 #endif /* VGA_NO_BIOS */
655 if (verify_adapter(&biosadapter) != 0)
658 biosadapter.va_flags |= V_ADP_PROBED;
660 biosadapter.va_initial_bios_mode = readb(BIOS_PADDRTOVADDR(0x449));
661 biosadapter.va_mode = biosadapter.va_initial_mode =
662 map_bios_mode_num(biosadapter.va_initial_bios_mode);
666 * Ensure a zero start address. This is mainly to recover after
667 * switching from pcvt using userconfig(). The registers are w/o
668 * for old hardware so it's too hard to relocate the active screen
670 * This must be done before vga_save_state() for VGA.
677 /* the video mode parameter table in VGA BIOS */
678 /* NOTE: there can be only one VGA recognized by the video BIOS.
681 bzero(mode_map, sizeof(mode_map));
682 vga_save_state(adp, &adpstate, sizeof(adpstate));
683 for(i = 0; i < 16; i++)
684 adp->va_palette_regs[i] = adpstate.regs[35 + i];
685 #if defined(VGA_NO_BIOS) || defined(VGA_NO_MODE_CHANGE)
686 mode_map[adp->va_initial_mode] = adpstate.regs;
688 #else /* VGA_NO_BIOS || VGA_NO_MODE_CHANGE */
689 if (video_mode_ptr == NULL) {
690 mode_map[adp->va_initial_mode] = adpstate.regs;
693 /* discard modes that we are not familiar with */
694 map_mode_table(mode_map, video_mode_ptr);
695 mp = get_mode_param(adp->va_initial_mode);
696 #if !defined(VGA_KEEP_POWERON_MODE)
698 bcopy(mp, adpstate2.regs, sizeof(adpstate2.regs));
699 rows_offset = adpstate.regs[1] + 1 - mp[1];
703 mode_map[adp->va_initial_mode] = adpstate.regs;
707 #endif /* VGA_NO_BIOS || VGA_NO_MODE_CHANGE */
709 #ifndef VGA_NO_MODE_CHANGE
710 adp->va_flags |= V_ADP_MODECHANGE;
712 #ifndef VGA_NO_FONT_LOADING
713 adp->va_flags |= V_ADP_FONT;
716 /* XXX remove conflicting modes */
717 for (i = 0; i < M_VGA_CG320; i++) {
718 if (vga_get_info(&biosadapter, i, &info))
720 if ((info.vi_flags & V_INFO_COLOR) != V_ADP_COLOR)
725 vga_get_info(&biosadapter, biosadapter.va_initial_mode, &info);
726 info.vi_flags &= ~V_INFO_LINEAR; /* XXX */
727 update_adapter_info(&biosadapter, &info);
730 * XXX: we should verify the following values for the primary adapter...
731 * crtc I/O port address: *(u_int16_t *)BIOS_PADDRTOVADDR(0x463);
732 * color/mono display: (*(u_int8_t *)BIOS_PADDRTOVADDR(0x487) & 0x02)
734 * columns: *(u_int8_t *)BIOS_PADDRTOVADDR(0x44a);
735 * rows: *(u_int8_t *)BIOS_PADDRTOVADDR(0x484);
736 * font size: *(u_int8_t *)BIOS_PADDRTOVADDR(0x485);
737 * buffer size: *(u_int16_t *)BIOS_PADDRTOVADDR(0x44c);
743 /* set the scan line length in pixel */
745 set_line_length(video_adapter_t *adp, int pixel)
748 int ppw; /* pixels per word */
749 int bpl; /* bytes per line */
752 mp = get_mode_param(adp->va_mode);
756 switch (adp->va_info.vi_mem_model) {
757 case V_INFO_MM_PLANAR:
758 ppw = 16/(adp->va_info.vi_depth/adp->va_info.vi_planes);
759 count = (pixel + ppw - 1)/ppw/2;
760 bpl = ((pixel + ppw - 1)/ppw/2)*4;
762 case V_INFO_MM_PACKED:
763 count = (pixel + 7)/8;
764 bpl = ((pixel + 7)/8)*8;
767 count = (pixel + 7)/8; /* columns */
768 bpl = (pixel + 7)/8; /* columns */
774 if (mp[10 + 0x17] & 0x40) /* CRTC mode control reg */
775 count *= 2; /* byte mode */
778 adp->va_line_width = bpl;
784 set_display_start(video_adapter_t *adp, int x, int y)
786 int off; /* byte offset (graphics mode)/word offset (text mode) */
787 int poff; /* pixel offset */
788 int roff; /* row offset */
789 int ppb; /* pixels per byte */
791 if (adp->va_info.vi_flags & V_INFO_GRAPHICS) {
792 ppb = 8/(adp->va_info.vi_depth/adp->va_info.vi_planes);
793 off = y*adp->va_line_width + x/ppb;
802 off = y/adp->va_info.vi_cheight*adp->va_line_width + x/ppb;
803 roff = y%adp->va_info.vi_cheight;
804 /* FIXME: is this correct? XXX */
812 outb(CRTC, 0xc); /* high */
813 outb(CRTC + 1, off >> 8);
814 outb(CRTC, 0xd); /* low */
815 outb(CRTC + 1, off & 0xff);
817 /* horizontal pel pan */
819 outb(ATC, 0x13 | 0x20);
824 /* preset raw scan */
826 outb(CRTC + 1, roff);
828 adp->va_disp_start.x = x;
829 adp->va_disp_start.y = y;
833 #ifndef VGA_NO_MODE_CHANGE
834 #if defined(__i386__) || defined(__x86_64__) /* XXX */
836 fill(int val, void *d, size_t size)
843 #endif /* __i386__ || __x86_64__ */
846 filll_io(int val, vm_offset_t d, size_t size)
850 d += sizeof(u_int32_t);
853 #endif /* !VGA_NO_MODE_CHANGE */
872 vga_probe(int unit, video_adapter_t **adpp, void *arg, int flags)
878 *adpp = &biosadapter;
884 vga_init(int unit, video_adapter_t *adp, int flags)
886 if ((unit != 0) || (adp == NULL) || !probe_done(adp))
889 if (!init_done(adp)) {
890 /* nothing to do really... */
891 adp->va_flags |= V_ADP_INITIALIZED;
894 if (!config_done(adp)) {
895 if (vid_register(adp) < 0)
897 adp->va_flags |= V_ADP_REGISTERED;
899 if (vga_sub_configure != NULL)
900 (*vga_sub_configure)(0);
907 * Return the video_info structure of the requested video mode.
910 vga_get_info(video_adapter_t *adp, int mode, video_info_t *info)
917 #ifndef VGA_NO_MODE_CHANGE
918 if (adp->va_flags & V_ADP_MODECHANGE) {
920 * If the parameter table entry for this mode is not found,
921 * the mode is not supported...
923 if (get_mode_param(mode) == NULL)
926 #endif /* VGA_NO_MODE_CHANGE */
929 * Even if we don't support video mode switching on this adapter,
930 * the information on the initial (thus current) video mode
931 * should be made available.
933 if (mode != adp->va_initial_mode)
937 for (i = 0; bios_vmode[i].vi_mode != EOT; ++i) {
938 if (bios_vmode[i].vi_mode == NA)
940 if (mode == bios_vmode[i].vi_mode) {
941 *info = bios_vmode[i];
943 info->vi_buffer_size = info->vi_window_size*info->vi_planes;
952 * Find a video mode matching the requested parameters.
953 * Fields filled with 0 are considered "don't care" fields and
957 vga_query_mode(video_adapter_t *adp, video_info_t *info)
964 for (i = 0; bios_vmode[i].vi_mode != EOT; ++i) {
965 if (bios_vmode[i].vi_mode == NA)
968 if ((info->vi_width != 0)
969 && (info->vi_width != bios_vmode[i].vi_width))
971 if ((info->vi_height != 0)
972 && (info->vi_height != bios_vmode[i].vi_height))
974 if ((info->vi_cwidth != 0)
975 && (info->vi_cwidth != bios_vmode[i].vi_cwidth))
977 if ((info->vi_cheight != 0)
978 && (info->vi_cheight != bios_vmode[i].vi_cheight))
980 if ((info->vi_depth != 0)
981 && (info->vi_depth != bios_vmode[i].vi_depth))
983 if ((info->vi_planes != 0)
984 && (info->vi_planes != bios_vmode[i].vi_planes))
986 /* XXX: should check pixel format, memory model */
987 if ((info->vi_flags != 0)
988 && (info->vi_flags != bios_vmode[i].vi_flags))
991 /* verify if this mode is supported on this adapter */
992 if (vga_get_info(adp, bios_vmode[i].vi_mode, info))
1001 * Change the video mode.
1004 #ifndef VGA_NO_MODE_CHANGE
1007 set_width90(adp_state_t *params)
1010 * Based on code submitted by Kelly Yancey (kbyanc@freedomnet.com)
1011 * and alexv@sui.gda.itesm.mx.
1013 params->regs[5] |= 1; /* toggle 8 pixel wide fonts */
1014 params->regs[10+0x0] = 0x6b;
1015 params->regs[10+0x1] = 0x59;
1016 params->regs[10+0x2] = 0x5a;
1017 params->regs[10+0x3] = 0x8e;
1018 params->regs[10+0x4] = 0x5e;
1019 params->regs[10+0x5] = 0x8a;
1020 params->regs[10+0x13] = 45;
1021 params->regs[35+0x13] = 0;
1023 #endif /* VGA_WIDTH90 */
1024 #endif /* !VGA_NO_MODE_CHANGE */
1027 vga_set_mode(video_adapter_t *adp, int mode)
1029 #ifndef VGA_NO_MODE_CHANGE
1033 prologue(adp, V_ADP_MODECHANGE, ENODEV);
1035 if (vga_get_info(adp, mode, &info))
1039 kprintf("vga_set_mode(): setting mode %d\n", mode);
1042 params.sig = V_STATE_SIG;
1043 bcopy(get_mode_param(mode), params.regs, sizeof(params.regs));
1047 case M_VGA_C90x60: case M_VGA_M90x60:
1048 set_width90(¶ms);
1051 case M_VGA_C80x60: case M_VGA_M80x60:
1052 params.regs[2] = 0x08;
1053 params.regs[19] = 0x47;
1057 case M_VGA_C90x30: case M_VGA_M90x30:
1058 set_width90(¶ms);
1061 case M_VGA_C80x30: case M_VGA_M80x30:
1062 params.regs[19] = 0x4f;
1064 params.regs[9] |= 0xc0;
1065 params.regs[16] = 0x08;
1066 params.regs[17] = 0x3e;
1067 params.regs[26] = 0xea;
1068 params.regs[28] = 0xdf;
1069 params.regs[31] = 0xe7;
1070 params.regs[32] = 0x04;
1074 case M_VGA_C90x43: case M_VGA_M90x43:
1075 set_width90(¶ms);
1078 case M_ENH_C80x43: case M_ENH_B80x43:
1079 params.regs[28] = 87;
1083 case M_VGA_C90x50: case M_VGA_M90x50:
1084 set_width90(¶ms);
1087 case M_VGA_C80x50: case M_VGA_M80x50:
1090 params.regs[19] = 7;
1094 case M_VGA_C90x25: case M_VGA_M90x25:
1095 set_width90(¶ms);
1098 case M_VGA_C40x25: case M_VGA_C80x25:
1100 case M_B40x25: case M_C40x25:
1101 case M_B80x25: case M_C80x25:
1102 case M_ENH_B40x25: case M_ENH_C40x25:
1103 case M_ENH_B80x25: case M_ENH_C80x25:
1104 case M_EGAMONO80x25:
1107 vga_load_state(adp, ¶ms);
1111 /* "unchain" the VGA mode */
1112 params.regs[5-1+0x04] &= 0xf7;
1113 params.regs[5-1+0x04] |= 0x04;
1114 /* turn off doubleword mode */
1115 params.regs[10+0x14] &= 0xbf;
1116 /* turn off word addressing */
1117 params.regs[10+0x17] |= 0x40;
1118 /* set logical screen width */
1119 params.regs[10+0x13] = 80;
1121 params.regs[10+0x11] = 0x2c;
1122 params.regs[10+0x06] = 0x0d;
1123 params.regs[10+0x07] = 0x3e;
1124 params.regs[10+0x10] = 0xea;
1125 params.regs[10+0x11] = 0xac;
1126 params.regs[10+0x12] = 0xdf;
1127 params.regs[10+0x15] = 0xe7;
1128 params.regs[10+0x16] = 0x06;
1129 /* set vertical sync polarity to reflect aspect ratio */
1130 params.regs[9] = 0xe3;
1133 case M_BG320: case M_CG320: case M_BG640:
1134 case M_CG320_D: case M_CG640_E:
1135 case M_CG640x350: case M_ENH_CG640:
1136 case M_BG640x480: case M_CG640x480: case M_VGA_CG320:
1139 vga_load_state(adp, ¶ms);
1146 adp->va_mode = mode;
1147 info.vi_flags &= ~V_INFO_LINEAR; /* XXX */
1148 update_adapter_info(adp, &info);
1150 /* move hardware cursor out of the way */
1151 (*vidsw[adp->va_index]->set_hw_cursor)(adp, -1, -1);
1154 #else /* VGA_NO_MODE_CHANGE */
1156 #endif /* VGA_NO_MODE_CHANGE */
1159 #ifndef VGA_NO_FONT_LOADING
1162 set_font_mode(video_adapter_t *adp, u_char *buf)
1166 /* save register values */
1167 outb(TSIDX, 0x02); buf[0] = inb(TSREG);
1168 outb(TSIDX, 0x04); buf[1] = inb(TSREG);
1169 outb(GDCIDX, 0x04); buf[2] = inb(GDCREG);
1170 outb(GDCIDX, 0x05); buf[3] = inb(GDCREG);
1171 outb(GDCIDX, 0x06); buf[4] = inb(GDCREG);
1173 outb(ATC, 0x10); buf[5] = inb(ATC + 1);
1175 /* setup vga for loading fonts */
1176 inb(CRTC + 6); /* reset flip-flop */
1177 outb(ATC, 0x10); outb(ATC, buf[5] & ~0x01);
1178 inb(CRTC + 6); /* reset flip-flop */
1179 outb(ATC, 0x20); /* enable palette */
1181 #ifdef VGA_ALT_SEQACCESS
1182 outw(TSIDX, 0x0100);
1184 outw(TSIDX, 0x0402);
1185 outw(TSIDX, 0x0704);
1186 #ifdef VGA_ALT_SEQACCESS
1187 outw(TSIDX, 0x0300);
1189 outw(GDCIDX, 0x0204);
1190 outw(GDCIDX, 0x0005);
1191 outw(GDCIDX, 0x0406); /* addr = a0000, 64kb */
1197 set_normal_mode(video_adapter_t *adp, u_char *buf)
1201 /* setup vga for normal operation mode again */
1202 inb(CRTC + 6); /* reset flip-flop */
1203 outb(ATC, 0x10); outb(ATC, buf[5]);
1204 inb(CRTC + 6); /* reset flip-flop */
1205 outb(ATC, 0x20); /* enable palette */
1207 #ifdef VGA_ALT_SEQACCESS
1208 outw(TSIDX, 0x0100);
1210 outw(TSIDX, 0x0002 | (buf[0] << 8));
1211 outw(TSIDX, 0x0004 | (buf[1] << 8));
1212 #ifdef VGA_ALT_SEQACCESS
1213 outw(TSIDX, 0x0300);
1215 outw(GDCIDX, 0x0004 | (buf[2] << 8));
1216 outw(GDCIDX, 0x0005 | (buf[3] << 8));
1217 outw(GDCIDX, 0x0006 | (((buf[4] & 0x03) | 0x0c)<<8));
1222 #endif /* VGA_NO_FONT_LOADING */
1226 * Read the font data in the requested font page from the video adapter.
1229 vga_save_font(video_adapter_t *adp, int page, int fontsize, u_char *data,
1232 #ifndef VGA_NO_FONT_LOADING
1233 u_char buf[PARAM_BUFSIZE];
1234 vm_offset_t segment;
1236 #ifdef VGA_ALT_SEQACCESS
1240 prologue(adp, V_ADP_FONT, ENODEV);
1242 if (fontsize < 14) {
1245 } else if (fontsize >= 32) {
1247 } else if (fontsize >= 16) {
1255 if (page < 0 || page >= 8)
1257 segment = FONT_BUF + 0x4000*page;
1261 #ifdef VGA_ALT_SEQACCESS
1263 outb(TSIDX, 0x00); outb(TSREG, 0x01);
1264 outb(TSIDX, 0x01); val = inb(TSREG); /* disable screen */
1265 outb(TSIDX, 0x01); outb(TSREG, val | 0x20);
1266 outb(TSIDX, 0x00); outb(TSREG, 0x03);
1270 set_font_mode(adp, buf);
1271 if (fontsize == 32) {
1272 bcopy_fromio((uintptr_t)segment + ch*32, data, fontsize*count);
1274 for (c = ch; count > 0; ++c, --count) {
1275 bcopy_fromio((uintptr_t)segment + c*32, data, fontsize);
1279 set_normal_mode(adp, buf);
1281 #ifdef VGA_ALT_SEQACCESS
1283 outb(TSIDX, 0x00); outb(TSREG, 0x01);
1284 outb(TSIDX, 0x01); outb(TSREG, val & 0xdf); /* enable screen */
1285 outb(TSIDX, 0x00); outb(TSREG, 0x03);
1290 #else /* VGA_NO_FONT_LOADING */
1292 #endif /* VGA_NO_FONT_LOADING */
1297 * Set the font data in the requested font page.
1298 * NOTE: it appears that some recent video adapters do not support
1299 * the font page other than 0... XXX
1302 vga_load_font(video_adapter_t *adp, int page, int fontsize, u_char *data,
1305 #ifndef VGA_NO_FONT_LOADING
1306 u_char buf[PARAM_BUFSIZE];
1307 vm_offset_t segment;
1309 #ifdef VGA_ALT_SEQACCESS
1313 prologue(adp, V_ADP_FONT, ENODEV);
1315 if (fontsize < 14) {
1318 } else if (fontsize >= 32) {
1320 } else if (fontsize >= 16) {
1328 if (page < 0 || page >= 8)
1330 segment = FONT_BUF + 0x4000*page;
1334 #ifdef VGA_ALT_SEQACCESS
1336 outb(TSIDX, 0x00); outb(TSREG, 0x01);
1337 outb(TSIDX, 0x01); val = inb(TSREG); /* disable screen */
1338 outb(TSIDX, 0x01); outb(TSREG, val | 0x20);
1339 outb(TSIDX, 0x00); outb(TSREG, 0x03);
1343 set_font_mode(adp, buf);
1344 if (fontsize == 32) {
1345 bcopy_toio(data, (uintptr_t)segment + ch*32, fontsize*count);
1347 for (c = ch; count > 0; ++c, --count) {
1348 bcopy_toio(data, (uintptr_t)segment + c*32, fontsize);
1352 set_normal_mode(adp, buf);
1354 #ifdef VGA_ALT_SEQACCESS
1356 outb(TSIDX, 0x00); outb(TSREG, 0x01);
1357 outb(TSIDX, 0x01); outb(TSREG, val & 0xdf); /* enable screen */
1358 outb(TSIDX, 0x00); outb(TSREG, 0x03);
1363 #else /* VGA_NO_FONT_LOADING */
1365 #endif /* VGA_NO_FONT_LOADING */
1370 * Activate the requested font page.
1371 * NOTE: it appears that some recent video adapters do not support
1372 * the font page other than 0... XXX
1375 vga_show_font(video_adapter_t *adp, int page)
1377 #ifndef VGA_NO_FONT_LOADING
1378 static u_char cg[] = { 0x00, 0x05, 0x0a, 0x0f, 0x30, 0x35, 0x3a, 0x3f };
1380 prologue(adp, V_ADP_FONT, ENODEV);
1381 if (page < 0 || page >= 8)
1385 outb(TSIDX, 0x03); outb(TSREG, cg[page]);
1389 #else /* VGA_NO_FONT_LOADING */
1391 #endif /* VGA_NO_FONT_LOADING */
1396 * Read DAC values. The values have expressed in 8 bits.
1401 vga_save_palette(video_adapter_t *adp, u_char *palette)
1405 prologue(adp, V_ADP_PALETTE, ENODEV);
1408 * We store 8 bit values in the palette buffer, while the standard
1409 * VGA has 6 bit DAC .
1411 outb(PALRADR, 0x00);
1412 for (i = 0; i < 256*3; ++i)
1413 palette[i] = inb(PALDATA) << 2;
1414 inb(CRTC + 6); /* reset flip/flop */
1419 vga_save_palette2(video_adapter_t *adp, int base, int count,
1420 u_char *r, u_char *g, u_char *b)
1424 prologue(adp, V_ADP_PALETTE, ENODEV);
1426 outb(PALRADR, base);
1427 for (i = 0; i < count; ++i) {
1428 r[i] = inb(PALDATA) << 2;
1429 g[i] = inb(PALDATA) << 2;
1430 b[i] = inb(PALDATA) << 2;
1432 inb(CRTC + 6); /* reset flip/flop */
1443 vga_load_palette(video_adapter_t *adp, const u_char *palette)
1447 prologue(adp, V_ADP_PALETTE, ENODEV);
1449 outb(PIXMASK, 0xff); /* no pixelmask */
1450 outb(PALWADR, 0x00);
1451 for (i = 0; i < 256*3; ++i)
1452 outb(PALDATA, palette[i] >> 2);
1453 inb(CRTC + 6); /* reset flip/flop */
1454 outb(ATC, 0x20); /* enable palette */
1459 vga_load_palette2(video_adapter_t *adp, int base, int count,
1460 u_char *r, u_char *g, u_char *b)
1464 prologue(adp, V_ADP_PALETTE, ENODEV);
1466 outb(PIXMASK, 0xff); /* no pixelmask */
1467 outb(PALWADR, base);
1468 for (i = 0; i < count; ++i) {
1469 outb(PALDATA, r[i] >> 2);
1470 outb(PALDATA, g[i] >> 2);
1471 outb(PALDATA, b[i] >> 2);
1473 inb(CRTC + 6); /* reset flip/flop */
1474 outb(ATC, 0x20); /* enable palette */
1480 * Change the border color.
1483 vga_set_border(video_adapter_t *adp, int color)
1485 prologue(adp, V_ADP_BORDER, ENODEV);
1487 inb(CRTC + 6); /* reset flip-flop */
1488 outb(ATC, 0x31); outb(ATC, color & 0xff);
1495 * Read video register values.
1496 * NOTE: this function only reads the standard VGA registers.
1497 * any extra/extended registers of SVGA adapters are not saved.
1500 vga_save_state(video_adapter_t *adp, void *p, size_t size)
1508 /* return the required buffer size */
1509 prologue(adp, V_ADP_STATESAVE, 0);
1510 return sizeof(adp_state_t);
1512 prologue(adp, V_ADP_STATESAVE, ENODEV);
1513 if (size < sizeof(adp_state_t))
1516 ((adp_state_t *)p)->sig = V_STATE_SIG;
1517 buf = ((adp_state_t *)p)->regs;
1518 bzero(buf, V_MODE_PARAM_SIZE);
1523 outb(TSIDX, 0x00); outb(TSREG, 0x01); /* stop sequencer */
1524 for (i = 0, j = 5; i < 4; i++) {
1526 buf[j++] = inb(TSREG);
1528 buf[9] = inb(MISC + 10); /* dot-clock */
1529 outb(TSIDX, 0x00); outb(TSREG, 0x03); /* start sequencer */
1531 for (i = 0, j = 10; i < 25; i++) { /* crtc */
1533 buf[j++] = inb(crtc_addr + 1);
1535 for (i = 0, j = 35; i < 20; i++) { /* attribute ctrl */
1536 inb(crtc_addr + 6); /* reset flip-flop */
1538 buf[j++] = inb(ATC + 1);
1540 for (i = 0, j = 55; i < 9; i++) { /* graph data ctrl */
1542 buf[j++] = inb(GDCREG);
1544 inb(crtc_addr + 6); /* reset flip-flop */
1545 outb(ATC, 0x20); /* enable palette */
1550 if (vga_get_info(adp, adp->va_mode, &info) == 0) {
1551 if (info.vi_flags & V_INFO_GRAPHICS) {
1552 buf[0] = info.vi_width/info.vi_cwidth; /* COLS */
1553 buf[1] = info.vi_height/info.vi_cheight - 1; /* ROWS */
1555 buf[0] = info.vi_width; /* COLS */
1556 buf[1] = info.vi_height - 1; /* ROWS */
1558 buf[2] = info.vi_cheight; /* POINTS */
1560 /* XXX: shouldn't be happening... */
1561 kprintf("vga%d: %s: failed to obtain mode info. (vga_save_state())\n",
1562 adp->va_unit, adp->va_name);
1565 buf[0] = readb(BIOS_PADDRTOVADDR(0x44a)); /* COLS */
1566 buf[1] = readb(BIOS_PADDRTOVADDR(0x484)); /* ROWS */
1567 buf[2] = readb(BIOS_PADDRTOVADDR(0x485)); /* POINTS */
1568 buf[3] = readb(BIOS_PADDRTOVADDR(0x44c));
1569 buf[4] = readb(BIOS_PADDRTOVADDR(0x44d));
1577 * Set video registers at once.
1578 * NOTE: this function only updates the standard VGA registers.
1579 * any extra/extended registers of SVGA adapters are not changed.
1582 vga_load_state(video_adapter_t *adp, void *p)
1588 prologue(adp, V_ADP_STATELOAD, ENODEV);
1589 if (((adp_state_t *)p)->sig != V_STATE_SIG)
1592 buf = ((adp_state_t *)p)->regs;
1596 dump_buffer(buf, V_MODE_PARAM_SIZE);
1601 outb(TSIDX, 0x00); outb(TSREG, 0x01); /* stop sequencer */
1602 for (i = 0; i < 4; ++i) { /* program sequencer */
1604 outb(TSREG, buf[i + 5]);
1606 outb(MISC, buf[9]); /* set dot-clock */
1607 outb(TSIDX, 0x00); outb(TSREG, 0x03); /* start sequencer */
1608 outb(crtc_addr, 0x11);
1609 outb(crtc_addr + 1, inb(crtc_addr + 1) & 0x7F);
1610 for (i = 0; i < 25; ++i) { /* program crtc */
1612 outb(crtc_addr + 1, buf[i + 10]);
1614 inb(crtc_addr+6); /* reset flip-flop */
1615 for (i = 0; i < 20; ++i) { /* program attribute ctrl */
1617 outb(ATC, buf[i + 35]);
1619 for (i = 0; i < 9; ++i) { /* program graph data ctrl */
1621 outb(GDCREG, buf[i + 55]);
1623 inb(crtc_addr + 6); /* reset flip-flop */
1624 outb(ATC, 0x20); /* enable palette */
1626 #if notyet /* a temporary workaround for kernel panic, XXX */
1628 if (adp->va_unit == V_ADP_PRIMARY) {
1629 writeb(BIOS_PADDRTOVADDR(0x44a), buf[0]); /* COLS */
1630 writeb(BIOS_PADDRTOVADDR(0x484), buf[1] + rows_offset - 1); /* ROWS */
1631 writeb(BIOS_PADDRTOVADDR(0x485), buf[2]); /* POINTS */
1633 writeb(BIOS_PADDRTOVADDR(0x44c), buf[3]);
1634 writeb(BIOS_PADDRTOVADDR(0x44d), buf[4]);
1637 #endif /* VGA_NO_BIOS */
1646 * Change the origin (window mapping) of the banked frame buffer.
1649 vga_set_origin(video_adapter_t *adp, off_t offset)
1652 * The standard video modes do not require window mapping;
1653 * always return error.
1660 * Read the position of the hardware text cursor.
1663 vga_read_hw_cursor(video_adapter_t *adp, int *col, int *row)
1670 if (adp->va_info.vi_flags & V_INFO_GRAPHICS)
1675 off = inb(CRTC + 1);
1677 off = (off << 8) | inb(CRTC + 1);
1680 *row = off / adp->va_info.vi_width;
1681 *col = off % adp->va_info.vi_width;
1688 * Move the hardware text cursor. If col and row are both -1,
1689 * the cursor won't be shown.
1692 vga_set_hw_cursor(video_adapter_t *adp, int col, int row)
1699 if ((col == -1) && (row == -1)) {
1702 if (adp->va_info.vi_flags & V_INFO_GRAPHICS)
1704 off = row*adp->va_info.vi_width + col;
1709 outb(CRTC + 1, off >> 8);
1711 outb(CRTC + 1, off & 0x00ff);
1718 * set_hw_cursor_shape():
1719 * Change the shape of the hardware text cursor. If the height is
1720 * zero or negative, the cursor won't be shown.
1723 vga_set_hw_cursor_shape(video_adapter_t *adp, int base, int height,
1724 int celsize, int blink)
1731 /* make the cursor invisible */
1738 outb(CRTC + 1, celsize - base - height);
1740 outb(CRTC + 1, celsize - base - 1);
1749 * Put the display in power save/power off mode.
1752 vga_blank_display(video_adapter_t *adp, int mode)
1758 case V_DISPLAY_SUSPEND:
1759 case V_DISPLAY_STAND_BY:
1763 outb(TSREG, val | 0x20);
1765 val = inb(CRTC + 1);
1766 outb(CRTC + 1, val & ~0x80);
1772 outb(TSREG, val | 0x20);
1778 outb(TSREG, val & 0xDF);
1780 val = inb(CRTC + 1);
1781 outb(CRTC + 1, val | 0x80);
1791 * Mmap frame buffer.
1794 vga_mmap_buf(video_adapter_t *adp, vm_offset_t offset, int prot)
1796 if (adp->va_info.vi_flags & V_INFO_LINEAR)
1800 kprintf("vga_mmap_buf(): window:0x%x, offset:%p\n",
1801 adp->va_info.vi_window, (void *)offset);
1804 /* XXX: is this correct? */
1805 if (offset > adp->va_window_size - PAGE_SIZE)
1808 #if defined(__i386__)
1809 return i386_btop(adp->va_info.vi_window + offset);
1810 #elif defined(__x86_64__)
1811 return x86_64_btop(adp->va_info.vi_window + offset);
1813 #error "vga_mmap_buf needs to return something"
1817 #ifndef VGA_NO_MODE_CHANGE
1820 planar_fill(video_adapter_t *adp, int val)
1823 int at; /* position in the frame buffer */
1826 outw(GDCIDX, 0x0005); /* read mode 0, write mode 0 */
1827 outw(GDCIDX, 0x0003); /* data rotate/function select */
1828 outw(GDCIDX, 0x0f01); /* set/reset enable */
1829 outw(GDCIDX, 0xff08); /* bit mask */
1830 outw(GDCIDX, (val << 8) | 0x00); /* set/reset */
1832 length = adp->va_line_width*adp->va_info.vi_height;
1833 while (length > 0) {
1834 l = imin(length, adp->va_window_size);
1835 (*vidsw[adp->va_index]->set_win_org)(adp, at);
1836 bzero_io(adp->va_window, l);
1840 outw(GDCIDX, 0x0000); /* set/reset */
1841 outw(GDCIDX, 0x0001); /* set/reset enable */
1845 packed_fill(video_adapter_t *adp, int val)
1848 int at; /* position in the frame buffer */
1852 length = adp->va_line_width*adp->va_info.vi_height;
1853 while (length > 0) {
1854 l = imin(length, adp->va_window_size);
1855 (*vidsw[adp->va_index]->set_win_org)(adp, at);
1856 fill_io(val, adp->va_window, l);
1863 direct_fill(video_adapter_t *adp, int val)
1866 int at; /* position in the frame buffer */
1870 length = adp->va_line_width*adp->va_info.vi_height;
1871 while (length > 0) {
1872 l = imin(length, adp->va_window_size);
1873 (*vidsw[adp->va_index]->set_win_org)(adp, at);
1874 switch (adp->va_info.vi_pixel_size) {
1875 case sizeof(u_int16_t):
1876 fillw_io(val, adp->va_window, l/sizeof(u_int16_t));
1881 case sizeof(u_int32_t):
1882 filll_io(val, adp->va_window, l/sizeof(u_int32_t));
1891 vga_clear(video_adapter_t *adp)
1893 switch (adp->va_info.vi_mem_model) {
1894 case V_INFO_MM_TEXT:
1895 /* do nothing? XXX */
1897 case V_INFO_MM_PLANAR:
1898 planar_fill(adp, 0);
1900 case V_INFO_MM_PACKED:
1901 packed_fill(adp, 0);
1903 case V_INFO_MM_DIRECT:
1904 direct_fill(adp, 0);
1912 planar_fill_rect(video_adapter_t *adp, int val, int x, int y, int cx, int cy)
1917 int offset; /* offset within window */
1921 outw(GDCIDX, 0x0005); /* read mode 0, write mode 0 */
1922 outw(GDCIDX, 0x0003); /* data rotate/function select */
1923 outw(GDCIDX, 0x0f01); /* set/reset enable */
1924 outw(GDCIDX, 0xff08); /* bit mask */
1925 outw(GDCIDX, (val << 8) | 0x00); /* set/reset */
1927 banksize = adp->va_window_size;
1930 pos = adp->va_line_width*y + x/8;
1931 if (bank != pos/banksize) {
1932 (*vidsw[adp->va_index]->set_win_org)(adp, pos);
1933 bank = pos/banksize;
1935 offset = pos%banksize;
1936 bx = (x + cx)/8 - x/8;
1938 outw(GDCIDX, ((0xff00 >> (x % 8)) & 0xff00) | 0x08);
1939 writeb(adp->va_window + offset, 0);
1942 if (offset >= banksize) {
1944 ++bank; /* next bank */
1945 (*vidsw[adp->va_index]->set_win_org)(adp, bank*banksize);
1947 outw(GDCIDX, 0xff08); /* bit mask */
1950 l = imin(bx, banksize);
1951 bzero_io(adp->va_window + offset, l);
1954 if (offset >= banksize) {
1956 ++bank; /* next bank */
1957 (*vidsw[adp->va_index]->set_win_org)(adp, bank*banksize);
1961 outw(GDCIDX, (~(0xff00 >> ((x + cx) % 8)) & 0xff00) | 0x08);
1962 writeb(adp->va_window + offset, 0);
1964 if (offset >= banksize) {
1966 ++bank; /* next bank */
1967 (*vidsw[adp->va_index]->set_win_org)(adp, bank*banksize);
1969 outw(GDCIDX, 0xff08); /* bit mask */
1975 outw(GDCIDX, 0xff08); /* bit mask */
1976 outw(GDCIDX, 0x0000); /* set/reset */
1977 outw(GDCIDX, 0x0001); /* set/reset enable */
1981 packed_fill_rect(video_adapter_t *adp, int val, int x, int y, int cx, int cy)
1986 int offset; /* offset within window */
1989 banksize = adp->va_window_size;
1991 cx *= adp->va_info.vi_pixel_size;
1993 pos = adp->va_line_width*y + x*adp->va_info.vi_pixel_size;
1994 if (bank != pos/banksize) {
1995 (*vidsw[adp->va_index]->set_win_org)(adp, pos);
1996 bank = pos/banksize;
1998 offset = pos%banksize;
1999 end = imin(offset + cx, banksize);
2000 fill_io(val, adp->va_window + offset,
2001 (end - offset)/adp->va_info.vi_pixel_size);
2002 /* the line may cross the window boundary */
2003 if (offset + cx > banksize) {
2004 ++bank; /* next bank */
2005 (*vidsw[adp->va_index]->set_win_org)(adp, bank*banksize);
2006 end = offset + cx - banksize;
2007 fill_io(val, adp->va_window, end/adp->va_info.vi_pixel_size);
2015 direct_fill_rect16(video_adapter_t *adp, int val, int x, int y, int cx, int cy)
2020 int offset; /* offset within window */
2024 * XXX: the function assumes that banksize is a muliple of
2025 * sizeof(u_int16_t).
2027 banksize = adp->va_window_size;
2029 cx *= sizeof(u_int16_t);
2031 pos = adp->va_line_width*y + x*sizeof(u_int16_t);
2032 if (bank != pos/banksize) {
2033 (*vidsw[adp->va_index]->set_win_org)(adp, pos);
2034 bank = pos/banksize;
2036 offset = pos%banksize;
2037 end = imin(offset + cx, banksize);
2038 fillw_io(val, adp->va_window + offset,
2039 (end - offset)/sizeof(u_int16_t));
2040 /* the line may cross the window boundary */
2041 if (offset + cx > banksize) {
2042 ++bank; /* next bank */
2043 (*vidsw[adp->va_index]->set_win_org)(adp, bank*banksize);
2044 end = offset + cx - banksize;
2045 fillw_io(val, adp->va_window, end/sizeof(u_int16_t));
2053 direct_fill_rect24(video_adapter_t *adp, int val, int x, int y, int cx, int cy)
2058 int offset; /* offset within window */
2064 b[0] = val & 0x0000ff;
2065 b[1] = (val >> 8) & 0x0000ff;
2066 b[2] = (val >> 16) & 0x0000ff;
2067 banksize = adp->va_window_size;
2071 pos = adp->va_line_width*y + x*3;
2072 if (bank != pos/banksize) {
2073 (*vidsw[adp->va_index]->set_win_org)(adp, pos);
2074 bank = pos/banksize;
2076 offset = pos%banksize;
2077 end = imin(offset + cx, banksize);
2078 for (i = 0, j = offset; j < end; i = (++i)%3, ++j) {
2079 writeb(adp->va_window + j, b[i]);
2081 /* the line may cross the window boundary */
2082 if (offset + cx >= banksize) {
2083 ++bank; /* next bank */
2084 (*vidsw[adp->va_index]->set_win_org)(adp, bank*banksize);
2086 end = offset + cx - banksize;
2087 for (; j < end; i = (++i)%3, ++j) {
2088 writeb(adp->va_window + j, b[i]);
2097 direct_fill_rect32(video_adapter_t *adp, int val, int x, int y, int cx, int cy)
2102 int offset; /* offset within window */
2106 * XXX: the function assumes that banksize is a muliple of
2107 * sizeof(u_int32_t).
2109 banksize = adp->va_window_size;
2111 cx *= sizeof(u_int32_t);
2113 pos = adp->va_line_width*y + x*sizeof(u_int32_t);
2114 if (bank != pos/banksize) {
2115 (*vidsw[adp->va_index]->set_win_org)(adp, pos);
2116 bank = pos/banksize;
2118 offset = pos%banksize;
2119 end = imin(offset + cx, banksize);
2120 filll_io(val, adp->va_window + offset,
2121 (end - offset)/sizeof(u_int32_t));
2122 /* the line may cross the window boundary */
2123 if (offset + cx > banksize) {
2124 ++bank; /* next bank */
2125 (*vidsw[adp->va_index]->set_win_org)(adp, bank*banksize);
2126 end = offset + cx - banksize;
2127 filll_io(val, adp->va_window, end/sizeof(u_int32_t));
2135 vga_fill_rect(video_adapter_t *adp, int val, int x, int y, int cx, int cy)
2137 switch (adp->va_info.vi_mem_model) {
2138 case V_INFO_MM_TEXT:
2139 /* do nothing? XXX */
2141 case V_INFO_MM_PLANAR:
2142 planar_fill_rect(adp, val, x, y, cx, cy);
2144 case V_INFO_MM_PACKED:
2145 packed_fill_rect(adp, val, x, y, cx, cy);
2147 case V_INFO_MM_DIRECT:
2148 switch (adp->va_info.vi_pixel_size) {
2149 case sizeof(u_int16_t):
2150 direct_fill_rect16(adp, val, x, y, cx, cy);
2153 direct_fill_rect24(adp, val, x, y, cx, cy);
2155 case sizeof(u_int32_t):
2156 direct_fill_rect32(adp, val, x, y, cx, cy);
2165 vga_fill_rect(video_adapter_t *adp, int val, int x, int y, int cx, int cy)
2172 vga_bitblt(video_adapter_t *adp,...)
2178 #endif /* !VGA_NO_MODE_CHANGE */
2181 get_palette(video_adapter_t *adp, int base, int count,
2182 u_char *red, u_char *green, u_char *blue, u_char *trans)
2188 if (count < 0 || base < 0 || count > 256 || base > 256 ||
2192 r = kmalloc(count*3, M_DEVBUF, M_WAITOK);
2195 if (vga_save_palette2(adp, base, count, r, g, b)) {
2199 copyout(r, red, count);
2200 copyout(g, green, count);
2201 copyout(b, blue, count);
2202 if (trans != NULL) {
2204 copyout(r, trans, count);
2212 set_palette(video_adapter_t *adp, int base, int count,
2213 u_char *red, u_char *green, u_char *blue, u_char *trans)
2220 if (count < 0 || base < 0 || count > 256 || base > 256 ||
2224 r = kmalloc(count*3, M_DEVBUF, M_WAITOK);
2227 err = copyin(red, r, count);
2229 err = copyin(green, g, count);
2231 err = copyin(blue, b, count);
2233 err = vga_load_palette2(adp, base, count, r, g, b);
2236 return (err ? ENODEV : 0);
2240 vga_dev_ioctl(video_adapter_t *adp, u_long cmd, caddr_t arg)
2243 case FBIO_GETWINORG: /* get frame buffer window origin */
2247 case FBIO_SETWINORG: /* set frame buffer window origin */
2250 case FBIO_SETDISPSTART: /* set display start address */
2251 return (set_display_start(adp,
2252 ((video_display_start_t *)arg)->x,
2253 ((video_display_start_t *)arg)->y)
2256 case FBIO_SETLINEWIDTH: /* set scan line length in pixel */
2257 return (set_line_length(adp, *(u_int *)arg) ? ENODEV : 0);
2259 case FBIO_GETPALETTE: /* get color palette */
2260 return get_palette(adp, ((video_color_palette_t *)arg)->index,
2261 ((video_color_palette_t *)arg)->count,
2262 ((video_color_palette_t *)arg)->red,
2263 ((video_color_palette_t *)arg)->green,
2264 ((video_color_palette_t *)arg)->blue,
2265 ((video_color_palette_t *)arg)->transparent);
2267 case FBIO_SETPALETTE: /* set color palette */
2268 return set_palette(adp, ((video_color_palette_t *)arg)->index,
2269 ((video_color_palette_t *)arg)->count,
2270 ((video_color_palette_t *)arg)->red,
2271 ((video_color_palette_t *)arg)->green,
2272 ((video_color_palette_t *)arg)->blue,
2273 ((video_color_palette_t *)arg)->transparent);
2275 case FBIOGTYPE: /* get frame buffer type info. */
2276 ((struct fbtype *)arg)->fb_type = fb_type(adp->va_type);
2277 ((struct fbtype *)arg)->fb_height = adp->va_info.vi_height;
2278 ((struct fbtype *)arg)->fb_width = adp->va_info.vi_width;
2279 ((struct fbtype *)arg)->fb_depth = adp->va_info.vi_depth;
2280 if ((adp->va_info.vi_depth <= 1) || (adp->va_info.vi_depth > 8))
2281 ((struct fbtype *)arg)->fb_cmsize = 0;
2283 ((struct fbtype *)arg)->fb_cmsize = 1 << adp->va_info.vi_depth;
2284 ((struct fbtype *)arg)->fb_size = adp->va_buffer_size;
2287 case FBIOGETCMAP: /* get color palette */
2288 return get_palette(adp, ((struct fbcmap *)arg)->index,
2289 ((struct fbcmap *)arg)->count,
2290 ((struct fbcmap *)arg)->red,
2291 ((struct fbcmap *)arg)->green,
2292 ((struct fbcmap *)arg)->blue, NULL);
2294 case FBIOPUTCMAP: /* set color palette */
2295 return set_palette(adp, ((struct fbcmap *)arg)->index,
2296 ((struct fbcmap *)arg)->count,
2297 ((struct fbcmap *)arg)->red,
2298 ((struct fbcmap *)arg)->green,
2299 ((struct fbcmap *)arg)->blue, NULL);
2302 return fb_commonioctl(adp, cmd, arg);
2307 dump_buffer(u_char *buf, size_t len)
2311 for(i = 0; i < len;) {
2312 kprintf("%02x ", buf[i]);
2313 if ((++i % 16) == 0)
2320 * Print some information about the video adapter and video modes,
2321 * with requested level of details.
2324 vga_diag(video_adapter_t *adp, int level)
2337 kprintf("vga: DCC code:0x%02x\n",
2338 readb(BIOS_PADDRTOVADDR(0x488)));
2339 kprintf("vga: CRTC:0x%x, video option:0x%02x, ",
2340 readw(BIOS_PADDRTOVADDR(0x463)),
2341 readb(BIOS_PADDRTOVADDR(0x487)));
2342 kprintf("rows:%d, cols:%d, font height:%d\n",
2343 readb(BIOS_PADDRTOVADDR(0x44a)),
2344 readb(BIOS_PADDRTOVADDR(0x484)) + 1,
2345 readb(BIOS_PADDRTOVADDR(0x485)));
2346 #endif /* VGA_NO_BIOS */
2347 #if !defined(VGA_NO_BIOS) && !defined(VGA_NO_MODE_CHANGE)
2348 kprintf("vga: param table:%p\n", video_mode_ptr);
2349 kprintf("vga: rows_offset:%d\n", rows_offset);
2351 #endif /* FB_DEBUG > 1 */
2353 fb_dump_adp_info(VGA_DRIVER_NAME, adp, level);
2356 if (adp->va_flags & V_ADP_MODECHANGE) {
2357 for (i = 0; bios_vmode[i].vi_mode != EOT; ++i) {
2358 if (bios_vmode[i].vi_mode == NA)
2360 if (get_mode_param(bios_vmode[i].vi_mode) == NULL)
2362 fb_dump_mode_info(VGA_DRIVER_NAME, adp, &bios_vmode[i], level);
2365 vga_get_info(adp, adp->va_initial_mode, &info); /* shouldn't fail */
2366 fb_dump_mode_info(VGA_DRIVER_NAME, adp, &info, level);
2368 #endif /* FB_DEBUG > 1 */
2370 #if !defined(VGA_NO_BIOS) && !defined(VGA_NO_MODE_CHANGE)
2371 if (video_mode_ptr == NULL)
2372 kprintf("vga%d: %s: WARNING: video mode switching is not "
2373 "fully supported on this adapter\n",
2374 adp->va_unit, adp->va_name);
2379 kprintf("VGA parameters upon power-up\n");
2380 dump_buffer(adpstate.regs, sizeof(adpstate.regs));
2382 mp = get_mode_param(adp->va_initial_mode);
2383 if (mp == NULL) /* this shouldn't be happening */
2385 kprintf("VGA parameters in BIOS for mode %d\n", adp->va_initial_mode);
2386 dump_buffer(adpstate2.regs, sizeof(adpstate2.regs));
2387 kprintf("VGA parameters to be used for mode %d\n", adp->va_initial_mode);
2388 dump_buffer(mp, V_MODE_PARAM_SIZE);