X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=MdePkg%2FLibrary%2FPeiPcdLib%2FPeiPcdLib.c;h=f686d4e8656505f2e81571fbde4b8479e76bd734;hb=c7d265a94a3ee2517430e4f19f5b24482e5e7132;hp=29fdeb0ee4525e9e5def15f4e45c909cb03bcad1;hpb=878ddf1fc3540a715f63594ed22b6929e881afb4;p=mirror_edk2.git diff --git a/MdePkg/Library/PeiPcdLib/PeiPcdLib.c b/MdePkg/Library/PeiPcdLib/PeiPcdLib.c index 29fdeb0ee4..f686d4e865 100644 --- a/MdePkg/Library/PeiPcdLib/PeiPcdLib.c +++ b/MdePkg/Library/PeiPcdLib/PeiPcdLib.c @@ -17,6 +17,22 @@ Module Name: PeiPcdLib.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 + /** The constructor function retrieve the PCD_PPI pointer. @@ -25,6 +41,7 @@ Module Name: PeiPcdLib.c @retval PCD_PPI * The pointer to the PCD_PPI. **/ +STATIC PCD_PPI * GetPcdPpiPtr ( VOID @@ -58,7 +75,7 @@ GetPcdPpiPtr ( @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 @@ -67,14 +84,10 @@ LibPcdSetSku ( IN UINTN SkuId ) { - EFI_STATUS Status; - PCD_PPI *PcdPpi; - - PcdPpi = GetPcdPpiPtr (); + ASSERT (SkuId < 0x100); - Status = PcdPpi->SetSku (SkuId); - ASSERT_EFI_ERROR (Status); + GetPcdPpiPtr()->SetSku (SkuId);; return SkuId; } @@ -92,7 +105,7 @@ LibPcdSetSku ( UINT8 EFIAPI LibPcdGet8 ( - IN UINTN TokenNumber + IN UINTN TokenNumber ) { PCD_PPI * PcdPpi; @@ -115,7 +128,7 @@ LibPcdGet8 ( UINT16 EFIAPI LibPcdGet16 ( - IN UINTN TokenNumber + IN UINTN TokenNumber ) { PCD_PPI *PcdPpi; @@ -138,7 +151,7 @@ LibPcdGet16 ( UINT32 EFIAPI LibPcdGet32 ( - IN UINTN TokenNumber + IN UINTN TokenNumber ) { PCD_PPI * PcdPpi; @@ -161,7 +174,7 @@ LibPcdGet32 ( UINT64 EFIAPI LibPcdGet64 ( - IN UINTN TokenNumber + IN UINTN TokenNumber ) { PCD_PPI * PcdPpi; @@ -184,7 +197,7 @@ LibPcdGet64 ( VOID * EFIAPI LibPcdGetPtr ( - IN UINTN TokenNumber + IN UINTN TokenNumber ) { PCD_PPI * PcdPpi; @@ -207,7 +220,7 @@ LibPcdGetPtr ( BOOLEAN EFIAPI LibPcdGetBool ( - IN UINTN TokenNumber + IN UINTN TokenNumber ) { PCD_PPI * PcdPpi; @@ -230,7 +243,7 @@ LibPcdGetBool ( UINTN EFIAPI LibPcdGetSize ( - IN UINTN TokenNumber + IN UINTN TokenNumber ) { PCD_PPI * PcdPpi; @@ -262,6 +275,8 @@ LibPcdGetEx8 ( { PCD_PPI * PcdPpi; + ASSERT (Guid != NULL); + PcdPpi = GetPcdPpiPtr (); return PcdPpi->Get8Ex (Guid, TokenNumber); @@ -289,6 +304,8 @@ LibPcdGetEx16 ( { PCD_PPI * PcdPpi; + ASSERT (Guid != NULL); + PcdPpi = GetPcdPpiPtr (); return PcdPpi->Get16Ex (Guid, TokenNumber); @@ -316,6 +333,8 @@ LibPcdGetEx32 ( { PCD_PPI * PcdPpi; + ASSERT (Guid != NULL); + PcdPpi = GetPcdPpiPtr (); return PcdPpi->Get32Ex (Guid, TokenNumber); @@ -344,6 +363,8 @@ LibPcdGetEx64 ( { PCD_PPI * PcdPpi; + ASSERT (Guid != NULL); + PcdPpi = GetPcdPpiPtr (); return PcdPpi->Get64Ex (Guid, TokenNumber); @@ -371,6 +392,8 @@ LibPcdGetExPtr ( { PCD_PPI * PcdPpi; + ASSERT (Guid != NULL); + PcdPpi = GetPcdPpiPtr (); return PcdPpi->GetPtrEx (Guid, TokenNumber); @@ -398,6 +421,8 @@ LibPcdGetExBool ( { PCD_PPI * PcdPpi; + ASSERT (Guid != NULL); + PcdPpi = GetPcdPpiPtr (); return PcdPpi->GetBoolEx (Guid, TokenNumber); @@ -425,6 +450,8 @@ LibPcdGetExSize ( { PCD_PPI * PcdPpi; + ASSERT (Guid != NULL); + PcdPpi = GetPcdPpiPtr (); return PcdPpi->GetSizeEx (Guid, TokenNumber); @@ -454,7 +481,6 @@ LibPcdSet8 ( PcdPpi = GetPcdPpiPtr (); - Status = PcdPpi->Set8 (TokenNumber, Value); ASSERT_EFI_ERROR (Status); @@ -486,7 +512,6 @@ LibPcdSet16 ( PcdPpi = GetPcdPpiPtr (); - Status = PcdPpi->Set16 (TokenNumber, Value); ASSERT_EFI_ERROR (Status); @@ -549,7 +574,6 @@ LibPcdSet64 ( PcdPpi = GetPcdPpiPtr (); - Status = PcdPpi->Set64 (TokenNumber, Value); ASSERT_EFI_ERROR (Status); @@ -561,10 +585,20 @@ 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. @@ -573,21 +607,29 @@ LibPcdSet64 ( VOID * EFIAPI LibPcdSetPtr ( - IN UINTN TokenNumber, - IN CONST VOID *Value + IN UINTN TokenNumber, + IN OUT UINTN *SizeOfBuffer, + IN VOID *Buffer ) { EFI_STATUS Status; - PCD_PPI * PcdPpi; + PCD_PPI *PcdPpi; - PcdPpi = GetPcdPpiPtr (); + ASSERT (SizeOfBuffer != NULL); + if (*SizeOfBuffer > 0) { + ASSERT (Buffer != NULL); + } - Status = PcdPpi->SetPtr (TokenNumber, Value); + PcdPpi = GetPcdPpiPtr (); + + Status = PcdPpi->SetPtr (TokenNumber, SizeOfBuffer, Buffer); - ASSERT_EFI_ERROR (Status); + if (EFI_ERROR (Status)) { + return NULL; + } - return (VOID *)Value; + return Buffer; } @@ -614,7 +656,6 @@ LibPcdSetBool ( PcdPpi = GetPcdPpiPtr (); - Status = PcdPpi->SetBool (TokenNumber, Value); ASSERT_EFI_ERROR (Status); @@ -650,6 +691,7 @@ LibPcdSetEx8 ( PcdPpi = GetPcdPpiPtr (); + ASSERT (Guid != NULL); Status = PcdPpi->Set8Ex (Guid, TokenNumber, Value); @@ -686,7 +728,7 @@ LibPcdSetEx16 ( PcdPpi = GetPcdPpiPtr (); - + ASSERT (Guid != NULL); Status = PcdPpi->Set16Ex (Guid, TokenNumber, Value); ASSERT_EFI_ERROR (Status); @@ -719,7 +761,7 @@ LibPcdSetEx32 ( { EFI_STATUS Status; PCD_PPI * PcdPpi; - + ASSERT (Guid != NULL); PcdPpi = GetPcdPpiPtr (); @@ -755,7 +797,7 @@ LibPcdSetEx64 ( { EFI_STATUS Status; PCD_PPI * PcdPpi; - + ASSERT (Guid != NULL); PcdPpi = GetPcdPpiPtr (); @@ -769,38 +811,48 @@ 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; - PCD_PPI * PcdPpi; - + EFI_STATUS Status; + PCD_PPI *PcdPpi; + ASSERT (SizeOfBuffer != NULL); + if (*SizeOfBuffer > 0) { + ASSERT (Buffer != NULL); + } + ASSERT (Guid != NULL); PcdPpi = GetPcdPpiPtr (); + Status = PcdPpi->SetPtrEx (Guid, TokenNumber, SizeOfBuffer, Buffer); - Status = PcdPpi->SetPtrEx (Guid, TokenNumber, Value); + if (EFI_ERROR (Status)) { + return NULL; + } - ASSERT_EFI_ERROR (Status); - - return (VOID *)Value; + return Buffer; } @@ -831,7 +883,7 @@ LibPcdSetExBool ( PcdPpi = GetPcdPpiPtr (); - + ASSERT (Guid != NULL); Status = PcdPpi->SetBoolEx (Guid, TokenNumber, Value); ASSERT_EFI_ERROR (Status); @@ -871,7 +923,7 @@ LibPcdCallbackOnSet ( PcdPpi = GetPcdPpiPtr (); - Status = PcdPpi->CallbackOnSet (TokenNumber, Guid, NotificationFunction); + Status = PcdPpi->CallbackOnSet (Guid, TokenNumber, NotificationFunction); ASSERT_EFI_ERROR (Status); @@ -905,7 +957,7 @@ LibPcdCancelCallback ( PcdPpi = GetPcdPpiPtr (); - Status = PcdPpi->CancelCallback (TokenNumber, Guid, NotificationFunction); + Status = PcdPpi->CancelCallback (Guid, TokenNumber, NotificationFunction); ASSERT_EFI_ERROR (Status); @@ -927,14 +979,51 @@ 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; + PCD_PPI * PcdPpi; + + PcdPpi = GetPcdPpiPtr (); + + + Status = PcdPpi->GetNextToken (Guid, &TokenNumber); + + ASSERT_EFI_ERROR (Status); + + 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; @@ -943,9 +1032,59 @@ LibPcdGetNextToken ( PcdPpi = GetPcdPpiPtr (); - Status = PcdPpi->GetNextToken (Guid, TokenNumber); + Status = PcdPpi->GetNextTokenSpace (&Guid); ASSERT_EFI_ERROR (Status); - return (*TokenNumber); + 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; +} + +