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>
7 #include <linux/module.h>
8 #include <linux/init.h>
10 #include <linux/acpi.h>
13 #include <asm/pci_x86.h>
15 #include <asm/xen/hypervisor.h>
17 #include <xen/events.h>
18 #include <asm/xen/pci.h>
21 static int xen_hvm_register_pirq(u32 gsi
, int triggering
)
24 struct physdev_map_pirq map_irq
;
28 if (!xen_hvm_domain())
31 map_irq
.domid
= DOMID_SELF
;
32 map_irq
.type
= MAP_PIRQ_TYPE_GSI
;
36 rc
= HYPERVISOR_physdev_op(PHYSDEVOP_map_pirq
, &map_irq
);
38 printk(KERN_WARNING
"xen map irq failed %d\n", rc
);
42 if (triggering
== ACPI_EDGE_SENSITIVE
) {
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
);
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
);
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
)
78 struct msi_desc
*msidesc
;
81 v
= kzalloc(sizeof(int) * max(1, nvec
), GFP_KERNEL
);
85 if (!xen_initial_domain()) {
86 if (type
== PCI_CAP_ID_MSIX
)
87 ret
= xen_pci_frontend_enable_msix(dev
, &v
, nvec
);
89 ret
= xen_pci_frontend_enable_msi(dev
, &v
);
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");
101 ret
= set_irq_msi(irq
, msidesc
);
110 unbind_from_irqhandler(irq
, NULL
);
113 dev_err(&dev
->dev
, "Xen PCI frontend has not registered" \
114 " MSI/MSI-X support!\n");
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
);
130 xen_pci_frontend_disable_msi(dev
);
135 static void xen_teardown_msi_irq(unsigned int irq
)
137 xen_destroy_irq(irq
);
141 static int xen_pcifront_enable_irq(struct pci_dev
*dev
)
146 dev_info(&dev
->dev
, "Xen PCI enabling IRQ: %d\n", dev
->irq
);
151 if (dev
->irq
< NR_IRQS_LEGACY
)
154 rc
= xen_allocate_pirq(dev
->irq
, share
, "pcifront");
156 dev_warn(&dev
->dev
, "Xen PCI IRQ: %d, failed to register:%d\n",
163 int __init
pci_xen_init(void)
165 if (!xen_pv_domain() || xen_initial_domain())
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
;
176 /* Keep ACPI out of the picture */
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
;