]> git.proxmox.com Git - mirror_edk2.git/blob - OvmfPkg/Library/XenHypercallLib/X86XenHypercall.c
OvmfPkg: Apply uncrustify changes
[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 RETURN_STATUS
51 EFIAPI
52 XenHypercallLibInit (
53 VOID
54 )
55 {
56 EFI_HOB_GUID_TYPE *GuidHob;
57 EFI_XEN_INFO *XenInfo;
58
59 GuidHob = GetFirstGuidHob (&gEfiXenInfoGuid);
60 if (GuidHob == NULL) {
61 return RETURN_NOT_FOUND;
62 }
63
64 XenInfo = (EFI_XEN_INFO *)GET_GUID_HOB_DATA (GuidHob);
65 HyperPage = XenInfo->HyperPages;
66 return RETURN_SUCCESS;
67 }
68
69 /**
70 This function will put the two arguments in the right place (registers) and
71 invoke the hypercall identified by HypercallID.
72
73 @param HypercallID The symbolic ID of the hypercall to be invoked
74 @param Arg1 First argument.
75 @param Arg2 Second argument.
76
77 @return Return 0 if success otherwise it return an errno.
78 **/
79 INTN
80 EFIAPI
81 XenHypercall2 (
82 IN UINTN HypercallID,
83 IN OUT INTN Arg1,
84 IN OUT INTN Arg2
85 )
86 {
87 ASSERT (HyperPage != NULL);
88
89 return __XenHypercall2 ((UINT8 *)HyperPage + HypercallID * 32, Arg1, Arg2);
90 }