ia64/xen-unstable

view tools/libxc/xc_evtchn.c @ 2422:2274a0386cc9

bitkeeper revision 1.1159.69.5 (4138e882jA1YaR_OfTfNHe_uT4PDIg)

trivial
author iap10@labyrinth.cl.cam.ac.uk
date Fri Sep 03 21:56:18 2004 +0000 (2004-09-03)
parents bd1640d9d7d4
children 06527e1d6757 77fbe6c094f2
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_bind_interdomain(int xc_handle,
35 u32 dom1,
36 u32 dom2,
37 int *port1,
38 int *port2)
39 {
40 evtchn_op_t op;
41 int rc;
43 op.cmd = EVTCHNOP_bind_interdomain;
44 op.u.bind_interdomain.dom1 = (domid_t)dom1;
45 op.u.bind_interdomain.dom2 = (domid_t)dom2;
47 if ( (rc = do_evtchn_op(xc_handle, &op)) == 0 )
48 {
49 if ( port1 != NULL )
50 *port1 = op.u.bind_interdomain.port1;
51 if ( port2 != NULL )
52 *port2 = op.u.bind_interdomain.port2;
53 }
55 return rc;
56 }
59 int xc_evtchn_bind_virq(int xc_handle,
60 int virq,
61 int *port)
62 {
63 evtchn_op_t op;
64 int rc;
66 op.cmd = EVTCHNOP_bind_virq;
67 op.u.bind_virq.virq = (u32)virq;
69 if ( (rc = do_evtchn_op(xc_handle, &op)) == 0 )
70 {
71 if ( port != NULL )
72 *port = op.u.bind_virq.port;
73 }
75 return rc;
76 }
79 int xc_evtchn_close(int xc_handle,
80 u32 dom,
81 int port)
82 {
83 evtchn_op_t op;
84 op.cmd = EVTCHNOP_close;
85 op.u.close.dom = (domid_t)dom;
86 op.u.close.port = port;
87 return do_evtchn_op(xc_handle, &op);
88 }
91 int xc_evtchn_send(int xc_handle,
92 int local_port)
93 {
94 evtchn_op_t op;
95 op.cmd = EVTCHNOP_send;
96 op.u.send.local_port = local_port;
97 return do_evtchn_op(xc_handle, &op);
98 }
101 int xc_evtchn_status(int xc_handle,
102 u32 dom,
103 int port,
104 xc_evtchn_status_t *status)
105 {
106 evtchn_op_t op;
107 int rc;
109 op.cmd = EVTCHNOP_status;
110 op.u.status.dom = (domid_t)dom;
111 op.u.status.port = port;
113 if ( (rc = do_evtchn_op(xc_handle, &op)) == 0 )
114 {
115 switch ( status->status = op.u.status.status )
116 {
117 case EVTCHNSTAT_interdomain:
118 status->u.interdomain.dom = (u16)op.u.status.u.interdomain.dom;
119 status->u.interdomain.port = op.u.status.u.interdomain.port;
120 break;
121 case EVTCHNSTAT_pirq:
122 status->u.pirq = op.u.status.u.pirq;
123 break;
124 case EVTCHNSTAT_virq:
125 status->u.virq = op.u.status.u.virq;
126 break;
127 }
128 }
130 return rc;
131 }