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