1 | /*␊ |
2 | * Copyright 2008 mackerintel␊ |
3 | */␊ |
4 | ␊ |
5 | /* ␊ |
6 | Copyright (c) 2010, Intel Corporation␊ |
7 | All rights reserved.␊ |
8 | ␊ |
9 | Redistribution and use in source and binary forms, with or without␊ |
10 | modification, are permitted provided that the following conditions are met:␊ |
11 | ␊ |
12 | * Redistributions of source code must retain the above copyright notice,␊ |
13 | this list of conditions and the following disclaimer.␊ |
14 | * Redistributions in binary form must reproduce the above copyright notice,␊ |
15 | this list of conditions and the following disclaimer in the documentation␊ |
16 | and/or other materials provided with the distribution.␊ |
17 | * Neither the name of Intel Corporation nor the names of its contributors␊ |
18 | may be used to endorse or promote products derived from this software␊ |
19 | without specific prior written permission.␊ |
20 | ␊ |
21 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND␊ |
22 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED␊ |
23 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE␊ |
24 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR␊ |
25 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES␊ |
26 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;␊ |
27 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON␊ |
28 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT␊ |
29 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS␊ |
30 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.␊ |
31 | */␊ |
32 | ␊ |
33 | /*␊ |
34 | * Copyright (c) 2011,2012 cparm <armelcadetpetit@gmail.com>. All rights reserved.␊ |
35 | *␊ |
36 | */␊ |
37 | ␊ |
38 | #include "libsaio.h"␊ |
39 | #include "bootstruct.h"␊ |
40 | #include "acpi.h"␊ |
41 | #include "acpidecode.h"␊ |
42 | #include "acpicode.h"␊ |
43 | #include "efi_tables.h"␊ |
44 | #include "fake_efi.h"␊ |
45 | #include "acpi_codec.h"␊ |
46 | #include "platform.h"␊ |
47 | #include "cpu.h"␊ |
48 | #include "xml.h"␊ |
49 | #include "sl.h"␊ |
50 | #include "convert.h"␊ |
51 | #include "modules.h"␊ |
52 | #include "pci.h"␊ |
53 | #include "pci_root.h"␊ |
54 | ␊ |
55 | U64 rsd_p;␊ |
56 | ACPI_TABLES acpi_tables;␊ |
57 | U32 uuid32;␊ |
58 | U32 Model32;␊ |
59 | bool checkOem = false;␊ |
60 | ␊ |
61 | extern EFI_STATUS addConfigurationTable();␊ |
62 | ␊ |
63 | extern EFI_GUID gEfiAcpiTableGuid;␊ |
64 | extern EFI_GUID gEfiAcpi20TableGuid;␊ |
65 | ␊ |
66 | #ifndef DEBUG_ACPI␊ |
67 | #define DEBUG_ACPI 0␊ |
68 | #endif␊ |
69 | ␊ |
70 | #if DEBUG_ACPI==2␊ |
71 | #define DBG(x...) {printf(x); sleep(1);}␊ |
72 | #elif DEBUG_ACPI==1␊ |
73 | #define DBG(x...) printf(x)␊ |
74 | #else␊ |
75 | #define DBG(x...)␊ |
76 | #endif␊ |
77 | ␊ |
78 | #define OLD_SSDT 0␊ |
79 | #define BETA 0␊ |
80 | #define BUILD_ACPI_TSS 0␊ |
81 | #define pstate_power_support 1␊ |
82 | ␊ |
83 | #if BETA␊ |
84 | #ifdef pstate_power_support␊ |
85 | #undef pstate_power_support␊ |
86 | #endif␊ |
87 | #define pstate_power_support 1␊ |
88 | #endif␊ |
89 | ␊ |
90 | #if DEBUG_ACPI␊ |
91 | static void print_nameseg(U32 i);␊ |
92 | #endif␊ |
93 | ␊ |
94 | static ACPI_TABLE_HEADER * get_new_table_in_list(U32 *new_table_list, U32 Signature, U8 *retIndex );␊ |
95 | static U8 get_number_of_tables_in_list(U32 *new_table_list, U32 Signature );␊ |
96 | static U8 get_0ul_index_in_list(U32 *new_table_list, bool reserved );␊ |
97 | static void sanitize_new_table_list(U32 *new_table_list );␊ |
98 | static void move_table_list_to_kmem(U32 *new_table_list );␊ |
99 | static ACPI_TABLE_RSDP * gen_alloc_rsdp_v2_from_v1(ACPI_TABLE_RSDP *rsdp );␊ |
100 | static ACPI_TABLE_RSDT * gen_alloc_rsdt_from_xsdt(ACPI_TABLE_XSDT *xsdt);␊ |
101 | static ACPI_TABLE_XSDT * gen_alloc_xsdt_from_rsdt(ACPI_TABLE_RSDT *rsdt);␊ |
102 | #if 0␊ |
103 | static void MakeAcpiSgn(void);␊ |
104 | #endif␊ |
105 | static void *loadACPITable(U32 *new_table_list, char *dirspec, const char *filename );␊ |
106 | static int generate_cpu_map_from_acpi(ACPI_TABLE_DSDT * DsdtPointer);␊ |
107 | static ACPI_GENERIC_ADDRESS FillGASStruct(U32 Address, U8 Length);␊ |
108 | static U32 process_xsdt (ACPI_TABLE_RSDP *rsdp_mod , U32 *new_table_list);␊ |
109 | static U32 process_rsdt(ACPI_TABLE_RSDP *rsdp_mod , bool gen_xsdt, U32 *new_table_list);␊ |
110 | static ACPI_TABLE_FADT * patch_fadt(ACPI_TABLE_FADT *fadt, ACPI_TABLE_DSDT *new_dsdt, bool UpdateFADT);␊ |
111 | ␊ |
112 | ␊ |
113 | #define IA32_MISC_ENABLES 0x01A0␊ |
114 | #define MSR_TURBO_POWER_CURRENT_LIMIT 0x1AC␊ |
115 | #define MSR_PKG_CST_CONFIG_CONTROL 0x00E2␊ |
116 | #define MSR_RAPL_POWER_UNIT 0x606␊ |
117 | #define MSR_PKG_RAPL_POWER_LIMIT 0x610␊ |
118 | static U32 turbo_enabled = 0;␊ |
119 | static U32 ProcessMadt(ACPI_TABLE_MADT * madt, MADT_INFO * madt_info, void * buffer, U32 bufferSize, U32 NB_CPU);␊ |
120 | static U32 buildMADT(U32 * new_table_list, ACPI_TABLE_DSDT *dsdt, MADT_INFO * madt_info);␊ |
121 | static U32 BuildSsdt(MADT_INFO * madt_info, ACPI_TABLE_DSDT *dsdt, void * buffer, U32 bufferSize, bool enable_cstates, bool enable_pstates, bool enable_tstates);␊ |
122 | static bool is_sandybridge(void);␊ |
123 | static bool is_jaketown(void);␊ |
124 | static U32 encode_pstate(U32 ratio);␊ |
125 | static void collect_cpu_info(CPU_DETAILS * cpu);␊ |
126 | #ifndef BETA␊ |
127 | //static U32 BuildCoreIPstateInfo(CPU_DETAILS * cpu);␊ |
128 | #endif␊ |
129 | static U32 BuildCstateInfo(CPU_DETAILS * cpu, U32 pmbase);␊ |
130 | static U32 BuildPstateInfo(CPU_DETAILS * cpu);␊ |
131 | static U32 ProcessSsdt(U32 * new_table_list, ACPI_TABLE_DSDT *dsdt, MADT_INFO * madt_info, bool enable_cstates, bool enable_pstates, bool enable_tstates );␊ |
132 | static void * buildCpuScope (void * current, U32 cpu_namespace, PROCESSOR_NUMBER_TO_NAMESEG * aslCpuNamePath);␊ |
133 | static void * buildPDC(void * current);␊ |
134 | static void * buildOSC(void * current);␊ |
135 | static void * buildPSS(void * current, PKG_PSTATES * pkg_pstates);␊ |
136 | static void * buildPSD(void * current, U32 domain, U32 cpusInDomain, U32 pstate_coordination);␊ |
137 | static void * buildPPC(void * current);␊ |
138 | static void * buildPCT(void * current);␊ |
139 | static void * buildCstate(void * current, ACPI_GENERIC_ADDRESS * gas, CSTATE * cstate);␊ |
140 | static void * buildReturnPackageCST(void * current, PKG_CSTATES * pkg_cstates);␊ |
141 | static void * buildCST(void * current, PKG_CSTATES * mwait_pkg_cstates, PKG_CSTATES * io_pkg_cstates);␊ |
142 | #if BUILD_ACPI_CSD␊ |
143 | static void * buildCSD(void * current, U32 domain, U32 cpusInDomain, PKG_CSTATES * pkg_cstates);␊ |
144 | #endif␊ |
145 | #if BUILD_ACPI_TSS␊ |
146 | static U32 BuildTstateInfo(CPU_DETAILS * cpu);␊ |
147 | static void * buildTPC(void * current);␊ |
148 | static void * buildPTC(void * current);␊ |
149 | static void * buildTSS(void * current, PKG_TSTATES * pkg_tstates);␊ |
150 | static void * buildTSD(void * current, U32 domain, U32 cpusInDomain);␊ |
151 | #endif␊ |
152 | #if pstate_power_support␊ |
153 | static U64 mulU64byU64(U64 a, U64 b, U64 * high);␊ |
154 | static U32 compute_pstate_power(CPU_DETAILS * cpu, U32 ratio, U32 TDP);␊ |
155 | #endif␊ |
156 | #if BUILD_ACPI_TSS || pstate_power_support␊ |
157 | static U64 divU64byU64(U64 n, U64 d, U64 * rem);␊ |
158 | static U32 compute_tdp(CPU_DETAILS * cpu);␊ |
159 | #endif␊ |
160 | static bool is_sandybridge(void);␊ |
161 | static bool is_jaketown(void);␊ |
162 | static U32 get_bclk(void);␊ |
163 | static void GetMaxRatio(U32 * max_non_turbo_ratio);␊ |
164 | //static U32 computePstateRatio(const U32 max, const U32 min, const U32 turboEnabled, const U32 numStates, const U32 pstate);␊ |
165 | //static U32 computeNumPstates(const U32 max, const U32 min, const U32 turboEnabled, const U32 pssLimit);␊ |
166 | ␊ |
167 | #if UNUSED␊ |
168 | static ACPI_TABLE_FACS* generate_facs(bool updatefacs );␊ |
169 | #endif␊ |
170 | ␊ |
171 | #define MAX_NON_SSDT_TABLE 15␊ |
172 | #define MAX_SSDT_TABLE 15 // 15 additional SSDT tables ␊ |
173 | #define MAX_ACPI_TABLE MAX_NON_SSDT_TABLE + MAX_SSDT_TABLE␊ |
174 | ␊ |
175 | // Security space for SSDT , FACP & MADT table generation,␊ |
176 | // the size can be increased ␊ |
177 | // note: the table will not placed in the reserved space if the 'normal' space is not full␊ |
178 | #define RESERVED_AERA 3␊ |
179 | ␊ |
180 | #define ACPI_TABLE_LIST_FULL MAX_ACPI_TABLE + RESERVED_AERA + 1␊ |
181 | ␊ |
182 | #define ACPI_TABLE_LIST_FULL_NON_RESERVED MAX_ACPI_TABLE + 1␊ |
183 | ␊ |
184 | #ifndef ULONG_MAX_32␊ |
185 | #define ULONG_MAX_32 4294967295UL␊ |
186 | #endif␊ |
187 | ␊ |
188 | #define __RES(s, u)␉␉␉␉␉␉␉␉␉␉␉␉\␊ |
189 | static inline unsigned u␉␉␉␉␉␉␉␉␉␉\␊ |
190 | resolve_##s(unsigned u defaultentry, char *str, int base) \␊ |
191 | {␉␉␉␉␉␉␉␉␉␉␉␉␉␉␉␉\␊ |
192 | unsigned u entry = defaultentry;␉␉␉␉␉␉␉\␊ |
193 | if (str && (strcmp(str,"Default") != 0)) {␉␉␉␉␉\␊ |
194 | entry = strtoul((const char *)str, NULL,base);␉␉␉␉\␊ |
195 | }␉␉␉␉␉␉␉␉␉␉␉␉␉␉␉\␊ |
196 | return entry;␉␉␉␉␉␉␉␉␉␉␉␉\␊ |
197 | }␊ |
198 | ␊ |
199 | #if UNUSED␊ |
200 | __RES(cst, int)␊ |
201 | #endif /* UNUSED */␊ |
202 | ␊ |
203 | static ACPI_TABLE_HEADER * get_new_table_in_list(U32 *new_table_list, U32 Signature, U8 *retIndex )␊ |
204 | {␊ |
205 | ␉ACPI_TABLE_HEADER **table_array = (ACPI_TABLE_HEADER **) new_table_list;␊ |
206 | ␉U8 index ;␊ |
207 | ␉*retIndex = 0;␊ |
208 | ␉␊ |
209 | ␉for (index = 0; index < (MAX_ACPI_TABLE + RESERVED_AERA); index++)␊ |
210 | ␉{␊ |
211 | ␉␉if (*(U32 *) (table_array[index]->Signature) == Signature)␊ |
212 | ␉␉{␊ |
213 | ␉␉␉*retIndex = index;␊ |
214 | ␉␉␉return table_array[index] ;␊ |
215 | ␉␉}␊ |
216 | ␉}␊ |
217 | ␉return (void*)0ul;␊ |
218 | }␊ |
219 | ␊ |
220 | static U8 get_number_of_tables_in_list(U32 *new_table_list, U32 Signature )␊ |
221 | {␊ |
222 | ␉ACPI_TABLE_HEADER **table_array = (ACPI_TABLE_HEADER **) new_table_list;␊ |
223 | ␉U8 index ;␊ |
224 | ␉U8 InstalledTables = 0;␊ |
225 | ␉␊ |
226 | ␉for (index = 0; index < (MAX_ACPI_TABLE + RESERVED_AERA); index++)␊ |
227 | ␉{␊ |
228 | ␉␉if (*(U32 *) (table_array[index]->Signature) == Signature)␊ |
229 | ␉␉{␊ |
230 | ␉␉␉InstalledTables++ ;␊ |
231 | ␉␉}␊ |
232 | ␉}␊ |
233 | ␉return InstalledTables;␊ |
234 | }␊ |
235 | ␊ |
236 | static U8 get_0ul_index_in_list(U32 *new_table_list, bool reserved )␊ |
237 | {␊ |
238 | ␉U8 index ;␊ |
239 | ␉␊ |
240 | ␉U8 maximum = (reserved == true) ? MAX_ACPI_TABLE + RESERVED_AERA : MAX_ACPI_TABLE;␊ |
241 | ␉␊ |
242 | ␉for (index = 0; index < maximum; index++)␊ |
243 | ␉{␊ |
244 | ␉␉if (new_table_list[index] == 0ul)␊ |
245 | ␉␉{␊ |
246 | ␉␉␉return index ;␊ |
247 | ␉␉}␊ |
248 | ␉}␊ |
249 | ␉return (reserved == true)? ACPI_TABLE_LIST_FULL : ACPI_TABLE_LIST_FULL_NON_RESERVED;␊ |
250 | }␊ |
251 | ␊ |
252 | /* cparm : This time we check it by the acpi signature */␊ |
253 | static void sanitize_new_table_list(U32 *new_table_list )␊ |
254 | {␊ |
255 | ␉ACPI_TABLE_HEADER **table_array = (ACPI_TABLE_HEADER **) new_table_list;␊ |
256 | ␉U8 index ;␊ |
257 | ␉␊ |
258 | ␉for (index = 0; index < MAX_ACPI_TABLE; index++)␊ |
259 | ␉{␊ |
260 | ␉␉U32 current_sig = *(U32 *) (table_array[index]->Signature);␊ |
261 | ␉␉␊ |
262 | ␉␉if ((current_sig == NAMESEG(ACPI_SIG_FACS) /* not supported */ ) ␊ |
263 | ␉␉␉|| (current_sig == NAMESEG(ACPI_SIG_XSDT)) ␊ |
264 | ␉␉␉|| (current_sig == NAMESEG(ACPI_SIG_RSDT)) || (*(volatile U64 *)table_array[index] == NAMESEG64(ACPI_SIG_RSDP)) )␊ |
265 | ␉␉{␊ |
266 | ␉␉␉␊ |
267 | ␉␉␉void *buf = (void*)new_table_list[index];␊ |
268 | ␉␉␉free(buf);␊ |
269 | ␉␉␉new_table_list[index] = 0ul ;␊ |
270 | ␉␉}␊ |
271 | ␉}␊ |
272 | }␊ |
273 | ␊ |
274 | /* cparm : move all tables to kernel memory */␊ |
275 | static void move_table_list_to_kmem(U32 *new_table_list )␊ |
276 | {␊ |
277 | ␉ACPI_TABLE_HEADER **table_array = (ACPI_TABLE_HEADER **) new_table_list;␊ |
278 | ␉U8 index ;␊ |
279 | ␉␊ |
280 | ␉for (index = 0; index < MAX_ACPI_TABLE; index++)␊ |
281 | ␉{␊ |
282 | ␉␉if (new_table_list[index] != 0ul)␊ |
283 | ␉␉{␊ |
284 | ␊ |
285 | ␉␉␉U32 current_sig = *(U32 *) (table_array[index]->Signature);␊ |
286 | ␉␉␉if ((current_sig != NAMESEG(ACPI_SIG_FACS) /* not supported */ ) ␊ |
287 | ␉␉␉␉&& (current_sig != NAMESEG(ACPI_SIG_XSDT)) ␊ |
288 | ␉␉␉␉&& (current_sig != NAMESEG(ACPI_SIG_RSDT)) && (*(volatile U64 *)table_array[index] != NAMESEG64(ACPI_SIG_RSDP))␊ |
289 | ␉␉␉␉&& (GetChecksum(table_array[index], table_array[index]->Length) == 0))␊ |
290 | ␉␉␉{␊ |
291 | ␉␉␉␉␊ |
292 | ␉␉␉␉void *tableAddr=(void*)AllocateKernelMemory(table_array[index]->Length);␊ |
293 | ␉␉␉␉if (!tableAddr) {␊ |
294 | ␉␉␉␉␉printf("Unable to allocate kernel memory for aml file ");␊ |
295 | ␉␉␉␉␉␊ |
296 | ␉␉␉␉␉void *buf = (void*)new_table_list[index];␊ |
297 | ␉␉␉␉␉free(buf);␊ |
298 | ␉␉␉␉␉new_table_list[index] = 0ul ;␊ |
299 | ␉␉␉␉␉continue;␊ |
300 | ␉␉␉␉}␊ |
301 | ␉␉␉␉bcopy(table_array[index], tableAddr, table_array[index]->Length);␊ |
302 | ␉␉␉␉new_table_list[index] = 0ul ;␊ |
303 | ␉␉␉␉new_table_list[index] = (U32)tableAddr ;␊ |
304 | ␉␉␉␉␊ |
305 | ␉␉␉} ␊ |
306 | ␉␉␉else␊ |
307 | ␉␉␉{␊ |
308 | ␉␉␉␉␊ |
309 | ␉␉␉␉void *buf = (void*)new_table_list[index];␊ |
310 | ␉␉␉␉free(buf);␊ |
311 | ␉␉␉␉new_table_list[index] = 0ul ;␊ |
312 | ␉␉␉}␉␉␉␊ |
313 | ␉␉}␊ |
314 | ␉}␊ |
315 | }␊ |
316 | ␊ |
317 | static ACPI_TABLE_RSDP * gen_alloc_rsdp_v2_from_v1(ACPI_TABLE_RSDP *rsdp )␊ |
318 | {␊ |
319 | ␉␊ |
320 | ␉ACPI_TABLE_RSDP * rsdp_conv = (ACPI_TABLE_RSDP *)AllocateKernelMemory(sizeof(ACPI_TABLE_RSDP));␊ |
321 | ␉␊ |
322 | ␉if (rsdp_conv) {␊ |
323 | ␉␉bzero(rsdp_conv, sizeof(ACPI_TABLE_RSDP));␊ |
324 | ␉␉memcpy(rsdp_conv, rsdp, ACPI_RSDP_REV0_SIZE);␊ |
325 | ␉␉␊ |
326 | ␉␉/* Add/change fields */␊ |
327 | ␉␉rsdp_conv->Revision = 2; /* ACPI version 3 */␊ |
328 | ␉␉rsdp_conv->Length = sizeof(ACPI_TABLE_RSDP);␊ |
329 | ␉␉␊ |
330 | ␉␉/* Correct checksums */ ␊ |
331 | ␉␉setRsdpchecksum(rsdp_conv);␊ |
332 | ␉␉setRsdpXchecksum(rsdp_conv);␊ |
333 | ␉}␉ ␊ |
334 | ␊ |
335 | return (rsdp_conv) ? rsdp_conv : (void*)0ul ;␊ |
336 | }␊ |
337 | ␊ |
338 | static ACPI_TABLE_RSDT * gen_alloc_rsdt_from_xsdt(ACPI_TABLE_XSDT *xsdt)␊ |
339 | {␊ |
340 | U32 index;␊ |
341 | U32 num_tables;␊ |
342 | ␊ |
343 | ␉DBG("Attempting to generate RSDT from XSDT \n");␊ |
344 | ␉␊ |
345 | num_tables= get_num_tables64(xsdt);␊ |
346 | ␊ |
347 | ACPI_TABLE_RSDT * rsdt_conv=(ACPI_TABLE_RSDT *)AllocateKernelMemory(sizeof(ACPI_TABLE_HEADER)+(num_tables * 4));␊ |
348 | ␉if (!rsdt_conv)␊ |
349 | ␉{␊ |
350 | ␉␉printf("Unable to allocate kernel memory for rsdt conv\n");␊ |
351 | ␉␉return (void*)0ul;␊ |
352 | ␉}␊ |
353 | ␉␊ |
354 | ␉␊ |
355 | ␉bzero(rsdt_conv, sizeof(ACPI_TABLE_HEADER)+(num_tables * 4));␊ |
356 | memcpy(&rsdt_conv->Header, &xsdt->Header, sizeof(ACPI_TABLE_HEADER));␊ |
357 | ␊ |
358 | rsdt_conv->Header.Signature[0] = 'R';␊ |
359 | rsdt_conv->Header.Signature[1] = 'S';␊ |
360 | rsdt_conv->Header.Signature[2] = 'D';␊ |
361 | rsdt_conv->Header.Signature[3] = 'T';␊ |
362 | rsdt_conv->Header.Length = sizeof(ACPI_TABLE_HEADER)+(num_tables * 4);␊ |
363 | ␊ |
364 | ␉for (index=0;index<num_tables;index++)␊ |
365 | {␊ |
366 | ␉␉U64 ptr = xsdt->TableOffsetEntry[index];␊ |
367 | ␉␉␊ |
368 | ␉␉{␉␉␉␉␊ |
369 | ␉␉␉if (ptr > ULONG_MAX)␊ |
370 | ␉␉␉{␊ |
371 | #if DEBUG_ACPI␉␉␉␉␉␉␊ |
372 | ␉␉␉␉printf("Warning xsdt->TableOffsetEntry[%d]: Beyond addressable memory in this CPU mode, ignored !!!\n",index);␊ |
373 | #endif␊ |
374 | ␉␉␉␉continue;␉␊ |
375 | ␉␉␉}␊ |
376 | #if DEBUG_ACPI␉␊ |
377 | ␉␉␉printf("* Processing : ");␊ |
378 | ␉␉␉print_nameseg(*(U32 *) ((ACPI_TABLE_HEADER *) (unsigned long)ptr)->Signature);␊ |
379 | ␉␉␉printf("\n");␉␉␉␊ |
380 | #endif␉␉␉␉␉␊ |
381 | ␉␉␉int method = 0;␊ |
382 | ␉␉␉getIntForKey(kAcpiMethod, &method, &bootInfo->chameleonConfig);␊ |
383 | ␉␉␉␊ |
384 | ␉␉␉␊ |
385 | ␉␉␉if (method != 0x2)␊ |
386 | ␉␉␉{␊ |
387 | ␉␉␉␉if (GetChecksum(((ACPI_TABLE_HEADER *) (unsigned long)ptr), ␊ |
388 | ␉␉␉␉␉␉␉␉((ACPI_TABLE_HEADER *) (unsigned long)ptr)->Length) != 0)␊ |
389 | ␉␉␉␉{␊ |
390 | #if DEBUG_ACPI␉␉␉␉␉␉␊ |
391 | ␉␉␉␉␉printf("Warning : Invalide checksum, ignored !!!\n",index);␊ |
392 | #endif␊ |
393 | ␉␉␉␉␉continue;␊ |
394 | ␉␉␉␉}␊ |
395 | ␉␉␉}␉␉␉␊ |
396 | ␉␉␉␊ |
397 | ␉␉}␉␉␉␊ |
398 | ␊ |
399 | ␉␉{␊ |
400 | ␉␉␉if (*(U32 *) ((ACPI_TABLE_HEADER *) (unsigned long)ptr)->Signature == NAMESEG(ACPI_SIG_FADT))␊ |
401 | ␉␉␉{␊ |
402 | ␉␉␉␉ACPI_TABLE_FADT *fadt=(ACPI_TABLE_FADT *)((U32)ptr);␊ |
403 | ␉␉␉␉␊ |
404 | ␉␉␉␉ACPI_TABLE_FADT *fadt_conv = (void*)0ul;␊ |
405 | ␉␉␉␉␊ |
406 | ␉␉␉␉if (fadt->Header.Revision > 1)␊ |
407 | ␉␉␉␉{␊ |
408 | ␉␉␉␉␉U8 buffer[0x74];␊ |
409 | ␉␉␉␉␉DBG("Downgrading ACPI V%d FADT to ACPI V1 FADT \n", fadt->Header.Revision);␊ |
410 | ␉␉␉␉␉fadt_conv=(ACPI_TABLE_FADT *)buffer;␊ |
411 | ␉␉␉␉␉memcpy(fadt_conv, fadt, 0x74);␊ |
412 | ␉␉␉␉␉fadt_conv->Header.Length = 0x74;␊ |
413 | ␉␉␉␉␉fadt_conv->Header.Revision = 0x01;␉␉␉␉␉␊ |
414 | ␉␉␉␉␉SetChecksum(&fadt_conv->Header);␊ |
415 | ␉␉␉␉} ␊ |
416 | ␉␉␉␉else␊ |
417 | ␉␉␉␉{␊ |
418 | ␉␉␉␉␉fadt_conv = fadt;␊ |
419 | ␉␉␉␉}␊ |
420 | ␉␉␉␉␊ |
421 | ␉␉␉␉ACPI_TABLE_FADT *fadt_mod = patch_fadt(fadt_conv, ((ACPI_TABLE_DSDT*)((U32)fadt->XDsdt)), false); ␊ |
422 | ␉␉␉␉if (fadt_mod == (void*)0ul)␊ |
423 | ␉␉␉␉{␊ |
424 | ␉␉␉␉␉printf("Error: Failed to patch FADT Table, trying wiht the original fadt pointer\n");␊ |
425 | ␉␉␉␉␉fadt_mod = fadt;␊ |
426 | ␉␉␉␉}␊ |
427 | ␉␉␉␉␊ |
428 | ␉␉␉␉rsdt_conv->TableOffsetEntry[index] = ((U32)fadt_mod);␊ |
429 | #if DEBUG_ACPI␉␉␉␊ |
430 | ␉␉␉␉print_nameseg(*(U32 *) ((ACPI_TABLE_HEADER *) (unsigned long)ptr)->Signature);␊ |
431 | ␉␉␉␉printf(" table converted and added succesfully\n");␉␉␉␊ |
432 | #endif␊ |
433 | ␉␉␉␉continue;␊ |
434 | ␉␉␉}␊ |
435 | ␉␉}␊ |
436 | ␊ |
437 | ␉␉{␊ |
438 | ␉␉␉rsdt_conv->TableOffsetEntry[index] = (U32)ptr;␊ |
439 | #if DEBUG_ACPI␉␉␉␊ |
440 | ␉␉␉print_nameseg(*(U32 *) ((ACPI_TABLE_HEADER *) (unsigned long)ptr)->Signature);␊ |
441 | ␉␉␉printf(" table converted and added succesfully\n");␉␊ |
442 | #endif␉␉␉␉␉␊ |
443 | ␉␉}␊ |
444 | ␊ |
445 | }␊ |
446 | DBG("RSDT_CONV : Original checksum %d\n", rsdt_conv->Header.Checksum);␊ |
447 | SetChecksum(&rsdt_conv->Header);␊ |
448 | DBG("New checksum %d\n", rsdt_conv->Header.Checksum);␊ |
449 | ␉␊ |
450 | return rsdt_conv;␊ |
451 | }␊ |
452 | ␊ |
453 | static ACPI_TABLE_XSDT * gen_alloc_xsdt_from_rsdt(ACPI_TABLE_RSDT *rsdt)␊ |
454 | {␉␊ |
455 | ␉U32 index;␊ |
456 | U32 num_tables;␉␊ |
457 | ␊ |
458 | ␉DBG("Attempting to generate XSDT from RSDT \n");␊ |
459 | ␉␊ |
460 | num_tables= get_num_tables(rsdt);␊ |
461 | ␊ |
462 | ACPI_TABLE_XSDT * xsdt_conv=(ACPI_TABLE_XSDT *)AllocateKernelMemory(sizeof(ACPI_TABLE_HEADER)+(num_tables * 8));␊ |
463 | ␉␊ |
464 | ␉if (!xsdt_conv) {␊ |
465 | ␉␉printf("Unable to allocate kernel memory for xsdt conv\n");␊ |
466 | ␉␉return (void*)0ul;␊ |
467 | ␉}␊ |
468 | ␉␊ |
469 | ␉bzero(xsdt_conv, sizeof(ACPI_TABLE_HEADER)+(num_tables * 8));␊ |
470 | memcpy(&xsdt_conv->Header, &rsdt->Header, sizeof(ACPI_TABLE_HEADER));␊ |
471 | ␊ |
472 | xsdt_conv->Header.Signature[0] = 'X';␊ |
473 | xsdt_conv->Header.Signature[1] = 'S';␊ |
474 | xsdt_conv->Header.Signature[2] = 'D';␊ |
475 | xsdt_conv->Header.Signature[3] = 'T';␊ |
476 | xsdt_conv->Header.Length = sizeof(ACPI_TABLE_HEADER)+(num_tables * 8);␊ |
477 | ␊ |
478 | ␉ACPI_TABLE_HEADER **table_array = (ACPI_TABLE_HEADER **) rsdt->TableOffsetEntry;␊ |
479 | ␉␊ |
480 | for (index=0;index<num_tables;index++)␊ |
481 | {␊ |
482 | {␉␉␉␉␊ |
483 | #if DEBUG_ACPI␉␊ |
484 | printf("* Processing : ");␊ |
485 | print_nameseg(*(U32*) (table_array[index]->Signature));␊ |
486 | printf("\n");␉␉␉␊ |
487 | #endif␉␉␉␊ |
488 | int method = 0;␊ |
489 | ␉␉␉getIntForKey(kAcpiMethod, &method, &bootInfo->chameleonConfig);␊ |
490 | ␉␉␉␊ |
491 | ␉␉␉␊ |
492 | ␉␉␉if (method != 0x2)␊ |
493 | {␊ |
494 | if (GetChecksum(table_array[index], table_array[index]->Length) != 0)␊ |
495 | {␊ |
496 | #if DEBUG_ACPI␉␉␉␉␉␉␊ |
497 | printf("Warning : Invalide checksum, ignored !!!\n",index);␊ |
498 | #endif␊ |
499 | continue;␊ |
500 | }␊ |
501 | }␊ |
502 | ␊ |
503 | }␊ |
504 | ␊ |
505 | {␊ |
506 | if (*(U32 *) (table_array[index]->Signature) == NAMESEG(ACPI_SIG_FADT))␊ |
507 | {␊ |
508 | ACPI_TABLE_FADT *FacpPointer = ((ACPI_TABLE_FADT*)table_array[index]);␊ |
509 | ACPI_TABLE_FADT *fadt_mod = (ACPI_TABLE_FADT *)patch_fadt(FacpPointer,((ACPI_TABLE_DSDT*)FacpPointer->Dsdt),true);␊ |
510 | if (fadt_mod == (void*)0ul) ␊ |
511 | {␊ |
512 | printf("Error: Failed to patch (& update) FADT Table, fallback to original fadt pointer\n");␊ |
513 | fadt_mod = FacpPointer;␊ |
514 | }␊ |
515 | xsdt_conv->TableOffsetEntry[index] = ((U64)((U32)fadt_mod));␊ |
516 | ␊ |
517 | continue;␊ |
518 | }␊ |
519 | }␊ |
520 | ␊ |
521 | xsdt_conv->TableOffsetEntry[index] = ((U64)((U32)table_array[index])); ␊ |
522 | }␊ |
523 | DBG("XSDT_CONV : Original checksum %d\n", xsdt_conv->Header.Checksum);␊ |
524 | SetChecksum(&xsdt_conv->Header);␊ |
525 | DBG("New checksum %d\n", xsdt_conv->Header.Checksum);␊ |
526 | ␉␊ |
527 | return xsdt_conv;␊ |
528 | }␊ |
529 | ␊ |
530 | #if ACPISGN␊ |
531 | static void MakeAcpiSgn(void)␊ |
532 | {␊ |
533 | ␊ |
534 | ␉char * DefaultplatformName = NULL;␊ |
535 | ␉Model32 = 0;␊ |
536 | ␉␊ |
537 | ␉if ((DefaultplatformName = readDefaultPlatformName()))␊ |
538 | ␉{␊ |
539 | ␉␉Model32 = OSSwapHostToBigInt32(adler32( (unsigned char *) DefaultplatformName, strlen(DefaultplatformName)));␊ |
540 | ␉}␊ |
541 | ␉␊ |
542 | ␉uuid32 = 0; ␊ |
543 | ␉␊ |
544 | ␉const char *uuidStr = getStringFromUUID((int8_t*)(uint32_t)get_env(envSysId));␊ |
545 | ␉␊ |
546 | ␉if (strlen(uuidStr)) ␊ |
547 | ␉{␊ |
548 | ␉␉uuid32 = OSSwapHostToBigInt32(adler32( (unsigned char *) uuidStr, UUID_STR_LEN ));␊ |
549 | ␉}␊ |
550 | ␊ |
551 | }␊ |
552 | #endif␊ |
553 | ␊ |
554 | static void *loadACPITable(U32 *new_table_list, char *dirspec, const char *filename )␊ |
555 | {␉␊ |
556 | ␉int fd = -1;␊ |
557 | ␉char acpi_file[512];␊ |
558 | ␊ |
559 | ␉DBG("Searching for %s file ...\n", filename);␊ |
560 | ␉// Check booting partition␉␊ |
561 | ␊ |
562 | ␉sprintf(acpi_file, "%s%s",dirspec, filename); ␊ |
563 | ␉␊ |
564 | ␉fd=open(acpi_file,0);␊ |
565 | ␉␊ |
566 | ␉if (fd<0)␊ |
567 | ␉{␉␉␉␉␉␉␉␊ |
568 | ␉␉DBG("Couldn't open ACPI Table: %s\n", acpi_file);␊ |
569 | ␉␉return (void *)0ul ;␉␉␉␉␊ |
570 | ␉}␉␉␊ |
571 | ␉␊ |
572 | ␉void *tableAddr=(void*)malloc(file_size (fd));␊ |
573 | ␊ |
574 | ␉if (tableAddr)␊ |
575 | ␉{␊ |
576 | ␉␉if (read (fd, tableAddr, file_size (fd))!=file_size (fd))␊ |
577 | ␉␉{␊ |
578 | ␉␉␉printf("Couldn't read table %s\n",acpi_file);␊ |
579 | ␉␉␉free (tableAddr);␊ |
580 | ␉␉␉close (fd);␊ |
581 | ␉␉␉return (void *)0ul ;␊ |
582 | ␉␉}␊ |
583 | ␉␉␊ |
584 | ␉␉close (fd);␊ |
585 | ␉␉␊ |
586 | ␉␉ACPI_TABLE_HEADER * header = (ACPI_TABLE_HEADER *)tableAddr;␉␉␊ |
587 | ␉␉␊ |
588 | ␉␉if (*(U32*)(header->Signature) != NAMESEG("SSDT"))␊ |
589 | ␉␉{␊ |
590 | ␉␉␉U8 dummy = 0;␊ |
591 | ␉␉␉if (get_new_table_in_list(new_table_list, *(U32*)(header->Signature), &dummy))␊ |
592 | ␉␉␉{␊ |
593 | #if DEBUG_ACPI␊ |
594 | ␉␉␉␉printf("Warning: A ");␊ |
595 | ␉␉␉␉print_nameseg(*(U32*) (header->Signature));␊ |
596 | ␉␉␉␉printf(" Aml file is already loaded and registred, file skipped !!\n");␊ |
597 | #endif␊ |
598 | ␉␉␉␉free(tableAddr);␊ |
599 | ␉␉␉␉return (void*)0ul;␊ |
600 | ␉␉␉} ␊ |
601 | ␉␉} ␊ |
602 | ␉␉else␊ |
603 | ␉␉{␊ |
604 | ␉␉␉if (get_number_of_tables_in_list(new_table_list, NAMESEG("SSDT")) >= MAX_SSDT_TABLE)␊ |
605 | ␉␉␉{␊ |
606 | ␉␉␉␉DBG("Warning: Max number of SSDT aml files reached, file skipped !!\n");␊ |
607 | ␉␉␉␉free(tableAddr);␊ |
608 | ␉␉␉␉return (void*)0ul;␊ |
609 | ␉␉␉}␊ |
610 | ␉␉}␊ |
611 | ␊ |
612 | ␉␉␊ |
613 | ␉␉if (checkOem == true)␊ |
614 | ␉␉{␉␉␉␊ |
615 | ␉␉␉if (header->OemRevision == Model32)␊ |
616 | ␉␉␉{␊ |
617 | ␉␉␉␉goto continue_loading;␊ |
618 | ␉␉␉}␊ |
619 | ␉␉␉␊ |
620 | ␉␉␉if (header->OemRevision == uuid32)␊ |
621 | ␉␉␉{␊ |
622 | ␉␉␉␉goto continue_loading;␊ |
623 | ␉␉␉}␊ |
624 | ␉␉␉␊ |
625 | ␉␉␉DBG("Bad signature aka Oem Revision (0x%08lx) for Aml file (%s), file skipped !!\n", header->OemRevision, acpi_file);␊ |
626 | ␉␉␉DBG("uuid32 (0x%08lx) , model32 (0x%08lx)\n", uuid32, Model32);␊ |
627 | ␉␉␉␊ |
628 | ␉␉␉free(tableAddr);␊ |
629 | ␉␉␉return (void*)0ul;␉␉␉␊ |
630 | ␉␉} ␊ |
631 | ␉␉␊ |
632 | continue_loading:␊ |
633 | ␉␉␊ |
634 | ␉␉if (GetChecksum(header, header->Length) == 0)␊ |
635 | ␉␉{␊ |
636 | ␉␉␉DBG("Found valid AML file : %s ", filename);␊ |
637 | ␉␉␉verbose("[ %s ] read and stored at: %x", acpi_file, tableAddr);␊ |
638 | ␉␉␉printf("\n");␊ |
639 | ␉␉␉return tableAddr;␊ |
640 | ␉␉} ␊ |
641 | ␉␉else␊ |
642 | ␉␉{␊ |
643 | ␉␉␉printf("Warning : Incorrect cheksum for the file : %s,", acpi_file);␊ |
644 | ␉␉␉printf("␉␉ this file will be dropped.\n");␊ |
645 | ␉␉␉free(tableAddr);␊ |
646 | ␉␉␉return (void*)0ul;␊ |
647 | ␉␉}␉␉␊ |
648 | ␉}␊ |
649 | ␉else ␊ |
650 | ␉{␊ |
651 | ␉␉printf("Couldn't allocate memory for table %s\n", acpi_file);␊ |
652 | ␉␉close (fd);␊ |
653 | ␉}␉␊ |
654 | ␉␊ |
655 | ␉return (void *)0ul ;␊ |
656 | }␊ |
657 | ␊ |
658 | static U32 pmbase;␊ |
659 | static short cpuNamespace;␊ |
660 | PROCESSOR_NUMBER_TO_NAMESEG cpu_map[CPU_MAP_LIMIT];␊ |
661 | unsigned int cpu_map_count;␊ |
662 | int cpu_map_error;␊ |
663 | ␊ |
664 | #if DEBUG_ACPI␊ |
665 | static void print_nameseg(U32 i)␊ |
666 | {␊ |
667 | printf("%c%c%c%c",␊ |
668 | (int)(i & 0x000000ff),␊ |
669 | (int)((i & 0x0000ff00) >> 8),␊ |
670 | (int)((i & 0x00ff0000) >> 16),␊ |
671 | (int)(i >> 24));␊ |
672 | }␊ |
673 | #endif␊ |
674 | ␊ |
675 | static int generate_cpu_map_from_acpi(ACPI_TABLE_DSDT * DsdtPointer)␊ |
676 | {␊ |
677 | PROCESSOR_NUMBER_TO_NAMESEG *map = cpu_map;␊ |
678 | U32 processor_namespace = 0;␊ |
679 | U32 cpu;␊ |
680 | U8 *current, *end;␊ |
681 | ACPI_TABLE_HEADER *header;␊ |
682 | struct acpi_namespace ns;␊ |
683 | ␊ |
684 | ␉if ((cpu_map_error == 1) || (DsdtPointer == (void*)0ul)) ␊ |
685 | ␉␉return 1;␊ |
686 | ␉else if (cpu_map_count > 0) ␊ |
687 | ␉␉return 0;␊ |
688 | ␉␊ |
689 | DBG("Attempting to autodetect CPU map from ACPI DSDT; wish me luck\n");␉␊ |
690 | ␊ |
691 | current = (U8 *) DsdtPointer;␊ |
692 | current = decodeTableHeader(current, &header);␊ |
693 | end = current - sizeof(*header) + header->Length;␊ |
694 | ns.depth = 0;␊ |
695 | acpi_processor_count = 0;␊ |
696 | ␉//DBG("* DSDT debug start\n");␊ |
697 | parse_acpi_termlist(&ns, current, end);␊ |
698 | ␉//DBG("* DSDT debug end\n");␊ |
699 | ␉␊ |
700 | if (acpi_processor_count > CPU_MAP_LIMIT)␊ |
701 | ␉{␊ |
702 | ␉␉verbose("Too many processors: found %u processors\n", acpi_processor_count);␊ |
703 | return (cpu_map_error = 1);␊ |
704 | ␉}␊ |
705 | if (acpi_processor_count == 0)␊ |
706 | ␉{␊ |
707 | ␉␉verbose( "Found no processors in ACPI\n");␊ |
708 | return (cpu_map_error = 1);␊ |
709 | ␉}␊ |
710 | for (cpu = 0; cpu < acpi_processor_count; cpu++)␊ |
711 | ␉{␊ |
712 | U32 nameseg;␊ |
713 | if (acpi_processors[cpu].pmbase)␊ |
714 | ␉␉{␊ |
715 | U32 cpu_pmbase = acpi_processors[cpu].pmbase - 0x10;␊ |
716 | if (pmbase && cpu_pmbase != pmbase)␊ |
717 | ␉␉␉{␊ |
718 | ␉␉␉␉verbose("Found inconsistent pmbase addresses in ACPI: 0x%x and 0x%x\n", pmbase, cpu_pmbase);␊ |
719 | ␉␉␉␉return (cpu_map_error = 1);␊ |
720 | ␉␉␉}␊ |
721 | pmbase = cpu_pmbase;␊ |
722 | }␊ |
723 | if (acpi_processors[cpu].ns.depth > MAX_SUPPORTED_CPU_NAMESEGS + 1)␊ |
724 | ␉␉{␊ |
725 | ␉␉␉verbose("Processor path too deep: depth %u\n", acpi_processors[cpu].ns.depth);␊ |
726 | ␉␉␉return (cpu_map_error = 1);␊ |
727 | ␉␉}␊ |
728 | if (processor_namespace && acpi_processors[cpu].ns.nameseg[0] != processor_namespace)␊ |
729 | ␉␉{␊ |
730 | ␉␉␉verbose("Processor namespaces inconsistent\n");␊ |
731 | ␉␉␉return (cpu_map_error = 1);␊ |
732 | ␉␉}␊ |
733 | processor_namespace = acpi_processors[cpu].ns.nameseg[0];␊ |
734 | map->acpi_processor_number = acpi_processors[cpu].id;␊ |
735 | map->seg_count = acpi_processors[cpu].ns.depth - 1;␊ |
736 | for (nameseg = 0; nameseg < map->seg_count; nameseg++)␊ |
737 | map->nameseg[nameseg] = acpi_processors[cpu].ns.nameseg[nameseg + 1];␊ |
738 | map++;␊ |
739 | }␊ |
740 | if (!pmbase)␊ |
741 | ␉{␊ |
742 | ␉␉verbose("No pmbase found in ACPI\n");␊ |
743 | ␉␉return (cpu_map_error = 1);␊ |
744 | ␉}␊ |
745 | if (processor_namespace == NAMESEG("_PR_"))␊ |
746 | cpuNamespace = CPU_NAMESPACE_PR;␊ |
747 | else if (processor_namespace == NAMESEG("_SB_"))␊ |
748 | cpuNamespace = CPU_NAMESPACE_SB;␊ |
749 | else␊ |
750 | ␉{␊ |
751 | verbose("Found processors in invalid namespace; not _PR_ or _SB_\n");␊ |
752 | ␉␉return (cpu_map_error = 1);␊ |
753 | ␉}␊ |
754 | cpu_map_count = map - cpu_map;␊ |
755 | ␉␊ |
756 | #if DEBUG_ACPI␊ |
757 | ␉verbose("Found %d processors in ACPI, pmbase : 0x%x, cpu_map_count : %d, namespace : ",acpi_processor_count, pmbase, cpu_map_count );␊ |
758 | ␉print_nameseg(processor_namespace); ␊ |
759 | ␉verbose("\n");␊ |
760 | U32 i;␊ |
761 | verbose("Found processors name : \n" );␊ |
762 | for ( i = 0; i<cpu_map_count; i++)␊ |
763 | ␉{␉␉␉␊ |
764 | ␉␉U32 nseg = *(U32*)cpu_map[i].nameseg;␊ |
765 | print_nameseg(nseg); ␊ |
766 | ␉␉verbose(" ");␊ |
767 | }␊ |
768 | verbose("\n");␊ |
769 | #endif␊ |
770 | ␉␊ |
771 | ␉// TODO: Save the cpu map into the device tree␊ |
772 | return (cpu_map_error = 0);␊ |
773 | }␊ |
774 | ␊ |
775 | static bool is_sandybridge(void)␊ |
776 | {␊ |
777 | return Platform.CPU.Model == CPU_MODEL_SANDYBRIDGE;␊ |
778 | }␊ |
779 | ␊ |
780 | static bool is_jaketown(void)␊ |
781 | {␊ |
782 | return Platform.CPU.Model == CPU_MODEL_JAKETOWN;␊ |
783 | }␊ |
784 | ␊ |
785 | static U32 get_bclk(void)␊ |
786 | {␊ |
787 | ␉return (is_jaketown() || is_sandybridge()) ? 100 : 133;␊ |
788 | }␊ |
789 | /*␊ |
790 | //-----------------------------------------------------------------------------␊ |
791 | static U32 computePstateRatio(const U32 max, const U32 min, const U32 turboEnabled, const U32 numStates, const U32 pstate)␊ |
792 | {␊ |
793 | U32 ratiorange = max-min;␊ |
794 | U32 numGaps = numStates-1-turboEnabled;␊ |
795 | U32 adjPstate = pstate-turboEnabled;␊ |
796 | return (pstate == 0) ? (max + turboEnabled) :␊ |
797 | (ratiorange == 0) ? max :␊ |
798 | max-(((adjPstate*ratiorange)+(numGaps/2))/numGaps);␊ |
799 | }␊ |
800 | //-----------------------------------------------------------------------------␊ |
801 | static U32 computeNumPstates(const U32 max, const U32 min, const U32 turboEnabled, const U32 pssLimit)␊ |
802 | {␊ |
803 | U32 ratiorange, maxStates, numStates;␊ |
804 | ␊ |
805 | ratiorange = max - min + 1;␊ |
806 | maxStates = ratiorange + (turboEnabled ? 1 : 0);␊ |
807 | numStates = (pssLimit < maxStates) ? pssLimit : maxStates;␊ |
808 | return (numStates < 2) ? 0 : numStates;␊ |
809 | }␊ |
810 | */␊ |
811 | #if BUILD_ACPI_TSS || pstate_power_support␊ |
812 | static U64 divU64byU64(U64 n, U64 d, U64 * rem)␊ |
813 | {␊ |
814 | U32 i;␊ |
815 | U64 q = n;␊ |
816 | U64 r = 0;␊ |
817 | ␉␊ |
818 | for (i = 0; i < 64; i++) {␊ |
819 | r <<= 1;␊ |
820 | r |= (q & (1ULL << 63)) >> 63;␊ |
821 | q <<= 1;␊ |
822 | if (r >= d) {␊ |
823 | r -= d;␊ |
824 | q |= 1;␊ |
825 | }␊ |
826 | }␊ |
827 | if (rem)␊ |
828 | *rem = r;␊ |
829 | return q;␊ |
830 | }␊ |
831 | ␊ |
832 | static U32 compute_tdp(CPU_DETAILS * cpu)␊ |
833 | { ␊ |
834 | {␊ |
835 | if (is_jaketown() || is_sandybridge())␊ |
836 | {␊ |
837 | U64 power_limit_1 = cpu->package_power_limit & ((1ULL << 15) - 1);␊ |
838 | U64 power_unit = cpu->package_power_sku_unit & ((1ULL << 4) - 1);␊ |
839 | U64 tdp = divU64byU64(power_limit_1, 1 << power_unit, NULL);␊ |
840 | return (U32)tdp;␊ |
841 | }␊ |
842 | else␊ |
843 | {␊ |
844 | // tdp = (TURBO_POWER_CURRENT_LIMIT MSR 1ACh bit [14:0] / 8) Watts␊ |
845 | return cpu->tdp_limit / 8;␊ |
846 | }␊ |
847 | }␊ |
848 | ␉return (0);␊ |
849 | }␊ |
850 | #endif // BUILD_ACPI_TSS || pstate_power_support␊ |
851 | ␊ |
852 | #if pstate_power_support␊ |
853 | static U64 mulU64byU64(U64 a, U64 b, U64 * high)␊ |
854 | {␊ |
855 | U64 b_high = 0;␊ |
856 | U64 r_high = 0, r_low = 0;␊ |
857 | U64 bit;␊ |
858 | ␉␊ |
859 | for (bit = 1; bit; bit <<= 1) {␊ |
860 | if (a & bit) {␊ |
861 | if (r_low + b < r_low)␊ |
862 | r_high++;␊ |
863 | r_low += b;␊ |
864 | r_high += b_high;␊ |
865 | }␊ |
866 | b_high <<= 1;␊ |
867 | b_high |= (b & (1ULL << 63)) >> 63;␊ |
868 | b <<= 1;␊ |
869 | }␊ |
870 | ␉␊ |
871 | if (high)␊ |
872 | *high = r_high;␊ |
873 | return r_low;␊ |
874 | }␊ |
875 | ␊ |
876 | static U32 compute_pstate_power(CPU_DETAILS * cpu, U32 ratio, U32 TDP)␊ |
877 | {␊ |
878 | ␉if (is_jaketown() || is_sandybridge())␊ |
879 | ␉{␊ |
880 | ␉␉U32 P1_Ratio = cpu->max_ratio_as_mfg;␊ |
881 | ␉␉U64 M, pstate_power;␊ |
882 | ␉␉␊ |
883 | ␉␉// M = ((1.1 - ((P1_ratio - ratio) * 0.00625)) / 1.1) ^2␊ |
884 | ␉␉// To prevent loss of precision compute M * 10^5 (preserves 5 decimal places)␊ |
885 | ␉␉M = (P1_Ratio - ratio) * 625;␊ |
886 | ␉␉M = (110000 - M);␊ |
887 | ␉␉M = divU64byU64(M, 11, NULL);␊ |
888 | ␉␉M = divU64byU64(mulU64byU64(M, M, NULL), 1000, NULL);␊ |
889 | ␉␉␊ |
890 | ␉␉// pstate_power = ((ratio/p1_ratio) * M * TDP)␊ |
891 | ␉␉// Divide the final answer by 10^5 to remove the precision factor␊ |
892 | ␉␉pstate_power = mulU64byU64(ratio, M, NULL);␊ |
893 | ␉␉pstate_power = mulU64byU64(pstate_power, TDP, NULL);␊ |
894 | ␉␉pstate_power = divU64byU64(pstate_power, P1_Ratio, NULL);␊ |
895 | ␉␉pstate_power = divU64byU64(pstate_power, 100000, NULL);␊ |
896 | ␉␉return (U32)pstate_power; // in Watts␊ |
897 | ␉}␊ |
898 | ␉else␊ |
899 | ␉{␊ |
900 | ␉␉// pstate_power[ratio] = (ratio/P1_ratio)^3 * Core_TDP + Uncore_TDP␊ |
901 | ␉␉␊ |
902 | ␉␉// Core_TDP = (TURBO_POWER_CURRENT_LIMIT MSR 1ACh bit [30:16] / 8) Watts␊ |
903 | ␉␉U32 Core_TDP = cpu->tdc_limit / 8;␊ |
904 | ␉␉␊ |
905 | ␉␉// Uncore_TDP = TDP - Core_TDP␊ |
906 | ␉␉U32 Uncore_TDP = TDP - Core_TDP;␊ |
907 | ␉␉␊ |
908 | ␉␉// max_ratio_as_mfg = P1_Ratio derived from Brand String returned by CPUID instruction␊ |
909 | ␉␉U32 P1_Ratio = cpu->max_ratio_as_mfg;␊ |
910 | ␉␉␊ |
911 | #define PRECISION_FACTOR (U32) 30␊ |
912 | #define PRECISION_FACTOR_CUBED (U32) (PRECISION_FACTOR * PRECISION_FACTOR * PRECISION_FACTOR)␊ |
913 | ␉␉␊ |
914 | ␉␉U32 ratio_factor = (ratio * PRECISION_FACTOR)/P1_Ratio;␊ |
915 | ␉␉return ((ratio_factor * ratio_factor * ratio_factor * Core_TDP) / PRECISION_FACTOR_CUBED) + Uncore_TDP;␊ |
916 | ␉}␊ |
917 | return (0);␊ |
918 | }␊ |
919 | #endif // pstate_power_support␊ |
920 | ␊ |
921 | static U32 encode_pstate(U32 ratio)␊ |
922 | {␊ |
923 | ␉if (is_jaketown() || is_sandybridge())␊ |
924 | ␉␉return ratio << 8;␊ |
925 | ␉return ratio;␊ |
926 | }␊ |
927 | ␊ |
928 | //-----------------------------------------------------------------------------␊ |
929 | static void GetMaxRatio(U32 * max_non_turbo_ratio)␊ |
930 | {␊ |
931 | ␉U32 index;␊ |
932 | ␉U32 max_ratio=0;␊ |
933 | ␉U32 frequency=0;␊ |
934 | U32 multiplier = 0;␊ |
935 | char␉␉␉*BrandString;␊ |
936 | ␉// Verify CPUID brand string function is supported␊ |
937 | ␉if (Platform.CPU.CPUID[CPUID_80][0] < 80000004)␊ |
938 | ␉{␊ |
939 | ␉␉*max_non_turbo_ratio = max_ratio;␊ |
940 | ␉␉return;␊ |
941 | ␉}␉␊ |
942 | ␉BrandString = (char *)Platform.CPU.BrandString;␊ |
943 | // -2 to prevent buffer overrun because looking for y in yHz, so z is +2 from y␊ |
944 | for (index=0; index<48-2; index++) {␊ |
945 | // format is either “x.xxyHz” or “xxxxyHz”, where y=M,G,T and x is digits␊ |
946 | // Search brand string for “yHz” where y is M, G, or T␊ |
947 | // Set multiplier so frequency is in MHz␊ |
948 | if ( BrandString[index+1] == 'H' && BrandString[index+2] == 'z')␊ |
949 | {␊ |
950 | if (BrandString[index] == 'M')␊ |
951 | multiplier = 1;␊ |
952 | else if (BrandString[index] == 'G')␊ |
953 | multiplier = 1000;␊ |
954 | else if (BrandString[index] == 'T')␊ |
955 | multiplier = 1000000;␊ |
956 | }␊ |
957 | if (multiplier > 0 && index >= 4 /* who can i call that, buffer underflow :-) ??*/)␊ |
958 | {␊ |
959 | // Copy 7 characters (length of “x.xxyHz”)␊ |
960 | // index is at position of y in “x.xxyHz”␊ |
961 | ␊ |
962 | // Compute frequency (in MHz) from brand string␊ |
963 | if (BrandString[index-3] == '.')␊ |
964 | { // If format is “x.xx”␊ |
965 | if (isdigit(BrandString[index-4]) && isdigit(BrandString[index-2]) &&␊ |
966 | isdigit(BrandString[index-1]))␊ |
967 | {␊ |
968 | frequency = (U32)(BrandString[index-4] - '0') * multiplier;␊ |
969 | frequency += (U32)(BrandString[index-2] - '0') * (multiplier / 10);␊ |
970 | frequency += (U32)(BrandString[index-1] - '0') * (multiplier / 100);␊ |
971 | } ␊ |
972 | }␊ |
973 | else␊ |
974 | { // If format is xxxx␊ |
975 | if (isdigit(BrandString[index-4]) && isdigit(BrandString[index-3]) && ␊ |
976 | isdigit(BrandString[index-2]) && isdigit(BrandString[index-1]))␊ |
977 | {␊ |
978 | frequency = (U32)(BrandString[index-4] - '0') * 1000;␊ |
979 | frequency += (U32)(BrandString[index-3] - '0') * 100;␊ |
980 | frequency += (U32)(BrandString[index-2] - '0') * 10;␊ |
981 | frequency += (U32)(BrandString[index-1] - '0');␊ |
982 | frequency *= multiplier;␊ |
983 | }␊ |
984 | ␊ |
985 | }␊ |
986 | ␊ |
987 | max_ratio = frequency / get_bclk();␊ |
988 | break; ␊ |
989 | }␊ |
990 | }␊ |
991 | ␉␊ |
992 | ␉// Return non-zero Max Non-Turbo Ratio obtained from CPUID brand string␊ |
993 | ␉// or return 0 indicating Max Non-Turbo Ratio not available␊ |
994 | ␉*max_non_turbo_ratio = max_ratio;␊ |
995 | }␊ |
996 | ␊ |
997 | //-----------------------------------------------------------------------------␊ |
998 | static void collect_cpu_info(CPU_DETAILS * cpu)␊ |
999 | { ␊ |
1000 | ␉boolean_t␉dynamic_acceleration = 0;␊ |
1001 | ␉U32␉sub_Cstates = 0;␊ |
1002 | ␉U32 extensions = 0; ␊ |
1003 | ␉boolean_t␉invariant_APIC_timer = 0;␊ |
1004 | ␉boolean_t␉fine_grain_clock_mod = 0;␊ |
1005 | ␊ |
1006 | #if BUILD_ACPI_TSS || pstate_power_support␊ |
1007 | ␉if (Platform.CPU.CPUID[CPUID_0][0] >= 0x5) { ␊ |
1008 | ␉␉/*␊ |
1009 | ␉␉ * Extract the Monitor/Mwait Leaf info:␊ |
1010 | ␉␉ */␊ |
1011 | sub_Cstates = Platform.CPU.CPUID[CPUID_5][3];␊ |
1012 | extensions = Platform.CPU.CPUID[CPUID_5][2];␉␊ |
1013 | ␉}␊ |
1014 | ␉␊ |
1015 | ␉if (Platform.CPU.CPUID[CPUID_0][0] >= 6) {␊ |
1016 | ␉␉dynamic_acceleration = bitfield(Platform.CPU.CPUID[CPUID_6][0], 1, 1); // "Dynamic Acceleration Technology (Turbo Mode)"␊ |
1017 | ␉␉invariant_APIC_timer = bitfield(Platform.CPU.CPUID[CPUID_6][0], 2, 2); // "Invariant APIC Timer"␊ |
1018 | fine_grain_clock_mod = bitfield(Platform.CPU.CPUID[CPUID_6][0], 4, 4);␊ |
1019 | ␉}␊ |
1020 | cpu->turbo_available = (U32)dynamic_acceleration;␊ |
1021 | ␉␊ |
1022 | ␉{␊ |
1023 | ␉␉U32 temp32 = 0;␊ |
1024 | ␉␉U64 temp64= 0;␊ |
1025 | ␉␉int tdp;␊ |
1026 | ␉␉if (getIntForKey("TDP", &tdp, &bootInfo->chameleonConfig))␊ |
1027 | ␉␉{␊ |
1028 | ␉␉␉temp32 = (U32) (tdp*8) ; ␊ |
1029 | ␉␉␉␊ |
1030 | ␉␉␉int tdc;␊ |
1031 | ␉␉␉if (getIntForKey("TDC", &tdc, &bootInfo->chameleonConfig))␊ |
1032 | ␉␉␉{␊ |
1033 | ␉␉␉␉temp32 = (U32) (temp32) | tdc<<16 ; ␊ |
1034 | ␉␉␉␉␊ |
1035 | ␉␉␉}␊ |
1036 | ␉␉␉else if (tdp)␊ |
1037 | ␉␉␉{␊ |
1038 | ␉␉␉␉temp32 = (U32) (temp32) | ((tdp)*8)<<16 ;␊ |
1039 | ␉␉␉}␊ |
1040 | ␉␉␉␊ |
1041 | ␉␉}␊ |
1042 | ␉␉else if (!is_sandybridge() && !is_jaketown())␊ |
1043 | ␉␉{␊ |
1044 | ␉␉␉if (turbo_enabled && cpu->turbo_available)␊ |
1045 | ␉␉␉{␊ |
1046 | ␉␉␉␉temp64 = rdmsr64(MSR_TURBO_POWER_CURRENT_LIMIT);␊ |
1047 | ␉␉␉␉temp32 = (U32)temp64;␊ |
1048 | ␉␉␉} ␊ |
1049 | ␉␉␉else ␊ |
1050 | ␉␉␉{␊ |
1051 | ␉␉␉␉// Unfortunately, Intel don't provide a better method for non turbo processors␊ |
1052 | ␉␉␉␉// and it will give a TDP of 95w (for ex. mine is 65w) , to fix this issue,␊ |
1053 | ␉␉␉␉// you can set this value by simply adding the option TDP = XX (XX is an integer)␊ |
1054 | ␉␉␉␉// in your boot.plist ␊ |
1055 | ␉␉␉␉temp32 = (U32)0x02a802f8;␊ |
1056 | ␉␉␉}␊ |
1057 | ␉␉␉␊ |
1058 | ␉␉}␊ |
1059 | ␉␉if (temp32) {␊ |
1060 | ␉␉␉cpu->tdp_limit = ( temp32 & 0x7fff );␊ |
1061 | ␉␉␉cpu->tdc_limit = ( (temp32 >> 16) & 0x7fff );␊ |
1062 | ␉␉}␊ |
1063 | ␉} ␊ |
1064 | ␊ |
1065 | #endif␊ |
1066 | ␊ |
1067 | ␉switch (Platform.CPU.Family)␊ |
1068 | ␉{␊ |
1069 | ␉␉case 0x06: ␊ |
1070 | ␉␉{␊ |
1071 | ␉␉␉switch (Platform.CPU.Model) ␊ |
1072 | ␉␉␉{␊ |
1073 | ␉␉␉␉case CPU_MODEL_DOTHAN: ␊ |
1074 | ␉␉␉␉case CPU_MODEL_YONAH: // Yonah␊ |
1075 | ␉␉␉␉case CPU_MODEL_MEROM: // Merom␊ |
1076 | ␉␉␉␉case CPU_MODEL_PENRYN: // Penryn␊ |
1077 | ␉␉␉␉case CPU_MODEL_ATOM: // Intel Atom (45nm)␊ |
1078 | ␉␉␉␉{␊ |
1079 | ␉␉␉␉␉␊ |
1080 | ␉␉␉␉␉cpu->core_c1_supported = ((sub_Cstates >> 4) & 0xf) ? 1 : 0;␊ |
1081 | ␉␉␉␉␉cpu->core_c4_supported = ((sub_Cstates >> 16) & 0xf) ? 1 : 0;␊ |
1082 | ␉␉␉␉␉␊ |
1083 | ␉␉␉␉␉if (Platform.CPU.Model == CPU_MODEL_ATOM)␊ |
1084 | ␉␉␉␉␉{␊ |
1085 | ␉␉␉␉␉␉cpu->core_c2_supported = cpu->core_c3_supported = ((sub_Cstates >> 8) & 0xf) ? 1 : 0;␊ |
1086 | ␉␉␉␉␉␉cpu->core_c6_supported = ((sub_Cstates >> 12) & 0xf) ? 1 : 0;␊ |
1087 | ␊ |
1088 | ␉␉␉␉␉} ␊ |
1089 | ␉␉␉␉␉else␊ |
1090 | ␉␉␉␉␉{␊ |
1091 | ␉␉␉␉␉␉cpu->core_c3_supported = ((sub_Cstates >> 12) & 0xf) ? 1 : 0;␊ |
1092 | ␉␉␉␉␉␉cpu->core_c2_supported = ((sub_Cstates >> 8) & 0xf) ? 1 : 0;␊ |
1093 | ␉␉␉␉␉␉cpu->core_c6_supported = 0;␊ |
1094 | ␊ |
1095 | ␉␉␉␉␉}␊ |
1096 | ␊ |
1097 | ␉␉␉␉␉cpu->core_c7_supported = 0;␊ |
1098 | ␊ |
1099 | #if BETA␊ |
1100 | ␉␉␉␉␉GetMaxRatio(&cpu->max_ratio_as_mfg);␊ |
1101 | ␉␉␉␉␉U64 msr = rdmsr64(MSR_IA32_PERF_STATUS);␊ |
1102 | ␉␉␉␉␉U16 idlo = (msr >> 48) & 0xffff;␊ |
1103 | ␉␉␉␉␉U16 idhi = (msr >> 32) & 0xffff;␊ |
1104 | ␉␉␉␉␉cpu->min_ratio = (U32) (idlo >> 8) & 0xff;␊ |
1105 | ␉␉␉␉␉cpu->max_ratio_as_cfg = (U32) (idhi >> 8) & 0xff;␊ |
1106 | ␉␉␉␉␉␊ |
1107 | #else␊ |
1108 | ␉␉␉␉␉if (Platform.CPU.MaxCoef) ␊ |
1109 | ␉␉␉␉␉{␊ |
1110 | ␉␉␉␉␉␉if (Platform.CPU.MaxDiv) ␊ |
1111 | ␉␉␉␉␉␉{␊ |
1112 | ␉␉␉␉␉␉␉cpu->max_ratio_as_cfg = cpu->max_ratio_as_mfg = (U32) (Platform.CPU.MaxCoef * 10) + 5;␊ |
1113 | ␉␉␉␉␉␉}␊ |
1114 | ␉␉␉␉␉␉else ␊ |
1115 | ␉␉␉␉␉␉{␊ |
1116 | ␉␉␉␉␉␉␉cpu->max_ratio_as_cfg = cpu->max_ratio_as_mfg = (U32) Platform.CPU.MaxCoef * 10;␊ |
1117 | ␉␉␉␉␉␉}␊ |
1118 | ␉␉␉␉␉}␊ |
1119 | #endif␊ |
1120 | ␉␉␉␉␉␊ |
1121 | ␉␉␉␉␉break;␊ |
1122 | ␉␉␉␉} ␊ |
1123 | ␉␉␉␉case CPU_MODEL_FIELDS:␊ |
1124 | ␉␉␉␉case CPU_MODEL_DALES:␊ |
1125 | ␉␉␉␉case CPU_MODEL_DALES_32NM:␊ |
1126 | ␉␉␉␉case CPU_MODEL_NEHALEM: ␊ |
1127 | ␉␉␉␉case CPU_MODEL_NEHALEM_EX:␊ |
1128 | ␉␉␉␉case CPU_MODEL_WESTMERE:␊ |
1129 | ␉␉␉␉case CPU_MODEL_WESTMERE_EX:␊ |
1130 | ␉␉␉␉case CPU_MODEL_SANDYBRIDGE:␊ |
1131 | ␉␉␉␉case CPU_MODEL_JAKETOWN:␊ |
1132 | ␉␉␉␉{␉␉␊ |
1133 | ␉␉␉␉␉␊ |
1134 | ␉␉␉␉␉cpu->core_c1_supported = ((sub_Cstates >> 4) & 0xf) ? 1 : 0;␊ |
1135 | ␉␉␉␉␉cpu->core_c3_supported = ((sub_Cstates >> 8) & 0xf) ? 1 : 0;␊ |
1136 | ␉␉␉␉␉cpu->core_c6_supported = ((sub_Cstates >> 12) & 0xf) ? 1 : 0;␊ |
1137 | ␉␉␉␉␉cpu->core_c7_supported = ((sub_Cstates >> 16) & 0xf) ? 1 : 0;␊ |
1138 | ␉␉␉␉␉cpu->core_c2_supported = 0;␊ |
1139 | ␉␉␉␉␉cpu->core_c4_supported = 0;␊ |
1140 | ␉␉␉␉␉␊ |
1141 | ␉␉␉␉␉GetMaxRatio(&cpu->max_ratio_as_mfg);␊ |
1142 | U64 platform_info = rdmsr64(MSR_PLATFORM_INFO); ␊ |
1143 | cpu->max_ratio_as_cfg = (U32) ((U32)platform_info >> 8) & 0xff; ␊ |
1144 | ␉␉␉␉␉cpu->min_ratio = (U32) ((platform_info >> 40) & 0xff);␊ |
1145 | ␉␉␉␉␉␊ |
1146 | cpu->tdc_tdp_limits_for_turbo_flag = (platform_info & (1ULL << 29)) ? 1 : 0;␊ |
1147 | ␉␉␉␉␉cpu->ratio_limits_for_turbo_flag = (platform_info & (1ULL << 28)) ? 1 : 0;␊ |
1148 | ␉␉␉␉␉cpu->xe_available = cpu->tdc_tdp_limits_for_turbo_flag | cpu->ratio_limits_for_turbo_flag;␊ |
1149 | ␉␉␉␉␉␊ |
1150 | ␊ |
1151 | ␊ |
1152 | ␉␉␉␉␉if (is_sandybridge() || is_jaketown())␊ |
1153 | ␉␉␉␉␉{␊ |
1154 | ␉␉␉␉␉␉cpu->package_power_limit = rdmsr64(MSR_PKG_RAPL_POWER_LIMIT);␊ |
1155 | ␉␉␉␉␉␉cpu->package_power_sku_unit = rdmsr64(MSR_RAPL_POWER_UNIT);␊ |
1156 | ␉␉␉␉␉}␊ |
1157 | ␉␉␉␉␉break;␊ |
1158 | ␉␉␉␉}␊ |
1159 | ␉␉␉␉default:␊ |
1160 | ␉␉␉␉␉verbose ("Unsupported CPU\n");␊ |
1161 | ␉␉␉␉␉return /*(0)*/;␊ |
1162 | ␉␉␉␉␉break;␊ |
1163 | ␉␉␉}␊ |
1164 | ␉␉}␊ |
1165 | ␉␉default:␉␉␉␊ |
1166 | ␉␉␉break;␊ |
1167 | ␉}␊ |
1168 | ␊ |
1169 | ␉cpu->mwait_supported = (extensions & (1UL << 0)) ? 1 : 0;␉␊ |
1170 | ␊ |
1171 | cpu->invariant_apic_timer_flag = (U32)invariant_APIC_timer;␊ |
1172 | ␊ |
1173 | #if DEBUG_ACPI␊ |
1174 | ␉printf("CPU INFO : \n");␊ |
1175 | #if BETA ␊ |
1176 | ␉printf("min_ratio : %d\n", cpu->min_ratio);␊ |
1177 | #endif␊ |
1178 | ␉printf("max_ratio_as_cfg : %d\n", cpu->max_ratio_as_cfg);␊ |
1179 | ␉printf("max_ratio_as_mfg : %d\n", cpu->max_ratio_as_mfg);␊ |
1180 | ␊ |
1181 | ␉printf("turbo_available : %d\n",cpu->turbo_available);␊ |
1182 | ␊ |
1183 | ␉printf("core_c1_supported : %d\n",cpu->core_c1_supported);␊ |
1184 | ␉printf("core_c2_supported : %d\n",cpu->core_c1_supported);␊ |
1185 | ␉printf("core_c3_supported : %d\n",cpu->core_c3_supported);␊ |
1186 | ␉printf("core_c6_supported : %d\n",cpu->core_c6_supported);␊ |
1187 | ␉printf("core_c7_supported : %d\n",cpu->core_c7_supported);␊ |
1188 | ␉printf("mwait_supported : %d\n",cpu->mwait_supported);␊ |
1189 | ␊ |
1190 | #if BUILD_ACPI_TSS || pstate_power_support␊ |
1191 | ␉if (is_sandybridge() || is_jaketown())␊ |
1192 | ␉{␊ |
1193 | ␊ |
1194 | ␉␉printf("package_power_limit : %d\n",cpu->package_power_limit);␊ |
1195 | ␉␉printf("package_power_sku_unit : %d\n",cpu->package_power_sku_unit); ␊ |
1196 | ␊ |
1197 | ␉}␊ |
1198 | #endif␊ |
1199 | ␉␊ |
1200 | ␉DBG("invariant_apic_timer_flag : %d\n",cpu->invariant_apic_timer_flag);␊ |
1201 | ␉␊ |
1202 | ␊ |
1203 | #endif␊ |
1204 | }␊ |
1205 | ␊ |
1206 | #if BETA␊ |
1207 | //-----------------------------------------------------------------------------␊ |
1208 | static U32 BuildPstateInfo(CPU_DETAILS * cpu)␊ |
1209 | {␊ |
1210 | ␉// Build P-state table info based on verified options␊ |
1211 | ␊ |
1212 | ␉// Compute the number of p-states based on the ratio range␊ |
1213 | ␉cpu->pkg_pstates.num_pstates = computeNumPstates(cpu->max_ratio_as_cfg, cpu->min_ratio, cpu->turbo_available, MAX_PSTATES);␊ |
1214 | ␉␊ |
1215 | ␉if (!cpu->pkg_pstates.num_pstates)␊ |
1216 | ␉{␊ |
1217 | ␉␉return (0);␊ |
1218 | ␉}␊ |
1219 | ␉␊ |
1220 | ␉// Compute pstate data␊ |
1221 | ␉{␊ |
1222 | ␉␉U32 TDP = compute_tdp(cpu);␊ |
1223 | ␉␉␊ |
1224 | ␉␉U32 index;␊ |
1225 | ␉␉for (index=0; index < cpu->pkg_pstates.num_pstates; index ++)␊ |
1226 | ␉␉{␊ |
1227 | ␉␉␉PSTATE * pstate = &cpu->pkg_pstates.pstate[index];␊ |
1228 | ␉␉␉␊ |
1229 | ␉␉␉// Set ratio␊ |
1230 | ␉␉␉pstate->ratio = computePstateRatio(cpu->max_ratio_as_cfg, cpu->min_ratio, cpu->turbo_available, cpu->pkg_pstates.num_pstates, index);␊ |
1231 | ␉␉␉␊ |
1232 | ␉␉␉// Compute frequency based on ratio␊ |
1233 | ␉␉␉if ((index != 0) || (cpu->turbo_available == 0))␊ |
1234 | ␉␉␉␉pstate->frequency = pstate->ratio * get_bclk();␊ |
1235 | ␉␉␉else␊ |
1236 | ␉␉␉␉pstate->frequency = ((pstate->ratio - 1) * get_bclk()) + 1;␊ |
1237 | ␉␉␉␊ |
1238 | ␉␉␉// Compute power based on ratio and other data␊ |
1239 | ␉␉␉if (pstate->ratio >= cpu->max_ratio_as_mfg)␊ |
1240 | ␉␉␉␉// Use max power in mW␊ |
1241 | ␉␉␉␉pstate->power = TDP * 1000;␊ |
1242 | ␉␉␉else␊ |
1243 | ␉␉␉{␊ |
1244 | ␉␉␉␉pstate->power = compute_pstate_power(cpu, pstate->ratio, TDP);␊ |
1245 | ␉␉␉␉␊ |
1246 | ␉␉␉␉// Convert to mW␊ |
1247 | ␉␉␉␉pstate->power*= 1000;␊ |
1248 | ␉␉␉}␊ |
1249 | ␉␉}␊ |
1250 | ␉}␉␉␊ |
1251 | ␊ |
1252 | ␉return (1);␊ |
1253 | }␊ |
1254 | #else␊ |
1255 | /*␊ |
1256 | //-----------------------------------------------------------------------------␊ |
1257 | static U32 BuildCoreIPstateInfo(CPU_DETAILS * cpu)␊ |
1258 | {␊ |
1259 | // Build P-state table info based on verified options␊ |
1260 | ␊ |
1261 | // Compute the number of p-states based on the ratio range␊ |
1262 | cpu->pkg_pstates.num_pstates = computeNumPstates(cpu->max_ratio_as_cfg, cpu->min_ratio, cpu->turbo_available, MAX_PSTATES);␊ |
1263 | ␊ |
1264 | if (!cpu->pkg_pstates.num_pstates)␊ |
1265 | {␊ |
1266 | return (0);␊ |
1267 | }␊ |
1268 | ␊ |
1269 | // Compute pstate data␊ |
1270 | {␊ |
1271 | #ifdef pstate_power_support␊ |
1272 | U32 TDP = compute_tdp(cpu);␉␉␉␉␉␉␉␉␊ |
1273 | #endif␊ |
1274 | ␊ |
1275 | U32 index;␊ |
1276 | for (index=0; index < cpu->pkg_pstates.num_pstates; index ++)␊ |
1277 | {␊ |
1278 | PSTATE * pstate = &cpu->pkg_pstates.pstate[index];␊ |
1279 | ␊ |
1280 | // Set ratio␊ |
1281 | pstate->ratio = computePstateRatio(cpu->max_ratio_as_cfg, cpu->min_ratio, cpu->turbo_available, cpu->pkg_pstates.num_pstates, index);␊ |
1282 | ␊ |
1283 | // Compute frequency based on ratio␊ |
1284 | if ((index != 0) || (cpu->turbo_available == 0))␊ |
1285 | pstate->frequency = pstate->ratio * get_bclk();␊ |
1286 | else␊ |
1287 | pstate->frequency = ((pstate->ratio - 1) * get_bclk()) + 1;␊ |
1288 | ␊ |
1289 | #ifdef pstate_power_support␊ |
1290 | // Compute power based on ratio and other data␊ |
1291 | if (pstate->ratio >= cpu->max_ratio_as_mfg)␊ |
1292 | // Use max power in mW␊ |
1293 | pstate->power = TDP * 1000;␊ |
1294 | else␊ |
1295 | {␊ |
1296 | pstate->power = compute_pstate_power(cpu, pstate->ratio, TDP);␊ |
1297 | ␊ |
1298 | // Convert to mW␊ |
1299 | pstate->power*= 1000;␊ |
1300 | }␊ |
1301 | #else␊ |
1302 | pstate->power = 0;␊ |
1303 | #endif␉␊ |
1304 | }␊ |
1305 | }␉␉␊ |
1306 | ␊ |
1307 | return (1);␊ |
1308 | }␊ |
1309 | */␊ |
1310 | //-----------------------------------------------------------------------------␊ |
1311 | static U32 BuildPstateInfo(CPU_DETAILS * cpu)␊ |
1312 | {␉␊ |
1313 | ␊ |
1314 | ␉struct p_state p_states[32];␊ |
1315 | ␉U8 p_states_count = 0;␉␊ |
1316 | ␉␊ |
1317 | if (!cpu)␊ |
1318 | {␊ |
1319 | return (0);␊ |
1320 | }␊ |
1321 | ␊ |
1322 | ␉{␊ |
1323 | #if UNUSED␊ |
1324 | ␉␉struct p_state initial;␊ |
1325 | #endif␉␊ |
1326 | ␉␉struct p_state maximum, minimum;␊ |
1327 | ␉␉// Retrieving P-States, ported from code by superhai (c)␊ |
1328 | ␉␉switch (Platform.CPU.Family)␊ |
1329 | ␉␉{␊ |
1330 | ␉␉␉case 0x06: ␊ |
1331 | ␉␉␉{␊ |
1332 | ␉␉␉␉switch (Platform.CPU.Model) ␊ |
1333 | ␉␉␉␉{␊ |
1334 | ␉␉␉␉␉case CPU_MODEL_DOTHAN: ␊ |
1335 | ␉␉␉␉␉case CPU_MODEL_YONAH: // Yonah␊ |
1336 | ␉␉␉␉␉case CPU_MODEL_MEROM: // Merom␊ |
1337 | ␉␉␉␉␉case CPU_MODEL_PENRYN: // Penryn␊ |
1338 | ␉␉␉␉␉case CPU_MODEL_ATOM: // Intel Atom (45nm)␊ |
1339 | ␉␉␉␉␉{␊ |
1340 | ␉␉␉␉␉␉bool cpu_dynamic_fsb = false;␊ |
1341 | ␉␉␉␉␉␉␊ |
1342 | ␉␉␉␉␉␉if (rdmsr64(MSR_IA32_EXT_CONFIG) & (1 << 27)) ␊ |
1343 | ␉␉␉␉␉␉{␊ |
1344 | ␉␉␉␉␉␉␉wrmsr64(MSR_IA32_EXT_CONFIG, (rdmsr64(MSR_IA32_EXT_CONFIG) | (1 << 28))); ␊ |
1345 | ␉␉␉␉␉␉␉delay(1);␊ |
1346 | ␉␉␉␉␉␉␉cpu_dynamic_fsb = rdmsr64(MSR_IA32_EXT_CONFIG) & (1 << 28);␊ |
1347 | ␉␉␉␉␉␉}␊ |
1348 | ␉␉␉␉␉␉␊ |
1349 | ␉␉␉␉␉␉bool cpu_noninteger_bus_ratio = (rdmsr64(MSR_IA32_PERF_STATUS) & (1ULL << 46));␊ |
1350 | #if UNUSED␊ |
1351 | ␉␉␉␉␉␉//initial.Control = rdmsr64(MSR_IA32_PERF_STATUS);␊ |
1352 | #endif␉␉␉␊ |
1353 | ␉␉␉␉␉␉maximum.Control = ((rdmsr64(MSR_IA32_PERF_STATUS) >> 32) & 0x1F3F) | (0x4000 * cpu_noninteger_bus_ratio);␊ |
1354 | ␉␉␉␉␉␉maximum.CID = ((maximum.FID & 0x1F) << 1) | cpu_noninteger_bus_ratio;␊ |
1355 | ␉␉␉␉␉␉␊ |
1356 | ␉␉␉␉␉␉minimum.FID = ((rdmsr64(MSR_IA32_PERF_STATUS) >> 24) & 0x1F) | (0x80 * cpu_dynamic_fsb);␊ |
1357 | ␉␉␉␉␉␉minimum.VID = ((rdmsr64(MSR_IA32_PERF_STATUS) >> 48) & 0x3F);␊ |
1358 | ␉␉␉␉␉␉␊ |
1359 | ␉␉␉␉␉␉if (minimum.FID == 0) ␊ |
1360 | ␉␉␉␉␉␉{␊ |
1361 | ␉␉␉␉␉␉␉U64 msr;␊ |
1362 | ␉␉␉␉␉␉␉U8 i;␊ |
1363 | ␉␉␉␉␉␉␉// Probe for lowest fid␊ |
1364 | ␉␉␉␉␉␉␉for (i = maximum.FID; i >= 0x6; i--) ␊ |
1365 | ␉␉␉␉␉␉␉{␊ |
1366 | ␉␉␉␉␉␉␉␉msr = rdmsr64(MSR_IA32_PERF_CONTROL);␊ |
1367 | ␉␉␉␉␉␉␉␉wrmsr64(MSR_IA32_PERF_CONTROL, (msr & 0xFFFFFFFFFFFF0000ULL) | (i << 8) | minimum.VID);␊ |
1368 | ␉␉␉␉␉␉␉␉intel_waitforsts();␊ |
1369 | ␉␉␉␉␉␉␉␉minimum.FID = (rdmsr64(MSR_IA32_PERF_STATUS) >> 8) & 0x1F; ␊ |
1370 | ␉␉␉␉␉␉␉␉delay(1);␊ |
1371 | ␉␉␉␉␉␉␉}␊ |
1372 | ␉␉␉␉␉␉␉␊ |
1373 | ␉␉␉␉␉␉␉msr = rdmsr64(MSR_IA32_PERF_CONTROL);␊ |
1374 | ␉␉␉␉␉␉␉wrmsr64(MSR_IA32_PERF_CONTROL, (msr & 0xFFFFFFFFFFFF0000ULL) | (maximum.FID << 8) | maximum.VID);␊ |
1375 | ␉␉␉␉␉␉␉intel_waitforsts();␊ |
1376 | ␉␉␉␉␉␉}␊ |
1377 | ␊ |
1378 | ␉␉␉␉␉␉if (minimum.VID == maximum.VID) ␊ |
1379 | ␉␉␉␉␉␉{␉␊ |
1380 | ␉␉␉␉␉␉␉U64 msr;␊ |
1381 | ␉␉␉␉␉␉␉U8 i;␊ |
1382 | ␉␉␉␉␉␉␉// Probe for lowest vid␊ |
1383 | ␉␉␉␉␉␉␉for (i = maximum.VID; i > 0xA; i--) ␊ |
1384 | ␉␉␉␉␉␉␉{␊ |
1385 | ␉␉␉␉␉␉␉␉msr = rdmsr64(MSR_IA32_PERF_CONTROL);␊ |
1386 | ␉␉␉␉␉␉␉␉wrmsr64(MSR_IA32_PERF_CONTROL, (msr & 0xFFFFFFFFFFFF0000ULL) | (minimum.FID << 8) | i);␊ |
1387 | ␉␉␉␉␉␉␉␉intel_waitforsts();␊ |
1388 | ␉␉␉␉␉␉␉␉minimum.VID = rdmsr64(MSR_IA32_PERF_STATUS) & 0x3F; ␊ |
1389 | ␉␉␉␉␉␉␉␉delay(1);␊ |
1390 | ␉␉␉␉␉␉␉}␊ |
1391 | ␉␉␉␉␉␉␉␊ |
1392 | ␉␉␉␉␉␉␉msr = rdmsr64(MSR_IA32_PERF_CONTROL);␊ |
1393 | ␉␉␉␉␉␉␉wrmsr64(MSR_IA32_PERF_CONTROL, (msr & 0xFFFFFFFFFFFF0000ULL) | (maximum.FID << 8) | maximum.VID);␊ |
1394 | ␉␉␉␉␉␉␉intel_waitforsts();␊ |
1395 | ␉␉␉␉␉␉}␊ |
1396 | ␊ |
1397 | ␉␉␉␉␉␉minimum.CID = ((minimum.FID & 0x1F) << 1) >> cpu_dynamic_fsb;␊ |
1398 | ␉␉␉␉␉␉␊ |
1399 | ␉␉␉␉␉␉// Sanity check␊ |
1400 | ␉␉␉␉␉␉if (maximum.CID < minimum.CID) ␊ |
1401 | ␉␉␉␉␉␉{␊ |
1402 | ␉␉␉␉␉␉␉DBG("Insane FID values!");␊ |
1403 | ␉␉␉␉␉␉␉p_states_count = 0;␊ |
1404 | ␉␉␉␉␉␉}␊ |
1405 | ␉␉␉␉␉␉else␊ |
1406 | ␉␉␉␉␉␉{␊ |
1407 | ␉␉␉␉␉␉␉// Finalize P-States␊ |
1408 | ␉␉␉␉␉␉␉// Find how many P-States machine supports␊ |
1409 | ␉␉␉␉␉␉␉p_states_count = maximum.CID - minimum.CID + 1;␊ |
1410 | ␉␉␉␉␉␉␉␊ |
1411 | ␉␉␉␉␉␉␉if (p_states_count > MAX_PSTATES) // was 32␊ |
1412 | ␉␉␉␉␉␉␉␉p_states_count = MAX_PSTATES; // was 32␊ |
1413 | ␉␉␉␉␉␉␉␊ |
1414 | ␉␉␉␉␉␉␉U8 vidstep;␊ |
1415 | ␉␉␉␉␉␉␉U8 i = 0, u, invalid = 0;␊ |
1416 | ␉␉␉␉␉␉␉␊ |
1417 | ␉␉␉␉␉␉␉vidstep = ((maximum.VID << 2) - (minimum.VID << 2)) / (p_states_count - 1);␊ |
1418 | ␉␉␉␉␉␉␉␊ |
1419 | U32 fsb = (U32)divU64byU64(Platform.CPU.FSBFrequency , 1000000 , NULL); ␊ |
1420 | ␊ |
1421 | ␉␉␉␉␉␉␉for (u = 0; u < p_states_count; u++) ␊ |
1422 | ␉␉␉␉␉␉␉{␊ |
1423 | ␉␉␉␉␉␉␉␉i = u - invalid;␊ |
1424 | ␉␉␉␉␉␉␉␉␊ |
1425 | ␉␉␉␉␉␉␉␉p_states[i].CID = maximum.CID - u;␊ |
1426 | ␉␉␉␉␉␉␉␉p_states[i].FID = (p_states[i].CID >> 1);␊ |
1427 | ␉␉␉␉␉␉␉␉␊ |
1428 | ␉␉␉␉␉␉␉␉if (p_states[i].FID < 0x6) ␊ |
1429 | ␉␉␉␉␉␉␉␉{␊ |
1430 | ␉␉␉␉␉␉␉␉␉if (cpu_dynamic_fsb) ␊ |
1431 | ␉␉␉␉␉␉␉␉␉␉p_states[i].FID = (p_states[i].FID << 1) | 0x80;␊ |
1432 | ␉␉␉␉␉␉␉␉} ␊ |
1433 | ␉␉␉␉␉␉␉␉else if (cpu_noninteger_bus_ratio) ␊ |
1434 | ␉␉␉␉␉␉␉␉{␊ |
1435 | ␉␉␉␉␉␉␉␉␉p_states[i].FID = p_states[i].FID | (0x40 * (p_states[i].CID & 0x1));␊ |
1436 | ␉␉␉␉␉␉␉␉}␊ |
1437 | ␉␉␉␉␉␉␉␉␊ |
1438 | ␉␉␉␉␉␉␉␉if (i && p_states[i].FID == p_states[i-1].FID)␊ |
1439 | ␉␉␉␉␉␉␉␉␉invalid++;␊ |
1440 | ␉␉␉␉␉␉␉␉␊ |
1441 | ␉␉␉␉␉␉␉␉p_states[i].VID = ((maximum.VID << 2) - (vidstep * u)) >> 2;␊ |
1442 | ␉␉␉␉␉␉␉␉␊ |
1443 | ␉␉␉␉␉␉␉␉U32 multiplier = p_states[i].FID & 0x1f;␉␉// = 0x08␊ |
1444 | ␉␉␉␉␉␉␉␉bool half = p_states[i].FID & 0x40;␉␉␉␉␉// = 0x01␊ |
1445 | ␉␉␉␉␉␉␉␉bool dfsb = p_states[i].FID & 0x80;␉␉␉␉␉// = 0x00␊ |
1446 | ␉␉␉␉␉␉␉␉//U32 fsb = (U32)get_env(envFSBFreq) / 1000000; // = 400␊ |
1447 | ␉␉␉␉␉␉␉␉U32 halffsb = (fsb + 1) >> 1;␉␉␉␉␉// = 200␊ |
1448 | ␉␉␉␉␉␉␉␉U32 frequency = (multiplier * fsb);␉␉␉// = 3200␊ |
1449 | ␉␉␉␉␉␉␉␉␊ |
1450 | ␉␉␉␉␉␉␉␉p_states[i].Frequency = (frequency + (half * halffsb)) >> dfsb;␉// = 3200 + 200 = 3400␊ |
1451 | ␉␉␉␉␉␉␉}␊ |
1452 | ␉␉␉␉␉␉␉␊ |
1453 | ␉␉␉␉␉␉␉p_states_count -= invalid;␊ |
1454 | ␉␉␉␉␉␉}␊ |
1455 | ␉␉␉␉␉␉break;␊ |
1456 | ␉␉␉␉␉} ␊ |
1457 | ␉␉␉␉␉case CPU_MODEL_FIELDS:␊ |
1458 | ␉␉␉␉␉case CPU_MODEL_DALES:␊ |
1459 | ␉␉␉␉␉case CPU_MODEL_DALES_32NM:␊ |
1460 | ␉␉␉␉␉case CPU_MODEL_NEHALEM: ␊ |
1461 | ␉␉␉␉␉case CPU_MODEL_NEHALEM_EX:␊ |
1462 | ␉␉␉␉␉case CPU_MODEL_WESTMERE:␊ |
1463 | ␉␉␉␉␉case CPU_MODEL_WESTMERE_EX:␊ |
1464 | ␉␉␉␉␉case CPU_MODEL_SANDYBRIDGE:␊ |
1465 | ␉␉␉␉␉case CPU_MODEL_JAKETOWN:␊ |
1466 | ␉␉␉␉␉{␉␉␊ |
1467 | ␉␉␉␉␉␉␊ |
1468 | ␉␉␉␉␉␉maximum.Control = rdmsr64(MSR_IA32_PERF_STATUS) & 0xff; // Seems it always contains maximum multiplier value (with turbo, that's we need)...␊ |
1469 | ␉␉␉␉␉␉minimum.Control = (rdmsr64(MSR_PLATFORM_INFO) >> 40) & 0xff;␊ |
1470 | ␉␉␉␉␉␉␊ |
1471 | ␉␉␉␉␉␉DBG("P-States: min 0x%x, max 0x%x\n", minimum.Control, maximum.Control);␊ |
1472 | ␉␉␉␉␉␉␊ |
1473 | ␉␉␉␉␉␉// Sanity check␊ |
1474 | ␉␉␉␉␉␉if (maximum.Control < minimum.Control) ␊ |
1475 | ␉␉␉␉␉␉{␊ |
1476 | ␉␉␉␉␉␉␉DBG("Insane control values!");␊ |
1477 | ␉␉␉␉␉␉␉p_states_count = 0;␊ |
1478 | ␉␉␉␉␉␉}␊ |
1479 | ␉␉␉␉␉␉else␊ |
1480 | ␉␉␉␉␉␉{␊ |
1481 | ␉␉␉␉␉␉␉U8 i;␊ |
1482 | ␉␉␉␉␉␉␉p_states_count = 0;␊ |
1483 | ␉␉␉␉␉␉␉U32 fsb = (U32)divU64byU64(Platform.CPU.FSBFrequency , 1000000, NULL) ;␊ |
1484 | ␉␉␉␉␉␉␉for (i = maximum.Control; i >= minimum.Control; i--) ␊ |
1485 | ␉␉␉␉␉␉␉{␊ |
1486 | ␉␉␉␉␉␉␉␉p_states[p_states_count].Control = i;␊ |
1487 | ␉␉␉␉␉␉␉␉p_states[p_states_count].CID = p_states[p_states_count].Control << 1;␊ |
1488 | ␉␉␉␉␉␉␉␉p_states[p_states_count].Frequency = (U32)fsb * i;␊ |
1489 | ␉␉␉␉␉␉␉␉p_states_count++;␊ |
1490 | ␉␉␉␉␉␉␉␉if (p_states_count >= MAX_PSTATES) { // was 32␊ |
1491 | ␉␉␉␉␉␉␉␉␉␊ |
1492 | ␉␉␉␉␉␉␉␉␉if (p_states_count > MAX_PSTATES) // was 32␊ |
1493 | ␉␉␉␉␉␉␉␉␉␉p_states_count = MAX_PSTATES; // was 32␊ |
1494 | ␉␉␉␉␉␉␉␉␉␊ |
1495 | ␉␉␉␉␉␉␉␉␉break;␊ |
1496 | ␉␉␉␉␉␉␉␉}␊ |
1497 | ␉␉␉␉␉␉␉}␊ |
1498 | ␉␉␉␉␉␉}␊ |
1499 | ␊ |
1500 | ␉␉␉␉␉␉/*␊ |
1501 | U32 sta = BuildCoreIPstateInfo(cpu);␊ |
1502 | if (sta) ␊ |
1503 | {␊ |
1504 | DBG("_PSS PGK generated successfully\n");␊ |
1505 | return (1);␊ |
1506 | ␊ |
1507 | }␊ |
1508 | else␊ |
1509 | {␊ |
1510 | verbose("CoreI _PSS Generation failed !!\n");␊ |
1511 | return (0);␊ |
1512 | }␊ |
1513 | */␊ |
1514 | ␉␉␉␉␉␉break;␊ |
1515 | ␉␉␉␉␉}␊ |
1516 | ␉␉␉␉␉default:␊ |
1517 | ␉␉␉␉␉␉verbose ("Unsupported CPU: P-States will not be generated !!!\n");␊ |
1518 | ␉␉␉␉␉␉return (0);␊ |
1519 | ␉␉␉␉␉␉break;␊ |
1520 | ␉␉␉␉}␊ |
1521 | ␉␉␉}␊ |
1522 | ␉␉␉default:␉␉␉␉␊ |
1523 | ␉␉␉␉break;␊ |
1524 | ␉␉}␊ |
1525 | ␉}␊ |
1526 | ␉␊ |
1527 | ␉// Generating Pstate PKG␊ |
1528 | ␉if (p_states_count > 0) ␊ |
1529 | ␉{␉␉␉␉␉␉␉␉␉␊ |
1530 | U32 fsb = (U32)Platform.CPU.FSBFrequency;␊ |
1531 | ␉␉U8 minPSratio = divU64byU64(p_states[p_states_count-1].Frequency , divU64byU64(fsb , 10000000 , NULL ) , NULL);␊ |
1532 | ␉␉U8 maxPSratio = divU64byU64(p_states[0].Frequency , divU64byU64(fsb , 10000000 , NULL ) , NULL);␊ |
1533 | ␉␉U8 cpu_ratio = 0;␊ |
1534 | ␉␉␊ |
1535 | ␉␉{␊ |
1536 | ␉␉␉U8 cpu_div = (U8)Platform.CPU.CurrDiv;␊ |
1537 | ␉␉␉U8 cpu_coef = (U8)Platform.CPU.CurrCoef;␊ |
1538 | ␊ |
1539 | ␉␉␉if (cpu_div) ␉␉␉␉␉␉␉␉␊ |
1540 | ␉␉␉␉cpu_ratio = (cpu_coef * 10) + 5;␉␉␉␉␉␉␉␉␊ |
1541 | ␉␉␉else ␉␉␉␉␉␉␉␉␊ |
1542 | ␉␉␉␉cpu_ratio = cpu_coef * 10;␊ |
1543 | ␉␉}␊ |
1544 | ␉␉␊ |
1545 | ␉␉␊ |
1546 | ␉␉{␊ |
1547 | ␉␉␉int user_max_ratio = 0;␊ |
1548 | ␉␉␉getIntForKey(kMaxRatio, &user_max_ratio, &bootInfo->chameleonConfig);␊ |
1549 | ␉␉␉if (user_max_ratio >= minPSratio && maxPSratio >= user_max_ratio)␊ |
1550 | ␉␉␉{␉␉␉␉␉␉␉␉␉␊ |
1551 | ␉␉␉␉␊ |
1552 | ␉␉␉␉U8 maxcurrdiv = 0, maxcurrcoef = (int)divU64byU64(user_max_ratio , 10, NULL);␉␉␉␉␉␉␉␉␉␊ |
1553 | ␉␉␉␉␊ |
1554 | ␉␉␉␉U8 maxdiv = user_max_ratio - (maxcurrcoef * 10);␊ |
1555 | ␉␉␉␉if (maxdiv > 0)␊ |
1556 | ␉␉␉␉␉maxcurrdiv = 1;␊ |
1557 | ␉␉␉␉␊ |
1558 | ␉␉␉␉if (maxcurrdiv) ␉␉␉␉␉␉␉␉␉␊ |
1559 | ␉␉␉␉␉cpu_ratio = (maxcurrcoef * 10) + 5;␉␉␉␉␉␉␉␉␉␊ |
1560 | ␉␉␉␉else ␉␉␉␉␉␉␉␉␉␊ |
1561 | ␉␉␉␉␉cpu_ratio = maxcurrcoef * 10;␉␉␉␉␉␉␉␉␉␉␉␉␉␉␉␉␊ |
1562 | ␉␉␉}␊ |
1563 | ␉␉}␊ |
1564 | ␉␉␊ |
1565 | ␉␉{␊ |
1566 | ␉␉␉int user_min_ratio = 0;␊ |
1567 | ␉␉␉getIntForKey(kMinRatio, &user_min_ratio, &bootInfo->chameleonConfig);␊ |
1568 | ␉␉␉if (user_min_ratio >= minPSratio && cpu_ratio >= user_min_ratio)␊ |
1569 | ␉␉␉{␊ |
1570 | ␉␉␉␉␊ |
1571 | ␉␉␉␉U8 mincurrdiv = 0, mincurrcoef = (int)divU64byU64(user_min_ratio , 10 , NULL);␉␉␉␉␉␉␉␉␉␊ |
1572 | ␉␉␉␉␊ |
1573 | ␉␉␉␉U8 mindiv = user_min_ratio - (mincurrcoef * 10);␊ |
1574 | ␉␉␉␉␊ |
1575 | ␉␉␉␉if (mindiv > 0)␊ |
1576 | ␉␉␉␉␉mincurrdiv = 1;␉␉␉␉␉␉␉␉␉␊ |
1577 | ␉␉␉␉␊ |
1578 | ␉␉␉␉if (mincurrdiv) ␉␉␉␉␉␉␉␉␉␊ |
1579 | ␉␉␉␉␉minPSratio = (mincurrcoef * 10) + 5;␉␉␉␉␉␉␉␉␉␊ |
1580 | ␉␉␉␉else ␉␉␉␉␉␉␉␉␉␊ |
1581 | ␉␉␉␉␉minPSratio = mincurrcoef * 10;␉␉␉␉␉␉␉␉␉␉␉␉␉␉␉␉␉␉␊ |
1582 | ␉␉␉␉␊ |
1583 | ␉␉␉}␊ |
1584 | ␉␉}␊ |
1585 | ␉␉␊ |
1586 | ␉␉␊ |
1587 | ␉␉if (maxPSratio >= cpu_ratio && cpu_ratio >= minPSratio)␉maxPSratio = cpu_ratio;␉␉␉␉␉␉␉␉␉␉␉␉␉␊ |
1588 | ␉␉␊ |
1589 | ␉␉{␊ |
1590 | ␉␉␉int base = 16;␉␉␉␉␉␉␉␉␊ |
1591 | ␉␉␉U8 expert = 0; /* Default: 0 , mean mixed mode ␊ |
1592 | ␉␉␉␉␉␉ * expert mode : 1 , mean add only p-states found in boot.plist␊ |
1593 | ␉␉␉␉␉␉ */␊ |
1594 | ␊ |
1595 | TagPtr PstateTag; ␊ |
1596 | U32 pstate_tag_count = 0;␊ |
1597 | ␊ |
1598 | ␉␉␉{␊ |
1599 | ␊ |
1600 | ␊ |
1601 | if (bootInfo->chameleonConfig.dictionary) ␊ |
1602 | {␊ |
1603 | PstateTag = XMLCastDict(XMLGetProperty(bootInfo->chameleonConfig.dictionary, (const char*)"P-States"));␊ |
1604 | if (PstateTag) pstate_tag_count = XMLTagCount(PstateTag) ;␊ |
1605 | }␊ |
1606 | ␊ |
1607 | if (!pstate_tag_count) ␊ |
1608 | if ((PstateTag = XMLCastDict(XMLGetProperty(bootInfo->chameleonConfig.dictionary, (const char*)"P-States")))) pstate_tag_count = XMLTagCount(PstateTag); ␊ |
1609 | ␊ |
1610 | ␊ |
1611 | ␉␉␉␉if ((pstate_tag_count > 0) && PstateTag)␊ |
1612 | ␉␉␉␉{␊ |
1613 | ␉␉␉␉␉char *tmpstr = XMLCastString(XMLGetProperty(PstateTag, (const char*)"Mode"));␊ |
1614 | ␉␉␉␉␉␊ |
1615 | ␉␉␉␉␉if (strcmp(tmpstr,"Expert") == 0)␊ |
1616 | ␉␉␉␉␉{␊ |
1617 | ␉␉␉␉␉␉p_states_count = pstate_tag_count - 1 ; // - 1 = - ("Mode" tag) ␉␉␉␉␉␉␉␉␉␉␊ |
1618 | ␉␉␉␉␉␉expert = 1;␊ |
1619 | ␉␉␉␉␉}␊ |
1620 | ␉␉␉␉␉␊ |
1621 | ␉␉␉␉␉␊ |
1622 | ␉␉␉␉␉if ((tmpstr = XMLCastString(XMLGetProperty(PstateTag, (const char*)"Base"))))␊ |
1623 | ␉␉␉␉␉{␊ |
1624 | ␉␉␉␉␉␉␊ |
1625 | ␉␉␉␉␉␉if (expert) p_states_count--; // -= ("Base" tag) ␊ |
1626 | ␉␉␉␉␉␉␊ |
1627 | ␉␉␉␉␉␉int mybase = strtol(tmpstr, NULL, 10);␉␊ |
1628 | ␉␉␉␉␉␉␊ |
1629 | ␉␉␉␉␉␉if (mybase == 8 || mybase == 10 || mybase == 16 )␊ |
1630 | ␉␉␉␉␉␉␉base = mybase;␉␉␉␉␉␉␉␉␉␊ |
1631 | ␉␉␉␉␉}␊ |
1632 | ␉␉␉␉}␊ |
1633 | ␉␉␉␉␊ |
1634 | ␉␉␉}␊ |
1635 | ␉␉␉␊ |
1636 | ␉␉␉{␊ |
1637 | ␉␉␉␉U32 dropPSS = 0, Pstatus = 0;␊ |
1638 | ␉␉␉␉char MatchStat[5];␊ |
1639 | #ifdef pstate_power_support␊ |
1640 | ␉␉␉␉U32 TDP = compute_tdp(cpu);␉␉␉␉␉␉␉␉␊ |
1641 | #endif␊ |
1642 | ␉␉␉␉U32 i;␉␊ |
1643 | U32 fsb = (U32)Platform.CPU.FSBFrequency;␊ |
1644 | ␉␉␉␉for (i = 0; i < p_states_count; i++) ␊ |
1645 | ␉␉␉␉{␉␉␉␊ |
1646 | ␉␉␉␉␉char *Lat1 = NULL, *clk = NULL, *Pw = NULL, *Lat2 = NULL, *Ctrl = NULL ;␊ |
1647 | ␉␉␉␉␉␊ |
1648 | ␉␉␉␉␉if ((pstate_tag_count > 0) && PstateTag)␊ |
1649 | ␉␉␉␉␉{␊ |
1650 | ␉␉␉␉␉␉sprintf(MatchStat, "%d",i);␊ |
1651 | ␉␉␉␉␉␉TagPtr match_Status = XMLGetProperty(PstateTag, (const char*)MatchStat); ␉␉␉␉␉␉␉␉ ␊ |
1652 | ␉␉␉␉␉␉␊ |
1653 | ␉␉␉␉␉␉if (match_Status && (XMLTagCount(match_Status) > 0))␊ |
1654 | ␉␉␉␉␉␉{␉␉␉␉␉␉␉␉␉␉␉␉␊ |
1655 | ␉␉␉␉␉␉␉␊ |
1656 | ␉␉␉␉␉␉␉clk = XMLCastString(XMLGetProperty(match_Status, (const char*)"CoreFreq"));␊ |
1657 | ␉␉␉␉␉␉␉Pw = XMLCastString(XMLGetProperty(match_Status, (const char*)"Power"));␊ |
1658 | ␉␉␉␉␉␉␉Lat1 = XMLCastString(XMLGetProperty(match_Status, (const char*)"Transition Latency"));␊ |
1659 | ␉␉␉␉␉␉␉Lat2 = XMLCastString(XMLGetProperty(match_Status, (const char*)"Bus Master Latency"));␊ |
1660 | ␉␉␉␉␉␉␉Ctrl = XMLCastString(XMLGetProperty(match_Status, (const char*)"Control"));␊ |
1661 | ␉␉␉␉␉␉␉␊ |
1662 | ␉␉␉␉␉␉␉␊ |
1663 | ␉␉␉␉␉␉} else if (expert) ␊ |
1664 | ␉␉␉␉␉␉␉continue;␊ |
1665 | ␉␉␉␉␉}␊ |
1666 | ␊ |
1667 | ␉␉␉␉␉unsigned long Frequency = 0x00000000;␊ |
1668 | ␉␉␉␉␉␊ |
1669 | ␉␉␉␉␉if (!expert || !pstate_tag_count) Frequency = p_states[i].Frequency;␊ |
1670 | ␉␉␉␉␉␊ |
1671 | ␉␉␉␉␉if (clk) ␊ |
1672 | ␉␉␉␉␉␉Frequency = strtoul((const char *)clk, NULL,base);␊ |
1673 | ␉␉␉␉␉␊ |
1674 | ␉␉␉␉␉if (!Frequency || Frequency > p_states[0].Frequency ) continue;␊ |
1675 | ␉␉␉␉␉␊ |
1676 | ␉␉␉␉␉U8 curr_ratio = (U8)divU64byU64(Frequency , divU64byU64(fsb , 10000000, NULL ), NULL);␊ |
1677 | ␊ |
1678 | ␊ |
1679 | {␊ |
1680 | ␉␉␉␉␉␉U8 fixed_ratio = (U8)divU64byU64(Frequency , divU64byU64(fsb , 1000000 , NULL ) , NULL) * 10;␊ |
1681 | ␉␉␉␉␉␉U8 diff = curr_ratio - fixed_ratio ;␊ |
1682 | ␉␉␉␉␉␉␊ |
1683 | ␉␉␉␉␉␉if (diff)␊ |
1684 | ␉␉␉␉␉␉{␊ |
1685 | ␉␉␉␉␉␉␉if (diff < 5)␊ |
1686 | ␉␉␉␉␉␉␉{␊ |
1687 | ␉␉␉␉␉␉␉␉curr_ratio = fixed_ratio;␊ |
1688 | ␉␉␉␉␉␉␉} ␊ |
1689 | ␉␉␉␉␉␉␉else␊ |
1690 | ␉␉␉␉␉␉␉{␊ |
1691 | ␉␉␉␉␉␉␉␉curr_ratio = fixed_ratio + 5;␊ |
1692 | ␉␉␉␉␉␉␉}␊ |
1693 | ␉␉␉␉␉␉}␉␉␉␉␉␉␊ |
1694 | ␊ |
1695 | ␉␉␉␉␉}␊ |
1696 | ␉␉␉␉␉␊ |
1697 | ␉␉␉␉␉if (curr_ratio > maxPSratio || minPSratio > curr_ratio)␊ |
1698 | ␉␉␉␉␉␉goto dropPstate;␊ |
1699 | ␊ |
1700 | ␉␉␉␉␉{␊ |
1701 | ␉␉␉␉␉␉PSTATE * pstate = &cpu->pkg_pstates.pstate[Pstatus];␊ |
1702 | ␉␉␉␉␉␉␊ |
1703 | ␉␉␉␉␉␉pstate->ratio = curr_ratio; ␊ |
1704 | ␉␉␉␉␉␉␊ |
1705 | ␉␉␉␉␉␉pstate->frequency = Frequency; // CoreFreq (in MHz).␉␊ |
1706 | ␉␉␉␉␉␉␊ |
1707 | ␉␉␉␉␉␉U32 power = 0x00000000;␊ |
1708 | #ifdef pstate_power_support␊ |
1709 | ␉␉␉␉␉␉// Compute power based on ratio and other data␊ |
1710 | ␉␉␉␉␉␉if (pstate->ratio >= cpu->max_ratio_as_mfg)␊ |
1711 | ␉␉␉␉␉␉␉// Use max power in mW␊ |
1712 | ␉␉␉␉␉␉␉power = TDP * 1000;␊ |
1713 | ␉␉␉␉␉␉else␊ |
1714 | ␉␉␉␉␉␉{␊ |
1715 | ␉␉␉␉␉␉␉power = compute_pstate_power(cpu, pstate->ratio, TDP);␊ |
1716 | ␉␉␉␉␉␉␉␊ |
1717 | ␉␉␉␉␉␉␉// Convert to mW␊ |
1718 | ␉␉␉␉␉␉␉power*= 1000;␊ |
1719 | ␉␉␉␉␉␉}␊ |
1720 | #endif␉␉␉␉␉␉␊ |
1721 | ␉␉␉␉␉␉pstate->power = resolve_pss(power, Pw, base); // Power (in milliWatts)␉␉␉␉␉␉␉␉␉␊ |
1722 | ␉␉␉␉␉␉pstate->translatency = resolve_pss(0x0000000A, Lat1, base); // Transition Latency (in microseconds).␉␉␉␉␉␉␉␉␉␊ |
1723 | ␉␉␉␉␉␉pstate->bmlatency = resolve_pss(0x0000000A, Lat2, base); // Bus Master Latency (in microseconds).␉␉␉␉␉␉␉␉␉␊ |
1724 | ␉␉␉␉␉␉␊ |
1725 | ␉␉␉␉␉␉{␊ |
1726 | ␉␉␉␉␉␉␉U32 Control = 0 /*encode_pstate(curr_ratio)*/ ;␊ |
1727 | ␉␉␉␉␉␉␉if (!expert || !pstate_tag_count) Control = p_states[i].Control;␉␉␉␉␉␉␉␉␉␊ |
1728 | ␉␉␉␉␉␉␉pstate->control = resolve_pss(Control, Ctrl, base); // Control␊ |
1729 | ␉␉␉␉␉␉}␉␉␉␉␉␉␉␉␉␉␉␉␉␉␊ |
1730 | ␉␉␉␉␉␉␊ |
1731 | ␉␉␉␉␉␉pstate->status = Pstatus+1; // Status␊ |
1732 | ␉␉␉␉␉␉␊ |
1733 | ␉␉␉␉␉␉DBG("state :: frequency :%d power: %d translatency: %d bmlatency: %d control: %d status: %d ratio :%d :: registred !! \n",pstate->frequency,pstate->power,␊ |
1734 | pstate->translatency,pstate->bmlatency,pstate->control,pstate->status,pstate->ratio );␊ |
1735 | ␉␉␉␉␉}␊ |
1736 | ␉␉␉␉␉␊ |
1737 | ␉␉␉␉␉␊ |
1738 | ␉␉␉␉␉Pstatus++;␊ |
1739 | ␉␉␉␉␉continue;␉␉␉␉␉␉␉␉␉␉␉␉␉␉␉␊ |
1740 | ␊ |
1741 | ␉␉␉␉dropPstate:␉␉␉␉␉␊ |
1742 | ␉␉␉␉␉DBG("state with cpu frequency :%d and ratio :%d will be dropped\n",p_states[i].Frequency,curr_ratio);␉␉␉␉␉␊ |
1743 | ␉␉␉␉␉dropPSS++;␊ |
1744 | ␉␉␉␉␉␊ |
1745 | ␉␉␉␉␉␊ |
1746 | ␉␉␉␉}␊ |
1747 | ␉␉␉␉␊ |
1748 | ␉␉␉␉if (Pstatus == 0)␊ |
1749 | ␉␉␉␉{␊ |
1750 | ␉␉␉␉␉verbose("No suitable P-states found, P-States will not be generated !!!\n");␊ |
1751 | ␉␉␉␉␉return (0);␊ |
1752 | ␉␉␉␉}␊ |
1753 | ␉␉␉␉cpu->pkg_pstates.num_pstates = Pstatus;␊ |
1754 | ␉␉␉}␊ |
1755 | ␉␉}␉␉␉␊ |
1756 | ␉}␉␊ |
1757 | ␉else ␊ |
1758 | ␉{␊ |
1759 | ␉␉verbose("ACPI CPUs not found: P-States will not be generated !!!\n");␊ |
1760 | ␉␉return (0);␊ |
1761 | ␉}␊ |
1762 | ␉␊ |
1763 | ␉DBG("_PSS PGK generated successfully\n");␊ |
1764 | ␉return (1);␊ |
1765 | }␊ |
1766 | #endif // BETA␊ |
1767 | ␊ |
1768 | //-----------------------------------------------------------------------------␊ |
1769 | static U32 BuildCstateInfo(CPU_DETAILS * cpu, U32 pmbase)␊ |
1770 | {␊ |
1771 | ␉{ ␊ |
1772 | ␊ |
1773 | ␉␉TagPtr CstateTag = NULL;␊ |
1774 | ␉␉U32 entry_count = 0;␊ |
1775 | ␊ |
1776 | if (bootInfo->chameleonConfig.dictionary) ␊ |
1777 | {␊ |
1778 | ␉␉CstateTag = XMLCastDict(XMLGetProperty(bootInfo->chameleonConfig.dictionary, (const char*)"C-States"));␊ |
1779 | } ␊ |
1780 | ␊ |
1781 | ␉␉if (CstateTag)␊ |
1782 | ␉␉{␊ |
1783 | ␉␉␉int base = 16;␉␊ |
1784 | ␉␉␉␊ |
1785 | ␉␉␉entry_count = XMLTagCount(CstateTag);␉␉␉␊ |
1786 | ␉␉␉␊ |
1787 | ␉␉␉if (entry_count > 0)␊ |
1788 | ␉␉␉{␉␊ |
1789 | {␊ |
1790 | char *tmpstr;␊ |
1791 | ␊ |
1792 | if ((tmpstr = XMLCastString(XMLGetProperty(CstateTag, (const char*)"Base"))))␊ |
1793 | {␊ |
1794 | ␊ |
1795 | entry_count--; // -= ("Base" tag) ␊ |
1796 | ␊ |
1797 | int mybase = strtol(tmpstr, NULL, 10);␉␊ |
1798 | ␊ |
1799 | if (mybase == 8 || mybase == 10 || mybase == 16 )␊ |
1800 | base = mybase;␉␉␉␉␉␉␉␉␉␊ |
1801 | }␊ |
1802 | }␉␉␉␉␊ |
1803 | ␉␉␉␉␊ |
1804 | ␉␉␉␉cpu->pkg_io_cstates.num_cstates = 0;␊ |
1805 | ␉␉␉␉cpu->pkg_mwait_cstates.num_cstates = 0;␊ |
1806 | ␉␉␉␉U32 num_cstates = 0;␊ |
1807 | ␉␉␉␉␊ |
1808 | ␉␉␉␉{␊ |
1809 | ␉␉␉␉␉U32 i;␊ |
1810 | ␉␉␉␉␉char MatchStat[5];␉␉␉␉␉␊ |
1811 | ␉␉␉␉␉␊ |
1812 | ␉␉␉␉␉for (i = 0; i < 32 ; i++)␊ |
1813 | ␉␉␉␉␉{␊ |
1814 | ␉␉␉␉␉␉char *Lat = NULL, *Pw = NULL, *BWidth= NULL, *BOffset= NULL, *Address= NULL, *AccessSize= NULL, *index= NULL;␊ |
1815 | ␉␉␉␉␉␉␊ |
1816 | ␉␉␉␉␉␉sprintf(MatchStat, "C%d",i);␊ |
1817 | ␉␉␉␉␉␉TagPtr match_Status = XMLGetProperty(CstateTag, (const char*)MatchStat);␊ |
1818 | ␉␉␉␉␉␉if (match_Status)␊ |
1819 | ␉␉␉␉␉␉{␉␊ |
1820 | ␉␉␉␉␉␉␉Pw = XMLCastString(XMLGetProperty(match_Status, (const char*)"Power"));␊ |
1821 | ␉␉␉␉␉␉␉Lat = XMLCastString(XMLGetProperty(match_Status, (const char*)"Latency"));␊ |
1822 | ␉␉␉␉␉␉␉BWidth= XMLCastString(XMLGetProperty(match_Status, (const char*)"BitWidth"));␊ |
1823 | ␉␉␉␉␉␉␉␊ |
1824 | ␉␉␉␉␉␉␉BOffset = XMLCastString(XMLGetProperty(match_Status, (const char*)"BitOffset"));␊ |
1825 | ␉␉␉␉␉␉␉Address = XMLCastString(XMLGetProperty(match_Status, (const char*)"Latency"));␊ |
1826 | ␉␉␉␉␉␉␉AccessSize = XMLCastString(XMLGetProperty(match_Status, (const char*)"AccessSize"));␊ |
1827 | ␉␉␉␉␉␉␉index = XMLCastString(XMLGetProperty(match_Status, (const char*)"index"));␊ |
1828 | ␉␉␉␉␉␉␉␊ |
1829 | ␉␉␉␉␉␉␉if (Pw && Lat && BWidth && BOffset && Address && AccessSize && index)␊ |
1830 | ␉␉␉␉␉␉␉{␊ |
1831 | ␉␉␉␉␉␉␉␉U32 bw␉␉= strtoul((const char *)BWidth, NULL,base);␊ |
1832 | ␉␉␉␉␉␉␉␉U32 boff␉= strtoul((const char *)BOffset, NULL,base);␊ |
1833 | ␉␉␉␉␉␉␉␉U32 acs␉␉= strtoul((const char *)AccessSize, NULL,base);␊ |
1834 | ␉␉␉␉␉␉␉␉U32 addr␉= strtoul((const char *)Address, NULL,base);␊ |
1835 | ␉␉␉␉␉␉␉␉U32 idx␉␉= strtoul((const char *)index, NULL,base);␊ |
1836 | ␉␉␉␉␉␉␉␉U32 lat␉␉= strtoul((const char *)Lat, NULL,base);␊ |
1837 | ␉␉␉␉␉␉␉␉U32 pw␉␉= strtoul((const char *)Pw, NULL,base);␊ |
1838 | ␉␉␉␉␉␉␉␉␊ |
1839 | ␉␉␉␉␉␉␉␉ACPI_GENERIC_ADDRESS mwait_gas = {GAS_TYPE_FFH,bw,boff,acs,addr}; ␊ |
1840 | ␉␉␉␉␉␉␉␉ACPI_GENERIC_ADDRESS io_gas = {(i == 1) ? GAS_TYPE_FFH : GAS_TYPE_SYSTEM_IO,bw,boff,acs,addr}; ␊ |
1841 | ␉␉␉␉␉␉␉␉␊ |
1842 | ␉␉␉␉␉␉␉␉CSTATE mwait_cstate = {idx,lat,pw};␊ |
1843 | ␉␉␉␉␉␉␉␉CSTATE io_cstate = {idx,lat,pw};␊ |
1844 | ␉␉␉␉␉␉␉␉␊ |
1845 | ␉␉␉␉␉␉␉␉{␊ |
1846 | ␉␉␉␉␉␉␉␉␉cpu->pkg_mwait_cstates.cstate[cpu->pkg_mwait_cstates.num_cstates] = mwait_cstate;␊ |
1847 | ␉␉␉␉␉␉␉␉␉cpu->pkg_mwait_cstates.gas[cpu->pkg_mwait_cstates.num_cstates] = mwait_gas;␊ |
1848 | ␉␉␉␉␉␉␉␉␉cpu->pkg_mwait_cstates.num_cstates++;␊ |
1849 | ␉␉␉␉␉␉␉␉}␊ |
1850 | ␉␉␉␉␉␉␉␉␊ |
1851 | ␉␉␉␉␉␉␉␉{␊ |
1852 | ␉␉␉␉␉␉␉␉␉cpu->pkg_io_cstates.cstate[cpu->pkg_io_cstates.num_cstates] = io_cstate;␊ |
1853 | ␉␉␉␉␉␉␉␉␉cpu->pkg_io_cstates.gas[cpu->pkg_io_cstates.num_cstates] = io_gas;␊ |
1854 | ␉␉␉␉␉␉␉␉␉cpu->pkg_io_cstates.num_cstates++;␊ |
1855 | ␉␉␉␉␉␉␉␉}␊ |
1856 | ␉␉␉␉␉␉␉␉num_cstates++;␉␉␉␉␉␉␉␉␊ |
1857 | ␉␉␉␉␉␉␉␉␊ |
1858 | ␉␉␉␉␉␉␉␉if (num_cstates >= MAX_CSTATES)␊ |
1859 | ␉␉␉␉␉␉␉␉{␊ |
1860 | ␉␉␉␉␉␉␉␉␉break;␊ |
1861 | ␉␉␉␉␉␉␉␉}␊ |
1862 | ␉␉␉␉␉␉␉}␊ |
1863 | ␉␉␉␉␉␉} ␊ |
1864 | ␉␉␉␉␉}␊ |
1865 | ␉␉␉␉}␊ |
1866 | ␉␉␉␉␊ |
1867 | ␉␉␉␉if (num_cstates)␊ |
1868 | ␉␉␉␉{␊ |
1869 | ␉␉␉␉␉return (1);␊ |
1870 | ␉␉␉␉}␉␉␉␉␊ |
1871 | ␉␉␉}␊ |
1872 | ␉␉}␉␊ |
1873 | ␉}␊ |
1874 | ␊ |
1875 | ␉{␊ |
1876 | ␉␉static const ACPI_GENERIC_ADDRESS mwait_gas[] = {␊ |
1877 | ␉␉␉{GAS_TYPE_FFH,1,2,1,0x00}, // processor C1␊ |
1878 | ␉␉␉{GAS_TYPE_FFH,1,2,1,0x10}, // processor C3 as ACPI C2␊ |
1879 | ␉␉␉{GAS_TYPE_FFH,1,2,1,0x10}, // processor C3 as ACPI C3␊ |
1880 | ␉␉␉{GAS_TYPE_FFH,1,2,1,0x10}, // processor C3 as ACPI C4␊ |
1881 | ␉␉␉{GAS_TYPE_FFH,1,2,1,0x20}, // processor C6␊ |
1882 | ␉␉␉{GAS_TYPE_FFH,1,2,1,0x30}, // processor C7␊ |
1883 | ␉␉};␊ |
1884 | ␉␉␊ |
1885 | ␉␉static const ACPI_GENERIC_ADDRESS io_gas[] = {␊ |
1886 | ␉␉␉{GAS_TYPE_FFH, 0,0,0,0x00}, // processor C1␊ |
1887 | ␉␉␉{GAS_TYPE_SYSTEM_IO,8,0,0,0x14}, // processor C3 as ACPI C2 or processor C2␊ |
1888 | ␉␉␉{GAS_TYPE_SYSTEM_IO,8,0,0,0x14}, // processor C3 as ACPI C3␊ |
1889 | ␉␉␉{GAS_TYPE_SYSTEM_IO,8,0,0,0x15}, // processor C4 as ACPI C4␊ |
1890 | ␉␉␉{GAS_TYPE_SYSTEM_IO,8,0,0,0x15}, // processor C6␊ |
1891 | ␉␉␉{GAS_TYPE_SYSTEM_IO,8,0,0,0x16}, // processor C7␊ |
1892 | ␉␉};␊ |
1893 | ␉␉␊ |
1894 | ␉␉static const CSTATE mwait_cstate [] = {␊ |
1895 | ␉␉␉{1,0x01,0x3e8}, // processor C1␊ |
1896 | ␉␉␉{2,0x40,0x1f4}, // processor C3 as ACPI C2 or processor C2␊ |
1897 | ␉␉␉{3,0x40,0x1f4}, // processor C3 as ACPI C3␊ |
1898 | ␉␉␉{4,0x40,0x1f4}, // processor C4 ␊ |
1899 | ␉␉␉{6/*was 3*/,0x60,0x15e}, // processor C6␊ |
1900 | ␉␉␉{7/*was 3*/,0x60,0x0c8}, // processor C7␊ |
1901 | ␉␉};␊ |
1902 | ␉␉␊ |
1903 | ␉␉static const CSTATE io_cstate [] = {␊ |
1904 | ␉␉␉{1,0x01,0x3e8}, // processor C1␊ |
1905 | ␉␉␉{2,0x40,0x1f4}, // processor C3 as ACPI C2 or processor C2␊ |
1906 | ␉␉␉{3,0x40,0x1f4}, // processor C3 as ACPI C3␊ |
1907 | ␉␉␉{4,0x40,0x1f4}, // processor C4 ␊ |
1908 | ␉␉␉{6/*was 3*/,0x60,0x15e}, // processor C6␊ |
1909 | ␉␉␉{7/*was 3*/,0x60,0x0c8}, // processor C7␊ |
1910 | ␉␉};␊ |
1911 | ␉␉␊ |
1912 | ␉␉static const U32 cstate_2_index [] = {0,0,0,1,2,3,4,5};␊ |
1913 | ␉␉␊ |
1914 | ␉␉// Build C-state table info based on verified options␊ |
1915 | ␉␉␊ |
1916 | ␉␉// Desired state for the processor core C3 state included in the _CST as an␊ |
1917 | ␉␉// ACPI C2 state.␊ |
1918 | ␉␉// 1= processor core C3 can be used as an ACPI C2 state␊ |
1919 | ␉␉// 0= processor core C3 cannot be used as an ACPI C2 state␊ |
1920 | ␉␉int c2_enabled = 0;␊ |
1921 | ␉␉␊ |
1922 | ␉␉// Desired state for the processor core C3 state included in the _CST␊ |
1923 | ␉␉// 0= processor core C3 cannot be used as an ACPI C state␊ |
1924 | ␉␉// 2= processor core C3 can be used as an ACPI C2 state␊ |
1925 | ␉␉// 3= processor core C3 can be used as an ACPI C3 state␊ |
1926 | ␉␉// 4= processor core C3 can be used as an ACPI C2 state␊ |
1927 | ␉␉// if Invariant APIC Timer detected, else not used as ACPI C state␊ |
1928 | ␉␉// 5= processor core C3 can be used as an ACPI C2 state␊ |
1929 | ␉␉// if Invariant APIC Timer detected, else APIC C3 state␊ |
1930 | ␉␉// 6= processor core C3 can be used as an ACPI C4 state␊ |
1931 | ␉␉int c3_enabled = 3;␊ |
1932 | ␉␉␊ |
1933 | ␉␉// Desired state for the processor core C3 state included in the _CST as an␊ |
1934 | ␉␉// ACPI C4 state.␊ |
1935 | ␉␉// 1= processor core C3 can be used as an ACPI C4 state␊ |
1936 | ␉␉// 0= processor core C3 cannot be used as an ACPI C4 state␊ |
1937 | ␉␉int c4_enabled = 0;␊ |
1938 | ␉␉␊ |
1939 | ␉␉// Desired state for the processor core C6 state included in the _CST as an␊ |
1940 | ␉␉// ACPI C3 state.␊ |
1941 | ␉␉// 1= processor core C6 can be used as an ACPI C3 state␊ |
1942 | ␉␉// 0= processor core C6 cannot be used as an ACPI C3 state␊ |
1943 | ␉␉int c6_enabled = 0;␊ |
1944 | ␉␉␊ |
1945 | ␉␉// Desired state for the processor core C7 state included in the _CST as an␊ |
1946 | ␉␉// ACPI C3 state.␊ |
1947 | ␉␉// 1= processor core C7 can be used as an ACPI C7 state␊ |
1948 | ␉␉// 0= processor core C7 cannot be used as an ACPI C7 state␊ |
1949 | ␉␉int c7_enabled = 0;␊ |
1950 | ␉␉␊ |
1951 | ␉␉{␉␉␊ |
1952 | ␉␉␉bool tmpval;␊ |
1953 | ␉␉␉␊ |
1954 | ␉␉␉␊ |
1955 | ␉␉␉if (getBoolForKey(kEnableC2State, &tmpval, &bootInfo->chameleonConfig))␊ |
1956 | ␉␉␉{␊ |
1957 | ␉␉␉␉c2_enabled = tmpval;␊ |
1958 | ␉␉␉}␊ |
1959 | ␊ |
1960 | ␉␉␉if (!getIntForKey("C3StateOption", &c3_enabled, &bootInfo->chameleonConfig))␊ |
1961 | ␉␉␉{␊ |
1962 | ␉␉␉␉c3_enabled = (getBoolForKey(kEnableC3State, &tmpval, &bootInfo->chameleonConfig)&&tmpval) ? 3 : 0;␊ |
1963 | ␉␉␉}␉␉␊ |
1964 | ␉␉␉if (c3_enabled == 6)␊ |
1965 | ␉␉␉{␊ |
1966 | ␉␉␉␉c4_enabled = 1;␊ |
1967 | ␉␉␉}␊ |
1968 | ␉␉␉else ␊ |
1969 | ␉␉␉{␊ |
1970 | ␉␉␉␉c4_enabled = (getBoolForKey(kEnableC4State, &tmpval, &bootInfo->chameleonConfig)&&tmpval) ? 1 : 0;␊ |
1971 | ␉␉␉}␊ |
1972 | ␉␉␉c6_enabled = (getBoolForKey(kEnableC6State, &tmpval, &bootInfo->chameleonConfig)&&tmpval) ? 1 : 0;␊ |
1973 | ␉␉␉c7_enabled = (getBoolForKey(kEnableC7State, &tmpval, &bootInfo->chameleonConfig)&&tmpval) ? 1 : 0;␉␉␊ |
1974 | ␉␉}␊ |
1975 | ␉␉␊ |
1976 | ␉␉cpu->pkg_mwait_cstates.num_cstates = 0;␊ |
1977 | ␉␉{␊ |
1978 | ␉␉␉{␊ |
1979 | ␉␉␉␉cpu->pkg_mwait_cstates.cstate[cpu->pkg_mwait_cstates.num_cstates] = mwait_cstate[cstate_2_index[CPU_C1]];␊ |
1980 | ␉␉␉␉cpu->pkg_mwait_cstates.gas[cpu->pkg_mwait_cstates.num_cstates] = mwait_gas[cstate_2_index[CPU_C1]];␊ |
1981 | ␉␉␉␉cpu->pkg_mwait_cstates.num_cstates++;␊ |
1982 | ␉␉␉}␊ |
1983 | ␉␉␉if (((cpu->core_c3_supported || cpu->core_c2_supported) && (c2_enabled)) && ((c3_enabled == 2) ||␊ |
1984 | ((c3_enabled == 4) && cpu->invariant_apic_timer_flag)))␊ |
1985 | ␉␉␉{␊ |
1986 | ␉␉␉␉cpu->pkg_mwait_cstates.cstate[cpu->pkg_mwait_cstates.num_cstates] = mwait_cstate[cstate_2_index[CPU_C3_ACPI_C2]];␊ |
1987 | ␉␉␉␉cpu->pkg_mwait_cstates.gas[cpu->pkg_mwait_cstates.num_cstates] = mwait_gas[cstate_2_index[CPU_C3_ACPI_C2]];␊ |
1988 | ␉␉␉␉cpu->pkg_mwait_cstates.num_cstates++;␊ |
1989 | ␉␉␉}␊ |
1990 | ␉␉␉if (cpu->core_c4_supported && c4_enabled)␊ |
1991 | ␉␉␉{␊ |
1992 | ␉␉␉␉␊ |
1993 | ␉␉␉␉cpu->pkg_mwait_cstates.cstate[cpu->pkg_mwait_cstates.num_cstates] = mwait_cstate[cstate_2_index[CPU_C4]];␊ |
1994 | ␉␉␉␉cpu->pkg_mwait_cstates.gas[cpu->pkg_mwait_cstates.num_cstates] = mwait_gas[cstate_2_index[CPU_C4]];␊ |
1995 | ␉␉␉␉cpu->pkg_mwait_cstates.num_cstates++;␊ |
1996 | ␉␉␉␉␊ |
1997 | ␉␉␉}␊ |
1998 | ␉␉␉else␊ |
1999 | ␉␉␉{␊ |
2000 | ␉␉␉␉␊ |
2001 | ␉␉␉␉if (cpu->core_c3_supported && ((c3_enabled == 3) ||␊ |
2002 | ␉␉␉␉␉␉␉␉␉␉␉ ((c3_enabled == 4) && !cpu->invariant_apic_timer_flag)))␊ |
2003 | ␉␉␉␉{␊ |
2004 | ␉␉␉␉␉cpu->pkg_mwait_cstates.cstate[cpu->pkg_mwait_cstates.num_cstates] = mwait_cstate[cstate_2_index[CPU_C3_ACPI_C3]];␊ |
2005 | ␉␉␉␉␉cpu->pkg_mwait_cstates.gas[cpu->pkg_mwait_cstates.num_cstates] = mwait_gas[cstate_2_index[CPU_C3_ACPI_C3]];␊ |
2006 | ␉␉␉␉␉cpu->pkg_mwait_cstates.num_cstates++;␊ |
2007 | ␉␉␉␉}␊ |
2008 | ␉␉␉}␊ |
2009 | ␉␉␉␊ |
2010 | ␉␉␉␊ |
2011 | ␉␉␉if (cpu->core_c6_supported && c6_enabled)␊ |
2012 | ␉␉␉{␊ |
2013 | ␉␉␉␉cpu->pkg_mwait_cstates.cstate[cpu->pkg_mwait_cstates.num_cstates] = mwait_cstate[cstate_2_index[CPU_C6]];␊ |
2014 | ␉␉␉␉cpu->pkg_mwait_cstates.gas[cpu->pkg_mwait_cstates.num_cstates] = mwait_gas[cstate_2_index[CPU_C6]];␊ |
2015 | ␉␉␉␉cpu->pkg_mwait_cstates.num_cstates++;␊ |
2016 | ␉␉␉}␊ |
2017 | ␉␉␉if (cpu->core_c7_supported && c7_enabled)␊ |
2018 | ␉␉␉{␊ |
2019 | ␉␉␉␉cpu->pkg_mwait_cstates.cstate[cpu->pkg_mwait_cstates.num_cstates] = mwait_cstate[cstate_2_index[CPU_C7]];␊ |
2020 | ␉␉␉␉cpu->pkg_mwait_cstates.gas[cpu->pkg_mwait_cstates.num_cstates] = mwait_gas[cstate_2_index[CPU_C7]];␊ |
2021 | ␉␉␉␉cpu->pkg_mwait_cstates.num_cstates++;␊ |
2022 | ␉␉␉}␊ |
2023 | ␉␉}␊ |
2024 | ␉␉␊ |
2025 | ␉␉cpu->pkg_io_cstates.num_cstates = 0;␊ |
2026 | ␉␉{␊ |
2027 | ␉␉␉{␊ |
2028 | ␉␉␉␉cpu->pkg_io_cstates.cstate[cpu->pkg_io_cstates.num_cstates] = io_cstate[cstate_2_index[CPU_C1]];␊ |
2029 | ␉␉␉␉cpu->pkg_io_cstates.gas[cpu->pkg_io_cstates.num_cstates] = io_gas[cstate_2_index[CPU_C1]];␊ |
2030 | ␉␉␉␉cpu->pkg_io_cstates.num_cstates++;␊ |
2031 | ␉␉␉}␊ |
2032 | ␉␉␉if ((cpu->core_c3_supported || cpu->core_c2_supported) && (c2_enabled || (c3_enabled == 2) ||␊ |
2033 | ((c3_enabled == 4) && cpu->invariant_apic_timer_flag)))␊ |
2034 | ␉␉␉{␊ |
2035 | ␉␉␉␉cpu->pkg_io_cstates.cstate[cpu->pkg_io_cstates.num_cstates] = io_cstate[cstate_2_index[CPU_C3_ACPI_C2]];␊ |
2036 | ␉␉␉␉cpu->pkg_io_cstates.gas[cpu->pkg_io_cstates.num_cstates] = io_gas[cstate_2_index[CPU_C3_ACPI_C2]];␊ |
2037 | ␉␉␉␉cpu->pkg_io_cstates.gas[cpu->pkg_io_cstates.num_cstates].Address += pmbase;␊ |
2038 | ␉␉␉␉cpu->pkg_io_cstates.num_cstates++;␊ |
2039 | ␉␉␉}␊ |
2040 | ␉␉␉if (cpu->core_c4_supported && c4_enabled)␊ |
2041 | ␉␉␉{␊ |
2042 | ␉␉␉␉␊ |
2043 | ␉␉␉␉cpu->pkg_io_cstates.cstate[cpu->pkg_io_cstates.num_cstates] = io_cstate[cstate_2_index[CPU_C4]];␊ |
2044 | ␉␉␉␉cpu->pkg_io_cstates.gas[cpu->pkg_io_cstates.num_cstates] = io_gas[cstate_2_index[CPU_C4]];␊ |
2045 | ␉␉␉␉cpu->pkg_io_cstates.gas[cpu->pkg_io_cstates.num_cstates].Address += pmbase;␊ |
2046 | ␉␉␉␉cpu->pkg_io_cstates.num_cstates++;␉␊ |
2047 | ␉␉␉␉␊ |
2048 | ␉␉␉}␊ |
2049 | ␉␉␉else ␊ |
2050 | ␉␉␉{␊ |
2051 | ␉␉␉␉␊ |
2052 | ␉␉␉␉if (cpu->core_c3_supported && ((c3_enabled == 3) ||␊ |
2053 | ␉␉␉␉␉␉␉␉␉␉␉ ((c3_enabled == 4) && !cpu->invariant_apic_timer_flag)))␊ |
2054 | ␉␉␉␉{␊ |
2055 | ␉␉␉␉␉cpu->pkg_io_cstates.cstate[cpu->pkg_io_cstates.num_cstates] = io_cstate[cstate_2_index[CPU_C3_ACPI_C3]];␊ |
2056 | ␉␉␉␉␉cpu->pkg_io_cstates.gas[cpu->pkg_io_cstates.num_cstates] = io_gas[cstate_2_index[CPU_C3_ACPI_C3]];␊ |
2057 | ␉␉␉␉␉cpu->pkg_io_cstates.gas[cpu->pkg_io_cstates.num_cstates].Address += pmbase;␊ |
2058 | ␉␉␉␉␉cpu->pkg_io_cstates.num_cstates++;␊ |
2059 | ␉␉␉␉}␊ |
2060 | ␉␉␉}␊ |
2061 | ␉␉␉␊ |
2062 | ␉␉␉if (cpu->core_c6_supported && c6_enabled)␊ |
2063 | ␉␉␉{␊ |
2064 | ␉␉␉␉cpu->pkg_io_cstates.cstate[cpu->pkg_io_cstates.num_cstates] = io_cstate[cstate_2_index[CPU_C6]];␊ |
2065 | ␉␉␉␉cpu->pkg_io_cstates.gas[cpu->pkg_io_cstates.num_cstates] = io_gas[cstate_2_index[CPU_C6]];␊ |
2066 | ␉␉␉␉cpu->pkg_io_cstates.gas[cpu->pkg_io_cstates.num_cstates].Address += pmbase;␊ |
2067 | ␉␉␉␉cpu->pkg_io_cstates.num_cstates++;␊ |
2068 | ␉␉␉}␊ |
2069 | ␉␉␉if (cpu->core_c7_supported && c7_enabled)␊ |
2070 | ␉␉␉{␊ |
2071 | ␉␉␉␉cpu->pkg_io_cstates.cstate[cpu->pkg_io_cstates.num_cstates] = io_cstate[cstate_2_index[CPU_C7]];␊ |
2072 | ␉␉␉␉cpu->pkg_io_cstates.gas[cpu->pkg_io_cstates.num_cstates] = io_gas[cstate_2_index[CPU_C7]];␊ |
2073 | ␉␉␉␉cpu->pkg_io_cstates.gas[cpu->pkg_io_cstates.num_cstates].Address += pmbase;␊ |
2074 | ␉␉␉␉cpu->pkg_io_cstates.num_cstates++;␊ |
2075 | ␉␉␉}␊ |
2076 | ␉␉}␊ |
2077 | ␉}␊ |
2078 | ␉␊ |
2079 | ␉return (1);␊ |
2080 | }␊ |
2081 | ␊ |
2082 | #if BUILD_ACPI_TSS␊ |
2083 | //-----------------------------------------------------------------------------␊ |
2084 | static U32 BuildTstateInfo(CPU_DETAILS * cpu)␊ |
2085 | {␊ |
2086 | // Coarse grained clock modulation is available if cpuid.6.eax[5] = 0␊ |
2087 | // Max of 8 T-states using 12.5% increments␊ |
2088 | static const TSTATE tstate_coarse_grain [] = {␊ |
2089 | {100,0,0,0x00,0},␊ |
2090 | { 88,0,0,0x1e,0},␊ |
2091 | { 75,0,0,0x1c,0},␊ |
2092 | { 63,0,0,0x1a,0},␊ |
2093 | { 50,0,0,0x18,0},␊ |
2094 | { 38,0,0,0x16,0},␊ |
2095 | { 25,0,0,0x14,0},␊ |
2096 | { 13,0,0,0x12,0},␊ |
2097 | };␊ |
2098 | ␊ |
2099 | // Fine grained clock modulation is available if cpuid.6.eax[5] = 1␊ |
2100 | // Max of 15 T-states using 6.25% increments␊ |
2101 | static const TSTATE tstate_fine_grain [] = {␊ |
2102 | {100,0,0,0x00,0},␊ |
2103 | { 94,0,0,0x1f,0},␊ |
2104 | { 88,0,0,0x1e,0},␊ |
2105 | { 81,0,0,0x1d,0},␊ |
2106 | { 75,0,0,0x1c,0},␊ |
2107 | { 69,0,0,0x1b,0},␊ |
2108 | { 63,0,0,0x1a,0},␊ |
2109 | { 56,0,0,0x19,0},␊ |
2110 | { 50,0,0,0x18,0},␊ |
2111 | { 44,0,0,0x17,0},␊ |
2112 | { 38,0,0,0x16,0},␊ |
2113 | { 31,0,0,0x15,0},␊ |
2114 | { 25,0,0,0x14,0},␊ |
2115 | { 19,0,0,0x13,0},␊ |
2116 | { 13,0,0,0x12,0},␊ |
2117 | };␊ |
2118 | ␊ |
2119 | // Build T-state table info based on verified options␊ |
2120 | U32 num_cpu;␊ |
2121 | const TSTATE * tstate;␊ |
2122 | U32 num_tstates;␊ |
2123 | ␊ |
2124 | for (num_cpu = 0; num_cpu < cpu_map_count; num_cpu ++)␊ |
2125 | { ␊ |
2126 | // Check if fine or coarse grained clock modulation is available␊ |
2127 | if (get_env(envFineGrainClockMod))␊ |
2128 | {␊ |
2129 | // Fine grain thermal throttling is available␊ |
2130 | num_tstates = 15;␊ |
2131 | tstate = tstate_fine_grain;␊ |
2132 | }␊ |
2133 | else␊ |
2134 | {␊ |
2135 | // Coarse grain thermal throttling is available␊ |
2136 | num_tstates = 8;␊ |
2137 | tstate = tstate_coarse_grain;␊ |
2138 | }␊ |
2139 | ␊ |
2140 | cpu->pkg_tstates.num_tstates = num_tstates;␊ |
2141 | {␊ |
2142 | U32 index;␊ |
2143 | for (index = 0; index < num_tstates; index++)␊ |
2144 | {␊ |
2145 | cpu->pkg_tstates.tstate[index] = tstate[index];␊ |
2146 | cpu->pkg_tstates.tstate[index].power = 1000 * (compute_tdp(cpu) * (num_tstates - index)) / num_tstates;␊ |
2147 | }␊ |
2148 | } ␊ |
2149 | ␊ |
2150 | ␊ |
2151 | }␊ |
2152 | return (1);␊ |
2153 | }␊ |
2154 | #endif // BUILD_ACPI_TSS␊ |
2155 | ␊ |
2156 | //-----------------------------------------------------------------------------␊ |
2157 | U32 ProcessMadt(ACPI_TABLE_MADT * madt, MADT_INFO * madt_info, void * buffer, U32 bufferSize, U32 nb_cpu)␊ |
2158 | {␊ |
2159 | void *current;␊ |
2160 | void *currentOut;␊ |
2161 | void *end;␊ |
2162 | void * endOut;␊ |
2163 | ␊ |
2164 | U32 LOCAL_APIC_NMI_CNT = 0, LOCAL_SAPIC_CNT = 0, INT_SRC_CNT = 0, Length = 0;␊ |
2165 | ␊ |
2166 | // Quick sanity check for a valid MADT␊ |
2167 | if (madt == 0ul || !nb_cpu)␊ |
2168 | return (0);␊ |
2169 | ␊ |
2170 | // Confirm a valid MADT buffer was provided␊ |
2171 | if (!buffer)␊ |
2172 | {␊ |
2173 | printf("Error: Invalid Buffer Address for MADT\n");␊ |
2174 | return(0);␊ |
2175 | }␊ |
2176 | ␊ |
2177 | // Confirm a valid MADT buffer length was provided␊ |
2178 | if (!bufferSize)␊ |
2179 | {␊ |
2180 | printf("Error: Invalid Buffer Length for MADT\n");␊ |
2181 | return(0);␊ |
2182 | } ␊ |
2183 | ␊ |
2184 | madt_info->lapic_count = 0; ␊ |
2185 | ␊ |
2186 | memcpy(buffer, madt, sizeof(ACPI_TABLE_MADT)); ␊ |
2187 | ␊ |
2188 | // Search MADT for Sub-tables with needed data␊ |
2189 | current = madt + 1;␊ |
2190 | currentOut = buffer + sizeof(ACPI_TABLE_MADT) ; ␊ |
2191 | ␊ |
2192 | end = (U8 *) madt + madt->Header.Length;␊ |
2193 | endOut = (U8 *)buffer + bufferSize; ␊ |
2194 | ␊ |
2195 | // Check to confirm no MADT buffer overflow␊ |
2196 | if ( (U8 *)currentOut > (U8 *)endOut )␊ |
2197 | {␊ |
2198 | printf("Error: MADT Buffer Length exceeded available space \n");␊ |
2199 | return(0);␊ |
2200 | }␊ |
2201 | ␊ |
2202 | Length += sizeof(ACPI_TABLE_MADT); ␊ |
2203 | ␊ |
2204 | while (current < end)␊ |
2205 | ␉{␊ |
2206 | ACPI_SUBTABLE_HEADER *subtable = current;␊ |
2207 | ACPI_SUBTABLE_HEADER *subtableOut = currentOut;␊ |
2208 | ␊ |
2209 | ␊ |
2210 | switch (subtable->Type)␊ |
2211 | ␉␉{␊ |
2212 | ␊ |
2213 | ␉␉␉case ACPI_MADT_TYPE_LOCAL_APIC:␊ |
2214 | {␊ |
2215 | ␊ |
2216 | // Process sub-tables with Type as 0: Processor Local APIC␊ |
2217 | ACPI_MADT_LOCAL_APIC *lapic = current;␊ |
2218 | current = lapic + 1; ␊ |
2219 | ␊ |
2220 | if (!(lapic->LapicFlags & ACPI_MADT_ENABLED))␊ |
2221 | continue;␊ |
2222 | ␊ |
2223 | if (madt_info->lapic_count >= nb_cpu)␊ |
2224 | continue;␊ |
2225 | ␊ |
2226 | // copy subtable␊ |
2227 | { ␊ |
2228 | ␊ |
2229 | memcpy(currentOut, lapic, lapic->Header.Length);␊ |
2230 | ␊ |
2231 | currentOut = currentOut + lapic->Header.Length;␊ |
2232 | ␊ |
2233 | // Check to confirm no MADT buffer overflow␊ |
2234 | if ( (U8 *)currentOut > (U8 *)endOut )␊ |
2235 | {␊ |
2236 | printf("Error: MADT Buffer Length exceeded available space \n");␊ |
2237 | return(0);␊ |
2238 | }␊ |
2239 | }␊ |
2240 | ␊ |
2241 | {␊ |
2242 | LAPIC_INFO *lapic_info = &madt_info->lapic[madt_info->lapic_count];␊ |
2243 | ␊ |
2244 | lapic_info->processorId = lapic->ProcessorId;␊ |
2245 | lapic_info->apicId = lapic->Id;␊ |
2246 | lapic_info->madt_type = ACPI_MADT_TYPE_LOCAL_APIC;␊ |
2247 | }␊ |
2248 | ␊ |
2249 | madt_info->lapic_count++;␊ |
2250 | ␊ |
2251 | Length += lapic->Header.Length;␊ |
2252 | ␊ |
2253 | // Sanity check to verify compile time limit for max logical CPU is not exceeded␊ |
2254 | if (madt_info->lapic_count > MAX_LOGICAL_CPU)␊ |
2255 | return (0);␊ |
2256 | ␊ |
2257 | break;␊ |
2258 | }␊ |
2259 | ␊ |
2260 | ␉␉␉case ACPI_MADT_TYPE_X2APIC:␊ |
2261 | {␊ |
2262 | ␊ |
2263 | // Process sub-tables with Type as 9: Processor X2APIC␊ |
2264 | ACPI_MADT_X2APIC *x2apic = current;␊ |
2265 | current = x2apic + 1; ␊ |
2266 | ␊ |
2267 | if (!(x2apic->x2apicFlags & ACPI_MADT_ENABLED))␊ |
2268 | continue;␊ |
2269 | ␊ |
2270 | if (madt_info->lapic_count >= nb_cpu)␊ |
2271 | continue;␊ |
2272 | ␊ |
2273 | // copy subtable␊ |
2274 | { ␊ |
2275 | memcpy(currentOut, x2apic, x2apic->Header.Length);␊ |
2276 | ␊ |
2277 | currentOut = currentOut + x2apic->Header.Length;␊ |
2278 | ␊ |
2279 | // Check to confirm no MADT buffer overflow␊ |
2280 | if ( (U8 *)currentOut > (U8 *)endOut )␊ |
2281 | {␊ |
2282 | printf("Error: MADT Buffer Length exceeded available space \n");␊ |
2283 | return(0);␊ |
2284 | }␊ |
2285 | ␊ |
2286 | }␊ |
2287 | ␊ |
2288 | {␊ |
2289 | LAPIC_INFO *lapic_info = &madt_info->lapic[madt_info->lapic_count];␊ |
2290 | ␊ |
2291 | lapic_info->uid = x2apic->UID;␊ |
2292 | lapic_info->apicId = x2apic->x2apicId;␊ |
2293 | lapic_info->madt_type = ACPI_MADT_TYPE_X2APIC;␊ |
2294 | }␊ |
2295 | ␊ |
2296 | madt_info->lapic_count++;␊ |
2297 | ␊ |
2298 | Length += x2apic->Header.Length;␊ |
2299 | ␊ |
2300 | // Sanity check to verify compile time limit for max logical CPU is not exceeded␊ |
2301 | if (madt_info->lapic_count > MAX_LOGICAL_CPU)␊ |
2302 | return (0);␊ |
2303 | ␊ |
2304 | break;␊ |
2305 | }␊ |
2306 | ␊ |
2307 | case ACPI_MADT_TYPE_LOCAL_APIC_NMI:␊ |
2308 | {␊ |
2309 | // Process sub-tables with Type as 4: Local APIC NMI␊ |
2310 | ACPI_MADT_LOCAL_APIC_NMI *nmi = current;␊ |
2311 | current = nmi + 1; ␊ |
2312 | /*␊ |
2313 | ␉␉␉␉ if (!(nmi->IntiFlags & ACPI_MADT_ENABLED))␊ |
2314 | ␉␉␉␉ continue;␊ |
2315 | ␉␉␉␉ */␊ |
2316 | if (LOCAL_APIC_NMI_CNT >= nb_cpu)␊ |
2317 | continue; ␊ |
2318 | ␊ |
2319 | memcpy(currentOut, nmi, nmi->Header.Length); ␊ |
2320 | ␊ |
2321 | currentOut = currentOut + nmi->Header.Length;␊ |
2322 | ␊ |
2323 | // Check to confirm no MADT buffer overflow␊ |
2324 | if ( (U8 *)currentOut > (U8 *)endOut )␊ |
2325 | {␊ |
2326 | printf("Error: MADT Buffer Length exceeded available space \n");␊ |
2327 | return(0);␊ |
2328 | }␊ |
2329 | ␊ |
2330 | ␊ |
2331 | LOCAL_APIC_NMI_CNT++;␊ |
2332 | ␊ |
2333 | Length += nmi->Header.Length;␊ |
2334 | ␊ |
2335 | // Sanity check to verify compile time limit for max logical CPU is not exceeded␊ |
2336 | if (LOCAL_APIC_NMI_CNT > MAX_LOGICAL_CPU)␊ |
2337 | return (0);␊ |
2338 | ␊ |
2339 | break;␊ |
2340 | }␊ |
2341 | ␊ |
2342 | case ACPI_MADT_TYPE_LOCAL_SAPIC:␊ |
2343 | {␊ |
2344 | // Process sub-tables with Type as 7: Local Sapic␊ |
2345 | ACPI_MADT_LOCAL_SAPIC *sapic = current;␊ |
2346 | current = sapic + 1; ␊ |
2347 | /*␊ |
2348 | ␉␉␉␉ if (!(sapic->LapicFlags & ACPI_MADT_ENABLED))␊ |
2349 | ␉␉␉␉ continue;␊ |
2350 | ␉␉␉␉ */␊ |
2351 | if (LOCAL_SAPIC_CNT >= nb_cpu)␊ |
2352 | continue; ␊ |
2353 | ␊ |
2354 | memcpy(currentOut, sapic, sapic->Header.Length); ␊ |
2355 | ␊ |
2356 | currentOut = currentOut + sapic->Header.Length;␊ |
2357 | ␊ |
2358 | // Check to confirm no MADT buffer overflow␊ |
2359 | if ( (U8 *)currentOut > (U8 *)endOut )␊ |
2360 | {␊ |
2361 | printf("Error: MADT Buffer Length exceeded available space \n");␊ |
2362 | return(0);␊ |
2363 | }␊ |
2364 | ␊ |
2365 | ␊ |
2366 | LOCAL_SAPIC_CNT++;␊ |
2367 | ␊ |
2368 | Length += sapic->Header.Length;␊ |
2369 | ␊ |
2370 | // Sanity check to verify compile time limit for max logical CPU is not exceeded␊ |
2371 | if (LOCAL_SAPIC_CNT > MAX_LOGICAL_CPU)␊ |
2372 | return (0);␊ |
2373 | ␊ |
2374 | break;␊ |
2375 | }␊ |
2376 | ␊ |
2377 | case ACPI_MADT_TYPE_INTERRUPT_SOURCE:␊ |
2378 | {␊ |
2379 | // Process sub-tables with Type as 8: Platform Interrupt Source␊ |
2380 | ACPI_MADT_INTERRUPT_SOURCE *intsrc = current;␊ |
2381 | current = intsrc + 1; ␊ |
2382 | /*␊ |
2383 | ␉␉␉␉ if (!(intsrc->IntiFlags & ACPI_MADT_ENABLED))␊ |
2384 | ␉␉␉␉ continue;␊ |
2385 | ␉␉␉␉ */␊ |
2386 | if (INT_SRC_CNT >= nb_cpu)␊ |
2387 | continue; ␊ |
2388 | ␊ |
2389 | memcpy(currentOut, intsrc, intsrc->Header.Length); ␊ |
2390 | ␊ |
2391 | currentOut = currentOut + intsrc->Header.Length;␊ |
2392 | ␊ |
2393 | // Check to confirm no MADT buffer overflow␊ |
2394 | if ( (U8 *)currentOut > (U8 *)endOut )␊ |
2395 | {␊ |
2396 | printf("Error: MADT Buffer Length exceeded available space \n");␊ |
2397 | return(0);␊ |
2398 | }␊ |
2399 | ␊ |
2400 | ␊ |
2401 | INT_SRC_CNT++;␊ |
2402 | ␊ |
2403 | Length += intsrc->Header.Length;␊ |
2404 | ␊ |
2405 | // Sanity check to verify compile time limit for max logical CPU is not exceeded␊ |
2406 | if (INT_SRC_CNT > MAX_LOGICAL_CPU)␊ |
2407 | return (0);␊ |
2408 | ␊ |
2409 | break;␊ |
2410 | }␊ |
2411 | ␊ |
2412 | ␉␉␉default:␊ |
2413 | {␊ |
2414 | ␊ |
2415 | // Process all other sub-tables␊ |
2416 | current = (U8 *) subtable + subtable->Length;␊ |
2417 | currentOut = (U8 *) subtableOut + subtable->Length;␊ |
2418 | ␊ |
2419 | memcpy(subtableOut, subtable, subtable->Length);␊ |
2420 | ␊ |
2421 | // Check to confirm no MADT buffer overflow␊ |
2422 | if ( (U8 *)currentOut > (U8 *)endOut )␊ |
2423 | {␊ |
2424 | printf("Error: MADT Buffer Length exceeded available space \n");␊ |
2425 | return(0);␊ |
2426 | } ␊ |
2427 | ␊ |
2428 | Length += subtable->Length;␊ |
2429 | ␊ |
2430 | break;␊ |
2431 | }␊ |
2432 | } // switch␊ |
2433 | ␊ |
2434 | } // while ␊ |
2435 | ␊ |
2436 | {␊ |
2437 | ACPI_TABLE_MADT * new_madt = (ACPI_TABLE_MADT * )buffer; ␊ |
2438 | ␊ |
2439 | // Update the Lenght of the new MADT table␊ |
2440 | new_madt->Header.Length = Length; ␊ |
2441 | ␊ |
2442 | // Update the checksum of the new MADT table␊ |
2443 | ␉␉SetChecksum(&new_madt->Header); ␊ |
2444 | }␊ |
2445 | ␊ |
2446 | return (1);␊ |
2447 | }␊ |
2448 | ␊ |
2449 | static U32 buildMADT(U32 * new_table_list, ACPI_TABLE_DSDT *dsdt, MADT_INFO * madt_info)␊ |
2450 | {␊ |
2451 | DBG("Build MADT\n");␊ |
2452 | ␉␊ |
2453 | ␉ACPI_TABLE_MADT * madt_file = (void*)0ul;␊ |
2454 | ␉ACPI_TABLE_MADT * MadtPointer = (void*)0ul;␊ |
2455 | bool oem_apic=false;␊ |
2456 | U8 new_table_index = 0;␊ |
2457 | ␊ |
2458 | // Check that we have a valid cpu_map (if it's not already done, it will try to generate it)␊ |
2459 | if (generate_cpu_map_from_acpi(dsdt) != 0)␊ |
2460 | {␊ |
2461 | return(0);␊ |
2462 | }␊ |
2463 | ␊ |
2464 | {␉␉␊ |
2465 | ␉␉bool tmpval;␉␉␊ |
2466 | ␉␉oem_apic=getBoolForKey(kOEMAPIC, &tmpval, &bootInfo->chameleonConfig)&&tmpval;␉␉␊ |
2467 | ␉}␊ |
2468 | ␊ |
2469 | if (oem_apic == true) ␊ |
2470 | {␊ |
2471 | return(0);␊ |
2472 | }␊ |
2473 | ␊ |
2474 | if ((madt_file = (ACPI_TABLE_MADT *)get_new_table_in_list(new_table_list, NAMESEG("APIC"), &new_table_index)) != (void *)0ul)␊ |
2475 | ␉{␉␉␉␉␊ |
2476 | MadtPointer = (ACPI_TABLE_MADT *)madt_file;␊ |
2477 | ␊ |
2478 | new_table_list[new_table_index] = 0ul; // This way, the non-patched table will not be added in our new rsdt/xsdt table list ␉␉␉␊ |
2479 | ␉} ␊ |
2480 | else␊ |
2481 | {␊ |
2482 | MadtPointer = (acpi_tables.MadtPointer64 != (void*)0ul) ? (ACPI_TABLE_MADT *)acpi_tables.MadtPointer64 : (ACPI_TABLE_MADT *)acpi_tables.MadtPointer;␊ |
2483 | ␊ |
2484 | new_table_index = get_0ul_index_in_list(new_table_list, true);␊ |
2485 | ␊ |
2486 | // Check to confirm space is available␊ |
2487 | if (new_table_index == ACPI_TABLE_LIST_FULL)␊ |
2488 | {␉␉␊ |
2489 | printf("Error: not enought reserved space in the new acpi list for the MADT table,\n ");␊ |
2490 | printf(" please increase the RESERVED_AERA\n");␊ |
2491 | return(0);␊ |
2492 | }␊ |
2493 | } ␊ |
2494 | ␊ |
2495 | // Create buffer for MADT␊ |
2496 | //U8 memory_for_madt[2 * 1024]; // seems to bug with xcode4, need to found out what is going on (not enough memory in the stack ?)␊ |
2497 | U8 *memory_for_madt = (U8*)AllocateKernelMemory(2 * 1024);␊ |
2498 | ␊ |
2499 | // Build the new MADT␊ |
2500 | if ( (ProcessMadt(MadtPointer, madt_info, memory_for_madt, 2 * 1024, cpu_map_count))== 0) ␊ |
2501 | ␉{␊ |
2502 | ␉␉printf("Error: Failed to build MADT table\n");␊ |
2503 | ␉␉return (0);␊ |
2504 | ␉}␊ |
2505 | ␉␊ |
2506 | ␉// insert MADT in the new_table_list␊ |
2507 | ␉{␊ |
2508 | ␉␉// Create pointer to MADT just built in the stack buffer␊ |
2509 | ␉␉ACPI_TABLE_MADT * old_madt = (ACPI_TABLE_MADT *)memory_for_madt;␉␉␊ |
2510 | ␉␉␊ |
2511 | ␉␉// Reserved kernel memory for the madt table␊ |
2512 | ␉␉ACPI_TABLE_MADT *new_madt = (ACPI_TABLE_MADT *)AllocateKernelMemory(old_madt->Header.Length);␊ |
2513 | ␉␉␊ |
2514 | ␉␉if (!new_madt) ␊ |
2515 | ␉␉{␊ |
2516 | ␉␉␉printf("Unable to allocate kernel memory for MADT ");␊ |
2517 | ␉␉␉return (0);␊ |
2518 | ␉␉}␊ |
2519 | ␉␉// Move the old stack buffer to kernel memory␊ |
2520 | ␉␉memcpy(new_madt, old_madt, old_madt->Header.Length);␊ |
2521 | ␉␉␊ |
2522 | ␉␉// Add the new madt into an empty space of the new_table_list␊ |
2523 | ␉␉new_table_list[new_table_index] = (U32)new_madt;␉␉␉␉␊ |
2524 | ␉}␊ |
2525 | ␊ |
2526 | verbose ("MADT table successfully patched\n");␊ |
2527 | ␉return(1);␊ |
2528 | }␊ |
2529 | ␊ |
2530 | static U32 ProcessSsdt(U32 * new_table_list, ACPI_TABLE_DSDT *dsdt, MADT_INFO * madt_info, bool enable_cstates, bool enable_pstates, bool enable_tstates )␊ |
2531 | {␊ |
2532 | ␉DBG("Processing SSDT\n");␉␊ |
2533 | ␊ |
2534 | ␉// Check we are on an intel platform␊ |
2535 | ␉if (Platform.CPU.Vendor != CPUID_VENDOR_INTEL) {␊ |
2536 | ␉␉verbose ("Not an Intel platform: SSDT will not be generated !!!\n");␊ |
2537 | ␉␉return(0);␊ |
2538 | ␉}␊ |
2539 | ␉␊ |
2540 | ␉// Check for the msr feature flag␊ |
2541 | ␉if (!(Platform.CPU.Features & CPU_FEATURE_MSR)) {␊ |
2542 | ␉␉verbose ("Unsupported CPU: SSDT will not be generated !!!\n");␊ |
2543 | ␉␉return(0);␊ |
2544 | ␉}␊ |
2545 | ␉␊ |
2546 | ␉if (dsdt == (void *)0ul) {␊ |
2547 | ␉␉verbose ("DSDT not found: SSDT will not be generated !!!\n");␊ |
2548 | ␉␉return (0);␊ |
2549 | ␉}␊ |
2550 | ␉␊ |
2551 | ␉// Get an empty space in the new_talbe_list (true = allow reserved space)␊ |
2552 | ␉U8 empty = get_0ul_index_in_list(new_table_list, true);␊ |
2553 | ␉␊ |
2554 | ␉// Check to confirm space is available␊ |
2555 | ␉if (empty == ACPI_TABLE_LIST_FULL)␊ |
2556 | ␉{␉␉␊ |
2557 | ␉␉printf("Error: not enought reserved space in the new acpi list for the SSDT table,\n ");␊ |
2558 | ␉␉printf(" please increase the RESERVED_AERA\n");␊ |
2559 | ␉␉return(0);␊ |
2560 | ␉}␊ |
2561 | ␊ |
2562 | ␉// Create buffer for SSDT␊ |
2563 | ␉//U8 memory_for_ssdt[20 * 1024];␉// seems to bug with xcode4, need to found out what is going on (not enough memory in the stack ?)␉␊ |
2564 | ␉U8 *memory_for_ssdt =(U8*)AllocateKernelMemory(20 * 1024);␊ |
2565 | ␉␊ |
2566 | ␉// Build the SSDT␊ |
2567 | ␉if ( (BuildSsdt(madt_info, dsdt, memory_for_ssdt, 20 * 1024 /*sizeof(memory_for_ssdt)*/, enable_cstates, enable_pstates, enable_tstates)) == 0)␊ |
2568 | ␉{␊ |
2569 | ␉␉printf("Error: Failed to build SSDT table\n");␊ |
2570 | ␉␉return (0);␊ |
2571 | ␉}␊ |
2572 | ␉␊ |
2573 | ␉// insert SSDT in the new_table_list␊ |
2574 | ␉{␊ |
2575 | ␉␉// Create pointer to SSDT just built in the stack buffer␊ |
2576 | ␉␉ACPI_TABLE_SSDT * old_ssdt = (ACPI_TABLE_SSDT *)memory_for_ssdt;␉␉␊ |
2577 | ␉␉␊ |
2578 | ␉␉// Reserved kernel memory for the ssdt table␊ |
2579 | ␉␉ACPI_TABLE_SSDT *new_ssdt = (ACPI_TABLE_SSDT *)AllocateKernelMemory(old_ssdt->Header.Length);␊ |
2580 | ␉␉␊ |
2581 | ␉␉if (!new_ssdt) ␊ |
2582 | ␉␉{␊ |
2583 | ␉␉␉printf("Unable to allocate kernel memory for SSDT ");␊ |
2584 | ␉␉␉return (0);␊ |
2585 | ␉␉}␊ |
2586 | ␉␉// Move the old stack buffer to kernel memory␊ |
2587 | ␉␉memcpy(new_ssdt, old_ssdt, old_ssdt->Header.Length);␊ |
2588 | ␉␉␊ |
2589 | ␉␉// Add the new ssdt into an empty space of the new_table_list␊ |
2590 | ␉␉new_table_list[empty] = (U32)new_ssdt;␉␉␉␉␊ |
2591 | ␉}␊ |
2592 | ␉␊ |
2593 | ␉verbose ("SSDT table generated successfully\n");␊ |
2594 | ␉return(1);␊ |
2595 | }␊ |
2596 | ␊ |
2597 | //-----------------------------------------------------------------------------␊ |
2598 | static void * buildCpuScope (void * current, U32 cpu_namespace, PROCESSOR_NUMBER_TO_NAMESEG * aslCpuNamePath)␊ |
2599 | {␊ |
2600 | ␉ACPI_SCOPE * scope = current;␊ |
2601 | ␉current = scope + 1;␊ |
2602 | ␉␊ |
2603 | ␉scope->scopeOpcode = AML_SCOPE_OP;␊ |
2604 | ␉scope->rootChar = AML_ROOT_PREFIX;␊ |
2605 | ␉␊ |
2606 | ␉if (aslCpuNamePath->seg_count == 1)␊ |
2607 | ␉{␊ |
2608 | ␉␉DUAL_NAME_PATH * dualNamePath = current;␊ |
2609 | ␉␉current = dualNamePath + 1;␊ |
2610 | ␉␉dualNamePath->prefix = AML_DUAL_NAME_PREFIX;␊ |
2611 | ␉␉dualNamePath->nameseg[0] = cpu_namespace;␊ |
2612 | ␉␉dualNamePath->nameseg[1] = aslCpuNamePath->nameseg[0];␊ |
2613 | ␉}␊ |
2614 | ␉else␊ |
2615 | ␉{␊ |
2616 | ␉␉MULTI_NAME_PATH * multiNamePath = current;␊ |
2617 | ␉␉current = multiNamePath + 1;␊ |
2618 | ␉␉multiNamePath->prefix = AML_MULTI_NAME_PREFIX;␊ |
2619 | ␉␉// the nameseg count includes the root prefix and all other namesegs␊ |
2620 | ␉␉multiNamePath->segCount = (U8) aslCpuNamePath->seg_count+1;␊ |
2621 | ␉␉multiNamePath->nameseg[0] = cpu_namespace;␊ |
2622 | ␉␉{␊ |
2623 | ␉␉␉U32 i;␊ |
2624 | ␉␉␉for (i=0; i<aslCpuNamePath->seg_count; i++)␊ |
2625 | ␉␉␉␉multiNamePath->nameseg[i+1] = aslCpuNamePath->nameseg[i];␊ |
2626 | ␉␉}␊ |
2627 | ␉}␊ |
2628 | ␉return (current);␊ |
2629 | }␊ |
2630 | //-----------------------------------------------------------------------------␊ |
2631 | static void * buildPDC(void * current)␊ |
2632 | {␊ |
2633 | ␉ACPI_METHOD * pdc = current;␊ |
2634 | ␉current = buildMethod(current, NAMESEG("_PDC"), 1);␊ |
2635 | ␉␊ |
2636 | ␉// CreateDWordField (Arg0, 0x08, CAPA)␊ |
2637 | ␉current = buildOpCode(current, AML_CREATE_DWORD_FIELD_OP);␊ |
2638 | ␉current = buildOpCode(current, AML_ARG0_OP);␊ |
2639 | ␉current = buildByteConst(current, 0x08);␊ |
2640 | ␉current = buildNameSeg(current, NAMESEG("CAPA"));␊ |
2641 | ␉␊ |
2642 | ␉// Store (CAPA, TYPE)␊ |
2643 | ␉current = buildOpCode(current, AML_STORE_OP);␊ |
2644 | ␉current = buildNameSeg(current, NAMESEG("CAPA"));␊ |
2645 | ␉current = buildNameSeg(current, NAMESEG("TYPE"));␊ |
2646 | ␉␊ |
2647 | ␉// CreateDWordField (Arg0, 0x00, REVS)␊ |
2648 | ␉current = buildOpCode(current, AML_CREATE_DWORD_FIELD_OP);␊ |
2649 | ␉current = buildOpCode(current, AML_ARG0_OP);␊ |
2650 | ␉current = buildByteConst(current, 0x00);␊ |
2651 | ␉current = buildNameSeg(current, NAMESEG("REVS"));␊ |
2652 | ␉␊ |
2653 | ␉// CreateDWordField (Arg0, 0x04, SIZE)␊ |
2654 | ␉current = buildOpCode(current, AML_CREATE_DWORD_FIELD_OP);␊ |
2655 | ␉current = buildOpCode(current, AML_ARG0_OP);␊ |
2656 | ␉current = buildByteConst(current, 0x04);␊ |
2657 | ␉current = buildNameSeg(current, NAMESEG("SIZE"));␊ |
2658 | ␉␊ |
2659 | ␉// Store(SizeOf(Arg0), Local0)␊ |
2660 | ␉current = buildOpCode(current, AML_STORE_OP);␊ |
2661 | ␉current = buildOpCode(current, AML_SIZEOF_OP);␊ |
2662 | ␉current = buildOpCode(current, AML_ARG0_OP);␊ |
2663 | ␉current = buildOpCode(current, AML_LOCAL0_OP);␊ |
2664 | ␉␊ |
2665 | ␉// Store(Subtract(Local0, 0x08),Local1)␊ |
2666 | ␉current = buildOpCode(current, AML_STORE_OP);␊ |
2667 | ␉current = buildOpCode(current, AML_SUBTRACT_OP);␊ |
2668 | ␉current = buildOpCode(current, AML_LOCAL0_OP);␊ |
2669 | ␉current = buildByteConst(current, 0x08);␊ |
2670 | ␉current = buildOpCode(current, AML_ZERO_OP);␊ |
2671 | ␉current = buildOpCode(current, AML_LOCAL1_OP);␊ |
2672 | ␉␊ |
2673 | ␉// CreateField (Arg0, 0x40, Multiply (Local1, 0x08), TEMP)␊ |
2674 | ␉current = buildOpCode(current, AML_EXT_OP_PREFIX);␊ |
2675 | ␉current = buildOpCode(current, AML_CREATE_FIELD_OP);␊ |
2676 | ␉current = buildOpCode(current, AML_ARG0_OP);␊ |
2677 | ␉current = buildByteConst(current, 0x40);␊ |
2678 | ␉current = buildOpCode(current, AML_MULTIPLY_OP);␊ |
2679 | ␉current = buildOpCode(current, AML_LOCAL1_OP);␊ |
2680 | ␉current = buildByteConst(current, 0x08);␊ |
2681 | ␉current = buildOpCode(current, AML_ZERO_OP);␊ |
2682 | ␉current = buildNameSeg(current, NAMESEG("TEMP"));␊ |
2683 | ␉␊ |
2684 | ␉// Name (STS0, Buffer (0x04) {0x00, 0x00, 0x00, 0x00})␊ |
2685 | ␉// Create STS0 as named buffer␊ |
2686 | ␉current = buildNamePath(current, NAMESEG("STS0"));␊ |
2687 | ␉{␊ |
2688 | ␉␉ACPI_SMALL_BUFFER * buff = current;␊ |
2689 | ␉␉current = buildSmallBuffer(current);␊ |
2690 | ␉␉␊ |
2691 | ␉␉// count of buffer elements␊ |
2692 | ␉␉current = buildByteConst(current, 4);␊ |
2693 | ␉␉␊ |
2694 | ␉␉current = buildOpCode(current, AML_ZERO_OP);␊ |
2695 | ␉␉current = buildOpCode(current, AML_ZERO_OP);␊ |
2696 | ␉␉current = buildOpCode(current, AML_ZERO_OP);␊ |
2697 | ␉␉current = buildOpCode(current, AML_ZERO_OP);␊ |
2698 | ␉␉{␊ |
2699 | ␉␉␉U32 length = (U8 *)current - (U8 *)buff;␊ |
2700 | ␉␉␉buff->packageLength = (U8)length - 1;␊ |
2701 | ␉␉}␊ |
2702 | ␉}␊ |
2703 | ␉␊ |
2704 | ␉//Concatenate (STS0, TEMP, Local2)␊ |
2705 | ␉current = buildOpCode(current, AML_CONCAT_OP);␊ |
2706 | ␉current = buildNameSeg(current, NAMESEG("STS0"));␊ |
2707 | ␉current = buildNameSeg(current, NAMESEG("TEMP"));␊ |
2708 | ␉current = buildOpCode(current, AML_LOCAL2_OP);␊ |
2709 | ␉␊ |
2710 | ␉//_OSC (Buffer (0x10)␊ |
2711 | ␉// {␊ |
2712 | ␉// /* 0000 */ 0x16, 0xA6, 0x77, 0x40, 0x0C, 0x29, 0xBE, 0x47,␊ |
2713 | ␉// /* 0008 */ 0x9E, 0xBD, 0xD8, 0x70, 0x58, 0x71, 0x39, 0x53␊ |
2714 | ␉// }, REVS, SIZE, Local2)␊ |
2715 | ␉current = buildNameSeg(current, NAMESEG("_OSC"));␊ |
2716 | ␉{␊ |
2717 | ␉␉ACPI_SMALL_BUFFER * buff = current;␊ |
2718 | ␉␉current = buildSmallBuffer(current);␊ |
2719 | ␉␉␊ |
2720 | ␉␉// count of buffer elements␊ |
2721 | ␉␉current = buildByteConst(current, 0x10);␊ |
2722 | ␉␉␊ |
2723 | ␉␉current = buildOpCode(current, 0x16);␊ |
2724 | ␉␉current = buildOpCode(current, 0xa6);␊ |
2725 | ␉␉current = buildOpCode(current, 0x77);␊ |
2726 | ␉␉current = buildOpCode(current, 0x40);␊ |
2727 | ␉␉current = buildOpCode(current, 0x0c);␊ |
2728 | ␉␉current = buildOpCode(current, 0x29);␊ |
2729 | ␉␉current = buildOpCode(current, 0xbe);␊ |
2730 | ␉␉current = buildOpCode(current, 0x47);␊ |
2731 | ␉␉current = buildOpCode(current, 0x9e);␊ |
2732 | ␉␉current = buildOpCode(current, 0xbd);␊ |
2733 | ␉␉current = buildOpCode(current, 0xd8);␊ |
2734 | ␉␉current = buildOpCode(current, 0x70);␊ |
2735 | ␉␉current = buildOpCode(current, 0x58);␊ |
2736 | ␉␉current = buildOpCode(current, 0x71);␊ |
2737 | ␉␉current = buildOpCode(current, 0x39);␊ |
2738 | ␉␉current = buildOpCode(current, 0x53);␊ |
2739 | ␉␉{␊ |
2740 | ␉␉␉U32 length = (U8 *)current - (U8 *)buff;␊ |
2741 | ␉␉␉buff->packageLength = (U8)length - 1;␊ |
2742 | ␉␉}␊ |
2743 | ␉}␊ |
2744 | ␉current = buildNameSeg(current, NAMESEG("REVS"));␊ |
2745 | ␉current = buildNameSeg(current, NAMESEG("SIZE"));␊ |
2746 | ␉current = buildOpCode(current, AML_LOCAL2_OP);␊ |
2747 | ␉␊ |
2748 | ␉// Update package length in PDC object␊ |
2749 | ␉//pdc->packageLength = (U8)((U8 *)current - (U8 *)&pdc->packageLength);␊ |
2750 | ␉setPackageLength(&pdc->pkgLength, (U8 *)current - (U8 *)&pdc->pkgLength);␊ |
2751 | ␉␊ |
2752 | ␉return(current);␊ |
2753 | }␊ |
2754 | ␊ |
2755 | //-----------------------------------------------------------------------------␊ |
2756 | static void * buildOSC(void * current)␊ |
2757 | {␊ |
2758 | ␉//␊ |
2759 | ␉//␊ |
2760 | ␉ACPI_METHOD * osc = current;␊ |
2761 | ␉current = buildMethod(current, NAMESEG("_OSC"), 4);␊ |
2762 | ␉␊ |
2763 | ␉// CreateDWordField (Arg3, 0x04, CAPA)␊ |
2764 | ␉current = buildOpCode(current, AML_CREATE_DWORD_FIELD_OP);␊ |
2765 | ␉current = buildOpCode(current, AML_ARG3_OP);␊ |
2766 | ␉current = buildByteConst(current, 0x04);␊ |
2767 | ␉current = buildNameSeg(current, NAMESEG("CAPA"));␊ |
2768 | ␉␊ |
2769 | ␉// Store (CAPA, TYPE)␊ |
2770 | ␉current = buildOpCode(current, AML_STORE_OP);␊ |
2771 | ␉current = buildNameSeg(current, NAMESEG("CAPA"));␊ |
2772 | ␉current = buildNameSeg(current, NAMESEG("TYPE"));␊ |
2773 | ␉␊ |
2774 | ␉// CreateDWordField (Arg3, 0x00, STS0)␊ |
2775 | ␉current = buildOpCode(current, AML_CREATE_DWORD_FIELD_OP);␊ |
2776 | ␉current = buildOpCode(current, AML_ARG3_OP);␊ |
2777 | ␉current = buildByteConst(current, 0x00);␊ |
2778 | ␉current = buildNameSeg(current, NAMESEG("STS0"));␊ |
2779 | ␉␊ |
2780 | ␉// CreateDWordField (Arg3, 0x04, CAP0)␊ |
2781 | ␉current = buildOpCode(current, AML_CREATE_DWORD_FIELD_OP);␊ |
2782 | ␉current = buildOpCode(current, AML_ARG3_OP);␊ |
2783 | ␉current = buildByteConst(current, 0x04);␊ |
2784 | ␉current = buildNameSeg(current, NAMESEG("CAP0"));␊ |
2785 | ␉␊ |
2786 | ␉// CreateDWordField (Arg0, 0x00, IID0)␊ |
2787 | ␉current = buildOpCode(current, AML_CREATE_DWORD_FIELD_OP);␊ |
2788 | ␉current = buildOpCode(current, AML_ARG0_OP);␊ |
2789 | ␉current = buildByteConst(current, 0x00);␊ |
2790 | ␉current = buildNameSeg(current, NAMESEG("IID0"));␊ |
2791 | ␉␊ |
2792 | ␉// CreateDWordField (Arg0, 0x04, IID1)␊ |
2793 | ␉current = buildOpCode(current, AML_CREATE_DWORD_FIELD_OP);␊ |
2794 | ␉current = buildOpCode(current, AML_ARG0_OP);␊ |
2795 | ␉current = buildByteConst(current, 0x04);␊ |
2796 | ␉current = buildNameSeg(current, NAMESEG("IID1"));␊ |
2797 | ␉␊ |
2798 | ␉// CreateDWordField (Arg0, 0x08, IID2)␊ |
2799 | ␉current = buildOpCode(current, AML_CREATE_DWORD_FIELD_OP);␊ |
2800 | ␉current = buildOpCode(current, AML_ARG0_OP);␊ |
2801 | ␉current = buildByteConst(current, 0x08);␊ |
2802 | ␉current = buildNameSeg(current, NAMESEG("IID2"));␊ |
2803 | ␉␊ |
2804 | ␉// CreateDWordField (Arg0, 0x0C, IID3)␊ |
2805 | ␉current = buildOpCode(current, AML_CREATE_DWORD_FIELD_OP);␊ |
2806 | ␉current = buildOpCode(current, AML_ARG0_OP);␊ |
2807 | ␉current = buildByteConst(current, 0x0C);␊ |
2808 | ␉current = buildNameSeg(current, NAMESEG("IID3"));␊ |
2809 | ␉␊ |
2810 | ␉// Name (UID0, Buffer (0x10)␊ |
2811 | ␉// {␊ |
2812 | ␉// 0x16, 0xA6, 0x77, 0x40, 0x0C, 0x29, 0xBE, 0x47,␊ |
2813 | ␉// 0x9E, 0xBD, 0xD8, 0x70, 0x58, 0x71, 0x39, 0x53␊ |
2814 | ␉// })␊ |
2815 | ␉current = buildNamePath(current, NAMESEG("UID0"));␊ |
2816 | ␉{␊ |
2817 | ␉␉ACPI_SMALL_BUFFER * buff = current;␊ |
2818 | ␉␉current = buildSmallBuffer(current);␊ |
2819 | ␉␉␊ |
2820 | ␉␉// count of buffer elements␊ |
2821 | ␉␉current = buildByteConst(current, 0x10);␊ |
2822 | ␉␉␊ |
2823 | ␉␉current = buildOpCode(current, 0x16);␊ |
2824 | ␉␉current = buildOpCode(current, 0xa6);␊ |
2825 | ␉␉current = buildOpCode(current, 0x77);␊ |
2826 | ␉␉current = buildOpCode(current, 0x40);␊ |
2827 | ␉␉current = buildOpCode(current, 0x0c);␊ |
2828 | ␉␉current = buildOpCode(current, 0x29);␊ |
2829 | ␉␉current = buildOpCode(current, 0xbe);␊ |
2830 | ␉␉current = buildOpCode(current, 0x47);␊ |
2831 | ␉␉current = buildOpCode(current, 0x9e);␊ |
2832 | ␉␉current = buildOpCode(current, 0xbd);␊ |
2833 | ␉␉current = buildOpCode(current, 0xd8);␊ |
2834 | ␉␉current = buildOpCode(current, 0x70);␊ |
2835 | ␉␉current = buildOpCode(current, 0x58);␊ |
2836 | ␉␉current = buildOpCode(current, 0x71);␊ |
2837 | ␉␉current = buildOpCode(current, 0x39);␊ |
2838 | ␉␉current = buildOpCode(current, 0x53);␊ |
2839 | ␉␉␊ |
2840 | ␉␉{␊ |
2841 | ␉␉␉U32 length = (U8 *)current - (U8 *)buff;␊ |
2842 | ␉␉␉buff->packageLength = (U8)length - 1;␊ |
2843 | ␉␉}␊ |
2844 | ␉}␊ |
2845 | ␉␊ |
2846 | ␉// CreateDWordField (UID0, 0x00, EID0)␊ |
2847 | ␉current = buildOpCode(current, AML_CREATE_DWORD_FIELD_OP);␊ |
2848 | ␉current = buildOpCode(current, AML_ARG0_OP);␊ |
2849 | ␉current = buildByteConst(current, 0x00);␊ |
2850 | ␉current = buildNameSeg(current, NAMESEG("EID0"));␊ |
2851 | ␉␊ |
2852 | ␉// CreateDWordField (UID0, 0x04, EID1)␊ |
2853 | ␉current = buildOpCode(current, AML_CREATE_DWORD_FIELD_OP);␊ |
2854 | ␉current = buildOpCode(current, AML_ARG0_OP);␊ |
2855 | ␉current = buildByteConst(current, 0x04);␊ |
2856 | ␉current = buildNameSeg(current, NAMESEG("EID1"));␊ |
2857 | ␉␊ |
2858 | ␉// CreateDWordField (UID0, 0x08, EID2)␊ |
2859 | ␉current = buildOpCode(current, AML_CREATE_DWORD_FIELD_OP);␊ |
2860 | ␉current = buildOpCode(current, AML_ARG0_OP);␊ |
2861 | ␉current = buildByteConst(current, 0x08);␊ |
2862 | ␉current = buildNameSeg(current, NAMESEG("EID2"));␊ |
2863 | ␉␊ |
2864 | ␉// CreateDWordField (UID0, 0x0C, EID3)␊ |
2865 | ␉current = buildOpCode(current, AML_CREATE_DWORD_FIELD_OP);␊ |
2866 | ␉current = buildOpCode(current, AML_ARG0_OP);␊ |
2867 | ␉current = buildByteConst(current, 0x0C);␊ |
2868 | ␉current = buildNameSeg(current, NAMESEG("EID3"));␊ |
2869 | ␉␊ |
2870 | ␉// If (LNot (LAnd (LAnd (LEqual (IID0, EID0), LEqual (IID1, EID1)),␊ |
2871 | ␉// LAnd (LEqual (IID2, EID2), LEqual (IID3, EID3)))))␊ |
2872 | ␉// {␊ |
2873 | ␉// Store (0x06, Index (STS0, 0x00))␊ |
2874 | ␉// Return (Arg3)␊ |
2875 | ␉// }␊ |
2876 | ␉{␊ |
2877 | ␉␉current = buildOpCode(current, AML_IF_OP);␊ |
2878 | ␉␉{␊ |
2879 | ␉␉␉ACPI_PACKAGE_LENGTH * packageLength = current;␊ |
2880 | ␉␉␉current = buildPackageLength(current, 0);␊ |
2881 | ␉␉␉␊ |
2882 | ␉␉␉current = buildOpCode(current, AML_LNOT_OP);␊ |
2883 | ␉␉␉current = buildOpCode(current, AML_LAND_OP);␊ |
2884 | ␉␉␉current = buildOpCode(current, AML_LAND_OP);␊ |
2885 | ␉␉␉current = buildOpCode(current, AML_LEQUAL_OP);␊ |
2886 | ␉␉␉current = buildNameSeg(current, NAMESEG("IID0"));␊ |
2887 | ␉␉␉current = buildNameSeg(current, NAMESEG("EID0"));␊ |
2888 | ␉␉␉␊ |
2889 | ␉␉␉current = buildOpCode(current, AML_LEQUAL_OP);␊ |
2890 | ␉␉␉current = buildNameSeg(current, NAMESEG("IID1"));␊ |
2891 | ␉␉␉current = buildNameSeg(current, NAMESEG("EID1"));␊ |
2892 | ␉␉␉␊ |
2893 | ␉␉␉current = buildOpCode(current, AML_LAND_OP);␊ |
2894 | ␉␉␉current = buildOpCode(current, AML_LEQUAL_OP);␊ |
2895 | ␉␉␉current = buildNameSeg(current, NAMESEG("IID2"));␊ |
2896 | ␉␉␉current = buildNameSeg(current, NAMESEG("EID2"));␊ |
2897 | ␉␉␉␊ |
2898 | ␉␉␉current = buildOpCode(current, AML_LEQUAL_OP);␊ |
2899 | ␉␉␉current = buildNameSeg(current, NAMESEG("IID3"));␊ |
2900 | ␉␉␉current = buildNameSeg(current, NAMESEG("EID3"));␊ |
2901 | ␉␉␉␊ |
2902 | ␉␉␉// Store (0x06, Index (STS0, 0x00))␊ |
2903 | ␉␉␉current = buildOpCode(current, AML_STORE_OP);␊ |
2904 | ␉␉␉current = buildByteConst(current, 0x06);␊ |
2905 | ␉␉␉current = buildOpCode(current, AML_INDEX_OP);␊ |
2906 | ␉␉␉current = buildNameSeg(current, NAMESEG("STS0"));␊ |
2907 | ␉␉␉current = buildByteConst(current, 0x00);␊ |
2908 | ␉␉␉current = buildOpCode(current, AML_ZERO_OP);␊ |
2909 | ␉␉␉␊ |
2910 | ␉␉␉// Return (Arg3)␊ |
2911 | ␉␉␉current = buildReturnOpcode(current, AML_ARG3_OP);␊ |
2912 | ␉␉␉␊ |
2913 | ␉␉␉setPackageLength(packageLength,␊ |
2914 | ␉␉␉␉␉␉␉ (U8 *)current - (U8 *)packageLength);␊ |
2915 | ␉␉}␊ |
2916 | ␉}␊ |
2917 | ␉␊ |
2918 | ␉// If (LNotEqual (Arg1, 0x01))␊ |
2919 | ␉// {␊ |
2920 | ␉// Store (0x0A, Index (STS0, 0x00))␊ |
2921 | ␉// Return (Arg3)␊ |
2922 | ␉// }␊ |
2923 | ␉{␊ |
2924 | ␉␉current = buildOpCode(current, AML_IF_OP);␊ |
2925 | ␉␉{␊ |
2926 | ␉␉␉ACPI_PACKAGE_LENGTH * packageLength = current;␊ |
2927 | ␉␉␉current = buildPackageLength(current, 0);␊ |
2928 | ␉␉␉␊ |
2929 | ␉␉␉// If ("LNotEqual (Arg1, 0x01)")␊ |
2930 | ␉␉␉current = buildOpCode(current, AML_LNOT_OP);␊ |
2931 | ␉␉␉current = buildOpCode(current, AML_LEQUAL_OP);␊ |
2932 | ␉␉␉current = buildOpCode(current, AML_ARG1_OP);␊ |
2933 | ␉␉␉current = buildByteConst(current, 0x01);␊ |
2934 | ␉␉␉␊ |
2935 | ␉␉␉// Store (0x0A, Index (STS0, 0x00))␊ |
2936 | ␉␉␉current = buildOpCode(current, AML_STORE_OP);␊ |
2937 | ␉␉␉current = buildByteConst(current, 0x0A);␊ |
2938 | ␉␉␉current = buildOpCode(current, AML_INDEX_OP);␊ |
2939 | ␉␉␉current = buildNameSeg(current, NAMESEG("STS0"));␊ |
2940 | ␉␉␉current = buildByteConst(current, 0x00);␊ |
2941 | ␉␉␉current = buildOpCode(current, AML_ZERO_OP);␊ |
2942 | ␉␉␉␊ |
2943 | ␉␉␉// Return (Arg3)␊ |
2944 | ␉␉␉current = buildReturnOpcode(current, AML_ARG3_OP);␊ |
2945 | ␉␉␉␊ |
2946 | ␉␉␉setPackageLength(packageLength,␊ |
2947 | ␉␉␉␉␉␉␉ (U8 *)current - (U8 *)packageLength);␊ |
2948 | ␉␉}␊ |
2949 | ␉}␊ |
2950 | ␉␊ |
2951 | ␉// If (And (STS0, 0x01))␊ |
2952 | ␉// {␊ |
2953 | ␉// And (CAP0, 0x0BFF, CAP0)␊ |
2954 | ␉// Return (Arg3)␊ |
2955 | ␉// }␊ |
2956 | ␉{␊ |
2957 | ␉␉current = buildOpCode(current, AML_IF_OP);␊ |
2958 | ␉␉{␊ |
2959 | ␉␉␉ACPI_PACKAGE_LENGTH * packageLength = current;␊ |
2960 | ␉␉␉current = buildPackageLength(current, 0);␊ |
2961 | ␉␉␉␊ |
2962 | ␉␉␉// If ("And (STS0, 0x01)")␊ |
2963 | ␉␉␉current = buildOpCode(current, AML_AND_OP);␊ |
2964 | ␉␉␉current = buildNameSeg(current, NAMESEG("STS0"));␊ |
2965 | ␉␉␉current = buildByteConst(current, 0x01);␊ |
2966 | ␉␉␉current = buildOpCode(current, AML_ZERO_OP);␊ |
2967 | ␉␉␉␊ |
2968 | ␉␉␉// And (CAP0, 0x0BFF, CAP0)␊ |
2969 | ␉␉␉current = buildOpCode(current, AML_AND_OP);␊ |
2970 | ␉␉␉current = buildNameSeg(current, NAMESEG("CAP0"));␊ |
2971 | ␉␉␉current = buildWordConst(current, 0x0BFF);␊ |
2972 | ␉␉␉current = buildNameSeg(current, NAMESEG("CAP0"));␊ |
2973 | ␉␉␉␊ |
2974 | ␉␉␉// Return (Arg3)␊ |
2975 | ␉␉␉current = buildReturnOpcode(current, AML_ARG3_OP);␊ |
2976 | ␉␉␉␊ |
2977 | ␉␉␉setPackageLength(packageLength,␊ |
2978 | ␉␉␉␉␉␉␉ (U8 *)current - (U8 *)packageLength);␊ |
2979 | ␉␉}␊ |
2980 | ␉}␊ |
2981 | ␉␊ |
2982 | ␉// And (CAP0, 0x0BFF, CAP0)␊ |
2983 | ␉current = buildOpCode(current, AML_AND_OP);␊ |
2984 | ␉current = buildNameSeg(current, NAMESEG("CAP0"));␊ |
2985 | ␉current = buildWordConst(current, 0x0BFF);␊ |
2986 | ␉current = buildNameSeg(current, NAMESEG("CAP0"));␊ |
2987 | ␉␊ |
2988 | ␉// Store (CAP0, TYPE)␊ |
2989 | ␉current = buildOpCode(current, AML_STORE_OP);␊ |
2990 | ␉current = buildNameSeg(current, NAMESEG("CAP0"));␊ |
2991 | ␉current = buildNameSeg(current, NAMESEG("TYPE"));␊ |
2992 | ␉␊ |
2993 | ␉// Return (Arg3)␊ |
2994 | ␉current = buildReturnOpcode(current, AML_ARG3_OP);␊ |
2995 | ␉␊ |
2996 | ␉// Set package length for the OSC object␊ |
2997 | ␉setPackageLength(&osc->pkgLength, (U8 *)current - (U8 *)&osc->pkgLength);␊ |
2998 | ␉␊ |
2999 | ␉return(current);␊ |
3000 | }␊ |
3001 | ␊ |
3002 | //-----------------------------------------------------------------------------␊ |
3003 | static void * buildPSS(void * current, PKG_PSTATES * pkg_pstates)␊ |
3004 | {␊ |
3005 | ␉//␊ |
3006 | ␉// IF (PSEN)␊ |
3007 | ␉// {␊ |
3008 | ␉// Return (Package of Pstate Packages)␊ |
3009 | ␉// }␊ |
3010 | ␉// Return(Zero)␊ |
3011 | ␉//␊ |
3012 | ␉ACPI_METHOD * pss = current;␊ |
3013 | ␉current = buildMethod(current, NAMESEG("_PSS"), 0);␊ |
3014 | ␉␊ |
3015 | ␉{␊ |
3016 | ␉␉// "IF" (PSEN) -- IF Opcode␊ |
3017 | ␉␉current = buildOpCode(current, AML_IF_OP);␊ |
3018 | ␉␉{␊ |
3019 | ␉␉␉ACPI_PACKAGE_LENGTH * packageLength = current;␊ |
3020 | ␉␉␉current = buildPackageLength(current, 0);␊ |
3021 | ␉␉␉␊ |
3022 | ␉␉␉// IF "(PSEN)" -- IF Predicate␊ |
3023 | ␉␉␉current = buildNameSeg(current, NAMESEG("PSEN"));␊ |
3024 | ␉␉␉␊ |
3025 | ␉␉␉{␊ |
3026 | ␉␉␉␉ACPI_RETURN_PACKAGE * returnPkg = current;␊ |
3027 | ␉␉␉␉current = buildReturnPackage(current, (U8)pkg_pstates->num_pstates);␊ |
3028 | ␉␉␉␉␊ |
3029 | ␉␉␉␉// (3.3.3) For each P-state␊ |
3030 | ␉␉␉␉{␊ |
3031 | ␉␉␉␉␉U32 pstateIndex = 0;␊ |
3032 | ␉␉␉␉␉for (pstateIndex=0; pstateIndex < pkg_pstates->num_pstates; pstateIndex++)␊ |
3033 | ␉␉␉␉␉{␊ |
3034 | ␉␉␉␉␉␉// (3.3.3.1) Create P-state package␊ |
3035 | ␉␉␉␉␉␉ACPI_PSTATE_PACKAGE * pstate = current;␊ |
3036 | ␉␉␉␉␉␉current = pstate + 1;␊ |
3037 | ␉␉␉␉␉␉␊ |
3038 | ␉␉␉␉␉␉setSmallPackage(&pstate->package, 6);␊ |
3039 | ␉␉␉␉␉␉pstate->package.packageLength = (U8)(sizeof(ACPI_PSTATE_PACKAGE) - 1);␊ |
3040 | ␉␉␉␉␉␉␊ |
3041 | ␉␉␉␉␉␉setDwordConst(&pstate->CoreFreq, pkg_pstates->pstate[pstateIndex].frequency);// CoreFreq (in MHz).␊ |
3042 | ␉␉␉␉␉␉setDwordConst(&pstate->Power, pkg_pstates->pstate[pstateIndex].power);// Power (in milliWatts).␊ |
3043 | ␉␉␉␉␉␉setDwordConst(&pstate->TransLatency, pkg_pstates->pstate[pstateIndex].translatency);// Transition Latency (in microseconds).␊ |
3044 | ␉␉␉␉␉␉setDwordConst(&pstate->BMLatency, pkg_pstates->pstate[pstateIndex].bmlatency);// Bus Master Latency (in microseconds).␊ |
3045 | ␉␉␉␉␉␉setDwordConst(&pstate->Control, pkg_pstates->pstate[pstateIndex].control); // Control.␊ |
3046 | ␉␉␉␉␉␉␊ |
3047 | ␉␉␉␉␉␉setDwordConst(&pstate->Status, encode_pstate(pkg_pstates->pstate[pstateIndex].ratio));// Status.␉␊ |
3048 | ␉␉␉␉␉} // for␊ |
3049 | ␉␉␉␉} // for block␊ |
3050 | ␉␉␉␉␊ |
3051 | ␉␉␉␉// (3.3.4) Update package length in return package␊ |
3052 | ␉␉␉␉setPackageLength(&returnPkg->package.pkgLength, (U8 *)current - (U8 *)&returnPkg->package.pkgLength);␊ |
3053 | ␉␉␉}␊ |
3054 | ␉␉␉␊ |
3055 | ␉␉␉// "IF (PSEN) and its body" -- Set package length␊ |
3056 | ␉␉␉setPackageLength(packageLength,␊ |
3057 | ␉␉␉␉␉␉␉ (U8 *)current - (U8 *)packageLength);␊ |
3058 | ␉␉}␊ |
3059 | ␉␉// "Return (ZERO)"␊ |
3060 | ␉␉current = buildReturnZero(current);␊ |
3061 | ␉}␊ |
3062 | ␉// Set package length for the _PSS object␊ |
3063 | ␉setPackageLength(&pss->pkgLength, (U8 *)current - (U8 *)&pss->pkgLength);␊ |
3064 | ␉␊ |
3065 | ␉return(current);␊ |
3066 | }␊ |
3067 | ␊ |
3068 | //-----------------------------------------------------------------------------␊ |
3069 | static void * buildPSD(void * current, U32 domain, U32 cpusInDomain, U32 pstate_coordination)␊ |
3070 | {␊ |
3071 | ␉// If (And(TYPE, 0x0820))␊ |
3072 | ␉// {␊ |
3073 | ␉// Return (PSD Package)␊ |
3074 | ␉// }␊ |
3075 | ␉// Return(Zero)␊ |
3076 | ␉␊ |
3077 | ␉ACPI_METHOD * psdMethod = current;␊ |
3078 | ␉current = buildMethod(current, NAMESEG("_PSD"), 0);␊ |
3079 | ␉{␊ |
3080 | ␉␉// "IF" (And(TYPE, 0x0820)) -- IF Opcode␊ |
3081 | ␉␉current = buildOpCode(current, AML_IF_OP);␊ |
3082 | ␉␉{␊ |
3083 | ␉␉␉ACPI_PACKAGE_LENGTH * packageLength = current;␊ |
3084 | ␉␉␉current = buildPackageLength(current, 0);␊ |
3085 | ␉␉␉␊ |
3086 | ␉␉␉// IF ("And"(TYPE, 0x820)) -- AND Opcode␊ |
3087 | ␉␉␉current = buildOpCode(current, AML_AND_OP);␊ |
3088 | ␉␉␉␊ |
3089 | ␉␉␉// IF (And("TYPE", 0x820)) -- TYPE Term␊ |
3090 | ␉␉␉current = buildNameSeg(current, NAMESEG("TYPE"));␊ |
3091 | ␉␉␉␊ |
3092 | ␉␉␉// IF (And(TYPE, "0x0820")) -- DWORD Value Term␊ |
3093 | ␉␉␉current = buildDwordConst(current, 0x820);␊ |
3094 | ␉␉␉␊ |
3095 | ␉␉␉// IF ("And(TYPE, 0x200)") -- Target for And term (unused)␊ |
3096 | ␉␉␉current = buildOpCode(current, AML_ZERO_OP);␊ |
3097 | ␉␉␉␊ |
3098 | ␉␉␉// Build return package containing PSD package␊ |
3099 | ␉␉␉{␊ |
3100 | ␉␉␉␉ACPI_RETURN_PACKAGE * returnPkg = current;␊ |
3101 | ␉␉␉␉current = buildReturnPackage(current, 1);␊ |
3102 | ␉␉␉␉␊ |
3103 | ␉␉␉␉{␊ |
3104 | ␉␉␉␉␉// Create PSD package␊ |
3105 | ␉␉␉␉␉ACPI_PSD_PACKAGE * psd = current;␊ |
3106 | ␉␉␉␉␉current = psd + 1;␊ |
3107 | ␉␉␉␉␉␊ |
3108 | ␉␉␉␉␉setSmallPackage(&psd->package, 5);␊ |
3109 | ␉␉␉␉␉psd->package.packageLength = (U8)(sizeof(ACPI_PSD_PACKAGE) - 1);␊ |
3110 | ␉␉␉␉␉␊ |
3111 | ␉␉␉␉␉setByteConst(&psd->NumberOfEntries, 5);␊ |
3112 | ␉␉␉␉␉setByteConst(&psd->Revision, 0);␊ |
3113 | ␉␉␉␉␉setDwordConst(&psd->Domain, domain);␊ |
3114 | ␉␉␉␉␉setDwordConst(&psd->CoordType, pstate_coordination);␊ |
3115 | ␉␉␉␉␉setDwordConst(&psd->NumProcessors, cpusInDomain);␊ |
3116 | ␉␉␉␉␉␊ |
3117 | ␉␉␉␉} // PSD package␊ |
3118 | ␉␉␉␉␊ |
3119 | ␉␉␉␉setPackageLength(&returnPkg->package.pkgLength,␊ |
3120 | ␉␉␉␉␉␉␉␉ (U8 *)current - (U8 *)&returnPkg->package.pkgLength);␊ |
3121 | ␉␉␉}␊ |
3122 | ␉␉␉setPackageLength(packageLength, (U8 *)current - (U8 *)packageLength);␊ |
3123 | ␉␉}␊ |
3124 | ␉␉// "Return (ZERO)"␊ |
3125 | ␉␉current = buildReturnZero(current);␊ |
3126 | ␉}␊ |
3127 | ␉// Update length in _PSD method␊ |
3128 | ␉setPackageLength(&psdMethod->pkgLength, (U8 *)current - (U8 *)&psdMethod->pkgLength);␊ |
3129 | ␉␊ |
3130 | ␉return(current);␊ |
3131 | }␊ |
3132 | ␊ |
3133 | //-----------------------------------------------------------------------------␊ |
3134 | static void * buildPPC(void * current/*, U8 valueToReturn*/)␊ |
3135 | {␊ |
3136 | ␉ACPI_SMALL_METHOD * ppc = current;␊ |
3137 | ␉current = buildSmallMethod(current, NAMESEG("_PPC"), 0);␊ |
3138 | ␉␊ |
3139 | ␉current = buildReturnZero(current);␊ |
3140 | ␉␊ |
3141 | ␉//current = buildReturnOpcode(current, valueToReturn);␊ |
3142 | ␊ |
3143 | ␉// Update package length in PPC object␊ |
3144 | ␉ppc->packageLength = (U8) ( (U8 *)current - (U8 *)&ppc->packageLength );␊ |
3145 | ␉␊ |
3146 | ␉return(current);␊ |
3147 | }␊ |
3148 | ␊ |
3149 | #if UNUSED␊ |
3150 | //-----------------------------------------------------------------------------␊ |
3151 | static void * buildPDL(void * current, U8 valueToReturn)␊ |
3152 | {␊ |
3153 | ␉ACPI_SMALL_METHOD * pdl = current;␊ |
3154 | ␉current = buildSmallMethod(current, NAMESEG("_PDL"), 0);␊ |
3155 | ␉␊ |
3156 | ␉current = buildReturnOpcode(current, valueToReturn);␊ |
3157 | ␉␊ |
3158 | ␉// Update package length in PDL object␊ |
3159 | ␉pdl->packageLength = (U8) ( (U8 *)current - (U8 *)&pdl->packageLength );␊ |
3160 | ␉␊ |
3161 | ␉return(current);␊ |
3162 | }␊ |
3163 | #endif␊ |
3164 | ␊ |
3165 | //-----------------------------------------------------------------------------␊ |
3166 | static void * buildPCT(void * current)␊ |
3167 | {␊ |
3168 | ␉static const ACPI_GENERIC_ADDRESS pct_gas[] = {␊ |
3169 | ␉␉{0x7f,0x40,0,0,0x199},␊ |
3170 | ␉␉{0x7f,0x10,0,0,0x198},␊ |
3171 | ␉};␊ |
3172 | ␉␊ |
3173 | ␉ACPI_SMALL_METHOD * pct = current;␊ |
3174 | ␉current = buildSmallMethod(current, NAMESEG("_PCT"), 0);␊ |
3175 | ␉␊ |
3176 | ␉{␊ |
3177 | ␉␉ACPI_RETURN_PACKAGE * returnPkg = current;␊ |
3178 | ␉␉current = buildReturnPackage(current, 2);␊ |
3179 | ␉␉␊ |
3180 | ␉␉{␊ |
3181 | ␉␉␉ACPI_SMALL_BUFFER * buff = current;␊ |
3182 | ␉␉␉current = buildSmallBuffer(current);␊ |
3183 | ␉␉␉␊ |
3184 | ␉␉␉current = buildByteConst(current, sizeof(ACPI_GENERIC_REGISTER) + sizeof(ACPI_END_TAG) );␊ |
3185 | ␉␉␉current = buildGenericRegister(current, &pct_gas[0]);␊ |
3186 | ␉␉␉current = buildEndTag(current);␊ |
3187 | ␉␉␉␊ |
3188 | ␉␉␉{␊ |
3189 | ␉␉␉␉U32 length = (U8 *)current - (U8 *)buff;␊ |
3190 | ␉␉␉␉buff->packageLength = (U8)length - 1;␊ |
3191 | ␉␉␉}␊ |
3192 | ␉␉}␊ |
3193 | ␉␉{␊ |
3194 | ␉␉␉ACPI_SMALL_BUFFER * buff = current;␊ |
3195 | ␉␉␉current = buildSmallBuffer(current);␊ |
3196 | ␉␉␉␊ |
3197 | ␉␉␉current = buildByteConst(current, sizeof(ACPI_GENERIC_REGISTER) + sizeof(ACPI_END_TAG) );␊ |
3198 | ␉␉␉current = buildGenericRegister(current, &pct_gas[1]);␊ |
3199 | ␉␉␉current = buildEndTag(current);␊ |
3200 | ␉␉␉␊ |
3201 | ␉␉␉{␊ |
3202 | ␉␉␉␉U32 length = (U8 *)current - (U8 *)buff;␊ |
3203 | ␉␉␉␉buff->packageLength = (U8)length - 1;␊ |
3204 | ␉␉␉}␊ |
3205 | ␉␉␉␊ |
3206 | ␉␉}␊ |
3207 | ␉␉␊ |
3208 | ␉␉setPackageLength(&returnPkg->package.pkgLength,␊ |
3209 | ␉␉␉␉␉␉ (U8 *)current - (U8 *)&returnPkg->package.pkgLength);␊ |
3210 | ␉}␊ |
3211 | ␉␊ |
3212 | ␉// Update package length in PCT object␊ |
3213 | ␉pct->packageLength = (U8)((U8 *)current - (U8 *)&pct->packageLength);␊ |
3214 | ␉␊ |
3215 | ␉return(current);␊ |
3216 | }␊ |
3217 | ␊ |
3218 | //-----------------------------------------------------------------------------␊ |
3219 | static void * buildCstate(void * current, ACPI_GENERIC_ADDRESS * gas, CSTATE * cstate)␊ |
3220 | {␊ |
3221 | ␉//␊ |
3222 | ␉// Build a C-state␊ |
3223 | ␉//␊ |
3224 | ␉ACPI_SMALL_PACKAGE * pkg1 = current;␊ |
3225 | ␉current = buildSmallPackage(current, 4);␊ |
3226 | ␉␊ |
3227 | ␉{␊ |
3228 | ␉␉{␊ |
3229 | ␉␉␉ACPI_SMALL_BUFFER * buffer = current;␊ |
3230 | ␉␉␉current = buildSmallBuffer(current);␊ |
3231 | ␉␉␉␊ |
3232 | ␉␉␉{␊ |
3233 | ␉␉␉␉// Buffer length␊ |
3234 | ␉␉␉␉current = buildByteConst(current, sizeof(ACPI_GENERIC_REGISTER) + sizeof(ACPI_END_TAG) );␊ |
3235 | ␉␉␉␉current = buildGenericRegister(current, gas);␊ |
3236 | ␉␉␉␉current = buildEndTag(current);␊ |
3237 | ␉␉␉}␊ |
3238 | ␉␉␉{␊ |
3239 | ␉␉␉␉U32 length = (U8 *)current - (U8 *)buffer;␊ |
3240 | ␉␉␉␉buffer->packageLength = (U8)length - 1;␊ |
3241 | ␉␉␉}␊ |
3242 | ␉␉}␊ |
3243 | ␉␉␊ |
3244 | ␉␉{␊ |
3245 | ␉␉␉current = buildByteConst(current, cstate->type);␊ |
3246 | ␉␉␉current = buildWordConst(current, cstate->latency);␊ |
3247 | ␉␉␉current = buildDwordConst(current, cstate->power);␊ |
3248 | ␉␉}␊ |
3249 | ␉}␊ |
3250 | ␉pkg1->packageLength = (U8)((U8 *)current - (U8 *)&pkg1->packageLength);␊ |
3251 | ␉␊ |
3252 | ␉return(current);␊ |
3253 | }␊ |
3254 | ␊ |
3255 | //-----------------------------------------------------------------------------␊ |
3256 | static void * buildReturnPackageCST(void * current, PKG_CSTATES * pkg_cstates)␊ |
3257 | {␊ |
3258 | ␉// Create package returning C-states␊ |
3259 | ␉ACPI_RETURN_PACKAGE * returnPkg = current;␊ |
3260 | ␉current = buildReturnPackage(current, (U8)pkg_cstates->num_cstates + 1);␊ |
3261 | ␉␊ |
3262 | ␉{␊ |
3263 | ␉␉// Include number of C-states␊ |
3264 | ␉␉current = buildByteConst(current, (U8)pkg_cstates->num_cstates);␊ |
3265 | ␉␉␊ |
3266 | ␉␉{␊ |
3267 | ␉␉␉U32 cstateIndex = 0;␊ |
3268 | ␉␉␉for (cstateIndex=0; cstateIndex < pkg_cstates->num_cstates; cstateIndex++)␊ |
3269 | ␉␉␉␉// Build C-state␊ |
3270 | ␉␉␉␉current = buildCstate(current, &pkg_cstates->gas[cstateIndex], &pkg_cstates->cstate[cstateIndex]);␊ |
3271 | ␉␉}␊ |
3272 | ␉}␊ |
3273 | ␉␊ |
3274 | ␉// Update package length in return package␊ |
3275 | ␉setPackageLength(&returnPkg->package.pkgLength,␊ |
3276 | (U8 *)current - (U8 *)&returnPkg->package.pkgLength);␊ |
3277 | ␉␊ |
3278 | ␉return(current);␊ |
3279 | }␊ |
3280 | ␊ |
3281 | //-----------------------------------------------------------------------------␊ |
3282 | static void * buildCST(void * current, PKG_CSTATES * mwait_pkg_cstates, PKG_CSTATES * io_pkg_cstates)␊ |
3283 | {␊ |
3284 | ␉//␊ |
3285 | ␉// IF (CSEN)␊ |
3286 | ␉// {␊ |
3287 | ␉// IF (LAnd(MWOS, And(TYPE, 0x200)))␊ |
3288 | ␉// {␊ |
3289 | ␉// Return package containing MWAIT C-states␊ |
3290 | ␉// }␊ |
3291 | ␉// Return package containing IO C-states␊ |
3292 | ␉// }␊ |
3293 | ␉// Return(Zero)␊ |
3294 | ␉//␊ |
3295 | ␉ACPI_METHOD * cst = current;␊ |
3296 | ␉current = buildMethod(current, NAMESEG("_CST"), 0);␊ |
3297 | ␉{␊ |
3298 | ␉␉// "IF" CSEN -- IF Opcode␊ |
3299 | ␉␉current = buildOpCode(current, AML_IF_OP);␊ |
3300 | ␉␉{␊ |
3301 | ␉␉␉ACPI_PACKAGE_LENGTH * packageLength1 = current;␊ |
3302 | ␉␉␉current = buildPackageLength(current, 0);␊ |
3303 | ␉␉␉␊ |
3304 | ␉␉␉// IF "(CSEN)" -- IF Predicate␊ |
3305 | ␉␉␉current = buildNameSeg(current, NAMESEG("CSEN"));␊ |
3306 | ␉␉␉␊ |
3307 | ␉␉␉// "IF" (LAnd(MWOS, And(TYPE, 0x200))) -- IF Opcode␊ |
3308 | ␉␉␉current = buildOpCode(current, AML_IF_OP);␊ |
3309 | ␉␉␉{␊ |
3310 | ␉␉␉␉ACPI_PACKAGE_LENGTH * packageLength2 = current;␊ |
3311 | ␉␉␉␉current = buildPackageLength(current, 0);␊ |
3312 | ␉␉␉␉␊ |
3313 | ␉␉␉␉// IF ("LAnd"(MWOS, And(TYPE, 0x200))) -- LAND Opcode␊ |
3314 | ␉␉␉␉current = buildOpCode(current, AML_LAND_OP);␊ |
3315 | ␉␉␉␉␊ |
3316 | ␉␉␉␉// IF (LAnd("MWOS", And(TYPE, 0x200))) -- MWOS Term␊ |
3317 | ␉␉␉␉current = buildNameSeg(current, NAMESEG("MWOS"));␊ |
3318 | ␉␉␉␉␊ |
3319 | ␉␉␉␉// IF (LAnd(MWOS, "And"(TYPE, 0x200))) -- AND Opcode␊ |
3320 | ␉␉␉␉current = buildOpCode(current, AML_AND_OP);␊ |
3321 | ␉␉␉␉␊ |
3322 | ␉␉␉␉// IF (LAnd(MWOS, And("TYPE", 0x200))) -- TYPE Term␊ |
3323 | ␉␉␉␉current = buildNameSeg(current, NAMESEG("TYPE"));␊ |
3324 | ␉␉␉␉␊ |
3325 | ␉␉␉␉// IF (LAnd(MWOS, And(TYPE, "0x200"))) -- DWORD Value Term␊ |
3326 | ␉␉␉␉current = buildWordConst(current, 0x200);␊ |
3327 | ␉␉␉␉␊ |
3328 | ␉␉␉␉// IF (LAnd(MWOS, "And(TYPE, 0x200)")) -- Target for And term (unused)␊ |
3329 | ␉␉␉␉current = buildOpCode(current, AML_ZERO_OP);␊ |
3330 | ␉␉␉␉␊ |
3331 | ␉␉␉␉// Build return package for mwait c-states␊ |
3332 | ␉␉␉␉current = buildReturnPackageCST(current, mwait_pkg_cstates);␊ |
3333 | ␉␉␉␉␊ |
3334 | ␉␉␉␉setPackageLength(packageLength2,␊ |
3335 | ␉␉␉␉␉␉␉␉ (U8 *)current - (U8 *)packageLength2);␊ |
3336 | ␉␉␉}␊ |
3337 | ␉␉␉␊ |
3338 | ␉␉␉// Build return package for io c-states␊ |
3339 | ␉␉␉current = buildReturnPackageCST(current, io_pkg_cstates);␊ |
3340 | ␉␉␉␊ |
3341 | ␉␉␉setPackageLength(packageLength1,␊ |
3342 | ␉␉␉␉␉␉␉ (U8 *)current - (U8 *)packageLength1);␊ |
3343 | ␉␉}␊ |
3344 | ␉␉// "Return (ZERO)"␊ |
3345 | ␉␉current = buildReturnZero(current);␊ |
3346 | ␉}␊ |
3347 | ␉// Update length in _CST method␊ |
3348 | ␉setPackageLength(&cst->pkgLength, (U8 *)current - (U8 *)&cst->pkgLength);␊ |
3349 | ␉␊ |
3350 | ␉return(current);␊ |
3351 | }␊ |
3352 | ␊ |
3353 | #if BUILD_ACPI_CSD␊ |
3354 | //-----------------------------------------------------------------------------␊ |
3355 | static void * buildCSD(void * current, U32 domain, U32 cpusInDomain, PKG_CSTATES * pkg_cstates)␊ |
3356 | {␊ |
3357 | // If (And(TYPE, 0x0040))␊ |
3358 | // {␊ |
3359 | // Return (CSD Package)␊ |
3360 | // }␊ |
3361 | // Return(Zero)␊ |
3362 | ␊ |
3363 | ACPI_METHOD * csdMethod = current;␊ |
3364 | current = buildMethod(current, NAMESEG("_CSD"), 0);␊ |
3365 | {␊ |
3366 | // "IF" (And(TYPE, 0x0040)) -- IF Opcode␊ |
3367 | current = buildOpCode(current, AML_IF_OP);␊ |
3368 | {␊ |
3369 | ACPI_PACKAGE_LENGTH * packageLength = current;␊ |
3370 | current = buildPackageLength(current, 0);␊ |
3371 | ␊ |
3372 | // IF ("And"(TYPE, 0x0040)) -- AND Opcode␊ |
3373 | current = buildOpCode(current, AML_AND_OP);␊ |
3374 | ␊ |
3375 | // IF (And("TYPE", 0x0040)) -- TYPE Term␊ |
3376 | current = buildNameSeg(current, NAMESEG("TYPE"));␊ |
3377 | ␊ |
3378 | // IF (And(TYPE, "0x0040")) -- DWORD Value Term␊ |
3379 | current = buildDwordConst(current, 0x0040);␊ |
3380 | ␊ |
3381 | // IF ("And(TYPE, 0x0040)") -- Target for And term (unused)␊ |
3382 | current = buildOpCode(current, AML_ZERO_OP);␊ |
3383 | ␊ |
3384 | // Build return package containing CSD package(s)␊ |
3385 | {␊ |
3386 | ACPI_RETURN_PACKAGE * returnPkg = current;␊ |
3387 | current = buildReturnPackage(current, (U8)pkg_cstates->num_cstates - 1);␊ |
3388 | ␊ |
3389 | {␊ |
3390 | U32 cstateIndex;␊ |
3391 | for (cstateIndex=1; cstateIndex < pkg_cstates->num_cstates; cstateIndex++)␊ |
3392 | {␊ |
3393 | // Build CSD for this C-state␊ |
3394 | ␊ |
3395 | // Create CSD package␊ |
3396 | ACPI_CSD_PACKAGE * csd = current;␊ |
3397 | current = csd + 1;␊ |
3398 | ␊ |
3399 | setSmallPackage(&csd->package, 6);␊ |
3400 | csd->package.packageLength = (U8)(sizeof(ACPI_CSD_PACKAGE) - 1);␊ |
3401 | ␊ |
3402 | setByteConst(&csd->NumberOfEntries, 6);␊ |
3403 | setByteConst(&csd->Revision, 0);␊ |
3404 | setDwordConst(&csd->Domain, domain);␊ |
3405 | setDwordConst(&csd->CoordType, ACPI_COORD_TYPE_HW_ALL);␊ |
3406 | setDwordConst(&csd->NumProcessors, cpusInDomain);␊ |
3407 | setDwordConst(&csd->Index, cstateIndex);␊ |
3408 | }␊ |
3409 | }␊ |
3410 | ␊ |
3411 | setPackageLength(&returnPkg->package.pkgLength,␊ |
3412 | (U8 *)current - (U8 *)&returnPkg->package.pkgLength);␊ |
3413 | }␊ |
3414 | ␊ |
3415 | setPackageLength(packageLength, (U8 *)current - (U8 *)packageLength);␊ |
3416 | }␊ |
3417 | // "Return (ZERO)"␊ |
3418 | current = buildReturnZero(current);␊ |
3419 | }␊ |
3420 | // Update length in _CSD method␊ |
3421 | setPackageLength(&csdMethod->pkgLength, (U8 *)current - (U8 *)&csdMethod->pkgLength);␊ |
3422 | ␊ |
3423 | return(current);␊ |
3424 | }␊ |
3425 | #endif // BUILD_ACPI_CSD␊ |
3426 | ␊ |
3427 | #if BUILD_ACPI_TSS␊ |
3428 | //-----------------------------------------------------------------------------␊ |
3429 | static void * buildTPC(void * current)␊ |
3430 | {␊ |
3431 | ACPI_SMALL_METHOD * tpc = current;␊ |
3432 | current = buildSmallMethod(current, NAMESEG("_TPC"), 0);␊ |
3433 | ␊ |
3434 | current = buildReturnZero(current);␊ |
3435 | ␊ |
3436 | // Update package length in PPC object␊ |
3437 | tpc->packageLength = (U8) ( (U8 *)current - (U8 *)&tpc->packageLength );␊ |
3438 | ␊ |
3439 | return(current);␊ |
3440 | }␊ |
3441 | ␊ |
3442 | //-----------------------------------------------------------------------------␊ |
3443 | static void * buildPTC(void * current)␊ |
3444 | {␊ |
3445 | static const ACPI_GENERIC_ADDRESS ptc_gas[] = {␊ |
3446 | {0x7f,0x00,0,0,0},␊ |
3447 | {0x7f,0x00,0,0,0},␊ |
3448 | };␊ |
3449 | ␊ |
3450 | ACPI_SMALL_METHOD * ptc = current;␊ |
3451 | current = buildSmallMethod(current, NAMESEG("_PTC"), 0);␊ |
3452 | ␊ |
3453 | {␊ |
3454 | ACPI_RETURN_PACKAGE * returnPkg = current;␊ |
3455 | current = buildReturnPackage(current, 2);␊ |
3456 | ␊ |
3457 | {␊ |
3458 | ACPI_SMALL_BUFFER * buff = current;␊ |
3459 | current = buildSmallBuffer(current);␊ |
3460 | ␊ |
3461 | current = buildByteConst(current, sizeof(ACPI_GENERIC_REGISTER) + sizeof(ACPI_END_TAG) );␊ |
3462 | current = buildGenericRegister(current, &ptc_gas[0]);␊ |
3463 | current = buildEndTag(current);␊ |
3464 | ␊ |
3465 | {␊ |
3466 | U32 length = (U8 *)current - (U8 *)buff;␊ |
3467 | buff->packageLength = (U8)length - 1;␊ |
3468 | }␊ |
3469 | }␊ |
3470 | {␊ |
3471 | ACPI_SMALL_BUFFER * buff = current;␊ |
3472 | current = buildSmallBuffer(current);␊ |
3473 | ␊ |
3474 | current = buildByteConst(current, sizeof(ACPI_GENERIC_REGISTER) + sizeof(ACPI_END_TAG) );␊ |
3475 | current = buildGenericRegister(current, &ptc_gas[1]);␊ |
3476 | current = buildEndTag(current);␊ |
3477 | ␊ |
3478 | {␊ |
3479 | U32 length = (U8 *)current - (U8 *)buff;␊ |
3480 | buff->packageLength = (U8)length - 1;␊ |
3481 | }␊ |
3482 | }␊ |
3483 | ␊ |
3484 | setPackageLength(&returnPkg->package.pkgLength,␊ |
3485 | (U8 *)current - (U8 *)&returnPkg->package.pkgLength);␊ |
3486 | }␊ |
3487 | ␊ |
3488 | // Update package length in PTC object␊ |
3489 | ptc->packageLength = (U8)((U8 *)current - (U8 *)&ptc->packageLength);␊ |
3490 | ␊ |
3491 | return(current);␊ |
3492 | }␊ |
3493 | ␊ |
3494 | //-----------------------------------------------------------------------------␊ |
3495 | static void * buildTSS(void * current, PKG_TSTATES * pkg_tstates)␊ |
3496 | {␊ |
3497 | //␊ |
3498 | // IF (LAnd(TSEN, And(TYPE,4)))␊ |
3499 | // {␊ |
3500 | // Return (Package of Tstate Packages)␊ |
3501 | // }␊ |
3502 | // Return(Zero)␊ |
3503 | //␊ |
3504 | ACPI_METHOD * tss = current;␊ |
3505 | current = buildMethod(current, NAMESEG("_TSS"), 0);␊ |
3506 | ␊ |
3507 | {␊ |
3508 | // "IF" (LAnd(TSEN, And(TYPE,4))) -- IF Opcode␊ |
3509 | current = buildOpCode(current, AML_IF_OP);␊ |
3510 | {␊ |
3511 | ACPI_PACKAGE_LENGTH * packageLength = current;␊ |
3512 | current = buildPackageLength(current, 0);␊ |
3513 | ␊ |
3514 | // IF ("LAnd"(TSEN, And(TYPE, 4))) -- LAND Opcode␊ |
3515 | current = buildOpCode(current, AML_LAND_OP);␊ |
3516 | ␊ |
3517 | // IF (LAnd("TSEN", And(TYPE, 4))) -- TSEN Term␊ |
3518 | current = buildNameSeg(current, NAMESEG("TSEN"));␊ |
3519 | ␊ |
3520 | // IF (LAnd(TSEN, "And"(TYPE, 4))) -- AND Opcode␊ |
3521 | current = buildOpCode(current, AML_AND_OP);␊ |
3522 | ␊ |
3523 | // IF (LAnd(TSEN, And("TYPE", 4))) -- TYPE Term␊ |
3524 | current = buildNameSeg(current, NAMESEG("TYPE"));␊ |
3525 | ␊ |
3526 | // IF (LAnd(TSEN, And(TYPE, "4"))) -- DWORD Value Term␊ |
3527 | current = buildWordConst(current, 4);␊ |
3528 | ␊ |
3529 | // IF (LAnd(MWOS, "And(TYPE, 4)")) -- Target for And term (unused)␊ |
3530 | current = buildOpCode(current, AML_ZERO_OP);␊ |
3531 | ␊ |
3532 | // Return (Package of Tstate Packages)␊ |
3533 | {␊ |
3534 | ACPI_RETURN_PACKAGE * returnPkg = current;␊ |
3535 | current = buildReturnPackage(current, (U8)pkg_tstates->num_tstates);␊ |
3536 | ␊ |
3537 | // (3.3.3) For each T-state␊ |
3538 | {␊ |
3539 | U32 tstateIndex = 0;␊ |
3540 | for (tstateIndex=0; tstateIndex < pkg_tstates->num_tstates; tstateIndex++)␊ |
3541 | {␊ |
3542 | // (3.3.3.1) Create T-state package␊ |
3543 | ACPI_TSTATE_PACKAGE * tstate = current;␊ |
3544 | current = tstate + 1;␊ |
3545 | ␊ |
3546 | setSmallPackage(&tstate->package, 5);␊ |
3547 | tstate->package.packageLength = (U8)(sizeof(ACPI_TSTATE_PACKAGE) - 1);␊ |
3548 | ␊ |
3549 | setDwordConst(&tstate->FreqPercent, pkg_tstates->tstate[tstateIndex].freqpercent);␊ |
3550 | setDwordConst(&tstate->Power, pkg_tstates->tstate[tstateIndex].power);␊ |
3551 | setDwordConst(&tstate->TransLatency, pkg_tstates->tstate[tstateIndex].latency);␊ |
3552 | setDwordConst(&tstate->Control, pkg_tstates->tstate[tstateIndex].control);␊ |
3553 | setDwordConst(&tstate->Status, pkg_tstates->tstate[tstateIndex].status);␊ |
3554 | } // for␊ |
3555 | } // for block␊ |
3556 | ␊ |
3557 | // (3.3.4) Update package length in return package␊ |
3558 | setPackageLength(&returnPkg->package.pkgLength, (U8 *)current - (U8 *)&returnPkg->package.pkgLength);␊ |
3559 | }␊ |
3560 | ␊ |
3561 | // "IF (LAnd(TSEN, And(TYPE,4))) and its body" -- Set package length␊ |
3562 | setPackageLength(packageLength, (U8 *)current - (U8 *)packageLength);␊ |
3563 | }␊ |
3564 | // "Return (ZERO)"␊ |
3565 | current = buildReturnZero(current);␊ |
3566 | }␊ |
3567 | // Set package length for the _TSS object␊ |
3568 | setPackageLength(&tss->pkgLength, (U8 *)current - (U8 *)&tss->pkgLength);␊ |
3569 | ␊ |
3570 | return(current);␊ |
3571 | }␊ |
3572 | ␊ |
3573 | //-----------------------------------------------------------------------------␊ |
3574 | static void * buildTSD(void * current, U32 domain, U32 cpusInDomain)␊ |
3575 | {␊ |
3576 | // If (And(TYPE, 0x0080))␊ |
3577 | // {␊ |
3578 | // Return (Package containing TSD package)␊ |
3579 | // }␊ |
3580 | // Return(Zero)␊ |
3581 | ␊ |
3582 | ACPI_METHOD * tsdMethod = current;␊ |
3583 | current = buildMethod(current, NAMESEG("_TSD"), 0);␊ |
3584 | {␊ |
3585 | // "IF" (And(TYPE, 0x0080)) -- IF Opcode␊ |
3586 | current = buildOpCode(current, AML_IF_OP);␊ |
3587 | {␊ |
3588 | ACPI_PACKAGE_LENGTH * packageLength = current;␊ |
3589 | current = buildPackageLength(current, 0);␊ |
3590 | ␊ |
3591 | // IF ("And"(TYPE, 0x0080)) -- AND Opcode␊ |
3592 | current = buildOpCode(current, AML_AND_OP);␊ |
3593 | ␊ |
3594 | // IF (And("TYPE", 0x0080)) -- TYPE Term␊ |
3595 | current = buildNameSeg(current, NAMESEG("TYPE"));␊ |
3596 | ␊ |
3597 | // IF (And(TYPE, "0x0080")) -- DWORD Value Term␊ |
3598 | current = buildDwordConst(current, 0x0080);␊ |
3599 | ␊ |
3600 | // IF ("And(TYPE, 0x0080)") -- Target for And term (unused)␊ |
3601 | current = buildOpCode(current, AML_ZERO_OP);␊ |
3602 | ␊ |
3603 | // Build package containing TSD package␊ |
3604 | {␊ |
3605 | ACPI_RETURN_PACKAGE * returnPkg = current;␊ |
3606 | current = buildReturnPackage(current, 1);␊ |
3607 | ␊ |
3608 | {␊ |
3609 | // Create PSD package␊ |
3610 | ACPI_TSD_PACKAGE * tsd = current;␊ |
3611 | current = tsd + 1;␊ |
3612 | ␊ |
3613 | setSmallPackage(&tsd->package, 5);␊ |
3614 | tsd->package.packageLength = (U8)(sizeof(ACPI_TSD_PACKAGE) - 1);␊ |
3615 | ␊ |
3616 | setByteConst(&tsd->NumberOfEntries, 5);␊ |
3617 | setByteConst(&tsd->Revision, 0);␊ |
3618 | setDwordConst(&tsd->Domain, domain);␊ |
3619 | setDwordConst(&tsd->CoordType, ACPI_COORD_TYPE_SW_ANY);␊ |
3620 | setDwordConst(&tsd->NumProcessors, cpusInDomain);␊ |
3621 | ␊ |
3622 | } // TSD package␊ |
3623 | ␊ |
3624 | setPackageLength(&returnPkg->package.pkgLength,␊ |
3625 | (U8 *)current - (U8 *)&returnPkg->package.pkgLength);␊ |
3626 | }␊ |
3627 | ␊ |
3628 | setPackageLength(packageLength, (U8 *)current - (U8 *)packageLength);␊ |
3629 | }␊ |
3630 | // "Return (ZERO)"␊ |
3631 | current = buildReturnZero(current);␊ |
3632 | }␊ |
3633 | // Update length in _TSD method␊ |
3634 | setPackageLength(&tsdMethod->pkgLength, (U8 *)current - (U8 *)&tsdMethod->pkgLength);␊ |
3635 | ␊ |
3636 | return(current);␊ |
3637 | }␊ |
3638 | #endif // BUILD_ACPI_TSS␊ |
3639 | ␊ |
3640 | //-----------------------------------------------------------------------------␊ |
3641 | static U32 BuildSsdt(MADT_INFO * madt_info, ACPI_TABLE_DSDT *dsdt, void * buffer, U32 bufferSize, bool enable_cstates, bool enable_pstates, bool enable_tstates)␊ |
3642 | {␊ |
3643 | ␉// Build SSDT␊ |
3644 | ␉{␊ |
3645 | ␉␉// (1) Setup pointers to SSDT memory location␊ |
3646 | ␉␉// (2) Create SSDT Definition Block␊ |
3647 | ␉␉// (2.1) Save pointer to SSDT package length and checksum fields␊ |
3648 | ␉␉// (2.2) Create variables in SSDT scope␊ |
3649 | ␉␉// (3) For each logical processor CPUn ␊ |
3650 | ␉␉// (3.1) Create scope for CPUn␊ |
3651 | ␉␉// (3.2) Create variables in CPU scope␊ |
3652 | ␉␉// (3.3) Create _OSC and/or _PDC Methods␊ |
3653 | ␉␉// (3.4) Create P-state related structures␊ |
3654 | ␉␉// (3.4.1) Create _PSS Method␊ |
3655 | ␉␉// (3.4.2) Create _PCT Object␊ |
3656 | ␉␉// (3.4.3) Create _PPC Method␊ |
3657 | ␉␉// (3.4.4) Create _PSD Object␊ |
3658 | ␉␉// (3.5) Create C-state related structures␊ |
3659 | ␉␉// (3.5.1) Create _CST Method␊ |
3660 | ␉␉// (3.5.2) Create _CSD Method␊ |
3661 | ␉␉// (3.6) Create T-state related structures (Optional)␊ |
3662 | ␉␉// (3.6.1) Create _TPC Method␊ |
3663 | ␉␉// (3.6.2) Create _PTC Method␊ |
3664 | ␉␉// (3.6.3) Create _TSS Method␊ |
3665 | ␉␉// (3.6.4) Create _TSD Method␊ |
3666 | ␉␉// (3.7) Update length in CPUn Scope␊ |
3667 | ␉␉// (4) Update length and checksum in SSDT Definition Block␊ |
3668 | ␉␉DBG("Attempting to build SSDT\n");␊ |
3669 | ␊ |
3670 | ␉␉U32 pstates_enabled = 0;␊ |
3671 | ␉␉U32 cstates_enabled = 0;␊ |
3672 | ␉␉CPU_DETAILS cpu;␊ |
3673 | ␉␉cpu.max_ratio_as_mfg = 0;␊ |
3674 | ␉␉cpu.package_power_limit = 0;␊ |
3675 | ␉␉␊ |
3676 | ␉␉U8 ACPI_COORD_TYPE = ACPI_COORD_TYPE_SW_ANY; // default␊ |
3677 | ␉␉ACPI_TABLE_SSDT *SsdtPointer = (void*)0ul;␊ |
3678 | ␉␉␊ |
3679 | ␉␉// Desired state for providing alternate ACPI _CST structure using MWAIT␊ |
3680 | ␉␉// extensions␊ |
3681 | ␉␉// 1= Alternate _CST using MWAIT extension is enabled for OSPM use␊ |
3682 | ␉␉// 0= Alternate _CST using MWAIT extension is disabled for OSPM use␊ |
3683 | ␉␉bool enable_mwait = 1;␊ |
3684 | ␉␉␊ |
3685 | ␉␉// (1) Setup pointers to SSDT memory location␊ |
3686 | ␉␉void * current = buffer;␊ |
3687 | ␉␉void * end = (U8 *)buffer + bufferSize;␉␉␊ |
3688 | ␊ |
3689 | ␉␉// Confirm a valid SSDT buffer was provided␊ |
3690 | ␉␉if (!buffer)␊ |
3691 | ␉␉{␊ |
3692 | ␉␉␉printf("Error: Invalid Buffer Address for SSDT\n");␊ |
3693 | ␉␉␉return(0);␊ |
3694 | ␉␉}␊ |
3695 | ␉␉␊ |
3696 | ␉␉// Confirm a valid SSDT buffer length was provided␊ |
3697 | ␉␉if (!bufferSize)␊ |
3698 | ␉␉{␊ |
3699 | ␉␉␉printf("Error: Invalid Buffer Length for SSDT\n");␊ |
3700 | ␉␉␉return(0);␊ |
3701 | ␉␉}␉␉␊ |
3702 | ␉␉␊ |
3703 | ␉␉if (madt_info == (void*) 0ul)␊ |
3704 | ␉␉{␊ |
3705 | ␉␉␉return(0);␊ |
3706 | ␉␉}␊ |
3707 | ␉␉␊ |
3708 | ␉␉if (dsdt == (void*) 0ul)␊ |
3709 | ␉␉{␊ |
3710 | ␉␉␉return(0);␊ |
3711 | ␉␉}␊ |
3712 | ␉␉␊ |
3713 | ␉␉// Check that we have a valid cpu_map (if it's not already done, it will try to generate it)␊ |
3714 | ␉␉if (generate_cpu_map_from_acpi(dsdt) != 0)␊ |
3715 | ␉␉{␊ |
3716 | ␉␉␉return(0);␊ |
3717 | ␉␉}␊ |
3718 | ␉␉␊ |
3719 | ␉␉collect_cpu_info(&cpu);␊ |
3720 | ␉␉␊ |
3721 | ␉␉if (enable_cstates && pmbase)␊ |
3722 | ␉␉{␊ |
3723 | ␉␉␉DBG("Building Cstate Info\n");␊ |
3724 | ␊ |
3725 | ␉␉␉cstates_enabled = BuildCstateInfo(&cpu, pmbase);␊ |
3726 | ␉␉␉if (cstates_enabled)␊ |
3727 | ␉␉␉{␊ |
3728 | ␉␉␉␉getBoolForKey(KEnableMwait, &enable_mwait, &bootInfo->chameleonConfig);␊ |
3729 | ␉␉␉}␊ |
3730 | ␉␉}␊ |
3731 | ␉␉␊ |
3732 | ␉␉if (enable_pstates)␊ |
3733 | ␉␉{␊ |
3734 | ␉␉␉DBG("Building Pstate Info\n");␊ |
3735 | ␊ |
3736 | ␉␉␉pstates_enabled = BuildPstateInfo(&cpu);␊ |
3737 | ␉␉␉if (pstates_enabled)␊ |
3738 | ␉␉␉{␊ |
3739 | ␉␉␉␉const char *str = getStringForKey(KAcpiCoordType, &bootInfo->chameleonConfig);␊ |
3740 | ␉␉␉␉U8 tmp = (U8)strtoul(str, NULL,16);␊ |
3741 | ␉␉␉␉if ((tmp == ACPI_COORD_TYPE_SW_ALL) || (tmp == ACPI_COORD_TYPE_SW_ANY) || (tmp == ACPI_COORD_TYPE_HW_ALL) )␊ |
3742 | ␉␉␉␉{␊ |
3743 | ␉␉␉␉␉ACPI_COORD_TYPE = tmp;␊ |
3744 | ␉␉␉␉}␊ |
3745 | ␉␉␉}␊ |
3746 | ␉␉}␊ |
3747 | #if BUILD_ACPI_TSS␊ |
3748 | U32 tstates_enabled = 0;␊ |
3749 | if (enable_tstates)␊ |
3750 | ␉␉{␊ |
3751 | ␉␉␉DBG("Building Pstate Info\n");␊ |
3752 | ␊ |
3753 | ␉␉␉tstates_enabled = BuildTstateInfo(&cpu);␉␉␉␊ |
3754 | ␉␉} ␊ |
3755 | #endif␊ |
3756 | ␉␉␊ |
3757 | ␉␉SsdtPointer = (ACPI_TABLE_SSDT *)buffer;␊ |
3758 | ␉␉␊ |
3759 | ␉␉// (2) Create SSDT Definition Block␊ |
3760 | ␉␉// (2.1) Save pointer to SSDT package length and checksum fields␊ |
3761 | ␉␉current = buildTableHeader(current, NAMESEG("SSDT"), NAMESEG64("PPM RCM "));␊ |
3762 | ␉␉␊ |
3763 | ␉␉// Check to confirm no SSDT buffer overflow␊ |
3764 | ␉␉if ( (U8 *)current > (U8 *)end )␊ |
3765 | ␉␉{␊ |
3766 | ␉␉␉printf("Error: SSDT Buffer Length exceeded available space \n");␊ |
3767 | ␉␉␉return(0);␊ |
3768 | ␉␉}␊ |
3769 | ␉␉␊ |
3770 | ␉␉// (3) For each logical processor CPUn ␊ |
3771 | ␉␉// We will use the dsdt datas in place of madt,for the cpu(s) detection.␊ |
3772 | ␉␉// 'Cause most users use the dsdt table to change the numbers of cpu(s) that the OS and the bootloader should use,␉␉␊ |
3773 | ␉␉// Note also that due to chameleon limit we use the same package per each cpu(s) for all objects and methods␊ |
3774 | ␉␉// (package detection for each cpu(s) is still in progress) ␊ |
3775 | ␉␉{␉␉␉␊ |
3776 | ␉␉␉U32 lapic_index;␊ |
3777 | ␉␉␉for (lapic_index=0; lapic_index < cpu_map_count; lapic_index++)␊ |
3778 | ␉␉␉{␊ |
3779 | ␉␉␉␉// (3.1) Create scope for CPUn␊ |
3780 | ␉␉␉␉ACPI_SCOPE * scope = current;␊ |
3781 | ␉␉␉␉␊ |
3782 | ␉␉␉␉{␊ |
3783 | ␉␉␉␉␉DBG("Building CPU Scope\n");␊ |
3784 | ␉␉␉␉␉U32 cpu_namespace = (cpuNamespace == CPU_NAMESPACE_SB) ? NAMESEG("_SB_") : NAMESEG("_PR_");␊ |
3785 | ␉␉␉␉␉PROCESSOR_NUMBER_TO_NAMESEG * namepath = &cpu_map[lapic_index];␊ |
3786 | ␉␉␉␉␉current = buildCpuScope (current, cpu_namespace, namepath );␊ |
3787 | ␉␉␉␉}␊ |
3788 | ␉␉␉␉␊ |
3789 | ␉␉␉␉// Check to confirm no SSDT buffer overflow␊ |
3790 | ␉␉␉␉if ( (U8 *)current > (U8 *)end )␊ |
3791 | ␉␉␉␉{␊ |
3792 | ␉␉␉␉␉printf("Error: SSDT Buffer Length exceeded available space \n");␊ |
3793 | ␉␉␉␉␉return(0);␊ |
3794 | ␉␉␉␉}␊ |
3795 | ␉␉␉␉␊ |
3796 | ␉␉␉␉// (3.2) Create variables in CPU scope␊ |
3797 | ␉␉␉␉DBG("Creating variables in CPU scope\n");␉␉␉␉// Build Type variable used to store PDC capabilities␊ |
3798 | ␉␉␉␉current = buildNamedDword(current, NAMESEG("TYPE"), 0);␊ |
3799 | ␉␉␉␉␊ |
3800 | ␉␉␉␉// Build PSEN variable used to store state of P-State Enable setup option␊ |
3801 | ␉␉␉␉current = buildNamedDword(current, NAMESEG("PSEN"), pstates_enabled);␊ |
3802 | ␉␉␉␉␊ |
3803 | ␉␉␉␉// Build CSEN variable used to store state of C-State Enable setup option␊ |
3804 | ␉␉␉␉current = buildNamedDword(current, NAMESEG("CSEN"), cstates_enabled);␊ |
3805 | ␉␉␉␉␊ |
3806 | ␉␉␉␉// Build MWOS variable used to store state of MWAIT OS setup option␊ |
3807 | ␉␉␉␉current = buildNamedDword(current, NAMESEG("MWOS"), (U32)(enable_mwait&&cpu.mwait_supported));␊ |
3808 | ␊ |
3809 | ␉␉␉␉// (3.3) Create _OSC and/or _PDC Methods␊ |
3810 | ␉␉␉␉{␊ |
3811 | ␉␉␉␉␉// Build _PDC method␊ |
3812 | ␉␉␉␉␉DBG("Building PDC method\n");␊ |
3813 | ␉␉␉␉␉current = buildPDC(current);␊ |
3814 | ␉␉␉␉␉␊ |
3815 | ␉␉␉␉␉// Check to confirm no SSDT buffer overflow␊ |
3816 | ␉␉␉␉␉if ( (U8 *)current > (U8 *)end )␊ |
3817 | ␉␉␉␉␉{␊ |
3818 | ␉␉␉␉␉␉printf("Error: SSDT Buffer Length exceeded available space \n");␊ |
3819 | ␉␉␉␉␉␉return(0);␊ |
3820 | ␉␉␉␉␉}␊ |
3821 | ␉␉␉␉␉␊ |
3822 | ␉␉␉␉␉// Build _OSC method␊ |
3823 | ␉␉␉␉␉DBG("Building _OSC method\n");␊ |
3824 | ␉␉␉␉␉current = buildOSC(current);␊ |
3825 | ␉␉␉␉␉␊ |
3826 | ␉␉␉␉␉// Check to confirm no SSDT buffer overflow␊ |
3827 | ␉␉␉␉␉if ( (U8 *)current > (U8 *)end )␊ |
3828 | ␉␉␉␉␉{␊ |
3829 | ␉␉␉␉␉␉printf("Error: SSDT Buffer Length exceeded available space \n");␊ |
3830 | ␉␉␉␉␉␉return(0);␊ |
3831 | ␉␉␉␉␉}␊ |
3832 | ␉␉␉␉}␊ |
3833 | ␉␉␉␉␊ |
3834 | ␉␉␉␉// (3.4) Create P-state related structures␊ |
3835 | ␉␉␉␉if (pstates_enabled == 1)␊ |
3836 | ␉␉␉␉{␊ |
3837 | ␉␉␉␉␉// (3.4.1) Create _PSS Method␊ |
3838 | ␉␉␉␉␉{␊ |
3839 | ␉␉␉␉␉␉DBG("Building _PSS method\n");␊ |
3840 | ␉␉␉␉␉␉PKG_PSTATES * pkg_pstates = &cpu.pkg_pstates;␊ |
3841 | ␉␉␉␉␉␉current = buildPSS(current, pkg_pstates);␊ |
3842 | ␉␉␉␉␉}␊ |
3843 | ␉␉␉␉␉␊ |
3844 | ␉␉␉␉␉// Check to confirm no SSDT buffer overflow␊ |
3845 | ␉␉␉␉␉if ( (U8 *)(current) > (U8 *)end )␊ |
3846 | ␉␉␉␉␉{␊ |
3847 | ␉␉␉␉␉␉printf("Error: SSDT Buffer Length exceeded available space \n");␊ |
3848 | ␉␉␉␉␉␉return(0);␊ |
3849 | ␉␉␉␉␉}␊ |
3850 | ␉␉␉␉␉␊ |
3851 | ␉␉␉␉␉// (3.4.2) Create _PCT Object␊ |
3852 | ␉␉␉␉␉DBG("Building _PCT Object\n");␊ |
3853 | ␉␉␉␉␉current = buildPCT(current);␊ |
3854 | ␉␉␉␉␉␊ |
3855 | ␉␉␉␉␉// Check to confirm no SSDT buffer overflow␊ |
3856 | ␉␉␉␉␉if ( (U8 *)(current) > (U8 *)end )␊ |
3857 | ␉␉␉␉␉{␊ |
3858 | ␉␉␉␉␉␉printf("Error: SSDT Buffer Length exceeded available space \n");␊ |
3859 | ␉␉␉␉␉␉return(0);␊ |
3860 | ␉␉␉␉␉}␊ |
3861 | ␉␉␉␉␉␊ |
3862 | ␉␉␉␉␉// (3.4.3) Create _PPC Method␊ |
3863 | ␉␉␉␉␉DBG("Building _PPC Method\n");␊ |
3864 | ␉␉␉␉␉current = buildPPC(current);␊ |
3865 | ␉␉␉␉␉␊ |
3866 | ␉␉␉␉␉// Check to confirm no SSDT buffer overflow␊ |
3867 | ␉␉␉␉␉if ( (U8 *)(current) > (U8 *)end )␊ |
3868 | ␉␉␉␉␉{␊ |
3869 | ␉␉␉␉␉␉printf("Error: SSDT Buffer Length exceeded available space \n");␊ |
3870 | ␉␉␉␉␉␉return(0);␊ |
3871 | ␉␉␉␉␉}␊ |
3872 | ␉␉␉␉␉␊ |
3873 | ␉␉␉␉␉// (3.4.4) Create PSD with hardware coordination␊ |
3874 | ␉␉␉␉␉{␊ |
3875 | ␉␉␉␉␉␉DBG("Building _PSD Method\n");␊ |
3876 | ␉␉␉␉␉␉U32 domain = madt_info->lapic[lapic_index].pkg_index;␊ |
3877 | ␊ |
3878 | // In this (bad?) implementation we use the nb of cpu found in the dsdt␊ |
3879 | ␉␉␉␉␉␉U32 cpusInDomain = cpu_map_count;␉␉␉␉␉␉␉␊ |
3880 | ␉␉␉␉␉␉current = buildPSD(current, domain, cpusInDomain, ACPI_COORD_TYPE);␊ |
3881 | ␉␉␉␉␉}␊ |
3882 | ␉␉␉␉␉␊ |
3883 | ␉␉␉␉␉// Check to confirm no SSDT buffer overflow␊ |
3884 | ␉␉␉␉␉if ( (U8 *)(current) > (U8 *)end )␊ |
3885 | ␉␉␉␉␉{␊ |
3886 | ␉␉␉␉␉␉printf("Error: SSDT Buffer Length exceeded available space \n");␊ |
3887 | ␉␉␉␉␉␉return(0);␊ |
3888 | ␉␉␉␉␉}␊ |
3889 | ␉␉␉␉}␊ |
3890 | ␊ |
3891 | ␉␉␉␉// (3.5) Create C-state related structures␊ |
3892 | ␉␉␉␉if (cstates_enabled == 1)␊ |
3893 | ␉␉␉␉{␊ |
3894 | ␉␉␉␉␉{␊ |
3895 | ␉␉␉␉␉␉PKG_CSTATES * mwait_pkg_cstates = &cpu.pkg_mwait_cstates;␊ |
3896 | ␉␉␉␉␉␉PKG_CSTATES * io_pkg_cstates = &cpu.pkg_io_cstates;␊ |
3897 | ␉␉␉␉␉␉␊ |
3898 | ␉␉␉␉␉␉// Build CST␊ |
3899 | ␉␉␉␉␉␉DBG("Building _CST Method\n");␊ |
3900 | ␉␉␉␉␉␉current = buildCST(current, mwait_pkg_cstates, io_pkg_cstates);␉␉␉␉␉␉␊ |
3901 | ␉␉␉␉␉}␊ |
3902 | ␊ |
3903 | #if BUILD_ACPI_CSD␊ |
3904 | {␊ |
3905 | // Use core_apic_id as domain␊ |
3906 | U32 domain = lapic->core_apic_id;␊ |
3907 | ␊ |
3908 | // In this (bad?) implementation we use the nb of cpu found in the dsdt ␊ |
3909 | U32 cpusInDomain = cpu_map_count;␊ |
3910 | ␊ |
3911 | // Create CSD␊ |
3912 | current = buildCSD(current, domain, cpusInDomain, io_pkg_cstates);␊ |
3913 | }␊ |
3914 | #endif␊ |
3915 | ␉␉␉␉␉␊ |
3916 | ␉␉␉␉␉// Check to confirm no SSDT buffer overflow␊ |
3917 | ␉␉␉␉␉if ( (U8 *)(current) > (U8 *)end )␊ |
3918 | ␉␉␉␉␉{␊ |
3919 | ␉␉␉␉␉␉printf("Error: SSDT Buffer Length exceeded available space \n");␊ |
3920 | ␉␉␉␉␉␉return(0);␊ |
3921 | ␉␉␉␉␉}␊ |
3922 | ␉␉␉␉}␊ |
3923 | #if BUILD_ACPI_TSS␉␉␉␉␊ |
3924 | // (3.6) Create T-state related structures␊ |
3925 | if (tstates_enabled == 1)␊ |
3926 | {␊ |
3927 | // (3.6.1) Create _TPC Method␊ |
3928 | current = buildTPC(current);␊ |
3929 | ␊ |
3930 | // (3.6.2) Create _PTC Method␊ |
3931 | current = buildPTC(current);␊ |
3932 | ␊ |
3933 | // (3.6.3) Create _TSS Method␊ |
3934 | {␊ |
3935 | PKG_TSTATES * pkg_tstates = &cpu.pkg_tstates; ␊ |
3936 | current = buildTSS(current, pkg_tstates);␊ |
3937 | }␊ |
3938 | ␊ |
3939 | // (3.6.4) Create _TSD Method␊ |
3940 | {␊ |
3941 | LAPIC_INFO * lapic = &madt_info.lapic[lapic_index];␊ |
3942 | ␊ |
3943 | // Use core_apic_id as domain␊ |
3944 | U32 domain = lapic->core_apic_id;␊ |
3945 | ␊ |
3946 | // In this (bad?) implementation we use the nb of cpu found in the dsdt ␊ |
3947 | U32 cpusInDomain = cpu_map_count;␊ |
3948 | ␊ |
3949 | current = buildTSD(current, domain, cpusInDomain);␊ |
3950 | }␊ |
3951 | }␊ |
3952 | #endif␉␉␊ |
3953 | ␉␉␉␉// (3.7) Update length in CPUn Scope␊ |
3954 | ␉␉␉␉setPackageLength(&scope->pkgLength, (U8 *)current - (U8 *)&scope->pkgLength);␊ |
3955 | ␉␉␉␉␊ |
3956 | ␉␉␉} // End for␊ |
3957 | ␉␉␉␊ |
3958 | ␉␉␉// (4) Update length and checksum in SSDT Definition Block␊ |
3959 | ␉␉␉{␊ |
3960 | ␉␉␉␉DBG("Updating length and checksum in SSDT Definition Block\n");␊ |
3961 | ␊ |
3962 | ␉␉␉␉SsdtPointer->Header.Length = (U8 *)current - (U8 *)SsdtPointer;␉␉␉␉␊ |
3963 | ␉␉␉␉SetChecksum(&SsdtPointer->Header);␊ |
3964 | ␉␉␉}␊ |
3965 | ␉␉␉␊ |
3966 | ␉␉␉// Check to confirm no SSDT buffer overflow␊ |
3967 | ␉␉␉if ( (U8 *)current > (U8 *)end )␊ |
3968 | ␉␉␉{␊ |
3969 | ␉␉␉␉printf("Error: SSDT Buffer Length exceeded available space \n");␊ |
3970 | ␉␉␉␉return(0);␊ |
3971 | ␉␉␉}␊ |
3972 | ␉␉␉␊ |
3973 | ␉␉} // End build SSDT␊ |
3974 | ␉␉␊ |
3975 | ␉} // SSDT␊ |
3976 | ␉␊ |
3977 | ␉return(1);␊ |
3978 | }␊ |
3979 | ␊ |
3980 | #if UNUSED␊ |
3981 | static ACPI_TABLE_FACS* generate_facs(bool updatefacs )␊ |
3982 | {␊ |
3983 | ACPI_TABLE_FACS* facs_mod=(ACPI_TABLE_FACS *)AllocateKernelMemory(sizeof(ACPI_TABLE_FACS));␊ |
3984 | ␉if (!facs_mod) ␊ |
3985 | ␉{␊ |
3986 | ␉␉printf("Unable to allocate kernel memory for facs mod\n");␊ |
3987 | ␉␉return (void*)0ul;␊ |
3988 | ␉}␊ |
3989 | bzero(facs_mod, sizeof(ACPI_TABLE_FACS));␊ |
3990 | ␉␊ |
3991 | ␉ACPI_TABLE_FACS * FacsPointer =(acpi_tables.FacsPointer64 != (void *)0ul) ? ␊ |
3992 | ␉(ACPI_TABLE_FACS *)acpi_tables.FacsPointer64 : (ACPI_TABLE_FACS *)acpi_tables.FacsPointer;␊ |
3993 | ␉␊ |
3994 | memcpy(facs_mod, FacsPointer , FacsPointer->Length);␊ |
3995 | facs_mod->Length = sizeof(ACPI_TABLE_FACS);␊ |
3996 | ␊ |
3997 | ␉if (FacsPointer->Length < sizeof(ACPI_TABLE_FACS))␊ |
3998 | ␉{␊ |
3999 | ␉␉facs_mod->FirmwareWakingVector = 0;␊ |
4000 | ␉␉facs_mod->GlobalLock = 0;␊ |
4001 | ␉␉facs_mod->Flags = 0;␊ |
4002 | ␉}␉␉␊ |
4003 | ␊ |
4004 | if (updatefacs && FacsPointer->Version < 2)␊ |
4005 | ␉{␊ |
4006 | ␉␉if (FacsPointer->Version > 0)␊ |
4007 | ␉␉{␊ |
4008 | ␉␉␉facs_mod->XFirmwareWakingVector = FacsPointer->XFirmwareWakingVector;␊ |
4009 | ␉␉} ␊ |
4010 | ␉␉else␊ |
4011 | ␉␉{␊ |
4012 | ␉␉␉facs_mod->XFirmwareWakingVector = (U64)facs_mod->FirmwareWakingVector;␊ |
4013 | ␉␉}␊ |
4014 | ␊ |
4015 | ␉␉facs_mod->Version = 2; /* ACPI 1.0: 0, ACPI 2.0/3.0: 1, ACPI 4.0: 2 */␊ |
4016 | ␉␉␊ |
4017 | ␉}␊ |
4018 | ␊ |
4019 | return facs_mod;␊ |
4020 | }␊ |
4021 | #endif␊ |
4022 | ␊ |
4023 | static ACPI_GENERIC_ADDRESS FillGASStruct(U32 Address, U8 Length)␊ |
4024 | {␊ |
4025 | ␉ACPI_GENERIC_ADDRESS TmpGAS;␊ |
4026 | ␉␊ |
4027 | ␉TmpGAS.SpaceId = 1; /* I/O Address */␊ |
4028 | ␉␊ |
4029 | ␉if (Address == 0)␊ |
4030 | ␉{␊ |
4031 | ␉␉TmpGAS.BitWidth = 0;␊ |
4032 | ␉} ␊ |
4033 | ␉else␊ |
4034 | ␉{␊ |
4035 | ␉␉TmpGAS.BitWidth = Length * 8;␊ |
4036 | ␉}␊ |
4037 | ␉␊ |
4038 | ␉TmpGAS.BitOffset = 0;␊ |
4039 | ␉TmpGAS.AccessWidth = 0; /* Not set for Legacy reasons... */␊ |
4040 | ␉TmpGAS.Address = (U64)Address;␊ |
4041 | ␉␊ |
4042 | ␉return (TmpGAS);␊ |
4043 | }␊ |
4044 | ␊ |
4045 | static ACPI_TABLE_FADT *␊ |
4046 | patch_fadt(ACPI_TABLE_FADT *fadt, ACPI_TABLE_DSDT *new_dsdt, bool UpdateFADT)␊ |
4047 | {␉␉␊ |
4048 | ␉ACPI_TABLE_FADT *fadt_mod = (void*)0;␊ |
4049 | ␉bool fadt_rev2_needed = false;␊ |
4050 | ␉bool fix_restart = false;␉␊ |
4051 | ␉const char * value;␉␊ |
4052 | ␊ |
4053 | ␉// Restart Fix␊ |
4054 | ␉if (Platform.CPU.Vendor == CPUID_VENDOR_INTEL) ␊ |
4055 | ␉{␉␊ |
4056 | ␉␉fix_restart = true;␊ |
4057 | ␉␉getBoolForKey(kRestartFix, &fix_restart, &bootInfo->chameleonConfig);␊ |
4058 | ␉␉␊ |
4059 | ␉} else {␊ |
4060 | ␉␉verbose ("Not an Intel platform: Restart Fix disabled !!!\n");␊ |
4061 | ␉}␊ |
4062 | ␉␊ |
4063 | ␉if (fix_restart)␊ |
4064 | ␉␉fadt_rev2_needed = true;␊ |
4065 | ␊ |
4066 | ␉// Allocate new fadt table␊ |
4067 | ␉if (UpdateFADT) ␊ |
4068 | ␉{ ␊ |
4069 | if (fadt->Header.Length < 0xF4)␊ |
4070 | {␊ |
4071 | fadt_mod=(ACPI_TABLE_FADT *)AllocateKernelMemory(0xF4);␊ |
4072 | if (!fadt_mod) ␊ |
4073 | {␊ |
4074 | printf("Unable to allocate kernel memory for fadt mod\n");␊ |
4075 | return (void*)0ul;␊ |
4076 | }␊ |
4077 | bzero(fadt_mod, 0xF4);␊ |
4078 | memcpy(fadt_mod, fadt, fadt->Header.Length);␊ |
4079 | fadt_mod->Header.Length = 0xF4;␊ |
4080 | ␊ |
4081 | ␉␉}␊ |
4082 | ␉␉else␊ |
4083 | ␉␉{␉␉␉␊ |
4084 | ␉␉␉fadt_mod=(ACPI_TABLE_FADT *)AllocateKernelMemory(fadt->Header.Length);␊ |
4085 | ␉␉␉if (!fadt_mod) ␊ |
4086 | ␉␉␉{␊ |
4087 | ␉␉␉␉printf("Unable to allocate kernel memory for fadt mod\n");␊ |
4088 | ␉␉␉␉return (void*)0ul;␊ |
4089 | ␉␉␉}␊ |
4090 | ␉␉␉memcpy(fadt_mod, fadt, fadt->Header.Length);␊ |
4091 | ␉␉}␉␉ ␊ |
4092 | ␊ |
4093 | ␊ |
4094 | ␉␉//fadt_mod->Header.Revision = 0x04; // FADT rev 4␊ |
4095 | ␉␉fadt_mod->ResetRegister = FillGASStruct(0, 0);␊ |
4096 | ␉␉fadt_mod->ResetValue = 0;␊ |
4097 | ␉␉fadt_mod->Reserved4[0] = 0;␊ |
4098 | ␉␉fadt_mod->Reserved4[1] = 0;␊ |
4099 | ␉␉fadt_mod->Reserved4[2] = 0;␊ |
4100 | ␊ |
4101 | fadt_mod->XPm1aEventBlock = FillGASStruct(fadt_mod->Pm1aEventBlock, fadt_mod->Pm1EventLength);␊ |
4102 | ␉␉fadt_mod->XPm1bEventBlock = FillGASStruct(fadt_mod->Pm1bEventBlock, fadt_mod->Pm1EventLength);␊ |
4103 | ␉␉fadt_mod->XPm1aControlBlock = FillGASStruct(fadt_mod->Pm1aControlBlock, fadt_mod->Pm1ControlLength);␊ |
4104 | ␉␉fadt_mod->XPm1bControlBlock = FillGASStruct(fadt_mod->Pm1bControlBlock, fadt_mod->Pm1ControlLength);␊ |
4105 | ␉␉fadt_mod->XPm2ControlBlock = FillGASStruct(fadt_mod->Pm2ControlBlock, fadt_mod->Pm2ControlLength);␊ |
4106 | ␉␉fadt_mod->XPmTimerBlock = FillGASStruct(fadt_mod->PmTimerBlock, fadt_mod->PmTimerLength);␊ |
4107 | ␉␉fadt_mod->XGpe0Block = FillGASStruct(fadt_mod->Gpe0Block, fadt_mod->Gpe0BlockLength);␊ |
4108 | ␉␉fadt_mod->XGpe1Block = FillGASStruct(fadt_mod->Gpe1Block, fadt_mod->Gpe1BlockLength);␉␊ |
4109 | if (fadt->Header.Revision < 4)␊ |
4110 | ␉␉{␉␉␉␉␉␊ |
4111 | ␉␉␉fadt_mod->Header.Revision = 0x04; // FADT rev 4␊ |
4112 | ␉␉␉verbose("Converted ACPI V%d FADT to ACPI V4 FADT\n", fadt->Header.Revision);␊ |
4113 | ␊ |
4114 | ␉␉}␊ |
4115 | ␉}␊ |
4116 | ␉else␊ |
4117 | ␉{␊ |
4118 | ␉␉␊ |
4119 | ␉␉if (fadt_rev2_needed)␊ |
4120 | ␉␉{␊ |
4121 | ␉␉␉if (fadt->Header.Length < 0x84 )␊ |
4122 | ␉␉␉{␊ |
4123 | ␉␉␉␉fadt_mod=(ACPI_TABLE_FADT *)AllocateKernelMemory(0x84);␊ |
4124 | ␉␉␉␉if (!fadt_mod) ␊ |
4125 | ␉␉␉␉{␊ |
4126 | ␉␉␉␉␉printf("Unable to allocate kernel memory for fadt mod\n");␊ |
4127 | ␉␉␉␉␉return (void*)0ul;␊ |
4128 | ␉␉␉␉}␊ |
4129 | ␉␉␉␉bzero(fadt_mod, 0x84);␊ |
4130 | ␉␉␉␉memcpy(fadt_mod, fadt, fadt->Header.Length);␊ |
4131 | ␉␉␉␉fadt_mod->Header.Length = 0x84;␊ |
4132 | ␉␉␉}␊ |
4133 | ␉␉␉else␊ |
4134 | ␉␉␉{␊ |
4135 | ␉␉␉␉fadt_mod=(ACPI_TABLE_FADT *)AllocateKernelMemory(fadt->Header.Length);␊ |
4136 | ␉␉␉␉if (!fadt_mod) ␊ |
4137 | ␉␉␉␉{␊ |
4138 | ␉␉␉␉␉printf("Unable to allocate kernel memory for fadt mod\n");␊ |
4139 | ␉␉␉␉␉return (void*)0ul;␊ |
4140 | ␉␉␉␉}␊ |
4141 | ␉␉␉␉memcpy(fadt_mod, fadt, fadt->Header.Length);␊ |
4142 | ␉␉␉}␉␉␉␊ |
4143 | ␉␉␉␊ |
4144 | ␉␉␉if (fadt->Header.Revision < 2) ␊ |
4145 | ␉␉␉{␉␉␉␉␉␊ |
4146 | ␉␉␉␉fadt_mod->Header.Revision = 0x02; // FADT rev 2 (ACPI 1.0B MS extensions) ␊ |
4147 | ␉␉␉␉verbose("Converted ACPI V%d FADT to ACPI V2 FADT\n", fadt->Header.Revision );␊ |
4148 | ␉␉␉}␊ |
4149 | ␉␉} ␊ |
4150 | ␉␉else␊ |
4151 | ␉␉{␊ |
4152 | ␉␉␉if (fadt->Header.Length < 0x74 )␊ |
4153 | ␉␉␉{␊ |
4154 | ␉␉␉␉fadt_mod=(ACPI_TABLE_FADT *)AllocateKernelMemory(0x74);␊ |
4155 | ␉␉␉␉if (!fadt_mod) ␊ |
4156 | ␉␉␉␉{␊ |
4157 | ␉␉␉␉␉printf("Unable to allocate kernel memory for fadt mod\n");␊ |
4158 | ␉␉␉␉␉return (void*)0ul;␊ |
4159 | ␉␉␉␉}␊ |
4160 | ␉␉␉␉bzero(fadt_mod, 0x74);␊ |
4161 | ␉␉␉␉memcpy(fadt_mod, fadt, fadt->Header.Length);␊ |
4162 | ␉␉␉␉fadt_mod->Header.Length = 0x74;␊ |
4163 | ␉␉␉␉fadt_mod->Header.Revision = 0x01; ␊ |
4164 | ␉␉␉␉verbose("Warning: ACPI FADT length was < 0x74 which is the minimum for the ACPI FADT V1 specification, \n", fadt->Header.Revision );␊ |
4165 | ␉␉␉␉verbose(" trying to convert it to Version 1. \n");␉␉␉␉␊ |
4166 | ␊ |
4167 | ␉␉␉} ␊ |
4168 | ␉␉␉else␊ |
4169 | ␉␉␉{␊ |
4170 | ␉␉␉␉fadt_mod=(ACPI_TABLE_FADT *)AllocateKernelMemory(fadt->Header.Length);␊ |
4171 | ␉␉␉␉if (!fadt_mod) ␊ |
4172 | ␉␉␉␉{␊ |
4173 | ␉␉␉␉␉printf("Unable to allocate kernel memory for fadt mod\n");␊ |
4174 | ␉␉␉␉␉return (void*)0ul;␊ |
4175 | ␉␉␉␉}␊ |
4176 | ␉␉␉␉memcpy(fadt_mod, fadt, fadt->Header.Length);␊ |
4177 | ␉␉␉}␊ |
4178 | ␉␉}␉␉ ␉␉␊ |
4179 | ␉}␊ |
4180 | ␉bool intelfadtspec = true;␊ |
4181 | ␉U8 Type = PMProfileError;␊ |
4182 | ␉// Determine system type / PM_Model␊ |
4183 | ␉␊ |
4184 | ␉// Fix System-type if needed (should never happen)␊ |
4185 | ␉if (Platform.Type > MaxSupportedPMProfile) ␊ |
4186 | ␉{␊ |
4187 | ␉␉if(fadt_mod->PreferredProfile <= MaxSupportedPMProfile)␊ |
4188 | Platform.Type = fadt_mod->PreferredProfile;// get the fadt if correct␊ |
4189 | ␉␉else ␊ |
4190 | ␉␉␉Platform.Type = 1;␉␉/* Set a fixed value (Desktop) */␊ |
4191 | ␉}␊ |
4192 | ␉␊ |
4193 | ␉// If needed, set System-type from PM_Profile (if valid) else set PM_Profile with a fixed the System-type ␊ |
4194 | ␉// Give prior to the FADT pm profile, allow to also control this value with a patched FADT table␊ |
4195 | ␉if (fadt_mod->PreferredProfile != Platform.Type) ␊ |
4196 | ␉{␊ |
4197 | ␉␉bool val = false; ␊ |
4198 | ␉␉getBoolForKey("PreferInternalProfileDetect", &val, &bootInfo->chameleonConfig); // if true Give prior to the profile resolved trought the CPU model␊ |
4199 | ␉␉␊ |
4200 | ␉␉//val = get_env(envIsServer) ;␊ |
4201 | ␉␉␊ |
4202 | ␉␉if (fadt_mod->PreferredProfile <= MaxSupportedPMProfile && !val)␊ |
4203 | ␉␉{␊ |
4204 | ␉␉␉Platform.Type = fadt_mod->PreferredProfile;␊ |
4205 | ␉␉} ␊ |
4206 | ␉␉else␊ |
4207 | ␉␉{␊ |
4208 | ␉␉␉fadt_mod->PreferredProfile = (U8)Platform.Type;␊ |
4209 | ␉␉}␉␉␊ |
4210 | ␉␉␊ |
4211 | ␉}␊ |
4212 | ␉␊ |
4213 | ␉// Set PM_Profile and System-type if user wanted this value to be forced␊ |
4214 | ␉if ( (value=getStringForKey("SystemType", &bootInfo->chameleonConfig))!=NULL)␊ |
4215 | ␉{␊ |
4216 | ␉␉if ((Type = (unsigned char) strtoul(value, NULL, 10) ) <= MaxSupportedPMProfile)␊ |
4217 | ␉␉{␊ |
4218 | ␉␉␉if (fadt_mod->PreferredProfile != Type)␊ |
4219 | ␉␉␉{␊ |
4220 | ␉␉␉␉verbose("FADT: changing Preferred_PM_Profile from %d to %d\n", fadt->PreferredProfile, Type);␊ |
4221 | ␉␉␉␉␊ |
4222 | ␉␉␉␉Platform.Type = (fadt_mod->PreferredProfile = Type);␊ |
4223 | ␉␉␉} ␊ |
4224 | ␉␉␉else␊ |
4225 | ␉␉␉{␊ |
4226 | ␉␉␉␉DBG("FADT: Preferred_PM_Profile was already set to %d, no need to be changed\n",Type);␊ |
4227 | ␉␉␉}␊ |
4228 | ␉␉␉␊ |
4229 | ␉␉} else printf("Error: system-type must be 0..6. Defaulting to %d !\n", (U8)Platform.Type);␊ |
4230 | ␉}␉␉␊ |
4231 | ␉␊ |
4232 | ␉getBoolForKey(KIntelFADT, &intelfadtspec, &bootInfo->chameleonConfig);␊ |
4233 | ␉if ((pmbase == 0) && (cpu_map_error == 0) && (intelfadtspec == true)) ␊ |
4234 | ␉{␊ |
4235 | ␉␉ACPI_TABLE_DSDT *DsdtPointer ;␊ |
4236 | ␉␉if (new_dsdt != (void*)0ul) ␊ |
4237 | ␉␉␉DsdtPointer = new_dsdt;␊ |
4238 | ␉␉else if ((fadt_mod->Header.Revision >= 3) && (fadt_mod->XDsdt != 0ul))␊ |
4239 | ␉␉␉DsdtPointer = (ACPI_TABLE_DSDT *)((U32)fadt_mod->XDsdt);␊ |
4240 | ␉␉else␊ |
4241 | ␉␉␉DsdtPointer = (ACPI_TABLE_DSDT *)fadt_mod->Dsdt;␊ |
4242 | ␉␉␊ |
4243 | ␉␉generate_cpu_map_from_acpi(DsdtPointer);␊ |
4244 | ␉}␉␊ |
4245 | ␉␊ |
4246 | ␉// Patch DSDT Address if we have loaded a DSDT table␊ |
4247 | ␉if(new_dsdt != (void*)0ul)␉␉␊ |
4248 | ␉␉fadt_mod->Dsdt=(U32)new_dsdt;␉␊ |
4249 | ␉␊ |
4250 | ␉fadt_mod->Facs= fadt->Facs;␊ |
4251 | ␉//fadt_mod->Facs=(U32)generate_facs(false);␊ |
4252 | ␊ |
4253 | ␉// Patch FADT to fix restart␊ |
4254 | ␉if (fadt_mod->Header.Revision >= 2 && fix_restart)␊ |
4255 | ␉{␉␉␊ |
4256 | fadt_mod->Flags|= 0x400;␉␉␊ |
4257 | ␉␉␊ |
4258 | ␉␉int type = PCI_RESET_TYPE;␊ |
4259 | ␉␉getIntForKey(KResetType, &type, &bootInfo->chameleonConfig);␊ |
4260 | ␉␉if (type == KEYBOARD_RESET_TYPE)␊ |
4261 | ␉␉{␊ |
4262 | ␉␉␉//Azi: keyboard reset; http://forum.voodooprojects.org/index.php/topic,1056.msg9802.html#msg9802␊ |
4263 | ␉␉␉fadt_mod->ResetRegister = FillGASStruct(0x64, 1);␊ |
4264 | ␉␉␉fadt_mod->ResetValue = 0xfe;␊ |
4265 | ␉␉} ␊ |
4266 | ␉␉else␊ |
4267 | ␉␉{␊ |
4268 | ␉␉␉fadt_mod->ResetRegister = FillGASStruct(0x0cf9, 1);␊ |
4269 | ␉␉␉fadt_mod->ResetValue = 0x06;␊ |
4270 | ␉␉}␊ |
4271 | ␉␉verbose("FADT: Restart Fix applied (Type : %s) !\n", (type == 0) ? "PCI": "KEYBOARD");␊ |
4272 | ␉}␊ |
4273 | ␊ |
4274 | if (fadt_mod->Header.Revision >= 3)␊ |
4275 | ␉{ ␊ |
4276 | ␊ |
4277 | ␊ |
4278 | if (UpdateFADT)␊ |
4279 | ␉␉{ ␊ |
4280 | ␊ |
4281 | ␉␉␉//fadt_mod->XFacs= (U64)((U32)generate_facs(true));␊ |
4282 | fadt_mod->XFacs=(U64)fadt->Facs; ␊ |
4283 | ␊ |
4284 | } ␊ |
4285 | ␉␉else␊ |
4286 | ␉␉{␊ |
4287 | ␉␉␉fadt_mod->XFacs=(U64)fadt->XFacs;␊ |
4288 | ␉␉}␊ |
4289 | ␊ |
4290 | ␊ |
4291 | if(new_dsdt != (void*)0ul)␊ |
4292 | fadt_mod->XDsdt=((U64)(U32)new_dsdt);␊ |
4293 | ␉␉else if (UpdateFADT)␊ |
4294 | fadt_mod->XDsdt=(U64)fadt_mod->Dsdt;␊ |
4295 | ␊ |
4296 | ␊ |
4297 | ␉␉//safe_set_env(envHardwareSignature,((ACPI_TABLE_FACS *)((U32)fadt_mod->XFacs))->HardwareSignature);␊ |
4298 | ␊ |
4299 | ␊ |
4300 | }␊ |
4301 | #if 0␊ |
4302 | ␉else␊ |
4303 | ␉{␊ |
4304 | ␊ |
4305 | ␉␉safe_set_env(envHardwareSignature,((ACPI_TABLE_FACS *)fadt_mod->Facs)->HardwareSignature);␊ |
4306 | ␊ |
4307 | } ␊ |
4308 | ␉␊ |
4309 | ␊ |
4310 | ␉DBG("setting hardware_signature to %x \n",(U32)get_env(envHardwareSignature)); ␊ |
4311 | #endif␊ |
4312 | ␊ |
4313 | ␊ |
4314 | ␊ |
4315 | ␉if (pmbase && (intelfadtspec == true))␊ |
4316 | ␉␉ProcessFadt(fadt_mod, pmbase); // The checksum correction will be done by ProcessFadt␊ |
4317 | ␉else␊ |
4318 | ␉␉SetChecksum(&fadt_mod->Header); // Correct the checksum␊ |
4319 | ␊ |
4320 | ␉return fadt_mod;␊ |
4321 | }␊ |
4322 | ␊ |
4323 | static U32 process_xsdt (ACPI_TABLE_RSDP *rsdp_mod , U32 *new_table_list)␊ |
4324 | {␊ |
4325 | ␉TagPtr DropTables_p = 0; ␊ |
4326 | int DropTables_tag_count = 0;␊ |
4327 | ␊ |
4328 | if (bootInfo->chameleonConfig.dictionary) ␊ |
4329 | {␊ |
4330 | DropTables_p = XMLCastDict(XMLGetProperty(bootInfo->chameleonConfig.dictionary, (const char*)"ACPIDropTables"));␊ |
4331 | if (DropTables_p) DropTables_tag_count = XMLTagCount(DropTables_p) ;␊ |
4332 | } ␊ |
4333 | ␊ |
4334 | ␉U32 new_table = 0ul;␊ |
4335 | ␉U8 new_table_index = 0, table_added = 0;␊ |
4336 | ␉ACPI_TABLE_XSDT *xsdt = (void*)0ul, *xsdt_mod = (void*)0ul;␊ |
4337 | ␉ACPI_TABLE_RSDT *rsdt_conv␉= (void *)0ul;␊ |
4338 | ␉␊ |
4339 | ␉// FIXME: handle 64-bit address correctly␊ |
4340 | ␉␊ |
4341 | ␉xsdt=(ACPI_TABLE_XSDT *)acpi_tables.XsdtPointer;␊ |
4342 | ␉␊ |
4343 | ␉verbose("* Processing XSDT: \n");␊ |
4344 | ␉␊ |
4345 | ␉DBG(" XSDT @%x, Length=%d\n", (U32)xsdt,␊ |
4346 | ␉␉xsdt->Header.Length);␊ |
4347 | ␉␊ |
4348 | ␉if (xsdt != (void *)0ul)␊ |
4349 | ␉{␉␉␉␉␊ |
4350 | ␉␉U32 dropoffset=0, index;␊ |
4351 | ␉␉table_added = 0;␊ |
4352 | ␉␉␊ |
4353 | ␉␉xsdt_mod=(ACPI_TABLE_XSDT *)AllocateKernelMemory(xsdt->Header.Length);␊ |
4354 | ␉␉if (!xsdt_mod) ␊ |
4355 | ␉␉{␊ |
4356 | ␉␉␉printf("Unable to allocate kernel memory for xsdt mod\n");␊ |
4357 | ␉␉␉return (0);␊ |
4358 | ␉␉}␊ |
4359 | ␉␉bzero(xsdt_mod, xsdt->Header.Length);␊ |
4360 | ␉␉memcpy(&xsdt_mod->Header, &xsdt->Header, sizeof(ACPI_TABLE_HEADER));␊ |
4361 | ␉␉␊ |
4362 | ␉␉U32 num_tables=get_num_tables64(xsdt);␊ |
4363 | ␉␉␊ |
4364 | ␉␉for (index = 0; index < num_tables; index++)␊ |
4365 | ␉␉{␊ |
4366 | ␉␉␉␊ |
4367 | ␉␉␉U64 ptr = xsdt->TableOffsetEntry[index];␊ |
4368 | ␉␉␉␊ |
4369 | ␉␉␉{␉␉␉␉␊ |
4370 | ␉␉␉␉if (ptr > ULONG_MAX)␊ |
4371 | ␉␉␉␉{␊ |
4372 | #if DEBUG_ACPI␉␉␉␉␉␉␊ |
4373 | ␉␉␉␉␉printf("Warning xsdt->TableOffsetEntry[%d]: Beyond addressable memory in this CPU mode, ignored !!!\n",index);␊ |
4374 | #endif␊ |
4375 | ␉␉␉␉␉continue;␉␊ |
4376 | ␉␉␉␉}␊ |
4377 | ␉␉␉␉␊ |
4378 | ␉␉␉␉int method = 0;␊ |
4379 | ␉␉␉␉getIntForKey(kAcpiMethod, &method, &bootInfo->chameleonConfig);␊ |
4380 | ␉␉␉␉␊ |
4381 | ␉␉␉␉␊ |
4382 | ␉␉␉␉if (method != 0x2)␊ |
4383 | ␉␉␉␉{␊ |
4384 | ␉␉␉␉␉if (GetChecksum(((ACPI_TABLE_HEADER *) (unsigned long)ptr), ␊ |
4385 | ␉␉␉␉␉␉␉␉␉((ACPI_TABLE_HEADER *) (unsigned long)ptr)->Length) != 0)␊ |
4386 | ␉␉␉␉␉{␊ |
4387 | #if DEBUG_ACPI␉␉␉␉␉␉␊ |
4388 | ␉␉␉␉␉␉printf("Warning xsdt->TableOffsetEntry[%d]: Invalide checksum, ignored !!!\n",index);␊ |
4389 | #endif␊ |
4390 | ␉␉␉␉␉␉continue;␊ |
4391 | ␉␉␉␉␉}␊ |
4392 | ␉␉␉␉}␊ |
4393 | ␊ |
4394 | ␉␉␉}␊ |
4395 | ␉␉␉␊ |
4396 | ␉␉␉xsdt_mod->TableOffsetEntry[index-dropoffset]=ptr;␊ |
4397 | ␉␉␉␊ |
4398 | ␉␉␉char tableSig[5];␊ |
4399 | ␉␉␉strlcpy(tableSig, (char*)((U32)ptr), sizeof(tableSig));␊ |
4400 | ␊ |
4401 | ␉␉␉DBG("** Processing %s,", tableSig );␊ |
4402 | ␉␉␉␊ |
4403 | ␉␉␉DBG(" @%x, Length=%d\n", (U32)ptr,␊ |
4404 | ␉␉␉␉((ACPI_TABLE_HEADER *) (unsigned long)ptr)->Length);␊ |
4405 | ␉␉␉␊ |
4406 | ␉␉␉{␊ |
4407 | ␉␉␉␉bool oem = false;␊ |
4408 | ␉␉␉␉char oemOption[OEMOPT_SIZE];␊ |
4409 | ␉␉␉␉sprintf(oemOption, "oem%s",tableSig );␊ |
4410 | ␉␉␉␉if (getBoolForKey(oemOption, &oem, &bootInfo->chameleonConfig) && oem) // This method don't work for DSDT and FACS␊ |
4411 | ␉␉␉␉{ ␊ |
4412 | ␉␉␉␉␉␊ |
4413 | ␉␉␉␉␉DBG(" %s required\n", oemOption);␊ |
4414 | ␉␉␉␉␉␊ |
4415 | ␉␉␉␉␉if (get_new_table_in_list(new_table_list,(*(U32 *) ((ACPI_TABLE_HEADER *) (unsigned long)ptr)->Signature), &new_table_index) != (void*)0ul) ␊ |
4416 | ␉␉␉␉␉␉new_table_list[new_table_index] = 0ul; // This way new table will not be added to the new rsdt list !!␊ |
4417 | ␉␉␉␉␉␊ |
4418 | ␉␉␉␉␉continue;␊ |
4419 | ␉␉␉␉}␊ |
4420 | ␉␉␉}␊ |
4421 | ␉␉␉␊ |
4422 | if ((DropTables_tag_count > 0) && DropTables_p) ␊ |
4423 | ␉␉␉{␊ |
4424 | ␉␉␉␉TagPtr match_drop = XMLGetProperty(DropTables_p, (const char*)tableSig); ␊ |
4425 | ␉␉␉␉if ( match_drop ) ␊ |
4426 | ␉␉␉␉{␊ |
4427 | ␉␉␉␉␉char *tmp = XMLCastString(match_drop);␊ |
4428 | ␉␉␉␉␉if (tmp && (strcmp(tmp,"No") != 0))␊ |
4429 | ␉␉␉␉␉{␊ |
4430 | ␉␉␉␉␉␉dropoffset++;␊ |
4431 | ␉␉␉␉␉␉DBG(" %s table dropped\n",tableSig);␊ |
4432 | ␉␉␉␉␉␉continue;␊ |
4433 | ␉␉␉␉␉}␊ |
4434 | ␉␉␉␉}␉␉␉␊ |
4435 | ␉␉␉}␊ |
4436 | ␉␉␉␊ |
4437 | ␉␉␉{␊ |
4438 | ␉␉␉␉if ((new_table = (U32)get_new_table_in_list(new_table_list,(*(U32 *) ((ACPI_TABLE_HEADER *) (unsigned long)ptr)->Signature), &new_table_index)) != 0ul)␊ |
4439 | ␉␉␉␉{␊ |
4440 | ␉␉␉␉␉DBG(" Found replacement for table %s\n",tableSig);␊ |
4441 | ␉␉␉␉␉xsdt_mod->TableOffsetEntry[index-dropoffset]=(U64)new_table;␊ |
4442 | ␉␉␉␉␉new_table_list[new_table_index] = 0ul; // table replaced !!␊ |
4443 | ␉␉␉␉␉continue;␊ |
4444 | ␉␉␉␉}␊ |
4445 | ␉␉␉}␉␉␉␉␉␉␉␊ |
4446 | ␊ |
4447 | ␉␉} ␊ |
4448 | ␉␉␊ |
4449 | ␉␉␊ |
4450 | ␉␉{␊ |
4451 | ␉␉␉U8 i;␊ |
4452 | ␉␉␉for (i = 0; i< (MAX_ACPI_TABLE + RESERVED_AERA); i++)␊ |
4453 | ␉␉␉{␊ |
4454 | ␉␉␉␉if (new_table_list[i] != 0ul)␊ |
4455 | ␉␉␉␉{␊ |
4456 | #if DEBUG_ACPI␊ |
4457 | ␉␉␉␉␉ACPI_TABLE_HEADER **table_array = (ACPI_TABLE_HEADER **) new_table_list;␊ |
4458 | ␉␉␉␉␉printf("Adding table : ");␊ |
4459 | ␉␉␉␉␉print_nameseg(*(U32 *) (table_array[i]->Signature));␊ |
4460 | ␉␉␉␉␉printf("\n");␉␉␉␉␉␊ |
4461 | #endif␊ |
4462 | ␉␉␉␉␉xsdt_mod->TableOffsetEntry[index-dropoffset]=(U64)new_table_list[i];␊ |
4463 | ␉␉␉␉␉table_added++;␊ |
4464 | ␉␉␉␉␉index++;␊ |
4465 | ␉␉␉␉}␊ |
4466 | ␉␉␉}␊ |
4467 | ␉␉}␊ |
4468 | ␉␉␊ |
4469 | ␉␉// Correct the checksum of XSDT␊ |
4470 | ␉␉xsdt_mod->Header.Length-=8*dropoffset;␊ |
4471 | ␉␉xsdt_mod->Header.Length+=8*table_added;␊ |
4472 | ␉␉␊ |
4473 | ␉␉SetChecksum(&xsdt_mod->Header);␊ |
4474 | ␉␉␊ |
4475 | ␉␉update_rsdp_with_xsdt(rsdp_mod, xsdt_mod);␊ |
4476 | ␉␉␊ |
4477 | ␉␉verbose("* Creating new RSDT from XSDT table\n");␊ |
4478 | ␉␉␊ |
4479 | ␉␉rsdt_conv = (ACPI_TABLE_RSDT *)gen_alloc_rsdt_from_xsdt(xsdt_mod);␊ |
4480 | ␉␉␊ |
4481 | ␉␉if (rsdt_conv != (void*)0ul)␊ |
4482 | ␉␉{␊ |
4483 | #if DEBUG_ACPI␊ |
4484 | ␉␉␉DBG("Attempting to update RSDP with RSDT \n");␊ |
4485 | ␉␉␉{␊ |
4486 | ␉␉␉␉U32 ret = update_rsdp_with_rsdt(rsdp_mod, rsdt_conv);␊ |
4487 | ␉␉␉␉if (ret)␊ |
4488 | ␉␉␉␉␉DBG("RSDP update with RSDT successfully !!! \n");␊ |
4489 | ␉␉␉}␊ |
4490 | #else␊ |
4491 | ␉␉␉update_rsdp_with_rsdt(rsdp_mod, rsdt_conv);␊ |
4492 | #endif␊ |
4493 | ␉␉}␉␉␊ |
4494 | ␉␉␊ |
4495 | ␉}␊ |
4496 | ␉else␊ |
4497 | ␉{␉␉␉␉␊ |
4498 | ␉␉DBG("About to drop XSDT\n");␊ |
4499 | ␉␉␊ |
4500 | ␉␉/*FIXME: Now we just hope that if MacOS doesn't find XSDT it reverts to RSDT. ␊ |
4501 | ␉␉ * A Better strategy would be to generate␊ |
4502 | ␉␉ */␊ |
4503 | ␉␉␊ |
4504 | ␉␉rsdp_mod->XsdtPhysicalAddress=0xffffffffffffffffLL;␊ |
4505 | ␉␉verbose("XSDT not found or XSDT incorrect\n");␊ |
4506 | ␉}␊ |
4507 | ␉return (1);␊ |
4508 | ␊ |
4509 | }␊ |
4510 | ␊ |
4511 | static U32 process_rsdt(ACPI_TABLE_RSDP *rsdp_mod , bool gen_xsdt, U32 *new_table_list)␊ |
4512 | {␉␉␉␊ |
4513 | ␉TagPtr DropTables_p = 0; ␊ |
4514 | int DropTables_tag_count = 0;␊ |
4515 | ␊ |
4516 | if (bootInfo->chameleonConfig.dictionary) ␊ |
4517 | {␊ |
4518 | DropTables_p = XMLCastDict(XMLGetProperty(bootInfo->chameleonConfig.dictionary, (const char*)"ACPIDropTables"));␊ |
4519 | if (DropTables_p) DropTables_tag_count = XMLTagCount(DropTables_p) ;␊ |
4520 | } ␊ |
4521 | ␊ |
4522 | ␉U32 new_table = 0ul;␊ |
4523 | ␉U8 new_table_index = 0, table_added = 0;␊ |
4524 | ␉U32 dropoffset=0, index;␊ |
4525 | ␉ACPI_TABLE_RSDT *rsdt␉␉ = (void *)0ul, *rsdt_mod␉= (void *)0ul;␊ |
4526 | ␉ACPI_TABLE_XSDT *xsdt_conv␉ = (void *)0ul;␊ |
4527 | ␉␊ |
4528 | ␉rsdt=(ACPI_TABLE_RSDT *)acpi_tables.RsdtPointer;␊ |
4529 | ␊ |
4530 | ␉rsdt_mod=(ACPI_TABLE_RSDT *)AllocateKernelMemory(rsdt->Header.Length);␊ |
4531 | ␉␊ |
4532 | ␉if (!rsdt_mod) ␊ |
4533 | ␉{␊ |
4534 | ␉␉printf("Unable to allocate kernel memory for rsdt mod\n");␊ |
4535 | ␉␉return (0);␊ |
4536 | ␉}␊ |
4537 | ␉␊ |
4538 | ␉bzero(rsdt_mod, rsdt->Header.Length);␊ |
4539 | ␉memcpy (&rsdt_mod->Header, &rsdt->Header, sizeof(ACPI_TABLE_HEADER));␊ |
4540 | ␉␊ |
4541 | // Compute number of table pointers included in RSDT␊ |
4542 | ␉U32 num_tables = get_num_tables(rsdt); ␊ |
4543 | ␉␊ |
4544 | ␉verbose("* Processing RSDT: \n");␊ |
4545 | ␉␊ |
4546 | ␉DBG(" RSDT @%x, Length %d\n",rsdt, rsdt->Header.Length);␊ |
4547 | ␉␊ |
4548 | ␉ACPI_TABLE_HEADER **table_array = (ACPI_TABLE_HEADER **) rsdt->TableOffsetEntry;␊ |
4549 | ␉␊ |
4550 | ␉for (index = 0; index < num_tables; index++)␊ |
4551 | ␉{␊ |
4552 | ␊ |
4553 | ␉␉{␉␉␉␊ |
4554 | ␉␉␉␊ |
4555 | ␉␉␉int method = 0;␊ |
4556 | ␉␉␉getIntForKey(kAcpiMethod, &method, &bootInfo->chameleonConfig);␊ |
4557 | ␉␉␉␊ |
4558 | ␉␉␉␊ |
4559 | ␉␉␉if (method != 0x2)␊ |
4560 | ␉␉␉{␊ |
4561 | ␉␉␉␉if (GetChecksum(table_array[index], table_array[index]->Length) != 0)␊ |
4562 | ␉␉␉␉{␊ |
4563 | #if DEBUG_ACPI␉␉␉␉␉␉␊ |
4564 | ␉␉␉␉␉printf("Warning rsdt->TableOffsetEntry[%d]: Invalide checksum, ignored !!!\n",index);␊ |
4565 | #endif␊ |
4566 | ␉␉␉␉␉continue;␊ |
4567 | ␉␉␉␉}␊ |
4568 | ␉␉␉}␉␉␉␊ |
4569 | ␉␉␉␊ |
4570 | ␉␉}␊ |
4571 | ␉␉␊ |
4572 | ␉␉rsdt_mod->TableOffsetEntry[index-dropoffset]=rsdt->TableOffsetEntry[index];␊ |
4573 | ␉␉␉␉␊ |
4574 | ␉␉char tableSig[5];␊ |
4575 | ␉␉strlcpy(tableSig, (char*)(rsdt->TableOffsetEntry[index]), sizeof(tableSig));␊ |
4576 | ␉␉␊ |
4577 | ␉␉DBG("** Processing %s,", tableSig );␊ |
4578 | ␉␉␊ |
4579 | ␉␉DBG(" @%x, Length=%d\n", (U32)table_array[index],␊ |
4580 | ␉␉␉table_array[index]->Length);␊ |
4581 | ␉␉␊ |
4582 | ␉␉{␊ |
4583 | ␉␉␉bool oem = false;␊ |
4584 | ␉␉␉char oemOption[OEMOPT_SIZE];␊ |
4585 | ␉␉␉sprintf(oemOption, "oem%s",tableSig );␊ |
4586 | ␉␉␉if (getBoolForKey(oemOption, &oem, &bootInfo->chameleonConfig) && oem) // This method don't work for DSDT and FACS␊ |
4587 | ␉␉␉{ ␊ |
4588 | ␉␉␉␉DBG(" %s required\n", oemOption);␊ |
4589 | ␉␉␉␉␊ |
4590 | ␉␉␉␉if (get_new_table_in_list(new_table_list,(*(U32 *) (table_array[index]->Signature)), &new_table_index) != (void*)0ul ) ␊ |
4591 | ␉␉␉␉␉new_table_list[new_table_index] = 0ul; // This way new table will not be added to the new rsdt list !!␊ |
4592 | ␉␉␉␉␊ |
4593 | ␉␉␉␉continue;␊ |
4594 | ␉␉␉}␊ |
4595 | ␉␉}␊ |
4596 | ␊ |
4597 | if ((DropTables_tag_count > 0) && DropTables_p)␊ |
4598 | ␉␉{␊ |
4599 | ␉␉␉TagPtr match_drop = XMLGetProperty(DropTables_p, (const char*)tableSig);␊ |
4600 | ␉␉␉if ( match_drop )␊ |
4601 | ␉␉␉{␊ |
4602 | ␉␉␉␉char *tmp = XMLCastString(match_drop);␊ |
4603 | ␉␉␉␉if (strcmp(tmp,"No") != 0)␊ |
4604 | ␉␉␉␉{␉␉␉␉␉␉␊ |
4605 | ␉␉␉␉␉dropoffset++;␊ |
4606 | ␉␉␉␉␉DBG(" %s table dropped\n",tableSig);␊ |
4607 | ␉␉␉␉␉continue;␊ |
4608 | ␉␉␉␉}␊ |
4609 | ␉␉␉}␊ |
4610 | ␉␉}␊ |
4611 | ␉␉␊ |
4612 | ␉␉{␊ |
4613 | ␉␉␉if ((new_table = (U32)get_new_table_in_list(new_table_list,(*(U32 *) (table_array[index]->Signature)), &new_table_index)) != 0ul)␊ |
4614 | ␉␉␉{␉␉␉␊ |
4615 | ␉␉␉␉DBG(" Found replacement for table %s\n",tableSig);␊ |
4616 | ␉␉␉␉␊ |
4617 | ␉␉␉␉rsdt_mod->TableOffsetEntry[index-dropoffset]=new_table;␊ |
4618 | ␉␉␉␉new_table_list[new_table_index] = 0ul; // table replaced !!␊ |
4619 | ␉␉␉␉continue;␊ |
4620 | ␉␉␉}␊ |
4621 | ␉␉}␉␉␉␊ |
4622 | ␉␉␊ |
4623 | ␉}␉␉␉␊ |
4624 | ␉DBG("\n");␊ |
4625 | ␉␊ |
4626 | ␉{␊ |
4627 | ␉␉U8 i;␊ |
4628 | ␉␉for (i = 0; i< (MAX_ACPI_TABLE + RESERVED_AERA); i++)␊ |
4629 | ␉␉{␊ |
4630 | ␉␉␉if (new_table_list[i] != 0ul)␊ |
4631 | ␉␉␉{␊ |
4632 | #if DEBUG_ACPI␊ |
4633 | ␉␉␉␉ACPI_TABLE_HEADER **table_array = (ACPI_TABLE_HEADER **) new_table_list;␊ |
4634 | ␉␉␉␉printf("Adding table : ");␊ |
4635 | ␉␉␉␉print_nameseg(*(U32 *) (table_array[i]->Signature));␊ |
4636 | ␉␉␉␉printf("\n");␉␉␉␉␊ |
4637 | #endif␊ |
4638 | ␉␉␉␉rsdt_mod->TableOffsetEntry[index-dropoffset]=new_table_list[i];␊ |
4639 | ␉␉␉␉table_added++;␊ |
4640 | ␉␉␉␉index++;␊ |
4641 | ␉␉␉}␊ |
4642 | ␉␉}␊ |
4643 | ␉}␉␉␊ |
4644 | ␉␊ |
4645 | ␉// Correct the checksum of RSDT␊ |
4646 | ␉rsdt_mod->Header.Length-=4*dropoffset;␊ |
4647 | ␉rsdt_mod->Header.Length+=4*table_added;␉␉␊ |
4648 | ␉␊ |
4649 | ␉DBG("RSDT: Original checksum %d\n", rsdt_mod->Header.Checksum);␉␉␉␊ |
4650 | ␉␊ |
4651 | ␉SetChecksum(&rsdt_mod->Header);␊ |
4652 | ␉␊ |
4653 | ␉DBG("New checksum %d at %x\n", rsdt_mod->Header.Checksum,rsdt_mod);␊ |
4654 | ␉␊ |
4655 | ␉update_rsdp_with_rsdt(rsdp_mod, rsdt_mod);␊ |
4656 | ␉␊ |
4657 | ␉if (gen_xsdt)␊ |
4658 | ␉{␊ |
4659 | ␉␉verbose("* Creating new XSDT from RSDT table\n");␊ |
4660 | ␉␉xsdt_conv = (ACPI_TABLE_XSDT *)gen_alloc_xsdt_from_rsdt(rsdt_mod);␊ |
4661 | ␉␉␊ |
4662 | ␉␉if (xsdt_conv != (void *)0ul )␊ |
4663 | ␉␉{␊ |
4664 | #if DEBUG_ACPI␊ |
4665 | ␉␉␉DBG("Attempting to update RSDP with XSDT \n");␊ |
4666 | ␉␉␉{␊ |
4667 | ␉␉␉␉U32 ret = update_rsdp_with_xsdt(rsdp_mod, xsdt_conv);␊ |
4668 | ␉␉␉␉if (ret)␊ |
4669 | ␉␉␉␉␉DBG("RSDP update with XSDT successfully !!! \n");␊ |
4670 | ␉␉␉}␊ |
4671 | #else␊ |
4672 | ␉␉␉update_rsdp_with_xsdt(rsdp_mod, xsdt_conv);␊ |
4673 | #endif␊ |
4674 | ␊ |
4675 | ␉␉}␊ |
4676 | ␉␉␊ |
4677 | ␉}␉␊ |
4678 | ␉return (1);␊ |
4679 | }␊ |
4680 | ␊ |
4681 | EFI_STATUS setup_Acpi(void)␊ |
4682 | {␉␊ |
4683 | ␉U8 Revision = 0;␊ |
4684 | ␉␊ |
4685 | cpu_map_error = 0;␊ |
4686 | cpu_map_count = 0;␊ |
4687 | pmbase = 0;␊ |
4688 | ␊ |
4689 | EFI_STATUS Status = EFI_ABORTED;␊ |
4690 | ␉␊ |
4691 | ␉U32 new_table_list[MAX_ACPI_TABLE + RESERVED_AERA]; //max table + reserved aera ␊ |
4692 | ␉U8 new_table_index = 0;␊ |
4693 | ␉␊ |
4694 | ␉ACPI_TABLE_DSDT* DsdtPtr␉ = (void *)0ul; // a Pointer to the dsdt table present in fadt_mod␊ |
4695 | ␉␊ |
4696 | ␉ACPI_TABLE_DSDT *new_dsdt␉ = (void *)0ul;␉// a Pointer to the dsdt file␉␊ |
4697 | ␉ACPI_TABLE_FADT *fadt_mod␉ = (void *)0ul; // a Pointer to the patched FACP table␊ |
4698 | ␉ACPI_TABLE_FADT *fadt_file␉ = (void *)0ul; // a Pointer to the (non-patched) fadt file ␊ |
4699 | ␉ACPI_TABLE_FADT *FacpPointer = (void *)0ul; // a Pointer to the non-patched FACP table, it can be a file or the FACP table found in the RSDT/XSDT␊ |
4700 | ␉ACPI_TABLE_RSDP *rsdp_mod␉ = (void *)0ul, *rsdp_conv␉= (void *)0ul;␊ |
4701 | ␊ |
4702 | ␉U32 rsdplength;␊ |
4703 | ␉␊ |
4704 | ␉bool update_acpi=false, gen_xsdt=false;␊ |
4705 | ␉␊ |
4706 | ␉bool gen_csta=false, gen_psta=false, speed_step=false;␊ |
4707 | ␉bool gen_ssdt=false; // will force to generate ssdt even if gen_csta and gen_psta = false␊ |
4708 | bool gen_tsta=false;␊ |
4709 | ␉bool oem_dsdt=false, oem_fadt=false;␊ |
4710 | ␉␊ |
4711 | ␉// Find original rsdp ␊ |
4712 | ␉if (!FindAcpiTables(&acpi_tables))␊ |
4713 | ␉{␊ |
4714 | ␉␉printf("Error: AcpiCodec Failed to detect ACPI tables.\n");␊ |
4715 | ␉␉getchar();␊ |
4716 | ␉␉return EFI_NOT_FOUND;␊ |
4717 | ␉} ␊ |
4718 | ␊ |
4719 | ␉{␊ |
4720 | ␉␉U8 i;␊ |
4721 | ␉␉␊ |
4722 | ␉␉for (i=0; i<(MAX_ACPI_TABLE + RESERVED_AERA); i++)␊ |
4723 | ␉␉{␊ |
4724 | ␉␉␉new_table_list[i] = 0ul;␊ |
4725 | ␉␉}␊ |
4726 | ␉␉bool tmpval;␊ |
4727 | ␉␉␊ |
4728 | ␉␉oem_dsdt=getBoolForKey(kOEMDSDT, &tmpval, &bootInfo->chameleonConfig)&&tmpval;␊ |
4729 | ␉␉oem_fadt=getBoolForKey(kOEMFADT, &tmpval, &bootInfo->chameleonConfig)&&tmpval;␊ |
4730 | ␊ |
4731 | ␉␉gen_csta=getBoolForKey(kGenerateCStates, &tmpval, &bootInfo->chameleonConfig)&&tmpval;␊ |
4732 | ␉␉gen_psta=getBoolForKey(kGeneratePStates, &tmpval, &bootInfo->chameleonConfig)&&tmpval;␊ |
4733 | ␉␉gen_ssdt=getBoolForKey(KForceSSDT, &tmpval, &bootInfo->chameleonConfig)&&tmpval;␊ |
4734 | ␉␉update_acpi=getBoolForKey(kUpdateACPI, &tmpval, &bootInfo->chameleonConfig)&&tmpval;␊ |
4735 | ␉␉␊ |
4736 | ␉␉speed_step=getBoolForKey(kSpeedstep, &tmpval, &bootInfo->chameleonConfig)&&tmpval;␊ |
4737 | ␉␉turbo_enabled=(U32)getBoolForKey(kCoreTurbo, &tmpval, &bootInfo->chameleonConfig)&&tmpval;␊ |
4738 | #if BUILD_ACPI_TSS ␊ |
4739 | ␉␉gen_tsta=(U32)getBoolForKey(kGenerateTStates, &tmpval, &bootInfo->chameleonConfig)&&tmpval;␊ |
4740 | #endif␊ |
4741 | ␉␉checkOem=getBoolForKey(kOnlySignedAml, &tmpval, &bootInfo->chameleonConfig)&&tmpval;␊ |
4742 | ␉} ␊ |
4743 | ␊ |
4744 | ␉{␊ |
4745 | long ret, length, flags, time;␊ |
4746 | long long␉ index = 0;␊ |
4747 | const char * name;␊ |
4748 | ␊ |
4749 | ␉␉U8 i = 0;␊ |
4750 | ␉␉char dirspec[512];␊ |
4751 | ␉␉bool acpidir_found = false;␊ |
4752 | ␉␉␊ |
4753 | ␉␉ret = GetFileInfo("rd(0,0)/Extra/", "Acpi", &flags, &time);␊ |
4754 | if ((ret == 0) && ((flags & kFileTypeMask) == kFileTypeDirectory)) ␊ |
4755 | ␉␉{␊ |
4756 | sprintf(dirspec, "rd(0,0)/Extra/Acpi/");␊ |
4757 | acpidir_found = true;␊ |
4758 | ␊ |
4759 | }␊ |
4760 | ␉␉else␊ |
4761 | ␉␉{␊ |
4762 | ␉␉␉␊ |
4763 | ret = GetFileInfo("/Extra/", "Acpi", &flags, &time);␊ |
4764 | if ((ret == 0) && ((flags & kFileTypeMask) == kFileTypeDirectory))␊ |
4765 | ␉␉␉{␊ |
4766 | sprintf(dirspec, "/Extra/Acpi/");␊ |
4767 | acpidir_found = true;␊ |
4768 | ␉␉␉␉␊ |
4769 | }␊ |
4770 | ␉␉␉else␊ |
4771 | ␉␉␉{␊ |
4772 | ret = GetFileInfo("bt(0,0)/Extra/", "Acpi", &flags, &time);␊ |
4773 | if ((ret == 0) && ((flags & kFileTypeMask) == kFileTypeDirectory))␊ |
4774 | ␉␉␉␉{␊ |
4775 | sprintf(dirspec, "bt(0,0)/Extra/Acpi/");␊ |
4776 | acpidir_found = true;␊ |
4777 | ␉␉␉␉␉␊ |
4778 | } ␊ |
4779 | }␊ |
4780 | }␊ |
4781 | ␊ |
4782 | ␉␉if (acpidir_found == true)␊ |
4783 | ␉␉{␊ |
4784 | #if ACPISGN␊ |
4785 | if (checkOem == true)␊ |
4786 | {␊ |
4787 | MakeAcpiSgn();␊ |
4788 | }␊ |
4789 | #endif␊ |
4790 | ␊ |
4791 | while (1) {␊ |
4792 | ret = GetDirEntry(dirspec, &index, &name, &flags, &time);␊ |
4793 | if (ret == -1) break;␊ |
4794 | #if DEBUG_ACPI␊ |
4795 | printf("testing %s\n", name);␊ |
4796 | #endif␊ |
4797 | // Make sure this is a directory.␊ |
4798 | if ((flags & kFileTypeMask) == kFileTypeDirectory) continue;␊ |
4799 | ␊ |
4800 | // Make sure this is a kext.␊ |
4801 | length = strlen(name);␊ |
4802 | if (strcmp(name + length - 4, ".aml"))␊ |
4803 | {␊ |
4804 | #if DEBUG_ACPI␊ |
4805 | printf("Ignoring %s\n", name);␊ |
4806 | #endif␊ |
4807 | continue;␊ |
4808 | }␊ |
4809 | ␊ |
4810 | // Some simple verifications to save time in case of those tables simply named as follow:␊ |
4811 | if ((strncmp(name, "RSDT", 4) == 0) || (strncmp(name, "rsdt", 4) == 0) ||␊ |
4812 | (strncmp(name, "XSDT", 4) == 0) || (strncmp(name, "xsdt", 4) == 0) ||␊ |
4813 | (strncmp(name, "RSDP", 4) == 0) || (strncmp(name, "rsdp", 4) == 0))␊ |
4814 | { ␊ |
4815 | #if DEBUG_ACPI␊ |
4816 | printf("Ignoring %s\n", name);␊ |
4817 | #endif␊ |
4818 | continue;␊ |
4819 | } ␊ |
4820 | ␊ |
4821 | if ((strncmp(name, "FACS", 4) == 0) || (strncmp(name, "facs", 4) == 0)) // FACS is not supported␊ |
4822 | { ␊ |
4823 | #if DEBUG_ACPI␊ |
4824 | printf("Ignoring %s\n", name);␊ |
4825 | #endif␊ |
4826 | continue;␊ |
4827 | }␉␉␉␉␉␊ |
4828 | ␊ |
4829 | DBG("* Attempting to load acpi table: %s\n", name);␉␉␉␊ |
4830 | if ( (new_table_list[i]=(U32)loadACPITable(new_table_list,dirspec,name)))␊ |
4831 | {␊ |
4832 | if (i < MAX_ACPI_TABLE)␊ |
4833 | {␊ |
4834 | i++;␊ |
4835 | } ␊ |
4836 | else␊ |
4837 | {␊ |
4838 | DBG("Max nb of allowed aml files reached, exiting .");␊ |
4839 | break;␊ |
4840 | }␉␉␉␉␉␉␊ |
4841 | }␊ |
4842 | }␊ |
4843 | ␊ |
4844 | if (i)␊ |
4845 | {␊ |
4846 | //sanitize the new tables list ␊ |
4847 | sanitize_new_table_list(new_table_list);␊ |
4848 | ␊ |
4849 | //move to kernel memory ␊ |
4850 | move_table_list_to_kmem(new_table_list);␊ |
4851 | ␊ |
4852 | DBG("New ACPI tables Loaded in memory\n");␊ |
4853 | } ␊ |
4854 | ␉␉␉␊ |
4855 | ␉␉␉␊ |
4856 | ␉␉}␊ |
4857 | ␉␉␊ |
4858 | ␉}␉␉␉␊ |
4859 | #if HARDCODED_DSDT␊ |
4860 | do {␊ |
4861 | #include "dsdt_PRLSACPI.h"␊ |
4862 | ␊ |
4863 | U8 index = 0;␊ |
4864 | ␊ |
4865 | if ((get_new_table_in_list(new_table_list, NAMESEG("DSDT"), &new_table_index)) != (void*)0ul )␊ |
4866 | {␊ |
4867 | index = new_table_index;␊ |
4868 | } ␊ |
4869 | else␊ |
4870 | {␊ |
4871 | U8 empty = get_0ul_index_in_list(new_table_list, false);␊ |
4872 | if (empty != ACPI_TABLE_LIST_FULL_NON_RESERVED)␊ |
4873 | {␊ |
4874 | index = empty; ␊ |
4875 | } ␊ |
4876 | else␊ |
4877 | {␊ |
4878 | printf("Error: not enought reserved space in the new acpi list for the Harcoded DSDT table,\n ");␊ |
4879 | printf(" please increase the RESERVED_AERA\n");␊ |
4880 | ␊ |
4881 | break;␊ |
4882 | }␊ |
4883 | }␊ |
4884 | ␊ |
4885 | ␉␉if (index)␊ |
4886 | ␉␉{␊ |
4887 | ␉␉␉␊ |
4888 | ␉␉␉ACPI_TABLE_DSDT *tmp = (ACPI_TABLE_DSDT *)DsdtAmlCode;␉␉␉␊ |
4889 | ␉␉␉ACPI_TABLE_DSDT *hardcoded_dsdt␉ = (void *)0ul;␉␊ |
4890 | ␉␉␉␊ |
4891 | ␉␉␉hardcoded_dsdt = (ACPI_TABLE_DSDT *)AllocateKernelMemory(tmp->Header.Length);␉␊ |
4892 | ␉␉␉memcpy(hardcoded_dsdt, tmp, tmp->Header.Length);␊ |
4893 | ␉␉␉new_table_list[index] = (U32)hardcoded_dsdt; // add the patched table to the list␊ |
4894 | ␉␉} ␊ |
4895 | ␉␉else␊ |
4896 | ␉␉{␊ |
4897 | ␉␉␉printf("Error: not enought reserved space in the new acpi list for the Harcoded DSDT table,\n ");␊ |
4898 | ␉␉␉printf(" please increase the RESERVED_AERA\n");␊ |
4899 | ␉␉␉␊ |
4900 | ␉␉␉break;␊ |
4901 | ␉␉} ␊ |
4902 | } while (0);␊ |
4903 | #endif␊ |
4904 | ␉if (speed_step)␊ |
4905 | ␉{␊ |
4906 | ␉␉gen_psta= true;␊ |
4907 | ␉␉gen_csta= true;␊ |
4908 | ␉} ␉␉␊ |
4909 | ␊ |
4910 | ␉␊ |
4911 | ␉ACPI_TABLE_RSDP *rsdp=(ACPI_TABLE_RSDP *)acpi_tables.RsdPointer;␊ |
4912 | ␉␊ |
4913 | ␉if (rsdp == (void*)0ul || (GetChecksum(rsdp, (rsdp->Revision == 0) ? ACPI_RSDP_REV0_SIZE:sizeof(ACPI_TABLE_RSDP)) != 0) )␊ |
4914 | ␉{␊ |
4915 | ␉␉printf("Error : ACPI RSD PTR Revision %d checksum is incorrect or table not found \n",rsdp->Revision );␊ |
4916 | ␉␉return EFI_UNSUPPORTED;␊ |
4917 | ␉}␊ |
4918 | ␉␊ |
4919 | ␉if ((update_acpi) && (rsdp->Revision == 0))␊ |
4920 | ␉{␊ |
4921 | ␉␉␊ |
4922 | ␉␉rsdp_conv = (ACPI_TABLE_RSDP *)gen_alloc_rsdp_v2_from_v1(rsdp);␊ |
4923 | ␉␉if (rsdp_conv != (void *)0ul)␊ |
4924 | ␉␉{␊ |
4925 | ␉␉␉gen_xsdt = true; ␊ |
4926 | ␉␉␉rsdp = rsdp_conv;␊ |
4927 | ␉␉␉verbose("Converted ACPI RSD PTR Revision 0 to Revision 2\n");␊ |
4928 | ␉␉}␊ |
4929 | ␉␉␊ |
4930 | ␉}␊ |
4931 | ␉␊ |
4932 | ␉Revision = rsdp->Revision ;␊ |
4933 | ␉rsdplength=(Revision == 2)?rsdp->Length:ACPI_RSDP_REV0_SIZE;␊ |
4934 | ␉␊ |
4935 | ␉DBG("RSDP Revision %d found @%x. Length=%d\n",Revision,rsdp,rsdplength);␊ |
4936 | ␊ |
4937 | ␉if (gen_xsdt)␊ |
4938 | ␉{␊ |
4939 | ␉␉rsdp_mod=rsdp_conv;␊ |
4940 | ␉}␊ |
4941 | ␉else␊ |
4942 | ␉{␊ |
4943 | ␉␉rsdp_mod=(ACPI_TABLE_RSDP *) AllocateKernelMemory(rsdplength);␊ |
4944 | ␉␉␊ |
4945 | ␉␉if (!rsdp_mod) return EFI_OUT_OF_RESOURCES; ␊ |
4946 | ␉␉␊ |
4947 | ␉␉memcpy(rsdp_mod, rsdp, rsdplength);␊ |
4948 | ␉}␉␊ |
4949 | ␉␊ |
4950 | ␊ |
4951 | ␉if ((fadt_file = (ACPI_TABLE_FADT *)get_new_table_in_list(new_table_list, NAMESEG("FACP"), &new_table_index)) != (void *)0ul)␊ |
4952 | ␉{␊ |
4953 | ␉␉␊ |
4954 | ␉␉if (oem_fadt == false)␊ |
4955 | ␉␉␉FacpPointer = (ACPI_TABLE_FADT *)fadt_file;␊ |
4956 | ␉␉␊ |
4957 | ␉␉new_table_list[new_table_index] = 0ul; // This way, the non-patched table will not be added in our new rsdt/xsdt table list␊ |
4958 | ␉␉␊ |
4959 | ␉} else␊ |
4960 | ␉␉FacpPointer = (acpi_tables.FacpPointer64 != (void *)0ul) ? ␊ |
4961 | ␉␉(ACPI_TABLE_FADT *)acpi_tables.FacpPointer64 : (ACPI_TABLE_FADT *)acpi_tables.FacpPointer;␉␉␉␊ |
4962 | ␉␊ |
4963 | #if DEBUG_ACPI␊ |
4964 | ␉if ((FacpPointer != (void *)0ul) || (oem_fadt == false))␊ |
4965 | ␉{␊ |
4966 | ␉␉printf("FADT found @%x, Length %d\n",FacpPointer, FacpPointer->Header.Length);␊ |
4967 | ␉␉printf("Attempting to patch FADT entry of %s\n",(acpi_tables.FacpPointer64 != (void *)0ul) ? ACPI_SIG_XSDT : ACPI_SIG_RSDT);␊ |
4968 | ␉} ␊ |
4969 | ␉else if (oem_fadt == true)␊ |
4970 | ␉{␊ |
4971 | ␉␉ACPI_TABLE_FADT * FacpPtr = (acpi_tables.FacpPointer64 != (void *)0ul) ? ␊ |
4972 | ␉␉(ACPI_TABLE_FADT *)acpi_tables.FacpPointer64 : (ACPI_TABLE_FADT *)acpi_tables.FacpPointer;␊ |
4973 | ␉␉␊ |
4974 | ␉␉printf("FADT found @%x ( Length %d ) in %s \n",FacpPtr, FacpPtr->Header.Length, (acpi_tables.FacpPointer64 != (void *)0ul) ? ACPI_SIG_XSDT : ACPI_SIG_RSDT);␊ |
4975 | ␉}␊ |
4976 | #endif␉␊ |
4977 | ␉␊ |
4978 | ␉if ((new_dsdt = (ACPI_TABLE_DSDT *)get_new_table_in_list(new_table_list, NAMESEG("DSDT"), &new_table_index)) != (void*)0ul )␊ |
4979 | ␉{␊ |
4980 | ␉␉new_table_list[new_table_index] = 0ul; // This way, the DSDT file will not be added in our new rsdt/xsdt table list, and it shouldn't be anyway␊ |
4981 | ␉}␊ |
4982 | ␉␊ |
4983 | ␉if (oem_fadt == false)␊ |
4984 | ␉{␊ |
4985 | ␉␉␊ |
4986 | ␉␉fadt_mod = patch_fadt(FacpPointer, (oem_dsdt == false) ? new_dsdt : (void*)0ul , (acpi_tables.FacpPointer64 != (void *)0ul ));␉␊ |
4987 | ␊ |
4988 | ␉␉if (fadt_mod != (void*)0ul)␊ |
4989 | ␉␉{␊ |
4990 | ␉␉␉DsdtPtr = ((fadt_mod->Header.Revision >= 3) && (fadt_mod->XDsdt != 0)) ? (ACPI_TABLE_DSDT*)((U32)fadt_mod->XDsdt):(ACPI_TABLE_DSDT*)fadt_mod->Dsdt;␊ |
4991 | ␉␉␉␊ |
4992 | ␉␉␉U8 empty = get_0ul_index_in_list(new_table_list,true);␊ |
4993 | ␉␉␉if (empty != ACPI_TABLE_LIST_FULL)␊ |
4994 | ␉␉␉{␊ |
4995 | ␉␉␉␉new_table_list[empty] = (U32)fadt_mod; // add the patched table to the list␊ |
4996 | ␉␉␉} ␊ |
4997 | ␉␉␉else␊ |
4998 | ␉␉␉{␊ |
4999 | ␉␉␉␉printf("Error: not enought reserved space in the new acpi list for the Patched FACP table,\n ");␊ |
5000 | ␉␉␉␉printf(" please increase the RESERVED_AERA\n");␊ |
5001 | ␉␉␉}␉␉␉␊ |
5002 | ␉␉␉␊ |
5003 | ␉␉} ␊ |
5004 | ␉␉else␊ |
5005 | ␉␉{␊ |
5006 | ␉␉␉printf("Error: Failed to patch the FADT Table, trying fallback to the FADT original pointer\n");␊ |
5007 | ␉␉␉fadt_mod = (acpi_tables.FacpPointer64 != (void *)0ul) ? ␊ |
5008 | ␉␉␉(ACPI_TABLE_FADT *)acpi_tables.FacpPointer64 : (ACPI_TABLE_FADT *)acpi_tables.FacpPointer;␊ |
5009 | ␉␉␉␊ |
5010 | ␉␉␉DsdtPtr = ((fadt_mod->Header.Revision >= 3) && (fadt_mod->XDsdt != 0)) ? (ACPI_TABLE_DSDT*)((U32)fadt_mod->XDsdt):(ACPI_TABLE_DSDT*)fadt_mod->Dsdt;␊ |
5011 | ␉␉␉␊ |
5012 | ␉␉␉U8 empty = get_0ul_index_in_list(new_table_list,true);␊ |
5013 | ␉␉␉if (empty != ACPI_TABLE_LIST_FULL)␊ |
5014 | ␉␉␉{␊ |
5015 | ␉␉␉␉new_table_list[empty] = (U32)fadt_mod; ␊ |
5016 | ␉␉␉} ␊ |
5017 | ␉␉␉else␊ |
5018 | ␉␉␉{␊ |
5019 | ␉␉␉␉printf("Error: not enought reserved space in the new acpi list for the FACP table,\n ");␊ |
5020 | ␉␉␉␉printf(" please increase the RESERVED_AERA\n");␊ |
5021 | ␉␉␉}␊ |
5022 | ␉␉}␉␊ |
5023 | ␉␉␊ |
5024 | ␉␉if (oem_dsdt == false)␊ |
5025 | ␉␉{␊ |
5026 | ␉␉␉if (generate_cpu_map_from_acpi(DsdtPtr) == 0)␊ |
5027 | ␉␉␉{␊ |
5028 | ␉␉␉␉U8 new_uid = (U8)getPciRootUID();␊ |
5029 | ␉␉␉␉␊ |
5030 | ␉␉␉␉/* WARNING: THIS METHOD WORK PERFECTLY BUT IT CAN RESULT TO AN INCORRECT CHECKSUM */␊ |
5031 | ␉␉␉␉␊ |
5032 | ␉␉␉␉if (ProcessDsdt(DsdtPtr, UIDPointer, new_uid))␊ |
5033 | ␉␉␉␉{␊ |
5034 | ␉␉␉␉␉printf("PCI0 _UID patched to %d in the DSDT table\n", new_uid);␊ |
5035 | ␉␉␉␉}␉␉␉␉␊ |
5036 | ␉␉␉␉␊ |
5037 | ␉␉␉}␊ |
5038 | ␉␉}␊ |
5039 | ␉␉␊ |
5040 | ␊ |
5041 | ␉} ␊ |
5042 | ␉else ␊ |
5043 | ␉{␊ |
5044 | ␉␉␊ |
5045 | ␉␉// here we use the variable fadt_mod only for SSDT Generation␊ |
5046 | ␉␉␊ |
5047 | ␉␉fadt_mod = (acpi_tables.FacpPointer64 != (void *)0ul) ? ␊ |
5048 | ␉␉(ACPI_TABLE_FADT *)acpi_tables.FacpPointer64 : (ACPI_TABLE_FADT *)acpi_tables.FacpPointer;␊ |
5049 | ␉␉␊ |
5050 | ␉␉DsdtPtr = ((fadt_mod->Header.Revision >= 3) && (fadt_mod->XDsdt != 0)) ? (ACPI_TABLE_DSDT*)((U32)fadt_mod->XDsdt)␊ |
5051 | :(ACPI_TABLE_DSDT*)fadt_mod->Dsdt;␊ |
5052 | ␉}␊ |
5053 | ␊ |
5054 | {␊ |
5055 | MADT_INFO madt_info;␊ |
5056 | bool strip_madt = true;␊ |
5057 | ␊ |
5058 | getBoolForKey(kSTRIPAPIC, &strip_madt, &bootInfo->chameleonConfig);␊ |
5059 | ␊ |
5060 | if ((strip_madt == false) || (!buildMADT(new_table_list, DsdtPtr, &madt_info ))) ␊ |
5061 | {␊ |
5062 | ␊ |
5063 | ACPI_TABLE_MADT * madt_file = (void*)0ul;␊ |
5064 | ACPI_TABLE_MADT * MadtPointer = (void*)0ul;␊ |
5065 | bool oem_apic=false;␊ |
5066 | ␊ |
5067 | {␉␉␊ |
5068 | bool tmpval;␉␉␊ |
5069 | oem_apic=getBoolForKey(kOEMAPIC, &tmpval, &bootInfo->chameleonConfig)&&tmpval;␉␉␊ |
5070 | } ␊ |
5071 | ␊ |
5072 | if ((madt_file = (ACPI_TABLE_MADT *)get_new_table_in_list(new_table_list, NAMESEG("APIC"), &new_table_index)) != (void *)0ul)␊ |
5073 | {␉␉␊ |
5074 | if (oem_apic == false) ␊ |
5075 | {␊ |
5076 | MadtPointer = (ACPI_TABLE_MADT *)madt_file;␉ ␊ |
5077 | }␊ |
5078 | ␊ |
5079 | } else␊ |
5080 | MadtPointer = (acpi_tables.MadtPointer64 != (void*)0ul) ? (ACPI_TABLE_MADT *)acpi_tables.MadtPointer64 : (ACPI_TABLE_MADT *)acpi_tables.MadtPointer;␊ |
5081 | ␊ |
5082 | ProcessMadtInfo(MadtPointer, &madt_info); ␊ |
5083 | ␊ |
5084 | }␊ |
5085 | ␊ |
5086 | if (gen_ssdt || gen_csta || gen_psta || gen_tsta) ␊ |
5087 | {␊ |
5088 | ProcessSsdt(new_table_list, DsdtPtr, &madt_info, gen_csta, gen_psta, gen_tsta );␉␉␊ |
5089 | }␊ |
5090 | } ␊ |
5091 | ␉␊ |
5092 | ␉if (rsdp_mod == (void *)0ul)␊ |
5093 | ␉{␉␉␊ |
5094 | ␉␉printf("Error: rsdp_mod == null \n");␊ |
5095 | ␉␉return EFI_ABORTED;␊ |
5096 | ␉}␊ |
5097 | ␉␊ |
5098 | ␉if (!(rsdp_mod->Length >= ACPI_RSDP_REV0_SIZE)) ␊ |
5099 | ␉{␊ |
5100 | ␉␉printf("Error: rsdp_mod size is incorrect \n");␊ |
5101 | ␉␉return EFI_ABORTED;␊ |
5102 | ␉␉␊ |
5103 | ␉}␊ |
5104 | ␉␊ |
5105 | ␉do {␊ |
5106 | ␉␉␊ |
5107 | ␉␉if ((rsdp_mod->Revision == 0) || (gen_xsdt == true))␊ |
5108 | ␉␉{␊ |
5109 | ␉␉␉if (process_rsdt(rsdp_mod, gen_xsdt, new_table_list))␊ |
5110 | ␉␉␉␉break;␊ |
5111 | ␉␉␉printf("Error : ACPI RSD PTR Revision 1 is incorrect, \n");␊ |
5112 | ␉␉}␊ |
5113 | ␉␉␊ |
5114 | ␉␉if ((GetChecksum(rsdp_mod, sizeof(ACPI_TABLE_RSDP)) == 0) &&␊ |
5115 | ␉␉␉(Revision == 2) &&␊ |
5116 | ␉␉␉(rsdplength == sizeof(ACPI_TABLE_RSDP)))␊ |
5117 | ␉␉{␊ |
5118 | ␉␉␉if (process_xsdt(rsdp_mod, new_table_list))␊ |
5119 | ␉␉␉␉break;␊ |
5120 | ␉␉␉printf("Error : ACPI RSD PTR Revision 2 is incorrect \n");␊ |
5121 | ␉␉}␉␉␊ |
5122 | ␉␉␊ |
5123 | ␉␉Revision = 0; // fallback to Revision 0␊ |
5124 | ␉␉␊ |
5125 | ␉␉if (process_rsdt(rsdp_mod, false, new_table_list))␊ |
5126 | ␉␉␉break;␉␉␉␊ |
5127 | ␉␉␊ |
5128 | ␉␉printf("Error: Incorect ACPI RSD PTR or not found \n");␊ |
5129 | ␉␉return EFI_ABORTED;␊ |
5130 | ␉␉␊ |
5131 | ␉} while (0); ␊ |
5132 | ␉␊ |
5133 | ␉␊ |
5134 | ␉// Correct the checksum of RSDP ␊ |
5135 | ␉␊ |
5136 | ␉DBG("RSDP: Original checksum %d\n", rsdp_mod->Checksum);␉␉␊ |
5137 | ␉␊ |
5138 | ␉setRsdpchecksum(rsdp_mod);␊ |
5139 | ␉␊ |
5140 | ␉DBG("New checksum %d\n", rsdp_mod->Checksum);␊ |
5141 | ␉␊ |
5142 | ␉if (Revision == 2)␊ |
5143 | ␉{␊ |
5144 | ␉␉DBG("RSDP: Original extended checksum %d\n", rsdp_mod->ExtendedChecksum);␉␉␉␊ |
5145 | ␉␉␊ |
5146 | ␉␉setRsdpXchecksum(rsdp_mod);␊ |
5147 | ␉␉␊ |
5148 | ␉␉DBG("New extended checksum %d\n", rsdp_mod->ExtendedChecksum);␊ |
5149 | ␉␉␊ |
5150 | ␉}␊ |
5151 | ␉␊ |
5152 | ␉verbose("ACPI Revision %d successfully patched\n", Revision);␊ |
5153 | ␉␊ |
5154 | if (Revision == 2)␊ |
5155 | ␉{␊ |
5156 | ␉␉/* XXX aserebln why uint32 cast if pointer is uint64 ? */␊ |
5157 | ␉␉rsd_p = (U32)rsdp_mod;␊ |
5158 | ␉␉addConfigurationTable(&gEfiAcpi20TableGuid, &rsd_p, "ACPI_20");␊ |
5159 | ␉}␊ |
5160 | ␉else␊ |
5161 | ␉{␊ |
5162 | ␉␉/* XXX aserebln why uint32 cast if pointer is uint64 ? */␊ |
5163 | ␉␉rsd_p = (U32)rsdp_mod;␊ |
5164 | ␉␉addConfigurationTable(&gEfiAcpiTableGuid, &rsd_p, "ACPI");␊ |
5165 | ␉}␊ |
5166 | ␉␊ |
5167 | ␉␊ |
5168 | #if DEBUG_ACPI==2␊ |
5169 | ␉printf("Press a key to continue... (DEBUG_ACPI)\n");␊ |
5170 | ␉getc();␊ |
5171 | #endif␊ |
5172 | ␉return Status;␊ |
5173 | }␊ |
5174 | ␊ |
5175 | int AcpiSetup(void)␊ |
5176 | {␊ |
5177 | ␉EFI_STATUS status = setup_Acpi();␊ |
5178 | ␉␊ |
5179 | ␉return (status == EFI_SUCCESS);␊ |
5180 | }␊ |
5181 | |