1e87eaf040ab639e94ed0a58ff0eac68d1d38fb0aEd Heyl/******************************************************************************
2e87eaf040ab639e94ed0a58ff0eac68d1d38fb0aEd Heyl * gntdev.h
3e87eaf040ab639e94ed0a58ff0eac68d1d38fb0aEd Heyl *
4e87eaf040ab639e94ed0a58ff0eac68d1d38fb0aEd Heyl * Interface to /dev/xen/gntdev.
5e87eaf040ab639e94ed0a58ff0eac68d1d38fb0aEd Heyl *
6e87eaf040ab639e94ed0a58ff0eac68d1d38fb0aEd Heyl * Copyright (c) 2007, D G Murray
7e87eaf040ab639e94ed0a58ff0eac68d1d38fb0aEd Heyl *
8e87eaf040ab639e94ed0a58ff0eac68d1d38fb0aEd Heyl * This program is free software; you can redistribute it and/or
9e87eaf040ab639e94ed0a58ff0eac68d1d38fb0aEd Heyl * modify it under the terms of the GNU General Public License version 2
10e87eaf040ab639e94ed0a58ff0eac68d1d38fb0aEd Heyl * as published by the Free Software Foundation; or, when distributed
11e87eaf040ab639e94ed0a58ff0eac68d1d38fb0aEd Heyl * separately from the Linux kernel or incorporated into other
12e87eaf040ab639e94ed0a58ff0eac68d1d38fb0aEd Heyl * software packages, subject to the following license:
13e87eaf040ab639e94ed0a58ff0eac68d1d38fb0aEd Heyl *
14e87eaf040ab639e94ed0a58ff0eac68d1d38fb0aEd Heyl * Permission is hereby granted, free of charge, to any person obtaining a copy
15e87eaf040ab639e94ed0a58ff0eac68d1d38fb0aEd Heyl * of this source file (the "Software"), to deal in the Software without
16e87eaf040ab639e94ed0a58ff0eac68d1d38fb0aEd Heyl * restriction, including without limitation the rights to use, copy, modify,
17e87eaf040ab639e94ed0a58ff0eac68d1d38fb0aEd Heyl * merge, publish, distribute, sublicense, and/or sell copies of the Software,
18e87eaf040ab639e94ed0a58ff0eac68d1d38fb0aEd Heyl * and to permit persons to whom the Software is furnished to do so, subject to
19e87eaf040ab639e94ed0a58ff0eac68d1d38fb0aEd Heyl * the following conditions:
20e87eaf040ab639e94ed0a58ff0eac68d1d38fb0aEd Heyl *
21e87eaf040ab639e94ed0a58ff0eac68d1d38fb0aEd Heyl * The above copyright notice and this permission notice shall be included in
22e87eaf040ab639e94ed0a58ff0eac68d1d38fb0aEd Heyl * all copies or substantial portions of the Software.
23e87eaf040ab639e94ed0a58ff0eac68d1d38fb0aEd Heyl *
24e87eaf040ab639e94ed0a58ff0eac68d1d38fb0aEd Heyl * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
25e87eaf040ab639e94ed0a58ff0eac68d1d38fb0aEd Heyl * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
26e87eaf040ab639e94ed0a58ff0eac68d1d38fb0aEd Heyl * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
27e87eaf040ab639e94ed0a58ff0eac68d1d38fb0aEd Heyl * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
28e87eaf040ab639e94ed0a58ff0eac68d1d38fb0aEd Heyl * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
29e87eaf040ab639e94ed0a58ff0eac68d1d38fb0aEd Heyl * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
30e87eaf040ab639e94ed0a58ff0eac68d1d38fb0aEd Heyl * IN THE SOFTWARE.
31e87eaf040ab639e94ed0a58ff0eac68d1d38fb0aEd Heyl */
32e87eaf040ab639e94ed0a58ff0eac68d1d38fb0aEd Heyl
33e87eaf040ab639e94ed0a58ff0eac68d1d38fb0aEd Heyl#ifndef __LINUX_PUBLIC_GNTDEV_H__
34e87eaf040ab639e94ed0a58ff0eac68d1d38fb0aEd Heyl#define __LINUX_PUBLIC_GNTDEV_H__
35e87eaf040ab639e94ed0a58ff0eac68d1d38fb0aEd Heyl
36e87eaf040ab639e94ed0a58ff0eac68d1d38fb0aEd Heylstruct ioctl_gntdev_grant_ref {
37e87eaf040ab639e94ed0a58ff0eac68d1d38fb0aEd Heyl	/* The domain ID of the grant to be mapped. */
38e87eaf040ab639e94ed0a58ff0eac68d1d38fb0aEd Heyl	uint32_t domid;
39e87eaf040ab639e94ed0a58ff0eac68d1d38fb0aEd Heyl	/* The grant reference of the grant to be mapped. */
40e87eaf040ab639e94ed0a58ff0eac68d1d38fb0aEd Heyl	uint32_t ref;
41e87eaf040ab639e94ed0a58ff0eac68d1d38fb0aEd Heyl};
42e87eaf040ab639e94ed0a58ff0eac68d1d38fb0aEd Heyl
43e87eaf040ab639e94ed0a58ff0eac68d1d38fb0aEd Heyl/*
44e87eaf040ab639e94ed0a58ff0eac68d1d38fb0aEd Heyl * Inserts the grant references into the mapping table of an instance
45e87eaf040ab639e94ed0a58ff0eac68d1d38fb0aEd Heyl * of gntdev. N.B. This does not perform the mapping, which is deferred
46e87eaf040ab639e94ed0a58ff0eac68d1d38fb0aEd Heyl * until mmap() is called with @index as the offset.
47e87eaf040ab639e94ed0a58ff0eac68d1d38fb0aEd Heyl */
48e87eaf040ab639e94ed0a58ff0eac68d1d38fb0aEd Heyl#define IOCTL_GNTDEV_MAP_GRANT_REF \
49e87eaf040ab639e94ed0a58ff0eac68d1d38fb0aEd Heyl_IOC(_IOC_NONE, 'G', 0, sizeof(struct ioctl_gntdev_map_grant_ref))
50e87eaf040ab639e94ed0a58ff0eac68d1d38fb0aEd Heylstruct ioctl_gntdev_map_grant_ref {
51e87eaf040ab639e94ed0a58ff0eac68d1d38fb0aEd Heyl	/* IN parameters */
52e87eaf040ab639e94ed0a58ff0eac68d1d38fb0aEd Heyl	/* The number of grants to be mapped. */
53e87eaf040ab639e94ed0a58ff0eac68d1d38fb0aEd Heyl	uint32_t count;
54e87eaf040ab639e94ed0a58ff0eac68d1d38fb0aEd Heyl	uint32_t pad;
55e87eaf040ab639e94ed0a58ff0eac68d1d38fb0aEd Heyl	/* OUT parameters */
56e87eaf040ab639e94ed0a58ff0eac68d1d38fb0aEd Heyl	/* The offset to be used on a subsequent call to mmap(). */
57e87eaf040ab639e94ed0a58ff0eac68d1d38fb0aEd Heyl	uint64_t index;
58e87eaf040ab639e94ed0a58ff0eac68d1d38fb0aEd Heyl	/* Variable IN parameter. */
59e87eaf040ab639e94ed0a58ff0eac68d1d38fb0aEd Heyl	/* Array of grant references, of size @count. */
60e87eaf040ab639e94ed0a58ff0eac68d1d38fb0aEd Heyl	struct ioctl_gntdev_grant_ref refs[1];
61e87eaf040ab639e94ed0a58ff0eac68d1d38fb0aEd Heyl};
62e87eaf040ab639e94ed0a58ff0eac68d1d38fb0aEd Heyl
63e87eaf040ab639e94ed0a58ff0eac68d1d38fb0aEd Heyl/*
64e87eaf040ab639e94ed0a58ff0eac68d1d38fb0aEd Heyl * Removes the grant references from the mapping table of an instance of
65e87eaf040ab639e94ed0a58ff0eac68d1d38fb0aEd Heyl * of gntdev. N.B. munmap() must be called on the relevant virtual address(es)
66e87eaf040ab639e94ed0a58ff0eac68d1d38fb0aEd Heyl * before this ioctl is called, or an error will result.
67e87eaf040ab639e94ed0a58ff0eac68d1d38fb0aEd Heyl */
68e87eaf040ab639e94ed0a58ff0eac68d1d38fb0aEd Heyl#define IOCTL_GNTDEV_UNMAP_GRANT_REF \
69e87eaf040ab639e94ed0a58ff0eac68d1d38fb0aEd Heyl_IOC(_IOC_NONE, 'G', 1, sizeof(struct ioctl_gntdev_unmap_grant_ref))
70e87eaf040ab639e94ed0a58ff0eac68d1d38fb0aEd Heylstruct ioctl_gntdev_unmap_grant_ref {
71e87eaf040ab639e94ed0a58ff0eac68d1d38fb0aEd Heyl	/* IN parameters */
72e87eaf040ab639e94ed0a58ff0eac68d1d38fb0aEd Heyl	/* The offset was returned by the corresponding map operation. */
73e87eaf040ab639e94ed0a58ff0eac68d1d38fb0aEd Heyl	uint64_t index;
74e87eaf040ab639e94ed0a58ff0eac68d1d38fb0aEd Heyl	/* The number of pages to be unmapped. */
75e87eaf040ab639e94ed0a58ff0eac68d1d38fb0aEd Heyl	uint32_t count;
76e87eaf040ab639e94ed0a58ff0eac68d1d38fb0aEd Heyl	uint32_t pad;
77e87eaf040ab639e94ed0a58ff0eac68d1d38fb0aEd Heyl};
78e87eaf040ab639e94ed0a58ff0eac68d1d38fb0aEd Heyl
79e87eaf040ab639e94ed0a58ff0eac68d1d38fb0aEd Heyl/*
80e87eaf040ab639e94ed0a58ff0eac68d1d38fb0aEd Heyl * Returns the offset in the driver's address space that corresponds
81e87eaf040ab639e94ed0a58ff0eac68d1d38fb0aEd Heyl * to @vaddr. This can be used to perform a munmap(), followed by an
82e87eaf040ab639e94ed0a58ff0eac68d1d38fb0aEd Heyl * UNMAP_GRANT_REF ioctl, where no state about the offset is retained by
83e87eaf040ab639e94ed0a58ff0eac68d1d38fb0aEd Heyl * the caller. The number of pages that were allocated at the same time as
84e87eaf040ab639e94ed0a58ff0eac68d1d38fb0aEd Heyl * @vaddr is returned in @count.
85e87eaf040ab639e94ed0a58ff0eac68d1d38fb0aEd Heyl *
86e87eaf040ab639e94ed0a58ff0eac68d1d38fb0aEd Heyl * N.B. Where more than one page has been mapped into a contiguous range, the
87e87eaf040ab639e94ed0a58ff0eac68d1d38fb0aEd Heyl *      supplied @vaddr must correspond to the start of the range; otherwise
88e87eaf040ab639e94ed0a58ff0eac68d1d38fb0aEd Heyl *      an error will result. It is only possible to munmap() the entire
89e87eaf040ab639e94ed0a58ff0eac68d1d38fb0aEd Heyl *      contiguously-allocated range at once, and not any subrange thereof.
90e87eaf040ab639e94ed0a58ff0eac68d1d38fb0aEd Heyl */
91e87eaf040ab639e94ed0a58ff0eac68d1d38fb0aEd Heyl#define IOCTL_GNTDEV_GET_OFFSET_FOR_VADDR \
92e87eaf040ab639e94ed0a58ff0eac68d1d38fb0aEd Heyl_IOC(_IOC_NONE, 'G', 2, sizeof(struct ioctl_gntdev_get_offset_for_vaddr))
93e87eaf040ab639e94ed0a58ff0eac68d1d38fb0aEd Heylstruct ioctl_gntdev_get_offset_for_vaddr {
94e87eaf040ab639e94ed0a58ff0eac68d1d38fb0aEd Heyl	/* IN parameters */
95e87eaf040ab639e94ed0a58ff0eac68d1d38fb0aEd Heyl	/* The virtual address of the first mapped page in a range. */
96e87eaf040ab639e94ed0a58ff0eac68d1d38fb0aEd Heyl	uint64_t vaddr;
97e87eaf040ab639e94ed0a58ff0eac68d1d38fb0aEd Heyl	/* OUT parameters */
98e87eaf040ab639e94ed0a58ff0eac68d1d38fb0aEd Heyl	/* The offset that was used in the initial mmap() operation. */
99e87eaf040ab639e94ed0a58ff0eac68d1d38fb0aEd Heyl	uint64_t offset;
100e87eaf040ab639e94ed0a58ff0eac68d1d38fb0aEd Heyl	/* The number of pages mapped in the VM area that begins at @vaddr. */
101e87eaf040ab639e94ed0a58ff0eac68d1d38fb0aEd Heyl	uint32_t count;
102e87eaf040ab639e94ed0a58ff0eac68d1d38fb0aEd Heyl	uint32_t pad;
103e87eaf040ab639e94ed0a58ff0eac68d1d38fb0aEd Heyl};
104e87eaf040ab639e94ed0a58ff0eac68d1d38fb0aEd Heyl
105e87eaf040ab639e94ed0a58ff0eac68d1d38fb0aEd Heyl/*
106e87eaf040ab639e94ed0a58ff0eac68d1d38fb0aEd Heyl * Sets the maximum number of grants that may mapped at once by this gntdev
107e87eaf040ab639e94ed0a58ff0eac68d1d38fb0aEd Heyl * instance.
108e87eaf040ab639e94ed0a58ff0eac68d1d38fb0aEd Heyl *
109e87eaf040ab639e94ed0a58ff0eac68d1d38fb0aEd Heyl * N.B. This must be called before any other ioctl is performed on the device.
110e87eaf040ab639e94ed0a58ff0eac68d1d38fb0aEd Heyl */
111e87eaf040ab639e94ed0a58ff0eac68d1d38fb0aEd Heyl#define IOCTL_GNTDEV_SET_MAX_GRANTS \
112e87eaf040ab639e94ed0a58ff0eac68d1d38fb0aEd Heyl_IOC(_IOC_NONE, 'G', 3, sizeof(struct ioctl_gntdev_set_max_grants))
113e87eaf040ab639e94ed0a58ff0eac68d1d38fb0aEd Heylstruct ioctl_gntdev_set_max_grants {
114e87eaf040ab639e94ed0a58ff0eac68d1d38fb0aEd Heyl	/* IN parameter */
115e87eaf040ab639e94ed0a58ff0eac68d1d38fb0aEd Heyl	/* The maximum number of grants that may be mapped at once. */
116e87eaf040ab639e94ed0a58ff0eac68d1d38fb0aEd Heyl	uint32_t count;
117e87eaf040ab639e94ed0a58ff0eac68d1d38fb0aEd Heyl};
118e87eaf040ab639e94ed0a58ff0eac68d1d38fb0aEd Heyl
119e87eaf040ab639e94ed0a58ff0eac68d1d38fb0aEd Heyl/*
120e87eaf040ab639e94ed0a58ff0eac68d1d38fb0aEd Heyl * Sets up an unmap notification within the page, so that the other side can do
121e87eaf040ab639e94ed0a58ff0eac68d1d38fb0aEd Heyl * cleanup if this side crashes. Required to implement cross-domain robust
122e87eaf040ab639e94ed0a58ff0eac68d1d38fb0aEd Heyl * mutexes or close notification on communication channels.
123e87eaf040ab639e94ed0a58ff0eac68d1d38fb0aEd Heyl *
124e87eaf040ab639e94ed0a58ff0eac68d1d38fb0aEd Heyl * Each mapped page only supports one notification; multiple calls referring to
125e87eaf040ab639e94ed0a58ff0eac68d1d38fb0aEd Heyl * the same page overwrite the previous notification. You must clear the
126e87eaf040ab639e94ed0a58ff0eac68d1d38fb0aEd Heyl * notification prior to the IOCTL_GNTALLOC_DEALLOC_GREF if you do not want it
127e87eaf040ab639e94ed0a58ff0eac68d1d38fb0aEd Heyl * to occur.
128e87eaf040ab639e94ed0a58ff0eac68d1d38fb0aEd Heyl */
129e87eaf040ab639e94ed0a58ff0eac68d1d38fb0aEd Heyl#define IOCTL_GNTDEV_SET_UNMAP_NOTIFY \
130e87eaf040ab639e94ed0a58ff0eac68d1d38fb0aEd Heyl_IOC(_IOC_NONE, 'G', 7, sizeof(struct ioctl_gntdev_unmap_notify))
131e87eaf040ab639e94ed0a58ff0eac68d1d38fb0aEd Heylstruct ioctl_gntdev_unmap_notify {
132e87eaf040ab639e94ed0a58ff0eac68d1d38fb0aEd Heyl	/* IN parameters */
133e87eaf040ab639e94ed0a58ff0eac68d1d38fb0aEd Heyl	/* Offset in the file descriptor for a byte within the page (same as
134e87eaf040ab639e94ed0a58ff0eac68d1d38fb0aEd Heyl	 * used in mmap). If using UNMAP_NOTIFY_CLEAR_BYTE, this is the byte to
135e87eaf040ab639e94ed0a58ff0eac68d1d38fb0aEd Heyl	 * be cleared. Otherwise, it can be any byte in the page whose
136e87eaf040ab639e94ed0a58ff0eac68d1d38fb0aEd Heyl	 * notification we are adjusting.
137e87eaf040ab639e94ed0a58ff0eac68d1d38fb0aEd Heyl	 */
138e87eaf040ab639e94ed0a58ff0eac68d1d38fb0aEd Heyl	uint64_t index;
139e87eaf040ab639e94ed0a58ff0eac68d1d38fb0aEd Heyl	/* Action(s) to take on unmap */
140e87eaf040ab639e94ed0a58ff0eac68d1d38fb0aEd Heyl	uint32_t action;
141e87eaf040ab639e94ed0a58ff0eac68d1d38fb0aEd Heyl	/* Event channel to notify */
142e87eaf040ab639e94ed0a58ff0eac68d1d38fb0aEd Heyl	uint32_t event_channel_port;
143e87eaf040ab639e94ed0a58ff0eac68d1d38fb0aEd Heyl};
144e87eaf040ab639e94ed0a58ff0eac68d1d38fb0aEd Heyl
145e87eaf040ab639e94ed0a58ff0eac68d1d38fb0aEd Heyl/* Clear (set to zero) the byte specified by index */
146e87eaf040ab639e94ed0a58ff0eac68d1d38fb0aEd Heyl#define UNMAP_NOTIFY_CLEAR_BYTE 0x1
147e87eaf040ab639e94ed0a58ff0eac68d1d38fb0aEd Heyl/* Send an interrupt on the indicated event channel */
148e87eaf040ab639e94ed0a58ff0eac68d1d38fb0aEd Heyl#define UNMAP_NOTIFY_SEND_EVENT 0x2
149e87eaf040ab639e94ed0a58ff0eac68d1d38fb0aEd Heyl
150e87eaf040ab639e94ed0a58ff0eac68d1d38fb0aEd Heyl#endif /* __LINUX_PUBLIC_GNTDEV_H__ */
151