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