IB/uverbs: Handle large number of entries in poll CQ
[linux-2.6/kvm.git] / drivers / xen / events.c
blob2811bb988ea0551b85bc4c77d15b8590382abdf4
1 /*
2 * Xen event channels
4 * Xen models interrupts with abstract event channels. Because each
5 * domain gets 1024 event channels, but NR_IRQ is not that large, we
6 * must dynamically map irqs<->event channels. The event channels
7 * interface with the rest of the kernel by defining a xen interrupt
8 * chip. When an event is recieved, it is mapped to an irq and sent
9 * through the normal interrupt processing path.
11 * There are four kinds of events which can be mapped to an event
12 * channel:
14 * 1. Inter-domain notifications. This includes all the virtual
15 * device events, since they're driven by front-ends in another domain
16 * (typically dom0).
17 * 2. VIRQs, typically used for timers. These are per-cpu events.
18 * 3. IPIs.
19 * 4. PIRQs - Hardware interrupts.
21 * Jeremy Fitzhardinge <jeremy@xensource.com>, XenSource Inc, 2007
24 #include <linux/linkage.h>
25 #include <linux/interrupt.h>
26 #include <linux/irq.h>
27 #include <linux/module.h>
28 #include <linux/string.h>
29 #include <linux/bootmem.h>
30 #include <linux/slab.h>
31 #include <linux/irqnr.h>
32 #include <linux/pci.h>
34 #include <asm/desc.h>
35 #include <asm/ptrace.h>
36 #include <asm/irq.h>
37 #include <asm/idle.h>
38 #include <asm/io_apic.h>
39 #include <asm/sync_bitops.h>
40 #include <asm/xen/pci.h>
41 #include <asm/xen/hypercall.h>
42 #include <asm/xen/hypervisor.h>
44 #include <xen/xen.h>
45 #include <xen/hvm.h>
46 #include <xen/xen-ops.h>
47 #include <xen/events.h>
48 #include <xen/interface/xen.h>
49 #include <xen/interface/event_channel.h>
50 #include <xen/interface/hvm/hvm_op.h>
51 #include <xen/interface/hvm/params.h>
54 * This lock protects updates to the following mapping and reference-count
55 * arrays. The lock does not need to be acquired to read the mapping tables.
57 static DEFINE_SPINLOCK(irq_mapping_update_lock);
59 /* IRQ <-> VIRQ mapping. */
60 static DEFINE_PER_CPU(int [NR_VIRQS], virq_to_irq) = {[0 ... NR_VIRQS-1] = -1};
62 /* IRQ <-> IPI mapping */
63 static DEFINE_PER_CPU(int [XEN_NR_IPIS], ipi_to_irq) = {[0 ... XEN_NR_IPIS-1] = -1};
65 /* Interrupt types. */
66 enum xen_irq_type {
67 IRQT_UNBOUND = 0,
68 IRQT_PIRQ,
69 IRQT_VIRQ,
70 IRQT_IPI,
71 IRQT_EVTCHN
75 * Packed IRQ information:
76 * type - enum xen_irq_type
77 * event channel - irq->event channel mapping
78 * cpu - cpu this event channel is bound to
79 * index - type-specific information:
80 * PIRQ - vector, with MSB being "needs EIO", or physical IRQ of the HVM
81 * guest, or GSI (real passthrough IRQ) of the device.
82 * VIRQ - virq number
83 * IPI - IPI vector
84 * EVTCHN -
86 struct irq_info
88 enum xen_irq_type type; /* type */
89 unsigned short evtchn; /* event channel */
90 unsigned short cpu; /* cpu bound */
92 union {
93 unsigned short virq;
94 enum ipi_vector ipi;
95 struct {
96 unsigned short pirq;
97 unsigned short gsi;
98 unsigned char vector;
99 unsigned char flags;
100 } pirq;
101 } u;
103 #define PIRQ_NEEDS_EOI (1 << 0)
104 #define PIRQ_SHAREABLE (1 << 1)
106 static struct irq_info *irq_info;
107 static int *pirq_to_irq;
108 static int nr_pirqs;
110 static int *evtchn_to_irq;
111 struct cpu_evtchn_s {
112 unsigned long bits[NR_EVENT_CHANNELS/BITS_PER_LONG];
115 static __initdata struct cpu_evtchn_s init_evtchn_mask = {
116 .bits[0 ... (NR_EVENT_CHANNELS/BITS_PER_LONG)-1] = ~0ul,
118 static struct cpu_evtchn_s *cpu_evtchn_mask_p = &init_evtchn_mask;
120 static inline unsigned long *cpu_evtchn_mask(int cpu)
122 return cpu_evtchn_mask_p[cpu].bits;
125 /* Xen will never allocate port zero for any purpose. */
126 #define VALID_EVTCHN(chn) ((chn) != 0)
128 static struct irq_chip xen_dynamic_chip;
129 static struct irq_chip xen_percpu_chip;
130 static struct irq_chip xen_pirq_chip;
132 /* Constructor for packed IRQ information. */
133 static struct irq_info mk_unbound_info(void)
135 return (struct irq_info) { .type = IRQT_UNBOUND };
138 static struct irq_info mk_evtchn_info(unsigned short evtchn)
140 return (struct irq_info) { .type = IRQT_EVTCHN, .evtchn = evtchn,
141 .cpu = 0 };
144 static struct irq_info mk_ipi_info(unsigned short evtchn, enum ipi_vector ipi)
146 return (struct irq_info) { .type = IRQT_IPI, .evtchn = evtchn,
147 .cpu = 0, .u.ipi = ipi };
150 static struct irq_info mk_virq_info(unsigned short evtchn, unsigned short virq)
152 return (struct irq_info) { .type = IRQT_VIRQ, .evtchn = evtchn,
153 .cpu = 0, .u.virq = virq };
156 static struct irq_info mk_pirq_info(unsigned short evtchn, unsigned short pirq,
157 unsigned short gsi, unsigned short vector)
159 return (struct irq_info) { .type = IRQT_PIRQ, .evtchn = evtchn,
160 .cpu = 0,
161 .u.pirq = { .pirq = pirq, .gsi = gsi, .vector = vector } };
165 * Accessors for packed IRQ information.
167 static struct irq_info *info_for_irq(unsigned irq)
169 return &irq_info[irq];
172 static unsigned int evtchn_from_irq(unsigned irq)
174 return info_for_irq(irq)->evtchn;
177 unsigned irq_from_evtchn(unsigned int evtchn)
179 return evtchn_to_irq[evtchn];
181 EXPORT_SYMBOL_GPL(irq_from_evtchn);
183 static enum ipi_vector ipi_from_irq(unsigned irq)
185 struct irq_info *info = info_for_irq(irq);
187 BUG_ON(info == NULL);
188 BUG_ON(info->type != IRQT_IPI);
190 return info->u.ipi;
193 static unsigned virq_from_irq(unsigned irq)
195 struct irq_info *info = info_for_irq(irq);
197 BUG_ON(info == NULL);
198 BUG_ON(info->type != IRQT_VIRQ);
200 return info->u.virq;
203 static unsigned pirq_from_irq(unsigned irq)
205 struct irq_info *info = info_for_irq(irq);
207 BUG_ON(info == NULL);
208 BUG_ON(info->type != IRQT_PIRQ);
210 return info->u.pirq.pirq;
213 static unsigned gsi_from_irq(unsigned irq)
215 struct irq_info *info = info_for_irq(irq);
217 BUG_ON(info == NULL);
218 BUG_ON(info->type != IRQT_PIRQ);
220 return info->u.pirq.gsi;
223 static unsigned vector_from_irq(unsigned irq)
225 struct irq_info *info = info_for_irq(irq);
227 BUG_ON(info == NULL);
228 BUG_ON(info->type != IRQT_PIRQ);
230 return info->u.pirq.vector;
233 static enum xen_irq_type type_from_irq(unsigned irq)
235 return info_for_irq(irq)->type;
238 static unsigned cpu_from_irq(unsigned irq)
240 return info_for_irq(irq)->cpu;
243 static unsigned int cpu_from_evtchn(unsigned int evtchn)
245 int irq = evtchn_to_irq[evtchn];
246 unsigned ret = 0;
248 if (irq != -1)
249 ret = cpu_from_irq(irq);
251 return ret;
254 static bool pirq_needs_eoi(unsigned irq)
256 struct irq_info *info = info_for_irq(irq);
258 BUG_ON(info->type != IRQT_PIRQ);
260 return info->u.pirq.flags & PIRQ_NEEDS_EOI;
263 static inline unsigned long active_evtchns(unsigned int cpu,
264 struct shared_info *sh,
265 unsigned int idx)
267 return (sh->evtchn_pending[idx] &
268 cpu_evtchn_mask(cpu)[idx] &
269 ~sh->evtchn_mask[idx]);
272 static void bind_evtchn_to_cpu(unsigned int chn, unsigned int cpu)
274 int irq = evtchn_to_irq[chn];
276 BUG_ON(irq == -1);
277 #ifdef CONFIG_SMP
278 cpumask_copy(irq_to_desc(irq)->affinity, cpumask_of(cpu));
279 #endif
281 clear_bit(chn, cpu_evtchn_mask(cpu_from_irq(irq)));
282 set_bit(chn, cpu_evtchn_mask(cpu));
284 irq_info[irq].cpu = cpu;
287 static void init_evtchn_cpu_bindings(void)
289 int i;
290 #ifdef CONFIG_SMP
291 struct irq_desc *desc;
293 /* By default all event channels notify CPU#0. */
294 for_each_irq_desc(i, desc) {
295 cpumask_copy(desc->affinity, cpumask_of(0));
297 #endif
299 for_each_possible_cpu(i)
300 memset(cpu_evtchn_mask(i),
301 (i == 0) ? ~0 : 0, sizeof(struct cpu_evtchn_s));
305 static inline void clear_evtchn(int port)
307 struct shared_info *s = HYPERVISOR_shared_info;
308 sync_clear_bit(port, &s->evtchn_pending[0]);
311 static inline void set_evtchn(int port)
313 struct shared_info *s = HYPERVISOR_shared_info;
314 sync_set_bit(port, &s->evtchn_pending[0]);
317 static inline int test_evtchn(int port)
319 struct shared_info *s = HYPERVISOR_shared_info;
320 return sync_test_bit(port, &s->evtchn_pending[0]);
325 * notify_remote_via_irq - send event to remote end of event channel via irq
326 * @irq: irq of event channel to send event to
328 * Unlike notify_remote_via_evtchn(), this is safe to use across
329 * save/restore. Notifications on a broken connection are silently
330 * dropped.
332 void notify_remote_via_irq(int irq)
334 int evtchn = evtchn_from_irq(irq);
336 if (VALID_EVTCHN(evtchn))
337 notify_remote_via_evtchn(evtchn);
339 EXPORT_SYMBOL_GPL(notify_remote_via_irq);
341 static void mask_evtchn(int port)
343 struct shared_info *s = HYPERVISOR_shared_info;
344 sync_set_bit(port, &s->evtchn_mask[0]);
347 static void unmask_evtchn(int port)
349 struct shared_info *s = HYPERVISOR_shared_info;
350 unsigned int cpu = get_cpu();
352 BUG_ON(!irqs_disabled());
354 /* Slow path (hypercall) if this is a non-local port. */
355 if (unlikely(cpu != cpu_from_evtchn(port))) {
356 struct evtchn_unmask unmask = { .port = port };
357 (void)HYPERVISOR_event_channel_op(EVTCHNOP_unmask, &unmask);
358 } else {
359 struct vcpu_info *vcpu_info = __get_cpu_var(xen_vcpu);
361 sync_clear_bit(port, &s->evtchn_mask[0]);
364 * The following is basically the equivalent of
365 * 'hw_resend_irq'. Just like a real IO-APIC we 'lose
366 * the interrupt edge' if the channel is masked.
368 if (sync_test_bit(port, &s->evtchn_pending[0]) &&
369 !sync_test_and_set_bit(port / BITS_PER_LONG,
370 &vcpu_info->evtchn_pending_sel))
371 vcpu_info->evtchn_upcall_pending = 1;
374 put_cpu();
377 static int get_nr_hw_irqs(void)
379 int ret = 1;
381 #ifdef CONFIG_X86_IO_APIC
382 ret = get_nr_irqs_gsi();
383 #endif
385 return ret;
388 /* callers of this function should make sure that PHYSDEVOP_get_nr_pirqs
389 * succeeded otherwise nr_pirqs won't hold the right value */
390 static int find_unbound_pirq(void)
392 int i;
393 for (i = nr_pirqs-1; i >= 0; i--) {
394 if (pirq_to_irq[i] < 0)
395 return i;
397 return -1;
400 static int find_unbound_irq(void)
402 struct irq_data *data;
403 int irq, res;
404 int start = get_nr_hw_irqs();
406 if (start == nr_irqs)
407 goto no_irqs;
409 /* nr_irqs is a magic value. Must not use it.*/
410 for (irq = nr_irqs-1; irq > start; irq--) {
411 data = irq_get_irq_data(irq);
412 /* only 0->15 have init'd desc; handle irq > 16 */
413 if (!data)
414 break;
415 if (data->chip == &no_irq_chip)
416 break;
417 if (data->chip != &xen_dynamic_chip)
418 continue;
419 if (irq_info[irq].type == IRQT_UNBOUND)
420 return irq;
423 if (irq == start)
424 goto no_irqs;
426 res = irq_alloc_desc_at(irq, 0);
428 if (WARN_ON(res != irq))
429 return -1;
431 return irq;
433 no_irqs:
434 panic("No available IRQ to bind to: increase nr_irqs!\n");
437 static bool identity_mapped_irq(unsigned irq)
439 /* identity map all the hardware irqs */
440 return irq < get_nr_hw_irqs();
443 static void pirq_unmask_notify(int irq)
445 struct physdev_eoi eoi = { .irq = pirq_from_irq(irq) };
447 if (unlikely(pirq_needs_eoi(irq))) {
448 int rc = HYPERVISOR_physdev_op(PHYSDEVOP_eoi, &eoi);
449 WARN_ON(rc);
453 static void pirq_query_unmask(int irq)
455 struct physdev_irq_status_query irq_status;
456 struct irq_info *info = info_for_irq(irq);
458 BUG_ON(info->type != IRQT_PIRQ);
460 irq_status.irq = pirq_from_irq(irq);
461 if (HYPERVISOR_physdev_op(PHYSDEVOP_irq_status_query, &irq_status))
462 irq_status.flags = 0;
464 info->u.pirq.flags &= ~PIRQ_NEEDS_EOI;
465 if (irq_status.flags & XENIRQSTAT_needs_eoi)
466 info->u.pirq.flags |= PIRQ_NEEDS_EOI;
469 static bool probing_irq(int irq)
471 struct irq_desc *desc = irq_to_desc(irq);
473 return desc && desc->action == NULL;
476 static unsigned int startup_pirq(unsigned int irq)
478 struct evtchn_bind_pirq bind_pirq;
479 struct irq_info *info = info_for_irq(irq);
480 int evtchn = evtchn_from_irq(irq);
481 int rc;
483 BUG_ON(info->type != IRQT_PIRQ);
485 if (VALID_EVTCHN(evtchn))
486 goto out;
488 bind_pirq.pirq = pirq_from_irq(irq);
489 /* NB. We are happy to share unless we are probing. */
490 bind_pirq.flags = info->u.pirq.flags & PIRQ_SHAREABLE ?
491 BIND_PIRQ__WILL_SHARE : 0;
492 rc = HYPERVISOR_event_channel_op(EVTCHNOP_bind_pirq, &bind_pirq);
493 if (rc != 0) {
494 if (!probing_irq(irq))
495 printk(KERN_INFO "Failed to obtain physical IRQ %d\n",
496 irq);
497 return 0;
499 evtchn = bind_pirq.port;
501 pirq_query_unmask(irq);
503 evtchn_to_irq[evtchn] = irq;
504 bind_evtchn_to_cpu(evtchn, 0);
505 info->evtchn = evtchn;
507 out:
508 unmask_evtchn(evtchn);
509 pirq_unmask_notify(irq);
511 return 0;
514 static void shutdown_pirq(unsigned int irq)
516 struct evtchn_close close;
517 struct irq_info *info = info_for_irq(irq);
518 int evtchn = evtchn_from_irq(irq);
520 BUG_ON(info->type != IRQT_PIRQ);
522 if (!VALID_EVTCHN(evtchn))
523 return;
525 mask_evtchn(evtchn);
527 close.port = evtchn;
528 if (HYPERVISOR_event_channel_op(EVTCHNOP_close, &close) != 0)
529 BUG();
531 bind_evtchn_to_cpu(evtchn, 0);
532 evtchn_to_irq[evtchn] = -1;
533 info->evtchn = 0;
536 static void enable_pirq(unsigned int irq)
538 startup_pirq(irq);
541 static void disable_pirq(unsigned int irq)
545 static void ack_pirq(unsigned int irq)
547 int evtchn = evtchn_from_irq(irq);
549 move_native_irq(irq);
551 if (VALID_EVTCHN(evtchn)) {
552 mask_evtchn(evtchn);
553 clear_evtchn(evtchn);
557 static void end_pirq(unsigned int irq)
559 int evtchn = evtchn_from_irq(irq);
560 struct irq_desc *desc = irq_to_desc(irq);
562 if (WARN_ON(!desc))
563 return;
565 if ((desc->status & (IRQ_DISABLED|IRQ_PENDING)) ==
566 (IRQ_DISABLED|IRQ_PENDING)) {
567 shutdown_pirq(irq);
568 } else if (VALID_EVTCHN(evtchn)) {
569 unmask_evtchn(evtchn);
570 pirq_unmask_notify(irq);
574 static int find_irq_by_gsi(unsigned gsi)
576 int irq;
578 for (irq = 0; irq < nr_irqs; irq++) {
579 struct irq_info *info = info_for_irq(irq);
581 if (info == NULL || info->type != IRQT_PIRQ)
582 continue;
584 if (gsi_from_irq(irq) == gsi)
585 return irq;
588 return -1;
591 int xen_allocate_pirq(unsigned gsi, int shareable, char *name)
593 return xen_map_pirq_gsi(gsi, gsi, shareable, name);
596 /* xen_map_pirq_gsi might allocate irqs from the top down, as a
597 * consequence don't assume that the irq number returned has a low value
598 * or can be used as a pirq number unless you know otherwise.
600 * One notable exception is when xen_map_pirq_gsi is called passing an
601 * hardware gsi as argument, in that case the irq number returned
602 * matches the gsi number passed as second argument.
604 * Note: We don't assign an event channel until the irq actually started
605 * up. Return an existing irq if we've already got one for the gsi.
607 int xen_map_pirq_gsi(unsigned pirq, unsigned gsi, int shareable, char *name)
609 int irq = 0;
610 struct physdev_irq irq_op;
612 spin_lock(&irq_mapping_update_lock);
614 if ((pirq > nr_pirqs) || (gsi > nr_irqs)) {
615 printk(KERN_WARNING "xen_map_pirq_gsi: %s %s is incorrect!\n",
616 pirq > nr_pirqs ? "nr_pirqs" :"",
617 gsi > nr_irqs ? "nr_irqs" : "");
618 goto out;
621 irq = find_irq_by_gsi(gsi);
622 if (irq != -1) {
623 printk(KERN_INFO "xen_map_pirq_gsi: returning irq %d for gsi %u\n",
624 irq, gsi);
625 goto out; /* XXX need refcount? */
628 /* If we are a PV guest, we don't have GSIs (no ACPI passed). Therefore
629 * we are using the !xen_initial_domain() to drop in the function.*/
630 if (identity_mapped_irq(gsi) || (!xen_initial_domain() &&
631 xen_pv_domain())) {
632 irq = gsi;
633 irq_alloc_desc_at(irq, 0);
634 } else
635 irq = find_unbound_irq();
637 set_irq_chip_and_handler_name(irq, &xen_pirq_chip,
638 handle_level_irq, name);
640 irq_op.irq = irq;
641 irq_op.vector = 0;
643 /* Only the privileged domain can do this. For non-priv, the pcifront
644 * driver provides a PCI bus that does the call to do exactly
645 * this in the priv domain. */
646 if (xen_initial_domain() &&
647 HYPERVISOR_physdev_op(PHYSDEVOP_alloc_irq_vector, &irq_op)) {
648 irq_free_desc(irq);
649 irq = -ENOSPC;
650 goto out;
653 irq_info[irq] = mk_pirq_info(0, pirq, gsi, irq_op.vector);
654 irq_info[irq].u.pirq.flags |= shareable ? PIRQ_SHAREABLE : 0;
655 pirq_to_irq[pirq] = irq;
657 out:
658 spin_unlock(&irq_mapping_update_lock);
660 return irq;
663 #ifdef CONFIG_PCI_MSI
664 #include <linux/msi.h>
665 #include "../pci/msi.h"
667 void xen_allocate_pirq_msi(char *name, int *irq, int *pirq)
669 spin_lock(&irq_mapping_update_lock);
671 *irq = find_unbound_irq();
672 if (*irq == -1)
673 goto out;
675 *pirq = find_unbound_pirq();
676 if (*pirq == -1)
677 goto out;
679 set_irq_chip_and_handler_name(*irq, &xen_pirq_chip,
680 handle_level_irq, name);
682 irq_info[*irq] = mk_pirq_info(0, *pirq, 0, 0);
683 pirq_to_irq[*pirq] = *irq;
685 out:
686 spin_unlock(&irq_mapping_update_lock);
689 int xen_create_msi_irq(struct pci_dev *dev, struct msi_desc *msidesc, int type)
691 int irq = -1;
692 struct physdev_map_pirq map_irq;
693 int rc;
694 int pos;
695 u32 table_offset, bir;
697 memset(&map_irq, 0, sizeof(map_irq));
698 map_irq.domid = DOMID_SELF;
699 map_irq.type = MAP_PIRQ_TYPE_MSI;
700 map_irq.index = -1;
701 map_irq.pirq = -1;
702 map_irq.bus = dev->bus->number;
703 map_irq.devfn = dev->devfn;
705 if (type == PCI_CAP_ID_MSIX) {
706 pos = pci_find_capability(dev, PCI_CAP_ID_MSIX);
708 pci_read_config_dword(dev, msix_table_offset_reg(pos),
709 &table_offset);
710 bir = (u8)(table_offset & PCI_MSIX_FLAGS_BIRMASK);
712 map_irq.table_base = pci_resource_start(dev, bir);
713 map_irq.entry_nr = msidesc->msi_attrib.entry_nr;
716 spin_lock(&irq_mapping_update_lock);
718 irq = find_unbound_irq();
720 if (irq == -1)
721 goto out;
723 rc = HYPERVISOR_physdev_op(PHYSDEVOP_map_pirq, &map_irq);
724 if (rc) {
725 printk(KERN_WARNING "xen map irq failed %d\n", rc);
727 irq_free_desc(irq);
729 irq = -1;
730 goto out;
732 irq_info[irq] = mk_pirq_info(0, map_irq.pirq, 0, map_irq.index);
734 set_irq_chip_and_handler_name(irq, &xen_pirq_chip,
735 handle_level_irq,
736 (type == PCI_CAP_ID_MSIX) ? "msi-x":"msi");
738 out:
739 spin_unlock(&irq_mapping_update_lock);
740 return irq;
742 #endif
744 int xen_destroy_irq(int irq)
746 struct irq_desc *desc;
747 struct physdev_unmap_pirq unmap_irq;
748 struct irq_info *info = info_for_irq(irq);
749 int rc = -ENOENT;
751 spin_lock(&irq_mapping_update_lock);
753 desc = irq_to_desc(irq);
754 if (!desc)
755 goto out;
757 if (xen_initial_domain()) {
758 unmap_irq.pirq = info->u.pirq.pirq;
759 unmap_irq.domid = DOMID_SELF;
760 rc = HYPERVISOR_physdev_op(PHYSDEVOP_unmap_pirq, &unmap_irq);
761 if (rc) {
762 printk(KERN_WARNING "unmap irq failed %d\n", rc);
763 goto out;
766 irq_info[irq] = mk_unbound_info();
768 irq_free_desc(irq);
770 out:
771 spin_unlock(&irq_mapping_update_lock);
772 return rc;
775 int xen_vector_from_irq(unsigned irq)
777 return vector_from_irq(irq);
780 int xen_gsi_from_irq(unsigned irq)
782 return gsi_from_irq(irq);
785 int bind_evtchn_to_irq(unsigned int evtchn)
787 int irq;
789 spin_lock(&irq_mapping_update_lock);
791 irq = evtchn_to_irq[evtchn];
793 if (irq == -1) {
794 irq = find_unbound_irq();
796 set_irq_chip_and_handler_name(irq, &xen_dynamic_chip,
797 handle_fasteoi_irq, "event");
799 evtchn_to_irq[evtchn] = irq;
800 irq_info[irq] = mk_evtchn_info(evtchn);
803 spin_unlock(&irq_mapping_update_lock);
805 return irq;
807 EXPORT_SYMBOL_GPL(bind_evtchn_to_irq);
809 static int bind_ipi_to_irq(unsigned int ipi, unsigned int cpu)
811 struct evtchn_bind_ipi bind_ipi;
812 int evtchn, irq;
814 spin_lock(&irq_mapping_update_lock);
816 irq = per_cpu(ipi_to_irq, cpu)[ipi];
818 if (irq == -1) {
819 irq = find_unbound_irq();
820 if (irq < 0)
821 goto out;
823 set_irq_chip_and_handler_name(irq, &xen_percpu_chip,
824 handle_percpu_irq, "ipi");
826 bind_ipi.vcpu = cpu;
827 if (HYPERVISOR_event_channel_op(EVTCHNOP_bind_ipi,
828 &bind_ipi) != 0)
829 BUG();
830 evtchn = bind_ipi.port;
832 evtchn_to_irq[evtchn] = irq;
833 irq_info[irq] = mk_ipi_info(evtchn, ipi);
834 per_cpu(ipi_to_irq, cpu)[ipi] = irq;
836 bind_evtchn_to_cpu(evtchn, cpu);
839 out:
840 spin_unlock(&irq_mapping_update_lock);
841 return irq;
845 int bind_virq_to_irq(unsigned int virq, unsigned int cpu)
847 struct evtchn_bind_virq bind_virq;
848 int evtchn, irq;
850 spin_lock(&irq_mapping_update_lock);
852 irq = per_cpu(virq_to_irq, cpu)[virq];
854 if (irq == -1) {
855 irq = find_unbound_irq();
857 set_irq_chip_and_handler_name(irq, &xen_percpu_chip,
858 handle_percpu_irq, "virq");
860 bind_virq.virq = virq;
861 bind_virq.vcpu = cpu;
862 if (HYPERVISOR_event_channel_op(EVTCHNOP_bind_virq,
863 &bind_virq) != 0)
864 BUG();
865 evtchn = bind_virq.port;
867 evtchn_to_irq[evtchn] = irq;
868 irq_info[irq] = mk_virq_info(evtchn, virq);
870 per_cpu(virq_to_irq, cpu)[virq] = irq;
872 bind_evtchn_to_cpu(evtchn, cpu);
875 spin_unlock(&irq_mapping_update_lock);
877 return irq;
880 static void unbind_from_irq(unsigned int irq)
882 struct evtchn_close close;
883 int evtchn = evtchn_from_irq(irq);
885 spin_lock(&irq_mapping_update_lock);
887 if (VALID_EVTCHN(evtchn)) {
888 close.port = evtchn;
889 if (HYPERVISOR_event_channel_op(EVTCHNOP_close, &close) != 0)
890 BUG();
892 switch (type_from_irq(irq)) {
893 case IRQT_VIRQ:
894 per_cpu(virq_to_irq, cpu_from_evtchn(evtchn))
895 [virq_from_irq(irq)] = -1;
896 break;
897 case IRQT_IPI:
898 per_cpu(ipi_to_irq, cpu_from_evtchn(evtchn))
899 [ipi_from_irq(irq)] = -1;
900 break;
901 default:
902 break;
905 /* Closed ports are implicitly re-bound to VCPU0. */
906 bind_evtchn_to_cpu(evtchn, 0);
908 evtchn_to_irq[evtchn] = -1;
911 if (irq_info[irq].type != IRQT_UNBOUND) {
912 irq_info[irq] = mk_unbound_info();
914 irq_free_desc(irq);
917 spin_unlock(&irq_mapping_update_lock);
920 int bind_evtchn_to_irqhandler(unsigned int evtchn,
921 irq_handler_t handler,
922 unsigned long irqflags,
923 const char *devname, void *dev_id)
925 unsigned int irq;
926 int retval;
928 irq = bind_evtchn_to_irq(evtchn);
929 retval = request_irq(irq, handler, irqflags, devname, dev_id);
930 if (retval != 0) {
931 unbind_from_irq(irq);
932 return retval;
935 return irq;
937 EXPORT_SYMBOL_GPL(bind_evtchn_to_irqhandler);
939 int bind_virq_to_irqhandler(unsigned int virq, unsigned int cpu,
940 irq_handler_t handler,
941 unsigned long irqflags, const char *devname, void *dev_id)
943 unsigned int irq;
944 int retval;
946 irq = bind_virq_to_irq(virq, cpu);
947 retval = request_irq(irq, handler, irqflags, devname, dev_id);
948 if (retval != 0) {
949 unbind_from_irq(irq);
950 return retval;
953 return irq;
955 EXPORT_SYMBOL_GPL(bind_virq_to_irqhandler);
957 int bind_ipi_to_irqhandler(enum ipi_vector ipi,
958 unsigned int cpu,
959 irq_handler_t handler,
960 unsigned long irqflags,
961 const char *devname,
962 void *dev_id)
964 int irq, retval;
966 irq = bind_ipi_to_irq(ipi, cpu);
967 if (irq < 0)
968 return irq;
970 irqflags |= IRQF_NO_SUSPEND;
971 retval = request_irq(irq, handler, irqflags, devname, dev_id);
972 if (retval != 0) {
973 unbind_from_irq(irq);
974 return retval;
977 return irq;
980 void unbind_from_irqhandler(unsigned int irq, void *dev_id)
982 free_irq(irq, dev_id);
983 unbind_from_irq(irq);
985 EXPORT_SYMBOL_GPL(unbind_from_irqhandler);
987 void xen_send_IPI_one(unsigned int cpu, enum ipi_vector vector)
989 int irq = per_cpu(ipi_to_irq, cpu)[vector];
990 BUG_ON(irq < 0);
991 notify_remote_via_irq(irq);
994 irqreturn_t xen_debug_interrupt(int irq, void *dev_id)
996 struct shared_info *sh = HYPERVISOR_shared_info;
997 int cpu = smp_processor_id();
998 unsigned long *cpu_evtchn = cpu_evtchn_mask(cpu);
999 int i;
1000 unsigned long flags;
1001 static DEFINE_SPINLOCK(debug_lock);
1002 struct vcpu_info *v;
1004 spin_lock_irqsave(&debug_lock, flags);
1006 printk("\nvcpu %d\n ", cpu);
1008 for_each_online_cpu(i) {
1009 int pending;
1010 v = per_cpu(xen_vcpu, i);
1011 pending = (get_irq_regs() && i == cpu)
1012 ? xen_irqs_disabled(get_irq_regs())
1013 : v->evtchn_upcall_mask;
1014 printk("%d: masked=%d pending=%d event_sel %0*lx\n ", i,
1015 pending, v->evtchn_upcall_pending,
1016 (int)(sizeof(v->evtchn_pending_sel)*2),
1017 v->evtchn_pending_sel);
1019 v = per_cpu(xen_vcpu, cpu);
1021 printk("\npending:\n ");
1022 for (i = ARRAY_SIZE(sh->evtchn_pending)-1; i >= 0; i--)
1023 printk("%0*lx%s", (int)sizeof(sh->evtchn_pending[0])*2,
1024 sh->evtchn_pending[i],
1025 i % 8 == 0 ? "\n " : " ");
1026 printk("\nglobal mask:\n ");
1027 for (i = ARRAY_SIZE(sh->evtchn_mask)-1; i >= 0; i--)
1028 printk("%0*lx%s",
1029 (int)(sizeof(sh->evtchn_mask[0])*2),
1030 sh->evtchn_mask[i],
1031 i % 8 == 0 ? "\n " : " ");
1033 printk("\nglobally unmasked:\n ");
1034 for (i = ARRAY_SIZE(sh->evtchn_mask)-1; i >= 0; i--)
1035 printk("%0*lx%s", (int)(sizeof(sh->evtchn_mask[0])*2),
1036 sh->evtchn_pending[i] & ~sh->evtchn_mask[i],
1037 i % 8 == 0 ? "\n " : " ");
1039 printk("\nlocal cpu%d mask:\n ", cpu);
1040 for (i = (NR_EVENT_CHANNELS/BITS_PER_LONG)-1; i >= 0; i--)
1041 printk("%0*lx%s", (int)(sizeof(cpu_evtchn[0])*2),
1042 cpu_evtchn[i],
1043 i % 8 == 0 ? "\n " : " ");
1045 printk("\nlocally unmasked:\n ");
1046 for (i = ARRAY_SIZE(sh->evtchn_mask)-1; i >= 0; i--) {
1047 unsigned long pending = sh->evtchn_pending[i]
1048 & ~sh->evtchn_mask[i]
1049 & cpu_evtchn[i];
1050 printk("%0*lx%s", (int)(sizeof(sh->evtchn_mask[0])*2),
1051 pending, i % 8 == 0 ? "\n " : " ");
1054 printk("\npending list:\n");
1055 for (i = 0; i < NR_EVENT_CHANNELS; i++) {
1056 if (sync_test_bit(i, sh->evtchn_pending)) {
1057 int word_idx = i / BITS_PER_LONG;
1058 printk(" %d: event %d -> irq %d%s%s%s\n",
1059 cpu_from_evtchn(i), i,
1060 evtchn_to_irq[i],
1061 sync_test_bit(word_idx, &v->evtchn_pending_sel)
1062 ? "" : " l2-clear",
1063 !sync_test_bit(i, sh->evtchn_mask)
1064 ? "" : " globally-masked",
1065 sync_test_bit(i, cpu_evtchn)
1066 ? "" : " locally-masked");
1070 spin_unlock_irqrestore(&debug_lock, flags);
1072 return IRQ_HANDLED;
1075 static DEFINE_PER_CPU(unsigned, xed_nesting_count);
1078 * Search the CPUs pending events bitmasks. For each one found, map
1079 * the event number to an irq, and feed it into do_IRQ() for
1080 * handling.
1082 * Xen uses a two-level bitmap to speed searching. The first level is
1083 * a bitset of words which contain pending event bits. The second
1084 * level is a bitset of pending events themselves.
1086 static void __xen_evtchn_do_upcall(void)
1088 int cpu = get_cpu();
1089 struct shared_info *s = HYPERVISOR_shared_info;
1090 struct vcpu_info *vcpu_info = __get_cpu_var(xen_vcpu);
1091 unsigned count;
1093 do {
1094 unsigned long pending_words;
1096 vcpu_info->evtchn_upcall_pending = 0;
1098 if (__get_cpu_var(xed_nesting_count)++)
1099 goto out;
1101 #ifndef CONFIG_X86 /* No need for a barrier -- XCHG is a barrier on x86. */
1102 /* Clear master flag /before/ clearing selector flag. */
1103 wmb();
1104 #endif
1105 pending_words = xchg(&vcpu_info->evtchn_pending_sel, 0);
1106 while (pending_words != 0) {
1107 unsigned long pending_bits;
1108 int word_idx = __ffs(pending_words);
1109 pending_words &= ~(1UL << word_idx);
1111 while ((pending_bits = active_evtchns(cpu, s, word_idx)) != 0) {
1112 int bit_idx = __ffs(pending_bits);
1113 int port = (word_idx * BITS_PER_LONG) + bit_idx;
1114 int irq = evtchn_to_irq[port];
1115 struct irq_desc *desc;
1117 mask_evtchn(port);
1118 clear_evtchn(port);
1120 if (irq != -1) {
1121 desc = irq_to_desc(irq);
1122 if (desc)
1123 generic_handle_irq_desc(irq, desc);
1128 BUG_ON(!irqs_disabled());
1130 count = __get_cpu_var(xed_nesting_count);
1131 __get_cpu_var(xed_nesting_count) = 0;
1132 } while (count != 1 || vcpu_info->evtchn_upcall_pending);
1134 out:
1136 put_cpu();
1139 void xen_evtchn_do_upcall(struct pt_regs *regs)
1141 struct pt_regs *old_regs = set_irq_regs(regs);
1143 exit_idle();
1144 irq_enter();
1146 __xen_evtchn_do_upcall();
1148 irq_exit();
1149 set_irq_regs(old_regs);
1152 void xen_hvm_evtchn_do_upcall(void)
1154 __xen_evtchn_do_upcall();
1156 EXPORT_SYMBOL_GPL(xen_hvm_evtchn_do_upcall);
1158 /* Rebind a new event channel to an existing irq. */
1159 void rebind_evtchn_irq(int evtchn, int irq)
1161 struct irq_info *info = info_for_irq(irq);
1163 /* Make sure the irq is masked, since the new event channel
1164 will also be masked. */
1165 disable_irq(irq);
1167 spin_lock(&irq_mapping_update_lock);
1169 /* After resume the irq<->evtchn mappings are all cleared out */
1170 BUG_ON(evtchn_to_irq[evtchn] != -1);
1171 /* Expect irq to have been bound before,
1172 so there should be a proper type */
1173 BUG_ON(info->type == IRQT_UNBOUND);
1175 evtchn_to_irq[evtchn] = irq;
1176 irq_info[irq] = mk_evtchn_info(evtchn);
1178 spin_unlock(&irq_mapping_update_lock);
1180 /* new event channels are always bound to cpu 0 */
1181 irq_set_affinity(irq, cpumask_of(0));
1183 /* Unmask the event channel. */
1184 enable_irq(irq);
1187 /* Rebind an evtchn so that it gets delivered to a specific cpu */
1188 static int rebind_irq_to_cpu(unsigned irq, unsigned tcpu)
1190 struct evtchn_bind_vcpu bind_vcpu;
1191 int evtchn = evtchn_from_irq(irq);
1193 /* events delivered via platform PCI interrupts are always
1194 * routed to vcpu 0 */
1195 if (!VALID_EVTCHN(evtchn) ||
1196 (xen_hvm_domain() && !xen_have_vector_callback))
1197 return -1;
1199 /* Send future instances of this interrupt to other vcpu. */
1200 bind_vcpu.port = evtchn;
1201 bind_vcpu.vcpu = tcpu;
1204 * If this fails, it usually just indicates that we're dealing with a
1205 * virq or IPI channel, which don't actually need to be rebound. Ignore
1206 * it, but don't do the xenlinux-level rebind in that case.
1208 if (HYPERVISOR_event_channel_op(EVTCHNOP_bind_vcpu, &bind_vcpu) >= 0)
1209 bind_evtchn_to_cpu(evtchn, tcpu);
1211 return 0;
1214 static int set_affinity_irq(unsigned irq, const struct cpumask *dest)
1216 unsigned tcpu = cpumask_first(dest);
1218 return rebind_irq_to_cpu(irq, tcpu);
1221 int resend_irq_on_evtchn(unsigned int irq)
1223 int masked, evtchn = evtchn_from_irq(irq);
1224 struct shared_info *s = HYPERVISOR_shared_info;
1226 if (!VALID_EVTCHN(evtchn))
1227 return 1;
1229 masked = sync_test_and_set_bit(evtchn, s->evtchn_mask);
1230 sync_set_bit(evtchn, s->evtchn_pending);
1231 if (!masked)
1232 unmask_evtchn(evtchn);
1234 return 1;
1237 static void enable_dynirq(unsigned int irq)
1239 int evtchn = evtchn_from_irq(irq);
1241 if (VALID_EVTCHN(evtchn))
1242 unmask_evtchn(evtchn);
1245 static void disable_dynirq(unsigned int irq)
1247 int evtchn = evtchn_from_irq(irq);
1249 if (VALID_EVTCHN(evtchn))
1250 mask_evtchn(evtchn);
1253 static void ack_dynirq(unsigned int irq)
1255 int evtchn = evtchn_from_irq(irq);
1257 move_masked_irq(irq);
1259 if (VALID_EVTCHN(evtchn))
1260 unmask_evtchn(evtchn);
1263 static int retrigger_dynirq(unsigned int irq)
1265 int evtchn = evtchn_from_irq(irq);
1266 struct shared_info *sh = HYPERVISOR_shared_info;
1267 int ret = 0;
1269 if (VALID_EVTCHN(evtchn)) {
1270 int masked;
1272 masked = sync_test_and_set_bit(evtchn, sh->evtchn_mask);
1273 sync_set_bit(evtchn, sh->evtchn_pending);
1274 if (!masked)
1275 unmask_evtchn(evtchn);
1276 ret = 1;
1279 return ret;
1282 static void restore_cpu_virqs(unsigned int cpu)
1284 struct evtchn_bind_virq bind_virq;
1285 int virq, irq, evtchn;
1287 for (virq = 0; virq < NR_VIRQS; virq++) {
1288 if ((irq = per_cpu(virq_to_irq, cpu)[virq]) == -1)
1289 continue;
1291 BUG_ON(virq_from_irq(irq) != virq);
1293 /* Get a new binding from Xen. */
1294 bind_virq.virq = virq;
1295 bind_virq.vcpu = cpu;
1296 if (HYPERVISOR_event_channel_op(EVTCHNOP_bind_virq,
1297 &bind_virq) != 0)
1298 BUG();
1299 evtchn = bind_virq.port;
1301 /* Record the new mapping. */
1302 evtchn_to_irq[evtchn] = irq;
1303 irq_info[irq] = mk_virq_info(evtchn, virq);
1304 bind_evtchn_to_cpu(evtchn, cpu);
1308 static void restore_cpu_ipis(unsigned int cpu)
1310 struct evtchn_bind_ipi bind_ipi;
1311 int ipi, irq, evtchn;
1313 for (ipi = 0; ipi < XEN_NR_IPIS; ipi++) {
1314 if ((irq = per_cpu(ipi_to_irq, cpu)[ipi]) == -1)
1315 continue;
1317 BUG_ON(ipi_from_irq(irq) != ipi);
1319 /* Get a new binding from Xen. */
1320 bind_ipi.vcpu = cpu;
1321 if (HYPERVISOR_event_channel_op(EVTCHNOP_bind_ipi,
1322 &bind_ipi) != 0)
1323 BUG();
1324 evtchn = bind_ipi.port;
1326 /* Record the new mapping. */
1327 evtchn_to_irq[evtchn] = irq;
1328 irq_info[irq] = mk_ipi_info(evtchn, ipi);
1329 bind_evtchn_to_cpu(evtchn, cpu);
1333 /* Clear an irq's pending state, in preparation for polling on it */
1334 void xen_clear_irq_pending(int irq)
1336 int evtchn = evtchn_from_irq(irq);
1338 if (VALID_EVTCHN(evtchn))
1339 clear_evtchn(evtchn);
1341 EXPORT_SYMBOL(xen_clear_irq_pending);
1342 void xen_set_irq_pending(int irq)
1344 int evtchn = evtchn_from_irq(irq);
1346 if (VALID_EVTCHN(evtchn))
1347 set_evtchn(evtchn);
1350 bool xen_test_irq_pending(int irq)
1352 int evtchn = evtchn_from_irq(irq);
1353 bool ret = false;
1355 if (VALID_EVTCHN(evtchn))
1356 ret = test_evtchn(evtchn);
1358 return ret;
1361 /* Poll waiting for an irq to become pending with timeout. In the usual case,
1362 * the irq will be disabled so it won't deliver an interrupt. */
1363 void xen_poll_irq_timeout(int irq, u64 timeout)
1365 evtchn_port_t evtchn = evtchn_from_irq(irq);
1367 if (VALID_EVTCHN(evtchn)) {
1368 struct sched_poll poll;
1370 poll.nr_ports = 1;
1371 poll.timeout = timeout;
1372 set_xen_guest_handle(poll.ports, &evtchn);
1374 if (HYPERVISOR_sched_op(SCHEDOP_poll, &poll) != 0)
1375 BUG();
1378 EXPORT_SYMBOL(xen_poll_irq_timeout);
1379 /* Poll waiting for an irq to become pending. In the usual case, the
1380 * irq will be disabled so it won't deliver an interrupt. */
1381 void xen_poll_irq(int irq)
1383 xen_poll_irq_timeout(irq, 0 /* no timeout */);
1386 void xen_irq_resume(void)
1388 unsigned int cpu, irq, evtchn;
1389 struct irq_desc *desc;
1391 init_evtchn_cpu_bindings();
1393 /* New event-channel space is not 'live' yet. */
1394 for (evtchn = 0; evtchn < NR_EVENT_CHANNELS; evtchn++)
1395 mask_evtchn(evtchn);
1397 /* No IRQ <-> event-channel mappings. */
1398 for (irq = 0; irq < nr_irqs; irq++)
1399 irq_info[irq].evtchn = 0; /* zap event-channel binding */
1401 for (evtchn = 0; evtchn < NR_EVENT_CHANNELS; evtchn++)
1402 evtchn_to_irq[evtchn] = -1;
1404 for_each_possible_cpu(cpu) {
1405 restore_cpu_virqs(cpu);
1406 restore_cpu_ipis(cpu);
1410 * Unmask any IRQF_NO_SUSPEND IRQs which are enabled. These
1411 * are not handled by the IRQ core.
1413 for_each_irq_desc(irq, desc) {
1414 if (!desc->action || !(desc->action->flags & IRQF_NO_SUSPEND))
1415 continue;
1416 if (desc->status & IRQ_DISABLED)
1417 continue;
1419 evtchn = evtchn_from_irq(irq);
1420 if (evtchn == -1)
1421 continue;
1423 unmask_evtchn(evtchn);
1427 static struct irq_chip xen_dynamic_chip __read_mostly = {
1428 .name = "xen-dyn",
1430 .disable = disable_dynirq,
1431 .mask = disable_dynirq,
1432 .unmask = enable_dynirq,
1434 .eoi = ack_dynirq,
1435 .set_affinity = set_affinity_irq,
1436 .retrigger = retrigger_dynirq,
1439 static struct irq_chip xen_pirq_chip __read_mostly = {
1440 .name = "xen-pirq",
1442 .startup = startup_pirq,
1443 .shutdown = shutdown_pirq,
1445 .enable = enable_pirq,
1446 .unmask = enable_pirq,
1448 .disable = disable_pirq,
1449 .mask = disable_pirq,
1451 .ack = ack_pirq,
1452 .end = end_pirq,
1454 .set_affinity = set_affinity_irq,
1456 .retrigger = retrigger_dynirq,
1459 static struct irq_chip xen_percpu_chip __read_mostly = {
1460 .name = "xen-percpu",
1462 .disable = disable_dynirq,
1463 .mask = disable_dynirq,
1464 .unmask = enable_dynirq,
1466 .ack = ack_dynirq,
1469 int xen_set_callback_via(uint64_t via)
1471 struct xen_hvm_param a;
1472 a.domid = DOMID_SELF;
1473 a.index = HVM_PARAM_CALLBACK_IRQ;
1474 a.value = via;
1475 return HYPERVISOR_hvm_op(HVMOP_set_param, &a);
1477 EXPORT_SYMBOL_GPL(xen_set_callback_via);
1479 #ifdef CONFIG_XEN_PVHVM
1480 /* Vector callbacks are better than PCI interrupts to receive event
1481 * channel notifications because we can receive vector callbacks on any
1482 * vcpu and we don't need PCI support or APIC interactions. */
1483 void xen_callback_vector(void)
1485 int rc;
1486 uint64_t callback_via;
1487 if (xen_have_vector_callback) {
1488 callback_via = HVM_CALLBACK_VECTOR(XEN_HVM_EVTCHN_CALLBACK);
1489 rc = xen_set_callback_via(callback_via);
1490 if (rc) {
1491 printk(KERN_ERR "Request for Xen HVM callback vector"
1492 " failed.\n");
1493 xen_have_vector_callback = 0;
1494 return;
1496 printk(KERN_INFO "Xen HVM callback vector for event delivery is "
1497 "enabled\n");
1498 /* in the restore case the vector has already been allocated */
1499 if (!test_bit(XEN_HVM_EVTCHN_CALLBACK, used_vectors))
1500 alloc_intr_gate(XEN_HVM_EVTCHN_CALLBACK, xen_hvm_callback_vector);
1503 #else
1504 void xen_callback_vector(void) {}
1505 #endif
1507 void __init xen_init_IRQ(void)
1509 int i, rc;
1510 struct physdev_nr_pirqs op_nr_pirqs;
1512 cpu_evtchn_mask_p = kcalloc(nr_cpu_ids, sizeof(struct cpu_evtchn_s),
1513 GFP_KERNEL);
1514 irq_info = kcalloc(nr_irqs, sizeof(*irq_info), GFP_KERNEL);
1516 rc = HYPERVISOR_physdev_op(PHYSDEVOP_get_nr_pirqs, &op_nr_pirqs);
1517 if (rc < 0) {
1518 nr_pirqs = nr_irqs;
1519 if (rc != -ENOSYS)
1520 printk(KERN_WARNING "PHYSDEVOP_get_nr_pirqs returned rc=%d\n", rc);
1521 } else {
1522 if (xen_pv_domain() && !xen_initial_domain())
1523 nr_pirqs = max((int)op_nr_pirqs.nr_pirqs, nr_irqs);
1524 else
1525 nr_pirqs = op_nr_pirqs.nr_pirqs;
1527 pirq_to_irq = kcalloc(nr_pirqs, sizeof(*pirq_to_irq), GFP_KERNEL);
1528 for (i = 0; i < nr_pirqs; i++)
1529 pirq_to_irq[i] = -1;
1531 evtchn_to_irq = kcalloc(NR_EVENT_CHANNELS, sizeof(*evtchn_to_irq),
1532 GFP_KERNEL);
1533 for (i = 0; i < NR_EVENT_CHANNELS; i++)
1534 evtchn_to_irq[i] = -1;
1536 init_evtchn_cpu_bindings();
1538 /* No event channels are 'live' right now. */
1539 for (i = 0; i < NR_EVENT_CHANNELS; i++)
1540 mask_evtchn(i);
1542 if (xen_hvm_domain()) {
1543 xen_callback_vector();
1544 native_init_IRQ();
1545 /* pci_xen_hvm_init must be called after native_init_IRQ so that
1546 * __acpi_register_gsi can point at the right function */
1547 pci_xen_hvm_init();
1548 } else {
1549 irq_ctx_init(smp_processor_id());
1550 if (xen_initial_domain())
1551 xen_setup_pirqs();