ia64/xen-unstable

view linux-2.6-xen-sparse/include/asm-ia64/hypercall.h @ 9975:e502007031f4

[IA64] linux: grant table hypercall work around

Current xen/ia64 grant table ignores some GNTMAP_xxx flags.
work around for that. This patch will be removed once the flags are supported.

Signed-off-by: Isaku Yamahata <yamahata@valinux.co.jp>
author awilliam@xenbuild.aw
date Tue May 09 11:41:06 2006 -0600 (2006-05-09)
parents 32db03c64a12
children 873a3451a81a
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 #include <linux/string.h> /* memcpy() */
38 #ifndef __HYPERVISOR_H__
39 # error "please don't include this file directly"
40 #endif
42 /*
43 * Assembler stubs for hyper-calls.
44 */
46 #define _hypercall0(type, name) \
47 ({ \
48 long __res; \
49 __asm__ __volatile__ (";;\n" \
50 "mov r2=%1\n" \
51 "break 0x1000 ;;\n" \
52 "mov %0=r8 ;;\n" \
53 : "=r" (__res) \
54 : "i" (__HYPERVISOR_##name) \
55 : "r2","r8", \
56 "memory" ); \
57 (type)__res; \
58 })
60 #define _hypercall1(type, name, a1) \
61 ({ \
62 long __res; \
63 __asm__ __volatile__ (";;\n" \
64 "mov r14=%2\n" \
65 "mov r2=%1\n" \
66 "break 0x1000 ;;\n" \
67 "mov %0=r8 ;;\n" \
68 : "=r" (__res) \
69 : "i" (__HYPERVISOR_##name), \
70 "r" ((unsigned long)(a1)) \
71 : "r14","r2","r8", \
72 "memory" ); \
73 (type)__res; \
74 })
76 #define _hypercall2(type, name, a1, a2) \
77 ({ \
78 long __res; \
79 __asm__ __volatile__ (";;\n" \
80 "mov r14=%2\n" \
81 "mov r15=%3\n" \
82 "mov r2=%1\n" \
83 "break 0x1000 ;;\n" \
84 "mov %0=r8 ;;\n" \
85 : "=r" (__res) \
86 : "i" (__HYPERVISOR_##name), \
87 "r" ((unsigned long)(a1)), \
88 "r" ((unsigned long)(a2)) \
89 : "r14","r15","r2","r8", \
90 "memory" ); \
91 (type)__res; \
92 })
94 #define _hypercall3(type, name, a1, a2, a3) \
95 ({ \
96 long __res; \
97 __asm__ __volatile__ (";;\n" \
98 "mov r14=%2\n" \
99 "mov r15=%3\n" \
100 "mov r16=%4\n" \
101 "mov r2=%1\n" \
102 "break 0x1000 ;;\n" \
103 "mov %0=r8 ;;\n" \
104 : "=r" (__res) \
105 : "i" (__HYPERVISOR_##name), \
106 "r" ((unsigned long)(a1)), \
107 "r" ((unsigned long)(a2)), \
108 "r" ((unsigned long)(a3)) \
109 : "r14","r15","r16","r2","r8", \
110 "memory" ); \
111 (type)__res; \
112 })
114 #define _hypercall4(type, name, a1, a2, a3, a4) \
115 ({ \
116 long __res; \
117 __asm__ __volatile__ (";;\n" \
118 "mov r14=%2\n" \
119 "mov r15=%3\n" \
120 "mov r16=%4\n" \
121 "mov r17=%5\n" \
122 "mov r2=%1\n" \
123 "break 0x1000 ;;\n" \
124 "mov %0=r8 ;;\n" \
125 : "=r" (__res) \
126 : "i" (__HYPERVISOR_##name), \
127 "r" ((unsigned long)(a1)), \
128 "r" ((unsigned long)(a2)), \
129 "r" ((unsigned long)(a3)), \
130 "r" ((unsigned long)(a4)) \
131 : "r14","r15","r16","r2","r8", \
132 "r17","memory" ); \
133 (type)__res; \
134 })
136 #define _hypercall5(type, name, a1, a2, a3, a4, a5) \
137 ({ \
138 long __res; \
139 __asm__ __volatile__ (";;\n" \
140 "mov r14=%2\n" \
141 "mov r15=%3\n" \
142 "mov r16=%4\n" \
143 "mov r17=%5\n" \
144 "mov r18=%6\n" \
145 "mov r2=%1\n" \
146 "break 0x1000 ;;\n" \
147 "mov %0=r8 ;;\n" \
148 : "=r" (__res) \
149 : "i" (__HYPERVISOR_##name), \
150 "r" ((unsigned long)(a1)), \
151 "r" ((unsigned long)(a2)), \
152 "r" ((unsigned long)(a3)), \
153 "r" ((unsigned long)(a4)), \
154 "r" ((unsigned long)(a5)) \
155 : "r14","r15","r16","r2","r8", \
156 "r17","r18","memory" ); \
157 (type)__res; \
158 })
160 static inline int
161 HYPERVISOR_sched_op_compat(
162 int cmd, unsigned long arg)
163 {
164 return _hypercall2(int, sched_op_compat, cmd, arg);
165 }
167 static inline int
168 HYPERVISOR_sched_op(
169 int cmd, void *arg)
170 {
171 return _hypercall2(int, sched_op, cmd, arg);
172 }
174 static inline long
175 HYPERVISOR_set_timer_op(
176 u64 timeout)
177 {
178 unsigned long timeout_hi = (unsigned long)(timeout>>32);
179 unsigned long timeout_lo = (unsigned long)timeout;
180 return _hypercall2(long, set_timer_op, timeout_lo, timeout_hi);
181 }
183 static inline int
184 HYPERVISOR_dom0_op(
185 dom0_op_t *dom0_op)
186 {
187 dom0_op->interface_version = DOM0_INTERFACE_VERSION;
188 return _hypercall1(int, dom0_op, dom0_op);
189 }
191 static inline int
192 HYPERVISOR_multicall(
193 void *call_list, int nr_calls)
194 {
195 return _hypercall2(int, multicall, call_list, nr_calls);
196 }
198 static inline int
199 HYPERVISOR_memory_op(
200 unsigned int cmd, void *arg)
201 {
202 return _hypercall2(int, memory_op, cmd, arg);
203 }
205 static inline int
206 HYPERVISOR_event_channel_op(
207 int cmd, void *arg)
208 {
209 int rc = _hypercall2(int, event_channel_op, cmd, arg);
210 if (unlikely(rc == -ENOSYS)) {
211 struct evtchn_op op;
212 op.cmd = cmd;
213 memcpy(&op.u, arg, sizeof(op.u));
214 rc = _hypercall1(int, event_channel_op_compat, &op);
215 }
216 return rc;
217 }
219 static inline int
220 HYPERVISOR_xen_version(
221 int cmd, void *arg)
222 {
223 return _hypercall2(int, xen_version, cmd, arg);
224 }
226 static inline int
227 HYPERVISOR_console_io(
228 int cmd, int count, char *str)
229 {
230 return _hypercall3(int, console_io, cmd, count, str);
231 }
233 static inline int
234 HYPERVISOR_physdev_op(
235 int cmd, void *arg)
236 {
237 int rc = _hypercall2(int, physdev_op, cmd, arg);
238 if (unlikely(rc == -ENOSYS)) {
239 struct physdev_op op;
240 op.cmd = cmd;
241 memcpy(&op.u, arg, sizeof(op.u));
242 rc = _hypercall1(int, physdev_op_compat, &op);
243 }
244 return rc;
245 }
247 //XXX __HYPERVISOR_grant_table_op is used for this hypercall constant.
248 static inline int
249 ____HYPERVISOR_grant_table_op(
250 unsigned int cmd, void *uop, unsigned int count)
251 {
252 return _hypercall3(int, grant_table_op, cmd, uop, count);
253 }
254 #ifndef CONFIG_XEN_IA64_DOM0_VP
255 #define HYPERVISOR_grant_table_op(cmd, uop, count) \
256 ____HYPERVISOR_grant_table_op((cmd), (uop), (count))
257 #else
258 int HYPERVISOR_grant_table_op(unsigned int cmd, void *uop, unsigned int count);
259 #endif
261 static inline int
262 HYPERVISOR_vcpu_op(
263 int cmd, int vcpuid, void *extra_args)
264 {
265 return _hypercall3(int, vcpu_op, cmd, vcpuid, extra_args);
266 }
268 static inline int
269 HYPERVISOR_suspend(
270 unsigned long srec)
271 {
272 struct sched_shutdown sched_shutdown = {
273 .reason = SHUTDOWN_suspend
274 };
276 int rc = _hypercall3(int, sched_op, SCHEDOP_shutdown,
277 &sched_shutdown, srec);
279 if (rc == -ENOSYS)
280 rc = _hypercall3(int, sched_op_compat, SCHEDOP_shutdown,
281 SHUTDOWN_suspend, srec);
283 return rc;
284 }
286 extern fastcall unsigned int __do_IRQ(unsigned int irq, struct pt_regs *regs);
287 static inline void exit_idle(void) {}
288 #define do_IRQ(irq, regs) __do_IRQ((irq), (regs))
290 #ifdef CONFIG_XEN_IA64_DOM0_VP
291 #include <asm/xen/privop.h>
293 #define _hypercall_imm1(type, name, imm, a1) \
294 ({ \
295 long __res; \
296 __asm__ __volatile__ (";;\n" \
297 "mov r14=%2\n" \
298 "mov r15=%3\n" \
299 "mov r2=%1\n" \
300 "break 0x1000 ;;\n" \
301 "mov %0=r8 ;;\n" \
302 : "=r" (__res) \
303 : "i" (__HYPERVISOR_##name), \
304 "i" (imm), \
305 "r" ((unsigned long)(a1)) \
306 : "r14","r15","r2","r8", \
307 "memory" ); \
308 (type)__res; \
309 })
311 #define _hypercall_imm2(type, name, imm, a1, a2) \
312 ({ \
313 long __res; \
314 __asm__ __volatile__ (";;\n" \
315 "mov r14=%2\n" \
316 "mov r15=%3\n" \
317 "mov r16=%4\n" \
318 "mov r2=%1\n" \
319 "break 0x1000 ;;\n" \
320 "mov %0=r8 ;;\n" \
321 : "=r" (__res) \
322 : "i" (__HYPERVISOR_##name), \
323 "i" (imm), \
324 "r" ((unsigned long)(a1)), \
325 "r" ((unsigned long)(a2)) \
326 : "r14","r15","r16","r2","r8", \
327 "memory" ); \
328 (type)__res; \
329 })
331 #define _hypercall_imm3(type, name, imm, a1, a2, a3) \
332 ({ \
333 long __res; \
334 __asm__ __volatile__ (";;\n" \
335 "mov r14=%2\n" \
336 "mov r15=%3\n" \
337 "mov r16=%4\n" \
338 "mov r17=%5\n" \
339 "mov r2=%1\n" \
340 "break 0x1000 ;;\n" \
341 "mov %0=r8 ;;\n" \
342 : "=r" (__res) \
343 : "i" (__HYPERVISOR_##name), \
344 "i" (imm), \
345 "r" ((unsigned long)(a1)), \
346 "r" ((unsigned long)(a2)), \
347 "r" ((unsigned long)(a3)) \
348 : "r14","r15","r16","r17", \
349 "r2","r8", \
350 "memory" ); \
351 (type)__res; \
352 })
354 #define _hypercall_imm4(type, name, imm, a1, a2, a3, a4) \
355 ({ \
356 long __res; \
357 __asm__ __volatile__ (";;\n" \
358 "mov r14=%2\n" \
359 "mov r15=%3\n" \
360 "mov r16=%4\n" \
361 "mov r17=%5\n" \
362 "mov r18=%6\n" \
363 "mov r2=%1\n" \
364 "break 0x1000 ;;\n" \
365 "mov %0=r8 ;;\n" \
366 : "=r" (__res) \
367 : "i" (__HYPERVISOR_##name), \
368 "i" (imm), \
369 "r" ((unsigned long)(a1)), \
370 "r" ((unsigned long)(a2)), \
371 "r" ((unsigned long)(a3)), \
372 "r" ((unsigned long)(a4)) \
373 : "r14","r15","r16","r17","r18", \
374 "r2","r8", \
375 "memory" ); \
376 (type)__res; \
377 })
379 static inline unsigned long
380 __HYPERVISOR_ioremap(unsigned long ioaddr, unsigned long size)
381 {
382 return _hypercall_imm2(unsigned long, ia64_dom0vp_op,
383 IA64_DOM0VP_ioremap, ioaddr, size);
384 }
386 static inline unsigned long
387 HYPERVISOR_ioremap(unsigned long ioaddr, unsigned long size)
388 {
389 unsigned long ret = ioaddr;
390 if (running_on_xen) {
391 ret = __HYPERVISOR_ioremap(ioaddr, size);
392 }
393 return ret;
394 }
396 static inline unsigned long
397 __HYPERVISOR_phystomach(unsigned long gpfn)
398 {
399 return _hypercall_imm1(unsigned long, ia64_dom0vp_op,
400 IA64_DOM0VP_phystomach, gpfn);
401 }
403 static inline unsigned long
404 HYPERVISOR_phystomach(unsigned long gpfn)
405 {
406 unsigned long ret = gpfn;
407 if (running_on_xen) {
408 ret = __HYPERVISOR_phystomach(gpfn);
409 }
410 return ret;
411 }
413 static inline unsigned long
414 __HYPERVISOR_machtophys(unsigned long mfn)
415 {
416 return _hypercall_imm1(unsigned long, ia64_dom0vp_op,
417 IA64_DOM0VP_machtophys, mfn);
418 }
420 static inline unsigned long
421 HYPERVISOR_machtophys(unsigned long mfn)
422 {
423 unsigned long ret = mfn;
424 if (running_on_xen) {
425 ret = __HYPERVISOR_machtophys(mfn);
426 }
427 return ret;
428 }
430 static inline unsigned long
431 __HYPERVISOR_populate_physmap(unsigned long gpfn, unsigned int extent_order,
432 unsigned int address_bits)
433 {
434 return _hypercall_imm3(unsigned long, ia64_dom0vp_op,
435 IA64_DOM0VP_populate_physmap, gpfn,
436 extent_order, address_bits);
437 }
439 static inline unsigned long
440 HYPERVISOR_populate_physmap(unsigned long gpfn, unsigned int extent_order,
441 unsigned int address_bits)
442 {
443 unsigned long ret = 0;
444 if (running_on_xen) {
445 ret = __HYPERVISOR_populate_physmap(gpfn, extent_order,
446 address_bits);
447 }
448 return ret;
449 }
451 static inline unsigned long
452 __HYPERVISOR_zap_physmap(unsigned long gpfn, unsigned int extent_order)
453 {
454 return _hypercall_imm2(unsigned long, ia64_dom0vp_op,
455 IA64_DOM0VP_zap_physmap, gpfn, extent_order);
456 }
458 static inline unsigned long
459 HYPERVISOR_zap_physmap(unsigned long gpfn, unsigned int extent_order)
460 {
461 unsigned long ret = 0;
462 if (running_on_xen) {
463 ret = __HYPERVISOR_zap_physmap(gpfn, extent_order);
464 }
465 return ret;
466 }
468 static inline unsigned long
469 __HYPERVISOR_add_physmap(unsigned long gpfn, unsigned long mfn,
470 unsigned int flags, domid_t domid)
471 {
472 return _hypercall_imm4(unsigned long, ia64_dom0vp_op,
473 IA64_DOM0VP_add_physmap, gpfn, mfn, flags,
474 domid);
475 }
476 static inline unsigned long
477 HYPERVISOR_add_physmap(unsigned long gpfn, unsigned long mfn,
478 unsigned int flags, domid_t domid)
479 {
480 unsigned long ret = 0;
481 BUG_ON(!running_on_xen);//XXX
482 if (running_on_xen) {
483 ret = __HYPERVISOR_add_physmap(gpfn, mfn, flags, domid);
484 }
485 return ret;
486 }
487 #else
488 #define HYPERVISOR_ioremap(ioaddr, size) (ioaddr)
489 #define HYPERVISOR_phystomach(gpfn) (gpfn)
490 #define HYPERVISOR_machtophys(mfn) (mfn)
491 #define HYPERVISOR_populate_physmap(gpfn, extent_order, address_bits) \
492 (0)
493 #define HYPERVISOR_zap_physmap(gpfn, extent_order) (0)
494 #define HYPERVISOR_add_physmap(gpfn, mfn, flags) (0)
495 #endif
496 #endif /* __HYPERCALL_H__ */