From: "Ard Biesheuvel" <ardb@kernel.org>
To: Laszlo Ersek <lersek@redhat.com>
Cc: Gerd Hoffmann <kraxel@redhat.com>,
devel@edk2.groups.io, Jiewen Yao <jiewen.yao@intel.com>,
Oliver Steffen <osteffen@redhat.com>,
Ard Biesheuvel <ardb+tianocore@kernel.org>,
Pawel Polawski <ppolawsk@redhat.com>,
Jordan Justen <jordan.l.justen@intel.com>
Subject: Re: [PATCH v4 3/5] OvmfPkg/PlatformInitLib: Add PlatformAddHobCB
Date: Tue, 17 Jan 2023 16:06:11 +0100 [thread overview]
Message-ID: <CAMj1kXF6pGgYs9zzu6joRxcDaBP2bfZSBbgLveg16B2Nt2gZOw@mail.gmail.com> (raw)
In-Reply-To: <64b79c1e-dc09-75d1-3345-4620ffe63629@redhat.com>
On Tue, 17 Jan 2023 at 16:03, Laszlo Ersek <lersek@redhat.com> wrote:
>
> On 1/17/23 13:16, Gerd Hoffmann wrote:
> > Add PlatformAddHobCB() callback function for use with
> > PlatformScanE820(). It adds HOBs for high memory and reservations (low
> > memory is handled elsewhere because there are some special cases to
> > consider). This replaces calls to PlatformScanOrAdd64BitE820Ram() with
> > AddHighHobs = TRUE.
> >
> > Write any actions done (adding HOBs, skip unknown types) to the firmware
> > log with INFO loglevel.
> >
> > Also remove PlatformScanOrAdd64BitE820Ram() which is not used any more.
> >
> > Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
> > ---
> > OvmfPkg/Library/PlatformInitLib/MemDetect.c | 185 +++++---------------
> > 1 file changed, 47 insertions(+), 138 deletions(-)
> >
> > diff --git a/OvmfPkg/Library/PlatformInitLib/MemDetect.c b/OvmfPkg/Library/PlatformInitLib/MemDetect.c
> > index dfaa05a1c24f..c626fc49cf6c 100644
> > --- a/OvmfPkg/Library/PlatformInitLib/MemDetect.c
> > +++ b/OvmfPkg/Library/PlatformInitLib/MemDetect.c
> > @@ -112,143 +112,6 @@ PlatformQemuUc32BaseInitialization (
> > }
> > }
> >
> > -/**
> > - Iterate over the RAM entries in QEMU's fw_cfg E820 RAM map that start outside
> > - of the 32-bit address range.
> > -
> > - Find the highest exclusive >=4GB RAM address, or produce memory resource
> > - descriptor HOBs for RAM entries that start at or above 4GB.
> > -
> > - @param[out] MaxAddress If MaxAddress is NULL, then PlatformScanOrAdd64BitE820Ram()
> > - produces memory resource descriptor HOBs for RAM
> > - entries that start at or above 4GB.
> > -
> > - Otherwise, MaxAddress holds the highest exclusive
> > - >=4GB RAM address on output. If QEMU's fw_cfg E820
> > - RAM map contains no RAM entry that starts outside of
> > - the 32-bit address range, then MaxAddress is exactly
> > - 4GB on output.
> > -
> > - @retval EFI_SUCCESS The fw_cfg E820 RAM map was found and processed.
> > -
> > - @retval EFI_PROTOCOL_ERROR The RAM map was found, but its size wasn't a
> > - whole multiple of sizeof(EFI_E820_ENTRY64). No
> > - RAM entry was processed.
> > -
> > - @return Error codes from QemuFwCfgFindFile(). No RAM
> > - entry was processed.
> > -**/
> > -STATIC
> > -EFI_STATUS
> > -PlatformScanOrAdd64BitE820Ram (
> > - IN BOOLEAN AddHighHob,
> > - OUT UINT64 *LowMemory OPTIONAL,
> > - OUT UINT64 *MaxAddress OPTIONAL
> > - )
> > -{
> > - EFI_STATUS Status;
> > - FIRMWARE_CONFIG_ITEM FwCfgItem;
> > - UINTN FwCfgSize;
> > - EFI_E820_ENTRY64 E820Entry;
> > - UINTN Processed;
> > -
> > - Status = QemuFwCfgFindFile ("etc/e820", &FwCfgItem, &FwCfgSize);
> > - if (EFI_ERROR (Status)) {
> > - return Status;
> > - }
> > -
> > - if (FwCfgSize % sizeof E820Entry != 0) {
> > - return EFI_PROTOCOL_ERROR;
> > - }
> > -
> > - if (LowMemory != NULL) {
> > - *LowMemory = 0;
> > - }
> > -
> > - if (MaxAddress != NULL) {
> > - *MaxAddress = BASE_4GB;
> > - }
> > -
> > - QemuFwCfgSelectItem (FwCfgItem);
> > - for (Processed = 0; Processed < FwCfgSize; Processed += sizeof E820Entry) {
> > - QemuFwCfgReadBytes (sizeof E820Entry, &E820Entry);
> > - DEBUG ((
> > - DEBUG_VERBOSE,
> > - "%a: Base=0x%Lx Length=0x%Lx Type=%u\n",
> > - __FUNCTION__,
> > - E820Entry.BaseAddr,
> > - E820Entry.Length,
> > - E820Entry.Type
> > - ));
> > - if (E820Entry.Type == EfiAcpiAddressRangeMemory) {
> > - if (AddHighHob && (E820Entry.BaseAddr >= BASE_4GB)) {
> > - UINT64 Base;
> > - UINT64 End;
> > -
> > - //
> > - // Round up the start address, and round down the end address.
> > - //
> > - Base = ALIGN_VALUE (E820Entry.BaseAddr, (UINT64)EFI_PAGE_SIZE);
> > - End = (E820Entry.BaseAddr + E820Entry.Length) &
> > - ~(UINT64)EFI_PAGE_MASK;
> > - if (Base < End) {
> > - PlatformAddMemoryRangeHob (Base, End);
> > - DEBUG ((
> > - DEBUG_VERBOSE,
> > - "%a: PlatformAddMemoryRangeHob [0x%Lx, 0x%Lx)\n",
> > - __FUNCTION__,
> > - Base,
> > - End
> > - ));
> > - }
> > - }
> > -
> > - if (MaxAddress || LowMemory) {
> > - UINT64 Candidate;
> > -
> > - Candidate = E820Entry.BaseAddr + E820Entry.Length;
> > - if (MaxAddress && (Candidate > *MaxAddress)) {
> > - *MaxAddress = Candidate;
> > - DEBUG ((
> > - DEBUG_VERBOSE,
> > - "%a: MaxAddress=0x%Lx\n",
> > - __FUNCTION__,
> > - *MaxAddress
> > - ));
> > - }
> > -
> > - if (LowMemory && (Candidate > *LowMemory) && (Candidate < BASE_4GB)) {
> > - *LowMemory = Candidate;
> > - DEBUG ((
> > - DEBUG_VERBOSE,
> > - "%a: LowMemory=0x%Lx\n",
> > - __FUNCTION__,
> > - *LowMemory
> > - ));
> > - }
> > - }
> > - } else if (E820Entry.Type == EfiAcpiAddressRangeReserved) {
> > - if (AddHighHob) {
> > - DEBUG ((
> > - DEBUG_INFO,
> > - "%a: Reserved: Base=0x%Lx Length=0x%Lx\n",
> > - __FUNCTION__,
> > - E820Entry.BaseAddr,
> > - E820Entry.Length
> > - ));
> > - BuildResourceDescriptorHob (
> > - EFI_RESOURCE_MEMORY_RESERVED,
> > - 0,
> > - E820Entry.BaseAddr,
> > - E820Entry.Length
> > - );
> > - }
> > - }
> > - }
> > -
> > - return EFI_SUCCESS;
> > -}
> > -
> > typedef VOID (*E820_SCAN_CALLBACK) (
> > EFI_E820_ENTRY64 *E820Entry,
> > EFI_HOB_PLATFORM_INFO *PlatformInfoHob
> > @@ -304,6 +167,52 @@ PlatformGetLowMemoryCB (
> > }
> > }
> >
> > +/**
> > + Create HOBs for reservations and RAM (except low memory).
> > +**/
> > +STATIC VOID
> > +PlatformAddHobCB (
> > + IN EFI_E820_ENTRY64 *E820Entry,
> > + IN OUT EFI_HOB_PLATFORM_INFO *PlatformInfoHob
> > + )
> > +{
> > + UINT64 Base, End;
> > +
> > + Base = E820Entry->BaseAddr;
> > + End = E820Entry->BaseAddr + E820Entry->Length;
> > +
> > + switch (E820Entry->Type) {
> > + case EfiAcpiAddressRangeMemory:
> > + if (Base >= BASE_4GB) {
> > + //
> > + // Round up the start address, and round down the end address.
> > + //
> > + Base = ALIGN_VALUE (Base, (UINT64)EFI_PAGE_SIZE);
> > + End = End & ~(UINT64)EFI_PAGE_MASK;
> > + if (Base < End) {
> > + DEBUG ((DEBUG_INFO, "%a: HighMemory [0x%Lx, 0x%Lx)\n", __FUNCTION__, Base, End-1));
>
> (1) Hehe, this is a bit funny: we now have *both* the round closing
> parenthesies ")" in the debug message, for the interval, *and* (End-1)
> as the argument! :)
>
> We need exactly one of those. Either-or. :) If the argument is exclusive
> ("End"), then the interval should be closed with ")". If the arg is
> inclusive ("End-1"), then we need a bracket "]".
>
> > + PlatformAddMemoryRangeHob (Base, End);
> > + }
> > + }
> > +
>
> (2) Still not sure if this empty line is intentional (it may be, you
> didn't answer it under the v2 review AFAICT).
>
> > + break;
> > + case EfiAcpiAddressRangeReserved:
> > + BuildResourceDescriptorHob (EFI_RESOURCE_MEMORY_RESERVED, 0, Base, End);
> > + DEBUG ((DEBUG_INFO, "%a: Reserved [0x%Lx, 0x%Lx)\n", __FUNCTION__, Base, End-1));
>
> (3) Same comment as (1) -- please pick either End-1 as arg, with "]", or
> ")" as interval closing character, with End as arg.
>
> > + break;
> > + default:
> > + DEBUG ((
> > + DEBUG_WARN,
> > + "%a: Type %u [0x%Lx, 0x%Lx) (NOT HANDLED)\n",
> > + __FUNCTION__,
> > + E820Entry->Type,
> > + Base,
> > + End-1
> > + ));
> > + break;
> > + }
>
> (4) Same as (1).
>
> > +}
> > +
> > /**
> > Iterate over the entries in QEMU's fw_cfg E820 RAM map, call the
> > passed callback for each entry.
> > @@ -1049,7 +958,7 @@ PlatformQemuInitializeRam (
> > // entries. Otherwise, create a single memory HOB with the flat >=4GB
> > // memory size read from the CMOS.
> > //
> > - Status = PlatformScanOrAdd64BitE820Ram (TRUE, NULL, NULL);
> > + Status = PlatformScanE820 (PlatformAddHobCB, PlatformInfoHob);
> > if (EFI_ERROR (Status)) {
> > UpperMemorySize = PlatformGetSystemMemorySizeAbove4gb ();
> > if (UpperMemorySize != 0) {
>
> Update as you see fit, either way:
>
> Reviewed-by: Laszlo Ersek <lersek@redhat.com>
>
Thanks Laszlo - I'll fix up the above locally.
next prev parent reply other threads:[~2023-01-17 15:06 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-01-17 12:16 [PATCH v4 0/5] OvmfPkg: check 64bit mmio window for resource conflicts Gerd Hoffmann
2023-01-17 12:16 ` [PATCH v4 1/5] OvmfPkg/PlatformInitLib: Add PlatformScanE820 and GetFirstNonAddressCB Gerd Hoffmann
2023-01-17 14:30 ` Laszlo Ersek
2023-01-17 14:46 ` Laszlo Ersek
2023-01-17 14:48 ` [edk2-devel] " Ard Biesheuvel
2023-01-17 12:16 ` [PATCH v4 2/5] OvmfPkg/PlatformInitLib: Add PlatformGetLowMemoryCB Gerd Hoffmann
2023-01-17 14:45 ` Laszlo Ersek
2023-01-17 12:16 ` [PATCH v4 3/5] OvmfPkg/PlatformInitLib: Add PlatformAddHobCB Gerd Hoffmann
2023-01-17 15:00 ` Laszlo Ersek
2023-01-17 15:06 ` Ard Biesheuvel [this message]
2023-01-17 16:04 ` Ard Biesheuvel
2023-01-24 22:33 ` [edk2-devel] " Lendacky, Thomas
2023-01-25 9:11 ` Gerd Hoffmann
2023-01-25 15:35 ` Lendacky, Thomas
2023-01-25 16:32 ` Lendacky, Thomas
2023-01-30 15:23 ` Laszlo Ersek
2023-01-30 15:24 ` Laszlo Ersek
2023-01-17 12:16 ` [PATCH v4 4/5] OvmfPkg/PlatformInitLib: Add PlatformReservationConflictCB Gerd Hoffmann
2023-01-17 15:05 ` Laszlo Ersek
2023-01-17 12:16 ` [PATCH v4 5/5] OvmfPkg/PlatformInitLib: reorder PlatformQemuUc32BaseInitialization Gerd Hoffmann
2023-01-17 14:49 ` Laszlo Ersek
2023-01-17 16:38 ` [edk2-devel] [PATCH v4 0/5] OvmfPkg: check 64bit mmio window for resource conflicts 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=CAMj1kXF6pGgYs9zzu6joRxcDaBP2bfZSBbgLveg16B2Nt2gZOw@mail.gmail.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