OvmfPkg/XenPlatformPei: Rework memory detection

When running as a Xen PVH guest, there is no CMOS to read the memory
size from.  Rework GetSystemMemorySize(Below|Above)4gb() so they can
work without CMOS by reading the e820 table.

Rework XenPublishRamRegions to also care for the reserved and ACPI
entry in the e820 table. The region that was added by InitializeXen()
isn't needed as that same entry is in the e820 table provided by
hvmloader.

MTRR settings aren't modified anymore, on HVM it's already done by
hvmloader, on PVH it is supposed to have sane default. MTRR will need
to be done properly but keeping what's already been done by programs
that have run before OVMF will do for now.

Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=1689
Signed-off-by: Anthony PERARD <anthony.perard@citrix.com>
Acked-by: Laszlo Ersek <lersek@redhat.com>
Message-Id: <20190813113119.14804-24-anthony.perard@citrix.com>
This commit is contained in:
Anthony PERARD
2019-08-13 12:31:07 +01:00
committed by Laszlo Ersek
parent a749e1f93b
commit 24465c380a
4 changed files with 147 additions and 21 deletions

View File

@@ -96,6 +96,45 @@ Q35TsegMbytesInitialization (
mQ35TsegMbytes = ExtendedTsegMbytes;
}
STATIC
UINT64
GetHighestSystemMemoryAddress (
BOOLEAN Below4gb
)
{
EFI_E820_ENTRY64 *E820Map;
UINT32 E820EntriesCount;
EFI_E820_ENTRY64 *Entry;
EFI_STATUS Status;
UINT32 Loop;
UINT64 HighestAddress;
UINT64 EntryEnd;
HighestAddress = 0;
Status = XenGetE820Map (&E820Map, &E820EntriesCount);
ASSERT_EFI_ERROR (Status);
for (Loop = 0; Loop < E820EntriesCount; Loop++) {
Entry = E820Map + Loop;
EntryEnd = Entry->BaseAddr + Entry->Length;
if (Entry->Type == EfiAcpiAddressRangeMemory &&
EntryEnd > HighestAddress) {
if (Below4gb && (EntryEnd <= BASE_4GB)) {
HighestAddress = EntryEnd;
} else if (!Below4gb && (EntryEnd >= BASE_4GB)) {
HighestAddress = EntryEnd;
}
}
}
//
// Round down the end address.
//
return HighestAddress & ~(UINT64)EFI_PAGE_MASK;
}
UINT32
GetSystemMemorySizeBelow4gb (
@@ -105,6 +144,19 @@ GetSystemMemorySizeBelow4gb (
UINT8 Cmos0x34;
UINT8 Cmos0x35;
//
// In PVH case, there is no CMOS, we have to calculate the memory size
// from parsing the E820
//
if (XenPvhDetected ()) {
UINT64 HighestAddress;
HighestAddress = GetHighestSystemMemoryAddress (TRUE);
ASSERT (HighestAddress > 0 && HighestAddress <= BASE_4GB);
return HighestAddress;
}
//
// CMOS 0x34/0x35 specifies the system memory above 16 MB.
// * CMOS(0x35) is the high byte
@@ -129,6 +181,23 @@ GetSystemMemorySizeAbove4gb (
UINT32 Size;
UINTN CmosIndex;
//
// In PVH case, there is no CMOS, we have to calculate the memory size
// from parsing the E820
//
if (XenPvhDetected ()) {
UINT64 HighestAddress;
HighestAddress = GetHighestSystemMemoryAddress (FALSE);
ASSERT (HighestAddress == 0 || HighestAddress >= BASE_4GB);
if (HighestAddress >= BASE_4GB) {
HighestAddress -= BASE_4GB;
}
return HighestAddress;
}
//
// CMOS 0x5b-0x5d specifies the system memory above 4GB MB.
// * CMOS(0x5d) is the most significant size byte