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