xen: add xen hvm acpi_register_gsi variant
[deliverable/linux.git] / arch / x86 / pci / xen.c
CommitLineData
b5401a96
AN
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
42a1de56
SS
20#ifdef CONFIG_ACPI
21static int xen_hvm_register_pirq(u32 gsi, int triggering)
22{
23 int rc, irq;
24 struct physdev_map_pirq map_irq;
25 int shareable = 0;
26 char *name;
27
28 if (!xen_hvm_domain())
29 return -1;
30
31 map_irq.domid = DOMID_SELF;
32 map_irq.type = MAP_PIRQ_TYPE_GSI;
33 map_irq.index = gsi;
34 map_irq.pirq = -1;
35
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;
40 }
41
42 if (triggering == ACPI_EDGE_SENSITIVE) {
43 shareable = 0;
44 name = "ioapic-edge";
45 } else {
46 shareable = 1;
47 name = "ioapic-level";
48 }
49
50 irq = xen_map_pirq_gsi(map_irq.pirq, gsi, shareable, name);
51
52 printk(KERN_DEBUG "xen: --> irq=%d, pirq=%d\n", irq, map_irq.pirq);
53
54 return irq;
55}
90f6881e
JF
56
57static int acpi_register_gsi_xen_hvm(struct device *dev, u32 gsi,
58 int trigger, int polarity)
59{
60 return xen_hvm_register_pirq(gsi, trigger);
61}
42a1de56
SS
62#endif
63
b5401a96
AN
64#if defined(CONFIG_PCI_MSI)
65#include <linux/msi.h>
66
67struct xen_pci_frontend_ops *xen_pci_frontend;
68EXPORT_SYMBOL_GPL(xen_pci_frontend);
69
70/*
71 * For MSI interrupts we have to use drivers/xen/event.s functions to
72 * allocate an irq_desc and setup the right */
73
74
75static int xen_setup_msi_irqs(struct pci_dev *dev, int nvec, int type)
76{
77 int irq, ret, i;
78 struct msi_desc *msidesc;
79 int *v;
80
81 v = kzalloc(sizeof(int) * max(1, nvec), GFP_KERNEL);
82 if (!v)
83 return -ENOMEM;
84
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;
92 }
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;
100
101 ret = set_irq_msi(irq, msidesc);
102 if (ret)
103 goto error_while;
104 i++;
105 }
106 kfree(v);
107 return 0;
108
109error_while:
110 unbind_from_irqhandler(irq, NULL);
111error:
112 if (ret == -ENODEV)
113 dev_err(&dev->dev, "Xen PCI frontend has not registered" \
114 " MSI/MSI-X support!\n");
115
116 kfree(v);
117 return ret;
118}
119
120static void xen_teardown_msi_irqs(struct pci_dev *dev)
121{
122 /* Only do this when were are in non-privileged mode.*/
123 if (!xen_initial_domain()) {
124 struct msi_desc *msidesc;
125
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);
131 }
132
133}
134
135static void xen_teardown_msi_irq(unsigned int irq)
136{
137 xen_destroy_irq(irq);
138}
139#endif
140
141static int xen_pcifront_enable_irq(struct pci_dev *dev)
142{
143 int rc;
144 int share = 1;
145
146 dev_info(&dev->dev, "Xen PCI enabling IRQ: %d\n", dev->irq);
147
148 if (dev->irq < 0)
149 return -EINVAL;
150
151 if (dev->irq < NR_IRQS_LEGACY)
152 share = 0;
153
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;
159 }
160 return 0;
161}
162
163int __init pci_xen_init(void)
164{
165 if (!xen_pv_domain() || xen_initial_domain())
166 return -ENODEV;
167
168 printk(KERN_INFO "PCI: setting up Xen PCI frontend stub\n");
169
170 pcibios_set_cache_line_size();
171
172 pcibios_enable_irq = xen_pcifront_enable_irq;
173 pcibios_disable_irq = NULL;
174
175#ifdef CONFIG_ACPI
176 /* Keep ACPI out of the picture */
177 acpi_noirq = 1;
178#endif
179
b5401a96
AN
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;
186}
This page took 0.038517 seconds and 5 git commands to generate.