aboutsummaryrefslogtreecommitdiffstats
path: root/tools/libxc/xc_evtchn.c
blob: f7698d354187acc93dcc1a6e663fc55104d9f1a8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
/******************************************************************************
 * xc_evtchn.c
 * 
 * API for manipulating and accessing inter-domain event channels.
 * 
 * Copyright (c) 2004, K A Fraser.
 */

#include "xc_private.h"


static int do_evtchn_op(int xc_handle, evtchn_op_t *op)
{
    int ret = -1;
    privcmd_hypercall_t hypercall;

    hypercall.op     = __HYPERVISOR_event_channel_op;
    hypercall.arg[0] = (unsigned long)op;

    if ( mlock(op, sizeof(*op)) != 0 )
    {
        PERROR("do_evtchn_op: op mlock failed");
        goto out;
    }

    if ((ret = do_xen_hypercall(xc_handle, &hypercall)) < 0)
        ERROR("do_evtchn_op: HYPERVISOR_event_channel_op failed: %d", ret);

    safe_munlock(op, sizeof(*op));
 out:
    return ret;
}


int xc_evtchn_alloc_unbound(int xc_handle,
                            u32 dom,
                            int *port)
{
    evtchn_op_t op;
    int         rc;

    op.cmd = EVTCHNOP_alloc_unbound;
    op.u.alloc_unbound.dom  = (domid_t)dom;
    op.u.alloc_unbound.port = (port != NULL) ? *port : 0;

    if ( (rc = do_evtchn_op(xc_handle, &op)) == 0 )
    {
        if ( port != NULL )
            *port = op.u.alloc_unbound.port;
    }
    
    return rc;
}


int xc_evtchn_bind_interdomain(int xc_handle,
                               u32 dom1,
                               u32 dom2,
                               int *port1,
                               int *port2)
{
    evtchn_op_t op;
    int         rc;

    op.cmd = EVTCHNOP_bind_interdomain;
    op.u.bind_interdomain.dom1  = (domid_t)dom1;
    op.u.bind_interdomain.dom2  = (domid_t)dom2;
    op.u.bind_interdomain.port1 = (port1 != NULL) ? *port1 : 0;
    op.u.bind_interdomain.port2 = (port2 != NULL) ? *port2 : 0;


    if ( (rc = do_evtchn_op(xc_handle, &op)) == 0 )
    {
        if ( port1 != NULL )
            *port1 = op.u.bind_interdomain.port1;
        if ( port2 != NULL )
            *port2 = op.u.bind_interdomain.port2;
    }
    
    return rc;
}


int xc_evtchn_bind_virq(int xc_handle,
                        int virq,
                        int *port)
{
    evtchn_op_t op;
    int         rc;

    op.cmd = EVTCHNOP_bind_virq;
    op.u.bind_virq.virq = (u32)virq;
    op.u.bind_virq.vcpu = 0;

    if ( (rc = do_evtchn_op(xc_handle, &op)) == 0 )
    {
        if ( port != NULL )
            *port = op.u.bind_virq.port;
    }
    
    return rc;
}


int xc_evtchn_close(int xc_handle,
                    u32 dom,
                    int port)
{
    evtchn_op_t op;
    op.cmd = EVTCHNOP_close;
    op.u.close.dom  = (domid_t)dom;
    op.u.close.port = port;
    return do_evtchn_op(xc_handle, &op);
}


int xc_evtchn_send(int xc_handle,
                   int local_port)
{
    evtchn_op_t op;
    op.cmd = EVTCHNOP_send;
    op.u.send.local_port = local_port;
    return do_evtchn_op(xc_handle, &op);
}


int xc_evtchn_status(int xc_handle,
                     u32 dom,
                     int port,
                     xc_evtchn_status_t *status)
{
    evtchn_op_t op;
    int         rc;

    op.cmd = EVTCHNOP_status;
    op.u.status.dom  = (domid_t)dom;
    op.u.status.port = port;
   
    if ( (rc = do_evtchn_op(xc_handle, &op)) == 0 )
        memcpy(status, &op.u.status, sizeof(*status));
    
    return rc;
}