Merge to Fedora kernel-2.6.18-1.2224_FC5 patched with stable patch-2.6.18.1-vs2.0...
[linux-2.6.git] / include / asm-x86_64 / mach-xen / asm / hypercall.h
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_dom0_op(
208         dom0_op_t *dom0_op)
209 {
210         dom0_op->interface_version = DOM0_INTERFACE_VERSION;
211         return _hypercall1(int, dom0_op, dom0_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         void *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         if (unlikely(rc == -ENOSYS)) {
262                 struct evtchn_op op;
263                 op.cmd = cmd;
264                 memcpy(&op.u, arg, sizeof(op.u));
265                 rc = _hypercall1(int, event_channel_op_compat, &op);
266                 memcpy(arg, &op.u, sizeof(op.u));
267         }
268         return rc;
269 }
270
271 static inline int
272 HYPERVISOR_acm_op(
273         int cmd, void *arg)
274 {
275         return _hypercall2(int, acm_op, cmd, arg);
276 }
277
278 static inline int
279 HYPERVISOR_xen_version(
280         int cmd, void *arg)
281 {
282         return _hypercall2(int, xen_version, cmd, arg);
283 }
284
285 static inline int
286 HYPERVISOR_console_io(
287         int cmd, int count, char *str)
288 {
289         return _hypercall3(int, console_io, cmd, count, str);
290 }
291
292 static inline int
293 HYPERVISOR_physdev_op(
294         int cmd, void *arg)
295 {
296         int rc = _hypercall2(int, physdev_op, cmd, arg);
297         if (unlikely(rc == -ENOSYS)) {
298                 struct physdev_op op;
299                 op.cmd = cmd;
300                 memcpy(&op.u, arg, sizeof(op.u));
301                 rc = _hypercall1(int, physdev_op_compat, &op);
302                 memcpy(arg, &op.u, sizeof(op.u));
303         }
304         return rc;
305 }
306
307 static inline int
308 HYPERVISOR_grant_table_op(
309         unsigned int cmd, void *uop, unsigned int count)
310 {
311         return _hypercall3(int, grant_table_op, cmd, uop, count);
312 }
313
314 static inline int
315 HYPERVISOR_update_va_mapping_otherdomain(
316         unsigned long va, pte_t new_val, unsigned long flags, domid_t domid)
317 {
318         return _hypercall4(int, update_va_mapping_otherdomain, va,
319                            new_val.pte, flags, domid);
320 }
321
322 static inline int
323 HYPERVISOR_vm_assist(
324         unsigned int cmd, unsigned int type)
325 {
326         return _hypercall2(int, vm_assist, cmd, type);
327 }
328
329 static inline int
330 HYPERVISOR_vcpu_op(
331         int cmd, int vcpuid, void *extra_args)
332 {
333         return _hypercall3(int, vcpu_op, cmd, vcpuid, extra_args);
334 }
335
336 static inline int
337 HYPERVISOR_set_segment_base(
338         int reg, unsigned long value)
339 {
340         return _hypercall2(int, set_segment_base, reg, value);
341 }
342
343 static inline int
344 HYPERVISOR_suspend(
345         unsigned long srec)
346 {
347         struct sched_shutdown sched_shutdown = {
348                 .reason = SHUTDOWN_suspend
349         };
350
351         int rc = _hypercall3(int, sched_op, SCHEDOP_shutdown,
352                              &sched_shutdown, srec);
353
354         if (rc == -ENOSYS)
355                 rc = _hypercall3(int, sched_op_compat, SCHEDOP_shutdown,
356                                  SHUTDOWN_suspend, srec);
357
358         return rc;
359 }
360
361 static inline int
362 HYPERVISOR_nmi_op(
363         unsigned long op, void *arg)
364 {
365         return _hypercall2(int, nmi_op, op, arg);
366 }
367
368 static inline unsigned long
369 HYPERVISOR_hvm_op(
370     int op, void *arg)
371 {
372     return _hypercall2(unsigned long, hvm_op, op, arg);
373 }
374
375 static inline int
376 HYPERVISOR_callback_op(
377         int cmd, void *arg)
378 {
379         return _hypercall2(int, callback_op, cmd, arg);
380 }
381
382 static inline int
383 HYPERVISOR_xenoprof_op(
384         int op, void *arg)
385 {
386         return _hypercall2(int, xenoprof_op, op, arg);
387 }
388
389 #endif /* __HYPERCALL_H__ */