public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [PATCH v2 0/3] OvmfPkg/PlatformPei: prefer etc/e820 for memory detection
@ 2021-08-26  9:55 Gerd Hoffmann
  2021-08-26  9:55 ` [PATCH v2 1/3] OvmfPkg/PlatformPei: ScanOrAdd64BitE820Ram improvements Gerd Hoffmann
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Gerd Hoffmann @ 2021-08-26  9:55 UTC (permalink / raw)
  To: devel
  Cc: Ard Biesheuvel, Jiewen Yao, Jordan Justen, Philippe Mathieu-Daude,
	Gerd Hoffmann

Don't use cmos for memory detection if possible.
qemu provides the etc/e820 firmware config file
as alternative since 2013.

v2:
 - fix lowmem detection
 - pick up review tags
 - add rfc patch to completely drop cmos support.

Gerd Hoffmann (3):
  OvmfPkg/PlatformPei: ScanOrAdd64BitE820Ram improvements
  OvmfPkg/PlatformPei: prefer etc/e820 for memory detection
  RFC: OvmfPkg/PlatformPei: stop using cmos for memory detection

 OvmfPkg/PlatformPei/MemDetect.c | 83 +++++++++++----------------------
 1 file changed, 27 insertions(+), 56 deletions(-)

-- 
2.31.1


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

* [PATCH v2 1/3] OvmfPkg/PlatformPei: ScanOrAdd64BitE820Ram improvements
  2021-08-26  9:55 [PATCH v2 0/3] OvmfPkg/PlatformPei: prefer etc/e820 for memory detection Gerd Hoffmann
@ 2021-08-26  9:55 ` Gerd Hoffmann
  2021-08-26  9:55 ` [PATCH v2 2/3] OvmfPkg/PlatformPei: prefer etc/e820 for memory detection Gerd Hoffmann
  2021-08-26  9:55 ` [PATCH v2 3/3] RFC: OvmfPkg/PlatformPei: stop using cmos " Gerd Hoffmann
  2 siblings, 0 replies; 6+ messages in thread
From: Gerd Hoffmann @ 2021-08-26  9:55 UTC (permalink / raw)
  To: devel
  Cc: Ard Biesheuvel, Jiewen Yao, Jordan Justen, Philippe Mathieu-Daude,
	Gerd Hoffmann

Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3593

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@redhat.com>
Reviewed-by: Philippe Mathieu-Daude <philmd@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


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

