1 | /*␊ |
2 | * Copyright 2008 mackerintel␊ |
3 | */␊ |
4 | ␊ |
5 | #include "libsaio.h"␊ |
6 | #include "bootstruct.h"␊ |
7 | #include "acpi.h"␊ |
8 | #include "efi_tables.h"␊ |
9 | #include "fake_efi.h"␊ |
10 | #include "dsdt_patcher.h"␊ |
11 | ␊ |
12 | #ifndef DEBUG_DSDT␊ |
13 | #define DEBUG_DSDT 0␊ |
14 | #endif␊ |
15 | ␊ |
16 | #if DEBUG_DSDT==2␊ |
17 | #define DBG(x...) {printf(x); sleep(1);}␊ |
18 | #elif DEBUG_DSDT==1␊ |
19 | #define DBG(x...) printf(x)␊ |
20 | #else␊ |
21 | #define DBG(x...)␊ |
22 | #endif␊ |
23 | ␊ |
24 | /* Gets the ACPI 1.0 RSDP address */␊ |
25 | static struct acpi_2_rsdp* getAddressOfAcpiTable()␊ |
26 | {␊ |
27 | /* TODO: Before searching the BIOS space we are supposed to search the first 1K of the EBDA */␊ |
28 | ␉␊ |
29 | void *acpi_addr = (void*)ACPI_RANGE_START;␊ |
30 | for(; acpi_addr <= (void*)ACPI_RANGE_END; acpi_addr += 16)␊ |
31 | {␊ |
32 | if(*(uint64_t *)acpi_addr == ACPI_SIGNATURE_UINT64_LE)␊ |
33 | {␊ |
34 | uint8_t csum = checksum8(acpi_addr, 20);␊ |
35 | if(csum == 0)␊ |
36 | {␊ |
37 | // Only return the table if it is a true version 1.0 table (Revision 0)␊ |
38 | if(((struct acpi_2_rsdp*)acpi_addr)->Revision == 0)␊ |
39 | return acpi_addr;␊ |
40 | }␊ |
41 | }␊ |
42 | }␊ |
43 | return NULL;␊ |
44 | }␊ |
45 | ␊ |
46 | /* Gets the ACPI 2.0 RSDP address */␊ |
47 | static struct acpi_2_rsdp* getAddressOfAcpi20Table()␊ |
48 | {␊ |
49 | /* TODO: Before searching the BIOS space we are supposed to search the first 1K of the EBDA */␊ |
50 | ␉␊ |
51 | void *acpi_addr = (void*)ACPI_RANGE_START;␊ |
52 | for(; acpi_addr <= (void*)ACPI_RANGE_END; acpi_addr += 16)␊ |
53 | {␊ |
54 | if(*(uint64_t *)acpi_addr == ACPI_SIGNATURE_UINT64_LE)␊ |
55 | {␊ |
56 | uint8_t csum = checksum8(acpi_addr, 20);␊ |
57 | ␊ |
58 | /* Only assume this is a 2.0 or better table if the revision is greater than 0␊ |
59 | * NOTE: ACPI 3.0 spec only seems to say that 1.0 tables have revision 1␊ |
60 | * and that the current revision is 2.. I am going to assume that rev > 0 is 2.0.␊ |
61 | */␊ |
62 | ␊ |
63 | if(csum == 0 && (((struct acpi_2_rsdp*)acpi_addr)->Revision > 0))␊ |
64 | {␊ |
65 | uint8_t csum2 = checksum8(acpi_addr, sizeof(struct acpi_2_rsdp));␊ |
66 | if(csum2 == 0)␊ |
67 | return acpi_addr;␊ |
68 | }␊ |
69 | }␊ |
70 | }␊ |
71 | return NULL;␊ |
72 | }␊ |
73 | ␊ |
74 | void *loadACPITable (const char *filename)␊ |
75 | {␊ |
76 | ␉void *kernelAddr;␊ |
77 | ␉int fd;␊ |
78 | ␉char dirspec[512];␊ |
79 | ␉␊ |
80 | ␉// Check booting partition␊ |
81 | ␉sprintf(dirspec,"%s",filename);␊ |
82 | ␉fd=open (dirspec,0);␊ |
83 | ␉if (fd<0)␊ |
84 | ␉{␉// Check Extra on booting partition␊ |
85 | ␉␉sprintf(dirspec,"/Extra/%s",filename);␊ |
86 | ␉␉fd=open (dirspec,0);␊ |
87 | ␉␉if (fd<0)␊ |
88 | ␉␉{␉// Fall back to booter partition␊ |
89 | ␉␉␉sprintf(dirspec,"bt(0,0)/Extra/%s",filename);␊ |
90 | ␉␉␉fd=open (dirspec,0);␊ |
91 | ␉␉␉if (fd<0)␊ |
92 | ␉␉␉{␊ |
93 | ␉␉␉␉verbose("ACPI Table not found: %s\n", filename);␊ |
94 | ␉␉␉␉return NULL;␊ |
95 | ␉␉␉}␊ |
96 | ␉␉}␊ |
97 | ␉}␊ |
98 | ␉␊ |
99 | ␉kernelAddr=(void*)AllocateKernelMemory(file_size (fd));␊ |
100 | ␉if (kernelAddr)␊ |
101 | ␉{␊ |
102 | ␉␉read (fd, kernelAddr, file_size (fd));␊ |
103 | ␉␉DBG("File read and stored at: %x\n", kernelAddr);␊ |
104 | ␉␉close (fd);␊ |
105 | ␉␉return kernelAddr;␊ |
106 | ␉}␊ |
107 | ␉close (fd);␉␉␉␉␊ |
108 | ␉return NULL;␉␊ |
109 | }␉␊ |
110 | ␊ |
111 | ␊ |
112 | ␊ |
113 | /* Setup ACPI without replacing DSDT. */␊ |
114 | int setupAcpiNoMod()␊ |
115 | {␊ |
116 | //␉addConfigurationTable(&gEfiAcpiTableGuid, getAddressOfAcpiTable(), "ACPI");␊ |
117 | //␉addConfigurationTable(&gEfiAcpi20TableGuid, getAddressOfAcpi20Table(), "ACPI_20");␊ |
118 | ␉acpi10_p = (uint32_t)getAddressOfAcpiTable();␊ |
119 | ␉acpi20_p = (uint32_t)getAddressOfAcpi20Table();␊ |
120 | ␉addConfigurationTable(&gEfiAcpiTableGuid, &acpi10_p, "ACPI");␊ |
121 | ␉if(acpi20_p) addConfigurationTable(&gEfiAcpi20TableGuid, &acpi20_p, "ACPI_20");␊ |
122 | ␉return 1;␊ |
123 | }␊ |
124 | ␊ |
125 | /* Setup ACPI. Replace DSDT if DSDT.aml is found */␊ |
126 | int setupAcpi()␊ |
127 | {␊ |
128 | ␉int version;␊ |
129 | ␉void *new_dsdt;␊ |
130 | ␉const char *dsdt_filename;␊ |
131 | ␉const char *facp_filename;␊ |
132 | ␉int len;␊ |
133 | ␉boolean_t drop_ssdt=NO;␊ |
134 | ␉boolean_t FixRestart=NO;␊ |
135 | ␊ |
136 | ␉//DBG("Enter setupACPI\n");␊ |
137 | ␊ |
138 | ␉if (!getValueForKey("DSDT", &dsdt_filename, &len, &bootInfo->bootConfig))␊ |
139 | ␉␉dsdt_filename="DSDT.aml";␊ |
140 | ␉␊ |
141 | ␉// Load replacement DSDT␊ |
142 | ␉new_dsdt=loadACPITable(dsdt_filename);␊ |
143 | ␉if (!new_dsdt)␊ |
144 | ␉{ ␊ |
145 | ␉␉return setupAcpiNoMod();␊ |
146 | ␉}␉␊ |
147 | ␉DBG("New DSDT Loaded in memory\n");␊ |
148 | ␉␊ |
149 | ␉BOOL tmp;␊ |
150 | ␉drop_ssdt=getBoolForKey("DropSSDT",&tmp, &bootInfo->bootConfig)&&tmp;␊ |
151 | ␉FixRestart=getBoolForKey("RestartFix",&tmp, &bootInfo->bootConfig)&&tmp;␊ |
152 | ␉␊ |
153 | ␉␊ |
154 | ␉// Do the same procedure for both versions of ACPI␊ |
155 | ␉for (version=0;version<2;version++)␊ |
156 | ␉{␊ |
157 | ␉␉struct acpi_2_rsdp *rsdp, *rsdp_mod;␊ |
158 | ␉␉struct acpi_2_rsdt *rsdt, *rsdt_mod;␊ |
159 | ␉␉int rsdplength;␊ |
160 | ␉␉␊ |
161 | ␉␉// Find original rsdp␊ |
162 | ␉␉rsdp=(struct acpi_2_rsdp *)(version?getAddressOfAcpi20Table():getAddressOfAcpiTable());␊ |
163 | ␉␉if (!rsdp)␊ |
164 | ␉␉{␊ |
165 | ␉␉␉DBG("No ACPI version %d found. Ignoring\n", version+1);␊ |
166 | ␉␉␉if (version)␊ |
167 | ␉␉␉␉addConfigurationTable(&gEfiAcpi20TableGuid, NULL, "ACPI_20");␊ |
168 | ␉␉␉else␊ |
169 | ␉␉␉␉addConfigurationTable(&gEfiAcpiTableGuid, NULL, "ACPI");␊ |
170 | ␉␉␉continue;␊ |
171 | ␉␉}␊ |
172 | ␉␉rsdplength=version?rsdp->Length:20;␊ |
173 | ␊ |
174 | ␉␉DBG("RSDP version %d found @%x. Length=%d\n",version+1,rsdp,rsdplength);␊ |
175 | ␊ |
176 | ␉␉/* FIXME: no check that memory allocation succeeded ␊ |
177 | ␉␉ * Copy and patch RSDP,RSDT, XSDT and FADT␊ |
178 | ␉␉ * For more info see ACPI Specification pages 110 and following␊ |
179 | ␉␉ */␊ |
180 | ␊ |
181 | ␉␉rsdp_mod=(struct acpi_2_rsdp *) AllocateKernelMemory(rsdplength);␊ |
182 | ␉␉memcpy(rsdp_mod, rsdp, rsdplength); ␊ |
183 | ␉␉rsdt=(struct acpi_2_rsdt *)(rsdp->RsdtAddress);␊ |
184 | ␊ |
185 | ␉␉DBG("RSDT @%x, Length %d\n",rsdt, rsdt->Length);␊ |
186 | ␉␉␊ |
187 | ␉␉if (rsdt && (uint32_t)rsdt !=0xffffffff && rsdt->Length<0x10000)␊ |
188 | ␉␉{␊ |
189 | ␉␉␉uint32_t *rsdt_entries;␊ |
190 | ␉␉␉int rsdt_entries_num;␊ |
191 | ␉␉␉int dropoffset=0, i;␊ |
192 | ␉␉␉␊ |
193 | ␉␉␉rsdt_mod=(struct acpi_2_rsdt *)AllocateKernelMemory(rsdt->Length); ␊ |
194 | ␉␉␉memcpy (rsdt_mod, rsdt, rsdt->Length);␊ |
195 | ␉␉␉rsdp_mod->RsdtAddress=(uint32_t)rsdt_mod;␊ |
196 | ␉␉␉rsdt_entries_num=(rsdt_mod->Length-sizeof(struct acpi_2_rsdt))/4;␊ |
197 | ␉␉␉rsdt_entries=(uint32_t *)(rsdt_mod+1);␊ |
198 | ␉␉␉for (i=0;i<rsdt_entries_num;i++)␊ |
199 | ␉␉␉{␊ |
200 | ␉␉␉␉char *table=(char *)(rsdt_entries[i]);␊ |
201 | ␉␉␉␉if (!table)␊ |
202 | ␉␉␉␉␉continue;␊ |
203 | ␊ |
204 | ␉␉␉␉DBG("TABLE %c%c%c%c,",table[0],table[1],table[2],table[3]);␊ |
205 | ␊ |
206 | ␉␉␉␉rsdt_entries[i-dropoffset]=rsdt_entries[i];␊ |
207 | ␉␉␉␉if (drop_ssdt && table[0]=='S' && table[1]=='S' && table[2]=='D' && table[3]=='T')␊ |
208 | ␉␉␉␉{␊ |
209 | ␉␉␉␉␉dropoffset++;␊ |
210 | ␉␉␉␉␉continue;␊ |
211 | ␉␉␉␉}␊ |
212 | ␉␉␉␉if (table[0]=='D' && table[1]=='S' && table[2]=='D' && table[3]=='T')␊ |
213 | ␉␉␉␉{␊ |
214 | ␉␉␉␉␉DBG("DSDT found\n");␊ |
215 | ␉␉␉␉␉rsdt_entries[i-dropoffset]=(uint32_t)new_dsdt;␊ |
216 | ␉␉␉␉␉continue;␊ |
217 | ␉␉␉␉}␊ |
218 | ␉␉␉␉if (table[0]=='F' && table[1]=='A' && table[2]=='C' && table[3]=='P')␊ |
219 | ␉␉␉␉{␊ |
220 | ␉␉␉␉␉struct acpi_2_fadt *fadt, *fadt_mod;␊ |
221 | ␉␉␉␉␉fadt=(struct acpi_2_fadt *)rsdt_entries[i];␊ |
222 | ␉␉␉␉␉␊ |
223 | ␉␉␉␉␉DBG("FADT found @%x, Length %d\n",fadt, fadt->Length);␊ |
224 | ␉␉␉␉␉␊ |
225 | ␉␉␉␉␉if (!fadt || (uint32_t)fadt == 0xffffffff || fadt->Length>0x10000)␊ |
226 | ␉␉␉␉␉{␊ |
227 | ␉␉␉␉␉␉printf("FADT incorrect. Not modified\n");␊ |
228 | ␉␉␉␉␉␉continue;␊ |
229 | ␉␉␉␉␉}␊ |
230 | ␉␉␉␉␉␊ |
231 | ␉␉␉␉␉if (fadt->Length < 0x81 && FixRestart)␊ |
232 | ␉␉␉␉␉{␊ |
233 | ␉␉␉␉␉␉fadt_mod=(struct acpi_2_fadt *)AllocateKernelMemory(0x81); ␊ |
234 | ␉␉␉␉␉␉memcpy(fadt_mod, fadt, fadt->Length);␊ |
235 | ␉␉␉␉␉␉fadt_mod->Length = 0x81;␊ |
236 | ␉␉␉␉␉}␊ |
237 | ␉␉␉␉␉else␊ |
238 | ␉␉␉␉␉{␉␉␉␉␉␉␉␉␉␉␉␉␉␉␊ |
239 | ␉␉␉␉␉␉fadt_mod=(struct acpi_2_fadt *)AllocateKernelMemory(fadt->Length); ␊ |
240 | ␉␉␉␉␉␉memcpy(fadt_mod, fadt, fadt->Length);␊ |
241 | ␉␉␉␉␉}␊ |
242 | ␉␉␉␉␉␊ |
243 | ␉␉␉␉␉if (FixRestart)␊ |
244 | ␉␉␉␉␉{␊ |
245 | ␉␉␉␉␉␉fadt_mod->Flags|= 0x400;␊ |
246 | ␉␉␉␉␉␉fadt_mod->Reset_SpaceID␉␉= 0x01;␊ |
247 | ␉␉␉␉␉␉fadt_mod->Reset_BitWidth␉= 0x08;␊ |
248 | ␉␉␉␉␉␉fadt_mod->Reset_BitOffset␉= 0x00;␊ |
249 | ␉␉␉␉␉␉fadt_mod->Reset_AccessWidth = 0x01;␊ |
250 | ␉␉␉␉␉␉fadt_mod->Reset_Address␉␉= 0x0cf9;␊ |
251 | ␉␉␉␉␉␉fadt_mod->Reset_Value␉␉= 0x06;␊ |
252 | ␉␉␉␉␉}␊ |
253 | ␉␉␉␉␉␊ |
254 | ␉␉␉␉␉// Patch DSDT Address␊ |
255 | ␉␉␉␉␉DBG("Old DSDT @%x,%x\n",fadt_mod->DSDT,fadt_mod->X_DSDT);␊ |
256 | ␉␉␉␉␉␊ |
257 | ␉␉␉␉␉fadt_mod->DSDT=(uint32_t)new_dsdt;␊ |
258 | ␉␉␉␉␉if ((uint32_t)(&(fadt_mod->X_DSDT))-(uint32_t)fadt_mod+8<=fadt_mod->Length)␊ |
259 | ␉␉␉␉␉␉fadt_mod->X_DSDT=(uint32_t)new_dsdt;␊ |
260 | ␉␉␉␉␉␊ |
261 | ␉␉␉␉␉DBG("New DSDT @%x,%x\n",fadt_mod->DSDT,fadt_mod->X_DSDT);␊ |
262 | ␉␉␉␉␉␊ |
263 | ␉␉␉␉␉// Correct the checksum␊ |
264 | ␉␉␉␉␉fadt_mod->Checksum=0;␊ |
265 | ␉␉␉␉␉fadt_mod->Checksum=256-checksum8(fadt_mod,fadt_mod->Length);␊ |
266 | ␉␉␉␉␉␊ |
267 | ␉␉␉␉␉rsdt_entries[i-dropoffset]=(uint32_t)fadt_mod;␊ |
268 | ␉␉␉␉␉continue;␊ |
269 | ␉␉␉␉}␊ |
270 | ␉␉␉}␊ |
271 | ␉␉␉␊ |
272 | ␉␉␉// Correct the checksum of RSDT␊ |
273 | ␉␉␉rsdt_mod->Length-=4*dropoffset;␊ |
274 | ␊ |
275 | ␉␉␉DBG("RSDT Original checksum %d\n", rsdt_mod->Checksum);␊ |
276 | ␊ |
277 | ␉␉␉rsdt_mod->Checksum=0;␊ |
278 | ␉␉␉rsdt_mod->Checksum=256-checksum8(rsdt_mod,rsdt_mod->Length);␊ |
279 | ␊ |
280 | ␉␉␉DBG("RSDT New checksum %d at %x\n", rsdt_mod->Checksum,rsdt_mod);␊ |
281 | ␉␉}␊ |
282 | ␉␉else␊ |
283 | ␉␉{␊ |
284 | ␉␉␉rsdp_mod->RsdtAddress=0;␊ |
285 | ␉␉␉printf("RSDT not found or RSDT incorrect\n");␊ |
286 | ␉␉}␊ |
287 | ␊ |
288 | ␉␉if (version)␊ |
289 | ␉␉{␊ |
290 | ␉␉␉struct acpi_2_xsdt *xsdt, *xsdt_mod;␊ |
291 | ␊ |
292 | ␉␉␉// FIXME: handle 64-bit address correctly␊ |
293 | ␊ |
294 | ␉␉␉xsdt=(struct acpi_2_xsdt*) ((uint32_t)rsdp->XsdtAddress);␊ |
295 | ␉␉␉DBG("XSDT @%x;%x, Length=%d\n", (uint32_t)(rsdp->XsdtAddress>>32),(uint32_t)rsdp->XsdtAddress,␊ |
296 | ␉␉␉␉␉xsdt->Length);␊ |
297 | ␉␉␉if (xsdt && (uint64_t)rsdp->XsdtAddress<0xffffffff && xsdt->Length<0x10000)␊ |
298 | ␉␉␉{␊ |
299 | ␉␉␉␉uint64_t *xsdt_entries;␊ |
300 | ␉␉␉␉int xsdt_entries_num, i;␊ |
301 | ␉␉␉␉int dropoffset=0;␊ |
302 | ␉␉␉␉␊ |
303 | ␉␉␉␉xsdt_mod=(struct acpi_2_xsdt*)AllocateKernelMemory(xsdt->Length); ␊ |
304 | ␉␉␉␉memcpy(xsdt_mod, xsdt, xsdt->Length);␊ |
305 | ␉␉␉␉rsdp_mod->XsdtAddress=(uint32_t)xsdt_mod;␊ |
306 | ␉␉␉␉xsdt_entries_num=(xsdt_mod->Length-sizeof(struct acpi_2_xsdt))/8;␊ |
307 | ␉␉␉␉xsdt_entries=(uint64_t *)(xsdt_mod+1);␊ |
308 | ␉␉␉␉for (i=0;i<xsdt_entries_num;i++)␊ |
309 | ␉␉␉␉{␊ |
310 | ␉␉␉␉␉char *table=(char *)((uint32_t)(xsdt_entries[i]));␊ |
311 | ␉␉␉␉␉if (!table)␊ |
312 | ␉␉␉␉␉␉continue;␊ |
313 | ␉␉␉␉␉xsdt_entries[i-dropoffset]=xsdt_entries[i];␊ |
314 | ␉␉␉␉␉if (drop_ssdt && table[0]=='S' && table[1]=='S' && table[2]=='D' && table[3]=='T')␊ |
315 | ␉␉␉␉␉{␊ |
316 | ␉␉␉␉␉␉dropoffset++;␊ |
317 | ␉␉␉␉␉␉continue;␊ |
318 | ␉␉␉␉␉}␉␉␉␉␉␊ |
319 | ␉␉␉␉␉if (table[0]=='D' && table[1]=='S' && table[2]=='D' && table[3]=='T')␊ |
320 | ␉␉␉␉␉{␊ |
321 | ␉␉␉␉␉␉DBG("DSDT found\n");␊ |
322 | ␊ |
323 | ␉␉␉␉␉␉xsdt_entries[i-dropoffset]=(uint32_t)new_dsdt;␊ |
324 | ␊ |
325 | ␉␉␉␉␉␉DBG("TABLE %c%c%c%c@%x,",table[0],table[1],table[2],table[3],xsdt_entries[i]);␊ |
326 | ␉␉␉␉␉␉␊ |
327 | ␉␉␉␉␉␉continue;␊ |
328 | ␉␉␉␉␉}␊ |
329 | ␉␉␉␉␉if (table[0]=='F' && table[1]=='A' && table[2]=='C' && table[3]=='P')␊ |
330 | ␉␉␉␉␉{␊ |
331 | ␉␉␉␉␉␉struct acpi_2_fadt *fadt, *fadt_mod;␊ |
332 | ␉␉␉␉␉␉fadt=(struct acpi_2_fadt *)(uint32_t)xsdt_entries[i];␊ |
333 | ␊ |
334 | ␉␉␉␉␉␉DBG("FADT found @%x,%x, Length %d\n",(uint32_t)(xsdt_entries[i]>>32),fadt, ␊ |
335 | ␉␉␉␉␉␉␉␉ fadt->Length);␊ |
336 | ␊ |
337 | ␉␉␉␉␉␉if (!fadt || (uint64_t)xsdt_entries[i] >= 0xffffffff || fadt->Length>0x10000)␊ |
338 | ␉␉␉␉␉␉{␊ |
339 | ␉␉␉␉␉␉␉printf("FADT incorrect or after 4GB. Dropping XSDT\n");␊ |
340 | ␉␉␉␉␉␉␉goto drop_xsdt;␊ |
341 | ␉␉␉␉␉␉}␊ |
342 | ␉␉␉␉␉␉␊ |
343 | ␉␉␉␉␉␉if (fadt->Length < 0x81 && FixRestart)␊ |
344 | ␉␉␉␉␉␉{␊ |
345 | ␉␉␉␉␉␉␉fadt_mod=(struct acpi_2_fadt *)AllocateKernelMemory(0x81); ␊ |
346 | ␉␉␉␉␉␉␉memcpy(fadt_mod, fadt, fadt->Length);␊ |
347 | ␉␉␉␉␉␉␉fadt_mod->Length = 0x81;␊ |
348 | ␉␉␉␉␉␉}␊ |
349 | ␉␉␉␉␉␉else␊ |
350 | ␉␉␉␉␉␉{␉␉␉␉␉␉␉␉␉␉␉␉␉␉␊ |
351 | ␉␉␉␉␉␉␉fadt_mod=(struct acpi_2_fadt *)AllocateKernelMemory(fadt->Length); ␊ |
352 | ␉␉␉␉␉␉␉memcpy(fadt_mod, fadt, fadt->Length);␊ |
353 | ␉␉␉␉␉␉}␊ |
354 | ␉␉␉␉␉␉␊ |
355 | ␉␉␉␉␉␉if (FixRestart)␊ |
356 | ␉␉␉␉␉␉{␊ |
357 | ␉␉␉␉␉␉␉fadt_mod->Flags|= 0x400;␊ |
358 | ␉␉␉␉␉␉␉fadt_mod->Reset_SpaceID␉␉= 0x01;␊ |
359 | ␉␉␉␉␉␉␉fadt_mod->Reset_BitWidth␉= 0x08;␊ |
360 | ␉␉␉␉␉␉␉fadt_mod->Reset_BitOffset␉= 0x00;␊ |
361 | ␉␉␉␉␉␉␉fadt_mod->Reset_AccessWidth = 0x01;␊ |
362 | ␉␉␉␉␉␉␉fadt_mod->Reset_Address␉␉= 0x0cf9;␊ |
363 | ␉␉␉␉␉␉␉fadt_mod->Reset_Value␉␉= 0x06;␊ |
364 | ␉␉␉␉␉␉}␉␉␉␉␉␉␊ |
365 | ␊ |
366 | ␉␉␉␉␉␉DBG("Old DSDT @%x,%x\n",fadt_mod->DSDT,fadt_mod->X_DSDT);␊ |
367 | ␉␉␉␉␉␉␊ |
368 | ␉␉␉␉␉␉fadt_mod->DSDT=(uint32_t)new_dsdt;␊ |
369 | ␉␉␉␉␉␉if ((uint32_t)(&(fadt_mod->X_DSDT))-(uint32_t)fadt_mod+8<=fadt_mod->Length)␊ |
370 | ␉␉␉␉␉␉␉fadt_mod->X_DSDT=(uint32_t)new_dsdt;␊ |
371 | ␉␉␉␉␉␉␊ |
372 | ␉␉␉␉␉␉DBG("New DSDT @%x,%x\n",fadt_mod->DSDT,fadt_mod->X_DSDT);␊ |
373 | ␉␉␉␉␉␉␊ |
374 | ␉␉␉␉␉␉// Correct the checksum␊ |
375 | ␉␉␉␉␉␉fadt_mod->Checksum=0;␊ |
376 | ␉␉␉␉␉␉fadt_mod->Checksum=256-checksum8(fadt_mod,fadt_mod->Length);␊ |
377 | ␉␉␉␉␉␉␊ |
378 | ␉␉␉␉␉␉xsdt_entries[i-dropoffset]=(uint32_t)fadt_mod;␊ |
379 | ␉␉␉␉␉␉continue;␊ |
380 | ␉␉␉␉␉}␊ |
381 | ␊ |
382 | ␉␉␉␉␉DBG("TABLE %c%c%c%c@%x,",table[0],table[1],table[2],table[3],xsdt_entries[i]);␊ |
383 | ␊ |
384 | ␉␉␉␉}␊ |
385 | ␊ |
386 | ␉␉␉␉// Correct the checksum of XSDT␊ |
387 | ␉␉␉␉xsdt_mod->Length-=8*dropoffset;␊ |
388 | ␉␉␉␉xsdt_mod->Checksum=0;␊ |
389 | ␉␉␉␉xsdt_mod->Checksum=256-checksum8(xsdt_mod,xsdt_mod->Length);␊ |
390 | ␉␉␉}␊ |
391 | ␉␉␉else␊ |
392 | ␉␉␉{␊ |
393 | ␉␉␉drop_xsdt:␊ |
394 | ␊ |
395 | ␉␉␉␉DBG("About to drop XSDT\n");␊ |
396 | ␊ |
397 | ␉␉␉␉/*FIXME: Now we just hope that if MacOS doesn't find XSDT it reverts to RSDT. ␊ |
398 | ␉␉␉␉ * A Better strategy would be to generate␊ |
399 | ␉␉␉␉ */␊ |
400 | ␊ |
401 | ␉␉␉␉rsdp_mod->XsdtAddress=0xffffffffffffffffLL;␊ |
402 | ␉␉␉␉printf("XSDT not found or XSDT incorrect\n");␊ |
403 | ␉␉␉}␊ |
404 | ␉␉}␊ |
405 | ␊ |
406 | ␉␉// Correct the checksum of RSDP ␊ |
407 | ␊ |
408 | ␉␉DBG("Original checksum %d\n", rsdp_mod->Checksum);␊ |
409 | ␊ |
410 | ␉␉rsdp_mod->Checksum=0;␊ |
411 | ␉␉rsdp_mod->Checksum=256-checksum8(rsdp_mod,20);␊ |
412 | ␊ |
413 | ␉␉DBG("New checksum %d\n", rsdp_mod->Checksum);␊ |
414 | ␊ |
415 | ␉␉if (version)␊ |
416 | ␉␉{␊ |
417 | ␉␉␉DBG("Original extended checksum %d\n", rsdp_mod->ExtendedChecksum);␊ |
418 | ␊ |
419 | ␉␉␉rsdp_mod->ExtendedChecksum=0;␊ |
420 | ␉␉␉rsdp_mod->ExtendedChecksum=256-checksum8(rsdp_mod,rsdp_mod->Length);␊ |
421 | ␊ |
422 | ␉␉␉DBG("New extended checksum %d\n", rsdp_mod->ExtendedChecksum);␊ |
423 | ␊ |
424 | ␉␉}␊ |
425 | ␉␉␊ |
426 | ␉␉verbose("Patched ACPI version %d DSDT\n", version+1);␊ |
427 | ␉␉if (version)␊ |
428 | ␉␉{␊ |
429 | ␉␉␉acpi20_p = (uint32_t)rsdp_mod;␊ |
430 | ␉␉␉addConfigurationTable(&gEfiAcpi20TableGuid, &acpi20_p, "ACPI_20");␊ |
431 | ␉␉}␊ |
432 | ␉␉else␊ |
433 | ␉␉{␊ |
434 | ␉␉␉acpi10_p = (uint32_t)rsdp_mod;␊ |
435 | ␉␉␉addConfigurationTable(&gEfiAcpiTableGuid, &acpi10_p, "ACPI");␊ |
436 | ␉␉}␊ |
437 | ␉}␊ |
438 | ␉#if DEBUG_DSDT␊ |
439 | ␉getc();␊ |
440 | ␉#endif␊ |
441 | ␉return 1;␊ |
442 | }␊ |
443 | |