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);
43 : "+a" (ax), "+D" (di), "=m" (vginfo)
44 : : "ebx", "ecx", "edx", "esi");
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) {
58 if (!heap_free(sizeof(struct mode_info)))
59 break; /* Heap full, can't save mode info */
64 memset(&vminfo, 0, sizeof vminfo); /* Just in case... */
70 : "+a" (ax), "+c" (cx), "+D" (di), "=m" (vminfo)
71 : : "ebx", "edx", "esi");
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 */
85 } else if ((vminfo.mode_attr & 0x99) == 0x99 &&
86 (vminfo.memory_layout == 4 ||
87 vminfo.memory_layout == 6) &&
88 vminfo.memory_planes == 1) {
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;
110 #endif /* CONFIG_VIDEO_VESA */
113 static int vesa_set_mode(struct mode_info *mode)
117 u16 vesa_mode = mode->mode - VIDEO_FIRST_VESA;
119 memset(&vminfo, 0, sizeof vminfo); /* Just in case... */
123 di = (size_t)&vminfo;
125 : "+a" (ax), "+c" (cx), "+D" (di), "=m" (vminfo)
126 : : "ebx", "edx", "esi");
131 if ((vminfo.mode_attr & 0x15) == 0x05) {
132 /* It's a supported text mode */
134 } else if ((vminfo.mode_attr & 0x99) == 0x99) {
135 /* It's a graphics mode with linear frame buffer */
137 vesa_mode |= 0x4000; /* Request linear frame buffer */
139 return -1; /* Invalid mode */
147 : "+a" (ax), "+b" (bx), "+D" (di)
148 : : "ecx", "edx", "esi");
153 graphic_mode = is_graphic;
161 vesa_store_mode_params_graphics();
168 /* Switch DAC to 8-bit mode */
169 static void vesa_dac_set_8bits(void)
173 /* If possible, switch the DAC to 8-bit mode */
174 if (vginfo.capabilities & 1) {
180 : "+a" (ax), "+b" (bx)
181 : : "ecx", "edx", "esi", "edi");
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)
206 asm("pushw %%es; "INT10"; movw %%es,%0; popw %%es"
207 : "=d" (es), "+a" (ax), "+b" (bx), "+D" (di)
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,
236 /* General parameters */
237 boot_params.screen_info.lfb_size = vginfo.total_memory;
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)
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 */
285 : "+a" (ax), "+b" (bx), "+d" (dx), "=m" (boot_params.edid_info)
288 #endif /* CONFIG_FIRMWARE_EDID */
291 __videocard video_vesa =
295 .set_mode = vesa_set_mode,
296 .xmode_first = VIDEO_FIRST_VESA,