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 "dsdt_patcher.h"␊ |
12 | #include "platform.h"␊ |
13 | ␊ |
14 | #ifndef DEBUG_DSDT␊ |
15 | #define DEBUG_DSDT 0␊ |
16 | #endif␊ |
17 | ␊ |
18 | #if DEBUG_DSDT==2␊ |
19 | #define DBG(x...) {printf(x); sleep(1);}␊ |
20 | #elif DEBUG_DSDT==1␊ |
21 | #define DBG(x...) printf(x)␊ |
22 | #else␊ |
23 | #define DBG(x...)␊ |
24 | #endif␊ |
25 | ␊ |
26 | /* Gets the ACPI 1.0 RSDP address */␊ |
27 | static struct acpi_2_rsdp* getAddressOfAcpiTable()␊ |
28 | {␊ |
29 | /* TODO: Before searching the BIOS space we are supposed to search the first 1K of the EBDA */␊ |
30 | ␉␊ |
31 | void *acpi_addr = (void*)ACPI_RANGE_START;␊ |
32 | for(; acpi_addr <= (void*)ACPI_RANGE_END; acpi_addr += 16)␊ |
33 | {␊ |
34 | if(*(uint64_t *)acpi_addr == ACPI_SIGNATURE_UINT64_LE)␊ |
35 | {␊ |
36 | uint8_t csum = checksum8(acpi_addr, 20);␊ |
37 | if(csum == 0)␊ |
38 | {␊ |
39 | // Only return the table if it is a true version 1.0 table (Revision 0)␊ |
40 | if(((struct acpi_2_rsdp*)acpi_addr)->Revision == 0)␊ |
41 | return acpi_addr;␊ |
42 | }␊ |
43 | }␊ |
44 | }␊ |
45 | return NULL;␊ |
46 | }␊ |
47 | ␊ |
48 | /* Gets the ACPI 2.0 RSDP address */␊ |
49 | static struct acpi_2_rsdp* getAddressOfAcpi20Table()␊ |
50 | {␊ |
51 | /* TODO: Before searching the BIOS space we are supposed to search the first 1K of the EBDA */␊ |
52 | ␉␊ |
53 | void *acpi_addr = (void*)ACPI_RANGE_START;␊ |
54 | for(; acpi_addr <= (void*)ACPI_RANGE_END; acpi_addr += 16)␊ |
55 | {␊ |
56 | if(*(uint64_t *)acpi_addr == ACPI_SIGNATURE_UINT64_LE)␊ |
57 | {␊ |
58 | uint8_t csum = checksum8(acpi_addr, 20);␊ |
59 | ␊ |
60 | /* Only assume this is a 2.0 or better table if the revision is greater than 0␊ |
61 | * NOTE: ACPI 3.0 spec only seems to say that 1.0 tables have revision 1␊ |
62 | * and that the current revision is 2.. I am going to assume that rev > 0 is 2.0.␊ |
63 | */␊ |
64 | ␊ |
65 | if(csum == 0 && (((struct acpi_2_rsdp*)acpi_addr)->Revision > 0))␊ |
66 | {␊ |
67 | uint8_t csum2 = checksum8(acpi_addr, sizeof(struct acpi_2_rsdp));␊ |
68 | if(csum2 == 0)␊ |
69 | return acpi_addr;␊ |
70 | }␊ |
71 | }␊ |
72 | }␊ |
73 | return NULL;␊ |
74 | }␊ |
75 | <<<<<<< .mine␊ |
76 | ␊ |
77 | void *loadACPITable(char *key)␊ |
78 | =======␊ |
79 | /** The folowing ACPI Table search algo. should be reused anywhere needed:*/␊ |
80 | int search_and_get_acpi_fd(const char * filename, const char ** outDirspec)␊ |
81 | >>>>>>> .r60␊ |
82 | {␊ |
83 | <<<<<<< .mine␊ |
84 | ␉void *tableAddr;␊ |
85 | ␉int fd = -1;␊ |
86 | ␉char dirspec[512];␊ |
87 | ␉char filename[512];␊ |
88 | ␉const char * overriden_pathname=NULL;␊ |
89 | ␉int len=0;␊ |
90 | =======␊ |
91 | int fd=0;␊ |
92 | const char * overriden_pathname=NULL;␊ |
93 | static char dirspec[512]="";␊ |
94 | int len=0;␊ |
95 | >>>>>>> .r60␊ |
96 | ␊ |
97 | <<<<<<< .mine␊ |
98 | ␉sprintf(filename, "%s.aml", key);␊ |
99 | ␊ |
100 | ␉// Check booting partition␊ |
101 | ␊ |
102 | ␉// Rek: if user specified a full path name then take it in consideration␊ |
103 | ␉if (getValueForKey(key, &overriden_pathname, &len, ␊ |
104 | ␉␉&bootInfo->bootConfig))␊ |
105 | =======␊ |
106 | /// Take in accound user overriding if it's DSDT only␊ |
107 | if (strstr(filename, "DSDT") && ␊ |
108 | getValueForKey(kDSDT, &overriden_pathname, &len, ␊ |
109 | ␉␉␉ &bootInfo->bootConfig))␊ |
110 | >>>>>>> .r60␊ |
111 | <<<<<<< .mine␊ |
112 | ␉{␊ |
113 | ␉␉sprintf(dirspec, "%s", overriden_pathname); // start searching root␊ |
114 | ␉␉//printf("Using custom %s path %s\n", key, dirspec);␊ |
115 | ␉␉//getc();␊ |
116 | ␉}␊ |
117 | ␉else␊ |
118 | ␉␉sprintf(dirspec, "/%s", filename); // start searching root␊ |
119 | =======␊ |
120 | {␊ |
121 | sprintf(dirspec, "%s", overriden_pathname); // start searching root␊ |
122 | fd=open (dirspec,0);␊ |
123 | if (fd>=0) goto success_fd;␊ |
124 | }␊ |
125 | >>>>>>> .r60␊ |
126 | ␊ |
127 | // Start searching any potential location for ACPI Table␊ |
128 | sprintf(dirspec, "/%s", filename); // start searching root␊ |
129 | fd=open (dirspec,0);␊ |
130 | if (fd>=0) goto success_fd;␊ |
131 | ␊ |
132 | <<<<<<< .mine␊ |
133 | ␉if (fd<0)␊ |
134 | ␉{␉// Check Extra on booting partition␊ |
135 | ␉ //verbose("Searching for %s.aml file ...\n", key);␊ |
136 | ␉␉sprintf(dirspec,"/Extra/%s",filename);␊ |
137 | ␉␉fd=open (dirspec,0);␊ |
138 | ␉␉if (fd<0)␊ |
139 | ␉␉{␉// Fall back to booter partition␊ |
140 | ␉␉␉sprintf(dirspec,"bt(0,0)/Extra/%s",filename);␊ |
141 | ␉␉␉fd=open (dirspec,0);␊ |
142 | ␉␉␉if (fd<0)␊ |
143 | ␉␉␉{␊ |
144 | ␉␉␉␉verbose("ACPI Table not found: %s\n", filename);␊ |
145 | ␉␉␉␉return NULL;␊ |
146 | ␉␉␉}␊ |
147 | ␉␉}␊ |
148 | ␉}␊ |
149 | =======␊ |
150 | sprintf(dirspec, "%s", filename); // start current dir␊ |
151 | fd=open (dirspec,0);␊ |
152 | if (fd>=0) goto success_fd;␊ |
153 | >>>>>>> .r60␊ |
154 | ␊ |
155 | sprintf(dirspec,"/Extra/%s",filename);␊ |
156 | fd=open (dirspec,0);␊ |
157 | if (fd>=0) goto success_fd;␊ |
158 | ␊ |
159 | sprintf(dirspec,"bt(0,0)/Extra/%s",filename);␊ |
160 | fd=open (dirspec,0);␊ |
161 | if (fd>=0) goto success_fd;␊ |
162 | ␊ |
163 | // NOT FOUND:␊ |
164 | verbose("ACPI Table not found: %s\n", filename);␊ |
165 | if (outDirspec) *outDirspec = "";␊ |
166 | return -1;␊ |
167 | // FOUND␊ |
168 | success_fd:␊ |
169 | if (outDirspec) *outDirspec = dirspec; ␊ |
170 | return fd;␊ |
171 | }␊ |
172 | ␊ |
173 | void *loadACPITable (const char * filename)␊ |
174 | {␊ |
175 | ␉void *tableAddr;␊ |
176 | ␉const char * dirspec=NULL;␊ |
177 | ␉␊ |
178 | ␉int fd = search_and_get_acpi_fd(filename, &dirspec);␊ |
179 | ␊ |
180 | ␉if (fd>=0)␊ |
181 | ␉{␊ |
182 | ␉ tableAddr=(void*)AllocateKernelMemory(file_size (fd));␊ |
183 | ␉ if (tableAddr)␊ |
184 | ␉ {␊ |
185 | ␉ if (read (fd, tableAddr, file_size (fd))!=file_size (fd))␊ |
186 | ␉ {␊ |
187 | ␉␉ printf("Couldn't read table %s\n",dirspec);␊ |
188 | ␉␉ free (tableAddr);␊ |
189 | ␉␉ close (fd);␊ |
190 | ␉␉ return NULL;␊ |
191 | ␉ }␊ |
192 | ␉ ␊ |
193 | ␉ DBG("Table %s read and stored at: %x\n", dirspec, tableAddr);␊ |
194 | ␉ close (fd);␊ |
195 | ␉ return tableAddr;␊ |
196 | ␉ }␊ |
197 | ␉ close (fd);␊ |
198 | ␉} ␊ |
199 | ␉printf("Couldn't allocate memory for table %s\n", dirspec);␊ |
200 | ␊ |
201 | ␉return NULL;␊ |
202 | }␊ |
203 | ␊ |
204 | void *loadSSDTTable(int ssdt_number)␊ |
205 | {␊ |
206 | ␉void *tableAddr;␊ |
207 | ␉int fd = -1;␊ |
208 | ␉char dirspec[512];␊ |
209 | ␉char filename[512];␊ |
210 | ␉const char * overriden_pathname=NULL;␊ |
211 | ␉int len=0;␊ |
212 | ␊ |
213 | ␉sprintf(filename, "SSDT-%d.aml", ssdt_number);␊ |
214 | ␉␊ |
215 | ␉// Check booting partition␊ |
216 | ␉␊ |
217 | ␉// Rek: if user specified a full path name then take it in consideration␊ |
218 | ␉if (getValueForKey(kSSDT, &overriden_pathname, &len, ␊ |
219 | ␉␉␉␉␉ &bootInfo->bootConfig))␊ |
220 | ␉{␊ |
221 | ␉␉sprintf(dirspec, "%s-%d.aml", overriden_pathname, ssdt_number); // start searching root␊ |
222 | ␉␉//printf("Using custom %s path %s\n", key, dirspec);␊ |
223 | ␉␉//getc();␊ |
224 | ␉}␊ |
225 | ␉else␊ |
226 | ␉␉sprintf(dirspec, "/%s", filename); // start searching root␊ |
227 | ␉␊ |
228 | ␉fd=open (dirspec,0);␊ |
229 | ␉␊ |
230 | ␉if (fd<0)␊ |
231 | ␉{␉// Check Extra on booting partition␊ |
232 | ␉␉//verbose("Searching for %s.aml file ...\n", key);␊ |
233 | ␉␉sprintf(dirspec,"/Extra/%s",filename);␊ |
234 | ␉␉fd=open (dirspec,0);␊ |
235 | ␉␉if (fd<0)␊ |
236 | ␉␉{␉// Fall back to booter partition␊ |
237 | ␉␉␉sprintf(dirspec,"bt(0,0)/Extra/%s",filename);␊ |
238 | ␉␉␉fd=open (dirspec,0);␊ |
239 | ␉␉␉if (fd<0)␊ |
240 | ␉␉␉{␊ |
241 | ␉␉␉␉verbose("SSDT Table not found: %s\n", filename);␊ |
242 | ␉␉␉␉return NULL;␊ |
243 | ␉␉␉}␊ |
244 | ␉␉}␊ |
245 | ␉}␊ |
246 | ␉␊ |
247 | ␉tableAddr=(void*)AllocateKernelMemory(file_size (fd));␊ |
248 | ␉if (tableAddr)␊ |
249 | ␉{␊ |
250 | ␉␉if (read (fd, tableAddr, file_size (fd))!=file_size (fd))␊ |
251 | ␉␉{␊ |
252 | ␉␉␉printf("Couldn't read table %s\n",dirspec);␊ |
253 | ␉␉␉free (tableAddr);␊ |
254 | ␉␉␉close (fd);␊ |
255 | ␉␉␉return NULL;␊ |
256 | ␉␉}␊ |
257 | ␉␉␊ |
258 | ␉␉DBG("Table %s read and stored at: %x\n", dirspec, tableAddr);␊ |
259 | ␉␉close (fd);␊ |
260 | ␉␉return tableAddr;␊ |
261 | ␉}␊ |
262 | ␉␊ |
263 | ␉printf("Couldn't allocate memory for table %s\n", dirspec);␊ |
264 | ␉close (fd);␊ |
265 | ␉␊ |
266 | ␉return NULL;␊ |
267 | }␊ |
268 | ␊ |
269 | struct acpi_2_gas FillGASStruct(uint32_t Address, uint8_t Length)␊ |
270 | {␊ |
271 | ␉struct acpi_2_gas TmpGAS;␊ |
272 | ␊ |
273 | ␉TmpGAS.Address_Space_ID = 1; /* I/O Address */␊ |
274 | ␊ |
275 | ␉if (Address == 0)␊ |
276 | ␉{␊ |
277 | ␉␉TmpGAS.Register_Bit_Width = 0;␊ |
278 | ␉} else {␊ |
279 | ␉␉TmpGAS.Register_Bit_Width = Length * 8;␊ |
280 | ␉}␊ |
281 | ␊ |
282 | ␉TmpGAS.Register_Bit_Offset = 0;␊ |
283 | ␉TmpGAS.Access_Size = 0; /* Not set for Legacy reasons... */␊ |
284 | ␉TmpGAS.Address = (uint64_t)Address;␊ |
285 | ␊ |
286 | ␉return(TmpGAS);␊ |
287 | }␊ |
288 | ␊ |
289 | struct acpi_2_fadt *␊ |
290 | patch_fadt(struct acpi_2_fadt *fadt, void *new_dsdt, bool UpdateFADT)␊ |
291 | {␊ |
292 | extern void setupSystemType(); ␊ |
293 | ␉␊ |
294 | ␉struct acpi_2_fadt *fadt_mod;␊ |
295 | ␉struct acpi_2_fadt *fadt_file = (struct acpi_2_fadt *)loadACPITable(kFADT);␊ |
296 | ␉bool fadt_rev2_needed = false;␊ |
297 | ␉bool fix_restart;␊ |
298 | ␉const char * value;␊ |
299 | ␊ |
300 | ␉// Restart Fix␊ |
301 | ␉if (Platform.CPU.Vendor == 0x756E6547) {␉/* Intel */␊ |
302 | ␉␉fix_restart = true;␊ |
303 | ␉␉getBoolForKey(kRestartFix, &fix_restart, &bootInfo->bootConfig);␊ |
304 | ␉} else {␊ |
305 | ␉␉verbose ("Not an Intel platform: Restart Fix not applied !!!\n");␊ |
306 | ␉␉fix_restart = false;␊ |
307 | ␉}␊ |
308 | ␊ |
309 | ␉if (fix_restart)␊ |
310 | ␉␉fadt_rev2_needed = true;␊ |
311 | ␊ |
312 | ␉// Allocate new fadt table␊ |
313 | ␉if ((UpdateFADT) && (((fadt_file) && (fadt_file->Length < sizeof(struct acpi_2_fadt))) ||␊ |
314 | ␉␉␉␉␉␉ ((!fadt_file) && (fadt->Length < sizeof(struct acpi_2_fadt)))))␊ |
315 | ␉{␊ |
316 | ␉␉fadt_mod=(struct acpi_2_fadt *)AllocateKernelMemory(sizeof(struct acpi_2_fadt));␊ |
317 | ␊ |
318 | ␉␉if (fadt_file)␊ |
319 | ␉␉␉memcpy(fadt_mod, fadt_file, fadt_file->Length);␊ |
320 | ␉␉else␊ |
321 | ␉␉␉memcpy(fadt_mod, fadt, fadt->Length);␊ |
322 | ␊ |
323 | ␉␉fadt_mod->Length = sizeof(struct acpi_2_fadt);␊ |
324 | ␉␉fadt_mod->Revision = 0x04; // FADT rev 4␊ |
325 | ␉␉fadt_mod->RESET_REG = FillGASStruct(0, 0);␊ |
326 | ␉␉fadt_mod->RESET_VALUE = 0;␊ |
327 | ␉␉fadt_mod->Reserved2[0] = 0;␊ |
328 | ␉␉fadt_mod->Reserved2[1] = 0;␊ |
329 | ␉␉fadt_mod->Reserved2[2] = 0;␊ |
330 | ␉␉fadt_mod->X_PM1a_EVT_BLK = FillGASStruct(fadt_mod->PM1a_EVT_BLK, fadt_mod->PM1_EVT_LEN);␊ |
331 | ␉␉fadt_mod->X_PM1b_EVT_BLK = FillGASStruct(fadt_mod->PM1b_EVT_BLK, fadt_mod->PM1_EVT_LEN);␊ |
332 | ␉␉fadt_mod->X_PM1a_CNT_BLK = FillGASStruct(fadt_mod->PM1a_CNT_BLK, fadt_mod->PM1_CNT_LEN);␊ |
333 | ␉␉fadt_mod->X_PM1b_CNT_BLK = FillGASStruct(fadt_mod->PM1b_CNT_BLK, fadt_mod->PM1_CNT_LEN);␊ |
334 | ␉␉fadt_mod->X_PM2_CNT_BLK = FillGASStruct(fadt_mod->PM2_CNT_BLK, fadt_mod->PM2_CNT_LEN);␊ |
335 | ␉␉fadt_mod->X_PM_TMR_BLK = FillGASStruct(fadt_mod->PM_TMR_BLK, fadt_mod->PM_TMR_LEN);␊ |
336 | ␉␉fadt_mod->X_GPE0_BLK = FillGASStruct(fadt_mod->GPE0_BLK, fadt_mod->GPE0_BLK_LEN);␊ |
337 | ␉␉fadt_mod->X_GPE1_BLK = FillGASStruct(fadt_mod->GPE1_BLK, fadt_mod->GPE1_BLK_LEN);␊ |
338 | ␉␉verbose("Converted ACPI V%d FADT to ACPI V4 FADT\n", (fadt_file) ? fadt_file->Revision : fadt->Revision);␊ |
339 | ␉} else {␊ |
340 | ␉␉if (((!fadt_file) && ((fadt->Length < 0x84) && (fadt_rev2_needed))) ||␊ |
341 | ␉␉␉ ((fadt_file) && ((fadt_file->Length < 0x84) && (fadt_rev2_needed))))␊ |
342 | ␉␉{␊ |
343 | ␉␉␉fadt_mod=(struct acpi_2_fadt *)AllocateKernelMemory(0x84);␊ |
344 | ␊ |
345 | ␉␉␉if (fadt_file)␊ |
346 | ␉␉␉␉memcpy(fadt_mod, fadt_file, fadt_file->Length);␊ |
347 | ␉␉␉else␊ |
348 | ␉␉␉␉memcpy(fadt_mod, fadt, fadt->Length);␊ |
349 | ␊ |
350 | ␉␉␉fadt_mod->Length = 0x84;␊ |
351 | ␉␉␉fadt_mod->Revision = 0x02; // FADT rev 2 (ACPI 1.0B MS extensions)␊ |
352 | ␉␉}␊ |
353 | ␉␉else␊ |
354 | ␉␉{␊ |
355 | ␉␉␉if (fadt_file)␊ |
356 | ␉␉␉{␊ |
357 | ␉␉␉␉fadt_mod=(struct acpi_2_fadt *)AllocateKernelMemory(fadt_file->Length);␊ |
358 | ␉␉␉␉memcpy(fadt_mod, fadt_file, fadt_file->Length);␊ |
359 | ␉␉␉} else {␊ |
360 | ␉␉␉␉fadt_mod=(struct acpi_2_fadt *)AllocateKernelMemory(fadt->Length);␊ |
361 | ␉␉␉␉memcpy(fadt_mod, fadt, fadt->Length);␊ |
362 | ␉␉␉}␊ |
363 | ␉␉}␊ |
364 | ␉}␊ |
365 | ␉// Determine system type / PM_Model␊ |
366 | ␉if ( (value=getStringForKey(kSystemType, &bootInfo->bootConfig))!=NULL)␊ |
367 | ␉{␊ |
368 | ␉ if (Platform.Type > 6) ␊ |
369 | ␉ {␊ |
370 | ␉ if(fadt_mod->Preferred_PM_Profile<=6)␊ |
371 | ␉ Platform.Type = fadt_mod->Preferred_PM_Profile; // get the fadt if correct␊ |
372 | ␉ else ␊ |
373 | ␉ Platform.Type = 1;␉␉/* Set a fixed value (Desktop) */␊ |
374 | ␉ verbose("Error: system-type must be 0..6. Defaulting to %d !\n", Platform.Type);␊ |
375 | ␉ }␊ |
376 | ␉ else␊ |
377 | ␉ Platform.Type = (unsigned char) strtoul(value, NULL, 10);␊ |
378 | ␉}␊ |
379 | ␉// Set Preferred_PM_Profile from System-type if only if user wanted this value to be forced␊ |
380 | ␉if (fadt_mod->Preferred_PM_Profile != Platform.Type) ␊ |
381 | ␉{␊ |
382 | ␉ if (value) ␊ |
383 | ␉ { // user has overriden the SystemType so take care of it in FACP␊ |
384 | ␉␉verbose("FADT: changing Preferred_PM_Profile from 0x%02x to 0x%02x\n", fadt_mod->Preferred_PM_Profile, Platform.Type);␊ |
385 | ␉␉fadt_mod->Preferred_PM_Profile = Platform.Type;␊ |
386 | ␉ }␊ |
387 | ␉ else␊ |
388 | ␉ { // Preferred_PM_Profile has a different value and no override has been set, so reflect the user value to ioregs␊ |
389 | ␉ Platform.Type = fadt_mod->Preferred_PM_Profile <= 6 ? fadt_mod->Preferred_PM_Profile : 1;␊ |
390 | ␉ } ␊ |
391 | ␉}␊ |
392 | ␉// We now have to write the systemm-type in ioregs: we cannot do it before in setupDeviceTree()␊ |
393 | ␉// because we need to take care of facp original content, if it is correct.␊ |
394 | ␉setupSystemType();␊ |
395 | ␊ |
396 | ␉// Patch FADT to fix restart␊ |
397 | ␉if (fix_restart)␊ |
398 | ␉{␊ |
399 | ␉␉fadt_mod->Flags|= 0x400;␊ |
400 | ␉␉fadt_mod->RESET_REG = FillGASStruct(0x0cf9, 1);␊ |
401 | ␉␉fadt_mod->RESET_VALUE = 0x06;␊ |
402 | ␉␉verbose("FADT: Restart Fix applied !\n");␊ |
403 | ␉}␊ |
404 | ␊ |
405 | ␉// Patch FACS Address␊ |
406 | ␉fadt_mod->FIRMWARE_CTRL=(uint32_t)fadt->FIRMWARE_CTRL;␊ |
407 | ␉if ((uint32_t)(&(fadt_mod->X_FIRMWARE_CTRL))-(uint32_t)fadt_mod+8<=fadt_mod->Length)␊ |
408 | ␉␉fadt_mod->X_FIRMWARE_CTRL=(uint32_t)fadt->FIRMWARE_CTRL␊ |
409 | ␊ |
410 | ␉// Patch DSDT Address␊ |
411 | ␉DBG("DSDT: Old @%x,%x, ",fadt_mod->DSDT,fadt_mod->X_DSDT);␊ |
412 | ␊ |
413 | ␉fadt_mod->DSDT=(uint32_t)new_dsdt;␊ |
414 | ␉if ((uint32_t)(&(fadt_mod->X_DSDT))-(uint32_t)fadt_mod+8<=fadt_mod->Length)␊ |
415 | ␉␉fadt_mod->X_DSDT=(uint32_t)new_dsdt;␊ |
416 | ␊ |
417 | ␉DBG("New @%x,%x\n",fadt_mod->DSDT,fadt_mod->X_DSDT);␊ |
418 | ␊ |
419 | ␉// Correct the checksum␊ |
420 | ␉fadt_mod->Checksum=0;␊ |
421 | ␉fadt_mod->Checksum=256-checksum8(fadt_mod,fadt_mod->Length);␊ |
422 | ␊ |
423 | ␉return fadt_mod;␊ |
424 | }␊ |
425 | ␊ |
426 | /* Setup ACPI without replacing DSDT. */␊ |
427 | int setupAcpiNoMod()␊ |
428 | {␊ |
429 | //␉addConfigurationTable(&gEfiAcpiTableGuid, getAddressOfAcpiTable(), "ACPI");␊ |
430 | //␉addConfigurationTable(&gEfiAcpi20TableGuid, getAddressOfAcpi20Table(), "ACPI_20");␊ |
431 | ␉/* XXX aserebln why uint32 cast if pointer is uint64 ? */␊ |
432 | ␉acpi10_p = (uint32_t)getAddressOfAcpiTable();␊ |
433 | ␉acpi20_p = (uint32_t)getAddressOfAcpi20Table();␊ |
434 | ␉addConfigurationTable(&gEfiAcpiTableGuid, &acpi10_p, "ACPI");␊ |
435 | ␉if(acpi20_p) addConfigurationTable(&gEfiAcpi20TableGuid, &acpi20_p, "ACPI_20");␊ |
436 | ␉return 1;␊ |
437 | }␊ |
438 | ␊ |
439 | /* Setup ACPI. Replace DSDT if DSDT.aml is found */␊ |
440 | int setupAcpi(void)␊ |
441 | {␊ |
442 | ␉int version;␊ |
443 | ␉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_ssdts[30];␊ |
444 | ␊ |
445 | <<<<<<< .mine␊ |
446 | ␉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;␊ |
447 | ␉bool drop_ssdt=false, drop_hpet=false, drop_slic=false, drop_sbst=false, drop_ecdt=false, drop_asft=false, drop_dmar=false;␊ |
448 | ␉bool update_acpi=false, gen_xsdt=false;␊ |
449 | ␉bool hpet_replaced=false, sbst_replaced=false, ecdt_replaced=false, asft_replaced=false, dmar_replaced=false, apic_replaced=false, mcfg_replaced=false;␊ |
450 | ␉bool hpet_added=false, sbst_added=false, ecdt_added=false, asft_added=false, dmar_added=false, apic_added=false, mcfg_added=false;␊ |
451 | ␊ |
452 | ␉int curssdt=0, loadtotssdt=0, totssdt=0, newtotssdt=0;␊ |
453 | ␊ |
454 | =======␊ |
455 | ␉bool drop_ssdt;␊ |
456 | ␉␊ |
457 | ␉// Load replacement DSDT␊ |
458 | ␉new_dsdt=loadACPITable("DSDT.aml");␊ |
459 | ␉if (!new_dsdt)␊ |
460 | >>>>>>> .r60␊ |
461 | ␉{␊ |
462 | ␉␉bool tmpval;␊ |
463 | ␊ |
464 | ␉␉drop_ssdt=getBoolForKey(kDropSSDT, &tmpval, &bootInfo->bootConfig)&&tmpval;␊ |
465 | ␉␉drop_hpet=getBoolForKey(kDropHPET, &tmpval, &bootInfo->bootConfig)&&tmpval;␊ |
466 | ␉␉drop_slic=getBoolForKey(kDropSLIC, &tmpval, &bootInfo->bootConfig)&&tmpval;␊ |
467 | ␉␉drop_sbst=getBoolForKey(kDropSBST, &tmpval, &bootInfo->bootConfig)&&tmpval;␊ |
468 | ␉␉drop_ecdt=getBoolForKey(kDropECDT, &tmpval, &bootInfo->bootConfig)&&tmpval;␊ |
469 | ␉␉drop_asft=getBoolForKey(kDropASFT, &tmpval, &bootInfo->bootConfig)&&tmpval;␊ |
470 | ␉␉drop_dmar=getBoolForKey(kDropDMAR, &tmpval, &bootInfo->bootConfig)&&tmpval;␊ |
471 | ␊ |
472 | ␉␉oem_dsdt=getBoolForKey(kOEMDSDT, &tmpval, &bootInfo->bootConfig)&&tmpval;␊ |
473 | ␉␉oem_ssdt=getBoolForKey(kOEMSSDT, &tmpval, &bootInfo->bootConfig)&&tmpval;␊ |
474 | ␉␉oem_hpet=getBoolForKey(kOEMHPET, &tmpval, &bootInfo->bootConfig)&&tmpval;␊ |
475 | ␉␉oem_sbst=getBoolForKey(kOEMSBST, &tmpval, &bootInfo->bootConfig)&&tmpval;␊ |
476 | ␉␉oem_ecdt=getBoolForKey(kOEMECDT, &tmpval, &bootInfo->bootConfig)&&tmpval;␊ |
477 | ␉␉oem_asft=getBoolForKey(kOEMASFT, &tmpval, &bootInfo->bootConfig)&&tmpval;␊ |
478 | ␉␉oem_dmar=getBoolForKey(kOEMDMAR, &tmpval, &bootInfo->bootConfig)&&tmpval;␊ |
479 | ␉␉oem_apic=getBoolForKey(kOEMAPIC, &tmpval, &bootInfo->bootConfig)&&tmpval;␊ |
480 | ␉␉oem_mcfg=getBoolForKey(kOEMMCFG, &tmpval, &bootInfo->bootConfig)&&tmpval;␊ |
481 | ␊ |
482 | ␉␉update_acpi=getBoolForKey(kUpdateACPI, &tmpval, &bootInfo->bootConfig)&&tmpval;␊ |
483 | ␉}␊ |
484 | ␊ |
485 | ␉// Load replacement ACPI tables␊ |
486 | ␉if (!oem_dsdt)␊ |
487 | ␉␉new_dsdt=loadACPITable(kDSDT);␊ |
488 | ␊ |
489 | ␉if (!oem_hpet)␊ |
490 | ␉␉new_hpet=loadACPITable(kHPET);␊ |
491 | ␊ |
492 | ␉if (!oem_sbst)␊ |
493 | ␉␉new_sbst=loadACPITable(kSBST);␊ |
494 | ␊ |
495 | ␉if (!oem_ecdt)␊ |
496 | ␉␉new_ecdt=loadACPITable(kECDT);␊ |
497 | ␊ |
498 | ␉if (!oem_asft)␊ |
499 | ␉␉new_asft=loadACPITable(kASFT);␊ |
500 | ␊ |
501 | ␉if (!oem_dmar)␊ |
502 | ␉␉new_dmar=loadACPITable(kDMAR);␊ |
503 | ␊ |
504 | ␉if (!oem_apic)␊ |
505 | ␉␉new_apic=loadACPITable(kAPIC);␊ |
506 | ␊ |
507 | ␉if (!oem_mcfg)␊ |
508 | ␉␉new_mcfg=loadACPITable(kMCFG);␊ |
509 | ␊ |
510 | ␉if (!oem_ssdt)␊ |
511 | ␉{␊ |
512 | ␉␉for (curssdt=0;curssdt<30;curssdt++)␊ |
513 | ␉␉{␊ |
514 | ␉␉␉new_ssdts[curssdt]=loadSSDTTable(curssdt);␊ |
515 | ␉␉␉if (new_ssdts[curssdt])␊ |
516 | ␉␉␉␉loadtotssdt++;␊ |
517 | ␉␉}␊ |
518 | ␉␉curssdt=0;␊ |
519 | ␉}␊ |
520 | ␊ |
521 | ␉if (!new_dsdt)␊ |
522 | ␉␉return setupAcpiNoMod();␊ |
523 | ␊ |
524 | ␉DBG("New ACPI tables Loaded in memory\n");␊ |
525 | ␉␉␉␊ |
526 | ␉// Do the same procedure for both versions of ACPI␊ |
527 | ␉for (version=0; version<2; version++) {␊ |
528 | ␉␉struct acpi_2_rsdp *rsdp, *rsdp_mod, *rsdp_conv=(struct acpi_2_rsdp *)0;␊ |
529 | ␉␉struct acpi_2_rsdt *rsdt, *rsdt_mod;␊ |
530 | ␉␉struct acpi_2_xsdt *xsdt_conv = (struct acpi_2_xsdt *)0;␊ |
531 | ␉␉int rsdplength;␊ |
532 | ␊ |
533 | ␉␉// Find original rsdp␊ |
534 | ␉␉rsdp=(struct acpi_2_rsdp *)(version?getAddressOfAcpi20Table():getAddressOfAcpiTable());␊ |
535 | ␉␉if ((update_acpi) && (rsdp->Revision == 0))␊ |
536 | ␉␉{␊ |
537 | ␉␉␉rsdp_conv = (struct acpi_2_rsdp *)AllocateKernelMemory(sizeof(struct acpi_2_rsdp));␊ |
538 | ␉␉␉memcpy(rsdp_conv, rsdp, 20);␊ |
539 | ␊ |
540 | ␉␉␉/* Add/change fields */␊ |
541 | ␉␉␉rsdp_conv->Revision = 2; /* ACPI version 3 */␊ |
542 | ␉␉␉rsdp_conv->Length = sizeof(struct acpi_2_rsdp);␊ |
543 | ␊ |
544 | ␉␉␉/* Correct checksums */␊ |
545 | ␉␉␉rsdp_conv->Checksum = 0;␊ |
546 | ␉␉␉rsdp_conv->Checksum = 256-checksum8(rsdp_conv, 20);␊ |
547 | ␉␉␉rsdp_conv->ExtendedChecksum = 0;␊ |
548 | ␉␉␉rsdp_conv->ExtendedChecksum = 256-checksum8(rsdp_conv, rsdp_conv->Length);␊ |
549 | ␊ |
550 | ␉␉␉rsdp = rsdp_conv;␊ |
551 | ␊ |
552 | ␉␉␉gen_xsdt = true;␊ |
553 | ␉␉␉version = 1;␊ |
554 | ␊ |
555 | ␉␉␉addConfigurationTable(&gEfiAcpiTableGuid, NULL, "ACPI");␊ |
556 | ␊ |
557 | ␉␉␉verbose("Converted ACPI RSD PTR version 1 to version 3\n");␊ |
558 | ␉␉}␊ |
559 | ␉␉if (!rsdp)␊ |
560 | ␉␉{␊ |
561 | ␉␉␉DBG("No ACPI version %d found. Ignoring\n", version+1);␊ |
562 | ␉␉␉if (version)␊ |
563 | ␉␉␉␉addConfigurationTable(&gEfiAcpi20TableGuid, NULL, "ACPI_20");␊ |
564 | ␉␉␉else␊ |
565 | ␉␉␉␉addConfigurationTable(&gEfiAcpiTableGuid, NULL, "ACPI");␊ |
566 | ␉␉␉continue;␊ |
567 | ␉␉}␊ |
568 | ␉␉rsdplength=version?rsdp->Length:20;␊ |
569 | ␊ |
570 | ␉␉DBG("RSDP version %d found @%x. Length=%d\n",version+1,rsdp,rsdplength);␊ |
571 | ␊ |
572 | ␉␉/* FIXME: no check that memory allocation succeeded ␊ |
573 | ␉␉ * Copy and patch RSDP,RSDT, XSDT and FADT␊ |
574 | ␉␉ * For more info see ACPI Specification pages 110 and following␊ |
575 | ␉␉ */␊ |
576 | ␊ |
577 | ␉␉if (gen_xsdt)␊ |
578 | ␉␉{␊ |
579 | ␉␉␉rsdp_mod=rsdp_conv;␊ |
580 | ␉␉} else {␊ |
581 | ␉␉␉rsdp_mod=(struct acpi_2_rsdp *) AllocateKernelMemory(rsdplength);␊ |
582 | ␉␉␉memcpy(rsdp_mod, rsdp, rsdplength);␊ |
583 | ␉␉}␊ |
584 | ␊ |
585 | ␉␉rsdt=(struct acpi_2_rsdt *)(rsdp->RsdtAddress);␊ |
586 | ␊ |
587 | ␉␉DBG("RSDT @%x, Length %d\n",rsdt, rsdt->Length);␊ |
588 | ␉␉␊ |
589 | ␉␉if (rsdt && (uint32_t)rsdt !=0xffffffff && rsdt->Length<0x10000)␊ |
590 | ␉␉{␊ |
591 | ␉␉␉uint32_t *rsdt_entries;␊ |
592 | ␉␉␉int rsdt_entries_num;␊ |
593 | ␉␉␉int dropoffset=0, i;␊ |
594 | ␉␉␉␊ |
595 | ␉␉␉rsdt_mod=(struct acpi_2_rsdt *)AllocateKernelMemory(rsdt->Length); ␊ |
596 | ␉␉␉memcpy (rsdt_mod, rsdt, rsdt->Length);␊ |
597 | ␉␉␉rsdp_mod->RsdtAddress=(uint32_t)rsdt_mod;␊ |
598 | ␉␉␉rsdt_entries_num=(rsdt_mod->Length-sizeof(struct acpi_2_rsdt))/4;␊ |
599 | ␉␉␉rsdt_entries=(uint32_t *)(rsdt_mod+1);␊ |
600 | ␊ |
601 | ␉␉␉if (gen_xsdt)␊ |
602 | ␉␉␉{␊ |
603 | ␉␉␉␉uint64_t *xsdt_conv_entries;␊ |
604 | ␊ |
605 | ␉␉␉␉xsdt_conv=(struct acpi_2_xsdt *)AllocateKernelMemory(sizeof(struct acpi_2_xsdt)+(rsdt_entries_num * 8));␊ |
606 | ␉␉␉␉memcpy(xsdt_conv, rsdt, sizeof(struct acpi_2_rsdt));␊ |
607 | ␊ |
608 | ␉␉␉␉xsdt_conv->Signature[0] = 'X';␊ |
609 | ␉␉␉␉xsdt_conv->Signature[1] = 'S';␊ |
610 | ␉␉␉␉xsdt_conv->Signature[2] = 'D';␊ |
611 | ␉␉␉␉xsdt_conv->Signature[3] = 'T';␊ |
612 | ␉␉␉␉xsdt_conv->Length = sizeof(struct acpi_2_xsdt)+(rsdt_entries_num * 8);␊ |
613 | ␊ |
614 | ␉␉␉␉xsdt_conv_entries=(uint64_t *)(xsdt_conv+1);␊ |
615 | ␊ |
616 | ␉␉␉␉for (i=0;i<rsdt_entries_num;i++)␊ |
617 | ␉␉␉␉{␊ |
618 | ␉␉␉␉␉xsdt_conv_entries[i] = (uint64_t)rsdt_entries[i];␊ |
619 | ␉␉␉␉}␊ |
620 | ␊ |
621 | ␉␉␉␉xsdt_conv->Checksum = 0;␊ |
622 | ␉␉␉␉xsdt_conv->Checksum = 256-checksum8(xsdt_conv, xsdt_conv->Length);␊ |
623 | ␊ |
624 | ␉␉␉␉rsdp->XsdtAddress = (uint32_t)xsdt_conv;␊ |
625 | ␊ |
626 | ␉␉␉␉rsdp->ExtendedChecksum = 0;␊ |
627 | ␉␉␉␉rsdp->ExtendedChecksum = 256-checksum8(rsdp, rsdp->Length);␊ |
628 | ␊ |
629 | ␉␉␉␉verbose("Converted RSDT table to XSDT table\n");␊ |
630 | ␉␉␉}␊ |
631 | ␊ |
632 | ␉␉␉for (i=0;i<rsdt_entries_num;i++)␊ |
633 | ␉␉␉{␊ |
634 | ␉␉␉␉char *table=(char *)(rsdt_entries[i]);␊ |
635 | ␉␉␉␉if (!table)␊ |
636 | ␉␉␉␉␉continue;␊ |
637 | ␊ |
638 | ␉␉␉␉DBG("TABLE %c%c%c%c,",table[0],table[1],table[2],table[3]);␊ |
639 | ␊ |
640 | ␉␉␉␉rsdt_entries[i-dropoffset]=rsdt_entries[i];␊ |
641 | ␉␉␉␉if (drop_ssdt && table[0]=='S' && table[1]=='S' && table[2]=='D' && table[3]=='T')␊ |
642 | ␉␉␉␉{␊ |
643 | ␉␉␉␉␉dropoffset++;␊ |
644 | ␉␉␉␉␉continue;␊ |
645 | ␉␉␉␉}␊ |
646 | ␉␉␉␉if (drop_hpet && table[0]=='H' && table[1]=='P' && table[2]=='E' && table[3]=='T')␊ |
647 | ␉␉␉␉{␊ |
648 | ␉␉␉␉␉dropoffset++;␊ |
649 | ␉␉␉␉␉continue;␊ |
650 | ␉␉␉␉}␉␉␉␊ |
651 | ␉␉␉␉if (drop_slic && table[0]=='S' && table[1]=='L' && table[2]=='I' && table[3]=='C')␊ |
652 | ␉␉␉␉{␊ |
653 | ␉␉␉␉␉dropoffset++;␊ |
654 | ␉␉␉␉␉continue;␊ |
655 | ␉␉␉␉}␊ |
656 | ␉␉␉␉if (drop_sbst && table[0]=='S' && table[1]=='B' && table[2]=='S' && table[3]=='T')␊ |
657 | ␉␉␉␉{␊ |
658 | ␉␉␉␉␉dropoffset++;␊ |
659 | ␉␉␉␉␉continue;␊ |
660 | ␉␉␉␉}␊ |
661 | ␉␉␉␉if (drop_ecdt && table[0]=='E' && table[1]=='C' && table[2]=='D' && table[3]=='T')␊ |
662 | ␉␉␉␉{␊ |
663 | ␉␉␉␉␉dropoffset++;␊ |
664 | ␉␉␉␉␉continue;␊ |
665 | ␉␉␉␉}␊ |
666 | ␉␉␉␉if (drop_asft && table[0]=='A' && table[1]=='S' && table[2]=='F' && table[3]=='!')␊ |
667 | ␉␉␉␉{␊ |
668 | ␉␉␉␉␉dropoffset++;␊ |
669 | ␉␉␉␉␉continue;␊ |
670 | ␉␉␉␉}␊ |
671 | ␉␉␉␉if (drop_dmar && table[0]=='D' && table[1]=='M' && table[2]=='A' && table[3]=='R')␊ |
672 | ␉␉␉␉{␊ |
673 | ␉␉␉␉␉dropoffset++;␊ |
674 | ␉␉␉␉␉continue;␊ |
675 | ␉␉␉␉}␊ |
676 | ␉␉␉␉if ((!(oem_hpet)) && table[0]=='H' && table[1]=='P' && table[2]=='E' && table[3]=='T')␊ |
677 | ␉␉␉␉{␊ |
678 | ␉␉␉␉␉DBG("HPET found\n");␊ |
679 | ␉␉␉␉␉if (new_hpet)␊ |
680 | ␉␉␉␉␉{␊ |
681 | ␉␉␉␉␉␉rsdt_entries[i-dropoffset]=(uint32_t)new_hpet;␊ |
682 | ␉␉␉␉␉␉hpet_replaced=true;␊ |
683 | ␉␉␉␉␉}␊ |
684 | ␉␉␉␉␉continue;␊ |
685 | ␉␉␉␉}␊ |
686 | ␉␉␉␉if ((!(oem_sbst)) && table[0]=='S' && table[1]=='B' && table[2]=='S' && table[3]=='T')␊ |
687 | ␉␉␉␉{␊ |
688 | ␉␉␉␉␉DBG("SBST found\n");␊ |
689 | ␉␉␉␉␉if (new_sbst)␊ |
690 | ␉␉␉␉␉{␊ |
691 | ␉␉␉␉␉␉rsdt_entries[i-dropoffset]=(uint32_t)new_sbst;␊ |
692 | ␉␉␉␉␉␉sbst_replaced=true;␊ |
693 | ␉␉␉␉␉}␊ |
694 | ␉␉␉␉␉continue;␊ |
695 | ␉␉␉␉}␊ |
696 | ␉␉␉␉if ((!(oem_ecdt)) && table[0]=='E' && table[1]=='C' && table[2]=='D' && table[3]=='T')␊ |
697 | ␉␉␉␉{␊ |
698 | ␉␉␉␉␉DBG("ECDT found\n");␊ |
699 | ␉␉␉␉␉if (new_ecdt)␊ |
700 | ␉␉␉␉␉{␊ |
701 | ␉␉␉␉␉␉rsdt_entries[i-dropoffset]=(uint32_t)new_ecdt;␊ |
702 | ␉␉␉␉␉␉ecdt_replaced=true;␊ |
703 | ␉␉␉␉␉}␊ |
704 | ␉␉␉␉␉continue;␊ |
705 | ␉␉␉␉}␊ |
706 | ␉␉␉␉if ((!(oem_asft)) && table[0]=='A' && table[1]=='S' && table[2]=='F' && table[3]=='!')␊ |
707 | ␉␉␉␉{␊ |
708 | ␉␉␉␉␉DBG("ASF! found\n");␊ |
709 | ␉␉␉␉␉if (new_asft)␊ |
710 | ␉␉␉␉␉{␊ |
711 | ␉␉␉␉␉␉rsdt_entries[i-dropoffset]=(uint32_t)new_asft;␊ |
712 | ␉␉␉␉␉␉asft_replaced=true;␊ |
713 | ␉␉␉␉␉}␊ |
714 | ␉␉␉␉␉continue;␊ |
715 | ␉␉␉␉}␊ |
716 | ␉␉␉␉if ((!(oem_dmar)) && table[0]=='D' && table[1]=='M' && table[2]=='A' && table[3]=='R')␊ |
717 | ␉␉␉␉{␊ |
718 | ␉␉␉␉␉DBG("DMAR found\n");␊ |
719 | ␉␉␉␉␉if (new_dmar)␊ |
720 | ␉␉␉␉␉{␊ |
721 | ␉␉␉␉␉␉rsdt_entries[i-dropoffset]=(uint32_t)new_dmar;␊ |
722 | ␉␉␉␉␉␉dmar_replaced=true;␊ |
723 | ␉␉␉␉␉}␊ |
724 | ␉␉␉␉␉continue;␊ |
725 | ␉␉␉␉}␊ |
726 | ␉␉␉␉if ((!(oem_apic)) && table[0]=='A' && table[1]=='P' && table[2]=='I' && table[3]=='C')␊ |
727 | ␉␉␉␉{␊ |
728 | ␉␉␉␉␉DBG("APIC found\n");␊ |
729 | ␉␉␉␉␉if (new_apic)␊ |
730 | ␉␉␉␉␉{␊ |
731 | ␉␉␉␉␉␉rsdt_entries[i-dropoffset]=(uint32_t)new_apic;␊ |
732 | ␉␉␉␉␉␉apic_replaced=true;␊ |
733 | ␉␉␉␉␉}␊ |
734 | ␉␉␉␉␉continue;␊ |
735 | ␉␉␉␉}␊ |
736 | ␉␉␉␉if ((!(oem_mcfg)) && table[0]=='M' && table[1]=='C' && table[2]=='F' && table[3]=='G')␊ |
737 | ␉␉␉␉{␊ |
738 | ␉␉␉␉␉DBG("MCFG found\n");␊ |
739 | ␉␉␉␉␉if (new_mcfg)␊ |
740 | ␉␉␉␉␉{␊ |
741 | ␉␉␉␉␉␉rsdt_entries[i-dropoffset]=(uint32_t)new_mcfg;␊ |
742 | ␉␉␉␉␉␉mcfg_replaced=true;␊ |
743 | ␉␉␉␉␉}␊ |
744 | ␉␉␉␉␉continue;␊ |
745 | ␉␉␉␉}␊ |
746 | ␉␉␉␉if ((!(oem_ssdt)) && table[0]=='S' && table[1]=='S' && table[2]=='D' && table[3]=='T')␊ |
747 | ␉␉␉␉{␊ |
748 | ␉␉␉␉␉DBG("SSDT %d found", curssdt);␊ |
749 | ␉␉␉␉␉if (new_ssdts[curssdt])␊ |
750 | ␉␉␉␉␉{␊ |
751 | ␉␉␉␉␉␉DBG(" and replaced");␊ |
752 | ␉␉␉␉␉␉rsdt_entries[i-dropoffset]=(uint32_t)new_ssdts[curssdt];␊ |
753 | ␉␉␉␉␉␉totssdt++;␊ |
754 | ␉␉␉␉␉}␊ |
755 | ␉␉␉␉␉DBG("\n");␊ |
756 | ␉␉␉␉␉curssdt++;␊ |
757 | ␉␉␉␉␉continue;␊ |
758 | ␉␉␉␉}␊ |
759 | ␉␉␉␉if (table[0]=='D' && table[1]=='S' && table[2]=='D' && table[3]=='T')␊ |
760 | ␉␉␉␉{␊ |
761 | ␉␉␉␉␉DBG("DSDT found\n");␊ |
762 | ␉␉␉␉␉rsdt_entries[i-dropoffset]=(uint32_t)new_dsdt;␊ |
763 | ␉␉␉␉␉continue;␊ |
764 | ␉␉␉␉}␊ |
765 | ␉␉␉␉if (table[0]=='F' && table[1]=='A' && table[2]=='C' && table[3]=='P')␊ |
766 | ␉␉␉␉{␊ |
767 | ␉␉␉␉␉struct acpi_2_fadt *fadt, *fadt_mod;␊ |
768 | ␉␉␉␉␉fadt=(struct acpi_2_fadt *)rsdt_entries[i];␊ |
769 | ␊ |
770 | ␉␉␉␉␉DBG("FADT found @%x, Length %d\n",fadt, fadt->Length);␊ |
771 | ␊ |
772 | ␉␉␉␉␉if (!fadt || (uint32_t)fadt == 0xffffffff || fadt->Length>0x10000)␊ |
773 | ␉␉␉␉␉{␊ |
774 | ␉␉␉␉␉␉printf("FADT incorrect. Not modified\n");␊ |
775 | ␉␉␉␉␉␉continue;␊ |
776 | ␉␉␉␉␉}␊ |
777 | ␉␉␉␉␉␊ |
778 | ␉␉␉␉␉fadt_mod = patch_fadt(fadt, new_dsdt, update_acpi);␊ |
779 | ␉␉␉␉␉rsdt_entries[i-dropoffset]=(uint32_t)fadt_mod;␊ |
780 | ␉␉␉␉␉continue;␊ |
781 | ␉␉␉␉}␊ |
782 | ␉␉␉}␊ |
783 | ␉␉␉DBG("\n");␊ |
784 | ␊ |
785 | ␉␉␉if ((!oem_hpet) && (!hpet_replaced))␊ |
786 | ␉␉␉{␊ |
787 | ␉␉␉␉if (new_hpet)␊ |
788 | ␉␉␉␉{␊ |
789 | ␉␉␉␉␉rsdt_entries[i-dropoffset]=(uint32_t)new_hpet;␊ |
790 | ␉␉␉␉␉hpet_added=true;␊ |
791 | ␉␉␉␉␉i++;␊ |
792 | ␉␉␉␉}␊ |
793 | ␉␉␉}␊ |
794 | ␊ |
795 | ␉␉␉if ((!oem_sbst) && (!sbst_replaced))␊ |
796 | ␉␉␉{␊ |
797 | ␉␉␉␉if (new_sbst)␊ |
798 | ␉␉␉␉{␊ |
799 | ␉␉␉␉␉rsdt_entries[i-dropoffset]=(uint32_t)new_sbst;␊ |
800 | ␉␉␉␉␉sbst_added=true;␊ |
801 | ␉␉␉␉␉i++;␊ |
802 | ␉␉␉␉}␊ |
803 | ␉␉␉}␊ |
804 | ␊ |
805 | ␉␉␉if ((!oem_ecdt) && (!ecdt_replaced))␊ |
806 | ␉␉␉{␊ |
807 | ␉␉␉␉if (new_ecdt)␊ |
808 | ␉␉␉␉{␊ |
809 | ␉␉␉␉␉rsdt_entries[i-dropoffset]=(uint32_t)new_ecdt;␊ |
810 | ␉␉␉␉␉ecdt_added=true;␊ |
811 | ␉␉␉␉␉i++;␊ |
812 | ␉␉␉␉}␊ |
813 | ␉␉␉}␊ |
814 | ␊ |
815 | ␉␉␉if ((!oem_asft) && (!asft_replaced))␊ |
816 | ␉␉␉{␊ |
817 | ␉␉␉␉if (new_asft)␊ |
818 | ␉␉␉␉{␊ |
819 | ␉␉␉␉␉rsdt_entries[i-dropoffset]=(uint32_t)new_asft;␊ |
820 | ␉␉␉␉␉asft_added=true;␊ |
821 | ␉␉␉␉␉i++;␊ |
822 | ␉␉␉␉}␊ |
823 | ␉␉␉}␊ |
824 | ␊ |
825 | ␉␉␉if ((!oem_dmar) && (!dmar_replaced))␊ |
826 | ␉␉␉{␊ |
827 | ␉␉␉␉if (new_dmar)␊ |
828 | ␉␉␉␉{␊ |
829 | ␉␉␉␉␉rsdt_entries[i-dropoffset]=(uint32_t)new_dmar;␊ |
830 | ␉␉␉␉␉dmar_added=true;␊ |
831 | ␉␉␉␉␉i++;␊ |
832 | ␉␉␉␉}␊ |
833 | ␉␉␉}␊ |
834 | ␊ |
835 | ␉␉␉if ((!oem_apic) && (!apic_replaced))␊ |
836 | ␉␉␉{␊ |
837 | ␉␉␉␉if (new_apic)␊ |
838 | ␉␉␉␉{␊ |
839 | ␉␉␉␉␉rsdt_entries[i-dropoffset]=(uint32_t)new_apic;␊ |
840 | ␉␉␉␉␉apic_added=true;␊ |
841 | ␉␉␉␉␉i++;␊ |
842 | ␉␉␉␉}␊ |
843 | ␉␉␉}␊ |
844 | ␊ |
845 | ␉␉␉if ((!oem_mcfg) && (!mcfg_replaced))␊ |
846 | ␉␉␉{␊ |
847 | ␉␉␉␉if (new_mcfg)␊ |
848 | ␉␉␉␉{␊ |
849 | ␉␉␉␉␉rsdt_entries[i-dropoffset]=(uint32_t)new_mcfg;␊ |
850 | ␉␉␉␉␉mcfg_added=true;␊ |
851 | ␉␉␉␉␉i++;␊ |
852 | ␉␉␉␉}␊ |
853 | ␉␉␉}␊ |
854 | ␉␉␉␊ |
855 | ␉␉␉if (!oem_ssdt)␊ |
856 | ␉␉␉{ ␉␉␉␊ |
857 | ␉␉␉␉while ((totssdt < loadtotssdt) && (curssdt < 30))␊ |
858 | ␉␉␉␉{␊ |
859 | ␉␉␉␉␉if (new_ssdts[curssdt])␊ |
860 | ␉␉␉␉␉{␊ |
861 | ␉␉␉␉␉␉DBG("adding SSDT %d\n", curssdt);␊ |
862 | ␉␉␉␉␉␉rsdt_entries[i-dropoffset]=(uint32_t)new_ssdts[curssdt];␊ |
863 | ␉␉␉␉␉␉totssdt++;␊ |
864 | ␉␉␉␉␉␉newtotssdt++;␊ |
865 | ␉␉␉␉␉␉i++;␊ |
866 | ␉␉␉␉␉}␊ |
867 | ␉␉␉␉␉curssdt++;␊ |
868 | ␉␉␉␉}␊ |
869 | ␉␉␉}␊ |
870 | ␊ |
871 | ␉␉␉// Correct the checksum of RSDT␊ |
872 | ␉␉␉rsdt_mod->Length-=4*dropoffset;␊ |
873 | ␉␉␉rsdt_mod->Length+=4*newtotssdt;␊ |
874 | ␉␉␉if (hpet_added)␊ |
875 | ␉␉␉␉rsdt_mod->Length+=4;␊ |
876 | ␉␉␉if (sbst_added)␊ |
877 | ␉␉␉␉rsdt_mod->Length+=4;␊ |
878 | ␉␉␉if (ecdt_added)␊ |
879 | ␉␉␉␉rsdt_mod->Length+=4;␊ |
880 | ␉␉␉if (asft_added)␊ |
881 | ␉␉␉␉rsdt_mod->Length+=4;␊ |
882 | ␉␉␉if (dmar_added)␊ |
883 | ␉␉␉␉rsdt_mod->Length+=4;␊ |
884 | ␉␉␉if (apic_added)␊ |
885 | ␉␉␉␉rsdt_mod->Length+=4;␊ |
886 | ␉␉␉if (mcfg_added)␊ |
887 | ␉␉␉␉rsdt_mod->Length+=4;␊ |
888 | ␊ |
889 | ␉␉␉DBG("RSDT: Original checksum %d, ", rsdt_mod->Checksum);␊ |
890 | ␊ |
891 | ␉␉␉rsdt_mod->Checksum=0;␊ |
892 | ␉␉␉rsdt_mod->Checksum=256-checksum8(rsdt_mod,rsdt_mod->Length);␊ |
893 | ␊ |
894 | ␉␉␉DBG("New checksum %d at %x\n", rsdt_mod->Checksum,rsdt_mod);␊ |
895 | ␉␉}␊ |
896 | ␉␉else␊ |
897 | ␉␉{␊ |
898 | ␉␉␉rsdp_mod->RsdtAddress=0;␊ |
899 | ␉␉␉printf("RSDT not found or RSDT incorrect\n");␊ |
900 | ␉␉}␊ |
901 | ␊ |
902 | ␉␉if (version)␊ |
903 | ␉␉{␊ |
904 | ␉␉␉struct acpi_2_xsdt *xsdt, *xsdt_mod;␊ |
905 | ␊ |
906 | ␉␉␉// FIXME: handle 64-bit address correctly␊ |
907 | ␊ |
908 | ␉␉␉if (gen_xsdt)␊ |
909 | ␉␉␉␉xsdt=xsdt_conv;␊ |
910 | ␉␉␉else␊ |
911 | ␉␉␉␉xsdt=(struct acpi_2_xsdt*) ((uint32_t)rsdp->XsdtAddress);␊ |
912 | ␊ |
913 | ␉␉␉DBG("XSDT @%x;%x, Length=%d\n", (uint32_t)(rsdp->XsdtAddress>>32),(uint32_t)rsdp->XsdtAddress,␊ |
914 | ␉␉␉␉␉xsdt->Length);␊ |
915 | ␉␉␉if (xsdt && (uint64_t)rsdp->XsdtAddress<0xffffffff && xsdt->Length<0x10000)␊ |
916 | ␉␉␉{␊ |
917 | ␉␉␉␉uint64_t *xsdt_entries;␊ |
918 | ␉␉␉␉int xsdt_entries_num, i;␊ |
919 | ␉␉␉␉int dropoffset=0;␊ |
920 | ␉␉␉␉curssdt=0, totssdt=0, newtotssdt=0;␊ |
921 | ␉␉␉␉hpet_replaced=false, hpet_added=false;␊ |
922 | ␉␉␉␉sbst_replaced=false, sbst_added=false;␊ |
923 | ␉␉␉␉ecdt_replaced=false, ecdt_added=false;␊ |
924 | ␉␉␉␉asft_replaced=false, asft_added=false;␊ |
925 | ␉␉␉␉dmar_replaced=false, dmar_added=false;␊ |
926 | ␉␉␉␉apic_replaced=false, apic_added=false;␊ |
927 | ␉␉␉␉mcfg_replaced=false, mcfg_added=false;␊ |
928 | ␊ |
929 | ␉␉␉␉if (gen_xsdt)␊ |
930 | ␉␉␉␉␉xsdt_mod=xsdt;␊ |
931 | ␉␉␉␉else␊ |
932 | ␉␉␉␉{␊ |
933 | ␉␉␉␉␉xsdt_mod=(struct acpi_2_xsdt*)AllocateKernelMemory(xsdt->Length); ␊ |
934 | ␉␉␉␉␉memcpy(xsdt_mod, xsdt, xsdt->Length);␊ |
935 | ␉␉␉␉}␊ |
936 | ␊ |
937 | ␉␉␉␉rsdp_mod->XsdtAddress=(uint32_t)xsdt_mod;␊ |
938 | ␉␉␉␉xsdt_entries_num=(xsdt_mod->Length-sizeof(struct acpi_2_xsdt))/8;␊ |
939 | ␉␉␉␉xsdt_entries=(uint64_t *)(xsdt_mod+1);␊ |
940 | ␉␉␉␉for (i=0;i<xsdt_entries_num;i++)␊ |
941 | ␉␉␉␉{␊ |
942 | ␉␉␉␉␉char *table=(char *)((uint32_t)(xsdt_entries[i]));␊ |
943 | ␉␉␉␉␉if (!table)␊ |
944 | ␉␉␉␉␉␉continue;␊ |
945 | ␉␉␉␉␉xsdt_entries[i-dropoffset]=xsdt_entries[i];␊ |
946 | ␉␉␉␉␉if (drop_ssdt && table[0]=='S' && table[1]=='S' && table[2]=='D' && table[3]=='T')␊ |
947 | ␉␉␉␉␉{␊ |
948 | ␉␉␉␉␉␉dropoffset++;␊ |
949 | ␉␉␉␉␉␉continue;␊ |
950 | ␉␉␉␉␉}␉␊ |
951 | ␉␉␉␉␉if (drop_hpet && table[0]=='H' && table[1]=='P' && table[2]=='E' && table[3]=='T')␊ |
952 | ␉␉␉␉␉{␊ |
953 | ␉␉␉␉␉␉dropoffset++;␊ |
954 | ␉␉␉␉␉␉continue;␊ |
955 | ␉␉␉␉␉}␊ |
956 | ␉␉␉␉␉if (drop_slic && table[0]=='S' && table[1]=='L' && table[2]=='I' && table[3]=='C')␊ |
957 | ␉␉␉␉␉{␊ |
958 | ␉␉␉␉␉␉dropoffset++;␊ |
959 | ␉␉␉␉␉␉continue;␊ |
960 | ␉␉␉␉␉}␊ |
961 | ␉␉␉␉␉if (drop_sbst && table[0]=='S' && table[1]=='B' && table[2]=='S' && table[3]=='T')␊ |
962 | ␉␉␉␉␉{␊ |
963 | ␉␉␉␉␉␉dropoffset++;␊ |
964 | ␉␉␉␉␉␉continue;␊ |
965 | ␉␉␉␉␉}␊ |
966 | ␉␉␉␉␉if (drop_ecdt && table[0]=='E' && table[1]=='C' && table[2]=='D' && table[3]=='T')␊ |
967 | ␉␉␉␉␉{␊ |
968 | ␉␉␉␉␉␉dropoffset++;␊ |
969 | ␉␉␉␉␉␉continue;␊ |
970 | ␉␉␉␉␉}␉␉␉␉␉␊ |
971 | ␉␉␉␉␉if (drop_asft && table[0]=='A' && table[1]=='S' && table[2]=='F' && table[3]=='!')␊ |
972 | ␉␉␉␉␉{␊ |
973 | ␉␉␉␉␉␉dropoffset++;␊ |
974 | ␉␉␉␉␉␉continue;␊ |
975 | ␉␉␉␉␉}␊ |
976 | ␉␉␉␉␉if (drop_dmar && table[0]=='D' && table[1]=='M' && table[2]=='A' && table[3]=='R')␊ |
977 | ␉␉␉␉␉{␊ |
978 | ␉␉␉␉␉␉dropoffset++;␊ |
979 | ␉␉␉␉␉␉continue;␊ |
980 | ␉␉␉␉␉}␉␉␉␉␉␊ |
981 | ␉␉␉␉␉if ((!(oem_hpet)) && table[0]=='H' && table[1]=='P' && table[2]=='E' && table[3]=='T')␊ |
982 | ␉␉␉␉␉{␊ |
983 | ␉␉␉␉␉␉DBG("HPET found\n");␊ |
984 | ␉␉␉␉␉␉if (new_hpet)␊ |
985 | ␉␉␉␉␉␉{␊ |
986 | ␉␉␉␉␉␉␉xsdt_entries[i-dropoffset]=(uint32_t)new_hpet;␊ |
987 | ␉␉␉␉␉␉␉hpet_replaced=true;␊ |
988 | ␉␉␉␉␉␉}␊ |
989 | ␉␉␉␉␉␉continue;␊ |
990 | ␉␉␉␉␉}␉␉␉␉␉␊ |
991 | ␉␉␉␉␉if ((!(oem_sbst)) && table[0]=='S' && table[1]=='B' && table[2]=='S' && table[3]=='T')␊ |
992 | ␉␉␉␉␉{␊ |
993 | ␉␉␉␉␉␉DBG("SBST found\n");␊ |
994 | ␉␉␉␉␉␉if (new_sbst)␊ |
995 | ␉␉␉␉␉␉{␊ |
996 | ␉␉␉␉␉␉␉xsdt_entries[i-dropoffset]=(uint32_t)new_sbst;␊ |
997 | ␉␉␉␉␉␉␉sbst_replaced=true;␊ |
998 | ␉␉␉␉␉␉}␊ |
999 | ␉␉␉␉␉␉continue;␊ |
1000 | ␉␉␉␉␉}␉␉␉␉␉␊ |
1001 | ␉␉␉␉␉if ((!(oem_ecdt)) && table[0]=='E' && table[1]=='C' && table[2]=='D' && table[3]=='T')␊ |
1002 | ␉␉␉␉␉{␊ |
1003 | ␉␉␉␉␉␉DBG("ECDT found\n");␊ |
1004 | ␉␉␉␉␉␉if (new_ecdt)␊ |
1005 | ␉␉␉␉␉␉{␊ |
1006 | ␉␉␉␉␉␉␉xsdt_entries[i-dropoffset]=(uint32_t)new_ecdt;␊ |
1007 | ␉␉␉␉␉␉␉ecdt_replaced=true;␊ |
1008 | ␉␉␉␉␉␉}␊ |
1009 | ␉␉␉␉␉␉continue;␊ |
1010 | ␉␉␉␉␉}␉␉␉␉␉␊ |
1011 | ␉␉␉␉␉if ((!(oem_asft)) && table[0]=='A' && table[1]=='S' && table[2]=='F' && table[3]=='!')␊ |
1012 | ␉␉␉␉␉{␊ |
1013 | ␉␉␉␉␉␉DBG("ASF! found\n");␊ |
1014 | ␉␉␉␉␉␉if (new_asft)␊ |
1015 | ␉␉␉␉␉␉{␊ |
1016 | ␉␉␉␉␉␉␉xsdt_entries[i-dropoffset]=(uint32_t)new_asft;␊ |
1017 | ␉␉␉␉␉␉␉asft_replaced=true;␊ |
1018 | ␉␉␉␉␉␉}␊ |
1019 | ␉␉␉␉␉␉continue;␊ |
1020 | ␉␉␉␉␉}␉␉␉␉␉␊ |
1021 | ␉␉␉␉␉if ((!(oem_dmar)) && table[0]=='D' && table[1]=='M' && table[2]=='A' && table[3]=='R')␊ |
1022 | ␉␉␉␉␉{␊ |
1023 | ␉␉␉␉␉␉DBG("DMAR found\n");␊ |
1024 | ␉␉␉␉␉␉if (new_dmar)␊ |
1025 | ␉␉␉␉␉␉{␊ |
1026 | ␉␉␉␉␉␉␉xsdt_entries[i-dropoffset]=(uint32_t)new_dmar;␊ |
1027 | ␉␉␉␉␉␉␉dmar_replaced=true;␊ |
1028 | ␉␉␉␉␉␉}␊ |
1029 | ␉␉␉␉␉␉continue;␊ |
1030 | ␉␉␉␉␉}␉␉␉␉␉␊ |
1031 | ␉␉␉␉␉if ((!(oem_apic)) && table[0]=='A' && table[1]=='P' && table[2]=='I' && table[3]=='C')␊ |
1032 | ␉␉␉␉␉{␊ |
1033 | ␉␉␉␉␉␉DBG("APIC found\n");␊ |
1034 | ␉␉␉␉␉␉if (new_apic)␊ |
1035 | ␉␉␉␉␉␉{␊ |
1036 | ␉␉␉␉␉␉␉xsdt_entries[i-dropoffset]=(uint32_t)new_apic;␊ |
1037 | ␉␉␉␉␉␉␉apic_replaced=true;␊ |
1038 | ␉␉␉␉␉␉}␊ |
1039 | ␉␉␉␉␉␉continue;␊ |
1040 | ␉␉␉␉␉}␉␉␉␉␉␊ |
1041 | ␉␉␉␉␉if ((!(oem_mcfg)) && table[0]=='M' && table[1]=='C' && table[2]=='F' && table[3]=='G')␊ |
1042 | ␉␉␉␉␉{␊ |
1043 | ␉␉␉␉␉␉DBG("MCFG found\n");␊ |
1044 | ␉␉␉␉␉␉if (new_mcfg)␊ |
1045 | ␉␉␉␉␉␉{␊ |
1046 | ␉␉␉␉␉␉␉xsdt_entries[i-dropoffset]=(uint32_t)new_mcfg;␊ |
1047 | ␉␉␉␉␉␉␉mcfg_replaced=true;␊ |
1048 | ␉␉␉␉␉␉}␊ |
1049 | ␉␉␉␉␉␉continue;␊ |
1050 | ␉␉␉␉␉}␉␉␉␉␉␊ |
1051 | ␉␉␉␉␉if ((!(oem_ssdt)) && table[0]=='S' && table[1]=='S' && table[2]=='D' && table[3]=='T')␊ |
1052 | ␉␉␉␉␉{␊ |
1053 | ␉␉␉␉␉␉DBG("SSDT %d found", curssdt);␊ |
1054 | ␉␉␉␉␉␉if (new_ssdts[curssdt])␊ |
1055 | ␉␉␉␉␉␉{␊ |
1056 | ␉␉␉␉␉␉␉DBG(" and replaced");␊ |
1057 | ␉␉␉␉␉␉␉xsdt_entries[i-dropoffset]=(uint32_t)new_ssdts[curssdt];␊ |
1058 | ␉␉␉␉␉␉␉totssdt++;␊ |
1059 | ␉␉␉␉␉␉}␊ |
1060 | ␉␉␉␉␉␉DBG("\n");␊ |
1061 | ␉␉␉␉␉␉curssdt++;␊ |
1062 | ␉␉␉␉␉␉continue;␊ |
1063 | ␉␉␉␉␉}␉␉␉␉␉␊ |
1064 | ␉␉␉␉␉if (table[0]=='D' && table[1]=='S' && table[2]=='D' && table[3]=='T')␊ |
1065 | ␉␉␉␉␉{␊ |
1066 | ␉␉␉␉␉␉DBG("DSDT found\n");␊ |
1067 | ␊ |
1068 | ␉␉␉␉␉␉xsdt_entries[i-dropoffset]=(uint32_t)new_dsdt;␊ |
1069 | ␊ |
1070 | ␉␉␉␉␉␉DBG("TABLE %c%c%c%c@%x,",table[0],table[1],table[2],table[3],xsdt_entries[i]);␊ |
1071 | ␉␉␉␉␉␉␊ |
1072 | ␉␉␉␉␉␉continue;␊ |
1073 | ␉␉␉␉␉}␊ |
1074 | ␉␉␉␉␉if (table[0]=='F' && table[1]=='A' && table[2]=='C' && table[3]=='P')␊ |
1075 | ␉␉␉␉␉{␊ |
1076 | ␉␉␉␉␉␉struct acpi_2_fadt *fadt, *fadt_mod;␊ |
1077 | ␉␉␉␉␉␉fadt=(struct acpi_2_fadt *)(uint32_t)xsdt_entries[i];␊ |
1078 | ␊ |
1079 | ␉␉␉␉␉␉DBG("FADT found @%x,%x, Length %d\n",(uint32_t)(xsdt_entries[i]>>32),fadt, ␊ |
1080 | ␉␉␉␉␉␉␉␉ fadt->Length);␊ |
1081 | ␊ |
1082 | ␉␉␉␉␉␉if (!fadt || (uint64_t)xsdt_entries[i] >= 0xffffffff || fadt->Length>0x10000)␊ |
1083 | ␉␉␉␉␉␉{␊ |
1084 | ␉␉␉␉␉␉␉verbose("FADT incorrect or after 4GB. Dropping XSDT\n");␊ |
1085 | ␉␉␉␉␉␉␉goto drop_xsdt;␊ |
1086 | ␉␉␉␉␉␉}␊ |
1087 | ␊ |
1088 | ␉␉␉␉␉␉fadt_mod = patch_fadt(fadt, new_dsdt,update_acpi);␊ |
1089 | ␉␉␉␉␉␉xsdt_entries[i-dropoffset]=(uint32_t)fadt_mod;␊ |
1090 | ␊ |
1091 | ␉␉␉␉␉␉DBG("TABLE %c%c%c%c@%x,",table[0],table[1],table[2],table[3],xsdt_entries[i]);␊ |
1092 | ␊ |
1093 | ␉␉␉␉␉␉continue;␊ |
1094 | ␉␉␉␉␉}␊ |
1095 | ␊ |
1096 | ␉␉␉␉␉DBG("TABLE %c%c%c%c@%x,",table[0],table[1],table[2],table[3],xsdt_entries[i]);␊ |
1097 | ␊ |
1098 | ␉␉␉␉}␊ |
1099 | ␊ |
1100 | ␉␉␉␉if ((!oem_hpet) && (!hpet_replaced))␊ |
1101 | ␉␉␉␉{␊ |
1102 | ␉␉␉␉␉if (new_hpet)␊ |
1103 | ␉␉␉␉␉{␊ |
1104 | ␉␉␉␉␉␉xsdt_entries[i-dropoffset]=(uint32_t)new_hpet;␊ |
1105 | ␉␉␉␉␉␉hpet_added=true;␊ |
1106 | ␉␉␉␉␉␉i++;␊ |
1107 | ␉␉␉␉␉}␊ |
1108 | ␉␉␉␉}␊ |
1109 | ␊ |
1110 | ␉␉␉␉if ((!oem_sbst) && (!sbst_replaced))␊ |
1111 | ␉␉␉␉{␊ |
1112 | ␉␉␉␉␉if (new_sbst)␊ |
1113 | ␉␉␉␉␉{␊ |
1114 | ␉␉␉␉␉␉xsdt_entries[i-dropoffset]=(uint32_t)new_sbst;␊ |
1115 | ␉␉␉␉␉␉sbst_added=true;␊ |
1116 | ␉␉␉␉␉␉i++;␊ |
1117 | ␉␉␉␉␉}␊ |
1118 | ␉␉␉␉}␊ |
1119 | ␊ |
1120 | ␉␉␉␉if ((!oem_ecdt) && (!ecdt_replaced))␊ |
1121 | ␉␉␉␉{␊ |
1122 | ␉␉␉␉␉if (new_ecdt)␊ |
1123 | ␉␉␉␉␉{␊ |
1124 | ␉␉␉␉␉␉xsdt_entries[i-dropoffset]=(uint32_t)new_ecdt;␊ |
1125 | ␉␉␉␉␉␉ecdt_added=true;␊ |
1126 | ␉␉␉␉␉␉i++;␊ |
1127 | ␉␉␉␉␉}␊ |
1128 | ␉␉␉␉}␊ |
1129 | ␊ |
1130 | ␉␉␉␉if ((!oem_asft) && (!asft_replaced))␊ |
1131 | ␉␉␉␉{␊ |
1132 | ␉␉␉␉␉if (new_asft)␊ |
1133 | ␉␉␉␉␉{␊ |
1134 | ␉␉␉␉␉␉xsdt_entries[i-dropoffset]=(uint32_t)new_asft;␊ |
1135 | ␉␉␉␉␉␉asft_added=true;␊ |
1136 | ␉␉␉␉␉␉i++;␊ |
1137 | ␉␉␉␉␉}␊ |
1138 | ␉␉␉␉}␊ |
1139 | ␊ |
1140 | ␉␉␉␉if ((!oem_dmar) && (!dmar_replaced))␊ |
1141 | ␉␉␉␉{␊ |
1142 | ␉␉␉␉␉if (new_dmar)␊ |
1143 | ␉␉␉␉␉{␊ |
1144 | ␉␉␉␉␉␉xsdt_entries[i-dropoffset]=(uint32_t)new_dmar;␊ |
1145 | ␉␉␉␉␉␉dmar_added=true;␊ |
1146 | ␉␉␉␉␉␉i++;␊ |
1147 | ␉␉␉␉␉}␊ |
1148 | ␉␉␉␉}␊ |
1149 | ␊ |
1150 | ␉␉␉␉if ((!oem_apic) && (!apic_replaced))␊ |
1151 | ␉␉␉␉{␊ |
1152 | ␉␉␉␉␉if (new_apic)␊ |
1153 | ␉␉␉␉␉{␊ |
1154 | ␉␉␉␉␉␉xsdt_entries[i-dropoffset]=(uint32_t)new_apic;␊ |
1155 | ␉␉␉␉␉␉apic_added=true;␊ |
1156 | ␉␉␉␉␉␉i++;␊ |
1157 | ␉␉␉␉␉}␊ |
1158 | ␉␉␉␉}␊ |
1159 | ␊ |
1160 | ␉␉␉␉if ((!oem_mcfg) && (!mcfg_replaced))␊ |
1161 | ␉␉␉␉{␊ |
1162 | ␉␉␉␉␉if (new_mcfg)␊ |
1163 | ␉␉␉␉␉{␊ |
1164 | ␉␉␉␉␉␉xsdt_entries[i-dropoffset]=(uint32_t)new_mcfg;␊ |
1165 | ␉␉␉␉␉␉mcfg_added=true;␊ |
1166 | ␉␉␉␉␉␉i++;␊ |
1167 | ␉␉␉␉␉}␊ |
1168 | ␉␉␉␉}␊ |
1169 | ␊ |
1170 | ␉␉␉␉if (!oem_ssdt)␊ |
1171 | ␉␉␉␉{ ␉␉␉␊ |
1172 | ␉␉␉␉␉while ((totssdt < loadtotssdt) && (curssdt < 30))␊ |
1173 | ␉␉␉␉␉{␊ |
1174 | ␉␉␉␉␉␉if (new_ssdts[curssdt])␊ |
1175 | ␉␉␉␉␉␉{␊ |
1176 | ␉␉␉␉␉␉␉DBG("adding SSDT %d\n", curssdt);␊ |
1177 | ␉␉␉␉␉␉␉xsdt_entries[i-dropoffset]=(uint32_t)new_ssdts[curssdt];␊ |
1178 | ␉␉␉␉␉␉␉totssdt++;␊ |
1179 | ␉␉␉␉␉␉␉newtotssdt++;␊ |
1180 | ␉␉␉␉␉␉␉i++;␊ |
1181 | ␉␉␉␉␉␉}␊ |
1182 | ␉␉␉␉␉␉curssdt++;␊ |
1183 | ␉␉␉␉␉}␊ |
1184 | ␉␉␉␉}␊ |
1185 | ␊ |
1186 | ␉␉␉␉// Correct the checksum of XSDT␊ |
1187 | ␉␉␉␉xsdt_mod->Length-=8*dropoffset;␊ |
1188 | ␉␉␉␉xsdt_mod->Length+=8*newtotssdt;␊ |
1189 | ␉␉␉␉if (hpet_added)␊ |
1190 | ␉␉␉␉␉xsdt_mod->Length+=8;␊ |
1191 | ␉␉␉␉if (sbst_added)␊ |
1192 | ␉␉␉␉␉xsdt_mod->Length+=8;␊ |
1193 | ␉␉␉␉if (ecdt_added)␊ |
1194 | ␉␉␉␉␉xsdt_mod->Length+=8;␊ |
1195 | ␉␉␉␉if (asft_added)␊ |
1196 | ␉␉␉␉␉xsdt_mod->Length+=8;␊ |
1197 | ␉␉␉␉if (dmar_added)␊ |
1198 | ␉␉␉␉␉xsdt_mod->Length+=8;␊ |
1199 | ␉␉␉␉if (apic_added)␊ |
1200 | ␉␉␉␉␉xsdt_mod->Length+=8;␊ |
1201 | ␉␉␉␉if (mcfg_added)␊ |
1202 | ␉␉␉␉␉xsdt_mod->Length+=8;␊ |
1203 | ␊ |
1204 | ␉␉␉␉xsdt_mod->Checksum=0;␊ |
1205 | ␉␉␉␉xsdt_mod->Checksum=256-checksum8(xsdt_mod,xsdt_mod->Length);␊ |
1206 | ␉␉␉}␊ |
1207 | ␉␉␉else␊ |
1208 | ␉␉␉{␊ |
1209 | ␉␉␉drop_xsdt:␊ |
1210 | ␊ |
1211 | ␉␉␉␉DBG("About to drop XSDT\n");␊ |
1212 | ␊ |
1213 | ␉␉␉␉/*FIXME: Now we just hope that if MacOS doesn't find XSDT it reverts to RSDT. ␊ |
1214 | ␉␉␉␉ * A Better strategy would be to generate␊ |
1215 | ␉␉␉␉ */␊ |
1216 | ␊ |
1217 | ␉␉␉␉rsdp_mod->XsdtAddress=0xffffffffffffffffLL;␊ |
1218 | ␉␉␉␉verbose("XSDT not found or XSDT incorrect\n");␊ |
1219 | ␉␉␉}␊ |
1220 | ␉␉}␊ |
1221 | ␊ |
1222 | ␉␉// Correct the checksum of RSDP ␊ |
1223 | ␊ |
1224 | ␉␉DBG("RSDP: Original checksum %d, ", rsdp_mod->Checksum);␊ |
1225 | ␊ |
1226 | ␉␉rsdp_mod->Checksum=0;␊ |
1227 | ␉␉rsdp_mod->Checksum=256-checksum8(rsdp_mod,20);␊ |
1228 | ␊ |
1229 | ␉␉DBG("New checksum %d\n", rsdp_mod->Checksum);␊ |
1230 | ␊ |
1231 | ␉␉if (version)␊ |
1232 | ␉␉{␊ |
1233 | ␉␉␉DBG("RSDP: Original extended checksum %d", rsdp_mod->ExtendedChecksum);␊ |
1234 | ␊ |
1235 | ␉␉␉rsdp_mod->ExtendedChecksum=0;␊ |
1236 | ␉␉␉rsdp_mod->ExtendedChecksum=256-checksum8(rsdp_mod,rsdp_mod->Length);␊ |
1237 | ␊ |
1238 | ␉␉␉DBG("New extended checksum %d\n", rsdp_mod->ExtendedChecksum);␊ |
1239 | ␊ |
1240 | ␉␉}␊ |
1241 | ␉␉␊ |
1242 | ␉␉verbose("Patched ACPI version %d DSDT\n", version+1);␊ |
1243 | ␉␉if (version)␊ |
1244 | ␉␉{␊ |
1245 | ␉/* XXX aserebln why uint32 cast if pointer is uint64 ? */␊ |
1246 | ␉␉␉acpi20_p = (uint32_t)rsdp_mod;␊ |
1247 | ␉␉␉addConfigurationTable(&gEfiAcpi20TableGuid, &acpi20_p, "ACPI_20");␊ |
1248 | ␉␉}␊ |
1249 | ␉␉else␊ |
1250 | ␉␉{␊ |
1251 | ␉/* XXX aserebln why uint32 cast if pointer is uint64 ? */␊ |
1252 | ␉␉␉acpi10_p = (uint32_t)rsdp_mod;␊ |
1253 | ␉␉␉addConfigurationTable(&gEfiAcpiTableGuid, &acpi10_p, "ACPI");␊ |
1254 | ␉␉}␊ |
1255 | ␉}␊ |
1256 | #if DEBUG_DSDT␊ |
1257 | ␉printf("Press a key to continue... (DEBUG_DSDT)\n");␊ |
1258 | ␉getc();␊ |
1259 | #endif␊ |
1260 | ␉return 1;␊ |
1261 | }␊ |
1262 | |