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
;
183 EFI_PROCESSOR_VERSION_DATA
*ProcessorVersion
;
184 CHAR16
*NewStringToken
;
185 STRING_REF TokenToUpdate
;
186 PROCESSOR_ID_DATA
*ProcessorId
= NULL
;
190 // First check for invalid parameters.
192 if (RecordData
== NULL
) {
193 return EFI_INVALID_PARAMETER
;
196 ForType4InputData
= (EFI_CPU_DATA_RECORD
*)RecordData
;
198 ProcessorId
= AllocateZeroPool(sizeof(PROCESSOR_ID_DATA
));
199 if (ProcessorId
== NULL
) {
200 return EFI_INVALID_PARAMETER
;
204 // Get the Data Hub Protocol. Assume only one instance
206 Status
= gBS
->LocateProtocol (
207 &gEfiDataHubProtocolGuid
,
211 ASSERT_EFI_ERROR(Status
);
217 Status
= DataHub
->GetNextRecord (
223 if (!EFI_ERROR(Status
)) {
224 if (Record
->DataRecordClass
== EFI_DATA_RECORD_CLASS_DATA
) {
226 DataHeader
= (EFI_SUBCLASS_TYPE1_HEADER
*)(Record
+ 1);
227 SrcData
= (UINT8
*)(DataHeader
+ 1);
228 SrcDataSize
= Record
->RecordSize
- Record
->HeaderSize
- sizeof (EFI_SUBCLASS_TYPE1_HEADER
);
233 if (CompareGuid(&Record
->DataRecordGuid
, &gEfiProcessorSubClassGuid
)) {
234 CopyMem (&mProcessorProducerGuid
, &Record
->ProducerName
, sizeof(EFI_GUID
));
235 switch (DataHeader
->RecordType
) {
236 case ProcessorVoltageRecordType
:
237 ProcessorVoltage
= (((EFI_EXP_BASE10_DATA
*)SrcData
)->Value
)/100 + 0x80;
239 case ProcessorCoreFrequencyRecordType
:
240 DEBUG ((EFI_D_ERROR
, "ProcessorCoreFrequencyRecordType SrcData1 =%d\n", ConvertBase10ToRaw((EFI_EXP_BASE10_DATA
*)SrcData
)/1000000));
241 Frequency
= (ConvertBase10ToRaw((EFI_EXP_BASE10_DATA
*)SrcData
)/1000000);
243 case ProcessorVersionRecordType
:
244 ProcessorVersion
= (EFI_PROCESSOR_VERSION_DATA
*)SrcData
;
245 NewStringToken
= HiiGetPackageString(&mProcessorProducerGuid
, *ProcessorVersion
, NULL
);
246 TokenToUpdate
= (STRING_REF
)STR_MISC_PROCESSOR_VERSION
;
247 HiiSetString(mHiiHandle
, TokenToUpdate
, NewStringToken
, NULL
);
255 } while (!EFI_ERROR(Status
) && (MonotonicCount
!= 0));
258 // Token to get for Socket Name
260 TokenToGet
= STRING_TOKEN (STR_MISC_SOCKET_NAME
);
261 Socket
= SmbiosMiscGetString (TokenToGet
);
262 SocketStrLen
= StrLen(Socket
);
263 if (SocketStrLen
> SMBIOS_STRING_MAX_LENGTH
) {
264 return EFI_UNSUPPORTED
;
268 // Token to get for Processor Manufacturer
270 TokenToGet
= STRING_TOKEN (STR_MISC_PROCESSOR_MAUFACTURER
);
271 Manufacturer
= SmbiosMiscGetString (TokenToGet
);
272 ManufacturerStrLen
= StrLen(Manufacturer
);
273 if (ManufacturerStrLen
> SMBIOS_STRING_MAX_LENGTH
) {
274 return EFI_UNSUPPORTED
;
278 // Token to get for Processor Version
280 TokenToGet
= STRING_TOKEN (STR_MISC_PROCESSOR_VERSION
);
281 Version
= SmbiosMiscGetString (TokenToGet
);
282 VersionStrLen
= StrLen(Version
);
283 if (VersionStrLen
> SMBIOS_STRING_MAX_LENGTH
) {
284 return EFI_UNSUPPORTED
;
288 // Token to get for Serial Number
290 TokenToGet
= STRING_TOKEN (STR_MISC_PROCESSOR_SERIAL_NUMBER
);
291 SerialNumber
= SmbiosMiscGetString (TokenToGet
);
292 SerialNumberStrLen
= StrLen(SerialNumber
);
293 if (SerialNumberStrLen
> SMBIOS_STRING_MAX_LENGTH
) {
294 return EFI_UNSUPPORTED
;
298 // Token to get for Assert Tag Information
300 TokenToGet
= STRING_TOKEN (STR_MISC_ASSERT_TAG_DATA
);
301 AssetTag
= SmbiosMiscGetString (TokenToGet
);
302 AssetTagStrLen
= StrLen(AssetTag
);
303 if (AssetTagStrLen
> SMBIOS_STRING_MAX_LENGTH
) {
304 return EFI_UNSUPPORTED
;
308 // Token to get for part number Information
310 TokenToGet
= STRING_TOKEN (STR_MISC_PART_NUMBER
);
311 PartNumber
= SmbiosMiscGetString (TokenToGet
);
312 PartNumberStrLen
= StrLen(PartNumber
);
313 if (PartNumberStrLen
> SMBIOS_STRING_MAX_LENGTH
) {
314 return EFI_UNSUPPORTED
;
318 // Two zeros following the last string.
320 SmbiosRecord
= AllocateZeroPool(sizeof (SMBIOS_TABLE_TYPE4
) + AssetTagStrLen
+ 1 + SocketStrLen
+ 1+ ManufacturerStrLen
+1 + VersionStrLen
+ 1+ SerialNumberStrLen
+ 1 + PartNumberStrLen
+ 1 + 1);
322 SmbiosRecord
->Hdr
.Type
= EFI_SMBIOS_TYPE_PROCESSOR_INFORMATION
;
323 SmbiosRecord
->Hdr
.Length
= sizeof (SMBIOS_TABLE_TYPE4
);
326 // Make handle chosen by smbios protocol.add automatically.
328 SmbiosRecord
->Hdr
.Handle
= 0;
330 SmbiosRecord
-> Socket
= 1;
331 SmbiosRecord
-> ProcessorManufacture
= 2;
332 SmbiosRecord
-> ProcessorVersion
= 3;
333 SmbiosRecord
->SerialNumber
=4;
335 SmbiosRecord
-> AssetTag
= 5;
336 SmbiosRecord
-> PartNumber
= 6;
341 ForType4InputData
-> VariableRecord
.ProcessorType
= EfiCentralProcessor
;
342 SmbiosRecord
-> ProcessorType
= ForType4InputData
-> VariableRecord
.ProcessorType
;
347 ForType4InputData
-> VariableRecord
.ProcessorFamily
= EfiProcessorFamilyIntelAtomProcessor
; //0x2B;;
348 SmbiosRecord
-> ProcessorFamily
= ForType4InputData
-> VariableRecord
.ProcessorFamily
;
349 SmbiosRecord
-> ExternalClock
= DetermineiFsbFromMsr();
354 AsmCpuid(0x001, &Eax01
, &Ebx01
, &Ecx01
, &Edx01
);
355 ProcessorId
->Signature
= *(PROCESSOR_SIGNATURE
*)&Eax01
;
356 ProcessorId
->FeatureFlags
= *(PROCESSOR_FEATURE_FLAGS
*)&Edx01
;
357 SmbiosRecord
-> ProcessorId
= *(PROCESSOR_ID_DATA
*)ProcessorId
;
362 ForType4InputData
-> VariableRecord
.ProcessorVoltage
= *(EFI_PROCESSOR_VOLTAGE_DATA
*)&ProcessorVoltage
;
363 SmbiosRecord
-> Voltage
= *(PROCESSOR_VOLTAGE
*) &(ForType4InputData
-> VariableRecord
.ProcessorVoltage
);
368 ForType4InputData
-> VariableRecord
.ProcessorHealthStatus
= 0x41;//0x41;
369 SmbiosRecord
-> Status
= ForType4InputData
-> VariableRecord
.ProcessorHealthStatus
;
374 SmbiosRecord
-> ProcessorUpgrade
= 0x008;
377 // Processor Family 2
379 SmbiosRecord
-> ProcessorFamily2
= ForType4InputData
-> VariableRecord
.ProcessorFamily
;
384 SmbiosRecord
-> CurrentSpeed
= *(UINT16
*) & Frequency
;
385 SmbiosRecord
-> MaxSpeed
= *(UINT16
*) & Frequency
;
388 // Processor Characteristics
390 AsmCpuid(0x8000000, NULL
, NULL
, NULL
, &Edx01
);
393 SmbiosRecord
-> ProcessorCharacteristics
= (UINT16
)Edx01
;
396 // Processor Core Count and Enabled core count
398 Status
= gBS
->LocateProtocol (
399 &gEfiMpServiceProtocolGuid
,
403 if (!EFI_ERROR (Status
)) {
405 // Determine the number of processors
407 MpService
->GetNumberOfProcessors (
410 &NumberOfEnabledProcessors
413 SmbiosRecord
-> CoreCount
= (UINT8
)NumberOfProcessors
;
414 SmbiosRecord
-> EnabledCoreCount
= (UINT8
)NumberOfEnabledProcessors
;
415 SmbiosRecord
-> ThreadCount
= (UINT8
)NumberOfEnabledProcessors
;
416 SmbiosRecord
-> ProcessorCharacteristics
= 0x2; // Unknown
419 // Processor Cache Handle
421 GetCacheHandle( Smbios
,1, &L1CacheHandle
);
422 GetCacheHandle( Smbios
,2, &L2CacheHandle
);
423 GetCacheHandle( Smbios
,3, &L3CacheHandle
);
426 // Updating Cache Handle Information
428 SmbiosRecord
->L1CacheHandle
= L1CacheHandle
;
429 SmbiosRecord
->L2CacheHandle
= L2CacheHandle
;
430 SmbiosRecord
->L3CacheHandle
= L3CacheHandle
;
432 OptionalStrStart
= (CHAR8
*)(SmbiosRecord
+ 1);
433 UnicodeStrToAsciiStr(Socket
, OptionalStrStart
);
434 UnicodeStrToAsciiStr(Manufacturer
, OptionalStrStart
+ SocketStrLen
+ 1);
435 UnicodeStrToAsciiStr(Version
, OptionalStrStart
+ SocketStrLen
+ 1 + ManufacturerStrLen
+ 1);
436 UnicodeStrToAsciiStr(SerialNumber
, OptionalStrStart
+ SocketStrLen
+ 1 + VersionStrLen
+ 1 + ManufacturerStrLen
+ 1);
437 UnicodeStrToAsciiStr(AssetTag
, OptionalStrStart
+ SerialNumberStrLen
+ 1 + VersionStrLen
+ 1 + ManufacturerStrLen
+ 1 + SocketStrLen
+ 1);
438 UnicodeStrToAsciiStr(PartNumber
, OptionalStrStart
+ SerialNumberStrLen
+ 1 + VersionStrLen
+ 1 + ManufacturerStrLen
+ 1 + SocketStrLen
+ 1 + AssetTagStrLen
+ 1 );
441 // Now we have got the full Smbios record, call Smbios protocol to add this record.
443 SmbiosHandle
= SMBIOS_HANDLE_PI_RESERVED
;
444 Status
= Smbios
-> Add(
448 (EFI_SMBIOS_TABLE_HEADER
*) SmbiosRecord
450 if (EFI_ERROR (Status
)) return Status
;
451 FreePool(SmbiosRecord
);