X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=MdePkg%2FLibrary%2FDxePcdLib%2FDxePcdLib.c;h=b05c6550c81663071d7b86193c483e2e15fb7607;hb=d57e875ca3aac3249751b18db03921b6f0cff5fe;hp=4773bf6c0cec2b0e505856434cab5a87fbb894a3;hpb=878ddf1fc3540a715f63594ed22b6929e881afb4;p=mirror_edk2.git diff --git a/MdePkg/Library/DxePcdLib/DxePcdLib.c b/MdePkg/Library/DxePcdLib/DxePcdLib.c index 4773bf6c0c..b05c6550c8 100644 --- a/MdePkg/Library/DxePcdLib/DxePcdLib.c +++ b/MdePkg/Library/DxePcdLib/DxePcdLib.c @@ -15,12 +15,28 @@ Module Name: DxePcdLib.c **/ +// +// The package level header files this module uses +// +#include +// +// The protocols, PPI and GUID defintions for this module +// +#include +// +// The Library classes this module consumes +// +#include +#include +#include +#include + static PCD_PROTOCOL *mPcd; /** 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. @@ -48,7 +64,7 @@ PcdLibConstructor ( @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. + @retval SKU_ID Return the SKU ID that just be set. **/ UINTN @@ -57,10 +73,9 @@ LibPcdSetSku ( IN UINTN SkuId ) { - EFI_STATUS Status; + ASSERT (SkuId < 0x100); - Status = mPcd->SetSku (SkuId); - ASSERT_EFI_ERROR (Status); + mPcd->SetSku (SkuId); return SkuId; } @@ -486,31 +501,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 SizeOfValue. 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 + 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. @retval VOID* 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; } @@ -680,37 +713,49 @@ 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 SizeOfValue. Buffer is returned. If SizeOfValue is greater than + the maximum size support by TokenNumber, then set SizeOfValue 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] 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. + @param[in, out] SizeOfBuffer The size, in bytes, of Buffer. + @param[in] Buffer A pointer to the buffer to set. - @retval VOID * Return the value been set. + @retval VOID * 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; } @@ -777,7 +822,7 @@ LibPcdCallbackOnSet ( ASSERT (NotificationFunction != NULL); - Status = mPcd->CallbackOnSet (TokenNumber, Guid, NotificationFunction); + Status = mPcd->CallbackOnSet (Guid, TokenNumber, NotificationFunction); ASSERT_EFI_ERROR (Status); @@ -809,7 +854,7 @@ LibPcdCancelCallback ( ASSERT (NotificationFunction != NULL); - Status = mPcd->CancelCallback (TokenNumber, Guid, NotificationFunction); + Status = mPcd->CancelCallback (Guid, TokenNumber, NotificationFunction); ASSERT_EFI_ERROR (Status); @@ -831,22 +876,105 @@ LibPcdCancelCallback ( @param[in] The previous PCD token number. If 0, then retrieves the first PCD token number. - @retval UINTN The next valid token number. + @retval UINTN 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; } + + +/** + 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(). + + + + @param[in] Pointer to a 128-bit unique value that designates from which namespace + to start the search. + + @retval CONST GUID * The next valid token namespace. + +**/ +GUID * +EFIAPI +LibPcdGetNextTokenSpace ( + IN CONST GUID *Guid + ) +{ + EFI_STATUS Status; + + Status = mPcd->GetNextTokenSpace (&Guid); + + ASSERT_EFI_ERROR (Status); + + return (GUID *) Guid; +} + + +/** + Sets the PCD entry specified by PatchVariable to the value specified by Buffer + and SizeOfValue. Buffer is returned. If SizeOfValue is greater than + MaximumDatumSize, then set SizeOfValue to MaximumDatumSize and return + NULL to indicate that the set operation was not actually performed. + If SizeOfValue is set to MAX_ADDRESS, then SizeOfValue must be set to + MaximumDatumSize and NULL must be returned. + + If PatchVariable is NULL, then ASSERT(). + If SizeOfValue is NULL, then ASSERT(). + If SizeOfValue > 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. + @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; +} + + +