1e46cdb66SJeremy Fitzhardinge #ifndef _XEN_EVENTS_H 2e46cdb66SJeremy Fitzhardinge #define _XEN_EVENTS_H 3e46cdb66SJeremy Fitzhardinge 4f87e4cacSJeremy Fitzhardinge #include <linux/interrupt.h> 5f87e4cacSJeremy Fitzhardinge 6f87e4cacSJeremy Fitzhardinge #include <xen/interface/event_channel.h> 7f87e4cacSJeremy Fitzhardinge #include <asm/xen/hypercall.h> 8e849c3e9SIsaku Yamahata #include <asm/xen/events.h> 9e46cdb66SJeremy Fitzhardinge 100dc0064aSDavid Vrabel unsigned xen_evtchn_nr_channels(void); 110dc0064aSDavid Vrabel 12b536b4b9SJeremy Fitzhardinge int bind_evtchn_to_irq(unsigned int evtchn); 13e46cdb66SJeremy Fitzhardinge int bind_evtchn_to_irqhandler(unsigned int evtchn, 14f87e4cacSJeremy Fitzhardinge irq_handler_t handler, 15e46cdb66SJeremy Fitzhardinge unsigned long irqflags, const char *devname, 16e46cdb66SJeremy Fitzhardinge void *dev_id); 174fe7d5a7SJeremy Fitzhardinge int bind_virq_to_irq(unsigned int virq, unsigned int cpu); 18e46cdb66SJeremy Fitzhardinge int bind_virq_to_irqhandler(unsigned int virq, unsigned int cpu, 19f87e4cacSJeremy Fitzhardinge irq_handler_t handler, 20f87e4cacSJeremy Fitzhardinge unsigned long irqflags, const char *devname, 21f87e4cacSJeremy Fitzhardinge void *dev_id); 22f87e4cacSJeremy Fitzhardinge int bind_ipi_to_irqhandler(enum ipi_vector ipi, 23f87e4cacSJeremy Fitzhardinge unsigned int cpu, 24f87e4cacSJeremy Fitzhardinge irq_handler_t handler, 25f87e4cacSJeremy Fitzhardinge unsigned long irqflags, 26f87e4cacSJeremy Fitzhardinge const char *devname, 27f87e4cacSJeremy Fitzhardinge void *dev_id); 282e820f58SIan Campbell int bind_interdomain_evtchn_to_irqhandler(unsigned int remote_domain, 292e820f58SIan Campbell unsigned int remote_port, 302e820f58SIan Campbell irq_handler_t handler, 312e820f58SIan Campbell unsigned long irqflags, 322e820f58SIan Campbell const char *devname, 332e820f58SIan Campbell void *dev_id); 34e46cdb66SJeremy Fitzhardinge 35e46cdb66SJeremy Fitzhardinge /* 36e46cdb66SJeremy Fitzhardinge * Common unbind function for all event sources. Takes IRQ to unbind from. 37e46cdb66SJeremy Fitzhardinge * Automatically closes the underlying event channel (even for bindings 38e46cdb66SJeremy Fitzhardinge * made with bind_evtchn_to_irqhandler()). 39e46cdb66SJeremy Fitzhardinge */ 40e46cdb66SJeremy Fitzhardinge void unbind_from_irqhandler(unsigned int irq, void *dev_id); 41e46cdb66SJeremy Fitzhardinge 426ccecb0fSDavid Vrabel #define XEN_IRQ_PRIORITY_MAX EVTCHN_FIFO_PRIORITY_MAX 436ccecb0fSDavid Vrabel #define XEN_IRQ_PRIORITY_DEFAULT EVTCHN_FIFO_PRIORITY_DEFAULT 446ccecb0fSDavid Vrabel #define XEN_IRQ_PRIORITY_MIN EVTCHN_FIFO_PRIORITY_MIN 456ccecb0fSDavid Vrabel int xen_set_irq_priority(unsigned irq, unsigned priority); 466ccecb0fSDavid Vrabel 47420eb554SDaniel De Graaf /* 48420eb554SDaniel De Graaf * Allow extra references to event channels exposed to userspace by evtchn 49420eb554SDaniel De Graaf */ 50420eb554SDaniel De Graaf int evtchn_make_refcounted(unsigned int evtchn); 51420eb554SDaniel De Graaf int evtchn_get(unsigned int evtchn); 52420eb554SDaniel De Graaf void evtchn_put(unsigned int evtchn); 53420eb554SDaniel De Graaf 54f87e4cacSJeremy Fitzhardinge void xen_send_IPI_one(unsigned int cpu, enum ipi_vector vector); 55642e0c88SIsaku Yamahata int resend_irq_on_evtchn(unsigned int irq); 56eb1e305fSJeremy Fitzhardinge void rebind_evtchn_irq(int evtchn, int irq); 57f87e4cacSJeremy Fitzhardinge 58e46cdb66SJeremy Fitzhardinge static inline void notify_remote_via_evtchn(int port) 59e46cdb66SJeremy Fitzhardinge { 60e46cdb66SJeremy Fitzhardinge struct evtchn_send send = { .port = port }; 61e46cdb66SJeremy Fitzhardinge (void)HYPERVISOR_event_channel_op(EVTCHNOP_send, &send); 62e46cdb66SJeremy Fitzhardinge } 63e46cdb66SJeremy Fitzhardinge 6476465b2dSIan Campbell void notify_remote_via_irq(int irq); 650e91398fSJeremy Fitzhardinge 6676465b2dSIan Campbell void xen_irq_resume(void); 670e91398fSJeremy Fitzhardinge 682d9e1e2fSJeremy Fitzhardinge /* Clear an irq's pending state, in preparation for polling on it */ 692d9e1e2fSJeremy Fitzhardinge void xen_clear_irq_pending(int irq); 70168d2f46SJeremy Fitzhardinge void xen_set_irq_pending(int irq); 71168d2f46SJeremy Fitzhardinge bool xen_test_irq_pending(int irq); 722d9e1e2fSJeremy Fitzhardinge 732d9e1e2fSJeremy Fitzhardinge /* Poll waiting for an irq to become pending. In the usual case, the 742d9e1e2fSJeremy Fitzhardinge irq will be disabled so it won't deliver an interrupt. */ 752d9e1e2fSJeremy Fitzhardinge void xen_poll_irq(int irq); 762d9e1e2fSJeremy Fitzhardinge 77d9a8814fSKonrad Rzeszutek Wilk /* Poll waiting for an irq to become pending with a timeout. In the usual case, 78d9a8814fSKonrad Rzeszutek Wilk * the irq will be disabled so it won't deliver an interrupt. */ 79d9a8814fSKonrad Rzeszutek Wilk void xen_poll_irq_timeout(int irq, u64 timeout); 80d9a8814fSKonrad Rzeszutek Wilk 81d4c04536SIan Campbell /* Determine the IRQ which is bound to an event channel */ 82d4c04536SIan Campbell unsigned irq_from_evtchn(unsigned int evtchn); 839a489f45SDavid Vrabel int irq_from_virq(unsigned int cpu, unsigned int virq); 849a489f45SDavid Vrabel unsigned int evtchn_from_irq(unsigned irq); 85d4c04536SIan Campbell 8638e20b07SSheng Yang /* Xen HVM evtchn vector callback */ 8776465b2dSIan Campbell void xen_hvm_callback_vector(void); 88cf910e83SSeiji Aguchi #ifdef CONFIG_TRACING 89cf910e83SSeiji Aguchi #define trace_xen_hvm_callback_vector xen_hvm_callback_vector 90cf910e83SSeiji Aguchi #endif 9138e20b07SSheng Yang extern int xen_have_vector_callback; 9238e20b07SSheng Yang int xen_set_callback_via(uint64_t via); 9338e20b07SSheng Yang void xen_evtchn_do_upcall(struct pt_regs *regs); 9438e20b07SSheng Yang void xen_hvm_evtchn_do_upcall(void); 9538e20b07SSheng Yang 96f4d0635bSIan Campbell /* Bind a pirq for a physical interrupt to an irq. */ 97f4d0635bSIan Campbell int xen_bind_pirq_gsi_to_irq(unsigned gsi, 98f4d0635bSIan Campbell unsigned pirq, int shareable, char *name); 99f731e3efSQing He 100f731e3efSQing He #ifdef CONFIG_PCI_MSI 101f4d0635bSIan Campbell /* Allocate a pirq for a MSI style physical interrupt. */ 102bf480d95SIan Campbell int xen_allocate_pirq_msi(struct pci_dev *dev, struct msi_desc *msidesc); 103f4d0635bSIan Campbell /* Bind an PSI pirq to an irq. */ 104bf480d95SIan Campbell int xen_bind_pirq_msi_to_irq(struct pci_dev *dev, struct msi_desc *msidesc, 105dec02deaSJan Beulich int pirq, const char *name, domid_t domid); 106f731e3efSQing He #endif 107d46a78b0SJeremy Fitzhardinge 108b5401a96SAlex Nixon /* De-allocates the above mentioned physical interrupt. */ 109b5401a96SAlex Nixon int xen_destroy_irq(int irq); 110b5401a96SAlex Nixon 111af42b8d1SStefano Stabellini /* Return irq from pirq */ 112af42b8d1SStefano Stabellini int xen_irq_from_pirq(unsigned pirq); 113af42b8d1SStefano Stabellini 114e6197accSKonrad Rzeszutek Wilk /* Return the pirq allocated to the irq. */ 115e6197accSKonrad Rzeszutek Wilk int xen_pirq_from_irq(unsigned irq); 116e6197accSKonrad Rzeszutek Wilk 11768c2c39aSStefano Stabellini /* Return the irq allocated to the gsi */ 11868c2c39aSStefano Stabellini int xen_irq_from_gsi(unsigned gsi); 11968c2c39aSStefano Stabellini 120c7c2c3a2SKonrad Rzeszutek Wilk /* Determine whether to ignore this IRQ if it is passed to a guest. */ 121c7c2c3a2SKonrad Rzeszutek Wilk int xen_test_irq_shared(int irq); 122c7c2c3a2SKonrad Rzeszutek Wilk 1230ec53ecfSStefano Stabellini /* initialize Xen IRQ subsystem */ 1240ec53ecfSStefano Stabellini void xen_init_IRQ(void); 125e46cdb66SJeremy Fitzhardinge #endif /* _XEN_EVENTS_H */ 126