]> Pileus Git - ~andy/linux/blob - arch/powerpc/include/asm/kvm_para.h
KVM: PPC: Tell guest about pending interrupts
[~andy/linux] / 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 #include <linux/of.h>
25
26 struct kvm_vcpu_arch_shared {
27         __u64 scratch1;
28         __u64 scratch2;
29         __u64 scratch3;
30         __u64 critical;         /* Guest may not get interrupts if == r1 */
31         __u64 sprg0;
32         __u64 sprg1;
33         __u64 sprg2;
34         __u64 sprg3;
35         __u64 srr0;
36         __u64 srr1;
37         __u64 dar;
38         __u64 msr;
39         __u32 dsisr;
40         __u32 int_pending;      /* Tells the guest if we have an interrupt */
41 };
42
43 #define KVM_SC_MAGIC_R0         0x4b564d21 /* "KVM!" */
44 #define HC_VENDOR_KVM           (42 << 16)
45 #define HC_EV_SUCCESS           0
46 #define HC_EV_UNIMPLEMENTED     12
47
48 #ifdef __KERNEL__
49
50 #ifdef CONFIG_KVM_GUEST
51
52 static inline int kvm_para_available(void)
53 {
54         struct device_node *hyper_node;
55
56         hyper_node = of_find_node_by_path("/hypervisor");
57         if (!hyper_node)
58                 return 0;
59
60         if (!of_device_is_compatible(hyper_node, "linux,kvm"))
61                 return 0;
62
63         return 1;
64 }
65
66 extern unsigned long kvm_hypercall(unsigned long *in,
67                                    unsigned long *out,
68                                    unsigned long nr);
69
70 #else
71
72 static inline int kvm_para_available(void)
73 {
74         return 0;
75 }
76
77 static unsigned long kvm_hypercall(unsigned long *in,
78                                    unsigned long *out,
79                                    unsigned long nr)
80 {
81         return HC_EV_UNIMPLEMENTED;
82 }
83
84 #endif
85
86 static inline long kvm_hypercall0_1(unsigned int nr, unsigned long *r2)
87 {
88         unsigned long in[8];
89         unsigned long out[8];
90         unsigned long r;
91
92         r = kvm_hypercall(in, out, nr | HC_VENDOR_KVM);
93         *r2 = out[0];
94
95         return r;
96 }
97
98 static inline long kvm_hypercall0(unsigned int nr)
99 {
100         unsigned long in[8];
101         unsigned long out[8];
102
103         return kvm_hypercall(in, out, nr | HC_VENDOR_KVM);
104 }
105
106 static inline long kvm_hypercall1(unsigned int nr, unsigned long p1)
107 {
108         unsigned long in[8];
109         unsigned long out[8];
110
111         in[0] = p1;
112         return kvm_hypercall(in, out, nr | HC_VENDOR_KVM);
113 }
114
115 static inline long kvm_hypercall2(unsigned int nr, unsigned long p1,
116                                   unsigned long p2)
117 {
118         unsigned long in[8];
119         unsigned long out[8];
120
121         in[0] = p1;
122         in[1] = p2;
123         return kvm_hypercall(in, out, nr | HC_VENDOR_KVM);
124 }
125
126 static inline long kvm_hypercall3(unsigned int nr, unsigned long p1,
127                                   unsigned long p2, unsigned long p3)
128 {
129         unsigned long in[8];
130         unsigned long out[8];
131
132         in[0] = p1;
133         in[1] = p2;
134         in[2] = p3;
135         return kvm_hypercall(in, out, nr | HC_VENDOR_KVM);
136 }
137
138 static inline long kvm_hypercall4(unsigned int nr, unsigned long p1,
139                                   unsigned long p2, unsigned long p3,
140                                   unsigned long p4)
141 {
142         unsigned long in[8];
143         unsigned long out[8];
144
145         in[0] = p1;
146         in[1] = p2;
147         in[2] = p3;
148         in[3] = p4;
149         return kvm_hypercall(in, out, nr | HC_VENDOR_KVM);
150 }
151
152
153 static inline unsigned int kvm_arch_para_features(void)
154 {
155         unsigned long r;
156
157         if (!kvm_para_available())
158                 return 0;
159
160         if(kvm_hypercall0_1(KVM_HC_FEATURES, &r))
161                 return 0;
162
163         return r;
164 }
165
166 #endif /* __KERNEL__ */
167
168 #endif /* __POWERPC_KVM_PARA_H__ */