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;
28 static void vesa_store_mode_params_graphics(void);
30 static inline void vesa_store_mode_params_graphics(void) {}
33 static int vesa_probe(void)
35 #if defined(CONFIG_VIDEO_VESA) || defined(CONFIG_FIRMWARE_EDID)
42 video_vesa.modes = GET_HEAP(struct mode_info, 0);
47 : "+a" (ax), "+D" (di), "=m" (vginfo)
48 : : "ebx", "ecx", "edx", "esi");
51 vginfo.signature != VESA_MAGIC ||
52 vginfo.version < 0x0102)
53 return 0; /* Not present */
54 #endif /* CONFIG_VIDEO_VESA || CONFIG_FIRMWARE_EDID */
55 #ifdef CONFIG_VIDEO_VESA
56 set_fs(vginfo.video_mode_ptr.seg);
57 mode_ptr = vginfo.video_mode_ptr.off;
59 while ((mode = rdfs16(mode_ptr)) != 0xffff) {
62 if (!heap_free(sizeof(struct mode_info)))
63 break; /* Heap full, can't save mode info */
68 memset(&vminfo, 0, sizeof vminfo); /* Just in case... */
74 : "+a" (ax), "+c" (cx), "+D" (di), "=m" (vminfo)
75 : : "ebx", "edx", "esi");
80 if ((vminfo.mode_attr & 0x15) == 0x05) {
81 /* Text Mode, TTY BIOS supported,
82 supported by hardware */
83 mi = GET_HEAP(struct mode_info, 1);
84 mi->mode = mode + VIDEO_FIRST_VESA;
85 mi->depth = 0; /* text */
89 } else if ((vminfo.mode_attr & 0x99) == 0x99 &&
90 (vminfo.memory_layout == 4 ||
91 vminfo.memory_layout == 6) &&
92 vminfo.memory_planes == 1) {
94 /* Graphics mode, color, linear frame buffer
95 supported. Only register the mode if
96 if framebuffer is configured, however,
97 otherwise the user will be left without a screen.
98 We don't require CONFIG_FB_VESA, however, since
99 some of the other framebuffer drivers can use
100 this mode-setting, too. */
101 mi = GET_HEAP(struct mode_info, 1);
102 mi->mode = mode + VIDEO_FIRST_VESA;
103 mi->depth = vminfo.bpp;
104 mi->x = vminfo.h_res;
105 mi->y = vminfo.v_res;
114 #endif /* CONFIG_VIDEO_VESA */
117 static int vesa_set_mode(struct mode_info *mode)
121 u16 vesa_mode = mode->mode - VIDEO_FIRST_VESA;
123 memset(&vminfo, 0, sizeof vminfo); /* Just in case... */
127 di = (size_t)&vminfo;
129 : "+a" (ax), "+c" (cx), "+D" (di), "=m" (vminfo)
130 : : "ebx", "edx", "esi");
135 if ((vminfo.mode_attr & 0x15) == 0x05) {
136 /* It's a supported text mode */
138 } else if ((vminfo.mode_attr & 0x99) == 0x99) {
139 /* It's a graphics mode with linear frame buffer */
141 vesa_mode |= 0x4000; /* Request linear frame buffer */
143 return -1; /* Invalid mode */
151 : "+a" (ax), "+b" (bx), "+D" (di)
152 : : "ecx", "edx", "esi");
157 graphic_mode = is_graphic;
165 vesa_store_mode_params_graphics();
174 /* Switch DAC to 8-bit mode */
175 static void vesa_dac_set_8bits(void)
179 /* If possible, switch the DAC to 8-bit mode */
180 if (vginfo.capabilities & 1) {
186 : "+a" (ax), "+b" (bx)
187 : : "ecx", "edx", "esi", "edi");
193 /* Set the color sizes to the DAC size, and offsets to 0 */
194 boot_params.screen_info.red_size = dac_size;
195 boot_params.screen_info.green_size = dac_size;
196 boot_params.screen_info.blue_size = dac_size;
197 boot_params.screen_info.rsvd_size = dac_size;
199 boot_params.screen_info.red_pos = 0;
200 boot_params.screen_info.green_pos = 0;
201 boot_params.screen_info.blue_pos = 0;
202 boot_params.screen_info.rsvd_pos = 0;
205 /* Save the VESA protected mode info */
206 static void vesa_store_pm_info(void)
212 asm("pushw %%es; "INT10"; movw %%es,%0; popw %%es"
213 : "=d" (es), "+a" (ax), "+b" (bx), "+D" (di)
219 boot_params.screen_info.vesapm_seg = es;
220 boot_params.screen_info.vesapm_off = di;
224 * Save video mode parameters for graphics mode
226 static void vesa_store_mode_params_graphics(void)
228 /* Tell the kernel we're in VESA graphics mode */
229 boot_params.screen_info.orig_video_isVGA = 0x23;
231 /* Mode parameters */
232 boot_params.screen_info.vesa_attributes = vminfo.mode_attr;
233 boot_params.screen_info.lfb_linelength = vminfo.logical_scan;
234 boot_params.screen_info.lfb_width = vminfo.h_res;
235 boot_params.screen_info.lfb_height = vminfo.v_res;
236 boot_params.screen_info.lfb_depth = vminfo.bpp;
237 boot_params.screen_info.pages = vminfo.image_planes;
238 boot_params.screen_info.lfb_base = vminfo.lfb_ptr;
239 memcpy(&boot_params.screen_info.red_size,
242 /* General parameters */
243 boot_params.screen_info.lfb_size = vginfo.total_memory;
246 vesa_dac_set_8bits();
248 vesa_store_pm_info();
252 * Save EDID information for the kernel; this is invoked, separately,
253 * after mode-setting.
255 void vesa_store_edid(void)
257 #ifdef CONFIG_FIRMWARE_EDID
258 u16 ax, bx, cx, dx, di;
260 /* Apparently used as a nonsense token... */
261 memset(&boot_params.edid_info, 0x13, sizeof boot_params.edid_info);
263 if (vginfo.version < 0x0200)
264 return; /* EDID requires VBE 2.0+ */
266 ax = 0x4f15; /* VBE DDC */
267 bx = 0x0000; /* Report DDC capabilities */
268 cx = 0; /* Controller 0 */
269 di = 0; /* ES:DI must be 0 by spec */
271 /* Note: The VBE DDC spec is different from the main VESA spec;
272 we genuinely have to assume all registers are destroyed here. */
274 asm("pushw %%es; movw %2,%%es; "INT10"; popw %%es"
275 : "+a" (ax), "+b" (bx)
280 return; /* No EDID */
282 /* BH = time in seconds to transfer EDD information */
283 /* BL = DDC level supported */
285 ax = 0x4f15; /* VBE DDC */
286 bx = 0x0001; /* Read EDID */
287 cx = 0; /* Controller 0 */
288 dx = 0; /* EDID block number */
289 di =(size_t) &boot_params.edid_info; /* (ES:)Pointer to block */
291 : "+a" (ax), "+b" (bx), "+d" (dx), "=m" (boot_params.edid_info)
294 #endif /* CONFIG_FIRMWARE_EDID */
297 #endif /* not _WAKEUP */
299 __videocard video_vesa =
303 .set_mode = vesa_set_mode,
304 .xmode_first = VIDEO_FIRST_VESA,