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