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