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