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