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_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)
75 #define CPU_FEATURE_BEFORE_ALL BIT27
76 #define CPU_FEATURE_AFTER_ALL BIT28
77 #define CPU_FEATURE_BEFORE BIT29
78 #define CPU_FEATURE_AFTER BIT30
79 #define CPU_FEATURE_END MAX_UINT32
83 /// CPU Information passed into the SupportFunc and InitializeFunc of the
84 /// RegisterCpuFeature() library function. This structure contains information
85 /// that is commonly used during CPU feature detection and initialization.
89 /// The package that the CPU resides
91 EFI_PROCESSOR_INFORMATION ProcessorInfo
;
93 /// The Display Family of the CPU computed from CPUID leaf CPUID_VERSION_INFO
97 /// The Display Model of the CPU computed from CPUID leaf CPUID_VERSION_INFO
101 /// The Stepping ID of the CPU computed from CPUID leaf CPUID_VERSION_INFO
105 /// The Processor Type of the CPU computed from CPUID leaf CPUID_VERSION_INFO
107 UINT32 ProcessorType
;
109 /// Bit field structured returned in ECX from CPUID leaf CPUID_VERSION_INFO
111 CPUID_VERSION_INFO_ECX CpuIdVersionInfoEcx
;
113 /// Bit field structured returned in EDX from CPUID leaf CPUID_VERSION_INFO
115 CPUID_VERSION_INFO_EDX CpuIdVersionInfoEdx
;
116 } REGISTER_CPU_FEATURE_INFORMATION
;
119 Determines if a CPU feature is enabled in PcdCpuFeaturesSupport bit mask.
120 If a CPU feature is disabled in PcdCpuFeaturesSupport then all the code/data
121 associated with that feature should be optimized away if compiler
122 optimizations are enabled.
124 @param[in] Feature The bit number of the CPU feature to check in the PCD
125 PcdCpuFeaturesSupport.
127 @retval TRUE The CPU feature is set in PcdCpuFeaturesSupport.
128 @retval FALSE The CPU feature is not set in PcdCpuFeaturesSupport.
130 @note This service could be called by BSP only.
134 IsCpuFeatureSupported (
139 Determines if a CPU feature is set in PcdCpuFeaturesSetting bit mask.
141 @param[in] Feature The bit number of the CPU feature to check in the PCD
142 PcdCpuFeaturesSetting.
144 @retval TRUE The CPU feature is set in PcdCpuFeaturesSetting.
145 @retval FALSE The CPU feature is not set in PcdCpuFeaturesSetting.
147 @note This service could be called by BSP only.
151 IsCpuFeatureInSetting (
156 Determines if a CPU feature is set in PcdCpuFeaturesCapability bit mask.
158 @param[in] Feature The bit number of the CPU feature to check in the PCD
159 PcdCpuFeaturesCapability.
161 @retval TRUE The CPU feature is set in PcdCpuFeaturesCapability.
162 @retval FALSE The CPU feature is not set in PcdCpuFeaturesCapability.
164 @note This service could be called by BSP only.
168 IsCpuFeatureCapability (
173 Determines if a CPU feature is set in PcdCpuFeaturesUserConfiguration bit mask.
175 @param[in] Feature The bit number of the CPU feature to check in the PCD
176 PcdCpuFeaturesUserConfiguration.
178 @retval TRUE The CPU feature is set in PcdCpuFeaturesUserConfiguration.
179 @retval FALSE The CPU feature is not set in PcdCpuFeaturesUserConfiguration.
181 @note This service could be called by BSP only.
185 IsCpuFeatureUserConfiguration (
190 Prepares for the data used by CPU feature detection and initialization.
192 @param[in] NumberOfProcessors The number of CPUs in the platform.
194 @return Pointer to a buffer of CPU related configuration data.
196 @note This service could be called by BSP only.
200 (EFIAPI
*CPU_FEATURE_GET_CONFIG_DATA
)(
201 IN UINTN NumberOfProcessors
205 Detects if CPU feature supported on current processor.
207 @param[in] ProcessorNumber The index of the CPU executing this function.
208 @param[in] CpuInfo A pointer to the REGISTER_CPU_FEATURE_INFORMATION
209 structure for the CPU executing this function.
210 @param[in] ConfigData A pointer to the configuration buffer returned
211 by CPU_FEATURE_GET_CONFIG_DATA. NULL if
212 CPU_FEATURE_GET_CONFIG_DATA was not provided in
213 RegisterCpuFeature().
215 @retval TRUE CPU feature is supported.
216 @retval FALSE CPU feature is not supported.
218 @note This service could be called by BSP/APs.
222 (EFIAPI
*CPU_FEATURE_SUPPORT
)(
223 IN UINTN ProcessorNumber
,
224 IN REGISTER_CPU_FEATURE_INFORMATION
*CpuInfo
,
225 IN VOID
*ConfigData OPTIONAL
229 Initializes CPU feature to specific state.
231 This service does not initialize hardware and only produces entries in the
232 Register Table for specified processor. Hardware initialization on BSP/APs
233 will be done in CpuFeaturesInitialize().
235 @param[in] ProcessorNumber The index of the CPU executing this function.
236 @param[in] CpuInfo A pointer to the REGISTER_CPU_FEATURE_INFORMATION
237 structure for the CPU executing this function.
238 @param[in] ConfigData A pointer to the configuration buffer returned
239 by CPU_FEATURE_GET_CONFIG_DATA. NULL if
240 CPU_FEATURE_GET_CONFIG_DATA was not provided in
241 RegisterCpuFeature().
242 @param[in] State If TRUE, then the CPU feature must be enabled.
243 If FALSE, then the CPU feature must be disabled.
245 @retval RETURN_SUCCESS CPU feature is initialized.
247 @note This service could be called by BSP only.
251 (EFIAPI
*CPU_FEATURE_INITIALIZE
)(
252 IN UINTN ProcessorNumber
,
253 IN REGISTER_CPU_FEATURE_INFORMATION
*CpuInfo
,
254 IN VOID
*ConfigData
, OPTIONAL
259 Registers a CPU Feature.
261 @param[in] FeatureName A Null-terminated Ascii string indicates CPU feature
263 @param[in] GetConfigDataFunc CPU feature get configuration data function. This
264 is an optional parameter that may be NULL. If NULL,
265 then the most recently registered function for the
266 CPU feature is used. If no functions are registered
267 for a CPU feature, then the CPU configuration data
268 for the registered feature is NULL.
269 @param[in] SupportFunc CPU feature support function. This is an optional
270 parameter that may be NULL. If NULL, then the most
271 recently registered function for the CPU feature is
272 used. If no functions are registered for a CPU
273 feature, then the CPU feature is assumed to be
274 supported by all CPUs.
275 @param[in] InitializeFunc CPU feature initialize function. This is an optional
276 parameter that may be NULL. If NULL, then the most
277 recently registered function for the CPU feature is
278 used. If no functions are registered for a CPU
279 feature, then the CPU feature initialization is
281 @param[in] ... Variable argument list of UINT32 CPU feature value.
282 Values with no modifiers are the features provided
283 by the registered functions.
284 Values with CPU_FEATURE_BEFORE modifier are features
285 that must be initialized after the features provided
286 by the registered functions are used.
287 Values with CPU_FEATURE_AFTER modifier are features
288 that must be initialized before the features provided
289 by the registered functions are used.
290 The last argument in this variable argument list must
291 always be CPU_FEATURE_END.
293 @retval RETURN_SUCCESS The CPU feature was successfully registered.
294 @retval RETURN_OUT_OF_RESOURCES There are not enough resources to register
296 @retval RETURN_UNSUPPORTED Registration of the CPU feature is not
297 supported due to a circular dependency between
298 BEFORE and AFTER features.
300 @note This service could be called by BSP only.
305 IN CHAR8
*FeatureName
, OPTIONAL
306 IN CPU_FEATURE_GET_CONFIG_DATA GetConfigDataFunc
, OPTIONAL
307 IN CPU_FEATURE_SUPPORT SupportFunc
, OPTIONAL
308 IN CPU_FEATURE_INITIALIZE InitializeFunc
, OPTIONAL
313 Performs CPU features detection.
315 This service will invoke MP service to check CPU features'
316 capabilities on BSP/APs.
318 @note This service could be called by BSP only.
327 Performs CPU features Initialization.
329 This service will invoke MP service to perform CPU features
330 initialization on BSP/APs per user configuration.
332 @note This service could be called by BSP only.
336 CpuFeaturesInitialize (
341 Switches to assigned BSP after CPU features initialization.
343 @param[in] ProcessorNumber The index of the CPU executing this function.
345 @note This service could be called by BSP only.
349 SwitchBspAfterFeaturesInitialize (
350 IN UINTN ProcessorNumber
354 Adds an entry in specified register table.
356 This function adds an entry in specified register table, with given register type,
357 register index, bit section and value.
359 @param[in] ProcessorNumber The index of the CPU to add a register table entry.
360 @param[in] RegisterType Type of the register to program
361 @param[in] Index Index of the register to program
362 @param[in] ValueMask Mask of bits in register to write
363 @param[in] Value Value to write
365 @note This service could be called by BSP only.
369 CpuRegisterTableWrite (
370 IN UINTN ProcessorNumber
,
371 IN REGISTER_TYPE RegisterType
,
378 Adds an entry in specified Pre-SMM register table.
380 This function adds an entry in specified register table, with given register type,
381 register index, bit section and value.
383 @param[in] ProcessorNumber The index of the CPU to add a register table entry.
384 @param[in] RegisterType Type of the register to program
385 @param[in] Index Index of the register to program
386 @param[in] ValueMask Mask of bits in register to write
387 @param[in] Value Value to write
389 @note This service could be called by BSP only.
393 PreSmmCpuRegisterTableWrite (
394 IN UINTN ProcessorNumber
,
395 IN REGISTER_TYPE RegisterType
,
402 Adds a 32-bit register write entry in specified register table.
404 This macro adds an entry in specified register table, with given register type,
405 register index, and value.
407 @param[in] ProcessorNumber The index of the CPU to add a register table entry.
408 @param[in] RegisterType Type of the register to program
409 @param[in] Index Index of the register to program
410 @param[in] Value Value to write
412 @note This service could be called by BSP only.
414 #define CPU_REGISTER_TABLE_WRITE32(ProcessorNumber, RegisterType, Index, Value) \
416 CpuRegisterTableWrite (ProcessorNumber, RegisterType, Index, MAX_UINT32, Value); \
420 Adds a 64-bit register write entry in specified register table.
422 This macro adds an entry in specified register table, with given register type,
423 register index, and value.
425 @param[in] ProcessorNumber The index of the CPU to add a register table entry.
426 @param[in] RegisterType Type of the register to program
427 @param[in] Index Index of the register to program
428 @param[in] Value Value to write
430 @note This service could be called by BSP only.
432 #define CPU_REGISTER_TABLE_WRITE64(ProcessorNumber, RegisterType, Index, Value) \
434 CpuRegisterTableWrite (ProcessorNumber, RegisterType, Index, MAX_UINT64, Value); \
438 Adds a bit field write entry in specified register table.
440 This macro adds an entry in specified register table, with given register type,
441 register index, bit field section, and value.
443 @param[in] ProcessorNumber The index of the CPU to add a register table entry.
444 @param[in] RegisterType Type of the register to program.
445 @param[in] Index Index of the register to program.
446 @param[in] Type The data type name of a register structure.
447 @param[in] Field The bit fiel name in register structure to write.
448 @param[in] Value Value to write to the bit field.
450 @note This service could be called by BSP only.
452 #define CPU_REGISTER_TABLE_WRITE_FIELD(ProcessorNumber, RegisterType, Index, Type, Field, Value) \
455 ValueMask = MAX_UINT64; \
456 ((Type *)(&ValueMask))->Field = 0; \
457 CpuRegisterTableWrite (ProcessorNumber, RegisterType, Index, ~ValueMask, Value); \
461 Adds a 32-bit register write entry in specified register table.
463 This macro adds an entry in specified register table, with given register type,
464 register index, and value.
466 @param[in] ProcessorNumber The index of the CPU to add a register table entry.
467 @param[in] RegisterType Type of the register to program
468 @param[in] Index Index of the register to program
469 @param[in] Value Value to write
471 @note This service could be called by BSP only.
473 #define PRE_SMM_CPU_REGISTER_TABLE_WRITE32(ProcessorNumber, RegisterType, Index, Value) \
475 PreSmmCpuRegisterTableWrite (ProcessorNumber, RegisterType, Index, MAX_UINT32, Value); \
479 Adds a 64-bit register write entry in specified register table.
481 This macro adds an entry in specified register table, with given register type,
482 register index, and value.
484 @param[in] ProcessorNumber The index of the CPU to add a register table entry.
485 @param[in] RegisterType Type of the register to program
486 @param[in] Index Index of the register to program
487 @param[in] Value Value to write
489 @note This service could be called by BSP only.
491 #define PRE_SMM_CPU_REGISTER_TABLE_WRITE64(ProcessorNumber, RegisterType, Index, Value) \
493 PreSmmCpuRegisterTableWrite (ProcessorNumber, RegisterType, Index, MAX_UINT64, Value); \
497 Adds a bit field write entry in specified register table.
499 This macro adds an entry in specified register table, with given register type,
500 register index, bit field section, and value.
502 @param[in] ProcessorNumber The index of the CPU to add a register table entry.
503 @param[in] RegisterType Type of the register to program.
504 @param[in] Index Index of the register to program.
505 @param[in] Type The data type name of a register structure.
506 @param[in] Field The bit fiel name in register structure to write.
507 @param[in] Value Value to write to the bit field.
509 @note This service could be called by BSP only.
511 #define PRE_SMM_CPU_REGISTER_TABLE_WRITE_FIELD(ProcessorNumber, RegisterType, Index, Type, Field, Value) \
514 ValueMask = MAX_UINT64; \
515 ((Type *)(&ValueMask))->Field = 0; \
516 PreSmmCpuRegisterTableWrite (ProcessorNumber, RegisterType, Index, ~ValueMask, Value); \