xref: /freebsd/sys/xen/xen_intr.h (revision bdd1243df58e60e85101c09001d9812a789b6bc4)
1 /******************************************************************************
2  * xen_intr.h
3  *
4  * APIs for managing Xen event channel, virtual IRQ, and physical IRQ
5  * notifications.
6  *
7  * Copyright (c) 2004, K A Fraser
8  * Copyright (c) 2012, Spectra Logic Corporation
9  *
10  * This file may be distributed separately from the Linux kernel, or
11  * incorporated into other software packages, subject to the following license:
12  *
13  * Permission is hereby granted, free of charge, to any person obtaining a copy
14  * of this source file (the "Software"), to deal in the Software without
15  * restriction, including without limitation the rights to use, copy, modify,
16  * merge, publish, distribute, sublicense, and/or sell copies of the Software,
17  * and to permit persons to whom the Software is furnished to do so, subject to
18  * the following conditions:
19  *
20  * The above copyright notice and this permission notice shall be included in
21  * all copies or substantial portions of the Software.
22  *
23  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
24  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
26  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
28  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
29  * IN THE SOFTWARE.
30  *
31  * $FreeBSD$
32  */
33 #ifndef _XEN_INTR_H_
34 #define _XEN_INTR_H_
35 
36 #include <contrib/xen/event_channel.h>
37 
38 /** Registered Xen interrupt callback handle. */
39 typedef void * xen_intr_handle_t;
40 
41 /*
42  * Main handler for Xen event channel interrupts
43  */
44 extern driver_filter_t xen_intr_handle_upcall;
45 
46 /**
47  * Associate an already allocated local event channel port an interrupt
48  * handler.
49  *
50  * \param dev         The device making this bind request.
51  * \param local_port  The event channel to bind.
52  * \param filter      An interrupt filter handler.  Specify NULL
53  *                    to always dispatch to the ithread handler.
54  * \param handler     An interrupt ithread handler.  Optional (can
55  *                    specify NULL) if all necessary event actions
56  *                    are performed by filter.
57  * \param arg         Argument to present to both filter and handler.
58  * \param irqflags    Interrupt handler flags.  See sys/bus.h.
59  * \param handlep     Pointer to an opaque handle used to manage this
60  *                    registration.
61  *
62  * \returns  0 on success, otherwise an errno.
63  */
64 int xen_intr_bind_local_port(device_t dev, evtchn_port_t local_port,
65 	driver_filter_t filter, driver_intr_t handler, void *arg,
66 	enum intr_type irqflags, xen_intr_handle_t *handlep);
67 
68 /**
69  * Allocate a local event channel port, accessible by the specified
70  * remote/foreign domain and, if successful, associate the port with
71  * the specified interrupt handler.
72  *
73  * \param dev            The device making this bind request.
74  * \param remote_domain  Remote domain grant permission to signal the
75  *                       newly allocated local port.
76  * \param filter         An interrupt filter handler.  Specify NULL
77  *                       to always dispatch to the ithread handler.
78  * \param handler        An interrupt ithread handler.  Optional (can
79  *                       specify NULL) if all necessary event actions
80  *                       are performed by filter.
81  * \param arg            Argument to present to both filter and handler.
82  * \param irqflags       Interrupt handler flags.  See sys/bus.h.
83  * \param handlep        Pointer to an opaque handle used to manage this
84  *                       registration.
85  *
86  * \returns  0 on success, otherwise an errno.
87  */
88 int xen_intr_alloc_and_bind_local_port(device_t dev,
89 	u_int remote_domain, driver_filter_t filter, driver_intr_t handler,
90 	void *arg, enum intr_type irqflags, xen_intr_handle_t *handlep);
91 
92 /**
93  * Associate the specified interrupt handler with the remote event
94  * channel port specified by remote_domain and remote_port.
95  *
96  * \param dev            The device making this bind request.
97  * \param remote_domain  The domain peer for this event channel connection.
98  * \param remote_port    Remote domain's local port number for this event
99  *                       channel port.
100  * \param filter         An interrupt filter handler.  Specify NULL
101  *                       to always dispatch to the ithread handler.
102  * \param handler        An interrupt ithread handler.  Optional (can
103  *                       specify NULL) if all necessary event actions
104  *                       are performed by filter.
105  * \param arg            Argument to present to both filter and handler.
106  * \param irqflags       Interrupt handler flags.  See sys/bus.h.
107  * \param handlep        Pointer to an opaque handle used to manage this
108  *                       registration.
109  *
110  * \returns  0 on success, otherwise an errno.
111  */
112 int xen_intr_bind_remote_port(device_t dev, u_int remote_domain,
113 	evtchn_port_t remote_port, driver_filter_t filter,
114 	driver_intr_t handler, void *arg, enum intr_type irqflags,
115 	xen_intr_handle_t *handlep);
116 
117 /**
118  * Associate the specified interrupt handler with the specified Xen
119  * virtual interrupt source.
120  *
121  * \param dev       The device making this bind request.
122  * \param virq      The Xen virtual IRQ number for the Xen interrupt
123  *                  source being hooked.
124  * \param cpu       The cpu on which interrupt events should be delivered.
125  * \param filter    An interrupt filter handler.  Specify NULL
126  *                  to always dispatch to the ithread handler.
127  * \param handler   An interrupt ithread handler.  Optional (can
128  *                  specify NULL) if all necessary event actions
129  *                  are performed by filter.
130  * \param arg       Argument to present to both filter and handler.
131  * \param irqflags  Interrupt handler flags.  See sys/bus.h.
132  * \param handlep   Pointer to an opaque handle used to manage this
133  *                  registration.
134  *
135  * \returns  0 on success, otherwise an errno.
136  */
137 int xen_intr_bind_virq(device_t dev, u_int virq, u_int cpu,
138 	driver_filter_t filter, driver_intr_t handler,
139 	void *arg, enum intr_type irqflags, xen_intr_handle_t *handlep);
140 
141 /**
142  * Allocate a local event channel port for servicing interprocessor
143  * interupts and, if successful, associate the port with the specified
144  * interrupt handler.
145  *
146  * \param cpu       The cpu receiving the IPI.
147  * \param filter    The interrupt filter servicing this IPI.
148  * \param irqflags  Interrupt handler flags.  See sys/bus.h.
149  * \param handlep   Pointer to an opaque handle used to manage this
150  *                  registration.
151  *
152  * \returns  0 on success, otherwise an errno.
153  */
154 int xen_intr_alloc_and_bind_ipi(u_int cpu,
155 	driver_filter_t filter, enum intr_type irqflags,
156 	xen_intr_handle_t *handlep);
157 
158 /**
159  * Unbind an interrupt handler from its interrupt source.
160  *
161  * \param handlep  A pointer to the opaque handle that was initialized
162  *		   at the time the interrupt source was bound.
163  *
164  * \returns  0 on success, otherwise an errno.
165  *
166  * \note  The event channel, if any, that was allocated at bind time is
167  *        closed upon successful return of this method.
168  *
169  * \note  It is always safe to call xen_intr_unbind() on a handle that
170  *        has been initilized to NULL.
171  */
172 void xen_intr_unbind(xen_intr_handle_t *handle);
173 
174 /**
175  * Add a description to an interrupt handler.
176  *
177  * \param handle  The opaque handle that was initialized at the time
178  *		  the interrupt source was bound.
179  *
180  * \param fmt     The sprintf compatible format string for the description,
181  *                followed by optional sprintf arguments.
182  *
183  * \returns  0 on success, otherwise an errno.
184  */
185 int
186 xen_intr_describe(xen_intr_handle_t port_handle, const char *fmt, ...)
187 	__attribute__((format(printf, 2, 3)));
188 
189 /**
190  * Signal the remote peer of an interrupt source associated with an
191  * event channel port.
192  *
193  * \param handle  The opaque handle that was initialized at the time
194  *                the interrupt source was bound.
195  *
196  * \note  For xen interrupt sources other than event channel ports,
197  *        this method takes no action.
198  */
199 void xen_intr_signal(xen_intr_handle_t handle);
200 
201 /**
202  * Get the local event channel port number associated with this interrupt
203  * source.
204  *
205  * \param handle  The opaque handle that was initialized at the time
206  *                the interrupt source was bound.
207  *
208  * \returns  0 if the handle is invalid, otherwise positive port number.
209  */
210 evtchn_port_t xen_intr_port(xen_intr_handle_t handle);
211 
212 /**
213  * Bind an event channel port with a handler
214  *
215  * \param dev       The device making this bind request.
216  * \param filter    An interrupt filter handler.  Specify NULL
217  *                  to always dispatch to the ithread handler.
218  * \param handler   An interrupt ithread handler.  Optional (can
219  *                  specify NULL) if all necessary event actions
220  *                  are performed by filter.
221  * \param arg       Argument to present to both filter and handler.
222  * \param irqflags  Interrupt handler flags.  See sys/bus.h.
223  * \param handle    Opaque handle used to manage this registration.
224  *
225  * \returns  0 on success, otherwise an errno.
226  */
227 int xen_intr_add_handler(const char *name, driver_filter_t filter,
228 	driver_intr_t handler, void *arg, enum intr_type flags,
229 	xen_intr_handle_t handle);
230 
231 /**
232  * Get a reference to an event channel port
233  *
234  * \param port	    Event channel port to which we get a reference.
235  * \param handlep   Pointer to an opaque handle used to manage this
236  *                  registration.
237  *
238  * \returns  0 on success, otherwise an errno.
239  */
240 int xen_intr_get_evtchn_from_port(evtchn_port_t port,
241 	xen_intr_handle_t *handlep);
242 
243 #endif /* _XEN_INTR_H_ */
244