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