diff options
Diffstat (limited to 'arch/x86/pci/xen.c')
-rw-r--r-- | arch/x86/pci/xen.c | 147 |
1 files changed, 147 insertions, 0 deletions
diff --git a/arch/x86/pci/xen.c b/arch/x86/pci/xen.c new file mode 100644 index 000000000000..b19c873d8d0c --- /dev/null +++ b/arch/x86/pci/xen.c | |||
@@ -0,0 +1,147 @@ | |||
1 | /* | ||
2 | * Xen PCI Frontend Stub - puts some "dummy" functions in to the Linux | ||
3 | * x86 PCI core to support the Xen PCI Frontend | ||
4 | * | ||
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> | ||
11 | |||
12 | #include <linux/io.h> | ||
13 | #include <asm/pci_x86.h> | ||
14 | |||
15 | #include <asm/xen/hypervisor.h> | ||
16 | |||
17 | #include <xen/events.h> | ||
18 | #include <asm/xen/pci.h> | ||
19 | |||
20 | #if defined(CONFIG_PCI_MSI) | ||
21 | #include <linux/msi.h> | ||
22 | |||
23 | struct xen_pci_frontend_ops *xen_pci_frontend; | ||
24 | EXPORT_SYMBOL_GPL(xen_pci_frontend); | ||
25 | |||
26 | /* | ||
27 | * For MSI interrupts we have to use drivers/xen/event.s functions to | ||
28 | * allocate an irq_desc and setup the right */ | ||
29 | |||
30 | |||
31 | static int xen_setup_msi_irqs(struct pci_dev *dev, int nvec, int type) | ||
32 | { | ||
33 | int irq, ret, i; | ||
34 | struct msi_desc *msidesc; | ||
35 | int *v; | ||
36 | |||
37 | v = kzalloc(sizeof(int) * max(1, nvec), GFP_KERNEL); | ||
38 | if (!v) | ||
39 | return -ENOMEM; | ||
40 | |||
41 | if (!xen_initial_domain()) { | ||
42 | if (type == PCI_CAP_ID_MSIX) | ||
43 | ret = xen_pci_frontend_enable_msix(dev, &v, nvec); | ||
44 | else | ||
45 | ret = xen_pci_frontend_enable_msi(dev, &v); | ||
46 | if (ret) | ||
47 | goto error; | ||
48 | } | ||
49 | i = 0; | ||
50 | list_for_each_entry(msidesc, &dev->msi_list, list) { | ||
51 | irq = xen_allocate_pirq(v[i], 0, /* not sharable */ | ||
52 | (type == PCI_CAP_ID_MSIX) ? | ||
53 | "pcifront-msi-x" : "pcifront-msi"); | ||
54 | if (irq < 0) | ||
55 | return -1; | ||
56 | |||
57 | ret = set_irq_msi(irq, msidesc); | ||
58 | if (ret) | ||
59 | goto error_while; | ||
60 | i++; | ||
61 | } | ||
62 | kfree(v); | ||
63 | return 0; | ||
64 | |||
65 | error_while: | ||
66 | unbind_from_irqhandler(irq, NULL); | ||
67 | error: | ||
68 | if (ret == -ENODEV) | ||
69 | dev_err(&dev->dev, "Xen PCI frontend has not registered" \ | ||
70 | " MSI/MSI-X support!\n"); | ||
71 | |||
72 | kfree(v); | ||
73 | return ret; | ||
74 | } | ||
75 | |||
76 | static void xen_teardown_msi_irqs(struct pci_dev *dev) | ||
77 | { | ||
78 | /* Only do this when were are in non-privileged mode.*/ | ||
79 | if (!xen_initial_domain()) { | ||
80 | struct msi_desc *msidesc; | ||
81 | |||
82 | msidesc = list_entry(dev->msi_list.next, struct msi_desc, list); | ||
83 | if (msidesc->msi_attrib.is_msix) | ||
84 | xen_pci_frontend_disable_msix(dev); | ||
85 | else | ||
86 | xen_pci_frontend_disable_msi(dev); | ||
87 | } | ||
88 | |||
89 | } | ||
90 | |||
91 | static void xen_teardown_msi_irq(unsigned int irq) | ||
92 | { | ||
93 | xen_destroy_irq(irq); | ||
94 | } | ||
95 | #endif | ||
96 | |||
97 | static int xen_pcifront_enable_irq(struct pci_dev *dev) | ||
98 | { | ||
99 | int rc; | ||
100 | int share = 1; | ||
101 | |||
102 | dev_info(&dev->dev, "Xen PCI enabling IRQ: %d\n", dev->irq); | ||
103 | |||
104 | if (dev->irq < 0) | ||
105 | return -EINVAL; | ||
106 | |||
107 | if (dev->irq < NR_IRQS_LEGACY) | ||
108 | share = 0; | ||
109 | |||
110 | rc = xen_allocate_pirq(dev->irq, share, "pcifront"); | ||
111 | if (rc < 0) { | ||
112 | dev_warn(&dev->dev, "Xen PCI IRQ: %d, failed to register:%d\n", | ||
113 | dev->irq, rc); | ||
114 | return rc; | ||
115 | } | ||
116 | return 0; | ||
117 | } | ||
118 | |||
119 | int __init pci_xen_init(void) | ||
120 | { | ||
121 | if (!xen_pv_domain() || xen_initial_domain()) | ||
122 | return -ENODEV; | ||
123 | |||
124 | printk(KERN_INFO "PCI: setting up Xen PCI frontend stub\n"); | ||
125 | |||
126 | pcibios_set_cache_line_size(); | ||
127 | |||
128 | pcibios_enable_irq = xen_pcifront_enable_irq; | ||
129 | pcibios_disable_irq = NULL; | ||
130 | |||
131 | #ifdef CONFIG_ACPI | ||
132 | /* Keep ACPI out of the picture */ | ||
133 | acpi_noirq = 1; | ||
134 | #endif | ||
135 | |||
136 | #ifdef CONFIG_ISAPNP | ||
137 | /* Stop isapnp from probing */ | ||
138 | isapnp_disable = 1; | ||
139 | #endif | ||
140 | |||
141 | #ifdef CONFIG_PCI_MSI | ||
142 | x86_msi.setup_msi_irqs = xen_setup_msi_irqs; | ||
143 | x86_msi.teardown_msi_irq = xen_teardown_msi_irq; | ||
144 | x86_msi.teardown_msi_irqs = xen_teardown_msi_irqs; | ||
145 | #endif | ||
146 | return 0; | ||
147 | } | ||