1*4882a593Smuzhiyun /* SPDX-License-Identifier: GPL-2.0-only */ 2*4882a593Smuzhiyun /* 3*4882a593Smuzhiyun * IRQ offload/bypass manager 4*4882a593Smuzhiyun * 5*4882a593Smuzhiyun * Copyright (C) 2015 Red Hat, Inc. 6*4882a593Smuzhiyun * Copyright (c) 2015 Linaro Ltd. 7*4882a593Smuzhiyun */ 8*4882a593Smuzhiyun #ifndef IRQBYPASS_H 9*4882a593Smuzhiyun #define IRQBYPASS_H 10*4882a593Smuzhiyun 11*4882a593Smuzhiyun #include <linux/list.h> 12*4882a593Smuzhiyun 13*4882a593Smuzhiyun struct irq_bypass_consumer; 14*4882a593Smuzhiyun 15*4882a593Smuzhiyun /* 16*4882a593Smuzhiyun * Theory of operation 17*4882a593Smuzhiyun * 18*4882a593Smuzhiyun * The IRQ bypass manager is a simple set of lists and callbacks that allows 19*4882a593Smuzhiyun * IRQ producers (ex. physical interrupt sources) to be matched to IRQ 20*4882a593Smuzhiyun * consumers (ex. virtualization hardware that allows IRQ bypass or offload) 21*4882a593Smuzhiyun * via a shared token (ex. eventfd_ctx). Producers and consumers register 22*4882a593Smuzhiyun * independently. When a token match is found, the optional @stop callback 23*4882a593Smuzhiyun * will be called for each participant. The pair will then be connected via 24*4882a593Smuzhiyun * the @add_* callbacks, and finally the optional @start callback will allow 25*4882a593Smuzhiyun * any final coordination. When either participant is unregistered, the 26*4882a593Smuzhiyun * process is repeated using the @del_* callbacks in place of the @add_* 27*4882a593Smuzhiyun * callbacks. Match tokens must be unique per producer/consumer, 1:N pairings 28*4882a593Smuzhiyun * are not supported. 29*4882a593Smuzhiyun */ 30*4882a593Smuzhiyun 31*4882a593Smuzhiyun /** 32*4882a593Smuzhiyun * struct irq_bypass_producer - IRQ bypass producer definition 33*4882a593Smuzhiyun * @node: IRQ bypass manager private list management 34*4882a593Smuzhiyun * @token: opaque token to match between producer and consumer (non-NULL) 35*4882a593Smuzhiyun * @irq: Linux IRQ number for the producer device 36*4882a593Smuzhiyun * @add_consumer: Connect the IRQ producer to an IRQ consumer (optional) 37*4882a593Smuzhiyun * @del_consumer: Disconnect the IRQ producer from an IRQ consumer (optional) 38*4882a593Smuzhiyun * @stop: Perform any quiesce operations necessary prior to add/del (optional) 39*4882a593Smuzhiyun * @start: Perform any startup operations necessary after add/del (optional) 40*4882a593Smuzhiyun * 41*4882a593Smuzhiyun * The IRQ bypass producer structure represents an interrupt source for 42*4882a593Smuzhiyun * participation in possible host bypass, for instance an interrupt vector 43*4882a593Smuzhiyun * for a physical device assigned to a VM. 44*4882a593Smuzhiyun */ 45*4882a593Smuzhiyun struct irq_bypass_producer { 46*4882a593Smuzhiyun struct list_head node; 47*4882a593Smuzhiyun void *token; 48*4882a593Smuzhiyun int irq; 49*4882a593Smuzhiyun int (*add_consumer)(struct irq_bypass_producer *, 50*4882a593Smuzhiyun struct irq_bypass_consumer *); 51*4882a593Smuzhiyun void (*del_consumer)(struct irq_bypass_producer *, 52*4882a593Smuzhiyun struct irq_bypass_consumer *); 53*4882a593Smuzhiyun void (*stop)(struct irq_bypass_producer *); 54*4882a593Smuzhiyun void (*start)(struct irq_bypass_producer *); 55*4882a593Smuzhiyun }; 56*4882a593Smuzhiyun 57*4882a593Smuzhiyun /** 58*4882a593Smuzhiyun * struct irq_bypass_consumer - IRQ bypass consumer definition 59*4882a593Smuzhiyun * @node: IRQ bypass manager private list management 60*4882a593Smuzhiyun * @token: opaque token to match between producer and consumer (non-NULL) 61*4882a593Smuzhiyun * @add_producer: Connect the IRQ consumer to an IRQ producer 62*4882a593Smuzhiyun * @del_producer: Disconnect the IRQ consumer from an IRQ producer 63*4882a593Smuzhiyun * @stop: Perform any quiesce operations necessary prior to add/del (optional) 64*4882a593Smuzhiyun * @start: Perform any startup operations necessary after add/del (optional) 65*4882a593Smuzhiyun * 66*4882a593Smuzhiyun * The IRQ bypass consumer structure represents an interrupt sink for 67*4882a593Smuzhiyun * participation in possible host bypass, for instance a hypervisor may 68*4882a593Smuzhiyun * support offloads to allow bypassing the host entirely or offload 69*4882a593Smuzhiyun * portions of the interrupt handling to the VM. 70*4882a593Smuzhiyun */ 71*4882a593Smuzhiyun struct irq_bypass_consumer { 72*4882a593Smuzhiyun struct list_head node; 73*4882a593Smuzhiyun void *token; 74*4882a593Smuzhiyun int (*add_producer)(struct irq_bypass_consumer *, 75*4882a593Smuzhiyun struct irq_bypass_producer *); 76*4882a593Smuzhiyun void (*del_producer)(struct irq_bypass_consumer *, 77*4882a593Smuzhiyun struct irq_bypass_producer *); 78*4882a593Smuzhiyun void (*stop)(struct irq_bypass_consumer *); 79*4882a593Smuzhiyun void (*start)(struct irq_bypass_consumer *); 80*4882a593Smuzhiyun }; 81*4882a593Smuzhiyun 82*4882a593Smuzhiyun int irq_bypass_register_producer(struct irq_bypass_producer *); 83*4882a593Smuzhiyun void irq_bypass_unregister_producer(struct irq_bypass_producer *); 84*4882a593Smuzhiyun int irq_bypass_register_consumer(struct irq_bypass_consumer *); 85*4882a593Smuzhiyun void irq_bypass_unregister_consumer(struct irq_bypass_consumer *); 86*4882a593Smuzhiyun 87*4882a593Smuzhiyun #endif /* IRQBYPASS_H */ 88