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