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 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 | ␉if (new_dsdt)␊ |
388 | ␉{␊ |
389 | ␊ |
390 | ␉// Patch FACS Address␊ |
391 | ␉fadt_mod->FIRMWARE_CTRL=(uint32_t)fadt->FIRMWARE_CTRL;␊ |
392 | ␉if ((uint32_t)(&(fadt_mod->X_FIRMWARE_CTRL))-(uint32_t)fadt_mod+8<=fadt_mod->Length)␊ |
393 | ␉␉fadt_mod->X_FIRMWARE_CTRL=(uint32_t)fadt->FIRMWARE_CTRL␊ |
394 | ␊ |
395 | ␉// Patch DSDT Address␊ |
396 | ␉DBG("DSDT: Old @%x,%x, ",fadt_mod->DSDT,fadt_mod->X_DSDT);␊ |
397 | ␊ |
398 | ␉fadt_mod->DSDT=(uint32_t)new_dsdt;␊ |
399 | ␉if ((uint32_t)(&(fadt_mod->X_DSDT))-(uint32_t)fadt_mod+8<=fadt_mod->Length)␊ |
400 | ␉␉fadt_mod->X_DSDT=(uint32_t)new_dsdt;␊ |
401 | ␊ |
402 | ␉DBG("New @%x,%x\n",fadt_mod->DSDT,fadt_mod->X_DSDT);␊ |
403 | ␉␉verbose("FADT: Custom DSDT used !\n");␊ |
404 | ␉}␊ |
405 | ␊ |
406 | ␉// Correct the checksum␊ |
407 | ␉fadt_mod->Checksum=0;␊ |
408 | ␉fadt_mod->Checksum=256-checksum8(fadt_mod,fadt_mod->Length);␊ |
409 | ␊ |
410 | ␉return fadt_mod;␊ |
411 | }␊ |
412 | ␊ |
413 | /* Setup ACPI without replacing DSDT. */␊ |
414 | int setupAcpiNoMod()␊ |
415 | {␊ |
416 | //␉addConfigurationTable(&gEfiAcpiTableGuid, getAddressOfAcpiTable(), "ACPI");␊ |
417 | //␉addConfigurationTable(&gEfiAcpi20TableGuid, getAddressOfAcpi20Table(), "ACPI_20");␊ |
418 | ␉/* XXX aserebln why uint32 cast if pointer is uint64 ? */␊ |
419 | ␉acpi10_p = (uint32_t)getAddressOfAcpiTable();␊ |
420 | ␉acpi20_p = (uint32_t)getAddressOfAcpi20Table();␊ |
421 | ␉addConfigurationTable(&gEfiAcpiTableGuid, &acpi10_p, "ACPI");␊ |
422 | ␉if(acpi20_p) addConfigurationTable(&gEfiAcpi20TableGuid, &acpi20_p, "ACPI_20");␊ |
423 | ␉return 1;␊ |
424 | }␊ |
425 | ␊ |
426 | /* Setup ACPI. Replace DSDT if DSDT.aml is found */␊ |
427 | int setupAcpi(void)␊ |
428 | {␊ |
429 | ␉int version;␊ |
430 | ␉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[14];␊ |
431 | ␊ |
432 | ␉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;␊ |
433 | ␉bool drop_ssdt=false, drop_hpet=false, drop_slic=false, drop_sbst=false, drop_ecdt=false, drop_asft=false, drop_dmar=false;␊ |
434 | ␉bool update_acpi=false, gen_xsdt=false;␊ |
435 | ␉bool hpet_replaced=false, sbst_replaced=false, ecdt_replaced=false, asft_replaced=false, dmar_replaced=false, apic_replaced=false, mcfg_replaced=false;␊ |
436 | ␉bool hpet_added=false, sbst_added=false, ecdt_added=false, asft_added=false, dmar_added=false, apic_added=false, mcfg_added=false;␊ |
437 | ␊ |
438 | ␉int curssdt=0, loadtotssdt=0, totssdt=0, newtotssdt=0;␊ |
439 | ␊ |
440 | ␉{␊ |
441 | ␉␉bool tmpval;␊ |
442 | ␊ |
443 | ␉␉drop_ssdt=getBoolForKey(kDropSSDT, &tmpval, &bootInfo->bootConfig)&&tmpval;␊ |
444 | ␉␉drop_hpet=getBoolForKey(kDropHPET, &tmpval, &bootInfo->bootConfig)&&tmpval;␊ |
445 | ␉␉drop_slic=getBoolForKey(kDropSLIC, &tmpval, &bootInfo->bootConfig)&&tmpval;␊ |
446 | ␉␉drop_sbst=getBoolForKey(kDropSBST, &tmpval, &bootInfo->bootConfig)&&tmpval;␊ |
447 | ␉␉drop_ecdt=getBoolForKey(kDropECDT, &tmpval, &bootInfo->bootConfig)&&tmpval;␊ |
448 | ␉␉drop_asft=getBoolForKey(kDropASFT, &tmpval, &bootInfo->bootConfig)&&tmpval;␊ |
449 | ␉␉drop_dmar=getBoolForKey(kDropDMAR, &tmpval, &bootInfo->bootConfig)&&tmpval;␊ |
450 | ␊ |
451 | ␉␉oem_dsdt=getBoolForKey(kOEMDSDT, &tmpval, &bootInfo->bootConfig)&&tmpval;␊ |
452 | ␉␉oem_ssdt=getBoolForKey(kOEMSSDT, &tmpval, &bootInfo->bootConfig)&&tmpval;␊ |
453 | ␉␉oem_hpet=getBoolForKey(kOEMHPET, &tmpval, &bootInfo->bootConfig)&&tmpval;␊ |
454 | ␉␉oem_sbst=getBoolForKey(kOEMSBST, &tmpval, &bootInfo->bootConfig)&&tmpval;␊ |
455 | ␉␉oem_ecdt=getBoolForKey(kOEMECDT, &tmpval, &bootInfo->bootConfig)&&tmpval;␊ |
456 | ␉␉oem_asft=getBoolForKey(kOEMASFT, &tmpval, &bootInfo->bootConfig)&&tmpval;␊ |
457 | ␉␉oem_dmar=getBoolForKey(kOEMDMAR, &tmpval, &bootInfo->bootConfig)&&tmpval;␊ |
458 | ␉␉oem_apic=getBoolForKey(kOEMAPIC, &tmpval, &bootInfo->bootConfig)&&tmpval;␊ |
459 | ␉␉oem_mcfg=getBoolForKey(kOEMMCFG, &tmpval, &bootInfo->bootConfig)&&tmpval;␊ |
460 | ␊ |
461 | ␉␉update_acpi=getBoolForKey(kUpdateACPI, &tmpval, &bootInfo->bootConfig)&&tmpval;␊ |
462 | ␉}␊ |
463 | ␊ |
464 | ␉// Load replacement ACPI tables␊ |
465 | ␉if (!oem_dsdt)␊ |
466 | ␉␉new_dsdt=loadACPITable(kDSDT);␊ |
467 | ␊ |
468 | ␉if (!oem_hpet)␊ |
469 | ␉␉new_hpet=loadACPITable(kHPET);␊ |
470 | ␊ |
471 | ␉if (!oem_sbst)␊ |
472 | ␉␉new_sbst=loadACPITable(kSBST);␊ |
473 | ␊ |
474 | ␉if (!oem_ecdt)␊ |
475 | ␉␉new_ecdt=loadACPITable(kECDT);␊ |
476 | ␊ |
477 | ␉if (!oem_asft)␊ |
478 | ␉␉new_asft=loadACPITable(kASFT);␊ |
479 | ␊ |
480 | ␉if (!oem_dmar)␊ |
481 | ␉␉new_dmar=loadACPITable(kDMAR);␊ |
482 | ␊ |
483 | ␉if (!oem_apic)␊ |
484 | ␉␉new_apic=loadACPITable(kAPIC);␊ |
485 | ␊ |
486 | ␉if (!oem_mcfg)␊ |
487 | ␉␉new_mcfg=loadACPITable(kMCFG);␊ |
488 | ␊ |
489 | ␉if (!oem_ssdt)␊ |
490 | ␉{␊ |
491 | ␉␉for (curssdt=0;curssdt<14;curssdt++)␊ |
492 | ␉␉{␊ |
493 | ␉␉␉new_ssdts[curssdt]=loadSSDTTable(curssdt);␊ |
494 | ␉␉␉if (new_ssdts[curssdt])␊ |
495 | ␉␉␉␉loadtotssdt++;␊ |
496 | ␉␉}␊ |
497 | ␉␉curssdt=0;␊ |
498 | ␉}␊ |
499 | /*␊ |
500 | ␉if (!new_dsdt)␊ |
501 | ␉␉return setupAcpiNoMod();␊ |
502 | */␊ |
503 | ␉DBG("New ACPI tables Loaded in memory\n");␊ |
504 | ␉␉␉␊ |
505 | ␉// Do the same procedure for both versions of ACPI␊ |
506 | ␉for (version=0; version<2; version++) {␊ |
507 | ␉␉struct acpi_2_rsdp *rsdp, *rsdp_mod, *rsdp_conv=(struct acpi_2_rsdp *)0;␊ |
508 | ␉␉struct acpi_2_rsdt *rsdt, *rsdt_mod;␊ |
509 | ␉␉struct acpi_2_xsdt *xsdt_conv = (struct acpi_2_xsdt *)0;␊ |
510 | ␉␉int rsdplength;␊ |
511 | ␊ |
512 | ␉␉// Find original rsdp␊ |
513 | ␉␉rsdp=(struct acpi_2_rsdp *)(version?getAddressOfAcpi20Table():getAddressOfAcpiTable());␊ |
514 | ␉␉if ((update_acpi) && (rsdp->Revision == 0))␊ |
515 | ␉␉{␊ |
516 | ␉␉␉rsdp_conv = (struct acpi_2_rsdp *)AllocateKernelMemory(sizeof(struct acpi_2_rsdp));␊ |
517 | ␉␉␉memcpy(rsdp_conv, rsdp, 20);␊ |
518 | ␊ |
519 | ␉␉␉/* Add/change fields */␊ |
520 | ␉␉␉rsdp_conv->Revision = 2; /* ACPI version 3 */␊ |
521 | ␉␉␉rsdp_conv->Length = sizeof(struct acpi_2_rsdp);␊ |
522 | ␊ |
523 | ␉␉␉/* Correct checksums */␊ |
524 | ␉␉␉rsdp_conv->Checksum = 0;␊ |
525 | ␉␉␉rsdp_conv->Checksum = 256-checksum8(rsdp_conv, 20);␊ |
526 | ␉␉␉rsdp_conv->ExtendedChecksum = 0;␊ |
527 | ␉␉␉rsdp_conv->ExtendedChecksum = 256-checksum8(rsdp_conv, rsdp_conv->Length);␊ |
528 | ␊ |
529 | ␉␉␉rsdp = rsdp_conv;␊ |
530 | ␊ |
531 | ␉␉␉gen_xsdt = true;␊ |
532 | ␉␉␉version = 1;␊ |
533 | ␊ |
534 | ␉␉␉addConfigurationTable(&gEfiAcpiTableGuid, NULL, "ACPI");␊ |
535 | ␊ |
536 | ␉␉␉verbose("Converted ACPI RSD PTR version 1 to version 3\n");␊ |
537 | ␉␉}␊ |
538 | ␉␉if (!rsdp)␊ |
539 | ␉␉{␊ |
540 | ␉␉␉DBG("No ACPI version %d found. Ignoring\n", version+1);␊ |
541 | ␉␉␉if (version)␊ |
542 | ␉␉␉␉addConfigurationTable(&gEfiAcpi20TableGuid, NULL, "ACPI_20");␊ |
543 | ␉␉␉else␊ |
544 | ␉␉␉␉addConfigurationTable(&gEfiAcpiTableGuid, NULL, "ACPI");␊ |
545 | ␉␉␉continue;␊ |
546 | ␉␉}␊ |
547 | ␉␉rsdplength=version?rsdp->Length:20;␊ |
548 | ␊ |
549 | ␉␉DBG("RSDP version %d found @%x. Length=%d\n",version+1,rsdp,rsdplength);␊ |
550 | ␊ |
551 | ␉␉/* FIXME: no check that memory allocation succeeded ␊ |
552 | ␉␉ * Copy and patch RSDP,RSDT, XSDT and FADT␊ |
553 | ␉␉ * For more info see ACPI Specification pages 110 and following␊ |
554 | ␉␉ */␊ |
555 | ␊ |
556 | ␉␉if (gen_xsdt)␊ |
557 | ␉␉{␊ |
558 | ␉␉␉rsdp_mod=rsdp_conv;␊ |
559 | ␉␉} else {␊ |
560 | ␉␉␉rsdp_mod=(struct acpi_2_rsdp *) AllocateKernelMemory(rsdplength);␊ |
561 | ␉␉␉memcpy(rsdp_mod, rsdp, rsdplength);␊ |
562 | ␉␉}␊ |
563 | ␊ |
564 | ␉␉rsdt=(struct acpi_2_rsdt *)(rsdp->RsdtAddress);␊ |
565 | ␊ |
566 | ␉␉DBG("RSDT @%x, Length %d\n",rsdt, rsdt->Length);␊ |
567 | ␉␉␊ |
568 | ␉␉if (rsdt && (uint32_t)rsdt !=0xffffffff && rsdt->Length<0x10000)␊ |
569 | ␉␉{␊ |
570 | ␉␉␉uint32_t *rsdt_entries;␊ |
571 | ␉␉␉int rsdt_entries_num;␊ |
572 | ␉␉␉int dropoffset=0, i;␊ |
573 | ␉␉␉␊ |
574 | ␉␉␉rsdt_mod=(struct acpi_2_rsdt *)AllocateKernelMemory(rsdt->Length); ␊ |
575 | ␉␉␉memcpy (rsdt_mod, rsdt, rsdt->Length);␊ |
576 | ␉␉␉rsdp_mod->RsdtAddress=(uint32_t)rsdt_mod;␊ |
577 | ␉␉␉rsdt_entries_num=(rsdt_mod->Length-sizeof(struct acpi_2_rsdt))/4;␊ |
578 | ␉␉␉rsdt_entries=(uint32_t *)(rsdt_mod+1);␊ |
579 | ␊ |
580 | ␉␉␉if (gen_xsdt)␊ |
581 | ␉␉␉{␊ |
582 | ␉␉␉␉uint64_t *xsdt_conv_entries;␊ |
583 | ␊ |
584 | ␉␉␉␉xsdt_conv=(struct acpi_2_xsdt *)AllocateKernelMemory(sizeof(struct acpi_2_xsdt)+(rsdt_entries_num * 8));␊ |
585 | ␉␉␉␉memcpy(xsdt_conv, rsdt, sizeof(struct acpi_2_rsdt));␊ |
586 | ␊ |
587 | ␉␉␉␉xsdt_conv->Signature[0] = 'X';␊ |
588 | ␉␉␉␉xsdt_conv->Signature[1] = 'S';␊ |
589 | ␉␉␉␉xsdt_conv->Signature[2] = 'D';␊ |
590 | ␉␉␉␉xsdt_conv->Signature[3] = 'T';␊ |
591 | ␉␉␉␉xsdt_conv->Length = sizeof(struct acpi_2_xsdt)+(rsdt_entries_num * 8);␊ |
592 | ␊ |
593 | ␉␉␉␉xsdt_conv_entries=(uint64_t *)(xsdt_conv+1);␊ |
594 | ␊ |
595 | ␉␉␉␉for (i=0;i<rsdt_entries_num;i++)␊ |
596 | ␉␉␉␉{␊ |
597 | ␉␉␉␉␉xsdt_conv_entries[i] = (uint64_t)rsdt_entries[i];␊ |
598 | ␉␉␉␉}␊ |
599 | ␊ |
600 | ␉␉␉␉xsdt_conv->Checksum = 0;␊ |
601 | ␉␉␉␉xsdt_conv->Checksum = 256-checksum8(xsdt_conv, xsdt_conv->Length);␊ |
602 | ␊ |
603 | ␉␉␉␉rsdp->XsdtAddress = (uint32_t)xsdt_conv;␊ |
604 | ␊ |
605 | ␉␉␉␉rsdp->ExtendedChecksum = 0;␊ |
606 | ␉␉␉␉rsdp->ExtendedChecksum = 256-checksum8(rsdp, rsdp->Length);␊ |
607 | ␊ |
608 | ␉␉␉␉verbose("Converted RSDT table to XSDT table\n");␊ |
609 | ␉␉␉}␊ |
610 | ␊ |
611 | ␉␉␉for (i=0;i<rsdt_entries_num;i++)␊ |
612 | ␉␉␉{␊ |
613 | ␉␉␉␉char *table=(char *)(rsdt_entries[i]);␊ |
614 | ␉␉␉␉if (!table)␊ |
615 | ␉␉␉␉␉continue;␊ |
616 | ␊ |
617 | ␉␉␉␉DBG("TABLE %c%c%c%c,",table[0],table[1],table[2],table[3]);␊ |
618 | ␊ |
619 | ␉␉␉␉rsdt_entries[i-dropoffset]=rsdt_entries[i];␊ |
620 | ␉␉␉␉if (drop_ssdt && table[0]=='S' && table[1]=='S' && table[2]=='D' && table[3]=='T')␊ |
621 | ␉␉␉␉{␊ |
622 | ␉␉␉␉␉dropoffset++;␊ |
623 | ␉␉␉␉␉continue;␊ |
624 | ␉␉␉␉}␊ |
625 | ␉␉␉␉if (drop_hpet && table[0]=='H' && table[1]=='P' && table[2]=='E' && table[3]=='T')␊ |
626 | ␉␉␉␉{␊ |
627 | ␉␉␉␉␉dropoffset++;␊ |
628 | ␉␉␉␉␉continue;␊ |
629 | ␉␉␉␉}␉␉␉␊ |
630 | ␉␉␉␉if (drop_slic && table[0]=='S' && table[1]=='L' && table[2]=='I' && table[3]=='C')␊ |
631 | ␉␉␉␉{␊ |
632 | ␉␉␉␉␉dropoffset++;␊ |
633 | ␉␉␉␉␉continue;␊ |
634 | ␉␉␉␉}␊ |
635 | ␉␉␉␉if (drop_sbst && table[0]=='S' && table[1]=='B' && table[2]=='S' && table[3]=='T')␊ |
636 | ␉␉␉␉{␊ |
637 | ␉␉␉␉␉dropoffset++;␊ |
638 | ␉␉␉␉␉continue;␊ |
639 | ␉␉␉␉}␊ |
640 | ␉␉␉␉if (drop_ecdt && table[0]=='E' && table[1]=='C' && table[2]=='D' && table[3]=='T')␊ |
641 | ␉␉␉␉{␊ |
642 | ␉␉␉␉␉dropoffset++;␊ |
643 | ␉␉␉␉␉continue;␊ |
644 | ␉␉␉␉}␊ |
645 | ␉␉␉␉if (drop_asft && table[0]=='A' && table[1]=='S' && table[2]=='F' && table[3]=='!')␊ |
646 | ␉␉␉␉{␊ |
647 | ␉␉␉␉␉dropoffset++;␊ |
648 | ␉␉␉␉␉continue;␊ |
649 | ␉␉␉␉}␊ |
650 | ␉␉␉␉if (drop_dmar && table[0]=='D' && table[1]=='M' && table[2]=='A' && table[3]=='R')␊ |
651 | ␉␉␉␉{␊ |
652 | ␉␉␉␉␉dropoffset++;␊ |
653 | ␉␉␉␉␉continue;␊ |
654 | ␉␉␉␉}␊ |
655 | ␉␉␉␉if ((!(oem_hpet)) && table[0]=='H' && table[1]=='P' && table[2]=='E' && table[3]=='T')␊ |
656 | ␉␉␉␉{␊ |
657 | ␉␉␉␉␉DBG("HPET found\n");␊ |
658 | ␉␉␉␉␉if (new_hpet)␊ |
659 | ␉␉␉␉␉{␊ |
660 | ␉␉␉␉␉␉rsdt_entries[i-dropoffset]=(uint32_t)new_hpet;␊ |
661 | ␉␉␉␉␉␉hpet_replaced=true;␊ |
662 | ␉␉␉␉␉}␊ |
663 | ␉␉␉␉␉continue;␊ |
664 | ␉␉␉␉}␊ |
665 | ␉␉␉␉if ((!(oem_sbst)) && table[0]=='S' && table[1]=='B' && table[2]=='S' && table[3]=='T')␊ |
666 | ␉␉␉␉{␊ |
667 | ␉␉␉␉␉DBG("SBST found\n");␊ |
668 | ␉␉␉␉␉if (new_sbst)␊ |
669 | ␉␉␉␉␉{␊ |
670 | ␉␉␉␉␉␉rsdt_entries[i-dropoffset]=(uint32_t)new_sbst;␊ |
671 | ␉␉␉␉␉␉sbst_replaced=true;␊ |
672 | ␉␉␉␉␉}␊ |
673 | ␉␉␉␉␉continue;␊ |
674 | ␉␉␉␉}␊ |
675 | ␉␉␉␉if ((!(oem_ecdt)) && table[0]=='E' && table[1]=='C' && table[2]=='D' && table[3]=='T')␊ |
676 | ␉␉␉␉{␊ |
677 | ␉␉␉␉␉DBG("ECDT found\n");␊ |
678 | ␉␉␉␉␉if (new_ecdt)␊ |
679 | ␉␉␉␉␉{␊ |
680 | ␉␉␉␉␉␉rsdt_entries[i-dropoffset]=(uint32_t)new_ecdt;␊ |
681 | ␉␉␉␉␉␉ecdt_replaced=true;␊ |
682 | ␉␉␉␉␉}␊ |
683 | ␉␉␉␉␉continue;␊ |
684 | ␉␉␉␉}␊ |
685 | ␉␉␉␉if ((!(oem_asft)) && table[0]=='A' && table[1]=='S' && table[2]=='F' && table[3]=='!')␊ |
686 | ␉␉␉␉{␊ |
687 | ␉␉␉␉␉DBG("ASF! found\n");␊ |
688 | ␉␉␉␉␉if (new_asft)␊ |
689 | ␉␉␉␉␉{␊ |
690 | ␉␉␉␉␉␉rsdt_entries[i-dropoffset]=(uint32_t)new_asft;␊ |
691 | ␉␉␉␉␉␉asft_replaced=true;␊ |
692 | ␉␉␉␉␉}␊ |
693 | ␉␉␉␉␉continue;␊ |
694 | ␉␉␉␉}␊ |
695 | ␉␉␉␉if ((!(oem_dmar)) && table[0]=='D' && table[1]=='M' && table[2]=='A' && table[3]=='R')␊ |
696 | ␉␉␉␉{␊ |
697 | ␉␉␉␉␉DBG("DMAR found\n");␊ |
698 | ␉␉␉␉␉if (new_dmar)␊ |
699 | ␉␉␉␉␉{␊ |
700 | ␉␉␉␉␉␉rsdt_entries[i-dropoffset]=(uint32_t)new_dmar;␊ |
701 | ␉␉␉␉␉␉dmar_replaced=true;␊ |
702 | ␉␉␉␉␉}␊ |
703 | ␉␉␉␉␉continue;␊ |
704 | ␉␉␉␉}␊ |
705 | ␉␉␉␉if ((!(oem_apic)) && table[0]=='A' && table[1]=='P' && table[2]=='I' && table[3]=='C')␊ |
706 | ␉␉␉␉{␊ |
707 | ␉␉␉␉␉DBG("APIC found\n");␊ |
708 | ␉␉␉␉␉if (new_apic)␊ |
709 | ␉␉␉␉␉{␊ |
710 | ␉␉␉␉␉␉rsdt_entries[i-dropoffset]=(uint32_t)new_apic;␊ |
711 | ␉␉␉␉␉␉apic_replaced=true;␊ |
712 | ␉␉␉␉␉}␊ |
713 | ␉␉␉␉␉continue;␊ |
714 | ␉␉␉␉}␊ |
715 | ␉␉␉␉if ((!(oem_mcfg)) && table[0]=='M' && table[1]=='C' && table[2]=='F' && table[3]=='G')␊ |
716 | ␉␉␉␉{␊ |
717 | ␉␉␉␉␉DBG("MCFG found\n");␊ |
718 | ␉␉␉␉␉if (new_mcfg)␊ |
719 | ␉␉␉␉␉{␊ |
720 | ␉␉␉␉␉␉rsdt_entries[i-dropoffset]=(uint32_t)new_mcfg;␊ |
721 | ␉␉␉␉␉␉mcfg_replaced=true;␊ |
722 | ␉␉␉␉␉}␊ |
723 | ␉␉␉␉␉continue;␊ |
724 | ␉␉␉␉}␊ |
725 | ␉␉␉␉if ((!(oem_ssdt)) && table[0]=='S' && table[1]=='S' && table[2]=='D' && table[3]=='T')␊ |
726 | ␉␉␉␉{␊ |
727 | ␉␉␉␉␉DBG("SSDT %d found", curssdt);␊ |
728 | ␉␉␉␉␉if (new_ssdts[curssdt])␊ |
729 | ␉␉␉␉␉{␊ |
730 | ␉␉␉␉␉␉DBG(" and replaced");␊ |
731 | ␉␉␉␉␉␉rsdt_entries[i-dropoffset]=(uint32_t)new_ssdts[curssdt];␊ |
732 | ␉␉␉␉␉␉totssdt++;␊ |
733 | ␉␉␉␉␉}␊ |
734 | ␉␉␉␉␉DBG("\n");␊ |
735 | ␉␉␉␉␉curssdt++;␊ |
736 | ␉␉␉␉␉continue;␊ |
737 | ␉␉␉␉}␊ |
738 | ␉␉␉␉if (table[0]=='D' && table[1]=='S' && table[2]=='D' && table[3]=='T')␊ |
739 | ␉␉␉␉{␊ |
740 | ␉␉␉␉␉DBG("DSDT found\n");␊ |
741 | ␉␉␉␉␉rsdt_entries[i-dropoffset]=(uint32_t)new_dsdt;␊ |
742 | ␉␉␉␉␉continue;␊ |
743 | ␉␉␉␉}␊ |
744 | ␉␉␉␉if (table[0]=='F' && table[1]=='A' && table[2]=='C' && table[3]=='P')␊ |
745 | ␉␉␉␉{␊ |
746 | ␉␉␉␉␉struct acpi_2_fadt *fadt, *fadt_mod;␊ |
747 | ␉␉␉␉␉fadt=(struct acpi_2_fadt *)rsdt_entries[i];␊ |
748 | ␊ |
749 | ␉␉␉␉␉DBG("FADT found @%x, Length %d\n",fadt, fadt->Length);␊ |
750 | ␊ |
751 | ␉␉␉␉␉if (!fadt || (uint32_t)fadt == 0xffffffff || fadt->Length>0x10000)␊ |
752 | ␉␉␉␉␉{␊ |
753 | ␉␉␉␉␉␉printf("FADT incorrect. Not modified\n");␊ |
754 | ␉␉␉␉␉␉continue;␊ |
755 | ␉␉␉␉␉}␊ |
756 | ␉␉␉␉␉␊ |
757 | ␉␉␉␉␉fadt_mod = patch_fadt(fadt, new_dsdt, update_acpi);␊ |
758 | ␉␉␉␉␉rsdt_entries[i-dropoffset]=(uint32_t)fadt_mod;␊ |
759 | ␉␉␉␉␉continue;␊ |
760 | ␉␉␉␉}␊ |
761 | ␉␉␉}␊ |
762 | ␉␉␉DBG("\n");␊ |
763 | ␊ |
764 | ␉␉␉if ((!oem_hpet) && (!hpet_replaced))␊ |
765 | ␉␉␉{␊ |
766 | ␉␉␉␉if (new_hpet)␊ |
767 | ␉␉␉␉{␊ |
768 | ␉␉␉␉␉rsdt_entries[i-dropoffset]=(uint32_t)new_hpet;␊ |
769 | ␉␉␉␉␉hpet_added=true;␊ |
770 | ␉␉␉␉␉i++;␊ |
771 | ␉␉␉␉}␊ |
772 | ␉␉␉}␊ |
773 | ␊ |
774 | ␉␉␉if ((!oem_sbst) && (!sbst_replaced))␊ |
775 | ␉␉␉{␊ |
776 | ␉␉␉␉if (new_sbst)␊ |
777 | ␉␉␉␉{␊ |
778 | ␉␉␉␉␉rsdt_entries[i-dropoffset]=(uint32_t)new_sbst;␊ |
779 | ␉␉␉␉␉sbst_added=true;␊ |
780 | ␉␉␉␉␉i++;␊ |
781 | ␉␉␉␉}␊ |
782 | ␉␉␉}␊ |
783 | ␊ |
784 | ␉␉␉if ((!oem_ecdt) && (!ecdt_replaced))␊ |
785 | ␉␉␉{␊ |
786 | ␉␉␉␉if (new_ecdt)␊ |
787 | ␉␉␉␉{␊ |
788 | ␉␉␉␉␉rsdt_entries[i-dropoffset]=(uint32_t)new_ecdt;␊ |
789 | ␉␉␉␉␉ecdt_added=true;␊ |
790 | ␉␉␉␉␉i++;␊ |
791 | ␉␉␉␉}␊ |
792 | ␉␉␉}␊ |
793 | ␊ |
794 | ␉␉␉if ((!oem_asft) && (!asft_replaced))␊ |
795 | ␉␉␉{␊ |
796 | ␉␉␉␉if (new_asft)␊ |
797 | ␉␉␉␉{␊ |
798 | ␉␉␉␉␉rsdt_entries[i-dropoffset]=(uint32_t)new_asft;␊ |
799 | ␉␉␉␉␉asft_added=true;␊ |
800 | ␉␉␉␉␉i++;␊ |
801 | ␉␉␉␉}␊ |
802 | ␉␉␉}␊ |
803 | ␊ |
804 | ␉␉␉if ((!oem_dmar) && (!dmar_replaced))␊ |
805 | ␉␉␉{␊ |
806 | ␉␉␉␉if (new_dmar)␊ |
807 | ␉␉␉␉{␊ |
808 | ␉␉␉␉␉rsdt_entries[i-dropoffset]=(uint32_t)new_dmar;␊ |
809 | ␉␉␉␉␉dmar_added=true;␊ |
810 | ␉␉␉␉␉i++;␊ |
811 | ␉␉␉␉}␊ |
812 | ␉␉␉}␊ |
813 | ␊ |
814 | ␉␉␉if ((!oem_apic) && (!apic_replaced))␊ |
815 | ␉␉␉{␊ |
816 | ␉␉␉␉if (new_apic)␊ |
817 | ␉␉␉␉{␊ |
818 | ␉␉␉␉␉rsdt_entries[i-dropoffset]=(uint32_t)new_apic;␊ |
819 | ␉␉␉␉␉apic_added=true;␊ |
820 | ␉␉␉␉␉i++;␊ |
821 | ␉␉␉␉}␊ |
822 | ␉␉␉}␊ |
823 | ␊ |
824 | ␉␉␉if ((!oem_mcfg) && (!mcfg_replaced))␊ |
825 | ␉␉␉{␊ |
826 | ␉␉␉␉if (new_mcfg)␊ |
827 | ␉␉␉␉{␊ |
828 | ␉␉␉␉␉rsdt_entries[i-dropoffset]=(uint32_t)new_mcfg;␊ |
829 | ␉␉␉␉␉mcfg_added=true;␊ |
830 | ␉␉␉␉␉i++;␊ |
831 | ␉␉␉␉}␊ |
832 | ␉␉␉}␊ |
833 | ␉␉␉␊ |
834 | ␉␉␉if (!oem_ssdt)␊ |
835 | ␉␉␉{ ␉␉␉␊ |
836 | ␉␉␉␉while ((totssdt < loadtotssdt) && (curssdt < 14))␊ |
837 | ␉␉␉␉{␊ |
838 | ␉␉␉␉␉if (new_ssdts[curssdt])␊ |
839 | ␉␉␉␉␉{␊ |
840 | ␉␉␉␉␉␉DBG("adding SSDT %d\n", curssdt);␊ |
841 | ␉␉␉␉␉␉rsdt_entries[i-dropoffset]=(uint32_t)new_ssdts[curssdt];␊ |
842 | ␉␉␉␉␉␉totssdt++;␊ |
843 | ␉␉␉␉␉␉newtotssdt++;␊ |
844 | ␉␉␉␉␉␉i++;␊ |
845 | ␉␉␉␉␉}␊ |
846 | ␉␉␉␉␉curssdt++;␊ |
847 | ␉␉␉␉}␊ |
848 | ␉␉␉}␊ |
849 | ␊ |
850 | ␉␉␉// Correct the checksum of RSDT␊ |
851 | ␉␉␉rsdt_mod->Length-=4*dropoffset;␊ |
852 | ␉␉␉rsdt_mod->Length+=4*newtotssdt;␊ |
853 | ␉␉␉if (hpet_added)␊ |
854 | ␉␉␉␉rsdt_mod->Length+=4;␊ |
855 | ␉␉␉if (sbst_added)␊ |
856 | ␉␉␉␉rsdt_mod->Length+=4;␊ |
857 | ␉␉␉if (ecdt_added)␊ |
858 | ␉␉␉␉rsdt_mod->Length+=4;␊ |
859 | ␉␉␉if (asft_added)␊ |
860 | ␉␉␉␉rsdt_mod->Length+=4;␊ |
861 | ␉␉␉if (dmar_added)␊ |
862 | ␉␉␉␉rsdt_mod->Length+=4;␊ |
863 | ␉␉␉if (apic_added)␊ |
864 | ␉␉␉␉rsdt_mod->Length+=4;␊ |
865 | ␉␉␉if (mcfg_added)␊ |
866 | ␉␉␉␉rsdt_mod->Length+=4;␊ |
867 | ␊ |
868 | ␉␉␉DBG("RSDT: Original checksum %d, ", rsdt_mod->Checksum);␊ |
869 | ␊ |
870 | ␉␉␉rsdt_mod->Checksum=0;␊ |
871 | ␉␉␉rsdt_mod->Checksum=256-checksum8(rsdt_mod,rsdt_mod->Length);␊ |
872 | ␊ |
873 | ␉␉␉DBG("New checksum %d at %x\n", rsdt_mod->Checksum,rsdt_mod);␊ |
874 | ␉␉}␊ |
875 | ␉␉else␊ |
876 | ␉␉{␊ |
877 | ␉␉␉rsdp_mod->RsdtAddress=0;␊ |
878 | ␉␉␉printf("RSDT not found or RSDT incorrect\n");␊ |
879 | ␉␉}␊ |
880 | ␊ |
881 | ␉␉if (version)␊ |
882 | ␉␉{␊ |
883 | ␉␉␉struct acpi_2_xsdt *xsdt, *xsdt_mod;␊ |
884 | ␊ |
885 | ␉␉␉// FIXME: handle 64-bit address correctly␊ |
886 | ␊ |
887 | ␉␉␉if (gen_xsdt)␊ |
888 | ␉␉␉␉xsdt=xsdt_conv;␊ |
889 | ␉␉␉else␊ |
890 | ␉␉␉␉xsdt=(struct acpi_2_xsdt*) ((uint32_t)rsdp->XsdtAddress);␊ |
891 | ␊ |
892 | ␉␉␉DBG("XSDT @%x;%x, Length=%d\n", (uint32_t)(rsdp->XsdtAddress>>32),(uint32_t)rsdp->XsdtAddress,␊ |
893 | ␉␉␉␉␉xsdt->Length);␊ |
894 | ␉␉␉if (xsdt && (uint64_t)rsdp->XsdtAddress<0xffffffff && xsdt->Length<0x10000)␊ |
895 | ␉␉␉{␊ |
896 | ␉␉␉␉uint64_t *xsdt_entries;␊ |
897 | ␉␉␉␉int xsdt_entries_num, i;␊ |
898 | ␉␉␉␉int dropoffset=0;␊ |
899 | ␉␉␉␉curssdt=0, totssdt=0, newtotssdt=0;␊ |
900 | ␉␉␉␉hpet_replaced=false, hpet_added=false;␊ |
901 | ␉␉␉␉sbst_replaced=false, sbst_added=false;␊ |
902 | ␉␉␉␉ecdt_replaced=false, ecdt_added=false;␊ |
903 | ␉␉␉␉asft_replaced=false, asft_added=false;␊ |
904 | ␉␉␉␉dmar_replaced=false, dmar_added=false;␊ |
905 | ␉␉␉␉apic_replaced=false, apic_added=false;␊ |
906 | ␉␉␉␉mcfg_replaced=false, mcfg_added=false;␊ |
907 | ␊ |
908 | ␉␉␉␉if (gen_xsdt)␊ |
909 | ␉␉␉␉␉xsdt_mod=xsdt;␊ |
910 | ␉␉␉␉else␊ |
911 | ␉␉␉␉{␊ |
912 | ␉␉␉␉␉xsdt_mod=(struct acpi_2_xsdt*)AllocateKernelMemory(xsdt->Length); ␊ |
913 | ␉␉␉␉␉memcpy(xsdt_mod, xsdt, xsdt->Length);␊ |
914 | ␉␉␉␉}␊ |
915 | ␊ |
916 | ␉␉␉␉rsdp_mod->XsdtAddress=(uint32_t)xsdt_mod;␊ |
917 | ␉␉␉␉xsdt_entries_num=(xsdt_mod->Length-sizeof(struct acpi_2_xsdt))/8;␊ |
918 | ␉␉␉␉xsdt_entries=(uint64_t *)(xsdt_mod+1);␊ |
919 | ␉␉␉␉for (i=0;i<xsdt_entries_num;i++)␊ |
920 | ␉␉␉␉{␊ |
921 | ␉␉␉␉␉char *table=(char *)((uint32_t)(xsdt_entries[i]));␊ |
922 | ␉␉␉␉␉if (!table)␊ |
923 | ␉␉␉␉␉␉continue;␊ |
924 | ␉␉␉␉␉xsdt_entries[i-dropoffset]=xsdt_entries[i];␊ |
925 | ␉␉␉␉␉if (drop_ssdt && table[0]=='S' && table[1]=='S' && table[2]=='D' && table[3]=='T')␊ |
926 | ␉␉␉␉␉{␊ |
927 | ␉␉␉␉␉␉dropoffset++;␊ |
928 | ␉␉␉␉␉␉continue;␊ |
929 | ␉␉␉␉␉}␉␊ |
930 | ␉␉␉␉␉if (drop_hpet && table[0]=='H' && table[1]=='P' && table[2]=='E' && table[3]=='T')␊ |
931 | ␉␉␉␉␉{␊ |
932 | ␉␉␉␉␉␉dropoffset++;␊ |
933 | ␉␉␉␉␉␉continue;␊ |
934 | ␉␉␉␉␉}␊ |
935 | ␉␉␉␉␉if (drop_slic && table[0]=='S' && table[1]=='L' && table[2]=='I' && table[3]=='C')␊ |
936 | ␉␉␉␉␉{␊ |
937 | ␉␉␉␉␉␉dropoffset++;␊ |
938 | ␉␉␉␉␉␉continue;␊ |
939 | ␉␉␉␉␉}␊ |
940 | ␉␉␉␉␉if (drop_sbst && table[0]=='S' && table[1]=='B' && table[2]=='S' && table[3]=='T')␊ |
941 | ␉␉␉␉␉{␊ |
942 | ␉␉␉␉␉␉dropoffset++;␊ |
943 | ␉␉␉␉␉␉continue;␊ |
944 | ␉␉␉␉␉}␊ |
945 | ␉␉␉␉␉if (drop_ecdt && table[0]=='E' && table[1]=='C' && table[2]=='D' && table[3]=='T')␊ |
946 | ␉␉␉␉␉{␊ |
947 | ␉␉␉␉␉␉dropoffset++;␊ |
948 | ␉␉␉␉␉␉continue;␊ |
949 | ␉␉␉␉␉}␉␉␉␉␉␊ |
950 | ␉␉␉␉␉if (drop_asft && table[0]=='A' && table[1]=='S' && table[2]=='F' && table[3]=='!')␊ |
951 | ␉␉␉␉␉{␊ |
952 | ␉␉␉␉␉␉dropoffset++;␊ |
953 | ␉␉␉␉␉␉continue;␊ |
954 | ␉␉␉␉␉}␊ |
955 | ␉␉␉␉␉if (drop_dmar && table[0]=='D' && table[1]=='M' && table[2]=='A' && table[3]=='R')␊ |
956 | ␉␉␉␉␉{␊ |
957 | ␉␉␉␉␉␉dropoffset++;␊ |
958 | ␉␉␉␉␉␉continue;␊ |
959 | ␉␉␉␉␉}␉␉␉␉␉␊ |
960 | ␉␉␉␉␉if ((!(oem_hpet)) && table[0]=='H' && table[1]=='P' && table[2]=='E' && table[3]=='T')␊ |
961 | ␉␉␉␉␉{␊ |
962 | ␉␉␉␉␉␉DBG("HPET found\n");␊ |
963 | ␉␉␉␉␉␉if (new_hpet)␊ |
964 | ␉␉␉␉␉␉{␊ |
965 | ␉␉␉␉␉␉␉xsdt_entries[i-dropoffset]=(uint32_t)new_hpet;␊ |
966 | ␉␉␉␉␉␉␉hpet_replaced=true;␊ |
967 | ␉␉␉␉␉␉}␊ |
968 | ␉␉␉␉␉␉continue;␊ |
969 | ␉␉␉␉␉}␉␉␉␉␉␊ |
970 | ␉␉␉␉␉if ((!(oem_sbst)) && table[0]=='S' && table[1]=='B' && table[2]=='S' && table[3]=='T')␊ |
971 | ␉␉␉␉␉{␊ |
972 | ␉␉␉␉␉␉DBG("SBST found\n");␊ |
973 | ␉␉␉␉␉␉if (new_sbst)␊ |
974 | ␉␉␉␉␉␉{␊ |
975 | ␉␉␉␉␉␉␉xsdt_entries[i-dropoffset]=(uint32_t)new_sbst;␊ |
976 | ␉␉␉␉␉␉␉sbst_replaced=true;␊ |
977 | ␉␉␉␉␉␉}␊ |
978 | ␉␉␉␉␉␉continue;␊ |
979 | ␉␉␉␉␉}␉␉␉␉␉␊ |
980 | ␉␉␉␉␉if ((!(oem_ecdt)) && table[0]=='E' && table[1]=='C' && table[2]=='D' && table[3]=='T')␊ |
981 | ␉␉␉␉␉{␊ |
982 | ␉␉␉␉␉␉DBG("ECDT found\n");␊ |
983 | ␉␉␉␉␉␉if (new_ecdt)␊ |
984 | ␉␉␉␉␉␉{␊ |
985 | ␉␉␉␉␉␉␉xsdt_entries[i-dropoffset]=(uint32_t)new_ecdt;␊ |
986 | ␉␉␉␉␉␉␉ecdt_replaced=true;␊ |
987 | ␉␉␉␉␉␉}␊ |
988 | ␉␉␉␉␉␉continue;␊ |
989 | ␉␉␉␉␉}␉␉␉␉␉␊ |
990 | ␉␉␉␉␉if ((!(oem_asft)) && table[0]=='A' && table[1]=='S' && table[2]=='F' && table[3]=='!')␊ |
991 | ␉␉␉␉␉{␊ |
992 | ␉␉␉␉␉␉DBG("ASF! found\n");␊ |
993 | ␉␉␉␉␉␉if (new_asft)␊ |
994 | ␉␉␉␉␉␉{␊ |
995 | ␉␉␉␉␉␉␉xsdt_entries[i-dropoffset]=(uint32_t)new_asft;␊ |
996 | ␉␉␉␉␉␉␉asft_replaced=true;␊ |
997 | ␉␉␉␉␉␉}␊ |
998 | ␉␉␉␉␉␉continue;␊ |
999 | ␉␉␉␉␉}␉␉␉␉␉␊ |
1000 | ␉␉␉␉␉if ((!(oem_dmar)) && table[0]=='D' && table[1]=='M' && table[2]=='A' && table[3]=='R')␊ |
1001 | ␉␉␉␉␉{␊ |
1002 | ␉␉␉␉␉␉DBG("DMAR found\n");␊ |
1003 | ␉␉␉␉␉␉if (new_dmar)␊ |
1004 | ␉␉␉␉␉␉{␊ |
1005 | ␉␉␉␉␉␉␉xsdt_entries[i-dropoffset]=(uint32_t)new_dmar;␊ |
1006 | ␉␉␉␉␉␉␉dmar_replaced=true;␊ |
1007 | ␉␉␉␉␉␉}␊ |
1008 | ␉␉␉␉␉␉continue;␊ |
1009 | ␉␉␉␉␉}␉␉␉␉␉␊ |
1010 | ␉␉␉␉␉if ((!(oem_apic)) && table[0]=='A' && table[1]=='P' && table[2]=='I' && table[3]=='C')␊ |
1011 | ␉␉␉␉␉{␊ |
1012 | ␉␉␉␉␉␉DBG("APIC found\n");␊ |
1013 | ␉␉␉␉␉␉if (new_apic)␊ |
1014 | ␉␉␉␉␉␉{␊ |
1015 | ␉␉␉␉␉␉␉xsdt_entries[i-dropoffset]=(uint32_t)new_apic;␊ |
1016 | ␉␉␉␉␉␉␉apic_replaced=true;␊ |
1017 | ␉␉␉␉␉␉}␊ |
1018 | ␉␉␉␉␉␉continue;␊ |
1019 | ␉␉␉␉␉}␉␉␉␉␉␊ |
1020 | ␉␉␉␉␉if ((!(oem_mcfg)) && table[0]=='M' && table[1]=='C' && table[2]=='F' && table[3]=='G')␊ |
1021 | ␉␉␉␉␉{␊ |
1022 | ␉␉␉␉␉␉DBG("MCFG found\n");␊ |
1023 | ␉␉␉␉␉␉if (new_mcfg)␊ |
1024 | ␉␉␉␉␉␉{␊ |
1025 | ␉␉␉␉␉␉␉xsdt_entries[i-dropoffset]=(uint32_t)new_mcfg;␊ |
1026 | ␉␉␉␉␉␉␉mcfg_replaced=true;␊ |
1027 | ␉␉␉␉␉␉}␊ |
1028 | ␉␉␉␉␉␉continue;␊ |
1029 | ␉␉␉␉␉}␉␉␉␉␉␊ |
1030 | ␉␉␉␉␉if ((!(oem_ssdt)) && table[0]=='S' && table[1]=='S' && table[2]=='D' && table[3]=='T')␊ |
1031 | ␉␉␉␉␉{␊ |
1032 | ␉␉␉␉␉␉DBG("SSDT %d found", curssdt);␊ |
1033 | ␉␉␉␉␉␉if (new_ssdts[curssdt])␊ |
1034 | ␉␉␉␉␉␉{␊ |
1035 | ␉␉␉␉␉␉␉DBG(" and replaced");␊ |
1036 | ␉␉␉␉␉␉␉xsdt_entries[i-dropoffset]=(uint32_t)new_ssdts[curssdt];␊ |
1037 | ␉␉␉␉␉␉␉totssdt++;␊ |
1038 | ␉␉␉␉␉␉}␊ |
1039 | ␉␉␉␉␉␉DBG("\n");␊ |
1040 | ␉␉␉␉␉␉curssdt++;␊ |
1041 | ␉␉␉␉␉␉continue;␊ |
1042 | ␉␉␉␉␉}␉␉␉␉␉␊ |
1043 | ␉␉␉␉␉if (table[0]=='D' && table[1]=='S' && table[2]=='D' && table[3]=='T')␊ |
1044 | ␉␉␉␉␉{␊ |
1045 | ␉␉␉␉␉␉DBG("DSDT found\n");␊ |
1046 | ␊ |
1047 | ␉␉␉␉␉␉xsdt_entries[i-dropoffset]=(uint32_t)new_dsdt;␊ |
1048 | ␊ |
1049 | ␉␉␉␉␉␉DBG("TABLE %c%c%c%c@%x,",table[0],table[1],table[2],table[3],xsdt_entries[i]);␊ |
1050 | ␉␉␉␉␉␉␊ |
1051 | ␉␉␉␉␉␉continue;␊ |
1052 | ␉␉␉␉␉}␊ |
1053 | ␉␉␉␉␉if (table[0]=='F' && table[1]=='A' && table[2]=='C' && table[3]=='P')␊ |
1054 | ␉␉␉␉␉{␊ |
1055 | ␉␉␉␉␉␉struct acpi_2_fadt *fadt, *fadt_mod;␊ |
1056 | ␉␉␉␉␉␉fadt=(struct acpi_2_fadt *)(uint32_t)xsdt_entries[i];␊ |
1057 | ␊ |
1058 | ␉␉␉␉␉␉DBG("FADT found @%x,%x, Length %d\n",(uint32_t)(xsdt_entries[i]>>32),fadt, ␊ |
1059 | ␉␉␉␉␉␉␉␉ fadt->Length);␊ |
1060 | ␊ |
1061 | ␉␉␉␉␉␉if (!fadt || (uint64_t)xsdt_entries[i] >= 0xffffffff || fadt->Length>0x10000)␊ |
1062 | ␉␉␉␉␉␉{␊ |
1063 | ␉␉␉␉␉␉␉verbose("FADT incorrect or after 4GB. Dropping XSDT\n");␊ |
1064 | ␉␉␉␉␉␉␉goto drop_xsdt;␊ |
1065 | ␉␉␉␉␉␉}␊ |
1066 | ␊ |
1067 | ␉␉␉␉␉␉fadt_mod = patch_fadt(fadt, new_dsdt,update_acpi);␊ |
1068 | ␉␉␉␉␉␉xsdt_entries[i-dropoffset]=(uint32_t)fadt_mod;␊ |
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 | ␊ |
1075 | ␉␉␉␉␉DBG("TABLE %c%c%c%c@%x,",table[0],table[1],table[2],table[3],xsdt_entries[i]);␊ |
1076 | ␊ |
1077 | ␉␉␉␉}␊ |
1078 | ␊ |
1079 | ␉␉␉␉if ((!oem_hpet) && (!hpet_replaced))␊ |
1080 | ␉␉␉␉{␊ |
1081 | ␉␉␉␉␉if (new_hpet)␊ |
1082 | ␉␉␉␉␉{␊ |
1083 | ␉␉␉␉␉␉xsdt_entries[i-dropoffset]=(uint32_t)new_hpet;␊ |
1084 | ␉␉␉␉␉␉hpet_added=true;␊ |
1085 | ␉␉␉␉␉␉i++;␊ |
1086 | ␉␉␉␉␉}␊ |
1087 | ␉␉␉␉}␊ |
1088 | ␊ |
1089 | ␉␉␉␉if ((!oem_sbst) && (!sbst_replaced))␊ |
1090 | ␉␉␉␉{␊ |
1091 | ␉␉␉␉␉if (new_sbst)␊ |
1092 | ␉␉␉␉␉{␊ |
1093 | ␉␉␉␉␉␉xsdt_entries[i-dropoffset]=(uint32_t)new_sbst;␊ |
1094 | ␉␉␉␉␉␉sbst_added=true;␊ |
1095 | ␉␉␉␉␉␉i++;␊ |
1096 | ␉␉␉␉␉}␊ |
1097 | ␉␉␉␉}␊ |
1098 | ␊ |
1099 | ␉␉␉␉if ((!oem_ecdt) && (!ecdt_replaced))␊ |
1100 | ␉␉␉␉{␊ |
1101 | ␉␉␉␉␉if (new_ecdt)␊ |
1102 | ␉␉␉␉␉{␊ |
1103 | ␉␉␉␉␉␉xsdt_entries[i-dropoffset]=(uint32_t)new_ecdt;␊ |
1104 | ␉␉␉␉␉␉ecdt_added=true;␊ |
1105 | ␉␉␉␉␉␉i++;␊ |
1106 | ␉␉␉␉␉}␊ |
1107 | ␉␉␉␉}␊ |
1108 | ␊ |
1109 | ␉␉␉␉if ((!oem_asft) && (!asft_replaced))␊ |
1110 | ␉␉␉␉{␊ |
1111 | ␉␉␉␉␉if (new_asft)␊ |
1112 | ␉␉␉␉␉{␊ |
1113 | ␉␉␉␉␉␉xsdt_entries[i-dropoffset]=(uint32_t)new_asft;␊ |
1114 | ␉␉␉␉␉␉asft_added=true;␊ |
1115 | ␉␉␉␉␉␉i++;␊ |
1116 | ␉␉␉␉␉}␊ |
1117 | ␉␉␉␉}␊ |
1118 | ␊ |
1119 | ␉␉␉␉if ((!oem_dmar) && (!dmar_replaced))␊ |
1120 | ␉␉␉␉{␊ |
1121 | ␉␉␉␉␉if (new_dmar)␊ |
1122 | ␉␉␉␉␉{␊ |
1123 | ␉␉␉␉␉␉xsdt_entries[i-dropoffset]=(uint32_t)new_dmar;␊ |
1124 | ␉␉␉␉␉␉dmar_added=true;␊ |
1125 | ␉␉␉␉␉␉i++;␊ |
1126 | ␉␉␉␉␉}␊ |
1127 | ␉␉␉␉}␊ |
1128 | ␊ |
1129 | ␉␉␉␉if ((!oem_apic) && (!apic_replaced))␊ |
1130 | ␉␉␉␉{␊ |
1131 | ␉␉␉␉␉if (new_apic)␊ |
1132 | ␉␉␉␉␉{␊ |
1133 | ␉␉␉␉␉␉xsdt_entries[i-dropoffset]=(uint32_t)new_apic;␊ |
1134 | ␉␉␉␉␉␉apic_added=true;␊ |
1135 | ␉␉␉␉␉␉i++;␊ |
1136 | ␉␉␉␉␉}␊ |
1137 | ␉␉␉␉}␊ |
1138 | ␊ |
1139 | ␉␉␉␉if ((!oem_mcfg) && (!mcfg_replaced))␊ |
1140 | ␉␉␉␉{␊ |
1141 | ␉␉␉␉␉if (new_mcfg)␊ |
1142 | ␉␉␉␉␉{␊ |
1143 | ␉␉␉␉␉␉xsdt_entries[i-dropoffset]=(uint32_t)new_mcfg;␊ |
1144 | ␉␉␉␉␉␉mcfg_added=true;␊ |
1145 | ␉␉␉␉␉␉i++;␊ |
1146 | ␉␉␉␉␉}␊ |
1147 | ␉␉␉␉}␊ |
1148 | ␊ |
1149 | ␉␉␉␉if (!oem_ssdt)␊ |
1150 | ␉␉␉␉{ ␉␉␉␊ |
1151 | ␉␉␉␉␉while ((totssdt < loadtotssdt) && (curssdt < 14))␊ |
1152 | ␉␉␉␉␉{␊ |
1153 | ␉␉␉␉␉␉if (new_ssdts[curssdt])␊ |
1154 | ␉␉␉␉␉␉{␊ |
1155 | ␉␉␉␉␉␉␉DBG("adding SSDT %d\n", curssdt);␊ |
1156 | ␉␉␉␉␉␉␉xsdt_entries[i-dropoffset]=(uint32_t)new_ssdts[curssdt];␊ |
1157 | ␉␉␉␉␉␉␉totssdt++;␊ |
1158 | ␉␉␉␉␉␉␉newtotssdt++;␊ |
1159 | ␉␉␉␉␉␉␉i++;␊ |
1160 | ␉␉␉␉␉␉}␊ |
1161 | ␉␉␉␉␉␉curssdt++;␊ |
1162 | ␉␉␉␉␉}␊ |
1163 | ␉␉␉␉}␊ |
1164 | ␊ |
1165 | ␉␉␉␉// Correct the checksum of XSDT␊ |
1166 | ␉␉␉␉xsdt_mod->Length-=8*dropoffset;␊ |
1167 | ␉␉␉␉xsdt_mod->Length+=8*newtotssdt;␊ |
1168 | ␉␉␉␉if (hpet_added)␊ |
1169 | ␉␉␉␉␉xsdt_mod->Length+=8;␊ |
1170 | ␉␉␉␉if (sbst_added)␊ |
1171 | ␉␉␉␉␉xsdt_mod->Length+=8;␊ |
1172 | ␉␉␉␉if (ecdt_added)␊ |
1173 | ␉␉␉␉␉xsdt_mod->Length+=8;␊ |
1174 | ␉␉␉␉if (asft_added)␊ |
1175 | ␉␉␉␉␉xsdt_mod->Length+=8;␊ |
1176 | ␉␉␉␉if (dmar_added)␊ |
1177 | ␉␉␉␉␉xsdt_mod->Length+=8;␊ |
1178 | ␉␉␉␉if (apic_added)␊ |
1179 | ␉␉␉␉␉xsdt_mod->Length+=8;␊ |
1180 | ␉␉␉␉if (mcfg_added)␊ |
1181 | ␉␉␉␉␉xsdt_mod->Length+=8;␊ |
1182 | ␊ |
1183 | ␉␉␉␉xsdt_mod->Checksum=0;␊ |
1184 | ␉␉␉␉xsdt_mod->Checksum=256-checksum8(xsdt_mod,xsdt_mod->Length);␊ |
1185 | ␉␉␉}␊ |
1186 | ␉␉␉else␊ |
1187 | ␉␉␉{␊ |
1188 | ␉␉␉drop_xsdt:␊ |
1189 | ␊ |
1190 | ␉␉␉␉DBG("About to drop XSDT\n");␊ |
1191 | ␊ |
1192 | ␉␉␉␉/*FIXME: Now we just hope that if MacOS doesn't find XSDT it reverts to RSDT. ␊ |
1193 | ␉␉␉␉ * A Better strategy would be to generate␊ |
1194 | ␉␉␉␉ */␊ |
1195 | ␊ |
1196 | ␉␉␉␉rsdp_mod->XsdtAddress=0xffffffffffffffffLL;␊ |
1197 | ␉␉␉␉verbose("XSDT not found or XSDT incorrect\n");␊ |
1198 | ␉␉␉}␊ |
1199 | ␉␉}␊ |
1200 | ␊ |
1201 | ␉␉// Correct the checksum of RSDP ␊ |
1202 | ␊ |
1203 | ␉␉DBG("RSDP: Original checksum %d, ", rsdp_mod->Checksum);␊ |
1204 | ␊ |
1205 | ␉␉rsdp_mod->Checksum=0;␊ |
1206 | ␉␉rsdp_mod->Checksum=256-checksum8(rsdp_mod,20);␊ |
1207 | ␊ |
1208 | ␉␉DBG("New checksum %d\n", rsdp_mod->Checksum);␊ |
1209 | ␊ |
1210 | ␉␉if (version)␊ |
1211 | ␉␉{␊ |
1212 | ␉␉␉DBG("RSDP: Original extended checksum %d", rsdp_mod->ExtendedChecksum);␊ |
1213 | ␊ |
1214 | ␉␉␉rsdp_mod->ExtendedChecksum=0;␊ |
1215 | ␉␉␉rsdp_mod->ExtendedChecksum=256-checksum8(rsdp_mod,rsdp_mod->Length);␊ |
1216 | ␊ |
1217 | ␉␉␉DBG("New extended checksum %d\n", rsdp_mod->ExtendedChecksum);␊ |
1218 | ␊ |
1219 | ␉␉}␊ |
1220 | ␉␉␊ |
1221 | ␉␉verbose("Patched ACPI version %d DSDT\n", version+1);␊ |
1222 | ␉␉if (version)␊ |
1223 | ␉␉{␊ |
1224 | ␉/* XXX aserebln why uint32 cast if pointer is uint64 ? */␊ |
1225 | ␉␉␉acpi20_p = (uint32_t)rsdp_mod;␊ |
1226 | ␉␉␉acpi10_p = (uint32_t)rsdp_mod;␊ |
1227 | ␉␉␉addConfigurationTable(&gEfiAcpi20TableGuid, &acpi20_p, "ACPI_20");␊ |
1228 | ␉␉␉addConfigurationTable(&gEfiAcpiTableGuid, &acpi10_p, "ACPI");␊ |
1229 | ␉␉}␊ |
1230 | ␉␉else␊ |
1231 | ␉␉{␊ |
1232 | ␉/* XXX aserebln why uint32 cast if pointer is uint64 ? */␊ |
1233 | ␉␉␉acpi10_p = (uint32_t)rsdp_mod;␊ |
1234 | ␉␉␉addConfigurationTable(&gEfiAcpiTableGuid, &acpi10_p, "ACPI");␊ |
1235 | ␉␉}␊ |
1236 | ␉}␊ |
1237 | #if DEBUG_DSDT␊ |
1238 | ␉printf("Press a key to continue... (DEBUG_DSDT)\n");␊ |
1239 | ␉getc();␊ |
1240 | #endif␊ |
1241 | ␉return 1;␊ |
1242 | }␊ |
1243 | |