* [PATCH v2 2/3] OvmfPkg/PlatformPei: prefer etc/e820 for memory detection
  2021-08-26  9:55 [PATCH v2 0/3] OvmfPkg/PlatformPei: prefer etc/e820 for memory detection Gerd Hoffmann
  2021-08-26  9:55 ` [PATCH v2 1/3] OvmfPkg/PlatformPei: ScanOrAdd64BitE820Ram improvements Gerd Hoffmann
@ 2021-08-26  9:55 ` Gerd Hoffmann
  2021-08-26  9:55 ` [PATCH v2 3/3] RFC: OvmfPkg/PlatformPei: stop using cmos " Gerd Hoffmann
  2 siblings, 0 replies; 6+ messages in thread
From: Gerd Hoffmann @ 2021-08-26  9:55 UTC (permalink / raw)
  To: devel
  Cc: Ard Biesheuvel, Jiewen Yao, Jordan Justen, Philippe Mathieu-Daude,
	Gerd Hoffmann

Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3593

Prefer the e820 map provided via qemu firmware config interface
for memory detection.  Use rtc cmos only as fallback, which should
be rarely needed these days as qemu supports etc/e820 since 2013.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Reviewed-by: Philippe Mathieu-Daude <philmd@redhat.com>
---
 OvmfPkg/PlatformPei/MemDetect.c | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/OvmfPkg/PlatformPei/MemDetect.c b/OvmfPkg/PlatformPei/MemDetect.c
index d7fb3e742be3..20154255324b 100644
--- a/OvmfPkg/PlatformPei/MemDetect.c
+++ b/OvmfPkg/PlatformPei/MemDetect.c
@@ -293,9 +293,16 @@ GetSystemMemorySizeBelow4gb (
   VOID
   )
 {
+  EFI_STATUS Status;
+  UINT64 LowerMemorySize = 0;
   UINT8 Cmos0x34;
   UINT8 Cmos0x35;
 
+  Status = ScanOrAdd64BitE820Ram (FALSE, &LowerMemorySize, NULL);
+  if (Status == EFI_SUCCESS && LowerMemorySize > 0) {
+    return LowerMemorySize;
+  }
+
   //
   // CMOS 0x34/0x35 specifies the system memory above 16 MB.
   // * CMOS(0x35) is the high byte
@@ -722,7 +729,6 @@ QemuInitializeRam (
   // Determine total memory size available
   //
   LowerMemorySize = GetSystemMemorySizeBelow4gb ();
-  UpperMemorySize = GetSystemMemorySizeAbove4gb ();
 
   if (mBootMode == BOOT_ON_S3_RESUME) {
     //
@@ -769,8 +775,11 @@ QemuInitializeRam (
     // memory size read from the CMOS.
     //
     Status = ScanOrAdd64BitE820Ram (TRUE, NULL, NULL);
-    if (EFI_ERROR (Status) && UpperMemorySize != 0) {
-      AddMemoryBaseSizeHob (BASE_4GB, UpperMemorySize);
+    if (EFI_ERROR (Status)) {
+      UpperMemorySize = GetSystemMemorySizeAbove4gb ();
+      if (UpperMemorySize != 0) {
+        AddMemoryBaseSizeHob (BASE_4GB, UpperMemorySize);
+      }
     }
   }
 
-- 
2.31.1


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

* [PATCH v2 3/3] RFC: OvmfPkg/PlatformPei: stop using cmos for memory detection
  2021-08-26  9:55 [PATCH v2 0/3] OvmfPkg/PlatformPei: prefer etc/e820 for memory detection Gerd Hoffmann
  2021-08-26  9:55 ` [PATCH v2 1/3] OvmfPkg/PlatformPei: ScanOrAdd64BitE820Ram improvements Gerd Hoffmann
  2021-08-26  9:55 ` [PATCH v2 2/3] OvmfPkg/PlatformPei: prefer etc/e820 for memory detection Gerd Hoffmann
@ 2021-08-26  9:55 ` Gerd Hoffmann
  2021-08-26 11:15   ` Ard Biesheuvel
  2 siblings, 1 reply; 6+ messages in thread
From: Gerd Hoffmann @ 2021-08-26  9:55 UTC (permalink / raw)
  To: devel
  Cc: Ard Biesheuvel, Jiewen Yao, Jordan Justen, Philippe Mathieu-Daude,
	Gerd Hoffmann

Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3593

Not needed for qemu 1.7 (released in 2013) and newer.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 OvmfPkg/PlatformPei/MemDetect.c | 58 ++-------------------------------
 1 file changed, 3 insertions(+), 55 deletions(-)

diff --git a/OvmfPkg/PlatformPei/MemDetect.c b/OvmfPkg/PlatformPei/MemDetect.c
index 20154255324b..8d2c7f432472 100644
--- a/OvmfPkg/PlatformPei/MemDetect.c
+++ b/OvmfPkg/PlatformPei/MemDetect.c
@@ -37,7 +37,6 @@ Module Name:
 #include <Library/QemuFwCfgSimpleParserLib.h>
 
 #include "Platform.h"
-#include "Cmos.h"
 
 UINT8 mPhysMemAddressWidth;
 
@@ -295,52 +294,11 @@ GetSystemMemorySizeBelow4gb (
 {
   EFI_STATUS Status;
   UINT64 LowerMemorySize = 0;
-  UINT8 Cmos0x34;
-  UINT8 Cmos0x35;
 
   Status = ScanOrAdd64BitE820Ram (FALSE, &LowerMemorySize, NULL);
-  if (Status == EFI_SUCCESS && LowerMemorySize > 0) {
-    return LowerMemorySize;
-  }
+  ASSERT (Status == EFI_SUCCESS && LowerMemorySize > 0);
+  return LowerMemorySize;
 
-  //
-  // CMOS 0x34/0x35 specifies the system memory above 16 MB.
-  // * CMOS(0x35) is the high byte
-  // * CMOS(0x34) is the low byte
-  // * The size is specified in 64kb chunks
-  // * Since this is memory above 16MB, the 16MB must be added
-  //   into the calculation to get the total memory size.
-  //
-
-  Cmos0x34 = (UINT8) CmosRead8 (0x34);
-  Cmos0x35 = (UINT8) CmosRead8 (0x35);
-
-  return (UINT32) (((UINTN)((Cmos0x35 << 8) + Cmos0x34) << 16) + SIZE_16MB);
-}
-
-
-STATIC
-UINT64
-GetSystemMemorySizeAbove4gb (
-  )
-{
-  UINT32 Size;
-  UINTN  CmosIndex;
-
-  //
-  // CMOS 0x5b-0x5d specifies the system memory above 4GB MB.
-  // * CMOS(0x5d) is the most significant size byte
-  // * CMOS(0x5c) is the middle size byte
-  // * CMOS(0x5b) is the least significant size byte
-  // * The size is specified in 64kb chunks
-  //
-
-  Size = 0;
-  for (CmosIndex = 0x5d; CmosIndex >= 0x5b; CmosIndex--) {
-    Size = (UINT32) (Size << 8) + (UINT32) CmosRead8 (CmosIndex);
-  }
-
-  return LShiftU64 (Size, 16);
 }
 
 
@@ -371,12 +329,9 @@ GetFirstNonAddress (
   // If QEMU presents an E820 map, then get the highest exclusive >=4GB RAM
   // address from it. This can express an address >= 4GB+1TB.
   //
-  // 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 (FALSE, NULL, &FirstNonAddress);
   if (EFI_ERROR (Status)) {
-    FirstNonAddress = BASE_4GB + GetSystemMemorySizeAbove4gb ();
+    FirstNonAddress = BASE_4GB;
   }
 
   //
@@ -719,7 +674,6 @@ QemuInitializeRam (
   )
 {
   UINT64                      LowerMemorySize;
-  UINT64                      UpperMemorySize;
   MTRR_SETTINGS               MtrrSettings;
   EFI_STATUS                  Status;
 
@@ -775,12 +729,6 @@ QemuInitializeRam (
     // memory size read from the CMOS.
     //
     Status = ScanOrAdd64BitE820Ram (TRUE, NULL, NULL);
-    if (EFI_ERROR (Status)) {
-      UpperMemorySize = GetSystemMemorySizeAbove4gb ();
-      if (UpperMemorySize != 0) {
-        AddMemoryBaseSizeHob (BASE_4GB, UpperMemorySize);
-      }
-    }
   }
 
   //
-- 
2.31.1


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

* Re: [PATCH v2 3/3] RFC: OvmfPkg/PlatformPei: stop using cmos for memory detection
  2021-08-26  9:55 ` [PATCH v2 3/3] RFC: OvmfPkg/PlatformPei: stop using cmos " Gerd Hoffmann
