xen: map MSIs into pirqs
authorStefano Stabellini <stefano.stabellini@eu.citrix.com>
Thu, 1 Jul 2010 16:10:39 +0000 (17:10 +0100)
committerStefano Stabellini <stefano.stabellini@eu.citrix.com>
Fri, 22 Oct 2010 20:25:43 +0000 (21:25 +0100)
Map MSIs into pirqs, writing 0 in the MSI vector data field and the pirq
number in the MSI destination id field.

Signed-off-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
Reviewed-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
arch/x86/pci/xen.c
drivers/xen/events.c
include/xen/events.h

index d5284c491aef016c3a9dfbb29b48c4c4e6ed3f46..b5bd6420851e48ce3ae94c818bee466ea2f818ab 100644 (file)
@@ -64,10 +64,62 @@ static int acpi_register_gsi_xen_hvm(struct device *dev, u32 gsi,
 
 #if defined(CONFIG_PCI_MSI)
 #include <linux/msi.h>
+#include <asm/msidef.h>
 
 struct xen_pci_frontend_ops *xen_pci_frontend;
 EXPORT_SYMBOL_GPL(xen_pci_frontend);
 
+static void xen_msi_compose_msg(struct pci_dev *pdev, unsigned int pirq,
+               struct msi_msg *msg)
+{
+       /* We set vector == 0 to tell the hypervisor we don't care about it,
+        * but we want a pirq setup instead.
+        * We use the dest_id field to pass the pirq that we want. */
+       msg->address_hi = MSI_ADDR_BASE_HI | MSI_ADDR_EXT_DEST_ID(pirq);
+       msg->address_lo =
+               MSI_ADDR_BASE_LO |
+               MSI_ADDR_DEST_MODE_PHYSICAL |
+               MSI_ADDR_REDIRECTION_CPU |
+               MSI_ADDR_DEST_ID(pirq);
+
+       msg->data =
+               MSI_DATA_TRIGGER_EDGE |
+               MSI_DATA_LEVEL_ASSERT |
+               /* delivery mode reserved */
+               (3 << 8) |
+               MSI_DATA_VECTOR(0);
+}
+
+static int xen_hvm_setup_msi_irqs(struct pci_dev *dev, int nvec, int type)
+{
+       int irq, pirq, ret = 0;
+       struct msi_desc *msidesc;
+       struct msi_msg msg;
+
+       list_for_each_entry(msidesc, &dev->msi_list, list) {
+               xen_allocate_pirq_msi((type == PCI_CAP_ID_MSIX) ?
+                               "msi-x" : "msi", &irq, &pirq);
+               if (irq < 0 || pirq < 0)
+                       goto error;
+               printk(KERN_DEBUG "xen: msi --> irq=%d, pirq=%d\n", irq, pirq);
+               xen_msi_compose_msg(dev, pirq, &msg);
+               ret = set_irq_msi(irq, msidesc);
+               if (ret < 0)
+                       goto error_while;
+               write_msi_msg(irq, &msg);
+       }
+       return 0;
+
+error_while:
+       unbind_from_irqhandler(irq, NULL);
+error:
+       if (ret == -ENODEV)
+               dev_err(&dev->dev, "Xen PCI frontend has not registered" \
+                               " MSI/MSI-X support!\n");
+
+       return ret;
+}
+
 /*
  * For MSI interrupts we have to use drivers/xen/event.s functions to
  * allocate an irq_desc and setup the right */
@@ -198,5 +250,10 @@ int __init pci_xen_hvm_init(void)
         */
        __acpi_register_gsi = acpi_register_gsi_xen_hvm;
 #endif
+
+#ifdef CONFIG_PCI_MSI
+       x86_msi.setup_msi_irqs = xen_hvm_setup_msi_irqs;
+       x86_msi.teardown_msi_irq = xen_teardown_msi_irq;
+#endif
        return 0;
 }
index 32269bcbd88cfc33ce85ac04ebb964d9b26aa5e4..efa683ee8840b49bf3e9db2d20b5a67f9483880e 100644 (file)
@@ -656,6 +656,28 @@ out:
        return irq;
 }
 
+void xen_allocate_pirq_msi(char *name, int *irq, int *pirq)
+{
+       spin_lock(&irq_mapping_update_lock);
+
+       *irq = find_unbound_irq();
+       if (*irq == -1)
+               goto out;
+
+       *pirq = find_unbound_pirq();
+       if (*pirq == -1)
+               goto out;
+
+       set_irq_chip_and_handler_name(*irq, &xen_pirq_chip,
+                                     handle_level_irq, name);
+
+       irq_info[*irq] = mk_pirq_info(0, *pirq, 0, 0);
+       pirq_to_irq[*pirq] = *irq;
+
+out:
+       spin_unlock(&irq_mapping_update_lock);
+}
+
 int xen_destroy_irq(int irq)
 {
        struct irq_desc *desc;
index deec8faace22a2d61c1c0797f8ca47aa063b7be7..0c58db6ea3f4c634a6c1b4132ca9eb6f8e82e86b 100644 (file)
@@ -72,6 +72,8 @@ void xen_hvm_evtchn_do_upcall(void);
  * usual. */
 int xen_allocate_pirq(unsigned gsi, int shareable, char *name);
 int xen_map_pirq_gsi(unsigned pirq, unsigned gsi, int shareable, char *name);
+/* Allocate an irq and a pirq to be used with MSIs. */
+void xen_allocate_pirq_msi(char *name, int *irq, int *pirq);
 
 /* De-allocates the above mentioned physical interrupt. */
 int xen_destroy_irq(int irq);