Chameleon

Chameleon Svn Source Tree

Root/branches/slice/i386/libsaio/acpi_patcher.c

1/*
2 * Copyright 2008 mackerintel
3 */
4
5#include "libsaio.h"
6#include "boot.h"
7#include "bootstruct.h"
8#include "acpi.h"
9#include "efi_tables.h"
10#include "fake_efi.h"
11#include "acpi_patcher.h"
12#include "platform.h"
13#include "cpu.h"
14#include "aml_generator.h"
15#include "smbios_patcher.h"
16
17#ifndef DEBUG_ACPI
18#define DEBUG_ACPI 0
19#endif
20
21#if DEBUG_ACPI==2
22#define DBG(x...) {printf(x); sleep(1);}
23#elif DEBUG_ACPI==3
24#define DBG(x...) verbose(x)
25#elif DEBUG_ACPI==1
26#define DBG(x...) msglog(x)
27#else
28#define DBG(x...)
29#endif
30
31bool fix_restart;
32uint64_t acpi10_p;
33uint64_t acpi20_p;
34
35int rsdplength;
36void *new_dsdt=NULL;
37
38extern char* gSMBIOSBoardModel;
39
40// Slice: New signature compare function
41boolean_t tableSign(char *table, const char *sgn)
42{
43int i;
44for (i=0; i<4; i++) {
45if ((table[i] &~0x20) != (sgn[i] &~0x20)) {
46return false;
47}
48}
49return true;
50}
51
52char st[20];
53char * FourChar(char * s)
54{
55int i;
56for(i=0; i<4;i++){
57st[i] = (isalpha(s[i])?s[i]:'.');
58}
59//strncpy(st, s, 4);
60st[4] = '\0';
61return st;
62}
63
64
65/* Gets the ACPI 1.0 RSDP address */
66static struct acpi_2_rsdp* getAddressOfAcpiTable()
67{
68 /* TODO: Before searching the BIOS space we are supposed to search the first 1K of the EBDA */
69
70 void *acpi_addr = (void*)ACPI_RANGE_START;
71 for(; acpi_addr <= (void*)ACPI_RANGE_END; acpi_addr += 16)
72 {
73 if(*(uint64_t *)acpi_addr == ACPI_SIGNATURE_UINT64_LE)
74 {
75 uint8_t csum = checksum8(acpi_addr, 20);
76 if(csum == 0)
77 {
78 // Only return the table if it is a true version 1.0 table (Revision 0)
79 if(((struct acpi_2_rsdp*)acpi_addr)->Revision == 0)
80 return acpi_addr;
81 }
82 }
83 }
84 return NULL;
85}
86
87/* Gets the ACPI 2.0 RSDP address */
88static struct acpi_2_rsdp* getAddressOfAcpi20Table()
89{
90 /* TODO: Before searching the BIOS space we are supposed to search the first 1K of the EBDA */
91
92 void *acpi_addr = (void*)ACPI_RANGE_START;
93 for(; acpi_addr <= (void*)ACPI_RANGE_END; acpi_addr += 16)
94 {
95 if(*(uint64_t *)acpi_addr == ACPI_SIGNATURE_UINT64_LE)
96 {
97 uint8_t csum = checksum8(acpi_addr, 20);
98
99 /* Only assume this is a 2.0 or better table if the revision is greater than 0
100 * NOTE: ACPI 3.0 spec only seems to say that 1.0 tables have revision 1
101 * and that the current revision is 2.. I am going to assume that rev > 0 is 2.0.
102 */
103
104 if(csum == 0 && (((struct acpi_2_rsdp*)acpi_addr)->Revision > 0))
105 {
106 uint8_t csum2 = checksum8(acpi_addr, sizeof(struct acpi_2_rsdp));
107 if(csum2 == 0)
108 return acpi_addr;
109 }
110 }
111 }
112 return NULL;
113}
114/** The folowing ACPI Table search algo. should be reused anywhere needed:*/
115int search_and_get_acpi_fd(const char * filename, const char ** outDirspec)
116{
117int fd = -1;
118char dirSpec[512] = "";
119
120// Try finding 'filename' in the usual places
121// Start searching any potential location for ACPI Table
122
123if(gSMBIOSBoardModel)
124{
125sprintf(dirSpec,"%s.%s", gSMBIOSBoardModel, filename);
126fd = open(dirSpec, 0);
127}
128
129if (fd < 0)
130{
131sprintf(dirSpec, "%s", filename);
132fd = open(dirSpec, 0);
133if (fd < 0)
134{
135if(gSMBIOSBoardModel)
136{
137sprintf(dirSpec, "/Extra/%s.%s", gSMBIOSBoardModel, filename);
138fd = open(dirSpec, 0);
139}
140if (fd < 0)
141{
142sprintf(dirSpec, "/Extra/%s", filename);
143fd = open(dirSpec, 0);
144if (fd < 0)
145{
146if(gSMBIOSBoardModel)
147{
148sprintf(dirSpec, "bt(0,0)/Extra/%s.%s", gSMBIOSBoardModel, filename);
149fd = open(dirSpec, 0);
150}
151if (fd < 0)
152{
153sprintf(dirSpec, "bt(0,0)/Extra/%s", filename);
154fd = open(dirSpec, 0);
155}
156}
157}
158}
159}
160
161if (fd < 0)
162{
163// NOT FOUND:
164DBG("ACPI table not found: %s\n", filename);
165*dirSpec = '\0';
166}
167
168if (outDirspec) *outDirspec = dirSpec;
169return fd;
170}
171
172
173void *loadACPITable (const char * filename)
174{
175void *tableAddr;
176const char * dirspec=NULL;
177
178int fd = search_and_get_acpi_fd(filename, &dirspec);
179
180if (fd>=0)
181{
182tableAddr=(void*)AllocateKernelMemory(file_size (fd));
183if (tableAddr)
184{
185if (read (fd, tableAddr, file_size (fd))!=file_size (fd))
186{
187verbose("Couldn't read table %s\n",dirspec);
188free (tableAddr);
189close (fd);
190return NULL;
191}
192
193DBG("Table %s read and stored at: %x\n", dirspec, tableAddr);
194close (fd);
195return tableAddr;
196}
197close (fd);
198verbose("Couldn't allocate memory for table \n", dirspec);
199}
200//printf("Couldn't find table %s\n", filename);
201return NULL;
202}
203
204uint8_tacpi_cpu_count = 0;
205char* acpi_cpu_name[32];
206
207void get_acpi_cpu_names(unsigned char* dsdt, uint32_t length)
208{
209uint32_t i;
210
211for (i=0; i<length-7; i++)
212{
213if (dsdt[i] == 0x5B && dsdt[i+1] == 0x83) // ProcessorOP
214{
215uint32_t offset = i + 3 + (dsdt[i+2] >> 6);
216
217bool add_name = true;
218
219uint8_t j;
220
221for (j=0; j<4; j++)
222{
223char c = dsdt[offset+j];
224
225if (!aml_isvalidchar(c))
226{
227add_name = false;
228DBG("Invalid character found in ProcessorOP 0x%x!\n", c);
229break;
230}
231}
232
233if (add_name)
234{
235acpi_cpu_name[acpi_cpu_count] = malloc(4);
236memcpy(acpi_cpu_name[acpi_cpu_count], dsdt+offset, 4);
237i = offset + 5;
238
239DBG("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]);
240
241if (++acpi_cpu_count == 32) return;
242}
243}
244}
245}
246
247struct acpi_2_ssdt *generate_cst_ssdt(struct acpi_2_fadt* fadt)
248{
249char ssdt_header[] =
250{
2510x53, 0x53, 0x44, 0x54, 0xE7, 0x00, 0x00, 0x00, /* SSDT.... */
2520x01, 0x17, 0x50, 0x6D, 0x52, 0x65, 0x66, 0x41, /* ..PmRefA */
2530x43, 0x70, 0x75, 0x43, 0x73, 0x74, 0x00, 0x00, /* CpuCst.. */
2540x00, 0x10, 0x00, 0x00, 0x49, 0x4E, 0x54, 0x4C, /* ....INTL */
2550x31, 0x03, 0x10, 0x20 /* 1.._*/
256};
257
258char cstate_resource_template[] =
259{
2600x11, 0x14, 0x0A, 0x11, 0x82, 0x0C, 0x00, 0x7F,
2610x01, 0x02, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
2620x00, 0x00, 0x00, 0x79, 0x00
263};
264
265if (Platform->CPU.Vendor != 0x756E6547) {
266verbose ("Not an Intel platform: C-States will not be generated !!!\n");
267return NULL;
268}
269
270if (fadt == NULL) {
271verbose ("FACP not exists: C-States will not be generated !!!\n");
272return NULL;
273}
274
275struct acpi_2_dsdt* dsdt = (void*)fadt->DSDT;
276
277if (dsdt == NULL) {
278verbose ("DSDT not found: C-States will not be generated !!!\n");
279return NULL;
280}
281
282if (acpi_cpu_count == 0)
283get_acpi_cpu_names((void*)dsdt, dsdt->Length);
284
285if (acpi_cpu_count > 0)
286{
287bool c2_enabled = false;
288bool c3_enabled = false;
289bool c4_enabled = false;
290
291getBoolForKey(kEnableC2States, &c2_enabled, &bootInfo->bootConfig);
292getBoolForKey(kEnableC3States, &c3_enabled, &bootInfo->bootConfig);
293getBoolForKey(kEnableC4States, &c4_enabled, &bootInfo->bootConfig);
294
295c2_enabled = c2_enabled | (fadt->C2_Latency < 100);
296c3_enabled = c3_enabled | (fadt->C3_Latency < 1000);
297
298unsigned char cstates_count = 1 + (c2_enabled ? 1 : 0) + (c3_enabled ? 1 : 0);
299
300struct aml_chunk* root = aml_create_node(NULL);
301aml_add_buffer(root, ssdt_header, sizeof(ssdt_header)); // SSDT header
302struct aml_chunk* scop = aml_add_scope(root, "\\_PR_");
303struct aml_chunk* name = aml_add_name(scop, "CST_");
304struct aml_chunk* pack = aml_add_package(name);
305aml_add_byte(pack, cstates_count);
306
307struct aml_chunk* tmpl = aml_add_package(pack);
308cstate_resource_template[11] = 0x00; // C1
309aml_add_buffer(tmpl, cstate_resource_template, sizeof(cstate_resource_template));
310aml_add_byte(tmpl, 0x01); // C1
311aml_add_byte(tmpl, 0x01); // Latency
312aml_add_word(tmpl, 0x03e8); // Power
313
314// C2
315if (c2_enabled)
316{
317tmpl = aml_add_package(pack);
318cstate_resource_template[11] = 0x10; // C2
319aml_add_buffer(tmpl, cstate_resource_template, sizeof(cstate_resource_template));
320aml_add_byte(tmpl, 0x02); // C2
321aml_add_byte(tmpl, fadt->C2_Latency);
322aml_add_word(tmpl, 0x01f4); // Power
323}
324// C4
325if (c4_enabled)
326{
327tmpl = aml_add_package(pack);
328cstate_resource_template[11] = 0x30; // C4
329aml_add_buffer(tmpl, cstate_resource_template, sizeof(cstate_resource_template));
330aml_add_byte(tmpl, 0x04); // C4
331aml_add_word(tmpl, fadt->C3_Latency / 2); // TODO: right latency for C4
332aml_add_byte(tmpl, 0xfa); // Power
333}
334else
335// C3
336if (c3_enabled)
337{
338tmpl = aml_add_package(pack);
339cstate_resource_template[11] = 0x20; // C3
340aml_add_buffer(tmpl, cstate_resource_template, sizeof(cstate_resource_template));
341aml_add_byte(tmpl, 0x03); // C3
342aml_add_word(tmpl, fadt->C3_Latency);
343aml_add_word(tmpl, 0x015e); // Power
344}
345
346
347// Aliaces
348int i;
349for (i = 0; i < acpi_cpu_count; i++)
350{
351char name[9];
352sprintf(name, "_PR_%c%c%c%c", acpi_cpu_name[i][0], acpi_cpu_name[i][1], acpi_cpu_name[i][2], acpi_cpu_name[i][3]);
353
354scop = aml_add_scope(root, name);
355aml_add_alias(scop, "CST_", "_CST");
356}
357
358aml_calculate_size(root);
359
360struct acpi_2_ssdt *ssdt = (struct acpi_2_ssdt *)AllocateKernelMemory(root->Size);
361
362aml_write_node(root, (void*)ssdt, 0);
363
364ssdt->Length = root->Size;
365ssdt->Checksum = 0;
366ssdt->Checksum = 256 - checksum8(ssdt, ssdt->Length);
367
368aml_destroy_node(root);
369
370//dumpPhysAddr("C-States SSDT content: ", ssdt, ssdt->Length);
371
372verbose ("SSDT with CPU C-States generated successfully\n");
373
374return ssdt;
375}
376else
377{
378verbose ("ACPI CPUs not found: C-States not generated !!!\n");
379}
380
381return NULL;
382}
383
384struct acpi_2_ssdt *generate_pss_ssdt(struct acpi_2_dsdt* dsdt)
385{
386char ssdt_header[] =
387{
3880x53, 0x53, 0x44, 0x54, 0x7E, 0x00, 0x00, 0x00, /* SSDT.... */
3890x01, 0x6A, 0x50, 0x6D, 0x52, 0x65, 0x66, 0x00, /* ..PmRef. */
3900x43, 0x70, 0x75, 0x50, 0x6D, 0x00, 0x00, 0x00, /* CpuPm... */
3910x00, 0x30, 0x00, 0x00, 0x49, 0x4E, 0x54, 0x4C, /* .0..INTL */
3920x31, 0x03, 0x10, 0x20,/* 1.._*/
393};
394cpuid_update_generic_info();
395if (Platform->CPU.Vendor != 0x756E6547) {
396verbose ("Not an Intel platform: P-States will not be generated !!!\n");
397return NULL;
398}
399
400if (!(Platform->CPU.Features & CPU_FEATURE_MSR)) {
401verbose ("Unsupported CPU: P-States will not be generated !!!\n");
402return NULL;
403}
404
405if (acpi_cpu_count == 0)
406get_acpi_cpu_names((void*)dsdt, dsdt->Length);
407
408if (acpi_cpu_count > 0)
409{
410struct p_state initial, maximum, minimum, p_states[32];
411uint8_t p_states_count = 0;
412
413// Retrieving P-States, ported from code by superhai (c)
414switch (Platform->CPU.Family) {
415case 0x06:
416{
417switch (Platform->CPU.Model)
418{
419case CPU_MODEL_PENTIUM_M: // ?
420case CPU_MODEL_YONAH: // Yonah
421case CPU_MODEL_MEROM: // Merom
422case CPU_MODEL_PENRYN: // Penryn
423case CPU_MODEL_ATOM: // Intel Atom (45nm)
424{
425bool cpu_dynamic_fsb = false;
426
427if (rdmsr64(MSR_IA32_EXT_CONFIG) & (1 << 27))
428{
429wrmsr64(MSR_IA32_EXT_CONFIG, (rdmsr64(MSR_IA32_EXT_CONFIG) | (1 << 28)));
430delay(1);
431cpu_dynamic_fsb = rdmsr64(MSR_IA32_EXT_CONFIG) & (1 << 28);
432}
433
434bool cpu_noninteger_bus_ratio = (rdmsr64(MSR_IA32_PERF_STATUS) & (1ULL << 46));
435
436initial.Control = rdmsr64(MSR_IA32_PERF_STATUS);
437
438maximum.Control = ((rdmsr64(MSR_IA32_PERF_STATUS) >> 32) & 0x1F3F) | (0x4000 * cpu_noninteger_bus_ratio);
439maximum.CID = ((maximum.FID & 0x1F) << 1) | cpu_noninteger_bus_ratio;
440
441minimum.FID = ((rdmsr64(MSR_IA32_PERF_STATUS) >> 24) & 0x1F) | (0x80 * cpu_dynamic_fsb);
442minimum.VID = ((rdmsr64(MSR_IA32_PERF_STATUS) >> 48) & 0x3F);
443
444if (minimum.FID == 0)
445{
446uint64_t msr;
447uint8_t i;
448// Probe for lowest fid
449for (i = maximum.FID; i >= 0x6; i--)
450{
451msr = rdmsr64(MSR_IA32_PERF_CONTROL);
452wrmsr64(MSR_IA32_PERF_CONTROL, (msr & 0xFFFFFFFFFFFF0000ULL) | (i << 8) | minimum.VID);
453intel_waitforsts();
454minimum.FID = (rdmsr64(MSR_IA32_PERF_STATUS) >> 8) & 0x1F;
455delay(1);
456}
457
458msr = rdmsr64(MSR_IA32_PERF_CONTROL);
459wrmsr64(MSR_IA32_PERF_CONTROL, (msr & 0xFFFFFFFFFFFF0000ULL) | (maximum.FID << 8) | maximum.VID);
460intel_waitforsts();
461}
462
463if (minimum.VID == maximum.VID)
464{
465uint64_t msr;
466uint8_t i;
467// Probe for lowest vid
468for (i = maximum.VID; i > 0xA; i--)
469{
470msr = rdmsr64(MSR_IA32_PERF_CONTROL);
471wrmsr64(MSR_IA32_PERF_CONTROL, (msr & 0xFFFFFFFFFFFF0000ULL) | (minimum.FID << 8) | i);
472intel_waitforsts();
473minimum.VID = rdmsr64(MSR_IA32_PERF_STATUS) & 0x3F;
474delay(1);
475}
476
477msr = rdmsr64(MSR_IA32_PERF_CONTROL);
478wrmsr64(MSR_IA32_PERF_CONTROL, (msr & 0xFFFFFFFFFFFF0000ULL) | (maximum.FID << 8) | maximum.VID);
479intel_waitforsts();
480}
481
482minimum.CID = ((minimum.FID & 0x1F) << 1) >> cpu_dynamic_fsb;
483
484// Sanity check
485if (maximum.CID < minimum.CID)
486{
487DBG("Insane FID values!");
488p_states_count = 0;
489}
490else
491{
492// Finalize P-States
493// Find how many P-States machine supports
494p_states_count = maximum.CID - minimum.CID + 1;
495
496if (p_states_count > 32)
497p_states_count = 32;
498
499uint8_t vidstep;
500uint8_t i = 0, u, invalid = 0;
501
502vidstep = ((maximum.VID << 2) - (minimum.VID << 2)) / (p_states_count - 1);
503
504for (u = 0; u < p_states_count; u++)
505{
506i = u - invalid;
507
508p_states[i].CID = maximum.CID - u;
509p_states[i].FID = (p_states[i].CID >> 1);
510
511if (p_states[i].FID < 0x6)
512{
513if (cpu_dynamic_fsb)
514p_states[i].FID = (p_states[i].FID << 1) | 0x80;
515}
516else if (cpu_noninteger_bus_ratio)
517{
518p_states[i].FID = p_states[i].FID | (0x40 * (p_states[i].CID & 0x1));
519}
520
521if (i && p_states[i].FID == p_states[i-1].FID)
522invalid++;
523
524p_states[i].VID = ((maximum.VID << 2) - (vidstep * u)) >> 2;
525
526uint32_t multiplier = p_states[i].FID & 0x1f;// = 0x08
527bool half = p_states[i].FID & 0x40;// = 0x01
528bool dfsb = p_states[i].FID & 0x80;// = 0x00
529uint32_t fsb = Platform->CPU.FSBFrequency / 1000000; // = 400
530uint32_t halffsb = (fsb + 1) >> 1;// = 200
531uint32_t frequency = (multiplier * fsb);// = 3200
532
533p_states[i].Frequency = (frequency + (half * halffsb)) >> dfsb;// = 3200 + 200 = 3400
534}
535
536p_states_count -= invalid;
537}
538} break;
539case CPU_MODEL_FIELDS:
540case CPU_MODEL_DALES:
541case CPU_MODEL_DALES_32NM:
542case CPU_MODEL_NEHALEM:
543case CPU_MODEL_NEHALEM_EX:
544case CPU_MODEL_WESTMERE:
545case CPU_MODEL_WESTMERE_EX:
546{
547maximum.Control = rdmsr64(MSR_IA32_PERF_STATUS) & 0xff; // Seems it always contains maximum multiplier value (with turbo, that's we need)...
548minimum.Control = (rdmsr64(MSR_PLATFORM_INFO) >> 40) & 0xff;
549
550verbose("P-States: min 0x%x, max 0x%x\n", minimum.Control, maximum.Control);
551
552// Sanity check
553if (maximum.Control < minimum.Control)
554{
555DBG("Insane control values!");
556p_states_count = 0;
557}
558else
559{
560uint8_t i;
561p_states_count = 0;
562
563for (i = maximum.Control; i >= minimum.Control; i--)
564{
565p_states[p_states_count].Control = i;
566p_states[p_states_count].CID = p_states[p_states_count].Control << 1;
567p_states[p_states_count].Frequency = (Platform->CPU.FSBFrequency / 1000000) * i;
568p_states_count++;
569}
570}
571
572break;
573}
574default:
575verbose ("Unsupported CPU (0x%X): P-States not generated !!!\n", Platform->CPU.Family);
576break;
577}
578}
579}
580
581// Generating SSDT
582if (p_states_count > 0)
583{
584int i;
585
586struct aml_chunk* root = aml_create_node(NULL);
587aml_add_buffer(root, ssdt_header, sizeof(ssdt_header)); // SSDT header
588struct aml_chunk* scop = aml_add_scope(root, "\\_PR_");
589struct aml_chunk* name = aml_add_name(scop, "PSS_");
590struct aml_chunk* pack = aml_add_package(name);
591
592for (i = 0; i < p_states_count; i++)
593{
594struct aml_chunk* pstt = aml_add_package(pack);
595
596aml_add_dword(pstt, p_states[i].Frequency);
597aml_add_dword(pstt, 0x00000000); // Power
598aml_add_dword(pstt, 0x0000000A); // Latency
599aml_add_dword(pstt, 0x0000000A); // Latency
600aml_add_dword(pstt, p_states[i].Control);
601aml_add_dword(pstt, i+1); // Status
602}
603
604// Add aliaces
605for (i = 0; i < acpi_cpu_count; i++)
606{
607char name[9];
608sprintf(name, "_PR_%c%c%c%c", acpi_cpu_name[i][0], acpi_cpu_name[i][1], acpi_cpu_name[i][2], acpi_cpu_name[i][3]);
609
610scop = aml_add_scope(root, name);
611aml_add_alias(scop, "PSS_", "_PSS");
612}
613
614aml_calculate_size(root);
615
616struct acpi_2_ssdt *ssdt = (struct acpi_2_ssdt *)AllocateKernelMemory(root->Size);
617
618aml_write_node(root, (void*)ssdt, 0);
619
620ssdt->Length = root->Size;
621ssdt->Checksum = 0;
622ssdt->Checksum = 256 - checksum8(ssdt, ssdt->Length);
623
624aml_destroy_node(root);
625
626//dumpPhysAddr("P-States SSDT content: ", ssdt, ssdt->Length);
627
628verbose ("SSDT with CPU P-States generated successfully\n");
629
630return ssdt;
631}
632}
633else
634{
635verbose ("ACPI CPUs not found: P-States not generated !!!\n");
636}
637
638return NULL;
639}
640
641struct acpi_2_fadt *patch_fadt(struct acpi_2_fadt *fadt, struct acpi_2_dsdt *new_dsdt)
642{
643extern void setupSystemType();
644
645struct acpi_2_fadt *fadt_mod = NULL;
646bool fadt_rev2_needed = false;
647//bool fix_restart;
648const char * value;
649
650// Restart Fix
651if (Platform->CPU.Vendor == 0x756E6547) {/* Intel */
652fix_restart = true;
653getBoolForKey(kRestartFix, &fix_restart, &bootInfo->bootConfig);
654} else {
655DBG ("Not an Intel platform: Restart Fix not applied !!!\n");
656fix_restart = false;
657}
658
659if (fix_restart) fadt_rev2_needed = true;
660
661// Allocate new fadt table
662if (fadt->Length < 0x84 && fadt_rev2_needed)
663{
664fadt_mod=(struct acpi_2_fadt *)AllocateKernelMemory(0x84);
665memcpy(fadt_mod, fadt, fadt->Length);
666fadt_mod->Length = 0x84;
667fadt_mod->Revision = 0x02; // FADT rev 2 (ACPI 1.0B MS extensions)
668}
669else
670{
671fadt_mod=(struct acpi_2_fadt *)AllocateKernelMemory(fadt->Length);
672memcpy(fadt_mod, fadt, fadt->Length);
673}
674// Determine system type / PM_Model
675if (fadt_mod && Platform->Type) {
676fadt_mod->PM_Profile = Platform->Type;
677} else if(fadt)
678Platform->Type = fadt->PM_Profile;
679else
680Platform->Type = 1;
681
682//User override default value
683if ( (value=getStringForKey(kSystemType, &bootInfo->bootConfig))!=NULL)
684{
685if (Platform->Type > 6)
686{
687if(fadt_mod->PM_Profile<=6)
688Platform->Type = fadt_mod->PM_Profile; // get the fadt if correct
689else
690Platform->Type = 1;/* Set a fixed value (Desktop) */
691verbose("Error: system-type must be 0..6. Defaulting to %d !\n", Platform->Type);
692}
693else
694Platform->Type = (unsigned char) strtoul(value, NULL, 10);
695}
696// Set PM_Profile from System-type if only user wanted this value to be forced
697if (fadt_mod->PM_Profile != Platform->Type)
698{
699 if (value)
700{ // user has overriden the SystemType so take care of it in FACP
701DBG("FADT: changing PM_Profile from 0x%02x to 0x%02x\n", fadt_mod->PM_Profile, Platform->Type);
702fadt_mod->PM_Profile = Platform->Type;
703 }
704 else
705 { // PM_Profile has a different value and no override has been set, so reflect the user value to ioregs
706Platform->Type = fadt_mod->PM_Profile <= 6 ? fadt_mod->PM_Profile : 1;
707 }
708}
709// We now have to write the systemm-type in ioregs: we cannot do it before in setupDeviceTree()
710// because we need to take care of facp original content, if it is correct.
711setupSystemType();
712
713// Patch FADT to fix restart
714if (fix_restart)
715{
716fadt_mod->Flags|= 0x400;
717fadt_mod->Reset_SpaceID= 0x01; // System I/O
718fadt_mod->Reset_BitWidth= 0x08; // 1 byte
719fadt_mod->Reset_BitOffset= 0x00; // Offset 0
720fadt_mod->Reset_AccessWidth= 0x01; // Byte access
721fadt_mod->Reset_Address= 0x0cf9; // Address of the register
722fadt_mod->Reset_Value= 0x06; // Value to write to reset the system
723msglog("FADT: Restart Fix applied!\n");
724}
725
726// Patch DSDT Address if we have loaded DSDT.aml
727if(new_dsdt)
728{
729DBG("DSDT: Old @%x,%x, ",fadt_mod->DSDT,fadt_mod->X_DSDT);
730
731// Insert old dsdt into the IORegistery
732Node* node = DT__FindNode("/dsdt", false);
733if(node == NULL)
734{
735// Only add if not already here
736Node* node = DT__FindNode("/", false);
737
738if(node != NULL)
739{
740node = DT__AddChild(node, "dsdt");
741
742struct acpi_2_dsdt *dsdt;
743dsdt = (struct acpi_2_dsdt*) (fadt_mod->DSDT);
744DT__AddProperty(node, "originaldsdt", (dsdt->Length + sizeof(struct acpi_2_dsdt) - 1), (void*)dsdt);/// Insert old dsdt. Length is header length (36) + dsdt length
745
746}
747}
748
749fadt_mod->DSDT=(uint32_t)new_dsdt;
750if ((uint32_t)(&(fadt_mod->X_DSDT))-(uint32_t)fadt_mod+8<=fadt_mod->Length)
751fadt_mod->X_DSDT=(uint32_t)new_dsdt;
752
753DBG("New @%x,%x\n",fadt_mod->DSDT,fadt_mod->X_DSDT);
754
755DBG("FADT: Using custom DSDT!\n");
756}
757
758// Correct the checksum
759fadt_mod->Checksum=0;
760fadt_mod->Checksum=256-checksum8(fadt_mod,fadt_mod->Length);
761
762return fadt_mod;
763}
764
765/* Setup ACPI without replacing DSDT. */
766int setupAcpiNoMod()
767{
768//addConfigurationTable(&gEfiAcpiTableGuid, getAddressOfAcpiTable(), "ACPI");
769//addConfigurationTable(&gEfiAcpi20TableGuid, getAddressOfAcpi20Table(), "ACPI_20");
770/* XXX aserebln why uint32 cast if pointer is uint64 ? */
771//Slice (uint64_t)
772acpi10_p = (uint64_t)(uint32_t)getAddressOfAcpiTable();
773acpi20_p = (uint64_t)(uint32_t)getAddressOfAcpi20Table();
774addConfigurationTable(&gEfiAcpiTableGuid, &acpi10_p, "ACPI");
775if(acpi20_p) addConfigurationTable(&gEfiAcpi20TableGuid, &acpi20_p, "ACPI_20");
776else {
777DBG("no ACPI 2\n");
778}
779return 1;
780}
781
782static struct acpi_2_xsdt* createNewXSDTfromRSDT(struct acpi_2_rsdt * rsdt)
783{
784struct acpi_2_xsdt *xsdt;
785int xsdt_entries_num, i;
786uint32_t xsdt_len;
787if (!rsdt) {
788return NULL;
789}
790//Create XSDT in addition to RSDT as a 64bit copy
791if((rsdt->Length<0) || (rsdt->Length>1000)){
792DBG(" incorrect RSDT length: %08lx\n", rsdt->Length);
793#if DEBUG_DSDT
794getc();
795#endif
796return NULL;
797}
798xsdt_entries_num = (rsdt->Length - sizeof(struct acpi_2_rsdt)) >> 2;
799xsdt_len = sizeof(struct acpi_2_rsdt) + (xsdt_entries_num << 3);
800xsdt = (struct acpi_2_xsdt*)AllocateKernelMemory(xsdt_len);
801bcopy(rsdt, xsdt, sizeof(struct acpi_2_rsdt));
802//Change signature from RSDT to XSDT
803strncpy(xsdt->Signature, FourChar("XSDT"), 4);
804//Now copy address table
805uint64_t *table1 = (uint64_t *)(xsdt+1);
806uint32_t *table2 = (uint32_t *)(rsdt+1);
807if ((xsdt_entries_num>0) && (xsdt_entries_num<20)) {
808for(i=0; i<xsdt_entries_num; i++){
809table1[i] = (uint64_t)table2[i];
810}
811} else {
812DBG("RSDT entries = %d xsdtAddr = %08lx rsdtAdrr = %08lx\n",
813xsdt_entries_num, (uint32_t)xsdt, (uint32_t)rsdt);
814}
815xsdt->Length = xsdt_len;
816//Correct checksums
817xsdt->Checksum=0;
818xsdt->Checksum=256-checksum8(xsdt,xsdt_len);
819return xsdt;
820}
821
822static struct acpi_2_rsdp* createNewACPI20(struct acpi_2_rsdp * old_rsdp)
823{
824if(!old_rsdp) return NULL;
825//Slice I want to copy acpi10 table to create ACPI20
826//uint64_t *xsdt_entries;
827if(*(uint64_t *)old_rsdp != ACPI_SIGNATURE_UINT64_LE){
828DBG(" wrong signature %08lx\n", (*(uint64_t *)old_rsdp));
829return NULL;
830}
831DBG(" old_rsdp = %08lx\n", (uint32_t)old_rsdp);
832//if(((int)old_rsdp->Length < 0) || ((int)old_rsdp->Length > 84))
833//return NULL;
834//No! ACPI10_rsdp_length=20 and no such field old_rsdp->Length
835
836struct acpi_2_rsdp * rsdp=(struct acpi_2_rsdp *) AllocateKernelMemory(36);
837DBG(" new_rsdp = %08lx\n", (uint32_t)rsdp);
838bzero(rsdp, 36);
839bcopy(old_rsdp, rsdp, 20);
840strncpy(rsdp->OEMID, "Apple ", 6);
841rsdp->Revision = 2;
842rsdp->Length = 36;
843struct acpi_2_rsdt *rsdt = (struct acpi_2_rsdt *)(rsdp->RsdtAddress); //copied from old
844//dumpRSDT(rsdt, 0);
845rsdp->XsdtAddress = (uint64_t)(uint32_t)createNewXSDTfromRSDT(rsdt);
846//dumpRSDT((struct acpi_2_rsdt *)(uint32_t)(rsdp->XsdtAddress), 0);
847rsdp->Checksum=0;
848rsdp->Checksum=256-checksum8(rsdp,20);
849rsdp->ExtendedChecksum=0;
850rsdp->ExtendedChecksum=256-checksum8(rsdp,36);
851return rsdp;
852}
853
854
855/* Setup ACPI. Replace DSDT if DSDT.aml is found */
856int setupAcpi(void)
857{
858int version;
859//void *new_dsdt;
860
861const char *filename;
862char dirSpec[128];
863int len = 0, old_dsdt_len = 0;
864struct acpi_2_rsdp *rsdp, *rsdp_mod, *rsdp1 = 0;
865struct acpi_2_rsdt *rsdt, *rsdt_mod = 0;
866struct acpi_2_rsdt *xsdt; //, *xsdt_mod = 0;
867char* old_dsdt = 0;
868
869// Try using the file specified with the DSDT option
870if (getValueForKey(kDSDT, &filename, &len, &bootInfo->bootConfig))
871{
872sprintf(dirSpec, filename);
873}
874else
875{
876sprintf(dirSpec, "DSDT.aml");
877}
878
879// Load replacement DSDT
880new_dsdt = loadACPITable(dirSpec);
881if(!new_dsdt)
882{
883sprintf(dirSpec, "DSDT.%s.aml", gSMBIOSBoardModel);
884new_dsdt = loadACPITable(dirSpec);
885}
886
887// Mozodojo: going to patch FACP and load SSDT's even if DSDT.aml is not present
888/*if (!new_dsdt)
889 {
890 return setupAcpiNoMod();
891 }*/
892
893// Mozodojo: Load additional SSDTs
894struct acpi_2_ssdt *new_ssdt[32]; // 30 + 2 additional tables for pss & cst
895int ssdt_count=0;
896
897// SSDT Options
898bool drop_ssdt=false, generate_pstates=false, generate_cstates=false;
899
900getBoolForKey(kDropSSDT, &drop_ssdt, &bootInfo->bootConfig);
901getBoolForKey(kGeneratePStates, &generate_pstates, &bootInfo->bootConfig);
902getBoolForKey(kGenerateCStates, &generate_cstates, &bootInfo->bootConfig);
903
904{
905int i;
906
907for (i=0; i<30; i++)
908{
909char filename[512];
910
911sprintf(filename, i>0?"SSDT-%d.aml":"SSDT.aml", i);
912
913if(new_ssdt[ssdt_count] = loadACPITable(filename))
914{
915ssdt_count++;
916}
917else
918{
919break;
920}
921}
922}
923
924// Do the same procedure for both versions of ACPI
925for (version=0; version<2; version++) {
926//int rsdplength;
927//Here version=0 for ACPI 1.0 and version=1 for ACPI 2.0
928// Find original rsdp
929rsdp=(struct acpi_2_rsdp *)(version?getAddressOfAcpi20Table():getAddressOfAcpiTable());
930//Slice
931if (!rsdp)
932{
933if (version){
934DBG("No ACPI version 2 found. Creating...\n");
935rsdp=createNewACPI20(rsdp1);
936if(!rsdp){
937addConfigurationTable(&gEfiAcpi20TableGuid, NULL, "ACPI_20");
938continue;
939}
940} else {
941DBG("No ACPI version 1 found. Ignoring\n");
942addConfigurationTable(&gEfiAcpiTableGuid, NULL, "ACPI");
943continue;
944}
945}
946if(!version) rsdp1 = rsdp; //save to create new.
947rsdplength=version?rsdp->Length:20;
948
949DBG("RSDP version %d found @%x. Length=%d\n",version+1,rsdp,rsdplength);
950
951/* FIXME: no check that memory allocation succeeded
952 * Copy and patch RSDP,RSDT, XSDT and FADT
953 * For more info see ACPI Specification pages 110 and following
954 */
955
956rsdp_mod=(struct acpi_2_rsdp *) AllocateKernelMemory(rsdplength);
957memcpy(rsdp_mod, rsdp, rsdplength);
958rsdt=(struct acpi_2_rsdt *)(rsdp->RsdtAddress);
959xsdt=(struct acpi_2_rsdt *)(uint32_t)(rsdp->XsdtAddress);
960DBG("RSDT @%x, Length %d\n",rsdt, rsdt->Length);
961
962//if we have RSDT table
963if (rsdt && (uint32_t)rsdt !=0xffffffff && rsdt->Length<0x10000)
964{
965uint32_t *rsdt_entries;
966int rsdt_entries_num;
967int dropoffset=0, i;
968
969// mozo: using malloc cos I didn't found how to free already allocated kernel memory
970rsdt_mod=(struct acpi_2_rsdt *)malloc(rsdt->Length);
971memcpy (rsdt_mod, rsdt, rsdt->Length);
972rsdp_mod->RsdtAddress=(uint32_t)rsdt_mod;
973rsdt_entries_num=(rsdt_mod->Length-sizeof(struct acpi_2_rsdt))/4;
974rsdt_entries=(uint32_t *)(rsdt_mod+1);
975for (i=0;i<rsdt_entries_num;i++)
976{
977char *table=(char *)(rsdt_entries[i]);
978if (!table)
979continue;
980
981DBG("TABLE %c%c%c%c,",table[0],table[1],table[2],table[3]);
982
983rsdt_entries[i-dropoffset]=rsdt_entries[i];
984
985if (drop_ssdt && tableSign(table, "SSDT"))
986{
987dropoffset++;
988continue;
989}
990if (tableSign(table, "DSDT"))
991{
992DBG("DSDT found\n");
993
994if(new_dsdt)
995rsdt_entries[i-dropoffset]=(uint32_t)new_dsdt;
996
997continue;
998} else {
999//Slice - Correct header to MacModel & Vendor, correct chechsum
1000struct acpi_2_rsdt *t = (struct acpi_2_rsdt *)table;
1001strncpy(t->OEMID, "Apple ", 6);
1002strncpy(t->OEMTableId, MacModel, 8);
1003t->OEMRevision = ModelRev;
1004t->Checksum=0;
1005t->Checksum=256-checksum8(t,t->Length);
1006
1007}
1008if (tableSign(table, "FACP"))
1009{
1010struct acpi_2_fadt *fadt, *fadt_mod;
1011fadt=(struct acpi_2_fadt *)rsdt_entries[i];
1012
1013DBG("FADT found @%x, Length %d\n",fadt, fadt->Length);
1014
1015if (!fadt || (uint32_t)fadt == 0xffffffff || fadt->Length>0x10000)
1016{
1017printf("FADT incorrect. Not modified\n");
1018continue;
1019}
1020DBG("Old DSDT @%x, X_DSDT %x from FADT\n",fadt->DSDT,fadt->X_DSDT);
1021
1022if(version && fix_restart){ //ACPI 2.0
1023fadt_mod = patch_fadt(fadt, new_dsdt);
1024rsdt_entries[i-dropoffset]=(uint32_t)fadt_mod;
1025} else {
1026if (fadt && Platform->Type)
1027fadt->PM_Profile = Platform->Type;//For ACPI1.0 the only patch
1028fadt_mod = fadt;
1029rsdt_entries[i-dropoffset]=(uint32_t)fadt;
1030}
1031DBG("FADT_mod table sign: %s\n", fadt_mod->Signature);
1032//Slice
1033//Now I want to replace DSDT in place
1034// it is only way to patch DSDT on some platform
1035old_dsdt = (char *)fadt->DSDT;
1036if(!old_dsdt || !tableSign(old_dsdt, "DSDT")){
1037if(fadt_mod->Length > 140) old_dsdt = (char *)(uint32_t)fadt_mod->X_DSDT;
1038if(!old_dsdt || !tableSign(old_dsdt, "DSDT")) old_dsdt = (char *)new_dsdt;
1039}
1040DBG("New DSDT @%x, X_DSDT %x after FADT patch\n",fadt_mod->DSDT,fadt_mod->X_DSDT);
1041
1042if(tableSign(old_dsdt, "DSDT"))
1043old_dsdt_len = ((struct acpi_2_rsdt *)old_dsdt)->Length;
1044int new_dsdt_len = ((struct acpi_2_rsdt *)new_dsdt)->Length;
1045if(new_dsdt_len > old_dsdt_len) {
1046old_dsdt = (char *)new_dsdt;
1047DBG(" New DSDT is longer then old\n");
1048len = 0;
1049}
1050else len = new_dsdt_len;
1051
1052
1053// Generate _CST SSDT
1054if (generate_cstates && (new_ssdt[ssdt_count] = generate_cst_ssdt(fadt_mod)))
1055{
1056generate_cstates = false; // Generate SSDT only once!
1057ssdt_count++;
1058}
1059
1060// Generating _PSS SSDT
1061if (generate_pstates && (new_ssdt[ssdt_count] = generate_pss_ssdt((void*)fadt_mod->DSDT)))
1062{
1063generate_pstates = false; // Generate SSDT only once!
1064ssdt_count++;
1065}
1066
1067continue;
1068}
1069}//for rsdt entries
1070DBG("\n");
1071//Slice - Correct header to MacModel & Vendor, correct chechsum
1072strncpy(rsdt_mod->OEMID, "Apple ", 6);
1073strncpy(rsdt_mod->OEMTableId, MacModel, 8);
1074rsdt_mod->OEMRevision = ModelRev;
1075
1076// Allocate rsdt in Kernel memory area
1077rsdt_mod->Length += 4*ssdt_count - 4*dropoffset;
1078struct acpi_2_rsdt *rsdt_copy = (struct acpi_2_rsdt *)AllocateKernelMemory(rsdt_mod->Length);
1079memcpy (rsdt_copy, rsdt_mod, rsdt_mod->Length);
1080free(rsdt_mod); rsdt_mod = rsdt_copy;
1081rsdp_mod->RsdtAddress=(uint32_t)rsdt_mod;
1082rsdt_entries_num=(rsdt_mod->Length-sizeof(struct acpi_2_rsdt))/4;
1083rsdt_entries=(uint32_t *)(rsdt_mod+1);
1084
1085// Mozodojo: Insert additional SSDTs into RSDT
1086if(ssdt_count>0)
1087{
1088int j;
1089
1090for (j=0; j<ssdt_count; j++)
1091rsdt_entries[i-dropoffset+j]=(uint32_t)new_ssdt[j];
1092
1093DBG("RSDT: Added %d SSDT table(s)\n", ssdt_count);
1094}
1095
1096// Correct the checksum of RSDT
1097//DBG("RSDT: Original checksum %d, ", rsdt_mod->Checksum);
1098
1099rsdt_mod->Checksum=0;
1100rsdt_mod->Checksum=256-checksum8(rsdt_mod,rsdt_mod->Length);
1101
1102//DBG("New checksum %d at %x\n", rsdt_mod->Checksum,rsdt_mod);
1103}
1104else
1105{
1106rsdp_mod->RsdtAddress=0;
1107verbose("RSDT not found or RSDT incorrect\n");
1108}
1109
1110if (version)
1111{
1112struct acpi_2_xsdt *xsdt, *xsdt_mod;
1113
1114// FIXME: handle 64-bit address correctly
1115
1116xsdt=(struct acpi_2_xsdt*) ((uint32_t)rsdp->XsdtAddress);
1117DBG("XSDT @%x;%x, Length=%d Sign=%c%c%c%c\n", (uint32_t)(rsdp->XsdtAddress>>32),
1118(uint32_t)rsdp->XsdtAddress, xsdt->Length, xsdt[0], xsdt[1], xsdt[2], xsdt[3]);
1119if (xsdt && (uint64_t)rsdp->XsdtAddress<0xffffffff && xsdt->Length<0x10000)
1120{
1121uint64_t *xsdt_entries;
1122int xsdt_entries_num, i;
1123int dropoffset=0;
1124
1125// mozo: using malloc cos I didn't found how to free already allocated kernel memory
1126xsdt_mod=(struct acpi_2_xsdt*)malloc(xsdt->Length);
1127memcpy(xsdt_mod, xsdt, xsdt->Length);
1128rsdp_mod->XsdtAddress=(uint32_t)xsdt_mod;
1129xsdt_entries_num=(xsdt_mod->Length-sizeof(struct acpi_2_xsdt))/8;
1130xsdt_entries=(uint64_t *)(xsdt_mod+1);
1131for (i=0;i<xsdt_entries_num;i++)
1132{
1133char *table=(char *)((uint32_t)(xsdt_entries[i]));
1134if (!table)
1135continue;
1136
1137xsdt_entries[i-dropoffset]=xsdt_entries[i];
1138
1139if (drop_ssdt && tableSign(table, "SSDT"))
1140{
1141dropoffset++;
1142continue;
1143}
1144if (tableSign(table, "DSDT"))
1145{
1146DBG("DSDT found\n");
1147
1148if (new_dsdt)
1149xsdt_entries[i-dropoffset]=(uint32_t)new_dsdt;
1150
1151DBG("TABLE %c%c%c%c@%x \n", table[0],table[1],table[2],table[3],xsdt_entries[i]);
1152
1153continue;
1154}
1155if (tableSign(table, "FACP"))
1156{
1157struct acpi_2_fadt *fadt, *fadt_mod;
1158fadt=(struct acpi_2_fadt *)(uint32_t)xsdt_entries[i];
1159
1160DBG("FADT found @%x%x, Length %d\n", (uint32_t)(xsdt_entries[i]>>32),fadt,
1161fadt->Length);
1162
1163if (!fadt || (uint64_t)xsdt_entries[i] >= 0xffffffff || fadt->Length>0x10000)
1164{
1165DBG("FADT incorrect or after 4GB. Dropping XSDT\n");
1166goto drop_xsdt;
1167}
1168
1169fadt_mod = patch_fadt(fadt, new_dsdt);
1170xsdt_entries[i-dropoffset]=(uint32_t)fadt_mod;
1171
1172DBG("TABLE %c%c%c%c@%x \n", table[0],table[1],table[2],table[3],xsdt_entries[i]);
1173
1174// Generate _CST SSDT
1175if (generate_cstates && (new_ssdt[ssdt_count] = generate_cst_ssdt(fadt_mod)))
1176{
1177generate_cstates = false; // Generate SSDT only once!
1178ssdt_count++;
1179}
1180
1181// Generating _PSS SSDT
1182if (generate_pstates && (new_ssdt[ssdt_count] = generate_pss_ssdt((void*)fadt_mod->DSDT)))
1183{
1184generate_pstates = false; // Generate SSDT only once!
1185ssdt_count++;
1186}
1187
1188continue;
1189}
1190
1191DBG("TABLE %c%c%c%c@%x \n", table[0],table[1],table[2],table[3],xsdt_entries[i]);
1192
1193}
1194
1195// Allocate xsdt in Kernel memory area
1196xsdt_mod->Length += 8*ssdt_count - 8*dropoffset;
1197struct acpi_2_xsdt *xsdt_copy = (struct acpi_2_xsdt *)AllocateKernelMemory(xsdt_mod->Length);
1198memcpy(xsdt_copy, xsdt_mod, xsdt_mod->Length);
1199free(xsdt_mod); xsdt_mod = xsdt_copy;
1200rsdp_mod->XsdtAddress=(uint32_t)xsdt_mod;
1201xsdt_entries_num=(xsdt_mod->Length-sizeof(struct acpi_2_xsdt))/8;
1202xsdt_entries=(uint64_t *)(xsdt_mod+1);
1203
1204// Mozodojo: Insert additional SSDTs into XSDT
1205if(ssdt_count>0)
1206{
1207int j;
1208
1209for (j=0; j<ssdt_count; j++)
1210xsdt_entries[i-dropoffset+j]=(uint32_t)new_ssdt[j];
1211
1212DBG("Added %d SSDT table(s) into XSDT\n", ssdt_count);
1213}
1214
1215// Correct the checksum of XSDT
1216xsdt_mod->Checksum=0;
1217xsdt_mod->Checksum=256-checksum8(xsdt_mod,xsdt_mod->Length);
1218}
1219else
1220{
1221drop_xsdt:
1222
1223DBG("About to drop XSDT\n");
1224
1225/*FIXME: Now we just hope that if MacOS doesn't find XSDT it reverts to RSDT.
1226 * A Better strategy would be to generate
1227 */
1228//Slice - it is possible only for ACPI20
1229if (version) {
1230if(rsdp->RsdtAddress){
1231rsdp_mod->XsdtAddress =
1232(uint64_t)(uint32_t)createNewXSDTfromRSDT((struct acpi_2_rsdt*)rsdp->RsdtAddress);
1233continue;
1234}
1235else
1236DBG(" no sample to create XSDT, dropping\n");
1237}
1238
1239rsdp_mod->XsdtAddress=0xffffffffffffffffLL;
1240DBG("XSDT not found or XSDT incorrect\n");
1241}
1242}
1243//Slice - correct DSDT in place
1244if(len && old_dsdt && new_dsdt && (old_dsdt != new_dsdt)){
1245DBG("old_dsdt=%08x new_dsdt=%08x new_len=%d\n", (unsigned int)old_dsdt, (unsigned int)new_dsdt, len);
1246bcopy(new_dsdt, old_dsdt, len);
1247}
1248
1249// Correct the checksum of RSDP
1250
1251DBG("RSDP: Original checksum %d, ", rsdp_mod->Checksum);
1252
1253rsdp_mod->Checksum=0;
1254rsdp_mod->Checksum=256-checksum8(rsdp_mod,20);
1255
1256DBG("New checksum %d\n", rsdp_mod->Checksum);
1257
1258if (version)
1259{
1260DBG("RSDP: Original extended checksum %d", rsdp_mod->ExtendedChecksum);
1261
1262rsdp_mod->ExtendedChecksum=0;
1263rsdp_mod->ExtendedChecksum=256-checksum8(rsdp_mod,rsdp_mod->Length);
1264
1265DBG("New extended checksum %d\n", rsdp_mod->ExtendedChecksum);
1266
1267}
1268
1269//verbose("Patched ACPI version %d DSDT\n", version+1);
1270if (version)
1271{
1272/* XXX aserebln why uint32 cast if pointer is uint64 ? */
1273//Slice because rsdp_mod is a pointer (32bit in i386) to a structure uint64_t*
1274acpi20_p = (uint64_t)(uint32_t)rsdp_mod;
1275addConfigurationTable(&gEfiAcpi20TableGuid, &acpi20_p, "ACPI_20");
1276}
1277else
1278{
1279/* XXX aserebln why uint32 cast if pointer is uint64 ? */
1280acpi10_p = (uint64_t)(uint32_t)rsdp_mod;
1281addConfigurationTable(&gEfiAcpiTableGuid, &acpi10_p, "ACPI");
1282}
1283}
1284#if DEBUG_ACPI
1285printf("Press a key to continue... (DEBUG_ACPI)\n");
1286getc();
1287#endif
1288return 1;
1289}
1290

Archive Download this file

Revision: 714