From: "Gerd Hoffmann" <kraxel@redhat.com>
To: devel@edk2.groups.io
Cc: "Philippe Mathieu-Daudé" <philmd@redhat.com>,
"Ard Biesheuvel" <ardb+tianocore@kernel.org>,
"Pawel Polawski" <ppolawsk@redhat.com>,
"Jordan Justen" <jordan.l.justen@intel.com>,
"Jiewen Yao" <jiewen.yao@intel.com>,
"Gerd Hoffmann" <kraxel@redhat.com>
Subject: [PATCH v4 1/3] OvmfPkg/PlatformPei: ScanOrAdd64BitE820Ram improvements
Date: Wed, 8 Dec 2021 08:01:44 +0100 [thread overview]
Message-ID: <20211208070146.1239368-2-kraxel@redhat.com> (raw)
In-Reply-To: <20211208070146.1239368-1-kraxel@redhat.com>
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 | 32 ++++++++++++++++++++++++--------
1 file changed, 24 insertions(+), 8 deletions(-)
diff --git a/OvmfPkg/PlatformPei/MemDetect.c b/OvmfPkg/PlatformPei/MemDetect.c
index 3f59a1ac79f6..912889ab9b75 100644
--- a/OvmfPkg/PlatformPei/MemDetect.c
+++ b/OvmfPkg/PlatformPei/MemDetect.c
@@ -216,6 +216,8 @@ QemuUc32BaseInitialization (
STATIC
EFI_STATUS
ScanOrAdd64BitE820Ram (
+ IN BOOLEAN AddHighHob,
+ OUT UINT64 *LowMemory OPTIONAL,
OUT UINT64 *MaxAddress OPTIONAL
)
{
@@ -234,6 +236,10 @@ ScanOrAdd64BitE820Ram (
return EFI_PROTOCOL_ERROR;
}
+ if (LowMemory != NULL) {
+ *LowMemory = 0;
+ }
+
if (MaxAddress != NULL) {
*MaxAddress = BASE_4GB;
}
@@ -249,10 +255,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;
@@ -272,11 +276,13 @@ 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,
@@ -285,6 +291,16 @@ ScanOrAdd64BitE820Ram (
*MaxAddress
));
}
+
+ if (LowMemory && (Candidate > *LowMemory) && (Candidate < BASE_4GB)) {
+ *LowMemory = Candidate;
+ DEBUG ((
+ DEBUG_VERBOSE,
+ "%a: LowMemory=0x%Lx\n",
+ __FUNCTION__,
+ *LowMemory
+ ));
+ }
}
}
}
@@ -369,7 +385,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 ();
}
@@ -802,7 +818,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.33.1
next prev parent reply other threads:[~2021-12-08 7:02 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-12-08 7:01 [PATCH v4 0/3] OvmfPkg/PlatformPei: prefer etc/e820 for memory detection Gerd Hoffmann
2021-12-08 7:01 ` Gerd Hoffmann [this message]
2021-12-08 7:01 ` [PATCH v4 2/3] " Gerd Hoffmann
2021-12-08 7:01 ` [PATCH v4 3/3] RFC: OvmfPkg/PlatformPei: stop using cmos " Gerd Hoffmann
2021-12-13 11:55 ` Ard Biesheuvel
2021-12-13 15:01 ` [PATCH v4 0/3] OvmfPkg/PlatformPei: prefer etc/e820 " Ard Biesheuvel
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-list from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20211208070146.1239368-2-kraxel@redhat.com \
--to=devel@edk2.groups.io \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox