1 /* SPDX-License-Identifier: ((GPL-2.0 WITH Linux-syscall-note) OR MIT) */
2 /******************************************************************************
5 * Interface to /dev/xen/gntdev.
7 * Copyright (c) 2007, D G Murray
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License version 2
11 * as published by the Free Software Foundation; or, when distributed
12 * separately from the Linux kernel or incorporated into other
13 * software packages, subject to the following license:
15 * Permission is hereby granted, free of charge, to any person obtaining a copy
16 * of this source file (the "Software"), to deal in the Software without
17 * restriction, including without limitation the rights to use, copy, modify,
18 * merge, publish, distribute, sublicense, and/or sell copies of the Software,
19 * and to permit persons to whom the Software is furnished to do so, subject to
20 * the following conditions:
22 * The above copyright notice and this permission notice shall be included in
23 * all copies or substantial portions of the Software.
25 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
26 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
27 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
28 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
29 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
30 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
34 #ifndef __LINUX_PUBLIC_GNTDEV_H__
35 #define __LINUX_PUBLIC_GNTDEV_H__
37 #include <linux/types.h>
39 struct ioctl_gntdev_grant_ref
{
40 /* The domain ID of the grant to be mapped. */
42 /* The grant reference of the grant to be mapped. */
47 * Inserts the grant references into the mapping table of an instance
48 * of gntdev. N.B. This does not perform the mapping, which is deferred
49 * until mmap() is called with @index as the offset.
51 #define IOCTL_GNTDEV_MAP_GRANT_REF \
52 _IOC(_IOC_NONE, 'G', 0, sizeof(struct ioctl_gntdev_map_grant_ref))
53 struct ioctl_gntdev_map_grant_ref
{
55 /* The number of grants to be mapped. */
59 /* The offset to be used on a subsequent call to mmap(). */
61 /* Variable IN parameter. */
62 /* Array of grant references, of size @count. */
63 struct ioctl_gntdev_grant_ref refs
[1];
67 * Removes the grant references from the mapping table of an instance of
68 * of gntdev. N.B. munmap() must be called on the relevant virtual address(es)
69 * before this ioctl is called, or an error will result.
71 #define IOCTL_GNTDEV_UNMAP_GRANT_REF \
72 _IOC(_IOC_NONE, 'G', 1, sizeof(struct ioctl_gntdev_unmap_grant_ref))
73 struct ioctl_gntdev_unmap_grant_ref
{
75 /* The offset was returned by the corresponding map operation. */
77 /* The number of pages to be unmapped. */
83 * Returns the offset in the driver's address space that corresponds
84 * to @vaddr. This can be used to perform a munmap(), followed by an
85 * UNMAP_GRANT_REF ioctl, where no state about the offset is retained by
86 * the caller. The number of pages that were allocated at the same time as
87 * @vaddr is returned in @count.
89 * N.B. Where more than one page has been mapped into a contiguous range, the
90 * supplied @vaddr must correspond to the start of the range; otherwise
91 * an error will result. It is only possible to munmap() the entire
92 * contiguously-allocated range at once, and not any subrange thereof.
94 #define IOCTL_GNTDEV_GET_OFFSET_FOR_VADDR \
95 _IOC(_IOC_NONE, 'G', 2, sizeof(struct ioctl_gntdev_get_offset_for_vaddr))
96 struct ioctl_gntdev_get_offset_for_vaddr
{
98 /* The virtual address of the first mapped page in a range. */
101 /* The offset that was used in the initial mmap() operation. */
103 /* The number of pages mapped in the VM area that begins at @vaddr. */
109 * Sets the maximum number of grants that may mapped at once by this gntdev
112 * N.B. This must be called before any other ioctl is performed on the device.
114 #define IOCTL_GNTDEV_SET_MAX_GRANTS \
115 _IOC(_IOC_NONE, 'G', 3, sizeof(struct ioctl_gntdev_set_max_grants))
116 struct ioctl_gntdev_set_max_grants
{
118 /* The maximum number of grants that may be mapped at once. */
123 * Sets up an unmap notification within the page, so that the other side can do
124 * cleanup if this side crashes. Required to implement cross-domain robust
125 * mutexes or close notification on communication channels.
127 * Each mapped page only supports one notification; multiple calls referring to
128 * the same page overwrite the previous notification. You must clear the
129 * notification prior to the IOCTL_GNTALLOC_DEALLOC_GREF if you do not want it
132 #define IOCTL_GNTDEV_SET_UNMAP_NOTIFY \
133 _IOC(_IOC_NONE, 'G', 7, sizeof(struct ioctl_gntdev_unmap_notify))
134 struct ioctl_gntdev_unmap_notify
{
136 /* Offset in the file descriptor for a byte within the page (same as
137 * used in mmap). If using UNMAP_NOTIFY_CLEAR_BYTE, this is the byte to
138 * be cleared. Otherwise, it can be any byte in the page whose
139 * notification we are adjusting.
142 /* Action(s) to take on unmap */
144 /* Event channel to notify */
145 __u32 event_channel_port
;
148 struct gntdev_grant_copy_segment
{
159 __u16 flags
; /* GNTCOPY_* */
160 __s16 status
; /* GNTST_* */
164 * Copy between grant references and local buffers.
166 * The copy is split into @count @segments, each of which can copy
167 * to/from one grant reference.
169 * Each segment is similar to struct gnttab_copy in the hypervisor ABI
170 * except the local buffer is specified using a virtual address
171 * (instead of a GFN and offset).
173 * The local buffer may cross a Xen page boundary -- the driver will
174 * split segments into multiple ops if required.
176 * Returns 0 if all segments have been processed and @status in each
177 * segment is valid. Note that one or more segments may have failed
178 * (status != GNTST_okay).
180 * If the driver had to split a segment into two or more ops, @status
181 * includes the status of the first failed op for that segment (or
182 * GNTST_okay if all ops were successful).
184 * If -1 is returned, the status of all segments is undefined.
186 * EINVAL: A segment has local buffers for both source and
188 * EINVAL: A segment crosses the boundary of a foreign page.
189 * EFAULT: A segment's local buffer is not accessible.
191 #define IOCTL_GNTDEV_GRANT_COPY \
192 _IOC(_IOC_NONE, 'G', 8, sizeof(struct ioctl_gntdev_grant_copy))
193 struct ioctl_gntdev_grant_copy
{
195 struct gntdev_grant_copy_segment __user
*segments
;
198 /* Clear (set to zero) the byte specified by index */
199 #define UNMAP_NOTIFY_CLEAR_BYTE 0x1
200 /* Send an interrupt on the indicated event channel */
201 #define UNMAP_NOTIFY_SEND_EVENT 0x2
203 #endif /* __LINUX_PUBLIC_GNTDEV_H__ */