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 BIT23
77 #define CPU_FEATURE_AFTER_ALL BIT24
79 // CPU_FEATURE_BEFORE and CPU_FEATURE_AFTER only mean Thread scope
80 // before and Thread scope after.
81 // It will be replace with CPU_FEATURE_THREAD_BEFORE and
82 // CPU_FEATURE_THREAD_AFTER, and should not be used anymore.
84 #define CPU_FEATURE_BEFORE BIT25
85 #define CPU_FEATURE_AFTER BIT26
87 #define CPU_FEATURE_THREAD_BEFORE CPU_FEATURE_BEFORE
88 #define CPU_FEATURE_THREAD_AFTER CPU_FEATURE_AFTER
89 #define CPU_FEATURE_CORE_BEFORE BIT27
90 #define CPU_FEATURE_CORE_AFTER BIT28
91 #define CPU_FEATURE_PACKAGE_BEFORE BIT29
92 #define CPU_FEATURE_PACKAGE_AFTER BIT30
93 #define CPU_FEATURE_END MAX_UINT32
97 /// CPU Information passed into the SupportFunc and InitializeFunc of the
98 /// RegisterCpuFeature() library function. This structure contains information
99 /// that is commonly used during CPU feature detection and initialization.
103 /// The package that the CPU resides
105 EFI_PROCESSOR_INFORMATION ProcessorInfo
;
107 /// The Display Family of the CPU computed from CPUID leaf CPUID_VERSION_INFO
109 UINT32 DisplayFamily
;
111 /// The Display Model of the CPU computed from CPUID leaf CPUID_VERSION_INFO
115 /// The Stepping ID of the CPU computed from CPUID leaf CPUID_VERSION_INFO
119 /// The Processor Type of the CPU computed from CPUID leaf CPUID_VERSION_INFO
121 UINT32 ProcessorType
;
123 /// Bit field structured returned in ECX from CPUID leaf CPUID_VERSION_INFO
125 CPUID_VERSION_INFO_ECX CpuIdVersionInfoEcx
;
127 /// Bit field structured returned in EDX from CPUID leaf CPUID_VERSION_INFO
129 CPUID_VERSION_INFO_EDX CpuIdVersionInfoEdx
;
130 } REGISTER_CPU_FEATURE_INFORMATION
;
133 Determines if a CPU feature is enabled in PcdCpuFeaturesSupport bit mask.
134 If a CPU feature is disabled in PcdCpuFeaturesSupport then all the code/data
135 associated with that feature should be optimized away if compiler
136 optimizations are enabled.
138 @param[in] Feature The bit number of the CPU feature to check in the PCD
139 PcdCpuFeaturesSupport.
141 @retval TRUE The CPU feature is set in PcdCpuFeaturesSupport.
142 @retval FALSE The CPU feature is not set in PcdCpuFeaturesSupport.
144 @note This service could be called by BSP only.
148 IsCpuFeatureSupported (
153 Determines if a CPU feature is set in PcdCpuFeaturesSetting bit mask.
155 @param[in] Feature The bit number of the CPU feature to check in the PCD
156 PcdCpuFeaturesSetting.
158 @retval TRUE The CPU feature is set in PcdCpuFeaturesSetting.
159 @retval FALSE The CPU feature is not set in PcdCpuFeaturesSetting.
161 @note This service could be called by BSP only.
165 IsCpuFeatureInSetting (
170 Determines if a CPU feature is set in PcdCpuFeaturesCapability bit mask.
172 @param[in] Feature The bit number of the CPU feature to check in the PCD
173 PcdCpuFeaturesCapability.
175 @retval TRUE The CPU feature is set in PcdCpuFeaturesCapability.
176 @retval FALSE The CPU feature is not set in PcdCpuFeaturesCapability.
178 @note This service could be called by BSP only.
182 IsCpuFeatureCapability (
187 Determines if a CPU feature is set in PcdCpuFeaturesUserConfiguration bit mask.
189 @param[in] Feature The bit number of the CPU feature to check in the PCD
190 PcdCpuFeaturesUserConfiguration.
192 @retval TRUE The CPU feature is set in PcdCpuFeaturesUserConfiguration.
193 @retval FALSE The CPU feature is not set in PcdCpuFeaturesUserConfiguration.
195 @note This service could be called by BSP only.
199 IsCpuFeatureUserConfiguration (
204 Prepares for the data used by CPU feature detection and initialization.
206 @param[in] NumberOfProcessors The number of CPUs in the platform.
208 @return Pointer to a buffer of CPU related configuration data.
210 @note This service could be called by BSP only.
214 (EFIAPI
*CPU_FEATURE_GET_CONFIG_DATA
)(
215 IN UINTN NumberOfProcessors
219 Detects if CPU feature supported on current processor.
221 @param[in] ProcessorNumber The index of the CPU executing this function.
222 @param[in] CpuInfo A pointer to the REGISTER_CPU_FEATURE_INFORMATION
223 structure for the CPU executing this function.
224 @param[in] ConfigData A pointer to the configuration buffer returned
225 by CPU_FEATURE_GET_CONFIG_DATA. NULL if
226 CPU_FEATURE_GET_CONFIG_DATA was not provided in
227 RegisterCpuFeature().
229 @retval TRUE CPU feature is supported.
230 @retval FALSE CPU feature is not supported.
232 @note This service could be called by BSP/APs.
236 (EFIAPI
*CPU_FEATURE_SUPPORT
)(
237 IN UINTN ProcessorNumber
,
238 IN REGISTER_CPU_FEATURE_INFORMATION
*CpuInfo
,
239 IN VOID
*ConfigData OPTIONAL
243 Initializes CPU feature to specific state.
245 This service does not initialize hardware and only produces entries in the
246 Register Table for specified processor. Hardware initialization on BSP/APs
247 will be done in CpuFeaturesInitialize().
249 @param[in] ProcessorNumber The index of the CPU executing this function.
250 @param[in] CpuInfo A pointer to the REGISTER_CPU_FEATURE_INFORMATION
251 structure for the CPU executing this function.
252 @param[in] ConfigData A pointer to the configuration buffer returned
253 by CPU_FEATURE_GET_CONFIG_DATA. NULL if
254 CPU_FEATURE_GET_CONFIG_DATA was not provided in
255 RegisterCpuFeature().
256 @param[in] State If TRUE, then the CPU feature must be enabled.
257 If FALSE, then the CPU feature must be disabled.
259 @retval RETURN_SUCCESS CPU feature is initialized.
261 @note This service could be called by BSP only.
265 (EFIAPI
*CPU_FEATURE_INITIALIZE
)(
266 IN UINTN ProcessorNumber
,
267 IN REGISTER_CPU_FEATURE_INFORMATION
*CpuInfo
,
268 IN VOID
*ConfigData
, OPTIONAL
273 Registers a CPU Feature.
275 @param[in] FeatureName A Null-terminated Ascii string indicates CPU feature
277 @param[in] GetConfigDataFunc CPU feature get configuration data function. This
278 is an optional parameter that may be NULL. If NULL,
279 then the most recently registered function for the
280 CPU feature is used. If no functions are registered
281 for a CPU feature, then the CPU configuration data
282 for the registered feature is NULL.
283 @param[in] SupportFunc CPU feature support function. This is an optional
284 parameter that may be NULL. If NULL, then the most
285 recently registered function for the CPU feature is
286 used. If no functions are registered for a CPU
287 feature, then the CPU feature is assumed to be
288 supported by all CPUs.
289 @param[in] InitializeFunc CPU feature initialize function. This is an optional
290 parameter that may be NULL. If NULL, then the most
291 recently registered function for the CPU feature is
292 used. If no functions are registered for a CPU
293 feature, then the CPU feature initialization is
295 @param[in] ... Variable argument list of UINT32 CPU feature value.
296 Values with no modifiers are the features provided
297 by the registered functions.
298 Values with CPU_FEATURE_BEFORE modifier are features
299 that must be initialized after the features provided
300 by the registered functions are used.
301 Values with CPU_FEATURE_AFTER modifier are features
302 that must be initialized before the features provided
303 by the registered functions are used.
304 The last argument in this variable argument list must
305 always be CPU_FEATURE_END.
307 @retval RETURN_SUCCESS The CPU feature was successfully registered.
308 @retval RETURN_OUT_OF_RESOURCES There are not enough resources to register
310 @retval RETURN_UNSUPPORTED Registration of the CPU feature is not
311 supported due to a circular dependency between
312 BEFORE and AFTER features.
314 @note This service could be called by BSP only.
319 IN CHAR8
*FeatureName
, OPTIONAL
320 IN CPU_FEATURE_GET_CONFIG_DATA GetConfigDataFunc
, OPTIONAL
321 IN CPU_FEATURE_SUPPORT SupportFunc
, OPTIONAL
322 IN CPU_FEATURE_INITIALIZE InitializeFunc
, OPTIONAL
327 Performs CPU features detection.
329 This service will invoke MP service to check CPU features'
330 capabilities on BSP/APs.
332 @note This service could be called by BSP only.
341 Performs CPU features Initialization.
343 This service will invoke MP service to perform CPU features
344 initialization on BSP/APs per user configuration.
346 @note This service could be called by BSP only.
350 CpuFeaturesInitialize (
355 Switches to assigned BSP after CPU features initialization.
357 @param[in] ProcessorNumber The index of the CPU executing this function.
359 @note This service could be called by BSP only.
363 SwitchBspAfterFeaturesInitialize (
364 IN UINTN ProcessorNumber
368 Adds an entry in specified register table.
370 This function adds an entry in specified register table, with given register type,
371 register index, bit section and value.
373 @param[in] ProcessorNumber The index of the CPU to add a register table entry.
374 @param[in] RegisterType Type of the register to program
375 @param[in] Index Index of the register to program
376 @param[in] ValueMask Mask of bits in register to write
377 @param[in] Value Value to write
379 @note This service could be called by BSP only.
383 CpuRegisterTableWrite (
384 IN UINTN ProcessorNumber
,
385 IN REGISTER_TYPE RegisterType
,
392 Adds an entry in specified Pre-SMM register table.
394 This function adds an entry in specified register table, with given register type,
395 register index, bit section and value.
397 @param[in] ProcessorNumber The index of the CPU to add a register table entry.
398 @param[in] RegisterType Type of the register to program
399 @param[in] Index Index of the register to program
400 @param[in] ValueMask Mask of bits in register to write
401 @param[in] Value Value to write
403 @note This service could be called by BSP only.
407 PreSmmCpuRegisterTableWrite (
408 IN UINTN ProcessorNumber
,
409 IN REGISTER_TYPE RegisterType
,
416 Adds a 32-bit register write entry in specified register table.
418 This macro adds an entry in specified register table, with given register type,
419 register index, and value.
421 @param[in] ProcessorNumber The index of the CPU to add a register table entry.
422 @param[in] RegisterType Type of the register to program
423 @param[in] Index Index of the register to program
424 @param[in] Value Value to write
426 @note This service could be called by BSP only.
428 #define CPU_REGISTER_TABLE_WRITE32(ProcessorNumber, RegisterType, Index, Value) \
430 CpuRegisterTableWrite (ProcessorNumber, RegisterType, Index, MAX_UINT32, Value); \
434 Adds a 64-bit register write entry in specified register table.
436 This macro adds an entry in specified register table, with given register type,
437 register index, and value.
439 @param[in] ProcessorNumber The index of the CPU to add a register table entry.
440 @param[in] RegisterType Type of the register to program
441 @param[in] Index Index of the register to program
442 @param[in] Value Value to write
444 @note This service could be called by BSP only.
446 #define CPU_REGISTER_TABLE_WRITE64(ProcessorNumber, RegisterType, Index, Value) \
448 CpuRegisterTableWrite (ProcessorNumber, RegisterType, Index, MAX_UINT64, Value); \
452 Adds a bit field write entry in specified register table.
454 This macro adds an entry in specified register table, with given register type,
455 register index, bit field section, and value.
457 @param[in] ProcessorNumber The index of the CPU to add a register table entry.
458 @param[in] RegisterType Type of the register to program.
459 @param[in] Index Index of the register to program.
460 @param[in] Type The data type name of a register structure.
461 @param[in] Field The bit fiel name in register structure to write.
462 @param[in] Value Value to write to the bit field.
464 @note This service could be called by BSP only.
466 #define CPU_REGISTER_TABLE_WRITE_FIELD(ProcessorNumber, RegisterType, Index, Type, Field, Value) \
469 ValueMask = MAX_UINT64; \
470 ((Type *)(&ValueMask))->Field = 0; \
471 CpuRegisterTableWrite (ProcessorNumber, RegisterType, Index, ~ValueMask, Value); \
475 Adds a 32-bit register write entry in specified register table.
477 This macro adds an entry in specified register table, with given register type,
478 register index, and value.
480 @param[in] ProcessorNumber The index of the CPU to add a register table entry.
481 @param[in] RegisterType Type of the register to program
482 @param[in] Index Index of the register to program
483 @param[in] Value Value to write
485 @note This service could be called by BSP only.
487 #define PRE_SMM_CPU_REGISTER_TABLE_WRITE32(ProcessorNumber, RegisterType, Index, Value) \
489 PreSmmCpuRegisterTableWrite (ProcessorNumber, RegisterType, Index, MAX_UINT32, Value); \
493 Adds a 64-bit register write entry in specified register table.
495 This macro adds an entry in specified register table, with given register type,
496 register index, and value.
498 @param[in] ProcessorNumber The index of the CPU to add a register table entry.
499 @param[in] RegisterType Type of the register to program
500 @param[in] Index Index of the register to program
501 @param[in] Value Value to write
503 @note This service could be called by BSP only.
505 #define PRE_SMM_CPU_REGISTER_TABLE_WRITE64(ProcessorNumber, RegisterType, Index, Value) \
507 PreSmmCpuRegisterTableWrite (ProcessorNumber, RegisterType, Index, MAX_UINT64, Value); \
511 Adds a bit field write entry in specified register table.
513 This macro adds an entry in specified register table, with given register type,
514 register index, bit field section, and value.
516 @param[in] ProcessorNumber The index of the CPU to add a register table entry.
517 @param[in] RegisterType Type of the register to program.
518 @param[in] Index Index of the register to program.
519 @param[in] Type The data type name of a register structure.
520 @param[in] Field The bit fiel name in register structure to write.
521 @param[in] Value Value to write to the bit field.
523 @note This service could be called by BSP only.
525 #define PRE_SMM_CPU_REGISTER_TABLE_WRITE_FIELD(ProcessorNumber, RegisterType, Index, Type, Field, Value) \
528 ValueMask = MAX_UINT64; \
529 ((Type *)(&ValueMask))->Field = 0; \
530 PreSmmCpuRegisterTableWrite (ProcessorNumber, RegisterType, Index, ~ValueMask, Value); \