176acc41fSJustin T. Gibbs /****************************************************************************** 276acc41fSJustin T. Gibbs * xen_intr.h 33a6d1fcfSKip Macy * 476acc41fSJustin T. Gibbs * APIs for managing Xen event channel, virtual IRQ, and physical IRQ 576acc41fSJustin T. Gibbs * notifications. 676acc41fSJustin T. Gibbs * 776acc41fSJustin T. Gibbs * Copyright (c) 2004, K A Fraser 876acc41fSJustin T. Gibbs * Copyright (c) 2012, Spectra Logic Corporation 976acc41fSJustin T. Gibbs * 1076acc41fSJustin T. Gibbs * This file may be distributed separately from the Linux kernel, or 1176acc41fSJustin T. Gibbs * incorporated into other software packages, subject to the following license: 1276acc41fSJustin T. Gibbs * 1376acc41fSJustin T. Gibbs * Permission is hereby granted, free of charge, to any person obtaining a copy 1476acc41fSJustin T. Gibbs * of this source file (the "Software"), to deal in the Software without 1576acc41fSJustin T. Gibbs * restriction, including without limitation the rights to use, copy, modify, 1676acc41fSJustin T. Gibbs * merge, publish, distribute, sublicense, and/or sell copies of the Software, 1776acc41fSJustin T. Gibbs * and to permit persons to whom the Software is furnished to do so, subject to 1876acc41fSJustin T. Gibbs * the following conditions: 1976acc41fSJustin T. Gibbs * 2076acc41fSJustin T. Gibbs * The above copyright notice and this permission notice shall be included in 2176acc41fSJustin T. Gibbs * all copies or substantial portions of the Software. 2276acc41fSJustin T. Gibbs * 2376acc41fSJustin T. Gibbs * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 2476acc41fSJustin T. Gibbs * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 2576acc41fSJustin T. Gibbs * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 2676acc41fSJustin T. Gibbs * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 2776acc41fSJustin T. Gibbs * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 2876acc41fSJustin T. Gibbs * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 2976acc41fSJustin T. Gibbs * IN THE SOFTWARE. 303a6d1fcfSKip Macy */ 3176acc41fSJustin T. Gibbs #ifndef _XEN_INTR_H_ 3276acc41fSJustin T. Gibbs #define _XEN_INTR_H_ 333a6d1fcfSKip Macy 34ad7dd514SElliott Mitchell #include <contrib/xen/event_channel.h> 353a6d1fcfSKip Macy 3676acc41fSJustin T. Gibbs /** Registered Xen interrupt callback handle. */ 3776acc41fSJustin T. Gibbs typedef void * xen_intr_handle_t; 383a6d1fcfSKip Macy 39*af610cabSElliott Mitchell /* 40*af610cabSElliott Mitchell * Main handler for Xen event channel interrupts 41*af610cabSElliott Mitchell */ 42*af610cabSElliott Mitchell extern driver_filter_t xen_intr_handle_upcall; 432f9ec994SRoger Pau Monné 4476acc41fSJustin T. Gibbs /** 4576acc41fSJustin T. Gibbs * Associate an already allocated local event channel port an interrupt 4676acc41fSJustin T. Gibbs * handler. 4776acc41fSJustin T. Gibbs * 4876acc41fSJustin T. Gibbs * \param dev The device making this bind request. 4976acc41fSJustin T. Gibbs * \param local_port The event channel to bind. 5076acc41fSJustin T. Gibbs * \param filter An interrupt filter handler. Specify NULL 5176acc41fSJustin T. Gibbs * to always dispatch to the ithread handler. 5276acc41fSJustin T. Gibbs * \param handler An interrupt ithread handler. Optional (can 5376acc41fSJustin T. Gibbs * specify NULL) if all necessary event actions 5476acc41fSJustin T. Gibbs * are performed by filter. 5576acc41fSJustin T. Gibbs * \param arg Argument to present to both filter and handler. 5676acc41fSJustin T. Gibbs * \param irqflags Interrupt handler flags. See sys/bus.h. 5776acc41fSJustin T. Gibbs * \param handlep Pointer to an opaque handle used to manage this 5876acc41fSJustin T. Gibbs * registration. 5976acc41fSJustin T. Gibbs * 6076acc41fSJustin T. Gibbs * \returns 0 on success, otherwise an errno. 6112678024SDoug Rabson */ 6276acc41fSJustin T. Gibbs int xen_intr_bind_local_port(device_t dev, evtchn_port_t local_port, 6376acc41fSJustin T. Gibbs driver_filter_t filter, driver_intr_t handler, void *arg, 6476acc41fSJustin T. Gibbs enum intr_type irqflags, xen_intr_handle_t *handlep); 653a6d1fcfSKip Macy 6676acc41fSJustin T. Gibbs /** 6776acc41fSJustin T. Gibbs * Allocate a local event channel port, accessible by the specified 6876acc41fSJustin T. Gibbs * remote/foreign domain and, if successful, associate the port with 6976acc41fSJustin T. Gibbs * the specified interrupt handler. 7076acc41fSJustin T. Gibbs * 7176acc41fSJustin T. Gibbs * \param dev The device making this bind request. 7276acc41fSJustin T. Gibbs * \param remote_domain Remote domain grant permission to signal the 7376acc41fSJustin T. Gibbs * newly allocated local port. 7476acc41fSJustin T. Gibbs * \param filter An interrupt filter handler. Specify NULL 7576acc41fSJustin T. Gibbs * to always dispatch to the ithread handler. 7676acc41fSJustin T. Gibbs * \param handler An interrupt ithread handler. Optional (can 7776acc41fSJustin T. Gibbs * specify NULL) if all necessary event actions 7876acc41fSJustin T. Gibbs * are performed by filter. 7976acc41fSJustin T. Gibbs * \param arg Argument to present to both filter and handler. 8076acc41fSJustin T. Gibbs * \param irqflags Interrupt handler flags. See sys/bus.h. 8176acc41fSJustin T. Gibbs * \param handlep Pointer to an opaque handle used to manage this 8276acc41fSJustin T. Gibbs * registration. 8376acc41fSJustin T. Gibbs * 8476acc41fSJustin T. Gibbs * \returns 0 on success, otherwise an errno. 8512678024SDoug Rabson */ 8676acc41fSJustin T. Gibbs int xen_intr_alloc_and_bind_local_port(device_t dev, 8776acc41fSJustin T. Gibbs u_int remote_domain, driver_filter_t filter, driver_intr_t handler, 8876acc41fSJustin T. Gibbs void *arg, enum intr_type irqflags, xen_intr_handle_t *handlep); 8912678024SDoug Rabson 9076acc41fSJustin T. Gibbs /** 9176acc41fSJustin T. Gibbs * Associate the specified interrupt handler with the remote event 9276acc41fSJustin T. Gibbs * channel port specified by remote_domain and remote_port. 9376acc41fSJustin T. Gibbs * 9476acc41fSJustin T. Gibbs * \param dev The device making this bind request. 9576acc41fSJustin T. Gibbs * \param remote_domain The domain peer for this event channel connection. 9676acc41fSJustin T. Gibbs * \param remote_port Remote domain's local port number for this event 9776acc41fSJustin T. Gibbs * channel port. 9876acc41fSJustin T. Gibbs * \param filter An interrupt filter handler. Specify NULL 9976acc41fSJustin T. Gibbs * to always dispatch to the ithread handler. 10076acc41fSJustin T. Gibbs * \param handler An interrupt ithread handler. Optional (can 10176acc41fSJustin T. Gibbs * specify NULL) if all necessary event actions 10276acc41fSJustin T. Gibbs * are performed by filter. 10376acc41fSJustin T. Gibbs * \param arg Argument to present to both filter and handler. 10476acc41fSJustin T. Gibbs * \param irqflags Interrupt handler flags. See sys/bus.h. 10576acc41fSJustin T. Gibbs * \param handlep Pointer to an opaque handle used to manage this 10676acc41fSJustin T. Gibbs * registration. 10776acc41fSJustin T. Gibbs * 10876acc41fSJustin T. Gibbs * \returns 0 on success, otherwise an errno. 10912678024SDoug Rabson */ 11076acc41fSJustin T. Gibbs int xen_intr_bind_remote_port(device_t dev, u_int remote_domain, 11176acc41fSJustin T. Gibbs evtchn_port_t remote_port, driver_filter_t filter, 11276acc41fSJustin T. Gibbs driver_intr_t handler, void *arg, enum intr_type irqflags, 11376acc41fSJustin T. Gibbs xen_intr_handle_t *handlep); 11412678024SDoug Rabson 11576acc41fSJustin T. Gibbs /** 11676acc41fSJustin T. Gibbs * Associate the specified interrupt handler with the specified Xen 11776acc41fSJustin T. Gibbs * virtual interrupt source. 11876acc41fSJustin T. Gibbs * 11976acc41fSJustin T. Gibbs * \param dev The device making this bind request. 12076acc41fSJustin T. Gibbs * \param virq The Xen virtual IRQ number for the Xen interrupt 12176acc41fSJustin T. Gibbs * source being hooked. 12276acc41fSJustin T. Gibbs * \param cpu The cpu on which interrupt events should be delivered. 12376acc41fSJustin T. Gibbs * \param filter An interrupt filter handler. Specify NULL 12476acc41fSJustin T. Gibbs * to always dispatch to the ithread handler. 12576acc41fSJustin T. Gibbs * \param handler An interrupt ithread handler. Optional (can 12676acc41fSJustin T. Gibbs * specify NULL) if all necessary event actions 12776acc41fSJustin T. Gibbs * are performed by filter. 12876acc41fSJustin T. Gibbs * \param arg Argument to present to both filter and handler. 12976acc41fSJustin T. Gibbs * \param irqflags Interrupt handler flags. See sys/bus.h. 13076acc41fSJustin T. Gibbs * \param handlep Pointer to an opaque handle used to manage this 13176acc41fSJustin T. Gibbs * registration. 13276acc41fSJustin T. Gibbs * 13376acc41fSJustin T. Gibbs * \returns 0 on success, otherwise an errno. 13412678024SDoug Rabson */ 13576acc41fSJustin T. Gibbs int xen_intr_bind_virq(device_t dev, u_int virq, u_int cpu, 13676acc41fSJustin T. Gibbs driver_filter_t filter, driver_intr_t handler, 13776acc41fSJustin T. Gibbs void *arg, enum intr_type irqflags, xen_intr_handle_t *handlep); 1383a6d1fcfSKip Macy 13976acc41fSJustin T. Gibbs /** 140e44af46eSJustin T. Gibbs * Allocate a local event channel port for servicing interprocessor 141e44af46eSJustin T. Gibbs * interupts and, if successful, associate the port with the specified 142e44af46eSJustin T. Gibbs * interrupt handler. 14376acc41fSJustin T. Gibbs * 14476acc41fSJustin T. Gibbs * \param cpu The cpu receiving the IPI. 145e44af46eSJustin T. Gibbs * \param filter The interrupt filter servicing this IPI. 14676acc41fSJustin T. Gibbs * \param irqflags Interrupt handler flags. See sys/bus.h. 14776acc41fSJustin T. Gibbs * \param handlep Pointer to an opaque handle used to manage this 14876acc41fSJustin T. Gibbs * registration. 14976acc41fSJustin T. Gibbs * 15076acc41fSJustin T. Gibbs * \returns 0 on success, otherwise an errno. 15112678024SDoug Rabson */ 152ca7af67aSRoger Pau Monné int xen_intr_alloc_and_bind_ipi(u_int cpu, 15376acc41fSJustin T. Gibbs driver_filter_t filter, enum intr_type irqflags, 15476acc41fSJustin T. Gibbs xen_intr_handle_t *handlep); 15512678024SDoug Rabson 15676acc41fSJustin T. Gibbs /** 15776acc41fSJustin T. Gibbs * Unbind an interrupt handler from its interrupt source. 15876acc41fSJustin T. Gibbs * 15976acc41fSJustin T. Gibbs * \param handlep A pointer to the opaque handle that was initialized 16076acc41fSJustin T. Gibbs * at the time the interrupt source was bound. 16176acc41fSJustin T. Gibbs * 16276acc41fSJustin T. Gibbs * \returns 0 on success, otherwise an errno. 16376acc41fSJustin T. Gibbs * 16476acc41fSJustin T. Gibbs * \note The event channel, if any, that was allocated at bind time is 16576acc41fSJustin T. Gibbs * closed upon successful return of this method. 16676acc41fSJustin T. Gibbs * 16776acc41fSJustin T. Gibbs * \note It is always safe to call xen_intr_unbind() on a handle that 16876acc41fSJustin T. Gibbs * has been initilized to NULL. 16912678024SDoug Rabson */ 17076acc41fSJustin T. Gibbs void xen_intr_unbind(xen_intr_handle_t *handle); 1713a6d1fcfSKip Macy 17276acc41fSJustin T. Gibbs /** 17376acc41fSJustin T. Gibbs * Add a description to an interrupt handler. 17476acc41fSJustin T. Gibbs * 17576acc41fSJustin T. Gibbs * \param handle The opaque handle that was initialized at the time 17676acc41fSJustin T. Gibbs * the interrupt source was bound. 17776acc41fSJustin T. Gibbs * 17876acc41fSJustin T. Gibbs * \param fmt The sprintf compatible format string for the description, 17976acc41fSJustin T. Gibbs * followed by optional sprintf arguments. 18076acc41fSJustin T. Gibbs * 18176acc41fSJustin T. Gibbs * \returns 0 on success, otherwise an errno. 18212678024SDoug Rabson */ 18376acc41fSJustin T. Gibbs int 18476acc41fSJustin T. Gibbs xen_intr_describe(xen_intr_handle_t port_handle, const char *fmt, ...) 18576acc41fSJustin T. Gibbs __attribute__((format(printf, 2, 3))); 1863a6d1fcfSKip Macy 18776acc41fSJustin T. Gibbs /** 18876acc41fSJustin T. Gibbs * Signal the remote peer of an interrupt source associated with an 18976acc41fSJustin T. Gibbs * event channel port. 19076acc41fSJustin T. Gibbs * 19176acc41fSJustin T. Gibbs * \param handle The opaque handle that was initialized at the time 19276acc41fSJustin T. Gibbs * the interrupt source was bound. 19376acc41fSJustin T. Gibbs * 19476acc41fSJustin T. Gibbs * \note For xen interrupt sources other than event channel ports, 19576acc41fSJustin T. Gibbs * this method takes no action. 19676acc41fSJustin T. Gibbs */ 19776acc41fSJustin T. Gibbs void xen_intr_signal(xen_intr_handle_t handle); 1983a6d1fcfSKip Macy 19976acc41fSJustin T. Gibbs /** 20076acc41fSJustin T. Gibbs * Get the local event channel port number associated with this interrupt 20176acc41fSJustin T. Gibbs * source. 20276acc41fSJustin T. Gibbs * 20376acc41fSJustin T. Gibbs * \param handle The opaque handle that was initialized at the time 20476acc41fSJustin T. Gibbs * the interrupt source was bound. 20576acc41fSJustin T. Gibbs * 20676acc41fSJustin T. Gibbs * \returns 0 if the handle is invalid, otherwise positive port number. 20776acc41fSJustin T. Gibbs */ 20876acc41fSJustin T. Gibbs evtchn_port_t xen_intr_port(xen_intr_handle_t handle); 2093a6d1fcfSKip Macy 21044e06d15SRoger Pau Monné /** 2116d54cab1SRoger Pau Monné * Bind an event channel port with a handler 2126d54cab1SRoger Pau Monné * 2136d54cab1SRoger Pau Monné * \param dev The device making this bind request. 2146d54cab1SRoger Pau Monné * \param filter An interrupt filter handler. Specify NULL 2156d54cab1SRoger Pau Monné * to always dispatch to the ithread handler. 2166d54cab1SRoger Pau Monné * \param handler An interrupt ithread handler. Optional (can 2176d54cab1SRoger Pau Monné * specify NULL) if all necessary event actions 2186d54cab1SRoger Pau Monné * are performed by filter. 2196d54cab1SRoger Pau Monné * \param arg Argument to present to both filter and handler. 2206d54cab1SRoger Pau Monné * \param irqflags Interrupt handler flags. See sys/bus.h. 2216d54cab1SRoger Pau Monné * \param handle Opaque handle used to manage this registration. 2226d54cab1SRoger Pau Monné * 2236d54cab1SRoger Pau Monné * \returns 0 on success, otherwise an errno. 2246d54cab1SRoger Pau Monné */ 225ca7af67aSRoger Pau Monné int xen_intr_add_handler(const char *name, driver_filter_t filter, 2266d54cab1SRoger Pau Monné driver_intr_t handler, void *arg, enum intr_type flags, 2276d54cab1SRoger Pau Monné xen_intr_handle_t handle); 2286d54cab1SRoger Pau Monné 2290f4d7d9fSRoger Pau Monné /** 2300f4d7d9fSRoger Pau Monné * Get a reference to an event channel port 2310f4d7d9fSRoger Pau Monné * 2320f4d7d9fSRoger Pau Monné * \param port Event channel port to which we get a reference. 2330f4d7d9fSRoger Pau Monné * \param handlep Pointer to an opaque handle used to manage this 2340f4d7d9fSRoger Pau Monné * registration. 2350f4d7d9fSRoger Pau Monné * 2360f4d7d9fSRoger Pau Monné * \returns 0 on success, otherwise an errno. 2370f4d7d9fSRoger Pau Monné */ 2380f4d7d9fSRoger Pau Monné int xen_intr_get_evtchn_from_port(evtchn_port_t port, 2390f4d7d9fSRoger Pau Monné xen_intr_handle_t *handlep); 2400f4d7d9fSRoger Pau Monné 2413a6d1fcfSKip Macy #endif /* _XEN_INTR_H_ */ 242