From patchwork Fri Jan 23 15:03:02 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 43663 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wg0-f69.google.com (mail-wg0-f69.google.com [74.125.82.69]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 31330218DB for ; Fri, 23 Jan 2015 15:04:31 +0000 (UTC) Received: by mail-wg0-f69.google.com with SMTP id x12sf4505028wgg.0 for ; Fri, 23 Jan 2015 07:04:30 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:date:message-id:in-reply-to :references:subject:precedence:reply-to:list-id:list-unsubscribe :list-archive:list-post:list-help:list-subscribe:mime-version :content-type:content-transfer-encoding:errors-to:x-original-sender :x-original-authentication-results:mailing-list; bh=1Xns79YHmjGH04A+ndBu0+liPW2m8TcCs30ZCEU2VCw=; b=L5BFCaEbLxju9PQrBReKoHUa6he8xdLpj09x5O2N+yrqCcLdBtenwscxLT6KnNc8Gj XiXz7BkCZn9WN4yKXzA8Ir4t1dnhcl01L2JurTHXepdNzNjjLKY/Z7SKbmg0CC2A/E4t +vZ1s5bmLcMbi8uheq9FOAyfd0AiElPhaU1pP9BXzM2GSw5o6MRRcIKHWYdzzzex/fsJ rG7gDHvw8QRTXxZowlaJb2i8lnqLrjOUmrZlYEeiKRXDs7nD42CXpazOxwhxSkpy/uYh pZG7mm73dgPsXYbz4TWp6Q6tnzdCZGP00YpSxeNkHoEbmqqO4T0+oGm6BrSwjRm5TwPV 066A== X-Gm-Message-State: ALoCoQl8b1JPhai8jG6ulS0fVXl6DnNCL0S+7korrCxnDfdymH9zZZ+jhi16ufV/8RpA2YbW01Zz X-Received: by 10.112.42.104 with SMTP id n8mr8159lbl.19.1422025470491; Fri, 23 Jan 2015 07:04:30 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.22.40 with SMTP id a8ls269085laf.66.gmail; Fri, 23 Jan 2015 07:04:30 -0800 (PST) X-Received: by 10.112.129.228 with SMTP id nz4mr7802955lbb.8.1422025470323; Fri, 23 Jan 2015 07:04:30 -0800 (PST) Received: from mail-la0-f43.google.com (mail-la0-f43.google.com. [209.85.215.43]) by mx.google.com with ESMTPS id c4si1593132lbv.53.2015.01.23.07.04.30 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 23 Jan 2015 07:04:30 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.43 as permitted sender) client-ip=209.85.215.43; Received: by mail-la0-f43.google.com with SMTP id q1so7795416lam.2 for ; Fri, 23 Jan 2015 07:04:30 -0800 (PST) X-Received: by 10.112.180.135 with SMTP id do7mr7682081lbc.23.1422025470182; Fri, 23 Jan 2015 07:04:30 -0800 (PST) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.9.200 with SMTP id c8csp283182lbb; Fri, 23 Jan 2015 07:04:28 -0800 (PST) X-Received: by 10.43.127.198 with SMTP id hb6mr2741317icc.86.1422025463594; Fri, 23 Jan 2015 07:04:23 -0800 (PST) Received: from lists.sourceforge.net (lists.sourceforge.net. [216.34.181.88]) by mx.google.com with ESMTPS id x10si1086562igl.16.2015.01.23.07.04.22 (version=TLSv1 cipher=RC4-SHA bits=128/128); Fri, 23 Jan 2015 07:04:23 -0800 (PST) Received-SPF: pass (google.com: domain of edk2-devel-bounces@lists.sourceforge.net designates 216.34.181.88 as permitted sender) client-ip=216.34.181.88; Received: from localhost ([127.0.0.1] helo=sfs-ml-2.v29.ch3.sourceforge.com) by sfs-ml-2.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1YEfmQ-000373-Lq; Fri, 23 Jan 2015 15:04:14 +0000 Received: from sog-mx-1.v43.ch3.sourceforge.com ([172.29.43.191] helo=mx.sourceforge.net) by sfs-ml-2.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1YEfmP-00036r-GV for edk2-devel@lists.sourceforge.net; Fri, 23 Jan 2015 15:04:13 +0000 Received-SPF: pass (sog-mx-1.v43.ch3.sourceforge.com: domain of linaro.org designates 74.125.82.42 as permitted sender) client-ip=74.125.82.42; envelope-from=ard.biesheuvel@linaro.org; helo=mail-wg0-f42.google.com; Received: from mail-wg0-f42.google.com ([74.125.82.42]) by sog-mx-1.v43.ch3.sourceforge.com with esmtps (TLSv1:RC4-SHA:128) (Exim 4.76) id 1YEfmN-0003Kb-1a for edk2-devel@lists.sourceforge.net; Fri, 23 Jan 2015 15:04:13 +0000 Received: by mail-wg0-f42.google.com with SMTP id x13so8005543wgg.1 for ; Fri, 23 Jan 2015 07:04:05 -0800 (PST) X-Received: by 10.181.28.168 with SMTP id jp8mr4746894wid.40.1422025445016; Fri, 23 Jan 2015 07:04:05 -0800 (PST) Received: from ards-macbook-pro.local ([197.129.136.117]) by mx.google.com with ESMTPSA id pl1sm2176036wic.16.2015.01.23.07.04.02 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 23 Jan 2015 07:04:04 -0800 (PST) From: Ard Biesheuvel To: edk2-devel@lists.sourceforge.net, lersek@redhat.com, olivier.martin@arm.com, roy.franz@linaro.org, leif.lindholm@linaro.org, stefano.stabellini@eu.citrix.com, ian.campbell@citrix.com, anthony.perard@citrix.com, christoffer.dall@linaro.org, xen-devel@lists.xen.org, ilias.biris@linaro.org Date: Fri, 23 Jan 2015 15:03:02 +0000 Message-Id: <1422025390-8036-14-git-send-email-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1422025390-8036-1-git-send-email-ard.biesheuvel@linaro.org> References: <1422025390-8036-1-git-send-email-ard.biesheuvel@linaro.org> X-Spam-Score: -1.5 (-) X-Spam-Report: Spam Filtering performed by mx.sourceforge.net. See http://spamassassin.org/tag/ for more details. -1.5 SPF_CHECK_PASS SPF reports sender host as permitted sender for sender-domain -0.0 SPF_PASS SPF: sender matches SPF record -0.0 AWL AWL: Adjusted score from AWL reputation of From: address X-Headers-End: 1YEfmN-0003Kb-1a Subject: [edk2] [PATCH v1 13/21] Ovmf/Xen: move arch specific hypercall implementation to XenHypercallLib X-BeenThere: edk2-devel@lists.sourceforge.net X-Mailman-Version: 2.1.9 Precedence: list Reply-To: edk2-devel@lists.sourceforge.net List-Id: List-Unsubscribe: , List-Archive: List-Post: , List-Help: , List-Subscribe: , MIME-Version: 1.0 Errors-To: edk2-devel-bounces@lists.sourceforge.net X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: ard.biesheuvel@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.43 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 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 --- OvmfPkg/Include/Library/XenHypercallLib.h | 78 ++++++++++++++ .../XenHypercallLib}/Ia32/hypercall.nasm | 6 +- .../XenHypercallLib}/X64/hypercall.nasm | 6 +- .../XenHypercallLib/XenHypercallLibCommon.c | 63 +++++++++++ .../Library/XenHypercallLib/XenHypercallLibIntel.c | 77 ++++++++++++++ .../XenHypercallLib/XenHypercallLibIntel.inf | 52 +++++++++ OvmfPkg/OvmfPkg.dec | 4 + OvmfPkg/OvmfPkgIa32.dsc | 1 + OvmfPkg/OvmfPkgIa32X64.dsc | 1 + OvmfPkg/OvmfPkgX64.dsc | 1 + OvmfPkg/XenBusDxe/EventChannel.c | 14 +-- OvmfPkg/XenBusDxe/GrantTable.c | 6 +- OvmfPkg/XenBusDxe/XenBusDxe.c | 51 +++++++-- OvmfPkg/XenBusDxe/XenBusDxe.h | 1 - OvmfPkg/XenBusDxe/XenBusDxe.inf | 11 +- OvmfPkg/XenBusDxe/XenHypercall.c | 118 --------------------- OvmfPkg/XenBusDxe/XenHypercall.h | 113 -------------------- OvmfPkg/XenBusDxe/XenStore.c | 6 +- 18 files changed, 338 insertions(+), 271 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/XenHypercallLibCommon.c create mode 100644 OvmfPkg/Library/XenHypercallLib/XenHypercallLibIntel.c create mode 100644 OvmfPkg/Library/XenHypercallLib/XenHypercallLibIntel.inf delete mode 100644 OvmfPkg/XenBusDxe/XenHypercall.c delete mode 100644 OvmfPkg/XenBusDxe/XenHypercall.h diff --git a/OvmfPkg/Include/Library/XenHypercallLib.h b/OvmfPkg/Include/Library/XenHypercallLib.h new file mode 100644 index 000000000000..6c94cbf7f2e6 --- /dev/null +++ b/OvmfPkg/Include/Library/XenHypercallLib.h @@ -0,0 +1,78 @@ +/** @file + Xen Hypercall Library definition + +Copyright (c) 2014, Linaro Ltd. All rights reserved.
+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_ + +/** + Return the value of the HVM parameter Index. + + @param Index The parameter to get, e.g. HVM_PARAM_STORE_EVTCHN. + + @return The value of the asked parameter or 0 in case of error. +**/ +UINT64 +XenHypercallHvmGetParam ( + UINT32 Index + ); + +/** + Hypercall to do different operation on the memory. + + @param Operation The operation number, e.g. XENMEM_add_to_physmap. + @param Arguments The arguments associated to the operation. + + @return Return the return value from the hypercall, 0 in case of success + otherwise, an error code. +**/ +INTN +XenHypercallMemoryOp ( + IN UINTN Operation, + IN OUT VOID *Arguments + ); + +/** + Do an operation on the event channels. + + @param Operation The operation number, e.g. EVTCHNOP_send. + @param Arguments The argument associated to the operation. + + @return Return the return value from the hypercall, 0 in case of success + otherwise, an error code. +**/ +INTN +XenHypercallEventChannelOp ( + IN INTN Operation, + IN OUT VOID *Arguments + ); + +/** + 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/XenHypercallLibCommon.c b/OvmfPkg/Library/XenHypercallLib/XenHypercallLibCommon.c new file mode 100644 index 000000000000..ecc757cf707c --- /dev/null +++ b/OvmfPkg/Library/XenHypercallLib/XenHypercallLibCommon.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 + +#include +#include + +#include +#include + +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/XenHypercallLibIntel.c b/OvmfPkg/Library/XenHypercallLib/XenHypercallLibIntel.c new file mode 100644 index 000000000000..362640f6a16f --- /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.
+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 +#include +#include +#include + +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..db6aab6174b2 --- /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.
+# 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 + +[Sources] + XenHypercallLibCommon.c + +[Packages] + MdePkg/MdePkg.dec + OvmfPkg/OvmfPkg.dec + +[LibraryClasses] + BaseLib + HobLib + DebugLib + +[Guids] + gEfiXenInfoGuid diff --git a/OvmfPkg/OvmfPkg.dec b/OvmfPkg/OvmfPkg.dec index 6eb551a8d436..30a9fb1e9b42 100644 --- a/OvmfPkg/OvmfPkg.dec +++ b/OvmfPkg/OvmfPkg.dec @@ -44,6 +44,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 ca656698754b..90540272745c 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 4b4a1da717c1..0a331eda8be0 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 eb3f34b8350b..e2b37c271681 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/EventChannel.c b/OvmfPkg/XenBusDxe/EventChannel.c index 03efaf9cb904..6a36dca29911 100644 --- a/OvmfPkg/XenBusDxe/EventChannel.c +++ b/OvmfPkg/XenBusDxe/EventChannel.c @@ -16,7 +16,8 @@ **/ #include "EventChannel.h" -#include "XenHypercall.h" + +#include UINT32 XenEventChannelNotify ( @@ -28,7 +29,7 @@ XenEventChannelNotify ( evtchn_send_t Send; Send.port = Port; - ReturnCode = XenHypercallEventChannelOp (Dev, EVTCHNOP_send, &Send); + ReturnCode = XenHypercallEventChannelOp (EVTCHNOP_send, &Send); return (UINT32)ReturnCode; } @@ -40,15 +41,12 @@ XenBusEventChannelAllocate ( OUT evtchn_port_t *Port ) { - XENBUS_PRIVATE_DATA *Private; evtchn_alloc_unbound_t Parameter; UINT32 ReturnCode; - Private = XENBUS_PRIVATE_DATA_FROM_THIS (This); - Parameter.dom = DOMID_SELF; Parameter.remote_dom = DomainId; - ReturnCode = (UINT32)XenHypercallEventChannelOp (Private->Dev, + ReturnCode = (UINT32)XenHypercallEventChannelOp ( EVTCHNOP_alloc_unbound, &Parameter); if (ReturnCode != 0) { @@ -79,10 +77,8 @@ XenBusEventChannelClose ( IN evtchn_port_t Port ) { - XENBUS_PRIVATE_DATA *Private; evtchn_close_t Close; - Private = XENBUS_PRIVATE_DATA_FROM_THIS (This); Close.port = Port; - return (UINT32)XenHypercallEventChannelOp (Private->Dev, EVTCHNOP_close, &Close); + return (UINT32)XenHypercallEventChannelOp (EVTCHNOP_close, &Close); } diff --git a/OvmfPkg/XenBusDxe/GrantTable.c b/OvmfPkg/XenBusDxe/GrantTable.c index cc6f045c9827..52ff045a74db 100644 --- a/OvmfPkg/XenBusDxe/GrantTable.c +++ b/OvmfPkg/XenBusDxe/GrantTable.c @@ -34,7 +34,7 @@ #include -#include "XenHypercall.h" +#include #include "GrantTable.h" #include "InterlockedCompareExchange16.h" @@ -161,7 +161,7 @@ XenGrantTableInit ( Parameters.idx = Index; Parameters.space = XENMAPSPACE_grant_table; Parameters.gpfn = (((xen_pfn_t)(UINTN) GrantTable) >> EFI_PAGE_SHIFT) + Index; - ReturnCode = XenHypercallMemoryOp (Dev, XENMEM_add_to_physmap, &Parameters); + ReturnCode = XenHypercallMemoryOp (XENMEM_add_to_physmap, &Parameters); if (ReturnCode != 0) { DEBUG ((EFI_D_ERROR, "Xen GrantTable, add_to_physmap hypercall error: %d\n", ReturnCode)); } @@ -184,7 +184,7 @@ XenGrantTableDeinit ( Parameters.domid = DOMID_SELF; Parameters.gpfn = (((xen_pfn_t)(UINTN) GrantTable) >> EFI_PAGE_SHIFT) + Index; DEBUG ((EFI_D_INFO, "Xen GrantTable, removing %X\n", Parameters.gpfn)); - ReturnCode = XenHypercallMemoryOp (Dev, XENMEM_remove_from_physmap, &Parameters); + ReturnCode = XenHypercallMemoryOp (XENMEM_remove_from_physmap, &Parameters); if (ReturnCode != 0) { DEBUG ((EFI_D_ERROR, "Xen GrantTable, remove_from_physmap hypercall error: %d\n", ReturnCode)); } diff --git a/OvmfPkg/XenBusDxe/XenBusDxe.c b/OvmfPkg/XenBusDxe/XenBusDxe.c index 7a7fd82d559d..cc334c086c1f 100644 --- a/OvmfPkg/XenBusDxe/XenBusDxe.c +++ b/OvmfPkg/XenBusDxe/XenBusDxe.c @@ -26,14 +26,16 @@ #include #include #include +#include #include "XenBusDxe.h" -#include "XenHypercall.h" #include "GrantTable.h" #include "XenStore.h" #include "XenBus.h" +#include +#include /// /// Driver Binding Protocol instance @@ -52,6 +54,46 @@ 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. @param ImageHandle Handle that identifies the image to be unloaded. @@ -348,13 +390,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 80253b7d1ca9..9b7219906a69 100644 --- a/OvmfPkg/XenBusDxe/XenBusDxe.h +++ b/OvmfPkg/XenBusDxe/XenBusDxe.h @@ -91,7 +91,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..714607dbd6f8 100644 --- a/OvmfPkg/XenBusDxe/XenBusDxe.inf +++ b/OvmfPkg/XenBusDxe/XenBusDxe.inf @@ -34,8 +34,6 @@ DriverBinding.h ComponentName.c ComponentName.h - XenHypercall.c - XenHypercall.h InterlockedCompareExchange16.c InterlockedCompareExchange16.h GrantTable.c @@ -49,12 +47,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 +63,7 @@ UefiLib DevicePathLib DebugLib - HobLib - + XenHypercallLib [Protocols] gEfiDriverBindingProtocolGuid @@ -77,7 +72,3 @@ gEfiComponentNameProtocolGuid gXenBusProtocolGuid - -[Guids] - gEfiXenInfoGuid - diff --git a/OvmfPkg/XenBusDxe/XenHypercall.c b/OvmfPkg/XenBusDxe/XenHypercall.c deleted file mode 100644 index 34d92e76b7e3..000000000000 --- a/OvmfPkg/XenBusDxe/XenHypercall.c +++ /dev/null @@ -1,118 +0,0 @@ -/** @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 -#include -#include - -#include "XenBusDxe.h" -#include "XenHypercall.h" - -#include -#include - -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 UINT32 Index - ) -{ - 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, - 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 ((UINT8*)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 ((UINT8*)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; -} diff --git a/OvmfPkg/XenBusDxe/XenHypercall.h b/OvmfPkg/XenBusDxe/XenHypercall.h deleted file mode 100644 index 06693830e16e..000000000000 --- a/OvmfPkg/XenBusDxe/XenHypercall.h +++ /dev/null @@ -1,113 +0,0 @@ -/** @file - Functions declarations 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. - -**/ - -#ifndef __XENBUS_DXE_HYPERCALL_H__ -#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. - @param Index The parameter to get, e.g. HVM_PARAM_STORE_EVTCHN. - - @return The value of the asked parameter or 0 in case of error. -**/ -UINT64 -XenHypercallHvmGetParam ( - XENBUS_DEVICE *Dev, - UINT32 Index - ); - -/** - Hypercall to do different operation on the memory. - - @param Dev A XENBUS_DEVICE instance. - @param Operation The operation number, e.g. XENMEM_add_to_physmap. - @param Arguments The arguments associated to the operation. - - @return Return the return value from the hypercall, 0 in case of success - otherwise, an error code. -**/ -INTN -XenHypercallMemoryOp ( - IN XENBUS_DEVICE *Dev, - IN UINTN Operation, - IN OUT VOID *Arguments - ); - -/** - Do an operation on the event channels. - - @param Dev A XENBUS_DEVICE instance. - @param Operation The operation number, e.g. EVTCHNOP_send. - @param Arguments The argument associated to the operation. - - @return Return the return value from the hypercall, 0 in case of success - otherwise, an error code. -**/ -INTN -XenHypercallEventChannelOp ( - IN XENBUS_DEVICE *Dev, - IN INTN Operation, - IN OUT VOID *Arguments - ); - -/** - 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. -**/ -EFI_STATUS -XenGetSharedInfoPage ( - IN OUT XENBUS_DEVICE *Dev - ); - -#endif diff --git a/OvmfPkg/XenBusDxe/XenStore.c b/OvmfPkg/XenBusDxe/XenStore.c index 2df8f5348585..9850f1e644fc 100644 --- a/OvmfPkg/XenBusDxe/XenStore.c +++ b/OvmfPkg/XenBusDxe/XenStore.c @@ -60,8 +60,8 @@ #include -#include "XenHypercall.h" #include "EventChannel.h" +#include // // Private Data Structures @@ -1057,8 +1057,8 @@ XenStoreInit ( xs.Dev = Dev; - xs.EventChannel = (evtchn_port_t)XenHypercallHvmGetParam (Dev, HVM_PARAM_STORE_EVTCHN); - XenStoreGpfn = (UINTN)XenHypercallHvmGetParam (Dev, HVM_PARAM_STORE_PFN); + xs.EventChannel = (evtchn_port_t)XenHypercallHvmGetParam (HVM_PARAM_STORE_EVTCHN); + XenStoreGpfn = (UINTN)XenHypercallHvmGetParam (HVM_PARAM_STORE_PFN); xs.XenStore = (VOID *) (XenStoreGpfn << EFI_PAGE_SHIFT); DEBUG ((EFI_D_INFO, "XenBusInit: XenBus rings @%p, event channel %x\n", xs.XenStore, xs.EventChannel));