]> git.proxmox.com Git - mirror_edk2.git/blob - UefiCpuPkg/Include/Library/RegisterCpuFeaturesLib.h
2f7e71c833994aef816f5e9d0ba795cc370028ec
[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, 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
9
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.
12
13 **/
14
15 #ifndef __REGISTER_CPU_FEATURES_LIB_H__
16 #define __REGISTER_CPU_FEATURES_LIB_H__
17
18 #include <AcpiCpuData.h>
19 #include <Register/Cpuid.h>
20 #include <Protocol/MpService.h>
21
22 ///
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.
28 /// @{
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
61
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)
75
76 #define CPU_FEATURE_BEFORE_ALL BIT23
77 #define CPU_FEATURE_AFTER_ALL BIT24
78 //
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.
83 //
84 #define CPU_FEATURE_BEFORE BIT25
85 #define CPU_FEATURE_AFTER BIT26
86
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
94 /// @}
95
96 ///
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.
100 ///
101 typedef struct {
102 ///
103 /// The package that the CPU resides
104 ///
105 EFI_PROCESSOR_INFORMATION ProcessorInfo;
106 ///
107 /// The Display Family of the CPU computed from CPUID leaf CPUID_VERSION_INFO
108 ///
109 UINT32 DisplayFamily;
110 ///
111 /// The Display Model of the CPU computed from CPUID leaf CPUID_VERSION_INFO
112 ///
113 UINT32 DisplayModel;
114 ///
115 /// The Stepping ID of the CPU computed from CPUID leaf CPUID_VERSION_INFO
116 ///
117 UINT32 SteppingId;
118 ///
119 /// The Processor Type of the CPU computed from CPUID leaf CPUID_VERSION_INFO
120 ///
121 UINT32 ProcessorType;
122 ///
123 /// Bit field structured returned in ECX from CPUID leaf CPUID_VERSION_INFO
124 ///
125 CPUID_VERSION_INFO_ECX CpuIdVersionInfoEcx;
126 ///
127 /// Bit field structured returned in EDX from CPUID leaf CPUID_VERSION_INFO
128 ///
129 CPUID_VERSION_INFO_EDX CpuIdVersionInfoEdx;
130 } REGISTER_CPU_FEATURE_INFORMATION;
131
132 /**
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.
137
138 @param[in] Feature The bit number of the CPU feature to check in the PCD
139 PcdCpuFeaturesSupport.
140
141 @retval TRUE The CPU feature is set in PcdCpuFeaturesSupport.
142 @retval FALSE The CPU feature is not set in PcdCpuFeaturesSupport.
143
144 @note This service could be called by BSP only.
145 **/
146 BOOLEAN
147 EFIAPI
148 IsCpuFeatureSupported (
149 IN UINT32 Feature
150 );
151
152 /**
153 Determines if a CPU feature is set in PcdCpuFeaturesSetting bit mask.
154
155 @param[in] Feature The bit number of the CPU feature to check in the PCD
156 PcdCpuFeaturesSetting.
157
158 @retval TRUE The CPU feature is set in PcdCpuFeaturesSetting.
159 @retval FALSE The CPU feature is not set in PcdCpuFeaturesSetting.
160
161 @note This service could be called by BSP only.
162 **/
163 BOOLEAN
164 EFIAPI
165 IsCpuFeatureInSetting (
166 IN UINT32 Feature
167 );
168
169 /**
170 Determines if a CPU feature is set in PcdCpuFeaturesCapability bit mask.
171
172 @param[in] Feature The bit number of the CPU feature to check in the PCD
173 PcdCpuFeaturesCapability.
174
175 @retval TRUE The CPU feature is set in PcdCpuFeaturesCapability.
176 @retval FALSE The CPU feature is not set in PcdCpuFeaturesCapability.
177
178 @note This service could be called by BSP only.
179 **/
180 BOOLEAN
181 EFIAPI
182 IsCpuFeatureCapability (
183 IN UINT32 Feature
184 );
185
186 /**
187 Determines if a CPU feature is set in PcdCpuFeaturesUserConfiguration bit mask.
188
189 @param[in] Feature The bit number of the CPU feature to check in the PCD
190 PcdCpuFeaturesUserConfiguration.
191
192 @retval TRUE The CPU feature is set in PcdCpuFeaturesUserConfiguration.
193 @retval FALSE The CPU feature is not set in PcdCpuFeaturesUserConfiguration.
194
195 @note This service could be called by BSP only.
196 **/
197 BOOLEAN
198 EFIAPI
199 IsCpuFeatureUserConfiguration (
200 IN UINT32 Feature
201 );
202
203 /**
204 Prepares for the data used by CPU feature detection and initialization.
205
206 @param[in] NumberOfProcessors The number of CPUs in the platform.
207
208 @return Pointer to a buffer of CPU related configuration data.
209
210 @note This service could be called by BSP only.
211 **/
212 typedef
213 VOID *
214 (EFIAPI *CPU_FEATURE_GET_CONFIG_DATA)(
215 IN UINTN NumberOfProcessors
216 );
217
218 /**
219 Detects if CPU feature supported on current processor.
220
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().
228
229 @retval TRUE CPU feature is supported.
230 @retval FALSE CPU feature is not supported.
231
232 @note This service could be called by BSP/APs.
233 **/
234 typedef
235 BOOLEAN
236 (EFIAPI *CPU_FEATURE_SUPPORT)(
237 IN UINTN ProcessorNumber,
238 IN REGISTER_CPU_FEATURE_INFORMATION *CpuInfo,
239 IN VOID *ConfigData OPTIONAL
240 );
241
242 /**
243 Initializes CPU feature to specific state.
244
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().
248
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.
258
259 @retval RETURN_SUCCESS CPU feature is initialized.
260
261 @note This service could be called by BSP only.
262 **/
263 typedef
264 RETURN_STATUS
265 (EFIAPI *CPU_FEATURE_INITIALIZE)(
266 IN UINTN ProcessorNumber,
267 IN REGISTER_CPU_FEATURE_INFORMATION *CpuInfo,
268 IN VOID *ConfigData, OPTIONAL
269 IN BOOLEAN State
270 );
271
272 /**
273 Registers a CPU Feature.
274
275 @param[in] FeatureName A Null-terminated Ascii string indicates CPU feature
276 name.
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
294 skipped.
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.
306
307 @retval RETURN_SUCCESS The CPU feature was successfully registered.
308 @retval RETURN_OUT_OF_RESOURCES There are not enough resources to register
309 the CPU feature.
310 @retval RETURN_UNSUPPORTED Registration of the CPU feature is not
311 supported due to a circular dependency between
312 BEFORE and AFTER features.
313
314 @note This service could be called by BSP only.
315 **/
316 RETURN_STATUS
317 EFIAPI
318 RegisterCpuFeature (
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
323 ...
324 );
325
326 /**
327 Performs CPU features detection.
328
329 This service will invoke MP service to check CPU features'
330 capabilities on BSP/APs.
331
332 @note This service could be called by BSP only.
333 **/
334 VOID
335 EFIAPI
336 CpuFeaturesDetect (
337 VOID
338 );
339
340 /**
341 Performs CPU features Initialization.
342
343 This service will invoke MP service to perform CPU features
344 initialization on BSP/APs per user configuration.
345
346 @note This service could be called by BSP only.
347 **/
348 VOID
349 EFIAPI
350 CpuFeaturesInitialize (
351 VOID
352 );
353
354 /**
355 Switches to assigned BSP after CPU features initialization.
356
357 @param[in] ProcessorNumber The index of the CPU executing this function.
358
359 @note This service could be called by BSP only.
360 **/
361 VOID
362 EFIAPI
363 SwitchBspAfterFeaturesInitialize (
364 IN UINTN ProcessorNumber
365 );
366
367 /**
368 Adds an entry in specified register table.
369
370 This function adds an entry in specified register table, with given register type,
371 register index, bit section and value.
372
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
378
379 @note This service could be called by BSP only.
380 **/
381 VOID
382 EFIAPI
383 CpuRegisterTableWrite (
384 IN UINTN ProcessorNumber,
385 IN REGISTER_TYPE RegisterType,
386 IN UINT64 Index,
387 IN UINT64 ValueMask,
388 IN UINT64 Value
389 );
390
391 /**
392 Adds an entry in specified Pre-SMM register table.
393
394 This function adds an entry in specified register table, with given register type,
395 register index, bit section and value.
396
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
402
403 @note This service could be called by BSP only.
404 **/
405 VOID
406 EFIAPI
407 PreSmmCpuRegisterTableWrite (
408 IN UINTN ProcessorNumber,
409 IN REGISTER_TYPE RegisterType,
410 IN UINT64 Index,
411 IN UINT64 ValueMask,
412 IN UINT64 Value
413 );
414
415 /**
416 Adds a 32-bit register write entry in specified register table.
417
418 This macro adds an entry in specified register table, with given register type,
419 register index, and value.
420
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
425
426 @note This service could be called by BSP only.
427 **/
428 #define CPU_REGISTER_TABLE_WRITE32(ProcessorNumber, RegisterType, Index, Value) \
429 do { \
430 CpuRegisterTableWrite (ProcessorNumber, RegisterType, Index, MAX_UINT32, Value); \
431 } while(FALSE);
432
433 /**
434 Adds a 64-bit register write entry in specified register table.
435
436 This macro adds an entry in specified register table, with given register type,
437 register index, and value.
438
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
443
444 @note This service could be called by BSP only.
445 **/
446 #define CPU_REGISTER_TABLE_WRITE64(ProcessorNumber, RegisterType, Index, Value) \
447 do { \
448 CpuRegisterTableWrite (ProcessorNumber, RegisterType, Index, MAX_UINT64, Value); \
449 } while(FALSE);
450
451 /**
452 Adds a bit field write entry in specified register table.
453
454 This macro adds an entry in specified register table, with given register type,
455 register index, bit field section, and value.
456
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.
463
464 @note This service could be called by BSP only.
465 **/
466 #define CPU_REGISTER_TABLE_WRITE_FIELD(ProcessorNumber, RegisterType, Index, Type, Field, Value) \
467 do { \
468 UINT64 ValueMask; \
469 ValueMask = MAX_UINT64; \
470 ((Type *)(&ValueMask))->Field = 0; \
471 CpuRegisterTableWrite (ProcessorNumber, RegisterType, Index, ~ValueMask, Value); \
472 } while(FALSE);
473
474 /**
475 Adds a 32-bit register write entry in specified register table.
476
477 This macro adds an entry in specified register table, with given register type,
478 register index, and value.
479
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
484
485 @note This service could be called by BSP only.
486 **/
487 #define PRE_SMM_CPU_REGISTER_TABLE_WRITE32(ProcessorNumber, RegisterType, Index, Value) \
488 do { \
489 PreSmmCpuRegisterTableWrite (ProcessorNumber, RegisterType, Index, MAX_UINT32, Value); \
490 } while(FALSE);
491
492 /**
493 Adds a 64-bit register write entry in specified register table.
494
495 This macro adds an entry in specified register table, with given register type,
496 register index, and value.
497
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
502
503 @note This service could be called by BSP only.
504 **/
505 #define PRE_SMM_CPU_REGISTER_TABLE_WRITE64(ProcessorNumber, RegisterType, Index, Value) \
506 do { \
507 PreSmmCpuRegisterTableWrite (ProcessorNumber, RegisterType, Index, MAX_UINT64, Value); \
508 } while(FALSE);
509
510 /**
511 Adds a bit field write entry in specified register table.
512
513 This macro adds an entry in specified register table, with given register type,
514 register index, bit field section, and value.
515
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.
522
523 @note This service could be called by BSP only.
524 **/
525 #define PRE_SMM_CPU_REGISTER_TABLE_WRITE_FIELD(ProcessorNumber, RegisterType, Index, Type, Field, Value) \
526 do { \
527 UINT64 ValueMask; \
528 ValueMask = MAX_UINT64; \
529 ((Type *)(&ValueMask))->Field = 0; \
530 PreSmmCpuRegisterTableWrite (ProcessorNumber, RegisterType, Index, ~ValueMask, Value); \
531 } while(FALSE);
532
533 #endif