3 Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved.<BR>
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.
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.
17 MiscProcessorInformationFunction.c
21 Onboard processor information boot time changes.
26 #include "CommonHeader.h"
28 #include "MiscSubclassDriver.h"
30 #include <Protocol/MpService.h>
31 #include <Protocol/DataHub.h>
32 #include <Guid/DataHubRecords.h>
33 #include <Library/CpuIA32.h>
35 #define EfiProcessorFamilyIntelAtomProcessor 0x2B
37 EFI_GUID mProcessorProducerGuid
;
41 Get cache SMBIOS record handle.
43 @param Smbios Pointer to SMBIOS protocol instance.
44 @param CacheLevel Level of cache, starting from one.
45 @param Handle Returned record handle.
51 IN EFI_SMBIOS_PROTOCOL
*Smbios
,
53 OUT EFI_SMBIOS_HANDLE
*Handle
58 EFI_SMBIOS_TYPE RecordType
;
59 EFI_SMBIOS_TABLE_HEADER
*Buffer
;
62 RecordType
= EFI_SMBIOS_TYPE_CACHE_INFORMATION
;
65 Status
= Smbios
->GetNext (
72 if (!EFI_ERROR(Status
)) {
73 CacheConfig
= *(UINT16
*)((UINT8
*)Buffer
+ 5);
74 if ((CacheConfig
& 0x7) == (CacheLevel
-1) ) {
78 } while (!EFI_ERROR(Status
));
85 This function makes boot time changes to the contents of the
86 MiscProcessorInformation (Type 4).
88 @param RecordData Pointer to copy of RecordData from the Data Table.
90 @retval EFI_SUCCESS All parameters were valid.
91 @retval EFI_UNSUPPORTED Unexpected RecordType value.
92 @retval EFI_INVALID_PARAMETER Invalid parameter was found.
97 IN EFI_EXP_BASE10_DATA
*Data
)
102 RawData
= Data
->Value
;
103 for (Index
= 0; Index
< (UINTN
) Data
->Exponent
; Index
++) {
110 #define BSEL_CR_OVERCLOCK_CONTROL 0xCD
111 #define FUSE_BSEL_MASK 0x03
115 UINT16 miFSBFrequencyTable
[4] = {
123 Determine the processor core frequency
127 @retval Processor core frequency multiplied by 3
132 DetermineiFsbFromMsr (
137 // Determine the processor core frequency
140 Temp
= (EfiReadMsr (BSEL_CR_OVERCLOCK_CONTROL
)) & FUSE_BSEL_MASK
;
141 return miFSBFrequencyTable
[(UINT32
)(Temp
)];
145 MISC_SMBIOS_TABLE_FUNCTION (MiscProcessorInformation
)
147 CHAR8
*OptionalStrStart
;
148 EFI_STRING SerialNumber
;
149 CHAR16
*Version
=NULL
;
150 CHAR16
*Manufacturer
=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;
165 STRING_REF TokenToGet
;
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
;
182 EFI_PROCESSOR_VERSION_DATA
*ProcessorVersion
;
183 CHAR16
*NewStringToken
;
184 STRING_REF TokenToUpdate
;
185 PROCESSOR_ID_DATA
*ProcessorId
= NULL
;
189 // First check for invalid parameters.
191 if (RecordData
== NULL
) {
192 return EFI_INVALID_PARAMETER
;
195 ForType4InputData
= (EFI_CPU_DATA_RECORD
*)RecordData
;
197 ProcessorId
= AllocateZeroPool(sizeof(PROCESSOR_ID_DATA
));
198 if (ProcessorId
== NULL
) {
199 return EFI_INVALID_PARAMETER
;
203 // Get the Data Hub Protocol. Assume only one instance
205 Status
= gBS
->LocateProtocol (
206 &gEfiDataHubProtocolGuid
,
210 ASSERT_EFI_ERROR(Status
);
216 Status
= DataHub
->GetNextRecord (
222 if (!EFI_ERROR(Status
)) {
223 if (Record
->DataRecordClass
== EFI_DATA_RECORD_CLASS_DATA
) {
225 DataHeader
= (EFI_SUBCLASS_TYPE1_HEADER
*)(Record
+ 1);
226 SrcData
= (UINT8
*)(DataHeader
+ 1);
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;
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);
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
);
253 } while (!EFI_ERROR(Status
) && (MonotonicCount
!= 0));
256 // Token to get for Socket Name
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
;
266 // Token to get for Processor Manufacturer
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
;
276 // Token to get for Processor Version
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
;
286 // Token to get for Serial Number
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
;
296 // Token to get for Assert Tag Information
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
;
306 // Token to get for part number Information
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
;
316 // Two zeros following the last string.
318 SmbiosRecord
= AllocateZeroPool(sizeof (SMBIOS_TABLE_TYPE4
) + AssetTagStrLen
+ 1 + SocketStrLen
+ 1+ ManufacturerStrLen
+1 + VersionStrLen
+ 1+ SerialNumberStrLen
+ 1 + PartNumberStrLen
+ 1 + 1);
320 SmbiosRecord
->Hdr
.Type
= EFI_SMBIOS_TYPE_PROCESSOR_INFORMATION
;
321 SmbiosRecord
->Hdr
.Length
= sizeof (SMBIOS_TABLE_TYPE4
);
324 // Make handle chosen by smbios protocol.add automatically.
326 SmbiosRecord
->Hdr
.Handle
= 0;
328 SmbiosRecord
-> Socket
= 1;
329 SmbiosRecord
-> ProcessorManufacture
= 2;
330 SmbiosRecord
-> ProcessorVersion
= 3;
331 SmbiosRecord
->SerialNumber
=4;
333 SmbiosRecord
-> AssetTag
= 5;
334 SmbiosRecord
-> PartNumber
= 6;
339 ForType4InputData
-> VariableRecord
.ProcessorType
= EfiCentralProcessor
;
340 SmbiosRecord
-> ProcessorType
= ForType4InputData
-> VariableRecord
.ProcessorType
;
345 ForType4InputData
-> VariableRecord
.ProcessorFamily
= EfiProcessorFamilyIntelAtomProcessor
; //0x2B;;
346 SmbiosRecord
-> ProcessorFamily
= ForType4InputData
-> VariableRecord
.ProcessorFamily
;
347 SmbiosRecord
-> ExternalClock
= DetermineiFsbFromMsr();
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
;
360 ForType4InputData
-> VariableRecord
.ProcessorVoltage
= *(EFI_PROCESSOR_VOLTAGE_DATA
*)&ProcessorVoltage
;
361 SmbiosRecord
-> Voltage
= *(PROCESSOR_VOLTAGE
*) &(ForType4InputData
-> VariableRecord
.ProcessorVoltage
);
366 ForType4InputData
-> VariableRecord
.ProcessorHealthStatus
= 0x41;//0x41;
367 SmbiosRecord
-> Status
= ForType4InputData
-> VariableRecord
.ProcessorHealthStatus
;
372 SmbiosRecord
-> ProcessorUpgrade
= 0x008;
375 // Processor Family 2
377 SmbiosRecord
-> ProcessorFamily2
= ForType4InputData
-> VariableRecord
.ProcessorFamily
;
382 SmbiosRecord
-> CurrentSpeed
= *(UINT16
*) & Frequency
;
383 SmbiosRecord
-> MaxSpeed
= *(UINT16
*) & Frequency
;
386 // Processor Characteristics
388 AsmCpuid(0x8000000, NULL
, NULL
, NULL
, &Edx01
);
391 SmbiosRecord
-> ProcessorCharacteristics
= (UINT16
)Edx01
;
394 // Processor Core Count and Enabled core count
396 Status
= gBS
->LocateProtocol (
397 &gEfiMpServiceProtocolGuid
,
401 if (!EFI_ERROR (Status
)) {
403 // Determine the number of processors
405 MpService
->GetNumberOfProcessors (
408 &NumberOfEnabledProcessors
411 SmbiosRecord
-> CoreCount
= (UINT8
)NumberOfProcessors
;
412 SmbiosRecord
-> EnabledCoreCount
= (UINT8
)NumberOfEnabledProcessors
;
413 SmbiosRecord
-> ThreadCount
= (UINT8
)NumberOfEnabledProcessors
;
414 SmbiosRecord
-> ProcessorCharacteristics
= 0x2; // Unknown
417 // Processor Cache Handle
419 GetCacheHandle( Smbios
,1, &L1CacheHandle
);
420 GetCacheHandle( Smbios
,2, &L2CacheHandle
);
421 GetCacheHandle( Smbios
,3, &L3CacheHandle
);
424 // Updating Cache Handle Information
426 SmbiosRecord
->L1CacheHandle
= L1CacheHandle
;
427 SmbiosRecord
->L2CacheHandle
= L2CacheHandle
;
428 SmbiosRecord
->L3CacheHandle
= L3CacheHandle
;
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 );
439 // Now we have got the full Smbios record, call Smbios protocol to add this record.
441 SmbiosHandle
= SMBIOS_HANDLE_PI_RESERVED
;
442 Status
= Smbios
-> Add(
446 (EFI_SMBIOS_TABLE_HEADER
*) SmbiosRecord
448 if (EFI_ERROR (Status
)) return Status
;
449 FreePool(SmbiosRecord
);