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