The purpose of XenPlatformPei is to regroup the few functions that are
used in several places to detect if Xen is detected, and to get the
XenInfo HOB.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Anthony PERARD <anthony.per...@citrix.com>
---
 OvmfPkg/XenOvmf.dsc                                                            
                           |  1 +
 MdePkg/Library/BaseSmbusLibNull/BaseSmbusLibNull.inf => 
OvmfPkg/Library/XenPlatformLib/XenPlatformLib.inf | 27 +++----
 OvmfPkg/Include/Library/XenPlatformLib.h                                       
                           | 59 +++++++++++++++
 OvmfPkg/Library/XenPlatformLib/XenPlatformLib.c                                
                           | 75 ++++++++++++++++++++
 4 files changed, 150 insertions(+), 12 deletions(-)

diff --git a/OvmfPkg/XenOvmf.dsc b/OvmfPkg/XenOvmf.dsc
index cc51bac3be..9529b4834f 100644
--- a/OvmfPkg/XenOvmf.dsc
+++ b/OvmfPkg/XenOvmf.dsc
@@ -198,6 +198,7 @@ [LibraryClasses]
   SmbusLib|MdePkg/Library/BaseSmbusLibNull/BaseSmbusLibNull.inf
   
OrderedCollectionLib|MdePkg/Library/BaseOrderedCollectionRedBlackTreeLib/BaseOrderedCollectionRedBlackTreeLib.inf
   XenHypercallLib|OvmfPkg/Library/XenHypercallLib/XenHypercallLib.inf
+  XenPlatformLib|OvmfPkg/Library/XenPlatformLib/XenPlatformLib.inf
 
   
Tcg2PhysicalPresenceLib|OvmfPkg/Library/Tcg2PhysicalPresenceLibNull/DxeTcg2PhysicalPresenceLib.inf
 
diff --git a/MdePkg/Library/BaseSmbusLibNull/BaseSmbusLibNull.inf 
b/OvmfPkg/Library/XenPlatformLib/XenPlatformLib.inf
similarity index 56%
copy from MdePkg/Library/BaseSmbusLibNull/BaseSmbusLibNull.inf
copy to OvmfPkg/Library/XenPlatformLib/XenPlatformLib.inf
index 4fd4874595..ca078f7263 100644
--- a/MdePkg/Library/BaseSmbusLibNull/BaseSmbusLibNull.inf
+++ b/OvmfPkg/Library/XenPlatformLib/XenPlatformLib.inf
@@ -1,7 +1,10 @@
 ## @file
-# Null implementation of the SMBUS Library.
+#  Get information about Xen
 #
-# Copyright (c) 2013 - 2018, Intel Corporation. All rights reserved.<BR>
+#  This library simply allow to find out if OVMF is running under Xen and
+#  allow to get more information when it is the case.
+#
+#  Copyright (c) 2019, Citrix Systems, Inc.
 #
 #  This program and the accompanying materials
 #  are licensed and made available under the terms and conditions of the BSD 
License
@@ -10,26 +13,26 @@
 #  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                      = BaseSmbusLibNull
-  MODULE_UNI_FILE                = BaseSmbusLibNull.uni
-  FILE_GUID                      = E2ECA273-A1C0-407E-9A5C-F10C55142196
+  BASE_NAME                      = XenPlatformLib
+  FILE_GUID                      = DB54DBB7-8142-4EE5-9364-78C824B582EB
   MODULE_TYPE                    = BASE
   VERSION_STRING                 = 1.0
-  LIBRARY_CLASS                  = SmbusLib
-
-#
-#  VALID_ARCHITECTURES           = IA32 X64 EBC
-#
+  LIBRARY_CLASS                  = XenPlatformLib
 
 [Sources]
-  BaseSmbusLibNull.c
+  XenPlatformLib.c
 
 [Packages]
   MdePkg/MdePkg.dec
+  OvmfPkg/OvmfPkg.dec
 
 [LibraryClasses]
