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