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;
42 /* Optimistically assume a VESA BIOS is register-clean... */
44 asm("int $0x10" : "+a" (ax), "=m" (vginfo) : "D" (&vginfo));
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... */
68 : "+a" (ax), "=m" (vminfo)
69 : "c" (mode), "D" (&vminfo));
74 if ((vminfo.mode_attr & 0x15) == 0x05) {
75 /* Text Mode, TTY BIOS supported,
76 supported by hardware */
77 mi = GET_HEAP(struct mode_info, 1);
78 mi->mode = mode + VIDEO_FIRST_VESA;
82 } else if ((vminfo.mode_attr & 0x99) == 0x99) {
84 /* Graphics mode, color, linear frame buffer
85 supported -- register the mode but hide from
86 the menu. Only do this if framebuffer is
87 configured, however, otherwise the user will
88 be left without a screen. */
89 mi = GET_HEAP(struct mode_info, 1);
90 mi->mode = mode + VIDEO_FIRST_VESA;
100 #endif /* CONFIG_VIDEO_VESA */
103 static int vesa_set_mode(struct mode_info *mode)
107 u16 vesa_mode = mode->mode - VIDEO_FIRST_VESA;
109 memset(&vminfo, 0, sizeof vminfo); /* Just in case... */
113 : "+a" (ax), "=m" (vminfo)
114 : "c" (vesa_mode), "D" (&vminfo));
119 if ((vminfo.mode_attr & 0x15) == 0x05) {
120 /* It's a supported text mode */
122 } else if ((vminfo.mode_attr & 0x99) == 0x99) {
123 /* It's a graphics mode with linear frame buffer */
125 vesa_mode |= 0x4000; /* Request linear frame buffer */
127 return -1; /* Invalid mode */
132 asm volatile("int $0x10"
134 : "b" (vesa_mode), "D" (0));
139 graphic_mode = is_graphic;
147 vesa_store_mode_params_graphics();
154 /* Switch DAC to 8-bit mode */
155 static void vesa_dac_set_8bits(void)
159 /* If possible, switch the DAC to 8-bit mode */
160 if (vginfo.capabilities & 1) {
166 : "+a" (ax), "+b" (bx)
167 : : "ecx", "edx", "esi", "edi");
173 /* Set the color sizes to the DAC size, and offsets to 0 */
174 boot_params.screen_info.red_size = dac_size;
175 boot_params.screen_info.green_size = dac_size;
176 boot_params.screen_info.blue_size = dac_size;
177 boot_params.screen_info.rsvd_size = dac_size;
179 boot_params.screen_info.red_pos = 0;
180 boot_params.screen_info.green_pos = 0;
181 boot_params.screen_info.blue_pos = 0;
182 boot_params.screen_info.rsvd_pos = 0;
185 /* Save the VESA protected mode info */
186 static void vesa_store_pm_info(void)
192 asm("pushw %%es; "INT10"; movw %%es,%0; popw %%es"
193 : "=d" (es), "+a" (ax), "+b" (bx), "+D" (di)
199 boot_params.screen_info.vesapm_seg = es;
200 boot_params.screen_info.vesapm_off = di;
204 * Save video mode parameters for graphics mode
206 static void vesa_store_mode_params_graphics(void)
208 /* Tell the kernel we're in VESA graphics mode */
209 boot_params.screen_info.orig_video_isVGA = 0x23;
211 /* Mode parameters */
212 boot_params.screen_info.vesa_attributes = vminfo.mode_attr;
213 boot_params.screen_info.lfb_linelength = vminfo.logical_scan;
214 boot_params.screen_info.lfb_width = vminfo.h_res;
215 boot_params.screen_info.lfb_height = vminfo.v_res;
216 boot_params.screen_info.lfb_depth = vminfo.bpp;
217 boot_params.screen_info.pages = vminfo.image_planes;
218 boot_params.screen_info.lfb_base = vminfo.lfb_ptr;
219 memcpy(&boot_params.screen_info.red_size,
222 /* General parameters */
223 boot_params.screen_info.lfb_size = vginfo.total_memory;
226 vesa_dac_set_8bits();
228 vesa_store_pm_info();
232 * Save EDID information for the kernel; this is invoked, separately,
233 * after mode-setting.
235 void vesa_store_edid(void)
237 #ifdef CONFIG_FIRMWARE_EDID
238 u16 ax, bx, cx, dx, di;
240 /* Apparently used as a nonsense token... */
241 memset(&boot_params.edid_info, 0x13, sizeof boot_params.edid_info);
243 if (vginfo.version < 0x0200)
244 return; /* EDID requires VBE 2.0+ */
246 ax = 0x4f15; /* VBE DDC */
247 bx = 0x0000; /* Report DDC capabilities */
248 cx = 0; /* Controller 0 */
249 di = 0; /* ES:DI must be 0 by spec */
251 /* Note: The VBE DDC spec is different from the main VESA spec;
252 we genuinely have to assume all registers are destroyed here. */
254 asm("pushw %%es; movw %2,%%es; "INT10"; popw %%es"
255 : "+a" (ax), "+b" (bx)
260 return; /* No EDID */
262 /* BH = time in seconds to transfer EDD information */
263 /* BL = DDC level supported */
265 ax = 0x4f15; /* VBE DDC */
266 bx = 0x0001; /* Read EDID */
267 cx = 0; /* Controller 0 */
268 dx = 0; /* EDID block number */
269 di =(size_t) &boot_params.edid_info; /* (ES:)Pointer to block */
271 : "+a" (ax), "+b" (bx), "+d" (dx)
274 #endif /* CONFIG_FIRMWARE_EDID */
277 __videocard video_vesa =
281 .set_mode = vesa_set_mode,
282 .xmode_first = VIDEO_FIRST_VESA,