diff mbox

[edk2] Ovmf/Xen: avoid calling XenHypercallLib constructor on !Xen

Message ID 1425316402-4687-1-git-send-email-ard.biesheuvel@linaro.org
State New
Headers show

Commit Message

Ard Biesheuvel March 2, 2015, 5:13 p.m. UTC
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 <ard.biesheuvel@linaro.org>
---
 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 mbox

Patch

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.<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 <Uefi/UefiBaseType.h>
+#include <Library/XenHypercallLib.h>
+
+/**
+  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"));