summaryrefslogtreecommitdiff
path: root/OvmfPkg/Library/XenHypercallLib
diff options
context:
space:
mode:
authorArd Biesheuvel <ard.biesheuvel@linaro.org>2015-02-28 20:32:39 +0000
committerlersek <lersek@Edk2>2015-02-28 20:32:39 +0000
commitcd8ff8fdda24c83be6ac247f8c21e5e4032fe586 (patch)
tree1931452cf00096df4bb7fd945e6fadbd4de68981 /OvmfPkg/Library/XenHypercallLib
parentbbc3758ab5bc0e526994a63d739d445416ff0c07 (diff)
downloadedk2-platforms-cd8ff8fdda24c83be6ac247f8c21e5e4032fe586.tar.xz
Ovmf/Xen: move XenBusDxe hypercall code to separate library
This moves all of the Xen hypercall code that was private to XenBusDxe to a new library class XenHypercallLib. This will allow us to reimplement it for ARM, and to export the Xen hypercall functionality to other parts of the code, such as a Xen console SerialPortLib driver. Contributed-under: TianoCore Contribution Agreement 1.0 Reviewed-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@16970 6f19259b-4bc3-4df7-8a09-765794883524
Diffstat (limited to 'OvmfPkg/Library/XenHypercallLib')
-rw-r--r--OvmfPkg/Library/XenHypercallLib/Ia32/hypercall.nasm25
-rw-r--r--OvmfPkg/Library/XenHypercallLib/X64/hypercall.nasm26
-rw-r--r--OvmfPkg/Library/XenHypercallLib/XenHypercall.c63
-rw-r--r--OvmfPkg/Library/XenHypercallLib/XenHypercallIntel.c77
-rw-r--r--OvmfPkg/Library/XenHypercallLib/XenHypercallLibIntel.inf52
5 files changed, 243 insertions, 0 deletions
diff --git a/OvmfPkg/Library/XenHypercallLib/Ia32/hypercall.nasm b/OvmfPkg/Library/XenHypercallLib/Ia32/hypercall.nasm
new file mode 100644
index 0000000000..e0fa71bb5b
--- /dev/null
+++ b/OvmfPkg/Library/XenHypercallLib/Ia32/hypercall.nasm
@@ -0,0 +1,25 @@
+SECTION .text
+
+; INTN
+; EFIAPI
+; __XenHypercall2 (
+; IN VOID *HypercallAddr,
+; IN OUT INTN Arg1,
+; IN OUT INTN Arg2
+; );
+global ASM_PFX(__XenHypercall2)
+ASM_PFX(__XenHypercall2):
+ ; Save only ebx, ecx is supposed to be a scratch register and needs to be
+ ; saved by the caller
+ push ebx
+ ; Copy HypercallAddr to eax
+ mov eax, [esp + 8]
+ ; Copy Arg1 to the register expected by Xen
+ mov ebx, [esp + 12]
+ ; Copy Arg2 to the register expected by Xen
+ mov ecx, [esp + 16]
+ ; Call HypercallAddr
+ call eax
+ pop ebx
+ ret
+
diff --git a/OvmfPkg/Library/XenHypercallLib/X64/hypercall.nasm b/OvmfPkg/Library/XenHypercallLib/X64/hypercall.nasm
new file mode 100644
index 0000000000..5e6a0c05c5
--- /dev/null
+++ b/OvmfPkg/Library/XenHypercallLib/X64/hypercall.nasm
@@ -0,0 +1,26 @@
+DEFAULT REL
+SECTION .text
+
+; INTN
+; EFIAPI
+; __XenHypercall2 (
+; IN VOID *HypercallAddr,
+; IN OUT INTN Arg1,
+; IN OUT INTN Arg2
+; );
+global ASM_PFX(__XenHypercall2)
+ASM_PFX(__XenHypercall2):
+ push rdi
+ push rsi
+ ; Copy HypercallAddr to rax
+ mov rax, rcx
+ ; Copy Arg1 to the register expected by Xen
+ mov rdi, rdx
+ ; Copy Arg2 to the register expected by Xen
+ mov rsi, r8
+ ; Call HypercallAddr
+ call rax
+ pop rsi
+ pop rdi
+ ret
+
diff --git a/OvmfPkg/Library/XenHypercallLib/XenHypercall.c b/OvmfPkg/Library/XenHypercallLib/XenHypercall.c
new file mode 100644
index 0000000000..ecc757cf70
--- /dev/null
+++ b/OvmfPkg/Library/XenHypercallLib/XenHypercall.c
@@ -0,0 +1,63 @@
+/** @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 <IndustryStandard/Xen/hvm/params.h>
+#include <IndustryStandard/Xen/memory.h>
+
+#include <Library/DebugLib.h>
+#include <Library/XenHypercallLib.h>
+
+UINT64
+XenHypercallHvmGetParam (
+ IN UINT32 Index
+ )
+{
+ xen_hvm_param_t Parameter;
+ INTN Error;
+
+ Parameter.domid = DOMID_SELF;
+ Parameter.index = Index;
+ Error = XenHypercall2 (__HYPERVISOR_hvm_op,
+ 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 UINTN Operation,
+ IN OUT VOID *Arguments
+ )
+{
+ return XenHypercall2 (__HYPERVISOR_memory_op,
+ Operation, (INTN) Arguments);
+}
+
+INTN
+XenHypercallEventChannelOp (
+ IN INTN Operation,
+ IN OUT VOID *Arguments
+ )
+{
+ return XenHypercall2 (__HYPERVISOR_event_channel_op,
+ Operation, (INTN) Arguments);
+}
diff --git a/OvmfPkg/Library/XenHypercallLib/XenHypercallIntel.c b/OvmfPkg/Library/XenHypercallLib/XenHypercallIntel.c
new file mode 100644
index 0000000000..fc52823f23
--- /dev/null
+++ b/OvmfPkg/Library/XenHypercallLib/XenHypercallIntel.c
@@ -0,0 +1,77 @@
+/** @file
+ Xen Hypercall Library implementation for Intel architecture
+
+Copyright (c) 2014, Linaro Ltd. All rights reserved.<BR>
+This program and the accompanying materials are licensed and made available under
+the terms and conditions of the BSD License that 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 <Library/DebugLib.h>
+#include <Guid/XenInfo.h>
+
+STATIC VOID *HyperPage;
+
+//
+// Interface exposed by the ASM implementation of the core hypercall
+//
+INTN
+EFIAPI
+__XenHypercall2 (
+ IN VOID *HypercallAddr,
+ IN OUT INTN Arg1,
+ IN OUT INTN Arg2
+ );
+
+/**
+ Library constructor: retrieves the Hyperpage address
+ from the gEfiXenInfoGuid HOB
+**/
+
+RETURN_STATUS
+EFIAPI
+XenHypercallLibIntelInit (
+ VOID
+ )
+{
+ EFI_HOB_GUID_TYPE *GuidHob;
+ EFI_XEN_INFO *XenInfo;
+
+ GuidHob = GetFirstGuidHob (&gEfiXenInfoGuid);
+ if (GuidHob == NULL) {
+ return RETURN_NOT_FOUND;
+ }
+ XenInfo = (EFI_XEN_INFO *) GET_GUID_HOB_DATA (GuidHob);
+ HyperPage = XenInfo->HyperPages;
+ return RETURN_SUCCESS;
+}
+
+/**
+ This function will put the two arguments in the right place (registers) and
+ invoke the hypercall identified by HypercallID.
+
+ @param HypercallID The symbolic ID of the hypercall to be invoked
+ @param Arg1 First argument.
+ @param Arg2 Second argument.
+
+ @return Return 0 if success otherwise it return an errno.
+**/
+INTN
+EFIAPI
+XenHypercall2 (
+ IN UINTN HypercallID,
+ IN OUT INTN Arg1,
+ IN OUT INTN Arg2
+ )
+{
+ ASSERT (HyperPage != NULL);
+
+ return __XenHypercall2 ((UINT8*)HyperPage + HypercallID * 32, Arg1, Arg2);
+}
diff --git a/OvmfPkg/Library/XenHypercallLib/XenHypercallLibIntel.inf b/OvmfPkg/Library/XenHypercallLib/XenHypercallLibIntel.inf
new file mode 100644
index 0000000000..2afd608f4a
--- /dev/null
+++ b/OvmfPkg/Library/XenHypercallLib/XenHypercallLibIntel.inf
@@ -0,0 +1,52 @@
+## @file
+# Xen Hypercall abstraction lib for Intel architecture
+#
+# Copyright (c) 2014, Linaro Ltd. All rights reserved.<BR>
+# 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.
+#
+##
+
+[Defines]
+ INF_VERSION = 0x00010005
+ BASE_NAME = XenHypercallLibIntel
+ FILE_GUID = B5EE9A32-CA5A-49A8-82E3-ADA4CCB77C7C
+ MODULE_TYPE = BASE
+ VERSION_STRING = 1.0
+ LIBRARY_CLASS = XenHypercallLib|DXE_DRIVER UEFI_DRIVER
+ CONSTRUCTOR = XenHypercallLibIntelInit
+
+#
+# The following information is for reference only and not required by the build tools.
+#
+# VALID_ARCHITECTURES = IA32 X64
+#
+
+[Sources]
+ XenHypercallIntel.c
+
+[Sources.IA32]
+ Ia32/hypercall.nasm
+
+[Sources.X64]
+ X64/hypercall.nasm
+
+[Sources]
+ XenHypercall.c
+
+[Packages]
+ MdePkg/MdePkg.dec
+ OvmfPkg/OvmfPkg.dec
+
+[LibraryClasses]
+ BaseLib
+ HobLib
+ DebugLib
+
+[Guids]
+ gEfiXenInfoGuid