blob: 4716b9a963575aa8d0eedf703feaa7997ada608e [file] [log] [blame]
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -07001/* -*- 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 */
22static struct vesa_general_info vginfo;
23static struct vesa_mode_info vminfo;
24
25__videocard video_vesa;
26
27static void vesa_store_mode_params_graphics(void);
28
29static int vesa_probe(void)
30{
31#if defined(CONFIG_VIDEO_VESA) || defined(CONFIG_FIRMWARE_EDID)
H. Peter Anvin4221d012007-08-31 11:30:31 -070032 u16 ax, cx, di;
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -070033 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
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -070042 ax = 0x4f00;
H. Peter Anvin4221d012007-08-31 11:30:31 -070043 di = (size_t)&vginfo;
44 asm(INT10
45 : "+a" (ax), "+D" (di), "=m" (vginfo)
46 : : "ebx", "ecx", "edx", "esi");
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -070047
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
H. Peter Anvine6e1ace2007-10-25 16:09:38 -070060 if (!heap_free(sizeof(struct mode_info)))
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -070061 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;
H. Peter Anvin4221d012007-08-31 11:30:31 -070069 cx = mode;
70 di = (size_t)&vminfo;
71 asm(INT10
72 : "+a" (ax), "+c" (cx), "+D" (di), "=m" (vminfo)
73 : : "ebx", "edx", "esi");
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -070074
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->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
98 }
99 }
100
101 return nmodes;
102#else
103 return 0;
104#endif /* CONFIG_VIDEO_VESA */
105}
106
107static int vesa_set_mode(struct mode_info *mode)
108{
H. Peter Anvin4221d012007-08-31 11:30:31 -0700109 u16 ax, bx, cx, di;
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -0700110 int is_graphic;
111 u16 vesa_mode = mode->mode - VIDEO_FIRST_VESA;
112
113 memset(&vminfo, 0, sizeof vminfo); /* Just in case... */
114
115 ax = 0x4f01;
H. Peter Anvin4221d012007-08-31 11:30:31 -0700116 cx = vesa_mode;
117 di = (size_t)&vminfo;
118 asm(INT10
119 : "+a" (ax), "+c" (cx), "+D" (di), "=m" (vminfo)
120 : : "ebx", "edx", "esi");
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -0700121
122 if (ax != 0x004f)
123 return -1;
124
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 */
134 }
135
136
137 ax = 0x4f02;
H. Peter Anvin4221d012007-08-31 11:30:31 -0700138 bx = vesa_mode;
139 di = 0;
140 asm volatile(INT10
141 : "+a" (ax), "+b" (bx), "+D" (di)
142 : : "ecx", "edx", "esi");
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -0700143
144 if (ax != 0x004f)
145 return -1;
146
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();
156 }
157
158 return 0;
159}
160
161
162/* Switch DAC to 8-bit mode */
163static void vesa_dac_set_8bits(void)
164{
165 u8 dac_size = 6;
166
167 /* If possible, switch the DAC to 8-bit mode */
168 if (vginfo.capabilities & 1) {
169 u16 ax, bx;
170
171 ax = 0x4f08;
172 bx = 0x0800;
173 asm volatile(INT10
174 : "+a" (ax), "+b" (bx)
175 : : "ecx", "edx", "esi", "edi");
176
177 if (ax == 0x004f)
178 dac_size = bx >> 8;
179 }
180
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;
186
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;
191}
192
193/* Save the VESA protected mode info */
194static void vesa_store_pm_info(void)
195{
196 u16 ax, bx, di, es;
197
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");
203
204 if (ax != 0x004f)
205 return;
206
207 boot_params.screen_info.vesapm_seg = es;
208 boot_params.screen_info.vesapm_off = di;
209}
210
211/*
212 * Save video mode parameters for graphics mode
213 */
214static void vesa_store_mode_params_graphics(void)
215{
216 /* Tell the kernel we're in VESA graphics mode */
217 boot_params.screen_info.orig_video_isVGA = 0x23;
218
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);
229
230 /* General parameters */
231 boot_params.screen_info.lfb_size = vginfo.total_memory;
232
233 if (vminfo.bpp <= 8)
234 vesa_dac_set_8bits();
235
236 vesa_store_pm_info();
237}
238
239/*
240 * Save EDID information for the kernel; this is invoked, separately,
241 * after mode-setting.
242 */
243void vesa_store_edid(void)
244{
245#ifdef CONFIG_FIRMWARE_EDID
246 u16 ax, bx, cx, dx, di;
247
248 /* Apparently used as a nonsense token... */
249 memset(&boot_params.edid_info, 0x13, sizeof boot_params.edid_info);
250
251 if (vginfo.version < 0x0200)
252 return; /* EDID requires VBE 2.0+ */
253
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 */
258
259 /* Note: The VBE DDC spec is different from the main VESA spec;
260 we genuinely have to assume all registers are destroyed here. */
261
262 asm("pushw %%es; movw %2,%%es; "INT10"; popw %%es"
263 : "+a" (ax), "+b" (bx)
264 : "c" (cx), "D" (di)
265 : "esi");
266
267 if (ax != 0x004f)
268 return; /* No EDID */
269
270 /* BH = time in seconds to transfer EDD information */
271 /* BL = DDC level supported */
272
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
Antonino A. Daplas59acc082007-08-02 18:16:46 +0800279 : "+a" (ax), "+b" (bx), "+d" (dx), "=m" (boot_params.edid_info)
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -0700280 : "c" (cx), "D" (di)
281 : "esi");
282#endif /* CONFIG_FIRMWARE_EDID */
283}
284
285__videocard video_vesa =
286{
287 .card_name = "VESA",
288 .probe = vesa_probe,
289 .set_mode = vesa_set_mode,
290 .xmode_first = VIDEO_FIRST_VESA,
291 .xmode_n = 0x200,
292};