ia64/xen-unstable

view linux-2.6-xen-sparse/include/asm-ia64/hypercall.h @ 13367:01ea554f1c5e

[IA64] Hypercall optimizations

provide hypercall the same path with system
most of scrach registers don't need to be saved/restored
it is good for performance

Signed-off-by: Anthony Xu <anthony.xu@intel.com>
author awilliam@xenbuild2.aw
date Thu Jan 11 16:56:58 2007 -0700 (2007-01-11)
parents 9787cb7262e8
children 9fbaf07d3f67 8af1a8250c13
line source
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 */
33 #ifndef __HYPERCALL_H__
34 #define __HYPERCALL_H__
36 #ifndef __HYPERVISOR_H__
37 # error "please don't include this file directly"
38 #endif
40 #include <asm/xen/xcom_hcall.h>
41 struct xencomm_handle;
42 extern unsigned long __hypercall(unsigned long a1, unsigned long a2,
43 unsigned long a3, unsigned long a4,
44 unsigned long a5, unsigned long cmd);
46 /*
47 * Assembler stubs for hyper-calls.
48 */
50 #define _hypercall0(type, name) \
51 ({ \
52 long __res; \
53 __res=__hypercall(0, 0, 0, 0, 0, __HYPERVISOR_##name); \
54 (type)__res; \
55 })
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 })
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 })
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 })
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 })
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 })
108 static inline int
109 xencomm_arch_hypercall_sched_op(int cmd, struct xencomm_handle *arg)
110 {
111 return _hypercall2(int, sched_op, cmd, arg);
112 }
114 static inline long
115 HYPERVISOR_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 }
122 static inline int
123 xencomm_arch_hypercall_dom0_op(struct xencomm_handle *op)
124 {
125 return _hypercall1(int, dom0_op, op);
126 }
128 static inline int
129 xencomm_arch_hypercall_sysctl(struct xencomm_handle *op)
130 {
131 return _hypercall1(int, sysctl, op);
132 }
134 static inline int
135 xencomm_arch_hypercall_domctl(struct xencomm_handle *op)
136 {
137 return _hypercall1(int, domctl, op);
138 }
140 static inline int
141 xencomm_arch_hypercall_multicall(struct xencomm_handle *call_list,
142 int nr_calls)
143 {
144 return _hypercall2(int, multicall, call_list, nr_calls);
145 }
147 static inline int
148 xencomm_arch_hypercall_memory_op(unsigned int cmd, struct xencomm_handle *arg)
149 {
150 return _hypercall2(int, memory_op, cmd, arg);
151 }
153 static inline int
154 xencomm_arch_hypercall_event_channel_op(int cmd, struct xencomm_handle *arg)
155 {
156 return _hypercall2(int, event_channel_op, cmd, arg);
157 }
159 static inline int
160 xencomm_arch_hypercall_acm_op(unsigned int cmd, struct xencomm_handle *arg)
161 {
162 return _hypercall2(int, acm_op, cmd, arg);
163 }
165 static inline int
166 xencomm_arch_hypercall_xen_version(int cmd, struct xencomm_handle *arg)
167 {
168 return _hypercall2(int, xen_version, cmd, arg);
169 }
171 static inline int
172 xencomm_arch_hypercall_console_io(int cmd, int count,
173 struct xencomm_handle *str)
174 {
175 return _hypercall3(int, console_io, cmd, count, str);
176 }
178 static inline int
179 xencomm_arch_hypercall_physdev_op(int cmd, struct xencomm_handle *arg)
180 {
181 return _hypercall2(int, physdev_op, cmd, arg);
182 }
184 static inline int
185 xencomm_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 }
192 int HYPERVISOR_grant_table_op(unsigned int cmd, void *uop, unsigned int count);
194 extern int xencomm_arch_hypercall_suspend(struct xencomm_handle *arg);
196 static inline int
197 xencomm_arch_hypercall_callback_op(int cmd, struct xencomm_handle *arg)
198 {
199 return _hypercall2(int, callback_op, cmd, arg);
200 }
202 static inline unsigned long
203 xencomm_arch_hypercall_hvm_op(int cmd, void *arg)
204 {
205 return _hypercall2(unsigned long, hvm_op, cmd, arg);
206 }
208 static inline int
209 HYPERVISOR_physdev_op(int cmd, void *arg)
210 {
211 switch (cmd) {
212 case PHYSDEVOP_eoi:
213 return _hypercall1(int, ia64_fast_eoi,
214 ((struct physdev_eoi *)arg)->irq);
215 default:
216 return xencomm_hypercall_physdev_op(cmd, arg);
217 }
218 }
220 static inline int
221 xencomm_arch_hypercall_xenoprof_op(int op, struct xencomm_handle *arg)
222 {
223 return _hypercall2(int, xenoprof_op, op, arg);
224 }
226 extern fastcall unsigned int __do_IRQ(unsigned int irq, struct pt_regs *regs);
227 static inline void exit_idle(void) {}
228 #define do_IRQ(irq, regs) ({ \
229 irq_enter(); \
230 __do_IRQ((irq), (regs)); \
231 irq_exit(); \
232 })
234 #include <linux/err.h>
235 #ifdef CONFIG_XEN
236 #include <asm/xen/privop.h>
237 #endif /* CONFIG_XEN */
238 #ifdef HAVE_XEN_PLATFORM_COMPAT_H
239 #include <xen/platform-compat.h>
240 #endif
242 static inline unsigned long
243 __HYPERVISOR_ioremap(unsigned long ioaddr, unsigned long size)
244 {
245 return _hypercall3(unsigned long, ia64_dom0vp_op,
246 IA64_DOM0VP_ioremap, ioaddr, size);
247 }
249 static inline unsigned long
250 HYPERVISOR_ioremap(unsigned long ioaddr, unsigned long size)
251 {
252 unsigned long ret = ioaddr;
253 if (is_running_on_xen()) {
254 ret = __HYPERVISOR_ioremap(ioaddr, size);
255 if (unlikely(ret == -ENOSYS))
256 panic("hypercall %s failed with %ld. "
257 "Please check Xen and Linux config mismatch\n",
258 __func__, -ret);
259 else if (unlikely(IS_ERR_VALUE(ret)))
260 ret = ioaddr;
261 }
262 return ret;
263 }
265 static inline unsigned long
266 __HYPERVISOR_phystomach(unsigned long gpfn)
267 {
268 return _hypercall2(unsigned long, ia64_dom0vp_op,
269 IA64_DOM0VP_phystomach, gpfn);
270 }
272 static inline unsigned long
273 HYPERVISOR_phystomach(unsigned long gpfn)
274 {
275 unsigned long ret = gpfn;
276 if (is_running_on_xen()) {
277 ret = __HYPERVISOR_phystomach(gpfn);
278 }
279 return ret;
280 }
282 static inline unsigned long
283 __HYPERVISOR_machtophys(unsigned long mfn)
284 {
285 return _hypercall2(unsigned long, ia64_dom0vp_op,
286 IA64_DOM0VP_machtophys, mfn);
287 }
289 static inline unsigned long
290 HYPERVISOR_machtophys(unsigned long mfn)
291 {
292 unsigned long ret = mfn;
293 if (is_running_on_xen()) {
294 ret = __HYPERVISOR_machtophys(mfn);
295 }
296 return ret;
297 }
299 static inline unsigned long
300 __HYPERVISOR_zap_physmap(unsigned long gpfn, unsigned int extent_order)
301 {
302 return _hypercall3(unsigned long, ia64_dom0vp_op,
303 IA64_DOM0VP_zap_physmap, gpfn, extent_order);
304 }
306 static inline unsigned long
307 HYPERVISOR_zap_physmap(unsigned long gpfn, unsigned int extent_order)
308 {
309 unsigned long ret = 0;
310 if (is_running_on_xen()) {
311 ret = __HYPERVISOR_zap_physmap(gpfn, extent_order);
312 }
313 return ret;
314 }
316 static inline unsigned long
317 __HYPERVISOR_add_physmap(unsigned long gpfn, unsigned long mfn,
318 unsigned long flags, domid_t domid)
319 {
320 return _hypercall5(unsigned long, ia64_dom0vp_op,
321 IA64_DOM0VP_add_physmap, gpfn, mfn, flags, domid);
322 }
324 static inline unsigned long
325 HYPERVISOR_add_physmap(unsigned long gpfn, unsigned long mfn,
326 unsigned long flags, domid_t domid)
327 {
328 unsigned long ret = 0;
329 BUG_ON(!is_running_on_xen());//XXX
330 if (is_running_on_xen()) {
331 ret = __HYPERVISOR_add_physmap(gpfn, mfn, flags, domid);
332 }
333 return ret;
334 }
336 static inline unsigned long
337 __HYPERVISOR_add_physmap_with_gmfn(unsigned long gpfn, unsigned long gmfn,
338 unsigned long flags, domid_t domid)
339 {
340 return _hypercall5(unsigned long, ia64_dom0vp_op,
341 IA64_DOM0VP_add_physmap_with_gmfn,
342 gpfn, gmfn, flags, domid);
343 }
345 static inline unsigned long
346 HYPERVISOR_add_physmap_with_gmfn(unsigned long gpfn, unsigned long gmfn,
347 unsigned long flags, domid_t domid)
348 {
349 unsigned long ret = 0;
350 BUG_ON(!is_running_on_xen());//XXX
351 if (is_running_on_xen()) {
352 ret = __HYPERVISOR_add_physmap_with_gmfn(gpfn, gmfn,
353 flags, domid);
354 }
355 return ret;
356 }
358 #ifdef CONFIG_XEN_IA64_EXPOSE_P2M
359 static inline unsigned long
360 HYPERVISOR_expose_p2m(unsigned long conv_start_gpfn,
361 unsigned long assign_start_gpfn,
362 unsigned long expose_size, unsigned long granule_pfn)
363 {
364 return _hypercall5(unsigned long, ia64_dom0vp_op,
365 IA64_DOM0VP_expose_p2m, conv_start_gpfn,
366 assign_start_gpfn, expose_size, granule_pfn);
367 }
368 #endif
370 static inline int
371 xencomm_arch_hypercall_perfmon_op(unsigned long cmd,
372 struct xencomm_handle *arg,
373 unsigned long count)
374 {
375 return _hypercall4(int, ia64_dom0vp_op,
376 IA64_DOM0VP_perfmon, cmd, arg, count);
377 }
379 // for balloon driver
380 #define HYPERVISOR_update_va_mapping(va, new_val, flags) (0)
382 /* Use xencomm to do hypercalls. */
383 #ifdef MODULE
384 #define HYPERVISOR_sched_op xencomm_mini_hypercall_sched_op
385 #define HYPERVISOR_event_channel_op xencomm_mini_hypercall_event_channel_op
386 #define HYPERVISOR_callback_op xencomm_mini_hypercall_callback_op
387 #define HYPERVISOR_multicall xencomm_mini_hypercall_multicall
388 #define HYPERVISOR_xen_version xencomm_mini_hypercall_xen_version
389 #define HYPERVISOR_console_io xencomm_mini_hypercall_console_io
390 #define HYPERVISOR_hvm_op xencomm_mini_hypercall_hvm_op
391 #define HYPERVISOR_memory_op xencomm_mini_hypercall_memory_op
392 #define HYPERVISOR_xenoprof_op xencomm_mini_hypercall_xenoprof_op
393 #define HYPERVISOR_perfmon_op xencomm_mini_hypercall_perfmon_op
394 #else
395 #define HYPERVISOR_sched_op xencomm_hypercall_sched_op
396 #define HYPERVISOR_event_channel_op xencomm_hypercall_event_channel_op
397 #define HYPERVISOR_callback_op xencomm_hypercall_callback_op
398 #define HYPERVISOR_multicall xencomm_hypercall_multicall
399 #define HYPERVISOR_xen_version xencomm_hypercall_xen_version
400 #define HYPERVISOR_console_io xencomm_hypercall_console_io
401 #define HYPERVISOR_hvm_op xencomm_hypercall_hvm_op
402 #define HYPERVISOR_memory_op xencomm_hypercall_memory_op
403 #define HYPERVISOR_xenoprof_op xencomm_hypercall_xenoprof_op
404 #define HYPERVISOR_perfmon_op xencomm_hypercall_perfmon_op
405 #endif
407 #define HYPERVISOR_suspend xencomm_hypercall_suspend
409 #endif /* __HYPERCALL_H__ */