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 * ----------------------------------------------------------------------- */
19 /* VESA information */
20 static struct vesa_general_info vginfo
;
21 static struct vesa_mode_info vminfo
;
23 static __videocard video_vesa
;
26 static void vesa_store_mode_params_graphics(void);
28 static inline void vesa_store_mode_params_graphics(void) {}
31 static int vesa_probe(void)
33 #if defined(CONFIG_VIDEO_VESA) || defined(CONFIG_FIRMWARE_EDID)
40 video_vesa
.modes
= GET_HEAP(struct mode_info
, 0);
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
;
83 mi
->depth
= 0; /* text */
87 } else if ((vminfo
.mode_attr
& 0x99) == 0x99 &&
88 (vminfo
.memory_layout
== 4 ||
89 vminfo
.memory_layout
== 6) &&
90 vminfo
.memory_planes
== 1) {
91 #ifdef CONFIG_FB_BOOT_VESA_SUPPORT
92 /* Graphics mode, color, linear frame buffer
93 supported. Only register the mode if
94 if framebuffer is configured, however,
95 otherwise the user will be left without a screen. */
96 mi
= GET_HEAP(struct mode_info
, 1);
97 mi
->mode
= mode
+ VIDEO_FIRST_VESA
;
98 mi
->depth
= vminfo
.bpp
;
100 mi
->y
= vminfo
.v_res
;
109 #endif /* CONFIG_VIDEO_VESA */
112 static int vesa_set_mode(struct mode_info
*mode
)
116 u16 vesa_mode
= mode
->mode
- VIDEO_FIRST_VESA
;
118 memset(&vminfo
, 0, sizeof vminfo
); /* Just in case... */
122 di
= (size_t)&vminfo
;
124 : "+a" (ax
), "+c" (cx
), "+D" (di
), "=m" (vminfo
)
125 : : "ebx", "edx", "esi");
130 if ((vminfo
.mode_attr
& 0x15) == 0x05) {
131 /* It's a supported text mode */
133 #ifdef CONFIG_FB_BOOT_VESA_SUPPORT
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 */
140 return -1; /* Invalid mode */
148 : "+a" (ax
), "+b" (bx
), "+D" (di
)
149 : : "ecx", "edx", "esi");
154 graphic_mode
= is_graphic
;
162 vesa_store_mode_params_graphics();
171 /* Switch DAC to 8-bit mode */
172 static void vesa_dac_set_8bits(void)
176 /* If possible, switch the DAC to 8-bit mode */
177 if (vginfo
.capabilities
& 1) {
183 : "+a" (ax
), "+b" (bx
)
184 : : "ecx", "edx", "esi", "edi");
190 /* Set the color sizes to the DAC size, and offsets to 0 */
191 boot_params
.screen_info
.red_size
= dac_size
;
192 boot_params
.screen_info
.green_size
= dac_size
;
193 boot_params
.screen_info
.blue_size
= dac_size
;
194 boot_params
.screen_info
.rsvd_size
= dac_size
;
196 boot_params
.screen_info
.red_pos
= 0;
197 boot_params
.screen_info
.green_pos
= 0;
198 boot_params
.screen_info
.blue_pos
= 0;
199 boot_params
.screen_info
.rsvd_pos
= 0;
202 /* Save the VESA protected mode info */
203 static void vesa_store_pm_info(void)
209 asm("pushw %%es; "INT10
"; movw %%es,%0; popw %%es"
210 : "=d" (es
), "+a" (ax
), "+b" (bx
), "+D" (di
)
216 boot_params
.screen_info
.vesapm_seg
= es
;
217 boot_params
.screen_info
.vesapm_off
= di
;
221 * Save video mode parameters for graphics mode
223 static void vesa_store_mode_params_graphics(void)
225 /* Tell the kernel we're in VESA graphics mode */
226 boot_params
.screen_info
.orig_video_isVGA
= VIDEO_TYPE_VLFB
;
228 /* Mode parameters */
229 boot_params
.screen_info
.vesa_attributes
= vminfo
.mode_attr
;
230 boot_params
.screen_info
.lfb_linelength
= vminfo
.logical_scan
;
231 boot_params
.screen_info
.lfb_width
= vminfo
.h_res
;
232 boot_params
.screen_info
.lfb_height
= vminfo
.v_res
;
233 boot_params
.screen_info
.lfb_depth
= vminfo
.bpp
;
234 boot_params
.screen_info
.pages
= vminfo
.image_planes
;
235 boot_params
.screen_info
.lfb_base
= vminfo
.lfb_ptr
;
236 memcpy(&boot_params
.screen_info
.red_size
,
239 /* General parameters */
240 boot_params
.screen_info
.lfb_size
= vginfo
.total_memory
;
243 vesa_dac_set_8bits();
245 vesa_store_pm_info();
249 * Save EDID information for the kernel; this is invoked, separately,
250 * after mode-setting.
252 void vesa_store_edid(void)
254 #ifdef CONFIG_FIRMWARE_EDID
255 u16 ax
, bx
, cx
, dx
, di
;
257 /* Apparently used as a nonsense token... */
258 memset(&boot_params
.edid_info
, 0x13, sizeof boot_params
.edid_info
);
260 if (vginfo
.version
< 0x0200)
261 return; /* EDID requires VBE 2.0+ */
263 ax
= 0x4f15; /* VBE DDC */
264 bx
= 0x0000; /* Report DDC capabilities */
265 cx
= 0; /* Controller 0 */
266 di
= 0; /* ES:DI must be 0 by spec */
268 /* Note: The VBE DDC spec is different from the main VESA spec;
269 we genuinely have to assume all registers are destroyed here. */
271 asm("pushw %%es; movw %2,%%es; "INT10
"; popw %%es"
272 : "+a" (ax
), "+b" (bx
), "+c" (cx
), "+D" (di
)
276 return; /* No EDID */
278 /* BH = time in seconds to transfer EDD information */
279 /* BL = DDC level supported */
281 ax
= 0x4f15; /* VBE DDC */
282 bx
= 0x0001; /* Read EDID */
283 cx
= 0; /* Controller 0 */
284 dx
= 0; /* EDID block number */
285 di
=(size_t) &boot_params
.edid_info
; /* (ES:)Pointer to block */
287 : "+a" (ax
), "+b" (bx
), "+d" (dx
), "=m" (boot_params
.edid_info
),
290 #endif /* CONFIG_FIRMWARE_EDID */
293 #endif /* not _WAKEUP */
295 static __videocard video_vesa
=
299 .set_mode
= vesa_set_mode
,
300 .xmode_first
= VIDEO_FIRST_VESA
,