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