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