In preparation of permitting the virt code to define a larger PA space
size via gEmbeddedTokenSpaceGuid.PcdPrePiCpuMemorySize than what the
CPU actually supports, take the CPU's capabilities into account when
setting up the page tables. This is necessary because KVM will shortly
support variable PA space sizes, and to support running the same UEFI
binaries regardless of that limit, PcdPrePiCpuMemorySize needs to be
treated as an upper bound rather than a fixed size.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Ard Biesheuvel <[email protected]>
---
 ArmPkg/Library/ArmMmuLib/AArch64/ArmMmuLibCore.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/ArmPkg/Library/ArmMmuLib/AArch64/ArmMmuLibCore.c 
b/ArmPkg/Library/ArmMmuLib/AArch64/ArmMmuLibCore.c
index 4b62ecb6a476..a4fde9b59383 100644
--- a/ArmPkg/Library/ArmMmuLib/AArch64/ArmMmuLibCore.c
+++ b/ArmPkg/Library/ArmMmuLib/AArch64/ArmMmuLibCore.c
@@ -593,6 +593,7 @@ ArmConfigureMmu (
 {
   VOID*                         TranslationTable;
   UINT32                        TranslationTableAttribute;
+  UINTN                         MaxAddressBits;
   UINT64                        MaxAddress;
   UINTN                         T0SZ;
   UINTN                         RootTableEntryCount;
@@ -605,7 +606,9 @@ ArmConfigureMmu (
   }
 
   // Cover the entire GCD memory space
-  MaxAddress = (1UL << PcdGet8 (PcdPrePiCpuMemorySize)) - 1;
+  MaxAddressBits = MIN (ArmGetPhysicalAddressBits (),
+                        PcdGet8 (PcdPrePiCpuMemorySize));
+  MaxAddress = (1UL << MaxAddressBits) - 1;
 
   // Lookup the Table Level to get the information
   LookupAddresstoRootTable (MaxAddress, &T0SZ, &RootTableEntryCount);
-- 
2.17.1

_______________________________________________
edk2-devel mailing list
[email protected]
https://lists.01.org/mailman/listinfo/edk2-devel

Reply via email to