Similarly to QemuFwCfgLib, we prefer mellow library construction code and
an explicit "are you available" query function in the XenHypercallLib
class. In this step we introduce that query function, but move no client
code to it yet.

Suggested-by: Jordan Justen <jordan.l.jus...@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Laszlo Ersek <ler...@redhat.com>
---
 OvmfPkg/Include/Library/XenHypercallLib.h         | 16 ++++++++++++++++
 OvmfPkg/Library/XenHypercallLib/ArmXenHypercall.c | 19 +++++++++++++++++++
 OvmfPkg/Library/XenHypercallLib/X86XenHypercall.c | 19 +++++++++++++++++++
 3 files changed, 54 insertions(+)

diff --git a/OvmfPkg/Include/Library/XenHypercallLib.h 
b/OvmfPkg/Include/Library/XenHypercallLib.h
index 1a468ea..509855d 100644
--- a/OvmfPkg/Include/Library/XenHypercallLib.h
+++ b/OvmfPkg/Include/Library/XenHypercallLib.h
@@ -17,6 +17,22 @@
 #define __XEN_HYPERCALL_LIB_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
+  );
+
+/**
   This function will put the two arguments in the right place (registers) and
   invoke the hypercall identified by HypercallID.
 
diff --git a/OvmfPkg/Library/XenHypercallLib/ArmXenHypercall.c 
b/OvmfPkg/Library/XenHypercallLib/ArmXenHypercall.c
index 56cc2f6..99a3170 100644
--- a/OvmfPkg/Library/XenHypercallLib/ArmXenHypercall.c
+++ b/OvmfPkg/Library/XenHypercallLib/ArmXenHypercall.c
@@ -15,6 +15,25 @@
 
 #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
 ArmXenHypercallLibInit (
diff --git a/OvmfPkg/Library/XenHypercallLib/X86XenHypercall.c 
b/OvmfPkg/Library/XenHypercallLib/X86XenHypercall.c
index 3ca05c7..14fa175 100644
--- a/OvmfPkg/Library/XenHypercallLib/X86XenHypercall.c
+++ b/OvmfPkg/Library/XenHypercallLib/X86XenHypercall.c
@@ -19,6 +19,25 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER 
EXPRESS OR IMPLIED.
 
 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
 //
-- 
1.8.3.1



------------------------------------------------------------------------------
Dive into the World of Parallel Programming The Go Parallel Website, sponsored
by Intel and developed in partnership with Slashdot Media, is your hub for all
things parallel software development, from weekly thought leadership blogs to
news, videos, case studies, tutorials and more. Take a look and join the 
conversation now. http://goparallel.sourceforge.net/
_______________________________________________
edk2-devel mailing list
edk2-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/edk2-devel

Reply via email to