]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/PCD/Pei/Pcd.c
UefiCpuPkg: Move AsmRelocateApLoopStart from Mpfuncs.nasm to AmdSev.nasm
[mirror_edk2.git] / MdeModulePkg / Universal / PCD / Pei / Pcd.c
index 668860b61c6ccb3590a51002e578451731c76779..c51ac96a32e382a6909cb14de8e4a7796f76a3f0 100644 (file)
@@ -1,15 +1,9 @@
-/** @file \r
+/** @file\r
   All Pcd Ppi services are implemented here.\r
-  \r
-Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.<BR>\r
-(C) Copyright 2016 Hewlett Packard Enterprise Development LP<BR>\r
-This program and the accompanying materials\r
-are licensed and made available under the terms and conditions of the BSD License\r
-which accompanies this distribution.  The full text of the license may be found at\r
-http://opensource.org/licenses/bsd-license.php\r
 \r
-THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
-WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+Copyright (c) 2006 - 2021, Intel Corporation. All rights reserved.<BR>\r
+(C) Copyright 2016 Hewlett Packard Enterprise Development LP<BR>\r
+SPDX-License-Identifier: BSD-2-Clause-Patent\r
 \r
 **/\r
 \r
@@ -19,37 +13,37 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 /// Instance of PCD_PPI protocol is EDKII native implementation.\r
 /// This protocol instance support dynamic and dynamicEx type PCDs.\r
 ///\r
