From patchwork Mon Mar 2 17:13:22 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 45299 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-la0-f69.google.com (mail-la0-f69.google.com [209.85.215.69]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 4DAF3214B5 for ; Mon, 2 Mar 2015 17:13:50 +0000 (UTC) Received: by labhs14 with SMTP id hs14sf9703620lab.0 for ; Mon, 02 Mar 2015 09:13:49 -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: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=kKSbybjv+Wzhyg/3ubrKd3uKDFYG1ohzAPsgwLjRLGg=; b=jQ53VCS4tRTFLu/5eAJkd2TydvVRsTgQR+IrYYuKghlzWL3BxWu0iuX5wB/eKuKiuN vgiEXs7b38x48GPM/+JJcA6MLHK9rKS2kKAqxOrDrUK57U5z8mlKYO6rtyIBPr6gr4kg e6zhrVec5KyUrrdFyxmMVTwSLbTqTioM9/kVmzfeXJpB1/+J9DnXWY55FeDac/6/E3GI 8UxLSExKDITjPTCtIhbYZzpW/Up3DnrNxnVDVC67KqVzBUq83zDwMSXRr6laxOoU8Aki 5wwsBu8iPlSa4SQNzHIYSl6niOL+p3KHD/xeguCoEaPq35rDesNhrmHRjf0TK3fQBuqZ cSHg== X-Gm-Message-State: ALoCoQkPAUi+L0sfUUVyfHxULCiCjWlWnuTEFJle7Pxf+om7EWR1Dsboxwfyz0zHYkxckwQtiWwe X-Received: by 10.112.181.198 with SMTP id dy6mr4057314lbc.22.1425316429117; Mon, 02 Mar 2015 09:13:49 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.153.7.172 with SMTP id dd12ls518251lad.20.gmail; Mon, 02 Mar 2015 09:13:49 -0800 (PST) X-Received: by 10.152.36.226 with SMTP id t2mr6845628laj.53.1425316428969; Mon, 02 Mar 2015 09:13:48 -0800 (PST) Received: from mail-lb0-f173.google.com (mail-lb0-f173.google.com. [209.85.217.173]) by mx.google.com with ESMTPS id r6si9221609lbf.165.2015.03.02.09.13.48 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 02 Mar 2015 09:13:48 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.173 as permitted sender) client-ip=209.85.217.173; Received: by lbiv13 with SMTP id v13so12699344lbi.11 for ; Mon, 02 Mar 2015 09:13:48 -0800 (PST) X-Received: by 10.152.22.67 with SMTP id b3mr24754636laf.117.1425316428804; Mon, 02 Mar 2015 09:13:48 -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.35.133 with SMTP id h5csp39604lbj; Mon, 2 Mar 2015 09:13:47 -0800 (PST) X-Received: by 10.50.93.70 with SMTP id cs6mr22290560igb.6.1425316427075; Mon, 02 Mar 2015 09:13:47 -0800 (PST) Received: from lists.sourceforge.net (lists.sourceforge.net. [216.34.181.88]) by mx.google.com with ESMTPS id z2si7512956ick.66.2015.03.02.09.13.46 (version=TLSv1 cipher=RC4-SHA bits=128/128); Mon, 02 Mar 2015 09:13:47 -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 1YSTuS-0006tG-Fm; Mon, 02 Mar 2015 17:13:36 +0000 Received: from sog-mx-2.v43.ch3.sourceforge.com ([172.29.43.192] helo=mx.sourceforge.net) by sfs-ml-2.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1YSTuR-0006tA-KI for edk2-devel@lists.sourceforge.net; Mon, 02 Mar 2015 17:13:35 +0000 Received-SPF: pass (sog-mx-2.v43.ch3.sourceforge.com: domain of linaro.org designates 74.125.82.178 as permitted sender) client-ip=74.125.82.178; envelope-from=ard.biesheuvel@linaro.org; helo=mail-we0-f178.google.com; Received: from mail-we0-f178.google.com ([74.125.82.178]) by sog-mx-2.v43.ch3.sourceforge.com with esmtps (TLSv1:RC4-SHA:128) (Exim 4.76) id 1YSTuQ-0006dG-7C for edk2-devel@lists.sourceforge.net; Mon, 02 Mar 2015 17:13:35 +0000 Received: by wevm14 with SMTP id m14so34646633wev.13 for ; Mon, 02 Mar 2015 09:13:28 -0800 (PST) X-Received: by 10.180.189.37 with SMTP id gf5mr37945989wic.86.1425316408217; Mon, 02 Mar 2015 09:13:28 -0800 (PST) Received: from ards-macbook-pro.local ([213.143.61.132]) by mx.google.com with ESMTPSA id v6sm16922407wix.8.2015.03.02.09.13.26 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 02 Mar 2015 09:13:27 -0800 (PST) From: Ard Biesheuvel To: lersek@redhat.com, edk2-devel@lists.sourceforge.net, gsomlo@gmail.com Date: Mon, 2 Mar 2015 17:13:22 +0000 Message-Id: <1425316402-4687-1-git-send-email-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 1.8.3.2 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 X-Headers-End: 1YSTuQ-0006dG-7C Subject: [edk2] [PATCH] Ovmf/Xen: avoid calling XenHypercallLib constructor on !Xen 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.217.173 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 This refactors the XenHypercallLib implementation for ARM and x86, and their callers, so that the init code for the XenHypercallLib is only called in places where we have already established that we are running as a Xen guest, or (in the XenConsoleSerialPortLib case) where ARM is the only user of the library, and its init code is a nop. Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Ard Biesheuvel --- OvmfPkg/Include/Library/XenHypercallLib.h | 12 +++++++++ .../XenConsoleSerialPortLib.c | 7 +++++ OvmfPkg/Library/XenHypercallLib/XenHypercallArm.c | 30 ++++++++++++++++++++++ .../Library/XenHypercallLib/XenHypercallIntel.c | 8 +++--- .../Library/XenHypercallLib/XenHypercallLibArm.inf | 1 + .../XenHypercallLib/XenHypercallLibIntel.inf | 1 - OvmfPkg/XenBusDxe/XenBusDxe.c | 7 +++++ 7 files changed, 61 insertions(+), 5 deletions(-) create mode 100644 OvmfPkg/Library/XenHypercallLib/XenHypercallArm.c diff --git a/OvmfPkg/Include/Library/XenHypercallLib.h b/OvmfPkg/Include/Library/XenHypercallLib.h index 1a468ea7dcc5..0e4b13d5397a 100644 --- a/OvmfPkg/Include/Library/XenHypercallLib.h +++ b/OvmfPkg/Include/Library/XenHypercallLib.h @@ -17,6 +17,18 @@ #define __XEN_HYPERCALL_LIB_H__ /** + Initialize the Xen hypercall library + + @return EFI_SUCCESS on success, or an EFI_xxx return code appropriate + for the failure mode on failure. +**/ +EFI_STATUS +EFIAPI +XenHypercallLibInit ( + VOID + ); + +/** This function will put the two arguments in the right place (registers) and invoke the hypercall identified by HypercallID. diff --git a/OvmfPkg/Library/XenConsoleSerialPortLib/XenConsoleSerialPortLib.c b/OvmfPkg/Library/XenConsoleSerialPortLib/XenConsoleSerialPortLib.c index 98022354cf31..5bf588f75246 100644 --- a/OvmfPkg/Library/XenConsoleSerialPortLib/XenConsoleSerialPortLib.c +++ b/OvmfPkg/Library/XenConsoleSerialPortLib/XenConsoleSerialPortLib.c @@ -40,6 +40,13 @@ SerialPortInitialize ( VOID ) { + EFI_STATUS Status; + + Status = XenHypercallLibInit (); + if (EFI_ERROR (Status)) { + return RETURN_DEVICE_ERROR; + } + if (!mXenConsoleInterface) { mXenConsoleEventChain.port = (UINT32)XenHypercallHvmGetParam (HVM_PARAM_CONSOLE_EVTCHN); mXenConsoleInterface = (struct xencons_interface *)(UINTN) diff --git a/OvmfPkg/Library/XenHypercallLib/XenHypercallArm.c b/OvmfPkg/Library/XenHypercallLib/XenHypercallArm.c new file mode 100644 index 000000000000..d2a91b7ed6c7 --- /dev/null +++ b/OvmfPkg/Library/XenHypercallLib/XenHypercallArm.c @@ -0,0 +1,30 @@ +/** @file + Xen Hypercall Library implementation for ARM architecture + +Copyright (c) 2015, 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 + +/** + Library constructor: retrieves the Hyperpage address + from the gEfiXenInfoGuid HOB +**/ + +EFI_STATUS +EFIAPI +XenHypercallLibInit ( + VOID + ) +{ + return EFI_SUCCESS; +} diff --git a/OvmfPkg/Library/XenHypercallLib/XenHypercallIntel.c b/OvmfPkg/Library/XenHypercallLib/XenHypercallIntel.c index fc52823f239a..a4ec4924bd7e 100644 --- a/OvmfPkg/Library/XenHypercallLib/XenHypercallIntel.c +++ b/OvmfPkg/Library/XenHypercallLib/XenHypercallIntel.c @@ -35,9 +35,9 @@ __XenHypercall2 ( from the gEfiXenInfoGuid HOB **/ -RETURN_STATUS +EFI_STATUS EFIAPI -XenHypercallLibIntelInit ( +XenHypercallLibInit ( VOID ) { @@ -46,11 +46,11 @@ XenHypercallLibIntelInit ( GuidHob = GetFirstGuidHob (&gEfiXenInfoGuid); if (GuidHob == NULL) { - return RETURN_NOT_FOUND; + return EFI_NOT_FOUND; } XenInfo = (EFI_XEN_INFO *) GET_GUID_HOB_DATA (GuidHob); HyperPage = XenInfo->HyperPages; - return RETURN_SUCCESS; + return EFI_SUCCESS; } /** diff --git a/OvmfPkg/Library/XenHypercallLib/XenHypercallLibArm.inf b/OvmfPkg/Library/XenHypercallLib/XenHypercallLibArm.inf index 9cbbeb5d8789..e1e784a83d74 100644 --- a/OvmfPkg/Library/XenHypercallLib/XenHypercallLibArm.inf +++ b/OvmfPkg/Library/XenHypercallLib/XenHypercallLibArm.inf @@ -34,6 +34,7 @@ [Sources] XenHypercall.c + XenHypercallArm.c [Packages] MdePkg/MdePkg.dec diff --git a/OvmfPkg/Library/XenHypercallLib/XenHypercallLibIntel.inf b/OvmfPkg/Library/XenHypercallLib/XenHypercallLibIntel.inf index 2afd608f4a05..0afccac0994e 100644 --- a/OvmfPkg/Library/XenHypercallLib/XenHypercallLibIntel.inf +++ b/OvmfPkg/Library/XenHypercallLib/XenHypercallLibIntel.inf @@ -19,7 +19,6 @@ 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. diff --git a/OvmfPkg/XenBusDxe/XenBusDxe.c b/OvmfPkg/XenBusDxe/XenBusDxe.c index 2c4a08673ce6..fd18a1707c2c 100644 --- a/OvmfPkg/XenBusDxe/XenBusDxe.c +++ b/OvmfPkg/XenBusDxe/XenBusDxe.c @@ -361,6 +361,13 @@ XenBusDxeDriverBindingStart ( mMyDevice = Dev; EfiReleaseLock (&mMyDeviceLock); + Status = XenHypercallLibInit (); + if (EFI_ERROR (Status)) { + DEBUG ((EFI_D_ERROR, "XenBus: XenHypercallLibInit () failed.\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"));