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 "acpi_patcher.h"␊ |
12 | #include "platform.h"␊ |
13 | #include "cpu.h"␊ |
14 | #include "aml_generator.h"␊ |
15 | ␊ |
16 | #ifndef DEBUG_ACPI␊ |
17 | #define DEBUG_ACPI 0␊ |
18 | #endif␊ |
19 | ␊ |
20 | #if DEBUG_ACPI==2␊ |
21 | #define DBG(x...) {printf(x); sleep(1);}␊ |
22 | #elif DEBUG_ACPI==1␊ |
23 | #define DBG(x...) printf(x)␊ |
24 | #else␊ |
25 | #define DBG(x...)␊ |
26 | #endif␊ |
27 | ␊ |
28 | // Slice: New signature compare function␊ |
29 | boolean_t tableSign(char *table, const char *sgn)␊ |
30 | {␊ |
31 | ␉int i;␊ |
32 | ␉for (i=0; i<4; i++) {␊ |
33 | ␉␉if ((table[i] &~0x20) != (sgn[i] &~0x20)) {␊ |
34 | ␉␉␉return false;␊ |
35 | ␉␉}␊ |
36 | ␉}␊ |
37 | ␉return true;␊ |
38 | }␊ |
39 | ␊ |
40 | /* Gets the ACPI 1.0 RSDP address */␊ |
41 | static struct acpi_2_rsdp* getAddressOfAcpiTable()␊ |
42 | {␊ |
43 | /* TODO: Before searching the BIOS space we are supposed to search the first 1K of the EBDA */␊ |
44 | ␉␊ |
45 | void *acpi_addr = (void*)ACPI_RANGE_START;␊ |
46 | for(; acpi_addr <= (void*)ACPI_RANGE_END; acpi_addr += 16)␊ |
47 | {␊ |
48 | if(*(uint64_t *)acpi_addr == ACPI_SIGNATURE_UINT64_LE)␊ |
49 | {␊ |
50 | uint8_t csum = checksum8(acpi_addr, 20);␊ |
51 | if(csum == 0)␊ |
52 | {␊ |
53 | // Only return the table if it is a true version 1.0 table (Revision 0)␊ |
54 | if(((struct acpi_2_rsdp*)acpi_addr)->Revision == 0)␊ |
55 | return acpi_addr;␊ |
56 | }␊ |
57 | }␊ |
58 | }␊ |
59 | return NULL;␊ |
60 | }␊ |
61 | ␊ |
62 | /* Gets the ACPI 2.0 RSDP address */␊ |
63 | static struct acpi_2_rsdp* getAddressOfAcpi20Table()␊ |
64 | {␊ |
65 | /* TODO: Before searching the BIOS space we are supposed to search the first 1K of the EBDA */␊ |
66 | ␉␊ |
67 | void *acpi_addr = (void*)ACPI_RANGE_START;␊ |
68 | for(; acpi_addr <= (void*)ACPI_RANGE_END; acpi_addr += 16)␊ |
69 | {␊ |
70 | if(*(uint64_t *)acpi_addr == ACPI_SIGNATURE_UINT64_LE)␊ |
71 | {␊ |
72 | uint8_t csum = checksum8(acpi_addr, 20);␊ |
73 | ␉␉␉␊ |
74 | /* Only assume this is a 2.0 or better table if the revision is greater than 0␊ |
75 | * NOTE: ACPI 3.0 spec only seems to say that 1.0 tables have revision 1␊ |
76 | * and that the current revision is 2.. I am going to assume that rev > 0 is 2.0.␊ |
77 | */␊ |
78 | ␉␉␉␊ |
79 | if(csum == 0 && (((struct acpi_2_rsdp*)acpi_addr)->Revision > 0))␊ |
80 | {␊ |
81 | uint8_t csum2 = checksum8(acpi_addr, sizeof(struct acpi_2_rsdp));␊ |
82 | if(csum2 == 0)␊ |
83 | return acpi_addr;␊ |
84 | }␊ |
85 | }␊ |
86 | }␊ |
87 | return NULL;␊ |
88 | }␊ |
89 | /** The folowing ACPI Table search algo. should be reused anywhere needed:*/␊ |
90 | int search_and_get_acpi_fd(const char * filename, const char ** outDirspec)␊ |
91 | {␊ |
92 | ␉int fd = 0;␊ |
93 | ␉char dirSpec[512] = "";␊ |
94 | ␉␊ |
95 | ␉// Try finding 'filename' in the usual places␊ |
96 | ␉// Start searching any potential location for ACPI Table␊ |
97 | ␉sprintf(dirSpec, "%s", filename); ␊ |
98 | ␉fd = open(dirSpec, 0);␊ |
99 | ␉if (fd < 0)␊ |
100 | ␉{␉␊ |
101 | ␉␉sprintf(dirSpec, "/Extra/%s", filename); ␊ |
102 | ␉␉fd = open(dirSpec, 0);␊ |
103 | ␉␉if (fd < 0)␊ |
104 | ␉␉{␊ |
105 | ␉␉␉sprintf(dirSpec, "bt(0,0)/Extra/%s", filename);␊ |
106 | ␉␉␉fd = open(dirSpec, 0);␊ |
107 | ␉␉}␊ |
108 | ␉}␊ |
109 | ␊ |
110 | ␉if (fd < 0)␊ |
111 | ␉{␊ |
112 | ␉␉// NOT FOUND:␊ |
113 | ␉␉verbose("ACPI table not found: %s\n", filename);␊ |
114 | ␉␉*dirSpec = '\0';␊ |
115 | ␉}␊ |
116 | ␊ |
117 | ␉if (outDirspec) *outDirspec = dirSpec; ␊ |
118 | ␉return fd;␊ |
119 | }␊ |
120 | ␊ |
121 | ␊ |
122 | void *loadACPITable (const char * filename)␊ |
123 | {␊ |
124 | ␉void *tableAddr;␊ |
125 | ␉const char * dirspec=NULL;␊ |
126 | ␉␊ |
127 | ␉int fd = search_and_get_acpi_fd(filename, &dirspec);␊ |
128 | ␉␊ |
129 | ␉if (fd>=0)␊ |
130 | ␉{␊ |
131 | ␉␉tableAddr=(void*)AllocateKernelMemory(file_size (fd));␊ |
132 | ␉␉if (tableAddr)␊ |
133 | ␉␉{␊ |
134 | ␉␉␉if (read (fd, tableAddr, file_size (fd))!=file_size (fd))␊ |
135 | ␉␉␉{␊ |
136 | ␉␉␉␉printf("Couldn't read table %s\n",dirspec);␊ |
137 | ␉␉␉␉free (tableAddr);␊ |
138 | ␉␉␉␉close (fd);␊ |
139 | ␉␉␉␉return NULL;␊ |
140 | ␉␉␉}␊ |
141 | ␉␉␉␊ |
142 | ␉␉␉DBG("Table %s read and stored at: %x\n", dirspec, tableAddr);␊ |
143 | ␉␉␉close (fd);␊ |
144 | ␉␉␉return tableAddr;␊ |
145 | ␉␉}␊ |
146 | ␉␉close (fd);␊ |
147 | ␉␉printf("Couldn't allocate memory for table \n", dirspec);␊ |
148 | ␉} ␊ |
149 | ␉//printf("Couldn't find table %s\n", filename);␊ |
150 | ␉return NULL;␊ |
151 | }␊ |
152 | ␊ |
153 | uint8_t␉acpi_cpu_count = 0;␊ |
154 | char* acpi_cpu_name[32];␊ |
155 | ␊ |
156 | void get_acpi_cpu_names(unsigned char* dsdt, uint32_t length)␊ |
157 | {␊ |
158 | ␉uint32_t i;␊ |
159 | ␉␊ |
160 | ␉for (i=0; i<length-7; i++) ␊ |
161 | ␉{␊ |
162 | ␉␉if (dsdt[i] == 0x5B && dsdt[i+1] == 0x83) // ProcessorOP␊ |
163 | ␉␉{␊ |
164 | ␉␉␉uint32_t offset = i + 3 + (dsdt[i+2] >> 6);␊ |
165 | ␉␉␉␊ |
166 | ␉␉␉bool add_name = true;␊ |
167 | ␊ |
168 | ␉␉␉uint8_t j;␊ |
169 | ␉␉␉␊ |
170 | ␉␉␉for (j=0; j<4; j++) ␊ |
171 | ␉␉␉{␊ |
172 | ␉␉␉␉char c = dsdt[offset+j];␊ |
173 | ␉␉␉␉␊ |
174 | ␉␉␉␉if (!aml_isvalidchar(c)) ␊ |
175 | ␉␉␉␉{␊ |
176 | ␉␉␉␉␉add_name = false;␊ |
177 | ␉␉␉␉␉verbose("Invalid character found in ProcessorOP 0x%x!\n", c);␊ |
178 | ␉␉␉␉␉break;␊ |
179 | ␉␉␉␉}␊ |
180 | ␉␉␉}␊ |
181 | ␉␉␉␊ |
182 | ␉␉␉if (add_name) ␊ |
183 | ␉␉␉{␊ |
184 | ␉␉␉␉acpi_cpu_name[acpi_cpu_count] = malloc(4);␊ |
185 | ␉␉␉␉memcpy(acpi_cpu_name[acpi_cpu_count], dsdt+offset, 4);␊ |
186 | ␉␉␉␉i = offset + 5;␊ |
187 | ␉␉␉␉␊ |
188 | ␉␉␉␉verbose("Found ACPI CPU: %c%c%c%c\n", acpi_cpu_name[acpi_cpu_count][0], acpi_cpu_name[acpi_cpu_count][1], acpi_cpu_name[acpi_cpu_count][2], acpi_cpu_name[acpi_cpu_count][3]);␊ |
189 | ␉␉␉␉␊ |
190 | ␉␉␉␉if (++acpi_cpu_count == 32) return;␊ |
191 | ␉␉␉}␊ |
192 | ␉␉}␊ |
193 | ␉}␊ |
194 | }␊ |
195 | ␊ |
196 | struct acpi_2_ssdt *generate_cst_ssdt(struct acpi_2_fadt* fadt)␊ |
197 | {␊ |
198 | ␉char ssdt_header[] =␊ |
199 | ␉{␊ |
200 | ␉␉0x53, 0x53, 0x44, 0x54, 0xE7, 0x00, 0x00, 0x00, /* SSDT.... */␊ |
201 | ␉␉0x01, 0x17, 0x50, 0x6D, 0x52, 0x65, 0x66, 0x41, /* ..PmRefA */␊ |
202 | ␉␉0x43, 0x70, 0x75, 0x43, 0x73, 0x74, 0x00, 0x00, /* CpuCst.. */␊ |
203 | ␉␉0x00, 0x10, 0x00, 0x00, 0x49, 0x4E, 0x54, 0x4C, /* ....INTL */␊ |
204 | ␉␉0x31, 0x03, 0x10, 0x20 ␉␉␉␉␉␉␉/* 1.._␉␉*/␊ |
205 | ␉};␊ |
206 | ␉␊ |
207 | ␉char cstate_resource_template[] = ␊ |
208 | ␉{␊ |
209 | ␉␉0x11, 0x14, 0x0A, 0x11, 0x82, 0x0C, 0x00, 0x7F, ␊ |
210 | ␉␉0x01, 0x02, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, ␊ |
211 | ␉␉0x00, 0x00, 0x00, 0x79, 0x00␊ |
212 | ␉};␊ |
213 | ␊ |
214 | ␉if (Platform.CPU.Vendor != 0x756E6547) {␊ |
215 | ␉␉verbose ("Not an Intel platform: C-States will not be generated !!!\n");␊ |
216 | ␉␉return NULL;␊ |
217 | ␉}␊ |
218 | ␉␊ |
219 | ␉if (fadt == NULL) {␊ |
220 | ␉␉verbose ("FACP not exists: C-States will not be generated !!!\n");␊ |
221 | ␉␉return NULL;␊ |
222 | ␉}␊ |
223 | ␉␊ |
224 | ␉struct acpi_2_dsdt* dsdt = (void*)fadt->DSDT;␊ |
225 | ␉␊ |
226 | ␉if (dsdt == NULL) {␊ |
227 | ␉␉verbose ("DSDT not found: C-States will not be generated !!!\n");␊ |
228 | ␉␉return NULL;␊ |
229 | ␉}␊ |
230 | ␉␊ |
231 | ␉if (acpi_cpu_count == 0) ␊ |
232 | ␉␉get_acpi_cpu_names((void*)dsdt, dsdt->Length);␊ |
233 | ␉␊ |
234 | ␉if (acpi_cpu_count > 0) ␊ |
235 | ␉{␊ |
236 | ␉␉bool c2_enabled = false;␊ |
237 | ␉␉bool c3_enabled = false;␊ |
238 | ␉␉bool c4_enabled = false;␊ |
239 | ␉␉␊ |
240 | ␉␉getBoolForKey(kEnableC2States, &c2_enabled, &bootInfo->bootConfig);␊ |
241 | ␉␉getBoolForKey(kEnableC3States, &c3_enabled, &bootInfo->bootConfig);␊ |
242 | ␉␉getBoolForKey(kEnableC4States, &c4_enabled, &bootInfo->bootConfig);␊ |
243 | ␉␉␊ |
244 | ␉␉c2_enabled = c2_enabled | (fadt->C2_Latency < 100);␊ |
245 | ␉␉c3_enabled = c3_enabled | (fadt->C3_Latency < 1000);␊ |
246 | ␊ |
247 | ␉␉unsigned char cstates_count = 1 + (c2_enabled ? 1 : 0) + (c3_enabled ? 1 : 0);␊ |
248 | ␉␉␊ |
249 | ␉␉struct aml_chunk* root = aml_create_node(NULL);␊ |
250 | ␉␉␉aml_add_buffer(root, ssdt_header, sizeof(ssdt_header)); // SSDT header␊ |
251 | ␉␉␉struct aml_chunk* scop = aml_add_scope(root, "\\_PR_");␊ |
252 | ␉␉␉␉struct aml_chunk* name = aml_add_name(scop, "CST_");␊ |
253 | ␉␉␉␉␉struct aml_chunk* pack = aml_add_package(name);␊ |
254 | ␉␉␉␉␉␉aml_add_byte(pack, cstates_count);␊ |
255 | ␉␉␊ |
256 | ␉␉␉␉␉␉struct aml_chunk* tmpl = aml_add_package(pack);␊ |
257 | ␉␉␉␉␉␉␉cstate_resource_template[11] = 0x00; // C1␊ |
258 | ␉␉␉␉␉␉␉aml_add_buffer(tmpl, cstate_resource_template, sizeof(cstate_resource_template));␊ |
259 | ␉␉␉␉␉␉␉aml_add_byte(tmpl, 0x01); // C1␊ |
260 | ␉␉␉␉␉␉␉aml_add_byte(tmpl, 0x01); // Latency␊ |
261 | ␉␉␉␉␉␉␉aml_add_word(tmpl, 0x03e8); // Power␊ |
262 | ␊ |
263 | ␉␉␉␉␉␉// C2␊ |
264 | ␉␉␉␉␉␉if (c2_enabled) ␊ |
265 | ␉␉␉␉␉␉{␊ |
266 | ␉␉␉␉␉␉␉tmpl = aml_add_package(pack);␊ |
267 | ␉␉␉␉␉␉␉␉cstate_resource_template[11] = 0x10; // C2␊ |
268 | ␉␉␉␉␉␉␉␉aml_add_buffer(tmpl, cstate_resource_template, sizeof(cstate_resource_template));␊ |
269 | ␉␉␉␉␉␉␉␉aml_add_byte(tmpl, 0x02); // C2␊ |
270 | ␉␉␉␉␉␉␉␉aml_add_byte(tmpl, fadt->C2_Latency);␊ |
271 | ␉␉␉␉␉␉␉␉aml_add_word(tmpl, 0x01f4); // Power␊ |
272 | ␉␉␉␉␉␉}␊ |
273 | ␉␉␉␉␉␉// C4␊ |
274 | ␉␉␉␉␉␉if (c4_enabled) ␊ |
275 | ␉␉␉␉␉␉{␊ |
276 | ␉␉␉␉␉␉␉tmpl = aml_add_package(pack);␊ |
277 | ␉␉␉␉␉␉␉cstate_resource_template[11] = 0x30; // C4␊ |
278 | ␉␉␉␉␉␉␉aml_add_buffer(tmpl, cstate_resource_template, sizeof(cstate_resource_template));␊ |
279 | ␉␉␉␉␉␉␉aml_add_byte(tmpl, 0x04); // C4␊ |
280 | ␉␉␉␉␉␉␉aml_add_word(tmpl, fadt->C3_Latency / 2); // TODO: right latency for C4␊ |
281 | ␉␉␉␉␉␉␉aml_add_byte(tmpl, 0xfa); // Power␊ |
282 | ␉␉␉␉␉␉}␊ |
283 | ␉␉␉␉␉␉else␊ |
284 | ␉␉␉␉␉␉// C3␊ |
285 | ␉␉␉␉␉␉if (c3_enabled) ␊ |
286 | ␉␉␉␉␉␉{␊ |
287 | ␉␉␉␉␉␉␉tmpl = aml_add_package(pack);␊ |
288 | ␉␉␉␉␉␉␉cstate_resource_template[11] = 0x20; // C3␊ |
289 | ␉␉␉␉␉␉␉aml_add_buffer(tmpl, cstate_resource_template, sizeof(cstate_resource_template));␊ |
290 | ␉␉␉␉␉␉␉aml_add_byte(tmpl, 0x03); // C3␊ |
291 | ␉␉␉␉␉␉␉aml_add_word(tmpl, fadt->C3_Latency);␊ |
292 | ␉␉␉␉␉␉␉aml_add_word(tmpl, 0x015e); // Power␊ |
293 | ␉␉␉␉␉␉}␊ |
294 | ␉␉␉␉␉␉␊ |
295 | ␉␉␉␊ |
296 | ␉␉␉// Aliaces␊ |
297 | ␉␉␉int i;␊ |
298 | ␉␉␉for (i = 0; i < acpi_cpu_count; i++) ␊ |
299 | ␉␉␉{␊ |
300 | ␉␉␉␉char name[9];␊ |
301 | ␉␉␉␉sprintf(name, "_PR_%c%c%c%c", acpi_cpu_name[i][0], acpi_cpu_name[i][1], acpi_cpu_name[i][2], acpi_cpu_name[i][3]);␊ |
302 | ␉␉␉␉␊ |
303 | ␉␉␉␉scop = aml_add_scope(root, name);␊ |
304 | ␉␉␉␉␉aml_add_alias(scop, "CST_", "_CST");␊ |
305 | ␉␉␉}␊ |
306 | ␉␉␊ |
307 | ␉␉aml_calculate_size(root);␊ |
308 | ␉␉␊ |
309 | ␉␉struct acpi_2_ssdt *ssdt = (struct acpi_2_ssdt *)AllocateKernelMemory(root->Size);␊ |
310 | ␉␊ |
311 | ␉␉aml_write_node(root, (void*)ssdt, 0);␊ |
312 | ␉␉␊ |
313 | ␉␉ssdt->Length = root->Size;␊ |
314 | ␉␉ssdt->Checksum = 0;␊ |
315 | ␉␉ssdt->Checksum = 256 - checksum8(ssdt, ssdt->Length);␊ |
316 | ␉␉␊ |
317 | ␉␉aml_destroy_node(root);␊ |
318 | ␉␉␊ |
319 | ␉␉//dumpPhysAddr("C-States SSDT content: ", ssdt, ssdt->Length);␊ |
320 | ␉␉␉␉␊ |
321 | ␉␉verbose ("SSDT with CPU C-States generated successfully\n");␊ |
322 | ␉␉␊ |
323 | ␉␉return ssdt;␊ |
324 | ␉}␊ |
325 | ␉else ␊ |
326 | ␉{␊ |
327 | ␉␉verbose ("ACPI CPUs not found: C-States not generated !!!\n");␊ |
328 | ␉}␊ |
329 | ␊ |
330 | ␉return NULL;␊ |
331 | }␊ |
332 | ␊ |
333 | struct acpi_2_ssdt *generate_pss_ssdt(struct acpi_2_dsdt* dsdt)␊ |
334 | {␉␊ |
335 | ␉char ssdt_header[] =␊ |
336 | ␉{␊ |
337 | ␉␉0x53, 0x53, 0x44, 0x54, 0x7E, 0x00, 0x00, 0x00, /* SSDT.... */␊ |
338 | ␉␉0x01, 0x6A, 0x50, 0x6D, 0x52, 0x65, 0x66, 0x00, /* ..PmRef. */␊ |
339 | ␉␉0x43, 0x70, 0x75, 0x50, 0x6D, 0x00, 0x00, 0x00, /* CpuPm... */␊ |
340 | ␉␉0x00, 0x30, 0x00, 0x00, 0x49, 0x4E, 0x54, 0x4C, /* .0..INTL */␊ |
341 | ␉␉0x31, 0x03, 0x10, 0x20,␉␉␉␉␉␉␉/* 1.._␉␉*/␊ |
342 | ␉};␊ |
343 | ␉␊ |
344 | ␉if (Platform.CPU.Vendor != 0x756E6547) {␊ |
345 | ␉␉verbose ("Not an Intel platform: P-States will not be generated !!!\n");␊ |
346 | ␉␉return NULL;␊ |
347 | ␉}␊ |
348 | ␉␊ |
349 | ␉if (!(Platform.CPU.Features & CPU_FEATURE_MSR)) {␊ |
350 | ␉␉verbose ("Unsupported CPU: P-States will not be generated !!!\n");␊ |
351 | ␉␉return NULL;␊ |
352 | ␉}␊ |
353 | ␉␊ |
354 | ␉if (acpi_cpu_count == 0) ␊ |
355 | ␉␉get_acpi_cpu_names((void*)dsdt, dsdt->Length);␊ |
356 | ␉␊ |
357 | ␉if (acpi_cpu_count > 0) ␊ |
358 | ␉{␊ |
359 | ␉␉struct p_state initial, maximum, minimum, p_states[32];␊ |
360 | ␉␉uint8_t p_states_count = 0;␉␉␊ |
361 | ␉␉␊ |
362 | ␉␉// Retrieving P-States, ported from code by superhai (c)␊ |
363 | ␉␉switch (Platform.CPU.Family) {␊ |
364 | ␉␉␉case 0x06: ␊ |
365 | ␉␉␉{␊ |
366 | ␉␉␉␉switch (Platform.CPU.Model) ␊ |
367 | ␉␉␉␉{␊ |
368 | ␉␉␉␉␉case 0x0D:␉␉␉␉// ???␊ |
369 | ␉␉␉␉␉case CPU_MODEL_YONAH:␉// Intel Mobile Core Solo, Duo␊ |
370 | ␉␉␉␉␉case CPU_MODEL_MEROM:␉// Intel Mobile Core 2 Solo, Duo, Xeon 30xx, Xeon 51xx, Xeon X53xx, Xeon E53xx, Xeon X32xx␊ |
371 | ␉␉␉␉␉case CPU_MODEL_PENRYN:␉// Intel Core 2 Solo, Duo, Quad, Extreme, Xeon X54xx, Xeon X33xx␊ |
372 | ␉␉␉␉␉case CPU_MODEL_ATOM:␉// Intel Atom (45nm)␊ |
373 | ␉␉␉␉␉{␊ |
374 | ␉␉␉␉␉␉bool cpu_dynamic_fsb = false;␊ |
375 | ␉␉␉␉␉␉␊ |
376 | ␉␉␉␉␉␉if (rdmsr64(MSR_IA32_EXT_CONFIG) & (1 << 27)) ␊ |
377 | ␉␉␉␉␉␉{␊ |
378 | ␉␉␉␉␉␉␉wrmsr64(MSR_IA32_EXT_CONFIG, (rdmsr64(MSR_IA32_EXT_CONFIG) | (1 << 28))); ␊ |
379 | ␉␉␉␉␉␉␉delay(1);␊ |
380 | ␉␉␉␉␉␉␉cpu_dynamic_fsb = rdmsr64(MSR_IA32_EXT_CONFIG) & (1 << 28);␊ |
381 | ␉␉␉␉␉␉}␊ |
382 | ␉␉␉␉␉␉␊ |
383 | ␉␉␉␉␉␉bool cpu_noninteger_bus_ratio = (rdmsr64(MSR_IA32_PERF_STATUS) & (1ULL << 46));␊ |
384 | ␉␉␉␉␉␉␊ |
385 | ␉␉␉␉␉␉initial.Control = rdmsr64(MSR_IA32_PERF_STATUS);␊ |
386 | ␉␉␉␉␉␉␊ |
387 | ␉␉␉␉␉␉maximum.Control = ((rdmsr64(MSR_IA32_PERF_STATUS) >> 32) & 0x1F3F) | (0x4000 * cpu_noninteger_bus_ratio);␊ |
388 | ␉␉␉␉␉␉maximum.CID = ((maximum.FID & 0x1F) << 1) | cpu_noninteger_bus_ratio;␊ |
389 | ␉␉␉␉␉␉␊ |
390 | ␉␉␉␉␉␉minimum.FID = ((rdmsr64(MSR_IA32_PERF_STATUS) >> 24) & 0x1F) | (0x80 * cpu_dynamic_fsb);␊ |
391 | ␉␉␉␉␉␉minimum.VID = ((rdmsr64(MSR_IA32_PERF_STATUS) >> 48) & 0x3F);␊ |
392 | ␉␉␉␉␉␉␊ |
393 | ␉␉␉␉␉␉if (minimum.FID == 0) ␊ |
394 | ␉␉␉␉␉␉{␊ |
395 | ␉␉␉␉␉␉␉uint64_t msr;␊ |
396 | ␉␉␉␉␉␉␉uint8_t i;␊ |
397 | ␉␉␉␉␉␉␉// Probe for lowest fid␊ |
398 | ␉␉␉␉␉␉␉for (i = maximum.FID; i >= 0x6; i--) ␊ |
399 | ␉␉␉␉␉␉␉{␊ |
400 | ␉␉␉␉␉␉␉␉msr = rdmsr64(MSR_IA32_PERF_CONTROL);␊ |
401 | ␉␉␉␉␉␉␉␉wrmsr64(MSR_IA32_PERF_CONTROL, (msr & 0xFFFFFFFFFFFF0000ULL) | (i << 8) | minimum.VID);␊ |
402 | ␉␉␉␉␉␉␉␉intel_waitforsts();␊ |
403 | ␉␉␉␉␉␉␉␉minimum.FID = (rdmsr64(MSR_IA32_PERF_STATUS) >> 8) & 0x1F; ␊ |
404 | ␉␉␉␉␉␉␉␉delay(1);␊ |
405 | ␉␉␉␉␉␉␉}␊ |
406 | ␉␉␉␉␉␉␉␊ |
407 | ␉␉␉␉␉␉␉msr = rdmsr64(MSR_IA32_PERF_CONTROL);␊ |
408 | ␉␉␉␉␉␉␉wrmsr64(MSR_IA32_PERF_CONTROL, (msr & 0xFFFFFFFFFFFF0000ULL) | (maximum.FID << 8) | maximum.VID);␊ |
409 | ␉␉␉␉␉␉␉intel_waitforsts();␊ |
410 | ␉␉␉␉␉␉}␊ |
411 | ␉␉␉␉␉␉␊ |
412 | ␉␉␉␉␉␉if (minimum.VID == maximum.VID) ␊ |
413 | ␉␉␉␉␉␉{␉␊ |
414 | ␉␉␉␉␉␉␉uint64_t msr;␊ |
415 | ␉␉␉␉␉␉␉uint8_t i;␊ |
416 | ␉␉␉␉␉␉␉// Probe for lowest vid␊ |
417 | ␉␉␉␉␉␉␉for (i = maximum.VID; i > 0xA; i--) ␊ |
418 | ␉␉␉␉␉␉␉{␊ |
419 | ␉␉␉␉␉␉␉␉msr = rdmsr64(MSR_IA32_PERF_CONTROL);␊ |
420 | ␉␉␉␉␉␉␉␉wrmsr64(MSR_IA32_PERF_CONTROL, (msr & 0xFFFFFFFFFFFF0000ULL) | (minimum.FID << 8) | i);␊ |
421 | ␉␉␉␉␉␉␉␉intel_waitforsts();␊ |
422 | ␉␉␉␉␉␉␉␉minimum.VID = rdmsr64(MSR_IA32_PERF_STATUS) & 0x3F; ␊ |
423 | ␉␉␉␉␉␉␉␉delay(1);␊ |
424 | ␉␉␉␉␉␉␉}␊ |
425 | ␉␉␉␉␉␉␉␊ |
426 | ␉␉␉␉␉␉␉msr = rdmsr64(MSR_IA32_PERF_CONTROL);␊ |
427 | ␉␉␉␉␉␉␉wrmsr64(MSR_IA32_PERF_CONTROL, (msr & 0xFFFFFFFFFFFF0000ULL) | (maximum.FID << 8) | maximum.VID);␊ |
428 | ␉␉␉␉␉␉␉intel_waitforsts();␊ |
429 | ␉␉␉␉␉␉}␊ |
430 | ␉␉␉␉␉␉␊ |
431 | ␉␉␉␉␉␉minimum.CID = ((minimum.FID & 0x1F) << 1) >> cpu_dynamic_fsb;␊ |
432 | ␉␉␉␉␉␉␊ |
433 | ␉␉␉␉␉␉// Sanity check␊ |
434 | ␉␉␉␉␉␉if (maximum.CID < minimum.CID) ␊ |
435 | ␉␉␉␉␉␉{␊ |
436 | ␉␉␉␉␉␉␉DBG("Insane FID values!");␊ |
437 | ␉␉␉␉␉␉␉p_states_count = 0;␊ |
438 | ␉␉␉␉␉␉}␊ |
439 | ␉␉␉␉␉␉else␊ |
440 | ␉␉␉␉␉␉{␊ |
441 | ␉␉␉␉␉␉␉// Finalize P-States␊ |
442 | ␉␉␉␉␉␉␉// Find how many P-States machine supports␊ |
443 | ␉␉␉␉␉␉␉p_states_count = maximum.CID - minimum.CID + 1;␊ |
444 | ␉␉␉␉␉␉␉␊ |
445 | ␉␉␉␉␉␉␉if (p_states_count > 32) ␊ |
446 | ␉␉␉␉␉␉␉␉p_states_count = 32;␊ |
447 | ␉␉␉␉␉␉␉␊ |
448 | ␉␉␉␉␉␉␉uint8_t vidstep;␊ |
449 | ␉␉␉␉␉␉␉uint8_t i = 0, u, invalid = 0;␊ |
450 | ␉␉␉␉␉␉␉␊ |
451 | ␉␉␉␉␉␉␉vidstep = ((maximum.VID << 2) - (minimum.VID << 2)) / (p_states_count - 1);␊ |
452 | ␉␉␉␉␉␉␉␊ |
453 | ␉␉␉␉␉␉␉for (u = 0; u < p_states_count; u++) ␊ |
454 | ␉␉␉␉␉␉␉{␊ |
455 | ␉␉␉␉␉␉␉␉i = u - invalid;␊ |
456 | ␉␉␉␉␉␉␉␉␊ |
457 | ␉␉␉␉␉␉␉␉p_states[i].CID = maximum.CID - u;␊ |
458 | ␉␉␉␉␉␉␉␉p_states[i].FID = (p_states[i].CID >> 1);␊ |
459 | ␉␉␉␉␉␉␉␉␊ |
460 | ␉␉␉␉␉␉␉␉if (p_states[i].FID < 0x6) ␊ |
461 | ␉␉␉␉␉␉␉␉{␊ |
462 | ␉␉␉␉␉␉␉␉␉if (cpu_dynamic_fsb) ␊ |
463 | ␉␉␉␉␉␉␉␉␉␉p_states[i].FID = (p_states[i].FID << 1) | 0x80;␊ |
464 | ␉␉␉␉␉␉␉␉} ␊ |
465 | ␉␉␉␉␉␉␉␉else if (cpu_noninteger_bus_ratio) ␊ |
466 | ␉␉␉␉␉␉␉␉{␊ |
467 | ␉␉␉␉␉␉␉␉␉p_states[i].FID = p_states[i].FID | (0x40 * (p_states[i].CID & 0x1));␊ |
468 | ␉␉␉␉␉␉␉␉}␊ |
469 | ␉␉␉␉␉␉␉␉␊ |
470 | ␉␉␉␉␉␉␉␉if (i && p_states[i].FID == p_states[i-1].FID)␊ |
471 | ␉␉␉␉␉␉␉␉␉invalid++;␊ |
472 | ␉␉␉␉␉␉␉␉␊ |
473 | ␉␉␉␉␉␉␉␉p_states[i].VID = ((maximum.VID << 2) - (vidstep * u)) >> 2;␊ |
474 | ␉␉␉␉␉␉␉␉␊ |
475 | ␉␉␉␉␉␉␉␉uint32_t multiplier = p_states[i].FID & 0x1f;␉␉// = 0x08␊ |
476 | ␉␉␉␉␉␉␉␉bool half = p_states[i].FID & 0x40;␉␉␉␉␉// = 0x01␊ |
477 | ␉␉␉␉␉␉␉␉bool dfsb = p_states[i].FID & 0x80;␉␉␉␉␉// = 0x00␊ |
478 | ␉␉␉␉␉␉␉␉uint32_t fsb = Platform.CPU.FSBFrequency / 1000000; // = 400␊ |
479 | ␉␉␉␉␉␉␉␉uint32_t halffsb = (fsb + 1) >> 1;␉␉␉␉␉// = 200␊ |
480 | ␉␉␉␉␉␉␉␉uint32_t frequency = (multiplier * fsb);␉␉␉// = 3200␊ |
481 | ␉␉␉␉␉␉␉␉␊ |
482 | ␉␉␉␉␉␉␉␉p_states[i].Frequency = (frequency + (half * halffsb)) >> dfsb;␉// = 3200 + 200 = 3400␊ |
483 | ␉␉␉␉␉␉␉}␊ |
484 | ␉␉␉␉␉␉␉␊ |
485 | ␉␉␉␉␉␉␉p_states_count -= invalid;␊ |
486 | ␉␉␉␉␉␉}␊ |
487 | ␉␉␉␉␉␉␊ |
488 | ␉␉␉␉␉␉break;␊ |
489 | ␉␉␉␉␉} ␊ |
490 | ␉␉␉␉␉case CPU_MODEL_FIELDS:␉␉// Intel Core i5, i7, Xeon X34xx LGA1156 (45nm)␊ |
491 | ␉␉␉␉␉case CPU_MODEL_DALES:␉␉␊ |
492 | ␉␉␉␉␉case CPU_MODEL_DALES_32NM:␉// Intel Core i3, i5 LGA1156 (32nm)␊ |
493 | ␉␉␉␉␉case CPU_MODEL_NEHALEM:␉␉// Intel Core i7, Xeon W35xx, Xeon X55xx, Xeon E55xx LGA1366 (45nm)␊ |
494 | ␉␉␉␉␉case CPU_MODEL_NEHALEM_EX:␉// Intel Xeon X75xx, Xeon X65xx, Xeon E75xx, Xeon E65x␊ |
495 | ␉␉␉␉␉case CPU_MODEL_WESTMERE:␉// Intel Core i7, Xeon X56xx, Xeon E56xx, Xeon W36xx LGA1366 (32nm) 6 Core␊ |
496 | ␉␉␉␉␉case CPU_MODEL_WESTMERE_EX:␉// Intel Xeon E7␊ |
497 | case CPU_MODEL_SANDY:␉␉// Intel Core i3, i5, i7 LGA1155 (32nm)␊ |
498 | case CPU_MODEL_SANDY_XEON:␉// Intel Xeon E3␊ |
499 | ␉␉␉␉␉{␊ |
500 | ␉␉␉␉␉␉maximum.Control = rdmsr64(MSR_IA32_PERF_STATUS) & 0xff; // Seems it always contains maximum multiplier value (with turbo, that's we need)...␊ |
501 | ␉␉␉␉␉␉minimum.Control = (rdmsr64(MSR_PLATFORM_INFO) >> 40) & 0xff;␊ |
502 | ␉␉␉␉␉␉␊ |
503 | ␉␉␉␉␉␉verbose("P-States: min 0x%x, max 0x%x\n", minimum.Control, maximum.Control);␉␉␉␊ |
504 | ␉␉␉␉␉␉␊ |
505 | ␉␉␉␉␉␉// Sanity check␊ |
506 | ␉␉␉␉␉␉if (maximum.Control < minimum.Control) ␊ |
507 | ␉␉␉␉␉␉{␊ |
508 | ␉␉␉␉␉␉␉DBG("Insane control values!");␊ |
509 | ␉␉␉␉␉␉␉p_states_count = 0;␊ |
510 | ␉␉␉␉␉␉}␊ |
511 | ␉␉␉␉␉␉else␊ |
512 | ␉␉␉␉␉␉{␊ |
513 | ␉␉␉␉␉␉␉uint8_t i;␊ |
514 | ␉␉␉␉␉␉␉p_states_count = 0;␊ |
515 | ␉␉␉␉␉␉␉␊ |
516 | ␉␉␉␉␉␉␉for (i = maximum.Control; i >= minimum.Control; i--) ␊ |
517 | ␉␉␉␉␉␉␉{␊ |
518 | ␉␉␉␉␉␉␉␉p_states[p_states_count].Control = i;␊ |
519 | ␉␉␉␉␉␉␉␉p_states[p_states_count].CID = p_states[p_states_count].Control << 1;␊ |
520 | ␉␉␉␉␉␉␉␉p_states[p_states_count].Frequency = (Platform.CPU.FSBFrequency / 1000000) * i;␊ |
521 | ␉␉␉␉␉␉␉␉p_states_count++;␊ |
522 | ␉␉␉␉␉␉␉}␊ |
523 | ␉␉␉␉␉␉}␊ |
524 | ␉␉␉␉␉␉␊ |
525 | ␉␉␉␉␉␉break;␊ |
526 | ␉␉␉␉␉}␉␊ |
527 | ␉␉␉␉␉default:␊ |
528 | ␉␉␉␉␉␉verbose ("Unsupported CPU: P-States not generated !!!\n");␊ |
529 | ␉␉␉␉␉␉break;␊ |
530 | ␉␉␉␉}␊ |
531 | ␉␉␉}␊ |
532 | ␉␉}␊ |
533 | ␉␉␊ |
534 | ␉␉// Generating SSDT␊ |
535 | ␉␉if (p_states_count > 0) ␊ |
536 | ␉␉{␉␊ |
537 | ␉␉␉int i;␊ |
538 | ␉␉␉␊ |
539 | ␉␉␉struct aml_chunk* root = aml_create_node(NULL);␊ |
540 | ␉␉␉␉aml_add_buffer(root, ssdt_header, sizeof(ssdt_header)); // SSDT header␊ |
541 | ␉␉␉␉␉struct aml_chunk* scop = aml_add_scope(root, "\\_PR_");␊ |
542 | ␉␉␉␉␉␉struct aml_chunk* name = aml_add_name(scop, "PSS_");␊ |
543 | ␉␉␉␉␉␉␉struct aml_chunk* pack = aml_add_package(name);␊ |
544 | ␉␉␉␊ |
545 | ␉␉␉␉␉␉␉␉for (i = 0; i < p_states_count; i++) ␊ |
546 | ␉␉␉␉␉␉␉␉{␊ |
547 | ␉␉␉␉␉␉␉␉␉struct aml_chunk* pstt = aml_add_package(pack);␊ |
548 | ␉␉␉␉␉␉␉␉␉␊ |
549 | ␉␉␉␉␉␉␉␉␉aml_add_dword(pstt, p_states[i].Frequency);␊ |
550 | ␉␉␉␉␉␉␉␉␉aml_add_dword(pstt, 0x00000000); // Power␊ |
551 | ␉␉␉␉␉␉␉␉␉aml_add_dword(pstt, 0x0000000A); // Latency␊ |
552 | ␉␉␉␉␉␉␉␉␉aml_add_dword(pstt, 0x0000000A); // Latency␊ |
553 | ␉␉␉␉␉␉␉␉␉aml_add_dword(pstt, p_states[i].Control);␊ |
554 | ␉␉␉␉␉␉␉␉␉aml_add_dword(pstt, i+1); // Status␊ |
555 | ␉␉␉␉␉␉␉␉}␊ |
556 | ␉␉␉␉␊ |
557 | ␉␉␉// Add aliaces␊ |
558 | ␉␉␉for (i = 0; i < acpi_cpu_count; i++) ␊ |
559 | ␉␉␉{␊ |
560 | ␉␉␉␉char name[9];␊ |
561 | ␉␉␉␉sprintf(name, "_PR_%c%c%c%c", acpi_cpu_name[i][0], acpi_cpu_name[i][1], acpi_cpu_name[i][2], acpi_cpu_name[i][3]);␊ |
562 | ␉␉␉␉␊ |
563 | ␉␉␉␉scop = aml_add_scope(root, name);␊ |
564 | ␉␉␉␉aml_add_alias(scop, "PSS_", "_PSS");␊ |
565 | ␉␉␉}␊ |
566 | ␉␉␉␊ |
567 | ␉␉␉aml_calculate_size(root);␊ |
568 | ␉␉␉␊ |
569 | ␉␉␉struct acpi_2_ssdt *ssdt = (struct acpi_2_ssdt *)AllocateKernelMemory(root->Size);␊ |
570 | ␉␉␉␊ |
571 | ␉␉␉aml_write_node(root, (void*)ssdt, 0);␊ |
572 | ␉␉␉␊ |
573 | ␉␉␉ssdt->Length = root->Size;␊ |
574 | ␉␉␉ssdt->Checksum = 0;␊ |
575 | ␉␉␉ssdt->Checksum = 256 - checksum8(ssdt, ssdt->Length);␊ |
576 | ␉␉␉␊ |
577 | ␉␉␉aml_destroy_node(root);␊ |
578 | ␉␉␉␊ |
579 | ␉␉␉//dumpPhysAddr("P-States SSDT content: ", ssdt, ssdt->Length);␊ |
580 | ␉␉␉␊ |
581 | ␉␉␉verbose ("SSDT with CPU P-States generated successfully\n");␊ |
582 | ␉␉␉␊ |
583 | ␉␉␉return ssdt;␊ |
584 | ␉␉}␊ |
585 | ␉}␊ |
586 | ␉else ␊ |
587 | ␉{␊ |
588 | ␉␉verbose ("ACPI CPUs not found: P-States not generated !!!\n");␊ |
589 | ␉}␊ |
590 | ␉␊ |
591 | ␉return NULL;␊ |
592 | }␊ |
593 | ␊ |
594 | struct acpi_2_fadt *patch_fadt(struct acpi_2_fadt *fadt, struct acpi_2_dsdt *new_dsdt)␊ |
595 | {␊ |
596 | ␉extern void setupSystemType(); ␊ |
597 | ␉␊ |
598 | ␉struct acpi_2_fadt *fadt_mod;␊ |
599 | ␉bool fadt_rev2_needed = false;␊ |
600 | ␉bool fix_restart;␊ |
601 | ␉const char * value;␊ |
602 | ␉␊ |
603 | ␉// Restart Fix␊ |
604 | ␉if (Platform.CPU.Vendor == 0x756E6547) {␉/* Intel */␊ |
605 | ␉␉fix_restart = true;␊ |
606 | ␉␉getBoolForKey(kRestartFix, &fix_restart, &bootInfo->bootConfig);␊ |
607 | ␉} else {␊ |
608 | ␉␉verbose ("Not an Intel platform: Restart Fix not applied !!!\n");␊ |
609 | ␉␉fix_restart = false;␊ |
610 | ␉}␊ |
611 | ␉␊ |
612 | ␉if (fix_restart) fadt_rev2_needed = true;␊ |
613 | ␉␊ |
614 | ␉// Allocate new fadt table␊ |
615 | ␉if (fadt->Length < 0x84 && fadt_rev2_needed)␊ |
616 | ␉{␊ |
617 | ␉␉fadt_mod=(struct acpi_2_fadt *)AllocateKernelMemory(0x84);␊ |
618 | ␉␉memcpy(fadt_mod, fadt, fadt->Length);␊ |
619 | ␉␉fadt_mod->Length = 0x84;␊ |
620 | ␉␉fadt_mod->Revision = 0x02; // FADT rev 2 (ACPI 1.0B MS extensions)␊ |
621 | ␉}␊ |
622 | ␉else␊ |
623 | ␉{␊ |
624 | ␉␉fadt_mod=(struct acpi_2_fadt *)AllocateKernelMemory(fadt->Length);␊ |
625 | ␉␉memcpy(fadt_mod, fadt, fadt->Length);␊ |
626 | ␉}␊ |
627 | ␉// Determine system type / PM_Model␊ |
628 | ␉if ( (value=getStringForKey(kSystemType, &bootInfo->bootConfig))!=NULL)␊ |
629 | ␉{␊ |
630 | ␉␉if (Platform.Type > 6) ␊ |
631 | ␉␉{␊ |
632 | ␉␉␉if(fadt_mod->PM_Profile<=6)␊ |
633 | ␉␉␉␉Platform.Type = fadt_mod->PM_Profile; // get the fadt if correct␊ |
634 | ␉␉␉else ␊ |
635 | ␉␉␉␉Platform.Type = 1;␉␉/* Set a fixed value (Desktop) */␊ |
636 | ␉␉␉verbose("Error: system-type must be 0..6. Defaulting to %d !\n", Platform.Type);␊ |
637 | ␉␉}␊ |
638 | ␉␉else␊ |
639 | ␉␉␉Platform.Type = (unsigned char) strtoul(value, NULL, 10);␊ |
640 | ␉}␊ |
641 | ␉// Set PM_Profile from System-type if only user wanted this value to be forced␊ |
642 | ␉if (fadt_mod->PM_Profile != Platform.Type) ␊ |
643 | ␉{␊ |
644 | ␉ if (value) ␊ |
645 | ␉␉{ // user has overriden the SystemType so take care of it in FACP␊ |
646 | ␉␉␉verbose("FADT: changing PM_Profile from 0x%02x to 0x%02x\n", fadt_mod->PM_Profile, Platform.Type);␊ |
647 | ␉␉␉fadt_mod->PM_Profile = Platform.Type;␊ |
648 | ␉ }␊ |
649 | ␉ else␊ |
650 | ␉ { // PM_Profile has a different value and no override has been set, so reflect the user value to ioregs␊ |
651 | ␉␉␉Platform.Type = fadt_mod->PM_Profile <= 6 ? fadt_mod->PM_Profile : 1;␊ |
652 | ␉ } ␊ |
653 | ␉}␊ |
654 | ␉// We now have to write the systemm-type in ioregs: we cannot do it before in setupDeviceTree()␊ |
655 | ␉// because we need to take care of facp original content, if it is correct.␊ |
656 | ␉setupSystemType();␊ |
657 | ␉␊ |
658 | ␉// Patch FADT to fix restart␊ |
659 | ␉if (fix_restart)␊ |
660 | ␉{␊ |
661 | ␉␉fadt_mod->Flags|= 0x400;␊ |
662 | ␉␉fadt_mod->Reset_SpaceID␉␉= 0x01; // System I/O␊ |
663 | ␉␉fadt_mod->Reset_BitWidth␉= 0x08; // 1 byte␊ |
664 | ␉␉fadt_mod->Reset_BitOffset␉= 0x00; // Offset 0␊ |
665 | ␉␉fadt_mod->Reset_AccessWidth␉= 0x01; // Byte access␊ |
666 | ␉␉fadt_mod->Reset_Address␉␉= 0x0cf9; // Address of the register␊ |
667 | ␉␉fadt_mod->Reset_Value␉␉= 0x06; // Value to write to reset the system␊ |
668 | ␉␉verbose("FADT: Restart Fix applied!\n");␊ |
669 | ␉}␊ |
670 | ␉␊ |
671 | ␉// Patch DSDT Address if we have loaded DSDT.aml␊ |
672 | ␉if(new_dsdt)␊ |
673 | ␉{␊ |
674 | ␉␉DBG("DSDT: Old @%x,%x, ",fadt_mod->DSDT,fadt_mod->X_DSDT);␊ |
675 | ␉␉␊ |
676 | ␉␉fadt_mod->DSDT=(uint32_t)new_dsdt;␊ |
677 | ␉␉if ((uint32_t)(&(fadt_mod->X_DSDT))-(uint32_t)fadt_mod+8<=fadt_mod->Length)␊ |
678 | ␉␉␉fadt_mod->X_DSDT=(uint32_t)new_dsdt;␊ |
679 | ␉␉␊ |
680 | ␉␉DBG("New @%x,%x\n",fadt_mod->DSDT,fadt_mod->X_DSDT);␊ |
681 | ␉␉␊ |
682 | ␉␉verbose("FADT: Using custom DSDT!\n");␊ |
683 | ␉}␊ |
684 | ␉␊ |
685 | ␉// Correct the checksum␊ |
686 | ␉fadt_mod->Checksum=0;␊ |
687 | ␉fadt_mod->Checksum=256-checksum8(fadt_mod,fadt_mod->Length);␊ |
688 | ␉␊ |
689 | ␉return fadt_mod;␊ |
690 | }␊ |
691 | ␊ |
692 | /* Setup ACPI without replacing DSDT. */␊ |
693 | int setupAcpiNoMod()␊ |
694 | {␊ |
695 | ␉//␉addConfigurationTable(&gEfiAcpiTableGuid, getAddressOfAcpiTable(), "ACPI");␊ |
696 | ␉//␉addConfigurationTable(&gEfiAcpi20TableGuid, getAddressOfAcpi20Table(), "ACPI_20");␊ |
697 | ␉/* XXX aserebln why uint32 cast if pointer is uint64 ? */␊ |
698 | ␉acpi10_p = (uint32_t)getAddressOfAcpiTable();␊ |
699 | ␉acpi20_p = (uint32_t)getAddressOfAcpi20Table();␊ |
700 | ␉addConfigurationTable(&gEfiAcpiTableGuid, &acpi10_p, "ACPI");␊ |
701 | ␉if(acpi20_p) addConfigurationTable(&gEfiAcpi20TableGuid, &acpi20_p, "ACPI_20");␊ |
702 | ␉return 1;␊ |
703 | }␊ |
704 | ␊ |
705 | /* Setup ACPI. Replace DSDT if DSDT.aml is found */␊ |
706 | int setupAcpi(void)␊ |
707 | {␊ |
708 | ␉int version;␊ |
709 | ␉void *new_dsdt;␊ |
710 | ␊ |
711 | ␉const char *filename;␊ |
712 | ␉char dirSpec[128];␊ |
713 | ␉int len = 0;␊ |
714 | ␊ |
715 | ␉// Try using the file specified with the DSDT option␊ |
716 | ␉if (getValueForKey(kDSDT, &filename, &len, &bootInfo->bootConfig))␊ |
717 | ␉{␊ |
718 | ␉␉sprintf(dirSpec, filename);␊ |
719 | ␉}␊ |
720 | ␉else␊ |
721 | ␉{␊ |
722 | ␉␉sprintf(dirSpec, "DSDT.aml");␊ |
723 | ␉}␊ |
724 | ␉␊ |
725 | ␉// Load replacement DSDT␊ |
726 | ␉new_dsdt = loadACPITable(dirSpec);␊ |
727 | ␉// Mozodojo: going to patch FACP and load SSDT's even if DSDT.aml is not present␊ |
728 | ␉/*if (!new_dsdt)␊ |
729 | ␉ {␊ |
730 | ␉ return setupAcpiNoMod();␊ |
731 | ␉ }*/␊ |
732 | ␉␊ |
733 | ␉// Mozodojo: Load additional SSDTs␊ |
734 | ␉struct acpi_2_ssdt *new_ssdt[32]; // 30 + 2 additional tables for pss & cst␊ |
735 | ␉int ssdt_count=0;␊ |
736 | ␉␊ |
737 | ␉// SSDT Options␊ |
738 | ␉bool drop_ssdt=false, generate_pstates=false, generate_cstates=false; ␊ |
739 | ␉␊ |
740 | ␉getBoolForKey(kDropSSDT, &drop_ssdt, &bootInfo->bootConfig);␊ |
741 | ␉getBoolForKey(kGeneratePStates, &generate_pstates, &bootInfo->bootConfig);␊ |
742 | ␉getBoolForKey(kGenerateCStates, &generate_cstates, &bootInfo->bootConfig);␊ |
743 | ␉␊ |
744 | ␉{␊ |
745 | ␉␉int i;␊ |
746 | ␉␉␊ |
747 | ␉␉for (i=0; i<30; i++)␊ |
748 | ␉␉{␊ |
749 | ␉␉␉char filename[512];␊ |
750 | ␊ |
751 | ␉␉␉sprintf(filename, i>0?"SSDT-%d.aml":"SSDT.aml", i);␊ |
752 | ␉␉␉␊ |
753 | ␉␉␉if(new_ssdt[ssdt_count] = loadACPITable(filename)) ␊ |
754 | ␉␉␉{␉␉␉␉␊ |
755 | ␉␉␉␉ssdt_count++;␊ |
756 | ␉␉␉}␊ |
757 | ␉␉␉else ␊ |
758 | ␉␉␉{␊ |
759 | ␉␉␉␉break;␊ |
760 | ␉␉␉}␊ |
761 | ␉␉}␊ |
762 | ␉}␊ |
763 | ␉␉␊ |
764 | ␉// Do the same procedure for both versions of ACPI␊ |
765 | ␉for (version=0; version<2; version++) {␊ |
766 | ␉␉struct acpi_2_rsdp *rsdp, *rsdp_mod;␊ |
767 | ␉␉struct acpi_2_rsdt *rsdt, *rsdt_mod;␊ |
768 | ␉␉int rsdplength;␊ |
769 | ␉␉␊ |
770 | ␉␉// Find original rsdp␊ |
771 | ␉␉rsdp=(struct acpi_2_rsdp *)(version?getAddressOfAcpi20Table():getAddressOfAcpiTable());␊ |
772 | ␉␉if (!rsdp)␊ |
773 | ␉␉{␊ |
774 | ␉␉␉DBG("No ACPI version %d found. Ignoring\n", version+1);␊ |
775 | ␉␉␉if (version)␊ |
776 | ␉␉␉␉addConfigurationTable(&gEfiAcpi20TableGuid, NULL, "ACPI_20");␊ |
777 | ␉␉␉else␊ |
778 | ␉␉␉␉addConfigurationTable(&gEfiAcpiTableGuid, NULL, "ACPI");␊ |
779 | ␉␉␉continue;␊ |
780 | ␉␉}␊ |
781 | ␉␉rsdplength=version?rsdp->Length:20;␊ |
782 | ␉␉␊ |
783 | ␉␉DBG("RSDP version %d found @%x. Length=%d\n",version+1,rsdp,rsdplength);␊ |
784 | ␉␉␊ |
785 | ␉␉/* FIXME: no check that memory allocation succeeded ␊ |
786 | ␉␉ * Copy and patch RSDP,RSDT, XSDT and FADT␊ |
787 | ␉␉ * For more info see ACPI Specification pages 110 and following␊ |
788 | ␉␉ */␊ |
789 | ␉␉␊ |
790 | ␉␉rsdp_mod=(struct acpi_2_rsdp *) AllocateKernelMemory(rsdplength);␊ |
791 | ␉␉memcpy(rsdp_mod, rsdp, rsdplength); ␊ |
792 | ␉␉rsdt=(struct acpi_2_rsdt *)(rsdp->RsdtAddress);␊ |
793 | ␉␉␊ |
794 | ␉␉DBG("RSDT @%x, Length %d\n",rsdt, rsdt->Length);␊ |
795 | ␉␉␊ |
796 | ␉␉if (rsdt && (uint32_t)rsdt !=0xffffffff && rsdt->Length<0x10000)␊ |
797 | ␉␉{␊ |
798 | ␉␉␉uint32_t *rsdt_entries;␊ |
799 | ␉␉␉int rsdt_entries_num;␊ |
800 | ␉␉␉int dropoffset=0, i;␊ |
801 | ␉␉␉␊ |
802 | ␉␉␉// mozo: using malloc cos I didn't found how to free already allocated kernel memory␊ |
803 | ␉␉␉rsdt_mod=(struct acpi_2_rsdt *)malloc(rsdt->Length); ␊ |
804 | ␉␉␉memcpy (rsdt_mod, rsdt, rsdt->Length);␊ |
805 | ␉␉␉rsdp_mod->RsdtAddress=(uint32_t)rsdt_mod;␊ |
806 | ␉␉␉rsdt_entries_num=(rsdt_mod->Length-sizeof(struct acpi_2_rsdt))/4;␊ |
807 | ␉␉␉rsdt_entries=(uint32_t *)(rsdt_mod+1);␊ |
808 | ␉␉␉for (i=0;i<rsdt_entries_num;i++)␊ |
809 | ␉␉␉{␊ |
810 | ␉␉␉␉char *table=(char *)(rsdt_entries[i]);␊ |
811 | ␉␉␉␉if (!table)␊ |
812 | ␉␉␉␉␉continue;␊ |
813 | ␉␉␉␉␊ |
814 | ␉␉␉␉DBG("TABLE %c%c%c%c,",table[0],table[1],table[2],table[3]);␊ |
815 | ␉␉␉␉␊ |
816 | ␉␉␉␉rsdt_entries[i-dropoffset]=rsdt_entries[i];␊ |
817 | ␉␉␉␉␊ |
818 | ␉␉␉␉if (drop_ssdt && tableSign(table, "SSDT"))␊ |
819 | ␉␉␉␉{␊ |
820 | ␉␉␉␉␉dropoffset++;␊ |
821 | ␉␉␉␉␉continue;␊ |
822 | ␉␉␉␉}␊ |
823 | ␉␉␉␉if (tableSign(table, "DSDT"))␊ |
824 | ␉␉␉␉{␊ |
825 | ␉␉␉␉␉DBG("DSDT found\n");␊ |
826 | ␉␉␉␉␉␊ |
827 | ␉␉␉␉␉if(new_dsdt)␊ |
828 | ␉␉␉␉␉␉rsdt_entries[i-dropoffset]=(uint32_t)new_dsdt;␊ |
829 | ␉␉␉␉␉␉␉␉␉␉␊ |
830 | ␉␉␉␉␉continue;␊ |
831 | ␉␉␉␉}␊ |
832 | ␉␉␉␉if (tableSign(table, "FACP"))␊ |
833 | ␉␉␉␉{␊ |
834 | ␉␉␉␉␉struct acpi_2_fadt *fadt, *fadt_mod;␊ |
835 | ␉␉␉␉␉fadt=(struct acpi_2_fadt *)rsdt_entries[i];␊ |
836 | ␉␉␉␉␉␊ |
837 | ␉␉␉␉␉DBG("FADT found @%x, Length %d\n",fadt, fadt->Length);␊ |
838 | ␉␉␉␉␉␊ |
839 | ␉␉␉␉␉if (!fadt || (uint32_t)fadt == 0xffffffff || fadt->Length>0x10000)␊ |
840 | ␉␉␉␉␉{␊ |
841 | ␉␉␉␉␉␉printf("FADT incorrect. Not modified\n");␊ |
842 | ␉␉␉␉␉␉continue;␊ |
843 | ␉␉␉␉␉}␊ |
844 | ␉␉␉␉␉␊ |
845 | ␉␉␉␉␉fadt_mod = patch_fadt(fadt, new_dsdt);␊ |
846 | ␉␉␉␉␉rsdt_entries[i-dropoffset]=(uint32_t)fadt_mod;␊ |
847 | ␉␉␉␉␉␊ |
848 | ␉␉␉␉␉// Generate _CST SSDT␊ |
849 | ␉␉␉␉␉if (generate_cstates && (new_ssdt[ssdt_count] = generate_cst_ssdt(fadt_mod)))␊ |
850 | ␉␉␉␉␉{␊ |
851 | ␉␉␉␉␉␉generate_cstates = false; // Generate SSDT only once!␊ |
852 | ␉␉␉␉␉␉ssdt_count++;␊ |
853 | ␉␉␉␉␉}␊ |
854 | ␉␉␉␉␉␊ |
855 | ␉␉␉␉␉// Generating _PSS SSDT␊ |
856 | ␉␉␉␉␉if (generate_pstates && (new_ssdt[ssdt_count] = generate_pss_ssdt((void*)fadt_mod->DSDT)))␊ |
857 | ␉␉␉␉␉{␊ |
858 | ␉␉␉␉␉␉generate_pstates = false; // Generate SSDT only once!␊ |
859 | ␉␉␉␉␉␉ssdt_count++;␊ |
860 | ␉␉␉␉␉}␊ |
861 | ␉␉␉␉␉␊ |
862 | ␉␉␉␉␉continue;␊ |
863 | ␉␉␉␉}␊ |
864 | ␉␉␉}␊ |
865 | ␉␉␉DBG("\n");␊ |
866 | ␉␉␉␊ |
867 | ␉␉␉// Allocate rsdt in Kernel memory area␊ |
868 | ␉␉␉rsdt_mod->Length += 4*ssdt_count - 4*dropoffset;␊ |
869 | ␉␉␉struct acpi_2_rsdt *rsdt_copy = (struct acpi_2_rsdt *)AllocateKernelMemory(rsdt_mod->Length);␊ |
870 | ␉␉␉memcpy (rsdt_copy, rsdt_mod, rsdt_mod->Length);␊ |
871 | ␉␉␉free(rsdt_mod); rsdt_mod = rsdt_copy;␊ |
872 | ␉␉␉rsdp_mod->RsdtAddress=(uint32_t)rsdt_mod;␊ |
873 | ␉␉␉rsdt_entries_num=(rsdt_mod->Length-sizeof(struct acpi_2_rsdt))/4;␊ |
874 | ␉␉␉rsdt_entries=(uint32_t *)(rsdt_mod+1);␊ |
875 | ␉␉␉␊ |
876 | ␉␉␉// Mozodojo: Insert additional SSDTs into RSDT␊ |
877 | ␉␉␉if(ssdt_count>0)␊ |
878 | ␉␉␉{␊ |
879 | ␉␉␉␉int j;␊ |
880 | ␉␉␉␉␊ |
881 | ␉␉␉␉for (j=0; j<ssdt_count; j++)␊ |
882 | ␉␉␉␉␉rsdt_entries[i-dropoffset+j]=(uint32_t)new_ssdt[j];␊ |
883 | ␉␉␉␉␉␊ |
884 | ␉␉␉␉verbose("RSDT: Added %d SSDT table(s)\n", ssdt_count);␊ |
885 | ␉␉␉}␊ |
886 | ␊ |
887 | ␉␉␉// Correct the checksum of RSDT␊ |
888 | ␉␉␉DBG("RSDT: Original checksum %d, ", rsdt_mod->Checksum);␊ |
889 | ␉␉␉␊ |
890 | ␉␉␉rsdt_mod->Checksum=0;␊ |
891 | ␉␉␉rsdt_mod->Checksum=256-checksum8(rsdt_mod,rsdt_mod->Length);␊ |
892 | ␉␉␉␊ |
893 | ␉␉␉DBG("New checksum %d at %x\n", rsdt_mod->Checksum,rsdt_mod);␊ |
894 | ␉␉}␊ |
895 | ␉␉else␊ |
896 | ␉␉{␊ |
897 | ␉␉␉rsdp_mod->RsdtAddress=0;␊ |
898 | ␉␉␉printf("RSDT not found or RSDT incorrect\n");␊ |
899 | ␉␉}␊ |
900 | ␉␉␊ |
901 | ␉␉if (version)␊ |
902 | ␉␉{␊ |
903 | ␉␉␉struct acpi_2_xsdt *xsdt, *xsdt_mod;␊ |
904 | ␉␉␉␊ |
905 | ␉␉␉// FIXME: handle 64-bit address correctly␊ |
906 | ␉␉␉␊ |
907 | ␉␉␉xsdt=(struct acpi_2_xsdt*) ((uint32_t)rsdp->XsdtAddress);␊ |
908 | ␉␉␉DBG("XSDT @%x;%x, Length=%d\n", (uint32_t)(rsdp->XsdtAddress>>32),(uint32_t)rsdp->XsdtAddress,␊ |
909 | ␉␉␉␉xsdt->Length);␊ |
910 | ␉␉␉if (xsdt && (uint64_t)rsdp->XsdtAddress<0xffffffff && xsdt->Length<0x10000)␊ |
911 | ␉␉␉{␊ |
912 | ␉␉␉␉uint64_t *xsdt_entries;␊ |
913 | ␉␉␉␉int xsdt_entries_num, i;␊ |
914 | ␉␉␉␉int dropoffset=0;␊ |
915 | ␉␉␉␉␊ |
916 | ␉␉␉␉// mozo: using malloc cos I didn't found how to free already allocated kernel memory␊ |
917 | ␉␉␉␉xsdt_mod=(struct acpi_2_xsdt*)malloc(xsdt->Length); ␊ |
918 | ␉␉␉␉memcpy(xsdt_mod, xsdt, xsdt->Length);␊ |
919 | ␉␉␉␉rsdp_mod->XsdtAddress=(uint32_t)xsdt_mod;␊ |
920 | ␉␉␉␉xsdt_entries_num=(xsdt_mod->Length-sizeof(struct acpi_2_xsdt))/8;␊ |
921 | ␉␉␉␉xsdt_entries=(uint64_t *)(xsdt_mod+1);␊ |
922 | ␉␉␉␉for (i=0;i<xsdt_entries_num;i++)␊ |
923 | ␉␉␉␉{␊ |
924 | ␉␉␉␉␉char *table=(char *)((uint32_t)(xsdt_entries[i]));␊ |
925 | ␉␉␉␉␉if (!table)␊ |
926 | ␉␉␉␉␉␉continue;␊ |
927 | ␉␉␉␉␉␊ |
928 | ␉␉␉␉␉xsdt_entries[i-dropoffset]=xsdt_entries[i];␊ |
929 | ␉␉␉␉␉␊ |
930 | ␉␉␉␉␉if (drop_ssdt && tableSign(table, "SSDT"))␊ |
931 | ␉␉␉␉␉{␊ |
932 | ␉␉␉␉␉␉dropoffset++;␊ |
933 | ␉␉␉␉␉␉continue;␊ |
934 | ␉␉␉␉␉}␉␉␉␉␉␊ |
935 | ␉␉␉␉␉if (tableSign(table, "DSDT"))␊ |
936 | ␉␉␉␉␉{␊ |
937 | ␉␉␉␉␉␉DBG("DSDT found\n");␊ |
938 | ␉␉␉␉␉␉␊ |
939 | ␉␉␉␉␉␉if (new_dsdt) ␊ |
940 | ␉␉␉␉␉␉␉xsdt_entries[i-dropoffset]=(uint32_t)new_dsdt;␊ |
941 | ␉␉␉␉␉␉␊ |
942 | ␉␉␉␉␉␉DBG("TABLE %c%c%c%c@%x,",table[0],table[1],table[2],table[3],xsdt_entries[i]);␊ |
943 | ␉␉␉␉␉␉␊ |
944 | ␉␉␉␉␉␉continue;␊ |
945 | ␉␉␉␉␉}␊ |
946 | ␉␉␉␉␉if (tableSign(table, "FACP"))␊ |
947 | ␉␉␉␉␉{␊ |
948 | ␉␉␉␉␉␉struct acpi_2_fadt *fadt, *fadt_mod;␊ |
949 | ␉␉␉␉␉␉fadt=(struct acpi_2_fadt *)(uint32_t)xsdt_entries[i];␊ |
950 | ␉␉␉␉␉␉␊ |
951 | ␉␉␉␉␉␉DBG("FADT found @%x,%x, Length %d\n",(uint32_t)(xsdt_entries[i]>>32),fadt, ␊ |
952 | ␉␉␉␉␉␉␉fadt->Length);␊ |
953 | ␉␉␉␉␉␉␊ |
954 | ␉␉␉␉␉␉if (!fadt || (uint64_t)xsdt_entries[i] >= 0xffffffff || fadt->Length>0x10000)␊ |
955 | ␉␉␉␉␉␉{␊ |
956 | ␉␉␉␉␉␉␉verbose("FADT incorrect or after 4GB. Dropping XSDT\n");␊ |
957 | ␉␉␉␉␉␉␉goto drop_xsdt;␊ |
958 | ␉␉␉␉␉␉}␊ |
959 | ␉␉␉␉␉␉␊ |
960 | ␉␉␉␉␉␉fadt_mod = patch_fadt(fadt, new_dsdt);␊ |
961 | ␉␉␉␉␉␉xsdt_entries[i-dropoffset]=(uint32_t)fadt_mod;␊ |
962 | ␉␉␉␉␉␉␊ |
963 | ␉␉␉␉␉␉DBG("TABLE %c%c%c%c@%x,",table[0],table[1],table[2],table[3],xsdt_entries[i]);␊ |
964 | ␉␉␉␉␉␉␊ |
965 | ␉␉␉␉␉␉// Generate _CST SSDT␊ |
966 | ␉␉␉␉␉␉if (generate_cstates && (new_ssdt[ssdt_count] = generate_cst_ssdt(fadt_mod))) ␊ |
967 | ␉␉␉␉␉␉{␊ |
968 | ␉␉␉␉␉␉␉generate_cstates = false; // Generate SSDT only once!␊ |
969 | ␉␉␉␉␉␉␉ssdt_count++;␊ |
970 | ␉␉␉␉␉␉}␊ |
971 | ␉␉␉␉␉␉␊ |
972 | ␉␉␉␉␉␉// Generating _PSS SSDT␊ |
973 | ␉␉␉␉␉␉if (generate_pstates && (new_ssdt[ssdt_count] = generate_pss_ssdt((void*)fadt_mod->DSDT)))␊ |
974 | ␉␉␉␉␉␉{␊ |
975 | ␉␉␉␉␉␉␉generate_pstates = false; // Generate SSDT only once!␊ |
976 | ␉␉␉␉␉␉␉ssdt_count++;␊ |
977 | ␉␉␉␉␉␉}␊ |
978 | ␉␉␉␉␉␉␊ |
979 | ␉␉␉␉␉␉continue;␊ |
980 | ␉␉␉␉␉}␊ |
981 | ␉␉␉␉␉␊ |
982 | ␉␉␉␉␉DBG("TABLE %c%c%c%c@%x,",table[0],table[1],table[2],table[3],xsdt_entries[i]);␊ |
983 | ␉␉␉␉␉␊ |
984 | ␉␉␉␉}␊ |
985 | ␉␉␉␉␊ |
986 | ␉␉␉␉// Allocate xsdt in Kernel memory area␊ |
987 | ␉␉␉␉xsdt_mod->Length += 8*ssdt_count - 8*dropoffset;␊ |
988 | ␉␉␉␉struct acpi_2_xsdt *xsdt_copy = (struct acpi_2_xsdt *)AllocateKernelMemory(xsdt_mod->Length);␊ |
989 | ␉␉␉␉memcpy(xsdt_copy, xsdt_mod, xsdt_mod->Length);␊ |
990 | ␉␉␉␉free(xsdt_mod); xsdt_mod = xsdt_copy;␊ |
991 | ␉␉␉␉rsdp_mod->XsdtAddress=(uint32_t)xsdt_mod;␊ |
992 | ␉␉␉␉xsdt_entries_num=(xsdt_mod->Length-sizeof(struct acpi_2_xsdt))/8;␊ |
993 | ␉␉␉␉xsdt_entries=(uint64_t *)(xsdt_mod+1);␊ |
994 | ␉␉␉␉␊ |
995 | ␉␉␉␉// Mozodojo: Insert additional SSDTs into XSDT␊ |
996 | ␉␉␉␉if(ssdt_count>0)␊ |
997 | ␉␉␉␉{␊ |
998 | ␉␉␉␉␉int j;␊ |
999 | ␉␉␉␉␉␊ |
1000 | ␉␉␉␉␉for (j=0; j<ssdt_count; j++)␊ |
1001 | ␉␉␉␉␉␉xsdt_entries[i-dropoffset+j]=(uint32_t)new_ssdt[j];␊ |
1002 | ␉␉␉␉␉␉␊ |
1003 | ␉␉␉␉␉verbose("Added %d SSDT table(s) into XSDT\n", ssdt_count);␊ |
1004 | ␉␉␉␉}␊ |
1005 | ␊ |
1006 | ␉␉␉␉// Correct the checksum of XSDT␊ |
1007 | ␉␉␉␉xsdt_mod->Checksum=0;␊ |
1008 | ␉␉␉␉xsdt_mod->Checksum=256-checksum8(xsdt_mod,xsdt_mod->Length);␊ |
1009 | ␉␉␉}␊ |
1010 | ␉␉␉else␊ |
1011 | ␉␉␉{␊ |
1012 | ␉␉␉drop_xsdt:␊ |
1013 | ␉␉␉␉␊ |
1014 | ␉␉␉␉DBG("About to drop XSDT\n");␊ |
1015 | ␉␉␉␉␊ |
1016 | ␉␉␉␉/*FIXME: Now we just hope that if MacOS doesn't find XSDT it reverts to RSDT. ␊ |
1017 | ␉␉␉␉ * A Better strategy would be to generate␊ |
1018 | ␉␉␉␉ */␊ |
1019 | ␉␉␉␉␊ |
1020 | ␉␉␉␉rsdp_mod->XsdtAddress=0xffffffffffffffffLL;␊ |
1021 | ␉␉␉␉verbose("XSDT not found or XSDT incorrect\n");␊ |
1022 | ␉␉␉}␊ |
1023 | ␉␉}␊ |
1024 | ␉␉␊ |
1025 | ␉␉// Correct the checksum of RSDP ␊ |
1026 | ␉␉␊ |
1027 | ␉␉DBG("RSDP: Original checksum %d, ", rsdp_mod->Checksum);␊ |
1028 | ␉␉␊ |
1029 | ␉␉rsdp_mod->Checksum=0;␊ |
1030 | ␉␉rsdp_mod->Checksum=256-checksum8(rsdp_mod,20);␊ |
1031 | ␉␉␊ |
1032 | ␉␉DBG("New checksum %d\n", rsdp_mod->Checksum);␊ |
1033 | ␉␉␊ |
1034 | ␉␉if (version)␊ |
1035 | ␉␉{␊ |
1036 | ␉␉␉DBG("RSDP: Original extended checksum %d", rsdp_mod->ExtendedChecksum);␊ |
1037 | ␉␉␉␊ |
1038 | ␉␉␉rsdp_mod->ExtendedChecksum=0;␊ |
1039 | ␉␉␉rsdp_mod->ExtendedChecksum=256-checksum8(rsdp_mod,rsdp_mod->Length);␊ |
1040 | ␉␉␉␊ |
1041 | ␉␉␉DBG("New extended checksum %d\n", rsdp_mod->ExtendedChecksum);␊ |
1042 | ␉␉␉␊ |
1043 | ␉␉}␊ |
1044 | ␉␉␊ |
1045 | ␉␉//verbose("Patched ACPI version %d DSDT\n", version+1);␊ |
1046 | ␉␉if (version)␊ |
1047 | ␉␉{␊ |
1048 | ␉␉␉/* XXX aserebln why uint32 cast if pointer is uint64 ? */␊ |
1049 | ␉␉␉acpi20_p = (uint32_t)rsdp_mod;␊ |
1050 | ␉␉␉addConfigurationTable(&gEfiAcpi20TableGuid, &acpi20_p, "ACPI_20");␊ |
1051 | ␉␉}␊ |
1052 | ␉␉else␊ |
1053 | ␉␉{␊ |
1054 | ␉␉␉/* XXX aserebln why uint32 cast if pointer is uint64 ? */␊ |
1055 | ␉␉␉acpi10_p = (uint32_t)rsdp_mod;␊ |
1056 | ␉␉␉addConfigurationTable(&gEfiAcpiTableGuid, &acpi10_p, "ACPI");␊ |
1057 | ␉␉}␊ |
1058 | ␉}␊ |
1059 | #if DEBUG_ACPI␊ |
1060 | ␉printf("Press a key to continue... (DEBUG_ACPI)\n");␊ |
1061 | ␉getchar();␊ |
1062 | #endif␊ |
1063 | ␉return 1;␊ |
1064 | }␊ |
1065 | |