xenio_gntdev.h revision 1.1 1 1.1 cegger /******************************************************************************
2 1.1 cegger * gntdev.h
3 1.1 cegger *
4 1.1 cegger * Interface to /dev/xen/gntdev.
5 1.1 cegger *
6 1.1 cegger * Copyright (c) 2007, D G Murray
7 1.1 cegger *
8 1.1 cegger * This program is free software; you can redistribute it and/or
9 1.1 cegger * modify it under the terms of the GNU General Public License version 2
10 1.1 cegger * as published by the Free Software Foundation; or, when distributed
11 1.1 cegger * separately from the Linux kernel or incorporated into other
12 1.1 cegger * software packages, subject to the following license:
13 1.1 cegger *
14 1.1 cegger * Permission is hereby granted, free of charge, to any person obtaining a copy
15 1.1 cegger * of this source file (the "Software"), to deal in the Software without
16 1.1 cegger * restriction, including without limitation the rights to use, copy, modify,
17 1.1 cegger * merge, publish, distribute, sublicense, and/or sell copies of the Software,
18 1.1 cegger * and to permit persons to whom the Software is furnished to do so, subject to
19 1.1 cegger * the following conditions:
20 1.1 cegger *
21 1.1 cegger * The above copyright notice and this permission notice shall be included in
22 1.1 cegger * all copies or substantial portions of the Software.
23 1.1 cegger *
24 1.1 cegger * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
25 1.1 cegger * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
26 1.1 cegger * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
27 1.1 cegger * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
28 1.1 cegger * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
29 1.1 cegger * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
30 1.1 cegger * IN THE SOFTWARE.
31 1.1 cegger */
32 1.1 cegger
33 1.1 cegger #ifndef __XEN_GNTDEV_H__
34 1.1 cegger #define __XEN_GNTDEV_H__
35 1.1 cegger
36 1.1 cegger struct ioctl_gntdev_grant_ref {
37 1.1 cegger /* The domain ID of the grant to be mapped. */
38 1.1 cegger uint32_t domid;
39 1.1 cegger /* The grant reference of the grant to be mapped. */
40 1.1 cegger uint32_t ref;
41 1.1 cegger };
42 1.1 cegger
43 1.1 cegger /*
44 1.1 cegger * Inserts the grant references into the mapping table of an instance
45 1.1 cegger * of gntdev. N.B. This does not perform the mapping, which is deferred
46 1.1 cegger * until mmap() is called with @index as the offset.
47 1.1 cegger */
48 1.1 cegger #define IOCTL_GNTDEV_MAP_GRANT_REF \
49 1.1 cegger _IOWR('G', 0, sizeof(struct ioctl_gntdev_map_grant_ref))
50 1.1 cegger struct ioctl_gntdev_map_grant_ref {
51 1.1 cegger /* IN parameters */
52 1.1 cegger /* The number of grants to be mapped. */
53 1.1 cegger uint32_t count;
54 1.1 cegger uint32_t pad;
55 1.1 cegger /* OUT parameters */
56 1.1 cegger /* The offset to be used on a subsequent call to mmap(). */
57 1.1 cegger uint64_t index;
58 1.1 cegger /* Variable IN parameter. */
59 1.1 cegger /* Array of grant references, of size @count. */
60 1.1 cegger struct ioctl_gntdev_grant_ref refs[1];
61 1.1 cegger };
62 1.1 cegger
63 1.1 cegger /*
64 1.1 cegger * Removes the grant references from the mapping table of an instance of
65 1.1 cegger * of gntdev. N.B. munmap() must be called on the relevant virtual address(es)
66 1.1 cegger * before this ioctl is called, or an error will result.
67 1.1 cegger */
68 1.1 cegger #define IOCTL_GNTDEV_UNMAP_GRANT_REF \
69 1.1 cegger _IOW('G', 1, sizeof(struct ioctl_gntdev_unmap_grant_ref))
70 1.1 cegger struct ioctl_gntdev_unmap_grant_ref {
71 1.1 cegger /* IN parameters */
72 1.1 cegger /* The offset was returned by the corresponding map operation. */
73 1.1 cegger uint64_t index;
74 1.1 cegger /* The number of pages to be unmapped. */
75 1.1 cegger uint32_t count;
76 1.1 cegger uint32_t pad;
77 1.1 cegger };
78 1.1 cegger
79 1.1 cegger /*
80 1.1 cegger * Returns the offset in the driver's address space that corresponds
81 1.1 cegger * to @vaddr. This can be used to perform a munmap(), followed by an
82 1.1 cegger * UNMAP_GRANT_REF ioctl, where no state about the offset is retained by
83 1.1 cegger * the caller. The number of pages that were allocated at the same time as
84 1.1 cegger * @vaddr is returned in @count.
85 1.1 cegger *
86 1.1 cegger * N.B. Where more than one page has been mapped into a contiguous range, the
87 1.1 cegger * supplied @vaddr must correspond to the start of the range; otherwise
88 1.1 cegger * an error will result. It is only possible to munmap() the entire
89 1.1 cegger * contiguously-allocated range at once, and not any subrange thereof.
90 1.1 cegger */
91 1.1 cegger #define IOCTL_GNTDEV_GET_OFFSET_FOR_VADDR \
92 1.1 cegger _IOWR('G', 2, sizeof(struct ioctl_gntdev_get_offset_for_vaddr))
93 1.1 cegger struct ioctl_gntdev_get_offset_for_vaddr {
94 1.1 cegger /* IN parameters */
95 1.1 cegger /* The virtual address of the first mapped page in a range. */
96 1.1 cegger uint64_t vaddr;
97 1.1 cegger /* OUT parameters */
98 1.1 cegger /* The offset that was used in the initial mmap() operation. */
99 1.1 cegger uint64_t offset;
100 1.1 cegger /* The number of pages mapped in the VM area that begins at @vaddr. */
101 1.1 cegger uint32_t count;
102 1.1 cegger uint32_t pad;
103 1.1 cegger };
104 1.1 cegger
105 1.1 cegger /*
106 1.1 cegger * Sets the maximum number of grants that may mapped at once by this gntdev
107 1.1 cegger * instance.
108 1.1 cegger *
109 1.1 cegger * N.B. This must be called before any other ioctl is performed on the device.
110 1.1 cegger */
111 1.1 cegger #define IOCTL_GNTDEV_SET_MAX_GRANTS \
112 1.1 cegger _IOW('G', 3, sizeof(struct ioctl_gntdev_set_max_grants))
113 1.1 cegger struct ioctl_gntdev_set_max_grants {
114 1.1 cegger /* IN parameter */
115 1.1 cegger /* The maximum number of grants that may be mapped at once. */
116 1.1 cegger uint32_t count;
117 1.1 cegger };
118 1.1 cegger
119 1.1 cegger #endif /* __XEN_GNTDEV_H__ */
120