X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=MdePkg%2FLibrary%2FDxePcdLib%2FDxePcdLib.c;h=4f552ebb0b219f32b418e7cca92b867f75303aef;hp=4773bf6c0cec2b0e505856434cab5a87fbb894a3;hb=122e21915101b8f38d81edc6d4f1fd1dd353e28a;hpb=878ddf1fc3540a715f63594ed22b6929e881afb4 diff --git a/MdePkg/Library/DxePcdLib/DxePcdLib.c b/MdePkg/Library/DxePcdLib/DxePcdLib.c index 4773bf6c0c..4f552ebb0b 100644 --- a/MdePkg/Library/DxePcdLib/DxePcdLib.c +++ b/MdePkg/Library/DxePcdLib/DxePcdLib.c @@ -11,16 +11,25 @@ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. -Module Name: DxePcdLib.c - **/ -static PCD_PROTOCOL *mPcd; + +#include + +#include + +#include +#include +#include +#include + +PCD_PROTOCOL *mPcd = NULL; + /** The constructor function caches the PCD_PROTOCOL pointer. - @param[in] ImageHandle The firmware allocated handle for the EFI image. + @param[in] ImageHandle The firmware allocated handle for the EFI image. @param[in] SystemTable A pointer to the EFI System Table. @retval EFI_SUCCESS The constructor always return EFI_SUCCESS. @@ -35,20 +44,26 @@ PcdLibConstructor ( { EFI_STATUS Status; + // + // PCD protocol has not been installed, but a module needs to access a + // dynamic PCD entry. + // Status = gBS->LocateProtocol (&gPcdProtocolGuid, NULL, (VOID **)&mPcd); ASSERT_EFI_ERROR (Status); + ASSERT (mPcd!= NULL); - return EFI_SUCCESS; + return Status; } /** Sets the current SKU in the PCD database to the value specified by SkuId. SkuId is returned. + If SkuId is not less than PCD_MAX_SKU_ID, then ASSERT(). + + @param[in] SkuId System SKU ID. The SKU value that will be used when the PCD service will retrieve and + set values. - @param[in] SkuId The SKU value that will be used when the PCD service will retrieve and - set values associated with a PCD token. - - @retval UINTN Return the SKU ID that just be set. + @return Return the SKU ID that just be set. **/ UINTN @@ -57,10 +72,9 @@ LibPcdSetSku ( IN UINTN SkuId ) { - EFI_STATUS Status; + ASSERT (SkuId < PCD_MAX_SKU_ID); - Status = mPcd->SetSku (SkuId); - ASSERT_EFI_ERROR (Status); + mPcd->SetSku (SkuId); return SkuId; } @@ -70,9 +84,9 @@ LibPcdSetSku ( /** Returns the 8-bit value for the token specified by TokenNumber. - @param[in] The PCD token number to retrieve a current value for. + @param[in] TokenNumber The PCD token number to retrieve a current value for. - @retval UINT8 Returns the 8-bit value for the token specified by TokenNumber. + @return Returns the 8-bit value for the token specified by TokenNumber. **/ UINT8 @@ -89,9 +103,9 @@ LibPcdGet8 ( /** Returns the 16-bit value for the token specified by TokenNumber. - @param[in] The PCD token number to retrieve a current value for. + @param[in] TokenNumber The PCD token number to retrieve a current value for. - @retval UINT16 Returns the 16-bit value for the token specified by TokenNumber. + @return Returns the 16-bit value for the token specified by TokenNumber. **/ UINT16 @@ -110,7 +124,7 @@ LibPcdGet16 ( @param[in] TokenNumber The PCD token number to retrieve a current value for. - @retval UINT32 Returns the 32-bit value for the token specified by TokenNumber. + @return Returns the 32-bit value for the token specified by TokenNumber. **/ UINT32 @@ -129,7 +143,7 @@ LibPcdGet32 ( @param[in] TokenNumber The PCD token number to retrieve a current value for. - @retval UINT64 Returns the 64-bit value for the token specified by TokenNumber. + @return Returns the 64-bit value for the token specified by TokenNumber. **/ UINT64 @@ -148,7 +162,7 @@ LibPcdGet64 ( @param[in] TokenNumber The PCD token number to retrieve a current value for. - @retval VOID* Returns the pointer to the token specified by TokenNumber. + @return Returns the pointer to the token specified by TokenNumber. **/ VOID * @@ -167,7 +181,7 @@ LibPcdGetPtr ( @param[in] TokenNumber The PCD token number to retrieve a current value for. - @retval BOOLEAN Returns the Boolean value of the token specified by TokenNumber. + @return Returns the Boolean value of the token specified by TokenNumber. **/ BOOLEAN @@ -186,7 +200,7 @@ LibPcdGetBool ( @param[in] TokenNumber The PCD token number to retrieve a current value for. - @retval UINTN Returns the size of the token specified by TokenNumber. + @return Returns the size of the token specified by TokenNumber. **/ UINTN @@ -208,7 +222,7 @@ LibPcdGetSize ( which namespace to retrieve a value from. @param[in] TokenNumber The PCD token number to retrieve a current value for. - @retval UINT8 Return the UINT8. + @return Return the UINT8. **/ UINT8 @@ -232,7 +246,7 @@ LibPcdGetEx8 ( which namespace to retrieve a value from. @param[in] TokenNumber The PCD token number to retrieve a current value for. - @retval UINT16 Return the UINT16. + @return Return the UINT16. **/ UINT16 @@ -256,7 +270,7 @@ LibPcdGetEx16 ( which namespace to retrieve a value from. @param[in] TokenNumber The PCD token number to retrieve a current value for. - @retval UINT32 Return the UINT32. + @return Return the UINT32. **/ UINT32 @@ -281,7 +295,7 @@ LibPcdGetEx32 ( which namespace to retrieve a value from. @param[in] TokenNumber The PCD token number to retrieve a current value for. - @retval UINT64 Return the UINT64. + @return Return the UINT64. **/ UINT64 @@ -306,7 +320,7 @@ LibPcdGetEx64 ( which namespace to retrieve a value from. @param[in] TokenNumber The PCD token number to retrieve a current value for. - @retval VOID* Return the VOID* pointer. + @return Return the VOID* pointer. **/ VOID * @@ -331,7 +345,7 @@ LibPcdGetExPtr ( which namespace to retrieve a value from. @param[in] TokenNumber The PCD token number to retrieve a current value for. - @retval BOOLEAN Return the BOOLEAN. + @return Return the BOOLEAN. **/ BOOLEAN @@ -356,7 +370,7 @@ LibPcdGetExBool ( which namespace to retrieve a value from. @param[in] TokenNumber The PCD token number to retrieve a current value for. - @retval UINTN Return the size. + @return Return the size. **/ UINTN @@ -376,11 +390,12 @@ LibPcdGetExSize ( /** Sets the 8-bit value for the token specified by TokenNumber to the value specified by Value. Value is returned. + If fail to set pcd value, then ASSERT_EFI_ERROR(). @param[in] TokenNumber The PCD token number to set a current value for. @param[in] Value The 8-bit value to set. - @retval UINT8 Return the value been set. + @return Return the value been set. **/ UINT8 @@ -404,11 +419,12 @@ LibPcdSet8 ( /** Sets the 16-bit value for the token specified by TokenNumber to the value specified by Value. Value is returned. + If fail to set pcd value, then ASSERT_EFI_ERROR(). @param[in] TokenNumber The PCD token number to set a current value for. @param[in] Value The 16-bit value to set. - @retval UINT16 Return the value been set. + @return Return the value been set. **/ UINT16 @@ -432,11 +448,12 @@ LibPcdSet16 ( /** Sets the 32-bit value for the token specified by TokenNumber to the value specified by Value. Value is returned. + If fail to set pcd value, then ASSERT_EFI_ERROR(). @param[in] TokenNumber The PCD token number to set a current value for. @param[in] Value The 32-bit value to set. - @retval UINT32 Return the value been set. + @return Return the value been set. **/ UINT32 @@ -459,11 +476,12 @@ LibPcdSet32 ( /** Sets the 64-bit value for the token specified by TokenNumber to the value specified by Value. Value is returned. + If fail to set pcd value, then ASSERT_EFI_ERROR(). @param[in] TokenNumber The PCD token number to set a current value for. @param[in] Value The 64-bit value to set. - @retval UINT64 Return the value been set. + @return Return the value been set. **/ UINT64 @@ -486,31 +504,49 @@ LibPcdSet64 ( /** Sets a buffer for the token specified by TokenNumber to - the value specified by Value. Value is returned. - If Value is NULL, then ASSERT(). + the value specified by Buffer and SizeOfBuffer. Buffer to + be set is returned. The content of the buffer could be + overwritten if a Callback on SET is registered with this + TokenNumber. - @param[in] TokenNumber The PCD token number to set a current value for. - @param[in] Value A pointer to the buffer to set. + If SizeOfBuffer is greater than the maximum + size support by TokenNumber, then set SizeOfBuffer to the + maximum size supported by TokenNumber and return NULL to + indicate that the set operation was not actually performed. + + If SizeOfBuffer > 0 and Buffer is NULL, then ASSERT(). + + @param[in] TokenNumber The PCD token number to set a current value for. + @param[in, out] SizeOfBuffer The size, in bytes, of Buffer. + In out, returns actual size of buff is set. + @param[in] Buffer A pointer to the buffer to set. - @retval VOID* Return the pointer for the buffer been set. + @return Return the pointer for the buffer been set. **/ VOID * EFIAPI LibPcdSetPtr ( - IN UINTN TokenNumber, - IN CONST VOID *Value + IN UINTN TokenNumber, + IN OUT UINTN *SizeOfBuffer, + IN VOID *Buffer ) { EFI_STATUS Status; - - ASSERT (Value != NULL); - Status = mPcd->SetPtr (TokenNumber, Value); + ASSERT (SizeOfBuffer != NULL); - ASSERT_EFI_ERROR (Status); + if (*SizeOfBuffer > 0) { + ASSERT (Buffer != NULL); + } + + Status = mPcd->SetPtr (TokenNumber, SizeOfBuffer, Buffer); - return (VOID *)Value; + if (EFI_ERROR (Status)) { + return NULL; + } + + return Buffer; } @@ -518,11 +554,12 @@ LibPcdSetPtr ( /** Sets the Boolean value for the token specified by TokenNumber to the value specified by Value. Value is returned. + If fail to set pcd value, then ASSERT_EFI_ERROR(). @param[in] TokenNumber The PCD token number to set a current value for. - @param[in] Value The boolean value to set. + @param[in] Value The boolean value to set. - @retval BOOLEAN Return the value been set. + @return Return the value been set. **/ BOOLEAN @@ -547,13 +584,14 @@ LibPcdSetBool ( Sets the 8-bit value for the token specified by TokenNumber and Guid to the value specified by Value. Value is returned. If Guid is NULL, then ASSERT(). + If fail to set pcd value, then ASSERT_EFI_ERROR(). @param[in] Guid Pointer to a 128-bit unique value that designates which namespace to set a value from. @param[in] TokenNumber The PCD token number to set a current value for. @param[in] Value The 8-bit value to set. - @retval UINT8 Return the value been set. + @return Return the value been set. **/ UINT8 @@ -581,13 +619,14 @@ LibPcdSetEx8 ( Sets the 16-bit value for the token specified by TokenNumber and Guid to the value specified by Value. Value is returned. If Guid is NULL, then ASSERT(). + If fail to set pcd value, then ASSERT_EFI_ERROR(). @param[in] Guid Pointer to a 128-bit unique value that designates which namespace to set a value from. @param[in] TokenNumber The PCD token number to set a current value for. @param[in] Value The 16-bit value to set. - @retval UINT8 Return the value been set. + @return Return the value been set. **/ UINT16 @@ -615,13 +654,14 @@ LibPcdSetEx16 ( Sets the 32-bit value for the token specified by TokenNumber and Guid to the value specified by Value. Value is returned. If Guid is NULL, then ASSERT(). + If fail to set pcd value, then ASSERT_EFI_ERROR(). @param[in] Guid Pointer to a 128-bit unique value that designates which namespace to set a value from. @param[in] TokenNumber The PCD token number to set a current value for. @param[in] Value The 32-bit value to set. - @retval UINT32 Return the value been set. + @return Return the value been set. **/ UINT32 @@ -655,7 +695,7 @@ LibPcdSetEx32 ( @param[in] TokenNumber The PCD token number to set a current value for. @param[in] Value The 64-bit value to set. - @retval UINT64 Return the value been set. + @return Return the value been set. **/ UINT64 @@ -680,37 +720,50 @@ LibPcdSetEx64 ( /** - Sets a buffer for the token specified by TokenNumber and - Guid to the value specified by Value. Value is returned. - If Guid is NULL, then ASSERT(). - If Value is NULL, then ASSERT(). + Sets a buffer for the token specified by TokenNumber to the value specified by + Buffer and SizeOfBuffer. Buffer is returned. If SizeOfBuffer is greater than + the maximum size support by TokenNumber, then set SizeOfBuffer to the maximum size + supported by TokenNumber and return NULL to indicate that the set operation + was not actually performed. - @param[in] Guid Pointer to a 128-bit unique value that - designates which namespace to set a value from. - @param[in] TokenNumber The PCD token number to set a current value for. - @param[in] Value The 8-bit value to set. + If SizeOfBuffer > 0 and Buffer is NULL, then ASSERT(). + + @param[in] Guid Pointer to a 128-bit unique value that + designates which namespace to set a value from. + @param[in] TokenNumber The PCD token number to set a current value for. + @param[in, out] SizeOfBuffer The size, in bytes, of Buffer. + In out, returns actual size of buffer is set. + @param[in] Buffer A pointer to the buffer to set. - @retval VOID * Return the value been set. + @return Return the pinter to the buffer been set. **/ VOID * EFIAPI LibPcdSetExPtr ( - IN CONST GUID *Guid, - IN UINTN TokenNumber, - IN CONST VOID *Value + IN CONST GUID *Guid, + IN UINTN TokenNumber, + IN OUT UINTN *SizeOfBuffer, + IN VOID *Buffer ) { - EFI_STATUS Status; + EFI_STATUS Status; ASSERT (Guid != NULL); - ASSERT (Value != NULL); - Status = mPcd->SetPtrEx (Guid, TokenNumber, Value); + ASSERT (SizeOfBuffer != NULL); - ASSERT_EFI_ERROR (Status); + if (*SizeOfBuffer > 0) { + ASSERT (Buffer != NULL); + } + + Status = mPcd->SetPtrEx (Guid, TokenNumber, SizeOfBuffer, Buffer); - return (VOID *)Value; + if (EFI_ERROR (Status)) { + return NULL; + } + + return Buffer; } @@ -719,13 +772,14 @@ LibPcdSetExPtr ( Sets the Boolean value for the token specified by TokenNumber and Guid to the value specified by Value. Value is returned. If Guid is NULL, then ASSERT(). + If fail to set pcd value, then ASSERT_EFI_ERROR(). @param[in] Guid Pointer to a 128-bit unique value that designates which namespace to set a value from. @param[in] TokenNumber The PCD token number to set a current value for. @param[in] Value The Boolean value to set. - @retval Boolean Return the value been set. + @return Return the value been set. **/ BOOLEAN @@ -754,16 +808,14 @@ LibPcdSetExBool ( then notification function specified by NotificationFunction is called. If Guid is NULL, then the default token space is used. If NotificationFunction is NULL, then ASSERT(). - + If fail to set callback function, then ASSERT_EFI_ERROR(). + @param[in] Guid Pointer to a 128-bit unique value that designates which namespace to set a value from. If NULL, then the default token space is used. @param[in] TokenNumber The PCD token number to monitor. @param[in] NotificationFunction The function to call when the token specified by Guid and TokenNumber is set. - - @retval VOID - **/ VOID EFIAPI @@ -777,7 +829,7 @@ LibPcdCallbackOnSet ( ASSERT (NotificationFunction != NULL); - Status = mPcd->CallbackOnSet (TokenNumber, Guid, NotificationFunction); + Status = mPcd->CallbackOnSet (Guid, TokenNumber, NotificationFunction); ASSERT_EFI_ERROR (Status); @@ -789,13 +841,12 @@ LibPcdCallbackOnSet ( /** Disable a notification function that was established with LibPcdCallbackonSet(). If NotificationFunction is NULL, then ASSERT(). - + If fail to cancel callback function, then ASSERT_EFI_ERROR(). + @param[in] Guid Specify the GUID token space. @param[in] TokenNumber Specify the token number. @param[in] NotificationFunction The callback function to be unregistered. - @retval VOID - **/ VOID EFIAPI @@ -809,7 +860,7 @@ LibPcdCancelCallback ( ASSERT (NotificationFunction != NULL); - Status = mPcd->CancelCallback (TokenNumber, Guid, NotificationFunction); + Status = mPcd->CancelCallback (Guid, TokenNumber, NotificationFunction); ASSERT_EFI_ERROR (Status); @@ -825,28 +876,117 @@ LibPcdCancelCallback ( follows TokenNumber in the token space is returned. If TokenNumber is the last token number in the token space, then 0 is returned. If TokenNumber is not 0 and is not in the token space specified by Guid, then ASSERT(). + If Fail to get next token, then ASSERT_EFI_ERROR(). - @param[in] Pointer to a 128-bit unique value that designates which namespace - to set a value from. If NULL, then the default token space is used. - @param[in] The previous PCD token number. If 0, then retrieves the first PCD - token number. + @param[in] Guid Pointer to a 128-bit unique value that designates which namespace + to set a value from. If NULL, then the default token space is used. + @param[in] TokenNumber The previous PCD token number. If 0, then retrieves the first PCD + token number. - @retval UINTN The next valid token number. + @return The next valid token number. **/ -UINTN +UINTN EFIAPI LibPcdGetNextToken ( IN CONST GUID *Guid, OPTIONAL - IN OUT UINTN *TokenNumber + IN UINTN TokenNumber ) { EFI_STATUS Status; - Status = mPcd->GetNextToken (Guid, TokenNumber); + Status = mPcd->GetNextToken (Guid, &TokenNumber); ASSERT_EFI_ERROR (Status); - return (*TokenNumber); + return TokenNumber; } + + +/** + Used to retrieve the list of available PCD token space GUIDs. + + Retrieves the next PCD token space from a token space specified by Guid. + Guid of NULL is reserved to mark the default local token namespace on the current + platform. If Guid is NULL, then the GUID of the first non-local token space of the + current platform is returned. If Guid is the last non-local token space, + then NULL is returned. + + If Guid is not NULL and is not a valid token space in the current platform, then ASSERT(). + If fail to get next token space, then ASSERT_EFI_ERROR(). + + @param[in] Guid Pointer to a 128-bit unique value that designates from which namespace + to start the search. + + @return The next valid token namespace. + +**/ +GUID * +EFIAPI +LibPcdGetNextTokenSpace ( + IN CONST GUID *TokenSpaceGuid + ) +{ + EFI_STATUS Status; + + Status = mPcd->GetNextTokenSpace (&TokenSpaceGuid); + + ASSERT_EFI_ERROR (Status); + + return (GUID *) TokenSpaceGuid; +} + + +/** + Sets the PCD entry specified by PatchVariable to the value specified by Buffer + and SizeOfBuffer. Buffer is returned. If SizeOfBuffer is greater than + MaximumDatumSize, then set SizeOfBuffer to MaximumDatumSize and return + NULL to indicate that the set operation was not actually performed. + If SizeOfBuffer is set to MAX_ADDRESS, then SizeOfBuffer must be set to + MaximumDatumSize and NULL must be returned. + + If PatchVariable is NULL, then ASSERT(). + If SizeOfBuffer is NULL, then ASSERT(). + If SizeOfBuffer > 0 and Buffer is NULL, then ASSERT(). + + @param[in] PatchVariable A pointer to the global variable in a module that is + the target of the set operation. + @param[in] MaximumDatumSize The maximum size allowed for the PCD entry specified by PatchVariable. + @param[in, out] SizeOfBuffer A pointer to the size, in bytes, of Buffer. + In out, returns actual size of buffer is set. + @param[in] Buffer A pointer to the buffer to used to set the target variable. + + @return Return the pinter to the buffer been set. + @retval NULL If SizeOfBuffer is set to MAX_ADDRESS or larger than MaximumDatumSize, + then SizeOfBuffer must be set to MaximumDatumSize and NULL must be returned. +**/ +VOID * +EFIAPI +LibPatchPcdSetPtr ( + IN VOID *PatchVariable, + IN UINTN MaximumDatumSize, + IN OUT UINTN *SizeOfBuffer, + IN CONST VOID *Buffer + ) +{ + ASSERT (PatchVariable != NULL); + ASSERT (SizeOfBuffer != NULL); + + if (*SizeOfBuffer > 0) { + ASSERT (Buffer != NULL); + } + + if ((*SizeOfBuffer > MaximumDatumSize) || + (*SizeOfBuffer == MAX_ADDRESS)) { + *SizeOfBuffer = MaximumDatumSize; + return NULL; + } + + CopyMem (PatchVariable, Buffer, *SizeOfBuffer); + + return (VOID *) Buffer; +} + + +