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