xen/trace: add multicall tracing
[deliverable/linux.git] / arch / x86 / include / asm / xen / hypercall.h
CommitLineData
a42089dd
JF
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
05e4d316
PA
33#ifndef _ASM_X86_XEN_HYPERCALL_H
34#define _ASM_X86_XEN_HYPERCALL_H
a42089dd 35
ecbf29cd
JF
36#include <linux/kernel.h>
37#include <linux/spinlock.h>
a42089dd
JF
38#include <linux/errno.h>
39#include <linux/string.h>
ecbf29cd
JF
40#include <linux/types.h>
41
c796f213
JF
42#include <trace/events/xen.h>
43
ecbf29cd
JF
44#include <asm/page.h>
45#include <asm/pgtable.h>
a42089dd
JF
46
47#include <xen/interface/xen.h>
48#include <xen/interface/sched.h>
49#include <xen/interface/physdev.h>
50
e7435902
JF
51/*
52 * The hypercall asms have to meet several constraints:
53 * - Work on 32- and 64-bit.
54 * The two architectures put their arguments in different sets of
55 * registers.
56 *
57 * - Work around asm syntax quirks
58 * It isn't possible to specify one of the rNN registers in a
59 * constraint, so we use explicit register variables to get the
60 * args into the right place.
61 *
62 * - Mark all registers as potentially clobbered
63 * Even unused parameters can be clobbered by the hypervisor, so we
64 * need to make sure gcc knows it.
65 *
66 * - Avoid compiler bugs.
67 * This is the tricky part. Because x86_32 has such a constrained
68 * register set, gcc versions below 4.3 have trouble generating
69 * code when all the arg registers and memory are trashed by the
70 * asm. There are syntactically simpler ways of achieving the
71 * semantics below, but they cause the compiler to crash.
72 *
73 * The only combination I found which works is:
74 * - assign the __argX variables first
75 * - list all actually used parameters as "+r" (__argX)
76 * - clobber the rest
77 *
78 * The result certainly isn't pretty, and it really shows up cpp's
79 * weakness as as macro language. Sorry. (But let's just give thanks
80 * there aren't more than 5 arguments...)
81 */
82
a42089dd
JF
83extern struct { char _entry[32]; } hypercall_page[];
84
e7435902
JF
85#define __HYPERCALL "call hypercall_page+%c[offset]"
86#define __HYPERCALL_ENTRY(x) \
87 [offset] "i" (__HYPERVISOR_##x * sizeof(hypercall_page[0]))
88
89#ifdef CONFIG_X86_32
90#define __HYPERCALL_RETREG "eax"
91#define __HYPERCALL_ARG1REG "ebx"
92#define __HYPERCALL_ARG2REG "ecx"
93#define __HYPERCALL_ARG3REG "edx"
94#define __HYPERCALL_ARG4REG "esi"
95#define __HYPERCALL_ARG5REG "edi"
96#else
97#define __HYPERCALL_RETREG "rax"
98#define __HYPERCALL_ARG1REG "rdi"
99#define __HYPERCALL_ARG2REG "rsi"
100#define __HYPERCALL_ARG3REG "rdx"
101#define __HYPERCALL_ARG4REG "r10"
102#define __HYPERCALL_ARG5REG "r8"
103#endif
104
105#define __HYPERCALL_DECLS \
106 register unsigned long __res asm(__HYPERCALL_RETREG); \
107 register unsigned long __arg1 asm(__HYPERCALL_ARG1REG) = __arg1; \
108 register unsigned long __arg2 asm(__HYPERCALL_ARG2REG) = __arg2; \
109 register unsigned long __arg3 asm(__HYPERCALL_ARG3REG) = __arg3; \
110 register unsigned long __arg4 asm(__HYPERCALL_ARG4REG) = __arg4; \
111 register unsigned long __arg5 asm(__HYPERCALL_ARG5REG) = __arg5;
112
113#define __HYPERCALL_0PARAM "=r" (__res)
114#define __HYPERCALL_1PARAM __HYPERCALL_0PARAM, "+r" (__arg1)
115#define __HYPERCALL_2PARAM __HYPERCALL_1PARAM, "+r" (__arg2)
116#define __HYPERCALL_3PARAM __HYPERCALL_2PARAM, "+r" (__arg3)
117#define __HYPERCALL_4PARAM __HYPERCALL_3PARAM, "+r" (__arg4)
118#define __HYPERCALL_5PARAM __HYPERCALL_4PARAM, "+r" (__arg5)
119
120#define __HYPERCALL_0ARG()
121#define __HYPERCALL_1ARG(a1) \
122 __HYPERCALL_0ARG() __arg1 = (unsigned long)(a1);
123#define __HYPERCALL_2ARG(a1,a2) \
124 __HYPERCALL_1ARG(a1) __arg2 = (unsigned long)(a2);
125#define __HYPERCALL_3ARG(a1,a2,a3) \
126 __HYPERCALL_2ARG(a1,a2) __arg3 = (unsigned long)(a3);
127#define __HYPERCALL_4ARG(a1,a2,a3,a4) \
128 __HYPERCALL_3ARG(a1,a2,a3) __arg4 = (unsigned long)(a4);
129#define __HYPERCALL_5ARG(a1,a2,a3,a4,a5) \
130 __HYPERCALL_4ARG(a1,a2,a3,a4) __arg5 = (unsigned long)(a5);
131
132#define __HYPERCALL_CLOBBER5 "memory"
133#define __HYPERCALL_CLOBBER4 __HYPERCALL_CLOBBER5, __HYPERCALL_ARG5REG
134#define __HYPERCALL_CLOBBER3 __HYPERCALL_CLOBBER4, __HYPERCALL_ARG4REG
135#define __HYPERCALL_CLOBBER2 __HYPERCALL_CLOBBER3, __HYPERCALL_ARG3REG
136#define __HYPERCALL_CLOBBER1 __HYPERCALL_CLOBBER2, __HYPERCALL_ARG2REG
137#define __HYPERCALL_CLOBBER0 __HYPERCALL_CLOBBER1, __HYPERCALL_ARG1REG
138
a42089dd
JF
139#define _hypercall0(type, name) \
140({ \
e7435902
JF
141 __HYPERCALL_DECLS; \
142 __HYPERCALL_0ARG(); \
143 asm volatile (__HYPERCALL \
144 : __HYPERCALL_0PARAM \
145 : __HYPERCALL_ENTRY(name) \
146 : __HYPERCALL_CLOBBER0); \
a42089dd
JF
147 (type)__res; \
148})
149
150#define _hypercall1(type, name, a1) \
151({ \
e7435902
JF
152 __HYPERCALL_DECLS; \
153 __HYPERCALL_1ARG(a1); \
154 asm volatile (__HYPERCALL \
155 : __HYPERCALL_1PARAM \
156 : __HYPERCALL_ENTRY(name) \
157 : __HYPERCALL_CLOBBER1); \
a42089dd
JF
158 (type)__res; \
159})
160
161#define _hypercall2(type, name, a1, a2) \
162({ \
e7435902
JF
163 __HYPERCALL_DECLS; \
164 __HYPERCALL_2ARG(a1, a2); \
165 asm volatile (__HYPERCALL \
166 : __HYPERCALL_2PARAM \
167 : __HYPERCALL_ENTRY(name) \
168 : __HYPERCALL_CLOBBER2); \
a42089dd
JF
169 (type)__res; \
170})
171
172#define _hypercall3(type, name, a1, a2, a3) \
173({ \
e7435902
JF
174 __HYPERCALL_DECLS; \
175 __HYPERCALL_3ARG(a1, a2, a3); \
176 asm volatile (__HYPERCALL \
177 : __HYPERCALL_3PARAM \
178 : __HYPERCALL_ENTRY(name) \
179 : __HYPERCALL_CLOBBER3); \
a42089dd
JF
180 (type)__res; \
181})
182
183#define _hypercall4(type, name, a1, a2, a3, a4) \
184({ \
e7435902
JF
185 __HYPERCALL_DECLS; \
186 __HYPERCALL_4ARG(a1, a2, a3, a4); \
187 asm volatile (__HYPERCALL \
188 : __HYPERCALL_4PARAM \
189 : __HYPERCALL_ENTRY(name) \
190 : __HYPERCALL_CLOBBER4); \
a42089dd
JF
191 (type)__res; \
192})
193
194#define _hypercall5(type, name, a1, a2, a3, a4, a5) \
195({ \
e7435902
JF
196 __HYPERCALL_DECLS; \
197 __HYPERCALL_5ARG(a1, a2, a3, a4, a5); \
198 asm volatile (__HYPERCALL \
199 : __HYPERCALL_5PARAM \
200 : __HYPERCALL_ENTRY(name) \
201 : __HYPERCALL_CLOBBER5); \
a42089dd
JF
202 (type)__res; \
203})
204
1246ae0b
JF
205static inline long
206privcmd_call(unsigned call,
207 unsigned long a1, unsigned long a2,
208 unsigned long a3, unsigned long a4,
209 unsigned long a5)
210{
211 __HYPERCALL_DECLS;
212 __HYPERCALL_5ARG(a1, a2, a3, a4, a5);
213
214 asm volatile("call *%[call]"
215 : __HYPERCALL_5PARAM
216 : [call] "a" (&hypercall_page[call])
217 : __HYPERCALL_CLOBBER5);
218
219 return (long)__res;
220}
221
a42089dd
JF
222static inline int
223HYPERVISOR_set_trap_table(struct trap_info *table)
224{
225 return _hypercall1(int, set_trap_table, table);
226}
227
228static inline int
229HYPERVISOR_mmu_update(struct mmu_update *req, int count,
230 int *success_count, domid_t domid)
231{
232 return _hypercall4(int, mmu_update, req, count, success_count, domid);
233}
234
235static inline int
236HYPERVISOR_mmuext_op(struct mmuext_op *op, int count,
237 int *success_count, domid_t domid)
238{
239 return _hypercall4(int, mmuext_op, op, count, success_count, domid);
240}
241
242static inline int
243HYPERVISOR_set_gdt(unsigned long *frame_list, int entries)
244{
245 return _hypercall2(int, set_gdt, frame_list, entries);
246}
247
248static inline int
249HYPERVISOR_stack_switch(unsigned long ss, unsigned long esp)
250{
251 return _hypercall2(int, stack_switch, ss, esp);
252}
253
88459d4c 254#ifdef CONFIG_X86_32
a42089dd
JF
255static inline int
256HYPERVISOR_set_callbacks(unsigned long event_selector,
257 unsigned long event_address,
258 unsigned long failsafe_selector,
259 unsigned long failsafe_address)
260{
261 return _hypercall4(int, set_callbacks,
262 event_selector, event_address,
263 failsafe_selector, failsafe_address);
264}
88459d4c
JF
265#else /* CONFIG_X86_64 */
266static inline int
267HYPERVISOR_set_callbacks(unsigned long event_address,
268 unsigned long failsafe_address,
269 unsigned long syscall_address)
270{
271 return _hypercall3(int, set_callbacks,
272 event_address, failsafe_address,
273 syscall_address);
274}
275#endif /* CONFIG_X86_{32,64} */
a42089dd 276
aa380c82
JF
277static inline int
278HYPERVISOR_callback_op(int cmd, void *arg)
279{
280 return _hypercall2(int, callback_op, cmd, arg);
281}
282
a42089dd
JF
283static inline int
284HYPERVISOR_fpu_taskswitch(int set)
285{
286 return _hypercall1(int, fpu_taskswitch, set);
287}
288
289static inline int
349c709f 290HYPERVISOR_sched_op(int cmd, void *arg)
a42089dd 291{
a8b74583 292 return _hypercall2(int, sched_op, cmd, arg);
a42089dd
JF
293}
294
295static inline long
296HYPERVISOR_set_timer_op(u64 timeout)
297{
298 unsigned long timeout_hi = (unsigned long)(timeout>>32);
299 unsigned long timeout_lo = (unsigned long)timeout;
300 return _hypercall2(long, set_timer_op, timeout_lo, timeout_hi);
301}
302
303static inline int
304HYPERVISOR_set_debugreg(int reg, unsigned long value)
305{
306 return _hypercall2(int, set_debugreg, reg, value);
307}
308
309static inline unsigned long
310HYPERVISOR_get_debugreg(int reg)
311{
312 return _hypercall1(unsigned long, get_debugreg, reg);
313}
314
315static inline int
316HYPERVISOR_update_descriptor(u64 ma, u64 desc)
317{
6a5c05f0
JB
318 if (sizeof(u64) == sizeof(long))
319 return _hypercall2(int, update_descriptor, ma, desc);
a42089dd
JF
320 return _hypercall4(int, update_descriptor, ma, ma>>32, desc, desc>>32);
321}
322
323static inline int
324HYPERVISOR_memory_op(unsigned int cmd, void *arg)
325{
326 return _hypercall2(int, memory_op, cmd, arg);
327}
328
329static inline int
330HYPERVISOR_multicall(void *call_list, int nr_calls)
331{
332 return _hypercall2(int, multicall, call_list, nr_calls);
333}
334
335static inline int
336HYPERVISOR_update_va_mapping(unsigned long va, pte_t new_val,
337 unsigned long flags)
338{
ca15f20f
JF
339 if (sizeof(new_val) == sizeof(long))
340 return _hypercall3(int, update_va_mapping, va,
341 new_val.pte, flags);
342 else
343 return _hypercall4(int, update_va_mapping, va,
344 new_val.pte, new_val.pte >> 32, flags);
a42089dd
JF
345}
346
347static inline int
348HYPERVISOR_event_channel_op(int cmd, void *arg)
349{
350 int rc = _hypercall2(int, event_channel_op, cmd, arg);
351 if (unlikely(rc == -ENOSYS)) {
352 struct evtchn_op op;
353 op.cmd = cmd;
354 memcpy(&op.u, arg, sizeof(op.u));
355 rc = _hypercall1(int, event_channel_op_compat, &op);
356 memcpy(arg, &op.u, sizeof(op.u));
357 }
358 return rc;
359}
360
361static inline int
362HYPERVISOR_xen_version(int cmd, void *arg)
363{
364 return _hypercall2(int, xen_version, cmd, arg);
365}
366
367static inline int
368HYPERVISOR_console_io(int cmd, int count, char *str)
369{
370 return _hypercall3(int, console_io, cmd, count, str);
371}
372
373static inline int
374HYPERVISOR_physdev_op(int cmd, void *arg)
375{
376 int rc = _hypercall2(int, physdev_op, cmd, arg);
377 if (unlikely(rc == -ENOSYS)) {
378 struct physdev_op op;
379 op.cmd = cmd;
380 memcpy(&op.u, arg, sizeof(op.u));
381 rc = _hypercall1(int, physdev_op_compat, &op);
382 memcpy(arg, &op.u, sizeof(op.u));
383 }
384 return rc;
385}
386
387static inline int
388HYPERVISOR_grant_table_op(unsigned int cmd, void *uop, unsigned int count)
389{
390 return _hypercall3(int, grant_table_op, cmd, uop, count);
391}
392
393static inline int
394HYPERVISOR_update_va_mapping_otherdomain(unsigned long va, pte_t new_val,
395 unsigned long flags, domid_t domid)
396{
ca15f20f
JF
397 if (sizeof(new_val) == sizeof(long))
398 return _hypercall4(int, update_va_mapping_otherdomain, va,
399 new_val.pte, flags, domid);
400 else
401 return _hypercall5(int, update_va_mapping_otherdomain, va,
402 new_val.pte, new_val.pte >> 32,
403 flags, domid);
a42089dd
JF
404}
405
406static inline int
407HYPERVISOR_vm_assist(unsigned int cmd, unsigned int type)
408{
409 return _hypercall2(int, vm_assist, cmd, type);
410}
411
412static inline int
413HYPERVISOR_vcpu_op(int cmd, int vcpuid, void *extra_args)
414{
415 return _hypercall3(int, vcpu_op, cmd, vcpuid, extra_args);
416}
417
45eb0d88
EH
418#ifdef CONFIG_X86_64
419static inline int
420HYPERVISOR_set_segment_base(int reg, unsigned long value)
421{
422 return _hypercall2(int, set_segment_base, reg, value);
423}
424#endif
425
a42089dd 426static inline int
8e15597f 427HYPERVISOR_suspend(unsigned long start_info_mfn)
a42089dd 428{
8e15597f
IC
429 struct sched_shutdown r = { .reason = SHUTDOWN_suspend };
430
431 /*
432 * For a PV guest the tools require that the start_info mfn be
433 * present in rdx/edx when the hypercall is made. Per the
434 * hypercall calling convention this is the third hypercall
435 * argument, which is start_info_mfn here.
436 */
a8b74583 437 return _hypercall3(int, sched_op, SCHEDOP_shutdown, &r, start_info_mfn);
a42089dd
JF
438}
439
440static inline int
441HYPERVISOR_nmi_op(unsigned long op, unsigned long arg)
442{
443 return _hypercall2(int, nmi_op, op, arg);
444}
445
18f19aa6
JF
446static inline unsigned long __must_check
447HYPERVISOR_hvm_op(int op, void *arg)
448{
449 return _hypercall2(unsigned long, hvm_op, op, arg);
450}
451
5bc20fc5
DM
452static inline int
453HYPERVISOR_tmem_op(
454 struct tmem_op *op)
455{
456 return _hypercall1(int, tmem_op, op);
457}
458
7b1333aa
JF
459static inline void
460MULTI_fpu_taskswitch(struct multicall_entry *mcl, int set)
461{
462 mcl->op = __HYPERVISOR_fpu_taskswitch;
463 mcl->args[0] = set;
c796f213
JF
464
465 trace_xen_mc_entry(mcl, 1);
7b1333aa
JF
466}
467
a42089dd
JF
468static inline void
469MULTI_update_va_mapping(struct multicall_entry *mcl, unsigned long va,
470 pte_t new_val, unsigned long flags)
471{
472 mcl->op = __HYPERVISOR_update_va_mapping;
473 mcl->args[0] = va;
ca15f20f
JF
474 if (sizeof(new_val) == sizeof(long)) {
475 mcl->args[1] = new_val.pte;
476 mcl->args[2] = flags;
477 } else {
478 mcl->args[1] = new_val.pte;
479 mcl->args[2] = new_val.pte >> 32;
480 mcl->args[3] = flags;
481 }
c796f213
JF
482
483 trace_xen_mc_entry(mcl, sizeof(new_val) == sizeof(long) ? 3 : 4);
a42089dd
JF
484}
485
486static inline void
487MULTI_grant_table_op(struct multicall_entry *mcl, unsigned int cmd,
488 void *uop, unsigned int count)
489{
490 mcl->op = __HYPERVISOR_grant_table_op;
491 mcl->args[0] = cmd;
492 mcl->args[1] = (unsigned long)uop;
493 mcl->args[2] = count;
c796f213
JF
494
495 trace_xen_mc_entry(mcl, 3);
a42089dd
JF
496}
497
498static inline void
499MULTI_update_va_mapping_otherdomain(struct multicall_entry *mcl, unsigned long va,
500 pte_t new_val, unsigned long flags,
501 domid_t domid)
502{
503 mcl->op = __HYPERVISOR_update_va_mapping_otherdomain;
504 mcl->args[0] = va;
ca15f20f
JF
505 if (sizeof(new_val) == sizeof(long)) {
506 mcl->args[1] = new_val.pte;
507 mcl->args[2] = flags;
508 mcl->args[3] = domid;
509 } else {
510 mcl->args[1] = new_val.pte;
511 mcl->args[2] = new_val.pte >> 32;
512 mcl->args[3] = flags;
513 mcl->args[4] = domid;
514 }
c796f213
JF
515
516 trace_xen_mc_entry(mcl, sizeof(new_val) == sizeof(long) ? 4 : 5);
a42089dd
JF
517}
518
519static inline void
520MULTI_update_descriptor(struct multicall_entry *mcl, u64 maddr,
521 struct desc_struct desc)
522{
523 mcl->op = __HYPERVISOR_update_descriptor;
c05f1cfa
JF
524 if (sizeof(maddr) == sizeof(long)) {
525 mcl->args[0] = maddr;
526 mcl->args[1] = *(unsigned long *)&desc;
527 } else {
528 mcl->args[0] = maddr;
529 mcl->args[1] = maddr >> 32;
530 mcl->args[2] = desc.a;
531 mcl->args[3] = desc.b;
532 }
c796f213
JF
533
534 trace_xen_mc_entry(mcl, sizeof(maddr) == sizeof(long) ? 2 : 4);
a42089dd
JF
535}
536
537static inline void
538MULTI_memory_op(struct multicall_entry *mcl, unsigned int cmd, void *arg)
539{
540 mcl->op = __HYPERVISOR_memory_op;
541 mcl->args[0] = cmd;
542 mcl->args[1] = (unsigned long)arg;
c796f213
JF
543
544 trace_xen_mc_entry(mcl, 2);
a42089dd
JF
545}
546
547static inline void
548MULTI_mmu_update(struct multicall_entry *mcl, struct mmu_update *req,
549 int count, int *success_count, domid_t domid)
550{
551 mcl->op = __HYPERVISOR_mmu_update;
552 mcl->args[0] = (unsigned long)req;
553 mcl->args[1] = count;
554 mcl->args[2] = (unsigned long)success_count;
555 mcl->args[3] = domid;
c796f213
JF
556
557 trace_xen_mc_entry(mcl, 4);
a42089dd
JF
558}
559
560static inline void
561MULTI_mmuext_op(struct multicall_entry *mcl, struct mmuext_op *op, int count,
562 int *success_count, domid_t domid)
563{
564 mcl->op = __HYPERVISOR_mmuext_op;
565 mcl->args[0] = (unsigned long)op;
566 mcl->args[1] = count;
567 mcl->args[2] = (unsigned long)success_count;
568 mcl->args[3] = domid;
c796f213
JF
569
570 trace_xen_mc_entry(mcl, 4);
a42089dd 571}
5ead97c8
JF
572
573static inline void
574MULTI_set_gdt(struct multicall_entry *mcl, unsigned long *frames, int entries)
575{
576 mcl->op = __HYPERVISOR_set_gdt;
577 mcl->args[0] = (unsigned long)frames;
578 mcl->args[1] = entries;
c796f213
JF
579
580 trace_xen_mc_entry(mcl, 2);
5ead97c8
JF
581}
582
583static inline void
584MULTI_stack_switch(struct multicall_entry *mcl,
585 unsigned long ss, unsigned long esp)
586{
587 mcl->op = __HYPERVISOR_stack_switch;
588 mcl->args[0] = ss;
589 mcl->args[1] = esp;
c796f213
JF
590
591 trace_xen_mc_entry(mcl, 2);
5ead97c8
JF
592}
593
05e4d316 594#endif /* _ASM_X86_XEN_HYPERCALL_H */
This page took 0.529986 seconds and 5 git commands to generate.