aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/xen
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2010-10-28 20:11:17 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2010-10-28 20:11:17 -0400
commit18cb657ca1bafe635f368346a1676fb04c512edf (patch)
treeb0eb6a4ceddf98e7bf820be7ff24bf131ff56b0c /drivers/xen
parent2301b65b86df8b80e6779ce9885ad62a5c4adc38 (diff)
parente28c31a96b1570f17731b18e8efabb7308d0c22c (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/xen')
-rw-r--r--drivers/xen/Kconfig3
-rw-r--r--drivers/xen/Makefile2
-rw-r--r--drivers/xen/biomerge.c13
-rw-r--r--drivers/xen/events.c509
-rw-r--r--drivers/xen/pci.c117
-rw-r--r--drivers/xen/xenbus/xenbus_client.c2
-rw-r--r--drivers/xen/xenbus/xenbus_probe.c29
7 files changed, 652 insertions, 23 deletions
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
75config SWIOTLB_XEN 75config SWIOTLB_XEN
76 def_bool y 76 def_bool y
77 depends on SWIOTLB 77 depends on PCI
78 select SWIOTLB
78 79
79endmenu 80endmenu
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/
4nostackp := $(call cc-option, -fno-stack-protector) 4nostackp := $(call cc-option, -fno-stack-protector)
5CFLAGS_features.o := $(nostackp) 5CFLAGS_features.o := $(nostackp)
6 6
7obj-$(CONFIG_BLOCK) += biomerge.o
7obj-$(CONFIG_HOTPLUG_CPU) += cpu_hotplug.o 8obj-$(CONFIG_HOTPLUG_CPU) += cpu_hotplug.o
8obj-$(CONFIG_XEN_XENCOMM) += xencomm.o 9obj-$(CONFIG_XEN_XENCOMM) += xencomm.o
9obj-$(CONFIG_XEN_BALLOON) += balloon.o 10obj-$(CONFIG_XEN_BALLOON) += balloon.o
@@ -12,3 +13,4 @@ obj-$(CONFIG_XENFS) += xenfs/
12obj-$(CONFIG_XEN_SYS_HYPERVISOR) += sys-hypervisor.o 13obj-$(CONFIG_XEN_SYS_HYPERVISOR) += sys-hypervisor.o
13obj-$(CONFIG_XEN_PLATFORM_PCI) += platform-pci.o 14obj-$(CONFIG_XEN_PLATFORM_PCI) += platform-pci.o
14obj-$(CONFIG_SWIOTLB_XEN) += swiotlb-xen.o 15obj-$(CONFIG_SWIOTLB_XEN) += swiotlb-xen.o
16obj-$(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
5bool 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
97static struct irq_info irq_info[NR_IRQS]; 106static struct irq_info *irq_info;
107static int *pirq_to_irq;
108static int nr_pirqs;
98 109
99static int evtchn_to_irq[NR_EVENT_CHANNELS] = { 110static int *evtchn_to_irq;
100 [0 ... NR_EVENT_CHANNELS-1] = -1
101};
102struct cpu_evtchn_s { 111struct 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};
105static struct cpu_evtchn_s *cpu_evtchn_mask_p; 114
115static __initdata struct cpu_evtchn_s init_evtchn_mask = {
116 .bits[0 ... (NR_EVENT_CHANNELS/BITS_PER_LONG)-1] = ~0ul,
117};
118static struct cpu_evtchn_s *cpu_evtchn_mask_p = &init_evtchn_mask;
119
106static inline unsigned long *cpu_evtchn_mask(int cpu) 120static 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
114static struct irq_chip xen_dynamic_chip; 128static struct irq_chip xen_dynamic_chip;
115static struct irq_chip xen_percpu_chip; 129static struct irq_chip xen_percpu_chip;
130static struct irq_chip xen_pirq_chip;
116 131
117/* Constructor for packed IRQ information. */ 132/* Constructor for packed IRQ information. */
118static struct irq_info mk_unbound_info(void) 133static 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
141static struct irq_info mk_pirq_info(unsigned short evtchn, 156static 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
203static 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
187static unsigned gsi_from_irq(unsigned irq) 213static 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
254static 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
228static inline unsigned long active_evtchns(unsigned int cpu, 263static 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
374static 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 */
387static 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
339static int find_unbound_irq(void) 397static 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
430no_irqs:
431 panic("No available IRQ to bind to: increase nr_irqs!\n");
432}
433
434static bool identity_mapped_irq(unsigned irq)
435{
436 /* identity map all the hardware irqs */
437 return irq < get_nr_hw_irqs();
438}
439
440static 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
450static 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
466static bool probing_irq(int irq)
467{
468 struct irq_desc *desc = irq_to_desc(irq);
469
470 return desc && desc->action == NULL;
471}
472
473static 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
504out:
505 unmask_evtchn(evtchn);
506 pirq_unmask_notify(irq);
507
508 return 0;
509}
510
511static 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
533static void enable_pirq(unsigned int irq)
534{
535 startup_pirq(irq);
536}
537
538static void disable_pirq(unsigned int irq)
539{
540}
541
542static 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
554static 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
571static 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
588int 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 */
604int 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
654out:
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
664void 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
682out:
683 spin_unlock(&irq_mapping_update_lock);
684}
685
686int 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
735out:
736 spin_unlock(&irq_mapping_update_lock);
737 return irq;
738}
739#endif
740
741int 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
767out:
768 spin_unlock(&irq_mapping_update_lock);
769 return rc;
770}
771
772int xen_vector_from_irq(unsigned irq)
773{
774 return vector_from_irq(irq);
775}
776
777int xen_gsi_from_irq(unsigned irq)
778{
779 return gsi_from_irq(irq);
366} 780}
367 781
368int bind_evtchn_to_irq(unsigned int evtchn) 782int 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
428static int bind_virq_to_irq(unsigned int virq, unsigned int cpu) 842int 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 1345EXPORT_SYMBOL(xen_clear_irq_pending);
932void xen_set_irq_pending(int irq) 1346void 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. */
953void xen_poll_irq(int irq) 1367void 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}
1382EXPORT_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. */
1385void xen_poll_irq(int irq)
1386{
1387 xen_poll_irq_timeout(irq, 0 /* no timeout */);
1388}
968 1389
969void xen_irq_resume(void) 1390void 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
1425static 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
1004static struct irq_chip xen_percpu_chip __read_mostly = { 1445static 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
1052void __init xen_init_IRQ(void) 1493void __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
29static 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
70static 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
85static 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
105struct notifier_block device_nb = {
106 .notifier_call = xen_pci_notifier,
107};
108
109static 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
117arch_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);
803static int __init xenbus_init(void) 803static 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