1 /* -*- linux-c -*- ------------------------------------------------------- *
3 * Copyright (C) 1991, 1992 Linus Torvalds
4 * Copyright 2007 rPath, Inc. - All Rights Reserved
5 * Copyright 2009 Intel Corporation; author H. Peter Anvin
7 * This file is part of the Linux kernel, and is made available under
8 * the terms of the GNU General Public License version 2.
10 * ----------------------------------------------------------------------- */
21 /* VESA information */
22 static struct vesa_general_info vginfo
;
23 static struct vesa_mode_info vminfo
;
25 static __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 struct biosregs ireg
, oreg
;
41 video_vesa
.modes
= GET_HEAP(struct mode_info
, 0);
45 ireg
.di
= (size_t)&vginfo
;
46 intcall(0x10, &ireg
, &oreg
);
48 if (oreg
.ax
!= 0x004f ||
49 vginfo
.signature
!= VESA_MAGIC
||
50 vginfo
.version
< 0x0102)
51 return 0; /* Not present */
53 set_fs(vginfo
.video_mode_ptr
.seg
);
54 mode_ptr
= vginfo
.video_mode_ptr
.off
;
56 while ((mode
= rdfs16(mode_ptr
)) != 0xffff) {
59 if (!heap_free(sizeof(struct mode_info
)))
60 break; /* Heap full, can't save mode info */
65 memset(&vminfo
, 0, sizeof vminfo
); /* Just in case... */
69 ireg
.di
= (size_t)&vminfo
;
70 intcall(0x10, &ireg
, &oreg
);
72 if (oreg
.ax
!= 0x004f)
75 if ((vminfo
.mode_attr
& 0x15) == 0x05) {
76 /* Text Mode, TTY BIOS supported,
77 supported by hardware */
78 mi
= GET_HEAP(struct mode_info
, 1);
79 mi
->mode
= mode
+ VIDEO_FIRST_VESA
;
80 mi
->depth
= 0; /* text */
84 } else if ((vminfo
.mode_attr
& 0x99) == 0x99 &&
85 (vminfo
.memory_layout
== 4 ||
86 vminfo
.memory_layout
== 6) &&
87 vminfo
.memory_planes
== 1) {
88 #ifdef CONFIG_FB_BOOT_VESA_SUPPORT
89 /* Graphics mode, color, linear frame buffer
90 supported. Only register the mode if
91 if framebuffer is configured, however,
92 otherwise the user will be left without a screen. */
93 mi
= GET_HEAP(struct mode_info
, 1);
94 mi
->mode
= mode
+ VIDEO_FIRST_VESA
;
95 mi
->depth
= vminfo
.bpp
;
106 static int vesa_set_mode(struct mode_info
*mode
)
108 struct biosregs ireg
, oreg
;
110 u16 vesa_mode
= mode
->mode
- VIDEO_FIRST_VESA
;
112 memset(&vminfo
, 0, sizeof vminfo
); /* Just in case... */
117 ireg
.di
= (size_t)&vminfo
;
118 intcall(0x10, &ireg
, &oreg
);
120 if (oreg
.ax
!= 0x004f)
123 if ((vminfo
.mode_attr
& 0x15) == 0x05) {
124 /* It's a supported text mode */
126 #ifdef CONFIG_FB_BOOT_VESA_SUPPORT
127 } else if ((vminfo
.mode_attr
& 0x99) == 0x99) {
128 /* It's a graphics mode with linear frame buffer */
130 vesa_mode
|= 0x4000; /* Request linear frame buffer */
133 return -1; /* Invalid mode */
140 intcall(0x10, &ireg
, &oreg
);
142 if (oreg
.ax
!= 0x004f)
145 graphic_mode
= is_graphic
;
153 vesa_store_mode_params_graphics();
162 /* Switch DAC to 8-bit mode */
163 static void vesa_dac_set_8bits(void)
165 struct biosregs ireg
, oreg
;
168 /* If possible, switch the DAC to 8-bit mode */
169 if (vginfo
.capabilities
& 1) {
173 intcall(0x10, &ireg
, &oreg
);
174 if (oreg
.ax
== 0x004f)
178 /* Set the color sizes to the DAC size, and offsets to 0 */
179 boot_params
.screen_info
.red_size
= dac_size
;
180 boot_params
.screen_info
.green_size
= dac_size
;
181 boot_params
.screen_info
.blue_size
= dac_size
;
182 boot_params
.screen_info
.rsvd_size
= dac_size
;
184 boot_params
.screen_info
.red_pos
= 0;
185 boot_params
.screen_info
.green_pos
= 0;
186 boot_params
.screen_info
.blue_pos
= 0;
187 boot_params
.screen_info
.rsvd_pos
= 0;
190 /* Save the VESA protected mode info */
191 static void vesa_store_pm_info(void)
193 struct biosregs ireg
, oreg
;
197 intcall(0x10, &ireg
, &oreg
);
199 if (oreg
.ax
!= 0x004f)
202 boot_params
.screen_info
.vesapm_seg
= oreg
.es
;
203 boot_params
.screen_info
.vesapm_off
= oreg
.di
;
207 * Save video mode parameters for graphics mode
209 static void vesa_store_mode_params_graphics(void)
211 /* Tell the kernel we're in VESA graphics mode */
212 boot_params
.screen_info
.orig_video_isVGA
= VIDEO_TYPE_VLFB
;
214 /* Mode parameters */
215 boot_params
.screen_info
.vesa_attributes
= vminfo
.mode_attr
;
216 boot_params
.screen_info
.lfb_linelength
= vminfo
.logical_scan
;
217 boot_params
.screen_info
.lfb_width
= vminfo
.h_res
;
218 boot_params
.screen_info
.lfb_height
= vminfo
.v_res
;
219 boot_params
.screen_info
.lfb_depth
= vminfo
.bpp
;
220 boot_params
.screen_info
.pages
= vminfo
.image_planes
;
221 boot_params
.screen_info
.lfb_base
= vminfo
.lfb_ptr
;
222 memcpy(&boot_params
.screen_info
.red_size
,
225 /* General parameters */
226 boot_params
.screen_info
.lfb_size
= vginfo
.total_memory
;
229 vesa_dac_set_8bits();
231 vesa_store_pm_info();
235 * Save EDID information for the kernel; this is invoked, separately,
236 * after mode-setting.
238 void vesa_store_edid(void)
240 #ifdef CONFIG_FIRMWARE_EDID
241 struct biosregs ireg
, oreg
;
243 /* Apparently used as a nonsense token... */
244 memset(&boot_params
.edid_info
, 0x13, sizeof boot_params
.edid_info
);
246 if (vginfo
.version
< 0x0200)
247 return; /* EDID requires VBE 2.0+ */
250 ireg
.ax
= 0x4f15; /* VBE DDC */
251 /* ireg.bx = 0x0000; */ /* Report DDC capabilities */
252 /* ireg.cx = 0; */ /* Controller 0 */
253 ireg
.es
= 0; /* ES:DI must be 0 by spec */
254 intcall(0x10, &ireg
, &oreg
);
256 if (oreg
.ax
!= 0x004f)
257 return; /* No EDID */
259 /* BH = time in seconds to transfer EDD information */
260 /* BL = DDC level supported */
262 ireg
.ax
= 0x4f15; /* VBE DDC */
263 ireg
.bx
= 0x0001; /* Read EDID */
264 /* ireg.cx = 0; */ /* Controller 0 */
265 /* ireg.dx = 0; */ /* EDID block number */
267 ireg
.di
=(size_t)&boot_params
.edid_info
; /* (ES:)Pointer to block */
268 intcall(0x10, &ireg
, &oreg
);
269 #endif /* CONFIG_FIRMWARE_EDID */
272 #endif /* not _WAKEUP */
274 static __videocard video_vesa
=
278 .set_mode
= vesa_set_mode
,
279 .xmode_first
= VIDEO_FIRST_VESA
,