1 | /*␊ |
2 | * Copyright 2008 mackerintel␊ |
3 | * 2010 mojodojo, 2012 slice␊ |
4 | */␊ |
5 | ␊ |
6 | #include "libsaio.h"␊ |
7 | #include "boot.h"␊ |
8 | #include "bootstruct.h"␊ |
9 | #include "acpi.h"␊ |
10 | #include "efi_tables.h"␊ |
11 | #include "fake_efi.h"␊ |
12 | #include "acpi_patcher.h"␊ |
13 | #include "platform.h"␊ |
14 | #include "cpu.h"␊ |
15 | #include "aml_generator.h"␊ |
16 | #include "state_generator.h"␊ |
17 | ␊ |
18 | #ifndef DEBUG_ACPI␊ |
19 | #define DEBUG_ACPI 0␊ |
20 | #endif␊ |
21 | ␊ |
22 | #if DEBUG_ACPI==2␊ |
23 | #define DBG(x...) {printf(x); sleep(1);}␊ |
24 | #elif DEBUG_ACPI==1␊ |
25 | #define DBG(x...) printf(x)␊ |
26 | #else␊ |
27 | #define DBG(x...) msglog(x)␊ |
28 | #endif␊ |
29 | ␊ |
30 | // Slice: New signature compare function␊ |
31 | boolean_t tableSign(char *table, const char *sgn)␊ |
32 | {␊ |
33 | ␉int i;␊ |
34 | ␉for (i = 0; i < 4; i++)␊ |
35 | ␉{␊ |
36 | ␉␉if ((table[i] &~0x20) != (sgn[i] &~0x20))␊ |
37 | ␉␉{␊ |
38 | ␉␉␉return false;␊ |
39 | ␉␉}␊ |
40 | ␉}␊ |
41 | ␉return true;␊ |
42 | }␊ |
43 | ␊ |
44 | /* Gets the ACPI 1.0 RSDP address */␊ |
45 | static struct acpi_2_rsdp *getAddressOfAcpiTable()␊ |
46 | {␊ |
47 | ␉/* TODO: Before searching the BIOS space we are supposed to search the first 1K of the EBDA */␊ |
48 | ␊ |
49 | ␉void *acpi_addr = (void*)ACPI_RANGE_START;␊ |
50 | ␊ |
51 | ␉for(; acpi_addr <= (void*)ACPI_RANGE_END; acpi_addr += 16)␊ |
52 | ␉{␊ |
53 | ␉␉if(*(uint64_t *)acpi_addr == ACPI_SIGNATURE_UINT64_LE)␊ |
54 | ␉␉{␊ |
55 | ␉␉␉uint8_t csum = checksum8(acpi_addr, 20);␊ |
56 | ␉␉␉if(csum == 0)␊ |
57 | ␉␉␉{␊ |
58 | ␉␉␉// Only return the table if it is a true version 1.0 table (Revision 0)␊ |
59 | ␉␉␉␉if(((struct acpi_2_rsdp*)acpi_addr)->Revision == 0)␊ |
60 | ␉␉␉␉return acpi_addr;␊ |
61 | ␉␉␉}␊ |
62 | ␉␉}␊ |
63 | ␉}␊ |
64 | ␉return NULL;␊ |
65 | }␊ |
66 | ␊ |
67 | /* Gets the ACPI 2.0 RSDP address */␊ |
68 | static struct acpi_2_rsdp *getAddressOfAcpi20Table()␊ |
69 | {␊ |
70 | ␉/* TODO: Before searching the BIOS space we are supposed to search the first 1K of the EBDA */␊ |
71 | ␊ |
72 | ␉void *acpi_addr = (void *)ACPI_RANGE_START;␊ |
73 | ␊ |
74 | ␉for(; acpi_addr <= (void *)ACPI_RANGE_END; acpi_addr += 16)␊ |
75 | ␉{␊ |
76 | ␉␉if(*(uint64_t *)acpi_addr == ACPI_SIGNATURE_UINT64_LE)␊ |
77 | ␉␉{␊ |
78 | ␉␉␉uint8_t csum = checksum8(acpi_addr, 20);␊ |
79 | ␊ |
80 | ␉␉␉/* Only assume this is a 2.0 or better table if the revision is greater than 0␊ |
81 | ␉␉␉ * NOTE: ACPI 3.0 spec only seems to say that 1.0 tables have revision 1␊ |
82 | ␉␉␉ * and that the current revision is 2.. I am going to assume that rev > 0 is 2.0.␊ |
83 | ␉␉␉ */␊ |
84 | ␊ |
85 | ␉␉␉if(csum == 0 && (((struct acpi_2_rsdp*)acpi_addr)->Revision > 0))␊ |
86 | ␉␉␉{␊ |
87 | ␉␉␉␉uint8_t csum2 = checksum8(acpi_addr, sizeof(struct acpi_2_rsdp));␊ |
88 | ␉␉␉␉if(csum2 == 0)␊ |
89 | ␉␉␉␉{␊ |
90 | ␉␉␉␉␉return acpi_addr;␊ |
91 | ␉␉␉␉}␊ |
92 | ␉␉␉}␊ |
93 | ␉␉}␊ |
94 | ␉}␊ |
95 | ␉return NULL;␊ |
96 | }␊ |
97 | ␊ |
98 | /* The folowing ACPI Table search algo. should be reused anywhere needed:*/␊ |
99 | /* WARNING: outDirspec string will be overwritten by subsequent calls! */␊ |
100 | int search_and_get_acpi_fd(const char *filename, const char **outDirspec)␊ |
101 | {␊ |
102 | ␉int fd = 0;␊ |
103 | ␉static char dirSpec[512];␊ |
104 | ␊ |
105 | ␉// Try finding 'filename' in the usual places␊ |
106 | ␉// Start searching any potential location for ACPI Table␊ |
107 | ␉snprintf(dirSpec, sizeof(dirSpec), "%s", filename);␊ |
108 | ␉fd = open(dirSpec, 0);␊ |
109 | ␉if (fd < 0)␊ |
110 | ␉{␊ |
111 | ␉␉snprintf(dirSpec, sizeof(dirSpec), "/Extra/%s", filename); ␊ |
112 | ␉␉fd = open(dirSpec, 0);␊ |
113 | ␉␉if (fd < 0)␊ |
114 | ␉␉{␊ |
115 | ␉␉␉snprintf(dirSpec, sizeof(dirSpec), "bt(0,0)/Extra/%s", filename);␊ |
116 | ␉␉␉fd = open(dirSpec, 0);␊ |
117 | ␉␉␉if (fd < 0)␊ |
118 | ␉␉␉{␊ |
119 | ␉␉␉␉// NOT FOUND:␊ |
120 | ␉␉␉␉DBG("ACPI Table not found: %s\n", filename);␊ |
121 | ␉␉␉␉*dirSpec = '\0';␊ |
122 | ␉␉␉}␊ |
123 | ␉␉}␊ |
124 | ␉}␊ |
125 | ␊ |
126 | ␉if (outDirspec) *outDirspec = dirSpec; ␊ |
127 | ␉return fd;␊ |
128 | }␊ |
129 | ␊ |
130 | void *loadACPITable (const char *filename)␊ |
131 | {␊ |
132 | ␉const char *dirspec = NULL;␊ |
133 | ␊ |
134 | ␉int fd = search_and_get_acpi_fd(filename, &dirspec);␊ |
135 | ␊ |
136 | ␉if (fd >= 0)␊ |
137 | ␉{␊ |
138 | ␉␉void *tableAddr = (void*)AllocateKernelMemory(file_size(fd));␊ |
139 | ␉␉if (tableAddr)␊ |
140 | ␉␉{␊ |
141 | ␉␉␉if (read(fd, tableAddr, file_size(fd)) != file_size(fd))␊ |
142 | ␉␉␉{␊ |
143 | ␉␉␉␉DBG("Couldn't read table %s\n",dirspec);␊ |
144 | ␉␉␉␉free(tableAddr);␊ |
145 | ␉␉␉␉close(fd);␊ |
146 | ␉␉␉␉return NULL;␊ |
147 | ␉␉␉}␊ |
148 | ␊ |
149 | ␉␉␉DBG("Table %s read and stored at: %x\n", dirspec, tableAddr);␊ |
150 | ␉␉␉close(fd);␊ |
151 | ␉␉␉return tableAddr;␊ |
152 | ␉␉}␊ |
153 | ␉␉close(fd);␊ |
154 | ␉␉DBG("Couldn't allocate memory for table \n", dirspec);␊ |
155 | ␉} ␊ |
156 | ␉//printf("Couldn't find table %s\n", filename);␊ |
157 | ␉return NULL;␊ |
158 | }␊ |
159 | ␊ |
160 | uint8_t acpi_cpu_count␉= 0;␊ |
161 | uint32_t acpi_cpu_p_blk␉= 0;␊ |
162 | char *acpi_cpu_name[32];␊ |
163 | ␊ |
164 | void get_acpi_cpu_names(unsigned char *dsdt, uint32_t length)␊ |
165 | {␊ |
166 | ␉uint32_t i;␊ |
167 | ␊ |
168 | ␉DBG("ACPIpatcher: start finding cpu names. Length %d\n", length);␊ |
169 | ␊ |
170 | ␉for (i=0; i<length-7; i++)␊ |
171 | ␉{␊ |
172 | ␉␉if (dsdt[i] == 0x5B && dsdt[i+1] == 0x83) // ProcessorOP␊ |
173 | ␉␉{␊ |
174 | ␉␉␉DBG("ACPIpatcher: DSDT[%X%X]\n", dsdt[i], dsdt[i+1]);␊ |
175 | ␊ |
176 | ␉␉␉uint32_t offset = i + 3 + (dsdt[i+2] >> 6);␊ |
177 | ␊ |
178 | ␉␉␉bool add_name = true;␊ |
179 | ␊ |
180 | ␉␉␉uint8_t j;␊ |
181 | ␊ |
182 | ␉␉␉for (j=0; j<4; j++)␊ |
183 | ␉␉␉{␊ |
184 | ␉␉␉␉char c = dsdt[offset+j];␊ |
185 | ␊ |
186 | ␉␉␉␉if (!aml_isvalidchar(c))␊ |
187 | ␉␉␉␉{␊ |
188 | ␉␉␉␉␉add_name = false;␊ |
189 | ␉␉␉␉␉DBG("ACPIpatcher: invalid character found in ProcessorOP '0x%X'!\n", c);␊ |
190 | ␉␉␉␉␉break;␊ |
191 | ␉␉␉␉}␊ |
192 | ␉␉␉}␊ |
193 | ␊ |
194 | ␉␉␉if (add_name)␊ |
195 | ␉␉␉{␊ |
196 | ␉␉␉␉acpi_cpu_name[acpi_cpu_count] = malloc(4);␊ |
197 | ␉␉␉␉memcpy(acpi_cpu_name[acpi_cpu_count], dsdt+offset, 4);␊ |
198 | ␉␉␉␉i = offset + 5;␊ |
199 | ␊ |
200 | ␉␉␉␉if (acpi_cpu_count == 0)␊ |
201 | ␉␉␉␉{␊ |
202 | ␉␉␉␉␉acpi_cpu_p_blk = dsdt[i] | (dsdt[i+1] << 8);␊ |
203 | ␉␉␉␉}␊ |
204 | ␊ |
205 | ␉␉␉␉DBG("ACPIpatcher: 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]);␊ |
206 | ␊ |
207 | ␉␉␉␉if (++acpi_cpu_count == 32)␊ |
208 | ␉␉␉␉{␊ |
209 | ␉␉␉␉␉return;␊ |
210 | ␉␉␉␉}␊ |
211 | ␉␉␉}␊ |
212 | ␉␉}␊ |
213 | ␉}␊ |
214 | ␊ |
215 | ␉DBG("ACPIpatcher: finished finding cpu names. Found: %d.\n", acpi_cpu_count);␊ |
216 | }␊ |
217 | ␊ |
218 | struct acpi_2_fadt *patch_fadt(struct acpi_2_fadt *fadt, struct acpi_2_dsdt *new_dsdt)␊ |
219 | {␊ |
220 | ␉extern void setupSystemType();␊ |
221 | ␊ |
222 | ␉struct acpi_2_fadt *fadt_mod = NULL;␊ |
223 | ␉bool fadt_rev2_needed = false;␊ |
224 | ␉bool fix_restart;␊ |
225 | ␉bool fix_restart_ps2;␊ |
226 | ␉const char * value;␊ |
227 | ␊ |
228 | ␉// Restart Fix␊ |
229 | ␉if (Platform.CPU.Vendor == 0x756E6547)␊ |
230 | ␉{␉/* Intel */␊ |
231 | ␉␉fix_restart = true;␊ |
232 | ␉␉fix_restart_ps2 = false;␊ |
233 | ␉␉if ( getBoolForKey(kPS2RestartFix, &fix_restart_ps2, &bootInfo->chameleonConfig) && fix_restart_ps2)␊ |
234 | ␉␉{␊ |
235 | ␉␉␉fix_restart = true;␊ |
236 | ␉␉}␊ |
237 | ␉␉else␊ |
238 | ␉␉{␊ |
239 | ␉␉␉getBoolForKey(kRestartFix, &fix_restart, &bootInfo->chameleonConfig);␊ |
240 | ␉␉}␊ |
241 | ␉}␊ |
242 | ␉else␊ |
243 | ␉{␊ |
244 | ␉␉DBG("Not an Intel platform: Restart Fix not applied !!!\n");␊ |
245 | ␉␉fix_restart = false;␊ |
246 | ␉}␊ |
247 | ␊ |
248 | ␉if (fix_restart)␊ |
249 | ␉{␊ |
250 | ␉␉fadt_rev2_needed = true;␊ |
251 | ␉}␊ |
252 | ␊ |
253 | ␉// Allocate new fadt table␊ |
254 | ␉if (fadt->Length < 0x84 && fadt_rev2_needed)␊ |
255 | ␉{␊ |
256 | ␉␉fadt_mod = (struct acpi_2_fadt *)AllocateKernelMemory(0x84);␊ |
257 | ␉␉memcpy(fadt_mod, fadt, fadt->Length);␊ |
258 | ␉␉fadt_mod->Length = 0x84;␊ |
259 | ␉␉fadt_mod->Revision = 0x02; // FADT rev 2 (ACPI 1.0B MS extensions)␊ |
260 | ␉}␊ |
261 | ␉else␊ |
262 | ␉{␊ |
263 | ␉␉fadt_mod = (struct acpi_2_fadt *)AllocateKernelMemory(fadt->Length);␊ |
264 | ␉␉memcpy(fadt_mod, fadt, fadt->Length);␊ |
265 | ␉}␊ |
266 | ␉// Determine system type / PM_Model␊ |
267 | ␉if ( (value=getStringForKey(kSystemType, &bootInfo->chameleonConfig))!=NULL)␊ |
268 | ␉{␊ |
269 | ␉␉if (Platform.Type > 6)␊ |
270 | ␉␉{␊ |
271 | ␉␉␉if(fadt_mod->PM_Profile<=6)␊ |
272 | ␉␉␉{␊ |
273 | ␉␉␉␉Platform.Type = fadt_mod->PM_Profile; // get the fadt if correct␊ |
274 | ␉␉␉}␊ |
275 | ␉␉␉else␊ |
276 | ␉␉␉{␊ |
277 | ␉␉␉␉Platform.Type = 1;␉␉/* Set a fixed value (Desktop) */␊ |
278 | ␉␉␉}␊ |
279 | ␉␉␉DBG("Error: system-type must be 0..6. Defaulting to %d !\n", Platform.Type);␊ |
280 | ␉␉}␊ |
281 | ␉␉else␊ |
282 | ␉␉{␊ |
283 | ␉␉␉Platform.Type = (unsigned char) strtoul(value, NULL, 10);␊ |
284 | ␉␉}␊ |
285 | ␉}␊ |
286 | ␉// Set PM_Profile from System-type if only user wanted this value to be forced␊ |
287 | ␉if (fadt_mod->PM_Profile != Platform.Type)␊ |
288 | ␉{␊ |
289 | ␉␉if (value)␊ |
290 | ␉␉{␊ |
291 | ␉␉␉// user has overriden the SystemType so take care of it in FACP␊ |
292 | ␉␉␉DBG("FADT: changing PM_Profile from 0x%02x to 0x%02x\n", fadt_mod->PM_Profile, Platform.Type);␊ |
293 | ␉␉␉fadt_mod->PM_Profile = Platform.Type;␊ |
294 | ␉␉}␊ |
295 | ␉␉else␊ |
296 | ␉␉{␊ |
297 | ␉␉␉// PM_Profile has a different value and no override has been set, so reflect the user value to ioregs␊ |
298 | ␉␉␉Platform.Type = fadt_mod->PM_Profile <= 6 ? fadt_mod->PM_Profile : 1;␊ |
299 | ␉␉}␊ |
300 | ␉}␊ |
301 | ␉// We now have to write the systemm-type in ioregs: we cannot do it before in setupDeviceTree()␊ |
302 | ␉// because we need to take care of FACP original content, if it is correct.␊ |
303 | ␉setupSystemType();␊ |
304 | ␊ |
305 | ␉// Patch FADT to fix restart␊ |
306 | ␉if (fix_restart)␊ |
307 | ␉{␊ |
308 | ␉␉if (fix_restart_ps2)␊ |
309 | ␉␉{␊ |
310 | ␉␉␉fadt_mod->Flags|= 0x400;␊ |
311 | ␉␉␉fadt_mod->Reset_SpaceID␉␉= 0x01; // System I/O␊ |
312 | ␉␉␉fadt_mod->Reset_BitWidth␉= 0x08; // 1 byte␊ |
313 | ␉␉␉fadt_mod->Reset_BitOffset␉= 0x00; // Offset 0␊ |
314 | ␉␉␉fadt_mod->Reset_AccessWidth␉= 0x01; // Byte access␊ |
315 | ␉␉␉fadt_mod->Reset_Address␉␉= 0x64; // Address of the register␊ |
316 | ␉␉␉fadt_mod->Reset_Value␉␉= 0xfe; // Value to write to reset the system␊ |
317 | ␉␉␉DBG("FADT: PS2 Restart Fix applied!\n");␊ |
318 | ␉␉}␊ |
319 | ␉␉else␊ |
320 | ␉␉{␊ |
321 | ␉␉␉fadt_mod->Flags|= 0x400;␊ |
322 | ␉␉␉fadt_mod->Reset_SpaceID␉␉= 0x01; // System I/O␊ |
323 | ␉␉␉fadt_mod->Reset_BitWidth␉= 0x08; // 1 byte␊ |
324 | ␉␉␉fadt_mod->Reset_BitOffset␉= 0x00; // Offset 0␊ |
325 | ␉␉␉fadt_mod->Reset_AccessWidth␉= 0x01; // Byte access␊ |
326 | ␉␉␉fadt_mod->Reset_Address␉␉= 0x0cf9; // Address of the register␊ |
327 | ␉␉␉fadt_mod->Reset_Value␉␉= 0x06; // Value to write to reset the system␊ |
328 | ␉␉␉DBG("FADT: ACPI Restart Fix applied!\n");␊ |
329 | ␉␉}␊ |
330 | ␊ |
331 | ␉}␊ |
332 | ␊ |
333 | ␉// Patch DSDT Address if we have loaded DSDT.aml␊ |
334 | ␉if(new_dsdt)␊ |
335 | ␉{␊ |
336 | ␉␉DBG("DSDT: Old @%x,%x, ",fadt_mod->DSDT,fadt_mod->X_DSDT);␊ |
337 | ␊ |
338 | ␉␉fadt_mod->DSDT=(uint32_t)new_dsdt;␊ |
339 | ␉␉if ((uint32_t)(&(fadt_mod->X_DSDT))-(uint32_t)fadt_mod+8<=fadt_mod->Length)␊ |
340 | ␉␉{␊ |
341 | ␉␉␉fadt_mod->X_DSDT=(uint32_t)new_dsdt;␊ |
342 | ␉␉}␊ |
343 | ␊ |
344 | ␉␉DBG("New @%x,%x\n",fadt_mod->DSDT,fadt_mod->X_DSDT);␊ |
345 | ␊ |
346 | ␉␉DBG("FADT: Using custom DSDT!\n");␊ |
347 | ␉}␊ |
348 | ␊ |
349 | ␉// Correct the checksum␊ |
350 | ␉fadt_mod->Checksum=0;␊ |
351 | ␉fadt_mod->Checksum=256-checksum8(fadt_mod,fadt_mod->Length);␊ |
352 | ␊ |
353 | ␉return fadt_mod;␊ |
354 | }␊ |
355 | ␊ |
356 | /* Setup ACPI without replacing DSDT. */␊ |
357 | int setupAcpiNoMod()␊ |
358 | {␊ |
359 | //␉addConfigurationTable(&gEfiAcpiTableGuid, getAddressOfAcpiTable(), "ACPI");␊ |
360 | //␉addConfigurationTable(&gEfiAcpi20TableGuid, getAddressOfAcpi20Table(), "ACPI_20");␊ |
361 | ␉/* XXX aserebln why uint32 cast if pointer is uint64 ? */␊ |
362 | ␉acpi10_p = (uint64_t)(uint32_t)getAddressOfAcpiTable();␊ |
363 | ␉acpi20_p = (uint64_t)(uint32_t)getAddressOfAcpi20Table();␊ |
364 | ␉addConfigurationTable(&gEfiAcpiTableGuid, &acpi10_p, "ACPI");␊ |
365 | ␉if(acpi20_p)␊ |
366 | ␉{␊ |
367 | ␉␉addConfigurationTable(&gEfiAcpi20TableGuid, &acpi20_p, "ACPI_20");␊ |
368 | ␉}␊ |
369 | ␉else␊ |
370 | ␉{␊ |
371 | ␉␉DBG("No ACPI 2.\n");␊ |
372 | ␉}␊ |
373 | ␉return 1;␊ |
374 | }␊ |
375 | ␊ |
376 | /* Setup ACPI. Replace DSDT if DSDT.aml is found */␊ |
377 | int setupAcpi(void)␊ |
378 | {␊ |
379 | ␉int version;␊ |
380 | ␊ |
381 | ␉// ACPI Tables␊ |
382 | ␉bool drop_dmar = getBoolForKey(kDropDMAR, &drop_dmar, &bootInfo->chameleonConfig);␊ |
383 | ␉bool drop_hpet = getBoolForKey(kDropHPET, &drop_hpet, &bootInfo->chameleonConfig);␊ |
384 | ␉bool drop_slic = getBoolForKey(kDropSLIC, &drop_slic, &bootInfo->chameleonConfig);␊ |
385 | ␉bool drop_sbst = getBoolForKey(kDropSBST, &drop_sbst, &bootInfo->chameleonConfig);␊ |
386 | ␉bool drop_ecdt = getBoolForKey(kDropECDT, &drop_ecdt, &bootInfo->chameleonConfig);␊ |
387 | ␉bool drop_asft = getBoolForKey(kDropASFT, &drop_asft, &bootInfo->chameleonConfig);␊ |
388 | ␊ |
389 | ␉void *new_dsdt = NULL; // DSDT.aml DSDT␊ |
390 | ␉void *new_hpet = NULL; // HPET.aml HPET␊ |
391 | ␉void *new_sbst = NULL; // SBST.aml SBST␊ |
392 | ␉void *new_ecdt = NULL; // ECDT.aml ECDT␊ |
393 | ␉void *new_asft = NULL; // ASFT.aml ASF!␊ |
394 | ␉void *new_dmar = NULL; // DMAR.aml DMAR␊ |
395 | ␉void *new_apic = NULL; // APIC.aml APIC␊ |
396 | ␉void *new_mcfg = NULL; // MCFG.aml MCFG␊ |
397 | ␊ |
398 | ␉const char *filename;␊ |
399 | ␉char dirSpec[128];␊ |
400 | ␉int len = 0;␊ |
401 | ␊ |
402 | ␉// always reset cpu count to 0 when injecting new acpi␊ |
403 | ␉acpi_cpu_count = 0;␊ |
404 | ␊ |
405 | ␉/* Try using the file specified with the DSDT option */␊ |
406 | ␉if (getValueForKey(kDSDT, &filename, &len, &bootInfo->chameleonConfig))␊ |
407 | ␉{␊ |
408 | ␉␉snprintf(dirSpec, sizeof(dirSpec), filename);␊ |
409 | ␉}␊ |
410 | ␉else␊ |
411 | ␉{␊ |
412 | ␉␉sprintf(dirSpec, "DSDT.aml");␊ |
413 | ␉␉//verbose("dirSpec, DSDT.aml");␊ |
414 | ␉}␊ |
415 | ␊ |
416 | ␉// Load replacement DSDT␊ |
417 | ␉new_dsdt = loadACPITable(dirSpec);␊ |
418 | ␊ |
419 | ␉/* Try using the file specified with the HPET option */␊ |
420 | ␉if (getValueForKey(kHPET, &filename, &len, &bootInfo->chameleonConfig))␊ |
421 | ␉{␊ |
422 | ␉␉snprintf(dirSpec, sizeof(dirSpec), filename);␊ |
423 | ␉}␊ |
424 | ␉else␊ |
425 | ␉{␊ |
426 | ␉␉sprintf(dirSpec, "HPET.aml");␊ |
427 | ␉}␊ |
428 | ␉// Load replacement HPET␊ |
429 | ␉new_hpet = loadACPITable(dirSpec);␊ |
430 | ␊ |
431 | ␉/* Try using the file specified with the SBST option */␊ |
432 | ␉if (getValueForKey(kSBST, &filename, &len, &bootInfo->chameleonConfig))␊ |
433 | ␉{␊ |
434 | ␉␉snprintf(dirSpec, sizeof(dirSpec), filename);␊ |
435 | ␉}␊ |
436 | ␉else␊ |
437 | ␉{␊ |
438 | ␉␉sprintf(dirSpec, "SBST.aml");␊ |
439 | ␉}␊ |
440 | ␉// Load replacement SBST␊ |
441 | ␉new_sbst = loadACPITable(dirSpec);␊ |
442 | ␊ |
443 | ␉/* Try using the file specified with the ECDT option */␊ |
444 | ␉if (getValueForKey(kECDT, &filename, &len, &bootInfo->chameleonConfig))␊ |
445 | ␉{␊ |
446 | ␉␉snprintf(dirSpec, sizeof(dirSpec), filename);␊ |
447 | ␉}␊ |
448 | ␉else␊ |
449 | ␉{␊ |
450 | ␉␉sprintf(dirSpec, "ECDT.aml");␊ |
451 | ␉}␊ |
452 | ␉// Load replacement ECDT␊ |
453 | ␉new_ecdt = loadACPITable(dirSpec);␊ |
454 | ␊ |
455 | ␉/* Try using the file specified with the ASF! option */␊ |
456 | ␉if (getValueForKey(kASFT, &filename, &len, &bootInfo->chameleonConfig))␊ |
457 | ␉{␊ |
458 | ␉␉snprintf(dirSpec, sizeof(dirSpec), filename);␊ |
459 | ␉}␊ |
460 | ␉else␊ |
461 | ␉{␊ |
462 | ␉␉sprintf(dirSpec, "ASFT.aml");␊ |
463 | ␉}␊ |
464 | ␉// Load replacement ASF!␊ |
465 | ␉new_asft = loadACPITable(dirSpec);␊ |
466 | ␊ |
467 | ␉/* Try using the file specified with the DMAR option */␊ |
468 | ␉if (getValueForKey(kDMAR, &filename, &len, &bootInfo->chameleonConfig))␊ |
469 | ␉{␊ |
470 | ␉␉snprintf(dirSpec, sizeof(dirSpec), filename);␊ |
471 | ␉}␊ |
472 | ␉else␊ |
473 | ␉{␊ |
474 | ␉␉sprintf(dirSpec, "DMAR.aml");␊ |
475 | ␉}␊ |
476 | ␉// Load replacement DMAR␊ |
477 | ␉new_dmar = loadACPITable(dirSpec);␊ |
478 | ␊ |
479 | ␉/* Try using the file specified with the APIC option */␊ |
480 | ␉if (getValueForKey(kAPIC, &filename, &len, &bootInfo->chameleonConfig))␊ |
481 | ␉{␊ |
482 | ␉␉snprintf(dirSpec, sizeof(dirSpec), filename);␊ |
483 | ␉}␊ |
484 | ␉else␊ |
485 | ␉{␊ |
486 | ␉␉sprintf(dirSpec, "APIC.aml");␊ |
487 | ␉}␊ |
488 | ␉// Load replacement APIC␊ |
489 | ␉new_apic = loadACPITable(dirSpec);␊ |
490 | ␊ |
491 | ␉// Try using the file specified with the MCFG option */␊ |
492 | ␉if (getValueForKey(kMCFG, &filename, &len, &bootInfo->chameleonConfig))␊ |
493 | ␉{␊ |
494 | ␉␉snprintf(dirSpec, sizeof(dirSpec), filename);␊ |
495 | ␉}␊ |
496 | ␉else␊ |
497 | ␉{␊ |
498 | ␉␉sprintf(dirSpec, "MCFG.aml");␊ |
499 | ␉}␊ |
500 | ␉// Load replacement MCFG␊ |
501 | ␉new_mcfg = loadACPITable(dirSpec);␊ |
502 | ␊ |
503 | ␉// Mozodojo: going to patch FACP and load SSDT's even if DSDT.aml is not present␊ |
504 | ␉/*if (!new_dsdt)␊ |
505 | ␉ {␊ |
506 | ␉ return setupAcpiNoMod();␊ |
507 | ␉ }*/␊ |
508 | ␊ |
509 | ␉// Mozodojo: Load additional SSDTs␊ |
510 | ␉struct acpi_2_ssdt *new_ssdt[32]; // 30 + 2 additional tables for pss & cst␊ |
511 | ␉int ssdt_count=0;␊ |
512 | ␊ |
513 | ␉// SSDT Options␊ |
514 | ␉bool drop_ssdt = false, generate_pstates = false, generate_cstates = false;␊ |
515 | ␊ |
516 | ␉getBoolForKey(kDropSSDT, &drop_ssdt, &bootInfo->chameleonConfig);␊ |
517 | ␉getBoolForKey(kGeneratePStates, &generate_pstates, &bootInfo->chameleonConfig);␊ |
518 | ␉getBoolForKey(kGenerateCStates, &generate_cstates, &bootInfo->chameleonConfig);␊ |
519 | ␉//getBoolForKey(kGenerateTStates, &generate_tstates, &bootInfo->chameleonConfig);␊ |
520 | ␊ |
521 | ␉DBG("Generating P-States config: %s\n", generate_pstates ? "YES" : "NO");␊ |
522 | ␉DBG("Generating C-States config: %s\n", generate_cstates ? "YES" : "NO");␊ |
523 | ␉//DBG("Generating T-States config: %s\n", generate_tstates ? "YES" : "NO");␊ |
524 | ␊ |
525 | ␉{␊ |
526 | ␉␉int i;␊ |
527 | ␊ |
528 | ␉␉for (i = 0; i < 30; i++)␊ |
529 | ␉␉{␊ |
530 | ␉␉␉char filename[512];␊ |
531 | ␊ |
532 | ␉␉␉sprintf(filename, i > 0 ? "SSDT-%d.aml" : "SSDT.aml", i);␊ |
533 | ␊ |
534 | ␉␉␉if ( (new_ssdt[ssdt_count] = loadACPITable(filename)) )␊ |
535 | ␉␉␉{␊ |
536 | ␉␉␉␉ssdt_count++;␊ |
537 | ␉␉␉}␊ |
538 | ␉␉␉else␊ |
539 | ␉␉␉{␊ |
540 | ␉␉␉␉break;␊ |
541 | ␉␉␉}␊ |
542 | ␉␉}␊ |
543 | ␉}␊ |
544 | ␊ |
545 | ␉// Do the same procedure for both versions of ACPI␊ |
546 | ␉for (version = 0; version < 2; version++)␊ |
547 | ␉{␊ |
548 | ␉␉struct acpi_2_rsdp *rsdp, *rsdp_mod;␊ |
549 | ␉␉struct acpi_2_rsdt *rsdt, *rsdt_mod;␊ |
550 | ␉␉int rsdplength;␊ |
551 | ␊ |
552 | ␉␉// Find original rsdp␊ |
553 | ␉␉rsdp = (struct acpi_2_rsdp *)(version ? getAddressOfAcpi20Table() : getAddressOfAcpiTable());␊ |
554 | ␉␉if (!rsdp)␊ |
555 | ␉␉{␊ |
556 | ␉␉␉DBG("No ACPI version %d found. Ignoring\n", version+1);␊ |
557 | ␉␉␉if (version)␊ |
558 | ␉␉␉{␊ |
559 | ␉␉␉␉addConfigurationTable(&gEfiAcpi20TableGuid, NULL, "ACPI_20");␊ |
560 | ␉␉␉}␊ |
561 | ␉␉␉else␊ |
562 | ␉␉␉{␊ |
563 | ␉␉␉␉addConfigurationTable(&gEfiAcpiTableGuid, NULL, "ACPI");␊ |
564 | ␉␉␉}␊ |
565 | ␉␉␉continue;␊ |
566 | ␉␉}␊ |
567 | ␉␉rsdplength = version ? rsdp->Length : 20;␊ |
568 | ␊ |
569 | ␉␉DBG("RSDP version %d found @%x. Length=%d\n",version+1,rsdp,rsdplength);␊ |
570 | ␊ |
571 | ␉␉/* FIXME: no check that memory allocation succeeded ␊ |
572 | ␉␉ * Copy and patch RSDP,RSDT, XSDT and FADT␊ |
573 | ␉␉ * For more info see ACPI Specification pages 110 and following␊ |
574 | ␉␉ */␊ |
575 | ␊ |
576 | ␉␉rsdp_mod = (struct acpi_2_rsdp *) AllocateKernelMemory(rsdplength);␊ |
577 | ␉␉memcpy(rsdp_mod, rsdp, rsdplength);␊ |
578 | ␊ |
579 | ␉␉rsdt = (struct acpi_2_rsdt *)rsdp->RsdtAddress;␊ |
580 | ␊ |
581 | ␉␉DBG("RSDT @%x, Length %d\n",rsdt, rsdt ? rsdt->Length : 0);␊ |
582 | ␊ |
583 | ␉␉if (rsdt && (uint32_t)rsdt !=0xffffffff && rsdt->Length < 0x10000)␊ |
584 | ␉␉{␊ |
585 | ␉␉␉uint32_t *rsdt_entries;␊ |
586 | ␉␉␉int rsdt_entries_num;␊ |
587 | ␉␉␉int dropoffset=0, i;␊ |
588 | ␊ |
589 | ␉␉␉// mozo: using malloc cos I didn't found how to free already allocated kernel memory␊ |
590 | ␉␉␉rsdt_mod = (struct acpi_2_rsdt *)malloc(rsdt->Length);␊ |
591 | ␉␉␉memcpy(rsdt_mod, rsdt, rsdt->Length);␊ |
592 | ␉␉␉rsdp_mod->RsdtAddress = (uint32_t)rsdt_mod;␊ |
593 | ␉␉␉rsdt_entries_num = (rsdt_mod->Length - sizeof(struct acpi_2_rsdt)) / 4;␊ |
594 | ␉␉␉rsdt_entries = (uint32_t *)(rsdt_mod + 1);␊ |
595 | ␉␉␉for (i = 0;i < rsdt_entries_num;i++)␊ |
596 | ␉␉␉{␊ |
597 | ␉␉␉␉char *table=(char *)(rsdt_entries[i]);␊ |
598 | ␉␉␉␉if (!table)␊ |
599 | ␉␉␉␉{␊ |
600 | ␉␉␉␉␉continue;␊ |
601 | ␉␉␉␉}␊ |
602 | ␊ |
603 | ␉␉␉␉DBG("TABLE %c%c%c%c,",table[0],table[1],table[2],table[3]);␊ |
604 | ␊ |
605 | ␉␉␉␉rsdt_entries[i-dropoffset]=rsdt_entries[i];␊ |
606 | ␊ |
607 | ␉␉␉␉if (drop_ssdt && tableSign(table, "SSDT"))␊ |
608 | ␉␉␉␉{␊ |
609 | ␉␉␉␉␉DBG("OEM SSDT tables was dropped\n");␊ |
610 | ␉␉␉␉␉dropoffset++;␊ |
611 | ␉␉␉␉␉continue;␊ |
612 | ␉␉␉␉}␊ |
613 | ␊ |
614 | ␉␉␉␉if (drop_hpet && tableSign(table, "HPET"))␊ |
615 | ␉␉␉␉{␊ |
616 | ␉␉␉␉␉DBG("OEM HPET table was dropped\n");␊ |
617 | ␉␉␉␉␉dropoffset++;␊ |
618 | ␉␉␉␉␉continue;␊ |
619 | ␉␉␉␉}␊ |
620 | ␊ |
621 | ␉␉␉␉if (drop_slic && tableSign(table, "SLIC"))␊ |
622 | ␉␉␉␉{␊ |
623 | ␉␉␉␉␉DBG("OEM SLIC table was dropped\n");␊ |
624 | ␉␉␉␉␉dropoffset++;␊ |
625 | ␉␉␉␉␉continue;␊ |
626 | ␉␉␉␉}␊ |
627 | ␊ |
628 | ␉␉␉␉if (drop_sbst && tableSign(table, "SBST"))␊ |
629 | ␉␉␉␉{␊ |
630 | ␉␉␉␉␉DBG("OEM SBST table was dropped\n");␊ |
631 | ␉␉␉␉␉dropoffset++;␊ |
632 | ␉␉␉␉␉continue;␊ |
633 | ␉␉␉␉}␊ |
634 | ␊ |
635 | ␉␉␉␉if (drop_ecdt && tableSign(table, "ECDT"))␊ |
636 | ␉␉␉␉{␊ |
637 | ␉␉␉␉␉DBG("OEM ECDT table was dropped\n");␊ |
638 | ␉␉␉␉␉dropoffset++;␊ |
639 | ␉␉␉␉␉continue;␊ |
640 | ␉␉␉␉}␊ |
641 | ␊ |
642 | ␉␉␉␉if (drop_asft && tableSign(table, "ASF!"))␊ |
643 | ␉␉␉␉{␊ |
644 | ␉␉␉␉␉DBG("OEM ASF! table was dropped\n");␊ |
645 | ␉␉␉␉␉dropoffset++;␊ |
646 | ␉␉␉␉␉continue;␊ |
647 | ␉␉␉␉}␊ |
648 | ␊ |
649 | ␉␉␉␉if (drop_dmar && tableSign(table, "DMAR"))␊ |
650 | ␉␉␉␉{␊ |
651 | ␉␉␉␉␉DBG("OEM DMAR table was dropped\n");␊ |
652 | ␉␉␉␉␉dropoffset++;␊ |
653 | ␉␉␉␉␉continue;␊ |
654 | ␉␉␉␉}␊ |
655 | ␊ |
656 | ␉␉␉␉if (tableSign(table, "HPET"))␊ |
657 | ␉␉␉␉{␊ |
658 | ␉␉␉␉␉DBG("HPET found\n");␊ |
659 | ␉␉␉␉␉DBG("Custom HPET table was found\n");␊ |
660 | ␉␉␉␉␉if(new_hpet)␊ |
661 | ␉␉␉␉␉{␊ |
662 | ␉␉␉␉␉␉rsdt_entries[i-dropoffset]=(uint32_t)new_hpet;␊ |
663 | ␉␉␉␉␉}␊ |
664 | ␉␉␉␉␉continue;␊ |
665 | ␉␉␉␉}␊ |
666 | ␊ |
667 | ␉␉␉␉if (tableSign(table, "SBST"))␊ |
668 | ␉␉␉␉{␊ |
669 | ␉␉␉␉␉DBG("SBST found\n");␊ |
670 | ␉␉␉␉␉DBG("Custom SBST table was found\n");␊ |
671 | ␉␉␉␉␉if(new_sbst)␊ |
672 | ␉␉␉␉␉{␊ |
673 | ␉␉␉␉␉␉rsdt_entries[i-dropoffset]=(uint32_t)new_sbst;␊ |
674 | ␉␉␉␉␉}␊ |
675 | ␉␉␉␉␉continue;␊ |
676 | ␉␉␉␉}␊ |
677 | ␊ |
678 | ␉␉␉␉if (tableSign(table, "ECDT"))␊ |
679 | ␉␉␉␉{␊ |
680 | ␉␉␉␉␉DBG("ECDT found\n");␊ |
681 | ␉␉␉␉␉DBG("Custom ECDT table was found\n");␊ |
682 | ␉␉␉␉␉if(new_ecdt)␊ |
683 | ␉␉␉␉␉{␊ |
684 | ␉␉␉␉␉␉rsdt_entries[i-dropoffset]=(uint32_t)new_ecdt;␊ |
685 | ␉␉␉␉␉}␊ |
686 | ␉␉␉␉␉continue;␊ |
687 | ␉␉␉␉}␊ |
688 | ␊ |
689 | ␉␉␉␉if (tableSign(table, "ASF!"))␊ |
690 | ␉␉␉␉{␊ |
691 | ␉␉␉␉␉DBG("ASF! found\n");␊ |
692 | ␉␉␉␉␉DBG("Custom ASF! table was found\n");␊ |
693 | ␉␉␉␉␉if(new_asft)␊ |
694 | ␉␉␉␉␉{␊ |
695 | ␉␉␉␉␉␉rsdt_entries[i-dropoffset]=(uint32_t)new_asft;␊ |
696 | ␉␉␉␉␉}␊ |
697 | ␉␉␉␉␉continue;␊ |
698 | ␉␉␉␉}␊ |
699 | ␊ |
700 | ␉␉␉␉if (tableSign(table, "DMAR"))␊ |
701 | ␉␉␉␉{␊ |
702 | ␉␉␉␉␉DBG("DMAR found\n");␊ |
703 | ␉␉␉␉␉DBG("Custom DMAR table was found\n");␊ |
704 | ␉␉␉␉␉if(new_dmar)␊ |
705 | ␉␉␉␉␉{␊ |
706 | ␉␉␉␉␉␉rsdt_entries[i-dropoffset]=(uint32_t)new_dmar;␊ |
707 | ␉␉␉␉␉}␊ |
708 | ␉␉␉␉␉continue;␊ |
709 | ␉␉␉␉}␊ |
710 | ␊ |
711 | ␉␉␉␉if (tableSign(table, "APIC"))␊ |
712 | ␉␉␉␉{␊ |
713 | ␉␉␉␉␉DBG("APIC found\n");␊ |
714 | ␉␉␉␉␉DBG("Custom APIC table was found\n");␊ |
715 | ␉␉␉␉␉if(new_apic)␊ |
716 | ␉␉␉␉␉{␊ |
717 | ␉␉␉␉␉␉rsdt_entries[i-dropoffset]=(uint32_t)new_apic;␊ |
718 | ␉␉␉␉␉}␊ |
719 | ␉␉␉␉␉continue;␊ |
720 | ␉␉␉␉}␊ |
721 | ␊ |
722 | ␉␉␉␉if (tableSign(table, "MCFG"))␊ |
723 | ␉␉␉␉{␊ |
724 | ␉␉␉␉␉DBG("MCFG found\n");␊ |
725 | ␉␉␉␉␉DBG("Custom MCFG table was found\n");␊ |
726 | ␉␉␉␉␉if(new_mcfg)␊ |
727 | ␉␉␉␉␉{␊ |
728 | ␉␉␉␉␉␉rsdt_entries[i-dropoffset]=(uint32_t)new_mcfg;␊ |
729 | ␉␉␉␉␉}␊ |
730 | ␊ |
731 | ␉␉␉␉␉continue;␊ |
732 | ␉␉␉␉}␊ |
733 | ␉␉␉␉if (tableSign(table, "DSDT"))␊ |
734 | ␉␉␉␉{␊ |
735 | ␉␉␉␉␉DBG("DSDT found\n");␊ |
736 | ␉␉␉␉␉DBG("Custom DSDT table was found\n");␊ |
737 | ␉␉␉␉␉if(new_dsdt)␊ |
738 | ␉␉␉␉␉{␊ |
739 | ␉␉␉␉␉␉rsdt_entries[i-dropoffset]=(uint32_t)new_dsdt;␊ |
740 | ␉␉␉␉␉}␊ |
741 | ␊ |
742 | ␉␉␉␉␉continue;␊ |
743 | ␉␉␉␉}␊ |
744 | ␊ |
745 | ␉␉␉␉if (tableSign(table, "FACP"))␊ |
746 | ␉␉␉␉{␊ |
747 | ␉␉␉␉␉struct acpi_2_fadt *fadt, *fadt_mod;␊ |
748 | ␉␉␉␉␉fadt=(struct acpi_2_fadt *)rsdt_entries[i];␊ |
749 | ␊ |
750 | ␉␉␉␉␉DBG("FADT found @%x, Length %d\n",fadt, fadt->Length);␊ |
751 | ␊ |
752 | ␉␉␉␉␉if (!fadt || (uint32_t)fadt == 0xffffffff || fadt->Length>0x10000)␊ |
753 | ␉␉␉␉␉{␊ |
754 | ␉␉␉␉␉␉DBG("FADT incorrect. Not modified\n");␊ |
755 | ␉␉␉␉␉␉continue;␊ |
756 | ␉␉␉␉␉}␊ |
757 | ␉␉␉␉␉␊ |
758 | ␉␉␉␉␉fadt_mod = patch_fadt(fadt, new_dsdt);␊ |
759 | ␉␉␉␉␉rsdt_entries[i-dropoffset] = (uint32_t)fadt_mod;␊ |
760 | ␉␉␉␉␉␊ |
761 | ␉␉␉␉␉// Generate _CST SSDT␊ |
762 | ␉␉␉␉␉if (generate_cstates && (new_ssdt[ssdt_count] = generate_cst_ssdt(fadt_mod)))␊ |
763 | ␉␉␉␉␉{␊ |
764 | ␉␉␉␉␉␉DBG("C-States generated\n");␊ |
765 | ␉␉␉␉␉␉generate_cstates = false; // Generate SSDT only once!␊ |
766 | ␉␉␉␉␉␉ssdt_count++;␊ |
767 | ␉␉␉␉␉}␊ |
768 | ␊ |
769 | ␉␉␉␉␉// Generating _PSS SSDT␊ |
770 | ␉␉␉␉␉if (generate_pstates && (new_ssdt[ssdt_count] = generate_pss_ssdt((void*)fadt_mod->DSDT)))␊ |
771 | ␉␉␉␉␉{␊ |
772 | ␉␉␉␉␉␉DBG("P-States generated\n");␊ |
773 | ␉␉␉␉␉␉generate_pstates = false; // Generate SSDT only once!␊ |
774 | ␉␉␉␉␉␉ssdt_count++;␊ |
775 | ␉␉␉␉␉}␊ |
776 | ␉␉␉␉␉continue;␊ |
777 | ␉␉␉␉}␊ |
778 | ␉␉␉}␊ |
779 | ␉␉␉DBG("\n");␊ |
780 | ␊ |
781 | ␉␉␉// Allocate rsdt in Kernel memory area␊ |
782 | ␉␉␉rsdt_mod->Length += 4*ssdt_count - 4*dropoffset;␊ |
783 | ␉␉␉struct acpi_2_rsdt *rsdt_copy = (struct acpi_2_rsdt *)AllocateKernelMemory(rsdt_mod->Length);␊ |
784 | ␉␉␉memcpy(rsdt_copy, rsdt_mod, rsdt_mod->Length);␊ |
785 | ␉␉␉free(rsdt_mod);␊ |
786 | ␉␉␉rsdt_mod = rsdt_copy;␊ |
787 | ␉␉␉rsdp_mod->RsdtAddress = (uint32_t)rsdt_mod;␊ |
788 | ␉␉␉rsdt_entries_num = (rsdt_mod->Length-sizeof(struct acpi_2_rsdt)) / 4;␊ |
789 | ␉␉␉rsdt_entries = (uint32_t *)(rsdt_mod + 1);␊ |
790 | ␊ |
791 | ␉␉␉// Mozodojo: Insert additional SSDTs into RSDT␊ |
792 | ␉␉␉if(ssdt_count > 0)␊ |
793 | ␉␉␉{␊ |
794 | ␉␉␉␉int j;␊ |
795 | ␊ |
796 | ␉␉␉␉for (j=0; j<ssdt_count; j++)␊ |
797 | ␉␉␉␉{␊ |
798 | ␉␉␉␉␉rsdt_entries[i-dropoffset+j]=(uint32_t)new_ssdt[j];␊ |
799 | ␉␉␉␉}␊ |
800 | ␊ |
801 | ␉␉␉␉DBG("RSDT: Added %d SSDT table(s)\n", ssdt_count);␊ |
802 | ␊ |
803 | ␉␉␉}␊ |
804 | ␊ |
805 | ␉␉␉// Correct the checksum of RSDT␊ |
806 | ␉␉␉DBG("RSDT: Original checksum %d, ", rsdt_mod->Checksum);␊ |
807 | ␊ |
808 | ␉␉␉rsdt_mod->Checksum=0;␊ |
809 | ␉␉␉rsdt_mod->Checksum=256-checksum8(rsdt_mod,rsdt_mod->Length);␊ |
810 | ␊ |
811 | ␉␉␉DBG("New checksum %d at %x\n", rsdt_mod->Checksum,rsdt_mod);␊ |
812 | ␉␉}␊ |
813 | ␉␉else␊ |
814 | ␉␉{␊ |
815 | ␉␉␉rsdp_mod->RsdtAddress=0;␊ |
816 | ␉␉␉DBG("RSDT not found or RSDT incorrect\n");␊ |
817 | ␉␉}␊ |
818 | ␉␉DBG("\n");␊ |
819 | ␊ |
820 | ␉␉if (version)␊ |
821 | ␉␉{␊ |
822 | ␉␉␉struct acpi_2_xsdt *xsdt, *xsdt_mod;␊ |
823 | ␊ |
824 | ␉␉␉// FIXME: handle 64-bit address correctly␊ |
825 | ␊ |
826 | ␉␉␉xsdt=(struct acpi_2_xsdt*) ((uint32_t)rsdp->XsdtAddress);␊ |
827 | ␉␉␉DBG("XSDT @%x;%x, Length=%d Sign=%c%c%c%c\n", (uint32_t)(rsdp->XsdtAddress>>32),␊ |
828 | ␉␉␉␉(uint32_t)rsdp->XsdtAddress, xsdt->Length, xsdt[0], xsdt[1], xsdt[2], xsdt[3]);␊ |
829 | ␉␉␉if (xsdt && (uint64_t)rsdp->XsdtAddress<0xffffffff && xsdt->Length<0x10000)␊ |
830 | ␉␉␉{␊ |
831 | ␉␉␉␉uint64_t *xsdt_entries;␊ |
832 | ␉␉␉␉int xsdt_entries_num, i;␊ |
833 | ␉␉␉␉int dropoffset=0;␊ |
834 | ␊ |
835 | ␉␉␉␉// mozo: using malloc cos I didn't found how to free already allocated kernel memory␊ |
836 | ␉␉␉␉xsdt_mod=(struct acpi_2_xsdt*)malloc(xsdt->Length);␊ |
837 | ␉␉␉␉memcpy(xsdt_mod, xsdt, xsdt->Length);␊ |
838 | ␊ |
839 | ␉␉␉␉rsdp_mod->XsdtAddress = (uint32_t)xsdt_mod;␊ |
840 | ␉␉␉␉xsdt_entries_num = (xsdt_mod->Length - sizeof(struct acpi_2_xsdt)) / 8;␊ |
841 | ␉␉␉␉xsdt_entries = (uint64_t *)(xsdt_mod + 1);␊ |
842 | ␉␉␉␉for (i = 0;i < xsdt_entries_num;i++)␊ |
843 | ␉␉␉␉{␊ |
844 | ␉␉␉␉␉char *table = (char *)((uint32_t)(xsdt_entries[i]));␊ |
845 | ␉␉␉␉␉if (!table)␊ |
846 | ␉␉␉␉␉{␊ |
847 | ␉␉␉␉␉␉continue;␊ |
848 | ␉␉␉␉␉}␊ |
849 | ␉␉␉␉␉xsdt_entries[i - dropoffset] = xsdt_entries[i];␊ |
850 | ␊ |
851 | ␉␉␉␉␉if (drop_ssdt && tableSign(table, "SSDT"))␊ |
852 | ␉␉␉␉␉{␊ |
853 | ␉␉␉␉␉␉verbose("OEM SSDT tables was dropped\n");␊ |
854 | ␉␉␉␉␉␉dropoffset++;␊ |
855 | ␉␉␉␉␉␉continue;␊ |
856 | ␉␉␉␉␉}␊ |
857 | ␊ |
858 | ␉␉␉␉␉if (drop_hpet && tableSign(table, "HPET"))␊ |
859 | ␉␉␉␉␉{␊ |
860 | ␉␉␉␉␉␉verbose("OEM HPET table was dropped\n");␊ |
861 | ␉␉␉␉␉␉dropoffset++;␊ |
862 | ␉␉␉␉␉␉continue;␊ |
863 | ␉␉␉␉␉}␊ |
864 | ␊ |
865 | ␉␉␉␉␉if (drop_slic && tableSign(table, "SLIC"))␊ |
866 | ␉␉␉␉␉{␊ |
867 | ␉␉␉␉␉␉verbose("OEM SLIC table was dropped\n");␊ |
868 | ␉␉␉␉␉␉dropoffset++;␊ |
869 | ␉␉␉␉␉␉continue;␊ |
870 | ␉␉␉␉␉}␊ |
871 | ␊ |
872 | ␉␉␉␉␉if (drop_sbst && tableSign(table, "SBST"))␊ |
873 | ␉␉␉␉␉{␊ |
874 | ␉␉␉␉␉␉verbose("OEM SBST table was dropped\n");␊ |
875 | ␉␉␉␉␉␉dropoffset++;␊ |
876 | ␉␉␉␉␉␉continue;␊ |
877 | ␉␉␉␉␉}␊ |
878 | ␊ |
879 | ␉␉␉␉␉if (drop_ecdt && tableSign(table, "ECDT"))␊ |
880 | ␉␉␉␉␉{␊ |
881 | ␉␉␉␉␉␉verbose("OEM ECDT table was dropped\n");␊ |
882 | ␉␉␉␉␉␉dropoffset++;␊ |
883 | ␉␉␉␉␉␉continue;␊ |
884 | ␉␉␉␉␉}␊ |
885 | ␊ |
886 | ␉␉␉␉␉if (drop_asft && tableSign(table, "ASF!"))␊ |
887 | ␉␉␉␉␉{␊ |
888 | ␉␉␉␉␉␉verbose("OEM ASF! table was dropped\n");␊ |
889 | ␉␉␉␉␉␉dropoffset++;␊ |
890 | ␉␉␉␉␉␉continue;␊ |
891 | ␉␉␉␉␉}␊ |
892 | ␊ |
893 | ␉␉␉␉␉if (drop_dmar && tableSign(table, "DMAR"))␊ |
894 | ␉␉␉␉␉{␊ |
895 | ␉␉␉␉␉␉verbose("OEM DMAR table was dropped\n");␊ |
896 | ␉␉␉␉␉␉dropoffset++;␊ |
897 | ␉␉␉␉␉␉continue;␊ |
898 | ␉␉␉␉␉}␊ |
899 | ␊ |
900 | ␉␉␉␉␉if (tableSign(table, "DSDT"))␊ |
901 | ␉␉␉␉␉{␊ |
902 | ␉␉␉␉␉␉DBG("DSDT found\n");␊ |
903 | ␊ |
904 | ␉␉␉␉␉␉if (new_dsdt)␊ |
905 | ␉␉␉␉␉␉{␊ |
906 | ␉␉␉␉␉␉␉xsdt_entries[i-dropoffset]=(uint32_t)new_dsdt;␊ |
907 | ␉␉␉␉␉␉}␊ |
908 | ␊ |
909 | ␉␉␉␉␉␉DBG("TABLE %c%c%c%c@%x \n", table[0],table[1],table[2],table[3],xsdt_entries[i]);␊ |
910 | ␊ |
911 | ␉␉␉␉␉␉continue;␊ |
912 | ␉␉␉␉␉}␊ |
913 | ␊ |
914 | ␉␉␉␉␉if (tableSign(table, "HPET"))␊ |
915 | ␉␉␉␉␉{␊ |
916 | ␉␉␉␉␉␉DBG("HPET found\n");␊ |
917 | ␊ |
918 | ␉␉␉␉␉␉if (new_hpet)␊ |
919 | ␉␉␉␉␉␉{␊ |
920 | ␉␉␉␉␉␉␉xsdt_entries[i-dropoffset]=(uint32_t)new_hpet;␊ |
921 | ␉␉␉␉␉␉}␊ |
922 | ␊ |
923 | ␉␉␉␉␉␉DBG("TABLE %c%c%c%c@%x \n", table[0],table[1],table[2],table[3],xsdt_entries[i]);␊ |
924 | ␊ |
925 | ␉␉␉␉␉␉continue;␊ |
926 | ␉␉␉␉␉}␊ |
927 | ␊ |
928 | ␉␉␉␉␉if (tableSign(table, "SBST"))␊ |
929 | ␉␉␉␉␉{␊ |
930 | ␉␉␉␉␉␉DBG("SBST found\n");␊ |
931 | ␊ |
932 | ␉␉␉␉␉␉if (new_sbst)␊ |
933 | ␉␉␉␉␉␉{␊ |
934 | ␉␉␉␉␉␉␉xsdt_entries[i-dropoffset]=(uint32_t)new_sbst;␊ |
935 | ␉␉␉␉␉␉}␊ |
936 | ␊ |
937 | ␉␉␉␉␉␉DBG("TABLE %c%c%c%c@%x \n", table[0],table[1],table[2],table[3],xsdt_entries[i]);␊ |
938 | ␊ |
939 | ␉␉␉␉␉␉continue;␊ |
940 | ␉␉␉␉␉}␊ |
941 | ␊ |
942 | ␉␉␉␉␉if (tableSign(table, "ECDT"))␊ |
943 | ␉␉␉␉␉{␊ |
944 | ␉␉␉␉␉␉DBG("ECDT found\n");␊ |
945 | ␊ |
946 | ␉␉␉␉␉␉if (new_ecdt)␊ |
947 | ␉␉␉␉␉␉{␊ |
948 | ␉␉␉␉␉␉␉xsdt_entries[i-dropoffset]=(uint32_t)new_ecdt;␊ |
949 | ␉␉␉␉␉␉}␊ |
950 | ␊ |
951 | ␉␉␉␉␉␉DBG("TABLE %c%c%c%c@%x \n", table[0],table[1],table[2],table[3],xsdt_entries[i]);␊ |
952 | ␊ |
953 | ␉␉␉␉␉␉continue;␊ |
954 | ␉␉␉␉␉}␊ |
955 | ␊ |
956 | ␉␉␉␉␉if (tableSign(table, "ASF!"))␊ |
957 | ␉␉␉␉␉{␊ |
958 | ␉␉␉␉␉␉DBG("ASF! found\n");␊ |
959 | ␊ |
960 | ␉␉␉␉␉␉if (new_asft)␊ |
961 | ␉␉␉␉␉␉{␊ |
962 | ␉␉␉␉␉␉␉xsdt_entries[i-dropoffset]=(uint32_t)new_asft;␊ |
963 | ␉␉␉␉␉␉}␊ |
964 | ␊ |
965 | ␉␉␉␉␉␉DBG("TABLE %c%c%c%c@%x \n", table[0],table[1],table[2],table[3],xsdt_entries[i]);␊ |
966 | ␊ |
967 | ␉␉␉␉␉␉continue;␊ |
968 | ␉␉␉␉␉}␊ |
969 | ␊ |
970 | ␉␉␉␉␉if (tableSign(table, "DMAR"))␊ |
971 | ␉␉␉␉␉{␊ |
972 | ␉␉␉␉␉␉DBG("DMAR found\n");␊ |
973 | ␊ |
974 | ␉␉␉␉␉␉if (new_dmar)␊ |
975 | ␉␉␉␉␉␉{␊ |
976 | ␉␉␉␉␉␉␉xsdt_entries[i-dropoffset]=(uint32_t)new_dmar;␊ |
977 | ␉␉␉␉␉␉}␊ |
978 | ␊ |
979 | ␉␉␉␉␉␉DBG("TABLE %c%c%c%c@%x \n", table[0],table[1],table[2],table[3],xsdt_entries[i]);␊ |
980 | ␊ |
981 | ␉␉␉␉␉␉continue;␊ |
982 | ␉␉␉␉␉}␊ |
983 | ␊ |
984 | ␉␉␉␉␉if (tableSign(table, "APIC"))␊ |
985 | ␉␉␉␉␉{␊ |
986 | ␉␉␉␉␉␉DBG("APIC found\n");␊ |
987 | ␊ |
988 | ␉␉␉␉␉␉if (new_apic)␊ |
989 | ␉␉␉␉␉␉{␊ |
990 | ␉␉␉␉␉␉␉xsdt_entries[i-dropoffset]=(uint32_t)new_apic;␊ |
991 | ␉␉␉␉␉␉}␊ |
992 | ␊ |
993 | ␉␉␉␉␉␉DBG("TABLE %c%c%c%c@%x \n", table[0],table[1],table[2],table[3],xsdt_entries[i]);␊ |
994 | ␊ |
995 | ␉␉␉␉␉␉continue;␊ |
996 | ␉␉␉␉␉}␊ |
997 | ␊ |
998 | ␉␉␉␉␉if (tableSign(table, "MCFG"))␊ |
999 | ␉␉␉␉␉{␊ |
1000 | ␉␉␉␉␉␉DBG("MCFG found\n");␊ |
1001 | ␊ |
1002 | ␉␉␉␉␉␉if (new_mcfg)␊ |
1003 | ␉␉␉␉␉␉{␊ |
1004 | ␉␉␉␉␉␉␉xsdt_entries[i-dropoffset]=(uint32_t)new_mcfg;␊ |
1005 | ␉␉␉␉␉␉}␊ |
1006 | ␊ |
1007 | ␉␉␉␉␉␉DBG("TABLE %c%c%c%c@%x \n", table[0],table[1],table[2],table[3],xsdt_entries[i]);␊ |
1008 | ␊ |
1009 | ␉␉␉␉␉␉continue;␊ |
1010 | ␉␉␉␉␉}␊ |
1011 | ␊ |
1012 | ␉␉␉␉␉if (tableSign(table, "FACP"))␊ |
1013 | ␉␉␉␉␉{␊ |
1014 | ␉␉␉␉␉␉struct acpi_2_fadt *fadt, *fadt_mod;␊ |
1015 | ␉␉␉␉␉␉fadt=(struct acpi_2_fadt *)(uint32_t)xsdt_entries[i];␊ |
1016 | ␊ |
1017 | ␉␉␉␉␉␉DBG("FADT found @%x%x, Length %d\n",(uint32_t)(xsdt_entries[i]>>32),fadt, ␊ |
1018 | ␉␉␉␉␉␉␉fadt->Length);␊ |
1019 | ␊ |
1020 | ␉␉␉␉␉␉if (!fadt || (uint64_t)xsdt_entries[i] >= 0xffffffff || fadt->Length>0x10000)␊ |
1021 | ␉␉␉␉␉␉{␊ |
1022 | ␉␉␉␉␉␉␉DBG("FADT incorrect or after 4GB. Dropping XSDT\n");␊ |
1023 | ␉␉␉␉␉␉␉goto drop_xsdt;␊ |
1024 | ␉␉␉␉␉␉}␊ |
1025 | ␊ |
1026 | ␉␉␉␉␉␉fadt_mod = patch_fadt(fadt, new_dsdt);␊ |
1027 | ␉␉␉␉␉␉xsdt_entries[i-dropoffset]=(uint32_t)fadt_mod;␊ |
1028 | ␊ |
1029 | ␉␉␉␉␉␉// DBG("TABLE %c%c%c%c@%x \n", table[0],table[1],table[2],table[3],xsdt_entries[i]);␊ |
1030 | ␊ |
1031 | ␉␉␉␉␉␉// Generate _CST SSDT␊ |
1032 | ␉␉␉␉␉␉if (generate_cstates && (new_ssdt[ssdt_count] = generate_cst_ssdt(fadt_mod)))␊ |
1033 | ␉␉␉␉␉␉{␊ |
1034 | ␉␉␉␉␉␉␉DBG("C-States generated\n");␊ |
1035 | ␉␉␉␉␉␉␉generate_cstates = false; // Generate SSDT only once!␊ |
1036 | ␉␉␉␉␉␉␉ssdt_count++;␊ |
1037 | ␉␉␉␉␉␉}␊ |
1038 | ␊ |
1039 | ␉␉␉␉␉␉// Generating _PSS SSDT␊ |
1040 | ␉␉␉␉␉␉if (generate_pstates && (new_ssdt[ssdt_count] = generate_pss_ssdt((void*)fadt_mod->DSDT)))␊ |
1041 | ␉␉␉␉␉␉{␊ |
1042 | ␉␉␉␉␉␉␉DBG("P-States generated\n");␊ |
1043 | ␉␉␉␉␉␉␉generate_pstates = false; // Generate SSDT only once!␊ |
1044 | ␉␉␉␉␉␉␉ssdt_count++;␊ |
1045 | ␉␉␉␉␉␉}␊ |
1046 | ␊ |
1047 | ␉␉␉␉␉␉// Generating _TSS SSDT␊ |
1048 | ␉␉␉␉␉␉/*if (generate_tstates && (new_ssdt[ssdt_count] = generate_tss_ssdt((void*)fadt_mod->DSDT)))␊ |
1049 | ␉␉␉␉␉␉{␊ |
1050 | ␉␉␉␉␉␉␉generate_tstates = false; // Generate SSDT only once!␊ |
1051 | ␉␉␉␉␉␉␉ssdt_count++;␊ |
1052 | ␉␉␉␉␉␉}*/␊ |
1053 | ␉␉␉␉␉␉continue;␊ |
1054 | ␉␉␉␉␉}␊ |
1055 | ␊ |
1056 | ␉␉␉␉␉DBG("TABLE %c%c%c%c@%x \n", table[0],table[1],table[2],table[3],xsdt_entries[i]);␊ |
1057 | ␊ |
1058 | ␉␉␉␉}␊ |
1059 | ␊ |
1060 | ␉␉␉␉// Allocate xsdt in Kernel memory area␊ |
1061 | ␉␉␉␉xsdt_mod->Length += 8*ssdt_count - 8*dropoffset;␊ |
1062 | ␉␉␉␉struct acpi_2_xsdt *xsdt_copy = (struct acpi_2_xsdt *)AllocateKernelMemory(xsdt_mod->Length);␊ |
1063 | ␉␉␉␉memcpy(xsdt_copy, xsdt_mod, xsdt_mod->Length);␊ |
1064 | ␉␉␉␉free(xsdt_mod);␊ |
1065 | ␉␉␉␉xsdt_mod = xsdt_copy;␊ |
1066 | ␉␉␉␉rsdp_mod->XsdtAddress = (uint32_t)xsdt_mod;␊ |
1067 | ␉␉␉␉xsdt_entries_num = (xsdt_mod->Length - sizeof(struct acpi_2_xsdt)) / 8;␊ |
1068 | ␉␉␉␉xsdt_entries = (uint64_t *)(xsdt_mod + 1);␊ |
1069 | ␊ |
1070 | ␉␉␉␉// Mozodojo: Insert additional SSDTs into XSDT␊ |
1071 | ␉␉␉␉if(ssdt_count > 0)␊ |
1072 | ␉␉␉␉{␊ |
1073 | ␉␉␉␉␉int j;␊ |
1074 | ␊ |
1075 | ␉␉␉␉␉for (j=0; j<ssdt_count; j++)␊ |
1076 | ␉␉␉␉␉{␊ |
1077 | ␉␉␉␉␉␉xsdt_entries[i-dropoffset+j]=(uint32_t)new_ssdt[j];␊ |
1078 | ␉␉␉␉␉}␊ |
1079 | ␊ |
1080 | ␉␉␉␉␉verbose("Added %d SSDT table(s) into XSDT\n", ssdt_count);␊ |
1081 | ␊ |
1082 | ␉␉␉␉}␊ |
1083 | ␊ |
1084 | ␉␉␉␉// Correct the checksum of XSDT␊ |
1085 | ␉␉␉␉xsdt_mod->Checksum=0;␊ |
1086 | ␉␉␉␉xsdt_mod->Checksum=256-checksum8(xsdt_mod,xsdt_mod->Length);␊ |
1087 | ␉␉␉}␊ |
1088 | ␉␉␉else␊ |
1089 | ␉␉␉{␊ |
1090 | ␉␉␉drop_xsdt:␊ |
1091 | ␊ |
1092 | ␉␉␉␉DBG("About to drop XSDT\n");␊ |
1093 | ␊ |
1094 | ␉␉␉␉/*FIXME: Now we just hope that if MacOS doesn't find XSDT it reverts to RSDT. ␊ |
1095 | ␉␉␉␉ * A Better strategy would be to generate␊ |
1096 | ␉␉␉␉ */␊ |
1097 | ␊ |
1098 | ␉␉␉␉rsdp_mod->XsdtAddress=0xffffffffffffffffLL;␊ |
1099 | ␉␉␉␉verbose("XSDT not found or XSDT incorrect\n");␊ |
1100 | ␉␉␉}␊ |
1101 | ␉␉}␊ |
1102 | ␉␉DBG("\n");␊ |
1103 | ␊ |
1104 | ␉␉// Correct the checksum of RSDP␊ |
1105 | ␊ |
1106 | ␉␉DBG("RSDP: Original checksum %d, ", rsdp_mod->Checksum);␊ |
1107 | ␊ |
1108 | ␉␉rsdp_mod->Checksum=0;␊ |
1109 | ␉␉rsdp_mod->Checksum=256-checksum8(rsdp_mod,20);␊ |
1110 | ␊ |
1111 | ␉␉DBG("New checksum %d\n", rsdp_mod->Checksum);␊ |
1112 | ␊ |
1113 | ␉␉if (version)␊ |
1114 | ␉␉{␊ |
1115 | ␉␉␉DBG("RSDP: Original extended checksum %d, ", rsdp_mod->ExtendedChecksum);␊ |
1116 | ␊ |
1117 | ␉␉␉rsdp_mod->ExtendedChecksum=0;␊ |
1118 | ␉␉␉rsdp_mod->ExtendedChecksum=256-checksum8(rsdp_mod,rsdp_mod->Length);␊ |
1119 | ␊ |
1120 | ␉␉␉DBG("New extended checksum %d\n", rsdp_mod->ExtendedChecksum);␊ |
1121 | ␊ |
1122 | ␉␉}␊ |
1123 | ␊ |
1124 | ␉␉if (version)␊ |
1125 | ␉␉{␊ |
1126 | ␉␉␉/* XXX aserebln why uint32 cast if pointer is uint64 ? */␊ |
1127 | ␉␉␉acpi20_p = (uint64_t)(uint32_t)rsdp_mod;␊ |
1128 | ␉␉␉addConfigurationTable(&gEfiAcpi20TableGuid, &acpi20_p, "ACPI_20");␊ |
1129 | ␉␉}␊ |
1130 | ␉␉else␊ |
1131 | ␉␉{␊ |
1132 | ␉␉␉/* XXX aserebln why uint32 cast if pointer is uint64 ? */␊ |
1133 | ␉␉␉acpi10_p = (uint64_t)(uint32_t)rsdp_mod;␊ |
1134 | ␉␉␉addConfigurationTable(&gEfiAcpiTableGuid, &acpi10_p, "ACPI");␊ |
1135 | ␉␉}␊ |
1136 | ␉␉DBG("ACPI version %d patching finished\n\n", version+1);␊ |
1137 | ␉}␊ |
1138 | #if DEBUG_ACPI␊ |
1139 | ␉printf("Press a key to continue... (DEBUG_ACPI)\n");␊ |
1140 | ␉getchar();␊ |
1141 | #endif␊ |
1142 | ␉return 1;␊ |
1143 | }␊ |
1144 | |