diff mbox series

[edk2,edk2-platforms,4/8] Silicon/SynQuacerMemoryInitPeiLib: don't map memory above MAX_ALLOC_ADDRESS

Message ID 20190114170205.9748-5-ard.biesheuvel@linaro.org
State New
Headers show
Series Silicon/SynQuacer: add support for 32-bit mode | expand

Commit Message

Ard Biesheuvel Jan. 14, 2019, 5:02 p.m. UTC
When encountering memory that is above the threshold of what we can
map, don't add it to the virtual memory table. This table is only
used by the early MMU code that creates the 1:1 mapping, and since
it cannot be mapped in the first place, there is no point.

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

---
 Silicon/Socionext/SynQuacer/Library/SynQuacerMemoryInitPeiLib/SynQuacerMemoryInitPeiLib.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

-- 
2.17.1

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

Patch

diff --git a/Silicon/Socionext/SynQuacer/Library/SynQuacerMemoryInitPeiLib/SynQuacerMemoryInitPeiLib.c b/Silicon/Socionext/SynQuacer/Library/SynQuacerMemoryInitPeiLib/SynQuacerMemoryInitPeiLib.c
index 1402ecafce4a..3955b6df84a0 100644
--- a/Silicon/Socionext/SynQuacer/Library/SynQuacerMemoryInitPeiLib/SynQuacerMemoryInitPeiLib.c
+++ b/Silicon/Socionext/SynQuacer/Library/SynQuacerMemoryInitPeiLib/SynQuacerMemoryInitPeiLib.c
@@ -156,17 +156,22 @@  DeclareDram (
 
   DramDescriptor = *VirtualMemoryTable + ARRAY_SIZE (mVirtualMemoryTable);
 
-  for (Idx = 0; Idx < RegionCount; Idx++, DramDescriptor++) {
+  for (Idx = 0; Idx < RegionCount; Idx++) {
     Status = DramInfo->GetRegion (Idx, &Base, &Size);
     ASSERT_EFI_ERROR (Status);
 
     BuildResourceDescriptorHob (EFI_RESOURCE_SYSTEM_MEMORY,
       mDramResourceAttributes, Base, Size);
 
+    if (Base > MAX_ALLOC_ADDRESS - Size + 1) {
+      continue;
+    }
+
     DramDescriptor->PhysicalBase = Base;
     DramDescriptor->VirtualBase  = Base;
-    DramDescriptor->Length       = Size;
+    DramDescriptor->Length       = MIN (Size, MAX_ALLOC_ADDRESS - Base + 1);
     DramDescriptor->Attributes   = ARM_MEMORY_REGION_ATTRIBUTE_WRITE_BACK;
+    DramDescriptor++;
   }
 
   DramDescriptor->PhysicalBase = 0;