blob: 8019edd0125c93d1310c187cf74e6520852c1ef7 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
Jeremy Fitzhardinge53937442009-02-02 13:55:42 -08002/*
Juergen Grossedcb5cf2017-08-16 19:31:56 +02003 * Asm versions of Xen pv-ops, suitable for direct use.
Tejun Heo130ace12009-02-06 00:57:48 +09004 *
5 * We only bother with direct forms (ie, vcpu in percpu data) of the
Juergen Grossedcb5cf2017-08-16 19:31:56 +02006 * operations here; the indirect forms are better handled in C.
Jeremy Fitzhardinge53937442009-02-02 13:55:42 -08007 */
8
9#include <asm/asm-offsets.h>
10#include <asm/percpu.h>
11#include <asm/processor-flags.h>
Josh Poimboeuf8be0eb72016-01-21 16:49:11 -060012#include <asm/frame.h>
Jeremy Fitzhardinge53937442009-02-02 13:55:42 -080013
Juergen Grossedcb5cf2017-08-16 19:31:56 +020014#include <linux/linkage.h>
Jeremy Fitzhardinge53937442009-02-02 13:55:42 -080015
16/*
Tejun Heo130ace12009-02-06 00:57:48 +090017 * Enable events. This clears the event mask and tests the pending
18 * event status with one and operation. If there are pending events,
19 * then enter the hypervisor to get them handled.
Jeremy Fitzhardinge53937442009-02-02 13:55:42 -080020 */
21ENTRY(xen_irq_enable_direct)
Josh Poimboeuf8be0eb72016-01-21 16:49:11 -060022 FRAME_BEGIN
Jeremy Fitzhardinge53937442009-02-02 13:55:42 -080023 /* Unmask events */
24 movb $0, PER_CPU_VAR(xen_vcpu_info) + XEN_vcpu_info_mask
25
Tejun Heo130ace12009-02-06 00:57:48 +090026 /*
27 * Preempt here doesn't matter because that will deal with any
28 * pending interrupts. The pending check may end up being run
29 * on the wrong CPU, but that doesn't hurt.
30 */
Jeremy Fitzhardinge53937442009-02-02 13:55:42 -080031
32 /* Test for pending */
33 testb $0xff, PER_CPU_VAR(xen_vcpu_info) + XEN_vcpu_info_pending
34 jz 1f
35
Juergen Grossedcb5cf2017-08-16 19:31:56 +020036 call check_events
Jeremy Fitzhardinge53937442009-02-02 13:55:42 -0800371:
Josh Poimboeuf8be0eb72016-01-21 16:49:11 -060038 FRAME_END
Jeremy Fitzhardinge53937442009-02-02 13:55:42 -080039 ret
40 ENDPROC(xen_irq_enable_direct)
Jeremy Fitzhardinge53937442009-02-02 13:55:42 -080041
42
43/*
Tejun Heo130ace12009-02-06 00:57:48 +090044 * Disabling events is simply a matter of making the event mask
45 * non-zero.
Jeremy Fitzhardinge53937442009-02-02 13:55:42 -080046 */
47ENTRY(xen_irq_disable_direct)
48 movb $1, PER_CPU_VAR(xen_vcpu_info) + XEN_vcpu_info_mask
Jeremy Fitzhardinge53937442009-02-02 13:55:42 -080049 ret
Juergen Grossedcb5cf2017-08-16 19:31:56 +020050ENDPROC(xen_irq_disable_direct)
Jeremy Fitzhardinge53937442009-02-02 13:55:42 -080051
52/*
Tejun Heo130ace12009-02-06 00:57:48 +090053 * (xen_)save_fl is used to get the current interrupt enable status.
54 * Callers expect the status to be in X86_EFLAGS_IF, and other bits
55 * may be set in the return value. We take advantage of this by
56 * making sure that X86_EFLAGS_IF has the right value (and other bits
57 * in that byte are 0), but other bits in the return value are
58 * undefined. We need to toggle the state of the bit, because Xen and
59 * x86 use opposite senses (mask vs enable).
Jeremy Fitzhardinge53937442009-02-02 13:55:42 -080060 */
61ENTRY(xen_save_fl_direct)
62 testb $0xff, PER_CPU_VAR(xen_vcpu_info) + XEN_vcpu_info_mask
63 setz %ah
Tejun Heo130ace12009-02-06 00:57:48 +090064 addb %ah, %ah
Jeremy Fitzhardinge53937442009-02-02 13:55:42 -080065 ret
66 ENDPROC(xen_save_fl_direct)
Jeremy Fitzhardinge53937442009-02-02 13:55:42 -080067
68
69/*
Tejun Heo130ace12009-02-06 00:57:48 +090070 * In principle the caller should be passing us a value return from
71 * xen_save_fl_direct, but for robustness sake we test only the
72 * X86_EFLAGS_IF flag rather than the whole byte. After setting the
73 * interrupt mask state, it checks for unmasked pending events and
74 * enters the hypervisor to get them delivered if so.
Jeremy Fitzhardinge53937442009-02-02 13:55:42 -080075 */
76ENTRY(xen_restore_fl_direct)
Josh Poimboeuf8be0eb72016-01-21 16:49:11 -060077 FRAME_BEGIN
Jeremy Fitzhardinge53937442009-02-02 13:55:42 -080078#ifdef CONFIG_X86_64
79 testw $X86_EFLAGS_IF, %di
80#else
81 testb $X86_EFLAGS_IF>>8, %ah
82#endif
83 setz PER_CPU_VAR(xen_vcpu_info) + XEN_vcpu_info_mask
Tejun Heo130ace12009-02-06 00:57:48 +090084 /*
85 * Preempt here doesn't matter because that will deal with any
86 * pending interrupts. The pending check may end up being run
87 * on the wrong CPU, but that doesn't hurt.
88 */
Jeremy Fitzhardinge53937442009-02-02 13:55:42 -080089
90 /* check for unmasked and pending */
91 cmpw $0x0001, PER_CPU_VAR(xen_vcpu_info) + XEN_vcpu_info_pending
David Vrabel7eb7ce42012-04-26 19:44:06 +010092 jnz 1f
Juergen Grossedcb5cf2017-08-16 19:31:56 +020093 call check_events
Jeremy Fitzhardinge53937442009-02-02 13:55:42 -0800941:
Josh Poimboeuf8be0eb72016-01-21 16:49:11 -060095 FRAME_END
Jeremy Fitzhardinge53937442009-02-02 13:55:42 -080096 ret
97 ENDPROC(xen_restore_fl_direct)
Jeremy Fitzhardinge53937442009-02-02 13:55:42 -080098
99
100/*
Tejun Heo130ace12009-02-06 00:57:48 +0900101 * Force an event check by making a hypercall, but preserve regs
102 * before making the call.
Jeremy Fitzhardinge53937442009-02-02 13:55:42 -0800103 */
Josh Poimboeuf8be0eb72016-01-21 16:49:11 -0600104ENTRY(check_events)
105 FRAME_BEGIN
Jeremy Fitzhardinge53937442009-02-02 13:55:42 -0800106#ifdef CONFIG_X86_32
107 push %eax
108 push %ecx
109 push %edx
110 call xen_force_evtchn_callback
111 pop %edx
112 pop %ecx
113 pop %eax
114#else
115 push %rax
116 push %rcx
117 push %rdx
118 push %rsi
119 push %rdi
120 push %r8
121 push %r9
122 push %r10
123 push %r11
124 call xen_force_evtchn_callback
125 pop %r11
126 pop %r10
127 pop %r9
128 pop %r8
129 pop %rdi
130 pop %rsi
131 pop %rdx
132 pop %rcx
133 pop %rax
134#endif
Josh Poimboeuf8be0eb72016-01-21 16:49:11 -0600135 FRAME_END
Jeremy Fitzhardinge53937442009-02-02 13:55:42 -0800136 ret
Josh Poimboeuf8be0eb72016-01-21 16:49:11 -0600137ENDPROC(check_events)