xref: /openbmc/linux/arch/s390/include/asm/kvm_para.h (revision 12eb4683)
1 /*
2  * definition for paravirtual devices on s390
3  *
4  * Copyright IBM Corp. 2008
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License (version 2 only)
8  * as published by the Free Software Foundation.
9  *
10  *    Author(s): Christian Borntraeger <borntraeger@de.ibm.com>
11  */
12 /*
13  * Hypercalls for KVM on s390. The calling convention is similar to the
14  * s390 ABI, so we use R2-R6 for parameters 1-5. In addition we use R1
15  * as hypercall number and R7 as parameter 6. The return value is
16  * written to R2. We use the diagnose instruction as hypercall. To avoid
17  * conflicts with existing diagnoses for LPAR and z/VM, we do not use
18  * the instruction encoded number, but specify the number in R1 and
19  * use 0x500 as KVM hypercall
20  *
21  * Copyright IBM Corp. 2007,2008
22  * Author(s): Christian Borntraeger <borntraeger@de.ibm.com>
23  *
24  * This work is licensed under the terms of the GNU GPL, version 2.
25  */
26 #ifndef __S390_KVM_PARA_H
27 #define __S390_KVM_PARA_H
28 
29 #include <uapi/asm/kvm_para.h>
30 
31 
32 
33 static inline long kvm_hypercall0(unsigned long nr)
34 {
35 	register unsigned long __nr asm("1") = nr;
36 	register long __rc asm("2");
37 
38 	asm volatile ("diag 2,4,0x500\n"
39 		      : "=d" (__rc) : "d" (__nr): "memory", "cc");
40 	return __rc;
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_hypercall2(unsigned long nr, unsigned long p1,
55 			       unsigned long p2)
56 {
57 	register unsigned long __nr asm("1") = nr;
58 	register unsigned long __p1 asm("2") = p1;
59 	register unsigned long __p2 asm("3") = p2;
60 	register long __rc asm("2");
61 
62 	asm volatile ("diag 2,4,0x500\n"
63 		      : "=d" (__rc) : "d" (__nr), "0" (__p1), "d" (__p2)
64 		      : "memory", "cc");
65 	return __rc;
66 }
67 
68 static inline long kvm_hypercall3(unsigned long nr, unsigned long p1,
69 			       unsigned long p2, unsigned long p3)
70 {
71 	register unsigned long __nr asm("1") = nr;
72 	register unsigned long __p1 asm("2") = p1;
73 	register unsigned long __p2 asm("3") = p2;
74 	register unsigned long __p3 asm("4") = p3;
75 	register long __rc asm("2");
76 
77 	asm volatile ("diag 2,4,0x500\n"
78 		      : "=d" (__rc) : "d" (__nr), "0" (__p1), "d" (__p2),
79 			"d" (__p3) : "memory", "cc");
80 	return __rc;
81 }
82 
83 
84 static inline long kvm_hypercall4(unsigned long nr, unsigned long p1,
85 			       unsigned long p2, unsigned long p3,
86 			       unsigned long p4)
87 {
88 	register unsigned long __nr asm("1") = nr;
89 	register unsigned long __p1 asm("2") = p1;
90 	register unsigned long __p2 asm("3") = p2;
91 	register unsigned long __p3 asm("4") = p3;
92 	register unsigned long __p4 asm("5") = p4;
93 	register long __rc asm("2");
94 
95 	asm volatile ("diag 2,4,0x500\n"
96 		      : "=d" (__rc) : "d" (__nr), "0" (__p1), "d" (__p2),
97 			"d" (__p3), "d" (__p4) : "memory", "cc");
98 	return __rc;
99 }
100 
101 static inline long kvm_hypercall5(unsigned long nr, unsigned long p1,
102 			       unsigned long p2, unsigned long p3,
103 			       unsigned long p4, unsigned long p5)
104 {
105 	register unsigned long __nr asm("1") = nr;
106 	register unsigned long __p1 asm("2") = p1;
107 	register unsigned long __p2 asm("3") = p2;
108 	register unsigned long __p3 asm("4") = p3;
109 	register unsigned long __p4 asm("5") = p4;
110 	register unsigned long __p5 asm("6") = p5;
111 	register long __rc asm("2");
112 
113 	asm volatile ("diag 2,4,0x500\n"
114 		      : "=d" (__rc) : "d" (__nr), "0" (__p1), "d" (__p2),
115 			"d" (__p3), "d" (__p4), "d" (__p5)  : "memory", "cc");
116 	return __rc;
117 }
118 
119 static inline long kvm_hypercall6(unsigned long nr, unsigned long p1,
120 			       unsigned long p2, unsigned long p3,
121 			       unsigned long p4, unsigned long p5,
122 			       unsigned long p6)
123 {
124 	register unsigned long __nr asm("1") = nr;
125 	register unsigned long __p1 asm("2") = p1;
126 	register unsigned long __p2 asm("3") = p2;
127 	register unsigned long __p3 asm("4") = p3;
128 	register unsigned long __p4 asm("5") = p4;
129 	register unsigned long __p5 asm("6") = p5;
130 	register unsigned long __p6 asm("7") = p6;
131 	register long __rc asm("2");
132 
133 	asm volatile ("diag 2,4,0x500\n"
134 		      : "=d" (__rc) : "d" (__nr), "0" (__p1), "d" (__p2),
135 			"d" (__p3), "d" (__p4), "d" (__p5), "d" (__p6)
136 		      : "memory", "cc");
137 	return __rc;
138 }
139 
140 /* kvm on s390 is always paravirtualization enabled */
141 static inline int kvm_para_available(void)
142 {
143 	return 1;
144 }
145 
146 /* No feature bits are currently assigned for kvm on s390 */
147 static inline unsigned int kvm_arch_para_features(void)
148 {
149 	return 0;
150 }
151 
152 static inline bool kvm_check_and_clear_guest_paused(void)
153 {
154 	return false;
155 }
156 
157 #endif /* __S390_KVM_PARA_H */
158