]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blob - arch/x86/boot/video-vesa.c
662dd2f130684c050d46f6950263ef9b4e7cfc08
[linux-2.6-omap-h63xx.git] / arch / x86 / boot / video-vesa.c
1 /* -*- linux-c -*- ------------------------------------------------------- *
2  *
3  *   Copyright (C) 1991, 1992 Linus Torvalds
4  *   Copyright 2007 rPath, Inc. - All Rights Reserved
5  *
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.
8  *
9  * ----------------------------------------------------------------------- */
10
11 /*
12  * arch/i386/boot/video-vesa.c
13  *
14  * VESA text modes
15  */
16
17 #include "boot.h"
18 #include "video.h"
19 #include "vesa.h"
20
21 /* VESA information */
22 static struct vesa_general_info vginfo;
23 static struct vesa_mode_info vminfo;
24
25 __videocard video_vesa;
26
27 static void vesa_store_mode_params_graphics(void);
28
29 static int vesa_probe(void)
30 {
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;
37
38         video_vesa.modes = GET_HEAP(struct mode_info, 0);
39
40         vginfo.signature = VBE2_MAGIC;
41
42         ax = 0x4f00;
43         di = (size_t)&vginfo;
44         asm(INT10
45             : "+a" (ax), "+D" (di), "=m" (vginfo)
46             : : "ebx", "ecx", "edx", "esi");
47
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;
56
57         while ((mode = rdfs16(mode_ptr)) != 0xffff) {
58                 mode_ptr += 2;
59
60                 if (!heap_free(sizeof(struct mode_info)))
61                         break;  /* Heap full, can't save mode info */
62
63                 if (mode & ~0x1ff)
64                         continue;
65
66                 memset(&vminfo, 0, sizeof vminfo); /* Just in case... */
67
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");
74
75                 if (ax != 0x004f)
76                         continue;
77
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 */
84                         mi->x     = vminfo.h_res;
85                         mi->y     = vminfo.v_res;
86                         nmodes++;
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
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                            We don't require CONFIG_FB_VESA, however, since
97                            some of the other framebuffer drivers can use
98                            this mode-setting, too. */
99                         mi = GET_HEAP(struct mode_info, 1);
100                         mi->mode = mode + VIDEO_FIRST_VESA;
101                         mi->depth = vminfo.bpp;
102                         mi->x = vminfo.h_res;
103                         mi->y = vminfo.v_res;
104                         nmodes++;
105 #endif
106                 }
107         }
108
109         return nmodes;
110 #else
111         return 0;
112 #endif /* CONFIG_VIDEO_VESA */
113 }
114
115 static int vesa_set_mode(struct mode_info *mode)
116 {
117         u16 ax, bx, cx, di;
118         int is_graphic;
119         u16 vesa_mode = mode->mode - VIDEO_FIRST_VESA;
120
121         memset(&vminfo, 0, sizeof vminfo); /* Just in case... */
122
123         ax = 0x4f01;
124         cx = vesa_mode;
125         di = (size_t)&vminfo;
126         asm(INT10
127             : "+a" (ax), "+c" (cx), "+D" (di), "=m" (vminfo)
128             : : "ebx", "edx", "esi");
129
130         if (ax != 0x004f)
131                 return -1;
132
133         if ((vminfo.mode_attr & 0x15) == 0x05) {
134                 /* It's a supported text mode */
135                 is_graphic = 0;
136         } else if ((vminfo.mode_attr & 0x99) == 0x99) {
137                 /* It's a graphics mode with linear frame buffer */
138                 is_graphic = 1;
139                 vesa_mode |= 0x4000; /* Request linear frame buffer */
140         } else {
141                 return -1;      /* Invalid mode */
142         }
143
144
145         ax = 0x4f02;
146         bx = vesa_mode;
147         di = 0;
148         asm volatile(INT10
149                      : "+a" (ax), "+b" (bx), "+D" (di)
150                      : : "ecx", "edx", "esi");
151
152         if (ax != 0x004f)
153                 return -1;
154
155         graphic_mode = is_graphic;
156         if (!is_graphic) {
157                 /* Text mode */
158                 force_x = mode->x;
159                 force_y = mode->y;
160                 do_restore = 1;
161         } else {
162                 /* Graphics mode */
163                 vesa_store_mode_params_graphics();
164         }
165
166         return 0;
167 }
168
169
170 /* Switch DAC to 8-bit mode */
171 static void vesa_dac_set_8bits(void)
172 {
173         u8 dac_size = 6;
174
175         /* If possible, switch the DAC to 8-bit mode */
176         if (vginfo.capabilities & 1) {
177                 u16 ax, bx;
178
179                 ax = 0x4f08;
180                 bx = 0x0800;
181                 asm volatile(INT10
182                              : "+a" (ax), "+b" (bx)
183                              : : "ecx", "edx", "esi", "edi");
184
185                 if (ax == 0x004f)
186                         dac_size = bx >> 8;
187         }
188
189         /* Set the color sizes to the DAC size, and offsets to 0 */
190         boot_params.screen_info.red_size = dac_size;
191         boot_params.screen_info.green_size = dac_size;
192         boot_params.screen_info.blue_size = dac_size;
193         boot_params.screen_info.rsvd_size = dac_size;
194
195         boot_params.screen_info.red_pos = 0;
196         boot_params.screen_info.green_pos = 0;
197         boot_params.screen_info.blue_pos = 0;
198         boot_params.screen_info.rsvd_pos = 0;
199 }
200
201 /* Save the VESA protected mode info */
202 static void vesa_store_pm_info(void)
203 {
204         u16 ax, bx, di, es;
205
206         ax = 0x4f0a;
207         bx = di = 0;
208         asm("pushw %%es; "INT10"; movw %%es,%0; popw %%es"
209             : "=d" (es), "+a" (ax), "+b" (bx), "+D" (di)
210             : : "ecx", "esi");
211
212         if (ax != 0x004f)
213                 return;
214
215         boot_params.screen_info.vesapm_seg = es;
216         boot_params.screen_info.vesapm_off = di;
217 }
218
219 /*
220  * Save video mode parameters for graphics mode
221  */
222 static void vesa_store_mode_params_graphics(void)
223 {
224         /* Tell the kernel we're in VESA graphics mode */
225         boot_params.screen_info.orig_video_isVGA = 0x23;
226
227         /* Mode parameters */
228         boot_params.screen_info.vesa_attributes = vminfo.mode_attr;
229         boot_params.screen_info.lfb_linelength = vminfo.logical_scan;
230         boot_params.screen_info.lfb_width = vminfo.h_res;
231         boot_params.screen_info.lfb_height = vminfo.v_res;
232         boot_params.screen_info.lfb_depth = vminfo.bpp;
233         boot_params.screen_info.pages = vminfo.image_planes;
234         boot_params.screen_info.lfb_base = vminfo.lfb_ptr;
235         memcpy(&boot_params.screen_info.red_size,
236                &vminfo.rmask, 8);
237
238         /* General parameters */
239         boot_params.screen_info.lfb_size = vginfo.total_memory;
240
241         if (vminfo.bpp <= 8)
242                 vesa_dac_set_8bits();
243
244         vesa_store_pm_info();
245 }
246
247 /*
248  * Save EDID information for the kernel; this is invoked, separately,
249  * after mode-setting.
250  */
251 void vesa_store_edid(void)
252 {
253 #ifdef CONFIG_FIRMWARE_EDID
254         u16 ax, bx, cx, dx, di;
255
256         /* Apparently used as a nonsense token... */
257         memset(&boot_params.edid_info, 0x13, sizeof boot_params.edid_info);
258
259         if (vginfo.version < 0x0200)
260                 return;         /* EDID requires VBE 2.0+ */
261
262         ax = 0x4f15;            /* VBE DDC */
263         bx = 0x0000;            /* Report DDC capabilities */
264         cx = 0;                 /* Controller 0 */
265         di = 0;                 /* ES:DI must be 0 by spec */
266
267         /* Note: The VBE DDC spec is different from the main VESA spec;
268            we genuinely have to assume all registers are destroyed here. */
269
270         asm("pushw %%es; movw %2,%%es; "INT10"; popw %%es"
271             : "+a" (ax), "+b" (bx)
272             :  "c" (cx), "D" (di)
273             : "esi");
274
275         if (ax != 0x004f)
276                 return;         /* No EDID */
277
278         /* BH = time in seconds to transfer EDD information */
279         /* BL = DDC level supported */
280
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 */
286         asm(INT10
287             : "+a" (ax), "+b" (bx), "+d" (dx), "=m" (boot_params.edid_info)
288             : "c" (cx), "D" (di)
289             : "esi");
290 #endif /* CONFIG_FIRMWARE_EDID */
291 }
292
293 __videocard video_vesa =
294 {
295         .card_name      = "VESA",
296         .probe          = vesa_probe,
297         .set_mode       = vesa_set_mode,
298         .xmode_first    = VIDEO_FIRST_VESA,
299         .xmode_n        = 0x200,
300 };