]> git.proxmox.com Git - mirror_edk2.git/blob - OvmfPkg/XenBusDxe/XenHypercall.c
Ovmf/Xen: refactor XenBusDxe hypercall implementation
[mirror_edk2.git] / OvmfPkg / XenBusDxe / XenHypercall.c
1 /** @file
2 Functions to make Xen hypercalls.
3
4 Copyright (C) 2014, Citrix Ltd.
5
6 This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
10
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
13
14 **/
15
16 #include <PiDxe.h>
17 #include <Library/HobLib.h>
18 #include <Guid/XenInfo.h>
19
20 #include "XenBusDxe.h"
21 #include "XenHypercall.h"
22
23 #include <IndustryStandard/Xen/hvm/params.h>
24 #include <IndustryStandard/Xen/memory.h>
25
26 STATIC VOID *HyperPage;
27
28 //
29 // Interface exposed by the ASM implementation of the core hypercall
30 //
31 INTN
32 EFIAPI
33 __XenHypercall2 (
34 IN VOID *HypercallAddr,
35 IN OUT INTN Arg1,
36 IN OUT INTN Arg2
37 );
38
39 EFI_STATUS
40 XenHyperpageInit (
41 )
42 {
43 EFI_HOB_GUID_TYPE *GuidHob;
44 EFI_XEN_INFO *XenInfo;
45
46 GuidHob = GetFirstGuidHob (&gEfiXenInfoGuid);
47 if (GuidHob == NULL) {
48 return EFI_NOT_FOUND;
49 }
50 XenInfo = (EFI_XEN_INFO *) GET_GUID_HOB_DATA (GuidHob);
51 HyperPage = XenInfo->HyperPages;
52 return EFI_SUCCESS;
53 }
54
55 UINT64
56 XenHypercallHvmGetParam (
57 IN UINT32 Index
58 )
59 {
60 xen_hvm_param_t Parameter;
61 INTN Error;
62
63 Parameter.domid = DOMID_SELF;
64 Parameter.index = Index;
65 Error = XenHypercall2 (__HYPERVISOR_hvm_op,
66 HVMOP_get_param, (INTN) &Parameter);
67 if (Error != 0) {
68 DEBUG ((EFI_D_ERROR,
69 "XenHypercall: Error %d trying to get HVM parameter %d\n",
70 Error, Index));
71 return 0;
72 }
73 return Parameter.value;
74 }
75
76 INTN
77 XenHypercallMemoryOp (
78 IN UINTN Operation,
79 IN OUT VOID *Arguments
80 )
81 {
82 return XenHypercall2 (__HYPERVISOR_memory_op,
83 Operation, (INTN) Arguments);
84 }
85
86 INTN
87 XenHypercallEventChannelOp (
88 IN INTN Operation,
89 IN OUT VOID *Arguments
90 )
91 {
92 return XenHypercall2 (__HYPERVISOR_event_channel_op,
93 Operation, (INTN) Arguments);
94 }
95
96 INTN
97 EFIAPI
98 XenHypercall2 (
99 IN UINTN HypercallID,
100 IN OUT INTN Arg1,
101 IN OUT INTN Arg2
102 )
103 {
104 ASSERT (HyperPage != NULL);
105
106 return __XenHypercall2 ((UINT8*)HyperPage + HypercallID * 32, Arg1, Arg2);
107 }