Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
kvm_para.h
Go to the documentation of this file.
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 <[email protected]>
18  */
19 #ifndef __POWERPC_KVM_PARA_H__
20 #define __POWERPC_KVM_PARA_H__
21 
22 #include <uapi/asm/kvm_para.h>
23 
24 
25 #ifdef CONFIG_KVM_GUEST
26 
27 #include <linux/of.h>
28 
29 static inline int kvm_para_available(void)
30 {
31  struct device_node *hyper_node;
32 
33  hyper_node = of_find_node_by_path("/hypervisor");
34  if (!hyper_node)
35  return 0;
36 
37  if (!of_device_is_compatible(hyper_node, "linux,kvm"))
38  return 0;
39 
40  return 1;
41 }
42 
43 extern unsigned long kvm_hypercall(unsigned long *in,
44  unsigned long *out,
45  unsigned long nr);
46 
47 #else
48 
49 static inline int kvm_para_available(void)
50 {
51  return 0;
52 }
53 
54 static unsigned long kvm_hypercall(unsigned long *in,
55  unsigned long *out,
56  unsigned long nr)
57 {
58  return HC_EV_UNIMPLEMENTED;
59 }
60 
61 #endif
62 
63 static inline long kvm_hypercall0_1(unsigned int nr, unsigned long *r2)
64 {
65  unsigned long in[8];
66  unsigned long out[8];
67  unsigned long r;
68 
69  r = kvm_hypercall(in, out, nr | HC_VENDOR_KVM);
70  *r2 = out[0];
71 
72  return r;
73 }
74 
75 static inline long kvm_hypercall0(unsigned int nr)
76 {
77  unsigned long in[8];
78  unsigned long out[8];
79 
80  return kvm_hypercall(in, out, nr | HC_VENDOR_KVM);
81 }
82 
83 static inline long kvm_hypercall1(unsigned int nr, unsigned long p1)
84 {
85  unsigned long in[8];
86  unsigned long out[8];
87 
88  in[0] = p1;
89  return kvm_hypercall(in, out, nr | HC_VENDOR_KVM);
90 }
91 
92 static inline long kvm_hypercall2(unsigned int nr, unsigned long p1,
93  unsigned long p2)
94 {
95  unsigned long in[8];
96  unsigned long out[8];
97 
98  in[0] = p1;
99  in[1] = p2;
100  return kvm_hypercall(in, out, nr | HC_VENDOR_KVM);
101 }
102 
103 static inline long kvm_hypercall3(unsigned int nr, unsigned long p1,
104  unsigned long p2, unsigned long p3)
105 {
106  unsigned long in[8];
107  unsigned long out[8];
108 
109  in[0] = p1;
110  in[1] = p2;
111  in[2] = p3;
112  return kvm_hypercall(in, out, nr | HC_VENDOR_KVM);
113 }
114 
115 static inline long kvm_hypercall4(unsigned int nr, unsigned long p1,
116  unsigned long p2, unsigned long p3,
117  unsigned long p4)
118 {
119  unsigned long in[8];
120  unsigned long out[8];
121 
122  in[0] = p1;
123  in[1] = p2;
124  in[2] = p3;
125  in[3] = p4;
126  return kvm_hypercall(in, out, nr | HC_VENDOR_KVM);
127 }
128 
129 
130 static inline unsigned int kvm_arch_para_features(void)
131 {
132  unsigned long r;
133 
134  if (!kvm_para_available())
135  return 0;
136 
137  if(kvm_hypercall0_1(KVM_HC_FEATURES, &r))
138  return 0;
139 
140  return r;
141 }
142 
143 static inline bool kvm_check_and_clear_guest_paused(void)
144 {
145  return false;
146 }
147 
148 #endif /* __POWERPC_KVM_PARA_H__ */