xen: add xen hvm acpi_register_gsi variant
[linux-2.6.git] / arch / x86 / pci / xen.c
blob3a4ab0b4dcca8bb3464c37fd7021ba22034b966d
1 /*
2 * Xen PCI Frontend Stub - puts some "dummy" functions in to the Linux
3 * x86 PCI core to support the Xen PCI Frontend
5 * Author: Ryan Wilson <hap9@epoch.ncsc.mil>
6 */
7 #include <linux/module.h>
8 #include <linux/init.h>
9 #include <linux/pci.h>
10 #include <linux/acpi.h>
12 #include <linux/io.h>
13 #include <asm/pci_x86.h>
15 #include <asm/xen/hypervisor.h>
17 #include <xen/events.h>
18 #include <asm/xen/pci.h>
20 #ifdef CONFIG_ACPI
21 static int xen_hvm_register_pirq(u32 gsi, int triggering)
23 int rc, irq;
24 struct physdev_map_pirq map_irq;
25 int shareable = 0;
26 char *name;
28 if (!xen_hvm_domain())
29 return -1;
31 map_irq.domid = DOMID_SELF;
32 map_irq.type = MAP_PIRQ_TYPE_GSI;
33 map_irq.index = gsi;
34 map_irq.pirq = -1;
36 rc = HYPERVISOR_physdev_op(PHYSDEVOP_map_pirq, &map_irq);
37 if (rc) {
38 printk(KERN_WARNING "xen map irq failed %d\n", rc);
39 return -1;
42 if (triggering == ACPI_EDGE_SENSITIVE) {
43 shareable = 0;
44 name = "ioapic-edge";
45 } else {
46 shareable = 1;
47 name = "ioapic-level";
50 irq = xen_map_pirq_gsi(map_irq.pirq, gsi, shareable, name);
52 printk(KERN_DEBUG "xen: --> irq=%d, pirq=%d\n", irq, map_irq.pirq);
54 return irq;
57 static int acpi_register_gsi_xen_hvm(struct device *dev, u32 gsi,
58 int trigger, int polarity)
60 return xen_hvm_register_pirq(gsi, trigger);
62 #endif
64 #if defined(CONFIG_PCI_MSI)
65 #include <linux/msi.h>
67 struct xen_pci_frontend_ops *xen_pci_frontend;
68 EXPORT_SYMBOL_GPL(xen_pci_frontend);
71 * For MSI interrupts we have to use drivers/xen/event.s functions to
72 * allocate an irq_desc and setup the right */
75 static int xen_setup_msi_irqs(struct pci_dev *dev, int nvec, int type)
77 int irq, ret, i;
78 struct msi_desc *msidesc;
79 int *v;
81 v = kzalloc(sizeof(int) * max(1, nvec), GFP_KERNEL);
82 if (!v)
83 return -ENOMEM;
85 if (!xen_initial_domain()) {
86 if (type == PCI_CAP_ID_MSIX)
87 ret = xen_pci_frontend_enable_msix(dev, &v, nvec);
88 else
89 ret = xen_pci_frontend_enable_msi(dev, &v);
90 if (ret)
91 goto error;
93 i = 0;
94 list_for_each_entry(msidesc, &dev->msi_list, list) {
95 irq = xen_allocate_pirq(v[i], 0, /* not sharable */
96 (type == PCI_CAP_ID_MSIX) ?
97 "pcifront-msi-x" : "pcifront-msi");
98 if (irq < 0)
99 return -1;
101 ret = set_irq_msi(irq, msidesc);
102 if (ret)
103 goto error_while;
104 i++;
106 kfree(v);
107 return 0;
109 error_while:
110 unbind_from_irqhandler(irq, NULL);
111 error:
112 if (ret == -ENODEV)
113 dev_err(&dev->dev, "Xen PCI frontend has not registered" \
114 " MSI/MSI-X support!\n");
116 kfree(v);
117 return ret;
120 static void xen_teardown_msi_irqs(struct pci_dev *dev)
122 /* Only do this when were are in non-privileged mode.*/
123 if (!xen_initial_domain()) {
124 struct msi_desc *msidesc;
126 msidesc = list_entry(dev->msi_list.next, struct msi_desc, list);
127 if (msidesc->msi_attrib.is_msix)
128 xen_pci_frontend_disable_msix(dev);
129 else
130 xen_pci_frontend_disable_msi(dev);
135 static void xen_teardown_msi_irq(unsigned int irq)
137 xen_destroy_irq(irq);
139 #endif
141 static int xen_pcifront_enable_irq(struct pci_dev *dev)
143 int rc;
144 int share = 1;
146 dev_info(&dev->dev, "Xen PCI enabling IRQ: %d\n", dev->irq);
148 if (dev->irq < 0)
149 return -EINVAL;
151 if (dev->irq < NR_IRQS_LEGACY)
152 share = 0;
154 rc = xen_allocate_pirq(dev->irq, share, "pcifront");
155 if (rc < 0) {
156 dev_warn(&dev->dev, "Xen PCI IRQ: %d, failed to register:%d\n",
157 dev->irq, rc);
158 return rc;
160 return 0;
163 int __init pci_xen_init(void)
165 if (!xen_pv_domain() || xen_initial_domain())
166 return -ENODEV;
168 printk(KERN_INFO "PCI: setting up Xen PCI frontend stub\n");
170 pcibios_set_cache_line_size();
172 pcibios_enable_irq = xen_pcifront_enable_irq;
173 pcibios_disable_irq = NULL;
175 #ifdef CONFIG_ACPI
176 /* Keep ACPI out of the picture */
177 acpi_noirq = 1;
178 #endif
180 #ifdef CONFIG_PCI_MSI
181 x86_msi.setup_msi_irqs = xen_setup_msi_irqs;
182 x86_msi.teardown_msi_irq = xen_teardown_msi_irq;
183 x86_msi.teardown_msi_irqs = xen_teardown_msi_irqs;
184 #endif
185 return 0;