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 <xen/interface/event_channel.h> 37 38 /** Registered Xen interrupt callback handle. */ 39 typedef void * xen_intr_handle_t; 40 41 /** If non-zero, the hypervisor has been configured to use a direct vector */ 42 extern int xen_vector_callback_enabled; 43 44 /** 45 * Associate an already allocated local event channel port an interrupt 46 * handler. 47 * 48 * \param dev The device making this bind request. 49 * \param local_port The event channel to bind. 50 * \param filter An interrupt filter handler. Specify NULL 51 * to always dispatch to the ithread handler. 52 * \param handler An interrupt ithread handler. Optional (can 53 * specify NULL) if all necessary event actions 54 * are performed by filter. 55 * \param arg Argument to present to both filter and handler. 56 * \param irqflags Interrupt handler flags. See sys/bus.h. 57 * \param handlep Pointer to an opaque handle used to manage this 58 * registration. 59 * 60 * \returns 0 on success, otherwise an errno. 61 */ 62 int xen_intr_bind_local_port(device_t dev, evtchn_port_t local_port, 63 driver_filter_t filter, driver_intr_t handler, void *arg, 64 enum intr_type irqflags, xen_intr_handle_t *handlep); 65 66 /** 67 * Allocate a local event channel port, accessible by the specified 68 * remote/foreign domain and, if successful, associate the port with 69 * the specified interrupt handler. 70 * 71 * \param dev The device making this bind request. 72 * \param remote_domain Remote domain grant permission to signal the 73 * newly allocated local port. 74 * \param filter An interrupt filter handler. Specify NULL 75 * to always dispatch to the ithread handler. 76 * \param handler An interrupt ithread handler. Optional (can 77 * specify NULL) if all necessary event actions 78 * are performed by filter. 79 * \param arg Argument to present to both filter and handler. 80 * \param irqflags Interrupt handler flags. See sys/bus.h. 81 * \param handlep Pointer to an opaque handle used to manage this 82 * registration. 83 * 84 * \returns 0 on success, otherwise an errno. 85 */ 86 int xen_intr_alloc_and_bind_local_port(device_t dev, 87 u_int remote_domain, driver_filter_t filter, driver_intr_t handler, 88 void *arg, enum intr_type irqflags, xen_intr_handle_t *handlep); 89 90 /** 91 * Associate the specified interrupt handler with the remote event 92 * channel port specified by remote_domain and remote_port. 93 * 94 * \param dev The device making this bind request. 95 * \param remote_domain The domain peer for this event channel connection. 96 * \param remote_port Remote domain's local port number for this event 97 * channel port. 98 * \param filter An interrupt filter handler. Specify NULL 99 * to always dispatch to the ithread handler. 100 * \param handler An interrupt ithread handler. Optional (can 101 * specify NULL) if all necessary event actions 102 * are performed by filter. 103 * \param arg Argument to present to both filter and handler. 104 * \param irqflags Interrupt handler flags. See sys/bus.h. 105 * \param handlep Pointer to an opaque handle used to manage this 106 * registration. 107 * 108 * \returns 0 on success, otherwise an errno. 109 */ 110 int xen_intr_bind_remote_port(device_t dev, u_int remote_domain, 111 evtchn_port_t remote_port, driver_filter_t filter, 112 driver_intr_t handler, void *arg, enum intr_type irqflags, 113 xen_intr_handle_t *handlep); 114 115 /** 116 * Associate the specified interrupt handler with the specified Xen 117 * virtual interrupt source. 118 * 119 * \param dev The device making this bind request. 120 * \param virq The Xen virtual IRQ number for the Xen interrupt 121 * source being hooked. 122 * \param cpu The cpu on which interrupt events should be delivered. 123 * \param filter An interrupt filter handler. Specify NULL 124 * to always dispatch to the ithread handler. 125 * \param handler An interrupt ithread handler. Optional (can 126 * specify NULL) if all necessary event actions 127 * are performed by filter. 128 * \param arg Argument to present to both filter and handler. 129 * \param irqflags Interrupt handler flags. See sys/bus.h. 130 * \param handlep Pointer to an opaque handle used to manage this 131 * registration. 132 * 133 * \returns 0 on success, otherwise an errno. 134 */ 135 int xen_intr_bind_virq(device_t dev, u_int virq, u_int cpu, 136 driver_filter_t filter, driver_intr_t handler, 137 void *arg, enum intr_type irqflags, xen_intr_handle_t *handlep); 138 139 /** 140 * Allocate a local event channel port for servicing interprocessor 141 * interupts and, if successful, associate the port with the specified 142 * interrupt handler. 143 * 144 * \param dev The device making this bind request. 145 * \param cpu The cpu receiving the IPI. 146 * \param filter The interrupt filter servicing this IPI. 147 * \param irqflags Interrupt handler flags. See sys/bus.h. 148 * \param handlep Pointer to an opaque handle used to manage this 149 * registration. 150 * 151 * \returns 0 on success, otherwise an errno. 152 */ 153 int xen_intr_alloc_and_bind_ipi(device_t dev, u_int cpu, 154 driver_filter_t filter, enum intr_type irqflags, 155 xen_intr_handle_t *handlep); 156 157 /** 158 * Register a physical interrupt vector and setup the interrupt source. 159 * 160 * \param vector The global vector to use. 161 * \param trig Default trigger method. 162 * \param pol Default polarity of the interrupt. 163 * 164 * \returns 0 on success, otherwise an errno. 165 */ 166 int xen_register_pirq(int vector, enum intr_trigger trig, 167 enum intr_polarity pol); 168 169 /** 170 * Unbind an interrupt handler from its interrupt source. 171 * 172 * \param handlep A pointer to the opaque handle that was initialized 173 * at the time the interrupt source was bound. 174 * 175 * \returns 0 on success, otherwise an errno. 176 * 177 * \note The event channel, if any, that was allocated at bind time is 178 * closed upon successful return of this method. 179 * 180 * \note It is always safe to call xen_intr_unbind() on a handle that 181 * has been initilized to NULL. 182 */ 183 void xen_intr_unbind(xen_intr_handle_t *handle); 184 185 /** 186 * Add a description to an interrupt handler. 187 * 188 * \param handle The opaque handle that was initialized at the time 189 * the interrupt source was bound. 190 * 191 * \param fmt The sprintf compatible format string for the description, 192 * followed by optional sprintf arguments. 193 * 194 * \returns 0 on success, otherwise an errno. 195 */ 196 int 197 xen_intr_describe(xen_intr_handle_t port_handle, const char *fmt, ...) 198 __attribute__((format(printf, 2, 3))); 199 200 /** 201 * Signal the remote peer of an interrupt source associated with an 202 * event channel port. 203 * 204 * \param handle The opaque handle that was initialized at the time 205 * the interrupt source was bound. 206 * 207 * \note For xen interrupt sources other than event channel ports, 208 * this method takes no action. 209 */ 210 void xen_intr_signal(xen_intr_handle_t handle); 211 212 /** 213 * Get the local event channel port number associated with this interrupt 214 * source. 215 * 216 * \param handle The opaque handle that was initialized at the time 217 * the interrupt source was bound. 218 * 219 * \returns 0 if the handle is invalid, otherwise positive port number. 220 */ 221 evtchn_port_t xen_intr_port(xen_intr_handle_t handle); 222 223 /** 224 * Setup MSI vector interrupt(s). 225 * 226 * \param dev The device that requests the binding. 227 * 228 * \param vector Requested initial vector to bind the MSI interrupt(s) to. 229 * 230 * \param count Number of vectors to allocate. 231 * 232 * \returns 0 on success, otherwise an errno. 233 */ 234 int xen_register_msi(device_t dev, int vector, int count); 235 236 /** 237 * Teardown a MSI vector interrupt. 238 * 239 * \param vector Requested vector to release. 240 * 241 * \returns 0 on success, otherwise an errno. 242 */ 243 int xen_release_msi(int vector); 244 245 /** 246 * Bind an event channel port with a handler 247 * 248 * \param dev The device making this bind request. 249 * \param filter An interrupt filter handler. Specify NULL 250 * to always dispatch to the ithread handler. 251 * \param handler An interrupt ithread handler. Optional (can 252 * specify NULL) if all necessary event actions 253 * are performed by filter. 254 * \param arg Argument to present to both filter and handler. 255 * \param irqflags Interrupt handler flags. See sys/bus.h. 256 * \param handle Opaque handle used to manage this registration. 257 * 258 * \returns 0 on success, otherwise an errno. 259 */ 260 int xen_intr_add_handler(device_t dev, driver_filter_t filter, 261 driver_intr_t handler, void *arg, enum intr_type flags, 262 xen_intr_handle_t handle); 263 264 #endif /* _XEN_INTR_H_ */ 265