source: trunk/packages/xen-3.1/xen-3.1/linux-2.6-xen-sparse/include/asm-i386/mach-xen/asm/hypercall.h @ 34

Last change on this file since 34 was 34, checked in by hartmans, 18 years ago

Add xen and xen-common

File size: 9.3 KB
Line 
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
128static inline int
129HYPERVISOR_set_trap_table(
130        trap_info_t *table)
131{
132        return _hypercall1(int, set_trap_table, table);
133}
134
135static inline int
136HYPERVISOR_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
142static inline int
143HYPERVISOR_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
149static inline int
150HYPERVISOR_set_gdt(
151        unsigned long *frame_list, int entries)
152{
153        return _hypercall2(int, set_gdt, frame_list, entries);
154}
155
156static inline int
157HYPERVISOR_stack_switch(
158        unsigned long ss, unsigned long esp)
159{
160        return _hypercall2(int, stack_switch, ss, esp);
161}
162
163static inline int
164HYPERVISOR_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
173static inline int
174HYPERVISOR_fpu_taskswitch(
175        int set)
176{
177        return _hypercall1(int, fpu_taskswitch, set);
178}
179
180static inline int
181HYPERVISOR_sched_op_compat(
182        int cmd, unsigned long arg)
183{
184        return _hypercall2(int, sched_op_compat, cmd, arg);
185}
186
187static inline int
188HYPERVISOR_sched_op(
189        int cmd, void *arg)
190{
191        return _hypercall2(int, sched_op, cmd, arg);
192}
193
194static inline long
195HYPERVISOR_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
203static inline int
204HYPERVISOR_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
211static inline int
212HYPERVISOR_set_debugreg(
213        int reg, unsigned long value)
214{
215        return _hypercall2(int, set_debugreg, reg, value);
216}
217
218static inline unsigned long
219HYPERVISOR_get_debugreg(
220        int reg)
221{
222        return _hypercall1(unsigned long, get_debugreg, reg);
223}
224
225static inline int
226HYPERVISOR_update_descriptor(
227        u64 ma, u64 desc)
228{
229        return _hypercall4(int, update_descriptor, ma, ma>>32, desc, desc>>32);
230}
231
232static inline int
233HYPERVISOR_memory_op(
234        unsigned int cmd, void *arg)
235{
236        return _hypercall2(int, memory_op, cmd, arg);
237}
238
239static inline int
240HYPERVISOR_multicall(
241        multicall_entry_t *call_list, int nr_calls)
242{
243        return _hypercall2(int, multicall, call_list, nr_calls);
244}
245
246static inline int
247HYPERVISOR_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
258static inline int
259HYPERVISOR_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
277static inline int
278HYPERVISOR_acm_op(
279        int cmd, void *arg)
280{
281        return _hypercall2(int, acm_op, cmd, arg);
282}
283
284static inline int
285HYPERVISOR_xen_version(
286        int cmd, void *arg)
287{
288        return _hypercall2(int, xen_version, cmd, arg);
289}
290
291static inline int
292HYPERVISOR_console_io(
293        int cmd, int count, char *str)
294{
295        return _hypercall3(int, console_io, cmd, count, str);
296}
297
298static inline int
299HYPERVISOR_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
317static inline int
318HYPERVISOR_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
324static inline int
325HYPERVISOR_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
336static inline int
337HYPERVISOR_vm_assist(
338        unsigned int cmd, unsigned int type)
339{
340        return _hypercall2(int, vm_assist, cmd, type);
341}
342
343static inline int
344HYPERVISOR_vcpu_op(
345        int cmd, int vcpuid, void *extra_args)
346{
347        return _hypercall3(int, vcpu_op, cmd, vcpuid, extra_args);
348}
349
350static inline int
351HYPERVISOR_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
370static inline int
371HYPERVISOR_nmi_op(
372        unsigned long op, void *arg)
373{
374        return _hypercall2(int, nmi_op, op, arg);
375}
376
377static inline unsigned long
378HYPERVISOR_hvm_op(
379    int op, void *arg)
380{
381    return _hypercall2(unsigned long, hvm_op, op, arg);
382}
383
384static inline int
385HYPERVISOR_callback_op(
386        int cmd, void *arg)
387{
388        return _hypercall2(int, callback_op, cmd, arg);
389}
390
391static inline int
392HYPERVISOR_xenoprof_op(
393        int op, void *arg)
394{
395        return _hypercall2(int, xenoprof_op, op, arg);
396}
397
398static inline int
399HYPERVISOR_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__ */
Note: See TracBrowser for help on using the repository browser.