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