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 ("Not an Intel platform: C-States will not be generated !!!\n");␊ |
252 | ␉␉return NULL;␊ |
253 | ␉}␊ |
254 | ␉␊ |
255 | ␉if (fadt == NULL) {␊ |
256 | ␉␉verbose ("FACP not exists: C-States will not be generated !!!\n");␊ |
257 | ␉␉return NULL;␊ |
258 | ␉}␊ |
259 | ␉␊ |
260 | ␉struct acpi_2_dsdt* dsdt = (void*)fadt->DSDT;␊ |
261 | ␉␊ |
262 | ␉if (dsdt == NULL) {␊ |
263 | ␉␉verbose ("DSDT not found: C-States will not be generated !!!\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 ("ACPI CPUs not found: C-States not generated !!!\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 ("Not an Intel platform: P-States will not be generated !!!\n");␊ |
586 | ␉␉return NULL;␊ |
587 | ␉}␊ |
588 | ␉␊ |
589 | ␉if (!(platformCPUFeature(CPU_FEATURE_MSR))) {␊ |
590 | ␉␉verbose ("Unsupported CPU: P-States will not be generated !!!\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("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 | ␉␉␉␊ |
792 | ␉␉␉struct aml_chunk* root = aml_create_node(NULL);␊ |
793 | ␉␉␉aml_add_buffer(root, ssdt_header, sizeof(ssdt_header)); // SSDT header␊ |
794 | ␉␉␉struct aml_chunk* scop = aml_add_scope(root, "\\_PR_");␊ |
795 | ␉␉␉␊ |
796 | ␉␉␉aml_add_buffer(scop, ssdt_pct, sizeof(ssdt_pct));␊ |
797 | ␉␉␉␊ |
798 | ␉␉␉struct aml_chunk* name_psd = aml_add_name(scop, "PSD_");␊ |
799 | ␉␉␉struct aml_chunk* pack_psd = aml_add_package(name_psd);␊ |
800 | ␉␉␉struct aml_chunk* psd = aml_add_package(pack_psd);␊ |
801 | ␉␉␉aml_add_byte(psd, 0x05);␊ |
802 | ␉␉␉aml_add_byte(psd, 0x00);␊ |
803 | ␉␉␉aml_add_dword(psd, 0x00);␊ |
804 | ␉␉␉aml_add_dword(psd, 0xfc);␊ |
805 | ␉␉␉aml_add_dword(psd, Platform.CPU.NoCores);␊ |
806 | ␉␉␉␊ |
807 | ␉␉␉struct aml_chunk* name_pss = aml_add_name(scop, "PSS_");␊ |
808 | ␉␉␉struct aml_chunk* pack_pss = aml_add_package(name_pss);␊ |
809 | ␊ |
810 | //valv: this should not be␊ |
811 | /*␉␉␉if(Platform.CPU.Turbo)␊ |
812 | ␉␉␉{␊ |
813 | ␉␉␉␉int turbo_one = Platform.CPU.Tone;␊ |
814 | ␉␉␉␉int turbo_two = Platform.CPU.Ttwo;␊ |
815 | ␉␉␉␉int turbo_thr = Platform.CPU.Tthr;␊ |
816 | ␉␉␉␉int turbo_for = Platform.CPU.Tfor;␊ |
817 | ␊ |
818 | ␉␉␉␉uint8_t TFIDone = (turbo_one & 0x1F);␊ |
819 | ␉␉␉␉uint8_t TFIDtwo = (turbo_two & 0x1F);␊ |
820 | ␉␉␉␉uint8_t TFIDthr = (turbo_thr & 0x1F);␊ |
821 | ␉␉␉␉uint8_t TFIDfor = (turbo_for & 0x1F);␊ |
822 | ␊ |
823 | ␉␉␉␉uint32_t fsb = Platform.CPU.FSBFrequency / 1000000;␊ |
824 | ␉␉␉␉uint32_t tfreq_one = (TFIDone * fsb);␊ |
825 | ␉␉␉␉uint32_t tfreq_two = (TFIDtwo * fsb);␊ |
826 | ␉␉␉␉uint32_t tfreq_thr = (TFIDthr * fsb);␊ |
827 | ␉␉␉␉uint32_t tfreq_for = (TFIDfor * fsb);␊ |
828 | ␊ |
829 | ␉␉␉␉if(tfreq_one > 0)␊ |
830 | ␉␉␉␉{␊ |
831 | ␉␉␉␉␉struct aml_chunk* psturbo1 = aml_add_package(pack_pss);␊ |
832 | ␉␉␉␉␉aml_add_dword(psturbo1, tfreq_one);␊ |
833 | ␉␉␉␉␉aml_add_dword(psturbo1, 0x00000000); // Power␊ |
834 | ␉␉␉␉␉aml_add_dword(psturbo1, 0x0000000A); // Latency␊ |
835 | ␉␉␉␉␉aml_add_dword(psturbo1, 0x0000000A); // Latency␊ |
836 | ␉␉␉␉␉aml_add_dword(psturbo1, TFIDone);␊ |
837 | ␉␉␉␉␉aml_add_dword(psturbo1, TFIDone);␊ |
838 | ␉␉␉␉␉verbose("P-State: Added [TurboFreq %d MHz, FID 0x%x]\n", tfreq_one, TFIDone);␊ |
839 | ␉␉␉␉}␊ |
840 | ␊ |
841 | ␉␉␉␉if((tfreq_one != tfreq_two) && (tfreq_two > 0))␊ |
842 | ␉␉␉␉{␊ |
843 | ␉␉␉␉␉struct aml_chunk* psturbo2 = aml_add_package(pack_pss);␊ |
844 | ␉␉␉␉␉aml_add_dword(psturbo2, tfreq_two);␊ |
845 | ␉␉␉␉␉aml_add_dword(psturbo2, 0x00000000); // Power␊ |
846 | ␉␉␉␉␉aml_add_dword(psturbo2, 0x0000000A); // Latency␊ |
847 | ␉␉␉␉␉aml_add_dword(psturbo2, 0x0000000A); // Latency␊ |
848 | ␉␉␉␉␉aml_add_dword(psturbo2, TFIDtwo);␊ |
849 | ␉␉␉␉␉aml_add_dword(psturbo2, TFIDtwo);␊ |
850 | ␉␉␉␉␉verbose("P-State: Added [TurboFreq %d MHz, FID 0x%x]\n", tfreq_two, TFIDtwo);␊ |
851 | ␉␉␉␉}␊ |
852 | ␊ |
853 | ␉␉␉␉if((tfreq_two != tfreq_thr) && (tfreq_thr > 0))␊ |
854 | ␉␉␉␉{␊ |
855 | ␉␉␉␉␉struct aml_chunk* psturbo3 = aml_add_package(pack_pss);␊ |
856 | ␉␉␉␉␉aml_add_dword(psturbo3, tfreq_thr);␊ |
857 | ␉␉␉␉␉aml_add_dword(psturbo3, 0x00000000); // Power␊ |
858 | ␉␉␉␉␉aml_add_dword(psturbo3, 0x0000000A); // Latency␊ |
859 | ␉␉␉␉␉aml_add_dword(psturbo3, 0x0000000A); // Latency␊ |
860 | ␉␉␉␉␉aml_add_dword(psturbo3, TFIDthr);␊ |
861 | ␉␉␉␉␉aml_add_dword(psturbo3, TFIDthr);␊ |
862 | ␉␉␉␉␉verbose("P-State: Added [TurboFreq %d MHz, FID 0x%x]\n", tfreq_thr, TFIDthr);␊ |
863 | ␉␉␉␉}␊ |
864 | ␊ |
865 | ␉␉␉␉if((tfreq_thr != tfreq_for) && (tfreq_for > 0))␊ |
866 | ␉␉␉␉{␊ |
867 | ␉␉␉␉␉struct aml_chunk* psturbo4 = aml_add_package(pack_pss);␊ |
868 | ␉␉␉␉␉aml_add_dword(psturbo4, tfreq_for);␊ |
869 | ␉␉␉␉␉aml_add_dword(psturbo4, 0x00000000); // Power␊ |
870 | ␉␉␉␉␉aml_add_dword(psturbo4, 0x0000000A); // Latency␊ |
871 | ␉␉␉␉␉aml_add_dword(psturbo4, 0x0000000A); // Latency␊ |
872 | ␉␉␉␉␉aml_add_dword(psturbo4, TFIDfor);␊ |
873 | ␉␉␉␉␉aml_add_dword(psturbo4, TFIDfor);␊ |
874 | ␉␉␉␉␉verbose("P-State: Added [TurboFreq %d MHz, FID 0x%x]\n", tfreq_for, TFIDfor);␊ |
875 | ␉␉␉␉}␊ |
876 | ␉␉␉}␊ |
877 | */␊ |
878 | ␉␉␉for (i = pstart; i < p_states_count; i++)␊ |
879 | ␉␉␉{␊ |
880 | ␉␉␉␉if ((p_states[i].Frequency <= freq_max) && (p_states[i].Frequency >= freq_min))␊ |
881 | ␉␉␉␉{␊ |
882 | ␉␉␉␉␉//valv: inspired from cparm's pss-drop; coded by me ;)␊ |
883 | ␉␉␉␉␉if ((i > pstates) && (pstates > 0))␊ |
884 | ␉␉␉␉␉{␊ |
885 | ␉␉␉␉␉␉if(Platform.CPU.ISerie) verbose("P-State: [Frequency %d MHz, FID 0x%x] is the %dth state. Removed!\n",␊ |
886 | ␉␉␉␉␉␉␉␉p_states[i].Frequency, p_states[i].FID, (i+1));␊ |
887 | ␉␉␉␉␉␉else verbose("P-State: [Frequency %d MHz, FID 0x%x, VID 0x%x] is the %dth state. Removed!\n",␊ |
888 | ␉␉␉␉␉␉␉␉p_states[i].Frequency, p_states[i].FID, p_states[i].VID, (i+1));␊ |
889 | ␉␉␉␉␉}␊ |
890 | ␉␉␉␉␉else␊ |
891 | ␉␉␉␉␉{␊ |
892 | ␉␉␉␉␉␉struct aml_chunk* pstt = aml_add_package(pack_pss);␊ |
893 | ␊ |
894 | ␉␉␉␉␉␉aml_add_dword(pstt, p_states[i].Frequency);␊ |
895 | ␉␉␉␉␉␉aml_add_dword(pstt, 0x00000000); // Power␊ |
896 | ␉␉␉␉␉␉aml_add_dword(pstt, 0x0000000A); // Latency␊ |
897 | ␉␉␉␉␉␉aml_add_dword(pstt, 0x0000000A); // Latency␊ |
898 | ␉␉␉␉␉␉if(Platform.CPU.ISerie)␊ |
899 | ␉␉␉␉␉␉{␊ |
900 | ␉␉␉␉␉␉␉aml_add_dword(pstt, p_states[i].FID);␊ |
901 | ␉␉␉␉␉␉␉aml_add_dword(pstt, p_states[i].FID);␊ |
902 | ␉␉␉␉␉␉␉verbose("P-State: Added [Frequency %d MHz, FID 0x%x]\n", p_states[i].Frequency, p_states[i].FID);␊ |
903 | ␉␉␉␉␉␉}␊ |
904 | ␉␉␉␉␉␉else␊ |
905 | ␉␉␉␉␉␉{␊ |
906 | ␉␉␉␉␉␉␉aml_add_dword(pstt, p_states[i].Control);␊ |
907 | ␉␉␉␉␉␉␉aml_add_dword(pstt, p_states[i].Control);␊ |
908 | ␉␉␉␉␉␉␉//aml_add_dword(pstt, i+1); // Status␊ |
909 | ␉␉␉␉␉␉␉verbose("P-State: Added [Frequency %d MHz, FID 0x%x, VID 0x%x]\n",␊ |
910 | ␉␉␉␉␉␉␉␉p_states[i].Frequency, p_states[i].FID, p_states[i].VID);␊ |
911 | ␉␉␉␉␉␉}␊ |
912 | ␉␉␉␉␉}␊ |
913 | ␉␉␉␉}␊ |
914 | ␉␉␉␉else␊ |
915 | ␉␉␉␉{␊ |
916 | ␉␉␉␉␉if(Platform.CPU.ISerie) verbose("P-State: [Frequency %d MHz, FID 0x%x] is over the limit. Removed!\n",␊ |
917 | ␉␉␉␉␉␉␉p_states[i].Frequency, p_states[i].FID);␊ |
918 | ␉␉␉␉␉else verbose("P-State: [Frequency %d MHz, FID 0x%x, VID 0x%x] is over the limit. Removed!\n",␊ |
919 | ␉␉␉␉␉␉␉p_states[i].Frequency, p_states[i].FID, p_states[i].VID);␊ |
920 | ␉␉␉␉}␊ |
921 | ␉␉␉}␊ |
922 | ␉␉␉␊ |
923 | ␉␉␉struct aml_chunk* name_ppc = aml_add_name(scop, "PPC_");␊ |
924 | ␉␉␉/*struct aml_chunk* pack_ppc = aml_add_package(name_ppc);␊ |
925 | ␉␉␉struct aml_chunk* ppc = aml_add_package(pack_ppc);*/␊ |
926 | ␉␉␉aml_add_byte(name_ppc, 0x00);␊ |
927 | ␉␉␉␊ |
928 | ␉␉␉// Add aliaces␊ |
929 | ␉␉␉for (i = 0; i < acpi_cpu_count; i++) ␊ |
930 | ␉␉␉{␊ |
931 | ␉␉␉␉char name[9];␊ |
932 | ␉␉␉␉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]);␊ |
933 | ␉␉␉␉␊ |
934 | ␉␉␉␉scop = aml_add_scope(root, name);␊ |
935 | ␉␉␉␉aml_add_alias(scop, "PCT_", "_PCT");␊ |
936 | ␉␉␉␉aml_add_alias(scop, "PSD_", "_PSD");␊ |
937 | ␉␉␉␉aml_add_alias(scop, "PSS_", "_PSS");␊ |
938 | ␉␉␉␉aml_add_alias(scop, "PPC_", "_PPC");␊ |
939 | ␉␉␉}␊ |
940 | ␉␉␉␊ |
941 | ␉␉␉aml_calculate_size(root);␊ |
942 | ␉␉␉␊ |
943 | ␉␉␉struct acpi_2_ssdt *ssdt = (struct acpi_2_ssdt *)AllocateKernelMemory(root->Size);␊ |
944 | ␉␉␉␊ |
945 | ␉␉␉aml_write_node(root, (void*)ssdt, 0);␊ |
946 | ␉␉␉␊ |
947 | ␉␉␉ssdt->Length = root->Size;␊ |
948 | ␉␉␉ssdt->Checksum = 0;␊ |
949 | ␉␉␉ssdt->Checksum = 256 - checksum8(ssdt, ssdt->Length);␊ |
950 | ␊ |
951 | aml_destroy_node(root);␊ |
952 | ␉␉␉␊ |
953 | ␉␉␉//verbose ("SSDT with CPU P-States generated successfully\n");␊ |
954 | ␉␉␉␊ |
955 | ␉␉␉return ssdt;␊ |
956 | ␉␉}␊ |
957 | ␉}␊ |
958 | ␉else {␊ |
959 | ␉␉verbose ("ACPI CPUs not found: P-States not generated !!!\n");␊ |
960 | ␉}␊ |
961 | ␉␊ |
962 | ␉return NULL;␊ |
963 | }␊ |
964 | ␊ |
965 | /*valv: to be uncommented when finished ;)␊ |
966 | struct acpi_2_ssdt *generate_tss_ssdt(struct acpi_2_dsdt* dsdt)␊ |
967 | {␊ |
968 | ␉char ssdt_header[] =␊ |
969 | ␉{␊ |
970 | 0x53, 0x53, 0x44, 0x54, 0xE7, 0x00, 0x00, 0x00,␊ |
971 | 0x01, 0x17, 0x50, 0x6D, 0x52, 0x65, 0x66, 0x42,␊ |
972 | 0x43, 0x70, 0x75, 0x54, 0x73, 0x74, 0x00, 0x00,␊ |
973 | 0x00, 0x10, 0x00, 0x00, 0x49, 0x4E, 0x54, 0x4C,␊ |
974 | 0x31, 0x03, 0x10, 0x20␊ |
975 | ␉};␊ |
976 | ␉␊ |
977 | ␉char ssdt_ptc[] =␊ |
978 | ␉{␊ |
979 | ␉␉0x08, 0x5F, 0x50, 0x54, 0x43, 0x12, 0x2C, 0x02,␊ |
980 | ␉␉0x11, 0x14, 0x0A, 0x11, 0x82, 0x0C, 0x00, 0x7F,␊ |
981 | ␉␉0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,␊ |
982 | ␉␉0x00, 0x00, 0x00, 0x79, 0x00, 0x11, 0x14, 0x0A,␊ |
983 | ␉␉0x11, 0x82, 0x0C, 0x00, 0x7F, 0x00, 0x00, 0x00,␊ |
984 | ␉␉0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,␊ |
985 | ␉␉0x79, 0x00␊ |
986 | ␉};␊ |
987 | }*/␊ |
988 | ␊ |
989 | void *loadSSDTTable(int ssdt_number)␊ |
990 | {␊ |
991 | ␉void *tableAddr;␊ |
992 | ␉int fd = -1;␊ |
993 | ␉char dirspec[512];␊ |
994 | ␉char filename[512];␊ |
995 | ␉const char * overriden_pathname=NULL;␊ |
996 | ␉int len=0;␊ |
997 | ␊ |
998 | ␉sprintf(filename, "SSDT-%d.aml", ssdt_number);␊ |
999 | ␉␊ |
1000 | ␉// Check booting partition␊ |
1001 | ␉␊ |
1002 | ␉// Rek: if user specified a full path name then take it in consideration␊ |
1003 | ␉if (getValueForKey(kSSDT, &overriden_pathname, &len, &bootInfo->bootConfig))␊ |
1004 | ␉{␊ |
1005 | ␉␉sprintf(dirspec, "%s-%d.aml", overriden_pathname, ssdt_number); // start searching root␊ |
1006 | ␉␉//printf("Using custom %s path %s\n", key, dirspec);␊ |
1007 | ␉␉//getc();␊ |
1008 | ␉}␊ |
1009 | ␉else␊ |
1010 | ␉␉sprintf(dirspec, "/%s", filename); // start searching root␊ |
1011 | ␉␊ |
1012 | ␉fd=open (dirspec,0);␊ |
1013 | ␉␊ |
1014 | ␉if (fd<0)␊ |
1015 | ␉{␉// Check Extra on booting partition␊ |
1016 | ␉␉//verbose("Searching for %s.aml file ...\n", key);␊ |
1017 | ␉␉sprintf(dirspec,"/Extra/%s",filename);␊ |
1018 | ␉␉fd=open (dirspec,0);␊ |
1019 | ␉␉if (fd<0)␊ |
1020 | ␉␉{␉// Fall back to booter partition␊ |
1021 | ␉␉␉sprintf(dirspec,"bt(0,0)/Extra/%s",filename);␊ |
1022 | ␉␉␉fd=open (dirspec,0);␊ |
1023 | ␉␉␉if (fd<0)␊ |
1024 | ␉␉␉{␊ |
1025 | ␉␉␉␉//verbose("SSDT Table not found: %s\n", filename);␊ |
1026 | ␉␉␉␉return NULL;␊ |
1027 | ␉␉␉}␊ |
1028 | ␉␉}␊ |
1029 | ␉}␊ |
1030 | ␉␊ |
1031 | ␉tableAddr=(void*)AllocateKernelMemory(file_size (fd));␊ |
1032 | ␉if (tableAddr)␊ |
1033 | ␉{␊ |
1034 | ␉␉if (read (fd, tableAddr, file_size (fd))!=file_size (fd))␊ |
1035 | ␉␉{␊ |
1036 | ␉␉␉printf("Couldn't read table %s\n",dirspec);␊ |
1037 | ␉␉␉free (tableAddr);␊ |
1038 | ␉␉␉close (fd);␊ |
1039 | ␉␉␉return NULL;␊ |
1040 | ␉␉}␊ |
1041 | ␉␉␊ |
1042 | ␉␉DBG("Table %s read and stored at: %x\n", dirspec, tableAddr);␊ |
1043 | ␉␉close (fd);␊ |
1044 | ␉␉return tableAddr;␊ |
1045 | ␉}␊ |
1046 | ␉␊ |
1047 | ␉printf("Couldn't allocate memory for table %s\n", dirspec);␊ |
1048 | ␉close (fd);␊ |
1049 | ␉␊ |
1050 | ␉return NULL;␊ |
1051 | }␊ |
1052 | ␊ |
1053 | struct acpi_2_gas FillGASStruct(uint32_t Address, uint8_t Length)␊ |
1054 | {␊ |
1055 | ␉struct acpi_2_gas TmpGAS;␊ |
1056 | ␊ |
1057 | ␉TmpGAS.Address_Space_ID = 1; /* I/O Address */␊ |
1058 | ␊ |
1059 | ␉if (Address == 0)␊ |
1060 | ␉{␊ |
1061 | ␉␉TmpGAS.Register_Bit_Width = 0;␊ |
1062 | ␉} else {␊ |
1063 | ␉␉TmpGAS.Register_Bit_Width = Length * 8;␊ |
1064 | ␉}␊ |
1065 | ␊ |
1066 | ␉TmpGAS.Register_Bit_Offset = 0;␊ |
1067 | ␉TmpGAS.Access_Size = 0; /* Not set for Legacy reasons... */␊ |
1068 | ␉TmpGAS.Address = (uint64_t)Address;␊ |
1069 | ␊ |
1070 | ␉return(TmpGAS);␊ |
1071 | }␊ |
1072 | ␊ |
1073 | struct acpi_2_fadt *patch_fadt(struct acpi_2_fadt *fadt, void *new_dsdt, bool UpdateFADT)␊ |
1074 | {␊ |
1075 | extern void setupSystemType(); ␊ |
1076 | ␉␊ |
1077 | ␉struct acpi_2_fadt *fadt_mod;␊ |
1078 | ␉struct acpi_2_fadt *fadt_file = (struct acpi_2_fadt *)loadACPITable(kFADT);␊ |
1079 | ␉bool fadt_rev2_needed = false;␊ |
1080 | ␉bool fix_restart;␊ |
1081 | ␉const char * value;␊ |
1082 | ␊ |
1083 | ␉// Restart Fix␊ |
1084 | ␉if (Platform.CPU.Vendor == 0x756E6547) {␉/* Intel */␊ |
1085 | ␉␉fix_restart = true;␊ |
1086 | ␉␉getBoolForKey(kRestartFix, &fix_restart, &bootInfo->bootConfig);␊ |
1087 | ␉} else {␊ |
1088 | ␉␉verbose ("Not an Intel platform: Restart Fix not applied !!!\n");␊ |
1089 | ␉␉fix_restart = false;␊ |
1090 | ␉}␊ |
1091 | ␊ |
1092 | ␉if (fix_restart)␊ |
1093 | ␉␉fadt_rev2_needed = true;␊ |
1094 | ␊ |
1095 | ␉// Allocate new fadt table␊ |
1096 | ␉if ((UpdateFADT) && (((fadt_file) && (fadt_file->Length < sizeof(struct acpi_2_fadt))) ||␊ |
1097 | ␉␉␉␉␉␉ ((!fadt_file) && (fadt->Length < sizeof(struct acpi_2_fadt)))))␊ |
1098 | ␉{␊ |
1099 | ␉␉fadt_mod=(struct acpi_2_fadt *)AllocateKernelMemory(sizeof(struct acpi_2_fadt));␊ |
1100 | ␊ |
1101 | ␉␉if (fadt_file)␊ |
1102 | ␉␉␉memcpy(fadt_mod, fadt_file, fadt_file->Length);␊ |
1103 | ␉␉else␊ |
1104 | ␉␉␉memcpy(fadt_mod, fadt, fadt->Length);␊ |
1105 | ␊ |
1106 | ␉␉fadt_mod->Length = sizeof(struct acpi_2_fadt);␊ |
1107 | ␉␉fadt_mod->Revision = 0x04; // FADT rev 4␊ |
1108 | ␉␉fadt_mod->RESET_REG = FillGASStruct(0, 0);␊ |
1109 | ␉␉fadt_mod->RESET_VALUE = 0;␊ |
1110 | ␉␉fadt_mod->Reserved2[0] = 0;␊ |
1111 | ␉␉fadt_mod->Reserved2[1] = 0;␊ |
1112 | ␉␉fadt_mod->Reserved2[2] = 0;␊ |
1113 | ␉␉fadt_mod->X_PM1a_EVT_BLK = FillGASStruct(fadt_mod->PM1a_EVT_BLK, fadt_mod->PM1_EVT_LEN);␊ |
1114 | ␉␉fadt_mod->X_PM1b_EVT_BLK = FillGASStruct(fadt_mod->PM1b_EVT_BLK, fadt_mod->PM1_EVT_LEN);␊ |
1115 | ␉␉fadt_mod->X_PM1a_CNT_BLK = FillGASStruct(fadt_mod->PM1a_CNT_BLK, fadt_mod->PM1_CNT_LEN);␊ |
1116 | ␉␉fadt_mod->X_PM1b_CNT_BLK = FillGASStruct(fadt_mod->PM1b_CNT_BLK, fadt_mod->PM1_CNT_LEN);␊ |
1117 | ␉␉fadt_mod->X_PM2_CNT_BLK = FillGASStruct(fadt_mod->PM2_CNT_BLK, fadt_mod->PM2_CNT_LEN);␊ |
1118 | ␉␉fadt_mod->X_PM_TMR_BLK = FillGASStruct(fadt_mod->PM_TMR_BLK, fadt_mod->PM_TMR_LEN);␊ |
1119 | ␉␉fadt_mod->X_GPE0_BLK = FillGASStruct(fadt_mod->GPE0_BLK, fadt_mod->GPE0_BLK_LEN);␊ |
1120 | ␉␉fadt_mod->X_GPE1_BLK = FillGASStruct(fadt_mod->GPE1_BLK, fadt_mod->GPE1_BLK_LEN);␊ |
1121 | ␉␉verbose("Converted ACPI V%d FADT to ACPI V4 FADT\n", (fadt_file) ? fadt_file->Revision : fadt->Revision);␊ |
1122 | ␉} else {␊ |
1123 | ␉␉if (((!fadt_file) && ((fadt->Length < 0x84) && (fadt_rev2_needed))) ||␊ |
1124 | ␉␉␉ ((fadt_file) && ((fadt_file->Length < 0x84) && (fadt_rev2_needed))))␊ |
1125 | ␉␉{␊ |
1126 | ␉␉␉fadt_mod=(struct acpi_2_fadt *)AllocateKernelMemory(0x84);␊ |
1127 | ␊ |
1128 | ␉␉␉if (fadt_file)␊ |
1129 | ␉␉␉␉memcpy(fadt_mod, fadt_file, fadt_file->Length);␊ |
1130 | ␉␉␉else␊ |
1131 | ␉␉␉␉memcpy(fadt_mod, fadt, fadt->Length);␊ |
1132 | ␊ |
1133 | ␉␉␉fadt_mod->Length = 0x84;␊ |
1134 | ␉␉␉fadt_mod->Revision = 0x02; // FADT rev 2 (ACPI 1.0B MS extensions)␊ |
1135 | ␉␉}␊ |
1136 | ␉␉else␊ |
1137 | ␉␉{␊ |
1138 | ␉␉␉if (fadt_file)␊ |
1139 | ␉␉␉{␊ |
1140 | ␉␉␉␉fadt_mod=(struct acpi_2_fadt *)AllocateKernelMemory(fadt_file->Length);␊ |
1141 | ␉␉␉␉memcpy(fadt_mod, fadt_file, fadt_file->Length);␊ |
1142 | ␉␉␉} else {␊ |
1143 | ␉␉␉␉fadt_mod=(struct acpi_2_fadt *)AllocateKernelMemory(fadt->Length);␊ |
1144 | ␉␉␉␉memcpy(fadt_mod, fadt, fadt->Length);␊ |
1145 | ␉␉␉}␊ |
1146 | ␉␉}␊ |
1147 | ␉}␊ |
1148 | ␉// Determine system type / PM_Model␊ |
1149 | ␉if ( (value=getStringForKey(kSystemType, &bootInfo->bootConfig))!=NULL)␊ |
1150 | ␉{␊ |
1151 | ␉ if (Platform.Type > 6) ␊ |
1152 | ␉ {␊ |
1153 | ␉ if(fadt_mod->Preferred_PM_Profile<=6)␊ |
1154 | ␉ Platform.Type = fadt_mod->Preferred_PM_Profile; // get the fadt if correct␊ |
1155 | ␉ else ␊ |
1156 | ␉ Platform.Type = 1;␉␉/* Set a fixed value (Desktop) */␊ |
1157 | ␉ verbose("Error: system-type must be 0..6. Defaulting to %d !\n", Platform.Type);␊ |
1158 | ␉ }␊ |
1159 | ␉ else␊ |
1160 | ␉ Platform.Type = (unsigned char) strtoul(value, NULL, 10);␊ |
1161 | ␉}␊ |
1162 | ␉// Set Preferred_PM_Profile from System-type only if user wanted this value to be forced␊ |
1163 | ␉if (fadt_mod->Preferred_PM_Profile != Platform.Type) ␊ |
1164 | ␉{␊ |
1165 | ␉ if (value) ␊ |
1166 | ␉ { // user has overriden the SystemType so take care of it in FACP␊ |
1167 | ␉␉verbose("FADT: changing Preferred_PM_Profile from 0x%02x to 0x%02x\n", fadt_mod->Preferred_PM_Profile, Platform.Type);␊ |
1168 | ␉␉fadt_mod->Preferred_PM_Profile = Platform.Type;␊ |
1169 | ␉ }␊ |
1170 | ␉ else␊ |
1171 | ␉ { // Preferred_PM_Profile has a different value and no override has been set, so reflect the user value to ioregs␊ |
1172 | ␉ Platform.Type = fadt_mod->Preferred_PM_Profile <= 6 ? fadt_mod->Preferred_PM_Profile : 1;␊ |
1173 | ␉ } ␊ |
1174 | ␉}␊ |
1175 | ␉// We now have to write the systemm-type in ioregs: we cannot do it before in setupDeviceTree()␊ |
1176 | ␉// because we need to take care of facp original content, if it is correct.␊ |
1177 | ␉setupSystemType();␊ |
1178 | ␊ |
1179 | ␉// Patch FADT to fix restart␊ |
1180 | ␉if (fix_restart)␊ |
1181 | ␉{␊ |
1182 | ␉␉fadt_mod->Flags|= 0x400;␊ |
1183 | ␉␉fadt_mod->RESET_REG = FillGASStruct(0x0cf9, 1);␊ |
1184 | ␉␉fadt_mod->RESET_VALUE = 0x06;␊ |
1185 | ␉␉␊ |
1186 | ␉␉verbose("FADT: Restart Fix applied !\n");␊ |
1187 | ␉}␊ |
1188 | ␊ |
1189 | ␉// Patch FACS Address␊ |
1190 | ␉fadt_mod->FIRMWARE_CTRL=(uint32_t)fadt->FIRMWARE_CTRL;␊ |
1191 | ␉if ((uint32_t)(&(fadt_mod->X_FIRMWARE_CTRL))-(uint32_t)fadt_mod+8<=fadt_mod->Length)␊ |
1192 | ␉␉fadt_mod->X_FIRMWARE_CTRL=(uint32_t)fadt->FIRMWARE_CTRL;␊ |
1193 | ␊ |
1194 | ␉// Patch DSDT Address if we have one loaded␊ |
1195 | ␉if(new_dsdt)␊ |
1196 | ␉{␊ |
1197 | ␉␉fadt_mod->DSDT=(uint32_t)new_dsdt;␊ |
1198 | ␉␉if ((uint32_t)(&(fadt_mod->X_DSDT))-(uint32_t)fadt_mod+8<=fadt_mod->Length)␊ |
1199 | ␉␉␉fadt_mod->X_DSDT=(uint32_t)new_dsdt;␊ |
1200 | ␉}␊ |
1201 | ␊ |
1202 | ␊ |
1203 | ␉// Correct the checksum␊ |
1204 | ␉fadt_mod->Checksum=0;␊ |
1205 | ␉fadt_mod->Checksum=256-checksum8(fadt_mod,fadt_mod->Length);␊ |
1206 | ␊ |
1207 | ␉return fadt_mod;␊ |
1208 | }␊ |
1209 | #if UNUSED␊ |
1210 | /* Setup ACPI without replacing DSDT. */␊ |
1211 | int setupAcpiNoMod()␊ |
1212 | {␊ |
1213 | //␉addConfigurationTable(&gEfiAcpiTableGuid, getAddressOfAcpiTable(), "ACPI");␊ |
1214 | //␉addConfigurationTable(&gEfiAcpi20TableGuid, getAddressOfAcpi20Table(), "ACPI_20");␊ |
1215 | ␉/* XXX aserebln why uint32 cast if pointer is uint64 ? */␊ |
1216 | ␉acpi10_p = (uint32_t)getAddressOfAcpiTable();␊ |
1217 | ␉acpi20_p = (uint32_t)getAddressOfAcpi20Table();␊ |
1218 | ␉addConfigurationTable(&gEfiAcpiTableGuid, &acpi10_p, "ACPI");␊ |
1219 | ␉if(acpi20_p) addConfigurationTable(&gEfiAcpi20TableGuid, &acpi20_p, "ACPI_20");␊ |
1220 | ␉return 1;␊ |
1221 | }␊ |
1222 | #endif␊ |
1223 | ␊ |
1224 | /* Setup ACPI. Replace DSDT if DSDT.aml is found */␊ |
1225 | int setupAcpi(void)␊ |
1226 | {␊ |
1227 | ␉int version;␊ |
1228 | ␉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];␊ |
1229 | ␊ |
1230 | ␉struct acpi_2_ssdt *new_ssdt[16]; // 2 additional tables for pss/tss & cst␊ |
1231 | ␉struct acpi_2_fadt *fadt; // will be used in CST generator␊ |
1232 | ␊ |
1233 | ␉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;␊ |
1234 | ␉bool drop_ssdt=false, drop_hpet=false, drop_slic=false, drop_sbst=false, drop_ecdt=false, drop_asft=false, drop_dmar=false;␊ |
1235 | ␉bool update_acpi=false, gen_xsdt=false;␊ |
1236 | ␉bool hpet_replaced=false, sbst_replaced=false, ecdt_replaced=false, asft_replaced=false, dmar_replaced=false, apic_replaced=false, mcfg_replaced=false;␊ |
1237 | ␉bool hpet_added=false, sbst_added=false, ecdt_added=false, asft_added=false, dmar_added=false, apic_added=false, mcfg_added=false;␊ |
1238 | ␉bool gen_cst=false, gen_pss=false;//, gen_tss=false;␊ |
1239 | ␊ |
1240 | ␉int curssdt=0, loadtotssdt=0, totssdt=0, newtotssdt=0;␊ |
1241 | ␊ |
1242 | ␉{␊ |
1243 | ␉␉bool tmpval, tmpval2, tmpval3, tmpval4, tmpval6;␊ |
1244 | ␊ |
1245 | ␉␉drop_ssdt = getBoolForKey(kDropSSDT, &tmpval, &bootInfo->bootConfig)&&tmpval;␊ |
1246 | ␉␉drop_hpet = getBoolForKey(kDropHPET, &tmpval, &bootInfo->bootConfig)&&tmpval;␊ |
1247 | ␉␉drop_slic = getBoolForKey(kDropSLIC, &tmpval, &bootInfo->bootConfig)&&tmpval;␊ |
1248 | ␉␉drop_sbst = getBoolForKey(kDropSBST, &tmpval, &bootInfo->bootConfig)&&tmpval;␊ |
1249 | ␉␉drop_ecdt = getBoolForKey(kDropECDT, &tmpval, &bootInfo->bootConfig)&&tmpval;␊ |
1250 | ␉␉drop_asft = getBoolForKey(kDropASFT, &tmpval, &bootInfo->bootConfig)&&tmpval;␊ |
1251 | ␉␉drop_dmar = getBoolForKey(kDropDMAR, &tmpval, &bootInfo->bootConfig)&&tmpval;␊ |
1252 | ␊ |
1253 | ␉␉oem_dsdt = getBoolForKey(kOEMDSDT, &tmpval, &bootInfo->bootConfig)&&tmpval;␊ |
1254 | ␉␉oem_ssdt = getBoolForKey(kOEMSSDT, &tmpval, &bootInfo->bootConfig)&&tmpval;␊ |
1255 | ␉␉oem_hpet = getBoolForKey(kOEMHPET, &tmpval, &bootInfo->bootConfig)&&tmpval;␊ |
1256 | ␉␉oem_sbst = getBoolForKey(kOEMSBST, &tmpval, &bootInfo->bootConfig)&&tmpval;␊ |
1257 | ␉␉oem_ecdt = getBoolForKey(kOEMECDT, &tmpval, &bootInfo->bootConfig)&&tmpval;␊ |
1258 | ␉␉oem_asft = getBoolForKey(kOEMASFT, &tmpval, &bootInfo->bootConfig)&&tmpval;␊ |
1259 | ␉␉oem_dmar = getBoolForKey(kOEMDMAR, &tmpval, &bootInfo->bootConfig)&&tmpval;␊ |
1260 | ␉␉oem_apic = getBoolForKey(kOEMAPIC, &tmpval, &bootInfo->bootConfig)&&tmpval;␊ |
1261 | ␉␉oem_mcfg = getBoolForKey(kOEMMCFG, &tmpval, &bootInfo->bootConfig)&&tmpval;␊ |
1262 | ␊ |
1263 | ␉␉gen_cst = (getBoolForKey(kGenerateCStates, &tmpval, &bootInfo->bootConfig)&&tmpval)␊ |
1264 | ␉␉␉␉| (getBoolForKey(kEnableC2State, &tmpval2, &bootInfo->bootConfig)&&tmpval2)␊ |
1265 | ␉␉␉␉| (getBoolForKey(kEnableC3State, &tmpval3, &bootInfo->bootConfig)&&tmpval3)␊ |
1266 | ␉␉␉␉| (getBoolForKey(kEnableC4State, &tmpval4, &bootInfo->bootConfig)&&tmpval4)␊ |
1267 | ␉␉␉␉| (getBoolForKey(kEnableC6State, &tmpval6, &bootInfo->bootConfig)&&tmpval6);␊ |
1268 | ␊ |
1269 | ␉␉gen_pss = getBoolForKey(kGeneratePStates, &tmpval, &bootInfo->bootConfig)&&tmpval;␊ |
1270 | ␊ |
1271 | //␉␉gen_tss = getBoolForKey(kGenerateTStates, &tmpval, &bootInfo->bootConfig)&&tmpval;␊ |
1272 | ␊ |
1273 | ␉␉update_acpi = getBoolForKey(kUpdateACPI, &tmpval, &bootInfo->bootConfig)&&tmpval;␊ |
1274 | ␉}␊ |
1275 | ␊ |
1276 | ␉// Load replacement ACPI tables␊ |
1277 | ␉if (!oem_dsdt)␊ |
1278 | ␉␉new_dsdt=loadACPITable(kDSDT);␊ |
1279 | ␊ |
1280 | ␉if (!oem_hpet)␊ |
1281 | ␉␉new_hpet=loadACPITable(kHPET);␊ |
1282 | ␊ |
1283 | ␉if (!oem_sbst)␊ |
1284 | ␉␉new_sbst=loadACPITable(kSBST);␊ |
1285 | ␊ |
1286 | ␉if (!oem_ecdt)␊ |
1287 | ␉␉new_ecdt=loadACPITable(kECDT);␊ |
1288 | ␊ |
1289 | ␉if (!oem_asft)␊ |
1290 | ␉␉new_asft=loadACPITable(kASFT);␊ |
1291 | ␊ |
1292 | ␉if (!oem_dmar)␊ |
1293 | ␉␉new_dmar=loadACPITable(kDMAR);␊ |
1294 | ␊ |
1295 | ␉if (!oem_apic)␊ |
1296 | ␉␉new_apic=loadACPITable(kAPIC);␊ |
1297 | ␊ |
1298 | ␉if (!oem_mcfg)␊ |
1299 | ␉␉new_mcfg=loadACPITable(kMCFG);␊ |
1300 | ␊ |
1301 | ␉if (gen_cst || gen_pss/* || gen_tss*/) oem_ssdt = false;␊ |
1302 | ␊ |
1303 | ␉if (!oem_ssdt)␊ |
1304 | ␉{␊ |
1305 | ␉␉for (curssdt=0;curssdt<14;curssdt++)␊ |
1306 | ␉␉{␊ |
1307 | ␉␉␉new_ssdt[curssdt]=loadSSDTTable(curssdt);␊ |
1308 | ␉␉␉if (new_ssdt[curssdt])␊ |
1309 | ␉␉␉␉loadtotssdt++;␊ |
1310 | ␉␉}␊ |
1311 | ␉␉curssdt=0;␊ |
1312 | ␉}␊ |
1313 | /*␊ |
1314 | ␉if (!new_dsdt)␊ |
1315 | ␉␉return setupAcpiNoMod();␊ |
1316 | */␊ |
1317 | ␉DBG("New ACPI tables Loaded in memory\n");␊ |
1318 | ␉␉␉␊ |
1319 | ␉// Do the same procedure for both versions of ACPI␊ |
1320 | ␉for (version=0; version<2; version++) {␊ |
1321 | ␉␉struct acpi_2_rsdp *rsdp, *rsdp_mod, *rsdp_conv=(struct acpi_2_rsdp *)0;␊ |
1322 | ␉␉struct acpi_2_rsdt *rsdt, *rsdt_mod;␊ |
1323 | ␉␉struct acpi_2_xsdt *xsdt_conv = (struct acpi_2_xsdt *)0;␊ |
1324 | ␉␉int rsdplength;␊ |
1325 | ␊ |
1326 | ␉␉// Find original rsdp␊ |
1327 | ␉␉rsdp=(struct acpi_2_rsdp *)(version?getAddressOfAcpi20Table():getAddressOfAcpiTable());␊ |
1328 | ␉␉if ((update_acpi) && (rsdp->Revision == 0))␊ |
1329 | ␉␉{␊ |
1330 | ␉␉␉rsdp_conv = (struct acpi_2_rsdp *)AllocateKernelMemory(sizeof(struct acpi_2_rsdp));␊ |
1331 | ␉␉␉memcpy(rsdp_conv, rsdp, 20);␊ |
1332 | ␊ |
1333 | ␉␉␉/* Add/change fields */␊ |
1334 | ␉␉␉strncpy(rsdp->OEMID, "Apple ", 6);␊ |
1335 | ␉␉␉rsdp_conv->Revision = 2; /* ACPI version 3 */␊ |
1336 | ␉␉␉rsdp_conv->Length = sizeof(struct acpi_2_rsdp);␊ |
1337 | ␊ |
1338 | ␉␉␉/* Correct checksums */␊ |
1339 | ␉␉␉rsdp_conv->Checksum = 0;␊ |
1340 | ␉␉␉rsdp_conv->Checksum = 256-checksum8(rsdp_conv, 20);␊ |
1341 | ␉␉␉rsdp_conv->ExtendedChecksum = 0;␊ |
1342 | ␉␉␉rsdp_conv->ExtendedChecksum = 256-checksum8(rsdp_conv, rsdp_conv->Length);␊ |
1343 | ␊ |
1344 | ␉␉␉rsdp = rsdp_conv;␊ |
1345 | ␊ |
1346 | ␉␉␉gen_xsdt = true;␊ |
1347 | ␉␉␉version = 1;␊ |
1348 | ␊ |
1349 | ␉␉␉addConfigurationTable(&gEfiAcpiTableGuid, NULL, "ACPI");␊ |
1350 | ␊ |
1351 | ␉␉␉verbose("Converted ACPI RSD PTR version 1 to version 3\n");␊ |
1352 | ␉␉}␊ |
1353 | ␉␉if (!rsdp)␊ |
1354 | ␉␉{␊ |
1355 | ␉␉␉DBG("No ACPI version %d found. Ignoring\n", version+1);␊ |
1356 | ␉␉␉if (version)␊ |
1357 | ␉␉␉␉addConfigurationTable(&gEfiAcpi20TableGuid, NULL, "ACPI_20");␊ |
1358 | ␉␉␉else␊ |
1359 | ␉␉␉␉addConfigurationTable(&gEfiAcpiTableGuid, NULL, "ACPI");␊ |
1360 | ␉␉␉continue;␊ |
1361 | ␉␉}␊ |
1362 | ␉␉rsdplength=version?rsdp->Length:20;␊ |
1363 | ␊ |
1364 | ␉␉DBG("RSDP version %d found @%x. Length=%d\n",version+1,rsdp,rsdplength);␊ |
1365 | ␊ |
1366 | ␉␉/* FIXME: no check that memory allocation succeeded ␊ |
1367 | ␉␉ * Copy and patch RSDP,RSDT, XSDT and FADT␊ |
1368 | ␉␉ * For more info see ACPI Specification pages 110 and following␊ |
1369 | ␉␉ */␊ |
1370 | ␊ |
1371 | ␉␉if (gen_xsdt)␊ |
1372 | ␉␉{␊ |
1373 | ␉␉␉rsdp_mod=rsdp_conv;␊ |
1374 | ␉␉} else {␊ |
1375 | ␉␉␉rsdp_mod=(struct acpi_2_rsdp *) AllocateKernelMemory(rsdplength);␊ |
1376 | ␉␉␉memcpy(rsdp_mod, rsdp, rsdplength);␊ |
1377 | ␉␉}␊ |
1378 | ␊ |
1379 | ␉␉rsdt=(struct acpi_2_rsdt *)(rsdp->RsdtAddress);␊ |
1380 | ␊ |
1381 | ␉␉DBG("RSDT @%x, Length %d\n",rsdt, rsdt->Length);␊ |
1382 | ␉␉␊ |
1383 | ␉␉if (rsdt && (uint32_t)rsdt !=0xffffffff && rsdt->Length<0x10000)␊ |
1384 | ␉␉{␊ |
1385 | ␉␉␉uint32_t *rsdt_entries;␊ |
1386 | ␉␉␉int rsdt_entries_num;␊ |
1387 | ␉␉␉int dropoffset=0, i;␊ |
1388 | ␉␉␉␊ |
1389 | ␉␉␉rsdt_mod=(struct acpi_2_rsdt *)AllocateKernelMemory(rsdt->Length); ␊ |
1390 | ␉␉␉memcpy (rsdt_mod, rsdt, rsdt->Length);␊ |
1391 | ␉␉␉rsdp_mod->RsdtAddress=(uint32_t)rsdt_mod;␊ |
1392 | ␉␉␉rsdt_entries_num=(rsdt_mod->Length-sizeof(struct acpi_2_rsdt))/4;␊ |
1393 | ␉␉␉rsdt_entries=(uint32_t *)(rsdt_mod+1);␊ |
1394 | ␊ |
1395 | ␉␉␉if (gen_xsdt)␊ |
1396 | ␉␉␉{␊ |
1397 | ␉␉␉␉uint64_t *xsdt_conv_entries;␊ |
1398 | ␊ |
1399 | ␉␉␉␉xsdt_conv=(struct acpi_2_xsdt *)AllocateKernelMemory(sizeof(struct acpi_2_xsdt)+(rsdt_entries_num * 8));␊ |
1400 | ␉␉␉␉memcpy(xsdt_conv, rsdt, sizeof(struct acpi_2_rsdt));␊ |
1401 | ␊ |
1402 | ␉␉␉␉xsdt_conv->Signature[0] = 'X';␊ |
1403 | ␉␉␉␉xsdt_conv->Signature[1] = 'S';␊ |
1404 | ␉␉␉␉xsdt_conv->Signature[2] = 'D';␊ |
1405 | ␉␉␉␉xsdt_conv->Signature[3] = 'T';␊ |
1406 | ␉␉␉␉xsdt_conv->Length = sizeof(struct acpi_2_xsdt)+(rsdt_entries_num * 8);␊ |
1407 | ␊ |
1408 | ␉␉␉␉xsdt_conv_entries=(uint64_t *)(xsdt_conv+1);␊ |
1409 | ␊ |
1410 | ␉␉␉␉for (i=0;i<rsdt_entries_num;i++)␊ |
1411 | ␉␉␉␉{␊ |
1412 | ␉␉␉␉␉xsdt_conv_entries[i] = (uint64_t)rsdt_entries[i];␊ |
1413 | ␉␉␉␉}␊ |
1414 | ␊ |
1415 | ␉␉␉␉xsdt_conv->Checksum = 0;␊ |
1416 | ␉␉␉␉xsdt_conv->Checksum = 256-checksum8(xsdt_conv, xsdt_conv->Length);␊ |
1417 | ␊ |
1418 | ␉␉␉␉rsdp->XsdtAddress = (uint32_t)xsdt_conv;␊ |
1419 | ␊ |
1420 | ␉␉␉␉rsdp->ExtendedChecksum = 0;␊ |
1421 | ␉␉␉␉rsdp->ExtendedChecksum = 256-checksum8(rsdp, rsdp->Length);␊ |
1422 | ␊ |
1423 | ␉␉␉␉verbose("Converted RSDT table to XSDT table\n");␊ |
1424 | ␉␉␉}␊ |
1425 | ␊ |
1426 | ␉␉␉for (i=0;i<rsdt_entries_num;i++)␊ |
1427 | ␉␉␉{␊ |
1428 | ␉␉␉␉char *table=(char *)(rsdt_entries[i]);␊ |
1429 | ␉␉␉␉if (!table)␊ |
1430 | ␉␉␉␉␉continue;␊ |
1431 | ␊ |
1432 | ␉␉␉␉DBG("TABLE %c%c%c%c,",table[0],table[1],table[2],table[3]);␊ |
1433 | ␊ |
1434 | ␉␉␉␉rsdt_entries[i-dropoffset]=rsdt_entries[i];␊ |
1435 | ␉␉␉␉if (drop_ssdt && table[0]=='S' && table[1]=='S' && table[2]=='D' && table[3]=='T')␊ |
1436 | ␉␉␉␉{␊ |
1437 | ␉␉␉␉␉dropoffset++;␊ |
1438 | ␉␉␉␉␉continue;␊ |
1439 | ␉␉␉␉}␊ |
1440 | ␉␉␉␉if (drop_hpet && table[0]=='H' && table[1]=='P' && table[2]=='E' && table[3]=='T')␊ |
1441 | ␉␉␉␉{␊ |
1442 | ␉␉␉␉␉dropoffset++;␊ |
1443 | ␉␉␉␉␉continue;␊ |
1444 | ␉␉␉␉}␉␉␉␊ |
1445 | ␉␉␉␉if (drop_slic && table[0]=='S' && table[1]=='L' && table[2]=='I' && table[3]=='C')␊ |
1446 | ␉␉␉␉{␊ |
1447 | ␉␉␉␉␉dropoffset++;␊ |
1448 | ␉␉␉␉␉continue;␊ |
1449 | ␉␉␉␉}␊ |
1450 | ␉␉␉␉if (drop_sbst && table[0]=='S' && table[1]=='B' && table[2]=='S' && table[3]=='T')␊ |
1451 | ␉␉␉␉{␊ |
1452 | ␉␉␉␉␉dropoffset++;␊ |
1453 | ␉␉␉␉␉continue;␊ |
1454 | ␉␉␉␉}␊ |
1455 | ␉␉␉␉if (drop_ecdt && table[0]=='E' && table[1]=='C' && table[2]=='D' && table[3]=='T')␊ |
1456 | ␉␉␉␉{␊ |
1457 | ␉␉␉␉␉dropoffset++;␊ |
1458 | ␉␉␉␉␉continue;␊ |
1459 | ␉␉␉␉}␊ |
1460 | ␉␉␉␉if (drop_asft && table[0]=='A' && table[1]=='S' && table[2]=='F' && table[3]=='!')␊ |
1461 | ␉␉␉␉{␊ |
1462 | ␉␉␉␉␉dropoffset++;␊ |
1463 | ␉␉␉␉␉continue;␊ |
1464 | ␉␉␉␉}␊ |
1465 | ␉␉␉␉if (drop_dmar && table[0]=='D' && table[1]=='M' && table[2]=='A' && table[3]=='R')␊ |
1466 | ␉␉␉␉{␊ |
1467 | ␉␉␉␉␉dropoffset++;␊ |
1468 | ␉␉␉␉␉continue;␊ |
1469 | ␉␉␉␉}␊ |
1470 | ␉␉␉␉if ((!(oem_hpet)) && table[0]=='H' && table[1]=='P' && table[2]=='E' && table[3]=='T')␊ |
1471 | ␉␉␉␉{␊ |
1472 | ␉␉␉␉␉DBG("HPET found\n");␊ |
1473 | ␉␉␉␉␉if (new_hpet)␊ |
1474 | ␉␉␉␉␉{␊ |
1475 | ␉␉␉␉␉␉rsdt_entries[i-dropoffset]=(uint32_t)new_hpet;␊ |
1476 | ␉␉␉␉␉␉hpet_replaced=true;␊ |
1477 | ␉␉␉␉␉}␊ |
1478 | ␉␉␉␉␉continue;␊ |
1479 | ␉␉␉␉}␊ |
1480 | ␉␉␉␉if ((!(oem_sbst)) && table[0]=='S' && table[1]=='B' && table[2]=='S' && table[3]=='T')␊ |
1481 | ␉␉␉␉{␊ |
1482 | ␉␉␉␉␉DBG("SBST found\n");␊ |
1483 | ␉␉␉␉␉if (new_sbst)␊ |
1484 | ␉␉␉␉␉{␊ |
1485 | ␉␉␉␉␉␉rsdt_entries[i-dropoffset]=(uint32_t)new_sbst;␊ |
1486 | ␉␉␉␉␉␉sbst_replaced=true;␊ |
1487 | ␉␉␉␉␉}␊ |
1488 | ␉␉␉␉␉continue;␊ |
1489 | ␉␉␉␉}␊ |
1490 | ␉␉␉␉if ((!(oem_ecdt)) && table[0]=='E' && table[1]=='C' && table[2]=='D' && table[3]=='T')␊ |
1491 | ␉␉␉␉{␊ |
1492 | ␉␉␉␉␉DBG("ECDT found\n");␊ |
1493 | ␉␉␉␉␉if (new_ecdt)␊ |
1494 | ␉␉␉␉␉{␊ |
1495 | ␉␉␉␉␉␉rsdt_entries[i-dropoffset]=(uint32_t)new_ecdt;␊ |
1496 | ␉␉␉␉␉␉ecdt_replaced=true;␊ |
1497 | ␉␉␉␉␉}␊ |
1498 | ␉␉␉␉␉continue;␊ |
1499 | ␉␉␉␉}␊ |
1500 | ␉␉␉␉if ((!(oem_asft)) && table[0]=='A' && table[1]=='S' && table[2]=='F' && table[3]=='!')␊ |
1501 | ␉␉␉␉{␊ |
1502 | ␉␉␉␉␉DBG("ASF! found\n");␊ |
1503 | ␉␉␉␉␉if (new_asft)␊ |
1504 | ␉␉␉␉␉{␊ |
1505 | ␉␉␉␉␉␉rsdt_entries[i-dropoffset]=(uint32_t)new_asft;␊ |
1506 | ␉␉␉␉␉␉asft_replaced=true;␊ |
1507 | ␉␉␉␉␉}␊ |
1508 | ␉␉␉␉␉continue;␊ |
1509 | ␉␉␉␉}␊ |
1510 | ␉␉␉␉if ((!(oem_dmar)) && table[0]=='D' && table[1]=='M' && table[2]=='A' && table[3]=='R')␊ |
1511 | ␉␉␉␉{␊ |
1512 | ␉␉␉␉␉DBG("DMAR found\n");␊ |
1513 | ␉␉␉␉␉if (new_dmar)␊ |
1514 | ␉␉␉␉␉{␊ |
1515 | ␉␉␉␉␉␉rsdt_entries[i-dropoffset]=(uint32_t)new_dmar;␊ |
1516 | ␉␉␉␉␉␉dmar_replaced=true;␊ |
1517 | ␉␉␉␉␉}␊ |
1518 | ␉␉␉␉␉continue;␊ |
1519 | ␉␉␉␉}␊ |
1520 | ␉␉␉␉if ((!(oem_apic)) && table[0]=='A' && table[1]=='P' && table[2]=='I' && table[3]=='C')␊ |
1521 | ␉␉␉␉{␊ |
1522 | ␉␉␉␉␉DBG("APIC found\n");␊ |
1523 | ␉␉␉␉␉if (new_apic)␊ |
1524 | ␉␉␉␉␉{␊ |
1525 | ␉␉␉␉␉␉rsdt_entries[i-dropoffset]=(uint32_t)new_apic;␊ |
1526 | ␉␉␉␉␉␉apic_replaced=true;␊ |
1527 | ␉␉␉␉␉}␊ |
1528 | ␉␉␉␉␉continue;␊ |
1529 | ␉␉␉␉}␊ |
1530 | ␉␉␉␉if ((!(oem_mcfg)) && table[0]=='M' && table[1]=='C' && table[2]=='F' && table[3]=='G')␊ |
1531 | ␉␉␉␉{␊ |
1532 | ␉␉␉␉␉DBG("MCFG found\n");␊ |
1533 | ␉␉␉␉␉if (new_mcfg)␊ |
1534 | ␉␉␉␉␉{␊ |
1535 | ␉␉␉␉␉␉rsdt_entries[i-dropoffset]=(uint32_t)new_mcfg;␊ |
1536 | ␉␉␉␉␉␉mcfg_replaced=true;␊ |
1537 | ␉␉␉␉␉}␊ |
1538 | ␉␉␉␉␉continue;␊ |
1539 | ␉␉␉␉}␊ |
1540 | ␉␉␉␉if ((!(oem_ssdt)) && table[0]=='S' && table[1]=='S' && table[2]=='D' && table[3]=='T')␊ |
1541 | ␉␉␉␉{␊ |
1542 | ␉␉␉␉␉DBG("SSDT %d found", curssdt);␊ |
1543 | ␉␉␉␉␉if (new_ssdt[curssdt])␊ |
1544 | ␉␉␉␉␉{␊ |
1545 | ␉␉␉␉␉␉DBG(" and replaced");␊ |
1546 | ␉␉␉␉␉␉rsdt_entries[i-dropoffset]=(uint32_t)new_ssdt[curssdt];␊ |
1547 | ␉␉␉␉␉␉totssdt++;␊ |
1548 | ␉␉␉␉␉}␊ |
1549 | ␉␉␉␉␉DBG("\n");␊ |
1550 | ␉␉␉␉␉curssdt++;␊ |
1551 | ␉␉␉␉␉continue;␊ |
1552 | ␉␉␉␉}␊ |
1553 | ␉␉␉␉if (table[0]=='D' && table[1]=='S' && table[2]=='D' && table[3]=='T')␊ |
1554 | ␉␉␉␉{␊ |
1555 | ␉␉␉␉␉DBG("DSDT found\n");␊ |
1556 | ␉␉␉␉␉rsdt_entries[i-dropoffset]=(uint32_t)new_dsdt;␊ |
1557 | ␉␉␉␉␉continue;␊ |
1558 | ␊ |
1559 | ␉␉␉␉} else {␊ |
1560 | ␉␉␉␉␉struct acpi_2_rsdt *t = (struct acpi_2_rsdt *)table;␊ |
1561 | ␉␉␉␉␉strncpy(t->OEMID, "Apple ", 6);␊ |
1562 | ␉␉␉␉␉strncpy(t->OEMTableId, MacModel, 8);␊ |
1563 | ␉␉␉␉␉t->OEMRevision = ModelRev;␊ |
1564 | ␉␉␉␉␉t->Checksum=0;␊ |
1565 | ␉␉␉␉␉t->Checksum=256-checksum8(t,t->Length);␊ |
1566 | ␉␉␉␉}␊ |
1567 | ␉␉␉␉if (table[0]=='F' && table[1]=='A' && table[2]=='C' && table[3]=='P')␊ |
1568 | ␉␉␉␉{␊ |
1569 | ␉␉␉␉␉struct acpi_2_fadt *fadt_mod;␊ |
1570 | ␉␉␉␉␉fadt=(struct acpi_2_fadt *)rsdt_entries[i];␊ |
1571 | ␊ |
1572 | ␉␉␉␉␉DBG("FADT found @%x, Length %d\n",fadt, fadt->Length);␊ |
1573 | ␊ |
1574 | ␉␉␉␉␉if (!fadt || (uint32_t)fadt == 0xffffffff || fadt->Length>0x10000)␊ |
1575 | ␉␉␉␉␉{␊ |
1576 | ␉␉␉␉␉␉printf("FADT incorrect. Not modified\n");␊ |
1577 | ␉␉␉␉␉␉continue;␊ |
1578 | ␉␉␉␉␉}␊ |
1579 | ␉␉␉␉␉␊ |
1580 | ␉␉␉␉␉fadt_mod = patch_fadt(fadt, new_dsdt, update_acpi);␊ |
1581 | ␉␉␉␉␉rsdt_entries[i-dropoffset]=(uint32_t)fadt_mod;␊ |
1582 | ␊ |
1583 | ␉␉␉␉␉if(!oem_ssdt)␊ |
1584 | ␉␉␉␉␉{␊ |
1585 | ␉␉␉␉␉␉// Generate _CST SSDT␊ |
1586 | ␉␉␉␉␉␉if ( gen_cst && (new_ssdt[loadtotssdt] = generate_cst_ssdt(fadt_mod)))␊ |
1587 | ␉␉␉␉␉␉{␊ |
1588 | ␉␉␉␉␉␉␉gen_cst= false;␊ |
1589 | ␉␉␉␉␉␉␉loadtotssdt++;␊ |
1590 | ␉␉␉␉␉␉}␊ |
1591 | ␉␉␉␉␉␊ |
1592 | ␉␉␉␉␉␉// Generating _PSS SSDT␊ |
1593 | ␉␉␉␉␉␉if (gen_pss && (new_ssdt[loadtotssdt] = generate_pss_ssdt((void*)fadt_mod->DSDT)))␊ |
1594 | ␉␉␉␉␉␉{␊ |
1595 | ␉␉␉␉␉␉␉gen_pss= false;␊ |
1596 | ␉␉␉␉␉␉␉loadtotssdt++;␊ |
1597 | ␉␉␉␉␉␉}␊ |
1598 | /*␉␉␉␉␉␊ |
1599 | ␉␉␉␉␉␉// Generating _TSS SSDT␊ |
1600 | ␉␉␉␉␉␉else if (gen_tss && (new_ssdt[loadtotssdt] = generate_tss_ssdt((void*)fadt_mod->DSDT)))␊ |
1601 | ␉␉␉␉␉␉{␊ |
1602 | ␉␉␉␉␉␉␉gen_tss= false;␊ |
1603 | ␉␉␉␉␉␉␉loadtotssdt++;␊ |
1604 | ␉␉␉␉␉␉}␊ |
1605 | */␉␉␉␉␉}␊ |
1606 | ␊ |
1607 | ␉␉␉␉␉continue;␊ |
1608 | ␉␉␉␉}␊ |
1609 | ␉␉␉}␊ |
1610 | ␉␉␉DBG("\n");␊ |
1611 | ␊ |
1612 | ␉␉␉strncpy(rsdt_mod->OEMID, "Apple ", 6);␊ |
1613 | ␉␉␉strncpy(rsdt_mod->OEMTableId, MacModel, 8);␊ |
1614 | ␉␉␉rsdt_mod->OEMRevision = ModelRev;␊ |
1615 | ␊ |
1616 | ␉␉␉if ((!oem_hpet) && (!hpet_replaced))␊ |
1617 | ␉␉␉{␊ |
1618 | ␉␉␉␉if (new_hpet)␊ |
1619 | ␉␉␉␉{␊ |
1620 | ␉␉␉␉␉rsdt_entries[i-dropoffset]=(uint32_t)new_hpet;␊ |
1621 | ␉␉␉␉␉hpet_added=true;␊ |
1622 | ␉␉␉␉␉i++;␊ |
1623 | ␉␉␉␉}␊ |
1624 | ␉␉␉}␊ |
1625 | ␊ |
1626 | ␉␉␉if ((!oem_sbst) && (!sbst_replaced))␊ |
1627 | ␉␉␉{␊ |
1628 | ␉␉␉␉if (new_sbst)␊ |
1629 | ␉␉␉␉{␊ |
1630 | ␉␉␉␉␉rsdt_entries[i-dropoffset]=(uint32_t)new_sbst;␊ |
1631 | ␉␉␉␉␉sbst_added=true;␊ |
1632 | ␉␉␉␉␉i++;␊ |
1633 | ␉␉␉␉}␊ |
1634 | ␉␉␉}␊ |
1635 | ␊ |
1636 | ␉␉␉if ((!oem_ecdt) && (!ecdt_replaced))␊ |
1637 | ␉␉␉{␊ |
1638 | ␉␉␉␉if (new_ecdt)␊ |
1639 | ␉␉␉␉{␊ |
1640 | ␉␉␉␉␉rsdt_entries[i-dropoffset]=(uint32_t)new_ecdt;␊ |
1641 | ␉␉␉␉␉ecdt_added=true;␊ |
1642 | ␉␉␉␉␉i++;␊ |
1643 | ␉␉␉␉}␊ |
1644 | ␉␉␉}␊ |
1645 | ␊ |
1646 | ␉␉␉if ((!oem_asft) && (!asft_replaced))␊ |
1647 | ␉␉␉{␊ |
1648 | ␉␉␉␉if (new_asft)␊ |
1649 | ␉␉␉␉{␊ |
1650 | ␉␉␉␉␉rsdt_entries[i-dropoffset]=(uint32_t)new_asft;␊ |
1651 | ␉␉␉␉␉asft_added=true;␊ |
1652 | ␉␉␉␉␉i++;␊ |
1653 | ␉␉␉␉}␊ |
1654 | ␉␉␉}␊ |
1655 | ␊ |
1656 | ␉␉␉if ((!oem_dmar) && (!dmar_replaced))␊ |
1657 | ␉␉␉{␊ |
1658 | ␉␉␉␉if (new_dmar)␊ |
1659 | ␉␉␉␉{␊ |
1660 | ␉␉␉␉␉rsdt_entries[i-dropoffset]=(uint32_t)new_dmar;␊ |
1661 | ␉␉␉␉␉dmar_added=true;␊ |
1662 | ␉␉␉␉␉i++;␊ |
1663 | ␉␉␉␉}␊ |
1664 | ␉␉␉}␊ |
1665 | ␊ |
1666 | ␉␉␉if ((!oem_apic) && (!apic_replaced))␊ |
1667 | ␉␉␉{␊ |
1668 | ␉␉␉␉if (new_apic)␊ |
1669 | ␉␉␉␉{␊ |
1670 | ␉␉␉␉␉rsdt_entries[i-dropoffset]=(uint32_t)new_apic;␊ |
1671 | ␉␉␉␉␉apic_added=true;␊ |
1672 | ␉␉␉␉␉i++;␊ |
1673 | ␉␉␉␉}␊ |
1674 | ␉␉␉}␊ |
1675 | ␊ |
1676 | ␉␉␉if ((!oem_mcfg) && (!mcfg_replaced))␊ |
1677 | ␉␉␉{␊ |
1678 | ␉␉␉␉if (new_mcfg)␊ |
1679 | ␉␉␉␉{␊ |
1680 | ␉␉␉␉␉rsdt_entries[i-dropoffset]=(uint32_t)new_mcfg;␊ |
1681 | ␉␉␉␉␉mcfg_added=true;␊ |
1682 | ␉␉␉␉␉i++;␊ |
1683 | ␉␉␉␉}␊ |
1684 | ␉␉␉}␊ |
1685 | ␉␉␉␊ |
1686 | ␉␉␉if (!oem_ssdt)␊ |
1687 | ␉␉␉{ ␉␉␉␊ |
1688 | ␉␉␉␉while ((totssdt < loadtotssdt) && (curssdt < 14))␊ |
1689 | ␉␉␉␉{␊ |
1690 | ␉␉␉␉␉if (new_ssdt[curssdt])␊ |
1691 | ␉␉␉␉␉{␊ |
1692 | ␉␉␉␉␉␉DBG("adding SSDT %d\n", curssdt);␊ |
1693 | ␉␉␉␉␉␉rsdt_entries[i-dropoffset]=(uint32_t)new_ssdt[curssdt];␊ |
1694 | ␉␉␉␉␉␉totssdt++;␊ |
1695 | ␉␉␉␉␉␉newtotssdt++;␊ |
1696 | ␉␉␉␉␉␉i++;␊ |
1697 | ␉␉␉␉␉}␊ |
1698 | ␉␉␉␉␉curssdt++;␊ |
1699 | ␉␉␉␉}␊ |
1700 | ␉␉␉}␊ |
1701 | ␊ |
1702 | ␉␉␉// Correct the checksum of RSDT␊ |
1703 | ␉␉␉rsdt_mod->Length-=4*dropoffset;␊ |
1704 | ␉␉␉rsdt_mod->Length+=4*newtotssdt;␊ |
1705 | ␉␉␉if (hpet_added)␊ |
1706 | ␉␉␉␉rsdt_mod->Length+=4;␊ |
1707 | ␉␉␉if (sbst_added)␊ |
1708 | ␉␉␉␉rsdt_mod->Length+=4;␊ |
1709 | ␉␉␉if (ecdt_added)␊ |
1710 | ␉␉␉␉rsdt_mod->Length+=4;␊ |
1711 | ␉␉␉if (asft_added)␊ |
1712 | ␉␉␉␉rsdt_mod->Length+=4;␊ |
1713 | ␉␉␉if (dmar_added)␊ |
1714 | ␉␉␉␉rsdt_mod->Length+=4;␊ |
1715 | ␉␉␉if (apic_added)␊ |
1716 | ␉␉␉␉rsdt_mod->Length+=4;␊ |
1717 | ␉␉␉if (mcfg_added)␊ |
1718 | ␉␉␉␉rsdt_mod->Length+=4;␊ |
1719 | ␊ |
1720 | ␉␉␉DBG("RSDT: Original checksum %d, ", rsdt_mod->Checksum);␊ |
1721 | ␊ |
1722 | ␉␉␉rsdt_mod->Checksum=0;␊ |
1723 | ␉␉␉rsdt_mod->Checksum=256-checksum8(rsdt_mod,rsdt_mod->Length);␊ |
1724 | ␊ |
1725 | ␉␉␉DBG("New checksum %d at %x\n", rsdt_mod->Checksum,rsdt_mod);␊ |
1726 | ␉␉}␊ |
1727 | ␉␉else␊ |
1728 | ␉␉{␊ |
1729 | ␉␉␉rsdp_mod->RsdtAddress=0;␊ |
1730 | ␉␉␉printf("RSDT not found or RSDT incorrect\n");␊ |
1731 | ␉␉}␊ |
1732 | ␊ |
1733 | ␉␉if (version)␊ |
1734 | ␉␉{␊ |
1735 | ␉␉␉struct acpi_2_xsdt *xsdt, *xsdt_mod;␊ |
1736 | ␊ |
1737 | ␉␉␉// FIXME: handle 64-bit address correctly␊ |
1738 | ␊ |
1739 | ␉␉␉if (gen_xsdt)␊ |
1740 | ␉␉␉␉xsdt=xsdt_conv;␊ |
1741 | ␉␉␉else␊ |
1742 | ␉␉␉␉xsdt=(struct acpi_2_xsdt*) ((uint32_t)rsdp->XsdtAddress);␊ |
1743 | ␊ |
1744 | ␉␉␉DBG("XSDT @%x;%x, Length=%d\n", (uint32_t)(rsdp->XsdtAddress>>32),(uint32_t)rsdp->XsdtAddress, xsdt->Length);␊ |
1745 | ␉␉␉if (xsdt && (uint64_t)rsdp->XsdtAddress<0xffffffff && xsdt->Length<0x10000)␊ |
1746 | ␉␉␉{␊ |
1747 | ␉␉␉␉uint64_t *xsdt_entries;␊ |
1748 | ␉␉␉␉int xsdt_entries_num, i;␊ |
1749 | ␉␉␉␉int dropoffset=0;␊ |
1750 | ␉␉␉␉curssdt=0, totssdt=0, newtotssdt=0;␊ |
1751 | ␉␉␉␉hpet_replaced=false, hpet_added=false;␊ |
1752 | ␉␉␉␉sbst_replaced=false, sbst_added=false;␊ |
1753 | ␉␉␉␉ecdt_replaced=false, ecdt_added=false;␊ |
1754 | ␉␉␉␉asft_replaced=false, asft_added=false;␊ |
1755 | ␉␉␉␉dmar_replaced=false, dmar_added=false;␊ |
1756 | ␉␉␉␉apic_replaced=false, apic_added=false;␊ |
1757 | ␉␉␉␉mcfg_replaced=false, mcfg_added=false;␊ |
1758 | ␊ |
1759 | ␉␉␉␉if (gen_xsdt)␊ |
1760 | ␉␉␉␉␉xsdt_mod=xsdt;␊ |
1761 | ␉␉␉␉else␊ |
1762 | ␉␉␉␉{␊ |
1763 | ␉␉␉␉␉xsdt_mod=(struct acpi_2_xsdt*)AllocateKernelMemory(xsdt->Length); ␊ |
1764 | ␉␉␉␉␉memcpy(xsdt_mod, xsdt, xsdt->Length);␊ |
1765 | ␉␉␉␉}␊ |
1766 | ␊ |
1767 | ␉␉␉␉rsdp_mod->XsdtAddress=(uint32_t)xsdt_mod;␊ |
1768 | ␉␉␉␉xsdt_entries_num=(xsdt_mod->Length-sizeof(struct acpi_2_xsdt))/8;␊ |
1769 | ␉␉␉␉xsdt_entries=(uint64_t *)(xsdt_mod+1);␊ |
1770 | ␉␉␉␉for (i=0;i<xsdt_entries_num;i++)␊ |
1771 | ␉␉␉␉{␊ |
1772 | ␉␉␉␉␉char *table=(char *)((uint32_t)(xsdt_entries[i]));␊ |
1773 | ␉␉␉␉␉if (!table)␊ |
1774 | ␉␉␉␉␉␉continue;␊ |
1775 | ␉␉␉␉␉xsdt_entries[i-dropoffset]=xsdt_entries[i];␊ |
1776 | ␉␉␉␉␉if (drop_ssdt && table[0]=='S' && table[1]=='S' && table[2]=='D' && table[3]=='T')␊ |
1777 | ␉␉␉␉␉{␊ |
1778 | ␉␉␉␉␉␉dropoffset++;␊ |
1779 | ␉␉␉␉␉␉continue;␊ |
1780 | ␉␉␉␉␉}␉␊ |
1781 | ␉␉␉␉␉if (drop_hpet && table[0]=='H' && table[1]=='P' && table[2]=='E' && table[3]=='T')␊ |
1782 | ␉␉␉␉␉{␊ |
1783 | ␉␉␉␉␉␉dropoffset++;␊ |
1784 | ␉␉␉␉␉␉continue;␊ |
1785 | ␉␉␉␉␉}␊ |
1786 | ␉␉␉␉␉if (drop_slic && table[0]=='S' && table[1]=='L' && table[2]=='I' && table[3]=='C')␊ |
1787 | ␉␉␉␉␉{␊ |
1788 | ␉␉␉␉␉␉dropoffset++;␊ |
1789 | ␉␉␉␉␉␉continue;␊ |
1790 | ␉␉␉␉␉}␊ |
1791 | ␉␉␉␉␉if (drop_sbst && table[0]=='S' && table[1]=='B' && table[2]=='S' && table[3]=='T')␊ |
1792 | ␉␉␉␉␉{␊ |
1793 | ␉␉␉␉␉␉dropoffset++;␊ |
1794 | ␉␉␉␉␉␉continue;␊ |
1795 | ␉␉␉␉␉}␊ |
1796 | ␉␉␉␉␉if (drop_ecdt && table[0]=='E' && table[1]=='C' && table[2]=='D' && table[3]=='T')␊ |
1797 | ␉␉␉␉␉{␊ |
1798 | ␉␉␉␉␉␉dropoffset++;␊ |
1799 | ␉␉␉␉␉␉continue;␊ |
1800 | ␉␉␉␉␉}␉␉␉␉␉␊ |
1801 | ␉␉␉␉␉if (drop_asft && table[0]=='A' && table[1]=='S' && table[2]=='F' && table[3]=='!')␊ |
1802 | ␉␉␉␉␉{␊ |
1803 | ␉␉␉␉␉␉dropoffset++;␊ |
1804 | ␉␉␉␉␉␉continue;␊ |
1805 | ␉␉␉␉␉}␊ |
1806 | ␉␉␉␉␉if (drop_dmar && table[0]=='D' && table[1]=='M' && table[2]=='A' && table[3]=='R')␊ |
1807 | ␉␉␉␉␉{␊ |
1808 | ␉␉␉␉␉␉dropoffset++;␊ |
1809 | ␉␉␉␉␉␉continue;␊ |
1810 | ␉␉␉␉␉}␉␉␉␉␉␊ |
1811 | ␉␉␉␉␉if ((!(oem_hpet)) && table[0]=='H' && table[1]=='P' && table[2]=='E' && table[3]=='T')␊ |
1812 | ␉␉␉␉␉{␊ |
1813 | ␉␉␉␉␉␉DBG("HPET found\n");␊ |
1814 | ␉␉␉␉␉␉if (new_hpet)␊ |
1815 | ␉␉␉␉␉␉{␊ |
1816 | ␉␉␉␉␉␉␉xsdt_entries[i-dropoffset]=(uint32_t)new_hpet;␊ |
1817 | ␉␉␉␉␉␉␉hpet_replaced=true;␊ |
1818 | ␉␉␉␉␉␉}␊ |
1819 | ␉␉␉␉␉␉continue;␊ |
1820 | ␉␉␉␉␉}␉␉␉␉␉␊ |
1821 | ␉␉␉␉␉if ((!(oem_sbst)) && table[0]=='S' && table[1]=='B' && table[2]=='S' && table[3]=='T')␊ |
1822 | ␉␉␉␉␉{␊ |
1823 | ␉␉␉␉␉␉DBG("SBST found\n");␊ |
1824 | ␉␉␉␉␉␉if (new_sbst)␊ |
1825 | ␉␉␉␉␉␉{␊ |
1826 | ␉␉␉␉␉␉␉xsdt_entries[i-dropoffset]=(uint32_t)new_sbst;␊ |
1827 | ␉␉␉␉␉␉␉sbst_replaced=true;␊ |
1828 | ␉␉␉␉␉␉}␊ |
1829 | ␉␉␉␉␉␉continue;␊ |
1830 | ␉␉␉␉␉}␉␉␉␉␉␊ |
1831 | ␉␉␉␉␉if ((!(oem_ecdt)) && table[0]=='E' && table[1]=='C' && table[2]=='D' && table[3]=='T')␊ |
1832 | ␉␉␉␉␉{␊ |
1833 | ␉␉␉␉␉␉DBG("ECDT found\n");␊ |
1834 | ␉␉␉␉␉␉if (new_ecdt)␊ |
1835 | ␉␉␉␉␉␉{␊ |
1836 | ␉␉␉␉␉␉␉xsdt_entries[i-dropoffset]=(uint32_t)new_ecdt;␊ |
1837 | ␉␉␉␉␉␉␉ecdt_replaced=true;␊ |
1838 | ␉␉␉␉␉␉}␊ |
1839 | ␉␉␉␉␉␉continue;␊ |
1840 | ␉␉␉␉␉}␉␉␉␉␉␊ |
1841 | ␉␉␉␉␉if ((!(oem_asft)) && table[0]=='A' && table[1]=='S' && table[2]=='F' && table[3]=='!')␊ |
1842 | ␉␉␉␉␉{␊ |
1843 | ␉␉␉␉␉␉DBG("ASF! found\n");␊ |
1844 | ␉␉␉␉␉␉if (new_asft)␊ |
1845 | ␉␉␉␉␉␉{␊ |
1846 | ␉␉␉␉␉␉␉xsdt_entries[i-dropoffset]=(uint32_t)new_asft;␊ |
1847 | ␉␉␉␉␉␉␉asft_replaced=true;␊ |
1848 | ␉␉␉␉␉␉}␊ |
1849 | ␉␉␉␉␉␉continue;␊ |
1850 | ␉␉␉␉␉}␉␉␉␉␉␊ |
1851 | ␉␉␉␉␉if ((!(oem_dmar)) && table[0]=='D' && table[1]=='M' && table[2]=='A' && table[3]=='R')␊ |
1852 | ␉␉␉␉␉{␊ |
1853 | ␉␉␉␉␉␉DBG("DMAR found\n");␊ |
1854 | ␉␉␉␉␉␉if (new_dmar)␊ |
1855 | ␉␉␉␉␉␉{␊ |
1856 | ␉␉␉␉␉␉␉xsdt_entries[i-dropoffset]=(uint32_t)new_dmar;␊ |
1857 | ␉␉␉␉␉␉␉dmar_replaced=true;␊ |
1858 | ␉␉␉␉␉␉}␊ |
1859 | ␉␉␉␉␉␉continue;␊ |
1860 | ␉␉␉␉␉}␉␉␉␉␉␊ |
1861 | ␉␉␉␉␉if ((!(oem_apic)) && table[0]=='A' && table[1]=='P' && table[2]=='I' && table[3]=='C')␊ |
1862 | ␉␉␉␉␉{␊ |
1863 | ␉␉␉␉␉␉DBG("APIC found\n");␊ |
1864 | ␉␉␉␉␉␉if (new_apic)␊ |
1865 | ␉␉␉␉␉␉{␊ |
1866 | ␉␉␉␉␉␉␉xsdt_entries[i-dropoffset]=(uint32_t)new_apic;␊ |
1867 | ␉␉␉␉␉␉␉apic_replaced=true;␊ |
1868 | ␉␉␉␉␉␉}␊ |
1869 | ␉␉␉␉␉␉continue;␊ |
1870 | ␉␉␉␉␉}␉␉␉␉␉␊ |
1871 | ␉␉␉␉␉if ((!(oem_mcfg)) && table[0]=='M' && table[1]=='C' && table[2]=='F' && table[3]=='G')␊ |
1872 | ␉␉␉␉␉{␊ |
1873 | ␉␉␉␉␉␉DBG("MCFG found\n");␊ |
1874 | ␉␉␉␉␉␉if (new_mcfg)␊ |
1875 | ␉␉␉␉␉␉{␊ |
1876 | ␉␉␉␉␉␉␉xsdt_entries[i-dropoffset]=(uint32_t)new_mcfg;␊ |
1877 | ␉␉␉␉␉␉␉mcfg_replaced=true;␊ |
1878 | ␉␉␉␉␉␉}␊ |
1879 | ␉␉␉␉␉␉continue;␊ |
1880 | ␉␉␉␉␉}␉␉␉␉␉␊ |
1881 | ␉␉␉␉␉if ((!(oem_ssdt)) && table[0]=='S' && table[1]=='S' && table[2]=='D' && table[3]=='T')␊ |
1882 | ␉␉␉␉␉{␊ |
1883 | ␉␉␉␉␉␉DBG("SSDT %d found", curssdt);␊ |
1884 | ␉␉␉␉␉␉if (new_ssdt[curssdt])␊ |
1885 | ␉␉␉␉␉␉{␊ |
1886 | ␉␉␉␉␉␉␉DBG(" and replaced");␊ |
1887 | ␉␉␉␉␉␉␉xsdt_entries[i-dropoffset]=(uint32_t)new_ssdt[curssdt];␊ |
1888 | ␉␉␉␉␉␉␉totssdt++;␊ |
1889 | ␉␉␉␉␉␉}␊ |
1890 | ␉␉␉␉␉␉DBG("\n");␊ |
1891 | ␉␉␉␉␉␉curssdt++;␊ |
1892 | ␉␉␉␉␉␉continue;␊ |
1893 | ␉␉␉␉␉}␉␉␉␉␉␊ |
1894 | ␉␉␉␉␉if (table[0]=='D' && table[1]=='S' && table[2]=='D' && table[3]=='T')␊ |
1895 | ␉␉␉␉␉{␊ |
1896 | ␉␉␉␉␉␉DBG("DSDT found\n");␊ |
1897 | ␊ |
1898 | ␉␉␉␉␉␉xsdt_entries[i-dropoffset]=(uint32_t)new_dsdt;␊ |
1899 | ␊ |
1900 | ␉␉␉␉␉␉DBG("TABLE %c%c%c%c@%x,",table[0],table[1],table[2],table[3],xsdt_entries[i]);␊ |
1901 | ␉␉␉␉␉␉␊ |
1902 | ␉␉␉␉␉␉continue;␊ |
1903 | ␉␉␉␉␉}␊ |
1904 | ␊ |
1905 | ␉␉␉␉␉struct acpi_2_xsdt* t = (struct acpi_2_xsdt*)table;␊ |
1906 | ␉␉␉␉␉strncpy(t->OEMID, "Apple ", 6);␊ |
1907 | ␉␉␉␉␉strncpy(t->OEMTableId, MacModel, 8);␊ |
1908 | ␉␉␉␉␉t->OEMRevision = ModelRev;␊ |
1909 | ␊ |
1910 | ␉␉␉␉␉if (table[0]=='F' && table[1]=='A' && table[2]=='C' && table[3]=='P')␊ |
1911 | ␉␉␉␉␉{␊ |
1912 | ␉␉␉␉␉␉struct acpi_2_fadt *fadt_mod;␊ |
1913 | ␉␉␉␉␉␉fadt=(struct acpi_2_fadt *)(uint32_t)xsdt_entries[i];␊ |
1914 | ␊ |
1915 | ␉␉␉␉␉␉DBG("FADT found @%x,%x, Length %d\n",(uint32_t)(xsdt_entries[i]>>32),fadt, ␊ |
1916 | ␉␉␉␉␉␉␉␉ fadt->Length);␊ |
1917 | ␊ |
1918 | ␉␉␉␉␉␉if (!fadt || (uint64_t)xsdt_entries[i] >= 0xffffffff || fadt->Length>0x10000)␊ |
1919 | ␉␉␉␉␉␉{␊ |
1920 | ␉␉␉␉␉␉␉verbose("FADT incorrect or after 4GB. Dropping XSDT\n");␊ |
1921 | ␉␉␉␉␉␉␉goto drop_xsdt;␊ |
1922 | ␉␉␉␉␉␉}␊ |
1923 | ␊ |
1924 | ␉␉␉␉␉␉fadt_mod = patch_fadt(fadt, new_dsdt, update_acpi);␊ |
1925 | ␉␉␉␉␉␉xsdt_entries[i-dropoffset]=(uint32_t)fadt_mod;␊ |
1926 | ␊ |
1927 | ␉␉␉␉␉␉DBG("TABLE %c%c%c%c@%x,",table[0],table[1],table[2],table[3],xsdt_entries[i]);␊ |
1928 | ␊ |
1929 | ␉␉␉␉␉␉if (!oem_ssdt)␊ |
1930 | ␉␉␉␉␉␉{␊ |
1931 | ␉␉␉␉␉␉␉// Generate _CST SSDT␊ |
1932 | ␉␉␉␉␉␉␉if ( gen_cst && (new_ssdt[loadtotssdt] = generate_cst_ssdt(fadt_mod)))␊ |
1933 | ␉␉␉␉␉␉␉{␊ |
1934 | ␉␉␉␉␉␉␉␉gen_cst= false;␊ |
1935 | ␉␉␉␉␉␉␉␉loadtotssdt++;␊ |
1936 | ␉␉␉␉␉␉␉}␊ |
1937 | ␊ |
1938 | ␉␉␉␉␉␉␉// Generating _PSS SSDT␊ |
1939 | ␉␉␉␉␉␉␉if (gen_pss && (new_ssdt[loadtotssdt] = generate_pss_ssdt((void*)fadt_mod->DSDT)))␊ |
1940 | ␉␉␉␉␉␉␉{␊ |
1941 | ␉␉␉␉␉␉␉␉gen_pss= false;␊ |
1942 | ␉␉␉␉␉␉␉␉loadtotssdt++;␊ |
1943 | ␉␉␉␉␉␉␉}␊ |
1944 | /*␉␉␉␉␉␉␊ |
1945 | ␉␉␉␉␉␉␉// Generating _TSS SSDT␊ |
1946 | ␉␉␉␉␉␉␉else if (gen_tss && (new_ssdt[loadtotssdt] = generate_tss_ssdt((void*)fadt_mod->DSDT)))␊ |
1947 | ␉␉␉␉␉␉␉{␊ |
1948 | ␉␉␉␉␉␉␉␉gen_tss= false;␊ |
1949 | ␉␉␉␉␉␉␉␉loadtotssdt++;␊ |
1950 | ␉␉␉␉␉␉␉}␊ |
1951 | */␉␉␉␉␉␉}␊ |
1952 | ␊ |
1953 | ␉␉␉␉␉␉continue;␊ |
1954 | ␉␉␉␉␉}␊ |
1955 | ␊ |
1956 | ␉␉␉␉␉DBG("TABLE %c%c%c%c@%x,",table[0],table[1],table[2],table[3],xsdt_entries[i]);␊ |
1957 | ␊ |
1958 | ␉␉␉␉}␊ |
1959 | ␊ |
1960 | ␉␉␉␉strncpy(xsdt_mod->OEMID, "Apple ", 6);␊ |
1961 | ␉␉␉␉strncpy(xsdt_mod->OEMTableId, MacModel, 8);␊ |
1962 | ␉␉␉␉xsdt_mod->OEMRevision = ModelRev;␊ |
1963 | ␊ |
1964 | ␉␉␉␉if ((!oem_hpet) && (!hpet_replaced))␊ |
1965 | ␉␉␉␉{␊ |
1966 | ␉␉␉␉␉if (new_hpet)␊ |
1967 | ␉␉␉␉␉{␊ |
1968 | ␉␉␉␉␉␉xsdt_entries[i-dropoffset]=(uint32_t)new_hpet;␊ |
1969 | ␉␉␉␉␉␉hpet_added=true;␊ |
1970 | ␉␉␉␉␉␉i++;␊ |
1971 | ␉␉␉␉␉}␊ |
1972 | ␉␉␉␉}␊ |
1973 | ␊ |
1974 | ␉␉␉␉if ((!oem_sbst) && (!sbst_replaced))␊ |
1975 | ␉␉␉␉{␊ |
1976 | ␉␉␉␉␉if (new_sbst)␊ |
1977 | ␉␉␉␉␉{␊ |
1978 | ␉␉␉␉␉␉xsdt_entries[i-dropoffset]=(uint32_t)new_sbst;␊ |
1979 | ␉␉␉␉␉␉sbst_added=true;␊ |
1980 | ␉␉␉␉␉␉i++;␊ |
1981 | ␉␉␉␉␉}␊ |
1982 | ␉␉␉␉}␊ |
1983 | ␊ |
1984 | ␉␉␉␉if ((!oem_ecdt) && (!ecdt_replaced))␊ |
1985 | ␉␉␉␉{␊ |
1986 | ␉␉␉␉␉if (new_ecdt)␊ |
1987 | ␉␉␉␉␉{␊ |
1988 | ␉␉␉␉␉␉xsdt_entries[i-dropoffset]=(uint32_t)new_ecdt;␊ |
1989 | ␉␉␉␉␉␉ecdt_added=true;␊ |
1990 | ␉␉␉␉␉␉i++;␊ |
1991 | ␉␉␉␉␉}␊ |
1992 | ␉␉␉␉}␊ |
1993 | ␊ |
1994 | ␉␉␉␉if ((!oem_asft) && (!asft_replaced))␊ |
1995 | ␉␉␉␉{␊ |
1996 | ␉␉␉␉␉if (new_asft)␊ |
1997 | ␉␉␉␉␉{␊ |
1998 | ␉␉␉␉␉␉xsdt_entries[i-dropoffset]=(uint32_t)new_asft;␊ |
1999 | ␉␉␉␉␉␉asft_added=true;␊ |
2000 | ␉␉␉␉␉␉i++;␊ |
2001 | ␉␉␉␉␉}␊ |
2002 | ␉␉␉␉}␊ |
2003 | ␊ |
2004 | ␉␉␉␉if ((!oem_dmar) && (!dmar_replaced))␊ |
2005 | ␉␉␉␉{␊ |
2006 | ␉␉␉␉␉if (new_dmar)␊ |
2007 | ␉␉␉␉␉{␊ |
2008 | ␉␉␉␉␉␉xsdt_entries[i-dropoffset]=(uint32_t)new_dmar;␊ |
2009 | ␉␉␉␉␉␉dmar_added=true;␊ |
2010 | ␉␉␉␉␉␉i++;␊ |
2011 | ␉␉␉␉␉}␊ |
2012 | ␉␉␉␉}␊ |
2013 | ␊ |
2014 | ␉␉␉␉if ((!oem_apic) && (!apic_replaced))␊ |
2015 | ␉␉␉␉{␊ |
2016 | ␉␉␉␉␉if (new_apic)␊ |
2017 | ␉␉␉␉␉{␊ |
2018 | ␉␉␉␉␉␉xsdt_entries[i-dropoffset]=(uint32_t)new_apic;␊ |
2019 | ␉␉␉␉␉␉apic_added=true;␊ |
2020 | ␉␉␉␉␉␉i++;␊ |
2021 | ␉␉␉␉␉}␊ |
2022 | ␉␉␉␉}␊ |
2023 | ␊ |
2024 | ␉␉␉␉if ((!oem_mcfg) && (!mcfg_replaced))␊ |
2025 | ␉␉␉␉{␊ |
2026 | ␉␉␉␉␉if (new_mcfg)␊ |
2027 | ␉␉␉␉␉{␊ |
2028 | ␉␉␉␉␉␉xsdt_entries[i-dropoffset]=(uint32_t)new_mcfg;␊ |
2029 | ␉␉␉␉␉␉mcfg_added=true;␊ |
2030 | ␉␉␉␉␉␉i++;␊ |
2031 | ␉␉␉␉␉}␊ |
2032 | ␉␉␉␉}␊ |
2033 | ␊ |
2034 | ␉␉␉␉if (!oem_ssdt)␊ |
2035 | ␉␉␉␉{ ␉␉␉␊ |
2036 | ␉␉␉␉␉while ((totssdt < loadtotssdt) && (curssdt < 14))␊ |
2037 | ␉␉␉␉␉{␊ |
2038 | ␉␉␉␉␉␉if (new_ssdt[curssdt])␊ |
2039 | ␉␉␉␉␉␉{␊ |
2040 | ␉␉␉␉␉␉␉DBG("adding SSDT %d\n", curssdt);␊ |
2041 | ␉␉␉␉␉␉␉xsdt_entries[i-dropoffset]=(uint32_t)new_ssdt[curssdt];␊ |
2042 | ␉␉␉␉␉␉␉totssdt++;␊ |
2043 | ␉␉␉␉␉␉␉newtotssdt++;␊ |
2044 | ␉␉␉␉␉␉␉i++;␊ |
2045 | ␉␉␉␉␉␉}␊ |
2046 | ␉␉␉␉␉␉curssdt++;␊ |
2047 | ␉␉␉␉␉}␊ |
2048 | ␉␉␉␉}␊ |
2049 | ␊ |
2050 | ␉␉␉␉// Correct the checksum of XSDT␊ |
2051 | ␉␉␉␉xsdt_mod->Length-=8*dropoffset;␊ |
2052 | ␉␉␉␉xsdt_mod->Length+=8*newtotssdt;␊ |
2053 | ␉␉␉␉if (hpet_added)␊ |
2054 | ␉␉␉␉␉xsdt_mod->Length+=8;␊ |
2055 | ␉␉␉␉if (sbst_added)␊ |
2056 | ␉␉␉␉␉xsdt_mod->Length+=8;␊ |
2057 | ␉␉␉␉if (ecdt_added)␊ |
2058 | ␉␉␉␉␉xsdt_mod->Length+=8;␊ |
2059 | ␉␉␉␉if (asft_added)␊ |
2060 | ␉␉␉␉␉xsdt_mod->Length+=8;␊ |
2061 | ␉␉␉␉if (dmar_added)␊ |
2062 | ␉␉␉␉␉xsdt_mod->Length+=8;␊ |
2063 | ␉␉␉␉if (apic_added)␊ |
2064 | ␉␉␉␉␉xsdt_mod->Length+=8;␊ |
2065 | ␉␉␉␉if (mcfg_added)␊ |
2066 | ␉␉␉␉␉xsdt_mod->Length+=8;␊ |
2067 | ␊ |
2068 | ␉␉␉␉xsdt_mod->Checksum=0;␊ |
2069 | ␉␉␉␉xsdt_mod->Checksum=256-checksum8(xsdt_mod,xsdt_mod->Length);␊ |
2070 | ␉␉␉}␊ |
2071 | ␉␉␉else␊ |
2072 | ␉␉␉{␊ |
2073 | ␉␉␉drop_xsdt:␊ |
2074 | ␊ |
2075 | ␉␉␉␉DBG("About to drop XSDT\n");␊ |
2076 | ␊ |
2077 | ␉␉␉␉/*FIXME: Now we just hope that if MacOS doesn't find XSDT it reverts to RSDT. ␊ |
2078 | ␉␉␉␉ * A Better strategy would be to generate␊ |
2079 | ␉␉␉␉ */␊ |
2080 | ␊ |
2081 | ␉␉␉␉rsdp_mod->XsdtAddress=0xffffffffffffffffLL;␊ |
2082 | ␉␉␉␉verbose("XSDT not found or XSDT incorrect\n");␊ |
2083 | ␉␉␉}␊ |
2084 | ␉␉}␊ |
2085 | ␊ |
2086 | ␉␉// Correct the checksum of RSDP ␊ |
2087 | ␊ |
2088 | ␉␉DBG("RSDP: Original checksum %d, ", rsdp_mod->Checksum);␊ |
2089 | ␊ |
2090 | ␉␉rsdp_mod->Checksum=0;␊ |
2091 | ␉␉rsdp_mod->Checksum=256-checksum8(rsdp_mod,20);␊ |
2092 | ␊ |
2093 | ␉␉DBG("New checksum %d\n", rsdp_mod->Checksum);␊ |
2094 | ␊ |
2095 | ␉␉if (version)␊ |
2096 | ␉␉{␊ |
2097 | ␉␉␉DBG("RSDP: Original extended checksum %d", rsdp_mod->ExtendedChecksum);␊ |
2098 | ␊ |
2099 | ␉␉␉rsdp_mod->ExtendedChecksum=0;␊ |
2100 | ␉␉␉rsdp_mod->ExtendedChecksum=256-checksum8(rsdp_mod,rsdp_mod->Length);␊ |
2101 | ␊ |
2102 | ␉␉␉DBG("New extended checksum %d\n", rsdp_mod->ExtendedChecksum);␊ |
2103 | ␊ |
2104 | ␉␉}␊ |
2105 | ␉␉␊ |
2106 | ␉␉verbose("Patched ACPI version %d DSDT\n", version+1);␊ |
2107 | ␉␉if (version)␊ |
2108 | ␉␉{␊ |
2109 | ␉/* XXX aserebln why uint32 cast if pointer is uint64 ? */␊ |
2110 | ␉␉␉acpi20_p = (uint32_t)rsdp_mod;␊ |
2111 | ␉␉␉acpi10_p = (uint32_t)rsdp_mod;␊ |
2112 | ␉␉␉addConfigurationTable(&gEfiAcpi20TableGuid, &acpi20_p, "ACPI_20");␊ |
2113 | ␉␉␉addConfigurationTable(&gEfiAcpiTableGuid, &acpi10_p, "ACPI");␊ |
2114 | ␉␉}␊ |
2115 | ␉␉else␊ |
2116 | ␉␉{␊ |
2117 | ␉/* XXX aserebln why uint32 cast if pointer is uint64 ? */␊ |
2118 | ␉␉␉acpi10_p = (uint32_t)rsdp_mod;␊ |
2119 | ␉␉␉addConfigurationTable(&gEfiAcpiTableGuid, &acpi10_p, "ACPI");␊ |
2120 | ␉␉}␊ |
2121 | ␉}␊ |
2122 | #if DEBUG_ACPI␊ |
2123 | ␉printf("Press a key to continue... (DEBUG_ACPI)\n");␊ |
2124 | ␉getc();␊ |
2125 | #endif␊ |
2126 | ␉return 1;␊ |
2127 | }␊ |
2128 | |