[edk2-devel] [PATCH 1/2] OvmfPkg/PlatformPei: ScanOrAdd64BitE820Ram improvements

Gerd Hoffmann kraxel at redhat.com
Thu Aug 19 08:11:09 UTC 2021


Add a bool parameter to ScanOrAdd64BitE820Ram to explicitly specify
whenever ScanOrAdd64BitE820Ram should add HOBs for high memory (above
4G) or scan only.

Also add a lowmem parameter so ScanOrAdd64BitE820Ram
can report the memory size below 4G.

This allows a more flexible usage of ScanOrAdd64BitE820Ram,
a followup patch will use it for all memory detection.

No functional change.

Signed-off-by: Gerd Hoffmann <kraxel at redhat.com>
---
 OvmfPkg/PlatformPei/MemDetect.c | 28 +++++++++++++++++++++-------
 1 file changed, 21 insertions(+), 7 deletions(-)

diff --git a/OvmfPkg/PlatformPei/MemDetect.c b/OvmfPkg/PlatformPei/MemDetect.c
index 2deec128f464..d7fb3e742be3 100644
--- a/OvmfPkg/PlatformPei/MemDetect.c
+++ b/OvmfPkg/PlatformPei/MemDetect.c
@@ -200,6 +200,8 @@ QemuUc32BaseInitialization (
 STATIC
 EFI_STATUS
 ScanOrAdd64BitE820Ram (
+  IN BOOLEAN AddHighHob,
+  OUT UINT64 *LowMemory OPTIONAL,
   OUT UINT64 *MaxAddress OPTIONAL
   )
 {
@@ -217,6 +219,9 @@ ScanOrAdd64BitE820Ram (
     return EFI_PROTOCOL_ERROR;
   }
 
+  if (LowMemory != NULL) {
+    *LowMemory = 0;
+  }
   if (MaxAddress != NULL) {
     *MaxAddress = BASE_4GB;
   }
@@ -232,9 +237,8 @@ ScanOrAdd64BitE820Ram (
       E820Entry.Length,
       E820Entry.Type
       ));
-    if (E820Entry.Type == EfiAcpiAddressRangeMemory &&
-        E820Entry.BaseAddr >= BASE_4GB) {
-      if (MaxAddress == NULL) {
+    if (E820Entry.Type == EfiAcpiAddressRangeMemory) {
+      if (AddHighHob && E820Entry.BaseAddr >= BASE_4GB) {
         UINT64 Base;
         UINT64 End;
 
@@ -254,11 +258,12 @@ ScanOrAdd64BitE820Ram (
             End
             ));
         }
-      } else {
+      }
+      if (MaxAddress || LowMemory) {
         UINT64 Candidate;
 
         Candidate = E820Entry.BaseAddr + E820Entry.Length;
-        if (Candidate > *MaxAddress) {
+        if (MaxAddress && Candidate > *MaxAddress) {
           *MaxAddress = Candidate;
           DEBUG ((
             DEBUG_VERBOSE,
@@ -267,6 +272,15 @@ ScanOrAdd64BitE820Ram (
             *MaxAddress
             ));
         }
+        if (LowMemory && Candidate > *LowMemory && Candidate < BASE_4GB) {
+          *LowMemory = Candidate;
+          DEBUG ((
+            DEBUG_VERBOSE,
+            "%a: LowMemory=0x%Lx\n",
+            __FUNCTION__,
+            *LowMemory
+            ));
+        }
       }
     }
   }
@@ -353,7 +367,7 @@ GetFirstNonAddress (
   // Otherwise, get the flat size of the memory above 4GB from the CMOS (which
   // can only express a size smaller than 1TB), and add it to 4GB.
   //
-  Status = ScanOrAdd64BitE820Ram (&FirstNonAddress);
+  Status = ScanOrAdd64BitE820Ram (FALSE, NULL, &FirstNonAddress);
   if (EFI_ERROR (Status)) {
     FirstNonAddress = BASE_4GB + GetSystemMemorySizeAbove4gb ();
   }
@@ -754,7 +768,7 @@ QemuInitializeRam (
     // entries. Otherwise, create a single memory HOB with the flat >=4GB
     // memory size read from the CMOS.
     //
-    Status = ScanOrAdd64BitE820Ram (NULL);
+    Status = ScanOrAdd64BitE820Ram (TRUE, NULL, NULL);
     if (EFI_ERROR (Status) && UpperMemorySize != 0) {
       AddMemoryBaseSizeHob (BASE_4GB, UpperMemorySize);
     }
-- 
2.31.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#79561): https://edk2.groups.io/g/devel/message/79561
Mute This Topic: https://groups.io/mt/84992115/1813853
Group Owner: devel+owner at edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [edk2-devel-archive at redhat.com]
-=-=-=-=-=-=-=-=-=-=-=-





More information about the edk2-devel-archive mailing list