xref: /illumos-gate/usr/src/uts/common/xen/public/event_channel.h (revision 598f4ceed9327d2d6c2325dd67cae3aa06f7fea6)
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 /*
31  * Prototype for this hypercall is:
32  *  int event_channel_op(int cmd, void *args)
33  * @cmd  == EVTCHNOP_??? (event-channel operation).
34  * @args == Operation-specific extra arguments (NULL if none).
35  */
36 
37 typedef uint32_t evtchn_port_t;
38 DEFINE_XEN_GUEST_HANDLE(evtchn_port_t);
39 
40 /*
41  * EVTCHNOP_alloc_unbound: Allocate a port in domain <dom> and mark as
42  * accepting interdomain bindings from domain <remote_dom>. A fresh port
43  * is allocated in <dom> and returned as <port>.
44  * NOTES:
45  *  1. If the caller is unprivileged then <dom> must be DOMID_SELF.
46  *  2. <rdom> may be DOMID_SELF, allowing loopback connections.
47  */
48 #define EVTCHNOP_alloc_unbound    6
49 struct evtchn_alloc_unbound {
50     /* IN parameters */
51     domid_t dom, remote_dom;
52     /* OUT parameters */
53     evtchn_port_t port;
54 };
55 typedef struct evtchn_alloc_unbound evtchn_alloc_unbound_t;
56 
57 /*
58  * EVTCHNOP_bind_interdomain: Construct an interdomain event channel between
59  * the calling domain and <remote_dom>. <remote_dom,remote_port> must identify
60  * a port that is unbound and marked as accepting bindings from the calling
61  * domain. A fresh port is allocated in the calling domain and returned as
62  * <local_port>.
63  * NOTES:
64  *  2. <remote_dom> may be DOMID_SELF, allowing loopback connections.
65  */
66 #define EVTCHNOP_bind_interdomain 0
67 struct evtchn_bind_interdomain {
68     /* IN parameters. */
69     domid_t remote_dom;
70     evtchn_port_t remote_port;
71     /* OUT parameters. */
72     evtchn_port_t local_port;
73 };
74 typedef struct evtchn_bind_interdomain evtchn_bind_interdomain_t;
75 
76 /*
77  * EVTCHNOP_bind_virq: Bind a local event channel to VIRQ <irq> on specified
78  * vcpu.
79  * NOTES:
80  *  1. Virtual IRQs are classified as per-vcpu or global. See the VIRQ list
81  *     in xen.h for the classification of each VIRQ.
82  *  2. Global VIRQs must be allocated on VCPU0 but can subsequently be
83  *     re-bound via EVTCHNOP_bind_vcpu.
84  *  3. Per-vcpu VIRQs may be bound to at most one event channel per vcpu.
85  *     The allocated event channel is bound to the specified vcpu and the
86  *     binding cannot be changed.
87  */
88 #define EVTCHNOP_bind_virq        1
89 struct evtchn_bind_virq {
90     /* IN parameters. */
91     uint32_t virq;
92     uint32_t vcpu;
93     /* OUT parameters. */
94     evtchn_port_t port;
95 };
96 typedef struct evtchn_bind_virq evtchn_bind_virq_t;
97 
98 /*
99  * EVTCHNOP_bind_pirq: Bind a local event channel to PIRQ <irq>.
100  * NOTES:
101  *  1. A physical IRQ may be bound to at most one event channel per domain.
102  *  2. Only a sufficiently-privileged domain may bind to a physical IRQ.
103  */
104 #define EVTCHNOP_bind_pirq        2
105 struct evtchn_bind_pirq {
106     /* IN parameters. */
107     uint32_t pirq;
108 #define BIND_PIRQ__WILL_SHARE 1
109     uint32_t flags; /* BIND_PIRQ__* */
110     /* OUT parameters. */
111     evtchn_port_t port;
112 };
113 typedef struct evtchn_bind_pirq evtchn_bind_pirq_t;
114 
115 /*
116  * EVTCHNOP_bind_ipi: Bind a local event channel to receive events.
117  * NOTES:
118  *  1. The allocated event channel is bound to the specified vcpu. The binding
119  *     may not be changed.
120  */
121 #define EVTCHNOP_bind_ipi         7
122 struct evtchn_bind_ipi {
123     uint32_t vcpu;
124     /* OUT parameters. */
125     evtchn_port_t port;
126 };
127 typedef struct evtchn_bind_ipi evtchn_bind_ipi_t;
128 
129 /*
130  * EVTCHNOP_close: Close a local event channel <port>. If the channel is
131  * interdomain then the remote end is placed in the unbound state
132  * (EVTCHNSTAT_unbound), awaiting a new connection.
133  */
134 #define EVTCHNOP_close            3
135 struct evtchn_close {
136     /* IN parameters. */
137     evtchn_port_t port;
138 };
139 typedef struct evtchn_close evtchn_close_t;
140 
141 /*
142  * EVTCHNOP_send: Send an event to the remote end of the channel whose local
143  * endpoint is <port>.
144  */
145 #define EVTCHNOP_send             4
146 struct evtchn_send {
147     /* IN parameters. */
148     evtchn_port_t port;
149 };
150 typedef struct evtchn_send evtchn_send_t;
151 
152 /*
153  * EVTCHNOP_status: Get the current status of the communication channel which
154  * has an endpoint at <dom, port>.
155  * NOTES:
156  *  1. <dom> may be specified as DOMID_SELF.
157  *  2. Only a sufficiently-privileged domain may obtain the status of an event
158  *     channel for which <dom> is not DOMID_SELF.
159  */
160 #define EVTCHNOP_status           5
161 struct evtchn_status {
162     /* IN parameters */
163     domid_t  dom;
164     evtchn_port_t port;
165     /* OUT parameters */
166 #define EVTCHNSTAT_closed       0  /* Channel is not in use.                 */
167 #define EVTCHNSTAT_unbound      1  /* Channel is waiting interdom connection.*/
168 #define EVTCHNSTAT_interdomain  2  /* Channel is connected to remote domain. */
169 #define EVTCHNSTAT_pirq         3  /* Channel is bound to a phys IRQ line.   */
170 #define EVTCHNSTAT_virq         4  /* Channel is bound to a virtual IRQ line */
171 #define EVTCHNSTAT_ipi          5  /* Channel is bound to a virtual IPI line */
172     uint32_t status;
173     uint32_t vcpu;                 /* VCPU to which this channel is bound.   */
174     union {
175         struct {
176             domid_t dom;
177         } unbound; /* EVTCHNSTAT_unbound */
178         struct {
179             domid_t dom;
180             evtchn_port_t port;
181         } interdomain; /* EVTCHNSTAT_interdomain */
182         uint32_t pirq;      /* EVTCHNSTAT_pirq        */
183         uint32_t virq;      /* EVTCHNSTAT_virq        */
184     } u;
185 };
186 typedef struct evtchn_status evtchn_status_t;
187 
188 /*
189  * EVTCHNOP_bind_vcpu: Specify which vcpu a channel should notify when an
190  * event is pending.
191  * NOTES:
192  *  1. IPI-bound channels always notify the vcpu specified at bind time.
193  *     This binding cannot be changed.
194  *  2. Per-VCPU VIRQ channels always notify the vcpu specified at bind time.
195  *     This binding cannot be changed.
196  *  3. All other channels notify vcpu0 by default. This default is set when
197  *     the channel is allocated (a port that is freed and subsequently reused
198  *     has its binding reset to vcpu0).
199  */
200 #define EVTCHNOP_bind_vcpu        8
201 struct evtchn_bind_vcpu {
202     /* IN parameters. */
203     evtchn_port_t port;
204     uint32_t vcpu;
205 };
206 typedef struct evtchn_bind_vcpu evtchn_bind_vcpu_t;
207 
208 /*
209  * EVTCHNOP_unmask: Unmask the specified local event-channel port and deliver
210  * a notification to the appropriate VCPU if an event is pending.
211  */
212 #define EVTCHNOP_unmask           9
213 struct evtchn_unmask {
214     /* IN parameters. */
215     evtchn_port_t port;
216 };
217 typedef struct evtchn_unmask evtchn_unmask_t;
218 
219 /*
220  * EVTCHNOP_reset: Close all event channels associated with specified domain.
221  * NOTES:
222  *  1. <dom> may be specified as DOMID_SELF.
223  *  2. Only a sufficiently-privileged domain may specify other than DOMID_SELF.
224  */
225 #define EVTCHNOP_reset           10
226 struct evtchn_reset {
227     /* IN parameters. */
228     domid_t dom;
229 };
230 typedef struct evtchn_reset evtchn_reset_t;
231 
232 /*
233  * Argument to event_channel_op_compat() hypercall. Superceded by new
234  * event_channel_op() hypercall since 0x00030202.
235  */
236 struct evtchn_op {
237     uint32_t cmd; /* EVTCHNOP_* */
238     union {
239         struct evtchn_alloc_unbound    alloc_unbound;
240         struct evtchn_bind_interdomain bind_interdomain;
241         struct evtchn_bind_virq        bind_virq;
242         struct evtchn_bind_pirq        bind_pirq;
243         struct evtchn_bind_ipi         bind_ipi;
244         struct evtchn_close            close;
245         struct evtchn_send             send;
246         struct evtchn_status           status;
247         struct evtchn_bind_vcpu        bind_vcpu;
248         struct evtchn_unmask           unmask;
249     } u;
250 };
251 typedef struct evtchn_op evtchn_op_t;
252 DEFINE_XEN_GUEST_HANDLE(evtchn_op_t);
253 
254 #endif /* __XEN_PUBLIC_EVENT_CHANNEL_H__ */
255 
256 /*
257  * Local variables:
258  * mode: C
259  * c-set-style: "BSD"
260  * c-basic-offset: 4
261  * tab-width: 4
262  * indent-tabs-mode: nil
263  * End:
264  */
265