@ 2021-08-26 11:15   ` Ard Biesheuvel
  2021-08-26 16:40     ` Yao, Jiewen
  0 siblings, 1 reply; 6+ messages in thread
From: Ard Biesheuvel @ 2021-08-26 11:15 UTC (permalink / raw)
  To: Gerd Hoffmann
  Cc: edk2-devel-groups-io, Ard Biesheuvel, Jiewen Yao, Jordan Justen,
	Philippe Mathieu-Daude

On Thu, 26 Aug 2021 at 11:55, Gerd Hoffmann <kraxel@redhat.com> wrote:
>
> Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3593
>
> Not needed for qemu 1.7 (released in 2013) and newer.
>
> Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
> ---
>  OvmfPkg/PlatformPei/MemDetect.c | 58 ++-------------------------------
>  1 file changed, 3 insertions(+), 55 deletions(-)
>
> diff --git a/OvmfPkg/PlatformPei/MemDetect.c b/OvmfPkg/PlatformPei/MemDetect.c
> index 20154255324b..8d2c7f432472 100644
> --- a/OvmfPkg/PlatformPei/MemDetect.c
> +++ b/OvmfPkg/PlatformPei/MemDetect.c
> @@ -37,7 +37,6 @@ Module Name:
>  #include <Library/QemuFwCfgSimpleParserLib.h>
>
>  #include "Platform.h"
> -#include "Cmos.h"
>
>  UINT8 mPhysMemAddressWidth;
>
> @@ -295,52 +294,11 @@ GetSystemMemorySizeBelow4gb (
>  {
>    EFI_STATUS Status;
>    UINT64 LowerMemorySize = 0;
> -  UINT8 Cmos0x34;
> -  UINT8 Cmos0x35;
>
>    Status = ScanOrAdd64BitE820Ram (FALSE, &LowerMemorySize, NULL);
> -  if (Status == EFI_SUCCESS && LowerMemorySize > 0) {
> -    return LowerMemorySize;
> -  }
> +  ASSERT (Status == EFI_SUCCESS && LowerMemorySize > 0);

Nit: better to do

ASSERT_EFI_ERROR (Status);
ASSERT (LowerMemorySize > 0);

so that you can tell from the debug log which condition triggered, and
if it is the first one, what the actual error code was.


> +  return LowerMemorySize;
>
> -  //
> -  // CMOS 0x34/0x35 specifies the system memory above 16 MB.
> -  // * CMOS(0x35) is the high byte
> -  // * CMOS(0x34) is the low byte
> -  // * The size is specified in 64kb chunks
> -  // * Since this is memory above 16MB, the 16MB must be added
> -  //   into the calculation to get the total memory size.
> -  //
> -
> -  Cmos0x34 = (UINT8) CmosRead8 (0x34);
> -  Cmos0x35 = (UINT8) CmosRead8 (0x35);
> -
> -  return (UINT32) (((UINTN)((Cmos0x35 << 8) + Cmos0x34) << 16) + SIZE_16MB);
> -}
> -
> -
> -STATIC
> -UINT64
> -GetSystemMemorySizeAbove4gb (
> -  )
> -{
> -  UINT32 Size;
> -  UINTN  CmosIndex;
> -
> -  //
> -  // CMOS 0x5b-0x5d specifies the system memory above 4GB MB.
> -  // * CMOS(0x5d) is the most significant size byte
> -  // * CMOS(0x5c) is the middle size byte
> -  // * CMOS(0x5b) is the least significant size byte
> -  // * The size is specified in 64kb chunks
> -  //
> -
> -  Size = 0;
> -  for (CmosIndex = 0x5d; CmosIndex >= 0x5b; CmosIndex--) {
> -    Size = (UINT32) (Size << 8) + (UINT32) CmosRead8 (CmosIndex);
> -  }
> -
> -  return LShiftU64 (Size, 16);
>  }
>
>
> @@ -371,12 +329,9 @@ GetFirstNonAddress (
>    // If QEMU presents an E820 map, then get the highest exclusive >=4GB RAM
>    // address from it. This can express an address >= 4GB+1TB.
>    //
> -  // 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 (FALSE, NULL, &FirstNonAddress);
>    if (EFI_ERROR (Status)) {
> -    FirstNonAddress = BASE_4GB + GetSystemMemorySizeAbove4gb ();
> +    FirstNonAddress = BASE_4GB;
>    }
>
>    //
> @@ -719,7 +674,6 @@ QemuInitializeRam (
>    )
>  {
>    UINT64                      LowerMemorySize;
> -  UINT64                      UpperMemorySize;
>    MTRR_SETTINGS               MtrrSettings;
>    EFI_STATUS                  Status;
>
> @@ -775,12 +729,6 @@ QemuInitializeRam (
>      // memory size read from the CMOS.
>      //
>      Status = ScanOrAdd64BitE820Ram (TRUE, NULL, NULL);
> -    if (EFI_ERROR (Status)) {
> -      UpperMemorySize = GetSystemMemorySizeAbove4gb ();
> -      if (UpperMemorySize != 0) {
> -        AddMemoryBaseSizeHob (BASE_4GB, UpperMemorySize);
> -      }
> -    }
>    }
>
>    //
> --
> 2.31.1
>

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

* Re: [PATCH v2 3/3] RFC: OvmfPkg/PlatformPei: stop using cmos for memory detection
  2021-08-26 11:15   ` Ard Biesheuvel
@ 2021-08-26 16:40     ` Yao, Jiewen
  0 siblings, 0 replies; 6+ messages in thread
From: Yao, Jiewen @ 2021-08-26 16:40 UTC (permalink / raw)
  To: Ard Biesheuvel, Gerd Hoffmann
  Cc: edk2-devel-groups-io, Ard Biesheuvel, Justen, Jordan L,
	Philippe Mathieu-Daude, Yao, Jiewen

Good idea, Ard.

> ASSERT_EFI_ERROR (Status);
> ASSERT (LowerMemorySize > 0);

I like this suggestion.


Thank you
Yao Jiewen


> -----Original Message-----
> From: Ard Biesheuvel <ardb@kernel.org>
> Sent: Thursday, August 26, 2021 7:15 PM
> To: Gerd Hoffmann <kraxel@redhat.com>
> Cc: edk2-devel-groups-io <devel@edk2.groups.io>; Ard Biesheuvel
> <ardb+tianocore@kernel.org>; Yao, Jiewen <jiewen.yao@intel.com>; Justen,
> Jordan L <jordan.l.justen@intel.com>; Philippe Mathieu-Daude
> <philmd@redhat.com>
> Subject: Re: [PATCH v2 3/3] RFC: OvmfPkg/PlatformPei: stop using cmos for
> memory detection
> 
> On Thu, 26 Aug 2021 at 11:55, Gerd Hoffmann <kraxel@redhat.com> wrote:
> >
> > Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3593
> >
> > Not needed for qemu 1.7 (released in 2013) and newer.
> >
> > Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
> > ---
> >  OvmfPkg/PlatformPei/MemDetect.c | 58 ++-------------------------------
> >  1 file changed, 3 insertions(+), 55 deletions(-)
> >
> > diff --git a/OvmfPkg/PlatformPei/MemDetect.c
> b/OvmfPkg/PlatformPei/MemDetect.c
> > index 20154255324b..8d2c7f432472 100644
> > --- a/OvmfPkg/PlatformPei/MemDetect.c
> > +++ b/OvmfPkg/PlatformPei/MemDetect.c
> > @@ -37,7 +37,6 @@ Module Name:
> >  #include <Library/QemuFwCfgSimpleParserLib.h>
> >
> >  #include "Platform.h"
> > -#include "Cmos.h"
> >
> >  UINT8 mPhysMemAddressWidth;
> >
> > @@ -295,52 +294,11 @@ GetSystemMemorySizeBelow4gb (
> >  {
> >    EFI_STATUS Status;
> >    UINT64 LowerMemorySize = 0;
> > -  UINT8 Cmos0x34;
> > -  UINT8 Cmos0x35;
> >
> >    Status = ScanOrAdd64BitE820Ram (FALSE, &LowerMemorySize, NULL);
> > -  if (Status == EFI_SUCCESS && LowerMemorySize > 0) {
> > -    return LowerMemorySize;
> > -  }
> > +  ASSERT (Status == EFI_SUCCESS && LowerMemorySize > 0);
> 
> Nit: better to do
> 
> ASSERT_EFI_ERROR (Status);
> ASSERT (LowerMemorySize > 0);
> 
> so that you can tell from the debug log which condition triggered, and
> if it is the first one, what the actual error code was.
> 
> 
> > +  return LowerMemorySize;
> >
> > -  //
> > -  // CMOS 0x34/0x35 specifies the system memory above 16 MB.
> > -  // * CMOS(0x35) is the high byte
> > -  // * CMOS(0x34) is the low byte
> > -  // * The size is specified in 64kb chunks
> > -  // * Since this is memory above 16MB, the 16MB must be added
> > -  //   into the calculation to get the total memory size.
> > -  //
> > -
> > -  Cmos0x34 = (UINT8) CmosRead8 (0x34);
> > -  Cmos0x35 = (UINT8) CmosRead8 (0x35);
> > -
> > -  return (UINT32) (((UINTN)((Cmos0x35 << 8) + Cmos0x34) << 16) +
> SIZE_16MB);
> > -}
> > -
> > -
> > -STATIC
> > -UINT64
> > -GetSystemMemorySizeAbove4gb (
> > -  )
> > -{
> > -  UINT32 Size;
> > -  UINTN  CmosIndex;
> > -
> > -  //
> > -  // CMOS 0x5b-0x5d specifies the system memory above 4GB MB.
> > -  // * CMOS(0x5d) is the most significant size byte
> > -  // * CMOS(0x5c) is the middle size byte
> > -  // * CMOS(0x5b) is the least significant size byte
> > -  // * The size is specified in 64kb chunks
> > -  //
> > -
> > -  Size = 0;
> > -  for (CmosIndex = 0x5d; CmosIndex >= 0x5b; CmosIndex--) {
> > -    Size = (UINT32) (Size << 8) + (UINT32) CmosRead8 (CmosIndex);
> > -  }
> > -
> > -  return LShiftU64 (Size, 16);
> >  }
> >
> >
> > @@ -371,12 +329,9 @@ GetFirstNonAddress (
> >    // If QEMU presents an E820 map, then get the highest exclusive >=4GB RAM
> >    // address from it. This can express an address >= 4GB+1TB.
> >    //
> > -  // 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 (FALSE, NULL, &FirstNonAddress);
> >    if (EFI_ERROR (Status)) {
> > -    FirstNonAddress = BASE_4GB + GetSystemMemorySizeAbove4gb ();
> > +    FirstNonAddress = BASE_4GB;
> >    }
> >
> >    //
> > @@ -719,7 +674,6 @@ QemuInitializeRam (
> >    )
> >  {
> >    UINT64                      LowerMemorySize;
> > -  UINT64                      UpperMemorySize;
> >    MTRR_SETTINGS               MtrrSettings;
> >    EFI_STATUS                  Status;
> >
> > @@ -775,12 +729,6 @@ QemuInitializeRam (
> >      // memory size read from the CMOS.
> >      //
> >      Status = ScanOrAdd64BitE820Ram (TRUE, NULL, NULL);
> > -    if (EFI_ERROR (Status)) {
> > -      UpperMemorySize = GetSystemMemorySizeAbove4gb ();
> > -      if (UpperMemorySize != 0) {
> > -        AddMemoryBaseSizeHob (BASE_4GB, UpperMemorySize);
> > -      }
> > -    }
> >    }
> >
> >    //
> > --
> > 2.31.1
> >

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

end of thread, other threads:[~2021-08-26 16:40 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-08-26  9:55 [PATCH v2 0/3] OvmfPkg/PlatformPei: prefer etc/e820 for memory detection Gerd Hoffmann
2021-08-26  9:55 ` [PATCH v2 1/3] OvmfPkg/PlatformPei: ScanOrAdd64BitE820Ram improvements Gerd Hoffmann
2021-08-26  9:55 ` [PATCH v2 2/3] OvmfPkg/PlatformPei: prefer etc/e820 for memory detection Gerd Hoffmann
2021-08-26  9:55 ` [PATCH v2 3/3] RFC: OvmfPkg/PlatformPei: stop using cmos " Gerd Hoffmann
2021-08-26 11:15   ` Ard Biesheuvel
2021-08-26 16:40     ` Yao, Jiewen

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