]> git.proxmox.com Git - mirror_edk2.git/commitdiff
OvmfPkg/PlatformPei: ScanOrAdd64BitE820Ram improvements
authorGerd Hoffmann <kraxel@redhat.com>
Wed, 8 Dec 2021 07:01:44 +0000 (08:01 +0100)
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Mon, 13 Dec 2021 14:47:37 +0000 (14:47 +0000)
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.

Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3593
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Reviewed-by: Philippe Mathieu-Daude <philmd@redhat.com>
OvmfPkg/PlatformPei/MemDetect.c

index 934d5c196570cbbece58eb77b2718340a8ea68bb..b0b7e466a7bc2045465ea77eabac589b1d17c056 100644 (file)
@@ -223,6 +223,8 @@ QemuUc32BaseInitialization (
 STATIC\r
 EFI_STATUS\r
 ScanOrAdd64BitE820Ram (\r
+  IN BOOLEAN  AddHighHob,\r
+  OUT UINT64  *LowMemory OPTIONAL,\r
   OUT UINT64  *MaxAddress OPTIONAL\r
   )\r
 {\r
@@ -241,6 +243,10 @@ ScanOrAdd64BitE820Ram (
     return EFI_PROTOCOL_ERROR;\r
   }\r
 \r
+  if (LowMemory != NULL) {\r
+    *LowMemory = 0;\r
+  }\r
+\r
   if (MaxAddress != NULL) {\r
     *MaxAddress = BASE_4GB;\r
   }\r
@@ -256,10 +262,8 @@ ScanOrAdd64BitE820Ram (
       E820Entry.Length,\r
       E820Entry.Type\r
       ));\r
-    if ((E820Entry.Type == EfiAcpiAddressRangeMemory) &&\r
-        (E820Entry.BaseAddr >= BASE_4GB))\r
-    {\r
-      if (MaxAddress == NULL) {\r
+    if (E820Entry.Type == EfiAcpiAddressRangeMemory) {\r
+      if (AddHighHob && (E820Entry.BaseAddr >= BASE_4GB)) {\r
         UINT64  Base;\r
         UINT64  End;\r
 \r
@@ -279,11 +283,13 @@ ScanOrAdd64BitE820Ram (
             End\r
             ));\r
         }\r
-      } else {\r
+      }\r
+\r
+      if (MaxAddress || LowMemory) {\r
         UINT64  Candidate;\r
 \r
         Candidate = E820Entry.BaseAddr + E820Entry.Length;\r
-        if (Candidate > *MaxAddress) {\r
+        if (MaxAddress && (Candidate > *MaxAddress)) {\r
           *MaxAddress = Candidate;\r
           DEBUG ((\r
             DEBUG_VERBOSE,\r
@@ -292,6 +298,16 @@ ScanOrAdd64BitE820Ram (
             *MaxAddress\r
             ));\r
         }\r
+\r
+        if (LowMemory && (Candidate > *LowMemory) && (Candidate < BASE_4GB)) {\r
+          *LowMemory = Candidate;\r
+          DEBUG ((\r
+            DEBUG_VERBOSE,\r
+            "%a: LowMemory=0x%Lx\n",\r
+            __FUNCTION__,\r
+            *LowMemory\r
+            ));\r
+        }\r
       }\r
     }\r
   }\r
@@ -376,7 +392,7 @@ GetFirstNonAddress (
   // Otherwise, get the flat size of the memory above 4GB from the CMOS (which\r
   // can only express a size smaller than 1TB), and add it to 4GB.\r
   //\r
-  Status = ScanOrAdd64BitE820Ram (&FirstNonAddress);\r
+  Status = ScanOrAdd64BitE820Ram (FALSE, NULL, &FirstNonAddress);\r
   if (EFI_ERROR (Status)) {\r
     FirstNonAddress = BASE_4GB + GetSystemMemorySizeAbove4gb ();\r
   }\r
@@ -809,7 +825,7 @@ QemuInitializeRam (
     // entries. Otherwise, create a single memory HOB with the flat >=4GB\r
     // memory size read from the CMOS.\r
     //\r
-    Status = ScanOrAdd64BitE820Ram (NULL);\r
+    Status = ScanOrAdd64BitE820Ram (TRUE, NULL, NULL);\r
     if (EFI_ERROR (Status) && (UpperMemorySize != 0)) {\r
       AddMemoryBaseSizeHob (BASE_4GB, UpperMemorySize);\r
     }\r