diff options
author | 2023-10-10 14:33:42 +0000 | |
---|---|---|
committer | 2023-10-10 14:33:42 +0000 | |
commit | af1a266670d040d2f4083ff309d732d648afba2a (patch) | |
tree | 2fc46203448ddcc6f81546d379abfaeb323575e9 /roms/edk2/OvmfPkg/Library/XenHypercallLib | |
parent | e02cda008591317b1625707ff8e115a4841aa889 (diff) |
Change-Id: Iaf8d18082d3991dec7c0ebbea540f092188eb4ec
Diffstat (limited to 'roms/edk2/OvmfPkg/Library/XenHypercallLib')
8 files changed, 360 insertions, 0 deletions
diff --git a/roms/edk2/OvmfPkg/Library/XenHypercallLib/Aarch64/Hypercall.S b/roms/edk2/OvmfPkg/Library/XenHypercallLib/Aarch64/Hypercall.S new file mode 100644 index 000000000..1533d48d0 --- /dev/null +++ b/roms/edk2/OvmfPkg/Library/XenHypercallLib/Aarch64/Hypercall.S @@ -0,0 +1,20 @@ +
+/** @file
+ AArch64 implementation of XenHypercall2
+
+ Copyright (C) 2014, Linaro Ltd.
+
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include <IndustryStandard/Xen/arch-arm/xen.h>
+
+ .text
+ .global ASM_PFX(XenHypercall2)
+ASM_PFX(XenHypercall2):
+ mov x16, x0
+ mov x0, x1
+ mov x1, x2
+ hvc #XEN_HYPERCALL_TAG
+ ret
diff --git a/roms/edk2/OvmfPkg/Library/XenHypercallLib/Arm/Hypercall.S b/roms/edk2/OvmfPkg/Library/XenHypercallLib/Arm/Hypercall.S new file mode 100644 index 000000000..06cf1e68a --- /dev/null +++ b/roms/edk2/OvmfPkg/Library/XenHypercallLib/Arm/Hypercall.S @@ -0,0 +1,22 @@ +/** @file
+ ARM (AArch32) implementation of XenHypercall2
+
+ Copyright (C) 2014, Linaro Ltd.
+
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include <IndustryStandard/Xen/arch-arm/xen.h>
+
+ .text
+ .arch_extension virt
+
+GCC_ASM_EXPORT(XenHypercall2)
+
+ASM_PFX(XenHypercall2):
+ mov r12, r0
+ mov r0, r1
+ mov r1, r2
+ hvc #XEN_HYPERCALL_TAG
+ bx lr
diff --git a/roms/edk2/OvmfPkg/Library/XenHypercallLib/ArmXenHypercall.c b/roms/edk2/OvmfPkg/Library/XenHypercallLib/ArmXenHypercall.c new file mode 100644 index 000000000..2cacc67ba --- /dev/null +++ b/roms/edk2/OvmfPkg/Library/XenHypercallLib/ArmXenHypercall.c @@ -0,0 +1,38 @@ +/** @file
+ Xen Hypercall Library implementation for ARM architecture
+
+ Copyright (C) 2015, Red Hat, Inc.
+ Copyright (c) 2014, Linaro Ltd. All rights reserved.<BR>
+
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+**/
+
+#include <Base.h>
+
+/**
+ Check if the Xen Hypercall library is able to make calls to the Xen
+ hypervisor.
+
+ Client code should call further functions in this library only if, and after,
+ this function returns TRUE.
+
+ @retval TRUE Hypercalls are available.
+ @retval FALSE Hypercalls are not available.
+**/
+BOOLEAN
+EFIAPI
+XenHypercallIsAvailable (
+ VOID
+ )
+{
+ return TRUE;
+}
+
+RETURN_STATUS
+EFIAPI
+XenHypercallLibInit (
+ VOID
+ )
+{
+ return RETURN_SUCCESS;
+}
diff --git a/roms/edk2/OvmfPkg/Library/XenHypercallLib/Ia32/hypercall.nasm b/roms/edk2/OvmfPkg/Library/XenHypercallLib/Ia32/hypercall.nasm new file mode 100644 index 000000000..e0fa71bb5 --- /dev/null +++ b/roms/edk2/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/roms/edk2/OvmfPkg/Library/XenHypercallLib/X64/hypercall.nasm b/roms/edk2/OvmfPkg/Library/XenHypercallLib/X64/hypercall.nasm new file mode 100644 index 000000000..5e6a0c05c --- /dev/null +++ b/roms/edk2/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/roms/edk2/OvmfPkg/Library/XenHypercallLib/X86XenHypercall.c b/roms/edk2/OvmfPkg/Library/XenHypercallLib/X86XenHypercall.c new file mode 100644 index 000000000..f779e4647 --- /dev/null +++ b/roms/edk2/OvmfPkg/Library/XenHypercallLib/X86XenHypercall.c @@ -0,0 +1,90 @@ +/** @file
+ Xen Hypercall Library implementation for Intel architecture
+
+Copyright (c) 2014, Linaro Ltd. All rights reserved.<BR>
+SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include <PiDxe.h>
+#include <Library/HobLib.h>
+#include <Library/DebugLib.h>
+#include <Guid/XenInfo.h>
+
+STATIC VOID *HyperPage;
+
+/**
+ Check if the Xen Hypercall library is able to make calls to the Xen
+ hypervisor.
+
+ Client code should call further functions in this library only if, and after,
+ this function returns TRUE.
+
+ @retval TRUE Hypercalls are available.
+ @retval FALSE Hypercalls are not available.
+**/
+BOOLEAN
+EFIAPI
+XenHypercallIsAvailable (
+ VOID
+ )
+{
+ return HyperPage != NULL;
+}
+
+//
+// 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
+XenHypercallLibInit (
+ 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/roms/edk2/OvmfPkg/Library/XenHypercallLib/XenHypercall.c b/roms/edk2/OvmfPkg/Library/XenHypercallLib/XenHypercall.c new file mode 100644 index 000000000..265aa766d --- /dev/null +++ b/roms/edk2/OvmfPkg/Library/XenHypercallLib/XenHypercall.c @@ -0,0 +1,76 @@ +/** @file
+ Functions to make Xen hypercalls.
+
+ Copyright (C) 2014, Citrix Ltd.
+
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include <PiDxe.h>
+
+#include <IndustryStandard/Xen/hvm/params.h>
+#include <IndustryStandard/Xen/memory.h>
+
+#include <Library/DebugLib.h>
+#include <Library/XenHypercallLib.h>
+
+RETURN_STATUS
+EFIAPI
+XenHypercallLibConstruct (
+ VOID
+ )
+{
+ XenHypercallLibInit ();
+ //
+ // We don't fail library construction, since that has catastrophic
+ // consequences for client modules (whereas those modules may easily be
+ // running on a non-Xen platform). Instead, XenHypercallIsAvailable()
+ // will return FALSE.
+ //
+ return RETURN_SUCCESS;
+}
+
+UINT64
+EFIAPI
+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 ((DEBUG_ERROR,
+ "XenHypercall: Error %Ld trying to get HVM parameter %d\n",
+ (INT64)Error, Index));
+ return 0;
+ }
+ return Parameter.value;
+}
+
+INTN
+EFIAPI
+XenHypercallMemoryOp (
+ IN UINTN Operation,
+ IN OUT VOID *Arguments
+ )
+{
+ return XenHypercall2 (__HYPERVISOR_memory_op,
+ Operation, (INTN) Arguments);
+}
+
+INTN
+EFIAPI
+XenHypercallEventChannelOp (
+ IN INTN Operation,
+ IN OUT VOID *Arguments
+ )
+{
+ return XenHypercall2 (__HYPERVISOR_event_channel_op,
+ Operation, (INTN) Arguments);
+}
diff --git a/roms/edk2/OvmfPkg/Library/XenHypercallLib/XenHypercallLib.inf b/roms/edk2/OvmfPkg/Library/XenHypercallLib/XenHypercallLib.inf new file mode 100644 index 000000000..21ce5b443 --- /dev/null +++ b/roms/edk2/OvmfPkg/Library/XenHypercallLib/XenHypercallLib.inf @@ -0,0 +1,63 @@ +## @file
+# Xen Hypercall abstraction lib for Intel and ARM architectures
+#
+# Copyright (c) 2014, Linaro Ltd. All rights reserved.<BR>
+# SPDX-License-Identifier: BSD-2-Clause-Patent
+#
+##
+
+[Defines]
+ INF_VERSION = 0x00010005
+ BASE_NAME = XenHypercallLib
+ FILE_GUID = B5EE9A32-CA5A-49A8-82E3-ADA4CCB77C7C
+ MODULE_TYPE = BASE
+ VERSION_STRING = 1.0
+ CONSTRUCTOR = XenHypercallLibConstruct
+
+[Defines.IA32, Defines.X64]
+ LIBRARY_CLASS = XenHypercallLib|PEIM DXE_DRIVER UEFI_DRIVER
+
+[Defines.ARM, Defines.AARCH64]
+ LIBRARY_CLASS = XenHypercallLib
+
+#
+# The following information is for reference only and not required by the build tools.
+#
+# VALID_ARCHITECTURES = IA32 X64 ARM AARCH64
+#
+
+[Sources.IA32, Sources.X64]
+ X86XenHypercall.c
+
+[Sources.IA32]
+ Ia32/hypercall.nasm
+
+[Sources.X64]
+ X64/hypercall.nasm
+
+[Sources.ARM, Sources.AARCH64]
+ ArmXenHypercall.c
+
+[Sources.ARM]
+ Arm/Hypercall.S
+
+[Sources.AARCH64]
+ Aarch64/Hypercall.S
+
+[Sources]
+ XenHypercall.c
+
+[Packages]
+ MdePkg/MdePkg.dec
+ OvmfPkg/OvmfPkg.dec
+
+[LibraryClasses.IA32, LibraryClasses.X64]
+ BaseLib
+ HobLib
+ DebugLib
+
+[Guids.IA32, Guids.X64]
+ gEfiXenInfoGuid
+
+[BuildOptions.ARM]
+ RVCT:*_*_ARM_PLATFORM_FLAGS == --cpu Cortex-A15
|