1 | ␊ |
2 | /* Copied from 915 resolution created by steve tomljenovic␊ |
3 | *␊ |
4 | * This code is based on the techniques used in :␊ |
5 | *␊ |
6 | * - 855patch. Many thanks to Christian Zietz (czietz gmx net)␊ |
7 | * for demonstrating how to shadow the VBIOS into system RAM␊ |
8 | * and then modify it.␊ |
9 | *␊ |
10 | * - 1280patch by Andrew Tipton (andrewtipton null li).␊ |
11 | *␊ |
12 | * - 855resolution by Alain Poirier␊ |
13 | *␊ |
14 | * This source code is into the public domain.␊ |
15 | */␊ |
16 | ␊ |
17 | //#include "libsaio.h"␊ |
18 | #include "saio_internal.h"␊ |
19 | //---␊ |
20 | //#include "autoresolution.h" - included on ati_resolution.h␊ |
21 | #include "nvidia_resolution.h"␊ |
22 | #include "ati_resolution.h"␊ |
23 | #include "gma_resolution.h"␊ |
24 | #include "../boot2/graphics.h"␊ |
25 | ␊ |
26 | char * chipsetTypeNames[] = {␊ |
27 | ␉"UNKNOWN", "830", "845G", "855GM", "865G", "915G", "915GM", "945G", "945GM", "945GME",␊ |
28 | ␉"946GZ", "955X", "G965", "Q965", "965GM", "975X",␊ |
29 | ␉"P35", "X48", "B43", "Q45", "P45", "GM45", "G41", "G31", "G45", "500"␊ |
30 | };␊ |
31 | ␊ |
32 | uint32_t getChipsetId(void)␊ |
33 | {␊ |
34 | ␉outl(0xcf8, 0x80000000);␊ |
35 | ␉return inl(0xcfc);␊ |
36 | }␊ |
37 | ␊ |
38 | chipsetType getChipset(uint32_t id)␊ |
39 | {␊ |
40 | ␉chipsetType type;␊ |
41 | ␉␊ |
42 | ␉switch (id)␊ |
43 | ␉{␊ |
44 | ␉␉case 0x35758086:␊ |
45 | ␉␉␉type = CT_830;␊ |
46 | ␉␉␉break;␊ |
47 | ␉␉␊ |
48 | ␉␉case 0x25608086:␊ |
49 | ␉␉␉type = CT_845G;␊ |
50 | ␉␉␉break;␊ |
51 | ␉␉␉␉␊ |
52 | ␉␉case 0x35808086:␊ |
53 | ␉␉␉type = CT_855GM;␊ |
54 | ␉␉␉break;␊ |
55 | ␉␉␉␉␊ |
56 | ␉␉case 0x25708086:␊ |
57 | ␉␉␉type = CT_865G;␊ |
58 | ␉␉␉break;␊ |
59 | ␉␉␊ |
60 | ␉␉case 0x25808086:␊ |
61 | ␉␉␉type = CT_915G;␊ |
62 | ␉␉␉break;␊ |
63 | ␉␉␉␊ |
64 | ␉␉case 0x25908086:␊ |
65 | ␉␉␉type = CT_915GM;␊ |
66 | ␉␉␉break;␊ |
67 | ␉␉␉␊ |
68 | ␉␉case 0x27708086:␊ |
69 | ␉␉␉type = CT_945G;␊ |
70 | ␉␉␉break;␊ |
71 | ␉␉␉␊ |
72 | ␉␉case 0x27748086:␊ |
73 | ␉␉␉type = CT_955X;␊ |
74 | ␉␉␉break;␊ |
75 | ␉␉␉␊ |
76 | ␉␉case 0x277c8086:␊ |
77 | ␉␉␉type = CT_975X;␊ |
78 | ␉␉␉break;␊ |
79 | ␉␉␊ |
80 | ␉␉case 0x27a08086:␊ |
81 | ␉␉␉type = CT_945GM;␊ |
82 | ␉␉␉break;␊ |
83 | ␉␉␉␊ |
84 | ␉␉case 0x27ac8086:␊ |
85 | ␉␉␉type = CT_945GME;␊ |
86 | ␉␉␉break;␊ |
87 | ␉␉␉␊ |
88 | ␉␉case 0x29708086:␊ |
89 | ␉␉␉type = CT_946GZ;␊ |
90 | ␉␉␉break;␊ |
91 | ␉␉␉␊ |
92 | ␉␉case 0x29a08086:␊ |
93 | ␉␉␉type = CT_G965;␊ |
94 | ␉␉␉break;␊ |
95 | ␉␉␉␊ |
96 | ␉␉case 0x29908086:␊ |
97 | ␉␉␉type = CT_Q965;␊ |
98 | ␉␉␉break;␊ |
99 | ␉␉␉␊ |
100 | ␉␉case 0x2a008086:␊ |
101 | ␉␉␉type = CT_965GM;␊ |
102 | ␉␉␉break;␊ |
103 | ␉␉␉␊ |
104 | ␉␉case 0x29e08086:␊ |
105 | ␉␉␉type = CT_X48;␊ |
106 | ␉␉␉break;␉␉␉␊ |
107 | ␉␉␉␊ |
108 | ␉␉case 0x2a408086:␊ |
109 | ␉␉␉type = CT_GM45;␊ |
110 | ␉␉␉break;␊ |
111 | ␉␉␉␊ |
112 | ␉␉case 0x2e108086:␊ |
113 | ␉␉case 0X2e908086:␊ |
114 | ␉␉␉type = CT_B43;␊ |
115 | ␉␉␉break;␊ |
116 | ␉␉␉␊ |
117 | ␉␉case 0x2e208086:␊ |
118 | ␉␉␉type = CT_P45;␊ |
119 | ␉␉␉break;␊ |
120 | ␉␉␉␊ |
121 | ␉␉case 0x2e308086:␊ |
122 | ␉␉␉type = CT_G41;␊ |
123 | ␉␉␉break;␊ |
124 | ␉␉␉␊ |
125 | ␉␉case 0x29c08086:␊ |
126 | ␉␉␉type = CT_G31;␊ |
127 | ␉␉␉break;␊ |
128 | ␉␉␉␊ |
129 | ␉␉case 0x29208086:␊ |
130 | ␉␉␉type = CT_G45;␊ |
131 | ␉␉␉break;␊ |
132 | ␉␉␉␊ |
133 | ␉␉case 0x81008086:␊ |
134 | ␉␉␉type = CT_500;␊ |
135 | ␉␉␉break;␊ |
136 | ␉␉␉␊ |
137 | ␉␉default:␊ |
138 | ␉␉␉type = CT_UNKWN;␊ |
139 | ␉␉␉break;␊ |
140 | ␉}␊ |
141 | ␉return type;␊ |
142 | }␊ |
143 | ␊ |
144 | ␊ |
145 | void gtfTimings(uint32_t x, uint32_t y, uint32_t freq,␊ |
146 | ␉␉␉␉ uint32_t *clock,␊ |
147 | ␉␉␉␉ uint16_t *hSyncStart, uint16_t *hSyncEnd, uint16_t *hBlank,␊ |
148 | ␉␉␉␉ uint16_t *vSyncStart, uint16_t *vSyncEnd, uint16_t *vBlank)␊ |
149 | {␊ |
150 | ␉uint32_t hbl, vbl, vfreq;␊ |
151 | ␉␊ |
152 | ␉vbl = y + (y+1)/(20000/(11*freq) - 1) + 1;␊ |
153 | ␉␊ |
154 | ␉vfreq = vbl * freq;␊ |
155 | ␉hbl = 16 * (int)(x * (30 - 300000 / vfreq) /␊ |
156 | ␉␉␉␉␉ + (70 + 300000 / vfreq) / 16 + 0);␊ |
157 | ␉␊ |
158 | ␉*vSyncStart = y;␊ |
159 | ␉*vSyncEnd = y + 3;␊ |
160 | ␉*vBlank = vbl;␉␊ |
161 | ␉*hSyncStart = x + hbl / 2 - (x + hbl + 50) / 100 * 8 ;␉␊ |
162 | ␉*hSyncEnd = x + hbl / 2;␉␊ |
163 | ␉*hBlank = x + hbl;␉␊ |
164 | ␉*clock = (x + hbl) * vfreq / 1000;␊ |
165 | }␊ |
166 | ␊ |
167 | ␊ |
168 | void getAspectRatio(sAspect* aspect, uint32_t x, uint32_t y)␊ |
169 | {␊ |
170 | ␉if ((y * 16 / 9) == x)␊ |
171 | ␉{␊ |
172 | ␉␉aspect->width = 16;␊ |
173 | ␉␉aspect->height = 9;␊ |
174 | ␉}␊ |
175 | ␉else if ((y * 16 / 10) == x)␊ |
176 | ␉{␊ |
177 | ␉␉aspect->width = 16;␊ |
178 | ␉␉aspect->height = 10;␊ |
179 | ␉}␊ |
180 | ␉else if ((y * 5 / 4) == x)␊ |
181 | ␉{␊ |
182 | ␉␉aspect->width = 5;␊ |
183 | ␉␉aspect->height = 4;␊ |
184 | ␉}␊ |
185 | ␉else if ((y * 15 / 9) == x)␊ |
186 | ␉{␊ |
187 | ␉␉aspect->width = 15;␊ |
188 | ␉␉aspect->height = 9;␊ |
189 | ␉}␊ |
190 | ␉else␊ |
191 | ␉{␊ |
192 | ␉␉aspect->width = 4;␊ |
193 | ␉␉aspect->height = 3;␊ |
194 | ␉}␊ |
195 | ␉PRINT("Aspect Ratio is %d/%d\n", aspect->width, aspect->height);␊ |
196 | }␊ |
197 | ␊ |
198 | ␊ |
199 | /*␊ |
200 | * initialize the mode tables chain␊ |
201 | * tablesCount represents the number of VESA tables in the vBios␊ |
202 | * return value is a pointer to the first table␊ |
203 | */␊ |
204 | sModeTable * intializeTables(vBiosMap * map, int tablesCount) {␊ |
205 | ␉map->modeTables = (sModeTable *)malloc(sizeof(sModeTable));␊ |
206 | ␉sModeTable * table = map->modeTables;␊ |
207 | ␉␊ |
208 | ␉PRINT("Creating %d Mode Tables\n", tablesCount);␊ |
209 | ␉␊ |
210 | ␉int i = tablesCount;␊ |
211 | ␉while ( i != 0 )␊ |
212 | ␉{␉␉␊ |
213 | ␉␉table->id = tablesCount - i;␊ |
214 | ␉␉PRINT("New table with id : %d\n", table->id);␊ |
215 | ␉␉␊ |
216 | ␉␉// opening the chain if it's the first table␊ |
217 | ␉␉if (i == tablesCount)␊ |
218 | ␉␉␉table->prev = NULL;␊ |
219 | ␉␉else // attache the table to the chain␊ |
220 | ␉␉␉table->prev = table; ␊ |
221 | ␉␉␊ |
222 | ␉␉//if there is more than one table, alloc the next one␊ |
223 | ␉␉if (i > 1)␊ |
224 | ␉␉{␊ |
225 | ␉␉␉table->next = (sModeTable *)malloc(sizeof(sModeTable));␊ |
226 | ␉␉␉table = table->next;␊ |
227 | ␉␉}␊ |
228 | ␉␉else // no more table, close the chain␊ |
229 | ␉␉␉table->next = NULL;␊ |
230 | ␉␉␊ |
231 | ␉␉i--;␊ |
232 | ␉}␊ |
233 | ␉␊ |
234 | ␉return map->modeTables;␊ |
235 | }␊ |
236 | ␊ |
237 | ␊ |
238 | void closeVbios(vBiosMap * map);␊ |
239 | ␊ |
240 | vBiosMap * openVbios(chipsetType forcedChipset)␊ |
241 | {␊ |
242 | ␉uint32_t z;␊ |
243 | ␉vBiosMap * map = NEW(vBiosMap);␊ |
244 | ␉␊ |
245 | ␉for(z = 0; z < sizeof(vBiosMap); z++)␊ |
246 | ␉␉((char*)map)[z] = 0;␊ |
247 | ␉␊ |
248 | ␉/*␊ |
249 | ␉ * Determine chipset␊ |
250 | ␉ */␊ |
251 | ␉␊ |
252 | ␉if (forcedChipset == CT_UNKWN)␊ |
253 | ␉{␊ |
254 | ␉␉map->chipsetId = getChipsetId();␊ |
255 | ␉␉map->chipset = getChipset(map->chipsetId);␊ |
256 | ␉␉PRINT("Chipset is %s (pci id 0x%x)\n",chipsetTypeNames[map->chipset], map->chipsetId);␊ |
257 | ␉}␊ |
258 | ␉else if (forcedChipset != CT_UNKWN)␊ |
259 | ␉{␊ |
260 | ␉␉map->chipset = forcedChipset;␊ |
261 | ␉}␊ |
262 | ␉else␊ |
263 | ␉{␊ |
264 | ␉␉map->chipset = CT_915GM;␊ |
265 | ␉}␊ |
266 | ␉ ␊ |
267 | ␉/*␊ |
268 | ␉ * Map the video bios to memory␊ |
269 | ␉ */␊ |
270 | ␉␊ |
271 | ␉map->biosPtr=(uint8_t*)VBIOS_START;␊ |
272 | ␉␊ |
273 | ␉/*␊ |
274 | ␉ * Common initialisation␊ |
275 | ␉ */␊ |
276 | ␉␊ |
277 | ␉map->hasSwitched = false;␊ |
278 | ␉␊ |
279 | ␉/*␊ |
280 | ␉ * check if we have ATI Radeon and open atombios␊ |
281 | ␉ */␊ |
282 | ␉atiBiosTables atiTables;␊ |
283 | ␉␊ |
284 | ␉atiTables.base = map->biosPtr;␊ |
285 | ␉atiTables.atomRomHeader = (atomRomHeader *) (map->biosPtr + *(uint16_t *) (map->biosPtr + OFFSET_TO_POINTER_TO_ATOM_ROM_HEADER)); ␊ |
286 | ␉␊ |
287 | ␉if (strcmp ((char *) atiTables.atomRomHeader->firmWareSignature, "ATOM") == 0)␊ |
288 | ␉{␊ |
289 | ␉␉map->bios = BT_ATI_1;␊ |
290 | ␉␉PRINT("We have an AtomBios Card\n");␊ |
291 | ␉␉return openAtiVbios(map, atiTables);␊ |
292 | ␉}␊ |
293 | ␊ |
294 | ␊ |
295 | ␉/*␊ |
296 | ␉ * check if we have NVidia␊ |
297 | ␉ */␊ |
298 | ␉if (map->bios != BT_ATI_1)␊ |
299 | ␉{␊ |
300 | ␉␉int i = 0;␊ |
301 | ␉␉while (i < 512) // we don't need to look through the whole bios, just the first 512 bytes␊ |
302 | ␉␉{␊ |
303 | ␉␉␉if ((map->biosPtr[i] == 'N') ␊ |
304 | ␉␉␉␉&& (map->biosPtr[i+1] == 'V') ␊ |
305 | ␉␉␉␉&& (map->biosPtr[i+2] == 'I') ␊ |
306 | ␉␉␉␉&& (map->biosPtr[i+3] == 'D')) ␊ |
307 | ␉␉␉{␊ |
308 | ␉␉␉␉map->bios = BT_NVDA;␊ |
309 | ␉␉␉␉PRINT("We have an NVIDIA Card\n");␊ |
310 | ␉␉␉␉return openNvidiaVbios(map);␊ |
311 | ␉␉␉␉break;␊ |
312 | ␉␉␉}␊ |
313 | ␉␉␉i++;␊ |
314 | ␉␉}␊ |
315 | ␉}␊ |
316 | ␉␊ |
317 | ␉/*␊ |
318 | ␉ * check if we have Intel␊ |
319 | ␉ */␊ |
320 | ␉ ␊ |
321 | ␉if ((map->bios != BT_ATI_1) && (map->bios != BT_NVDA))␊ |
322 | ␉{␊ |
323 | ␉␉int i = 0;␊ |
324 | ␉␉while (i < VBIOS_SIZE)␊ |
325 | ␉␉{␊ |
326 | ␉␉␉if ((map->biosPtr[i] == 'I') ␊ |
327 | ␉␉␉␉&& (map->biosPtr[i+1] == 'n') ␊ |
328 | ␉␉␉␉&& (map->biosPtr[i+2] == 't') ␊ |
329 | ␉␉␉␉&& (map->biosPtr[i+3] == 'e') ␊ |
330 | ␉␉␉␉&& (map->biosPtr[i+4] == 'l')) ␊ |
331 | ␉␉␉{␊ |
332 | ␉␉␉␉map->bios = BT_1;␊ |
333 | ␉␉␉␉PRINT("We have an Intel Card\n");␊ |
334 | ␉␉␉␉saveVbios(map);␊ |
335 | ␉␉␉␉return openIntelVbios(map);␊ |
336 | ␉␉␉␉break;␊ |
337 | ␉␉␉}␊ |
338 | ␉␉␉i++;␊ |
339 | ␉␉}␊ |
340 | ␉}␊ |
341 | ␉␊ |
342 | ␉/*␊ |
343 | ␉ * Unidentified Chipset␊ |
344 | ␉ */␊ |
345 | ␉␊ |
346 | ␉if ( (map->chipset == CT_UNKWN) || ((map->bios != BT_ATI_1) && (map->bios != BT_NVDA) && (map->bios != BT_1)) )␊ |
347 | ␉{␊ |
348 | ␉␉PRINT("Unknown chipset type and unrecognized bios.\n");␊ |
349 | ␉␉␊ |
350 | ␉␉PRINT("autoresolution only works with Intel 800/900 series graphic chipsets.\n");␊ |
351 | ␉␉␊ |
352 | ␉␉PRINT("Chipset Id: %x\n", map->chipsetId);␊ |
353 | ␉␉closeVbios(map);␊ |
354 | ␉␉return 0;␊ |
355 | ␉}␊ |
356 | ␊ |
357 | ␉/*␊ |
358 | ␉ * Should never get there ␊ |
359 | ␉ */␊ |
360 | ␉return 0;␊ |
361 | }␊ |
362 | ␊ |
363 | void closeVbios(vBiosMap * map)␊ |
364 | {␊ |
365 | ␉PRINT("Closing VBios\n");␊ |
366 | ␉//make sure to turn autoResolution off␊ |
367 | ␉if (gAutoResolution == TRUE)␊ |
368 | ␉␉gAutoResolution = FALSE;␊ |
369 | ␉␊ |
370 | ␉// if we saved the vBios, free the copy␊ |
371 | ␉if (map->biosBackupPtr != NULL)␊ |
372 | ␉{␊ |
373 | ␉␉PRINT("Freeing biosBackupPtr\t");␊ |
374 | ␉␉FREE(map->biosBackupPtr);␊ |
375 | ␉␉PRINT("[OK]\n");␊ |
376 | ␉}␊ |
377 | ␉␊ |
378 | ␉// free table backups if any␊ |
379 | ␉sModeTable * table = map->modeTables;␊ |
380 | ␉while (table != NULL)␊ |
381 | ␉{␉␉␊ |
382 | ␉␉if (table->backup != NULL)␊ |
383 | ␉␉{␊ |
384 | ␉␉␉PRINT("Table #%d : Freeing backup\t", table->id);␊ |
385 | ␉␉␉FREE(table->backup);␊ |
386 | ␉␉␉PRINT("[OK]\n");␊ |
387 | ␉␉}␊ |
388 | ␉␉␊ |
389 | ␉␉if (table != NULL)␊ |
390 | ␉␉{ ␊ |
391 | ␉␉␉PRINT("Table #%d : Freeing\t\t", table->id);␊ |
392 | ␉␉␉FREE(table);␊ |
393 | ␉␉␉PRINT("[OK]\n");␊ |
394 | ␉␉}␊ |
395 | ␉␉␊ |
396 | ␉␉if (table->next == NULL)␊ |
397 | ␉␉␉break;␊ |
398 | ␉␉␊ |
399 | ␉␉table = table->next;␊ |
400 | ␉}␊ |
401 | ␉␊ |
402 | ␉PRINT("Freeing map\t\t\t");␊ |
403 | ␉FREE(map);␊ |
404 | ␉PRINT("[OK]\n");␊ |
405 | }␊ |
406 | ␊ |
407 | void unlockVbios(vBiosMap * map)␊ |
408 | {␊ |
409 | ␊ |
410 | ␉map->unlocked = TRUE;␊ |
411 | ␉ ␊ |
412 | ␉switch (map->chipset)␊ |
413 | ␉{␊ |
414 | ␉␉case CT_UNKWN:␊ |
415 | ␉␉␉break;␊ |
416 | ␉␉case CT_830:␊ |
417 | ␉␉case CT_855GM:␊ |
418 | ␉␉␉outl(0xcf8, 0x8000005a);␊ |
419 | ␉␉␉map->b1 = inb(0xcfe);␊ |
420 | ␉␉␉␉␊ |
421 | ␉␉␉outl(0xcf8, 0x8000005a);␊ |
422 | ␉␉␉outb(0xcfe, 0x33);␊ |
423 | ␉␉␉break;␊ |
424 | ␉␉case CT_845G:␊ |
425 | ␉␉case CT_865G:␊ |
426 | ␉␉case CT_915G:␊ |
427 | ␉␉case CT_915GM:␊ |
428 | ␉␉case CT_945G:␊ |
429 | ␉␉case CT_945GM:␊ |
430 | ␉␉case CT_945GME:␊ |
431 | ␉␉case CT_946GZ:␊ |
432 | ␉␉case CT_955X:␊ |
433 | ␉␉case CT_G965:␊ |
434 | ␉␉case CT_Q965:␊ |
435 | ␉␉case CT_965GM:␊ |
436 | ␉␉case CT_975X:␊ |
437 | ␉␉case CT_P35:␊ |
438 | ␉␉case CT_X48:␊ |
439 | ␉␉case CT_B43:␊ |
440 | ␉␉case CT_Q45:␊ |
441 | ␉␉case CT_P45:␊ |
442 | ␉␉case CT_GM45:␊ |
443 | ␉␉case CT_G41:␊ |
444 | ␉␉case CT_G31:␊ |
445 | ␉␉case CT_G45:␊ |
446 | ␉␉case CT_500:␊ |
447 | ␊ |
448 | ␉␉␉outl(0xcf8, 0x80000090);␊ |
449 | ␉␉␉map->b1 = inb(0xcfd);␊ |
450 | ␉␉␉map->b2 = inb(0xcfe);␊ |
451 | ␉␉␉outl(0xcf8, 0x80000090);␊ |
452 | ␉␉␉outb(0xcfd, 0x33);␊ |
453 | ␉␉␉outb(0xcfe, 0x33);␊ |
454 | ␉␉break;␊ |
455 | ␉}␊ |
456 | ␉␊ |
457 | ␉#if DEBUG␊ |
458 | ␉{␊ |
459 | ␉␉uint32_t t = inl(0xcfc);␊ |
460 | ␉␉PRINT("unlock PAM: (0x%08x)\n", t);␊ |
461 | ␉}␊ |
462 | #endif␊ |
463 | }␊ |
464 | ␊ |
465 | void relockVbios(vBiosMap * map)␊ |
466 | {␊ |
467 | ␊ |
468 | ␉map->unlocked = FALSE;␊ |
469 | ␉␊ |
470 | ␉switch (map->chipset)␊ |
471 | ␉{␊ |
472 | ␉␉case CT_UNKWN:␊ |
473 | ␉␉␉break;␊ |
474 | ␉␉case CT_830:␊ |
475 | ␉␉case CT_855GM:␊ |
476 | ␉␉␉outl(0xcf8, 0x8000005a);␊ |
477 | ␉␉␉outb(0xcfe, map->b1);␊ |
478 | ␉␉␉break;␊ |
479 | ␉␉case CT_845G:␊ |
480 | ␉␉case CT_865G:␊ |
481 | ␉␉case CT_915G:␊ |
482 | ␉␉case CT_915GM:␊ |
483 | ␉␉case CT_945G:␊ |
484 | ␉␉case CT_945GM:␊ |
485 | ␉␉case CT_945GME:␊ |
486 | ␉␉case CT_946GZ:␊ |
487 | ␉␉case CT_955X:␊ |
488 | ␉␉case CT_G965:␊ |
489 | ␉␉case CT_Q965:␊ |
490 | ␉␉case CT_965GM:␊ |
491 | ␉␉case CT_975X:␊ |
492 | ␉␉case CT_P35:␊ |
493 | ␉␉case CT_X48:␊ |
494 | ␉␉case CT_B43:␊ |
495 | ␉␉case CT_Q45:␊ |
496 | ␉␉case CT_P45:␊ |
497 | ␉␉case CT_GM45:␊ |
498 | ␉␉case CT_G41:␊ |
499 | ␉␉case CT_G31:␊ |
500 | ␉␉case CT_G45:␊ |
501 | ␉␉case CT_500:␊ |
502 | ␉␉␉␊ |
503 | ␉␉␉outl(0xcf8, 0x80000090);␊ |
504 | ␉␉␉outb(0xcfd, map->b1);␊ |
505 | ␉␉␉outb(0xcfe, map->b2);␊ |
506 | ␉␉␉break;␊ |
507 | ␉}␊ |
508 | ␉␊ |
509 | ␉#if DEBUG␊ |
510 | ␉{␊ |
511 | uint32_t t = inl(0xcfc);␊ |
512 | ␉␉PRINT("relock PAM: (0x%08x)\n", t);␊ |
513 | ␉}␊ |
514 | ␉#endif␊ |
515 | }␊ |
516 | ␊ |
517 | /*␊ |
518 | * saveVbios - save the entire vBios in case the patch has to be removed␊ |
519 | */␊ |
520 | void saveVbios(vBiosMap * map)␊ |
521 | {␊ |
522 | ␉map->biosBackupPtr = malloc(VBIOS_SIZE);␊ |
523 | ␉bcopy((const uint8_t *)0xC0000, map->biosBackupPtr, VBIOS_SIZE);␊ |
524 | }␊ |
525 | ␊ |
526 | /*␊ |
527 | * restoreVbios - restore the vBios backup or table backups if any␊ |
528 | */␊ |
529 | void restoreVbios(vBiosMap * map)␊ |
530 | {␊ |
531 | ␉if ((map->bios == BT_ATI_1) || (map->bios == BT_ATI_2) || (map->bios == BT_NVDA))␊ |
532 | ␉{␊ |
533 | ␉␉restoreTables(map, map->modeTables);␊ |
534 | ␉}␊ |
535 | ␉else␊ |
536 | ␉{␊ |
537 | ␉␉unlockVbios(map);␊ |
538 | ␉␉bcopy(map->biosBackupPtr,(uint8_t *)0xC0000, VBIOS_SIZE);␊ |
539 | ␉␉relockVbios(map);␊ |
540 | ␉}␊ |
541 | }␊ |
542 | ␊ |
543 | /*␊ |
544 | * saveTables - save the tables in case the patch has to be removed␊ |
545 | */␊ |
546 | void saveTables(sModeTable * table)␊ |
547 | {␊ |
548 | ␉while (table != NULL)␊ |
549 | ␉{␊ |
550 | ␉␉table->backup = (uint8_t *)malloc(table->size);␊ |
551 | ␉␉bcopy((const uint8_t *)table->pointer, table->backup, table->size);␊ |
552 | ␉␉table = table->next;␊ |
553 | ␉}␊ |
554 | }␊ |
555 | ␊ |
556 | /*␊ |
557 | * restoreTables - restore tables backup ␊ |
558 | */␊ |
559 | void restoreTables(vBiosMap * map, sModeTable * table)␊ |
560 | {␊ |
561 | ␉unlockVbios(map);␊ |
562 | ␉while (table != NULL)␊ |
563 | ␉{␊ |
564 | ␉␉bcopy(table->backup, (uint8_t *)table->pointer, table->size);␊ |
565 | ␉␉table = table->next;␊ |
566 | ␉}␊ |
567 | ␉relockVbios(map);␊ |
568 | }␊ |
569 | ␊ |
570 | /*␊ |
571 | * patchVbios - call the vendor specific function to patch the VESA tables␊ |
572 | * x & y are horizontal and vertical dimensions respectively, in pixels␊ |
573 | * for GMA and ATI, only first mode in Table is patched␊ |
574 | *␊ |
575 | * each vendor specific function have the same form :␊ |
576 | * bool vendorSetMode_type(sModeTable * table, uint8_t index, uint32_t * x, uint32_t * y);␊ |
577 | * where 'table' is the VESA table to patch, 'index' is the index of the mode in table,␊ |
578 | * 'x' & 'y' are pointer to the target resolution and return the next resolution in table.␊ |
579 | */␊ |
580 | void patchVbios(vBiosMap * map, uint32_t x, uint32_t y, uint32_t bp, uint32_t hTotal, uint32_t vTotal)␊ |
581 | {␊ |
582 | ␉uint32_t i = 0;␊ |
583 | ␉␊ |
584 | ␉sModeTable * table = map->modeTables;␊ |
585 | ␉␊ |
586 | ␉// save the target resolution for future use␊ |
587 | ␉map->currentX = x;␊ |
588 | ␉map->currentY = y;␊ |
589 | ␉␊ |
590 | ␉unlockVbios(map);␊ |
591 | ␉␊ |
592 | ␉// Get the aspect ratio for the requested mode␊ |
593 | ␉getAspectRatio(&map->aspectRatio, x, y);␊ |
594 | ␉␊ |
595 | ␉i = 0;␊ |
596 | ␉␊ |
597 | ␉// Call the vendor specific function for each available VESA Table␊ |
598 | ␉table = map->modeTables;␊ |
599 | ␉while (table != NULL)␊ |
600 | ␉{␊ |
601 | ␉␉//reset resolution value before treating a new table␊ |
602 | ␉␉x = map->currentX;␊ |
603 | ␉␉y = map->currentY;␊ |
604 | ␉␉␊ |
605 | ␉␉PRINT("Patching Table #%d : \n", table->id);␊ |
606 | ␉␉␊ |
607 | ␉␉map->setMode(table, i, &x, &y);␊ |
608 | #ifdef AUTORES_DEBUG␊ |
609 | ␉␉getc();␊ |
610 | #endif␊ |
611 | ␊ |
612 | ␉␉table = table->next;␊ |
613 | ␉}␊ |
614 | ␉␊ |
615 | ␉relockVbios(map);␊ |
616 | ␉return;␊ |
617 | } |