547c111aae499fc515b0f1bf9f8975d95fe6d68b
[mirror_edk2.git] / OvmfPkg / XenBusDxe / EventChannel.c
1 /** @file
2 Event Channel function implementation.
3
4 Event channel are use to notify of an event that happend in a shared
5 structure for example.
6
7 Copyright (C) 2014, Citrix Ltd.
8
9 This program and the accompanying materials
10 are licensed and made available under the terms and conditions of the BSD License
11 which accompanies this distribution. The full text of the license may be found at
12 http://opensource.org/licenses/bsd-license.php
13
14 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
15 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
16
17 **/
18 #include "EventChannel.h"
19 #include "XenHypercall.h"
20
21 UINT32
22 XenEventChannelNotify (
23 IN XENBUS_DEVICE *Dev,
24 IN evtchn_port_t Port
25 )
26 {
27 INTN ReturnCode;
28 evtchn_send_t Send;
29
30 Send.port = Port;
31 ReturnCode = XenHypercallEventChannelOp (Dev, EVTCHNOP_send, &Send);
32 return ReturnCode;
33 }
34
35 UINT32
36 EFIAPI
37 XenBusEventChannelAllocate (
38 IN XENBUS_PROTOCOL *This,
39 IN domid_t DomainId,
40 OUT evtchn_port_t *Port
41 )
42 {
43 XENBUS_PRIVATE_DATA *Private;
44 evtchn_alloc_unbound_t Parameter;
45 UINT32 ReturnCode;
46
47 Private = XENBUS_PRIVATE_DATA_FROM_THIS (This);
48
49 Parameter.dom = DOMID_SELF;
50 Parameter.remote_dom = DomainId;
51 ReturnCode = XenHypercallEventChannelOp (Private->Dev,
52 EVTCHNOP_alloc_unbound,
53 &Parameter);
54 if (ReturnCode != 0) {
55 DEBUG ((EFI_D_ERROR, "ERROR: alloc_unbound failed with rc=%d", ReturnCode));
56 return ReturnCode;
57 }
58 *Port = Parameter.port;
59 return ReturnCode;
60 }
61
62 UINT32
63 EFIAPI
64 XenBusEventChannelNotify (
65 IN XENBUS_PROTOCOL *This,
66 IN evtchn_port_t Port
67 )
68 {
69 XENBUS_PRIVATE_DATA *Private;
70
71 Private = XENBUS_PRIVATE_DATA_FROM_THIS(This);
72 return XenEventChannelNotify (Private->Dev, Port);
73 }
74
75 UINT32
76 EFIAPI
77 XenBusEventChannelClose (
78 IN XENBUS_PROTOCOL *This,
79 IN evtchn_port_t Port
80 )
81 {
82 XENBUS_PRIVATE_DATA *Private;
83 evtchn_close_t Close;
84
85 Private = XENBUS_PRIVATE_DATA_FROM_THIS (This);
86 Close.port = Port;
87 return XenHypercallEventChannelOp (Private->Dev, EVTCHNOP_close, &Close);
88 }