Coverage Report

Created: 2017-10-25 09:10

/root/src/xen/xen/include/public/event_channel.h
Line
Count
Source (jump to first uncovered line)
1
/******************************************************************************
2
 * event_channel.h
3
 *
4
 * Event channels between domains.
5
 *
6
 * Permission is hereby granted, free of charge, to any person obtaining a copy
7
 * of this software and associated documentation files (the "Software"), to
8
 * deal in the Software without restriction, including without limitation the
9
 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10
 * sell copies of the Software, and to permit persons to whom the Software is
11
 * furnished to do so, subject to the following conditions:
12
 *
13
 * The above copyright notice and this permission notice shall be included in
14
 * all copies or substantial portions of the Software.
15
 *
16
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22
 * DEALINGS IN THE SOFTWARE.
23
 *
24
 * Copyright (c) 2003-2004, K A Fraser.
25
 */
26
27
#ifndef __XEN_PUBLIC_EVENT_CHANNEL_H__
28
#define __XEN_PUBLIC_EVENT_CHANNEL_H__
29
30
#include "xen.h"
31
32
/*
33
 * `incontents 150 evtchn Event Channels
34
 *
35
 * Event channels are the basic primitive provided by Xen for event
36
 * notifications. An event is the Xen equivalent of a hardware
37
 * interrupt. They essentially store one bit of information, the event
38
 * of interest is signalled by transitioning this bit from 0 to 1.
39
 *
40
 * Notifications are received by a guest via an upcall from Xen,
41
 * indicating when an event arrives (setting the bit). Further
42
 * notifications are masked until the bit is cleared again (therefore,
43
 * guests must check the value of the bit after re-enabling event
44
 * delivery to ensure no missed notifications).
45
 *
46
 * Event notifications can be masked by setting a flag; this is
47
 * equivalent to disabling interrupts and can be used to ensure
48
 * atomicity of certain operations in the guest kernel.
49
 *
50
 * Event channels are represented by the evtchn_* fields in
51
 * struct shared_info and struct vcpu_info.
52
 */
53
54
/*
55
 * ` enum neg_errnoval
56
 * ` HYPERVISOR_event_channel_op(enum event_channel_op cmd, void *args)
57
 * `
58
 * @cmd  == EVTCHNOP_* (event-channel operation).
59
 * @args == struct evtchn_* Operation-specific extra arguments (NULL if none).
60
 */
61
62
/* ` enum event_channel_op { // EVTCHNOP_* => struct evtchn_* */
63
1
#define EVTCHNOP_bind_interdomain 0
64
26
#define EVTCHNOP_bind_virq        1
65
0
#define EVTCHNOP_bind_pirq        2
66
0
#define EVTCHNOP_close            3
67
94.0k
#define EVTCHNOP_send             4
68
0
#define EVTCHNOP_status           5
69
1
#define EVTCHNOP_alloc_unbound    6
70
108
#define EVTCHNOP_bind_ipi         7
71
2
#define EVTCHNOP_bind_vcpu        8
72
451
#define EVTCHNOP_unmask           9
73
0
#define EVTCHNOP_reset           10
74
0
#define EVTCHNOP_init_control    11
75
0
#define EVTCHNOP_expand_array    12
76
0
#define EVTCHNOP_set_priority    13
77
/* ` } */
78
79
typedef uint32_t evtchn_port_t;
80
DEFINE_XEN_GUEST_HANDLE(evtchn_port_t);
81
82
/*
83
 * EVTCHNOP_alloc_unbound: Allocate a port in domain <dom> and mark as
84
 * accepting interdomain bindings from domain <remote_dom>. A fresh port
85
 * is allocated in <dom> and returned as <port>.
86
 * NOTES:
87
 *  1. If the caller is unprivileged then <dom> must be DOMID_SELF.
88
 *  2. <remote_dom> may be DOMID_SELF, allowing loopback connections.
89
 */
