]> git.proxmox.com Git - mirror_edk2.git/blob - UefiCpuPkg/Include/Library/RegisterCpuFeaturesLib.h
048fd48c124e9fdb02e500fbf9cb0200d5c7fa2d
[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 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 Prepares for the data used by CPU feature detection and initialization.
171
172 @param[in] NumberOfProcessors The number of CPUs in the platform.
173
174 @return Pointer to a buffer of CPU related configuration data.
175
176 @note This service could be called by BSP only.
177 **/
178 typedef
179 VOID *
180 (EFIAPI *CPU_FEATURE_GET_CONFIG_DATA)(
181 IN UINTN NumberOfProcessors
182 );
183
184 /**
185 Detects if CPU feature supported on current processor.
186
187 @param[in] ProcessorNumber The index of the CPU executing this function.
188 @param[in] CpuInfo A pointer to the REGISTER_CPU_FEATURE_INFORMATION
189 structure for the CPU executing this function.
190 @param[in] ConfigData A pointer to the configuration buffer returned
191 by CPU_FEATURE_GET_CONFIG_DATA. NULL if
192 CPU_FEATURE_GET_CONFIG_DATA was not provided in
193 RegisterCpuFeature().
194
195 @retval TRUE CPU feature is supported.
196 @retval FALSE CPU feature is not supported.
197
198 @note This service could be called by BSP/APs.
199 **/
200 typedef
201 BOOLEAN
202 (EFIAPI *CPU_FEATURE_SUPPORT)(
203 IN UINTN ProcessorNumber,
204 IN REGISTER_CPU_FEATURE_INFORMATION *CpuInfo,
205 IN VOID *ConfigData OPTIONAL
206 );
207
208 /**
209 Initializes CPU feature to specific state.
210
211 This service does not initialize hardware and only produces entries in the
212 Register Table for specified processor. Hardware initialization on BSP/APs
213 will be done in CpuFeaturesInitialize().
214
215 @param[in] ProcessorNumber The index of the CPU executing this function.
216 @param[in] CpuInfo A pointer to the REGISTER_CPU_FEATURE_INFORMATION
217 structure for the CPU executing this function.
218 @param[in] ConfigData A pointer to the configuration buffer returned
219 by CPU_FEATURE_GET_CONFIG_DATA. NULL if
220 CPU_FEATURE_GET_CONFIG_DATA was not provided in
221 RegisterCpuFeature().
222 @param[in] State If TRUE, then the CPU feature must be enabled.
223 If FALSE, then the CPU feature must be disabled.
224
225 @retval RETURN_SUCCESS CPU feature is initialized.
226
227 @note This service could be called by BSP only.
228 **/
229 typedef
230 RETURN_STATUS
231 (EFIAPI *CPU_FEATURE_INITIALIZE)(
232 IN UINTN ProcessorNumber,
233 IN REGISTER_CPU_FEATURE_INFORMATION *CpuInfo,
234 IN VOID *ConfigData, OPTIONAL
235 IN BOOLEAN State
236 );
237
238 /**
239 Registers a CPU Feature.
240
241 @param[in] FeatureName A Null-terminated Ascii string indicates CPU feature
242 name.
243 @param[in] GetConfigDataFunc CPU feature get configuration data function. This
244 is an optional parameter that may be NULL. If NULL,
245 then the most recently registered function for the
246 CPU feature is used. If no functions are registered
247 for a CPU feature, then the CPU configuration data
248 for the registered feature is NULL.
249 @param[in] SupportFunc CPU feature support 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 is assumed to be
254 supported by all CPUs.
255 @param[in] InitializeFunc CPU feature initialize function. This is an optional
256 parameter that may be NULL. If NULL, then the most
257 recently registered function for the CPU feature is
258 used. If no functions are registered for a CPU
259 feature, then the CPU feature initialization is
260 skipped.
261 @param[in] ... Variable argument list of UINT32 CPU feature value.
262 Values with no modifiers are the features provided
263 by the registered functions.
264 Values with CPU_FEATURE_BEFORE modifier are features
265 that must be initialized after the features provided
266 by the registered functions are used.
267 Values with CPU_FEATURE_AFTER modifier are features
268 that must be initialized before the features provided
269 by the registered functions are used.
270 The last argument in this variable argument list must
271 always be CPU_FEATURE_END.
272
273 @retval RETURN_SUCCESS The CPU feature was successfully registered.
274 @retval RETURN_OUT_OF_RESOURCES There are not enough resources to register
275 the CPU feature.
276 @retval RETURN_UNSUPPORTED Registration of the CPU feature is not
277 supported due to a circular dependency between
278 BEFORE and AFTER features.
279
280 @note This service could be called by BSP only.
281 **/
282 RETURN_STATUS
283 EFIAPI
284 RegisterCpuFeature (
285 IN CHAR8 *FeatureName, OPTIONAL
286 IN CPU_FEATURE_GET_CONFIG_DATA GetConfigDataFunc, OPTIONAL
287 IN CPU_FEATURE_SUPPORT SupportFunc, OPTIONAL
288 IN CPU_FEATURE_INITIALIZE InitializeFunc, OPTIONAL
289 ...
290 );
291
292 /**
293 Performs CPU features detection.
294
295 This service will invoke MP service to check CPU features'
296 capabilities on BSP/APs.
297
298 @note This service could be called by BSP only.
299 **/
300 VOID
301 EFIAPI
302 CpuFeaturesDetect (
303 VOID
304 );
305
306 /**
307 Performs CPU features Initialization.
308
309 This service will invoke MP service to perform CPU features
310 initialization on BSP/APs per user configuration.
311
312 @note This service could be called by BSP only.
313 **/
314 VOID
315 EFIAPI
316 CpuFeaturesInitialize (
317 VOID
318 );
319
320 /**
321 Switches to assigned BSP after CPU features initialization.
322
323 @param[in] ProcessorNumber The index of the CPU executing this function.
324
325 @note This service could be called by BSP only.
326 **/
327 VOID
328 EFIAPI
329 SwitchBspAfterFeaturesInitialize (
330 IN UINTN ProcessorNumber
331 );
332
333 /**
334 Adds an entry in specified register table.
335
336 This function adds an entry in specified register table, with given register type,
337 register index, bit section and value.
338
339 @param[in] ProcessorNumber The index of the CPU to add a register table entry.
340 @param[in] RegisterType Type of the register to program
341 @param[in] Index Index of the register to program
342 @param[in] ValueMask Mask of bits in register to write
343 @param[in] Value Value to write
344
345 @note This service could be called by BSP only.
346 **/
347 VOID
348 EFIAPI
349 CpuRegisterTableWrite (
350 IN UINTN ProcessorNumber,
351 IN REGISTER_TYPE RegisterType,
352 IN UINT64 Index,
353 IN UINT64 ValueMask,
354 IN UINT64 Value
355 );
356
357 /**
358 Adds an entry in specified Pre-SMM register table.
359
360 This function adds an entry in specified register table, with given register type,
361 register index, bit section and value.
362
363 @param[in] ProcessorNumber The index of the CPU to add a register table entry.
364 @param[in] RegisterType Type of the register to program
365 @param[in] Index Index of the register to program
366 @param[in] ValueMask Mask of bits in register to write
367 @param[in] Value Value to write
368
369 @note This service could be called by BSP only.
370 **/
371 VOID
372 EFIAPI
373 PreSmmCpuRegisterTableWrite (
374 IN UINTN ProcessorNumber,
375 IN REGISTER_TYPE RegisterType,
376 IN UINT64 Index,
377 IN UINT64 ValueMask,
378 IN UINT64 Value
379 );
380
381 /**
382 Adds a 32-bit register write entry in specified register table.
383
384 This macro adds an entry in specified register table, with given register type,
385 register index, and value.
386
387 @param[in] ProcessorNumber The index of the CPU to add a register table entry.
388 @param[in] RegisterType Type of the register to program
389 @param[in] Index Index of the register to program
390 @param[in] Value Value to write
391
392 @note This service could be called by BSP only.
393 **/
394 #define CPU_REGISTER_TABLE_WRITE32(ProcessorNumber, RegisterType, Index, Value) \
395 do { \
396 CpuRegisterTableWrite (ProcessorNumber, RegisterType, Index, MAX_UINT32, Value); \
397 } while(FALSE);
398
399 /**
400 Adds a 64-bit register write entry in specified register table.
401
402 This macro adds an entry in specified register table, with given register type,
403 register index, and value.
404
405 @param[in] ProcessorNumber The index of the CPU to add a register table entry.
406 @param[in] RegisterType Type of the register to program
407 @param[in] Index Index of the register to program
408 @param[in] Value Value to write
409
410 @note This service could be called by BSP only.
411 **/
412 #define CPU_REGISTER_TABLE_WRITE64(ProcessorNumber, RegisterType, Index, Value) \
413 do { \
414 CpuRegisterTableWrite (ProcessorNumber, RegisterType, Index, MAX_UINT64, Value); \
415 } while(FALSE);
416
417 /**
418 Adds a bit field write entry in specified register table.
419
420 This macro adds an entry in specified register table, with given register type,
421 register index, bit field section, and value.
422
423 @param[in] ProcessorNumber The index of the CPU to add a register table entry.
424 @param[in] RegisterType Type of the register to program.
425 @param[in] Index Index of the register to program.
426 @param[in] Type The data type name of a register structure.
427 @param[in] Field The bit fiel name in register structure to write.
428 @param[in] Value Value to write to the bit field.
429
430 @note This service could be called by BSP only.
431 **/
432 #define CPU_REGISTER_TABLE_WRITE_FIELD(ProcessorNumber, RegisterType, Index, Type, Field, Value) \
433 do { \
434 UINT64 ValueMask; \
435 ValueMask = MAX_UINT64; \
436 ((Type *)(&ValueMask))->Field = 0; \
437 CpuRegisterTableWrite (ProcessorNumber, RegisterType, Index, ~ValueMask, Value); \
438 } while(FALSE);
439
440 /**
441 Adds a 32-bit register write entry in specified register table.
442
443 This macro adds an entry in specified register table, with given register type,
444 register index, and value.
445
446 @param[in] ProcessorNumber The index of the CPU to add a register table entry.
447 @param[in] RegisterType Type of the register to program
448 @param[in] Index Index of the register to program
449 @param[in] Value Value to write
450
451 @note This service could be called by BSP only.
452 **/
453 #define PRE_SMM_CPU_REGISTER_TABLE_WRITE32(ProcessorNumber, RegisterType, Index, Value) \
454 do { \
455 PreSmmCpuRegisterTableWrite (ProcessorNumber, RegisterType, Index, MAX_UINT32, Value); \
456 } while(FALSE);
457
458 /**
459 Adds a 64-bit register write entry in specified register table.
460
461 This macro adds an entry in specified register table, with given register type,
462 register index, and value.
463
464 @param[in] ProcessorNumber The index of the CPU to add a register table entry.
465 @param[in] RegisterType Type of the register to program
466 @param[in] Index Index of the register to program
467 @param[in] Value Value to write
468
469 @note This service could be called by BSP only.
470 **/
471 #define PRE_SMM_CPU_REGISTER_TABLE_WRITE64(ProcessorNumber, RegisterType, Index, Value) \
472 do { \
473 PreSmmCpuRegisterTableWrite (ProcessorNumber, RegisterType, Index, MAX_UINT64, Value); \
474 } while(FALSE);
475
476 /**
477 Adds a bit field write entry in specified register table.
478
479 This macro adds an entry in specified register table, with given register type,
480 register index, bit field section, and value.
481
482 @param[in] ProcessorNumber The index of the CPU to add a register table entry.
483 @param[in] RegisterType Type of the register to program.
484 @param[in] Index Index of the register to program.
485 @param[in] Type The data type name of a register structure.
486 @param[in] Field The bit fiel name in register structure to write.
487 @param[in] Value Value to write to the bit field.
488
489 @note This service could be called by BSP only.
490 **/
491 #define PRE_SMM_CPU_REGISTER_TABLE_WRITE_FIELD(ProcessorNumber, RegisterType, Index, Type, Field, Value) \
492 do { \
493 UINT64 ValueMask; \
494 ValueMask = MAX_UINT64; \
495 ((Type *)(&ValueMask))->Field = 0; \
496 PreSmmCpuRegisterTableWrite (ProcessorNumber, RegisterType, Index, ~ValueMask, Value); \
497 } while(FALSE);
498
499 #endif