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