]> git.proxmox.com Git - mirror_edk2.git/blame - UefiCpuPkg/Include/Library/RegisterCpuFeaturesLib.h
UefiCpuPkg/RegisterCpuFeaturesLib.h: Add new dependence types.
[mirror_edk2.git] / UefiCpuPkg / Include / Library / RegisterCpuFeaturesLib.h
CommitLineData
80c4b236
JF
1/** @file\r
2 Register CPU Features Library to register and manage CPU features.\r
3\r
4 Copyright (c) 2017, Intel Corporation. All rights reserved.<BR>\r
5 This program and the accompanying materials\r
6 are licensed and made available under the terms and conditions of the BSD License\r
7 which accompanies this distribution. The full text of the license may be found at\r
8 http://opensource.org/licenses/bsd-license.php\r
9\r
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
12\r
13**/\r
14\r
15#ifndef __REGISTER_CPU_FEATURES_LIB_H__\r
16#define __REGISTER_CPU_FEATURES_LIB_H__\r
17\r
18#include <AcpiCpuData.h>\r
19#include <Register/Cpuid.h>\r
20#include <Protocol/MpService.h>\r
21\r
22///\r
23/// Defines used to identify a CPU feature. The lower 16-bits are used to\r
24/// identify a unique CPU feature and the value represents a bit number in\r
25/// a bit mask. The upper 16-bits are bit mask values that are used as\r
26/// modifiers of a CPU feature. When used in a list, the define value\r
27/// CPU_FEATURE_END is used to terminate a list of CPU feature values.\r
28/// @{\r
29#define CPU_FEATURE_AESNI 0\r
30#define CPU_FEATURE_TURBO_MODE 1\r
31#define CPU_FEATURE_MWAIT 2\r
32#define CPU_FEATURE_ACPI 3\r
33#define CPU_FEATURE_EIST 4\r
34#define CPU_FEATURE_XD 5\r
35#define CPU_FEATURE_FASTSTRINGS 6\r
36#define CPU_FEATURE_VMX 7\r
37#define CPU_FEATURE_SMX 8\r
ac36ef87 38#define CPU_FEATURE_LMCE 9\r
80c4b236
JF
39#define CPU_FEATURE_LOCK_FEATURE_CONTROL_REGISTER 10\r
40#define CPU_FEATURE_LIMIT_CPUID_MAX_VAL 11\r
41#define CPU_FEATURE_MCE 12\r
42#define CPU_FEATURE_MCA 13\r
43#define CPU_FEATURE_MCG_CTL 14\r
44#define CPU_FEATURE_PENDING_BREAK 15\r
45#define CPU_FEATURE_C1E 16\r
46#define CPU_FEATURE_C1_AUTO_DEMOTION 17\r
47#define CPU_FEATURE_C3_AUTO_DEMOTION 18\r
bea7af27
JF
48#define CPU_FEATURE_C1_UNDEMOTION 19\r
49#define CPU_FEATURE_C3_UNDEMOTION 20\r
80c4b236
JF
50#define CPU_FEATURE_C_STATE 21\r
51#define CPU_FEATURE_TM 22\r
52#define CPU_FEATURE_TM2 23\r
53#define CPU_FEATURE_X2APIC 24\r
54#define CPU_FEATURE_RESERVED_25 25\r
55#define CPU_FEATURE_RESERVED_26 26\r
56#define CPU_FEATURE_RESERVED_27 27\r
57#define CPU_FEATURE_RESERVED_28 28\r
58#define CPU_FEATURE_RESERVED_29 29\r
59#define CPU_FEATURE_RESERVED_30 30\r
60#define CPU_FEATURE_RESERVED_31 31\r
61\r
62#define CPU_FEATURE_L2_PREFETCHER (32+0)\r
63#define CPU_FEATURE_L1_DATA_PREFETCHER (32+1)\r
64#define CPU_FEATURE_HARDWARE_PREFETCHER (32+2)\r
65#define CPU_FEATURE_ADJACENT_CACHE_LINE_PREFETCH (32+3)\r
66#define CPU_FEATURE_DCU_PREFETCHER (32+4)\r
67#define CPU_FEATURE_IP_PREFETCHER (32+5)\r
68#define CPU_FEATURE_MLC_STREAMER_PREFETCHER (32+6)\r
69#define CPU_FEATURE_MLC_SPATIAL_PREFETCHER (32+7)\r
70#define CPU_FEATURE_THREE_STRICK_COUNTER (32+8)\r
71#define CPU_FEATURE_APIC_TPR_UPDATE_MESSAGE (32+9)\r
72#define CPU_FEATURE_ENERGY_PERFORMANCE_BIAS (32+10)\r
f1a68ab2 73#define CPU_FEATURE_PPIN (32+11)\r
a7e2a253 74#define CPU_FEATURE_PROC_TRACE (32+12)\r
80c4b236 75\r
87e93951
ED
76#define CPU_FEATURE_BEFORE_ALL BIT23\r
77#define CPU_FEATURE_AFTER_ALL BIT24\r
78//\r
79// CPU_FEATURE_BEFORE and CPU_FEATURE_AFTER only mean Thread scope\r
80// before and Thread scope after.\r
81// It will be replace with CPU_FEATURE_THREAD_BEFORE and\r
82// CPU_FEATURE_THREAD_AFTER, and should not be used anymore.\r
83//\r
84#define CPU_FEATURE_BEFORE BIT25\r
85#define CPU_FEATURE_AFTER BIT26\r
86\r
87#define CPU_FEATURE_THREAD_BEFORE CPU_FEATURE_BEFORE\r
88#define CPU_FEATURE_THREAD_AFTER CPU_FEATURE_AFTER\r
89#define CPU_FEATURE_CORE_BEFORE BIT27\r
90#define CPU_FEATURE_CORE_AFTER BIT28\r
91#define CPU_FEATURE_PACKAGE_BEFORE BIT29\r
92#define CPU_FEATURE_PACKAGE_AFTER BIT30\r
80c4b236
JF
93#define CPU_FEATURE_END MAX_UINT32\r
94/// @}\r
95\r
96///\r
97/// CPU Information passed into the SupportFunc and InitializeFunc of the\r
98/// RegisterCpuFeature() library function. This structure contains information\r
99/// that is commonly used during CPU feature detection and initialization.\r
100///\r
101typedef struct {\r
102 ///\r
103 /// The package that the CPU resides\r
104 ///\r
105 EFI_PROCESSOR_INFORMATION ProcessorInfo;\r
106 ///\r
107 /// The Display Family of the CPU computed from CPUID leaf CPUID_VERSION_INFO\r
108 ///\r
109 UINT32 DisplayFamily;\r
110 ///\r
111 /// The Display Model of the CPU computed from CPUID leaf CPUID_VERSION_INFO\r
112 ///\r
113 UINT32 DisplayModel;\r
114 ///\r
115 /// The Stepping ID of the CPU computed from CPUID leaf CPUID_VERSION_INFO\r
116 ///\r
117 UINT32 SteppingId;\r
118 ///\r
119 /// The Processor Type of the CPU computed from CPUID leaf CPUID_VERSION_INFO\r
120 ///\r
121 UINT32 ProcessorType;\r
122 ///\r
123 /// Bit field structured returned in ECX from CPUID leaf CPUID_VERSION_INFO\r
124 ///\r
125 CPUID_VERSION_INFO_ECX CpuIdVersionInfoEcx;\r
126 ///\r
127 /// Bit field structured returned in EDX from CPUID leaf CPUID_VERSION_INFO\r
128 ///\r
129 CPUID_VERSION_INFO_EDX CpuIdVersionInfoEdx;\r
130} REGISTER_CPU_FEATURE_INFORMATION;\r
131\r
132/**\r
133 Determines if a CPU feature is enabled in PcdCpuFeaturesSupport bit mask.\r
134 If a CPU feature is disabled in PcdCpuFeaturesSupport then all the code/data\r
135 associated with that feature should be optimized away if compiler\r
136 optimizations are enabled.\r
137\r
138 @param[in] Feature The bit number of the CPU feature to check in the PCD\r
139 PcdCpuFeaturesSupport.\r
140\r
141 @retval TRUE The CPU feature is set in PcdCpuFeaturesSupport.\r
142 @retval FALSE The CPU feature is not set in PcdCpuFeaturesSupport.\r
143\r
144 @note This service could be called by BSP only.\r
145**/\r
146BOOLEAN\r
147EFIAPI\r
148IsCpuFeatureSupported (\r
149 IN UINT32 Feature\r
150 );\r
151\r
152/**\r
153 Determines if a CPU feature is set in PcdCpuFeaturesSetting bit mask.\r
154\r
155 @param[in] Feature The bit number of the CPU feature to check in the PCD\r
156 PcdCpuFeaturesSetting.\r
157\r
158 @retval TRUE The CPU feature is set in PcdCpuFeaturesSetting.\r
159 @retval FALSE The CPU feature is not set in PcdCpuFeaturesSetting.\r
160\r
161 @note This service could be called by BSP only.\r
162**/\r
163BOOLEAN\r
164EFIAPI\r
165IsCpuFeatureInSetting (\r
166 IN UINT32 Feature\r
167 );\r
168\r
169/**\r
170 Determines if a CPU feature is set in PcdCpuFeaturesCapability bit mask.\r
171\r
172 @param[in] Feature The bit number of the CPU feature to check in the PCD\r
173 PcdCpuFeaturesCapability.\r
174\r
175 @retval TRUE The CPU feature is set in PcdCpuFeaturesCapability.\r
176 @retval FALSE The CPU feature is not set in PcdCpuFeaturesCapability.\r
177\r
178 @note This service could be called by BSP only.\r
179**/\r
180BOOLEAN\r
181EFIAPI\r
182IsCpuFeatureCapability (\r
183 IN UINT32 Feature\r
184 );\r
185\r
186/**\r
187 Determines if a CPU feature is set in PcdCpuFeaturesUserConfiguration bit mask.\r
188\r
189 @param[in] Feature The bit number of the CPU feature to check in the PCD\r
190 PcdCpuFeaturesUserConfiguration.\r
191\r
192 @retval TRUE The CPU feature is set in PcdCpuFeaturesUserConfiguration.\r
193 @retval FALSE The CPU feature is not set in PcdCpuFeaturesUserConfiguration.\r
194\r
195 @note This service could be called by BSP only.\r
196**/\r
197BOOLEAN\r
198EFIAPI\r
199IsCpuFeatureUserConfiguration (\r
200 IN UINT32 Feature\r
201 );\r
202\r
203/**\r
204 Prepares for the data used by CPU feature detection and initialization.\r
205\r
206 @param[in] NumberOfProcessors The number of CPUs in the platform.\r
207\r
208 @return Pointer to a buffer of CPU related configuration data.\r
209\r
210 @note This service could be called by BSP only.\r
211**/\r
212typedef\r
213VOID *\r
214(EFIAPI *CPU_FEATURE_GET_CONFIG_DATA)(\r
215 IN UINTN NumberOfProcessors\r
216 );\r
217\r
218/**\r
219 Detects if CPU feature supported on current processor.\r
220\r
221 @param[in] ProcessorNumber The index of the CPU executing this function.\r
222 @param[in] CpuInfo A pointer to the REGISTER_CPU_FEATURE_INFORMATION\r
223 structure for the CPU executing this function.\r
224 @param[in] ConfigData A pointer to the configuration buffer returned\r
225 by CPU_FEATURE_GET_CONFIG_DATA. NULL if\r
226 CPU_FEATURE_GET_CONFIG_DATA was not provided in\r
227 RegisterCpuFeature().\r
228\r
229 @retval TRUE CPU feature is supported.\r
230 @retval FALSE CPU feature is not supported.\r
231\r
232 @note This service could be called by BSP/APs.\r
233**/\r
234typedef\r
235BOOLEAN\r
236(EFIAPI *CPU_FEATURE_SUPPORT)(\r
237 IN UINTN ProcessorNumber,\r
238 IN REGISTER_CPU_FEATURE_INFORMATION *CpuInfo,\r
239 IN VOID *ConfigData OPTIONAL\r
240 );\r
241\r
242/**\r
243 Initializes CPU feature to specific state.\r
244\r
245 This service does not initialize hardware and only produces entries in the\r
246 Register Table for specified processor. Hardware initialization on BSP/APs\r
247 will be done in CpuFeaturesInitialize().\r
248\r
249 @param[in] ProcessorNumber The index of the CPU executing this function.\r
250 @param[in] CpuInfo A pointer to the REGISTER_CPU_FEATURE_INFORMATION\r
251 structure for the CPU executing this function.\r
252 @param[in] ConfigData A pointer to the configuration buffer returned\r
253 by CPU_FEATURE_GET_CONFIG_DATA. NULL if\r
254 CPU_FEATURE_GET_CONFIG_DATA was not provided in\r
255 RegisterCpuFeature().\r
256 @param[in] State If TRUE, then the CPU feature must be enabled.\r
257 If FALSE, then the CPU feature must be disabled.\r
258\r
259 @retval RETURN_SUCCESS CPU feature is initialized.\r
260\r
261 @note This service could be called by BSP only.\r
262**/\r
263typedef\r
264RETURN_STATUS\r
265(EFIAPI *CPU_FEATURE_INITIALIZE)(\r
266 IN UINTN ProcessorNumber,\r
267 IN REGISTER_CPU_FEATURE_INFORMATION *CpuInfo,\r
268 IN VOID *ConfigData, OPTIONAL\r
269 IN BOOLEAN State\r
270 );\r
271\r
272/**\r
273 Registers a CPU Feature.\r
274\r
275 @param[in] FeatureName A Null-terminated Ascii string indicates CPU feature\r
276 name.\r
277 @param[in] GetConfigDataFunc CPU feature get configuration data function. This\r
278 is an optional parameter that may be NULL. If NULL,\r
279 then the most recently registered function for the\r
280 CPU feature is used. If no functions are registered\r
281 for a CPU feature, then the CPU configuration data\r
282 for the registered feature is NULL.\r
283 @param[in] SupportFunc CPU feature support function. This is an optional\r
284 parameter that may be NULL. If NULL, then the most\r
285 recently registered function for the CPU feature is\r
286 used. If no functions are registered for a CPU\r
287 feature, then the CPU feature is assumed to be\r
288 supported by all CPUs.\r
289 @param[in] InitializeFunc CPU feature initialize function. This is an optional\r
290 parameter that may be NULL. If NULL, then the most\r
291 recently registered function for the CPU feature is\r
292 used. If no functions are registered for a CPU\r
293 feature, then the CPU feature initialization is\r
294 skipped.\r
295 @param[in] ... Variable argument list of UINT32 CPU feature value.\r
296 Values with no modifiers are the features provided\r
297 by the registered functions.\r
298 Values with CPU_FEATURE_BEFORE modifier are features\r
299 that must be initialized after the features provided\r
300 by the registered functions are used.\r
301 Values with CPU_FEATURE_AFTER modifier are features\r
302 that must be initialized before the features provided\r
303 by the registered functions are used.\r
304 The last argument in this variable argument list must\r
305 always be CPU_FEATURE_END.\r
306\r
307 @retval RETURN_SUCCESS The CPU feature was successfully registered.\r
308 @retval RETURN_OUT_OF_RESOURCES There are not enough resources to register\r
309 the CPU feature.\r
310 @retval RETURN_UNSUPPORTED Registration of the CPU feature is not\r
311 supported due to a circular dependency between\r
312 BEFORE and AFTER features.\r
313\r
314 @note This service could be called by BSP only.\r
315**/\r
316RETURN_STATUS\r
317EFIAPI\r
318RegisterCpuFeature (\r
319 IN CHAR8 *FeatureName, OPTIONAL\r
320 IN CPU_FEATURE_GET_CONFIG_DATA GetConfigDataFunc, OPTIONAL\r
321 IN CPU_FEATURE_SUPPORT SupportFunc, OPTIONAL\r
322 IN CPU_FEATURE_INITIALIZE InitializeFunc, OPTIONAL\r
323 ...\r
324 );\r
325\r
326/**\r
327 Performs CPU features detection.\r
328\r
329 This service will invoke MP service to check CPU features'\r
330 capabilities on BSP/APs.\r
331\r
332 @note This service could be called by BSP only.\r
333**/\r
334VOID\r
335EFIAPI\r
336CpuFeaturesDetect (\r
337 VOID\r
338 );\r
339\r
340/**\r
341 Performs CPU features Initialization.\r
342\r
343 This service will invoke MP service to perform CPU features\r
344 initialization on BSP/APs per user configuration.\r
345\r
346 @note This service could be called by BSP only.\r
347**/\r
348VOID\r
349EFIAPI\r
350CpuFeaturesInitialize (\r
351 VOID\r
352 );\r
353\r
354/**\r
355 Switches to assigned BSP after CPU features initialization.\r
356\r
357 @param[in] ProcessorNumber The index of the CPU executing this function.\r
358\r
359 @note This service could be called by BSP only.\r
360**/\r
361VOID\r
362EFIAPI\r
363SwitchBspAfterFeaturesInitialize (\r
364 IN UINTN ProcessorNumber\r
365 );\r
366\r
367/**\r
368 Adds an entry in specified register table.\r
369\r
370 This function adds an entry in specified register table, with given register type,\r
371 register index, bit section and value.\r
372\r
373 @param[in] ProcessorNumber The index of the CPU to add a register table entry.\r
374 @param[in] RegisterType Type of the register to program\r
375 @param[in] Index Index of the register to program\r
376 @param[in] ValueMask Mask of bits in register to write\r
377 @param[in] Value Value to write\r
378\r
379 @note This service could be called by BSP only.\r
380**/\r
381VOID\r
382EFIAPI\r
383CpuRegisterTableWrite (\r
384 IN UINTN ProcessorNumber,\r
385 IN REGISTER_TYPE RegisterType,\r
386 IN UINT64 Index,\r
387 IN UINT64 ValueMask,\r
388 IN UINT64 Value\r
389 );\r
390\r
391/**\r
392 Adds an entry in specified Pre-SMM register table.\r
393\r
394 This function adds an entry in specified register table, with given register type,\r
395 register index, bit section and value.\r
396\r
397 @param[in] ProcessorNumber The index of the CPU to add a register table entry.\r
398 @param[in] RegisterType Type of the register to program\r
399 @param[in] Index Index of the register to program\r
400 @param[in] ValueMask Mask of bits in register to write\r
401 @param[in] Value Value to write\r
402\r
403 @note This service could be called by BSP only.\r
404**/\r
405VOID\r
406EFIAPI\r
407PreSmmCpuRegisterTableWrite (\r
408 IN UINTN ProcessorNumber,\r
409 IN REGISTER_TYPE RegisterType,\r
410 IN UINT64 Index,\r
411 IN UINT64 ValueMask,\r
412 IN UINT64 Value\r
413 );\r
414\r
415/**\r
416 Adds a 32-bit register write entry in specified register table.\r
417\r
418 This macro adds an entry in specified register table, with given register type,\r
419 register index, and value.\r
420\r
421 @param[in] ProcessorNumber The index of the CPU to add a register table entry.\r
422 @param[in] RegisterType Type of the register to program\r
423 @param[in] Index Index of the register to program\r
424 @param[in] Value Value to write\r
425\r
426 @note This service could be called by BSP only.\r
427**/\r
428#define CPU_REGISTER_TABLE_WRITE32(ProcessorNumber, RegisterType, Index, Value) \\r
429 do { \\r
430 CpuRegisterTableWrite (ProcessorNumber, RegisterType, Index, MAX_UINT32, Value); \\r
431 } while(FALSE);\r
432\r
433/**\r
434 Adds a 64-bit register write entry in specified register table.\r
435\r
436 This macro adds an entry in specified register table, with given register type,\r
437 register index, and value.\r
438\r
439 @param[in] ProcessorNumber The index of the CPU to add a register table entry.\r
440 @param[in] RegisterType Type of the register to program\r
441 @param[in] Index Index of the register to program\r
442 @param[in] Value Value to write\r
443\r
444 @note This service could be called by BSP only.\r
445**/\r
446#define CPU_REGISTER_TABLE_WRITE64(ProcessorNumber, RegisterType, Index, Value) \\r
447 do { \\r
448 CpuRegisterTableWrite (ProcessorNumber, RegisterType, Index, MAX_UINT64, Value); \\r
449 } while(FALSE);\r
450\r
451/**\r
452 Adds a bit field write entry in specified register table.\r
453\r
454 This macro adds an entry in specified register table, with given register type,\r
455 register index, bit field section, and value.\r
456\r
457 @param[in] ProcessorNumber The index of the CPU to add a register table entry.\r
458 @param[in] RegisterType Type of the register to program.\r
459 @param[in] Index Index of the register to program.\r
460 @param[in] Type The data type name of a register structure.\r
461 @param[in] Field The bit fiel name in register structure to write.\r
462 @param[in] Value Value to write to the bit field.\r
463\r
464 @note This service could be called by BSP only.\r
465**/\r
466#define CPU_REGISTER_TABLE_WRITE_FIELD(ProcessorNumber, RegisterType, Index, Type, Field, Value) \\r
467 do { \\r
468 UINT64 ValueMask; \\r
469 ValueMask = MAX_UINT64; \\r
470 ((Type *)(&ValueMask))->Field = 0; \\r
471 CpuRegisterTableWrite (ProcessorNumber, RegisterType, Index, ~ValueMask, Value); \\r
472 } while(FALSE);\r
473\r
474/**\r
475 Adds a 32-bit register write entry in specified register table.\r
476\r
477 This macro adds an entry in specified register table, with given register type,\r
478 register index, and value.\r
479\r
480 @param[in] ProcessorNumber The index of the CPU to add a register table entry.\r
481 @param[in] RegisterType Type of the register to program\r
482 @param[in] Index Index of the register to program\r
483 @param[in] Value Value to write\r
484\r
485 @note This service could be called by BSP only.\r
486**/\r
487#define PRE_SMM_CPU_REGISTER_TABLE_WRITE32(ProcessorNumber, RegisterType, Index, Value) \\r
488 do { \\r
489 PreSmmCpuRegisterTableWrite (ProcessorNumber, RegisterType, Index, MAX_UINT32, Value); \\r
490 } while(FALSE);\r
491\r
492/**\r
493 Adds a 64-bit register write entry in specified register table.\r
494\r
495 This macro adds an entry in specified register table, with given register type,\r
496 register index, and value.\r
497\r
498 @param[in] ProcessorNumber The index of the CPU to add a register table entry.\r
499 @param[in] RegisterType Type of the register to program\r
500 @param[in] Index Index of the register to program\r
501 @param[in] Value Value to write\r
502\r
503 @note This service could be called by BSP only.\r
504**/\r
505#define PRE_SMM_CPU_REGISTER_TABLE_WRITE64(ProcessorNumber, RegisterType, Index, Value) \\r
506 do { \\r
507 PreSmmCpuRegisterTableWrite (ProcessorNumber, RegisterType, Index, MAX_UINT64, Value); \\r
508 } while(FALSE);\r
509\r
510/**\r
511 Adds a bit field write entry in specified register table.\r
512\r
513 This macro adds an entry in specified register table, with given register type,\r
514 register index, bit field section, and value.\r
515\r
516 @param[in] ProcessorNumber The index of the CPU to add a register table entry.\r
517 @param[in] RegisterType Type of the register to program.\r
518 @param[in] Index Index of the register to program.\r
519 @param[in] Type The data type name of a register structure.\r
520 @param[in] Field The bit fiel name in register structure to write.\r
521 @param[in] Value Value to write to the bit field.\r
522\r
523 @note This service could be called by BSP only.\r
524**/\r
525#define PRE_SMM_CPU_REGISTER_TABLE_WRITE_FIELD(ProcessorNumber, RegisterType, Index, Type, Field, Value) \\r
526 do { \\r
527 UINT64 ValueMask; \\r
528 ValueMask = MAX_UINT64; \\r
529 ((Type *)(&ValueMask))->Field = 0; \\r
530 PreSmmCpuRegisterTableWrite (ProcessorNumber, RegisterType, Index, ~ValueMask, Value); \\r
531 } while(FALSE);\r
532\r
533#endif\r