]> git.proxmox.com Git - mirror_edk2.git/blob - UefiCpuPkg/Include/Library/RegisterCpuFeaturesLib.h
UefiCpuPkg: Replace BSD License with BSD+Patent License
[mirror_edk2.git] / UefiCpuPkg / Include / Library / RegisterCpuFeaturesLib.h
1 /** @file
2 Register CPU Features Library to register and manage CPU features.
3
4 Copyright (c) 2017 - 2019, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
6
7 **/
8
9 #ifndef __REGISTER_CPU_FEATURES_LIB_H__
10 #define __REGISTER_CPU_FEATURES_LIB_H__
11
12 #include <AcpiCpuData.h>
13 #include <Register/Cpuid.h>
14 #include <Protocol/MpService.h>
15
16 ///
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.
22 /// @{
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
55
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)
69
70 #define CPU_FEATURE_BEFORE_ALL BIT23
71 #define CPU_FEATURE_AFTER_ALL BIT24
72 //
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.
77 //
78 #define CPU_FEATURE_BEFORE BIT25
79 #define CPU_FEATURE_AFTER BIT26
80
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
88 /// @}
89
90 ///
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.
94 ///
95 typedef struct {
96 ///
97 /// The package that the CPU resides
98 ///
99 EFI_PROCESSOR_INFORMATION ProcessorInfo;
100 ///
101 /// The Display Family of the CPU computed from CPUID leaf CPUID_VERSION_INFO
102 ///
103 UINT32 DisplayFamily;
104 ///
105 /// The Display Model of the CPU computed from CPUID leaf CPUID_VERSION_INFO
106 ///
107 UINT32 DisplayModel;
108 ///
109 /// The Stepping ID of the CPU computed from CPUID leaf CPUID_VERSION_INFO
110 ///
111 UINT32 SteppingId;
112 ///
113 /// The Processor Type of the CPU computed from CPUID leaf CPUID_VERSION_INFO
114 ///
115 UINT32 ProcessorType;
116 ///
117 /// Bit field structured returned in ECX from CPUID leaf CPUID_VERSION_INFO
118 ///
119 CPUID_VERSION_INFO_ECX CpuIdVersionInfoEcx;
120 ///
121 /// Bit field structured returned in EDX from CPUID leaf CPUID_VERSION_INFO
122 ///
123 CPUID_VERSION_INFO_EDX CpuIdVersionInfoEdx;
124 } REGISTER_CPU_FEATURE_INFORMATION;
125
126 /**
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.
131
132 @param[in] Feature The bit number of the CPU feature to check in the PCD
133 PcdCpuFeaturesSupport.
134
135 @retval TRUE The CPU feature is set in PcdCpuFeaturesSupport.
136 @retval FALSE The CPU feature is not set in PcdCpuFeaturesSupport.
137
138 @note This service could be called by BSP only.
139 **/
140 BOOLEAN
141 EFIAPI
142 IsCpuFeatureSupported (
143 IN UINT32 Feature
144 );
145
146 /**
147 Determines if a CPU feature is set in PcdCpuFeaturesSetting bit mask.
148
149 @param[in] Feature The bit number of the CPU feature to check in the PCD
150 PcdCpuFeaturesSetting.
151
152 @retval TRUE The CPU feature is set in PcdCpuFeaturesSetting.
153 @retval FALSE The CPU feature is not set in PcdCpuFeaturesSetting.
154
155 @note This service could be called by BSP only.
156 **/
157 BOOLEAN
158 EFIAPI
159 IsCpuFeatureInSetting (
160 IN UINT32 Feature
161 );
162
163 /**
164 Prepares for the data used by CPU feature detection and initialization.
165
166 @param[in] NumberOfProcessors The number of CPUs in the platform.
167
168 @return Pointer to a buffer of CPU related configuration data.
169
170 @note This service could be called by BSP only.
171 **/
172 typedef
173 VOID *
174 (EFIAPI *CPU_FEATURE_GET_CONFIG_DATA)(
175 IN UINTN NumberOfProcessors
176 );
177
178 /**
179 Detects if CPU feature supported on current processor.
180
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().
188
189 @retval TRUE CPU feature is supported.
190 @retval FALSE CPU feature is not supported.
191
192 @note This service could be called by BSP/APs.
193 **/
194 typedef
195 BOOLEAN
196 (EFIAPI *CPU_FEATURE_SUPPORT)(
197 IN UINTN ProcessorNumber,
198 IN REGISTER_CPU_FEATURE_INFORMATION *CpuInfo,
199 IN VOID *ConfigData OPTIONAL
200 );
201
202 /**
203 Initializes CPU feature to specific state.
204
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().
208
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.
218
219 @retval RETURN_SUCCESS CPU feature is initialized.
220
221 @note This service could be called by BSP only.
222 **/
223 typedef
224 RETURN_STATUS
225 (EFIAPI *CPU_FEATURE_INITIALIZE)(
226 IN UINTN ProcessorNumber,
227 IN REGISTER_CPU_FEATURE_INFORMATION *CpuInfo,
228 IN VOID *ConfigData, OPTIONAL
229 IN BOOLEAN State
230 );
231
232 /**
233 Registers a CPU Feature.
234
235 @param[in] FeatureName A Null-terminated Ascii string indicates CPU feature
236 name.
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
254 skipped.
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.
266
267 @retval RETURN_SUCCESS The CPU feature was successfully registered.
268 @retval RETURN_OUT_OF_RESOURCES There are not enough resources to register
269 the CPU feature.
270 @retval RETURN_UNSUPPORTED Registration of the CPU feature is not
271 supported due to a circular dependency between
272 BEFORE and AFTER features.
273
274 @note This service could be called by BSP only.
275 **/
276 RETURN_STATUS
277 EFIAPI
278 RegisterCpuFeature (
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
283 ...
284 );
285
286 /**
287 Performs CPU features detection.
288
289 This service will invoke MP service to check CPU features'
290 capabilities on BSP/APs.
291
292 @note This service could be called by BSP only.
293 **/
294 VOID
295 EFIAPI
296 CpuFeaturesDetect (
297 VOID
298 );
299
300 /**
301 Performs CPU features Initialization.
302
303 This service will invoke MP service to perform CPU features
304 initialization on BSP/APs per user configuration.
305
306 @note This service could be called by BSP only.
307 **/
308 VOID
309 EFIAPI
310 CpuFeaturesInitialize (
311 VOID
312 );
313
314 /**
315 Switches to assigned BSP after CPU features initialization.
316
317 @param[in] ProcessorNumber The index of the CPU executing this function.
318
319 @note This service could be called by BSP only.
320 **/
321 VOID
322 EFIAPI
323 SwitchBspAfterFeaturesInitialize (
324 IN UINTN ProcessorNumber
325 );
326
327 /**
328 Adds an entry in specified register table.
329
330 This function adds an entry in specified register table, with given register type,
331 register index, bit section and value.
332
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
338
339 @note This service could be called by BSP only.
340 **/
341 VOID
342 EFIAPI
343 CpuRegisterTableWrite (
344 IN UINTN ProcessorNumber,
345 IN REGISTER_TYPE RegisterType,
346 IN UINT64 Index,
347 IN UINT64 ValueMask,
348 IN UINT64 Value
349 );
350
351 /**
352 Adds an entry in specified Pre-SMM register table.
353
354 This function adds an entry in specified register table, with given register type,
355 register index, bit section and value.
356
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
362
363 @note This service could be called by BSP only.
364 **/
365 VOID
366 EFIAPI
367 PreSmmCpuRegisterTableWrite (
368 IN UINTN ProcessorNumber,
369 IN REGISTER_TYPE RegisterType,
370 IN UINT64 Index,
371 IN UINT64 ValueMask,
372 IN UINT64 Value
373 );
374
375 /**
376 Adds a 32-bit register write entry in specified register table.
377
378 This macro adds an entry in specified register table, with given register type,
379 register index, and value.
380
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
385
386 @note This service could be called by BSP only.
387 **/
388 #define CPU_REGISTER_TABLE_WRITE32(ProcessorNumber, RegisterType, Index, Value) \
389 do { \
390 CpuRegisterTableWrite (ProcessorNumber, RegisterType, Index, MAX_UINT32, Value); \
391 } while(FALSE);
392
393 /**
394 Adds a 64-bit register write entry in specified register table.
395
396 This macro adds an entry in specified register table, with given register type,
397 register index, and value.
398
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
403
404 @note This service could be called by BSP only.
405 **/
406 #define CPU_REGISTER_TABLE_WRITE64(ProcessorNumber, RegisterType, Index, Value) \
407 do { \
408 CpuRegisterTableWrite (ProcessorNumber, RegisterType, Index, MAX_UINT64, Value); \
409 } while(FALSE);
410
411 /**
412 Adds a bit field write entry in specified register table.
413
414 This macro adds an entry in specified register table, with given register type,
415 register index, bit field section, and value.
416
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.
423
424 @note This service could be called by BSP only.
425 **/
426 #define CPU_REGISTER_TABLE_WRITE_FIELD(ProcessorNumber, RegisterType, Index, Type, Field, Value) \
427 do { \
428 UINT64 ValueMask; \
429 ValueMask = MAX_UINT64; \
430 ((Type *)(&ValueMask))->Field = 0; \
431 CpuRegisterTableWrite (ProcessorNumber, RegisterType, Index, ~ValueMask, Value); \
432 } while(FALSE);
433
434 /**
435 Adds a 32-bit register write entry in specified register table.
436
437 This macro adds an entry in specified register table, with given register type,
438 register index, and value.
439
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
444
445 @note This service could be called by BSP only.
446 **/
447 #define PRE_SMM_CPU_REGISTER_TABLE_WRITE32(ProcessorNumber, RegisterType, Index, Value) \
448 do { \
449 PreSmmCpuRegisterTableWrite (ProcessorNumber, RegisterType, Index, MAX_UINT32, Value); \
450 } while(FALSE);
451
452 /**
453 Adds a 64-bit register write entry in specified register table.
454
455 This macro adds an entry in specified register table, with given register type,
456 register index, and value.
457
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
462
463 @note This service could be called by BSP only.
464 **/
465 #define PRE_SMM_CPU_REGISTER_TABLE_WRITE64(ProcessorNumber, RegisterType, Index, Value) \
466 do { \
467 PreSmmCpuRegisterTableWrite (ProcessorNumber, RegisterType, Index, MAX_UINT64, Value); \
468 } while(FALSE);
469
470 /**
471 Adds a bit field write entry in specified register table.
472
473 This macro adds an entry in specified register table, with given register type,
474 register index, bit field section, and value.
475
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.
482
483 @note This service could be called by BSP only.
484 **/
485 #define PRE_SMM_CPU_REGISTER_TABLE_WRITE_FIELD(ProcessorNumber, RegisterType, Index, Type, Field, Value) \
486 do { \
487 UINT64 ValueMask; \
488 ValueMask = MAX_UINT64; \
489 ((Type *)(&ValueMask))->Field = 0; \
490 PreSmmCpuRegisterTableWrite (ProcessorNumber, RegisterType, Index, ~ValueMask, Value); \
491 } while(FALSE);
492
493 #endif