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
diff --git a/MdePkg/Library/DxePcdLib/DxePcdLib.c b/MdePkg/Library/DxePcdLib/DxePcdLib.c
index 3ab27f4..a7303e8 100644
--- a/MdePkg/Library/DxePcdLib/DxePcdLib.c
+++ b/MdePkg/Library/DxePcdLib/DxePcdLib.c
@@ -24,43 +24,53 @@
 #include <Library/UefiBootServicesTableLib.h>

 #include <Library/BaseMemoryLib.h>

 

-PCD_PROTOCOL     *mPcd = NULL;

+PCD_PROTOCOL     *mPcd   = NULL;

 EFI_PCD_PROTOCOL *mPiPcd = NULL;

 

 /**

-  The constructor function caches the PCD_PROTOCOL pointer.

-

-  @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.

-

+  Retrieves the PI PCD protocol from the handle database.

 **/

-EFI_STATUS

+EFI_PCD_PROTOCOL *

 EFIAPI

-PcdLibConstructor (

-  IN EFI_HANDLE        ImageHandle,

-  IN EFI_SYSTEM_TABLE  *SystemTable

+GetPiPcdProtocol (

+  VOID

   )

 {

   EFI_STATUS  Status;

 

-  //

-  // 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.

-  // 

-  gBS->LocateProtocol (&gPcdProtocolGuid, NULL, (VOID **)&mPcd);

-  

-  //

-  // PI Pcd protocol defined in PI 1.2 vol3 should be installed before the module 

-  // access DynamicEx type PCD.

-  //

-  Status = gBS->LocateProtocol (&gEfiPcdProtocolGuid, NULL, (VOID **) &mPiPcd);

-  

-  ASSERT_EFI_ERROR (Status);

-  ASSERT (mPiPcd!= NULL);

+  if (mPiPcd == NULL) {

+    //

+    // PI Pcd protocol defined in PI 1.2 vol3 should be installed before the module 

+    // access DynamicEx type PCD.

+    //

+    Status = gBS->LocateProtocol (&gEfiPcdProtocolGuid, NULL, (VOID **) &mPiPcd);

+    ASSERT_EFI_ERROR (Status);

+    ASSERT (mPiPcd != NULL);

+  }

+  return mPiPcd;

+}

 

-  return Status;

+/**

+  Retrieves the PCD protocol from the handle database.

+**/

+PCD_PROTOCOL *

+EFIAPI

+GetPcdProtocol (

+  VOID

+  )

+{

+  EFI_STATUS  Status;

+

+  if (mPcd == 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.

+    // 

+    Status = gBS->LocateProtocol (&gPcdProtocolGuid, NULL, (VOID **)&mPcd);

+    ASSERT_EFI_ERROR (Status);

+    ASSERT (mPcd != NULL);

+  }

+  return mPcd;

 }

 

 

@@ -82,10 +92,9 @@
   IN UINTN   SkuId

   )

 {

-  ASSERT (mPcd != NULL);

   ASSERT (SkuId < PCD_MAX_SKU_ID);

 

-  mPcd->SetSku (SkuId);

+  GetPcdProtocol()->SetSku (SkuId);

 

   return SkuId;

 }

@@ -108,8 +117,7 @@
   IN UINTN             TokenNumber

   )

 {

-  ASSERT (mPcd != NULL);

-  return mPcd->Get8 (TokenNumber);

+  return GetPcdProtocol()->Get8 (TokenNumber);

 }

 

 

@@ -130,8 +138,7 @@
   IN UINTN             TokenNumber

   )

 {

-  ASSERT (mPcd != NULL);

-  return mPcd->Get16 (TokenNumber);

+  return GetPcdProtocol()->Get16 (TokenNumber);

 }

 

 

@@ -152,8 +159,7 @@
   IN UINTN             TokenNumber

   )

 {

-  ASSERT (mPcd != NULL);

-  return mPcd->Get32 (TokenNumber);

+  return GetPcdProtocol()->Get32 (TokenNumber);

 }

 

 

@@ -174,8 +180,7 @@
   IN UINTN             TokenNumber

   )

 {

-  ASSERT (mPcd != NULL);

-  return mPcd->Get64 (TokenNumber);

+  return GetPcdProtocol()->Get64 (TokenNumber);

 }

 

 

