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
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)
38 video_vesa.modes = GET_HEAP(struct mode_info, 0);
40 vginfo.signature = VBE2_MAGIC;
45 : "+a" (ax), "+D" (di), "=m" (vginfo)
46 : : "ebx", "ecx", "edx", "esi");
49 vginfo.signature != VESA_MAGIC ||
50 vginfo.version < 0x0102)
51 return 0; /* Not present */
52 #endif /* CONFIG_VIDEO_VESA || CONFIG_FIRMWARE_EDID */
53 #ifdef CONFIG_VIDEO_VESA
54 set_fs(vginfo.video_mode_ptr.seg);
55 mode_ptr = vginfo.video_mode_ptr.off;
57 while ((mode = rdfs16(mode_ptr)) != 0xffff) {
60 if (heap_free() < sizeof(struct mode_info))
61 break; /* Heap full, can't save mode info */
66 memset(&vminfo, 0, sizeof vminfo); /* Just in case... */
72 : "+a" (ax), "+c" (cx), "+D" (di), "=m" (vminfo)
73 : : "ebx", "edx", "esi");
78 if ((vminfo.mode_attr & 0x15) == 0x05) {
79 /* Text Mode, TTY BIOS supported,
80 supported by hardware */
81 mi = GET_HEAP(struct mode_info, 1);
82 mi->mode = mode + VIDEO_FIRST_VESA;
86 } else if ((vminfo.mode_attr & 0x99) == 0x99) {
88 /* Graphics mode, color, linear frame buffer
89 supported -- register the mode but hide from
90 the menu. Only do this if framebuffer is
91 configured, however, otherwise the user will
92 be left without a screen. */
93 mi = GET_HEAP(struct mode_info, 1);
94 mi->mode = mode + VIDEO_FIRST_VESA;
104 #endif /* CONFIG_VIDEO_VESA */
107 static int vesa_set_mode(struct mode_info *mode)
111 u16 vesa_mode = mode->mode - VIDEO_FIRST_VESA;
113 memset(&vminfo, 0, sizeof vminfo); /* Just in case... */
117 di = (size_t)&vminfo;
119 : "+a" (ax), "+c" (cx), "+D" (di), "=m" (vminfo)
120 : : "ebx", "edx", "esi");
125 if ((vminfo.mode_attr & 0x15) == 0x05) {
126 /* It's a supported text mode */
128 } else if ((vminfo.mode_attr & 0x99) == 0x99) {
129 /* It's a graphics mode with linear frame buffer */
131 vesa_mode |= 0x4000; /* Request linear frame buffer */
133 return -1; /* Invalid mode */
141 : "+a" (ax), "+b" (bx), "+D" (di)
142 : : "ecx", "edx", "esi");
147 graphic_mode = is_graphic;
155 vesa_store_mode_params_graphics();
162 /* Switch DAC to 8-bit mode */
163 static void vesa_dac_set_8bits(void)
167 /* If possible, switch the DAC to 8-bit mode */
168 if (vginfo.capabilities & 1) {
174 : "+a" (ax), "+b" (bx)
175 : : "ecx", "edx", "esi", "edi");
181 /* Set the color sizes to the DAC size, and offsets to 0 */
182 boot_params.screen_info.red_size = dac_size;
183 boot_params.screen_info.green_size = dac_size;
184 boot_params.screen_info.blue_size = dac_size;
185 boot_params.screen_info.rsvd_size = dac_size;
187 boot_params.screen_info.red_pos = 0;
188 boot_params.screen_info.green_pos = 0;
189 boot_params.screen_info.blue_pos = 0;
190 boot_params.screen_info.rsvd_pos = 0;
193 /* Save the VESA protected mode info */
194 static void vesa_store_pm_info(void)
200 asm("pushw %%es; "INT10"; movw %%es,%0; popw %%es"
201 : "=d" (es), "+a" (ax), "+b" (bx), "+D" (di)
207 boot_params.screen_info.vesapm_seg = es;
208 boot_params.screen_info.vesapm_off = di;
212 * Save video mode parameters for graphics mode
214 static void vesa_store_mode_params_graphics(void)
216 /* Tell the kernel we're in VESA graphics mode */
217 boot_params.screen_info.orig_video_isVGA = 0x23;
219 /* Mode parameters */
220 boot_params.screen_info.vesa_attributes = vminfo.mode_attr;
221 boot_params.screen_info.lfb_linelength = vminfo.logical_scan;
222 boot_params.screen_info.lfb_width = vminfo.h_res;
223 boot_params.screen_info.lfb_height = vminfo.v_res;
224 boot_params.screen_info.lfb_depth = vminfo.bpp;
225 boot_params.screen_info.pages = vminfo.image_planes;
226 boot_params.screen_info.lfb_base = vminfo.lfb_ptr;
227 memcpy(&boot_params.screen_info.red_size,
230 /* General parameters */
231 boot_params.screen_info.lfb_size = vginfo.total_memory;
234 vesa_dac_set_8bits();
236 vesa_store_pm_info();
240 * Save EDID information for the kernel; this is invoked, separately,
241 * after mode-setting.
243 void vesa_store_edid(void)
245 #ifdef CONFIG_FIRMWARE_EDID
246 u16 ax, bx, cx, dx, di;
248 /* Apparently used as a nonsense token... */
249 memset(&boot_params.edid_info, 0x13, sizeof boot_params.edid_info);
251 if (vginfo.version < 0x0200)
252 return; /* EDID requires VBE 2.0+ */
254 ax = 0x4f15; /* VBE DDC */
255 bx = 0x0000; /* Report DDC capabilities */
256 cx = 0; /* Controller 0 */
257 di = 0; /* ES:DI must be 0 by spec */
259 /* Note: The VBE DDC spec is different from the main VESA spec;
260 we genuinely have to assume all registers are destroyed here. */
262 asm("pushw %%es; movw %2,%%es; "INT10"; popw %%es"
263 : "+a" (ax), "+b" (bx)
268 return; /* No EDID */
270 /* BH = time in seconds to transfer EDD information */
271 /* BL = DDC level supported */
273 ax = 0x4f15; /* VBE DDC */
274 bx = 0x0001; /* Read EDID */
275 cx = 0; /* Controller 0 */
276 dx = 0; /* EDID block number */
277 di =(size_t) &boot_params.edid_info; /* (ES:)Pointer to block */
279 : "+a" (ax), "+b" (bx), "+d" (dx), "=m" (boot_params.edid_info)
282 #endif /* CONFIG_FIRMWARE_EDID */
285 __videocard video_vesa =
289 .set_mode = vesa_set_mode,
290 .xmode_first = VIDEO_FIRST_VESA,