1 | /****************************************************************************** |
---|
2 | * hypercall.h |
---|
3 | * |
---|
4 | * Linux-specific hypervisor handling. |
---|
5 | * |
---|
6 | * Copyright (c) 2002-2004, K A Fraser |
---|
7 | * |
---|
8 | * This program is free software; you can redistribute it and/or |
---|
9 | * modify it under the terms of the GNU General Public License version 2 |
---|
10 | * as published by the Free Software Foundation; or, when distributed |
---|
11 | * separately from the Linux kernel or incorporated into other |
---|
12 | * software packages, subject to the following license: |
---|
13 | * |
---|
14 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
---|
15 | * of this source file (the "Software"), to deal in the Software without |
---|
16 | * restriction, including without limitation the rights to use, copy, modify, |
---|
17 | * merge, publish, distribute, sublicense, and/or sell copies of the Software, |
---|
18 | * and to permit persons to whom the Software is furnished to do so, subject to |
---|
19 | * the following conditions: |
---|
20 | * |
---|
21 | * The above copyright notice and this permission notice shall be included in |
---|
22 | * all copies or substantial portions of the Software. |
---|
23 | * |
---|
24 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
---|
25 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
---|
26 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
---|
27 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
---|
28 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
---|
29 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS |
---|
30 | * IN THE SOFTWARE. |
---|
31 | */ |
---|
32 | |
---|
33 | #ifndef __HYPERCALL_H__ |
---|
34 | #define __HYPERCALL_H__ |
---|
35 | |
---|
36 | #include <linux/string.h> /* memcpy() */ |
---|
37 | |
---|
38 | #ifndef __HYPERVISOR_H__ |
---|
39 | # error "please don't include this file directly" |
---|
40 | #endif |
---|
41 | |
---|
42 | #define __STR(x) #x |
---|
43 | #define STR(x) __STR(x) |
---|
44 | |
---|
45 | #ifdef CONFIG_XEN |
---|
46 | #define HYPERCALL_STR(name) \ |
---|
47 | "call hypercall_page + ("STR(__HYPERVISOR_##name)" * 32)" |
---|
48 | #else |
---|
49 | #define HYPERCALL_STR(name) \ |
---|
50 | "mov hypercall_stubs,%%eax; " \ |
---|
51 | "add $("STR(__HYPERVISOR_##name)" * 32),%%eax; " \ |
---|
52 | "call *%%eax" |
---|
53 | #endif |
---|
54 | |
---|
55 | #define _hypercall0(type, name) \ |
---|
56 | ({ \ |
---|
57 | long __res; \ |
---|
58 | asm volatile ( \ |
---|
59 | HYPERCALL_STR(name) \ |
---|
60 | : "=a" (__res) \ |
---|
61 | : \ |
---|
62 | : "memory" ); \ |
---|
63 | (type)__res; \ |
---|
64 | }) |
---|
65 | |
---|
66 | #define _hypercall1(type, name, a1) \ |
---|
67 | ({ \ |
---|
68 | long __res, __ign1; \ |
---|
69 | asm volatile ( \ |
---|
70 | HYPERCALL_STR(name) \ |
---|
71 | : "=a" (__res), "=b" (__ign1) \ |
---|
72 | : "1" ((long)(a1)) \ |
---|
73 | : "memory" ); \ |
---|
74 | (type)__res; \ |
---|
75 | }) |
---|
76 | |
---|
77 | #define _hypercall2(type, name, a1, a2) \ |
---|
78 | ({ \ |
---|
79 | long __res, __ign1, __ign2; \ |
---|
80 | asm volatile ( \ |
---|
81 | HYPERCALL_STR(name) \ |
---|
82 | : "=a" (__res), "=b" (__ign1), "=c" (__ign2) \ |
---|
83 | : "1" ((long)(a1)), "2" ((long)(a2)) \ |
---|
84 | : "memory" ); \ |
---|
85 | (type)__res; \ |
---|
86 | }) |
---|
87 | |
---|
88 | #define _hypercall3(type, name, a1, a2, a3) \ |
---|
89 | ({ \ |
---|
90 | long __res, __ign1, __ign2, __ign3; \ |
---|
91 | asm volatile ( \ |
---|
92 | HYPERCALL_STR(name) \ |
---|
93 | : "=a" (__res), "=b" (__ign1), "=c" (__ign2), \ |
---|
94 | "=d" (__ign3) \ |
---|
95 | : "1" ((long)(a1)), "2" ((long)(a2)), \ |
---|
96 | "3" ((long)(a3)) \ |
---|
97 | : "memory" ); \ |
---|
98 | (type)__res; \ |
---|
99 | }) |
---|
100 | |
---|
101 | #define _hypercall4(type, name, a1, a2, a3, a4) \ |
---|
102 | ({ \ |
---|
103 | long __res, __ign1, __ign2, __ign3, __ign4; \ |
---|
104 | asm volatile ( \ |
---|
105 | HYPERCALL_STR(name) \ |
---|
106 | : "=a" (__res), "=b" (__ign1), "=c" (__ign2), \ |
---|
107 | "=d" (__ign3), "=S" (__ign4) \ |
---|
108 | : "1" ((long)(a1)), "2" ((long)(a2)), \ |
---|
109 | "3" ((long)(a3)), "4" ((long)(a4)) \ |
---|
110 | : "memory" ); \ |
---|
111 | (type)__res; \ |
---|
112 | }) |
---|
113 | |
---|
114 | #define _hypercall5(type, name, a1, a2, a3, a4, a5) \ |
---|
115 | ({ \ |
---|
116 | long __res, __ign1, __ign2, __ign3, __ign4, __ign5; \ |
---|
117 | asm volatile ( \ |
---|
118 | HYPERCALL_STR(name) \ |
---|
119 | : "=a" (__res), "=b" (__ign1), "=c" (__ign2), \ |
---|
120 | "=d" (__ign3), "=S" (__ign4), "=D" (__ign5) \ |
---|
121 | : "1" ((long)(a1)), "2" ((long)(a2)), \ |
---|
122 | "3" ((long)(a3)), "4" ((long)(a4)), \ |
---|
123 | "5" ((long)(a5)) \ |
---|
124 | : "memory" ); \ |
---|
125 | (type)__res; \ |
---|
126 | }) |
---|
127 | |
---|
128 | static inline int |
---|
129 | HYPERVISOR_set_trap_table( |
---|
130 | trap_info_t *table) |
---|
131 | { |
---|
132 | return _hypercall1(int, set_trap_table, table); |
---|
133 | } |
---|
134 | |
---|
135 | static inline int |
---|
136 | HYPERVISOR_mmu_update( |
---|
137 | mmu_update_t *req, int count, int *success_count, domid_t domid) |
---|
138 | { |
---|
139 | return _hypercall4(int, mmu_update, req, count, success_count, domid); |
---|
140 | } |
---|
141 | |
---|
142 | static inline int |
---|
143 | HYPERVISOR_mmuext_op( |
---|
144 | struct mmuext_op *op, int count, int *success_count, domid_t domid) |
---|
145 | { |
---|
146 | return _hypercall4(int, mmuext_op, op, count, success_count, domid); |
---|
147 | } |
---|
148 | |
---|
149 | static inline int |
---|
150 | HYPERVISOR_set_gdt( |
---|
151 | unsigned long *frame_list, int entries) |
---|
152 | { |
---|
153 | return _hypercall2(int, set_gdt, frame_list, entries); |
---|
154 | } |
---|
155 | |
---|
156 | static inline int |
---|
157 | HYPERVISOR_stack_switch( |
---|
158 | unsigned long ss, unsigned long esp) |
---|
159 | { |
---|
160 | return _hypercall2(int, stack_switch, ss, esp); |
---|
161 | } |
---|
162 | |
---|
163 | static inline int |
---|
164 | HYPERVISOR_set_callbacks( |
---|
165 | unsigned long event_selector, unsigned long event_address, |
---|
166 | unsigned long failsafe_selector, unsigned long failsafe_address) |
---|
167 | { |
---|
168 | return _hypercall4(int, set_callbacks, |
---|
169 | event_selector, event_address, |
---|
170 | failsafe_selector, failsafe_address); |
---|
171 | } |
---|
172 | |
---|
173 | static inline int |
---|
174 | HYPERVISOR_fpu_taskswitch( |
---|
175 | int set) |
---|
176 | { |
---|
177 | return _hypercall1(int, fpu_taskswitch, set); |
---|
178 | } |
---|
179 | |
---|
180 | static inline int |
---|
181 | HYPERVISOR_sched_op_compat( |
---|
182 | int cmd, unsigned long arg) |
---|
183 | { |
---|
184 | return _hypercall2(int, sched_op_compat, cmd, arg); |
---|
185 | } |
---|
186 | |
---|
187 | static inline int |
---|
188 | HYPERVISOR_sched_op( |
---|
189 | int cmd, void *arg) |
---|
190 | { |
---|
191 | return _hypercall2(int, sched_op, cmd, arg); |
---|
192 | } |
---|
193 | |
---|
194 | static inline long |
---|
195 | HYPERVISOR_set_timer_op( |
---|
196 | u64 timeout) |
---|
197 | { |
---|
198 | unsigned long timeout_hi = (unsigned long)(timeout>>32); |
---|
199 | unsigned long timeout_lo = (unsigned long)timeout; |
---|
200 | return _hypercall2(long, set_timer_op, timeout_lo, timeout_hi); |
---|
201 | } |
---|
202 | |
---|
203 | static inline int |
---|
204 | HYPERVISOR_platform_op( |
---|
205 | struct xen_platform_op *platform_op) |
---|
206 | { |
---|
207 | platform_op->interface_version = XENPF_INTERFACE_VERSION; |
---|
208 | return _hypercall1(int, platform_op, platform_op); |
---|
209 | } |
---|
210 | |
---|
211 | static inline int |
---|
212 | HYPERVISOR_set_debugreg( |
---|
213 | int reg, unsigned long value) |
---|
214 | { |
---|
215 | return _hypercall2(int, set_debugreg, reg, value); |
---|
216 | } |
---|
217 | |
---|
218 | static inline unsigned long |
---|
219 | HYPERVISOR_get_debugreg( |
---|
220 | int reg) |
---|
221 | { |
---|
222 | return _hypercall1(unsigned long, get_debugreg, reg); |
---|
223 | } |
---|
224 | |
---|
225 | static inline int |
---|
226 | HYPERVISOR_update_descriptor( |
---|
227 | u64 ma, u64 desc) |
---|
228 | { |
---|
229 | return _hypercall4(int, update_descriptor, ma, ma>>32, desc, desc>>32); |
---|
230 | } |
---|
231 | |
---|
232 | static inline int |
---|
233 | HYPERVISOR_memory_op( |
---|
234 | unsigned int cmd, void *arg) |
---|
235 | { |
---|
236 | return _hypercall2(int, memory_op, cmd, arg); |
---|
237 | } |
---|
238 | |
---|
239 | static inline int |
---|
240 | HYPERVISOR_multicall( |
---|
241 | multicall_entry_t *call_list, int nr_calls) |
---|
242 | { |
---|
243 | return _hypercall2(int, multicall, call_list, nr_calls); |
---|
244 | } |
---|
245 | |
---|
246 | static inline int |
---|
247 | HYPERVISOR_update_va_mapping( |
---|
248 | unsigned long va, pte_t new_val, unsigned long flags) |
---|
249 | { |
---|
250 | unsigned long pte_hi = 0; |
---|
251 | #ifdef CONFIG_X86_PAE |
---|
252 | pte_hi = new_val.pte_high; |
---|
253 | #endif |
---|
254 | return _hypercall4(int, update_va_mapping, va, |
---|
255 | new_val.pte_low, pte_hi, flags); |
---|
256 | } |
---|
257 | |
---|
258 | static inline int |
---|
259 | HYPERVISOR_event_channel_op( |
---|
260 | int cmd, void *arg) |
---|
261 | { |
---|
262 | int rc = _hypercall2(int, event_channel_op, cmd, arg); |
---|
263 | |
---|
264 | #if CONFIG_XEN_COMPAT <= 0x030002 |
---|
265 | if (unlikely(rc == -ENOSYS)) { |
---|
266 | struct evtchn_op op; |
---|
267 | op.cmd = cmd; |
---|
268 | memcpy(&op.u, arg, sizeof(op.u)); |
---|
269 | rc = _hypercall1(int, event_channel_op_compat, &op); |
---|
270 | memcpy(arg, &op.u, sizeof(op.u)); |
---|
271 | } |
---|
272 | #endif |
---|
273 | |
---|
274 | return rc; |
---|
275 | } |
---|
276 | |
---|
277 | static inline int |
---|
278 | HYPERVISOR_acm_op( |
---|
279 | int cmd, void *arg) |
---|
280 | { |
---|
281 | return _hypercall2(int, acm_op, cmd, arg); |
---|
282 | } |
---|
283 | |
---|
284 | static inline int |
---|
285 | HYPERVISOR_xen_version( |
---|
286 | int cmd, void *arg) |
---|
287 | { |
---|
288 | return _hypercall2(int, xen_version, cmd, arg); |
---|
289 | } |
---|
290 | |
---|
291 | static inline int |
---|
292 | HYPERVISOR_console_io( |
---|
293 | int cmd, int count, char *str) |
---|
294 | { |
---|
295 | return _hypercall3(int, console_io, cmd, count, str); |
---|
296 | } |
---|
297 | |
---|
298 | static inline int |
---|
299 | HYPERVISOR_physdev_op( |
---|
300 | int cmd, void *arg) |
---|
301 | { |
---|
302 | int rc = _hypercall2(int, physdev_op, cmd, arg); |
---|
303 | |
---|
304 | #if CONFIG_XEN_COMPAT <= 0x030002 |
---|
305 | if (unlikely(rc == -ENOSYS)) { |
---|
306 | struct physdev_op op; |
---|
307 | op.cmd = cmd; |
---|
308 | memcpy(&op.u, arg, sizeof(op.u)); |
---|
309 | rc = _hypercall1(int, physdev_op_compat, &op); |
---|
310 | memcpy(arg, &op.u, sizeof(op.u)); |
---|
311 | } |
---|
312 | #endif |
---|
313 | |
---|
314 | return rc; |
---|
315 | } |
---|
316 | |
---|
317 | static inline int |
---|
318 | HYPERVISOR_grant_table_op( |
---|
319 | unsigned int cmd, void *uop, unsigned int count) |
---|
320 | { |
---|
321 | return _hypercall3(int, grant_table_op, cmd, uop, count); |
---|
322 | } |
---|
323 | |
---|
324 | static inline int |
---|
325 | HYPERVISOR_update_va_mapping_otherdomain( |
---|
326 | unsigned long va, pte_t new_val, unsigned long flags, domid_t domid) |
---|
327 | { |
---|
328 | unsigned long pte_hi = 0; |
---|
329 | #ifdef CONFIG_X86_PAE |
---|
330 | pte_hi = new_val.pte_high; |
---|
331 | #endif |
---|
332 | return _hypercall5(int, update_va_mapping_otherdomain, va, |
---|
333 | new_val.pte_low, pte_hi, flags, domid); |
---|
334 | } |
---|
335 | |
---|
336 | static inline int |
---|
337 | HYPERVISOR_vm_assist( |
---|
338 | unsigned int cmd, unsigned int type) |
---|
339 | { |
---|
340 | return _hypercall2(int, vm_assist, cmd, type); |
---|
341 | } |
---|
342 | |
---|
343 | static inline int |
---|
344 | HYPERVISOR_vcpu_op( |
---|
345 | int cmd, int vcpuid, void *extra_args) |
---|
346 | { |
---|
347 | return _hypercall3(int, vcpu_op, cmd, vcpuid, extra_args); |
---|
348 | } |
---|
349 | |
---|
350 | static inline int |
---|
351 | HYPERVISOR_suspend( |
---|
352 | unsigned long srec) |
---|
353 | { |
---|
354 | struct sched_shutdown sched_shutdown = { |
---|
355 | .reason = SHUTDOWN_suspend |
---|
356 | }; |
---|
357 | |
---|
358 | int rc = _hypercall3(int, sched_op, SCHEDOP_shutdown, |
---|
359 | &sched_shutdown, srec); |
---|
360 | |
---|
361 | #if CONFIG_XEN_COMPAT <= 0x030002 |
---|
362 | if (rc == -ENOSYS) |
---|
363 | rc = _hypercall3(int, sched_op_compat, SCHEDOP_shutdown, |
---|
364 | SHUTDOWN_suspend, srec); |
---|
365 | #endif |
---|
366 | |
---|
367 | return rc; |
---|
368 | } |
---|
369 | |
---|
370 | static inline int |
---|
371 | HYPERVISOR_nmi_op( |
---|
372 | unsigned long op, void *arg) |
---|
373 | { |
---|
374 | return _hypercall2(int, nmi_op, op, arg); |
---|
375 | } |
---|
376 | |
---|
377 | static inline unsigned long |
---|
378 | HYPERVISOR_hvm_op( |
---|
379 | int op, void *arg) |
---|
380 | { |
---|
381 | return _hypercall2(unsigned long, hvm_op, op, arg); |
---|
382 | } |
---|
383 | |
---|
384 | static inline int |
---|
385 | HYPERVISOR_callback_op( |
---|
386 | int cmd, void *arg) |
---|
387 | { |
---|
388 | return _hypercall2(int, callback_op, cmd, arg); |
---|
389 | } |
---|
390 | |
---|
391 | static inline int |
---|
392 | HYPERVISOR_xenoprof_op( |
---|
393 | int op, void *arg) |
---|
394 | { |
---|
395 | return _hypercall2(int, xenoprof_op, op, arg); |
---|
396 | } |
---|
397 | |
---|
398 | static inline int |
---|
399 | HYPERVISOR_kexec_op( |
---|
400 | unsigned long op, void *args) |
---|
401 | { |
---|
402 | return _hypercall2(int, kexec_op, op, args); |
---|
403 | } |
---|
404 | |
---|
405 | |
---|
406 | |
---|
407 | #endif /* __HYPERCALL_H__ */ |
---|