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