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