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