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