Ovmf/Xen: refactor XenBusDxe hypercall implementation

This refactors the Xen hypercall implementation that is part of the
XenBusDxe driver, in preparation of splitting it off entirely into
a XenHypercallLib library. This involves:
- removing the dependency on XENBUS_DEVICE* pointers in the XenHypercall()
  prototypes
- moving the discovered hyperpage address to a global variable
- moving XenGetSharedInfoPage() to its only user XenBusDxe.c (the shared info
  page is not strictly part of the Xen hypercall interface, and is not used
  by other expected users of XenHypercallLib such as the Xen console version
  of SerialPortLib
- reimplement XenHypercall2() in C and move the indexing of the hyperpage
  there; the existing asm implementations are renamed to __XenHypercall2() and
  invoked from the new C implementation.

Contributed-under: TianoCore Contribution Agreement 1.0
Acked-by: Laszlo Ersek <lersek@redhat.com>
Reviewed-by: Anthony PERARD <anthony.perard@citrix.com>
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Signed-off-by: Laszlo Ersek <lersek@redhat.com>

git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@16969 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
Ard Biesheuvel
2015-02-28 20:32:27 +00:00
committed by lersek
parent d6970b9b41
commit bbc3758ab5
9 changed files with 84 additions and 81 deletions

View File

@@ -34,6 +34,8 @@
#include "XenStore.h"
#include "XenBus.h"
#include <IndustryStandard/Xen/hvm/params.h>
#include <IndustryStandard/Xen/memory.h>
///
/// Driver Binding Protocol instance
@@ -51,6 +53,46 @@ EFI_DRIVER_BINDING_PROTOCOL gXenBusDxeDriverBinding = {
STATIC EFI_LOCK mMyDeviceLock = EFI_INITIALIZE_LOCK_VARIABLE (TPL_CALLBACK);
STATIC XENBUS_DEVICE *mMyDevice = NULL;
/**
Map the shared_info_t page into memory.
@param Dev A XENBUS_DEVICE instance.
@retval EFI_SUCCESS Dev->SharedInfo whill contain a pointer to
the shared info page
@retval EFI_LOAD_ERROR The shared info page could not be mapped. The
hypercall returned an error.
**/
STATIC
EFI_STATUS
XenGetSharedInfoPage (
IN OUT XENBUS_DEVICE *Dev
)
{
xen_add_to_physmap_t Parameter;
ASSERT (Dev->SharedInfo == NULL);
Parameter.domid = DOMID_SELF;
Parameter.space = XENMAPSPACE_shared_info;
Parameter.idx = 0;
//
// using reserved page because the page is not released when Linux is
// starting because of the add_to_physmap. QEMU might try to access the
// page, and fail because it have no right to do so (segv).
//
Dev->SharedInfo = AllocateReservedPages (1);
Parameter.gpfn = (UINTN) Dev->SharedInfo >> EFI_PAGE_SHIFT;
if (XenHypercallMemoryOp (XENMEM_add_to_physmap, &Parameter) != 0) {
FreePages (Dev->SharedInfo, 1);
Dev->SharedInfo = NULL;
return EFI_LOAD_ERROR;
}
return EFI_SUCCESS;
}
/**
Unloads an image.
@@ -348,7 +390,7 @@ XenBusDxeDriverBindingStart (
MmioAddr = BarDesc->AddrRangeMin;
FreePool (BarDesc);
Status = XenHyperpageInit (Dev);
Status = XenHyperpageInit ();
if (EFI_ERROR (Status)) {
DEBUG ((EFI_D_ERROR, "XenBus: Unable to retrieve the hyperpage.\n"));
Status = EFI_UNSUPPORTED;