]> git.proxmox.com Git - mirror_edk2.git/blob - OvmfPkg/Library/XenHypercallLib/X86XenHypercall.c
OvmfPkg: Replace BSD License with BSD+Patent License
[mirror_edk2.git] / OvmfPkg / Library / XenHypercallLib / X86XenHypercall.c
1 /** @file
2 Xen Hypercall Library implementation for Intel architecture
3
4 Copyright (c) 2014, Linaro Ltd. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
6
7 **/
8
9 #include <PiDxe.h>
10 #include <Library/HobLib.h>
11 #include <Library/DebugLib.h>
12 #include <Guid/XenInfo.h>
13
14 STATIC VOID *HyperPage;
15
16 /**
17 Check if the Xen Hypercall library is able to make calls to the Xen
18 hypervisor.
19
20 Client code should call further functions in this library only if, and after,
21 this function returns TRUE.
22
23 @retval TRUE Hypercalls are available.
24 @retval FALSE Hypercalls are not available.
25 **/
26 BOOLEAN
27 EFIAPI
28 XenHypercallIsAvailable (
29 VOID
30 )
31 {
32 return HyperPage != NULL;
33 }
34
35 //
36 // Interface exposed by the ASM implementation of the core hypercall
37 //
38 INTN
39 EFIAPI
40 __XenHypercall2 (
41 IN VOID *HypercallAddr,
42 IN OUT INTN Arg1,
43 IN OUT INTN Arg2
44 );
45
46 /**
47 Library constructor: retrieves the Hyperpage address
48 from the gEfiXenInfoGuid HOB
49 **/
50
51 RETURN_STATUS
52 EFIAPI
53 XenHypercallLibInit (
54 VOID
55 )
56 {
57 EFI_HOB_GUID_TYPE *GuidHob;
58 EFI_XEN_INFO *XenInfo;
59
60 GuidHob = GetFirstGuidHob (&gEfiXenInfoGuid);
61 if (GuidHob == NULL) {
62 //
63 // We don't fail library construction, since that has catastrophic
64 // consequences for client modules (whereas those modules may easily be
65 // running on a non-Xen platform). Instead, XenHypercallIsAvailable() above
66 // will return FALSE.
67 //
68 return RETURN_SUCCESS;
69 }
70 XenInfo = (EFI_XEN_INFO *) GET_GUID_HOB_DATA (GuidHob);
71 HyperPage = XenInfo->HyperPages;
72 return RETURN_SUCCESS;
73 }
74
75 /**
76 This function will put the two arguments in the right place (registers) and
77 invoke the hypercall identified by HypercallID.
78
79 @param HypercallID The symbolic ID of the hypercall to be invoked
80 @param Arg1 First argument.
81 @param Arg2 Second argument.
82
83 @return Return 0 if success otherwise it return an errno.
84 **/
85 INTN
86 EFIAPI
87 XenHypercall2 (
88 IN UINTN HypercallID,
89 IN OUT INTN Arg1,
90 IN OUT INTN Arg2
91 )
92 {
93 ASSERT (HyperPage != NULL);
94
95 return __XenHypercall2 ((UINT8*)HyperPage + HypercallID * 32, Arg1, Arg2);
96 }