12 #include <linux/module.h>
14 #include <linux/pci.h>
21 #include <asm/xen/hypervisor.h>
24 #include <xen/events.h>
27 static int xen_pcifront_enable_irq(
struct pci_dev *
dev)
36 dev_warn(&dev->
dev,
"Xen PCI: failed to read interrupt line: %d\n",
48 dev_warn(&dev->
dev,
"Xen PCI: failed to bind GSI%d (PIRQ%d) to IRQ: %d\n",
54 dev_info(&dev->
dev,
"Xen PCI mapped GSI%d to IRQ%d\n", gsi, dev->
irq);
59 static int xen_register_pirq(
u32 gsi,
int gsi_override,
int triggering,
62 int rc, pirq = -1,
irq = -1;
90 name =
"ioapic-level";
93 if (gsi_override >= 0)
100 printk(
KERN_DEBUG "xen: --> pirq=%d -> irq=%d (gsi=%d)\n", map_irq.pirq, irq, gsi);
105 static int acpi_register_gsi_xen_hvm(
struct device *dev,
u32 gsi,
111 return xen_register_pirq(gsi, -1 , trigger,
115 #ifdef CONFIG_XEN_DOM0
116 static int xen_register_gsi(
u32 gsi,
int gsi_override,
int triggering,
int polarity)
125 gsi, triggering, polarity);
127 irq = xen_register_pirq(gsi, gsi_override, triggering,
true);
144 static int acpi_register_gsi_xen(
struct device *dev,
u32 gsi,
145 int trigger,
int polarity)
147 return xen_register_gsi(gsi, -1 , trigger, polarity);
152 #if defined(CONFIG_PCI_MSI)
154 #include <asm/msidef.h>
156 struct xen_pci_frontend_ops *xen_pci_frontend;
159 static int xen_setup_msi_irqs(
struct pci_dev *dev,
int nvec,
int type)
170 ret = xen_pci_frontend_enable_msix(dev, v, nvec);
172 ret = xen_pci_frontend_enable_msi(dev, v);
177 irq = xen_bind_pirq_msi_to_irq(dev, msidesc, v[i], 0,
192 dev_err(&dev->
dev,
"Xen PCI frontend has not registered MSI/MSI-X support!\n");
198 #define XEN_PIRQ_MSI_DATA (MSI_DATA_TRIGGER_EDGE | \
199 MSI_DATA_LEVEL_ASSERT | (3 << 8) | MSI_DATA_VECTOR(0))
201 static void xen_msi_compose_msg(
struct pci_dev *pdev,
unsigned int pirq,
214 msg->
data = XEN_PIRQ_MSI_DATA;
217 static int xen_hvm_setup_msi_irqs(
struct pci_dev *dev,
int nvec,
int type)
227 if (
msg.data != XEN_PIRQ_MSI_DATA ||
229 pirq = xen_allocate_pirq_msi(dev, msidesc);
234 xen_msi_compose_msg(dev, pirq, &
msg);
236 dev_dbg(&dev->
dev,
"xen: msi bound to pirq=%d\n", pirq);
239 "xen: msi already bound to pirq=%d\n", pirq);
241 irq = xen_bind_pirq_msi_to_irq(dev, msidesc, pirq, 0,
248 "xen: msi --> pirq=%d --> irq=%d\n", pirq, irq);
254 "Xen PCI frontend has not registered MSI/MSI-X support!\n");
258 #ifdef CONFIG_XEN_DOM0
261 static int xen_initdom_setup_msi_irqs(
struct pci_dev *dev,
int nvec,
int type)
270 domid = ret = xen_find_device_domain_owner(dev);
276 memset(&map_irq, 0,
sizeof(map_irq));
277 map_irq.domid =
domid;
281 map_irq.bus = dev->
bus->number |
283 map_irq.devfn = dev->
devfn;
287 u32 table_offset, bir;
296 map_irq.entry_nr = msidesc->
msi_attrib.entry_nr;
300 if (pci_seg_supported)
307 map_irq.bus = dev->
bus->number;
311 pci_seg_supported =
false;
314 dev_warn(&dev->
dev,
"xen map irq failed %d for %d domain\n",
319 ret = xen_bind_pirq_msi_to_irq(dev, msidesc,
320 map_irq.pirq, map_irq.index,
332 static void xen_initdom_restore_msi_irqs(
struct pci_dev *dev,
int irq)
336 if (pci_seg_supported) {
340 restore_ext.bus = dev->
bus->number;
341 restore_ext.devfn = dev->
devfn;
345 pci_seg_supported =
false;
346 WARN(ret && ret != -
ENOSYS,
"restore_msi_ext -> %d\n", ret);
348 if (!pci_seg_supported) {
351 restore.
bus = dev->
bus->number;
352 restore.devfn = dev->
devfn;
354 WARN(ret && ret != -
ENOSYS,
"restore_msi -> %d\n", ret);
359 static void xen_teardown_msi_irqs(
struct pci_dev *dev)
365 xen_pci_frontend_disable_msix(dev);
367 xen_pci_frontend_disable_msi(dev);
373 static void xen_teardown_msi_irq(
unsigned int irq)
397 #ifdef CONFIG_PCI_MSI
398 x86_msi.setup_msi_irqs = xen_setup_msi_irqs;
399 x86_msi.teardown_msi_irq = xen_teardown_msi_irq;
400 x86_msi.teardown_msi_irqs = xen_teardown_msi_irqs;
418 #ifdef CONFIG_PCI_MSI
419 x86_msi.setup_msi_irqs = xen_hvm_setup_msi_irqs;
420 x86_msi.teardown_msi_irq = xen_teardown_msi_irq;
425 #ifdef CONFIG_XEN_DOM0
426 static __init void xen_setup_acpi_sci(
void)
430 int gsi = acpi_sci_override_gsi;
432 int gsi_override = -1;
440 " sci, rc=%d\n", rc);
447 "polarity=%d\n", gsi, trigger, polarity);
466 gsi = xen_register_gsi(gsi, gsi_override, trigger, polarity);
472 int __init pci_xen_initial_domain(
void)
476 #ifdef CONFIG_PCI_MSI
477 x86_msi.setup_msi_irqs = xen_initdom_setup_msi_irqs;
478 x86_msi.teardown_msi_irq = xen_teardown_msi_irq;
479 x86_msi.restore_msi_irqs = xen_initdom_restore_msi_irqs;
481 xen_setup_acpi_sci();
490 xen_register_pirq(irq, -1 ,
501 struct xen_device_domain_owner {
510 static struct xen_device_domain_owner *find_device(
struct pci_dev *dev)
512 struct xen_device_domain_owner *
owner;
515 if (owner->dev == dev)
521 int xen_find_device_domain_owner(
struct pci_dev *dev)
523 struct xen_device_domain_owner *
owner;
526 spin_lock(&dev_domain_list_spinlock);
527 owner = find_device(dev);
529 domain = owner->domain;
530 spin_unlock(&dev_domain_list_spinlock);
535 int xen_register_device_domain_owner(
struct pci_dev *dev,
uint16_t domain)
537 struct xen_device_domain_owner *
owner;
539 owner = kzalloc(
sizeof(
struct xen_device_domain_owner),
GFP_KERNEL);
543 spin_lock(&dev_domain_list_spinlock);
544 if (find_device(dev)) {
545 spin_unlock(&dev_domain_list_spinlock);
549 owner->domain = domain;
552 spin_unlock(&dev_domain_list_spinlock);
557 int xen_unregister_device_domain_owner(
struct pci_dev *dev)
559 struct xen_device_domain_owner *
owner;
561 spin_lock(&dev_domain_list_spinlock);
562 owner = find_device(dev);
564 spin_unlock(&dev_domain_list_spinlock);
568 spin_unlock(&dev_domain_list_spinlock);