ia64/xen-unstable

view xen/include/xen/compat.h @ 19800:78962f85c562

IOMMU: Add two generic functions to vendor neutral interface

Add 2 generic functions into the vendor neutral iommu interface, The
reason is that from changeset 19732, there is only one global flag
"iommu_enabled" that controls iommu enablement for both vtd and amd
systems, so we need different code paths for vtd and amd iommu systems
if this flag has been turned on. Also, the early checking of
"iommu_enabled" in iommu_setup() is removed to prevent iommu
functionalities from been disabled on amd systems.

Signed-off-by: Wei Wang <wei.wang2@amd.com>
author Keir Fraser <keir.fraser@citrix.com>
date Fri Jun 19 08:41:50 2009 +0100 (2009-06-19)
parents 71af89e70fee
children
line source
1 /******************************************************************************
2 * compat.h
3 */
5 #ifndef __XEN_COMPAT_H__
6 #define __XEN_COMPAT_H__
8 #include <xen/config.h>
10 #ifdef CONFIG_COMPAT
12 #include <xen/types.h>
13 #include <asm/compat.h>
14 #include <compat/xlat.h>
16 #define __DEFINE_COMPAT_HANDLE(name, type) \
17 typedef struct { \
18 compat_ptr_t c; \
19 type *_[0] __attribute__((__packed__)); \
20 } __compat_handle_ ## name
22 #define DEFINE_COMPAT_HANDLE(name) \
23 __DEFINE_COMPAT_HANDLE(name, name); \
24 __DEFINE_COMPAT_HANDLE(const_ ## name, const name)
25 #define COMPAT_HANDLE(name) __compat_handle_ ## name
27 /* Is the compat handle a NULL reference? */
28 #define compat_handle_is_null(hnd) ((hnd).c == 0)
30 /* Offset the given compat handle into the array it refers to. */
31 #define compat_handle_add_offset(hnd, nr) \
32 ((hnd).c += (nr) * sizeof(**(hnd)._))
34 /* Cast a compat handle to the specified type of handle. */
35 #define compat_handle_cast(chnd, type) ({ \
36 type *_x = (__typeof__(**(chnd)._) *)(full_ptr_t)(chnd).c; \
37 (XEN_GUEST_HANDLE(type)) { _x }; \
38 })
40 #define guest_from_compat_handle(ghnd, chnd) \
41 set_xen_guest_handle(ghnd, \
42 (__typeof__(**(chnd)._) *)(full_ptr_t)(chnd).c)
44 /*
45 * Copy an array of objects to guest context via a compat handle,
46 * specifying an offset into the guest array.
47 */
48 #define copy_to_compat_offset(hnd, off, ptr, nr) ({ \
49 const typeof(*(ptr)) *_s = (ptr); \
50 char (*_d)[sizeof(*_s)] = (void *)(full_ptr_t)(hnd).c; \
51 ((void)((typeof(**(hnd)._) *)(full_ptr_t)(hnd).c == (ptr))); \
52 raw_copy_to_guest(_d + (off), _s, sizeof(*_s) * (nr)); \
53 })
55 /*
56 * Copy an array of objects from guest context via a compat handle,
57 * specifying an offset into the guest array.
58 */
59 #define copy_from_compat_offset(ptr, hnd, off, nr) ({ \
60 const typeof(*(ptr)) *_s = (typeof(**(hnd)._) *)(full_ptr_t)(hnd).c; \
61 typeof(*(ptr)) *_d = (ptr); \
62 raw_copy_from_guest(_d, _s + (off), sizeof(*_d) * (nr)); \
63 })
65 #define copy_to_compat(hnd, ptr, nr) \
66 copy_to_compat_offset(hnd, 0, ptr, nr)
68 #define copy_from_compat(ptr, hnd, nr) \
69 copy_from_compat_offset(ptr, hnd, 0, nr)
71 /* Copy sub-field of a structure to guest context via a compat handle. */
72 #define copy_field_to_compat(hnd, ptr, field) ({ \
73 const typeof(&(ptr)->field) _s = &(ptr)->field; \
74 void *_d = &((typeof(**(hnd)._) *)(full_ptr_t)(hnd).c)->field; \
75 ((void)(&((typeof(**(hnd)._) *)(full_ptr_t)(hnd).c)->field == \
76 &(ptr)->field)); \
77 raw_copy_to_guest(_d, _s, sizeof(*_s)); \
78 })
80 /* Copy sub-field of a structure from guest context via a compat handle. */
81 #define copy_field_from_compat(ptr, hnd, field) ({ \
82 const typeof(&(ptr)->field) _s = \
83 &((typeof(**(hnd)._) *)(full_ptr_t)(hnd).c)->field; \
84 typeof(&(ptr)->field) _d = &(ptr)->field; \
85 raw_copy_from_guest(_d, _s, sizeof(*_d)); \
86 })
88 /*
89 * Pre-validate a guest handle.
90 * Allows use of faster __copy_* functions.
91 */
92 #define compat_handle_okay(hnd, nr) \
93 compat_array_access_ok((void *)(full_ptr_t)(hnd).c, (nr), \
94 sizeof(**(hnd)._))
96 #define __copy_to_compat_offset(hnd, off, ptr, nr) ({ \
97 const typeof(*(ptr)) *_s = (ptr); \
98 char (*_d)[sizeof(*_s)] = (void *)(full_ptr_t)(hnd).c; \
99 ((void)((typeof(**(hnd)._) *)(full_ptr_t)(hnd).c == (ptr))); \
100 __raw_copy_to_guest(_d + (off), _s, sizeof(*_s) * (nr)); \
101 })
103 #define __copy_from_compat_offset(ptr, hnd, off, nr) ({ \
104 const typeof(*(ptr)) *_s = (typeof(**(hnd)._) *)(full_ptr_t)(hnd).c; \
105 typeof(*(ptr)) *_d = (ptr); \
106 __raw_copy_from_guest(_d, _s + (off), sizeof(*_d) * (nr)); \
107 })
109 #define __copy_to_compat(hnd, ptr, nr) \
110 __copy_to_compat_offset(hnd, 0, ptr, nr)
112 #define __copy_from_compat(ptr, hnd, nr) \
113 __copy_from_compat_offset(ptr, hnd, 0, nr)
115 #define __copy_field_to_compat(hnd, ptr, field) ({ \
116 const typeof(&(ptr)->field) _s = &(ptr)->field; \
117 void *_d = &((typeof(**(hnd)._) *)(full_ptr_t)(hnd).c)->field; \
118 ((void)(&((typeof(**(hnd)._) *)(full_ptr_t)(hnd).c)->field == \
119 &(ptr)->field)); \
120 __raw_copy_to_guest(_d, _s, sizeof(*_s)); \
121 })
123 #define __copy_field_from_compat(ptr, hnd, field) ({ \
124 const typeof(&(ptr)->field) _s = \
125 &((typeof(**(hnd)._) *)(full_ptr_t)(hnd).c)->field; \
126 typeof(&(ptr)->field) _d = &(ptr)->field; \
127 __raw_copy_from_guest(_d, _s, sizeof(*_d)); \
128 })
131 #define CHECK_TYPE(name) \
132 typedef int __checkT ## name[1 - ((xen_ ## name ## _t *)0 != \
133 (compat_ ## name ## _t *)0) * 2]
134 #define CHECK_TYPE_(k, n) \
135 typedef int __checkT ## k ## _ ## n[1 - ((k xen_ ## n *)0 != \
136 (k compat_ ## n *)0) * 2]
138 #define CHECK_SIZE(name) \
139 typedef int __checkS ## name[1 - (sizeof(xen_ ## name ## _t) != \
140 sizeof(compat_ ## name ## _t)) * 2]
141 #define CHECK_SIZE_(k, n) \
142 typedef int __checkS ## k ## _ ## n[1 - (sizeof(k xen_ ## n) != \
143 sizeof(k compat_ ## n)) * 2]
145 #define CHECK_FIELD(t, f) \
146 typedef int __checkF ## t ## __ ## f[1 - (&((xen_ ## t ## _t *)0)->f != \
147 &((compat_ ## t ## _t *)0)->f) * 2]
148 #define CHECK_FIELD_(k, n, f) \
149 typedef int __checkF ## k ## _ ## n ## __ ## f[1 - (&((k xen_ ## n *)0)->f != \
150 &((k compat_ ## n *)0)->f) * 2]
152 #define CHECK_SUBFIELD_1(t, f1, f2) \
153 typedef int __checkF1 ## t ## __ ## f1 ## __ ## f2 \
154 [1 - (&((xen_ ## t ## _t *)0)->f1.f2 != \
155 &((compat_ ## t ## _t *)0)->f1.f2) * 2]
156 #define CHECK_SUBFIELD_1_(k, n, f1, f2) \
157 typedef int __checkF1 ## k ## _ ## n ## __ ## f1 ## __ ## f2 \
158 [1 - (&((k xen_ ## n *)0)->f1.f2 != \
159 &((k compat_ ## n *)0)->f1.f2) * 2]
161 #define CHECK_SUBFIELD_2(t, f1, f2, f3) \
162 typedef int __checkF2 ## t ## __ ## f1 ## __ ## f2 ## __ ## f3 \
163 [1 - (&((xen_ ## t ## _t *)0)->f1.f2.f3 != \
164 &((compat_ ## t ## _t *)0)->f1.f2.f3) * 2]
165 #define CHECK_SUBFIELD_2_(k, n, f1, f2, f3) \
166 typedef int __checkF2 ## k ## _ ## n ## __ ## f1 ## __ ## f2 ## __ ## f3 \
167 [1 - (&((k xen_ ## n *)0)->f1.f2.f3 != \
168 &((k compat_ ## n *)0)->f1.f2.f3) * 2]
170 int hypercall_xlat_continuation(unsigned int *id, unsigned int mask, ...);
172 /* In-place translation functons: */
173 struct start_info;
174 void xlat_start_info(struct start_info *, enum XLAT_start_info_console);
175 struct vcpu_runstate_info;
176 void xlat_vcpu_runstate_info(struct vcpu_runstate_info *);
178 int switch_compat(struct domain *);
179 int switch_native(struct domain *);
181 #else
183 #define compat_handle_is_null(hnd) 0
185 #endif
187 #endif /* __XEN_COMPAT_H__ */