Chameleon

Chameleon Svn Source Tree

Root/trunk/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
375DBG("Generating P-States config: %s\n", generate_pstates ? "YES" : "NO");
376DBG("Generating C-States config: %s\n", generate_cstates ? "YES" : "NO");
377
378{
379int i;
380
381for (i = 0; i < 30; i++)
382{
383char filename[512];
384
385if (i > 0)
386{
387sprintf(filename, "SSDT-%d.aml", i);
388}
389else
390{
391strcpy(filename, "SSDT.aml");
392}
393
394if ( (new_ssdt[ssdt_count] = loadACPITable(filename)) )
395{
396ssdt_count++;
397}
398else
399{
400break;
401}
402}
403}
404
405// Do the same procedure for both versions of ACPI
406for (version = 0; version < 2; version++)
407{
408struct acpi_2_rsdp *rsdp, *rsdp_mod;
409struct acpi_2_rsdt *rsdt, *rsdt_mod;
410int rsdplength;
411
412// Find original rsdp
413rsdp = (struct acpi_2_rsdp *)(version ? getAddressOfAcpi20Table() : getAddressOfAcpiTable());
414if (!rsdp)
415{
416DBG("No ACPI version %d found. Ignoring\n", version+1);
417if (version)
418{
419addConfigurationTable(&gEfiAcpi20TableGuid, NULL, "ACPI_20");
420}
421else
422{
423addConfigurationTable(&gEfiAcpiTableGuid, NULL, "ACPI");
424}
425continue;
426}
427rsdplength = version ? rsdp->Length : 20;
428
429DBG("RSDP version %d found @%x. Length=%d\n",version+1,rsdp,rsdplength);
430
431/* FIXME: no check that memory allocation succeeded
432 * Copy and patch RSDP,RSDT, XSDT and FADT
433 * For more info see ACPI Specification pages 110 and following
434 */
435
436rsdp_mod = (struct acpi_2_rsdp *) AllocateKernelMemory(rsdplength);
437memcpy(rsdp_mod, rsdp, rsdplength);
438
439rsdt = (struct acpi_2_rsdt *)rsdp->RsdtAddress;
440
441DBG("RSDT @%x, Length %d\n",rsdt, rsdt ? rsdt->Length : 0);
442
443if (rsdt && (uint32_t)rsdt !=0xffffffff && rsdt->Length < 0x10000)
444{
445uint32_t *rsdt_entries;
446int rsdt_entries_num;
447int dropoffset = 0, i;
448
449// mozo: using malloc cos I didn't found how to free already allocated kernel memory
450rsdt_mod = (struct acpi_2_rsdt *)malloc(rsdt->Length);
451memcpy(rsdt_mod, rsdt, rsdt->Length);
452rsdp_mod->RsdtAddress = (uint32_t)rsdt_mod;
453rsdt_entries_num = (rsdt_mod->Length - sizeof(struct acpi_2_rsdt)) / 4;
454rsdt_entries = (uint32_t *)(rsdt_mod + 1);
455for (i = 0; i < rsdt_entries_num; i++)
456{
457char *table=(char *)(rsdt_entries[i]);
458if (!table)
459{
460continue;
461}
462
463DBG("TABLE %c%c%c%c,",table[0],table[1],table[2],table[3]);
464
465rsdt_entries[i-dropoffset]=rsdt_entries[i];
466
467if (drop_ssdt && tableSign(table, "SSDT"))
468{
469DBG("OEM SSDT tables was dropped\n");
470dropoffset++;
471continue;
472}
473
474if (tableSign(table, "DSDT"))
475{
476DBG("DSDT found\n");
477DBG("Custom DSDT table was found\n");
478if(new_dsdt)
479{
480rsdt_entries[i-dropoffset] = (uint32_t)new_dsdt;
481}
482
483continue;
484}
485
486if (tableSign(table, "FACP"))
487{
488struct acpi_2_fadt *fadt, *fadt_mod;
489fadt=(struct acpi_2_fadt *)rsdt_entries[i];
490
491DBG("FADT found @%x, Length %d\n",fadt, fadt->Length);
492
493if (!fadt || (uint32_t)fadt == 0xffffffff || fadt->Length>0x10000)
494{
495DBG("FADT incorrect. Not modified\n");
496continue;
497}
498
499fadt_mod = patch_fadt(fadt, new_dsdt);
500rsdt_entries[i-dropoffset] = (uint32_t)fadt_mod;
501
502// Generate _CST SSDT
503if (generate_cstates && (new_ssdt[ssdt_count] = generate_cst_ssdt(fadt_mod)))
504{
505DBG("\tC-States generated.\n");
506generate_cstates = false; // Generate SSDT only once!
507ssdt_count++;
508}
509
510// Generating _PSS SSDT
511if (generate_pstates && (new_ssdt[ssdt_count] = generate_pss_ssdt((void*)fadt_mod->DSDT)))
512{
513DBG("\tP-States generated.\n");
514generate_pstates = false; // Generate SSDT only once!
515ssdt_count++;
516}
517continue;
518}
519}
520DBG("\n");
521
522// Allocate rsdt in Kernel memory area
523rsdt_mod->Length += 4*ssdt_count - 4*dropoffset;
524struct acpi_2_rsdt *rsdt_copy = (struct acpi_2_rsdt *)AllocateKernelMemory(rsdt_mod->Length);
525memcpy(rsdt_copy, rsdt_mod, rsdt_mod->Length);
526free(rsdt_mod);
527rsdt_mod = rsdt_copy;
528rsdp_mod->RsdtAddress = (uint32_t)rsdt_mod;
529rsdt_entries_num = (rsdt_mod->Length-sizeof(struct acpi_2_rsdt)) / 4;
530rsdt_entries = (uint32_t *)(rsdt_mod + 1);
531
532// Mozodojo: Insert additional SSDTs into RSDT
533if(ssdt_count > 0)
534{
535int j;
536
537for (j=0; j<ssdt_count; j++)
538{
539rsdt_entries[i-dropoffset+j] = (uint32_t)new_ssdt[j];
540}
541
542DBG("RSDT: Added %d SSDT table(s)\n", ssdt_count);
543
544}
545
546// Correct the checksum of RSDT
547DBG("RSDT: Original checksum %d, ", rsdt_mod->Checksum);
548
549rsdt_mod->Checksum=0;
550rsdt_mod->Checksum=256-checksum8(rsdt_mod,rsdt_mod->Length);
551
552DBG("New checksum %d at %x\n", rsdt_mod->Checksum,rsdt_mod);
553}
554else
555{
556rsdp_mod->RsdtAddress=0;
557DBG("RSDT not found or RSDT incorrect\n");
558}
559DBG("\n");
560
561if (version)
562{
563struct acpi_2_xsdt *xsdt, *xsdt_mod;
564
565// FIXME: handle 64-bit address correctly
566
567xsdt=(struct acpi_2_xsdt*) ((uint32_t)rsdp->XsdtAddress);
568DBG("XSDT @%x;%x, Length=%d\n", (uint32_t)(rsdp->XsdtAddress>>32),(uint32_t)rsdp->XsdtAddress, xsdt->Length);
569
570if (xsdt && (uint64_t)rsdp->XsdtAddress<0xffffffff && xsdt->Length<0x10000)
571{
572uint64_t *xsdt_entries;
573int xsdt_entries_num, i;
574int dropoffset = 0;
575
576// mozo: using malloc cos I didn't found how to free already allocated kernel memory
577xsdt_mod = (struct acpi_2_xsdt *)malloc(xsdt->Length);
578memcpy(xsdt_mod, xsdt, xsdt->Length);
579
580rsdp_mod->XsdtAddress = (uint32_t)xsdt_mod;
581xsdt_entries_num = (xsdt_mod->Length - sizeof(struct acpi_2_xsdt)) / 8;
582xsdt_entries = (uint64_t *)(xsdt_mod + 1);
583for (i = 0;i < xsdt_entries_num; i++)
584{
585char *table = (char *)((uint32_t)(xsdt_entries[i]));
586if (!table)
587{
588continue;
589}
590xsdt_entries[i - dropoffset] = xsdt_entries[i];
591
592if (drop_ssdt && tableSign(table, "SSDT"))
593{
594DBG("OEM SSDT tables was dropped\n");
595dropoffset++;
596continue;
597}
598if (tableSign(table, "DSDT"))
599{
600DBG("DSDT found\n");
601
602if (new_dsdt)
603{
604xsdt_entries[i-dropoffset] = (uint32_t)new_dsdt;
605DBG("custom table added.\n");
606}
607
608DBG("TABLE %c%c%c%c@%x \n", table[0],table[1],table[2],table[3],xsdt_entries[i]);
609
610continue;
611}
612if (tableSign(table, "FACP"))
613{
614struct acpi_2_fadt *fadt, *fadt_mod;
615fadt=(struct acpi_2_fadt *)(uint32_t)xsdt_entries[i];
616
617DBG("FADT found @%x%x, Length %d\n",(uint32_t)(xsdt_entries[i]>>32),fadt,
618fadt->Length);
619
620if (!fadt || (uint64_t)xsdt_entries[i] >= 0xffffffff || fadt->Length>0x10000)
621{
622DBG("FADT incorrect or after 4GB. Dropping XSDT\n");
623goto drop_xsdt;
624}
625
626fadt_mod = patch_fadt(fadt, new_dsdt);
627xsdt_entries[i - dropoffset] = (uint32_t)fadt_mod;
628
629// DBG("TABLE %c%c%c%c@%x \n", table[0],table[1],table[2],table[3],xsdt_entries[i]);
630
631// Generate _CST SSDT
632if (generate_cstates && (new_ssdt[ssdt_count] = generate_cst_ssdt(fadt_mod)))
633{
634DBG("\tC-States generated.\n");
635generate_cstates = false; // Generate SSDT only once!
636ssdt_count++;
637}
638
639// Generating _PSS SSDT
640if (generate_pstates && (new_ssdt[ssdt_count] = generate_pss_ssdt((void*)fadt_mod->DSDT)))
641{
642DBG("\tP-States generated.\n");
643generate_pstates = false; // Generate SSDT only once!
644ssdt_count++;
645}
646
647continue;
648}
649DBG("copied (OEM)\n");
650// DBG("TABLE %c%c%c%c@%x \n", table[0],table[1],table[2],table[3],xsdt_entries[i]);
651}
652
653// Allocate xsdt in Kernel memory area
654xsdt_mod->Length += 8*ssdt_count - 8*dropoffset;
655struct acpi_2_xsdt *xsdt_copy = (struct acpi_2_xsdt *)AllocateKernelMemory(xsdt_mod->Length);
656memcpy(xsdt_copy, xsdt_mod, xsdt_mod->Length);
657free(xsdt_mod);
658xsdt_mod = xsdt_copy;
659rsdp_mod->XsdtAddress = (uint32_t)xsdt_mod;
660xsdt_entries_num = (xsdt_mod->Length - sizeof(struct acpi_2_xsdt)) / 8;
661xsdt_entries = (uint64_t *)(xsdt_mod + 1);
662
663// Mozodojo: Insert additional SSDTs into XSDT
664if(ssdt_count > 0)
665{
666int j;
667
668for (j=0; j<ssdt_count; j++)
669{
670xsdt_entries[i - dropoffset + j] = (uint32_t)new_ssdt[j];
671}
672
673verbose("Added %d SSDT table(s) into XSDT\n", ssdt_count);
674
675}
676
677// Correct the checksum of XSDT
678xsdt_mod->Checksum=0;
679xsdt_mod->Checksum=256-checksum8(xsdt_mod,xsdt_mod->Length);
680}
681else
682{
683drop_xsdt:
684
685DBG("About to drop XSDT\n");
686
687/*FIXME: Now we just hope that if MacOS doesn't find XSDT it reverts to RSDT.
688 * A Better strategy would be to generate
689 */
690
691rsdp_mod->XsdtAddress=0xffffffffffffffffLL;
692verbose("XSDT not found or XSDT incorrect\n");
693}
694}
695DBG("\n");
696
697// Correct the checksum of RSDP
698
699DBG("RSDP: Original checksum %d, ", rsdp_mod->Checksum);
700
701rsdp_mod->Checksum=0;
702rsdp_mod->Checksum=256-checksum8(rsdp_mod,20);
703
704DBG("New checksum %d\n", rsdp_mod->Checksum);
705
706if (version)
707{
708DBG("RSDP: Original extended checksum %d, ", rsdp_mod->ExtendedChecksum);
709
710rsdp_mod->ExtendedChecksum=0;
711rsdp_mod->ExtendedChecksum=256-checksum8(rsdp_mod,rsdp_mod->Length);
712
713DBG("New extended checksum %d\n", rsdp_mod->ExtendedChecksum);
714
715}
716
717if (version)
718{
719/* XXX aserebln why uint32 cast if pointer is uint64 ? */
720acpi20_p = (uint64_t)(uint32_t)rsdp_mod;
721addConfigurationTable(&gEfiAcpi20TableGuid, &acpi20_p, "ACPI_20");
722}
723else
724{
725/* XXX aserebln why uint32 cast if pointer is uint64 ? */
726acpi10_p = (uint64_t)(uint32_t)rsdp_mod;
727addConfigurationTable(&gEfiAcpiTableGuid, &acpi10_p, "ACPI");
728}
729DBG("ACPI version %d patching finished\n\n", version + 1);
730}
731#if DEBUG_ACPI
732printf("Press a key to continue... (DEBUG_ACPI)\n");
733getchar();
734#endif
735return 1;
736}
737

Archive Download this file

Revision: HEAD