[edk2,16/21] ArmVirtPkg/BaseCachingPciExpressLib: construct at first invocation

Message ID 1459959319-19293-17-git-send-email-ard.biesheuvel@linaro.org
State Superseded
Headers show

Commit Message

Ard Biesheuvel April 6, 2016, 4:15 p.m.
Instead of using a constructor, which may reference a dynamic PCD which is
set by the DXE entry point of its user, defer the assignment of the global
mPciExpressBaseAddress until the first the library is actually invoked.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>

---
 ArmVirtPkg/Library/BaseCachingPciExpressLib/BaseCachingPciExpressLib.inf |  1 -
 ArmVirtPkg/Library/BaseCachingPciExpressLib/PciExpressLib.c              | 16 ++++------------
 2 files changed, 4 insertions(+), 13 deletions(-)

-- 
2.5.0

_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel

Patch

diff --git a/ArmVirtPkg/Library/BaseCachingPciExpressLib/BaseCachingPciExpressLib.inf b/ArmVirtPkg/Library/BaseCachingPciExpressLib/BaseCachingPciExpressLib.inf
index f6a346d49f22..5374f1b9a369 100644
--- a/ArmVirtPkg/Library/BaseCachingPciExpressLib/BaseCachingPciExpressLib.inf
+++ b/ArmVirtPkg/Library/BaseCachingPciExpressLib/BaseCachingPciExpressLib.inf
@@ -23,7 +23,6 @@  [Defines]
   MODULE_TYPE                    = BASE
   VERSION_STRING                 = 1.0
   LIBRARY_CLASS                  = PciExpressLib|DXE_DRIVER UEFI_DRIVER UEFI_APPLICATION
-  CONSTRUCTOR                    = PciExpressLibInitialize
 
 #
 #  VALID_ARCHITECTURES           = ARM AARCH64
diff --git a/ArmVirtPkg/Library/BaseCachingPciExpressLib/PciExpressLib.c b/ArmVirtPkg/Library/BaseCachingPciExpressLib/PciExpressLib.c
index 6479f53b3714..6135d49a7854 100644
--- a/ArmVirtPkg/Library/BaseCachingPciExpressLib/PciExpressLib.c
+++ b/ArmVirtPkg/Library/BaseCachingPciExpressLib/PciExpressLib.c
@@ -68,18 +68,7 @@  PciExpressRegisterForRuntimeAccess (
   return RETURN_UNSUPPORTED;
 }
 
-STATIC UINT64 mPciExpressBaseAddress;
-
-RETURN_STATUS
-EFIAPI
-PciExpressLibInitialize (
-  VOID
-  )
-{
-  mPciExpressBaseAddress = PcdGet64 (PcdPciExpressBaseAddress);
-  return RETURN_SUCCESS;
-}
-
+STATIC UINT64 mPciExpressBaseAddress = 0xFFFFFFFFFFFFFFFFULL;
 
 /**
   Gets the base address of PCI Express.
@@ -92,6 +81,9 @@  GetPciExpressBaseAddress (
   VOID
   )
 {
+  if (mPciExpressBaseAddress == 0xFFFFFFFFFFFFFFFFULL) {
+    mPciExpressBaseAddress = PcdGet64 (PcdPciExpressBaseAddress);
+  }
   return (VOID*)(UINTN) mPciExpressBaseAddress;
 }