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