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.
31 * $FreeBSD: src/sys/dev/fb/vga.c,v 1.9.2.1 2001/08/11 02:58:44 yokota Exp $
37 #include <sys/param.h>
38 #include <sys/systm.h>
39 #include <sys/kernel.h>
41 #include <sys/fcntl.h>
42 #include <sys/malloc.h>
44 #include <sys/thread2.h>
46 #include <bus/isa/isareg.h>
48 #include <machine/clock.h>
49 #include <machine/md_var.h>
50 #include <machine/pc/bios.h>
53 #include <vm/vm_param.h>
64 vga_probe_unit(int unit, video_adapter_t *buf, int flags)
70 sw = vid_get_switch(VGA_DRIVER_NAME);
73 error = (*sw->probe)(unit, &adp, NULL, flags);
76 bcopy(adp, buf, sizeof(*buf));
81 vga_attach_unit(int unit, vga_softc_t *sc, int flags)
86 sw = vid_get_switch(VGA_DRIVER_NAME);
90 error = (*sw->probe)(unit, &sc->adp, NULL, flags);
93 return (*sw->init)(unit, sc->adp, flags);
96 /* cdev driver functions */
98 #ifdef FB_INSTALL_CDEV
103 vga_open(cdev_t dev, vga_softc_t *sc, int flag, int mode, struct ucred *cred)
107 if (mode & (O_CREAT | O_APPEND | O_TRUNC))
110 return genfbopen(&sc->gensc, sc->adp, flag, mode, cred);
114 vga_close(cdev_t dev, vga_softc_t *sc, int flag, int mode)
116 return genfbclose(&sc->gensc, sc->adp, flag, mode);
120 vga_read(cdev_t dev, vga_softc_t *sc, struct uio *uio, int flag)
122 return genfbread(&sc->gensc, sc->adp, uio, flag);
126 vga_write(cdev_t dev, vga_softc_t *sc, struct uio *uio, int flag)
128 return genfbread(&sc->gensc, sc->adp, uio, flag);
132 vga_ioctl(cdev_t dev, vga_softc_t *sc, u_long cmd, caddr_t arg, int flag,
135 return genfbioctl(&sc->gensc, sc->adp, cmd, arg, flag, cred);
139 vga_mmap(cdev_t dev, vga_softc_t *sc, vm_offset_t offset, int prot)
141 return genfbmmap(&sc->gensc, sc->adp, offset, prot);
144 #endif /* FB_INSTALL_CDEV */
148 #define probe_done(adp) ((adp)->va_flags & V_ADP_PROBED)
149 #define init_done(adp) ((adp)->va_flags & V_ADP_INITIALIZED)
150 #define config_done(adp) ((adp)->va_flags & V_ADP_REGISTERED)
153 #define V_MODE_MAP_SIZE (M_VGA_CG320 + 1)
154 #define V_MODE_PARAM_SIZE 64
156 /* video adapter state buffer */
159 #define V_STATE_SIG 0x736f6962
160 u_char regs[V_MODE_PARAM_SIZE];
162 typedef struct adp_state adp_state_t;
165 * NOTE: `va_window' should have a virtual address, but is initialized
166 * with a physical address in the following table, as verify_adapter()
167 * will perform address conversion at run-time.
169 static video_adapter_t biosadapter = {
170 0, KD_VGA, VGA_DRIVER_NAME, 0, 0, V_ADP_COLOR, IO_VGA, 32,
171 EGA_BUF_BASE, EGA_BUF_SIZE, CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE,
172 0, 0, 0, M_VGA_C80x25, M_C80x25, M_VGA_C80x25
175 /* video driver declarations */
176 static int vga_configure(int flags);
177 int (*vga_sub_configure)(int flags);
179 static int vga_nop(void);
181 static int vga_error(void);
182 static vi_probe_t vga_probe;
183 static vi_init_t vga_init;
184 static vi_get_info_t vga_get_info;
185 static vi_query_mode_t vga_query_mode;
186 static vi_set_mode_t vga_set_mode;
187 static vi_save_font_t vga_save_font;
188 static vi_load_font_t vga_load_font;
189 static vi_show_font_t vga_show_font;
190 static vi_save_palette_t vga_save_palette;
191 static vi_load_palette_t vga_load_palette;
192 static vi_set_border_t vga_set_border;
193 static vi_save_state_t vga_save_state;
194 static vi_load_state_t vga_load_state;
195 static vi_set_win_org_t vga_set_origin;
196 static vi_read_hw_cursor_t vga_read_hw_cursor;
197 static vi_set_hw_cursor_t vga_set_hw_cursor;
198 static vi_set_hw_cursor_shape_t vga_set_hw_cursor_shape;
199 static vi_blank_display_t vga_blank_display;
200 static vi_mmap_t vga_mmap_buf;
201 static vi_ioctl_t vga_dev_ioctl;
202 #ifndef VGA_NO_MODE_CHANGE
203 static vi_clear_t vga_clear;
204 static vi_fill_rect_t vga_fill_rect;
205 static vi_bitblt_t vga_bitblt;
206 #else /* VGA_NO_MODE_CHANGE */
207 #define vga_clear (vi_clear_t *)vga_error
208 #define vga_fill_rect (vi_fill_rect_t *)vga_error
209 #define vga_bitblt (vi_bitblt_t *)vga_error
211 static vi_diag_t vga_diag;
213 static video_switch_t vgavidsw = {
230 vga_set_hw_cursor_shape,
242 VIDEO_DRIVER(vga, vgavidsw, vga_configure);
244 /* VGA BIOS standard video modes */
248 static video_info_t bios_vmode[] = {
250 { M_B40x25, V_INFO_COLOR, 40, 25, 8, 8, 2, 1,
251 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
252 { M_C40x25, V_INFO_COLOR, 40, 25, 8, 8, 4, 1,
253 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
254 { M_B80x25, V_INFO_COLOR, 80, 25, 8, 8, 2, 1,
255 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
256 { M_C80x25, V_INFO_COLOR, 80, 25, 8, 8, 4, 1,
257 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
259 { M_ENH_B40x25, V_INFO_COLOR, 40, 25, 8, 14, 2, 1,
260 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
261 { M_ENH_C40x25, V_INFO_COLOR, 40, 25, 8, 14, 4, 1,
262 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
263 { M_ENH_B80x25, V_INFO_COLOR, 80, 25, 8, 14, 2, 1,
264 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
265 { M_ENH_C80x25, V_INFO_COLOR, 80, 25, 8, 14, 4, 1,
266 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
268 { M_VGA_C40x25, V_INFO_COLOR, 40, 25, 8, 16, 4, 1,
269 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
270 { M_VGA_M80x25, 0, 80, 25, 8, 16, 2, 1,
271 MDA_BUF_BASE, MDA_BUF_SIZE, MDA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
272 { M_VGA_C80x25, V_INFO_COLOR, 80, 25, 8, 16, 4, 1,
273 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
275 { M_EGAMONO80x25, 0, 80, 25, 8, 14, 2, 1,
276 MDA_BUF_BASE, MDA_BUF_SIZE, MDA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
278 { M_ENH_B80x43, 0, 80, 43, 8, 8, 2, 1,
279 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
280 { M_ENH_C80x43, V_INFO_COLOR, 80, 43, 8, 8, 4, 1,
281 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
283 { M_VGA_M80x30, 0, 80, 30, 8, 16, 2, 1,
284 MDA_BUF_BASE, MDA_BUF_SIZE, MDA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
285 { M_VGA_C80x30, V_INFO_COLOR, 80, 30, 8, 16, 4, 1,
286 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
287 { M_VGA_M80x50, 0, 80, 50, 8, 8, 2, 1,
288 MDA_BUF_BASE, MDA_BUF_SIZE, MDA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
289 { M_VGA_C80x50, V_INFO_COLOR, 80, 50, 8, 8, 4, 1,
290 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
291 { M_VGA_M80x60, 0, 80, 60, 8, 8, 2, 1,
292 MDA_BUF_BASE, MDA_BUF_SIZE, MDA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
293 { M_VGA_C80x60, V_INFO_COLOR, 80, 60, 8, 8, 4, 1,
294 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
296 #ifndef VGA_NO_MODE_CHANGE
299 { M_VGA_M90x25, 0, 90, 25, 8, 16, 2, 1,
300 MDA_BUF_BASE, MDA_BUF_SIZE, MDA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
301 { M_VGA_C90x25, V_INFO_COLOR, 90, 25, 8, 16, 4, 1,
302 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
303 { M_VGA_M90x30, 0, 90, 30, 8, 16, 2, 1,
304 MDA_BUF_BASE, MDA_BUF_SIZE, MDA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
305 { M_VGA_C90x30, V_INFO_COLOR, 90, 30, 8, 16, 4, 1,
306 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
307 { M_VGA_M90x43, 0, 90, 43, 8, 8, 2, 1,
308 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
309 { M_VGA_C90x43, V_INFO_COLOR, 90, 43, 8, 8, 4, 1,
310 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
311 { M_VGA_M90x50, 0, 90, 50, 8, 8, 2, 1,
312 MDA_BUF_BASE, MDA_BUF_SIZE, MDA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
313 { M_VGA_C90x50, V_INFO_COLOR, 90, 50, 8, 8, 4, 1,
314 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
315 { M_VGA_M90x60, 0, 90, 60, 8, 8, 2, 1,
316 MDA_BUF_BASE, MDA_BUF_SIZE, MDA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
317 { M_VGA_C90x60, V_INFO_COLOR, 90, 60, 8, 8, 4, 1,
318 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
319 #endif /* VGA_WIDTH90 */
322 { M_BG320, V_INFO_COLOR | V_INFO_GRAPHICS, 320, 200, 8, 8, 2, 1,
323 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_CGA },
324 { M_CG320, V_INFO_COLOR | V_INFO_GRAPHICS, 320, 200, 8, 8, 2, 1,
325 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_CGA },
326 { M_BG640, V_INFO_COLOR | V_INFO_GRAPHICS, 640, 200, 8, 8, 1, 1,
327 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_CGA },
329 { M_CG320_D, V_INFO_COLOR | V_INFO_GRAPHICS, 320, 200, 8, 8, 4, 4,
330 GRAPHICS_BUF_BASE, GRAPHICS_BUF_SIZE, GRAPHICS_BUF_SIZE, 0, 0,
332 { M_CG640_E, V_INFO_COLOR | V_INFO_GRAPHICS, 640, 200, 8, 8, 4, 4,
333 GRAPHICS_BUF_BASE, GRAPHICS_BUF_SIZE, GRAPHICS_BUF_SIZE, 0, 0 ,
335 { M_EGAMONOAPA, V_INFO_GRAPHICS, 640, 350, 8, 14, 4, 4,
336 GRAPHICS_BUF_BASE, GRAPHICS_BUF_SIZE, 64*1024, 0, 0 ,
338 { M_ENHMONOAPA2,V_INFO_GRAPHICS, 640, 350, 8, 14, 4, 4,
339 GRAPHICS_BUF_BASE, GRAPHICS_BUF_SIZE, GRAPHICS_BUF_SIZE, 0, 0 ,
341 { M_CG640x350, V_INFO_COLOR | V_INFO_GRAPHICS, 640, 350, 8, 14, 2, 2,
342 GRAPHICS_BUF_BASE, GRAPHICS_BUF_SIZE, GRAPHICS_BUF_SIZE, 0, 0 ,
344 { M_ENH_CG640, V_INFO_COLOR | V_INFO_GRAPHICS, 640, 350, 8, 14, 4, 4,
345 GRAPHICS_BUF_BASE, GRAPHICS_BUF_SIZE, GRAPHICS_BUF_SIZE, 0, 0 ,
348 { M_BG640x480, V_INFO_COLOR | V_INFO_GRAPHICS, 640, 480, 8, 16, 4, 4,
349 GRAPHICS_BUF_BASE, GRAPHICS_BUF_SIZE, GRAPHICS_BUF_SIZE, 0, 0 ,
351 { M_CG640x480, V_INFO_COLOR | V_INFO_GRAPHICS, 640, 480, 8, 16, 4, 4,
352 GRAPHICS_BUF_BASE, GRAPHICS_BUF_SIZE, GRAPHICS_BUF_SIZE, 0, 0 ,
354 { M_VGA_CG320, V_INFO_COLOR | V_INFO_GRAPHICS, 320, 200, 8, 8, 8, 1,
355 GRAPHICS_BUF_BASE, GRAPHICS_BUF_SIZE, GRAPHICS_BUF_SIZE, 0, 0,
356 V_INFO_MM_PACKED, 1 },
357 { M_VGA_MODEX, V_INFO_COLOR | V_INFO_GRAPHICS, 320, 240, 8, 8, 8, 4,
358 GRAPHICS_BUF_BASE, GRAPHICS_BUF_SIZE, GRAPHICS_BUF_SIZE, 0, 0,
360 #endif /* VGA_NO_MODE_CHANGE */
365 static int vga_init_done = FALSE;
366 #if !defined(VGA_NO_BIOS) && !defined(VGA_NO_MODE_CHANGE)
367 static u_char *video_mode_ptr = NULL;
369 static u_char *mode_map[V_MODE_MAP_SIZE];
370 static adp_state_t adpstate;
371 static adp_state_t adpstate2;
372 static int rows_offset = 1;
374 /* local macros and functions */
375 #define BIOS_SADDRTOLADDR(p) ((((p) & 0xffff0000) >> 12) + ((p) & 0x0000ffff))
377 #if !defined(VGA_NO_BIOS) && !defined(VGA_NO_MODE_CHANGE)
378 static void map_mode_table(u_char **, u_char *);
379 static int map_mode_num(int);
382 static int map_bios_mode_num(int);
384 static u_char *get_mode_param(int);
385 static int verify_adapter(video_adapter_t *);
386 static void update_adapter_info(video_adapter_t *, video_info_t *);
387 static int probe_adapters(void);
388 static int set_line_length(video_adapter_t *, int);
389 static int set_display_start(video_adapter_t *, int, int);
391 #ifndef VGA_NO_MODE_CHANGE
393 static void set_width90(adp_state_t *);
395 #endif /* !VGA_NO_MODE_CHANGE */
397 #ifndef VGA_NO_FONT_LOADING
398 #define PARAM_BUFSIZE 6
399 static void set_font_mode(video_adapter_t *, u_char *);
400 static void set_normal_mode(video_adapter_t *, u_char *);
403 #ifndef VGA_NO_MODE_CHANGE
404 static void filll_io(int, vm_offset_t, size_t);
405 static void planar_fill(video_adapter_t *, int);
406 static void packed_fill(video_adapter_t *, int);
407 static void direct_fill(video_adapter_t *, int);
409 static void planar_fill_rect(video_adapter_t *, int, int, int, int, int);
410 static void packed_fill_rect(video_adapter_t *, int, int, int, int, int);
411 static void direct_fill_rect16(video_adapter_t *, int, int, int, int, int);
412 static void direct_fill_rect24(video_adapter_t *, int, int, int, int, int);
413 static void direct_fill_rect32(video_adapter_t *, int, int, int, int, int);
415 #endif /* !VGA_NO_MODE_CHANGE */
417 #define ISMAPPED(pa, width) \
418 (((pa) <= (u_long)0x1000 - (width)) \
419 || ((pa) >= ISA_HOLE_START && (pa) <= 0x100000 - (width)))
421 #define prologue(adp, flag, err) \
422 if (!vga_init_done || !((adp)->va_flags & (flag))) \
425 /* a backdoor for the console driver */
427 vga_configure(int flags)
430 if (probe_done(&biosadapter)) {
431 biosadapter.va_flags |= V_ADP_INITIALIZED;
432 if (!config_done(&biosadapter) && !(vid_register(&biosadapter) < 0))
433 biosadapter.va_flags |= V_ADP_REGISTERED;
435 if (vga_sub_configure != NULL)
436 (*vga_sub_configure)(flags);
441 /* local subroutines */
443 #if !defined(VGA_NO_BIOS) && !defined(VGA_NO_MODE_CHANGE)
444 /* construct the mode parameter map (accept 40x25, 80x25 and 80x30 modes) */
446 map_mode_table(u_char *map[], u_char *table)
450 for(i = 0; i < V_MODE_MAP_SIZE; ++i) {
451 map[i] = table + i*V_MODE_PARAM_SIZE;
453 if ((map[i][0] == 40 && map[i][1] == 24) ||
454 (map[i][0] == 80 && (map[i][1] == 24 || map[i][1] == 29)))
460 #endif /* !VGA_NO_BIOS && !VGA_NO_MODE_CHANGE */
462 #if !defined(VGA_NO_BIOS) && !defined(VGA_NO_MODE_CHANGE)
463 /* map the non-standard video mode to a known mode number */
465 map_mode_num(int mode)
471 { M_ENH_B80x43, M_ENH_B80x25 },
472 { M_ENH_C80x43, M_ENH_C80x25 },
473 { M_VGA_M80x30, M_VGA_M80x25 },
474 { M_VGA_C80x30, M_VGA_C80x25 },
475 { M_VGA_M80x50, M_VGA_M80x25 },
476 { M_VGA_C80x50, M_VGA_C80x25 },
477 { M_VGA_M80x60, M_VGA_M80x25 },
478 { M_VGA_C80x60, M_VGA_C80x25 },
480 { M_VGA_M90x25, M_VGA_M80x25 },
481 { M_VGA_C90x25, M_VGA_C80x25 },
482 { M_VGA_M90x30, M_VGA_M80x25 },
483 { M_VGA_C90x30, M_VGA_C80x25 },
484 { M_VGA_M90x43, M_ENH_B80x25 },
485 { M_VGA_C90x43, M_ENH_C80x25 },
486 { M_VGA_M90x50, M_VGA_M80x25 },
487 { M_VGA_C90x50, M_VGA_C80x25 },
488 { M_VGA_M90x60, M_VGA_M80x25 },
489 { M_VGA_C90x60, M_VGA_C80x25 },
491 { M_VGA_MODEX, M_VGA_CG320 },
495 for (i = 0; i < NELEM(mode_map); ++i) {
496 if (mode_map[i].from == mode)
497 return mode_map[i].to;
501 #endif /* !VGA_NO_BIOS && !VGA_NO_MODE_CHANGE */
504 /* turn the BIOS video number into our video mode number */
506 map_bios_mode_num(int bios_mode)
508 static int vga_modes[20] = {
509 M_VGA_C40x25, M_VGA_C40x25, /* 0, 1 */
510 M_VGA_C80x25, M_VGA_C80x25, /* 2, 3 */
513 M_VGA_M80x25, /* 7 */
519 M_BG640x480, M_CG640x480,
523 if (bios_mode < NELEM(vga_modes))
524 return vga_modes[bios_mode];
530 /* look up a parameter table entry */
532 get_mode_param(int mode)
534 #if !defined(VGA_NO_BIOS) && !defined(VGA_NO_MODE_CHANGE)
535 if (mode >= V_MODE_MAP_SIZE)
536 mode = map_mode_num(mode);
538 if ((mode >= 0) && (mode < V_MODE_MAP_SIZE))
539 return mode_map[mode];
545 verify_adapter(video_adapter_t *adp)
549 #if !defined(VGA_NO_BIOS) && !defined(VGA_NO_MODE_CHANGE)
553 buf = BIOS_PADDRTOVADDR(adp->va_window);
556 if (readw(buf) != 0xA55A)
564 adp->va_flags |= V_ADP_STATELOAD | V_ADP_STATESAVE | V_ADP_PALETTE |
567 #if !defined(VGA_NO_BIOS) && !defined(VGA_NO_MODE_CHANGE)
568 /* get the BIOS video mode pointer */
569 p = *(u_int32_t *)BIOS_PADDRTOVADDR(0x4a8);
570 p = BIOS_SADDRTOLADDR(p);
571 if (ISMAPPED(p, sizeof(u_int32_t))) {
572 p = *(u_int32_t *)BIOS_PADDRTOVADDR(p);
573 p = BIOS_SADDRTOLADDR(p);
574 if (ISMAPPED(p, V_MODE_PARAM_SIZE))
575 video_mode_ptr = (u_char *)BIOS_PADDRTOVADDR(p);
583 update_adapter_info(video_adapter_t *adp, video_info_t *info)
585 adp->va_flags |= V_ADP_COLOR;
586 adp->va_window = BIOS_PADDRTOVADDR(info->vi_window);
587 adp->va_window_size = info->vi_window_size;
588 adp->va_window_gran = info->vi_window_gran;
589 adp->va_window_orig = 0;
591 adp->va_buffer = info->vi_buffer;
592 adp->va_buffer_size = info->vi_buffer_size;
593 if (info->vi_mem_model == V_INFO_MM_VGAX) {
594 adp->va_line_width = info->vi_width/2;
595 } else if (info->vi_flags & V_INFO_GRAPHICS) {
596 switch (info->vi_depth/info->vi_planes) {
598 adp->va_line_width = info->vi_width/8;
601 adp->va_line_width = info->vi_width/4;
604 adp->va_line_width = info->vi_width/2;
607 default: /* shouldn't happen */
608 adp->va_line_width = info->vi_width;
612 adp->va_line_width = info->vi_width;
614 adp->va_disp_start.x = 0;
615 adp->va_disp_start.y = 0;
616 bcopy(info, &adp->va_info, sizeof(adp->va_info));
619 /* probe video adapters and return the number of detected adapters */
623 video_adapter_t *adp;
625 #if !defined(VGA_NO_BIOS) && !defined(VGA_NO_MODE_CHANGE)
630 /* do this test only once */
633 vga_init_done = TRUE;
635 if (verify_adapter(&biosadapter) != 0)
638 biosadapter.va_flags |= V_ADP_PROBED;
640 biosadapter.va_initial_bios_mode = readb(BIOS_PADDRTOVADDR(0x449));
641 biosadapter.va_mode = biosadapter.va_initial_mode =
642 map_bios_mode_num(biosadapter.va_initial_bios_mode);
646 * Ensure a zero start address. This is mainly to recover after
647 * switching from pcvt using userconfig(). The registers are w/o
648 * for old hardware so it's too hard to relocate the active screen
650 * This must be done before vga_save_state() for VGA.
657 /* the video mode parameter table in VGA BIOS */
658 /* NOTE: there can be only one VGA recognized by the video BIOS.
661 bzero(mode_map, sizeof(mode_map));
662 vga_save_state(adp, &adpstate, sizeof(adpstate));
663 for(i = 0; i < 16; i++)
664 adp->va_palette_regs[i] = adpstate.regs[35 + i];
665 #if defined(VGA_NO_BIOS) || defined(VGA_NO_MODE_CHANGE)
666 mode_map[adp->va_initial_mode] = adpstate.regs;
668 #else /* VGA_NO_BIOS || VGA_NO_MODE_CHANGE */
669 if (video_mode_ptr == NULL) {
670 mode_map[adp->va_initial_mode] = adpstate.regs;
673 /* discard modes that we are not familiar with */
674 map_mode_table(mode_map, video_mode_ptr);
675 mp = get_mode_param(adp->va_initial_mode);
676 #if !defined(VGA_KEEP_POWERON_MODE)
678 bcopy(mp, adpstate2.regs, sizeof(adpstate2.regs));
679 rows_offset = adpstate.regs[1] + 1 - mp[1];
683 mode_map[adp->va_initial_mode] = adpstate.regs;
687 #endif /* VGA_NO_BIOS || VGA_NO_MODE_CHANGE */
689 #ifndef VGA_NO_MODE_CHANGE
690 adp->va_flags |= V_ADP_MODECHANGE;
692 #ifndef VGA_NO_FONT_LOADING
693 adp->va_flags |= V_ADP_FONT;
696 /* XXX remove conflicting modes */
697 for (i = 0; i < M_VGA_CG320; i++) {
698 if (vga_get_info(&biosadapter, i, &info))
700 if ((info.vi_flags & V_INFO_COLOR) != V_ADP_COLOR)
705 vga_get_info(&biosadapter, biosadapter.va_initial_mode, &info);
706 info.vi_flags &= ~V_INFO_LINEAR; /* XXX */
707 update_adapter_info(&biosadapter, &info);
710 * XXX: we should verify the following values for the primary adapter...
711 * crtc I/O port address: *(u_int16_t *)BIOS_PADDRTOVADDR(0x463);
712 * color/mono display: (*(u_int8_t *)BIOS_PADDRTOVADDR(0x487) & 0x02)
714 * columns: *(u_int8_t *)BIOS_PADDRTOVADDR(0x44a);
715 * rows: *(u_int8_t *)BIOS_PADDRTOVADDR(0x484);
716 * font size: *(u_int8_t *)BIOS_PADDRTOVADDR(0x485);
717 * buffer size: *(u_int16_t *)BIOS_PADDRTOVADDR(0x44c);
723 /* set the scan line length in pixel */
725 set_line_length(video_adapter_t *adp, int pixel)
728 int ppw; /* pixels per word */
729 int bpl; /* bytes per line */
732 mp = get_mode_param(adp->va_mode);
736 switch (adp->va_info.vi_mem_model) {
737 case V_INFO_MM_PLANAR:
738 ppw = 16/(adp->va_info.vi_depth/adp->va_info.vi_planes);
739 count = (pixel + ppw - 1)/ppw/2;
740 bpl = ((pixel + ppw - 1)/ppw/2)*4;
742 case V_INFO_MM_PACKED:
743 count = (pixel + 7)/8;
744 bpl = ((pixel + 7)/8)*8;
747 count = (pixel + 7)/8; /* columns */
748 bpl = (pixel + 7)/8; /* columns */
754 if (mp[10 + 0x17] & 0x40) /* CRTC mode control reg */
755 count *= 2; /* byte mode */
758 adp->va_line_width = bpl;
764 set_display_start(video_adapter_t *adp, int x, int y)
766 int off; /* byte offset (graphics mode)/word offset (text mode) */
767 int poff; /* pixel offset */
768 int roff; /* row offset */
769 int ppb; /* pixels per byte */
771 if (adp->va_info.vi_flags & V_INFO_GRAPHICS) {
772 ppb = 8/(adp->va_info.vi_depth/adp->va_info.vi_planes);
773 off = y*adp->va_line_width + x/ppb;
782 off = y/adp->va_info.vi_cheight*adp->va_line_width + x/ppb;
783 roff = y%adp->va_info.vi_cheight;
784 /* FIXME: is this correct? XXX */
792 outb(CRTC, 0xc); /* high */
793 outb(CRTC + 1, off >> 8);
794 outb(CRTC, 0xd); /* low */
795 outb(CRTC + 1, off & 0xff);
797 /* horizontal pel pan */
799 outb(ATC, 0x13 | 0x20);
804 /* preset raw scan */
806 outb(CRTC + 1, roff);
808 adp->va_disp_start.x = x;
809 adp->va_disp_start.y = y;
813 #ifndef VGA_NO_MODE_CHANGE
814 #if defined(__i386__) || defined(__x86_64__) /* XXX */
816 fill(int val, void *d, size_t size)
823 #endif /* __i386__ || __x86_64__ */
826 filll_io(int val, vm_offset_t d, size_t size)
830 d += sizeof(u_int32_t);
833 #endif /* !VGA_NO_MODE_CHANGE */
852 vga_probe(int unit, video_adapter_t **adpp, void *arg, int flags)
858 *adpp = &biosadapter;
864 vga_init(int unit, video_adapter_t *adp, int flags)
866 if ((unit != 0) || (adp == NULL) || !probe_done(adp))
869 if (!init_done(adp)) {
870 /* nothing to do really... */
871 adp->va_flags |= V_ADP_INITIALIZED;
874 if (!config_done(adp)) {
875 if (vid_register(adp) < 0)
877 adp->va_flags |= V_ADP_REGISTERED;
879 if (vga_sub_configure != NULL)
880 (*vga_sub_configure)(0);
887 * Return the video_info structure of the requested video mode.
890 vga_get_info(video_adapter_t *adp, int mode, video_info_t *info)
897 #ifndef VGA_NO_MODE_CHANGE
898 if (adp->va_flags & V_ADP_MODECHANGE) {
900 * If the parameter table entry for this mode is not found,
901 * the mode is not supported...
903 if (get_mode_param(mode) == NULL)
906 #endif /* VGA_NO_MODE_CHANGE */
909 * Even if we don't support video mode switching on this adapter,
910 * the information on the initial (thus current) video mode
911 * should be made available.
913 if (mode != adp->va_initial_mode)
917 for (i = 0; bios_vmode[i].vi_mode != EOT; ++i) {
918 if (bios_vmode[i].vi_mode == NA)
920 if (mode == bios_vmode[i].vi_mode) {
921 *info = bios_vmode[i];
923 info->vi_buffer_size = info->vi_window_size*info->vi_planes;
932 * Find a video mode matching the requested parameters.
933 * Fields filled with 0 are considered "don't care" fields and
937 vga_query_mode(video_adapter_t *adp, video_info_t *info)
944 for (i = 0; bios_vmode[i].vi_mode != EOT; ++i) {
945 if (bios_vmode[i].vi_mode == NA)
948 if ((info->vi_width != 0)
949 && (info->vi_width != bios_vmode[i].vi_width))
951 if ((info->vi_height != 0)
952 && (info->vi_height != bios_vmode[i].vi_height))
954 if ((info->vi_cwidth != 0)
955 && (info->vi_cwidth != bios_vmode[i].vi_cwidth))
957 if ((info->vi_cheight != 0)
958 && (info->vi_cheight != bios_vmode[i].vi_cheight))
960 if ((info->vi_depth != 0)
961 && (info->vi_depth != bios_vmode[i].vi_depth))
963 if ((info->vi_planes != 0)
964 && (info->vi_planes != bios_vmode[i].vi_planes))
966 /* XXX: should check pixel format, memory model */
967 if ((info->vi_flags != 0)
968 && (info->vi_flags != bios_vmode[i].vi_flags))
971 /* verify if this mode is supported on this adapter */
972 if (vga_get_info(adp, bios_vmode[i].vi_mode, info))
981 * Change the video mode.
984 #ifndef VGA_NO_MODE_CHANGE
987 set_width90(adp_state_t *params)
990 * Based on code submitted by Kelly Yancey (kbyanc@freedomnet.com)
991 * and alexv@sui.gda.itesm.mx.
993 params->regs[5] |= 1; /* toggle 8 pixel wide fonts */
994 params->regs[10+0x0] = 0x6b;
995 params->regs[10+0x1] = 0x59;
996 params->regs[10+0x2] = 0x5a;
997 params->regs[10+0x3] = 0x8e;
998 params->regs[10+0x4] = 0x5e;
999 params->regs[10+0x5] = 0x8a;
1000 params->regs[10+0x13] = 45;
1001 params->regs[35+0x13] = 0;
1003 #endif /* VGA_WIDTH90 */
1004 #endif /* !VGA_NO_MODE_CHANGE */
1007 vga_set_mode(video_adapter_t *adp, int mode)
1009 #ifndef VGA_NO_MODE_CHANGE
1013 prologue(adp, V_ADP_MODECHANGE, ENODEV);
1015 if (vga_get_info(adp, mode, &info))
1018 lwkt_gettoken(&tty_token);
1021 kprintf("vga_set_mode(): setting mode %d\n", mode);
1024 params.sig = V_STATE_SIG;
1025 bcopy(get_mode_param(mode), params.regs, sizeof(params.regs));
1029 case M_VGA_C90x60: case M_VGA_M90x60:
1030 set_width90(¶ms);
1033 case M_VGA_C80x60: case M_VGA_M80x60:
1034 params.regs[2] = 0x08;
1035 params.regs[19] = 0x47;
1039 case M_VGA_C90x30: case M_VGA_M90x30:
1040 set_width90(¶ms);
1043 case M_VGA_C80x30: case M_VGA_M80x30:
1044 params.regs[19] = 0x4f;
1046 params.regs[9] |= 0xc0;
1047 params.regs[16] = 0x08;
1048 params.regs[17] = 0x3e;
1049 params.regs[26] = 0xea;
1050 params.regs[28] = 0xdf;
1051 params.regs[31] = 0xe7;
1052 params.regs[32] = 0x04;
1056 case M_VGA_C90x43: case M_VGA_M90x43:
1057 set_width90(¶ms);
1060 case M_ENH_C80x43: case M_ENH_B80x43:
1061 params.regs[28] = 87;
1065 case M_VGA_C90x50: case M_VGA_M90x50:
1066 set_width90(¶ms);
1069 case M_VGA_C80x50: case M_VGA_M80x50:
1072 params.regs[19] = 7;
1076 case M_VGA_C90x25: case M_VGA_M90x25:
1077 set_width90(¶ms);
1080 case M_VGA_C40x25: case M_VGA_C80x25:
1082 case M_B40x25: case M_C40x25:
1083 case M_B80x25: case M_C80x25:
1084 case M_ENH_B40x25: case M_ENH_C40x25:
1085 case M_ENH_B80x25: case M_ENH_C80x25:
1086 case M_EGAMONO80x25:
1089 vga_load_state(adp, ¶ms);
1093 /* "unchain" the VGA mode */
1094 params.regs[5-1+0x04] &= 0xf7;
1095 params.regs[5-1+0x04] |= 0x04;
1096 /* turn off doubleword mode */
1097 params.regs[10+0x14] &= 0xbf;
1098 /* turn off word addressing */
1099 params.regs[10+0x17] |= 0x40;
1100 /* set logical screen width */
1101 params.regs[10+0x13] = 80;
1103 params.regs[10+0x11] = 0x2c;
1104 params.regs[10+0x06] = 0x0d;
1105 params.regs[10+0x07] = 0x3e;
1106 params.regs[10+0x10] = 0xea;
1107 params.regs[10+0x11] = 0xac;
1108 params.regs[10+0x12] = 0xdf;
1109 params.regs[10+0x15] = 0xe7;
1110 params.regs[10+0x16] = 0x06;
1111 /* set vertical sync polarity to reflect aspect ratio */
1112 params.regs[9] = 0xe3;
1115 case M_BG320: case M_CG320: case M_BG640:
1116 case M_CG320_D: case M_CG640_E:
1117 case M_CG640x350: case M_ENH_CG640:
1118 case M_BG640x480: case M_CG640x480: case M_VGA_CG320:
1121 vga_load_state(adp, ¶ms);
1125 lwkt_reltoken(&tty_token);
1129 adp->va_mode = mode;
1130 info.vi_flags &= ~V_INFO_LINEAR; /* XXX */
1131 update_adapter_info(adp, &info);
1133 /* move hardware cursor out of the way */
1134 (*vidsw[adp->va_index]->set_hw_cursor)(adp, -1, -1);
1136 lwkt_reltoken(&tty_token);
1138 #else /* VGA_NO_MODE_CHANGE */
1139 lwkt_reltoken(&tty_token);
1141 #endif /* VGA_NO_MODE_CHANGE */
1144 #ifndef VGA_NO_FONT_LOADING
1147 set_font_mode(video_adapter_t *adp, u_char *buf)
1151 /* save register values */
1152 outb(TSIDX, 0x02); buf[0] = inb(TSREG);
1153 outb(TSIDX, 0x04); buf[1] = inb(TSREG);
1154 outb(GDCIDX, 0x04); buf[2] = inb(GDCREG);
1155 outb(GDCIDX, 0x05); buf[3] = inb(GDCREG);
1156 outb(GDCIDX, 0x06); buf[4] = inb(GDCREG);
1158 outb(ATC, 0x10); buf[5] = inb(ATC + 1);
1160 /* setup vga for loading fonts */
1161 inb(CRTC + 6); /* reset flip-flop */
1162 outb(ATC, 0x10); outb(ATC, buf[5] & ~0x01);
1163 inb(CRTC + 6); /* reset flip-flop */
1164 outb(ATC, 0x20); /* enable palette */
1166 #ifdef VGA_ALT_SEQACCESS
1167 outw(TSIDX, 0x0100);
1169 outw(TSIDX, 0x0402);
1170 outw(TSIDX, 0x0704);
1171 #ifdef VGA_ALT_SEQACCESS
1172 outw(TSIDX, 0x0300);
1174 outw(GDCIDX, 0x0204);
1175 outw(GDCIDX, 0x0005);
1176 outw(GDCIDX, 0x0406); /* addr = a0000, 64kb */
1182 set_normal_mode(video_adapter_t *adp, u_char *buf)
1186 /* setup vga for normal operation mode again */
1187 inb(CRTC + 6); /* reset flip-flop */
1188 outb(ATC, 0x10); outb(ATC, buf[5]);
1189 inb(CRTC + 6); /* reset flip-flop */
1190 outb(ATC, 0x20); /* enable palette */
1192 #ifdef VGA_ALT_SEQACCESS
1193 outw(TSIDX, 0x0100);
1195 outw(TSIDX, 0x0002 | (buf[0] << 8));
1196 outw(TSIDX, 0x0004 | (buf[1] << 8));
1197 #ifdef VGA_ALT_SEQACCESS
1198 outw(TSIDX, 0x0300);
1200 outw(GDCIDX, 0x0004 | (buf[2] << 8));
1201 outw(GDCIDX, 0x0005 | (buf[3] << 8));
1202 outw(GDCIDX, 0x0006 | (((buf[4] & 0x03) | 0x0c)<<8));
1207 #endif /* VGA_NO_FONT_LOADING */
1211 * Read the font data in the requested font page from the video adapter.
1214 vga_save_font(video_adapter_t *adp, int page, int fontsize, u_char *data,
1217 #ifndef VGA_NO_FONT_LOADING
1218 u_char buf[PARAM_BUFSIZE];
1219 vm_offset_t segment;
1221 #ifdef VGA_ALT_SEQACCESS
1225 prologue(adp, V_ADP_FONT, ENODEV);
1227 if (fontsize < 14) {
1230 } else if (fontsize >= 32) {
1232 } else if (fontsize >= 16) {
1240 if (page < 0 || page >= 8)
1242 segment = FONT_BUF + 0x4000*page;
1246 #ifdef VGA_ALT_SEQACCESS
1248 outb(TSIDX, 0x00); outb(TSREG, 0x01);
1249 outb(TSIDX, 0x01); val = inb(TSREG); /* disable screen */
1250 outb(TSIDX, 0x01); outb(TSREG, val | 0x20);
1251 outb(TSIDX, 0x00); outb(TSREG, 0x03);
1255 set_font_mode(adp, buf);
1256 if (fontsize == 32) {
1257 bcopy_fromio((uintptr_t)segment + ch*32, data, fontsize*count);
1259 for (c = ch; count > 0; ++c, --count) {
1260 bcopy_fromio((uintptr_t)segment + c*32, data, fontsize);
1264 set_normal_mode(adp, buf);
1266 #ifdef VGA_ALT_SEQACCESS
1268 outb(TSIDX, 0x00); outb(TSREG, 0x01);
1269 outb(TSIDX, 0x01); outb(TSREG, val & 0xdf); /* enable screen */
1270 outb(TSIDX, 0x00); outb(TSREG, 0x03);
1275 #else /* VGA_NO_FONT_LOADING */
1277 #endif /* VGA_NO_FONT_LOADING */
1282 * Set the font data in the requested font page.
1283 * NOTE: it appears that some recent video adapters do not support
1284 * the font page other than 0... XXX
1287 vga_load_font(video_adapter_t *adp, int page, int fontsize, u_char *data,
1290 #ifndef VGA_NO_FONT_LOADING
1291 u_char buf[PARAM_BUFSIZE];
1292 vm_offset_t segment;
1294 #ifdef VGA_ALT_SEQACCESS
1298 prologue(adp, V_ADP_FONT, ENODEV);
1300 if (fontsize < 14) {
1303 } else if (fontsize >= 32) {
1305 } else if (fontsize >= 16) {
1313 if (page < 0 || page >= 8)
1315 segment = FONT_BUF + 0x4000*page;
1319 #ifdef VGA_ALT_SEQACCESS
1321 outb(TSIDX, 0x00); outb(TSREG, 0x01);
1322 outb(TSIDX, 0x01); val = inb(TSREG); /* disable screen */
1323 outb(TSIDX, 0x01); outb(TSREG, val | 0x20);
1324 outb(TSIDX, 0x00); outb(TSREG, 0x03);
1328 set_font_mode(adp, buf);
1329 if (fontsize == 32) {
1330 bcopy_toio(data, (uintptr_t)segment + ch*32, fontsize*count);
1332 for (c = ch; count > 0; ++c, --count) {
1333 bcopy_toio(data, (uintptr_t)segment + c*32, fontsize);
1337 set_normal_mode(adp, buf);
1339 #ifdef VGA_ALT_SEQACCESS
1341 outb(TSIDX, 0x00); outb(TSREG, 0x01);
1342 outb(TSIDX, 0x01); outb(TSREG, val & 0xdf); /* enable screen */
1343 outb(TSIDX, 0x00); outb(TSREG, 0x03);
1348 #else /* VGA_NO_FONT_LOADING */
1350 #endif /* VGA_NO_FONT_LOADING */
1355 * Activate the requested font page.
1356 * NOTE: it appears that some recent video adapters do not support
1357 * the font page other than 0... XXX
1360 vga_show_font(video_adapter_t *adp, int page)
1362 #ifndef VGA_NO_FONT_LOADING
1363 static u_char cg[] = { 0x00, 0x05, 0x0a, 0x0f, 0x30, 0x35, 0x3a, 0x3f };
1365 prologue(adp, V_ADP_FONT, ENODEV);
1366 if (page < 0 || page >= 8)
1370 outb(TSIDX, 0x03); outb(TSREG, cg[page]);
1374 #else /* VGA_NO_FONT_LOADING */
1376 #endif /* VGA_NO_FONT_LOADING */
1381 * Read DAC values. The values have expressed in 8 bits.
1386 vga_save_palette(video_adapter_t *adp, u_char *palette)
1390 prologue(adp, V_ADP_PALETTE, ENODEV);
1393 * We store 8 bit values in the palette buffer, while the standard
1394 * VGA has 6 bit DAC .
1396 outb(PALRADR, 0x00);
1397 for (i = 0; i < 256*3; ++i)
1398 palette[i] = inb(PALDATA) << 2;
1399 inb(CRTC + 6); /* reset flip/flop */
1404 vga_save_palette2(video_adapter_t *adp, int base, int count,
1405 u_char *r, u_char *g, u_char *b)
1409 prologue(adp, V_ADP_PALETTE, ENODEV);
1411 outb(PALRADR, base);
1412 for (i = 0; i < count; ++i) {
1413 r[i] = inb(PALDATA) << 2;
1414 g[i] = inb(PALDATA) << 2;
1415 b[i] = inb(PALDATA) << 2;
1417 inb(CRTC + 6); /* reset flip/flop */
1428 vga_load_palette(video_adapter_t *adp, const u_char *palette)
1432 prologue(adp, V_ADP_PALETTE, ENODEV);
1434 outb(PIXMASK, 0xff); /* no pixelmask */
1435 outb(PALWADR, 0x00);
1436 for (i = 0; i < 256*3; ++i)
1437 outb(PALDATA, palette[i] >> 2);
1438 inb(CRTC + 6); /* reset flip/flop */
1439 outb(ATC, 0x20); /* enable palette */
1444 vga_load_palette2(video_adapter_t *adp, int base, int count,
1445 u_char *r, u_char *g, u_char *b)
1449 prologue(adp, V_ADP_PALETTE, ENODEV);
1451 outb(PIXMASK, 0xff); /* no pixelmask */
1452 outb(PALWADR, base);
1453 for (i = 0; i < count; ++i) {
1454 outb(PALDATA, r[i] >> 2);
1455 outb(PALDATA, g[i] >> 2);
1456 outb(PALDATA, b[i] >> 2);
1458 inb(CRTC + 6); /* reset flip/flop */
1459 outb(ATC, 0x20); /* enable palette */
1465 * Change the border color.
1468 vga_set_border(video_adapter_t *adp, int color)
1470 prologue(adp, V_ADP_BORDER, ENODEV);
1472 inb(CRTC + 6); /* reset flip-flop */
1473 outb(ATC, 0x31); outb(ATC, color & 0xff);
1480 * Read video register values.
1481 * NOTE: this function only reads the standard VGA registers.
1482 * any extra/extended registers of SVGA adapters are not saved.
1485 vga_save_state(video_adapter_t *adp, void *p, size_t size)
1493 /* return the required buffer size */
1494 prologue(adp, V_ADP_STATESAVE, 0);
1495 return sizeof(adp_state_t);
1497 prologue(adp, V_ADP_STATESAVE, ENODEV);
1498 if (size < sizeof(adp_state_t))
1501 ((adp_state_t *)p)->sig = V_STATE_SIG;
1502 buf = ((adp_state_t *)p)->regs;
1503 bzero(buf, V_MODE_PARAM_SIZE);
1508 outb(TSIDX, 0x00); outb(TSREG, 0x01); /* stop sequencer */
1509 for (i = 0, j = 5; i < 4; i++) {
1511 buf[j++] = inb(TSREG);
1513 buf[9] = inb(MISC + 10); /* dot-clock */
1514 outb(TSIDX, 0x00); outb(TSREG, 0x03); /* start sequencer */
1516 for (i = 0, j = 10; i < 25; i++) { /* crtc */
1518 buf[j++] = inb(crtc_addr + 1);
1520 for (i = 0, j = 35; i < 20; i++) { /* attribute ctrl */
1521 inb(crtc_addr + 6); /* reset flip-flop */
1523 buf[j++] = inb(ATC + 1);
1525 for (i = 0, j = 55; i < 9; i++) { /* graph data ctrl */
1527 buf[j++] = inb(GDCREG);
1529 inb(crtc_addr + 6); /* reset flip-flop */
1530 outb(ATC, 0x20); /* enable palette */
1535 if (vga_get_info(adp, adp->va_mode, &info) == 0) {
1536 if (info.vi_flags & V_INFO_GRAPHICS) {
1537 buf[0] = info.vi_width/info.vi_cwidth; /* COLS */
1538 buf[1] = info.vi_height/info.vi_cheight - 1; /* ROWS */
1540 buf[0] = info.vi_width; /* COLS */
1541 buf[1] = info.vi_height - 1; /* ROWS */
1543 buf[2] = info.vi_cheight; /* POINTS */
1545 /* XXX: shouldn't be happening... */
1546 kprintf("vga%d: %s: failed to obtain mode info. (vga_save_state())\n",
1547 adp->va_unit, adp->va_name);
1550 buf[0] = readb(BIOS_PADDRTOVADDR(0x44a)); /* COLS */
1551 buf[1] = readb(BIOS_PADDRTOVADDR(0x484)); /* ROWS */
1552 buf[2] = readb(BIOS_PADDRTOVADDR(0x485)); /* POINTS */
1553 buf[3] = readb(BIOS_PADDRTOVADDR(0x44c));
1554 buf[4] = readb(BIOS_PADDRTOVADDR(0x44d));
1562 * Set video registers at once.
1563 * NOTE: this function only updates the standard VGA registers.
1564 * any extra/extended registers of SVGA adapters are not changed.
1567 vga_load_state(video_adapter_t *adp, void *p)
1573 prologue(adp, V_ADP_STATELOAD, ENODEV);
1574 if (((adp_state_t *)p)->sig != V_STATE_SIG)
1577 buf = ((adp_state_t *)p)->regs;
1581 hexdump(buf, V_MODE_PARAM_SIZE, NULL, HD_OMIT_CHARS | HD_OMIT_COUNT);
1586 outb(TSIDX, 0x00); outb(TSREG, 0x01); /* stop sequencer */
1587 for (i = 0; i < 4; ++i) { /* program sequencer */
1589 outb(TSREG, buf[i + 5]);
1591 outb(MISC, buf[9]); /* set dot-clock */
1592 outb(TSIDX, 0x00); outb(TSREG, 0x03); /* start sequencer */
1593 outb(crtc_addr, 0x11);
1594 outb(crtc_addr + 1, inb(crtc_addr + 1) & 0x7F);
1595 for (i = 0; i < 25; ++i) { /* program crtc */
1597 outb(crtc_addr + 1, buf[i + 10]);
1599 inb(crtc_addr+6); /* reset flip-flop */
1600 for (i = 0; i < 20; ++i) { /* program attribute ctrl */
1602 outb(ATC, buf[i + 35]);
1604 for (i = 0; i < 9; ++i) { /* program graph data ctrl */
1606 outb(GDCREG, buf[i + 55]);
1608 inb(crtc_addr + 6); /* reset flip-flop */
1609 outb(ATC, 0x20); /* enable palette */
1611 #if 0 /* XXX a temporary workaround for kernel panic */
1613 if (adp->va_unit == V_ADP_PRIMARY) {
1614 writeb(BIOS_PADDRTOVADDR(0x44a), buf[0]); /* COLS */
1615 writeb(BIOS_PADDRTOVADDR(0x484), buf[1] + rows_offset - 1); /* ROWS */
1616 writeb(BIOS_PADDRTOVADDR(0x485), buf[2]); /* POINTS */
1618 writeb(BIOS_PADDRTOVADDR(0x44c), buf[3]);
1619 writeb(BIOS_PADDRTOVADDR(0x44d), buf[4]);
1622 #endif /* VGA_NO_BIOS */
1631 * Change the origin (window mapping) of the banked frame buffer.
1634 vga_set_origin(video_adapter_t *adp, off_t offset)
1637 * The standard video modes do not require window mapping;
1638 * always return error.
1645 * Read the position of the hardware text cursor.
1648 vga_read_hw_cursor(video_adapter_t *adp, int *col, int *row)
1655 if (adp->va_info.vi_flags & V_INFO_GRAPHICS)
1660 off = inb(CRTC + 1);
1662 off = (off << 8) | inb(CRTC + 1);
1665 *row = off / adp->va_info.vi_width;
1666 *col = off % adp->va_info.vi_width;
1673 * Move the hardware text cursor. If col and row are both -1,
1674 * the cursor won't be shown.
1677 vga_set_hw_cursor(video_adapter_t *adp, int col, int row)
1684 if ((col == -1) && (row == -1)) {
1687 if (adp->va_info.vi_flags & V_INFO_GRAPHICS)
1689 off = row*adp->va_info.vi_width + col;
1694 outb(CRTC + 1, off >> 8);
1696 outb(CRTC + 1, off & 0x00ff);
1703 * set_hw_cursor_shape():
1704 * Change the shape of the hardware text cursor. If the height is
1705 * zero or negative, the cursor won't be shown.
1708 vga_set_hw_cursor_shape(video_adapter_t *adp, int base, int height,
1709 int celsize, int blink)
1716 /* make the cursor invisible */
1723 outb(CRTC + 1, celsize - base - height);
1725 outb(CRTC + 1, celsize - base - 1);
1734 * Put the display in power save/power off mode.
1737 vga_blank_display(video_adapter_t *adp, int mode)
1743 case V_DISPLAY_SUSPEND:
1744 case V_DISPLAY_STAND_BY:
1748 outb(TSREG, val | 0x20);
1750 val = inb(CRTC + 1);
1751 outb(CRTC + 1, val & ~0x80);
1757 outb(TSREG, val | 0x20);
1763 outb(TSREG, val & 0xDF);
1765 val = inb(CRTC + 1);
1766 outb(CRTC + 1, val | 0x80);
1776 * Mmap frame buffer.
1779 vga_mmap_buf(video_adapter_t *adp, vm_offset_t offset, int prot)
1781 if (adp->va_info.vi_flags & V_INFO_LINEAR)
1785 kprintf("vga_mmap_buf(): window:0x%x, offset:%p\n",
1786 adp->va_info.vi_window, (void *)offset);
1789 /* XXX: is this correct? */
1790 if (offset > adp->va_window_size - PAGE_SIZE)
1793 #if defined(__i386__)
1794 return i386_btop(adp->va_info.vi_window + offset);
1795 #elif defined(__x86_64__)
1796 return x86_64_btop(adp->va_info.vi_window + offset);
1798 #error "vga_mmap_buf needs to return something"
1802 #ifndef VGA_NO_MODE_CHANGE
1805 planar_fill(video_adapter_t *adp, int val)
1808 int at; /* position in the frame buffer */
1811 lwkt_gettoken(&tty_token);
1812 outw(GDCIDX, 0x0005); /* read mode 0, write mode 0 */
1813 outw(GDCIDX, 0x0003); /* data rotate/function select */
1814 outw(GDCIDX, 0x0f01); /* set/reset enable */
1815 outw(GDCIDX, 0xff08); /* bit mask */
1816 outw(GDCIDX, (val << 8) | 0x00); /* set/reset */
1818 length = adp->va_line_width*adp->va_info.vi_height;
1819 while (length > 0) {
1820 l = imin(length, adp->va_window_size);
1821 (*vidsw[adp->va_index]->set_win_org)(adp, at);
1822 bzero_io(adp->va_window, l);
1826 outw(GDCIDX, 0x0000); /* set/reset */
1827 outw(GDCIDX, 0x0001); /* set/reset enable */
1828 lwkt_reltoken(&tty_token);
1832 packed_fill(video_adapter_t *adp, int val)
1835 int at; /* position in the frame buffer */
1838 lwkt_gettoken(&tty_token);
1840 length = adp->va_line_width*adp->va_info.vi_height;
1841 while (length > 0) {
1842 l = imin(length, adp->va_window_size);
1843 (*vidsw[adp->va_index]->set_win_org)(adp, at);
1844 fill_io(val, adp->va_window, l);
1848 lwkt_reltoken(&tty_token);
1852 direct_fill(video_adapter_t *adp, int val)
1855 int at; /* position in the frame buffer */
1858 lwkt_gettoken(&tty_token);
1860 length = adp->va_line_width*adp->va_info.vi_height;
1861 while (length > 0) {
1862 l = imin(length, adp->va_window_size);
1863 (*vidsw[adp->va_index]->set_win_org)(adp, at);
1864 switch (adp->va_info.vi_pixel_size) {
1865 case sizeof(u_int16_t):
1866 fillw_io(val, adp->va_window, l/sizeof(u_int16_t));
1871 case sizeof(u_int32_t):
1872 filll_io(val, adp->va_window, l/sizeof(u_int32_t));
1878 lwkt_reltoken(&tty_token);
1882 vga_clear(video_adapter_t *adp)
1884 switch (adp->va_info.vi_mem_model) {
1885 case V_INFO_MM_TEXT:
1886 /* do nothing? XXX */
1888 case V_INFO_MM_PLANAR:
1889 planar_fill(adp, 0);
1891 case V_INFO_MM_PACKED:
1892 packed_fill(adp, 0);
1894 case V_INFO_MM_DIRECT:
1895 direct_fill(adp, 0);
1903 planar_fill_rect(video_adapter_t *adp, int val, int x, int y, int cx, int cy)
1908 int offset; /* offset within window */
1912 lwkt_gettoken(&tty_token);
1913 outw(GDCIDX, 0x0005); /* read mode 0, write mode 0 */
1914 outw(GDCIDX, 0x0003); /* data rotate/function select */
1915 outw(GDCIDX, 0x0f01); /* set/reset enable */
1916 outw(GDCIDX, 0xff08); /* bit mask */
1917 outw(GDCIDX, (val << 8) | 0x00); /* set/reset */
1919 banksize = adp->va_window_size;
1922 pos = adp->va_line_width*y + x/8;
1923 if (bank != pos/banksize) {
1924 (*vidsw[adp->va_index]->set_win_org)(adp, pos);
1925 bank = pos/banksize;
1927 offset = pos%banksize;
1928 bx = (x + cx)/8 - x/8;
1930 outw(GDCIDX, ((0xff00 >> (x % 8)) & 0xff00) | 0x08);
1931 writeb(adp->va_window + offset, 0);
1934 if (offset >= banksize) {
1936 ++bank; /* next bank */
1937 (*vidsw[adp->va_index]->set_win_org)(adp, bank*banksize);
1939 outw(GDCIDX, 0xff08); /* bit mask */
1942 l = imin(bx, banksize);
1943 bzero_io(adp->va_window + offset, l);
1946 if (offset >= banksize) {
1948 ++bank; /* next bank */
1949 (*vidsw[adp->va_index]->set_win_org)(adp, bank*banksize);
1953 outw(GDCIDX, (~(0xff00 >> ((x + cx) % 8)) & 0xff00) | 0x08);
1954 writeb(adp->va_window + offset, 0);
1956 if (offset >= banksize) {
1958 ++bank; /* next bank */
1959 (*vidsw[adp->va_index]->set_win_org)(adp, bank*banksize);
1961 outw(GDCIDX, 0xff08); /* bit mask */
1967 outw(GDCIDX, 0xff08); /* bit mask */
1968 outw(GDCIDX, 0x0000); /* set/reset */
1969 outw(GDCIDX, 0x0001); /* set/reset enable */
1970 lwkt_reltoken(&tty_token);
1974 packed_fill_rect(video_adapter_t *adp, int val, int x, int y, int cx, int cy)
1979 int offset; /* offset within window */
1982 lwkt_gettoken(&tty_token);
1983 banksize = adp->va_window_size;
1985 cx *= adp->va_info.vi_pixel_size;
1987 pos = adp->va_line_width*y + x*adp->va_info.vi_pixel_size;
1988 if (bank != pos/banksize) {
1989 (*vidsw[adp->va_index]->set_win_org)(adp, pos);
1990 bank = pos/banksize;
1992 offset = pos%banksize;
1993 end = imin(offset + cx, banksize);
1994 fill_io(val, adp->va_window + offset,
1995 (end - offset)/adp->va_info.vi_pixel_size);
1996 /* the line may cross the window boundary */
1997 if (offset + cx > banksize) {
1998 ++bank; /* next bank */
1999 (*vidsw[adp->va_index]->set_win_org)(adp, bank*banksize);
2000 end = offset + cx - banksize;
2001 fill_io(val, adp->va_window, end/adp->va_info.vi_pixel_size);
2006 lwkt_reltoken(&tty_token);
2010 direct_fill_rect16(video_adapter_t *adp, int val, int x, int y, int cx, int cy)
2015 int offset; /* offset within window */
2018 lwkt_gettoken(&tty_token);
2020 * XXX: the function assumes that banksize is a muliple of
2021 * sizeof(u_int16_t).
2023 banksize = adp->va_window_size;
2025 cx *= sizeof(u_int16_t);
2027 pos = adp->va_line_width*y + x*sizeof(u_int16_t);
2028 if (bank != pos/banksize) {
2029 (*vidsw[adp->va_index]->set_win_org)(adp, pos);
2030 bank = pos/banksize;
2032 offset = pos%banksize;
2033 end = imin(offset + cx, banksize);
2034 fillw_io(val, adp->va_window + offset,
2035 (end - offset)/sizeof(u_int16_t));
2036 /* the line may cross the window boundary */
2037 if (offset + cx > banksize) {
2038 ++bank; /* next bank */
2039 (*vidsw[adp->va_index]->set_win_org)(adp, bank*banksize);
2040 end = offset + cx - banksize;
2041 fillw_io(val, adp->va_window, end/sizeof(u_int16_t));
2046 lwkt_reltoken(&tty_token);
2050 direct_fill_rect24(video_adapter_t *adp, int val, int x, int y, int cx, int cy)
2055 int offset; /* offset within window */
2061 lwkt_gettoken(&tty_token);
2062 b[0] = val & 0x0000ff;
2063 b[1] = (val >> 8) & 0x0000ff;
2064 b[2] = (val >> 16) & 0x0000ff;
2065 banksize = adp->va_window_size;
2069 pos = adp->va_line_width*y + x*3;
2070 if (bank != pos/banksize) {
2071 (*vidsw[adp->va_index]->set_win_org)(adp, pos);
2072 bank = pos/banksize;
2074 offset = pos%banksize;
2075 end = imin(offset + cx, banksize);
2076 for (i = 0, j = offset; j < end; i = (++i)%3, ++j) {
2077 writeb(adp->va_window + j, b[i]);
2079 /* the line may cross the window boundary */
2080 if (offset + cx >= banksize) {
2081 ++bank; /* next bank */
2082 (*vidsw[adp->va_index]->set_win_org)(adp, bank*banksize);
2084 end = offset + cx - banksize;
2085 for (; j < end; i = (++i)%3, ++j) {
2086 writeb(adp->va_window + j, b[i]);
2092 lwkt_reltoken(&tty_token);
2096 direct_fill_rect32(video_adapter_t *adp, int val, int x, int y, int cx, int cy)
2101 int offset; /* offset within window */
2104 lwkt_gettoken(&tty_token);
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));
2132 lwkt_reltoken(&tty_token);
2136 vga_fill_rect(video_adapter_t *adp, int val, int x, int y, int cx, int cy)
2138 switch (adp->va_info.vi_mem_model) {
2139 case V_INFO_MM_TEXT:
2140 /* do nothing? XXX */
2142 case V_INFO_MM_PLANAR:
2143 planar_fill_rect(adp, val, x, y, cx, cy);
2145 case V_INFO_MM_PACKED:
2146 packed_fill_rect(adp, val, x, y, cx, cy);
2148 case V_INFO_MM_DIRECT:
2149 switch (adp->va_info.vi_pixel_size) {
2150 case sizeof(u_int16_t):
2151 direct_fill_rect16(adp, val, x, y, cx, cy);
2154 direct_fill_rect24(adp, val, x, y, cx, cy);
2156 case sizeof(u_int32_t):
2157 direct_fill_rect32(adp, val, x, y, cx, cy);
2166 vga_fill_rect(video_adapter_t *adp, int val, int x, int y, int cx, int cy)
2173 vga_bitblt(video_adapter_t *adp,...)
2179 #endif /* !VGA_NO_MODE_CHANGE */
2182 get_palette(video_adapter_t *adp, int base, int count,
2183 u_char *red, u_char *green, u_char *blue, u_char *trans)
2189 if (count < 0 || base < 0 || count > 256 || base > 256 ||
2193 r = kmalloc(count*3, M_DEVBUF, M_WAITOK);
2196 if (vga_save_palette2(adp, base, count, r, g, b)) {
2200 copyout(r, red, count);
2201 copyout(g, green, count);
2202 copyout(b, blue, count);
2203 if (trans != NULL) {
2205 copyout(r, trans, count);
2213 set_palette(video_adapter_t *adp, int base, int count,
2214 u_char *red, u_char *green, u_char *blue, u_char *trans)
2221 if (count < 0 || base < 0 || count > 256 || base > 256 ||
2225 r = kmalloc(count*3, M_DEVBUF, M_WAITOK);
2228 err = copyin(red, r, count);
2230 err = copyin(green, g, count);
2232 err = copyin(blue, b, count);
2234 err = vga_load_palette2(adp, base, count, r, g, b);
2237 return (err ? ENODEV : 0);
2241 vga_dev_ioctl(video_adapter_t *adp, u_long cmd, caddr_t arg)
2244 case FBIO_GETWINORG: /* get frame buffer window origin */
2248 case FBIO_SETWINORG: /* set frame buffer window origin */
2251 case FBIO_SETDISPSTART: /* set display start address */
2252 return (set_display_start(adp,
2253 ((video_display_start_t *)arg)->x,
2254 ((video_display_start_t *)arg)->y)
2257 case FBIO_SETLINEWIDTH: /* set scan line length in pixel */
2258 return (set_line_length(adp, *(u_int *)arg) ? ENODEV : 0);
2260 case FBIO_GETPALETTE: /* get color palette */
2261 return get_palette(adp, ((video_color_palette_t *)arg)->index,
2262 ((video_color_palette_t *)arg)->count,
2263 ((video_color_palette_t *)arg)->red,
2264 ((video_color_palette_t *)arg)->green,
2265 ((video_color_palette_t *)arg)->blue,
2266 ((video_color_palette_t *)arg)->transparent);
2268 case FBIO_SETPALETTE: /* set color palette */
2269 return set_palette(adp, ((video_color_palette_t *)arg)->index,
2270 ((video_color_palette_t *)arg)->count,
2271 ((video_color_palette_t *)arg)->red,
2272 ((video_color_palette_t *)arg)->green,
2273 ((video_color_palette_t *)arg)->blue,
2274 ((video_color_palette_t *)arg)->transparent);
2276 case FBIOGTYPE: /* get frame buffer type info. */
2277 ((struct fbtype *)arg)->fb_type = fb_type(adp->va_type);
2278 ((struct fbtype *)arg)->fb_height = adp->va_info.vi_height;
2279 ((struct fbtype *)arg)->fb_width = adp->va_info.vi_width;
2280 ((struct fbtype *)arg)->fb_depth = adp->va_info.vi_depth;
2281 if ((adp->va_info.vi_depth <= 1) || (adp->va_info.vi_depth > 8))
2282 ((struct fbtype *)arg)->fb_cmsize = 0;
2284 ((struct fbtype *)arg)->fb_cmsize = 1 << adp->va_info.vi_depth;
2285 ((struct fbtype *)arg)->fb_size = adp->va_buffer_size;
2288 case FBIOGETCMAP: /* get color palette */
2289 return get_palette(adp, ((struct fbcmap *)arg)->index,
2290 ((struct fbcmap *)arg)->count,
2291 ((struct fbcmap *)arg)->red,
2292 ((struct fbcmap *)arg)->green,
2293 ((struct fbcmap *)arg)->blue, NULL);
2295 case FBIOPUTCMAP: /* set color palette */
2296 return set_palette(adp, ((struct fbcmap *)arg)->index,
2297 ((struct fbcmap *)arg)->count,
2298 ((struct fbcmap *)arg)->red,
2299 ((struct fbcmap *)arg)->green,
2300 ((struct fbcmap *)arg)->blue, NULL);
2303 return fb_commonioctl(adp, cmd, arg);
2309 * Print some information about the video adapter and video modes,
2310 * with requested level of details.
2313 vga_diag(video_adapter_t *adp, int level)
2326 kprintf("vga: DCC code:0x%02x\n",
2327 readb(BIOS_PADDRTOVADDR(0x488)));
2328 kprintf("vga: CRTC:0x%x, video option:0x%02x, ",
2329 readw(BIOS_PADDRTOVADDR(0x463)),
2330 readb(BIOS_PADDRTOVADDR(0x487)));
2331 kprintf("rows:%d, cols:%d, font height:%d\n",
2332 readb(BIOS_PADDRTOVADDR(0x44a)),
2333 readb(BIOS_PADDRTOVADDR(0x484)) + 1,
2334 readb(BIOS_PADDRTOVADDR(0x485)));
2335 #endif /* VGA_NO_BIOS */
2336 #if !defined(VGA_NO_BIOS) && !defined(VGA_NO_MODE_CHANGE)
2337 kprintf("vga: param table:%p\n", video_mode_ptr);
2338 kprintf("vga: rows_offset:%d\n", rows_offset);
2340 #endif /* FB_DEBUG > 1 */
2342 fb_dump_adp_info(VGA_DRIVER_NAME, adp, level);
2345 if (adp->va_flags & V_ADP_MODECHANGE) {
2346 for (i = 0; bios_vmode[i].vi_mode != EOT; ++i) {
2347 if (bios_vmode[i].vi_mode == NA)
2349 if (get_mode_param(bios_vmode[i].vi_mode) == NULL)
2351 fb_dump_mode_info(VGA_DRIVER_NAME, adp, &bios_vmode[i], level);
2354 vga_get_info(adp, adp->va_initial_mode, &info); /* shouldn't fail */
2355 fb_dump_mode_info(VGA_DRIVER_NAME, adp, &info, level);
2357 #endif /* FB_DEBUG > 1 */
2359 #if !defined(VGA_NO_BIOS) && !defined(VGA_NO_MODE_CHANGE)
2360 if (video_mode_ptr == NULL)
2361 kprintf("vga%d: %s: WARNING: video mode switching is not "
2362 "fully supported on this adapter\n",
2363 adp->va_unit, adp->va_name);
2368 kprintf("VGA parameters upon power-up\n");
2369 hexdump(adpstate.regs, sizeof(adpstate.regs), NULL,
2370 HD_OMIT_CHARS | HD_OMIT_COUNT);
2372 mp = get_mode_param(adp->va_initial_mode);
2373 if (mp == NULL) /* this shouldn't be happening */
2375 kprintf("VGA parameters in BIOS for mode %d\n", adp->va_initial_mode);
2376 hexdump(adpstate2.regs, sizeof(adpstate2.regs), NULL,
2377 HD_OMIT_CHARS | HD_OMIT_COUNT);
2378 kprintf("VGA parameters to be used for mode %d\n", adp->va_initial_mode);
2379 hexdump(mp, V_MODE_PARAM_SIZE, NULL, HD_OMIT_CHARS | HD_OMIT_COUNT);