OvmfPkg/PlatformPei: parse "X-PciMmio64Mb" with QemuFwCfgSimpleParserLib

Replace the

- QemuFwCfgFindFile(),
- QemuFwCfgSelectItem(),
- QemuFwCfgReadBytes(),
- AsciiStrDecimalToUint64()

sequence in the GetFirstNonAddress() function with a call to
QemuFwCfgSimpleParserLib.

This change is compatible with valid strings accepted previously.

Cc: Ard Biesheuvel <ard.biesheuvel@arm.com>
Cc: Jordan Justen <jordan.l.justen@intel.com>
Cc: Per Sundstrom <per_sundstrom@yahoo.com>
Cc: Philippe Mathieu-Daudé <philmd@redhat.com>
Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=2681
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
Message-Id: <20200424075353.8489-3-lersek@redhat.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Reviewed-by: Ard Biesheuvel <ard.biesheuvel@arm.com>
This commit is contained in:
Laszlo Ersek 2020-04-24 09:53:48 +02:00 committed by mergify[bot]
parent 611c7f1101
commit 98800cce65
2 changed files with 22 additions and 15 deletions

View File

@ -33,6 +33,7 @@ Module Name:
#include <Library/ResourcePublicationLib.h> #include <Library/ResourcePublicationLib.h>
#include <Library/MtrrLib.h> #include <Library/MtrrLib.h>
#include <Library/QemuFwCfgLib.h> #include <Library/QemuFwCfgLib.h>
#include <Library/QemuFwCfgSimpleParserLib.h>
#include "Platform.h" #include "Platform.h"
#include "Cmos.h" #include "Cmos.h"
@ -336,7 +337,7 @@ GetFirstNonAddress (
{ {
UINT64 FirstNonAddress; UINT64 FirstNonAddress;
UINT64 Pci64Base, Pci64Size; UINT64 Pci64Base, Pci64Size;
CHAR8 MbString[7 + 1]; UINT32 FwCfgPciMmio64Mb;
EFI_STATUS Status; EFI_STATUS Status;
FIRMWARE_CONFIG_ITEM FwCfgItem; FIRMWARE_CONFIG_ITEM FwCfgItem;
UINTN FwCfgSize; UINTN FwCfgSize;
@ -379,25 +380,30 @@ GetFirstNonAddress (
// //
// See if the user specified the number of megabytes for the 64-bit PCI host // See if the user specified the number of megabytes for the 64-bit PCI host
// aperture. The number of non-NUL characters in MbString allows for // aperture. Accept an aperture size up to 16TB.
// 9,999,999 MB, which is approximately 10 TB.
// //
// As signaled by the "X-" prefix, this knob is experimental, and might go // As signaled by the "X-" prefix, this knob is experimental, and might go
// away at any time. // away at any time.
// //
Status = QemuFwCfgFindFile ("opt/ovmf/X-PciMmio64Mb", &FwCfgItem, Status = QemuFwCfgParseUint32 ("opt/ovmf/X-PciMmio64Mb", FALSE,
&FwCfgSize); &FwCfgPciMmio64Mb);
if (!EFI_ERROR (Status)) { switch (Status) {
if (FwCfgSize >= sizeof MbString) { case EFI_UNSUPPORTED:
DEBUG ((EFI_D_WARN, case EFI_NOT_FOUND:
"%a: ignoring malformed 64-bit PCI host aperture size from fw_cfg\n", break;
__FUNCTION__)); case EFI_SUCCESS:
} else { if (FwCfgPciMmio64Mb <= 0x1000000) {
QemuFwCfgSelectItem (FwCfgItem); Pci64Size = LShiftU64 (FwCfgPciMmio64Mb, 20);
QemuFwCfgReadBytes (FwCfgSize, MbString); break;
MbString[FwCfgSize] = '\0';
Pci64Size = LShiftU64 (AsciiStrDecimalToUint64 (MbString), 20);
} }
//
// fall through
//
default:
DEBUG ((DEBUG_WARN,
"%a: ignoring malformed 64-bit PCI host aperture size from fw_cfg\n",
__FUNCTION__));
break;
} }
if (Pci64Size == 0) { if (Pci64Size == 0) {

View File

@ -60,6 +60,7 @@
PeimEntryPoint PeimEntryPoint
QemuFwCfgLib QemuFwCfgLib
QemuFwCfgS3Lib QemuFwCfgS3Lib
QemuFwCfgSimpleParserLib
MtrrLib MtrrLib
MemEncryptSevLib MemEncryptSevLib
PcdLib PcdLib