public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [PATCH v2 00/14] ArmVirtPkg: get rid of ArmPlatformLib
@ 2017-11-22 10:07 Ard Biesheuvel
  2017-11-22 10:07 ` [PATCH v2 01/14] ArmVirtPkg/PrePi: run all library constructors by hand Ard Biesheuvel
                   ` (14 more replies)
  0 siblings, 15 replies; 21+ messages in thread
From: Ard Biesheuvel @ 2017-11-22 10:07 UTC (permalink / raw)
  To: edk2-devel, lersek; +Cc: Ard Biesheuvel

ArmPlatformLib is a mixed bag of platform specific hooks, some of which
are called from early startup code, and some of which are called from C
code, to get the boot mode, memory layout etc.

This library class is tightly coupled to the old ARM implementations that
ran some parts of UEFI in the secure world, and booted all cores into SEC.
Also, the fact that both PrePi and PrePeiCore use ArmPlatformLib makes it
difficult to use PEI phase features such as PPI depexes. It would be better
if we could get rid of it completely, or at least not require each platform
to implement it in its entirety.

So as a first step towards phasing out ArmPlatformLib to the extent possible,
let's remove it from ArmVirtPkg. For ArmVirtXen and ArmVirtQemuKernel, we can
get rid of it completely. For ArmVirtQemu, we can't, but we can still remove
our own implementation by switching to the NULL implementation from
ArmPlatformPkg (which does require a minimal tweak in patch #1). Further
reductions of the scope of ArmPlatformLib will be reflected in that library
without the need for further changes to ArmVirtPkg.

v2: drop ArmPlatformPkg prereq patch, it is merged now
    use constructor instead of PEIM depex ordering to ensure ArmVirtQemu's
    PcdSystemMemorySize PCD is set before being consumed
    add acks from Laszlo

Ard Biesheuvel (14):
  ArmVirtPkg/PrePi: run all library constructors by hand
  ArmVirtPkg/PrePi: remove unused GetPlatformPpi() function
  ArmVirtPkg/PrePi: remove bogus primary core check
  ArmVirtPkg/PrePi: move DRAM discovery code into PrePi
  ArmVirtPkg/PrePi: remove dependency on ArmPlatformLib
  ArmVirtPkg/PrePi: remove ArmPlatformStackLib dependency
  ArmVirtPkg/PrePi: remove bogus IntelFrameworkModulePkg.dec dependency
  ArmVirtPkg/ArmVirtPlatformLib: remove support for uncached mappings
  ArmVirtPkg: introduce ArmVirtMemInfoLib library class
  ArmVirtPkg/ArmVirtXen: add ArmVirtMemInfoLib implementation
  ArmVirtPkg/ArmVirtQemu: add ArmVirtMemInfoLib implementation
  ArmVirtPkg: create QemuVirtMemInfoLib version for ArmVirtQemu
  ArmVirtPkg/ArmVirtMemoryInitPeiLib: move to ArmVirtMemInfoLib
  ArmVirtPkg: remove ArmPlatformLib implementations

 ArmVirtPkg/ArmVirt.dsc.inc                                                                                  |   1 -
 ArmVirtPkg/ArmVirtPkg.dec                                                                                   |   3 +
 ArmVirtPkg/ArmVirtQemu.dsc                                                                                  |   5 +-
 ArmVirtPkg/ArmVirtQemuKernel.dsc                                                                            |   2 +-
 ArmVirtPkg/ArmVirtXen.dsc                                                                                   |   2 +-
 ArmVirtPkg/Include/Library/ArmVirtMemInfoLib.h                                                              |  41 ++++++
 ArmVirtPkg/Library/ArmQemuRelocatablePlatformLib/AARCH64/RelocatableVirtHelper.S                            | 141 --------------------
 ArmVirtPkg/Library/ArmQemuRelocatablePlatformLib/ARM/RelocatableVirtHelper.S                                | 123 -----------------
 ArmVirtPkg/Library/ArmQemuRelocatablePlatformLib/ArmQemuRelocatablePlatformLib.inf                          |  64 ---------
 ArmVirtPkg/Library/ArmQemuRelocatablePlatformLib/RelocatableVirt.c                                          |  70 ----------
 ArmVirtPkg/Library/ArmVirtMemoryInitPeiLib/ArmVirtMemoryInitPeiLib.c                                        |   4 +-
 ArmVirtPkg/Library/ArmVirtMemoryInitPeiLib/ArmVirtMemoryInitPeiLib.inf                                      |   3 +-
 ArmVirtPkg/Library/ArmVirtPlatformLib/ARM/VirtHelper.S                                                      |  57 --------
 ArmVirtPkg/Library/ArmVirtPlatformLib/ARM/VirtHelper.asm                                                    |  71 ----------
 ArmVirtPkg/Library/ArmVirtPlatformLib/ArmVirtPlatformLib.inf                                                |  64 ---------
 ArmVirtPkg/Library/ArmVirtPlatformLib/VirtMem.c                                                             | 113 ----------------
 ArmVirtPkg/Library/ArmXenRelocatablePlatformLib/AARCH64/RelocatableVirtHelper.S                             | 140 -------------------
 ArmVirtPkg/Library/ArmXenRelocatablePlatformLib/ARM/RelocatableVirtHelper.S                                 | 123 -----------------
 ArmVirtPkg/Library/ArmXenRelocatablePlatformLib/ArmXenRelocatablePlatformLib.inf                            |  63 ---------
 ArmVirtPkg/Library/ArmXenRelocatablePlatformLib/FdtParser.c                                                 |  89 ------------
 ArmVirtPkg/Library/ArmXenRelocatablePlatformLib/RelocatableVirt.c                                           |  70 ----------
 ArmVirtPkg/Library/ArmXenRelocatablePlatformLib/XenVirtMem.c                                                |  82 ------------
 ArmVirtPkg/Library/{ArmVirtPlatformLib/AARCH64/VirtHelper.S => QemuVirtMemInfoLib/AArch64/PhysAddrTop.S}    |  33 +----
 ArmVirtPkg/Library/QemuVirtMemInfoLib/Arm/PhysAddrTop.S                                                     |  24 ++++
 ArmVirtPkg/Library/{ArmQemuRelocatablePlatformLib/QemuVirtMem.c => QemuVirtMemInfoLib/QemuVirtMemInfoLib.c} |  62 ++++-----
 ArmVirtPkg/Library/QemuVirtMemInfoLib/QemuVirtMemInfoLib.inf                                                |  54 ++++++++
 ArmVirtPkg/Library/QemuVirtMemInfoLib/QemuVirtMemInfoPeiLib.inf                                             |  58 ++++++++
 ArmVirtPkg/Library/{ArmVirtPlatformLib/Virt.c => QemuVirtMemInfoLib/QemuVirtMemInfoPeiLibConstructor.c}     |  92 +++----------
 ArmVirtPkg/Library/XenVirtMemInfoLib/AArch64/PhysAddrTop.S                                                  |  39 ++++++
 ArmVirtPkg/Library/XenVirtMemInfoLib/Arm/PhysAddrTop.S                                                      |  24 ++++
 ArmVirtPkg/Library/XenVirtMemInfoLib/XenVirtMemInfoLib.c                                                    |  63 +++++++++
 ArmVirtPkg/Library/XenVirtMemInfoLib/XenVirtMemInfoLib.inf                                                  |  41 ++++++
 ArmVirtPkg/PrePi/AArch64/ModuleEntryPoint.S                                                                 |  98 +++++++++++---
 ArmVirtPkg/PrePi/Arm/ModuleEntryPoint.S                                                                     |  92 ++++++++++---
 ArmVirtPkg/PrePi/ArmVirtPrePiUniCoreRelocatable.inf                                                         |   5 +-
 ArmVirtPkg/{Library/ArmQemuRelocatablePlatformLib => PrePi}/FdtParser.c                                     |   0
 ArmVirtPkg/PrePi/PrePi.c                                                                                    |  43 +-----
 ArmVirtPkg/PrePi/PrePi.h                                                                                    |   7 -
 38 files changed, 562 insertions(+), 1504 deletions(-)
 create mode 100644 ArmVirtPkg/Include/Library/ArmVirtMemInfoLib.h
 delete mode 100644 ArmVirtPkg/Library/ArmQemuRelocatablePlatformLib/AARCH64/RelocatableVirtHelper.S
 delete mode 100644 ArmVirtPkg/Library/ArmQemuRelocatablePlatformLib/ARM/RelocatableVirtHelper.S
 delete mode 100644 ArmVirtPkg/Library/ArmQemuRelocatablePlatformLib/ArmQemuRelocatablePlatformLib.inf
 delete mode 100644 ArmVirtPkg/Library/ArmQemuRelocatablePlatformLib/RelocatableVirt.c
 delete mode 100644 ArmVirtPkg/Library/ArmVirtPlatformLib/ARM/VirtHelper.S
 delete mode 100644 ArmVirtPkg/Library/ArmVirtPlatformLib/ARM/VirtHelper.asm
 delete mode 100644 ArmVirtPkg/Library/ArmVirtPlatformLib/ArmVirtPlatformLib.inf
 delete mode 100644 ArmVirtPkg/Library/ArmVirtPlatformLib/VirtMem.c
 delete mode 100644 ArmVirtPkg/Library/ArmXenRelocatablePlatformLib/AARCH64/RelocatableVirtHelper.S
 delete mode 100644 ArmVirtPkg/Library/ArmXenRelocatablePlatformLib/ARM/RelocatableVirtHelper.S
 delete mode 100644 ArmVirtPkg/Library/ArmXenRelocatablePlatformLib/ArmXenRelocatablePlatformLib.inf
 delete mode 100644 ArmVirtPkg/Library/ArmXenRelocatablePlatformLib/FdtParser.c
 delete mode 100644 ArmVirtPkg/Library/ArmXenRelocatablePlatformLib/RelocatableVirt.c
 delete mode 100644 ArmVirtPkg/Library/ArmXenRelocatablePlatformLib/XenVirtMem.c
 rename ArmVirtPkg/Library/{ArmVirtPlatformLib/AARCH64/VirtHelper.S => QemuVirtMemInfoLib/AArch64/PhysAddrTop.S} (58%)
 create mode 100644 ArmVirtPkg/Library/QemuVirtMemInfoLib/Arm/PhysAddrTop.S
 rename ArmVirtPkg/Library/{ArmQemuRelocatablePlatformLib/QemuVirtMem.c => QemuVirtMemInfoLib/QemuVirtMemInfoLib.c} (58%)
 create mode 100644 ArmVirtPkg/Library/QemuVirtMemInfoLib/QemuVirtMemInfoLib.inf
 create mode 100644 ArmVirtPkg/Library/QemuVirtMemInfoLib/QemuVirtMemInfoPeiLib.inf
 rename ArmVirtPkg/Library/{ArmVirtPlatformLib/Virt.c => QemuVirtMemInfoLib/QemuVirtMemInfoPeiLibConstructor.c} (52%)
 create mode 100644 ArmVirtPkg/Library/XenVirtMemInfoLib/AArch64/PhysAddrTop.S
 create mode 100644 ArmVirtPkg/Library/XenVirtMemInfoLib/Arm/PhysAddrTop.S
 create mode 100644 ArmVirtPkg/Library/XenVirtMemInfoLib/XenVirtMemInfoLib.c
 create mode 100644 ArmVirtPkg/Library/XenVirtMemInfoLib/XenVirtMemInfoLib.inf
 rename ArmVirtPkg/{Library/ArmQemuRelocatablePlatformLib => PrePi}/FdtParser.c (100%)

-- 
2.11.0



^ permalink raw reply	[flat|nested] 21+ messages in thread

* [PATCH v2 01/14] ArmVirtPkg/PrePi: run all library constructors by hand
  2017-11-22 10:07 [PATCH v2 00/14] ArmVirtPkg: get rid of ArmPlatformLib Ard Biesheuvel
@ 2017-11-22 10:07 ` Ard Biesheuvel
  2017-11-22 10:07 ` [PATCH v2 02/14] ArmVirtPkg/PrePi: remove unused GetPlatformPpi() function Ard Biesheuvel
                   ` (13 subsequent siblings)
  14 siblings, 0 replies; 21+ messages in thread
From: Ard Biesheuvel @ 2017-11-22 10:07 UTC (permalink / raw)
  To: edk2-devel, lersek; +Cc: Ard Biesheuvel

Instead of invoking the library constructors of some libraries by
hand, invoke the generated function ProcessLibraryConstructorList
in AutoGen.c so all constructors are executed.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Reviewed-by: Laszlo Ersek <lersek@redhat.com>
---
 ArmVirtPkg/PrePi/PrePi.c | 13 +++----------
 1 file changed, 3 insertions(+), 10 deletions(-)

diff --git a/ArmVirtPkg/PrePi/PrePi.c b/ArmVirtPkg/PrePi/PrePi.c
index c69cff249e80..3679087aec4d 100755
--- a/ArmVirtPkg/PrePi/PrePi.c
+++ b/ArmVirtPkg/PrePi/PrePi.c
@@ -29,15 +29,9 @@
 #include "PrePi.h"
 #include "LzmaDecompress.h"
 
-EFI_STATUS
-EFIAPI
-ExtractGuidedSectionLibConstructor (
-  VOID
-  );
-
-EFI_STATUS
+VOID
 EFIAPI
-LzmaDecompressLibConstructor (
+ProcessLibraryConstructorList (
   VOID
   );
 
@@ -125,8 +119,7 @@ PrePiMain (
   PERF_START (NULL, "PEI", NULL, StartTimeStamp);
 
   // SEC phase needs to run library constructors by hand.
-  ExtractGuidedSectionLibConstructor ();
-  LzmaDecompressLibConstructor ();
+  ProcessLibraryConstructorList ();
 
   // Build HOBs to pass up our version of stuff the DXE Core needs to save space
   BuildPeCoffLoaderHob ();
-- 
2.11.0



^ permalink raw reply related	[flat|nested] 21+ messages in thread

* [PATCH v2 02/14] ArmVirtPkg/PrePi: remove unused GetPlatformPpi() function
  2017-11-22 10:07 [PATCH v2 00/14] ArmVirtPkg: get rid of ArmPlatformLib Ard Biesheuvel
  2017-11-22 10:07 ` [PATCH v2 01/14] ArmVirtPkg/PrePi: run all library constructors by hand Ard Biesheuvel
@ 2017-11-22 10:07 ` Ard Biesheuvel
  2017-11-22 10:07 ` [PATCH v2 03/14] ArmVirtPkg/PrePi: remove bogus primary core check Ard Biesheuvel
                   ` (12 subsequent siblings)
  14 siblings, 0 replies; 21+ messages in thread
From: Ard Biesheuvel @ 2017-11-22 10:07 UTC (permalink / raw)
  To: edk2-devel, lersek; +Cc: Ard Biesheuvel

Remove GetPlatformPpi() from PrePi: it is not used anywhere.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Reviewed-by: Laszlo Ersek <lersek@redhat.com>
---
 ArmVirtPkg/PrePi/PrePi.c | 24 --------------------
 ArmVirtPkg/PrePi/PrePi.h |  6 -----
 2 files changed, 30 deletions(-)

diff --git a/ArmVirtPkg/PrePi/PrePi.c b/ArmVirtPkg/PrePi/PrePi.c
index 3679087aec4d..c4fa979c43ef 100755
--- a/ArmVirtPkg/PrePi/PrePi.c
+++ b/ArmVirtPkg/PrePi/PrePi.c
@@ -35,30 +35,6 @@ ProcessLibraryConstructorList (
   VOID
   );
 
-EFI_STATUS
-GetPlatformPpi (
-  IN  EFI_GUID  *PpiGuid,
-  OUT VOID      **Ppi
-  )
-{
-  UINTN                   PpiListSize;
-  UINTN                   PpiListCount;
-  EFI_PEI_PPI_DESCRIPTOR  *PpiList;
-  UINTN                   Index;
-
-  PpiListSize = 0;
-  ArmPlatformGetPlatformPpiList (&PpiListSize, &PpiList);
-  PpiListCount = PpiListSize / sizeof(EFI_PEI_PPI_DESCRIPTOR);
-  for (Index = 0; Index < PpiListCount; Index++, PpiList++) {
-    if (CompareGuid (PpiList->Guid, PpiGuid) == TRUE) {
-      *Ppi = PpiList->Ppi;
-      return EFI_SUCCESS;
-    }
-  }
-
-  return EFI_NOT_FOUND;
-}
-
 VOID
 PrePiMain (
   IN  UINTN                     UefiMemoryBase,
diff --git a/ArmVirtPkg/PrePi/PrePi.h b/ArmVirtPkg/PrePi/PrePi.h
index d3189c0b8a6f..153f06b9c7fb 100644
--- a/ArmVirtPkg/PrePi/PrePi.h
+++ b/ArmVirtPkg/PrePi/PrePi.h
@@ -61,12 +61,6 @@ BuildMemoryTypeInformationHob (
   VOID
   );
 
-EFI_STATUS
-GetPlatformPpi (
-  IN  EFI_GUID  *PpiGuid,
-  OUT VOID      **Ppi
-  );
-
 // Initialize the Architecture specific controllers
 VOID
 ArchInitialize (
-- 
2.11.0



^ permalink raw reply related	[flat|nested] 21+ messages in thread

* [PATCH v2 03/14] ArmVirtPkg/PrePi: remove bogus primary core check
  2017-11-22 10:07 [PATCH v2 00/14] ArmVirtPkg: get rid of ArmPlatformLib Ard Biesheuvel
  2017-11-22 10:07 ` [PATCH v2 01/14] ArmVirtPkg/PrePi: run all library constructors by hand Ard Biesheuvel
  2017-11-22 10:07 ` [PATCH v2 02/14] ArmVirtPkg/PrePi: remove unused GetPlatformPpi() function Ard Biesheuvel
@ 2017-11-22 10:07 ` Ard Biesheuvel
  2017-11-22 10:07 ` [PATCH v2 04/14] ArmVirtPkg/PrePi: move DRAM discovery code into PrePi Ard Biesheuvel
                   ` (11 subsequent siblings)
  14 siblings, 0 replies; 21+ messages in thread
From: Ard Biesheuvel @ 2017-11-22 10:07 UTC (permalink / raw)
  To: edk2-devel, lersek; +Cc: Ard Biesheuvel

QEMU and KVM based ARM/AARCH64 virtual machines only enter UEFI on
a single core, so ArmPlatformIsPrimaryCore() always returns true.
And even if it didn't, our code does absolutely nothing meaningful
based on its return value, so don't bother calling it, and remove
another frivolous dependency on ArmPlatformLib.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Reviewed-by: Laszlo Ersek <lersek@redhat.com>
---
 ArmVirtPkg/PrePi/AArch64/ModuleEntryPoint.S | 7 -------
 ArmVirtPkg/PrePi/Arm/ModuleEntryPoint.S     | 7 -------
 2 files changed, 14 deletions(-)

diff --git a/ArmVirtPkg/PrePi/AArch64/ModuleEntryPoint.S b/ArmVirtPkg/PrePi/AArch64/ModuleEntryPoint.S
index cc8b47e69026..7a9c0c3787cc 100644
--- a/ArmVirtPkg/PrePi/AArch64/ModuleEntryPoint.S
+++ b/ArmVirtPkg/PrePi/AArch64/ModuleEntryPoint.S
@@ -128,13 +128,6 @@ _GetStackBase:
   MOV32 (x3, FixedPcdGet32(PcdCPUCoreSecondaryStackSize))
   bl    ASM_PFX(ArmPlatformStackSet)
 
-  // Is it the Primary Core ?
-  mov   x0, x10
-  bl    ASM_PFX(ArmPlatformIsPrimaryCore)
-  cmp   x0, #1
-  bne   _PrepareArguments
-
-_PrepareArguments:
   mov   x0, x20
   mov   x1, x21
   mov   x2, x22
diff --git a/ArmVirtPkg/PrePi/Arm/ModuleEntryPoint.S b/ArmVirtPkg/PrePi/Arm/ModuleEntryPoint.S
index 59028d0a553e..eebf660acdb2 100644
--- a/ArmVirtPkg/PrePi/Arm/ModuleEntryPoint.S
+++ b/ArmVirtPkg/PrePi/Arm/ModuleEntryPoint.S
@@ -136,13 +136,6 @@ _GetStackBase:
   MOV32 (r3, FixedPcdGet32(PcdCPUCoreSecondaryStackSize))
   bl    ASM_PFX(ArmPlatformStackSet)
 
-  // Is it the Primary Core ?
-  mov   r0, r10
-  bl    ASM_PFX(ArmPlatformIsPrimaryCore)
-  cmp   r0, #1
-  bne   _PrepareArguments
-
-_PrepareArguments:
   mov   r0, r10
   mov   r1, r11
   mov   r2, r9
-- 
2.11.0



^ permalink raw reply related	[flat|nested] 21+ messages in thread

* [PATCH v2 04/14] ArmVirtPkg/PrePi: move DRAM discovery code into PrePi
  2017-11-22 10:07 [PATCH v2 00/14] ArmVirtPkg: get rid of ArmPlatformLib Ard Biesheuvel
                   ` (2 preceding siblings ...)
  2017-11-22 10:07 ` [PATCH v2 03/14] ArmVirtPkg/PrePi: remove bogus primary core check Ard Biesheuvel
@ 2017-11-22 10:07 ` Ard Biesheuvel
  2017-11-22 10:07 ` [PATCH v2 05/14] ArmVirtPkg/PrePi: remove dependency on ArmPlatformLib Ard Biesheuvel
                   ` (10 subsequent siblings)
  14 siblings, 0 replies; 21+ messages in thread
From: Ard Biesheuvel @ 2017-11-22 10:07 UTC (permalink / raw)
  To: edk2-devel, lersek; +Cc: Ard Biesheuvel

ArmVirtQemuKernel and ArmVirtXen use essentially the same code to
retrieve DRAM information from the DT /memory node at early boot,
and invoke it via the ArmPlatformPeiBootAction () hook exposed by
ArmPlatformLib. Let's move this code into the PrePi implementation
these platforms share between them (and not with any other platforms)
so we can eliminate another dependency on the messy ArmPlatformLib.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Acked-by: Laszlo Ersek <lersek@redhat.com>
---
 ArmVirtPkg/PrePi/AArch64/ModuleEntryPoint.S         | 77 ++++++++++++++++-
 ArmVirtPkg/PrePi/Arm/ModuleEntryPoint.S             | 71 +++++++++++++++
 ArmVirtPkg/PrePi/ArmVirtPrePiUniCoreRelocatable.inf |  2 +
 ArmVirtPkg/PrePi/FdtParser.c                        | 90 ++++++++++++++++++++
 4 files changed, 238 insertions(+), 2 deletions(-)

diff --git a/ArmVirtPkg/PrePi/AArch64/ModuleEntryPoint.S b/ArmVirtPkg/PrePi/AArch64/ModuleEntryPoint.S
index 7a9c0c3787cc..3296aedfe9aa 100644
--- a/ArmVirtPkg/PrePi/AArch64/ModuleEntryPoint.S
+++ b/ArmVirtPkg/PrePi/AArch64/ModuleEntryPoint.S
@@ -49,8 +49,7 @@ ASM_FUNC(_ModuleEntryPoint)
   b     .Lreloc_loop
 .Lreloc_done:
 
-  // Do early platform specific actions
-  bl    ASM_PFX(ArmPlatformPeiBootAction)
+  bl    ASM_PFX(DiscoverDramFromDt)
 
   // Get ID of this CPU in Multicore system
   bl    ASM_PFX(ArmReadMpidr)
@@ -140,3 +139,77 @@ _GetStackBase:
 
 _NeverReturn:
   b _NeverReturn
+
+// VOID
+// DiscoverDramFromDt (
+//   VOID   *DeviceTreeBaseAddress,   // passed by loader in x0
+//   VOID   *ImageBase                // passed by FDF trampoline in x1
+//   );
+ASM_PFX(DiscoverDramFromDt):
+  //
+  // If we are booting from RAM using the Linux kernel boot protocol, x0 will
+  // point to the DTB image in memory. Otherwise, use the default value defined
+  // by the platform.
+  //
+  cbnz  x0, 0f
+  ldr   x0, PcdGet64 (PcdDeviceTreeInitialBaseAddress)
+
+0:mov   x29, x30            // preserve LR
+  mov   x28, x0             // preserve DTB pointer
+  mov   x27, x1             // preserve base of image pointer
+
+  //
+  // The base of the runtime image has been preserved in x1. Check whether
+  // the expected magic number can be found in the header.
+  //
+  ldr   w8, .LArm64LinuxMagic
+  ldr   w9, [x1, #0x38]
+  cmp   w8, w9
+  bne   .Lout
+
+  //
+  //
+  // OK, so far so good. We have confirmed that we likely have a DTB and are
+  // booting via the arm64 Linux boot protocol. Update the base-of-image PCD
+  // to the actual relocated value, and add the shift of PcdFdBaseAddress to
+  // PcdFvBaseAddress as well
+  //
+  adr   x8, PcdGet64 (PcdFdBaseAddress)
+  adr   x9, PcdGet64 (PcdFvBaseAddress)
+  ldr   x6, [x8]
+  ldr   x7, [x9]
+  sub   x7, x7, x6
+  add   x7, x7, x1
+  str   x1, [x8]
+  str   x7, [x9]
+
+  //
+  // Discover the memory size and offset from the DTB, and record in the
+  // respective PCDs. This will also return false if a corrupt DTB is
+  // encountered. Since we are calling a C function, use the window at the
+  // beginning of the FD image as a temp stack.
+  //
+  adr   x1, PcdGet64 (PcdSystemMemoryBase)
+  adr   x2, PcdGet64 (PcdSystemMemorySize)
+  mov   sp, x7
+  bl    FindMemnode
+  cbz   x0, .Lout
+
+  //
+  // Copy the DTB to the slack space right after the 64 byte arm64/Linux style
+  // image header at the base of this image (defined in the FDF), and record the
+  // pointer in PcdDeviceTreeInitialBaseAddress.
+  //
+  adr   x8, PcdGet64 (PcdDeviceTreeInitialBaseAddress)
+  add   x27, x27, #0x40
+  str   x27, [x8]
+
+  mov   x0, x27
+  mov   x1, x28
+  bl    CopyFdt
+
+.Lout:
+  ret    x29
+
+.LArm64LinuxMagic:
+  .byte   0x41, 0x52, 0x4d, 0x64
diff --git a/ArmVirtPkg/PrePi/Arm/ModuleEntryPoint.S b/ArmVirtPkg/PrePi/Arm/ModuleEntryPoint.S
index eebf660acdb2..a918c191432e 100644
--- a/ArmVirtPkg/PrePi/Arm/ModuleEntryPoint.S
+++ b/ArmVirtPkg/PrePi/Arm/ModuleEntryPoint.S
@@ -148,3 +148,74 @@ _GetStackBase:
 
 _NeverReturn:
   b _NeverReturn
+
+ASM_PFX(ArmPlatformPeiBootAction):
+  //
+  // If we are booting from RAM using the Linux kernel boot protocol, r0 will
+  // point to the DTB image in memory. Otherwise, use the default value defined
+  // by the platform.
+  //
+  teq   r0, #0
+  bne   0f
+  LDRL  (r0, PcdGet64 (PcdDeviceTreeInitialBaseAddress))
+
+0:mov   r11, r14            // preserve LR
+  mov   r10, r0             // preserve DTB pointer
+  mov   r9, r1              // preserve base of image pointer
+
+  //
+  // The base of the runtime image has been preserved in r1. Check whether
+  // the expected magic number can be found in the header.
+  //
+  ldr   r8, .LArm32LinuxMagic
+  ldr   r7, [r1, #0x24]
+  cmp   r7, r8
+  bne   .Lout
+
+  //
+  //
+  // OK, so far so good. We have confirmed that we likely have a DTB and are
+  // booting via the ARM Linux boot protocol. Update the base-of-image PCD
+  // to the actual relocated value, and add the shift of PcdFdBaseAddress to
+  // PcdFvBaseAddress as well
+  //
+  ADRL  (r8, PcdGet64 (PcdFdBaseAddress))
+  ADRL  (r7, PcdGet64 (PcdFvBaseAddress))
+  ldr   r6, [r8]
+  ldr   r5, [r7]
+  sub   r5, r5, r6
+  add   r5, r5, r1
+  str   r1, [r8]
+  str   r5, [r7]
+
+  //
+  // Discover the memory size and offset from the DTB, and record in the
+  // respective PCDs. This will also return false if a corrupt DTB is
+  // encountered. Since we are calling a C function, use the window at the
+  // beginning of the FD image as a temp stack.
+  //
+  ADRL  (r1, PcdGet64 (PcdSystemMemoryBase))
+  ADRL  (r2, PcdGet64 (PcdSystemMemorySize))
+  mov   sp, r5
+  bl    FindMemnode
+  teq   r0, #0
+  beq   .Lout
+
+  //
+  // Copy the DTB to the slack space right after the 64 byte arm64/Linux style
+  // image header at the base of this image (defined in the FDF), and record the
+  // pointer in PcdDeviceTreeInitialBaseAddress.
+  //
+  ADRL  (r8, PcdGet64 (PcdDeviceTreeInitialBaseAddress))
+  add   r9, r9, #0x40
+  str   r9, [r8]
+
+  mov   r0, r9
+  mov   r1, r10
+  bl    CopyFdt
+
+.Lout:
+  bx    r11
+
+.LArm32LinuxMagic:
+  .byte   0x18, 0x28, 0x6f, 0x01
diff --git a/ArmVirtPkg/PrePi/ArmVirtPrePiUniCoreRelocatable.inf b/ArmVirtPkg/PrePi/ArmVirtPrePiUniCoreRelocatable.inf
index 5e706934f69f..789a896857aa 100755
--- a/ArmVirtPkg/PrePi/ArmVirtPrePiUniCoreRelocatable.inf
+++ b/ArmVirtPkg/PrePi/ArmVirtPrePiUniCoreRelocatable.inf
@@ -23,6 +23,7 @@ [Defines]
 
 [Sources]
   PrePi.c
+  FdtParser.c
 
 [Sources.AArch64]
   AArch64/ArchPrePi.c
@@ -44,6 +45,7 @@ [Packages]
 [LibraryClasses]
   BaseLib
   DebugLib
+  FdtLib
   ArmLib
   IoLib
   TimerLib
diff --git a/ArmVirtPkg/PrePi/FdtParser.c b/ArmVirtPkg/PrePi/FdtParser.c
new file mode 100644
index 000000000000..afdc81a8839d
--- /dev/null
+++ b/ArmVirtPkg/PrePi/FdtParser.c
@@ -0,0 +1,90 @@
+/*
+ * Copyright (c) 2015, Linaro Ltd. All rights reserved.
+ *
+ * This program and the accompanying materials
+ * are licensed and made available under the terms and conditions of the BSD License
+ * which accompanies this distribution.  The full text of the license may be found at
+ * http://opensource.org/licenses/bsd-license.php
+ *
+ * THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+ */
+
+#include <Uefi.h>
+#include <Include/libfdt.h>
+
+BOOLEAN
+FindMemnode (
+  IN  VOID    *DeviceTreeBlob,
+  OUT UINT64  *SystemMemoryBase,
+  OUT UINT64  *SystemMemorySize
+  )
+{
+  INT32         MemoryNode;
+  INT32         AddressCells;
+  INT32         SizeCells;
+  INT32         Length;
+  CONST INT32   *Prop;
+
+  if (fdt_check_header (DeviceTreeBlob) != 0) {
+    return FALSE;
+  }
+
+  //
+  // Look for a node called "memory" at the lowest level of the tree
+  //
+  MemoryNode = fdt_path_offset (DeviceTreeBlob, "/memory");
+  if (MemoryNode <= 0) {
+    return FALSE;
+  }
+
+  //
+  // Retrieve the #address-cells and #size-cells properties
+  // from the root node, or use the default if not provided.
+  //
+  AddressCells = 1;
+  SizeCells = 1;
+
+  Prop = fdt_getprop (DeviceTreeBlob, 0, "#address-cells", &Length);
+  if (Length == 4) {
+    AddressCells = fdt32_to_cpu (*Prop);
+  }
+
+  Prop = fdt_getprop (DeviceTreeBlob, 0, "#size-cells", &Length);
+  if (Length == 4) {
+    SizeCells = fdt32_to_cpu (*Prop);
+  }
+
+  //
+  // Now find the 'reg' property of the /memory node, and read the first
+  // range listed.
+  //
+  Prop = fdt_getprop (DeviceTreeBlob, MemoryNode, "reg", &Length);
+
+  if (Length < (AddressCells + SizeCells) * sizeof (INT32)) {
+    return FALSE;
+  }
+
+  *SystemMemoryBase = fdt32_to_cpu (Prop[0]);
+  if (AddressCells > 1) {
+    *SystemMemoryBase = (*SystemMemoryBase << 32) | fdt32_to_cpu (Prop[1]);
+  }
+  Prop += AddressCells;
+
+  *SystemMemorySize = fdt32_to_cpu (Prop[0]);
+  if (SizeCells > 1) {
+    *SystemMemorySize = (*SystemMemorySize << 32) | fdt32_to_cpu (Prop[1]);
+  }
+
+  return TRUE;
+}
+
+VOID
+CopyFdt (
+  IN    VOID    *FdtDest,
+  IN    VOID    *FdtSource
+  )
+{
+  fdt_pack(FdtSource);
+  CopyMem (FdtDest, FdtSource, fdt_totalsize (FdtSource));
+}
-- 
2.11.0



^ permalink raw reply related	[flat|nested] 21+ messages in thread

* [PATCH v2 05/14] ArmVirtPkg/PrePi: remove dependency on ArmPlatformLib
  2017-11-22 10:07 [PATCH v2 00/14] ArmVirtPkg: get rid of ArmPlatformLib Ard Biesheuvel
                   ` (3 preceding siblings ...)
  2017-11-22 10:07 ` [PATCH v2 04/14] ArmVirtPkg/PrePi: move DRAM discovery code into PrePi Ard Biesheuvel
@ 2017-11-22 10:07 ` Ard Biesheuvel
  2017-11-22 10:07 ` [PATCH v2 06/14] ArmVirtPkg/PrePi: remove ArmPlatformStackLib dependency Ard Biesheuvel
                   ` (9 subsequent siblings)
  14 siblings, 0 replies; 21+ messages in thread
From: Ard Biesheuvel @ 2017-11-22 10:07 UTC (permalink / raw)
  To: edk2-devel, lersek; +Cc: Ard Biesheuvel

Remove the pointless dependency on ArmPlatformLib: none of the code we
call from it actually does anything useful.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Reviewed-by: Laszlo Ersek <lersek@redhat.com>
---
 ArmVirtPkg/PrePi/ArmVirtPrePiUniCoreRelocatable.inf | 1 -
 ArmVirtPkg/PrePi/PrePi.c                            | 6 ++----
 ArmVirtPkg/PrePi/PrePi.h                            | 1 -
 3 files changed, 2 insertions(+), 6 deletions(-)

diff --git a/ArmVirtPkg/PrePi/ArmVirtPrePiUniCoreRelocatable.inf b/ArmVirtPkg/PrePi/ArmVirtPrePiUniCoreRelocatable.inf
index 789a896857aa..e816e9583da8 100755
--- a/ArmVirtPkg/PrePi/ArmVirtPrePiUniCoreRelocatable.inf
+++ b/ArmVirtPkg/PrePi/ArmVirtPrePiUniCoreRelocatable.inf
@@ -54,7 +54,6 @@ [LibraryClasses]
   LzmaDecompressLib
   PeCoffGetEntryPointLib
   PrePiLib
-  ArmPlatformLib
   ArmPlatformStackLib
   MemoryAllocationLib
   HobLib
diff --git a/ArmVirtPkg/PrePi/PrePi.c b/ArmVirtPkg/PrePi/PrePi.c
index c4fa979c43ef..fce4ab9428a5 100755
--- a/ArmVirtPkg/PrePi/PrePi.c
+++ b/ArmVirtPkg/PrePi/PrePi.c
@@ -13,6 +13,7 @@
 **/
 
 #include <PiPei.h>
+#include <Pi/PiBootMode.h>
 
 #include <Library/PrePiLib.h>
 #include <Library/PrintLib.h>
@@ -85,7 +86,7 @@ PrePiMain (
   BuildCpuHob (PcdGet8 (PcdPrePiCpuMemorySize), PcdGet8 (PcdPrePiCpuIoSize));
 
   // Set the Boot Mode
-  SetBootMode (ArmPlatformGetBootMode ());
+  SetBootMode (BOOT_WITH_FULL_CONFIGURATION);
 
   // Initialize Platform HOBs (CpuHob and FvHob)
   Status = PlatformPeim ();
@@ -123,9 +124,6 @@ CEntryPoint (
 {
   UINT64   StartTimeStamp;
 
-  // Initialize the platform specific controllers
-  ArmPlatformInitialize (MpId);
-
   if (PerformanceMeasurementEnabled ()) {
     // Initialize the Timer Library to setup the Timer HW controller
     TimerConstructor ();
diff --git a/ArmVirtPkg/PrePi/PrePi.h b/ArmVirtPkg/PrePi/PrePi.h
index 153f06b9c7fb..14c9bf92c115 100644
--- a/ArmVirtPkg/PrePi/PrePi.h
+++ b/ArmVirtPkg/PrePi/PrePi.h
@@ -25,7 +25,6 @@
 #include <Library/MemoryAllocationLib.h>
 #include <Library/HobLib.h>
 #include <Library/SerialPortLib.h>
-#include <Library/ArmPlatformLib.h>
 
 #define SerialPrint(txt)  SerialPortWrite (txt, AsciiStrLen(txt)+1);
 
-- 
2.11.0



^ permalink raw reply related	[flat|nested] 21+ messages in thread

* [PATCH v2 06/14] ArmVirtPkg/PrePi: remove ArmPlatformStackLib dependency
  2017-11-22 10:07 [PATCH v2 00/14] ArmVirtPkg: get rid of ArmPlatformLib Ard Biesheuvel
                   ` (4 preceding siblings ...)
  2017-11-22 10:07 ` [PATCH v2 05/14] ArmVirtPkg/PrePi: remove dependency on ArmPlatformLib Ard Biesheuvel
@ 2017-11-22 10:07 ` Ard Biesheuvel
  2017-11-22 10:07 ` [PATCH v2 07/14] ArmVirtPkg/PrePi: remove bogus IntelFrameworkModulePkg.dec dependency Ard Biesheuvel
                   ` (8 subsequent siblings)
  14 siblings, 0 replies; 21+ messages in thread
From: Ard Biesheuvel @ 2017-11-22 10:07 UTC (permalink / raw)
  To: edk2-devel, lersek; +Cc: Ard Biesheuvel

ArmPlatformStackLib has hooks into primary/secondary core PCDs and
other ArmPlatformLib related junk, so let's simply set the stack
pointer directly. This is trivial given that our PrePi is unicore
only.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Acked-by: Laszlo Ersek <lersek@redhat.com>
---
 ArmVirtPkg/ArmVirt.dsc.inc                          |  1 -
 ArmVirtPkg/PrePi/AArch64/ModuleEntryPoint.S         | 14 ++------------
 ArmVirtPkg/PrePi/Arm/ModuleEntryPoint.S             | 14 ++------------
 ArmVirtPkg/PrePi/ArmVirtPrePiUniCoreRelocatable.inf |  1 -
 4 files changed, 4 insertions(+), 26 deletions(-)

diff --git a/ArmVirtPkg/ArmVirt.dsc.inc b/ArmVirtPkg/ArmVirt.dsc.inc
index 50eb8675d1c0..5d7edff104b5 100644
--- a/ArmVirtPkg/ArmVirt.dsc.inc
+++ b/ArmVirtPkg/ArmVirt.dsc.inc
@@ -93,7 +93,6 @@ [LibraryClasses.common]
   ArmDisassemblerLib|ArmPkg/Library/ArmDisassemblerLib/ArmDisassemblerLib.inf
   ArmGicLib|ArmPkg/Drivers/ArmGic/ArmGicLib.inf
   ArmGicArchLib|ArmVirtPkg/Library/ArmVirtGicArchLib/ArmVirtGicArchLib.inf
-  ArmPlatformStackLib|ArmPlatformPkg/Library/ArmPlatformStackLib/ArmPlatformStackLib.inf
   ArmSmcLib|ArmPkg/Library/ArmSmcLib/ArmSmcLib.inf
   ArmHvcLib|ArmPkg/Library/ArmHvcLib/ArmHvcLib.inf
   ArmGenericTimerCounterLib|ArmPkg/Library/ArmGenericTimerVirtCounterLib/ArmGenericTimerVirtCounterLib.inf
diff --git a/ArmVirtPkg/PrePi/AArch64/ModuleEntryPoint.S b/ArmVirtPkg/PrePi/AArch64/ModuleEntryPoint.S
index 3296aedfe9aa..891cf1fcab40 100644
--- a/ArmVirtPkg/PrePi/AArch64/ModuleEntryPoint.S
+++ b/ArmVirtPkg/PrePi/AArch64/ModuleEntryPoint.S
@@ -111,22 +111,12 @@ _GetBaseUefiMemory:
 
 _GetStackBase:
   // r1 = The top of the Mpcore Stacks
+  mov   sp, x1
+
   // Stack for the primary core = PrimaryCoreStack
   MOV32 (x2, FixedPcdGet32(PcdCPUCorePrimaryStackSize))
   sub   x22, x1, x2
 
-  // Stack for the secondary core = Number of Cores - 1
-  MOV32 (x1, (FixedPcdGet32(PcdCoreCount) - 1) * FixedPcdGet32(PcdCPUCoreSecondaryStackSize))
-  sub   x22, x22, x1
-
-  // x22 = The base of the MpCore Stacks (primary stack & secondary stacks)
-  mov   x0, x22
-  mov   x1, x20
-  //ArmPlatformStackSet(StackBase, MpId, PrimaryStackSize, SecondaryStackSize)
-  MOV32 (x2, FixedPcdGet32(PcdCPUCorePrimaryStackSize))
-  MOV32 (x3, FixedPcdGet32(PcdCPUCoreSecondaryStackSize))
-  bl    ASM_PFX(ArmPlatformStackSet)
-
   mov   x0, x20
   mov   x1, x21
   mov   x2, x22
diff --git a/ArmVirtPkg/PrePi/Arm/ModuleEntryPoint.S b/ArmVirtPkg/PrePi/Arm/ModuleEntryPoint.S
index a918c191432e..ced08593e9de 100644
--- a/ArmVirtPkg/PrePi/Arm/ModuleEntryPoint.S
+++ b/ArmVirtPkg/PrePi/Arm/ModuleEntryPoint.S
@@ -120,22 +120,12 @@ _GetBaseUefiMemory:
 
 _GetStackBase:
   // r1 = The top of the Mpcore Stacks
+  mov   sp, r1
+
   // Stack for the primary core = PrimaryCoreStack
   MOV32 (r2, FixedPcdGet32(PcdCPUCorePrimaryStackSize))
   sub   r9, r1, r2
 
-  // Stack for the secondary core = Number of Cores - 1
-  MOV32 (r1, (FixedPcdGet32(PcdCoreCount) - 1) * FixedPcdGet32(PcdCPUCoreSecondaryStackSize))
-  sub   r9, r9, r1
-
-  // r9 = The base of the MpCore Stacks (primary stack & secondary stacks)
-  mov   r0, r9
-  mov   r1, r10
-  //ArmPlatformStackSet(StackBase, MpId, PrimaryStackSize, SecondaryStackSize)
-  MOV32 (r2, FixedPcdGet32(PcdCPUCorePrimaryStackSize))
-  MOV32 (r3, FixedPcdGet32(PcdCPUCoreSecondaryStackSize))
-  bl    ASM_PFX(ArmPlatformStackSet)
-
   mov   r0, r10
   mov   r1, r11
   mov   r2, r9
diff --git a/ArmVirtPkg/PrePi/ArmVirtPrePiUniCoreRelocatable.inf b/ArmVirtPkg/PrePi/ArmVirtPrePiUniCoreRelocatable.inf
index e816e9583da8..ae9a088c7256 100755
--- a/ArmVirtPkg/PrePi/ArmVirtPrePiUniCoreRelocatable.inf
+++ b/ArmVirtPkg/PrePi/ArmVirtPrePiUniCoreRelocatable.inf
@@ -54,7 +54,6 @@ [LibraryClasses]
   LzmaDecompressLib
   PeCoffGetEntryPointLib
   PrePiLib
-  ArmPlatformStackLib
   MemoryAllocationLib
   HobLib
   PrePiHobListPointerLib
-- 
2.11.0



^ permalink raw reply related	[flat|nested] 21+ messages in thread

* [PATCH v2 07/14] ArmVirtPkg/PrePi: remove bogus IntelFrameworkModulePkg.dec dependency
  2017-11-22 10:07 [PATCH v2 00/14] ArmVirtPkg: get rid of ArmPlatformLib Ard Biesheuvel
                   ` (5 preceding siblings ...)
  2017-11-22 10:07 ` [PATCH v2 06/14] ArmVirtPkg/PrePi: remove ArmPlatformStackLib dependency Ard Biesheuvel
@ 2017-11-22 10:07 ` Ard Biesheuvel
  2017-11-22 10:07 ` [PATCH v2 08/14] ArmVirtPkg/ArmVirtPlatformLib: remove support for uncached mappings Ard Biesheuvel
                   ` (7 subsequent siblings)
  14 siblings, 0 replies; 21+ messages in thread
From: Ard Biesheuvel @ 2017-11-22 10:07 UTC (permalink / raw)
  To: edk2-devel, lersek; +Cc: Ard Biesheuvel

PrePi doesn't use anything defined by this package so drop the bogus
dependency.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Reviewed-by: Laszlo Ersek <lersek@redhat.com>
---
 ArmVirtPkg/PrePi/ArmVirtPrePiUniCoreRelocatable.inf | 1 -
 1 file changed, 1 deletion(-)

diff --git a/ArmVirtPkg/PrePi/ArmVirtPrePiUniCoreRelocatable.inf b/ArmVirtPkg/PrePi/ArmVirtPrePiUniCoreRelocatable.inf
index ae9a088c7256..58290d2d1b76 100755
--- a/ArmVirtPkg/PrePi/ArmVirtPrePiUniCoreRelocatable.inf
+++ b/ArmVirtPkg/PrePi/ArmVirtPrePiUniCoreRelocatable.inf
@@ -40,7 +40,6 @@ [Packages]
   ArmPkg/ArmPkg.dec
   ArmPlatformPkg/ArmPlatformPkg.dec
   ArmVirtPkg/ArmVirtPkg.dec
-  IntelFrameworkModulePkg/IntelFrameworkModulePkg.dec
 
 [LibraryClasses]
   BaseLib
-- 
2.11.0



^ permalink raw reply related	[flat|nested] 21+ messages in thread

* [PATCH v2 08/14] ArmVirtPkg/ArmVirtPlatformLib: remove support for uncached mappings
  2017-11-22 10:07 [PATCH v2 00/14] ArmVirtPkg: get rid of ArmPlatformLib Ard Biesheuvel
                   ` (6 preceding siblings ...)
  2017-11-22 10:07 ` [PATCH v2 07/14] ArmVirtPkg/PrePi: remove bogus IntelFrameworkModulePkg.dec dependency Ard Biesheuvel
@ 2017-11-22 10:07 ` Ard Biesheuvel
  2017-11-22 10:07 ` [PATCH v2 09/14] ArmVirtPkg: introduce ArmVirtMemInfoLib library class Ard Biesheuvel
                   ` (6 subsequent siblings)
  14 siblings, 0 replies; 21+ messages in thread
From: Ard Biesheuvel @ 2017-11-22 10:07 UTC (permalink / raw)
  To: edk2-devel, lersek; +Cc: Ard Biesheuvel

QEMU/KVM has very little tolerance for using anything except writeback
cacheable mappings of DRAM, so let's remove the 'feature' that allows
us to select uncached mappings at build time.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Reviewed-by: Laszlo Ersek <lersek@redhat.com>
---
 ArmVirtPkg/Library/ArmVirtPlatformLib/VirtMem.c | 15 ++-------------
 1 file changed, 2 insertions(+), 13 deletions(-)

diff --git a/ArmVirtPkg/Library/ArmVirtPlatformLib/VirtMem.c b/ArmVirtPkg/Library/ArmVirtPlatformLib/VirtMem.c
index d10548f86dfc..4368d05f76ef 100644
--- a/ArmVirtPkg/Library/ArmVirtPlatformLib/VirtMem.c
+++ b/ArmVirtPkg/Library/ArmVirtPlatformLib/VirtMem.c
@@ -22,10 +22,6 @@
 // Number of Virtual Memory Map Descriptors
 #define MAX_VIRTUAL_MEMORY_MAP_DESCRIPTORS          5
 
-// DDR attributes
-#define DDR_ATTRIBUTES_CACHED    ARM_MEMORY_REGION_ATTRIBUTE_WRITE_BACK
-#define DDR_ATTRIBUTES_UNCACHED  ARM_MEMORY_REGION_ATTRIBUTE_UNCACHED_UNBUFFERED
-
 EFI_PHYSICAL_ADDRESS
 ArmGetPhysAddrTop (
   VOID
@@ -48,7 +44,6 @@ ArmPlatformGetVirtualMemoryMap (
   IN ARM_MEMORY_REGION_DESCRIPTOR** VirtualMemoryMap
   )
 {
-  ARM_MEMORY_REGION_ATTRIBUTES  CacheAttributes;
   ARM_MEMORY_REGION_DESCRIPTOR  *VirtualMemoryTable;
 
   ASSERT (VirtualMemoryMap != NULL);
@@ -65,17 +60,11 @@ ArmPlatformGetVirtualMemoryMap (
     return;
   }
 
-  if (FeaturePcdGet (PcdCacheEnable) == TRUE) {
-    CacheAttributes = DDR_ATTRIBUTES_CACHED;
-  } else {
-    CacheAttributes = DDR_ATTRIBUTES_UNCACHED;
-  }
-
   // System DRAM
   VirtualMemoryTable[0].PhysicalBase = PcdGet64 (PcdSystemMemoryBase);
   VirtualMemoryTable[0].VirtualBase  = VirtualMemoryTable[0].PhysicalBase;
   VirtualMemoryTable[0].Length       = PcdGet64 (PcdSystemMemorySize);
-  VirtualMemoryTable[0].Attributes   = CacheAttributes;
+  VirtualMemoryTable[0].Attributes   = ARM_MEMORY_REGION_ATTRIBUTE_WRITE_BACK;
 
   DEBUG ((EFI_D_INFO, "%a: Dumping System DRAM Memory Map:\n"
       "\tPhysicalBase: 0x%lX\n"
@@ -104,7 +93,7 @@ ArmPlatformGetVirtualMemoryMap (
   VirtualMemoryTable[3].PhysicalBase = FixedPcdGet64 (PcdFdBaseAddress);
   VirtualMemoryTable[3].VirtualBase  = VirtualMemoryTable[3].PhysicalBase;
   VirtualMemoryTable[3].Length       = FixedPcdGet32 (PcdFdSize);
-  VirtualMemoryTable[3].Attributes   = CacheAttributes;
+  VirtualMemoryTable[3].Attributes   = ARM_MEMORY_REGION_ATTRIBUTE_WRITE_BACK;
 
   // End of Table
   ZeroMem (&VirtualMemoryTable[4], sizeof (ARM_MEMORY_REGION_DESCRIPTOR));
-- 
2.11.0



^ permalink raw reply related	[flat|nested] 21+ messages in thread

* [PATCH v2 09/14] ArmVirtPkg: introduce ArmVirtMemInfoLib library class
  2017-11-22 10:07 [PATCH v2 00/14] ArmVirtPkg: get rid of ArmPlatformLib Ard Biesheuvel
                   ` (7 preceding siblings ...)
  2017-11-22 10:07 ` [PATCH v2 08/14] ArmVirtPkg/ArmVirtPlatformLib: remove support for uncached mappings Ard Biesheuvel
@ 2017-11-22 10:07 ` Ard Biesheuvel
  2017-11-23 16:00   ` Laszlo Ersek
  2017-11-22 10:07 ` [PATCH v2 10/14] ArmVirtPkg/ArmVirtXen: add ArmVirtMemInfoLib implementation Ard Biesheuvel
                   ` (5 subsequent siblings)
  14 siblings, 1 reply; 21+ messages in thread
From: Ard Biesheuvel @ 2017-11-22 10:07 UTC (permalink / raw)
  To: edk2-devel, lersek; +Cc: Ard Biesheuvel

As part of the effort to get rid of ArmPlatformLib (which incorporates
far too many duties in a single library), introduce ArmVirtMemInfoLib
which will be invoked by our ArmVirtMemoryInitPeiLib implementation to
get a description of the virtual address space. This will allow us to
remove this functionality from ArmPlatformLib later, or, in the case of
ArmVirtXen and ArmVirtQemuKernel, drop ArmPlatformLib altogether.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
---
 ArmVirtPkg/ArmVirtPkg.dec                      |  3 ++
 ArmVirtPkg/Include/Library/ArmVirtMemInfoLib.h | 41 ++++++++++++++++++++
 2 files changed, 44 insertions(+)

diff --git a/ArmVirtPkg/ArmVirtPkg.dec b/ArmVirtPkg/ArmVirtPkg.dec
index a8603e1b80e5..8f656fd2739d 100644
--- a/ArmVirtPkg/ArmVirtPkg.dec
+++ b/ArmVirtPkg/ArmVirtPkg.dec
@@ -30,6 +30,9 @@ [Defines]
 [Includes.common]
   Include                        # Root include for the package
 
+[LibraryClasses]
+  ArmVirtMemInfoLib|Include/Library/ArmVirtMemInfoLib.h
+
 [Guids.common]
   gArmVirtTokenSpaceGuid = { 0x0B6F5CA7, 0x4F53, 0x445A, { 0xB7, 0x6E, 0x2E, 0x36, 0x5B, 0x80, 0x63, 0x66 } }
   gEarlyPL011BaseAddressGuid       = { 0xB199DEA9, 0xFD5C, 0x4A84, { 0x80, 0x82, 0x2F, 0x41, 0x70, 0x78, 0x03, 0x05 } }
diff --git a/ArmVirtPkg/Include/Library/ArmVirtMemInfoLib.h b/ArmVirtPkg/Include/Library/ArmVirtMemInfoLib.h
new file mode 100644
index 000000000000..bdf1c513bc6d
--- /dev/null
+++ b/ArmVirtPkg/Include/Library/ArmVirtMemInfoLib.h
@@ -0,0 +1,41 @@
+/** @file
+
+  Copyright (c) 2011-2013, ARM Limited. All rights reserved.
+  Copyright (c) 2017, Linaro, Ltd. All rights reserved.
+
+  This program and the accompanying materials are licensed and made available
+  under the terms and conditions of the BSD License which accompanies this
+  distribution.  The full text of the license may be found at
+  http://opensource.org/licenses/bsd-license.php
+
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+**/
+
+#ifndef _ARM_VIRT_MEMINFO_LIB_H_
+#define _ARM_VIRT_MEMINFO_LIB_H_
+
+#include <Base.h>
+#include <Library/ArmLib.h>
+
+/**
+  Return the Virtual Memory Map of your platform
+
+  This Virtual Memory Map is used by MemoryInitPei Module to initialize the MMU
+  on your platform.
+
+  @param[out]   VirtualMemoryMap    Array of ARM_MEMORY_REGION_DESCRIPTOR
+                                    describing a Physical-to-Virtual Memory
+                                    mapping. This array must be ended by a
+                                    zero-filled entry. The allocated memory
+                                    will not be freed.
+
+**/
+VOID
+EFIAPI
+ArmVirtGetMemoryMap (
+  OUT ARM_MEMORY_REGION_DESCRIPTOR    **VirtualMemoryMap
+  );
+
+#endif
-- 
2.11.0



^ permalink raw reply related	[flat|nested] 21+ messages in thread

* [PATCH v2 10/14] ArmVirtPkg/ArmVirtXen: add ArmVirtMemInfoLib implementation
  2017-11-22 10:07 [PATCH v2 00/14] ArmVirtPkg: get rid of ArmPlatformLib Ard Biesheuvel
                   ` (8 preceding siblings ...)
  2017-11-22 10:07 ` [PATCH v2 09/14] ArmVirtPkg: introduce ArmVirtMemInfoLib library class Ard Biesheuvel
@ 2017-11-22 10:07 ` Ard Biesheuvel
  2017-11-22 17:03   ` Julien Grall
  2017-11-22 10:07 ` [PATCH v2 11/14] ArmVirtPkg/ArmVirtQemu: " Ard Biesheuvel
                   ` (4 subsequent siblings)
  14 siblings, 1 reply; 21+ messages in thread
From: Ard Biesheuvel @ 2017-11-22 10:07 UTC (permalink / raw)
  To: edk2-devel, lersek; +Cc: Ard Biesheuvel, Julien Grall

Clone the existing ArmPlatformGetVirtualMemoryMap () for this platform,
clean it up slightly (by using a static buffer rather than a heap
allocation, and removing the support for uncached DRAM mappings), and
turn it into a new ArmVirtMemInfoLib implementation.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Acked-by: Laszlo Ersek <lersek@redhat.com>
Cc: Julien Grall <julien.grall@linaro.org>
---
 ArmVirtPkg/ArmVirtXen.dsc                                  |  1 +
 ArmVirtPkg/Library/XenVirtMemInfoLib/AArch64/PhysAddrTop.S | 39 ++++++++++++
 ArmVirtPkg/Library/XenVirtMemInfoLib/Arm/PhysAddrTop.S     | 24 ++++++++
 ArmVirtPkg/Library/XenVirtMemInfoLib/XenVirtMemInfoLib.c   | 63 ++++++++++++++++++++
 ArmVirtPkg/Library/XenVirtMemInfoLib/XenVirtMemInfoLib.inf | 41 +++++++++++++
 5 files changed, 168 insertions(+)

diff --git a/ArmVirtPkg/ArmVirtXen.dsc b/ArmVirtPkg/ArmVirtXen.dsc
index 7a443483d1ac..3df684d13cb0 100644
--- a/ArmVirtPkg/ArmVirtXen.dsc
+++ b/ArmVirtPkg/ArmVirtXen.dsc
@@ -44,6 +44,7 @@ [LibraryClasses]
   VirtioMmioDeviceLib|OvmfPkg/Library/VirtioMmioDeviceLib/VirtioMmioDeviceLib.inf
 
   ArmPlatformLib|ArmVirtPkg/Library/ArmXenRelocatablePlatformLib/ArmXenRelocatablePlatformLib.inf
+  ArmVirtMemInfoLib|ArmVirtPkg/Library/XenVirtMemInfoLib/XenVirtMemInfoLib.inf
 
   TimerLib|ArmPkg/Library/ArmArchTimerLib/ArmArchTimerLib.inf
 
diff --git a/ArmVirtPkg/Library/XenVirtMemInfoLib/AArch64/PhysAddrTop.S b/ArmVirtPkg/Library/XenVirtMemInfoLib/AArch64/PhysAddrTop.S
new file mode 100644
index 000000000000..a1f6a194d59b
--- /dev/null
+++ b/ArmVirtPkg/Library/XenVirtMemInfoLib/AArch64/PhysAddrTop.S
@@ -0,0 +1,39 @@
+#
+#  Copyright (c) 2011-2013, ARM Limited. All rights reserved.
+#  Copyright (c) 2016-2017, Linaro Limited. All rights reserved.
+#
+#  This program and the accompanying materials
+#  are licensed and made available under the terms and conditions of the BSD License
+#  which accompanies this distribution.  The full text of the license may be found at
+#  http://opensource.org/licenses/bsd-license.php
+#
+#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+#
+#
+
+#include <AsmMacroIoLibV8.h>
+
+//EFI_PHYSICAL_ADDRESS
+//GetPhysAddrTop (
+//  VOID
+//  );
+ASM_FUNC(ArmGetPhysAddrTop)
+  mrs   x0, id_aa64mmfr0_el1
+  adr   x1, .LPARanges
+  and   x0, x0, #7
+  ldrb  w1, [x1, x0]
+  mov   x0, #1
+  lsl   x0, x0, x1
+  ret
+
+//
+// Bits 0..2 of the AA64MFR0_EL1 system register encode the size of the
+// physical address space support on this CPU:
+// 0 == 32 bits, 1 == 36 bits, etc etc
+// 6 and 7 are reserved
+//
+.LPARanges:
+  .byte 32, 36, 40, 42, 44, 48, -1, -1
+
+ASM_FUNCTION_REMOVE_IF_UNREFERENCED
diff --git a/ArmVirtPkg/Library/XenVirtMemInfoLib/Arm/PhysAddrTop.S b/ArmVirtPkg/Library/XenVirtMemInfoLib/Arm/PhysAddrTop.S
new file mode 100644
index 000000000000..9cd81529fb3d
--- /dev/null
+++ b/ArmVirtPkg/Library/XenVirtMemInfoLib/Arm/PhysAddrTop.S
@@ -0,0 +1,24 @@
+#
+#  Copyright (c) 2011-2013, ARM Limited. All rights reserved.
+#  Copyright (c) 2014-2017, Linaro Limited. All rights reserved.
+#
+#  This program and the accompanying materials
+#  are licensed and made available under the terms and conditions of the BSD License
+#  which accompanies this distribution.  The full text of the license may be found at
+#  http://opensource.org/licenses/bsd-license.php
+#
+#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+#
+#
+
+#include <AsmMacroIoLib.h>
+
+//EFI_PHYSICAL_ADDRESS
+//GetPhysAddrTop (
+//  VOID
+//  );
+ASM_FUNC(ArmGetPhysAddrTop)
+  mov   r0, #0x00000000
+  mov   r1, #0x10000
+  bx    lr
diff --git a/ArmVirtPkg/Library/XenVirtMemInfoLib/XenVirtMemInfoLib.c b/ArmVirtPkg/Library/XenVirtMemInfoLib/XenVirtMemInfoLib.c
new file mode 100644
index 000000000000..88ff3167cbfd
--- /dev/null
+++ b/ArmVirtPkg/Library/XenVirtMemInfoLib/XenVirtMemInfoLib.c
@@ -0,0 +1,63 @@
+/** @file
+
+  Copyright (c) 2014-2017, Linaro Limited. All rights reserved.
+
+  This program and the accompanying materials are licensed and made available
+  under the terms and conditions of the BSD License which accompanies this
+  distribution.  The full text of the license may be found at
+  http://opensource.org/licenses/bsd-license.php
+
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+**/
+
+#include <Base.h>
+#include <Library/ArmLib.h>
+#include <Library/DebugLib.h>
+
+STATIC ARM_MEMORY_REGION_DESCRIPTOR  mVirtualMemoryTable[2];
+
+EFI_PHYSICAL_ADDRESS
+ArmGetPhysAddrTop (
+  VOID
+  );
+
+/**
+  Return the Virtual Memory Map of your platform
+
+  This Virtual Memory Map is used by MemoryInitPei Module to initialize the MMU
+  on your platform.
+
+  @param[out]   VirtualMemoryMap    Array of ARM_MEMORY_REGION_DESCRIPTOR
+                                    describing a Physical-to-Virtual Memory
+                                    mapping. This array must be ended by a
+                                    zero-filled entry. The allocated memory
+                                    will not be freed.
+
+**/
+VOID
+EFIAPI
+ArmVirtGetMemoryMap (
+  OUT ARM_MEMORY_REGION_DESCRIPTOR   **VirtualMemoryMap
+  )
+{
+  ASSERT (VirtualMemoryMap != NULL);
+
+  //
+  // Map the entire physical memory space as cached. The only device
+  // we care about is the GIC, which will be stage 2 mapped as a device
+  // by the hypervisor, overriding the cached mapping we install here.
+  //
+  mVirtualMemoryTable[0].PhysicalBase = 0x0;
+  mVirtualMemoryTable[0].VirtualBase  = 0x0;
+  mVirtualMemoryTable[0].Length       = ArmGetPhysAddrTop ();
+  mVirtualMemoryTable[0].Attributes   = ARM_MEMORY_REGION_ATTRIBUTE_WRITE_BACK;
+
+  mVirtualMemoryTable[1].PhysicalBase = 0x0;
+  mVirtualMemoryTable[1].VirtualBase  = 0x0;
+  mVirtualMemoryTable[1].Length       = 0x0;
+  mVirtualMemoryTable[1].Attributes   = 0x0;
+
+  *VirtualMemoryMap = mVirtualMemoryTable;
+}
diff --git a/ArmVirtPkg/Library/XenVirtMemInfoLib/XenVirtMemInfoLib.inf b/ArmVirtPkg/Library/XenVirtMemInfoLib/XenVirtMemInfoLib.inf
new file mode 100644
index 000000000000..cd4c805a4db9
--- /dev/null
+++ b/ArmVirtPkg/Library/XenVirtMemInfoLib/XenVirtMemInfoLib.inf
@@ -0,0 +1,41 @@
+#/* @file
+#
+#  Copyright (c) 2011-2015, ARM Limited. All rights reserved.
+#  Copyright (c) 2014-2017, Linaro Limited. All rights reserved.
+#
+#  This program and the accompanying materials are licensed and made available
+#  under the terms and conditions of the BSD License which accompanies this
+#  distribution.  The full text of the license may be found at
+#  http://opensource.org/licenses/bsd-license.php
+#
+#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+#
+#*/
+
+[Defines]
+  INF_VERSION                    = 0x0001001A
+  BASE_NAME                      = XenVirtMemInfoLib
+  FILE_GUID                      = 40d1f8f5-4dfe-4e0f-9a15-b1de9dc9f4ed
+  MODULE_TYPE                    = BASE
+  VERSION_STRING                 = 1.0
+  LIBRARY_CLASS                  = ArmVirtMemInfoLib
+
+[Sources]
+  XenVirtMemInfoLib.c
+
+[Sources.ARM]
+  Arm/PhysAddrTop.S
+
+[Sources.AARCH64]
+  AArch64/PhysAddrTop.S
+
+[Packages]
+  ArmPkg/ArmPkg.dec
+  ArmVirtPkg/ArmVirtPkg.dec
+  MdeModulePkg/MdeModulePkg.dec
+  MdePkg/MdePkg.dec
+
+[LibraryClasses]
+  ArmLib
+  DebugLib
-- 
2.11.0



^ permalink raw reply related	[flat|nested] 21+ messages in thread

* [PATCH v2 11/14] ArmVirtPkg/ArmVirtQemu: add ArmVirtMemInfoLib implementation
  2017-11-22 10:07 [PATCH v2 00/14] ArmVirtPkg: get rid of ArmPlatformLib Ard Biesheuvel
                   ` (9 preceding siblings ...)
  2017-11-22 10:07 ` [PATCH v2 10/14] ArmVirtPkg/ArmVirtXen: add ArmVirtMemInfoLib implementation Ard Biesheuvel
@ 2017-11-22 10:07 ` Ard Biesheuvel
  2017-11-23 16:18   ` Laszlo Ersek
  2017-11-22 10:07 ` [PATCH v2 12/14] ArmVirtPkg: create QemuVirtMemInfoLib version for ArmVirtQemu Ard Biesheuvel
                   ` (3 subsequent siblings)
  14 siblings, 1 reply; 21+ messages in thread
From: Ard Biesheuvel @ 2017-11-22 10:07 UTC (permalink / raw)
  To: edk2-devel, lersek; +Cc: Ard Biesheuvel

Create a new ArmVirtMemInfoLib for ArmVirtQemuKernel by cloning the
existing ArmPlatformGetVirtualMemoryMap () for this platform,
(ArmQemuRelocatablePlatformLib *not* ArmVirtPlatformLib), and cleaning
it up:
- remove support for uncached DRAM mappings
- replace EFI_D_xxx with DEBUG_xxx throughout
- use a temp variable to hold the top of the physical address space
- use AllocatePool () instead of AllocatePages (), given that we use
  160 bytes only, and the memory is never freed.

In a future patch, we will add this library to the ordinary ArmVirtQemu
platform as well.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
---
 ArmVirtPkg/ArmVirtQemuKernel.dsc                             |   1 +
 ArmVirtPkg/Library/QemuVirtMemInfoLib/AArch64/PhysAddrTop.S  |  39 ++++++++
 ArmVirtPkg/Library/QemuVirtMemInfoLib/Arm/PhysAddrTop.S      |  24 +++++
 ArmVirtPkg/Library/QemuVirtMemInfoLib/QemuVirtMemInfoLib.c   | 100 ++++++++++++++++++++
 ArmVirtPkg/Library/QemuVirtMemInfoLib/QemuVirtMemInfoLib.inf |  54 +++++++++++
 5 files changed, 218 insertions(+)

diff --git a/ArmVirtPkg/ArmVirtQemuKernel.dsc b/ArmVirtPkg/ArmVirtQemuKernel.dsc
index 7e5d584344b4..f50d30388cf2 100644
--- a/ArmVirtPkg/ArmVirtQemuKernel.dsc
+++ b/ArmVirtPkg/ArmVirtQemuKernel.dsc
@@ -49,6 +49,7 @@ [LibraryClasses.common]
   QemuFwCfgS3Lib|OvmfPkg/Library/QemuFwCfgS3Lib/BaseQemuFwCfgS3LibNull.inf
 
   ArmPlatformLib|ArmVirtPkg/Library/ArmQemuRelocatablePlatformLib/ArmQemuRelocatablePlatformLib.inf
+  ArmVirtMemInfoLib|ArmVirtPkg/Library/QemuVirtMemInfoLib/QemuVirtMemInfoLib.inf
 
   TimerLib|ArmPkg/Library/ArmArchTimerLib/ArmArchTimerLib.inf
   NorFlashPlatformLib|ArmVirtPkg/Library/NorFlashQemuLib/NorFlashQemuLib.inf
diff --git a/ArmVirtPkg/Library/QemuVirtMemInfoLib/AArch64/PhysAddrTop.S b/ArmVirtPkg/Library/QemuVirtMemInfoLib/AArch64/PhysAddrTop.S
new file mode 100644
index 000000000000..a1f6a194d59b
--- /dev/null
+++ b/ArmVirtPkg/Library/QemuVirtMemInfoLib/AArch64/PhysAddrTop.S
@@ -0,0 +1,39 @@
+#
+#  Copyright (c) 2011-2013, ARM Limited. All rights reserved.
+#  Copyright (c) 2016-2017, Linaro Limited. All rights reserved.
+#
+#  This program and the accompanying materials
+#  are licensed and made available under the terms and conditions of the BSD License
+#  which accompanies this distribution.  The full text of the license may be found at
+#  http://opensource.org/licenses/bsd-license.php
+#
+#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+#
+#
+
+#include <AsmMacroIoLibV8.h>
+
+//EFI_PHYSICAL_ADDRESS
+//GetPhysAddrTop (
+//  VOID
+//  );
+ASM_FUNC(ArmGetPhysAddrTop)
+  mrs   x0, id_aa64mmfr0_el1
+  adr   x1, .LPARanges
+  and   x0, x0, #7
+  ldrb  w1, [x1, x0]
+  mov   x0, #1
+  lsl   x0, x0, x1
+  ret
+
+//
+// Bits 0..2 of the AA64MFR0_EL1 system register encode the size of the
+// physical address space support on this CPU:
+// 0 == 32 bits, 1 == 36 bits, etc etc
+// 6 and 7 are reserved
+//
+.LPARanges:
+  .byte 32, 36, 40, 42, 44, 48, -1, -1
+
+ASM_FUNCTION_REMOVE_IF_UNREFERENCED
diff --git a/ArmVirtPkg/Library/QemuVirtMemInfoLib/Arm/PhysAddrTop.S b/ArmVirtPkg/Library/QemuVirtMemInfoLib/Arm/PhysAddrTop.S
new file mode 100644
index 000000000000..9cd81529fb3d
--- /dev/null
+++ b/ArmVirtPkg/Library/QemuVirtMemInfoLib/Arm/PhysAddrTop.S
@@ -0,0 +1,24 @@
+#
+#  Copyright (c) 2011-2013, ARM Limited. All rights reserved.
+#  Copyright (c) 2014-2017, Linaro Limited. All rights reserved.
+#
+#  This program and the accompanying materials
+#  are licensed and made available under the terms and conditions of the BSD License
+#  which accompanies this distribution.  The full text of the license may be found at
+#  http://opensource.org/licenses/bsd-license.php
+#
+#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+#
+#
+
+#include <AsmMacroIoLib.h>
+
+//EFI_PHYSICAL_ADDRESS
+//GetPhysAddrTop (
+//  VOID
+//  );
+ASM_FUNC(ArmGetPhysAddrTop)
+  mov   r0, #0x00000000
+  mov   r1, #0x10000
+  bx    lr
diff --git a/ArmVirtPkg/Library/QemuVirtMemInfoLib/QemuVirtMemInfoLib.c b/ArmVirtPkg/Library/QemuVirtMemInfoLib/QemuVirtMemInfoLib.c
new file mode 100644
index 000000000000..ea70f2c33b77
--- /dev/null
+++ b/ArmVirtPkg/Library/QemuVirtMemInfoLib/QemuVirtMemInfoLib.c
@@ -0,0 +1,100 @@
+/** @file
+
+  Copyright (c) 2014-2017, Linaro Limited. All rights reserved.
+
+  This program and the accompanying materials are licensed and made available
+  under the terms and conditions of the BSD License which accompanies this
+  distribution.  The full text of the license may be found at
+  http://opensource.org/licenses/bsd-license.php
+
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+**/
+
+#include <Base.h>
+#include <Library/ArmLib.h>
+#include <Library/BaseMemoryLib.h>
+#include <Library/DebugLib.h>
+#include <Library/MemoryAllocationLib.h>
+
+// Number of Virtual Memory Map Descriptors
+#define MAX_VIRTUAL_MEMORY_MAP_DESCRIPTORS          5
+
+EFI_PHYSICAL_ADDRESS
+ArmGetPhysAddrTop (
+  VOID
+  );
+
+/**
+  Return the Virtual Memory Map of your platform
+
+  This Virtual Memory Map is used by MemoryInitPei Module to initialize the MMU
+  on your platform.
+
+  @param[out]   VirtualMemoryMap    Array of ARM_MEMORY_REGION_DESCRIPTOR
+                                    describing a Physical-to-Virtual Memory
+                                    mapping. This array must be ended by a
+                                    zero-filled entry. The allocated memory
+                                    will not be freed.
+
+**/
+VOID
+ArmVirtGetMemoryMap (
+  OUT ARM_MEMORY_REGION_DESCRIPTOR   **VirtualMemoryMap
+  )
+{
+  ARM_MEMORY_REGION_DESCRIPTOR  *VirtualMemoryTable;
+  UINT64                        TopOfMemory;
+
+  ASSERT (VirtualMemoryMap != NULL);
+
+  VirtualMemoryTable = AllocatePool (sizeof (ARM_MEMORY_REGION_DESCRIPTOR) *
+                                     MAX_VIRTUAL_MEMORY_MAP_DESCRIPTORS);
+
+  if (VirtualMemoryTable == NULL) {
+    DEBUG ((DEBUG_ERROR, "%a: Error: Failed AllocatePages()\n", __FUNCTION__));
+    return;
+  }
+
+  // System DRAM
+  VirtualMemoryTable[0].PhysicalBase = PcdGet64 (PcdSystemMemoryBase);
+  VirtualMemoryTable[0].VirtualBase  = VirtualMemoryTable[0].PhysicalBase;
+  VirtualMemoryTable[0].Length       = PcdGet64 (PcdSystemMemorySize);
+  VirtualMemoryTable[0].Attributes   = ARM_MEMORY_REGION_ATTRIBUTE_WRITE_BACK;
+
+  DEBUG ((DEBUG_INFO, "%a: Dumping System DRAM Memory Map:\n"
+      "\tPhysicalBase: 0x%lX\n"
+      "\tVirtualBase: 0x%lX\n"
+      "\tLength: 0x%lX\n",
+      __FUNCTION__,
+      VirtualMemoryTable[0].PhysicalBase,
+      VirtualMemoryTable[0].VirtualBase,
+      VirtualMemoryTable[0].Length));
+
+  // Peripheral space before DRAM
+  VirtualMemoryTable[1].PhysicalBase = 0x0;
+  VirtualMemoryTable[1].VirtualBase  = 0x0;
+  VirtualMemoryTable[1].Length       = VirtualMemoryTable[0].PhysicalBase;
+  VirtualMemoryTable[1].Attributes   = ARM_MEMORY_REGION_ATTRIBUTE_DEVICE;
+
+  // Peripheral space after DRAM
+  TopOfMemory = MIN (1ULL << FixedPcdGet8 (PcdPrePiCpuMemorySize),
+                     ArmGetPhysAddrTop ());
+  VirtualMemoryTable[2].PhysicalBase = VirtualMemoryTable[0].Length + VirtualMemoryTable[1].Length;
+  VirtualMemoryTable[2].VirtualBase  = VirtualMemoryTable[2].PhysicalBase;
+  VirtualMemoryTable[2].Length       = TopOfMemory -
+                                       VirtualMemoryTable[2].PhysicalBase;
+  VirtualMemoryTable[2].Attributes   = ARM_MEMORY_REGION_ATTRIBUTE_DEVICE;
+
+  // Remap the FD region as normal executable memory
+  VirtualMemoryTable[3].PhysicalBase = PcdGet64 (PcdFdBaseAddress);
+  VirtualMemoryTable[3].VirtualBase  = VirtualMemoryTable[3].PhysicalBase;
+  VirtualMemoryTable[3].Length       = FixedPcdGet32 (PcdFdSize);
+  VirtualMemoryTable[3].Attributes   = ARM_MEMORY_REGION_ATTRIBUTE_WRITE_BACK;
+
+  // End of Table
+  ZeroMem (&VirtualMemoryTable[4], sizeof (ARM_MEMORY_REGION_DESCRIPTOR));
+
+  *VirtualMemoryMap = VirtualMemoryTable;
+}
diff --git a/ArmVirtPkg/Library/QemuVirtMemInfoLib/QemuVirtMemInfoLib.inf b/ArmVirtPkg/Library/QemuVirtMemInfoLib/QemuVirtMemInfoLib.inf
new file mode 100644
index 000000000000..c72a97f9e78a
--- /dev/null
+++ b/ArmVirtPkg/Library/QemuVirtMemInfoLib/QemuVirtMemInfoLib.inf
@@ -0,0 +1,54 @@
+#/* @file
+#
+#  Copyright (c) 2011-2015, ARM Limited. All rights reserved.
+#  Copyright (c) 2014-2017, Linaro Limited. All rights reserved.
+#
+#  This program and the accompanying materials are licensed and made available
+#  under the terms and conditions of the BSD License which accompanies this
+#  distribution.  The full text of the license may be found at
+#  http://opensource.org/licenses/bsd-license.php
+#
+#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+#
+#*/
+
+[Defines]
+  INF_VERSION                    = 0x0001001A
+  BASE_NAME                      = QemuVirtMemInfoLib
+  FILE_GUID                      = 9b30ca82-6746-4a82-a3e6-11ea79df3b46
+  MODULE_TYPE                    = BASE
+  VERSION_STRING                 = 1.0
+  LIBRARY_CLASS                  = ArmVirtMemInfoLib
+
+[Sources]
+  QemuVirtMemInfoLib.c
+
+[Sources.ARM]
+  Arm/PhysAddrTop.S
+
+[Sources.AARCH64]
+  AArch64/PhysAddrTop.S
+
+[Packages]
+  ArmPkg/ArmPkg.dec
+  ArmVirtPkg/ArmVirtPkg.dec
+  EmbeddedPkg/EmbeddedPkg.dec
+  MdeModulePkg/MdeModulePkg.dec
+  MdePkg/MdePkg.dec
+
+[LibraryClasses]
+  ArmLib
+  BaseMemoryLib
+  DebugLib
+  MemoryAllocationLib
+  PcdLib
+
+[Pcd]
+  gArmTokenSpaceGuid.PcdFdBaseAddress
+  gArmTokenSpaceGuid.PcdSystemMemoryBase
+  gArmTokenSpaceGuid.PcdSystemMemorySize
+
+[FixedPcd]
+  gArmTokenSpaceGuid.PcdFdSize
+  gEmbeddedTokenSpaceGuid.PcdPrePiCpuMemorySize
-- 
2.11.0



^ permalink raw reply related	[flat|nested] 21+ messages in thread

* [PATCH v2 12/14] ArmVirtPkg: create QemuVirtMemInfoLib version for ArmVirtQemu
  2017-11-22 10:07 [PATCH v2 00/14] ArmVirtPkg: get rid of ArmPlatformLib Ard Biesheuvel
                   ` (10 preceding siblings ...)
  2017-11-22 10:07 ` [PATCH v2 11/14] ArmVirtPkg/ArmVirtQemu: " Ard Biesheuvel
@ 2017-11-22 10:07 ` Ard Biesheuvel
  2017-11-23 16:26   ` Laszlo Ersek
  2017-11-22 10:07 ` [PATCH v2 13/14] ArmVirtPkg/ArmVirtMemoryInitPeiLib: move to ArmVirtMemInfoLib Ard Biesheuvel
                   ` (2 subsequent siblings)
  14 siblings, 1 reply; 21+ messages in thread
From: Ard Biesheuvel @ 2017-11-22 10:07 UTC (permalink / raw)
  To: edk2-devel, lersek; +Cc: Ard Biesheuvel

The QemuVirtMemInfoLib ArmVirtMemInfoLib implementation created for
ArmVirtQemuKernel does exactly what we need for ArmVirtQemu, the only
difference being that the latter is PrePeiCore based, and so it uses
a different method to ensure that PcdSystemMemorySize is set when
ArmVirtGetMemoryMap() is called.

On ArmVirtQemu, we currently abuse the implied ordering guarantees
provided by ArmPlatformLib, by implementing this as follows:

  ArmPlatformPkg/MemoryInitPei/MemoryInitPeim.inf [ArmVirtPkg/ArmVirtQemu.dsc]
    InitializeMemory()                            [ArmPlatformPkg/MemoryInitPei/MemoryInitPeim.c]
      ArmPlatformInitializeSystemMemory()         [ArmVirtPkg/Library/ArmVirtPlatformLib/Virt.c]
        //
        // set PcdSystemMemorySize from the DT
        //
      MemoryPeim()                                [ArmVirtPkg/Library/ArmVirtMemoryInitPeiLib/ArmVirtMemoryInitPeiLib.c]
        InitMmu()                                 [ArmVirtPkg/Library/ArmVirtMemoryInitPeiLib/ArmVirtMemoryInitPeiLib.c]
          ArmPlatformGetVirtualMemoryMap()        [ArmVirtPkg/Library/ArmVirtPlatformLib/VirtMem.c]
            //
            // consume PcdSystemMemorySize
            //

Given that we are trying to get rid of ArmPlatformLib, or at least remove
some of these API functions that are never used for their original purpose
by any platforms, we need to move the PCD assignment elsewhere.

So create a PEIM-only version of QemuVirtMemInfoLib especially for
ArmVirtQemu, and add the PCD assignment code to its constructor.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
---
 ArmVirtPkg/ArmVirtQemu.dsc                                               |   3 +
 ArmVirtPkg/Library/QemuVirtMemInfoLib/QemuVirtMemInfoPeiLib.inf          |  58 +++++++++++
 ArmVirtPkg/Library/QemuVirtMemInfoLib/QemuVirtMemInfoPeiLibConstructor.c | 106 ++++++++++++++++++++
 3 files changed, 167 insertions(+)

diff --git a/ArmVirtPkg/ArmVirtQemu.dsc b/ArmVirtPkg/ArmVirtQemu.dsc
index d14a0dd0d1d9..519c2ae2e939 100644
--- a/ArmVirtPkg/ArmVirtQemu.dsc
+++ b/ArmVirtPkg/ArmVirtQemu.dsc
@@ -67,6 +67,9 @@ [LibraryClasses.common]
   HttpLib|MdeModulePkg/Library/DxeHttpLib/DxeHttpLib.inf
 !endif
 
+[LibraryClasses.common.PEIM]
+  ArmVirtMemInfoLib|ArmVirtPkg/Library/QemuVirtMemInfoLib/QemuVirtMemInfoPeiLib.inf
+
 [LibraryClasses.common.UEFI_DRIVER]
   UefiScsiLib|MdePkg/Library/UefiScsiLib/UefiScsiLib.inf
 
diff --git a/ArmVirtPkg/Library/QemuVirtMemInfoLib/QemuVirtMemInfoPeiLib.inf b/ArmVirtPkg/Library/QemuVirtMemInfoLib/QemuVirtMemInfoPeiLib.inf
new file mode 100644
index 000000000000..e574a47443d0
--- /dev/null
+++ b/ArmVirtPkg/Library/QemuVirtMemInfoLib/QemuVirtMemInfoPeiLib.inf
@@ -0,0 +1,58 @@
+#/* @file
+#
+#  Copyright (c) 2011-2015, ARM Limited. All rights reserved.
+#  Copyright (c) 2014-2017, Linaro Limited. All rights reserved.
+#
+#  This program and the accompanying materials are licensed and made available
+#  under the terms and conditions of the BSD License which accompanies this
+#  distribution.  The full text of the license may be found at
+#  http://opensource.org/licenses/bsd-license.php
+#
+#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+#
+#*/
+
+[Defines]
+  INF_VERSION                    = 0x0001001A
+  BASE_NAME                      = QemuVirtMemInfoLib
+  FILE_GUID                      = 0c4d10cf-d949-49b4-bd13-47a4ae22efce
+  MODULE_TYPE                    = BASE
+  VERSION_STRING                 = 1.0
+  LIBRARY_CLASS                  = ArmVirtMemInfoLib|PEIM
+  CONSTRUCTOR                    = QemuVirtMemInfoPeiLibConstructor
+
+[Sources]
+  QemuVirtMemInfoLib.c
+  QemuVirtMemInfoPeiLibConstructor.c
+
+[Sources.ARM]
+  Arm/PhysAddrTop.S
+
+[Sources.AARCH64]
+  AArch64/PhysAddrTop.S
+
+[Packages]
+  ArmPkg/ArmPkg.dec
+  ArmVirtPkg/ArmVirtPkg.dec
+  EmbeddedPkg/EmbeddedPkg.dec
+  MdeModulePkg/MdeModulePkg.dec
+  MdePkg/MdePkg.dec
+
+[LibraryClasses]
+  ArmLib
+  BaseMemoryLib
+  DebugLib
+  FdtLib
+  PcdLib
+  MemoryAllocationLib
+
+[Pcd]
+  gArmTokenSpaceGuid.PcdFdBaseAddress
+  gArmTokenSpaceGuid.PcdSystemMemoryBase
+  gArmTokenSpaceGuid.PcdSystemMemorySize
+
+[FixedPcd]
+  gArmTokenSpaceGuid.PcdFdSize
+  gArmVirtTokenSpaceGuid.PcdDeviceTreeInitialBaseAddress
+  gEmbeddedTokenSpaceGuid.PcdPrePiCpuMemorySize
diff --git a/ArmVirtPkg/Library/QemuVirtMemInfoLib/QemuVirtMemInfoPeiLibConstructor.c b/ArmVirtPkg/Library/QemuVirtMemInfoLib/QemuVirtMemInfoPeiLibConstructor.c
new file mode 100644
index 000000000000..ef8ac6e018d1
--- /dev/null
+++ b/ArmVirtPkg/Library/QemuVirtMemInfoLib/QemuVirtMemInfoPeiLibConstructor.c
@@ -0,0 +1,106 @@
+/** @file
+
+  Copyright (c) 2014-2017, Linaro Limited. All rights reserved.
+
+  This program and the accompanying materials are licensed and made available
+  under the terms and conditions of the BSD License which accompanies this
+  distribution.  The full text of the license may be found at
+  http://opensource.org/licenses/bsd-license.php
+
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+**/
+
+#include <Base.h>
+#include <Library/DebugLib.h>
+#include <Library/PcdLib.h>
+#include <libfdt.h>
+
+RETURN_STATUS
+EFIAPI
+QemuVirtMemInfoPeiLibConstructor (
+  VOID
+  )
+{
+  VOID          *DeviceTreeBase;
+  INT32         Node, Prev;
+  UINT64        NewBase, CurBase;
+  UINT64        NewSize, CurSize;
+  CONST CHAR8   *Type;
+  INT32         Len;
+  CONST UINT64  *RegProp;
+  RETURN_STATUS PcdStatus;
+
+  NewBase = 0;
+  NewSize = 0;
+
+  DeviceTreeBase = (VOID *)(UINTN)PcdGet64 (PcdDeviceTreeInitialBaseAddress);
+  ASSERT (DeviceTreeBase != NULL);
+
+  //
+  // Make sure we have a valid device tree blob
+  //
+  ASSERT (fdt_check_header (DeviceTreeBase) == 0);
+
+  //
+  // Look for the lowest memory node
+  //
+  for (Prev = 0;; Prev = Node) {
+    Node = fdt_next_node (DeviceTreeBase, Prev, NULL);
+    if (Node < 0) {
+      break;
+    }
+
+    //
+    // Check for memory node
+    //
+    Type = fdt_getprop (DeviceTreeBase, Node, "device_type", &Len);
+    if (Type && AsciiStrnCmp (Type, "memory", Len) == 0) {
+      //
+      // Get the 'reg' property of this node. For now, we will assume
+      // two 8 byte quantities for base and size, respectively.
+      //
+      RegProp = fdt_getprop (DeviceTreeBase, Node, "reg", &Len);
+      if (RegProp != 0 && Len == (2 * sizeof (UINT64))) {
+
+        CurBase = fdt64_to_cpu (ReadUnaligned64 (RegProp));
+        CurSize = fdt64_to_cpu (ReadUnaligned64 (RegProp + 1));
+
+        DEBUG ((DEBUG_INFO, "%a: System RAM @ 0x%lx - 0x%lx\n",
+          __FUNCTION__, CurBase, CurBase + CurSize - 1));
+
+        if (NewBase > CurBase || NewBase == 0) {
+          NewBase = CurBase;
+          NewSize = CurSize;
+        }
+      } else {
+        DEBUG ((DEBUG_ERROR, "%a: Failed to parse FDT memory node\n",
+          __FUNCTION__));
+      }
+    }
+  }
+
+  //
+  // Make sure the start of DRAM matches our expectation
+  //
+  ASSERT (FixedPcdGet64 (PcdSystemMemoryBase) == NewBase);
+  PcdStatus = PcdSet64S (PcdSystemMemorySize, NewSize);
+  ASSERT_RETURN_ERROR (PcdStatus);
+
+  //
+  // We need to make sure that the machine we are running on has at least
+  // 128 MB of memory configured, and is currently executing this binary from
+  // NOR flash. This prevents a device tree image in DRAM from getting
+  // clobbered when our caller installs permanent PEI RAM, before we have a
+  // chance of marking its location as reserved or copy it to a freshly
+  // allocated block in the permanent PEI RAM in the platform PEIM.
+  //
+  ASSERT (NewSize >= SIZE_128MB);
+  ASSERT (
+    (((UINT64)PcdGet64 (PcdFdBaseAddress) +
+      (UINT64)PcdGet32 (PcdFdSize)) <= NewBase) ||
+    ((UINT64)PcdGet64 (PcdFdBaseAddress) >= (NewBase + NewSize)));
+
+  return RETURN_SUCCESS;
+}
-- 
2.11.0



^ permalink raw reply related	[flat|nested] 21+ messages in thread

* [PATCH v2 13/14] ArmVirtPkg/ArmVirtMemoryInitPeiLib: move to ArmVirtMemInfoLib
  2017-11-22 10:07 [PATCH v2 00/14] ArmVirtPkg: get rid of ArmPlatformLib Ard Biesheuvel
                   ` (11 preceding siblings ...)
  2017-11-22 10:07 ` [PATCH v2 12/14] ArmVirtPkg: create QemuVirtMemInfoLib version for ArmVirtQemu Ard Biesheuvel
@ 2017-11-22 10:07 ` Ard Biesheuvel
  2017-11-23 16:32   ` Laszlo Ersek
  2017-11-22 10:07 ` [PATCH v2 14/14] ArmVirtPkg: remove ArmPlatformLib implementations Ard Biesheuvel
  2017-11-23 16:56 ` [PATCH v2 00/14] ArmVirtPkg: get rid of ArmPlatformLib Ard Biesheuvel
  14 siblings, 1 reply; 21+ messages in thread
From: Ard Biesheuvel @ 2017-11-22 10:07 UTC (permalink / raw)
  To: edk2-devel, lersek; +Cc: Ard Biesheuvel

Move to the new ArmVirtMemInfoLib library to retrieve DRAM information
from the platform, so that we can phase out ArmPlatformLib going forward.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
---
 ArmVirtPkg/ArmVirtQemu.dsc                                             | 2 +-
 ArmVirtPkg/Library/ArmVirtMemoryInitPeiLib/ArmVirtMemoryInitPeiLib.c   | 4 ++--
 ArmVirtPkg/Library/ArmVirtMemoryInitPeiLib/ArmVirtMemoryInitPeiLib.inf | 3 ++-
 3 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/ArmVirtPkg/ArmVirtQemu.dsc b/ArmVirtPkg/ArmVirtQemu.dsc
index 519c2ae2e939..f09226671827 100644
--- a/ArmVirtPkg/ArmVirtQemu.dsc
+++ b/ArmVirtPkg/ArmVirtQemu.dsc
@@ -48,7 +48,7 @@ [LibraryClasses.common]
   QemuFwCfgLib|ArmVirtPkg/Library/QemuFwCfgLib/QemuFwCfgLib.inf
   QemuFwCfgS3Lib|OvmfPkg/Library/QemuFwCfgS3Lib/BaseQemuFwCfgS3LibNull.inf
 
-  ArmPlatformLib|ArmVirtPkg/Library/ArmVirtPlatformLib/ArmVirtPlatformLib.inf
+  ArmPlatformLib|ArmPlatformPkg/Library/ArmPlatformLibNull/ArmPlatformLibNull.inf
 
   TimerLib|ArmPkg/Library/ArmArchTimerLib/ArmArchTimerLib.inf
   NorFlashPlatformLib|ArmVirtPkg/Library/NorFlashQemuLib/NorFlashQemuLib.inf
diff --git a/ArmVirtPkg/Library/ArmVirtMemoryInitPeiLib/ArmVirtMemoryInitPeiLib.c b/ArmVirtPkg/Library/ArmVirtMemoryInitPeiLib/ArmVirtMemoryInitPeiLib.c
index 6f3e54b7afcb..05afd1282422 100644
--- a/ArmVirtPkg/Library/ArmVirtMemoryInitPeiLib/ArmVirtMemoryInitPeiLib.c
+++ b/ArmVirtPkg/Library/ArmVirtMemoryInitPeiLib/ArmVirtMemoryInitPeiLib.c
@@ -16,7 +16,7 @@
 #include <PiPei.h>
 
 #include <Library/ArmMmuLib.h>
-#include <Library/ArmPlatformLib.h>
+#include <Library/ArmVirtMemInfoLib.h>
 #include <Library/DebugLib.h>
 #include <Library/HobLib.h>
 #include <Library/MemoryAllocationLib.h>
@@ -39,7 +39,7 @@ InitMmu (
   RETURN_STATUS                 Status;
 
   // Get Virtual Memory Map from the Platform Library
-  ArmPlatformGetVirtualMemoryMap (&MemoryTable);
+  ArmVirtGetMemoryMap (&MemoryTable);
 
   //Note: Because we called PeiServicesInstallPeiMemory() before to call InitMmu() the MMU Page Table resides in
   //      DRAM (even at the top of DRAM as it is the first permanent memory allocation)
diff --git a/ArmVirtPkg/Library/ArmVirtMemoryInitPeiLib/ArmVirtMemoryInitPeiLib.inf b/ArmVirtPkg/Library/ArmVirtMemoryInitPeiLib/ArmVirtMemoryInitPeiLib.inf
index 028d6fb5ac28..54879d590a8a 100644
--- a/ArmVirtPkg/Library/ArmVirtMemoryInitPeiLib/ArmVirtMemoryInitPeiLib.inf
+++ b/ArmVirtPkg/Library/ArmVirtMemoryInitPeiLib/ArmVirtMemoryInitPeiLib.inf
@@ -29,13 +29,14 @@ [Packages]
   EmbeddedPkg/EmbeddedPkg.dec
   ArmPkg/ArmPkg.dec
   ArmPlatformPkg/ArmPlatformPkg.dec
+  ArmVirtPkg/ArmVirtPkg.dec
 
 [LibraryClasses]
   DebugLib
   HobLib
   ArmLib
   ArmMmuLib
-  ArmPlatformLib
+  ArmVirtMemInfoLib
   CacheMaintenanceLib
 
 [Guids]
-- 
2.11.0



^ permalink raw reply related	[flat|nested] 21+ messages in thread

* [PATCH v2 14/14] ArmVirtPkg: remove ArmPlatformLib implementations
  2017-11-22 10:07 [PATCH v2 00/14] ArmVirtPkg: get rid of ArmPlatformLib Ard Biesheuvel
                   ` (12 preceding siblings ...)
  2017-11-22 10:07 ` [PATCH v2 13/14] ArmVirtPkg/ArmVirtMemoryInitPeiLib: move to ArmVirtMemInfoLib Ard Biesheuvel
@ 2017-11-22 10:07 ` Ard Biesheuvel
  2017-11-23 16:56 ` [PATCH v2 00/14] ArmVirtPkg: get rid of ArmPlatformLib Ard Biesheuvel
  14 siblings, 0 replies; 21+ messages in thread
From: Ard Biesheuvel @ 2017-11-22 10:07 UTC (permalink / raw)
  To: edk2-devel, lersek; +Cc: Ard Biesheuvel

These libraries are no longer used, so remove them from the tree.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Reviewed-by: Laszlo Ersek <lersek@redhat.com>
---
 ArmVirtPkg/ArmVirtQemuKernel.dsc                                                   |   1 -
 ArmVirtPkg/ArmVirtXen.dsc                                                          |   1 -
 ArmVirtPkg/Library/ArmQemuRelocatablePlatformLib/AARCH64/RelocatableVirtHelper.S   | 141 -----------------
 ArmVirtPkg/Library/ArmQemuRelocatablePlatformLib/ARM/RelocatableVirtHelper.S       | 123 ---------------
 ArmVirtPkg/Library/ArmQemuRelocatablePlatformLib/ArmQemuRelocatablePlatformLib.inf |  64 --------
 ArmVirtPkg/Library/ArmQemuRelocatablePlatformLib/FdtParser.c                       |  90 -----------
 ArmVirtPkg/Library/ArmQemuRelocatablePlatformLib/QemuVirtMem.c                     | 106 -------------
 ArmVirtPkg/Library/ArmQemuRelocatablePlatformLib/RelocatableVirt.c                 |  70 ---------
 ArmVirtPkg/Library/ArmVirtPlatformLib/AARCH64/VirtHelper.S                         |  70 ---------
 ArmVirtPkg/Library/ArmVirtPlatformLib/ARM/VirtHelper.S                             |  57 -------
 ArmVirtPkg/Library/ArmVirtPlatformLib/ARM/VirtHelper.asm                           |  71 ---------
 ArmVirtPkg/Library/ArmVirtPlatformLib/ArmVirtPlatformLib.inf                       |  64 --------
 ArmVirtPkg/Library/ArmVirtPlatformLib/Virt.c                                       | 160 --------------------
 ArmVirtPkg/Library/ArmVirtPlatformLib/VirtMem.c                                    | 102 -------------
 ArmVirtPkg/Library/ArmXenRelocatablePlatformLib/AARCH64/RelocatableVirtHelper.S    | 140 -----------------
 ArmVirtPkg/Library/ArmXenRelocatablePlatformLib/ARM/RelocatableVirtHelper.S        | 123 ---------------
 ArmVirtPkg/Library/ArmXenRelocatablePlatformLib/ArmXenRelocatablePlatformLib.inf   |  63 --------
 ArmVirtPkg/Library/ArmXenRelocatablePlatformLib/FdtParser.c                        |  89 -----------
 ArmVirtPkg/Library/ArmXenRelocatablePlatformLib/RelocatableVirt.c                  |  70 ---------
 ArmVirtPkg/Library/ArmXenRelocatablePlatformLib/XenVirtMem.c                       |  82 ----------
 20 files changed, 1687 deletions(-)

diff --git a/ArmVirtPkg/ArmVirtQemuKernel.dsc b/ArmVirtPkg/ArmVirtQemuKernel.dsc
index f50d30388cf2..cc2c5a50c925 100644
--- a/ArmVirtPkg/ArmVirtQemuKernel.dsc
+++ b/ArmVirtPkg/ArmVirtQemuKernel.dsc
@@ -48,7 +48,6 @@ [LibraryClasses.common]
   QemuFwCfgLib|ArmVirtPkg/Library/QemuFwCfgLib/QemuFwCfgLib.inf
   QemuFwCfgS3Lib|OvmfPkg/Library/QemuFwCfgS3Lib/BaseQemuFwCfgS3LibNull.inf
 
-  ArmPlatformLib|ArmVirtPkg/Library/ArmQemuRelocatablePlatformLib/ArmQemuRelocatablePlatformLib.inf
   ArmVirtMemInfoLib|ArmVirtPkg/Library/QemuVirtMemInfoLib/QemuVirtMemInfoLib.inf
 
   TimerLib|ArmPkg/Library/ArmArchTimerLib/ArmArchTimerLib.inf
diff --git a/ArmVirtPkg/ArmVirtXen.dsc b/ArmVirtPkg/ArmVirtXen.dsc
index 3df684d13cb0..11e073287a84 100644
--- a/ArmVirtPkg/ArmVirtXen.dsc
+++ b/ArmVirtPkg/ArmVirtXen.dsc
@@ -43,7 +43,6 @@ [LibraryClasses]
   VirtioLib|OvmfPkg/Library/VirtioLib/VirtioLib.inf
   VirtioMmioDeviceLib|OvmfPkg/Library/VirtioMmioDeviceLib/VirtioMmioDeviceLib.inf
 
-  ArmPlatformLib|ArmVirtPkg/Library/ArmXenRelocatablePlatformLib/ArmXenRelocatablePlatformLib.inf
   ArmVirtMemInfoLib|ArmVirtPkg/Library/XenVirtMemInfoLib/XenVirtMemInfoLib.inf
 
   TimerLib|ArmPkg/Library/ArmArchTimerLib/ArmArchTimerLib.inf
diff --git a/ArmVirtPkg/Library/ArmQemuRelocatablePlatformLib/AARCH64/RelocatableVirtHelper.S b/ArmVirtPkg/Library/ArmQemuRelocatablePlatformLib/AARCH64/RelocatableVirtHelper.S
deleted file mode 100644
index ec6955cf0af8..000000000000
--- a/ArmVirtPkg/Library/ArmQemuRelocatablePlatformLib/AARCH64/RelocatableVirtHelper.S
+++ /dev/null
@@ -1,141 +0,0 @@
-#
-#  Copyright (c) 2011-2013, ARM Limited. All rights reserved.
-#  Copyright (c) 2016, Linaro Limited. All rights reserved.
-#
-#  This program and the accompanying materials
-#  are licensed and made available under the terms and conditions of the BSD License
-#  which accompanies this distribution.  The full text of the license may be found at
-#  http://opensource.org/licenses/bsd-license.php
-#
-#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
-#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
-#
-#
-
-#include <AsmMacroIoLibV8.h>
-#include <Library/ArmLib.h>
-
-// VOID
-// ArmPlatformPeiBootAction (
-//   VOID   *DeviceTreeBaseAddress,   // passed by loader in x0
-//   VOID   *ImageBase                // passed by FDF trampoline in x1
-//   );
-ASM_FUNC(ArmPlatformPeiBootAction)
-  //
-  // If we are booting from RAM using the Linux kernel boot protocol, x0 will
-  // point to the DTB image in memory. Otherwise, use the default value defined
-  // by the platform.
-  //
-  cbnz  x0, 0f
-  ldr   x0, PcdGet64 (PcdDeviceTreeInitialBaseAddress)
-
-0:mov   x29, x30            // preserve LR
-  mov   x28, x0             // preserve DTB pointer
-  mov   x27, x1             // preserve base of image pointer
-
-  //
-  // The base of the runtime image has been preserved in x1. Check whether
-  // the expected magic number can be found in the header.
-  //
-  ldr   w8, .LArm64LinuxMagic
-  ldr   w9, [x1, #0x38]
-  cmp   w8, w9
-  bne   .Lout
-
-  //
-  //
-  // OK, so far so good. We have confirmed that we likely have a DTB and are
-  // booting via the arm64 Linux boot protocol. Update the base-of-image PCD
-  // to the actual relocated value, and add the shift of PcdFdBaseAddress to
-  // PcdFvBaseAddress as well
-  //
-  adr   x8, PcdGet64 (PcdFdBaseAddress)
-  adr   x9, PcdGet64 (PcdFvBaseAddress)
-  ldr   x6, [x8]
-  ldr   x7, [x9]
-  sub   x7, x7, x6
-  add   x7, x7, x1
-  str   x1, [x8]
-  str   x7, [x9]
-
-  //
-  // Discover the memory size and offset from the DTB, and record in the
-  // respective PCDs. This will also return false if a corrupt DTB is
-  // encountered. Since we are calling a C function, use the window at the
-  // beginning of the FD image as a temp stack.
-  //
-  adr   x1, PcdGet64 (PcdSystemMemoryBase)
-  adr   x2, PcdGet64 (PcdSystemMemorySize)
-  mov   sp, x7
-  bl    FindMemnode
-  cbz   x0, .Lout
-
-  //
-  // Copy the DTB to the slack space right after the 64 byte arm64/Linux style
-  // image header at the base of this image (defined in the FDF), and record the
-  // pointer in PcdDeviceTreeInitialBaseAddress.
-  //
-  adr   x8, PcdGet64 (PcdDeviceTreeInitialBaseAddress)
-  add   x27, x27, #0x40
-  str   x27, [x8]
-
-  mov   x0, x27
-  mov   x1, x28
-  bl    CopyFdt
-
-.Lout:
-  ret    x29
-
-.LArm64LinuxMagic:
-  .byte   0x41, 0x52, 0x4d, 0x64
-
-//UINTN
-//ArmPlatformGetPrimaryCoreMpId (
-//  VOID
-//  );
-ASM_FUNC(ArmPlatformGetPrimaryCoreMpId)
-  MOV32  (w0, FixedPcdGet32 (PcdArmPrimaryCore))
-  ret
-
-//UINTN
-//ArmPlatformIsPrimaryCore (
-//  IN UINTN MpId
-//  );
-ASM_FUNC(ArmPlatformIsPrimaryCore)
-  mov   x0, #1
-  ret
-
-//UINTN
-//ArmPlatformGetCorePosition (
-//  IN UINTN MpId
-//  );
-// With this function: CorePos = (ClusterId * 4) + CoreId
-ASM_FUNC(ArmPlatformGetCorePosition)
-  and   x1, x0, #ARM_CORE_MASK
-  and   x0, x0, #ARM_CLUSTER_MASK
-  add   x0, x1, x0, LSR #6
-  ret
-
-//EFI_PHYSICAL_ADDRESS
-//GetPhysAddrTop (
-//  VOID
-//  );
-ASM_FUNC(ArmGetPhysAddrTop)
-  mrs   x0, id_aa64mmfr0_el1
-  adr   x1, .LPARanges
-  and   x0, x0, #7
-  ldrb  w1, [x1, x0]
-  mov   x0, #1
-  lsl   x0, x0, x1
-  ret
-
-//
-// Bits 0..2 of the AA64MFR0_EL1 system register encode the size of the
-// physical address space support on this CPU:
-// 0 == 32 bits, 1 == 36 bits, etc etc
-// 6 and 7 are reserved
-//
-.LPARanges:
-  .byte 32, 36, 40, 42, 44, 48, -1, -1
-
-ASM_FUNCTION_REMOVE_IF_UNREFERENCED
diff --git a/ArmVirtPkg/Library/ArmQemuRelocatablePlatformLib/ARM/RelocatableVirtHelper.S b/ArmVirtPkg/Library/ArmQemuRelocatablePlatformLib/ARM/RelocatableVirtHelper.S
deleted file mode 100644
index 27af98970c16..000000000000
--- a/ArmVirtPkg/Library/ArmQemuRelocatablePlatformLib/ARM/RelocatableVirtHelper.S
+++ /dev/null
@@ -1,123 +0,0 @@
-#
-#  Copyright (c) 2011-2013, ARM Limited. All rights reserved.
-#  Copyright (c) 2014-2016, Linaro Limited. All rights reserved.
-#
-#  This program and the accompanying materials
-#  are licensed and made available under the terms and conditions of the BSD License
-#  which accompanies this distribution.  The full text of the license may be found at
-#  http://opensource.org/licenses/bsd-license.php
-#
-#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
-#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
-#
-#
-
-#include <AsmMacroIoLib.h>
-#include <Library/ArmLib.h>
-
-ASM_FUNC(ArmPlatformPeiBootAction)
-  //
-  // If we are booting from RAM using the Linux kernel boot protocol, r0 will
-  // point to the DTB image in memory. Otherwise, use the default value defined
-  // by the platform.
-  //
-  teq   r0, #0
-  bne   0f
-  LDRL  (r0, PcdGet64 (PcdDeviceTreeInitialBaseAddress))
-
-0:mov   r11, r14            // preserve LR
-  mov   r10, r0             // preserve DTB pointer
-  mov   r9, r1              // preserve base of image pointer
-
-  //
-  // The base of the runtime image has been preserved in r1. Check whether
-  // the expected magic number can be found in the header.
-  //
-  ldr   r8, .LArm32LinuxMagic
-  ldr   r7, [r1, #0x24]
-  cmp   r7, r8
-  bne   .Lout
-
-  //
-  //
-  // OK, so far so good. We have confirmed that we likely have a DTB and are
-  // booting via the ARM Linux boot protocol. Update the base-of-image PCD
-  // to the actual relocated value, and add the shift of PcdFdBaseAddress to
-  // PcdFvBaseAddress as well
-  //
-  ADRL  (r8, PcdGet64 (PcdFdBaseAddress))
-  ADRL  (r7, PcdGet64 (PcdFvBaseAddress))
-  ldr   r6, [r8]
-  ldr   r5, [r7]
-  sub   r5, r5, r6
-  add   r5, r5, r1
-  str   r1, [r8]
-  str   r5, [r7]
-
-  //
-  // Discover the memory size and offset from the DTB, and record in the
-  // respective PCDs. This will also return false if a corrupt DTB is
-  // encountered. Since we are calling a C function, use the window at the
-  // beginning of the FD image as a temp stack.
-  //
-  ADRL  (r1, PcdGet64 (PcdSystemMemoryBase))
-  ADRL  (r2, PcdGet64 (PcdSystemMemorySize))
-  mov   sp, r5
-  bl    FindMemnode
-  teq   r0, #0
-  beq   .Lout
-
-  //
-  // Copy the DTB to the slack space right after the 64 byte arm64/Linux style
-  // image header at the base of this image (defined in the FDF), and record the
-  // pointer in PcdDeviceTreeInitialBaseAddress.
-  //
-  ADRL  (r8, PcdGet64 (PcdDeviceTreeInitialBaseAddress))
-  add   r9, r9, #0x40
-  str   r9, [r8]
-
-  mov   r0, r9
-  mov   r1, r10
-  bl    CopyFdt
-
-.Lout:
-  bx    r11
-
-.LArm32LinuxMagic:
-  .byte   0x18, 0x28, 0x6f, 0x01
-
-//UINTN
-//ArmPlatformGetPrimaryCoreMpId (
-//  VOID
-//  );
-ASM_FUNC(ArmPlatformGetPrimaryCoreMpId)
-  MOV32  (r0, FixedPcdGet32 (PcdArmPrimaryCore))
-  bx     lr
-
-//UINTN
-//ArmPlatformIsPrimaryCore (
-//  IN UINTN MpId
-//  );
-ASM_FUNC(ArmPlatformIsPrimaryCore)
-  mov   r0, #1
-  bx    lr
-
-//UINTN
-//ArmPlatformGetCorePosition (
-//  IN UINTN MpId
-//  );
-// With this function: CorePos = (ClusterId * 4) + CoreId
-ASM_FUNC(ArmPlatformGetCorePosition)
-  and   r1, r0, #ARM_CORE_MASK
-  and   r0, r0, #ARM_CLUSTER_MASK
-  add   r0, r1, r0, LSR #6
-  bx    lr
-
-//EFI_PHYSICAL_ADDRESS
-//GetPhysAddrTop (
-//  VOID
-//  );
-ASM_FUNC(ArmGetPhysAddrTop)
-  mov   r0, #0x00000000
-  mov   r1, #0x10000
-  bx    lr
diff --git a/ArmVirtPkg/Library/ArmQemuRelocatablePlatformLib/ArmQemuRelocatablePlatformLib.inf b/ArmVirtPkg/Library/ArmQemuRelocatablePlatformLib/ArmQemuRelocatablePlatformLib.inf
deleted file mode 100644
index acd523bbd2ce..000000000000
--- a/ArmVirtPkg/Library/ArmQemuRelocatablePlatformLib/ArmQemuRelocatablePlatformLib.inf
+++ /dev/null
@@ -1,64 +0,0 @@
-#/* @file
-#  Copyright (c) 2011-2015, ARM Limited. All rights reserved.
-#  Copyright (c) 2014, Linaro Limited. All rights reserved.
-#
-#  This program and the accompanying materials
-#  are licensed and made available under the terms and conditions of the BSD License
-#  which accompanies this distribution.  The full text of the license may be found at
-#  http://opensource.org/licenses/bsd-license.php
-#
-#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
-#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
-#
-#*/
-
-[Defines]
-  INF_VERSION                    = 0x00010005
-  BASE_NAME                      = ArmXenRelocatablePlatformLib
-  FILE_GUID                      = c8602718-4faa-4119-90ca-cae72509ac4c
-  MODULE_TYPE                    = BASE
-  VERSION_STRING                 = 1.0
-  LIBRARY_CLASS                  = ArmPlatformLib|SEC PEIM
-
-[Packages]
-  MdePkg/MdePkg.dec
-  MdeModulePkg/MdeModulePkg.dec
-  EmbeddedPkg/EmbeddedPkg.dec
-  ArmPkg/ArmPkg.dec
-  ArmPlatformPkg/ArmPlatformPkg.dec
-  ArmVirtPkg/ArmVirtPkg.dec
-
-[LibraryClasses]
-  IoLib
-  ArmLib
-  PrintLib
-  FdtLib
-
-[Sources.common]
-  RelocatableVirt.c
-  QemuVirtMem.c
-  FdtParser.c
-
-[Sources.AARCH64]
-  AARCH64/RelocatableVirtHelper.S
-
-[Sources.ARM]
-  ARM/RelocatableVirtHelper.S
-
-[FeaturePcd]
-  gEmbeddedTokenSpaceGuid.PcdCacheEnable
-  gArmPlatformTokenSpaceGuid.PcdSystemMemoryInitializeInSec
-
-[PatchPcd]
-  gArmVirtTokenSpaceGuid.PcdDeviceTreeInitialBaseAddress
-  gArmTokenSpaceGuid.PcdFdBaseAddress
-  gArmTokenSpaceGuid.PcdFvBaseAddress
-  gArmTokenSpaceGuid.PcdSystemMemoryBase
-  gArmTokenSpaceGuid.PcdSystemMemorySize
-
-[FixedPcd]
-  gArmPlatformTokenSpaceGuid.PcdCoreCount
-  gArmTokenSpaceGuid.PcdArmPrimaryCoreMask
-  gArmTokenSpaceGuid.PcdArmPrimaryCore
-  gArmTokenSpaceGuid.PcdFdSize
-  gEmbeddedTokenSpaceGuid.PcdPrePiCpuMemorySize
diff --git a/ArmVirtPkg/Library/ArmQemuRelocatablePlatformLib/FdtParser.c b/ArmVirtPkg/Library/ArmQemuRelocatablePlatformLib/FdtParser.c
deleted file mode 100644
index afdc81a8839d..000000000000
--- a/ArmVirtPkg/Library/ArmQemuRelocatablePlatformLib/FdtParser.c
+++ /dev/null
@@ -1,90 +0,0 @@
-/*
- * Copyright (c) 2015, Linaro Ltd. All rights reserved.
- *
- * This program and the accompanying materials
- * are licensed and made available under the terms and conditions of the BSD License
- * which accompanies this distribution.  The full text of the license may be found at
- * http://opensource.org/licenses/bsd-license.php
- *
- * THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
- * WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
- */
-
-#include <Uefi.h>
-#include <Include/libfdt.h>
-
-BOOLEAN
-FindMemnode (
-  IN  VOID    *DeviceTreeBlob,
-  OUT UINT64  *SystemMemoryBase,
-  OUT UINT64  *SystemMemorySize
-  )
-{
-  INT32         MemoryNode;
-  INT32         AddressCells;
-  INT32         SizeCells;
-  INT32         Length;
-  CONST INT32   *Prop;
-
-  if (fdt_check_header (DeviceTreeBlob) != 0) {
-    return FALSE;
-  }
-
-  //
-  // Look for a node called "memory" at the lowest level of the tree
-  //
-  MemoryNode = fdt_path_offset (DeviceTreeBlob, "/memory");
-  if (MemoryNode <= 0) {
-    return FALSE;
-  }
-
-  //
-  // Retrieve the #address-cells and #size-cells properties
-  // from the root node, or use the default if not provided.
-  //
-  AddressCells = 1;
-  SizeCells = 1;
-
-  Prop = fdt_getprop (DeviceTreeBlob, 0, "#address-cells", &Length);
-  if (Length == 4) {
-    AddressCells = fdt32_to_cpu (*Prop);
-  }
-
-  Prop = fdt_getprop (DeviceTreeBlob, 0, "#size-cells", &Length);
-  if (Length == 4) {
-    SizeCells = fdt32_to_cpu (*Prop);
-  }
-
-  //
-  // Now find the 'reg' property of the /memory node, and read the first
-  // range listed.
-  //
-  Prop = fdt_getprop (DeviceTreeBlob, MemoryNode, "reg", &Length);
-
-  if (Length < (AddressCells + SizeCells) * sizeof (INT32)) {
-    return FALSE;
-  }
-
-  *SystemMemoryBase = fdt32_to_cpu (Prop[0]);
-  if (AddressCells > 1) {
-    *SystemMemoryBase = (*SystemMemoryBase << 32) | fdt32_to_cpu (Prop[1]);
-  }
-  Prop += AddressCells;
-
-  *SystemMemorySize = fdt32_to_cpu (Prop[0]);
-  if (SizeCells > 1) {
-    *SystemMemorySize = (*SystemMemorySize << 32) | fdt32_to_cpu (Prop[1]);
-  }
-
-  return TRUE;
-}
-
-VOID
-CopyFdt (
-  IN    VOID    *FdtDest,
-  IN    VOID    *FdtSource
-  )
-{
-  fdt_pack(FdtSource);
-  CopyMem (FdtDest, FdtSource, fdt_totalsize (FdtSource));
-}
diff --git a/ArmVirtPkg/Library/ArmQemuRelocatablePlatformLib/QemuVirtMem.c b/ArmVirtPkg/Library/ArmQemuRelocatablePlatformLib/QemuVirtMem.c
deleted file mode 100644
index 2ce5c48d52cf..000000000000
--- a/ArmVirtPkg/Library/ArmQemuRelocatablePlatformLib/QemuVirtMem.c
+++ /dev/null
@@ -1,106 +0,0 @@
-/** @file
-*
-*  Copyright (c) 2014, Linaro Limited. All rights reserved.
-*
-*  This program and the accompanying materials
-*  are licensed and made available under the terms and conditions of the BSD License
-*  which accompanies this distribution.  The full text of the license may be found at
-*  http://opensource.org/licenses/bsd-license.php
-*
-*  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
-*  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
-*
-**/
-
-#include <Library/ArmPlatformLib.h>
-#include <Library/DebugLib.h>
-#include <Library/BaseMemoryLib.h>
-#include <Library/PcdLib.h>
-#include <Library/IoLib.h>
-#include <Library/MemoryAllocationLib.h>
-
-// Number of Virtual Memory Map Descriptors
-#define MAX_VIRTUAL_MEMORY_MAP_DESCRIPTORS          5
-
-// DDR attributes
-#define DDR_ATTRIBUTES_CACHED    ARM_MEMORY_REGION_ATTRIBUTE_WRITE_BACK
-#define DDR_ATTRIBUTES_UNCACHED  ARM_MEMORY_REGION_ATTRIBUTE_UNCACHED_UNBUFFERED
-
-EFI_PHYSICAL_ADDRESS
-ArmGetPhysAddrTop (
-  VOID
-  );
-
-/**
-  Return the Virtual Memory Map of your platform
-
-  This Virtual Memory Map is used by MemoryInitPei Module to initialize the MMU
-  on your platform.
-
-  @param[out]   VirtualMemoryMap    Array of ARM_MEMORY_REGION_DESCRIPTOR
-                                    describing a Physical-to-Virtual Memory
-                                    mapping. This array must be ended by a
-                                    zero-filled entry
-
-**/
-VOID
-ArmPlatformGetVirtualMemoryMap (
-  IN ARM_MEMORY_REGION_DESCRIPTOR** VirtualMemoryMap
-  )
-{
-  ARM_MEMORY_REGION_DESCRIPTOR  *VirtualMemoryTable;
-
-  ASSERT (VirtualMemoryMap != NULL);
-
-  VirtualMemoryTable = AllocatePages (
-                         EFI_SIZE_TO_PAGES (
-                           sizeof (ARM_MEMORY_REGION_DESCRIPTOR)
-                           * MAX_VIRTUAL_MEMORY_MAP_DESCRIPTORS
-                           )
-                         );
-
-  if (VirtualMemoryTable == NULL) {
-    DEBUG ((EFI_D_ERROR, "%a: Error: Failed AllocatePages()\n", __FUNCTION__));
-    return;
-  }
-
-  // System DRAM
-  VirtualMemoryTable[0].PhysicalBase = PcdGet64 (PcdSystemMemoryBase);
-  VirtualMemoryTable[0].VirtualBase  = VirtualMemoryTable[0].PhysicalBase;
-  VirtualMemoryTable[0].Length       = PcdGet64 (PcdSystemMemorySize);
-  VirtualMemoryTable[0].Attributes   = DDR_ATTRIBUTES_CACHED;
-
-  DEBUG ((EFI_D_INFO, "%a: Dumping System DRAM Memory Map:\n"
-      "\tPhysicalBase: 0x%lX\n"
-      "\tVirtualBase: 0x%lX\n"
-      "\tLength: 0x%lX\n",
-      __FUNCTION__,
-      VirtualMemoryTable[0].PhysicalBase,
-      VirtualMemoryTable[0].VirtualBase,
-      VirtualMemoryTable[0].Length));
-
-  // Peripheral space before DRAM
-  VirtualMemoryTable[1].PhysicalBase = 0x0;
-  VirtualMemoryTable[1].VirtualBase  = 0x0;
-  VirtualMemoryTable[1].Length       = VirtualMemoryTable[0].PhysicalBase;
-  VirtualMemoryTable[1].Attributes   = ARM_MEMORY_REGION_ATTRIBUTE_DEVICE;
-
-  // Peripheral space after DRAM
-  VirtualMemoryTable[2].PhysicalBase = VirtualMemoryTable[0].Length + VirtualMemoryTable[1].Length;
-  VirtualMemoryTable[2].VirtualBase  = VirtualMemoryTable[2].PhysicalBase;
-  VirtualMemoryTable[2].Length       = MIN (1ULL << FixedPcdGet8 (PcdPrePiCpuMemorySize),
-                                         ArmGetPhysAddrTop ()) -
-                                       VirtualMemoryTable[2].PhysicalBase;
-  VirtualMemoryTable[2].Attributes   = ARM_MEMORY_REGION_ATTRIBUTE_DEVICE;
-
-  // Remap the FD region as normal executable memory
-  VirtualMemoryTable[3].PhysicalBase = PcdGet64 (PcdFdBaseAddress);
-  VirtualMemoryTable[3].VirtualBase  = VirtualMemoryTable[3].PhysicalBase;
-  VirtualMemoryTable[3].Length       = FixedPcdGet32 (PcdFdSize);
-  VirtualMemoryTable[3].Attributes   = DDR_ATTRIBUTES_CACHED;
-
-  // End of Table
-  ZeroMem (&VirtualMemoryTable[4], sizeof (ARM_MEMORY_REGION_DESCRIPTOR));
-
-  *VirtualMemoryMap = VirtualMemoryTable;
-}
diff --git a/ArmVirtPkg/Library/ArmQemuRelocatablePlatformLib/RelocatableVirt.c b/ArmVirtPkg/Library/ArmQemuRelocatablePlatformLib/RelocatableVirt.c
deleted file mode 100644
index 6df207733ab2..000000000000
--- a/ArmVirtPkg/Library/ArmQemuRelocatablePlatformLib/RelocatableVirt.c
+++ /dev/null
@@ -1,70 +0,0 @@
-/** @file
-*
-*  Copyright (c) 2011-2013, ARM Limited. All rights reserved.
-*  Copyright (c) 2014, Linaro Limited. All rights reserved.
-*  Copyright (c) 2014, Red Hat, Inc.
-*
-*
-*  This program and the accompanying materials
-*  are licensed and made available under the terms and conditions of the BSD License
-*  which accompanies this distribution.  The full text of the license may be found at
-*  http://opensource.org/licenses/bsd-license.php
-*
-*  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
-*  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
-*
-**/
-
-#include <Library/IoLib.h>
-#include <Library/ArmPlatformLib.h>
-#include <Library/DebugLib.h>
-#include <Pi/PiBootMode.h>
-
-/**
-  Return the current Boot Mode
-
-  This function returns the boot reason on the platform
-
-  @return   Return the current Boot Mode of the platform
-
-**/
-EFI_BOOT_MODE
-ArmPlatformGetBootMode (
-  VOID
-  )
-{
-  return BOOT_WITH_FULL_CONFIGURATION;
-}
-
-/**
-  This function is called by PrePeiCore, in the SEC phase.
-**/
-RETURN_STATUS
-ArmPlatformInitialize (
-  IN  UINTN                     MpId
-  )
-{
-  //
-  // We are relying on ArmPlatformInitializeSystemMemory () being called from
-  // InitializeMemory (), which only occurs if the following feature is disabled
-  //
-  ASSERT (!FeaturePcdGet (PcdSystemMemoryInitializeInSec));
-  return RETURN_SUCCESS;
-}
-
-VOID
-ArmPlatformInitializeSystemMemory (
-  VOID
-  )
-{
-}
-
-VOID
-ArmPlatformGetPlatformPpiList (
-  OUT UINTN                   *PpiListSize,
-  OUT EFI_PEI_PPI_DESCRIPTOR  **PpiList
-  )
-{
-  *PpiListSize = 0;
-  *PpiList = NULL;
-}
diff --git a/ArmVirtPkg/Library/ArmVirtPlatformLib/AARCH64/VirtHelper.S b/ArmVirtPkg/Library/ArmVirtPlatformLib/AARCH64/VirtHelper.S
deleted file mode 100644
index 1d8fe25928d8..000000000000
--- a/ArmVirtPkg/Library/ArmVirtPlatformLib/AARCH64/VirtHelper.S
+++ /dev/null
@@ -1,70 +0,0 @@
-#
-#  Copyright (c) 2011-2013, ARM Limited. All rights reserved.
-#  Copyright (c) 2016, Linaro Limited. All rights reserved.
-#
-#  This program and the accompanying materials
-#  are licensed and made available under the terms and conditions of the BSD License
-#  which accompanies this distribution.  The full text of the license may be found at
-#  http://opensource.org/licenses/bsd-license.php
-#
-#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
-#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
-#
-#
-
-#include <AsmMacroIoLibV8.h>
-#include <Library/ArmLib.h>
-
-ASM_FUNC(ArmPlatformPeiBootAction)
-  ret
-
-//UINTN
-//ArmPlatformGetPrimaryCoreMpId (
-//  VOID
-//  );
-ASM_FUNC(ArmPlatformGetPrimaryCoreMpId)
-  MOV32  (w0, FixedPcdGet32 (PcdArmPrimaryCore))
-  ret
-
-//UINTN
-//ArmPlatformIsPrimaryCore (
-//  IN UINTN MpId
-//  );
-ASM_FUNC(ArmPlatformIsPrimaryCore)
-  mov   x0, #1
-  ret
-
-//UINTN
-//ArmPlatformGetCorePosition (
-//  IN UINTN MpId
-//  );
-// With this function: CorePos = (ClusterId * 4) + CoreId
-ASM_FUNC(ArmPlatformGetCorePosition)
-  and   x1, x0, #ARM_CORE_MASK
-  and   x0, x0, #ARM_CLUSTER_MASK
-  add   x0, x1, x0, LSR #6
-  ret
-
-//EFI_PHYSICAL_ADDRESS
-//GetPhysAddrTop (
-//  VOID
-//  );
-ASM_FUNC(ArmGetPhysAddrTop)
-  mrs   x0, id_aa64mmfr0_el1
-  adr   x1, .LPARanges
-  and   x0, x0, #7
-  ldrb  w1, [x1, x0]
-  mov   x0, #1
-  lsl   x0, x0, x1
-  ret
-
-//
-// Bits 0..2 of the AA64MFR0_EL1 system register encode the size of the
-// physical address space support on this CPU:
-// 0 == 32 bits, 1 == 36 bits, etc etc
-// 6 and 7 are reserved
-//
-.LPARanges:
-  .byte 32, 36, 40, 42, 44, 48, -1, -1
-
-ASM_FUNCTION_REMOVE_IF_UNREFERENCED
diff --git a/ArmVirtPkg/Library/ArmVirtPlatformLib/ARM/VirtHelper.S b/ArmVirtPkg/Library/ArmVirtPlatformLib/ARM/VirtHelper.S
deleted file mode 100644
index 4a4db3721072..000000000000
--- a/ArmVirtPkg/Library/ArmVirtPlatformLib/ARM/VirtHelper.S
+++ /dev/null
@@ -1,57 +0,0 @@
-#
-#  Copyright (c) 2011-2013, ARM Limited. All rights reserved.
-#  Copyright (c) 2014-2016, Linaro Limited. All rights reserved.
-#
-#  This program and the accompanying materials
-#  are licensed and made available under the terms and conditions of the BSD License
-#  which accompanies this distribution.  The full text of the license may be found at
-#  http://opensource.org/licenses/bsd-license.php
-#
-#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
-#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
-#
-#
-
-#include <AsmMacroIoLib.h>
-#include <Library/ArmLib.h>
-
-ASM_FUNC(ArmPlatformPeiBootAction)
-  bx    lr
-
-//UINTN
-//ArmPlatformGetPrimaryCoreMpId (
-//  VOID
-//  );
-ASM_FUNC(ArmPlatformGetPrimaryCoreMpId)
-  MOV32  (r0, FixedPcdGet32 (PcdArmPrimaryCore))
-  bx     lr
-
-//UINTN
-//ArmPlatformIsPrimaryCore (
-//  IN UINTN MpId
-//  );
-ASM_FUNC(ArmPlatformIsPrimaryCore)
-  mov   r0, #1
-  bx    lr
-
-//UINTN
-//ArmPlatformGetCorePosition (
-//  IN UINTN MpId
-//  );
-// With this function: CorePos = (ClusterId * 4) + CoreId
-ASM_FUNC(ArmPlatformGetCorePosition)
-  and   r1, r0, #ARM_CORE_MASK
-  and   r0, r0, #ARM_CLUSTER_MASK
-  add   r0, r1, r0, LSR #6
-  bx    lr
-
-//EFI_PHYSICAL_ADDRESS
-//GetPhysAddrTop (
-//  VOID
-//  );
-ASM_FUNC(ArmGetPhysAddrTop)
-  mov   r0, #0x00000000
-  mov   r1, #0x10000
-  bx    lr
-
-ASM_FUNCTION_REMOVE_IF_UNREFERENCED
diff --git a/ArmVirtPkg/Library/ArmVirtPlatformLib/ARM/VirtHelper.asm b/ArmVirtPkg/Library/ArmVirtPlatformLib/ARM/VirtHelper.asm
deleted file mode 100644
index b476516f2115..000000000000
--- a/ArmVirtPkg/Library/ArmVirtPlatformLib/ARM/VirtHelper.asm
+++ /dev/null
@@ -1,71 +0,0 @@
-//
-//  Copyright (c) 2011-2014, ARM Limited. All rights reserved.
-//  Copyright (c) 2014, Linaro Limited. All rights reserved.
-//
-//  This program and the accompanying materials
-//  are licensed and made available under the terms and conditions of the BSD License
-//  which accompanies this distribution.  The full text of the license may be found at
-//  http://opensource.org/licenses/bsd-license.php
-//
-//  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
-//  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
-//
-
-#include <Library/ArmLib.h>
-#include <AutoGen.h>
-
-  INCLUDE AsmMacroIoLib.inc
-
-  EXPORT  ArmPlatformPeiBootAction
-  EXPORT  ArmPlatformIsPrimaryCore
-  EXPORT  ArmPlatformGetPrimaryCoreMpId
-  EXPORT  ArmPlatformGetCorePosition
-  EXPORT  ArmGetPhysAddrTop
-
-  AREA VirtHelper, CODE, READONLY
-
-ArmPlatformPeiBootAction FUNCTION
-  bx    lr
-  ENDFUNC
-
-//UINTN
-//ArmPlatformGetPrimaryCoreMpId (
-//  VOID
-//  );
-ArmPlatformGetPrimaryCoreMpId FUNCTION
-  MOV32  r0, FixedPcdGet32 (PcdArmPrimaryCore)
-  bx     lr
-  ENDFUNC
-
-//UINTN
-//ArmPlatformIsPrimaryCore (
-//  IN UINTN MpId
-//  );
-ArmPlatformIsPrimaryCore FUNCTION
-  mov   r0, #1
-  bx    lr
-  ENDFUNC
-
-//UINTN
-//ArmPlatformGetCorePosition (
-//  IN UINTN MpId
-//  );
-// With this function: CorePos = (ClusterId * 4) + CoreId
-ArmPlatformGetCorePosition FUNCTION
-  and   r1, r0, #ARM_CORE_MASK
-  and   r0, r0, #ARM_CLUSTER_MASK
-  add   r0, r1, r0, LSR #6
-  bx    lr
-  ENDFUNC
-
-//EFI_PHYSICAL_ADDRESS
-//GetPhysAddrTop (
-//  VOID
-//  );
-ArmGetPhysAddrTop FUNCTION
-  mov   r0, #0x00000000
-  mov   r1, #0x10000
-  bx    lr
-  ENDFUNC
-
-  END
diff --git a/ArmVirtPkg/Library/ArmVirtPlatformLib/ArmVirtPlatformLib.inf b/ArmVirtPkg/Library/ArmVirtPlatformLib/ArmVirtPlatformLib.inf
deleted file mode 100644
index 3cb3fb1f3aea..000000000000
--- a/ArmVirtPkg/Library/ArmVirtPlatformLib/ArmVirtPlatformLib.inf
+++ /dev/null
@@ -1,64 +0,0 @@
-#/* @file
-#  Copyright (c) 2011-2014, ARM Limited. All rights reserved.
-#  Copyright (c) 2014, Linaro Limited. All rights reserved.
-#
-#  This program and the accompanying materials
-#  are licensed and made available under the terms and conditions of the BSD License
-#  which accompanies this distribution.  The full text of the license may be found at
-#  http://opensource.org/licenses/bsd-license.php
-#
-#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
-#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
-#
-#*/
-
-[Defines]
-  INF_VERSION                    = 0x00010005
-  BASE_NAME                      = ArmVirtPlatformLib
-  FILE_GUID                      = 00214cc1-06d1-45fe-9700-dca5726ad7bf
-  MODULE_TYPE                    = BASE
-  VERSION_STRING                 = 1.0
-  LIBRARY_CLASS                  = ArmPlatformLib|SEC PEIM
-
-[Packages]
-  MdePkg/MdePkg.dec
-  MdeModulePkg/MdeModulePkg.dec
-  EmbeddedPkg/EmbeddedPkg.dec
-  ArmPkg/ArmPkg.dec
-  ArmPlatformPkg/ArmPlatformPkg.dec
-  ArmVirtPkg/ArmVirtPkg.dec
-
-[LibraryClasses]
-  IoLib
-  MemoryAllocationLib
-  ArmLib
-  PrintLib
-  FdtLib
-
-[Sources.common]
-  Virt.c
-  VirtMem.c
-
-[Sources.AARCH64]
-  AARCH64/VirtHelper.S
-
-[Sources.ARM]
-  ARM/VirtHelper.S          | GCC
-  ARM/VirtHelper.asm        | RVCT
-
-[FeaturePcd]
-  gEmbeddedTokenSpaceGuid.PcdCacheEnable
-  gArmPlatformTokenSpaceGuid.PcdSystemMemoryInitializeInSec
-
-[Pcd]
-  gArmTokenSpaceGuid.PcdSystemMemorySize
-
-[FixedPcd]
-  gArmVirtTokenSpaceGuid.PcdDeviceTreeInitialBaseAddress
-  gArmPlatformTokenSpaceGuid.PcdCoreCount
-  gArmTokenSpaceGuid.PcdSystemMemoryBase
-  gArmTokenSpaceGuid.PcdArmPrimaryCoreMask
-  gArmTokenSpaceGuid.PcdArmPrimaryCore
-  gArmTokenSpaceGuid.PcdFdBaseAddress
-  gArmTokenSpaceGuid.PcdFdSize
-  gEmbeddedTokenSpaceGuid.PcdPrePiCpuMemorySize
diff --git a/ArmVirtPkg/Library/ArmVirtPlatformLib/Virt.c b/ArmVirtPkg/Library/ArmVirtPlatformLib/Virt.c
deleted file mode 100644
index 140bdde8b2ac..000000000000
--- a/ArmVirtPkg/Library/ArmVirtPlatformLib/Virt.c
+++ /dev/null
@@ -1,160 +0,0 @@
-/** @file
-*
-*  Copyright (c) 2011-2013, ARM Limited. All rights reserved.
-*  Copyright (c) 2014, Linaro Limited. All rights reserved.
-*  Copyright (c) 2014, Red Hat, Inc.
-*
-*
-*  This program and the accompanying materials
-*  are licensed and made available under the terms and conditions of the BSD License
-*  which accompanies this distribution.  The full text of the license may be found at
-*  http://opensource.org/licenses/bsd-license.php
-*
-*  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
-*  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
-*
-**/
-
-#include <Library/IoLib.h>
-#include <Library/ArmPlatformLib.h>
-#include <Library/DebugLib.h>
-#include <Library/PcdLib.h>
-#include <libfdt.h>
-#include <Pi/PiBootMode.h>
-#include <Uefi/UefiBaseType.h>
-#include <Uefi/UefiMultiPhase.h>
-
-/**
-  Return the current Boot Mode
-
-  This function returns the boot reason on the platform
-
-  @return   Return the current Boot Mode of the platform
-
-**/
-EFI_BOOT_MODE
-ArmPlatformGetBootMode (
-  VOID
-  )
-{
-  return BOOT_WITH_FULL_CONFIGURATION;
-}
-
-/**
-  This function is called by PrePeiCore, in the SEC phase.
-**/
-RETURN_STATUS
-ArmPlatformInitialize (
-  IN  UINTN                     MpId
-  )
-{
-  //
-  // We are relying on ArmPlatformInitializeSystemMemory () being called from
-  // InitializeMemory (), which only occurs if the following feature is disabled
-  //
-  ASSERT (!FeaturePcdGet (PcdSystemMemoryInitializeInSec));
-  return RETURN_SUCCESS;
-}
-
-/**
-  Initialize the system (or sometimes called permanent) memory
-
-  This memory is generally represented by the DRAM.
-
-  This function is called from InitializeMemory() in MemoryInitPeim, in the PEI
-  phase.
-**/
-VOID
-ArmPlatformInitializeSystemMemory (
-  VOID
-  )
-{
-  VOID          *DeviceTreeBase;
-  INT32         Node, Prev;
-  UINT64        NewBase, CurBase;
-  UINT64        NewSize, CurSize;
-  CONST CHAR8   *Type;
-  INT32         Len;
-  CONST UINT64  *RegProp;
-  RETURN_STATUS PcdStatus;
-
-  NewBase = 0;
-  NewSize = 0;
-
-  DeviceTreeBase = (VOID *)(UINTN)PcdGet64 (PcdDeviceTreeInitialBaseAddress);
-  ASSERT (DeviceTreeBase != NULL);
-
-  //
-  // Make sure we have a valid device tree blob
-  //
-  ASSERT (fdt_check_header (DeviceTreeBase) == 0);
-
-  //
-  // Look for the lowest memory node
-  //
-  for (Prev = 0;; Prev = Node) {
-    Node = fdt_next_node (DeviceTreeBase, Prev, NULL);
-    if (Node < 0) {
-      break;
-    }
-
-    //
-    // Check for memory node
-    //
-    Type = fdt_getprop (DeviceTreeBase, Node, "device_type", &Len);
-    if (Type && AsciiStrnCmp (Type, "memory", Len) == 0) {
-      //
-      // Get the 'reg' property of this node. For now, we will assume
-      // two 8 byte quantities for base and size, respectively.
-      //
-      RegProp = fdt_getprop (DeviceTreeBase, Node, "reg", &Len);
-      if (RegProp != 0 && Len == (2 * sizeof (UINT64))) {
-
-        CurBase = fdt64_to_cpu (ReadUnaligned64 (RegProp));
-        CurSize = fdt64_to_cpu (ReadUnaligned64 (RegProp + 1));
-
-        DEBUG ((EFI_D_INFO, "%a: System RAM @ 0x%lx - 0x%lx\n",
-               __FUNCTION__, CurBase, CurBase + CurSize - 1));
-
-        if (NewBase > CurBase || NewBase == 0) {
-          NewBase = CurBase;
-          NewSize = CurSize;
-        }
-      } else {
-        DEBUG ((EFI_D_ERROR, "%a: Failed to parse FDT memory node\n",
-               __FUNCTION__));
-      }
-    }
-  }
-
-  //
-  // Make sure the start of DRAM matches our expectation
-  //
-  ASSERT (FixedPcdGet64 (PcdSystemMemoryBase) == NewBase);
-  PcdStatus = PcdSet64S (PcdSystemMemorySize, NewSize);
-  ASSERT_RETURN_ERROR (PcdStatus);
-
-  //
-  // We need to make sure that the machine we are running on has at least
-  // 128 MB of memory configured, and is currently executing this binary from
-  // NOR flash. This prevents a device tree image in DRAM from getting
-  // clobbered when our caller installs permanent PEI RAM, before we have a
-  // chance of marking its location as reserved or copy it to a freshly
-  // allocated block in the permanent PEI RAM in the platform PEIM.
-  //
-  ASSERT (NewSize >= SIZE_128MB);
-  ASSERT (
-    (((UINT64)PcdGet64 (PcdFdBaseAddress) +
-      (UINT64)PcdGet32 (PcdFdSize)) <= NewBase) ||
-    ((UINT64)PcdGet64 (PcdFdBaseAddress) >= (NewBase + NewSize)));
-}
-
-VOID
-ArmPlatformGetPlatformPpiList (
-  OUT UINTN                   *PpiListSize,
-  OUT EFI_PEI_PPI_DESCRIPTOR  **PpiList
-  )
-{
-  *PpiListSize = 0;
-  *PpiList = NULL;
-}
diff --git a/ArmVirtPkg/Library/ArmVirtPlatformLib/VirtMem.c b/ArmVirtPkg/Library/ArmVirtPlatformLib/VirtMem.c
deleted file mode 100644
index 4368d05f76ef..000000000000
--- a/ArmVirtPkg/Library/ArmVirtPlatformLib/VirtMem.c
+++ /dev/null
@@ -1,102 +0,0 @@
-/** @file
-*
-*  Copyright (c) 2014, Linaro Limited. All rights reserved.
-*
-*  This program and the accompanying materials
-*  are licensed and made available under the terms and conditions of the BSD License
-*  which accompanies this distribution.  The full text of the license may be found at
-*  http://opensource.org/licenses/bsd-license.php
-*
-*  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
-*  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
-*
-**/
-
-#include <Library/ArmPlatformLib.h>
-#include <Library/DebugLib.h>
-#include <Library/BaseMemoryLib.h>
-#include <Library/PcdLib.h>
-#include <Library/IoLib.h>
-#include <Library/MemoryAllocationLib.h>
-
-// Number of Virtual Memory Map Descriptors
-#define MAX_VIRTUAL_MEMORY_MAP_DESCRIPTORS          5
-
-EFI_PHYSICAL_ADDRESS
-ArmGetPhysAddrTop (
-  VOID
-  );
-
-/**
-  Return the Virtual Memory Map of your platform
-
-  This Virtual Memory Map is used by MemoryInitPei Module to initialize the MMU
-  on your platform.
-
-  @param[out]   VirtualMemoryMap    Array of ARM_MEMORY_REGION_DESCRIPTOR
-                                    describing a Physical-to-Virtual Memory
-                                    mapping. This array must be ended by a
-                                    zero-filled entry
-
-**/
-VOID
-ArmPlatformGetVirtualMemoryMap (
-  IN ARM_MEMORY_REGION_DESCRIPTOR** VirtualMemoryMap
-  )
-{
-  ARM_MEMORY_REGION_DESCRIPTOR  *VirtualMemoryTable;
-
-  ASSERT (VirtualMemoryMap != NULL);
-
-  VirtualMemoryTable = AllocatePages (
-                         EFI_SIZE_TO_PAGES (
-                           sizeof (ARM_MEMORY_REGION_DESCRIPTOR)
-                           * MAX_VIRTUAL_MEMORY_MAP_DESCRIPTORS
-                           )
-                         );
-
-  if (VirtualMemoryTable == NULL) {
-    DEBUG ((EFI_D_ERROR, "%a: Error: Failed AllocatePages()\n", __FUNCTION__));
-    return;
-  }
-
-  // System DRAM
-  VirtualMemoryTable[0].PhysicalBase = PcdGet64 (PcdSystemMemoryBase);
-  VirtualMemoryTable[0].VirtualBase  = VirtualMemoryTable[0].PhysicalBase;
-  VirtualMemoryTable[0].Length       = PcdGet64 (PcdSystemMemorySize);
-  VirtualMemoryTable[0].Attributes   = ARM_MEMORY_REGION_ATTRIBUTE_WRITE_BACK;
-
-  DEBUG ((EFI_D_INFO, "%a: Dumping System DRAM Memory Map:\n"
-      "\tPhysicalBase: 0x%lX\n"
-      "\tVirtualBase: 0x%lX\n"
-      "\tLength: 0x%lX\n",
-      __FUNCTION__,
-      VirtualMemoryTable[0].PhysicalBase,
-      VirtualMemoryTable[0].VirtualBase,
-      VirtualMemoryTable[0].Length));
-
-  // Peripheral space before DRAM
-  VirtualMemoryTable[1].PhysicalBase = 0x0;
-  VirtualMemoryTable[1].VirtualBase  = 0x0;
-  VirtualMemoryTable[1].Length       = VirtualMemoryTable[0].PhysicalBase;
-  VirtualMemoryTable[1].Attributes   = ARM_MEMORY_REGION_ATTRIBUTE_DEVICE;
-
-  // Peripheral space after DRAM
-  VirtualMemoryTable[2].PhysicalBase = VirtualMemoryTable[0].Length + VirtualMemoryTable[1].Length;
-  VirtualMemoryTable[2].VirtualBase  = VirtualMemoryTable[2].PhysicalBase;
-  VirtualMemoryTable[2].Length       = MIN (1ULL << FixedPcdGet8 (PcdPrePiCpuMemorySize),
-                                         ArmGetPhysAddrTop ()) -
-                                       VirtualMemoryTable[2].PhysicalBase;
-  VirtualMemoryTable[2].Attributes   = ARM_MEMORY_REGION_ATTRIBUTE_DEVICE;
-
-  // Remap the FD region as normal executable memory
-  VirtualMemoryTable[3].PhysicalBase = FixedPcdGet64 (PcdFdBaseAddress);
-  VirtualMemoryTable[3].VirtualBase  = VirtualMemoryTable[3].PhysicalBase;
-  VirtualMemoryTable[3].Length       = FixedPcdGet32 (PcdFdSize);
-  VirtualMemoryTable[3].Attributes   = ARM_MEMORY_REGION_ATTRIBUTE_WRITE_BACK;
-
-  // End of Table
-  ZeroMem (&VirtualMemoryTable[4], sizeof (ARM_MEMORY_REGION_DESCRIPTOR));
-
-  *VirtualMemoryMap = VirtualMemoryTable;
-}
diff --git a/ArmVirtPkg/Library/ArmXenRelocatablePlatformLib/AARCH64/RelocatableVirtHelper.S b/ArmVirtPkg/Library/ArmXenRelocatablePlatformLib/AARCH64/RelocatableVirtHelper.S
deleted file mode 100644
index ce886378eae6..000000000000
--- a/ArmVirtPkg/Library/ArmXenRelocatablePlatformLib/AARCH64/RelocatableVirtHelper.S
+++ /dev/null
@@ -1,140 +0,0 @@
-#
-#  Copyright (c) 2011-2013, ARM Limited. All rights reserved.
-#  Copyright (c) 2016, Linaro Limited. All rights reserved.
-#
-#  This program and the accompanying materials
-#  are licensed and made available under the terms and conditions of the BSD License
-#  which accompanies this distribution.  The full text of the license may be found at
-#  http://opensource.org/licenses/bsd-license.php
-#
-#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
-#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
-#
-#
-
-#include <AsmMacroIoLibV8.h>
-#include <Library/ArmLib.h>
-
-// VOID
-// ArmPlatformPeiBootAction (
-//   VOID   *DeviceTreeBaseAddress,   // passed by loader in x0
-//   VOID   *ImageBase                // passed by FDF trampoline in x1
-//   );
-ASM_FUNC(ArmPlatformPeiBootAction)
-  mov   x29, x30            // preserve LR
-  mov   x28, x0             // preserve DTB pointer
-  mov   x27, x1             // preserve base of image pointer
-
-  //
-  // If we are booting from RAM using the Linux kernel boot protocol, x0 will
-  // point to the DTB image in memory. Otherwise, we are just coming out of
-  // reset, and x0 will be 0.
-  //
-  cbz   x0, .Lout
-
-  //
-  // The base of the runtime image has been preserved in x1. Check whether
-  // the expected magic number can be found in the header.
-  //
-  ldr   w8, .LArm64LinuxMagic
-  ldr   w9, [x1, #0x38]
-  cmp   w8, w9
-  bne   .Lout
-
-  //
-  //
-  // OK, so far so good. We have confirmed that we likely have a DTB and are
-  // booting via the arm64 Linux boot protocol. Update the base-of-image PCD
-  // to the actual relocated value, and add the shift of PcdFdBaseAddress to
-  // PcdFvBaseAddress as well
-  //
-  adr   x8, PcdGet64 (PcdFdBaseAddress)
-  adr   x9, PcdGet64 (PcdFvBaseAddress)
-  ldr   x6, [x8]
-  ldr   x7, [x9]
-  sub   x7, x7, x6
-  add   x7, x7, x1
-  str   x1, [x8]
-  str   x7, [x9]
-
-  //
-  // Discover the memory size and offset from the DTB, and record in the
-  // respective PCDs. This will also return false if a corrupt DTB is
-  // encountered. Since we are calling a C function, use the window at the
-  // beginning of the FD image as a temp stack.
-  //
-  adr   x1, PcdGet64 (PcdSystemMemoryBase)
-  adr   x2, PcdGet64 (PcdSystemMemorySize)
-  mov   sp, x7
-  bl    FindMemnode
-  cbz   x0, .Lout
-
-  //
-  // Copy the DTB to the slack space right after the 64 byte arm64/Linux style
-  // image header at the base of this image (defined in the FDF), and record the
-  // pointer in PcdDeviceTreeInitialBaseAddress.
-  //
-  adr   x8, PcdGet64 (PcdDeviceTreeInitialBaseAddress)
-  add   x27, x27, #0x40
-  str   x27, [x8]
-
-  mov   x0, x27
-  mov   x1, x28
-  bl    CopyFdt
-
-.Lout:
-  ret    x29
-
-.LArm64LinuxMagic:
-  .byte   0x41, 0x52, 0x4d, 0x64
-
-//UINTN
-//ArmPlatformGetPrimaryCoreMpId (
-//  VOID
-//  );
-ASM_FUNC(ArmPlatformGetPrimaryCoreMpId)
-  MOV32  (w0, FixedPcdGet32 (PcdArmPrimaryCore))
-  ret
-
-//UINTN
-//ArmPlatformIsPrimaryCore (
-//  IN UINTN MpId
-//  );
-ASM_FUNC(ArmPlatformIsPrimaryCore)
-  mov   x0, #1
-  ret
-
-//UINTN
-//ArmPlatformGetCorePosition (
-//  IN UINTN MpId
-//  );
-// With this function: CorePos = (ClusterId * 4) + CoreId
-ASM_FUNC(ArmPlatformGetCorePosition)
-  and   x1, x0, #ARM_CORE_MASK
-  and   x0, x0, #ARM_CLUSTER_MASK
-  add   x0, x1, x0, LSR #6
-  ret
-
-//EFI_PHYSICAL_ADDRESS
-//GetPhysAddrTop (
-//  VOID
-//  );
-ASM_FUNC(ArmGetPhysAddrTop)
-  mrs   x0, id_aa64mmfr0_el1
-  adr   x1, .LPARanges
-  and   x0, x0, #7
-  ldrb  w1, [x1, x0]
-  mov   x0, #1
-  lsl   x0, x0, x1
-  ret
-
-//
-// Bits 0..2 of the AA64MFR0_EL1 system register encode the size of the
-// physical address space support on this CPU:
-// 0 == 32 bits, 1 == 36 bits, etc etc
-// 6 and 7 are reserved
-//
-.LPARanges:
-  .byte 32, 36, 40, 42, 44, 48, -1, -1
-
-ASM_FUNCTION_REMOVE_IF_UNREFERENCED
diff --git a/ArmVirtPkg/Library/ArmXenRelocatablePlatformLib/ARM/RelocatableVirtHelper.S b/ArmVirtPkg/Library/ArmXenRelocatablePlatformLib/ARM/RelocatableVirtHelper.S
deleted file mode 100644
index f264fa1cf731..000000000000
--- a/ArmVirtPkg/Library/ArmXenRelocatablePlatformLib/ARM/RelocatableVirtHelper.S
+++ /dev/null
@@ -1,123 +0,0 @@
-#
-#  Copyright (c) 2011-2013, ARM Limited. All rights reserved.
-#  Copyright (c) 2014-2016, Linaro Limited. All rights reserved.
-#
-#  This program and the accompanying materials
-#  are licensed and made available under the terms and conditions of the BSD License
-#  which accompanies this distribution.  The full text of the license may be found at
-#  http://opensource.org/licenses/bsd-license.php
-#
-#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
-#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
-#
-#
-
-#include <AsmMacroIoLib.h>
-#include <Library/ArmLib.h>
-
-ASM_FUNC(ArmPlatformPeiBootAction)
-  mov   r11, r14            // preserve LR
-  mov   r10, r0             // preserve DTB pointer
-  mov   r9, r1              // preserve base of image pointer
-
-  //
-  // If we are booting from RAM using the Linux kernel boot protocol, r0 will
-  // point to the DTB image in memory. Otherwise, we are just coming out of
-  // reset, and r0 will be 0.
-  //
-  teq   r0, #0
-  beq   .Lout
-
-  //
-  // The base of the runtime image has been preserved in r1. Check whether
-  // the expected magic number can be found in the header.
-  //
-  ldr   r8, .LArm32LinuxMagic
-  ldr   r7, [r1, #0x24]
-  cmp   r7, r8
-  bne   .Lout
-
-  //
-  //
-  // OK, so far so good. We have confirmed that we likely have a DTB and are
-  // booting via the ARM Linux boot protocol. Update the base-of-image PCD
-  // to the actual relocated value, and add the shift of PcdFdBaseAddress to
-  // PcdFvBaseAddress as well
-  //
-  ADRL  (r8, PcdGet64 (PcdFdBaseAddress))
-  ADRL  (r7, PcdGet64 (PcdFvBaseAddress))
-  ldr   r6, [r8]
-  ldr   r5, [r7]
-  sub   r5, r5, r6
-  add   r5, r5, r1
-  str   r1, [r8]
-  str   r5, [r7]
-
-  //
-  // Discover the memory size and offset from the DTB, and record in the
-  // respective PCDs. This will also return false if a corrupt DTB is
-  // encountered. Since we are calling a C function, use the window at the
-  // beginning of the FD image as a temp stack.
-  //
-  ADRL  (r1, PcdGet64 (PcdSystemMemoryBase))
-  ADRL  (r2, PcdGet64 (PcdSystemMemorySize))
-  mov   sp, r5
-  bl    FindMemnode
-  teq   r0, #0
-  beq   .Lout
-
-  //
-  // Copy the DTB to the slack space right after the 64 byte arm64/Linux style
-  // image header at the base of this image (defined in the FDF), and record the
-  // pointer in PcdDeviceTreeInitialBaseAddress.
-  //
-  ADRL  (r8, PcdGet64 (PcdDeviceTreeInitialBaseAddress))
-  add   r9, r9, #0x40
-  str   r9, [r8]
-
-  mov   r0, r9
-  mov   r1, r10
-  bl    CopyFdt
-
-.Lout:
-  bx    r11
-
-.LArm32LinuxMagic:
-  .byte   0x18, 0x28, 0x6f, 0x01
-
-//UINTN
-//ArmPlatformGetPrimaryCoreMpId (
-//  VOID
-//  );
-ASM_FUNC(ArmPlatformGetPrimaryCoreMpId)
-  MOV32  (r0, FixedPcdGet32 (PcdArmPrimaryCore))
-  bx     lr
-
-//UINTN
-//ArmPlatformIsPrimaryCore (
-//  IN UINTN MpId
-//  );
-ASM_FUNC(ArmPlatformIsPrimaryCore)
-  mov   r0, #1
-  bx    lr
-
-//UINTN
-//ArmPlatformGetCorePosition (
-//  IN UINTN MpId
-//  );
-// With this function: CorePos = (ClusterId * 4) + CoreId
-ASM_FUNC(ArmPlatformGetCorePosition)
-  and   r1, r0, #ARM_CORE_MASK
-  and   r0, r0, #ARM_CLUSTER_MASK
-  add   r0, r1, r0, LSR #6
-  bx    lr
-
-//EFI_PHYSICAL_ADDRESS
-//GetPhysAddrTop (
-//  VOID
-//  );
-ASM_FUNC(ArmGetPhysAddrTop)
-  mov   r0, #0x00000000
-  mov   r1, #0x10000
-  bx    lr
-
diff --git a/ArmVirtPkg/Library/ArmXenRelocatablePlatformLib/ArmXenRelocatablePlatformLib.inf b/ArmVirtPkg/Library/ArmXenRelocatablePlatformLib/ArmXenRelocatablePlatformLib.inf
deleted file mode 100644
index b8cb24514d4c..000000000000
--- a/ArmVirtPkg/Library/ArmXenRelocatablePlatformLib/ArmXenRelocatablePlatformLib.inf
+++ /dev/null
@@ -1,63 +0,0 @@
-#/* @file
-#  Copyright (c) 2011-2015, ARM Limited. All rights reserved.
-#  Copyright (c) 2014, Linaro Limited. All rights reserved.
-#
-#  This program and the accompanying materials
-#  are licensed and made available under the terms and conditions of the BSD License
-#  which accompanies this distribution.  The full text of the license may be found at
-#  http://opensource.org/licenses/bsd-license.php
-#
-#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
-#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
-#
-#*/
-
-[Defines]
-  INF_VERSION                    = 0x00010005
-  BASE_NAME                      = ArmXenRelocatablePlatformLib
-  FILE_GUID                      = c8602718-4faa-4119-90ca-cae72509ac4c
-  MODULE_TYPE                    = BASE
-  VERSION_STRING                 = 1.0
-  LIBRARY_CLASS                  = ArmPlatformLib|SEC PEIM
-
-[Packages]
-  MdePkg/MdePkg.dec
-  MdeModulePkg/MdeModulePkg.dec
-  EmbeddedPkg/EmbeddedPkg.dec
-  ArmPkg/ArmPkg.dec
-  ArmPlatformPkg/ArmPlatformPkg.dec
-  ArmVirtPkg/ArmVirtPkg.dec
-
-[LibraryClasses]
-  IoLib
-  ArmLib
-  PrintLib
-  FdtLib
-
-[Sources.common]
-  RelocatableVirt.c
-  XenVirtMem.c
-  FdtParser.c
-
-[Sources.AARCH64]
-  AARCH64/RelocatableVirtHelper.S
-
-[Sources.ARM]
-  ARM/RelocatableVirtHelper.S
-
-[FeaturePcd]
-  gEmbeddedTokenSpaceGuid.PcdCacheEnable
-  gArmPlatformTokenSpaceGuid.PcdSystemMemoryInitializeInSec
-
-[PatchPcd]
-  gArmVirtTokenSpaceGuid.PcdDeviceTreeInitialBaseAddress
-  gArmTokenSpaceGuid.PcdFdBaseAddress
-  gArmTokenSpaceGuid.PcdFvBaseAddress
-  gArmTokenSpaceGuid.PcdSystemMemoryBase
-  gArmTokenSpaceGuid.PcdSystemMemorySize
-
-[FixedPcd]
-  gArmPlatformTokenSpaceGuid.PcdCoreCount
-  gArmTokenSpaceGuid.PcdArmPrimaryCoreMask
-  gArmTokenSpaceGuid.PcdArmPrimaryCore
-  gArmTokenSpaceGuid.PcdFdSize
diff --git a/ArmVirtPkg/Library/ArmXenRelocatablePlatformLib/FdtParser.c b/ArmVirtPkg/Library/ArmXenRelocatablePlatformLib/FdtParser.c
deleted file mode 100644
index 38fd5d3ed00c..000000000000
--- a/ArmVirtPkg/Library/ArmXenRelocatablePlatformLib/FdtParser.c
+++ /dev/null
@@ -1,89 +0,0 @@
-/*
- * Copyright (c) 2015, Linaro Ltd. All rights reserved.
- *
- * This program and the accompanying materials
- * are licensed and made available under the terms and conditions of the BSD License
- * which accompanies this distribution.  The full text of the license may be found at
- * http://opensource.org/licenses/bsd-license.php
- *
- * THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
- * WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
- */
-
-#include <Uefi.h>
-#include <Include/libfdt.h>
-
-BOOLEAN
-FindMemnode (
-  IN  VOID    *DeviceTreeBlob,
-  OUT UINT64  *SystemMemoryBase,
-  OUT UINT64  *SystemMemorySize
-  )
-{
-  INT32         MemoryNode;
-  INT32         AddressCells;
-  INT32         SizeCells;
-  INT32         Length;
-  CONST INT32   *Prop;
-
-  if (fdt_check_header (DeviceTreeBlob) != 0) {
-    return FALSE;
-  }
-
-  //
-  // Look for a node called "memory" at the lowest level of the tree
-  //
-  MemoryNode = fdt_path_offset (DeviceTreeBlob, "/memory");
-  if (MemoryNode <= 0) {
-    return FALSE;
-  }
-
-  //
-  // Retrieve the #address-cells and #size-cells properties
-  // from the root node, or use the default if not provided.
-  //
-  AddressCells = 1;
-  SizeCells = 1;
-
-  Prop = fdt_getprop (DeviceTreeBlob, 0, "#address-cells", &Length);
-  if (Length == 4) {
-    AddressCells = fdt32_to_cpu (*Prop);
-  }
-
-  Prop = fdt_getprop (DeviceTreeBlob, 0, "#size-cells", &Length);
-  if (Length == 4) {
-    SizeCells = fdt32_to_cpu (*Prop);
-  }
-
-  //
-  // Now find the 'reg' property of the /memory node, and read the first
-  // range listed.
-  //
-  Prop = fdt_getprop (DeviceTreeBlob, MemoryNode, "reg", &Length);
-
-  if (Length < (AddressCells + SizeCells) * sizeof (INT32)) {
-    return FALSE;
-  }
-
-  *SystemMemoryBase = fdt32_to_cpu (Prop[0]);
-  if (AddressCells > 1) {
-    *SystemMemoryBase = (*SystemMemoryBase << 32) | fdt32_to_cpu (Prop[1]);
-  }
-  Prop += AddressCells;
-
-  *SystemMemorySize = fdt32_to_cpu (Prop[0]);
-  if (SizeCells > 1) {
-    *SystemMemorySize = (*SystemMemorySize << 32) | fdt32_to_cpu (Prop[1]);
-  }
-
-  return TRUE;
-}
-
-VOID
-CopyFdt (
-  IN    VOID    *FdtDest,
-  IN    VOID    *FdtSource
-  )
-{
-  CopyMem (FdtDest, FdtSource, fdt_totalsize (FdtSource));
-}
diff --git a/ArmVirtPkg/Library/ArmXenRelocatablePlatformLib/RelocatableVirt.c b/ArmVirtPkg/Library/ArmXenRelocatablePlatformLib/RelocatableVirt.c
deleted file mode 100644
index 6df207733ab2..000000000000
--- a/ArmVirtPkg/Library/ArmXenRelocatablePlatformLib/RelocatableVirt.c
+++ /dev/null
@@ -1,70 +0,0 @@
-/** @file
-*
-*  Copyright (c) 2011-2013, ARM Limited. All rights reserved.
-*  Copyright (c) 2014, Linaro Limited. All rights reserved.
-*  Copyright (c) 2014, Red Hat, Inc.
-*
-*
-*  This program and the accompanying materials
-*  are licensed and made available under the terms and conditions of the BSD License
-*  which accompanies this distribution.  The full text of the license may be found at
-*  http://opensource.org/licenses/bsd-license.php
-*
-*  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
-*  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
-*
-**/
-
-#include <Library/IoLib.h>
-#include <Library/ArmPlatformLib.h>
-#include <Library/DebugLib.h>
-#include <Pi/PiBootMode.h>
-
-/**
-  Return the current Boot Mode
-
-  This function returns the boot reason on the platform
-
-  @return   Return the current Boot Mode of the platform
-
-**/
-EFI_BOOT_MODE
-ArmPlatformGetBootMode (
-  VOID
-  )
-{
-  return BOOT_WITH_FULL_CONFIGURATION;
-}
-
-/**
-  This function is called by PrePeiCore, in the SEC phase.
-**/
-RETURN_STATUS
-ArmPlatformInitialize (
-  IN  UINTN                     MpId
-  )
-{
-  //
-  // We are relying on ArmPlatformInitializeSystemMemory () being called from
-  // InitializeMemory (), which only occurs if the following feature is disabled
-  //
-  ASSERT (!FeaturePcdGet (PcdSystemMemoryInitializeInSec));
-  return RETURN_SUCCESS;
-}
-
-VOID
-ArmPlatformInitializeSystemMemory (
-  VOID
-  )
-{
-}
-
-VOID
-ArmPlatformGetPlatformPpiList (
-  OUT UINTN                   *PpiListSize,
-  OUT EFI_PEI_PPI_DESCRIPTOR  **PpiList
-  )
-{
-  *PpiListSize = 0;
-  *PpiList = NULL;
-}
diff --git a/ArmVirtPkg/Library/ArmXenRelocatablePlatformLib/XenVirtMem.c b/ArmVirtPkg/Library/ArmXenRelocatablePlatformLib/XenVirtMem.c
deleted file mode 100644
index 63090586cf8b..000000000000
--- a/ArmVirtPkg/Library/ArmXenRelocatablePlatformLib/XenVirtMem.c
+++ /dev/null
@@ -1,82 +0,0 @@
-/** @file
-*
-*  Copyright (c) 2014, Linaro Limited. All rights reserved.
-*
-*  This program and the accompanying materials
-*  are licensed and made available under the terms and conditions of the BSD License
-*  which accompanies this distribution.  The full text of the license may be found at
-*  http://opensource.org/licenses/bsd-license.php
-*
-*  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
-*  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
-*
-**/
-
-#include <Library/ArmPlatformLib.h>
-#include <Library/DebugLib.h>
-#include <Library/BaseMemoryLib.h>
-#include <Library/PcdLib.h>
-#include <Library/IoLib.h>
-#include <Library/MemoryAllocationLib.h>
-
-// Number of Virtual Memory Map Descriptors
-#define MAX_VIRTUAL_MEMORY_MAP_DESCRIPTORS          2
-
-// DDR attributes
-#define DDR_ATTRIBUTES_CACHED    ARM_MEMORY_REGION_ATTRIBUTE_WRITE_BACK
-#define DDR_ATTRIBUTES_UNCACHED  ARM_MEMORY_REGION_ATTRIBUTE_UNCACHED_UNBUFFERED
-
-EFI_PHYSICAL_ADDRESS
-ArmGetPhysAddrTop (
-  VOID
-  );
-
-/**
-  Return the Virtual Memory Map of your platform
-
-  This Virtual Memory Map is used by MemoryInitPei Module to initialize the MMU
-  on your platform.
-
-  @param[out]   VirtualMemoryMap    Array of ARM_MEMORY_REGION_DESCRIPTOR
-                                    describing a Physical-to-Virtual Memory
-                                    mapping. This array must be ended by a
-                                    zero-filled entry
-
-**/
-VOID
-ArmPlatformGetVirtualMemoryMap (
-  IN ARM_MEMORY_REGION_DESCRIPTOR** VirtualMemoryMap
-  )
-{
-  ARM_MEMORY_REGION_DESCRIPTOR  *VirtualMemoryTable;
-
-  ASSERT (VirtualMemoryMap != NULL);
-
-  VirtualMemoryTable = AllocatePages (
-                         EFI_SIZE_TO_PAGES (
-                           sizeof (ARM_MEMORY_REGION_DESCRIPTOR)
-                           * MAX_VIRTUAL_MEMORY_MAP_DESCRIPTORS
-                           )
-                         );
-
-  if (VirtualMemoryTable == NULL) {
-    DEBUG ((EFI_D_ERROR, "%a: Error: Failed AllocatePages()\n", __FUNCTION__));
-    return;
-  }
-
-  //
-  // Map the entire physical memory space as cached. The only device
-  // we care about is the GIC, which will be stage 2 mapped as a device
-  // by the hypervisor, which will override the cached mapping we install
-  // here.
-  //
-  VirtualMemoryTable[0].PhysicalBase = 0x0;
-  VirtualMemoryTable[0].VirtualBase  = 0x0;
-  VirtualMemoryTable[0].Length       = ArmGetPhysAddrTop ();
-  VirtualMemoryTable[0].Attributes   = DDR_ATTRIBUTES_CACHED;
-
-  // End of Table
-  ZeroMem (&VirtualMemoryTable[1], sizeof (ARM_MEMORY_REGION_DESCRIPTOR));
-
-  *VirtualMemoryMap = VirtualMemoryTable;
-}
-- 
2.11.0



^ permalink raw reply related	[flat|nested] 21+ messages in thread

* Re: [PATCH v2 10/14] ArmVirtPkg/ArmVirtXen: add ArmVirtMemInfoLib implementation
  2017-11-22 10:07 ` [PATCH v2 10/14] ArmVirtPkg/ArmVirtXen: add ArmVirtMemInfoLib implementation Ard Biesheuvel
@ 2017-11-22 17:03   ` Julien Grall
  0 siblings, 0 replies; 21+ messages in thread
From: Julien Grall @ 2017-11-22 17:03 UTC (permalink / raw)
  To: Ard Biesheuvel, edk2-devel, lersek

Hi Ard,

On 11/22/2017 10:07 AM, Ard Biesheuvel wrote:
> Clone the existing ArmPlatformGetVirtualMemoryMap () for this platform,
> clean it up slightly (by using a static buffer rather than a heap
> allocation, and removing the support for uncached DRAM mappings), and
> turn it into a new ArmVirtMemInfoLib implementation.
> 
> Contributed-under: TianoCore Contribution Agreement 1.1
> Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
> Acked-by: Laszlo Ersek <lersek@redhat.com>
> Cc: Julien Grall <julien.grall@linaro.org>

I have tested the series on both Arm32 and Arm64 guests:

Tested-by: Julien Grall <julien.grall@linaro.org>

[...]

> +VOID
> +EFIAPI
> +ArmVirtGetMemoryMap (
> +  OUT ARM_MEMORY_REGION_DESCRIPTOR   **VirtualMemoryMap
> +  )
> +{
> +  ASSERT (VirtualMemoryMap != NULL);
> +
> +  //
> +  // Map the entire physical memory space as cached. The only device
> +  // we care about is the GIC, which will be stage 2 mapped as a device
> +  // by the hypervisor, overriding the cached mapping we install here.
> +  //

I was about to complain about the fact you rely on the hypervisor 
setting correct stage-2 memory attribute. But I see this is a copy of 
the current code :).

We did relax the attribute for MMIO in the case of the Hardware Domain. 
I will keep the UEFI implementation in mind if we ever decide to relax 
for guests too.


> +  mVirtualMemoryTable[0].PhysicalBase = 0x0;
> +  mVirtualMemoryTable[0].VirtualBase  = 0x0;
> +  mVirtualMemoryTable[0].Length       = ArmGetPhysAddrTop ();
> +  mVirtualMemoryTable[0].Attributes   = ARM_MEMORY_REGION_ATTRIBUTE_WRITE_BACK;
> +
> +  mVirtualMemoryTable[1].PhysicalBase = 0x0;
> +  mVirtualMemoryTable[1].VirtualBase  = 0x0;
> +  mVirtualMemoryTable[1].Length       = 0x0;
> +  mVirtualMemoryTable[1].Attributes   = 0x0;
> +
> +  *VirtualMemoryMap = mVirtualMemoryTable;
> +}

Cheers,

-- 
Julien Grall


^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PATCH v2 09/14] ArmVirtPkg: introduce ArmVirtMemInfoLib library class
  2017-11-22 10:07 ` [PATCH v2 09/14] ArmVirtPkg: introduce ArmVirtMemInfoLib library class Ard Biesheuvel
@ 2017-11-23 16:00   ` Laszlo Ersek
  0 siblings, 0 replies; 21+ messages in thread
From: Laszlo Ersek @ 2017-11-23 16:00 UTC (permalink / raw)
  To: Ard Biesheuvel, edk2-devel

On 11/22/17 11:07, Ard Biesheuvel wrote:
> As part of the effort to get rid of ArmPlatformLib (which incorporates
> far too many duties in a single library), introduce ArmVirtMemInfoLib
> which will be invoked by our ArmVirtMemoryInitPeiLib implementation to
> get a description of the virtual address space. This will allow us to
> remove this functionality from ArmPlatformLib later, or, in the case of
> ArmVirtXen and ArmVirtQemuKernel, drop ArmPlatformLib altogether.
> 
> Contributed-under: TianoCore Contribution Agreement 1.1
> Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
> ---
>  ArmVirtPkg/ArmVirtPkg.dec                      |  3 ++
>  ArmVirtPkg/Include/Library/ArmVirtMemInfoLib.h | 41 ++++++++++++++++++++
>  2 files changed, 44 insertions(+)
> 
> diff --git a/ArmVirtPkg/ArmVirtPkg.dec b/ArmVirtPkg/ArmVirtPkg.dec
> index a8603e1b80e5..8f656fd2739d 100644
> --- a/ArmVirtPkg/ArmVirtPkg.dec
> +++ b/ArmVirtPkg/ArmVirtPkg.dec
> @@ -30,6 +30,9 @@ [Defines]
>  [Includes.common]
>    Include                        # Root include for the package
>  
> +[LibraryClasses]
> +  ArmVirtMemInfoLib|Include/Library/ArmVirtMemInfoLib.h
> +
>  [Guids.common]
>    gArmVirtTokenSpaceGuid = { 0x0B6F5CA7, 0x4F53, 0x445A, { 0xB7, 0x6E, 0x2E, 0x36, 0x5B, 0x80, 0x63, 0x66 } }
>    gEarlyPL011BaseAddressGuid       = { 0xB199DEA9, 0xFD5C, 0x4A84, { 0x80, 0x82, 0x2F, 0x41, 0x70, 0x78, 0x03, 0x05 } }
> diff --git a/ArmVirtPkg/Include/Library/ArmVirtMemInfoLib.h b/ArmVirtPkg/Include/Library/ArmVirtMemInfoLib.h
> new file mode 100644
> index 000000000000..bdf1c513bc6d
> --- /dev/null
> +++ b/ArmVirtPkg/Include/Library/ArmVirtMemInfoLib.h
> @@ -0,0 +1,41 @@
> +/** @file
> +
> +  Copyright (c) 2011-2013, ARM Limited. All rights reserved.
> +  Copyright (c) 2017, Linaro, Ltd. All rights reserved.
> +
> +  This program and the accompanying materials are licensed and made available
> +  under the terms and conditions of the BSD License which accompanies this
> +  distribution.  The full text of the license may be found at
> +  http://opensource.org/licenses/bsd-license.php
> +
> +  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
> +  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
> +
> +**/
> +
> +#ifndef _ARM_VIRT_MEMINFO_LIB_H_
> +#define _ARM_VIRT_MEMINFO_LIB_H_
> +
> +#include <Base.h>
> +#include <Library/ArmLib.h>
> +
> +/**
> +  Return the Virtual Memory Map of your platform
> +
> +  This Virtual Memory Map is used by MemoryInitPei Module to initialize the MMU
> +  on your platform.
> +
> +  @param[out]   VirtualMemoryMap    Array of ARM_MEMORY_REGION_DESCRIPTOR
> +                                    describing a Physical-to-Virtual Memory
> +                                    mapping. This array must be ended by a
> +                                    zero-filled entry. The allocated memory
> +                                    will not be freed.
> +
> +**/
> +VOID
> +EFIAPI
> +ArmVirtGetMemoryMap (
> +  OUT ARM_MEMORY_REGION_DESCRIPTOR    **VirtualMemoryMap
> +  );
> +
> +#endif
> 

Reviewed-by: Laszlo Ersek <lersek@redhat.com>


^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PATCH v2 11/14] ArmVirtPkg/ArmVirtQemu: add ArmVirtMemInfoLib implementation
  2017-11-22 10:07 ` [PATCH v2 11/14] ArmVirtPkg/ArmVirtQemu: " Ard Biesheuvel
@ 2017-11-23 16:18   ` Laszlo Ersek
  0 siblings, 0 replies; 21+ messages in thread
From: Laszlo Ersek @ 2017-11-23 16:18 UTC (permalink / raw)
  To: Ard Biesheuvel, edk2-devel

On 11/22/17 11:07, Ard Biesheuvel wrote:
> Create a new ArmVirtMemInfoLib for ArmVirtQemuKernel by cloning the
> existing ArmPlatformGetVirtualMemoryMap () for this platform,
> (ArmQemuRelocatablePlatformLib *not* ArmVirtPlatformLib), and cleaning
> it up:
> - remove support for uncached DRAM mappings
> - replace EFI_D_xxx with DEBUG_xxx throughout
> - use a temp variable to hold the top of the physical address space
> - use AllocatePool () instead of AllocatePages (), given that we use
>   160 bytes only, and the memory is never freed.
> 
> In a future patch, we will add this library to the ordinary ArmVirtQemu
> platform as well.
> 
> Contributed-under: TianoCore Contribution Agreement 1.1
> Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
> ---
>  ArmVirtPkg/ArmVirtQemuKernel.dsc                             |   1 +
>  ArmVirtPkg/Library/QemuVirtMemInfoLib/AArch64/PhysAddrTop.S  |  39 ++++++++
>  ArmVirtPkg/Library/QemuVirtMemInfoLib/Arm/PhysAddrTop.S      |  24 +++++
>  ArmVirtPkg/Library/QemuVirtMemInfoLib/QemuVirtMemInfoLib.c   | 100 ++++++++++++++++++++
>  ArmVirtPkg/Library/QemuVirtMemInfoLib/QemuVirtMemInfoLib.inf |  54 +++++++++++
>  5 files changed, 218 insertions(+)
> 
> diff --git a/ArmVirtPkg/ArmVirtQemuKernel.dsc b/ArmVirtPkg/ArmVirtQemuKernel.dsc
> index 7e5d584344b4..f50d30388cf2 100644
> --- a/ArmVirtPkg/ArmVirtQemuKernel.dsc
> +++ b/ArmVirtPkg/ArmVirtQemuKernel.dsc
> @@ -49,6 +49,7 @@ [LibraryClasses.common]
>    QemuFwCfgS3Lib|OvmfPkg/Library/QemuFwCfgS3Lib/BaseQemuFwCfgS3LibNull.inf
>  
>    ArmPlatformLib|ArmVirtPkg/Library/ArmQemuRelocatablePlatformLib/ArmQemuRelocatablePlatformLib.inf
> +  ArmVirtMemInfoLib|ArmVirtPkg/Library/QemuVirtMemInfoLib/QemuVirtMemInfoLib.inf
>  
>    TimerLib|ArmPkg/Library/ArmArchTimerLib/ArmArchTimerLib.inf
>    NorFlashPlatformLib|ArmVirtPkg/Library/NorFlashQemuLib/NorFlashQemuLib.inf
> diff --git a/ArmVirtPkg/Library/QemuVirtMemInfoLib/AArch64/PhysAddrTop.S b/ArmVirtPkg/Library/QemuVirtMemInfoLib/AArch64/PhysAddrTop.S
> new file mode 100644
> index 000000000000..a1f6a194d59b
> --- /dev/null
> +++ b/ArmVirtPkg/Library/QemuVirtMemInfoLib/AArch64/PhysAddrTop.S
> @@ -0,0 +1,39 @@
> +#
> +#  Copyright (c) 2011-2013, ARM Limited. All rights reserved.
> +#  Copyright (c) 2016-2017, Linaro Limited. All rights reserved.
> +#
> +#  This program and the accompanying materials
> +#  are licensed and made available under the terms and conditions of the BSD License
> +#  which accompanies this distribution.  The full text of the license may be found at
> +#  http://opensource.org/licenses/bsd-license.php
> +#
> +#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
> +#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
> +#
> +#
> +
> +#include <AsmMacroIoLibV8.h>
> +
> +//EFI_PHYSICAL_ADDRESS
> +//GetPhysAddrTop (
> +//  VOID
> +//  );
> +ASM_FUNC(ArmGetPhysAddrTop)
> +  mrs   x0, id_aa64mmfr0_el1
> +  adr   x1, .LPARanges
> +  and   x0, x0, #7
> +  ldrb  w1, [x1, x0]
> +  mov   x0, #1
> +  lsl   x0, x0, x1
> +  ret
> +
> +//
> +// Bits 0..2 of the AA64MFR0_EL1 system register encode the size of the
> +// physical address space support on this CPU:
> +// 0 == 32 bits, 1 == 36 bits, etc etc
> +// 6 and 7 are reserved
> +//
> +.LPARanges:
> +  .byte 32, 36, 40, 42, 44, 48, -1, -1
> +
> +ASM_FUNCTION_REMOVE_IF_UNREFERENCED
> diff --git a/ArmVirtPkg/Library/QemuVirtMemInfoLib/Arm/PhysAddrTop.S b/ArmVirtPkg/Library/QemuVirtMemInfoLib/Arm/PhysAddrTop.S
> new file mode 100644
> index 000000000000..9cd81529fb3d
> --- /dev/null
> +++ b/ArmVirtPkg/Library/QemuVirtMemInfoLib/Arm/PhysAddrTop.S
> @@ -0,0 +1,24 @@
> +#
> +#  Copyright (c) 2011-2013, ARM Limited. All rights reserved.
> +#  Copyright (c) 2014-2017, Linaro Limited. All rights reserved.
> +#
> +#  This program and the accompanying materials
> +#  are licensed and made available under the terms and conditions of the BSD License
> +#  which accompanies this distribution.  The full text of the license may be found at
> +#  http://opensource.org/licenses/bsd-license.php
> +#
> +#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
> +#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
> +#
> +#
> +
> +#include <AsmMacroIoLib.h>
> +
> +//EFI_PHYSICAL_ADDRESS
> +//GetPhysAddrTop (
> +//  VOID
> +//  );
> +ASM_FUNC(ArmGetPhysAddrTop)
> +  mov   r0, #0x00000000
> +  mov   r1, #0x10000
> +  bx    lr
> diff --git a/ArmVirtPkg/Library/QemuVirtMemInfoLib/QemuVirtMemInfoLib.c b/ArmVirtPkg/Library/QemuVirtMemInfoLib/QemuVirtMemInfoLib.c
> new file mode 100644
> index 000000000000..ea70f2c33b77
> --- /dev/null
> +++ b/ArmVirtPkg/Library/QemuVirtMemInfoLib/QemuVirtMemInfoLib.c
> @@ -0,0 +1,100 @@
> +/** @file
> +
> +  Copyright (c) 2014-2017, Linaro Limited. All rights reserved.
> +
> +  This program and the accompanying materials are licensed and made available
> +  under the terms and conditions of the BSD License which accompanies this
> +  distribution.  The full text of the license may be found at
> +  http://opensource.org/licenses/bsd-license.php
> +
> +  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
> +  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
> +
> +**/
> +
> +#include <Base.h>
> +#include <Library/ArmLib.h>
> +#include <Library/BaseMemoryLib.h>
> +#include <Library/DebugLib.h>
> +#include <Library/MemoryAllocationLib.h>
> +
> +// Number of Virtual Memory Map Descriptors
> +#define MAX_VIRTUAL_MEMORY_MAP_DESCRIPTORS          5
> +
> +EFI_PHYSICAL_ADDRESS
> +ArmGetPhysAddrTop (
> +  VOID
> +  );
> +
> +/**
> +  Return the Virtual Memory Map of your platform
> +
> +  This Virtual Memory Map is used by MemoryInitPei Module to initialize the MMU
> +  on your platform.
> +
> +  @param[out]   VirtualMemoryMap    Array of ARM_MEMORY_REGION_DESCRIPTOR
> +                                    describing a Physical-to-Virtual Memory
> +                                    mapping. This array must be ended by a
> +                                    zero-filled entry. The allocated memory
> +                                    will not be freed.
> +
> +**/
> +VOID
> +ArmVirtGetMemoryMap (
> +  OUT ARM_MEMORY_REGION_DESCRIPTOR   **VirtualMemoryMap
> +  )
> +{
> +  ARM_MEMORY_REGION_DESCRIPTOR  *VirtualMemoryTable;
> +  UINT64                        TopOfMemory;
> +
> +  ASSERT (VirtualMemoryMap != NULL);
> +
> +  VirtualMemoryTable = AllocatePool (sizeof (ARM_MEMORY_REGION_DESCRIPTOR) *
> +                                     MAX_VIRTUAL_MEMORY_MAP_DESCRIPTORS);

Pool allocations like this are satisfied from HOBs, before permanent PEI
RAM is installed. As part of the temp RAM migration, the HOBs are moved,
and the previous addresses become invalid. (This is not true for memory
allocated with AllocatePages().)

However, I think in this specific case that should be fine. We actually
don't want or need this allocation to stick around forever; the caller
(InitMmu()) uses it immediately. And, as far as I can see in InitMmu(),
the address of the map is not remembered. So this should be fine.

> +
> +  if (VirtualMemoryTable == NULL) {
> +    DEBUG ((DEBUG_ERROR, "%a: Error: Failed AllocatePages()\n", __FUNCTION__));
> +    return;
> +  }

Not very important, but before pushing, please update the error message
to say AllocatePool().

Reviewed-by: Laszlo Ersek <lersek@redhat.com>

Thanks
Laszlo

> +
> +  // System DRAM
> +  VirtualMemoryTable[0].PhysicalBase = PcdGet64 (PcdSystemMemoryBase);
> +  VirtualMemoryTable[0].VirtualBase  = VirtualMemoryTable[0].PhysicalBase;
> +  VirtualMemoryTable[0].Length       = PcdGet64 (PcdSystemMemorySize);
> +  VirtualMemoryTable[0].Attributes   = ARM_MEMORY_REGION_ATTRIBUTE_WRITE_BACK;
> +
> +  DEBUG ((DEBUG_INFO, "%a: Dumping System DRAM Memory Map:\n"
> +      "\tPhysicalBase: 0x%lX\n"
> +      "\tVirtualBase: 0x%lX\n"
> +      "\tLength: 0x%lX\n",
> +      __FUNCTION__,
> +      VirtualMemoryTable[0].PhysicalBase,
> +      VirtualMemoryTable[0].VirtualBase,
> +      VirtualMemoryTable[0].Length));
> +
> +  // Peripheral space before DRAM
> +  VirtualMemoryTable[1].PhysicalBase = 0x0;
> +  VirtualMemoryTable[1].VirtualBase  = 0x0;
> +  VirtualMemoryTable[1].Length       = VirtualMemoryTable[0].PhysicalBase;
> +  VirtualMemoryTable[1].Attributes   = ARM_MEMORY_REGION_ATTRIBUTE_DEVICE;
> +
> +  // Peripheral space after DRAM
> +  TopOfMemory = MIN (1ULL << FixedPcdGet8 (PcdPrePiCpuMemorySize),
> +                     ArmGetPhysAddrTop ());
> +  VirtualMemoryTable[2].PhysicalBase = VirtualMemoryTable[0].Length + VirtualMemoryTable[1].Length;
> +  VirtualMemoryTable[2].VirtualBase  = VirtualMemoryTable[2].PhysicalBase;
> +  VirtualMemoryTable[2].Length       = TopOfMemory -
> +                                       VirtualMemoryTable[2].PhysicalBase;
> +  VirtualMemoryTable[2].Attributes   = ARM_MEMORY_REGION_ATTRIBUTE_DEVICE;
> +
> +  // Remap the FD region as normal executable memory
> +  VirtualMemoryTable[3].PhysicalBase = PcdGet64 (PcdFdBaseAddress);
> +  VirtualMemoryTable[3].VirtualBase  = VirtualMemoryTable[3].PhysicalBase;
> +  VirtualMemoryTable[3].Length       = FixedPcdGet32 (PcdFdSize);
> +  VirtualMemoryTable[3].Attributes   = ARM_MEMORY_REGION_ATTRIBUTE_WRITE_BACK;
> +
> +  // End of Table
> +  ZeroMem (&VirtualMemoryTable[4], sizeof (ARM_MEMORY_REGION_DESCRIPTOR));
> +
> +  *VirtualMemoryMap = VirtualMemoryTable;
> +}
> diff --git a/ArmVirtPkg/Library/QemuVirtMemInfoLib/QemuVirtMemInfoLib.inf b/ArmVirtPkg/Library/QemuVirtMemInfoLib/QemuVirtMemInfoLib.inf
> new file mode 100644
> index 000000000000..c72a97f9e78a
> --- /dev/null
> +++ b/ArmVirtPkg/Library/QemuVirtMemInfoLib/QemuVirtMemInfoLib.inf
> @@ -0,0 +1,54 @@
> +#/* @file
> +#
> +#  Copyright (c) 2011-2015, ARM Limited. All rights reserved.
> +#  Copyright (c) 2014-2017, Linaro Limited. All rights reserved.
> +#
> +#  This program and the accompanying materials are licensed and made available
> +#  under the terms and conditions of the BSD License which accompanies this
> +#  distribution.  The full text of the license may be found at
> +#  http://opensource.org/licenses/bsd-license.php
> +#
> +#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
> +#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
> +#
> +#*/
> +
> +[Defines]
> +  INF_VERSION                    = 0x0001001A
> +  BASE_NAME                      = QemuVirtMemInfoLib
> +  FILE_GUID                      = 9b30ca82-6746-4a82-a3e6-11ea79df3b46
> +  MODULE_TYPE                    = BASE
> +  VERSION_STRING                 = 1.0
> +  LIBRARY_CLASS                  = ArmVirtMemInfoLib
> +
> +[Sources]
> +  QemuVirtMemInfoLib.c
> +
> +[Sources.ARM]
> +  Arm/PhysAddrTop.S
> +
> +[Sources.AARCH64]
> +  AArch64/PhysAddrTop.S
> +
> +[Packages]
> +  ArmPkg/ArmPkg.dec
> +  ArmVirtPkg/ArmVirtPkg.dec
> +  EmbeddedPkg/EmbeddedPkg.dec
> +  MdeModulePkg/MdeModulePkg.dec
> +  MdePkg/MdePkg.dec
> +
> +[LibraryClasses]
> +  ArmLib
> +  BaseMemoryLib
> +  DebugLib
> +  MemoryAllocationLib
> +  PcdLib
> +
> +[Pcd]
> +  gArmTokenSpaceGuid.PcdFdBaseAddress
> +  gArmTokenSpaceGuid.PcdSystemMemoryBase
> +  gArmTokenSpaceGuid.PcdSystemMemorySize
> +
> +[FixedPcd]
> +  gArmTokenSpaceGuid.PcdFdSize
> +  gEmbeddedTokenSpaceGuid.PcdPrePiCpuMemorySize
> 



^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PATCH v2 12/14] ArmVirtPkg: create QemuVirtMemInfoLib version for ArmVirtQemu
  2017-11-22 10:07 ` [PATCH v2 12/14] ArmVirtPkg: create QemuVirtMemInfoLib version for ArmVirtQemu Ard Biesheuvel
@ 2017-11-23 16:26   ` Laszlo Ersek
  0 siblings, 0 replies; 21+ messages in thread
From: Laszlo Ersek @ 2017-11-23 16:26 UTC (permalink / raw)
  To: Ard Biesheuvel, edk2-devel

On 11/22/17 11:07, Ard Biesheuvel wrote:
> The QemuVirtMemInfoLib ArmVirtMemInfoLib implementation created for
> ArmVirtQemuKernel does exactly what we need for ArmVirtQemu, the only
> difference being that the latter is PrePeiCore based, and so it uses
> a different method to ensure that PcdSystemMemorySize is set when
> ArmVirtGetMemoryMap() is called.
> 
> On ArmVirtQemu, we currently abuse the implied ordering guarantees
> provided by ArmPlatformLib, by implementing this as follows:
> 
>   ArmPlatformPkg/MemoryInitPei/MemoryInitPeim.inf [ArmVirtPkg/ArmVirtQemu.dsc]
>     InitializeMemory()                            [ArmPlatformPkg/MemoryInitPei/MemoryInitPeim.c]
>       ArmPlatformInitializeSystemMemory()         [ArmVirtPkg/Library/ArmVirtPlatformLib/Virt.c]
>         //
>         // set PcdSystemMemorySize from the DT
>         //
>       MemoryPeim()                                [ArmVirtPkg/Library/ArmVirtMemoryInitPeiLib/ArmVirtMemoryInitPeiLib.c]
>         InitMmu()                                 [ArmVirtPkg/Library/ArmVirtMemoryInitPeiLib/ArmVirtMemoryInitPeiLib.c]
>           ArmPlatformGetVirtualMemoryMap()        [ArmVirtPkg/Library/ArmVirtPlatformLib/VirtMem.c]
>             //
>             // consume PcdSystemMemorySize
>             //
> 
> Given that we are trying to get rid of ArmPlatformLib, or at least remove
> some of these API functions that are never used for their original purpose
> by any platforms, we need to move the PCD assignment elsewhere.
> 
> So create a PEIM-only version of QemuVirtMemInfoLib especially for
> ArmVirtQemu, and add the PCD assignment code to its constructor.
> 
> Contributed-under: TianoCore Contribution Agreement 1.1
> Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
> ---
>  ArmVirtPkg/ArmVirtQemu.dsc                                               |   3 +
>  ArmVirtPkg/Library/QemuVirtMemInfoLib/QemuVirtMemInfoPeiLib.inf          |  58 +++++++++++
>  ArmVirtPkg/Library/QemuVirtMemInfoLib/QemuVirtMemInfoPeiLibConstructor.c | 106 ++++++++++++++++++++
>  3 files changed, 167 insertions(+)
> 
> diff --git a/ArmVirtPkg/ArmVirtQemu.dsc b/ArmVirtPkg/ArmVirtQemu.dsc
> index d14a0dd0d1d9..519c2ae2e939 100644
> --- a/ArmVirtPkg/ArmVirtQemu.dsc
> +++ b/ArmVirtPkg/ArmVirtQemu.dsc
> @@ -67,6 +67,9 @@ [LibraryClasses.common]
>    HttpLib|MdeModulePkg/Library/DxeHttpLib/DxeHttpLib.inf
>  !endif
>  
> +[LibraryClasses.common.PEIM]
> +  ArmVirtMemInfoLib|ArmVirtPkg/Library/QemuVirtMemInfoLib/QemuVirtMemInfoPeiLib.inf
> +
>  [LibraryClasses.common.UEFI_DRIVER]
>    UefiScsiLib|MdePkg/Library/UefiScsiLib/UefiScsiLib.inf
>  
> diff --git a/ArmVirtPkg/Library/QemuVirtMemInfoLib/QemuVirtMemInfoPeiLib.inf b/ArmVirtPkg/Library/QemuVirtMemInfoLib/QemuVirtMemInfoPeiLib.inf
> new file mode 100644
> index 000000000000..e574a47443d0
> --- /dev/null
> +++ b/ArmVirtPkg/Library/QemuVirtMemInfoLib/QemuVirtMemInfoPeiLib.inf
> @@ -0,0 +1,58 @@
> +#/* @file
> +#
> +#  Copyright (c) 2011-2015, ARM Limited. All rights reserved.
> +#  Copyright (c) 2014-2017, Linaro Limited. All rights reserved.
> +#
> +#  This program and the accompanying materials are licensed and made available
> +#  under the terms and conditions of the BSD License which accompanies this
> +#  distribution.  The full text of the license may be found at
> +#  http://opensource.org/licenses/bsd-license.php
> +#
> +#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
> +#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
> +#
> +#*/
> +
> +[Defines]
> +  INF_VERSION                    = 0x0001001A
> +  BASE_NAME                      = QemuVirtMemInfoLib

(1) Please update BASE_NAME before pushing.

> +  FILE_GUID                      = 0c4d10cf-d949-49b4-bd13-47a4ae22efce
> +  MODULE_TYPE                    = BASE
> +  VERSION_STRING                 = 1.0
> +  LIBRARY_CLASS                  = ArmVirtMemInfoLib|PEIM
> +  CONSTRUCTOR                    = QemuVirtMemInfoPeiLibConstructor
> +
> +[Sources]
> +  QemuVirtMemInfoLib.c
> +  QemuVirtMemInfoPeiLibConstructor.c
> +
> +[Sources.ARM]
> +  Arm/PhysAddrTop.S
> +
> +[Sources.AARCH64]
> +  AArch64/PhysAddrTop.S
> +
> +[Packages]
> +  ArmPkg/ArmPkg.dec
> +  ArmVirtPkg/ArmVirtPkg.dec
> +  EmbeddedPkg/EmbeddedPkg.dec
> +  MdeModulePkg/MdeModulePkg.dec
> +  MdePkg/MdePkg.dec
> +
> +[LibraryClasses]
> +  ArmLib
> +  BaseMemoryLib
> +  DebugLib
> +  FdtLib
> +  PcdLib
> +  MemoryAllocationLib
> +
> +[Pcd]
> +  gArmTokenSpaceGuid.PcdFdBaseAddress
> +  gArmTokenSpaceGuid.PcdSystemMemoryBase
> +  gArmTokenSpaceGuid.PcdSystemMemorySize
> +
> +[FixedPcd]
> +  gArmTokenSpaceGuid.PcdFdSize
> +  gArmVirtTokenSpaceGuid.PcdDeviceTreeInitialBaseAddress
> +  gEmbeddedTokenSpaceGuid.PcdPrePiCpuMemorySize
> diff --git a/ArmVirtPkg/Library/QemuVirtMemInfoLib/QemuVirtMemInfoPeiLibConstructor.c b/ArmVirtPkg/Library/QemuVirtMemInfoLib/QemuVirtMemInfoPeiLibConstructor.c
> new file mode 100644
> index 000000000000..ef8ac6e018d1
> --- /dev/null
> +++ b/ArmVirtPkg/Library/QemuVirtMemInfoLib/QemuVirtMemInfoPeiLibConstructor.c
> @@ -0,0 +1,106 @@
> +/** @file
> +
> +  Copyright (c) 2014-2017, Linaro Limited. All rights reserved.
> +
> +  This program and the accompanying materials are licensed and made available
> +  under the terms and conditions of the BSD License which accompanies this
> +  distribution.  The full text of the license may be found at
> +  http://opensource.org/licenses/bsd-license.php
> +
> +  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
> +  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
> +
> +**/
> +
> +#include <Base.h>
> +#include <Library/DebugLib.h>
> +#include <Library/PcdLib.h>
> +#include <libfdt.h>
> +
> +RETURN_STATUS
> +EFIAPI
> +QemuVirtMemInfoPeiLibConstructor (
> +  VOID
> +  )
> +{
> +  VOID          *DeviceTreeBase;
> +  INT32         Node, Prev;
> +  UINT64        NewBase, CurBase;
> +  UINT64        NewSize, CurSize;
> +  CONST CHAR8   *Type;
> +  INT32         Len;
> +  CONST UINT64  *RegProp;
> +  RETURN_STATUS PcdStatus;
> +
> +  NewBase = 0;
> +  NewSize = 0;
> +
> +  DeviceTreeBase = (VOID *)(UINTN)PcdGet64 (PcdDeviceTreeInitialBaseAddress);
> +  ASSERT (DeviceTreeBase != NULL);
> +
> +  //
> +  // Make sure we have a valid device tree blob
> +  //
> +  ASSERT (fdt_check_header (DeviceTreeBase) == 0);
> +
> +  //
> +  // Look for the lowest memory node
> +  //
> +  for (Prev = 0;; Prev = Node) {
> +    Node = fdt_next_node (DeviceTreeBase, Prev, NULL);
> +    if (Node < 0) {
> +      break;
> +    }
> +
> +    //
> +    // Check for memory node
> +    //
> +    Type = fdt_getprop (DeviceTreeBase, Node, "device_type", &Len);
> +    if (Type && AsciiStrnCmp (Type, "memory", Len) == 0) {
> +      //
> +      // Get the 'reg' property of this node. For now, we will assume
> +      // two 8 byte quantities for base and size, respectively.
> +      //
> +      RegProp = fdt_getprop (DeviceTreeBase, Node, "reg", &Len);
> +      if (RegProp != 0 && Len == (2 * sizeof (UINT64))) {
> +
> +        CurBase = fdt64_to_cpu (ReadUnaligned64 (RegProp));
> +        CurSize = fdt64_to_cpu (ReadUnaligned64 (RegProp + 1));
> +
> +        DEBUG ((DEBUG_INFO, "%a: System RAM @ 0x%lx - 0x%lx\n",
> +          __FUNCTION__, CurBase, CurBase + CurSize - 1));
> +
> +        if (NewBase > CurBase || NewBase == 0) {
> +          NewBase = CurBase;
> +          NewSize = CurSize;
> +        }
> +      } else {
> +        DEBUG ((DEBUG_ERROR, "%a: Failed to parse FDT memory node\n",
> +          __FUNCTION__));

(2) Thanks for improving the indentation of the DEBUGs.

("--find-copies-harder" remains awesome :) )

Reviewed-by: Laszlo Ersek <lersek@redhat.com>

Thanks!
Laszlo

> +      }
> +    }
> +  }
> +
> +  //
> +  // Make sure the start of DRAM matches our expectation
> +  //
> +  ASSERT (FixedPcdGet64 (PcdSystemMemoryBase) == NewBase);
> +  PcdStatus = PcdSet64S (PcdSystemMemorySize, NewSize);
> +  ASSERT_RETURN_ERROR (PcdStatus);
> +
> +  //
> +  // We need to make sure that the machine we are running on has at least
> +  // 128 MB of memory configured, and is currently executing this binary from
> +  // NOR flash. This prevents a device tree image in DRAM from getting
> +  // clobbered when our caller installs permanent PEI RAM, before we have a
> +  // chance of marking its location as reserved or copy it to a freshly
> +  // allocated block in the permanent PEI RAM in the platform PEIM.
> +  //
> +  ASSERT (NewSize >= SIZE_128MB);
> +  ASSERT (
> +    (((UINT64)PcdGet64 (PcdFdBaseAddress) +
> +      (UINT64)PcdGet32 (PcdFdSize)) <= NewBase) ||
> +    ((UINT64)PcdGet64 (PcdFdBaseAddress) >= (NewBase + NewSize)));
> +
> +  return RETURN_SUCCESS;
> +}
> 



^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PATCH v2 13/14] ArmVirtPkg/ArmVirtMemoryInitPeiLib: move to ArmVirtMemInfoLib
  2017-11-22 10:07 ` [PATCH v2 13/14] ArmVirtPkg/ArmVirtMemoryInitPeiLib: move to ArmVirtMemInfoLib Ard Biesheuvel
@ 2017-11-23 16:32   ` Laszlo Ersek
  0 siblings, 0 replies; 21+ messages in thread
From: Laszlo Ersek @ 2017-11-23 16:32 UTC (permalink / raw)
  To: Ard Biesheuvel, edk2-devel

On 11/22/17 11:07, Ard Biesheuvel wrote:
> Move to the new ArmVirtMemInfoLib library to retrieve DRAM information
> from the platform, so that we can phase out ArmPlatformLib going forward.
> 
> Contributed-under: TianoCore Contribution Agreement 1.1
> Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
> ---
>  ArmVirtPkg/ArmVirtQemu.dsc                                             | 2 +-
>  ArmVirtPkg/Library/ArmVirtMemoryInitPeiLib/ArmVirtMemoryInitPeiLib.c   | 4 ++--
>  ArmVirtPkg/Library/ArmVirtMemoryInitPeiLib/ArmVirtMemoryInitPeiLib.inf | 3 ++-
>  3 files changed, 5 insertions(+), 4 deletions(-)
> 
> diff --git a/ArmVirtPkg/ArmVirtQemu.dsc b/ArmVirtPkg/ArmVirtQemu.dsc
> index 519c2ae2e939..f09226671827 100644
> --- a/ArmVirtPkg/ArmVirtQemu.dsc
> +++ b/ArmVirtPkg/ArmVirtQemu.dsc
> @@ -48,7 +48,7 @@ [LibraryClasses.common]
>    QemuFwCfgLib|ArmVirtPkg/Library/QemuFwCfgLib/QemuFwCfgLib.inf
>    QemuFwCfgS3Lib|OvmfPkg/Library/QemuFwCfgS3Lib/BaseQemuFwCfgS3LibNull.inf
>  
> -  ArmPlatformLib|ArmVirtPkg/Library/ArmVirtPlatformLib/ArmVirtPlatformLib.inf
> +  ArmPlatformLib|ArmPlatformPkg/Library/ArmPlatformLibNull/ArmPlatformLibNull.inf
>  
>    TimerLib|ArmPkg/Library/ArmArchTimerLib/ArmArchTimerLib.inf
>    NorFlashPlatformLib|ArmVirtPkg/Library/NorFlashQemuLib/NorFlashQemuLib.inf
> diff --git a/ArmVirtPkg/Library/ArmVirtMemoryInitPeiLib/ArmVirtMemoryInitPeiLib.c b/ArmVirtPkg/Library/ArmVirtMemoryInitPeiLib/ArmVirtMemoryInitPeiLib.c
> index 6f3e54b7afcb..05afd1282422 100644
> --- a/ArmVirtPkg/Library/ArmVirtMemoryInitPeiLib/ArmVirtMemoryInitPeiLib.c
> +++ b/ArmVirtPkg/Library/ArmVirtMemoryInitPeiLib/ArmVirtMemoryInitPeiLib.c
> @@ -16,7 +16,7 @@
>  #include <PiPei.h>
>  
>  #include <Library/ArmMmuLib.h>
> -#include <Library/ArmPlatformLib.h>
> +#include <Library/ArmVirtMemInfoLib.h>
>  #include <Library/DebugLib.h>
>  #include <Library/HobLib.h>
>  #include <Library/MemoryAllocationLib.h>
> @@ -39,7 +39,7 @@ InitMmu (
>    RETURN_STATUS                 Status;
>  
>    // Get Virtual Memory Map from the Platform Library
> -  ArmPlatformGetVirtualMemoryMap (&MemoryTable);
> +  ArmVirtGetMemoryMap (&MemoryTable);
>  
>    //Note: Because we called PeiServicesInstallPeiMemory() before to call InitMmu() the MMU Page Table resides in
>    //      DRAM (even at the top of DRAM as it is the first permanent memory allocation)
> diff --git a/ArmVirtPkg/Library/ArmVirtMemoryInitPeiLib/ArmVirtMemoryInitPeiLib.inf b/ArmVirtPkg/Library/ArmVirtMemoryInitPeiLib/ArmVirtMemoryInitPeiLib.inf
> index 028d6fb5ac28..54879d590a8a 100644
> --- a/ArmVirtPkg/Library/ArmVirtMemoryInitPeiLib/ArmVirtMemoryInitPeiLib.inf
> +++ b/ArmVirtPkg/Library/ArmVirtMemoryInitPeiLib/ArmVirtMemoryInitPeiLib.inf
> @@ -29,13 +29,14 @@ [Packages]
>    EmbeddedPkg/EmbeddedPkg.dec
>    ArmPkg/ArmPkg.dec
>    ArmPlatformPkg/ArmPlatformPkg.dec
> +  ArmVirtPkg/ArmVirtPkg.dec
>  
>  [LibraryClasses]
>    DebugLib
>    HobLib
>    ArmLib
>    ArmMmuLib
> -  ArmPlatformLib
> +  ArmVirtMemInfoLib
>    CacheMaintenanceLib
>  
>  [Guids]
> 

Reviewed-by: Laszlo Ersek <lersek@redhat.com>


^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PATCH v2 00/14] ArmVirtPkg: get rid of ArmPlatformLib
  2017-11-22 10:07 [PATCH v2 00/14] ArmVirtPkg: get rid of ArmPlatformLib Ard Biesheuvel
                   ` (13 preceding siblings ...)
  2017-11-22 10:07 ` [PATCH v2 14/14] ArmVirtPkg: remove ArmPlatformLib implementations Ard Biesheuvel
@ 2017-11-23 16:56 ` Ard Biesheuvel
  14 siblings, 0 replies; 21+ messages in thread
From: Ard Biesheuvel @ 2017-11-23 16:56 UTC (permalink / raw)
  To: edk2-devel@lists.01.org, Laszlo Ersek; +Cc: Ard Biesheuvel

On 22 November 2017 at 10:07, Ard Biesheuvel <ard.biesheuvel@linaro.org> wrote:
> ArmPlatformLib is a mixed bag of platform specific hooks, some of which
> are called from early startup code, and some of which are called from C
> code, to get the boot mode, memory layout etc.
>
> This library class is tightly coupled to the old ARM implementations that
> ran some parts of UEFI in the secure world, and booted all cores into SEC.
> Also, the fact that both PrePi and PrePeiCore use ArmPlatformLib makes it
> difficult to use PEI phase features such as PPI depexes. It would be better
> if we could get rid of it completely, or at least not require each platform
> to implement it in its entirety.
>
> So as a first step towards phasing out ArmPlatformLib to the extent possible,
> let's remove it from ArmVirtPkg. For ArmVirtXen and ArmVirtQemuKernel, we can
> get rid of it completely. For ArmVirtQemu, we can't, but we can still remove
> our own implementation by switching to the NULL implementation from
> ArmPlatformPkg (which does require a minimal tweak in patch #1). Further
> reductions of the scope of ArmPlatformLib will be reflected in that library
> without the need for further changes to ArmVirtPkg.
>
> v2: drop ArmPlatformPkg prereq patch, it is merged now
>     use constructor instead of PEIM depex ordering to ensure ArmVirtQemu's
>     PcdSystemMemorySize PCD is set before being consumed
>     add acks from Laszlo
>
> Ard Biesheuvel (14):
>   ArmVirtPkg/PrePi: run all library constructors by hand
>   ArmVirtPkg/PrePi: remove unused GetPlatformPpi() function
>   ArmVirtPkg/PrePi: remove bogus primary core check
>   ArmVirtPkg/PrePi: move DRAM discovery code into PrePi
>   ArmVirtPkg/PrePi: remove dependency on ArmPlatformLib
>   ArmVirtPkg/PrePi: remove ArmPlatformStackLib dependency
>   ArmVirtPkg/PrePi: remove bogus IntelFrameworkModulePkg.dec dependency
>   ArmVirtPkg/ArmVirtPlatformLib: remove support for uncached mappings
>   ArmVirtPkg: introduce ArmVirtMemInfoLib library class
>   ArmVirtPkg/ArmVirtXen: add ArmVirtMemInfoLib implementation
>   ArmVirtPkg/ArmVirtQemu: add ArmVirtMemInfoLib implementation
>   ArmVirtPkg: create QemuVirtMemInfoLib version for ArmVirtQemu
>   ArmVirtPkg/ArmVirtMemoryInitPeiLib: move to ArmVirtMemInfoLib
>   ArmVirtPkg: remove ArmPlatformLib implementations
>

Pushed as 14ca435fb6c0..3d544c564bd6

Thanks.


^ permalink raw reply	[flat|nested] 21+ messages in thread

end of thread, other threads:[~2017-11-23 16:52 UTC | newest]

Thread overview: 21+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-11-22 10:07 [PATCH v2 00/14] ArmVirtPkg: get rid of ArmPlatformLib Ard Biesheuvel
2017-11-22 10:07 ` [PATCH v2 01/14] ArmVirtPkg/PrePi: run all library constructors by hand Ard Biesheuvel
2017-11-22 10:07 ` [PATCH v2 02/14] ArmVirtPkg/PrePi: remove unused GetPlatformPpi() function Ard Biesheuvel
2017-11-22 10:07 ` [PATCH v2 03/14] ArmVirtPkg/PrePi: remove bogus primary core check Ard Biesheuvel
2017-11-22 10:07 ` [PATCH v2 04/14] ArmVirtPkg/PrePi: move DRAM discovery code into PrePi Ard Biesheuvel
2017-11-22 10:07 ` [PATCH v2 05/14] ArmVirtPkg/PrePi: remove dependency on ArmPlatformLib Ard Biesheuvel
2017-11-22 10:07 ` [PATCH v2 06/14] ArmVirtPkg/PrePi: remove ArmPlatformStackLib dependency Ard Biesheuvel
2017-11-22 10:07 ` [PATCH v2 07/14] ArmVirtPkg/PrePi: remove bogus IntelFrameworkModulePkg.dec dependency Ard Biesheuvel
2017-11-22 10:07 ` [PATCH v2 08/14] ArmVirtPkg/ArmVirtPlatformLib: remove support for uncached mappings Ard Biesheuvel
2017-11-22 10:07 ` [PATCH v2 09/14] ArmVirtPkg: introduce ArmVirtMemInfoLib library class Ard Biesheuvel
2017-11-23 16:00   ` Laszlo Ersek
2017-11-22 10:07 ` [PATCH v2 10/14] ArmVirtPkg/ArmVirtXen: add ArmVirtMemInfoLib implementation Ard Biesheuvel
2017-11-22 17:03   ` Julien Grall
2017-11-22 10:07 ` [PATCH v2 11/14] ArmVirtPkg/ArmVirtQemu: " Ard Biesheuvel
2017-11-23 16:18   ` Laszlo Ersek
2017-11-22 10:07 ` [PATCH v2 12/14] ArmVirtPkg: create QemuVirtMemInfoLib version for ArmVirtQemu Ard Biesheuvel
2017-11-23 16:26   ` Laszlo Ersek
2017-11-22 10:07 ` [PATCH v2 13/14] ArmVirtPkg/ArmVirtMemoryInitPeiLib: move to ArmVirtMemInfoLib Ard Biesheuvel
2017-11-23 16:32   ` Laszlo Ersek
2017-11-22 10:07 ` [PATCH v2 14/14] ArmVirtPkg: remove ArmPlatformLib implementations Ard Biesheuvel
2017-11-23 16:56 ` [PATCH v2 00/14] ArmVirtPkg: get rid of ArmPlatformLib Ard Biesheuvel

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox