i386: move boot
[wandboard.git] / arch / x86 / boot / video-vesa.c
blob19219071071023e631518e102c4dbcc7481dea17
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
14 * VESA text modes
17 #include "boot.h"
18 #include "video.h"
19 #include "vesa.h"
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)
32 u16 ax, cx, di;
33 u16 mode;
34 addr_t mode_ptr;
35 struct mode_info *mi;
36 int nmodes = 0;
38 video_vesa.modes = GET_HEAP(struct mode_info, 0);
40 vginfo.signature = VBE2_MAGIC;
42 ax = 0x4f00;
43 di = (size_t)&vginfo;
44 asm(INT10
45 : "+a" (ax), "+D" (di), "=m" (vginfo)
46 : : "ebx", "ecx", "edx", "esi");
48 if (ax != 0x004f ||
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) {
58 mode_ptr += 2;
60 if (heap_free() < sizeof(struct mode_info))
61 break; /* Heap full, can't save mode info */
63 if (mode & ~0x1ff)
64 continue;
66 memset(&vminfo, 0, sizeof vminfo); /* Just in case... */
68 ax = 0x4f01;
69 cx = mode;
70 di = (size_t)&vminfo;
71 asm(INT10
72 : "+a" (ax), "+c" (cx), "+D" (di), "=m" (vminfo)
73 : : "ebx", "edx", "esi");
75 if (ax != 0x004f)
76 continue;
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->x = vminfo.h_res;
84 mi->y = vminfo.v_res;
85 nmodes++;
86 } else if ((vminfo.mode_attr & 0x99) == 0x99) {
87 #ifdef CONFIG_FB
88 /* Graphics mode, color, linear frame buffer
89 supported -- register the mode but hide from
90 the menu. Only do this if framebuffer is
91 configured, however, otherwise the user will
92 be left without a screen. */
93 mi = GET_HEAP(struct mode_info, 1);
94 mi->mode = mode + VIDEO_FIRST_VESA;
95 mi->x = mi->y = 0;
96 nmodes++;
97 #endif
101 return nmodes;
102 #else
103 return 0;
104 #endif /* CONFIG_VIDEO_VESA */
107 static int vesa_set_mode(struct mode_info *mode)
109 u16 ax, bx, cx, di;
110 int is_graphic;
111 u16 vesa_mode = mode->mode - VIDEO_FIRST_VESA;
113 memset(&vminfo, 0, sizeof vminfo); /* Just in case... */
115 ax = 0x4f01;
116 cx = vesa_mode;
117 di = (size_t)&vminfo;
118 asm(INT10
119 : "+a" (ax), "+c" (cx), "+D" (di), "=m" (vminfo)
120 : : "ebx", "edx", "esi");
122 if (ax != 0x004f)
123 return -1;
125 if ((vminfo.mode_attr & 0x15) == 0x05) {
126 /* It's a supported text mode */
127 is_graphic = 0;
128 } else if ((vminfo.mode_attr & 0x99) == 0x99) {
129 /* It's a graphics mode with linear frame buffer */
130 is_graphic = 1;
131 vesa_mode |= 0x4000; /* Request linear frame buffer */
132 } else {
133 return -1; /* Invalid mode */
137 ax = 0x4f02;
138 bx = vesa_mode;
139 di = 0;
140 asm volatile(INT10
141 : "+a" (ax), "+b" (bx), "+D" (di)
142 : : "ecx", "edx", "esi");
144 if (ax != 0x004f)
145 return -1;
147 graphic_mode = is_graphic;
148 if (!is_graphic) {
149 /* Text mode */
150 force_x = mode->x;
151 force_y = mode->y;
152 do_restore = 1;
153 } else {
154 /* Graphics mode */
155 vesa_store_mode_params_graphics();
158 return 0;
162 /* Switch DAC to 8-bit mode */
163 static void vesa_dac_set_8bits(void)
165 u8 dac_size = 6;
167 /* If possible, switch the DAC to 8-bit mode */
168 if (vginfo.capabilities & 1) {
169 u16 ax, bx;
171 ax = 0x4f08;
172 bx = 0x0800;
173 asm volatile(INT10
174 : "+a" (ax), "+b" (bx)
175 : : "ecx", "edx", "esi", "edi");
177 if (ax == 0x004f)
178 dac_size = bx >> 8;
181 /* Set the color sizes to the DAC size, and offsets to 0 */
182 boot_params.screen_info.red_size = dac_size;
183 boot_params.screen_info.green_size = dac_size;
184 boot_params.screen_info.blue_size = dac_size;
185 boot_params.screen_info.rsvd_size = dac_size;
187 boot_params.screen_info.red_pos = 0;
188 boot_params.screen_info.green_pos = 0;
189 boot_params.screen_info.blue_pos = 0;
190 boot_params.screen_info.rsvd_pos = 0;
193 /* Save the VESA protected mode info */
194 static void vesa_store_pm_info(void)
196 u16 ax, bx, di, es;
198 ax = 0x4f0a;
199 bx = di = 0;
200 asm("pushw %%es; "INT10"; movw %%es,%0; popw %%es"
201 : "=d" (es), "+a" (ax), "+b" (bx), "+D" (di)
202 : : "ecx", "esi");
204 if (ax != 0x004f)
205 return;
207 boot_params.screen_info.vesapm_seg = es;
208 boot_params.screen_info.vesapm_off = di;
212 * Save video mode parameters for graphics mode
214 static void vesa_store_mode_params_graphics(void)
216 /* Tell the kernel we're in VESA graphics mode */
217 boot_params.screen_info.orig_video_isVGA = 0x23;
219 /* Mode parameters */
220 boot_params.screen_info.vesa_attributes = vminfo.mode_attr;
221 boot_params.screen_info.lfb_linelength = vminfo.logical_scan;
222 boot_params.screen_info.lfb_width = vminfo.h_res;
223 boot_params.screen_info.lfb_height = vminfo.v_res;
224 boot_params.screen_info.lfb_depth = vminfo.bpp;
225 boot_params.screen_info.pages = vminfo.image_planes;
226 boot_params.screen_info.lfb_base = vminfo.lfb_ptr;
227 memcpy(&boot_params.screen_info.red_size,
228 &vminfo.rmask, 8);
230 /* General parameters */
231 boot_params.screen_info.lfb_size = vginfo.total_memory;
233 if (vminfo.bpp <= 8)
234 vesa_dac_set_8bits();
236 vesa_store_pm_info();
240 * Save EDID information for the kernel; this is invoked, separately,
241 * after mode-setting.
243 void vesa_store_edid(void)
245 #ifdef CONFIG_FIRMWARE_EDID
246 u16 ax, bx, cx, dx, di;
248 /* Apparently used as a nonsense token... */
249 memset(&boot_params.edid_info, 0x13, sizeof boot_params.edid_info);
251 if (vginfo.version < 0x0200)
252 return; /* EDID requires VBE 2.0+ */
254 ax = 0x4f15; /* VBE DDC */
255 bx = 0x0000; /* Report DDC capabilities */
256 cx = 0; /* Controller 0 */
257 di = 0; /* ES:DI must be 0 by spec */
259 /* Note: The VBE DDC spec is different from the main VESA spec;
260 we genuinely have to assume all registers are destroyed here. */
262 asm("pushw %%es; movw %2,%%es; "INT10"; popw %%es"
263 : "+a" (ax), "+b" (bx)
264 : "c" (cx), "D" (di)
265 : "esi");
267 if (ax != 0x004f)
268 return; /* No EDID */
270 /* BH = time in seconds to transfer EDD information */
271 /* BL = DDC level supported */
273 ax = 0x4f15; /* VBE DDC */
274 bx = 0x0001; /* Read EDID */
275 cx = 0; /* Controller 0 */
276 dx = 0; /* EDID block number */
277 di =(size_t) &boot_params.edid_info; /* (ES:)Pointer to block */
278 asm(INT10
279 : "+a" (ax), "+b" (bx), "+d" (dx), "=m" (boot_params.edid_info)
280 : "c" (cx), "D" (di)
281 : "esi");
282 #endif /* CONFIG_FIRMWARE_EDID */
285 __videocard video_vesa =
287 .card_name = "VESA",
288 .probe = vesa_probe,
289 .set_mode = vesa_set_mode,
290 .xmode_first = VIDEO_FIRST_VESA,
291 .xmode_n = 0x200,