summaryrefslogtreecommitdiffstats
path: root/OvmfPkg/XenBusDxe/XenHypercall.c
diff options
context:
space:
mode:
authorAnthony PERARD <anthony.perard@citrix.com>2014-10-29 06:49:10 +0000
committerjljusten <jljusten@Edk2>2014-10-29 06:49:10 +0000
commitabcbbb14a44a83b4cdf90137307a62e7b58e6720 (patch)
tree233c7beab4c4edcc10b0936cd8ef56e3accde136 /OvmfPkg/XenBusDxe/XenHypercall.c
parenta154f420147b0a3f449bb52da1e76dabef3478a5 (diff)
downloadedk2-abcbbb14a44a83b4cdf90137307a62e7b58e6720.tar.gz
edk2-abcbbb14a44a83b4cdf90137307a62e7b58e6720.tar.bz2
edk2-abcbbb14a44a83b4cdf90137307a62e7b58e6720.zip
OvmfPkg/XenBusDxe: Add support to make Xen Hypercalls.
Change in V4: - Replace the license by the commonly used file header text. - add file header to XenHypercall.h (license, copyright, brief desc) Change in V3: - adding IA32 support. (not reviewed yet) both XenBusDxe/Ia32/hypercall.{S,asm} file are new Change in V2: - file header, copyright - Add License - Add push/pop instruction. - fix types - Comment of exported functions - Improve coding style - Add error handling in the main init function (of the drivers) - Comment assembly Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Anthony PERARD <anthony.perard@citrix.com> Reviewed-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com> Reviewed-by: Jordan Justen <jordan.l.justen@intel.com> git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@16260 6f19259b-4bc3-4df7-8a09-765794883524
Diffstat (limited to 'OvmfPkg/XenBusDxe/XenHypercall.c')
-rw-r--r--OvmfPkg/XenBusDxe/XenHypercall.c118
1 files changed, 118 insertions, 0 deletions
diff --git a/OvmfPkg/XenBusDxe/XenHypercall.c b/OvmfPkg/XenBusDxe/XenHypercall.c
new file mode 100644
index 0000000000..0f2ba5d693
--- /dev/null
+++ b/OvmfPkg/XenBusDxe/XenHypercall.c
@@ -0,0 +1,118 @@
+/** @file
+ Functions to make Xen hypercalls.
+
+ Copyright (C) 2014, Citrix Ltd.
+
+ This program and the accompanying materials
+ are licensed and made available under the terms and conditions of the BSD License
+ which accompanies this distribution. The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.php
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+**/
+
+#include <PiDxe.h>
+#include <Library/HobLib.h>
+#include <Guid/XenInfo.h>
+
+#include "XenBusDxe.h"
+#include "XenHypercall.h"
+
+#include <IndustryStandard/Xen/hvm/params.h>
+#include <IndustryStandard/Xen/memory.h>
+
+EFI_STATUS
+XenHyperpageInit (
+ IN OUT XENBUS_DEVICE *Dev
+ )
+{
+ EFI_HOB_GUID_TYPE *GuidHob;
+ EFI_XEN_INFO *XenInfo;
+
+ GuidHob = GetFirstGuidHob (&gEfiXenInfoGuid);
+ if (GuidHob == NULL) {
+ return EFI_NOT_FOUND;
+ }
+ XenInfo = (EFI_XEN_INFO *) GET_GUID_HOB_DATA (GuidHob);
+ Dev->Hyperpage = XenInfo->HyperPages;
+ return EFI_SUCCESS;
+}
+
+UINT64
+XenHypercallHvmGetParam (
+ IN XENBUS_DEVICE *Dev,
+ IN INTN Index
+ )
+{
+ xen_hvm_param_t Parameter;
+ INTN Error;
+
+ ASSERT (Dev->Hyperpage != NULL);
+
+ Parameter.domid = DOMID_SELF;
+ Parameter.index = Index;
+ Error = XenHypercall2 (Dev->Hyperpage + __HYPERVISOR_hvm_op * 32,
+ HVMOP_get_param, (INTN) &Parameter);
+ if (Error != 0) {
+ DEBUG ((EFI_D_ERROR,
+ "XenHypercall: Error %d trying to get HVM parameter %d\n",
+ Error, Index));
+ return 0;
+ }
+ return Parameter.value;
+}
+
+INTN
+XenHypercallMemoryOp (
+ IN XENBUS_DEVICE *Dev,
+ IN UINTN Operation,
+ IN OUT VOID *Arguments
+ )
+{
+ ASSERT (Dev->Hyperpage != NULL);
+ return XenHypercall2 (Dev->Hyperpage + __HYPERVISOR_memory_op * 32,
+ Operation, (INTN) Arguments);
+}
+
+INTN
+XenHypercallEventChannelOp (
+ IN XENBUS_DEVICE *Dev,
+ IN INTN Operation,
+ IN OUT VOID *Arguments
+ )
+{
+ ASSERT (Dev->Hyperpage != NULL);
+ return XenHypercall2 (Dev->Hyperpage + __HYPERVISOR_event_channel_op * 32,
+ Operation, (INTN) Arguments);
+}
+
+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 (Dev, XENMEM_add_to_physmap, &Parameter) != 0) {
+ FreePages (Dev->SharedInfo, 1);
+ Dev->SharedInfo = NULL;
+ return EFI_LOAD_ERROR;
+ }
+
+ return EFI_SUCCESS;
+}