Remove CONSTRUCTOR from DxePcdLib aligning the DxePcdLib design with the PeiPcdLib and reduces the number of CONSTRUCTORs that have to be run for most DXE modules.

git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@11182 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
mdkinney
2010-12-18 00:22:08 +00:00
parent 5bd2d2cb03
commit b35a5f731c
2 changed files with 71 additions and 92 deletions

View File

@ -24,43 +24,53 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#include <Library/UefiBootServicesTableLib.h> #include <Library/UefiBootServicesTableLib.h>
#include <Library/BaseMemoryLib.h> #include <Library/BaseMemoryLib.h>
PCD_PROTOCOL *mPcd = NULL; PCD_PROTOCOL *mPcd = NULL;
EFI_PCD_PROTOCOL *mPiPcd = NULL; EFI_PCD_PROTOCOL *mPiPcd = NULL;
/** /**
The constructor function caches the PCD_PROTOCOL pointer. Retrieves the PI PCD protocol from the handle database.
@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.
**/ **/
EFI_STATUS EFI_PCD_PROTOCOL *
EFIAPI EFIAPI
PcdLibConstructor ( GetPiPcdProtocol (
IN EFI_HANDLE ImageHandle, VOID
IN EFI_SYSTEM_TABLE *SystemTable
) )
{ {
EFI_STATUS Status; EFI_STATUS Status;
// if (mPiPcd == NULL) {
// PCD protocol need to be installed before the module access Dynamic type PCD. //
// But dynamic type PCD is not required in PI 1.2 specification. // PI Pcd protocol defined in PI 1.2 vol3 should be installed before the module
// // access DynamicEx type PCD.
gBS->LocateProtocol (&gPcdProtocolGuid, NULL, (VOID **)&mPcd); //
Status = gBS->LocateProtocol (&gEfiPcdProtocolGuid, NULL, (VOID **) &mPiPcd);
ASSERT_EFI_ERROR (Status);
ASSERT (mPiPcd != NULL);
}
return mPiPcd;
}
// /**
// PI Pcd protocol defined in PI 1.2 vol3 should be installed before the module Retrieves the PCD protocol from the handle database.
// access DynamicEx type PCD. **/
// PCD_PROTOCOL *
Status = gBS->LocateProtocol (&gEfiPcdProtocolGuid, NULL, (VOID **) &mPiPcd); EFIAPI
GetPcdProtocol (
VOID
)
{
EFI_STATUS Status;
ASSERT_EFI_ERROR (Status); if (mPcd == NULL) {
ASSERT (mPiPcd!= NULL); //
// PCD protocol need to be installed before the module access Dynamic type PCD.
return Status; // But dynamic type PCD is not required in PI 1.2 specification.
//
Status = gBS->LocateProtocol (&gPcdProtocolGuid, NULL, (VOID **)&mPcd);
ASSERT_EFI_ERROR (Status);
ASSERT (mPcd != NULL);
}
return mPcd;
} }
@ -82,10 +92,9 @@ LibPcdSetSku (
IN UINTN SkuId IN UINTN SkuId
) )
{ {
ASSERT (mPcd != NULL);
ASSERT (SkuId < PCD_MAX_SKU_ID); ASSERT (SkuId < PCD_MAX_SKU_ID);
mPcd->SetSku (SkuId); GetPcdProtocol()->SetSku (SkuId);
return SkuId; return SkuId;
} }
@ -108,8 +117,7 @@ LibPcdGet8 (
IN UINTN TokenNumber IN UINTN TokenNumber
) )
{ {
ASSERT (mPcd != NULL); return GetPcdProtocol()->Get8 (TokenNumber);
return mPcd->Get8 (TokenNumber);
} }
@ -130,8 +138,7 @@ LibPcdGet16 (
IN UINTN TokenNumber IN UINTN TokenNumber
) )
{ {
ASSERT (mPcd != NULL); return GetPcdProtocol()->Get16 (TokenNumber);
return mPcd->Get16 (TokenNumber);
} }
@ -152,8 +159,7 @@ LibPcdGet32 (
IN UINTN TokenNumber IN UINTN TokenNumber
) )
{ {
ASSERT (mPcd != NULL); return GetPcdProtocol()->Get32 (TokenNumber);
return mPcd->Get32 (TokenNumber);
} }
@ -174,8 +180,7 @@ LibPcdGet64 (
IN UINTN TokenNumber IN UINTN TokenNumber
) )
{ {
ASSERT (mPcd != NULL); return GetPcdProtocol()->Get64 (TokenNumber);
return mPcd->Get64 (TokenNumber);
} }
@ -196,8 +201,7 @@ LibPcdGetPtr (
IN UINTN TokenNumber IN UINTN TokenNumber
) )
{ {
ASSERT (mPcd != NULL); return GetPcdProtocol()->GetPtr (TokenNumber);
return mPcd->GetPtr (TokenNumber);
} }
@ -218,8 +222,7 @@ LibPcdGetBool (
IN UINTN TokenNumber IN UINTN TokenNumber
) )
{ {
ASSERT (mPcd != NULL); return GetPcdProtocol()->GetBool (TokenNumber);
return mPcd->GetBool (TokenNumber);
} }
@ -238,8 +241,7 @@ LibPcdGetSize (
IN UINTN TokenNumber IN UINTN TokenNumber
) )
{ {
ASSERT (mPcd != NULL); return GetPcdProtocol()->GetSize (TokenNumber);
return mPcd->GetSize (TokenNumber);
} }
@ -267,7 +269,7 @@ LibPcdGetEx8 (
{ {
ASSERT (Guid != NULL); ASSERT (Guid != NULL);
return mPiPcd->Get8 (Guid, TokenNumber); return GetPiPcdProtocol()->Get8 (Guid, TokenNumber);
} }
@ -294,7 +296,7 @@ LibPcdGetEx16 (
{ {
ASSERT (Guid != NULL); ASSERT (Guid != NULL);
return mPiPcd->Get16 (Guid, TokenNumber); return GetPiPcdProtocol()->Get16 (Guid, TokenNumber);
} }
@ -318,7 +320,7 @@ LibPcdGetEx32 (
{ {
ASSERT (Guid != NULL); ASSERT (Guid != NULL);
return mPiPcd->Get32 (Guid, TokenNumber); return GetPiPcdProtocol()->Get32 (Guid, TokenNumber);
} }
@ -346,7 +348,7 @@ LibPcdGetEx64 (
{ {
ASSERT (Guid != NULL); ASSERT (Guid != NULL);
return mPiPcd->Get64 (Guid, TokenNumber); return GetPiPcdProtocol()->Get64 (Guid, TokenNumber);
} }
@ -374,7 +376,7 @@ LibPcdGetExPtr (
{ {
ASSERT (Guid != NULL); ASSERT (Guid != NULL);
return mPiPcd->GetPtr (Guid, TokenNumber); return GetPiPcdProtocol()->GetPtr (Guid, TokenNumber);
} }
@ -402,7 +404,7 @@ LibPcdGetExBool (
{ {
ASSERT (Guid != NULL); ASSERT (Guid != NULL);
return mPiPcd->GetBool (Guid, TokenNumber); return GetPiPcdProtocol()->GetBool (Guid, TokenNumber);
} }
@ -430,7 +432,7 @@ LibPcdGetExSize (
{ {
ASSERT (Guid != NULL); ASSERT (Guid != NULL);
return mPiPcd->GetSize (Guid, TokenNumber); return GetPiPcdProtocol()->GetSize (Guid, TokenNumber);
} }
@ -456,9 +458,7 @@ LibPcdSet8 (
{ {
EFI_STATUS Status; EFI_STATUS Status;
ASSERT (mPcd != NULL); Status = GetPcdProtocol()->Set8 (TokenNumber, Value);
Status = mPcd->Set8 (TokenNumber, Value);
ASSERT_EFI_ERROR (Status); ASSERT_EFI_ERROR (Status);
return Value; return Value;
@ -487,9 +487,7 @@ LibPcdSet16 (
{ {
EFI_STATUS Status; EFI_STATUS Status;
ASSERT (mPcd != NULL); Status = GetPcdProtocol()->Set16 (TokenNumber, Value);
Status = mPcd->Set16 (TokenNumber, Value);
ASSERT_EFI_ERROR (Status); ASSERT_EFI_ERROR (Status);
return Value; return Value;
@ -518,9 +516,7 @@ LibPcdSet32 (
{ {
EFI_STATUS Status; EFI_STATUS Status;
ASSERT (mPcd != NULL); Status = GetPcdProtocol()->Set32 (TokenNumber, Value);
Status = mPcd->Set32 (TokenNumber, Value);
ASSERT_EFI_ERROR (Status); ASSERT_EFI_ERROR (Status);
return Value; return Value;
@ -549,9 +545,7 @@ LibPcdSet64 (
{ {
EFI_STATUS Status; EFI_STATUS Status;
ASSERT (mPcd != NULL); Status = GetPcdProtocol()->Set64 (TokenNumber, Value);
Status = mPcd->Set64 (TokenNumber, Value);
ASSERT_EFI_ERROR (Status); ASSERT_EFI_ERROR (Status);
return Value; return Value;
@ -591,20 +585,18 @@ LibPcdSetPtr (
{ {
EFI_STATUS Status; EFI_STATUS Status;
ASSERT (mPcd != NULL);
ASSERT (SizeOfBuffer != NULL); ASSERT (SizeOfBuffer != NULL);
if (*SizeOfBuffer > 0) { if (*SizeOfBuffer > 0) {
ASSERT (Buffer != NULL); ASSERT (Buffer != NULL);
} }
Status = mPcd->SetPtr (TokenNumber, SizeOfBuffer, (VOID *) Buffer); Status = GetPcdProtocol()->SetPtr (TokenNumber, SizeOfBuffer, (VOID *) Buffer);
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
return NULL; return NULL;
} }
return (VOID *) Buffer; return (VOID *)Buffer;
} }
@ -630,9 +622,7 @@ LibPcdSetBool (
{ {
EFI_STATUS Status; EFI_STATUS Status;
ASSERT (mPcd != NULL); Status = GetPcdProtocol()->SetBool (TokenNumber, Value);
Status = mPcd->SetBool (TokenNumber, Value);
ASSERT_EFI_ERROR (Status); ASSERT_EFI_ERROR (Status);
return Value; return Value;
@ -668,8 +658,7 @@ LibPcdSetEx8 (
ASSERT (Guid != NULL); ASSERT (Guid != NULL);
Status = mPiPcd->Set8 (Guid, TokenNumber, Value); Status = GetPiPcdProtocol()->Set8 (Guid, TokenNumber, Value);
ASSERT_EFI_ERROR (Status); ASSERT_EFI_ERROR (Status);
return Value; return Value;
@ -705,8 +694,7 @@ LibPcdSetEx16 (
ASSERT (Guid != NULL); ASSERT (Guid != NULL);
Status = mPiPcd->Set16 (Guid, TokenNumber, Value); Status = GetPiPcdProtocol()->Set16 (Guid, TokenNumber, Value);
ASSERT_EFI_ERROR (Status); ASSERT_EFI_ERROR (Status);
return Value; return Value;
@ -742,8 +730,7 @@ LibPcdSetEx32 (
ASSERT (Guid != NULL); ASSERT (Guid != NULL);
Status = mPiPcd->Set32 (Guid, TokenNumber, Value); Status = GetPiPcdProtocol()->Set32 (Guid, TokenNumber, Value);
ASSERT_EFI_ERROR (Status); ASSERT_EFI_ERROR (Status);
return Value; return Value;
@ -778,8 +765,7 @@ LibPcdSetEx64 (
ASSERT (Guid != NULL); ASSERT (Guid != NULL);
Status = mPiPcd->Set64 (Guid, TokenNumber, Value); Status = GetPiPcdProtocol()->Set64 (Guid, TokenNumber, Value);
ASSERT_EFI_ERROR (Status); ASSERT_EFI_ERROR (Status);
return Value; return Value;
@ -806,7 +792,7 @@ LibPcdSetEx64 (
@param[in, out] SizeOfBuffer The size, in bytes, of Buffer. @param[in, out] SizeOfBuffer The size, in bytes, of Buffer.
@param[in] Buffer A pointer to the buffer to set. @param[in] Buffer A pointer to the buffer to set.
@return Return the pinter to the buffer been set. @return Return the pointer to the buffer been set.
**/ **/
VOID * VOID *
@ -828,8 +814,7 @@ LibPcdSetExPtr (
ASSERT (Buffer != NULL); ASSERT (Buffer != NULL);
} }
Status = mPiPcd->SetPtr (Guid, TokenNumber, SizeOfBuffer, Buffer); Status = GetPiPcdProtocol()->SetPtr (Guid, TokenNumber, SizeOfBuffer, Buffer);
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
return NULL; return NULL;
} }
@ -867,8 +852,7 @@ LibPcdSetExBool (
ASSERT (Guid != NULL); ASSERT (Guid != NULL);
Status = mPiPcd->SetBool (Guid, TokenNumber, Value); Status = GetPiPcdProtocol()->SetBool (Guid, TokenNumber, Value);
ASSERT_EFI_ERROR (Status); ASSERT_EFI_ERROR (Status);
return Value; return Value;
@ -904,8 +888,7 @@ LibPcdCallbackOnSet (
ASSERT (NotificationFunction != NULL); ASSERT (NotificationFunction != NULL);
Status = mPiPcd->CallbackOnSet (Guid, TokenNumber, (EFI_PCD_PROTOCOL_CALLBACK) NotificationFunction); Status = GetPiPcdProtocol()->CallbackOnSet (Guid, TokenNumber, (EFI_PCD_PROTOCOL_CALLBACK) NotificationFunction);
ASSERT_EFI_ERROR (Status); ASSERT_EFI_ERROR (Status);
return; return;
@ -938,8 +921,7 @@ LibPcdCancelCallback (
ASSERT (NotificationFunction != NULL); ASSERT (NotificationFunction != NULL);
Status = mPiPcd->CancelCallback (Guid, TokenNumber, (EFI_PCD_PROTOCOL_CALLBACK) NotificationFunction); Status = GetPiPcdProtocol()->CancelCallback (Guid, TokenNumber, (EFI_PCD_PROTOCOL_CALLBACK) NotificationFunction);
ASSERT_EFI_ERROR (Status); ASSERT_EFI_ERROR (Status);
return; return;
@ -975,8 +957,7 @@ LibPcdGetNextToken (
{ {
EFI_STATUS Status; EFI_STATUS Status;
Status = mPiPcd->GetNextToken (Guid, &TokenNumber); Status = GetPiPcdProtocol()->GetNextToken (Guid, &TokenNumber);
ASSERT_EFI_ERROR (Status); ASSERT_EFI_ERROR (Status);
return TokenNumber; return TokenNumber;
@ -1005,11 +986,10 @@ LibPcdGetNextTokenSpace (
{ {
EFI_STATUS Status; EFI_STATUS Status;
Status = mPiPcd->GetNextTokenSpace (&TokenSpaceGuid); Status = GetPiPcdProtocol()->GetNextTokenSpace (&TokenSpaceGuid);
ASSERT_EFI_ERROR (Status); ASSERT_EFI_ERROR (Status);
return (GUID *) TokenSpaceGuid; return (GUID *)TokenSpaceGuid;
} }

View File

@ -32,7 +32,6 @@
MODULE_TYPE = DXE_DRIVER MODULE_TYPE = DXE_DRIVER
VERSION_STRING = 1.0 VERSION_STRING = 1.0
LIBRARY_CLASS = PcdLib|DXE_CORE DXE_DRIVER DXE_RUNTIME_DRIVER DXE_SAL_DRIVER DXE_SMM_DRIVER SMM_CORE UEFI_APPLICATION UEFI_DRIVER LIBRARY_CLASS = PcdLib|DXE_CORE DXE_DRIVER DXE_RUNTIME_DRIVER DXE_SAL_DRIVER DXE_SMM_DRIVER SMM_CORE UEFI_APPLICATION UEFI_DRIVER
CONSTRUCTOR = PcdLibConstructor
# #
# VALID_ARCHITECTURES = IA32 X64 IPF EBC # VALID_ARCHITECTURES = IA32 X64 IPF EBC