]> git.proxmox.com Git - mirror_edk2.git/blob - UefiCpuPkg/Include/Library/RegisterCpuFeaturesLib.h
be14a92b352d3ed220589337f02de9f36c488dc0
[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 - 2020, 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/Intel/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_RESERVED_5 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_STRIKE_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 #define CPU_FEATURE_THREAD_BEFORE BIT25
73 #define CPU_FEATURE_THREAD_AFTER BIT26
74 #define CPU_FEATURE_CORE_BEFORE BIT27
75 #define CPU_FEATURE_CORE_AFTER BIT28
76 #define CPU_FEATURE_PACKAGE_BEFORE BIT29
77 #define CPU_FEATURE_PACKAGE_AFTER BIT30
78 #define CPU_FEATURE_END MAX_UINT32
79 /// @}
80
81 ///
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.
85 ///
86 typedef struct {
87 ///
88 /// The package that the CPU resides
89 ///
90 EFI_PROCESSOR_INFORMATION ProcessorInfo;
91 ///
92 /// The Display Family of the CPU computed from CPUID leaf CPUID_VERSION_INFO
93 ///
94 UINT32 DisplayFamily;
95 ///
96 /// The Display Model of the CPU computed from CPUID leaf CPUID_VERSION_INFO
97 ///
98 UINT32 DisplayModel;
99 ///
100 /// The Stepping ID of the CPU computed from CPUID leaf CPUID_VERSION_INFO
101 ///
102 UINT32 SteppingId;
103 ///
104 /// The Processor Type of the CPU computed from CPUID leaf CPUID_VERSION_INFO
105 ///
106 UINT32 ProcessorType;
107 ///
108 /// Bit field structured returned in ECX from CPUID leaf CPUID_VERSION_INFO
109 ///
110 CPUID_VERSION_INFO_ECX CpuIdVersionInfoEcx;
111 ///
112 /// Bit field structured returned in EDX from CPUID leaf CPUID_VERSION_INFO
113 ///
114 CPUID_VERSION_INFO_EDX CpuIdVersionInfoEdx;
115 } REGISTER_CPU_FEATURE_INFORMATION;
116
117 /**
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.
122
123 @param[in] Feature The bit number of the CPU feature to check in the PCD
124 PcdCpuFeaturesSupport.
125
126 @retval TRUE The CPU feature is set in PcdCpuFeaturesSupport.
127 @retval FALSE The CPU feature is not set in PcdCpuFeaturesSupport.
128
129 @note This service could be called by BSP only.
130 **/
131 BOOLEAN
132 EFIAPI
133 IsCpuFeatureSupported (
134 IN UINT32 Feature
135 );
136
137 /**
138 Determines if a CPU feature is set in PcdCpuFeaturesSetting bit mask.
139
140 @param[in] Feature The bit number of the CPU feature to check in the PCD
141 PcdCpuFeaturesSetting.
142
143 @retval TRUE The CPU feature is set in PcdCpuFeaturesSetting.
144 @retval FALSE The CPU feature is not set in PcdCpuFeaturesSetting.
145
146 @note This service could be called by BSP only.
147 **/
148 BOOLEAN
149 EFIAPI
150 IsCpuFeatureInSetting (
151 IN UINT32 Feature
152 );
153
154 /**
155 Prepares for the data used by CPU feature detection and initialization.
156
157 @param[in] NumberOfProcessors The number of CPUs in the platform.
158
159 @return Pointer to a buffer of CPU related configuration data.
160
161 @note This service could be called by BSP only.
162 **/
163 typedef
164 VOID *
165 (EFIAPI *CPU_FEATURE_GET_CONFIG_DATA)(
166 IN UINTN NumberOfProcessors
167 );
168
169 /**
170 Detects if CPU feature supported on current processor.
171
172 @param[in] ProcessorNumber The index of the CPU executing this function.
173 @param[in] CpuInfo A pointer to the REGISTER_CPU_FEATURE_INFORMATION
174 structure for the CPU executing this function.
175 @param[in] ConfigData A pointer to the configuration buffer returned
176 by CPU_FEATURE_GET_CONFIG_DATA. NULL if
177 CPU_FEATURE_GET_CONFIG_DATA was not provided in
178 RegisterCpuFeature().
179
180 @retval TRUE CPU feature is supported.
181 @retval FALSE CPU feature is not supported.
182
183 @note This service could be called by BSP/APs.
184 **/
185 typedef
186 BOOLEAN
187 (EFIAPI *CPU_FEATURE_SUPPORT)(
188 IN UINTN ProcessorNumber,
189 IN REGISTER_CPU_FEATURE_INFORMATION *CpuInfo,
190 IN VOID *ConfigData OPTIONAL
191 );
192
193 /**
194 Initializes CPU feature to specific state.
195
196 This service does not initialize hardware and only produces entries in the
197 Register Table for specified processor. Hardware initialization on BSP/APs
198 will be done in CpuFeaturesInitialize().
199
200 @param[in] ProcessorNumber The index of the CPU executing this function.
201 @param[in] CpuInfo A pointer to the REGISTER_CPU_FEATURE_INFORMATION
202 structure for the CPU executing this function.
203 @param[in] ConfigData A pointer to the configuration buffer returned
204 by CPU_FEATURE_GET_CONFIG_DATA. NULL if
205 CPU_FEATURE_GET_CONFIG_DATA was not provided in
206 RegisterCpuFeature().
207 @param[in] State If TRUE, then the CPU feature must be enabled.
208 If FALSE, then the CPU feature must be disabled.
209
210 @retval RETURN_SUCCESS CPU feature is initialized.
211
212 @note This service could be called by BSP only.
213 **/
214 typedef
215 RETURN_STATUS
216 (EFIAPI *CPU_FEATURE_INITIALIZE)(
217 IN UINTN ProcessorNumber,
218 IN REGISTER_CPU_FEATURE_INFORMATION *CpuInfo,
219 IN VOID *ConfigData, OPTIONAL
220 IN BOOLEAN State
221 );
222
223 /**
224 Registers a CPU Feature.
225
226 @param[in] FeatureName A Null-terminated Ascii string indicates CPU feature
227 name.
228 @param[in] GetConfigDataFunc CPU feature get configuration data function. This
229 is an optional parameter that may be NULL. If NULL,
230 then the most recently registered function for the
231 CPU feature is used. If no functions are registered
232 for a CPU feature, then the CPU configuration data
233 for the registered feature is NULL.
234 @param[in] SupportFunc CPU feature support function. This is an optional
235 parameter that may be NULL. If NULL, then the most
236 recently registered function for the CPU feature is
237 used. If no functions are registered for a CPU
238 feature, then the CPU feature is assumed to be
239 supported by all CPUs.
240 @param[in] InitializeFunc CPU feature initialize function. This is an optional
241 parameter that may be NULL. If NULL, then the most
242 recently registered function for the CPU feature is
243 used. If no functions are registered for a CPU
244 feature, then the CPU feature initialization is
245 skipped.
246 @param[in] ... Variable argument list of UINT32 CPU feature value.
247 Values with no modifiers are the features provided
248 by the registered functions.
249 Values with CPU_FEATURE_BEFORE modifier are features
250 that must be initialized after the features provided
251 by the registered functions are used.
252 Values with CPU_FEATURE_AFTER modifier are features
253 that must be initialized before the features provided
254 by the registered functions are used.
255 The last argument in this variable argument list must
256 always be CPU_FEATURE_END.
257
258 @retval RETURN_SUCCESS The CPU feature was successfully registered.
259 @retval RETURN_OUT_OF_RESOURCES There are not enough resources to register
260 the CPU feature.
261 @retval RETURN_UNSUPPORTED Registration of the CPU feature is not
262 supported due to a circular dependency between
263 BEFORE and AFTER features.
264
265 @note This service could be called by BSP only.
266 **/
267 RETURN_STATUS
268 EFIAPI
269 RegisterCpuFeature (
270 IN CHAR8 *FeatureName, OPTIONAL
271 IN CPU_FEATURE_GET_CONFIG_DATA GetConfigDataFunc, OPTIONAL
272 IN CPU_FEATURE_SUPPORT SupportFunc, OPTIONAL
273 IN CPU_FEATURE_INITIALIZE InitializeFunc, OPTIONAL
274 ...
275 );
276
277 /**
278 Performs CPU features detection.
279
280 This service will invoke MP service to check CPU features'
281 capabilities on BSP/APs.
282
283 @note This service could be called by BSP only.
284 **/
285 VOID
286 EFIAPI
287 CpuFeaturesDetect (
288 VOID
289 );
290
291 /**
292 Performs CPU features Initialization.
293
294 This service will invoke MP service to perform CPU features
295 initialization on BSP/APs per user configuration.
296
297 @note This service could be called by BSP only.
298 **/
299 VOID
300 EFIAPI
301 CpuFeaturesInitialize (
302 VOID
303 );
304
305 /**
306 Switches to assigned BSP after CPU features initialization.
307
308 @param[in] ProcessorNumber The index of the CPU executing this function.
309
310 @note This service could be called by BSP only.
311 **/
312 VOID
313 EFIAPI
314 SwitchBspAfterFeaturesInitialize (
315 IN UINTN ProcessorNumber
316 );
317
318 /**
319 Adds an entry in specified register table.
320
321 This function adds an entry in specified register table, with given register type,
322 register index, bit section and value.
323
324 @param[in] ProcessorNumber The index of the CPU to add a register table entry.
325 @param[in] RegisterType Type of the register to program
326 @param[in] Index Index of the register to program
327 @param[in] ValueMask Mask of bits in register to write
328 @param[in] Value Value to write
329
330 @note This service could be called by BSP only.
331 **/
332 VOID
333 EFIAPI
334 CpuRegisterTableWrite (
335 IN UINTN ProcessorNumber,
336 IN REGISTER_TYPE RegisterType,
337 IN UINT64 Index,
338 IN UINT64 ValueMask,
339 IN UINT64 Value
340 );
341
342 /**
343 Adds an entry in specified register table.
344
345 This function adds an entry in specified register table, with given register type,
346 register index, bit section and value.
347
348 Driver will test the current value before setting new value.
349
350 @param[in] ProcessorNumber The index of the CPU to add a register table entry
351 @param[in] RegisterType Type of the register to program
352 @param[in] Index Index of the register to program
353 @param[in] ValueMask Mask of bits in register to write
354 @param[in] Value Value to write
355
356 @note This service could be called by BSP only.
357 **/
358 VOID
359 EFIAPI
360 CpuRegisterTableTestThenWrite (
361 IN UINTN ProcessorNumber,
362 IN REGISTER_TYPE RegisterType,
363 IN UINT64 Index,
364 IN UINT64 ValueMask,
365 IN UINT64 Value
366 );
367
368 /**
369 Adds an entry in specified Pre-SMM register table.
370
371 This function adds an entry in specified register table, with given register type,
372 register index, bit section and value.
373
374 @param[in] ProcessorNumber The index of the CPU to add a register table entry.
375 @param[in] RegisterType Type of the register to program
376 @param[in] Index Index of the register to program
377 @param[in] ValueMask Mask of bits in register to write
378 @param[in] Value Value to write
379
380 @note This service could be called by BSP only.
381 **/
382 VOID
383 EFIAPI
384 PreSmmCpuRegisterTableWrite (
385 IN UINTN ProcessorNumber,
386 IN REGISTER_TYPE RegisterType,
387 IN UINT64 Index,
388 IN UINT64 ValueMask,
389 IN UINT64 Value
390 );
391
392 /**
393 Adds a 32-bit register write entry in specified register table.
394
395 This macro adds an entry in specified register table, with given register type,
396 register index, and value.
397
398 @param[in] ProcessorNumber The index of the CPU to add a register table entry.
399 @param[in] RegisterType Type of the register to program
400 @param[in] Index Index of the register to program
401 @param[in] Value Value to write
402
403 @note This service could be called by BSP only.
404 **/
405 #define CPU_REGISTER_TABLE_WRITE32(ProcessorNumber, RegisterType, Index, Value) \
406 do { \
407 CpuRegisterTableWrite (ProcessorNumber, RegisterType, Index, MAX_UINT32, Value); \
408 } while(FALSE);
409
410 /**
411 Adds a 32-bit register write entry in specified register table.
412
413 This macro adds an entry in specified register table, with given register type,
414 register index, and value.
415
416 Driver will test the current value before setting new value.
417
418 @param[in] ProcessorNumber The index of the CPU to add a register table entry.
419 @param[in] RegisterType Type of the register to program
420 @param[in] Index Index of the register to program
421 @param[in] Value Value to write
422
423 @note This service could be called by BSP only.
424 **/
425 #define CPU_REGISTER_TABLE_TEST_THEN_WRITE32(ProcessorNumber, RegisterType, Index, Value) \
426 do { \
427 CpuRegisterTableTestThenWrite (ProcessorNumber, RegisterType, Index, MAX_UINT32, Value); \
428 } while(FALSE);
429
430 /**
431 Adds a 64-bit register write entry in specified register table.
432
433 This macro adds an entry in specified register table, with given register type,
434 register index, and value.
435
436 @param[in] ProcessorNumber The index of the CPU to add a register table entry.
437 @param[in] RegisterType Type of the register to program
438 @param[in] Index Index of the register to program
439 @param[in] Value Value to write
440
441 @note This service could be called by BSP only.
442 **/
443 #define CPU_REGISTER_TABLE_WRITE64(ProcessorNumber, RegisterType, Index, Value) \
444 do { \
445 CpuRegisterTableWrite (ProcessorNumber, RegisterType, Index, MAX_UINT64, Value); \
446 } while(FALSE);
447
448 /**
449 Adds a 64-bit register write entry in specified register table.
450
451 This macro adds an entry in specified register table, with given register type,
452 register index, and value.
453
454 Driver will test the current value before setting new value.
455
456 @param[in] ProcessorNumber The index of the CPU to add a register table entry.
457 @param[in] RegisterType Type of the register to program
458 @param[in] Index Index of the register to program
459 @param[in] Value Value to write
460
461 @note This service could be called by BSP only.
462 **/
463 #define CPU_REGISTER_TABLE_TEST_THEN_WRITE64(ProcessorNumber, RegisterType, Index, Value) \
464 do { \
465 CpuRegisterTableTestThenWrite (ProcessorNumber, RegisterType, Index, MAX_UINT64, Value); \
466 } while(FALSE);
467
468 /**
469 Adds a bit field write entry in specified register table.
470
471 This macro adds an entry in specified register table, with given register type,
472 register index, bit field section, and value.
473
474 @param[in] ProcessorNumber The index of the CPU to add a register table entry.
475 @param[in] RegisterType Type of the register to program.
476 @param[in] Index Index of the register to program.
477 @param[in] Type The data type name of a register structure.
478 @param[in] Field The bit fiel name in register structure to write.
479 @param[in] Value Value to write to the bit field.
480
481 @note This service could be called by BSP only.
482 **/
483 #define CPU_REGISTER_TABLE_WRITE_FIELD(ProcessorNumber, RegisterType, Index, Type, Field, Value) \
484 do { \
485 UINT64 ValueMask; \
486 ValueMask = MAX_UINT64; \
487 ((Type *)(&ValueMask))->Field = 0; \
488 CpuRegisterTableWrite (ProcessorNumber, RegisterType, Index, ~ValueMask, Value); \
489 } while(FALSE);
490
491 /**
492 Adds a bit field write entry in specified register table.
493
494 This macro adds an entry in specified register table, with given register type,
495 register index, bit field section, and value.
496
497 Driver will test the current value before setting new value.
498
499 @param[in] ProcessorNumber The index of the CPU to add a register table entry.
500 @param[in] RegisterType Type of the register to program.
501 @param[in] Index Index of the register to program.
502 @param[in] Type The data type name of a register structure.
503 @param[in] Field The bit fiel name in register structure to write.
504 @param[in] Value Value to write to the bit field.
505
506 @note This service could be called by BSP only.
507 **/
508 #define CPU_REGISTER_TABLE_TEST_THEN_WRITE_FIELD(ProcessorNumber, RegisterType, Index, Type, Field, Value) \
509 do { \
510 UINT64 ValueMask; \
511 ValueMask = MAX_UINT64; \
512 ((Type *)(&ValueMask))->Field = 0; \
513 CpuRegisterTableTestThenWrite (ProcessorNumber, RegisterType, Index, ~ValueMask, Value); \
514 } while(FALSE);
515
516 /**
517 Adds a 32-bit register write entry in specified register table.
518
519 This macro adds an entry in specified register table, with given register type,
520 register index, and value.
521
522 @param[in] ProcessorNumber The index of the CPU to add a register table entry.
523 @param[in] RegisterType Type of the register to program
524 @param[in] Index Index of the register to program
525 @param[in] Value Value to write
526
527 @note This service could be called by BSP only.
528 **/
529 #define PRE_SMM_CPU_REGISTER_TABLE_WRITE32(ProcessorNumber, RegisterType, Index, Value) \
530 do { \
531 PreSmmCpuRegisterTableWrite (ProcessorNumber, RegisterType, Index, MAX_UINT32, Value); \
532 } while(FALSE);
533
534 /**
535 Adds a 64-bit register write entry in specified register table.
536
537 This macro adds an entry in specified register table, with given register type,
538 register index, and value.
539
540 @param[in] ProcessorNumber The index of the CPU to add a register table entry.
541 @param[in] RegisterType Type of the register to program
542 @param[in] Index Index of the register to program
543 @param[in] Value Value to write
544
545 @note This service could be called by BSP only.
546 **/
547 #define PRE_SMM_CPU_REGISTER_TABLE_WRITE64(ProcessorNumber, RegisterType, Index, Value) \
548 do { \
549 PreSmmCpuRegisterTableWrite (ProcessorNumber, RegisterType, Index, MAX_UINT64, Value); \
550 } while(FALSE);
551
552 /**
553 Adds a bit field write entry in specified register table.
554
555 This macro adds an entry in specified register table, with given register type,
556 register index, bit field section, and value.
557
558 @param[in] ProcessorNumber The index of the CPU to add a register table entry.
559 @param[in] RegisterType Type of the register to program.
560 @param[in] Index Index of the register to program.
561 @param[in] Type The data type name of a register structure.
562 @param[in] Field The bit fiel name in register structure to write.
563 @param[in] Value Value to write to the bit field.
564
565 @note This service could be called by BSP only.
566 **/
567 #define PRE_SMM_CPU_REGISTER_TABLE_WRITE_FIELD(ProcessorNumber, RegisterType, Index, Type, Field, Value) \
568 do { \
569 UINT64 ValueMask; \
570 ValueMask = MAX_UINT64; \
571 ((Type *)(&ValueMask))->Field = 0; \
572 PreSmmCpuRegisterTableWrite (ProcessorNumber, RegisterType, Index, ~ValueMask, Value); \
573 } while(FALSE);
574
575 #endif