1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _ASM_LOONGARCH_KVM_PARA_H
3 #define _ASM_LOONGARCH_KVM_PARA_H
5 #include <uapi/asm/kvm_para.h>
10 #define HYPERVISOR_KVM 1
11 #define HYPERVISOR_VENDOR_SHIFT 8
12 #define HYPERCALL_ENCODE(vendor, code) ((vendor << HYPERVISOR_VENDOR_SHIFT) + code)
14 #define KVM_HCALL_CODE_SERVICE 0
15 #define KVM_HCALL_CODE_SWDBG 1
17 #define KVM_HCALL_SERVICE HYPERCALL_ENCODE(HYPERVISOR_KVM, KVM_HCALL_CODE_SERVICE)
18 #define KVM_HCALL_FUNC_IPI 1
19 #define KVM_HCALL_FUNC_NOTIFY 2
21 #define KVM_HCALL_SWDBG HYPERCALL_ENCODE(HYPERVISOR_KVM, KVM_HCALL_CODE_SWDBG)
24 * LoongArch hypercall return code
26 #define KVM_HCALL_SUCCESS 0
27 #define KVM_HCALL_INVALID_CODE -1UL
28 #define KVM_HCALL_INVALID_PARAMETER -2UL
30 #define KVM_STEAL_PHYS_VALID BIT_ULL(0)
31 #define KVM_STEAL_PHYS_MASK GENMASK_ULL(63, 6)
33 struct kvm_steal_time
{
41 * Hypercall interface for KVM hypervisor
43 * a0: function identifier
45 * Return value will be placed in a0.
46 * Up to 5 arguments are passed in a1, a2, a3, a4, a5.
48 static __always_inline
long kvm_hypercall0(u64 fid
)
50 register long ret
asm("a0");
51 register unsigned long fun
asm("a0") = fid
;
54 "hvcl "__stringify(KVM_HCALL_SERVICE
)
63 static __always_inline
long kvm_hypercall1(u64 fid
, unsigned long arg0
)
65 register long ret
asm("a0");
66 register unsigned long fun
asm("a0") = fid
;
67 register unsigned long a1
asm("a1") = arg0
;
70 "hvcl "__stringify(KVM_HCALL_SERVICE
)
79 static __always_inline
long kvm_hypercall2(u64 fid
,
80 unsigned long arg0
, unsigned long arg1
)
82 register long ret
asm("a0");
83 register unsigned long fun
asm("a0") = fid
;
84 register unsigned long a1
asm("a1") = arg0
;
85 register unsigned long a2
asm("a2") = arg1
;
88 "hvcl "__stringify(KVM_HCALL_SERVICE
)
90 : "r" (fun
), "r" (a1
), "r" (a2
)
97 static __always_inline
long kvm_hypercall3(u64 fid
,
98 unsigned long arg0
, unsigned long arg1
, unsigned long arg2
)
100 register long ret
asm("a0");
101 register unsigned long fun
asm("a0") = fid
;
102 register unsigned long a1
asm("a1") = arg0
;
103 register unsigned long a2
asm("a2") = arg1
;
104 register unsigned long a3
asm("a3") = arg2
;
106 __asm__
__volatile__(
107 "hvcl "__stringify(KVM_HCALL_SERVICE
)
109 : "r" (fun
), "r" (a1
), "r" (a2
), "r" (a3
)
116 static __always_inline
long kvm_hypercall4(u64 fid
,
117 unsigned long arg0
, unsigned long arg1
,
118 unsigned long arg2
, unsigned long arg3
)
120 register long ret
asm("a0");
121 register unsigned long fun
asm("a0") = fid
;
122 register unsigned long a1
asm("a1") = arg0
;
123 register unsigned long a2
asm("a2") = arg1
;
124 register unsigned long a3
asm("a3") = arg2
;
125 register unsigned long a4
asm("a4") = arg3
;
127 __asm__
__volatile__(
128 "hvcl "__stringify(KVM_HCALL_SERVICE
)
130 : "r"(fun
), "r" (a1
), "r" (a2
), "r" (a3
), "r" (a4
)
137 static __always_inline
long kvm_hypercall5(u64 fid
,
138 unsigned long arg0
, unsigned long arg1
,
139 unsigned long arg2
, unsigned long arg3
, unsigned long arg4
)
141 register long ret
asm("a0");
142 register unsigned long fun
asm("a0") = fid
;
143 register unsigned long a1
asm("a1") = arg0
;
144 register unsigned long a2
asm("a2") = arg1
;
145 register unsigned long a3
asm("a3") = arg2
;
146 register unsigned long a4
asm("a4") = arg3
;
147 register unsigned long a5
asm("a5") = arg4
;
149 __asm__
__volatile__(
150 "hvcl "__stringify(KVM_HCALL_SERVICE
)
152 : "r"(fun
), "r" (a1
), "r" (a2
), "r" (a3
), "r" (a4
), "r" (a5
)
159 #ifdef CONFIG_PARAVIRT
160 bool kvm_para_available(void);
161 unsigned int kvm_arch_para_features(void);
163 static inline bool kvm_para_available(void)
168 static inline unsigned int kvm_arch_para_features(void)
174 static inline unsigned int kvm_arch_para_hints(void)
179 static inline bool kvm_check_and_clear_guest_paused(void)
184 #endif /* _ASM_LOONGARCH_KVM_PARA_H */