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