1 /* -*- linux-c -*- ------------------------------------------------------- *
3 * Copyright (C) 1991, 1992 Linus Torvalds
4 * Copyright 2007-2008 rPath, Inc. - All Rights Reserved
6 * This file is part of the Linux kernel, and is made available under
7 * the terms of the GNU General Public License version 2.
9 * ----------------------------------------------------------------------- */
12 * arch/i386/boot/video-mode.c
14 * Set the video mode. This is separated out into a different
15 * file in order to be shared with the ACPI wakeup code.
25 int adapter
; /* 0=CGA/MDA/HGC, 1=EGA, 2=VGA+ */
26 int force_x
, force_y
; /* Don't query the BIOS for cols/rows */
27 int do_restore
; /* Screen contents changed during mode flip */
28 int graphic_mode
; /* Graphic mode with linear frame buffer */
30 /* Probe the video drivers and have them generate their mode lists. */
31 void probe_cards(int unsafe
)
33 struct card_info
*card
;
41 for (card
= video_cards
; card
< video_cards_end
; card
++) {
42 if (card
->unsafe
== unsafe
) {
44 card
->nmodes
= card
->probe();
51 /* Test if a mode is defined */
52 int mode_defined(u16 mode
)
54 struct card_info
*card
;
58 for (card
= video_cards
; card
< video_cards_end
; card
++) {
60 for (i
= 0; i
< card
->nmodes
; i
++, mi
++) {
69 /* Set mode (without recalc) */
70 static int raw_set_mode(u16 mode
, u16
*real_mode
)
73 struct card_info
*card
;
76 /* Drop the recalc bit if set */
77 mode
&= ~VIDEO_RECALC
;
79 /* Scan for mode based on fixed ID, position, or resolution */
81 for (card
= video_cards
; card
< video_cards_end
; card
++) {
83 for (i
= 0; i
< card
->nmodes
; i
++, mi
++) {
84 int visible
= mi
->x
|| mi
->y
;
86 if ((mode
== nmode
&& visible
) ||
88 mode
== (mi
->y
<< 8)+mi
->x
) {
89 *real_mode
= mi
->mode
;
90 return card
->set_mode(mi
);
98 /* Nothing found? Is it an "exceptional" (unprobed) mode? */
99 for (card
= video_cards
; card
< video_cards_end
; card
++) {
100 if (mode
>= card
->xmode_first
&&
101 mode
< card
->xmode_first
+card
->xmode_n
) {
102 struct mode_info mix
;
103 *real_mode
= mix
.mode
= mode
;
105 return card
->set_mode(&mix
);
109 /* Otherwise, failure... */
114 * Recalculate the vertical video cutoff (hack!)
116 static void vga_recalc_vertical(void)
118 unsigned int font_size
, rows
;
123 font_size
= rdfs8(0x485); /* BIOS: font size (pixels) */
124 rows
= force_y
? force_y
: rdfs8(0x484)+1; /* Text rows */
126 rows
*= font_size
; /* Visible scan lines */
127 rows
--; /* ... minus one */
131 pt
= in_idx(crtc
, 0x11);
132 pt
&= ~0x80; /* Unlock CR0-7 */
133 out_idx(pt
, crtc
, 0x11);
135 out_idx((u8
)rows
, crtc
, 0x12); /* Lower height register */
137 ov
= in_idx(crtc
, 0x07); /* Overflow register */
139 ov
|= (rows
>> (8-1)) & 0x02;
140 ov
|= (rows
>> (9-6)) & 0x40;
141 out_idx(ov
, crtc
, 0x07);
144 /* Set mode (with recalc if specified) */
145 int set_mode(u16 mode
)
150 /* Very special mode numbers... */
151 if (mode
== VIDEO_CURRENT_MODE
)
152 return 0; /* Nothing to do... */
153 else if (mode
== NORMAL_VGA
)
155 else if (mode
== EXTENDED_VGA
)
158 rv
= raw_set_mode(mode
, &real_mode
);
162 if (mode
& VIDEO_RECALC
)
163 vga_recalc_vertical();
165 /* Save the canonical mode number for the kernel, not
166 an alias, size specification or menu position */
168 boot_params
.hdr
.vid_mode
= real_mode
;