xref: /OK3568_Linux_fs/kernel/include/linux/kvm_irqfd.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /* SPDX-License-Identifier: GPL-2.0-only */
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun  *
4*4882a593Smuzhiyun  * irqfd: Allows an fd to be used to inject an interrupt to the guest
5*4882a593Smuzhiyun  * Credit goes to Avi Kivity for the original idea.
6*4882a593Smuzhiyun  */
7*4882a593Smuzhiyun 
8*4882a593Smuzhiyun #ifndef __LINUX_KVM_IRQFD_H
9*4882a593Smuzhiyun #define __LINUX_KVM_IRQFD_H
10*4882a593Smuzhiyun 
11*4882a593Smuzhiyun #include <linux/kvm_host.h>
12*4882a593Smuzhiyun #include <linux/poll.h>
13*4882a593Smuzhiyun 
14*4882a593Smuzhiyun /*
15*4882a593Smuzhiyun  * Resampling irqfds are a special variety of irqfds used to emulate
16*4882a593Smuzhiyun  * level triggered interrupts.  The interrupt is asserted on eventfd
17*4882a593Smuzhiyun  * trigger.  On acknowledgment through the irq ack notifier, the
18*4882a593Smuzhiyun  * interrupt is de-asserted and userspace is notified through the
19*4882a593Smuzhiyun  * resamplefd.  All resamplers on the same gsi are de-asserted
20*4882a593Smuzhiyun  * together, so we don't need to track the state of each individual
21*4882a593Smuzhiyun  * user.  We can also therefore share the same irq source ID.
22*4882a593Smuzhiyun  */
23*4882a593Smuzhiyun struct kvm_kernel_irqfd_resampler {
24*4882a593Smuzhiyun 	struct kvm *kvm;
25*4882a593Smuzhiyun 	/*
26*4882a593Smuzhiyun 	 * List of resampling struct _irqfd objects sharing this gsi.
27*4882a593Smuzhiyun 	 * RCU list modified under kvm->irqfds.resampler_lock
28*4882a593Smuzhiyun 	 */
29*4882a593Smuzhiyun 	struct list_head list;
30*4882a593Smuzhiyun 	struct kvm_irq_ack_notifier notifier;
31*4882a593Smuzhiyun 	/*
32*4882a593Smuzhiyun 	 * Entry in list of kvm->irqfd.resampler_list.  Use for sharing
33*4882a593Smuzhiyun 	 * resamplers among irqfds on the same gsi.
34*4882a593Smuzhiyun 	 * Accessed and modified under kvm->irqfds.resampler_lock
35*4882a593Smuzhiyun 	 */
36*4882a593Smuzhiyun 	struct list_head link;
37*4882a593Smuzhiyun };
38*4882a593Smuzhiyun 
39*4882a593Smuzhiyun struct kvm_kernel_irqfd {
40*4882a593Smuzhiyun 	/* Used for MSI fast-path */
41*4882a593Smuzhiyun 	struct kvm *kvm;
42*4882a593Smuzhiyun 	wait_queue_entry_t wait;
43*4882a593Smuzhiyun 	/* Update side is protected by irqfds.lock */
44*4882a593Smuzhiyun 	struct kvm_kernel_irq_routing_entry irq_entry;
45*4882a593Smuzhiyun 	seqcount_spinlock_t irq_entry_sc;
46*4882a593Smuzhiyun 	/* Used for level IRQ fast-path */
47*4882a593Smuzhiyun 	int gsi;
48*4882a593Smuzhiyun 	struct work_struct inject;
49*4882a593Smuzhiyun 	/* The resampler used by this irqfd (resampler-only) */
50*4882a593Smuzhiyun 	struct kvm_kernel_irqfd_resampler *resampler;
51*4882a593Smuzhiyun 	/* Eventfd notified on resample (resampler-only) */
52*4882a593Smuzhiyun 	struct eventfd_ctx *resamplefd;
53*4882a593Smuzhiyun 	/* Entry in list of irqfds for a resampler (resampler-only) */
54*4882a593Smuzhiyun 	struct list_head resampler_link;
55*4882a593Smuzhiyun 	/* Used for setup/shutdown */
56*4882a593Smuzhiyun 	struct eventfd_ctx *eventfd;
57*4882a593Smuzhiyun 	struct list_head list;
58*4882a593Smuzhiyun 	poll_table pt;
59*4882a593Smuzhiyun 	struct work_struct shutdown;
60*4882a593Smuzhiyun 	struct irq_bypass_consumer consumer;
61*4882a593Smuzhiyun 	struct irq_bypass_producer *producer;
62*4882a593Smuzhiyun };
63*4882a593Smuzhiyun 
64*4882a593Smuzhiyun #endif /* __LINUX_KVM_IRQFD_H */
65