Chameleon

Chameleon Svn Source Tree

Root/branches/ErmaC/Enoch/i386/libsaio/acpi_patcher.c

1/*
2 * Copyright 2008 mackerintel
3 * 2010 mojodojo, 2012 slice
4 */
5
6#include "libsaio.h"
7#include "boot.h"
8#include "bootstruct.h"
9#include "acpi.h"
10#include "efi_tables.h"
11#include "fake_efi.h"
12#include "acpi_patcher.h"
13#include "platform.h"
14#include "cpu.h"
15#include "aml_generator.h"
16#include "state_generator.h"
17
18#ifndef DEBUG_ACPI
19#define DEBUG_ACPI 0
20#endif
21
22#if DEBUG_ACPI==2
23#define DBG(x...) {printf(x); sleep(1);}
24#elif DEBUG_ACPI==1
25#define DBG(x...) printf(x)
26#else
27#define DBG(x...) msglog(x)
28#endif
29
30// Slice: New signature compare function
31boolean_t tableSign(char *table, const char *sgn)
32{
33int i;
34for (i = 0; i < 4; i++)
35{
36if ((table[i] & ~0x20) != (sgn[i] & ~0x20))
37{
38return false;
39}
40}
41return true;
42}
43
44/* Gets the ACPI 1.0 RSDP address */
45static struct acpi_2_rsdp *getAddressOfAcpiTable()
46{
47/* TODO: Before searching the BIOS space we are supposed to search the first 1K of the EBDA */
48
49void *acpi_addr = (void*)ACPI_RANGE_START;
50
51for(; acpi_addr <= (void*)ACPI_RANGE_END; acpi_addr += 16)
52{
53if(*(uint64_t *)acpi_addr == ACPI_SIGNATURE_UINT64_LE)
54{
55uint8_t csum = checksum8(acpi_addr, 20);
56if (csum == 0)
57{
58// Only return the table if it is a true version 1.0 table (Revision 0)
59if(((struct acpi_2_rsdp*)acpi_addr)->Revision == 0)
60return acpi_addr;
61}
62}
63}
64return NULL;
65}
66
67/* Gets the ACPI 2.0 RSDP address */
68static struct acpi_2_rsdp *getAddressOfAcpi20Table()
69{
70/* TODO: Before searching the BIOS space we are supposed to search the first 1K of the EBDA */
71
72void *acpi_addr = (void *)ACPI_RANGE_START;
73
74for(; acpi_addr <= (void *)ACPI_RANGE_END; acpi_addr += 16)
75{
76if(*(uint64_t *)acpi_addr == ACPI_SIGNATURE_UINT64_LE)
77{
78uint8_t csum = checksum8(acpi_addr, 20);
79
80/* Only assume this is a 2.0 or better table if the revision is greater than 0
81 * NOTE: ACPI 3.0 spec only seems to say that 1.0 tables have revision 1
82 * and that the current revision is 2.. I am going to assume that rev > 0 is 2.0.
83 */
84
85if(csum == 0 && (((struct acpi_2_rsdp*)acpi_addr)->Revision > 0))
86{
87uint8_t csum2 = checksum8(acpi_addr, sizeof(struct acpi_2_rsdp));
88if(csum2 == 0)
89{
90return acpi_addr;
91}
92}
93}
94}
95return NULL;
96}
97
98/* The folowing ACPI Table search algo. should be reused anywhere needed:*/
99/* WARNING: outDirspec string will be overwritten by subsequent calls! */
100int search_and_get_acpi_fd(const char *filename, const char **outDirspec)
101{
102int fd = 0;
103static char dirSpec[512];
104
105// Try finding 'filename' in the usual places
106// Start searching any potential location for ACPI Table
107strncpy(dirSpec, filename, sizeof(dirSpec) );
108fd = open(dirSpec, 0);
109if (fd < 0)
110{
111snprintf(dirSpec, sizeof(dirSpec), "/Extra/%s", filename);
112fd = open(dirSpec, 0);
113if (fd < 0)
114{
115snprintf(dirSpec, sizeof(dirSpec), "bt(0,0)/Extra/%s", filename);
116fd = open(dirSpec, 0);
117if (fd < 0)
118{
119// NOT FOUND:
120DBG("ACPI Table not found: %s\n", filename);
121*dirSpec = '\0';
122}
123}
124}
125
126if (outDirspec) *outDirspec = dirSpec;
127return fd;
128}
129
130void *loadACPITable (const char *filename)
131{
132const char *dirspec = NULL;
133
134int fd = search_and_get_acpi_fd(filename, &dirspec);
135
136if (fd >= 0)
137{
138void *tableAddr = (void *)AllocateKernelMemory(file_size(fd));
139if (tableAddr)
140{
141if (read(fd, tableAddr, file_size(fd)) != file_size(fd))
142{
143DBG("Couldn't read table %s\n", dirspec);
144free(tableAddr);
145close(fd);
146return NULL;
147}
148
149DBG("Table %s read and stored at: %x\n", dirspec, tableAddr);
150close(fd);
151return tableAddr;
152}
153close(fd);
154DBG("Couldn't allocate memory for table: %s.\n", dirspec);
155}
156//printf("Couldn't find table %s\n", filename);
157return NULL;
158}
159
160struct acpi_2_fadt *patch_fadt(struct acpi_2_fadt *fadt, struct acpi_2_dsdt *new_dsdt)
161{
162extern void setupSystemType();
163
164struct acpi_2_fadt *fadt_mod = NULL;
165bool fadt_rev2_needed = false;
166bool fix_restart;
167bool fix_restart_ps2;
168const char * value;
169
170// Restart Fix
171if (Platform.CPU.Vendor == 0x756E6547)
172{/* Intel */
173fix_restart = true;
174fix_restart_ps2 = false;
175if ( getBoolForKey(kPS2RestartFix, &fix_restart_ps2, &bootInfo->chameleonConfig) && fix_restart_ps2)
176{
177fix_restart = true;
178}
179else
180{
181getBoolForKey(kRestartFix, &fix_restart, &bootInfo->chameleonConfig);
182}
183}
184else
185{
186DBG("\tNot an Intel platform, FACP Restart Fix will not be applied!\n");
187fix_restart = false;
188}
189
190if (fix_restart)
191{
192fadt_rev2_needed = true;
193}
194
195// Allocate new fadt table
196if ((fadt->Length < 0x84) && fadt_rev2_needed)
197{
198fadt_mod = (struct acpi_2_fadt *)AllocateKernelMemory(0x84);
199memcpy(fadt_mod, fadt, fadt->Length);
200fadt_mod->Length = 0x84;
201fadt_mod->Revision = 0x02; // FACP rev 2 (ACPI 1.0B MS extensions)
202}
203else
204{
205fadt_mod = (struct acpi_2_fadt *)AllocateKernelMemory(fadt->Length);
206memcpy(fadt_mod, fadt, fadt->Length);
207}
208// Determine system type / PM_Model
209if ( (value=getStringForKey(kSystemType, &bootInfo->chameleonConfig))!=NULL)
210{
211if (Platform.Type > 6)
212{
213if(fadt_mod->PM_Profile<=6)
214{
215Platform.Type = fadt_mod->PM_Profile; // get the fadt if correct
216}
217else
218{
219Platform.Type = 1;/* Set a fixed value (Desktop) */
220}
221DBG("Error: system-type must be 0..6. Defaulting to %d !\n", Platform.Type);
222}
223else
224{
225Platform.Type = (unsigned char) strtoul(value, NULL, 10);
226}
227}
228// Set PM_Profile from System-type if only user wanted this value to be forced
229if (fadt_mod->PM_Profile != Platform.Type)
230{
231if (value)
232{
233// user has overriden the SystemType so take care of it in FACP
234DBG("FADT: changing PM_Profile from 0x%02x to 0x%02x\n", fadt_mod->PM_Profile, Platform.Type);
235fadt_mod->PM_Profile = Platform.Type;
236}
237else
238{
239// PM_Profile has a different value and no override has been set, so reflect the user value to ioregs
240Platform.Type = fadt_mod->PM_Profile <= 6 ? fadt_mod->PM_Profile : 1;
241}
242}
243// We now have to write the systemm-type in ioregs: we cannot do it before in setupDeviceTree()
244// because we need to take care of FACP original content, if it is correct.
245setupSystemType();
246
247// Patch FACP to fix restart
248if (fix_restart)
249{
250if (fix_restart_ps2)
251{
252fadt_mod->Flags|= 0x400;
253fadt_mod->Reset_SpaceID= 0x01; // System I/O
254fadt_mod->Reset_BitWidth= 0x08; // 1 byte
255fadt_mod->Reset_BitOffset= 0x00; // Offset 0
256fadt_mod->Reset_AccessWidth= 0x01; // Byte access
257fadt_mod->Reset_Address= 0x64; // Address of the register
258fadt_mod->Reset_Value= 0xfe; // Value to write to reset the system
259DBG("\tFACP PS2 Restart Fix applied!\n");
260}
261else
262{
263fadt_mod->Flags|= 0x400;
264fadt_mod->Reset_SpaceID= 0x01; // System I/O
265fadt_mod->Reset_BitWidth= 0x08; // 1 byte
266fadt_mod->Reset_BitOffset= 0x00; // Offset 0
267fadt_mod->Reset_AccessWidth= 0x01; // Byte access
268fadt_mod->Reset_Address= 0x0cf9; // Address of the register
269fadt_mod->Reset_Value= 0x06; // Value to write to reset the system
270DBG("\tFACP Restart Fix applied!\n");
271}
272
273}
274
275// Bungo: Save Hardware Signature (machine-signature)
276if ((fadt_mod->FACS > 0) && (fadt_mod->FACS < 0xFFFFFFFF) && (((struct acpi_2_facs *)fadt_mod->FACS)->Length >= 64))
277{
278Platform.HWSignature = ((struct acpi_2_facs *)fadt_mod->FACS)->HWSignature;
279DBG("\tHardware Signature=0x%08X: using.\n", Platform.HWSignature);
280}
281else
282{
283Platform.HWSignature = 0;
284DBG("\tFixing Hardware Signature=0x%08X.\n", Platform.HWSignature);
285}
286
287// Patch DSDT address if we have loaded DSDT.aml
288if (new_dsdt)
289{
290DBG("DSDT: Old @%x,%x, ",fadt_mod->DSDT,fadt_mod->X_DSDT);
291
292fadt_mod->DSDT = (uint32_t)new_dsdt;
293if ((uint32_t)(&(fadt_mod->X_DSDT)) - (uint32_t)fadt_mod + 8<=fadt_mod->Length)
294{
295fadt_mod->X_DSDT = (uint32_t)new_dsdt;
296}
297
298DBG("New @%x,%x\n",fadt_mod->DSDT,fadt_mod->X_DSDT);
299
300DBG("FADT: Using custom DSDT!\n");
301}
302
303// Correct the checksum
304fadt_mod->Checksum=0;
305fadt_mod->Checksum=256-checksum8(fadt_mod,fadt_mod->Length);
306
307return fadt_mod;
308}
309
310/* Setup ACPI without replacing DSDT. */
311int setupAcpiNoMod()
312{
313//addConfigurationTable(&gEfiAcpiTableGuid, getAddressOfAcpiTable(), "ACPI");
314//addConfigurationTable(&gEfiAcpi20TableGuid, getAddressOfAcpi20Table(), "ACPI_20");
315/* XXX aserebln why uint32 cast if pointer is uint64 ? */
316acpi10_p = (uint64_t)(uint32_t)getAddressOfAcpiTable();
317acpi20_p = (uint64_t)(uint32_t)getAddressOfAcpi20Table();
318addConfigurationTable(&gEfiAcpiTableGuid, &acpi10_p, "ACPI");
319if(acpi20_p)
320{
321addConfigurationTable(&gEfiAcpi20TableGuid, &acpi20_p, "ACPI_20");
322}
323else
324{
325DBG("No ACPI 2.\n");
326}
327return 1;
328}
329
330/* Setup ACPI. Replace DSDT if DSDT.aml is found */
331int setupAcpi(void)
332{
333int version;
334void *new_dsdt = NULL;
335
336
337const char *filename;
338char dirSpec[128];
339int len = 0;
340
341// always reset cpu count to 0 when injecting new acpi
342acpi_cpu_count = 0;
343
344/* Try using the file specified with the DSDT option */
345if (getValueForKey(kDSDT, &filename, &len, &bootInfo->chameleonConfig))
346{
347strncpy(dirSpec, filename, sizeof(dirSpec) );
348}
349else
350{
351strcpy(dirSpec, "DSDT.aml");
352//verbose("dirSpec, DSDT.aml");
353}
354
355// Load replacement DSDT
356new_dsdt = loadACPITable(dirSpec);
357
358// Mozodojo: going to patch FACP and load SSDT's even if DSDT.aml is not present
359/*if (!new_dsdt)
360 {
361 return setupAcpiNoMod();
362 }*/
363
364// Mozodojo: Load additional SSDTs
365struct acpi_2_ssdt *new_ssdt[32]; // 30 + 2 additional tables for pss & cst
366int ssdt_count=0;
367
368// SSDT Options
369bool drop_ssdt = false, generate_pstates = false, generate_cstates = false;
370
371getBoolForKey(kDropSSDT, &drop_ssdt, &bootInfo->chameleonConfig);
372getBoolForKey(kGeneratePStates, &generate_pstates, &bootInfo->chameleonConfig);
373getBoolForKey(kGenerateCStates, &generate_cstates, &bootInfo->chameleonConfig);
374//getBoolForKey(kGenerateTStates, &generate_tstates, &bootInfo->chameleonConfig);
375
376DBG("Generating P-States config: %s\n", generate_pstates ? "YES" : "NO");
377DBG("Generating C-States config: %s\n", generate_cstates ? "YES" : "NO");
378//DBG("Generating T-States config: %s\n", generate_tstates ? "YES" : "NO");
379
380{
381int i;
382
383for (i = 0; i < 30; i++)
384{
385char filename[512];
386
387if (i > 0)
388{
389sprintf(filename, "SSDT-%d.aml", i);
390}
391else
392{
393strcpy(filename, "SSDT.aml");
394}
395
396if ( (new_ssdt[ssdt_count] = loadACPITable(filename)) )
397{
398ssdt_count++;
399}
400else
401{
402break;
403}
404}
405}
406
407// Do the same procedure for both versions of ACPI
408for (version = 0; version < 2; version++)
409{
410struct acpi_2_rsdp *rsdp, *rsdp_mod;
411struct acpi_2_rsdt *rsdt, *rsdt_mod;
412int rsdplength;
413
414// Find original rsdp
415rsdp = (struct acpi_2_rsdp *)(version ? getAddressOfAcpi20Table() : getAddressOfAcpiTable());
416if (!rsdp)
417{
418DBG("No ACPI version %d found. Ignoring\n", version+1);
419if (version)
420{
421addConfigurationTable(&gEfiAcpi20TableGuid, NULL, "ACPI_20");
422}
423else
424{
425addConfigurationTable(&gEfiAcpiTableGuid, NULL, "ACPI");
426}
427continue;
428}
429rsdplength = version ? rsdp->Length : 20;
430
431DBG("RSDP version %d found @%x. Length=%d\n",version+1,rsdp,rsdplength);
432
433/* FIXME: no check that memory allocation succeeded
434 * Copy and patch RSDP,RSDT, XSDT and FADT
435 * For more info see ACPI Specification pages 110 and following
436 */
437
438rsdp_mod = (struct acpi_2_rsdp *) AllocateKernelMemory(rsdplength);
439memcpy(rsdp_mod, rsdp, rsdplength);
440
441rsdt = (struct acpi_2_rsdt *)rsdp->RsdtAddress;
442
443DBG("RSDT @%x, Length %d\n",rsdt, rsdt ? rsdt->Length : 0);
444
445if (rsdt && (uint32_t)rsdt !=0xffffffff && rsdt->Length < 0x10000)
446{
447uint32_t *rsdt_entries;
448int rsdt_entries_num;
449int dropoffset = 0, i;
450
451// mozo: using malloc cos I didn't found how to free already allocated kernel memory
452rsdt_mod = (struct acpi_2_rsdt *)malloc(rsdt->Length);
453memcpy(rsdt_mod, rsdt, rsdt->Length);
454rsdp_mod->RsdtAddress = (uint32_t)rsdt_mod;
455rsdt_entries_num = (rsdt_mod->Length - sizeof(struct acpi_2_rsdt)) / 4;
456rsdt_entries = (uint32_t *)(rsdt_mod + 1);
457for (i = 0; i < rsdt_entries_num; i++)
458{
459char *table=(char *)(rsdt_entries[i]);
460if (!table)
461{
462continue;
463}
464
465DBG("TABLE %c%c%c%c,",table[0],table[1],table[2],table[3]);
466
467rsdt_entries[i-dropoffset]=rsdt_entries[i];
468
469if (drop_ssdt && tableSign(table, "SSDT"))
470{
471DBG("OEM SSDT tables was dropped\n");
472dropoffset++;
473continue;
474}
475
476if (tableSign(table, "DSDT"))
477{
478DBG("DSDT found\n");
479DBG("Custom DSDT table was found\n");
480if(new_dsdt)
481{
482rsdt_entries[i-dropoffset] = (uint32_t)new_dsdt;
483}
484
485continue;
486}
487
488if (tableSign(table, "FACP"))
489{
490struct acpi_2_fadt *fadt, *fadt_mod;
491fadt=(struct acpi_2_fadt *)rsdt_entries[i];
492
493DBG("FADT found @%x, Length %d\n",fadt, fadt->Length);
494
495if (!fadt || (uint32_t)fadt == 0xffffffff || fadt->Length>0x10000)
496{
497DBG("FADT incorrect. Not modified\n");
498continue;
499}
500
501fadt_mod = patch_fadt(fadt, new_dsdt);
502rsdt_entries[i-dropoffset] = (uint32_t)fadt_mod;
503
504// Generate _CST SSDT
505if (generate_cstates && (new_ssdt[ssdt_count] = generate_cst_ssdt(fadt_mod)))
506{
507DBG("\tC-States generated.\n");
508generate_cstates = false; // Generate SSDT only once!
509ssdt_count++;
510}
511
512// Generating _PSS SSDT
513if (generate_pstates && (new_ssdt[ssdt_count] = generate_pss_ssdt((void*)fadt_mod->DSDT)))
514{
515DBG("\tP-States generated.\n");
516generate_pstates = false; // Generate SSDT only once!
517ssdt_count++;
518}
519continue;
520}
521}
522DBG("\n");
523
524// Allocate rsdt in Kernel memory area
525rsdt_mod->Length += 4*ssdt_count - 4*dropoffset;
526struct acpi_2_rsdt *rsdt_copy = (struct acpi_2_rsdt *)AllocateKernelMemory(rsdt_mod->Length);
527memcpy(rsdt_copy, rsdt_mod, rsdt_mod->Length);
528free(rsdt_mod);
529rsdt_mod = rsdt_copy;
530rsdp_mod->RsdtAddress = (uint32_t)rsdt_mod;
531rsdt_entries_num = (rsdt_mod->Length-sizeof(struct acpi_2_rsdt)) / 4;
532rsdt_entries = (uint32_t *)(rsdt_mod + 1);
533
534// Mozodojo: Insert additional SSDTs into RSDT
535if(ssdt_count > 0)
536{
537int j;
538
539for (j=0; j<ssdt_count; j++)
540{
541rsdt_entries[i-dropoffset+j] = (uint32_t)new_ssdt[j];
542}
543
544DBG("RSDT: Added %d SSDT table(s)\n", ssdt_count);
545
546}
547
548// Correct the checksum of RSDT
549DBG("RSDT: Original checksum %d, ", rsdt_mod->Checksum);
550
551rsdt_mod->Checksum=0;
552rsdt_mod->Checksum=256-checksum8(rsdt_mod,rsdt_mod->Length);
553
554DBG("New checksum %d at %x\n", rsdt_mod->Checksum,rsdt_mod);
555}
556else
557{
558rsdp_mod->RsdtAddress=0;
559DBG("RSDT not found or RSDT incorrect\n");
560}
561DBG("\n");
562
563if (version)
564{
565struct acpi_2_xsdt *xsdt, *xsdt_mod;
566
567// FIXME: handle 64-bit address correctly
568
569xsdt=(struct acpi_2_xsdt*) ((uint32_t)rsdp->XsdtAddress);
570DBG("XSDT @%x;%x, Length=%d\n", (uint32_t)(rsdp->XsdtAddress>>32),(uint32_t)rsdp->XsdtAddress, xsdt->Length);
571
572if (xsdt && (uint64_t)rsdp->XsdtAddress<0xffffffff && xsdt->Length<0x10000)
573{
574uint64_t *xsdt_entries;
575int xsdt_entries_num, i;
576int dropoffset = 0;
577
578// mozo: using malloc cos I didn't found how to free already allocated kernel memory
579xsdt_mod = (struct acpi_2_xsdt *)malloc(xsdt->Length);
580memcpy(xsdt_mod, xsdt, xsdt->Length);
581
582rsdp_mod->XsdtAddress = (uint32_t)xsdt_mod;
583xsdt_entries_num = (xsdt_mod->Length - sizeof(struct acpi_2_xsdt)) / 8;
584xsdt_entries = (uint64_t *)(xsdt_mod + 1);
585for (i = 0;i < xsdt_entries_num; i++)
586{
587char *table = (char *)((uint32_t)(xsdt_entries[i]));
588if (!table)
589{
590continue;
591}
592xsdt_entries[i - dropoffset] = xsdt_entries[i];
593
594if (drop_ssdt && tableSign(table, "SSDT"))
595{
596DBG("OEM SSDT tables was dropped\n");
597dropoffset++;
598continue;
599}
600if (tableSign(table, "DSDT"))
601{
602DBG("DSDT found\n");
603
604if (new_dsdt)
605{
606xsdt_entries[i-dropoffset] = (uint32_t)new_dsdt;
607DBG("custom table added.\n");
608}
609
610DBG("TABLE %c%c%c%c@%x \n", table[0],table[1],table[2],table[3],xsdt_entries[i]);
611
612continue;
613}
614if (tableSign(table, "FACP"))
615{
616struct acpi_2_fadt *fadt, *fadt_mod;
617fadt=(struct acpi_2_fadt *)(uint32_t)xsdt_entries[i];
618
619DBG("FADT found @%x%x, Length %d\n",(uint32_t)(xsdt_entries[i]>>32),fadt,
620fadt->Length);
621
622if (!fadt || (uint64_t)xsdt_entries[i] >= 0xffffffff || fadt->Length>0x10000)
623{
624DBG("FADT incorrect or after 4GB. Dropping XSDT\n");
625goto drop_xsdt;
626}
627
628fadt_mod = patch_fadt(fadt, new_dsdt);
629xsdt_entries[i - dropoffset] = (uint32_t)fadt_mod;
630
631// DBG("TABLE %c%c%c%c@%x \n", table[0],table[1],table[2],table[3],xsdt_entries[i]);
632
633// Generate _CST SSDT
634if (generate_cstates && (new_ssdt[ssdt_count] = generate_cst_ssdt(fadt_mod)))
635{
636DBG("\tC-States generated.\n");
637generate_cstates = false; // Generate SSDT only once!
638ssdt_count++;
639}
640
641// Generating _PSS SSDT
642if (generate_pstates && (new_ssdt[ssdt_count] = generate_pss_ssdt((void*)fadt_mod->DSDT)))
643{
644DBG("\tP-States generated.\n");
645generate_pstates = false; // Generate SSDT only once!
646ssdt_count++;
647}
648
649// Generating _TSS SSDT
650/*if (generate_tstates && (new_ssdt[ssdt_count] = generate_tss_ssdt((void*)fadt_mod->DSDT)))
651{
652generate_tstates = false; // Generate SSDT only once!
653ssdt_count++;
654}*/
655continue;
656}
657DBG("copied (OEM)\n");
658// DBG("TABLE %c%c%c%c@%x \n", table[0],table[1],table[2],table[3],xsdt_entries[i]);
659}
660
661// Allocate xsdt in Kernel memory area
662xsdt_mod->Length += 8*ssdt_count - 8*dropoffset;
663struct acpi_2_xsdt *xsdt_copy = (struct acpi_2_xsdt *)AllocateKernelMemory(xsdt_mod->Length);
664memcpy(xsdt_copy, xsdt_mod, xsdt_mod->Length);
665free(xsdt_mod);
666xsdt_mod = xsdt_copy;
667rsdp_mod->XsdtAddress = (uint32_t)xsdt_mod;
668xsdt_entries_num = (xsdt_mod->Length - sizeof(struct acpi_2_xsdt)) / 8;
669xsdt_entries = (uint64_t *)(xsdt_mod + 1);
670
671// Mozodojo: Insert additional SSDTs into XSDT
672if(ssdt_count > 0)
673{
674int j;
675
676for (j=0; j<ssdt_count; j++)
677{
678xsdt_entries[i - dropoffset + j] = (uint32_t)new_ssdt[j];
679}
680
681verbose("Added %d SSDT table(s) into XSDT\n", ssdt_count);
682
683}
684
685// Correct the checksum of XSDT
686xsdt_mod->Checksum=0;
687xsdt_mod->Checksum=256-checksum8(xsdt_mod,xsdt_mod->Length);
688}
689else
690{
691drop_xsdt:
692
693DBG("About to drop XSDT\n");
694
695/*FIXME: Now we just hope that if MacOS doesn't find XSDT it reverts to RSDT.
696 * A Better strategy would be to generate
697 */
698
699rsdp_mod->XsdtAddress=0xffffffffffffffffLL;
700verbose("XSDT not found or XSDT incorrect\n");
701}
702}
703DBG("\n");
704
705// Correct the checksum of RSDP
706
707DBG("RSDP: Original checksum %d, ", rsdp_mod->Checksum);
708
709rsdp_mod->Checksum=0;
710rsdp_mod->Checksum=256-checksum8(rsdp_mod,20);
711
712DBG("New checksum %d\n", rsdp_mod->Checksum);
713
714if (version)
715{
716DBG("RSDP: Original extended checksum %d, ", rsdp_mod->ExtendedChecksum);
717
718rsdp_mod->ExtendedChecksum=0;
719rsdp_mod->ExtendedChecksum=256-checksum8(rsdp_mod,rsdp_mod->Length);
720
721DBG("New extended checksum %d\n", rsdp_mod->ExtendedChecksum);
722
723}
724
725if (version)
726{
727/* XXX aserebln why uint32 cast if pointer is uint64 ? */
728acpi20_p = (uint64_t)(uint32_t)rsdp_mod;
729addConfigurationTable(&gEfiAcpi20TableGuid, &acpi20_p, "ACPI_20");
730}
731else
732{
733/* XXX aserebln why uint32 cast if pointer is uint64 ? */
734acpi10_p = (uint64_t)(uint32_t)rsdp_mod;
735addConfigurationTable(&gEfiAcpiTableGuid, &acpi10_p, "ACPI");
736}
737DBG("ACPI version %d patching finished\n\n", version + 1);
738}
739#if DEBUG_ACPI
740printf("Press a key to continue... (DEBUG_ACPI)\n");
741getchar();
742#endif
743return 1;
744}
745

Archive Download this file

Revision: 2679