x86-boot: don't request VBE2 information
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / arch / x86 / boot / video-vesa.c
blob419b5c27337463b59ffc6bf5ae545c25c8aaafbc
1 /* -*- linux-c -*- ------------------------------------------------------- *
3 * Copyright (C) 1991, 1992 Linus Torvalds
4 * Copyright 2007 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-vesa.c
14 * VESA text modes
17 #include "boot.h"
18 #include "video.h"
19 #include "vesa.h"
21 /* VESA information */
22 static struct vesa_general_info vginfo;
23 static struct vesa_mode_info vminfo;
25 __videocard video_vesa;
27 static void vesa_store_mode_params_graphics(void);
29 static int vesa_probe(void)
31 #if defined(CONFIG_VIDEO_VESA) || defined(CONFIG_FIRMWARE_EDID)
32 u16 ax, cx, di;
33 u16 mode;
34 addr_t mode_ptr;
35 struct mode_info *mi;
36 int nmodes = 0;
38 video_vesa.modes = GET_HEAP(struct mode_info, 0);
40 ax = 0x4f00;
41 di = (size_t)&vginfo;
42 asm(INT10
43 : "+a" (ax), "+D" (di), "=m" (vginfo)
44 : : "ebx", "ecx", "edx", "esi");
46 if (ax != 0x004f ||
47 vginfo.signature != VESA_MAGIC ||
48 vginfo.version < 0x0102)
49 return 0; /* Not present */
50 #endif /* CONFIG_VIDEO_VESA || CONFIG_FIRMWARE_EDID */
51 #ifdef CONFIG_VIDEO_VESA
52 set_fs(vginfo.video_mode_ptr.seg);
53 mode_ptr = vginfo.video_mode_ptr.off;
55 while ((mode = rdfs16(mode_ptr)) != 0xffff) {
56 mode_ptr += 2;
58 if (!heap_free(sizeof(struct mode_info)))
59 break; /* Heap full, can't save mode info */
61 if (mode & ~0x1ff)
62 continue;
64 memset(&vminfo, 0, sizeof vminfo); /* Just in case... */
66 ax = 0x4f01;
67 cx = mode;
68 di = (size_t)&vminfo;
69 asm(INT10
70 : "+a" (ax), "+c" (cx), "+D" (di), "=m" (vminfo)
71 : : "ebx", "edx", "esi");
73 if (ax != 0x004f)
74 continue;
76 if ((vminfo.mode_attr & 0x15) == 0x05) {
77 /* Text Mode, TTY BIOS supported,
78 supported by hardware */
79 mi = GET_HEAP(struct mode_info, 1);
80 mi->mode = mode + VIDEO_FIRST_VESA;
81 mi->depth = 0; /* text */
82 mi->x = vminfo.h_res;
83 mi->y = vminfo.v_res;
84 nmodes++;
85 } else if ((vminfo.mode_attr & 0x99) == 0x99 &&
86 (vminfo.memory_layout == 4 ||
87 vminfo.memory_layout == 6) &&
88 vminfo.memory_planes == 1) {
89 #ifdef CONFIG_FB
90 /* Graphics mode, color, linear frame buffer
91 supported. Only register the mode if
92 if framebuffer is configured, however,
93 otherwise the user will be left without a screen.
94 We don't require CONFIG_FB_VESA, however, since
95 some of the other framebuffer drivers can use
96 this mode-setting, too. */
97 mi = GET_HEAP(struct mode_info, 1);
98 mi->mode = mode + VIDEO_FIRST_VESA;
99 mi->depth = vminfo.bpp;
100 mi->x = vminfo.h_res;
101 mi->y = vminfo.v_res;
102 nmodes++;
103 #endif
107 return nmodes;
108 #else
109 return 0;
110 #endif /* CONFIG_VIDEO_VESA */
113 static int vesa_set_mode(struct mode_info *mode)
115 u16 ax, bx, cx, di;
116 int is_graphic;
117 u16 vesa_mode = mode->mode - VIDEO_FIRST_VESA;
119 memset(&vminfo, 0, sizeof vminfo); /* Just in case... */
121 ax = 0x4f01;
122 cx = vesa_mode;
123 di = (size_t)&vminfo;
124 asm(INT10
125 : "+a" (ax), "+c" (cx), "+D" (di), "=m" (vminfo)
126 : : "ebx", "edx", "esi");
128 if (ax != 0x004f)
129 return -1;
131 if ((vminfo.mode_attr & 0x15) == 0x05) {
132 /* It's a supported text mode */
133 is_graphic = 0;
134 } else if ((vminfo.mode_attr & 0x99) == 0x99) {
135 /* It's a graphics mode with linear frame buffer */
136 is_graphic = 1;
137 vesa_mode |= 0x4000; /* Request linear frame buffer */
138 } else {
139 return -1; /* Invalid mode */
143 ax = 0x4f02;
144 bx = vesa_mode;
145 di = 0;
146 asm volatile(INT10
147 : "+a" (ax), "+b" (bx), "+D" (di)
148 : : "ecx", "edx", "esi");
150 if (ax != 0x004f)
151 return -1;
153 graphic_mode = is_graphic;
154 if (!is_graphic) {
155 /* Text mode */
156 force_x = mode->x;
157 force_y = mode->y;
158 do_restore = 1;
159 } else {
160 /* Graphics mode */
161 vesa_store_mode_params_graphics();
164 return 0;
168 /* Switch DAC to 8-bit mode */
169 static void vesa_dac_set_8bits(void)
171 u8 dac_size = 6;
173 /* If possible, switch the DAC to 8-bit mode */
174 if (vginfo.capabilities & 1) {
175 u16 ax, bx;
177 ax = 0x4f08;
178 bx = 0x0800;
179 asm volatile(INT10
180 : "+a" (ax), "+b" (bx)
181 : : "ecx", "edx", "esi", "edi");
183 if (ax == 0x004f)
184 dac_size = bx >> 8;
187 /* Set the color sizes to the DAC size, and offsets to 0 */
188 boot_params.screen_info.red_size = dac_size;
189 boot_params.screen_info.green_size = dac_size;
190 boot_params.screen_info.blue_size = dac_size;
191 boot_params.screen_info.rsvd_size = dac_size;
193 boot_params.screen_info.red_pos = 0;
194 boot_params.screen_info.green_pos = 0;
195 boot_params.screen_info.blue_pos = 0;
196 boot_params.screen_info.rsvd_pos = 0;
199 /* Save the VESA protected mode info */
200 static void vesa_store_pm_info(void)
202 u16 ax, bx, di, es;
204 ax = 0x4f0a;
205 bx = di = 0;
206 asm("pushw %%es; "INT10"; movw %%es,%0; popw %%es"
207 : "=d" (es), "+a" (ax), "+b" (bx), "+D" (di)
208 : : "ecx", "esi");
210 if (ax != 0x004f)
211 return;
213 boot_params.screen_info.vesapm_seg = es;
214 boot_params.screen_info.vesapm_off = di;
218 * Save video mode parameters for graphics mode
220 static void vesa_store_mode_params_graphics(void)
222 /* Tell the kernel we're in VESA graphics mode */
223 boot_params.screen_info.orig_video_isVGA = 0x23;
225 /* Mode parameters */
226 boot_params.screen_info.vesa_attributes = vminfo.mode_attr;
227 boot_params.screen_info.lfb_linelength = vminfo.logical_scan;
228 boot_params.screen_info.lfb_width = vminfo.h_res;
229 boot_params.screen_info.lfb_height = vminfo.v_res;
230 boot_params.screen_info.lfb_depth = vminfo.bpp;
231 boot_params.screen_info.pages = vminfo.image_planes;
232 boot_params.screen_info.lfb_base = vminfo.lfb_ptr;
233 memcpy(&boot_params.screen_info.red_size,
234 &vminfo.rmask, 8);
236 /* General parameters */
237 boot_params.screen_info.lfb_size = vginfo.total_memory;
239 if (vminfo.bpp <= 8)
240 vesa_dac_set_8bits();
242 vesa_store_pm_info();
246 * Save EDID information for the kernel; this is invoked, separately,
247 * after mode-setting.
249 void vesa_store_edid(void)
251 #ifdef CONFIG_FIRMWARE_EDID
252 u16 ax, bx, cx, dx, di;
254 /* Apparently used as a nonsense token... */
255 memset(&boot_params.edid_info, 0x13, sizeof boot_params.edid_info);
257 if (vginfo.version < 0x0200)
258 return; /* EDID requires VBE 2.0+ */
260 ax = 0x4f15; /* VBE DDC */
261 bx = 0x0000; /* Report DDC capabilities */
262 cx = 0; /* Controller 0 */
263 di = 0; /* ES:DI must be 0 by spec */
265 /* Note: The VBE DDC spec is different from the main VESA spec;
266 we genuinely have to assume all registers are destroyed here. */
268 asm("pushw %%es; movw %2,%%es; "INT10"; popw %%es"
269 : "+a" (ax), "+b" (bx)
270 : "c" (cx), "D" (di)
271 : "esi");
273 if (ax != 0x004f)
274 return; /* No EDID */
276 /* BH = time in seconds to transfer EDD information */
277 /* BL = DDC level supported */
279 ax = 0x4f15; /* VBE DDC */
280 bx = 0x0001; /* Read EDID */
281 cx = 0; /* Controller 0 */
282 dx = 0; /* EDID block number */
283 di =(size_t) &boot_params.edid_info; /* (ES:)Pointer to block */
284 asm(INT10
285 : "+a" (ax), "+b" (bx), "+d" (dx), "=m" (boot_params.edid_info)
286 : "c" (cx), "D" (di)
287 : "esi");
288 #endif /* CONFIG_FIRMWARE_EDID */
291 __videocard video_vesa =
293 .card_name = "VESA",
294 .probe = vesa_probe,
295 .set_mode = vesa_set_mode,
296 .xmode_first = VIDEO_FIRST_VESA,
297 .xmode_n = 0x200,