1
2
3
4
5
6
7
8
9
10
11
12
13
14
15#include "boot.h"
16#include "video.h"
17#include "vesa.h"
18
19
20static struct vesa_general_info vginfo;
21static struct vesa_mode_info vminfo;
22
23__videocard video_vesa;
24
25#ifndef _WAKEUP
26static void vesa_store_mode_params_graphics(void);
27#else
28static inline void vesa_store_mode_params_graphics(void) {}
29#endif
30
31static int vesa_probe(void)
32{
33#if defined(CONFIG_VIDEO_VESA) || defined(CONFIG_FIRMWARE_EDID)
34 u16 ax, cx, di;
35 u16 mode;
36 addr_t mode_ptr;
37 struct mode_info *mi;
38 int nmodes = 0;
39
40 video_vesa.modes = GET_HEAP(struct mode_info, 0);
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;
52#endif
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;
62
63 if (mode & ~0x1ff)
64 continue;
65
66 memset(&vminfo, 0, sizeof vminfo);
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
80
81 mi = GET_HEAP(struct mode_info, 1);
82 mi->mode = mode + VIDEO_FIRST_VESA;
83 mi->depth = 0;
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
93
94
95
96
97
98
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
113}
114
115static 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);
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
135 is_graphic = 0;
136 } else if ((vminfo.mode_attr & 0x99) == 0x99) {
137
138 is_graphic = 1;
139 vesa_mode |= 0x4000;
140 } else {
141 return -1;
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
158 force_x = mode->x;
159 force_y = mode->y;
160 do_restore = 1;
161 } else {
162
163 vesa_store_mode_params_graphics();
164 }
165
166 return 0;
167}
168
169
170#ifndef _WAKEUP
171
172
173static void vesa_dac_set_8bits(void)
174{
175 u8 dac_size = 6;
176
177
178 if (vginfo.capabilities & 1) {
179 u16 ax, bx;
180
181 ax = 0x4f08;
182 bx = 0x0800;
183 asm volatile(INT10
184 : "+a" (ax), "+b" (bx)
185 : : "ecx", "edx", "esi", "edi");
186
187 if (ax == 0x004f)
188 dac_size = bx >> 8;
189 }
190
191
192 boot_params.screen_info.red_size = dac_size;
193 boot_params.screen_info.green_size = dac_size;
194 boot_params.screen_info.blue_size = dac_size;
195 boot_params.screen_info.rsvd_size = dac_size;
196
197 boot_params.screen_info.red_pos = 0;
198 boot_params.screen_info.green_pos = 0;
199 boot_params.screen_info.blue_pos = 0;
200 boot_params.screen_info.rsvd_pos = 0;
201}
202
203
204static void vesa_store_pm_info(void)
205{
206 u16 ax, bx, di, es;
207
208 ax = 0x4f0a;
209 bx = di = 0;
210 asm("pushw %%es; "INT10"; movw %%es,%0; popw %%es"
211 : "=d" (es), "+a" (ax), "+b" (bx), "+D" (di)
212 : : "ecx", "esi");
213
214 if (ax != 0x004f)
215 return;
216
217 boot_params.screen_info.vesapm_seg = es;
218 boot_params.screen_info.vesapm_off = di;
219}
220
221
222
223
224static void vesa_store_mode_params_graphics(void)
225{
226
227 boot_params.screen_info.orig_video_isVGA = 0x23;
228
229
230 boot_params.screen_info.vesa_attributes = vminfo.mode_attr;
231 boot_params.screen_info.lfb_linelength = vminfo.logical_scan;
232 boot_params.screen_info.lfb_width = vminfo.h_res;
233 boot_params.screen_info.lfb_height = vminfo.v_res;
234 boot_params.screen_info.lfb_depth = vminfo.bpp;
235 boot_params.screen_info.pages = vminfo.image_planes;
236 boot_params.screen_info.lfb_base = vminfo.lfb_ptr;
237 memcpy(&boot_params.screen_info.red_size,
238 &vminfo.rmask, 8);
239
240
241 boot_params.screen_info.lfb_size = vginfo.total_memory;
242
243 if (vminfo.bpp <= 8)
244 vesa_dac_set_8bits();
245
246 vesa_store_pm_info();
247}
248
249
250
251
252
253void vesa_store_edid(void)
254{
255#ifdef CONFIG_FIRMWARE_EDID
256 u16 ax, bx, cx, dx, di;
257
258
259 memset(&boot_params.edid_info, 0x13, sizeof boot_params.edid_info);
260
261 if (vginfo.version < 0x0200)
262 return;
263
264 ax = 0x4f15;
265 bx = 0x0000;
266 cx = 0;
267 di = 0;
268
269
270
271
272 asm("pushw %%es; movw %2,%%es; "INT10"; popw %%es"
273 : "+a" (ax), "+b" (bx)
274 : "c" (cx), "D" (di)
275 : "esi");
276
277 if (ax != 0x004f)
278 return;
279
280
281
282
283 ax = 0x4f15;
284 bx = 0x0001;
285 cx = 0;
286 dx = 0;
287 di =(size_t) &boot_params.edid_info;
288 asm(INT10
289 : "+a" (ax), "+b" (bx), "+d" (dx), "=m" (boot_params.edid_info)
290 : "c" (cx), "D" (di)
291 : "esi");
292#endif
293}
294
295#endif
296
297__videocard video_vesa =
298{
299 .card_name = "VESA",
300 .probe = vesa_probe,
301 .set_mode = vesa_set_mode,
302 .xmode_first = VIDEO_FIRST_VESA,
303 .xmode_n = 0x200,
304};
305