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/xen/events.c | |
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/xen/events.c')
-rw-r--r-- | drivers/xen/events.c | 509 |
1 files changed, 488 insertions, 21 deletions
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 | } |