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.
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.
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.
15 * Copyright IBM Corp. 2008
17 * Authors: Hollis Blanchard <hollisb@us.ibm.com>
20 #ifndef __POWERPC_KVM_PARA_H__
21 #define __POWERPC_KVM_PARA_H__
23 #include <linux/types.h>
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).
30 * Struct fields are always 32 or 64 bit aligned, depending on them being 32
31 * or 64 bit wide respectively.
33 * See Documentation/virtual/kvm/ppc-pv.txt
35 struct kvm_vcpu_arch_shared {
39 __u64 critical; /* Guest may not get interrupts if == r1 */
46 __u64 dar; /* dear on BookE */
49 __u32 int_pending; /* Tells the guest if we have an interrupt */
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
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.
77 #define KVM_SC_MAGIC_R0 0x4b564d21 /* "KVM!" */
78 #define HC_VENDOR_KVM (42 << 16)
79 #define HC_EV_SUCCESS 0
80 #define HC_EV_UNIMPLEMENTED 12
82 #define KVM_FEATURE_MAGIC_PAGE 1
84 #define KVM_MAGIC_FEAT_SR (1 << 0)
86 /* MASn, ESR, PIR, and high SPRGs */
87 #define KVM_MAGIC_FEAT_MAS0_TO_SPRG7 (1 << 1)
91 #ifdef CONFIG_KVM_GUEST
95 static inline int kvm_para_available(void)
97 struct device_node *hyper_node;
99 hyper_node = of_find_node_by_path("/hypervisor");
103 if (!of_device_is_compatible(hyper_node, "linux,kvm"))
109 extern unsigned long kvm_hypercall(unsigned long *in,
115 static inline int kvm_para_available(void)
120 static unsigned long kvm_hypercall(unsigned long *in,
124 return HC_EV_UNIMPLEMENTED;
129 static inline long kvm_hypercall0_1(unsigned int nr, unsigned long *r2)
132 unsigned long out[8];
135 r = kvm_hypercall(in, out, nr | HC_VENDOR_KVM);
141 static inline long kvm_hypercall0(unsigned int nr)
144 unsigned long out[8];
146 return kvm_hypercall(in, out, nr | HC_VENDOR_KVM);
149 static inline long kvm_hypercall1(unsigned int nr, unsigned long p1)
152 unsigned long out[8];
155 return kvm_hypercall(in, out, nr | HC_VENDOR_KVM);
158 static inline long kvm_hypercall2(unsigned int nr, unsigned long p1,
162 unsigned long out[8];
166 return kvm_hypercall(in, out, nr | HC_VENDOR_KVM);
169 static inline long kvm_hypercall3(unsigned int nr, unsigned long p1,
170 unsigned long p2, unsigned long p3)
173 unsigned long out[8];
178 return kvm_hypercall(in, out, nr | HC_VENDOR_KVM);
181 static inline long kvm_hypercall4(unsigned int nr, unsigned long p1,
182 unsigned long p2, unsigned long p3,
186 unsigned long out[8];
192 return kvm_hypercall(in, out, nr | HC_VENDOR_KVM);
196 static inline unsigned int kvm_arch_para_features(void)
200 if (!kvm_para_available())
203 if(kvm_hypercall0_1(KVM_HC_FEATURES, &r))
209 #endif /* __KERNEL__ */
211 #endif /* __POWERPC_KVM_PARA_H__ */