/** @file\r
Implementation of PcdLib class library for DXE phase.\r
\r
-Copyright (c) 2006 - 2013, 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
\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
\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
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
\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
\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
\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
\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
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
)\r
{\r
EFI_STATUS Status;\r
+ UINTN InputSizeOfBuffer;\r
\r
ASSERT (SizeOfBuffer != NULL);\r
\r
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
\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
\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
\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
\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
\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
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
)\r
{\r
EFI_STATUS Status;\r
+ UINTN InputSizeOfBuffer;\r
\r
ASSERT (Guid != NULL);\r
\r
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
\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
IN UINTN TokenNumber\r
)\r
{\r
- GetPiPcdProtocol()->GetNextToken (Guid, &TokenNumber);\r
+ EFI_STATUS Status;\r
+\r
+ Status = GetPiPcdProtocol()->GetNextToken (Guid, &TokenNumber);\r
+ ASSERT (!EFI_ERROR (Status) || TokenNumber == 0);\r
\r
return TokenNumber;\r
}\r
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