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