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