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