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