90
struct evtchn_alloc_unbound {
91
    /* IN parameters */
92
    domid_t dom, remote_dom;
93
    /* OUT parameters */
94
    evtchn_port_t port;
95
};
96
typedef struct evtchn_alloc_unbound evtchn_alloc_unbound_t;
97
98
/*
99
 * EVTCHNOP_bind_interdomain: Construct an interdomain event channel between
100
 * the calling domain and <remote_dom>. <remote_dom,remote_port> must identify
101
 * a port that is unbound and marked as accepting bindings from the calling
102
 * domain. A fresh port is allocated in the calling domain and returned as
103
 * <local_port>.
104
 *
105
 * In case the peer domain has already tried to set our event channel
106
 * pending, before it was bound, EVTCHNOP_bind_interdomain always sets
107
 * the local event channel pending.
108
 *
109
 * The usual pattern of use, in the guest's upcall (or subsequent
110
 * handler) is as follows: (Re-enable the event channel for subsequent
111
 * signalling and then) check for the existence of whatever condition
112
 * is being waited for by other means, and take whatever action is
113
 * needed (if any).
114
 *
115
 * NOTES:
116
 *  1. <remote_dom> may be DOMID_SELF, allowing loopback connections.
117
 */
118
struct evtchn_bind_interdomain {
119
    /* IN parameters. */
120
    domid_t remote_dom;
121
    evtchn_port_t remote_port;
122
    /* OUT parameters. */
123
    evtchn_port_t local_port;
124
};
125
typedef struct evtchn_bind_interdomain evtchn_bind_interdomain_t;
126
127
/*
128
 * EVTCHNOP_bind_virq: Bind a local event channel to VIRQ <irq> on specified
129
 * vcpu.
130
 * NOTES:
131
 *  1. Virtual IRQs are classified as per-vcpu or global. See the VIRQ list
132
 *     in xen.h for the classification of each VIRQ.
133
 *  2. Global VIRQs must be allocated on VCPU0 but can subsequently be
134
 *     re-bound via EVTCHNOP_bind_vcpu.
135
 *  3. Per-vcpu VIRQs may be bound to at most one event channel per vcpu.
136
 *     The allocated event channel is bound to the specified vcpu and the
137
 *     binding cannot be changed.
138
 */
139
struct evtchn_bind_virq {
140
    /* IN parameters. */
141
    uint32_t virq; /* enum virq */
142
    uint32_t vcpu;
143
    /* OUT parameters. */
144
    evtchn_port_t port;
145
};
146
typedef struct evtchn_bind_virq evtchn_bind_virq_t;
147
148
/*
149
 * EVTCHNOP_bind_pirq: Bind a local event channel to a real IRQ (PIRQ <irq>).
150
 * NOTES:
151
 *  1. A physical IRQ may be bound to at most one event channel per domain.
152
 *  2. Only a sufficiently-privileged domain may bind to a physical IRQ.
153
 */
154
struct evtchn_bind_pirq {
155
    /* IN parameters. */
156
    uint32_t pirq;
157
0
#define BIND_PIRQ__WILL_SHARE 1
158
    uint32_t flags; /* BIND_PIRQ__* */
159
    /* OUT parameters. */
160
    evtchn_port_t port;
161
};
162
typedef struct evtchn_bind_pirq evtchn_bind_pirq_t;
163
164
/*
165
 * EVTCHNOP_bind_ipi: Bind a local event channel to receive events.
166
 * NOTES:
167
 *  1. The allocated event channel is bound to the specified vcpu. The binding
168
 *     may not be changed.
169
 */
170
struct evtchn_bind_ipi {
171
    uint32_t vcpu;
172
    /* OUT parameters. */
173
    evtchn_port_t port;
174
};
175
typedef struct evtchn_bind_ipi evtchn_bind_ipi_t;
176
177
/*
178
 * EVTCHNOP_close: Close a local event channel <port>. If the channel is
179
 * interdomain then the remote end is placed in the unbound state
180
 * (EVTCHNSTAT_unbound), awaiting a new connection.
181
 */
182
struct evtchn_close {
183
    /* IN parameters. */
184
    evtchn_port_t port;
185
};
186
typedef struct evtchn_close evtchn_close_t;
187
188
/*
189
 * EVTCHNOP_send: Send an event to the remote end of the channel whose local
190
 * endpoint is <port>.
191
 */
