1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
|
/** @file
Copyright (c) 2018, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials are licensed and made available under
the terms and conditions of the BSD License that accompanies this distribution.
The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php.
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
#ifndef _CPU_CONFIG_LIB_H_
#define _CPU_CONFIG_LIB_H_
#include <Protocol/MpService.h>
#include <AcpiCpuData.h>
//
// Bits definition of PcdProcessorFeatureUserConfiguration,
// PcdProcessorFeatureCapability, and PcdProcessorFeatureSetting
//
#define PCD_CPU_HT_BIT 0x00000001
#define PCD_CPU_CMP_BIT 0x00000002
#define PCD_CPU_L2_CACHE_BIT 0x00000004
#define PCD_CPU_L2_ECC_BIT 0x00000008
#define PCD_CPU_VT_BIT 0x00000010
#define PCD_CPU_LT_BIT 0x00000020
#define PCD_CPU_EXECUTE_DISABLE_BIT 0x00000040
#define PCD_CPU_L3_CACHE_BIT 0x00000080
#define PCD_CPU_MAX_CPUID_VALUE_LIMIT_BIT 0x00000100
#define PCD_CPU_FAST_STRING_BIT 0x00000200
#define PCD_CPU_FERR_SIGNAL_BREAK_BIT 0x00000400
#define PCD_CPU_PECI_BIT 0x00000800
#define PCD_CPU_HARDWARE_PREFETCHER_BIT 0x00001000
#define PCD_CPU_ADJACENT_CACHE_LINE_PREFETCH_BIT 0x00002000
#define PCD_CPU_DCU_PREFETCHER_BIT 0x00004000
#define PCD_CPU_IP_PREFETCHER_BIT 0x00008000
#define PCD_CPU_MACHINE_CHECK_BIT 0x00010000
#define PCD_CPU_THERMAL_MANAGEMENT_BIT 0x00040000
#define PCD_CPU_EIST_BIT 0x00080000
#define PCD_CPU_C1E_BIT 0x00200000
#define PCD_CPU_C2E_BIT 0x00400000
#define PCD_CPU_C3E_BIT 0x00800000
#define PCD_CPU_C4E_BIT 0x01000000
#define PCD_CPU_HARD_C4E_BIT 0x02000000
#define PCD_CPU_DEEP_C4_BIT 0x04000000
#define PCD_CPU_A20M_DISABLE_BIT 0x08000000
#define PCD_CPU_MONITOR_MWAIT_BIT 0x10000000
#define PCD_CPU_TSTATE_BIT 0x20000000
#define PCD_CPU_TURBO_MODE_BIT 0x80000000
//
// Bits definition of PcdProcessorFeatureUserConfigurationEx1,
// PcdProcessorFeatureCapabilityEx1, and PcdProcessorFeatureSettingEx1
//
#define PCD_CPU_C_STATE_BIT 0x00000001
#define PCD_CPU_C1_AUTO_DEMOTION_BIT 0x00000002
#define PCD_CPU_C3_AUTO_DEMOTION_BIT 0x00000004
#define PCD_CPU_MLC_STREAMER_PREFETCHER_BIT 0x00000008
#define PCD_CPU_MLC_SPATIAL_PREFETCHER_BIT 0x00000010
#define PCD_CPU_THREE_STRIKE_COUNTER_BIT 0x00000020
#define PCD_CPU_ENERGY_PERFORMANCE_BIAS_BIT 0x00000040
#define PCD_CPU_DCA_BIT 0x00000080
#define PCD_CPU_X2APIC_BIT 0x00000100
#define PCD_CPU_AES_BIT 0x00000200
#define PCD_CPU_APIC_TPR_UPDATE_MESSAGE_BIT 0x00000400
#define PCD_CPU_SOCKET_ID_REASSIGNMENT_BIT 0x00000800
#define PCD_CPU_PECI_DOWNSTREAM_WRITE_BIT 0x00001000
#define PCD_CPU_ENABLE_IA_UNTRUSTED_MODE_BIT 0x00002000
#define PCD_CPU_L2_PREFETCHER_BIT 0x00004000
#define PCD_CPU_L1_DATA_PREFETCHER_BIT 0x00008000
#define PCD_CPU_C1_AUTO_UNDEMOTION_BIT 0x00010000
#define PCD_CPU_C3_AUTO_UNDEMOTION_BIT 0x00020000
//
// Value definition for PcdCpuCallbackSignal
//
#define CPU_BYPASS_SIGNAL 0x00000000
#define CPU_DATA_COLLECTION_SIGNAL 0x00000001
#define CPU_PROCESSOR_FEATURE_LIST_CONFIG_SIGNAL 0x00000002
#define CPU_REGISTER_TABLE_TRANSLATION_SIGNAL 0x00000003
#define CPU_PROCESSOR_SETTING_SIGNAL 0x00000004
#define CPU_PROCESSOR_SETTING_END_SIGNAL 0x00000005
// CPU C State Settings
#define C3_ENABLE 0x02
#define C6_ENABLE 0x03
#define C7_ENABLE 0x04
#define C8_ENABLE 0x05
#define C9_ENABLE 0x06
#define C10_ENABLE 0x07
typedef struct {
UINT32 RegEax;
UINT32 RegEbx;
UINT32 RegEcx;
UINT32 RegEdx;
} EFI_CPUID_REGISTER;
//
// Enumeration of processor features
//
typedef enum {
Ht,
Cmp,
Vt,
ExecuteDisableBit,
L3Cache,
MaxCpuidValueLimit,
FastString,
FerrSignalBreak,
Peci,
HardwarePrefetcher,
AdjacentCacheLinePrefetch,
DcuPrefetcher,
IpPrefetcher,
ThermalManagement,
Eist,
BiDirectionalProchot,
Forcepr,
C1e,
C2e,
C3e,
C4e,
HardC4e,
DeepC4,
Microcode,
Microcode2,
MachineCheck,
GateA20MDisable,
MonitorMwait,
TState,
TurboMode,
CState,
C1AutoDemotion,
C3AutoDemotion,
MlcStreamerPrefetcher,
MlcSpatialPrefetcher,
ThreeStrikeCounter,
EnergyPerformanceBias,
Dca,
X2Apic,
Aes,
ApicTprUpdateMessage,
TccActivation,
PeciDownstreamWrite,
IaUntrustedMode,
L2Prefetcher,
L1DataPrefetcher,
C1AutoUndemotion,
C3AutoUndemotion,
CpuFeatureMaximum
} CPU_FEATURE_ID;
//
// Structure for collected processor feature capability,
// and feature-specific attribute.
//
typedef struct {
BOOLEAN Capability;
VOID *Attribute;
} CPU_FEATURE_DATA;
//
// Structure for collected CPUID data.
//
typedef struct {
EFI_CPUID_REGISTER *CpuIdLeaf;
UINTN NumberOfBasicCpuidLeafs;
UINTN NumberOfExtendedCpuidLeafs;
UINTN NumberOfCacheAndTlbCpuidLeafs;
UINTN NumberOfDeterministicCacheParametersCpuidLeafs;
UINTN NumberOfExtendedTopologyEnumerationLeafs;
} CPU_CPUID_DATA;
typedef struct {
UINTN Ratio;
UINTN Vid;
UINTN Power;
UINTN TransitionLatency;
UINTN BusMasterLatency;
} FVID_ENTRY;
//
// Miscellaneous processor data
//
typedef struct {
//
// Local Apic Data
//
UINT32 InitialApicID; ///< Initial APIC ID
UINT32 ApicID; ///< Current APIC ID
EFI_PHYSICAL_ADDRESS ApicBase;
UINT32 ApicVersion;
//
// Frequency data
//
UINTN IntendedFsbFrequency;
UINTN ActualFsbFrequency;
BOOLEAN FrequencyLocked;
UINTN MaxCoreToBusRatio;
UINTN MinCoreToBusRatio;
UINTN MaxTurboRatio;
UINTN MaxVid;
UINTN MinVid;
UINTN PackageTdp;
UINTN CoreTdp;
UINTN NumberOfPStates;
FVID_ENTRY *FvidTable;
//
// Config TDP data
//
UINTN PkgMinPwrLvl1;
UINTN PkgMaxPwrLvl1;
UINTN ConfigTDPLvl1Ratio;
UINTN PkgTDPLvl1;
UINTN PkgMinPwrLvl2;
UINTN PkgMaxPwrLvl2;
UINTN ConfigTDPLvl2Ratio;
UINTN PkgTDPLvl2;
//
// Other data
//
UINT32 PlatformRequirement;
UINT64 HealthData;
UINT32 MicrocodeRevision;
UINT64 EnabledThreadCountMsr;
} CPU_MISC_DATA;
//
// Structure for all collected processor data
//
typedef struct {
CPU_CPUID_DATA CpuidData;
EFI_CPU_PHYSICAL_LOCATION ProcessorLocation;
CPU_MISC_DATA CpuMiscData;
CPU_FEATURE_DATA FeatureData[CpuFeatureMaximum];
UINT8 PackageIdBitOffset;
BOOLEAN PackageBsp;
} CPU_COLLECTED_DATA;
#define GET_CPU_MISC_DATA(ProcessorNumber, Item) \
((mCpuConfigLibConfigContextBuffer->CollectedDataBuffer[ProcessorNumber]).CpuMiscData.Item)
//
// Signature for feature list entry
//
#define EFI_CPU_FEATURE_ENTRY_SIGNATURE SIGNATURE_32 ('C', 'f', 't', 'r')
//
// Node of processor feature list
//
typedef struct {
UINT32 Signature;
CPU_FEATURE_ID FeatureID;
VOID *Attribute;
LIST_ENTRY Link;
} CPU_FEATURE_ENTRY;
#define CPU_FEATURE_ENTRY_FROM_LINK(link) CR (link, CPU_FEATURE_ENTRY, Link, EFI_CPU_FEATURE_ENTRY_SIGNATURE)
//
// Definition of Processor Configuration Context Buffer
//
typedef struct {
UINTN NumberOfProcessors;
UINTN BspNumber;
CPU_COLLECTED_DATA *CollectedDataBuffer;
LIST_ENTRY *FeatureLinkListEntry;
CPU_REGISTER_TABLE *PreSmmInitRegisterTable;
CPU_REGISTER_TABLE *RegisterTable;
UINTN *SettingSequence;
} CPU_CONFIG_CONTEXT_BUFFER;
//
// Structure conveying socket ID configuration information.
//
typedef struct {
UINT32 DefaultSocketId;
UINT32 NewSocketId;
} CPU_SOCKET_ID_INFO;
extern CPU_CONFIG_CONTEXT_BUFFER *mCpuConfigLibConfigContextBuffer;
/**
Set feature capability and related attribute.
This function sets the feature capability and its attribute.
@param ProcessorNumber Handle number of specified logical processor
@param FeatureID The ID of the feature.
@param Attribute Feature-specific data.
**/
VOID
EFIAPI
SetProcessorFeatureCapability (
IN UINTN ProcessorNumber,
IN CPU_FEATURE_ID FeatureID,
IN VOID *Attribute
);
/**
Clears feature capability and related attribute.
This function clears the feature capability and its attribute.
@param ProcessorNumber Handle number of specified logical processor
@param FeatureID The ID of the feature.
**/
VOID
EFIAPI
ClearProcessorFeatureCapability (
IN UINTN ProcessorNumber,
IN CPU_FEATURE_ID FeatureID
);
/**
Get feature capability and related attribute.
This function gets the feature capability and its attribute.
@param ProcessorNumber Handle number of specified logical processor
@param FeatureID The ID of the feature.
@param Attribute Pointer to the output feature-specific data.
@retval TRUE The feature is supported by the processor
@retval FALSE The feature is not supported by the processor
**/
BOOLEAN
EFIAPI
GetProcessorFeatureCapability (
IN UINTN ProcessorNumber,
IN CPU_FEATURE_ID FeatureID,
OUT VOID **Attribute OPTIONAL
);
typedef enum {
BasicCpuidLeaf,
ExtendedCpuidLeaf,
CacheAndTlbCpuidLeafs,
DeterministicCacheParametersCpuidLeafs,
ExtendedTopologyEnumerationCpuidLeafs
} CPUID_TYPE;
/**
Get the number of CPUID leafs of various types.
This function get the number of CPUID leafs of various types.
@param ProcessorNumber Handle number of specified logical processor
@param CpuidType The type of the CPU id.
@return Maximal index of CPUID instruction for basic leafs.
**/
UINTN
EFIAPI
GetNumberOfCpuidLeafs (
IN UINTN ProcessorNumber,
IN CPUID_TYPE CpuidType
);
/**
Get the pointer to specified CPUID leaf.
This function gets the pointer to specified CPUID leaf.
@param ProcessorNumber Handle number of specified logical processor
@param Index Index of the CPUID leaf.
@return Pointer to specified CPUID leaf
**/
EFI_CPUID_REGISTER*
EFIAPI
GetProcessorCpuid (
IN UINTN ProcessorNumber,
IN UINTN Index
);
/**
Get the pointer to specified CPUID leaf of cache and TLB parameters.
This function gets the pointer to specified CPUID leaf of cache and TLB parameters.
@param ProcessorNumber Handle number of specified logical processor
@param Index Index of the CPUID leaf.
@return Pointer to specified CPUID leaf.
**/
EFI_CPUID_REGISTER*
EFIAPI
GetCacheAndTlbCpuidLeaf (
IN UINTN ProcessorNumber,
IN UINTN Index
);
/**
Get the pointer to specified CPUID leaf of deterministic cache parameters.
This function gets the pointer to specified CPUID leaf of deterministic cache parameters.
@param ProcessorNumber Handle number of specified logical processor
@param Index Index of the CPUID leaf.
@return Pointer to specified CPUID leaf.
**/
EFI_CPUID_REGISTER*
EFIAPI
GetDeterministicCacheParametersCpuidLeaf (
IN UINTN ProcessorNumber,
IN UINTN Index
);
/**
Get the pointer to specified CPUID leaf of Extended Topology Enumeration.
This function gets the pointer to specified CPUID leaf of Extended Topology Enumeration.
@param ProcessorNumber Handle number of specified logical processor.
@param Index Index of the CPUID leaf.
@return Pointer to specified CPUID leaf.
**/
EFI_CPUID_REGISTER*
EFIAPI
GetExtendedTopologyEnumerationCpuidLeafs (
IN UINTN ProcessorNumber,
IN UINTN Index
);
/**
Get the version information of specified logical processor.
This function gets the version information of specified logical processor,
including family ID, model ID, stepping ID and processor type.
@param ProcessorNumber Handle number of specified logical processor
@param DisplayedFamily Pointer to family ID for output
@param DisplayedModel Pointer to model ID for output
@param SteppingId Pointer to stepping ID for output
@param ProcessorType Pointer to processor type for output
**/
VOID
EFIAPI
GetProcessorVersionInfo (
IN UINTN ProcessorNumber,
OUT UINT32 *DisplayedFamily OPTIONAL,
OUT UINT32 *DisplayedModel OPTIONAL,
OUT UINT32 *SteppingId OPTIONAL,
OUT UINT32 *ProcessorType OPTIONAL
);
/**
Get initial local APIC ID of specified logical processor
This function gets initial local APIC ID of specified logical processor.
@param ProcessorNumber Handle number of specified logical processor
@return Initial local APIC ID of specified logical processor
**/
UINT32
EFIAPI
GetInitialLocalApicId (
UINTN ProcessorNumber
);
/**
Get the location of specified processor.
This function gets the location of specified processor, including
package number, core number within package, thread number within core.
@param ProcessorNumber Handle number of specified logical processor.
@param PackageNumber Pointer to the output package number.
@param CoreNumber Pointer to the output core number.
@param ThreadNumber Pointer to the output thread number.
**/
VOID
EFIAPI
GetProcessorLocation (
IN UINTN ProcessorNumber,
OUT UINT32 *PackageNumber OPTIONAL,
OUT UINT32 *CoreNumber OPTIONAL,
OUT UINT32 *ThreadNumber OPTIONAL
);
/**
Get the Feature entry at specified position in a feature list.
This function gets the Feature entry at specified position in a feature list.
@param ProcessorNumber Handle number of specified logical processor
@param FeatureIndex The index of the node in feature list.
@param Attribute Pointer to output feature-specific attribute
@return Feature ID of specified feature. CpuFeatureMaximum means not found
**/
CPU_FEATURE_ID
EFIAPI
GetProcessorFeatureEntry (
IN UINTN ProcessorNumber,
IN UINTN FeatureIndex,
OUT VOID **Attribute OPTIONAL
);
/**
Append a feature entry at the end of a feature list.
This function appends a feature entry at the end of a feature list.
@param ProcessorNumber Handle number of specified logical processor
@param FeatureID ID of the specified feature.
@param Attribute Feature-specific attribute.
@retval EFI_SUCCESS This function always return EFI_SUCCESS
**/
EFI_STATUS
EFIAPI
AppendProcessorFeatureIntoList (
IN UINTN ProcessorNumber,
IN CPU_FEATURE_ID FeatureID,
IN VOID *Attribute
);
/**
Delete a feature entry in a feature list.
This function deletes a feature entry in a feature list.
@param ProcessorNumber Handle number of specified logical processor
@param FeatureIndex The index of the node in feature list.
@retval EFI_SUCCESS The feature node successfully removed.
@retval EFI_INVALID_PARAMETER Index surpasses the length of list.
**/
EFI_STATUS
EFIAPI
DeleteProcessorFeatureFromList (
IN UINTN ProcessorNumber,
IN UINTN FeatureIndex
);
/**
Insert a feature entry into a feature list.
This function insert a feature entry into a feature list before a node specified by FeatureIndex.
@param ProcessorNumber Handle number of specified logical processor
@param FeatureIndex The index of the new node in feature list.
@param FeatureID ID of the specified feature.
@param Attribute Feature-specific attribute.
@retval EFI_SUCCESS The feature node successfully inserted.
@retval EFI_INVALID_PARAMETER Index surpasses the length of list.
**/
EFI_STATUS
EFIAPI
InsertProcessorFeatureIntoList (
IN UINTN ProcessorNumber,
IN UINTN FeatureIndex,
IN CPU_FEATURE_ID FeatureID,
IN VOID *Attribute
);
/**
Add an entry in the post-SMM-init register table.
This function adds an entry in the post-SMM-init register table, with given register type,
register index, bit section and value.
@param ProcessorNumber Handle number of specified logical processor
@param RegisterType Type of the register to program
@param Index Index of the register to program
@param ValidBitStart Start of the bit section
@param ValidBitLength Length of the bit section
@param Value Value to write
**/
VOID
EFIAPI
WriteRegisterTable (
IN UINTN ProcessorNumber,
IN REGISTER_TYPE RegisterType,
IN UINT32 Index,
IN UINT8 ValidBitStart,
IN UINT8 ValidBitLength,
IN UINT64 Value
);
/**
Add an entry in the pre-SMM-init register table.
This function adds an entry in the pre-SMM-init register table, with given register type,
register index, bit section and value.
@param ProcessorNumber Handle number of specified logical processor
@param RegisterType Type of the register to program
@param Index Index of the register to program
@param ValidBitStart Start of the bit section
@param ValidBitLength Length of the bit section
@param Value Value to write
**/
VOID
EFIAPI
WritePreSmmInitRegisterTable (
IN UINTN ProcessorNumber,
IN REGISTER_TYPE RegisterType,
IN UINT32 Index,
IN UINT8 ValidBitStart,
IN UINT8 ValidBitLength,
IN UINT64 Value
);
/**
Set the sequence of processor setting.
This function sets the a processor setting at the position in
setting sequence specified by Index.
@param Index The zero-based index in the sequence.
@param ProcessorNumber Handle number of the processor to set.
@retval EFI_SUCCESS The sequence successfully modified.
@retval EFI_INVALID_PARAMETER Index surpasses the boundary of sequence.
@retval EFI_NOT_FOUND Processor specified by ProcessorNumber does not exist.
**/
EFI_STATUS
SetSettingSequence (
IN UINTN Index,
IN UINTN ProcessorNumber
);
/**
Set PcdCpuCallbackSignal, and then read the value back.
This function sets PCD entry PcdCpuCallbackSignal. If there is callback
function registered on it, the callback function will be triggered, and
it may change the value of PcdCpuCallbackSignal. This function then reads
the value of PcdCpuCallbackSignal back, the check whether it has been changed.
@param Value The value to set to PcdCpuCallbackSignal.
@return The value of PcdCpuCallbackSignal read back.
**/
UINT8
SetAndReadCpuCallbackSignal (
IN UINT8 Value
);
#endif
|