direct-io.hg

view xen/include/asm-ia64/guest_access.h @ 15399:45a44a9cbe8d

Enhance guest memory accessor macros so that source operands can be
pointers to const or arrays.

Only build-tested on ia64, and untested for powerpc (which, however,
is almost identical to ia64, except for an apparent bug in the original
version of __copy_field_{from,to}_guest in that the field offset was
multiplied by the field size).

Signed-off-by: Jan Beulich <jbeulich@novell.com>
author kfraser@localhost.localdomain
date Wed Jun 20 15:29:53 2007 +0100 (2007-06-20)
parents 5c97ef4c7147
children
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 * Tristan Gingold <tristan.gingold@bull.net>
20 */
22 #ifndef __ASM_GUEST_ACCESS_H__
23 #define __ASM_GUEST_ACCESS_H__
25 extern unsigned long xencomm_copy_to_guest(void *to, const void *from,
26 unsigned int len, unsigned int skip);
27 extern unsigned long xencomm_copy_from_guest(void *to, const void *from,
28 unsigned int len, unsigned int skip);
29 extern void *xencomm_add_offset(void *handle, unsigned int bytes);
30 extern int xencomm_handle_is_null(void *ptr);
33 /* Is the guest handle a NULL reference? */
34 #define guest_handle_is_null(hnd) \
35 ((hnd).p == NULL || xencomm_handle_is_null((hnd).p))
37 /* Offset the given guest handle into the array it refers to. */
38 #define guest_handle_add_offset(hnd, nr) ({ \
39 const typeof((hnd).p) _ptr = (hnd).p; \
40 (hnd).p = xencomm_add_offset(_ptr, nr * sizeof(*_ptr)); \
41 })
43 /* Cast a guest handle to the specified type of handle. */
44 #define guest_handle_cast(hnd, type) ({ \
45 type *_x = (hnd).p; \
46 XEN_GUEST_HANDLE(type) _y; \
47 set_xen_guest_handle(_y, _x); \
48 _y; \
49 })
52 /* Since we run in real mode, we can safely access all addresses. That also
53 * means our __routines are identical to our "normal" routines. */
54 #define guest_handle_okay(hnd, nr) 1
56 /*
57 * Copy an array of objects to guest context via a guest handle.
58 * Optionally specify an offset into the guest array.
59 */
60 #define copy_to_guest_offset(hnd, idx, ptr, nr) \
61 __copy_to_guest_offset(hnd, idx, ptr, nr)
63 /* Copy sub-field of a structure to guest context via a guest handle. */
64 #define copy_field_to_guest(hnd, ptr, field) \
65 __copy_field_to_guest(hnd, ptr, field)
67 /*
68 * Copy an array of objects from guest context via a guest handle.
69 * Optionally specify an offset into the guest array.
70 */
71 #define copy_from_guest_offset(ptr, hnd, idx, nr) \
72 __copy_from_guest_offset(ptr, hnd, idx, nr)
74 /* Copy sub-field of a structure from guest context via a guest handle. */
75 #define copy_field_from_guest(ptr, hnd, field) \
76 __copy_field_from_guest(ptr, hnd, field)
78 #define __copy_to_guest_offset(hnd, idx, ptr, nr) ({ \
79 const typeof(*(ptr)) *_s = (ptr); \
80 void *_d = (hnd).p; \
81 ((void)((hnd).p == (ptr))); \
82 xencomm_copy_to_guest(_d, _s, sizeof(*_s)*(nr), sizeof(*_s)*(idx)); \
83 })
85 #define __copy_field_to_guest(hnd, ptr, field) ({ \
86 unsigned int _off = offsetof(typeof(*(hnd).p), field); \
87 const typeof(&(ptr)->field) _s = &(ptr)->field; \
88 void *_d = (hnd).p; \
89 ((void)(&(hnd).p->field == &(ptr)->field)); \
90 xencomm_copy_to_guest(_d, _s, sizeof(*_s), _off); \
91 })
93 #define __copy_from_guest_offset(ptr, hnd, idx, nr) ({ \
94 const typeof(*(ptr)) *_s = (hnd).p; \
95 typeof(*(ptr)) *_d = (ptr); \
96 xencomm_copy_from_guest(_d, _s, sizeof(*_d)*(nr), sizeof(*_d)*(idx)); \
97 })
99 #define __copy_field_from_guest(ptr, hnd, field) ({ \
100 unsigned int _off = offsetof(typeof(*(hnd).p), field); \
101 const void *_s = (hnd).p; \
102 typeof(&(ptr)->field) _d = &(ptr)->field; \
103 ((void)(&(hnd).p->field == &(ptr)->field)); \
104 xencomm_copy_from_guest(_d, _s, sizeof(*_d), _off); \
105 })
107 /* Internal use only: returns 0 in case of bad address. */
108 extern unsigned long xencomm_paddr_to_maddr(unsigned long paddr);
110 #endif /* __ASM_GUEST_ACCESS_H__ */