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_SENTER 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_AUTO_UNDEMOTION 19
49 #define CPU_FEATURE_C3_AUTO_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)
74 #define CPU_FEATURE_BEFORE_ALL BIT27
75 #define CPU_FEATURE_AFTER_ALL BIT28
76 #define CPU_FEATURE_BEFORE BIT29
77 #define CPU_FEATURE_AFTER BIT30
78 #define CPU_FEATURE_END MAX_UINT32
82 /// CPU Information passed into the SupportFunc and InitializeFunc of the
83 /// RegisterCpuFeature() library function. This structure contains information
84 /// that is commonly used during CPU feature detection and initialization.
88 /// The package that the CPU resides
90 EFI_PROCESSOR_INFORMATION ProcessorInfo
;
92 /// The Display Family of the CPU computed from CPUID leaf CPUID_VERSION_INFO
96 /// The Display Model of the CPU computed from CPUID leaf CPUID_VERSION_INFO
100 /// The Stepping ID of the CPU computed from CPUID leaf CPUID_VERSION_INFO
104 /// The Processor Type of the CPU computed from CPUID leaf CPUID_VERSION_INFO
106 UINT32 ProcessorType
;
108 /// Bit field structured returned in ECX from CPUID leaf CPUID_VERSION_INFO
110 CPUID_VERSION_INFO_ECX CpuIdVersionInfoEcx
;
112 /// Bit field structured returned in EDX from CPUID leaf CPUID_VERSION_INFO
114 CPUID_VERSION_INFO_EDX CpuIdVersionInfoEdx
;
115 } REGISTER_CPU_FEATURE_INFORMATION
;
118 Determines if a CPU feature is enabled in PcdCpuFeaturesSupport bit mask.
119 If a CPU feature is disabled in PcdCpuFeaturesSupport then all the code/data
120 associated with that feature should be optimized away if compiler
121 optimizations are enabled.
123 @param[in] Feature The bit number of the CPU feature to check in the PCD
124 PcdCpuFeaturesSupport.
126 @retval TRUE The CPU feature is set in PcdCpuFeaturesSupport.
127 @retval FALSE The CPU feature is not set in PcdCpuFeaturesSupport.
129 @note This service could be called by BSP only.
133 IsCpuFeatureSupported (
138 Determines if a CPU feature is set in PcdCpuFeaturesSetting bit mask.
140 @param[in] Feature The bit number of the CPU feature to check in the PCD
141 PcdCpuFeaturesSetting.
143 @retval TRUE The CPU feature is set in PcdCpuFeaturesSetting.
144 @retval FALSE The CPU feature is not set in PcdCpuFeaturesSetting.
146 @note This service could be called by BSP only.
150 IsCpuFeatureInSetting (
155 Determines if a CPU feature is set in PcdCpuFeaturesCapability bit mask.
157 @param[in] Feature The bit number of the CPU feature to check in the PCD
158 PcdCpuFeaturesCapability.
160 @retval TRUE The CPU feature is set in PcdCpuFeaturesCapability.
161 @retval FALSE The CPU feature is not set in PcdCpuFeaturesCapability.
163 @note This service could be called by BSP only.
167 IsCpuFeatureCapability (
172 Determines if a CPU feature is set in PcdCpuFeaturesUserConfiguration bit mask.
174 @param[in] Feature The bit number of the CPU feature to check in the PCD
175 PcdCpuFeaturesUserConfiguration.
177 @retval TRUE The CPU feature is set in PcdCpuFeaturesUserConfiguration.
178 @retval FALSE The CPU feature is not set in PcdCpuFeaturesUserConfiguration.
180 @note This service could be called by BSP only.
184 IsCpuFeatureUserConfiguration (
189 Prepares for the data used by CPU feature detection and initialization.
191 @param[in] NumberOfProcessors The number of CPUs in the platform.
193 @return Pointer to a buffer of CPU related configuration data.
195 @note This service could be called by BSP only.
199 (EFIAPI
*CPU_FEATURE_GET_CONFIG_DATA
)(
200 IN UINTN NumberOfProcessors
204 Detects if CPU feature supported on current processor.
206 @param[in] ProcessorNumber The index of the CPU executing this function.
207 @param[in] CpuInfo A pointer to the REGISTER_CPU_FEATURE_INFORMATION
208 structure for the CPU executing this function.
209 @param[in] ConfigData A pointer to the configuration buffer returned
210 by CPU_FEATURE_GET_CONFIG_DATA. NULL if
211 CPU_FEATURE_GET_CONFIG_DATA was not provided in
212 RegisterCpuFeature().
214 @retval TRUE CPU feature is supported.
215 @retval FALSE CPU feature is not supported.
217 @note This service could be called by BSP/APs.
221 (EFIAPI
*CPU_FEATURE_SUPPORT
)(
222 IN UINTN ProcessorNumber
,
223 IN REGISTER_CPU_FEATURE_INFORMATION
*CpuInfo
,
224 IN VOID
*ConfigData OPTIONAL
228 Initializes CPU feature to specific state.
230 This service does not initialize hardware and only produces entries in the
231 Register Table for specified processor. Hardware initialization on BSP/APs
232 will be done in CpuFeaturesInitialize().
234 @param[in] ProcessorNumber The index of the CPU executing this function.
235 @param[in] CpuInfo A pointer to the REGISTER_CPU_FEATURE_INFORMATION
236 structure for the CPU executing this function.
237 @param[in] ConfigData A pointer to the configuration buffer returned
238 by CPU_FEATURE_GET_CONFIG_DATA. NULL if
239 CPU_FEATURE_GET_CONFIG_DATA was not provided in
240 RegisterCpuFeature().
241 @param[in] State If TRUE, then the CPU feature must be enabled.
242 If FALSE, then the CPU feature must be disabled.
244 @retval RETURN_SUCCESS CPU feature is initialized.
246 @note This service could be called by BSP only.
250 (EFIAPI
*CPU_FEATURE_INITIALIZE
)(
251 IN UINTN ProcessorNumber
,
252 IN REGISTER_CPU_FEATURE_INFORMATION
*CpuInfo
,
253 IN VOID
*ConfigData
, OPTIONAL
258 Registers a CPU Feature.
260 @param[in] FeatureName A Null-terminated Ascii string indicates CPU feature
262 @param[in] GetConfigDataFunc CPU feature get configuration data function. This
263 is an optional parameter that may be NULL. If NULL,
264 then the most recently registered function for the
265 CPU feature is used. If no functions are registered
266 for a CPU feature, then the CPU configuration data
267 for the registered feature is NULL.
268 @param[in] SupportFunc CPU feature support function. This is an optional
269 parameter that may be NULL. If NULL, then the most
270 recently registered function for the CPU feature is
271 used. If no functions are registered for a CPU
272 feature, then the CPU feature is assumed to be
273 supported by all CPUs.
274 @param[in] InitializeFunc CPU feature initialize function. This is an optional
275 parameter that may be NULL. If NULL, then the most
276 recently registered function for the CPU feature is
277 used. If no functions are registered for a CPU
278 feature, then the CPU feature initialization is
280 @param[in] ... Variable argument list of UINT32 CPU feature value.
281 Values with no modifiers are the features provided
282 by the registered functions.
283 Values with CPU_FEATURE_BEFORE modifier are features
284 that must be initialized after the features provided
285 by the registered functions are used.
286 Values with CPU_FEATURE_AFTER modifier are features
287 that must be initialized before the features provided
288 by the registered functions are used.
289 The last argument in this variable argument list must
290 always be CPU_FEATURE_END.
292 @retval RETURN_SUCCESS The CPU feature was successfully registered.
293 @retval RETURN_OUT_OF_RESOURCES There are not enough resources to register
295 @retval RETURN_UNSUPPORTED Registration of the CPU feature is not
296 supported due to a circular dependency between
297 BEFORE and AFTER features.
299 @note This service could be called by BSP only.
304 IN CHAR8
*FeatureName
, OPTIONAL
305 IN CPU_FEATURE_GET_CONFIG_DATA GetConfigDataFunc
, OPTIONAL
306 IN CPU_FEATURE_SUPPORT SupportFunc
, OPTIONAL
307 IN CPU_FEATURE_INITIALIZE InitializeFunc
, OPTIONAL
312 Performs CPU features detection.
314 This service will invoke MP service to check CPU features'
315 capabilities on BSP/APs.
317 @note This service could be called by BSP only.
326 Performs CPU features Initialization.
328 This service will invoke MP service to perform CPU features
329 initialization on BSP/APs per user configuration.
331 @note This service could be called by BSP only.
335 CpuFeaturesInitialize (
340 Switches to assigned BSP after CPU features initialization.
342 @param[in] ProcessorNumber The index of the CPU executing this function.
344 @note This service could be called by BSP only.
348 SwitchBspAfterFeaturesInitialize (
349 IN UINTN ProcessorNumber
353 Adds an entry in specified register table.
355 This function adds an entry in specified register table, with given register type,
356 register index, bit section and value.
358 @param[in] ProcessorNumber The index of the CPU to add a register table entry.
359 @param[in] RegisterType Type of the register to program
360 @param[in] Index Index of the register to program
361 @param[in] ValueMask Mask of bits in register to write
362 @param[in] Value Value to write
364 @note This service could be called by BSP only.
368 CpuRegisterTableWrite (
369 IN UINTN ProcessorNumber
,
370 IN REGISTER_TYPE RegisterType
,
377 Adds an entry in specified Pre-SMM register table.
379 This function adds an entry in specified register table, with given register type,
380 register index, bit section and value.
382 @param[in] ProcessorNumber The index of the CPU to add a register table entry.
383 @param[in] RegisterType Type of the register to program
384 @param[in] Index Index of the register to program
385 @param[in] ValueMask Mask of bits in register to write
386 @param[in] Value Value to write
388 @note This service could be called by BSP only.
392 PreSmmCpuRegisterTableWrite (
393 IN UINTN ProcessorNumber
,
394 IN REGISTER_TYPE RegisterType
,
401 Adds a 32-bit register write entry in specified register table.
403 This macro adds an entry in specified register table, with given register type,
404 register index, and value.
406 @param[in] ProcessorNumber The index of the CPU to add a register table entry.
407 @param[in] RegisterType Type of the register to program
408 @param[in] Index Index of the register to program
409 @param[in] Value Value to write
411 @note This service could be called by BSP only.
413 #define CPU_REGISTER_TABLE_WRITE32(ProcessorNumber, RegisterType, Index, Value) \
415 CpuRegisterTableWrite (ProcessorNumber, RegisterType, Index, MAX_UINT32, Value); \
419 Adds a 64-bit register write entry in specified register table.
421 This macro adds an entry in specified register table, with given register type,
422 register index, and value.
424 @param[in] ProcessorNumber The index of the CPU to add a register table entry.
425 @param[in] RegisterType Type of the register to program
426 @param[in] Index Index of the register to program
427 @param[in] Value Value to write
429 @note This service could be called by BSP only.
431 #define CPU_REGISTER_TABLE_WRITE64(ProcessorNumber, RegisterType, Index, Value) \
433 CpuRegisterTableWrite (ProcessorNumber, RegisterType, Index, MAX_UINT64, Value); \
437 Adds a bit field write entry in specified register table.
439 This macro adds an entry in specified register table, with given register type,
440 register index, bit field section, and value.
442 @param[in] ProcessorNumber The index of the CPU to add a register table entry.
443 @param[in] RegisterType Type of the register to program.
444 @param[in] Index Index of the register to program.
445 @param[in] Type The data type name of a register structure.
446 @param[in] Field The bit fiel name in register structure to write.
447 @param[in] Value Value to write to the bit field.
449 @note This service could be called by BSP only.
451 #define CPU_REGISTER_TABLE_WRITE_FIELD(ProcessorNumber, RegisterType, Index, Type, Field, Value) \
454 ValueMask = MAX_UINT64; \
455 ((Type *)(&ValueMask))->Field = 0; \
456 CpuRegisterTableWrite (ProcessorNumber, RegisterType, Index, ~ValueMask, Value); \
460 Adds a 32-bit register write entry in specified register table.
462 This macro adds an entry in specified register table, with given register type,
463 register index, and value.
465 @param[in] ProcessorNumber The index of the CPU to add a register table entry.
466 @param[in] RegisterType Type of the register to program
467 @param[in] Index Index of the register to program
468 @param[in] Value Value to write
470 @note This service could be called by BSP only.
472 #define PRE_SMM_CPU_REGISTER_TABLE_WRITE32(ProcessorNumber, RegisterType, Index, Value) \
474 PreSmmCpuRegisterTableWrite (ProcessorNumber, RegisterType, Index, MAX_UINT32, Value); \
478 Adds a 64-bit register write entry in specified register table.
480 This macro adds an entry in specified register table, with given register type,
481 register index, and value.
483 @param[in] ProcessorNumber The index of the CPU to add a register table entry.
484 @param[in] RegisterType Type of the register to program
485 @param[in] Index Index of the register to program
486 @param[in] Value Value to write
488 @note This service could be called by BSP only.
490 #define PRE_SMM_CPU_REGISTER_TABLE_WRITE64(ProcessorNumber, RegisterType, Index, Value) \
492 PreSmmCpuRegisterTableWrite (ProcessorNumber, RegisterType, Index, MAX_UINT64, Value); \
496 Adds a bit field write entry in specified register table.
498 This macro adds an entry in specified register table, with given register type,
499 register index, bit field section, and value.
501 @param[in] ProcessorNumber The index of the CPU to add a register table entry.
502 @param[in] RegisterType Type of the register to program.
503 @param[in] Index Index of the register to program.
504 @param[in] Type The data type name of a register structure.
505 @param[in] Field The bit fiel name in register structure to write.
506 @param[in] Value Value to write to the bit field.
508 @note This service could be called by BSP only.
510 #define PRE_SMM_CPU_REGISTER_TABLE_WRITE_FIELD(ProcessorNumber, RegisterType, Index, Type, Field, Value) \
513 ValueMask = MAX_UINT64; \
514 ((Type *)(&ValueMask))->Field = 0; \
515 PreSmmCpuRegisterTableWrite (ProcessorNumber, RegisterType, Index, ~ValueMask, Value); \