]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdePkg/Library/PeiPcdLib/PeiPcdLib.c
MdePkg PcdLib: Follow the comment of LibPcdGetNextToken to ASSERT when an invalid...
[mirror_edk2.git] / MdePkg / Library / PeiPcdLib / PeiPcdLib.c
index 4d91799025a46ccc346dacfc1068b6a49e3799d0..31ff457fc8f7823cfc3b4d103298b3b9054f7ed4 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
 Implementation of PcdLib class library for PEI phase.\r
 \r
-Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2006 - 2013, Intel Corporation. All rights reserved.<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
@@ -20,6 +20,8 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 \r
 #include <Ppi/Pcd.h>\r
 #include <Ppi/PiPcd.h>\r
+#include <Ppi/PcdInfo.h>\r
+#include <Ppi/PiPcdInfo.h>\r
 \r
 #include <Library/PeiServicesLib.h>\r
 #include <Library/PcdLib.h>\r
@@ -71,7 +73,53 @@ GetPiPcdPpiPointer (
   \r
   return PiPcdPpi;\r
 }  \r
+\r
+/**\r
+  Retrieve the GET_PCD_INFO_PPI pointer.\r
+\r
+  This function is to locate GET_PCD_INFO_PPI PPI via PeiService. \r
+  If fail to locate GET_PCD_INFO_PPI, then ASSERT_EFI_ERROR().\r
+\r
+  @retval GET_PCD_INFO_PPI * The pointer to the GET_PCD_INFO_PPI.\r
+\r
+**/\r
+GET_PCD_INFO_PPI *\r
+GetPcdInfoPpiPointer (\r
+  VOID\r
+  ) \r
+{\r
+  EFI_STATUS            Status;\r
+  GET_PCD_INFO_PPI      *PcdInfoPpi;\r
   \r
+  Status = PeiServicesLocatePpi (&gGetPcdInfoPpiGuid, 0, NULL, (VOID **)&PcdInfoPpi);\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  return PcdInfoPpi;\r
+}\r
+\r
+/**\r
+  Retrieve the pointer of EFI_GET_PCD_INFO_PPI defined in PI 1.2.1 Vol 3.\r
+\r
+  This function is to locate EFI_GET_PCD_INFO_PPI PPI via PeiService. \r
+  If fail to locate EFI_GET_PCD_INFO_PPI, then ASSERT_EFI_ERROR().\r
+\r
+  @retval EFI_GET_PCD_INFO_PPI * The pointer to the EFI_GET_PCD_INFO_PPI.\r
+\r
+**/\r
+EFI_GET_PCD_INFO_PPI *\r
+GetPiPcdInfoPpiPointer (\r
+  VOID\r
+  )\r
+{\r
+  EFI_STATUS            Status;\r
+  EFI_GET_PCD_INFO_PPI  *PiPcdInfoPpi;\r
+  \r
+  Status = PeiServicesLocatePpi (&gEfiGetPcdInfoPpiGuid, 0, NULL, (VOID **)&PiPcdInfoPpi);\r
+  ASSERT_EFI_ERROR (Status);\r
+  \r
+  return PiPcdInfoPpi;\r
+}  \r
+\r
 /**\r
   This function provides a means by which SKU support can be established in the PCD infrastructure.\r
 \r
@@ -962,11 +1010,10 @@ LibPcdGetNextToken (
   IN UINTN                    TokenNumber\r
   )\r
 {\r
-  EFI_STATUS Status;\r
+  EFI_STATUS    Status;\r
 \r
   Status = (GetPiPcdPpiPointer ())->GetNextToken (Guid, &TokenNumber);\r
-\r
-  ASSERT_EFI_ERROR (Status);\r
+  ASSERT (!EFI_ERROR (Status) || TokenNumber == 0);\r
 \r
   return TokenNumber;\r
 }\r
@@ -991,11 +1038,7 @@ LibPcdGetNextTokenSpace (
   IN CONST GUID  *TokenSpaceGuid\r
   )\r
 {\r
-  EFI_STATUS Status;\r
-\r
-  Status = (GetPiPcdPpiPointer ())->GetNextTokenSpace (&TokenSpaceGuid);\r
-\r
-  ASSERT_EFI_ERROR (Status);\r
+  (GetPiPcdPpiPointer ())->GetNextTokenSpace (&TokenSpaceGuid);\r
 \r
   return (GUID *) TokenSpaceGuid;\r
 }\r
@@ -1052,4 +1095,77 @@ LibPatchPcdSetPtr (
   return (VOID *) Buffer;\r
 }\r
 \r
+/**\r
+  Retrieve additional information associated with a PCD token.\r
+\r
+  This includes information such as the type of value the TokenNumber is associated with as well as possible\r
+  human readable name that is associated with the token.\r
+\r
+  If TokenNumber is not in the default token space specified, then ASSERT().\r
+\r
+  @param[in]    TokenNumber The PCD token number.\r
+  @param[out]   PcdInfo     The returned information associated with the requested TokenNumber.\r
+                            The caller is responsible for freeing the buffer that is allocated by callee for PcdInfo->PcdName.\r
+**/\r
+VOID\r
+EFIAPI\r
+LibPcdGetInfo (\r
+  IN        UINTN           TokenNumber,\r
+  OUT       PCD_INFO        *PcdInfo\r
+  )\r
+{\r
+  EFI_STATUS Status;\r
+\r
+  Status = GetPcdInfoPpiPointer()->GetInfo (TokenNumber, (EFI_PCD_INFO *) PcdInfo);\r
+  ASSERT_EFI_ERROR (Status);\r
+}\r
+\r
+/**\r
+  Retrieve additional information associated with a PCD token.\r
+\r
+  This includes information such as the type of value the TokenNumber is associated with as well as possible\r
+  human readable name that is associated with the token.\r
+\r
+  If TokenNumber is not in the token space specified by Guid, then ASSERT().\r
 \r
+  @param[in]    Guid        The 128-bit unique value that designates the namespace from which to extract the value.\r
+  @param[in]    TokenNumber The PCD token number.\r
+  @param[out]   PcdInfo     The returned information associated with the requested TokenNumber.\r
+                            The caller is responsible for freeing the buffer that is allocated by callee for PcdInfo->PcdName.\r
+**/\r
+VOID\r
+EFIAPI\r
+LibPcdGetInfoEx (\r
+  IN CONST  GUID            *Guid,\r
+  IN        UINTN           TokenNumber,\r
+  OUT       PCD_INFO        *PcdInfo\r
+  )\r
+{\r
+  EFI_STATUS Status;\r
+\r
+  Status = GetPiPcdInfoPpiPointer()->GetInfo (Guid, TokenNumber, (EFI_PCD_INFO *) PcdInfo);\r
+  ASSERT_EFI_ERROR (Status);\r
+}\r
+\r
+/**\r
+  Retrieve the currently set SKU Id.\r
+\r
+  If the sku id got >= PCD_MAX_SKU_ID, then ASSERT().\r
+\r
+  @return   The currently set SKU Id. If the platform has not set at a SKU Id, then the\r
+            default SKU Id value of 0 is returned. If the platform has set a SKU Id, then the currently set SKU\r
+            Id is returned.\r
+**/\r
+UINTN\r
+EFIAPI\r
+LibPcdGetSku (\r
+  VOID\r
+  )\r
+{\r
+  UINTN SkuId;\r
+\r
+  SkuId = GetPiPcdInfoPpiPointer()->GetSku ();\r
+  ASSERT (SkuId < PCD_MAX_SKU_ID);\r
+\r
+  return SkuId;\r
+}\r