diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2010-10-28 20:11:17 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2010-10-28 20:11:17 -0400 |
commit | 18cb657ca1bafe635f368346a1676fb04c512edf (patch) | |
tree | b0eb6a4ceddf98e7bf820be7ff24bf131ff56b0c /drivers | |
parent | 2301b65b86df8b80e6779ce9885ad62a5c4adc38 (diff) | |
parent | e28c31a96b1570f17731b18e8efabb7308d0c22c (diff) |
Merge branch 'stable/xen-pcifront-0.8.2' of git://git.kernel.org/pub/scm/linux/kernel/git/konrad/xen
and branch 'for-linus' of git://xenbits.xen.org/people/sstabellini/linux-pvhvm
* 'for-linus' of git://xenbits.xen.org/people/sstabellini/linux-pvhvm:
xen: register xen pci notifier
xen: initialize cpu masks for pv guests in xen_smp_init
xen: add a missing #include to arch/x86/pci/xen.c
xen: mask the MTRR feature from the cpuid
xen: make hvc_xen console work for dom0.
xen: add the direct mapping area for ISA bus access
xen: Initialize xenbus for dom0.
xen: use vcpu_ops to setup cpu masks
xen: map a dummy page for local apic and ioapic in xen_set_fixmap
xen: remap MSIs into pirqs when running as initial domain
xen: remap GSIs as pirqs when running as initial domain
xen: introduce XEN_DOM0 as a silent option
xen: map MSIs into pirqs
xen: support GSI -> pirq remapping in PV on HVM guests
xen: add xen hvm acpi_register_gsi variant
acpi: use indirect call to register gsi in different modes
xen: implement xen_hvm_register_pirq
xen: get the maximum number of pirqs from xen
xen: support pirq != irq
* 'stable/xen-pcifront-0.8.2' of git://git.kernel.org/pub/scm/linux/kernel/git/konrad/xen: (27 commits)
X86/PCI: Remove the dependency on isapnp_disable.
xen: Update Makefile with CONFIG_BLOCK dependency for biomerge.c
MAINTAINERS: Add myself to the Xen Hypervisor Interface and remove Chris Wright.
x86: xen: Sanitse irq handling (part two)
swiotlb-xen: On x86-32 builts, select SWIOTLB instead of depending on it.
MAINTAINERS: Add myself for Xen PCI and Xen SWIOTLB maintainer.
xen/pci: Request ACS when Xen-SWIOTLB is activated.
xen-pcifront: Xen PCI frontend driver.
xenbus: prevent warnings on unhandled enumeration values
xenbus: Xen paravirtualised PCI hotplug support.
xen/x86/PCI: Add support for the Xen PCI subsystem
x86: Introduce x86_msi_ops
msi: Introduce default_[teardown|setup]_msi_irqs with fallback.
x86/PCI: Export pci_walk_bus function.
x86/PCI: make sure _PAGE_IOMAP it set on pci mappings
x86/PCI: Clean up pci_cache_line_size
xen: fix shared irq device passthrough
xen: Provide a variant of xen_poll_irq with timeout.
xen: Find an unbound irq number in reverse order (high to low).
xen: statically initialize cpu_evtchn_mask_p
...
Fix up trivial conflicts in drivers/pci/Makefile
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/block/xen-blkfront.c | 2 | ||||
-rw-r--r-- | drivers/char/hvc_xen.c | 98 | ||||
-rw-r--r-- | drivers/input/xen-kbdfront.c | 2 | ||||
-rw-r--r-- | drivers/net/xen-netfront.c | 2 | ||||
-rw-r--r-- | drivers/pci/Kconfig | 21 | ||||
-rw-r--r-- | drivers/pci/Makefile | 2 | ||||
-rw-r--r-- | drivers/pci/bus.c | 1 | ||||
-rw-r--r-- | drivers/pci/msi.c | 14 | ||||
-rw-r--r-- | drivers/pci/xen-pcifront.c | 1148 | ||||
-rw-r--r-- | drivers/video/xen-fbfront.c | 2 | ||||
-rw-r--r-- | drivers/xen/Kconfig | 3 | ||||
-rw-r--r-- | drivers/xen/Makefile | 2 | ||||
-rw-r--r-- | drivers/xen/biomerge.c | 13 | ||||
-rw-r--r-- | drivers/xen/events.c | 509 | ||||
-rw-r--r-- | drivers/xen/pci.c | 117 | ||||
-rw-r--r-- | drivers/xen/xenbus/xenbus_client.c | 2 | ||||
-rw-r--r-- | drivers/xen/xenbus/xenbus_probe.c | 29 |
17 files changed, 1909 insertions, 58 deletions
diff --git a/drivers/block/xen-blkfront.c b/drivers/block/xen-blkfront.c index 4b33a18c32e0..06e2812ba124 100644 --- a/drivers/block/xen-blkfront.c +++ b/drivers/block/xen-blkfront.c | |||
@@ -1112,6 +1112,8 @@ static void blkback_changed(struct xenbus_device *dev, | |||
1112 | case XenbusStateInitialising: | 1112 | case XenbusStateInitialising: |
1113 | case XenbusStateInitWait: | 1113 | case XenbusStateInitWait: |
1114 | case XenbusStateInitialised: | 1114 | case XenbusStateInitialised: |
1115 | case XenbusStateReconfiguring: | ||
1116 | case XenbusStateReconfigured: | ||
1115 | case XenbusStateUnknown: | 1117 | case XenbusStateUnknown: |
1116 | case XenbusStateClosed: | 1118 | case XenbusStateClosed: |
1117 | break; | 1119 | break; |
diff --git a/drivers/char/hvc_xen.c b/drivers/char/hvc_xen.c index 6b8e6d18a8e6..3740e327f180 100644 --- a/drivers/char/hvc_xen.c +++ b/drivers/char/hvc_xen.c | |||
@@ -79,7 +79,7 @@ static int __write_console(const char *data, int len) | |||
79 | return sent; | 79 | return sent; |
80 | } | 80 | } |
81 | 81 | ||
82 | static int write_console(uint32_t vtermno, const char *data, int len) | 82 | static int domU_write_console(uint32_t vtermno, const char *data, int len) |
83 | { | 83 | { |
84 | int ret = len; | 84 | int ret = len; |
85 | 85 | ||
@@ -102,7 +102,7 @@ static int write_console(uint32_t vtermno, const char *data, int len) | |||
102 | return ret; | 102 | return ret; |
103 | } | 103 | } |
104 | 104 | ||
105 | static int read_console(uint32_t vtermno, char *buf, int len) | 105 | static int domU_read_console(uint32_t vtermno, char *buf, int len) |
106 | { | 106 | { |
107 | struct xencons_interface *intf = xencons_interface(); | 107 | struct xencons_interface *intf = xencons_interface(); |
108 | XENCONS_RING_IDX cons, prod; | 108 | XENCONS_RING_IDX cons, prod; |
@@ -123,28 +123,62 @@ static int read_console(uint32_t vtermno, char *buf, int len) | |||
123 | return recv; | 123 | return recv; |
124 | } | 124 | } |
125 | 125 | ||
126 | static const struct hv_ops hvc_ops = { | 126 | static struct hv_ops domU_hvc_ops = { |
127 | .get_chars = read_console, | 127 | .get_chars = domU_read_console, |
128 | .put_chars = write_console, | 128 | .put_chars = domU_write_console, |
129 | .notifier_add = notifier_add_irq, | 129 | .notifier_add = notifier_add_irq, |
130 | .notifier_del = notifier_del_irq, | 130 | .notifier_del = notifier_del_irq, |
131 | .notifier_hangup = notifier_hangup_irq, | 131 | .notifier_hangup = notifier_hangup_irq, |
132 | }; | 132 | }; |
133 | 133 | ||
134 | static int __init xen_init(void) | 134 | static int dom0_read_console(uint32_t vtermno, char *buf, int len) |
135 | { | ||
136 | return HYPERVISOR_console_io(CONSOLEIO_read, len, buf); | ||
137 | } | ||
138 | |||
139 | /* | ||
140 | * Either for a dom0 to write to the system console, or a domU with a | ||
141 | * debug version of Xen | ||
142 | */ | ||
143 | static int dom0_write_console(uint32_t vtermno, const char *str, int len) | ||
144 | { | ||
145 | int rc = HYPERVISOR_console_io(CONSOLEIO_write, len, (char *)str); | ||
146 | if (rc < 0) | ||
147 | return 0; | ||
148 | |||
149 | return len; | ||
150 | } | ||
151 | |||
152 | static struct hv_ops dom0_hvc_ops = { | ||
153 | .get_chars = dom0_read_console, | ||
154 | .put_chars = dom0_write_console, | ||
155 | .notifier_add = notifier_add_irq, | ||
156 | .notifier_del = notifier_del_irq, | ||
157 | .notifier_hangup = notifier_hangup_irq, | ||
158 | }; | ||
159 | |||
160 | static int __init xen_hvc_init(void) | ||
135 | { | 161 | { |
136 | struct hvc_struct *hp; | 162 | struct hvc_struct *hp; |
163 | struct hv_ops *ops; | ||
137 | 164 | ||
138 | if (!xen_pv_domain() || | 165 | if (!xen_pv_domain()) |
139 | xen_initial_domain() || | ||
140 | !xen_start_info->console.domU.evtchn) | ||
141 | return -ENODEV; | 166 | return -ENODEV; |
142 | 167 | ||
143 | xencons_irq = bind_evtchn_to_irq(xen_start_info->console.domU.evtchn); | 168 | if (xen_initial_domain()) { |
169 | ops = &dom0_hvc_ops; | ||
170 | xencons_irq = bind_virq_to_irq(VIRQ_CONSOLE, 0); | ||
171 | } else { | ||
172 | if (!xen_start_info->console.domU.evtchn) | ||
173 | return -ENODEV; | ||
174 | |||
175 | ops = &domU_hvc_ops; | ||
176 | xencons_irq = bind_evtchn_to_irq(xen_start_info->console.domU.evtchn); | ||
177 | } | ||
144 | if (xencons_irq < 0) | 178 | if (xencons_irq < 0) |
145 | xencons_irq = 0; /* NO_IRQ */ | 179 | xencons_irq = 0; /* NO_IRQ */ |
146 | 180 | ||
147 | hp = hvc_alloc(HVC_COOKIE, xencons_irq, &hvc_ops, 256); | 181 | hp = hvc_alloc(HVC_COOKIE, xencons_irq, ops, 256); |
148 | if (IS_ERR(hp)) | 182 | if (IS_ERR(hp)) |
149 | return PTR_ERR(hp); | 183 | return PTR_ERR(hp); |
150 | 184 | ||
@@ -161,7 +195,7 @@ void xen_console_resume(void) | |||
161 | rebind_evtchn_irq(xen_start_info->console.domU.evtchn, xencons_irq); | 195 | rebind_evtchn_irq(xen_start_info->console.domU.evtchn, xencons_irq); |
162 | } | 196 | } |
163 | 197 | ||
164 | static void __exit xen_fini(void) | 198 | static void __exit xen_hvc_fini(void) |
165 | { | 199 | { |
166 | if (hvc) | 200 | if (hvc) |
167 | hvc_remove(hvc); | 201 | hvc_remove(hvc); |
@@ -169,29 +203,24 @@ static void __exit xen_fini(void) | |||
169 | 203 | ||
170 | static int xen_cons_init(void) | 204 | static int xen_cons_init(void) |
171 | { | 205 | { |
206 | struct hv_ops *ops; | ||
207 | |||
172 | if (!xen_pv_domain()) | 208 | if (!xen_pv_domain()) |
173 | return 0; | 209 | return 0; |
174 | 210 | ||
175 | hvc_instantiate(HVC_COOKIE, 0, &hvc_ops); | 211 | if (xen_initial_domain()) |
212 | ops = &dom0_hvc_ops; | ||
213 | else | ||
214 | ops = &domU_hvc_ops; | ||
215 | |||
216 | hvc_instantiate(HVC_COOKIE, 0, ops); | ||
176 | return 0; | 217 | return 0; |
177 | } | 218 | } |
178 | 219 | ||
179 | module_init(xen_init); | 220 | module_init(xen_hvc_init); |
180 | module_exit(xen_fini); | 221 | module_exit(xen_hvc_fini); |
181 | console_initcall(xen_cons_init); | 222 | console_initcall(xen_cons_init); |
182 | 223 | ||
183 | static void raw_console_write(const char *str, int len) | ||
184 | { | ||
185 | while(len > 0) { | ||
186 | int rc = HYPERVISOR_console_io(CONSOLEIO_write, len, (char *)str); | ||
187 | if (rc <= 0) | ||
188 | break; | ||
189 | |||
190 | str += rc; | ||
191 | len -= rc; | ||
192 | } | ||
193 | } | ||
194 | |||
195 | #ifdef CONFIG_EARLY_PRINTK | 224 | #ifdef CONFIG_EARLY_PRINTK |
196 | static void xenboot_write_console(struct console *console, const char *string, | 225 | static void xenboot_write_console(struct console *console, const char *string, |
197 | unsigned len) | 226 | unsigned len) |
@@ -199,19 +228,22 @@ static void xenboot_write_console(struct console *console, const char *string, | |||
199 | unsigned int linelen, off = 0; | 228 | unsigned int linelen, off = 0; |
200 | const char *pos; | 229 | const char *pos; |
201 | 230 | ||
202 | raw_console_write(string, len); | 231 | dom0_write_console(0, string, len); |
232 | |||
233 | if (xen_initial_domain()) | ||
234 | return; | ||
203 | 235 | ||
204 | write_console(0, "(early) ", 8); | 236 | domU_write_console(0, "(early) ", 8); |
205 | while (off < len && NULL != (pos = strchr(string+off, '\n'))) { | 237 | while (off < len && NULL != (pos = strchr(string+off, '\n'))) { |
206 | linelen = pos-string+off; | 238 | linelen = pos-string+off; |
207 | if (off + linelen > len) | 239 | if (off + linelen > len) |
208 | break; | 240 | break; |
209 | write_console(0, string+off, linelen); | 241 | domU_write_console(0, string+off, linelen); |
210 | write_console(0, "\r\n", 2); | 242 | domU_write_console(0, "\r\n", 2); |
211 | off += linelen + 1; | 243 | off += linelen + 1; |
212 | } | 244 | } |
213 | if (off < len) | 245 | if (off < len) |
214 | write_console(0, string+off, len-off); | 246 | domU_write_console(0, string+off, len-off); |
215 | } | 247 | } |
216 | 248 | ||
217 | struct console xenboot_console = { | 249 | struct console xenboot_console = { |
@@ -223,7 +255,7 @@ struct console xenboot_console = { | |||
223 | 255 | ||
224 | void xen_raw_console_write(const char *str) | 256 | void xen_raw_console_write(const char *str) |
225 | { | 257 | { |
226 | raw_console_write(str, strlen(str)); | 258 | dom0_write_console(0, str, strlen(str)); |
227 | } | 259 | } |
228 | 260 | ||
229 | void xen_raw_printk(const char *fmt, ...) | 261 | void xen_raw_printk(const char *fmt, ...) |
diff --git a/drivers/input/xen-kbdfront.c b/drivers/input/xen-kbdfront.c index ebb11907d402..e0c024db2ca5 100644 --- a/drivers/input/xen-kbdfront.c +++ b/drivers/input/xen-kbdfront.c | |||
@@ -276,6 +276,8 @@ static void xenkbd_backend_changed(struct xenbus_device *dev, | |||
276 | switch (backend_state) { | 276 | switch (backend_state) { |
277 | case XenbusStateInitialising: | 277 | case XenbusStateInitialising: |
278 | case XenbusStateInitialised: | 278 | case XenbusStateInitialised: |
279 | case XenbusStateReconfiguring: | ||
280 | case XenbusStateReconfigured: | ||
279 | case XenbusStateUnknown: | 281 | case XenbusStateUnknown: |
280 | case XenbusStateClosed: | 282 | case XenbusStateClosed: |
281 | break; | 283 | break; |
diff --git a/drivers/net/xen-netfront.c b/drivers/net/xen-netfront.c index 630fb8664768..458bb57914a3 100644 --- a/drivers/net/xen-netfront.c +++ b/drivers/net/xen-netfront.c | |||
@@ -1610,6 +1610,8 @@ static void netback_changed(struct xenbus_device *dev, | |||
1610 | switch (backend_state) { | 1610 | switch (backend_state) { |
1611 | case XenbusStateInitialising: | 1611 | case XenbusStateInitialising: |
1612 | case XenbusStateInitialised: | 1612 | case XenbusStateInitialised: |
1613 | case XenbusStateReconfiguring: | ||
1614 | case XenbusStateReconfigured: | ||
1613 | case XenbusStateConnected: | 1615 | case XenbusStateConnected: |
1614 | case XenbusStateUnknown: | 1616 | case XenbusStateUnknown: |
1615 | case XenbusStateClosed: | 1617 | case XenbusStateClosed: |
diff --git a/drivers/pci/Kconfig b/drivers/pci/Kconfig index 34ef70d562b2..5b1630e4e9e3 100644 --- a/drivers/pci/Kconfig +++ b/drivers/pci/Kconfig | |||
@@ -40,6 +40,27 @@ config PCI_STUB | |||
40 | 40 | ||
41 | When in doubt, say N. | 41 | When in doubt, say N. |
42 | 42 | ||
43 | config XEN_PCIDEV_FRONTEND | ||
44 | tristate "Xen PCI Frontend" | ||
45 | depends on PCI && X86 && XEN | ||
46 | select HOTPLUG | ||
47 | select PCI_XEN | ||
48 | default y | ||
49 | help | ||
50 | The PCI device frontend driver allows the kernel to import arbitrary | ||
51 | PCI devices from a PCI backend to support PCI driver domains. | ||
52 | |||
53 | config XEN_PCIDEV_FE_DEBUG | ||
54 | bool "Xen PCI Frontend debugging" | ||
55 | depends on XEN_PCIDEV_FRONTEND && PCI_DEBUG | ||
56 | help | ||
57 | Say Y here if you want the Xen PCI frontend to produce a bunch of debug | ||
58 | messages to the system log. Select this if you are having a | ||
59 | problem with Xen PCI frontend support and want to see more of what is | ||
60 | going on. | ||
61 | |||
62 | When in doubt, say N. | ||
63 | |||
43 | config HT_IRQ | 64 | config HT_IRQ |
44 | bool "Interrupts on hypertransport devices" | 65 | bool "Interrupts on hypertransport devices" |
45 | default y | 66 | default y |
diff --git a/drivers/pci/Makefile b/drivers/pci/Makefile index dcd7ace9221e..f01e344cf4bd 100644 --- a/drivers/pci/Makefile +++ b/drivers/pci/Makefile | |||
@@ -65,4 +65,6 @@ obj-$(CONFIG_PCI_SYSCALL) += syscall.o | |||
65 | 65 | ||
66 | obj-$(CONFIG_PCI_STUB) += pci-stub.o | 66 | obj-$(CONFIG_PCI_STUB) += pci-stub.o |
67 | 67 | ||
68 | obj-$(CONFIG_XEN_PCIDEV_FRONTEND) += xen-pcifront.o | ||
69 | |||
68 | ccflags-$(CONFIG_PCI_DEBUG) := -DDEBUG | 70 | ccflags-$(CONFIG_PCI_DEBUG) := -DDEBUG |
diff --git a/drivers/pci/bus.c b/drivers/pci/bus.c index 172bf26e0680..5624db8c9ad0 100644 --- a/drivers/pci/bus.c +++ b/drivers/pci/bus.c | |||
@@ -342,6 +342,7 @@ void pci_walk_bus(struct pci_bus *top, int (*cb)(struct pci_dev *, void *), | |||
342 | } | 342 | } |
343 | up_read(&pci_bus_sem); | 343 | up_read(&pci_bus_sem); |
344 | } | 344 | } |
345 | EXPORT_SYMBOL_GPL(pci_walk_bus); | ||
345 | 346 | ||
346 | EXPORT_SYMBOL(pci_bus_alloc_resource); | 347 | EXPORT_SYMBOL(pci_bus_alloc_resource); |
347 | EXPORT_SYMBOL_GPL(pci_bus_add_device); | 348 | EXPORT_SYMBOL_GPL(pci_bus_add_device); |
diff --git a/drivers/pci/msi.c b/drivers/pci/msi.c index 5fcf5aec680f..7c24dcef2989 100644 --- a/drivers/pci/msi.c +++ b/drivers/pci/msi.c | |||
@@ -35,7 +35,12 @@ int arch_msi_check_device(struct pci_dev *dev, int nvec, int type) | |||
35 | #endif | 35 | #endif |
36 | 36 | ||
37 | #ifndef arch_setup_msi_irqs | 37 | #ifndef arch_setup_msi_irqs |
38 | int arch_setup_msi_irqs(struct pci_dev *dev, int nvec, int type) | 38 | # define arch_setup_msi_irqs default_setup_msi_irqs |
39 | # define HAVE_DEFAULT_MSI_SETUP_IRQS | ||
40 | #endif | ||
41 | |||
42 | #ifdef HAVE_DEFAULT_MSI_SETUP_IRQS | ||
43 | int default_setup_msi_irqs(struct pci_dev *dev, int nvec, int type) | ||
39 | { | 44 | { |
40 | struct msi_desc *entry; | 45 | struct msi_desc *entry; |
41 | int ret; | 46 | int ret; |
@@ -60,7 +65,12 @@ int arch_setup_msi_irqs(struct pci_dev *dev, int nvec, int type) | |||
60 | #endif | 65 | #endif |
61 | 66 | ||
62 | #ifndef arch_teardown_msi_irqs | 67 | #ifndef arch_teardown_msi_irqs |
63 | void arch_teardown_msi_irqs(struct pci_dev *dev) | 68 | # define arch_teardown_msi_irqs default_teardown_msi_irqs |
69 | # define HAVE_DEFAULT_MSI_TEARDOWN_IRQS | ||
70 | #endif | ||
71 | |||
72 | #ifdef HAVE_DEFAULT_MSI_TEARDOWN_IRQS | ||
73 | void default_teardown_msi_irqs(struct pci_dev *dev) | ||
64 | { | 74 | { |
65 | struct msi_desc *entry; | 75 | struct msi_desc *entry; |
66 | 76 | ||
diff --git a/drivers/pci/xen-pcifront.c b/drivers/pci/xen-pcifront.c new file mode 100644 index 000000000000..a87c4985326e --- /dev/null +++ b/drivers/pci/xen-pcifront.c | |||
@@ -0,0 +1,1148 @@ | |||
1 | /* | ||
2 | * Xen PCI Frontend. | ||
3 | * | ||
4 | * Author: Ryan Wilson <hap9@epoch.ncsc.mil> | ||
5 | */ | ||
6 | #include <linux/module.h> | ||
7 | #include <linux/init.h> | ||
8 | #include <linux/mm.h> | ||
9 | #include <xen/xenbus.h> | ||
10 | #include <xen/events.h> | ||
11 | #include <xen/grant_table.h> | ||
12 | #include <xen/page.h> | ||
13 | #include <linux/spinlock.h> | ||
14 | #include <linux/pci.h> | ||
15 | #include <linux/msi.h> | ||
16 | #include <xen/xenbus.h> | ||
17 | #include <xen/interface/io/pciif.h> | ||
18 | #include <asm/xen/pci.h> | ||
19 | #include <linux/interrupt.h> | ||
20 | #include <asm/atomic.h> | ||
21 | #include <linux/workqueue.h> | ||
22 | #include <linux/bitops.h> | ||
23 | #include <linux/time.h> | ||
24 | |||
25 | #define INVALID_GRANT_REF (0) | ||
26 | #define INVALID_EVTCHN (-1) | ||
27 | |||
28 | struct pci_bus_entry { | ||
29 | struct list_head list; | ||
30 | struct pci_bus *bus; | ||
31 | }; | ||
32 | |||
33 | #define _PDEVB_op_active (0) | ||
34 | #define PDEVB_op_active (1 << (_PDEVB_op_active)) | ||
35 | |||
36 | struct pcifront_device { | ||
37 | struct xenbus_device *xdev; | ||
38 | struct list_head root_buses; | ||
39 | |||
40 | int evtchn; | ||
41 | int gnt_ref; | ||
42 | |||
43 | int irq; | ||
44 | |||
45 | /* Lock this when doing any operations in sh_info */ | ||
46 | spinlock_t sh_info_lock; | ||
47 | struct xen_pci_sharedinfo *sh_info; | ||
48 | struct work_struct op_work; | ||
49 | unsigned long flags; | ||
50 | |||
51 | }; | ||
52 | |||
53 | struct pcifront_sd { | ||
54 | int domain; | ||
55 | struct pcifront_device *pdev; | ||
56 | }; | ||
57 | |||
58 | static inline struct pcifront_device * | ||
59 | pcifront_get_pdev(struct pcifront_sd *sd) | ||
60 | { | ||
61 | return sd->pdev; | ||
62 | } | ||
63 | |||
64 | static inline void pcifront_init_sd(struct pcifront_sd *sd, | ||
65 | unsigned int domain, unsigned int bus, | ||
66 | struct pcifront_device *pdev) | ||
67 | { | ||
68 | sd->domain = domain; | ||
69 | sd->pdev = pdev; | ||
70 | } | ||
71 | |||
72 | static DEFINE_SPINLOCK(pcifront_dev_lock); | ||
73 | static struct pcifront_device *pcifront_dev; | ||
74 | |||
75 | static int verbose_request; | ||
76 | module_param(verbose_request, int, 0644); | ||
77 | |||
78 | static int errno_to_pcibios_err(int errno) | ||
79 | { | ||
80 | switch (errno) { | ||
81 | case XEN_PCI_ERR_success: | ||
82 | return PCIBIOS_SUCCESSFUL; | ||
83 | |||
84 | case XEN_PCI_ERR_dev_not_found: | ||
85 | return PCIBIOS_DEVICE_NOT_FOUND; | ||
86 | |||
87 | case XEN_PCI_ERR_invalid_offset: | ||
88 | case XEN_PCI_ERR_op_failed: | ||
89 | return PCIBIOS_BAD_REGISTER_NUMBER; | ||
90 | |||
91 | case XEN_PCI_ERR_not_implemented: | ||
92 | return PCIBIOS_FUNC_NOT_SUPPORTED; | ||
93 | |||
94 | case XEN_PCI_ERR_access_denied: | ||
95 | return PCIBIOS_SET_FAILED; | ||
96 | } | ||
97 | return errno; | ||
98 | } | ||
99 | |||
100 | static inline void schedule_pcifront_aer_op(struct pcifront_device *pdev) | ||
101 | { | ||
102 | if (test_bit(_XEN_PCIB_active, (unsigned long *)&pdev->sh_info->flags) | ||
103 | && !test_and_set_bit(_PDEVB_op_active, &pdev->flags)) { | ||
104 | dev_dbg(&pdev->xdev->dev, "schedule aer frontend job\n"); | ||
105 | schedule_work(&pdev->op_work); | ||
106 | } | ||
107 | } | ||
108 | |||
109 | static int do_pci_op(struct pcifront_device *pdev, struct xen_pci_op *op) | ||
110 | { | ||
111 | int err = 0; | ||
112 | struct xen_pci_op *active_op = &pdev->sh_info->op; | ||
113 | unsigned long irq_flags; | ||
114 | evtchn_port_t port = pdev->evtchn; | ||
115 | unsigned irq = pdev->irq; | ||
116 | s64 ns, ns_timeout; | ||
117 | struct timeval tv; | ||
118 | |||
119 | spin_lock_irqsave(&pdev->sh_info_lock, irq_flags); | ||
120 | |||
121 | memcpy(active_op, op, sizeof(struct xen_pci_op)); | ||
122 | |||
123 | /* Go */ | ||
124 | wmb(); | ||
125 | set_bit(_XEN_PCIF_active, (unsigned long *)&pdev->sh_info->flags); | ||
126 | notify_remote_via_evtchn(port); | ||
127 | |||
128 | /* | ||
129 | * We set a poll timeout of 3 seconds but give up on return after | ||
130 | * 2 seconds. It is better to time out too late rather than too early | ||
131 | * (in the latter case we end up continually re-executing poll() with a | ||
132 | * timeout in the past). 1s difference gives plenty of slack for error. | ||
133 | */ | ||
134 | do_gettimeofday(&tv); | ||
135 | ns_timeout = timeval_to_ns(&tv) + 2 * (s64)NSEC_PER_SEC; | ||
136 | |||
137 | xen_clear_irq_pending(irq); | ||
138 | |||
139 | while (test_bit(_XEN_PCIF_active, | ||
140 | (unsigned long *)&pdev->sh_info->flags)) { | ||
141 | xen_poll_irq_timeout(irq, jiffies + 3*HZ); | ||
142 | xen_clear_irq_pending(irq); | ||
143 | do_gettimeofday(&tv); | ||
144 | ns = timeval_to_ns(&tv); | ||
145 | if (ns > ns_timeout) { | ||
146 | dev_err(&pdev->xdev->dev, | ||
147 | "pciback not responding!!!\n"); | ||
148 | clear_bit(_XEN_PCIF_active, | ||
149 | (unsigned long *)&pdev->sh_info->flags); | ||
150 | err = XEN_PCI_ERR_dev_not_found; | ||
151 | goto out; | ||
152 | } | ||
153 | } | ||
154 | |||
155 | /* | ||
156 | * We might lose backend service request since we | ||
157 | * reuse same evtchn with pci_conf backend response. So re-schedule | ||
158 | * aer pcifront service. | ||
159 | */ | ||
160 | if (test_bit(_XEN_PCIB_active, | ||
161 | (unsigned long *)&pdev->sh_info->flags)) { | ||
162 | dev_err(&pdev->xdev->dev, | ||
163 | "schedule aer pcifront service\n"); | ||
164 | schedule_pcifront_aer_op(pdev); | ||
165 | } | ||
166 | |||
167 | memcpy(op, active_op, sizeof(struct xen_pci_op)); | ||
168 | |||
169 | err = op->err; | ||
170 | out: | ||
171 | spin_unlock_irqrestore(&pdev->sh_info_lock, irq_flags); | ||
172 | return err; | ||
173 | } | ||
174 | |||
175 | /* Access to this function is spinlocked in drivers/pci/access.c */ | ||
176 | static int pcifront_bus_read(struct pci_bus *bus, unsigned int devfn, | ||
177 | int where, int size, u32 *val) | ||
178 | { | ||
179 | int err = 0; | ||
180 | struct xen_pci_op op = { | ||
181 | .cmd = XEN_PCI_OP_conf_read, | ||
182 | .domain = pci_domain_nr(bus), | ||
183 | .bus = bus->number, | ||
184 | .devfn = devfn, | ||
185 | .offset = where, | ||
186 | .size = size, | ||
187 | }; | ||
188 | struct pcifront_sd *sd = bus->sysdata; | ||
189 | struct pcifront_device *pdev = pcifront_get_pdev(sd); | ||
190 | |||
191 | if (verbose_request) | ||
192 | dev_info(&pdev->xdev->dev, | ||
193 | "read dev=%04x:%02x:%02x.%01x - offset %x size %d\n", | ||
194 | pci_domain_nr(bus), bus->number, PCI_SLOT(devfn), | ||
195 | PCI_FUNC(devfn), where, size); | ||
196 | |||
197 | err = do_pci_op(pdev, &op); | ||
198 | |||
199 | if (likely(!err)) { | ||
200 | if (verbose_request) | ||
201 | dev_info(&pdev->xdev->dev, "read got back value %x\n", | ||
202 | op.value); | ||
203 | |||
204 | *val = op.value; | ||
205 | } else if (err == -ENODEV) { | ||
206 | /* No device here, pretend that it just returned 0 */ | ||
207 | err = 0; | ||
208 | *val = 0; | ||
209 | } | ||
210 | |||
211 | return errno_to_pcibios_err(err); | ||
212 | } | ||
213 | |||
214 | /* Access to this function is spinlocked in drivers/pci/access.c */ | ||
215 | static int pcifront_bus_write(struct pci_bus *bus, unsigned int devfn, | ||
216 | int where, int size, u32 val) | ||
217 | { | ||
218 | struct xen_pci_op op = { | ||
219 | .cmd = XEN_PCI_OP_conf_write, | ||
220 | .domain = pci_domain_nr(bus), | ||
221 | .bus = bus->number, | ||
222 | .devfn = devfn, | ||
223 | .offset = where, | ||
224 | .size = size, | ||
225 | .value = val, | ||
226 | }; | ||
227 | struct pcifront_sd *sd = bus->sysdata; | ||
228 | struct pcifront_device *pdev = pcifront_get_pdev(sd); | ||
229 | |||
230 | if (verbose_request) | ||
231 | dev_info(&pdev->xdev->dev, | ||
232 | "write dev=%04x:%02x:%02x.%01x - " | ||
233 | "offset %x size %d val %x\n", | ||
234 | pci_domain_nr(bus), bus->number, | ||
235 | PCI_SLOT(devfn), PCI_FUNC(devfn), where, size, val); | ||
236 | |||
237 | return errno_to_pcibios_err(do_pci_op(pdev, &op)); | ||
238 | } | ||
239 | |||
240 | struct pci_ops pcifront_bus_ops = { | ||
241 | .read = pcifront_bus_read, | ||
242 | .write = pcifront_bus_write, | ||
243 | }; | ||
244 | |||
245 | #ifdef CONFIG_PCI_MSI | ||
246 | static int pci_frontend_enable_msix(struct pci_dev *dev, | ||
247 | int **vector, int nvec) | ||
248 | { | ||
249 | int err; | ||
250 | int i; | ||
251 | struct xen_pci_op op = { | ||
252 | .cmd = XEN_PCI_OP_enable_msix, | ||
253 | .domain = pci_domain_nr(dev->bus), | ||
254 | .bus = dev->bus->number, | ||
255 | .devfn = dev->devfn, | ||
256 | .value = nvec, | ||
257 | }; | ||
258 | struct pcifront_sd *sd = dev->bus->sysdata; | ||
259 | struct pcifront_device *pdev = pcifront_get_pdev(sd); | ||
260 | struct msi_desc *entry; | ||
261 | |||
262 | if (nvec > SH_INFO_MAX_VEC) { | ||
263 | dev_err(&dev->dev, "too much vector for pci frontend: %x." | ||
264 | " Increase SH_INFO_MAX_VEC.\n", nvec); | ||
265 | return -EINVAL; | ||
266 | } | ||
267 | |||
268 | i = 0; | ||
269 | list_for_each_entry(entry, &dev->msi_list, list) { | ||
270 | op.msix_entries[i].entry = entry->msi_attrib.entry_nr; | ||
271 | /* Vector is useless at this point. */ | ||
272 | op.msix_entries[i].vector = -1; | ||
273 | i++; | ||
274 | } | ||
275 | |||
276 | err = do_pci_op(pdev, &op); | ||
277 | |||
278 | if (likely(!err)) { | ||
279 | if (likely(!op.value)) { | ||
280 | /* we get the result */ | ||
281 | for (i = 0; i < nvec; i++) | ||
282 | *(*vector+i) = op.msix_entries[i].vector; | ||
283 | return 0; | ||
284 | } else { | ||
285 | printk(KERN_DEBUG "enable msix get value %x\n", | ||
286 | op.value); | ||
287 | return op.value; | ||
288 | } | ||
289 | } else { | ||
290 | dev_err(&dev->dev, "enable msix get err %x\n", err); | ||
291 | return err; | ||
292 | } | ||
293 | } | ||
294 | |||
295 | static void pci_frontend_disable_msix(struct pci_dev *dev) | ||
296 | { | ||
297 | int err; | ||
298 | struct xen_pci_op op = { | ||
299 | .cmd = XEN_PCI_OP_disable_msix, | ||
300 | .domain = pci_domain_nr(dev->bus), | ||
301 | .bus = dev->bus->number, | ||
302 | .devfn = dev->devfn, | ||
303 | }; | ||
304 | struct pcifront_sd *sd = dev->bus->sysdata; | ||
305 | struct pcifront_device *pdev = pcifront_get_pdev(sd); | ||
306 | |||
307 | err = do_pci_op(pdev, &op); | ||
308 | |||
309 | /* What should do for error ? */ | ||
310 | if (err) | ||
311 | dev_err(&dev->dev, "pci_disable_msix get err %x\n", err); | ||
312 | } | ||
313 | |||
314 | static int pci_frontend_enable_msi(struct pci_dev *dev, int **vector) | ||
315 | { | ||
316 | int err; | ||
317 | struct xen_pci_op op = { | ||
318 | .cmd = XEN_PCI_OP_enable_msi, | ||
319 | .domain = pci_domain_nr(dev->bus), | ||
320 | .bus = dev->bus->number, | ||
321 | .devfn = dev->devfn, | ||
322 | }; | ||
323 | struct pcifront_sd *sd = dev->bus->sysdata; | ||
324 | struct pcifront_device *pdev = pcifront_get_pdev(sd); | ||
325 | |||
326 | err = do_pci_op(pdev, &op); | ||
327 | if (likely(!err)) { | ||
328 | *(*vector) = op.value; | ||
329 | } else { | ||
330 | dev_err(&dev->dev, "pci frontend enable msi failed for dev " | ||
331 | "%x:%x\n", op.bus, op.devfn); | ||
332 | err = -EINVAL; | ||
333 | } | ||
334 | return err; | ||
335 | } | ||
336 | |||
337 | static void pci_frontend_disable_msi(struct pci_dev *dev) | ||
338 | { | ||
339 | int err; | ||
340 | struct xen_pci_op op = { | ||
341 | .cmd = XEN_PCI_OP_disable_msi, | ||
342 | .domain = pci_domain_nr(dev->bus), | ||
343 | .bus = dev->bus->number, | ||
344 | .devfn = dev->devfn, | ||
345 | }; | ||
346 | struct pcifront_sd *sd = dev->bus->sysdata; | ||
347 | struct pcifront_device *pdev = pcifront_get_pdev(sd); | ||
348 | |||
349 | err = do_pci_op(pdev, &op); | ||
350 | if (err == XEN_PCI_ERR_dev_not_found) { | ||
351 | /* XXX No response from backend, what shall we do? */ | ||
352 | printk(KERN_DEBUG "get no response from backend for disable MSI\n"); | ||
353 | return; | ||
354 | } | ||
355 | if (err) | ||
356 | /* how can pciback notify us fail? */ | ||
357 | printk(KERN_DEBUG "get fake response frombackend\n"); | ||
358 | } | ||
359 | |||
360 | static struct xen_pci_frontend_ops pci_frontend_ops = { | ||
361 | .enable_msi = pci_frontend_enable_msi, | ||
362 | .disable_msi = pci_frontend_disable_msi, | ||
363 | .enable_msix = pci_frontend_enable_msix, | ||
364 | .disable_msix = pci_frontend_disable_msix, | ||
365 | }; | ||
366 | |||
367 | static void pci_frontend_registrar(int enable) | ||
368 | { | ||
369 | if (enable) | ||
370 | xen_pci_frontend = &pci_frontend_ops; | ||
371 | else | ||
372 | xen_pci_frontend = NULL; | ||
373 | }; | ||
374 | #else | ||
375 | static inline void pci_frontend_registrar(int enable) { }; | ||
376 | #endif /* CONFIG_PCI_MSI */ | ||
377 | |||
378 | /* Claim resources for the PCI frontend as-is, backend won't allow changes */ | ||
379 | static int pcifront_claim_resource(struct pci_dev *dev, void *data) | ||
380 | { | ||
381 | struct pcifront_device *pdev = data; | ||
382 | int i; | ||
383 | struct resource *r; | ||
384 | |||
385 | for (i = 0; i < PCI_NUM_RESOURCES; i++) { | ||
386 | r = &dev->resource[i]; | ||
387 | |||
388 | if (!r->parent && r->start && r->flags) { | ||
389 | dev_info(&pdev->xdev->dev, "claiming resource %s/%d\n", | ||
390 | pci_name(dev), i); | ||
391 | if (pci_claim_resource(dev, i)) { | ||
392 | dev_err(&pdev->xdev->dev, "Could not claim " | ||
393 | "resource %s/%d! Device offline. Try " | ||
394 | "giving less than 4GB to domain.\n", | ||
395 | pci_name(dev), i); | ||
396 | } | ||
397 | } | ||
398 | } | ||
399 | |||
400 | return 0; | ||
401 | } | ||
402 | |||
403 | static int __devinit pcifront_scan_bus(struct pcifront_device *pdev, | ||
404 | unsigned int domain, unsigned int bus, | ||
405 | struct pci_bus *b) | ||
406 | { | ||
407 | struct pci_dev *d; | ||
408 | unsigned int devfn; | ||
409 | |||
410 | /* Scan the bus for functions and add. | ||
411 | * We omit handling of PCI bridge attachment because pciback prevents | ||
412 | * bridges from being exported. | ||
413 | */ | ||
414 | for (devfn = 0; devfn < 0x100; devfn++) { | ||
415 | d = pci_get_slot(b, devfn); | ||
416 | if (d) { | ||
417 | /* Device is already known. */ | ||
418 | pci_dev_put(d); | ||
419 | continue; | ||
420 | } | ||
421 | |||
422 | d = pci_scan_single_device(b, devfn); | ||
423 | if (d) | ||
424 | dev_info(&pdev->xdev->dev, "New device on " | ||
425 | "%04x:%02x:%02x.%02x found.\n", domain, bus, | ||
426 | PCI_SLOT(devfn), PCI_FUNC(devfn)); | ||
427 | } | ||
428 | |||
429 | return 0; | ||
430 | } | ||
431 | |||
432 | static int __devinit pcifront_scan_root(struct pcifront_device *pdev, | ||
433 | unsigned int domain, unsigned int bus) | ||
434 | { | ||
435 | struct pci_bus *b; | ||
436 | struct pcifront_sd *sd = NULL; | ||
437 | struct pci_bus_entry *bus_entry = NULL; | ||
438 | int err = 0; | ||
439 | |||
440 | #ifndef CONFIG_PCI_DOMAINS | ||
441 | if (domain != 0) { | ||
442 | dev_err(&pdev->xdev->dev, | ||
443 | "PCI Root in non-zero PCI Domain! domain=%d\n", domain); | ||
444 | dev_err(&pdev->xdev->dev, | ||
445 | "Please compile with CONFIG_PCI_DOMAINS\n"); | ||
446 | err = -EINVAL; | ||
447 | goto err_out; | ||
448 | } | ||
449 | #endif | ||
450 | |||
451 | dev_info(&pdev->xdev->dev, "Creating PCI Frontend Bus %04x:%02x\n", | ||
452 | domain, bus); | ||
453 | |||
454 | bus_entry = kmalloc(sizeof(*bus_entry), GFP_KERNEL); | ||
455 | sd = kmalloc(sizeof(*sd), GFP_KERNEL); | ||
456 | if (!bus_entry || !sd) { | ||
457 | err = -ENOMEM; | ||
458 | goto err_out; | ||
459 | } | ||
460 | pcifront_init_sd(sd, domain, bus, pdev); | ||
461 | |||
462 | b = pci_scan_bus_parented(&pdev->xdev->dev, bus, | ||
463 | &pcifront_bus_ops, sd); | ||
464 | if (!b) { | ||
465 | dev_err(&pdev->xdev->dev, | ||
466 | "Error creating PCI Frontend Bus!\n"); | ||
467 | err = -ENOMEM; | ||
468 | goto err_out; | ||
469 | } | ||
470 | |||
471 | bus_entry->bus = b; | ||
472 | |||
473 | list_add(&bus_entry->list, &pdev->root_buses); | ||
474 | |||
475 | /* pci_scan_bus_parented skips devices which do not have a have | ||
476 | * devfn==0. The pcifront_scan_bus enumerates all devfn. */ | ||
477 | err = pcifront_scan_bus(pdev, domain, bus, b); | ||
478 | |||
479 | /* Claim resources before going "live" with our devices */ | ||
480 | pci_walk_bus(b, pcifront_claim_resource, pdev); | ||
481 | |||
482 | /* Create SysFS and notify udev of the devices. Aka: "going live" */ | ||
483 | pci_bus_add_devices(b); | ||
484 | |||
485 | return err; | ||
486 | |||
487 | err_out: | ||
488 | kfree(bus_entry); | ||
489 | kfree(sd); | ||
490 | |||
491 | return err; | ||
492 | } | ||
493 | |||
494 | static int __devinit pcifront_rescan_root(struct pcifront_device *pdev, | ||
495 | unsigned int domain, unsigned int bus) | ||
496 | { | ||
497 | int err; | ||
498 | struct pci_bus *b; | ||
499 | |||
500 | #ifndef CONFIG_PCI_DOMAINS | ||
501 | if (domain != 0) { | ||
502 | dev_err(&pdev->xdev->dev, | ||
503 | "PCI Root in non-zero PCI Domain! domain=%d\n", domain); | ||
504 | dev_err(&pdev->xdev->dev, | ||
505 | "Please compile with CONFIG_PCI_DOMAINS\n"); | ||
506 | return -EINVAL; | ||
507 | } | ||
508 | #endif | ||
509 | |||
510 | dev_info(&pdev->xdev->dev, "Rescanning PCI Frontend Bus %04x:%02x\n", | ||
511 | domain, bus); | ||
512 | |||
513 | b = pci_find_bus(domain, bus); | ||
514 | if (!b) | ||
515 | /* If the bus is unknown, create it. */ | ||
516 | return pcifront_scan_root(pdev, domain, bus); | ||
517 | |||
518 | err = pcifront_scan_bus(pdev, domain, bus, b); | ||
519 | |||
520 | /* Claim resources before going "live" with our devices */ | ||
521 | pci_walk_bus(b, pcifront_claim_resource, pdev); | ||
522 | |||
523 | /* Create SysFS and notify udev of the devices. Aka: "going live" */ | ||
524 | pci_bus_add_devices(b); | ||
525 | |||
526 | return err; | ||
527 | } | ||
528 | |||
529 | static void free_root_bus_devs(struct pci_bus *bus) | ||
530 | { | ||
531 | struct pci_dev *dev; | ||
532 | |||
533 | while (!list_empty(&bus->devices)) { | ||
534 | dev = container_of(bus->devices.next, struct pci_dev, | ||
535 | bus_list); | ||
536 | dev_dbg(&dev->dev, "removing device\n"); | ||
537 | pci_remove_bus_device(dev); | ||
538 | } | ||
539 | } | ||
540 | |||
541 | static void pcifront_free_roots(struct pcifront_device *pdev) | ||
542 | { | ||
543 | struct pci_bus_entry *bus_entry, *t; | ||
544 | |||
545 | dev_dbg(&pdev->xdev->dev, "cleaning up root buses\n"); | ||
546 | |||
547 | list_for_each_entry_safe(bus_entry, t, &pdev->root_buses, list) { | ||
548 | list_del(&bus_entry->list); | ||
549 | |||
550 | free_root_bus_devs(bus_entry->bus); | ||
551 | |||
552 | kfree(bus_entry->bus->sysdata); | ||
553 | |||
554 | device_unregister(bus_entry->bus->bridge); | ||
555 | pci_remove_bus(bus_entry->bus); | ||
556 | |||
557 | kfree(bus_entry); | ||
558 | } | ||
559 | } | ||
560 | |||
561 | static pci_ers_result_t pcifront_common_process(int cmd, | ||
562 | struct pcifront_device *pdev, | ||
563 | pci_channel_state_t state) | ||
564 | { | ||
565 | pci_ers_result_t result; | ||
566 | struct pci_driver *pdrv; | ||
567 | int bus = pdev->sh_info->aer_op.bus; | ||
568 | int devfn = pdev->sh_info->aer_op.devfn; | ||
569 | struct pci_dev *pcidev; | ||
570 | int flag = 0; | ||
571 | |||
572 | dev_dbg(&pdev->xdev->dev, | ||
573 | "pcifront AER process: cmd %x (bus:%x, devfn%x)", | ||
574 | cmd, bus, devfn); | ||
575 | result = PCI_ERS_RESULT_NONE; | ||
576 | |||
577 | pcidev = pci_get_bus_and_slot(bus, devfn); | ||
578 | if (!pcidev || !pcidev->driver) { | ||
579 | dev_err(&pcidev->dev, | ||
580 | "device or driver is NULL\n"); | ||
581 | return result; | ||
582 | } | ||
583 | pdrv = pcidev->driver; | ||
584 | |||
585 | if (get_driver(&pdrv->driver)) { | ||
586 | if (pdrv->err_handler && pdrv->err_handler->error_detected) { | ||
587 | dev_dbg(&pcidev->dev, | ||
588 | "trying to call AER service\n"); | ||
589 | if (pcidev) { | ||
590 | flag = 1; | ||
591 | switch (cmd) { | ||
592 | case XEN_PCI_OP_aer_detected: | ||
593 | result = pdrv->err_handler-> | ||
594 | error_detected(pcidev, state); | ||
595 | break; | ||
596 | case XEN_PCI_OP_aer_mmio: | ||
597 | result = pdrv->err_handler-> | ||
598 | mmio_enabled(pcidev); | ||
599 | break; | ||
600 | case XEN_PCI_OP_aer_slotreset: | ||
601 | result = pdrv->err_handler-> | ||
602 | slot_reset(pcidev); | ||
603 | break; | ||
604 | case XEN_PCI_OP_aer_resume: | ||
605 | pdrv->err_handler->resume(pcidev); | ||
606 | break; | ||
607 | default: | ||
608 | dev_err(&pdev->xdev->dev, | ||
609 | "bad request in aer recovery " | ||
610 | "operation!\n"); | ||
611 | |||
612 | } | ||
613 | } | ||
614 | } | ||
615 | put_driver(&pdrv->driver); | ||
616 | } | ||
617 | if (!flag) | ||
618 | result = PCI_ERS_RESULT_NONE; | ||
619 | |||
620 | return result; | ||
621 | } | ||
622 | |||
623 | |||
624 | static void pcifront_do_aer(struct work_struct *data) | ||
625 | { | ||
626 | struct pcifront_device *pdev = | ||
627 | container_of(data, struct pcifront_device, op_work); | ||
628 | int cmd = pdev->sh_info->aer_op.cmd; | ||
629 | pci_channel_state_t state = | ||
630 | (pci_channel_state_t)pdev->sh_info->aer_op.err; | ||
631 | |||
632 | /*If a pci_conf op is in progress, | ||
633 | we have to wait until it is done before service aer op*/ | ||
634 | dev_dbg(&pdev->xdev->dev, | ||
635 | "pcifront service aer bus %x devfn %x\n", | ||
636 | pdev->sh_info->aer_op.bus, pdev->sh_info->aer_op.devfn); | ||
637 | |||
638 | pdev->sh_info->aer_op.err = pcifront_common_process(cmd, pdev, state); | ||
639 | |||
640 | /* Post the operation to the guest. */ | ||
641 | wmb(); | ||
642 | clear_bit(_XEN_PCIB_active, (unsigned long *)&pdev->sh_info->flags); | ||
643 | notify_remote_via_evtchn(pdev->evtchn); | ||
644 | |||
645 | /*in case of we lost an aer request in four lines time_window*/ | ||
646 | smp_mb__before_clear_bit(); | ||
647 | clear_bit(_PDEVB_op_active, &pdev->flags); | ||
648 | smp_mb__after_clear_bit(); | ||
649 | |||
650 | schedule_pcifront_aer_op(pdev); | ||
651 | |||
652 | } | ||
653 | |||
654 | static irqreturn_t pcifront_handler_aer(int irq, void *dev) | ||
655 | { | ||
656 | struct pcifront_device *pdev = dev; | ||
657 | schedule_pcifront_aer_op(pdev); | ||
658 | return IRQ_HANDLED; | ||
659 | } | ||
660 | static int pcifront_connect(struct pcifront_device *pdev) | ||
661 | { | ||
662 | int err = 0; | ||
663 | |||
664 | spin_lock(&pcifront_dev_lock); | ||
665 | |||
666 | if (!pcifront_dev) { | ||
667 | dev_info(&pdev->xdev->dev, "Installing PCI frontend\n"); | ||
668 | pcifront_dev = pdev; | ||
669 | } else { | ||
670 | dev_err(&pdev->xdev->dev, "PCI frontend already installed!\n"); | ||
671 | err = -EEXIST; | ||
672 | } | ||
673 | |||
674 | spin_unlock(&pcifront_dev_lock); | ||
675 | |||
676 | return err; | ||
677 | } | ||
678 | |||
679 | static void pcifront_disconnect(struct pcifront_device *pdev) | ||
680 | { | ||
681 | spin_lock(&pcifront_dev_lock); | ||
682 | |||
683 | if (pdev == pcifront_dev) { | ||
684 | dev_info(&pdev->xdev->dev, | ||
685 | "Disconnecting PCI Frontend Buses\n"); | ||
686 | pcifront_dev = NULL; | ||
687 | } | ||
688 | |||
689 | spin_unlock(&pcifront_dev_lock); | ||
690 | } | ||
691 | static struct pcifront_device *alloc_pdev(struct xenbus_device *xdev) | ||
692 | { | ||
693 | struct pcifront_device *pdev; | ||
694 | |||
695 | pdev = kzalloc(sizeof(struct pcifront_device), GFP_KERNEL); | ||
696 | if (pdev == NULL) | ||
697 | goto out; | ||
698 | |||
699 | pdev->sh_info = | ||
700 | (struct xen_pci_sharedinfo *)__get_free_page(GFP_KERNEL); | ||
701 | if (pdev->sh_info == NULL) { | ||
702 | kfree(pdev); | ||
703 | pdev = NULL; | ||
704 | goto out; | ||
705 | } | ||
706 | pdev->sh_info->flags = 0; | ||
707 | |||
708 | /*Flag for registering PV AER handler*/ | ||
709 | set_bit(_XEN_PCIB_AERHANDLER, (void *)&pdev->sh_info->flags); | ||
710 | |||
711 | dev_set_drvdata(&xdev->dev, pdev); | ||
712 | pdev->xdev = xdev; | ||
713 | |||
714 | INIT_LIST_HEAD(&pdev->root_buses); | ||
715 | |||
716 | spin_lock_init(&pdev->sh_info_lock); | ||
717 | |||
718 | pdev->evtchn = INVALID_EVTCHN; | ||
719 | pdev->gnt_ref = INVALID_GRANT_REF; | ||
720 | pdev->irq = -1; | ||
721 | |||
722 | INIT_WORK(&pdev->op_work, pcifront_do_aer); | ||
723 | |||
724 | dev_dbg(&xdev->dev, "Allocated pdev @ 0x%p pdev->sh_info @ 0x%p\n", | ||
725 | pdev, pdev->sh_info); | ||
726 | out: | ||
727 | return pdev; | ||
728 | } | ||
729 | |||
730 | static void free_pdev(struct pcifront_device *pdev) | ||
731 | { | ||
732 | dev_dbg(&pdev->xdev->dev, "freeing pdev @ 0x%p\n", pdev); | ||
733 | |||
734 | pcifront_free_roots(pdev); | ||
735 | |||
736 | /*For PCIE_AER error handling job*/ | ||
737 | flush_scheduled_work(); | ||
738 | |||
739 | if (pdev->irq >= 0) | ||
740 | unbind_from_irqhandler(pdev->irq, pdev); | ||
741 | |||
742 | if (pdev->evtchn != INVALID_EVTCHN) | ||
743 | xenbus_free_evtchn(pdev->xdev, pdev->evtchn); | ||
744 | |||
745 | if (pdev->gnt_ref != INVALID_GRANT_REF) | ||
746 | gnttab_end_foreign_access(pdev->gnt_ref, 0 /* r/w page */, | ||
747 | (unsigned long)pdev->sh_info); | ||
748 | else | ||
749 | free_page((unsigned long)pdev->sh_info); | ||
750 | |||
751 | dev_set_drvdata(&pdev->xdev->dev, NULL); | ||
752 | |||
753 | kfree(pdev); | ||
754 | } | ||
755 | |||
756 | static int pcifront_publish_info(struct pcifront_device *pdev) | ||
757 | { | ||
758 | int err = 0; | ||
759 | struct xenbus_transaction trans; | ||
760 | |||
761 | err = xenbus_grant_ring(pdev->xdev, virt_to_mfn(pdev->sh_info)); | ||
762 | if (err < 0) | ||
763 | goto out; | ||
764 | |||
765 | pdev->gnt_ref = err; | ||
766 | |||
767 | err = xenbus_alloc_evtchn(pdev->xdev, &pdev->evtchn); | ||
768 | if (err) | ||
769 | goto out; | ||
770 | |||
771 | err = bind_evtchn_to_irqhandler(pdev->evtchn, pcifront_handler_aer, | ||
772 | 0, "pcifront", pdev); | ||
773 | |||
774 | if (err < 0) | ||
775 | return err; | ||
776 | |||
777 | pdev->irq = err; | ||
778 | |||
779 | do_publish: | ||
780 | err = xenbus_transaction_start(&trans); | ||
781 | if (err) { | ||
782 | xenbus_dev_fatal(pdev->xdev, err, | ||
783 | "Error writing configuration for backend " | ||
784 | "(start transaction)"); | ||
785 | goto out; | ||
786 | } | ||
787 | |||
788 | err = xenbus_printf(trans, pdev->xdev->nodename, | ||
789 | "pci-op-ref", "%u", pdev->gnt_ref); | ||
790 | if (!err) | ||
791 | err = xenbus_printf(trans, pdev->xdev->nodename, | ||
792 | "event-channel", "%u", pdev->evtchn); | ||
793 | if (!err) | ||
794 | err = xenbus_printf(trans, pdev->xdev->nodename, | ||
795 | "magic", XEN_PCI_MAGIC); | ||
796 | |||
797 | if (err) { | ||
798 | xenbus_transaction_end(trans, 1); | ||
799 | xenbus_dev_fatal(pdev->xdev, err, | ||
800 | "Error writing configuration for backend"); | ||
801 | goto out; | ||
802 | } else { | ||
803 | err = xenbus_transaction_end(trans, 0); | ||
804 | if (err == -EAGAIN) | ||
805 | goto do_publish; | ||
806 | else if (err) { | ||
807 | xenbus_dev_fatal(pdev->xdev, err, | ||
808 | "Error completing transaction " | ||
809 | "for backend"); | ||
810 | goto out; | ||
811 | } | ||
812 | } | ||
813 | |||
814 | xenbus_switch_state(pdev->xdev, XenbusStateInitialised); | ||
815 | |||
816 | dev_dbg(&pdev->xdev->dev, "publishing successful!\n"); | ||
817 | |||
818 | out: | ||
819 | return err; | ||
820 | } | ||
821 | |||
822 | static int __devinit pcifront_try_connect(struct pcifront_device *pdev) | ||
823 | { | ||
824 | int err = -EFAULT; | ||
825 | int i, num_roots, len; | ||
826 | char str[64]; | ||
827 | unsigned int domain, bus; | ||
828 | |||
829 | |||
830 | /* Only connect once */ | ||
831 | if (xenbus_read_driver_state(pdev->xdev->nodename) != | ||
832 | XenbusStateInitialised) | ||
833 | goto out; | ||
834 | |||
835 | err = pcifront_connect(pdev); | ||
836 | if (err) { | ||
837 | xenbus_dev_fatal(pdev->xdev, err, | ||
838 | "Error connecting PCI Frontend"); | ||
839 | goto out; | ||
840 | } | ||
841 | |||
842 | err = xenbus_scanf(XBT_NIL, pdev->xdev->otherend, | ||
843 | "root_num", "%d", &num_roots); | ||
844 | if (err == -ENOENT) { | ||
845 | xenbus_dev_error(pdev->xdev, err, | ||
846 | "No PCI Roots found, trying 0000:00"); | ||
847 | err = pcifront_scan_root(pdev, 0, 0); | ||
848 | num_roots = 0; | ||
849 | } else if (err != 1) { | ||
850 | if (err == 0) | ||
851 | err = -EINVAL; | ||
852 | xenbus_dev_fatal(pdev->xdev, err, | ||
853 | "Error reading number of PCI roots"); | ||
854 | goto out; | ||
855 | } | ||
856 | |||
857 | for (i = 0; i < num_roots; i++) { | ||
858 | len = snprintf(str, sizeof(str), "root-%d", i); | ||
859 | if (unlikely(len >= (sizeof(str) - 1))) { | ||
860 | err = -ENOMEM; | ||
861 | goto out; | ||
862 | } | ||
863 | |||
864 | err = xenbus_scanf(XBT_NIL, pdev->xdev->otherend, str, | ||
865 | "%x:%x", &domain, &bus); | ||
866 | if (err != 2) { | ||
867 | if (err >= 0) | ||
868 | err = -EINVAL; | ||
869 | xenbus_dev_fatal(pdev->xdev, err, | ||
870 | "Error reading PCI root %d", i); | ||
871 | goto out; | ||
872 | } | ||
873 | |||
874 | err = pcifront_scan_root(pdev, domain, bus); | ||
875 | if (err) { | ||
876 | xenbus_dev_fatal(pdev->xdev, err, | ||
877 | "Error scanning PCI root %04x:%02x", | ||
878 | domain, bus); | ||
879 | goto out; | ||
880 | } | ||
881 | } | ||
882 | |||
883 | err = xenbus_switch_state(pdev->xdev, XenbusStateConnected); | ||
884 | |||
885 | out: | ||
886 | return err; | ||
887 | } | ||
888 | |||
889 | static int pcifront_try_disconnect(struct pcifront_device *pdev) | ||
890 | { | ||
891 | int err = 0; | ||
892 | enum xenbus_state prev_state; | ||
893 | |||
894 | |||
895 | prev_state = xenbus_read_driver_state(pdev->xdev->nodename); | ||
896 | |||
897 | if (prev_state >= XenbusStateClosing) | ||
898 | goto out; | ||
899 | |||
900 | if (prev_state == XenbusStateConnected) { | ||
901 | pcifront_free_roots(pdev); | ||
902 | pcifront_disconnect(pdev); | ||
903 | } | ||
904 | |||
905 | err = xenbus_switch_state(pdev->xdev, XenbusStateClosed); | ||
906 | |||
907 | out: | ||
908 | |||
909 | return err; | ||
910 | } | ||
911 | |||
912 | static int __devinit pcifront_attach_devices(struct pcifront_device *pdev) | ||
913 | { | ||
914 | int err = -EFAULT; | ||
915 | int i, num_roots, len; | ||
916 | unsigned int domain, bus; | ||
917 | char str[64]; | ||
918 | |||
919 | if (xenbus_read_driver_state(pdev->xdev->nodename) != | ||
920 | XenbusStateReconfiguring) | ||
921 | goto out; | ||
922 | |||
923 | err = xenbus_scanf(XBT_NIL, pdev->xdev->otherend, | ||
924 | "root_num", "%d", &num_roots); | ||
925 | if (err == -ENOENT) { | ||
926 | xenbus_dev_error(pdev->xdev, err, | ||
927 | "No PCI Roots found, trying 0000:00"); | ||
928 | err = pcifront_rescan_root(pdev, 0, 0); | ||
929 | num_roots = 0; | ||
930 | } else if (err != 1) { | ||
931 | if (err == 0) | ||
932 | err = -EINVAL; | ||
933 | xenbus_dev_fatal(pdev->xdev, err, | ||
934 | "Error reading number of PCI roots"); | ||
935 | goto out; | ||
936 | } | ||
937 | |||
938 | for (i = 0; i < num_roots; i++) { | ||
939 | len = snprintf(str, sizeof(str), "root-%d", i); | ||
940 | if (unlikely(len >= (sizeof(str) - 1))) { | ||
941 | err = -ENOMEM; | ||
942 | goto out; | ||
943 | } | ||
944 | |||
945 | err = xenbus_scanf(XBT_NIL, pdev->xdev->otherend, str, | ||
946 | "%x:%x", &domain, &bus); | ||
947 | if (err != 2) { | ||
948 | if (err >= 0) | ||
949 | err = -EINVAL; | ||
950 | xenbus_dev_fatal(pdev->xdev, err, | ||
951 | "Error reading PCI root %d", i); | ||
952 | goto out; | ||
953 | } | ||
954 | |||
955 | err = pcifront_rescan_root(pdev, domain, bus); | ||
956 | if (err) { | ||
957 | xenbus_dev_fatal(pdev->xdev, err, | ||
958 | "Error scanning PCI root %04x:%02x", | ||
959 | domain, bus); | ||
960 | goto out; | ||
961 | } | ||
962 | } | ||
963 | |||
964 | xenbus_switch_state(pdev->xdev, XenbusStateConnected); | ||
965 | |||
966 | out: | ||
967 | return err; | ||
968 | } | ||
969 | |||
970 | static int pcifront_detach_devices(struct pcifront_device *pdev) | ||
971 | { | ||
972 | int err = 0; | ||
973 | int i, num_devs; | ||
974 | unsigned int domain, bus, slot, func; | ||
975 | struct pci_bus *pci_bus; | ||
976 | struct pci_dev *pci_dev; | ||
977 | char str[64]; | ||
978 | |||
979 | if (xenbus_read_driver_state(pdev->xdev->nodename) != | ||
980 | XenbusStateConnected) | ||
981 | goto out; | ||
982 | |||
983 | err = xenbus_scanf(XBT_NIL, pdev->xdev->otherend, "num_devs", "%d", | ||
984 | &num_devs); | ||
985 | if (err != 1) { | ||
986 | if (err >= 0) | ||
987 | err = -EINVAL; | ||
988 | xenbus_dev_fatal(pdev->xdev, err, | ||
989 | "Error reading number of PCI devices"); | ||
990 | goto out; | ||
991 | } | ||
992 | |||
993 | /* Find devices being detached and remove them. */ | ||
994 | for (i = 0; i < num_devs; i++) { | ||
995 | int l, state; | ||
996 | l = snprintf(str, sizeof(str), "state-%d", i); | ||
997 | if (unlikely(l >= (sizeof(str) - 1))) { | ||
998 | err = -ENOMEM; | ||
999 | goto out; | ||
1000 | } | ||
1001 | err = xenbus_scanf(XBT_NIL, pdev->xdev->otherend, str, "%d", | ||
1002 | &state); | ||
1003 | if (err != 1) | ||
1004 | state = XenbusStateUnknown; | ||
1005 | |||
1006 | if (state != XenbusStateClosing) | ||
1007 | continue; | ||
1008 | |||
1009 | /* Remove device. */ | ||
1010 | l = snprintf(str, sizeof(str), "vdev-%d", i); | ||
1011 | if (unlikely(l >= (sizeof(str) - 1))) { | ||
1012 | err = -ENOMEM; | ||
1013 | goto out; | ||
1014 | } | ||
1015 | err = xenbus_scanf(XBT_NIL, pdev->xdev->otherend, str, | ||
1016 | "%x:%x:%x.%x", &domain, &bus, &slot, &func); | ||
1017 | if (err != 4) { | ||
1018 | if (err >= 0) | ||
1019 | err = -EINVAL; | ||
1020 | xenbus_dev_fatal(pdev->xdev, err, | ||
1021 | "Error reading PCI device %d", i); | ||
1022 | goto out; | ||
1023 | } | ||
1024 | |||
1025 | pci_bus = pci_find_bus(domain, bus); | ||
1026 | if (!pci_bus) { | ||
1027 | dev_dbg(&pdev->xdev->dev, "Cannot get bus %04x:%02x\n", | ||
1028 | domain, bus); | ||
1029 | continue; | ||
1030 | } | ||
1031 | pci_dev = pci_get_slot(pci_bus, PCI_DEVFN(slot, func)); | ||
1032 | if (!pci_dev) { | ||
1033 | dev_dbg(&pdev->xdev->dev, | ||
1034 | "Cannot get PCI device %04x:%02x:%02x.%02x\n", | ||
1035 | domain, bus, slot, func); | ||
1036 | continue; | ||
1037 | } | ||
1038 | pci_remove_bus_device(pci_dev); | ||
1039 | pci_dev_put(pci_dev); | ||
1040 | |||
1041 | dev_dbg(&pdev->xdev->dev, | ||
1042 | "PCI device %04x:%02x:%02x.%02x removed.\n", | ||
1043 | domain, bus, slot, func); | ||
1044 | } | ||
1045 | |||
1046 | err = xenbus_switch_state(pdev->xdev, XenbusStateReconfiguring); | ||
1047 | |||
1048 | out: | ||
1049 | return err; | ||
1050 | } | ||
1051 | |||
1052 | static void __init_refok pcifront_backend_changed(struct xenbus_device *xdev, | ||
1053 | enum xenbus_state be_state) | ||
1054 | { | ||
1055 | struct pcifront_device *pdev = dev_get_drvdata(&xdev->dev); | ||
1056 | |||
1057 | switch (be_state) { | ||
1058 | case XenbusStateUnknown: | ||
1059 | case XenbusStateInitialising: | ||
1060 | case XenbusStateInitWait: | ||
1061 | case XenbusStateInitialised: | ||
1062 | case XenbusStateClosed: | ||
1063 | break; | ||
1064 | |||
1065 | case XenbusStateConnected: | ||
1066 | pcifront_try_connect(pdev); | ||
1067 | break; | ||
1068 | |||
1069 | case XenbusStateClosing: | ||
1070 | dev_warn(&xdev->dev, "backend going away!\n"); | ||
1071 | pcifront_try_disconnect(pdev); | ||
1072 | break; | ||
1073 | |||
1074 | case XenbusStateReconfiguring: | ||
1075 | pcifront_detach_devices(pdev); | ||
1076 | break; | ||
1077 | |||
1078 | case XenbusStateReconfigured: | ||
1079 | pcifront_attach_devices(pdev); | ||
1080 | break; | ||
1081 | } | ||
1082 | } | ||
1083 | |||
1084 | static int pcifront_xenbus_probe(struct xenbus_device *xdev, | ||
1085 | const struct xenbus_device_id *id) | ||
1086 | { | ||
1087 | int err = 0; | ||
1088 | struct pcifront_device *pdev = alloc_pdev(xdev); | ||
1089 | |||
1090 | if (pdev == NULL) { | ||
1091 | err = -ENOMEM; | ||
1092 | xenbus_dev_fatal(xdev, err, | ||
1093 | "Error allocating pcifront_device struct"); | ||
1094 | goto out; | ||
1095 | } | ||
1096 | |||
1097 | err = pcifront_publish_info(pdev); | ||
1098 | if (err) | ||
1099 | free_pdev(pdev); | ||
1100 | |||
1101 | out: | ||
1102 | return err; | ||
1103 | } | ||
1104 | |||
1105 | static int pcifront_xenbus_remove(struct xenbus_device *xdev) | ||
1106 | { | ||
1107 | struct pcifront_device *pdev = dev_get_drvdata(&xdev->dev); | ||
1108 | if (pdev) | ||
1109 | free_pdev(pdev); | ||
1110 | |||
1111 | return 0; | ||
1112 | } | ||
1113 | |||
1114 | static const struct xenbus_device_id xenpci_ids[] = { | ||
1115 | {"pci"}, | ||
1116 | {""}, | ||
1117 | }; | ||
1118 | |||
1119 | static struct xenbus_driver xenbus_pcifront_driver = { | ||
1120 | .name = "pcifront", | ||
1121 | .owner = THIS_MODULE, | ||
1122 | .ids = xenpci_ids, | ||
1123 | .probe = pcifront_xenbus_probe, | ||
1124 | .remove = pcifront_xenbus_remove, | ||
1125 | .otherend_changed = pcifront_backend_changed, | ||
1126 | }; | ||
1127 | |||
1128 | static int __init pcifront_init(void) | ||
1129 | { | ||
1130 | if (!xen_pv_domain() || xen_initial_domain()) | ||
1131 | return -ENODEV; | ||
1132 | |||
1133 | pci_frontend_registrar(1 /* enable */); | ||
1134 | |||
1135 | return xenbus_register_frontend(&xenbus_pcifront_driver); | ||
1136 | } | ||
1137 | |||
1138 | static void __exit pcifront_cleanup(void) | ||
1139 | { | ||
1140 | xenbus_unregister_driver(&xenbus_pcifront_driver); | ||
1141 | pci_frontend_registrar(0 /* disable */); | ||
1142 | } | ||
1143 | module_init(pcifront_init); | ||
1144 | module_exit(pcifront_cleanup); | ||
1145 | |||
1146 | MODULE_DESCRIPTION("Xen PCI passthrough frontend."); | ||
1147 | MODULE_LICENSE("GPL"); | ||
1148 | MODULE_ALIAS("xen:pci"); | ||
diff --git a/drivers/video/xen-fbfront.c b/drivers/video/xen-fbfront.c index 7c7f42a12796..428d273be727 100644 --- a/drivers/video/xen-fbfront.c +++ b/drivers/video/xen-fbfront.c | |||
@@ -631,6 +631,8 @@ static void xenfb_backend_changed(struct xenbus_device *dev, | |||
631 | switch (backend_state) { | 631 | switch (backend_state) { |
632 | case XenbusStateInitialising: | 632 | case XenbusStateInitialising: |
633 | case XenbusStateInitialised: | 633 | case XenbusStateInitialised: |
634 | case XenbusStateReconfiguring: | ||
635 | case XenbusStateReconfigured: | ||
634 | case XenbusStateUnknown: | 636 | case XenbusStateUnknown: |
635 | case XenbusStateClosed: | 637 | case XenbusStateClosed: |
636 | break; | 638 | break; |
diff --git a/drivers/xen/Kconfig b/drivers/xen/Kconfig index 60d71e9abe9f..6e6180ccd726 100644 --- a/drivers/xen/Kconfig +++ b/drivers/xen/Kconfig | |||
@@ -74,6 +74,7 @@ config XEN_PLATFORM_PCI | |||
74 | 74 | ||
75 | config SWIOTLB_XEN | 75 | config SWIOTLB_XEN |
76 | def_bool y | 76 | def_bool y |
77 | depends on SWIOTLB | 77 | depends on PCI |
78 | select SWIOTLB | ||
78 | 79 | ||
79 | endmenu | 80 | endmenu |
diff --git a/drivers/xen/Makefile b/drivers/xen/Makefile index fcaf838f54be..eb8a78d77d9d 100644 --- a/drivers/xen/Makefile +++ b/drivers/xen/Makefile | |||
@@ -4,6 +4,7 @@ obj-y += xenbus/ | |||
4 | nostackp := $(call cc-option, -fno-stack-protector) | 4 | nostackp := $(call cc-option, -fno-stack-protector) |
5 | CFLAGS_features.o := $(nostackp) | 5 | CFLAGS_features.o := $(nostackp) |
6 | 6 | ||
7 | obj-$(CONFIG_BLOCK) += biomerge.o | ||
7 | obj-$(CONFIG_HOTPLUG_CPU) += cpu_hotplug.o | 8 | obj-$(CONFIG_HOTPLUG_CPU) += cpu_hotplug.o |
8 | obj-$(CONFIG_XEN_XENCOMM) += xencomm.o | 9 | obj-$(CONFIG_XEN_XENCOMM) += xencomm.o |
9 | obj-$(CONFIG_XEN_BALLOON) += balloon.o | 10 | obj-$(CONFIG_XEN_BALLOON) += balloon.o |
@@ -12,3 +13,4 @@ obj-$(CONFIG_XENFS) += xenfs/ | |||
12 | obj-$(CONFIG_XEN_SYS_HYPERVISOR) += sys-hypervisor.o | 13 | obj-$(CONFIG_XEN_SYS_HYPERVISOR) += sys-hypervisor.o |
13 | obj-$(CONFIG_XEN_PLATFORM_PCI) += platform-pci.o | 14 | obj-$(CONFIG_XEN_PLATFORM_PCI) += platform-pci.o |
14 | obj-$(CONFIG_SWIOTLB_XEN) += swiotlb-xen.o | 15 | obj-$(CONFIG_SWIOTLB_XEN) += swiotlb-xen.o |
16 | obj-$(CONFIG_XEN_DOM0) += pci.o | ||
diff --git a/drivers/xen/biomerge.c b/drivers/xen/biomerge.c new file mode 100644 index 000000000000..ba6eda4b5143 --- /dev/null +++ b/drivers/xen/biomerge.c | |||
@@ -0,0 +1,13 @@ | |||
1 | #include <linux/bio.h> | ||
2 | #include <linux/io.h> | ||
3 | #include <xen/page.h> | ||
4 | |||
5 | bool xen_biovec_phys_mergeable(const struct bio_vec *vec1, | ||
6 | const struct bio_vec *vec2) | ||
7 | { | ||
8 | unsigned long mfn1 = pfn_to_mfn(page_to_pfn(vec1->bv_page)); | ||
9 | unsigned long mfn2 = pfn_to_mfn(page_to_pfn(vec2->bv_page)); | ||
10 | |||
11 | return __BIOVEC_PHYS_MERGEABLE(vec1, vec2) && | ||
12 | ((mfn1 == mfn2) || ((mfn1+1) == mfn2)); | ||
13 | } | ||
diff --git a/drivers/xen/events.c b/drivers/xen/events.c index 347f17edad77..97612f548a8e 100644 --- a/drivers/xen/events.c +++ b/drivers/xen/events.c | |||
@@ -16,7 +16,7 @@ | |||
16 | * (typically dom0). | 16 | * (typically dom0). |
17 | * 2. VIRQs, typically used for timers. These are per-cpu events. | 17 | * 2. VIRQs, typically used for timers. These are per-cpu events. |
18 | * 3. IPIs. | 18 | * 3. IPIs. |
19 | * 4. Hardware interrupts. Not supported at present. | 19 | * 4. PIRQs - Hardware interrupts. |
20 | * | 20 | * |
21 | * Jeremy Fitzhardinge <jeremy@xensource.com>, XenSource Inc, 2007 | 21 | * Jeremy Fitzhardinge <jeremy@xensource.com>, XenSource Inc, 2007 |
22 | */ | 22 | */ |
@@ -28,12 +28,16 @@ | |||
28 | #include <linux/string.h> | 28 | #include <linux/string.h> |
29 | #include <linux/bootmem.h> | 29 | #include <linux/bootmem.h> |
30 | #include <linux/slab.h> | 30 | #include <linux/slab.h> |
31 | #include <linux/irqnr.h> | ||
32 | #include <linux/pci.h> | ||
31 | 33 | ||
32 | #include <asm/desc.h> | 34 | #include <asm/desc.h> |
33 | #include <asm/ptrace.h> | 35 | #include <asm/ptrace.h> |
34 | #include <asm/irq.h> | 36 | #include <asm/irq.h> |
35 | #include <asm/idle.h> | 37 | #include <asm/idle.h> |
38 | #include <asm/io_apic.h> | ||
36 | #include <asm/sync_bitops.h> | 39 | #include <asm/sync_bitops.h> |
40 | #include <asm/xen/pci.h> | ||
37 | #include <asm/xen/hypercall.h> | 41 | #include <asm/xen/hypercall.h> |
38 | #include <asm/xen/hypervisor.h> | 42 | #include <asm/xen/hypervisor.h> |
39 | 43 | ||
@@ -73,7 +77,8 @@ enum xen_irq_type { | |||
73 | * event channel - irq->event channel mapping | 77 | * event channel - irq->event channel mapping |
74 | * cpu - cpu this event channel is bound to | 78 | * cpu - cpu this event channel is bound to |
75 | * index - type-specific information: | 79 | * index - type-specific information: |
76 | * PIRQ - vector, with MSB being "needs EIO" | 80 | * PIRQ - vector, with MSB being "needs EIO", or physical IRQ of the HVM |
81 | * guest, or GSI (real passthrough IRQ) of the device. | ||
77 | * VIRQ - virq number | 82 | * VIRQ - virq number |
78 | * IPI - IPI vector | 83 | * IPI - IPI vector |
79 | * EVTCHN - | 84 | * EVTCHN - |
@@ -88,21 +93,30 @@ struct irq_info | |||
88 | unsigned short virq; | 93 | unsigned short virq; |
89 | enum ipi_vector ipi; | 94 | enum ipi_vector ipi; |
90 | struct { | 95 | struct { |
96 | unsigned short pirq; | ||
91 | unsigned short gsi; | 97 | unsigned short gsi; |
92 | unsigned short vector; | 98 | unsigned char vector; |
99 | unsigned char flags; | ||
93 | } pirq; | 100 | } pirq; |
94 | } u; | 101 | } u; |
95 | }; | 102 | }; |
103 | #define PIRQ_NEEDS_EOI (1 << 0) | ||
104 | #define PIRQ_SHAREABLE (1 << 1) | ||
96 | 105 | ||
97 | static struct irq_info irq_info[NR_IRQS]; | 106 | static struct irq_info *irq_info; |
107 | static int *pirq_to_irq; | ||
108 | static int nr_pirqs; | ||
98 | 109 | ||
99 | static int evtchn_to_irq[NR_EVENT_CHANNELS] = { | 110 | static int *evtchn_to_irq; |
100 | [0 ... NR_EVENT_CHANNELS-1] = -1 | ||
101 | }; | ||
102 | struct cpu_evtchn_s { | 111 | struct cpu_evtchn_s { |
103 | unsigned long bits[NR_EVENT_CHANNELS/BITS_PER_LONG]; | 112 | unsigned long bits[NR_EVENT_CHANNELS/BITS_PER_LONG]; |
104 | }; | 113 | }; |
105 | static struct cpu_evtchn_s *cpu_evtchn_mask_p; | 114 | |
115 | static __initdata struct cpu_evtchn_s init_evtchn_mask = { | ||
116 | .bits[0 ... (NR_EVENT_CHANNELS/BITS_PER_LONG)-1] = ~0ul, | ||
117 | }; | ||
118 | static struct cpu_evtchn_s *cpu_evtchn_mask_p = &init_evtchn_mask; | ||
119 | |||
106 | static inline unsigned long *cpu_evtchn_mask(int cpu) | 120 | static inline unsigned long *cpu_evtchn_mask(int cpu) |
107 | { | 121 | { |
108 | return cpu_evtchn_mask_p[cpu].bits; | 122 | return cpu_evtchn_mask_p[cpu].bits; |
@@ -113,6 +127,7 @@ static inline unsigned long *cpu_evtchn_mask(int cpu) | |||
113 | 127 | ||
114 | static struct irq_chip xen_dynamic_chip; | 128 | static struct irq_chip xen_dynamic_chip; |
115 | static struct irq_chip xen_percpu_chip; | 129 | static struct irq_chip xen_percpu_chip; |
130 | static struct irq_chip xen_pirq_chip; | ||
116 | 131 | ||
117 | /* Constructor for packed IRQ information. */ | 132 | /* Constructor for packed IRQ information. */ |
118 | static struct irq_info mk_unbound_info(void) | 133 | static struct irq_info mk_unbound_info(void) |
@@ -138,11 +153,12 @@ static struct irq_info mk_virq_info(unsigned short evtchn, unsigned short virq) | |||
138 | .cpu = 0, .u.virq = virq }; | 153 | .cpu = 0, .u.virq = virq }; |
139 | } | 154 | } |
140 | 155 | ||
141 | static struct irq_info mk_pirq_info(unsigned short evtchn, | 156 | static struct irq_info mk_pirq_info(unsigned short evtchn, unsigned short pirq, |
142 | unsigned short gsi, unsigned short vector) | 157 | unsigned short gsi, unsigned short vector) |
143 | { | 158 | { |
144 | return (struct irq_info) { .type = IRQT_PIRQ, .evtchn = evtchn, | 159 | return (struct irq_info) { .type = IRQT_PIRQ, .evtchn = evtchn, |
145 | .cpu = 0, .u.pirq = { .gsi = gsi, .vector = vector } }; | 160 | .cpu = 0, |
161 | .u.pirq = { .pirq = pirq, .gsi = gsi, .vector = vector } }; | ||
146 | } | 162 | } |
147 | 163 | ||
148 | /* | 164 | /* |
@@ -184,6 +200,16 @@ static unsigned virq_from_irq(unsigned irq) | |||
184 | return info->u.virq; | 200 | return info->u.virq; |
185 | } | 201 | } |
186 | 202 | ||
203 | static unsigned pirq_from_irq(unsigned irq) | ||
204 | { | ||
205 | struct irq_info *info = info_for_irq(irq); | ||
206 | |||
207 | BUG_ON(info == NULL); | ||
208 | BUG_ON(info->type != IRQT_PIRQ); | ||
209 | |||
210 | return info->u.pirq.pirq; | ||
211 | } | ||
212 | |||
187 | static unsigned gsi_from_irq(unsigned irq) | 213 | static unsigned gsi_from_irq(unsigned irq) |
188 | { | 214 | { |
189 | struct irq_info *info = info_for_irq(irq); | 215 | struct irq_info *info = info_for_irq(irq); |
@@ -225,6 +251,15 @@ static unsigned int cpu_from_evtchn(unsigned int evtchn) | |||
225 | return ret; | 251 | return ret; |
226 | } | 252 | } |
227 | 253 | ||
254 | static bool pirq_needs_eoi(unsigned irq) | ||
255 | { | ||
256 | struct irq_info *info = info_for_irq(irq); | ||
257 | |||
258 | BUG_ON(info->type != IRQT_PIRQ); | ||
259 | |||
260 | return info->u.pirq.flags & PIRQ_NEEDS_EOI; | ||
261 | } | ||
262 | |||
228 | static inline unsigned long active_evtchns(unsigned int cpu, | 263 | static inline unsigned long active_evtchns(unsigned int cpu, |
229 | struct shared_info *sh, | 264 | struct shared_info *sh, |
230 | unsigned int idx) | 265 | unsigned int idx) |
@@ -336,12 +371,40 @@ static void unmask_evtchn(int port) | |||
336 | put_cpu(); | 371 | put_cpu(); |
337 | } | 372 | } |
338 | 373 | ||
374 | static int get_nr_hw_irqs(void) | ||
375 | { | ||
376 | int ret = 1; | ||
377 | |||
378 | #ifdef CONFIG_X86_IO_APIC | ||
379 | ret = get_nr_irqs_gsi(); | ||
380 | #endif | ||
381 | |||
382 | return ret; | ||
383 | } | ||
384 | |||
385 | /* callers of this function should make sure that PHYSDEVOP_get_nr_pirqs | ||
386 | * succeeded otherwise nr_pirqs won't hold the right value */ | ||
387 | static int find_unbound_pirq(void) | ||
388 | { | ||
389 | int i; | ||
390 | for (i = nr_pirqs-1; i >= 0; i--) { | ||
391 | if (pirq_to_irq[i] < 0) | ||
392 | return i; | ||
393 | } | ||
394 | return -1; | ||
395 | } | ||
396 | |||
339 | static int find_unbound_irq(void) | 397 | static int find_unbound_irq(void) |
340 | { | 398 | { |
341 | struct irq_data *data; | 399 | struct irq_data *data; |
342 | int irq, res; | 400 | int irq, res; |
401 | int start = get_nr_hw_irqs(); | ||
343 | 402 | ||
344 | for (irq = 0; irq < nr_irqs; irq++) { | 403 | if (start == nr_irqs) |
404 | goto no_irqs; | ||
405 | |||
406 | /* nr_irqs is a magic value. Must not use it.*/ | ||
407 | for (irq = nr_irqs-1; irq > start; irq--) { | ||
345 | data = irq_get_irq_data(irq); | 408 | data = irq_get_irq_data(irq); |
346 | /* only 0->15 have init'd desc; handle irq > 16 */ | 409 | /* only 0->15 have init'd desc; handle irq > 16 */ |
347 | if (!data) | 410 | if (!data) |
@@ -354,8 +417,8 @@ static int find_unbound_irq(void) | |||
354 | return irq; | 417 | return irq; |
355 | } | 418 | } |
356 | 419 | ||
357 | if (irq == nr_irqs) | 420 | if (irq == start) |
358 | panic("No available IRQ to bind to: increase nr_irqs!\n"); | 421 | goto no_irqs; |
359 | 422 | ||
360 | res = irq_alloc_desc_at(irq, 0); | 423 | res = irq_alloc_desc_at(irq, 0); |
361 | 424 | ||
@@ -363,6 +426,357 @@ static int find_unbound_irq(void) | |||
363 | return -1; | 426 | return -1; |
364 | 427 | ||
365 | return irq; | 428 | return irq; |
429 | |||
430 | no_irqs: | ||
431 | panic("No available IRQ to bind to: increase nr_irqs!\n"); | ||
432 | } | ||
433 | |||
434 | static bool identity_mapped_irq(unsigned irq) | ||
435 | { | ||
436 | /* identity map all the hardware irqs */ | ||
437 | return irq < get_nr_hw_irqs(); | ||
438 | } | ||
439 | |||
440 | static void pirq_unmask_notify(int irq) | ||
441 | { | ||
442 | struct physdev_eoi eoi = { .irq = pirq_from_irq(irq) }; | ||
443 | |||
444 | if (unlikely(pirq_needs_eoi(irq))) { | ||
445 | int rc = HYPERVISOR_physdev_op(PHYSDEVOP_eoi, &eoi); | ||
446 | WARN_ON(rc); | ||
447 | } | ||
448 | } | ||
449 | |||
450 | static void pirq_query_unmask(int irq) | ||
451 | { | ||
452 | struct physdev_irq_status_query irq_status; | ||
453 | struct irq_info *info = info_for_irq(irq); | ||
454 | |||
455 | BUG_ON(info->type != IRQT_PIRQ); | ||
456 | |||
457 | irq_status.irq = pirq_from_irq(irq); | ||
458 | if (HYPERVISOR_physdev_op(PHYSDEVOP_irq_status_query, &irq_status)) | ||
459 | irq_status.flags = 0; | ||
460 | |||
461 | info->u.pirq.flags &= ~PIRQ_NEEDS_EOI; | ||
462 | if (irq_status.flags & XENIRQSTAT_needs_eoi) | ||
463 | info->u.pirq.flags |= PIRQ_NEEDS_EOI; | ||
464 | } | ||
465 | |||
466 | static bool probing_irq(int irq) | ||
467 | { | ||
468 | struct irq_desc *desc = irq_to_desc(irq); | ||
469 | |||
470 | return desc && desc->action == NULL; | ||
471 | } | ||
472 | |||
473 | static unsigned int startup_pirq(unsigned int irq) | ||
474 | { | ||
475 | struct evtchn_bind_pirq bind_pirq; | ||
476 | struct irq_info *info = info_for_irq(irq); | ||
477 | int evtchn = evtchn_from_irq(irq); | ||
478 | int rc; | ||
479 | |||
480 | BUG_ON(info->type != IRQT_PIRQ); | ||
481 | |||
482 | if (VALID_EVTCHN(evtchn)) | ||
483 | goto out; | ||
484 | |||
485 | bind_pirq.pirq = pirq_from_irq(irq); | ||
486 | /* NB. We are happy to share unless we are probing. */ | ||
487 | bind_pirq.flags = info->u.pirq.flags & PIRQ_SHAREABLE ? | ||
488 | BIND_PIRQ__WILL_SHARE : 0; | ||
489 | rc = HYPERVISOR_event_channel_op(EVTCHNOP_bind_pirq, &bind_pirq); | ||
490 | if (rc != 0) { | ||
491 | if (!probing_irq(irq)) | ||
492 | printk(KERN_INFO "Failed to obtain physical IRQ %d\n", | ||
493 | irq); | ||
494 | return 0; | ||
495 | } | ||
496 | evtchn = bind_pirq.port; | ||
497 | |||
498 | pirq_query_unmask(irq); | ||
499 | |||
500 | evtchn_to_irq[evtchn] = irq; | ||
501 | bind_evtchn_to_cpu(evtchn, 0); | ||
502 | info->evtchn = evtchn; | ||
503 | |||
504 | out: | ||
505 | unmask_evtchn(evtchn); | ||
506 | pirq_unmask_notify(irq); | ||
507 | |||
508 | return 0; | ||
509 | } | ||
510 | |||
511 | static void shutdown_pirq(unsigned int irq) | ||
512 | { | ||
513 | struct evtchn_close close; | ||
514 | struct irq_info *info = info_for_irq(irq); | ||
515 | int evtchn = evtchn_from_irq(irq); | ||
516 | |||
517 | BUG_ON(info->type != IRQT_PIRQ); | ||
518 | |||
519 | if (!VALID_EVTCHN(evtchn)) | ||
520 | return; | ||
521 | |||
522 | mask_evtchn(evtchn); | ||
523 | |||
524 | close.port = evtchn; | ||
525 | if (HYPERVISOR_event_channel_op(EVTCHNOP_close, &close) != 0) | ||
526 | BUG(); | ||
527 | |||
528 | bind_evtchn_to_cpu(evtchn, 0); | ||
529 | evtchn_to_irq[evtchn] = -1; | ||
530 | info->evtchn = 0; | ||
531 | } | ||
532 | |||
533 | static void enable_pirq(unsigned int irq) | ||
534 | { | ||
535 | startup_pirq(irq); | ||
536 | } | ||
537 | |||
538 | static void disable_pirq(unsigned int irq) | ||
539 | { | ||
540 | } | ||
541 | |||
542 | static void ack_pirq(unsigned int irq) | ||
543 | { | ||
544 | int evtchn = evtchn_from_irq(irq); | ||
545 | |||
546 | move_native_irq(irq); | ||
547 | |||
548 | if (VALID_EVTCHN(evtchn)) { | ||
549 | mask_evtchn(evtchn); | ||
550 | clear_evtchn(evtchn); | ||
551 | } | ||
552 | } | ||
553 | |||
554 | static void end_pirq(unsigned int irq) | ||
555 | { | ||
556 | int evtchn = evtchn_from_irq(irq); | ||
557 | struct irq_desc *desc = irq_to_desc(irq); | ||
558 | |||
559 | if (WARN_ON(!desc)) | ||
560 | return; | ||
561 | |||
562 | if ((desc->status & (IRQ_DISABLED|IRQ_PENDING)) == | ||
563 | (IRQ_DISABLED|IRQ_PENDING)) { | ||
564 | shutdown_pirq(irq); | ||
565 | } else if (VALID_EVTCHN(evtchn)) { | ||
566 | unmask_evtchn(evtchn); | ||
567 | pirq_unmask_notify(irq); | ||
568 | } | ||
569 | } | ||
570 | |||
571 | static int find_irq_by_gsi(unsigned gsi) | ||
572 | { | ||
573 | int irq; | ||
574 | |||
575 | for (irq = 0; irq < nr_irqs; irq++) { | ||
576 | struct irq_info *info = info_for_irq(irq); | ||
577 | |||
578 | if (info == NULL || info->type != IRQT_PIRQ) | ||
579 | continue; | ||
580 | |||
581 | if (gsi_from_irq(irq) == gsi) | ||
582 | return irq; | ||
583 | } | ||
584 | |||
585 | return -1; | ||
586 | } | ||
587 | |||
588 | int xen_allocate_pirq(unsigned gsi, int shareable, char *name) | ||
589 | { | ||
590 | return xen_map_pirq_gsi(gsi, gsi, shareable, name); | ||
591 | } | ||
592 | |||
593 | /* xen_map_pirq_gsi might allocate irqs from the top down, as a | ||
594 | * consequence don't assume that the irq number returned has a low value | ||
595 | * or can be used as a pirq number unless you know otherwise. | ||
596 | * | ||
597 | * One notable exception is when xen_map_pirq_gsi is called passing an | ||
598 | * hardware gsi as argument, in that case the irq number returned | ||
599 | * matches the gsi number passed as second argument. | ||
600 | * | ||
601 | * Note: We don't assign an event channel until the irq actually started | ||
602 | * up. Return an existing irq if we've already got one for the gsi. | ||
603 | */ | ||
604 | int xen_map_pirq_gsi(unsigned pirq, unsigned gsi, int shareable, char *name) | ||
605 | { | ||
606 | int irq = 0; | ||
607 | struct physdev_irq irq_op; | ||
608 | |||
609 | spin_lock(&irq_mapping_update_lock); | ||
610 | |||
611 | if ((pirq > nr_pirqs) || (gsi > nr_irqs)) { | ||
612 | printk(KERN_WARNING "xen_map_pirq_gsi: %s %s is incorrect!\n", | ||
613 | pirq > nr_pirqs ? "nr_pirqs" :"", | ||
614 | gsi > nr_irqs ? "nr_irqs" : ""); | ||
615 | goto out; | ||
616 | } | ||
617 | |||
618 | irq = find_irq_by_gsi(gsi); | ||
619 | if (irq != -1) { | ||
620 | printk(KERN_INFO "xen_map_pirq_gsi: returning irq %d for gsi %u\n", | ||
621 | irq, gsi); | ||
622 | goto out; /* XXX need refcount? */ | ||
623 | } | ||
624 | |||
625 | /* If we are a PV guest, we don't have GSIs (no ACPI passed). Therefore | ||
626 | * we are using the !xen_initial_domain() to drop in the function.*/ | ||
627 | if (identity_mapped_irq(gsi) || (!xen_initial_domain() && | ||
628 | xen_pv_domain())) { | ||
629 | irq = gsi; | ||
630 | irq_alloc_desc_at(irq, 0); | ||
631 | } else | ||
632 | irq = find_unbound_irq(); | ||
633 | |||
634 | set_irq_chip_and_handler_name(irq, &xen_pirq_chip, | ||
635 | handle_level_irq, name); | ||
636 | |||
637 | irq_op.irq = irq; | ||
638 | irq_op.vector = 0; | ||
639 | |||
640 | /* Only the privileged domain can do this. For non-priv, the pcifront | ||
641 | * driver provides a PCI bus that does the call to do exactly | ||
642 | * this in the priv domain. */ | ||
643 | if (xen_initial_domain() && | ||
644 | HYPERVISOR_physdev_op(PHYSDEVOP_alloc_irq_vector, &irq_op)) { | ||
645 | irq_free_desc(irq); | ||
646 | irq = -ENOSPC; | ||
647 | goto out; | ||
648 | } | ||
649 | |||
650 | irq_info[irq] = mk_pirq_info(0, pirq, gsi, irq_op.vector); | ||
651 | irq_info[irq].u.pirq.flags |= shareable ? PIRQ_SHAREABLE : 0; | ||
652 | pirq_to_irq[pirq] = irq; | ||
653 | |||
654 | out: | ||
655 | spin_unlock(&irq_mapping_update_lock); | ||
656 | |||
657 | return irq; | ||
658 | } | ||
659 | |||
660 | #ifdef CONFIG_PCI_MSI | ||
661 | #include <linux/msi.h> | ||
662 | #include "../pci/msi.h" | ||
663 | |||
664 | void xen_allocate_pirq_msi(char *name, int *irq, int *pirq) | ||
665 | { | ||
666 | spin_lock(&irq_mapping_update_lock); | ||
667 | |||
668 | *irq = find_unbound_irq(); | ||
669 | if (*irq == -1) | ||
670 | goto out; | ||
671 | |||
672 | *pirq = find_unbound_pirq(); | ||
673 | if (*pirq == -1) | ||
674 | goto out; | ||
675 | |||
676 | set_irq_chip_and_handler_name(*irq, &xen_pirq_chip, | ||
677 | handle_level_irq, name); | ||
678 | |||
679 | irq_info[*irq] = mk_pirq_info(0, *pirq, 0, 0); | ||
680 | pirq_to_irq[*pirq] = *irq; | ||
681 | |||
682 | out: | ||
683 | spin_unlock(&irq_mapping_update_lock); | ||
684 | } | ||
685 | |||
686 | int xen_create_msi_irq(struct pci_dev *dev, struct msi_desc *msidesc, int type) | ||
687 | { | ||
688 | int irq = -1; | ||
689 | struct physdev_map_pirq map_irq; | ||
690 | int rc; | ||
691 | int pos; | ||
692 | u32 table_offset, bir; | ||
693 | |||
694 | memset(&map_irq, 0, sizeof(map_irq)); | ||
695 | map_irq.domid = DOMID_SELF; | ||
696 | map_irq.type = MAP_PIRQ_TYPE_MSI; | ||
697 | map_irq.index = -1; | ||
698 | map_irq.pirq = -1; | ||
699 | map_irq.bus = dev->bus->number; | ||
700 | map_irq.devfn = dev->devfn; | ||
701 | |||
702 | if (type == PCI_CAP_ID_MSIX) { | ||
703 | pos = pci_find_capability(dev, PCI_CAP_ID_MSIX); | ||
704 | |||
705 | pci_read_config_dword(dev, msix_table_offset_reg(pos), | ||
706 | &table_offset); | ||
707 | bir = (u8)(table_offset & PCI_MSIX_FLAGS_BIRMASK); | ||
708 | |||
709 | map_irq.table_base = pci_resource_start(dev, bir); | ||
710 | map_irq.entry_nr = msidesc->msi_attrib.entry_nr; | ||
711 | } | ||
712 | |||
713 | spin_lock(&irq_mapping_update_lock); | ||
714 | |||
715 | irq = find_unbound_irq(); | ||
716 | |||
717 | if (irq == -1) | ||
718 | goto out; | ||
719 | |||
720 | rc = HYPERVISOR_physdev_op(PHYSDEVOP_map_pirq, &map_irq); | ||
721 | if (rc) { | ||
722 | printk(KERN_WARNING "xen map irq failed %d\n", rc); | ||
723 | |||
724 | irq_free_desc(irq); | ||
725 | |||
726 | irq = -1; | ||
727 | goto out; | ||
728 | } | ||
729 | irq_info[irq] = mk_pirq_info(0, map_irq.pirq, 0, map_irq.index); | ||
730 | |||
731 | set_irq_chip_and_handler_name(irq, &xen_pirq_chip, | ||
732 | handle_level_irq, | ||
733 | (type == PCI_CAP_ID_MSIX) ? "msi-x":"msi"); | ||
734 | |||
735 | out: | ||
736 | spin_unlock(&irq_mapping_update_lock); | ||
737 | return irq; | ||
738 | } | ||
739 | #endif | ||
740 | |||
741 | int xen_destroy_irq(int irq) | ||
742 | { | ||
743 | struct irq_desc *desc; | ||
744 | struct physdev_unmap_pirq unmap_irq; | ||
745 | struct irq_info *info = info_for_irq(irq); | ||
746 | int rc = -ENOENT; | ||
747 | |||
748 | spin_lock(&irq_mapping_update_lock); | ||
749 | |||
750 | desc = irq_to_desc(irq); | ||
751 | if (!desc) | ||
752 | goto out; | ||
753 | |||
754 | if (xen_initial_domain()) { | ||
755 | unmap_irq.pirq = info->u.pirq.gsi; | ||
756 | unmap_irq.domid = DOMID_SELF; | ||
757 | rc = HYPERVISOR_physdev_op(PHYSDEVOP_unmap_pirq, &unmap_irq); | ||
758 | if (rc) { | ||
759 | printk(KERN_WARNING "unmap irq failed %d\n", rc); | ||
760 | goto out; | ||
761 | } | ||
762 | } | ||
763 | irq_info[irq] = mk_unbound_info(); | ||
764 | |||
765 | irq_free_desc(irq); | ||
766 | |||
767 | out: | ||
768 | spin_unlock(&irq_mapping_update_lock); | ||
769 | return rc; | ||
770 | } | ||
771 | |||
772 | int xen_vector_from_irq(unsigned irq) | ||
773 | { | ||
774 | return vector_from_irq(irq); | ||
775 | } | ||
776 | |||
777 | int xen_gsi_from_irq(unsigned irq) | ||
778 | { | ||
779 | return gsi_from_irq(irq); | ||
366 | } | 780 | } |
367 | 781 | ||
368 | int bind_evtchn_to_irq(unsigned int evtchn) | 782 | int bind_evtchn_to_irq(unsigned int evtchn) |
@@ -425,7 +839,7 @@ static int bind_ipi_to_irq(unsigned int ipi, unsigned int cpu) | |||
425 | } | 839 | } |
426 | 840 | ||
427 | 841 | ||
428 | static int bind_virq_to_irq(unsigned int virq, unsigned int cpu) | 842 | int bind_virq_to_irq(unsigned int virq, unsigned int cpu) |
429 | { | 843 | { |
430 | struct evtchn_bind_virq bind_virq; | 844 | struct evtchn_bind_virq bind_virq; |
431 | int evtchn, irq; | 845 | int evtchn, irq; |
@@ -928,7 +1342,7 @@ void xen_clear_irq_pending(int irq) | |||
928 | if (VALID_EVTCHN(evtchn)) | 1342 | if (VALID_EVTCHN(evtchn)) |
929 | clear_evtchn(evtchn); | 1343 | clear_evtchn(evtchn); |
930 | } | 1344 | } |
931 | 1345 | EXPORT_SYMBOL(xen_clear_irq_pending); | |
932 | void xen_set_irq_pending(int irq) | 1346 | void xen_set_irq_pending(int irq) |
933 | { | 1347 | { |
934 | int evtchn = evtchn_from_irq(irq); | 1348 | int evtchn = evtchn_from_irq(irq); |
@@ -948,9 +1362,9 @@ bool xen_test_irq_pending(int irq) | |||
948 | return ret; | 1362 | return ret; |
949 | } | 1363 | } |
950 | 1364 | ||
951 | /* Poll waiting for an irq to become pending. In the usual case, the | 1365 | /* Poll waiting for an irq to become pending with timeout. In the usual case, |
952 | irq will be disabled so it won't deliver an interrupt. */ | 1366 | * the irq will be disabled so it won't deliver an interrupt. */ |
953 | void xen_poll_irq(int irq) | 1367 | void xen_poll_irq_timeout(int irq, u64 timeout) |
954 | { | 1368 | { |
955 | evtchn_port_t evtchn = evtchn_from_irq(irq); | 1369 | evtchn_port_t evtchn = evtchn_from_irq(irq); |
956 | 1370 | ||
@@ -958,13 +1372,20 @@ void xen_poll_irq(int irq) | |||
958 | struct sched_poll poll; | 1372 | struct sched_poll poll; |
959 | 1373 | ||
960 | poll.nr_ports = 1; | 1374 | poll.nr_ports = 1; |
961 | poll.timeout = 0; | 1375 | poll.timeout = timeout; |
962 | set_xen_guest_handle(poll.ports, &evtchn); | 1376 | set_xen_guest_handle(poll.ports, &evtchn); |
963 | 1377 | ||
964 | if (HYPERVISOR_sched_op(SCHEDOP_poll, &poll) != 0) | 1378 | if (HYPERVISOR_sched_op(SCHEDOP_poll, &poll) != 0) |
965 | BUG(); | 1379 | BUG(); |
966 | } | 1380 | } |
967 | } | 1381 | } |
1382 | EXPORT_SYMBOL(xen_poll_irq_timeout); | ||
1383 | /* Poll waiting for an irq to become pending. In the usual case, the | ||
1384 | * irq will be disabled so it won't deliver an interrupt. */ | ||
1385 | void xen_poll_irq(int irq) | ||
1386 | { | ||
1387 | xen_poll_irq_timeout(irq, 0 /* no timeout */); | ||
1388 | } | ||
968 | 1389 | ||
969 | void xen_irq_resume(void) | 1390 | void xen_irq_resume(void) |
970 | { | 1391 | { |
@@ -1001,6 +1422,26 @@ static struct irq_chip xen_dynamic_chip __read_mostly = { | |||
1001 | .retrigger = retrigger_dynirq, | 1422 | .retrigger = retrigger_dynirq, |
1002 | }; | 1423 | }; |
1003 | 1424 | ||
1425 | static struct irq_chip xen_pirq_chip __read_mostly = { | ||
1426 | .name = "xen-pirq", | ||
1427 | |||
1428 | .startup = startup_pirq, | ||
1429 | .shutdown = shutdown_pirq, | ||
1430 | |||
1431 | .enable = enable_pirq, | ||
1432 | .unmask = enable_pirq, | ||
1433 | |||
1434 | .disable = disable_pirq, | ||
1435 | .mask = disable_pirq, | ||
1436 | |||
1437 | .ack = ack_pirq, | ||
1438 | .end = end_pirq, | ||
1439 | |||
1440 | .set_affinity = set_affinity_irq, | ||
1441 | |||
1442 | .retrigger = retrigger_dynirq, | ||
1443 | }; | ||
1444 | |||
1004 | static struct irq_chip xen_percpu_chip __read_mostly = { | 1445 | static struct irq_chip xen_percpu_chip __read_mostly = { |
1005 | .name = "xen-percpu", | 1446 | .name = "xen-percpu", |
1006 | 1447 | ||
@@ -1051,11 +1492,32 @@ void xen_callback_vector(void) {} | |||
1051 | 1492 | ||
1052 | void __init xen_init_IRQ(void) | 1493 | void __init xen_init_IRQ(void) |
1053 | { | 1494 | { |
1054 | int i; | 1495 | int i, rc; |
1496 | struct physdev_nr_pirqs op_nr_pirqs; | ||
1055 | 1497 | ||
1056 | cpu_evtchn_mask_p = kcalloc(nr_cpu_ids, sizeof(struct cpu_evtchn_s), | 1498 | cpu_evtchn_mask_p = kcalloc(nr_cpu_ids, sizeof(struct cpu_evtchn_s), |
1057 | GFP_KERNEL); | 1499 | GFP_KERNEL); |
1058 | BUG_ON(cpu_evtchn_mask_p == NULL); | 1500 | irq_info = kcalloc(nr_irqs, sizeof(*irq_info), GFP_KERNEL); |
1501 | |||
1502 | rc = HYPERVISOR_physdev_op(PHYSDEVOP_get_nr_pirqs, &op_nr_pirqs); | ||
1503 | if (rc < 0) { | ||
1504 | nr_pirqs = nr_irqs; | ||
1505 | if (rc != -ENOSYS) | ||
1506 | printk(KERN_WARNING "PHYSDEVOP_get_nr_pirqs returned rc=%d\n", rc); | ||
1507 | } else { | ||
1508 | if (xen_pv_domain() && !xen_initial_domain()) | ||
1509 | nr_pirqs = max((int)op_nr_pirqs.nr_pirqs, nr_irqs); | ||
1510 | else | ||
1511 | nr_pirqs = op_nr_pirqs.nr_pirqs; | ||
1512 | } | ||
1513 | pirq_to_irq = kcalloc(nr_pirqs, sizeof(*pirq_to_irq), GFP_KERNEL); | ||
1514 | for (i = 0; i < nr_pirqs; i++) | ||
1515 | pirq_to_irq[i] = -1; | ||
1516 | |||
1517 | evtchn_to_irq = kcalloc(NR_EVENT_CHANNELS, sizeof(*evtchn_to_irq), | ||
1518 | GFP_KERNEL); | ||
1519 | for (i = 0; i < NR_EVENT_CHANNELS; i++) | ||
1520 | evtchn_to_irq[i] = -1; | ||
1059 | 1521 | ||
1060 | init_evtchn_cpu_bindings(); | 1522 | init_evtchn_cpu_bindings(); |
1061 | 1523 | ||
@@ -1066,7 +1528,12 @@ void __init xen_init_IRQ(void) | |||
1066 | if (xen_hvm_domain()) { | 1528 | if (xen_hvm_domain()) { |
1067 | xen_callback_vector(); | 1529 | xen_callback_vector(); |
1068 | native_init_IRQ(); | 1530 | native_init_IRQ(); |
1531 | /* pci_xen_hvm_init must be called after native_init_IRQ so that | ||
1532 | * __acpi_register_gsi can point at the right function */ | ||
1533 | pci_xen_hvm_init(); | ||
1069 | } else { | 1534 | } else { |
1070 | irq_ctx_init(smp_processor_id()); | 1535 | irq_ctx_init(smp_processor_id()); |
1536 | if (xen_initial_domain()) | ||
1537 | xen_setup_pirqs(); | ||
1071 | } | 1538 | } |
1072 | } | 1539 | } |
diff --git a/drivers/xen/pci.c b/drivers/xen/pci.c new file mode 100644 index 000000000000..cef4bafc07dc --- /dev/null +++ b/drivers/xen/pci.c | |||
@@ -0,0 +1,117 @@ | |||
1 | /* | ||
2 | * Copyright (c) 2009, Intel Corporation. | ||
3 | * | ||
4 | * This program is free software; you can redistribute it and/or modify it | ||
5 | * under the terms and conditions of the GNU General Public License, | ||
6 | * version 2, as published by the Free Software Foundation. | ||
7 | * | ||
8 | * This program is distributed in the hope it will be useful, but WITHOUT | ||
9 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
10 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
11 | * more details. | ||
12 | * | ||
13 | * You should have received a copy of the GNU General Public License along with | ||
14 | * this program; if not, write to the Free Software Foundation, Inc., 59 Temple | ||
15 | * Place - Suite 330, Boston, MA 02111-1307 USA. | ||
16 | * | ||
17 | * Author: Weidong Han <weidong.han@intel.com> | ||
18 | */ | ||
19 | |||
20 | #include <linux/pci.h> | ||
21 | #include <xen/xen.h> | ||
22 | #include <xen/interface/physdev.h> | ||
23 | #include <xen/interface/xen.h> | ||
24 | |||
25 | #include <asm/xen/hypervisor.h> | ||
26 | #include <asm/xen/hypercall.h> | ||
27 | #include "../pci/pci.h" | ||
28 | |||
29 | static int xen_add_device(struct device *dev) | ||
30 | { | ||
31 | int r; | ||
32 | struct pci_dev *pci_dev = to_pci_dev(dev); | ||
33 | |||
34 | #ifdef CONFIG_PCI_IOV | ||
35 | if (pci_dev->is_virtfn) { | ||
36 | struct physdev_manage_pci_ext manage_pci_ext = { | ||
37 | .bus = pci_dev->bus->number, | ||
38 | .devfn = pci_dev->devfn, | ||
39 | .is_virtfn = 1, | ||
40 | .physfn.bus = pci_dev->physfn->bus->number, | ||
41 | .physfn.devfn = pci_dev->physfn->devfn, | ||
42 | }; | ||
43 | |||
44 | r = HYPERVISOR_physdev_op(PHYSDEVOP_manage_pci_add_ext, | ||
45 | &manage_pci_ext); | ||
46 | } else | ||
47 | #endif | ||
48 | if (pci_ari_enabled(pci_dev->bus) && PCI_SLOT(pci_dev->devfn)) { | ||
49 | struct physdev_manage_pci_ext manage_pci_ext = { | ||
50 | .bus = pci_dev->bus->number, | ||
51 | .devfn = pci_dev->devfn, | ||
52 | .is_extfn = 1, | ||
53 | }; | ||
54 | |||
55 | r = HYPERVISOR_physdev_op(PHYSDEVOP_manage_pci_add_ext, | ||
56 | &manage_pci_ext); | ||
57 | } else { | ||
58 | struct physdev_manage_pci manage_pci = { | ||
59 | .bus = pci_dev->bus->number, | ||
60 | .devfn = pci_dev->devfn, | ||
61 | }; | ||
62 | |||
63 | r = HYPERVISOR_physdev_op(PHYSDEVOP_manage_pci_add, | ||
64 | &manage_pci); | ||
65 | } | ||
66 | |||
67 | return r; | ||
68 | } | ||
69 | |||
70 | static int xen_remove_device(struct device *dev) | ||
71 | { | ||
72 | int r; | ||
73 | struct pci_dev *pci_dev = to_pci_dev(dev); | ||
74 | struct physdev_manage_pci manage_pci; | ||
75 | |||
76 | manage_pci.bus = pci_dev->bus->number; | ||
77 | manage_pci.devfn = pci_dev->devfn; | ||
78 | |||
79 | r = HYPERVISOR_physdev_op(PHYSDEVOP_manage_pci_remove, | ||
80 | &manage_pci); | ||
81 | |||
82 | return r; | ||
83 | } | ||
84 | |||
85 | static int xen_pci_notifier(struct notifier_block *nb, | ||
86 | unsigned long action, void *data) | ||
87 | { | ||
88 | struct device *dev = data; | ||
89 | int r = 0; | ||
90 | |||
91 | switch (action) { | ||
92 | case BUS_NOTIFY_ADD_DEVICE: | ||
93 | r = xen_add_device(dev); | ||
94 | break; | ||
95 | case BUS_NOTIFY_DEL_DEVICE: | ||
96 | r = xen_remove_device(dev); | ||
97 | break; | ||
98 | default: | ||
99 | break; | ||
100 | } | ||
101 | |||
102 | return r; | ||
103 | } | ||
104 | |||
105 | struct notifier_block device_nb = { | ||
106 | .notifier_call = xen_pci_notifier, | ||
107 | }; | ||
108 | |||
109 | static int __init register_xen_pci_notifier(void) | ||
110 | { | ||
111 | if (!xen_initial_domain()) | ||
112 | return 0; | ||
113 | |||
114 | return bus_register_notifier(&pci_bus_type, &device_nb); | ||
115 | } | ||
116 | |||
117 | arch_initcall(register_xen_pci_notifier); | ||
diff --git a/drivers/xen/xenbus/xenbus_client.c b/drivers/xen/xenbus/xenbus_client.c index 7e49527189b6..cdacf923e073 100644 --- a/drivers/xen/xenbus/xenbus_client.c +++ b/drivers/xen/xenbus/xenbus_client.c | |||
@@ -50,6 +50,8 @@ const char *xenbus_strstate(enum xenbus_state state) | |||
50 | [ XenbusStateConnected ] = "Connected", | 50 | [ XenbusStateConnected ] = "Connected", |
51 | [ XenbusStateClosing ] = "Closing", | 51 | [ XenbusStateClosing ] = "Closing", |
52 | [ XenbusStateClosed ] = "Closed", | 52 | [ XenbusStateClosed ] = "Closed", |
53 | [XenbusStateReconfiguring] = "Reconfiguring", | ||
54 | [XenbusStateReconfigured] = "Reconfigured", | ||
53 | }; | 55 | }; |
54 | return (state < ARRAY_SIZE(name)) ? name[state] : "INVALID"; | 56 | return (state < ARRAY_SIZE(name)) ? name[state] : "INVALID"; |
55 | } | 57 | } |
diff --git a/drivers/xen/xenbus/xenbus_probe.c b/drivers/xen/xenbus/xenbus_probe.c index 132939f36020..deb9c4ba3a93 100644 --- a/drivers/xen/xenbus/xenbus_probe.c +++ b/drivers/xen/xenbus/xenbus_probe.c | |||
@@ -803,6 +803,7 @@ device_initcall(xenbus_probe_initcall); | |||
803 | static int __init xenbus_init(void) | 803 | static int __init xenbus_init(void) |
804 | { | 804 | { |
805 | int err = 0; | 805 | int err = 0; |
806 | unsigned long page = 0; | ||
806 | 807 | ||
807 | DPRINTK(""); | 808 | DPRINTK(""); |
808 | 809 | ||
@@ -823,7 +824,31 @@ static int __init xenbus_init(void) | |||
823 | * Domain0 doesn't have a store_evtchn or store_mfn yet. | 824 | * Domain0 doesn't have a store_evtchn or store_mfn yet. |
824 | */ | 825 | */ |
825 | if (xen_initial_domain()) { | 826 | if (xen_initial_domain()) { |
826 | /* dom0 not yet supported */ | 827 | struct evtchn_alloc_unbound alloc_unbound; |
828 | |||
829 | /* Allocate Xenstore page */ | ||
830 | page = get_zeroed_page(GFP_KERNEL); | ||
831 | if (!page) | ||
832 | goto out_error; | ||
833 | |||
834 | xen_store_mfn = xen_start_info->store_mfn = | ||
835 | pfn_to_mfn(virt_to_phys((void *)page) >> | ||
836 | PAGE_SHIFT); | ||
837 | |||
838 | /* Next allocate a local port which xenstored can bind to */ | ||
839 | alloc_unbound.dom = DOMID_SELF; | ||
840 | alloc_unbound.remote_dom = 0; | ||
841 | |||
842 | err = HYPERVISOR_event_channel_op(EVTCHNOP_alloc_unbound, | ||
843 | &alloc_unbound); | ||
844 | if (err == -ENOSYS) | ||
845 | goto out_error; | ||
846 | |||
847 | BUG_ON(err); | ||
848 | xen_store_evtchn = xen_start_info->store_evtchn = | ||
849 | alloc_unbound.port; | ||
850 | |||
851 | xen_store_interface = mfn_to_virt(xen_store_mfn); | ||
827 | } else { | 852 | } else { |
828 | if (xen_hvm_domain()) { | 853 | if (xen_hvm_domain()) { |
829 | uint64_t v = 0; | 854 | uint64_t v = 0; |
@@ -869,6 +894,8 @@ static int __init xenbus_init(void) | |||
869 | bus_unregister(&xenbus_frontend.bus); | 894 | bus_unregister(&xenbus_frontend.bus); |
870 | 895 | ||
871 | out_error: | 896 | out_error: |
897 | if (page != 0) | ||
898 | free_page(page); | ||
872 | return err; | 899 | return err; |
873 | } | 900 | } |
874 | 901 | ||