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
14 * 1. Inter-domain notifications. This includes all the virtual
15 * device events, since they're driven by front-ends in another domain
17 * 2. VIRQs, typically used for timers. These are per-cpu events.
19 * 4. Hardware interrupts. Not supported at present.
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>
31 #include <asm/ptrace.h>
34 #include <asm/sync_bitops.h>
35 #include <asm/xen/hypercall.h>
36 #include <asm/xen/hypervisor.h>
38 #include <xen/xen-ops.h>
39 #include <xen/events.h>
40 #include <xen/interface/xen.h>
41 #include <xen/interface/event_channel.h>
44 * This lock protects updates to the following mapping and reference-count
45 * arrays. The lock does not need to be acquired to read the mapping tables.
47 static DEFINE_SPINLOCK(irq_mapping_update_lock
);
49 /* IRQ <-> VIRQ mapping. */
50 static DEFINE_PER_CPU(int [NR_VIRQS
], virq_to_irq
) = {[0 ... NR_VIRQS
-1] = -1};
52 /* IRQ <-> IPI mapping */
53 static DEFINE_PER_CPU(int [XEN_NR_IPIS
], ipi_to_irq
) = {[0 ... XEN_NR_IPIS
-1] = -1};
55 /* Interrupt types. */
65 * Packed IRQ information:
66 * type - enum xen_irq_type
67 * event channel - irq->event channel mapping
68 * cpu - cpu this event channel is bound to
69 * index - type-specific information:
70 * PIRQ - vector, with MSB being "needs EIO"
77 enum xen_irq_type type
; /* type */
78 unsigned short evtchn
; /* event channel */
79 unsigned short cpu
; /* cpu bound */
86 unsigned short vector
;
91 static struct irq_info irq_info
[NR_IRQS
];
93 static int evtchn_to_irq
[NR_EVENT_CHANNELS
] = {
94 [0 ... NR_EVENT_CHANNELS
-1] = -1
97 unsigned long bits
[NR_EVENT_CHANNELS
/BITS_PER_LONG
];
99 static struct cpu_evtchn_s
*cpu_evtchn_mask_p
;
100 static inline unsigned long *cpu_evtchn_mask(int cpu
)
102 return cpu_evtchn_mask_p
[cpu
].bits
;
105 /* Xen will never allocate port zero for any purpose. */
106 #define VALID_EVTCHN(chn) ((chn) != 0)
108 static struct irq_chip xen_dynamic_chip
;
110 /* Constructor for packed IRQ information. */
111 static struct irq_info
mk_unbound_info(void)
113 return (struct irq_info
) { .type
= IRQT_UNBOUND
};
116 static struct irq_info
mk_evtchn_info(unsigned short evtchn
)
118 return (struct irq_info
) { .type
= IRQT_EVTCHN
, .evtchn
= evtchn
,
122 static struct irq_info
mk_ipi_info(unsigned short evtchn
, enum ipi_vector ipi
)
124 return (struct irq_info
) { .type
= IRQT_IPI
, .evtchn
= evtchn
,
125 .cpu
= 0, .u
.ipi
= ipi
};
128 static struct irq_info
mk_virq_info(unsigned short evtchn
, unsigned short virq
)
130 return (struct irq_info
) { .type
= IRQT_VIRQ
, .evtchn
= evtchn
,
131 .cpu
= 0, .u
.virq
= virq
};
134 static struct irq_info
mk_pirq_info(unsigned short evtchn
,
135 unsigned short gsi
, unsigned short vector
)
137 return (struct irq_info
) { .type
= IRQT_PIRQ
, .evtchn
= evtchn
,
138 .cpu
= 0, .u
.pirq
= { .gsi
= gsi
, .vector
= vector
} };
142 * Accessors for packed IRQ information.
144 static struct irq_info
*info_for_irq(unsigned irq
)
146 return &irq_info
[irq
];
149 static unsigned int evtchn_from_irq(unsigned irq
)
151 return info_for_irq(irq
)->evtchn
;
154 unsigned irq_from_evtchn(unsigned int evtchn
)
156 return evtchn_to_irq
[evtchn
];
158 EXPORT_SYMBOL_GPL(irq_from_evtchn
);
160 static enum ipi_vector
ipi_from_irq(unsigned irq
)
162 struct irq_info
*info
= info_for_irq(irq
);
164 BUG_ON(info
== NULL
);
165 BUG_ON(info
->type
!= IRQT_IPI
);
170 static unsigned virq_from_irq(unsigned irq
)
172 struct irq_info
*info
= info_for_irq(irq
);
174 BUG_ON(info
== NULL
);
175 BUG_ON(info
->type
!= IRQT_VIRQ
);
180 static unsigned gsi_from_irq(unsigned irq
)
182 struct irq_info
*info
= info_for_irq(irq
);
184 BUG_ON(info
== NULL
);
185 BUG_ON(info
->type
!= IRQT_PIRQ
);
187 return info
->u
.pirq
.gsi
;
190 static unsigned vector_from_irq(unsigned irq
)
192 struct irq_info
*info
= info_for_irq(irq
);
194 BUG_ON(info
== NULL
);
195 BUG_ON(info
->type
!= IRQT_PIRQ
);
197 return info
->u
.pirq
.vector
;
200 static enum xen_irq_type
type_from_irq(unsigned irq
)
202 return info_for_irq(irq
)->type
;
205 static unsigned cpu_from_irq(unsigned irq
)
207 return info_for_irq(irq
)->cpu
;
210 static unsigned int cpu_from_evtchn(unsigned int evtchn
)
212 int irq
= evtchn_to_irq
[evtchn
];
216 ret
= cpu_from_irq(irq
);
221 static inline unsigned long active_evtchns(unsigned int cpu
,
222 struct shared_info
*sh
,
225 return (sh
->evtchn_pending
[idx
] &
226 cpu_evtchn_mask(cpu
)[idx
] &
227 ~sh
->evtchn_mask
[idx
]);
230 static void bind_evtchn_to_cpu(unsigned int chn
, unsigned int cpu
)
232 int irq
= evtchn_to_irq
[chn
];
236 cpumask_copy(irq_to_desc(irq
)->affinity
, cpumask_of(cpu
));
239 __clear_bit(chn
, cpu_evtchn_mask(cpu_from_irq(irq
)));
240 __set_bit(chn
, cpu_evtchn_mask(cpu
));
242 irq_info
[irq
].cpu
= cpu
;
245 static void init_evtchn_cpu_bindings(void)
248 struct irq_desc
*desc
;
251 /* By default all event channels notify CPU#0. */
252 for_each_irq_desc(i
, desc
) {
253 cpumask_copy(desc
->affinity
, cpumask_of(0));
257 memset(cpu_evtchn_mask(0), ~0, sizeof(cpu_evtchn_mask(0)));
260 static inline void clear_evtchn(int port
)
262 struct shared_info
*s
= HYPERVISOR_shared_info
;
263 sync_clear_bit(port
, &s
->evtchn_pending
[0]);
266 static inline void set_evtchn(int port
)
268 struct shared_info
*s
= HYPERVISOR_shared_info
;
269 sync_set_bit(port
, &s
->evtchn_pending
[0]);
272 static inline int test_evtchn(int port
)
274 struct shared_info
*s
= HYPERVISOR_shared_info
;
275 return sync_test_bit(port
, &s
->evtchn_pending
[0]);
280 * notify_remote_via_irq - send event to remote end of event channel via irq
281 * @irq: irq of event channel to send event to
283 * Unlike notify_remote_via_evtchn(), this is safe to use across
284 * save/restore. Notifications on a broken connection are silently
287 void notify_remote_via_irq(int irq
)
289 int evtchn
= evtchn_from_irq(irq
);
291 if (VALID_EVTCHN(evtchn
))
292 notify_remote_via_evtchn(evtchn
);
294 EXPORT_SYMBOL_GPL(notify_remote_via_irq
);
296 static void mask_evtchn(int port
)
298 struct shared_info
*s
= HYPERVISOR_shared_info
;
299 sync_set_bit(port
, &s
->evtchn_mask
[0]);
302 static void unmask_evtchn(int port
)
304 struct shared_info
*s
= HYPERVISOR_shared_info
;
305 unsigned int cpu
= get_cpu();
307 BUG_ON(!irqs_disabled());
309 /* Slow path (hypercall) if this is a non-local port. */
310 if (unlikely(cpu
!= cpu_from_evtchn(port
))) {
311 struct evtchn_unmask unmask
= { .port
= port
};
312 (void)HYPERVISOR_event_channel_op(EVTCHNOP_unmask
, &unmask
);
314 struct vcpu_info
*vcpu_info
= __get_cpu_var(xen_vcpu
);
316 sync_clear_bit(port
, &s
->evtchn_mask
[0]);
319 * The following is basically the equivalent of
320 * 'hw_resend_irq'. Just like a real IO-APIC we 'lose
321 * the interrupt edge' if the channel is masked.
323 if (sync_test_bit(port
, &s
->evtchn_pending
[0]) &&
324 !sync_test_and_set_bit(port
/ BITS_PER_LONG
,
325 &vcpu_info
->evtchn_pending_sel
))
326 vcpu_info
->evtchn_upcall_pending
= 1;
332 static int find_unbound_irq(void)
335 struct irq_desc
*desc
;
337 for (irq
= 0; irq
< nr_irqs
; irq
++)
338 if (irq_info
[irq
].type
== IRQT_UNBOUND
)
342 panic("No available IRQ to bind to: increase nr_irqs!\n");
344 desc
= irq_to_desc_alloc_node(irq
, 0);
345 if (WARN_ON(desc
== NULL
))
348 dynamic_irq_init(irq
);
353 int bind_evtchn_to_irq(unsigned int evtchn
)
357 spin_lock(&irq_mapping_update_lock
);
359 irq
= evtchn_to_irq
[evtchn
];
362 irq
= find_unbound_irq();
364 set_irq_chip_and_handler_name(irq
, &xen_dynamic_chip
,
365 handle_level_irq
, "event");
367 evtchn_to_irq
[evtchn
] = irq
;
368 irq_info
[irq
] = mk_evtchn_info(evtchn
);
371 spin_unlock(&irq_mapping_update_lock
);
375 EXPORT_SYMBOL_GPL(bind_evtchn_to_irq
);
377 static int bind_ipi_to_irq(unsigned int ipi
, unsigned int cpu
)
379 struct evtchn_bind_ipi bind_ipi
;
382 spin_lock(&irq_mapping_update_lock
);
384 irq
= per_cpu(ipi_to_irq
, cpu
)[ipi
];
387 irq
= find_unbound_irq();
391 set_irq_chip_and_handler_name(irq
, &xen_dynamic_chip
,
392 handle_level_irq
, "ipi");
395 if (HYPERVISOR_event_channel_op(EVTCHNOP_bind_ipi
,
398 evtchn
= bind_ipi
.port
;
400 evtchn_to_irq
[evtchn
] = irq
;
401 irq_info
[irq
] = mk_ipi_info(evtchn
, ipi
);
402 per_cpu(ipi_to_irq
, cpu
)[ipi
] = irq
;
404 bind_evtchn_to_cpu(evtchn
, cpu
);
408 spin_unlock(&irq_mapping_update_lock
);
413 static int bind_virq_to_irq(unsigned int virq
, unsigned int cpu
)
415 struct evtchn_bind_virq bind_virq
;
418 spin_lock(&irq_mapping_update_lock
);
420 irq
= per_cpu(virq_to_irq
, cpu
)[virq
];
423 bind_virq
.virq
= virq
;
424 bind_virq
.vcpu
= cpu
;
425 if (HYPERVISOR_event_channel_op(EVTCHNOP_bind_virq
,
428 evtchn
= bind_virq
.port
;
430 irq
= find_unbound_irq();
432 set_irq_chip_and_handler_name(irq
, &xen_dynamic_chip
,
433 handle_level_irq
, "virq");
435 evtchn_to_irq
[evtchn
] = irq
;
436 irq_info
[irq
] = mk_virq_info(evtchn
, virq
);
438 per_cpu(virq_to_irq
, cpu
)[virq
] = irq
;
440 bind_evtchn_to_cpu(evtchn
, cpu
);
443 spin_unlock(&irq_mapping_update_lock
);
448 static void unbind_from_irq(unsigned int irq
)
450 struct evtchn_close close
;
451 int evtchn
= evtchn_from_irq(irq
);
453 spin_lock(&irq_mapping_update_lock
);
455 if (VALID_EVTCHN(evtchn
)) {
457 if (HYPERVISOR_event_channel_op(EVTCHNOP_close
, &close
) != 0)
460 switch (type_from_irq(irq
)) {
462 per_cpu(virq_to_irq
, cpu_from_evtchn(evtchn
))
463 [virq_from_irq(irq
)] = -1;
466 per_cpu(ipi_to_irq
, cpu_from_evtchn(evtchn
))
467 [ipi_from_irq(irq
)] = -1;
473 /* Closed ports are implicitly re-bound to VCPU0. */
474 bind_evtchn_to_cpu(evtchn
, 0);
476 evtchn_to_irq
[evtchn
] = -1;
479 if (irq_info
[irq
].type
!= IRQT_UNBOUND
) {
480 irq_info
[irq
] = mk_unbound_info();
482 dynamic_irq_cleanup(irq
);
485 spin_unlock(&irq_mapping_update_lock
);
488 int bind_evtchn_to_irqhandler(unsigned int evtchn
,
489 irq_handler_t handler
,
490 unsigned long irqflags
,
491 const char *devname
, void *dev_id
)
496 irq
= bind_evtchn_to_irq(evtchn
);
497 retval
= request_irq(irq
, handler
, irqflags
, devname
, dev_id
);
499 unbind_from_irq(irq
);
505 EXPORT_SYMBOL_GPL(bind_evtchn_to_irqhandler
);
507 int bind_virq_to_irqhandler(unsigned int virq
, unsigned int cpu
,
508 irq_handler_t handler
,
509 unsigned long irqflags
, const char *devname
, void *dev_id
)
514 irq
= bind_virq_to_irq(virq
, cpu
);
515 retval
= request_irq(irq
, handler
, irqflags
, devname
, dev_id
);
517 unbind_from_irq(irq
);
523 EXPORT_SYMBOL_GPL(bind_virq_to_irqhandler
);
525 int bind_ipi_to_irqhandler(enum ipi_vector ipi
,
527 irq_handler_t handler
,
528 unsigned long irqflags
,
534 irq
= bind_ipi_to_irq(ipi
, cpu
);
538 irqflags
|= IRQF_NO_SUSPEND
;
539 retval
= request_irq(irq
, handler
, irqflags
, devname
, dev_id
);
541 unbind_from_irq(irq
);
548 void unbind_from_irqhandler(unsigned int irq
, void *dev_id
)
550 free_irq(irq
, dev_id
);
551 unbind_from_irq(irq
);
553 EXPORT_SYMBOL_GPL(unbind_from_irqhandler
);
555 void xen_send_IPI_one(unsigned int cpu
, enum ipi_vector vector
)
557 int irq
= per_cpu(ipi_to_irq
, cpu
)[vector
];
559 notify_remote_via_irq(irq
);
562 irqreturn_t
xen_debug_interrupt(int irq
, void *dev_id
)
564 struct shared_info
*sh
= HYPERVISOR_shared_info
;
565 int cpu
= smp_processor_id();
568 static DEFINE_SPINLOCK(debug_lock
);
570 spin_lock_irqsave(&debug_lock
, flags
);
572 printk("vcpu %d\n ", cpu
);
574 for_each_online_cpu(i
) {
575 struct vcpu_info
*v
= per_cpu(xen_vcpu
, i
);
576 printk("%d: masked=%d pending=%d event_sel %08lx\n ", i
,
577 (get_irq_regs() && i
== cpu
) ? xen_irqs_disabled(get_irq_regs()) : v
->evtchn_upcall_mask
,
578 v
->evtchn_upcall_pending
,
579 v
->evtchn_pending_sel
);
581 printk("pending:\n ");
582 for(i
= ARRAY_SIZE(sh
->evtchn_pending
)-1; i
>= 0; i
--)
583 printk("%08lx%s", sh
->evtchn_pending
[i
],
584 i
% 8 == 0 ? "\n " : " ");
585 printk("\nmasks:\n ");
586 for(i
= ARRAY_SIZE(sh
->evtchn_mask
)-1; i
>= 0; i
--)
587 printk("%08lx%s", sh
->evtchn_mask
[i
],
588 i
% 8 == 0 ? "\n " : " ");
590 printk("\nunmasked:\n ");
591 for(i
= ARRAY_SIZE(sh
->evtchn_mask
)-1; i
>= 0; i
--)
592 printk("%08lx%s", sh
->evtchn_pending
[i
] & ~sh
->evtchn_mask
[i
],
593 i
% 8 == 0 ? "\n " : " ");
595 printk("\npending list:\n");
596 for(i
= 0; i
< NR_EVENT_CHANNELS
; i
++) {
597 if (sync_test_bit(i
, sh
->evtchn_pending
)) {
598 printk(" %d: event %d -> irq %d\n",
599 cpu_from_evtchn(i
), i
,
604 spin_unlock_irqrestore(&debug_lock
, flags
);
609 static DEFINE_PER_CPU(unsigned, xed_nesting_count
);
612 * Search the CPUs pending events bitmasks. For each one found, map
613 * the event number to an irq, and feed it into do_IRQ() for
616 * Xen uses a two-level bitmap to speed searching. The first level is
617 * a bitset of words which contain pending event bits. The second
618 * level is a bitset of pending events themselves.
620 void xen_evtchn_do_upcall(struct pt_regs
*regs
)
623 struct pt_regs
*old_regs
= set_irq_regs(regs
);
624 struct shared_info
*s
= HYPERVISOR_shared_info
;
625 struct vcpu_info
*vcpu_info
= __get_cpu_var(xen_vcpu
);
632 unsigned long pending_words
;
634 vcpu_info
->evtchn_upcall_pending
= 0;
636 if (__get_cpu_var(xed_nesting_count
)++)
639 #ifndef CONFIG_X86 /* No need for a barrier -- XCHG is a barrier on x86. */
640 /* Clear master flag /before/ clearing selector flag. */
643 pending_words
= xchg(&vcpu_info
->evtchn_pending_sel
, 0);
644 while (pending_words
!= 0) {
645 unsigned long pending_bits
;
646 int word_idx
= __ffs(pending_words
);
647 pending_words
&= ~(1UL << word_idx
);
649 while ((pending_bits
= active_evtchns(cpu
, s
, word_idx
)) != 0) {
650 int bit_idx
= __ffs(pending_bits
);
651 int port
= (word_idx
* BITS_PER_LONG
) + bit_idx
;
652 int irq
= evtchn_to_irq
[port
];
655 handle_irq(irq
, regs
);
659 BUG_ON(!irqs_disabled());
661 count
= __get_cpu_var(xed_nesting_count
);
662 __get_cpu_var(xed_nesting_count
) = 0;
667 set_irq_regs(old_regs
);
672 /* Rebind a new event channel to an existing irq. */
673 void rebind_evtchn_irq(int evtchn
, int irq
)
675 struct irq_info
*info
= info_for_irq(irq
);
677 /* Make sure the irq is masked, since the new event channel
678 will also be masked. */
681 spin_lock(&irq_mapping_update_lock
);
683 /* After resume the irq<->evtchn mappings are all cleared out */
684 BUG_ON(evtchn_to_irq
[evtchn
] != -1);
685 /* Expect irq to have been bound before,
686 so there should be a proper type */
687 BUG_ON(info
->type
== IRQT_UNBOUND
);
689 evtchn_to_irq
[evtchn
] = irq
;
690 irq_info
[irq
] = mk_evtchn_info(evtchn
);
692 spin_unlock(&irq_mapping_update_lock
);
694 /* new event channels are always bound to cpu 0 */
695 irq_set_affinity(irq
, cpumask_of(0));
697 /* Unmask the event channel. */
701 /* Rebind an evtchn so that it gets delivered to a specific cpu */
702 static int rebind_irq_to_cpu(unsigned irq
, unsigned tcpu
)
704 struct evtchn_bind_vcpu bind_vcpu
;
705 int evtchn
= evtchn_from_irq(irq
);
707 if (!VALID_EVTCHN(evtchn
))
710 /* Send future instances of this interrupt to other vcpu. */
711 bind_vcpu
.port
= evtchn
;
712 bind_vcpu
.vcpu
= tcpu
;
715 * If this fails, it usually just indicates that we're dealing with a
716 * virq or IPI channel, which don't actually need to be rebound. Ignore
717 * it, but don't do the xenlinux-level rebind in that case.
719 if (HYPERVISOR_event_channel_op(EVTCHNOP_bind_vcpu
, &bind_vcpu
) >= 0)
720 bind_evtchn_to_cpu(evtchn
, tcpu
);
725 static int set_affinity_irq(unsigned irq
, const struct cpumask
*dest
)
727 unsigned tcpu
= cpumask_first(dest
);
729 return rebind_irq_to_cpu(irq
, tcpu
);
732 int resend_irq_on_evtchn(unsigned int irq
)
734 int masked
, evtchn
= evtchn_from_irq(irq
);
735 struct shared_info
*s
= HYPERVISOR_shared_info
;
737 if (!VALID_EVTCHN(evtchn
))
740 masked
= sync_test_and_set_bit(evtchn
, s
->evtchn_mask
);
741 sync_set_bit(evtchn
, s
->evtchn_pending
);
743 unmask_evtchn(evtchn
);
748 static void enable_dynirq(unsigned int irq
)
750 int evtchn
= evtchn_from_irq(irq
);
752 if (VALID_EVTCHN(evtchn
))
753 unmask_evtchn(evtchn
);
756 static void disable_dynirq(unsigned int irq
)
758 int evtchn
= evtchn_from_irq(irq
);
760 if (VALID_EVTCHN(evtchn
))
764 static void ack_dynirq(unsigned int irq
)
766 int evtchn
= evtchn_from_irq(irq
);
768 move_native_irq(irq
);
770 if (VALID_EVTCHN(evtchn
))
771 clear_evtchn(evtchn
);
774 static int retrigger_dynirq(unsigned int irq
)
776 int evtchn
= evtchn_from_irq(irq
);
777 struct shared_info
*sh
= HYPERVISOR_shared_info
;
780 if (VALID_EVTCHN(evtchn
)) {
783 masked
= sync_test_and_set_bit(evtchn
, sh
->evtchn_mask
);
784 sync_set_bit(evtchn
, sh
->evtchn_pending
);
786 unmask_evtchn(evtchn
);
793 static void restore_cpu_virqs(unsigned int cpu
)
795 struct evtchn_bind_virq bind_virq
;
796 int virq
, irq
, evtchn
;
798 for (virq
= 0; virq
< NR_VIRQS
; virq
++) {
799 if ((irq
= per_cpu(virq_to_irq
, cpu
)[virq
]) == -1)
802 BUG_ON(virq_from_irq(irq
) != virq
);
804 /* Get a new binding from Xen. */
805 bind_virq
.virq
= virq
;
806 bind_virq
.vcpu
= cpu
;
807 if (HYPERVISOR_event_channel_op(EVTCHNOP_bind_virq
,
810 evtchn
= bind_virq
.port
;
812 /* Record the new mapping. */
813 evtchn_to_irq
[evtchn
] = irq
;
814 irq_info
[irq
] = mk_virq_info(evtchn
, virq
);
815 bind_evtchn_to_cpu(evtchn
, cpu
);
818 unmask_evtchn(evtchn
);
822 static void restore_cpu_ipis(unsigned int cpu
)
824 struct evtchn_bind_ipi bind_ipi
;
825 int ipi
, irq
, evtchn
;
827 for (ipi
= 0; ipi
< XEN_NR_IPIS
; ipi
++) {
828 if ((irq
= per_cpu(ipi_to_irq
, cpu
)[ipi
]) == -1)
831 BUG_ON(ipi_from_irq(irq
) != ipi
);
833 /* Get a new binding from Xen. */
835 if (HYPERVISOR_event_channel_op(EVTCHNOP_bind_ipi
,
838 evtchn
= bind_ipi
.port
;
840 /* Record the new mapping. */
841 evtchn_to_irq
[evtchn
] = irq
;
842 irq_info
[irq
] = mk_ipi_info(evtchn
, ipi
);
843 bind_evtchn_to_cpu(evtchn
, cpu
);
846 unmask_evtchn(evtchn
);
851 /* Clear an irq's pending state, in preparation for polling on it */
852 void xen_clear_irq_pending(int irq
)
854 int evtchn
= evtchn_from_irq(irq
);
856 if (VALID_EVTCHN(evtchn
))
857 clear_evtchn(evtchn
);
860 void xen_set_irq_pending(int irq
)
862 int evtchn
= evtchn_from_irq(irq
);
864 if (VALID_EVTCHN(evtchn
))
868 bool xen_test_irq_pending(int irq
)
870 int evtchn
= evtchn_from_irq(irq
);
873 if (VALID_EVTCHN(evtchn
))
874 ret
= test_evtchn(evtchn
);
879 /* Poll waiting for an irq to become pending. In the usual case, the
880 irq will be disabled so it won't deliver an interrupt. */
881 void xen_poll_irq(int irq
)
883 evtchn_port_t evtchn
= evtchn_from_irq(irq
);
885 if (VALID_EVTCHN(evtchn
)) {
886 struct sched_poll poll
;
890 set_xen_guest_handle(poll
.ports
, &evtchn
);
892 if (HYPERVISOR_sched_op(SCHEDOP_poll
, &poll
) != 0)
897 void xen_irq_resume(void)
899 unsigned int cpu
, irq
, evtchn
;
901 init_evtchn_cpu_bindings();
903 /* New event-channel space is not 'live' yet. */
904 for (evtchn
= 0; evtchn
< NR_EVENT_CHANNELS
; evtchn
++)
907 /* No IRQ <-> event-channel mappings. */
908 for (irq
= 0; irq
< nr_irqs
; irq
++)
909 irq_info
[irq
].evtchn
= 0; /* zap event-channel binding */
911 for (evtchn
= 0; evtchn
< NR_EVENT_CHANNELS
; evtchn
++)
912 evtchn_to_irq
[evtchn
] = -1;
914 for_each_possible_cpu(cpu
) {
915 restore_cpu_virqs(cpu
);
916 restore_cpu_ipis(cpu
);
920 static struct irq_chip xen_dynamic_chip __read_mostly
= {
923 .disable
= disable_dynirq
,
924 .mask
= disable_dynirq
,
925 .unmask
= enable_dynirq
,
928 .set_affinity
= set_affinity_irq
,
929 .retrigger
= retrigger_dynirq
,
932 void __init
xen_init_IRQ(void)
936 cpu_evtchn_mask_p
= kcalloc(nr_cpu_ids
, sizeof(struct cpu_evtchn_s
),
938 BUG_ON(cpu_evtchn_mask_p
== NULL
);
940 init_evtchn_cpu_bindings();
942 /* No event channels are 'live' right now. */
943 for (i
= 0; i
< NR_EVENT_CHANNELS
; i
++)
946 irq_ctx_init(smp_processor_id());