xref: /openbmc/linux/arch/s390/include/asm/kvm_para.h (revision 5d331b7f)
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 static inline long __kvm_hypercall0(unsigned long nr)
28 {
29 	register unsigned long __nr asm("1") = nr;
30 	register long __rc asm("2");
31 
32 	asm volatile ("diag 2,4,0x500\n"
33 		      : "=d" (__rc) : "d" (__nr): "memory", "cc");
34 	return __rc;
35 }
36 
37 static inline long kvm_hypercall0(unsigned long nr)
38 {
39 	diag_stat_inc(DIAG_STAT_X500);
40 	return __kvm_hypercall0(nr);
41 }
42 
43 static inline long __kvm_hypercall1(unsigned long nr, unsigned long p1)
44 {
45 	register unsigned long __nr asm("1") = nr;
46 	register unsigned long __p1 asm("2") = p1;
47 	register long __rc asm("2");
48 
49 	asm volatile ("diag 2,4,0x500\n"
50 		      : "=d" (__rc) : "d" (__nr), "0" (__p1) : "memory", "cc");
51 	return __rc;
52 }
53 
54 static inline long kvm_hypercall1(unsigned long nr, unsigned long p1)
55 {
56 	diag_stat_inc(DIAG_STAT_X500);
57 	return __kvm_hypercall1(nr, p1);
58 }
59 
60 static inline long __kvm_hypercall2(unsigned long nr, unsigned long p1,
61 			       unsigned long p2)
62 {
63 	register unsigned long __nr asm("1") = nr;
64 	register unsigned long __p1 asm("2") = p1;
65 	register unsigned long __p2 asm("3") = p2;
66 	register long __rc asm("2");
67 
68 	asm volatile ("diag 2,4,0x500\n"
69 		      : "=d" (__rc) : "d" (__nr), "0" (__p1), "d" (__p2)
70 		      : "memory", "cc");
71 	return __rc;
72 }
73 
74 static inline long kvm_hypercall2(unsigned long nr, unsigned long p1,
75 			       unsigned long p2)
76 {
77 	diag_stat_inc(DIAG_STAT_X500);
78 	return __kvm_hypercall2(nr, p1, p2);
79 }
80 
81 static inline long __kvm_hypercall3(unsigned long nr, unsigned long p1,
82 			       unsigned long p2, unsigned long p3)
83 {
84 	register unsigned long __nr asm("1") = nr;
85 	register unsigned long __p1 asm("2") = p1;
86 	register unsigned long __p2 asm("3") = p2;
87 	register unsigned long __p3 asm("4") = p3;
88 	register long __rc asm("2");
89 
90 	asm volatile ("diag 2,4,0x500\n"
91 		      : "=d" (__rc) : "d" (__nr), "0" (__p1), "d" (__p2),
92 			"d" (__p3) : "memory", "cc");
93 	return __rc;
94 }
95 
96 static inline long kvm_hypercall3(unsigned long nr, unsigned long p1,
97 			       unsigned long p2, unsigned long p3)
98 {
99 	diag_stat_inc(DIAG_STAT_X500);
100 	return __kvm_hypercall3(nr, p1, p2, p3);
101 }
102 
103 static inline long __kvm_hypercall4(unsigned long nr, unsigned long p1,
104 			       unsigned long p2, unsigned long p3,
105 			       unsigned long p4)
106 {
107 	register unsigned long __nr asm("1") = nr;
108 	register unsigned long __p1 asm("2") = p1;
109 	register unsigned long __p2 asm("3") = p2;
110 	register unsigned long __p3 asm("4") = p3;
111 	register unsigned long __p4 asm("5") = p4;
112 	register long __rc asm("2");
113 
114 	asm volatile ("diag 2,4,0x500\n"
115 		      : "=d" (__rc) : "d" (__nr), "0" (__p1), "d" (__p2),
116 			"d" (__p3), "d" (__p4) : "memory", "cc");
117 	return __rc;
118 }
119 
120 static inline long kvm_hypercall4(unsigned long nr, unsigned long p1,
121 			       unsigned long p2, unsigned long p3,
122 			       unsigned long p4)
123 {
124 	diag_stat_inc(DIAG_STAT_X500);
125 	return __kvm_hypercall4(nr, p1, p2, p3, p4);
126 }
127 
128 static inline long __kvm_hypercall5(unsigned long nr, unsigned long p1,
129 			       unsigned long p2, unsigned long p3,
130 			       unsigned long p4, unsigned long p5)
131 {
132 	register unsigned long __nr asm("1") = nr;
133 	register unsigned long __p1 asm("2") = p1;
134 	register unsigned long __p2 asm("3") = p2;
135 	register unsigned long __p3 asm("4") = p3;
136 	register unsigned long __p4 asm("5") = p4;
137 	register unsigned long __p5 asm("6") = p5;
138 	register long __rc asm("2");
139 
140 	asm volatile ("diag 2,4,0x500\n"
141 		      : "=d" (__rc) : "d" (__nr), "0" (__p1), "d" (__p2),
142 			"d" (__p3), "d" (__p4), "d" (__p5)  : "memory", "cc");
143 	return __rc;
144 }
145 
146 static inline long kvm_hypercall5(unsigned long nr, unsigned long p1,
147 			       unsigned long p2, unsigned long p3,
148 			       unsigned long p4, unsigned long p5)
149 {
150 	diag_stat_inc(DIAG_STAT_X500);
151 	return __kvm_hypercall5(nr, p1, p2, p3, p4, p5);
152 }
153 
154 static inline long __kvm_hypercall6(unsigned long nr, unsigned long p1,
155 			       unsigned long p2, unsigned long p3,
156 			       unsigned long p4, unsigned long p5,
157 			       unsigned long p6)
158 {
159 	register unsigned long __nr asm("1") = nr;
160 	register unsigned long __p1 asm("2") = p1;
161 	register unsigned long __p2 asm("3") = p2;
162 	register unsigned long __p3 asm("4") = p3;
163 	register unsigned long __p4 asm("5") = p4;
164 	register unsigned long __p5 asm("6") = p5;
165 	register unsigned long __p6 asm("7") = p6;
166 	register long __rc asm("2");
167 
168 	asm volatile ("diag 2,4,0x500\n"
169 		      : "=d" (__rc) : "d" (__nr), "0" (__p1), "d" (__p2),
170 			"d" (__p3), "d" (__p4), "d" (__p5), "d" (__p6)
171 		      : "memory", "cc");
172 	return __rc;
173 }
174 
175 static inline long kvm_hypercall6(unsigned long nr, unsigned long p1,
176 			       unsigned long p2, unsigned long p3,
177 			       unsigned long p4, unsigned long p5,
178 			       unsigned long p6)
179 {
180 	diag_stat_inc(DIAG_STAT_X500);
181 	return __kvm_hypercall6(nr, p1, p2, p3, p4, p5, p6);
182 }
183 
184 /* kvm on s390 is always paravirtualization enabled */
185 static inline int kvm_para_available(void)
186 {
187 	return 1;
188 }
189 
190 /* No feature bits are currently assigned for kvm on s390 */
191 static inline unsigned int kvm_arch_para_features(void)
192 {
193 	return 0;
194 }
195 
196 static inline unsigned int kvm_arch_para_hints(void)
197 {
198 	return 0;
199 }
200 
201 static inline bool kvm_check_and_clear_guest_paused(void)
202 {
203 	return false;
204 }
205 
206 #endif /* __S390_KVM_PARA_H */
207