1 | /*␊ |
2 | * Copyright 2008 mackerintel␊ |
3 | */␊ |
4 | ␊ |
5 | #include "libsaio.h"␊ |
6 | #include "boot.h"␊ |
7 | #include "bootstruct.h"␊ |
8 | #include "acpi.h"␊ |
9 | #include "efi_tables.h"␊ |
10 | #include "fake_efi.h"␊ |
11 | #include "acpi_patcher.h"␊ |
12 | #include "platform.h"␊ |
13 | #include "cpu.h"␊ |
14 | #include "aml_generator.h"␊ |
15 | ␊ |
16 | #ifndef DEBUG_ACPI␊ |
17 | #define DEBUG_ACPI 0␊ |
18 | #endif␊ |
19 | ␊ |
20 | #if DEBUG_ACPI==2␊ |
21 | #define DBG(x...) {printf(x); sleep(1);}␊ |
22 | #elif DEBUG_ACPI==1␊ |
23 | #define DBG(x...) printf(x)␊ |
24 | #else␊ |
25 | #define DBG(x...)␊ |
26 | #endif␊ |
27 | ␊ |
28 | uint64_t acpi10_p;␊ |
29 | uint64_t acpi20_p;␊ |
30 | ␊ |
31 | /* Gets the ACPI 1.0 RSDP address */␊ |
32 | static struct acpi_2_rsdp* getAddressOfAcpiTable()␊ |
33 | {␊ |
34 | /* TODO: Before searching the BIOS space we are supposed to search the first 1K of the EBDA */␊ |
35 | ␉␊ |
36 | void *acpi_addr = (void*)ACPI_RANGE_START;␊ |
37 | for(; acpi_addr <= (void*)ACPI_RANGE_END; acpi_addr += 16)␊ |
38 | {␊ |
39 | if(*(uint64_t *)acpi_addr == ACPI_SIGNATURE_UINT64_LE)␊ |
40 | {␊ |
41 | uint8_t csum = checksum8(acpi_addr, 20);␊ |
42 | if(csum == 0)␊ |
43 | {␊ |
44 | // Only return the table if it is a true version 1.0 table (Revision 0)␊ |
45 | if(((struct acpi_2_rsdp*)acpi_addr)->Revision == 0)␊ |
46 | return acpi_addr;␊ |
47 | }␊ |
48 | }␊ |
49 | }␊ |
50 | return NULL;␊ |
51 | }␊ |
52 | ␊ |
53 | /* Gets the ACPI 2.0 RSDP address */␊ |
54 | static struct acpi_2_rsdp* getAddressOfAcpi20Table()␊ |
55 | {␊ |
56 | /* TODO: Before searching the BIOS space we are supposed to search the first 1K of the EBDA */␊ |
57 | ␉␊ |
58 | void *acpi_addr = (void*)ACPI_RANGE_START;␊ |
59 | for(; acpi_addr <= (void*)ACPI_RANGE_END; acpi_addr += 16)␊ |
60 | {␊ |
61 | if(*(uint64_t *)acpi_addr == ACPI_SIGNATURE_UINT64_LE)␊ |
62 | {␊ |
63 | uint8_t csum = checksum8(acpi_addr, 20);␊ |
64 | ␊ |
65 | /* Only assume this is a 2.0 or better table if the revision is greater than 0␊ |
66 | * NOTE: ACPI 3.0 spec only seems to say that 1.0 tables have revision 1␊ |
67 | * and that the current revision is 2.. I am going to assume that rev > 0 is 2.0.␊ |
68 | */␊ |
69 | ␊ |
70 | if(csum == 0 && (((struct acpi_2_rsdp*)acpi_addr)->Revision > 0))␊ |
71 | {␊ |
72 | uint8_t csum2 = checksum8(acpi_addr, sizeof(struct acpi_2_rsdp));␊ |
73 | if(csum2 == 0)␊ |
74 | return acpi_addr;␊ |
75 | }␊ |
76 | }␊ |
77 | }␊ |
78 | return NULL;␊ |
79 | }␊ |
80 | ␊ |
81 | /* The folowing ACPI Table search algo. should be reused anywhere needed:*/␊ |
82 | int search_and_get_acpi_fd(const char * filename, const char ** outDirspec)␊ |
83 | {␊ |
84 | ␉int fd=0;␊ |
85 | ␉const char * overriden_pathname=NULL;␊ |
86 | ␉static char dirspec[512]="";␊ |
87 | ␉int len=0;␊ |
88 | ␉␊ |
89 | ␉// Take in accound user overriding if it's DSDT only␊ |
90 | ␉if (strstr(filename, "DSDT") && ␊ |
91 | ␉␉getValueForKey(kDSDT, &overriden_pathname, &len, &bootInfo->bootConfig))␊ |
92 | {␊ |
93 | ␉␉sprintf(dirspec, "%s", overriden_pathname); // start searching root␊ |
94 | ␉␉fd=open (dirspec,0);␊ |
95 | ␉␉if (fd>=0) goto success_fd;␊ |
96 | }␊ |
97 | ␉␊ |
98 | ␉// Start searching any potential location for ACPI Table␊ |
99 | ␉sprintf(dirspec, "/%s", filename); // start searching root␊ |
100 | ␉fd=open (dirspec,0);␊ |
101 | ␉if (fd>=0) goto success_fd;␊ |
102 | ␉␊ |
103 | ␉sprintf(dirspec, "%s", filename); // start current dir␊ |
104 | ␉fd=open (dirspec,0);␊ |
105 | ␉if (fd>=0) goto success_fd;␊ |
106 | ␉␊ |
107 | ␉sprintf(dirspec,"/Extra/%s",filename);␊ |
108 | ␉fd=open (dirspec,0);␊ |
109 | ␉if (fd>=0) goto success_fd;␊ |
110 | ␉␊ |
111 | ␉sprintf(dirspec,"bt(0,0)/Extra/%s",filename);␊ |
112 | ␉fd=open (dirspec,0);␊ |
113 | ␉if (fd>=0) goto success_fd;␊ |
114 | ␉␊ |
115 | ␉// NOT FOUND:␊ |
116 | ␉//verbose("ACPI Table not found: %s\n", filename);␊ |
117 | ␉if (outDirspec) *outDirspec = "";␊ |
118 | ␉return -1;␊ |
119 | ␉// FOUND␊ |
120 | success_fd:␊ |
121 | ␉if (outDirspec) *outDirspec = dirspec; ␊ |
122 | ␉return fd;␊ |
123 | }␊ |
124 | ␊ |
125 | void *loadACPITable(char *key)␊ |
126 | {␊ |
127 | ␉void *tableAddr;␊ |
128 | ␉int fd = -1;␊ |
129 | ␉char dirspec[512];␊ |
130 | ␉char filename[512];␊ |
131 | ␉const char * overriden_pathname=NULL;␊ |
132 | ␉int len=0;␊ |
133 | ␊ |
134 | ␉sprintf(filename, "%s.aml", key);␊ |
135 | ␊ |
136 | ␉// Checking boot partition␊ |
137 | ␊ |
138 | ␉// Rek: if user specified a full path name then take it in consideration␊ |
139 | ␉if (getValueForKey(key, &overriden_pathname, &len, &bootInfo->bootConfig))␊ |
140 | ␉{␊ |
141 | ␉␉sprintf(dirspec, "%s", overriden_pathname); // start searching root␊ |
142 | ␉␉//printf("Using custom %s path %s\n", key, dirspec);␊ |
143 | ␉␉//getc();␊ |
144 | ␉}␊ |
145 | ␉else␊ |
146 | ␉␉sprintf(dirspec, "/%s", filename); // start searching root␊ |
147 | ␊ |
148 | ␉fd=open (dirspec,0);␊ |
149 | ␊ |
150 | ␉if (fd<0)␊ |
151 | ␉{␉// Check Extra on booting partition␊ |
152 | ␉ //verbose("Searching for %s.aml file ...\n", key);␊ |
153 | ␉␉sprintf(dirspec,"/Extra/%s",filename);␊ |
154 | ␉␉fd=open (dirspec,0);␊ |
155 | ␉␉if (fd<0)␊ |
156 | ␉␉{␉// Fall back to booter partition␊ |
157 | ␉␉␉sprintf(dirspec,"bt(0,0)/Extra/%s",filename);␊ |
158 | ␉␉␉fd=open (dirspec,0);␊ |
159 | ␉␉␉if (fd<0)␊ |
160 | ␉␉␉{␊ |
161 | ␉␉␉␉//verbose("ACPI Table not found: %s\n", filename);␊ |
162 | ␉␉␉␉return NULL;␊ |
163 | ␉␉␉}␊ |
164 | ␉␉}␊ |
165 | ␉}␊ |
166 | ␊ |
167 | ␉tableAddr=(void*)AllocateKernelMemory(file_size (fd));␊ |
168 | ␉if (tableAddr)␊ |
169 | ␉{␊ |
170 | ␉␉if (read (fd, tableAddr, file_size (fd))!=file_size (fd))␊ |
171 | ␉␉{␊ |
172 | ␉␉␉printf("Couldn't read table %s\n",dirspec);␊ |
173 | ␉␉␉free (tableAddr);␊ |
174 | ␉␉␉close (fd);␊ |
175 | ␉␉␉return NULL;␊ |
176 | ␉␉}␊ |
177 | ␊ |
178 | ␉␉DBG("Table %s read and stored at: %x\n", dirspec, tableAddr);␊ |
179 | ␉␉close (fd);␊ |
180 | ␉␉return tableAddr;␊ |
181 | ␉}␊ |
182 | ␊ |
183 | ␉printf("Couldn't allocate memory for table %s\n", dirspec);␊ |
184 | ␉close (fd);␊ |
185 | ␊ |
186 | ␉return NULL;␊ |
187 | }␊ |
188 | ␊ |
189 | uint8_t␉acpi_cpu_count = 0;␊ |
190 | char* acpi_cpu_name[32];␊ |
191 | ␊ |
192 | void get_acpi_cpu_names(unsigned char* dsdt, uint32_t length)␊ |
193 | {␊ |
194 | ␉uint32_t i;␊ |
195 | ␉␊ |
196 | ␉for (i=0; i<length-7; i++) ␊ |
197 | ␉{␊ |
198 | ␉␉if (dsdt[i] == 0x5B && dsdt[i+1] == 0x83) // ProcessorOP␊ |
199 | ␉␉{␊ |
200 | ␉␉␉uint32_t offset = i + 3 + (dsdt[i+2] >> 6);␊ |
201 | ␉␉␉␊ |
202 | ␉␉␉bool add_name = true;␊ |
203 | ␊ |
204 | ␉␉␉uint8_t j;␊ |
205 | ␉␉␉␊ |
206 | ␉␉␉for (j=0; j<4; j++) ␊ |
207 | ␉␉␉{␊ |
208 | ␉␉␉␉char c = dsdt[offset+j];␊ |
209 | ␉␉␉␉␊ |
210 | ␉␉␉␉if (!aml_isvalidchar(c)) ␊ |
211 | ␉␉␉␉{␊ |
212 | ␉␉␉␉␉add_name = false;␊ |
213 | ␉␉␉␉␉verbose("Invalid character found in ProcessorOP 0x%x!\n", c);␊ |
214 | ␉␉␉␉␉break;␊ |
215 | ␉␉␉␉}␊ |
216 | ␉␉␉}␊ |
217 | ␉␉␉␊ |
218 | ␉␉␉if (add_name)␊ |
219 | ␉␉␉{␊ |
220 | ␉␉␉␉acpi_cpu_name[acpi_cpu_count] = malloc(4);␊ |
221 | ␉␉␉␉memcpy(acpi_cpu_name[acpi_cpu_count], dsdt+offset, 4);␊ |
222 | ␉␉␉␉i = offset + 5;␊ |
223 | ␊ |
224 | ␉␉␉␉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]);␊ |
225 | ␊ |
226 | ␉␉␉␉if (++acpi_cpu_count == 32) return;␊ |
227 | ␉␉␉}␊ |
228 | ␉␉}␊ |
229 | ␉}␊ |
230 | }␊ |
231 | ␊ |
232 | struct acpi_2_ssdt *generate_cst_ssdt(struct acpi_2_fadt* fadt)␊ |
233 | {␊ |
234 | ␉char ssdt_header[] =␊ |
235 | ␉{␊ |
236 | ␉␉0x53, 0x53, 0x44, 0x54, 0xE7, 0x00, 0x00, 0x00, /* SSDT.... */␊ |
237 | ␉␉0x01, 0x17, 0x50, 0x6D, 0x52, 0x65, 0x66, 0x41, /* ..PmRefA */␊ |
238 | ␉␉0x43, 0x70, 0x75, 0x43, 0x73, 0x74, 0x00, 0x00, /* CpuCst.. */␊ |
239 | ␉␉0x00, 0x10, 0x00, 0x00, 0x49, 0x4E, 0x54, 0x4C, /* ....INTL */␊ |
240 | ␉␉0x31, 0x03, 0x10, 0x20 ␉␉␉␉␉␉␉/* 1.._␉␉*/␊ |
241 | ␉};␊ |
242 | ␉␊ |
243 | ␉char cstate_resource_template[] = ␊ |
244 | ␉{␊ |
245 | ␉␉0x11, 0x14, 0x0A, 0x11, 0x82, 0x0C, 0x00, 0x7F, ␊ |
246 | ␉␉0x01, 0x02, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, ␊ |
247 | ␉␉0x00, 0x00, 0x00, 0x79, 0x00␊ |
248 | ␉};␊ |
249 | ␊ |
250 | ␉if (Platform.CPU.Vendor != 0x756E6547) {␊ |
251 | ␉␉verbose ("C-States: Not an Intel platform !!!\n");␊ |
252 | ␉␉return NULL;␊ |
253 | ␉}␊ |
254 | ␉␊ |
255 | ␉if (fadt == NULL) {␊ |
256 | ␉␉verbose ("C-States: FACP not found !!!\n");␊ |
257 | ␉␉return NULL;␊ |
258 | ␉}␊ |
259 | ␉␊ |
260 | ␉struct acpi_2_dsdt* dsdt = (void*)fadt->DSDT;␊ |
261 | ␉␊ |
262 | ␉if (dsdt == NULL) {␊ |
263 | ␉␉verbose ("C-States: DSDT not found !!!\n");␊ |
264 | ␉␉return NULL;␊ |
265 | ␉}␊ |
266 | ␉␊ |
267 | ␉if (acpi_cpu_count == 0) ␊ |
268 | ␉␉get_acpi_cpu_names((void*)dsdt, dsdt->Length);␊ |
269 | ␉␊ |
270 | ␉if (acpi_cpu_count > 0) ␊ |
271 | ␉{␊ |
272 | ␉␉//valv: c2 & c3 are enabled by default; else don't use EnableCStates␊ |
273 | ␉␉bool c2_enabled, c3_enabled, c4_enabled, c6_enabled, tmpval2, tmpval3, tmpval4, tmpval6;␊ |
274 | ␉␉c2_enabled = c3_enabled = c4_enabled = c6_enabled = false;␊ |
275 | ␉␉unsigned char cstates_count;␊ |
276 | ␊ |
277 | ␉␉c2_enabled = (getBoolForKey(kEnableC2State, &tmpval2, &bootInfo->bootConfig)&&tmpval2) | (fadt->P_LVL2_LAT < 100);␊ |
278 | ␉␉c3_enabled = (getBoolForKey(kEnableC3State, &tmpval3, &bootInfo->bootConfig)&&tmpval3) | (fadt->P_LVL2_LAT < 1000);␊ |
279 | ␉␉c4_enabled = getBoolForKey(kEnableC4State, &tmpval4, &bootInfo->bootConfig)&&tmpval4;␊ |
280 | ␉␉c6_enabled = getBoolForKey(kEnableC6State, &tmpval6, &bootInfo->bootConfig)&&tmpval6;␊ |
281 | ␊ |
282 | ␉␉if(c6_enabled) c4_enabled = true;␊ |
283 | ␉␉if(c4_enabled) c3_enabled = true;␊ |
284 | ␉␉if(c3_enabled) c2_enabled = true;␊ |
285 | ␊ |
286 | ␉␉if(Platform.CPU.Family == 0x06)␊ |
287 | ␉␉{␊ |
288 | ␉␉␉int intelCPU = Platform.CPU.Model;␊ |
289 | ␉␉␉switch (intelCPU) ␊ |
290 | ␉␉␉{␊ |
291 | ␉␉␉␉case 0x0C:␊ |
292 | ␉␉␉␉␉if (strstr(Platform.CPU.BrandString, "Atom")) goto ncst_atm;␊ |
293 | ␉␉␉␉case 0x0F: // Core (65nm)␊ |
294 | ␉␉␉␉case 0x1A: // Core i7, Xeon 5500 series - Bloomfield, Gainstown NHM-EP - LGA1366 (45nm)␊ |
295 | ␉␉␉␉case 0x1E: // Core i5, i7 - Clarksfield, Lynnfield, Jasper Forest - LGA1156 (45nm)␊ |
296 | ␉␉␉␉case 0x1F: // Core i5, i7 - Nehalem␊ |
297 | ␉␉␉␉case 0x25: // Core i3, i5, i7 - Westmere Client - Clarkdale, Arrandale - LGA1156 (32nm)␊ |
298 | ␉␉␉␉case 0x2C: // Core i7 - Westmere EP - Gulftown - LGA1366 (32nm) 6 Core␊ |
299 | ␉␉␉␉case 0x2E: // Westmere-Ex Xeon␊ |
300 | ␉␉␉␉case 0x2F: // Westmere-Ex Xeon - Eagelton␊ |
301 | ␉␉␉␉␉cstates_count = 1 + (c2_enabled ? 1 : 0) + (c3_enabled ? 1 : 0);␊ |
302 | ␉␉␉␉␉verbose("C-State: Adding %d states: ", cstates_count);␊ |
303 | ␉␉␉␉␉break;␊ |
304 | ␉␉␉␉case 0x1C: // Atom (45nm)␊ |
305 | ␉␉␉␉case 0x26: // Atom Lincroft␊ |
306 | ␉␉␉␉␉ncst_atm:␊ |
307 | ␉␉␉␉␉cstates_count = 1 + (c2_enabled ? 1 : 0) + (c4_enabled ? 1 : 0) + (c6_enabled ? 1 : 0);␊ |
308 | ␉␉␉␉␉verbose("C-State: Adding %d states: ", cstates_count);␊ |
309 | ␉␉␉␉␉break;␊ |
310 | ␉␉␉␉case 0x17:␊ |
311 | ␉␉␉␉␉cstates_count = 1 + (c2_enabled ? 1 : 0) + (c3_enabled ? 1 : 0) + (c4_enabled ? 1 : 0) + (c6_enabled ? 1 : 0);␊ |
312 | ␉␉␉␉␉verbose("C-State: Adding %d states: ", cstates_count);␊ |
313 | ␉␉␉␉␉break;␊ |
314 | ␉␉␉␉default:␊ |
315 | ␉␉␉␉␉cstates_count = 1 + (c2_enabled ? 1 : 0) + (c3_enabled ? 1 : 0) + (c4_enabled ? 1 : 0);␊ |
316 | ␉␉␉␉␉break;␊ |
317 | ␉␉␉}␊ |
318 | ␉␉}␊ |
319 | ␉␉else cstates_count = 1 + (c2_enabled ? 1 : 0) + (c3_enabled ? 1 : 0) + (c4_enabled ? 1 : 0);␊ |
320 | ␉␉␊ |
321 | ␉␉struct aml_chunk* root = aml_create_node(NULL);␊ |
322 | ␉␉aml_add_buffer(root, ssdt_header, sizeof(ssdt_header)); // SSDT header␊ |
323 | ␉␉struct aml_chunk* scop = aml_add_scope(root, "\\_PR_");␊ |
324 | ␊ |
325 | ␉␉struct aml_chunk* name_csd = aml_add_name(scop, "CSD_");␊ |
326 | ␉␉struct aml_chunk* pack_csd = aml_add_package(name_csd);␊ |
327 | ␉␉struct aml_chunk* csd = aml_add_package(pack_csd);␊ |
328 | ␉␉aml_add_byte(csd, 0x05);␊ |
329 | ␉␉aml_add_byte(csd, 0x00);␊ |
330 | ␉␉aml_add_dword(csd, 0x00);␊ |
331 | ␉␉aml_add_dword(csd, 0xfd);␊ |
332 | ␉␉aml_add_dword(csd, Platform.CPU.NoCores);␊ |
333 | ␊ |
334 | ␉␉struct aml_chunk* name = aml_add_name(scop, "CST_");␊ |
335 | ␉␉struct aml_chunk* pack = aml_add_package(name);␊ |
336 | ␉␉aml_add_byte(pack, cstates_count);␊ |
337 | ␉␉struct aml_chunk* tmpl = aml_add_package(pack);␊ |
338 | ␊ |
339 | ␉␉switch (Platform.CPU.Family) {␊ |
340 | ␉␉␉case 0x06: ␊ |
341 | ␉␉␉{␊ |
342 | ␉␉␉␉switch (Platform.CPU.Model) ␊ |
343 | ␉␉␉␉{␊ |
344 | ␉␉␉␉␉case 0x0C:␊ |
345 | ␉␉␉␉␉␉if (strstr(Platform.CPU.BrandString, "Atom")) goto cst_atm;␊ |
346 | ␉␉␉␉␉case 0x0F: // Core (65nm)␊ |
347 | ␉␉␉␉␉case 0x1A: // Core i7, Xeon 5500 series - Bloomfield, Gainstown NHM-EP - LGA1366 (45nm)␊ |
348 | ␉␉␉␉␉case 0x1E: // Core i5, i7 - Clarksfield, Lynnfield, Jasper Forest - LGA1156 (45nm)␊ |
349 | ␉␉␉␉␉case 0x1F: // Core i5, i7 - Nehalem␊ |
350 | ␉␉␉␉␉case 0x25: // Core i3, i5, i7 - Westmere Client - Clarkdale, Arrandale - LGA1156 (32nm)␊ |
351 | ␉␉␉␉␉case 0x2C: // Core i7 - Westmere EP - Gulftown - LGA1366 (32nm) 6 Core␊ |
352 | ␉␉␉␉␉case 0x2E: // Westmere-Ex Xeon␊ |
353 | ␉␉␉␉␉case 0x2F: // Westmere-Ex Xeon - Eagelton␊ |
354 | ␊ |
355 | ␉␉␉␉␉␉␉// C1␊ |
356 | ␉␉␉␉␉␉␉cstate_resource_template[11] = 0x00; // C1-Nehalem␊ |
357 | ␉␉␉␉␉␉␉aml_add_buffer(tmpl, cstate_resource_template, sizeof(cstate_resource_template));␊ |
358 | ␉␉␉␉␉␉␉aml_add_byte(tmpl, 0x01); // C1␊ |
359 | ␉␉␉␉␉␉␉aml_add_byte(tmpl, 0x03); // Latency␊ |
360 | ␉␉␉␉␉␉␉aml_add_word(tmpl, 0x03e8); // Power␊ |
361 | ␉␉␉␉␉␉␉verbose ("C1 ");␊ |
362 | ␊ |
363 | ␉␉␉␉␉␉␉// C2␊ |
364 | ␉␉␉␉␉␉␉if (c2_enabled)␊ |
365 | ␉␉␉␉␉␉␉{␊ |
366 | ␉␉␉␉␉␉␉␉tmpl = aml_add_package(pack);␊ |
367 | ␉␉␉␉␉␉␉␉cstate_resource_template[11] = 0x10; // C3-Nehalem␊ |
368 | ␉␉␉␉␉␉␉␉aml_add_buffer(tmpl, cstate_resource_template, sizeof(cstate_resource_template));␊ |
369 | ␉␉␉␉␉␉␉␉aml_add_byte(tmpl, 0x02); // C2␊ |
370 | ␉␉␉␉␉␉␉␉aml_add_byte(tmpl, 0x14); // Latency␊ |
371 | ␉␉␉␉␉␉␉␉aml_add_word(tmpl, 0x01f4); // Power␊ |
372 | ␉␉␉␉␉␉␉␉verbose ("C3 ");␊ |
373 | ␉␉␉␉␉␉␉}␊ |
374 | ␊ |
375 | ␉␉␉␉␉␉␉// C3␊ |
376 | ␉␉␉␉␉␉␉if (c3_enabled) ␊ |
377 | ␉␉␉␉␉␉␉{␊ |
378 | ␉␉␉␉␉␉␉␉tmpl = aml_add_package(pack);␊ |
379 | ␉␉␉␉␉␉␉␉cstate_resource_template[11] = 0x20; // C6-Nehalem␊ |
380 | ␉␉␉␉␉␉␉␉aml_add_buffer(tmpl, cstate_resource_template, sizeof(cstate_resource_template));␊ |
381 | ␉␉␉␉␉␉␉␉aml_add_byte(tmpl, 0x03); // C3␊ |
382 | ␉␉␉␉␉␉␉␉aml_add_word(tmpl, 0xc8); // Latency␊ |
383 | ␉␉␉␉␉␉␉␉aml_add_word(tmpl, 0x015e); // Power␊ |
384 | ␉␉␉␉␉␉␉␉verbose ("C6");␊ |
385 | ␉␉␉␉␉␉␉}␊ |
386 | ␉␉␉␉␉␉␉//verbose("\n");␊ |
387 | ␊ |
388 | ␉␉␉␉␉␉break;␊ |
389 | ␊ |
390 | ␉␉␉␉␉case 0x1C: // Atom (45nm)␊ |
391 | ␉␉␉␉␉//valv: was 0x26 ??? rely on cpu.c & smbios_patcher.c␊ |
392 | ␉␉␉␉␉case 0x27: // Atom Lincroft␊ |
393 | ␉␉␉␉␉␉␉cst_atm:␊ |
394 | ␉␉␉␉␉␉␉// C1␊ |
395 | ␉␉␉␉␉␉␉cstate_resource_template[11] = 0x00; // C1-Atom␊ |
396 | ␉␉␉␉␉␉␉aml_add_buffer(tmpl, cstate_resource_template, sizeof(cstate_resource_template));␊ |
397 | ␉␉␉␉␉␉␉aml_add_byte(tmpl, 0x01); // C1␊ |
398 | ␉␉␉␉␉␉␉aml_add_byte(tmpl, 0x01); // Latency␊ |
399 | ␉␉␉␉␉␉␉aml_add_word(tmpl, 0x03e8); // Power␊ |
400 | ␉␉␉␉␉␉␉verbose ("C1 ");␊ |
401 | ␊ |
402 | ␉␉␉␉␉␉␉// C2␊ |
403 | ␉␉␉␉␉␉␉if (c2_enabled) ␊ |
404 | ␉␉␉␉␉␉␉{␊ |
405 | ␉␉␉␉␉␉␉␉tmpl = aml_add_package(pack);␊ |
406 | ␉␉␉␉␉␉␉␉cstate_resource_template[11] = 0x10; // C2-Atom␊ |
407 | ␉␉␉␉␉␉␉␉aml_add_buffer(tmpl, cstate_resource_template, sizeof(cstate_resource_template));␊ |
408 | ␉␉␉␉␉␉␉␉aml_add_byte(tmpl, 0x02); // C2␊ |
409 | ␉␉␉␉␉␉␉␉aml_add_byte(tmpl, fadt->P_LVL2_LAT); // Latency␊ |
410 | ␉␉␉␉␉␉␉␉aml_add_word(tmpl, 0x01f4); // Power␊ |
411 | ␉␉␉␉␉␉␉␉verbose ("C2 ");␊ |
412 | ␉␉␉␉␉␉␉}␊ |
413 | ␊ |
414 | ␉␉␉␉␉␉␉// C3␊ |
415 | ␉␉␉␉␉␉␉/*if (c3_enabled)␊ |
416 | ␉␉␉␉␉␉␉{␊ |
417 | ␉␉␉␉␉␉␉␉tmpl = aml_add_package(pack);␊ |
418 | ␉␉␉␉␉␉␉␉cstate_resource_template[11] = 0x20; // C3-Atom␊ |
419 | ␉␉␉␉␉␉␉␉aml_add_buffer(tmpl, cstate_resource_template, sizeof(cstate_resource_template));␊ |
420 | ␉␉␉␉␉␉␉␉aml_add_byte(tmpl, 0x03); // C3␊ |
421 | ␉␉␉␉␉␉␉␉aml_add_word(tmpl, fadt->P_LVL3_LAT); // Latency␊ |
422 | ␉␉␉␉␉␉␉␉aml_add_word(tmpl, 0x015e); // Power␊ |
423 | ␉␉␉␉␉␉␉␉verbose ("C-State: Added C3\n");␊ |
424 | ␉␉␉␉␉␉␉}*/␊ |
425 | ␊ |
426 | ␉␉␉␉␉␉␉// C4␊ |
427 | ␉␉␉␉␉␉␉if (c4_enabled)␊ |
428 | ␉␉␉␉␉␉␉{␊ |
429 | ␉␉␉␉␉␉␉␉tmpl = aml_add_package(pack);␊ |
430 | ␉␉␉␉␉␉␉␉cstate_resource_template[11] = 0x30; // C4-Atom␊ |
431 | ␉␉␉␉␉␉␉␉aml_add_buffer(tmpl, cstate_resource_template, sizeof(cstate_resource_template));␊ |
432 | ␉␉␉␉␉␉␉␉aml_add_byte(tmpl, 0x03); // C4␊ |
433 | ␉␉␉␉␉␉␉␉aml_add_word(tmpl, 0x64); // Latency␊ |
434 | ␉␉␉␉␉␉␉␉aml_add_word(tmpl, 0x00fa); // Power␊ |
435 | ␉␉␉␉␉␉␉␉verbose ("C4 ");␊ |
436 | ␉␉␉␉␉␉␉}␊ |
437 | ␊ |
438 | ␉␉␉␉␉␉␉// C6␊ |
439 | ␉␉␉␉␉␉␉if (c6_enabled)␊ |
440 | ␉␉␉␉␉␉␉{␊ |
441 | ␉␉␉␉␉␉␉␉tmpl = aml_add_package(pack);␊ |
442 | ␉␉␉␉␉␉␉␉cstate_resource_template[11] = 0x40; // C6-Atom␊ |
443 | ␉␉␉␉␉␉␉␉aml_add_buffer(tmpl, cstate_resource_template, sizeof(cstate_resource_template));␊ |
444 | ␉␉␉␉␉␉␉␉aml_add_byte(tmpl, 0x03); // C6␊ |
445 | ␉␉␉␉␉␉␉␉aml_add_word(tmpl, 0xC8); // Latency␊ |
446 | ␉␉␉␉␉␉␉␉aml_add_word(tmpl, 0x0096); // Power␊ |
447 | ␉␉␉␉␉␉␉␉verbose ("C6 ");␊ |
448 | ␉␉␉␉␉␉␉}␊ |
449 | ␉␉␉␉␉␉␉//verbose("\n");␊ |
450 | ␊ |
451 | ␉␉␉␉␉␉break;␊ |
452 | ␊ |
453 | ␉␉␉␉␉case 0x17:␊ |
454 | ␉␉␉␉␉default:␊ |
455 | ␊ |
456 | ␉␉␉␉␉␉␉// C1␊ |
457 | ␉␉␉␉␉␉␉cstate_resource_template[11] = 0x00; // C1␊ |
458 | ␉␉␉␉␉␉␉aml_add_buffer(tmpl, cstate_resource_template, sizeof(cstate_resource_template));␊ |
459 | ␉␉␉␉␉␉␉aml_add_byte(tmpl, 0x01); // C1␊ |
460 | ␉␉␉␉␉␉␉aml_add_byte(tmpl, 0x01); // Latency␊ |
461 | ␉␉␉␉␉␉␉aml_add_word(tmpl, 0x03e8); // Power 1000␊ |
462 | ␉␉␉␉␉␉␉verbose ("C1 ");␊ |
463 | ␊ |
464 | ␉␉␉␉␉␉␉// C2␊ |
465 | ␉␉␉␉␉␉␉if (c2_enabled) ␊ |
466 | ␉␉␉␉␉␉␉{␊ |
467 | ␉␉␉␉␉␉␉␉tmpl = aml_add_package(pack);␊ |
468 | ␉␉␉␉␉␉␉␉cstate_resource_template[11] = 0x10; // C2␊ |
469 | ␉␉␉␉␉␉␉␉aml_add_buffer(tmpl, cstate_resource_template, sizeof(cstate_resource_template));␊ |
470 | ␉␉␉␉␉␉␉␉aml_add_byte(tmpl, 0x02); // C2␊ |
471 | ␉␉␉␉␉␉␉␉aml_add_byte(tmpl, 0x14); // Latency 20␊ |
472 | ␉␉␉␉␉␉␉␉aml_add_word(tmpl, 0x01f4); // Power 500␊ |
473 | ␉␉␉␉␉␉␉␉verbose ("C2 ");␊ |
474 | ␉␉␉␉␉␉␉}␊ |
475 | ␊ |
476 | ␉␉␉␉␉␉␉// C3␊ |
477 | ␉␉␉␉␉␉␉if (c3_enabled) ␊ |
478 | ␉␉␉␉␉␉␉{␊ |
479 | ␉␉␉␉␉␉␉␉tmpl = aml_add_package(pack);␊ |
480 | ␉␉␉␉␉␉␉␉cstate_resource_template[11] = 0x20; // C3␊ |
481 | ␉␉␉␉␉␉␉␉aml_add_buffer(tmpl, cstate_resource_template, sizeof(cstate_resource_template));␊ |
482 | ␉␉␉␉␉␉␉␉aml_add_byte(tmpl, 0x03); // C3␊ |
483 | ␉␉␉␉␉␉␉␉aml_add_word(tmpl, 0x28); // Latency 40␊ |
484 | ␉␉␉␉␉␉␉␉aml_add_word(tmpl, 0x015e); // Power 350␊ |
485 | ␉␉␉␉␉␉␉␉verbose ("C3 ");␊ |
486 | ␉␉␉␉␉␉␉}␊ |
487 | ␊ |
488 | ␉␉␉␉␉␉␉// C4␊ |
489 | ␉␉␉␉␉␉␉if (c4_enabled)␊ |
490 | ␉␉␉␉␉␉␉{␊ |
491 | ␉␉␉␉␉␉␉␉tmpl = aml_add_package(pack);␊ |
492 | ␉␉␉␉␉␉␉␉cstate_resource_template[11] = 0x30; // C4␊ |
493 | ␉␉␉␉␉␉␉␉aml_add_buffer(tmpl, cstate_resource_template, sizeof(cstate_resource_template));␊ |
494 | ␉␉␉␉␉␉␉␉aml_add_byte(tmpl, 0x03); // C4␊ |
495 | ␉␉␉␉␉␉␉␉aml_add_word(tmpl, 0x64); // Latency 100␊ |
496 | ␉␉␉␉␉␉␉␉aml_add_word(tmpl, 0x00fa); // Power 250␊ |
497 | ␉␉␉␉␉␉␉␉verbose ("C4 ");␊ |
498 | ␉␉␉␉␉␉␉}␊ |
499 | ␊ |
500 | ␉␉␉␉␉␉␉// C6␊ |
501 | ␉␉␉␉␉␉␉if (c6_enabled)␊ |
502 | ␉␉␉␉␉␉␉{␊ |
503 | ␉␉␉␉␉␉␉␉tmpl = aml_add_package(pack);␊ |
504 | ␉␉␉␉␉␉␉␉cstate_resource_template[11] = 0x40; // C6␊ |
505 | ␉␉␉␉␉␉␉␉aml_add_buffer(tmpl, cstate_resource_template, sizeof(cstate_resource_template));␊ |
506 | ␉␉␉␉␉␉␉␉aml_add_byte(tmpl, 0x03); // C6␊ |
507 | ␉␉␉␉␉␉␉␉aml_add_word(tmpl, 0xc8); // Latency 200␊ |
508 | ␉␉␉␉␉␉␉␉aml_add_word(tmpl, 0x0096); // Power 150␊ |
509 | ␉␉␉␉␉␉␉␉verbose ("C6");␊ |
510 | ␉␉␉␉␉␉␉}␊ |
511 | ␉␉␉␉␉␉␉//verbose("\n");␊ |
512 | ␊ |
513 | ␉␉␉␉␉␉break;␊ |
514 | ␉␉␉␉}␊ |
515 | ␉␉␉}␊ |
516 | ␉␉}␊ |
517 | ␊ |
518 | ␉␉// Aliaces␊ |
519 | ␉␉int i;␊ |
520 | ␉␉for (i = 0; i < acpi_cpu_count; i++) ␊ |
521 | ␉␉{␊ |
522 | ␉␉␉char name[9];␊ |
523 | ␉␉␉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]);␊ |
524 | ␉␉␉␊ |
525 | ␉␉␉scop = aml_add_scope(root, name);␊ |
526 | ␉␉␉aml_add_alias(scop, "CST_", "_CST");␊ |
527 | ␉␉}␊ |
528 | ␉␉␊ |
529 | ␊ |
530 | ␉␉aml_calculate_size(root);␊ |
531 | ␉␉␊ |
532 | ␉␉struct acpi_2_ssdt *ssdt = (struct acpi_2_ssdt *)AllocateKernelMemory(root->Size);␊ |
533 | ␉␊ |
534 | ␉␉aml_write_node(root, (void*)ssdt, 0);␊ |
535 | ␉␉␊ |
536 | ␉␉ssdt->Length = root->Size;␊ |
537 | ␉␉ssdt->Checksum = 0;␊ |
538 | ␉␉ssdt->Checksum = 256 - checksum8(ssdt, ssdt->Length);␊ |
539 | ␊ |
540 | ␉␉verbose (" @ %x\n", ssdt);␊ |
541 | ␉␉aml_destroy_node(root);␊ |
542 | ␉␉␊ |
543 | ␉␉//dumpPhysAddr("C-States SSDT content: ", ssdt, ssdt->Length);␊ |
544 | ␉␉␊ |
545 | ␉␉return ssdt;␊ |
546 | ␉}␊ |
547 | ␉else ␊ |
548 | ␉{␊ |
549 | ␉␉verbose ("C-States: ACPI CPUs not found !!!\n");␊ |
550 | ␉}␊ |
551 | ␊ |
552 | ␉return NULL;␊ |
553 | }␊ |
554 | ␊ |
555 | uint8_t mV_to_VID(uint16_t mv) {␊ |
556 | ␉if (Platform.CPU.Vendor == 0x756E6547)␊ |
557 | ␉{␊ |
558 | ␉␉if ((Platform.CPU.Family == 0x06) && (Platform.CPU.Model == 0x17))␊ |
559 | ␉␉␉return ((mv * 10) - 7125) / 125;␊ |
560 | ␉␉else␊ |
561 | ␉␉␉return (mv - 700) / 16;␊ |
562 | ␉}␊ |
563 | ␉return 0;␊ |
564 | }␊ |
565 | ␊ |
566 | uint16_t VID_to_mV(uint8_t VID) {␊ |
567 | ␉if (Platform.CPU.Vendor == 0x756E6547)␊ |
568 | ␉{␊ |
569 | ␉␉if ((Platform.CPU.Family == 0x06) && (Platform.CPU.Model == 0x17))␊ |
570 | ␉␉␉return (((int)VID * 125) + 7125) / 10;␊ |
571 | ␉␉else␊ |
572 | ␉␉␉return (((int)VID * 16) + 700);␊ |
573 | ␉}␊ |
574 | ␉return 0;␊ |
575 | }␊ |
576 | ␊ |
577 | struct acpi_2_ssdt *generate_pss_ssdt(struct acpi_2_dsdt* dsdt)␊ |
578 | {␊ |
579 | ␉char ssdt_header[] =␊ |
580 | ␉{␊ |
581 | ␉␉0x53, 0x53, 0x44, 0x54, 0x7E, 0x00, 0x00, 0x00, /* SSDT.... */␊ |
582 | ␉␉0x01, 0x6A, 0x50, 0x6D, 0x52, 0x65, 0x66, 0x00, /* ..PmRef. */␊ |
583 | ␉␉0x43, 0x70, 0x75, 0x50, 0x6D, 0x00, 0x00, 0x00, /* CpuPm... */␊ |
584 | ␉␉0x00, 0x30, 0x00, 0x00, 0x49, 0x4E, 0x54, 0x4C, /* .0..INTL */␊ |
585 | ␉␉0x31, 0x03, 0x10, 0x20,␉␉␉␉␉␉␉/* 1.._␉␉*/␊ |
586 | ␉};␊ |
587 | ␉␊ |
588 | ␉char ssdt_pct[] =␊ |
589 | ␉{␊ |
590 | ␉␉0x08, 0x5F, 0x50, 0x43, 0x54, 0x12, 0x2C, 0x02,␉/* 0._PCT., */␊ |
591 | ␉␉0x11, 0x14, 0x0A, 0x11, 0x82, 0x0C, 0x00, 0x7F,␉/* ........ */␊ |
592 | ␉␉0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* ........ */␊ |
593 | ␉␉0x00, 0x00, 0x00, 0x79, 0x00, 0x11, 0x14, 0x0A, /* ....y... */␊ |
594 | ␉␉0x11, 0x82, 0x0C, 0x00, 0x7F, 0x00, 0x00, 0x00, /* ........ */␊ |
595 | ␉␉0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* ........ */␊ |
596 | ␉␉0x79, 0x00␊ |
597 | ␉};␊ |
598 | ␊ |
599 | ␉if (Platform.CPU.Vendor != 0x756E6547) {␊ |
600 | ␉␉verbose ("P-States: Not an Intel platform !!!\n");␊ |
601 | ␉␉return NULL;␊ |
602 | ␉}␊ |
603 | ␉␊ |
604 | ␉if (!(platformCPUFeature(CPU_FEATURE_MSR))) {␊ |
605 | ␉␉verbose ("P-States: Unsupported CPU !!!\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 | ␉␉␊ |
615 | ␉␉struct p_state initial, maximum, minimum, p_states[32];␊ |
616 | ␉␉uint8_t p_states_count = 0;␊ |
617 | ␊ |
618 | ␉␉//TODO: make use of minimum & friends instead, (busratios, freqs ...)␊ |
619 | ␉␉int busratio_min = Platform.CPU.MinRatio;␊ |
620 | ␉␉int busratio_max = Platform.CPU.MaxRatio;␊ |
621 | ␉␉␊ |
622 | ␉␉int freq_max = ((Platform.CPU.FSBFrequency / 1000000) * busratio_max) / 10;␊ |
623 | ␉␉int freq_min = ((Platform.CPU.FSBFrequency / 1000000) * busratio_min) / 10;␊ |
624 | ␉␉int p = ((busratio_max - busratio_min) * 2) / 10;␊ |
625 | ␉␉int f_step = (freq_max - freq_min) / p;␊ |
626 | ␉␉if (Platform.CPU.SLFM) freq_min = (busratio_min * f_step) / 10;␊ |
627 | ␉␉freq_max = (((Platform.CPU.FSBFrequency / 1000000) + 1) * busratio_max) / 10;␊ |
628 | ␊ |
629 | ␉␉//valv: minimum instead of current␊ |
630 | ␉␉//initial.Control = rdmsr64(MSR_IA32_PERF_STATUS);␊ |
631 | ␉␉initial.Control = ((rdmsr64(MSR_IA32_PERF_STATUS) >> 48) & 0x1F3F);␊ |
632 | ␉␉maximum.Control = ((rdmsr64(MSR_IA32_PERF_STATUS) >> 32) & 0x1F3F) | (0x4000 * Platform.CPU.MaxDiv);␊ |
633 | ␊ |
634 | ␉␉maximum.FID = (busratio_max / 0xA) & 0x1F | (0x40 * Platform.CPU.MaxDiv);␊ |
635 | ␉␉maximum.CID = ((maximum.FID & 0x1F) << 1) | Platform.CPU.MaxDiv;␊ |
636 | ␉␉␊ |
637 | ␉␉// current isn't always minimum␊ |
638 | ␉␉//minimum.FID = ((rdmsr64(MSR_IA32_PERF_STATUS) >> 24) & 0x1F) | (0x80 * cpu_dynamic_fsb);␊ |
639 | ␉␉minimum.FID = ((rdmsr64(MSR_IA32_PERF_STATUS) >> 56) & 0x1F) | (0x80 * Platform.CPU.SLFM);␊ |
640 | ␉␉// this may not be valid when slfm (did) is enabled. Rely on vmin instead␊ |
641 | ␉␉minimum.VID = ((rdmsr64(MSR_IA32_PERF_STATUS) >> 48) & 0x3F);␊ |
642 | ␊ |
643 | ␉␉int umaxVolt, uminVolt, moreVolt, lessVolt, vstate;␊ |
644 | ␉␉int maxVolt_limit = VID_to_mV(maximum.VID) + 250;␊ |
645 | ␉␉int minVolt_limit = VID_to_mV(minimum.VID) - 250;␊ |
646 | ␉␉uint8_t vstep = 0;␊ |
647 | ␊ |
648 | ␉␉if((getIntForKey(kmaxVoltage, &umaxVolt, &bootInfo->bootConfig)) && (umaxVolt <= maxVolt_limit))␊ |
649 | ␉␉{␊ |
650 | ␉␉␉uint8_t vmax = mV_to_VID(umaxVolt);␊ |
651 | ␉␉␉maximum.Control = (((busratio_max / 0xA) & 0x1F) * 0x100 | vmax) | (0x4000 * Platform.CPU.MaxDiv);␊ |
652 | ␉␉␉maximum.VID = vmax & 0x3F;␊ |
653 | ␉␉}␊ |
654 | ␉␉if((getIntForKey(kminVoltage, &uminVolt, &bootInfo->bootConfig)) && (uminVolt >= minVolt_limit))␊ |
655 | ␉␉{␊ |
656 | ␉␉␉uint8_t vmin = mV_to_VID(uminVolt);␊ |
657 | ␉␉␉minimum.VID = vmin & 0x3F;␊ |
658 | ␉␉}␊ |
659 | ␉␉␊ |
660 | ␉␉if (minimum.FID == 0) ␊ |
661 | ␉␉{␊ |
662 | ␉␉␉uint64_t msr;␊ |
663 | ␉␉␉uint8_t i;␊ |
664 | ␉␉␉// Probe for lowest fid␊ |
665 | ␉␉␉// this is for requested FID, and not forcibly the lowest␊ |
666 | ␉␉␉for (i = maximum.FID; i >= 0x6; i--)␊ |
667 | ␉␉␉{␊ |
668 | ␉␉␉␉msr = rdmsr64(MSR_IA32_PERF_CONTROL);␊ |
669 | ␉␉␉␉wrmsr64(MSR_IA32_PERF_CONTROL, (msr & 0xFFFFFFFFFFFF0000ULL) | (i << 8) | minimum.VID);␊ |
670 | ␉␉␉␉intel_waitforsts();␊ |
671 | ␉␉␉␉minimum.FID = (rdmsr64(MSR_IA32_PERF_STATUS) >> 8) & 0x1F; ␊ |
672 | ␉␉␉␉delay(1);␊ |
673 | ␉␉␉}␊ |
674 | ␊ |
675 | ␉␉␉msr = rdmsr64(MSR_IA32_PERF_CONTROL);␊ |
676 | ␉␉␉wrmsr64(MSR_IA32_PERF_CONTROL, (msr & 0xFFFFFFFFFFFF0000ULL) | (maximum.FID << 8) | maximum.VID);␊ |
677 | ␉␉␉intel_waitforsts();␊ |
678 | ␉␉}␊ |
679 | ␊ |
680 | ␉␉if (minimum.VID == maximum.VID) ␊ |
681 | ␉␉{␉␊ |
682 | ␉␉␉uint64_t msr;␊ |
683 | ␉␉␉uint8_t i;␊ |
684 | ␉␉␉// Probe for lowest vid␊ |
685 | ␉␉␉for (i = maximum.VID; i > 0xA; i--) ␊ |
686 | ␉␉␉{␊ |
687 | ␉␉␉␉msr = rdmsr64(MSR_IA32_PERF_CONTROL);␊ |
688 | ␉␉␉␉wrmsr64(MSR_IA32_PERF_CONTROL, (msr & 0xFFFFFFFFFFFF0000ULL) | (minimum.FID << 8) | i);␊ |
689 | ␉␉␉␉intel_waitforsts();␊ |
690 | ␉␉␉␉minimum.VID = rdmsr64(MSR_IA32_PERF_STATUS) & 0x3F;␊ |
691 | ␉␉␉␉delay(1);␊ |
692 | ␉␉␉}␊ |
693 | ␊ |
694 | ␉␉␉msr = rdmsr64(MSR_IA32_PERF_CONTROL);␊ |
695 | ␉␉␉wrmsr64(MSR_IA32_PERF_CONTROL, (msr & 0xFFFFFFFFFFFF0000ULL) | (maximum.FID << 8) | maximum.VID);␊ |
696 | ␉␉␉intel_waitforsts();␊ |
697 | ␉␉}␊ |
698 | ␊ |
699 | ␉␉minimum.CID = ((minimum.FID & 0x1F) << 1) >> Platform.CPU.SLFM;␊ |
700 | ␊ |
701 | ␉␉// Sanity check␊ |
702 | ␉␉if (maximum.CID < minimum.CID)␊ |
703 | ␉␉{␊ |
704 | ␉␉␉DBG("P-States: Insane FID values!");␊ |
705 | ␉␉␉p_states_count = 1;␊ |
706 | ␉␉}␊ |
707 | ␉␉else␊ |
708 | ␉␉{␊ |
709 | ␉␉␉// Print the voltage to be used␊ |
710 | ␉␉␉int minVoltage = VID_to_mV(minimum.VID);␊ |
711 | ␉␉␉int maxVoltage = VID_to_mV(maximum.VID);␊ |
712 | ␉␉␉verbose("Voltage: min= %dmV, max= %dmV\n", minVoltage, maxVoltage);␊ |
713 | ␊ |
714 | ␉␉␉// Finalize P-States␊ |
715 | ␉␉␉// Find how many P-States machine supports␊ |
716 | ␉␉␉␊ |
717 | ␉␉␉p_states_count = maximum.CID - minimum.CID + 1;␊ |
718 | ␉␉␉␊ |
719 | ␉␉␉if (p_states_count > 32) ␊ |
720 | ␉␉␉␉p_states_count = 32;␊ |
721 | ␉␉␊ |
722 | ␉␉␉uint8_t vidstep;␊ |
723 | ␉␉␉uint8_t i = 0, u, invalid = 0;␊ |
724 | ␊ |
725 | ␉␉␉vidstep = ((maximum.VID << 2) - (minimum.VID << 2)) / (p_states_count - 1);␊ |
726 | ␉␉␉for (u = 0; u < p_states_count; u++) ␊ |
727 | ␉␉␉{␊ |
728 | ␉␉␉␉i = u - invalid;␊ |
729 | ␉␉␉␉␊ |
730 | ␉␉␉␉p_states[i].CID = maximum.CID - u;␊ |
731 | ␉␉␉␉p_states[i].FID = (p_states[i].CID >> 1);␊ |
732 | ␊ |
733 | ␉␉␉␉if (i && p_states[i].FID < 0x6)␊ |
734 | ␉␉␉␉{␊ |
735 | ␉␉␉␉␉if (Platform.CPU.SLFM)␊ |
736 | ␉␉␉␉␉{␊ |
737 | ␉␉␉␉␉␉p_states[i].FID = (p_states[i].FID << 1) | 0x80;␊ |
738 | ␉␉␉␉␉}␊ |
739 | ␉␉␉␉␉// intel doesn't allow FIDs lower that 6 on core, core2 and eventually core-i␊ |
740 | ␉␉␉␉␉else invalid++;␊ |
741 | ␉␉␉␉}␊ |
742 | ␊ |
743 | ␉␉␉␉// 6.5 isn't selectable␊ |
744 | ␉␉␉␉else if (Platform.CPU.MaxDiv && p_states[i].FID > 0x6)␊ |
745 | ␉␉␉␉{␊ |
746 | ␉␉␉␉␉// first state only!?␊ |
747 | ␉␉␉␉␉//p_states[0].FID = p_states[0].FID | (0x40 * (p_states[0].CID & 0x1));␊ |
748 | ␉␉␉␉␉p_states[i].FID = p_states[i].FID | (0x40 * (p_states[i].CID & 0x1));␊ |
749 | ␉␉␉␉}␊ |
750 | ␉␉␉␉␊ |
751 | ␉␉␉␉if (i && p_states[i].FID == p_states[i-1].FID)␊ |
752 | ␉␉␉␉␉invalid++;␊ |
753 | ␉␉␉␉␊ |
754 | ␉␉␉␉p_states[i].VID = ((maximum.VID << 2) - (vidstep * u)) >> 2;␊ |
755 | ␊ |
756 | ␉␉␉␉if(getIntForKey(klessVoltage, &lessVolt, &bootInfo->bootConfig))␊ |
757 | ␉␉␉␉{␊ |
758 | ␉␉␉␉␉vstate = (VID_to_mV(p_states[i].VID)) - lessVolt;␊ |
759 | ␉␉␉␉␉vstep = mV_to_VID(vstate);␊ |
760 | ␉␉␉␉␉p_states[i].VID = vstep & 0x3F;␊ |
761 | ␉␉␉␉}␊ |
762 | ␉␉␉␉else if(getIntForKey(kmoreVoltage, &moreVolt, &bootInfo->bootConfig))␊ |
763 | ␉␉␉␉{␊ |
764 | ␉␉␉␉␉vstate = (VID_to_mV(p_states[i].VID)) + moreVolt;␊ |
765 | ␉␉␉␉␉vstep = mV_to_VID(vstate);␊ |
766 | ␉␉␉␉␉p_states[i].VID = vstep & 0x3F;␊ |
767 | ␉␉␉␉}␊ |
768 | ␊ |
769 | ␉␉␉␉uint32_t multiplier = p_states[i].FID & 0x1f;␉␉// = 0x08␊ |
770 | ␉␉␉␉bool half = p_states[i].FID & 0x40;␉␉␉␉␉// = 0x01␊ |
771 | ␉␉␉␉bool dfsb = p_states[i].FID & 0x80;␉␉␉␉␉// = 0x00␊ |
772 | ␉␉␉␉uint32_t fsb = Platform.CPU.FSBFrequency / 1000000; // = 400␊ |
773 | ␉␉␉␉uint32_t halffsb = (fsb + 1) >> 1;␉␉␉␉␉// = 200␊ |
774 | ␉␉␉␉uint32_t frequency = (multiplier * fsb);␉␉␉// = 3200␊ |
775 | ␊ |
776 | ␉␉␉␉p_states[i].Frequency = (frequency + (half * halffsb)) >> dfsb;␉// = 3200 + 200 = 3400␊ |
777 | ␉␉␉}␊ |
778 | ␉␉␉p_states_count -= invalid;␊ |
779 | ␉␉}␊ |
780 | ␉␉␊ |
781 | ␉␉//valv: Silly! Isn't it? :)␊ |
782 | ␉␉int pstates = 0;␊ |
783 | ␉␉if (getIntForKey(kpstates, &pstates, &bootInfo->bootConfig) && pstates < p_states_count && pstates > 0)␊ |
784 | ␉␉{␊ |
785 | ␉␉␉verbose("P-State: Only the %d highest states will be added\n", pstates);␊ |
786 | ␉␉␉pstates = pstates - 1;␊ |
787 | ␉␉}␊ |
788 | ␊ |
789 | ␉␉int pstart = 0;␊ |
790 | ␉␉if (getIntForKey(kpstart, &pstart, &bootInfo->bootConfig) && pstart < p_states_count && pstart > 0)␊ |
791 | ␉␉{␊ |
792 | ␉␉␉const char *newratio;␊ |
793 | ␉␉␉int len;␊ |
794 | ␉␉␉if (getValueForKey(kbusratio, &newratio, &len, &bootInfo->bootConfig))␊ |
795 | ␉␉␉{␊ |
796 | ␉␉␉␉verbose("P-State: Already using bus-ratio injection! PStart key will have no effect.\n");␊ |
797 | ␉␉␉␉pstart = 0;␊ |
798 | ␉␉␉}␊ |
799 | ␉␉␉else verbose("P-State: Starting from state P%d\n", pstart);␊ |
800 | ␉␉}␊ |
801 | ␉␉␊ |
802 | ␉␉// Generating SSDT␊ |
803 | ␉␉if (p_states_count > 0)␊ |
804 | ␉␉{␉␊ |
805 | ␉␉␉int i;␊ |
806 | ␉␉␉//valv: fix p-states number issue on some models.␊ |
807 | ␉␉␉verbose("Model detected: %s\n", MacProduct);␊ |
808 | ␉␉␉if(!strstr(MacProduct, "applemac2010"))␊ |
809 | ␉␉␉{␊ |
810 | ␉␉␉␉if(strstr(MacProduct, "MacBookPro4,1") && ((p_states_count > 9) && ((pstart == 0) && (pstates == 0)))) pstates = 8;␊ |
811 | ␉␉␉␉if(strstr(MacProduct, "MacBookAir1,1") && ((p_states_count > 4) && ((pstart == 0) && (pstates == 0)))) pstates = 3;␊ |
812 | ␉␉␉}␊ |
813 | ␉␉␉␊ |
814 | ␉␉␉struct aml_chunk* root = aml_create_node(NULL);␊ |
815 | ␉␉␉aml_add_buffer(root, ssdt_header, sizeof(ssdt_header)); // SSDT header␊ |
816 | ␉␉␉struct aml_chunk* scop = aml_add_scope(root, "\\_PR_");␊ |
817 | ␉␉␉␊ |
818 | ␉␉␉aml_add_buffer(scop, ssdt_pct, sizeof(ssdt_pct));␊ |
819 | ␉␉␉␊ |
820 | ␉␉␉struct aml_chunk* name_psd = aml_add_name(scop, "PSD_");␊ |
821 | ␉␉␉struct aml_chunk* pack_psd = aml_add_package(name_psd);␊ |
822 | ␉␉␉struct aml_chunk* psd = aml_add_package(pack_psd);␊ |
823 | ␉␉␉aml_add_byte(psd, 0x05);␊ |
824 | ␉␉␉aml_add_byte(psd, 0x00);␊ |
825 | ␉␉␉aml_add_dword(psd, 0x00);␊ |
826 | ␉␉␉aml_add_dword(psd, 0xfd);␊ |
827 | ␉␉␉aml_add_dword(psd, Platform.CPU.NoCores);␊ |
828 | ␉␉␉␊ |
829 | ␉␉␉struct aml_chunk* name_pss = aml_add_name(scop, "PSS_");␊ |
830 | ␉␉␉struct aml_chunk* pack_pss = aml_add_package(name_pss);␊ |
831 | ␊ |
832 | ␉␉␉uint8_t p_states_num = 0;␊ |
833 | ␉␉␉for (i = pstart; i < p_states_count; i++)␊ |
834 | ␉␉␉{␊ |
835 | ␉␉␉␉if ((p_states[i].Frequency <= freq_max) && (p_states[i].Frequency >= freq_min))␊ |
836 | ␉␉␉␉{␊ |
837 | ␉␉␉␉␉//valv: inspired from cparm's pss-drop; coded by me ;)␊ |
838 | ␉␉␉␉␉if ((i > pstates) && (pstates > 0))␊ |
839 | ␉␉␉␉␉{␊ |
840 | ␉␉␉␉␉␉if(Platform.CPU.ISerie) verbose("P-State: [Frequency %d MHz\tFID 0x%x] is the %dth state. Removed!\n",␊ |
841 | ␉␉␉␉␉␉␉␉p_states[i].Frequency, p_states[i].FID, (i+1));␊ |
842 | ␉␉␉␉␉␉else verbose("P-State: [Frequency %d MHz\tFID 0x%x \tVID 0x%x] is the %dth state. Removed!\n",␊ |
843 | ␉␉␉␉␉␉␉␉p_states[i].Frequency, p_states[i].FID, p_states[i].VID, (i+1));␊ |
844 | ␉␉␉␉␉}␊ |
845 | ␉␉␉␉␉else␊ |
846 | ␉␉␉␉␉{␊ |
847 | ␉␉␉␉␉␉struct aml_chunk* pstt = aml_add_package(pack_pss);␊ |
848 | ␊ |
849 | ␉␉␉␉␉␉aml_add_dword(pstt, p_states[i].Frequency);␊ |
850 | ␉␉␉␉␉␉aml_add_dword(pstt, 0x00000000); // Power␊ |
851 | ␉␉␉␉␉␉aml_add_dword(pstt, 0x0000000A); // Latency␊ |
852 | ␉␉␉␉␉␉aml_add_dword(pstt, 0x0000000A); // Latency␊ |
853 | ␉␉␉␉␉␉if(Platform.CPU.ISerie)␊ |
854 | ␉␉␉␉␉␉{␊ |
855 | ␉␉␉␉␉␉␉aml_add_dword(pstt, p_states[i].FID);␊ |
856 | ␉␉␉␉␉␉␉aml_add_dword(pstt, p_states[i].FID);␊ |
857 | ␉␉␉␉␉␉␉verbose("P-State: Added [Frequency %d MHz\tFID 0x%x]\n", p_states[i].Frequency, p_states[i].FID);␊ |
858 | ␉␉␉␉␉␉}␊ |
859 | ␉␉␉␉␉␉else␊ |
860 | ␉␉␉␉␉␉{␊ |
861 | ␉␉␉␉␉␉␉aml_add_dword(pstt, p_states[i].Control);␊ |
862 | ␉␉␉␉␉␉␉aml_add_dword(pstt, p_states[i].Control);␊ |
863 | ␉␉␉␉␉␉␉//aml_add_dword(pstt, i+1); // Status␊ |
864 | ␉␉␉␉␉␉␉verbose("P-State: Added [Frequency %d MHz\tFID 0x%x \tVID 0x%x]\n",␊ |
865 | ␉␉␉␉␉␉␉␉p_states[i].Frequency, p_states[i].FID, p_states[i].VID);␊ |
866 | ␉␉␉␉␉␉}␊ |
867 | ␉␉␉␉␉␉p_states_num++;␊ |
868 | ␉␉␉␉␉}␊ |
869 | ␉␉␉␉}␊ |
870 | ␉␉␉␉else␊ |
871 | ␉␉␉␉{␊ |
872 | ␉␉␉␉␉if(Platform.CPU.ISerie) verbose("P-State: [Frequency %d MHz\tFID 0x%x] is over the limit. Removed!\n",␊ |
873 | ␉␉␉␉␉␉␉p_states[i].Frequency, p_states[i].FID);␊ |
874 | ␉␉␉␉␉else verbose("P-State: [Frequency %d MHz\tFID 0x%x \tVID 0x%x] is over the limit. Removed!\n",␊ |
875 | ␉␉␉␉␉␉␉p_states[i].Frequency, p_states[i].FID, p_states[i].VID);␊ |
876 | ␉␉␉␉}␊ |
877 | ␉␉␉}␊ |
878 | ␉␉␉␊ |
879 | ␉␉␉struct aml_chunk* name_ppc = aml_add_name(scop, "PPC_");␊ |
880 | ␉␉␉aml_add_byte(name_ppc, 0x00);␊ |
881 | ␉␉␉␊ |
882 | ␉␉␉// Add aliaces␊ |
883 | ␉␉␉for (i = 0; i < acpi_cpu_count; i++) ␊ |
884 | ␉␉␉{␊ |
885 | ␉␉␉␉char name[9];␊ |
886 | ␉␉␉␉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]);␊ |
887 | ␉␉␉␉␊ |
888 | ␉␉␉␉scop = aml_add_scope(root, name);␊ |
889 | ␉␉␉␉aml_add_alias(scop, "PCT_", "_PCT");␊ |
890 | ␉␉␉␉aml_add_alias(scop, "PSD_", "_PSD");␊ |
891 | ␉␉␉␉aml_add_alias(scop, "PSS_", "_PSS");␊ |
892 | ␉␉␉␉aml_add_alias(scop, "PPC_", "_PPC");␊ |
893 | ␉␉␉}␊ |
894 | ␉␉␉␊ |
895 | ␉␉␉aml_calculate_size(root);␊ |
896 | ␉␉␉␊ |
897 | ␉␉␉struct acpi_2_ssdt *ssdt = (struct acpi_2_ssdt *)AllocateKernelMemory(root->Size);␊ |
898 | ␉␉␉␊ |
899 | ␉␉␉aml_write_node(root, (void*)ssdt, 0);␊ |
900 | ␉␉␉␊ |
901 | ␉␉␉ssdt->Length = root->Size;␊ |
902 | ␉␉␉ssdt->Checksum = 0;␊ |
903 | ␉␉␉ssdt->Checksum = 256 - checksum8(ssdt, ssdt->Length);␊ |
904 | ␉␉␉␊ |
905 | ␉␉␉verbose ("P-States: %d states were succefully generated @ %x\n", p_states_num, ssdt);␊ |
906 | ␉␉␉aml_destroy_node(root);␊ |
907 | ␉␉␉␊ |
908 | ␉␉␉return ssdt;␊ |
909 | ␉␉}␊ |
910 | ␉}␊ |
911 | ␉else {␊ |
912 | ␉␉verbose ("P-States: ACPI CPUs not found !!!\n");␊ |
913 | ␉}␊ |
914 | ␉␊ |
915 | ␉return NULL;␊ |
916 | }␊ |
917 | ␊ |
918 | struct acpi_2_ssdt *generate_tss_ssdt(struct acpi_2_fadt* fadt)␊ |
919 | {␊ |
920 | ␉char ssdt_header[] =␊ |
921 | ␉{␊ |
922 | 0x53, 0x53, 0x44, 0x54, 0xE7, 0x00, 0x00, 0x00,␊ |
923 | 0x01, 0x17, 0x50, 0x6D, 0x52, 0x65, 0x66, 0x42,␊ |
924 | 0x43, 0x70, 0x75, 0x54, 0x73, 0x74, 0x00, 0x00,␊ |
925 | 0x00, 0x10, 0x00, 0x00, 0x49, 0x4E, 0x54, 0x4C,␊ |
926 | 0x31, 0x03, 0x10, 0x20␊ |
927 | ␉};␊ |
928 | ␉␊ |
929 | ␉char ssdt_ptc[] =␊ |
930 | ␉{␊ |
931 | ␉␉0x08, 0x5F, 0x50, 0x54, 0x43, 0x12, 0x2C, 0x02,␊ |
932 | ␉␉0x11, 0x14, 0x0A, 0x11, 0x82, 0x0C, 0x00, 0x7F,␊ |
933 | ␉␉0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,␊ |
934 | ␉␉0x00, 0x00, 0x00, 0x79, 0x00, 0x11, 0x14, 0x0A,␊ |
935 | ␉␉0x11, 0x82, 0x0C, 0x00, 0x7F, 0x00, 0x00, 0x00,␊ |
936 | ␉␉0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,␊ |
937 | ␉␉0x79, 0x00␊ |
938 | ␉};␊ |
939 | ␉␊ |
940 | ␉if (Platform.CPU.Vendor != 0x756E6547) {␊ |
941 | ␉␉verbose ("T-States: Not an Intel platform !!!\n");␊ |
942 | ␉␉return NULL;␊ |
943 | ␉}␊ |
944 | ␉␊ |
945 | ␉if (!(platformCPUFeature(CPU_FEATURE_MSR))) {␊ |
946 | ␉␉verbose ("T-States: Unsupported CPU !!!\n");␊ |
947 | ␉␉return NULL;␊ |
948 | ␉}␊ |
949 | ␉␊ |
950 | ␉if (fadt == NULL) {␊ |
951 | ␉␉verbose ("FACP not found: T-States will not be generated !!!\n");␊ |
952 | ␉␉return NULL;␊ |
953 | ␉}␊ |
954 | ␉␊ |
955 | ␉struct acpi_2_dsdt* dsdt = (void*)fadt->DSDT;␊ |
956 | ␉␊ |
957 | ␉if (dsdt == NULL) {␊ |
958 | ␉␉verbose ("T-States: DSDT not found !!!\n");␊ |
959 | ␉␉return NULL;␊ |
960 | ␉}␊ |
961 | ␊ |
962 | ␉if (acpi_cpu_count == 0)␊ |
963 | ␉␉get_acpi_cpu_names((void*)dsdt, dsdt->Length);␊ |
964 | ␉␊ |
965 | ␉if (acpi_cpu_count > 0)␊ |
966 | ␉{␊ |
967 | ␉␉␊ |
968 | ␉␉struct t_state t_states[32];␊ |
969 | ␉␉uint8_t t_states_count = 0, ctrl0 = 0x10, j = 0x01;␊ |
970 | ␉␉int i, step;␊ |
971 | ␉␉uint64_t msr;␊ |
972 | ␉␉uint32_t ext_mod; // *ret = 0;␊ |
973 | ␉␉␊ |
974 | ␉␉do_cpuid(6, Platform.CPU.CPUID[CPUID_81]);␊ |
975 | ␉␉ext_mod = bitfield(Platform.CPU.CPUID[CPUID_81][0], 5, 5);␊ |
976 | ␉␉␊ |
977 | ␉␉if(ext_mod == 1)␊ |
978 | ␉␉{␊ |
979 | ␉␉␉verbose("T-States: Unsupported CPU !!!\n");␊ |
980 | ␉␉␉return NULL;␊ |
981 | ␉␉}␊ |
982 | ␉␉␊ |
983 | ␉␉msr = rdmsr64(MSR_IA32_CLOCK_MODULATION);␊ |
984 | ␉␉t_states_count = msr & 0xE;␊ |
985 | ␊ |
986 | ␉␉//if(!fadt->DUTY_WIDTH)␊ |
987 | ␉␉if(t_states_count == 0)␊ |
988 | ␉␉{␊ |
989 | ␉␉␉verbose("T-States: Unsupported CPU !!!\n");␊ |
990 | ␉␉␉return NULL;␊ |
991 | ␉␉}␊ |
992 | /*␉␉␊ |
993 | ␉␉verbose("T-States: duty_offset=%d, duty_width=%d\n", fadt->DUTY_OFFSET, fadt->DUTY_WIDTH);␊ |
994 | ␉␉uint8_t duty_cycle = fadt->DUTY_WIDTH + fadt->DUTY_OFFSET;␊ |
995 | ␉␉␊ |
996 | ␉␉if(duty_cycle > 4)␊ |
997 | ␉␉{␊ |
998 | ␉␉␉verbose("T-States: Spanning bit 4\n");␊ |
999 | ␉␉␉for (i=2; i<21; i++)␊ |
1000 | ␉␉␉{␊ |
1001 | ␉␉␉␉if(duty_cycle > 4)␊ |
1002 | ␉␉␉␉{␊ |
1003 | ␉␉␉␉␉verbose("duty_cycle: %d\n", duty_cycle);␊ |
1004 | ␉␉␉␉␉sleep(i);␊ |
1005 | ␉␉␉␉␉i++;␊ |
1006 | ␉␉␉␉}␊ |
1007 | ␉␉␉␉//return NULL;␊ |
1008 | ␉␉␉␉else␊ |
1009 | ␉␉␉␉{␊ |
1010 | ␉␉␉␉␉t_states_count = 8;␊ |
1011 | ␉␉␉␉␉goto nrx;␊ |
1012 | ␉␉␉␉}␊ |
1013 | ␉␉␉}␊ |
1014 | ␉␉}␊ |
1015 | ␉␉else t_states_count = 1 << fadt->DUTY_WIDTH;␊ |
1016 | ␉␉␊ |
1017 | ␉␉nrx:␊ |
1018 | */␊ |
1019 | ␉␉step = (1000 / t_states_count);␊ |
1020 | ␉␉for (i = 1; i < t_states_count; i++)␊ |
1021 | ␉␉{␊ |
1022 | ␉␉␉t_states[i].perf = (1000 - (step * i)) / 10;␊ |
1023 | ␉␉␉t_states[i].pwer = 1000 - (step * i);␊ |
1024 | ␉␉␉t_states[i].ctrl = ctrl0 - j;␊ |
1025 | ␉␉␉j++;␊ |
1026 | ␉␉}␊ |
1027 | ␊ |
1028 | ␉␉// Generating SSDT␊ |
1029 | ␉␉if (t_states_count > 0)␊ |
1030 | ␉␉{␊ |
1031 | ␉␉␉struct aml_chunk* root = aml_create_node(NULL);␊ |
1032 | ␉␉␉aml_add_buffer(root, ssdt_header, sizeof(ssdt_header)); // SSDT header␊ |
1033 | ␉␉␉struct aml_chunk* scop = aml_add_scope(root, "\\_PR_");␊ |
1034 | ␊ |
1035 | ␉␉␉struct aml_chunk* name_tpc = aml_add_name(scop, "TPC_");␊ |
1036 | ␉␉␉aml_add_byte(name_tpc, 0x00);␊ |
1037 | ␊ |
1038 | ␉␉␉aml_add_buffer(scop, ssdt_ptc, sizeof(ssdt_ptc));␊ |
1039 | ␊ |
1040 | ␉␉␉struct aml_chunk* name_tss = aml_add_name(scop, "TSS_");␊ |
1041 | ␉␉␉struct aml_chunk* pack_tss = aml_add_package(name_tss);␊ |
1042 | ␊ |
1043 | ␉␉␉struct aml_chunk* tssp0 = aml_add_package(pack_tss);␊ |
1044 | ␉␉␉aml_add_dword(tssp0, 0x64);␉␉// Frequency %␊ |
1045 | ␉␉␉aml_add_dword(tssp0, 0x03E8);␉// Power␊ |
1046 | ␉␉␉aml_add_dword(tssp0, 0x00);␉␉// Latency␊ |
1047 | ␉␉␉aml_add_dword(tssp0, 0x00);␉␉// Control; spec says 0x07; apple uses 0;␊ |
1048 | ␉␉␉aml_add_dword(tssp0, 0x00);␉␉// Status␊ |
1049 | ␉␉␉␊ |
1050 | ␉␉␉for (i = 1; i < t_states_count; i++)␊ |
1051 | ␉␉␉{␊ |
1052 | ␉␉␉␉struct aml_chunk* tssp = aml_add_package(pack_tss);␊ |
1053 | ␊ |
1054 | ␉␉␉␉aml_add_dword(tssp, t_states[i].perf);␊ |
1055 | ␉␉␉␉aml_add_dword(tssp, t_states[i].pwer);␊ |
1056 | ␉␉␉␉aml_add_dword(tssp, 0x00);␊ |
1057 | ␉␉␉␉aml_add_dword(tssp, t_states[i].ctrl);␊ |
1058 | ␉␉␉␉aml_add_dword(tssp, 0x00);␊ |
1059 | ␉␉␉}␊ |
1060 | ␊ |
1061 | ␉␉␉struct aml_chunk* name_tsd = aml_add_name(scop, "TSD_");␊ |
1062 | ␉␉␉struct aml_chunk* pack_tsd = aml_add_package(name_tsd);␊ |
1063 | ␉␉␉struct aml_chunk* tsd = aml_add_package(pack_tsd);␊ |
1064 | ␉␉␉aml_add_byte(tsd, 0x05);␊ |
1065 | ␉␉␉aml_add_byte(tsd, 0x00);␊ |
1066 | ␉␉␉aml_add_dword(tsd, 0x00);␊ |
1067 | ␉␉␉aml_add_dword(tsd, 0xfd);␊ |
1068 | ␉␉␉aml_add_dword(tsd, Platform.CPU.NoCores);␊ |
1069 | ␊ |
1070 | ␉␉␉// Add aliaces␊ |
1071 | ␉␉␉for (i = 0; i < acpi_cpu_count; i++) ␊ |
1072 | ␉␉␉{␊ |
1073 | ␉␉␉␉char name[9];␊ |
1074 | ␉␉␉␉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]);␊ |
1075 | ␉␉␉␉␊ |
1076 | ␉␉␉␉scop = aml_add_scope(root, name);␊ |
1077 | ␉␉␉␉aml_add_alias(scop, "TPC_", "_TPC");␊ |
1078 | ␉␉␉␉aml_add_alias(scop, "PTC_", "_PTC");␊ |
1079 | ␉␉␉␉aml_add_alias(scop, "TSS_", "_TSS");␊ |
1080 | ␉␉␉␉aml_add_alias(scop, "TSD_", "_TSD");␊ |
1081 | ␉␉␉}␊ |
1082 | ␊ |
1083 | ␉␉␉aml_calculate_size(root);␊ |
1084 | ␉␉␉␊ |
1085 | ␉␉␉struct acpi_2_ssdt *ssdt = (struct acpi_2_ssdt *)AllocateKernelMemory(root->Size);␊ |
1086 | ␉␉␉␊ |
1087 | ␉␉␉aml_write_node(root, (void*)ssdt, 0);␊ |
1088 | ␉␉␉␊ |
1089 | ␉␉␉ssdt->Length = root->Size;␊ |
1090 | ␉␉␉ssdt->Checksum = 0;␊ |
1091 | ␉␉␉ssdt->Checksum = 256 - checksum8(ssdt, ssdt->Length);␊ |
1092 | ␉␉␉␊ |
1093 | ␉␉␉verbose ("T-States: step=%d, %d states were succefully generated @ %x\n", step, t_states_count, ssdt);␊ |
1094 | ␉␉␉␊ |
1095 | ␉␉␉aml_destroy_node(root);␊ |
1096 | ␉␉␊ |
1097 | ␉␉␉return ssdt;␊ |
1098 | ␉␉}␊ |
1099 | ␉}␊ |
1100 | ␉else ␊ |
1101 | ␉{␊ |
1102 | ␉␉verbose ("ACPI CPUs not found: T-States not generated !!!\n");␊ |
1103 | ␉}␊ |
1104 | ␊ |
1105 | ␉return NULL;␊ |
1106 | }␊ |
1107 | ␊ |
1108 | void *loadSSDTTable(int ssdt_number)␊ |
1109 | {␊ |
1110 | ␉void *tableAddr;␊ |
1111 | ␉int fd = -1;␊ |
1112 | ␉char dirspec[512];␊ |
1113 | ␉char filename[512];␊ |
1114 | ␉const char * overriden_pathname=NULL;␊ |
1115 | ␉int len=0;␊ |
1116 | ␊ |
1117 | ␉sprintf(filename, "SSDT-%d.aml", ssdt_number);␊ |
1118 | ␉␊ |
1119 | ␉// Check booting partition␊ |
1120 | ␉␊ |
1121 | ␉// Rek: if user specified a full path name then take it in consideration␊ |
1122 | ␉if (getValueForKey(kSSDT, &overriden_pathname, &len, &bootInfo->bootConfig))␊ |
1123 | ␉{␊ |
1124 | ␉␉sprintf(dirspec, "%s-%d.aml", overriden_pathname, ssdt_number); // start searching root␊ |
1125 | ␉␉//printf("Using custom %s path %s\n", key, dirspec);␊ |
1126 | ␉␉//getc();␊ |
1127 | ␉}␊ |
1128 | ␉else␊ |
1129 | ␉␉sprintf(dirspec, "/%s", filename); // start searching root␊ |
1130 | ␉␊ |
1131 | ␉fd=open (dirspec,0);␊ |
1132 | ␉␊ |
1133 | ␉if (fd<0)␊ |
1134 | ␉{␉// Check Extra on booting partition␊ |
1135 | ␉␉//verbose("Searching for %s.aml file ...\n", key);␊ |
1136 | ␉␉sprintf(dirspec,"/Extra/%s",filename);␊ |
1137 | ␉␉fd=open (dirspec,0);␊ |
1138 | ␉␉if (fd<0)␊ |
1139 | ␉␉{␉// Fall back to booter partition␊ |
1140 | ␉␉␉sprintf(dirspec,"bt(0,0)/Extra/%s",filename);␊ |
1141 | ␉␉␉fd=open (dirspec,0);␊ |
1142 | ␉␉␉if (fd<0)␊ |
1143 | ␉␉␉{␊ |
1144 | ␉␉␉␉//verbose("SSDT Table not found: %s\n", filename);␊ |
1145 | ␉␉␉␉return NULL;␊ |
1146 | ␉␉␉}␊ |
1147 | ␉␉}␊ |
1148 | ␉}␊ |
1149 | ␉␊ |
1150 | ␉tableAddr=(void*)AllocateKernelMemory(file_size (fd));␊ |
1151 | ␉if (tableAddr)␊ |
1152 | ␉{␊ |
1153 | ␉␉if (read (fd, tableAddr, file_size (fd))!=file_size (fd))␊ |
1154 | ␉␉{␊ |
1155 | ␉␉␉printf("Couldn't read table %s\n",dirspec);␊ |
1156 | ␉␉␉free (tableAddr);␊ |
1157 | ␉␉␉close (fd);␊ |
1158 | ␉␉␉return NULL;␊ |
1159 | ␉␉}␊ |
1160 | ␉␉␊ |
1161 | ␉␉verbose("Table %s read and stored at: %x\n", dirspec, tableAddr);␊ |
1162 | ␉␉close (fd);␊ |
1163 | ␉␉return tableAddr;␊ |
1164 | ␉}␊ |
1165 | ␉␊ |
1166 | ␉printf("Couldn't allocate memory for table %s\n", dirspec);␊ |
1167 | ␉close (fd);␊ |
1168 | ␉␊ |
1169 | ␉return NULL;␊ |
1170 | }␊ |
1171 | ␊ |
1172 | struct acpi_2_gas FillGASStruct(uint32_t Address, uint8_t Length)␊ |
1173 | {␊ |
1174 | ␉struct acpi_2_gas TmpGAS;␊ |
1175 | ␊ |
1176 | ␉TmpGAS.Address_Space_ID = 1; /* I/O Address */␊ |
1177 | ␊ |
1178 | ␉if (Address == 0)␊ |
1179 | ␉{␊ |
1180 | ␉␉TmpGAS.Register_Bit_Width = 0;␊ |
1181 | ␉} else {␊ |
1182 | ␉␉TmpGAS.Register_Bit_Width = Length * 8;␊ |
1183 | ␉}␊ |
1184 | ␊ |
1185 | ␉TmpGAS.Register_Bit_Offset = 0;␊ |
1186 | ␉TmpGAS.Access_Size = 0; /* Not set for Legacy reasons... */␊ |
1187 | ␉TmpGAS.Address = (uint64_t)Address;␊ |
1188 | ␊ |
1189 | ␉return(TmpGAS);␊ |
1190 | }␊ |
1191 | ␊ |
1192 | struct acpi_2_fadt *patch_fadt(struct acpi_2_fadt *fadt, void *new_dsdt, bool UpdateFADT)␊ |
1193 | {␊ |
1194 | extern void setupSystemType(); ␊ |
1195 | ␉␊ |
1196 | ␉struct acpi_2_fadt *fadt_mod;␊ |
1197 | ␉struct acpi_2_fadt *fadt_file = (struct acpi_2_fadt *)loadACPITable(kFADT);␊ |
1198 | ␉bool fadt_rev2_needed = false;␊ |
1199 | ␉bool fix_restart;␊ |
1200 | ␉const char * value;␊ |
1201 | ␊ |
1202 | ␉// Restart Fix␊ |
1203 | ␉if (Platform.CPU.Vendor == 0x756E6547) {␉/* Intel */␊ |
1204 | ␉␉fix_restart = true;␊ |
1205 | ␉␉getBoolForKey(kRestartFix, &fix_restart, &bootInfo->bootConfig);␊ |
1206 | ␉} else {␊ |
1207 | ␉␉verbose ("Not an Intel platform: Restart Fix not applied !!!\n");␊ |
1208 | ␉␉fix_restart = false;␊ |
1209 | ␉}␊ |
1210 | ␊ |
1211 | ␉if (fix_restart)␊ |
1212 | ␉␉fadt_rev2_needed = true;␊ |
1213 | ␊ |
1214 | ␉// Allocate new fadt table␊ |
1215 | ␉if ((UpdateFADT) && (((fadt_file) && (fadt_file->Length < sizeof(struct acpi_2_fadt))) ||␊ |
1216 | ␉␉␉␉␉␉ ((!fadt_file) && (fadt->Length < sizeof(struct acpi_2_fadt)))))␊ |
1217 | ␉{␊ |
1218 | ␉␉fadt_mod=(struct acpi_2_fadt *)AllocateKernelMemory(sizeof(struct acpi_2_fadt));␊ |
1219 | ␊ |
1220 | ␉␉if (fadt_file)␊ |
1221 | ␉␉␉memcpy(fadt_mod, fadt_file, fadt_file->Length);␊ |
1222 | ␉␉else␊ |
1223 | ␉␉␉memcpy(fadt_mod, fadt, fadt->Length);␊ |
1224 | ␊ |
1225 | ␉␉fadt_mod->Length = sizeof(struct acpi_2_fadt);␊ |
1226 | ␉␉fadt_mod->Revision = 0x04; // FADT rev 4␊ |
1227 | ␉␉fadt_mod->RESET_REG = FillGASStruct(0, 0);␊ |
1228 | ␉␉fadt_mod->RESET_VALUE = 0;␊ |
1229 | ␉␉fadt_mod->Reserved2[0] = 0;␊ |
1230 | ␉␉fadt_mod->Reserved2[1] = 0;␊ |
1231 | ␉␉fadt_mod->Reserved2[2] = 0;␊ |
1232 | ␉␉fadt_mod->X_PM1a_EVT_BLK = FillGASStruct(fadt_mod->PM1a_EVT_BLK, fadt_mod->PM1_EVT_LEN);␊ |
1233 | ␉␉fadt_mod->X_PM1b_EVT_BLK = FillGASStruct(fadt_mod->PM1b_EVT_BLK, fadt_mod->PM1_EVT_LEN);␊ |
1234 | ␉␉fadt_mod->X_PM1a_CNT_BLK = FillGASStruct(fadt_mod->PM1a_CNT_BLK, fadt_mod->PM1_CNT_LEN);␊ |
1235 | ␉␉fadt_mod->X_PM1b_CNT_BLK = FillGASStruct(fadt_mod->PM1b_CNT_BLK, fadt_mod->PM1_CNT_LEN);␊ |
1236 | ␉␉fadt_mod->X_PM2_CNT_BLK = FillGASStruct(fadt_mod->PM2_CNT_BLK, fadt_mod->PM2_CNT_LEN);␊ |
1237 | ␉␉fadt_mod->X_PM_TMR_BLK = FillGASStruct(fadt_mod->PM_TMR_BLK, fadt_mod->PM_TMR_LEN);␊ |
1238 | ␉␉fadt_mod->X_GPE0_BLK = FillGASStruct(fadt_mod->GPE0_BLK, fadt_mod->GPE0_BLK_LEN);␊ |
1239 | ␉␉fadt_mod->X_GPE1_BLK = FillGASStruct(fadt_mod->GPE1_BLK, fadt_mod->GPE1_BLK_LEN);␊ |
1240 | ␉␉verbose("Converted ACPI V%d FADT to ACPI V4 FADT\n", (fadt_file) ? fadt_file->Revision : fadt->Revision);␊ |
1241 | ␉} else {␊ |
1242 | ␉␉if (((!fadt_file) && ((fadt->Length < 0x84) && (fadt_rev2_needed))) ||␊ |
1243 | ␉␉␉ ((fadt_file) && ((fadt_file->Length < 0x84) && (fadt_rev2_needed))))␊ |
1244 | ␉␉{␊ |
1245 | ␉␉␉fadt_mod=(struct acpi_2_fadt *)AllocateKernelMemory(0x84);␊ |
1246 | ␊ |
1247 | ␉␉␉if (fadt_file)␊ |
1248 | ␉␉␉␉memcpy(fadt_mod, fadt_file, fadt_file->Length);␊ |
1249 | ␉␉␉else␊ |
1250 | ␉␉␉␉memcpy(fadt_mod, fadt, fadt->Length);␊ |
1251 | ␊ |
1252 | ␉␉␉fadt_mod->Length = 0x84;␊ |
1253 | ␉␉␉fadt_mod->Revision = 0x02; // FADT rev 2 (ACPI 1.0B MS extensions)␊ |
1254 | ␉␉}␊ |
1255 | ␉␉else␊ |
1256 | ␉␉{␊ |
1257 | ␉␉␉if (fadt_file)␊ |
1258 | ␉␉␉{␊ |
1259 | ␉␉␉␉fadt_mod=(struct acpi_2_fadt *)AllocateKernelMemory(fadt_file->Length);␊ |
1260 | ␉␉␉␉memcpy(fadt_mod, fadt_file, fadt_file->Length);␊ |
1261 | ␉␉␉} else {␊ |
1262 | ␉␉␉␉fadt_mod=(struct acpi_2_fadt *)AllocateKernelMemory(fadt->Length);␊ |
1263 | ␉␉␉␉memcpy(fadt_mod, fadt, fadt->Length);␊ |
1264 | ␉␉␉}␊ |
1265 | ␉␉}␊ |
1266 | ␉}␊ |
1267 | ␉// Determine system type / PM_Model␊ |
1268 | ␉if ( (value=getStringForKey(kSystemType, &bootInfo->bootConfig))!=NULL)␊ |
1269 | ␉{␊ |
1270 | ␉ if (Platform.Type > 6) ␊ |
1271 | ␉ {␊ |
1272 | ␉ if(fadt_mod->Preferred_PM_Profile<=6)␊ |
1273 | ␉ Platform.Type = fadt_mod->Preferred_PM_Profile; // get the fadt if correct␊ |
1274 | ␉ else ␊ |
1275 | ␉ Platform.Type = 1;␉␉/* Set a fixed value (Desktop) */␊ |
1276 | ␉ verbose("Error: system-type must be 0..6. Defaulting to %d !\n", Platform.Type);␊ |
1277 | ␉ }␊ |
1278 | ␉ else␊ |
1279 | ␉ Platform.Type = (unsigned char) strtoul(value, NULL, 10);␊ |
1280 | ␉}␊ |
1281 | ␉// Set Preferred_PM_Profile from System-type only if user wanted this value to be forced␊ |
1282 | ␉if (fadt_mod->Preferred_PM_Profile != Platform.Type) ␊ |
1283 | ␉{␊ |
1284 | ␉ if (value) ␊ |
1285 | ␉ { // user has overriden the SystemType so take care of it in FACP␊ |
1286 | ␉␉verbose("FADT: changing Preferred_PM_Profile from 0x%02x to 0x%02x\n", fadt_mod->Preferred_PM_Profile, Platform.Type);␊ |
1287 | ␉␉fadt_mod->Preferred_PM_Profile = Platform.Type;␊ |
1288 | ␉ }␊ |
1289 | ␉ else␊ |
1290 | ␉ { // Preferred_PM_Profile has a different value and no override has been set, so reflect the user value to ioregs␊ |
1291 | ␉ Platform.Type = fadt_mod->Preferred_PM_Profile <= 6 ? fadt_mod->Preferred_PM_Profile : 1;␊ |
1292 | ␉ } ␊ |
1293 | ␉}␊ |
1294 | ␉// We now have to write the systemm-type in ioregs: we cannot do it before in setupDeviceTree()␊ |
1295 | ␉// because we need to take care of facp original content, if it is correct.␊ |
1296 | ␉setupSystemType();␊ |
1297 | ␊ |
1298 | ␉// Patch FADT to fix restart␊ |
1299 | ␉if (fix_restart)␊ |
1300 | ␉{␊ |
1301 | ␉␉fadt_mod->Flags|= 0x400;␊ |
1302 | ␉␉fadt_mod->RESET_REG = FillGASStruct(0x0cf9, 1);␊ |
1303 | ␉␉fadt_mod->RESET_VALUE = 0x06;␊ |
1304 | ␉␉␊ |
1305 | ␉␉verbose("FADT: Restart Fix applied !\n");␊ |
1306 | ␉}␊ |
1307 | ␊ |
1308 | ␉// Patch FACS Address␊ |
1309 | ␉fadt_mod->FIRMWARE_CTRL=(uint32_t)fadt->FIRMWARE_CTRL;␊ |
1310 | ␉if ((uint32_t)(&(fadt_mod->X_FIRMWARE_CTRL))-(uint32_t)fadt_mod+8<=fadt_mod->Length)␊ |
1311 | ␉␉fadt_mod->X_FIRMWARE_CTRL=(uint32_t)fadt->FIRMWARE_CTRL;␊ |
1312 | ␊ |
1313 | ␉// Patch DSDT Address if we have one loaded␊ |
1314 | ␉if(new_dsdt)␊ |
1315 | ␉{␊ |
1316 | ␉␉fadt_mod->DSDT=(uint32_t)new_dsdt;␊ |
1317 | ␉␉if ((uint32_t)(&(fadt_mod->X_DSDT))-(uint32_t)fadt_mod+8<=fadt_mod->Length)␊ |
1318 | ␉␉␉fadt_mod->X_DSDT=(uint32_t)new_dsdt;␊ |
1319 | ␉}␊ |
1320 | ␊ |
1321 | ␊ |
1322 | ␉// Correct the checksum␊ |
1323 | ␉fadt_mod->Checksum=0;␊ |
1324 | ␉fadt_mod->Checksum=256-checksum8(fadt_mod,fadt_mod->Length);␊ |
1325 | ␊ |
1326 | ␉return fadt_mod;␊ |
1327 | }␊ |
1328 | #if UNUSED␊ |
1329 | /* Setup ACPI without replacing DSDT. */␊ |
1330 | int setupAcpiNoMod()␊ |
1331 | {␊ |
1332 | //␉addConfigurationTable(&gEfiAcpiTableGuid, getAddressOfAcpiTable(), "ACPI");␊ |
1333 | //␉addConfigurationTable(&gEfiAcpi20TableGuid, getAddressOfAcpi20Table(), "ACPI_20");␊ |
1334 | ␉/* XXX aserebln why uint32 cast if pointer is uint64 ? */␊ |
1335 | ␉acpi10_p = (uint32_t)getAddressOfAcpiTable();␊ |
1336 | ␉acpi20_p = (uint32_t)getAddressOfAcpi20Table();␊ |
1337 | ␉addConfigurationTable(&gEfiAcpiTableGuid, &acpi10_p, "ACPI");␊ |
1338 | ␉if(acpi20_p) addConfigurationTable(&gEfiAcpi20TableGuid, &acpi20_p, "ACPI_20");␊ |
1339 | ␉return 1;␊ |
1340 | }␊ |
1341 | #endif␊ |
1342 | ␊ |
1343 | /* Setup ACPI. Replace DSDT if DSDT.aml is found */␊ |
1344 | int setupAcpi(void)␊ |
1345 | {␊ |
1346 | ␉int version;␊ |
1347 | ␉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_ssdt[14];␊ |
1348 | ␊ |
1349 | ␉struct acpi_2_ssdt *new_ssdt[16]; // 2 additional tables for pss/tss & cst␊ |
1350 | ␉struct acpi_2_fadt *fadt; // will be used in CST generator␊ |
1351 | ␊ |
1352 | ␉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;␊ |
1353 | ␉bool drop_ssdt=false, drop_hpet=false, drop_slic=false, drop_sbst=false, drop_ecdt=false, drop_asft=false, drop_dmar=false;␊ |
1354 | ␉bool update_acpi=false, gen_xsdt=false;␊ |
1355 | ␉bool hpet_replaced=false, sbst_replaced=false, ecdt_replaced=false, asft_replaced=false, dmar_replaced=false, apic_replaced=false, mcfg_replaced=false;␊ |
1356 | ␉bool hpet_added=false, sbst_added=false, ecdt_added=false, asft_added=false, dmar_added=false, apic_added=false, mcfg_added=false;␊ |
1357 | ␉bool gen_cst=false, gen_pss=false, gen_tss=false;␊ |
1358 | ␊ |
1359 | ␉int curssdt=0, loadtotssdt=0, totssdt=0, newtotssdt=0;␊ |
1360 | ␊ |
1361 | ␉{␊ |
1362 | ␉␉bool tmpval, tmpval2, tmpval3, tmpval4, tmpval6;␊ |
1363 | ␊ |
1364 | ␉␉drop_ssdt = getBoolForKey(kDropSSDT, &tmpval, &bootInfo->bootConfig)&&tmpval;␊ |
1365 | ␉␉drop_hpet = getBoolForKey(kDropHPET, &tmpval, &bootInfo->bootConfig)&&tmpval;␊ |
1366 | ␉␉drop_slic = getBoolForKey(kDropSLIC, &tmpval, &bootInfo->bootConfig)&&tmpval;␊ |
1367 | ␉␉drop_sbst = getBoolForKey(kDropSBST, &tmpval, &bootInfo->bootConfig)&&tmpval;␊ |
1368 | ␉␉drop_ecdt = getBoolForKey(kDropECDT, &tmpval, &bootInfo->bootConfig)&&tmpval;␊ |
1369 | ␉␉drop_asft = getBoolForKey(kDropASFT, &tmpval, &bootInfo->bootConfig)&&tmpval;␊ |
1370 | ␉␉drop_dmar = getBoolForKey(kDropDMAR, &tmpval, &bootInfo->bootConfig)&&tmpval;␊ |
1371 | ␊ |
1372 | ␉␉oem_dsdt = getBoolForKey(kOEMDSDT, &tmpval, &bootInfo->bootConfig)&&tmpval;␊ |
1373 | ␉␉oem_ssdt = getBoolForKey(kOEMSSDT, &tmpval, &bootInfo->bootConfig)&&tmpval;␊ |
1374 | ␉␉oem_hpet = getBoolForKey(kOEMHPET, &tmpval, &bootInfo->bootConfig)&&tmpval;␊ |
1375 | ␉␉oem_sbst = getBoolForKey(kOEMSBST, &tmpval, &bootInfo->bootConfig)&&tmpval;␊ |
1376 | ␉␉oem_ecdt = getBoolForKey(kOEMECDT, &tmpval, &bootInfo->bootConfig)&&tmpval;␊ |
1377 | ␉␉oem_asft = getBoolForKey(kOEMASFT, &tmpval, &bootInfo->bootConfig)&&tmpval;␊ |
1378 | ␉␉oem_dmar = getBoolForKey(kOEMDMAR, &tmpval, &bootInfo->bootConfig)&&tmpval;␊ |
1379 | ␉␉oem_apic = getBoolForKey(kOEMAPIC, &tmpval, &bootInfo->bootConfig)&&tmpval;␊ |
1380 | ␉␉oem_mcfg = getBoolForKey(kOEMMCFG, &tmpval, &bootInfo->bootConfig)&&tmpval;␊ |
1381 | ␊ |
1382 | ␉␉gen_cst = (getBoolForKey(kGenerateCStates, &tmpval, &bootInfo->bootConfig)&&tmpval)␊ |
1383 | ␉␉␉␉| (getBoolForKey(kEnableC2State, &tmpval2, &bootInfo->bootConfig)&&tmpval2)␊ |
1384 | ␉␉␉␉| (getBoolForKey(kEnableC3State, &tmpval3, &bootInfo->bootConfig)&&tmpval3)␊ |
1385 | ␉␉␉␉| (getBoolForKey(kEnableC4State, &tmpval4, &bootInfo->bootConfig)&&tmpval4)␊ |
1386 | ␉␉␉␉| (getBoolForKey(kEnableC6State, &tmpval6, &bootInfo->bootConfig)&&tmpval6);␊ |
1387 | ␊ |
1388 | ␉␉gen_pss = getBoolForKey(kGeneratePStates, &tmpval, &bootInfo->bootConfig)&&tmpval;␊ |
1389 | ␊ |
1390 | ␉␉gen_tss = getBoolForKey(kGenerateTStates, &tmpval, &bootInfo->bootConfig)&&tmpval;␊ |
1391 | ␊ |
1392 | ␉␉update_acpi = getBoolForKey(kUpdateACPI, &tmpval, &bootInfo->bootConfig)&&tmpval;␊ |
1393 | ␉}␊ |
1394 | ␊ |
1395 | ␉// Load replacement ACPI tables␊ |
1396 | ␉if (!oem_dsdt)␊ |
1397 | ␉␉new_dsdt=loadACPITable(kDSDT);␊ |
1398 | ␊ |
1399 | ␉if (!oem_hpet)␊ |
1400 | ␉␉new_hpet=loadACPITable(kHPET);␊ |
1401 | ␊ |
1402 | ␉if (!oem_sbst)␊ |
1403 | ␉␉new_sbst=loadACPITable(kSBST);␊ |
1404 | ␊ |
1405 | ␉if (!oem_ecdt)␊ |
1406 | ␉␉new_ecdt=loadACPITable(kECDT);␊ |
1407 | ␊ |
1408 | ␉if (!oem_asft)␊ |
1409 | ␉␉new_asft=loadACPITable(kASFT);␊ |
1410 | ␊ |
1411 | ␉if (!oem_dmar)␊ |
1412 | ␉␉new_dmar=loadACPITable(kDMAR);␊ |
1413 | ␊ |
1414 | ␉if (!oem_apic)␊ |
1415 | ␉␉new_apic=loadACPITable(kAPIC);␊ |
1416 | ␊ |
1417 | ␉if (!oem_mcfg)␊ |
1418 | ␉␉new_mcfg=loadACPITable(kMCFG);␊ |
1419 | ␊ |
1420 | ␉if (gen_cst || gen_pss || gen_tss) oem_ssdt = false;␊ |
1421 | ␊ |
1422 | ␉if (!oem_ssdt)␊ |
1423 | ␉{␊ |
1424 | ␉␉for (curssdt=0;curssdt<14;curssdt++)␊ |
1425 | ␉␉{␊ |
1426 | ␉␉␉new_ssdt[curssdt]=loadSSDTTable(curssdt);␊ |
1427 | ␉␉␉if (new_ssdt[curssdt])␊ |
1428 | ␉␉␉␉loadtotssdt++;␊ |
1429 | ␉␉}␊ |
1430 | ␉␉curssdt=0;␊ |
1431 | ␉}␊ |
1432 | /*␊ |
1433 | ␉if (!new_dsdt)␊ |
1434 | ␉␉return setupAcpiNoMod();␊ |
1435 | */␊ |
1436 | ␉DBG("New ACPI tables Loaded in memory\n");␊ |
1437 | ␉␉␉␊ |
1438 | ␉// Do the same procedure for both versions of ACPI␊ |
1439 | ␉for (version=0; version<2; version++) {␊ |
1440 | ␉␉struct acpi_2_rsdp *rsdp, *rsdp_mod, *rsdp_conv=(struct acpi_2_rsdp *)0;␊ |
1441 | ␉␉struct acpi_2_rsdt *rsdt, *rsdt_mod;␊ |
1442 | ␉␉struct acpi_2_xsdt *xsdt_conv = (struct acpi_2_xsdt *)0;␊ |
1443 | ␉␉int rsdplength;␊ |
1444 | ␊ |
1445 | ␉␉// Find original rsdp␊ |
1446 | ␉␉rsdp=(struct acpi_2_rsdp *)(version?getAddressOfAcpi20Table():getAddressOfAcpiTable());␊ |
1447 | ␉␉if ((update_acpi) && (rsdp->Revision == 0))␊ |
1448 | ␉␉{␊ |
1449 | ␉␉␉rsdp_conv = (struct acpi_2_rsdp *)AllocateKernelMemory(sizeof(struct acpi_2_rsdp));␊ |
1450 | ␉␉␉memcpy(rsdp_conv, rsdp, 20);␊ |
1451 | ␊ |
1452 | ␉␉␉/* Add/change fields */␊ |
1453 | ␉␉␉strncpy(rsdp->OEMID, "Apple ", 6);␊ |
1454 | ␉␉␉rsdp_conv->Revision = 2; /* ACPI version 3 */␊ |
1455 | ␉␉␉rsdp_conv->Length = sizeof(struct acpi_2_rsdp);␊ |
1456 | ␊ |
1457 | ␉␉␉/* Correct checksums */␊ |
1458 | ␉␉␉rsdp_conv->Checksum = 0;␊ |
1459 | ␉␉␉rsdp_conv->Checksum = 256-checksum8(rsdp_conv, 20);␊ |
1460 | ␉␉␉rsdp_conv->ExtendedChecksum = 0;␊ |
1461 | ␉␉␉rsdp_conv->ExtendedChecksum = 256-checksum8(rsdp_conv, rsdp_conv->Length);␊ |
1462 | ␊ |
1463 | ␉␉␉rsdp = rsdp_conv;␊ |
1464 | ␊ |
1465 | ␉␉␉gen_xsdt = true;␊ |
1466 | ␉␉␉version = 1;␊ |
1467 | ␊ |
1468 | ␉␉␉addConfigurationTable(&gEfiAcpiTableGuid, NULL, "ACPI");␊ |
1469 | ␊ |
1470 | ␉␉␉verbose("Converted ACPI RSD PTR version 1 to version 3\n");␊ |
1471 | ␉␉}␊ |
1472 | ␉␉if (!rsdp)␊ |
1473 | ␉␉{␊ |
1474 | ␉␉␉DBG("No ACPI version %d found. Ignoring\n", version+1);␊ |
1475 | ␉␉␉if (version)␊ |
1476 | ␉␉␉␉addConfigurationTable(&gEfiAcpi20TableGuid, NULL, "ACPI_20");␊ |
1477 | ␉␉␉else␊ |
1478 | ␉␉␉␉addConfigurationTable(&gEfiAcpiTableGuid, NULL, "ACPI");␊ |
1479 | ␉␉␉continue;␊ |
1480 | ␉␉}␊ |
1481 | ␉␉rsdplength=version?rsdp->Length:20;␊ |
1482 | ␊ |
1483 | ␉␉DBG("RSDP version %d found @%x. Length=%d\n",version+1,rsdp,rsdplength);␊ |
1484 | ␊ |
1485 | ␉␉/* FIXME: no check that memory allocation succeeded ␊ |
1486 | ␉␉ * Copy and patch RSDP,RSDT, XSDT and FADT␊ |
1487 | ␉␉ * For more info see ACPI Specification pages 110 and following␊ |
1488 | ␉␉ */␊ |
1489 | ␊ |
1490 | ␉␉if (gen_xsdt)␊ |
1491 | ␉␉{␊ |
1492 | ␉␉␉rsdp_mod=rsdp_conv;␊ |
1493 | ␉␉} else {␊ |
1494 | ␉␉␉rsdp_mod=(struct acpi_2_rsdp *) AllocateKernelMemory(rsdplength);␊ |
1495 | ␉␉␉memcpy(rsdp_mod, rsdp, rsdplength);␊ |
1496 | ␉␉}␊ |
1497 | ␊ |
1498 | ␉␉rsdt=(struct acpi_2_rsdt *)(rsdp->RsdtAddress);␊ |
1499 | ␊ |
1500 | ␉␉DBG("RSDT @%x, Length %d\n",rsdt, rsdt->Length);␊ |
1501 | ␉␉␊ |
1502 | ␉␉if (rsdt && (uint32_t)rsdt !=0xffffffff && rsdt->Length<0x10000)␊ |
1503 | ␉␉{␊ |
1504 | ␉␉␉uint32_t *rsdt_entries;␊ |
1505 | ␉␉␉int rsdt_entries_num;␊ |
1506 | ␉␉␉int dropoffset=0, i;␊ |
1507 | ␉␉␉␊ |
1508 | ␉␉␉rsdt_mod=(struct acpi_2_rsdt *)AllocateKernelMemory(rsdt->Length); ␊ |
1509 | ␉␉␉memcpy (rsdt_mod, rsdt, rsdt->Length);␊ |
1510 | ␉␉␉rsdp_mod->RsdtAddress=(uint32_t)rsdt_mod;␊ |
1511 | ␉␉␉rsdt_entries_num=(rsdt_mod->Length-sizeof(struct acpi_2_rsdt))/4;␊ |
1512 | ␉␉␉rsdt_entries=(uint32_t *)(rsdt_mod+1);␊ |
1513 | ␊ |
1514 | ␉␉␉if (gen_xsdt)␊ |
1515 | ␉␉␉{␊ |
1516 | ␉␉␉␉uint64_t *xsdt_conv_entries;␊ |
1517 | ␊ |
1518 | ␉␉␉␉xsdt_conv=(struct acpi_2_xsdt *)AllocateKernelMemory(sizeof(struct acpi_2_xsdt)+(rsdt_entries_num * 8));␊ |
1519 | ␉␉␉␉memcpy(xsdt_conv, rsdt, sizeof(struct acpi_2_rsdt));␊ |
1520 | ␊ |
1521 | ␉␉␉␉xsdt_conv->Signature[0] = 'X';␊ |
1522 | ␉␉␉␉xsdt_conv->Signature[1] = 'S';␊ |
1523 | ␉␉␉␉xsdt_conv->Signature[2] = 'D';␊ |
1524 | ␉␉␉␉xsdt_conv->Signature[3] = 'T';␊ |
1525 | ␉␉␉␉xsdt_conv->Length = sizeof(struct acpi_2_xsdt)+(rsdt_entries_num * 8);␊ |
1526 | ␊ |
1527 | ␉␉␉␉xsdt_conv_entries=(uint64_t *)(xsdt_conv+1);␊ |
1528 | ␊ |
1529 | ␉␉␉␉for (i=0;i<rsdt_entries_num;i++)␊ |
1530 | ␉␉␉␉{␊ |
1531 | ␉␉␉␉␉xsdt_conv_entries[i] = (uint64_t)rsdt_entries[i];␊ |
1532 | ␉␉␉␉}␊ |
1533 | ␊ |
1534 | ␉␉␉␉xsdt_conv->Checksum = 0;␊ |
1535 | ␉␉␉␉xsdt_conv->Checksum = 256-checksum8(xsdt_conv, xsdt_conv->Length);␊ |
1536 | ␊ |
1537 | ␉␉␉␉rsdp->XsdtAddress = (uint32_t)xsdt_conv;␊ |
1538 | ␊ |
1539 | ␉␉␉␉rsdp->ExtendedChecksum = 0;␊ |
1540 | ␉␉␉␉rsdp->ExtendedChecksum = 256-checksum8(rsdp, rsdp->Length);␊ |
1541 | ␊ |
1542 | ␉␉␉␉verbose("Converted RSDT table to XSDT table\n");␊ |
1543 | ␉␉␉}␊ |
1544 | ␊ |
1545 | ␉␉␉for (i=0;i<rsdt_entries_num;i++)␊ |
1546 | ␉␉␉{␊ |
1547 | ␉␉␉␉char *table=(char *)(rsdt_entries[i]);␊ |
1548 | ␉␉␉␉if (!table)␊ |
1549 | ␉␉␉␉␉continue;␊ |
1550 | ␊ |
1551 | ␉␉␉␉DBG("TABLE %c%c%c%c,",table[0],table[1],table[2],table[3]);␊ |
1552 | ␊ |
1553 | ␉␉␉␉rsdt_entries[i-dropoffset]=rsdt_entries[i];␊ |
1554 | ␉␉␉␉if (drop_ssdt && table[0]=='S' && table[1]=='S' && table[2]=='D' && table[3]=='T')␊ |
1555 | ␉␉␉␉{␊ |
1556 | ␉␉␉␉␉dropoffset++;␊ |
1557 | ␉␉␉␉␉continue;␊ |
1558 | ␉␉␉␉}␊ |
1559 | ␉␉␉␉if (drop_hpet && table[0]=='H' && table[1]=='P' && table[2]=='E' && table[3]=='T')␊ |
1560 | ␉␉␉␉{␊ |
1561 | ␉␉␉␉␉dropoffset++;␊ |
1562 | ␉␉␉␉␉continue;␊ |
1563 | ␉␉␉␉}␉␉␉␊ |
1564 | ␉␉␉␉if (drop_slic && table[0]=='S' && table[1]=='L' && table[2]=='I' && table[3]=='C')␊ |
1565 | ␉␉␉␉{␊ |
1566 | ␉␉␉␉␉dropoffset++;␊ |
1567 | ␉␉␉␉␉continue;␊ |
1568 | ␉␉␉␉}␊ |
1569 | ␉␉␉␉if (drop_sbst && table[0]=='S' && table[1]=='B' && table[2]=='S' && table[3]=='T')␊ |
1570 | ␉␉␉␉{␊ |
1571 | ␉␉␉␉␉dropoffset++;␊ |
1572 | ␉␉␉␉␉continue;␊ |
1573 | ␉␉␉␉}␊ |
1574 | ␉␉␉␉if (drop_ecdt && table[0]=='E' && table[1]=='C' && table[2]=='D' && table[3]=='T')␊ |
1575 | ␉␉␉␉{␊ |
1576 | ␉␉␉␉␉dropoffset++;␊ |
1577 | ␉␉␉␉␉continue;␊ |
1578 | ␉␉␉␉}␊ |
1579 | ␉␉␉␉if (drop_asft && table[0]=='A' && table[1]=='S' && table[2]=='F' && table[3]=='!')␊ |
1580 | ␉␉␉␉{␊ |
1581 | ␉␉␉␉␉dropoffset++;␊ |
1582 | ␉␉␉␉␉continue;␊ |
1583 | ␉␉␉␉}␊ |
1584 | ␉␉␉␉if (drop_dmar && table[0]=='D' && table[1]=='M' && table[2]=='A' && table[3]=='R')␊ |
1585 | ␉␉␉␉{␊ |
1586 | ␉␉␉␉␉dropoffset++;␊ |
1587 | ␉␉␉␉␉continue;␊ |
1588 | ␉␉␉␉}␊ |
1589 | ␉␉␉␉if ((!(oem_hpet)) && table[0]=='H' && table[1]=='P' && table[2]=='E' && table[3]=='T')␊ |
1590 | ␉␉␉␉{␊ |
1591 | ␉␉␉␉␉DBG("HPET found\n");␊ |
1592 | ␉␉␉␉␉if (new_hpet)␊ |
1593 | ␉␉␉␉␉{␊ |
1594 | ␉␉␉␉␉␉rsdt_entries[i-dropoffset]=(uint32_t)new_hpet;␊ |
1595 | ␉␉␉␉␉␉hpet_replaced=true;␊ |
1596 | ␉␉␉␉␉}␊ |
1597 | ␉␉␉␉␉continue;␊ |
1598 | ␉␉␉␉}␊ |
1599 | ␉␉␉␉if ((!(oem_sbst)) && table[0]=='S' && table[1]=='B' && table[2]=='S' && table[3]=='T')␊ |
1600 | ␉␉␉␉{␊ |
1601 | ␉␉␉␉␉DBG("SBST found\n");␊ |
1602 | ␉␉␉␉␉if (new_sbst)␊ |
1603 | ␉␉␉␉␉{␊ |
1604 | ␉␉␉␉␉␉rsdt_entries[i-dropoffset]=(uint32_t)new_sbst;␊ |
1605 | ␉␉␉␉␉␉sbst_replaced=true;␊ |
1606 | ␉␉␉␉␉}␊ |
1607 | ␉␉␉␉␉continue;␊ |
1608 | ␉␉␉␉}␊ |
1609 | ␉␉␉␉if ((!(oem_ecdt)) && table[0]=='E' && table[1]=='C' && table[2]=='D' && table[3]=='T')␊ |
1610 | ␉␉␉␉{␊ |
1611 | ␉␉␉␉␉DBG("ECDT found\n");␊ |
1612 | ␉␉␉␉␉if (new_ecdt)␊ |
1613 | ␉␉␉␉␉{␊ |
1614 | ␉␉␉␉␉␉rsdt_entries[i-dropoffset]=(uint32_t)new_ecdt;␊ |
1615 | ␉␉␉␉␉␉ecdt_replaced=true;␊ |
1616 | ␉␉␉␉␉}␊ |
1617 | ␉␉␉␉␉continue;␊ |
1618 | ␉␉␉␉}␊ |
1619 | ␉␉␉␉if ((!(oem_asft)) && table[0]=='A' && table[1]=='S' && table[2]=='F' && table[3]=='!')␊ |
1620 | ␉␉␉␉{␊ |
1621 | ␉␉␉␉␉DBG("ASF! found\n");␊ |
1622 | ␉␉␉␉␉if (new_asft)␊ |
1623 | ␉␉␉␉␉{␊ |
1624 | ␉␉␉␉␉␉rsdt_entries[i-dropoffset]=(uint32_t)new_asft;␊ |
1625 | ␉␉␉␉␉␉asft_replaced=true;␊ |
1626 | ␉␉␉␉␉}␊ |
1627 | ␉␉␉␉␉continue;␊ |
1628 | ␉␉␉␉}␊ |
1629 | ␉␉␉␉if ((!(oem_dmar)) && table[0]=='D' && table[1]=='M' && table[2]=='A' && table[3]=='R')␊ |
1630 | ␉␉␉␉{␊ |
1631 | ␉␉␉␉␉DBG("DMAR found\n");␊ |
1632 | ␉␉␉␉␉if (new_dmar)␊ |
1633 | ␉␉␉␉␉{␊ |
1634 | ␉␉␉␉␉␉rsdt_entries[i-dropoffset]=(uint32_t)new_dmar;␊ |
1635 | ␉␉␉␉␉␉dmar_replaced=true;␊ |
1636 | ␉␉␉␉␉}␊ |
1637 | ␉␉␉␉␉continue;␊ |
1638 | ␉␉␉␉}␊ |
1639 | ␉␉␉␉if ((!(oem_apic)) && table[0]=='A' && table[1]=='P' && table[2]=='I' && table[3]=='C')␊ |
1640 | ␉␉␉␉{␊ |
1641 | ␉␉␉␉␉DBG("APIC found\n");␊ |
1642 | ␉␉␉␉␉if (new_apic)␊ |
1643 | ␉␉␉␉␉{␊ |
1644 | ␉␉␉␉␉␉rsdt_entries[i-dropoffset]=(uint32_t)new_apic;␊ |
1645 | ␉␉␉␉␉␉apic_replaced=true;␊ |
1646 | ␉␉␉␉␉}␊ |
1647 | ␉␉␉␉␉continue;␊ |
1648 | ␉␉␉␉}␊ |
1649 | ␉␉␉␉if ((!(oem_mcfg)) && table[0]=='M' && table[1]=='C' && table[2]=='F' && table[3]=='G')␊ |
1650 | ␉␉␉␉{␊ |
1651 | ␉␉␉␉␉DBG("MCFG found\n");␊ |
1652 | ␉␉␉␉␉if (new_mcfg)␊ |
1653 | ␉␉␉␉␉{␊ |
1654 | ␉␉␉␉␉␉rsdt_entries[i-dropoffset]=(uint32_t)new_mcfg;␊ |
1655 | ␉␉␉␉␉␉mcfg_replaced=true;␊ |
1656 | ␉␉␉␉␉}␊ |
1657 | ␉␉␉␉␉continue;␊ |
1658 | ␉␉␉␉}␊ |
1659 | ␉␉␉␉if ((!(oem_ssdt)) && table[0]=='S' && table[1]=='S' && table[2]=='D' && table[3]=='T')␊ |
1660 | ␉␉␉␉{␊ |
1661 | ␉␉␉␉␉DBG("SSDT %d found", curssdt);␊ |
1662 | ␉␉␉␉␉if (new_ssdt[curssdt])␊ |
1663 | ␉␉␉␉␉{␊ |
1664 | ␉␉␉␉␉␉DBG(" and replaced");␊ |
1665 | ␉␉␉␉␉␉rsdt_entries[i-dropoffset]=(uint32_t)new_ssdt[curssdt];␊ |
1666 | ␉␉␉␉␉␉totssdt++;␊ |
1667 | ␉␉␉␉␉}␊ |
1668 | ␉␉␉␉␉DBG("\n");␊ |
1669 | ␉␉␉␉␉curssdt++;␊ |
1670 | ␉␉␉␉␉continue;␊ |
1671 | ␉␉␉␉}␊ |
1672 | ␉␉␉␉if (table[0]=='D' && table[1]=='S' && table[2]=='D' && table[3]=='T')␊ |
1673 | ␉␉␉␉{␊ |
1674 | ␉␉␉␉␉DBG("DSDT found\n");␊ |
1675 | ␉␉␉␉␉rsdt_entries[i-dropoffset]=(uint32_t)new_dsdt;␊ |
1676 | ␉␉␉␉␉continue;␊ |
1677 | ␊ |
1678 | ␉␉␉␉} else {␊ |
1679 | ␉␉␉␉␉struct acpi_2_rsdt *t = (struct acpi_2_rsdt *)table;␊ |
1680 | ␉␉␉␉␉strncpy(t->OEMID, "Apple ", 6);␊ |
1681 | ␉␉␉␉␉strncpy(t->OEMTableId, MacModel, 8);␊ |
1682 | ␉␉␉␉␉t->OEMRevision = ModelRev;␊ |
1683 | ␉␉␉␉␉t->Checksum=0;␊ |
1684 | ␉␉␉␉␉t->Checksum=256-checksum8(t,t->Length);␊ |
1685 | ␉␉␉␉}␊ |
1686 | ␉␉␉␉if (table[0]=='F' && table[1]=='A' && table[2]=='C' && table[3]=='P')␊ |
1687 | ␉␉␉␉{␊ |
1688 | ␉␉␉␉␉struct acpi_2_fadt *fadt_mod;␊ |
1689 | ␉␉␉␉␉fadt=(struct acpi_2_fadt *)rsdt_entries[i];␊ |
1690 | ␊ |
1691 | ␉␉␉␉␉DBG("FADT found @%x, Length %d\n",fadt, fadt->Length);␊ |
1692 | ␊ |
1693 | ␉␉␉␉␉if (!fadt || (uint32_t)fadt == 0xffffffff || fadt->Length>0x10000)␊ |
1694 | ␉␉␉␉␉{␊ |
1695 | ␉␉␉␉␉␉printf("FADT incorrect. Not modified\n");␊ |
1696 | ␉␉␉␉␉␉continue;␊ |
1697 | ␉␉␉␉␉}␊ |
1698 | ␉␉␉␉␉␊ |
1699 | ␉␉␉␉␉fadt_mod = patch_fadt(fadt, new_dsdt, update_acpi);␊ |
1700 | ␉␉␉␉␉rsdt_entries[i-dropoffset]=(uint32_t)fadt_mod;␊ |
1701 | ␊ |
1702 | ␉␉␉␉␉if(!oem_ssdt)␊ |
1703 | ␉␉␉␉␉{␊ |
1704 | ␉␉␉␉␉␉// Generate _CST SSDT␊ |
1705 | ␉␉␉␉␉␉if ( gen_cst && (new_ssdt[loadtotssdt] = generate_cst_ssdt(fadt_mod)))␊ |
1706 | ␉␉␉␉␉␉{␊ |
1707 | ␉␉␉␉␉␉␉gen_cst= false;␊ |
1708 | ␉␉␉␉␉␉␉loadtotssdt++;␊ |
1709 | ␉␉␉␉␉␉}␊ |
1710 | ␉␉␉␉␉␊ |
1711 | ␉␉␉␉␉␉// Generating _PSS SSDT␊ |
1712 | ␉␉␉␉␉␉if (gen_pss && (new_ssdt[loadtotssdt] = generate_pss_ssdt((void*)fadt_mod->DSDT)))␊ |
1713 | ␉␉␉␉␉␉{␊ |
1714 | ␉␉␉␉␉␉␉gen_pss= false;␊ |
1715 | ␉␉␉␉␉␉␉loadtotssdt++;␊ |
1716 | ␉␉␉␉␉␉}␊ |
1717 | ␉␉␉␉␉␊ |
1718 | ␉␉␉␉␉␉// Generating _TSS SSDT␊ |
1719 | ␉␉␉␉␉␉if (gen_tss && (new_ssdt[loadtotssdt] = generate_tss_ssdt((void*)fadt_mod->DSDT)))␊ |
1720 | ␉␉␉␉␉␉{␊ |
1721 | ␉␉␉␉␉␉␉gen_tss= false;␊ |
1722 | ␉␉␉␉␉␉␉loadtotssdt++;␊ |
1723 | ␉␉␉␉␉␉}␊ |
1724 | ␉␉␉␉␉}␊ |
1725 | ␊ |
1726 | ␉␉␉␉␉continue;␊ |
1727 | ␉␉␉␉}␊ |
1728 | ␉␉␉}␊ |
1729 | ␉␉␉DBG("\n");␊ |
1730 | ␊ |
1731 | ␉␉␉strncpy(rsdt_mod->OEMID, "Apple ", 6);␊ |
1732 | ␉␉␉strncpy(rsdt_mod->OEMTableId, MacModel, 8);␊ |
1733 | ␉␉␉rsdt_mod->OEMRevision = ModelRev;␊ |
1734 | ␊ |
1735 | ␉␉␉if ((!oem_hpet) && (!hpet_replaced))␊ |
1736 | ␉␉␉{␊ |
1737 | ␉␉␉␉if (new_hpet)␊ |
1738 | ␉␉␉␉{␊ |
1739 | ␉␉␉␉␉rsdt_entries[i-dropoffset]=(uint32_t)new_hpet;␊ |
1740 | ␉␉␉␉␉hpet_added=true;␊ |
1741 | ␉␉␉␉␉i++;␊ |
1742 | ␉␉␉␉}␊ |
1743 | ␉␉␉}␊ |
1744 | ␊ |
1745 | ␉␉␉if ((!oem_sbst) && (!sbst_replaced))␊ |
1746 | ␉␉␉{␊ |
1747 | ␉␉␉␉if (new_sbst)␊ |
1748 | ␉␉␉␉{␊ |
1749 | ␉␉␉␉␉rsdt_entries[i-dropoffset]=(uint32_t)new_sbst;␊ |
1750 | ␉␉␉␉␉sbst_added=true;␊ |
1751 | ␉␉␉␉␉i++;␊ |
1752 | ␉␉␉␉}␊ |
1753 | ␉␉␉}␊ |
1754 | ␊ |
1755 | ␉␉␉if ((!oem_ecdt) && (!ecdt_replaced))␊ |
1756 | ␉␉␉{␊ |
1757 | ␉␉␉␉if (new_ecdt)␊ |
1758 | ␉␉␉␉{␊ |
1759 | ␉␉␉␉␉rsdt_entries[i-dropoffset]=(uint32_t)new_ecdt;␊ |
1760 | ␉␉␉␉␉ecdt_added=true;␊ |
1761 | ␉␉␉␉␉i++;␊ |
1762 | ␉␉␉␉}␊ |
1763 | ␉␉␉}␊ |
1764 | ␊ |
1765 | ␉␉␉if ((!oem_asft) && (!asft_replaced))␊ |
1766 | ␉␉␉{␊ |
1767 | ␉␉␉␉if (new_asft)␊ |
1768 | ␉␉␉␉{␊ |
1769 | ␉␉␉␉␉rsdt_entries[i-dropoffset]=(uint32_t)new_asft;␊ |
1770 | ␉␉␉␉␉asft_added=true;␊ |
1771 | ␉␉␉␉␉i++;␊ |
1772 | ␉␉␉␉}␊ |
1773 | ␉␉␉}␊ |
1774 | ␊ |
1775 | ␉␉␉if ((!oem_dmar) && (!dmar_replaced))␊ |
1776 | ␉␉␉{␊ |
1777 | ␉␉␉␉if (new_dmar)␊ |
1778 | ␉␉␉␉{␊ |
1779 | ␉␉␉␉␉rsdt_entries[i-dropoffset]=(uint32_t)new_dmar;␊ |
1780 | ␉␉␉␉␉dmar_added=true;␊ |
1781 | ␉␉␉␉␉i++;␊ |
1782 | ␉␉␉␉}␊ |
1783 | ␉␉␉}␊ |
1784 | ␊ |
1785 | ␉␉␉if ((!oem_apic) && (!apic_replaced))␊ |
1786 | ␉␉␉{␊ |
1787 | ␉␉␉␉if (new_apic)␊ |
1788 | ␉␉␉␉{␊ |
1789 | ␉␉␉␉␉rsdt_entries[i-dropoffset]=(uint32_t)new_apic;␊ |
1790 | ␉␉␉␉␉apic_added=true;␊ |
1791 | ␉␉␉␉␉i++;␊ |
1792 | ␉␉␉␉}␊ |
1793 | ␉␉␉}␊ |
1794 | ␊ |
1795 | ␉␉␉if ((!oem_mcfg) && (!mcfg_replaced))␊ |
1796 | ␉␉␉{␊ |
1797 | ␉␉␉␉if (new_mcfg)␊ |
1798 | ␉␉␉␉{␊ |
1799 | ␉␉␉␉␉rsdt_entries[i-dropoffset]=(uint32_t)new_mcfg;␊ |
1800 | ␉␉␉␉␉mcfg_added=true;␊ |
1801 | ␉␉␉␉␉i++;␊ |
1802 | ␉␉␉␉}␊ |
1803 | ␉␉␉}␊ |
1804 | ␉␉␉␊ |
1805 | ␉␉␉if (!oem_ssdt)␊ |
1806 | ␉␉␉{ ␉␉␉␊ |
1807 | ␉␉␉␉while ((totssdt < loadtotssdt) && (curssdt < 14))␊ |
1808 | ␉␉␉␉{␊ |
1809 | ␉␉␉␉␉if (new_ssdt[curssdt])␊ |
1810 | ␉␉␉␉␉{␊ |
1811 | ␉␉␉␉␉␉DBG("adding SSDT %d\n", curssdt);␊ |
1812 | ␉␉␉␉␉␉rsdt_entries[i-dropoffset]=(uint32_t)new_ssdt[curssdt];␊ |
1813 | ␉␉␉␉␉␉totssdt++;␊ |
1814 | ␉␉␉␉␉␉newtotssdt++;␊ |
1815 | ␉␉␉␉␉␉i++;␊ |
1816 | ␉␉␉␉␉}␊ |
1817 | ␉␉␉␉␉curssdt++;␊ |
1818 | ␉␉␉␉}␊ |
1819 | ␉␉␉}␊ |
1820 | ␊ |
1821 | ␉␉␉// Correct the checksum of RSDT␊ |
1822 | ␉␉␉rsdt_mod->Length-=4*dropoffset;␊ |
1823 | ␉␉␉rsdt_mod->Length+=4*newtotssdt;␊ |
1824 | ␉␉␉if (hpet_added)␊ |
1825 | ␉␉␉␉rsdt_mod->Length+=4;␊ |
1826 | ␉␉␉if (sbst_added)␊ |
1827 | ␉␉␉␉rsdt_mod->Length+=4;␊ |
1828 | ␉␉␉if (ecdt_added)␊ |
1829 | ␉␉␉␉rsdt_mod->Length+=4;␊ |
1830 | ␉␉␉if (asft_added)␊ |
1831 | ␉␉␉␉rsdt_mod->Length+=4;␊ |
1832 | ␉␉␉if (dmar_added)␊ |
1833 | ␉␉␉␉rsdt_mod->Length+=4;␊ |
1834 | ␉␉␉if (apic_added)␊ |
1835 | ␉␉␉␉rsdt_mod->Length+=4;␊ |
1836 | ␉␉␉if (mcfg_added)␊ |
1837 | ␉␉␉␉rsdt_mod->Length+=4;␊ |
1838 | ␊ |
1839 | ␉␉␉DBG("RSDT: Original checksum %d, ", rsdt_mod->Checksum);␊ |
1840 | ␊ |
1841 | ␉␉␉rsdt_mod->Checksum=0;␊ |
1842 | ␉␉␉rsdt_mod->Checksum=256-checksum8(rsdt_mod,rsdt_mod->Length);␊ |
1843 | ␊ |
1844 | ␉␉␉DBG("New checksum %d at %x\n", rsdt_mod->Checksum,rsdt_mod);␊ |
1845 | ␉␉}␊ |
1846 | ␉␉else␊ |
1847 | ␉␉{␊ |
1848 | ␉␉␉rsdp_mod->RsdtAddress=0;␊ |
1849 | ␉␉␉printf("RSDT not found or incorrect\n");␊ |
1850 | ␉␉}␊ |
1851 | ␊ |
1852 | ␉␉if (version)␊ |
1853 | ␉␉{␊ |
1854 | ␉␉␉struct acpi_2_xsdt *xsdt, *xsdt_mod;␊ |
1855 | ␊ |
1856 | ␉␉␉// FIXME: handle 64-bit address correctly␊ |
1857 | ␊ |
1858 | ␉␉␉if (gen_xsdt)␊ |
1859 | ␉␉␉␉xsdt=xsdt_conv;␊ |
1860 | ␉␉␉else␊ |
1861 | ␉␉␉␉xsdt=(struct acpi_2_xsdt*) ((uint32_t)rsdp->XsdtAddress);␊ |
1862 | ␊ |
1863 | ␉␉␉DBG("XSDT @%x;%x, Length=%d\n", (uint32_t)(rsdp->XsdtAddress>>32),(uint32_t)rsdp->XsdtAddress, xsdt->Length);␊ |
1864 | ␉␉␉if (xsdt && (uint64_t)rsdp->XsdtAddress<0xffffffff && xsdt->Length<0x10000)␊ |
1865 | ␉␉␉{␊ |
1866 | ␉␉␉␉uint64_t *xsdt_entries;␊ |
1867 | ␉␉␉␉int xsdt_entries_num, i;␊ |
1868 | ␉␉␉␉int dropoffset=0;␊ |
1869 | ␉␉␉␉curssdt=0, totssdt=0, newtotssdt=0;␊ |
1870 | ␉␉␉␉hpet_replaced=false, hpet_added=false;␊ |
1871 | ␉␉␉␉sbst_replaced=false, sbst_added=false;␊ |
1872 | ␉␉␉␉ecdt_replaced=false, ecdt_added=false;␊ |
1873 | ␉␉␉␉asft_replaced=false, asft_added=false;␊ |
1874 | ␉␉␉␉dmar_replaced=false, dmar_added=false;␊ |
1875 | ␉␉␉␉apic_replaced=false, apic_added=false;␊ |
1876 | ␉␉␉␉mcfg_replaced=false, mcfg_added=false;␊ |
1877 | ␊ |
1878 | ␉␉␉␉if (gen_xsdt)␊ |
1879 | ␉␉␉␉␉xsdt_mod=xsdt;␊ |
1880 | ␉␉␉␉else␊ |
1881 | ␉␉␉␉{␊ |
1882 | ␉␉␉␉␉xsdt_mod=(struct acpi_2_xsdt*)AllocateKernelMemory(xsdt->Length); ␊ |
1883 | ␉␉␉␉␉memcpy(xsdt_mod, xsdt, xsdt->Length);␊ |
1884 | ␉␉␉␉}␊ |
1885 | ␊ |
1886 | ␉␉␉␉rsdp_mod->XsdtAddress=(uint32_t)xsdt_mod;␊ |
1887 | ␉␉␉␉xsdt_entries_num=(xsdt_mod->Length-sizeof(struct acpi_2_xsdt))/8;␊ |
1888 | ␉␉␉␉xsdt_entries=(uint64_t *)(xsdt_mod+1);␊ |
1889 | ␉␉␉␉for (i=0;i<xsdt_entries_num;i++)␊ |
1890 | ␉␉␉␉{␊ |
1891 | ␉␉␉␉␉char *table=(char *)((uint32_t)(xsdt_entries[i]));␊ |
1892 | ␉␉␉␉␉if (!table)␊ |
1893 | ␉␉␉␉␉␉continue;␊ |
1894 | ␉␉␉␉␉xsdt_entries[i-dropoffset]=xsdt_entries[i];␊ |
1895 | ␉␉␉␉␉if (drop_ssdt && table[0]=='S' && table[1]=='S' && table[2]=='D' && table[3]=='T')␊ |
1896 | ␉␉␉␉␉{␊ |
1897 | ␉␉␉␉␉␉dropoffset++;␊ |
1898 | ␉␉␉␉␉␉continue;␊ |
1899 | ␉␉␉␉␉}␉␊ |
1900 | ␉␉␉␉␉if (drop_hpet && table[0]=='H' && table[1]=='P' && table[2]=='E' && table[3]=='T')␊ |
1901 | ␉␉␉␉␉{␊ |
1902 | ␉␉␉␉␉␉dropoffset++;␊ |
1903 | ␉␉␉␉␉␉continue;␊ |
1904 | ␉␉␉␉␉}␊ |
1905 | ␉␉␉␉␉if (drop_slic && table[0]=='S' && table[1]=='L' && table[2]=='I' && table[3]=='C')␊ |
1906 | ␉␉␉␉␉{␊ |
1907 | ␉␉␉␉␉␉dropoffset++;␊ |
1908 | ␉␉␉␉␉␉continue;␊ |
1909 | ␉␉␉␉␉}␊ |
1910 | ␉␉␉␉␉if (drop_sbst && table[0]=='S' && table[1]=='B' && table[2]=='S' && table[3]=='T')␊ |
1911 | ␉␉␉␉␉{␊ |
1912 | ␉␉␉␉␉␉dropoffset++;␊ |
1913 | ␉␉␉␉␉␉continue;␊ |
1914 | ␉␉␉␉␉}␊ |
1915 | ␉␉␉␉␉if (drop_ecdt && table[0]=='E' && table[1]=='C' && table[2]=='D' && table[3]=='T')␊ |
1916 | ␉␉␉␉␉{␊ |
1917 | ␉␉␉␉␉␉dropoffset++;␊ |
1918 | ␉␉␉␉␉␉continue;␊ |
1919 | ␉␉␉␉␉}␉␉␉␉␉␊ |
1920 | ␉␉␉␉␉if (drop_asft && table[0]=='A' && table[1]=='S' && table[2]=='F' && table[3]=='!')␊ |
1921 | ␉␉␉␉␉{␊ |
1922 | ␉␉␉␉␉␉dropoffset++;␊ |
1923 | ␉␉␉␉␉␉continue;␊ |
1924 | ␉␉␉␉␉}␊ |
1925 | ␉␉␉␉␉if (drop_dmar && table[0]=='D' && table[1]=='M' && table[2]=='A' && table[3]=='R')␊ |
1926 | ␉␉␉␉␉{␊ |
1927 | ␉␉␉␉␉␉dropoffset++;␊ |
1928 | ␉␉␉␉␉␉continue;␊ |
1929 | ␉␉␉␉␉}␉␉␉␉␉␊ |
1930 | ␉␉␉␉␉if ((!(oem_hpet)) && table[0]=='H' && table[1]=='P' && table[2]=='E' && table[3]=='T')␊ |
1931 | ␉␉␉␉␉{␊ |
1932 | ␉␉␉␉␉␉DBG("HPET found\n");␊ |
1933 | ␉␉␉␉␉␉if (new_hpet)␊ |
1934 | ␉␉␉␉␉␉{␊ |
1935 | ␉␉␉␉␉␉␉xsdt_entries[i-dropoffset]=(uint32_t)new_hpet;␊ |
1936 | ␉␉␉␉␉␉␉hpet_replaced=true;␊ |
1937 | ␉␉␉␉␉␉}␊ |
1938 | ␉␉␉␉␉␉continue;␊ |
1939 | ␉␉␉␉␉}␉␉␉␉␉␊ |
1940 | ␉␉␉␉␉if ((!(oem_sbst)) && table[0]=='S' && table[1]=='B' && table[2]=='S' && table[3]=='T')␊ |
1941 | ␉␉␉␉␉{␊ |
1942 | ␉␉␉␉␉␉DBG("SBST found\n");␊ |
1943 | ␉␉␉␉␉␉if (new_sbst)␊ |
1944 | ␉␉␉␉␉␉{␊ |
1945 | ␉␉␉␉␉␉␉xsdt_entries[i-dropoffset]=(uint32_t)new_sbst;␊ |
1946 | ␉␉␉␉␉␉␉sbst_replaced=true;␊ |
1947 | ␉␉␉␉␉␉}␊ |
1948 | ␉␉␉␉␉␉continue;␊ |
1949 | ␉␉␉␉␉}␉␉␉␉␉␊ |
1950 | ␉␉␉␉␉if ((!(oem_ecdt)) && table[0]=='E' && table[1]=='C' && table[2]=='D' && table[3]=='T')␊ |
1951 | ␉␉␉␉␉{␊ |
1952 | ␉␉␉␉␉␉DBG("ECDT found\n");␊ |
1953 | ␉␉␉␉␉␉if (new_ecdt)␊ |
1954 | ␉␉␉␉␉␉{␊ |
1955 | ␉␉␉␉␉␉␉xsdt_entries[i-dropoffset]=(uint32_t)new_ecdt;␊ |
1956 | ␉␉␉␉␉␉␉ecdt_replaced=true;␊ |
1957 | ␉␉␉␉␉␉}␊ |
1958 | ␉␉␉␉␉␉continue;␊ |
1959 | ␉␉␉␉␉}␉␉␉␉␉␊ |
1960 | ␉␉␉␉␉if ((!(oem_asft)) && table[0]=='A' && table[1]=='S' && table[2]=='F' && table[3]=='!')␊ |
1961 | ␉␉␉␉␉{␊ |
1962 | ␉␉␉␉␉␉DBG("ASF! found\n");␊ |
1963 | ␉␉␉␉␉␉if (new_asft)␊ |
1964 | ␉␉␉␉␉␉{␊ |
1965 | ␉␉␉␉␉␉␉xsdt_entries[i-dropoffset]=(uint32_t)new_asft;␊ |
1966 | ␉␉␉␉␉␉␉asft_replaced=true;␊ |
1967 | ␉␉␉␉␉␉}␊ |
1968 | ␉␉␉␉␉␉continue;␊ |
1969 | ␉␉␉␉␉}␉␉␉␉␉␊ |
1970 | ␉␉␉␉␉if ((!(oem_dmar)) && table[0]=='D' && table[1]=='M' && table[2]=='A' && table[3]=='R')␊ |
1971 | ␉␉␉␉␉{␊ |
1972 | ␉␉␉␉␉␉DBG("DMAR found\n");␊ |
1973 | ␉␉␉␉␉␉if (new_dmar)␊ |
1974 | ␉␉␉␉␉␉{␊ |
1975 | ␉␉␉␉␉␉␉xsdt_entries[i-dropoffset]=(uint32_t)new_dmar;␊ |
1976 | ␉␉␉␉␉␉␉dmar_replaced=true;␊ |
1977 | ␉␉␉␉␉␉}␊ |
1978 | ␉␉␉␉␉␉continue;␊ |
1979 | ␉␉␉␉␉}␉␉␉␉␉␊ |
1980 | ␉␉␉␉␉if ((!(oem_apic)) && table[0]=='A' && table[1]=='P' && table[2]=='I' && table[3]=='C')␊ |
1981 | ␉␉␉␉␉{␊ |
1982 | ␉␉␉␉␉␉DBG("APIC found\n");␊ |
1983 | ␉␉␉␉␉␉if (new_apic)␊ |
1984 | ␉␉␉␉␉␉{␊ |
1985 | ␉␉␉␉␉␉␉xsdt_entries[i-dropoffset]=(uint32_t)new_apic;␊ |
1986 | ␉␉␉␉␉␉␉apic_replaced=true;␊ |
1987 | ␉␉␉␉␉␉}␊ |
1988 | ␉␉␉␉␉␉continue;␊ |
1989 | ␉␉␉␉␉}␉␉␉␉␉␊ |
1990 | ␉␉␉␉␉if ((!(oem_mcfg)) && table[0]=='M' && table[1]=='C' && table[2]=='F' && table[3]=='G')␊ |
1991 | ␉␉␉␉␉{␊ |
1992 | ␉␉␉␉␉␉DBG("MCFG found\n");␊ |
1993 | ␉␉␉␉␉␉if (new_mcfg)␊ |
1994 | ␉␉␉␉␉␉{␊ |
1995 | ␉␉␉␉␉␉␉xsdt_entries[i-dropoffset]=(uint32_t)new_mcfg;␊ |
1996 | ␉␉␉␉␉␉␉mcfg_replaced=true;␊ |
1997 | ␉␉␉␉␉␉}␊ |
1998 | ␉␉␉␉␉␉continue;␊ |
1999 | ␉␉␉␉␉}␉␉␉␉␉␊ |
2000 | ␉␉␉␉␉if ((!(oem_ssdt)) && table[0]=='S' && table[1]=='S' && table[2]=='D' && table[3]=='T')␊ |
2001 | ␉␉␉␉␉{␊ |
2002 | ␉␉␉␉␉␉DBG("SSDT %d found", curssdt);␊ |
2003 | ␉␉␉␉␉␉if (new_ssdt[curssdt])␊ |
2004 | ␉␉␉␉␉␉{␊ |
2005 | ␉␉␉␉␉␉␉DBG(" and replaced");␊ |
2006 | ␉␉␉␉␉␉␉xsdt_entries[i-dropoffset]=(uint32_t)new_ssdt[curssdt];␊ |
2007 | ␉␉␉␉␉␉␉totssdt++;␊ |
2008 | ␉␉␉␉␉␉}␊ |
2009 | ␉␉␉␉␉␉DBG("\n");␊ |
2010 | ␉␉␉␉␉␉curssdt++;␊ |
2011 | ␉␉␉␉␉␉continue;␊ |
2012 | ␉␉␉␉␉}␉␉␉␉␉␊ |
2013 | ␉␉␉␉␉if (table[0]=='D' && table[1]=='S' && table[2]=='D' && table[3]=='T')␊ |
2014 | ␉␉␉␉␉{␊ |
2015 | ␉␉␉␉␉␉DBG("DSDT found\n");␊ |
2016 | ␊ |
2017 | ␉␉␉␉␉␉xsdt_entries[i-dropoffset]=(uint32_t)new_dsdt;␊ |
2018 | ␊ |
2019 | ␉␉␉␉␉␉DBG("TABLE %c%c%c%c@%x,",table[0],table[1],table[2],table[3],xsdt_entries[i]);␊ |
2020 | ␉␉␉␉␉␉␊ |
2021 | ␉␉␉␉␉␉continue;␊ |
2022 | ␉␉␉␉␉}␊ |
2023 | ␊ |
2024 | ␉␉␉␉␉struct acpi_2_xsdt* t = (struct acpi_2_xsdt*)table;␊ |
2025 | ␉␉␉␉␉strncpy(t->OEMID, "Apple ", 6);␊ |
2026 | ␉␉␉␉␉strncpy(t->OEMTableId, MacModel, 8);␊ |
2027 | ␉␉␉␉␉t->OEMRevision = ModelRev;␊ |
2028 | ␊ |
2029 | ␉␉␉␉␉if (table[0]=='F' && table[1]=='A' && table[2]=='C' && table[3]=='P')␊ |
2030 | ␉␉␉␉␉{␊ |
2031 | ␉␉␉␉␉␉struct acpi_2_fadt *fadt_mod;␊ |
2032 | ␉␉␉␉␉␉fadt=(struct acpi_2_fadt *)(uint32_t)xsdt_entries[i];␊ |
2033 | ␊ |
2034 | ␉␉␉␉␉␉DBG("FADT found @%x,%x, Length %d\n",(uint32_t)(xsdt_entries[i]>>32),fadt, ␊ |
2035 | ␉␉␉␉␉␉␉␉ fadt->Length);␊ |
2036 | ␊ |
2037 | ␉␉␉␉␉␉if (!fadt || (uint64_t)xsdt_entries[i] >= 0xffffffff || fadt->Length>0x10000)␊ |
2038 | ␉␉␉␉␉␉{␊ |
2039 | ␉␉␉␉␉␉␉verbose("FADT incorrect or after 4GB. Dropping XSDT\n");␊ |
2040 | ␉␉␉␉␉␉␉goto drop_xsdt;␊ |
2041 | ␉␉␉␉␉␉}␊ |
2042 | ␊ |
2043 | ␉␉␉␉␉␉fadt_mod = patch_fadt(fadt, new_dsdt, update_acpi);␊ |
2044 | ␉␉␉␉␉␉xsdt_entries[i-dropoffset]=(uint32_t)fadt_mod;␊ |
2045 | ␊ |
2046 | ␉␉␉␉␉␉DBG("TABLE %c%c%c%c@%x,",table[0],table[1],table[2],table[3],xsdt_entries[i]);␊ |
2047 | ␊ |
2048 | ␉␉␉␉␉␉if (!oem_ssdt)␊ |
2049 | ␉␉␉␉␉␉{␊ |
2050 | ␉␉␉␉␉␉␉// Generate _CST SSDT␊ |
2051 | ␉␉␉␉␉␉␉if ( gen_cst && (new_ssdt[loadtotssdt] = generate_cst_ssdt(fadt_mod)))␊ |
2052 | ␉␉␉␉␉␉␉{␊ |
2053 | ␉␉␉␉␉␉␉␉gen_cst= false;␊ |
2054 | ␉␉␉␉␉␉␉␉loadtotssdt++;␊ |
2055 | ␉␉␉␉␉␉␉}␊ |
2056 | ␊ |
2057 | ␉␉␉␉␉␉␉// Generating _PSS SSDT␊ |
2058 | ␉␉␉␉␉␉␉if (gen_pss && (new_ssdt[loadtotssdt] = generate_pss_ssdt((void*)fadt_mod->DSDT)))␊ |
2059 | ␉␉␉␉␉␉␉{␊ |
2060 | ␉␉␉␉␉␉␉␉gen_pss= false;␊ |
2061 | ␉␉␉␉␉␉␉␉loadtotssdt++;␊ |
2062 | ␉␉␉␉␉␉␉}␊ |
2063 | ␉␉␉␉␉␉␊ |
2064 | ␉␉␉␉␉␉␉// Generating _TSS SSDT␊ |
2065 | ␉␉␉␉␉␉␉if (gen_tss && (new_ssdt[loadtotssdt] = generate_tss_ssdt((void*)fadt_mod->DSDT)))␊ |
2066 | ␉␉␉␉␉␉␉{␊ |
2067 | ␉␉␉␉␉␉␉␉gen_tss= false;␊ |
2068 | ␉␉␉␉␉␉␉␉loadtotssdt++;␊ |
2069 | ␉␉␉␉␉␉␉}␊ |
2070 | ␉␉␉␉␉␉}␊ |
2071 | ␊ |
2072 | ␉␉␉␉␉␉continue;␊ |
2073 | ␉␉␉␉␉}␊ |
2074 | ␊ |
2075 | ␉␉␉␉␉DBG("TABLE %c%c%c%c@%x,",table[0],table[1],table[2],table[3],xsdt_entries[i]);␊ |
2076 | ␊ |
2077 | ␉␉␉␉}␊ |
2078 | ␊ |
2079 | ␉␉␉␉strncpy(xsdt_mod->OEMID, "Apple ", 6);␊ |
2080 | ␉␉␉␉strncpy(xsdt_mod->OEMTableId, MacModel, 8);␊ |
2081 | ␉␉␉␉xsdt_mod->OEMRevision = ModelRev;␊ |
2082 | ␊ |
2083 | ␉␉␉␉if ((!oem_hpet) && (!hpet_replaced))␊ |
2084 | ␉␉␉␉{␊ |
2085 | ␉␉␉␉␉if (new_hpet)␊ |
2086 | ␉␉␉␉␉{␊ |
2087 | ␉␉␉␉␉␉xsdt_entries[i-dropoffset]=(uint32_t)new_hpet;␊ |
2088 | ␉␉␉␉␉␉hpet_added=true;␊ |
2089 | ␉␉␉␉␉␉i++;␊ |
2090 | ␉␉␉␉␉}␊ |
2091 | ␉␉␉␉}␊ |
2092 | ␊ |
2093 | ␉␉␉␉if ((!oem_sbst) && (!sbst_replaced))␊ |
2094 | ␉␉␉␉{␊ |
2095 | ␉␉␉␉␉if (new_sbst)␊ |
2096 | ␉␉␉␉␉{␊ |
2097 | ␉␉␉␉␉␉xsdt_entries[i-dropoffset]=(uint32_t)new_sbst;␊ |
2098 | ␉␉␉␉␉␉sbst_added=true;␊ |
2099 | ␉␉␉␉␉␉i++;␊ |
2100 | ␉␉␉␉␉}␊ |
2101 | ␉␉␉␉}␊ |
2102 | ␊ |
2103 | ␉␉␉␉if ((!oem_ecdt) && (!ecdt_replaced))␊ |
2104 | ␉␉␉␉{␊ |
2105 | ␉␉␉␉␉if (new_ecdt)␊ |
2106 | ␉␉␉␉␉{␊ |
2107 | ␉␉␉␉␉␉xsdt_entries[i-dropoffset]=(uint32_t)new_ecdt;␊ |
2108 | ␉␉␉␉␉␉ecdt_added=true;␊ |
2109 | ␉␉␉␉␉␉i++;␊ |
2110 | ␉␉␉␉␉}␊ |
2111 | ␉␉␉␉}␊ |
2112 | ␊ |
2113 | ␉␉␉␉if ((!oem_asft) && (!asft_replaced))␊ |
2114 | ␉␉␉␉{␊ |
2115 | ␉␉␉␉␉if (new_asft)␊ |
2116 | ␉␉␉␉␉{␊ |
2117 | ␉␉␉␉␉␉xsdt_entries[i-dropoffset]=(uint32_t)new_asft;␊ |
2118 | ␉␉␉␉␉␉asft_added=true;␊ |
2119 | ␉␉␉␉␉␉i++;␊ |
2120 | ␉␉␉␉␉}␊ |
2121 | ␉␉␉␉}␊ |
2122 | ␊ |
2123 | ␉␉␉␉if ((!oem_dmar) && (!dmar_replaced))␊ |
2124 | ␉␉␉␉{␊ |
2125 | ␉␉␉␉␉if (new_dmar)␊ |
2126 | ␉␉␉␉␉{␊ |
2127 | ␉␉␉␉␉␉xsdt_entries[i-dropoffset]=(uint32_t)new_dmar;␊ |
2128 | ␉␉␉␉␉␉dmar_added=true;␊ |
2129 | ␉␉␉␉␉␉i++;␊ |
2130 | ␉␉␉␉␉}␊ |
2131 | ␉␉␉␉}␊ |
2132 | ␊ |
2133 | ␉␉␉␉if ((!oem_apic) && (!apic_replaced))␊ |
2134 | ␉␉␉␉{␊ |
2135 | ␉␉␉␉␉if (new_apic)␊ |
2136 | ␉␉␉␉␉{␊ |
2137 | ␉␉␉␉␉␉xsdt_entries[i-dropoffset]=(uint32_t)new_apic;␊ |
2138 | ␉␉␉␉␉␉apic_added=true;␊ |
2139 | ␉␉␉␉␉␉i++;␊ |
2140 | ␉␉␉␉␉}␊ |
2141 | ␉␉␉␉}␊ |
2142 | ␊ |
2143 | ␉␉␉␉if ((!oem_mcfg) && (!mcfg_replaced))␊ |
2144 | ␉␉␉␉{␊ |
2145 | ␉␉␉␉␉if (new_mcfg)␊ |
2146 | ␉␉␉␉␉{␊ |
2147 | ␉␉␉␉␉␉xsdt_entries[i-dropoffset]=(uint32_t)new_mcfg;␊ |
2148 | ␉␉␉␉␉␉mcfg_added=true;␊ |
2149 | ␉␉␉␉␉␉i++;␊ |
2150 | ␉␉␉␉␉}␊ |
2151 | ␉␉␉␉}␊ |
2152 | ␊ |
2153 | ␉␉␉␉if (!oem_ssdt)␊ |
2154 | ␉␉␉␉{ ␉␉␉␊ |
2155 | ␉␉␉␉␉while ((totssdt < loadtotssdt) && (curssdt < 14))␊ |
2156 | ␉␉␉␉␉{␊ |
2157 | ␉␉␉␉␉␉if (new_ssdt[curssdt])␊ |
2158 | ␉␉␉␉␉␉{␊ |
2159 | ␉␉␉␉␉␉␉DBG("adding SSDT %d\n", curssdt);␊ |
2160 | ␉␉␉␉␉␉␉xsdt_entries[i-dropoffset]=(uint32_t)new_ssdt[curssdt];␊ |
2161 | ␉␉␉␉␉␉␉totssdt++;␊ |
2162 | ␉␉␉␉␉␉␉newtotssdt++;␊ |
2163 | ␉␉␉␉␉␉␉i++;␊ |
2164 | ␉␉␉␉␉␉}␊ |
2165 | ␉␉␉␉␉␉curssdt++;␊ |
2166 | ␉␉␉␉␉}␊ |
2167 | ␉␉␉␉}␊ |
2168 | ␊ |
2169 | ␉␉␉␉// Correct the checksum of XSDT␊ |
2170 | ␉␉␉␉xsdt_mod->Length-=8*dropoffset;␊ |
2171 | ␉␉␉␉xsdt_mod->Length+=8*newtotssdt;␊ |
2172 | ␉␉␉␉if (hpet_added)␊ |
2173 | ␉␉␉␉␉xsdt_mod->Length+=8;␊ |
2174 | ␉␉␉␉if (sbst_added)␊ |
2175 | ␉␉␉␉␉xsdt_mod->Length+=8;␊ |
2176 | ␉␉␉␉if (ecdt_added)␊ |
2177 | ␉␉␉␉␉xsdt_mod->Length+=8;␊ |
2178 | ␉␉␉␉if (asft_added)␊ |
2179 | ␉␉␉␉␉xsdt_mod->Length+=8;␊ |
2180 | ␉␉␉␉if (dmar_added)␊ |
2181 | ␉␉␉␉␉xsdt_mod->Length+=8;␊ |
2182 | ␉␉␉␉if (apic_added)␊ |
2183 | ␉␉␉␉␉xsdt_mod->Length+=8;␊ |
2184 | ␉␉␉␉if (mcfg_added)␊ |
2185 | ␉␉␉␉␉xsdt_mod->Length+=8;␊ |
2186 | ␊ |
2187 | ␉␉␉␉xsdt_mod->Checksum=0;␊ |
2188 | ␉␉␉␉xsdt_mod->Checksum=256-checksum8(xsdt_mod,xsdt_mod->Length);␊ |
2189 | ␉␉␉}␊ |
2190 | ␉␉␉else␊ |
2191 | ␉␉␉{␊ |
2192 | ␉␉␉drop_xsdt:␊ |
2193 | ␊ |
2194 | ␉␉␉␉DBG("About to drop XSDT\n");␊ |
2195 | ␊ |
2196 | ␉␉␉␉/*FIXME: Now we just hope that if MacOS doesn't find XSDT it reverts to RSDT. ␊ |
2197 | ␉␉␉␉ * A Better strategy would be to generate␊ |
2198 | ␉␉␉␉ */␊ |
2199 | ␊ |
2200 | ␉␉␉␉rsdp_mod->XsdtAddress=0xffffffffffffffffLL;␊ |
2201 | ␉␉␉␉verbose("XSDT not found or incorrect\n");␊ |
2202 | ␉␉␉}␊ |
2203 | ␉␉}␊ |
2204 | ␊ |
2205 | ␉␉// Correct the checksum of RSDP ␊ |
2206 | ␊ |
2207 | ␉␉DBG("RSDP: Original checksum %d, ", rsdp_mod->Checksum);␊ |
2208 | ␊ |
2209 | ␉␉rsdp_mod->Checksum=0;␊ |
2210 | ␉␉rsdp_mod->Checksum=256-checksum8(rsdp_mod,20);␊ |
2211 | ␊ |
2212 | ␉␉DBG("New checksum %d\n", rsdp_mod->Checksum);␊ |
2213 | ␊ |
2214 | ␉␉if (version)␊ |
2215 | ␉␉{␊ |
2216 | ␉␉␉DBG("RSDP: Original extended checksum %d", rsdp_mod->ExtendedChecksum);␊ |
2217 | ␊ |
2218 | ␉␉␉rsdp_mod->ExtendedChecksum=0;␊ |
2219 | ␉␉␉rsdp_mod->ExtendedChecksum=256-checksum8(rsdp_mod,rsdp_mod->Length);␊ |
2220 | ␊ |
2221 | ␉␉␉DBG("New extended checksum %d\n", rsdp_mod->ExtendedChecksum);␊ |
2222 | ␊ |
2223 | ␉␉}␊ |
2224 | ␉␉␊ |
2225 | ␉␉verbose("Patched ACPI version %d DSDT\n", version+1);␊ |
2226 | ␉␉if (version)␊ |
2227 | ␉␉{␊ |
2228 | ␉/* XXX aserebln why uint32 cast if pointer is uint64 ? */␊ |
2229 | ␉␉␉acpi20_p = (uint32_t)rsdp_mod;␊ |
2230 | ␉␉␉acpi10_p = (uint32_t)rsdp_mod;␊ |
2231 | ␉␉␉addConfigurationTable(&gEfiAcpi20TableGuid, &acpi20_p, "ACPI_20");␊ |
2232 | ␉␉␉addConfigurationTable(&gEfiAcpiTableGuid, &acpi10_p, "ACPI");␊ |
2233 | ␉␉}␊ |
2234 | ␉␉else␊ |
2235 | ␉␉{␊ |
2236 | ␉/* XXX aserebln why uint32 cast if pointer is uint64 ? */␊ |
2237 | ␉␉␉acpi10_p = (uint32_t)rsdp_mod;␊ |
2238 | ␉␉␉addConfigurationTable(&gEfiAcpiTableGuid, &acpi10_p, "ACPI");␊ |
2239 | ␉␉}␊ |
2240 | ␉}␊ |
2241 | #if DEBUG_ACPI␊ |
2242 | ␉printf("Press a key to continue... (DEBUG_ACPI)\n");␊ |
2243 | ␉getc();␊ |
2244 | #endif␊ |
2245 | ␉return 1;␊ |
2246 | }␊ |
2247 | |