]> git.proxmox.com Git - mirror_edk2.git/blame - UefiCpuPkg/Include/Library/RegisterCpuFeaturesLib.h
StandaloneMmPkg: Replace BSD License with BSD+Patent License
[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
79be3d27 4 Copyright (c) 2017 - 2019, Intel Corporation. All rights reserved.<BR>\r
80c4b236
JF
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
80c4b236
JF
169/**\r
170 Prepares for the data used by CPU feature detection and initialization.\r
171\r
172 @param[in] NumberOfProcessors The number of CPUs in the platform.\r
173\r
174 @return Pointer to a buffer of CPU related configuration data.\r
175\r
176 @note This service could be called by BSP only.\r
177**/\r
178typedef\r
179VOID *\r
180(EFIAPI *CPU_FEATURE_GET_CONFIG_DATA)(\r
181 IN UINTN NumberOfProcessors\r
182 );\r
183\r
184/**\r
185 Detects if CPU feature supported on current processor.\r
186\r
187 @param[in] ProcessorNumber The index of the CPU executing this function.\r
188 @param[in] CpuInfo A pointer to the REGISTER_CPU_FEATURE_INFORMATION\r
189 structure for the CPU executing this function.\r
190 @param[in] ConfigData A pointer to the configuration buffer returned\r
191 by CPU_FEATURE_GET_CONFIG_DATA. NULL if\r
192 CPU_FEATURE_GET_CONFIG_DATA was not provided in\r
193 RegisterCpuFeature().\r
194\r
195 @retval TRUE CPU feature is supported.\r
196 @retval FALSE CPU feature is not supported.\r
197\r
198 @note This service could be called by BSP/APs.\r
199**/\r
200typedef\r
201BOOLEAN\r
202(EFIAPI *CPU_FEATURE_SUPPORT)(\r
203 IN UINTN ProcessorNumber,\r
204 IN REGISTER_CPU_FEATURE_INFORMATION *CpuInfo,\r
205 IN VOID *ConfigData OPTIONAL\r
206 );\r
207\r
208/**\r
209 Initializes CPU feature to specific state.\r
210\r
211 This service does not initialize hardware and only produces entries in the\r
212 Register Table for specified processor. Hardware initialization on BSP/APs\r
213 will be done in CpuFeaturesInitialize().\r
214\r
215 @param[in] ProcessorNumber The index of the CPU executing this function.\r
216 @param[in] CpuInfo A pointer to the REGISTER_CPU_FEATURE_INFORMATION\r
217 structure for the CPU executing this function.\r
218 @param[in] ConfigData A pointer to the configuration buffer returned\r
219 by CPU_FEATURE_GET_CONFIG_DATA. NULL if\r
220 CPU_FEATURE_GET_CONFIG_DATA was not provided in\r
221 RegisterCpuFeature().\r
222 @param[in] State If TRUE, then the CPU feature must be enabled.\r
223 If FALSE, then the CPU feature must be disabled.\r
224\r
225 @retval RETURN_SUCCESS CPU feature is initialized.\r
226\r
227 @note This service could be called by BSP only.\r
228**/\r
229typedef\r
230RETURN_STATUS\r
231(EFIAPI *CPU_FEATURE_INITIALIZE)(\r
232 IN UINTN ProcessorNumber,\r
233 IN REGISTER_CPU_FEATURE_INFORMATION *CpuInfo,\r
234 IN VOID *ConfigData, OPTIONAL\r
235 IN BOOLEAN State\r
236 );\r
237\r
238/**\r
239 Registers a CPU Feature.\r
240\r
241 @param[in] FeatureName A Null-terminated Ascii string indicates CPU feature\r
242 name.\r
243 @param[in] GetConfigDataFunc CPU feature get configuration data function. This\r
244 is an optional parameter that may be NULL. If NULL,\r
245 then the most recently registered function for the\r
246 CPU feature is used. If no functions are registered\r
247 for a CPU feature, then the CPU configuration data\r
248 for the registered feature is NULL.\r
249 @param[in] SupportFunc CPU feature support function. This is an optional\r
250 parameter that may be NULL. If NULL, then the most\r
251 recently registered function for the CPU feature is\r
252 used. If no functions are registered for a CPU\r
253 feature, then the CPU feature is assumed to be\r
254 supported by all CPUs.\r
255 @param[in] InitializeFunc CPU feature initialize function. This is an optional\r
256 parameter that may be NULL. If NULL, then the most\r
257 recently registered function for the CPU feature is\r
258 used. If no functions are registered for a CPU\r
259 feature, then the CPU feature initialization is\r
260 skipped.\r
261 @param[in] ... Variable argument list of UINT32 CPU feature value.\r
262 Values with no modifiers are the features provided\r
263 by the registered functions.\r
264 Values with CPU_FEATURE_BEFORE modifier are features\r
265 that must be initialized after the features provided\r
266 by the registered functions are used.\r
267 Values with CPU_FEATURE_AFTER modifier are features\r
268 that must be initialized before the features provided\r
269 by the registered functions are used.\r
270 The last argument in this variable argument list must\r
271 always be CPU_FEATURE_END.\r
272\r
273 @retval RETURN_SUCCESS The CPU feature was successfully registered.\r
274 @retval RETURN_OUT_OF_RESOURCES There are not enough resources to register\r
275 the CPU feature.\r
276 @retval RETURN_UNSUPPORTED Registration of the CPU feature is not\r
277 supported due to a circular dependency between\r
278 BEFORE and AFTER features.\r
279\r
280 @note This service could be called by BSP only.\r
281**/\r
282RETURN_STATUS\r
283EFIAPI\r
284RegisterCpuFeature (\r
285 IN CHAR8 *FeatureName, OPTIONAL\r
286 IN CPU_FEATURE_GET_CONFIG_DATA GetConfigDataFunc, OPTIONAL\r
287 IN CPU_FEATURE_SUPPORT SupportFunc, OPTIONAL\r
288 IN CPU_FEATURE_INITIALIZE InitializeFunc, OPTIONAL\r
289 ...\r
290 );\r
291\r
292/**\r
293 Performs CPU features detection.\r
294\r
295 This service will invoke MP service to check CPU features'\r
296 capabilities on BSP/APs.\r
297\r
298 @note This service could be called by BSP only.\r
299**/\r
300VOID\r
301EFIAPI\r
302CpuFeaturesDetect (\r
303 VOID\r
304 );\r
305\r
306/**\r
307 Performs CPU features Initialization.\r
308\r
309 This service will invoke MP service to perform CPU features\r
310 initialization on BSP/APs per user configuration.\r
311\r
312 @note This service could be called by BSP only.\r
313**/\r
314VOID\r
315EFIAPI\r
316CpuFeaturesInitialize (\r
317 VOID\r
318 );\r
319\r
320/**\r
321 Switches to assigned BSP after CPU features initialization.\r
322\r
323 @param[in] ProcessorNumber The index of the CPU executing this function.\r
324\r
325 @note This service could be called by BSP only.\r
326**/\r
327VOID\r
328EFIAPI\r
329SwitchBspAfterFeaturesInitialize (\r
330 IN UINTN ProcessorNumber\r
331 );\r
332\r
333/**\r
334 Adds an entry in specified register table.\r
335\r
336 This function adds an entry in specified register table, with given register type,\r
337 register index, bit section and value.\r
338\r
339 @param[in] ProcessorNumber The index of the CPU to add a register table entry.\r
340 @param[in] RegisterType Type of the register to program\r
341 @param[in] Index Index of the register to program\r
342 @param[in] ValueMask Mask of bits in register to write\r
343 @param[in] Value Value to write\r
344\r
345 @note This service could be called by BSP only.\r
346**/\r
347VOID\r
348EFIAPI\r
349CpuRegisterTableWrite (\r
350 IN UINTN ProcessorNumber,\r
351 IN REGISTER_TYPE RegisterType,\r
352 IN UINT64 Index,\r
353 IN UINT64 ValueMask,\r
354 IN UINT64 Value\r
355 );\r
356\r
357/**\r
358 Adds an entry in specified Pre-SMM register table.\r
359\r
360 This function adds an entry in specified register table, with given register type,\r
361 register index, bit section and value.\r
362\r
363 @param[in] ProcessorNumber The index of the CPU to add a register table entry.\r
364 @param[in] RegisterType Type of the register to program\r
365 @param[in] Index Index of the register to program\r
366 @param[in] ValueMask Mask of bits in register to write\r
367 @param[in] Value Value to write\r
368\r
369 @note This service could be called by BSP only.\r
370**/\r
371VOID\r
372EFIAPI\r
373PreSmmCpuRegisterTableWrite (\r
374 IN UINTN ProcessorNumber,\r
375 IN REGISTER_TYPE RegisterType,\r
376 IN UINT64 Index,\r
377 IN UINT64 ValueMask,\r
378 IN UINT64 Value\r
379 );\r
380\r
381/**\r
382 Adds a 32-bit register write entry in specified register table.\r
383\r
384 This macro adds an entry in specified register table, with given register type,\r
385 register index, and value.\r
386\r
387 @param[in] ProcessorNumber The index of the CPU to add a register table entry.\r
388 @param[in] RegisterType Type of the register to program\r
389 @param[in] Index Index of the register to program\r
390 @param[in] Value Value to write\r
391\r
392 @note This service could be called by BSP only.\r
393**/\r
394#define CPU_REGISTER_TABLE_WRITE32(ProcessorNumber, RegisterType, Index, Value) \\r
395 do { \\r
396 CpuRegisterTableWrite (ProcessorNumber, RegisterType, Index, MAX_UINT32, Value); \\r
397 } while(FALSE);\r
398\r
399/**\r
400 Adds a 64-bit register write entry in specified register table.\r
401\r
402 This macro adds an entry in specified register table, with given register type,\r
403 register index, and value.\r
404\r
405 @param[in] ProcessorNumber The index of the CPU to add a register table entry.\r
406 @param[in] RegisterType Type of the register to program\r
407 @param[in] Index Index of the register to program\r
408 @param[in] Value Value to write\r
409\r
410 @note This service could be called by BSP only.\r
411**/\r
412#define CPU_REGISTER_TABLE_WRITE64(ProcessorNumber, RegisterType, Index, Value) \\r
413 do { \\r
414 CpuRegisterTableWrite (ProcessorNumber, RegisterType, Index, MAX_UINT64, Value); \\r
415 } while(FALSE);\r
416\r
417/**\r
418 Adds a bit field write entry in specified register table.\r
419\r
420 This macro adds an entry in specified register table, with given register type,\r
421 register index, bit field section, and value.\r
422\r
423 @param[in] ProcessorNumber The index of the CPU to add a register table entry.\r
424 @param[in] RegisterType Type of the register to program.\r
425 @param[in] Index Index of the register to program.\r
426 @param[in] Type The data type name of a register structure.\r
427 @param[in] Field The bit fiel name in register structure to write.\r
428 @param[in] Value Value to write to the bit field.\r
429\r
430 @note This service could be called by BSP only.\r
431**/\r
432#define CPU_REGISTER_TABLE_WRITE_FIELD(ProcessorNumber, RegisterType, Index, Type, Field, Value) \\r
433 do { \\r
434 UINT64 ValueMask; \\r
435 ValueMask = MAX_UINT64; \\r
436 ((Type *)(&ValueMask))->Field = 0; \\r
437 CpuRegisterTableWrite (ProcessorNumber, RegisterType, Index, ~ValueMask, Value); \\r
438 } while(FALSE);\r
439\r
440/**\r
441 Adds a 32-bit register write entry in specified register table.\r
442\r
443 This macro adds an entry in specified register table, with given register type,\r
444 register index, and value.\r
445\r
446 @param[in] ProcessorNumber The index of the CPU to add a register table entry.\r
447 @param[in] RegisterType Type of the register to program\r
448 @param[in] Index Index of the register to program\r
449 @param[in] Value Value to write\r
450\r
451 @note This service could be called by BSP only.\r
452**/\r
453#define PRE_SMM_CPU_REGISTER_TABLE_WRITE32(ProcessorNumber, RegisterType, Index, Value) \\r
454 do { \\r
455 PreSmmCpuRegisterTableWrite (ProcessorNumber, RegisterType, Index, MAX_UINT32, Value); \\r
456 } while(FALSE);\r
457\r
458/**\r
459 Adds a 64-bit register write entry in specified register table.\r
460\r
461 This macro adds an entry in specified register table, with given register type,\r
462 register index, and value.\r
463\r
464 @param[in] ProcessorNumber The index of the CPU to add a register table entry.\r
465 @param[in] RegisterType Type of the register to program\r
466 @param[in] Index Index of the register to program\r
467 @param[in] Value Value to write\r
468\r
469 @note This service could be called by BSP only.\r
470**/\r
471#define PRE_SMM_CPU_REGISTER_TABLE_WRITE64(ProcessorNumber, RegisterType, Index, Value) \\r
472 do { \\r
473 PreSmmCpuRegisterTableWrite (ProcessorNumber, RegisterType, Index, MAX_UINT64, Value); \\r
474 } while(FALSE);\r
475\r
476/**\r
477 Adds a bit field write entry in specified register table.\r
478\r
479 This macro adds an entry in specified register table, with given register type,\r
480 register index, bit field section, and value.\r
481\r
482 @param[in] ProcessorNumber The index of the CPU to add a register table entry.\r
483 @param[in] RegisterType Type of the register to program.\r
484 @param[in] Index Index of the register to program.\r
485 @param[in] Type The data type name of a register structure.\r
486 @param[in] Field The bit fiel name in register structure to write.\r
487 @param[in] Value Value to write to the bit field.\r
488\r
489 @note This service could be called by BSP only.\r
490**/\r
491#define PRE_SMM_CPU_REGISTER_TABLE_WRITE_FIELD(ProcessorNumber, RegisterType, Index, Type, Field, Value) \\r
492 do { \\r
493 UINT64 ValueMask; \\r
494 ValueMask = MAX_UINT64; \\r
495 ((Type *)(&ValueMask))->Field = 0; \\r
496 PreSmmCpuRegisterTableWrite (ProcessorNumber, RegisterType, Index, ~ValueMask, Value); \\r
497 } while(FALSE);\r
498\r
499#endif\r