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