ia64/xen-unstable

view xen/include/xen/xencomm.h @ 17402:146f214a0e63

xencomm: add support for log dirty mode

Signed-off-by: Kouya Shimura <kouya@jp.fujitsu.com>
author Keir Fraser <keir.fraser@citrix.com>
date Mon Apr 07 15:02:47 2008 +0100 (2008-04-07)
parents c98c707a07a8
children 6e92603ed9f2
line source
1 /*
2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; either version 2 of the License, or
5 * (at your option) any later version.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 *
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15 *
16 * Copyright (C) IBM Corp. 2006
17 *
18 * Authors: Hollis Blanchard <hollisb@us.ibm.com>
19 */
21 #ifndef __XENCOMM_H__
22 #define __XENCOMM_H__
24 #include <public/xen.h>
26 unsigned long xencomm_copy_to_guest(
27 void *to, const void *from, unsigned int len, unsigned int skip);
28 unsigned long xencomm_copy_from_guest(
29 void *to, const void *from, unsigned int len, unsigned int skip);
30 int xencomm_add_offset(void **handle, unsigned int bytes);
31 int xencomm_handle_is_null(void *ptr);
33 static inline int xencomm_is_inline(const void *handle)
34 {
35 unsigned long addr = (unsigned long)handle;
36 return (addr & XENCOMM_INLINE_FLAG) == XENCOMM_INLINE_FLAG;
37 }
39 static inline unsigned long xencomm_inline_addr(const void *handle)
40 {
41 return (unsigned long)handle & ~XENCOMM_INLINE_FLAG;
42 }
44 /* Is the guest handle a NULL reference? */
45 #define guest_handle_is_null(hnd) \
46 ((hnd).p == NULL || xencomm_handle_is_null((hnd).p))
48 /* Offset the given guest handle into the array it refers to. */
49 #define guest_handle_add_offset(hnd, nr) ({ \
50 const typeof((hnd).p) _ptr; \
51 xencomm_add_offset((void **)&((hnd).p), nr * sizeof(*_ptr)); \
52 })
54 /* Cast a guest handle to the specified type of handle. */
55 #define guest_handle_cast(hnd, type) ({ \
56 type *_x = (hnd).p; \
57 XEN_GUEST_HANDLE(type) _y; \
58 set_xen_guest_handle(_y, _x); \
59 _y; \
60 })
62 /* Since we run in real mode, we can safely access all addresses. That also
63 * means our __routines are identical to our "normal" routines. */
64 #define guest_handle_okay(hnd, nr) 1
66 /*
67 * Copy an array of objects to guest context via a guest handle.
68 * Optionally specify an offset into the guest array.
69 */
70 #define copy_to_guest_offset(hnd, idx, ptr, nr) \
71 __copy_to_guest_offset(hnd, idx, ptr, nr)
73 /* Copy sub-field of a structure to guest context via a guest handle. */
74 #define copy_field_to_guest(hnd, ptr, field) \
75 __copy_field_to_guest(hnd, ptr, field)
77 /*
78 * Copy an array of objects from guest context via a guest handle.
79 * Optionally specify an offset into the guest array.
80 */
81 #define copy_from_guest_offset(ptr, hnd, idx, nr) \
82 __copy_from_guest_offset(ptr, hnd, idx, nr)
84 /* Copy sub-field of a structure from guest context via a guest handle. */
85 #define copy_field_from_guest(ptr, hnd, field) \
86 __copy_field_from_guest(ptr, hnd, field)
88 #define __copy_to_guest_offset(hnd, idx, ptr, nr) ({ \
89 const typeof(*(ptr)) *_s = (ptr); \
90 void *_d = (hnd).p; \
91 ((void)((hnd).p == (ptr))); \
92 xencomm_copy_to_guest(_d, _s, sizeof(*_s)*(nr), sizeof(*_s)*(idx)); \
93 })
95 #define __copy_field_to_guest(hnd, ptr, field) ({ \
96 unsigned int _off = offsetof(typeof(*(hnd).p), field); \
97 const typeof(&(ptr)->field) _s = &(ptr)->field; \
98 void *_d = (hnd).p; \
99 ((void)(&(hnd).p->field == &(ptr)->field)); \
100 xencomm_copy_to_guest(_d, _s, sizeof(*_s), _off); \
101 })
103 #define __copy_from_guest_offset(ptr, hnd, idx, nr) ({ \
104 const typeof(*(ptr)) *_s = (hnd).p; \
105 typeof(*(ptr)) *_d = (ptr); \
106 xencomm_copy_from_guest(_d, _s, sizeof(*_d)*(nr), sizeof(*_d)*(idx)); \
107 })
109 #define __copy_field_from_guest(ptr, hnd, field) ({ \
110 unsigned int _off = offsetof(typeof(*(hnd).p), field); \
111 const void *_s = (hnd).p; \
112 typeof(&(ptr)->field) _d = &(ptr)->field; \
113 ((void)(&(hnd).p->field == &(ptr)->field)); \
114 xencomm_copy_from_guest(_d, _s, sizeof(*_d), _off); \
115 })
117 #ifdef CONFIG_XENCOMM_MARK_DIRTY
118 extern void xencomm_mark_dirty(unsigned long addr, unsigned int len);
119 #else
120 static inline void xencomm_mark_dirty(unsigned long addr, unsigned int len)
121 {
122 }
123 #endif
125 #endif /* __XENCOMM_H__ */