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.
22 #include <uapi/asm/boot.h>
27 int adapter
; /* 0=CGA/MDA/HGC, 1=EGA, 2=VGA+ */
28 int force_x
, force_y
; /* Don't query the BIOS for cols/rows */
29 int do_restore
; /* Screen contents changed during mode flip */
30 int graphic_mode
; /* Graphic mode with linear frame buffer */
32 /* Probe the video drivers and have them generate their mode lists. */
33 void probe_cards(int unsafe
)
35 struct card_info
*card
;
43 for (card
= video_cards
; card
< video_cards_end
; card
++) {
44 if (card
->unsafe
== unsafe
) {
46 card
->nmodes
= card
->probe();
53 /* Test if a mode is defined */
54 int mode_defined(u16 mode
)
56 struct card_info
*card
;
60 for (card
= video_cards
; card
< video_cards_end
; card
++) {
62 for (i
= 0; i
< card
->nmodes
; i
++, mi
++) {
71 /* Set mode (without recalc) */
72 static int raw_set_mode(u16 mode
, u16
*real_mode
)
75 struct card_info
*card
;
78 /* Drop the recalc bit if set */
79 mode
&= ~VIDEO_RECALC
;
81 /* Scan for mode based on fixed ID, position, or resolution */
83 for (card
= video_cards
; card
< video_cards_end
; card
++) {
85 for (i
= 0; i
< card
->nmodes
; i
++, mi
++) {
86 int visible
= mi
->x
|| mi
->y
;
88 if ((mode
== nmode
&& visible
) ||
90 mode
== (mi
->y
<< 8)+mi
->x
) {
91 *real_mode
= mi
->mode
;
92 return card
->set_mode(mi
);
100 /* Nothing found? Is it an "exceptional" (unprobed) mode? */
101 for (card
= video_cards
; card
< video_cards_end
; card
++) {
102 if (mode
>= card
->xmode_first
&&
103 mode
< card
->xmode_first
+card
->xmode_n
) {
104 struct mode_info mix
;
105 *real_mode
= mix
.mode
= mode
;
107 return card
->set_mode(&mix
);
111 /* Otherwise, failure... */
116 * Recalculate the vertical video cutoff (hack!)
118 static void vga_recalc_vertical(void)
120 unsigned int font_size
, rows
;
125 font_size
= rdfs8(0x485); /* BIOS: font size (pixels) */
126 rows
= force_y
? force_y
: rdfs8(0x484)+1; /* Text rows */
128 rows
*= font_size
; /* Visible scan lines */
129 rows
--; /* ... minus one */
133 pt
= in_idx(crtc
, 0x11);
134 pt
&= ~0x80; /* Unlock CR0-7 */
135 out_idx(pt
, crtc
, 0x11);
137 out_idx((u8
)rows
, crtc
, 0x12); /* Lower height register */
139 ov
= in_idx(crtc
, 0x07); /* Overflow register */
141 ov
|= (rows
>> (8-1)) & 0x02;
142 ov
|= (rows
>> (9-6)) & 0x40;
143 out_idx(ov
, crtc
, 0x07);
146 /* Set mode (with recalc if specified) */
147 int set_mode(u16 mode
)
152 /* Very special mode numbers... */
153 if (mode
== VIDEO_CURRENT_MODE
)
154 return 0; /* Nothing to do... */
155 else if (mode
== NORMAL_VGA
)
157 else if (mode
== EXTENDED_VGA
)
160 rv
= raw_set_mode(mode
, &real_mode
);
164 if (mode
& VIDEO_RECALC
)
165 vga_recalc_vertical();
167 /* Save the canonical mode number for the kernel, not
168 an alias, size specification or menu position */
170 boot_params
.hdr
.vid_mode
= real_mode
;