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