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