Home | History | Annotate | Download | only in PlatformSetupDxe
      1 /** @file
      2 
      3   Copyright (c) 2004  - 2014, Intel Corporation. All rights reserved.<BR>
      4 
      5   This program and the accompanying materials are licensed and made available under
      7   the terms and conditions of the BSD License that accompanies this distribution.
      9   The full text of the license may be found at
     11   http://opensource.org/licenses/bsd-license.php.
     13 
     15   THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
     17   WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
     19 
     21 
     23 
     24 Module Name:
     25 
     26     SetupInfoRecords.c
     27 
     28 Abstract:
     29 
     30     This is the filter driver to retrieve data hub entries.
     31 
     32 Revision History:
     33 --*/
     34 
     35 #include "PlatformSetupDxe.h"
     36 #include <Protocol/LegacyBios.h>
     37 #include <Protocol/PciRootBridgeIo.h>
     38 #include <Protocol/SimpleNetwork.h>
     39 #include <Protocol/DevicePath.h>
     40 #include <Protocol/DiskInfo.h>
     41 #include <Protocol/IdeControllerInit.h>
     42 #include <Protocol/MpService.h>
     43 #include <Protocol/PchPlatformPolicy.h>
     44 #include <Protocol/CpuIo2.h>
     45 #include <Protocol/Smbios.h>
     46 #include <IndustryStandard/SmBios.h>
     47 #include <Library/IoLib.h>
     48 #include <Library/I2CLib.h>
     49 #include <Guid/GlobalVariable.h>
     50 
     51 #include "Valleyview.h"
     52 #include "VlvAccess.h"
     53 #include "PchAccess.h"
     54 #include "SetupMode.h"
     55 #include "PchCommonDefinitions.h"
     56 #include <PlatformBaseAddresses.h>
     57 
     58 
     59 typedef struct {
     60   UINT8  ID;
     61   CHAR8  String[16];
     62 } VLV_REV;
     63 
     64 typedef struct {
     65   UINT8 RevId;
     66   CHAR8 String[16];
     67 } SB_REV;
     68 
     69 //
     70 // Silicon Steppings
     71 //
     72 SB_REV  SBRevisionTable[] = {
     73   {V_PCH_LPC_RID_0, "(A0 Stepping)"},
     74   {V_PCH_LPC_RID_1, "(A0 Stepping)"},
     75   {V_PCH_LPC_RID_2, "(A1 Stepping)"},
     76   {V_PCH_LPC_RID_3, "(A1 Stepping)"},
     77   {V_PCH_LPC_RID_4, "(B0 Stepping)"},
     78   {V_PCH_LPC_RID_5, "(B0 Stepping)"},
     79   {V_PCH_LPC_RID_6, "(B1 Stepping)"},
     80   {V_PCH_LPC_RID_7, "(B1 Stepping)"},
     81   {V_PCH_LPC_RID_8, "(B2 Stepping)"},
     82   {V_PCH_LPC_RID_9, "(B2 Stepping)"},
     83   {V_PCH_LPC_RID_A, "(B3 Stepping)"},
     84   {V_PCH_LPC_RID_B, "(B3 Stepping)"},
     85   {V_PCH_LPC_RID_C, "(C0 Stepping)"},
     86   {V_PCH_LPC_RID_D, "(C0 Stepping)"}
     87 };
     88 
     89 #define LEFT_JUSTIFY  0x01
     90 #define PREFIX_SIGN   0x02
     91 #define PREFIX_BLANK  0x04
     92 #define COMMA_TYPE    0x08
     93 #define LONG_TYPE     0x10
     94 #define PREFIX_ZERO   0x20
     95 
     96 #define ICH_REG_REV                 0x08
     97 #define MSR_IA32_PLATFORM_ID        0x17
     98 
     99 
    100 BOOLEAN                         mSetupInfoDone = FALSE;
    101 UINT8                           mUseProductKey = 0;
    102 EFI_EXP_BASE10_DATA             mProcessorFrequency;
    103 EFI_EXP_BASE10_DATA             mProcessorFsbFrequency;
    104 
    105 EFI_GUID                        mProcessorProducerGuid;
    106 EFI_HII_HANDLE                  mHiiHandle;
    107 EFI_PLATFORM_CPU_INFO           mPlatformCpuInfo;
    108 SYSTEM_CONFIGURATION            mSystemConfiguration;
    109 EFI_PLATFORM_INFO_HOB           *mPlatformInfo;
    110 
    111 
    112 #define memset SetMem
    113 
    114 UINT16                mMemorySpeed         = 0xffff;
    115 EFI_PHYSICAL_ADDRESS  mMemorySizeChannelASlot0  = 0;
    116 UINT16                mMemorySpeedChannelASlot0 = 0xffff;
    117 EFI_PHYSICAL_ADDRESS  mMemorySizeChannelASlot1  = 0;
    118 UINT16                mMemorySpeedChannelASlot1 = 0xffff;
    119 EFI_PHYSICAL_ADDRESS  mMemorySizeChannelBSlot0  = 0;
    120 UINT16                mMemorySpeedChannelBSlot0 = 0xffff;
    121 EFI_PHYSICAL_ADDRESS  mMemorySizeChannelBSlot1  = 0;
    122 UINT16                mMemorySpeedChannelBSlot1 = 0xffff;
    123 EFI_PHYSICAL_ADDRESS  mMemorySizeChannelCSlot0  = 0;
    124 UINT16                mMemorySpeedChannelCSlot0 = 0xffff;
    125 EFI_PHYSICAL_ADDRESS  mMemorySizeChannelCSlot1  = 0;
    126 UINT16                mMemorySpeedChannelCSlot1 = 0xffff;
    127 UINTN                 mMemoryMode          = 0xff;
    128 
    129 #define CHARACTER_NUMBER_FOR_VALUE  30
    130   typedef struct {
    131   EFI_STRING_TOKEN            MemoryDeviceLocator;
    132   EFI_STRING_TOKEN            MemoryBankLocator;
    133   EFI_STRING_TOKEN            MemoryManufacturer;
    134   EFI_STRING_TOKEN            MemorySerialNumber;
    135   EFI_STRING_TOKEN            MemoryAssetTag;
    136   EFI_STRING_TOKEN            MemoryPartNumber;
    137   EFI_INTER_LINK_DATA         MemoryArrayLink;
    138   EFI_INTER_LINK_DATA         MemorySubArrayLink;
    139   UINT16                      MemoryTotalWidth;
    140   UINT16                      MemoryDataWidth;
    141   UINT64                      MemoryDeviceSize;
    142   EFI_MEMORY_FORM_FACTOR      MemoryFormFactor;
    143   UINT8                       MemoryDeviceSet;
    144   EFI_MEMORY_ARRAY_TYPE       MemoryType;
    145   EFI_MEMORY_TYPE_DETAIL      MemoryTypeDetail;
    146   UINT16                      MemorySpeed;
    147   EFI_MEMORY_STATE            MemoryState;
    148 } EFI_MEMORY_ARRAY_LINK;
    149 
    150 
    151 typedef struct {
    152   EFI_PHYSICAL_ADDRESS        MemoryArrayStartAddress;
    153   EFI_PHYSICAL_ADDRESS        MemoryArrayEndAddress;
    154   EFI_INTER_LINK_DATA         PhysicalMemoryArrayLink;
    155   UINT16                      MemoryArrayPartitionWidth;
    156 } EFI_MEMORY_ARRAY_START_ADDRESS;
    157 
    158 
    159 typedef enum {
    160   PCH_SATA_MODE_IDE = 0,
    161   PCH_SATA_MODE_AHCI,
    162   PCH_SATA_MODE_RAID,
    163   PCH_SATA_MODE_MAX
    164 } PCH_SATA_MODE;
    165 
    166 /**
    167   Acquire the string associated with the Index from smbios structure and return it.
    168   The caller is responsible for free the string buffer.
    169 
    170   @param OptionalStrStart   The start position to search the string
    171   @param Index              The index of the string to extract
    172   @param String             The string that is extracted
    173 
    174   @retval EFI_SUCCESS       The function returns EFI_SUCCESS always.
    175 
    176 **/
    177 EFI_STATUS
    178 GetOptionalStringByIndex (
    179   IN      CHAR8                   *OptionalStrStart,
    180   IN      UINT8                   Index,
    181   OUT     CHAR16                  **String
    182   )
    183 {
    184   UINTN          StrSize;
    185 
    186   if (Index == 0) {
    187     *String = AllocateZeroPool (sizeof (CHAR16));
    188     return EFI_SUCCESS;
    189   }
    190 
    191   StrSize = 0;
    192   do {
    193     Index--;
    194     OptionalStrStart += StrSize;
    195     StrSize           = AsciiStrSize (OptionalStrStart);
    196   } while (OptionalStrStart[StrSize] != 0 && Index != 0);
    197 
    198   if ((Index != 0) || (StrSize == 1)) {
    199     //
    200     // Meet the end of strings set but Index is non-zero, or
    201     // Find an empty string
    202     //
    203     return EFI_NOT_FOUND;
    204   } else {
    205     *String = AllocatePool (StrSize * sizeof (CHAR16));
    206     AsciiStrToUnicodeStr (OptionalStrStart, *String);
    207   }
    208 
    209   return EFI_SUCCESS;
    210 }
    211 
    212 /**
    213   VSPrint worker function that prints a Value as a decimal number in Buffer
    214 
    215   @param Buffer  Location to place ascii decimal number string of Value.
    216   @param Value   Decimal value to convert to a string in Buffer.
    217   @param Flags   Flags to use in printing decimal string, see file header for details.
    218   @param Width   Width of hex value.
    219 
    220   Number of characters printed.
    221 
    222 **/
    223 UINTN
    224 EfiValueToString (
    225   IN  OUT CHAR16  *Buffer,
    226   IN  INT64       Value,
    227   IN  UINTN       Flags,
    228   IN  UINTN       Width
    229   )
    230 {
    231   CHAR16    TempBuffer[CHARACTER_NUMBER_FOR_VALUE];
    232   CHAR16    *TempStr;
    233   CHAR16    *BufferPtr;
    234   UINTN     Count;
    235   UINTN     ValueCharNum;
    236   UINTN     Remainder;
    237   CHAR16    Prefix;
    238   UINTN     Index;
    239   BOOLEAN   ValueIsNegative;
    240   UINT64    TempValue;
    241 
    242   TempStr         = TempBuffer;
    243   BufferPtr       = Buffer;
    244   Count           = 0;
    245   ValueCharNum    = 0;
    246   ValueIsNegative = FALSE;
    247 
    248   if (Width > CHARACTER_NUMBER_FOR_VALUE - 1) {
    249     Width = CHARACTER_NUMBER_FOR_VALUE - 1;
    250   }
    251 
    252   if (Value < 0) {
    253     Value           = -Value;
    254     ValueIsNegative = TRUE;
    255   }
    256 
    257   do {
    258     TempValue = Value;
    259     Value = (INT64)DivU64x32 ((UINT64)Value, 10);
    260     Remainder = (UINTN)((UINT64)TempValue - 10 * Value);
    261     *(TempStr++) = (CHAR16)(Remainder + '0');
    262     ValueCharNum++;
    263     Count++;
    264     if ((Flags & COMMA_TYPE) == COMMA_TYPE) {
    265       if (ValueCharNum % 3 == 0 && Value != 0) {
    266         *(TempStr++) = ',';
    267         Count++;
    268       }
    269     }
    270   } while (Value != 0);
    271 
    272   if (ValueIsNegative) {
    273     *(TempStr++)    = '-';
    274     Count++;
    275   }
    276 
    277   if ((Flags & PREFIX_ZERO) && !ValueIsNegative) {
    278     Prefix = '0';
    279   } else {
    280     Prefix = ' ';
    281   }
    282 
    283   Index = Count;
    284   if (!(Flags & LEFT_JUSTIFY)) {
    285     for (; Index < Width; Index++) {
    286       *(TempStr++) = Prefix;
    287     }
    288   }
    289 
    290   //
    291   // Reverse temp string into Buffer.
    292   //
    293   if (Width > 0 && (UINTN) (TempStr - TempBuffer) > Width) {
    294     TempStr = TempBuffer + Width;
    295   }
    296   Index = 0;
    297   while (TempStr != TempBuffer) {
    298     *(BufferPtr++) = *(--TempStr);
    299     Index++;
    300   }
    301 
    302   *BufferPtr = 0;
    303   return Index;
    304 }
    305 
    306 static CHAR16 mHexStr[] = { L'0', L'1', L'2', L'3', L'4', L'5', L'6', L'7',
    307                             L'8', L'9', L'A', L'B', L'C', L'D', L'E', L'F' };
    308 
    309 /**
    310   VSPrint worker function that prints a Value as a hex number in Buffer
    311 
    312   @param  Buffer  Location to place ascii hex string of Value.
    313   @param  Value   Hex value to convert to a string in Buffer.
    314   @param  Flags   Flags to use in printing Hex string, see file header for details.
    315   @param  Width   Width of hex value.
    316 
    317   @retval         Number of characters printed.
    318 
    319 **/
    320 UINTN
    321 EfiValueToHexStr (
    322   IN  OUT CHAR16  *Buffer,
    323   IN  UINT64      Value,
    324   IN  UINTN       Flags,
    325   IN  UINTN       Width
    326   )
    327 {
    328   CHAR16  TempBuffer[CHARACTER_NUMBER_FOR_VALUE];
    329   CHAR16  *TempStr;
    330   CHAR16  Prefix;
    331   CHAR16  *BufferPtr;
    332   UINTN   Count;
    333   UINTN   Index;
    334 
    335   TempStr   = TempBuffer;
    336   BufferPtr = Buffer;
    337 
    338   //
    339   // Count starts at one since we will null terminate. Each iteration of the
    340   // loop picks off one nibble. Oh yea TempStr ends up backwards
    341   //
    342   Count = 0;
    343 
    344   if (Width > CHARACTER_NUMBER_FOR_VALUE - 1) {
    345     Width = CHARACTER_NUMBER_FOR_VALUE - 1;
    346   }
    347 
    348   do {
    349     Index = ((UINTN)Value & 0xf);
    350     *(TempStr++) = mHexStr[Index];
    351     Value = RShiftU64 (Value, 4);
    352     Count++;
    353   } while (Value != 0);
    354 
    355   if (Flags & PREFIX_ZERO) {
    356     Prefix = '0';
    357   } else {
    358     Prefix = ' ';
    359   }
    360 
    361   Index = Count;
    362   if (!(Flags & LEFT_JUSTIFY)) {
    363     for (; Index < Width; Index++) {
    364       *(TempStr++) = Prefix;
    365     }
    366   }
    367 
    368   //
    369   // Reverse temp string into Buffer.
    370   //
    371   if (Width > 0 && (UINTN) (TempStr - TempBuffer) > Width) {
    372     TempStr = TempBuffer + Width;
    373   }
    374   Index = 0;
    375   while (TempStr != TempBuffer) {
    376     *(BufferPtr++) = *(--TempStr);
    377     Index++;
    378   }
    379 
    380   *BufferPtr = 0;
    381   return Index;
    382 }
    383 
    384 /*++
    385   Converts MAC address to Unicode string.
    386   The value is 64-bit and the resulting string will be 12
    387   digit hex number in pairs of digits separated by dashes.
    388 
    389   @param  String    string that will contain the value
    390   @param  MacAddr   add argument and description to function comment
    391   @param  AddrSize  add argument and description to function comment
    392 
    393 **/
    394 CHAR16 *
    395 StrMacToString (
    396   OUT CHAR16              *String,
    397   IN  EFI_MAC_ADDRESS     *MacAddr,
    398   IN  UINT32              AddrSize
    399   )
    400 {
    401   UINT32  i;
    402 
    403   for (i = 0; i < AddrSize; i++) {
    404 
    405     EfiValueToHexStr (
    406       &String[2 * i],
    407       MacAddr->Addr[i] & 0xFF,
    408       PREFIX_ZERO,
    409       2
    410       );
    411   }
    412 
    413   //
    414   // Terminate the string.
    415   //
    416   String[2 * AddrSize] = L'\0';
    417 
    418   return String;
    419 }
    420 
    421 VOID UpdateLatestBootTime() {
    422   UINTN                         VarSize;
    423   EFI_STATUS                   Status;
    424   UINT64                       TimeValue;
    425   CHAR16                       Buffer[40];
    426   if (mSystemConfiguration.LogBootTime != 1) {
    427     return;
    428   }
    429   VarSize = sizeof(TimeValue);
    430   Status = gRT->GetVariable(
    431                   BOOT_TIME_NAME,
    432                   &gEfiNormalSetupGuid,
    433                   NULL,
    434                   &VarSize,
    435                   &TimeValue
    436 				          );
    437   if (EFI_ERROR(Status)) {
    438     return;
    439   }
    440   UnicodeSPrint (Buffer, sizeof (Buffer), L"%d ms", (UINT32)TimeValue);
    441   HiiSetString(mHiiHandle,STRING_TOKEN(STR_LOG_BOOT_TIME_VALUE), Buffer, NULL);
    442 }
    443 
    444 /**
    445   Get Cache Type for the specified Cache. This function is invoked when there is data records
    446   available in the Data Hub.
    447 
    448   Get Cache Type function arguments:
    449 
    450   @param  Instance        The instance number of the subclass with the same ProducerName..
    451   @param  SubInstance     The instance number of the RecordType for the same Instance.
    452   @param  CacheType       Cache type, see definition of EFI_CACHE_TYPE_DATA.
    453 
    454   @retval EFI_STATUS
    455 
    456 **/
    457 EFI_STATUS
    458 GetCacheType(
    459   IN  UINT16                            Instance,
    460   IN  UINT16                            SubInstance,
    461   IN  EFI_CACHE_TYPE_DATA*              CacheType)
    462 {
    463   EFI_STATUS                  Status;
    464   EFI_DATA_HUB_PROTOCOL       *DataHub;
    465   EFI_DATA_RECORD_HEADER      *Record;
    466   UINT64                      MonotonicCount;
    467   EFI_CACHE_VARIABLE_RECORD*  CacheVariableRecord;
    468   EFI_SUBCLASS_TYPE1_HEADER   *DataHeader;
    469 
    470   Status = gBS->LocateProtocol (
    471                   &gEfiDataHubProtocolGuid,
    472                   NULL,
    473                   (void **)&DataHub
    474                   );
    475   ASSERT_EFI_ERROR(Status);
    476 
    477   //
    478   // Get all available data records from data hub
    479   //
    480   MonotonicCount = 0;
    481   Record = NULL;
    482 
    483   do {
    484     Status = DataHub->GetNextRecord (
    485 	                    DataHub,
    486 						&MonotonicCount,
    487 						NULL,
    488 						&Record
    489 						);
    490     if (!EFI_ERROR(Status)) {
    491       if (Record->DataRecordClass == EFI_DATA_RECORD_CLASS_DATA) {
    492         DataHeader  = (EFI_SUBCLASS_TYPE1_HEADER *)(Record + 1);
    493 
    494         if(CompareGuid(&Record->DataRecordGuid, &gEfiCacheSubClassGuid) &&
    495           (DataHeader->RecordType == CacheTypeRecordType) &&
    496           (DataHeader->Instance == Instance) &&
    497           (DataHeader->SubInstance == SubInstance)) {
    498           CacheVariableRecord     = (EFI_CACHE_VARIABLE_RECORD  *)(DataHeader + 1);
    499           if(CacheType){
    500             *CacheType = CacheVariableRecord->CacheType;
    501             return EFI_SUCCESS;
    502           }
    503         }
    504       }
    505     }
    506   } while(!EFI_ERROR(Status) && (MonotonicCount != 0));
    507 
    508   return EFI_NOT_FOUND;
    509 }
    510 
    511 /**
    512   Setup data filter function. This function is invoked when there is data records
    513   available in the Data Hub.
    514 
    515 
    516   Standard event notification function arguments:
    517   @param Event          The event that is signaled.
    518   @param Context        Not used here.
    519 
    520   @retval EFI_STATUS
    521 
    522 **/
    523 VOID
    524 PrepareSetupInformation (
    525   )
    526 {
    527 
    528   EFI_STATUS                  Status;
    529   EFI_DATA_HUB_PROTOCOL       *DataHub;
    530   EFI_DATA_RECORD_HEADER      *Record;
    531   UINT8                       *SrcData;
    532   EFI_SUBCLASS_TYPE1_HEADER   *DataHeader;
    533   CHAR16                      *NewString;
    534   CHAR16                      *NewString2;
    535   CHAR16                      *NewStringToken;
    536   STRING_REF                  TokenToUpdate;
    537   EFI_PROCESSOR_VERSION_DATA  *ProcessorVersion;
    538   UINTN                       Index;
    539   UINTN                       DataOutput;
    540 
    541   EFI_PROCESSOR_MICROCODE_REVISION_DATA   *CpuUcodeRevisionData;
    542   EFI_MEMORY_ARRAY_START_ADDRESS          *MemoryArray;
    543   EFI_MEMORY_ARRAY_LINK                   *MemoryArrayLink;
    544   UINT64                      MonotonicCount;
    545 
    546   CHAR16                      Version[100];         //Assuming that strings are < 100 UCHAR
    547   CHAR16                      ReleaseDate[100];     //Assuming that strings are < 100 UCHAR
    548   CHAR16                      ReleaseTime[100];     //Assuming that strings are < 100 UCHAR
    549 
    550   NewString = AllocateZeroPool (0x100);
    551   NewString2 = AllocateZeroPool (0x100);
    552   SetMem(Version, sizeof(Version), 0);
    553   SetMem(ReleaseDate, sizeof(ReleaseDate), 0);
    554   SetMem(ReleaseTime, sizeof(ReleaseTime), 0);
    555 
    556   //
    557   // Get the Data Hub Protocol. Assume only one instance
    558   //
    559   Status = gBS->LocateProtocol (&gEfiDataHubProtocolGuid, NULL, (void **)&DataHub);
    560   ASSERT_EFI_ERROR(Status);
    561 
    562   //
    563   // Get all available data records from data hub
    564   //
    565   MonotonicCount = 0;
    566   Record = NULL;
    567 
    568   do {
    569     Status = DataHub->GetNextRecord (DataHub, &MonotonicCount, NULL, &Record);
    570     if (!EFI_ERROR(Status)) {
    571       if (Record->DataRecordClass == EFI_DATA_RECORD_CLASS_DATA) {
    572         DataHeader  = (EFI_SUBCLASS_TYPE1_HEADER *)(Record + 1);
    573         SrcData     = (UINT8  *)(DataHeader + 1);
    574 
    575         //
    576         // Processor
    577         //
    578         if (CompareGuid(&Record->DataRecordGuid, &gEfiProcessorSubClassGuid)) {
    579           CopyMem (&mProcessorProducerGuid, &Record->ProducerName, sizeof(EFI_GUID));
    580           switch (DataHeader->RecordType) {
    581             case ProcessorCoreFrequencyRecordType:
    582               CopyMem(&mProcessorFrequency, SrcData, sizeof(EFI_EXP_BASE10_DATA));
    583               Index = EfiValueToString (
    584 			            NewString,
    585 						ConvertBase10ToRaw ((EFI_EXP_BASE10_DATA *)SrcData)/1000000000,
    586 						PREFIX_ZERO,
    587 						0
    588 						);
    589               StrCat (NewString, L".");
    590               EfiValueToString (
    591 			    NewString + Index + 1,
    592 				((ConvertBase10ToRaw ((EFI_EXP_BASE10_DATA *)SrcData)%1000000000)/10000000),
    593 				PREFIX_ZERO,
    594 				0
    595 				);
    596               StrCat (NewString, L" GHz");
    597               TokenToUpdate = (STRING_REF)STR_PROCESSOR_SPEED_VALUE;
    598               HiiSetString(mHiiHandle, TokenToUpdate, NewString, NULL);
    599               break;
    600 
    601             case ProcessorVersionRecordType:
    602               ProcessorVersion = (EFI_PROCESSOR_VERSION_DATA *)SrcData;
    603               NewStringToken = HiiGetPackageString(&mProcessorProducerGuid, *ProcessorVersion, NULL);
    604               TokenToUpdate = (STRING_REF)STR_PROCESSOR_VERSION_VALUE;
    605               HiiSetString(mHiiHandle, TokenToUpdate, NewStringToken, NULL);
    606               break;
    607             case CpuUcodeRevisionDataRecordType:
    608               CpuUcodeRevisionData = (EFI_PROCESSOR_MICROCODE_REVISION_DATA *) SrcData;
    609               if (CpuUcodeRevisionData->ProcessorMicrocodeRevisionNumber != 0) {
    610                 EfiValueToHexStr (
    611 				  NewString,
    612                   CpuUcodeRevisionData->ProcessorMicrocodeRevisionNumber,
    613                   PREFIX_ZERO,
    614                   8
    615 				  );
    616                 TokenToUpdate = (STRING_REF)STR_PROCESSOR_MICROCODE_VALUE;
    617                 HiiSetString(mHiiHandle, TokenToUpdate, NewString, NULL);
    618               }
    619               break;
    620             default:
    621               break;
    622           }
    623 
    624         //
    625         // Cache
    626         //
    627         } else if (CompareGuid(&Record->DataRecordGuid, &gEfiCacheSubClassGuid) &&
    628                    (DataHeader->RecordType == CacheSizeRecordType)) {
    629           if (DataHeader->SubInstance == EFI_CACHE_L1) {
    630             EFI_CACHE_TYPE_DATA              CacheType;
    631             if (EFI_SUCCESS == GetCacheType(DataHeader->Instance, DataHeader->SubInstance,&CacheType)){
    632               if (CacheType == EfiCacheTypeData) {
    633                 TokenToUpdate = (STRING_REF)STR_PROCESSOR_L1_DATA_CACHE_VALUE;
    634               } else if (CacheType == EfiCacheTypeInstruction) {
    635                   TokenToUpdate = (STRING_REF)STR_PROCESSOR_L1_INSTR_CACHE_VALUE;
    636               } else {
    637                 continue;
    638               }
    639             } else {
    640               continue;
    641             }
    642           }
    643           else if (DataHeader->SubInstance == EFI_CACHE_L2) {
    644             TokenToUpdate = (STRING_REF)STR_PROCESSOR_L2_CACHE_VALUE;
    645           } else {
    646             continue;
    647           }
    648           if (ConvertBase2ToRaw((EFI_EXP_BASE2_DATA *)SrcData)) {
    649             DataOutput = ConvertBase2ToRaw((EFI_EXP_BASE2_DATA *)SrcData) >> 10;
    650             EfiValueToString (NewString, DataOutput, PREFIX_ZERO, 0);
    651 
    652             StrCat (NewString, L" KB");
    653             if (DataHeader->SubInstance == EFI_CACHE_L3) {
    654               HiiSetString(mHiiHandle, TokenToUpdate, NewString, NULL);
    655             } else if(DataHeader->SubInstance == EFI_CACHE_L2 && mPlatformCpuInfo.CpuPackage.CoresPerPhysicalPackage > 1){
    656 			  //
    657               // Show XxL2 string
    658 			  //
    659               EfiValueToString (
    660 			    NewString2,
    661                 mPlatformCpuInfo.CpuPackage.CoresPerPhysicalPackage,
    662                 PREFIX_ZERO,
    663                 0
    664 				);
    665               StrCat(NewString2, L"x ");
    666               StrCat(NewString2, NewString);
    667               HiiSetString(mHiiHandle, TokenToUpdate, NewString2, NULL);
    668             } else {
    669               HiiSetString(mHiiHandle, TokenToUpdate, NewString, NULL);
    670             }
    671           }
    672 
    673         //
    674         // Memory
    675         //
    676         } else if (CompareGuid(&Record->DataRecordGuid, &gEfiMemorySubClassGuid)) {
    677           switch (DataHeader->RecordType) {
    678             case EFI_MEMORY_ARRAY_LINK_RECORD_NUMBER:
    679               MemoryArrayLink = (EFI_MEMORY_ARRAY_LINK *)SrcData;
    680 
    681               if (MemoryArrayLink->MemorySpeed > 0) {
    682                 //
    683                 // Save the lowest speed memory module
    684                 //
    685                 if (MemoryArrayLink->MemorySpeed < mMemorySpeed) {
    686                   mMemorySpeed = MemoryArrayLink->MemorySpeed;
    687                 }
    688                 switch (DataHeader->SubInstance) {
    689                   case 1:
    690                     mMemorySpeedChannelASlot0 = MemoryArrayLink->MemorySpeed;
    691                     mMemorySizeChannelASlot0 = MemoryArrayLink->MemoryDeviceSize;
    692                     break;
    693                   case 2:
    694                     mMemorySpeedChannelASlot1 = MemoryArrayLink->MemorySpeed;
    695                     mMemorySizeChannelASlot1 = MemoryArrayLink->MemoryDeviceSize;
    696                     break;
    697                   case 3:
    698                     mMemorySpeedChannelBSlot0 = MemoryArrayLink->MemorySpeed;
    699                     mMemorySizeChannelBSlot0 = MemoryArrayLink->MemoryDeviceSize;
    700                     break;
    701                   case 4:
    702                     mMemorySpeedChannelBSlot1 = MemoryArrayLink->MemorySpeed;
    703                     mMemorySizeChannelBSlot1 = MemoryArrayLink->MemoryDeviceSize;
    704                     break;
    705                   case 5:
    706                     mMemorySpeedChannelCSlot0 = MemoryArrayLink->MemorySpeed;
    707                     mMemorySizeChannelCSlot0 = MemoryArrayLink->MemoryDeviceSize;
    708                     break;
    709                   case 6:
    710                     mMemorySpeedChannelCSlot1 = MemoryArrayLink->MemorySpeed;
    711                     mMemorySizeChannelCSlot1 = MemoryArrayLink->MemoryDeviceSize;
    712                     break;
    713                   default:
    714                     break;
    715                   }
    716               }
    717               break;
    718 
    719             case EFI_MEMORY_ARRAY_START_ADDRESS_RECORD_NUMBER:
    720               MemoryArray = (EFI_MEMORY_ARRAY_START_ADDRESS *)SrcData;
    721               if (MemoryArray->MemoryArrayEndAddress - MemoryArray->MemoryArrayStartAddress) {
    722               	DataOutput = (UINTN)RShiftU64((MemoryArray->MemoryArrayEndAddress - MemoryArray->MemoryArrayStartAddress + 1), 20);
    723               	EfiValueToString (NewString, DataOutput / 1024, PREFIX_ZERO, 0);
    724               	if(DataOutput % 1024) {
    725               	  StrCat (NewString, L".");
    726               	  DataOutput = ((DataOutput % 1024) * 1000) / 1024;
    727               	  while(!(DataOutput % 10))
    728               	    DataOutput = DataOutput / 10;
    729                   EfiValueToString (NewString2, DataOutput, PREFIX_ZERO, 0);
    730                   StrCat (NewString, NewString2);
    731                 }
    732                 StrCat (NewString, L" GB");
    733                 TokenToUpdate = (STRING_REF)STR_TOTAL_MEMORY_SIZE_VALUE;
    734                 HiiSetString(mHiiHandle, TokenToUpdate, NewString, NULL);
    735               }
    736               break;
    737 
    738             default:
    739               break;
    740           }
    741         }
    742       }
    743     }
    744   } while (!EFI_ERROR(Status) && (MonotonicCount != 0));
    745 
    746   Status = GetBiosVersionDateTime (
    747              Version,
    748 			 ReleaseDate,
    749 			 ReleaseTime
    750 			 );
    751 
    752   DEBUG ((EFI_D_ERROR, "GetBiosVersionDateTime :%s %s %s \n", Version, ReleaseDate, ReleaseTime));
    753   if (!EFI_ERROR (Status)) {
    754     UINTN         Length = 0;
    755     CHAR16        *BuildDateTime;
    756 
    757     Length = StrLen(ReleaseDate) + StrLen(ReleaseTime);
    758 
    759     BuildDateTime = AllocateZeroPool ((Length+2) * sizeof(CHAR16));
    760     StrCpy (BuildDateTime, ReleaseDate);
    761     StrCat (BuildDateTime, L" ");
    762     StrCat (BuildDateTime, ReleaseTime);
    763 
    764     TokenToUpdate = (STRING_REF)STR_BIOS_VERSION_VALUE;
    765     DEBUG ((EFI_D_ERROR, "update STR_BIOS_VERSION_VALUE\n"));
    766     HiiSetString(mHiiHandle, TokenToUpdate, Version, NULL);
    767 
    768     TokenToUpdate = (STRING_REF)STR_BIOS_BUILD_TIME_VALUE;
    769     DEBUG ((EFI_D_ERROR, "update STR_BIOS_BUILD_TIME_VALUE\n"));
    770     HiiSetString(mHiiHandle, TokenToUpdate, BuildDateTime, NULL);
    771   }
    772 
    773   //
    774   // Calculate and update memory speed display in Main Page
    775   //
    776   //
    777   // Update the overall memory speed
    778   //
    779   if (mMemorySpeed != 0xffff) {
    780     EfiValueToString (NewString, mMemorySpeed, PREFIX_ZERO, 0);
    781     StrCat (NewString, L" MHz");
    782 
    783     TokenToUpdate = (STRING_REF)STR_SYSTEM_MEMORY_SPEED_VALUE;
    784     HiiSetString(mHiiHandle, TokenToUpdate, NewString, NULL);
    785   }
    786 
    787   gBS->FreePool(NewString);
    788   gBS->FreePool(NewString2);
    789 
    790   return;
    791 }
    792 
    793 /**
    794 
    795   Routine Description: update the SETUP info for "Additional Information" which is SMBIOS info.
    796 
    797   @retval EFI_STATUS
    798 
    799 **/
    800 EFI_STATUS
    801 UpdateAdditionalInformation (
    802   )
    803 {
    804   EFI_STATUS                      Status;
    805   UINT64                          MonotonicCount;
    806   EFI_DATA_HUB_PROTOCOL           *DataHub;
    807   EFI_DATA_RECORD_HEADER          *Record;
    808   EFI_SUBCLASS_TYPE1_HEADER       *DataHeader;
    809   EFI_SMBIOS_PROTOCOL             *Smbios;
    810   EFI_SMBIOS_HANDLE               SmbiosHandle;
    811   EFI_SMBIOS_TABLE_HEADER         *SmbiosRecord;
    812   SMBIOS_TABLE_TYPE0              *Type0Record;
    813   UINT8                           StrIndex;
    814   CHAR16                          *BiosVersion = NULL;
    815   CHAR16                          *IfwiVersion = NULL;
    816   UINT16                          SearchIndex;
    817   EFI_STRING_ID                   TokenToUpdate;
    818 #if defined( RVP_SUPPORT ) && RVP_SUPPORT
    819   EFI_MISC_SYSTEM_MANUFACTURER    *SystemManufacturer;
    820 #endif
    821 
    822   Status = gBS->LocateProtocol (
    823                   &gEfiDataHubProtocolGuid,
    824                   NULL,
    825                   (void **)&DataHub
    826                   );
    827 
    828   ASSERT_EFI_ERROR(Status);
    829 
    830   MonotonicCount  = 0;
    831   Record = NULL;
    832   do {
    833     Status = DataHub->GetNextRecord (
    834                         DataHub,
    835                         &MonotonicCount,
    836                         NULL,
    837                         &Record
    838                         );
    839     if (Record->DataRecordClass == EFI_DATA_RECORD_CLASS_DATA) {
    840       DataHeader  = (EFI_SUBCLASS_TYPE1_HEADER *)(Record + 1);
    841 
    842       if (CompareGuid(&Record->DataRecordGuid, &gEfiMiscSubClassGuid) &&
    843           (DataHeader->RecordType == EFI_MISC_SYSTEM_MANUFACTURER_RECORD_NUMBER)) {
    844 #if defined( RVP_SUPPORT ) && RVP_SUPPORT
    845         //
    846         // System Information
    847         //
    848         SystemManufacturer = (EFI_MISC_SYSTEM_MANUFACTURER *)(DataHeader + 1);
    849 
    850         //
    851         // UUID  (System Information)
    852         //
    853         SMBIOSString = EfiLibAllocateZeroPool (0x100);
    854         GuidToString ( &SystemManufacturer->SystemUuid, SMBIOSString, 0x00 );
    855 
    856         TokenToUpdate = (STRING_REF)STR_SYSTEM_UUID_VALUE;
    857         HiiSetString(mHiiHandle, TokenToUpdate, SMBIOSString, NULL);
    858 
    859         gBS->FreePool(SMBIOSString);
    860 #endif
    861       }
    862     }
    863   } while (!EFI_ERROR(Status) && (MonotonicCount != 0));
    864 
    865   Status = gBS->LocateProtocol (
    866                   &gEfiSmbiosProtocolGuid,
    867                   NULL,
    868                   (VOID **) &Smbios
    869                   );
    870   ASSERT_EFI_ERROR (Status);
    871 
    872   SmbiosHandle = SMBIOS_HANDLE_PI_RESERVED;
    873   do {
    874     Status = Smbios->GetNext (
    875                        Smbios,
    876                        &SmbiosHandle,
    877                        NULL,
    878                        &SmbiosRecord,
    879                        NULL
    880                        );
    881     if (SmbiosRecord->Type == EFI_SMBIOS_TYPE_BIOS_INFORMATION) {
    882       Type0Record = (SMBIOS_TABLE_TYPE0 *) SmbiosRecord;
    883       StrIndex = Type0Record->BiosVersion;
    884       GetOptionalStringByIndex ((CHAR8*)((UINT8*)Type0Record + Type0Record->Hdr.Length), StrIndex, &BiosVersion);
    885       TokenToUpdate = STRING_TOKEN (STR_BIOS_VERSION_VALUE);
    886       for (SearchIndex = 0x0; SearchIndex < SMBIOS_STRING_MAX_LENGTH; SearchIndex++) {
    887         if (BiosVersion[SearchIndex] == 0x0020) {
    888           BiosVersion[SearchIndex] = 0x0000;
    889           IfwiVersion = (CHAR16 *)(&BiosVersion[SearchIndex+1]);
    890           break;
    891         } else if (BiosVersion[SearchIndex] == 0x0000) {
    892           break;
    893         }
    894       }
    895       HiiSetString (mHiiHandle, TokenToUpdate, BiosVersion, NULL);
    896 
    897       //
    898       // Check IfwiVersion, to avoid no IFWI version in SMBIOS Type 0 strucntion
    899       //
    900       if(IfwiVersion) {
    901         TokenToUpdate = STRING_TOKEN (STR_IFWI_VERSION_VALUE);
    902         HiiSetString (mHiiHandle, TokenToUpdate, IfwiVersion, NULL);
    903       }
    904     }
    905   } while (!EFI_ERROR(Status));
    906 
    907   UpdateLatestBootTime();
    908 
    909   return  EFI_SUCCESS;
    910 }
    911 
    912 VOID
    913 UpdateCPUInformation ()
    914 {
    915   CHAR16								Buffer[40];
    916   UINT16                                FamilyId;
    917   UINT8                                 Model;
    918   UINT8                                 SteppingId;
    919   UINT8                                 ProcessorType;
    920   EFI_STATUS                            Status;
    921   EFI_MP_SERVICES_PROTOCOL              *MpService;
    922   UINTN                                 MaximumNumberOfCPUs;
    923   UINTN                                 NumberOfEnabledCPUs;
    924   UINT32								Buffer32 = 0xFFFFFFFF;   // Keep buffer with unknown device
    925 
    926   EfiCpuVersion (&FamilyId, &Model, &SteppingId, &ProcessorType);
    927 
    928   //
    929   //we need raw Model data
    930   //
    931   Model = Model & 0xf;
    932 
    933   //
    934   //Family/Model/Step
    935   //
    936   UnicodeSPrint (Buffer, sizeof (Buffer), L"%d/%d/%d", FamilyId,  Model, SteppingId);
    937   HiiSetString(mHiiHandle,STRING_TOKEN(STR_PROCESSOR_ID_VALUE), Buffer, NULL);
    938 
    939   Status = gBS->LocateProtocol (
    940                   &gEfiMpServiceProtocolGuid,
    941                   NULL,
    942                   (void **)&MpService
    943                   );
    944   if (!EFI_ERROR (Status)) {
    945     //
    946     // Determine the number of processors
    947     //
    948     MpService->GetNumberOfProcessors (
    949                  MpService,
    950                  &MaximumNumberOfCPUs,
    951                  &NumberOfEnabledCPUs
    952                  );
    953     UnicodeSPrint (Buffer, sizeof (Buffer), L"%d", MaximumNumberOfCPUs);
    954     HiiSetString(mHiiHandle,STRING_TOKEN(STR_PROCESSOR_CORE_VALUE), Buffer, NULL);
    955   }
    956   //
    957   // Update Mobile / Desktop / Tablet SKU
    958   //
    959   Buffer32 =(UINT32) RShiftU64 (EfiReadMsr (MSR_IA32_PLATFORM_ID), 50) & 0x07;
    960 
    961   switch(Buffer32){
    962       case 0x0:
    963         UnicodeSPrint (Buffer, sizeof (Buffer), L"(%d) - ISG SKU SOC", Buffer32);
    964         break;
    965       case 0x01:
    966         UnicodeSPrint (Buffer, sizeof (Buffer), L"(%d) - Mobile SKU SOC", Buffer32);
    967         break;
    968       case 0x02:
    969         UnicodeSPrint (Buffer, sizeof (Buffer), L"(%d) - Desktop SKU SOC", Buffer32);
    970         break;
    971       case 0x03:
    972         UnicodeSPrint (Buffer, sizeof (Buffer), L"(%d) - Mobile SKU SOC", Buffer32);
    973         break;
    974       default:
    975         UnicodeSPrint (Buffer, sizeof (Buffer), L"(%d) - Unknown SKU SOC", Buffer32);
    976         break;
    977     }
    978   HiiSetString(mHiiHandle,STRING_TOKEN(STR_PROCESSOR_SKU_VALUE), Buffer, NULL);
    979 
    980 }
    981 
    982 
    983 EFI_STATUS
    984 SearchChildHandle(
    985   EFI_HANDLE Father,
    986   EFI_HANDLE *Child
    987   )
    988 {
    989   EFI_STATUS                                                 Status;
    990   UINTN                                                          HandleIndex;
    991   EFI_GUID                                                     **ProtocolGuidArray = NULL;
    992   UINTN                                                          ArrayCount;
    993   UINTN                                                          ProtocolIndex;
    994   UINTN                                                          OpenInfoCount;
    995   UINTN                                                          OpenInfoIndex;
    996   EFI_OPEN_PROTOCOL_INFORMATION_ENTRY  *OpenInfo = NULL;
    997   UINTN                                                          mHandleCount;
    998   EFI_HANDLE                                                 *mHandleBuffer= NULL;
    999 
   1000   //
   1001   // Retrieve the list of all handles from the handle database
   1002   //
   1003   Status = gBS->LocateHandleBuffer (
   1004                   AllHandles,
   1005                   NULL,
   1006                   NULL,
   1007                   &mHandleCount,
   1008                   &mHandleBuffer
   1009                   );
   1010 
   1011   for (HandleIndex = 0; HandleIndex < mHandleCount; HandleIndex++)
   1012   {
   1013     //
   1014     // Retrieve the list of all the protocols on each handle
   1015     //
   1016     Status = gBS->ProtocolsPerHandle (
   1017                     mHandleBuffer[HandleIndex],
   1018                     &ProtocolGuidArray,
   1019                     &ArrayCount
   1020                     );
   1021     if (!EFI_ERROR (Status))
   1022     {
   1023       for (ProtocolIndex = 0; ProtocolIndex < ArrayCount; ProtocolIndex++)
   1024       {
   1025         Status = gBS->OpenProtocolInformation (
   1026                         mHandleBuffer[HandleIndex],
   1027                         ProtocolGuidArray[ProtocolIndex],
   1028                         &OpenInfo,
   1029                         &OpenInfoCount
   1030                         );
   1031         if (!EFI_ERROR (Status))
   1032         {
   1033           for (OpenInfoIndex = 0; OpenInfoIndex < OpenInfoCount; OpenInfoIndex++)
   1034           {
   1035             if(OpenInfo[OpenInfoIndex].AgentHandle == Father)
   1036             {
   1037               if ((OpenInfo[OpenInfoIndex].Attributes & EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER) == EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER)
   1038               {
   1039                 *Child = mHandleBuffer[HandleIndex];
   1040 		  Status = EFI_SUCCESS;
   1041 		  goto TryReturn;
   1042               }
   1043             }
   1044           }
   1045 	   Status = EFI_NOT_FOUND;
   1046         }
   1047       }
   1048       if(OpenInfo != NULL)
   1049       {
   1050         FreePool(OpenInfo);
   1051 	 OpenInfo = NULL;
   1052       }
   1053     }
   1054     FreePool (ProtocolGuidArray);
   1055     ProtocolGuidArray = NULL;
   1056   }
   1057 TryReturn:
   1058   if(OpenInfo != NULL)
   1059   {
   1060     FreePool (OpenInfo);
   1061     OpenInfo = NULL;
   1062   }
   1063   if(ProtocolGuidArray != NULL)
   1064   {
   1065     FreePool(ProtocolGuidArray);
   1066     ProtocolGuidArray = NULL;
   1067   }
   1068   if(mHandleBuffer != NULL)
   1069   {
   1070     FreePool (mHandleBuffer);
   1071     mHandleBuffer = NULL;
   1072   }
   1073   return Status;
   1074 }
   1075 
   1076 EFI_STATUS
   1077 JudgeHandleIsPCIDevice(
   1078   EFI_HANDLE    Handle,
   1079   UINT8            Device,
   1080   UINT8            Funs
   1081   )
   1082 {
   1083   EFI_STATUS  Status;
   1084   EFI_DEVICE_PATH   *DPath;
   1085 
   1086   Status = gBS->HandleProtocol (
   1087                   Handle,
   1088                   &gEfiDevicePathProtocolGuid,
   1089                   (VOID **) &DPath
   1090                   );
   1091   if(!EFI_ERROR(Status))
   1092   {
   1093     while(!IsDevicePathEnd(DPath))
   1094     {
   1095       if((DPath->Type == HARDWARE_DEVICE_PATH) && (DPath->SubType == HW_PCI_DP))
   1096       {
   1097         PCI_DEVICE_PATH   *PCIPath;
   1098 
   1099         PCIPath = (PCI_DEVICE_PATH*) DPath;
   1100         DPath = NextDevicePathNode(DPath);
   1101         if(IsDevicePathEnd(DPath) && (PCIPath->Device == Device) && (PCIPath->Function == Funs))
   1102         {
   1103           return EFI_SUCCESS;
   1104         }
   1105       }
   1106       else
   1107       {
   1108         DPath = NextDevicePathNode(DPath);
   1109       }
   1110     }
   1111   }
   1112   return EFI_UNSUPPORTED;
   1113 }
   1114 
   1115 EFI_STATUS
   1116 GetDriverName(
   1117   EFI_HANDLE   Handle,
   1118   CHAR16         *Name
   1119   )
   1120 {
   1121   EFI_DRIVER_BINDING_PROTOCOL        *BindHandle = NULL;
   1122   EFI_STATUS                                        Status;
   1123   UINT32                                               Version;
   1124   UINT16                                               *Ptr;
   1125   Status = gBS->OpenProtocol(
   1126                   Handle,
   1127                   &gEfiDriverBindingProtocolGuid,
   1128                   (VOID**)&BindHandle,
   1129                   NULL,
   1130                   NULL,
   1131                   EFI_OPEN_PROTOCOL_GET_PROTOCOL
   1132                   );
   1133 
   1134   if (EFI_ERROR(Status))
   1135   {
   1136     return EFI_NOT_FOUND;
   1137   }
   1138 
   1139   Version = BindHandle->Version;
   1140   Ptr = (UINT16*)&Version;
   1141   UnicodeSPrint(Name, 40, L"%d.%d.%d", Version >> 24 , (Version >>16)& 0x0f ,*(Ptr));
   1142 
   1143   return EFI_SUCCESS;
   1144 }
   1145 
   1146 EFI_STATUS
   1147 GetGOPDriverName(
   1148   CHAR16 *Name
   1149   )
   1150 {
   1151   UINTN                         HandleCount;
   1152   EFI_HANDLE                *Handles= NULL;
   1153   UINTN                         Index;
   1154   EFI_STATUS                Status;
   1155   EFI_HANDLE                Child = 0;
   1156 
   1157   Status = gBS->LocateHandleBuffer(
   1158 		              ByProtocol,
   1159 		              &gEfiDriverBindingProtocolGuid,
   1160 		              NULL,
   1161 		              &HandleCount,
   1162 		              &Handles
   1163                   );
   1164   for (Index = 0; Index < HandleCount ; Index++)
   1165   {
   1166     Status = SearchChildHandle(Handles[Index], &Child);
   1167     if(!EFI_ERROR(Status))
   1168     {
   1169       Status = JudgeHandleIsPCIDevice(
   1170                  Child,
   1171                  0x02,
   1172                  0x00
   1173                  );
   1174       if(!EFI_ERROR(Status))
   1175       {
   1176         return GetDriverName(Handles[Index], Name);
   1177       }
   1178     }
   1179   }
   1180   return EFI_UNSUPPORTED;
   1181 }
   1182 
   1183 EFI_STATUS
   1184 UpdatePlatformInformation (
   1185   )
   1186 {
   1187   UINT32                   MicroCodeVersion;
   1188   CHAR16                   Buffer[40];
   1189   UINT8                    IgdVBIOSRevH;
   1190   UINT8                    IgdVBIOSRevL;
   1191   UINT16                   EDX;
   1192   EFI_IA32_REGISTER_SET    RegSet;
   1193   EFI_LEGACY_BIOS_PROTOCOL *LegacyBios = NULL;
   1194   EFI_STATUS               Status;
   1195   UINT8                    CpuFlavor=0;
   1196   EFI_PEI_HOB_POINTERS     GuidHob;
   1197   EFI_PLATFORM_INFO_HOB    *mPlatformInfo=NULL;
   1198   UINTN                    NumHandles;
   1199   EFI_HANDLE                        *HandleBuffer;
   1200   UINTN                             Index;
   1201   DXE_PCH_PLATFORM_POLICY_PROTOCOL  *PchPlatformPolicy;
   1202   UINTN                             PciD31F0RegBase;
   1203   UINT8                             count;
   1204   UINT8                             Data8;
   1205   UINT8                             PIDData8;
   1206 
   1207   CHAR16                            Name[40];
   1208   UINT32                            MrcVersion;
   1209 
   1210   //
   1211   // Get the HOB list.  If it is not present, then ASSERT.
   1212   //
   1213   GuidHob.Raw = GetHobList ();
   1214   if (GuidHob.Raw != NULL) {
   1215     if ((GuidHob.Raw = GetNextGuidHob (&gEfiPlatformInfoGuid, GuidHob.Raw)) != NULL) {
   1216       mPlatformInfo = GET_GUID_HOB_DATA (GuidHob.Guid);
   1217     }
   1218   }
   1219 
   1220   //
   1221   //VBIOS version
   1222   //
   1223   Status = gBS->LocateProtocol(
   1224                   &gEfiLegacyBiosProtocolGuid,
   1225                   NULL,
   1226                   (void **)&LegacyBios
   1227                   );
   1228   if (!EFI_ERROR (Status)) {
   1229   RegSet.X.AX = 0x5f01;
   1230   Status = LegacyBios->Int86 (LegacyBios, 0x10, &RegSet);
   1231   ASSERT_EFI_ERROR(Status);
   1232 
   1233   //
   1234   // simulate AMI int15 (ax=5f01) handler
   1235   // check NbInt15.asm in AMI code for asm edition
   1236   //
   1237   EDX = (UINT16)((RegSet.E.EBX >> 16) & 0xffff);
   1238   IgdVBIOSRevH = (UINT8)(((EDX & 0x0F00) >> 4) | (EDX & 0x000F));
   1239   IgdVBIOSRevL = (UINT8)(((RegSet.X.BX & 0x0F00) >> 4) | (RegSet.X.BX & 0x000F));
   1240 
   1241   if (IgdVBIOSRevH==0 && IgdVBIOSRevL==0){
   1242     HiiSetString(mHiiHandle, STRING_TOKEN(STR_CHIP_IGD_VBIOS_REV_VALUE), L"N/A", NULL);
   1243   } else {
   1244     UnicodeSPrint (Buffer, sizeof (Buffer), L"%02X%02X", IgdVBIOSRevH,IgdVBIOSRevL);
   1245     HiiSetString(mHiiHandle, STRING_TOKEN(STR_CHIP_IGD_VBIOS_REV_VALUE), Buffer, NULL);
   1246     }
   1247   }
   1248 
   1249   Status = GetGOPDriverName(Name);
   1250 
   1251   if (!EFI_ERROR(Status))
   1252   {
   1253     HiiSetString(mHiiHandle, STRING_TOKEN(STR_GOP_VALUE), Name, NULL);
   1254   }
   1255 
   1256 
   1257   //
   1258   // CpuFlavor
   1259   // ISG-DC Tablet        000
   1260   // VLV-QC Tablet        001
   1261   // VLV-QC Desktop       010
   1262   // VLV-QC Notebook      011
   1263   //
   1264   CpuFlavor = RShiftU64 (EfiReadMsr (MSR_IA32_PLATFORM_ID), 50) & 0x07;
   1265 
   1266   switch(CpuFlavor){
   1267     case 0x0:
   1268       UnicodeSPrint (Buffer, sizeof (Buffer), L"%s (%01x)", L"VLV-DC Tablet", CpuFlavor);
   1269       break;
   1270     case 0x01:
   1271       UnicodeSPrint (Buffer, sizeof (Buffer), L"%s (%01x)", L"VLV-QC Notebook", CpuFlavor);
   1272       break;
   1273     case 0x02:
   1274       UnicodeSPrint (Buffer, sizeof (Buffer), L"%s (%01x)", L"VLV-QC Desktop", CpuFlavor);
   1275       break;
   1276     case 0x03:
   1277       UnicodeSPrint (Buffer, sizeof (Buffer), L"%s (%01x)", L"VLV-QC Notebook", CpuFlavor);
   1278       break;
   1279     default:
   1280       UnicodeSPrint (Buffer, sizeof (Buffer), L"%s (%01x)", L"Unknown CPU", CpuFlavor);
   1281       break;
   1282   }
   1283   HiiSetString(mHiiHandle,STRING_TOKEN(STR_CPU_FLAVOR_VALUE), Buffer, NULL);
   1284 
   1285   if ( NULL != mPlatformInfo) {
   1286     //
   1287     //BoardId
   1288     //
   1289     switch(mPlatformInfo->BoardId){
   1290       case 0x2:
   1291         UnicodeSPrint (Buffer, sizeof (Buffer), L"BAY LAKE RVP(%02x)", mPlatformInfo->BoardId);
   1292         break;
   1293 
   1294       case 0x4:
   1295         UnicodeSPrint (Buffer, sizeof (Buffer), L"BAY LAKE FFRD(%02x)", mPlatformInfo->BoardId);
   1296         break;
   1297 
   1298       case 0x5:
   1299         UnicodeSPrint (Buffer, sizeof (Buffer), L"BAY ROCK RVP DDR3L (%02x)", mPlatformInfo->BoardId);
   1300         break;
   1301 
   1302       case 0x20:
   1303         UnicodeSPrint (Buffer, sizeof (Buffer), L"BAYLEY BAY (%02x)", mPlatformInfo->BoardId);
   1304         break;
   1305 
   1306       case 0x30:
   1307         UnicodeSPrint (Buffer, sizeof (Buffer), L"BAKER SPORT (%02x)", mPlatformInfo->BoardId);
   1308         break;
   1309 
   1310       case 0x0:
   1311         UnicodeSPrint (Buffer, sizeof (Buffer), L"ALPINE VALLEY (%x)", mPlatformInfo->BoardId);
   1312         break;
   1313 
   1314       case 0x3:
   1315         UnicodeSPrint (Buffer, sizeof (Buffer), L"BAY LAKE FFD8 (%x)", mPlatformInfo->BoardId);
   1316         break;
   1317 
   1318       default:
   1319         UnicodeSPrint (Buffer, sizeof (Buffer), L"Unknown BOARD (%02x)", mPlatformInfo->BoardId);
   1320         break;
   1321     }
   1322     HiiSetString(mHiiHandle,STRING_TOKEN(STR_BOARD_ID_VALUE), Buffer, NULL);
   1323 
   1324 
   1325     //
   1326     // Get Board FAB ID Info from protocol, update into the NVS area.
   1327     // bit0~bit3 are for Fab ID, 0x0F means unknow FAB.
   1328     //
   1329     if(mPlatformInfo->BoardRev == 0x0F) {
   1330       UnicodeSPrint (Buffer, sizeof (Buffer), L"%s", L"Unknown FAB");
   1331       HiiSetString(mHiiHandle,STRING_TOKEN(STR_FAB_ID_VALUE), Buffer, NULL);
   1332     } else {
   1333       UnicodeSPrint (Buffer, sizeof (Buffer), L"%2x", mPlatformInfo->BoardRev);
   1334       HiiSetString(mHiiHandle,STRING_TOKEN(STR_FAB_ID_VALUE), Buffer, NULL);
   1335     }
   1336   }
   1337 
   1338   //
   1339   //Update MRC Version
   1340   //
   1341   MrcVersion = 0x00000000;
   1342   MrcVersion &= 0xffff;
   1343   Index = EfiValueToString (Buffer, MrcVersion/100, PREFIX_ZERO, 0);
   1344   StrCat (Buffer, L".");
   1345   EfiValueToString (Buffer + Index + 1, (MrcVersion%100)/10, PREFIX_ZERO, 0);
   1346   EfiValueToString (Buffer + Index + 2, (MrcVersion%100)%10, PREFIX_ZERO, 0);
   1347   HiiSetString(mHiiHandle,STRING_TOKEN(STR_MRC_VERSION_VALUE), Buffer, NULL);
   1348 
   1349   //
   1350   //Update Soc Version
   1351   //
   1352 
   1353   //
   1354   // Retrieve all instances of PCH Platform Policy protocol
   1355   //
   1356   Status = gBS->LocateHandleBuffer (
   1357                   ByProtocol,
   1358                   &gDxePchPlatformPolicyProtocolGuid,
   1359                   NULL,
   1360                   &NumHandles,
   1361                   &HandleBuffer
   1362                   );
   1363   if (!EFI_ERROR (Status)) {
   1364     //
   1365     // Find the matching PCH Policy protocol
   1366     //
   1367     for (Index = 0; Index < NumHandles; Index++) {
   1368       Status = gBS->HandleProtocol (
   1369                       HandleBuffer[Index],
   1370                       &gDxePchPlatformPolicyProtocolGuid,
   1371                       (void **)&PchPlatformPolicy
   1372                       );
   1373       if (!EFI_ERROR (Status)) {
   1374         PciD31F0RegBase = MmPciAddress (
   1375                             0,
   1376                             PchPlatformPolicy->BusNumber,
   1377                             PCI_DEVICE_NUMBER_PCH_LPC,
   1378                             PCI_FUNCTION_NUMBER_PCH_LPC,
   1379                             0
   1380                             );
   1381 
   1382          Data8 = MmioRead8 (PciD31F0RegBase + R_PCH_LPC_RID_CC);
   1383          count = ARRAY_SIZE (SBRevisionTable);
   1384          for (Index = 0; Index < count; Index++) {
   1385            if(Data8 == SBRevisionTable[Index].RevId) {
   1386               UnicodeSPrint (Buffer, sizeof (Buffer), L"%02x %a", Data8, SBRevisionTable[Index].String);
   1387               HiiSetString(mHiiHandle,STRING_TOKEN(STR_SOC_VALUE), Buffer, NULL);
   1388              break;
   1389            }
   1390          }
   1391         break;
   1392       }
   1393     }
   1394   }
   1395 
   1396   //
   1397   // Microcode Revision
   1398   //
   1399   EfiWriteMsr (EFI_MSR_IA32_BIOS_SIGN_ID, 0);
   1400   EfiCpuid (EFI_CPUID_VERSION_INFO, NULL);
   1401   MicroCodeVersion = (UINT32) RShiftU64 (EfiReadMsr (EFI_MSR_IA32_BIOS_SIGN_ID), 32);
   1402   UnicodeSPrint (Buffer, sizeof (Buffer), L"%x", MicroCodeVersion);
   1403   HiiSetString(mHiiHandle,STRING_TOKEN(STR_PROCESSOR_MICROCODE_VALUE), Buffer, NULL);
   1404 
   1405   //
   1406   // Punit Version
   1407   //
   1408   Data8 = 0;
   1409   UnicodeSPrint (Buffer, sizeof (Buffer), L"0x%x", Data8);
   1410   HiiSetString(mHiiHandle,STRING_TOKEN(STR_PUNIT_FW_VALUE), Buffer, NULL);
   1411 
   1412   //
   1413   //  PMC Version
   1414   //
   1415   Data8 = (UINT8)((MmioRead32 (PMC_BASE_ADDRESS + R_PCH_PMC_PRSTS)>>16)&0x00FF);
   1416   PIDData8 = (UINT8)((MmioRead32 (PMC_BASE_ADDRESS + R_PCH_PMC_PRSTS)>>24)&0x00FF);
   1417   UnicodeSPrint (Buffer, sizeof (Buffer), L"0x%X_%X",PIDData8, Data8);
   1418   HiiSetString(mHiiHandle,STRING_TOKEN(STR_PMC_FW_VALUE), Buffer, NULL);
   1419 
   1420   return EFI_SUCCESS;
   1421 }
   1422 
   1423 /**
   1424 
   1425   Update SATA Drivesize Strings for Setup and Boot order
   1426 
   1427   @param NewString - pointer to string.
   1428   @param DeviceSpeed - speed of drive.
   1429 
   1430 **/
   1431 VOID
   1432 GetDeviceSpeedString (
   1433   CHAR16                      *NewString,
   1434   IN UINTN                    DeviceSpeed
   1435   )
   1436 {
   1437   if (DeviceSpeed == 0x01) {
   1438     StrCat (NewString, L"1.5Gb/s");
   1439   } else if (DeviceSpeed == 0x02) {
   1440     StrCat (NewString, L"3.0Gb/s");
   1441   } else if (DeviceSpeed == 0x03) {
   1442     StrCat (NewString, L"6.0Gb/s");
   1443   } else if (DeviceSpeed == 0x0) {
   1444 
   1445   }
   1446 }
   1447 
   1448 UINT8
   1449 GetChipsetSataPortSpeed (
   1450   UINTN PortNum
   1451   )
   1452 {
   1453   UINT32                      DeviceSpeed;
   1454   UINT8                       DeviceConfigStatus;
   1455   UINT32                      IdeAhciBar;
   1456   EFI_PHYSICAL_ADDRESS        MemBaseAddress = 0;
   1457   UINT8                       FunNum;
   1458 
   1459   DeviceSpeed = 0x01; // generation 1
   1460 
   1461 
   1462   //
   1463   // Allocate the AHCI BAR
   1464   //
   1465     FunNum = PCI_FUNCTION_NUMBER_PCH_SATA;
   1466     MemBaseAddress = 0x0ffffffff;
   1467     gDS->AllocateMemorySpace (
   1468            EfiGcdAllocateMaxAddressSearchBottomUp,
   1469            EfiGcdMemoryTypeMemoryMappedIo,
   1470            N_PCH_SATA_ABAR_ALIGNMENT,  // 2^11: 2K Alignment
   1471            V_PCH_SATA_ABAR_LENGTH,     // 2K Length
   1472            &MemBaseAddress,
   1473            mImageHandle,
   1474            NULL
   1475            );
   1476     IdeAhciBar = MmioRead32 (
   1477                    MmPciAddress (
   1478 				     0,
   1479                      0,
   1480                      PCI_DEVICE_NUMBER_PCH_SATA,
   1481                      FunNum,
   1482                      R_PCH_SATA_ABAR
   1483                      )
   1484                    );
   1485     IdeAhciBar &= 0xFFFFF800;
   1486     DeviceConfigStatus = 0;
   1487     if (IdeAhciBar == 0) {
   1488       DeviceConfigStatus = 1;
   1489       IdeAhciBar = (UINT32)MemBaseAddress;
   1490       MmioWrite32 (
   1491         MmPciAddress (0, 0, PCI_DEVICE_NUMBER_PCH_SATA, FunNum, R_PCH_SATA_ABAR),
   1492         IdeAhciBar
   1493         );
   1494       MmioOr16 (
   1495         MmPciAddress (0, 0, PCI_DEVICE_NUMBER_PCH_SATA, FunNum, R_PCH_SATA_COMMAND),
   1496         B_PCH_SATA_COMMAND_MSE
   1497         );
   1498     }
   1499 
   1500     if (mSystemConfiguration.SataType == PCH_SATA_MODE_IDE){
   1501       //
   1502       // Program the "Ports Implemented Register"
   1503       //
   1504       MmioAndThenOr32 (IdeAhciBar + R_PCH_SATA_AHCI_PI, (UINT32)~(B_PCH_SATA_PORT0_IMPLEMENTED + B_PCH_SATA_PORT1_IMPLEMENTED), (UINT32)(B_PCH_SATA_PORT0_IMPLEMENTED + B_PCH_SATA_PORT1_IMPLEMENTED));
   1505     }
   1506 
   1507     switch (PortNum)
   1508     {
   1509       case 0:
   1510         DeviceSpeed = *(volatile UINT32 *)(UINTN)(IdeAhciBar + R_PCH_SATA_AHCI_P0SSTS);
   1511         break;
   1512       case 1:
   1513         DeviceSpeed = *(volatile UINT32 *)(UINTN)(IdeAhciBar + R_PCH_SATA_AHCI_P1SSTS);
   1514         break;
   1515     }
   1516 
   1517     if (MemBaseAddress) {
   1518       gDS->FreeMemorySpace (
   1519              MemBaseAddress,
   1520              V_PCH_SATA_ABAR_LENGTH
   1521              );
   1522     }
   1523 
   1524   if (DeviceConfigStatus) {
   1525     IdeAhciBar = 0;
   1526     MmioWrite32 (
   1527       MmPciAddress (0, 0, PCI_DEVICE_NUMBER_PCH_SATA, FunNum, R_PCH_SATA_ABAR),
   1528       IdeAhciBar
   1529       );
   1530   }
   1531 
   1532   DeviceSpeed = (UINT8)((DeviceSpeed >> 4) & 0x0F);
   1533 
   1534   return (UINT8)DeviceSpeed;
   1535 }
   1536 
   1537 /**
   1538 
   1539   IDE data filter function.
   1540 
   1541 **/
   1542 void
   1543 IdeDataFilter (void)
   1544 {
   1545   EFI_STATUS                  Status;
   1546   UINTN                       HandleCount;
   1547   EFI_HANDLE                  *HandleBuffer;
   1548   EFI_DISK_INFO_PROTOCOL      *DiskInfo;
   1549   EFI_DEVICE_PATH_PROTOCOL    *DevicePath, *DevicePathNode;
   1550   PCI_DEVICE_PATH             *PciDevicePath;
   1551   UINTN                       Index;
   1552   UINT8                       Index1;
   1553   UINT32                      BufferSize;
   1554   UINT32                      DriveSize;
   1555   UINT32                      IdeChannel;
   1556   UINT32                      IdeDevice;
   1557   EFI_ATA_IDENTIFY_DATA       *IdentifyDriveInfo;
   1558   CHAR16                      *NewString;
   1559   CHAR16                      SizeString[20];
   1560   STRING_REF                  NameToUpdate;
   1561   CHAR8                       StringBuffer[0x100];
   1562   UINT32                      DeviceSpeed;
   1563   UINTN                       PortNumber;
   1564 
   1565   //
   1566   // Assume no line strings is longer than 256 bytes.
   1567   //
   1568   NewString = AllocateZeroPool (0x100);
   1569   PciDevicePath = NULL;
   1570 
   1571   //
   1572   // Fill IDE Infomation
   1573   //
   1574   Status = gBS->LocateHandleBuffer (
   1575                   ByProtocol,
   1576                   &gEfiDiskInfoProtocolGuid,
   1577                   NULL,
   1578                   &HandleCount,
   1579                   &HandleBuffer
   1580 				  );
   1581 
   1582   if (EFI_ERROR (Status)) {
   1583     return;
   1584   }
   1585 
   1586   for (Index = 0; Index < HandleCount; Index++) {
   1587 
   1588     Status = gBS->HandleProtocol (
   1589                     HandleBuffer[Index],
   1590                     &gEfiDevicePathProtocolGuid,
   1591                     (VOID*)&DevicePath
   1592 				    );
   1593     ASSERT_EFI_ERROR (Status);
   1594 
   1595     DevicePathNode = DevicePath;
   1596     while (!IsDevicePathEnd (DevicePathNode) ) {
   1597       if  ((DevicePathType (DevicePathNode) == HARDWARE_DEVICE_PATH) &&
   1598            ( DevicePathSubType (DevicePathNode) == HW_PCI_DP)) {
   1599         PciDevicePath = (PCI_DEVICE_PATH *) DevicePathNode;
   1600         break;
   1601       }
   1602       DevicePathNode    = NextDevicePathNode (DevicePathNode);
   1603     }
   1604 
   1605     if (PciDevicePath == NULL) {
   1606       continue;
   1607     }
   1608 
   1609     //
   1610     // Check for onboard IDE
   1611     //
   1612     if (PciDevicePath->Device== PCI_DEVICE_NUMBER_PCH_SATA) {
   1613       Status = gBS->HandleProtocol (
   1614 	                  HandleBuffer[Index],
   1615 					  &gEfiDiskInfoProtocolGuid,
   1616 					  (void **)&DiskInfo
   1617 					  );
   1618       ASSERT_EFI_ERROR (Status);
   1619 
   1620       Status = DiskInfo->WhichIde (
   1621 	                       DiskInfo,
   1622                            &IdeChannel,
   1623                            &IdeDevice
   1624 						   );
   1625       ASSERT_EFI_ERROR (Status);
   1626 
   1627       IdentifyDriveInfo = AllocatePool (sizeof(EFI_ATA_IDENTIFY_DATA));
   1628 
   1629       BufferSize = sizeof(EFI_ATA_IDENTIFY_DATA);
   1630       Status = DiskInfo->Identify (
   1631 	                       DiskInfo,
   1632                            IdentifyDriveInfo,
   1633                            &BufferSize
   1634                            );
   1635       ASSERT_EFI_ERROR(Status);
   1636 
   1637       //
   1638       // Onboard SATA Devices
   1639       //
   1640       if (PciDevicePath->Function == PCI_FUNCTION_NUMBER_PCH_SATA) {
   1641         if (IdeChannel == 0 && IdeDevice == 0) {
   1642           NameToUpdate = (STRING_REF)STR_SATA0_NAME;
   1643         } else if (IdeChannel == 1 && IdeDevice == 0) {
   1644           NameToUpdate = (STRING_REF)STR_SATA1_NAME;
   1645         } else {
   1646           continue;
   1647         }
   1648       } else {
   1649         continue;
   1650       }
   1651 
   1652       ZeroMem(StringBuffer, sizeof(StringBuffer));
   1653       CopyMem(
   1654         StringBuffer,
   1655         (CHAR8 *)&IdentifyDriveInfo->ModelName,
   1656         sizeof(IdentifyDriveInfo->ModelName)
   1657         );
   1658       SwapEntries(StringBuffer);
   1659       AsciiToUnicode(StringBuffer, NewString);
   1660 
   1661 	  //
   1662       // Chap it off after 16 characters
   1663 	  //
   1664       NewString[16] = 0;
   1665 
   1666       //
   1667       // For HardDisk append the size. Otherwise display atapi
   1668       //
   1669       if ((IdentifyDriveInfo->config & 0x8000) == 00) {
   1670         //
   1671         // 48 bit address feature set is supported, get maximum capacity
   1672         //
   1673         if ((IdentifyDriveInfo->command_set_supported_83 & 0x0400) == 0) {
   1674         DriveSize = (((((IdentifyDriveInfo->user_addressable_sectors_hi << 16) +
   1675                       IdentifyDriveInfo->user_addressable_sectors_lo) / 1000) * 512) / 1000);
   1676         } else {
   1677           DriveSize    = IdentifyDriveInfo->maximum_lba_for_48bit_addressing[0];
   1678           for (Index1 = 1; Index1 < 4; Index1++) {
   1679             //
   1680             // Lower byte goes first: word[100] is the lowest word, word[103] is highest
   1681             //
   1682             DriveSize |= LShiftU64(IdentifyDriveInfo->maximum_lba_for_48bit_addressing[Index1], 16 * Index1);
   1683           }
   1684           DriveSize = (UINT32) DivU64x32(MultU64x32(DivU64x32(DriveSize, 1000), 512), 1000);
   1685         }
   1686 
   1687         StrCat (NewString, L"(");
   1688         EfiValueToString (SizeString, DriveSize/1000, PREFIX_BLANK, 0);
   1689         StrCat (NewString, SizeString);
   1690         StrCat (NewString, L".");
   1691         EfiValueToString (SizeString, (DriveSize%1000)/100, PREFIX_BLANK, 0);
   1692         StrCat (NewString, SizeString);
   1693         StrCat (NewString, L"GB");
   1694       } else {
   1695         StrCat (NewString, L"(ATAPI");
   1696       }
   1697 
   1698       //
   1699       // Update SPEED.
   1700       //
   1701       PortNumber = (IdeDevice << 1) + IdeChannel;
   1702       DeviceSpeed = GetChipsetSataPortSpeed(PortNumber);
   1703 
   1704       if (DeviceSpeed) {
   1705         StrCat (NewString, L"-");
   1706         GetDeviceSpeedString( NewString, DeviceSpeed);
   1707       }
   1708 
   1709       StrCat (NewString, L")");
   1710 
   1711       HiiSetString(mHiiHandle, NameToUpdate, NewString, NULL);
   1712 
   1713     }
   1714   }
   1715 
   1716   if (HandleBuffer != NULL) {
   1717     gBS->FreePool (HandleBuffer);
   1718   }
   1719 
   1720   gBS->FreePool(NewString);
   1721 
   1722   return;
   1723 }
   1724 
   1725 
   1726 VOID
   1727 EFIAPI
   1728 SetupInfo (void)
   1729 {
   1730   EFI_STATUS                  Status;
   1731   UINTN                       VarSize;
   1732   EFI_PEI_HOB_POINTERS        GuidHob;
   1733 
   1734   if (mSetupInfoDone) {
   1735       return;
   1736   }
   1737 
   1738   VarSize = sizeof(SYSTEM_CONFIGURATION);
   1739   Status = gRT->GetVariable(
   1740                   NORMAL_SETUP_NAME,
   1741                   &gEfiNormalSetupGuid,
   1742                   NULL,
   1743                   &VarSize,
   1744                   &mSystemConfiguration
   1745 				  );
   1746 
   1747   if (EFI_ERROR (Status) || VarSize != sizeof(SYSTEM_CONFIGURATION)) {
   1748     //The setup variable is corrupted
   1749     VarSize = sizeof(SYSTEM_CONFIGURATION);
   1750     Status = gRT->GetVariable(
   1751               L"SetupRecovery",
   1752               &gEfiNormalSetupGuid,
   1753               NULL,
   1754               &VarSize,
   1755               &mSystemConfiguration
   1756               );
   1757     ASSERT_EFI_ERROR (Status);
   1758   }
   1759 
   1760   //
   1761   // Update HOB variable for PCI resource information
   1762   // Get the HOB list.  If it is not present, then ASSERT.
   1763   //
   1764   GuidHob.Raw = GetHobList ();
   1765   if (GuidHob.Raw != NULL) {
   1766     if ((GuidHob.Raw = GetNextGuidHob (&gEfiPlatformInfoGuid, GuidHob.Raw)) != NULL) {
   1767       mPlatformInfo = GET_GUID_HOB_DATA (GuidHob.Guid);
   1768     }
   1769   }
   1770 
   1771 
   1772   PrepareSetupInformation();
   1773   UpdateAdditionalInformation ();
   1774   UpdatePlatformInformation();
   1775   UpdateCPUInformation();
   1776   IdeDataFilter();
   1777   mSetupInfoDone = TRUE;
   1778 
   1779   return;
   1780 }
   1781 
   1782 
   1783 #define EFI_SECURE_BOOT_MODE_NAME                   L"SecureBoot"
   1784 
   1785 VOID
   1786 CheckSystemConfigLoad(SYSTEM_CONFIGURATION *SystemConfigPtr)
   1787 {
   1788   EFI_STATUS              Status;
   1789   UINT8                   SecureBoot;
   1790   UINTN                   DataSize;
   1791 
   1792 
   1793   DataSize = sizeof(SecureBoot);
   1794   Status = gRT->GetVariable (
   1795                   EFI_SECURE_BOOT_MODE_NAME,
   1796                   &gEfiGlobalVariableGuid,
   1797                   NULL,
   1798                   &DataSize,
   1799                   &SecureBoot
   1800                   );
   1801 
   1802   if (EFI_ERROR(Status)) {
   1803     SystemConfigPtr->SecureBoot = 0;
   1804   } else {
   1805     SystemConfigPtr->SecureBoot = SecureBoot;
   1806   }
   1807 }
   1808 
   1809 
   1810 //
   1811 // "SecureBootEnable" variable for the Secure boot feature enable/disable.
   1812 //
   1813 #define EFI_SECURE_BOOT_ENABLE_NAME      L"SecureBootEnable"
   1814 extern EFI_GUID gEfiSecureBootEnableDisableGuid;
   1815 
   1816 
   1817 VOID
   1818 CheckSystemConfigSave(SYSTEM_CONFIGURATION *SystemConfigPtr)
   1819 {
   1820   EFI_STATUS              Status;
   1821   UINT8                   SecureBootCfg;
   1822   BOOLEAN                 SecureBootNotFound;
   1823   UINTN                   DataSize;
   1824 
   1825 
   1826     //
   1827     // Secure Boot configuration changes
   1828 	//
   1829     DataSize = sizeof(SecureBootCfg);
   1830     SecureBootNotFound = FALSE;
   1831     Status = gRT->GetVariable (
   1832                     EFI_SECURE_BOOT_ENABLE_NAME,
   1833                     &gEfiSecureBootEnableDisableGuid,
   1834                     NULL,
   1835                     &DataSize,
   1836                     &SecureBootCfg
   1837                     );
   1838 
   1839     if (EFI_ERROR(Status)) {
   1840       SecureBootNotFound = TRUE;
   1841     }
   1842     if (SecureBootNotFound) {
   1843       Status = gRT->GetVariable (
   1844                       EFI_SECURE_BOOT_ENABLE_NAME,
   1845                       &gEfiSecureBootEnableDisableGuid,
   1846                       NULL,
   1847                       &DataSize,
   1848                       &SecureBootCfg
   1849                       );
   1850       ASSERT_EFI_ERROR(Status);
   1851     }
   1852     if ((SecureBootCfg) != SystemConfigPtr->SecureBoot) {
   1853       SecureBootCfg = !SecureBootCfg;
   1854       Status = gRT->SetVariable (
   1855                       EFI_SECURE_BOOT_ENABLE_NAME,
   1856                       &gEfiSecureBootEnableDisableGuid,
   1857                       EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS,
   1858                       sizeof (UINT8),
   1859                       &SecureBootCfg
   1860                       );
   1861     }
   1862 
   1863 }
   1864 
   1865 VOID
   1866 ConfirmSecureBootTest()
   1867 {
   1868 
   1869 }
   1870 
   1871