2 Register CPU Features Library to register and manage CPU features.
4 Copyright (c) 2017 - 2019, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
9 #ifndef __REGISTER_CPU_FEATURES_LIB_H__
10 #define __REGISTER_CPU_FEATURES_LIB_H__
12 #include <AcpiCpuData.h>
13 #include <Register/Cpuid.h>
14 #include <Protocol/MpService.h>
17 /// Defines used to identify a CPU feature. The lower 16-bits are used to
18 /// identify a unique CPU feature and the value represents a bit number in
19 /// a bit mask. The upper 16-bits are bit mask values that are used as
20 /// modifiers of a CPU feature. When used in a list, the define value
21 /// CPU_FEATURE_END is used to terminate a list of CPU feature values.
23 #define CPU_FEATURE_AESNI 0
24 #define CPU_FEATURE_TURBO_MODE 1
25 #define CPU_FEATURE_MWAIT 2
26 #define CPU_FEATURE_ACPI 3
27 #define CPU_FEATURE_EIST 4
28 #define CPU_FEATURE_XD 5
29 #define CPU_FEATURE_FASTSTRINGS 6
30 #define CPU_FEATURE_VMX 7
31 #define CPU_FEATURE_SMX 8
32 #define CPU_FEATURE_LMCE 9
33 #define CPU_FEATURE_LOCK_FEATURE_CONTROL_REGISTER 10
34 #define CPU_FEATURE_LIMIT_CPUID_MAX_VAL 11
35 #define CPU_FEATURE_MCE 12
36 #define CPU_FEATURE_MCA 13
37 #define CPU_FEATURE_MCG_CTL 14
38 #define CPU_FEATURE_PENDING_BREAK 15
39 #define CPU_FEATURE_C1E 16
40 #define CPU_FEATURE_C1_AUTO_DEMOTION 17
41 #define CPU_FEATURE_C3_AUTO_DEMOTION 18
42 #define CPU_FEATURE_C1_UNDEMOTION 19
43 #define CPU_FEATURE_C3_UNDEMOTION 20
44 #define CPU_FEATURE_C_STATE 21
45 #define CPU_FEATURE_TM 22
46 #define CPU_FEATURE_TM2 23
47 #define CPU_FEATURE_X2APIC 24
48 #define CPU_FEATURE_RESERVED_25 25
49 #define CPU_FEATURE_RESERVED_26 26
50 #define CPU_FEATURE_RESERVED_27 27
51 #define CPU_FEATURE_RESERVED_28 28
52 #define CPU_FEATURE_RESERVED_29 29
53 #define CPU_FEATURE_RESERVED_30 30
54 #define CPU_FEATURE_RESERVED_31 31
56 #define CPU_FEATURE_L2_PREFETCHER (32+0)
57 #define CPU_FEATURE_L1_DATA_PREFETCHER (32+1)
58 #define CPU_FEATURE_HARDWARE_PREFETCHER (32+2)
59 #define CPU_FEATURE_ADJACENT_CACHE_LINE_PREFETCH (32+3)
60 #define CPU_FEATURE_DCU_PREFETCHER (32+4)
61 #define CPU_FEATURE_IP_PREFETCHER (32+5)
62 #define CPU_FEATURE_MLC_STREAMER_PREFETCHER (32+6)
63 #define CPU_FEATURE_MLC_SPATIAL_PREFETCHER (32+7)
64 #define CPU_FEATURE_THREE_STRICK_COUNTER (32+8)
65 #define CPU_FEATURE_APIC_TPR_UPDATE_MESSAGE (32+9)
66 #define CPU_FEATURE_ENERGY_PERFORMANCE_BIAS (32+10)
67 #define CPU_FEATURE_PPIN (32+11)
68 #define CPU_FEATURE_PROC_TRACE (32+12)
70 #define CPU_FEATURE_BEFORE_ALL BIT23
71 #define CPU_FEATURE_AFTER_ALL BIT24
73 // CPU_FEATURE_BEFORE and CPU_FEATURE_AFTER only mean Thread scope
74 // before and Thread scope after.
75 // It will be replace with CPU_FEATURE_THREAD_BEFORE and
76 // CPU_FEATURE_THREAD_AFTER, and should not be used anymore.
78 #define CPU_FEATURE_BEFORE BIT25
79 #define CPU_FEATURE_AFTER BIT26
81 #define CPU_FEATURE_THREAD_BEFORE CPU_FEATURE_BEFORE
82 #define CPU_FEATURE_THREAD_AFTER CPU_FEATURE_AFTER
83 #define CPU_FEATURE_CORE_BEFORE BIT27
84 #define CPU_FEATURE_CORE_AFTER BIT28
85 #define CPU_FEATURE_PACKAGE_BEFORE BIT29
86 #define CPU_FEATURE_PACKAGE_AFTER BIT30
87 #define CPU_FEATURE_END MAX_UINT32
91 /// CPU Information passed into the SupportFunc and InitializeFunc of the
92 /// RegisterCpuFeature() library function. This structure contains information
93 /// that is commonly used during CPU feature detection and initialization.
97 /// The package that the CPU resides
99 EFI_PROCESSOR_INFORMATION ProcessorInfo
;
101 /// The Display Family of the CPU computed from CPUID leaf CPUID_VERSION_INFO
103 UINT32 DisplayFamily
;
105 /// The Display Model of the CPU computed from CPUID leaf CPUID_VERSION_INFO
109 /// The Stepping ID of the CPU computed from CPUID leaf CPUID_VERSION_INFO
113 /// The Processor Type of the CPU computed from CPUID leaf CPUID_VERSION_INFO
115 UINT32 ProcessorType
;
117 /// Bit field structured returned in ECX from CPUID leaf CPUID_VERSION_INFO
119 CPUID_VERSION_INFO_ECX CpuIdVersionInfoEcx
;
121 /// Bit field structured returned in EDX from CPUID leaf CPUID_VERSION_INFO
123 CPUID_VERSION_INFO_EDX CpuIdVersionInfoEdx
;
124 } REGISTER_CPU_FEATURE_INFORMATION
;
127 Determines if a CPU feature is enabled in PcdCpuFeaturesSupport bit mask.
128 If a CPU feature is disabled in PcdCpuFeaturesSupport then all the code/data
129 associated with that feature should be optimized away if compiler
130 optimizations are enabled.
132 @param[in] Feature The bit number of the CPU feature to check in the PCD
133 PcdCpuFeaturesSupport.
135 @retval TRUE The CPU feature is set in PcdCpuFeaturesSupport.
136 @retval FALSE The CPU feature is not set in PcdCpuFeaturesSupport.
138 @note This service could be called by BSP only.
142 IsCpuFeatureSupported (
147 Determines if a CPU feature is set in PcdCpuFeaturesSetting bit mask.
149 @param[in] Feature The bit number of the CPU feature to check in the PCD
150 PcdCpuFeaturesSetting.
152 @retval TRUE The CPU feature is set in PcdCpuFeaturesSetting.
153 @retval FALSE The CPU feature is not set in PcdCpuFeaturesSetting.
155 @note This service could be called by BSP only.
159 IsCpuFeatureInSetting (
164 Prepares for the data used by CPU feature detection and initialization.
166 @param[in] NumberOfProcessors The number of CPUs in the platform.
168 @return Pointer to a buffer of CPU related configuration data.
170 @note This service could be called by BSP only.
174 (EFIAPI
*CPU_FEATURE_GET_CONFIG_DATA
)(
175 IN UINTN NumberOfProcessors
179 Detects if CPU feature supported on current processor.
181 @param[in] ProcessorNumber The index of the CPU executing this function.
182 @param[in] CpuInfo A pointer to the REGISTER_CPU_FEATURE_INFORMATION
183 structure for the CPU executing this function.
184 @param[in] ConfigData A pointer to the configuration buffer returned
185 by CPU_FEATURE_GET_CONFIG_DATA. NULL if
186 CPU_FEATURE_GET_CONFIG_DATA was not provided in
187 RegisterCpuFeature().
189 @retval TRUE CPU feature is supported.
190 @retval FALSE CPU feature is not supported.
192 @note This service could be called by BSP/APs.
196 (EFIAPI
*CPU_FEATURE_SUPPORT
)(
197 IN UINTN ProcessorNumber
,
198 IN REGISTER_CPU_FEATURE_INFORMATION
*CpuInfo
,
199 IN VOID
*ConfigData OPTIONAL
203 Initializes CPU feature to specific state.
205 This service does not initialize hardware and only produces entries in the
206 Register Table for specified processor. Hardware initialization on BSP/APs
207 will be done in CpuFeaturesInitialize().
209 @param[in] ProcessorNumber The index of the CPU executing this function.
210 @param[in] CpuInfo A pointer to the REGISTER_CPU_FEATURE_INFORMATION
211 structure for the CPU executing this function.
212 @param[in] ConfigData A pointer to the configuration buffer returned
213 by CPU_FEATURE_GET_CONFIG_DATA. NULL if
214 CPU_FEATURE_GET_CONFIG_DATA was not provided in
215 RegisterCpuFeature().
216 @param[in] State If TRUE, then the CPU feature must be enabled.
217 If FALSE, then the CPU feature must be disabled.
219 @retval RETURN_SUCCESS CPU feature is initialized.
221 @note This service could be called by BSP only.
225 (EFIAPI
*CPU_FEATURE_INITIALIZE
)(
226 IN UINTN ProcessorNumber
,
227 IN REGISTER_CPU_FEATURE_INFORMATION
*CpuInfo
,
228 IN VOID
*ConfigData
, OPTIONAL
233 Registers a CPU Feature.
235 @param[in] FeatureName A Null-terminated Ascii string indicates CPU feature
237 @param[in] GetConfigDataFunc CPU feature get configuration data function. This
238 is an optional parameter that may be NULL. If NULL,
239 then the most recently registered function for the
240 CPU feature is used. If no functions are registered
241 for a CPU feature, then the CPU configuration data
242 for the registered feature is NULL.
243 @param[in] SupportFunc CPU feature support function. This is an optional
244 parameter that may be NULL. If NULL, then the most
245 recently registered function for the CPU feature is
246 used. If no functions are registered for a CPU
247 feature, then the CPU feature is assumed to be
248 supported by all CPUs.
249 @param[in] InitializeFunc CPU feature initialize function. This is an optional
250 parameter that may be NULL. If NULL, then the most
251 recently registered function for the CPU feature is
252 used. If no functions are registered for a CPU
253 feature, then the CPU feature initialization is
255 @param[in] ... Variable argument list of UINT32 CPU feature value.
256 Values with no modifiers are the features provided
257 by the registered functions.
258 Values with CPU_FEATURE_BEFORE modifier are features
259 that must be initialized after the features provided
260 by the registered functions are used.
261 Values with CPU_FEATURE_AFTER modifier are features
262 that must be initialized before the features provided
263 by the registered functions are used.
264 The last argument in this variable argument list must
265 always be CPU_FEATURE_END.
267 @retval RETURN_SUCCESS The CPU feature was successfully registered.
268 @retval RETURN_OUT_OF_RESOURCES There are not enough resources to register
270 @retval RETURN_UNSUPPORTED Registration of the CPU feature is not
271 supported due to a circular dependency between
272 BEFORE and AFTER features.
274 @note This service could be called by BSP only.
279 IN CHAR8
*FeatureName
, OPTIONAL
280 IN CPU_FEATURE_GET_CONFIG_DATA GetConfigDataFunc
, OPTIONAL
281 IN CPU_FEATURE_SUPPORT SupportFunc
, OPTIONAL
282 IN CPU_FEATURE_INITIALIZE InitializeFunc
, OPTIONAL
287 Performs CPU features detection.
289 This service will invoke MP service to check CPU features'
290 capabilities on BSP/APs.
292 @note This service could be called by BSP only.
301 Performs CPU features Initialization.
303 This service will invoke MP service to perform CPU features
304 initialization on BSP/APs per user configuration.
306 @note This service could be called by BSP only.
310 CpuFeaturesInitialize (
315 Switches to assigned BSP after CPU features initialization.
317 @param[in] ProcessorNumber The index of the CPU executing this function.
319 @note This service could be called by BSP only.
323 SwitchBspAfterFeaturesInitialize (
324 IN UINTN ProcessorNumber
328 Adds an entry in specified register table.
330 This function adds an entry in specified register table, with given register type,
331 register index, bit section and value.
333 @param[in] ProcessorNumber The index of the CPU to add a register table entry.
334 @param[in] RegisterType Type of the register to program
335 @param[in] Index Index of the register to program
336 @param[in] ValueMask Mask of bits in register to write
337 @param[in] Value Value to write
339 @note This service could be called by BSP only.
343 CpuRegisterTableWrite (
344 IN UINTN ProcessorNumber
,
345 IN REGISTER_TYPE RegisterType
,
352 Adds an entry in specified Pre-SMM register table.
354 This function adds an entry in specified register table, with given register type,
355 register index, bit section and value.
357 @param[in] ProcessorNumber The index of the CPU to add a register table entry.
358 @param[in] RegisterType Type of the register to program
359 @param[in] Index Index of the register to program
360 @param[in] ValueMask Mask of bits in register to write
361 @param[in] Value Value to write
363 @note This service could be called by BSP only.
367 PreSmmCpuRegisterTableWrite (
368 IN UINTN ProcessorNumber
,
369 IN REGISTER_TYPE RegisterType
,
376 Adds a 32-bit register write entry in specified register table.
378 This macro adds an entry in specified register table, with given register type,
379 register index, and value.
381 @param[in] ProcessorNumber The index of the CPU to add a register table entry.
382 @param[in] RegisterType Type of the register to program
383 @param[in] Index Index of the register to program
384 @param[in] Value Value to write
386 @note This service could be called by BSP only.
388 #define CPU_REGISTER_TABLE_WRITE32(ProcessorNumber, RegisterType, Index, Value) \
390 CpuRegisterTableWrite (ProcessorNumber, RegisterType, Index, MAX_UINT32, Value); \
394 Adds a 64-bit register write entry in specified register table.
396 This macro adds an entry in specified register table, with given register type,
397 register index, and value.
399 @param[in] ProcessorNumber The index of the CPU to add a register table entry.
400 @param[in] RegisterType Type of the register to program
401 @param[in] Index Index of the register to program
402 @param[in] Value Value to write
404 @note This service could be called by BSP only.
406 #define CPU_REGISTER_TABLE_WRITE64(ProcessorNumber, RegisterType, Index, Value) \
408 CpuRegisterTableWrite (ProcessorNumber, RegisterType, Index, MAX_UINT64, Value); \
412 Adds a bit field write entry in specified register table.
414 This macro adds an entry in specified register table, with given register type,
415 register index, bit field section, and value.
417 @param[in] ProcessorNumber The index of the CPU to add a register table entry.
418 @param[in] RegisterType Type of the register to program.
419 @param[in] Index Index of the register to program.
420 @param[in] Type The data type name of a register structure.
421 @param[in] Field The bit fiel name in register structure to write.
422 @param[in] Value Value to write to the bit field.
424 @note This service could be called by BSP only.
426 #define CPU_REGISTER_TABLE_WRITE_FIELD(ProcessorNumber, RegisterType, Index, Type, Field, Value) \
429 ValueMask = MAX_UINT64; \
430 ((Type *)(&ValueMask))->Field = 0; \
431 CpuRegisterTableWrite (ProcessorNumber, RegisterType, Index, ~ValueMask, Value); \
435 Adds a 32-bit register write entry in specified register table.
437 This macro adds an entry in specified register table, with given register type,
438 register index, and value.
440 @param[in] ProcessorNumber The index of the CPU to add a register table entry.
441 @param[in] RegisterType Type of the register to program
442 @param[in] Index Index of the register to program
443 @param[in] Value Value to write
445 @note This service could be called by BSP only.
447 #define PRE_SMM_CPU_REGISTER_TABLE_WRITE32(ProcessorNumber, RegisterType, Index, Value) \
449 PreSmmCpuRegisterTableWrite (ProcessorNumber, RegisterType, Index, MAX_UINT32, Value); \
453 Adds a 64-bit register write entry in specified register table.
455 This macro adds an entry in specified register table, with given register type,
456 register index, and value.
458 @param[in] ProcessorNumber The index of the CPU to add a register table entry.
459 @param[in] RegisterType Type of the register to program
460 @param[in] Index Index of the register to program
461 @param[in] Value Value to write
463 @note This service could be called by BSP only.
465 #define PRE_SMM_CPU_REGISTER_TABLE_WRITE64(ProcessorNumber, RegisterType, Index, Value) \
467 PreSmmCpuRegisterTableWrite (ProcessorNumber, RegisterType, Index, MAX_UINT64, Value); \
471 Adds a bit field write entry in specified register table.
473 This macro adds an entry in specified register table, with given register type,
474 register index, bit field section, and value.
476 @param[in] ProcessorNumber The index of the CPU to add a register table entry.
477 @param[in] RegisterType Type of the register to program.
478 @param[in] Index Index of the register to program.
479 @param[in] Type The data type name of a register structure.
480 @param[in] Field The bit fiel name in register structure to write.
481 @param[in] Value Value to write to the bit field.
483 @note This service could be called by BSP only.
485 #define PRE_SMM_CPU_REGISTER_TABLE_WRITE_FIELD(ProcessorNumber, RegisterType, Index, Type, Field, Value) \
488 ValueMask = MAX_UINT64; \
489 ((Type *)(&ValueMask))->Field = 0; \
490 PreSmmCpuRegisterTableWrite (ProcessorNumber, RegisterType, Index, ~ValueMask, Value); \