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