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 \n", dirspec);
155}
156//printf("Couldn't find table %s\n", filename);
157return NULL;
158}
159
160uint8_t acpi_cpu_count= 0;
161uint32_t acpi_cpu_p_blk= 0;
162char *acpi_cpu_name[32];
163
164void get_acpi_cpu_names(unsigned char *dsdt, uint32_t length)
165{
166uint32_t i;
167
168DBG("ACPIpatcher: start finding cpu names. Length %d\n", length);
169
170for (i=0; i<length-7; i++)
171{
172if (dsdt[i] == 0x5B && dsdt[i+1] == 0x83) // ProcessorOP
173{
174DBG("ACPIpatcher: DSDT[%X%X]\n", dsdt[i], dsdt[i+1]);
175
176uint32_t offset = i + 3 + (dsdt[i+2] >> 6);
177
178bool add_name = true;
179
180uint8_t j;
181
182for (j=0; j<4; j++)
183{
184char c = dsdt[offset+j];
185
186if (!aml_isvalidchar(c))
187{
188add_name = false;
189DBG("ACPIpatcher: invalid character found in ProcessorOP '0x%X'!\n", c);
190break;
191}
192}
193
194if (add_name)
195{
196acpi_cpu_name[acpi_cpu_count] = malloc(4);
197memcpy(acpi_cpu_name[acpi_cpu_count], dsdt+offset, 4);
198i = offset + 5;
199
200if (acpi_cpu_count == 0)
201{
202acpi_cpu_p_blk = dsdt[i] | (dsdt[i+1] << 8);
203}
204
205DBG("ACPIpatcher: found ACPI CPU [%c%c%c%c]\n", acpi_cpu_name[acpi_cpu_count][0], acpi_cpu_name[acpi_cpu_count][1], acpi_cpu_name[acpi_cpu_count][2], acpi_cpu_name[acpi_cpu_count][3]);
206
207if (++acpi_cpu_count == 32)
208{
209return;
210}
211}
212}
213}
214
215DBG("ACPIpatcher: finished finding cpu names. Found: %d.\n", acpi_cpu_count);
216}
217
218struct acpi_2_fadt *patch_fadt(struct acpi_2_fadt *fadt, struct acpi_2_dsdt *new_dsdt)
219{
220extern void setupSystemType();
221
222struct acpi_2_fadt *fadt_mod = NULL;
223bool fadt_rev2_needed = false;
224bool fix_restart;
225bool fix_restart_ps2;
226const char * value;
227
228// Restart Fix
229if (Platform.CPU.Vendor == 0x756E6547)
230{/* Intel */
231fix_restart = true;
232fix_restart_ps2 = false;
233if ( getBoolForKey(kPS2RestartFix, &fix_restart_ps2, &bootInfo->chameleonConfig) && fix_restart_ps2)
234{
235fix_restart = true;
236}
237else
238{
239getBoolForKey(kRestartFix, &fix_restart, &bootInfo->chameleonConfig);
240}
241}
242else
243{
244DBG("Not an Intel platform: Restart Fix not applied !!!\n");
245fix_restart = false;
246}
247
248if (fix_restart)
249{
250fadt_rev2_needed = true;
251}
252
253// Allocate new fadt table
254if (fadt->Length < 0x84 && fadt_rev2_needed)
255{
256fadt_mod = (struct acpi_2_fadt *)AllocateKernelMemory(0x84);
257memcpy(fadt_mod, fadt, fadt->Length);
258fadt_mod->Length = 0x84;
259fadt_mod->Revision = 0x02; // FADT rev 2 (ACPI 1.0B MS extensions)
260}
261else
262{
263fadt_mod = (struct acpi_2_fadt *)AllocateKernelMemory(fadt->Length);
264memcpy(fadt_mod, fadt, fadt->Length);
265}
266// Determine system type / PM_Model
267if ( (value=getStringForKey(kSystemType, &bootInfo->chameleonConfig))!=NULL)
268{
269if (Platform.Type > 6)
270{
271if(fadt_mod->PM_Profile<=6)
272{
273Platform.Type = fadt_mod->PM_Profile; // get the fadt if correct
274}
275else
276{
277Platform.Type = 1;/* Set a fixed value (Desktop) */
278}
279DBG("Error: system-type must be 0..6. Defaulting to %d !\n", Platform.Type);
280}
281else
282{
283Platform.Type = (unsigned char) strtoul(value, NULL, 10);
284}
285}
286// Set PM_Profile from System-type if only user wanted this value to be forced
287if (fadt_mod->PM_Profile != Platform.Type)
288{
289if (value)
290{
291// user has overriden the SystemType so take care of it in FACP
292DBG("FADT: changing PM_Profile from 0x%02x to 0x%02x\n", fadt_mod->PM_Profile, Platform.Type);
293fadt_mod->PM_Profile = Platform.Type;
294}
295else
296{
297// PM_Profile has a different value and no override has been set, so reflect the user value to ioregs
298Platform.Type = fadt_mod->PM_Profile <= 6 ? fadt_mod->PM_Profile : 1;
299}
300}
301// We now have to write the systemm-type in ioregs: we cannot do it before in setupDeviceTree()
302// because we need to take care of FACP original content, if it is correct.
303setupSystemType();
304
305// Patch FADT to fix restart
306if (fix_restart)
307{
308if (fix_restart_ps2)
309{
310fadt_mod->Flags|= 0x400;
311fadt_mod->Reset_SpaceID= 0x01; // System I/O
312fadt_mod->Reset_BitWidth= 0x08; // 1 byte
313fadt_mod->Reset_BitOffset= 0x00; // Offset 0
314fadt_mod->Reset_AccessWidth= 0x01; // Byte access
315fadt_mod->Reset_Address= 0x64; // Address of the register
316fadt_mod->Reset_Value= 0xfe; // Value to write to reset the system
317DBG("FADT: PS2 Restart Fix applied!\n");
318}
319else
320{
321fadt_mod->Flags|= 0x400;
322fadt_mod->Reset_SpaceID= 0x01; // System I/O
323fadt_mod->Reset_BitWidth= 0x08; // 1 byte
324fadt_mod->Reset_BitOffset= 0x00; // Offset 0
325fadt_mod->Reset_AccessWidth= 0x01; // Byte access
326fadt_mod->Reset_Address= 0x0cf9; // Address of the register
327fadt_mod->Reset_Value= 0x06; // Value to write to reset the system
328DBG("FADT: ACPI Restart Fix applied!\n");
329}
330
331}
332
333// Patch DSDT Address if we have loaded DSDT.aml
334if(new_dsdt)
335{
336DBG("DSDT: Old @%x,%x, ",fadt_mod->DSDT,fadt_mod->X_DSDT);
337
338fadt_mod->DSDT=(uint32_t)new_dsdt;
339if ((uint32_t)(&(fadt_mod->X_DSDT))-(uint32_t)fadt_mod+8<=fadt_mod->Length)
340{
341fadt_mod->X_DSDT=(uint32_t)new_dsdt;
342}
343
344DBG("New @%x,%x\n",fadt_mod->DSDT,fadt_mod->X_DSDT);
345
346DBG("FADT: Using custom DSDT!\n");
347}
348
349// Correct the checksum
350fadt_mod->Checksum=0;
351fadt_mod->Checksum=256-checksum8(fadt_mod,fadt_mod->Length);
352
353return fadt_mod;
354}
355
356/* Setup ACPI without replacing DSDT. */
357int setupAcpiNoMod()
358{
359//addConfigurationTable(&gEfiAcpiTableGuid, getAddressOfAcpiTable(), "ACPI");
360//addConfigurationTable(&gEfiAcpi20TableGuid, getAddressOfAcpi20Table(), "ACPI_20");
361/* XXX aserebln why uint32 cast if pointer is uint64 ? */
362acpi10_p = (uint64_t)(uint32_t)getAddressOfAcpiTable();
363acpi20_p = (uint64_t)(uint32_t)getAddressOfAcpi20Table();
364addConfigurationTable(&gEfiAcpiTableGuid, &acpi10_p, "ACPI");
365if(acpi20_p)
366{
367addConfigurationTable(&gEfiAcpi20TableGuid, &acpi20_p, "ACPI_20");
368}
369else
370{
371DBG("No ACPI 2.\n");
372}
373return 1;
374}
375
376/* Setup ACPI. Replace DSDT if DSDT.aml is found */
377int setupAcpi(void)
378{
379int version;
380void *new_dsdt = NULL;
381
382
383const char *filename;
384char dirSpec[128];
385int len = 0;
386
387// always reset cpu count to 0 when injecting new acpi
388acpi_cpu_count = 0;
389
390/* Try using the file specified with the DSDT option */
391if (getValueForKey(kDSDT, &filename, &len, &bootInfo->chameleonConfig))
392{
393strncpy(dirSpec, filename, sizeof(dirSpec) );
394}
395else
396{
397strcpy(dirSpec, "DSDT.aml");
398//verbose("dirSpec, DSDT.aml");
399}
400
401// Load replacement DSDT
402new_dsdt = loadACPITable(dirSpec);
403
404// Mozodojo: going to patch FACP and load SSDT's even if DSDT.aml is not present
405/*if (!new_dsdt)
406 {
407 return setupAcpiNoMod();
408 }*/
409
410// Mozodojo: Load additional SSDTs
411struct acpi_2_ssdt *new_ssdt[32]; // 30 + 2 additional tables for pss & cst
412int ssdt_count=0;
413
414// SSDT Options
415bool drop_ssdt = false, generate_pstates = false, generate_cstates = false;
416
417getBoolForKey(kDropSSDT, &drop_ssdt, &bootInfo->chameleonConfig);
418getBoolForKey(kGeneratePStates, &generate_pstates, &bootInfo->chameleonConfig);
419getBoolForKey(kGenerateCStates, &generate_cstates, &bootInfo->chameleonConfig);
420
421DBG("Generating P-States config: %s\n", generate_pstates ? "YES" : "NO");
422DBG("Generating C-States config: %s\n", generate_cstates ? "YES" : "NO");
423
424{
425int i;
426
427for (i = 0; i < 30; i++)
428{
429char filename[512];
430
431if (i > 0)
432{
433sprintf(filename, "SSDT-%d.aml", i);
434}
435else
436{
437strcpy(filename, "SSDT.aml");
438}
439
440if ( (new_ssdt[ssdt_count] = loadACPITable(filename)) )
441{
442ssdt_count++;
443}
444else
445{
446break;
447}
448}
449}
450
451// Do the same procedure for both versions of ACPI
452for (version = 0; version < 2; version++)
453{
454struct acpi_2_rsdp *rsdp, *rsdp_mod;
455struct acpi_2_rsdt *rsdt, *rsdt_mod;
456int rsdplength;
457
458// Find original rsdp
459rsdp = (struct acpi_2_rsdp *)(version ? getAddressOfAcpi20Table() : getAddressOfAcpiTable());
460if (!rsdp)
461{
462DBG("No ACPI version %d found. Ignoring\n", version+1);
463if (version)
464{
465addConfigurationTable(&gEfiAcpi20TableGuid, NULL, "ACPI_20");
466}
467else
468{
469addConfigurationTable(&gEfiAcpiTableGuid, NULL, "ACPI");
470}
471continue;
472}
473rsdplength = version ? rsdp->Length : 20;
474
475DBG("RSDP version %d found @%x. Length=%d\n",version+1,rsdp,rsdplength);
476
477/* FIXME: no check that memory allocation succeeded
478 * Copy and patch RSDP,RSDT, XSDT and FADT
479 * For more info see ACPI Specification pages 110 and following
480 */
481
482rsdp_mod = (struct acpi_2_rsdp *) AllocateKernelMemory(rsdplength);
483memcpy(rsdp_mod, rsdp, rsdplength);
484
485rsdt = (struct acpi_2_rsdt *)rsdp->RsdtAddress;
486
487DBG("RSDT @%x, Length %d\n",rsdt, rsdt ? rsdt->Length : 0);
488
489if (rsdt && (uint32_t)rsdt !=0xffffffff && rsdt->Length < 0x10000)
490{
491uint32_t *rsdt_entries;
492int rsdt_entries_num;
493int dropoffset=0, i;
494
495// mozo: using malloc cos I didn't found how to free already allocated kernel memory
496rsdt_mod = (struct acpi_2_rsdt *)malloc(rsdt->Length);
497memcpy(rsdt_mod, rsdt, rsdt->Length);
498rsdp_mod->RsdtAddress = (uint32_t)rsdt_mod;
499rsdt_entries_num = (rsdt_mod->Length - sizeof(struct acpi_2_rsdt)) / 4;
500rsdt_entries = (uint32_t *)(rsdt_mod + 1);
501for (i = 0;i < rsdt_entries_num;i++)
502{
503char *table=(char *)(rsdt_entries[i]);
504if (!table)
505{
506continue;
507}
508
509DBG("TABLE %c%c%c%c,",table[0],table[1],table[2],table[3]);
510
511rsdt_entries[i-dropoffset]=rsdt_entries[i];
512
513if (drop_ssdt && tableSign(table, "SSDT"))
514{
515DBG("OEM SSDT tables was dropped\n");
516dropoffset++;
517continue;
518}
519
520if (tableSign(table, "DSDT"))
521{
522DBG("DSDT found\n");
523DBG("Custom DSDT table was found\n");
524if(new_dsdt)
525{
526rsdt_entries[i-dropoffset]=(uint32_t)new_dsdt;
527}
528
529continue;
530}
531
532if (tableSign(table, "FACP"))
533{
534struct acpi_2_fadt *fadt, *fadt_mod;
535fadt=(struct acpi_2_fadt *)rsdt_entries[i];
536
537DBG("FADT found @%x, Length %d\n",fadt, fadt->Length);
538
539if (!fadt || (uint32_t)fadt == 0xffffffff || fadt->Length>0x10000)
540{
541DBG("FADT incorrect. Not modified\n");
542continue;
543}
544
545fadt_mod = patch_fadt(fadt, new_dsdt);
546rsdt_entries[i-dropoffset] = (uint32_t)fadt_mod;
547
548// Generate _CST SSDT
549if (generate_cstates && (new_ssdt[ssdt_count] = generate_cst_ssdt(fadt_mod)))
550{
551DBG("C-States generated\n");
552generate_cstates = false; // Generate SSDT only once!
553ssdt_count++;
554}
555
556// Generating _PSS SSDT
557if (generate_pstates && (new_ssdt[ssdt_count] = generate_pss_ssdt((void*)fadt_mod->DSDT)))
558{
559DBG("P-States generated\n");
560generate_pstates = false; // Generate SSDT only once!
561ssdt_count++;
562}
563continue;
564}
565}
566DBG("\n");
567
568// Allocate rsdt in Kernel memory area
569rsdt_mod->Length += 4*ssdt_count - 4*dropoffset;
570struct acpi_2_rsdt *rsdt_copy = (struct acpi_2_rsdt *)AllocateKernelMemory(rsdt_mod->Length);
571memcpy(rsdt_copy, rsdt_mod, rsdt_mod->Length);
572free(rsdt_mod);
573rsdt_mod = rsdt_copy;
574rsdp_mod->RsdtAddress = (uint32_t)rsdt_mod;
575rsdt_entries_num = (rsdt_mod->Length-sizeof(struct acpi_2_rsdt)) / 4;
576rsdt_entries = (uint32_t *)(rsdt_mod + 1);
577
578// Mozodojo: Insert additional SSDTs into RSDT
579if(ssdt_count > 0)
580{
581int j;
582
583for (j=0; j<ssdt_count; j++)
584{
585rsdt_entries[i-dropoffset+j]=(uint32_t)new_ssdt[j];
586}
587
588DBG("RSDT: Added %d SSDT table(s)\n", ssdt_count);
589
590}
591
592// Correct the checksum of RSDT
593DBG("RSDT: Original checksum %d, ", rsdt_mod->Checksum);
594
595rsdt_mod->Checksum=0;
596rsdt_mod->Checksum=256-checksum8(rsdt_mod,rsdt_mod->Length);
597
598DBG("New checksum %d at %x\n", rsdt_mod->Checksum,rsdt_mod);
599}
600else
601{
602rsdp_mod->RsdtAddress=0;
603DBG("RSDT not found or RSDT incorrect\n");
604}
605DBG("\n");
606
607if (version)
608{
609struct acpi_2_xsdt *xsdt, *xsdt_mod;
610
611// FIXME: handle 64-bit address correctly
612
613xsdt=(struct acpi_2_xsdt*) ((uint32_t)rsdp->XsdtAddress);
614DBG("XSDT @%x;%x, Length=%d\n", (uint32_t)(rsdp->XsdtAddress>>32),(uint32_t)rsdp->XsdtAddress, xsdt->Length);
615
616if (xsdt && (uint64_t)rsdp->XsdtAddress<0xffffffff && xsdt->Length<0x10000)
617{
618uint64_t *xsdt_entries;
619int xsdt_entries_num, i;
620int dropoffset=0;
621
622// mozo: using malloc cos I didn't found how to free already allocated kernel memory
623xsdt_mod=(struct acpi_2_xsdt*)malloc(xsdt->Length);
624memcpy(xsdt_mod, xsdt, xsdt->Length);
625
626rsdp_mod->XsdtAddress = (uint32_t)xsdt_mod;
627xsdt_entries_num = (xsdt_mod->Length - sizeof(struct acpi_2_xsdt)) / 8;
628xsdt_entries = (uint64_t *)(xsdt_mod + 1);
629for (i = 0;i < xsdt_entries_num;i++)
630{
631char *table = (char *)((uint32_t)(xsdt_entries[i]));
632if (!table)
633{
634continue;
635}
636xsdt_entries[i - dropoffset] = xsdt_entries[i];
637
638if (drop_ssdt && tableSign(table, "SSDT"))
639{
640DBG("OEM SSDT tables was dropped\n");
641dropoffset++;
642continue;
643}
644if (tableSign(table, "DSDT"))
645{
646DBG("DSDT found\n");
647
648if (new_dsdt)
649{
650xsdt_entries[i-dropoffset] = (uint32_t)new_dsdt;
651DBG("custom table added\n");
652}
653
654DBG("TABLE %c%c%c%c@%x \n", table[0],table[1],table[2],table[3],xsdt_entries[i]);
655
656continue;
657}
658if (tableSign(table, "FACP"))
659{
660struct acpi_2_fadt *fadt, *fadt_mod;
661fadt=(struct acpi_2_fadt *)(uint32_t)xsdt_entries[i];
662
663DBG("FADT found @%x%x, Length %d\n",(uint32_t)(xsdt_entries[i]>>32),fadt,
664fadt->Length);
665
666if (!fadt || (uint64_t)xsdt_entries[i] >= 0xffffffff || fadt->Length>0x10000)
667{
668DBG("FADT incorrect or after 4GB. Dropping XSDT\n");
669goto drop_xsdt;
670}
671
672fadt_mod = patch_fadt(fadt, new_dsdt);
673xsdt_entries[i-dropoffset]=(uint32_t)fadt_mod;
674
675// DBG("TABLE %c%c%c%c@%x \n", table[0],table[1],table[2],table[3],xsdt_entries[i]);
676
677// Generate _CST SSDT
678if (generate_cstates && (new_ssdt[ssdt_count] = generate_cst_ssdt(fadt_mod)))
679{
680DBG("C-States generated\n");
681generate_cstates = false; // Generate SSDT only once!
682ssdt_count++;
683}
684
685// Generating _PSS SSDT
686if (generate_pstates && (new_ssdt[ssdt_count] = generate_pss_ssdt((void*)fadt_mod->DSDT)))
687{
688DBG("P-States generated\n");
689generate_pstates = false; // Generate SSDT only once!
690ssdt_count++;
691}
692
693continue;
694}
695DBG("copied (OEM)\n");
696// DBG("TABLE %c%c%c%c@%x \n", table[0],table[1],table[2],table[3],xsdt_entries[i]);
697}
698
699// Allocate xsdt in Kernel memory area
700xsdt_mod->Length += 8*ssdt_count - 8*dropoffset;
701struct acpi_2_xsdt *xsdt_copy = (struct acpi_2_xsdt *)AllocateKernelMemory(xsdt_mod->Length);
702memcpy(xsdt_copy, xsdt_mod, xsdt_mod->Length);
703free(xsdt_mod);
704xsdt_mod = xsdt_copy;
705rsdp_mod->XsdtAddress = (uint32_t)xsdt_mod;
706xsdt_entries_num = (xsdt_mod->Length - sizeof(struct acpi_2_xsdt)) / 8;
707xsdt_entries = (uint64_t *)(xsdt_mod + 1);
708
709// Mozodojo: Insert additional SSDTs into XSDT
710if(ssdt_count > 0)
711{
712int j;
713
714for (j=0; j<ssdt_count; j++)
715{
716xsdt_entries[i-dropoffset+j]=(uint32_t)new_ssdt[j];
717}
718
719verbose("Added %d SSDT table(s) into XSDT\n", ssdt_count);
720
721}
722
723// Correct the checksum of XSDT
724xsdt_mod->Checksum=0;
725xsdt_mod->Checksum=256-checksum8(xsdt_mod,xsdt_mod->Length);
726}
727else
728{
729drop_xsdt:
730
731DBG("About to drop XSDT\n");
732
733/*FIXME: Now we just hope that if MacOS doesn't find XSDT it reverts to RSDT.
734 * A Better strategy would be to generate
735 */
736
737rsdp_mod->XsdtAddress=0xffffffffffffffffLL;
738verbose("XSDT not found or XSDT incorrect\n");
739}
740}
741DBG("\n");
742
743// Correct the checksum of RSDP
744
745DBG("RSDP: Original checksum %d, ", rsdp_mod->Checksum);
746
747rsdp_mod->Checksum=0;
748rsdp_mod->Checksum=256-checksum8(rsdp_mod,20);
749
750DBG("New checksum %d\n", rsdp_mod->Checksum);
751
752if (version)
753{
754DBG("RSDP: Original extended checksum %d, ", rsdp_mod->ExtendedChecksum);
755
756rsdp_mod->ExtendedChecksum=0;
757rsdp_mod->ExtendedChecksum=256-checksum8(rsdp_mod,rsdp_mod->Length);
758
759DBG("New extended checksum %d\n", rsdp_mod->ExtendedChecksum);
760
761}
762
763if (version)
764{
765/* XXX aserebln why uint32 cast if pointer is uint64 ? */
766acpi20_p = (uint64_t)(uint32_t)rsdp_mod;
767addConfigurationTable(&gEfiAcpi20TableGuid, &acpi20_p, "ACPI_20");
768}
769else
770{
771/* XXX aserebln why uint32 cast if pointer is uint64 ? */
772acpi10_p = (uint64_t)(uint32_t)rsdp_mod;
773addConfigurationTable(&gEfiAcpiTableGuid, &acpi10_p, "ACPI");
774}
775DBG("ACPI version %d patching finished\n\n", version+1);
776}
777#if DEBUG_ACPI
778printf("Press a key to continue... (DEBUG_ACPI)\n");
779getchar();
780#endif
781return 1;
782}
783

Archive Download this file

Revision: 2633