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