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