xref: /linux/include/xen/events.h (revision 55ec81f7517fad09135f65552cea0a3ee84fff30)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _XEN_EVENTS_H
3 #define _XEN_EVENTS_H
4 
5 #include <linux/interrupt.h>
6 #include <linux/irq.h>
7 #ifdef CONFIG_PCI_MSI
8 #include <linux/msi.h>
9 #endif
10 
11 #include <xen/interface/event_channel.h>
12 #include <asm/xen/hypercall.h>
13 #include <asm/xen/events.h>
14 
15 struct xenbus_device;
16 
17 unsigned xen_evtchn_nr_channels(void);
18 
19 int bind_evtchn_to_irq(evtchn_port_t evtchn);
20 int bind_evtchn_to_irq_lateeoi(evtchn_port_t evtchn);
21 int bind_evtchn_to_irqhandler(evtchn_port_t evtchn,
22 			      irq_handler_t handler,
23 			      unsigned long irqflags, const char *devname,
24 			      void *dev_id);
25 int bind_evtchn_to_irqhandler_lateeoi(evtchn_port_t evtchn,
26 			      irq_handler_t handler,
27 			      unsigned long irqflags, const char *devname,
28 			      void *dev_id);
29 int bind_virq_to_irq(unsigned int virq, unsigned int cpu, bool percpu);
30 int bind_virq_to_irqhandler(unsigned int virq, unsigned int cpu,
31 			    irq_handler_t handler,
32 			    unsigned long irqflags, const char *devname,
33 			    void *dev_id);
34 int bind_ipi_to_irqhandler(enum ipi_vector ipi,
35 			   unsigned int cpu,
36 			   irq_handler_t handler,
37 			   unsigned long irqflags,
38 			   const char *devname,
39 			   void *dev_id);
40 int bind_interdomain_evtchn_to_irq_lateeoi(struct xenbus_device *dev,
41 					   evtchn_port_t remote_port);
42 int bind_interdomain_evtchn_to_irqhandler_lateeoi(struct xenbus_device *dev,
43 						  evtchn_port_t remote_port,
44 						  irq_handler_t handler,
45 						  unsigned long irqflags,
46 						  const char *devname,
47 						  void *dev_id);
48 
49 /*
50  * Common unbind function for all event sources. Takes IRQ to unbind from.
51  * Automatically closes the underlying event channel (even for bindings
52  * made with bind_evtchn_to_irqhandler()).
53  */
54 void unbind_from_irqhandler(unsigned int irq, void *dev_id);
55 
56 /*
57  * Send late EOI for an IRQ bound to an event channel via one of the *_lateeoi
58  * functions above.
59  */
60 void xen_irq_lateeoi(unsigned int irq, unsigned int eoi_flags);
61 /* Signal an event was spurious, i.e. there was no action resulting from it. */
62 #define XEN_EOI_FLAG_SPURIOUS	0x00000001
63 
64 #define XEN_IRQ_PRIORITY_MAX     EVTCHN_FIFO_PRIORITY_MAX
65 #define XEN_IRQ_PRIORITY_DEFAULT EVTCHN_FIFO_PRIORITY_DEFAULT
66 #define XEN_IRQ_PRIORITY_MIN     EVTCHN_FIFO_PRIORITY_MIN
67 int xen_set_irq_priority(unsigned irq, unsigned priority);
68 
69 /*
70  * Allow extra references to event channels exposed to userspace by evtchn
71  */
72 int evtchn_make_refcounted(evtchn_port_t evtchn, bool is_static);
73 int evtchn_get(evtchn_port_t evtchn);
74 void evtchn_put(evtchn_port_t evtchn);
75 
76 void xen_send_IPI_one(unsigned int cpu, enum ipi_vector vector);
77 void rebind_evtchn_irq(evtchn_port_t evtchn, int irq);
78 
79 static inline void notify_remote_via_evtchn(evtchn_port_t port)
80 {
81 	struct evtchn_send send = { .port = port };
82 	(void)HYPERVISOR_event_channel_op(EVTCHNOP_send, &send);
83 }
84 
85 void notify_remote_via_irq(int irq);
86 
87 void xen_irq_resume(void);
88 
89 /* Clear an irq's pending state, in preparation for polling on it */
90 void xen_clear_irq_pending(int irq);
91 void xen_set_irq_pending(int irq);
92 bool xen_test_irq_pending(int irq);
93 
94 /* Poll waiting for an irq to become pending.  In the usual case, the
95    irq will be disabled so it won't deliver an interrupt. */
96 void xen_poll_irq(int irq);
97 
98 /* Poll waiting for an irq to become pending with a timeout.  In the usual case,
99  * the irq will be disabled so it won't deliver an interrupt. */
100 void xen_poll_irq_timeout(int irq, u64 timeout);
101 
102 /* Determine the IRQ which is bound to an event channel */
103 unsigned int irq_from_evtchn(evtchn_port_t evtchn);
104 int irq_from_virq(unsigned int cpu, unsigned int virq);
105 evtchn_port_t evtchn_from_irq(unsigned irq);
106 
107 int xen_set_callback_via(uint64_t via);
108 void xen_evtchn_do_upcall(struct pt_regs *regs);
109 int xen_hvm_evtchn_do_upcall(void);
110 
111 /* Bind a pirq for a physical interrupt to an irq. */
112 int xen_bind_pirq_gsi_to_irq(unsigned gsi,
113 			     unsigned pirq, int shareable, char *name);
114 
115 #ifdef CONFIG_PCI_MSI
116 /* Allocate a pirq for a MSI style physical interrupt. */
117 int xen_allocate_pirq_msi(struct pci_dev *dev, struct msi_desc *msidesc);
118 /* Bind an PSI pirq to an irq. */
119 int xen_bind_pirq_msi_to_irq(struct pci_dev *dev, struct msi_desc *msidesc,
120 			     int pirq, int nvec, const char *name, domid_t domid);
121 #endif
122 
123 /* De-allocates the above mentioned physical interrupt. */
124 int xen_destroy_irq(int irq);
125 
126 /* Return irq from pirq */
127 int xen_irq_from_pirq(unsigned pirq);
128 
129 /* Return the pirq allocated to the irq. */
130 int xen_pirq_from_irq(unsigned irq);
131 
132 /* Return the irq allocated to the gsi */
133 int xen_irq_from_gsi(unsigned gsi);
134 
135 /* Determine whether to ignore this IRQ if it is passed to a guest. */
136 int xen_test_irq_shared(int irq);
137 
138 /* initialize Xen IRQ subsystem */
139 void xen_init_IRQ(void);
140 
141 irqreturn_t xen_debug_interrupt(int irq, void *dev_id);
142 
143 static inline void xen_evtchn_close(evtchn_port_t port)
144 {
145 	struct evtchn_close close;
146 
147 	close.port = port;
148 	if (HYPERVISOR_event_channel_op(EVTCHNOP_close, &close) != 0)
149 		BUG();
150 }
151 
152 #endif	/* _XEN_EVENTS_H */
153