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