]> git.proxmox.com Git - mirror_edk2.git/blob - Vlv2TbltDevicePkg/SmBiosMiscDxe/MiscProcessorInformationFunction.c
BaseTools/BinToPcd: Fix Python 2.7.x compatibility issue
[mirror_edk2.git] / Vlv2TbltDevicePkg / SmBiosMiscDxe / MiscProcessorInformationFunction.c
1 /*++
2
3 Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved.<BR>
4
5 This program and the accompanying materials are licensed and made available under
6 the terms and conditions of the BSD License that accompanies this distribution.
7 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 Module Name:
16
17 MiscProcessorInformationFunction.c
18
19 Abstract:
20
21 Onboard processor information boot time changes.
22 SMBIOS type 4.
23
24 --*/
25
26 #include "CommonHeader.h"
27
28 #include "MiscSubclassDriver.h"
29
30 #include <Protocol/MpService.h>
31 #include <Protocol/DataHub.h>
32 #include <Guid/DataHubRecords.h>
33 #include <Library/CpuIA32.h>
34
35 #define EfiProcessorFamilyIntelAtomProcessor 0x2B
36
37 EFI_GUID mProcessorProducerGuid;
38
39
40 /**
41 Get cache SMBIOS record handle.
42
43 @param Smbios Pointer to SMBIOS protocol instance.
44 @param CacheLevel Level of cache, starting from one.
45 @param Handle Returned record handle.
46
47 **/
48
49 VOID
50 GetCacheHandle (
51 IN EFI_SMBIOS_PROTOCOL *Smbios,
52 IN UINT8 CacheLevel,
53 OUT EFI_SMBIOS_HANDLE *Handle
54 )
55 {
56 UINT16 CacheConfig;
57 EFI_STATUS Status;
58 EFI_SMBIOS_TYPE RecordType;
59 EFI_SMBIOS_TABLE_HEADER *Buffer;
60
61 *Handle = 0;
62 RecordType = EFI_SMBIOS_TYPE_CACHE_INFORMATION;
63
64 do {
65 Status = Smbios->GetNext (
66 Smbios,
67 Handle,
68 &RecordType,
69 &Buffer,
70 NULL
71 );
72 if (!EFI_ERROR(Status)) {
73 CacheConfig = *(UINT16*)((UINT8*)Buffer + 5);
74 if ((CacheConfig & 0x7) == (CacheLevel -1) ) {
75 return;
76 }
77 }
78 } while (!EFI_ERROR(Status));
79
80 *Handle = 0xFFFF;
81 }
82
83
84 /**
85 This function makes boot time changes to the contents of the
86 MiscProcessorInformation (Type 4).
87
88 @param RecordData Pointer to copy of RecordData from the Data Table.
89
90 @retval EFI_SUCCESS All parameters were valid.
91 @retval EFI_UNSUPPORTED Unexpected RecordType value.
92 @retval EFI_INVALID_PARAMETER Invalid parameter was found.
93
94 **/
95 UINT32
96 ConvertBase10ToRaw (
97 IN EFI_EXP_BASE10_DATA *Data)
98 {
99 UINTN Index;
100 UINT32 RawData;
101
102 RawData = Data->Value;
103 for (Index = 0; Index < (UINTN) Data->Exponent; Index++) {
104 RawData *= 10;
105 }
106
107 return RawData;
108 }
109
110 #define BSEL_CR_OVERCLOCK_CONTROL 0xCD
111 #define FUSE_BSEL_MASK 0x03
112
113
114
115 UINT16 miFSBFrequencyTable[4] = {
116 83, // 83.3MHz
117 100, // 100MHz
118 133, // 133MHz
119 117 // 116.7MHz
120 };
121
122 /**
123 Determine the processor core frequency
124
125 @param None
126
127 @retval Processor core frequency multiplied by 3
128
129
130 **/
131 UINT16
132 DetermineiFsbFromMsr (
133 VOID
134 )
135 {
136 //
137 // Determine the processor core frequency
138 //
139 UINT64 Temp;
140 Temp = (EfiReadMsr (BSEL_CR_OVERCLOCK_CONTROL)) & FUSE_BSEL_MASK;
141 return miFSBFrequencyTable[(UINT32)(Temp)];
142
143 }
144
145 MISC_SMBIOS_TABLE_FUNCTION (MiscProcessorInformation)
146 {
147 CHAR8 *OptionalStrStart;
148 EFI_STRING SerialNumber;
149 CHAR16 *Version=NULL;
150 CHAR16 *Manufacturer=NULL;
151 CHAR16 *Socket=NULL;
152 CHAR16 *AssetTag=NULL;
153 CHAR16 *PartNumber=NULL;
154 UINTN SerialNumberStrLen=0;
155 UINTN VersionStrLen=0;
156 UINTN ManufacturerStrLen=0;
157 UINTN SocketStrLen=0;
158 UINTN AssetTagStrLen=0;
159 UINTN PartNumberStrLen=0;
160 UINTN ProcessorVoltage=0xAE;
161 UINT32 Eax01;
162 UINT32 Ebx01;
163 UINT32 Ecx01;
164 UINT32 Edx01;
165 STRING_REF TokenToGet;
166 EFI_STATUS Status;
167 EFI_SMBIOS_HANDLE SmbiosHandle;
168 SMBIOS_TABLE_TYPE4 *SmbiosRecord;
169 EFI_CPU_DATA_RECORD *ForType4InputData;
170 UINT16 L1CacheHandle=0;
171 UINT16 L2CacheHandle=0;
172 UINT16 L3CacheHandle=0;
173 UINTN NumberOfEnabledProcessors=0 ;
174 UINTN NumberOfProcessors=0;
175 UINT64 Frequency = 0;
176 EFI_MP_SERVICES_PROTOCOL *MpService;
177 EFI_DATA_HUB_PROTOCOL *DataHub;
178 UINT64 MonotonicCount;
179 EFI_DATA_RECORD_HEADER *Record;
180 EFI_SUBCLASS_TYPE1_HEADER *DataHeader;
181 UINT8 *SrcData;
182 EFI_PROCESSOR_VERSION_DATA *ProcessorVersion;
183 CHAR16 *NewStringToken;
184 STRING_REF TokenToUpdate;
185 PROCESSOR_ID_DATA *ProcessorId = NULL;
186
187
188 //
189 // First check for invalid parameters.
190 //
191 if (RecordData == NULL) {
192 return EFI_INVALID_PARAMETER;
193 }
194
195 ForType4InputData = (EFI_CPU_DATA_RECORD *)RecordData;
196
197 ProcessorId = AllocateZeroPool(sizeof(PROCESSOR_ID_DATA));
198 if (ProcessorId == NULL) {
199 return EFI_INVALID_PARAMETER;
200 }
201
202 //
203 // Get the Data Hub Protocol. Assume only one instance
204 //
205 Status = gBS->LocateProtocol (
206 &gEfiDataHubProtocolGuid,
207 NULL,
208 (VOID **)&DataHub
209 );
210 ASSERT_EFI_ERROR(Status);
211
212 MonotonicCount = 0;
213 Record = NULL;
214
215 do {
216 Status = DataHub->GetNextRecord (
217 DataHub,
218 &MonotonicCount,
219 NULL,
220 &Record
221 );
222 if (!EFI_ERROR(Status)) {
223 if (Record->DataRecordClass == EFI_DATA_RECORD_CLASS_DATA) {
224
225 DataHeader = (EFI_SUBCLASS_TYPE1_HEADER *)(Record + 1);
226 SrcData = (UINT8 *)(DataHeader + 1);
227
228 //
229 // Processor
230 //
231 if (CompareGuid(&Record->DataRecordGuid, &gEfiProcessorSubClassGuid)) {
232 CopyMem (&mProcessorProducerGuid, &Record->ProducerName, sizeof(EFI_GUID));
233 switch (DataHeader->RecordType) {
234 case ProcessorVoltageRecordType:
235 ProcessorVoltage = (((EFI_EXP_BASE10_DATA *)SrcData)->Value)/100 + 0x80;
236 break;
237 case ProcessorCoreFrequencyRecordType:
238 DEBUG ((EFI_D_ERROR, "ProcessorCoreFrequencyRecordType SrcData1 =%d\n", ConvertBase10ToRaw((EFI_EXP_BASE10_DATA *)SrcData)/1000000));
239 Frequency = (ConvertBase10ToRaw((EFI_EXP_BASE10_DATA *)SrcData)/1000000);
240 break;
241 case ProcessorVersionRecordType:
242 ProcessorVersion = (EFI_PROCESSOR_VERSION_DATA *)SrcData;
243 NewStringToken = HiiGetPackageString(&mProcessorProducerGuid, *ProcessorVersion, NULL);
244 TokenToUpdate = (STRING_REF)STR_MISC_PROCESSOR_VERSION;
245 HiiSetString(mHiiHandle, TokenToUpdate, NewStringToken, NULL);
246 break;
247 default:
248 break;
249 }
250 }
251 }
252 }
253 } while (!EFI_ERROR(Status) && (MonotonicCount != 0));
254
255 //
256 // Token to get for Socket Name
257 //
258 TokenToGet = STRING_TOKEN (STR_MISC_SOCKET_NAME);
259 Socket = SmbiosMiscGetString (TokenToGet);
260 SocketStrLen = StrLen(Socket);
261 if (SocketStrLen > SMBIOS_STRING_MAX_LENGTH) {
262 return EFI_UNSUPPORTED;
263 }
264
265 //
266 // Token to get for Processor Manufacturer
267 //
268 TokenToGet = STRING_TOKEN (STR_MISC_PROCESSOR_MAUFACTURER);
269 Manufacturer = SmbiosMiscGetString (TokenToGet);
270 ManufacturerStrLen = StrLen(Manufacturer);
271 if (ManufacturerStrLen > SMBIOS_STRING_MAX_LENGTH) {
272 return EFI_UNSUPPORTED;
273 }
274
275 //
276 // Token to get for Processor Version
277 //
278 TokenToGet = STRING_TOKEN (STR_MISC_PROCESSOR_VERSION);
279 Version = SmbiosMiscGetString (TokenToGet);
280 VersionStrLen = StrLen(Version);
281 if (VersionStrLen > SMBIOS_STRING_MAX_LENGTH) {
282 return EFI_UNSUPPORTED;
283 }
284
285 //
286 // Token to get for Serial Number
287 //
288 TokenToGet = STRING_TOKEN (STR_MISC_PROCESSOR_SERIAL_NUMBER);
289 SerialNumber = SmbiosMiscGetString (TokenToGet);
290 SerialNumberStrLen = StrLen(SerialNumber);
291 if (SerialNumberStrLen > SMBIOS_STRING_MAX_LENGTH) {
292 return EFI_UNSUPPORTED;
293 }
294
295 //
296 // Token to get for Assert Tag Information
297 //
298 TokenToGet = STRING_TOKEN (STR_MISC_ASSERT_TAG_DATA);
299 AssetTag = SmbiosMiscGetString (TokenToGet);
300 AssetTagStrLen = StrLen(AssetTag);
301 if (AssetTagStrLen > SMBIOS_STRING_MAX_LENGTH) {
302 return EFI_UNSUPPORTED;
303 }
304
305 //
306 // Token to get for part number Information
307 //
308 TokenToGet = STRING_TOKEN (STR_MISC_PART_NUMBER);
309 PartNumber = SmbiosMiscGetString (TokenToGet);
310 PartNumberStrLen = StrLen(PartNumber);
311 if (PartNumberStrLen > SMBIOS_STRING_MAX_LENGTH) {
312 return EFI_UNSUPPORTED;
313 }
314
315 //
316 // Two zeros following the last string.
317 //
318 SmbiosRecord = AllocateZeroPool(sizeof (SMBIOS_TABLE_TYPE4) + AssetTagStrLen + 1 + SocketStrLen + 1+ ManufacturerStrLen +1 + VersionStrLen+ 1+ SerialNumberStrLen + 1 + PartNumberStrLen+ 1 + 1);
319
320 SmbiosRecord->Hdr.Type = EFI_SMBIOS_TYPE_PROCESSOR_INFORMATION;
321 SmbiosRecord->Hdr.Length = sizeof (SMBIOS_TABLE_TYPE4);
322
323 //
324 // Make handle chosen by smbios protocol.add automatically.
325 //
326 SmbiosRecord->Hdr.Handle = 0;
327
328 SmbiosRecord-> Socket= 1;
329 SmbiosRecord -> ProcessorManufacture = 2;
330 SmbiosRecord -> ProcessorVersion = 3;
331 SmbiosRecord ->SerialNumber =4;
332
333 SmbiosRecord-> AssetTag= 5;
334 SmbiosRecord-> PartNumber= 6;
335
336 //
337 // Processor Type
338 //
339 ForType4InputData-> VariableRecord.ProcessorType= EfiCentralProcessor;
340 SmbiosRecord -> ProcessorType = ForType4InputData-> VariableRecord.ProcessorType;
341
342 //
343 // Processor Family
344 //
345 ForType4InputData-> VariableRecord.ProcessorFamily= EfiProcessorFamilyIntelAtomProcessor; //0x2B;;
346 SmbiosRecord -> ProcessorFamily = ForType4InputData-> VariableRecord.ProcessorFamily;
347 SmbiosRecord -> ExternalClock = DetermineiFsbFromMsr();
348
349 //
350 // Processor ID
351 //
352 AsmCpuid(0x001, &Eax01, &Ebx01, &Ecx01, &Edx01);
353 ProcessorId->Signature = *(PROCESSOR_SIGNATURE *)&Eax01;
354 ProcessorId->FeatureFlags = *(PROCESSOR_FEATURE_FLAGS *)&Edx01;
355 SmbiosRecord -> ProcessorId = *(PROCESSOR_ID_DATA *)ProcessorId;
356
357 //
358 // Processor Voltage
359 //
360 ForType4InputData-> VariableRecord.ProcessorVoltage= *(EFI_PROCESSOR_VOLTAGE_DATA *)&ProcessorVoltage;
361 SmbiosRecord -> Voltage = *(PROCESSOR_VOLTAGE *) &(ForType4InputData-> VariableRecord.ProcessorVoltage);
362
363 //
364 // Status
365 //
366 ForType4InputData-> VariableRecord.ProcessorHealthStatus= 0x41;//0x41;
367 SmbiosRecord -> Status = ForType4InputData-> VariableRecord.ProcessorHealthStatus;
368
369 //
370 // Processor Upgrade
371 //
372 SmbiosRecord -> ProcessorUpgrade = 0x008;
373
374 //
375 // Processor Family 2
376 //
377 SmbiosRecord -> ProcessorFamily2 = ForType4InputData-> VariableRecord.ProcessorFamily;
378
379 //
380 // Processor speed
381 //
382 SmbiosRecord-> CurrentSpeed = *(UINT16*) & Frequency;
383 SmbiosRecord-> MaxSpeed = *(UINT16*) & Frequency;
384
385 //
386 // Processor Characteristics
387 //
388 AsmCpuid(0x8000000, NULL, NULL, NULL, &Edx01);
389 Edx01= Edx01 >> 28;
390 Edx01 &= 0x01;
391 SmbiosRecord-> ProcessorCharacteristics= (UINT16)Edx01;
392
393 //
394 // Processor Core Count and Enabled core count
395 //
396 Status = gBS->LocateProtocol (
397 &gEfiMpServiceProtocolGuid,
398 NULL,
399 (void **)&MpService
400 );
401 if (!EFI_ERROR (Status)) {
402 //
403 // Determine the number of processors
404 //
405 MpService->GetNumberOfProcessors (
406 MpService,
407 &NumberOfProcessors,
408 &NumberOfEnabledProcessors
409 );
410 }
411 SmbiosRecord-> CoreCount= (UINT8)NumberOfProcessors;
412 SmbiosRecord-> EnabledCoreCount= (UINT8)NumberOfEnabledProcessors;
413 SmbiosRecord-> ThreadCount= (UINT8)NumberOfEnabledProcessors;
414 SmbiosRecord-> ProcessorCharacteristics = 0x2; // Unknown
415
416 //
417 // Processor Cache Handle
418 //
419 GetCacheHandle( Smbios,1, &L1CacheHandle);
420 GetCacheHandle( Smbios,2, &L2CacheHandle);
421 GetCacheHandle( Smbios,3, &L3CacheHandle);
422
423 //
424 // Updating Cache Handle Information
425 //
426 SmbiosRecord->L1CacheHandle = L1CacheHandle;
427 SmbiosRecord->L2CacheHandle = L2CacheHandle;
428 SmbiosRecord->L3CacheHandle = L3CacheHandle;
429
430 OptionalStrStart = (CHAR8 *)(SmbiosRecord + 1);
431 UnicodeStrToAsciiStr(Socket, OptionalStrStart);
432 UnicodeStrToAsciiStr(Manufacturer, OptionalStrStart + SocketStrLen + 1);
433 UnicodeStrToAsciiStr(Version, OptionalStrStart + SocketStrLen + 1 + ManufacturerStrLen+ 1);
434 UnicodeStrToAsciiStr(SerialNumber, OptionalStrStart + SocketStrLen + 1 + VersionStrLen + 1 + ManufacturerStrLen + 1);
435 UnicodeStrToAsciiStr(AssetTag, OptionalStrStart + SerialNumberStrLen + 1 + VersionStrLen + 1 + ManufacturerStrLen + 1 + SocketStrLen + 1);
436 UnicodeStrToAsciiStr(PartNumber, OptionalStrStart + SerialNumberStrLen + 1 + VersionStrLen + 1 + ManufacturerStrLen + 1 + SocketStrLen + 1 + AssetTagStrLen + 1 );
437
438 //
439 // Now we have got the full Smbios record, call Smbios protocol to add this record.
440 //
441 SmbiosHandle = SMBIOS_HANDLE_PI_RESERVED;
442 Status = Smbios-> Add(
443 Smbios,
444 NULL,
445 &SmbiosHandle,
446 (EFI_SMBIOS_TABLE_HEADER *) SmbiosRecord
447 );
448 if (EFI_ERROR (Status)) return Status;
449 FreePool(SmbiosRecord);
450 return Status;
451
452 }
453