direct-io.hg

view tools/libxc/xc_evtchn.c @ 2787:a5c335665fd6

bitkeeper revision 1.1159.142.2 (41849fadYlUYMwSy6tcq8Y-Yi8NMZA)

Clean up libxc by allowing direct use of Xen headers from userland:
#include <xen/...>
author kaf24@freefall.cl.cam.ac.uk
date Sun Oct 31 08:17:49 2004 +0000 (2004-10-31)
parents 77fbe6c094f2
children 3f929065a1d1
line source
1 /******************************************************************************
2 * xc_evtchn.c
3 *
4 * API for manipulating and accessing inter-domain event channels.
5 *
6 * Copyright (c) 2004, K A Fraser.
7 */
9 #include "xc_private.h"
12 static int do_evtchn_op(int xc_handle, evtchn_op_t *op)
13 {
14 int ret = -1;
15 privcmd_hypercall_t hypercall;
17 hypercall.op = __HYPERVISOR_event_channel_op;
18 hypercall.arg[0] = (unsigned long)op;
20 if ( mlock(op, sizeof(*op)) != 0 )
21 {
22 PERROR("Could not lock memory for Xen hypercall");
23 goto out1;
24 }
26 if ( (ret = do_xen_hypercall(xc_handle, &hypercall)) < 0 )
27 goto out2;
29 out2: (void)munlock(op, sizeof(*op));
30 out1: return ret;
31 }
34 int xc_evtchn_alloc_unbound(int xc_handle,
35 u32 dom,
36 int *port)
37 {
38 evtchn_op_t op;
39 int rc;
41 op.cmd = EVTCHNOP_alloc_unbound;
42 op.u.alloc_unbound.dom = (domid_t)dom;
44 if ( (rc = do_evtchn_op(xc_handle, &op)) == 0 )
45 {
46 if ( port != NULL )
47 *port = op.u.alloc_unbound.port;
48 }
50 return rc;
51 }
54 int xc_evtchn_bind_interdomain(int xc_handle,
55 u32 dom1,
56 u32 dom2,
57 int *port1,
58 int *port2)
59 {
60 evtchn_op_t op;
61 int rc;
63 op.cmd = EVTCHNOP_bind_interdomain;
64 op.u.bind_interdomain.dom1 = (domid_t)dom1;
65 op.u.bind_interdomain.dom2 = (domid_t)dom2;
66 op.u.bind_interdomain.port1 = (port1 != NULL) ? *port1 : 0;
67 op.u.bind_interdomain.port2 = (port2 != NULL) ? *port2 : 0;
70 if ( (rc = do_evtchn_op(xc_handle, &op)) == 0 )
71 {
72 if ( port1 != NULL )
73 *port1 = op.u.bind_interdomain.port1;
74 if ( port2 != NULL )
75 *port2 = op.u.bind_interdomain.port2;
76 }
78 return rc;
79 }
82 int xc_evtchn_bind_virq(int xc_handle,
83 int virq,
84 int *port)
85 {
86 evtchn_op_t op;
87 int rc;
89 op.cmd = EVTCHNOP_bind_virq;
90 op.u.bind_virq.virq = (u32)virq;
92 if ( (rc = do_evtchn_op(xc_handle, &op)) == 0 )
93 {
94 if ( port != NULL )
95 *port = op.u.bind_virq.port;
96 }
98 return rc;
99 }
102 int xc_evtchn_close(int xc_handle,
103 u32 dom,
104 int port)
105 {
106 evtchn_op_t op;
107 op.cmd = EVTCHNOP_close;
108 op.u.close.dom = (domid_t)dom;
109 op.u.close.port = port;
110 return do_evtchn_op(xc_handle, &op);
111 }
114 int xc_evtchn_send(int xc_handle,
115 int local_port)
116 {
117 evtchn_op_t op;
118 op.cmd = EVTCHNOP_send;
119 op.u.send.local_port = local_port;
120 return do_evtchn_op(xc_handle, &op);
121 }
124 int xc_evtchn_status(int xc_handle,
125 u32 dom,
126 int port,
127 xc_evtchn_status_t *status)
128 {
129 evtchn_op_t op;
130 int rc;
132 op.cmd = EVTCHNOP_status;
133 op.u.status.dom = (domid_t)dom;
134 op.u.status.port = port;
136 if ( (rc = do_evtchn_op(xc_handle, &op)) == 0 )
137 memcpy(status, &op.u.status, sizeof(*status));
139 return rc;
140 }