]> git.kernelconcepts.de Git - karo-tx-linux.git/blob - arch/powerpc/include/asm/kvm_para.h
KVM: ia64: remove unused variable in kvm_release_vm_pages()
[karo-tx-linux.git] / arch / powerpc / include / asm / kvm_para.h
1 /*
2  * This program is free software; you can redistribute it and/or modify
3  * it under the terms of the GNU General Public License, version 2, as
4  * published by the Free Software Foundation.
5  *
6  * This program is distributed in the hope that it will be useful,
7  * but WITHOUT ANY WARRANTY; without even the implied warranty of
8  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
9  * GNU General Public License for more details.
10  *
11  * You should have received a copy of the GNU General Public License
12  * along with this program; if not, write to the Free Software
13  * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
14  *
15  * Copyright IBM Corp. 2008
16  *
17  * Authors: Hollis Blanchard <hollisb@us.ibm.com>
18  */
19
20 #ifndef __POWERPC_KVM_PARA_H__
21 #define __POWERPC_KVM_PARA_H__
22
23 #include <linux/types.h>
24
25 /*
26  * Additions to this struct must only occur at the end, and should be
27  * accompanied by a KVM_MAGIC_FEAT flag to advertise that they are present
28  * (albeit not necessarily relevant to the current target hardware platform).
29  *
30  * Struct fields are always 32 or 64 bit aligned, depending on them being 32
31  * or 64 bit wide respectively.
32  *
33  * See Documentation/virtual/kvm/ppc-pv.txt
34  */
35 struct kvm_vcpu_arch_shared {
36         __u64 scratch1;
37         __u64 scratch2;
38         __u64 scratch3;
39         __u64 critical;         /* Guest may not get interrupts if == r1 */
40         __u64 sprg0;
41         __u64 sprg1;
42         __u64 sprg2;
43         __u64 sprg3;
44         __u64 srr0;
45         __u64 srr1;
46         __u64 dar;              /* dear on BookE */
47         __u64 msr;
48         __u32 dsisr;
49         __u32 int_pending;      /* Tells the guest if we have an interrupt */
50         __u32 sr[16];
51         __u32 mas0;
52         __u32 mas1;
53         __u64 mas7_3;
54         __u64 mas2;
55         __u32 mas4;
56         __u32 mas6;
57         __u32 esr;
58         __u32 pir;
59
60         /*
61          * SPRG4-7 are user-readable, so we can only keep these consistent
62          * between the shared area and the real registers when there's an
63          * intervening exit to KVM.  This also applies to SPRG3 on some
64          * chips.
65          *
66          * This suffices for access by guest userspace, since in PR-mode
67          * KVM, an exit must occur when changing the guest's MSR[PR].
68          * If the guest kernel writes to SPRG3-7 via the shared area, it
69          * must also use the shared area for reading while in kernel space.
70          */
71         __u64 sprg4;
72         __u64 sprg5;
73         __u64 sprg6;
74         __u64 sprg7;
75 };
76
77 #define KVM_SC_MAGIC_R0         0x4b564d21 /* "KVM!" */
78
79 #define KVM_HCALL_TOKEN(num)     _EV_HCALL_TOKEN(EV_KVM_VENDOR_ID, num)
80
81 #include <asm/epapr_hcalls.h>
82
83 #define KVM_FEATURE_MAGIC_PAGE  1
84
85 #define KVM_MAGIC_FEAT_SR               (1 << 0)
86
87 /* MASn, ESR, PIR, and high SPRGs */
88 #define KVM_MAGIC_FEAT_MAS0_TO_SPRG7    (1 << 1)
89
90 #ifdef __KERNEL__
91
92 #ifdef CONFIG_KVM_GUEST
93
94 #include <linux/of.h>
95
96 static inline int kvm_para_available(void)
97 {
98         struct device_node *hyper_node;
99
100         hyper_node = of_find_node_by_path("/hypervisor");
101         if (!hyper_node)
102                 return 0;
103
104         if (!of_device_is_compatible(hyper_node, "linux,kvm"))
105                 return 0;
106
107         return 1;
108 }
109
110 extern unsigned long kvm_hypercall(unsigned long *in,
111                                    unsigned long *out,
112                                    unsigned long nr);
113
114 #else
115
116 static inline int kvm_para_available(void)
117 {
118         return 0;
119 }
120
121 static unsigned long kvm_hypercall(unsigned long *in,
122                                    unsigned long *out,
123                                    unsigned long nr)
124 {
125         return EV_UNIMPLEMENTED;
126 }
127
128 #endif
129
130 static inline long kvm_hypercall0_1(unsigned int nr, unsigned long *r2)
131 {
132         unsigned long in[8];
133         unsigned long out[8];
134         unsigned long r;
135
136         r = kvm_hypercall(in, out, KVM_HCALL_TOKEN(nr));
137         *r2 = out[0];
138
139         return r;
140 }
141
142 static inline long kvm_hypercall0(unsigned int nr)
143 {
144         unsigned long in[8];
145         unsigned long out[8];
146
147         return kvm_hypercall(in, out, KVM_HCALL_TOKEN(nr));
148 }
149
150 static inline long kvm_hypercall1(unsigned int nr, unsigned long p1)
151 {
152         unsigned long in[8];
153         unsigned long out[8];
154
155         in[0] = p1;
156         return kvm_hypercall(in, out, KVM_HCALL_TOKEN(nr));
157 }
158
159 static inline long kvm_hypercall2(unsigned int nr, unsigned long p1,
160                                   unsigned long p2)
161 {
162         unsigned long in[8];
163         unsigned long out[8];
164
165         in[0] = p1;
166         in[1] = p2;
167         return kvm_hypercall(in, out, KVM_HCALL_TOKEN(nr));
168 }
169
170 static inline long kvm_hypercall3(unsigned int nr, unsigned long p1,
171                                   unsigned long p2, unsigned long p3)
172 {
173         unsigned long in[8];
174         unsigned long out[8];
175
176         in[0] = p1;
177         in[1] = p2;
178         in[2] = p3;
179         return kvm_hypercall(in, out, KVM_HCALL_TOKEN(nr));
180 }
181
182 static inline long kvm_hypercall4(unsigned int nr, unsigned long p1,
183                                   unsigned long p2, unsigned long p3,
184                                   unsigned long p4)
185 {
186         unsigned long in[8];
187         unsigned long out[8];
188
189         in[0] = p1;
190         in[1] = p2;
191         in[2] = p3;
192         in[3] = p4;
193         return kvm_hypercall(in, out, KVM_HCALL_TOKEN(nr));
194 }
195
196
197 static inline unsigned int kvm_arch_para_features(void)
198 {
199         unsigned long r;
200
201         if (!kvm_para_available())
202                 return 0;
203
204         if(kvm_hypercall0_1(KVM_HC_FEATURES, &r))
205                 return 0;
206
207         return r;
208 }
209
210 static inline bool kvm_check_and_clear_guest_paused(void)
211 {
212         return false;
213 }
214
215 #endif /* __KERNEL__ */
216
217 #endif /* __POWERPC_KVM_PARA_H__ */