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