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