xref: /openbmc/linux/arch/s390/include/asm/kvm_para.h (revision da1d9caf)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * definition for paravirtual devices on s390
4  *
5  * Copyright IBM Corp. 2008
6  *
7  *    Author(s): Christian Borntraeger <borntraeger@de.ibm.com>
8  */
9 /*
10  * Hypercalls for KVM on s390. The calling convention is similar to the
11  * s390 ABI, so we use R2-R6 for parameters 1-5. In addition we use R1
12  * as hypercall number and R7 as parameter 6. The return value is
13  * written to R2. We use the diagnose instruction as hypercall. To avoid
14  * conflicts with existing diagnoses for LPAR and z/VM, we do not use
15  * the instruction encoded number, but specify the number in R1 and
16  * use 0x500 as KVM hypercall
17  *
18  * Copyright IBM Corp. 2007,2008
19  * Author(s): Christian Borntraeger <borntraeger@de.ibm.com>
20  */
21 #ifndef __S390_KVM_PARA_H
22 #define __S390_KVM_PARA_H
23 
24 #include <uapi/asm/kvm_para.h>
25 #include <asm/diag.h>
26 
27 #define HYPERCALL_FMT_0
28 #define HYPERCALL_FMT_1 , "0" (r2)
29 #define HYPERCALL_FMT_2 , "d" (r3) HYPERCALL_FMT_1
30 #define HYPERCALL_FMT_3 , "d" (r4) HYPERCALL_FMT_2
31 #define HYPERCALL_FMT_4 , "d" (r5) HYPERCALL_FMT_3
32 #define HYPERCALL_FMT_5 , "d" (r6) HYPERCALL_FMT_4
33 #define HYPERCALL_FMT_6 , "d" (r7) HYPERCALL_FMT_5
34 
35 #define HYPERCALL_PARM_0
36 #define HYPERCALL_PARM_1 , unsigned long arg1
37 #define HYPERCALL_PARM_2 HYPERCALL_PARM_1, unsigned long arg2
38 #define HYPERCALL_PARM_3 HYPERCALL_PARM_2, unsigned long arg3
39 #define HYPERCALL_PARM_4 HYPERCALL_PARM_3, unsigned long arg4
40 #define HYPERCALL_PARM_5 HYPERCALL_PARM_4, unsigned long arg5
41 #define HYPERCALL_PARM_6 HYPERCALL_PARM_5, unsigned long arg6
42 
43 #define HYPERCALL_REGS_0
44 #define HYPERCALL_REGS_1						\
45 	register unsigned long r2 asm("2") = arg1
46 #define HYPERCALL_REGS_2						\
47 	HYPERCALL_REGS_1;						\
48 	register unsigned long r3 asm("3") = arg2
49 #define HYPERCALL_REGS_3						\
50 	HYPERCALL_REGS_2;						\
51 	register unsigned long r4 asm("4") = arg3
52 #define HYPERCALL_REGS_4						\
53 	HYPERCALL_REGS_3;						\
54 	register unsigned long r5 asm("5") = arg4
55 #define HYPERCALL_REGS_5						\
56 	HYPERCALL_REGS_4;						\
57 	register unsigned long r6 asm("6") = arg5
58 #define HYPERCALL_REGS_6						\
59 	HYPERCALL_REGS_5;						\
60 	register unsigned long r7 asm("7") = arg6
61 
62 #define HYPERCALL_ARGS_0
63 #define HYPERCALL_ARGS_1 , arg1
64 #define HYPERCALL_ARGS_2 HYPERCALL_ARGS_1, arg2
65 #define HYPERCALL_ARGS_3 HYPERCALL_ARGS_2, arg3
66 #define HYPERCALL_ARGS_4 HYPERCALL_ARGS_3, arg4
67 #define HYPERCALL_ARGS_5 HYPERCALL_ARGS_4, arg5
68 #define HYPERCALL_ARGS_6 HYPERCALL_ARGS_5, arg6
69 
70 #define GENERATE_KVM_HYPERCALL_FUNC(args)				\
71 static inline								\
72 long __kvm_hypercall##args(unsigned long nr HYPERCALL_PARM_##args)	\
73 {									\
74 	register unsigned long __nr asm("1") = nr;			\
75 	register long __rc asm("2");					\
76 	HYPERCALL_REGS_##args;						\
77 									\
78 	asm volatile (							\
79 		"	diag	2,4,0x500\n"				\
80 		: "=d" (__rc)						\
81 		: "d" (__nr) HYPERCALL_FMT_##args			\
82 		: "memory", "cc");					\
83 	return __rc;							\
84 }									\
85 									\
86 static inline								\
87 long kvm_hypercall##args(unsigned long nr HYPERCALL_PARM_##args)	\
88 {									\
89 	diag_stat_inc(DIAG_STAT_X500);					\
90 	return __kvm_hypercall##args(nr HYPERCALL_ARGS_##args);		\
91 }
92 
93 GENERATE_KVM_HYPERCALL_FUNC(0)
94 GENERATE_KVM_HYPERCALL_FUNC(1)
95 GENERATE_KVM_HYPERCALL_FUNC(2)
96 GENERATE_KVM_HYPERCALL_FUNC(3)
97 GENERATE_KVM_HYPERCALL_FUNC(4)
98 GENERATE_KVM_HYPERCALL_FUNC(5)
99 GENERATE_KVM_HYPERCALL_FUNC(6)
100 
101 /* kvm on s390 is always paravirtualization enabled */
102 static inline int kvm_para_available(void)
103 {
104 	return 1;
105 }
106 
107 /* No feature bits are currently assigned for kvm on s390 */
108 static inline unsigned int kvm_arch_para_features(void)
109 {
110 	return 0;
111 }
112 
113 static inline unsigned int kvm_arch_para_hints(void)
114 {
115 	return 0;
116 }
117 
118 static inline bool kvm_check_and_clear_guest_paused(void)
119 {
120 	return false;
121 }
122 
123 #endif /* __S390_KVM_PARA_H */
124