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 | void *loadACPITable (const char *filename)␊ |
77 | {␊ |
78 | ␉void *tableAddr;␊ |
79 | ␉int fd;␊ |
80 | ␉char dirspec[512];␊ |
81 | ␊ |
82 | ␉// Check booting partition␊ |
83 | ␉sprintf(dirspec,"%s",filename);␊ |
84 | ␉fd=open (dirspec,0);␊ |
85 | ␉if (fd<0)␊ |
86 | ␉{␉// Check Extra on booting partition␊ |
87 | ␉␉sprintf(dirspec,"/Extra/%s",filename);␊ |
88 | ␉␉fd=open (dirspec,0);␊ |
89 | ␉␉if (fd<0)␊ |
90 | ␉␉{␉// Fall back to booter partition␊ |
91 | ␉␉␉sprintf(dirspec,"bt(0,0)/Extra/%s",filename);␊ |
92 | ␉␉␉fd=open (dirspec,0);␊ |
93 | ␉␉␉if (fd<0)␊ |
94 | ␉␉␉{␊ |
95 | ␉␉␉␉verbose("ACPI Table not found: %s\n", filename);␊ |
96 | ␉␉␉␉return NULL;␊ |
97 | ␉␉␉}␊ |
98 | ␉␉}␊ |
99 | ␉}␊ |
100 | ␊ |
101 | ␉tableAddr=(void*)AllocateKernelMemory(file_size (fd));␊ |
102 | ␉if (tableAddr)␊ |
103 | ␉{␊ |
104 | ␉␉if (read (fd, tableAddr, file_size (fd))!=file_size (fd))␊ |
105 | ␉␉{␊ |
106 | ␉␉␉printf("Couldn't read table %s\n",dirspec);␊ |
107 | ␉␉␉free (tableAddr);␊ |
108 | ␉␉␉close (fd);␊ |
109 | ␉␉␉return NULL;␊ |
110 | ␉␉}␊ |
111 | ␊ |
112 | ␉␉DBG("Table %s read and stored at: %x\n", dirspec, tableAddr);␊ |
113 | ␉␉close (fd);␊ |
114 | ␉␉return tableAddr;␊ |
115 | ␉}␊ |
116 | ␊ |
117 | ␉printf("Couldn't allocate memory for table %s\n", dirspec);␊ |
118 | ␉close (fd);␊ |
119 | ␉return NULL;␊ |
120 | }␊ |
121 | ␊ |
122 | struct acpi_2_fadt *␊ |
123 | patch_fadt(struct acpi_2_fadt *fadt, void *new_dsdt)␊ |
124 | {␊ |
125 | ␊ |
126 | ␉struct acpi_2_fadt *fadt_mod;␊ |
127 | ␉bool fadt_rev2_needed = false;␊ |
128 | ␉bool fix_restart;␊ |
129 | ␊ |
130 | ␉// Restart Fix␊ |
131 | ␉if (Platform.CPU.Vendor == 0x756E6547) {␉/* Intel */␊ |
132 | ␉␉fix_restart = true;␊ |
133 | ␉␉getBoolForKey(kRestartFix, &fix_restart, &bootInfo->bootConfig);␊ |
134 | ␉} else {␊ |
135 | ␉␉verbose ("Not an Intel platform: Restart Fix not applied !!!\n");␊ |
136 | ␉␉fix_restart = false;␊ |
137 | ␉}␊ |
138 | ␊ |
139 | ␉if (fix_restart) fadt_rev2_needed = true;␊ |
140 | ␊ |
141 | ␉// Allocate new fadt table␊ |
142 | ␉if (fadt->Length < 0x84 && fadt_rev2_needed)␊ |
143 | ␉{␊ |
144 | ␉␉fadt_mod=(struct acpi_2_fadt *)AllocateKernelMemory(0x84);␊ |
145 | ␉␉memcpy(fadt_mod, fadt, fadt->Length);␊ |
146 | ␉␉fadt_mod->Length = 0x84;␊ |
147 | ␉␉fadt_mod->Revision = 0x02; // FADT rev 2 (ACPI 1.0B MS extensions)␊ |
148 | ␉}␊ |
149 | ␉else␊ |
150 | ␉{␊ |
151 | ␉␉fadt_mod=(struct acpi_2_fadt *)AllocateKernelMemory(fadt->Length);␊ |
152 | ␉␉memcpy(fadt_mod, fadt, fadt->Length);␊ |
153 | ␉}␊ |
154 | ␊ |
155 | ␉// Set PM_Profile from System-type␊ |
156 | ␉if (fadt_mod->PM_Profile != Platform.Type) {␊ |
157 | ␉␉verbose("FADT: changing PM_Profile from 0x%02x to 0x%02x\n", fadt_mod->PM_Profile, Platform.Type);␊ |
158 | ␉␉fadt_mod->PM_Profile = Platform.Type;␊ |
159 | ␉}␊ |
160 | ␊ |
161 | ␉// Patch FADT to fix restart␊ |
162 | ␉if (fix_restart)␊ |
163 | ␉{␊ |
164 | ␉␉fadt_mod->Flags|= 0x400;␊ |
165 | ␉␉fadt_mod->Reset_SpaceID␉␉= 0x01; // System I/O␊ |
166 | ␉␉fadt_mod->Reset_BitWidth␉= 0x08; // 1 byte␊ |
167 | ␉␉fadt_mod->Reset_BitOffset␉= 0x00; // Offset 0␊ |
168 | ␉␉fadt_mod->Reset_AccessWidth␉= 0x01; // Byte access␊ |
169 | ␉␉fadt_mod->Reset_Address␉␉= 0x0cf9; // Address of the register␊ |
170 | ␉␉fadt_mod->Reset_Value␉␉= 0x06; // Value to write to reset the system␊ |
171 | ␉␉verbose("FADT: Restart Fix applied !\n");␊ |
172 | ␉}␊ |
173 | ␊ |
174 | ␉// Patch DSDT Address␊ |
175 | ␉DBG("DSDT: Old @%x,%x, ",fadt_mod->DSDT,fadt_mod->X_DSDT);␊ |
176 | ␊ |
177 | ␉fadt_mod->DSDT=(uint32_t)new_dsdt;␊ |
178 | ␉if ((uint32_t)(&(fadt_mod->X_DSDT))-(uint32_t)fadt_mod+8<=fadt_mod->Length)␊ |
179 | ␉␉fadt_mod->X_DSDT=(uint32_t)new_dsdt;␊ |
180 | ␊ |
181 | ␉DBG("New @%x,%x\n",fadt_mod->DSDT,fadt_mod->X_DSDT);␊ |
182 | ␊ |
183 | ␉// Correct the checksum␊ |
184 | ␉fadt_mod->Checksum=0;␊ |
185 | ␉fadt_mod->Checksum=256-checksum8(fadt_mod,fadt_mod->Length);␊ |
186 | ␊ |
187 | ␉return fadt_mod;␊ |
188 | }␊ |
189 | ␊ |
190 | /* Setup ACPI without replacing DSDT. */␊ |
191 | int setupAcpiNoMod()␊ |
192 | {␊ |
193 | //␉addConfigurationTable(&gEfiAcpiTableGuid, getAddressOfAcpiTable(), "ACPI");␊ |
194 | //␉addConfigurationTable(&gEfiAcpi20TableGuid, getAddressOfAcpi20Table(), "ACPI_20");␊ |
195 | ␉/* XXX aserebln why uint32 cast if pointer is uint64 ? */␊ |
196 | ␉acpi10_p = (uint32_t)getAddressOfAcpiTable();␊ |
197 | ␉acpi20_p = (uint32_t)getAddressOfAcpi20Table();␊ |
198 | ␉addConfigurationTable(&gEfiAcpiTableGuid, &acpi10_p, "ACPI");␊ |
199 | ␉if(acpi20_p) addConfigurationTable(&gEfiAcpi20TableGuid, &acpi20_p, "ACPI_20");␊ |
200 | ␉return 1;␊ |
201 | }␊ |
202 | ␊ |
203 | /* Setup ACPI. Replace DSDT if DSDT.aml is found */␊ |
204 | int setupAcpi(void)␊ |
205 | {␊ |
206 | ␉int version;␊ |
207 | ␉void *new_dsdt;␊ |
208 | ␉const char *dsdt_filename;␊ |
209 | ␊ |
210 | ␉char dirspec[512];␊ |
211 | ␊ |
212 | ␉int fd;␊ |
213 | ␊ |
214 | ␉int len;␊ |
215 | ␉bool tmp;␊ |
216 | ␉bool drop_ssdt;␊ |
217 | ␉bool fix_restart;␊ |
218 | ␊ |
219 | ␉if (!getValueForKey(kDSDT, &dsdt_filename, &len, &bootInfo->bootConfig))␊ |
220 | ␉␉dsdt_filename="DSDT.aml";␊ |
221 | ␉␊ |
222 | ␉// Load replacement DSDT␊ |
223 | ␉new_dsdt=loadACPITable(dsdt_filename);␊ |
224 | ␉if (!new_dsdt)␊ |
225 | ␉{␊ |
226 | ␉␉close(fd);␊ |
227 | ␉␉return setupAcpiNoMod();␊ |
228 | ␉}␊ |
229 | ␊ |
230 | ␉DBG("New DSDT Loaded in memory\n");␊ |
231 | ␉␊ |
232 | ␉{␊ |
233 | ␉␉bool tmp;␊ |
234 | ␉␉drop_ssdt=getBoolForKey(kDropSSDT, &tmp, &bootInfo->bootConfig)&&tmp;␊ |
235 | ␉}␊ |
236 | ␊ |
237 | ␉// Do the same procedure for both versions of ACPI␊ |
238 | ␉for (version=0; version<2; version++) {␊ |
239 | ␉␉struct acpi_2_rsdp *rsdp, *rsdp_mod;␊ |
240 | ␉␉struct acpi_2_rsdt *rsdt, *rsdt_mod;␊ |
241 | ␉␉int rsdplength;␊ |
242 | ␉␉␊ |
243 | ␉␉// Find original rsdp␊ |
244 | ␉␉rsdp=(struct acpi_2_rsdp *)(version?getAddressOfAcpi20Table():getAddressOfAcpiTable());␊ |
245 | ␉␉if (!rsdp)␊ |
246 | ␉␉{␊ |
247 | ␉␉␉DBG("No ACPI version %d found. Ignoring\n", version+1);␊ |
248 | ␉␉␉if (version)␊ |
249 | ␉␉␉␉addConfigurationTable(&gEfiAcpi20TableGuid, NULL, "ACPI_20");␊ |
250 | ␉␉␉else␊ |
251 | ␉␉␉␉addConfigurationTable(&gEfiAcpiTableGuid, NULL, "ACPI");␊ |
252 | ␉␉␉continue;␊ |
253 | ␉␉}␊ |
254 | ␉␉rsdplength=version?rsdp->Length:20;␊ |
255 | ␊ |
256 | ␉␉DBG("RSDP version %d found @%x. Length=%d\n",version+1,rsdp,rsdplength);␊ |
257 | ␊ |
258 | ␉␉/* FIXME: no check that memory allocation succeeded ␊ |
259 | ␉␉ * Copy and patch RSDP,RSDT, XSDT and FADT␊ |
260 | ␉␉ * For more info see ACPI Specification pages 110 and following␊ |
261 | ␉␉ */␊ |
262 | ␊ |
263 | ␉␉rsdp_mod=(struct acpi_2_rsdp *) AllocateKernelMemory(rsdplength);␊ |
264 | ␉␉memcpy(rsdp_mod, rsdp, rsdplength); ␊ |
265 | ␉␉rsdt=(struct acpi_2_rsdt *)(rsdp->RsdtAddress);␊ |
266 | ␊ |
267 | ␉␉DBG("RSDT @%x, Length %d\n",rsdt, rsdt->Length);␊ |
268 | ␉␉␊ |
269 | ␉␉if (rsdt && (uint32_t)rsdt !=0xffffffff && rsdt->Length<0x10000)␊ |
270 | ␉␉{␊ |
271 | ␉␉␉uint32_t *rsdt_entries;␊ |
272 | ␉␉␉int rsdt_entries_num;␊ |
273 | ␉␉␉int dropoffset=0, i;␊ |
274 | ␉␉␉␊ |
275 | ␉␉␉rsdt_mod=(struct acpi_2_rsdt *)AllocateKernelMemory(rsdt->Length); ␊ |
276 | ␉␉␉memcpy (rsdt_mod, rsdt, rsdt->Length);␊ |
277 | ␉␉␉rsdp_mod->RsdtAddress=(uint32_t)rsdt_mod;␊ |
278 | ␉␉␉rsdt_entries_num=(rsdt_mod->Length-sizeof(struct acpi_2_rsdt))/4;␊ |
279 | ␉␉␉rsdt_entries=(uint32_t *)(rsdt_mod+1);␊ |
280 | ␉␉␉for (i=0;i<rsdt_entries_num;i++)␊ |
281 | ␉␉␉{␊ |
282 | ␉␉␉␉char *table=(char *)(rsdt_entries[i]);␊ |
283 | ␉␉␉␉if (!table)␊ |
284 | ␉␉␉␉␉continue;␊ |
285 | ␊ |
286 | ␉␉␉␉DBG("TABLE %c%c%c%c,",table[0],table[1],table[2],table[3]);␊ |
287 | ␊ |
288 | ␉␉␉␉rsdt_entries[i-dropoffset]=rsdt_entries[i];␊ |
289 | ␉␉␉␉if (drop_ssdt && table[0]=='S' && table[1]=='S' && table[2]=='D' && table[3]=='T')␊ |
290 | ␉␉␉␉{␊ |
291 | ␉␉␉␉␉dropoffset++;␊ |
292 | ␉␉␉␉␉continue;␊ |
293 | ␉␉␉␉}␊ |
294 | ␉␉␉␉if (table[0]=='D' && table[1]=='S' && table[2]=='D' && table[3]=='T')␊ |
295 | ␉␉␉␉{␊ |
296 | ␉␉␉␉␉DBG("DSDT found\n");␊ |
297 | ␉␉␉␉␉rsdt_entries[i-dropoffset]=(uint32_t)new_dsdt;␊ |
298 | ␉␉␉␉␉continue;␊ |
299 | ␉␉␉␉}␊ |
300 | ␉␉␉␉if (table[0]=='F' && table[1]=='A' && table[2]=='C' && table[3]=='P')␊ |
301 | ␉␉␉␉{␊ |
302 | ␉␉␉␉␉struct acpi_2_fadt *fadt, *fadt_mod;␊ |
303 | ␉␉␉␉␉fadt=(struct acpi_2_fadt *)rsdt_entries[i];␊ |
304 | ␊ |
305 | ␉␉␉␉␉DBG("FADT found @%x, Length %d\n",fadt, fadt->Length);␊ |
306 | ␊ |
307 | ␉␉␉␉␉if (!fadt || (uint32_t)fadt == 0xffffffff || fadt->Length>0x10000)␊ |
308 | ␉␉␉␉␉{␊ |
309 | ␉␉␉␉␉␉printf("FADT incorrect. Not modified\n");␊ |
310 | ␉␉␉␉␉␉continue;␊ |
311 | ␉␉␉␉␉}␊ |
312 | ␉␉␉␉␉␊ |
313 | ␉␉␉␉␉fadt_mod = patch_fadt(fadt, new_dsdt);␊ |
314 | ␉␉␉␉␉rsdt_entries[i-dropoffset]=(uint32_t)fadt_mod;␊ |
315 | ␉␉␉␉␉continue;␊ |
316 | ␉␉␉␉}␊ |
317 | ␉␉␉}␊ |
318 | ␉␉␉DBG("\n");␊ |
319 | ␊ |
320 | ␉␉␉// Correct the checksum of RSDT␊ |
321 | ␉␉␉rsdt_mod->Length-=4*dropoffset;␊ |
322 | ␊ |
323 | ␉␉␉DBG("RSDT: Original checksum %d, ", rsdt_mod->Checksum);␊ |
324 | ␊ |
325 | ␉␉␉rsdt_mod->Checksum=0;␊ |
326 | ␉␉␉rsdt_mod->Checksum=256-checksum8(rsdt_mod,rsdt_mod->Length);␊ |
327 | ␊ |
328 | ␉␉␉DBG("New checksum %d at %x\n", rsdt_mod->Checksum,rsdt_mod);␊ |
329 | ␉␉}␊ |
330 | ␉␉else␊ |
331 | ␉␉{␊ |
332 | ␉␉␉rsdp_mod->RsdtAddress=0;␊ |
333 | ␉␉␉printf("RSDT not found or RSDT incorrect\n");␊ |
334 | ␉␉}␊ |
335 | ␊ |
336 | ␉␉if (version)␊ |
337 | ␉␉{␊ |
338 | ␉␉␉struct acpi_2_xsdt *xsdt, *xsdt_mod;␊ |
339 | ␊ |
340 | ␉␉␉// FIXME: handle 64-bit address correctly␊ |
341 | ␊ |
342 | ␉␉␉xsdt=(struct acpi_2_xsdt*) ((uint32_t)rsdp->XsdtAddress);␊ |
343 | ␉␉␉DBG("XSDT @%x;%x, Length=%d\n", (uint32_t)(rsdp->XsdtAddress>>32),(uint32_t)rsdp->XsdtAddress,␊ |
344 | ␉␉␉␉␉xsdt->Length);␊ |
345 | ␉␉␉if (xsdt && (uint64_t)rsdp->XsdtAddress<0xffffffff && xsdt->Length<0x10000)␊ |
346 | ␉␉␉{␊ |
347 | ␉␉␉␉uint64_t *xsdt_entries;␊ |
348 | ␉␉␉␉int xsdt_entries_num, i;␊ |
349 | ␉␉␉␉int dropoffset=0;␊ |
350 | ␉␉␉␉␊ |
351 | ␉␉␉␉xsdt_mod=(struct acpi_2_xsdt*)AllocateKernelMemory(xsdt->Length); ␊ |
352 | ␉␉␉␉memcpy(xsdt_mod, xsdt, xsdt->Length);␊ |
353 | ␉␉␉␉rsdp_mod->XsdtAddress=(uint32_t)xsdt_mod;␊ |
354 | ␉␉␉␉xsdt_entries_num=(xsdt_mod->Length-sizeof(struct acpi_2_xsdt))/8;␊ |
355 | ␉␉␉␉xsdt_entries=(uint64_t *)(xsdt_mod+1);␊ |
356 | ␉␉␉␉for (i=0;i<xsdt_entries_num;i++)␊ |
357 | ␉␉␉␉{␊ |
358 | ␉␉␉␉␉char *table=(char *)((uint32_t)(xsdt_entries[i]));␊ |
359 | ␉␉␉␉␉if (!table)␊ |
360 | ␉␉␉␉␉␉continue;␊ |
361 | ␉␉␉␉␉xsdt_entries[i-dropoffset]=xsdt_entries[i];␊ |
362 | ␉␉␉␉␉if (drop_ssdt && table[0]=='S' && table[1]=='S' && table[2]=='D' && table[3]=='T')␊ |
363 | ␉␉␉␉␉{␊ |
364 | ␉␉␉␉␉␉dropoffset++;␊ |
365 | ␉␉␉␉␉␉continue;␊ |
366 | ␉␉␉␉␉}␉␉␉␉␉␊ |
367 | ␉␉␉␉␉if (table[0]=='D' && table[1]=='S' && table[2]=='D' && table[3]=='T')␊ |
368 | ␉␉␉␉␉{␊ |
369 | ␉␉␉␉␉␉DBG("DSDT found\n");␊ |
370 | ␊ |
371 | ␉␉␉␉␉␉xsdt_entries[i-dropoffset]=(uint32_t)new_dsdt;␊ |
372 | ␊ |
373 | ␉␉␉␉␉␉DBG("TABLE %c%c%c%c@%x,",table[0],table[1],table[2],table[3],xsdt_entries[i]);␊ |
374 | ␉␉␉␉␉␉␊ |
375 | ␉␉␉␉␉␉continue;␊ |
376 | ␉␉␉␉␉}␊ |
377 | ␉␉␉␉␉if (table[0]=='F' && table[1]=='A' && table[2]=='C' && table[3]=='P')␊ |
378 | ␉␉␉␉␉{␊ |
379 | ␉␉␉␉␉␉struct acpi_2_fadt *fadt, *fadt_mod;␊ |
380 | ␉␉␉␉␉␉fadt=(struct acpi_2_fadt *)(uint32_t)xsdt_entries[i];␊ |
381 | ␊ |
382 | ␉␉␉␉␉␉DBG("FADT found @%x,%x, Length %d\n",(uint32_t)(xsdt_entries[i]>>32),fadt, ␊ |
383 | ␉␉␉␉␉␉␉␉ fadt->Length);␊ |
384 | ␊ |
385 | ␉␉␉␉␉␉if (!fadt || (uint64_t)xsdt_entries[i] >= 0xffffffff || fadt->Length>0x10000)␊ |
386 | ␉␉␉␉␉␉{␊ |
387 | ␉␉␉␉␉␉␉verbose("FADT incorrect or after 4GB. Dropping XSDT\n");␊ |
388 | ␉␉␉␉␉␉␉goto drop_xsdt;␊ |
389 | ␉␉␉␉␉␉}␊ |
390 | ␊ |
391 | ␉␉␉␉␉␉fadt_mod = patch_fadt(fadt, new_dsdt);␊ |
392 | ␉␉␉␉␉␉xsdt_entries[i-dropoffset]=(uint32_t)fadt_mod;␊ |
393 | ␊ |
394 | ␉␉␉␉␉␉DBG("TABLE %c%c%c%c@%x,",table[0],table[1],table[2],table[3],xsdt_entries[i]);␊ |
395 | ␊ |
396 | ␉␉␉␉␉␉continue;␊ |
397 | ␉␉␉␉␉}␊ |
398 | ␊ |
399 | ␉␉␉␉␉DBG("TABLE %c%c%c%c@%x,",table[0],table[1],table[2],table[3],xsdt_entries[i]);␊ |
400 | ␊ |
401 | ␉␉␉␉}␊ |
402 | ␊ |
403 | ␉␉␉␉// Correct the checksum of XSDT␊ |
404 | ␉␉␉␉xsdt_mod->Length-=8*dropoffset;␊ |
405 | ␉␉␉␉xsdt_mod->Checksum=0;␊ |
406 | ␉␉␉␉xsdt_mod->Checksum=256-checksum8(xsdt_mod,xsdt_mod->Length);␊ |
407 | ␉␉␉}␊ |
408 | ␉␉␉else␊ |
409 | ␉␉␉{␊ |
410 | ␉␉␉drop_xsdt:␊ |
411 | ␊ |
412 | ␉␉␉␉DBG("About to drop XSDT\n");␊ |
413 | ␊ |
414 | ␉␉␉␉/*FIXME: Now we just hope that if MacOS doesn't find XSDT it reverts to RSDT. ␊ |
415 | ␉␉␉␉ * A Better strategy would be to generate␊ |
416 | ␉␉␉␉ */␊ |
417 | ␊ |
418 | ␉␉␉␉rsdp_mod->XsdtAddress=0xffffffffffffffffLL;␊ |
419 | ␉␉␉␉verbose("XSDT not found or XSDT incorrect\n");␊ |
420 | ␉␉␉}␊ |
421 | ␉␉}␊ |
422 | ␊ |
423 | ␉␉// Correct the checksum of RSDP ␊ |
424 | ␊ |
425 | ␉␉DBG("RSDP: Original checksum %d, ", rsdp_mod->Checksum);␊ |
426 | ␊ |
427 | ␉␉rsdp_mod->Checksum=0;␊ |
428 | ␉␉rsdp_mod->Checksum=256-checksum8(rsdp_mod,20);␊ |
429 | ␊ |
430 | ␉␉DBG("New checksum %d\n", rsdp_mod->Checksum);␊ |
431 | ␊ |
432 | ␉␉if (version)␊ |
433 | ␉␉{␊ |
434 | ␉␉␉DBG("RSDP: Original extended checksum %d", rsdp_mod->ExtendedChecksum);␊ |
435 | ␊ |
436 | ␉␉␉rsdp_mod->ExtendedChecksum=0;␊ |
437 | ␉␉␉rsdp_mod->ExtendedChecksum=256-checksum8(rsdp_mod,rsdp_mod->Length);␊ |
438 | ␊ |
439 | ␉␉␉DBG("New extended checksum %d\n", rsdp_mod->ExtendedChecksum);␊ |
440 | ␊ |
441 | ␉␉}␊ |
442 | ␉␉␊ |
443 | ␉␉verbose("Patched ACPI version %d DSDT\n", version+1);␊ |
444 | ␉␉if (version)␊ |
445 | ␉␉{␊ |
446 | ␉/* XXX aserebln why uint32 cast if pointer is uint64 ? */␊ |
447 | ␉␉␉acpi20_p = (uint32_t)rsdp_mod;␊ |
448 | ␉␉␉addConfigurationTable(&gEfiAcpi20TableGuid, &acpi20_p, "ACPI_20");␊ |
449 | ␉␉}␊ |
450 | ␉␉else␊ |
451 | ␉␉{␊ |
452 | ␉/* XXX aserebln why uint32 cast if pointer is uint64 ? */␊ |
453 | ␉␉␉acpi10_p = (uint32_t)rsdp_mod;␊ |
454 | ␉␉␉addConfigurationTable(&gEfiAcpiTableGuid, &acpi10_p, "ACPI");␊ |
455 | ␉␉}␊ |
456 | ␉}␊ |
457 | #if DEBUG_DSDT␊ |
458 | ␉printf("Press a key to continue... (DEBUG_DSDT)\n");␊ |
459 | ␉getc();␊ |
460 | #endif␊ |
461 | ␉return 1;␊ |
462 | }␊ |
463 | |