]> git.proxmox.com Git - mirror_edk2.git/blob - OvmfPkg/Library/XenPlatformLib/XenPlatformLib.c
OvmfPkg/Library/XenPlatformLib: New library
[mirror_edk2.git] / OvmfPkg / Library / XenPlatformLib / XenPlatformLib.c
1 /** @file
2 Get information about Xen
3
4 This library simply allow to find out if OVMF is running under Xen and
5 allow to get more information when it is the case.
6
7 Copyright (c) 2019, Citrix Systems, Inc.
8
9 SPDX-License-Identifier: BSD-2-Clause-Patent
10
11 **/
12
13 #include <PiDxe.h>
14 #include <Library/HobLib.h>
15 #include <Library/XenPlatformLib.h>
16
17 /**
18 This function return a pointer to the XenInfo HOB.
19
20 @return XenInfo pointer or NULL if not available
21 **/
22 EFI_XEN_INFO *
23 EFIAPI
24 XenGetInfoHOB (
25 VOID
26 )
27 {
28 EFI_HOB_GUID_TYPE *GuidHob;
29
30 GuidHob = GetFirstGuidHob (&gEfiXenInfoGuid);
31 if (GuidHob == NULL) {
32 return NULL;
33 }
34
35 return (EFI_XEN_INFO *) GET_GUID_HOB_DATA (GuidHob);
36 }
37
38 /**
39 This function detects if OVMF is running on Xen.
40
41 @retval TRUE OVMF is running on Xen
42 @retval FALSE Xen has not been detected
43 **/
44 BOOLEAN
45 EFIAPI
46 XenDetected (
47 VOID
48 )
49 {
50 return (XenGetInfoHOB () != NULL);
51 }
52
53 /**
54 This function detect if OVMF have started via the PVH entry point.
55
56 @retval TRUE PVH entry point as been used
57 @retval FALSE OVMF have started via the HVM route
58 **/
59 BOOLEAN
60 EFIAPI
61 XenPvhDetected (
62 VOID
63 )
64 {
65 EFI_XEN_INFO *XenInfo;
66
67 XenInfo = XenGetInfoHOB ();
68 return (XenInfo != NULL && XenInfo->RsdpPvh != NULL);
69 }