Skip to content

Commit

Permalink
OvmfPkg/XenPlatformPei: no hvmloader: get the E820 table via hypercall
Browse files Browse the repository at this point in the history
When the Xen PVH entry point has been used, hvmloader hasn't run and
hasn't prepared an E820 table. The only way left to get an E820 table
is to ask Xen via an hypercall.  We keep the result cached to avoid
making a second hypercall which would give the same result.

Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=1689
Signed-off-by: Anthony PERARD <[email protected]>
Acked-by: Laszlo Ersek <[email protected]>
Message-Id: <[email protected]>
  • Loading branch information
anthonyper-ctx authored and lersek committed Aug 21, 2019
1 parent 23f9374 commit a749e1f
Showing 1 changed file with 45 additions and 1 deletion.
46 changes: 45 additions & 1 deletion OvmfPkg/XenPlatformPei/Xen.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include <Library/MtrrLib.h>
#include <IndustryStandard/Xen/arch-x86/hvm/start_info.h>
#include <Library/XenHypercallLib.h>
#include <IndustryStandard/Xen/memory.h>

#include "Platform.h"
#include "Xen.h"
Expand All @@ -40,6 +41,8 @@ EFI_XEN_INFO mXenInfo;
// Only the E820 table is used by OVMF.
//
EFI_XEN_OVMF_INFO *mXenHvmloaderInfo;
STATIC EFI_E820_ENTRY64 mE820Entries[128];
STATIC UINT32 mE820EntriesCount;

/**
Returns E820 map provided by Xen
Expand All @@ -55,6 +58,12 @@ XenGetE820Map (
UINT32 *Count
)
{
INTN ReturnCode;
xen_memory_map_t Parameters;
UINTN LoopIndex;
UINTN Index;
EFI_E820_ENTRY64 TmpEntry;

//
// Get E820 produced by hvmloader
//
Expand All @@ -66,7 +75,42 @@ XenGetE820Map (
return EFI_SUCCESS;
}

return EFI_NOT_FOUND;
//
// Otherwise, get the E820 table from the Xen hypervisor
//

if (mE820EntriesCount > 0) {
*Entries = mE820Entries;
*Count = mE820EntriesCount;
return EFI_SUCCESS;
}

Parameters.nr_entries = 128;
set_xen_guest_handle (Parameters.buffer, mE820Entries);

// Returns a errno
ReturnCode = XenHypercallMemoryOp (XENMEM_memory_map, &Parameters);
ASSERT (ReturnCode == 0);

mE820EntriesCount = Parameters.nr_entries;

//
// Sort E820 entries
//
for (LoopIndex = 1; LoopIndex < mE820EntriesCount; LoopIndex++) {
for (Index = LoopIndex; Index < mE820EntriesCount; Index++) {
if (mE820Entries[Index - 1].BaseAddr > mE820Entries[Index].BaseAddr) {
TmpEntry = mE820Entries[Index];
mE820Entries[Index] = mE820Entries[Index - 1];
mE820Entries[Index - 1] = TmpEntry;
}
}
}

*Count = mE820EntriesCount;
*Entries = mE820Entries;

return EFI_SUCCESS;
}

/**
Expand Down

0 comments on commit a749e1f

Please sign in to comment.