1 /******************************************************************************
4 * Event channels between domains.
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:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
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.
24 * Copyright (c) 2003-2004, K A Fraser.
27 #ifndef __XEN_PUBLIC_EVENT_CHANNEL_H__
28 #define __XEN_PUBLIC_EVENT_CHANNEL_H__
35 * `incontents 150 evtchn Event Channels
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.
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).
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.
52 * Event channels are represented by the evtchn_* fields in
53 * struct shared_info and struct vcpu_info.
58 * ` HYPERVISOR_event_channel_op(enum event_channel_op cmd, void *args)
60 * @cmd == EVTCHNOP_* (event-channel operation).
61 * @args == struct evtchn_* Operation-specific extra arguments (NULL if none).
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
81 typedef uint32_t evtchn_port_t;
82 DEFINE_XEN_GUEST_HANDLE(evtchn_port_t);
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>.
89 * 1. If the caller is unprivileged then <dom> must be DOMID_SELF.
90 * 2. <rdom> may be DOMID_SELF, allowing loopback connections.
92 struct evtchn_alloc_unbound {
94 domid_t dom, remote_dom;
98 typedef struct evtchn_alloc_unbound evtchn_alloc_unbound_t;
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
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.
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
118 * 1. <remote_dom> may be DOMID_SELF, allowing loopback connections.
120 struct evtchn_bind_interdomain {
123 evtchn_port_t remote_port;
124 /* OUT parameters. */
125 evtchn_port_t local_port;
127 typedef struct evtchn_bind_interdomain evtchn_bind_interdomain_t;
130 * EVTCHNOP_bind_virq: Bind a local event channel to VIRQ <irq> on specified
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.
141 struct evtchn_bind_virq {
143 uint32_t virq; /* enum virq */
145 /* OUT parameters. */
148 typedef struct evtchn_bind_virq evtchn_bind_virq_t;
151 * EVTCHNOP_bind_pirq: Bind a local event channel to a real IRQ (PIRQ <irq>).
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.
156 struct evtchn_bind_pirq {
159 #define BIND_PIRQ__WILL_SHARE 1
160 uint32_t flags; /* BIND_PIRQ__* */
161 /* OUT parameters. */
164 typedef struct evtchn_bind_pirq evtchn_bind_pirq_t;
167 * EVTCHNOP_bind_ipi: Bind a local event channel to receive events.
169 * 1. The allocated event channel is bound to the specified vcpu. The binding
170 * may not be changed.
172 struct evtchn_bind_ipi {
174 /* OUT parameters. */
177 typedef struct evtchn_bind_ipi evtchn_bind_ipi_t;
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.
184 struct evtchn_close {
188 typedef struct evtchn_close evtchn_close_t;
191 * EVTCHNOP_send: Send an event to the remote end of the channel whose local
192 * endpoint is <port>.
198 typedef struct evtchn_send evtchn_send_t;
201 * EVTCHNOP_status: Get the current status of the communication channel which
202 * has an endpoint at <dom, port>.
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.
208 struct evtchn_status {
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 */
220 uint32_t vcpu; /* VCPU to which this channel is bound. */
224 } unbound; /* EVTCHNSTAT_unbound */
228 } interdomain; /* EVTCHNSTAT_interdomain */
229 uint32_t pirq; /* EVTCHNSTAT_pirq */
230 uint32_t virq; /* EVTCHNSTAT_virq */
233 typedef struct evtchn_status evtchn_status_t;
236 * EVTCHNOP_bind_vcpu: Specify which vcpu a channel should notify when an
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).
247 struct evtchn_bind_vcpu {
252 typedef struct evtchn_bind_vcpu evtchn_bind_vcpu_t;
255 * EVTCHNOP_unmask: Unmask the specified local event-channel port and deliver
256 * a notification to the appropriate VCPU if an event is pending.
258 struct evtchn_unmask {
262 typedef struct evtchn_unmask evtchn_unmask_t;
265 * EVTCHNOP_reset: Close all event channels associated with specified domain.
267 * 1. <dom> may be specified as DOMID_SELF.
268 * 2. Only a sufficiently-privileged domain may specify other than DOMID_SELF.
270 struct evtchn_reset {
274 typedef struct evtchn_reset evtchn_reset_t;
277 * EVTCHNOP_init_control: initialize the control block for the FIFO ABI.
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.
283 struct evtchn_init_control {
285 uint64_t control_gfn;
288 /* OUT parameters. */
292 typedef struct evtchn_init_control evtchn_init_control_t;
295 * EVTCHNOP_expand_array: add an additional page to the event array.
297 struct evtchn_expand_array {
301 typedef struct evtchn_expand_array evtchn_expand_array_t;
304 * EVTCHNOP_set_priority: set the priority for an event channel.
306 struct evtchn_set_priority {
311 typedef struct evtchn_set_priority evtchn_set_priority_t;
314 * ` enum neg_errnoval
315 * ` HYPERVISOR_event_channel_op_compat(struct evtchn_op *op)
317 * Superceded by new event_channel_op() hypercall since 0x00030202.
320 uint32_t cmd; /* enum event_channel_op */
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;
334 typedef struct evtchn_op evtchn_op_t;
335 DEFINE_XEN_GUEST_HANDLE(evtchn_op_t);
341 #define EVTCHN_2L_NR_CHANNELS (sizeof(xen_ulong_t) * sizeof(xen_ulong_t) * 64)
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
352 #define EVTCHN_FIFO_MAX_QUEUES (EVTCHN_FIFO_PRIORITY_MIN + 1)
354 typedef uint32_t event_word_t;
356 #define EVTCHN_FIFO_PENDING 31
357 #define EVTCHN_FIFO_MASKED 30
358 #define EVTCHN_FIFO_LINKED 29
359 #define EVTCHN_FIFO_BUSY 28
361 #define EVTCHN_FIFO_LINK_BITS 17
362 #define EVTCHN_FIFO_LINK_MASK ((1 << EVTCHN_FIFO_LINK_BITS) - 1)
364 #define EVTCHN_FIFO_NR_CHANNELS (1 << EVTCHN_FIFO_LINK_BITS)
366 struct evtchn_fifo_control_block {
369 uint32_t head[EVTCHN_FIFO_MAX_QUEUES];
371 typedef struct evtchn_fifo_control_block evtchn_fifo_control_block_t;
373 #endif /* __XEN_PUBLIC_EVENT_CHANNEL_H__ */
378 * c-file-style: "BSD"
381 * indent-tabs-mode: nil