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 | ␊ |
50 | ␉for(; acpi_addr <= (void*)ACPI_RANGE_END; acpi_addr += 16)␊ |
51 | ␉{␊ |
52 | ␉␉if(*(uint64_t *)acpi_addr == ACPI_SIGNATURE_UINT64_LE)␊ |
53 | ␉␉{␊ |
54 | ␉␉␉uint8_t csum = checksum8(acpi_addr, 20);␊ |
55 | ␉␉␉if(csum == 0)␊ |
56 | ␉␉␉{␊ |
57 | ␉␉␉// Only return the table if it is a true version 1.0 table (Revision 0)␊ |
58 | ␉␉␉␉if(((struct acpi_2_rsdp*)acpi_addr)->Revision == 0)␊ |
59 | ␉␉␉␉return acpi_addr;␊ |
60 | ␉␉␉}␊ |
61 | ␉␉}␊ |
62 | ␉}␊ |
63 | ␉return NULL;␊ |
64 | }␊ |
65 | ␊ |
66 | /* Gets the ACPI 2.0 RSDP address */␊ |
67 | static struct acpi_2_rsdp* getAddressOfAcpi20Table()␊ |
68 | {␊ |
69 | ␉/* TODO: Before searching the BIOS space we are supposed to search the first 1K of the EBDA */␊ |
70 | ␊ |
71 | ␉void *acpi_addr = (void*)ACPI_RANGE_START;␊ |
72 | ␊ |
73 | ␉for(; acpi_addr <= (void*)ACPI_RANGE_END; acpi_addr += 16)␊ |
74 | ␉{␊ |
75 | ␉␉if(*(uint64_t *)acpi_addr == ACPI_SIGNATURE_UINT64_LE)␊ |
76 | ␉␉{␊ |
77 | ␉␉␉uint8_t csum = checksum8(acpi_addr, 20);␊ |
78 | ␊ |
79 | ␉␉␉/* Only assume this is a 2.0 or better table if the revision is greater than 0␊ |
80 | ␉␉␉ * NOTE: ACPI 3.0 spec only seems to say that 1.0 tables have revision 1␊ |
81 | ␉␉␉ * and that the current revision is 2.. I am going to assume that rev > 0 is 2.0.␊ |
82 | ␉␉␉ */␊ |
83 | ␊ |
84 | ␉␉␉if(csum == 0 && (((struct acpi_2_rsdp*)acpi_addr)->Revision > 0))␊ |
85 | ␉␉␉{␊ |
86 | ␉␉␉␉uint8_t csum2 = checksum8(acpi_addr, sizeof(struct acpi_2_rsdp));␊ |
87 | ␉␉␉␉if(csum2 == 0)␊ |
88 | ␉␉␉␉{␊ |
89 | ␉␉␉␉␉return acpi_addr;␊ |
90 | ␉␉␉␉}␊ |
91 | ␉␉␉}␊ |
92 | ␉␉}␊ |
93 | ␉}␊ |
94 | ␉return NULL;␊ |
95 | }␊ |
96 | ␊ |
97 | /* The folowing ACPI Table search algo. should be reused anywhere needed:*/␊ |
98 | /* WARNING: outDirspec string will be overwritten by subsequent calls! */␊ |
99 | int search_and_get_acpi_fd(const char * filename, const char ** outDirspec)␊ |
100 | {␊ |
101 | ␉int fd = 0;␊ |
102 | ␉static char dirSpec[512];␊ |
103 | ␊ |
104 | ␉// Try finding 'filename' in the usual places␊ |
105 | ␉// Start searching any potential location for ACPI Table␊ |
106 | ␉snprintf(dirSpec, sizeof(dirSpec), "%s", filename); ␊ |
107 | ␉fd = open(dirSpec, 0);␊ |
108 | ␉if (fd < 0)␊ |
109 | ␉{␊ |
110 | ␉␉snprintf(dirSpec, sizeof(dirSpec), "/Extra/%s", filename); ␊ |
111 | ␉␉fd = open(dirSpec, 0);␊ |
112 | ␉␉if (fd < 0)␊ |
113 | ␉␉{␊ |
114 | ␉␉␉snprintf(dirSpec, sizeof(dirSpec), "bt(0,0)/Extra/%s", filename);␊ |
115 | ␉␉␉fd = open(dirSpec, 0);␊ |
116 | ␉␉␉if (fd < 0)␊ |
117 | ␉␉␉{␊ |
118 | ␉␉␉␉// NOT FOUND:␊ |
119 | ␉␉␉␉DBG("ACPI Table not found: %s\n", filename);␊ |
120 | ␉␉␉␉*dirSpec = '\0';␊ |
121 | ␉␉␉}␊ |
122 | ␉␉}␊ |
123 | ␉}␊ |
124 | ␊ |
125 | ␉if (outDirspec) *outDirspec = dirSpec; ␊ |
126 | ␉return fd;␊ |
127 | }␊ |
128 | ␊ |
129 | void *loadACPITable (const char * filename)␊ |
130 | {␊ |
131 | ␉const char * dirspec=NULL;␊ |
132 | ␊ |
133 | ␉int fd = search_and_get_acpi_fd(filename, &dirspec);␊ |
134 | ␊ |
135 | ␉if (fd >= 0)␊ |
136 | ␉{␊ |
137 | ␉␉void *tableAddr = (void*)AllocateKernelMemory(file_size (fd));␊ |
138 | ␉␉if (tableAddr)␊ |
139 | ␉␉{␊ |
140 | ␉␉␉if (read (fd, tableAddr, file_size (fd))!=file_size (fd))␊ |
141 | ␉␉␉{␊ |
142 | ␉␉␉␉DBG("Couldn't read table %s\n",dirspec);␊ |
143 | ␉␉␉␉free (tableAddr);␊ |
144 | ␉␉␉␉close (fd);␊ |
145 | ␉␉␉␉return NULL;␊ |
146 | ␉␉␉}␊ |
147 | ␊ |
148 | ␉␉␉DBG("Table %s read and stored at: %x\n", dirspec, tableAddr);␊ |
149 | ␉␉␉close (fd);␊ |
150 | ␉␉␉return tableAddr;␊ |
151 | ␉␉}␊ |
152 | ␉␉close (fd);␊ |
153 | ␉␉DBG("Couldn't allocate memory for table \n", dirspec);␊ |
154 | ␉} ␊ |
155 | ␉//printf("Couldn't find table %s\n", filename);␊ |
156 | ␉return NULL;␊ |
157 | }␊ |
158 | ␊ |
159 | uint8_t␉acpi_cpu_count = 0;␊ |
160 | char* acpi_cpu_name[32];␊ |
161 | uint32_t acpi_cpu_p_blk = 0;␊ |
162 | ␊ |
163 | void get_acpi_cpu_names(unsigned char* dsdt, uint32_t length)␊ |
164 | {␊ |
165 | ␉uint32_t i;␊ |
166 | ␊ |
167 | ␉DBG("Start finding cpu names. length %d\n", length);␊ |
168 | ␊ |
169 | ␉for (i=0; i<length-7; i++)␊ |
170 | ␉{␊ |
171 | ␉␉if (dsdt[i] == 0x5B && dsdt[i+1] == 0x83) // ProcessorOP␊ |
172 | ␉␉{␊ |
173 | ␉␉␉DBG("DSDT: %x%x\n", dsdt[i], dsdt[i+1]);␊ |
174 | ␊ |
175 | ␉␉␉uint32_t offset = i + 3 + (dsdt[i+2] >> 6);␊ |
176 | ␊ |
177 | ␉␉␉bool add_name = true;␊ |
178 | ␊ |
179 | ␉␉␉uint8_t j;␊ |
180 | ␊ |
181 | ␉␉␉for (j=0; j<4; j++)␊ |
182 | ␉␉␉{␊ |
183 | ␉␉␉␉char c = dsdt[offset+j];␊ |
184 | ␊ |
185 | ␉␉␉␉if (!aml_isvalidchar(c))␊ |
186 | ␉␉␉␉{␊ |
187 | ␉␉␉␉␉add_name = false;␊ |
188 | ␉␉␉␉␉DBG("Invalid character found in ProcessorOP 0x%x!\n", c);␊ |
189 | ␉␉␉␉␉break;␊ |
190 | ␉␉␉␉}␊ |
191 | ␉␉␉}␊ |
192 | ␊ |
193 | ␉␉␉if (add_name)␊ |
194 | ␉␉␉{␊ |
195 | ␉␉␉␉acpi_cpu_name[acpi_cpu_count] = malloc(4);␊ |
196 | ␉␉␉␉memcpy(acpi_cpu_name[acpi_cpu_count], dsdt+offset, 4);␊ |
197 | ␉␉␉␉i = offset + 5;␊ |
198 | ␊ |
199 | ␉␉␉␉if (acpi_cpu_count == 0)␊ |
200 | ␉␉␉␉{␊ |
201 | ␉␉␉␉␉acpi_cpu_p_blk = dsdt[i] | (dsdt[i+1] << 8);␊ |
202 | ␉␉␉␉}␊ |
203 | ␊ |
204 | ␉␉␉␉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]);␊ |
205 | ␊ |
206 | ␉␉␉␉if (++acpi_cpu_count == 32)␊ |
207 | ␉␉␉␉{␊ |
208 | ␉␉␉␉␉return;␊ |
209 | ␉␉␉␉}␊ |
210 | ␉␉␉}␊ |
211 | ␉␉}␊ |
212 | ␉}␊ |
213 | ␊ |
214 | ␉DBG("End finding cpu names: cpu names found: %d\n", acpi_cpu_count);␊ |
215 | }␊ |
216 | ␊ |
217 | struct acpi_2_ssdt *generate_cst_ssdt(struct acpi_2_fadt* fadt)␊ |
218 | {␊ |
219 | ␉static char const ssdt_header[] = // cst_ssdt_header␊ |
220 | ␉{␊ |
221 | ␉␉0x53, 0x53, 0x44, 0x54, 0xE7, 0x00, 0x00, 0x00, /* SSDT.... */␊ |
222 | ␉␉0x01, 0x17, 0x50, 0x6D, 0x52, 0x65, 0x66, 0x41, /* ..PmRefA */␊ |
223 | ␉␉0x43, 0x70, 0x75, 0x43, 0x73, 0x74, 0x00, 0x00, /* CpuCst.. */␊ |
224 | ␉␉0x00, 0x10, 0x00, 0x00, 0x49, 0x4E, 0x54, 0x4C, /* ....INTL */␊ |
225 | ␉␉0x31, 0x03, 0x10, 0x20␉␉␉␉␉␉␉/* 1.._␉␉*/␊ |
226 | ␉};␊ |
227 | ␉␊ |
228 | ␉char resource_template_register_fixedhw[] =␊ |
229 | ␉{␊ |
230 | ␉␉0x11, 0x14, 0x0A, 0x11, 0x82, 0x0C, 0x00, 0x7F,␊ |
231 | ␉␉0x01, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,␊ |
232 | ␉␉0x00, 0x00, 0x01, 0x79, 0x00␊ |
233 | ␉};␊ |
234 | ␊ |
235 | ␉char resource_template_register_systemio[] =␊ |
236 | ␉{␊ |
237 | ␉␉0x11, 0x14, 0x0A, 0x11, 0x82, 0x0C, 0x00, 0x01,␊ |
238 | ␉␉0x08, 0x00, 0x00, 0x15, 0x04, 0x00, 0x00, 0x00,␊ |
239 | ␉␉0x00, 0x00, 0x00, 0x79, 0x00,␊ |
240 | ␉};␊ |
241 | ␊ |
242 | ␉if (Platform.CPU.Vendor != 0x756E6547) {␊ |
243 | ␉␉DBG("Not an Intel platform: C-States will not be generated !!!\n");␊ |
244 | ␉␉return NULL;␊ |
245 | ␉}␊ |
246 | ␊ |
247 | ␉if (fadt == NULL) {␊ |
248 | ␉␉DBG("FACP not exists: C-States will not be generated !!!\n");␊ |
249 | ␉␉return NULL;␊ |
250 | ␉}␊ |
251 | ␊ |
252 | ␉struct acpi_2_dsdt* dsdt = (void*)fadt->DSDT;␊ |
253 | ␊ |
254 | ␉if (dsdt == NULL) {␊ |
255 | ␉␉DBG("DSDT not found: C-States will not be generated !!!\n");␊ |
256 | ␉␉return NULL;␊ |
257 | ␉}␊ |
258 | ␊ |
259 | ␉if (acpi_cpu_count == 0)␊ |
260 | ␉␉get_acpi_cpu_names((void*)dsdt, dsdt->Length);␊ |
261 | ␊ |
262 | ␉if (acpi_cpu_count > 0)␊ |
263 | ␉{␊ |
264 | ␉␉bool c2_enabled = false;␊ |
265 | ␉␉bool c3_enabled = false;␊ |
266 | ␉␉bool c4_enabled = false;␊ |
267 | ␉␉bool cst_using_systemio = false;␊ |
268 | ␊ |
269 | ␉␉getBoolForKey(kEnableC2State, &c2_enabled, &bootInfo->chameleonConfig);␊ |
270 | ␉␉getBoolForKey(kEnableC3State, &c3_enabled, &bootInfo->chameleonConfig);␊ |
271 | ␉␉getBoolForKey(kEnableC4State, &c4_enabled, &bootInfo->chameleonConfig);␊ |
272 | ␉␉getBoolForKey(kCSTUsingSystemIO, &cst_using_systemio, &bootInfo->chameleonConfig);␊ |
273 | ␊ |
274 | ␉␉c2_enabled = c2_enabled | (fadt->C2_Latency < 100);␊ |
275 | ␉␉c3_enabled = c3_enabled | (fadt->C3_Latency < 1000);␊ |
276 | ␊ |
277 | ␉␉unsigned char cstates_count = 1 + (c2_enabled ? 1 : 0) + (c3_enabled ? 1 : 0);␊ |
278 | ␊ |
279 | ␉␉AML_CHUNK* root = aml_create_node(NULL);␊ |
280 | ␉␉aml_add_buffer(root, ssdt_header, sizeof(ssdt_header)); // SSDT header␊ |
281 | ␉␉AML_CHUNK* scop = aml_add_scope(root, "\\_PR_");␊ |
282 | ␉␉AML_CHUNK* name = aml_add_name(scop, "CST_");␊ |
283 | ␉␉AML_CHUNK* pack = aml_add_package(name);␊ |
284 | ␉␉aml_add_byte(pack, cstates_count);␊ |
285 | ␊ |
286 | ␉␉AML_CHUNK* tmpl = aml_add_package(pack);␊ |
287 | ␉␉if (cst_using_systemio) {␊ |
288 | ␉␉␉// C1␊ |
289 | ␉␉␉resource_template_register_fixedhw[8] = 0x00;␊ |
290 | ␉␉␉resource_template_register_fixedhw[9] = 0x00;␊ |
291 | ␉␉␉resource_template_register_fixedhw[18] = 0x00;␊ |
292 | ␉␉␉aml_add_buffer(tmpl, resource_template_register_fixedhw, sizeof(resource_template_register_fixedhw));␊ |
293 | ␉␉␉aml_add_byte(tmpl, 0x01);␉␉// C1␊ |
294 | ␉␉␉aml_add_word(tmpl, 0x0001);␉␉// Latency␊ |
295 | ␉␉␉aml_add_dword(tmpl, 0x000003e8);␉// Power␊ |
296 | ␊ |
297 | ␉␉␉uint8_t p_blk_lo, p_blk_hi;␊ |
298 | ␊ |
299 | ␉␉␉if (c2_enabled) // C2␊ |
300 | ␉␉␉{␊ |
301 | ␉␉␉␉p_blk_lo = acpi_cpu_p_blk + 4;␊ |
302 | ␉␉␉␉p_blk_hi = (acpi_cpu_p_blk + 4) >> 8;␊ |
303 | ␊ |
304 | ␉␉␉␉tmpl = aml_add_package(pack);␊ |
305 | ␉␉␉␉resource_template_register_systemio[11] = p_blk_lo; // C2␊ |
306 | ␉␉␉␉resource_template_register_systemio[12] = p_blk_hi; // C2␊ |
307 | ␉␉␉␉aml_add_buffer(tmpl, resource_template_register_systemio, sizeof(resource_template_register_systemio));␊ |
308 | ␉␉␉␉aml_add_byte(tmpl, 0x02);␉␉// C2␊ |
309 | ␉␉␉␉aml_add_word(tmpl, 0x0040);␉␉// Latency␊ |
310 | ␉␉␉␉aml_add_dword(tmpl, 0x000001f4);␉// Power␊ |
311 | ␉␉␉}␊ |
312 | ␊ |
313 | ␉␉␉if (c4_enabled) // C4␊ |
314 | ␉␉␉{␊ |
315 | ␉␉␉␉p_blk_lo = acpi_cpu_p_blk + 5;␊ |
316 | ␉␉␉␉p_blk_hi = (acpi_cpu_p_blk + 5) >> 8;␊ |
317 | ␊ |
318 | ␉␉␉␉tmpl = aml_add_package(pack);␊ |
319 | ␉␉␉␉resource_template_register_systemio[11] = p_blk_lo; // C4␊ |
320 | ␉␉␉␉resource_template_register_systemio[12] = p_blk_hi; // C4␊ |
321 | ␉␉␉␉aml_add_buffer(tmpl, resource_template_register_systemio, sizeof(resource_template_register_systemio));␊ |
322 | ␉␉␉␉aml_add_byte(tmpl, 0x04);␉␉// C4␊ |
323 | ␉␉␉␉aml_add_word(tmpl, 0x0080);␉␉// Latency␊ |
324 | ␉␉␉␉aml_add_dword(tmpl, 0x000000C8);␉// Power␊ |
325 | ␉␉␉}␊ |
326 | ␉␉␉else if (c3_enabled) // C3␊ |
327 | ␉␉␉{␊ |
328 | ␉␉␉␉p_blk_lo = acpi_cpu_p_blk + 5;␊ |
329 | ␉␉␉␉p_blk_hi = (acpi_cpu_p_blk + 5) >> 8;␊ |
330 | ␊ |
331 | ␉␉␉␉tmpl = aml_add_package(pack);␊ |
332 | ␉␉␉␉resource_template_register_systemio[11] = p_blk_lo; // C3␊ |
333 | ␉␉␉␉resource_template_register_systemio[12] = p_blk_hi; // C3␊ |
334 | ␉␉␉␉aml_add_buffer(tmpl, resource_template_register_systemio, sizeof(resource_template_register_systemio));␊ |
335 | ␉␉␉␉aml_add_byte(tmpl, 0x03);␉␉// C3␊ |
336 | ␉␉␉␉aml_add_word(tmpl, 0x0060);␉␉// Latency␊ |
337 | ␉␉␉␉aml_add_dword(tmpl, 0x0000015e);␉// Power␊ |
338 | ␉␉␉}␊ |
339 | ␉␉}␊ |
340 | ␉␉else␊ |
341 | ␉␉{␊ |
342 | ␉␉␉// C1␊ |
343 | ␉␉␉resource_template_register_fixedhw[8] = 0x01;␊ |
344 | ␉␉␉resource_template_register_fixedhw[9] = 0x02;␊ |
345 | ␉␉␉resource_template_register_fixedhw[18] = 0x01;␊ |
346 | ␊ |
347 | ␉␉␉resource_template_register_fixedhw[11] = 0x00; // C1␊ |
348 | ␉␉␉aml_add_buffer(tmpl, resource_template_register_fixedhw, sizeof(resource_template_register_fixedhw));␊ |
349 | ␉␉␉aml_add_byte(tmpl, 0x01);␉␉// C1␊ |
350 | ␉␉␉aml_add_word(tmpl, 0x0001);␉␉// Latency␊ |
351 | ␉␉␉aml_add_dword(tmpl, 0x000003e8);␉// Power␊ |
352 | ␊ |
353 | ␉␉␉resource_template_register_fixedhw[18] = 0x03;␊ |
354 | ␊ |
355 | ␉␉␉if (c2_enabled) // C2␊ |
356 | ␉␉␉{␊ |
357 | ␉␉␉␉tmpl = aml_add_package(pack);␊ |
358 | ␉␉␉␉resource_template_register_fixedhw[11] = 0x10; // C2␊ |
359 | ␉␉␉␉aml_add_buffer(tmpl, resource_template_register_fixedhw, sizeof(resource_template_register_fixedhw));␊ |
360 | ␉␉␉␉aml_add_byte(tmpl, 0x02);␉␉// C2␊ |
361 | ␉␉␉␉aml_add_word(tmpl, 0x0040);␉␉// Latency␊ |
362 | ␉␉␉␉aml_add_dword(tmpl, 0x000001f4);␉// Power␊ |
363 | ␉␉␉}␊ |
364 | ␊ |
365 | ␉␉␉if (c4_enabled) // C4␊ |
366 | ␉␉␉{␊ |
367 | ␉␉␉␉tmpl = aml_add_package(pack);␊ |
368 | ␉␉␉␉resource_template_register_fixedhw[11] = 0x30; // C4␊ |
369 | ␉␉␉␉aml_add_buffer(tmpl, resource_template_register_fixedhw, sizeof(resource_template_register_fixedhw));␊ |
370 | ␉␉␉␉aml_add_byte(tmpl, 0x04);␉␉// C4␊ |
371 | ␉␉␉␉aml_add_word(tmpl, 0x0080);␉␉// Latency␊ |
372 | ␉␉␉␉aml_add_dword(tmpl, 0x000000C8);␉// Power␊ |
373 | ␉␉␉}␊ |
374 | ␉␉␉else if (c3_enabled)␊ |
375 | ␉␉␉{␊ |
376 | ␉␉␉␉tmpl = aml_add_package(pack);␊ |
377 | ␉␉␉␉resource_template_register_fixedhw[11] = 0x20; // C3␊ |
378 | ␉␉␉␉aml_add_buffer(tmpl, resource_template_register_fixedhw, sizeof(resource_template_register_fixedhw));␊ |
379 | ␉␉␉␉aml_add_byte(tmpl, 0x03);␉␉// C3␊ |
380 | ␉␉␉␉aml_add_word(tmpl, 0x0060);␉␉// Latency␊ |
381 | ␉␉␉␉aml_add_dword(tmpl, 0x0000015e);␉// Power␊ |
382 | ␉␉␉}␊ |
383 | ␉␉}␊ |
384 | ␊ |
385 | ␉␉// Aliaces␊ |
386 | ␉␉int i;␊ |
387 | ␉␉for (i = 0; i < acpi_cpu_count; i++) ␊ |
388 | ␉␉{␊ |
389 | ␉␉␉char name[9];␊ |
390 | ␉␉␉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]);␊ |
391 | ␊ |
392 | ␉␉␉scop = aml_add_scope(root, name);␊ |
393 | ␉␉␉␉aml_add_alias(scop, "CST_", "_CST");␊ |
394 | ␉␉}␊ |
395 | ␊ |
396 | ␉␉aml_calculate_size(root);␊ |
397 | ␊ |
398 | ␉␉struct acpi_2_ssdt *ssdt = (struct acpi_2_ssdt *)AllocateKernelMemory(root->Size);␊ |
399 | ␊ |
400 | ␉␉aml_write_node(root, (void*)ssdt, 0);␊ |
401 | ␊ |
402 | ␉␉ssdt->Length = root->Size;␊ |
403 | ␉␉ssdt->Checksum = 0;␊ |
404 | ␉␉ssdt->Checksum = 256 - checksum8(ssdt, ssdt->Length);␊ |
405 | ␊ |
406 | ␉␉aml_destroy_node(root);␊ |
407 | ␊ |
408 | ␉␉// dumpPhysAddr("C-States SSDT content: ", ssdt, ssdt->Length);␊ |
409 | ␉␉␊ |
410 | ␉␉DBG("SSDT with CPU C-States generated successfully\n");␊ |
411 | ␊ |
412 | ␉␉return ssdt;␊ |
413 | ␉} else {␊ |
414 | ␉␉DBG("ACPI CPUs not found: C-States not generated !!!\n");␊ |
415 | ␉}␊ |
416 | ␊ |
417 | ␉return NULL;␊ |
418 | }␊ |
419 | ␊ |
420 | struct acpi_2_ssdt *generate_pss_ssdt(struct acpi_2_dsdt* dsdt)␊ |
421 | {␊ |
422 | ␉static char const ssdt_header[] = // pss_ssdt_header␊ |
423 | ␉{␊ |
424 | ␉␉0x53, 0x53, 0x44, 0x54, 0x7E, 0x00, 0x00, 0x00, /* SSDT.... */␊ |
425 | ␉␉0x01, 0x6A, 0x50, 0x6D, 0x52, 0x65, 0x66, 0x00, /* ..PmRef. */␊ |
426 | ␉␉0x43, 0x70, 0x75, 0x50, 0x6D, 0x00, 0x00, 0x00, /* CpuPm... */␊ |
427 | ␉␉0x00, 0x30, 0x00, 0x00, 0x49, 0x4E, 0x54, 0x4C, /* .0..INTL */␊ |
428 | ␉␉0x31, 0x03, 0x10, 0x20,␉␉␉␉␉␉␉/* 1.._␉␉*/␊ |
429 | ␉};␊ |
430 | ␊ |
431 | ␉if (Platform.CPU.Vendor != 0x756E6547) {␊ |
432 | ␉␉DBG("Not an Intel platform: P-States will not be generated !!!\n");␊ |
433 | ␉␉return NULL;␊ |
434 | ␉}␊ |
435 | ␊ |
436 | ␉if (!(Platform.CPU.Features & CPU_FEATURE_MSR)) {␊ |
437 | ␉␉DBG("Unsupported CPU: P-States will not be generated !!! No MSR support\n");␊ |
438 | ␉␉return NULL;␊ |
439 | ␉}␊ |
440 | ␊ |
441 | ␉if (acpi_cpu_count == 0)␊ |
442 | ␉␉get_acpi_cpu_names((void*)dsdt, dsdt->Length);␊ |
443 | ␊ |
444 | ␉if (acpi_cpu_count > 0)␊ |
445 | ␉{␊ |
446 | ␉␉struct p_state initial, maximum, minimum, p_states[32];␊ |
447 | ␉␉uint8_t p_states_count = 0;␊ |
448 | ␊ |
449 | ␉␉// Retrieving P-States, ported from code by superhai (c)␊ |
450 | ␉␉switch (Platform.CPU.Family) {␊ |
451 | ␉␉␉case 0x06:␊ |
452 | ␉␉␉{␊ |
453 | ␉␉␉␉switch (Platform.CPU.Model) ␊ |
454 | ␉␉␉␉{␊ |
455 | ␉␉␉␉␉case CPU_MODEL_DOTHAN:␉// Intel Pentium M␊ |
456 | ␉␉␉␉␉case CPU_MODEL_YONAH:␉// Intel Mobile Core Solo, Duo␊ |
457 | ␉␉␉␉␉case CPU_MODEL_MEROM:␉// Intel Mobile Core 2 Solo, Duo, Xeon 30xx, Xeon 51xx, Xeon X53xx, Xeon E53xx, Xeon X32xx␊ |
458 | ␉␉␉␉␉case CPU_MODEL_PENRYN:␉// Intel Core 2 Solo, Duo, Quad, Extreme, Xeon X54xx, Xeon X33xx␊ |
459 | ␉␉␉␉␉case CPU_MODEL_ATOM:␉// Intel Atom (45nm)␊ |
460 | ␉␉␉␉␉{␊ |
461 | ␉␉␉␉␉␉bool cpu_dynamic_fsb = false;␊ |
462 | ␊ |
463 | ␉␉␉␉␉␉if (rdmsr64(MSR_IA32_EXT_CONFIG) & (1 << 27)) ␊ |
464 | ␉␉␉␉␉␉{␊ |
465 | ␉␉␉␉␉␉␉wrmsr64(MSR_IA32_EXT_CONFIG, (rdmsr64(MSR_IA32_EXT_CONFIG) | (1 << 28))); ␊ |
466 | ␉␉␉␉␉␉␉delay(1);␊ |
467 | ␉␉␉␉␉␉␉cpu_dynamic_fsb = rdmsr64(MSR_IA32_EXT_CONFIG) & (1 << 28);␊ |
468 | ␉␉␉␉␉␉}␊ |
469 | ␊ |
470 | ␉␉␉␉␉␉bool cpu_noninteger_bus_ratio = (rdmsr64(MSR_IA32_PERF_STATUS) & (1ULL << 46));␊ |
471 | ␊ |
472 | ␉␉␉␉␉␉initial.Control = rdmsr64(MSR_IA32_PERF_STATUS);␊ |
473 | ␊ |
474 | ␉␉␉␉␉␉maximum.Control = ((rdmsr64(MSR_IA32_PERF_STATUS) >> 32) & 0x1F3F) | (0x4000 * cpu_noninteger_bus_ratio);␊ |
475 | ␉␉␉␉␉␉maximum.CID = ((maximum.FID & 0x1F) << 1) | cpu_noninteger_bus_ratio;␊ |
476 | ␊ |
477 | ␉␉␉␉␉␉minimum.FID = ((rdmsr64(MSR_IA32_PERF_STATUS) >> 24) & 0x1F) | (0x80 * cpu_dynamic_fsb);␊ |
478 | ␉␉␉␉␉␉minimum.VID = ((rdmsr64(MSR_IA32_PERF_STATUS) >> 48) & 0x3F);␊ |
479 | ␊ |
480 | ␉␉␉␉␉␉if (minimum.FID == 0) ␊ |
481 | ␉␉␉␉␉␉{␊ |
482 | ␉␉␉␉␉␉␉uint64_t msr;␊ |
483 | ␉␉␉␉␉␉␉uint8_t i;␊ |
484 | ␉␉␉␉␉␉␉// Probe for lowest fid␊ |
485 | ␉␉␉␉␉␉␉for (i = maximum.FID; i >= 0x6; i--)␊ |
486 | ␉␉␉␉␉␉␉{␊ |
487 | ␉␉␉␉␉␉␉␉msr = rdmsr64(MSR_IA32_PERF_CONTROL);␊ |
488 | ␉␉␉␉␉␉␉␉wrmsr64(MSR_IA32_PERF_CONTROL, (msr & 0xFFFFFFFFFFFF0000ULL) | (i << 8) | minimum.VID);␊ |
489 | ␉␉␉␉␉␉␉␉intel_waitforsts();␊ |
490 | ␉␉␉␉␉␉␉␉minimum.FID = (rdmsr64(MSR_IA32_PERF_STATUS) >> 8) & 0x1F; ␊ |
491 | ␉␉␉␉␉␉␉␉delay(1);␊ |
492 | ␉␉␉␉␉␉␉}␊ |
493 | ␊ |
494 | ␉␉␉␉␉␉␉msr = rdmsr64(MSR_IA32_PERF_CONTROL);␊ |
495 | ␉␉␉␉␉␉␉wrmsr64(MSR_IA32_PERF_CONTROL, (msr & 0xFFFFFFFFFFFF0000ULL) | (maximum.FID << 8) | maximum.VID);␊ |
496 | ␉␉␉␉␉␉␉intel_waitforsts();␊ |
497 | ␉␉␉␉␉␉}␊ |
498 | ␊ |
499 | ␉␉␉␉␉␉if (minimum.VID == maximum.VID) ␊ |
500 | ␉␉␉␉␉␉{␊ |
501 | ␉␉␉␉␉␉␉uint64_t msr;␊ |
502 | ␉␉␉␉␉␉␉uint8_t i;␊ |
503 | ␉␉␉␉␉␉␉// Probe for lowest vid␊ |
504 | ␉␉␉␉␉␉␉for (i = maximum.VID; i > 0xA; i--) ␊ |
505 | ␉␉␉␉␉␉␉{␊ |
506 | ␉␉␉␉␉␉␉␉msr = rdmsr64(MSR_IA32_PERF_CONTROL);␊ |
507 | ␉␉␉␉␉␉␉␉wrmsr64(MSR_IA32_PERF_CONTROL, (msr & 0xFFFFFFFFFFFF0000ULL) | (minimum.FID << 8) | i);␊ |
508 | ␉␉␉␉␉␉␉␉intel_waitforsts();␊ |
509 | ␉␉␉␉␉␉␉␉minimum.VID = rdmsr64(MSR_IA32_PERF_STATUS) & 0x3F; ␊ |
510 | ␉␉␉␉␉␉␉␉delay(1);␊ |
511 | ␉␉␉␉␉␉␉}␊ |
512 | ␊ |
513 | ␉␉␉␉␉␉␉msr = rdmsr64(MSR_IA32_PERF_CONTROL);␊ |
514 | ␉␉␉␉␉␉␉wrmsr64(MSR_IA32_PERF_CONTROL, (msr & 0xFFFFFFFFFFFF0000ULL) | (maximum.FID << 8) | maximum.VID);␊ |
515 | ␉␉␉␉␉␉␉intel_waitforsts();␊ |
516 | ␉␉␉␉␉␉}␊ |
517 | ␊ |
518 | ␉␉␉␉␉␉minimum.CID = ((minimum.FID & 0x1F) << 1) >> cpu_dynamic_fsb;␊ |
519 | ␊ |
520 | ␉␉␉␉␉␉// Sanity check␊ |
521 | ␉␉␉␉␉␉if (maximum.CID < minimum.CID) {␊ |
522 | ␉␉␉␉␉␉␉DBG("P-States: Insane FID values!");␊ |
523 | ␉␉␉␉␉␉␉p_states_count = 0;␊ |
524 | ␉␉␉␉␉␉} else {␊ |
525 | ␉␉␉␉␉␉␉uint8_t vidstep;␊ |
526 | ␉␉␉␉␉␉␉uint8_t u, invalid = 0;␊ |
527 | ␉␉␉␉␉␉␉// Finalize P-States␊ |
528 | ␉␉␉␉␉␉␉// Find how many P-States machine supports␊ |
529 | ␉␉␉␉␉␉␉p_states_count = (uint8_t)(maximum.CID - minimum.CID + 1);␊ |
530 | ␊ |
531 | ␉␉␉␉␉␉␉if (p_states_count > 32) {␊ |
532 | ␉␉␉␉␉␉␉␉p_states_count = 32;␊ |
533 | ␉␉␉␉␉␉␉}␊ |
534 | ␊ |
535 | ␉␉␉␉␉␉␉vidstep = ((maximum.VID << 2) - (minimum.VID << 2)) / (p_states_count - 1);␊ |
536 | ␊ |
537 | ␉␉␉␉␉␉␉for (u = 0; u < p_states_count; u++) {␊ |
538 | ␉␉␉␉␉␉␉␉uint8_t i = u - invalid;␊ |
539 | ␊ |
540 | ␉␉␉␉␉␉␉␉p_states[i].CID = maximum.CID - u;␊ |
541 | ␉␉␉␉␉␉␉␉p_states[i].FID = (uint8_t)(p_states[i].CID >> 1);␊ |
542 | ␊ |
543 | ␉␉␉␉␉␉␉␉if (p_states[i].FID < 0x6) {␊ |
544 | ␉␉␉␉␉␉␉␉␉if (cpu_dynamic_fsb) {␊ |
545 | ␉␉␉␉␉␉␉␉␉␉p_states[i].FID = (p_states[i].FID << 1) | 0x80;␊ |
546 | ␉␉␉␉␉␉␉␉␉}␊ |
547 | ␉␉␉␉␉␉␉␉} else if (cpu_noninteger_bus_ratio) {␊ |
548 | ␉␉␉␉␉␉␉␉␉p_states[i].FID = p_states[i].FID | (0x40 * (p_states[i].CID & 0x1));␊ |
549 | ␉␉␉␉␉␉␉␉}␊ |
550 | ␊ |
551 | ␉␉␉␉␉␉␉␉if (i && p_states[i].FID == p_states[i-1].FID) {␊ |
552 | ␉␉␉␉␉␉␉␉␉invalid++;␊ |
553 | ␉␉␉␉␉␉␉␉}␊ |
554 | ␉␉␉␉␉␉␉␉p_states[i].VID = ((maximum.VID << 2) - (vidstep * u)) >> 2;␊ |
555 | ␉␉␉␉␉␉␉␉uint32_t multiplier = p_states[i].FID & 0x1f;␉␉// = 0x08␊ |
556 | ␉␉␉␉␉␉␉␉bool half = p_states[i].FID & 0x40;␉␉␉␉␉// = 0x01␊ |
557 | ␉␉␉␉␉␉␉␉bool dfsb = p_states[i].FID & 0x80;␉␉␉␉␉// = 0x00␊ |
558 | ␉␉␉␉␉␉␉␉uint32_t fsb = (uint32_t)(Platform.CPU.FSBFrequency / 1000000); // = 400␊ |
559 | ␉␉␉␉␉␉␉␉uint32_t halffsb = (fsb + 1) >> 1;␉␉␉␉␉// = 200␊ |
560 | ␉␉␉␉␉␉␉␉uint32_t frequency = (multiplier * fsb);␉␉␉// = 3200␊ |
561 | ␊ |
562 | ␉␉␉␉␉␉␉␉p_states[i].Frequency = (uint32_t)(frequency + (half * halffsb)) >> dfsb;␉// = 3200 + 200 = 3400␊ |
563 | ␉␉␉␉␉␉␉}␊ |
564 | ␊ |
565 | ␉␉␉␉␉␉␉p_states_count -= invalid;␊ |
566 | ␉␉␉␉␉␉}␊ |
567 | ␊ |
568 | ␉␉␉␉␉␉break;␊ |
569 | ␉␉␉␉␉}␊ |
570 | ␉␉␉␉␉case CPU_MODEL_FIELDS:␉␉// Intel Core i5, i7, Xeon X34xx LGA1156 (45nm)␊ |
571 | ␉␉␉␉␉case CPU_MODEL_DALES:␉␉␊ |
572 | ␉␉␉␉␉case CPU_MODEL_DALES_32NM:␉// Intel Core i3, i5 LGA1156 (32nm)␊ |
573 | ␉␉␉␉␉case CPU_MODEL_NEHALEM:␉␉// Intel Core i7, Xeon W35xx, Xeon X55xx, Xeon E55xx LGA1366 (45nm)␊ |
574 | ␉␉␉␉␉case CPU_MODEL_NEHALEM_EX:␉// Intel Xeon X75xx, Xeon X65xx, Xeon E75xx, Xeon E65xx␊ |
575 | ␉␉␉␉␉case CPU_MODEL_WESTMERE:␉// Intel Core i7, Xeon X56xx, Xeon E56xx, Xeon W36xx LGA1366 (32nm) 6 Core␊ |
576 | ␉␉␉␉␉case CPU_MODEL_WESTMERE_EX:␉// Intel Xeon E7␊ |
577 | ␉␉␉␉␉case CPU_MODEL_SANDYBRIDGE:␉// Intel Core i3, i5, i7 LGA1155 (32nm)␊ |
578 | ␉␉␉␉␉case CPU_MODEL_JAKETOWN:// Intel Core i7, Xeon E5 LGA2011 (32nm)␊ |
579 | ␉␉␉␉␉case CPU_MODEL_IVYBRIDGE:␉// Intel Core i3, i5, i7 LGA1155 (22nm)␊ |
580 | ␉␉␉␉␉case CPU_MODEL_HASWELL:␉//␊ |
581 | ␉␉␉␉␉case CPU_MODEL_IVYBRIDGE_XEON: //␊ |
582 | ␉␉␉␉␉//case CPU_MODEL_HASWELL_H:␉//␊ |
583 | ␉␉␉␉␉case CPU_MODEL_HASWELL_SVR:␉//␊ |
584 | ␉␉␉␉␉case CPU_MODEL_HASWELL_ULT:␉//␊ |
585 | ␉␉␉␉␉case CPU_MODEL_CRYSTALWELL:␉//␊ |
586 | ␊ |
587 | ␉␉␉␉␉{␊ |
588 | ␉␉␉␉␉if ((Platform.CPU.Model == CPU_MODEL_SANDYBRIDGE) || (Platform.CPU.Model == CPU_MODEL_JAKETOWN) ||␊ |
589 | ␉␉␉␉␉␉(Platform.CPU.Model == CPU_MODEL_IVYBRIDGE) || (Platform.CPU.Model == CPU_MODEL_HASWELL) ||␊ |
590 | ␉␉␉␉␉␉(Platform.CPU.Model == CPU_MODEL_IVYBRIDGE_XEON) || (Platform.CPU.Model == CPU_MODEL_HASWELL_SVR) ||␊ |
591 | ␉␉␉␉␉␉(Platform.CPU.Model == CPU_MODEL_HASWELL_ULT) || (Platform.CPU.Model == CPU_MODEL_CRYSTALWELL))␊ |
592 | ␉␉␉␉␉{␊ |
593 | ␉␉␉␉␉␉maximum.Control = (rdmsr64(MSR_IA32_PERF_STATUS) >> 8) & 0xff;␊ |
594 | ␉␉␉␉␉} else {␊ |
595 | ␉␉␉␉␉␉maximum.Control = rdmsr64(MSR_IA32_PERF_STATUS) & 0xff;␊ |
596 | ␉␉␉␉␉}␊ |
597 | ␊ |
598 | ␉␉␉␉␉minimum.Control = (rdmsr64(MSR_PLATFORM_INFO) >> 40) & 0xff;␊ |
599 | ␊ |
600 | ␉␉␉␉␉␉DBG("P-States: min 0x%x, max 0x%x\n", minimum.Control, maximum.Control);␊ |
601 | ␊ |
602 | ␉␉␉␉␉␉// Sanity check␊ |
603 | ␉␉␉␉␉␉if (maximum.Control < minimum.Control) {␊ |
604 | ␉␉␉␉␉␉␉DBG("Insane control values!");␊ |
605 | ␉␉␉␉␉␉␉p_states_count = 0;␊ |
606 | ␉␉␉␉␉␉} else {␊ |
607 | ␉␉␉␉␉␉␉uint8_t i;␊ |
608 | ␉␉␉␉␉␉␉p_states_count = 0;␊ |
609 | ␊ |
610 | ␉␉␉␉␉␉␉for (i = maximum.Control; i >= minimum.Control; i--) {␊ |
611 | ␉␉␉␉␉␉␉␉p_states[p_states_count].Control = i;␊ |
612 | ␉␉␉␉␉␉␉␉p_states[p_states_count].CID = p_states[p_states_count].Control << 1;␊ |
613 | ␉␉␉␉␉␉␉␉p_states[p_states_count].Frequency = (Platform.CPU.FSBFrequency / 1000000) * i;␊ |
614 | ␉␉␉␉␉␉␉␉p_states_count++;␊ |
615 | ␉␉␉␉␉␉␉}␊ |
616 | ␉␉␉␉␉␉}␊ |
617 | ␊ |
618 | ␉␉␉␉␉␉break;␊ |
619 | ␉␉␉␉␉}␊ |
620 | ␉␉␉␉␉default:␊ |
621 | ␉␉␉␉␉␉DBG("Unsupported CPU (0x%X): P-States not generated !!!\n", Platform.CPU.Family);␊ |
622 | ␉␉␉␉␉␉break;␊ |
623 | ␉␉␉␉}␊ |
624 | ␉␉␉}␊ |
625 | ␉␉}␊ |
626 | ␊ |
627 | ␉␉// Generating SSDT␊ |
628 | ␉␉if (p_states_count > 0) {␊ |
629 | ␉␉␉int i;␊ |
630 | ␊ |
631 | ␉␉␉AML_CHUNK* root = aml_create_node(NULL);␊ |
632 | ␉␉␉␉aml_add_buffer(root, ssdt_header, sizeof(ssdt_header)); // SSDT header␊ |
633 | ␉␉␉␉␉AML_CHUNK* scop = aml_add_scope(root, "\\_PR_");␊ |
634 | ␉␉␉␉␉␉AML_CHUNK* name = aml_add_name(scop, "PSS_");␊ |
635 | ␉␉␉␉␉␉␉AML_CHUNK* pack = aml_add_package(name);␊ |
636 | ␊ |
637 | ␉␉␉␉␉␉␉␉for (i = 0; i < p_states_count; i++) {␊ |
638 | ␉␉␉␉␉␉␉␉␉AML_CHUNK* pstt = aml_add_package(pack);␊ |
639 | ␊ |
640 | ␉␉␉␉␉␉␉␉␉aml_add_dword(pstt, p_states[i].Frequency);␊ |
641 | ␉␉␉␉␉␉␉␉␉aml_add_dword(pstt, 0x00000000); // Power␊ |
642 | ␉␉␉␉␉␉␉␉␉aml_add_dword(pstt, 0x0000000A); // Latency␊ |
643 | ␉␉␉␉␉␉␉␉␉aml_add_dword(pstt, 0x0000000A); // Latency␊ |
644 | ␉␉␉␉␉␉␉␉␉aml_add_dword(pstt, p_states[i].Control);␊ |
645 | ␉␉␉␉␉␉␉␉␉aml_add_dword(pstt, i+1); // Status␊ |
646 | ␉␉␉␉␉␉␉␉}␊ |
647 | ␊ |
648 | ␉␉␉// Add aliaces␊ |
649 | ␉␉␉for (i = 0; i < acpi_cpu_count; i++) {␊ |
650 | ␉␉␉␉char name[9];␊ |
651 | ␉␉␉␉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]);␊ |
652 | ␊ |
653 | ␉␉␉␉scop = aml_add_scope(root, name);␊ |
654 | ␉␉␉␉aml_add_alias(scop, "PSS_", "_PSS");␊ |
655 | ␉␉␉}␊ |
656 | ␊ |
657 | ␉␉␉aml_calculate_size(root);␊ |
658 | ␊ |
659 | ␉␉␉struct acpi_2_ssdt *ssdt = (struct acpi_2_ssdt *)AllocateKernelMemory(root->Size);␊ |
660 | ␊ |
661 | ␉␉␉aml_write_node(root, (void*)ssdt, 0);␊ |
662 | ␊ |
663 | ␉␉␉ssdt->Length = root->Size;␊ |
664 | ␉␉␉ssdt->Checksum = 0;␊ |
665 | ␉␉␉ssdt->Checksum = 256 - (uint8_t)(checksum8(ssdt, ssdt->Length));␊ |
666 | ␊ |
667 | ␉␉␉aml_destroy_node(root);␊ |
668 | ␊ |
669 | ␉␉␉//dumpPhysAddr("P-States SSDT content: ", ssdt, ssdt->Length);␊ |
670 | ␊ |
671 | ␉␉␉DBG("SSDT with CPU P-States generated successfully\n");␊ |
672 | ␊ |
673 | ␉␉␉return ssdt;␊ |
674 | ␉␉}␊ |
675 | ␉} else {␊ |
676 | ␉␉DBG("ACPI CPUs not found: P-States not generated !!!\n");␊ |
677 | ␉}␊ |
678 | ␊ |
679 | ␉return NULL;␊ |
680 | }␊ |
681 | ␊ |
682 | struct acpi_2_fadt *patch_fadt(struct acpi_2_fadt *fadt, struct acpi_2_dsdt *new_dsdt)␊ |
683 | {␊ |
684 | ␉extern void setupSystemType(); ␊ |
685 | ␊ |
686 | ␉struct acpi_2_fadt *fadt_mod = NULL;␊ |
687 | ␉bool fadt_rev2_needed = false;␊ |
688 | ␉bool fix_restart;␊ |
689 | ␉bool fix_restart_ps2;␊ |
690 | ␉const char * value;␊ |
691 | ␊ |
692 | ␉// Restart Fix␊ |
693 | ␉if (Platform.CPU.Vendor == 0x756E6547)␊ |
694 | ␉{␉/* Intel */␊ |
695 | ␉␉fix_restart = true;␊ |
696 | ␉␉fix_restart_ps2 = false;␊ |
697 | ␉␉if ( getBoolForKey(kPS2RestartFix, &fix_restart_ps2, &bootInfo->chameleonConfig) && fix_restart_ps2)␊ |
698 | ␉␉{␊ |
699 | ␉␉␉fix_restart = true;␊ |
700 | ␉␉}␊ |
701 | ␉␉else␊ |
702 | ␉␉{␊ |
703 | ␉␉␉getBoolForKey(kRestartFix, &fix_restart, &bootInfo->chameleonConfig);␊ |
704 | ␉␉}␊ |
705 | ␉}␊ |
706 | ␉else␊ |
707 | ␉{␊ |
708 | ␉␉DBG("Not an Intel platform: Restart Fix not applied !!!\n");␊ |
709 | ␉␉fix_restart = false;␊ |
710 | ␉}␊ |
711 | ␊ |
712 | ␉if (fix_restart)␊ |
713 | ␉{␊ |
714 | ␉␉fadt_rev2_needed = true;␊ |
715 | ␉}␊ |
716 | ␊ |
717 | ␉// Allocate new fadt table␊ |
718 | ␉if (fadt->Length < 0x84 && fadt_rev2_needed)␊ |
719 | ␉{␊ |
720 | ␉␉fadt_mod=(struct acpi_2_fadt *)AllocateKernelMemory(0x84);␊ |
721 | ␉␉memcpy(fadt_mod, fadt, fadt->Length);␊ |
722 | ␉␉fadt_mod->Length = 0x84;␊ |
723 | ␉␉fadt_mod->Revision = 0x02; // FADT rev 2 (ACPI 1.0B MS extensions)␊ |
724 | ␉}␊ |
725 | ␉else␊ |
726 | ␉{␊ |
727 | ␉␉fadt_mod=(struct acpi_2_fadt *)AllocateKernelMemory(fadt->Length);␊ |
728 | ␉␉memcpy(fadt_mod, fadt, fadt->Length);␊ |
729 | ␉}␊ |
730 | ␉// Determine system type / PM_Model␊ |
731 | ␉if ( (value=getStringForKey(kSystemType, &bootInfo->chameleonConfig))!=NULL)␊ |
732 | ␉{␊ |
733 | ␉␉if (Platform.Type > 6)␊ |
734 | ␉␉{␊ |
735 | ␉␉␉if(fadt_mod->PM_Profile<=6)␊ |
736 | ␉␉␉{␊ |
737 | ␉␉␉␉Platform.Type = fadt_mod->PM_Profile; // get the fadt if correct␊ |
738 | ␉␉␉}␊ |
739 | ␉␉␉else␊ |
740 | ␉␉␉{␊ |
741 | ␉␉␉␉Platform.Type = 1;␉␉/* Set a fixed value (Desktop) */␊ |
742 | ␉␉␉}␊ |
743 | ␉␉␉DBG("Error: system-type must be 0..6. Defaulting to %d !\n", Platform.Type);␊ |
744 | ␉␉}␊ |
745 | ␉␉else␊ |
746 | ␉␉{␊ |
747 | ␉␉␉Platform.Type = (unsigned char) strtoul(value, NULL, 10);␊ |
748 | ␉␉}␊ |
749 | ␉}␊ |
750 | ␉// Set PM_Profile from System-type if only user wanted this value to be forced␊ |
751 | ␉if (fadt_mod->PM_Profile != Platform.Type)␊ |
752 | ␉{␊ |
753 | ␉␉if (value)␊ |
754 | ␉␉{␊ |
755 | ␉␉␉// user has overriden the SystemType so take care of it in FACP␊ |
756 | ␉␉␉DBG("FADT: changing PM_Profile from 0x%02x to 0x%02x\n", fadt_mod->PM_Profile, Platform.Type);␊ |
757 | ␉␉␉fadt_mod->PM_Profile = Platform.Type;␊ |
758 | ␉␉}␊ |
759 | ␉␉else␊ |
760 | ␉␉{␊ |
761 | ␉␉␉// PM_Profile has a different value and no override has been set, so reflect the user value to ioregs␊ |
762 | ␉␉␉Platform.Type = fadt_mod->PM_Profile <= 6 ? fadt_mod->PM_Profile : 1;␊ |
763 | ␉␉}␊ |
764 | ␉}␊ |
765 | ␉// We now have to write the systemm-type in ioregs: we cannot do it before in setupDeviceTree()␊ |
766 | ␉// because we need to take care of FACP original content, if it is correct.␊ |
767 | ␉setupSystemType();␊ |
768 | ␊ |
769 | ␉// Patch FADT to fix restart␊ |
770 | ␉if (fix_restart)␊ |
771 | ␉{␊ |
772 | ␉␉if (fix_restart_ps2)␊ |
773 | ␉␉{␊ |
774 | ␉␉␉fadt_mod->Flags|= 0x400;␊ |
775 | ␉␉␉fadt_mod->Reset_SpaceID␉␉= 0x01; // System I/O␊ |
776 | ␉␉␉fadt_mod->Reset_BitWidth␉= 0x08; // 1 byte␊ |
777 | ␉␉␉fadt_mod->Reset_BitOffset␉= 0x00; // Offset 0␊ |
778 | ␉␉␉fadt_mod->Reset_AccessWidth␉= 0x01; // Byte access␊ |
779 | ␉␉␉fadt_mod->Reset_Address␉␉= 0x64; // Address of the register␊ |
780 | ␉␉␉fadt_mod->Reset_Value␉␉= 0xfe; // Value to write to reset the system␊ |
781 | ␉␉␉DBG("FADT: PS2 Restart Fix applied!\n");␊ |
782 | ␉␉}␊ |
783 | ␉␉else␊ |
784 | ␉␉{␊ |
785 | ␉␉␉fadt_mod->Flags|= 0x400;␊ |
786 | ␉␉␉fadt_mod->Reset_SpaceID␉␉= 0x01; // System I/O␊ |
787 | ␉␉␉fadt_mod->Reset_BitWidth␉= 0x08; // 1 byte␊ |
788 | ␉␉␉fadt_mod->Reset_BitOffset␉= 0x00; // Offset 0␊ |
789 | ␉␉␉fadt_mod->Reset_AccessWidth␉= 0x01; // Byte access␊ |
790 | ␉␉␉fadt_mod->Reset_Address␉␉= 0x0cf9; // Address of the register␊ |
791 | ␉␉␉fadt_mod->Reset_Value␉␉= 0x06; // Value to write to reset the system␊ |
792 | ␉␉␉DBG("FADT: ACPI Restart Fix applied!\n");␊ |
793 | ␉␉}␊ |
794 | ␊ |
795 | ␉}␊ |
796 | ␊ |
797 | ␉// Patch DSDT Address if we have loaded DSDT.aml␊ |
798 | ␉if(new_dsdt)␊ |
799 | ␉{␊ |
800 | ␉␉DBG("DSDT: Old @%x,%x, ",fadt_mod->DSDT,fadt_mod->X_DSDT);␊ |
801 | ␊ |
802 | ␉␉fadt_mod->DSDT=(uint32_t)new_dsdt;␊ |
803 | ␉␉if ((uint32_t)(&(fadt_mod->X_DSDT))-(uint32_t)fadt_mod+8<=fadt_mod->Length)␊ |
804 | ␉␉{␊ |
805 | ␉␉␉fadt_mod->X_DSDT=(uint32_t)new_dsdt;␊ |
806 | ␉␉}␊ |
807 | ␊ |
808 | ␉␉DBG("New @%x,%x\n",fadt_mod->DSDT,fadt_mod->X_DSDT);␊ |
809 | ␊ |
810 | ␉␉DBG("FADT: Using custom DSDT!\n");␊ |
811 | ␉}␊ |
812 | ␊ |
813 | ␉// Correct the checksum␊ |
814 | ␉fadt_mod->Checksum=0;␊ |
815 | ␉fadt_mod->Checksum=256-checksum8(fadt_mod,fadt_mod->Length);␊ |
816 | ␊ |
817 | ␉return fadt_mod;␊ |
818 | }␊ |
819 | ␊ |
820 | /* Setup ACPI without replacing DSDT. */␊ |
821 | int setupAcpiNoMod()␊ |
822 | {␊ |
823 | //␉addConfigurationTable(&gEfiAcpiTableGuid, getAddressOfAcpiTable(), "ACPI");␊ |
824 | //␉addConfigurationTable(&gEfiAcpi20TableGuid, getAddressOfAcpi20Table(), "ACPI_20");␊ |
825 | ␉/* XXX aserebln why uint32 cast if pointer is uint64 ? */␊ |
826 | ␉acpi10_p = (uint64_t)(uint32_t)getAddressOfAcpiTable();␊ |
827 | ␉acpi20_p = (uint64_t)(uint32_t)getAddressOfAcpi20Table();␊ |
828 | ␉addConfigurationTable(&gEfiAcpiTableGuid, &acpi10_p, "ACPI");␊ |
829 | ␉if(acpi20_p)␊ |
830 | ␉{␊ |
831 | ␉␉addConfigurationTable(&gEfiAcpi20TableGuid, &acpi20_p, "ACPI_20");␊ |
832 | ␉}␊ |
833 | ␉else␊ |
834 | ␉{␊ |
835 | ␉␉DBG("No ACPI 2.\n");␊ |
836 | ␉}␊ |
837 | ␉return 1;␊ |
838 | }␊ |
839 | ␊ |
840 | /* Setup ACPI. Replace DSDT if DSDT.aml is found */␊ |
841 | int setupAcpi(void)␊ |
842 | {␊ |
843 | ␉int version;␊ |
844 | ␊ |
845 | ␉// ACPI Tables␊ |
846 | ␉bool drop_dmar = getBoolForKey(kDropDMAR, &drop_dmar, &bootInfo->chameleonConfig);␊ |
847 | ␉bool drop_hpet = getBoolForKey(kDropHPET, &drop_hpet, &bootInfo->chameleonConfig);␊ |
848 | ␉bool drop_slic = getBoolForKey(kDropSLIC, &drop_slic, &bootInfo->chameleonConfig);␊ |
849 | ␉bool drop_sbst = getBoolForKey(kDropSBST, &drop_sbst, &bootInfo->chameleonConfig);␊ |
850 | ␉bool drop_ecdt = getBoolForKey(kDropECDT, &drop_ecdt, &bootInfo->chameleonConfig);␊ |
851 | ␉bool drop_asft = getBoolForKey(kDropASFT, &drop_asft, &bootInfo->chameleonConfig);␊ |
852 | ␊ |
853 | ␉void *new_dsdt = NULL; // DSDT.aml DSDT␊ |
854 | ␉void *new_hpet = NULL; // HPET.aml HPET␊ |
855 | ␉void *new_sbst = NULL; // SBST.aml SBST␊ |
856 | ␉void *new_ecdt = NULL; // ECDT.aml ECDT␊ |
857 | ␉void *new_asft = NULL; // ASFT.aml ASF!␊ |
858 | ␉void *new_dmar = NULL; // DMAR.aml DMAR␊ |
859 | ␉void *new_apic = NULL; // APIC.aml APIC␊ |
860 | ␉void *new_mcfg = NULL; // MCFG.aml MCFG␊ |
861 | ␊ |
862 | ␉const char *filename;␊ |
863 | ␉char dirSpec[128];␊ |
864 | ␉int len = 0;␊ |
865 | ␊ |
866 | ␉// always reset cpu count to 0 when injecting new acpi␊ |
867 | ␉acpi_cpu_count = 0;␊ |
868 | ␊ |
869 | ␉/* Try using the file specified with the DSDT option */␊ |
870 | ␉if (getValueForKey(kDSDT, &filename, &len, &bootInfo->chameleonConfig))␊ |
871 | ␉{␊ |
872 | ␉␉snprintf(dirSpec, sizeof(dirSpec), filename);␊ |
873 | ␉}␊ |
874 | ␉else␊ |
875 | ␉{␊ |
876 | ␉␉sprintf(dirSpec, "DSDT.aml");␊ |
877 | ␉␉//verbose("dirSpec, DSDT.aml");␊ |
878 | ␉}␊ |
879 | ␊ |
880 | ␉// Load replacement DSDT␊ |
881 | ␉new_dsdt = loadACPITable(dirSpec);␊ |
882 | ␊ |
883 | ␉/* Try using the file specified with the HPET option */␊ |
884 | ␉if (getValueForKey(kHPET, &filename, &len, &bootInfo->chameleonConfig))␊ |
885 | ␉{␊ |
886 | ␉␉snprintf(dirSpec, sizeof(dirSpec), filename);␊ |
887 | ␉}␊ |
888 | ␉else␊ |
889 | ␉{␊ |
890 | ␉␉sprintf(dirSpec, "HPET.aml");␊ |
891 | ␉}␊ |
892 | ␉// Load replacement HPET␊ |
893 | ␉new_hpet = loadACPITable(dirSpec);␊ |
894 | ␊ |
895 | ␉/* Try using the file specified with the SBST option */␊ |
896 | ␉if (getValueForKey(kSBST, &filename, &len, &bootInfo->chameleonConfig))␊ |
897 | ␉{␊ |
898 | ␉␉snprintf(dirSpec, sizeof(dirSpec), filename);␊ |
899 | ␉}␊ |
900 | ␉else␊ |
901 | ␉{␊ |
902 | ␉␉sprintf(dirSpec, "SBST.aml");␊ |
903 | ␉}␊ |
904 | ␉// Load replacement SBST␊ |
905 | ␉new_sbst = loadACPITable(dirSpec);␊ |
906 | ␊ |
907 | ␉/* Try using the file specified with the ECDT option */␊ |
908 | ␉if (getValueForKey(kECDT, &filename, &len, &bootInfo->chameleonConfig))␊ |
909 | ␉{␊ |
910 | ␉␉snprintf(dirSpec, sizeof(dirSpec), filename);␊ |
911 | ␉}␊ |
912 | ␉else␊ |
913 | ␉{␊ |
914 | ␉␉sprintf(dirSpec, "ECDT.aml");␊ |
915 | ␉}␊ |
916 | ␉// Load replacement ECDT␊ |
917 | ␉new_ecdt = loadACPITable(dirSpec);␊ |
918 | ␊ |
919 | ␉/* Try using the file specified with the ASF! option */␊ |
920 | ␉if (getValueForKey(kASFT, &filename, &len, &bootInfo->chameleonConfig))␊ |
921 | ␉{␊ |
922 | ␉␉snprintf(dirSpec, sizeof(dirSpec), filename);␊ |
923 | ␉}␊ |
924 | ␉else␊ |
925 | ␉{␊ |
926 | ␉␉sprintf(dirSpec, "ASFT.aml");␊ |
927 | ␉}␊ |
928 | ␉// Load replacement ASF!␊ |
929 | ␉new_asft = loadACPITable(dirSpec);␊ |
930 | ␊ |
931 | ␉/* Try using the file specified with the DMAR option */␊ |
932 | ␉if (getValueForKey(kDMAR, &filename, &len, &bootInfo->chameleonConfig))␊ |
933 | ␉{␊ |
934 | ␉␉snprintf(dirSpec, sizeof(dirSpec), filename);␊ |
935 | ␉}␊ |
936 | ␉else␊ |
937 | ␉{␊ |
938 | ␉␉sprintf(dirSpec, "DMAR.aml");␊ |
939 | ␉}␊ |
940 | ␉// Load replacement DMAR␊ |
941 | ␉new_dmar = loadACPITable(dirSpec);␊ |
942 | ␊ |
943 | ␉/* Try using the file specified with the APIC option */␊ |
944 | ␉if (getValueForKey(kAPIC, &filename, &len, &bootInfo->chameleonConfig))␊ |
945 | ␉{␊ |
946 | ␉␉snprintf(dirSpec, sizeof(dirSpec), filename);␊ |
947 | ␉}␊ |
948 | ␉else␊ |
949 | ␉{␊ |
950 | ␉␉sprintf(dirSpec, "APIC.aml");␊ |
951 | ␉}␊ |
952 | ␉// Load replacement APIC␊ |
953 | ␉new_apic = loadACPITable(dirSpec);␊ |
954 | ␊ |
955 | ␉// Try using the file specified with the MCFG option */␊ |
956 | ␉if (getValueForKey(kMCFG, &filename, &len, &bootInfo->chameleonConfig))␊ |
957 | ␉{␊ |
958 | ␉␉snprintf(dirSpec, sizeof(dirSpec), filename);␊ |
959 | ␉}␊ |
960 | ␉else␊ |
961 | ␉{␊ |
962 | ␉␉sprintf(dirSpec, "MCFG.aml");␊ |
963 | ␉}␊ |
964 | ␉// Load replacement MCFG␊ |
965 | ␉new_mcfg = loadACPITable(dirSpec);␊ |
966 | ␊ |
967 | ␉// Mozodojo: going to patch FACP and load SSDT's even if DSDT.aml is not present␊ |
968 | ␉/*if (!new_dsdt)␊ |
969 | ␉ {␊ |
970 | ␉ return setupAcpiNoMod();␊ |
971 | ␉ }*/␊ |
972 | ␊ |
973 | ␉// Mozodojo: Load additional SSDTs␊ |
974 | ␉struct acpi_2_ssdt *new_ssdt[32]; // 30 + 2 additional tables for pss & cst␊ |
975 | ␉int ssdt_count=0;␊ |
976 | ␊ |
977 | ␉// SSDT Options␊ |
978 | ␉bool drop_ssdt=false, generate_pstates=false, generate_cstates=false;␊ |
979 | ␊ |
980 | ␉getBoolForKey(kDropSSDT, &drop_ssdt, &bootInfo->chameleonConfig);␊ |
981 | ␉getBoolForKey(kGeneratePStates, &generate_pstates, &bootInfo->chameleonConfig);␊ |
982 | ␉getBoolForKey(kGenerateCStates, &generate_cstates, &bootInfo->chameleonConfig);␊ |
983 | ␉//getBoolForKey(kGenerateTStates, &generate_tstates, &bootInfo->chameleonConfig);␊ |
984 | ␊ |
985 | ␉DBG("Generating P-States config: %s\n", generate_pstates ? "YES" : "NO");␊ |
986 | ␉DBG("Generating C-States config: %s\n", generate_cstates ? "YES" : "NO");␊ |
987 | ␉//DBG("Generating T-States config: %s\n", generate_tstates ? "YES" : "NO");␊ |
988 | ␊ |
989 | ␉{␊ |
990 | ␉␉int i;␊ |
991 | ␊ |
992 | ␉␉for (i = 0; i < 30; i++)␊ |
993 | ␉␉{␊ |
994 | ␉␉␉char filename[512];␊ |
995 | ␊ |
996 | ␉␉␉sprintf(filename, i > 0 ? "SSDT-%d.aml" : "SSDT.aml", i);␊ |
997 | ␊ |
998 | ␉␉␉if ( (new_ssdt[ssdt_count] = loadACPITable(filename)) )␊ |
999 | ␉␉␉{␊ |
1000 | ␉␉␉␉ssdt_count++;␊ |
1001 | ␉␉␉}␊ |
1002 | ␉␉␉else␊ |
1003 | ␉␉␉{␊ |
1004 | ␉␉␉␉break;␊ |
1005 | ␉␉␉}␊ |
1006 | ␉␉}␊ |
1007 | ␉}␊ |
1008 | ␊ |
1009 | ␉// Do the same procedure for both versions of ACPI␊ |
1010 | ␉for (version = 0; version < 2; version++)␊ |
1011 | ␉{␊ |
1012 | ␉␉struct acpi_2_rsdp *rsdp, *rsdp_mod;␊ |
1013 | ␉␉struct acpi_2_rsdt *rsdt, *rsdt_mod;␊ |
1014 | ␉␉int rsdplength;␊ |
1015 | ␊ |
1016 | ␉␉// Find original rsdp␊ |
1017 | ␉␉rsdp=(struct acpi_2_rsdp *)(version ? getAddressOfAcpi20Table() : getAddressOfAcpiTable());␊ |
1018 | ␉␉if (!rsdp)␊ |
1019 | ␉␉{␊ |
1020 | ␉␉␉DBG("No ACPI version %d found. Ignoring\n", version+1);␊ |
1021 | ␉␉␉if (version)␊ |
1022 | ␉␉␉{␊ |
1023 | ␉␉␉␉addConfigurationTable(&gEfiAcpi20TableGuid, NULL, "ACPI_20");␊ |
1024 | ␉␉␉}␊ |
1025 | ␉␉␉else␊ |
1026 | ␉␉␉{␊ |
1027 | ␉␉␉␉addConfigurationTable(&gEfiAcpiTableGuid, NULL, "ACPI");␊ |
1028 | ␉␉␉}␊ |
1029 | ␉␉␉continue;␊ |
1030 | ␉␉}␊ |
1031 | ␉␉rsdplength=version ? rsdp->Length : 20;␊ |
1032 | ␊ |
1033 | ␉␉DBG("RSDP version %d found @%x. Length=%d\n",version+1,rsdp,rsdplength);␊ |
1034 | ␊ |
1035 | ␉␉/* FIXME: no check that memory allocation succeeded ␊ |
1036 | ␉␉ * Copy and patch RSDP,RSDT, XSDT and FADT␊ |
1037 | ␉␉ * For more info see ACPI Specification pages 110 and following␊ |
1038 | ␉␉ */␊ |
1039 | ␊ |
1040 | ␉␉rsdp_mod=(struct acpi_2_rsdp *) AllocateKernelMemory(rsdplength);␊ |
1041 | ␉␉memcpy(rsdp_mod, rsdp, rsdplength);␊ |
1042 | ␊ |
1043 | ␉␉rsdt=(struct acpi_2_rsdt *)(rsdp->RsdtAddress);␊ |
1044 | ␊ |
1045 | ␉␉DBG("RSDT @%x, Length %d\n",rsdt, rsdt ? rsdt->Length : 0);␊ |
1046 | ␉␉␊ |
1047 | ␉␉if (rsdt && (uint32_t)rsdt !=0xffffffff && rsdt->Length<0x10000)␊ |
1048 | ␉␉{␊ |
1049 | ␉␉␉uint32_t *rsdt_entries;␊ |
1050 | ␉␉␉int rsdt_entries_num;␊ |
1051 | ␉␉␉int dropoffset=0, i;␊ |
1052 | ␊ |
1053 | ␉␉␉// mozo: using malloc cos I didn't found how to free already allocated kernel memory␊ |
1054 | ␉␉␉rsdt_mod=(struct acpi_2_rsdt *)malloc(rsdt->Length); ␊ |
1055 | ␉␉␉memcpy (rsdt_mod, rsdt, rsdt->Length);␊ |
1056 | ␉␉␉rsdp_mod->RsdtAddress=(uint32_t)rsdt_mod;␊ |
1057 | ␉␉␉rsdt_entries_num=(rsdt_mod->Length-sizeof(struct acpi_2_rsdt))/4;␊ |
1058 | ␉␉␉rsdt_entries=(uint32_t *)(rsdt_mod+1);␊ |
1059 | ␉␉␉for (i=0;i<rsdt_entries_num;i++)␊ |
1060 | ␉␉␉{␊ |
1061 | ␉␉␉␉char *table=(char *)(rsdt_entries[i]);␊ |
1062 | ␉␉␉␉if (!table)␊ |
1063 | ␉␉␉␉{␊ |
1064 | ␉␉␉␉␉continue;␊ |
1065 | ␉␉␉␉}␊ |
1066 | ␊ |
1067 | ␉␉␉␉DBG("TABLE %c%c%c%c,",table[0],table[1],table[2],table[3]);␊ |
1068 | ␊ |
1069 | ␉␉␉␉rsdt_entries[i-dropoffset]=rsdt_entries[i];␊ |
1070 | ␊ |
1071 | ␉␉␉␉if (drop_ssdt && tableSign(table, "SSDT"))␊ |
1072 | ␉␉␉␉{␊ |
1073 | ␉␉␉␉␉DBG("OEM SSDT tables was dropped\n");␊ |
1074 | ␉␉␉␉␉dropoffset++;␊ |
1075 | ␉␉␉␉␉continue;␊ |
1076 | ␉␉␉␉}␊ |
1077 | ␊ |
1078 | ␉␉␉␉if (drop_hpet && tableSign(table, "HPET"))␊ |
1079 | ␉␉␉␉{␊ |
1080 | ␉␉␉␉␉DBG("OEM HPET table was dropped\n");␊ |
1081 | ␉␉␉␉␉dropoffset++;␊ |
1082 | ␉␉␉␉␉continue;␊ |
1083 | ␉␉␉␉}␉␉␉␊ |
1084 | ␊ |
1085 | ␉␉␉␉if (drop_slic && tableSign(table, "SLIC"))␊ |
1086 | ␉␉␉␉{␊ |
1087 | ␉␉␉␉␉DBG("OEM SLIC table was dropped\n");␊ |
1088 | ␉␉␉␉␉dropoffset++;␊ |
1089 | ␉␉␉␉␉continue;␊ |
1090 | ␉␉␉␉}␊ |
1091 | ␊ |
1092 | ␉␉␉␉if (drop_sbst && tableSign(table, "SBST"))␊ |
1093 | ␉␉␉␉{␊ |
1094 | ␉␉␉␉␉DBG("OEM SBST table was dropped\n");␊ |
1095 | ␉␉␉␉␉dropoffset++;␊ |
1096 | ␉␉␉␉␉continue;␊ |
1097 | ␉␉␉␉}␊ |
1098 | ␊ |
1099 | ␉␉␉␉if (drop_ecdt && tableSign(table, "ECDT"))␊ |
1100 | ␉␉␉␉{␊ |
1101 | ␉␉␉␉␉DBG("OEM ECDT table was dropped\n");␊ |
1102 | ␉␉␉␉␉dropoffset++;␊ |
1103 | ␉␉␉␉␉continue;␊ |
1104 | ␉␉␉␉}␊ |
1105 | ␊ |
1106 | ␉␉␉␉if (drop_asft && tableSign(table, "ASF!"))␊ |
1107 | ␉␉␉␉{␊ |
1108 | ␉␉␉␉␉DBG("OEM ASF! table was dropped\n");␊ |
1109 | ␉␉␉␉␉dropoffset++;␊ |
1110 | ␉␉␉␉␉continue;␊ |
1111 | ␉␉␉␉}␊ |
1112 | ␊ |
1113 | ␉␉␉␉if (drop_dmar && tableSign(table, "DMAR"))␊ |
1114 | ␉␉␉␉{␊ |
1115 | ␉␉␉␉␉DBG("OEM DMAR table was dropped\n");␊ |
1116 | ␉␉␉␉␉dropoffset++;␊ |
1117 | ␉␉␉␉␉continue;␊ |
1118 | ␉␉␉␉}␊ |
1119 | ␊ |
1120 | ␉␉␉␉if (tableSign(table, "HPET"))␊ |
1121 | ␉␉␉␉{␊ |
1122 | ␉␉␉␉␉DBG("HPET found\n");␊ |
1123 | ␉␉␉␉␉DBG("Custom HPET table was found\n");␊ |
1124 | ␉␉␉␉␉if(new_hpet)␊ |
1125 | ␉␉␉␉␉{␊ |
1126 | ␉␉␉␉␉␉rsdt_entries[i-dropoffset]=(uint32_t)new_hpet;␊ |
1127 | ␉␉␉␉␉}␊ |
1128 | ␉␉␉␉␉continue;␊ |
1129 | ␉␉␉␉}␊ |
1130 | ␊ |
1131 | ␉␉␉␉if (tableSign(table, "SBST"))␊ |
1132 | ␉␉␉␉{␊ |
1133 | ␉␉␉␉␉DBG("SBST found\n");␊ |
1134 | ␉␉␉␉␉DBG("Custom SBST table was found\n");␊ |
1135 | ␉␉␉␉␉if(new_sbst)␊ |
1136 | ␉␉␉␉␉{␊ |
1137 | ␉␉␉␉␉␉rsdt_entries[i-dropoffset]=(uint32_t)new_sbst;␊ |
1138 | ␉␉␉␉␉}␊ |
1139 | ␉␉␉␉␉continue;␊ |
1140 | ␉␉␉␉}␊ |
1141 | ␊ |
1142 | ␉␉␉␉if (tableSign(table, "ECDT"))␊ |
1143 | ␉␉␉␉{␊ |
1144 | ␉␉␉␉␉DBG("ECDT found\n");␊ |
1145 | ␉␉␉␉␉DBG("Custom ECDT table was found\n");␊ |
1146 | ␉␉␉␉␉if(new_ecdt)␊ |
1147 | ␉␉␉␉␉{␊ |
1148 | ␉␉␉␉␉␉rsdt_entries[i-dropoffset]=(uint32_t)new_ecdt;␊ |
1149 | ␉␉␉␉␉}␊ |
1150 | ␉␉␉␉␉continue;␊ |
1151 | ␉␉␉␉}␊ |
1152 | ␊ |
1153 | ␉␉␉␉if (tableSign(table, "ASF!"))␊ |
1154 | ␉␉␉␉{␊ |
1155 | ␉␉␉␉␉DBG("ASF! found\n");␊ |
1156 | ␉␉␉␉␉DBG("Custom ASF! table was found\n");␊ |
1157 | ␉␉␉␉␉if(new_asft)␊ |
1158 | ␉␉␉␉␉{␊ |
1159 | ␉␉␉␉␉␉rsdt_entries[i-dropoffset]=(uint32_t)new_asft;␊ |
1160 | ␉␉␉␉␉}␊ |
1161 | ␉␉␉␉␉continue;␊ |
1162 | ␉␉␉␉}␊ |
1163 | ␊ |
1164 | ␉␉␉␉if (tableSign(table, "DMAR"))␊ |
1165 | ␉␉␉␉{␊ |
1166 | ␉␉␉␉␉DBG("DMAR found\n");␊ |
1167 | ␉␉␉␉␉DBG("Custom DMAR table was found\n");␊ |
1168 | ␉␉␉␉␉if(new_dmar)␊ |
1169 | ␉␉␉␉␉{␊ |
1170 | ␉␉␉␉␉␉rsdt_entries[i-dropoffset]=(uint32_t)new_dmar;␊ |
1171 | ␉␉␉␉␉}␊ |
1172 | ␉␉␉␉␉continue;␊ |
1173 | ␉␉␉␉}␊ |
1174 | ␊ |
1175 | ␉␉␉␉if (tableSign(table, "APIC"))␊ |
1176 | ␉␉␉␉{␊ |
1177 | ␉␉␉␉␉DBG("APIC found\n");␊ |
1178 | ␉␉␉␉␉DBG("Custom APIC table was found\n");␊ |
1179 | ␉␉␉␉␉if(new_apic)␊ |
1180 | ␉␉␉␉␉{␊ |
1181 | ␉␉␉␉␉␉rsdt_entries[i-dropoffset]=(uint32_t)new_apic;␊ |
1182 | ␉␉␉␉␉}␊ |
1183 | ␉␉␉␉␉continue;␊ |
1184 | ␉␉␉␉}␊ |
1185 | ␊ |
1186 | ␉␉␉␉if (tableSign(table, "MCFG"))␊ |
1187 | ␉␉␉␉{␊ |
1188 | ␉␉␉␉␉DBG("MCFG found\n");␊ |
1189 | ␉␉␉␉␉DBG("Custom MCFG table was found\n");␊ |
1190 | ␉␉␉␉␉if(new_mcfg)␊ |
1191 | ␉␉␉␉␉{␊ |
1192 | ␉␉␉␉␉␉rsdt_entries[i-dropoffset]=(uint32_t)new_mcfg;␊ |
1193 | ␉␉␉␉␉}␊ |
1194 | ␊ |
1195 | ␉␉␉␉␉continue;␊ |
1196 | ␉␉␉␉}␊ |
1197 | ␉␉␉␉if (tableSign(table, "DSDT"))␊ |
1198 | ␉␉␉␉{␊ |
1199 | ␉␉␉␉␉DBG("DSDT found\n");␊ |
1200 | ␉␉␉␉␉DBG("Custom DSDT table was found\n");␊ |
1201 | ␉␉␉␉␉if(new_dsdt)␊ |
1202 | ␉␉␉␉␉{␊ |
1203 | ␉␉␉␉␉␉rsdt_entries[i-dropoffset]=(uint32_t)new_dsdt;␊ |
1204 | ␉␉␉␉␉}␊ |
1205 | ␊ |
1206 | ␉␉␉␉␉continue;␊ |
1207 | ␉␉␉␉}␊ |
1208 | ␊ |
1209 | ␉␉␉␉if (tableSign(table, "FACP"))␊ |
1210 | ␉␉␉␉{␊ |
1211 | ␉␉␉␉␉struct acpi_2_fadt *fadt, *fadt_mod;␊ |
1212 | ␉␉␉␉␉fadt=(struct acpi_2_fadt *)rsdt_entries[i];␊ |
1213 | ␊ |
1214 | ␉␉␉␉␉DBG("FADT found @%x, Length %d\n",fadt, fadt->Length);␊ |
1215 | ␊ |
1216 | ␉␉␉␉␉if (!fadt || (uint32_t)fadt == 0xffffffff || fadt->Length>0x10000)␊ |
1217 | ␉␉␉␉␉{␊ |
1218 | ␉␉␉␉␉␉DBG("FADT incorrect. Not modified\n");␊ |
1219 | ␉␉␉␉␉␉continue;␊ |
1220 | ␉␉␉␉␉}␊ |
1221 | ␉␉␉␉␉␊ |
1222 | ␉␉␉␉␉fadt_mod = patch_fadt(fadt, new_dsdt);␊ |
1223 | ␉␉␉␉␉rsdt_entries[i-dropoffset]=(uint32_t)fadt_mod;␊ |
1224 | ␉␉␉␉␉␊ |
1225 | ␉␉␉␉␉// Generate _CST SSDT␊ |
1226 | ␉␉␉␉␉if (generate_cstates && (new_ssdt[ssdt_count] = generate_cst_ssdt(fadt_mod)))␊ |
1227 | ␉␉␉␉␉{␊ |
1228 | ␉␉␉␉␉␉DBG("C-States generated\n");␊ |
1229 | ␉␉␉␉␉␉generate_cstates = false; // Generate SSDT only once!␊ |
1230 | ␉␉␉␉␉␉ssdt_count++;␊ |
1231 | ␉␉␉␉␉}␊ |
1232 | ␊ |
1233 | ␉␉␉␉␉// Generating _PSS SSDT␊ |
1234 | ␉␉␉␉␉if (generate_pstates && (new_ssdt[ssdt_count] = generate_pss_ssdt((void*)fadt_mod->DSDT)))␊ |
1235 | ␉␉␉␉␉{␊ |
1236 | ␉␉␉␉␉␉DBG("P-States generated\n");␊ |
1237 | ␉␉␉␉␉␉generate_pstates = false; // Generate SSDT only once!␊ |
1238 | ␉␉␉␉␉␉ssdt_count++;␊ |
1239 | ␉␉␉␉␉}␊ |
1240 | ␉␉␉␉␉continue;␊ |
1241 | ␉␉␉␉}␊ |
1242 | ␉␉␉}␊ |
1243 | ␉␉␉DBG("\n");␊ |
1244 | ␊ |
1245 | ␉␉␉// Allocate rsdt in Kernel memory area␊ |
1246 | ␉␉␉rsdt_mod->Length += 4*ssdt_count - 4*dropoffset;␊ |
1247 | ␉␉␉struct acpi_2_rsdt *rsdt_copy = (struct acpi_2_rsdt *)AllocateKernelMemory(rsdt_mod->Length);␊ |
1248 | ␉␉␉memcpy (rsdt_copy, rsdt_mod, rsdt_mod->Length);␊ |
1249 | ␉␉␉free(rsdt_mod); rsdt_mod = rsdt_copy;␊ |
1250 | ␉␉␉rsdp_mod->RsdtAddress=(uint32_t)rsdt_mod;␊ |
1251 | ␉␉␉rsdt_entries_num=(rsdt_mod->Length-sizeof(struct acpi_2_rsdt))/4;␊ |
1252 | ␉␉␉rsdt_entries=(uint32_t *)(rsdt_mod+1);␊ |
1253 | ␊ |
1254 | ␉␉␉// Mozodojo: Insert additional SSDTs into RSDT␊ |
1255 | ␉␉␉if(ssdt_count > 0)␊ |
1256 | ␉␉␉{␊ |
1257 | ␉␉␉␉int j;␊ |
1258 | ␊ |
1259 | ␉␉␉␉for (j=0; j<ssdt_count; j++)␊ |
1260 | ␉␉␉␉{␊ |
1261 | ␉␉␉␉␉rsdt_entries[i-dropoffset+j]=(uint32_t)new_ssdt[j];␊ |
1262 | ␉␉␉␉}␊ |
1263 | ␉␉␉␉DBG("RSDT: Added %d SSDT table(s)\n", ssdt_count);␊ |
1264 | ␊ |
1265 | ␉␉␉}␊ |
1266 | ␊ |
1267 | ␉␉␉// Correct the checksum of RSDT␊ |
1268 | ␉␉␉DBG("RSDT: Original checksum %d, ", rsdt_mod->Checksum);␊ |
1269 | ␊ |
1270 | ␉␉␉rsdt_mod->Checksum=0;␊ |
1271 | ␉␉␉rsdt_mod->Checksum=256-checksum8(rsdt_mod,rsdt_mod->Length);␊ |
1272 | ␊ |
1273 | ␉␉␉DBG("New checksum %d at %x\n", rsdt_mod->Checksum,rsdt_mod);␊ |
1274 | ␉␉}␊ |
1275 | ␉␉else␊ |
1276 | ␉␉{␊ |
1277 | ␉␉␉rsdp_mod->RsdtAddress=0;␊ |
1278 | ␉␉␉DBG("RSDT not found or RSDT incorrect\n");␊ |
1279 | ␉␉}␊ |
1280 | ␉␉DBG("\n");␊ |
1281 | ␊ |
1282 | ␉␉if (version)␊ |
1283 | ␉␉{␊ |
1284 | ␉␉␉struct acpi_2_xsdt *xsdt, *xsdt_mod;␊ |
1285 | ␊ |
1286 | ␉␉␉// FIXME: handle 64-bit address correctly␊ |
1287 | ␊ |
1288 | ␉␉␉xsdt=(struct acpi_2_xsdt*) ((uint32_t)rsdp->XsdtAddress);␊ |
1289 | ␉␉␉DBG("XSDT @%x;%x, Length=%d Sign=%c%c%c%c\n", (uint32_t)(rsdp->XsdtAddress>>32),␊ |
1290 | ␉␉␉␉(uint32_t)rsdp->XsdtAddress, xsdt->Length, xsdt[0], xsdt[1], xsdt[2], xsdt[3]);␊ |
1291 | ␉␉␉if (xsdt && (uint64_t)rsdp->XsdtAddress<0xffffffff && xsdt->Length<0x10000)␊ |
1292 | ␉␉␉{␊ |
1293 | ␉␉␉␉uint64_t *xsdt_entries;␊ |
1294 | ␉␉␉␉int xsdt_entries_num, i;␊ |
1295 | ␉␉␉␉int dropoffset=0;␊ |
1296 | ␊ |
1297 | ␉␉␉␉// mozo: using malloc cos I didn't found how to free already allocated kernel memory␊ |
1298 | ␉␉␉␉xsdt_mod=(struct acpi_2_xsdt*)malloc(xsdt->Length); ␊ |
1299 | ␉␉␉␉memcpy(xsdt_mod, xsdt, xsdt->Length);␊ |
1300 | ␊ |
1301 | ␉␉␉␉rsdp_mod->XsdtAddress=(uint32_t)xsdt_mod;␊ |
1302 | ␉␉␉␉xsdt_entries_num=(xsdt_mod->Length-sizeof(struct acpi_2_xsdt))/8;␊ |
1303 | ␉␉␉␉xsdt_entries=(uint64_t *)(xsdt_mod+1);␊ |
1304 | ␉␉␉␉for (i=0;i<xsdt_entries_num;i++)␊ |
1305 | ␉␉␉␉{␊ |
1306 | ␉␉␉␉␉char *table=(char *)((uint32_t)(xsdt_entries[i]));␊ |
1307 | ␉␉␉␉␉if (!table)␊ |
1308 | ␉␉␉␉␉{␊ |
1309 | ␉␉␉␉␉␉continue;␊ |
1310 | ␉␉␉␉␉}␊ |
1311 | ␉␉␉␉␉xsdt_entries[i-dropoffset]=xsdt_entries[i];␊ |
1312 | ␊ |
1313 | ␉␉␉␉␉if (drop_ssdt && tableSign(table, "SSDT"))␊ |
1314 | ␉␉␉␉␉{␊ |
1315 | ␉␉␉␉␉␉verbose("OEM SSDT tables was dropped\n");␊ |
1316 | ␉␉␉␉␉␉dropoffset++;␊ |
1317 | ␉␉␉␉␉␉continue;␊ |
1318 | ␉␉␉␉␉}␊ |
1319 | ␊ |
1320 | ␉␉␉␉␉if (drop_hpet && tableSign(table, "HPET"))␊ |
1321 | ␉␉␉␉␉{␊ |
1322 | ␉␉␉␉␉␉verbose("OEM HPET table was dropped\n");␊ |
1323 | ␉␉␉␉␉␉dropoffset++;␊ |
1324 | ␉␉␉␉␉␉continue;␊ |
1325 | ␉␉␉␉␉}␊ |
1326 | ␊ |
1327 | ␉␉␉␉␉if (drop_slic && tableSign(table, "SLIC"))␊ |
1328 | ␉␉␉␉␉{␊ |
1329 | ␉␉␉␉␉␉verbose("OEM SLIC table was dropped\n");␊ |
1330 | ␉␉␉␉␉␉dropoffset++;␊ |
1331 | ␉␉␉␉␉␉continue;␊ |
1332 | ␉␉␉␉␉}␊ |
1333 | ␊ |
1334 | ␉␉␉␉␉if (drop_sbst && tableSign(table, "SBST"))␊ |
1335 | ␉␉␉␉␉{␊ |
1336 | ␉␉␉␉␉␉verbose("OEM SBST table was dropped\n");␊ |
1337 | ␉␉␉␉␉␉dropoffset++;␊ |
1338 | ␉␉␉␉␉␉continue;␊ |
1339 | ␉␉␉␉␉}␊ |
1340 | ␊ |
1341 | ␉␉␉␉␉if (drop_ecdt && tableSign(table, "ECDT"))␊ |
1342 | ␉␉␉␉␉{␊ |
1343 | ␉␉␉␉␉␉verbose("OEM ECDT table was dropped\n");␊ |
1344 | ␉␉␉␉␉␉dropoffset++;␊ |
1345 | ␉␉␉␉␉␉continue;␊ |
1346 | ␉␉␉␉␉}␊ |
1347 | ␊ |
1348 | ␉␉␉␉␉if (drop_asft && tableSign(table, "ASF!"))␊ |
1349 | ␉␉␉␉␉{␊ |
1350 | ␉␉␉␉␉␉verbose("OEM ASF! table was dropped\n");␊ |
1351 | ␉␉␉␉␉␉dropoffset++;␊ |
1352 | ␉␉␉␉␉␉continue;␊ |
1353 | ␉␉␉␉␉}␊ |
1354 | ␊ |
1355 | ␉␉␉␉␉if (drop_dmar && tableSign(table, "DMAR"))␊ |
1356 | ␉␉␉␉␉{␊ |
1357 | ␉␉␉␉␉␉verbose("OEM DMAR table was dropped\n");␊ |
1358 | ␉␉␉␉␉␉dropoffset++;␊ |
1359 | ␉␉␉␉␉␉continue;␊ |
1360 | ␉␉␉␉␉}␊ |
1361 | ␊ |
1362 | ␉␉␉␉␉if (tableSign(table, "DSDT"))␊ |
1363 | ␉␉␉␉␉{␊ |
1364 | ␉␉␉␉␉␉DBG("DSDT found\n");␊ |
1365 | ␊ |
1366 | ␉␉␉␉␉␉if (new_dsdt)␊ |
1367 | ␉␉␉␉␉␉{␊ |
1368 | ␉␉␉␉␉␉␉xsdt_entries[i-dropoffset]=(uint32_t)new_dsdt;␊ |
1369 | ␉␉␉␉␉␉}␊ |
1370 | ␊ |
1371 | ␉␉␉␉␉␉DBG("TABLE %c%c%c%c@%x \n", table[0],table[1],table[2],table[3],xsdt_entries[i]);␊ |
1372 | ␊ |
1373 | ␉␉␉␉␉␉continue;␊ |
1374 | ␉␉␉␉␉}␊ |
1375 | ␊ |
1376 | ␉␉␉␉␉if (tableSign(table, "HPET"))␊ |
1377 | ␉␉␉␉␉{␊ |
1378 | ␉␉␉␉␉␉DBG("HPET found\n");␊ |
1379 | ␊ |
1380 | ␉␉␉␉␉␉if (new_hpet)␊ |
1381 | ␉␉␉␉␉␉{␊ |
1382 | ␉␉␉␉␉␉␉xsdt_entries[i-dropoffset]=(uint32_t)new_hpet;␊ |
1383 | ␉␉␉␉␉␉}␊ |
1384 | ␊ |
1385 | ␉␉␉␉␉␉DBG("TABLE %c%c%c%c@%x \n", table[0],table[1],table[2],table[3],xsdt_entries[i]);␊ |
1386 | ␊ |
1387 | ␉␉␉␉␉␉continue;␊ |
1388 | ␉␉␉␉␉}␊ |
1389 | ␊ |
1390 | ␉␉␉␉␉if (tableSign(table, "SBST"))␊ |
1391 | ␉␉␉␉␉{␊ |
1392 | ␉␉␉␉␉␉DBG("SBST found\n");␊ |
1393 | ␊ |
1394 | ␉␉␉␉␉␉if (new_sbst)␊ |
1395 | ␉␉␉␉␉␉{␊ |
1396 | ␉␉␉␉␉␉␉xsdt_entries[i-dropoffset]=(uint32_t)new_sbst;␊ |
1397 | ␉␉␉␉␉␉}␊ |
1398 | ␊ |
1399 | ␉␉␉␉␉␉DBG("TABLE %c%c%c%c@%x \n", table[0],table[1],table[2],table[3],xsdt_entries[i]);␊ |
1400 | ␊ |
1401 | ␉␉␉␉␉␉continue;␊ |
1402 | ␉␉␉␉␉}␊ |
1403 | ␊ |
1404 | ␉␉␉␉␉if (tableSign(table, "ECDT"))␊ |
1405 | ␉␉␉␉␉{␊ |
1406 | ␉␉␉␉␉␉DBG("ECDT found\n");␊ |
1407 | ␊ |
1408 | ␉␉␉␉␉␉if (new_ecdt)␊ |
1409 | ␉␉␉␉␉␉{␊ |
1410 | ␉␉␉␉␉␉␉xsdt_entries[i-dropoffset]=(uint32_t)new_ecdt;␊ |
1411 | ␉␉␉␉␉␉}␊ |
1412 | ␊ |
1413 | ␉␉␉␉␉␉DBG("TABLE %c%c%c%c@%x \n", table[0],table[1],table[2],table[3],xsdt_entries[i]);␊ |
1414 | ␊ |
1415 | ␉␉␉␉␉␉continue;␊ |
1416 | ␉␉␉␉␉}␊ |
1417 | ␊ |
1418 | ␉␉␉␉␉if (tableSign(table, "ASF!"))␊ |
1419 | ␉␉␉␉␉{␊ |
1420 | ␉␉␉␉␉␉DBG("ASF! found\n");␊ |
1421 | ␊ |
1422 | ␉␉␉␉␉␉if (new_asft)␊ |
1423 | ␉␉␉␉␉␉{␊ |
1424 | ␉␉␉␉␉␉␉xsdt_entries[i-dropoffset]=(uint32_t)new_asft;␊ |
1425 | ␉␉␉␉␉␉}␊ |
1426 | ␊ |
1427 | ␉␉␉␉␉␉DBG("TABLE %c%c%c%c@%x \n", table[0],table[1],table[2],table[3],xsdt_entries[i]);␊ |
1428 | ␊ |
1429 | ␉␉␉␉␉␉continue;␊ |
1430 | ␉␉␉␉␉}␊ |
1431 | ␊ |
1432 | ␉␉␉␉␉if (tableSign(table, "DMAR"))␊ |
1433 | ␉␉␉␉␉{␊ |
1434 | ␉␉␉␉␉␉DBG("DMAR found\n");␊ |
1435 | ␊ |
1436 | ␉␉␉␉␉␉if (new_dmar)␊ |
1437 | ␉␉␉␉␉␉{␊ |
1438 | ␉␉␉␉␉␉␉xsdt_entries[i-dropoffset]=(uint32_t)new_dmar;␊ |
1439 | ␉␉␉␉␉␉}␊ |
1440 | ␊ |
1441 | ␉␉␉␉␉␉DBG("TABLE %c%c%c%c@%x \n", table[0],table[1],table[2],table[3],xsdt_entries[i]);␊ |
1442 | ␊ |
1443 | ␉␉␉␉␉␉continue;␊ |
1444 | ␉␉␉␉␉}␊ |
1445 | ␊ |
1446 | ␉␉␉␉␉if (tableSign(table, "APIC"))␊ |
1447 | ␉␉␉␉␉{␊ |
1448 | ␉␉␉␉␉␉DBG("APIC found\n");␊ |
1449 | ␊ |
1450 | ␉␉␉␉␉␉if (new_apic)␊ |
1451 | ␉␉␉␉␉␉{␊ |
1452 | ␉␉␉␉␉␉␉xsdt_entries[i-dropoffset]=(uint32_t)new_apic;␊ |
1453 | ␉␉␉␉␉␉}␊ |
1454 | ␊ |
1455 | ␉␉␉␉␉␉DBG("TABLE %c%c%c%c@%x \n", table[0],table[1],table[2],table[3],xsdt_entries[i]);␊ |
1456 | ␊ |
1457 | ␉␉␉␉␉␉continue;␊ |
1458 | ␉␉␉␉␉}␊ |
1459 | ␊ |
1460 | ␉␉␉␉␉if (tableSign(table, "MCFG"))␊ |
1461 | ␉␉␉␉␉{␊ |
1462 | ␉␉␉␉␉␉DBG("MCFG found\n");␊ |
1463 | ␊ |
1464 | ␉␉␉␉␉␉if (new_mcfg)␊ |
1465 | ␉␉␉␉␉␉{␊ |
1466 | ␉␉␉␉␉␉␉xsdt_entries[i-dropoffset]=(uint32_t)new_mcfg;␊ |
1467 | ␉␉␉␉␉␉}␊ |
1468 | ␊ |
1469 | ␉␉␉␉␉␉DBG("TABLE %c%c%c%c@%x \n", table[0],table[1],table[2],table[3],xsdt_entries[i]);␊ |
1470 | ␊ |
1471 | ␉␉␉␉␉␉continue;␊ |
1472 | ␉␉␉␉␉}␊ |
1473 | ␊ |
1474 | ␉␉␉␉␉if (tableSign(table, "FACP"))␊ |
1475 | ␉␉␉␉␉{␊ |
1476 | ␉␉␉␉␉␉struct acpi_2_fadt *fadt, *fadt_mod;␊ |
1477 | ␉␉␉␉␉␉fadt=(struct acpi_2_fadt *)(uint32_t)xsdt_entries[i];␊ |
1478 | ␊ |
1479 | ␉␉␉␉␉␉DBG("FADT found @%x%x, Length %d\n",(uint32_t)(xsdt_entries[i]>>32),fadt, ␊ |
1480 | ␉␉␉␉␉␉␉fadt->Length);␊ |
1481 | ␊ |
1482 | ␉␉␉␉␉␉if (!fadt || (uint64_t)xsdt_entries[i] >= 0xffffffff || fadt->Length>0x10000)␊ |
1483 | ␉␉␉␉␉␉{␊ |
1484 | ␉␉␉␉␉␉␉DBG("FADT incorrect or after 4GB. Dropping XSDT\n");␊ |
1485 | ␉␉␉␉␉␉␉goto drop_xsdt;␊ |
1486 | ␉␉␉␉␉␉}␊ |
1487 | ␊ |
1488 | ␉␉␉␉␉␉fadt_mod = patch_fadt(fadt, new_dsdt);␊ |
1489 | ␉␉␉␉␉␉xsdt_entries[i-dropoffset]=(uint32_t)fadt_mod;␊ |
1490 | ␊ |
1491 | ␉␉␉␉␉␉// DBG("TABLE %c%c%c%c@%x \n", table[0],table[1],table[2],table[3],xsdt_entries[i]);␊ |
1492 | ␊ |
1493 | ␉␉␉␉␉␉// Generate _CST SSDT␊ |
1494 | ␉␉␉␉␉␉if (generate_cstates && (new_ssdt[ssdt_count] = generate_cst_ssdt(fadt_mod)))␊ |
1495 | ␉␉␉␉␉␉{␊ |
1496 | ␉␉␉␉␉␉␉DBG("C-States generated\n");␊ |
1497 | ␉␉␉␉␉␉␉generate_cstates = false; // Generate SSDT only once!␊ |
1498 | ␉␉␉␉␉␉␉ssdt_count++;␊ |
1499 | ␉␉␉␉␉␉}␊ |
1500 | ␊ |
1501 | ␉␉␉␉␉␉// Generating _PSS SSDT␊ |
1502 | ␉␉␉␉␉␉if (generate_pstates && (new_ssdt[ssdt_count] = generate_pss_ssdt((void*)fadt_mod->DSDT)))␊ |
1503 | ␉␉␉␉␉␉{␊ |
1504 | ␉␉␉␉␉␉␉DBG("P-States generated\n");␊ |
1505 | ␉␉␉␉␉␉␉generate_pstates = false; // Generate SSDT only once!␊ |
1506 | ␉␉␉␉␉␉␉ssdt_count++;␊ |
1507 | ␉␉␉␉␉␉}␊ |
1508 | ␊ |
1509 | ␉␉␉␉␉␉// Generating _TSS SSDT␊ |
1510 | ␉␉␉␉␉␉/*if (generate_tstates && (new_ssdt[ssdt_count] = generate_tss_ssdt((void*)fadt_mod->DSDT)))␊ |
1511 | ␉␉␉␉␉␉{␊ |
1512 | ␉␉␉␉␉␉␉generate_tstates = false; // Generate SSDT only once!␊ |
1513 | ␉␉␉␉␉␉␉ssdt_count++;␊ |
1514 | ␉␉␉␉␉␉}*/␊ |
1515 | ␉␉␉␉␉␉continue;␊ |
1516 | ␉␉␉␉␉}␊ |
1517 | ␊ |
1518 | ␉␉␉␉␉DBG("TABLE %c%c%c%c@%x \n", table[0],table[1],table[2],table[3],xsdt_entries[i]);␊ |
1519 | ␊ |
1520 | ␉␉␉␉}␊ |
1521 | ␊ |
1522 | ␉␉␉␉// Allocate xsdt in Kernel memory area␊ |
1523 | ␉␉␉␉xsdt_mod->Length += 8*ssdt_count - 8*dropoffset;␊ |
1524 | ␉␉␉␉struct acpi_2_xsdt *xsdt_copy = (struct acpi_2_xsdt *)AllocateKernelMemory(xsdt_mod->Length);␊ |
1525 | ␉␉␉␉memcpy(xsdt_copy, xsdt_mod, xsdt_mod->Length);␊ |
1526 | ␉␉␉␉free(xsdt_mod); xsdt_mod = xsdt_copy;␊ |
1527 | ␉␉␉␉rsdp_mod->XsdtAddress=(uint32_t)xsdt_mod;␊ |
1528 | ␉␉␉␉xsdt_entries_num=(xsdt_mod->Length-sizeof(struct acpi_2_xsdt))/8;␊ |
1529 | ␉␉␉␉xsdt_entries=(uint64_t *)(xsdt_mod+1);␊ |
1530 | ␊ |
1531 | ␉␉␉␉// Mozodojo: Insert additional SSDTs into XSDT␊ |
1532 | ␉␉␉␉if(ssdt_count > 0)␊ |
1533 | ␉␉␉␉{␊ |
1534 | ␉␉␉␉␉int j;␊ |
1535 | ␊ |
1536 | ␉␉␉␉␉for (j=0; j<ssdt_count; j++)␊ |
1537 | ␉␉␉␉␉{␊ |
1538 | ␉␉␉␉␉␉xsdt_entries[i-dropoffset+j]=(uint32_t)new_ssdt[j];␊ |
1539 | ␉␉␉␉␉}␊ |
1540 | ␊ |
1541 | ␉␉␉␉␉verbose("Added %d SSDT table(s) into XSDT\n", ssdt_count);␊ |
1542 | ␊ |
1543 | ␉␉␉␉}␊ |
1544 | ␊ |
1545 | ␉␉␉␉// Correct the checksum of XSDT␊ |
1546 | ␉␉␉␉xsdt_mod->Checksum=0;␊ |
1547 | ␉␉␉␉xsdt_mod->Checksum=256-checksum8(xsdt_mod,xsdt_mod->Length);␊ |
1548 | ␉␉␉}␊ |
1549 | ␉␉␉else␊ |
1550 | ␉␉␉{␊ |
1551 | ␉␉␉drop_xsdt:␊ |
1552 | ␊ |
1553 | ␉␉␉␉DBG("About to drop XSDT\n");␊ |
1554 | ␊ |
1555 | ␉␉␉␉/*FIXME: Now we just hope that if MacOS doesn't find XSDT it reverts to RSDT. ␊ |
1556 | ␉␉␉␉ * A Better strategy would be to generate␊ |
1557 | ␉␉␉␉ */␊ |
1558 | ␊ |
1559 | ␉␉␉␉rsdp_mod->XsdtAddress=0xffffffffffffffffLL;␊ |
1560 | ␉␉␉␉verbose("XSDT not found or XSDT incorrect\n");␊ |
1561 | ␉␉␉}␊ |
1562 | ␉␉}␊ |
1563 | ␉␉DBG("\n");␊ |
1564 | ␊ |
1565 | ␉␉// Correct the checksum of RSDP␊ |
1566 | ␊ |
1567 | ␉␉DBG("RSDP: Original checksum %d, ", rsdp_mod->Checksum);␊ |
1568 | ␊ |
1569 | ␉␉rsdp_mod->Checksum=0;␊ |
1570 | ␉␉rsdp_mod->Checksum=256-checksum8(rsdp_mod,20);␊ |
1571 | ␊ |
1572 | ␉␉DBG("New checksum %d\n", rsdp_mod->Checksum);␊ |
1573 | ␊ |
1574 | ␉␉if (version)␊ |
1575 | ␉␉{␊ |
1576 | ␉␉␉DBG("RSDP: Original extended checksum %d, ", rsdp_mod->ExtendedChecksum);␊ |
1577 | ␊ |
1578 | ␉␉␉rsdp_mod->ExtendedChecksum=0;␊ |
1579 | ␉␉␉rsdp_mod->ExtendedChecksum=256-checksum8(rsdp_mod,rsdp_mod->Length);␊ |
1580 | ␊ |
1581 | ␉␉␉DBG("New extended checksum %d\n", rsdp_mod->ExtendedChecksum);␊ |
1582 | ␊ |
1583 | ␉␉}␊ |
1584 | ␊ |
1585 | ␉␉if (version)␊ |
1586 | ␉␉{␊ |
1587 | ␉␉␉/* XXX aserebln why uint32 cast if pointer is uint64 ? */␊ |
1588 | ␉␉␉acpi20_p = (uint64_t)(uint32_t)rsdp_mod;␊ |
1589 | ␉␉␉addConfigurationTable(&gEfiAcpi20TableGuid, &acpi20_p, "ACPI_20");␊ |
1590 | ␉␉}␊ |
1591 | ␉␉else␊ |
1592 | ␉␉{␊ |
1593 | ␉␉␉/* XXX aserebln why uint32 cast if pointer is uint64 ? */␊ |
1594 | ␉␉␉acpi10_p = (uint64_t)(uint32_t)rsdp_mod;␊ |
1595 | ␉␉␉addConfigurationTable(&gEfiAcpiTableGuid, &acpi10_p, "ACPI");␊ |
1596 | ␉␉}␊ |
1597 | ␉␉DBG("ACPI version %d patching finished\n\n", version+1);␊ |
1598 | ␉}␊ |
1599 | #if DEBUG_ACPI␊ |
1600 | ␉printf("Press a key to continue... (DEBUG_ACPI)\n");␊ |
1601 | ␉getchar();␊ |
1602 | #endif␊ |
1603 | ␉return 1;␊ |
1604 | }␊ |
1605 | |