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