192
struct evtchn_send {
193
    /* IN parameters. */
194
    evtchn_port_t port;
195
};
196
typedef struct evtchn_send evtchn_send_t;
197
198
/*
199
 * EVTCHNOP_status: Get the current status of the communication channel which
200
 * has an endpoint at <dom, port>.
201
 * NOTES:
202
 *  1. <dom> may be specified as DOMID_SELF.
203
 *  2. Only a sufficiently-privileged domain may obtain the status of an event
204
 *     channel for which <dom> is not DOMID_SELF.
205
 */
206
struct evtchn_status {
207
    /* IN parameters */
208
    domid_t  dom;
209
    evtchn_port_t port;
210
    /* OUT parameters */
211
0
#define EVTCHNSTAT_closed       0  /* Channel is not in use.                 */
212
0
#define EVTCHNSTAT_unbound      1  /* Channel is waiting interdom connection.*/
213
0
#define EVTCHNSTAT_interdomain  2  /* Channel is connected to remote domain. */
214
0
#define EVTCHNSTAT_pirq         3  /* Channel is bound to a phys IRQ line.   */
215
0
#define EVTCHNSTAT_virq         4  /* Channel is bound to a virtual IRQ line */
216
0
#define EVTCHNSTAT_ipi          5  /* Channel is bound to a virtual IPI line */
217
    uint32_t status;
218
    uint32_t vcpu;                 /* VCPU to which this channel is bound.   */
219
    union {
220
        struct {
221
            domid_t dom;
222
        } unbound;                 /* EVTCHNSTAT_unbound */
223
        struct {
224
            domid_t dom;
225
            evtchn_port_t port;
226
        } interdomain;             /* EVTCHNSTAT_interdomain */
227
        uint32_t pirq;             /* EVTCHNSTAT_pirq        */
228
        uint32_t virq;             /* EVTCHNSTAT_virq        */
229
    } u;
230
};
231
typedef struct evtchn_status evtchn_status_t;
232
233
/*
234
 * EVTCHNOP_bind_vcpu: Specify which vcpu a channel should notify when an
235
 * event is pending.
236
 * NOTES:
237
 *  1. IPI-bound channels always notify the vcpu specified at bind time.
238
 *     This binding cannot be changed.
239
 *  2. Per-VCPU VIRQ channels always notify the vcpu specified at bind time.
240
 *     This binding cannot be changed.
241
 *  3. All other channels notify vcpu0 by default. This default is set when
242
 *     the channel is allocated (a port that is freed and subsequently reused
243
 *     has its binding reset to vcpu0).
244
 */
245
struct evtchn_bind_vcpu {
246
    /* IN parameters. */
247
    evtchn_port_t port;
248
    uint32_t vcpu;
249
};
250
typedef struct evtchn_bind_vcpu evtchn_bind_vcpu_t;
251
252
/*
253
 * EVTCHNOP_unmask: Unmask the specified local event-channel port and deliver
254
 * a notification to the appropriate VCPU if an event is pending.
255
 */
256
struct evtchn_unmask {
257
    /* IN parameters. */
258
    evtchn_port_t port;
259
};
260
typedef struct evtchn_unmask evtchn_unmask_t;
261
262
/*
263
 * EVTCHNOP_reset: Close all event channels associated with specified domain.
264
 * NOTES:
265
 *  1. <dom> may be specified as DOMID_SELF.
266
 *  2. Only a sufficiently-privileged domain may specify other than DOMID_SELF.
267
 *  3. Destroys all control blocks and event array, resets event channel
268
 *     operations to 2-level ABI if called with <dom> == DOMID_SELF and FIFO
269
 *     ABI was used. Guests should not bind events during EVTCHNOP_reset call
270
 *     as these events are likely to be lost.
271
 */
272
struct evtchn_reset {
273
    /* IN parameters. */
274
    domid_t dom;
275
};
276
typedef struct evtchn_reset evtchn_reset_t;
277
278
/*
279
 * EVTCHNOP_init_control: initialize the control block for the FIFO ABI.
280
 *
281
 * Note: any events that are currently pending will not be resent and
282
 * will be lost.  Guests should call this before binding any event to
283
 * avoid losing any events.
284
 */
