This commit was manufactured by cvs2svn to create branch 'vserver'.
[linux-2.6.git] / include / asm-i386 / 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  * 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 #define _hypercall0(type, name)                 \
46 ({                                              \
47         long __res;                             \
48         asm volatile (                          \
49                 "call hypercall_page + ("STR(__HYPERVISOR_##name)" * 32)"\
50                 : "=a" (__res)                  \
51                 :                               \
52                 : "memory" );                   \
53         (type)__res;                            \
54 })
55
56 #define _hypercall1(type, name, a1)                             \
57 ({                                                              \
58         long __res, __ign1;                                     \
59         asm volatile (                                          \
60                 "call hypercall_page + ("STR(__HYPERVISOR_##name)" * 32)"\
61                 : "=a" (__res), "=b" (__ign1)                   \
62                 : "1" ((long)(a1))                              \
63                 : "memory" );                                   \
64         (type)__res;                                            \
65 })
66
67 #define _hypercall2(type, name, a1, a2)                         \
68 ({                                                              \
69         long __res, __ign1, __ign2;                             \
70         asm volatile (                                          \
71                 "call hypercall_page + ("STR(__HYPERVISOR_##name)" * 32)"\
72                 : "=a" (__res), "=b" (__ign1), "=c" (__ign2)    \
73                 : "1" ((long)(a1)), "2" ((long)(a2))            \
74                 : "memory" );                                   \
75         (type)__res;                                            \
76 })
77
78 #define _hypercall3(type, name, a1, a2, a3)                     \
79 ({                                                              \
80         long __res, __ign1, __ign2, __ign3;                     \
81         asm volatile (                                          \
82                 "call hypercall_page + ("STR(__HYPERVISOR_##name)" * 32)"\
83                 : "=a" (__res), "=b" (__ign1), "=c" (__ign2),   \
84                 "=d" (__ign3)                                   \
85                 : "1" ((long)(a1)), "2" ((long)(a2)),           \
86                 "3" ((long)(a3))                                \
87                 : "memory" );                                   \
88         (type)__res;                                            \
89 })
90
91 #define _hypercall4(type, name, a1, a2, a3, a4)                 \
92 ({                                                              \
93         long __res, __ign1, __ign2, __ign3, __ign4;             \
94         asm volatile (                                          \
95                 "call hypercall_page + ("STR(__HYPERVISOR_##name)" * 32)"\
96                 : "=a" (__res), "=b" (__ign1), "=c" (__ign2),   \
97                 "=d" (__ign3), "=S" (__ign4)                    \
98                 : "1" ((long)(a1)), "2" ((long)(a2)),           \
99                 "3" ((long)(a3)), "4" ((long)(a4))              \
100                 : "memory" );                                   \
101         (type)__res;                                            \
102 })
103
104 #define _hypercall5(type, name, a1, a2, a3, a4, a5)             \
105 ({                                                              \
106         long __res, __ign1, __ign2, __ign3, __ign4, __ign5;     \
107         asm volatile (                                          \
108                 "call hypercall_page + ("STR(__HYPERVISOR_##name)" * 32)"\
109                 : "=a" (__res), "=b" (__ign1), "=c" (__ign2),   \
110                 "=d" (__ign3), "=S" (__ign4), "=D" (__ign5)     \
111                 : "1" ((long)(a1)), "2" ((long)(a2)),           \
112                 "3" ((long)(a3)), "4" ((long)(a4)),             \
113                 "5" ((long)(a5))                                \
114                 : "memory" );                                   \
115         (type)__res;                                            \
116 })
117
118 static inline int
119 HYPERVISOR_set_trap_table(
120         trap_info_t *table)
121 {
122         return _hypercall1(int, set_trap_table, table);
123 }
124
125 static inline int
126 HYPERVISOR_mmu_update(
127         mmu_update_t *req, int count, int *success_count, domid_t domid)
128 {
129         return _hypercall4(int, mmu_update, req, count, success_count, domid);
130 }
131
132 static inline int
133 HYPERVISOR_mmuext_op(
134         struct mmuext_op *op, int count, int *success_count, domid_t domid)
135 {
136         return _hypercall4(int, mmuext_op, op, count, success_count, domid);
137 }
138
139 static inline int
140 HYPERVISOR_set_gdt(
141         unsigned long *frame_list, int entries)
142 {
143         return _hypercall2(int, set_gdt, frame_list, entries);
144 }
145
146 static inline int
147 HYPERVISOR_stack_switch(
148         unsigned long ss, unsigned long esp)
149 {
150         return _hypercall2(int, stack_switch, ss, esp);
151 }
152
153 static inline int
154 HYPERVISOR_set_callbacks(
155         unsigned long event_selector, unsigned long event_address,
156         unsigned long failsafe_selector, unsigned long failsafe_address)
157 {
158         return _hypercall4(int, set_callbacks,
159                            event_selector, event_address,
160                            failsafe_selector, failsafe_address);
161 }
162
163 static inline int
164 HYPERVISOR_fpu_taskswitch(
165         int set)
166 {
167         return _hypercall1(int, fpu_taskswitch, set);
168 }
169
170 static inline int
171 HYPERVISOR_sched_op_compat(
172         int cmd, unsigned long arg)
173 {
174         return _hypercall2(int, sched_op_compat, cmd, arg);
175 }
176
177 static inline int
178 HYPERVISOR_sched_op(
179         int cmd, void *arg)
180 {
181         return _hypercall2(int, sched_op, cmd, arg);
182 }
183
184 static inline long
185 HYPERVISOR_set_timer_op(
186         u64 timeout)
187 {
188         unsigned long timeout_hi = (unsigned long)(timeout>>32);
189         unsigned long timeout_lo = (unsigned long)timeout;
190         return _hypercall2(long, set_timer_op, timeout_lo, timeout_hi);
191 }
192
193 static inline int
194 HYPERVISOR_dom0_op(
195         dom0_op_t *dom0_op)
196 {
197         dom0_op->interface_version = DOM0_INTERFACE_VERSION;
198         return _hypercall1(int, dom0_op, dom0_op);
199 }
200
201 static inline int
202 HYPERVISOR_set_debugreg(
203         int reg, unsigned long value)
204 {
205         return _hypercall2(int, set_debugreg, reg, value);
206 }
207
208 static inline unsigned long
209 HYPERVISOR_get_debugreg(
210         int reg)
211 {
212         return _hypercall1(unsigned long, get_debugreg, reg);
213 }
214
215 static inline int
216 HYPERVISOR_update_descriptor(
217         u64 ma, u64 desc)
218 {
219         return _hypercall4(int, update_descriptor, ma, ma>>32, desc, desc>>32);
220 }
221
222 static inline int
223 HYPERVISOR_memory_op(
224         unsigned int cmd, void *arg)
225 {
226         return _hypercall2(int, memory_op, cmd, arg);
227 }
228
229 static inline int
230 HYPERVISOR_multicall(
231         void *call_list, int nr_calls)
232 {
233         return _hypercall2(int, multicall, call_list, nr_calls);
234 }
235
236 static inline int
237 HYPERVISOR_update_va_mapping(
238         unsigned long va, pte_t new_val, unsigned long flags)
239 {
240         unsigned long pte_hi = 0;
241 #ifdef CONFIG_X86_PAE
242         pte_hi = new_val.pte_high;
243 #endif
244         return _hypercall4(int, update_va_mapping, va,
245                            new_val.pte_low, pte_hi, flags);
246 }
247
248 static inline int
249 HYPERVISOR_event_channel_op(
250         int cmd, void *arg)
251 {
252         int rc = _hypercall2(int, event_channel_op, cmd, arg);
253         if (unlikely(rc == -ENOSYS)) {
254                 struct evtchn_op op;
255                 op.cmd = cmd;
256                 memcpy(&op.u, arg, sizeof(op.u));
257                 rc = _hypercall1(int, event_channel_op_compat, &op);
258                 memcpy(arg, &op.u, sizeof(op.u));
259         }
260         return rc;
261 }
262
263 static inline int
264 HYPERVISOR_acm_op(
265         int cmd, void *arg)
266 {
267         return _hypercall2(int, acm_op, cmd, arg);
268 }
269
270 static inline int
271 HYPERVISOR_xen_version(
272         int cmd, void *arg)
273 {
274         return _hypercall2(int, xen_version, cmd, arg);
275 }
276
277 static inline int
278 HYPERVISOR_console_io(
279         int cmd, int count, char *str)
280 {
281         return _hypercall3(int, console_io, cmd, count, str);
282 }
283
284 static inline int
285 HYPERVISOR_physdev_op(
286         int cmd, void *arg)
287 {
288         int rc = _hypercall2(int, physdev_op, cmd, arg);
289         if (unlikely(rc == -ENOSYS)) {
290                 struct physdev_op op;
291                 op.cmd = cmd;
292                 memcpy(&op.u, arg, sizeof(op.u));
293                 rc = _hypercall1(int, physdev_op_compat, &op);
294                 memcpy(arg, &op.u, sizeof(op.u));
295         }
296         return rc;
297 }
298
299 static inline int
300 HYPERVISOR_grant_table_op(
301         unsigned int cmd, void *uop, unsigned int count)
302 {
303         return _hypercall3(int, grant_table_op, cmd, uop, count);
304 }
305
306 static inline int
307 HYPERVISOR_update_va_mapping_otherdomain(
308         unsigned long va, pte_t new_val, unsigned long flags, domid_t domid)
309 {
310         unsigned long pte_hi = 0;
311 #ifdef CONFIG_X86_PAE
312         pte_hi = new_val.pte_high;
313 #endif
314         return _hypercall5(int, update_va_mapping_otherdomain, va,
315                            new_val.pte_low, pte_hi, flags, domid);
316 }
317
318 static inline int
319 HYPERVISOR_vm_assist(
320         unsigned int cmd, unsigned int type)
321 {
322         return _hypercall2(int, vm_assist, cmd, type);
323 }
324
325 static inline int
326 HYPERVISOR_vcpu_op(
327         int cmd, int vcpuid, void *extra_args)
328 {
329         return _hypercall3(int, vcpu_op, cmd, vcpuid, extra_args);
330 }
331
332 static inline int
333 HYPERVISOR_suspend(
334         unsigned long srec)
335 {
336         struct sched_shutdown sched_shutdown = {
337                 .reason = SHUTDOWN_suspend
338         };
339
340         int rc = _hypercall3(int, sched_op, SCHEDOP_shutdown,
341                              &sched_shutdown, srec);
342
343         if (rc == -ENOSYS)
344                 rc = _hypercall3(int, sched_op_compat, SCHEDOP_shutdown,
345                                  SHUTDOWN_suspend, srec);
346
347         return rc;
348 }
349
350 static inline int
351 HYPERVISOR_nmi_op(
352         unsigned long op, void *arg)
353 {
354         return _hypercall2(int, nmi_op, op, arg);
355 }
356
357 static inline int
358 HYPERVISOR_callback_op(
359         int cmd, void *arg)
360 {
361         return _hypercall2(int, callback_op, cmd, arg);
362 }
363
364 static inline int
365 HYPERVISOR_xenoprof_op(
366         int op, void *arg)
367 {
368         return _hypercall2(int, xenoprof_op, op, arg);
369 }
370
371
372 #endif /* __HYPERCALL_H__ */