blob: d79fd09109649acfd16e539e6587bda594b9128c [file] [log] [blame]
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -05001/*
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
Alexander Graf96bc4512010-07-29 14:47:42 +020023#include <linux/types.h>
Alexander Graf2a342ed2010-07-29 14:47:48 +020024#include <linux/of.h>
Alexander Graf96bc4512010-07-29 14:47:42 +020025
26struct kvm_vcpu_arch_shared {
Alexander Graffad93fe2010-07-29 14:47:50 +020027 __u64 scratch1;
28 __u64 scratch2;
29 __u64 scratch3;
Alexander Graf5c6cedf2010-07-29 14:47:49 +020030 __u64 critical; /* Guest may not get interrupts if == r1 */
Alexander Grafa73a9592010-07-29 14:47:47 +020031 __u64 sprg0;
32 __u64 sprg1;
33 __u64 sprg2;
34 __u64 sprg3;
Alexander Grafde7906c2010-07-29 14:47:46 +020035 __u64 srr0;
36 __u64 srr1;
Alexander Graf5e030182010-07-29 14:47:45 +020037 __u64 dar;
Alexander Graf666e7252010-07-29 14:47:43 +020038 __u64 msr;
Alexander Grafd562de42010-07-29 14:47:44 +020039 __u32 dsisr;
Alexander Graf90bba352010-07-29 14:47:51 +020040 __u32 int_pending; /* Tells the guest if we have an interrupt */
Alexander Grafdf1bfa22010-08-03 02:29:27 +020041 __u32 sr[16];
Alexander Graf96bc4512010-07-29 14:47:42 +020042};
43
Alexander Graf2a342ed2010-07-29 14:47:48 +020044#define KVM_SC_MAGIC_R0 0x4b564d21 /* "KVM!" */
45#define HC_VENDOR_KVM (42 << 16)
46#define HC_EV_SUCCESS 0
47#define HC_EV_UNIMPLEMENTED 12
48
Alexander Graf5fc87402010-07-29 14:47:55 +020049#define KVM_FEATURE_MAGIC_PAGE 1
50
Alexander Graf7508e162010-08-03 11:32:56 +020051#define KVM_MAGIC_FEAT_SR (1 << 0)
52
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -050053#ifdef __KERNEL__
54
Alexander Graf2a342ed2010-07-29 14:47:48 +020055#ifdef CONFIG_KVM_GUEST
56
57static inline int kvm_para_available(void)
58{
59 struct device_node *hyper_node;
60
61 hyper_node = of_find_node_by_path("/hypervisor");
62 if (!hyper_node)
63 return 0;
64
65 if (!of_device_is_compatible(hyper_node, "linux,kvm"))
66 return 0;
67
68 return 1;
69}
70
71extern unsigned long kvm_hypercall(unsigned long *in,
72 unsigned long *out,
73 unsigned long nr);
74
75#else
76
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -050077static inline int kvm_para_available(void)
78{
79 return 0;
80}
81
Alexander Graf2a342ed2010-07-29 14:47:48 +020082static unsigned long kvm_hypercall(unsigned long *in,
83 unsigned long *out,
84 unsigned long nr)
85{
86 return HC_EV_UNIMPLEMENTED;
87}
88
89#endif
90
91static inline long kvm_hypercall0_1(unsigned int nr, unsigned long *r2)
92{
93 unsigned long in[8];
94 unsigned long out[8];
95 unsigned long r;
96
97 r = kvm_hypercall(in, out, nr | HC_VENDOR_KVM);
98 *r2 = out[0];
99
100 return r;
101}
102
103static inline long kvm_hypercall0(unsigned int nr)
104{
105 unsigned long in[8];
106 unsigned long out[8];
107
108 return kvm_hypercall(in, out, nr | HC_VENDOR_KVM);
109}
110
111static inline long kvm_hypercall1(unsigned int nr, unsigned long p1)
112{
113 unsigned long in[8];
114 unsigned long out[8];
115
116 in[0] = p1;
117 return kvm_hypercall(in, out, nr | HC_VENDOR_KVM);
118}
119
120static inline long kvm_hypercall2(unsigned int nr, unsigned long p1,
121 unsigned long p2)
122{
123 unsigned long in[8];
124 unsigned long out[8];
125
126 in[0] = p1;
127 in[1] = p2;
128 return kvm_hypercall(in, out, nr | HC_VENDOR_KVM);
129}
130
131static inline long kvm_hypercall3(unsigned int nr, unsigned long p1,
132 unsigned long p2, unsigned long p3)
133{
134 unsigned long in[8];
135 unsigned long out[8];
136
137 in[0] = p1;
138 in[1] = p2;
139 in[2] = p3;
140 return kvm_hypercall(in, out, nr | HC_VENDOR_KVM);
141}
142
143static inline long kvm_hypercall4(unsigned int nr, unsigned long p1,
144 unsigned long p2, unsigned long p3,
145 unsigned long p4)
146{
147 unsigned long in[8];
148 unsigned long out[8];
149
150 in[0] = p1;
151 in[1] = p2;
152 in[2] = p3;
153 in[3] = p4;
154 return kvm_hypercall(in, out, nr | HC_VENDOR_KVM);
155}
156
157
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500158static inline unsigned int kvm_arch_para_features(void)
159{
Alexander Graf2a342ed2010-07-29 14:47:48 +0200160 unsigned long r;
161
162 if (!kvm_para_available())
163 return 0;
164
165 if(kvm_hypercall0_1(KVM_HC_FEATURES, &r))
166 return 0;
167
168 return r;
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500169}
170
171#endif /* __KERNEL__ */
172
173#endif /* __POWERPC_KVM_PARA_H__ */