2 * SPDX-License-Identifier: BSD-3-Clause
4 * Copyright (c) 1999 Kazutaka YOKOTA <yokota@zodiac.mech.utsunomiya-u.ac.jp>
5 * Copyright (c) 1992-1998 Søren Schmidt
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer as
13 * the first lines of this file unmodified.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 * 3. The name of the author may not be used to endorse or promote products
18 * derived from this software without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
21 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
22 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
23 * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
24 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
25 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
29 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 #include <sys/cdefs.h>
34 __FBSDID("$FreeBSD$");
41 #include "opt_syscons.h" /* should be removed in the future, XXX */
43 #include <sys/param.h>
44 #include <sys/systm.h>
45 #include <sys/kernel.h>
47 #include <sys/fcntl.h>
48 #include <sys/malloc.h>
52 #include <vm/vm_param.h>
55 #include <machine/md_var.h>
56 #if defined(__i386__) || defined(__amd64__)
57 #include <machine/pc/bios.h>
59 #include <machine/bus.h>
61 #include <dev/fb/fbreg.h>
62 #include <dev/fb/vgareg.h>
64 #include <isa/isareg.h>
70 /* XXX machine/pc/bios.h has got too much i386-specific stuff in it */
71 #ifndef BIOS_PADDRTOVADDR
72 #define BIOS_PADDRTOVADDR(x) (x)
76 vga_probe_unit(int unit, video_adapter_t *buf, int flags)
82 sw = vid_get_switch(VGA_DRIVER_NAME);
85 error = (*sw->probe)(unit, &adp, NULL, flags);
88 bcopy(adp, buf, sizeof(*buf));
93 vga_attach_unit(int unit, vga_softc_t *sc, int flags)
98 sw = vid_get_switch(VGA_DRIVER_NAME);
102 error = (*sw->probe)(unit, &sc->adp, NULL, flags);
105 return (*sw->init)(unit, sc->adp, flags);
108 /* cdev driver functions */
110 #ifdef FB_INSTALL_CDEV
113 vga_open(struct cdev *dev, vga_softc_t *sc, int flag, int mode, struct thread *td)
117 if (mode & (O_CREAT | O_APPEND | O_TRUNC))
120 return genfbopen(&sc->gensc, sc->adp, flag, mode, td);
124 vga_close(struct cdev *dev, vga_softc_t *sc, int flag, int mode, struct thread *td)
126 return genfbclose(&sc->gensc, sc->adp, flag, mode, td);
130 vga_read(struct cdev *dev, vga_softc_t *sc, struct uio *uio, int flag)
132 return genfbread(&sc->gensc, sc->adp, uio, flag);
136 vga_write(struct cdev *dev, vga_softc_t *sc, struct uio *uio, int flag)
138 return genfbread(&sc->gensc, sc->adp, uio, flag);
142 vga_ioctl(struct cdev *dev, vga_softc_t *sc, u_long cmd, caddr_t arg, int flag,
145 return genfbioctl(&sc->gensc, sc->adp, cmd, arg, flag, td);
149 vga_mmap(struct cdev *dev, vga_softc_t *sc, vm_ooffset_t offset,
150 vm_offset_t *paddr, int prot, vm_memattr_t *memattr)
152 return genfbmmap(&sc->gensc, sc->adp, offset, paddr, prot, memattr);
155 #endif /* FB_INSTALL_CDEV */
161 #include <dev/fb/vesa.h>
164 #define probe_done(adp) ((adp)->va_flags & V_ADP_PROBED)
165 #define init_done(adp) ((adp)->va_flags & V_ADP_INITIALIZED)
166 #define config_done(adp) ((adp)->va_flags & V_ADP_REGISTERED)
168 /* for compatibility with old kernel options */
169 #ifdef SC_ALT_SEQACCESS
170 #undef SC_ALT_SEQACCESS
171 #undef VGA_ALT_SEQACCESS
172 #define VGA_ALT_SEQACCESS 1
177 #undef VGA_SLOW_IOACCESS
178 #define VGA_SLOW_IOACCESS
181 /* architecture dependent option */
182 #if !defined(__i386__) && !defined(__amd64__)
183 #define VGA_NO_BIOS 1
186 /* this should really be in `rtc.h' */
187 #define RTC_EQUIPMENT 0x14
190 #define V_MODE_MAP_SIZE (M_VGA_CG320 + 1)
191 #define V_MODE_PARAM_SIZE 64
193 /* video adapter state buffer */
196 #define V_STATE_SIG 0x736f6962
197 u_char regs[V_MODE_PARAM_SIZE];
199 typedef struct adp_state adp_state_t;
201 /* video adapter information */
205 #define DCC_EGAMONO 3
210 * NOTE: `va_window' should have a virtual address, but is initialized
211 * with a physical address in the following table, as verify_adapter()
212 * will perform address conversion at run-time.
214 static video_adapter_t adapter_init_value[] = {
216 { 0, KD_MONO, "mda", 0, 0, 0, IO_MDA, IO_MDASIZE, MONO_CRTC,
217 MDA_BUF_BASE, MDA_BUF_SIZE, MDA_BUF_BASE, MDA_BUF_SIZE, MDA_BUF_SIZE,
220 { 0, KD_CGA, "cga", 0, 0, V_ADP_COLOR, IO_CGA, IO_CGASIZE, COLOR_CRTC,
221 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE,
224 { 0, KD_CGA, "cga", 0, 0, V_ADP_COLOR, IO_CGA, IO_CGASIZE, COLOR_CRTC,
225 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE,
228 { 0, KD_EGA, "ega", 0, 0, 0, IO_MDA, 48, MONO_CRTC,
229 EGA_BUF_BASE, EGA_BUF_SIZE, MDA_BUF_BASE, MDA_BUF_SIZE, MDA_BUF_SIZE,
232 { 0, KD_EGA, "ega", 0, 0, V_ADP_COLOR, IO_MDA, 48, COLOR_CRTC,
233 EGA_BUF_BASE, EGA_BUF_SIZE, CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE,
236 { 0, KD_EGA, "ega", 0, 0, V_ADP_COLOR, IO_MDA, 48, COLOR_CRTC,
237 EGA_BUF_BASE, EGA_BUF_SIZE, CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE,
241 static video_adapter_t biosadapter[2];
242 static int biosadapters = 0;
244 /* video driver declarations */
245 static int vga_configure(int flags);
246 int (*vga_sub_configure)(int flags);
248 static int vga_nop(void);
250 static int vga_error(void);
251 static vi_probe_t vga_probe;
252 static vi_init_t vga_init;
253 static vi_get_info_t vga_get_info;
254 static vi_query_mode_t vga_query_mode;
255 static vi_set_mode_t vga_set_mode;
256 static vi_save_font_t vga_save_font;
257 static vi_load_font_t vga_load_font;
258 static vi_show_font_t vga_show_font;
259 static vi_save_palette_t vga_save_palette;
260 static vi_load_palette_t vga_load_palette;
261 static vi_set_border_t vga_set_border;
262 static vi_save_state_t vga_save_state;
263 static vi_load_state_t vga_load_state;
264 static vi_set_win_org_t vga_set_origin;
265 static vi_read_hw_cursor_t vga_read_hw_cursor;
266 static vi_set_hw_cursor_t vga_set_hw_cursor;
267 static vi_set_hw_cursor_shape_t vga_set_hw_cursor_shape;
268 static vi_blank_display_t vga_blank_display;
269 static vi_mmap_t vga_mmap_buf;
270 static vi_ioctl_t vga_dev_ioctl;
271 #ifndef VGA_NO_MODE_CHANGE
272 static vi_clear_t vga_clear;
273 static vi_fill_rect_t vga_fill_rect;
274 static vi_bitblt_t vga_bitblt;
275 #else /* VGA_NO_MODE_CHANGE */
276 #define vga_clear (vi_clear_t *)vga_error
277 #define vga_fill_rect (vi_fill_rect_t *)vga_error
278 #define vga_bitblt (vi_bitblt_t *)vga_error
280 static vi_diag_t vga_diag;
282 static video_switch_t vgavidsw = {
299 vga_set_hw_cursor_shape,
311 VIDEO_DRIVER(mda, vgavidsw, NULL);
312 VIDEO_DRIVER(cga, vgavidsw, NULL);
313 VIDEO_DRIVER(ega, vgavidsw, NULL);
314 VIDEO_DRIVER(vga, vgavidsw, vga_configure);
316 /* VGA BIOS standard video modes */
320 static video_info_t bios_vmode[] = {
322 { M_B40x25, V_INFO_COLOR, 40, 25, 8, 8, 2, 1,
323 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
324 { M_C40x25, V_INFO_COLOR, 40, 25, 8, 8, 4, 1,
325 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
326 { M_B80x25, V_INFO_COLOR, 80, 25, 8, 8, 2, 1,
327 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
328 { M_C80x25, V_INFO_COLOR, 80, 25, 8, 8, 4, 1,
329 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
331 { M_ENH_B40x25, V_INFO_COLOR, 40, 25, 8, 14, 2, 1,
332 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
333 { M_ENH_C40x25, V_INFO_COLOR, 40, 25, 8, 14, 4, 1,
334 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
335 { M_ENH_B80x25, V_INFO_COLOR, 80, 25, 8, 14, 2, 1,
336 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
337 { M_ENH_C80x25, V_INFO_COLOR, 80, 25, 8, 14, 4, 1,
338 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
340 { M_VGA_C40x25, V_INFO_COLOR, 40, 25, 8, 16, 4, 1,
341 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
342 { M_VGA_M80x25, 0, 80, 25, 8, 16, 2, 1,
343 MDA_BUF_BASE, MDA_BUF_SIZE, MDA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
344 { M_VGA_C80x25, V_INFO_COLOR, 80, 25, 8, 16, 4, 1,
345 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
347 { M_EGAMONO80x25, 0, 80, 25, 8, 14, 2, 1,
348 MDA_BUF_BASE, MDA_BUF_SIZE, MDA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
350 { M_ENH_B80x43, V_INFO_COLOR, 80, 43, 8, 8, 2, 1,
351 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
352 { M_ENH_C80x43, V_INFO_COLOR, 80, 43, 8, 8, 4, 1,
353 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
355 { M_VGA_M80x30, 0, 80, 30, 8, 16, 2, 1,
356 MDA_BUF_BASE, MDA_BUF_SIZE, MDA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
357 { M_VGA_C80x30, V_INFO_COLOR, 80, 30, 8, 16, 4, 1,
358 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
359 { M_VGA_M80x50, 0, 80, 50, 8, 8, 2, 1,
360 MDA_BUF_BASE, MDA_BUF_SIZE, MDA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
361 { M_VGA_C80x50, V_INFO_COLOR, 80, 50, 8, 8, 4, 1,
362 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
363 { M_VGA_M80x60, 0, 80, 60, 8, 8, 2, 1,
364 MDA_BUF_BASE, MDA_BUF_SIZE, MDA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
365 { M_VGA_C80x60, V_INFO_COLOR, 80, 60, 8, 8, 4, 1,
366 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
368 #ifndef VGA_NO_MODE_CHANGE
371 { M_VGA_M90x25, 0, 90, 25, 8, 16, 2, 1,
372 MDA_BUF_BASE, MDA_BUF_SIZE, MDA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
373 { M_VGA_C90x25, V_INFO_COLOR, 90, 25, 8, 16, 4, 1,
374 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
375 { M_VGA_M90x30, 0, 90, 30, 8, 16, 2, 1,
376 MDA_BUF_BASE, MDA_BUF_SIZE, MDA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
377 { M_VGA_C90x30, V_INFO_COLOR, 90, 30, 8, 16, 4, 1,
378 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
379 { M_VGA_M90x43, 0, 90, 43, 8, 8, 2, 1,
380 MDA_BUF_BASE, MDA_BUF_SIZE, MDA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
381 { M_VGA_C90x43, V_INFO_COLOR, 90, 43, 8, 8, 4, 1,
382 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
383 { M_VGA_M90x50, 0, 90, 50, 8, 8, 2, 1,
384 MDA_BUF_BASE, MDA_BUF_SIZE, MDA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
385 { M_VGA_C90x50, V_INFO_COLOR, 90, 50, 8, 8, 4, 1,
386 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
387 { M_VGA_M90x60, 0, 90, 60, 8, 8, 2, 1,
388 MDA_BUF_BASE, MDA_BUF_SIZE, MDA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
389 { M_VGA_C90x60, V_INFO_COLOR, 90, 60, 8, 8, 4, 1,
390 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT },
391 #endif /* VGA_WIDTH90 */
394 { M_BG320, V_INFO_COLOR | V_INFO_GRAPHICS, 320, 200, 8, 8, 2, 1,
395 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_CGA },
396 { M_CG320, V_INFO_COLOR | V_INFO_GRAPHICS, 320, 200, 8, 8, 2, 1,
397 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_CGA },
398 { M_BG640, V_INFO_COLOR | V_INFO_GRAPHICS, 640, 200, 8, 8, 1, 1,
399 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_CGA },
401 { M_CG320_D, V_INFO_COLOR | V_INFO_GRAPHICS, 320, 200, 8, 8, 4, 4,
402 GRAPHICS_BUF_BASE, GRAPHICS_BUF_SIZE, GRAPHICS_BUF_SIZE, 0, 0,
404 { M_CG640_E, V_INFO_COLOR | V_INFO_GRAPHICS, 640, 200, 8, 8, 4, 4,
405 GRAPHICS_BUF_BASE, GRAPHICS_BUF_SIZE, GRAPHICS_BUF_SIZE, 0, 0 ,
407 { M_EGAMONOAPA, V_INFO_GRAPHICS, 640, 350, 8, 14, 4, 4,
408 GRAPHICS_BUF_BASE, GRAPHICS_BUF_SIZE, 64*1024, 0, 0 ,
410 { M_ENHMONOAPA2,V_INFO_GRAPHICS, 640, 350, 8, 14, 4, 4,
411 GRAPHICS_BUF_BASE, GRAPHICS_BUF_SIZE, GRAPHICS_BUF_SIZE, 0, 0 ,
413 { M_CG640x350, V_INFO_COLOR | V_INFO_GRAPHICS, 640, 350, 8, 14, 2, 2,
414 GRAPHICS_BUF_BASE, GRAPHICS_BUF_SIZE, GRAPHICS_BUF_SIZE, 0, 0 ,
416 { M_ENH_CG640, V_INFO_COLOR | V_INFO_GRAPHICS, 640, 350, 8, 14, 4, 4,
417 GRAPHICS_BUF_BASE, GRAPHICS_BUF_SIZE, GRAPHICS_BUF_SIZE, 0, 0 ,
420 { M_BG640x480, V_INFO_COLOR | V_INFO_GRAPHICS, 640, 480, 8, 16, 4, 4,
421 GRAPHICS_BUF_BASE, GRAPHICS_BUF_SIZE, GRAPHICS_BUF_SIZE, 0, 0 ,
423 { M_CG640x480, V_INFO_COLOR | V_INFO_GRAPHICS, 640, 480, 8, 16, 4, 4,
424 GRAPHICS_BUF_BASE, GRAPHICS_BUF_SIZE, GRAPHICS_BUF_SIZE, 0, 0 ,
426 { M_VGA_CG320, V_INFO_COLOR | V_INFO_GRAPHICS, 320, 200, 8, 8, 8, 1,
427 GRAPHICS_BUF_BASE, GRAPHICS_BUF_SIZE, GRAPHICS_BUF_SIZE, 0, 0,
428 V_INFO_MM_PACKED, 1 },
429 { M_VGA_MODEX, V_INFO_COLOR | V_INFO_GRAPHICS, 320, 240, 8, 8, 8, 4,
430 GRAPHICS_BUF_BASE, GRAPHICS_BUF_SIZE, GRAPHICS_BUF_SIZE, 0, 0,
432 #endif /* VGA_NO_MODE_CHANGE */
437 static int vga_init_done = FALSE;
438 #if !defined(VGA_NO_BIOS) && !defined(VGA_NO_MODE_CHANGE)
439 static u_char *video_mode_ptr = NULL; /* EGA/VGA */
440 static u_char *video_mode_ptr2 = NULL; /* CGA/MDA */
442 static u_char *mode_map[V_MODE_MAP_SIZE];
443 static adp_state_t adpstate;
444 static adp_state_t adpstate2;
445 static int rows_offset = 1;
447 /* local macros and functions */
448 #define BIOS_SADDRTOLADDR(p) ((((p) & 0xffff0000) >> 12) + ((p) & 0x0000ffff))
450 #if !defined(VGA_NO_BIOS) && !defined(VGA_NO_MODE_CHANGE)
451 static void map_mode_table(u_char *map[], u_char *table, int max);
453 static void clear_mode_map(video_adapter_t *adp, u_char *map[], int max,
455 #if !defined(VGA_NO_BIOS) && !defined(VGA_NO_MODE_CHANGE)
456 static int map_mode_num(int mode);
458 static int map_gen_mode_num(int type, int color, int mode);
459 static int map_bios_mode_num(int type, int color, int bios_mode);
460 static u_char *get_mode_param(int mode);
462 static void fill_adapter_param(int code, video_adapter_t *adp);
464 static int verify_adapter(video_adapter_t *adp);
465 static void update_adapter_info(video_adapter_t *adp, video_info_t *info);
466 #if !defined(VGA_NO_BIOS) && !defined(VGA_NO_MODE_CHANGE)
467 #define COMP_IDENTICAL 0
468 #define COMP_SIMILAR 1
469 #define COMP_DIFFERENT 2
470 static int comp_adpregs(u_char *buf1, u_char *buf2);
472 static int probe_adapters(void);
473 static int set_line_length(video_adapter_t *adp, int pixel);
474 static int set_display_start(video_adapter_t *adp, int x, int y);
476 #ifndef VGA_NO_MODE_CHANGE
478 static void set_width90(adp_state_t *params);
480 #endif /* !VGA_NO_MODE_CHANGE */
482 #ifndef VGA_NO_FONT_LOADING
483 #define PARAM_BUFSIZE 6
484 static void set_font_mode(video_adapter_t *adp, u_char *buf);
485 static void set_normal_mode(video_adapter_t *adp, u_char *buf);
488 #ifndef VGA_NO_MODE_CHANGE
489 static void filll_io(int val, vm_offset_t d, size_t size);
490 static void planar_fill(video_adapter_t *adp, int val);
491 static void packed_fill(video_adapter_t *adp, int val);
492 static void direct_fill(video_adapter_t *adp, int val);
494 static void planar_fill_rect(video_adapter_t *adp, int val, int x, int y,
496 static void packed_fill_rect(video_adapter_t *adp, int val, int x, int y,
498 static void direct_fill_rect16(video_adapter_t *adp, int val, int x, int y,
500 static void direct_fill_rect24(video_adapter_t *adp, int val, int x, int y,
502 static void direct_fill_rect32(video_adapter_t *adp, int val, int x, int y,
505 #endif /* !VGA_NO_MODE_CHANGE */
507 static void dump_buffer(u_char *buf, size_t len);
509 #define ISMAPPED(pa, width) \
510 (((pa) <= (u_long)0x1000 - (width)) \
511 || ((pa) >= ISA_HOLE_START && (pa) <= 0x100000 - (width)))
513 #define prologue(adp, flag, err) \
514 if (!vga_init_done || !((adp)->va_flags & (flag))) \
517 /* a backdoor for the console driver */
519 vga_configure(int flags)
524 for (i = 0; i < biosadapters; ++i) {
525 if (!probe_done(&biosadapter[i]))
527 biosadapter[i].va_flags |= V_ADP_INITIALIZED;
528 if (!config_done(&biosadapter[i])) {
529 if (vid_register(&biosadapter[i]) < 0)
531 biosadapter[i].va_flags |= V_ADP_REGISTERED;
534 if (vga_sub_configure != NULL)
535 (*vga_sub_configure)(flags);
540 /* local subroutines */
542 #if !defined(VGA_NO_BIOS) && !defined(VGA_NO_MODE_CHANGE)
543 /* construct the mode parameter map */
545 map_mode_table(u_char *map[], u_char *table, int max)
549 for(i = 0; i < max; ++i)
550 map[i] = table + i*V_MODE_PARAM_SIZE;
551 for(; i < V_MODE_MAP_SIZE; ++i)
554 #endif /* !VGA_NO_BIOS && !VGA_NO_MODE_CHANGE */
557 clear_mode_map(video_adapter_t *adp, u_char *map[], int max, int color)
563 * NOTE: we don't touch `bios_vmode[]' because it is shared
566 for(i = 0; i < max; ++i) {
567 if (vga_get_info(adp, i, &info))
569 if ((info.vi_flags & V_INFO_COLOR) != color)
574 #if !defined(VGA_NO_BIOS) && !defined(VGA_NO_MODE_CHANGE)
575 /* map the non-standard video mode to a known mode number */
577 map_mode_num(int mode)
583 { M_ENH_B80x43, M_ENH_B80x25 },
584 { M_ENH_C80x43, M_ENH_C80x25 },
585 { M_VGA_M80x30, M_VGA_M80x25 },
586 { M_VGA_C80x30, M_VGA_C80x25 },
587 { M_VGA_M80x50, M_VGA_M80x25 },
588 { M_VGA_C80x50, M_VGA_C80x25 },
589 { M_VGA_M80x60, M_VGA_M80x25 },
590 { M_VGA_C80x60, M_VGA_C80x25 },
592 { M_VGA_M90x25, M_VGA_M80x25 },
593 { M_VGA_C90x25, M_VGA_C80x25 },
594 { M_VGA_M90x30, M_VGA_M80x25 },
595 { M_VGA_C90x30, M_VGA_C80x25 },
596 { M_VGA_M90x43, M_VGA_M80x25 },
597 { M_VGA_C90x43, M_ENH_C80x25 },
598 { M_VGA_M90x50, M_VGA_M80x25 },
599 { M_VGA_C90x50, M_VGA_C80x25 },
600 { M_VGA_M90x60, M_VGA_M80x25 },
601 { M_VGA_C90x60, M_VGA_C80x25 },
603 { M_VGA_MODEX, M_VGA_CG320 },
607 for (i = 0; i < nitems(mode_map); ++i) {
608 if (mode_map[i].from == mode)
609 return mode_map[i].to;
613 #endif /* !VGA_NO_BIOS && !VGA_NO_MODE_CHANGE */
615 /* map a generic video mode to a known mode number */
617 map_gen_mode_num(int type, int color, int mode)
624 { M_TEXT_80x30, M_VGA_C80x30, M_VGA_M80x30, },
625 { M_TEXT_80x43, M_ENH_C80x43, M_ENH_B80x43, },
626 { M_TEXT_80x50, M_VGA_C80x50, M_VGA_M80x50, },
627 { M_TEXT_80x60, M_VGA_C80x60, M_VGA_M80x60, },
631 if (mode == M_TEXT_80x25) {
645 return M_EGAMONO80x25;
653 return M_EGAMONO80x25; /* XXX: this name is confusing */
660 for (i = 0; i < nitems(mode_map); ++i) {
661 if (mode_map[i].from == mode)
662 return ((color) ? mode_map[i].to_color : mode_map[i].to_mono);
667 /* turn the BIOS video number into our video mode number */
669 map_bios_mode_num(int type, int color, int bios_mode)
671 static int cga_modes[7] = {
672 M_B40x25, M_C40x25, /* 0, 1 */
673 M_B80x25, M_C80x25, /* 2, 3 */
677 static int ega_modes[17] = {
678 M_ENH_B40x25, M_ENH_C40x25, /* 0, 1 */
679 M_ENH_B80x25, M_ENH_C80x25, /* 2, 3 */
682 M_EGAMONO80x25, /* 7 */
686 M_ENHMONOAPA2, /* XXX: video momery > 64K */
687 M_ENH_CG640, /* XXX: video momery > 64K */
689 static int vga_modes[20] = {
690 M_VGA_C40x25, M_VGA_C40x25, /* 0, 1 */
691 M_VGA_C80x25, M_VGA_C80x25, /* 2, 3 */
694 M_VGA_M80x25, /* 7 */
700 M_BG640x480, M_CG640x480,
707 if (bios_mode < nitems(vga_modes))
708 return vga_modes[bios_mode];
716 if (bios_mode < nitems(ega_modes))
717 return ega_modes[bios_mode];
721 return M_EGAMONO80x25;
725 if (bios_mode < nitems(cga_modes))
726 return cga_modes[bios_mode];
733 return M_EGAMONO80x25; /* XXX: this name is confusing */
741 /* look up a parameter table entry */
743 *get_mode_param(int mode)
745 #if !defined(VGA_NO_BIOS) && !defined(VGA_NO_MODE_CHANGE)
746 if (mode >= V_MODE_MAP_SIZE)
747 mode = map_mode_num(mode);
749 if ((mode >= 0) && (mode < V_MODE_MAP_SIZE))
750 return mode_map[mode];
757 fill_adapter_param(int code, video_adapter_t *adp)
763 { DCC_MONO, DCC_EGA40 /* CGA monitor */ },
764 { DCC_MONO, DCC_EGA80 /* CGA monitor */ },
765 { DCC_MONO, DCC_EGA80 },
766 { DCC_MONO, DCC_EGA80 },
767 { DCC_CGA40, DCC_EGAMONO },
768 { DCC_CGA80, DCC_EGAMONO },
769 { DCC_EGA40 /* CGA monitor */, DCC_MONO},
770 { DCC_EGA80 /* CGA monitor */, DCC_MONO},
771 { DCC_EGA80, DCC_MONO },
772 { DCC_EGA80, DCC_MONO },
773 { DCC_EGAMONO, DCC_CGA40 },
774 { DCC_EGAMONO, DCC_CGA80 },
777 if ((code < 0) || (code >= nitems(dcc))) {
778 adp[V_ADP_PRIMARY] = adapter_init_value[DCC_MONO];
779 adp[V_ADP_SECONDARY] = adapter_init_value[DCC_CGA80];
781 adp[V_ADP_PRIMARY] = adapter_init_value[dcc[code].primary];
782 adp[V_ADP_SECONDARY] = adapter_init_value[dcc[code].secondary];
785 #endif /* VGA_NO_BIOS */
788 verify_adapter(video_adapter_t *adp)
792 #if !defined(VGA_NO_BIOS) && !defined(VGA_NO_MODE_CHANGE)
796 buf = BIOS_PADDRTOVADDR(adp->va_window);
799 if (readw(buf) != 0xA55A)
803 switch (adp->va_type) {
806 outb(adp->va_crtc_addr, 7);
807 if (inb(adp->va_crtc_addr) == 7) {
808 adp->va_type = KD_VGA;
809 adp->va_name = "vga";
810 adp->va_flags |= V_ADP_STATESAVE | V_ADP_PALETTE;
812 adp->va_flags |= V_ADP_STATELOAD | V_ADP_BORDER;
813 /* the color adapter may be in the 40x25 mode... XXX */
815 #if !defined(VGA_NO_BIOS) && !defined(VGA_NO_MODE_CHANGE)
816 /* get the BIOS video mode pointer */
817 p = *(u_int32_t *)BIOS_PADDRTOVADDR(0x4a8);
818 p = BIOS_SADDRTOLADDR(p);
819 if (ISMAPPED(p, sizeof(u_int32_t))) {
820 p = *(u_int32_t *)BIOS_PADDRTOVADDR(p);
821 p = BIOS_SADDRTOLADDR(p);
822 if (ISMAPPED(p, V_MODE_PARAM_SIZE))
823 video_mode_ptr = (u_char *)BIOS_PADDRTOVADDR(p);
829 adp->va_flags |= V_ADP_COLOR | V_ADP_BORDER;
830 /* may be in the 40x25 mode... XXX */
831 #if !defined(VGA_NO_BIOS) && !defined(VGA_NO_MODE_CHANGE)
832 /* get the BIOS video mode pointer */
833 p = *(u_int32_t *)BIOS_PADDRTOVADDR(0x1d*4);
834 p = BIOS_SADDRTOLADDR(p);
835 video_mode_ptr2 = (u_char *)BIOS_PADDRTOVADDR(p);
840 #if !defined(VGA_NO_BIOS) && !defined(VGA_NO_MODE_CHANGE)
841 /* get the BIOS video mode pointer */
842 p = *(u_int32_t *)BIOS_PADDRTOVADDR(0x1d*4);
843 p = BIOS_SADDRTOLADDR(p);
844 video_mode_ptr2 = (u_char *)BIOS_PADDRTOVADDR(p);
853 update_adapter_info(video_adapter_t *adp, video_info_t *info)
855 adp->va_flags &= ~V_ADP_COLOR;
857 (info->vi_flags & V_INFO_COLOR) ? V_ADP_COLOR : 0;
859 (adp->va_flags & V_ADP_COLOR) ? COLOR_CRTC : MONO_CRTC;
860 adp->va_window = BIOS_PADDRTOVADDR(info->vi_window);
861 adp->va_window_size = info->vi_window_size;
862 adp->va_window_gran = info->vi_window_gran;
863 adp->va_window_orig = 0;
865 adp->va_buffer = info->vi_buffer;
866 adp->va_buffer_size = info->vi_buffer_size;
867 adp->va_flags &= ~V_ADP_CWIDTH9;
868 if (info->vi_flags & V_INFO_CWIDTH9)
869 adp->va_flags |= V_ADP_CWIDTH9;
870 if (info->vi_mem_model == V_INFO_MM_VGAX) {
871 adp->va_line_width = info->vi_width/2;
872 } else if (info->vi_flags & V_INFO_GRAPHICS) {
873 switch (info->vi_depth/info->vi_planes) {
875 adp->va_line_width = info->vi_width/8;
878 adp->va_line_width = info->vi_width/4;
881 adp->va_line_width = info->vi_width/2;
884 default: /* shouldn't happen */
885 adp->va_line_width = info->vi_width;
889 adp->va_line_width = info->vi_width;
891 adp->va_disp_start.x = 0;
892 adp->va_disp_start.y = 0;
893 bcopy(info, &adp->va_info, sizeof(adp->va_info));
896 #if !defined(VGA_NO_BIOS) && !defined(VGA_NO_MODE_CHANGE)
897 /* compare two parameter table entries */
899 comp_adpregs(u_char *buf1, u_char *buf2)
903 } params[V_MODE_PARAM_SIZE] = {
904 {0xff}, {0x00}, {0xff}, /* COLS}, ROWS}, POINTS */
905 {0x00}, {0x00}, /* page length */
906 {0xfe}, {0xff}, {0xff}, {0xff}, /* sequencer registers */
907 {0xf3}, /* misc register */
908 {0xff}, {0xff}, {0xff}, {0x7f}, {0xff}, /* CRTC */
909 {0xff}, {0xff}, {0xff}, {0x7f}, {0xff},
910 {0x00}, {0x00}, {0x00}, {0x00}, {0x00},
911 {0x00}, {0xff}, {0x7f}, {0xff}, {0xff},
912 {0x7f}, {0xff}, {0xff}, {0xef}, {0xff},
913 {0xff}, {0xff}, {0xff}, {0xff}, {0xff}, /* attribute controller regs */
914 {0xff}, {0xff}, {0xff}, {0xff}, {0xff},
915 {0xff}, {0xff}, {0xff}, {0xff}, {0xff},
916 {0xff}, {0xff}, {0xff}, {0xff}, {0xf0},
917 {0xff}, {0xff}, {0xff}, {0xff}, {0xff}, /* GDC register */
918 {0xff}, {0xff}, {0xff}, {0xff},
920 int identical = TRUE;
923 if ((buf1 == NULL) || (buf2 == NULL))
924 return COMP_DIFFERENT;
926 for (i = 0; i < nitems(params); ++i) {
927 if (params[i].mask == 0) /* don't care */
929 if ((buf1[i] & params[i].mask) != (buf2[i] & params[i].mask))
930 return COMP_DIFFERENT;
931 if (buf1[i] != buf2[i])
934 return (identical) ? COMP_IDENTICAL : COMP_SIMILAR;
936 #endif /* !VGA_NO_BIOS && !VGA_NO_MODE_CHANGE */
938 /* probe video adapters and return the number of detected adapters */
942 video_adapter_t *adp;
944 #if !defined(VGA_NO_BIOS) && !defined(VGA_NO_MODE_CHANGE)
947 int height, i, width;
949 /* do this test only once */
952 vga_init_done = TRUE;
955 * Locate display adapters.
956 * The AT architecture supports up to two adapters. `syscons' allows
957 * the following combinations of adapters:
959 * 2) MDA + EGA/VGA color
960 * 3) CGA + EGA/VGA mono
961 * Note that `syscons' doesn't bother with MCGA as it is only
962 * avaiable for low end PS/2 models which has 80286 or earlier CPUs,
963 * thus, they are not running FreeBSD!
964 * When there are two adapaters in the system, one becomes `primary'
965 * and the other `secondary'. The EGA adapter has a set of DIP
966 * switches on board for this information and the EGA BIOS copies
967 * it in the BIOS data area BIOSDATA_VIDEOSWITCH (40:88).
968 * The VGA BIOS has more sophisticated mechanism and has this
969 * information in BIOSDATA_DCCINDEX (40:8a), but it also maintains
970 * compatibility with the EGA BIOS by updating BIOSDATA_VIDEOSWITCH.
974 * Check rtc and BIOS data area.
975 * XXX: we don't use BIOSDATA_EQUIPMENT, since it is not a dead
976 * copy of RTC_EQUIPMENT. Bits 4 and 5 of ETC_EQUIPMENT are
977 * zeros for EGA and VGA. However, the EGA/VGA BIOS sets
978 * these bits in BIOSDATA_EQUIPMENT according to the monitor
982 if (*(u_int32_t *)BIOS_PADDRTOVADDR(0x4a8)) {
983 /* EGA/VGA BIOS is present */
984 fill_adapter_param(readb(BIOS_PADDRTOVADDR(0x488)) & 0x0f,
987 switch ((rtcin(RTC_EQUIPMENT) >> 4) & 3) { /* bit 4 and 5 */
989 /* EGA/VGA: shouldn't be happening */
990 fill_adapter_param(readb(BIOS_PADDRTOVADDR(0x488)) & 0x0f,
995 /* FIXME: switch to the 80x25 mode? XXX */
996 biosadapter[V_ADP_PRIMARY] = adapter_init_value[DCC_CGA40];
997 biosadapter[V_ADP_SECONDARY] = adapter_init_value[DCC_MONO];
1001 biosadapter[V_ADP_PRIMARY] = adapter_init_value[DCC_CGA80];
1002 biosadapter[V_ADP_SECONDARY] = adapter_init_value[DCC_MONO];
1006 biosadapter[V_ADP_PRIMARY] = adapter_init_value[DCC_MONO];
1007 biosadapter[V_ADP_SECONDARY] = adapter_init_value[DCC_CGA80];
1012 /* assume EGA/VGA? XXX */
1013 biosadapter[V_ADP_PRIMARY] = adapter_init_value[DCC_EGA80];
1014 biosadapter[V_ADP_SECONDARY] = adapter_init_value[DCC_MONO];
1015 #endif /* VGA_NO_BIOS */
1018 if (verify_adapter(&biosadapter[V_ADP_SECONDARY]) == 0) {
1020 biosadapter[V_ADP_SECONDARY].va_flags |= V_ADP_PROBED;
1021 biosadapter[V_ADP_SECONDARY].va_mode =
1022 biosadapter[V_ADP_SECONDARY].va_initial_mode =
1023 map_bios_mode_num(biosadapter[V_ADP_SECONDARY].va_type,
1024 biosadapter[V_ADP_SECONDARY].va_flags
1026 biosadapter[V_ADP_SECONDARY].va_initial_bios_mode);
1028 biosadapter[V_ADP_SECONDARY].va_type = -1;
1030 if (verify_adapter(&biosadapter[V_ADP_PRIMARY]) == 0) {
1032 biosadapter[V_ADP_PRIMARY].va_flags |= V_ADP_PROBED;
1034 biosadapter[V_ADP_PRIMARY].va_initial_bios_mode =
1035 readb(BIOS_PADDRTOVADDR(0x449));
1037 biosadapter[V_ADP_PRIMARY].va_initial_bios_mode = 3; /* XXX */
1039 biosadapter[V_ADP_PRIMARY].va_mode =
1040 biosadapter[V_ADP_PRIMARY].va_initial_mode =
1041 map_bios_mode_num(biosadapter[V_ADP_PRIMARY].va_type,
1042 biosadapter[V_ADP_PRIMARY].va_flags & V_ADP_COLOR,
1043 biosadapter[V_ADP_PRIMARY].va_initial_bios_mode);
1045 biosadapter[V_ADP_PRIMARY] = biosadapter[V_ADP_SECONDARY];
1046 biosadapter[V_ADP_SECONDARY].va_type = -1;
1048 if (biosadapters == 0)
1049 return biosadapters;
1050 biosadapter[V_ADP_PRIMARY].va_unit = V_ADP_PRIMARY;
1051 biosadapter[V_ADP_SECONDARY].va_unit = V_ADP_SECONDARY;
1053 #if 0 /* we don't need these... */
1054 fb_init_struct(&biosadapter[V_ADP_PRIMARY], ...);
1055 fb_init_struct(&biosadapter[V_ADP_SECONDARY], ...);
1060 * We cannot have two video adapter of the same type; there must be
1061 * only one of color or mono adapter, or one each of them.
1063 if (biosadapters > 1) {
1064 if (!((biosadapter[0].va_flags ^ biosadapter[1].va_flags)
1066 /* we have two mono or color adapters!! */
1067 return (biosadapters = 0);
1072 * Ensure a zero start address. The registers are w/o
1073 * for old hardware so it's too hard to relocate the active screen
1075 * This must be done before vga_save_state() for VGA.
1077 outb(biosadapter[V_ADP_PRIMARY].va_crtc_addr, 12);
1078 outb(biosadapter[V_ADP_PRIMARY].va_crtc_addr + 1, 0);
1079 outb(biosadapter[V_ADP_PRIMARY].va_crtc_addr, 13);
1080 outb(biosadapter[V_ADP_PRIMARY].va_crtc_addr + 1, 0);
1082 /* the video mode parameter table in EGA/VGA BIOS */
1083 /* NOTE: there can be only one EGA/VGA, wheather color or mono,
1084 * recognized by the video BIOS.
1086 if ((biosadapter[V_ADP_PRIMARY].va_type == KD_EGA) ||
1087 (biosadapter[V_ADP_PRIMARY].va_type == KD_VGA)) {
1088 adp = &biosadapter[V_ADP_PRIMARY];
1089 } else if ((biosadapter[V_ADP_SECONDARY].va_type == KD_EGA) ||
1090 (biosadapter[V_ADP_SECONDARY].va_type == KD_VGA)) {
1091 adp = &biosadapter[V_ADP_SECONDARY];
1095 bzero(mode_map, sizeof(mode_map));
1097 if (adp->va_type == KD_VGA) {
1098 vga_save_state(adp, &adpstate, sizeof(adpstate));
1099 #if defined(VGA_NO_BIOS) || defined(VGA_NO_MODE_CHANGE)
1100 mode_map[adp->va_initial_mode] = adpstate.regs;
1102 #else /* VGA_NO_BIOS || VGA_NO_MODE_CHANGE */
1103 if (video_mode_ptr == NULL) {
1104 mode_map[adp->va_initial_mode] = adpstate.regs;
1107 /* discard the table if we are not familiar with it... */
1108 map_mode_table(mode_map, video_mode_ptr, M_VGA_CG320 + 1);
1109 mp = get_mode_param(adp->va_initial_mode);
1111 bcopy(mp, adpstate2.regs, sizeof(adpstate2.regs));
1112 switch (comp_adpregs(adpstate.regs, mp)) {
1113 case COMP_IDENTICAL:
1115 * OK, this parameter table looks reasonably familiar
1119 * This is a kludge for Toshiba DynaBook SS433
1120 * whose BIOS video mode table entry has the actual #
1121 * of rows at the offset 1; BIOSes from other
1122 * manufacturers store the # of rows - 1 there. XXX
1124 rows_offset = adpstate.regs[1] + 1 - mp[1];
1129 * Not exactly the same, but similar enough to be
1130 * trusted. However, use the saved register values
1131 * for the initial mode and other modes which are
1132 * based on the initial mode.
1134 mode_map[adp->va_initial_mode] = adpstate.regs;
1135 rows_offset = adpstate.regs[1] + 1 - mp[1];
1136 adpstate.regs[1] -= rows_offset - 1;
1139 case COMP_DIFFERENT:
1142 * Don't use the parameter table in the BIOS, since
1143 * even the BIOS doesn't use it for the initial mode.
1144 * Restrict the tweaked modes to (in practice) 80x50
1145 * from 80x25 with 400 scan lines, since the only safe
1146 * tweak is changing the characters from 8x16 to 8x8.
1148 video_mode_ptr = NULL;
1149 bzero(mode_map, sizeof(mode_map));
1150 mode_map[adp->va_initial_mode] = adpstate.regs;
1153 width = height = -1;
1154 for (i = 0; i < nitems(bios_vmode); ++i) {
1155 if (bios_vmode[i].vi_mode == adp->va_initial_mode) {
1156 width = bios_vmode[i].vi_width;
1157 height = bios_vmode[i].vi_height;
1161 for (i = 0; i < nitems(bios_vmode); ++i) {
1162 if (bios_vmode[i].vi_mode != adp->va_initial_mode &&
1163 map_mode_num(bios_vmode[i].vi_mode) ==
1164 adp->va_initial_mode &&
1165 (bios_vmode[i].vi_width != width ||
1166 bios_vmode[i].vi_height != 2 * height)) {
1167 bios_vmode[i].vi_mode = NA;
1173 #endif /* VGA_NO_BIOS || VGA_NO_MODE_CHANGE */
1175 #ifndef VGA_NO_MODE_CHANGE
1176 adp->va_flags |= V_ADP_MODECHANGE;
1178 #ifndef VGA_NO_FONT_LOADING
1179 adp->va_flags |= V_ADP_FONT;
1181 } else if (adp->va_type == KD_EGA) {
1182 #if defined(VGA_NO_BIOS) || defined(VGA_NO_MODE_CHANGE)
1184 #else /* VGA_NO_BIOS || VGA_NO_MODE_CHANGE */
1185 if (video_mode_ptr == NULL) {
1188 map_mode_table(mode_map, video_mode_ptr, M_ENH_C80x25 + 1);
1189 /* XXX how can one validate the EGA table... */
1190 mp = get_mode_param(adp->va_initial_mode);
1192 adp->va_flags |= V_ADP_MODECHANGE;
1193 #ifndef VGA_NO_FONT_LOADING
1194 adp->va_flags |= V_ADP_FONT;
1199 * This is serious. We will not be able to switch video
1202 video_mode_ptr = NULL;
1203 bzero(mode_map, sizeof(mode_map));
1207 #endif /* VGA_NO_BIOS || VGA_NO_MODE_CHANGE */
1211 /* remove conflicting modes if we have more than one adapter */
1212 if (biosadapters > 0) {
1213 for (i = 0; i < biosadapters; ++i) {
1214 if (!(biosadapter[i].va_flags & V_ADP_MODECHANGE))
1216 clear_mode_map(&biosadapter[i], mode_map, M_VGA_CG320 + 1,
1217 (biosadapter[i].va_flags & V_ADP_COLOR) ?
1219 if ((biosadapter[i].va_type == KD_VGA)
1220 || (biosadapter[i].va_type == KD_EGA)) {
1221 biosadapter[i].va_io_base =
1222 (biosadapter[i].va_flags & V_ADP_COLOR) ?
1224 biosadapter[i].va_io_size = 32;
1229 #if !defined(VGA_NO_BIOS) && !defined(VGA_NO_MODE_CHANGE)
1231 * Attempt to determine the real character width for each mode. 9 wide
1232 * is supposed to be standard for EGA mono mode and most VGA text modes,
1233 * but some hardware doesn't support it, so dynamic configuration is
1234 * needed. Bit 0 in sequencer register 1 is supposed control the width
1235 * (set = 8), but this is unreliable too. Trust that 0 in the sequencer
1236 * bit means 9 wide after verifying that 9 is consistent with some CRTC
1237 * timing. The ratio (Horizontal Total) / (Horizontal Displayed) is
1238 * about 1.2 in all standard 9-wide modes and should be about 9/8 larger
1239 * again in similar 8-wide modes; in practice it is usually about 1.4
1242 for (i = 0; i < nitems(bios_vmode); ++i) {
1243 if (bios_vmode[i].vi_mem_model == V_INFO_MM_TEXT &&
1244 bios_vmode[i].vi_width != 90) {
1245 mp = get_mode_param(map_mode_num(bios_vmode[i].vi_mode));
1246 if (mp != NULL && !(mp[5] & 1) && mp[10] <= mp[11] * 125 / 100)
1247 bios_vmode[i].vi_flags |= V_INFO_CWIDTH9;
1252 /* buffer address */
1253 vga_get_info(&biosadapter[V_ADP_PRIMARY],
1254 biosadapter[V_ADP_PRIMARY].va_initial_mode, &info);
1255 info.vi_flags &= ~V_INFO_LINEAR; /* XXX */
1256 update_adapter_info(&biosadapter[V_ADP_PRIMARY], &info);
1258 if (biosadapters > 1) {
1259 vga_get_info(&biosadapter[V_ADP_SECONDARY],
1260 biosadapter[V_ADP_SECONDARY].va_initial_mode, &info);
1261 info.vi_flags &= ~V_INFO_LINEAR; /* XXX */
1262 update_adapter_info(&biosadapter[V_ADP_SECONDARY], &info);
1266 * XXX: we should verify the following values for the primary adapter...
1267 * crtc I/O port address: *(u_int16_t *)BIOS_PADDRTOVADDR(0x463);
1268 * color/mono display: (*(u_int8_t *)BIOS_PADDRTOVADDR(0x487) & 0x02)
1269 * ? 0 : V_ADP_COLOR;
1270 * columns: *(u_int8_t *)BIOS_PADDRTOVADDR(0x44a);
1271 * rows: *(u_int8_t *)BIOS_PADDRTOVADDR(0x484);
1272 * font size: *(u_int8_t *)BIOS_PADDRTOVADDR(0x485);
1273 * buffer size: *(u_int16_t *)BIOS_PADDRTOVADDR(0x44c);
1276 return biosadapters;
1279 /* set the scan line length in pixel */
1281 set_line_length(video_adapter_t *adp, int pixel)
1284 int ppw; /* pixels per word */
1285 int bpl; /* bytes per line */
1288 if ((adp->va_type != KD_VGA) && (adp->va_type != KD_EGA))
1290 mp = get_mode_param(adp->va_mode);
1294 switch (adp->va_info.vi_mem_model) {
1295 case V_INFO_MM_PLANAR:
1296 ppw = 16/(adp->va_info.vi_depth/adp->va_info.vi_planes);
1297 count = howmany(pixel, ppw)/2;
1298 bpl = (howmany(pixel, ppw)/2)*4;
1300 case V_INFO_MM_PACKED:
1301 count = (pixel + 7)/8;
1302 bpl = rounddown(pixel + 7, 8);
1304 case V_INFO_MM_TEXT:
1305 count = (pixel + 7)/8; /* columns */
1306 bpl = (pixel + 7)/8; /* columns */
1312 if (mp[10 + 0x17] & 0x40) /* CRTC mode control reg */
1313 count *= 2; /* byte mode */
1314 outb(adp->va_crtc_addr, 0x13);
1315 outb(adp->va_crtc_addr + 1, count);
1316 adp->va_line_width = bpl;
1322 set_display_start(video_adapter_t *adp, int x, int y)
1324 int off; /* byte offset (graphics mode)/word offset (text mode) */
1325 int poff; /* pixel offset */
1326 int roff; /* row offset */
1327 int ppb; /* pixels per byte */
1329 if ((adp->va_type != KD_VGA) && (adp->va_type != KD_EGA))
1331 if (adp->va_info.vi_flags & V_INFO_GRAPHICS) {
1332 ppb = 8/(adp->va_info.vi_depth/adp->va_info.vi_planes);
1333 off = y*adp->va_line_width + x/ppb;
1337 if ((adp->va_type == KD_VGA) || (adp->va_type == KD_EGA)) {
1346 off = y/adp->va_info.vi_cheight*adp->va_line_width + x/ppb;
1347 roff = y%adp->va_info.vi_cheight;
1348 /* FIXME: is this correct? XXX */
1356 outb(adp->va_crtc_addr, 0xc); /* high */
1357 outb(adp->va_crtc_addr + 1, off >> 8);
1358 outb(adp->va_crtc_addr, 0xd); /* low */
1359 outb(adp->va_crtc_addr + 1, off & 0xff);
1361 /* horizontal pel pan */
1362 if ((adp->va_type == KD_VGA) || (adp->va_type == KD_EGA)) {
1363 inb(adp->va_crtc_addr + 6);
1364 outb(ATC, 0x13 | 0x20);
1366 inb(adp->va_crtc_addr + 6);
1370 /* preset raw scan */
1371 outb(adp->va_crtc_addr, 8);
1372 outb(adp->va_crtc_addr + 1, roff);
1374 adp->va_disp_start.x = x;
1375 adp->va_disp_start.y = y;
1379 #ifndef VGA_NO_MODE_CHANGE
1380 #if defined(__i386__) || defined(__amd64__) /* XXX */
1382 fill(int val, void *d, size_t size)
1389 #endif /* __i386__ */
1392 filll_io(int val, vm_offset_t d, size_t size)
1394 while (size-- > 0) {
1396 d += sizeof(u_int32_t);
1399 #endif /* !VGA_NO_MODE_CHANGE */
1418 vga_probe(int unit, video_adapter_t **adpp, void *arg, int flags)
1421 if (unit >= biosadapters)
1424 *adpp = &biosadapter[unit];
1430 vga_init(int unit, video_adapter_t *adp, int flags)
1432 if ((unit >= biosadapters) || (adp == NULL) || !probe_done(adp))
1435 if (!init_done(adp)) {
1436 /* nothing to do really... */
1437 adp->va_flags |= V_ADP_INITIALIZED;
1440 if (!config_done(adp)) {
1441 if (vid_register(adp) < 0)
1443 adp->va_flags |= V_ADP_REGISTERED;
1445 if (vga_sub_configure != NULL)
1446 (*vga_sub_configure)(0);
1453 * Return the video_info structure of the requested video mode.
1458 vga_get_info(video_adapter_t *adp, int mode, video_info_t *info)
1465 mode = map_gen_mode_num(adp->va_type, adp->va_flags & V_ADP_COLOR, mode);
1466 #ifndef VGA_NO_MODE_CHANGE
1467 if (adp->va_flags & V_ADP_MODECHANGE) {
1469 * If the parameter table entry for this mode is not found,
1470 * the mode is not supported...
1472 if (get_mode_param(mode) == NULL)
1475 #endif /* VGA_NO_MODE_CHANGE */
1478 * Even if we don't support video mode switching on this adapter,
1479 * the information on the initial (thus current) video mode
1480 * should be made available.
1482 if (mode != adp->va_initial_mode)
1486 for (i = 0; bios_vmode[i].vi_mode != EOT; ++i) {
1487 if (bios_vmode[i].vi_mode == NA)
1489 if (mode == bios_vmode[i].vi_mode) {
1490 *info = bios_vmode[i];
1492 info->vi_buffer_size = info->vi_window_size*info->vi_planes;
1501 * Find a video mode matching the requested parameters.
1502 * Fields filled with 0 are considered "don't care" fields and
1508 vga_query_mode(video_adapter_t *adp, video_info_t *info)
1515 for (i = 0; bios_vmode[i].vi_mode != EOT; ++i) {
1516 if (bios_vmode[i].vi_mode == NA)
1519 if ((info->vi_width != 0)
1520 && (info->vi_width != bios_vmode[i].vi_width))
1522 if ((info->vi_height != 0)
1523 && (info->vi_height != bios_vmode[i].vi_height))
1525 if ((info->vi_cwidth != 0)
1526 && (info->vi_cwidth != bios_vmode[i].vi_cwidth))
1528 if ((info->vi_cheight != 0)
1529 && (info->vi_cheight != bios_vmode[i].vi_cheight))
1531 if ((info->vi_depth != 0)
1532 && (info->vi_depth != bios_vmode[i].vi_depth))
1534 if ((info->vi_planes != 0)
1535 && (info->vi_planes != bios_vmode[i].vi_planes))
1537 /* XXX: should check pixel format, memory model */
1538 if ((info->vi_flags != 0)
1539 && (info->vi_flags != bios_vmode[i].vi_flags))
1542 /* verify if this mode is supported on this adapter */
1543 if (vga_get_info(adp, bios_vmode[i].vi_mode, info))
1552 * Change the video mode.
1557 #ifndef VGA_NO_MODE_CHANGE
1560 set_width90(adp_state_t *params)
1563 * Based on code submitted by Kelly Yancey (kbyanc@freedomnet.com)
1564 * and alexv@sui.gda.itesm.mx.
1566 params->regs[5] |= 1; /* toggle 8 pixel wide fonts */
1567 params->regs[10+0x0] = 0x6b;
1568 params->regs[10+0x1] = 0x59;
1569 params->regs[10+0x2] = 0x5a;
1570 params->regs[10+0x3] = 0x8e;
1571 params->regs[10+0x4] = 0x5e;
1572 params->regs[10+0x5] = 0x8a;
1573 params->regs[10+0x13] = 45;
1574 params->regs[35+0x13] = 0;
1576 #endif /* VGA_WIDTH90 */
1577 #endif /* !VGA_NO_MODE_CHANGE */
1580 vga_set_mode(video_adapter_t *adp, int mode)
1582 #ifndef VGA_NO_MODE_CHANGE
1586 prologue(adp, V_ADP_MODECHANGE, ENODEV);
1588 mode = map_gen_mode_num(adp->va_type,
1589 adp->va_flags & V_ADP_COLOR, mode);
1590 if (vga_get_info(adp, mode, &info))
1594 printf("vga_set_mode(): setting mode %d\n", mode);
1597 params.sig = V_STATE_SIG;
1598 bcopy(get_mode_param(mode), params.regs, sizeof(params.regs));
1602 case M_VGA_C90x60: case M_VGA_M90x60:
1603 set_width90(¶ms);
1606 case M_VGA_C80x60: case M_VGA_M80x60:
1607 params.regs[2] = 0x08;
1608 params.regs[19] = 0x47;
1612 case M_VGA_C90x30: case M_VGA_M90x30:
1613 set_width90(¶ms);
1616 case M_VGA_C80x30: case M_VGA_M80x30:
1617 params.regs[19] = 0x4f;
1619 params.regs[9] |= 0xc0;
1620 params.regs[16] = 0x08;
1621 params.regs[17] = 0x3e;
1622 params.regs[26] = 0xea;
1623 params.regs[28] = 0xdf;
1624 params.regs[31] = 0xe7;
1625 params.regs[32] = 0x04;
1629 case M_VGA_C90x43: case M_VGA_M90x43:
1630 set_width90(¶ms);
1633 case M_ENH_C80x43: case M_ENH_B80x43:
1634 params.regs[28] = 87;
1638 case M_VGA_C90x50: case M_VGA_M90x50:
1639 set_width90(¶ms);
1642 case M_VGA_C80x50: case M_VGA_M80x50:
1645 params.regs[19] = 7;
1649 case M_VGA_C90x25: case M_VGA_M90x25:
1650 set_width90(¶ms);
1653 case M_VGA_C40x25: case M_VGA_C80x25:
1655 case M_B40x25: case M_C40x25:
1656 case M_B80x25: case M_C80x25:
1657 case M_ENH_B40x25: case M_ENH_C40x25:
1658 case M_ENH_B80x25: case M_ENH_C80x25:
1659 case M_EGAMONO80x25:
1662 vga_load_state(adp, ¶ms);
1666 /* "unchain" the VGA mode */
1667 params.regs[5-1+0x04] &= 0xf7;
1668 params.regs[5-1+0x04] |= 0x04;
1669 /* turn off doubleword mode */
1670 params.regs[10+0x14] &= 0xbf;
1671 /* turn off word addressing */
1672 params.regs[10+0x17] |= 0x40;
1673 /* set logical screen width */
1674 params.regs[10+0x13] = 80;
1676 params.regs[10+0x11] = 0x2c;
1677 params.regs[10+0x06] = 0x0d;
1678 params.regs[10+0x07] = 0x3e;
1679 params.regs[10+0x10] = 0xea;
1680 params.regs[10+0x11] = 0xac;
1681 params.regs[10+0x12] = 0xdf;
1682 params.regs[10+0x15] = 0xe7;
1683 params.regs[10+0x16] = 0x06;
1684 /* set vertical sync polarity to reflect aspect ratio */
1685 params.regs[9] = 0xe3;
1688 case M_BG320: case M_CG320: case M_BG640:
1689 case M_CG320_D: case M_CG640_E:
1690 case M_CG640x350: case M_ENH_CG640:
1691 case M_BG640x480: case M_CG640x480: case M_VGA_CG320:
1694 vga_load_state(adp, ¶ms);
1701 adp->va_mode = mode;
1702 info.vi_flags &= ~V_INFO_LINEAR; /* XXX */
1703 update_adapter_info(adp, &info);
1705 /* move hardware cursor out of the way */
1706 vidd_set_hw_cursor(adp, -1, -1);
1709 #else /* VGA_NO_MODE_CHANGE */
1711 #endif /* VGA_NO_MODE_CHANGE */
1714 #ifndef VGA_NO_FONT_LOADING
1717 set_font_mode(video_adapter_t *adp, u_char *buf)
1724 /* save register values */
1725 if (adp->va_type == KD_VGA) {
1726 outb(TSIDX, 0x02); buf[0] = inb(TSREG);
1727 outb(TSIDX, 0x04); buf[1] = inb(TSREG);
1728 outb(GDCIDX, 0x04); buf[2] = inb(GDCREG);
1729 outb(GDCIDX, 0x05); buf[3] = inb(GDCREG);
1730 outb(GDCIDX, 0x06); buf[4] = inb(GDCREG);
1731 inb(adp->va_crtc_addr + 6);
1732 outb(ATC, 0x10); buf[5] = inb(ATC + 1);
1733 } else /* if (adp->va_type == KD_EGA) */ {
1735 * EGA cannot be read; copy parameters from the mode parameter
1738 mp = get_mode_param(adp->va_mode);
1739 buf[0] = mp[5 + 0x02 - 1];
1740 buf[1] = mp[5 + 0x04 - 1];
1741 buf[2] = mp[55 + 0x04];
1742 buf[3] = mp[55 + 0x05];
1743 buf[4] = mp[55 + 0x06];
1744 buf[5] = mp[35 + 0x10];
1747 /* setup vga for loading fonts */
1748 inb(adp->va_crtc_addr + 6); /* reset flip-flop */
1749 outb(ATC, 0x10); outb(ATC, buf[5] & ~0x01);
1750 inb(adp->va_crtc_addr + 6); /* reset flip-flop */
1751 outb(ATC, 0x20); /* enable palette */
1753 #ifdef VGA_SLOW_IOACCESS
1754 #ifdef VGA_ALT_SEQACCESS
1755 outb(TSIDX, 0x00); outb(TSREG, 0x01);
1757 outb(TSIDX, 0x02); outb(TSREG, 0x04);
1758 outb(TSIDX, 0x04); outb(TSREG, 0x07);
1759 #ifdef VGA_ALT_SEQACCESS
1760 outb(TSIDX, 0x00); outb(TSREG, 0x03);
1762 outb(GDCIDX, 0x04); outb(GDCREG, 0x02);
1763 outb(GDCIDX, 0x05); outb(GDCREG, 0x00);
1764 outb(GDCIDX, 0x06); outb(GDCREG, 0x04);
1765 #else /* VGA_SLOW_IOACCESS */
1766 #ifdef VGA_ALT_SEQACCESS
1767 outw(TSIDX, 0x0100);
1769 outw(TSIDX, 0x0402);
1770 outw(TSIDX, 0x0704);
1771 #ifdef VGA_ALT_SEQACCESS
1772 outw(TSIDX, 0x0300);
1774 outw(GDCIDX, 0x0204);
1775 outw(GDCIDX, 0x0005);
1776 outw(GDCIDX, 0x0406); /* addr = a0000, 64kb */
1777 #endif /* VGA_SLOW_IOACCESS */
1783 set_normal_mode(video_adapter_t *adp, u_char *buf)
1789 /* setup vga for normal operation mode again */
1790 inb(adp->va_crtc_addr + 6); /* reset flip-flop */
1791 outb(ATC, 0x10); outb(ATC, buf[5]);
1792 inb(adp->va_crtc_addr + 6); /* reset flip-flop */
1793 outb(ATC, 0x20); /* enable palette */
1795 #ifdef VGA_SLOW_IOACCESS
1796 #ifdef VGA_ALT_SEQACCESS
1797 outb(TSIDX, 0x00); outb(TSREG, 0x01);
1799 outb(TSIDX, 0x02); outb(TSREG, buf[0]);
1800 outb(TSIDX, 0x04); outb(TSREG, buf[1]);
1801 #ifdef VGA_ALT_SEQACCESS
1802 outb(TSIDX, 0x00); outb(TSREG, 0x03);
1804 outb(GDCIDX, 0x04); outb(GDCREG, buf[2]);
1805 outb(GDCIDX, 0x05); outb(GDCREG, buf[3]);
1806 if (adp->va_crtc_addr == MONO_CRTC) {
1807 outb(GDCIDX, 0x06); outb(GDCREG,(buf[4] & 0x03) | 0x08);
1809 outb(GDCIDX, 0x06); outb(GDCREG,(buf[4] & 0x03) | 0x0c);
1811 #else /* VGA_SLOW_IOACCESS */
1812 #ifdef VGA_ALT_SEQACCESS
1813 outw(TSIDX, 0x0100);
1815 outw(TSIDX, 0x0002 | (buf[0] << 8));
1816 outw(TSIDX, 0x0004 | (buf[1] << 8));
1817 #ifdef VGA_ALT_SEQACCESS
1818 outw(TSIDX, 0x0300);
1820 outw(GDCIDX, 0x0004 | (buf[2] << 8));
1821 outw(GDCIDX, 0x0005 | (buf[3] << 8));
1822 if (adp->va_crtc_addr == MONO_CRTC)
1823 outw(GDCIDX, 0x0006 | (((buf[4] & 0x03) | 0x08)<<8));
1825 outw(GDCIDX, 0x0006 | (((buf[4] & 0x03) | 0x0c)<<8));
1826 #endif /* VGA_SLOW_IOACCESS */
1831 #endif /* VGA_NO_FONT_LOADING */
1835 * Read the font data in the requested font page from the video adapter.
1840 vga_save_font(video_adapter_t *adp, int page, int fontsize, int fontwidth,
1841 u_char *data, int ch, int count)
1843 #ifndef VGA_NO_FONT_LOADING
1844 u_char buf[PARAM_BUFSIZE];
1845 vm_offset_t segment;
1847 #ifdef VGA_ALT_SEQACCESS
1852 prologue(adp, V_ADP_FONT, ENODEV);
1854 if (fontsize < 14) {
1857 } else if (fontsize >= 32) {
1859 } else if (fontsize >= 16) {
1867 if (page < 0 || page >= 8 || fontwidth != 8)
1869 segment = FONT_BUF + 0x4000*page;
1873 #ifdef VGA_ALT_SEQACCESS
1874 if (adp->va_type == KD_VGA) { /* what about EGA? XXX */
1876 outb(TSIDX, 0x00); outb(TSREG, 0x01);
1877 outb(TSIDX, 0x01); val = inb(TSREG); /* disable screen */
1878 outb(TSIDX, 0x01); outb(TSREG, val | 0x20);
1879 outb(TSIDX, 0x00); outb(TSREG, 0x03);
1884 set_font_mode(adp, buf);
1885 if (fontsize == 32) {
1886 bcopy_fromio((uintptr_t)segment + ch*32, data, fontsize*count);
1888 for (c = ch; count > 0; ++c, --count) {
1889 bcopy_fromio((uintptr_t)segment + c*32, data, fontsize);
1893 set_normal_mode(adp, buf);
1895 #ifdef VGA_ALT_SEQACCESS
1896 if (adp->va_type == KD_VGA) {
1898 outb(TSIDX, 0x00); outb(TSREG, 0x01);
1899 outb(TSIDX, 0x01); outb(TSREG, val & 0xdf); /* enable screen */
1900 outb(TSIDX, 0x00); outb(TSREG, 0x03);
1906 #else /* VGA_NO_FONT_LOADING */
1908 #endif /* VGA_NO_FONT_LOADING */
1913 * Set the font data in the requested font page.
1914 * NOTE: it appears that some recent video adapters do not support
1915 * the font page other than 0... XXX
1920 vga_load_font(video_adapter_t *adp, int page, int fontsize, int fontwidth,
1921 u_char *data, int ch, int count)
1923 #ifndef VGA_NO_FONT_LOADING
1924 u_char buf[PARAM_BUFSIZE];
1925 vm_offset_t segment;
1927 #ifdef VGA_ALT_SEQACCESS
1932 prologue(adp, V_ADP_FONT, ENODEV);
1934 if (fontsize < 14) {
1937 } else if (fontsize >= 32) {
1939 } else if (fontsize >= 16) {
1947 if (page < 0 || page >= 8 || fontwidth != 8)
1949 segment = FONT_BUF + 0x4000*page;
1953 #ifdef VGA_ALT_SEQACCESS
1954 if (adp->va_type == KD_VGA) { /* what about EGA? XXX */
1956 outb(TSIDX, 0x00); outb(TSREG, 0x01);
1957 outb(TSIDX, 0x01); val = inb(TSREG); /* disable screen */
1958 outb(TSIDX, 0x01); outb(TSREG, val | 0x20);
1959 outb(TSIDX, 0x00); outb(TSREG, 0x03);
1964 set_font_mode(adp, buf);
1965 if (fontsize == 32) {
1966 bcopy_toio(data, (uintptr_t)segment + ch*32, fontsize*count);
1968 for (c = ch; count > 0; ++c, --count) {
1969 bcopy_toio(data, (uintptr_t)segment + c*32, fontsize);
1973 set_normal_mode(adp, buf);
1975 #ifdef VGA_ALT_SEQACCESS
1976 if (adp->va_type == KD_VGA) {
1978 outb(TSIDX, 0x00); outb(TSREG, 0x01);
1979 outb(TSIDX, 0x01); outb(TSREG, val & 0xdf); /* enable screen */
1980 outb(TSIDX, 0x00); outb(TSREG, 0x03);
1986 #else /* VGA_NO_FONT_LOADING */
1988 #endif /* VGA_NO_FONT_LOADING */
1993 * Activate the requested font page.
1994 * NOTE: it appears that some recent video adapters do not support
1995 * the font page other than 0... XXX
2000 vga_show_font(video_adapter_t *adp, int page)
2002 #ifndef VGA_NO_FONT_LOADING
2003 static u_char cg[] = { 0x00, 0x05, 0x0a, 0x0f, 0x30, 0x35, 0x3a, 0x3f };
2006 prologue(adp, V_ADP_FONT, ENODEV);
2007 if (page < 0 || page >= 8)
2011 outb(TSIDX, 0x03); outb(TSREG, cg[page]);
2015 #else /* VGA_NO_FONT_LOADING */
2017 #endif /* VGA_NO_FONT_LOADING */
2022 * Read DAC values. The values have expressed in 8 bits.
2027 vga_save_palette(video_adapter_t *adp, u_char *palette)
2032 prologue(adp, V_ADP_PALETTE, ENODEV);
2035 * We store 8 bit values in the palette buffer, while the standard
2036 * VGA has 6 bit DAC .
2038 outb(PALRADR, 0x00);
2039 bits = (adp->va_flags & V_ADP_DAC8) != 0 ? 0 : 2;
2040 for (i = 0; i < 256*3; ++i)
2041 palette[i] = inb(PALDATA) << bits;
2042 inb(adp->va_crtc_addr + 6); /* reset flip/flop */
2047 vga_save_palette2(video_adapter_t *adp, int base, int count,
2048 u_char *r, u_char *g, u_char *b)
2053 prologue(adp, V_ADP_PALETTE, ENODEV);
2055 outb(PALRADR, base);
2056 bits = (adp->va_flags & V_ADP_DAC8) != 0 ? 0 : 2;
2057 for (i = 0; i < count; ++i) {
2058 r[i] = inb(PALDATA) << bits;
2059 g[i] = inb(PALDATA) << bits;
2060 b[i] = inb(PALDATA) << bits;
2062 inb(adp->va_crtc_addr + 6); /* reset flip/flop */
2073 vga_load_palette(video_adapter_t *adp, u_char *palette)
2078 prologue(adp, V_ADP_PALETTE, ENODEV);
2080 outb(PIXMASK, 0xff); /* no pixelmask */
2081 outb(PALWADR, 0x00);
2082 bits = (adp->va_flags & V_ADP_DAC8) != 0 ? 0 : 2;
2083 for (i = 0; i < 256*3; ++i)
2084 outb(PALDATA, palette[i] >> bits);
2085 inb(adp->va_crtc_addr + 6); /* reset flip/flop */
2086 outb(ATC, 0x20); /* enable palette */
2091 vga_load_palette2(video_adapter_t *adp, int base, int count,
2092 u_char *r, u_char *g, u_char *b)
2097 prologue(adp, V_ADP_PALETTE, ENODEV);
2099 outb(PIXMASK, 0xff); /* no pixelmask */
2100 outb(PALWADR, base);
2101 bits = (adp->va_flags & V_ADP_DAC8) != 0 ? 0 : 2;
2102 for (i = 0; i < count; ++i) {
2103 outb(PALDATA, r[i] >> bits);
2104 outb(PALDATA, g[i] >> bits);
2105 outb(PALDATA, b[i] >> bits);
2107 inb(adp->va_crtc_addr + 6); /* reset flip/flop */
2108 outb(ATC, 0x20); /* enable palette */
2114 * Change the border color.
2119 vga_set_border(video_adapter_t *adp, int color)
2121 prologue(adp, V_ADP_BORDER, ENODEV);
2123 switch (adp->va_type) {
2126 inb(adp->va_crtc_addr + 6); /* reset flip-flop */
2127 outb(ATC, 0x31); outb(ATC, color & 0xff);
2130 outb(adp->va_crtc_addr + 5, color & 0x0f); /* color select register */
2142 * Read video register values.
2143 * NOTE: this function only reads the standard EGA/VGA registers.
2144 * any extra/extended registers of SVGA adapters are not saved.
2149 vga_save_state(video_adapter_t *adp, void *p, size_t size)
2158 /* return the required buffer size */
2159 prologue(adp, V_ADP_STATESAVE, 0);
2160 return sizeof(adp_state_t);
2162 prologue(adp, V_ADP_STATESAVE, ENODEV);
2163 if (size < sizeof(adp_state_t))
2167 ((adp_state_t *)p)->sig = V_STATE_SIG;
2168 buf = ((adp_state_t *)p)->regs;
2169 bzero(buf, V_MODE_PARAM_SIZE);
2170 crtc_addr = adp->va_crtc_addr;
2174 outb(TSIDX, 0x00); outb(TSREG, 0x01); /* stop sequencer */
2175 for (i = 0, j = 5; i < 4; i++) {
2177 buf[j++] = inb(TSREG);
2179 buf[9] = inb(MISC + 10); /* dot-clock */
2180 outb(TSIDX, 0x00); outb(TSREG, 0x03); /* start sequencer */
2182 for (i = 0, j = 10; i < 25; i++) { /* crtc */
2184 buf[j++] = inb(crtc_addr + 1);
2186 for (i = 0, j = 35; i < 20; i++) { /* attribute ctrl */
2187 inb(crtc_addr + 6); /* reset flip-flop */
2189 buf[j++] = inb(ATC + 1);
2191 for (i = 0, j = 55; i < 9; i++) { /* graph data ctrl */
2193 buf[j++] = inb(GDCREG);
2195 inb(crtc_addr + 6); /* reset flip-flop */
2196 outb(ATC, 0x20); /* enable palette */
2201 if (vga_get_info(adp, adp->va_mode, &info) == 0) {
2202 if (info.vi_flags & V_INFO_GRAPHICS) {
2203 buf[0] = info.vi_width/info.vi_cwidth; /* COLS */
2204 buf[1] = info.vi_height/info.vi_cheight - 1; /* ROWS */
2206 buf[0] = info.vi_width; /* COLS */
2207 buf[1] = info.vi_height - 1; /* ROWS */
2209 buf[2] = info.vi_cheight; /* POINTS */
2212 buf[0] = readb(BIOS_PADDRTOVADDR(0x44a)); /* COLS */
2213 buf[1] = readb(BIOS_PADDRTOVADDR(0x484)); /* ROWS */
2214 buf[2] = readb(BIOS_PADDRTOVADDR(0x485)); /* POINTS */
2215 buf[3] = readb(BIOS_PADDRTOVADDR(0x44c));
2216 buf[4] = readb(BIOS_PADDRTOVADDR(0x44d));
2224 * Set video registers at once.
2225 * NOTE: this function only updates the standard EGA/VGA registers.
2226 * any extra/extended registers of SVGA adapters are not changed.
2231 vga_load_state(video_adapter_t *adp, void *p)
2238 prologue(adp, V_ADP_STATELOAD, ENODEV);
2239 if (((adp_state_t *)p)->sig != V_STATE_SIG)
2242 buf = ((adp_state_t *)p)->regs;
2243 crtc_addr = adp->va_crtc_addr;
2246 dump_buffer(buf, V_MODE_PARAM_SIZE);
2251 outb(TSIDX, 0x00); outb(TSREG, 0x01); /* stop sequencer */
2252 for (i = 0; i < 4; ++i) { /* program sequencer */
2254 outb(TSREG, buf[i + 5]);
2256 outb(MISC, buf[9]); /* set dot-clock */
2257 outb(TSIDX, 0x00); outb(TSREG, 0x03); /* start sequencer */
2258 outb(crtc_addr, 0x11);
2259 outb(crtc_addr + 1, inb(crtc_addr + 1) & 0x7F);
2260 for (i = 0; i < 25; ++i) { /* program crtc */
2262 outb(crtc_addr + 1, buf[i + 10]);
2264 inb(crtc_addr+6); /* reset flip-flop */
2265 for (i = 0; i < 20; ++i) { /* program attribute ctrl */
2267 outb(ATC, buf[i + 35]);
2269 for (i = 0; i < 9; ++i) { /* program graph data ctrl */
2271 outb(GDCREG, buf[i + 55]);
2273 inb(crtc_addr + 6); /* reset flip-flop */
2274 outb(ATC, 0x20); /* enable palette */
2276 #ifdef notyet /* a temporary workaround for kernel panic, XXX */
2278 if (adp->va_unit == V_ADP_PRIMARY) {
2279 writeb(BIOS_PADDRTOVADDR(0x44a), buf[0]); /* COLS */
2280 writeb(BIOS_PADDRTOVADDR(0x484), buf[1] + rows_offset - 1); /* ROWS */
2281 writeb(BIOS_PADDRTOVADDR(0x485), buf[2]); /* POINTS */
2283 writeb(BIOS_PADDRTOVADDR(0x44c), buf[3]);
2284 writeb(BIOS_PADDRTOVADDR(0x44d), buf[4]);
2287 #endif /* VGA_NO_BIOS */
2296 * Change the origin (window mapping) of the banked frame buffer.
2299 vga_set_origin(video_adapter_t *adp, off_t offset)
2302 * The standard video modes do not require window mapping;
2303 * always return error.
2310 * Read the position of the hardware text cursor.
2315 vga_read_hw_cursor(video_adapter_t *adp, int *col, int *row)
2323 if (adp->va_info.vi_flags & V_INFO_GRAPHICS)
2327 outb(adp->va_crtc_addr, 14);
2328 off = inb(adp->va_crtc_addr + 1);
2329 outb(adp->va_crtc_addr, 15);
2330 off = (off << 8) | inb(adp->va_crtc_addr + 1);
2333 *row = off / adp->va_info.vi_width;
2334 *col = off % adp->va_info.vi_width;
2341 * Move the hardware text cursor. If col and row are both -1,
2342 * the cursor won't be shown.
2347 vga_set_hw_cursor(video_adapter_t *adp, int col, int row)
2355 if ((col == -1) && (row == -1)) {
2358 if (adp->va_info.vi_flags & V_INFO_GRAPHICS)
2360 off = row*adp->va_info.vi_width + col;
2364 outb(adp->va_crtc_addr, 14);
2365 outb(adp->va_crtc_addr + 1, off >> 8);
2366 outb(adp->va_crtc_addr, 15);
2367 outb(adp->va_crtc_addr + 1, off & 0x00ff);
2374 * set_hw_cursor_shape():
2375 * Change the shape of the hardware text cursor. If the height is
2376 * zero or negative, the cursor won't be shown.
2381 vga_set_hw_cursor_shape(video_adapter_t *adp, int base, int height,
2382 int celsize, int blink)
2390 switch (adp->va_type) {
2397 /* make the cursor invisible */
2398 outb(adp->va_crtc_addr, 10);
2399 outb(adp->va_crtc_addr + 1, 32);
2400 outb(adp->va_crtc_addr, 11);
2401 outb(adp->va_crtc_addr + 1, 0);
2403 outb(adp->va_crtc_addr, 10);
2404 outb(adp->va_crtc_addr + 1, celsize - base - height);
2405 outb(adp->va_crtc_addr, 11);
2406 outb(adp->va_crtc_addr + 1, celsize - base - 1);
2411 /* make the cursor invisible */
2412 outb(adp->va_crtc_addr, 10);
2413 outb(adp->va_crtc_addr + 1, celsize);
2414 outb(adp->va_crtc_addr, 11);
2415 outb(adp->va_crtc_addr + 1, 0);
2417 outb(adp->va_crtc_addr, 10);
2418 outb(adp->va_crtc_addr + 1, celsize - base - height);
2419 outb(adp->va_crtc_addr, 11);
2420 outb(adp->va_crtc_addr + 1, celsize - base);
2431 * Put the display in power save/power off mode.
2436 vga_blank_display(video_adapter_t *adp, int mode)
2442 switch (adp->va_type) {
2445 case V_DISPLAY_SUSPEND:
2446 case V_DISPLAY_STAND_BY:
2450 outb(TSREG, val | 0x20);
2451 outb(adp->va_crtc_addr, 0x17);
2452 val = inb(adp->va_crtc_addr + 1);
2453 outb(adp->va_crtc_addr + 1, val & ~0x80);
2455 case V_DISPLAY_BLANK:
2459 outb(TSREG, val | 0x20);
2465 outb(TSREG, val & 0xDF);
2466 outb(adp->va_crtc_addr, 0x17);
2467 val = inb(adp->va_crtc_addr + 1);
2468 outb(adp->va_crtc_addr + 1, val | 0x80);
2474 /* no support yet */
2480 case V_DISPLAY_SUSPEND:
2481 case V_DISPLAY_STAND_BY:
2482 case V_DISPLAY_BLANK:
2483 outb(adp->va_crtc_addr + 4, 0x25);
2486 outb(adp->va_crtc_addr + 4, 0x2d);
2494 case V_DISPLAY_SUSPEND:
2495 case V_DISPLAY_STAND_BY:
2496 case V_DISPLAY_BLANK:
2497 outb(adp->va_crtc_addr + 4, 0x21);
2500 outb(adp->va_crtc_addr + 4, 0x29);
2514 * Mmap frame buffer.
2519 vga_mmap_buf(video_adapter_t *adp, vm_ooffset_t offset, vm_paddr_t *paddr,
2520 int prot, vm_memattr_t *memattr)
2522 if (adp->va_info.vi_flags & V_INFO_LINEAR)
2526 printf("vga_mmap_buf(): window:0x%jx, offset:0x%jx\n",
2527 (uintmax_t)adp->va_info.vi_window, (uintmax_t)offset);
2530 /* XXX: is this correct? */
2531 if (offset > adp->va_window_size - PAGE_SIZE)
2534 *paddr = adp->va_info.vi_window + offset;
2538 #ifndef VGA_NO_MODE_CHANGE
2541 planar_fill(video_adapter_t *adp, int val)
2544 int at; /* position in the frame buffer */
2547 outw(GDCIDX, 0x0005); /* read mode 0, write mode 0 */
2548 outw(GDCIDX, 0x0003); /* data rotate/function select */
2549 outw(GDCIDX, 0x0f01); /* set/reset enable */
2550 outw(GDCIDX, 0xff08); /* bit mask */
2551 outw(GDCIDX, (val << 8) | 0x00); /* set/reset */
2553 length = adp->va_line_width*adp->va_info.vi_height;
2554 while (length > 0) {
2555 l = imin(length, adp->va_window_size);
2556 vidd_set_win_org(adp, at);
2557 bzero_io(adp->va_window, l);
2561 outw(GDCIDX, 0x0000); /* set/reset */
2562 outw(GDCIDX, 0x0001); /* set/reset enable */
2566 packed_fill(video_adapter_t *adp, int val)
2569 int at; /* position in the frame buffer */
2573 length = adp->va_line_width*adp->va_info.vi_height;
2574 while (length > 0) {
2575 l = imin(length, adp->va_window_size);
2576 vidd_set_win_org(adp, at);
2577 fill_io(val, adp->va_window, l);
2584 direct_fill(video_adapter_t *adp, int val)
2587 int at; /* position in the frame buffer */
2591 length = adp->va_line_width*adp->va_info.vi_height;
2592 while (length > 0) {
2593 l = imin(length, adp->va_window_size);
2594 vidd_set_win_org(adp, at);
2595 switch (adp->va_info.vi_pixel_size) {
2596 case sizeof(u_int16_t):
2597 fillw_io(val, adp->va_window, l/sizeof(u_int16_t));
2602 case sizeof(u_int32_t):
2603 filll_io(val, adp->va_window, l/sizeof(u_int32_t));
2612 vga_clear(video_adapter_t *adp)
2614 switch (adp->va_info.vi_mem_model) {
2615 case V_INFO_MM_TEXT:
2616 /* do nothing? XXX */
2618 case V_INFO_MM_PLANAR:
2619 planar_fill(adp, 0);
2621 case V_INFO_MM_PACKED:
2622 packed_fill(adp, 0);
2624 case V_INFO_MM_DIRECT:
2625 direct_fill(adp, 0);
2633 planar_fill_rect(video_adapter_t *adp, int val, int x, int y, int cx, int cy)
2638 int offset; /* offset within window */
2642 outw(GDCIDX, 0x0005); /* read mode 0, write mode 0 */
2643 outw(GDCIDX, 0x0003); /* data rotate/function select */
2644 outw(GDCIDX, 0x0f01); /* set/reset enable */
2645 outw(GDCIDX, 0xff08); /* bit mask */
2646 outw(GDCIDX, (val << 8) | 0x00); /* set/reset */
2648 banksize = adp->va_window_size;
2651 pos = adp->va_line_width*y + x/8;
2652 if (bank != pos/banksize) {
2653 vidd_set_win_org(adp, pos);
2654 bank = pos/banksize;
2656 offset = pos%banksize;
2657 bx = (x + cx)/8 - x/8;
2659 outw(GDCIDX, ((0xff00 >> (x % 8)) & 0xff00) | 0x08);
2660 writeb(adp->va_window + offset, 0);
2663 if (offset >= banksize) {
2665 ++bank; /* next bank */
2666 vidd_set_win_org(adp, bank*banksize);
2668 outw(GDCIDX, 0xff08); /* bit mask */
2671 l = imin(bx, banksize);
2672 bzero_io(adp->va_window + offset, l);
2675 if (offset >= banksize) {
2677 ++bank; /* next bank */
2678 vidd_set_win_org(adp, bank*banksize);
2682 outw(GDCIDX, (~(0xff00 >> ((x + cx) % 8)) & 0xff00) | 0x08);
2683 writeb(adp->va_window + offset, 0);
2685 if (offset >= banksize) {
2687 ++bank; /* next bank */
2688 vidd_set_win_org(adp, bank*banksize);
2690 outw(GDCIDX, 0xff08); /* bit mask */
2696 outw(GDCIDX, 0xff08); /* bit mask */
2697 outw(GDCIDX, 0x0000); /* set/reset */
2698 outw(GDCIDX, 0x0001); /* set/reset enable */
2702 packed_fill_rect(video_adapter_t *adp, int val, int x, int y, int cx, int cy)
2707 int offset; /* offset within window */
2710 banksize = adp->va_window_size;
2712 cx *= adp->va_info.vi_pixel_size;
2714 pos = adp->va_line_width*y + x*adp->va_info.vi_pixel_size;
2715 if (bank != pos/banksize) {
2716 vidd_set_win_org(adp, pos);
2717 bank = pos/banksize;
2719 offset = pos%banksize;
2720 end = imin(offset + cx, banksize);
2721 fill_io(val, adp->va_window + offset,
2722 (end - offset)/adp->va_info.vi_pixel_size);
2723 /* the line may cross the window boundary */
2724 if (offset + cx > banksize) {
2725 ++bank; /* next bank */
2726 vidd_set_win_org(adp, bank*banksize);
2727 end = offset + cx - banksize;
2728 fill_io(val, adp->va_window, end/adp->va_info.vi_pixel_size);
2736 direct_fill_rect16(video_adapter_t *adp, int val, int x, int y, int cx, int cy)
2741 int offset; /* offset within window */
2745 * XXX: the function assumes that banksize is a muliple of
2746 * sizeof(u_int16_t).
2748 banksize = adp->va_window_size;
2750 cx *= sizeof(u_int16_t);
2752 pos = adp->va_line_width*y + x*sizeof(u_int16_t);
2753 if (bank != pos/banksize) {
2754 vidd_set_win_org(adp, pos);
2755 bank = pos/banksize;
2757 offset = pos%banksize;
2758 end = imin(offset + cx, banksize);
2759 fillw_io(val, adp->va_window + offset,
2760 (end - offset)/sizeof(u_int16_t));
2761 /* the line may cross the window boundary */
2762 if (offset + cx > banksize) {
2763 ++bank; /* next bank */
2764 vidd_set_win_org(adp, bank*banksize);
2765 end = offset + cx - banksize;
2766 fillw_io(val, adp->va_window, end/sizeof(u_int16_t));
2774 direct_fill_rect24(video_adapter_t *adp, int val, int x, int y, int cx, int cy)
2779 int offset; /* offset within window */
2785 b[0] = val & 0x0000ff;
2786 b[1] = (val >> 8) & 0x0000ff;
2787 b[2] = (val >> 16) & 0x0000ff;
2788 banksize = adp->va_window_size;
2792 pos = adp->va_line_width*y + x*3;
2793 if (bank != pos/banksize) {
2794 vidd_set_win_org(adp, pos);
2795 bank = pos/banksize;
2797 offset = pos%banksize;
2798 end = imin(offset + cx, banksize);
2799 for (i = 0, j = offset; j < end; i = (++i)%3, ++j) {
2800 writeb(adp->va_window + j, b[i]);
2802 /* the line may cross the window boundary */
2803 if (offset + cx >= banksize) {
2804 ++bank; /* next bank */
2805 vidd_set_win_org(adp, bank*banksize);
2807 end = offset + cx - banksize;
2808 for (; j < end; i = (++i)%3, ++j) {
2809 writeb(adp->va_window + j, b[i]);
2818 direct_fill_rect32(video_adapter_t *adp, int val, int x, int y, int cx, int cy)
2823 int offset; /* offset within window */
2827 * XXX: the function assumes that banksize is a muliple of
2828 * sizeof(u_int32_t).
2830 banksize = adp->va_window_size;
2832 cx *= sizeof(u_int32_t);
2834 pos = adp->va_line_width*y + x*sizeof(u_int32_t);
2835 if (bank != pos/banksize) {
2836 vidd_set_win_org(adp, pos);
2837 bank = pos/banksize;
2839 offset = pos%banksize;
2840 end = imin(offset + cx, banksize);
2841 filll_io(val, adp->va_window + offset,
2842 (end - offset)/sizeof(u_int32_t));
2843 /* the line may cross the window boundary */
2844 if (offset + cx > banksize) {
2845 ++bank; /* next bank */
2846 vidd_set_win_org(adp, bank*banksize);
2847 end = offset + cx - banksize;
2848 filll_io(val, adp->va_window, end/sizeof(u_int32_t));
2856 vga_fill_rect(video_adapter_t *adp, int val, int x, int y, int cx, int cy)
2858 switch (adp->va_info.vi_mem_model) {
2859 case V_INFO_MM_TEXT:
2860 /* do nothing? XXX */
2862 case V_INFO_MM_PLANAR:
2863 planar_fill_rect(adp, val, x, y, cx, cy);
2865 case V_INFO_MM_PACKED:
2866 packed_fill_rect(adp, val, x, y, cx, cy);
2868 case V_INFO_MM_DIRECT:
2869 switch (adp->va_info.vi_pixel_size) {
2870 case sizeof(u_int16_t):
2871 direct_fill_rect16(adp, val, x, y, cx, cy);
2874 direct_fill_rect24(adp, val, x, y, cx, cy);
2876 case sizeof(u_int32_t):
2877 direct_fill_rect32(adp, val, x, y, cx, cy);
2886 vga_fill_rect(video_adapter_t *adp, int val, int x, int y, int cx, int cy)
2893 vga_bitblt(video_adapter_t *adp,...)
2899 #endif /* !VGA_NO_MODE_CHANGE */
2902 get_palette(video_adapter_t *adp, int base, int count,
2903 u_char *red, u_char *green, u_char *blue, u_char *trans)
2909 if (count < 0 || base < 0 || count > 256 || base > 256 ||
2913 r = malloc(count*3, M_DEVBUF, M_WAITOK);
2916 if (vga_save_palette2(adp, base, count, r, g, b)) {
2920 copyout(r, red, count);
2921 copyout(g, green, count);
2922 copyout(b, blue, count);
2923 if (trans != NULL) {
2925 copyout(r, trans, count);
2933 set_palette(video_adapter_t *adp, int base, int count,
2934 u_char *red, u_char *green, u_char *blue, u_char *trans)
2941 if (count < 0 || base < 0 || count > 256 || base > 256 ||
2945 r = malloc(count*3, M_DEVBUF, M_WAITOK);
2948 err = copyin(red, r, count);
2950 err = copyin(green, g, count);
2952 err = copyin(blue, b, count);
2954 err = vga_load_palette2(adp, base, count, r, g, b);
2957 return (err ? ENODEV : 0);
2961 vga_dev_ioctl(video_adapter_t *adp, u_long cmd, caddr_t arg)
2964 case FBIO_GETWINORG: /* get frame buffer window origin */
2968 case FBIO_SETWINORG: /* set frame buffer window origin */
2971 case FBIO_SETDISPSTART: /* set display start address */
2972 return (set_display_start(adp,
2973 ((video_display_start_t *)arg)->x,
2974 ((video_display_start_t *)arg)->y)
2977 case FBIO_SETLINEWIDTH: /* set scan line length in pixel */
2978 return (set_line_length(adp, *(u_int *)arg) ? ENODEV : 0);
2980 case FBIO_GETPALETTE: /* get color palette */
2981 return get_palette(adp, ((video_color_palette_t *)arg)->index,
2982 ((video_color_palette_t *)arg)->count,
2983 ((video_color_palette_t *)arg)->red,
2984 ((video_color_palette_t *)arg)->green,
2985 ((video_color_palette_t *)arg)->blue,
2986 ((video_color_palette_t *)arg)->transparent);
2988 case FBIO_SETPALETTE: /* set color palette */
2989 return set_palette(adp, ((video_color_palette_t *)arg)->index,
2990 ((video_color_palette_t *)arg)->count,
2991 ((video_color_palette_t *)arg)->red,
2992 ((video_color_palette_t *)arg)->green,
2993 ((video_color_palette_t *)arg)->blue,
2994 ((video_color_palette_t *)arg)->transparent);
2996 case FBIOGTYPE: /* get frame buffer type info. */
2997 ((struct fbtype *)arg)->fb_type = fb_type(adp->va_type);
2998 ((struct fbtype *)arg)->fb_height = adp->va_info.vi_height;
2999 ((struct fbtype *)arg)->fb_width = adp->va_info.vi_width;
3000 ((struct fbtype *)arg)->fb_depth = adp->va_info.vi_depth;
3001 if ((adp->va_info.vi_depth <= 1) || (adp->va_info.vi_depth > 8))
3002 ((struct fbtype *)arg)->fb_cmsize = 0;
3004 ((struct fbtype *)arg)->fb_cmsize = 1 << adp->va_info.vi_depth;
3005 ((struct fbtype *)arg)->fb_size = adp->va_buffer_size;
3008 case FBIOGETCMAP: /* get color palette */
3009 return get_palette(adp, ((struct fbcmap *)arg)->index,
3010 ((struct fbcmap *)arg)->count,
3011 ((struct fbcmap *)arg)->red,
3012 ((struct fbcmap *)arg)->green,
3013 ((struct fbcmap *)arg)->blue, NULL);
3015 case FBIOPUTCMAP: /* set color palette */
3016 return set_palette(adp, ((struct fbcmap *)arg)->index,
3017 ((struct fbcmap *)arg)->count,
3018 ((struct fbcmap *)arg)->red,
3019 ((struct fbcmap *)arg)->green,
3020 ((struct fbcmap *)arg)->blue, NULL);
3023 return fb_commonioctl(adp, cmd, arg);
3028 dump_buffer(u_char *buf, size_t len)
3032 for(i = 0; i < len;) {
3033 printf("%02x ", buf[i]);
3034 if ((++i % 16) == 0)
3041 * Print some information about the video adapter and video modes,
3042 * with requested level of details.
3047 vga_diag(video_adapter_t *adp, int level)
3060 printf("vga: RTC equip. code:0x%02x, DCC code:0x%02x\n",
3061 rtcin(RTC_EQUIPMENT), readb(BIOS_PADDRTOVADDR(0x488)));
3062 printf("vga: CRTC:0x%x, video option:0x%02x, ",
3063 readw(BIOS_PADDRTOVADDR(0x463)),
3064 readb(BIOS_PADDRTOVADDR(0x487)));
3065 printf("rows:%d, cols:%d, font height:%d\n",
3066 readb(BIOS_PADDRTOVADDR(0x44a)),
3067 readb(BIOS_PADDRTOVADDR(0x484)) + 1,
3068 readb(BIOS_PADDRTOVADDR(0x485)));
3069 #endif /* VGA_NO_BIOS */
3070 #if !defined(VGA_NO_BIOS) && !defined(VGA_NO_MODE_CHANGE)
3071 printf("vga: param table EGA/VGA:%p", video_mode_ptr);
3072 printf(", CGA/MDA:%p\n", video_mode_ptr2);
3073 printf("vga: rows_offset:%d\n", rows_offset);
3075 #endif /* FB_DEBUG > 1 */
3077 fb_dump_adp_info(VGA_DRIVER_NAME, adp, level);
3080 if (adp->va_flags & V_ADP_MODECHANGE) {
3081 for (i = 0; bios_vmode[i].vi_mode != EOT; ++i) {
3082 if (bios_vmode[i].vi_mode == NA)
3084 if (get_mode_param(bios_vmode[i].vi_mode) == NULL)
3086 fb_dump_mode_info(VGA_DRIVER_NAME, adp, &bios_vmode[i], level);
3089 vga_get_info(adp, adp->va_initial_mode, &info); /* shouldn't fail */
3090 fb_dump_mode_info(VGA_DRIVER_NAME, adp, &info, level);
3092 #endif /* FB_DEBUG > 1 */
3094 if ((adp->va_type != KD_EGA) && (adp->va_type != KD_VGA))
3096 #if !defined(VGA_NO_BIOS) && !defined(VGA_NO_MODE_CHANGE)
3097 if (video_mode_ptr == NULL)
3098 printf("vga%d: %s: WARNING: video mode switching is not "
3099 "fully supported on this adapter\n",
3100 adp->va_unit, adp->va_name);
3105 if (adp->va_type == KD_VGA) {
3106 printf("VGA parameters upon power-up\n");
3107 dump_buffer(adpstate.regs, sizeof(adpstate.regs));
3108 printf("VGA parameters in BIOS for mode %d\n", adp->va_initial_mode);
3109 dump_buffer(adpstate2.regs, sizeof(adpstate2.regs));
3112 mp = get_mode_param(adp->va_initial_mode);
3113 if (mp == NULL) /* this shouldn't be happening */
3115 printf("EGA/VGA parameters to be used for mode %d\n", adp->va_initial_mode);
3116 dump_buffer(mp, V_MODE_PARAM_SIZE);