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