summaryrefslogtreecommitdiffstats
path: root/OvmfPkg/XenPlatformPei/Xen.c
diff options
context:
space:
mode:
authorAnthony PERARD <anthony.perard@citrix.com>2019-08-13 12:31:07 +0100
committerLaszlo Ersek <lersek@redhat.com>2019-08-21 18:03:49 +0200
commit24465c380a3e6fb90f9efaf03184b658059e4ccd (patch)
treef3e1e7081bea0d115d797caf8a342df8c57a751d /OvmfPkg/XenPlatformPei/Xen.c
parenta749e1f93be67a799fcfb437253a533e462b90ee (diff)
downloadedk2-24465c380a3e6fb90f9efaf03184b658059e4ccd.tar.gz
edk2-24465c380a3e6fb90f9efaf03184b658059e4ccd.tar.bz2
edk2-24465c380a3e6fb90f9efaf03184b658059e4ccd.zip
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>
Diffstat (limited to 'OvmfPkg/XenPlatformPei/Xen.c')
-rw-r--r--OvmfPkg/XenPlatformPei/Xen.c77
1 files changed, 55 insertions, 22 deletions
diff --git a/OvmfPkg/XenPlatformPei/Xen.c b/OvmfPkg/XenPlatformPei/Xen.c
index 72f6f37b46..c4506def9a 100644
--- a/OvmfPkg/XenPlatformPei/Xen.c
+++ b/OvmfPkg/XenPlatformPei/Xen.c
@@ -276,9 +276,14 @@ XenPublishRamRegions (
VOID
)
{
- EFI_E820_ENTRY64 *E820Map;
- UINT32 E820EntriesCount;
- EFI_STATUS Status;
+ EFI_E820_ENTRY64 *E820Map;
+ UINT32 E820EntriesCount;
+ EFI_STATUS Status;
+ EFI_E820_ENTRY64 *Entry;
+ UINTN Index;
+ UINT64 LapicBase;
+ UINT64 LapicEnd;
+
DEBUG ((DEBUG_INFO, "Using memory map provided by Xen\n"));
@@ -287,26 +292,60 @@ XenPublishRamRegions (
//
E820EntriesCount = 0;
Status = XenGetE820Map (&E820Map, &E820EntriesCount);
-
ASSERT_EFI_ERROR (Status);
- if (E820EntriesCount > 0) {
- EFI_E820_ENTRY64 *Entry;
- UINT32 Loop;
-
- for (Loop = 0; Loop < E820EntriesCount; Loop++) {
- Entry = E820Map + Loop;
+ LapicBase = PcdGet32 (PcdCpuLocalApicBaseAddress);
+ LapicEnd = LapicBase + SIZE_1MB;
+ AddIoMemoryRangeHob (LapicBase, LapicEnd);
+
+ for (Index = 0; Index < E820EntriesCount; Index++) {
+ UINT64 Base;
+ UINT64 End;
+ UINT64 ReservedBase;
+ UINT64 ReservedEnd;
+
+ Entry = &E820Map[Index];
+
+ //
+ // Round up the start address, and round down the end address.
+ //
+ Base = ALIGN_VALUE (Entry->BaseAddr, (UINT64)EFI_PAGE_SIZE);
+ End = (Entry->BaseAddr + Entry->Length) & ~(UINT64)EFI_PAGE_MASK;
+
+ switch (Entry->Type) {
+ case EfiAcpiAddressRangeMemory:
+ AddMemoryRangeHob (Base, End);
+ break;
+ case EfiAcpiAddressRangeACPI:
+ AddReservedMemoryRangeHob (Base, End, FALSE);
+ break;
+ case EfiAcpiAddressRangeReserved:
+ //
+ // hvmloader marks a range that overlaps with the local APIC memory
+ // mapped region as reserved, but CpuDxe wants it as mapped IO. We
+ // have already added it as mapped IO, so skip it here.
+ //
//
- // Only care about RAM
+ // add LAPIC predecessor range, if any
//
- if (Entry->Type != EfiAcpiAddressRangeMemory) {
- continue;
+ ReservedBase = Base;
+ ReservedEnd = MIN (End, LapicBase);
+ if (ReservedBase < ReservedEnd) {
+ AddReservedMemoryRangeHob (ReservedBase, ReservedEnd, FALSE);
}
- AddMemoryBaseSizeHob (Entry->BaseAddr, Entry->Length);
-
- MtrrSetMemoryAttribute (Entry->BaseAddr, Entry->Length, CacheWriteBack);
+ //
+ // add LAPIC successor range, if any
+ //
+ ReservedBase = MAX (Base, LapicEnd);
+ ReservedEnd = End;
+ if (ReservedBase < ReservedEnd) {
+ AddReservedMemoryRangeHob (ReservedBase, ReservedEnd, FALSE);
+ }
+ break;
+ default:
+ break;
}
}
}
@@ -326,12 +365,6 @@ InitializeXen (
{
RETURN_STATUS PcdStatus;
- //
- // Reserve away HVMLOADER reserved memory [0xFC000000,0xFD000000).
- // This needs to match HVMLOADER RESERVED_MEMBASE/RESERVED_MEMSIZE.
- //
- AddReservedMemoryBaseSizeHob (0xFC000000, 0x1000000, FALSE);
-
PcdStatus = PcdSetBoolS (PcdPciDisableBusEnumeration, TRUE);
ASSERT_RETURN_ERROR (PcdStatus);