]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdePkg/Library/DxePcdLib/DxePcdLib.c
MdePkg PcdLib: Except for SizeOfBuffer is greater than the maximum size supported...
[mirror_edk2.git] / MdePkg / Library / DxePcdLib / DxePcdLib.c
index a7303e800c3d9046c6fbd5cc567a8b2013f936eb..6f3a1b28613504d1a632e9318b302f8b5f106e43 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 - 2014, 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
@@ -442,7 +489,9 @@ LibPcdGetExSize (
   \r
   Sets the 8-bit value for the token specified by TokenNumber \r
   to the value specified by Value.  Value is returned.\r
-  \r
+\r
+  If the set operation was not correctly performed, then ASSERT().\r
+\r
   @param[in]  TokenNumber   The PCD token number to set a current value for.\r
   @param[in]  Value         The 8-bit value to set.\r
 \r
@@ -471,7 +520,9 @@ LibPcdSet8 (
   \r
   Sets the 16-bit value for the token specified by TokenNumber \r
   to the value specified by Value.  Value is returned.\r
-  \r
+\r
+  If the set operation was not correctly performed, then ASSERT().\r
+\r
   @param[in]  TokenNumber   The PCD token number to set a current value for.\r
   @param[in]  Value         The 16-bit value to set.\r
 \r
@@ -500,7 +551,9 @@ LibPcdSet16 (
   \r
   Sets the 32-bit value for the token specified by TokenNumber \r
   to the value specified by Value.  Value is returned.\r
-  \r
+\r
+  If the set operation was not correctly performed, then ASSERT().\r
+\r
   @param[in]  TokenNumber   The PCD token number to set a current value for.\r
   @param[in]  Value         The 32-bit value to set.\r
 \r
@@ -529,6 +582,8 @@ LibPcdSet32 (
   \r
   Sets the 64-bit value for the token specified by TokenNumber \r
   to the value specified by Value.  Value is returned.\r
+\r
+  If the set operation was not correctly performed, then ASSERT().\r
   \r
   @param[in]  TokenNumber   The PCD token number to set a current value for.\r
   @param[in]  Value         The 64-bit value to set.\r
@@ -560,7 +615,8 @@ LibPcdSet64 (
   specified by Buffer and SizeOfBuffer.  Buffer is returned.  \r
   If SizeOfBuffer is greater than the maximum size support by TokenNumber, \r
   then set SizeOfBuffer to the maximum size supported by TokenNumber and \r
-  return NULL to indicate that the set operation was not actually performed.  \r
+  return NULL to indicate that the set operation was not actually performed,\r
+  or ASSERT() if the set operation was not correctly performed.\r
 \r
   If SizeOfBuffer is set to MAX_ADDRESS, then SizeOfBuffer must be set to the \r
   maximum size supported by TokenName and NULL must be returned.\r
@@ -584,6 +640,7 @@ LibPcdSetPtr (
   )\r
 {\r
   EFI_STATUS Status;\r
+  UINTN      InputSizeOfBuffer;\r
 \r
   ASSERT (SizeOfBuffer != NULL);\r
 \r
@@ -591,10 +648,12 @@ LibPcdSetPtr (
     ASSERT (Buffer != NULL);\r
   }\r
 \r
+  InputSizeOfBuffer = *SizeOfBuffer;\r
   Status = GetPcdProtocol()->SetPtr (TokenNumber, SizeOfBuffer, (VOID *) Buffer);\r
-  if (EFI_ERROR (Status)) {\r
+  if (EFI_ERROR (Status) && (*SizeOfBuffer < InputSizeOfBuffer)) {\r
     return NULL;\r
   }\r
+  ASSERT_EFI_ERROR (Status);\r
 \r
   return (VOID *)Buffer;\r
 }\r
@@ -606,7 +665,9 @@ LibPcdSetPtr (
   \r
   Sets the Boolean value for the token specified by TokenNumber \r
   to the value specified by Value.  Value is returned.\r
-  \r
+\r
+  If the set operation was not correctly performed, then ASSERT().\r
+\r
   @param[in]  TokenNumber   The PCD token number to set a current value for.\r
   @param[in]  Value         The boolean value to set.\r
 \r
@@ -635,9 +696,10 @@ LibPcdSetBool (
   \r
   Sets the 8-bit value for the token specified by TokenNumber and \r
   Guid to the value specified by Value. Value is returned.\r
-  \r
+\r
   If Guid is NULL, then ASSERT().\r
-  \r
+  If the set operation was not correctly performed, then ASSERT().\r
+\r
   @param[in]  Guid          The pointer to a 128-bit unique value that \r
                             designates which namespace to set a value from.\r
   @param[in]  TokenNumber   The PCD token number to set a current value for.\r
@@ -671,9 +733,10 @@ LibPcdSetEx8 (
   \r
   Sets the 16-bit value for the token specified by TokenNumber and \r
   Guid to the value specified by Value. Value is returned.\r
-  \r
+\r
   If Guid is NULL, then ASSERT().\r
-  \r
+  If the set operation was not correctly performed, then ASSERT().\r
+\r
   @param[in]  Guid          The pointer to a 128-bit unique value that \r
                             designates which namespace to set a value from.\r
   @param[in]  TokenNumber   The PCD token number to set a current value for.\r
@@ -707,9 +770,10 @@ LibPcdSetEx16 (
   \r
   Sets the 32-bit value for the token specified by TokenNumber and \r
   Guid to the value specified by Value. Value is returned.\r
-  \r
+\r
   If Guid is NULL, then ASSERT().\r
-  \r
+  If the set operation was not correctly performed, then ASSERT().\r
+\r
   @param[in]  Guid          The pointer to a 128-bit unique value that \r
                             designates which namespace to set a value from.\r
   @param[in]  TokenNumber   The PCD token number to set a current value for.\r
@@ -743,8 +807,10 @@ LibPcdSetEx32 (
   \r
   Sets the 64-bit value for the token specified by TokenNumber and \r
   Guid to the value specified by Value. Value is returned.\r
+\r
   If Guid is NULL, then ASSERT().\r
-  \r
+  If the set operation was not correctly performed, then ASSERT().\r
+\r
   @param[in]  Guid          The pointer to a 128-bit unique value that \r
                             designates which namespace to set a value from.\r
   @param[in]  TokenNumber   The PCD token number to set a current value for.\r
@@ -780,7 +846,7 @@ LibPcdSetEx64 (
   Buffer and SizeOfBuffer.  Buffer is returned.  If SizeOfBuffer is greater than \r
   the maximum size support by TokenNumber, then set SizeOfBuffer to the maximum size \r
   supported by TokenNumber and return NULL to indicate that the set operation \r
-  was not actually performed\r
+  was not actually performed, or ASSERT() if the set operation was not corretly performed.\r
   \r
   If Guid is NULL, then ASSERT().\r
   If SizeOfBuffer is NULL, then ASSERT().\r
@@ -805,6 +871,7 @@ LibPcdSetExPtr (
   )\r
 {\r
   EFI_STATUS  Status;\r
+  UINTN       InputSizeOfBuffer;\r
 \r
   ASSERT (Guid != NULL);\r
 \r
@@ -814,10 +881,12 @@ LibPcdSetExPtr (
     ASSERT (Buffer != NULL);\r
   }\r
 \r
+  InputSizeOfBuffer = *SizeOfBuffer;\r
   Status = GetPiPcdProtocol()->SetPtr (Guid, TokenNumber, SizeOfBuffer, Buffer);\r
-  if (EFI_ERROR (Status)) {\r
+  if (EFI_ERROR (Status) && (*SizeOfBuffer < InputSizeOfBuffer)) {\r
     return NULL;\r
   }\r
+  ASSERT_EFI_ERROR (Status);\r
 \r
   return Buffer;\r
 }\r
@@ -829,9 +898,10 @@ LibPcdSetExPtr (
   \r
   Sets the Boolean value for the token specified by TokenNumber and \r
   Guid to the value specified by Value. Value is returned.\r
-  \r
+\r
   If Guid is NULL, then ASSERT().\r
-  \r
+  If the set operation was not correctly performed, then ASSERT().\r
+\r
   @param[in]  Guid          The pointer to a 128-bit unique value that \r
                             designates which namespace to set a value from.\r
   @param[in]  TokenNumber   The PCD token number to set a current value for.\r
@@ -955,10 +1025,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 +1054,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 +1110,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