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