xref: /openbmc/linux/include/uapi/xen/gntdev.h (revision a4cdb556cae05cd3e7b602b3a44c01420c4e2258)
1564eb714SDavid Vrabel /******************************************************************************
2564eb714SDavid Vrabel  * gntdev.h
3564eb714SDavid Vrabel  *
4564eb714SDavid Vrabel  * Interface to /dev/xen/gntdev.
5564eb714SDavid Vrabel  *
6564eb714SDavid Vrabel  * Copyright (c) 2007, D G Murray
7564eb714SDavid Vrabel  *
8564eb714SDavid Vrabel  * This program is free software; you can redistribute it and/or
9564eb714SDavid Vrabel  * modify it under the terms of the GNU General Public License version 2
10564eb714SDavid Vrabel  * as published by the Free Software Foundation; or, when distributed
11564eb714SDavid Vrabel  * separately from the Linux kernel or incorporated into other
12564eb714SDavid Vrabel  * software packages, subject to the following license:
13564eb714SDavid Vrabel  *
14564eb714SDavid Vrabel  * Permission is hereby granted, free of charge, to any person obtaining a copy
15564eb714SDavid Vrabel  * of this source file (the "Software"), to deal in the Software without
16564eb714SDavid Vrabel  * restriction, including without limitation the rights to use, copy, modify,
17564eb714SDavid Vrabel  * merge, publish, distribute, sublicense, and/or sell copies of the Software,
18564eb714SDavid Vrabel  * and to permit persons to whom the Software is furnished to do so, subject to
19564eb714SDavid Vrabel  * the following conditions:
20564eb714SDavid Vrabel  *
21564eb714SDavid Vrabel  * The above copyright notice and this permission notice shall be included in
22564eb714SDavid Vrabel  * all copies or substantial portions of the Software.
23564eb714SDavid Vrabel  *
24564eb714SDavid Vrabel  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
25564eb714SDavid Vrabel  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
26564eb714SDavid Vrabel  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
27564eb714SDavid Vrabel  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
28564eb714SDavid Vrabel  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
29564eb714SDavid Vrabel  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
30564eb714SDavid Vrabel  * IN THE SOFTWARE.
31564eb714SDavid Vrabel  */
32564eb714SDavid Vrabel 
33564eb714SDavid Vrabel #ifndef __LINUX_PUBLIC_GNTDEV_H__
34564eb714SDavid Vrabel #define __LINUX_PUBLIC_GNTDEV_H__
35564eb714SDavid Vrabel 
36a36012beSMikko Rapeli #include <linux/types.h>
37a36012beSMikko Rapeli 
38564eb714SDavid Vrabel struct ioctl_gntdev_grant_ref {
39564eb714SDavid Vrabel 	/* The domain ID of the grant to be mapped. */
40a36012beSMikko Rapeli 	__u32 domid;
41564eb714SDavid Vrabel 	/* The grant reference of the grant to be mapped. */
42a36012beSMikko Rapeli 	__u32 ref;
43564eb714SDavid Vrabel };
44564eb714SDavid Vrabel 
45564eb714SDavid Vrabel /*
46564eb714SDavid Vrabel  * Inserts the grant references into the mapping table of an instance
47564eb714SDavid Vrabel  * of gntdev. N.B. This does not perform the mapping, which is deferred
48564eb714SDavid Vrabel  * until mmap() is called with @index as the offset.
49564eb714SDavid Vrabel  */
50564eb714SDavid Vrabel #define IOCTL_GNTDEV_MAP_GRANT_REF \
51564eb714SDavid Vrabel _IOC(_IOC_NONE, 'G', 0, sizeof(struct ioctl_gntdev_map_grant_ref))
52564eb714SDavid Vrabel struct ioctl_gntdev_map_grant_ref {
53564eb714SDavid Vrabel 	/* IN parameters */
54564eb714SDavid Vrabel 	/* The number of grants to be mapped. */
55a36012beSMikko Rapeli 	__u32 count;
56a36012beSMikko Rapeli 	__u32 pad;
57564eb714SDavid Vrabel 	/* OUT parameters */
58564eb714SDavid Vrabel 	/* The offset to be used on a subsequent call to mmap(). */
59a36012beSMikko Rapeli 	__u64 index;
60564eb714SDavid Vrabel 	/* Variable IN parameter. */
61564eb714SDavid Vrabel 	/* Array of grant references, of size @count. */
62564eb714SDavid Vrabel 	struct ioctl_gntdev_grant_ref refs[1];
63564eb714SDavid Vrabel };
64564eb714SDavid Vrabel 
65564eb714SDavid Vrabel /*
66564eb714SDavid Vrabel  * Removes the grant references from the mapping table of an instance of
67564eb714SDavid Vrabel  * of gntdev. N.B. munmap() must be called on the relevant virtual address(es)
68564eb714SDavid Vrabel  * before this ioctl is called, or an error will result.
69564eb714SDavid Vrabel  */
70564eb714SDavid Vrabel #define IOCTL_GNTDEV_UNMAP_GRANT_REF \
71564eb714SDavid Vrabel _IOC(_IOC_NONE, 'G', 1, sizeof(struct ioctl_gntdev_unmap_grant_ref))
72564eb714SDavid Vrabel struct ioctl_gntdev_unmap_grant_ref {
73564eb714SDavid Vrabel 	/* IN parameters */
74564eb714SDavid Vrabel 	/* The offset was returned by the corresponding map operation. */
75a36012beSMikko Rapeli 	__u64 index;
76564eb714SDavid Vrabel 	/* The number of pages to be unmapped. */
77a36012beSMikko Rapeli 	__u32 count;
78a36012beSMikko Rapeli 	__u32 pad;
79564eb714SDavid Vrabel };
80564eb714SDavid Vrabel 
81564eb714SDavid Vrabel /*
82564eb714SDavid Vrabel  * Returns the offset in the driver's address space that corresponds
83564eb714SDavid Vrabel  * to @vaddr. This can be used to perform a munmap(), followed by an
84564eb714SDavid Vrabel  * UNMAP_GRANT_REF ioctl, where no state about the offset is retained by
85564eb714SDavid Vrabel  * the caller. The number of pages that were allocated at the same time as
86564eb714SDavid Vrabel  * @vaddr is returned in @count.
87564eb714SDavid Vrabel  *
88564eb714SDavid Vrabel  * N.B. Where more than one page has been mapped into a contiguous range, the
89564eb714SDavid Vrabel  *      supplied @vaddr must correspond to the start of the range; otherwise
90564eb714SDavid Vrabel  *      an error will result. It is only possible to munmap() the entire
91564eb714SDavid Vrabel  *      contiguously-allocated range at once, and not any subrange thereof.
92564eb714SDavid Vrabel  */
93564eb714SDavid Vrabel #define IOCTL_GNTDEV_GET_OFFSET_FOR_VADDR \
94564eb714SDavid Vrabel _IOC(_IOC_NONE, 'G', 2, sizeof(struct ioctl_gntdev_get_offset_for_vaddr))
95564eb714SDavid Vrabel struct ioctl_gntdev_get_offset_for_vaddr {
96564eb714SDavid Vrabel 	/* IN parameters */
97564eb714SDavid Vrabel 	/* The virtual address of the first mapped page in a range. */
98a36012beSMikko Rapeli 	__u64 vaddr;
99564eb714SDavid Vrabel 	/* OUT parameters */
100564eb714SDavid Vrabel 	/* The offset that was used in the initial mmap() operation. */
101a36012beSMikko Rapeli 	__u64 offset;
102564eb714SDavid Vrabel 	/* The number of pages mapped in the VM area that begins at @vaddr. */
103a36012beSMikko Rapeli 	__u32 count;
104a36012beSMikko Rapeli 	__u32 pad;
105564eb714SDavid Vrabel };
106564eb714SDavid Vrabel 
107564eb714SDavid Vrabel /*
108564eb714SDavid Vrabel  * Sets the maximum number of grants that may mapped at once by this gntdev
109564eb714SDavid Vrabel  * instance.
110564eb714SDavid Vrabel  *
111564eb714SDavid Vrabel  * N.B. This must be called before any other ioctl is performed on the device.
112564eb714SDavid Vrabel  */
113564eb714SDavid Vrabel #define IOCTL_GNTDEV_SET_MAX_GRANTS \
114564eb714SDavid Vrabel _IOC(_IOC_NONE, 'G', 3, sizeof(struct ioctl_gntdev_set_max_grants))
115564eb714SDavid Vrabel struct ioctl_gntdev_set_max_grants {
116564eb714SDavid Vrabel 	/* IN parameter */
117564eb714SDavid Vrabel 	/* The maximum number of grants that may be mapped at once. */
118a36012beSMikko Rapeli 	__u32 count;
119564eb714SDavid Vrabel };
120564eb714SDavid Vrabel 
121564eb714SDavid Vrabel /*
122564eb714SDavid Vrabel  * Sets up an unmap notification within the page, so that the other side can do
123564eb714SDavid Vrabel  * cleanup if this side crashes. Required to implement cross-domain robust
124564eb714SDavid Vrabel  * mutexes or close notification on communication channels.
125564eb714SDavid Vrabel  *
126564eb714SDavid Vrabel  * Each mapped page only supports one notification; multiple calls referring to
127564eb714SDavid Vrabel  * the same page overwrite the previous notification. You must clear the
128564eb714SDavid Vrabel  * notification prior to the IOCTL_GNTALLOC_DEALLOC_GREF if you do not want it
129564eb714SDavid Vrabel  * to occur.
130564eb714SDavid Vrabel  */
131564eb714SDavid Vrabel #define IOCTL_GNTDEV_SET_UNMAP_NOTIFY \
132564eb714SDavid Vrabel _IOC(_IOC_NONE, 'G', 7, sizeof(struct ioctl_gntdev_unmap_notify))
133564eb714SDavid Vrabel struct ioctl_gntdev_unmap_notify {
134564eb714SDavid Vrabel 	/* IN parameters */
135564eb714SDavid Vrabel 	/* Offset in the file descriptor for a byte within the page (same as
136564eb714SDavid Vrabel 	 * used in mmap). If using UNMAP_NOTIFY_CLEAR_BYTE, this is the byte to
137564eb714SDavid Vrabel 	 * be cleared. Otherwise, it can be any byte in the page whose
138564eb714SDavid Vrabel 	 * notification we are adjusting.
139564eb714SDavid Vrabel 	 */
140a36012beSMikko Rapeli 	__u64 index;
141564eb714SDavid Vrabel 	/* Action(s) to take on unmap */
142a36012beSMikko Rapeli 	__u32 action;
143564eb714SDavid Vrabel 	/* Event channel to notify */
144a36012beSMikko Rapeli 	__u32 event_channel_port;
145564eb714SDavid Vrabel };
146564eb714SDavid Vrabel 
147*a4cdb556SDavid Vrabel struct gntdev_grant_copy_segment {
148*a4cdb556SDavid Vrabel 	union {
149*a4cdb556SDavid Vrabel 		void __user *virt;
150*a4cdb556SDavid Vrabel 		struct {
151*a4cdb556SDavid Vrabel 			grant_ref_t ref;
152*a4cdb556SDavid Vrabel 			__u16 offset;
153*a4cdb556SDavid Vrabel 			domid_t domid;
154*a4cdb556SDavid Vrabel 		} foreign;
155*a4cdb556SDavid Vrabel 	} source, dest;
156*a4cdb556SDavid Vrabel 	__u16 len;
157*a4cdb556SDavid Vrabel 
158*a4cdb556SDavid Vrabel 	__u16 flags;  /* GNTCOPY_* */
159*a4cdb556SDavid Vrabel 	__s16 status; /* GNTST_* */
160*a4cdb556SDavid Vrabel };
161*a4cdb556SDavid Vrabel 
162*a4cdb556SDavid Vrabel /*
163*a4cdb556SDavid Vrabel  * Copy between grant references and local buffers.
164*a4cdb556SDavid Vrabel  *
165*a4cdb556SDavid Vrabel  * The copy is split into @count @segments, each of which can copy
166*a4cdb556SDavid Vrabel  * to/from one grant reference.
167*a4cdb556SDavid Vrabel  *
168*a4cdb556SDavid Vrabel  * Each segment is similar to struct gnttab_copy in the hypervisor ABI
169*a4cdb556SDavid Vrabel  * except the local buffer is specified using a virtual address
170*a4cdb556SDavid Vrabel  * (instead of a GFN and offset).
171*a4cdb556SDavid Vrabel  *
172*a4cdb556SDavid Vrabel  * The local buffer may cross a Xen page boundary -- the driver will
173*a4cdb556SDavid Vrabel  * split segments into multiple ops if required.
174*a4cdb556SDavid Vrabel  *
175*a4cdb556SDavid Vrabel  * Returns 0 if all segments have been processed and @status in each
176*a4cdb556SDavid Vrabel  * segment is valid.  Note that one or more segments may have failed
177*a4cdb556SDavid Vrabel  * (status != GNTST_okay).
178*a4cdb556SDavid Vrabel  *
179*a4cdb556SDavid Vrabel  * If the driver had to split a segment into two or more ops, @status
180*a4cdb556SDavid Vrabel  * includes the status of the first failed op for that segment (or
181*a4cdb556SDavid Vrabel  * GNTST_okay if all ops were successful).
182*a4cdb556SDavid Vrabel  *
183*a4cdb556SDavid Vrabel  * If -1 is returned, the status of all segments is undefined.
184*a4cdb556SDavid Vrabel  *
185*a4cdb556SDavid Vrabel  * EINVAL: A segment has local buffers for both source and
186*a4cdb556SDavid Vrabel  *         destination.
187*a4cdb556SDavid Vrabel  * EINVAL: A segment crosses the boundary of a foreign page.
188*a4cdb556SDavid Vrabel  * EFAULT: A segment's local buffer is not accessible.
189*a4cdb556SDavid Vrabel  */
190*a4cdb556SDavid Vrabel #define IOCTL_GNTDEV_GRANT_COPY \
191*a4cdb556SDavid Vrabel 	_IOC(_IOC_NONE, 'G', 8, sizeof(struct ioctl_gntdev_grant_copy))
192*a4cdb556SDavid Vrabel struct ioctl_gntdev_grant_copy {
193*a4cdb556SDavid Vrabel 	unsigned int count;
194*a4cdb556SDavid Vrabel 	struct gntdev_grant_copy_segment __user *segments;
195*a4cdb556SDavid Vrabel };
196*a4cdb556SDavid Vrabel 
197564eb714SDavid Vrabel /* Clear (set to zero) the byte specified by index */
198564eb714SDavid Vrabel #define UNMAP_NOTIFY_CLEAR_BYTE 0x1
199564eb714SDavid Vrabel /* Send an interrupt on the indicated event channel */
200564eb714SDavid Vrabel #define UNMAP_NOTIFY_SEND_EVENT 0x2
201564eb714SDavid Vrabel 
202564eb714SDavid Vrabel #endif /* __LINUX_PUBLIC_GNTDEV_H__ */
203