-PCD_PPI mPcdPpiInstance = {\r
+PCD_PPI  mPcdPpiInstance = {\r
   PeiPcdSetSku,\r
 \r
   PeiPcdGet8,\r
-  PeiPcdGet16,          \r
-  PeiPcdGet32,          \r
-  PeiPcdGet64,          \r
-  PeiPcdGetPtr,         \r
-  PeiPcdGetBool,     \r
+  PeiPcdGet16,\r
+  PeiPcdGet32,\r
+  PeiPcdGet64,\r
+  PeiPcdGetPtr,\r
+  PeiPcdGetBool,\r
   PeiPcdGetSize,\r
 \r
   PeiPcdGet8Ex,\r
-  PeiPcdGet16Ex,          \r
-  PeiPcdGet32Ex,          \r
-  PeiPcdGet64Ex,          \r
-  PeiPcdGetPtrEx,         \r
-  PeiPcdGetBoolEx,     \r
+  PeiPcdGet16Ex,\r
+  PeiPcdGet32Ex,\r
+  PeiPcdGet64Ex,\r
+  PeiPcdGetPtrEx,\r
+  PeiPcdGetBoolEx,\r
   PeiPcdGetSizeEx,\r
-  \r
+\r
   PeiPcdSet8,\r
-  PeiPcdSet16,          \r
-  PeiPcdSet32,          \r
-  PeiPcdSet64,          \r
-  PeiPcdSetPtr,         \r
-  PeiPcdSetBool,     \r
+  PeiPcdSet16,\r
+  PeiPcdSet32,\r
+  PeiPcdSet64,\r
+  PeiPcdSetPtr,\r
+  PeiPcdSetBool,\r
 \r
   PeiPcdSet8Ex,\r
-  PeiPcdSet16Ex,          \r
-  PeiPcdSet32Ex,          \r
-  PeiPcdSet64Ex,          \r
-  PeiPcdSetPtrEx,         \r
+  PeiPcdSet16Ex,\r
+  PeiPcdSet32Ex,\r
+  PeiPcdSet64Ex,\r
+  PeiPcdSetPtrEx,\r
   PeiPcdSetBoolEx,\r
 \r
   PeiRegisterCallBackOnSet,\r
@@ -64,7 +58,7 @@ PCD_PPI mPcdPpiInstance = {
 ///\r
 EFI_PEI_PCD_PPI  mEfiPcdPpiInstance = {\r
   PeiPcdSetSku,\r
-  \r
+\r
   PeiPcdGet8Ex,\r
   PeiPcdGet16Ex,\r
   PeiPcdGet32Ex,\r
@@ -78,8 +72,8 @@ EFI_PEI_PCD_PPI  mEfiPcdPpiInstance = {
   PeiPcdSet64Ex,\r
   PeiPcdSetPtrEx,\r
   PeiPcdSetBoolEx,\r
-  (EFI_PEI_PCD_PPI_CALLBACK_ON_SET) PeiRegisterCallBackOnSet,\r
-  (EFI_PEI_PCD_PPI_CANCEL_CALLBACK) PcdUnRegisterCallBackOnSet,\r
+  (EFI_PEI_PCD_PPI_CALLBACK_ON_SET)PeiRegisterCallBackOnSet,\r
+  (EFI_PEI_PCD_PPI_CANCEL_CALLBACK)PcdUnRegisterCallBackOnSet,\r
   PeiPcdGetNextToken,\r
   PeiPcdGetNextTokenSpace\r
 };\r
@@ -88,7 +82,7 @@ EFI_PEI_PCD_PPI  mEfiPcdPpiInstance = {
 /// Instance of GET_PCD_INFO_PPI protocol is EDKII native implementation.\r
 /// This protocol instance support dynamic and dynamicEx type PCDs.\r
 ///\r
-GET_PCD_INFO_PPI mGetPcdInfoInstance = {\r
+GET_PCD_INFO_PPI  mGetPcdInfoInstance = {\r
   PeiGetPcdInfoGetInfo,\r
   PeiGetPcdInfoGetInfoEx,\r
   PeiGetPcdInfoGetSku\r
@@ -129,9 +123,212 @@ EFI_PEI_PPI_DESCRIPTOR  mPpiList2[] = {
   }\r
 };\r
 \r
+/**\r
+  Callback on SET PcdSetNvStoreDefaultId\r
+\r
+  Once PcdSetNvStoreDefaultId is set, the default NV storage will be found from\r
+  PcdNvStoreDefaultValueBuffer, and built into VariableHob.\r
+\r
+  @param[in]      CallBackGuid  The PCD token GUID being set.\r
+  @param[in]      CallBackToken The PCD token number being set.\r
+  @param[in, out] TokenData     A pointer to the token data being set.\r
+  @param[in]      TokenDataSize The size, in bytes, of the data being set.\r
+\r
+**/\r
+VOID\r
+EFIAPI\r
+PcdSetNvStoreDefaultIdCallBack (\r
+  IN CONST EFI_GUID  *CallBackGuid  OPTIONAL,\r
+  IN       UINTN     CallBackToken,\r
+  IN OUT   VOID      *TokenData,\r
+  IN       UINTN     TokenDataSize\r
+  )\r
+{\r
+  EFI_STATUS             Status;\r
+  UINT16                 DefaultId;\r
+  SKU_ID                 SkuId;\r
+  UINTN                  FullSize;\r
+  UINTN                  Index;\r
+  UINT8                  *DataBuffer;\r
+  UINT8                  *VarStoreHobData;\r
+  UINT8                  *BufferEnd;\r
+  BOOLEAN                IsFound;\r
+  VARIABLE_STORE_HEADER  *NvStoreBuffer;\r
+  PCD_DEFAULT_DATA       *DataHeader;\r
+  PCD_DEFAULT_INFO       *DefaultInfo;\r
+  PCD_DATA_DELTA         *DeltaData;\r
+\r
+  DefaultId = *(UINT16 *)TokenData;\r
+  SkuId     = GetPcdDatabase ()->SystemSkuId;\r
+  IsFound   = FALSE;\r
+\r
+  if (PeiPcdGetSizeEx (&gEfiMdeModulePkgTokenSpaceGuid, PcdToken (PcdNvStoreDefaultValueBuffer)) > sizeof (PCD_NV_STORE_DEFAULT_BUFFER_HEADER)) {\r
+    DataBuffer = (UINT8 *)PeiPcdGetPtrEx (&gEfiMdeModulePkgTokenSpaceGuid, PcdToken (PcdNvStoreDefaultValueBuffer));\r
+    FullSize   = ((PCD_NV_STORE_DEFAULT_BUFFER_HEADER *)DataBuffer)->Length;\r
+    DataHeader = (PCD_DEFAULT_DATA *)(DataBuffer + sizeof (PCD_NV_STORE_DEFAULT_BUFFER_HEADER));\r
+    //\r
+    // The first section data includes NV storage default setting.\r
+    //\r
+    NvStoreBuffer   = (VARIABLE_STORE_HEADER *)((UINT8 *)DataHeader + sizeof (DataHeader->DataSize) + DataHeader->HeaderSize);\r
+    VarStoreHobData = (UINT8 *)BuildGuidHob (&NvStoreBuffer->Signature, NvStoreBuffer->Size);\r
+    ASSERT (VarStoreHobData != NULL);\r
+    CopyMem (VarStoreHobData, NvStoreBuffer, NvStoreBuffer->Size);\r
+    //\r
+    // Find the matched SkuId and DefaultId in the first section\r
+    //\r
+    DefaultInfo = &(DataHeader->DefaultInfo[0]);\r
+    BufferEnd   = (UINT8 *)DataHeader + sizeof (DataHeader->DataSize) + DataHeader->HeaderSize;\r
+    while ((UINT8 *)DefaultInfo < BufferEnd) {\r
+      if ((DefaultInfo->DefaultId == DefaultId) && (DefaultInfo->SkuId == SkuId)) {\r
+        IsFound = TRUE;\r
+        break;\r
+      }\r
+\r
+      DefaultInfo++;\r
+    }\r
+\r
+    //\r
+    // Find the matched SkuId and DefaultId in the remaining section\r
+    //\r
+    Index      = sizeof (PCD_NV_STORE_DEFAULT_BUFFER_HEADER) + ((DataHeader->DataSize + 7) & (~7));\r
+    DataHeader = (PCD_DEFAULT_DATA *)(DataBuffer + Index);\r
+    while (!IsFound && Index < FullSize && DataHeader->DataSize != 0xFFFFFFFF) {\r
+      DefaultInfo = &(DataHeader->DefaultInfo[0]);\r
+      BufferEnd   = (UINT8 *)DataHeader + sizeof (DataHeader->DataSize) + DataHeader->HeaderSize;\r
+      while ((UINT8 *)DefaultInfo < BufferEnd) {\r
+        if ((DefaultInfo->DefaultId == DefaultId) && (DefaultInfo->SkuId == SkuId)) {\r
+          IsFound = TRUE;\r
+          break;\r
+        }\r
+\r
+        DefaultInfo++;\r
+      }\r
+\r
+      if (IsFound) {\r
+        DeltaData = (PCD_DATA_DELTA *)BufferEnd;\r
+        BufferEnd = (UINT8 *)DataHeader + DataHeader->DataSize;\r
+        while ((UINT8 *)DeltaData < BufferEnd) {\r
+          *(VarStoreHobData + DeltaData->Offset) = (UINT8)DeltaData->Value;\r
+          DeltaData++;\r
+        }\r
+\r
+        break;\r
+      }\r
+\r
+      Index      = (Index + DataHeader->DataSize + 7) & (~7);\r
+      DataHeader = (PCD_DEFAULT_DATA *)(DataBuffer + Index);\r
+    }\r
+  }\r
+\r
+  Status = PcdUnRegisterCallBackOnSet (\r
+             &gEfiMdeModulePkgTokenSpaceGuid,\r
+             PcdToken (PcdSetNvStoreDefaultId),\r
+             PcdSetNvStoreDefaultIdCallBack\r
+             );\r
+  ASSERT_EFI_ERROR (Status);\r
+}\r
+\r
+/**\r
+  Report Pei PCD database of all SKUs as Guid HOB so that DxePcd can access it.\r
+\r
+  @param PeiServices       An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation\r
+  @param NotifyDescriptor  Address of the notification descriptor data structure.\r
+  @param Ppi               Address of the PPI that was installed.\r
+\r
+  @retval EFI_SUCCESS      Successfully update the Boot records.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+EndOfPeiSignalPpiNotifyCallback (\r
+  IN EFI_PEI_SERVICES           **PeiServices,\r
+  IN EFI_PEI_NOTIFY_DESCRIPTOR  *NotifyDescriptor,\r
+  IN VOID                       *Ppi\r
+  )\r
+{\r
+  PEI_PCD_DATABASE     *Database;\r
+  EFI_BOOT_MODE        BootMode;\r
+  EFI_STATUS           Status;\r
+  UINTN                Instance;\r
+  EFI_PEI_FV_HANDLE    VolumeHandle;\r
+  EFI_PEI_FILE_HANDLE  FileHandle;\r
+  VOID                 *PcdDb;\r
+  UINT32               Length;\r
+  PEI_PCD_DATABASE     *PeiPcdDb;\r
+\r
+  Status = PeiServicesGetBootMode (&BootMode);\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  //\r
+  // Don't need to report it on S3 boot.\r
+  //\r
+  if (BootMode == BOOT_ON_S3_RESUME) {\r
+    return EFI_SUCCESS;\r
+  }\r
+\r
+  PeiPcdDb = GetPcdDatabase ();\r
+  if (PeiPcdDb->SystemSkuId != (SKU_ID)0) {\r
+    //\r
+    // SkuId has been set. Don't need to report it to DXE phase.\r
+    //\r
+    return EFI_SUCCESS;\r
+  }\r
+\r
+  //\r
+  // Get full PCD database from PcdPeim FileHandle\r
+  //\r
+  Instance   = 0;\r
+  FileHandle = NULL;\r
+  while (TRUE) {\r
+    //\r
+    // Traverse all firmware volume instances\r
+    //\r
+    Status = PeiServicesFfsFindNextVolume (Instance, &VolumeHandle);\r
+    //\r
+    // Error should not happen\r
+    //\r
+    ASSERT_EFI_ERROR (Status);\r
+\r
+    //\r
+    // Find PcdDb file from the beginning in this firmware volume.\r
+    //\r
+    FileHandle = NULL;\r
+    Status     = PeiServicesFfsFindFileByName (&gEfiCallerIdGuid, VolumeHandle, &FileHandle);\r
+    if (!EFI_ERROR (Status)) {\r
+      //\r
+      // Find PcdPeim FileHandle in this volume\r
+      //\r
+      break;\r
+    }\r
+\r
+    //\r
+    // We cannot find PcdPeim in this firmware volume, then search the next volume.\r
+    //\r
+    Instance++;\r
+  }\r
+\r
+  //\r
+  // Find PEI PcdDb and Build second PcdDB GuidHob\r
+  //\r
+  Status = PeiServicesFfsFindSectionData (EFI_SECTION_RAW, FileHandle, &PcdDb);\r
+  ASSERT_EFI_ERROR (Status);\r
+  Length   = PeiPcdDb->LengthForAllSkus;\r
+  Database = BuildGuidHob (&gPcdDataBaseHobGuid, Length);\r
+  CopyMem (Database, PcdDb, Length);\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+EFI_PEI_NOTIFY_DESCRIPTOR  mEndOfPeiSignalPpiNotifyList[] = {\r
+  {\r
+    (EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),\r
+    &gEfiEndOfPeiSignalPpiGuid,\r
+    EndOfPeiSignalPpiNotifyCallback\r
+  }\r
+};\r
+\r
 /**\r
   Main entry for PCD PEIM driver.\r
-  \r
+\r
   This routine initialize the PCD database for PEI phase and install PCD_PPI/EFI_PEI_PCD_PPI.\r
 \r
   @param  FileHandle  Handle of the file being invoked.\r
@@ -147,7 +344,76 @@ PcdPeimInit (
   IN CONST EFI_PEI_SERVICES     **PeiServices\r
   )\r
 {\r
-  EFI_STATUS Status;\r
+  EFI_STATUS  Status;\r
+\r
+  Status = PeiServicesRegisterForShadow (FileHandle);\r
+  if (Status == EFI_ALREADY_STARTED) {\r
+    //\r
+    // This is now starting in memory, the second time starting.\r
+    //\r
+    EFI_PEI_PPI_DESCRIPTOR  *OldPpiList;\r
+    EFI_PEI_PPI_DESCRIPTOR  *OldPpiList2;\r
+    VOID                    *Ppi;\r
+    VOID                    *Ppi2;\r
+\r
+    OldPpiList = NULL;\r
+    Status     = PeiServicesLocatePpi (\r
+                   &gPcdPpiGuid,\r
+                   0,\r
+                   &OldPpiList,\r
+                   &Ppi\r
+                   );\r
+    ASSERT_EFI_ERROR (Status);\r
+\r
+    if (OldPpiList != NULL) {\r
+      Status = PeiServicesReInstallPpi (OldPpiList, &mPpiList[0]);\r
+      ASSERT_EFI_ERROR (Status);\r
+    }\r
+\r
+    OldPpiList2 = NULL;\r
+    Status      = PeiServicesLocatePpi (\r
+                    &gGetPcdInfoPpiGuid,\r
+                    0,\r
+                    &OldPpiList2,\r
+                    &Ppi2\r
+                    );\r
+    ASSERT_EFI_ERROR (Status);\r
+\r
+    if (OldPpiList2 != NULL) {\r
+      Status = PeiServicesReInstallPpi (OldPpiList2, &mPpiList2[0]);\r
+      ASSERT_EFI_ERROR (Status);\r
+    }\r
+\r
+    OldPpiList = NULL;\r
+    Status     = PeiServicesLocatePpi (\r
+                   &gEfiPeiPcdPpiGuid,\r
+                   0,\r
+                   &OldPpiList,\r
+                   &Ppi\r
+                   );\r
+    ASSERT_EFI_ERROR (Status);\r
+\r
+    if (OldPpiList != NULL) {\r
+      Status = PeiServicesReInstallPpi (OldPpiList, &mPpiList[1]);\r
+      ASSERT_EFI_ERROR (Status);\r
+    }\r
+\r
+    OldPpiList2 = NULL;\r
+    Status      = PeiServicesLocatePpi (\r
+                    &gEfiGetPcdInfoPpiGuid,\r
+                    0,\r
+                    &OldPpiList2,\r
+                    &Ppi2\r
+                    );\r
+    ASSERT_EFI_ERROR (Status);\r
+\r
+    if (OldPpiList2 != NULL) {\r
+      Status = PeiServicesReInstallPpi (OldPpiList2, &mPpiList2[1]);\r
+      ASSERT_EFI_ERROR (Status);\r
+    }\r
+\r
+    return Status;\r
+  }\r
 \r
   BuildPcdDatabase (FileHandle);\r
 \r
@@ -163,6 +429,16 @@ PcdPeimInit (
   Status = PeiServicesInstallPpi (&mPpiList2[0]);\r
   ASSERT_EFI_ERROR (Status);\r
 \r
+  Status = PeiServicesNotifyPpi (&mEndOfPeiSignalPpiNotifyList[0]);\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  Status = PeiRegisterCallBackOnSet (\r
+             &gEfiMdeModulePkgTokenSpaceGuid,\r
+             PcdToken (PcdSetNvStoreDefaultId),\r
+             PcdSetNvStoreDefaultIdCallBack\r
+             );\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
   return Status;\r
 }\r
 \r
@@ -182,8 +458,8 @@ PcdPeimInit (
 EFI_STATUS\r
 EFIAPI\r
 PeiGetPcdInfoGetInfo (\r
-  IN        UINTN           TokenNumber,\r
-  OUT       EFI_PCD_INFO    *PcdInfo\r
+  IN        UINTN         TokenNumber,\r
+  OUT       EFI_PCD_INFO  *PcdInfo\r
   )\r
 {\r
   return PeiGetPcdInfo (NULL, TokenNumber, PcdInfo);\r
@@ -206,9 +482,9 @@ PeiGetPcdInfoGetInfo (
 EFI_STATUS\r
 EFIAPI\r
 PeiGetPcdInfoGetInfoEx (\r
-  IN CONST  EFI_GUID        *Guid,\r
-  IN        UINTN           TokenNumber,\r
-  OUT       EFI_PCD_INFO    *PcdInfo\r
+  IN CONST  EFI_GUID      *Guid,\r
+  IN        UINTN         TokenNumber,\r
+  OUT       EFI_PCD_INFO  *PcdInfo\r
   )\r
 {\r
   return PeiGetPcdInfo (Guid, TokenNumber, PcdInfo);\r
@@ -227,92 +503,190 @@ PeiGetPcdInfoGetSku (
   VOID\r
   )\r
 {\r
-  return (UINTN) GetPcdDatabase()->SystemSkuId;\r
+  return (UINTN)GetPcdDatabase ()->SystemSkuId;\r
 }\r
 \r
 /**\r
   Sets the SKU value for subsequent calls to set or get PCD token values.\r
 \r
-  SetSku() sets the SKU Id to be used for subsequent calls to set or get PCD values. \r
+  SetSku() sets the SKU Id to be used for subsequent calls to set or get PCD values.\r
   SetSku() is normally called only once by the system.\r
 \r
-  For each item (token), the database can hold a single value that applies to all SKUs, \r
-  or multiple values, where each value is associated with a specific SKU Id. Items with multiple, \r
-  SKU-specific values are called SKU enabled. \r
-  \r
+  For each item (token), the database can hold a single value that applies to all SKUs,\r
+  or multiple values, where each value is associated with a specific SKU Id. Items with multiple,\r
+  SKU-specific values are called SKU enabled.\r
+\r
   The SKU Id of zero is reserved as a default.\r
-  For tokens that are not SKU enabled, the system ignores any set SKU Id and works with the \r
-  single value for that token. For SKU-enabled tokens, the system will use the SKU Id set by the \r
-  last call to SetSku(). If no SKU Id is set or the currently set SKU Id isn't valid for the specified token, \r
-  the system uses the default SKU Id. If the system attempts to use the default SKU Id and no value has been \r
+  For tokens that are not SKU enabled, the system ignores any set SKU Id and works with the\r
+  single value for that token. For SKU-enabled tokens, the system will use the SKU Id set by the\r
+  last call to SetSku(). If no SKU Id is set or the currently set SKU Id isn't valid for the specified token,\r
+  the system uses the default SKU Id. If the system attempts to use the default SKU Id and no value has been\r
   set for that Id, the results are unpredictable.\r
 \r
-  @param[in]  SkuId The SKU value that will be used when the PCD service will retrieve and \r
+  @param[in]  SkuId The SKU value that will be used when the PCD service will retrieve and\r
               set values associated with a PCD token.\r
 \r
 **/\r
 VOID\r
 EFIAPI\r
 PeiPcdSetSku (\r
-  IN  UINTN                  SkuId\r
+  IN  UINTN  SkuId\r
   )\r
 {\r
-  PEI_PCD_DATABASE  *PeiPcdDb;\r
-  SKU_ID            *SkuIdTable;\r
-  UINTN             Index;\r
+  PEI_PCD_DATABASE        *PeiPcdDb;\r
+  SKU_ID                  *SkuIdTable;\r
+  UINTN                   Index;\r
+  EFI_STATUS              Status;\r
+  UINTN                   Instance;\r
+  EFI_PEI_FV_HANDLE       VolumeHandle;\r
+  EFI_PEI_FILE_HANDLE     FileHandle;\r
+  VOID                    *PcdDb;\r
+  UINT32                  Length;\r
+  PCD_DATABASE_SKU_DELTA  *SkuDelta;\r
+  PCD_DATA_DELTA          *SkuDeltaData;\r
+\r
+  DEBUG ((DEBUG_INFO, "PcdPei - SkuId 0x%lx is to be set.\n", (SKU_ID)SkuId));\r
+\r
+  PeiPcdDb = GetPcdDatabase ();\r
+\r
+  if (SkuId == PeiPcdDb->SystemSkuId) {\r
+    //\r
+    // The input SKU Id is equal to current SKU Id, return directly.\r
+    //\r
+    DEBUG ((DEBUG_INFO, "PcdPei - SkuId is same to current system Sku.\n"));\r
+    return;\r
+  }\r
+\r
+  if (PeiPcdDb->SystemSkuId != (SKU_ID)0) {\r
+    DEBUG ((DEBUG_ERROR, "PcdPei - The SKU Id could be changed only once."));\r
+    DEBUG ((\r
+      DEBUG_ERROR,\r
+      "PcdPei - The SKU Id was set to 0x%lx already, it could not be set to 0x%lx any more.",\r
+      PeiPcdDb->SystemSkuId,\r
+      (SKU_ID)SkuId\r
+      ));\r
+    ASSERT (FALSE);\r
+    return;\r
+  }\r
 \r
-  PeiPcdDb = GetPcdDatabase();\r
-  SkuIdTable = (SKU_ID *) ((UINT8 *) PeiPcdDb + PeiPcdDb->SkuIdTableOffset);\r
+  SkuIdTable = (SKU_ID *)((UINT8 *)PeiPcdDb + PeiPcdDb->SkuIdTableOffset);\r
   for (Index = 0; Index < SkuIdTable[0]; Index++) {\r
     if (SkuId == SkuIdTable[Index + 1]) {\r
-      PeiPcdDb->SystemSkuId = (SKU_ID) SkuId;\r
+      DEBUG ((DEBUG_INFO, "PcdPei - SkuId is found in SkuId table.\n"));\r
+      break;\r
+    }\r
+  }\r
+\r
+  if (Index < SkuIdTable[0]) {\r
+    //\r
+    // Get full PCD database from PcdPeim FileHandle\r
+    //\r
+    Instance   = 0;\r
+    FileHandle = NULL;\r
+    while (TRUE) {\r
+      //\r
+      // Traverse all firmware volume instances\r
+      //\r
+      Status = PeiServicesFfsFindNextVolume (Instance, &VolumeHandle);\r
+      //\r
+      // Error should not happen\r
+      //\r
+      ASSERT_EFI_ERROR (Status);\r
+\r
+      //\r
+      // Find PcdDb file from the beginning in this firmware volume.\r
+      //\r
+      FileHandle = NULL;\r
+      Status     = PeiServicesFfsFindFileByName (&gEfiCallerIdGuid, VolumeHandle, &FileHandle);\r
+      if (!EFI_ERROR (Status)) {\r
+        //\r
+        // Find PcdPeim FileHandle in this volume\r
+        //\r
+        break;\r
+      }\r
+\r
+      //\r
+      // We cannot find PcdPeim in this firmware volume, then search the next volume.\r
+      //\r
+      Instance++;\r
+    }\r
+\r
+    //\r
+    // Find the delta data between the different Skus\r
+    //\r
+    Status = PeiServicesFfsFindSectionData (EFI_SECTION_RAW, FileHandle, &PcdDb);\r
+    ASSERT_EFI_ERROR (Status);\r
+    Length   = PeiPcdDb->LengthForAllSkus;\r
+    Index    = (PeiPcdDb->Length + 7) & (~7);\r
+    SkuDelta = NULL;\r
+    while (Index < Length) {\r
+      SkuDelta = (PCD_DATABASE_SKU_DELTA *)((UINT8 *)PcdDb + Index);\r
+      if ((SkuDelta->SkuId == SkuId) && (SkuDelta->SkuIdCompared == 0)) {\r
+        break;\r
+      }\r
+\r
+      Index = (Index + SkuDelta->Length + 7) & (~7);\r
+    }\r
+\r
+    //\r
+    // Patch the delta data into current PCD database\r
+    //\r
+    if ((Index < Length) && (SkuDelta != NULL)) {\r
+      SkuDeltaData = (PCD_DATA_DELTA *)(SkuDelta + 1);\r
+      while ((UINT8 *)SkuDeltaData < (UINT8 *)SkuDelta + SkuDelta->Length) {\r
+        *((UINT8 *)PeiPcdDb + SkuDeltaData->Offset) = (UINT8)SkuDeltaData->Value;\r
+        SkuDeltaData++;\r
+      }\r
+\r
+      PeiPcdDb->SystemSkuId = (SKU_ID)SkuId;\r
+      DEBUG ((DEBUG_INFO, "PcdPei - Set current SKU Id to 0x%lx.\n", (SKU_ID)SkuId));\r
       return;\r
     }\r
   }\r
 \r
   //\r
-  // Invalid input SkuId, the default SKU Id will be used for the system.\r
+  // Invalid input SkuId, the default SKU Id will be still used for the system.\r
   //\r
-  DEBUG ((EFI_D_INFO, "PcdPei - Invalid input SkuId, the default SKU Id will be used.\n"));\r
-  PeiPcdDb->SystemSkuId = (SKU_ID) 0;\r
+  DEBUG ((DEBUG_ERROR, "PcdPei - Invalid input SkuId, the default SKU Id will be still used.\n"));\r
+\r
   return;\r
 }\r
 \r
 /**\r
   Retrieves an 8-bit value for a given PCD token.\r
 \r
-  Retrieves the current byte-sized value for a PCD token number.  \r
+  Retrieves the current byte-sized value for a PCD token number.\r
   If the TokenNumber is invalid, the results are unpredictable.\r
-  \r
-  @param[in]  TokenNumber The PCD token number. \r
+\r
+  @param[in]  TokenNumber The PCD token number.\r
 \r
   @return The UINT8 value.\r
-  \r
+\r
 **/\r
 UINT8\r
 EFIAPI\r
 PeiPcdGet8 (\r
-  IN UINTN                    TokenNumber\r
+  IN UINTN  TokenNumber\r
   )\r
 {\r
-  return *((UINT8 *) GetWorker (TokenNumber, sizeof (UINT8)));\r
+  return *((UINT8 *)GetWorker (TokenNumber, sizeof (UINT8)));\r
 }\r
 \r
 /**\r
   Retrieves an 16-bit value for a given PCD token.\r
 \r
-  Retrieves the current 16-bits value for a PCD token number.  \r
+  Retrieves the current 16-bits value for a PCD token number.\r
   If the TokenNumber is invalid, the results are unpredictable.\r
-  \r
-  @param[in]  TokenNumber The PCD token number. \r
+\r
+  @param[in]  TokenNumber The PCD token number.\r
 \r
   @return The UINT16 value.\r
-  \r
+\r
 **/\r
 UINT16\r
 EFIAPI\r
 PeiPcdGet16 (\r
-  IN UINTN                    TokenNumber\r
+  IN UINTN  TokenNumber\r
   )\r
 {\r
   return ReadUnaligned16 (GetWorker (TokenNumber, sizeof (UINT16)));\r
@@ -321,18 +695,18 @@ PeiPcdGet16 (
 /**\r
   Retrieves an 32-bit value for a given PCD token.\r
 \r
-  Retrieves the current 32-bits value for a PCD token number.  \r
+  Retrieves the current 32-bits value for a PCD token number.\r
   If the TokenNumber is invalid, the results are unpredictable.\r
-  \r
-  @param[in]  TokenNumber The PCD token number. \r
+\r
+  @param[in]  TokenNumber The PCD token number.\r
 \r
   @return The UINT32 value.\r
-  \r
+\r
 **/\r
 UINT32\r
 EFIAPI\r
 PeiPcdGet32 (\r
-  IN UINTN                    TokenNumber\r
+  IN UINTN  TokenNumber\r
   )\r
 {\r
   return ReadUnaligned32 (GetWorker (TokenNumber, sizeof (UINT32)));\r
@@ -341,18 +715,18 @@ PeiPcdGet32 (
 /**\r
   Retrieves an 64-bit value for a given PCD token.\r
 \r
-  Retrieves the current 64-bits value for a PCD token number.  \r
+  Retrieves the current 64-bits value for a PCD token number.\r
   If the TokenNumber is invalid, the results are unpredictable.\r
-  \r
-  @param[in]  TokenNumber The PCD token number. \r
+\r
+  @param[in]  TokenNumber The PCD token number.\r
 \r
   @return The UINT64 value.\r
-  \r
+\r
 **/\r
 UINT64\r
 EFIAPI\r
 PeiPcdGet64 (\r
-  IN UINTN                    TokenNumber\r
+  IN UINTN  TokenNumber\r
   )\r
 {\r
   return ReadUnaligned64 (GetWorker (TokenNumber, sizeof (UINT64)));\r
@@ -361,20 +735,20 @@ PeiPcdGet64 (
 /**\r
   Retrieves a pointer to a value for a given PCD token.\r
 \r
-  Retrieves the current pointer to the buffer for a PCD token number.  \r
-  Do not make any assumptions about the alignment of the pointer that \r
-  is returned by this function call.  If the TokenNumber is invalid, \r
+  Retrieves the current pointer to the buffer for a PCD token number.\r
+  Do not make any assumptions about the alignment of the pointer that\r
+  is returned by this function call.  If the TokenNumber is invalid,\r
   the results are unpredictable.\r
 \r
-  @param[in]  TokenNumber The PCD token number. \r
+  @param[in]  TokenNumber The PCD token number.\r
 \r
   @return The pointer to the buffer to be retrieved.\r
-  \r
+\r
 **/\r
 VOID *\r
 EFIAPI\r
 PeiPcdGetPtr (\r
-  IN UINTN                    TokenNumber\r
+  IN UINTN  TokenNumber\r
   )\r
 {\r
   return GetWorker (TokenNumber, 0);\r
@@ -383,46 +757,46 @@ PeiPcdGetPtr (
 /**\r
   Retrieves a Boolean value for a given PCD token.\r
 \r
-  Retrieves the current boolean value for a PCD token number.  \r
-  Do not make any assumptions about the alignment of the pointer that \r
-  is returned by this function call.  If the TokenNumber is invalid, \r
+  Retrieves the current boolean value for a PCD token number.\r
+  Do not make any assumptions about the alignment of the pointer that\r
+  is returned by this function call.  If the TokenNumber is invalid,\r
   the results are unpredictable.\r
 \r
-  @param[in]  TokenNumber The PCD token number. \r
+  @param[in]  TokenNumber The PCD token number.\r
 \r
   @return The Boolean value.\r
-  \r
+\r
 **/\r
 BOOLEAN\r
 EFIAPI\r
 PeiPcdGetBool (\r
-  IN UINTN                    TokenNumber\r
+  IN UINTN  TokenNumber\r
   )\r
 {\r
-  return *((BOOLEAN *) GetWorker (TokenNumber, sizeof (BOOLEAN)));\r
+  return *((BOOLEAN *)GetWorker (TokenNumber, sizeof (BOOLEAN)));\r
 }\r
 \r
 /**\r
   Retrieves the size of the value for a given PCD token.\r
 \r
-  Retrieves the current size of a particular PCD token.  \r
+  Retrieves the current size of a particular PCD token.\r
   If the TokenNumber is invalid, the results are unpredictable.\r
 \r
-  @param[in]  TokenNumber The PCD token number. \r
+  @param[in]  TokenNumber The PCD token number.\r
 \r
   @return The size of the value for the PCD token.\r
-  \r
+\r
 **/\r
 UINTN\r
 EFIAPI\r
 PeiPcdGetSize (\r
-  IN UINTN                    TokenNumber\r
+  IN UINTN  TokenNumber\r
   )\r
 {\r
-  PEI_PCD_DATABASE    *PeiPcdDb;\r
-  UINTN               Size;\r
-  UINTN               MaxSize;\r
-  UINT32              LocalTokenCount;\r
+  PEI_PCD_DATABASE  *PeiPcdDb;\r
+  UINTN             Size;\r
+  UINTN             MaxSize;\r
+  UINT32            LocalTokenCount;\r
 \r
   PeiPcdDb        = GetPcdDatabase ();\r
   LocalTokenCount = PeiPcdDb->LocalTokenCount;\r
@@ -434,7 +808,7 @@ PeiPcdGetSize (
   TokenNumber--;\r
 \r
   // EBC compiler is very choosy. It may report warning about comparison\r
-  // between UINTN and 0 . So we add 1 in each size of the \r
+  // between UINTN and 0 . So we add 1 in each size of the\r
   // comparison.\r
   ASSERT (TokenNumber + 1 < (LocalTokenCount + 1));\r
 \r
@@ -448,52 +822,51 @@ PeiPcdGetSize (
   } else {\r
     return Size;\r
   }\r
-\r
 }\r
 \r
 /**\r
   Retrieves an 8-bit value for a given PCD token.\r
 \r
-  Retrieves the 8-bit value of a particular PCD token.  \r
+  Retrieves the 8-bit value of a particular PCD token.\r
   If the TokenNumber is invalid or the token space\r
-  specified by Guid does not exist, the results are \r
+  specified by Guid does not exist, the results are\r
   unpredictable.\r
 \r
   @param[in]  Guid              The token space for the token number.\r
-  @param[in]  ExTokenNumber     The PCD token number. \r
+  @param[in]  ExTokenNumber     The PCD token number.\r
 \r
   @return The size 8-bit value for the PCD token.\r
-  \r
+\r
 **/\r
 UINT8\r
 EFIAPI\r
 PeiPcdGet8Ex (\r
-  IN CONST EFI_GUID             *Guid,\r
-  IN UINTN                      ExTokenNumber\r
+  IN CONST EFI_GUID  *Guid,\r
+  IN UINTN           ExTokenNumber\r
   )\r
 {\r
-  return *((UINT8 *) ExGetWorker (Guid, ExTokenNumber, sizeof (UINT8)));\r
+  return *((UINT8 *)ExGetWorker (Guid, ExTokenNumber, sizeof (UINT8)));\r
 }\r
 \r
 /**\r
   Retrieves an 16-bit value for a given PCD token.\r
 \r
-  Retrieves the 16-bit value of a particular PCD token.  \r
+  Retrieves the 16-bit value of a particular PCD token.\r
   If the TokenNumber is invalid or the token space\r
-  specified by Guid does not exist, the results are \r
+  specified by Guid does not exist, the results are\r
   unpredictable.\r
 \r
   @param[in]  Guid          The token space for the token number.\r
-  @param[in]  ExTokenNumber The PCD token number. \r
+  @param[in]  ExTokenNumber The PCD token number.\r
 \r
   @return The size 16-bit value for the PCD token.\r
-  \r
+\r
 **/\r
 UINT16\r
 EFIAPI\r
 PeiPcdGet16Ex (\r
-  IN CONST EFI_GUID             *Guid,\r
-  IN UINTN                      ExTokenNumber\r
+  IN CONST EFI_GUID  *Guid,\r
+  IN UINTN           ExTokenNumber\r
   )\r
 {\r
   return ReadUnaligned16 (ExGetWorker (Guid, ExTokenNumber, sizeof (UINT16)));\r
@@ -502,22 +875,22 @@ PeiPcdGet16Ex (
 /**\r
   Retrieves an 32-bit value for a given PCD token.\r
 \r
-  Retrieves the 32-bit value of a particular PCD token.  \r
+  Retrieves the 32-bit value of a particular PCD token.\r
   If the TokenNumber is invalid or the token space\r
-  specified by Guid does not exist, the results are \r
+  specified by Guid does not exist, the results are\r
   unpredictable.\r
 \r
   @param[in]  Guid The token space for the token number.\r
-  @param[in]  ExTokenNumber The PCD token number. \r
+  @param[in]  ExTokenNumber The PCD token number.\r
 \r
   @return The size 32-bit value for the PCD token.\r
-  \r
+\r
 **/\r
 UINT32\r
 EFIAPI\r
 PeiPcdGet32Ex (\r
-  IN CONST EFI_GUID             *Guid,\r
-  IN UINTN                      ExTokenNumber\r
+  IN CONST EFI_GUID  *Guid,\r
+  IN UINTN           ExTokenNumber\r
   )\r
 {\r
   return ReadUnaligned32 (ExGetWorker (Guid, ExTokenNumber, sizeof (UINT32)));\r
@@ -526,22 +899,22 @@ PeiPcdGet32Ex (
 /**\r
   Retrieves an 64-bit value for a given PCD token.\r
 \r
-  Retrieves the 64-bit value of a particular PCD token.  \r
+  Retrieves the 64-bit value of a particular PCD token.\r
   If the TokenNumber is invalid or the token space\r
-  specified by Guid does not exist, the results are \r
+  specified by Guid does not exist, the results are\r
   unpredictable.\r
 \r
   @param[in]  Guid The token space for the token number.\r
-  @param[in]  ExTokenNumber The PCD token number. \r
+  @param[in]  ExTokenNumber The PCD token number.\r
 \r
   @return The size 64-bit value for the PCD token.\r
-  \r
+\r
 **/\r
 UINT64\r
 EFIAPI\r
 PeiPcdGet64Ex (\r
-  IN CONST EFI_GUID             *Guid,\r
-  IN UINTN                      ExTokenNumber\r
+  IN CONST EFI_GUID  *Guid,\r
+  IN UINTN           ExTokenNumber\r
   )\r
 {\r
   return ReadUnaligned64 (ExGetWorker (Guid, ExTokenNumber, sizeof (UINT64)));\r
@@ -550,22 +923,22 @@ PeiPcdGet64Ex (
 /**\r
   Retrieves a pointer to a value for a given PCD token.\r
 \r
-  Retrieves the current pointer to the buffer for a PCD token number.  \r
-  Do not make any assumptions about the alignment of the pointer that \r
-  is returned by this function call.  If the TokenNumber is invalid, \r
+  Retrieves the current pointer to the buffer for a PCD token number.\r
+  Do not make any assumptions about the alignment of the pointer that\r
+  is returned by this function call.  If the TokenNumber is invalid,\r
   the results are unpredictable.\r
 \r
   @param[in]  Guid          The token space for the token number.\r
-  @param[in]  ExTokenNumber The PCD token number. \r
+  @param[in]  ExTokenNumber The PCD token number.\r
 \r
   @return The pointer to the buffer to be retrieved.\r
-  \r
+\r
 **/\r
 VOID *\r
 EFIAPI\r
 PeiPcdGetPtrEx (\r
-  IN CONST EFI_GUID             *Guid,\r
-  IN UINTN                      ExTokenNumber\r
+  IN CONST EFI_GUID  *Guid,\r
+  IN UINTN           ExTokenNumber\r
   )\r
 {\r
   return ExGetWorker (Guid, ExTokenNumber, 0);\r
@@ -574,44 +947,44 @@ PeiPcdGetPtrEx (
 /**\r
   Retrieves an Boolean value for a given PCD token.\r
 \r
-  Retrieves the Boolean value of a particular PCD token.  \r
+  Retrieves the Boolean value of a particular PCD token.\r
   If the TokenNumber is invalid or the token space\r
-  specified by Guid does not exist, the results are \r
+  specified by Guid does not exist, the results are\r
   unpredictable.\r
 \r
   @param[in]  Guid          The token space for the token number.\r
-  @param[in]  ExTokenNumber The PCD token number. \r
+  @param[in]  ExTokenNumber The PCD token number.\r
 \r
   @return The size Boolean value for the PCD token.\r
-  \r
+\r
 **/\r
 BOOLEAN\r
 EFIAPI\r
 PeiPcdGetBoolEx (\r
-  IN CONST  EFI_GUID              *Guid,\r
-  IN UINTN                        ExTokenNumber\r
+  IN CONST  EFI_GUID  *Guid,\r
+  IN UINTN            ExTokenNumber\r
   )\r
 {\r
-  return *((BOOLEAN *) ExGetWorker (Guid, ExTokenNumber, sizeof (BOOLEAN)));\r
+  return *((BOOLEAN *)ExGetWorker (Guid, ExTokenNumber, sizeof (BOOLEAN)));\r
 }\r
 \r
 /**\r
   Retrieves the size of the value for a given PCD token.\r
 \r
-  Retrieves the current size of a particular PCD token.  \r
+  Retrieves the current size of a particular PCD token.\r
   If the TokenNumber is invalid, the results are unpredictable.\r
 \r
   @param[in]  Guid          The token space for the token number.\r
-  @param[in]  ExTokenNumber The PCD token number. \r
+  @param[in]  ExTokenNumber The PCD token number.\r
 \r
   @return The size of the value for the PCD token.\r
-  \r
+\r
 **/\r
 UINTN\r
 EFIAPI\r
 PeiPcdGetSizeEx (\r
-  IN CONST  EFI_GUID              *Guid,\r
-  IN UINTN                        ExTokenNumber\r
+  IN CONST  EFI_GUID  *Guid,\r
+  IN UINTN            ExTokenNumber\r
   )\r
 {\r
   return PeiPcdGetSize (GetExPcdTokenNumber (Guid, ExTokenNumber));\r
@@ -620,25 +993,25 @@ PeiPcdGetSizeEx (
 /**\r
   Sets an 8-bit value for a given PCD token.\r
 \r
-  When the PCD service sets a value, it will check to ensure that the \r
-  size of the value being set is compatible with the Token's existing definition.  \r
+  When the PCD service sets a value, it will check to ensure that the\r
+  size of the value being set is compatible with the Token's existing definition.\r
   If it is not, an error will be returned.\r
 \r
-  @param[in]  TokenNumber The PCD token number. \r
+  @param[in]  TokenNumber The PCD token number.\r
   @param[in]  Value The value to set for the PCD token.\r
 \r
   @retval EFI_SUCCESS  Procedure returned successfully.\r
-  @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data \r
-                                  being set was incompatible with a call to this function.  \r
+  @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data\r
+                                  being set was incompatible with a call to this function.\r
                                   Use GetSize() to retrieve the size of the target data.\r
   @retval EFI_NOT_FOUND The PCD service could not find the requested token number.\r
-  \r
+\r
 **/\r
 EFI_STATUS\r
 EFIAPI\r
 PeiPcdSet8 (\r
-  IN UINTN                        TokenNumber,\r
-  IN UINT8                        Value\r
+  IN UINTN  TokenNumber,\r
+  IN UINT8  Value\r
   )\r
 {\r
   return SetValueWorker (TokenNumber, &Value, sizeof (Value));\r
@@ -647,25 +1020,25 @@ PeiPcdSet8 (
 /**\r
   Sets an 16-bit value for a given PCD token.\r
 \r
-  When the PCD service sets a value, it will check to ensure that the \r
-  size of the value being set is compatible with the Token's existing definition.  \r
+  When the PCD service sets a value, it will check to ensure that the\r
+  size of the value being set is compatible with the Token's existing definition.\r
   If it is not, an error will be returned.\r
 \r
-  @param[in]  TokenNumber The PCD token number. \r
+  @param[in]  TokenNumber The PCD token number.\r
   @param[in]  Value The value to set for the PCD token.\r
 \r
   @retval EFI_SUCCESS  Procedure returned successfully.\r
-  @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data \r
-                                  being set was incompatible with a call to this function.  \r
+  @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data\r
+                                  being set was incompatible with a call to this function.\r
                                   Use GetSize() to retrieve the size of the target data.\r
   @retval EFI_NOT_FOUND The PCD service could not find the requested token number.\r
-  \r
+\r
 **/\r
 EFI_STATUS\r
 EFIAPI\r
 PeiPcdSet16 (\r
-  IN UINTN                         TokenNumber,\r
-  IN UINT16                        Value\r
+  IN UINTN   TokenNumber,\r
+  IN UINT16  Value\r
   )\r
 {\r
   return SetValueWorker (TokenNumber, &Value, sizeof (Value));\r
@@ -674,25 +1047,25 @@ PeiPcdSet16 (
 /**\r
   Sets an 32-bit value for a given PCD token.\r
 \r
-  When the PCD service sets a value, it will check to ensure that the \r
-  size of the value being set is compatible with the Token's existing definition.  \r
+  When the PCD service sets a value, it will check to ensure that the\r
+  size of the value being set is compatible with the Token's existing definition.\r
   If it is not, an error will be returned.\r
 \r
-  @param[in]  TokenNumber The PCD token number. \r
+  @param[in]  TokenNumber The PCD token number.\r
   @param[in]  Value The value to set for the PCD token.\r
 \r
   @retval EFI_SUCCESS  Procedure returned successfully.\r
-  @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data \r
-                                  being set was incompatible with a call to this function.  \r
+  @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data\r
+                                  being set was incompatible with a call to this function.\r
                                   Use GetSize() to retrieve the size of the target data.\r
   @retval EFI_NOT_FOUND The PCD service could not find the requested token number.\r
-  \r
+\r
 **/\r
 EFI_STATUS\r
 EFIAPI\r
 PeiPcdSet32 (\r
-  IN UINTN                         TokenNumber,\r
-  IN UINT32                        Value\r
+  IN UINTN   TokenNumber,\r
+  IN UINT32  Value\r
   )\r
 {\r
   return SetValueWorker (TokenNumber, &Value, sizeof (Value));\r
@@ -701,25 +1074,25 @@ PeiPcdSet32 (
 /**\r
   Sets an 64-bit value for a given PCD token.\r
 \r
-  When the PCD service sets a value, it will check to ensure that the \r
-  size of the value being set is compatible with the Token's existing definition.  \r
+  When the PCD service sets a value, it will check to ensure that the\r
+  size of the value being set is compatible with the Token's existing definition.\r
   If it is not, an error will be returned.\r
 \r
-  @param[in]  TokenNumber The PCD token number. \r
+  @param[in]  TokenNumber The PCD token number.\r
   @param[in]  Value The value to set for the PCD token.\r
 \r
   @retval EFI_SUCCESS  Procedure returned successfully.\r
-  @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data \r
-                                  being set was incompatible with a call to this function.  \r
+  @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data\r
+                                  being set was incompatible with a call to this function.\r
                                   Use GetSize() to retrieve the size of the target data.\r
   @retval EFI_NOT_FOUND The PCD service could not find the requested token number.\r
-  \r
+\r
 **/\r
 EFI_STATUS\r
 EFIAPI\r
 PeiPcdSet64 (\r
-  IN UINTN                         TokenNumber,\r
-  IN UINT64                        Value\r
+  IN UINTN   TokenNumber,\r
+  IN UINT64  Value\r
   )\r
 {\r
   return SetValueWorker (TokenNumber, &Value, sizeof (Value));\r
@@ -728,30 +1101,30 @@ PeiPcdSet64 (
 /**\r
   Sets a value of a specified size for a given PCD token.\r
 \r
-  When the PCD service sets a value, it will check to ensure that the \r
-  size of the value being set is compatible with the Token's existing definition.  \r
+  When the PCD service sets a value, it will check to ensure that the\r
+  size of the value being set is compatible with the Token's existing definition.\r
   If it is not, an error will be returned.\r
 \r
-  @param[in]  TokenNumber The PCD token number. \r
-  @param[in, out] SizeOfBuffer A pointer to the length of the value being set for the PCD token.  \r
-                              On input, if the SizeOfValue is greater than the maximum size supported \r
-                              for this TokenNumber then the output value of SizeOfValue will reflect \r
+  @param[in]  TokenNumber The PCD token number.\r
+  @param[in, out] SizeOfBuffer A pointer to the length of the value being set for the PCD token.\r
+                              On input, if the SizeOfValue is greater than the maximum size supported\r
+                              for this TokenNumber then the output value of SizeOfValue will reflect\r
                               the maximum size supported for this TokenNumber.\r
   @param[in]  Buffer The buffer to set for the PCD token.\r
 \r
   @retval EFI_SUCCESS  Procedure returned successfully.\r
-  @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data \r
-                                  being set was incompatible with a call to this function.  \r
+  @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data\r
+                                  being set was incompatible with a call to this function.\r
                                   Use GetSize() to retrieve the size of the target data.\r
   @retval EFI_NOT_FOUND The PCD service could not find the requested token number.\r
-  \r
+\r
 **/\r
 EFI_STATUS\r
 EFIAPI\r
 PeiPcdSetPtr (\r
-  IN      UINTN                    TokenNumber,\r
-  IN OUT  UINTN                    *SizeOfBuffer,\r
-  IN      VOID                     *Buffer\r
+  IN      UINTN  TokenNumber,\r
+  IN OUT  UINTN  *SizeOfBuffer,\r
+  IN      VOID   *Buffer\r
   )\r
 {\r
   return SetWorker (TokenNumber, Buffer, SizeOfBuffer, TRUE);\r
@@ -760,25 +1133,25 @@ PeiPcdSetPtr (
 /**\r
   Sets an Boolean value for a given PCD token.\r
 \r
-  When the PCD service sets a value, it will check to ensure that the \r
-  size of the value being set is compatible with the Token's existing definition.  \r
+  When the PCD service sets a value, it will check to ensure that the\r
+  size of the value being set is compatible with the Token's existing definition.\r
   If it is not, an error will be returned.\r
 \r
-  @param[in]  TokenNumber The PCD token number. \r
+  @param[in]  TokenNumber The PCD token number.\r
   @param[in]  Value The value to set for the PCD token.\r
 \r
   @retval EFI_SUCCESS  Procedure returned successfully.\r
-  @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data \r
-                                  being set was incompatible with a call to this function.  \r
+  @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data\r
+                                  being set was incompatible with a call to this function.\r
                                   Use GetSize() to retrieve the size of the target data.\r
   @retval EFI_NOT_FOUND The PCD service could not find the requested token number.\r
-  \r
+\r
 **/\r
 EFI_STATUS\r
 EFIAPI\r
 PeiPcdSetBool (\r
-  IN UINTN                         TokenNumber,\r
-  IN BOOLEAN                       Value\r
+  IN UINTN    TokenNumber,\r
+  IN BOOLEAN  Value\r
   )\r
 {\r
   return SetValueWorker (TokenNumber, &Value, sizeof (Value));\r
@@ -787,27 +1160,27 @@ PeiPcdSetBool (
 /**\r
   Sets an 8-bit value for a given PCD token.\r
 \r
-  When the PCD service sets a value, it will check to ensure that the \r
-  size of the value being set is compatible with the Token's existing definition.  \r
+  When the PCD service sets a value, it will check to ensure that the\r
+  size of the value being set is compatible with the Token's existing definition.\r
   If it is not, an error will be returned.\r
 \r
   @param[in]  Guid          The 128-bit unique value that designates the namespace from which to extract the value.\r
-  @param[in]  ExTokenNumber The PCD token number. \r
+  @param[in]  ExTokenNumber The PCD token number.\r
   @param[in]  Value         The value to set for the PCD token.\r
 \r
   @retval EFI_SUCCESS  Procedure returned successfully.\r
-  @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data \r
-                                  being set was incompatible with a call to this function.  \r
+  @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data\r
+                                  being set was incompatible with a call to this function.\r
                                   Use GetSize() to retrieve the size of the target data.\r
   @retval EFI_NOT_FOUND The PCD service could not find the requested token number.\r
-  \r
+\r
 **/\r
 EFI_STATUS\r
 EFIAPI\r
 PeiPcdSet8Ex (\r
-  IN CONST EFI_GUID               *Guid,\r
-  IN UINTN                        ExTokenNumber,\r
-  IN UINT8                        Value\r
+  IN CONST EFI_GUID  *Guid,\r
+  IN UINTN           ExTokenNumber,\r
+  IN UINT8           Value\r
   )\r
 {\r
   return ExSetValueWorker (ExTokenNumber, Guid, &Value, sizeof (Value));\r
@@ -816,27 +1189,27 @@ PeiPcdSet8Ex (
 /**\r
   Sets an 16-bit value for a given PCD token.\r
 \r
-  When the PCD service sets a value, it will check to ensure that the \r
-  size of the value being set is compatible with the Token's existing definition.  \r
+  When the PCD service sets a value, it will check to ensure that the\r
+  size of the value being set is compatible with the Token's existing definition.\r
   If it is not, an error will be returned.\r
 \r
   @param[in]  Guid The 128-bit unique value that designates the namespace from which to extract the value.\r
-  @param[in]  ExTokenNumber The PCD token number. \r
+  @param[in]  ExTokenNumber The PCD token number.\r
   @param[in]  Value The value to set for the PCD token.\r
 \r
   @retval EFI_SUCCESS  Procedure returned successfully.\r
-  @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data \r
-                                  being set was incompatible with a call to this function.  \r
+  @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data\r
+                                  being set was incompatible with a call to this function.\r
                                   Use GetSize() to retrieve the size of the target data.\r
   @retval EFI_NOT_FOUND The PCD service could not find the requested token number.\r
-  \r
+\r
 **/\r
 EFI_STATUS\r
 EFIAPI\r
 PeiPcdSet16Ex (\r
-  IN CONST EFI_GUID               *Guid,\r
-  IN UINTN                        ExTokenNumber,\r
-  IN UINT16                       Value\r
+  IN CONST EFI_GUID  *Guid,\r
+  IN UINTN           ExTokenNumber,\r
+  IN UINT16          Value\r
   )\r
 {\r
   return ExSetValueWorker (ExTokenNumber, Guid, &Value, sizeof (Value));\r
@@ -845,27 +1218,27 @@ PeiPcdSet16Ex (
 /**\r
   Sets an 32-bit value for a given PCD token.\r
 \r
-  When the PCD service sets a value, it will check to ensure that the \r
-  size of the value being set is compatible with the Token's existing definition.  \r
+  When the PCD service sets a value, it will check to ensure that the\r
+  size of the value being set is compatible with the Token's existing definition.\r
   If it is not, an error will be returned.\r
 \r
   @param[in]  Guid          The 128-bit unique value that designates the namespace from which to extract the value.\r
-  @param[in]  ExTokenNumber The PCD token number. \r
+  @param[in]  ExTokenNumber The PCD token number.\r
   @param[in]  Value         The value to set for the PCD token.\r
 \r
   @retval EFI_SUCCESS  Procedure returned successfully.\r
-  @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data \r
-                                  being set was incompatible with a call to this function.  \r
+  @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data\r
+                                  being set was incompatible with a call to this function.\r
                                   Use GetSize() to retrieve the size of the target data.\r
   @retval EFI_NOT_FOUND The PCD service could not find the requested token number.\r
-  \r
+\r
 **/\r
 EFI_STATUS\r
 EFIAPI\r
 PeiPcdSet32Ex (\r
-  IN CONST EFI_GUID               *Guid,\r
-  IN UINTN                        ExTokenNumber,\r
-  IN UINT32                       Value\r
+  IN CONST EFI_GUID  *Guid,\r
+  IN UINTN           ExTokenNumber,\r
+  IN UINT32          Value\r
   )\r
 {\r
   return ExSetValueWorker (ExTokenNumber, Guid, &Value, sizeof (Value));\r
@@ -874,27 +1247,27 @@ PeiPcdSet32Ex (
 /**\r
   Sets an 64-bit value for a given PCD token.\r
 \r
-  When the PCD service sets a value, it will check to ensure that the \r
-  size of the value being set is compatible with the Token's existing definition.  \r
+  When the PCD service sets a value, it will check to ensure that the\r
+  size of the value being set is compatible with the Token's existing definition.\r
   If it is not, an error will be returned.\r
 \r
   @param[in]  Guid          The 128-bit unique value that designates the namespace from which to extract the value.\r
-  @param[in]  ExTokenNumber The PCD token number. \r
+  @param[in]  ExTokenNumber The PCD token number.\r
   @param[in]  Value         The value to set for the PCD token.\r
 \r
   @retval EFI_SUCCESS  Procedure returned successfully.\r
-  @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data \r
-                                  being set was incompatible with a call to this function.  \r
+  @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data\r
+                                  being set was incompatible with a call to this function.\r
                                   Use GetSize() to retrieve the size of the target data.\r
   @retval EFI_NOT_FOUND The PCD service could not find the requested token number.\r
-  \r
+\r
 **/\r
 EFI_STATUS\r
 EFIAPI\r
 PeiPcdSet64Ex (\r
-  IN CONST EFI_GUID               *Guid,\r
-  IN UINTN                        ExTokenNumber,\r
-  IN UINT64                       Value\r
+  IN CONST EFI_GUID  *Guid,\r
+  IN UINTN           ExTokenNumber,\r
+  IN UINT64          Value\r
   )\r
 {\r
   return ExSetValueWorker (ExTokenNumber, Guid, &Value, sizeof (Value));\r
@@ -903,32 +1276,32 @@ PeiPcdSet64Ex (
 /**\r
   Sets a value of a specified size for a given PCD token.\r
 \r
-  When the PCD service sets a value, it will check to ensure that the \r
-  size of the value being set is compatible with the Token's existing definition.  \r
+  When the PCD service sets a value, it will check to ensure that the\r
+  size of the value being set is compatible with the Token's existing definition.\r
   If it is not, an error will be returned.\r
 \r
   @param[in]        Guid            The 128-bit unique value that designates the namespace from which to extract the value.\r
-  @param[in]        ExTokenNumber   The PCD token number. \r
-  @param[in, out]   SizeOfBuffer    A pointer to the length of the value being set for the PCD token.  \r
-                                    On input, if the SizeOfValue is greater than the maximum size supported \r
-                                    for this TokenNumber then the output value of SizeOfValue will reflect \r
+  @param[in]        ExTokenNumber   The PCD token number.\r
+  @param[in, out]   SizeOfBuffer    A pointer to the length of the value being set for the PCD token.\r
+                                    On input, if the SizeOfValue is greater than the maximum size supported\r
+                                    for this TokenNumber then the output value of SizeOfValue will reflect\r
                                     the maximum size supported for this TokenNumber.\r
   @param[in]        Value           The buffer to set for the PCD token.\r
 \r
   @retval EFI_SUCCESS  Procedure returned successfully.\r
-  @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data \r
-                                  being set was incompatible with a call to this function.  \r
+  @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data\r
+                                  being set was incompatible with a call to this function.\r
                                   Use GetSize() to retrieve the size of the target data.\r
   @retval EFI_NOT_FOUND The PCD service could not find the requested token number.\r
-  \r
+\r
 **/\r
 EFI_STATUS\r
 EFIAPI\r
 PeiPcdSetPtrEx (\r
-  IN     CONST EFI_GUID               *Guid,\r
-  IN     UINTN                        ExTokenNumber,\r
-  IN OUT UINTN                        *SizeOfBuffer,\r
-  IN     VOID                         *Value\r
+  IN     CONST EFI_GUID  *Guid,\r
+  IN     UINTN           ExTokenNumber,\r
+  IN OUT UINTN           *SizeOfBuffer,\r
+  IN     VOID            *Value\r
   )\r
 {\r
   return ExSetWorker (ExTokenNumber, Guid, Value, SizeOfBuffer, TRUE);\r
@@ -937,27 +1310,27 @@ PeiPcdSetPtrEx (
 /**\r
   Sets an Boolean value for a given PCD token.\r
 \r
-  When the PCD service sets a value, it will check to ensure that the \r
-  size of the value being set is compatible with the Token's existing definition.  \r
+  When the PCD service sets a value, it will check to ensure that the\r
+  size of the value being set is compatible with the Token's existing definition.\r
   If it is not, an error will be returned.\r
 \r
   @param [in]  Guid          The 128-bit unique value that designates the namespace from which to extract the value.\r
-  @param [in]  ExTokenNumber The PCD token number. \r
+  @param [in]  ExTokenNumber The PCD token number.\r
   @param [in]  Value         The value to set for the PCD token.\r
 \r
   @retval EFI_SUCCESS  Procedure returned successfully.\r
-  @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data \r
-                                  being set was incompatible with a call to this function.  \r
+  @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data\r
+                                  being set was incompatible with a call to this function.\r
                                   Use GetSize() to retrieve the size of the target data.\r
   @retval EFI_NOT_FOUND The PCD service could not find the requested token number.\r
-  \r
+\r
 **/\r
 EFI_STATUS\r
 EFIAPI\r
 PeiPcdSetBoolEx (\r
-  IN CONST EFI_GUID             *Guid,\r
-  IN UINTN                      ExTokenNumber,\r
-  IN BOOLEAN                    Value\r
+  IN CONST EFI_GUID  *Guid,\r
+  IN UINTN           ExTokenNumber,\r
+  IN BOOLEAN         Value\r
   )\r
 {\r
   return ExSetValueWorker (ExTokenNumber, Guid, &Value, sizeof (Value));\r
@@ -967,10 +1340,10 @@ PeiPcdSetBoolEx (
   Specifies a function to be called anytime the value of a designated token is changed.\r
 \r
   @param[in]  Guid The 128-bit unique value that designates the namespace from which to extract the value.\r
-  @param[in]  ExTokenNumber The PCD token number. \r
-  @param[in]  CallBackFunction The function prototype called when the value associated with the CallBackToken is set.  \r
+  @param[in]  ExTokenNumber The PCD token number.\r
+  @param[in]  CallBackFunction The function prototype called when the value associated with the CallBackToken is set.\r
 \r
-  @retval EFI_SUCCESS  The PCD service has successfully established a call event \r
+  @retval EFI_SUCCESS  The PCD service has successfully established a call event\r
                         for the CallBackToken requested.\r
   @retval EFI_NOT_FOUND The PCD service could not find the referenced token number.\r
 \r
@@ -978,12 +1351,12 @@ PeiPcdSetBoolEx (
 EFI_STATUS\r
 EFIAPI\r
 PeiRegisterCallBackOnSet (\r
-  IN  CONST EFI_GUID              *Guid, OPTIONAL\r
-  IN  UINTN                       ExTokenNumber,\r
-  IN  PCD_PPI_CALLBACK            CallBackFunction\r
+  IN  CONST EFI_GUID    *Guid  OPTIONAL,\r
+  IN  UINTN             ExTokenNumber,\r
+  IN  PCD_PPI_CALLBACK  CallBackFunction\r
   )\r
 {\r
-  if (!FeaturePcdGet(PcdPeiFullPcdDatabaseEnable)) {\r
+  if (!FeaturePcdGet (PcdPeiFullPcdDatabaseEnable)) {\r
     return EFI_UNSUPPORTED;\r
   }\r
 \r
@@ -998,10 +1371,10 @@ PeiRegisterCallBackOnSet (
   Cancels a previously set callback function for a particular PCD token number.\r
 \r
   @param[in]  Guid The 128-bit unique value that designates the namespace from which to extract the value.\r
-  @param[in]  ExTokenNumber The PCD token number. \r
-  @param[in]  CallBackFunction The function prototype called when the value associated with the CallBackToken is set.  \r
+  @param[in]  ExTokenNumber The PCD token number.\r
+  @param[in]  CallBackFunction The function prototype called when the value associated with the CallBackToken is set.\r
 \r
-  @retval EFI_SUCCESS  The PCD service has successfully established a call event \r
+  @retval EFI_SUCCESS  The PCD service has successfully established a call event\r
                         for the CallBackToken requested.\r
   @retval EFI_NOT_FOUND The PCD service could not find the referenced token number.\r
 \r
@@ -1009,12 +1382,12 @@ PeiRegisterCallBackOnSet (
 EFI_STATUS\r
 EFIAPI\r
 PcdUnRegisterCallBackOnSet (\r
-  IN  CONST EFI_GUID              *Guid, OPTIONAL\r
-  IN  UINTN                       ExTokenNumber,\r
-  IN  PCD_PPI_CALLBACK            CallBackFunction\r
+  IN  CONST EFI_GUID    *Guid  OPTIONAL,\r
+  IN  UINTN             ExTokenNumber,\r
+  IN  PCD_PPI_CALLBACK  CallBackFunction\r
   )\r
 {\r
-  if (!FeaturePcdGet(PcdPeiFullPcdDatabaseEnable)) {\r
+  if (!FeaturePcdGet (PcdPeiFullPcdDatabaseEnable)) {\r
     return EFI_UNSUPPORTED;\r
   }\r
 \r
@@ -1026,26 +1399,26 @@ PcdUnRegisterCallBackOnSet (
 }\r
 \r
 /**\r
-  Retrieves the next valid token number in a given namespace.  \r
-  \r
-  This is useful since the PCD infrastructure contains a sparse list of token numbers, \r
-  and one cannot a priori know what token numbers are valid in the database. \r
-  \r
-  If TokenNumber is 0 and Guid is not NULL, then the first token from the token space specified by Guid is returned.  \r
-  If TokenNumber is not 0 and Guid is not NULL, then the next token in the token space specified by Guid is returned.  \r
-  If TokenNumber is 0 and Guid is NULL, then the first token in the default token space is returned.  \r
-  If TokenNumber is not 0 and Guid is NULL, then the next token in the default token space is returned.  \r
-  The token numbers in the default token space may not be related to token numbers in token spaces that are named by Guid.  \r
-  If the next token number can be retrieved, then it is returned in TokenNumber, and EFI_SUCCESS is returned.  \r
-  If TokenNumber represents the last token number in the token space specified by Guid, then EFI_NOT_FOUND is returned.  \r
+  Retrieves the next valid token number in a given namespace.\r
+\r
+  This is useful since the PCD infrastructure contains a sparse list of token numbers,\r
+  and one cannot a priori know what token numbers are valid in the database.\r
+\r
+  If TokenNumber is 0 and Guid is not NULL, then the first token from the token space specified by Guid is returned.\r
+  If TokenNumber is not 0 and Guid is not NULL, then the next token in the token space specified by Guid is returned.\r
+  If TokenNumber is 0 and Guid is NULL, then the first token in the default token space is returned.\r
+  If TokenNumber is not 0 and Guid is NULL, then the next token in the default token space is returned.\r
+  The token numbers in the default token space may not be related to token numbers in token spaces that are named by Guid.\r
+  If the next token number can be retrieved, then it is returned in TokenNumber, and EFI_SUCCESS is returned.\r
+  If TokenNumber represents the last token number in the token space specified by Guid, then EFI_NOT_FOUND is returned.\r
   If TokenNumber is not present in the token space specified by Guid, then EFI_NOT_FOUND is returned.\r
 \r
 \r
-  @param[in]       Guid        The 128-bit unique value that designates the namespace from which to extract the value.  \r
-                               This is an optional parameter that may be NULL.  If this parameter is NULL, then a request \r
+  @param[in]       Guid        The 128-bit unique value that designates the namespace from which to extract the value.\r
+                               This is an optional parameter that may be NULL.  If this parameter is NULL, then a request\r
                                is being made to retrieve tokens from the default token space.\r
   @param[in, out]  TokenNumber A pointer to the PCD token number to use to find the subsequent token number.\r
-                   \r
+\r
   @retval EFI_SUCCESS   The PCD service has retrieved the next valid token number.\r
   @retval EFI_NOT_FOUND The PCD service could not find data from the requested token number.\r
 \r
@@ -1053,19 +1426,19 @@ PcdUnRegisterCallBackOnSet (
 EFI_STATUS\r
 EFIAPI\r
 PeiPcdGetNextToken (\r
-  IN CONST EFI_GUID               *Guid, OPTIONAL\r
-  IN OUT  UINTN                   *TokenNumber\r
+  IN CONST EFI_GUID  *Guid  OPTIONAL,\r
+  IN OUT  UINTN      *TokenNumber\r
   )\r
 {\r
-  UINTN               GuidTableIdx;\r
-  PEI_PCD_DATABASE    *PeiPcdDb;\r
-  EFI_GUID            *MatchGuid;\r
-  EFI_GUID            *GuidTable;\r
-  DYNAMICEX_MAPPING   *ExMapTable;\r
-  UINTN               Index;\r
-  BOOLEAN             Found;\r
-  BOOLEAN             PeiExMapTableEmpty;\r
-  UINTN               PeiNexTokenNumber; \r
+  UINTN              GuidTableIdx;\r
+  PEI_PCD_DATABASE   *PeiPcdDb;\r
+  EFI_GUID           *MatchGuid;\r
+  EFI_GUID           *GuidTable;\r
+  DYNAMICEX_MAPPING  *ExMapTable;\r
+  UINTN              Index;\r
+  BOOLEAN            Found;\r
+  BOOLEAN            PeiExMapTableEmpty;\r
+  UINTN              PeiNexTokenNumber;\r
 \r
   if (!FeaturePcdGet (PcdPeiFullPcdDatabaseEnable)) {\r
     return EFI_UNSUPPORTED;\r
@@ -1080,22 +1453,25 @@ PeiPcdGetNextToken (
   } else {\r
     PeiExMapTableEmpty = FALSE;\r
   }\r
+\r
   if (Guid == NULL) {\r
     if (*TokenNumber > PeiNexTokenNumber) {\r
       return EFI_NOT_FOUND;\r
     }\r
+\r
     (*TokenNumber)++;\r
     if (*TokenNumber > PeiNexTokenNumber) {\r
       *TokenNumber = PCD_INVALID_TOKEN_NUMBER;\r
       return EFI_NOT_FOUND;\r
     }\r
+\r
     return EFI_SUCCESS;\r
   } else {\r
     if (PeiExMapTableEmpty) {\r
       return EFI_NOT_FOUND;\r
     }\r
 \r
-    MatchGuid = ScanGuid (GuidTable, PeiPcdDb->GuidTableCount * sizeof(EFI_GUID), Guid);\r
+    MatchGuid = ScanGuid (GuidTable, PeiPcdDb->GuidTableCount * sizeof (EFI_GUID), Guid);\r
 \r
     if (MatchGuid == NULL) {\r
       return EFI_NOT_FOUND;\r
@@ -1123,7 +1499,7 @@ PeiPcdGetNextToken (
       //\r
       if (*TokenNumber == PCD_INVALID_TOKEN_NUMBER) {\r
         *TokenNumber = ExMapTable[Index].ExTokenNumber;\r
-         return EFI_SUCCESS;\r
+        return EFI_SUCCESS;\r
       }\r
 \r
       for ( ; Index < PeiPcdDb->ExTokenCount; Index++) {\r
@@ -1165,7 +1541,7 @@ PeiPcdGetNextToken (
                             token namespace on the platform. If *Guid is NULL, then the GUID of the first token\r
                             space of the current platform is returned. If the search cannot locate the next valid\r
                             token namespace, an error is returned and the value of *Guid is undefined.\r
\r
+\r
   @retval  EFI_SUCCESS      The PCD service retrieved the value requested.\r
   @retval  EFI_NOT_FOUND    The PCD service could not find the next valid token namespace.\r
 \r
@@ -1173,18 +1549,18 @@ PeiPcdGetNextToken (
 EFI_STATUS\r
 EFIAPI\r
 PeiPcdGetNextTokenSpace (\r
-  IN OUT CONST EFI_GUID          **Guid\r
+  IN OUT CONST EFI_GUID  **Guid\r
   )\r
 {\r
-  UINTN               GuidTableIdx;\r
-  EFI_GUID            *MatchGuid;\r
-  PEI_PCD_DATABASE    *PeiPcdDb;\r
-  DYNAMICEX_MAPPING   *ExMapTable;\r
-  UINTN               Index;\r
-  UINTN               Index2;\r
-  BOOLEAN             Found;\r
-  BOOLEAN             PeiExMapTableEmpty;\r
-  EFI_GUID            *GuidTable;\r
+  UINTN              GuidTableIdx;\r
+  EFI_GUID           *MatchGuid;\r
+  PEI_PCD_DATABASE   *PeiPcdDb;\r
+  DYNAMICEX_MAPPING  *ExMapTable;\r
+  UINTN              Index;\r
+  UINTN              Index2;\r
+  BOOLEAN            Found;\r
+  BOOLEAN            PeiExMapTableEmpty;\r
+  EFI_GUID           *GuidTable;\r
 \r
   if (!FeaturePcdGet (PcdPeiFullPcdDatabaseEnable)) {\r
     return EFI_UNSUPPORTED;\r
@@ -1199,14 +1575,14 @@ PeiPcdGetNextTokenSpace (
   } else {\r
     PeiExMapTableEmpty = FALSE;\r
   }\r
-  \r
+\r
   if (PeiExMapTableEmpty) {\r
     return EFI_NOT_FOUND;\r
   }\r
 \r
   ExMapTable = (DYNAMICEX_MAPPING *)((UINT8 *)PeiPcdDb + PeiPcdDb->ExMapTableOffset);\r
   GuidTable  = (EFI_GUID *)((UINT8 *)PeiPcdDb + PeiPcdDb->GuidTableOffset);\r
-  \r
+\r
   if (*Guid == NULL) {\r
     //\r
     // return the first Token Space Guid.\r
@@ -1215,12 +1591,12 @@ PeiPcdGetNextTokenSpace (
     return EFI_SUCCESS;\r
   }\r
 \r
-  MatchGuid = ScanGuid (GuidTable, PeiPcdDb->GuidTableCount * sizeof(GuidTable[0]), *Guid);\r
+  MatchGuid = ScanGuid (GuidTable, PeiPcdDb->GuidTableCount * sizeof (GuidTable[0]), *Guid);\r
 \r
   if (MatchGuid == NULL) {\r
     return EFI_NOT_FOUND;\r
   }\r
-  \r
+\r
   GuidTableIdx = MatchGuid - GuidTable;\r
 \r
   Found = FALSE;\r
@@ -1236,7 +1612,7 @@ PeiPcdGetNextTokenSpace (
     for ( ; Index < PeiPcdDb->ExTokenCount; Index++ ) {\r
       if (ExMapTable[Index].ExGuidIndex != GuidTableIdx) {\r
         Found = FALSE;\r
-        for (Index2 = 0 ; Index2 < Index; Index2++) {\r
+        for (Index2 = 0; Index2 < Index; Index2++) {\r
           if (ExMapTable[Index2].ExGuidIndex == ExMapTable[Index].ExGuidIndex) {\r
             //\r
             // This token namespace should have been found and output at preceding getting.\r
@@ -1245,22 +1621,23 @@ PeiPcdGetNextTokenSpace (
             break;\r
           }\r
         }\r
+\r
         if (!Found) {\r
           *Guid = (EFI_GUID *)((UINT8 *)PeiPcdDb + PeiPcdDb->GuidTableOffset) + ExMapTable[Index].ExGuidIndex;\r
           return EFI_SUCCESS;\r
         }\r
       }\r
     }\r
+\r
     *Guid = NULL;\r
   }\r
 \r
   return EFI_NOT_FOUND;\r
-\r
 }\r
 \r
 /**\r
   Get PCD value's size for POINTER type PCD.\r
-  \r
+\r
   The POINTER type PCD's value will be stored into a buffer in specified size.\r
   The max size of this PCD's value is described in PCD's definition in DEC file.\r
 \r
@@ -1278,61 +1655,44 @@ GetPtrTypeSize (
   IN    PEI_PCD_DATABASE  *Database\r
   )\r
 {\r
-  INTN        SizeTableIdx;\r
-  UINTN       LocalTokenNumber;\r
-  SKU_ID      *SkuIdTable;\r
-  SIZE_INFO   *SizeTable;\r
-  UINTN       Index;\r
+  INTN       SizeTableIdx;\r
+  UINTN      LocalTokenNumber;\r
+  SIZE_INFO  *SizeTable;\r
 \r
   SizeTableIdx = GetSizeTableIndex (LocalTokenNumberTableIdx, Database);\r
 \r
   LocalTokenNumber = *((UINT32 *)((UINT8 *)Database + Database->LocalTokenNumberTableOffset) + LocalTokenNumberTableIdx);\r
 \r
   ASSERT ((LocalTokenNumber & PCD_DATUM_TYPE_ALL_SET) == PCD_DATUM_TYPE_POINTER);\r
-  \r
+\r
   SizeTable = (SIZE_INFO *)((UINT8 *)Database + Database->SizeTableOffset);\r
 \r
   *MaxSize = SizeTable[SizeTableIdx];\r
   //\r
-  // SizeTable only contain record for PCD_DATUM_TYPE_POINTER type \r
+  // SizeTable only contain record for PCD_DATUM_TYPE_POINTER type\r
   // PCD entry.\r
   //\r
   if ((LocalTokenNumber & PCD_TYPE_VPD) != 0) {\r
-      //\r
-      // We have only two entry for VPD enabled PCD entry:\r
-      // 1) MAX Size.\r
-      // 2) Current Size\r
-      // We consider current size is equal to MAX size.\r
-      //\r
-      return *MaxSize;\r
+    //\r
+    // We have only two entry for VPD enabled PCD entry:\r
+    // 1) MAX Size.\r
+    // 2) Current Size\r
+    // We consider current size is equal to MAX size.\r
+    //\r
+    return *MaxSize;\r
   } else {\r
-    if ((LocalTokenNumber & PCD_TYPE_SKU_ENABLED) == 0) {\r
-      //\r
-      // We have only two entry for Non-Sku enabled PCD entry:\r
-      // 1) MAX SIZE\r
-      // 2) Current Size\r
-      //\r
-      return SizeTable[SizeTableIdx + 1];\r
-    } else {\r
-      //\r
-      // We have these entry for SKU enabled PCD entry\r
-      // 1) MAX SIZE\r
-      // 2) Current Size for each SKU_ID (It is equal to MaxSku).\r
-      //\r
-      SkuIdTable = GetSkuIdArray (LocalTokenNumberTableIdx, Database);\r
-      for (Index = 0; Index < SkuIdTable[0]; Index++) {\r
-        if (SkuIdTable[1 + Index] == Database->SystemSkuId) {\r
-          return SizeTable[SizeTableIdx + 1 + Index];\r
-        }\r
-      }\r
-      return SizeTable[SizeTableIdx + 1];\r
-    }\r
+    //\r
+    // We have only two entry for Non-Sku enabled PCD entry:\r
+    // 1) MAX SIZE\r
+    // 2) Current Size\r
+    //\r
+    return SizeTable[SizeTableIdx + 1];\r
   }\r
 }\r
 \r
 /**\r
   Set PCD value's size for POINTER type PCD.\r
-  \r
+\r
   The POINTER type PCD's value will be stored into a buffer in specified size.\r
   The max size of this PCD's value is described in PCD's definition in DEC file.\r
 \r
@@ -1351,13 +1711,11 @@ SetPtrTypeSize (
   IN          PEI_PCD_DATABASE  *Database\r
   )\r
 {\r
-  INTN        SizeTableIdx;\r
-  UINTN       LocalTokenNumber;\r
-  SKU_ID      *SkuIdTable;\r
-  SIZE_INFO   *SizeTable;\r
-  UINTN       Index;\r
-  UINTN       MaxSize;\r
-  \r
+  INTN       SizeTableIdx;\r
+  UINTN      LocalTokenNumber;\r
+  SIZE_INFO  *SizeTable;\r
+  UINTN      MaxSize;\r
+\r
   SizeTableIdx = GetSizeTableIndex (LocalTokenNumberTableIdx, Database);\r
 \r
   LocalTokenNumber = *((UINT32 *)((UINT8 *)Database + Database->LocalTokenNumberTableOffset) + LocalTokenNumberTableIdx);\r
@@ -1368,46 +1726,29 @@ SetPtrTypeSize (
 \r
   MaxSize = SizeTable[SizeTableIdx];\r
   //\r
-  // SizeTable only contain record for PCD_DATUM_TYPE_POINTER type \r
+  // SizeTable only contain record for PCD_DATUM_TYPE_POINTER type\r
   // PCD entry.\r
   //\r
   if ((LocalTokenNumber & PCD_TYPE_VPD) != 0) {\r
-      //\r
-      // We shouldn't come here as we don't support SET for VPD\r
-      //\r
-      ASSERT (FALSE);\r
-      return FALSE;\r
+    //\r
+    // We shouldn't come here as we don't support SET for VPD\r
+    //\r
+    ASSERT (FALSE);\r
+    return FALSE;\r
   } else {\r
     if ((*CurrentSize > MaxSize) ||\r
-      (*CurrentSize == MAX_ADDRESS)) {\r
-       *CurrentSize = MaxSize;\r
-       return FALSE;\r
-    }\r
-    \r
-    if ((LocalTokenNumber & PCD_TYPE_SKU_ENABLED) == 0) {\r
-      //\r
-      // We have only two entry for Non-Sku enabled PCD entry:\r
-      // 1) MAX SIZE\r
-      // 2) Current Size\r
-      //\r
-      SizeTable[SizeTableIdx + 1] = (SIZE_INFO) *CurrentSize;\r
-      return TRUE;\r
-    } else {\r
-      //\r
-      // We have these entry for SKU enabled PCD entry\r
-      // 1) MAX SIZE\r
-      // 2) Current Size for each SKU_ID (It is equal to MaxSku).\r
-      //\r
-      SkuIdTable = GetSkuIdArray (LocalTokenNumberTableIdx, Database);\r
-      for (Index = 0; Index < SkuIdTable[0]; Index++) {\r
-        if (SkuIdTable[1 + Index] == Database->SystemSkuId) {\r
-          SizeTable[SizeTableIdx + 1 + Index] = (SIZE_INFO) *CurrentSize;\r
-          return TRUE;\r
-        }\r
-      }\r
-      SizeTable[SizeTableIdx + 1] = (SIZE_INFO) *CurrentSize;\r
-      return TRUE;\r
+        (*CurrentSize == MAX_ADDRESS))\r
+    {\r
+      *CurrentSize = MaxSize;\r
+      return FALSE;\r
     }\r
-  }\r
 \r
+    //\r
+    // We have only two entry for Non-Sku enabled PCD entry:\r
+    // 1) MAX SIZE\r
+    // 2) Current Size\r
+    //\r
+    SizeTable[SizeTableIdx + 1] = (SIZE_INFO)*CurrentSize;\r
+    return TRUE;\r
+  }\r
 }\r