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>
51 #include <machine/pc/bios.h>
55 #include <vm/vm_param.h>
65 /* machine/pc/bios.h has got too much i386-specific stuff in it */
66 #ifndef BIOS_PADDRTOVADDR
67 #define BIOS_PADDRTOVADDR(x) (((x) - ISA_HOLE_START) + atdevbase)
70 vga_probe_unit(int unit, video_adapter_t *buf, int flags)
76 sw = vid_get_switch(VGA_DRIVER_NAME);
79 error = (*sw->probe)(unit, &adp, NULL, flags);
82 bcopy(adp, buf, sizeof(*buf));
87 vga_attach_unit(int unit, vga_softc_t *sc, int flags)
92 sw = vid_get_switch(VGA_DRIVER_NAME);
96 error = (*sw->probe)(unit, &sc->adp, NULL, flags);
99 return (*sw->init)(unit, sc->adp, flags);
102 /* cdev driver functions */
104 #ifdef FB_INSTALL_CDEV
109 vga_open(cdev_t dev, vga_softc_t *sc, int flag, int mode, struct ucred *cred)
113 if (mode & (O_CREAT | O_APPEND | O_TRUNC))
116 return genfbopen(&sc->gensc, sc->adp, flag, mode, cred);
120 vga_close(cdev_t dev, vga_softc_t *sc, int flag, int mode)
122 return genfbclose(&sc->gensc, sc->adp, flag, mode);
126 vga_read(cdev_t dev, vga_softc_t *sc, struct uio *uio, int flag)
128 return genfbread(&sc->gensc, sc->adp, uio, flag);
132 vga_write(cdev_t dev, vga_softc_t *sc, struct uio *uio, int flag)
134 return genfbread(&sc->gensc, sc->adp, uio, flag);
138 vga_ioctl(cdev_t dev, vga_softc_t *sc, u_long cmd, caddr_t arg, int flag,
141 return genfbioctl(&sc->gensc, sc->adp, cmd, arg, flag, cred);
145 vga_mmap(cdev_t dev, vga_softc_t *sc, vm_offset_t offset, int prot)
147 return genfbmmap(&sc->gensc, sc->adp, offset, prot);
150 #endif /* FB_INSTALL_CDEV */
154 #define probe_done(adp) ((adp)->va_flags & V_ADP_PROBED)
155 #define init_done(adp) ((adp)->va_flags & V_ADP_INITIALIZED)
156 #define config_done(adp) ((adp)->va_flags & V_ADP_REGISTERED)
159 #define V_MODE_MAP_SIZE (M_VGA_CG320 + 1)
160 #define V_MODE_PARAM_SIZE 64
162 /* video adapter state buffer */
165 #define V_STATE_SIG 0x736f6962
166 u_char regs[V_MODE_PARAM_SIZE];
168 typedef struct adp_state adp_state_t;
171 * NOTE: `va_window' should have a virtual address, but is initialized
172 * with a physical address in the following table, as verify_adapter()
173 * will perform address conversion at run-time.
175 static video_adapter_t biosadapter = {
176 0, KD_VGA, VGA_DRIVER_NAME, 0, 0, V_ADP_COLOR, IO_VGA, 32,
177 EGA_BUF_BASE, EGA_BUF_SIZE, CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE,
178 0, 0, 0, M_VGA_C80x25, M_C80x25, M_VGA_C80x25
181 /* video driver declarations */
182 static int vga_configure(int flags);
183 int (*vga_sub_configure)(int flags);
185 static int vga_nop(void);
187 static int vga_error(void);
188 static vi_probe_t vga_probe;
189 static vi_init_t vga_init;
190 static vi_get_info_t vga_get_info;
191 static vi_query_mode_t vga_query_mode;
192 static vi_set_mode_t vga_set_mode;
193 static vi_save_font_t vga_save_font;
194 static vi_load_font_t vga_load_font;
195 static vi_show_font_t vga_show_font;
196 static vi_save_palette_t vga_save_palette;
197 static vi_load_palette_t vga_load_palette;
198 static vi_set_border_t vga_set_border;
199 static vi_save_state_t vga_save_state;
200 static vi_load_state_t vga_load_state;
201 static vi_set_win_org_t vga_set_origin;
202 static vi_read_hw_cursor_t vga_read_hw_cursor;
203 static vi_set_hw_cursor_t vga_set_hw_cursor;
204 static vi_set_hw_cursor_shape_t vga_set_hw_cursor_shape;
205 static vi_blank_display_t vga_blank_display;
206 static vi_mmap_t vga_mmap_buf;
207 static vi_ioctl_t vga_dev_ioctl;
208 #ifndef VGA_NO_MODE_CHANGE
209 static vi_clear_t vga_clear;
210 static vi_fill_rect_t vga_fill_rect;
211 static vi_bitblt_t vga_bitblt;
212 #else /* VGA_NO_MODE_CHANGE */
213 #define vga_clear (vi_clear_t *)vga_error
214 #define vga_fill_rect (vi_fill_rect_t *)vga_error
215 #define vga_bitblt (vi_bitblt_t *)vga_error
217 static vi_diag_t vga_diag;
219 static video_switch_t vgavidsw = {
236 vga_set_hw_cursor_shape,
248 VIDEO_DRIVER(vga, vgavidsw, vga_configure);
250 /* VGA BIOS standard video modes */
254 static video_info_t bios_vmode[] = {
256 { M_B40x25, V_INFO_COLOR, 40, 25, 8, 8, 2, 1,
257 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
258 { M_C40x25, V_INFO_COLOR, 40, 25, 8, 8, 4, 1,
259 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
260 { M_B80x25, V_INFO_COLOR, 80, 25, 8, 8, 2, 1,
261 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
262 { M_C80x25, V_INFO_COLOR, 80, 25, 8, 8, 4, 1,
263 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
265 { M_ENH_B40x25, V_INFO_COLOR, 40, 25, 8, 14, 2, 1,
266 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
267 { M_ENH_C40x25, V_INFO_COLOR, 40, 25, 8, 14, 4, 1,
268 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
269 { M_ENH_B80x25, V_INFO_COLOR, 80, 25, 8, 14, 2, 1,
270 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
271 { M_ENH_C80x25, V_INFO_COLOR, 80, 25, 8, 14, 4, 1,
272 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
274 { M_VGA_C40x25, V_INFO_COLOR, 40, 25, 8, 16, 4, 1,
275 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
276 { M_VGA_M80x25, 0, 80, 25, 8, 16, 2, 1,
277 MDA_BUF_BASE, MDA_BUF_SIZE, MDA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
278 { M_VGA_C80x25, V_INFO_COLOR, 80, 25, 8, 16, 4, 1,
279 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
281 { M_EGAMONO80x25, 0, 80, 25, 8, 14, 2, 1,
282 MDA_BUF_BASE, MDA_BUF_SIZE, MDA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
284 { M_ENH_B80x43, 0, 80, 43, 8, 8, 2, 1,
285 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
286 { M_ENH_C80x43, V_INFO_COLOR, 80, 43, 8, 8, 4, 1,
287 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
289 { M_VGA_M80x30, 0, 80, 30, 8, 16, 2, 1,
290 MDA_BUF_BASE, MDA_BUF_SIZE, MDA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
291 { M_VGA_C80x30, V_INFO_COLOR, 80, 30, 8, 16, 4, 1,
292 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
293 { M_VGA_M80x50, 0, 80, 50, 8, 8, 2, 1,
294 MDA_BUF_BASE, MDA_BUF_SIZE, MDA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
295 { M_VGA_C80x50, V_INFO_COLOR, 80, 50, 8, 8, 4, 1,
296 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
297 { M_VGA_M80x60, 0, 80, 60, 8, 8, 2, 1,
298 MDA_BUF_BASE, MDA_BUF_SIZE, MDA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
299 { M_VGA_C80x60, V_INFO_COLOR, 80, 60, 8, 8, 4, 1,
300 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
302 #ifndef VGA_NO_MODE_CHANGE
305 { M_VGA_M90x25, 0, 90, 25, 8, 16, 2, 1,
306 MDA_BUF_BASE, MDA_BUF_SIZE, MDA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
307 { M_VGA_C90x25, V_INFO_COLOR, 90, 25, 8, 16, 4, 1,
308 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
309 { M_VGA_M90x30, 0, 90, 30, 8, 16, 2, 1,
310 MDA_BUF_BASE, MDA_BUF_SIZE, MDA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
311 { M_VGA_C90x30, V_INFO_COLOR, 90, 30, 8, 16, 4, 1,
312 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
313 { M_VGA_M90x43, 0, 90, 43, 8, 8, 2, 1,
314 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
315 { M_VGA_C90x43, V_INFO_COLOR, 90, 43, 8, 8, 4, 1,
316 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
317 { M_VGA_M90x50, 0, 90, 50, 8, 8, 2, 1,
318 MDA_BUF_BASE, MDA_BUF_SIZE, MDA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
319 { M_VGA_C90x50, V_INFO_COLOR, 90, 50, 8, 8, 4, 1,
320 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
321 { M_VGA_M90x60, 0, 90, 60, 8, 8, 2, 1,
322 MDA_BUF_BASE, MDA_BUF_SIZE, MDA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
323 { M_VGA_C90x60, V_INFO_COLOR, 90, 60, 8, 8, 4, 1,
324 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
325 #endif /* VGA_WIDTH90 */
328 { M_BG320, 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_CG320, V_INFO_COLOR | V_INFO_GRAPHICS, 320, 200, 8, 8, 2, 1,
331 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_CGA },
332 { M_BG640, V_INFO_COLOR | V_INFO_GRAPHICS, 640, 200, 8, 8, 1, 1,
333 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_CGA },
335 { M_CG320_D, V_INFO_COLOR | V_INFO_GRAPHICS, 320, 200, 8, 8, 4, 4,
336 GRAPHICS_BUF_BASE, GRAPHICS_BUF_SIZE, GRAPHICS_BUF_SIZE, 0, 0,
338 { M_CG640_E, V_INFO_COLOR | V_INFO_GRAPHICS, 640, 200, 8, 8, 4, 4,
339 GRAPHICS_BUF_BASE, GRAPHICS_BUF_SIZE, GRAPHICS_BUF_SIZE, 0, 0 ,
341 { M_EGAMONOAPA, V_INFO_GRAPHICS, 640, 350, 8, 14, 4, 4,
342 GRAPHICS_BUF_BASE, GRAPHICS_BUF_SIZE, 64*1024, 0, 0 ,
344 { M_ENHMONOAPA2,V_INFO_GRAPHICS, 640, 350, 8, 14, 4, 4,
345 GRAPHICS_BUF_BASE, GRAPHICS_BUF_SIZE, GRAPHICS_BUF_SIZE, 0, 0 ,
347 { M_CG640x350, V_INFO_COLOR | V_INFO_GRAPHICS, 640, 350, 8, 14, 2, 2,
348 GRAPHICS_BUF_BASE, GRAPHICS_BUF_SIZE, GRAPHICS_BUF_SIZE, 0, 0 ,
350 { M_ENH_CG640, V_INFO_COLOR | V_INFO_GRAPHICS, 640, 350, 8, 14, 4, 4,
351 GRAPHICS_BUF_BASE, GRAPHICS_BUF_SIZE, GRAPHICS_BUF_SIZE, 0, 0 ,
354 { M_BG640x480, V_INFO_COLOR | V_INFO_GRAPHICS, 640, 480, 8, 16, 4, 4,
355 GRAPHICS_BUF_BASE, GRAPHICS_BUF_SIZE, GRAPHICS_BUF_SIZE, 0, 0 ,
357 { M_CG640x480, V_INFO_COLOR | V_INFO_GRAPHICS, 640, 480, 8, 16, 4, 4,
358 GRAPHICS_BUF_BASE, GRAPHICS_BUF_SIZE, GRAPHICS_BUF_SIZE, 0, 0 ,
360 { M_VGA_CG320, V_INFO_COLOR | V_INFO_GRAPHICS, 320, 200, 8, 8, 8, 1,
361 GRAPHICS_BUF_BASE, GRAPHICS_BUF_SIZE, GRAPHICS_BUF_SIZE, 0, 0,
362 V_INFO_MM_PACKED, 1 },
363 { M_VGA_MODEX, V_INFO_COLOR | V_INFO_GRAPHICS, 320, 240, 8, 8, 8, 4,
364 GRAPHICS_BUF_BASE, GRAPHICS_BUF_SIZE, GRAPHICS_BUF_SIZE, 0, 0,
366 #endif /* VGA_NO_MODE_CHANGE */
371 static int vga_init_done = FALSE;
372 #if !defined(VGA_NO_BIOS) && !defined(VGA_NO_MODE_CHANGE)
373 static u_char *video_mode_ptr = NULL;
375 static u_char *mode_map[V_MODE_MAP_SIZE];
376 static adp_state_t adpstate;
377 static adp_state_t adpstate2;
378 static int rows_offset = 1;
380 /* local macros and functions */
381 #define BIOS_SADDRTOLADDR(p) ((((p) & 0xffff0000) >> 12) + ((p) & 0x0000ffff))
383 #if !defined(VGA_NO_BIOS) && !defined(VGA_NO_MODE_CHANGE)
384 static void map_mode_table(u_char **, u_char *);
385 static int map_mode_num(int);
388 static int map_bios_mode_num(int);
390 static u_char *get_mode_param(int);
391 static int verify_adapter(video_adapter_t *);
392 static void update_adapter_info(video_adapter_t *, video_info_t *);
393 static int probe_adapters(void);
394 static int set_line_length(video_adapter_t *, int);
395 static int set_display_start(video_adapter_t *, int, int);
397 #ifndef VGA_NO_MODE_CHANGE
399 static void set_width90(adp_state_t *);
401 #endif /* !VGA_NO_MODE_CHANGE */
403 #ifndef VGA_NO_FONT_LOADING
404 #define PARAM_BUFSIZE 6
405 static void set_font_mode(video_adapter_t *, u_char *);
406 static void set_normal_mode(video_adapter_t *, u_char *);
409 #ifndef VGA_NO_MODE_CHANGE
410 static void filll_io(int, vm_offset_t, size_t);
411 static void planar_fill(video_adapter_t *, int);
412 static void packed_fill(video_adapter_t *, int);
413 static void direct_fill(video_adapter_t *, int);
415 static void planar_fill_rect(video_adapter_t *, int, int, int, int, int);
416 static void packed_fill_rect(video_adapter_t *, int, int, int, int, int);
417 static void direct_fill_rect16(video_adapter_t *, int, int, int, int, int);
418 static void direct_fill_rect24(video_adapter_t *, int, int, int, int, int);
419 static void direct_fill_rect32(video_adapter_t *, int, int, int, int, int);
421 #endif /* !VGA_NO_MODE_CHANGE */
423 #define ISMAPPED(pa, width) \
424 (((pa) <= (u_long)0x1000 - (width)) \
425 || ((pa) >= ISA_HOLE_START && (pa) <= 0x100000 - (width)))
427 #define prologue(adp, flag, err) \
428 if (!vga_init_done || !((adp)->va_flags & (flag))) \
431 /* a backdoor for the console driver */
433 vga_configure(int flags)
436 if (probe_done(&biosadapter)) {
437 biosadapter.va_flags |= V_ADP_INITIALIZED;
438 if (!config_done(&biosadapter) && !(vid_register(&biosadapter) < 0))
439 biosadapter.va_flags |= V_ADP_REGISTERED;
441 if (vga_sub_configure != NULL)
442 (*vga_sub_configure)(flags);
447 /* local subroutines */
449 #if !defined(VGA_NO_BIOS) && !defined(VGA_NO_MODE_CHANGE)
450 /* construct the mode parameter map (accept 40x25, 80x25 and 80x30 modes) */
452 map_mode_table(u_char *map[], u_char *table)
456 for(i = 0; i < V_MODE_MAP_SIZE; ++i) {
457 map[i] = table + i*V_MODE_PARAM_SIZE;
459 if ((map[i][0] == 40 && map[i][1] == 24) ||
460 (map[i][0] == 80 && (map[i][1] == 24 || map[i][1] == 29)))
466 #endif /* !VGA_NO_BIOS && !VGA_NO_MODE_CHANGE */
468 #if !defined(VGA_NO_BIOS) && !defined(VGA_NO_MODE_CHANGE)
469 /* map the non-standard video mode to a known mode number */
471 map_mode_num(int mode)
477 { M_ENH_B80x43, M_ENH_B80x25 },
478 { M_ENH_C80x43, M_ENH_C80x25 },
479 { M_VGA_M80x30, M_VGA_M80x25 },
480 { M_VGA_C80x30, M_VGA_C80x25 },
481 { M_VGA_M80x50, M_VGA_M80x25 },
482 { M_VGA_C80x50, M_VGA_C80x25 },
483 { M_VGA_M80x60, M_VGA_M80x25 },
484 { M_VGA_C80x60, M_VGA_C80x25 },
486 { M_VGA_M90x25, M_VGA_M80x25 },
487 { M_VGA_C90x25, M_VGA_C80x25 },
488 { M_VGA_M90x30, M_VGA_M80x25 },
489 { M_VGA_C90x30, M_VGA_C80x25 },
490 { M_VGA_M90x43, M_ENH_B80x25 },
491 { M_VGA_C90x43, M_ENH_C80x25 },
492 { M_VGA_M90x50, M_VGA_M80x25 },
493 { M_VGA_C90x50, M_VGA_C80x25 },
494 { M_VGA_M90x60, M_VGA_M80x25 },
495 { M_VGA_C90x60, M_VGA_C80x25 },
497 { M_VGA_MODEX, M_VGA_CG320 },
501 for (i = 0; i < NELEM(mode_map); ++i) {
502 if (mode_map[i].from == mode)
503 return mode_map[i].to;
507 #endif /* !VGA_NO_BIOS && !VGA_NO_MODE_CHANGE */
510 /* turn the BIOS video number into our video mode number */
512 map_bios_mode_num(int bios_mode)
514 static int vga_modes[20] = {
515 M_VGA_C40x25, M_VGA_C40x25, /* 0, 1 */
516 M_VGA_C80x25, M_VGA_C80x25, /* 2, 3 */
519 M_VGA_M80x25, /* 7 */
525 M_BG640x480, M_CG640x480,
529 if (bios_mode < NELEM(vga_modes))
530 return vga_modes[bios_mode];
536 /* look up a parameter table entry */
538 get_mode_param(int mode)
540 #if !defined(VGA_NO_BIOS) && !defined(VGA_NO_MODE_CHANGE)
541 if (mode >= V_MODE_MAP_SIZE)
542 mode = map_mode_num(mode);
544 if ((mode >= 0) && (mode < V_MODE_MAP_SIZE))
545 return mode_map[mode];
551 verify_adapter(video_adapter_t *adp)
555 #if !defined(VGA_NO_BIOS) && !defined(VGA_NO_MODE_CHANGE)
559 buf = BIOS_PADDRTOVADDR(adp->va_window);
562 if (readw(buf) != 0xA55A)
570 adp->va_flags |= V_ADP_STATELOAD | V_ADP_STATESAVE | V_ADP_PALETTE |
573 #if !defined(VGA_NO_BIOS) && !defined(VGA_NO_MODE_CHANGE)
574 /* get the BIOS video mode pointer */
575 p = *(u_int32_t *)BIOS_PADDRTOVADDR(0x4a8);
576 p = BIOS_SADDRTOLADDR(p);
577 if (ISMAPPED(p, sizeof(u_int32_t))) {
578 p = *(u_int32_t *)BIOS_PADDRTOVADDR(p);
579 p = BIOS_SADDRTOLADDR(p);
580 if (ISMAPPED(p, V_MODE_PARAM_SIZE))
581 video_mode_ptr = (u_char *)BIOS_PADDRTOVADDR(p);
589 update_adapter_info(video_adapter_t *adp, video_info_t *info)
591 adp->va_flags |= V_ADP_COLOR;
592 adp->va_window = BIOS_PADDRTOVADDR(info->vi_window);
593 adp->va_window_size = info->vi_window_size;
594 adp->va_window_gran = info->vi_window_gran;
595 adp->va_window_orig = 0;
597 adp->va_buffer = info->vi_buffer;
598 adp->va_buffer_size = info->vi_buffer_size;
599 if (info->vi_mem_model == V_INFO_MM_VGAX) {
600 adp->va_line_width = info->vi_width/2;
601 } else if (info->vi_flags & V_INFO_GRAPHICS) {
602 switch (info->vi_depth/info->vi_planes) {
604 adp->va_line_width = info->vi_width/8;
607 adp->va_line_width = info->vi_width/4;
610 adp->va_line_width = info->vi_width/2;
613 default: /* shouldn't happen */
614 adp->va_line_width = info->vi_width;
618 adp->va_line_width = info->vi_width;
620 adp->va_disp_start.x = 0;
621 adp->va_disp_start.y = 0;
622 bcopy(info, &adp->va_info, sizeof(adp->va_info));
625 /* probe video adapters and return the number of detected adapters */
629 video_adapter_t *adp;
631 #if !defined(VGA_NO_BIOS) && !defined(VGA_NO_MODE_CHANGE)
636 /* do this test only once */
639 vga_init_done = TRUE;
642 * Check BIOS data area.
643 * The VGA BIOS has more sophisticated mechanism and has this
644 * information in BIOSDATA_DCCINDEX (40:8a), but it also maintains
645 * compatibility with the EGA BIOS by updating BIOSDATA_VIDEOSWITCH.
649 * XXX: we don't use BIOSDATA_EQUIPMENT, since it is not a dead
650 * copy of RTC_EQUIPMENT. Bits 4 and 5 of ETC_EQUIPMENT are
651 * zeros for VGA. However, VGA BIOS sets these bits in
652 * BIOSDATA_EQUIPMENT according to the monitor type detected.
655 if ((readb(BIOS_PADDRTOVADDR(0x488)) & 0x0f) != 0x09)
657 #endif /* VGA_NO_BIOS */
659 if (verify_adapter(&biosadapter) != 0)
662 biosadapter.va_flags |= V_ADP_PROBED;
664 biosadapter.va_initial_bios_mode = readb(BIOS_PADDRTOVADDR(0x449));
665 biosadapter.va_mode = biosadapter.va_initial_mode =
666 map_bios_mode_num(biosadapter.va_initial_bios_mode);
670 * Ensure a zero start address. This is mainly to recover after
671 * switching from pcvt using userconfig(). The registers are w/o
672 * for old hardware so it's too hard to relocate the active screen
674 * This must be done before vga_save_state() for VGA.
681 /* the video mode parameter table in VGA BIOS */
682 /* NOTE: there can be only one VGA recognized by the video BIOS.
685 bzero(mode_map, sizeof(mode_map));
686 vga_save_state(adp, &adpstate, sizeof(adpstate));
687 for(i = 0; i < 16; i++)
688 adp->va_palette_regs[i] = adpstate.regs[35 + i];
689 #if defined(VGA_NO_BIOS) || defined(VGA_NO_MODE_CHANGE)
690 mode_map[adp->va_initial_mode] = adpstate.regs;
692 #else /* VGA_NO_BIOS || VGA_NO_MODE_CHANGE */
693 if (video_mode_ptr == NULL) {
694 mode_map[adp->va_initial_mode] = adpstate.regs;
697 /* discard modes that we are not familiar with */
698 map_mode_table(mode_map, video_mode_ptr);
699 mp = get_mode_param(adp->va_initial_mode);
700 #if !defined(VGA_KEEP_POWERON_MODE)
702 bcopy(mp, adpstate2.regs, sizeof(adpstate2.regs));
703 rows_offset = adpstate.regs[1] + 1 - mp[1];
707 mode_map[adp->va_initial_mode] = adpstate.regs;
711 #endif /* VGA_NO_BIOS || VGA_NO_MODE_CHANGE */
713 #ifndef VGA_NO_MODE_CHANGE
714 adp->va_flags |= V_ADP_MODECHANGE;
716 #ifndef VGA_NO_FONT_LOADING
717 adp->va_flags |= V_ADP_FONT;
720 /* XXX remove conflicting modes */
721 for (i = 0; i < M_VGA_CG320; i++) {
722 if (vga_get_info(&biosadapter, i, &info))
724 if ((info.vi_flags & V_INFO_COLOR) != V_ADP_COLOR)
729 vga_get_info(&biosadapter, biosadapter.va_initial_mode, &info);
730 info.vi_flags &= ~V_INFO_LINEAR; /* XXX */
731 update_adapter_info(&biosadapter, &info);
734 * XXX: we should verify the following values for the primary adapter...
735 * crtc I/O port address: *(u_int16_t *)BIOS_PADDRTOVADDR(0x463);
736 * color/mono display: (*(u_int8_t *)BIOS_PADDRTOVADDR(0x487) & 0x02)
738 * columns: *(u_int8_t *)BIOS_PADDRTOVADDR(0x44a);
739 * rows: *(u_int8_t *)BIOS_PADDRTOVADDR(0x484);
740 * font size: *(u_int8_t *)BIOS_PADDRTOVADDR(0x485);
741 * buffer size: *(u_int16_t *)BIOS_PADDRTOVADDR(0x44c);
747 /* set the scan line length in pixel */
749 set_line_length(video_adapter_t *adp, int pixel)
752 int ppw; /* pixels per word */
753 int bpl; /* bytes per line */
756 mp = get_mode_param(adp->va_mode);
760 switch (adp->va_info.vi_mem_model) {
761 case V_INFO_MM_PLANAR:
762 ppw = 16/(adp->va_info.vi_depth/adp->va_info.vi_planes);
763 count = (pixel + ppw - 1)/ppw/2;
764 bpl = ((pixel + ppw - 1)/ppw/2)*4;
766 case V_INFO_MM_PACKED:
767 count = (pixel + 7)/8;
768 bpl = ((pixel + 7)/8)*8;
771 count = (pixel + 7)/8; /* columns */
772 bpl = (pixel + 7)/8; /* columns */
778 if (mp[10 + 0x17] & 0x40) /* CRTC mode control reg */
779 count *= 2; /* byte mode */
782 adp->va_line_width = bpl;
788 set_display_start(video_adapter_t *adp, int x, int y)
790 int off; /* byte offset (graphics mode)/word offset (text mode) */
791 int poff; /* pixel offset */
792 int roff; /* row offset */
793 int ppb; /* pixels per byte */
795 if (adp->va_info.vi_flags & V_INFO_GRAPHICS) {
796 ppb = 8/(adp->va_info.vi_depth/adp->va_info.vi_planes);
797 off = y*adp->va_line_width + x/ppb;
806 off = y/adp->va_info.vi_cheight*adp->va_line_width + x/ppb;
807 roff = y%adp->va_info.vi_cheight;
808 /* FIXME: is this correct? XXX */
816 outb(CRTC, 0xc); /* high */
817 outb(CRTC + 1, off >> 8);
818 outb(CRTC, 0xd); /* low */
819 outb(CRTC + 1, off & 0xff);
821 /* horizontal pel pan */
823 outb(ATC, 0x13 | 0x20);
828 /* preset raw scan */
830 outb(CRTC + 1, roff);
832 adp->va_disp_start.x = x;
833 adp->va_disp_start.y = y;
837 #ifndef VGA_NO_MODE_CHANGE
838 #if defined(__i386__) || defined(__x86_64__) /* XXX */
840 fill(int val, void *d, size_t size)
847 #endif /* __i386__ || __x86_64__ */
850 filll_io(int val, vm_offset_t d, size_t size)
854 d += sizeof(u_int32_t);
857 #endif /* !VGA_NO_MODE_CHANGE */
876 vga_probe(int unit, video_adapter_t **adpp, void *arg, int flags)
882 *adpp = &biosadapter;
888 vga_init(int unit, video_adapter_t *adp, int flags)
890 if ((unit != 0) || (adp == NULL) || !probe_done(adp))
893 if (!init_done(adp)) {
894 /* nothing to do really... */
895 adp->va_flags |= V_ADP_INITIALIZED;
898 if (!config_done(adp)) {
899 if (vid_register(adp) < 0)
901 adp->va_flags |= V_ADP_REGISTERED;
903 if (vga_sub_configure != NULL)
904 (*vga_sub_configure)(0);
911 * Return the video_info structure of the requested video mode.
914 vga_get_info(video_adapter_t *adp, int mode, video_info_t *info)
921 #ifndef VGA_NO_MODE_CHANGE
922 if (adp->va_flags & V_ADP_MODECHANGE) {
924 * If the parameter table entry for this mode is not found,
925 * the mode is not supported...
927 if (get_mode_param(mode) == NULL)
930 #endif /* VGA_NO_MODE_CHANGE */
933 * Even if we don't support video mode switching on this adapter,
934 * the information on the initial (thus current) video mode
935 * should be made available.
937 if (mode != adp->va_initial_mode)
941 for (i = 0; bios_vmode[i].vi_mode != EOT; ++i) {
942 if (bios_vmode[i].vi_mode == NA)
944 if (mode == bios_vmode[i].vi_mode) {
945 *info = bios_vmode[i];
947 info->vi_buffer_size = info->vi_window_size*info->vi_planes;
956 * Find a video mode matching the requested parameters.
957 * Fields filled with 0 are considered "don't care" fields and
961 vga_query_mode(video_adapter_t *adp, video_info_t *info)
968 for (i = 0; bios_vmode[i].vi_mode != EOT; ++i) {
969 if (bios_vmode[i].vi_mode == NA)
972 if ((info->vi_width != 0)
973 && (info->vi_width != bios_vmode[i].vi_width))
975 if ((info->vi_height != 0)
976 && (info->vi_height != bios_vmode[i].vi_height))
978 if ((info->vi_cwidth != 0)
979 && (info->vi_cwidth != bios_vmode[i].vi_cwidth))
981 if ((info->vi_cheight != 0)
982 && (info->vi_cheight != bios_vmode[i].vi_cheight))
984 if ((info->vi_depth != 0)
985 && (info->vi_depth != bios_vmode[i].vi_depth))
987 if ((info->vi_planes != 0)
988 && (info->vi_planes != bios_vmode[i].vi_planes))
990 /* XXX: should check pixel format, memory model */
991 if ((info->vi_flags != 0)
992 && (info->vi_flags != bios_vmode[i].vi_flags))
995 /* verify if this mode is supported on this adapter */
996 if (vga_get_info(adp, bios_vmode[i].vi_mode, info))
1005 * Change the video mode.
1008 #ifndef VGA_NO_MODE_CHANGE
1011 set_width90(adp_state_t *params)
1014 * Based on code submitted by Kelly Yancey (kbyanc@freedomnet.com)
1015 * and alexv@sui.gda.itesm.mx.
1017 params->regs[5] |= 1; /* toggle 8 pixel wide fonts */
1018 params->regs[10+0x0] = 0x6b;
1019 params->regs[10+0x1] = 0x59;
1020 params->regs[10+0x2] = 0x5a;
1021 params->regs[10+0x3] = 0x8e;
1022 params->regs[10+0x4] = 0x5e;
1023 params->regs[10+0x5] = 0x8a;
1024 params->regs[10+0x13] = 45;
1025 params->regs[35+0x13] = 0;
1027 #endif /* VGA_WIDTH90 */
1028 #endif /* !VGA_NO_MODE_CHANGE */
1031 vga_set_mode(video_adapter_t *adp, int mode)
1033 #ifndef VGA_NO_MODE_CHANGE
1037 prologue(adp, V_ADP_MODECHANGE, ENODEV);
1039 if (vga_get_info(adp, mode, &info))
1042 lwkt_gettoken(&tty_token);
1045 kprintf("vga_set_mode(): setting mode %d\n", mode);
1048 params.sig = V_STATE_SIG;
1049 bcopy(get_mode_param(mode), params.regs, sizeof(params.regs));
1053 case M_VGA_C90x60: case M_VGA_M90x60:
1054 set_width90(¶ms);
1057 case M_VGA_C80x60: case M_VGA_M80x60:
1058 params.regs[2] = 0x08;
1059 params.regs[19] = 0x47;
1063 case M_VGA_C90x30: case M_VGA_M90x30:
1064 set_width90(¶ms);
1067 case M_VGA_C80x30: case M_VGA_M80x30:
1068 params.regs[19] = 0x4f;
1070 params.regs[9] |= 0xc0;
1071 params.regs[16] = 0x08;
1072 params.regs[17] = 0x3e;
1073 params.regs[26] = 0xea;
1074 params.regs[28] = 0xdf;
1075 params.regs[31] = 0xe7;
1076 params.regs[32] = 0x04;
1080 case M_VGA_C90x43: case M_VGA_M90x43:
1081 set_width90(¶ms);
1084 case M_ENH_C80x43: case M_ENH_B80x43:
1085 params.regs[28] = 87;
1089 case M_VGA_C90x50: case M_VGA_M90x50:
1090 set_width90(¶ms);
1093 case M_VGA_C80x50: case M_VGA_M80x50:
1096 params.regs[19] = 7;
1100 case M_VGA_C90x25: case M_VGA_M90x25:
1101 set_width90(¶ms);
1104 case M_VGA_C40x25: case M_VGA_C80x25:
1106 case M_B40x25: case M_C40x25:
1107 case M_B80x25: case M_C80x25:
1108 case M_ENH_B40x25: case M_ENH_C40x25:
1109 case M_ENH_B80x25: case M_ENH_C80x25:
1110 case M_EGAMONO80x25:
1113 vga_load_state(adp, ¶ms);
1117 /* "unchain" the VGA mode */
1118 params.regs[5-1+0x04] &= 0xf7;
1119 params.regs[5-1+0x04] |= 0x04;
1120 /* turn off doubleword mode */
1121 params.regs[10+0x14] &= 0xbf;
1122 /* turn off word addressing */
1123 params.regs[10+0x17] |= 0x40;
1124 /* set logical screen width */
1125 params.regs[10+0x13] = 80;
1127 params.regs[10+0x11] = 0x2c;
1128 params.regs[10+0x06] = 0x0d;
1129 params.regs[10+0x07] = 0x3e;
1130 params.regs[10+0x10] = 0xea;
1131 params.regs[10+0x11] = 0xac;
1132 params.regs[10+0x12] = 0xdf;
1133 params.regs[10+0x15] = 0xe7;
1134 params.regs[10+0x16] = 0x06;
1135 /* set vertical sync polarity to reflect aspect ratio */
1136 params.regs[9] = 0xe3;
1139 case M_BG320: case M_CG320: case M_BG640:
1140 case M_CG320_D: case M_CG640_E:
1141 case M_CG640x350: case M_ENH_CG640:
1142 case M_BG640x480: case M_CG640x480: case M_VGA_CG320:
1145 vga_load_state(adp, ¶ms);
1149 lwkt_reltoken(&tty_token);
1153 adp->va_mode = mode;
1154 info.vi_flags &= ~V_INFO_LINEAR; /* XXX */
1155 update_adapter_info(adp, &info);
1157 /* move hardware cursor out of the way */
1158 (*vidsw[adp->va_index]->set_hw_cursor)(adp, -1, -1);
1160 lwkt_reltoken(&tty_token);
1162 #else /* VGA_NO_MODE_CHANGE */
1163 lwkt_reltoken(&tty_token);
1165 #endif /* VGA_NO_MODE_CHANGE */
1168 #ifndef VGA_NO_FONT_LOADING
1171 set_font_mode(video_adapter_t *adp, u_char *buf)
1175 /* save register values */
1176 outb(TSIDX, 0x02); buf[0] = inb(TSREG);
1177 outb(TSIDX, 0x04); buf[1] = inb(TSREG);
1178 outb(GDCIDX, 0x04); buf[2] = inb(GDCREG);
1179 outb(GDCIDX, 0x05); buf[3] = inb(GDCREG);
1180 outb(GDCIDX, 0x06); buf[4] = inb(GDCREG);
1182 outb(ATC, 0x10); buf[5] = inb(ATC + 1);
1184 /* setup vga for loading fonts */
1185 inb(CRTC + 6); /* reset flip-flop */
1186 outb(ATC, 0x10); outb(ATC, buf[5] & ~0x01);
1187 inb(CRTC + 6); /* reset flip-flop */
1188 outb(ATC, 0x20); /* enable palette */
1190 #ifdef VGA_ALT_SEQACCESS
1191 outw(TSIDX, 0x0100);
1193 outw(TSIDX, 0x0402);
1194 outw(TSIDX, 0x0704);
1195 #ifdef VGA_ALT_SEQACCESS
1196 outw(TSIDX, 0x0300);
1198 outw(GDCIDX, 0x0204);
1199 outw(GDCIDX, 0x0005);
1200 outw(GDCIDX, 0x0406); /* addr = a0000, 64kb */
1206 set_normal_mode(video_adapter_t *adp, u_char *buf)
1210 /* setup vga for normal operation mode again */
1211 inb(CRTC + 6); /* reset flip-flop */
1212 outb(ATC, 0x10); outb(ATC, buf[5]);
1213 inb(CRTC + 6); /* reset flip-flop */
1214 outb(ATC, 0x20); /* enable palette */
1216 #ifdef VGA_ALT_SEQACCESS
1217 outw(TSIDX, 0x0100);
1219 outw(TSIDX, 0x0002 | (buf[0] << 8));
1220 outw(TSIDX, 0x0004 | (buf[1] << 8));
1221 #ifdef VGA_ALT_SEQACCESS
1222 outw(TSIDX, 0x0300);
1224 outw(GDCIDX, 0x0004 | (buf[2] << 8));
1225 outw(GDCIDX, 0x0005 | (buf[3] << 8));
1226 outw(GDCIDX, 0x0006 | (((buf[4] & 0x03) | 0x0c)<<8));
1231 #endif /* VGA_NO_FONT_LOADING */
1235 * Read the font data in the requested font page from the video adapter.
1238 vga_save_font(video_adapter_t *adp, int page, int fontsize, u_char *data,
1241 #ifndef VGA_NO_FONT_LOADING
1242 u_char buf[PARAM_BUFSIZE];
1243 vm_offset_t segment;
1245 #ifdef VGA_ALT_SEQACCESS
1249 prologue(adp, V_ADP_FONT, ENODEV);
1251 if (fontsize < 14) {
1254 } else if (fontsize >= 32) {
1256 } else if (fontsize >= 16) {
1264 if (page < 0 || page >= 8)
1266 segment = FONT_BUF + 0x4000*page;
1270 #ifdef VGA_ALT_SEQACCESS
1272 outb(TSIDX, 0x00); outb(TSREG, 0x01);
1273 outb(TSIDX, 0x01); val = inb(TSREG); /* disable screen */
1274 outb(TSIDX, 0x01); outb(TSREG, val | 0x20);
1275 outb(TSIDX, 0x00); outb(TSREG, 0x03);
1279 set_font_mode(adp, buf);
1280 if (fontsize == 32) {
1281 bcopy_fromio((uintptr_t)segment + ch*32, data, fontsize*count);
1283 for (c = ch; count > 0; ++c, --count) {
1284 bcopy_fromio((uintptr_t)segment + c*32, data, fontsize);
1288 set_normal_mode(adp, buf);
1290 #ifdef VGA_ALT_SEQACCESS
1292 outb(TSIDX, 0x00); outb(TSREG, 0x01);
1293 outb(TSIDX, 0x01); outb(TSREG, val & 0xdf); /* enable screen */
1294 outb(TSIDX, 0x00); outb(TSREG, 0x03);
1299 #else /* VGA_NO_FONT_LOADING */
1301 #endif /* VGA_NO_FONT_LOADING */
1306 * Set the font data in the requested font page.
1307 * NOTE: it appears that some recent video adapters do not support
1308 * the font page other than 0... XXX
1311 vga_load_font(video_adapter_t *adp, int page, int fontsize, u_char *data,
1314 #ifndef VGA_NO_FONT_LOADING
1315 u_char buf[PARAM_BUFSIZE];
1316 vm_offset_t segment;
1318 #ifdef VGA_ALT_SEQACCESS
1322 prologue(adp, V_ADP_FONT, ENODEV);
1324 if (fontsize < 14) {
1327 } else if (fontsize >= 32) {
1329 } else if (fontsize >= 16) {
1337 if (page < 0 || page >= 8)
1339 segment = FONT_BUF + 0x4000*page;
1343 #ifdef VGA_ALT_SEQACCESS
1345 outb(TSIDX, 0x00); outb(TSREG, 0x01);
1346 outb(TSIDX, 0x01); val = inb(TSREG); /* disable screen */
1347 outb(TSIDX, 0x01); outb(TSREG, val | 0x20);
1348 outb(TSIDX, 0x00); outb(TSREG, 0x03);
1352 set_font_mode(adp, buf);
1353 if (fontsize == 32) {
1354 bcopy_toio(data, (uintptr_t)segment + ch*32, fontsize*count);
1356 for (c = ch; count > 0; ++c, --count) {
1357 bcopy_toio(data, (uintptr_t)segment + c*32, fontsize);
1361 set_normal_mode(adp, buf);
1363 #ifdef VGA_ALT_SEQACCESS
1365 outb(TSIDX, 0x00); outb(TSREG, 0x01);
1366 outb(TSIDX, 0x01); outb(TSREG, val & 0xdf); /* enable screen */
1367 outb(TSIDX, 0x00); outb(TSREG, 0x03);
1372 #else /* VGA_NO_FONT_LOADING */
1374 #endif /* VGA_NO_FONT_LOADING */
1379 * Activate the requested font page.
1380 * NOTE: it appears that some recent video adapters do not support
1381 * the font page other than 0... XXX
1384 vga_show_font(video_adapter_t *adp, int page)
1386 #ifndef VGA_NO_FONT_LOADING
1387 static u_char cg[] = { 0x00, 0x05, 0x0a, 0x0f, 0x30, 0x35, 0x3a, 0x3f };
1389 prologue(adp, V_ADP_FONT, ENODEV);
1390 if (page < 0 || page >= 8)
1394 outb(TSIDX, 0x03); outb(TSREG, cg[page]);
1398 #else /* VGA_NO_FONT_LOADING */
1400 #endif /* VGA_NO_FONT_LOADING */
1405 * Read DAC values. The values have expressed in 8 bits.
1410 vga_save_palette(video_adapter_t *adp, u_char *palette)
1414 prologue(adp, V_ADP_PALETTE, ENODEV);
1417 * We store 8 bit values in the palette buffer, while the standard
1418 * VGA has 6 bit DAC .
1420 outb(PALRADR, 0x00);
1421 for (i = 0; i < 256*3; ++i)
1422 palette[i] = inb(PALDATA) << 2;
1423 inb(CRTC + 6); /* reset flip/flop */
1428 vga_save_palette2(video_adapter_t *adp, int base, int count,
1429 u_char *r, u_char *g, u_char *b)
1433 prologue(adp, V_ADP_PALETTE, ENODEV);
1435 outb(PALRADR, base);
1436 for (i = 0; i < count; ++i) {
1437 r[i] = inb(PALDATA) << 2;
1438 g[i] = inb(PALDATA) << 2;
1439 b[i] = inb(PALDATA) << 2;
1441 inb(CRTC + 6); /* reset flip/flop */
1452 vga_load_palette(video_adapter_t *adp, const u_char *palette)
1456 prologue(adp, V_ADP_PALETTE, ENODEV);
1458 outb(PIXMASK, 0xff); /* no pixelmask */
1459 outb(PALWADR, 0x00);
1460 for (i = 0; i < 256*3; ++i)
1461 outb(PALDATA, palette[i] >> 2);
1462 inb(CRTC + 6); /* reset flip/flop */
1463 outb(ATC, 0x20); /* enable palette */
1468 vga_load_palette2(video_adapter_t *adp, int base, int count,
1469 u_char *r, u_char *g, u_char *b)
1473 prologue(adp, V_ADP_PALETTE, ENODEV);
1475 outb(PIXMASK, 0xff); /* no pixelmask */
1476 outb(PALWADR, base);
1477 for (i = 0; i < count; ++i) {
1478 outb(PALDATA, r[i] >> 2);
1479 outb(PALDATA, g[i] >> 2);
1480 outb(PALDATA, b[i] >> 2);
1482 inb(CRTC + 6); /* reset flip/flop */
1483 outb(ATC, 0x20); /* enable palette */
1489 * Change the border color.
1492 vga_set_border(video_adapter_t *adp, int color)
1494 prologue(adp, V_ADP_BORDER, ENODEV);
1496 inb(CRTC + 6); /* reset flip-flop */
1497 outb(ATC, 0x31); outb(ATC, color & 0xff);
1504 * Read video register values.
1505 * NOTE: this function only reads the standard VGA registers.
1506 * any extra/extended registers of SVGA adapters are not saved.
1509 vga_save_state(video_adapter_t *adp, void *p, size_t size)
1517 /* return the required buffer size */
1518 prologue(adp, V_ADP_STATESAVE, 0);
1519 return sizeof(adp_state_t);
1521 prologue(adp, V_ADP_STATESAVE, ENODEV);
1522 if (size < sizeof(adp_state_t))
1525 ((adp_state_t *)p)->sig = V_STATE_SIG;
1526 buf = ((adp_state_t *)p)->regs;
1527 bzero(buf, V_MODE_PARAM_SIZE);
1532 outb(TSIDX, 0x00); outb(TSREG, 0x01); /* stop sequencer */
1533 for (i = 0, j = 5; i < 4; i++) {
1535 buf[j++] = inb(TSREG);
1537 buf[9] = inb(MISC + 10); /* dot-clock */
1538 outb(TSIDX, 0x00); outb(TSREG, 0x03); /* start sequencer */
1540 for (i = 0, j = 10; i < 25; i++) { /* crtc */
1542 buf[j++] = inb(crtc_addr + 1);
1544 for (i = 0, j = 35; i < 20; i++) { /* attribute ctrl */
1545 inb(crtc_addr + 6); /* reset flip-flop */
1547 buf[j++] = inb(ATC + 1);
1549 for (i = 0, j = 55; i < 9; i++) { /* graph data ctrl */
1551 buf[j++] = inb(GDCREG);
1553 inb(crtc_addr + 6); /* reset flip-flop */
1554 outb(ATC, 0x20); /* enable palette */
1559 if (vga_get_info(adp, adp->va_mode, &info) == 0) {
1560 if (info.vi_flags & V_INFO_GRAPHICS) {
1561 buf[0] = info.vi_width/info.vi_cwidth; /* COLS */
1562 buf[1] = info.vi_height/info.vi_cheight - 1; /* ROWS */
1564 buf[0] = info.vi_width; /* COLS */
1565 buf[1] = info.vi_height - 1; /* ROWS */
1567 buf[2] = info.vi_cheight; /* POINTS */
1569 /* XXX: shouldn't be happening... */
1570 kprintf("vga%d: %s: failed to obtain mode info. (vga_save_state())\n",
1571 adp->va_unit, adp->va_name);
1574 buf[0] = readb(BIOS_PADDRTOVADDR(0x44a)); /* COLS */
1575 buf[1] = readb(BIOS_PADDRTOVADDR(0x484)); /* ROWS */
1576 buf[2] = readb(BIOS_PADDRTOVADDR(0x485)); /* POINTS */
1577 buf[3] = readb(BIOS_PADDRTOVADDR(0x44c));
1578 buf[4] = readb(BIOS_PADDRTOVADDR(0x44d));
1586 * Set video registers at once.
1587 * NOTE: this function only updates the standard VGA registers.
1588 * any extra/extended registers of SVGA adapters are not changed.
1591 vga_load_state(video_adapter_t *adp, void *p)
1597 prologue(adp, V_ADP_STATELOAD, ENODEV);
1598 if (((adp_state_t *)p)->sig != V_STATE_SIG)
1601 buf = ((adp_state_t *)p)->regs;
1605 hexdump(buf, V_MODE_PARAM_SIZE, NULL, HD_OMIT_CHARS | HD_OMIT_COUNT);
1610 outb(TSIDX, 0x00); outb(TSREG, 0x01); /* stop sequencer */
1611 for (i = 0; i < 4; ++i) { /* program sequencer */
1613 outb(TSREG, buf[i + 5]);
1615 outb(MISC, buf[9]); /* set dot-clock */
1616 outb(TSIDX, 0x00); outb(TSREG, 0x03); /* start sequencer */
1617 outb(crtc_addr, 0x11);
1618 outb(crtc_addr + 1, inb(crtc_addr + 1) & 0x7F);
1619 for (i = 0; i < 25; ++i) { /* program crtc */
1621 outb(crtc_addr + 1, buf[i + 10]);
1623 inb(crtc_addr+6); /* reset flip-flop */
1624 for (i = 0; i < 20; ++i) { /* program attribute ctrl */
1626 outb(ATC, buf[i + 35]);
1628 for (i = 0; i < 9; ++i) { /* program graph data ctrl */
1630 outb(GDCREG, buf[i + 55]);
1632 inb(crtc_addr + 6); /* reset flip-flop */
1633 outb(ATC, 0x20); /* enable palette */
1635 #if 0 /* XXX a temporary workaround for kernel panic */
1637 if (adp->va_unit == V_ADP_PRIMARY) {
1638 writeb(BIOS_PADDRTOVADDR(0x44a), buf[0]); /* COLS */
1639 writeb(BIOS_PADDRTOVADDR(0x484), buf[1] + rows_offset - 1); /* ROWS */
1640 writeb(BIOS_PADDRTOVADDR(0x485), buf[2]); /* POINTS */
1642 writeb(BIOS_PADDRTOVADDR(0x44c), buf[3]);
1643 writeb(BIOS_PADDRTOVADDR(0x44d), buf[4]);
1646 #endif /* VGA_NO_BIOS */
1655 * Change the origin (window mapping) of the banked frame buffer.
1658 vga_set_origin(video_adapter_t *adp, off_t offset)
1661 * The standard video modes do not require window mapping;
1662 * always return error.
1669 * Read the position of the hardware text cursor.
1672 vga_read_hw_cursor(video_adapter_t *adp, int *col, int *row)
1679 if (adp->va_info.vi_flags & V_INFO_GRAPHICS)
1684 off = inb(CRTC + 1);
1686 off = (off << 8) | inb(CRTC + 1);
1689 *row = off / adp->va_info.vi_width;
1690 *col = off % adp->va_info.vi_width;
1697 * Move the hardware text cursor. If col and row are both -1,
1698 * the cursor won't be shown.
1701 vga_set_hw_cursor(video_adapter_t *adp, int col, int row)
1708 if ((col == -1) && (row == -1)) {
1711 if (adp->va_info.vi_flags & V_INFO_GRAPHICS)
1713 off = row*adp->va_info.vi_width + col;
1718 outb(CRTC + 1, off >> 8);
1720 outb(CRTC + 1, off & 0x00ff);
1727 * set_hw_cursor_shape():
1728 * Change the shape of the hardware text cursor. If the height is
1729 * zero or negative, the cursor won't be shown.
1732 vga_set_hw_cursor_shape(video_adapter_t *adp, int base, int height,
1733 int celsize, int blink)
1740 /* make the cursor invisible */
1747 outb(CRTC + 1, celsize - base - height);
1749 outb(CRTC + 1, celsize - base - 1);
1758 * Put the display in power save/power off mode.
1761 vga_blank_display(video_adapter_t *adp, int mode)
1767 case V_DISPLAY_SUSPEND:
1768 case V_DISPLAY_STAND_BY:
1772 outb(TSREG, val | 0x20);
1774 val = inb(CRTC + 1);
1775 outb(CRTC + 1, val & ~0x80);
1781 outb(TSREG, val | 0x20);
1787 outb(TSREG, val & 0xDF);
1789 val = inb(CRTC + 1);
1790 outb(CRTC + 1, val | 0x80);
1800 * Mmap frame buffer.
1803 vga_mmap_buf(video_adapter_t *adp, vm_offset_t offset, int prot)
1805 if (adp->va_info.vi_flags & V_INFO_LINEAR)
1809 kprintf("vga_mmap_buf(): window:0x%x, offset:%p\n",
1810 adp->va_info.vi_window, (void *)offset);
1813 /* XXX: is this correct? */
1814 if (offset > adp->va_window_size - PAGE_SIZE)
1817 #if defined(__i386__)
1818 return i386_btop(adp->va_info.vi_window + offset);
1819 #elif defined(__x86_64__)
1820 return x86_64_btop(adp->va_info.vi_window + offset);
1822 #error "vga_mmap_buf needs to return something"
1826 #ifndef VGA_NO_MODE_CHANGE
1829 planar_fill(video_adapter_t *adp, int val)
1832 int at; /* position in the frame buffer */
1835 lwkt_gettoken(&tty_token);
1836 outw(GDCIDX, 0x0005); /* read mode 0, write mode 0 */
1837 outw(GDCIDX, 0x0003); /* data rotate/function select */
1838 outw(GDCIDX, 0x0f01); /* set/reset enable */
1839 outw(GDCIDX, 0xff08); /* bit mask */
1840 outw(GDCIDX, (val << 8) | 0x00); /* set/reset */
1842 length = adp->va_line_width*adp->va_info.vi_height;
1843 while (length > 0) {
1844 l = imin(length, adp->va_window_size);
1845 (*vidsw[adp->va_index]->set_win_org)(adp, at);
1846 bzero_io(adp->va_window, l);
1850 outw(GDCIDX, 0x0000); /* set/reset */
1851 outw(GDCIDX, 0x0001); /* set/reset enable */
1852 lwkt_reltoken(&tty_token);
1856 packed_fill(video_adapter_t *adp, int val)
1859 int at; /* position in the frame buffer */
1862 lwkt_gettoken(&tty_token);
1864 length = adp->va_line_width*adp->va_info.vi_height;
1865 while (length > 0) {
1866 l = imin(length, adp->va_window_size);
1867 (*vidsw[adp->va_index]->set_win_org)(adp, at);
1868 fill_io(val, adp->va_window, l);
1872 lwkt_reltoken(&tty_token);
1876 direct_fill(video_adapter_t *adp, int val)
1879 int at; /* position in the frame buffer */
1882 lwkt_gettoken(&tty_token);
1884 length = adp->va_line_width*adp->va_info.vi_height;
1885 while (length > 0) {
1886 l = imin(length, adp->va_window_size);
1887 (*vidsw[adp->va_index]->set_win_org)(adp, at);
1888 switch (adp->va_info.vi_pixel_size) {
1889 case sizeof(u_int16_t):
1890 fillw_io(val, adp->va_window, l/sizeof(u_int16_t));
1895 case sizeof(u_int32_t):
1896 filll_io(val, adp->va_window, l/sizeof(u_int32_t));
1902 lwkt_reltoken(&tty_token);
1906 vga_clear(video_adapter_t *adp)
1908 switch (adp->va_info.vi_mem_model) {
1909 case V_INFO_MM_TEXT:
1910 /* do nothing? XXX */
1912 case V_INFO_MM_PLANAR:
1913 planar_fill(adp, 0);
1915 case V_INFO_MM_PACKED:
1916 packed_fill(adp, 0);
1918 case V_INFO_MM_DIRECT:
1919 direct_fill(adp, 0);
1927 planar_fill_rect(video_adapter_t *adp, int val, int x, int y, int cx, int cy)
1932 int offset; /* offset within window */
1936 lwkt_gettoken(&tty_token);
1937 outw(GDCIDX, 0x0005); /* read mode 0, write mode 0 */
1938 outw(GDCIDX, 0x0003); /* data rotate/function select */
1939 outw(GDCIDX, 0x0f01); /* set/reset enable */
1940 outw(GDCIDX, 0xff08); /* bit mask */
1941 outw(GDCIDX, (val << 8) | 0x00); /* set/reset */
1943 banksize = adp->va_window_size;
1946 pos = adp->va_line_width*y + x/8;
1947 if (bank != pos/banksize) {
1948 (*vidsw[adp->va_index]->set_win_org)(adp, pos);
1949 bank = pos/banksize;
1951 offset = pos%banksize;
1952 bx = (x + cx)/8 - x/8;
1954 outw(GDCIDX, ((0xff00 >> (x % 8)) & 0xff00) | 0x08);
1955 writeb(adp->va_window + offset, 0);
1958 if (offset >= banksize) {
1960 ++bank; /* next bank */
1961 (*vidsw[adp->va_index]->set_win_org)(adp, bank*banksize);
1963 outw(GDCIDX, 0xff08); /* bit mask */
1966 l = imin(bx, banksize);
1967 bzero_io(adp->va_window + offset, l);
1970 if (offset >= banksize) {
1972 ++bank; /* next bank */
1973 (*vidsw[adp->va_index]->set_win_org)(adp, bank*banksize);
1977 outw(GDCIDX, (~(0xff00 >> ((x + cx) % 8)) & 0xff00) | 0x08);
1978 writeb(adp->va_window + offset, 0);
1980 if (offset >= banksize) {
1982 ++bank; /* next bank */
1983 (*vidsw[adp->va_index]->set_win_org)(adp, bank*banksize);
1985 outw(GDCIDX, 0xff08); /* bit mask */
1991 outw(GDCIDX, 0xff08); /* bit mask */
1992 outw(GDCIDX, 0x0000); /* set/reset */
1993 outw(GDCIDX, 0x0001); /* set/reset enable */
1994 lwkt_reltoken(&tty_token);
1998 packed_fill_rect(video_adapter_t *adp, int val, int x, int y, int cx, int cy)
2003 int offset; /* offset within window */
2006 lwkt_gettoken(&tty_token);
2007 banksize = adp->va_window_size;
2009 cx *= adp->va_info.vi_pixel_size;
2011 pos = adp->va_line_width*y + x*adp->va_info.vi_pixel_size;
2012 if (bank != pos/banksize) {
2013 (*vidsw[adp->va_index]->set_win_org)(adp, pos);
2014 bank = pos/banksize;
2016 offset = pos%banksize;
2017 end = imin(offset + cx, banksize);
2018 fill_io(val, adp->va_window + offset,
2019 (end - offset)/adp->va_info.vi_pixel_size);
2020 /* the line may cross the window boundary */
2021 if (offset + cx > banksize) {
2022 ++bank; /* next bank */
2023 (*vidsw[adp->va_index]->set_win_org)(adp, bank*banksize);
2024 end = offset + cx - banksize;
2025 fill_io(val, adp->va_window, end/adp->va_info.vi_pixel_size);
2030 lwkt_reltoken(&tty_token);
2034 direct_fill_rect16(video_adapter_t *adp, int val, int x, int y, int cx, int cy)
2039 int offset; /* offset within window */
2042 lwkt_gettoken(&tty_token);
2044 * XXX: the function assumes that banksize is a muliple of
2045 * sizeof(u_int16_t).
2047 banksize = adp->va_window_size;
2049 cx *= sizeof(u_int16_t);
2051 pos = adp->va_line_width*y + x*sizeof(u_int16_t);
2052 if (bank != pos/banksize) {
2053 (*vidsw[adp->va_index]->set_win_org)(adp, pos);
2054 bank = pos/banksize;
2056 offset = pos%banksize;
2057 end = imin(offset + cx, banksize);
2058 fillw_io(val, adp->va_window + offset,
2059 (end - offset)/sizeof(u_int16_t));
2060 /* the line may cross the window boundary */
2061 if (offset + cx > banksize) {
2062 ++bank; /* next bank */
2063 (*vidsw[adp->va_index]->set_win_org)(adp, bank*banksize);
2064 end = offset + cx - banksize;
2065 fillw_io(val, adp->va_window, end/sizeof(u_int16_t));
2070 lwkt_reltoken(&tty_token);
2074 direct_fill_rect24(video_adapter_t *adp, int val, int x, int y, int cx, int cy)
2079 int offset; /* offset within window */
2085 lwkt_gettoken(&tty_token);
2086 b[0] = val & 0x0000ff;
2087 b[1] = (val >> 8) & 0x0000ff;
2088 b[2] = (val >> 16) & 0x0000ff;
2089 banksize = adp->va_window_size;
2093 pos = adp->va_line_width*y + x*3;
2094 if (bank != pos/banksize) {
2095 (*vidsw[adp->va_index]->set_win_org)(adp, pos);
2096 bank = pos/banksize;
2098 offset = pos%banksize;
2099 end = imin(offset + cx, banksize);
2100 for (i = 0, j = offset; j < end; i = (++i)%3, ++j) {
2101 writeb(adp->va_window + j, b[i]);
2103 /* the line may cross the window boundary */
2104 if (offset + cx >= banksize) {
2105 ++bank; /* next bank */
2106 (*vidsw[adp->va_index]->set_win_org)(adp, bank*banksize);
2108 end = offset + cx - banksize;
2109 for (; j < end; i = (++i)%3, ++j) {
2110 writeb(adp->va_window + j, b[i]);
2116 lwkt_reltoken(&tty_token);
2120 direct_fill_rect32(video_adapter_t *adp, int val, int x, int y, int cx, int cy)
2125 int offset; /* offset within window */
2128 lwkt_gettoken(&tty_token);
2130 * XXX: the function assumes that banksize is a muliple of
2131 * sizeof(u_int32_t).
2133 banksize = adp->va_window_size;
2135 cx *= sizeof(u_int32_t);
2137 pos = adp->va_line_width*y + x*sizeof(u_int32_t);
2138 if (bank != pos/banksize) {
2139 (*vidsw[adp->va_index]->set_win_org)(adp, pos);
2140 bank = pos/banksize;
2142 offset = pos%banksize;
2143 end = imin(offset + cx, banksize);
2144 filll_io(val, adp->va_window + offset,
2145 (end - offset)/sizeof(u_int32_t));
2146 /* the line may cross the window boundary */
2147 if (offset + cx > banksize) {
2148 ++bank; /* next bank */
2149 (*vidsw[adp->va_index]->set_win_org)(adp, bank*banksize);
2150 end = offset + cx - banksize;
2151 filll_io(val, adp->va_window, end/sizeof(u_int32_t));
2156 lwkt_reltoken(&tty_token);
2160 vga_fill_rect(video_adapter_t *adp, int val, int x, int y, int cx, int cy)
2162 switch (adp->va_info.vi_mem_model) {
2163 case V_INFO_MM_TEXT:
2164 /* do nothing? XXX */
2166 case V_INFO_MM_PLANAR:
2167 planar_fill_rect(adp, val, x, y, cx, cy);
2169 case V_INFO_MM_PACKED:
2170 packed_fill_rect(adp, val, x, y, cx, cy);
2172 case V_INFO_MM_DIRECT:
2173 switch (adp->va_info.vi_pixel_size) {
2174 case sizeof(u_int16_t):
2175 direct_fill_rect16(adp, val, x, y, cx, cy);
2178 direct_fill_rect24(adp, val, x, y, cx, cy);
2180 case sizeof(u_int32_t):
2181 direct_fill_rect32(adp, val, x, y, cx, cy);
2190 vga_fill_rect(video_adapter_t *adp, int val, int x, int y, int cx, int cy)
2197 vga_bitblt(video_adapter_t *adp,...)
2203 #endif /* !VGA_NO_MODE_CHANGE */
2206 get_palette(video_adapter_t *adp, int base, int count,
2207 u_char *red, u_char *green, u_char *blue, u_char *trans)
2213 if (count < 0 || base < 0 || count > 256 || base > 256 ||
2217 r = kmalloc(count*3, M_DEVBUF, M_WAITOK);
2220 if (vga_save_palette2(adp, base, count, r, g, b)) {
2224 copyout(r, red, count);
2225 copyout(g, green, count);
2226 copyout(b, blue, count);
2227 if (trans != NULL) {
2229 copyout(r, trans, count);
2237 set_palette(video_adapter_t *adp, int base, int count,
2238 u_char *red, u_char *green, u_char *blue, u_char *trans)
2245 if (count < 0 || base < 0 || count > 256 || base > 256 ||
2249 r = kmalloc(count*3, M_DEVBUF, M_WAITOK);
2252 err = copyin(red, r, count);
2254 err = copyin(green, g, count);
2256 err = copyin(blue, b, count);
2258 err = vga_load_palette2(adp, base, count, r, g, b);
2261 return (err ? ENODEV : 0);
2265 vga_dev_ioctl(video_adapter_t *adp, u_long cmd, caddr_t arg)
2268 case FBIO_GETWINORG: /* get frame buffer window origin */
2272 case FBIO_SETWINORG: /* set frame buffer window origin */
2275 case FBIO_SETDISPSTART: /* set display start address */
2276 return (set_display_start(adp,
2277 ((video_display_start_t *)arg)->x,
2278 ((video_display_start_t *)arg)->y)
2281 case FBIO_SETLINEWIDTH: /* set scan line length in pixel */
2282 return (set_line_length(adp, *(u_int *)arg) ? ENODEV : 0);
2284 case FBIO_GETPALETTE: /* get color palette */
2285 return get_palette(adp, ((video_color_palette_t *)arg)->index,
2286 ((video_color_palette_t *)arg)->count,
2287 ((video_color_palette_t *)arg)->red,
2288 ((video_color_palette_t *)arg)->green,
2289 ((video_color_palette_t *)arg)->blue,
2290 ((video_color_palette_t *)arg)->transparent);
2292 case FBIO_SETPALETTE: /* set color palette */
2293 return set_palette(adp, ((video_color_palette_t *)arg)->index,
2294 ((video_color_palette_t *)arg)->count,
2295 ((video_color_palette_t *)arg)->red,
2296 ((video_color_palette_t *)arg)->green,
2297 ((video_color_palette_t *)arg)->blue,
2298 ((video_color_palette_t *)arg)->transparent);
2300 case FBIOGTYPE: /* get frame buffer type info. */
2301 ((struct fbtype *)arg)->fb_type = fb_type(adp->va_type);
2302 ((struct fbtype *)arg)->fb_height = adp->va_info.vi_height;
2303 ((struct fbtype *)arg)->fb_width = adp->va_info.vi_width;
2304 ((struct fbtype *)arg)->fb_depth = adp->va_info.vi_depth;
2305 if ((adp->va_info.vi_depth <= 1) || (adp->va_info.vi_depth > 8))
2306 ((struct fbtype *)arg)->fb_cmsize = 0;
2308 ((struct fbtype *)arg)->fb_cmsize = 1 << adp->va_info.vi_depth;
2309 ((struct fbtype *)arg)->fb_size = adp->va_buffer_size;
2312 case FBIOGETCMAP: /* get color palette */
2313 return get_palette(adp, ((struct fbcmap *)arg)->index,
2314 ((struct fbcmap *)arg)->count,
2315 ((struct fbcmap *)arg)->red,
2316 ((struct fbcmap *)arg)->green,
2317 ((struct fbcmap *)arg)->blue, NULL);
2319 case FBIOPUTCMAP: /* set color palette */
2320 return set_palette(adp, ((struct fbcmap *)arg)->index,
2321 ((struct fbcmap *)arg)->count,
2322 ((struct fbcmap *)arg)->red,
2323 ((struct fbcmap *)arg)->green,
2324 ((struct fbcmap *)arg)->blue, NULL);
2327 return fb_commonioctl(adp, cmd, arg);
2333 * Print some information about the video adapter and video modes,
2334 * with requested level of details.
2337 vga_diag(video_adapter_t *adp, int level)
2350 kprintf("vga: DCC code:0x%02x\n",
2351 readb(BIOS_PADDRTOVADDR(0x488)));
2352 kprintf("vga: CRTC:0x%x, video option:0x%02x, ",
2353 readw(BIOS_PADDRTOVADDR(0x463)),
2354 readb(BIOS_PADDRTOVADDR(0x487)));
2355 kprintf("rows:%d, cols:%d, font height:%d\n",
2356 readb(BIOS_PADDRTOVADDR(0x44a)),
2357 readb(BIOS_PADDRTOVADDR(0x484)) + 1,
2358 readb(BIOS_PADDRTOVADDR(0x485)));
2359 #endif /* VGA_NO_BIOS */
2360 #if !defined(VGA_NO_BIOS) && !defined(VGA_NO_MODE_CHANGE)
2361 kprintf("vga: param table:%p\n", video_mode_ptr);
2362 kprintf("vga: rows_offset:%d\n", rows_offset);
2364 #endif /* FB_DEBUG > 1 */
2366 fb_dump_adp_info(VGA_DRIVER_NAME, adp, level);
2369 if (adp->va_flags & V_ADP_MODECHANGE) {
2370 for (i = 0; bios_vmode[i].vi_mode != EOT; ++i) {
2371 if (bios_vmode[i].vi_mode == NA)
2373 if (get_mode_param(bios_vmode[i].vi_mode) == NULL)
2375 fb_dump_mode_info(VGA_DRIVER_NAME, adp, &bios_vmode[i], level);
2378 vga_get_info(adp, adp->va_initial_mode, &info); /* shouldn't fail */
2379 fb_dump_mode_info(VGA_DRIVER_NAME, adp, &info, level);
2381 #endif /* FB_DEBUG > 1 */
2383 #if !defined(VGA_NO_BIOS) && !defined(VGA_NO_MODE_CHANGE)
2384 if (video_mode_ptr == NULL)
2385 kprintf("vga%d: %s: WARNING: video mode switching is not "
2386 "fully supported on this adapter\n",
2387 adp->va_unit, adp->va_name);
2392 kprintf("VGA parameters upon power-up\n");
2393 hexdump(adpstate.regs, sizeof(adpstate.regs), NULL,
2394 HD_OMIT_CHARS | HD_OMIT_COUNT);
2396 mp = get_mode_param(adp->va_initial_mode);
2397 if (mp == NULL) /* this shouldn't be happening */
2399 kprintf("VGA parameters in BIOS for mode %d\n", adp->va_initial_mode);
2400 hexdump(adpstate2.regs, sizeof(adpstate2.regs), NULL,
2401 HD_OMIT_CHARS | HD_OMIT_COUNT);
2402 kprintf("VGA parameters to be used for mode %d\n", adp->va_initial_mode);
2403 hexdump(mp, V_MODE_PARAM_SIZE, NULL, HD_OMIT_CHARS | HD_OMIT_COUNT);