1 | /*␊ |
2 | * Copyright 2008 mackerintel␊ |
3 | */␊ |
4 | ␊ |
5 | /*␊ |
6 | * Copyright (c) 2010 cparm <armelcadetpetit@gmail.com>. All rights reserved.␊ |
7 | *␊ |
8 | */␊ |
9 | ␊ |
10 | #include "libsaio.h"␊ |
11 | #include "boot.h"␊ |
12 | #include "bootstruct.h"␊ |
13 | #include "acpi.h"␊ |
14 | #include "efi_tables.h"␊ |
15 | #include "fake_efi.h"␊ |
16 | #include "acpi_patcher.h"␊ |
17 | #include "platform.h"␊ |
18 | #include "cpu.h"␊ |
19 | #include "aml_generator.h"␊ |
20 | #include "xml.h"␊ |
21 | ␊ |
22 | uint64_t acpi10_p;␊ |
23 | uint64_t acpi20_p;␊ |
24 | ␊ |
25 | #ifndef DEBUG_ACPI␊ |
26 | #define DEBUG_ACPI 0␊ |
27 | #endif␊ |
28 | ␊ |
29 | #if DEBUG_ACPI==2␊ |
30 | #define DBG(x...) {printf(x); sleep(1);}␊ |
31 | #elif DEBUG_ACPI==1␊ |
32 | #define DBG(x...) printf(x)␊ |
33 | #else␊ |
34 | #define DBG(x...)␊ |
35 | #endif␊ |
36 | ␊ |
37 | #define EBDA_SEG_ADDR␉␉␉0x40E␊ |
38 | #define EBDA_SEG_LEN␉␉␉0x400␊ |
39 | #define CMOS_BASE_MEMORY␉␉0x15␊ |
40 | ␊ |
41 | extern EFI_STATUS addConfigurationTable();␊ |
42 | ␊ |
43 | extern EFI_GUID gEfiAcpiTableGuid;␊ |
44 | extern EFI_GUID gEfiAcpi20TableGuid;␊ |
45 | ␊ |
46 | #define tableSign(table, sgn) (table[0]==sgn[0] && table[1]==sgn[1] && table[2]==sgn[2] && table[3]==sgn[3])␊ |
47 | ␊ |
48 | #define CMOS_WRITE_BYTE(x, y)␉cmos_write_byte(x, y)␊ |
49 | #define CMOS_READ_BYTE(x)␉cmos_read_byte(x)␊ |
50 | ␊ |
51 | #define RSDP_CHECKSUM_LENGTH 20␊ |
52 | ␊ |
53 | /*-␊ |
54 | *␉FOR biosacpi_search_rsdp AND biosacpi_find_rsdp␊ |
55 | *␊ |
56 | * Copyright (c) 2001 Michael Smith <msmith@freebsd.org>␊ |
57 | * All rights reserved.␊ |
58 | *␊ |
59 | * Redistribution and use in source and binary forms, with or without␊ |
60 | * modification, are permitted provided that the following conditions␊ |
61 | * are met:␊ |
62 | * 1. Redistributions of source code must retain the above copyright␊ |
63 | * notice, this list of conditions and the following disclaimer.␊ |
64 | * 2. Redistributions in binary form must reproduce the above copyright␊ |
65 | * notice, this list of conditions and the following disclaimer in the␊ |
66 | * documentation and/or other materials provided with the distribution.␊ |
67 | *␊ |
68 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND␊ |
69 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE␊ |
70 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE␊ |
71 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE␊ |
72 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL␊ |
73 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS␊ |
74 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)␊ |
75 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT␊ |
76 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY␊ |
77 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF␊ |
78 | * SUCH DAMAGE.␊ |
79 | *␊ |
80 | * $FreeBSD: src/sys/boot/i386/libi386/biosacpi.c,v 1.7 2003/08/25 23:28:31 obrien Exp $␊ |
81 | * $DragonFly: src/sys/boot/pc32/libi386/biosacpi.c,v 1.5 2007/01/17 17:31:19 y0netan1 Exp $␊ |
82 | */␊ |
83 | ␊ |
84 | static struct acpi_2_rsdp *␊ |
85 | biosacpi_search_rsdp(char *base, int length, int rev)␊ |
86 | {␊ |
87 | struct acpi_2_rsdp *rsdp;␊ |
88 | int␉␉␉ofs;␊ |
89 | ␉␊ |
90 | /* search on 16-byte boundaries */␊ |
91 | for (ofs = 0; ofs < length; ofs += 16) {␊ |
92 | ␉␉rsdp = (struct acpi_2_rsdp*)ptov(base + ofs);␊ |
93 | ␉␉␊ |
94 | ␉␉/* compare signature, validate checksum */␊ |
95 | ␉␉if (!strncmp(rsdp->Signature, ACPI_SIG_RSDP, strlen(ACPI_SIG_RSDP))) {␊ |
96 | ␉␉␉␊ |
97 | ␉␉␉uint8_t csum = checksum8(rsdp, RSDP_CHECKSUM_LENGTH);␊ |
98 | if(csum == 0)␊ |
99 | {␊ |
100 | ␉␉␉␉/* Only assume this is a 2.0 or better table if the revision is greater than 0␊ |
101 | ␉␉␉␉ * NOTE: ACPI 3.0 spec only seems to say that 1.0 tables have revision 1␊ |
102 | ␉␉␉␉ * and that the current revision is 2.. I am going to assume that rev > 0 is 2.0.␊ |
103 | ␉␉␉␉ */␊ |
104 | ␉␉␉␉␊ |
105 | ␉␉␉␉if((rsdp->Revision > 0) && rev > 0)␊ |
106 | ␉␉␉␉{␉␉␉␉␉␊ |
107 | ␉␉␉␉␉uint8_t csum2 = checksum8(rsdp, sizeof(struct acpi_2_rsdp));␊ |
108 | ␉␉␉␉␉if(csum2 == 0)␊ |
109 | ␉␉␉␉␉␉return(rsdp);␊ |
110 | ␉␉␉␉}␊ |
111 | ␉␉␉␉␊ |
112 | // Only return the table if it is a true version 1.0 table (Revision 0)␊ |
113 | if((rsdp->Revision == 0) && rev == 0)␊ |
114 | return(rsdp);␊ |
115 | }␊ |
116 | ␉␉␉␊ |
117 | ␉␉}␊ |
118 | }␊ |
119 | return(NULL);␊ |
120 | }␊ |
121 | ␊ |
122 | /*␊ |
123 | * Find the RSDP in low memory. See section 5.2.2 of the ACPI spec.␊ |
124 | */␊ |
125 | static struct acpi_2_rsdp *␊ |
126 | biosacpi_find_rsdp(int rev)␊ |
127 | {␊ |
128 | struct acpi_2_rsdp *rsdp;␊ |
129 | uint16_t␉␉*addr;␊ |
130 | ␉␊ |
131 | /* EBDA is the 1 KB addressed by the 16 bit pointer at 0x40E. */␊ |
132 | addr = (uint16_t *)ptov(EBDA_SEG_ADDR);␊ |
133 | if ((rsdp = biosacpi_search_rsdp((char *)(*addr << 4), EBDA_SEG_LEN, rev)) != NULL)␊ |
134 | ␉␉return (rsdp);␊ |
135 | ␉␊ |
136 | ␉unsigned mem_lower = ((CMOS_READ_BYTE(CMOS_BASE_MEMORY+1) << 8)␊ |
137 | ␉␉␉␉␉␉ | CMOS_READ_BYTE(CMOS_BASE_MEMORY)) << 10;␊ |
138 | ␉␊ |
139 | ␉if ((rsdp = biosacpi_search_rsdp((char *)mem_lower, EBDA_SEG_LEN, rev)) != NULL)␊ |
140 | ␉␉return (rsdp);␊ |
141 | ␉␊ |
142 | ␉␊ |
143 | /* Check the upper memory BIOS space, 0xe0000 - 0xfffff. */␊ |
144 | if ((rsdp = biosacpi_search_rsdp((char *)0xe0000, 0x20000, rev)) != NULL)␊ |
145 | ␉␉return (rsdp);␊ |
146 | ␉␊ |
147 | return (NULL);␊ |
148 | }␊ |
149 | ␊ |
150 | ␊ |
151 | ␊ |
152 | #define __RES(s, u)␉␉␉␉␉␉␉␉␉␉␉␉\␊ |
153 | inline unsigned u␉␉␉␉␉␉␉␉␉␉\␊ |
154 | resolve_##s(unsigned u defaultentry, char *str, int base) \␊ |
155 | {␉␉␉␉␉␉␉␉␉␉␉␉␉␉␉␉\␊ |
156 | unsigned u entry = defaultentry;␉␉␉␉␉␉␉\␊ |
157 | if (str && (strcmp(str,"Default") != 0)) {␉␉␉␉␉\␊ |
158 | entry = strtoul((const char *)str, NULL,base);␉␉␉␉\␊ |
159 | }␉␉␉␉␉␉␉␉␉␉␉␉␉␉␉\␊ |
160 | return entry;␉␉␉␉␉␉␉␉␉␉␉␉\␊ |
161 | }␊ |
162 | ␊ |
163 | __RES(pss, long) ␊ |
164 | __RES(cst, int) ␊ |
165 | ␊ |
166 | ␊ |
167 | static void setchecksum(struct acpi_common_header *header)␊ |
168 | { ␊ |
169 | header->Checksum = 0;␊ |
170 | header->Checksum = 256-checksum8(header, header->Length);␊ |
171 | }␊ |
172 | ␊ |
173 | static void setRsdpchecksum(struct acpi_2_rsdp *rsdp)␊ |
174 | { ␊ |
175 | rsdp->Checksum = 0;␊ |
176 | rsdp->Checksum = 256-checksum8(rsdp, 20);␊ |
177 | }␊ |
178 | ␊ |
179 | static void setRsdpXchecksum(struct acpi_2_rsdp *rsdp)␊ |
180 | { ␊ |
181 | rsdp->ExtendedChecksum = 0;␊ |
182 | rsdp->ExtendedChecksum = 256-checksum8(rsdp, rsdp->Length);␊ |
183 | }␊ |
184 | ␊ |
185 | static struct acpi_2_rsdp * gen_rsdp_v2_from_v1(struct acpi_2_rsdp *rsdp)␊ |
186 | {␊ |
187 | struct acpi_2_rsdp * rsdp_conv = (struct acpi_2_rsdp *)AllocateKernelMemory(sizeof(struct acpi_2_rsdp));␊ |
188 | memcpy(rsdp_conv, rsdp, 20);␊ |
189 | ␊ |
190 | /* Add/change fields */␊ |
191 | rsdp_conv->Revision = 2; /* ACPI version 3 */␊ |
192 | rsdp_conv->Length = sizeof(struct acpi_2_rsdp);␊ |
193 | ␊ |
194 | /* Correct checksums */ ␊ |
195 | setRsdpchecksum(rsdp_conv);␊ |
196 | setRsdpXchecksum(rsdp_conv);␊ |
197 | ␊ |
198 | rsdp = rsdp_conv;␊ |
199 | ␊ |
200 | return rsdp_conv;␊ |
201 | }␊ |
202 | ␊ |
203 | static struct acpi_2_xsdt * gen_xsdt_from_rsdt(struct acpi_2_rsdt *rsdt)␊ |
204 | {␊ |
205 | int i,rsdt_entries_num=(rsdt->Length-sizeof(struct acpi_2_rsdt))/4;␊ |
206 | ␊ |
207 | uint32_t *rsdt_entries=(uint32_t *)(rsdt+1);␊ |
208 | ␊ |
209 | struct acpi_2_xsdt * xsdt_conv=(struct acpi_2_xsdt *)AllocateKernelMemory(sizeof(struct acpi_2_xsdt)+(rsdt_entries_num * 8));␊ |
210 | memcpy(xsdt_conv, rsdt, sizeof(struct acpi_2_rsdt));␊ |
211 | ␊ |
212 | xsdt_conv->Signature[0] = 'X';␊ |
213 | xsdt_conv->Signature[1] = 'S';␊ |
214 | xsdt_conv->Signature[2] = 'D';␊ |
215 | xsdt_conv->Signature[3] = 'T';␊ |
216 | xsdt_conv->Length = sizeof(struct acpi_2_xsdt)+(rsdt_entries_num * 8);␊ |
217 | ␊ |
218 | uint64_t *xsdt_conv_entries=(uint64_t *)(xsdt_conv+1);␊ |
219 | ␊ |
220 | for (i=0;i<rsdt_entries_num;i++)␊ |
221 | {␊ |
222 | xsdt_conv_entries[i] = (uint64_t)rsdt_entries[i];␊ |
223 | }␊ |
224 | ␊ |
225 | setchecksum((struct acpi_common_header *)xsdt_conv);␊ |
226 | ␊ |
227 | return xsdt_conv;␊ |
228 | }␊ |
229 | ␊ |
230 | static void update_rsdp_with_xsdt(struct acpi_2_rsdp *rsdp, struct acpi_2_xsdt *xsdt)␊ |
231 | {␊ |
232 | rsdp->XsdtAddress = (uint32_t)xsdt;␊ |
233 | ␊ |
234 | setRsdpXchecksum(rsdp);␊ |
235 | }␊ |
236 | ␊ |
237 | static void update_rsdp_with_rsdt(struct acpi_2_rsdp *rsdp, struct acpi_2_rsdt *rsdt)␊ |
238 | {␊ |
239 | rsdp->RsdtAddress = (uint32_t)rsdt; ␊ |
240 | ␊ |
241 | setRsdpchecksum(rsdp);␊ |
242 | ␊ |
243 | }␊ |
244 | ␊ |
245 | ␊ |
246 | void *loadSSDTTable(int ssdt_number)␊ |
247 | {␉␊ |
248 | ␉int fd = -1;␊ |
249 | ␉char dirspec[512];␊ |
250 | ␉char filename[512];␊ |
251 | ␉const char * overriden_pathname=NULL;␊ |
252 | ␉int len=0;␊ |
253 | ␉␊ |
254 | ␉// Check booting partition␊ |
255 | ␉␊ |
256 | ␉// Rek: if user specified a full path name then take it in consideration␊ |
257 | ␉if (getValueForKey(kSSDT, &overriden_pathname, &len, ␊ |
258 | ␉␉␉␉␉ &bootInfo->bootConfig))␊ |
259 | ␉{␊ |
260 | ␉␉sprintf(filename, "%s-%d.aml", overriden_pathname, ssdt_number); // start searching root␉␉␊ |
261 | ␉}␊ |
262 | ␉else␊ |
263 | ␉␉sprintf(filename, "SSDT-%d.aml", ssdt_number);␊ |
264 | ␉␊ |
265 | ␉sprintf(dirspec, "/%s", filename); // start searching root␊ |
266 | ␉␊ |
267 | ␉fd=open (dirspec);␊ |
268 | ␉␊ |
269 | ␉if (fd<0)␊ |
270 | ␉{␉// Check Extra on booting partition␊ |
271 | ␉␉sprintf(dirspec,"/Extra/%s",filename);␊ |
272 | ␉␉fd=open (dirspec);␊ |
273 | ␉␉if (fd<0)␊ |
274 | ␉␉{␉// Fall back to booter partition␊ |
275 | ␉␉␉sprintf(dirspec,"bt(0,0)/Extra/%s",filename);␊ |
276 | ␉␉␉fd=open (dirspec);␊ |
277 | ␉␉␉if (fd<0)␊ |
278 | ␉␉␉{␊ |
279 | ␉␉␉␉DBG("SSDT Table not found: %s\n", filename);␊ |
280 | ␉␉␉␉return NULL;␊ |
281 | ␉␉␉}␊ |
282 | ␉␉}␊ |
283 | ␉}␉␊ |
284 | ␉␊ |
285 | ␉void *tableAddr=(void*)AllocateKernelMemory(file_size (fd));␊ |
286 | ␉if (tableAddr)␊ |
287 | ␉{␊ |
288 | ␉␉if (read (fd, tableAddr, file_size (fd))!=file_size (fd))␊ |
289 | ␉␉{␊ |
290 | ␉␉␉printf("Couldn't read table %s\n",dirspec);␊ |
291 | ␉␉␉free (tableAddr);␊ |
292 | ␉␉␉close (fd);␊ |
293 | ␉␉␉return NULL;␊ |
294 | ␉␉}␊ |
295 | ␉␉␊ |
296 | ␉␉printf("Valid SSDT Table found: %s\n", filename);␊ |
297 | ␉␉DBG("Table %s read and stored at: %x\n", dirspec, tableAddr);␊ |
298 | ␉␉close (fd);␊ |
299 | ␉␉return tableAddr;␊ |
300 | ␉}␊ |
301 | ␉␊ |
302 | ␉printf("Couldn't allocate memory for table %s\n", dirspec);␊ |
303 | ␉close (fd);␊ |
304 | ␉␊ |
305 | ␉return NULL;␊ |
306 | }␊ |
307 | ␊ |
308 | void *loadACPITable(char *key)␊ |
309 | {␉␊ |
310 | ␉int fd = -1;␊ |
311 | ␉char dirspec[512];␊ |
312 | ␉char filename[512];␊ |
313 | ␉const char * overriden_pathname=NULL;␊ |
314 | ␉int len=0;␊ |
315 | ␊ |
316 | ␉DBG("Searching for %s.aml file ...\n", key);␊ |
317 | ␉// Check booting partition␉␊ |
318 | ␊ |
319 | ␉// Rek: if user specified a full path name then take it in consideration␊ |
320 | ␉if (getValueForKey(key, &overriden_pathname, &len, ␊ |
321 | ␉␉␉␉␉ &bootInfo->bootConfig))␊ |
322 | ␉{␉␉␊ |
323 | ␉␉sprintf(filename, "%s", overriden_pathname);␉␉␊ |
324 | ␉}␊ |
325 | ␉else␉␉␊ |
326 | ␉␉sprintf(filename, "%s.aml", key);␊ |
327 | ␊ |
328 | ␉␊ |
329 | ␉sprintf(dirspec, "/%s", filename); // start searching root␊ |
330 | ␉␊ |
331 | ␉fd=open (dirspec);␊ |
332 | ␉␊ |
333 | ␉if (fd<0)␊ |
334 | ␉{␉␊ |
335 | ␉␉// Check Extra on booting partition␊ |
336 | ␉␉sprintf(dirspec,"/Extra/%s",filename);␊ |
337 | ␉␉fd=open (dirspec);␊ |
338 | ␉␉if (fd<0)␊ |
339 | ␉␉{␉// Fall back to booter partition␊ |
340 | ␉␉␉sprintf(dirspec,"bt(0,0)/Extra/%s",filename);␊ |
341 | ␉␉␉fd=open (dirspec);␊ |
342 | ␉␉␉if (fd<0)␊ |
343 | ␉␉␉{␉␉␉␉␊ |
344 | ␉␉␉␉DBG("ACPI Table not found: %s\n", key);␊ |
345 | ␉␉␉␉return NULL;␊ |
346 | ␉␉␉}␊ |
347 | ␉␉␉␊ |
348 | ␉␉}␊ |
349 | ␉␉␊ |
350 | ␉}␉␉␊ |
351 | ␉␊ |
352 | ␉void *tableAddr=(void*)AllocateKernelMemory(file_size (fd));␊ |
353 | ␉if (tableAddr)␊ |
354 | ␉{␊ |
355 | ␉␉if (read (fd, tableAddr, file_size (fd))!=file_size (fd))␊ |
356 | ␉␉{␊ |
357 | ␉␉␉printf("Couldn't read table %s\n",key);␊ |
358 | ␉␉␉free (tableAddr);␊ |
359 | ␉␉␉close (fd);␊ |
360 | ␉␉␉return NULL;␊ |
361 | ␉␉}␊ |
362 | ␉␉verbose("Valid ACPI Table found: %s\n", key);␊ |
363 | ␉␉//DBG("Table %s read and stored at: %x\n", key, tableAddr);␊ |
364 | ␉␉close (fd);␊ |
365 | ␉␉return tableAddr;␊ |
366 | ␉}␊ |
367 | ␉␊ |
368 | ␉printf("Couldn't allocate memory for table %s\n", key);␊ |
369 | ␉close (fd);␊ |
370 | ␉␊ |
371 | ␉return NULL;␊ |
372 | }␊ |
373 | ␊ |
374 | uint8_t␉acpi_cpu_count = 0;␊ |
375 | char* acpi_cpu_name[32];␊ |
376 | ␊ |
377 | void get_acpi_cpu_names(unsigned char* dsdt, uint32_t length)␊ |
378 | {␊ |
379 | ␉uint32_t i;␊ |
380 | ␉␊ |
381 | ␉for (i=0; i<length-7; i++) ␊ |
382 | ␉{␊ |
383 | ␉␉if (dsdt[i] == 0x5B && dsdt[i+1] == 0x83) // ProcessorOP␊ |
384 | ␉␉{␊ |
385 | ␉␉␉uint32_t offset = i + 3 + (dsdt[i+2] >> 6);␊ |
386 | ␉␉␉␊ |
387 | ␉␉␉bool add_name = true;␊ |
388 | ␊ |
389 | ␉␉␉uint8_t j;␊ |
390 | ␉␉␉␊ |
391 | ␉␉␉for (j=0; j<4; j++) ␊ |
392 | ␉␉␉{␊ |
393 | ␉␉␉␉char c = dsdt[offset+j];␊ |
394 | ␉␉␉␉␊ |
395 | ␉␉␉␉if (!aml_isvalidchar(c)) ␊ |
396 | ␉␉␉␉{␊ |
397 | ␉␉␉␉␉add_name = false;␊ |
398 | ␉␉␉␉␉verbose("Invalid character found in ProcessorOP 0x%x!\n", c);␊ |
399 | ␉␉␉␉␉break;␊ |
400 | ␉␉␉␉}␊ |
401 | ␉␉␉}␊ |
402 | ␉␉␉␊ |
403 | ␉␉␉if (add_name) ␊ |
404 | ␉␉␉{␊ |
405 | ␉␉␉␉acpi_cpu_name[acpi_cpu_count] = malloc(4);␊ |
406 | ␉␉␉␉memcpy(acpi_cpu_name[acpi_cpu_count], dsdt+offset, 4);␊ |
407 | ␉␉␉␉i = offset + 5;␊ |
408 | ␉␉␉␉␊ |
409 | ␉␉␉␉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]);␊ |
410 | ␉␉␉␉␊ |
411 | ␉␉␉␉if (++acpi_cpu_count == 32) return;␊ |
412 | ␉␉␉}␊ |
413 | ␉␉}␊ |
414 | ␉}␊ |
415 | }␊ |
416 | ␊ |
417 | ␊ |
418 | struct acpi_2_ssdt *generate_cst_ssdt(struct acpi_2_fadt* fadt)␊ |
419 | {␉␊ |
420 | ␉char ssdt_header[] =␊ |
421 | ␉{␊ |
422 | ␉␉0x53, 0x53, 0x44, 0x54, 0xE7, 0x00, 0x00, 0x00, /* SSDT.... */␊ |
423 | ␉␉0x01, 0x17, 0x50, 0x6D, 0x52, 0x65, 0x66, 0x41, /* ..PmRefA */␊ |
424 | ␉␉0x43, 0x70, 0x75, 0x43, 0x73, 0x74, 0x00, 0x00, /* CpuCst.. */␊ |
425 | ␉␉0x00, 0x10, 0x00, 0x00, 0x49, 0x4E, 0x54, 0x4C, /* ....INTL */␊ |
426 | ␉␉0x31, 0x03, 0x10, 0x20 ␉␉␉␉␉␉␉/* 1.._␉␉*/␊ |
427 | ␉};␊ |
428 | ␉␊ |
429 | ␉char cstate_resource_template[] = ␊ |
430 | ␉{␊ |
431 | ␉␉0x11, 0x14, 0x0A, 0x11, 0x82, 0x0C, 0x00, 0x7F, ␊ |
432 | ␉␉0x01, 0x02, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, ␊ |
433 | ␉␉0x00, 0x00, 0x00, 0x79, 0x00␊ |
434 | ␉};␊ |
435 | ␉␊ |
436 | ␉if (Platform->CPU.Vendor != 0x756E6547) {␊ |
437 | ␉␉verbose ("Not an Intel platform: C-States will not be generated !!!\n");␊ |
438 | ␉␉return NULL;␊ |
439 | ␉}␊ |
440 | ␉␊ |
441 | ␉if (fadt == NULL) {␊ |
442 | ␉␉verbose ("FACP not exists: C-States will not be generated !!!\n");␊ |
443 | ␉␉return NULL;␊ |
444 | ␉}␊ |
445 | ␊ |
446 | ␉struct acpi_2_dsdt* dsdt = (void*)fadt->DSDT;␊ |
447 | ␉␊ |
448 | ␉if (dsdt == NULL) {␊ |
449 | ␉␉verbose ("DSDT not found: C-States will not be generated !!!\n");␊ |
450 | ␉␉return NULL;␊ |
451 | ␉}␊ |
452 | ␉␊ |
453 | ␉if (acpi_cpu_count == 0) ␊ |
454 | ␉␉get_acpi_cpu_names((void*)dsdt, dsdt->Length);␊ |
455 | ␉␊ |
456 | ␉if (acpi_cpu_count > 0) ␊ |
457 | ␉{␊ |
458 | ␉␉bool c2_enabled = fadt->C2_Latency < 100;␊ |
459 | ␉␉bool c3_enabled = fadt->C3_Latency < 1000;␊ |
460 | ␉␉bool c4_enabled = false;␊ |
461 | ␉␉␊ |
462 | ␉␉getBoolForKey(kEnableC4State, &c4_enabled, &bootInfo->bootConfig);␊ |
463 | ␊ |
464 | ␉␉unsigned char cstates_count = 1 + (c2_enabled ? 1 : 0) + ((c3_enabled || c4_enabled) ? 1 : 0);␊ |
465 | ␉␉char *Lat = NULL, *Pw = NULL, *tmpstr =NULL;␊ |
466 | ␉␉int base = 16;␊ |
467 | ␉␉TagPtr personality = XMLCastDict(XMLGetProperty(bootInfo->bootConfig.dictionary, (const char*)"C-States"));␊ |
468 | ␉␉␊ |
469 | ␉␉if ((tmpstr = XMLCastString(XMLGetProperty(personality, (const char*)"Base")))) {␊ |
470 | ␉␉␉␊ |
471 | ␉␉␉int mybase = strtol(tmpstr, NULL, 10);␉␊ |
472 | ␉␉␉␊ |
473 | ␉␉␉if (mybase == 8 || mybase == 10 || mybase == 16 ) ␊ |
474 | ␉␉␉␉base = mybase;␉␉␉␉␉␉␉␉␉␊ |
475 | ␉␉}␊ |
476 | ␉␉␊ |
477 | ␉␉struct aml_chunk* root = aml_create_node(NULL);␊ |
478 | aml_add_buffer(root, ssdt_header, sizeof(ssdt_header)); // SSDT header␊ |
479 | struct aml_chunk* scop = aml_add_scope(root, "\\_PR_");␊ |
480 | struct aml_chunk* name = aml_add_name(scop, "CST_");␊ |
481 | struct aml_chunk* pack = aml_add_package(name);␊ |
482 | aml_add_byte(pack, cstates_count);␊ |
483 | ␉␉␊ |
484 | struct aml_chunk* tmpl = aml_add_package(pack);␊ |
485 | TagPtr match_Status = XMLGetProperty(personality, (const char*)"C1");␊ |
486 | if (match_Status) {␉␊ |
487 | Pw = XMLCastString(XMLGetProperty(match_Status, (const char*)"Power"));␊ |
488 | Lat = XMLCastString(XMLGetProperty(match_Status, (const char*)"Latency"));␊ |
489 | }␊ |
490 | cstate_resource_template[11] = 0x00; // C1␊ |
491 | aml_add_buffer(tmpl, cstate_resource_template, sizeof(cstate_resource_template));␊ |
492 | aml_add_byte(tmpl, 0x01); // C1␊ |
493 | aml_add_byte(tmpl, (unsigned char)resolve_cst(0x01, Lat, base)); // Latency␊ |
494 | aml_add_word(tmpl, resolve_cst(0x03e8, Pw, base)); // Power␊ |
495 | ␉␉// C2␊ |
496 | ␉␉if (c2_enabled) ␊ |
497 | ␉␉{␊ |
498 | ␉␉␉tmpl = aml_add_package(pack);␊ |
499 | ␉␉␉Lat = NULL; ␊ |
500 | ␉␉␉Pw = NULL;␊ |
501 | ␉␉␉match_Status = XMLGetProperty(personality, (const char*)"C2");␊ |
502 | ␉␉␉if (match_Status) {␉␊ |
503 | ␉␉␉␉Pw = XMLCastString(XMLGetProperty(match_Status, (const char*)"Power"));␊ |
504 | ␉␉␉␉Lat = XMLCastString(XMLGetProperty(match_Status, (const char*)"Latency"));␊ |
505 | ␉␉␉}␊ |
506 | ␉␉␉␊ |
507 | ␉␉␉cstate_resource_template[11] = 0x10; // C2␊ |
508 | ␉␉␉aml_add_buffer(tmpl, cstate_resource_template, sizeof(cstate_resource_template));␊ |
509 | ␉␉␉aml_add_byte(tmpl, 0x02); // C2␉␉␉␉␊ |
510 | ␉␉␉aml_add_word(tmpl, resolve_cst(fadt->C2_Latency, Lat, base)); // Latency␊ |
511 | ␉␉␉aml_add_word(tmpl, resolve_cst(0x01f4, Pw, base)); // Power␊ |
512 | ␉␉}␊ |
513 | ␉␉␊ |
514 | ␉␉// C4␊ |
515 | ␉␉if (c4_enabled) ␊ |
516 | ␉␉{␊ |
517 | ␉␉␉tmpl = aml_add_package(pack);␊ |
518 | ␉␉␉Lat = NULL; ␊ |
519 | ␉␉␉Pw = NULL;␊ |
520 | ␉␉␉match_Status = XMLGetProperty(personality, (const char*)"C4"); ␊ |
521 | ␉␉␉if (match_Status) {␉␊ |
522 | ␉␉␉␉Pw = XMLCastString(XMLGetProperty(match_Status, (const char*)"Power"));␊ |
523 | ␉␉␉␉Lat = XMLCastString(XMLGetProperty(match_Status, (const char*)"Latency"));␊ |
524 | ␉␉␉}␊ |
525 | ␉␉␉cstate_resource_template[11] = 0x30; // C4␊ |
526 | ␉␉␉aml_add_buffer(tmpl, cstate_resource_template, sizeof(cstate_resource_template));␊ |
527 | ␉␉␉aml_add_byte(tmpl, 0x04); // C4␉␊ |
528 | ␉␉␉aml_add_word(tmpl, resolve_cst(fadt->C3_Latency / 2, Lat, base)); // TODO: right latency for C4␊ |
529 | ␉␉␉aml_add_word(tmpl, resolve_cst(0xfa, Pw, base)); // Power␊ |
530 | ␉␉␉␊ |
531 | ␉␉}␉␉␊ |
532 | ␉␉// C3␊ |
533 | ␉␉else if (c3_enabled) ␊ |
534 | ␉␉{␊ |
535 | ␉␉␉tmpl = aml_add_package(pack);␊ |
536 | ␉␉␉Lat = NULL; ␊ |
537 | ␉␉␉Pw = NULL;␊ |
538 | ␉␉␉match_Status = XMLGetProperty(personality, (const char*)"C3"); ␊ |
539 | ␉␉␉if (match_Status) {␉␊ |
540 | ␉␉␉␉Pw = XMLCastString(XMLGetProperty(match_Status, (const char*)"Power"));␊ |
541 | ␉␉␉␉Lat = XMLCastString(XMLGetProperty(match_Status, (const char*)"Latency"));␊ |
542 | ␉␉␉}␊ |
543 | ␉␉␉cstate_resource_template[11] = 0x20; // C3␊ |
544 | ␉␉␉aml_add_buffer(tmpl, cstate_resource_template, sizeof(cstate_resource_template));␊ |
545 | ␉␉␉aml_add_byte(tmpl, 0x03); // C3␉␉␉␉␊ |
546 | ␉␉␉aml_add_word(tmpl, resolve_cst(fadt->C3_Latency , Lat, base)); ␊ |
547 | ␉␉␉aml_add_word(tmpl, resolve_cst(0x015e, Pw, base)); // Power␊ |
548 | ␉␉␉␊ |
549 | ␉␉}␊ |
550 | ␉␉␊ |
551 | ␊ |
552 | // Aliaces␊ |
553 | int i;␊ |
554 | for (i = 0; i < acpi_cpu_count; i++) ␊ |
555 | {␊ |
556 | char name[9];␊ |
557 | 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]);␊ |
558 | ␊ |
559 | scop = aml_add_scope(root, name);␊ |
560 | aml_add_alias(scop, "CST_", "_CST");␊ |
561 | }␊ |
562 | ␉␉␊ |
563 | ␉␉aml_calculate_size(root);␊ |
564 | ␉␉␊ |
565 | ␉␉struct acpi_2_ssdt *ssdt = (struct acpi_2_ssdt *)AllocateKernelMemory(root->Size);␊ |
566 | ␊ |
567 | ␉␉aml_write_node(root, (void*)ssdt, 0);␊ |
568 | ␉␉␊ |
569 | ␉␉ssdt->Length = root->Size; ␊ |
570 | ␉␉␊ |
571 | ␉␉setchecksum((struct acpi_common_header *)ssdt);␊ |
572 | ␊ |
573 | ␉␉aml_destroy_node(root);␉␉␊ |
574 | ␊ |
575 | ␉␉verbose ("SSDT with CPU C-States generated successfully\n");␊ |
576 | ␉␉␊ |
577 | ␉␉return ssdt;␊ |
578 | ␉}␊ |
579 | ␉else ␊ |
580 | ␉{␊ |
581 | ␉␉verbose ("ACPI CPUs not found: C-States not generated !!!\n");␊ |
582 | ␉}␊ |
583 | ␊ |
584 | ␉return NULL;␊ |
585 | }␊ |
586 | ␊ |
587 | struct acpi_2_ssdt *generate_pss_ssdt(struct acpi_2_dsdt* dsdt)␊ |
588 | {␉␉␊ |
589 | ␉␊ |
590 | ␉char ssdt_header[] =␊ |
591 | ␉{␊ |
592 | ␉␉0x53, 0x53, 0x44, 0x54, 0x7E, 0x00, 0x00, 0x00, /* SSDT.... */␊ |
593 | ␉␉0x01, 0x6A, 0x50, 0x6D, 0x52, 0x65, 0x66, 0x00, /* ..PmRef. */␊ |
594 | ␉␉0x43, 0x70, 0x75, 0x50, 0x6D, 0x00, 0x00, 0x00, /* CpuPm... */␊ |
595 | ␉␉0x00, 0x30, 0x00, 0x00, 0x49, 0x4E, 0x54, 0x4C, /* .0..INTL */␊ |
596 | ␉␉0x31, 0x03, 0x10, 0x20,␉␉␉␉␉␉␉/* 1.._␉␉*/␊ |
597 | ␉};␊ |
598 | ␊ |
599 | ␉if (Platform->CPU.Vendor != 0x756E6547) {␊ |
600 | ␉␉verbose ("Not an Intel platform: P-States will not be generated !!!\n");␊ |
601 | ␉␉return NULL;␊ |
602 | ␉}␊ |
603 | ␉␊ |
604 | ␉if (!(Platform->CPU.Features & CPUID_FEATURE_MSR)) {␊ |
605 | ␉␉verbose ("Unsupported CPU: P-States will not be generated !!!\n");␊ |
606 | ␉␉return NULL;␊ |
607 | ␉}␊ |
608 | ␉␊ |
609 | ␉if (acpi_cpu_count == 0) ␊ |
610 | ␉␉get_acpi_cpu_names((void*)dsdt, dsdt->Length);␊ |
611 | ␉␊ |
612 | ␉if (acpi_cpu_count > 0) ␊ |
613 | ␉{␊ |
614 | ␉␉struct p_state initial, maximum, minimum, p_states[32];␊ |
615 | ␉␉uint8_t p_states_count = 0;␉␉␊ |
616 | ␉␉␊ |
617 | ␉␉// Retrieving P-States, ported from code by superhai (c)␊ |
618 | ␉␉switch (Platform->CPU.Family) {␊ |
619 | ␉␉␉case 0x06: ␊ |
620 | ␉␉␉{␊ |
621 | ␉␉␉␉switch (Platform->CPU.Model) ␊ |
622 | ␉␉␉␉{␊ |
623 | ␉␉␉␉␉case CPUID_MODEL_DOTHAN: // ?␊ |
624 | ␉␉␉␉␉case CPUID_MODEL_YONAH: // Yonah␊ |
625 | ␉␉␉␉␉case CPUID_MODEL_MEROM: // Merom␊ |
626 | ␉␉␉␉␉case CPUID_MODEL_PENRYN: // Penryn␊ |
627 | ␉␉␉␉␉case CPUID_MODEL_ATOM: // Intel Atom (45nm)␊ |
628 | ␉␉␉␉␉{␊ |
629 | ␉␉␉␉␉␉bool cpu_dynamic_fsb = false;␊ |
630 | ␉␉␉␉␉␉␊ |
631 | ␉␉␉␉␉␉if (rdmsr64(MSR_IA32_EXT_CONFIG) & (1 << 27)) ␊ |
632 | ␉␉␉␉␉␉{␊ |
633 | ␉␉␉␉␉␉␉wrmsr64(MSR_IA32_EXT_CONFIG, (rdmsr64(MSR_IA32_EXT_CONFIG) | (1 << 28))); ␊ |
634 | ␉␉␉␉␉␉␉delay(1);␊ |
635 | ␉␉␉␉␉␉␉cpu_dynamic_fsb = rdmsr64(MSR_IA32_EXT_CONFIG) & (1 << 28);␊ |
636 | ␉␉␉␉␉␉}␊ |
637 | ␉␉␉␉␉␉␊ |
638 | ␉␉␉␉␉␉bool cpu_noninteger_bus_ratio = (rdmsr64(MSR_IA32_PERF_STATUS) & (1ULL << 46));␊ |
639 | ␉␉␉␉␉␉␊ |
640 | ␉␉␉␉␉␉initial.Control = rdmsr64(MSR_IA32_PERF_STATUS);␊ |
641 | ␉␉␉␉␉␉␊ |
642 | ␉␉␉␉␉␉maximum.Control = ((rdmsr64(MSR_IA32_PERF_STATUS) >> 32) & 0x1F3F) | (0x4000 * cpu_noninteger_bus_ratio);␊ |
643 | ␉␉␉␉␉␉maximum.CID = ((maximum.FID & 0x1F) << 1) | cpu_noninteger_bus_ratio;␊ |
644 | ␉␉␉␉␉␉␊ |
645 | ␉␉␉␉␉␉minimum.FID = ((rdmsr64(MSR_IA32_PERF_STATUS) >> 24) & 0x1F) | (0x80 * cpu_dynamic_fsb);␊ |
646 | ␉␉␉␉␉␉minimum.VID = ((rdmsr64(MSR_IA32_PERF_STATUS) >> 48) & 0x3F);␊ |
647 | ␉␉␉␉␉␉␊ |
648 | ␉␉␉␉␉␉if (minimum.FID == 0) ␊ |
649 | ␉␉␉␉␉␉{␊ |
650 | ␉␉␉␉␉␉␉uint64_t msr;␊ |
651 | ␉␉␉␉␉␉␉uint8_t i;␊ |
652 | ␉␉␉␉␉␉␉// Probe for lowest fid␊ |
653 | ␉␉␉␉␉␉␉for (i = maximum.FID; i >= 0x6; i--) ␊ |
654 | ␉␉␉␉␉␉␉{␊ |
655 | ␉␉␉␉␉␉␉␉msr = rdmsr64(MSR_IA32_PERF_CONTROL);␊ |
656 | ␉␉␉␉␉␉␉␉wrmsr64(MSR_IA32_PERF_CONTROL, (msr & 0xFFFFFFFFFFFF0000ULL) | (i << 8) | minimum.VID);␊ |
657 | ␉␉␉␉␉␉␉␉intel_waitforsts();␊ |
658 | ␉␉␉␉␉␉␉␉minimum.FID = (rdmsr64(MSR_IA32_PERF_STATUS) >> 8) & 0x1F; ␊ |
659 | ␉␉␉␉␉␉␉␉delay(1);␊ |
660 | ␉␉␉␉␉␉␉}␊ |
661 | ␉␉␉␉␉␉␉␊ |
662 | ␉␉␉␉␉␉␉msr = rdmsr64(MSR_IA32_PERF_CONTROL);␊ |
663 | ␉␉␉␉␉␉␉wrmsr64(MSR_IA32_PERF_CONTROL, (msr & 0xFFFFFFFFFFFF0000ULL) | (maximum.FID << 8) | maximum.VID);␊ |
664 | ␉␉␉␉␉␉␉intel_waitforsts();␊ |
665 | ␉␉␉␉␉␉}␊ |
666 | ␉␉␉␉␉␉␊ |
667 | ␉␉␉␉␉␉if (minimum.VID == maximum.VID) ␊ |
668 | ␉␉␉␉␉␉{␉␊ |
669 | ␉␉␉␉␉␉␉uint64_t msr;␊ |
670 | ␉␉␉␉␉␉␉uint8_t i;␊ |
671 | ␉␉␉␉␉␉␉// Probe for lowest vid␊ |
672 | ␉␉␉␉␉␉␉for (i = maximum.VID; i > 0xA; i--) ␊ |
673 | ␉␉␉␉␉␉␉{␊ |
674 | ␉␉␉␉␉␉␉␉msr = rdmsr64(MSR_IA32_PERF_CONTROL);␊ |
675 | ␉␉␉␉␉␉␉␉wrmsr64(MSR_IA32_PERF_CONTROL, (msr & 0xFFFFFFFFFFFF0000ULL) | (minimum.FID << 8) | i);␊ |
676 | ␉␉␉␉␉␉␉␉intel_waitforsts();␊ |
677 | ␉␉␉␉␉␉␉␉minimum.VID = rdmsr64(MSR_IA32_PERF_STATUS) & 0x3F; ␊ |
678 | ␉␉␉␉␉␉␉␉delay(1);␊ |
679 | ␉␉␉␉␉␉␉}␊ |
680 | ␉␉␉␉␉␉␉␊ |
681 | ␉␉␉␉␉␉␉msr = rdmsr64(MSR_IA32_PERF_CONTROL);␊ |
682 | ␉␉␉␉␉␉␉wrmsr64(MSR_IA32_PERF_CONTROL, (msr & 0xFFFFFFFFFFFF0000ULL) | (maximum.FID << 8) | maximum.VID);␊ |
683 | ␉␉␉␉␉␉␉intel_waitforsts();␊ |
684 | ␉␉␉␉␉␉}␊ |
685 | ␉␉␉␉␉␉␊ |
686 | ␉␉␉␉␉␉minimum.CID = ((minimum.FID & 0x1F) << 1) >> cpu_dynamic_fsb;␊ |
687 | ␉␉␉␉␉␉␊ |
688 | ␉␉␉␉␉␉// Sanity check␊ |
689 | ␉␉␉␉␉␉if (maximum.CID < minimum.CID) ␊ |
690 | ␉␉␉␉␉␉{␊ |
691 | ␉␉␉␉␉␉␉DBG("Insane FID values!");␊ |
692 | ␉␉␉␉␉␉␉p_states_count = 0;␊ |
693 | ␉␉␉␉␉␉}␊ |
694 | ␉␉␉␉␉␉else␊ |
695 | ␉␉␉␉␉␉{␊ |
696 | ␉␉␉␉␉␉␉// Finalize P-States␊ |
697 | ␉␉␉␉␉␉␉// Find how many P-States machine supports␊ |
698 | ␉␉␉␉␉␉␉p_states_count = maximum.CID - minimum.CID + 1;␊ |
699 | ␉␉␉␉␉␉␉␊ |
700 | ␉␉␉␉␉␉␉if (p_states_count > 32) ␊ |
701 | ␉␉␉␉␉␉␉␉p_states_count = 32;␊ |
702 | ␉␉␉␉␉␉␉␊ |
703 | ␉␉␉␉␉␉␉uint8_t vidstep;␊ |
704 | ␉␉␉␉␉␉␉uint8_t i = 0, u, invalid = 0;␊ |
705 | ␉␉␉␉␉␉␉␊ |
706 | ␉␉␉␉␉␉␉vidstep = ((maximum.VID << 2) - (minimum.VID << 2)) / (p_states_count - 1);␊ |
707 | ␉␉␉␉␉␉␉␊ |
708 | ␉␉␉␉␉␉␉for (u = 0; u < p_states_count; u++) ␊ |
709 | ␉␉␉␉␉␉␉{␊ |
710 | ␉␉␉␉␉␉␉␉i = u - invalid;␊ |
711 | ␉␉␉␉␉␉␉␉␊ |
712 | ␉␉␉␉␉␉␉␉p_states[i].CID = maximum.CID - u;␊ |
713 | ␉␉␉␉␉␉␉␉p_states[i].FID = (p_states[i].CID >> 1);␊ |
714 | ␉␉␉␉␉␉␉␉␊ |
715 | ␉␉␉␉␉␉␉␉if (p_states[i].FID < 0x6) ␊ |
716 | ␉␉␉␉␉␉␉␉{␊ |
717 | ␉␉␉␉␉␉␉␉␉if (cpu_dynamic_fsb) ␊ |
718 | ␉␉␉␉␉␉␉␉␉␉p_states[i].FID = (p_states[i].FID << 1) | 0x80;␊ |
719 | ␉␉␉␉␉␉␉␉} ␊ |
720 | ␉␉␉␉␉␉␉␉else if (cpu_noninteger_bus_ratio) ␊ |
721 | ␉␉␉␉␉␉␉␉{␊ |
722 | ␉␉␉␉␉␉␉␉␉p_states[i].FID = p_states[i].FID | (0x40 * (p_states[i].CID & 0x1));␊ |
723 | ␉␉␉␉␉␉␉␉}␊ |
724 | ␉␉␉␉␉␉␉␉␊ |
725 | ␉␉␉␉␉␉␉␉if (i && p_states[i].FID == p_states[i-1].FID)␊ |
726 | ␉␉␉␉␉␉␉␉␉invalid++;␊ |
727 | ␉␉␉␉␉␉␉␉␊ |
728 | ␉␉␉␉␉␉␉␉p_states[i].VID = ((maximum.VID << 2) - (vidstep * u)) >> 2;␊ |
729 | ␉␉␉␉␉␉␉␉␊ |
730 | ␉␉␉␉␉␉␉␉uint32_t multiplier = p_states[i].FID & 0x1f;␉␉// = 0x08␊ |
731 | ␉␉␉␉␉␉␉␉bool half = p_states[i].FID & 0x40;␉␉␉␉␉// = 0x01␊ |
732 | ␉␉␉␉␉␉␉␉bool dfsb = p_states[i].FID & 0x80;␉␉␉␉␉// = 0x00␊ |
733 | ␉␉␉␉␉␉␉␉uint32_t fsb = Platform->CPU.FSBFrequency / 1000000; // = 400␊ |
734 | ␉␉␉␉␉␉␉␉uint32_t halffsb = (fsb + 1) >> 1;␉␉␉␉␉// = 200␊ |
735 | ␉␉␉␉␉␉␉␉uint32_t frequency = (multiplier * fsb);␉␉␉// = 3200␊ |
736 | ␉␉␉␉␉␉␉␉␊ |
737 | ␉␉␉␉␉␉␉␉p_states[i].Frequency = (frequency + (half * halffsb)) >> dfsb;␉// = 3200 + 200 = 3400␊ |
738 | ␉␉␉␉␉␉␉}␊ |
739 | ␉␉␉␉␉␉␉␊ |
740 | ␉␉␉␉␉␉␉p_states_count -= invalid;␊ |
741 | ␉␉␉␉␉␉}␊ |
742 | ␉␉␉␉␉␉break;␊ |
743 | ␉␉␉␉␉} ␊ |
744 | ␉␉␉␉␉case CPUID_MODEL_FIELDS:␊ |
745 | ␉␉␉␉␉case CPUID_MODEL_DALES:␊ |
746 | ␉␉␉␉␉case CPUID_MODEL_DALES_32NM:␊ |
747 | ␉␉␉␉␉case CPUID_MODEL_NEHALEM: ␊ |
748 | ␉␉␉␉␉case CPUID_MODEL_NEHALEM_EX:␊ |
749 | ␉␉␉␉␉case CPUID_MODEL_WESTMERE:␊ |
750 | ␉␉␉␉␉case CPUID_MODEL_WESTMERE_EX:␊ |
751 | ␉␉␉␉␉case CPUID_MODEL_SANDYBRIDGE:␊ |
752 | case CPUID_MODEL_JAKETOWN:␊ |
753 | ␉␉␉␉␉{␉␉␊ |
754 | ␉␉␉␉␉␉maximum.Control = rdmsr64(MSR_IA32_PERF_STATUS) & 0xff; // Seems it always contains maximum multiplier value (with turbo, that's we need)...␊ |
755 | ␉␉␉␉␉␉minimum.Control = (rdmsr64(MSR_PLATFORM_INFO) >> 40) & 0xff;␊ |
756 | ␉␉␉␉␉␉␊ |
757 | ␉␉␉␉␉␉verbose("P-States: min 0x%x, max 0x%x\n", minimum.Control, maximum.Control);␊ |
758 | ␉␉␉␉␉␉␊ |
759 | ␉␉␉␉␉␉// Sanity check␊ |
760 | ␉␉␉␉␉␉if (maximum.Control < minimum.Control) ␊ |
761 | ␉␉␉␉␉␉{␊ |
762 | ␉␉␉␉␉␉␉DBG("Insane control values!");␊ |
763 | ␉␉␉␉␉␉␉p_states_count = 0;␊ |
764 | ␉␉␉␉␉␉}␊ |
765 | ␉␉␉␉␉␉else␊ |
766 | ␉␉␉␉␉␉{␊ |
767 | ␉␉␉␉␉␉␉uint8_t i;␊ |
768 | ␉␉␉␉␉␉␉p_states_count = 0;␊ |
769 | ␉␉␉␉␉␉␉␊ |
770 | ␉␉␉␉␉␉␉for (i = maximum.Control; i >= minimum.Control; i--) ␊ |
771 | ␉␉␉␉␉␉␉{␊ |
772 | ␉␉␉␉␉␉␉␉p_states[p_states_count].Control = i;␊ |
773 | ␉␉␉␉␉␉␉␉p_states[p_states_count].CID = p_states[p_states_count].Control << 1;␊ |
774 | ␉␉␉␉␉␉␉␉p_states[p_states_count].Frequency = (Platform->CPU.FSBFrequency / 1000000) * i;␊ |
775 | ␉␉␉␉␉␉␉␉p_states_count++;␊ |
776 | ␉␉␉␉␉␉␉}␊ |
777 | ␉␉␉␉␉␉}␊ |
778 | ␉␉␉␉␉␉␊ |
779 | ␉␉␉␉␉␉break;␊ |
780 | ␉␉␉␉␉}␊ |
781 | ␉␉␉␉␉default:␊ |
782 | ␉␉␉␉␉␉verbose ("Unsupported CPU: P-States not generated !!!\n");␊ |
783 | ␉␉␉␉␉␉break;␊ |
784 | ␉␉␉␉}␊ |
785 | ␉␉␉}␊ |
786 | ␉␉␉default:␊ |
787 | ␉␉␉␉break;␊ |
788 | ␉␉}␊ |
789 | ␉␉␊ |
790 | ␉␉// Generating SSDT␊ |
791 | ␉␉if (p_states_count) ␊ |
792 | ␉␉{␉␊ |
793 | ␉␉␉int i;␊ |
794 | ␉␉␉␊ |
795 | ␉␉␉struct aml_chunk* root = aml_create_node(NULL);␊ |
796 | aml_add_buffer(root, ssdt_header, sizeof(ssdt_header)); // SSDT header␊ |
797 | struct aml_chunk* scop = aml_add_scope(root, "\\_PR_");␊ |
798 | struct aml_chunk* name = aml_add_name(scop, "PSS_");␊ |
799 | struct aml_chunk* pack = aml_add_package(name);␊ |
800 | ␉␉␉␊ |
801 | uint8_t minPSratio = (p_states[p_states_count-1].Frequency / (Platform->CPU.FSBFrequency / 10000000 ));␊ |
802 | uint8_t maxPSratio = (p_states[0].Frequency / (Platform->CPU.FSBFrequency / 10000000 ));␊ |
803 | ␊ |
804 | uint8_t cpu_div = Platform->CPU.CurrDiv;␊ |
805 | uint8_t cpu_ratio = 0;␊ |
806 | ␉␉␉␊ |
807 | if (cpu_div) ␉␉␉␉␉␉␉␉␊ |
808 | cpu_ratio = (Platform->CPU.CurrCoef * 10) + 5;␉␉␉␉␉␉␉␉␊ |
809 | else ␉␉␉␉␉␉␉␉␊ |
810 | cpu_ratio = Platform->CPU.CurrCoef * 10;␊ |
811 | ␊ |
812 | ␉␉␉␊ |
813 | int user_max_ratio = 0;␊ |
814 | getIntForKey(kMaxRatio, &user_max_ratio, &bootInfo->bootConfig);␊ |
815 | if (user_max_ratio >= minPSratio && maxPSratio >= user_max_ratio) {␉␉␉␉␉␉␉␉␉␊ |
816 | ␉␉␉␉␊ |
817 | uint8_t maxcurrdiv = 0, maxcurrcoef = (int)(user_max_ratio / 10);␉␉␉␉␉␉␉␉␉␊ |
818 | ␉␉␉␉␊ |
819 | uint8_t maxdiv = user_max_ratio - (maxcurrcoef * 10);␊ |
820 | if (maxdiv > 0)␊ |
821 | maxcurrdiv = 1;␊ |
822 | ␉␉␉␉␊ |
823 | if (maxcurrdiv) ␉␉␉␉␉␉␉␉␉␊ |
824 | cpu_ratio = (maxcurrcoef * 10) + 5;␉␉␉␉␉␉␉␉␉␊ |
825 | else ␉␉␉␉␉␉␉␉␉␊ |
826 | cpu_ratio = maxcurrcoef * 10;␉␉␉␉␉␉␉␉␉␉␉␉␉␉␉␉␊ |
827 | }␊ |
828 | ␉␉␉␊ |
829 | int user_min_ratio = 0;␊ |
830 | getIntForKey(kMinRatio, &user_min_ratio, &bootInfo->bootConfig);␊ |
831 | if (user_min_ratio >= minPSratio && cpu_ratio >= user_min_ratio) {␊ |
832 | ␉␉␉␉␊ |
833 | uint8_t mincurrdiv = 0, mincurrcoef = (int)(user_min_ratio / 10);␉␉␉␉␉␉␉␉␉␊ |
834 | ␉␉␉␉␊ |
835 | uint8_t mindiv = user_min_ratio - (mincurrcoef * 10);␊ |
836 | ␉␉␉␉␊ |
837 | if (mindiv > 0)␊ |
838 | mincurrdiv = 1;␉␉␉␉␉␉␉␉␉␊ |
839 | ␉␉␉␉␊ |
840 | if (mincurrdiv) ␉␉␉␉␉␉␉␉␉␊ |
841 | minPSratio = (mincurrcoef * 10) + 5;␉␉␉␉␉␉␉␉␉␊ |
842 | else ␉␉␉␉␉␉␉␉␉␊ |
843 | minPSratio = mincurrcoef * 10;␉␉␉␉␉␉␉␉␉␉␉␉␉␉␉␉␉␉␊ |
844 | ␉␉␉␉␊ |
845 | }␊ |
846 | ␉␉␉␊ |
847 | if (maxPSratio >= cpu_ratio && cpu_ratio >= minPSratio)␉maxPSratio = cpu_ratio;␉␉␉␉␉␉␉␉␉␉␉␉␉␊ |
848 | ␉␉␉␊ |
849 | TagPtr personality = XMLCastDict(XMLGetProperty(bootInfo->bootConfig.dictionary, (const char*)"P-States"));␊ |
850 | char* MatchStat = 0;␊ |
851 | int dropPSS = 0, Pstatus = 0, base = 16;␉␉␉␉␉␉␉␉␊ |
852 | int expert = 0;/* Default: 0 , mean mixed mode | expert mode : 1 , mean add only p-states found in boot.plist*/␊ |
853 | char *tmpstr = XMLCastString(XMLGetProperty(personality, (const char*)"Mode"));␊ |
854 | ␊ |
855 | if (strcmp(tmpstr,"Expert") == 0) {␊ |
856 | p_states_count = (XMLTagCount(personality)) - 1 ; // - 1 = - ("Mode" tag) ␉␉␉␉␉␉␉␉␉␉␊ |
857 | expert = 1;␊ |
858 | }␊ |
859 | ␉␉␉␊ |
860 | ␊ |
861 | if ((tmpstr = XMLCastString(XMLGetProperty(personality, (const char*)"Base")))) {␊ |
862 | ␊ |
863 | if (expert) p_states_count--; // -= ("Base" tag) ␊ |
864 | ␊ |
865 | int mybase = strtol(tmpstr, NULL, 10);␉␊ |
866 | ␊ |
867 | if (mybase == 8 || mybase == 10 || mybase == 16 )␊ |
868 | base = mybase;␉␉␉␉␉␉␉␉␉␊ |
869 | }␊ |
870 | ␉␉␉␊ |
871 | for (i = 0; i < p_states_count; i++) ␊ |
872 | {␉␉␉␉␉␉␉␉␉␊ |
873 | sprintf(MatchStat, "%d",i);␊ |
874 | TagPtr match_Status = XMLGetProperty(personality, (const char*)MatchStat); ␉␉␉␉␉␉␉␉ ␊ |
875 | ␊ |
876 | char *Lat1 = NULL, *clk = NULL, *Pw = NULL, *Lat2 = NULL, *Ctrl = NULL ;␊ |
877 | ␊ |
878 | if (match_Status) {␉␉␉␉␉␉␉␉␉␉␉␉␊ |
879 | ␊ |
880 | clk = XMLCastString(XMLGetProperty(match_Status, (const char*)"CoreFreq"));␊ |
881 | Pw = XMLCastString(XMLGetProperty(match_Status, (const char*)"Power"));␊ |
882 | Lat1 = XMLCastString(XMLGetProperty(match_Status, (const char*)"Transition Latency"));␊ |
883 | Lat2 = XMLCastString(XMLGetProperty(match_Status, (const char*)"Bus Master Latency"));␊ |
884 | Ctrl = XMLCastString(XMLGetProperty(match_Status, (const char*)"Control"));␊ |
885 | ␊ |
886 | ␊ |
887 | } else if (expert) ␊ |
888 | continue;␊ |
889 | ␊ |
890 | ␊ |
891 | unsigned long Frequency = 0x00000000;␊ |
892 | ␊ |
893 | if (!expert) Frequency = p_states[i].Frequency;␊ |
894 | ␊ |
895 | if (clk) ␊ |
896 | Frequency = strtoul((const char *)clk, NULL,base);␊ |
897 | ␊ |
898 | if (!Frequency || Frequency > p_states[0].Frequency ) continue;␊ |
899 | ␊ |
900 | uint8_t curr_ratio = (Frequency / (Platform->CPU.FSBFrequency / 10000000 ));␊ |
901 | ␊ |
902 | if (curr_ratio > maxPSratio || minPSratio > curr_ratio)␊ |
903 | goto dropPstate;␊ |
904 | ␊ |
905 | struct aml_chunk* pstt = aml_add_package(pack);␉␉␉␉␉␉␉␉␉␉␉␉␉␉␉␉␉␉␉␉␉␉␉␉␉␉␉␊ |
906 | aml_add_dword(pstt, Frequency); // CoreFreq (in MHz).␉␉␉␉␉␉␉␉␉␉␉␉␉␉␉␉␉␉␊ |
907 | aml_add_dword(pstt, resolve_pss(0x00000000, Pw, base)); // Power (in milliWatts)␉␉␉␉␉␉␉␉␉␊ |
908 | aml_add_dword(pstt, resolve_pss(0x0000000A, Lat1, base)); // Transition Latency (in microseconds).␉␉␉␉␉␉␉␉␉␊ |
909 | aml_add_dword(pstt, resolve_pss(0x0000000A, Lat2, base)); // Bus Master Latency (in microseconds).␉␉␉␉␉␉␉␉␉␊ |
910 | unsigned long Control = 0x00000000;␊ |
911 | if (!expert) Control = p_states[i].Control;␉␉␉␉␉␉␉␉␉␊ |
912 | aml_add_dword(pstt, resolve_pss(Control, Ctrl, base)); // Control␉␉␉␉␉␉␉␉␉␊ |
913 | Pstatus++;␊ |
914 | aml_add_dword(pstt, Pstatus); // Status␉␉␉␉␉␉␉␉␉␊ |
915 | continue;␉␉␉␉␉␉␉␉␉␉␉␉␉␉␉␊ |
916 | dropPstate:␊ |
917 | #if DEBUG_ACPI␉␉␉␉␉␉␉␉␊ |
918 | verbose("state with cpu frequency :%d and ratio :%d will be dropped\n",p_states[i].Frequency,curr_ratio);␉␉␉␉␉␉␉␉␉␊ |
919 | #endif␊ |
920 | dropPSS++;␊ |
921 | ␊ |
922 | ␊ |
923 | }␉␉␉␊ |
924 | ␉␉␉␊ |
925 | ␉␉␉// Add aliaces␊ |
926 | ␉␉␉for (i = 0; i < acpi_cpu_count; i++) ␊ |
927 | ␉␉␉{␊ |
928 | ␉␉␉␉char name[9];␊ |
929 | ␉␉␉␉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]);␊ |
930 | ␉␉␉␉␊ |
931 | ␉␉␉␉scop = aml_add_scope(root, name);␊ |
932 | ␉␉␉␉aml_add_alias(scop, "PSS_", "_PSS");␊ |
933 | ␉␉␉}␊ |
934 | ␉␉␉␊ |
935 | ␉␉␉aml_calculate_size(root);␊ |
936 | ␉␉␉␊ |
937 | ␉␉␉struct acpi_2_ssdt *ssdt = (struct acpi_2_ssdt *)AllocateKernelMemory(root->Size);␊ |
938 | ␉␉␉␊ |
939 | ␉␉␉aml_write_node(root, (void*)ssdt, 0);␊ |
940 | ␉␉␉␊ |
941 | ␉␉␉ssdt->Length = root->Size;␊ |
942 | ␉␉␉␊ |
943 | setchecksum((struct acpi_common_header *)ssdt);␊ |
944 | ␉␉␉␊ |
945 | ␉␉␉aml_destroy_node(root);␉␉␉␊ |
946 | ␉␉␉␊ |
947 | ␉␉␉verbose ("SSDT with CPU P-States generated successfully");␊ |
948 | ␉␉␉␊ |
949 | ␉␉␉if (dropPSS)␊ |
950 | verbose(", %d P-state(s) dropped",dropPSS);␊ |
951 | ␉␉␉␊ |
952 | ␉␉␉verbose("\n");␊ |
953 | ␉␉␉␊ |
954 | ␉␉␉return ssdt;␊ |
955 | ␉␉}␊ |
956 | ␉}␊ |
957 | ␉else ␊ |
958 | ␉{␊ |
959 | ␉␉verbose("ACPI CPUs not found: P-States not generated !!!\n");␊ |
960 | ␉}␊ |
961 | ␉␊ |
962 | ␉return NULL;␊ |
963 | }␊ |
964 | ␊ |
965 | ␊ |
966 | struct acpi_2_gas FillGASStruct(uint32_t Address, uint8_t Length)␊ |
967 | {␊ |
968 | ␉struct acpi_2_gas TmpGAS;␊ |
969 | ␉␊ |
970 | ␉TmpGAS.Address_Space_ID = 1; /* I/O Address */␊ |
971 | ␉␊ |
972 | ␉if (Address == 0)␊ |
973 | ␉{␊ |
974 | ␉␉TmpGAS.Register_Bit_Width = 0;␊ |
975 | ␉} else {␊ |
976 | ␉␉TmpGAS.Register_Bit_Width = Length * 8;␊ |
977 | ␉}␊ |
978 | ␉␊ |
979 | ␉TmpGAS.Register_Bit_Offset = 0;␊ |
980 | ␉TmpGAS.Access_Size = 0; /* Not set for Legacy reasons... */␊ |
981 | ␉TmpGAS.Address = (uint64_t)Address;␊ |
982 | ␉␊ |
983 | ␉return(TmpGAS);␊ |
984 | }␊ |
985 | ␊ |
986 | struct acpi_2_fadt *␊ |
987 | patch_fadt(struct acpi_2_fadt *fadt, struct acpi_2_dsdt *new_dsdt, bool UpdateFADT)␊ |
988 | {␉␉␊ |
989 | ␉␊ |
990 | ␉struct acpi_2_fadt *fadt_mod;␊ |
991 | ␉struct acpi_2_fadt *fadt_file = (struct acpi_2_fadt *)loadACPITable(kFADT); ␊ |
992 | ␉bool fadt_rev2_needed = false;␊ |
993 | ␉bool fix_restart = false;␉␊ |
994 | ␉const char * value;␊ |
995 | ␉bool aspmOff = true;␊ |
996 | ␉bool msiOff = true;␊ |
997 | ␊ |
998 | ␉// Restart Fix␊ |
999 | ␉if (Platform->CPU.Vendor == 0x756E6547) {␉/* Intel */␊ |
1000 | ␉␉fix_restart = true;␊ |
1001 | ␉␉getBoolForKey(kRestartFix, &fix_restart, &bootInfo->bootConfig);␊ |
1002 | ␉␉␊ |
1003 | ␉} else {␊ |
1004 | ␉␉verbose ("Not an Intel platform: Restart Fix not applied !!!\n");␊ |
1005 | ␉}␊ |
1006 | ␉␊ |
1007 | ␉if (fix_restart)␊ |
1008 | ␉␉fadt_rev2_needed = true;␊ |
1009 | ␉␉␉␊ |
1010 | ␉// Allocate new fadt table␊ |
1011 | ␉if ((UpdateFADT) && (((fadt_file) && (fadt_file->Length < sizeof(struct acpi_2_fadt))) ||␊ |
1012 | ␉␉␉␉␉␉ ((!fadt_file) && (fadt->Length < sizeof(struct acpi_2_fadt))))) ␊ |
1013 | ␉{␊ |
1014 | getBoolForKey(kDisableMSI, &msiOff, &bootInfo->bootConfig) ;␊ |
1015 | getBoolForKey(kDisableASPM, &aspmOff, &bootInfo->bootConfig);␊ |
1016 | ␊ |
1017 | ␉␉if (fadt_file)␊ |
1018 | ␉␉{␊ |
1019 | ␉␉␉if (fadt_file->Length < 0xF4)␊ |
1020 | ␉␉␉{␊ |
1021 | ␉␉␉␉fadt_mod=(struct acpi_2_fadt *)AllocateKernelMemory(0xF4);␊ |
1022 | ␉␉␉␉memcpy(fadt_mod, fadt_file, fadt_file->Length);␊ |
1023 | ␉␉␉␉fadt_mod->Length = 0xF4;␊ |
1024 | ␉␉␉}␊ |
1025 | ␉␉␉else␊ |
1026 | ␉␉␉{␊ |
1027 | ␉␉␉␉␊ |
1028 | ␉␉␉␉fadt_mod=(struct acpi_2_fadt *)AllocateKernelMemory(fadt_file->Length);␊ |
1029 | ␉␉␉␉memcpy(fadt_mod, fadt_file, fadt_file->Length);␊ |
1030 | ␉␉␉}␊ |
1031 | ␉␉}␊ |
1032 | ␉␉else ␊ |
1033 | ␉␉{␊ |
1034 | ␉␉␉if (fadt->Length < 0xF4)␊ |
1035 | ␉␉␉{␊ |
1036 | ␉␉␉␉fadt_mod=(struct acpi_2_fadt *)AllocateKernelMemory(0xF4);␊ |
1037 | ␉␉␉␉memcpy(fadt_mod, fadt, fadt->Length);␊ |
1038 | ␉␉␉␉fadt_mod->Length = 0xF4;␊ |
1039 | ␉␉␉}␊ |
1040 | ␉␉␉else␊ |
1041 | ␉␉␉{␊ |
1042 | ␉␉␉␉␊ |
1043 | ␉␉␉␉fadt_mod=(struct acpi_2_fadt *)AllocateKernelMemory(fadt->Length);␉␊ |
1044 | ␉␉␉␉memcpy(fadt_mod, fadt, fadt->Length);␊ |
1045 | ␉␉␉}␉␉ ␊ |
1046 | ␉␉}␉␉␊ |
1047 | ␊ |
1048 | ␉␉fadt_mod->Revision = 0x04; // FADT rev 4␊ |
1049 | ␉␉fadt_mod->RESET_REG = FillGASStruct(0, 0);␊ |
1050 | ␉␉fadt_mod->Reset_Value = 0;␊ |
1051 | ␉␉fadt_mod->Reserved[0] = 0;␊ |
1052 | ␉␉fadt_mod->Reserved[1] = 0;␊ |
1053 | ␉␉fadt_mod->Reserved[2] = 0;␊ |
1054 | ␉␉␊ |
1055 | ␉␉␉fadt_mod->X_PM1a_EVT_BLK = FillGASStruct(fadt_mod->PM1A_Event_Block_Address, fadt_mod->PM1_Event_Block_Length);␊ |
1056 | ␉␉␉fadt_mod->X_PM1b_EVT_BLK = FillGASStruct(fadt_mod->PM1B_Event_Block_Address, fadt_mod->PM1_Event_Block_Length);␊ |
1057 | ␉␉␉fadt_mod->X_PM1a_CNT_BLK = FillGASStruct(fadt_mod->PM1A_Control_Block_Address, fadt_mod->PM1_Control_Block_Length);␊ |
1058 | ␉␉␉fadt_mod->X_PM1b_CNT_BLK = FillGASStruct(fadt_mod->PM1B_Control_Block_Address, fadt_mod->PM1_Control_Block_Length);␊ |
1059 | ␉␉␉fadt_mod->X_PM2_CNT_BLK = FillGASStruct(fadt_mod->PM2_Control_Block_Address, fadt_mod->PM2_Control_Block_Length);␊ |
1060 | ␉␉␉fadt_mod->X_PM_TMR_BLK = FillGASStruct(fadt_mod->PM_Timer_Block_Address, fadt_mod->PM_Timer_Block_Length);␊ |
1061 | ␉␉␉fadt_mod->X_GPE0_BLK = FillGASStruct(fadt_mod->GPE0_Block_Address, fadt_mod->GPE0_Block_Length);␊ |
1062 | ␉␉␉fadt_mod->X_GPE1_BLK = FillGASStruct(fadt_mod->GPE1_Block_Address, fadt_mod->GPE1_Block_Length);␊ |
1063 | ␉ ␊ |
1064 | ␉␉verbose("Converted ACPI V%d FADT to ACPI V4 FADT\n", (fadt) ? fadt->Revision : fadt->Revision);␊ |
1065 | ␉} else {␊ |
1066 | ␉␉␊ |
1067 | ␉␉if (fadt_file) {␊ |
1068 | ␉␉␉if (fadt_file->Length < 0x84 && fadt_rev2_needed)␊ |
1069 | ␉␉␉{␊ |
1070 | ␉␉␉␉fadt_mod=(struct acpi_2_fadt *)AllocateKernelMemory(0x84);␊ |
1071 | ␉␉␉␉memcpy(fadt_mod, fadt_file, fadt_file->Length);␊ |
1072 | ␉␉␉␉fadt_mod->Length = 0x84;␊ |
1073 | ␉␉␉␉fadt_mod->Revision = 0x02; // FADT rev 2 (ACPI 1.0B MS extensions)␊ |
1074 | ␉␉␉} else {␊ |
1075 | ␉␉␉␉fadt_mod=(struct acpi_2_fadt *)AllocateKernelMemory(fadt_file->Length);␊ |
1076 | ␉␉␉␉memcpy(fadt_mod, fadt_file, fadt_file->Length);␊ |
1077 | ␉␉␉}␊ |
1078 | ␊ |
1079 | ␉␉} else {␊ |
1080 | ␉␉␉if (fadt->Length < 0x84 && fadt_rev2_needed)␊ |
1081 | ␉␉␉{␊ |
1082 | ␉␉␉␉fadt_mod=(struct acpi_2_fadt *)AllocateKernelMemory(0x84);␊ |
1083 | ␉␉␉␉memcpy(fadt_mod, fadt, fadt->Length);␊ |
1084 | ␉␉␉␉fadt_mod->Length = 0x84;␊ |
1085 | ␉␉␉␉fadt_mod->Revision = 0x02; // FADT rev 2 (ACPI 1.0B MS extensions)␊ |
1086 | ␉␉␉} else {␊ |
1087 | ␉␉␉␉fadt_mod=(struct acpi_2_fadt *)AllocateKernelMemory(fadt->Length);␊ |
1088 | ␉␉␉␉memcpy(fadt_mod, fadt, fadt->Length);␊ |
1089 | ␉␉␉}␊ |
1090 | ␊ |
1091 | ␉␉} ␊ |
1092 | ␊ |
1093 | ␉}␊ |
1094 | ␊ |
1095 | ␉uint8_t Type = PMProfileError;␊ |
1096 | ␉// Determine system type / PM_Model␊ |
1097 | ␉␊ |
1098 | ␉// Fix System-type if needed (should never happen)␊ |
1099 | ␉if (Platform->Type > MaxSupportedPMProfile) ␊ |
1100 | ␉{␊ |
1101 | ␉␉if(fadt_mod->PM_Profile <= MaxSupportedPMProfile)␊ |
1102 | ␉␉␉Platform->Type = fadt_mod->PM_Profile; // get the fadt if correct␊ |
1103 | ␉␉else ␊ |
1104 | ␉␉␉Platform->Type = 1;␉␉/* Set a fixed value (Desktop) */␊ |
1105 | ␉}␊ |
1106 | ␉␊ |
1107 | ␉// If needed, set System-type from PM_Profile (if valid) else set PM_Profile with a fixed the System-type ␊ |
1108 | ␉// Give prior to the FADT pm profile, allow to also control this value with a patched FADT table␊ |
1109 | ␉if (fadt_mod->PM_Profile != Platform->Type) ␊ |
1110 | ␉{␊ |
1111 | ␉␉bool val = false; ␊ |
1112 | ␉␉getBoolForKey("PreferInternalProfileDetect", &val, &bootInfo->bootConfig); // if true Give prior to the profile resolved trought the CPU model␊ |
1113 | ␉␉␊ |
1114 | ␉␉val = Platform->CPU.isServer ;␊ |
1115 | ␉␉␊ |
1116 | ␉␉if (fadt_mod->PM_Profile <= MaxSupportedPMProfile && !val) {␊ |
1117 | ␉␉␉Platform->Type = fadt_mod->PM_Profile;␊ |
1118 | ␉␉} else {␊ |
1119 | ␉␉␉fadt_mod->PM_Profile = Platform->Type;␊ |
1120 | ␉␉}␉␉␊ |
1121 | ␉␉␊ |
1122 | ␉}␊ |
1123 | ␉␊ |
1124 | ␉// Set PM_Profile and System-type if user wanted this value to be forced␊ |
1125 | ␉if ( (value=getStringForKey("SystemType", &bootInfo->bootConfig))!=NULL) {␊ |
1126 | ␉␉if ((Type = (unsigned char) strtoul(value, NULL, 10) ) <= MaxSupportedPMProfile)␊ |
1127 | ␉␉{␊ |
1128 | ␉␉␉verbose("FADT: changing Preferred_PM_Profile from 0x%02x to 0x%02x\n", fadt->PM_Profile, Type);␊ |
1129 | ␉␉␉fadt_mod->PM_Profile = Platform->Type = Type;␊ |
1130 | ␉␉} else verbose("Error: system-type must be 0..6. Defaulting to %d !\n", Platform->Type);␊ |
1131 | ␉}␊ |
1132 | ␊ |
1133 | ␉// Patch FADT to fix restart␊ |
1134 | ␉if (fix_restart)␊ |
1135 | ␉{␉␉␊ |
1136 | fadt_mod->Flags|= 0x400;␉␉␉␉␊ |
1137 | ␉␉␊ |
1138 | ␉␉fadt_mod->RESET_REG = FillGASStruct(0x0cf9, 1);␊ |
1139 | ␉␉fadt_mod->Reset_Value = 0x06;␊ |
1140 | ␉␉verbose("FADT: Restart Fix applied !\n");␊ |
1141 | ␉}␊ |
1142 | ␉␊ |
1143 | ␉␊ |
1144 | ␉if (aspmOff) {␊ |
1145 | ␉␉fadt_mod->Boot_Flags |= 1 << 4; ␊ |
1146 | ␉} else {␊ |
1147 | ␉␉fadt_mod->Boot_Flags &= 0xFFEF; ␊ |
1148 | ␊ |
1149 | ␉}␉␉␉␊ |
1150 | ␊ |
1151 | ␉if (msiOff) {␊ |
1152 | ␉␉fadt_mod->Boot_Flags |= 1 << 3; ␊ |
1153 | ␉} else {␊ |
1154 | ␉␉fadt_mod->Boot_Flags &= 0xFFF7;␊ |
1155 | ␉}␊ |
1156 | ␉␊ |
1157 | ␉␉fadt_mod->FIRMWARE_CTRL=(uint32_t)fadt->FIRMWARE_CTRL;␊ |
1158 | ␉␉if ((uint32_t)(&(fadt_mod->X_FIRMWARE_CTRL))-(uint32_t)fadt_mod+8<=fadt_mod->Length)␊ |
1159 | ␉␉␉fadt_mod->X_FIRMWARE_CTRL=(uint32_t)fadt->FIRMWARE_CTRL;␊ |
1160 | ␊ |
1161 | ␉␉Platform->hardware_signature = ␉((struct acpi_2_facs *)fadt->FIRMWARE_CTRL)->hardware_signature;␊ |
1162 | ␊ |
1163 | ␉DBG("setting hardware_signature to %x \n",Platform->hardware_signature);␊ |
1164 | ␊ |
1165 | ␉␊ |
1166 | ␉␊ |
1167 | ␉// Patch DSDT Address if we have loaded a DSDT table␊ |
1168 | ␉if(new_dsdt)␊ |
1169 | ␉{␉␉␊ |
1170 | ␉␉␊ |
1171 | ␉␉fadt_mod->DSDT=(uint32_t)new_dsdt;␊ |
1172 | ␉␉if ((uint32_t)(&(fadt_mod->X_DSDT))-(uint32_t)fadt_mod+8<=fadt_mod->Length)␊ |
1173 | ␉␉␉fadt_mod->X_DSDT=(uint32_t)new_dsdt;␉␉␊ |
1174 | ␉␉␊ |
1175 | ␉}␊ |
1176 | ␉␊ |
1177 | ␉// Correct the checksum␉␊ |
1178 | setchecksum((struct acpi_common_header *)fadt_mod);␊ |
1179 | ␊ |
1180 | ␉return fadt_mod;␊ |
1181 | }␊ |
1182 | ␊ |
1183 | ␊ |
1184 | /* Setup ACPI */␊ |
1185 | EFI_STATUS setupAcpi(void)␊ |
1186 | {␉␊ |
1187 | ␉int version;␊ |
1188 | EFI_STATUS Status = EFI_ABORTED;␊ |
1189 | ␉void *new_dsdt=NULL, *new_hpet=NULL, *new_sbst=NULL, *new_ecdt=NULL, *new_asft=NULL, *new_dmar=NULL, *new_apic=NULL, *new_mcfg=NULL, *new_ssdts[14];␊ |
1190 | ␊ |
1191 | ␉struct acpi_2_ssdt *new_ssdt[17]; // 15 + 2 additional tables for pss & cst ␊ |
1192 | ␉struct acpi_2_fadt *fadt; // will be used in CST generator␊ |
1193 | ␉struct acpi_2_fadt *fadt_mod=NULL;␊ |
1194 | ␉bool oem_dsdt=false, oem_ssdt=false, oem_hpet=false, oem_sbst=false, oem_ecdt=false, oem_asft=false, oem_dmar=false, oem_apic=false, oem_mcfg=false;␊ |
1195 | ␉bool update_acpi=false, gen_xsdt=false;␊ |
1196 | ␉bool hpet_replaced=false, sbst_replaced=false, ecdt_replaced=false, asft_replaced=false, dmar_replaced=false, apic_replaced=false, mcfg_replaced=false;␊ |
1197 | ␉bool hpet_added=false, sbst_added=false, ecdt_added=false, asft_added=false, dmar_added=false, apic_added=false, mcfg_added=false;␊ |
1198 | ␉bool gen_csta=false, gen_psta=false, speed_step=false;␊ |
1199 | ␉␊ |
1200 | ␉bool quick_ssdt= false; ␊ |
1201 | ␉// Quick ssdt search, ␊ |
1202 | ␉// first try to find ssdt-0.aml, if the file do not exist we␊ |
1203 | ␉// stop searching here, else ssdt-0.aml is loaded and we try ␊ |
1204 | ␉// to find ssdt-1.aml, etc .........␊ |
1205 | ␉␊ |
1206 | ␉int curssdt=0, loadtotssdt=0, totssdt=0, newtotssdt=0;␊ |
1207 | ␉␊ |
1208 | ␉{␊ |
1209 | ␉␉bool tmpval;␊ |
1210 | ␉␉␊ |
1211 | ␉␉oem_dsdt=getBoolForKey(kOEMDSDT, &tmpval, &bootInfo->bootConfig)&&tmpval;␊ |
1212 | ␉␉oem_ssdt=getBoolForKey(kOEMSSDT, &tmpval, &bootInfo->bootConfig)&&tmpval;␊ |
1213 | ␉␉oem_hpet=getBoolForKey(kOEMHPET, &tmpval, &bootInfo->bootConfig)&&tmpval;␊ |
1214 | ␉␉oem_sbst=getBoolForKey(kOEMSBST, &tmpval, &bootInfo->bootConfig)&&tmpval;␊ |
1215 | ␉␉oem_ecdt=getBoolForKey(kOEMECDT, &tmpval, &bootInfo->bootConfig)&&tmpval;␊ |
1216 | ␉␉oem_asft=getBoolForKey(kOEMASFT, &tmpval, &bootInfo->bootConfig)&&tmpval;␊ |
1217 | ␉␉oem_dmar=getBoolForKey(kOEMDMAR, &tmpval, &bootInfo->bootConfig)&&tmpval;␊ |
1218 | ␉␉oem_apic=getBoolForKey(kOEMAPIC, &tmpval, &bootInfo->bootConfig)&&tmpval;␊ |
1219 | ␉␉oem_mcfg=getBoolForKey(kOEMMCFG, &tmpval, &bootInfo->bootConfig)&&tmpval;␊ |
1220 | ␊ |
1221 | ␉␉gen_csta=getBoolForKey(kGenerateCStates, &tmpval, &bootInfo->bootConfig)&&tmpval;␊ |
1222 | ␉␉gen_psta=getBoolForKey(kGeneratePStates, &tmpval, &bootInfo->bootConfig)&&tmpval;␊ |
1223 | ␊ |
1224 | ␉␉update_acpi=getBoolForKey(kUpdateACPI, &tmpval, &bootInfo->bootConfig)&&tmpval;␊ |
1225 | ␉␉␊ |
1226 | ␉␉quick_ssdt=getBoolForKey(kQSSDT, &tmpval, &bootInfo->bootConfig)&&tmpval;␊ |
1227 | ␉␉␊ |
1228 | ␉␉speed_step=getBoolForKey(kSpeedstep, &tmpval, &bootInfo->bootConfig)&&tmpval;␊ |
1229 | ␉␉␊ |
1230 | ␉} ␉␊ |
1231 | ␊ |
1232 | ␉if (speed_step) {␊ |
1233 | ␉␉gen_psta= true;␊ |
1234 | ␉␉gen_csta= true;␊ |
1235 | ␉} ␊ |
1236 | ␊ |
1237 | ␊ |
1238 | ␉// Load replacement ACPI tables␊ |
1239 | ␉if (!oem_dsdt)␊ |
1240 | ␉␉new_dsdt=loadACPITable(kDSDT);␊ |
1241 | ␉␊ |
1242 | ␉␊ |
1243 | ␉if (!oem_hpet)␊ |
1244 | ␉␉new_hpet=loadACPITable(kHPET);␊ |
1245 | ␉␊ |
1246 | ␉␊ |
1247 | ␉if (!oem_sbst)␊ |
1248 | ␉␉new_sbst=loadACPITable(kSBST);␊ |
1249 | ␉␊ |
1250 | ␉␊ |
1251 | ␉if (!oem_ecdt)␊ |
1252 | ␉␉new_ecdt=loadACPITable(kECDT);␊ |
1253 | ␉␊ |
1254 | ␉␊ |
1255 | ␉if (!oem_asft)␊ |
1256 | ␉␉new_asft=loadACPITable(kASFT);␊ |
1257 | ␉␊ |
1258 | ␉␊ |
1259 | ␉if (!oem_dmar)␊ |
1260 | ␉␉new_dmar=loadACPITable(kDMAR);␊ |
1261 | ␉␊ |
1262 | ␉␊ |
1263 | ␉if (!oem_apic)␊ |
1264 | ␉␉new_apic=loadACPITable(kAPIC);␊ |
1265 | ␉␊ |
1266 | ␉␊ |
1267 | ␉if (!oem_mcfg)␊ |
1268 | ␉␉new_mcfg=loadACPITable(kMCFG);␊ |
1269 | ␉␊ |
1270 | ␉if (!oem_ssdt)␊ |
1271 | ␉{ ␊ |
1272 | ␉␉␊ |
1273 | ␉␉for (curssdt=0;curssdt<15;curssdt++)␊ |
1274 | ␉␉{␊ |
1275 | ␉␉␉new_ssdt[curssdt]=loadSSDTTable(curssdt);␊ |
1276 | ␉␉␉␊ |
1277 | ␉␉␉if (new_ssdt[curssdt])␊ |
1278 | ␉␉␉␉loadtotssdt++;␉␉␉␊ |
1279 | ␉␉␉else if (quick_ssdt)␉␉␉␉␊ |
1280 | ␉␉␉␉break;␉␉␊ |
1281 | ␉␉␉␊ |
1282 | ␉␉}␊ |
1283 | ␊ |
1284 | ␉␉curssdt=0;␊ |
1285 | ␉␉␊ |
1286 | ␉}␊ |
1287 | ␊ |
1288 | ␉DBG("New ACPI tables Loaded in memory\n");␊ |
1289 | ␉TagPtr DropTables_p = XMLCastDict(XMLGetProperty(bootInfo->bootConfig.dictionary, (const char*)"ACPIDropTables"));␊ |
1290 | ␉// Do the same procedure for both versions of ACPI␊ |
1291 | ␉for (version=0; version<2; version++) {␊ |
1292 | ␉␉struct acpi_2_rsdp *rsdp_mod, *rsdp_conv=(struct acpi_2_rsdp *)0;␊ |
1293 | ␉␉struct acpi_2_rsdt *rsdt, *rsdt_mod;␊ |
1294 | ␉␉struct acpi_2_xsdt *xsdt_conv = (struct acpi_2_xsdt *)0;␊ |
1295 | ␉␉int rsdplength;␊ |
1296 | ␊ |
1297 | ␉␉// Find original rsdp ␊ |
1298 | struct acpi_2_rsdp *rsdp=(struct acpi_2_rsdp *)(version?biosacpi_find_rsdp(2):biosacpi_find_rsdp(0));␊ |
1299 | ␉␉␊ |
1300 | ␉␉if ((update_acpi) && (rsdp->Revision == 0))␊ |
1301 | ␉␉{␊ |
1302 | ␊ |
1303 | ␉␉␉rsdp_conv = gen_rsdp_v2_from_v1(rsdp);␊ |
1304 | ␉␉␉gen_xsdt = true;␊ |
1305 | ␉␉␉version = 1;␊ |
1306 | ␉␉␉␊ |
1307 | ␉␉␉addConfigurationTable(&gEfiAcpiTableGuid, NULL, "ACPI");␊ |
1308 | ␉␉␉␊ |
1309 | ␉␉␉verbose("Converted ACPI RSD PTR version 1 to version 3\n");␊ |
1310 | ␉␉}␊ |
1311 | ␊ |
1312 | ␉␉if (!rsdp)␊ |
1313 | ␉␉{␊ |
1314 | ␉␉␉DBG("No ACPI version %d found. Ignoring\n", version+1);␊ |
1315 | ␉␉␉if (version)␊ |
1316 | ␉␉␉␉addConfigurationTable(&gEfiAcpi20TableGuid, NULL, "ACPI_20");␊ |
1317 | ␉␉␉else␊ |
1318 | ␉␉␉␉addConfigurationTable(&gEfiAcpiTableGuid, NULL, "ACPI");␊ |
1319 | ␉␉␉continue;␊ |
1320 | ␉␉}␊ |
1321 | ␉␉rsdplength=version?rsdp->Length:20;␊ |
1322 | ␉␉␊ |
1323 | ␉␉DBG("RSDP version %d found @%x. Length=%d\n",version+1,rsdp,rsdplength);␊ |
1324 | ␉␉␊ |
1325 | ␉␉/* FIXME: no check that memory allocation succeeded ␊ |
1326 | ␉␉ * Copy and patch RSDP,RSDT, XSDT and FADT␊ |
1327 | ␉␉ * For more info see ACPI Specification pages 110 and following␊ |
1328 | ␉␉ */␊ |
1329 | ␉␉␊ |
1330 | ␉␉if (gen_xsdt)␊ |
1331 | ␉␉{␊ |
1332 | ␉␉␉rsdp_mod=rsdp_conv;␊ |
1333 | ␉␉} else {␊ |
1334 | ␉␉␉rsdp_mod=(struct acpi_2_rsdp *) AllocateKernelMemory(rsdplength);␊ |
1335 | ␉␉␉memcpy(rsdp_mod, rsdp, rsdplength);␊ |
1336 | ␉␉}␊ |
1337 | ␉␉␊ |
1338 | ␉␉rsdt=(struct acpi_2_rsdt *)(rsdp->RsdtAddress);␊ |
1339 | ␉␉␊ |
1340 | ␉␉DBG("RSDT @%x, Length %d\n",rsdt, rsdt->Length);␊ |
1341 | ␉␉␊ |
1342 | ␉␉if (rsdt && (uint32_t)rsdt !=0xffffffff && rsdt->Length<0x10000)␊ |
1343 | ␉␉{␉␉␉␊ |
1344 | ␉␉␉int dropoffset=0, i;␊ |
1345 | ␉␉␉␊ |
1346 | ␉␉␉rsdt_mod=(struct acpi_2_rsdt *)AllocateKernelMemory(rsdt->Length); ␊ |
1347 | ␉␉␉memcpy (rsdt_mod, rsdt, rsdt->Length);␊ |
1348 | ␊ |
1349 | update_rsdp_with_rsdt(rsdp_mod, rsdt_mod);␊ |
1350 | ␉␉␉␊ |
1351 | ␉␉␉int rsdt_entries_num=(rsdt_mod->Length-sizeof(struct acpi_2_rsdt))/4;␊ |
1352 | ␉␉␉uint32_t *rsdt_entries=(uint32_t *)(rsdt_mod+1);␊ |
1353 | ␉␉␉␊ |
1354 | ␉␉␉if (gen_xsdt)␊ |
1355 | ␉␉␉{␊ |
1356 | ␊ |
1357 | xsdt_conv=gen_xsdt_from_rsdt(rsdt_mod);␊ |
1358 | update_rsdp_with_xsdt(rsdp, xsdt_conv); ␊ |
1359 | ␉␉␉␉␊ |
1360 | ␉␉␉␉␊ |
1361 | ␉␉␉␉verbose("Converted RSDT table to XSDT table\n");␊ |
1362 | ␉␉␉}␊ |
1363 | ␉␉␉␊ |
1364 | ␉␉␉for (i=0;i<rsdt_entries_num;i++)␊ |
1365 | ␉␉␉{␊ |
1366 | ␉␉␉␉char *table=(char *)(rsdt_entries[i]);␊ |
1367 | ␉␉␉␉if (!table)␊ |
1368 | ␉␉␉␉␉continue;␊ |
1369 | ␉␉␉␉␊ |
1370 | ␉␉␉␉DBG("TABLE %c%c%c%c,",table[0],table[1],table[2],table[3]);␊ |
1371 | ␉␉␉␉␊ |
1372 | ␉␉␉␉rsdt_entries[i-dropoffset]=rsdt_entries[i];␊ |
1373 | ␉␉␉␉␊ |
1374 | ␉␉␉␉char table4[4];␊ |
1375 | ␉␉␉␉strlcpy(table4, table, sizeof(table4)+1);␊ |
1376 | ␉␉␉␉TagPtr match_drop = XMLGetProperty(DropTables_p, (const char*)table4);␊ |
1377 | ␉␉␉␉if ( match_drop ) {␊ |
1378 | ␉␉␉␉␉char *tmpstr = XMLCastString(match_drop);␊ |
1379 | ␉␉␉␉␉if (strcmp(tmpstr,"No") != 0) {␉␉␉␉␉␉␊ |
1380 | ␉␉␉␉␉␉dropoffset++;␊ |
1381 | ␉␉␉␉␉␉DBG("%s table dropped\n",table4);␊ |
1382 | ␉␉␉␉␉␉continue;␊ |
1383 | ␉␉␉␉␉}␊ |
1384 | ␉␉␉␉}␊ |
1385 | ␊ |
1386 | ␉␉␉␉if ((!(oem_hpet)) && tableSign(table, "HPET"))␊ |
1387 | ␉␉␉␉{␊ |
1388 | ␉␉␉␉␉DBG("HPET found\n");␊ |
1389 | ␉␉␉␉␉if (new_hpet)␊ |
1390 | ␉␉␉␉␉{␊ |
1391 | ␉␉␉␉␉␉rsdt_entries[i-dropoffset]=(uint32_t)new_hpet;␊ |
1392 | ␉␉␉␉␉␉hpet_replaced=true;␊ |
1393 | ␉␉␉␉␉}␊ |
1394 | ␉␉␉␉␉continue;␊ |
1395 | ␉␉␉␉}␊ |
1396 | ␊ |
1397 | ␉␉␉␉if ((!(oem_sbst)) && tableSign(table, "SBST"))␊ |
1398 | ␉␉␉␉{␊ |
1399 | ␉␉␉␉␉DBG("SBST found\n");␊ |
1400 | ␉␉␉␉␉if (new_sbst)␊ |
1401 | ␉␉␉␉␉{␊ |
1402 | ␉␉␉␉␉␉rsdt_entries[i-dropoffset]=(uint32_t)new_sbst;␊ |
1403 | ␉␉␉␉␉␉sbst_replaced=true;␊ |
1404 | ␉␉␉␉␉}␊ |
1405 | ␉␉␉␉␉continue;␊ |
1406 | ␉␉␉␉}␊ |
1407 | ␊ |
1408 | ␉␉␉␉if ((!(oem_ecdt)) && tableSign(table, "ECDT"))␊ |
1409 | ␉␉␉␉{␊ |
1410 | ␉␉␉␉␉DBG("ECDT found\n");␊ |
1411 | ␉␉␉␉␉␊ |
1412 | ␉␉␉␉␉if (new_ecdt)␊ |
1413 | ␉␉␉␉␉{␊ |
1414 | ␉␉␉␉␉␉rsdt_entries[i-dropoffset]=(uint32_t)new_ecdt;␊ |
1415 | ␉␉␉␉␉␉ecdt_replaced=true;␊ |
1416 | ␉␉␉␉␉}␊ |
1417 | ␉␉␉␉␉␊ |
1418 | ␉␉␉␉␉continue;␊ |
1419 | ␉␉␉␉}␊ |
1420 | ␊ |
1421 | ␉␉␉␉if ((!(oem_asft)) && tableSign(table, "ASF!"))␊ |
1422 | ␉␉␉␉{␊ |
1423 | ␉␉␉␉␉DBG("ASF! found\n");␊ |
1424 | ␉␉␉␉␉if (new_asft)␊ |
1425 | ␉␉␉␉␉{␊ |
1426 | ␉␉␉␉␉␉rsdt_entries[i-dropoffset]=(uint32_t)new_asft;␊ |
1427 | ␉␉␉␉␉␉asft_replaced=true;␊ |
1428 | ␉␉␉␉␉}␊ |
1429 | ␉␉␉␉␉continue;␊ |
1430 | ␉␉␉␉}␊ |
1431 | ␊ |
1432 | ␉␉␉␉if ((!(oem_dmar)) && tableSign(table, "DMAR"))␊ |
1433 | ␉␉␉␉{␊ |
1434 | ␉␉␉␉␉DBG("DMAR found\n");␊ |
1435 | ␉␉␉␉␉if (new_dmar)␊ |
1436 | ␉␉␉␉␉{␊ |
1437 | ␉␉␉␉␉␉rsdt_entries[i-dropoffset]=(uint32_t)new_dmar;␊ |
1438 | ␉␉␉␉␉␉dmar_replaced=true;␊ |
1439 | ␉␉␉␉␉}␊ |
1440 | ␉␉␉␉␉continue;␊ |
1441 | ␉␉␉␉}␊ |
1442 | ␊ |
1443 | ␉␉␉␉if ((!(oem_apic)) && tableSign(table, "APIC"))␊ |
1444 | ␉␉␉␉{␊ |
1445 | ␉␉␉␉␉DBG("APIC found\n");␊ |
1446 | ␉␉␉␉␉if (new_apic)␊ |
1447 | ␉␉␉␉␉{␊ |
1448 | ␉␉␉␉␉␉rsdt_entries[i-dropoffset]=(uint32_t)new_apic;␊ |
1449 | ␉␉␉␉␉␉apic_replaced=true;␊ |
1450 | ␉␉␉␉␉}␊ |
1451 | ␉␉␉␉␉continue;␊ |
1452 | ␉␉␉␉}␊ |
1453 | ␊ |
1454 | ␉␉␉␉if ((!(oem_mcfg)) && tableSign(table, "MCFG"))␊ |
1455 | ␉␉␉␉{␊ |
1456 | ␉␉␉␉␉DBG("MCFG found\n");␊ |
1457 | ␉␉␉␉␉if (new_mcfg)␊ |
1458 | ␉␉␉␉␉{␊ |
1459 | ␉␉␉␉␉␉rsdt_entries[i-dropoffset]=(uint32_t)new_mcfg;␊ |
1460 | ␉␉␉␉␉␉mcfg_replaced=true;␊ |
1461 | ␉␉␉␉␉}␊ |
1462 | ␉␉␉␉␉continue;␊ |
1463 | ␉␉␉␉}␊ |
1464 | ␊ |
1465 | ␉␉␉␉if ((!(oem_ssdt)) && tableSign(table, "SSDT"))␊ |
1466 | ␉␉␉␉{␊ |
1467 | ␉␉␉␉␉DBG("SSDT %d found", curssdt);␊ |
1468 | ␉␉␉␉␉if (new_ssdts[curssdt])␊ |
1469 | ␉␉␉␉␉{␊ |
1470 | ␉␉␉␉␉␉DBG(" and replaced");␊ |
1471 | ␉␉␉␉␉␉rsdt_entries[i-dropoffset]=(uint32_t)new_ssdts[curssdt];␊ |
1472 | ␉␉␉␉␉␉totssdt++;␊ |
1473 | ␉␉␉␉␉}␊ |
1474 | ␉␉␉␉␉DBG("\n");␊ |
1475 | ␉␉␉␉␉curssdt++;␊ |
1476 | ␉␉␉␉␉continue;␊ |
1477 | ␉␉␉␉}␊ |
1478 | ␊ |
1479 | ␉␉␉␉if ((!(oem_dsdt)) && tableSign(table, "DSDT"))␊ |
1480 | ␉␉␉␉{␉␉␉␉␉␉␉␉␉␉␊ |
1481 | ␉␉␉␉␉DBG("DSDT found\n");␊ |
1482 | ␉␉␉␉␉rsdt_entries[i-dropoffset]=(uint32_t)new_dsdt;␊ |
1483 | ␉␉␉␉␉continue;␉␉␉␉␊ |
1484 | ␉␉␉␉}␊ |
1485 | ␊ |
1486 | ␉␉␉␉if (tableSign(table, "FACP"))␊ |
1487 | ␉␉␉␉{␉␉␉␉␉␊ |
1488 | ␉␉␉␉␉fadt=(struct acpi_2_fadt *)rsdt_entries[i];␊ |
1489 | ␉␉␉␉␉␊ |
1490 | ␉␉␉␉␉DBG("FADT found @%x, Length %d\n",fadt, fadt->Length);␊ |
1491 | ␉␉␉␉␉␊ |
1492 | ␉␉␉␉␉if (!fadt || (uint32_t)fadt == 0xffffffff || fadt->Length>0x10000)␊ |
1493 | ␉␉␉␉␉{␊ |
1494 | ␉␉␉␉␉␉printf("FADT incorrect. Not modified\n");␊ |
1495 | ␉␉␉␉␉␉continue;␊ |
1496 | ␉␉␉␉␉}␊ |
1497 | ␉␉␉␉␉verbose("Attempting to patch FADT entry of RSDT\n");␊ |
1498 | ␉␉␉␉␉fadt_mod = patch_fadt(fadt, new_dsdt, update_acpi);␊ |
1499 | ␉␉␉␉␉␊ |
1500 | ␉␉␉␉␉rsdt_entries[i-dropoffset]=(uint32_t)fadt_mod;␊ |
1501 | ␉␉␉␉␉␊ |
1502 | ␉␉␉␉␉if (!oem_ssdt)␊ |
1503 | ␉␉␉␉␉{␊ |
1504 | ␉␉␉␉␉␉// Generate _CST SSDT␊ |
1505 | ␉␉␉␉␉␉if ( gen_csta && (new_ssdt[loadtotssdt] = generate_cst_ssdt(fadt_mod)))␊ |
1506 | ␉␉␉␉␉␉{␊ |
1507 | ␉␉␉␉␉␉␉gen_csta= false;␊ |
1508 | ␉␉␉␉␉␉␉loadtotssdt++;␊ |
1509 | ␉␉␉␉␉␉}␊ |
1510 | ␉␉␉␉␉␉␊ |
1511 | ␉␉␉␉␉␉// Generating _PSS SSDT␊ |
1512 | if (gen_psta && (new_ssdt[loadtotssdt] = generate_pss_ssdt((void*)fadt_mod->DSDT)))␊ |
1513 | {␊ |
1514 | gen_psta= false;␊ |
1515 | loadtotssdt++;␊ |
1516 | }␉␉␉␉␉␉␉␉␉␉␊ |
1517 | ␉␉␉␉␉␉␊ |
1518 | ␉␉␉␉␉}␊ |
1519 | ␉␉␉␉␉␊ |
1520 | ␉␉␉␉␉continue;␊ |
1521 | ␉␉␉␉}␊ |
1522 | ␉␉␉}␊ |
1523 | ␉␉␉DBG("\n");␊ |
1524 | ␉␉␉␊ |
1525 | ␉␉␉if ((!oem_hpet) && (!hpet_replaced))␊ |
1526 | ␉␉␉{␊ |
1527 | ␉␉␉␉if (new_hpet)␊ |
1528 | ␉␉␉␉{␊ |
1529 | ␉␉␉␉␉rsdt_entries[i-dropoffset]=(uint32_t)new_hpet;␊ |
1530 | ␉␉␉␉␉hpet_added=true;␊ |
1531 | ␉␉␉␉␉i++;␊ |
1532 | ␉␉␉␉}␊ |
1533 | ␉␉␉}␊ |
1534 | ␉␉␉␊ |
1535 | ␉␉␉if ((!oem_sbst) && (!sbst_replaced))␊ |
1536 | ␉␉␉{␊ |
1537 | ␉␉␉␉if (new_sbst)␊ |
1538 | ␉␉␉␉{␊ |
1539 | ␉␉␉␉␉rsdt_entries[i-dropoffset]=(uint32_t)new_sbst;␊ |
1540 | ␉␉␉␉␉sbst_added=true;␊ |
1541 | ␉␉␉␉␉i++;␊ |
1542 | ␉␉␉␉}␊ |
1543 | ␉␉␉}␊ |
1544 | ␉␉␉␊ |
1545 | ␉␉␉if ((!oem_ecdt) && (!ecdt_replaced))␊ |
1546 | ␉␉␉{␊ |
1547 | ␉␉␉␉if (new_ecdt)␊ |
1548 | ␉␉␉␉{␉␉␉␉␉␉␉␉␉␉␊ |
1549 | ␉␉␉␉␉rsdt_entries[i-dropoffset]=(uint32_t)new_ecdt;␊ |
1550 | ␉␉␉␉␉ecdt_added=true;␊ |
1551 | ␉␉␉␉␉i++;␊ |
1552 | ␉␉␉␉}␊ |
1553 | ␉␉␉}␊ |
1554 | ␉␉␉␊ |
1555 | ␉␉␉if ((!oem_asft) && (!asft_replaced))␊ |
1556 | ␉␉␉{␊ |
1557 | ␉␉␉␉if (new_asft)␊ |
1558 | ␉␉␉␉{␊ |
1559 | ␉␉␉␉␉rsdt_entries[i-dropoffset]=(uint32_t)new_asft;␊ |
1560 | ␉␉␉␉␉asft_added=true;␊ |
1561 | ␉␉␉␉␉i++;␊ |
1562 | ␉␉␉␉}␊ |
1563 | ␉␉␉}␊ |
1564 | ␉␉␉␊ |
1565 | ␉␉␉if ((!oem_dmar) && (!dmar_replaced))␊ |
1566 | ␉␉␉{␊ |
1567 | ␉␉␉␉if (new_dmar)␊ |
1568 | ␉␉␉␉{␊ |
1569 | ␉␉␉␉␉rsdt_entries[i-dropoffset]=(uint32_t)new_dmar;␊ |
1570 | ␉␉␉␉␉dmar_added=true;␊ |
1571 | ␉␉␉␉␉i++;␊ |
1572 | ␉␉␉␉}␊ |
1573 | ␉␉␉}␊ |
1574 | ␉␉␉␊ |
1575 | ␉␉␉if ((!oem_apic) && (!apic_replaced))␊ |
1576 | ␉␉␉{␊ |
1577 | ␉␉␉␉if (new_apic)␊ |
1578 | ␉␉␉␉{␊ |
1579 | ␉␉␉␉␉rsdt_entries[i-dropoffset]=(uint32_t)new_apic;␊ |
1580 | ␉␉␉␉␉apic_added=true;␊ |
1581 | ␉␉␉␉␉i++;␊ |
1582 | ␉␉␉␉}␊ |
1583 | ␉␉␉}␊ |
1584 | ␉␉␉␊ |
1585 | ␉␉␉if ((!oem_mcfg) && (!mcfg_replaced))␊ |
1586 | ␉␉␉{␊ |
1587 | ␉␉␉␉if (new_mcfg)␊ |
1588 | ␉␉␉␉{␊ |
1589 | ␉␉␉␉␉rsdt_entries[i-dropoffset]=(uint32_t)new_mcfg;␊ |
1590 | ␉␉␉␉␉mcfg_added=true;␊ |
1591 | ␉␉␉␉␉i++;␊ |
1592 | ␉␉␉␉}␊ |
1593 | ␉␉␉}␊ |
1594 | ␉␉␉␊ |
1595 | ␉␉␉if (!oem_ssdt)␊ |
1596 | ␉␉␉{ ␉␉␉␊ |
1597 | ␉␉␉␉while ((totssdt < loadtotssdt) && (curssdt < 17))␊ |
1598 | ␉␉␉␉{␊ |
1599 | ␉␉␉␉␉if (new_ssdt[curssdt])␊ |
1600 | ␉␉␉␉␉{␊ |
1601 | ␉␉␉␉␉␉DBG("adding SSDT %d\n", curssdt);␉␉␉␉␉␉␊ |
1602 | ␉␉␉␉␉␉rsdt_entries[i-dropoffset]=(uint32_t)new_ssdt[curssdt];␊ |
1603 | ␉␉␉␉␉␉totssdt++;␊ |
1604 | ␉␉␉␉␉␉newtotssdt++;␊ |
1605 | ␉␉␉␉␉␉i++;␊ |
1606 | ␉␉␉␉␉} else if (quick_ssdt) {␉␉␉␉␊ |
1607 | ␉␉␉␉␉␉break;␉␉␉␉␉␉␉␉␊ |
1608 | ␉␉␉␉␉}␊ |
1609 | ␉␉␉␉␉␊ |
1610 | ␉␉␉␉␉curssdt++;␊ |
1611 | ␉␉␉␉}␊ |
1612 | ␉␉␉}␊ |
1613 | ␉␉␉␊ |
1614 | ␉␉␉// Correct the checksum of RSDT␊ |
1615 | ␉␉␉rsdt_mod->Length-=4*dropoffset;␊ |
1616 | ␉␉␉rsdt_mod->Length+=4*newtotssdt;␊ |
1617 | ␉␉␉if (hpet_added)␊ |
1618 | ␉␉␉␉rsdt_mod->Length+=4;␊ |
1619 | ␉␉␉if (sbst_added)␊ |
1620 | ␉␉␉␉rsdt_mod->Length+=4;␊ |
1621 | ␉␉␉if (ecdt_added)␊ |
1622 | ␉␉␉␉rsdt_mod->Length+=4;␊ |
1623 | ␉␉␉if (asft_added)␊ |
1624 | ␉␉␉␉rsdt_mod->Length+=4;␊ |
1625 | ␉␉␉if (dmar_added)␊ |
1626 | ␉␉␉␉rsdt_mod->Length+=4;␊ |
1627 | ␉␉␉if (apic_added)␊ |
1628 | ␉␉␉␉rsdt_mod->Length+=4;␊ |
1629 | ␉␉␉if (mcfg_added)␊ |
1630 | ␉␉␉␉rsdt_mod->Length+=4;␊ |
1631 | ␉␉␉␊ |
1632 | ␉␉␉DBG("RSDT: Original checksum %d, ", rsdt_mod->Checksum);␉␉␉␊ |
1633 | ␉␉␉ ␊ |
1634 | setchecksum((struct acpi_common_header *)rsdt_mod);␊ |
1635 | ␉␉␉␊ |
1636 | ␉␉␉DBG("New checksum %d at %x\n", rsdt_mod->Checksum,rsdt_mod);␊ |
1637 | ␉␉␉␊ |
1638 | ␉␉}␊ |
1639 | ␉␉else␊ |
1640 | ␉␉{␊ |
1641 | ␉␉␉rsdp_mod->RsdtAddress=0;␊ |
1642 | ␉␉␉printf("RSDT not found or RSDT incorrect\n");␊ |
1643 | ␉␉}␊ |
1644 | ␉␉␊ |
1645 | ␉␉if (version)␊ |
1646 | ␉␉{␊ |
1647 | ␉␉␉struct acpi_2_xsdt *xsdt, *xsdt_mod;␊ |
1648 | ␉␉␉␊ |
1649 | ␉␉␉// FIXME: handle 64-bit address correctly␊ |
1650 | ␉␉␉␊ |
1651 | ␉␉␉if (gen_xsdt)␊ |
1652 | ␉␉␉␉xsdt=xsdt_conv;␊ |
1653 | ␉␉␉else␊ |
1654 | ␉␉␉␉xsdt=(struct acpi_2_xsdt*) ((uint32_t)rsdp->XsdtAddress);␊ |
1655 | ␉␉␉␊ |
1656 | ␉␉␉DBG("XSDT @%x;%x, Length=%d\n", (uint32_t)(rsdp->XsdtAddress>>32),(uint32_t)rsdp->XsdtAddress,␊ |
1657 | ␉␉␉␉xsdt->Length);␊ |
1658 | ␉␉␉if (xsdt && (uint64_t)rsdp->XsdtAddress<0xffffffff && xsdt->Length<0x10000)␊ |
1659 | ␉␉␉{␉␉␉␉␊ |
1660 | ␉␉␉␉int dropoffset=0, i;␊ |
1661 | ␉␉␉␉curssdt=0, totssdt=0, newtotssdt=0;␊ |
1662 | ␉␉␉␉hpet_replaced=false, hpet_added=false;␊ |
1663 | ␉␉␉␉sbst_replaced=false, sbst_added=false;␊ |
1664 | ␉␉␉␉ecdt_replaced=false, ecdt_added=false;␊ |
1665 | ␉␉␉␉asft_replaced=false, asft_added=false;␊ |
1666 | ␉␉␉␉dmar_replaced=false, dmar_added=false;␊ |
1667 | ␉␉␉␉apic_replaced=false, apic_added=false;␊ |
1668 | ␉␉␉␉mcfg_replaced=false, mcfg_added=false;␊ |
1669 | ␉␉␉␉␊ |
1670 | ␉␉␉␉if (gen_xsdt)␊ |
1671 | ␉␉␉␉␉xsdt_mod=xsdt;␊ |
1672 | ␉␉␉␉else␊ |
1673 | ␉␉␉␉{␊ |
1674 | ␉␉␉␉␉xsdt_mod=(struct acpi_2_xsdt*)AllocateKernelMemory(xsdt->Length); ␊ |
1675 | ␉␉␉␉␉memcpy(xsdt_mod, xsdt, xsdt->Length);␊ |
1676 | ␉␉␉␉}␊ |
1677 | ␊ |
1678 | update_rsdp_with_xsdt(rsdp_mod, xsdt_mod);␊ |
1679 | ␊ |
1680 | ␉␉␉␉int xsdt_entries_num=(xsdt_mod->Length-sizeof(struct acpi_2_xsdt))/8;␊ |
1681 | ␉␉␉␉uint64_t *xsdt_entries=(uint64_t *)(xsdt_mod+1);␊ |
1682 | ␉␉␉␉for (i=0;i<xsdt_entries_num;i++)␊ |
1683 | ␉␉␉␉{␊ |
1684 | ␊ |
1685 | ␉␉␉␉␉char *table=(char *)((uint32_t)(xsdt_entries[i]));␊ |
1686 | ␉␉␉␉␉if (!table)␊ |
1687 | ␉␉␉␉␉␉continue;␊ |
1688 | ␉␉␉␉␉ ␊ |
1689 | ␉␉␉␉␉xsdt_entries[i-dropoffset]=xsdt_entries[i];␊ |
1690 | ␉␉␉␉␉␊ |
1691 | ␉␉␉␉␉char table4[4];␊ |
1692 | ␉␉␉␉␉strlcpy(table4, table, sizeof(table4)+1);␊ |
1693 | ␉␉␉␉␉TagPtr match_drop = XMLGetProperty(DropTables_p, (const char*)table4); ␊ |
1694 | ␉␉␉␉␉if ( match_drop ) {␊ |
1695 | ␉␉␉␉␉␉char *tmpstr = XMLCastString(match_drop);␊ |
1696 | ␉␉␉␉␉␉if (strcmp(tmpstr,"No") != 0) {␊ |
1697 | ␉␉␉␉␉␉␉dropoffset++;␊ |
1698 | ␉␉␉␉␉␉␉DBG("%s table dropped\n",table4);␊ |
1699 | ␉␉␉␉␉␉␉continue;␊ |
1700 | ␉␉␉␉␉␉}␊ |
1701 | ␉␉␉␉␉}␊ |
1702 | ␉␉␉␉␉ ␊ |
1703 | if ((!(oem_hpet)) && tableSign(table, "HPET"))␊ |
1704 | ␉␉␉␉␉{␊ |
1705 | ␉␉␉␉␉␉DBG("HPET found\n");␊ |
1706 | ␉␉␉␉␉␉if (new_hpet)␊ |
1707 | ␉␉␉␉␉␉{␊ |
1708 | ␉␉␉␉␉␉␉xsdt_entries[i-dropoffset]=(uint32_t)new_hpet;␊ |
1709 | ␉␉␉␉␉␉␉hpet_replaced=true;␊ |
1710 | ␉␉␉␉␉␉}␊ |
1711 | ␉␉␉␉␉␉continue;␊ |
1712 | ␉␉␉␉␉}␊ |
1713 | ␊ |
1714 | if ((!(oem_sbst)) && tableSign(table, "SBST"))␊ |
1715 | ␉␉␉␉␉{␊ |
1716 | ␉␉␉␉␉␉DBG("SBST found\n");␊ |
1717 | ␉␉␉␉␉␉if (new_sbst)␊ |
1718 | ␉␉␉␉␉␉{␊ |
1719 | ␉␉␉␉␉␉␉xsdt_entries[i-dropoffset]=(uint32_t)new_sbst;␊ |
1720 | ␉␉␉␉␉␉␉sbst_replaced=true;␊ |
1721 | ␉␉␉␉␉␉}␊ |
1722 | ␉␉␉␉␉␉continue;␊ |
1723 | ␉␉␉␉␉}␊ |
1724 | ␊ |
1725 | if ((!(oem_ecdt)) && tableSign(table, "ECDT"))␊ |
1726 | ␉␉␉␉␉{␊ |
1727 | ␉␉␉␉␉␉DBG("ECDT found\n");␊ |
1728 | ␉␉␉␉␉␉␊ |
1729 | ␉␉␉␉␉␉if (new_ecdt)␊ |
1730 | ␉␉␉␉␉␉{␊ |
1731 | ␉␉␉␉␉␉␉xsdt_entries[i-dropoffset]=(uint32_t)new_ecdt;␊ |
1732 | ␉␉␉␉␉␉␉ecdt_replaced=true;␊ |
1733 | ␉␉␉␉␉␉}␊ |
1734 | ␉␉␉␉␉␉␊ |
1735 | ␉␉␉␉␉␉continue;␊ |
1736 | ␉␉␉␉␉}␊ |
1737 | ␊ |
1738 | if ((!(oem_asft)) && tableSign(table, "ASF!"))␊ |
1739 | ␉␉␉␉␉{␊ |
1740 | ␉␉␉␉␉␉DBG("ASF! found\n");␊ |
1741 | ␉␉␉␉␉␉if (new_asft)␊ |
1742 | ␉␉␉␉␉␉{␊ |
1743 | ␉␉␉␉␉␉␉xsdt_entries[i-dropoffset]=(uint32_t)new_asft;␊ |
1744 | ␉␉␉␉␉␉␉asft_replaced=true;␊ |
1745 | ␉␉␉␉␉␉}␊ |
1746 | ␉␉␉␉␉␉continue;␊ |
1747 | ␉␉␉␉␉}␊ |
1748 | ␊ |
1749 | ␊ |
1750 | if ((!(oem_dmar)) && tableSign(table, "DMAR"))␊ |
1751 | ␉␉␉␉␉{␊ |
1752 | ␉␉␉␉␉␉DBG("DMAR found\n");␊ |
1753 | ␉␉␉␉␉␉if (new_dmar)␊ |
1754 | ␉␉␉␉␉␉{␊ |
1755 | ␉␉␉␉␉␉␉xsdt_entries[i-dropoffset]=(uint32_t)new_dmar;␊ |
1756 | ␉␉␉␉␉␉␉dmar_replaced=true;␊ |
1757 | ␉␉␉␉␉␉}␊ |
1758 | ␉␉␉␉␉␉continue;␊ |
1759 | ␉␉␉␉␉}␊ |
1760 | ␊ |
1761 | if ((!(oem_apic)) && tableSign(table, "APIC"))␊ |
1762 | ␉␉␉␉␉{␊ |
1763 | ␉␉␉␉␉␉DBG("APIC found\n");␊ |
1764 | ␉␉␉␉␉␉if (new_apic)␊ |
1765 | ␉␉␉␉␉␉{␊ |
1766 | ␉␉␉␉␉␉␉xsdt_entries[i-dropoffset]=(uint32_t)new_apic;␊ |
1767 | ␉␉␉␉␉␉␉apic_replaced=true;␊ |
1768 | ␉␉␉␉␉␉}␊ |
1769 | ␉␉␉␉␉␉continue;␊ |
1770 | ␉␉␉␉␉} ␊ |
1771 | ␊ |
1772 | if ((!(oem_mcfg)) && tableSign(table, "MCFG"))␊ |
1773 | ␉␉␉␉␉{␊ |
1774 | ␉␉␉␉␉␉DBG("MCFG found\n");␊ |
1775 | ␉␉␉␉␉␉if (new_mcfg)␊ |
1776 | ␉␉␉␉␉␉{␊ |
1777 | ␉␉␉␉␉␉␉xsdt_entries[i-dropoffset]=(uint32_t)new_mcfg;␊ |
1778 | ␉␉␉␉␉␉␉mcfg_replaced=true;␊ |
1779 | ␉␉␉␉␉␉}␊ |
1780 | ␉␉␉␉␉␉continue;␊ |
1781 | ␉␉␉␉␉}␊ |
1782 | ␊ |
1783 | if ((!(oem_ssdt)) && tableSign(table, "SSDT"))␊ |
1784 | ␉␉␉␉␉{␊ |
1785 | ␉␉␉␉␉␉DBG("SSDT %d found", curssdt);␊ |
1786 | ␉␉␉␉␉␉if (new_ssdts[curssdt])␊ |
1787 | ␉␉␉␉␉␉{␊ |
1788 | ␉␉␉␉␉␉␉DBG(" and replaced");␊ |
1789 | ␉␉␉␉␉␉␉xsdt_entries[i-dropoffset]=(uint32_t)new_ssdts[curssdt];␊ |
1790 | ␉␉␉␉␉␉␉totssdt++;␊ |
1791 | ␉␉␉␉␉␉}␊ |
1792 | ␉␉␉␉␉␉DBG("\n");␊ |
1793 | ␉␉␉␉␉␉curssdt++;␊ |
1794 | ␉␉␉␉␉␉continue;␊ |
1795 | ␉␉␉␉␉}␊ |
1796 | ␊ |
1797 | if ((!(oem_dsdt)) && tableSign(table, "DSDT"))␊ |
1798 | ␉␉␉␉␉{␊ |
1799 | ␉␉␉␉␉␉DBG("DSDT found\n");␊ |
1800 | ␉␉␉␉␉␉␊ |
1801 | ␉␉␉␉␉␉xsdt_entries[i-dropoffset]=(uint32_t)new_dsdt;␊ |
1802 | ␉␉␉␉␉␉␊ |
1803 | ␉␉␉␉␉␉DBG("TABLE %c%c%c%c@%x,",table[0],table[1],table[2],table[3],xsdt_entries[i]);␊ |
1804 | ␉␉␉␉␉␉␊ |
1805 | ␉␉␉␉␉␉continue;␊ |
1806 | ␉␉␉␉␉␉␊ |
1807 | ␉␉␉␉␉}␊ |
1808 | ␊ |
1809 | if (tableSign(table, "FACP"))␊ |
1810 | ␉␉␉␉␉{␊ |
1811 | ␉␉␉␉␉␉fadt=(struct acpi_2_fadt *)(uint32_t)xsdt_entries[i];␊ |
1812 | ␉␉␉␉␉␉␊ |
1813 | ␉␉␉␉␉␉DBG("FADT found @%x,%x, Length %d\n",(uint32_t)(xsdt_entries[i]>>32),fadt, ␊ |
1814 | ␉␉␉␉␉␉␉fadt->Length);␊ |
1815 | ␉␉␉␉␉␉␊ |
1816 | ␉␉␉␉␉␉if (!fadt || (uint64_t)xsdt_entries[i] >= 0xffffffff || fadt->Length>0x10000)␊ |
1817 | ␉␉␉␉␉␉{␊ |
1818 | ␉␉␉␉␉␉␉verbose("FADT incorrect or after 4GB. Dropping XSDT\n");␊ |
1819 | ␉␉␉␉␉␉␉goto drop_xsdt;␊ |
1820 | ␉␉␉␉␉␉}␊ |
1821 | ␉␉␉␉␉␉verbose("Attempting to patch FADT entry of XSDT\n");␊ |
1822 | ␉␉␉␉␉␉fadt_mod = patch_fadt(fadt, new_dsdt, update_acpi);␊ |
1823 | ␉␉␉␉␉␉␊ |
1824 | ␉␉␉␉␉␉␊ |
1825 | ␉␉␉␉␉␉xsdt_entries[i-dropoffset]=(uint32_t)fadt_mod;␊ |
1826 | ␉␉␉␉␉␉␊ |
1827 | ␉␉␉␉␉␉//DBG("TABLE %c%c%c%c@%x,",table[0],table[1],table[2],table[3],xsdt_entries[i]);␊ |
1828 | ␉␉␉␉␉␉␊ |
1829 | ␉␉␉␉␉␉if (!oem_ssdt)␊ |
1830 | {␊ |
1831 | // Generate _CST SSDT␊ |
1832 | if ( gen_csta && (new_ssdt[loadtotssdt] = generate_cst_ssdt(fadt_mod)))␊ |
1833 | {␊ |
1834 | gen_csta= false;␊ |
1835 | loadtotssdt++;␊ |
1836 | }␊ |
1837 | ␊ |
1838 | // Generating _PSS SSDT␊ |
1839 | if (gen_psta && (new_ssdt[loadtotssdt] = generate_pss_ssdt((void*)fadt_mod->DSDT)))␊ |
1840 | {␊ |
1841 | gen_psta= false;␊ |
1842 | loadtotssdt++;␊ |
1843 | }␊ |
1844 | }␊ |
1845 | ␉␉␉␉␉␉␊ |
1846 | ␉␉␉␉␉␉␊ |
1847 | ␉␉␉␉␉␉continue;␊ |
1848 | ␉␉␉␉␉}␊ |
1849 | ␉␉␉␉␉␊ |
1850 | ␉␉␉␉␉//DBG("TABLE %c%c%c%c@%x,",table[0],table[1],table[2],table[3],xsdt_entries[i]);␊ |
1851 | ␉␉␉␉␉␊ |
1852 | ␉␉␉␉}␊ |
1853 | ␉␉␉␉␊ |
1854 | ␉␉␉␉if ((!oem_hpet) && (!hpet_replaced))␊ |
1855 | ␉␉␉␉{␊ |
1856 | ␉␉␉␉␉if (new_hpet)␊ |
1857 | ␉␉␉␉␉{␊ |
1858 | ␉␉␉␉␉␉xsdt_entries[i-dropoffset]=(uint32_t)new_hpet;␊ |
1859 | ␉␉␉␉␉␉hpet_added=true;␊ |
1860 | ␉␉␉␉␉␉i++;␊ |
1861 | ␉␉␉␉␉}␊ |
1862 | ␉␉␉␉}␊ |
1863 | ␉␉␉␉␊ |
1864 | ␉␉␉␉if ((!oem_sbst) && (!sbst_replaced))␊ |
1865 | ␉␉␉␉{␊ |
1866 | ␉␉␉␉␉if (new_sbst)␊ |
1867 | ␉␉␉␉␉{␊ |
1868 | ␉␉␉␉␉␉xsdt_entries[i-dropoffset]=(uint32_t)new_sbst;␊ |
1869 | ␉␉␉␉␉␉sbst_added=true;␊ |
1870 | ␉␉␉␉␉␉i++;␊ |
1871 | ␉␉␉␉␉}␊ |
1872 | ␉␉␉␉}␊ |
1873 | ␉␉␉␉␊ |
1874 | ␉␉␉␉if ((!oem_ecdt) && (!ecdt_replaced))␊ |
1875 | ␉␉␉␉{␊ |
1876 | ␉␉␉␉␉if (new_ecdt)␊ |
1877 | ␉␉␉␉␉{␊ |
1878 | ␉␉␉␉␉␉␊ |
1879 | ␉␉␉␉␉␉xsdt_entries[i-dropoffset]=(uint32_t)new_ecdt;␊ |
1880 | ␉␉␉␉␉␉ecdt_added=true;␊ |
1881 | ␉␉␉␉␉␉i++;␊ |
1882 | ␉␉␉␉␉}␊ |
1883 | ␉␉␉␉}␊ |
1884 | ␉␉␉␉␊ |
1885 | ␉␉␉␉if ((!oem_asft) && (!asft_replaced))␊ |
1886 | ␉␉␉␉{␊ |
1887 | ␉␉␉␉␉if (new_asft)␊ |
1888 | ␉␉␉␉␉{␊ |
1889 | ␉␉␉␉␉␉xsdt_entries[i-dropoffset]=(uint32_t)new_asft;␊ |
1890 | ␉␉␉␉␉␉asft_added=true;␊ |
1891 | ␉␉␉␉␉␉i++;␊ |
1892 | ␉␉␉␉␉}␊ |
1893 | ␉␉␉␉}␊ |
1894 | ␉␉␉␉␊ |
1895 | ␉␉␉␉if ((!oem_dmar) && (!dmar_replaced))␊ |
1896 | ␉␉␉␉{␊ |
1897 | ␉␉␉␉␉if (new_dmar)␊ |
1898 | ␉␉␉␉␉{␊ |
1899 | ␉␉␉␉␉␉xsdt_entries[i-dropoffset]=(uint32_t)new_dmar;␊ |
1900 | ␉␉␉␉␉␉dmar_added=true;␊ |
1901 | ␉␉␉␉␉␉i++;␊ |
1902 | ␉␉␉␉␉}␊ |
1903 | ␉␉␉␉}␊ |
1904 | ␉␉␉␉␊ |
1905 | ␉␉␉␉if ((!oem_apic) && (!apic_replaced))␊ |
1906 | ␉␉␉␉{␊ |
1907 | ␉␉␉␉␉if (new_apic)␊ |
1908 | ␉␉␉␉␉{␊ |
1909 | ␉␉␉␉␉␉xsdt_entries[i-dropoffset]=(uint32_t)new_apic;␊ |
1910 | ␉␉␉␉␉␉apic_added=true;␊ |
1911 | ␉␉␉␉␉␉i++;␊ |
1912 | ␉␉␉␉␉}␊ |
1913 | ␉␉␉␉}␊ |
1914 | ␉␉␉␉␊ |
1915 | ␉␉␉␉if ((!oem_mcfg) && (!mcfg_replaced))␊ |
1916 | ␉␉␉␉{␊ |
1917 | ␉␉␉␉␉if (new_mcfg)␊ |
1918 | ␉␉␉␉␉{␊ |
1919 | ␉␉␉␉␉␉xsdt_entries[i-dropoffset]=(uint32_t)new_mcfg;␊ |
1920 | ␉␉␉␉␉␉mcfg_added=true;␊ |
1921 | ␉␉␉␉␉␉i++;␊ |
1922 | ␉␉␉␉␉}␊ |
1923 | ␉␉␉␉}␊ |
1924 | ␉␉␉␉␊ |
1925 | ␉␉␉␉if (!oem_ssdt)␊ |
1926 | ␉␉␉␉{ ␉␉␉␊ |
1927 | ␉␉␉␉␉while ((totssdt < loadtotssdt) && (curssdt < 17))␊ |
1928 | ␉␉␉␉␉{␊ |
1929 | ␉␉␉␉␉␉if (new_ssdt[curssdt])␊ |
1930 | ␉␉␉␉␉␉{␊ |
1931 | ␉␉␉␉␉␉␉DBG("adding SSDT %d\n", curssdt);␊ |
1932 | ␉␉␉␉␉␉␉xsdt_entries[i-dropoffset]=(uint32_t)new_ssdt[curssdt];␊ |
1933 | ␉␉␉␉␉␉␉totssdt++;␊ |
1934 | ␉␉␉␉␉␉␉newtotssdt++;␊ |
1935 | ␉␉␉␉␉␉␉i++;␊ |
1936 | ␉␉␉␉␉␉} else if (quick_ssdt){␉␉␉␉␊ |
1937 | ␉␉␉␉␉␉␉break;␉␉␉␉␉␉␉␉␊ |
1938 | ␉␉␉␉␉␉}␊ |
1939 | ␉␉␉␉␉␉␊ |
1940 | ␉␉␉␉␉␉curssdt++;␊ |
1941 | ␉␉␉␉␉}␊ |
1942 | ␉␉␉␉}␊ |
1943 | ␉␉␉␉␊ |
1944 | ␉␉␉␉// Correct the checksum of XSDT␊ |
1945 | ␉␉␉␉xsdt_mod->Length-=8*dropoffset;␊ |
1946 | ␉␉␉␉xsdt_mod->Length+=8*newtotssdt;␊ |
1947 | ␉␉␉␉if (hpet_added)␊ |
1948 | ␉␉␉␉␉xsdt_mod->Length+=8;␊ |
1949 | ␉␉␉␉if (sbst_added)␊ |
1950 | ␉␉␉␉␉xsdt_mod->Length+=8;␊ |
1951 | ␉␉␉␉if (ecdt_added)␊ |
1952 | ␉␉␉␉␉xsdt_mod->Length+=8;␊ |
1953 | ␉␉␉␉if (asft_added)␊ |
1954 | ␉␉␉␉␉xsdt_mod->Length+=8;␊ |
1955 | ␉␉␉␉if (dmar_added)␊ |
1956 | ␉␉␉␉␉xsdt_mod->Length+=8;␊ |
1957 | ␉␉␉␉if (apic_added)␊ |
1958 | ␉␉␉␉␉xsdt_mod->Length+=8;␊ |
1959 | ␉␉␉␉if (mcfg_added)␊ |
1960 | ␉␉␉␉␉xsdt_mod->Length+=8;␉␉␉␉␊ |
1961 | ␊ |
1962 | setchecksum((struct acpi_common_header *)xsdt_mod);␊ |
1963 | ␉␉␉}␊ |
1964 | ␉␉␉else␊ |
1965 | ␉␉␉{␊ |
1966 | ␉␉␉drop_xsdt:␊ |
1967 | ␉␉␉␉␊ |
1968 | ␉␉␉␉DBG("About to drop XSDT\n");␊ |
1969 | ␉␉␉␉␊ |
1970 | ␉␉␉␉/*FIXME: Now we just hope that if MacOS doesn't find XSDT it reverts to RSDT. ␊ |
1971 | ␉␉␉␉ * A Better strategy would be to generate␊ |
1972 | ␉␉␉␉ */␊ |
1973 | ␉␉␉␉␊ |
1974 | ␉␉␉␉rsdp_mod->XsdtAddress=0xffffffffffffffffLL;␊ |
1975 | ␉␉␉␉verbose("XSDT not found or XSDT incorrect\n");␊ |
1976 | ␉␉␉}␊ |
1977 | ␉␉}␊ |
1978 | ␉␉␊ |
1979 | ␉␉// Correct the checksum of RSDP ␊ |
1980 | ␉␉␊ |
1981 | ␉␉DBG("RSDP: Original checksum %d, ", rsdp_mod->Checksum);␉␉␊ |
1982 | ␉␉ ␊ |
1983 | setRsdpchecksum(rsdp_mod);␊ |
1984 | ␉␉␊ |
1985 | ␉␉DBG("New checksum %d\n", rsdp_mod->Checksum);␊ |
1986 | ␉␉␊ |
1987 | ␉␉if (version)␊ |
1988 | ␉␉{␊ |
1989 | ␉␉␉DBG("RSDP: Original extended checksum %d", rsdp_mod->ExtendedChecksum);␉␉␉␊ |
1990 | ␊ |
1991 | setRsdpXchecksum(rsdp_mod);␊ |
1992 | ␉␉␉␊ |
1993 | ␉␉␉DBG("New extended checksum %d\n", rsdp_mod->ExtendedChecksum);␊ |
1994 | ␉␉␉␊ |
1995 | ␉␉}␊ |
1996 | ␉␉␊ |
1997 | ␉␉verbose("Patched ACPI version %d\n", version+1);␊ |
1998 | ␉␉␊ |
1999 | ␉␉if (version)␊ |
2000 | ␉␉{␊ |
2001 | ␉␉␉/* XXX aserebln why uint32 cast if pointer is uint64 ? */␊ |
2002 | ␉␉␉acpi20_p = (uint32_t)rsdp_mod;␊ |
2003 | if (acpi20_p)␊ |
2004 | ␉␉␉Status = addConfigurationTable(&gEfiAcpi20TableGuid, &acpi20_p, "ACPI_20");␊ |
2005 | ␉␉}␊ |
2006 | ␉␉else␊ |
2007 | ␉␉{␊ |
2008 | ␉␉␉/* XXX aserebln why uint32 cast if pointer is uint64 ? */␊ |
2009 | ␉␉␉acpi10_p = (uint32_t)rsdp_mod;␊ |
2010 | if (acpi10_p)␊ |
2011 | ␉␉␉Status = addConfigurationTable(&gEfiAcpiTableGuid, &acpi10_p, "ACPI");␊ |
2012 | ␉␉}␊ |
2013 | ␉}␊ |
2014 | ␊ |
2015 | #if DEBUG_DSDT␊ |
2016 | ␉printf("Press a key to continue... (DEBUG_DSDT)\n");␊ |
2017 | ␉getc();␊ |
2018 | #endif␊ |
2019 | ␉//return (Status == EFI_SUCCESS) ? 1 : 0;␊ |
2020 | ␉return Status ;␊ |
2021 | }␊ |
2022 | |