For future ARM/AArch64 support in the XenBus code, move the implementation of hypercall invocation to a dedicated library. The use of a library rather than just an arch specific source in XenBusDxe.inf allows us to move the constructor dependency on the gXenInfoGuid HOB to the library implementation.
Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Ard Biesheuvel ard.biesheuvel@linaro.org --- OvmfPkg/Include/Library/XenHypercallLib.h | 36 ++++++++++ .../XenHypercallLib}/Ia32/hypercall.nasm | 6 +- .../XenHypercallLib}/X64/hypercall.nasm | 6 +- .../Library/XenHypercallLib/XenHypercallLibIntel.c | 77 ++++++++++++++++++++++ .../XenHypercallLib/XenHypercallLibIntel.inf | 48 ++++++++++++++ OvmfPkg/OvmfPkg.dec | 4 ++ OvmfPkg/OvmfPkgIa32.dsc | 1 + OvmfPkg/OvmfPkgIa32X64.dsc | 1 + OvmfPkg/OvmfPkgX64.dsc | 1 + OvmfPkg/XenBusDxe/XenBusDxe.c | 7 -- OvmfPkg/XenBusDxe/XenBusDxe.h | 1 - OvmfPkg/XenBusDxe/XenBusDxe.inf | 9 +-- OvmfPkg/XenBusDxe/XenHypercall.c | 30 ++------- OvmfPkg/XenBusDxe/XenHypercall.h | 31 --------- 14 files changed, 179 insertions(+), 79 deletions(-) create mode 100644 OvmfPkg/Include/Library/XenHypercallLib.h rename OvmfPkg/{XenBusDxe => Library/XenHypercallLib}/Ia32/hypercall.nasm (81%) rename OvmfPkg/{XenBusDxe => Library/XenHypercallLib}/X64/hypercall.nasm (78%) create mode 100644 OvmfPkg/Library/XenHypercallLib/XenHypercallLibIntel.c create mode 100644 OvmfPkg/Library/XenHypercallLib/XenHypercallLibIntel.inf
diff --git a/OvmfPkg/Include/Library/XenHypercallLib.h b/OvmfPkg/Include/Library/XenHypercallLib.h new file mode 100644 index 000000000000..408807a55356 --- /dev/null +++ b/OvmfPkg/Include/Library/XenHypercallLib.h @@ -0,0 +1,36 @@ +/** @file + Xen Hypercall Library definition + +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. + +**/ + +#ifndef __XEN_HYPERCALL_LIB_H_ +#define __XEN_HYPERCALL_LIB_H_ + +/** + 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 INTN HypercallID, + IN OUT INTN Arg1, + IN OUT INTN Arg2 + ); + +#endif diff --git a/OvmfPkg/XenBusDxe/Ia32/hypercall.nasm b/OvmfPkg/Library/XenHypercallLib/Ia32/hypercall.nasm similarity index 81% rename from OvmfPkg/XenBusDxe/Ia32/hypercall.nasm rename to OvmfPkg/Library/XenHypercallLib/Ia32/hypercall.nasm index 8547c30b81ee..e0fa71bb5ba8 100644 --- a/OvmfPkg/XenBusDxe/Ia32/hypercall.nasm +++ b/OvmfPkg/Library/XenHypercallLib/Ia32/hypercall.nasm @@ -2,13 +2,13 @@ SECTION .text
; INTN ; EFIAPI -; XenHypercall2 ( +; __XenHypercall2 ( ; IN VOID *HypercallAddr, ; IN OUT INTN Arg1, ; IN OUT INTN Arg2 ; ); -global ASM_PFX(XenHypercall2) -ASM_PFX(XenHypercall2): +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 diff --git a/OvmfPkg/XenBusDxe/X64/hypercall.nasm b/OvmfPkg/Library/XenHypercallLib/X64/hypercall.nasm similarity index 78% rename from OvmfPkg/XenBusDxe/X64/hypercall.nasm rename to OvmfPkg/Library/XenHypercallLib/X64/hypercall.nasm index 177f271ef094..5e6a0c05c5c4 100644 --- a/OvmfPkg/XenBusDxe/X64/hypercall.nasm +++ b/OvmfPkg/Library/XenHypercallLib/X64/hypercall.nasm @@ -3,13 +3,13 @@ SECTION .text
; INTN ; EFIAPI -; XenHypercall2 ( +; __XenHypercall2 ( ; IN VOID *HypercallAddr, ; IN OUT INTN Arg1, ; IN OUT INTN Arg2 ; ); -global ASM_PFX(XenHypercall2) -ASM_PFX(XenHypercall2): +global ASM_PFX(__XenHypercall2) +ASM_PFX(__XenHypercall2): push rdi push rsi ; Copy HypercallAddr to rax diff --git a/OvmfPkg/Library/XenHypercallLib/XenHypercallLibIntel.c b/OvmfPkg/Library/XenHypercallLib/XenHypercallLibIntel.c new file mode 100644 index 000000000000..1fc22b4f07c8 --- /dev/null +++ b/OvmfPkg/Library/XenHypercallLib/XenHypercallLibIntel.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 INTN 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 000000000000..3f393e1f0f94 --- /dev/null +++ b/OvmfPkg/Library/XenHypercallLib/XenHypercallLibIntel.inf @@ -0,0 +1,48 @@ +## @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] + XenHypercallLibIntel.c + +[Sources.IA32] + Ia32/hypercall.nasm + +[Sources.X64] + X64/hypercall.nasm + +[Packages] + MdePkg/MdePkg.dec + OvmfPkg/OvmfPkg.dec + +[LibraryClasses] + BaseLib + HobLib + +[Guids] + gEfiXenInfoGuid diff --git a/OvmfPkg/OvmfPkg.dec b/OvmfPkg/OvmfPkg.dec index 33dcb82de232..314d97c258b3 100644 --- a/OvmfPkg/OvmfPkg.dec +++ b/OvmfPkg/OvmfPkg.dec @@ -39,6 +39,10 @@ # SerializeVariablesLib|Include/Library/SerializeVariablesLib.h
+ ## @libraryclass Invoke Xen hypercalls + # + XenHypercallLib|Include/Library/XenHypercallLib.h + [Guids] gUefiOvmfPkgTokenSpaceGuid = {0x93bb96af, 0xb9f2, 0x4eb8, {0x94, 0x62, 0xe0, 0xba, 0x74, 0x56, 0x42, 0x36}} gEfiXenInfoGuid = {0xd3b46f3b, 0xd441, 0x1244, {0x9a, 0x12, 0x0, 0x12, 0x27, 0x3f, 0xc1, 0x4d}} diff --git a/OvmfPkg/OvmfPkgIa32.dsc b/OvmfPkg/OvmfPkgIa32.dsc index dca7c6e51603..a896afa1bfb4 100644 --- a/OvmfPkg/OvmfPkgIa32.dsc +++ b/OvmfPkg/OvmfPkgIa32.dsc @@ -128,6 +128,7 @@ S3BootScriptLib|MdeModulePkg/Library/PiDxeS3BootScriptLib/DxeS3BootScriptLib.inf SmbusLib|MdePkg/Library/BaseSmbusLibNull/BaseSmbusLibNull.inf OrderedCollectionLib|MdePkg/Library/BaseOrderedCollectionRedBlackTreeLib/BaseOrderedCollectionRedBlackTreeLib.inf + XenHypercallLib|OvmfPkg/Library/XenHypercallLib/XenHypercallLibIntel.inf
[LibraryClasses.common] !if $(SECURE_BOOT_ENABLE) == TRUE diff --git a/OvmfPkg/OvmfPkgIa32X64.dsc b/OvmfPkg/OvmfPkgIa32X64.dsc index 085f43eaf11b..a5c11578cc3c 100644 --- a/OvmfPkg/OvmfPkgIa32X64.dsc +++ b/OvmfPkg/OvmfPkgIa32X64.dsc @@ -133,6 +133,7 @@ S3BootScriptLib|MdeModulePkg/Library/PiDxeS3BootScriptLib/DxeS3BootScriptLib.inf SmbusLib|MdePkg/Library/BaseSmbusLibNull/BaseSmbusLibNull.inf OrderedCollectionLib|MdePkg/Library/BaseOrderedCollectionRedBlackTreeLib/BaseOrderedCollectionRedBlackTreeLib.inf + XenHypercallLib|OvmfPkg/Library/XenHypercallLib/XenHypercallLibIntel.inf
[LibraryClasses.common] !if $(SECURE_BOOT_ENABLE) == TRUE diff --git a/OvmfPkg/OvmfPkgX64.dsc b/OvmfPkg/OvmfPkgX64.dsc index 17d674cd344d..70df1c8af1a4 100644 --- a/OvmfPkg/OvmfPkgX64.dsc +++ b/OvmfPkg/OvmfPkgX64.dsc @@ -133,6 +133,7 @@ S3BootScriptLib|MdeModulePkg/Library/PiDxeS3BootScriptLib/DxeS3BootScriptLib.inf SmbusLib|MdePkg/Library/BaseSmbusLibNull/BaseSmbusLibNull.inf OrderedCollectionLib|MdePkg/Library/BaseOrderedCollectionRedBlackTreeLib/BaseOrderedCollectionRedBlackTreeLib.inf + XenHypercallLib|OvmfPkg/Library/XenHypercallLib/XenHypercallLibIntel.inf
[LibraryClasses.common] !if $(SECURE_BOOT_ENABLE) == TRUE diff --git a/OvmfPkg/XenBusDxe/XenBusDxe.c b/OvmfPkg/XenBusDxe/XenBusDxe.c index 7a7fd82d559d..07336ff15bba 100644 --- a/OvmfPkg/XenBusDxe/XenBusDxe.c +++ b/OvmfPkg/XenBusDxe/XenBusDxe.c @@ -348,13 +348,6 @@ XenBusDxeDriverBindingStart ( MmioAddr = BarDesc->AddrRangeMin; FreePool (BarDesc);
- Status = XenHyperpageInit (Dev); - if (EFI_ERROR (Status)) { - DEBUG ((EFI_D_ERROR, "XenBus: Unable to retrieve the hyperpage.\n")); - Status = EFI_UNSUPPORTED; - goto ErrorAllocated; - } - Status = XenGetSharedInfoPage (Dev); if (EFI_ERROR (Status)) { DEBUG ((EFI_D_ERROR, "XenBus: Unable to get the shared info page.\n")); diff --git a/OvmfPkg/XenBusDxe/XenBusDxe.h b/OvmfPkg/XenBusDxe/XenBusDxe.h index 11640223ebf4..0879e9cd194f 100644 --- a/OvmfPkg/XenBusDxe/XenBusDxe.h +++ b/OvmfPkg/XenBusDxe/XenBusDxe.h @@ -96,7 +96,6 @@ struct _XENBUS_DEVICE { EFI_DEVICE_PATH_PROTOCOL *DevicePath; LIST_ENTRY ChildList;
- VOID *Hyperpage; shared_info_t *SharedInfo; };
diff --git a/OvmfPkg/XenBusDxe/XenBusDxe.inf b/OvmfPkg/XenBusDxe/XenBusDxe.inf index 4ce474345452..2645267a1c6f 100644 --- a/OvmfPkg/XenBusDxe/XenBusDxe.inf +++ b/OvmfPkg/XenBusDxe/XenBusDxe.inf @@ -49,12 +49,10 @@ Helpers.c
[Sources.IA32] - Ia32/hypercall.nasm Ia32/InterlockedCompareExchange16.nasm Ia32/TestAndClearBit.nasm
[Sources.X64] - X64/hypercall.nasm X64/InterlockedCompareExchange16.nasm X64/TestAndClearBit.nasm
@@ -67,8 +65,7 @@ UefiLib DevicePathLib DebugLib - HobLib - + XenHypercallLib
[Protocols] gEfiDriverBindingProtocolGuid @@ -77,7 +74,3 @@ gEfiComponentNameProtocolGuid gXenBusProtocolGuid
- -[Guids] - gEfiXenInfoGuid - diff --git a/OvmfPkg/XenBusDxe/XenHypercall.c b/OvmfPkg/XenBusDxe/XenHypercall.c index 34d92e76b7e3..e9075cafcdcd 100644 --- a/OvmfPkg/XenBusDxe/XenHypercall.c +++ b/OvmfPkg/XenBusDxe/XenHypercall.c @@ -14,31 +14,13 @@ **/
#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; -} +#include <Library/XenHypercallLib.h>
UINT64 XenHypercallHvmGetParam ( @@ -49,11 +31,9 @@ XenHypercallHvmGetParam ( xen_hvm_param_t Parameter; INTN Error;
- ASSERT (Dev->Hyperpage != NULL); - Parameter.domid = DOMID_SELF; Parameter.index = Index; - Error = XenHypercall2 ((UINT8*)Dev->Hyperpage + __HYPERVISOR_hvm_op * 32, + Error = XenHypercall2 (__HYPERVISOR_hvm_op, HVMOP_get_param, (INTN) &Parameter); if (Error != 0) { DEBUG ((EFI_D_ERROR, @@ -71,8 +51,7 @@ XenHypercallMemoryOp ( IN OUT VOID *Arguments ) { - ASSERT (Dev->Hyperpage != NULL); - return XenHypercall2 ((UINT8*)Dev->Hyperpage + __HYPERVISOR_memory_op * 32, + return XenHypercall2 (__HYPERVISOR_memory_op, Operation, (INTN) Arguments); }
@@ -83,8 +62,7 @@ XenHypercallEventChannelOp ( IN OUT VOID *Arguments ) { - ASSERT (Dev->Hyperpage != NULL); - return XenHypercall2 ((UINT8*)Dev->Hyperpage + __HYPERVISOR_event_channel_op * 32, + return XenHypercall2 (__HYPERVISOR_event_channel_op, Operation, (INTN) Arguments); }
diff --git a/OvmfPkg/XenBusDxe/XenHypercall.h b/OvmfPkg/XenBusDxe/XenHypercall.h index 06693830e16e..49244bc584f7 100644 --- a/OvmfPkg/XenBusDxe/XenHypercall.h +++ b/OvmfPkg/XenBusDxe/XenHypercall.h @@ -17,37 +17,6 @@ #define __XENBUS_DXE_HYPERCALL_H__
/** - This function will put the two arguments in the right place (registers) and - call HypercallAddr, which correspond to an entry in the hypercall pages. - - @param HypercallAddr A memory address where the hypercall to call is. - @param Arg1 First argument. - @param Arg2 Second argument. - - @return Return 0 if success otherwise it return an errno. -**/ -INTN -EFIAPI -XenHypercall2 ( - IN VOID *HypercallAddr, - IN OUT INTN Arg1, - IN OUT INTN Arg2 - ); - -/** - Get the page where all hypercall are from the XenInfo hob. - - @param Dev A XENBUS_DEVICE instance. - - @retval EFI_NOT_FOUND hyperpage could not be found. - @retval EFI_SUCCESS Successfully retrieve the hyperpage pointer. -**/ -EFI_STATUS -XenHyperpageInit ( - XENBUS_DEVICE *Dev - ); - -/** Return the value of the HVM parameter Index.
@param Dev A XENBUS_DEVICE instance.