@@ -196,8 +201,7 @@
   IN UINTN             TokenNumber

   )

 {

-  ASSERT (mPcd != NULL);

-  return mPcd->GetPtr (TokenNumber);

+  return GetPcdProtocol()->GetPtr (TokenNumber);

 }

 

 

@@ -218,8 +222,7 @@
   IN UINTN             TokenNumber

   )

 {

-  ASSERT (mPcd != NULL);

-  return mPcd->GetBool (TokenNumber);

+  return GetPcdProtocol()->GetBool (TokenNumber);

 }

 

 

@@ -238,8 +241,7 @@
   IN UINTN             TokenNumber

   )

 {

-  ASSERT (mPcd != NULL);

-  return mPcd->GetSize (TokenNumber);

+  return GetPcdProtocol()->GetSize (TokenNumber);

 }

 

 

@@ -267,7 +269,7 @@
 {

   ASSERT (Guid != NULL);

   

-  return mPiPcd->Get8 (Guid, TokenNumber);

+  return GetPiPcdProtocol()->Get8 (Guid, TokenNumber);

 }

 

 

@@ -294,7 +296,7 @@
 {

   ASSERT (Guid != NULL);

 

-  return mPiPcd->Get16 (Guid, TokenNumber);

+  return GetPiPcdProtocol()->Get16 (Guid, TokenNumber);

 }

 

 

@@ -318,7 +320,7 @@
 {

   ASSERT (Guid != NULL);

 

-  return mPiPcd->Get32 (Guid, TokenNumber);

+  return GetPiPcdProtocol()->Get32 (Guid, TokenNumber);

 }

 

 

@@ -346,7 +348,7 @@
 {

   ASSERT (Guid != NULL);

   

-  return mPiPcd->Get64 (Guid, TokenNumber);

+  return GetPiPcdProtocol()->Get64 (Guid, TokenNumber);

 }

 

 

@@ -374,7 +376,7 @@
 {

   ASSERT (Guid != NULL);

 

-  return mPiPcd->GetPtr (Guid, TokenNumber);

+  return GetPiPcdProtocol()->GetPtr (Guid, TokenNumber);

 }

 

 

@@ -402,7 +404,7 @@
 {

   ASSERT (Guid != NULL);

 

-  return mPiPcd->GetBool (Guid, TokenNumber);

+  return GetPiPcdProtocol()->GetBool (Guid, TokenNumber);

 }

 

 

@@ -430,7 +432,7 @@
 {

   ASSERT (Guid != NULL);

 

-  return mPiPcd->GetSize (Guid, TokenNumber);

+  return GetPiPcdProtocol()->GetSize (Guid, TokenNumber);

 }

 

 

