xref: /linux/include/xen/interface/event_channel.h (revision 827634added7f38b7d724cab1dccdb2b004c13c3)
1 /******************************************************************************
2  * event_channel.h
3  *
4  * Event channels between domains.
5  *
6  * Copyright (c) 2003-2004, K A Fraser.
7  */
8 
9 #ifndef __XEN_PUBLIC_EVENT_CHANNEL_H__
10 #define __XEN_PUBLIC_EVENT_CHANNEL_H__
11 
12 #include <xen/interface/xen.h>
13 
14 typedef uint32_t evtchn_port_t;
15 DEFINE_GUEST_HANDLE(evtchn_port_t);
16 
17 /*
18  * EVTCHNOP_alloc_unbound: Allocate a port in domain <dom> and mark as
19  * accepting interdomain bindings from domain <remote_dom>. A fresh port
20  * is allocated in <dom> and returned as <port>.
21  * NOTES:
22  *  1. If the caller is unprivileged then <dom> must be DOMID_SELF.
23  *  2. <rdom> may be DOMID_SELF, allowing loopback connections.
24  */
25 #define EVTCHNOP_alloc_unbound	  6
26 struct evtchn_alloc_unbound {
27 	/* IN parameters */
28 	domid_t dom, remote_dom;
29 	/* OUT parameters */
30 	evtchn_port_t port;
31 };
32 
33 /*
34  * EVTCHNOP_bind_interdomain: Construct an interdomain event channel between
35  * the calling domain and <remote_dom>. <remote_dom,remote_port> must identify
36  * a port that is unbound and marked as accepting bindings from the calling
37  * domain. A fresh port is allocated in the calling domain and returned as
38  * <local_port>.
39  * NOTES:
40  *  2. <remote_dom> may be DOMID_SELF, allowing loopback connections.
41  */
42 #define EVTCHNOP_bind_interdomain 0
43 struct evtchn_bind_interdomain {
44 	/* IN parameters. */
45 	domid_t remote_dom;
46 	evtchn_port_t remote_port;
47 	/* OUT parameters. */
48 	evtchn_port_t local_port;
49 };
50 
51 /*
52  * EVTCHNOP_bind_virq: Bind a local event channel to VIRQ <irq> on specified
53  * vcpu.
54  * NOTES:
55  *  1. A virtual IRQ may be bound to at most one event channel per vcpu.
56  *  2. The allocated event channel is bound to the specified vcpu. The binding
57  *     may not be changed.
58  */
59 #define EVTCHNOP_bind_virq	  1
60 struct evtchn_bind_virq {
61 	/* IN parameters. */
62 	uint32_t virq;
63 	uint32_t vcpu;
64 	/* OUT parameters. */
65 	evtchn_port_t port;
66 };
67 
68 /*
69  * EVTCHNOP_bind_pirq: Bind a local event channel to PIRQ <irq>.
70  * NOTES:
71  *  1. A physical IRQ may be bound to at most one event channel per domain.
72  *  2. Only a sufficiently-privileged domain may bind to a physical IRQ.
73  */
74 #define EVTCHNOP_bind_pirq	  2
75 struct evtchn_bind_pirq {
76 	/* IN parameters. */
77 	uint32_t pirq;
78 #define BIND_PIRQ__WILL_SHARE 1
79 	uint32_t flags; /* BIND_PIRQ__* */
80 	/* OUT parameters. */
81 	evtchn_port_t port;
82 };
83 
84 /*
85  * EVTCHNOP_bind_ipi: Bind a local event channel to receive events.
86  * NOTES:
87  *  1. The allocated event channel is bound to the specified vcpu. The binding
88  *     may not be changed.
89  */
90 #define EVTCHNOP_bind_ipi	  7
91 struct evtchn_bind_ipi {
92 	uint32_t vcpu;
93 	/* OUT parameters. */
94 	evtchn_port_t port;
95 };
96 
97 /*
98  * EVTCHNOP_close: Close a local event channel <port>. If the channel is
99  * interdomain then the remote end is placed in the unbound state
100  * (EVTCHNSTAT_unbound), awaiting a new connection.
101  */
102 #define EVTCHNOP_close		  3
103 struct evtchn_close {
104 	/* IN parameters. */
105 	evtchn_port_t port;
106 };
107 
108 /*
109  * EVTCHNOP_send: Send an event to the remote end of the channel whose local
110  * endpoint is <port>.
111  */
112 #define EVTCHNOP_send		  4
113 struct evtchn_send {
114 	/* IN parameters. */
115 	evtchn_port_t port;
116 };
117 
118 /*
119  * EVTCHNOP_status: Get the current status of the communication channel which
120  * has an endpoint at <dom, port>.
121  * NOTES:
122  *  1. <dom> may be specified as DOMID_SELF.
123  *  2. Only a sufficiently-privileged domain may obtain the status of an event
124  *     channel for which <dom> is not DOMID_SELF.
125  */
126 #define EVTCHNOP_status		  5
127 struct evtchn_status {
128 	/* IN parameters */
129 	domid_t  dom;
130 	evtchn_port_t port;
131 	/* OUT parameters */
132 #define EVTCHNSTAT_closed	0  /* Channel is not in use.		     */
133 #define EVTCHNSTAT_unbound	1  /* Channel is waiting interdom connection.*/
134 #define EVTCHNSTAT_interdomain	2  /* Channel is connected to remote domain. */
135 #define EVTCHNSTAT_pirq		3  /* Channel is bound to a phys IRQ line.   */
136 #define EVTCHNSTAT_virq		4  /* Channel is bound to a virtual IRQ line */
137 #define EVTCHNSTAT_ipi		5  /* Channel is bound to a virtual IPI line */
138 	uint32_t status;
139 	uint32_t vcpu;		   /* VCPU to which this channel is bound.   */
140 	union {
141 		struct {
142 			domid_t dom;
143 		} unbound; /* EVTCHNSTAT_unbound */
144 		struct {
145 			domid_t dom;
146 			evtchn_port_t port;
147 		} interdomain; /* EVTCHNSTAT_interdomain */
148 		uint32_t pirq;	    /* EVTCHNSTAT_pirq	      */
149 		uint32_t virq;	    /* EVTCHNSTAT_virq	      */
150 	} u;
151 };
152 
153 /*
154  * EVTCHNOP_bind_vcpu: Specify which vcpu a channel should notify when an
155  * event is pending.
156  * NOTES:
157  *  1. IPI- and VIRQ-bound channels always notify the vcpu that initialised
158  *     the binding. This binding cannot be changed.
159  *  2. All other channels notify vcpu0 by default. This default is set when
160  *     the channel is allocated (a port that is freed and subsequently reused
161  *     has its binding reset to vcpu0).
162  */
163 #define EVTCHNOP_bind_vcpu	  8
164 struct evtchn_bind_vcpu {
165 	/* IN parameters. */
166 	evtchn_port_t port;
167 	uint32_t vcpu;
168 };
169 
170 /*
171  * EVTCHNOP_unmask: Unmask the specified local event-channel port and deliver
172  * a notification to the appropriate VCPU if an event is pending.
173  */
174 #define EVTCHNOP_unmask		  9
175 struct evtchn_unmask {
176 	/* IN parameters. */
177 	evtchn_port_t port;
178 };
179 
180 /*
181  * EVTCHNOP_reset: Close all event channels associated with specified domain.
182  * NOTES:
183  *  1. <dom> may be specified as DOMID_SELF.
184  *  2. Only a sufficiently-privileged domain may specify other than DOMID_SELF.
185  */
186 #define EVTCHNOP_reset		 10
187 struct evtchn_reset {
188 	/* IN parameters. */
189 	domid_t dom;
190 };
191 typedef struct evtchn_reset evtchn_reset_t;
192 
193 /*
194  * EVTCHNOP_init_control: initialize the control block for the FIFO ABI.
195  */
196 #define EVTCHNOP_init_control    11
197 struct evtchn_init_control {
198 	/* IN parameters. */
199 	uint64_t control_gfn;
200 	uint32_t offset;
201 	uint32_t vcpu;
202 	/* OUT parameters. */
203 	uint8_t link_bits;
204 	uint8_t _pad[7];
205 };
206 
207 /*
208  * EVTCHNOP_expand_array: add an additional page to the event array.
209  */
210 #define EVTCHNOP_expand_array    12
211 struct evtchn_expand_array {
212 	/* IN parameters. */
213 	uint64_t array_gfn;
214 };
215 
216 /*
217  * EVTCHNOP_set_priority: set the priority for an event channel.
218  */
219 #define EVTCHNOP_set_priority    13
220 struct evtchn_set_priority {
221 	/* IN parameters. */
222 	uint32_t port;
223 	uint32_t priority;
224 };
225 
226 struct evtchn_op {
227 	uint32_t cmd; /* EVTCHNOP_* */
228 	union {
229 		struct evtchn_alloc_unbound    alloc_unbound;
230 		struct evtchn_bind_interdomain bind_interdomain;
231 		struct evtchn_bind_virq	       bind_virq;
232 		struct evtchn_bind_pirq	       bind_pirq;
233 		struct evtchn_bind_ipi	       bind_ipi;
234 		struct evtchn_close	       close;
235 		struct evtchn_send	       send;
236 		struct evtchn_status	       status;
237 		struct evtchn_bind_vcpu	       bind_vcpu;
238 		struct evtchn_unmask	       unmask;
239 	} u;
240 };
241 DEFINE_GUEST_HANDLE_STRUCT(evtchn_op);
242 
243 /*
244  * 2-level ABI
245  */
246 
247 #define EVTCHN_2L_NR_CHANNELS (sizeof(xen_ulong_t) * sizeof(xen_ulong_t) * 64)
248 
249 /*
250  * FIFO ABI
251  */
252 
253 /* Events may have priorities from 0 (highest) to 15 (lowest). */
254 #define EVTCHN_FIFO_PRIORITY_MAX     0
255 #define EVTCHN_FIFO_PRIORITY_DEFAULT 7
256 #define EVTCHN_FIFO_PRIORITY_MIN     15
257 
258 #define EVTCHN_FIFO_MAX_QUEUES (EVTCHN_FIFO_PRIORITY_MIN + 1)
259 
260 typedef uint32_t event_word_t;
261 
262 #define EVTCHN_FIFO_PENDING 31
263 #define EVTCHN_FIFO_MASKED  30
264 #define EVTCHN_FIFO_LINKED  29
265 #define EVTCHN_FIFO_BUSY    28
266 
267 #define EVTCHN_FIFO_LINK_BITS 17
268 #define EVTCHN_FIFO_LINK_MASK ((1 << EVTCHN_FIFO_LINK_BITS) - 1)
269 
270 #define EVTCHN_FIFO_NR_CHANNELS (1 << EVTCHN_FIFO_LINK_BITS)
271 
272 struct evtchn_fifo_control_block {
273 	uint32_t     ready;
274 	uint32_t     _rsvd;
275 	event_word_t head[EVTCHN_FIFO_MAX_QUEUES];
276 };
277 
278 #endif /* __XEN_PUBLIC_EVENT_CHANNEL_H__ */
279