1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16#include "boot.h"
17#include "video.h"
18#include "vesa.h"
19#include "string.h"
20
21
22static struct vesa_general_info vginfo;
23static struct vesa_mode_info vminfo;
24
25static __videocard video_vesa;
26
27#ifndef _WAKEUP
28static void vesa_store_mode_params_graphics(void);
29#else
30static inline void vesa_store_mode_params_graphics(void) {}
31#endif
32
33static int vesa_probe(void)
34{
35 struct biosregs ireg, oreg;
36 u16 mode;
37 addr_t mode_ptr;
38 struct mode_info *mi;
39 int nmodes = 0;
40
41 video_vesa.modes = GET_HEAP(struct mode_info, 0);
42
43 initregs(&ireg);
44 ireg.ax = 0x4f00;
45 ireg.di = (size_t)&vginfo;
46 intcall(0x10, &ireg, &oreg);
47
48 if (oreg.ax != 0x004f ||
49 vginfo.signature != VESA_MAGIC ||
50 vginfo.version < 0x0102)
51 return 0;
52
53 set_fs(vginfo.video_mode_ptr.seg);
54 mode_ptr = vginfo.video_mode_ptr.off;
55
56 while ((mode = rdfs16(mode_ptr)) != 0xffff) {
57 mode_ptr += 2;
58
59 if (!heap_free(sizeof(struct mode_info)))
60 break;
61
62 if (mode & ~0x1ff)
63 continue;
64
65 memset(&vminfo, 0, sizeof vminfo);
66
67 ireg.ax = 0x4f01;
68 ireg.cx = mode;
69 ireg.di = (size_t)&vminfo;
70 intcall(0x10, &ireg, &oreg);
71
72 if (oreg.ax != 0x004f)
73 continue;
74
75 if ((vminfo.mode_attr & 0x15) == 0x05) {
76
77
78 mi = GET_HEAP(struct mode_info, 1);
79 mi->mode = mode + VIDEO_FIRST_VESA;
80 mi->depth = 0;
81 mi->x = vminfo.h_res;
82 mi->y = vminfo.v_res;
83 nmodes++;
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
90
91
92
93 mi = GET_HEAP(struct mode_info, 1);
94 mi->mode = mode + VIDEO_FIRST_VESA;
95 mi->depth = vminfo.bpp;
96 mi->x = vminfo.h_res;
97 mi->y = vminfo.v_res;
98 nmodes++;
99#endif
100 }
101 }
102
103 return nmodes;
104}
105
106static int vesa_set_mode(struct mode_info *mode)
107{
108 struct biosregs ireg, oreg;
109 int is_graphic;
110 u16 vesa_mode = mode->mode - VIDEO_FIRST_VESA;
111
112 memset(&vminfo, 0, sizeof vminfo);
113
114 initregs(&ireg);
115 ireg.ax = 0x4f01;
116 ireg.cx = vesa_mode;
117 ireg.di = (size_t)&vminfo;
118 intcall(0x10, &ireg, &oreg);
119
120 if (oreg.ax != 0x004f)
121 return -1;
122
123 if ((vminfo.mode_attr & 0x15) == 0x05) {
124
125 is_graphic = 0;
126#ifdef CONFIG_FB_BOOT_VESA_SUPPORT
127 } else if ((vminfo.mode_attr & 0x99) == 0x99) {
128
129 is_graphic = 1;
130 vesa_mode |= 0x4000;
131#endif
132 } else {
133 return -1;
134 }
135
136
137 initregs(&ireg);
138 ireg.ax = 0x4f02;
139 ireg.bx = vesa_mode;
140 intcall(0x10, &ireg, &oreg);
141
142 if (oreg.ax != 0x004f)
143 return -1;
144
145 graphic_mode = is_graphic;
146 if (!is_graphic) {
147
148 force_x = mode->x;
149 force_y = mode->y;
150 do_restore = 1;
151 } else {
152
153 vesa_store_mode_params_graphics();
154 }
155
156 return 0;
157}
158
159
160#ifndef _WAKEUP
161
162
163static void vesa_dac_set_8bits(void)
164{
165 struct biosregs ireg, oreg;
166 u8 dac_size = 6;
167
168
169 if (vginfo.capabilities & 1) {
170 initregs(&ireg);
171 ireg.ax = 0x4f08;
172 ireg.bh = 0x08;
173 intcall(0x10, &ireg, &oreg);
174 if (oreg.ax == 0x004f)
175 dac_size = oreg.bh;
176 }
177
178
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;
183
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;
188}
189
190
191static void vesa_store_pm_info(void)
192{
193 struct biosregs ireg, oreg;
194
195 initregs(&ireg);
196 ireg.ax = 0x4f0a;
197 intcall(0x10, &ireg, &oreg);
198
199 if (oreg.ax != 0x004f)
200 return;
201
202 boot_params.screen_info.vesapm_seg = oreg.es;
203 boot_params.screen_info.vesapm_off = oreg.di;
204}
205
206
207
208
209static void vesa_store_mode_params_graphics(void)
210{
211
212 boot_params.screen_info.orig_video_isVGA = VIDEO_TYPE_VLFB;
213
214
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,
223 &vminfo.rmask, 8);
224
225
226 boot_params.screen_info.lfb_size = vginfo.total_memory;
227
228 if (vminfo.bpp <= 8)
229 vesa_dac_set_8bits();
230
231 vesa_store_pm_info();
232}
233
234
235
236
237
238void vesa_store_edid(void)
239{
240#ifdef CONFIG_FIRMWARE_EDID
241 struct biosregs ireg, oreg;
242
243
244 memset(&boot_params.edid_info, 0x13, sizeof boot_params.edid_info);
245
246 if (vginfo.version < 0x0200)
247 return;
248
249 initregs(&ireg);
250 ireg.ax = 0x4f15;
251
252
253 ireg.es = 0;
254 intcall(0x10, &ireg, &oreg);
255
256 if (oreg.ax != 0x004f)
257 return;
258
259
260
261
262 ireg.ax = 0x4f15;
263 ireg.bx = 0x0001;
264
265
266 ireg.es = ds();
267 ireg.di =(size_t)&boot_params.edid_info;
268 intcall(0x10, &ireg, &oreg);
269#endif
270}
271
272#endif
273
274static __videocard video_vesa =
275{
276 .card_name = "VESA",
277 .probe = vesa_probe,
278 .set_mode = vesa_set_mode,
279 .xmode_first = VIDEO_FIRST_VESA,
280 .xmode_n = 0x200,
281};
282