@@ -456,9 +458,7 @@
 {

   EFI_STATUS Status;

 

-  ASSERT (mPcd != NULL);

-  Status = mPcd->Set8 (TokenNumber, Value);

-

+  Status = GetPcdProtocol()->Set8 (TokenNumber, Value);

   ASSERT_EFI_ERROR (Status);

   

   return Value;

@@ -487,9 +487,7 @@
 {

   EFI_STATUS Status;

 

-  ASSERT (mPcd != NULL);

-  Status = mPcd->Set16 (TokenNumber, Value);

-

+  Status = GetPcdProtocol()->Set16 (TokenNumber, Value);

   ASSERT_EFI_ERROR (Status);

   

   return Value;

@@ -518,9 +516,7 @@
 {

   EFI_STATUS Status;

   

-  ASSERT (mPcd != NULL);

-  Status = mPcd->Set32 (TokenNumber, Value);

-

+  Status = GetPcdProtocol()->Set32 (TokenNumber, Value);

   ASSERT_EFI_ERROR (Status);

 

   return Value;

@@ -549,9 +545,7 @@
 {

   EFI_STATUS Status;

 

-  ASSERT (mPcd != NULL);

-  Status = mPcd->Set64 (TokenNumber, Value);

-

+  Status = GetPcdProtocol()->Set64 (TokenNumber, Value);

   ASSERT_EFI_ERROR (Status);

 

   return Value;

@@ -591,20 +585,18 @@
 {

   EFI_STATUS Status;

 

-  ASSERT (mPcd != NULL);

   ASSERT (SizeOfBuffer != NULL);

 

   if (*SizeOfBuffer > 0) {

     ASSERT (Buffer != NULL);

   }

 

-  Status = mPcd->SetPtr (TokenNumber, SizeOfBuffer, (VOID *) Buffer);

-

+  Status = GetPcdProtocol()->SetPtr (TokenNumber, SizeOfBuffer, (VOID *) Buffer);

   if (EFI_ERROR (Status)) {

     return NULL;

   }

 

-  return (VOID *) Buffer;

+  return (VOID *)Buffer;

 }

 

 

@@ -630,9 +622,7 @@
 {

   EFI_STATUS Status;

 

-  ASSERT (mPcd != NULL);

-  Status = mPcd->SetBool (TokenNumber, Value);

-

+  Status = GetPcdProtocol()->SetBool (TokenNumber, Value);

   ASSERT_EFI_ERROR (Status);

 

   return Value;

@@ -668,8 +658,7 @@
 

   ASSERT (Guid != NULL);

 

-  Status = mPiPcd->Set8 (Guid, TokenNumber, Value);

-

+  Status = GetPiPcdProtocol()->Set8 (Guid, TokenNumber, Value);

   ASSERT_EFI_ERROR (Status);

 

   return Value;

@@ -705,8 +694,7 @@
 

   ASSERT (Guid != NULL);

 

-  Status = mPiPcd->Set16 (Guid, TokenNumber, Value);

-

+  Status = GetPiPcdProtocol()->Set16 (Guid, TokenNumber, Value);

   ASSERT_EFI_ERROR (Status);

 

   return Value;

@@ -742,8 +730,7 @@
 

   ASSERT (Guid != NULL);

 

-  Status = mPiPcd->Set32 (Guid, TokenNumber, Value);

-

+  Status = GetPiPcdProtocol()->Set32 (Guid, TokenNumber, Value);

   ASSERT_EFI_ERROR (Status);

 

   return Value;

@@ -778,8 +765,7 @@
 

   ASSERT (Guid != NULL);

 

-  Status = mPiPcd->Set64 (Guid, TokenNumber, Value);

-

+  Status = GetPiPcdProtocol()->Set64 (Guid, TokenNumber, Value);

   ASSERT_EFI_ERROR (Status);

 

   return Value;

@@ -806,7 +792,7 @@
   @param[in, out] SizeOfBuffer  The size, in bytes, of Buffer.

   @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 *

@@ -828,8 +814,7 @@
     ASSERT (Buffer != NULL);

   }

 

-  Status = mPiPcd->SetPtr (Guid, TokenNumber, SizeOfBuffer, Buffer);

-

+  Status = GetPiPcdProtocol()->SetPtr (Guid, TokenNumber, SizeOfBuffer, Buffer);

   if (EFI_ERROR (Status)) {

     return NULL;

   }

@@ -867,8 +852,7 @@
 

   ASSERT (Guid != NULL);

 

-  Status = mPiPcd->SetBool (Guid, TokenNumber, Value);

-

+  Status = GetPiPcdProtocol()->SetBool (Guid, TokenNumber, Value);

   ASSERT_EFI_ERROR (Status);

 

   return Value;

@@ -904,8 +888,7 @@
 

   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);

 

   return;

@@ -938,8 +921,7 @@
 

   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);

 

   return;

@@ -975,8 +957,7 @@
 {

   EFI_STATUS Status;

 

-  Status = mPiPcd->GetNextToken (Guid, &TokenNumber);

-

+  Status = GetPiPcdProtocol()->GetNextToken (Guid, &TokenNumber);

   ASSERT_EFI_ERROR (Status);

 

   return TokenNumber;

@@ -1005,11 +986,10 @@
 {

   EFI_STATUS Status;

 

-  Status = mPiPcd->GetNextTokenSpace (&TokenSpaceGuid);

-

+  Status = GetPiPcdProtocol()->GetNextTokenSpace (&TokenSpaceGuid);

   ASSERT_EFI_ERROR (Status);

 

-  return (GUID *) TokenSpaceGuid;

+  return (GUID *)TokenSpaceGuid;

 }

 

 

diff --git a/MdePkg/Library/DxePcdLib/DxePcdLib.inf b/MdePkg/Library/DxePcdLib/DxePcdLib.inf
index 22c174f..8936090 100644
--- a/MdePkg/Library/DxePcdLib/DxePcdLib.inf
+++ b/MdePkg/Library/DxePcdLib/DxePcdLib.inf
@@ -32,7 +32,6 @@
   MODULE_TYPE                    = DXE_DRIVER

   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 

-  CONSTRUCTOR                    = PcdLibConstructor

 

 #

 #  VALID_ARCHITECTURES           = IA32 X64 IPF EBC