-  DebugLib
+  HobLib
+
+[Guids]
+  gEfiXenInfoGuid
diff --git a/OvmfPkg/Include/Library/XenPlatformLib.h 
b/OvmfPkg/Include/Library/XenPlatformLib.h
new file mode 100644
index 0000000000..8f57450575
--- /dev/null
+++ b/OvmfPkg/Include/Library/XenPlatformLib.h
@@ -0,0 +1,59 @@
+/** @file
+*  Get information about Xen
+*
+*  This library simply allow to find out if OVMF is running under Xen and
+*  allow to get more information when it is the case.
+*
+*  Copyright (c) 2019, Citrix Systems, Inc.
+*
+*  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 _XEN_PLATFORM_LIB_H_
+#define _XEN_PLATFORM_LIB_H_
+
+#include <Guid/XenInfo.h>
+
+/**
+  This function detects if OVMF is running on Xen.
+
+  @retval TRUE    OVMF is running on Xen
+  @retval FALSE   Xen as not been detected
+**/
+BOOLEAN
+EFIAPI
+XenDetected (
+  VOID
+  );
+
+/**
+  This function detect if OVMF have started via the PVH entry point.
+
+  @retval TRUE  PVH entry point as been used
+  @retval FALSE OVMF have started via the HVM route
+**/
+BOOLEAN
+EFIAPI
+XenPvhDetected (
+  VOID
+  );
+
+/**
+  This function return a pointer to the XenInfo HOB.
+
+  @return  XenInfo pointer or NULL if not available
+**/
+EFI_XEN_INFO *
+EFIAPI
+XenGetInfoHOB (
+  VOID
+  );
+
+#endif
diff --git a/OvmfPkg/Library/XenPlatformLib/XenPlatformLib.c 
b/OvmfPkg/Library/XenPlatformLib/XenPlatformLib.c
new file mode 100644
index 0000000000..274ddfc9ad
--- /dev/null
+++ b/OvmfPkg/Library/XenPlatformLib/XenPlatformLib.c
@@ -0,0 +1,75 @@
+/** @file
+*  Get information about Xen
+*
+*  This library simply allow to find out if OVMF is running under Xen and
+*  allow to get more information when it is the case.
+*
+*  Copyright (c) 2019, Citrix Systems, Inc.
+*
+*  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 <PiDxe.h>
+#include <Library/HobLib.h>
+#include <Library/XenPlatformLib.h>
+
+/**
+  This function return a pointer to the XenInfo HOB.
+
+  @return  XenInfo pointer or NULL if not available
+**/
+EFI_XEN_INFO *
+EFIAPI
+XenGetInfoHOB (
+  VOID
+  )
+{
+  EFI_HOB_GUID_TYPE  *GuidHob;
+
+  GuidHob = GetFirstGuidHob (&gEfiXenInfoGuid);
+  if (GuidHob == NULL) {
+    return NULL;
+  }
+
+  return (EFI_XEN_INFO *) GET_GUID_HOB_DATA (GuidHob);
+}
+
+/**
+  This function detects if OVMF is running on Xen.
+
+  @retval TRUE    OVMF is running on Xen
+  @retval FALSE   Xen as not been detected
+**/
+BOOLEAN
+EFIAPI
+XenDetected (
+  VOID
+  )
+{
+  return (XenGetInfoHOB () != NULL);
+}
+
+/**
+  This function detect if OVMF have started via the PVH entry point.
+
+  @retval TRUE  PVH entry point as been used
+  @retval FALSE OVMF have started via the HVM route
+**/
+BOOLEAN
+EFIAPI
+XenPvhDetected (
+  VOID
+  )
+{
+  EFI_XEN_INFO        *XenInfo;
+
+  XenInfo = XenGetInfoHOB ();
+  return (XenInfo != NULL && XenInfo->RsdpPvh != NULL);
+}
-- 
Anthony PERARD


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

Reply via email to