]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdePkg/Library/DxePcdLib/DxePcdLib.c
MdePkg PcdLib: Follow the comment of LibPcdGetNextToken to ASSERT when an invalid...
[mirror_edk2.git] / MdePkg / Library / DxePcdLib / DxePcdLib.c
index a7303e800c3d9046c6fbd5cc567a8b2013f936eb..f14a74652978bb38f6c1af867ab4294c7faa6e77 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
 Implementation of PcdLib class library for DXE 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
@@ -18,17 +18,23 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 \r
 #include <Protocol/Pcd.h>\r
 #include <Protocol/PiPcd.h>\r
+#include <Protocol/PcdInfo.h>\r
+#include <Protocol/PiPcdInfo.h>\r
 \r
 #include <Library/PcdLib.h>\r
 #include <Library/DebugLib.h>\r
 #include <Library/UefiBootServicesTableLib.h>\r
 #include <Library/BaseMemoryLib.h>\r
 \r
-PCD_PROTOCOL     *mPcd   = NULL;\r
-EFI_PCD_PROTOCOL *mPiPcd = NULL;\r
+PCD_PROTOCOL                *mPcd       = NULL;\r
+EFI_PCD_PROTOCOL            *mPiPcd     = NULL;\r
+GET_PCD_INFO_PROTOCOL       *mPcdInfo   = NULL;\r
+EFI_GET_PCD_INFO_PROTOCOL   *mPiPcdInfo = NULL;\r
 \r
 /**\r
   Retrieves the PI PCD protocol from the handle database.\r
+\r
+  @retval EFI_PCD_PROTOCOL * The pointer to the EFI_PCD_PROTOCOL.\r
 **/\r
 EFI_PCD_PROTOCOL *\r
 EFIAPI\r
@@ -52,6 +58,8 @@ GetPiPcdProtocol (
 \r
 /**\r
   Retrieves the PCD protocol from the handle database.\r
+\r
+  @retval PCD_PROTOCOL * The pointer to the PCD_PROTOCOL.\r
 **/\r
 PCD_PROTOCOL *\r
 EFIAPI\r
@@ -73,6 +81,45 @@ GetPcdProtocol (
   return mPcd;\r
 }\r
 \r
+/**\r
+  Retrieves the PI PCD info protocol from the handle database.\r
+\r
+  @retval EFI_GET_PCD_INFO_PROTOCOL * The pointer to the EFI_GET_PCD_INFO_PROTOCOL defined in PI 1.2.1 Vol 3.\r
+**/\r
+EFI_GET_PCD_INFO_PROTOCOL *\r
+GetPiPcdInfoProtocolPointer (\r
+  VOID\r
+  )\r
+{\r
+  EFI_STATUS  Status;\r
+\r
+  if (mPiPcdInfo == NULL) {\r
+    Status = gBS->LocateProtocol (&gEfiGetPcdInfoProtocolGuid, NULL, (VOID **)&mPiPcdInfo);\r
+    ASSERT_EFI_ERROR (Status);\r
+    ASSERT (mPiPcdInfo != NULL);\r
+  }\r
+  return mPiPcdInfo;\r
+}\r
+\r
+/**\r
+  Retrieves the PCD info protocol from the handle database.\r
+\r
+  @retval GET_PCD_INFO_PROTOCOL * The pointer to the GET_PCD_INFO_PROTOCOL.\r
+**/\r
+GET_PCD_INFO_PROTOCOL *\r
+GetPcdInfoProtocolPointer (\r
+  VOID\r
+  ) \r
+{\r
+  EFI_STATUS  Status;\r
+\r
+  if (mPcdInfo == NULL) {\r
+    Status = gBS->LocateProtocol (&gGetPcdInfoProtocolGuid, NULL, (VOID **)&mPcdInfo);\r
+    ASSERT_EFI_ERROR (Status);\r
+    ASSERT (mPcdInfo != NULL);\r
+  }\r
+  return mPcdInfo;\r
+}\r
 \r
 /**\r
   This function provides a means by which SKU support can be established in the PCD infrastructure.\r
@@ -955,10 +1002,10 @@ LibPcdGetNextToken (
   IN UINTN                    TokenNumber\r
   )\r
 {\r
-  EFI_STATUS Status;\r
+  EFI_STATUS    Status;\r
 \r
   Status = GetPiPcdProtocol()->GetNextToken (Guid, &TokenNumber);\r
-  ASSERT_EFI_ERROR (Status);\r
+  ASSERT (!EFI_ERROR (Status) || TokenNumber == 0);\r
 \r
   return TokenNumber;\r
 }\r
@@ -984,10 +1031,7 @@ LibPcdGetNextTokenSpace (
   IN CONST GUID  *TokenSpaceGuid\r
   )\r
 {\r
-  EFI_STATUS Status;\r
-\r
-  Status = GetPiPcdProtocol()->GetNextTokenSpace (&TokenSpaceGuid);\r
-  ASSERT_EFI_ERROR (Status);\r
+  GetPiPcdProtocol()->GetNextTokenSpace (&TokenSpaceGuid);\r
 \r
   return (GUID *)TokenSpaceGuid;\r
 }\r
@@ -1043,5 +1087,78 @@ 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 = GetPcdInfoProtocolPointer()->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 = GetPiPcdInfoProtocolPointer()->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 = GetPiPcdInfoProtocolPointer()->GetSku ();\r
+  ASSERT (SkuId < PCD_MAX_SKU_ID);\r
+\r
+  return SkuId;\r
+}\r
 \r