aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/xen
diff options
context:
space:
mode:
authorJeremy Fitzhardinge <jeremy.fitzhardinge@citrix.com>2010-11-16 14:06:22 -0500
committerJeremy Fitzhardinge <jeremy.fitzhardinge@citrix.com>2010-11-16 14:06:22 -0500
commit20b4755e4fbb226eb42951bd40b53fcbce9ef944 (patch)
tree43da70e0b32ee423d3643ecd422821383411ab72 /drivers/xen
parent744f9f104ea262de1dc3e29265870c649f0d9473 (diff)
parente53beacd23d9cb47590da6a7a7f6d417b941a994 (diff)
Merge commit 'v2.6.37-rc2' into upstream/xenfs
* commit 'v2.6.37-rc2': (10093 commits) Linux 2.6.37-rc2 capabilities/syslog: open code cap_syslog logic to fix build failure i2c: Sanity checks on adapter registration i2c: Mark i2c_adapter.id as deprecated i2c: Drivers shouldn't include <linux/i2c-id.h> i2c: Delete unused adapter IDs i2c: Remove obsolete cleanup for clientdata include/linux/kernel.h: Move logging bits to include/linux/printk.h Fix gcc 4.5.1 miscompiling drivers/char/i8k.c (again) hwmon: (w83795) Check for BEEP pin availability hwmon: (w83795) Clear intrusion alarm immediately hwmon: (w83795) Read the intrusion state properly hwmon: (w83795) Print the actual temperature channels as sources hwmon: (w83795) List all usable temperature sources hwmon: (w83795) Expose fan control method hwmon: (w83795) Fix fan control mode attributes hwmon: (lm95241) Check validity of input values hwmon: Change mail address of Hans J. Koch PCI: sysfs: fix printk warnings GFS2: Fix inode deallocation race ...
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.c656
-rw-r--r--drivers/xen/evtchn.c1
-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
-rw-r--r--drivers/xen/xenfs/super.c9
-rw-r--r--drivers/xen/xenfs/xenbus.c1
10 files changed, 756 insertions, 77 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 13365ba35218..321a0c8346e5 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)
@@ -261,7 +296,7 @@ static void init_evtchn_cpu_bindings(void)
261 } 296 }
262#endif 297#endif
263 298
264 memset(cpu_evtchn_mask(0), ~0, sizeof(cpu_evtchn_mask(0))); 299 memset(cpu_evtchn_mask(0), ~0, sizeof(struct cpu_evtchn_s));
265} 300}
266 301
267static inline void clear_evtchn(int port) 302static inline void clear_evtchn(int port)
@@ -336,36 +371,414 @@ 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 int irq; 399 struct irq_data *data;
342 struct irq_desc *desc; 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)
345 desc = irq_to_desc(irq); 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--) {
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 (desc == NULL) 410 if (!data)
348 break; 411 break;
349 if (desc->chip == &no_irq_chip) 412 if (data->chip == &no_irq_chip)
350 break; 413 break;
351 if (desc->chip != &xen_dynamic_chip) 414 if (data->chip != &xen_dynamic_chip)
352 continue; 415 continue;
353 if (irq_info[irq].type == IRQT_UNBOUND) 416 if (irq_info[irq].type == IRQT_UNBOUND)
354 break; 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 desc = irq_to_desc_alloc_node(irq, 0); 423 res = irq_alloc_desc_at(irq, 0);
361 if (WARN_ON(desc == NULL)) 424
425 if (WARN_ON(res != irq))
362 return -1; 426 return -1;
363 427
364 dynamic_irq_init_keep_chip_data(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);
365 656
366 return irq; 657 return irq;
367} 658}
368 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);
780}
781
369int bind_evtchn_to_irq(unsigned int evtchn) 782int bind_evtchn_to_irq(unsigned int evtchn)
370{ 783{
371 int irq; 784 int irq;
@@ -378,7 +791,7 @@ int bind_evtchn_to_irq(unsigned int evtchn)
378 irq = find_unbound_irq(); 791 irq = find_unbound_irq();
379 792
380 set_irq_chip_and_handler_name(irq, &xen_dynamic_chip, 793 set_irq_chip_and_handler_name(irq, &xen_dynamic_chip,
381 handle_edge_irq, "event"); 794 handle_fasteoi_irq, "event");
382 795
383 evtchn_to_irq[evtchn] = irq; 796 evtchn_to_irq[evtchn] = irq;
384 irq_info[irq] = mk_evtchn_info(evtchn); 797 irq_info[irq] = mk_evtchn_info(evtchn);
@@ -426,7 +839,7 @@ static int bind_ipi_to_irq(unsigned int ipi, unsigned int cpu)
426} 839}
427 840
428 841
429static int bind_virq_to_irq(unsigned int virq, unsigned int cpu) 842int bind_virq_to_irq(unsigned int virq, unsigned int cpu)
430{ 843{
431 struct evtchn_bind_virq bind_virq; 844 struct evtchn_bind_virq bind_virq;
432 int evtchn, irq; 845 int evtchn, irq;
@@ -436,6 +849,11 @@ static int bind_virq_to_irq(unsigned int virq, unsigned int cpu)
436 irq = per_cpu(virq_to_irq, cpu)[virq]; 849 irq = per_cpu(virq_to_irq, cpu)[virq];
437 850
438 if (irq == -1) { 851 if (irq == -1) {
852 irq = find_unbound_irq();
853
854 set_irq_chip_and_handler_name(irq, &xen_percpu_chip,
855 handle_percpu_irq, "virq");
856
439 bind_virq.virq = virq; 857 bind_virq.virq = virq;
440 bind_virq.vcpu = cpu; 858 bind_virq.vcpu = cpu;
441 if (HYPERVISOR_event_channel_op(EVTCHNOP_bind_virq, 859 if (HYPERVISOR_event_channel_op(EVTCHNOP_bind_virq,
@@ -443,11 +861,6 @@ static int bind_virq_to_irq(unsigned int virq, unsigned int cpu)
443 BUG(); 861 BUG();
444 evtchn = bind_virq.port; 862 evtchn = bind_virq.port;
445 863
446 irq = find_unbound_irq();
447
448 set_irq_chip_and_handler_name(irq, &xen_percpu_chip,
449 handle_percpu_irq, "virq");
450
451 evtchn_to_irq[evtchn] = irq; 864 evtchn_to_irq[evtchn] = irq;
452 irq_info[irq] = mk_virq_info(evtchn, virq); 865 irq_info[irq] = mk_virq_info(evtchn, virq);
453 866
@@ -495,7 +908,7 @@ static void unbind_from_irq(unsigned int irq)
495 if (irq_info[irq].type != IRQT_UNBOUND) { 908 if (irq_info[irq].type != IRQT_UNBOUND) {
496 irq_info[irq] = mk_unbound_info(); 909 irq_info[irq] = mk_unbound_info();
497 910
498 dynamic_irq_cleanup(irq); 911 irq_free_desc(irq);
499 } 912 }
500 913
501 spin_unlock(&irq_mapping_update_lock); 914 spin_unlock(&irq_mapping_update_lock);
@@ -579,41 +992,75 @@ irqreturn_t xen_debug_interrupt(int irq, void *dev_id)
579{ 992{
580 struct shared_info *sh = HYPERVISOR_shared_info; 993 struct shared_info *sh = HYPERVISOR_shared_info;
581 int cpu = smp_processor_id(); 994 int cpu = smp_processor_id();
995 unsigned long *cpu_evtchn = cpu_evtchn_mask(cpu);
582 int i; 996 int i;
583 unsigned long flags; 997 unsigned long flags;
584 static DEFINE_SPINLOCK(debug_lock); 998 static DEFINE_SPINLOCK(debug_lock);
999 struct vcpu_info *v;
585 1000
586 spin_lock_irqsave(&debug_lock, flags); 1001 spin_lock_irqsave(&debug_lock, flags);
587 1002
588 printk("vcpu %d\n ", cpu); 1003 printk("\nvcpu %d\n ", cpu);
589 1004
590 for_each_online_cpu(i) { 1005 for_each_online_cpu(i) {
591 struct vcpu_info *v = per_cpu(xen_vcpu, i); 1006 int pending;
592 printk("%d: masked=%d pending=%d event_sel %08lx\n ", i, 1007 v = per_cpu(xen_vcpu, i);
593 (get_irq_regs() && i == cpu) ? xen_irqs_disabled(get_irq_regs()) : v->evtchn_upcall_mask, 1008 pending = (get_irq_regs() && i == cpu)
594 v->evtchn_upcall_pending, 1009 ? xen_irqs_disabled(get_irq_regs())
595 v->evtchn_pending_sel); 1010 : v->evtchn_upcall_mask;
1011 printk("%d: masked=%d pending=%d event_sel %0*lx\n ", i,
1012 pending, v->evtchn_upcall_pending,
1013 (int)(sizeof(v->evtchn_pending_sel)*2),
1014 v->evtchn_pending_sel);
1015 }
1016 v = per_cpu(xen_vcpu, cpu);
1017
1018 printk("\npending:\n ");
1019 for (i = ARRAY_SIZE(sh->evtchn_pending)-1; i >= 0; i--)
1020 printk("%0*lx%s", (int)sizeof(sh->evtchn_pending[0])*2,
1021 sh->evtchn_pending[i],
1022 i % 8 == 0 ? "\n " : " ");
1023 printk("\nglobal mask:\n ");
1024 for (i = ARRAY_SIZE(sh->evtchn_mask)-1; i >= 0; i--)
1025 printk("%0*lx%s",
1026 (int)(sizeof(sh->evtchn_mask[0])*2),
1027 sh->evtchn_mask[i],
1028 i % 8 == 0 ? "\n " : " ");
1029
1030 printk("\nglobally unmasked:\n ");
1031 for (i = ARRAY_SIZE(sh->evtchn_mask)-1; i >= 0; i--)
1032 printk("%0*lx%s", (int)(sizeof(sh->evtchn_mask[0])*2),
1033 sh->evtchn_pending[i] & ~sh->evtchn_mask[i],
1034 i % 8 == 0 ? "\n " : " ");
1035
1036 printk("\nlocal cpu%d mask:\n ", cpu);
1037 for (i = (NR_EVENT_CHANNELS/BITS_PER_LONG)-1; i >= 0; i--)
1038 printk("%0*lx%s", (int)(sizeof(cpu_evtchn[0])*2),
1039 cpu_evtchn[i],
1040 i % 8 == 0 ? "\n " : " ");
1041
1042 printk("\nlocally unmasked:\n ");
1043 for (i = ARRAY_SIZE(sh->evtchn_mask)-1; i >= 0; i--) {
1044 unsigned long pending = sh->evtchn_pending[i]
1045 & ~sh->evtchn_mask[i]
1046 & cpu_evtchn[i];
1047 printk("%0*lx%s", (int)(sizeof(sh->evtchn_mask[0])*2),
1048 pending, i % 8 == 0 ? "\n " : " ");
596 } 1049 }
597 printk("pending:\n ");
598 for(i = ARRAY_SIZE(sh->evtchn_pending)-1; i >= 0; i--)
599 printk("%08lx%s", sh->evtchn_pending[i],
600 i % 8 == 0 ? "\n " : " ");
601 printk("\nmasks:\n ");
602 for(i = ARRAY_SIZE(sh->evtchn_mask)-1; i >= 0; i--)
603 printk("%08lx%s", sh->evtchn_mask[i],
604 i % 8 == 0 ? "\n " : " ");
605
606 printk("\nunmasked:\n ");
607 for(i = ARRAY_SIZE(sh->evtchn_mask)-1; i >= 0; i--)
608 printk("%08lx%s", sh->evtchn_pending[i] & ~sh->evtchn_mask[i],
609 i % 8 == 0 ? "\n " : " ");
610 1050
611 printk("\npending list:\n"); 1051 printk("\npending list:\n");
612 for(i = 0; i < NR_EVENT_CHANNELS; i++) { 1052 for (i = 0; i < NR_EVENT_CHANNELS; i++) {
613 if (sync_test_bit(i, sh->evtchn_pending)) { 1053 if (sync_test_bit(i, sh->evtchn_pending)) {
614 printk(" %d: event %d -> irq %d\n", 1054 int word_idx = i / BITS_PER_LONG;
1055 printk(" %d: event %d -> irq %d%s%s%s\n",
615 cpu_from_evtchn(i), i, 1056 cpu_from_evtchn(i), i,
616 evtchn_to_irq[i]); 1057 evtchn_to_irq[i],
1058 sync_test_bit(word_idx, &v->evtchn_pending_sel)
1059 ? "" : " l2-clear",
1060 !sync_test_bit(i, sh->evtchn_mask)
1061 ? "" : " globally-masked",
1062 sync_test_bit(i, cpu_evtchn)
1063 ? "" : " locally-masked");
617 } 1064 }
618 } 1065 }
619 1066
@@ -664,6 +1111,9 @@ static void __xen_evtchn_do_upcall(void)
664 int irq = evtchn_to_irq[port]; 1111 int irq = evtchn_to_irq[port];
665 struct irq_desc *desc; 1112 struct irq_desc *desc;
666 1113
1114 mask_evtchn(port);
1115 clear_evtchn(port);
1116
667 if (irq != -1) { 1117 if (irq != -1) {
668 desc = irq_to_desc(irq); 1118 desc = irq_to_desc(irq);
669 if (desc) 1119 if (desc)
@@ -801,10 +1251,10 @@ static void ack_dynirq(unsigned int irq)
801{ 1251{
802 int evtchn = evtchn_from_irq(irq); 1252 int evtchn = evtchn_from_irq(irq);
803 1253
804 move_native_irq(irq); 1254 move_masked_irq(irq);
805 1255
806 if (VALID_EVTCHN(evtchn)) 1256 if (VALID_EVTCHN(evtchn))
807 clear_evtchn(evtchn); 1257 unmask_evtchn(evtchn);
808} 1258}
809 1259
810static int retrigger_dynirq(unsigned int irq) 1260static int retrigger_dynirq(unsigned int irq)
@@ -849,9 +1299,6 @@ static void restore_cpu_virqs(unsigned int cpu)
849 evtchn_to_irq[evtchn] = irq; 1299 evtchn_to_irq[evtchn] = irq;
850 irq_info[irq] = mk_virq_info(evtchn, virq); 1300 irq_info[irq] = mk_virq_info(evtchn, virq);
851 bind_evtchn_to_cpu(evtchn, cpu); 1301 bind_evtchn_to_cpu(evtchn, cpu);
852
853 /* Ready for use. */
854 unmask_evtchn(evtchn);
855 } 1302 }
856} 1303}
857 1304
@@ -877,10 +1324,6 @@ static void restore_cpu_ipis(unsigned int cpu)
877 evtchn_to_irq[evtchn] = irq; 1324 evtchn_to_irq[evtchn] = irq;
878 irq_info[irq] = mk_ipi_info(evtchn, ipi); 1325 irq_info[irq] = mk_ipi_info(evtchn, ipi);
879 bind_evtchn_to_cpu(evtchn, cpu); 1326 bind_evtchn_to_cpu(evtchn, cpu);
880
881 /* Ready for use. */
882 unmask_evtchn(evtchn);
883
884 } 1327 }
885} 1328}
886 1329
@@ -892,7 +1335,7 @@ void xen_clear_irq_pending(int irq)
892 if (VALID_EVTCHN(evtchn)) 1335 if (VALID_EVTCHN(evtchn))
893 clear_evtchn(evtchn); 1336 clear_evtchn(evtchn);
894} 1337}
895 1338EXPORT_SYMBOL(xen_clear_irq_pending);
896void xen_set_irq_pending(int irq) 1339void xen_set_irq_pending(int irq)
897{ 1340{
898 int evtchn = evtchn_from_irq(irq); 1341 int evtchn = evtchn_from_irq(irq);
@@ -912,9 +1355,9 @@ bool xen_test_irq_pending(int irq)
912 return ret; 1355 return ret;
913} 1356}
914 1357
915/* Poll waiting for an irq to become pending. In the usual case, the 1358/* Poll waiting for an irq to become pending with timeout. In the usual case,
916 irq will be disabled so it won't deliver an interrupt. */ 1359 * the irq will be disabled so it won't deliver an interrupt. */
917void xen_poll_irq(int irq) 1360void xen_poll_irq_timeout(int irq, u64 timeout)
918{ 1361{
919 evtchn_port_t evtchn = evtchn_from_irq(irq); 1362 evtchn_port_t evtchn = evtchn_from_irq(irq);
920 1363
@@ -922,17 +1365,25 @@ void xen_poll_irq(int irq)
922 struct sched_poll poll; 1365 struct sched_poll poll;
923 1366
924 poll.nr_ports = 1; 1367 poll.nr_ports = 1;
925 poll.timeout = 0; 1368 poll.timeout = timeout;
926 set_xen_guest_handle(poll.ports, &evtchn); 1369 set_xen_guest_handle(poll.ports, &evtchn);
927 1370
928 if (HYPERVISOR_sched_op(SCHEDOP_poll, &poll) != 0) 1371 if (HYPERVISOR_sched_op(SCHEDOP_poll, &poll) != 0)
929 BUG(); 1372 BUG();
930 } 1373 }
931} 1374}
1375EXPORT_SYMBOL(xen_poll_irq_timeout);
1376/* Poll waiting for an irq to become pending. In the usual case, the
1377 * irq will be disabled so it won't deliver an interrupt. */
1378void xen_poll_irq(int irq)
1379{
1380 xen_poll_irq_timeout(irq, 0 /* no timeout */);
1381}
932 1382
933void xen_irq_resume(void) 1383void xen_irq_resume(void)
934{ 1384{
935 unsigned int cpu, irq, evtchn; 1385 unsigned int cpu, irq, evtchn;
1386 struct irq_desc *desc;
936 1387
937 init_evtchn_cpu_bindings(); 1388 init_evtchn_cpu_bindings();
938 1389
@@ -951,6 +1402,23 @@ void xen_irq_resume(void)
951 restore_cpu_virqs(cpu); 1402 restore_cpu_virqs(cpu);
952 restore_cpu_ipis(cpu); 1403 restore_cpu_ipis(cpu);
953 } 1404 }
1405
1406 /*
1407 * Unmask any IRQF_NO_SUSPEND IRQs which are enabled. These
1408 * are not handled by the IRQ core.
1409 */
1410 for_each_irq_desc(irq, desc) {
1411 if (!desc->action || !(desc->action->flags & IRQF_NO_SUSPEND))
1412 continue;
1413 if (desc->status & IRQ_DISABLED)
1414 continue;
1415
1416 evtchn = evtchn_from_irq(irq);
1417 if (evtchn == -1)
1418 continue;
1419
1420 unmask_evtchn(evtchn);
1421 }
954} 1422}
955 1423
956static struct irq_chip xen_dynamic_chip __read_mostly = { 1424static struct irq_chip xen_dynamic_chip __read_mostly = {
@@ -960,8 +1428,28 @@ static struct irq_chip xen_dynamic_chip __read_mostly = {
960 .mask = disable_dynirq, 1428 .mask = disable_dynirq,
961 .unmask = enable_dynirq, 1429 .unmask = enable_dynirq,
962 1430
963 .ack = ack_dynirq, 1431 .eoi = ack_dynirq,
1432 .set_affinity = set_affinity_irq,
1433 .retrigger = retrigger_dynirq,
1434};
1435
1436static struct irq_chip xen_pirq_chip __read_mostly = {
1437 .name = "xen-pirq",
1438
1439 .startup = startup_pirq,
1440 .shutdown = shutdown_pirq,
1441
1442 .enable = enable_pirq,
1443 .unmask = enable_pirq,
1444
1445 .disable = disable_pirq,
1446 .mask = disable_pirq,
1447
1448 .ack = ack_pirq,
1449 .end = end_pirq,
1450
964 .set_affinity = set_affinity_irq, 1451 .set_affinity = set_affinity_irq,
1452
965 .retrigger = retrigger_dynirq, 1453 .retrigger = retrigger_dynirq,
966}; 1454};
967 1455
@@ -1015,11 +1503,32 @@ void xen_callback_vector(void) {}
1015 1503
1016void __init xen_init_IRQ(void) 1504void __init xen_init_IRQ(void)
1017{ 1505{
1018 int i; 1506 int i, rc;
1507 struct physdev_nr_pirqs op_nr_pirqs;
1019 1508
1020 cpu_evtchn_mask_p = kcalloc(nr_cpu_ids, sizeof(struct cpu_evtchn_s), 1509 cpu_evtchn_mask_p = kcalloc(nr_cpu_ids, sizeof(struct cpu_evtchn_s),
1021 GFP_KERNEL); 1510 GFP_KERNEL);
1022 BUG_ON(cpu_evtchn_mask_p == NULL); 1511 irq_info = kcalloc(nr_irqs, sizeof(*irq_info), GFP_KERNEL);
1512
1513 rc = HYPERVISOR_physdev_op(PHYSDEVOP_get_nr_pirqs, &op_nr_pirqs);
1514 if (rc < 0) {
1515 nr_pirqs = nr_irqs;
1516 if (rc != -ENOSYS)
1517 printk(KERN_WARNING "PHYSDEVOP_get_nr_pirqs returned rc=%d\n", rc);
1518 } else {
1519 if (xen_pv_domain() && !xen_initial_domain())
1520 nr_pirqs = max((int)op_nr_pirqs.nr_pirqs, nr_irqs);
1521 else
1522 nr_pirqs = op_nr_pirqs.nr_pirqs;
1523 }
1524 pirq_to_irq = kcalloc(nr_pirqs, sizeof(*pirq_to_irq), GFP_KERNEL);
1525 for (i = 0; i < nr_pirqs; i++)
1526 pirq_to_irq[i] = -1;
1527
1528 evtchn_to_irq = kcalloc(NR_EVENT_CHANNELS, sizeof(*evtchn_to_irq),
1529 GFP_KERNEL);
1530 for (i = 0; i < NR_EVENT_CHANNELS; i++)
1531 evtchn_to_irq[i] = -1;
1023 1532
1024 init_evtchn_cpu_bindings(); 1533 init_evtchn_cpu_bindings();
1025 1534
@@ -1030,7 +1539,12 @@ void __init xen_init_IRQ(void)
1030 if (xen_hvm_domain()) { 1539 if (xen_hvm_domain()) {
1031 xen_callback_vector(); 1540 xen_callback_vector();
1032 native_init_IRQ(); 1541 native_init_IRQ();
1542 /* pci_xen_hvm_init must be called after native_init_IRQ so that
1543 * __acpi_register_gsi can point at the right function */
1544 pci_xen_hvm_init();
1033 } else { 1545 } else {
1034 irq_ctx_init(smp_processor_id()); 1546 irq_ctx_init(smp_processor_id());
1547 if (xen_initial_domain())
1548 xen_setup_pirqs();
1035 } 1549 }
1036} 1550}
diff --git a/drivers/xen/evtchn.c b/drivers/xen/evtchn.c
index 66e185cfe92f..fec6ba3c08a8 100644
--- a/drivers/xen/evtchn.c
+++ b/drivers/xen/evtchn.c
@@ -467,6 +467,7 @@ static const struct file_operations evtchn_fops = {
467 .fasync = evtchn_fasync, 467 .fasync = evtchn_fasync,
468 .open = evtchn_open, 468 .open = evtchn_open,
469 .release = evtchn_release, 469 .release = evtchn_release,
470 .llseek = noop_llseek,
470}; 471};
471 472
472static struct miscdevice evtchn_miscdev = { 473static struct miscdevice evtchn_miscdev = {
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
diff --git a/drivers/xen/xenfs/super.c b/drivers/xen/xenfs/super.c
index 984891e9a394..f6339d11d59c 100644
--- a/drivers/xen/xenfs/super.c
+++ b/drivers/xen/xenfs/super.c
@@ -93,6 +93,7 @@ static ssize_t capabilities_read(struct file *file, char __user *buf,
93 93
94static const struct file_operations capabilities_file_ops = { 94static const struct file_operations capabilities_file_ops = {
95 .read = capabilities_read, 95 .read = capabilities_read,
96 .llseek = default_llseek,
96}; 97};
97 98
98static int xenfs_fill_super(struct super_block *sb, void *data, int silent) 99static int xenfs_fill_super(struct super_block *sb, void *data, int silent)
@@ -120,17 +121,17 @@ static int xenfs_fill_super(struct super_block *sb, void *data, int silent)
120 return rc; 121 return rc;
121} 122}
122 123
123static int xenfs_get_sb(struct file_system_type *fs_type, 124static int xenfs_mount(struct file_system_type *fs_type,
124 int flags, const char *dev_name, 125 int flags, const char *dev_name,
125 void *data, struct vfsmount *mnt) 126 void *data)
126{ 127{
127 return get_sb_single(fs_type, flags, data, xenfs_fill_super, mnt); 128 return mount_single(fs_type, flags, data, xenfs_fill_super);
128} 129}
129 130
130static struct file_system_type xenfs_type = { 131static struct file_system_type xenfs_type = {
131 .owner = THIS_MODULE, 132 .owner = THIS_MODULE,
132 .name = "xenfs", 133 .name = "xenfs",
133 .get_sb = xenfs_get_sb, 134 .mount = xenfs_mount,
134 .kill_sb = kill_litter_super, 135 .kill_sb = kill_litter_super,
135}; 136};
136 137
diff --git a/drivers/xen/xenfs/xenbus.c b/drivers/xen/xenfs/xenbus.c
index 3b39c3752e21..1c1236087f78 100644
--- a/drivers/xen/xenfs/xenbus.c
+++ b/drivers/xen/xenfs/xenbus.c
@@ -594,4 +594,5 @@ const struct file_operations xenbus_file_ops = {
594 .open = xenbus_file_open, 594 .open = xenbus_file_open,
595 .release = xenbus_file_release, 595 .release = xenbus_file_release,
596 .poll = xenbus_file_poll, 596 .poll = xenbus_file_poll,
597 .llseek = no_llseek,
597}; 598};