X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=MdePkg%2FLibrary%2FDxePcdLib%2FDxePcdLib.c;h=e780bd32a24d0b3a4103388177767e3767599310;hb=25366245f586af7de63fa60ba328879707f25563;hp=ee517715f552b68744d410e929b16a73f92deb05;hpb=4276d5dacfd4812abc1d7a1bd1da995d7002ee9e;p=mirror_edk2.git diff --git a/MdePkg/Library/DxePcdLib/DxePcdLib.c b/MdePkg/Library/DxePcdLib/DxePcdLib.c index ee517715f5..e780bd32a2 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,18 +44,24 @@ 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. - - @param[in] SkuId The SKU value that will be used when the PCD service will retrieve and - set values associated with a PCD token. + 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. @retval SKU_ID Return the SKU ID that just be set. @@ -57,6 +72,8 @@ LibPcdSetSku ( IN UINTN SkuId ) { + ASSERT (SkuId < PCD_MAX_SKU_ID); + mPcd->SetSku (SkuId); return SkuId; @@ -67,7 +84,7 @@ 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. @@ -86,7 +103,7 @@ 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. @@ -373,6 +390,7 @@ 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. @@ -401,6 +419,7 @@ 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. @@ -429,6 +448,7 @@ 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. @@ -456,6 +476,7 @@ 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. @@ -483,26 +504,26 @@ LibPcdSet64 ( /** Sets a buffer for the token specified by TokenNumber to - the value specified by Buffer and SizeOfValue. Buffer to + 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. - If SizeOfValue is greater than the maximum - size support by TokenNumber, then set SizeOfValue to the + 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 SizeOfValue > 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. - @param[in] Value A pointer to the buffer to set. + @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. **/ - VOID * EFIAPI LibPcdSetPtr ( @@ -512,20 +533,18 @@ LibPcdSetPtr ( ) { EFI_STATUS Status; - UINTN Size; - - ASSERT ((*SizeOfBuffer > 0) && Buffer == NULL); - Size = LibPcdGetSize (TokenNumber); - - if (*SizeOfBuffer > Size) { - *SizeOfBuffer = Size; - return NULL; + ASSERT (SizeOfBuffer != NULL); + + if (*SizeOfBuffer > 0) { + ASSERT (Buffer != NULL); } - Status = mPcd->SetPtr (TokenNumber, *SizeOfBuffer, Buffer); + Status = mPcd->SetPtr (TokenNumber, SizeOfBuffer, Buffer); - ASSERT_EFI_ERROR (Status); + if (EFI_ERROR (Status)) { + return NULL; + } return Buffer; } @@ -535,9 +554,10 @@ 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. @@ -564,6 +584,7 @@ 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. @@ -598,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. + @retval UINT16 Return the value been set. **/ UINT16 @@ -632,6 +654,7 @@ 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. @@ -698,18 +721,19 @@ LibPcdSetEx64 ( /** Sets a buffer for the token specified by TokenNumber to the value specified by - Buffer and SizeOfValue. Buffer is returned. If SizeOfValue is greater than - the maximum size support by TokenNumber, then set SizeOfValue to the maximum size + 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. - If SizeOfValue > 0 and Buffer is NULL, then ASSERT(). + 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. - @param[in] Buffer A pointer to the buffer to set. + @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 pinter to the buffer been set. @@ -724,20 +748,20 @@ LibPcdSetExPtr ( ) { EFI_STATUS Status; - UINTN Size; ASSERT (Guid != NULL); - ASSERT (Buffer != NULL); - Size = LibPcdGetExSize (Guid, TokenNumber); - if (*SizeOfBuffer > Size) { - *SizeOfBuffer = Size; - return NULL; + ASSERT (SizeOfBuffer != NULL); + + if (*SizeOfBuffer > 0) { + ASSERT (Buffer != NULL); } - Status = mPcd->SetPtrEx (Guid, TokenNumber, *SizeOfBuffer, Buffer); + Status = mPcd->SetPtrEx (Guid, TokenNumber, SizeOfBuffer, Buffer); - ASSERT_EFI_ERROR (Status); + if (EFI_ERROR (Status)) { + return NULL; + } return Buffer; } @@ -748,6 +772,7 @@ 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. @@ -783,7 +808,8 @@ 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. @@ -806,7 +832,7 @@ LibPcdCallbackOnSet ( ASSERT (NotificationFunction != NULL); - Status = mPcd->CallbackOnSet (TokenNumber, Guid, NotificationFunction); + Status = mPcd->CallbackOnSet (Guid, TokenNumber, NotificationFunction); ASSERT_EFI_ERROR (Status); @@ -818,7 +844,8 @@ 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. @@ -838,7 +865,7 @@ LibPcdCancelCallback ( ASSERT (NotificationFunction != NULL); - Status = mPcd->CancelCallback (TokenNumber, Guid, NotificationFunction); + Status = mPcd->CancelCallback (Guid, TokenNumber, NotificationFunction); ASSERT_EFI_ERROR (Status); @@ -854,11 +881,12 @@ 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. @@ -889,16 +917,15 @@ LibPcdGetNextToken ( 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] Pointer to a 128-bit unique value that designates from which namespace - to start the search. + @param[in] Guid Pointer to a 128-bit unique value that designates from which namespace + to start the search. @retval CONST GUID * The next valid token namespace. **/ -CONST GUID* +GUID * EFIAPI LibPcdGetNextTokenSpace ( IN CONST GUID *Guid @@ -910,6 +937,56 @@ LibPcdGetNextTokenSpace ( ASSERT_EFI_ERROR (Status); - return Guid; + return (GUID *) Guid; +} + + +/** + 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. + +**/ +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; } + +