]> CyberLeo.Net >> Repos - FreeBSD/releng/10.2.git/blob - sys/xen/interface/event_channel.h
- Copy stable/10@285827 to releng/10.2 in preparation for 10.2-RC1
[FreeBSD/releng/10.2.git] / sys / xen / interface / 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 #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 #define EVTCHNOP_bind_interdomain 0
64 #define EVTCHNOP_bind_virq        1
65 #define EVTCHNOP_bind_pirq        2
66 #define EVTCHNOP_close            3
67 #define EVTCHNOP_send             4
68 #define EVTCHNOP_status           5
69 #define EVTCHNOP_alloc_unbound    6
70 #define EVTCHNOP_bind_ipi         7
71 #define EVTCHNOP_bind_vcpu        8
72 #define EVTCHNOP_unmask           9
73 #define EVTCHNOP_reset           10
74 /* ` } */
75
76 #ifndef __XEN_EVTCHN_PORT_DEFINED__
77 typedef uint32_t evtchn_port_t;
78 DEFINE_XEN_GUEST_HANDLE(evtchn_port_t);
79 #define __XEN_EVTCHN_PORT_DEFINED__ 1
80 #endif
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. <rdom> 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  * NOTES:
105  *  1. <remote_dom> may be DOMID_SELF, allowing loopback connections.
106  */
107 struct evtchn_bind_interdomain {
108     /* IN parameters. */
109     domid_t remote_dom;
110     evtchn_port_t remote_port;
111     /* OUT parameters. */
112     evtchn_port_t local_port;
113 };
114 typedef struct evtchn_bind_interdomain evtchn_bind_interdomain_t;
115
116 /*
117  * EVTCHNOP_bind_virq: Bind a local event channel to VIRQ <irq> on specified
118  * vcpu.
119  * NOTES:
120  *  1. Virtual IRQs are classified as per-vcpu or global. See the VIRQ list
121  *     in xen.h for the classification of each VIRQ.
122  *  2. Global VIRQs must be allocated on VCPU0 but can subsequently be
123  *     re-bound via EVTCHNOP_bind_vcpu.
124  *  3. Per-vcpu VIRQs may be bound to at most one event channel per vcpu.
125  *     The allocated event channel is bound to the specified vcpu and the
126  *     binding cannot be changed.
127  */
128 struct evtchn_bind_virq {
129     /* IN parameters. */
130     uint32_t virq; /* enum virq */
131     uint32_t vcpu;
132     /* OUT parameters. */
133     evtchn_port_t port;
134 };
135 typedef struct evtchn_bind_virq evtchn_bind_virq_t;
136
137 /*
138  * EVTCHNOP_bind_pirq: Bind a local event channel to a real IRQ (PIRQ <irq>).
139  * NOTES:
140  *  1. A physical IRQ may be bound to at most one event channel per domain.
141  *  2. Only a sufficiently-privileged domain may bind to a physical IRQ.
142  */
143 struct evtchn_bind_pirq {
144     /* IN parameters. */
145     uint32_t pirq;
146 #define BIND_PIRQ__WILL_SHARE 1
147     uint32_t flags; /* BIND_PIRQ__* */
148     /* OUT parameters. */
149     evtchn_port_t port;
150 };
151 typedef struct evtchn_bind_pirq evtchn_bind_pirq_t;
152
153 /*
154  * EVTCHNOP_bind_ipi: Bind a local event channel to receive events.
155  * NOTES:
156  *  1. The allocated event channel is bound to the specified vcpu. The binding
157  *     may not be changed.
158  */
159 struct evtchn_bind_ipi {
160     uint32_t vcpu;
161     /* OUT parameters. */
162     evtchn_port_t port;
163 };
164 typedef struct evtchn_bind_ipi evtchn_bind_ipi_t;
165
166 /*
167  * EVTCHNOP_close: Close a local event channel <port>. If the channel is
168  * interdomain then the remote end is placed in the unbound state
169  * (EVTCHNSTAT_unbound), awaiting a new connection.
170  */
171 struct evtchn_close {
172     /* IN parameters. */
173     evtchn_port_t port;
174 };
175 typedef struct evtchn_close evtchn_close_t;
176
177 /*
178  * EVTCHNOP_send: Send an event to the remote end of the channel whose local
179  * endpoint is <port>.
180  */
181 struct evtchn_send {
182     /* IN parameters. */
183     evtchn_port_t port;
184 };
185 typedef struct evtchn_send evtchn_send_t;
186
187 /*
188  * EVTCHNOP_status: Get the current status of the communication channel which
189  * has an endpoint at <dom, port>.
190  * NOTES:
191  *  1. <dom> may be specified as DOMID_SELF.
192  *  2. Only a sufficiently-privileged domain may obtain the status of an event
193  *     channel for which <dom> is not DOMID_SELF.
194  */
195 struct evtchn_status {
196     /* IN parameters */
197     domid_t  dom;
198     evtchn_port_t port;
199     /* OUT parameters */
200 #define EVTCHNSTAT_closed       0  /* Channel is not in use.                 */
201 #define EVTCHNSTAT_unbound      1  /* Channel is waiting interdom connection.*/
202 #define EVTCHNSTAT_interdomain  2  /* Channel is connected to remote domain. */
203 #define EVTCHNSTAT_pirq         3  /* Channel is bound to a phys IRQ line.   */
204 #define EVTCHNSTAT_virq         4  /* Channel is bound to a virtual IRQ line */
205 #define EVTCHNSTAT_ipi          5  /* Channel is bound to a virtual IPI line */
206     uint32_t status;
207     uint32_t vcpu;                 /* VCPU to which this channel is bound.   */
208     union {
209         struct {
210             domid_t dom;
211         } unbound;                 /* EVTCHNSTAT_unbound */
212         struct {
213             domid_t dom;
214             evtchn_port_t port;
215         } interdomain;             /* EVTCHNSTAT_interdomain */
216         uint32_t pirq;             /* EVTCHNSTAT_pirq        */
217         uint32_t virq;             /* EVTCHNSTAT_virq        */
218     } u;
219 };
220 typedef struct evtchn_status evtchn_status_t;
221
222 /*
223  * EVTCHNOP_bind_vcpu: Specify which vcpu a channel should notify when an
224  * event is pending.
225  * NOTES:
226  *  1. IPI-bound channels always notify the vcpu specified at bind time.
227  *     This binding cannot be changed.
228  *  2. Per-VCPU VIRQ channels always notify the vcpu specified at bind time.
229  *     This binding cannot be changed.
230  *  3. All other channels notify vcpu0 by default. This default is set when
231  *     the channel is allocated (a port that is freed and subsequently reused
232  *     has its binding reset to vcpu0).
233  */
234 struct evtchn_bind_vcpu {
235     /* IN parameters. */
236     evtchn_port_t port;
237     uint32_t vcpu;
238 };
239 typedef struct evtchn_bind_vcpu evtchn_bind_vcpu_t;
240
241 /*
242  * EVTCHNOP_unmask: Unmask the specified local event-channel port and deliver
243  * a notification to the appropriate VCPU if an event is pending.
244  */
245 struct evtchn_unmask {
246     /* IN parameters. */
247     evtchn_port_t port;
248 };
249 typedef struct evtchn_unmask evtchn_unmask_t;
250
251 /*
252  * EVTCHNOP_reset: Close all event channels associated with specified domain.
253  * NOTES:
254  *  1. <dom> may be specified as DOMID_SELF.
255  *  2. Only a sufficiently-privileged domain may specify other than DOMID_SELF.
256  */
257 struct evtchn_reset {
258     /* IN parameters. */
259     domid_t dom;
260 };
261 typedef struct evtchn_reset evtchn_reset_t;
262
263 /*
264  * ` enum neg_errnoval
265  * ` HYPERVISOR_event_channel_op_compat(struct evtchn_op *op)
266  * `
267  * Superceded by new event_channel_op() hypercall since 0x00030202.
268  */
269 struct evtchn_op {
270     uint32_t cmd; /* enum event_channel_op */
271     union {
272         struct evtchn_alloc_unbound    alloc_unbound;
273         struct evtchn_bind_interdomain bind_interdomain;
274         struct evtchn_bind_virq        bind_virq;
275         struct evtchn_bind_pirq        bind_pirq;
276         struct evtchn_bind_ipi         bind_ipi;
277         struct evtchn_close            close;
278         struct evtchn_send             send;
279         struct evtchn_status           status;
280         struct evtchn_bind_vcpu        bind_vcpu;
281         struct evtchn_unmask           unmask;
282     } u;
283 };
284 typedef struct evtchn_op evtchn_op_t;
285 DEFINE_XEN_GUEST_HANDLE(evtchn_op_t);
286
287 #endif /* __XEN_PUBLIC_EVENT_CHANNEL_H__ */
288
289 /*
290  * Local variables:
291  * mode: C
292  * c-set-style: "BSD"
293  * c-basic-offset: 4
294  * tab-width: 4
295  * indent-tabs-mode: nil
296  * End:
297  */