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