warning removal
[cor_2_6_31.git] / arch / x86 / xen / irq.c
blobcfd17799bd6d23e8e2ce93e2862b09d4270fa442
1 #include <linux/hardirq.h>
3 #include <xen/interface/xen.h>
4 #include <xen/interface/sched.h>
5 #include <xen/interface/vcpu.h>
7 #include <asm/xen/hypercall.h>
8 #include <asm/xen/hypervisor.h>
10 #include "xen-ops.h"
13 * Force a proper event-channel callback from Xen after clearing the
14 * callback mask. We do this in a very simple manner, by making a call
15 * down into Xen. The pending flag will be checked by Xen on return.
17 void xen_force_evtchn_callback(void)
19 (void)HYPERVISOR_xen_version(0, NULL);
22 static unsigned long xen_save_fl(void)
24 struct vcpu_info *vcpu;
25 unsigned long flags;
27 vcpu = percpu_read(xen_vcpu);
29 /* flag has opposite sense of mask */
30 flags = !vcpu->evtchn_upcall_mask;
32 /* convert to IF type flag
33 -0 -> 0x00000000
34 -1 -> 0xffffffff
36 return (-flags) & X86_EFLAGS_IF;
38 PV_CALLEE_SAVE_REGS_THUNK(xen_save_fl);
40 static void xen_restore_fl(unsigned long flags)
42 struct vcpu_info *vcpu;
44 /* convert from IF type flag */
45 flags = !(flags & X86_EFLAGS_IF);
47 /* There's a one instruction preempt window here. We need to
48 make sure we're don't switch CPUs between getting the vcpu
49 pointer and updating the mask. */
50 preempt_disable();
51 vcpu = percpu_read(xen_vcpu);
52 vcpu->evtchn_upcall_mask = flags;
53 preempt_enable_no_resched();
55 /* Doesn't matter if we get preempted here, because any
56 pending event will get dealt with anyway. */
58 if (flags == 0) {
59 preempt_check_resched();
60 barrier(); /* unmask then check (avoid races) */
61 if (unlikely(vcpu->evtchn_upcall_pending))
62 xen_force_evtchn_callback();
65 PV_CALLEE_SAVE_REGS_THUNK(xen_restore_fl);
67 static void xen_irq_disable(void)
69 /* There's a one instruction preempt window here. We need to
70 make sure we're don't switch CPUs between getting the vcpu
71 pointer and updating the mask. */
72 preempt_disable();
73 percpu_read(xen_vcpu)->evtchn_upcall_mask = 1;
74 preempt_enable_no_resched();
76 PV_CALLEE_SAVE_REGS_THUNK(xen_irq_disable);
78 static void xen_irq_enable(void)
80 struct vcpu_info *vcpu;
82 /* We don't need to worry about being preempted here, since
83 either a) interrupts are disabled, so no preemption, or b)
84 the caller is confused and is trying to re-enable interrupts
85 on an indeterminate processor. */
87 vcpu = percpu_read(xen_vcpu);
88 vcpu->evtchn_upcall_mask = 0;
90 /* Doesn't matter if we get preempted here, because any
91 pending event will get dealt with anyway. */
93 barrier(); /* unmask then check (avoid races) */
94 if (unlikely(vcpu->evtchn_upcall_pending))
95 xen_force_evtchn_callback();
97 PV_CALLEE_SAVE_REGS_THUNK(xen_irq_enable);
99 static void xen_safe_halt(void)
101 /* Blocking includes an implicit local_irq_enable(). */
102 if (HYPERVISOR_sched_op(SCHEDOP_block, NULL) != 0)
103 BUG();
106 static void xen_halt(void)
108 if (irqs_disabled())
109 HYPERVISOR_vcpu_op(VCPUOP_down, smp_processor_id(), NULL);
110 else
111 xen_safe_halt();
114 static const struct pv_irq_ops xen_irq_ops __initdata = {
115 .init_IRQ = xen_init_IRQ,
117 .save_fl = PV_CALLEE_SAVE(xen_save_fl),
118 .restore_fl = PV_CALLEE_SAVE(xen_restore_fl),
119 .irq_disable = PV_CALLEE_SAVE(xen_irq_disable),
120 .irq_enable = PV_CALLEE_SAVE(xen_irq_enable),
122 .safe_halt = xen_safe_halt,
123 .halt = xen_halt,
124 #ifdef CONFIG_X86_64
125 .adjust_exception_frame = xen_adjust_exception_frame,
126 #endif
129 void __init xen_init_irq_ops()
131 pv_irq_ops = xen_irq_ops;