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