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