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