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
|
/*++
Copyright (c) 2006 - 2014, 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.
Module Name:
MiscProcessorInformationFunction.c
Abstract:
Onboard processor information boot time changes.
SMBIOS type 4.
--*/
#include "CommonHeader.h"
#include "MiscSubclassDriver.h"
#include <Protocol/MpService.h>
#include <Protocol/DataHub.h>
#include <Guid/DataHubRecords.h>
#include <Library/CpuIA32.h>
#define EfiProcessorFamilyIntelAtomProcessor 0x2B
EFI_GUID mProcessorProducerGuid;
/**
Get cache SMBIOS record handle.
@param Smbios Pointer to SMBIOS protocol instance.
@param CacheLevel Level of cache, starting from one.
@param Handle Returned record handle.
**/
VOID
GetCacheHandle (
IN EFI_SMBIOS_PROTOCOL *Smbios,
IN UINT8 CacheLevel,
OUT EFI_SMBIOS_HANDLE *Handle
)
{
UINT16 CacheConfig;
EFI_STATUS Status;
EFI_SMBIOS_TYPE RecordType;
EFI_SMBIOS_TABLE_HEADER *Buffer;
*Handle = 0;
RecordType = EFI_SMBIOS_TYPE_CACHE_INFORMATION;
do {
Status = Smbios->GetNext (
Smbios,
Handle,
&RecordType,
&Buffer,
NULL
);
if (!EFI_ERROR(Status)) {
CacheConfig = *(UINT16*)((UINT8*)Buffer + 5);
if ((CacheConfig & 0x7) == (CacheLevel -1) ) {
return;
}
}
} while (!EFI_ERROR(Status));
*Handle = 0xFFFF;
}
/**
This function makes boot time changes to the contents of the
MiscProcessorInformation (Type 4).
@param RecordData Pointer to copy of RecordData from the Data Table.
@retval EFI_SUCCESS All parameters were valid.
@retval EFI_UNSUPPORTED Unexpected RecordType value.
@retval EFI_INVALID_PARAMETER Invalid parameter was found.
**/
UINT32
ConvertBase10ToRaw (
IN EFI_EXP_BASE10_DATA *Data)
{
UINTN Index;
UINT32 RawData;
RawData = Data->Value;
for (Index = 0; Index < (UINTN) Data->Exponent; Index++) {
RawData *= 10;
}
return RawData;
}
#define BSEL_CR_OVERCLOCK_CONTROL 0xCD
#define FUSE_BSEL_MASK 0x03
UINT16 miFSBFrequencyTable[4] = {
83, // 83.3MHz
100, // 100MHz
133, // 133MHz
117 // 116.7MHz
};
/**
Determine the processor core frequency
@param None
@retval Processor core frequency multiplied by 3
**/
UINT16
DetermineiFsbFromMsr (
VOID
)
{
//
// Determine the processor core frequency
//
UINT64 Temp;
Temp = (EfiReadMsr (BSEL_CR_OVERCLOCK_CONTROL)) & FUSE_BSEL_MASK;
return miFSBFrequencyTable[(UINT32)(Temp)];
}
MISC_SMBIOS_TABLE_FUNCTION (MiscProcessorInformation)
{
CHAR8 *OptionalStrStart;
EFI_STRING SerialNumber;
CHAR16 *Version=NULL;
CHAR16 *Manufacturer=NULL;
CHAR16 *Socket=NULL;
CHAR16 *AssetTag=NULL;
CHAR16 *PartNumber=NULL;
UINTN SerialNumberStrLen=0;
UINTN VersionStrLen=0;
UINTN ManufacturerStrLen=0;
UINTN SocketStrLen=0;
UINTN AssetTagStrLen=0;
UINTN PartNumberStrLen=0;
UINTN ProcessorVoltage=0xAE;
UINT32 Eax01;
UINT32 Ebx01;
UINT32 Ecx01;
UINT32 Edx01;
STRING_REF TokenToGet;
EFI_STATUS Status;
EFI_SMBIOS_HANDLE SmbiosHandle;
SMBIOS_TABLE_TYPE4 *SmbiosRecord;
EFI_CPU_DATA_RECORD *ForType4InputData;
UINT16 L1CacheHandle=0;
UINT16 L2CacheHandle=0;
UINT16 L3CacheHandle=0;
UINTN NumberOfEnabledProcessors=0 ;
UINTN NumberOfProcessors=0;
UINT64 Frequency = 0;
EFI_MP_SERVICES_PROTOCOL *MpService;
EFI_DATA_HUB_PROTOCOL *DataHub;
UINT64 MonotonicCount;
EFI_DATA_RECORD_HEADER *Record;
EFI_SUBCLASS_TYPE1_HEADER *DataHeader;
UINT8 *SrcData;
UINT32 SrcDataSize;
EFI_PROCESSOR_VERSION_DATA *ProcessorVersion;
CHAR16 *NewStringToken;
STRING_REF TokenToUpdate;
PROCESSOR_ID_DATA *ProcessorId = NULL;
//
// First check for invalid parameters.
//
if (RecordData == NULL) {
return EFI_INVALID_PARAMETER;
}
ForType4InputData = (EFI_CPU_DATA_RECORD *)RecordData;
ProcessorId = AllocateZeroPool(sizeof(PROCESSOR_ID_DATA));
if (ProcessorId == NULL) {
return EFI_INVALID_PARAMETER;
}
//
// Get the Data Hub Protocol. Assume only one instance
//
Status = gBS->LocateProtocol (
&gEfiDataHubProtocolGuid,
NULL,
(VOID **)&DataHub
);
ASSERT_EFI_ERROR(Status);
MonotonicCount = 0;
Record = NULL;
do {
Status = DataHub->GetNextRecord (
DataHub,
&MonotonicCount,
NULL,
&Record
);
if (!EFI_ERROR(Status)) {
if (Record->DataRecordClass == EFI_DATA_RECORD_CLASS_DATA) {
DataHeader = (EFI_SUBCLASS_TYPE1_HEADER *)(Record + 1);
SrcData = (UINT8 *)(DataHeader + 1);
SrcDataSize = Record->RecordSize - Record->HeaderSize - sizeof (EFI_SUBCLASS_TYPE1_HEADER);
//
// Processor
//
if (CompareGuid(&Record->DataRecordGuid, &gEfiProcessorSubClassGuid)) {
CopyMem (&mProcessorProducerGuid, &Record->ProducerName, sizeof(EFI_GUID));
switch (DataHeader->RecordType) {
case ProcessorVoltageRecordType:
ProcessorVoltage = (((EFI_EXP_BASE10_DATA *)SrcData)->Value)/100 + 0x80;
break;
case ProcessorCoreFrequencyRecordType:
DEBUG ((EFI_D_ERROR, "ProcessorCoreFrequencyRecordType SrcData1 =%d\n", ConvertBase10ToRaw((EFI_EXP_BASE10_DATA *)SrcData)/1000000));
Frequency = (ConvertBase10ToRaw((EFI_EXP_BASE10_DATA *)SrcData)/1000000);
break;
case ProcessorVersionRecordType:
ProcessorVersion = (EFI_PROCESSOR_VERSION_DATA *)SrcData;
NewStringToken = HiiGetPackageString(&mProcessorProducerGuid, *ProcessorVersion, NULL);
TokenToUpdate = (STRING_REF)STR_MISC_PROCESSOR_VERSION;
HiiSetString(mHiiHandle, TokenToUpdate, NewStringToken, NULL);
break;
default:
break;
}
}
}
}
} while (!EFI_ERROR(Status) && (MonotonicCount != 0));
//
// Token to get for Socket Name
//
TokenToGet = STRING_TOKEN (STR_MISC_SOCKET_NAME);
Socket = SmbiosMiscGetString (TokenToGet);
SocketStrLen = StrLen(Socket);
if (SocketStrLen > SMBIOS_STRING_MAX_LENGTH) {
return EFI_UNSUPPORTED;
}
//
// Token to get for Processor Manufacturer
//
TokenToGet = STRING_TOKEN (STR_MISC_PROCESSOR_MAUFACTURER);
Manufacturer = SmbiosMiscGetString (TokenToGet);
ManufacturerStrLen = StrLen(Manufacturer);
if (ManufacturerStrLen > SMBIOS_STRING_MAX_LENGTH) {
return EFI_UNSUPPORTED;
}
//
// Token to get for Processor Version
//
TokenToGet = STRING_TOKEN (STR_MISC_PROCESSOR_VERSION);
Version = SmbiosMiscGetString (TokenToGet);
VersionStrLen = StrLen(Version);
if (VersionStrLen > SMBIOS_STRING_MAX_LENGTH) {
return EFI_UNSUPPORTED;
}
//
// Token to get for Serial Number
//
TokenToGet = STRING_TOKEN (STR_MISC_PROCESSOR_SERIAL_NUMBER);
SerialNumber = SmbiosMiscGetString (TokenToGet);
SerialNumberStrLen = StrLen(SerialNumber);
if (SerialNumberStrLen > SMBIOS_STRING_MAX_LENGTH) {
return EFI_UNSUPPORTED;
}
//
// Token to get for Assert Tag Information
//
TokenToGet = STRING_TOKEN (STR_MISC_ASSERT_TAG_DATA);
AssetTag = SmbiosMiscGetString (TokenToGet);
AssetTagStrLen = StrLen(AssetTag);
if (AssetTagStrLen > SMBIOS_STRING_MAX_LENGTH) {
return EFI_UNSUPPORTED;
}
//
// Token to get for part number Information
//
TokenToGet = STRING_TOKEN (STR_MISC_PART_NUMBER);
PartNumber = SmbiosMiscGetString (TokenToGet);
PartNumberStrLen = StrLen(PartNumber);
if (PartNumberStrLen > SMBIOS_STRING_MAX_LENGTH) {
return EFI_UNSUPPORTED;
}
//
// Two zeros following the last string.
//
SmbiosRecord = AllocateZeroPool(sizeof (SMBIOS_TABLE_TYPE4) + AssetTagStrLen + 1 + SocketStrLen + 1+ ManufacturerStrLen +1 + VersionStrLen+ 1+ SerialNumberStrLen + 1 + PartNumberStrLen+ 1 + 1);
SmbiosRecord->Hdr.Type = EFI_SMBIOS_TYPE_PROCESSOR_INFORMATION;
SmbiosRecord->Hdr.Length = sizeof (SMBIOS_TABLE_TYPE4);
//
// Make handle chosen by smbios protocol.add automatically.
//
SmbiosRecord->Hdr.Handle = 0;
SmbiosRecord-> Socket= 1;
SmbiosRecord -> ProcessorManufacture = 2;
SmbiosRecord -> ProcessorVersion = 3;
SmbiosRecord ->SerialNumber =4;
SmbiosRecord-> AssetTag= 5;
SmbiosRecord-> PartNumber= 6;
//
// Processor Type
//
ForType4InputData-> VariableRecord.ProcessorType= EfiCentralProcessor;
SmbiosRecord -> ProcessorType = ForType4InputData-> VariableRecord.ProcessorType;
//
// Processor Family
//
ForType4InputData-> VariableRecord.ProcessorFamily= EfiProcessorFamilyIntelAtomProcessor; //0x2B;;
SmbiosRecord -> ProcessorFamily = ForType4InputData-> VariableRecord.ProcessorFamily;
SmbiosRecord -> ExternalClock = DetermineiFsbFromMsr();
//
// Processor ID
//
AsmCpuid(0x001, &Eax01, &Ebx01, &Ecx01, &Edx01);
ProcessorId->Signature = *(PROCESSOR_SIGNATURE *)&Eax01;
ProcessorId->FeatureFlags = *(PROCESSOR_FEATURE_FLAGS *)&Edx01;
SmbiosRecord -> ProcessorId = *(PROCESSOR_ID_DATA *)ProcessorId;
//
// Processor Voltage
//
ForType4InputData-> VariableRecord.ProcessorVoltage= *(EFI_PROCESSOR_VOLTAGE_DATA *)&ProcessorVoltage;
SmbiosRecord -> Voltage = *(PROCESSOR_VOLTAGE *) &(ForType4InputData-> VariableRecord.ProcessorVoltage);
//
// Status
//
ForType4InputData-> VariableRecord.ProcessorHealthStatus= 0x41;//0x41;
SmbiosRecord -> Status = ForType4InputData-> VariableRecord.ProcessorHealthStatus;
//
// Processor Upgrade
//
SmbiosRecord -> ProcessorUpgrade = 0x008;
//
// Processor Family 2
//
SmbiosRecord -> ProcessorFamily2 = ForType4InputData-> VariableRecord.ProcessorFamily;
//
// Processor speed
//
SmbiosRecord-> CurrentSpeed = *(UINT16*) & Frequency;
SmbiosRecord-> MaxSpeed = *(UINT16*) & Frequency;
//
// Processor Characteristics
//
AsmCpuid(0x8000000, NULL, NULL, NULL, &Edx01);
Edx01= Edx01 >> 28;
Edx01 &= 0x01;
SmbiosRecord-> ProcessorCharacteristics= (UINT16)Edx01;
//
// Processor Core Count and Enabled core count
//
Status = gBS->LocateProtocol (
&gEfiMpServiceProtocolGuid,
NULL,
(void **)&MpService
);
if (!EFI_ERROR (Status)) {
//
// Determine the number of processors
//
MpService->GetNumberOfProcessors (
MpService,
&NumberOfProcessors,
&NumberOfEnabledProcessors
);
}
SmbiosRecord-> CoreCount= (UINT8)NumberOfProcessors;
SmbiosRecord-> EnabledCoreCount= (UINT8)NumberOfEnabledProcessors;
SmbiosRecord-> ThreadCount= (UINT8)NumberOfEnabledProcessors;
SmbiosRecord-> ProcessorCharacteristics = 0x2; // Unknown
//
// Processor Cache Handle
//
GetCacheHandle( Smbios,1, &L1CacheHandle);
GetCacheHandle( Smbios,2, &L2CacheHandle);
GetCacheHandle( Smbios,3, &L3CacheHandle);
//
// Updating Cache Handle Information
//
SmbiosRecord->L1CacheHandle = L1CacheHandle;
SmbiosRecord->L2CacheHandle = L2CacheHandle;
SmbiosRecord->L3CacheHandle = L3CacheHandle;
OptionalStrStart = (CHAR8 *)(SmbiosRecord + 1);
UnicodeStrToAsciiStr(Socket, OptionalStrStart);
UnicodeStrToAsciiStr(Manufacturer, OptionalStrStart + SocketStrLen + 1);
UnicodeStrToAsciiStr(Version, OptionalStrStart + SocketStrLen + 1 + ManufacturerStrLen+ 1);
UnicodeStrToAsciiStr(SerialNumber, OptionalStrStart + SocketStrLen + 1 + VersionStrLen + 1 + ManufacturerStrLen + 1);
UnicodeStrToAsciiStr(AssetTag, OptionalStrStart + SerialNumberStrLen + 1 + VersionStrLen + 1 + ManufacturerStrLen + 1 + SocketStrLen + 1);
UnicodeStrToAsciiStr(PartNumber, OptionalStrStart + SerialNumberStrLen + 1 + VersionStrLen + 1 + ManufacturerStrLen + 1 + SocketStrLen + 1 + AssetTagStrLen + 1 );
//
// Now we have got the full Smbios record, call Smbios protocol to add this record.
//
SmbiosHandle = SMBIOS_HANDLE_PI_RESERVED;
Status = Smbios-> Add(
Smbios,
NULL,
&SmbiosHandle,
(EFI_SMBIOS_TABLE_HEADER *) SmbiosRecord
);
if (EFI_ERROR (Status)) return Status;
FreePool(SmbiosRecord);
return Status;
}
|