summaryrefslogtreecommitdiffstats
path: root/OvmfPkg/Library/XenPlatformLib/XenPlatformLib.c
blob: f6b3e5ca7001af9ec99f5cea099491051378b1f7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
/** @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.

  SPDX-License-Identifier: BSD-2-Clause-Patent

**/

#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;
  STATIC BOOLEAN       Cached = FALSE;
  STATIC EFI_XEN_INFO  *XenInfo;

  //
  // Return the cached result for the benefit of XenDetected that can be
  // called many times.
  //
  if (Cached) {
    return XenInfo;
  }

  GuidHob = GetFirstGuidHob (&gEfiXenInfoGuid);
  if (GuidHob == NULL) {
    XenInfo = NULL;
  } else {
    XenInfo = (EFI_XEN_INFO *)GET_GUID_HOB_DATA (GuidHob);
  }

  Cached = TRUE;
  return XenInfo;
}

/**
  This function detects if OVMF is running on Xen.

  @retval TRUE    OVMF is running on Xen
  @retval FALSE   Xen has 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);
}