xref: /openbmc/linux/include/xen/events.h (revision 4892c9b4)
1e46cdb66SJeremy Fitzhardinge #ifndef _XEN_EVENTS_H
2e46cdb66SJeremy Fitzhardinge #define _XEN_EVENTS_H
3e46cdb66SJeremy Fitzhardinge 
4f87e4cacSJeremy Fitzhardinge #include <linux/interrupt.h>
54892c9b4SRoger Pau Monne #ifdef CONFIG_PCI_MSI
64892c9b4SRoger Pau Monne #include <linux/msi.h>
74892c9b4SRoger Pau Monne #endif
8f87e4cacSJeremy Fitzhardinge 
9f87e4cacSJeremy Fitzhardinge #include <xen/interface/event_channel.h>
10f87e4cacSJeremy Fitzhardinge #include <asm/xen/hypercall.h>
11e849c3e9SIsaku Yamahata #include <asm/xen/events.h>
12e46cdb66SJeremy Fitzhardinge 
130dc0064aSDavid Vrabel unsigned xen_evtchn_nr_channels(void);
140dc0064aSDavid Vrabel 
15b536b4b9SJeremy Fitzhardinge int bind_evtchn_to_irq(unsigned int evtchn);
16e46cdb66SJeremy Fitzhardinge int bind_evtchn_to_irqhandler(unsigned int evtchn,
17f87e4cacSJeremy Fitzhardinge 			      irq_handler_t handler,
18e46cdb66SJeremy Fitzhardinge 			      unsigned long irqflags, const char *devname,
19e46cdb66SJeremy Fitzhardinge 			      void *dev_id);
204fe7d5a7SJeremy Fitzhardinge int bind_virq_to_irq(unsigned int virq, unsigned int cpu);
21e46cdb66SJeremy Fitzhardinge int bind_virq_to_irqhandler(unsigned int virq, unsigned int cpu,
22f87e4cacSJeremy Fitzhardinge 			    irq_handler_t handler,
23f87e4cacSJeremy Fitzhardinge 			    unsigned long irqflags, const char *devname,
24f87e4cacSJeremy Fitzhardinge 			    void *dev_id);
25f87e4cacSJeremy Fitzhardinge int bind_ipi_to_irqhandler(enum ipi_vector ipi,
26f87e4cacSJeremy Fitzhardinge 			   unsigned int cpu,
27f87e4cacSJeremy Fitzhardinge 			   irq_handler_t handler,
28f87e4cacSJeremy Fitzhardinge 			   unsigned long irqflags,
29f87e4cacSJeremy Fitzhardinge 			   const char *devname,
30f87e4cacSJeremy Fitzhardinge 			   void *dev_id);
312e820f58SIan Campbell int bind_interdomain_evtchn_to_irqhandler(unsigned int remote_domain,
322e820f58SIan Campbell 					  unsigned int remote_port,
332e820f58SIan Campbell 					  irq_handler_t handler,
342e820f58SIan Campbell 					  unsigned long irqflags,
352e820f58SIan Campbell 					  const char *devname,
362e820f58SIan Campbell 					  void *dev_id);
37e46cdb66SJeremy Fitzhardinge 
38e46cdb66SJeremy Fitzhardinge /*
39e46cdb66SJeremy Fitzhardinge  * Common unbind function for all event sources. Takes IRQ to unbind from.
40e46cdb66SJeremy Fitzhardinge  * Automatically closes the underlying event channel (even for bindings
41e46cdb66SJeremy Fitzhardinge  * made with bind_evtchn_to_irqhandler()).
42e46cdb66SJeremy Fitzhardinge  */
43e46cdb66SJeremy Fitzhardinge void unbind_from_irqhandler(unsigned int irq, void *dev_id);
44e46cdb66SJeremy Fitzhardinge 
456ccecb0fSDavid Vrabel #define XEN_IRQ_PRIORITY_MAX     EVTCHN_FIFO_PRIORITY_MAX
466ccecb0fSDavid Vrabel #define XEN_IRQ_PRIORITY_DEFAULT EVTCHN_FIFO_PRIORITY_DEFAULT
476ccecb0fSDavid Vrabel #define XEN_IRQ_PRIORITY_MIN     EVTCHN_FIFO_PRIORITY_MIN
486ccecb0fSDavid Vrabel int xen_set_irq_priority(unsigned irq, unsigned priority);
496ccecb0fSDavid Vrabel 
50420eb554SDaniel De Graaf /*
51420eb554SDaniel De Graaf  * Allow extra references to event channels exposed to userspace by evtchn
52420eb554SDaniel De Graaf  */
53420eb554SDaniel De Graaf int evtchn_make_refcounted(unsigned int evtchn);
54420eb554SDaniel De Graaf int evtchn_get(unsigned int evtchn);
55420eb554SDaniel De Graaf void evtchn_put(unsigned int evtchn);
56420eb554SDaniel De Graaf 
57f87e4cacSJeremy Fitzhardinge void xen_send_IPI_one(unsigned int cpu, enum ipi_vector vector);
58eb1e305fSJeremy Fitzhardinge void rebind_evtchn_irq(int evtchn, int irq);
59f87e4cacSJeremy Fitzhardinge 
60e46cdb66SJeremy Fitzhardinge static inline void notify_remote_via_evtchn(int port)
61e46cdb66SJeremy Fitzhardinge {
62e46cdb66SJeremy Fitzhardinge 	struct evtchn_send send = { .port = port };
63e46cdb66SJeremy Fitzhardinge 	(void)HYPERVISOR_event_channel_op(EVTCHNOP_send, &send);
64e46cdb66SJeremy Fitzhardinge }
65e46cdb66SJeremy Fitzhardinge 
6676465b2dSIan Campbell void notify_remote_via_irq(int irq);
670e91398fSJeremy Fitzhardinge 
6876465b2dSIan Campbell void xen_irq_resume(void);
690e91398fSJeremy Fitzhardinge 
702d9e1e2fSJeremy Fitzhardinge /* Clear an irq's pending state, in preparation for polling on it */
712d9e1e2fSJeremy Fitzhardinge void xen_clear_irq_pending(int irq);
72168d2f46SJeremy Fitzhardinge void xen_set_irq_pending(int irq);
73168d2f46SJeremy Fitzhardinge bool xen_test_irq_pending(int irq);
742d9e1e2fSJeremy Fitzhardinge 
752d9e1e2fSJeremy Fitzhardinge /* Poll waiting for an irq to become pending.  In the usual case, the
762d9e1e2fSJeremy Fitzhardinge    irq will be disabled so it won't deliver an interrupt. */
772d9e1e2fSJeremy Fitzhardinge void xen_poll_irq(int irq);
782d9e1e2fSJeremy Fitzhardinge 
79d9a8814fSKonrad Rzeszutek Wilk /* Poll waiting for an irq to become pending with a timeout.  In the usual case,
80d9a8814fSKonrad Rzeszutek Wilk  * the irq will be disabled so it won't deliver an interrupt. */
81d9a8814fSKonrad Rzeszutek Wilk void xen_poll_irq_timeout(int irq, u64 timeout);
82d9a8814fSKonrad Rzeszutek Wilk 
83d4c04536SIan Campbell /* Determine the IRQ which is bound to an event channel */
84d4c04536SIan Campbell unsigned irq_from_evtchn(unsigned int evtchn);
859a489f45SDavid Vrabel int irq_from_virq(unsigned int cpu, unsigned int virq);
869a489f45SDavid Vrabel unsigned int evtchn_from_irq(unsigned irq);
87d4c04536SIan Campbell 
8838e20b07SSheng Yang /* Xen HVM evtchn vector callback */
8976465b2dSIan Campbell void xen_hvm_callback_vector(void);
90cf910e83SSeiji Aguchi #ifdef CONFIG_TRACING
91cf910e83SSeiji Aguchi #define trace_xen_hvm_callback_vector xen_hvm_callback_vector
92cf910e83SSeiji Aguchi #endif
9338e20b07SSheng Yang extern int xen_have_vector_callback;
9438e20b07SSheng Yang int xen_set_callback_via(uint64_t via);
9538e20b07SSheng Yang void xen_evtchn_do_upcall(struct pt_regs *regs);
9638e20b07SSheng Yang void xen_hvm_evtchn_do_upcall(void);
9738e20b07SSheng Yang 
98f4d0635bSIan Campbell /* Bind a pirq for a physical interrupt to an irq. */
99f4d0635bSIan Campbell int xen_bind_pirq_gsi_to_irq(unsigned gsi,
100f4d0635bSIan Campbell 			     unsigned pirq, int shareable, char *name);
101f731e3efSQing He 
102f731e3efSQing He #ifdef CONFIG_PCI_MSI
103f4d0635bSIan Campbell /* Allocate a pirq for a MSI style physical interrupt. */
104bf480d95SIan Campbell int xen_allocate_pirq_msi(struct pci_dev *dev, struct msi_desc *msidesc);
105f4d0635bSIan Campbell /* Bind an PSI pirq to an irq. */
106bf480d95SIan Campbell int xen_bind_pirq_msi_to_irq(struct pci_dev *dev, struct msi_desc *msidesc,
1074892c9b4SRoger Pau Monne 			     int pirq, int nvec, const char *name, domid_t domid);
108f731e3efSQing He #endif
109d46a78b0SJeremy Fitzhardinge 
110b5401a96SAlex Nixon /* De-allocates the above mentioned physical interrupt. */
111b5401a96SAlex Nixon int xen_destroy_irq(int irq);
112b5401a96SAlex Nixon 
113af42b8d1SStefano Stabellini /* Return irq from pirq */
114af42b8d1SStefano Stabellini int xen_irq_from_pirq(unsigned pirq);
115af42b8d1SStefano Stabellini 
116e6197accSKonrad Rzeszutek Wilk /* Return the pirq allocated to the irq. */
117e6197accSKonrad Rzeszutek Wilk int xen_pirq_from_irq(unsigned irq);
118e6197accSKonrad Rzeszutek Wilk 
11968c2c39aSStefano Stabellini /* Return the irq allocated to the gsi */
12068c2c39aSStefano Stabellini int xen_irq_from_gsi(unsigned gsi);
12168c2c39aSStefano Stabellini 
122c7c2c3a2SKonrad Rzeszutek Wilk /* Determine whether to ignore this IRQ if it is passed to a guest. */
123c7c2c3a2SKonrad Rzeszutek Wilk int xen_test_irq_shared(int irq);
124c7c2c3a2SKonrad Rzeszutek Wilk 
1250ec53ecfSStefano Stabellini /* initialize Xen IRQ subsystem */
1260ec53ecfSStefano Stabellini void xen_init_IRQ(void);
127e46cdb66SJeremy Fitzhardinge #endif	/* _XEN_EVENTS_H */
128