285
struct evtchn_init_control {
286
    /* IN parameters. */
287
    uint64_t control_gfn;
288
    uint32_t offset;
289
    uint32_t vcpu;
290
    /* OUT parameters. */
291
    uint8_t link_bits;
292
    uint8_t _pad[7];
293
};
294
typedef struct evtchn_init_control evtchn_init_control_t;
295
296
/*
297
 * EVTCHNOP_expand_array: add an additional page to the event array.
298
 */
299
struct evtchn_expand_array {
300
    /* IN parameters. */
301
    uint64_t array_gfn;
302
};
303
typedef struct evtchn_expand_array evtchn_expand_array_t;
304
305
/*
306
 * EVTCHNOP_set_priority: set the priority for an event channel.
307
 */
308
struct evtchn_set_priority {
309
    /* IN parameters. */
310
    uint32_t port;
311
    uint32_t priority;
312
};
313
typedef struct evtchn_set_priority evtchn_set_priority_t;
314
315
/*
316
 * ` enum neg_errnoval
317
 * ` HYPERVISOR_event_channel_op_compat(struct evtchn_op *op)
318
 * `
319
 * Superceded by new event_channel_op() hypercall since 0x00030202.
320
 */
321
struct evtchn_op {
322
    uint32_t cmd; /* enum event_channel_op */
323
    union {
324
        struct evtchn_alloc_unbound    alloc_unbound;
325
        struct evtchn_bind_interdomain bind_interdomain;
326
        struct evtchn_bind_virq        bind_virq;
327
        struct evtchn_bind_pirq        bind_pirq;
328
        struct evtchn_bind_ipi         bind_ipi;
329
        struct evtchn_close            close;
330
        struct evtchn_send             send;
331
        struct evtchn_status           status;
332
        struct evtchn_bind_vcpu        bind_vcpu;
333
        struct evtchn_unmask           unmask;
334
    } u;
335
};
336
typedef struct evtchn_op evtchn_op_t;
337
DEFINE_XEN_GUEST_HANDLE(evtchn_op_t);
338
339
/*
340
 * 2-level ABI
341
 */
342
343
#define EVTCHN_2L_NR_CHANNELS (sizeof(xen_ulong_t) * sizeof(xen_ulong_t) * 64)
344
345
/*
346
 * FIFO ABI
347
 */
348
349
/* Events may have priorities from 0 (highest) to 15 (lowest). */
350
#define EVTCHN_FIFO_PRIORITY_MAX     0
351
0
#define EVTCHN_FIFO_PRIORITY_DEFAULT 7
352
0
#define EVTCHN_FIFO_PRIORITY_MIN     15
353
354
#define EVTCHN_FIFO_MAX_QUEUES (EVTCHN_FIFO_PRIORITY_MIN + 1)
355
356
typedef uint32_t event_word_t;
357
358
#define EVTCHN_FIFO_PENDING 31
359
#define EVTCHN_FIFO_MASKED  30
360
0
#define EVTCHN_FIFO_LINKED  29
361
0
#define EVTCHN_FIFO_BUSY    28
362
363
0
#define EVTCHN_FIFO_LINK_BITS 17
364
0
#define EVTCHN_FIFO_LINK_MASK ((1 << EVTCHN_FIFO_LINK_BITS) - 1)
365
366
0
#define EVTCHN_FIFO_NR_CHANNELS (1 << EVTCHN_FIFO_LINK_BITS)
367
368
struct evtchn_fifo_control_block {
369
    uint32_t ready;
370
    uint32_t _rsvd;
371
    uint32_t head[EVTCHN_FIFO_MAX_QUEUES];
372
};
373
typedef struct evtchn_fifo_control_block evtchn_fifo_control_block_t;
374
375
#endif /* __XEN_PUBLIC_EVENT_CHANNEL_H__ */
376
377
/*
378
 * Local variables:
379
 * mode: C
380
 * c-file-style: "BSD"
381
 * c-basic-offset: 4
382
 * tab-width: 4
383
 * indent-tabs-mode: nil
384
 * End:
385
 */