2 Register CPU Features Library to register and manage CPU features.
4 Copyright (c) 2017, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
15 #ifndef __REGISTER_CPU_FEATURES_LIB_H__
16 #define __REGISTER_CPU_FEATURES_LIB_H__
18 #include <AcpiCpuData.h>
19 #include <Register/Cpuid.h>
20 #include <Protocol/MpService.h>
23 /// Defines used to identify a CPU feature. The lower 16-bits are used to
24 /// identify a unique CPU feature and the value represents a bit number in
25 /// a bit mask. The upper 16-bits are bit mask values that are used as
26 /// modifiers of a CPU feature. When used in a list, the define value
27 /// CPU_FEATURE_END is used to terminate a list of CPU feature values.
29 #define CPU_FEATURE_AESNI 0
30 #define CPU_FEATURE_TURBO_MODE 1
31 #define CPU_FEATURE_MWAIT 2
32 #define CPU_FEATURE_ACPI 3
33 #define CPU_FEATURE_EIST 4
34 #define CPU_FEATURE_XD 5
35 #define CPU_FEATURE_FASTSTRINGS 6
36 #define CPU_FEATURE_VMX 7
37 #define CPU_FEATURE_SMX 8
38 #define CPU_FEATURE_LMCE 9
39 #define CPU_FEATURE_LOCK_FEATURE_CONTROL_REGISTER 10
40 #define CPU_FEATURE_LIMIT_CPUID_MAX_VAL 11
41 #define CPU_FEATURE_MCE 12
42 #define CPU_FEATURE_MCA 13
43 #define CPU_FEATURE_MCG_CTL 14
44 #define CPU_FEATURE_PENDING_BREAK 15
45 #define CPU_FEATURE_C1E 16
46 #define CPU_FEATURE_C1_AUTO_DEMOTION 17
47 #define CPU_FEATURE_C3_AUTO_DEMOTION 18
48 #define CPU_FEATURE_C1_UNDEMOTION 19
49 #define CPU_FEATURE_C3_UNDEMOTION 20
50 #define CPU_FEATURE_C_STATE 21
51 #define CPU_FEATURE_TM 22
52 #define CPU_FEATURE_TM2 23
53 #define CPU_FEATURE_X2APIC 24
54 #define CPU_FEATURE_RESERVED_25 25
55 #define CPU_FEATURE_RESERVED_26 26
56 #define CPU_FEATURE_RESERVED_27 27
57 #define CPU_FEATURE_RESERVED_28 28
58 #define CPU_FEATURE_RESERVED_29 29
59 #define CPU_FEATURE_RESERVED_30 30
60 #define CPU_FEATURE_RESERVED_31 31
62 #define CPU_FEATURE_L2_PREFETCHER (32+0)
63 #define CPU_FEATURE_L1_DATA_PREFETCHER (32+1)
64 #define CPU_FEATURE_HARDWARE_PREFETCHER (32+2)
65 #define CPU_FEATURE_ADJACENT_CACHE_LINE_PREFETCH (32+3)
66 #define CPU_FEATURE_DCU_PREFETCHER (32+4)
67 #define CPU_FEATURE_IP_PREFETCHER (32+5)
68 #define CPU_FEATURE_MLC_STREAMER_PREFETCHER (32+6)
69 #define CPU_FEATURE_MLC_SPATIAL_PREFETCHER (32+7)
70 #define CPU_FEATURE_THREE_STRICK_COUNTER (32+8)
71 #define CPU_FEATURE_APIC_TPR_UPDATE_MESSAGE (32+9)
72 #define CPU_FEATURE_ENERGY_PERFORMANCE_BIAS (32+10)
73 #define CPU_FEATURE_PPIN (32+11)
74 #define CPU_FEATURE_PROC_TRACE (32+12)
76 #define CPU_FEATURE_BEFORE_ALL BIT27
77 #define CPU_FEATURE_AFTER_ALL BIT28
78 #define CPU_FEATURE_BEFORE BIT29
79 #define CPU_FEATURE_AFTER BIT30
80 #define CPU_FEATURE_END MAX_UINT32
84 /// CPU Information passed into the SupportFunc and InitializeFunc of the
85 /// RegisterCpuFeature() library function. This structure contains information
86 /// that is commonly used during CPU feature detection and initialization.
90 /// The package that the CPU resides
92 EFI_PROCESSOR_INFORMATION ProcessorInfo
;
94 /// The Display Family of the CPU computed from CPUID leaf CPUID_VERSION_INFO
98 /// The Display Model of the CPU computed from CPUID leaf CPUID_VERSION_INFO
102 /// The Stepping ID of the CPU computed from CPUID leaf CPUID_VERSION_INFO
106 /// The Processor Type of the CPU computed from CPUID leaf CPUID_VERSION_INFO
108 UINT32 ProcessorType
;
110 /// Bit field structured returned in ECX from CPUID leaf CPUID_VERSION_INFO
112 CPUID_VERSION_INFO_ECX CpuIdVersionInfoEcx
;
114 /// Bit field structured returned in EDX from CPUID leaf CPUID_VERSION_INFO
116 CPUID_VERSION_INFO_EDX CpuIdVersionInfoEdx
;
117 } REGISTER_CPU_FEATURE_INFORMATION
;
120 Determines if a CPU feature is enabled in PcdCpuFeaturesSupport bit mask.
121 If a CPU feature is disabled in PcdCpuFeaturesSupport then all the code/data
122 associated with that feature should be optimized away if compiler
123 optimizations are enabled.
125 @param[in] Feature The bit number of the CPU feature to check in the PCD
126 PcdCpuFeaturesSupport.
128 @retval TRUE The CPU feature is set in PcdCpuFeaturesSupport.
129 @retval FALSE The CPU feature is not set in PcdCpuFeaturesSupport.
131 @note This service could be called by BSP only.
135 IsCpuFeatureSupported (
140 Determines if a CPU feature is set in PcdCpuFeaturesSetting bit mask.
142 @param[in] Feature The bit number of the CPU feature to check in the PCD
143 PcdCpuFeaturesSetting.
145 @retval TRUE The CPU feature is set in PcdCpuFeaturesSetting.
146 @retval FALSE The CPU feature is not set in PcdCpuFeaturesSetting.
148 @note This service could be called by BSP only.
152 IsCpuFeatureInSetting (
157 Determines if a CPU feature is set in PcdCpuFeaturesCapability bit mask.
159 @param[in] Feature The bit number of the CPU feature to check in the PCD
160 PcdCpuFeaturesCapability.
162 @retval TRUE The CPU feature is set in PcdCpuFeaturesCapability.
163 @retval FALSE The CPU feature is not set in PcdCpuFeaturesCapability.
165 @note This service could be called by BSP only.
169 IsCpuFeatureCapability (
174 Determines if a CPU feature is set in PcdCpuFeaturesUserConfiguration bit mask.
176 @param[in] Feature The bit number of the CPU feature to check in the PCD
177 PcdCpuFeaturesUserConfiguration.
179 @retval TRUE The CPU feature is set in PcdCpuFeaturesUserConfiguration.
180 @retval FALSE The CPU feature is not set in PcdCpuFeaturesUserConfiguration.
182 @note This service could be called by BSP only.
186 IsCpuFeatureUserConfiguration (
191 Prepares for the data used by CPU feature detection and initialization.
193 @param[in] NumberOfProcessors The number of CPUs in the platform.
195 @return Pointer to a buffer of CPU related configuration data.
197 @note This service could be called by BSP only.
201 (EFIAPI
*CPU_FEATURE_GET_CONFIG_DATA
)(
202 IN UINTN NumberOfProcessors
206 Detects if CPU feature supported on current processor.
208 @param[in] ProcessorNumber The index of the CPU executing this function.
209 @param[in] CpuInfo A pointer to the REGISTER_CPU_FEATURE_INFORMATION
210 structure for the CPU executing this function.
211 @param[in] ConfigData A pointer to the configuration buffer returned
212 by CPU_FEATURE_GET_CONFIG_DATA. NULL if
213 CPU_FEATURE_GET_CONFIG_DATA was not provided in
214 RegisterCpuFeature().
216 @retval TRUE CPU feature is supported.
217 @retval FALSE CPU feature is not supported.
219 @note This service could be called by BSP/APs.
223 (EFIAPI
*CPU_FEATURE_SUPPORT
)(
224 IN UINTN ProcessorNumber
,
225 IN REGISTER_CPU_FEATURE_INFORMATION
*CpuInfo
,
226 IN VOID
*ConfigData OPTIONAL
230 Initializes CPU feature to specific state.
232 This service does not initialize hardware and only produces entries in the
233 Register Table for specified processor. Hardware initialization on BSP/APs
234 will be done in CpuFeaturesInitialize().
236 @param[in] ProcessorNumber The index of the CPU executing this function.
237 @param[in] CpuInfo A pointer to the REGISTER_CPU_FEATURE_INFORMATION
238 structure for the CPU executing this function.
239 @param[in] ConfigData A pointer to the configuration buffer returned
240 by CPU_FEATURE_GET_CONFIG_DATA. NULL if
241 CPU_FEATURE_GET_CONFIG_DATA was not provided in
242 RegisterCpuFeature().
243 @param[in] State If TRUE, then the CPU feature must be enabled.
244 If FALSE, then the CPU feature must be disabled.
246 @retval RETURN_SUCCESS CPU feature is initialized.
248 @note This service could be called by BSP only.
252 (EFIAPI
*CPU_FEATURE_INITIALIZE
)(
253 IN UINTN ProcessorNumber
,
254 IN REGISTER_CPU_FEATURE_INFORMATION
*CpuInfo
,
255 IN VOID
*ConfigData
, OPTIONAL
260 Registers a CPU Feature.
262 @param[in] FeatureName A Null-terminated Ascii string indicates CPU feature
264 @param[in] GetConfigDataFunc CPU feature get configuration data function. This
265 is an optional parameter that may be NULL. If NULL,
266 then the most recently registered function for the
267 CPU feature is used. If no functions are registered
268 for a CPU feature, then the CPU configuration data
269 for the registered feature is NULL.
270 @param[in] SupportFunc CPU feature support function. This is an optional
271 parameter that may be NULL. If NULL, then the most
272 recently registered function for the CPU feature is
273 used. If no functions are registered for a CPU
274 feature, then the CPU feature is assumed to be
275 supported by all CPUs.
276 @param[in] InitializeFunc CPU feature initialize function. This is an optional
277 parameter that may be NULL. If NULL, then the most
278 recently registered function for the CPU feature is
279 used. If no functions are registered for a CPU
280 feature, then the CPU feature initialization is
282 @param[in] ... Variable argument list of UINT32 CPU feature value.
283 Values with no modifiers are the features provided
284 by the registered functions.
285 Values with CPU_FEATURE_BEFORE modifier are features
286 that must be initialized after the features provided
287 by the registered functions are used.
288 Values with CPU_FEATURE_AFTER modifier are features
289 that must be initialized before the features provided
290 by the registered functions are used.
291 The last argument in this variable argument list must
292 always be CPU_FEATURE_END.
294 @retval RETURN_SUCCESS The CPU feature was successfully registered.
295 @retval RETURN_OUT_OF_RESOURCES There are not enough resources to register
297 @retval RETURN_UNSUPPORTED Registration of the CPU feature is not
298 supported due to a circular dependency between
299 BEFORE and AFTER features.
301 @note This service could be called by BSP only.
306 IN CHAR8
*FeatureName
, OPTIONAL
307 IN CPU_FEATURE_GET_CONFIG_DATA GetConfigDataFunc
, OPTIONAL
308 IN CPU_FEATURE_SUPPORT SupportFunc
, OPTIONAL
309 IN CPU_FEATURE_INITIALIZE InitializeFunc
, OPTIONAL
314 Performs CPU features detection.
316 This service will invoke MP service to check CPU features'
317 capabilities on BSP/APs.
319 @note This service could be called by BSP only.
328 Performs CPU features Initialization.
330 This service will invoke MP service to perform CPU features
331 initialization on BSP/APs per user configuration.
333 @note This service could be called by BSP only.
337 CpuFeaturesInitialize (
342 Switches to assigned BSP after CPU features initialization.
344 @param[in] ProcessorNumber The index of the CPU executing this function.
346 @note This service could be called by BSP only.
350 SwitchBspAfterFeaturesInitialize (
351 IN UINTN ProcessorNumber
355 Adds an entry in specified register table.
357 This function adds an entry in specified register table, with given register type,
358 register index, bit section and value.
360 @param[in] ProcessorNumber The index of the CPU to add a register table entry.
361 @param[in] RegisterType Type of the register to program
362 @param[in] Index Index of the register to program
363 @param[in] ValueMask Mask of bits in register to write
364 @param[in] Value Value to write
366 @note This service could be called by BSP only.
370 CpuRegisterTableWrite (
371 IN UINTN ProcessorNumber
,
372 IN REGISTER_TYPE RegisterType
,
379 Adds an entry in specified Pre-SMM register table.
381 This function adds an entry in specified register table, with given register type,
382 register index, bit section and value.
384 @param[in] ProcessorNumber The index of the CPU to add a register table entry.
385 @param[in] RegisterType Type of the register to program
386 @param[in] Index Index of the register to program
387 @param[in] ValueMask Mask of bits in register to write
388 @param[in] Value Value to write
390 @note This service could be called by BSP only.
394 PreSmmCpuRegisterTableWrite (
395 IN UINTN ProcessorNumber
,
396 IN REGISTER_TYPE RegisterType
,
403 Adds a 32-bit register write entry in specified register table.
405 This macro adds an entry in specified register table, with given register type,
406 register index, and value.
408 @param[in] ProcessorNumber The index of the CPU to add a register table entry.
409 @param[in] RegisterType Type of the register to program
410 @param[in] Index Index of the register to program
411 @param[in] Value Value to write
413 @note This service could be called by BSP only.
415 #define CPU_REGISTER_TABLE_WRITE32(ProcessorNumber, RegisterType, Index, Value) \
417 CpuRegisterTableWrite (ProcessorNumber, RegisterType, Index, MAX_UINT32, Value); \
421 Adds a 64-bit register write entry in specified register table.
423 This macro adds an entry in specified register table, with given register type,
424 register index, and value.
426 @param[in] ProcessorNumber The index of the CPU to add a register table entry.
427 @param[in] RegisterType Type of the register to program
428 @param[in] Index Index of the register to program
429 @param[in] Value Value to write
431 @note This service could be called by BSP only.
433 #define CPU_REGISTER_TABLE_WRITE64(ProcessorNumber, RegisterType, Index, Value) \
435 CpuRegisterTableWrite (ProcessorNumber, RegisterType, Index, MAX_UINT64, Value); \
439 Adds a bit field write entry in specified register table.
441 This macro adds an entry in specified register table, with given register type,
442 register index, bit field section, and value.
444 @param[in] ProcessorNumber The index of the CPU to add a register table entry.
445 @param[in] RegisterType Type of the register to program.
446 @param[in] Index Index of the register to program.
447 @param[in] Type The data type name of a register structure.
448 @param[in] Field The bit fiel name in register structure to write.
449 @param[in] Value Value to write to the bit field.
451 @note This service could be called by BSP only.
453 #define CPU_REGISTER_TABLE_WRITE_FIELD(ProcessorNumber, RegisterType, Index, Type, Field, Value) \
456 ValueMask = MAX_UINT64; \
457 ((Type *)(&ValueMask))->Field = 0; \
458 CpuRegisterTableWrite (ProcessorNumber, RegisterType, Index, ~ValueMask, Value); \
462 Adds a 32-bit register write entry in specified register table.
464 This macro adds an entry in specified register table, with given register type,
465 register index, and value.
467 @param[in] ProcessorNumber The index of the CPU to add a register table entry.
468 @param[in] RegisterType Type of the register to program
469 @param[in] Index Index of the register to program
470 @param[in] Value Value to write
472 @note This service could be called by BSP only.
474 #define PRE_SMM_CPU_REGISTER_TABLE_WRITE32(ProcessorNumber, RegisterType, Index, Value) \
476 PreSmmCpuRegisterTableWrite (ProcessorNumber, RegisterType, Index, MAX_UINT32, Value); \
480 Adds a 64-bit register write entry in specified register table.
482 This macro adds an entry in specified register table, with given register type,
483 register index, and value.
485 @param[in] ProcessorNumber The index of the CPU to add a register table entry.
486 @param[in] RegisterType Type of the register to program
487 @param[in] Index Index of the register to program
488 @param[in] Value Value to write
490 @note This service could be called by BSP only.
492 #define PRE_SMM_CPU_REGISTER_TABLE_WRITE64(ProcessorNumber, RegisterType, Index, Value) \
494 PreSmmCpuRegisterTableWrite (ProcessorNumber, RegisterType, Index, MAX_UINT64, Value); \
498 Adds a bit field write entry in specified register table.
500 This macro adds an entry in specified register table, with given register type,
501 register index, bit field section, and value.
503 @param[in] ProcessorNumber The index of the CPU to add a register table entry.
504 @param[in] RegisterType Type of the register to program.
505 @param[in] Index Index of the register to program.
506 @param[in] Type The data type name of a register structure.
507 @param[in] Field The bit fiel name in register structure to write.
508 @param[in] Value Value to write to the bit field.
510 @note This service could be called by BSP only.
512 #define PRE_SMM_CPU_REGISTER_TABLE_WRITE_FIELD(ProcessorNumber, RegisterType, Index, Type, Field, Value) \
515 ValueMask = MAX_UINT64; \
516 ((Type *)(&ValueMask))->Field = 0; \
517 PreSmmCpuRegisterTableWrite (ProcessorNumber, RegisterType, Index, ~ValueMask, Value); \