blob: 8ec418e30c7fb0c65d7c63445b9622244af8bd5d [file] [log] [blame]
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00001/* SPDX-License-Identifier: GPL-2.0 */
2#ifndef _XEN_EVENTS_H
3#define _XEN_EVENTS_H
4
5#include <linux/interrupt.h>
David Brazdil0f672f62019-12-10 10:32:29 +00006#include <linux/irq.h>
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00007#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
15unsigned xen_evtchn_nr_channels(void);
16
Olivier Deprez0e641232021-09-23 10:07:05 +020017int bind_evtchn_to_irq(evtchn_port_t evtchn);
18int bind_evtchn_to_irq_lateeoi(evtchn_port_t evtchn);
19int bind_evtchn_to_irqhandler(evtchn_port_t evtchn,
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000020 irq_handler_t handler,
21 unsigned long irqflags, const char *devname,
22 void *dev_id);
Olivier Deprez0e641232021-09-23 10:07:05 +020023int bind_evtchn_to_irqhandler_lateeoi(evtchn_port_t evtchn,
Olivier Deprez157378f2022-04-04 15:47:50 +020024 irq_handler_t handler,
25 unsigned long irqflags, const char *devname,
26 void *dev_id);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000027int bind_virq_to_irq(unsigned int virq, unsigned int cpu, bool percpu);
28int 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);
32int 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);
Olivier Deprez0e641232021-09-23 10:07:05 +020038int bind_interdomain_evtchn_to_irq_lateeoi(unsigned int remote_domain,
39 evtchn_port_t remote_port);
Olivier Deprez0e641232021-09-23 10:07:05 +020040int 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);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000046
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 */
52void unbind_from_irqhandler(unsigned int irq, void *dev_id);
53
Olivier Deprez0e641232021-09-23 10:07:05 +020054/*
55 * Send late EOI for an IRQ bound to an event channel via one of the *_lateeoi
56 * functions above.
57 */
58void 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
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000062#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
65int xen_set_irq_priority(unsigned irq, unsigned priority);
66
67/*
68 * Allow extra references to event channels exposed to userspace by evtchn
69 */
Olivier Deprez157378f2022-04-04 15:47:50 +020070int evtchn_make_refcounted(evtchn_port_t evtchn);
71int evtchn_get(evtchn_port_t evtchn);
72void evtchn_put(evtchn_port_t evtchn);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000073
74void xen_send_IPI_one(unsigned int cpu, enum ipi_vector vector);
Olivier Deprez157378f2022-04-04 15:47:50 +020075void rebind_evtchn_irq(evtchn_port_t evtchn, int irq);
David Brazdil0f672f62019-12-10 10:32:29 +000076int xen_set_affinity_evtchn(struct irq_desc *desc, unsigned int tcpu);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000077
Olivier Deprez157378f2022-04-04 15:47:50 +020078static inline void notify_remote_via_evtchn(evtchn_port_t port)
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000079{
80 struct evtchn_send send = { .port = port };
81 (void)HYPERVISOR_event_channel_op(EVTCHNOP_send, &send);
82}
83
84void notify_remote_via_irq(int irq);
85
86void xen_irq_resume(void);
87
88/* Clear an irq's pending state, in preparation for polling on it */
89void xen_clear_irq_pending(int irq);
90void xen_set_irq_pending(int irq);
91bool 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. */
95void 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. */
99void xen_poll_irq_timeout(int irq, u64 timeout);
100
101/* Determine the IRQ which is bound to an event channel */
Olivier Deprez157378f2022-04-04 15:47:50 +0200102unsigned int irq_from_evtchn(evtchn_port_t evtchn);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000103int irq_from_virq(unsigned int cpu, unsigned int virq);
Olivier Deprez157378f2022-04-04 15:47:50 +0200104evtchn_port_t evtchn_from_irq(unsigned irq);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000105
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000106int xen_set_callback_via(uint64_t via);
107void xen_evtchn_do_upcall(struct pt_regs *regs);
108void xen_hvm_evtchn_do_upcall(void);
109
110/* Bind a pirq for a physical interrupt to an irq. */
111int 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. */
116int xen_allocate_pirq_msi(struct pci_dev *dev, struct msi_desc *msidesc);
117/* Bind an PSI pirq to an irq. */
118int 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. */
123int xen_destroy_irq(int irq);
124
125/* Return irq from pirq */
126int xen_irq_from_pirq(unsigned pirq);
127
128/* Return the pirq allocated to the irq. */
129int xen_pirq_from_irq(unsigned irq);
130
131/* Return the irq allocated to the gsi */
132int xen_irq_from_gsi(unsigned gsi);
133
134/* Determine whether to ignore this IRQ if it is passed to a guest. */
135int xen_test_irq_shared(int irq);
136
137/* initialize Xen IRQ subsystem */
138void xen_init_IRQ(void);
139#endif /* _XEN_EVENTS_H */