arm64: dts: Revert "specify console via command line"
[linux/fpc-iii.git] / arch / x86 / xen / irq.c
blob850c93f346c70f5d62d6134cb51b4ba909874d89
1 // SPDX-License-Identifier: GPL-2.0
2 #include <linux/hardirq.h>
4 #include <asm/x86_init.h>
6 #include <xen/interface/xen.h>
7 #include <xen/interface/sched.h>
8 #include <xen/interface/vcpu.h>
9 #include <xen/features.h>
10 #include <xen/events.h>
12 #include <asm/xen/hypercall.h>
13 #include <asm/xen/hypervisor.h>
15 #include "xen-ops.h"
18 * Force a proper event-channel callback from Xen after clearing the
19 * callback mask. We do this in a very simple manner, by making a call
20 * down into Xen. The pending flag will be checked by Xen on return.
22 void xen_force_evtchn_callback(void)
24 (void)HYPERVISOR_xen_version(0, NULL);
27 asmlinkage __visible unsigned long xen_save_fl(void)
29 struct vcpu_info *vcpu;
30 unsigned long flags;
32 vcpu = this_cpu_read(xen_vcpu);
34 /* flag has opposite sense of mask */
35 flags = !vcpu->evtchn_upcall_mask;
37 /* convert to IF type flag
38 -0 -> 0x00000000
39 -1 -> 0xffffffff
41 return (-flags) & X86_EFLAGS_IF;
43 PV_CALLEE_SAVE_REGS_THUNK(xen_save_fl);
45 __visible void xen_restore_fl(unsigned long flags)
47 struct vcpu_info *vcpu;
49 /* convert from IF type flag */
50 flags = !(flags & X86_EFLAGS_IF);
52 /* See xen_irq_enable() for why preemption must be disabled. */
53 preempt_disable();
54 vcpu = this_cpu_read(xen_vcpu);
55 vcpu->evtchn_upcall_mask = flags;
57 if (flags == 0) {
58 barrier(); /* unmask then check (avoid races) */
59 if (unlikely(vcpu->evtchn_upcall_pending))
60 xen_force_evtchn_callback();
61 preempt_enable();
62 } else
63 preempt_enable_no_resched();
65 PV_CALLEE_SAVE_REGS_THUNK(xen_restore_fl);
67 asmlinkage __visible 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 this_cpu_read(xen_vcpu)->evtchn_upcall_mask = 1;
74 preempt_enable_no_resched();
76 PV_CALLEE_SAVE_REGS_THUNK(xen_irq_disable);
78 asmlinkage __visible void xen_irq_enable(void)
80 struct vcpu_info *vcpu;
83 * We may be preempted as soon as vcpu->evtchn_upcall_mask is
84 * cleared, so disable preemption to ensure we check for
85 * events on the VCPU we are still running on.
87 preempt_disable();
89 vcpu = this_cpu_read(xen_vcpu);
90 vcpu->evtchn_upcall_mask = 0;
92 /* Doesn't matter if we get preempted here, because any
93 pending event will get dealt with anyway. */
95 barrier(); /* unmask then check (avoid races) */
96 if (unlikely(vcpu->evtchn_upcall_pending))
97 xen_force_evtchn_callback();
99 preempt_enable();
101 PV_CALLEE_SAVE_REGS_THUNK(xen_irq_enable);
103 static void xen_safe_halt(void)
105 /* Blocking includes an implicit local_irq_enable(). */
106 if (HYPERVISOR_sched_op(SCHEDOP_block, NULL) != 0)
107 BUG();
110 static void xen_halt(void)
112 if (irqs_disabled())
113 HYPERVISOR_vcpu_op(VCPUOP_down,
114 xen_vcpu_nr(smp_processor_id()), NULL);
115 else
116 xen_safe_halt();
119 static const struct pv_irq_ops xen_irq_ops __initconst = {
120 .save_fl = PV_CALLEE_SAVE(xen_save_fl),
121 .restore_fl = PV_CALLEE_SAVE(xen_restore_fl),
122 .irq_disable = PV_CALLEE_SAVE(xen_irq_disable),
123 .irq_enable = PV_CALLEE_SAVE(xen_irq_enable),
125 .safe_halt = xen_safe_halt,
126 .halt = xen_halt,
129 void __init xen_init_irq_ops(void)
131 pv_ops.irq = xen_irq_ops;
132 x86_init.irqs.intr_init = xen_init_IRQ;