source: trunk/packages/xen-3.1/xen-3.1/linux-2.6-xen-sparse/include/asm-ia64/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: 12.1 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#ifndef __HYPERVISOR_H__
37# error "please don't include this file directly"
38#endif
39
40#include <asm/xen/xcom_hcall.h>
41struct xencomm_handle;
42extern unsigned long __hypercall(unsigned long a1, unsigned long a2,
43                                 unsigned long a3, unsigned long a4,
44                                 unsigned long a5, unsigned long cmd);
45
46/*
47 * Assembler stubs for hyper-calls.
48 */
49
50#define _hypercall0(type, name)                                 \
51({                                                              \
52        long __res;                                             \
53        __res=__hypercall(0, 0, 0, 0, 0, __HYPERVISOR_##name);  \
54        (type)__res;                                            \
55})
56
57#define _hypercall1(type, name, a1)                             \
58({                                                              \
59        long __res;                                             \
60        __res = __hypercall((unsigned long)a1,                  \
61                             0, 0, 0, 0, __HYPERVISOR_##name);  \
62        (type)__res;                                            \
63})
64
65#define _hypercall2(type, name, a1, a2)                         \
66({                                                              \
67        long __res;                                             \
68        __res = __hypercall((unsigned long)a1,                  \
69                            (unsigned long)a2,                  \
70                            0, 0, 0, __HYPERVISOR_##name);      \
71        (type)__res;                                            \
72})
73
74#define _hypercall3(type, name, a1, a2, a3)                     \
75({                                                              \
76        long __res;                                             \
77        __res = __hypercall((unsigned long)a1,                  \
78                            (unsigned long)a2,                  \
79                            (unsigned long)a3,                  \
80                            0, 0, __HYPERVISOR_##name);         \
81        (type)__res;                                            \
82})
83
84#define _hypercall4(type, name, a1, a2, a3, a4)                 \
85({                                                              \
86        long __res;                                             \
87        __res = __hypercall((unsigned long)a1,                  \
88                            (unsigned long)a2,                  \
89                            (unsigned long)a3,                  \
90                            (unsigned long)a4,                  \
91                            0, __HYPERVISOR_##name);            \
92        (type)__res;                                            \
93})
94
95#define _hypercall5(type, name, a1, a2, a3, a4, a5)             \
96({                                                              \
97        long __res;                                             \
98        __res = __hypercall((unsigned long)a1,                  \
99                            (unsigned long)a2,                  \
100                            (unsigned long)a3,                  \
101                            (unsigned long)a4,                  \
102                            (unsigned long)a5,                  \
103                            __HYPERVISOR_##name);               \
104        (type)__res;                                            \
105})
106
107
108static inline int
109xencomm_arch_hypercall_sched_op(int cmd, struct xencomm_handle *arg)
110{
111        return _hypercall2(int, sched_op, cmd, arg);
112}
113
114static inline long
115HYPERVISOR_set_timer_op(u64 timeout)
116{
117        unsigned long timeout_hi = (unsigned long)(timeout >> 32);
118        unsigned long timeout_lo = (unsigned long)timeout;
119        return _hypercall2(long, set_timer_op, timeout_lo, timeout_hi);
120}
121
122static inline int
123xencomm_arch_hypercall_platform_op(struct xencomm_handle *op)
124{
125        return _hypercall1(int, platform_op, op);
126}
127
128static inline int
129xencomm_arch_hypercall_sysctl(struct xencomm_handle *op)
130{
131        return _hypercall1(int, sysctl, op);
132}
133
134static inline int
135xencomm_arch_hypercall_domctl(struct xencomm_handle *op)
136{
137        return _hypercall1(int, domctl, op);
138}
139
140static inline int
141xencomm_arch_hypercall_multicall(struct xencomm_handle *call_list,
142                                 int nr_calls)
143{
144        return _hypercall2(int, multicall, call_list, nr_calls);
145}
146
147static inline int
148xencomm_arch_hypercall_memory_op(unsigned int cmd, struct xencomm_handle *arg)
149{
150        return _hypercall2(int, memory_op, cmd, arg);
151}
152
153static inline int
154xencomm_arch_hypercall_event_channel_op(int cmd, struct xencomm_handle *arg)
155{
156        return _hypercall2(int, event_channel_op, cmd, arg);
157}
158
159static inline int
160xencomm_arch_hypercall_acm_op(unsigned int cmd, struct xencomm_handle *arg)
161{
162        return _hypercall2(int, acm_op, cmd, arg);
163}
164
165static inline int
166xencomm_arch_hypercall_xen_version(int cmd, struct xencomm_handle *arg)
167{
168        return _hypercall2(int, xen_version, cmd, arg);
169}
170
171static inline int
172xencomm_arch_hypercall_console_io(int cmd, int count,
173                                  struct xencomm_handle *str)
174{
175        return _hypercall3(int, console_io, cmd, count, str);
176}
177
178static inline int
179xencomm_arch_hypercall_physdev_op(int cmd, struct xencomm_handle *arg)
180{
181        return _hypercall2(int, physdev_op, cmd, arg);
182}
183
184static inline int
185xencomm_arch_hypercall_grant_table_op(unsigned int cmd,
186                                      struct xencomm_handle *uop,
187                                      unsigned int count)
188{
189        return _hypercall3(int, grant_table_op, cmd, uop, count);
190}
191
192int HYPERVISOR_grant_table_op(unsigned int cmd, void *uop, unsigned int count);
193
194extern int xencomm_arch_hypercall_suspend(struct xencomm_handle *arg);
195
196static inline int
197xencomm_arch_hypercall_callback_op(int cmd, struct xencomm_handle *arg)
198{
199        return _hypercall2(int, callback_op, cmd, arg);
200}
201
202static inline unsigned long
203xencomm_arch_hypercall_hvm_op(int cmd, void *arg)
204{
205        return _hypercall2(unsigned long, hvm_op, cmd, arg);
206}
207
208static inline long
209xencomm_arch_hypercall_vcpu_op(int cmd, int cpu, void *arg)
210{
211        return _hypercall3(long, vcpu_op, cmd, cpu, arg);
212}
213
214static inline int
215HYPERVISOR_physdev_op(int cmd, void *arg)
216{
217        switch (cmd) {
218        case PHYSDEVOP_eoi:
219                return _hypercall1(int, ia64_fast_eoi,
220                                   ((struct physdev_eoi *)arg)->irq);
221        default:
222                return xencomm_hypercall_physdev_op(cmd, arg);
223        }
224}
225
226static inline int
227xencomm_arch_hypercall_xenoprof_op(int op, struct xencomm_handle *arg)
228{
229        return _hypercall2(int, xenoprof_op, op, arg);
230}
231
232extern fastcall unsigned int __do_IRQ(unsigned int irq, struct pt_regs *regs);
233static inline void exit_idle(void) {}
234#define do_IRQ(irq, regs) ({                    \
235        irq_enter();                            \
236        __do_IRQ((irq), (regs));                \
237        irq_exit();                             \
238})
239
240#include <linux/err.h>
241#ifdef CONFIG_XEN
242#include <asm/xen/privop.h>
243#endif /* CONFIG_XEN */
244#ifdef HAVE_XEN_PLATFORM_COMPAT_H
245#include <xen/platform-compat.h>
246#endif
247
248static inline unsigned long
249__HYPERVISOR_ioremap(unsigned long ioaddr, unsigned long size)
250{
251        return _hypercall3(unsigned long, ia64_dom0vp_op,
252                           IA64_DOM0VP_ioremap, ioaddr, size);
253}
254
255static inline unsigned long
256HYPERVISOR_ioremap(unsigned long ioaddr, unsigned long size)
257{
258        unsigned long ret = ioaddr;
259        if (is_running_on_xen()) {
260                ret = __HYPERVISOR_ioremap(ioaddr, size);
261                if (unlikely(ret == -ENOSYS))
262                        panic("hypercall %s failed with %ld. "
263                              "Please check Xen and Linux config mismatch\n",
264                              __func__, -ret);
265                else if (unlikely(IS_ERR_VALUE(ret)))
266                        ret = ioaddr;
267        }
268        return ret;
269}
270
271static inline unsigned long
272__HYPERVISOR_phystomach(unsigned long gpfn)
273{
274        return _hypercall2(unsigned long, ia64_dom0vp_op,
275                           IA64_DOM0VP_phystomach, gpfn);
276}
277
278static inline unsigned long
279HYPERVISOR_phystomach(unsigned long gpfn)
280{
281        unsigned long ret = gpfn;
282        if (is_running_on_xen()) {
283                ret = __HYPERVISOR_phystomach(gpfn);
284        }
285        return ret;
286}
287
288static inline unsigned long
289__HYPERVISOR_machtophys(unsigned long mfn)
290{
291        return _hypercall2(unsigned long, ia64_dom0vp_op,
292                           IA64_DOM0VP_machtophys, mfn);
293}
294
295static inline unsigned long
296HYPERVISOR_machtophys(unsigned long mfn)
297{
298        unsigned long ret = mfn;
299        if (is_running_on_xen()) {
300                ret = __HYPERVISOR_machtophys(mfn);
301        }
302        return ret;
303}
304
305static inline unsigned long
306__HYPERVISOR_zap_physmap(unsigned long gpfn, unsigned int extent_order)
307{
308        return _hypercall3(unsigned long, ia64_dom0vp_op,
309                           IA64_DOM0VP_zap_physmap, gpfn, extent_order);
310}
311
312static inline unsigned long
313HYPERVISOR_zap_physmap(unsigned long gpfn, unsigned int extent_order)
314{
315        unsigned long ret = 0;
316        if (is_running_on_xen()) {
317                ret = __HYPERVISOR_zap_physmap(gpfn, extent_order);
318        }
319        return ret;
320}
321
322static inline unsigned long
323__HYPERVISOR_add_physmap(unsigned long gpfn, unsigned long mfn,
324                         unsigned long flags, domid_t domid)
325{
326        return _hypercall5(unsigned long, ia64_dom0vp_op,
327                           IA64_DOM0VP_add_physmap, gpfn, mfn, flags, domid);
328}
329
330static inline unsigned long
331HYPERVISOR_add_physmap(unsigned long gpfn, unsigned long mfn,
332                       unsigned long flags, domid_t domid)
333{
334        unsigned long ret = 0;
335        BUG_ON(!is_running_on_xen());//XXX
336        if (is_running_on_xen()) {
337                ret = __HYPERVISOR_add_physmap(gpfn, mfn, flags, domid);
338        }
339        return ret;
340}
341
342static inline unsigned long
343__HYPERVISOR_add_physmap_with_gmfn(unsigned long gpfn, unsigned long gmfn,
344                                   unsigned long flags, domid_t domid)
345{
346        return _hypercall5(unsigned long, ia64_dom0vp_op,
347                           IA64_DOM0VP_add_physmap_with_gmfn,
348                           gpfn, gmfn, flags, domid);
349}
350
351static inline unsigned long
352HYPERVISOR_add_physmap_with_gmfn(unsigned long gpfn, unsigned long gmfn,
353                                 unsigned long flags, domid_t domid)
354{
355        unsigned long ret = 0;
356        BUG_ON(!is_running_on_xen());//XXX
357        if (is_running_on_xen()) {
358                ret = __HYPERVISOR_add_physmap_with_gmfn(gpfn, gmfn,
359                                                         flags, domid);
360        }
361        return ret;
362}
363
364#ifdef CONFIG_XEN_IA64_EXPOSE_P2M
365static inline unsigned long
366HYPERVISOR_expose_p2m(unsigned long conv_start_gpfn,
367                      unsigned long assign_start_gpfn,
368                      unsigned long expose_size, unsigned long granule_pfn)
369{
370        return _hypercall5(unsigned long, ia64_dom0vp_op,
371                           IA64_DOM0VP_expose_p2m, conv_start_gpfn,
372                           assign_start_gpfn, expose_size, granule_pfn);
373}
374#endif
375
376static inline int
377xencomm_arch_hypercall_perfmon_op(unsigned long cmd,
378                                  struct xencomm_handle *arg,
379                                  unsigned long count)
380{
381        return _hypercall4(int, ia64_dom0vp_op,
382                           IA64_DOM0VP_perfmon, cmd, arg, count);
383}
384
385// for balloon driver
386#define HYPERVISOR_update_va_mapping(va, new_val, flags) (0)
387
388/* Use xencomm to do hypercalls.  */
389#ifdef MODULE
390#define HYPERVISOR_sched_op xencomm_mini_hypercall_sched_op
391#define HYPERVISOR_event_channel_op xencomm_mini_hypercall_event_channel_op
392#define HYPERVISOR_callback_op xencomm_mini_hypercall_callback_op
393#define HYPERVISOR_multicall xencomm_mini_hypercall_multicall
394#define HYPERVISOR_xen_version xencomm_mini_hypercall_xen_version
395#define HYPERVISOR_console_io xencomm_mini_hypercall_console_io
396#define HYPERVISOR_hvm_op xencomm_mini_hypercall_hvm_op
397#define HYPERVISOR_memory_op xencomm_mini_hypercall_memory_op
398#define HYPERVISOR_xenoprof_op xencomm_mini_hypercall_xenoprof_op
399#define HYPERVISOR_perfmon_op xencomm_mini_hypercall_perfmon_op
400#else
401#define HYPERVISOR_sched_op xencomm_hypercall_sched_op
402#define HYPERVISOR_event_channel_op xencomm_hypercall_event_channel_op
403#define HYPERVISOR_callback_op xencomm_hypercall_callback_op
404#define HYPERVISOR_multicall xencomm_hypercall_multicall
405#define HYPERVISOR_xen_version xencomm_hypercall_xen_version
406#define HYPERVISOR_console_io xencomm_hypercall_console_io
407#define HYPERVISOR_hvm_op xencomm_hypercall_hvm_op
408#define HYPERVISOR_memory_op xencomm_hypercall_memory_op
409#define HYPERVISOR_xenoprof_op xencomm_hypercall_xenoprof_op
410#define HYPERVISOR_perfmon_op xencomm_hypercall_perfmon_op
411#endif
412
413#define HYPERVISOR_suspend xencomm_hypercall_suspend
414#define HYPERVISOR_vcpu_op xencomm_hypercall_vcpu_op
415
416#endif /* __HYPERCALL_H__ */
Note: See TracBrowser for help on using the repository browser.