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