]> git.proxmox.com Git - mirror_edk2.git/blame - OvmfPkg/Library/XenHypercallLib/X86XenHypercall.c
OvmfPkg: XenHypercallLib: introduce XenHypercallIsAvailable()
[mirror_edk2.git] / OvmfPkg / Library / XenHypercallLib / X86XenHypercall.c
CommitLineData
cd8ff8fd
AB
1/** @file\r
2 Xen Hypercall Library implementation for Intel architecture\r
3\r
4Copyright (c) 2014, Linaro Ltd. All rights reserved.<BR>\r
5This program and the accompanying materials are licensed and made available under\r
6the terms and conditions of the BSD License that accompanies this distribution.\r
7The full text of the license may be found at\r
8http://opensource.org/licenses/bsd-license.php.\r
9\r
10THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
12\r
13**/\r
14\r
15#include <PiDxe.h>\r
16#include <Library/HobLib.h>\r
17#include <Library/DebugLib.h>\r
18#include <Guid/XenInfo.h>\r
19\r
20STATIC VOID *HyperPage;\r
21\r
02f69a25
LE
22/**\r
23 Check if the Xen Hypercall library is able to make calls to the Xen\r
24 hypervisor.\r
25\r
26 Client code should call further functions in this library only if, and after,\r
27 this function returns TRUE.\r
28\r
29 @retval TRUE Hypercalls are available.\r
30 @retval FALSE Hypercalls are not available.\r
31**/\r
32BOOLEAN\r
33EFIAPI\r
34XenHypercallIsAvailable (\r
35 VOID\r
36 )\r
37{\r
38 return HyperPage != NULL;\r
39}\r
40\r
cd8ff8fd
AB
41//\r
42// Interface exposed by the ASM implementation of the core hypercall\r
43//\r
44INTN\r
45EFIAPI\r
46__XenHypercall2 (\r
47 IN VOID *HypercallAddr,\r
48 IN OUT INTN Arg1,\r
49 IN OUT INTN Arg2\r
50 );\r
51\r
52/**\r
53 Library constructor: retrieves the Hyperpage address\r
54 from the gEfiXenInfoGuid HOB\r
55**/\r
56\r
57RETURN_STATUS\r
58EFIAPI\r
df040c00 59XenHypercallLibInit (\r
cd8ff8fd
AB
60 VOID\r
61 )\r
62{\r
63 EFI_HOB_GUID_TYPE *GuidHob;\r
64 EFI_XEN_INFO *XenInfo;\r
65\r
66 GuidHob = GetFirstGuidHob (&gEfiXenInfoGuid);\r
67 if (GuidHob == NULL) {\r
68 return RETURN_NOT_FOUND;\r
69 }\r
70 XenInfo = (EFI_XEN_INFO *) GET_GUID_HOB_DATA (GuidHob);\r
71 HyperPage = XenInfo->HyperPages;\r
72 return RETURN_SUCCESS;\r
73}\r
74\r
75/**\r
76 This function will put the two arguments in the right place (registers) and\r
77 invoke the hypercall identified by HypercallID.\r
78\r
79 @param HypercallID The symbolic ID of the hypercall to be invoked\r
80 @param Arg1 First argument.\r
81 @param Arg2 Second argument.\r
82\r
83 @return Return 0 if success otherwise it return an errno.\r
84**/\r
85INTN\r
86EFIAPI\r
87XenHypercall2 (\r
88 IN UINTN HypercallID,\r
89 IN OUT INTN Arg1,\r
90 IN OUT INTN Arg2\r
91 )\r
92{\r
93 ASSERT (HyperPage != NULL);\r
94\r
95 return __XenHypercall2 ((UINT8*)HyperPage + HypercallID * 32, Arg1, Arg2);\r
96}\r