^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /* SPDX-License-Identifier: ((GPL-2.0 WITH Linux-syscall-note) OR MIT) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /******************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * gntdev.h
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Interface to /dev/xen/gntdev.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * Copyright (c) 2007, D G Murray
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) * Copyright (c) 2018, Oleksandr Andrushchenko, EPAM Systems Inc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) * This program is free software; you can redistribute it and/or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) * modify it under the terms of the GNU General Public License version 2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) * as published by the Free Software Foundation; or, when distributed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) * separately from the Linux kernel or incorporated into other
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) * software packages, subject to the following license:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) * Permission is hereby granted, free of charge, to any person obtaining a copy
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) * of this source file (the "Software"), to deal in the Software without
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) * restriction, including without limitation the rights to use, copy, modify,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) * merge, publish, distribute, sublicense, and/or sell copies of the Software,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) * and to permit persons to whom the Software is furnished to do so, subject to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) * the following conditions:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) * The above copyright notice and this permission notice shall be included in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) * all copies or substantial portions of the Software.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) * IN THE SOFTWARE.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) #ifndef __LINUX_PUBLIC_GNTDEV_H__
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) #define __LINUX_PUBLIC_GNTDEV_H__
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) struct ioctl_gntdev_grant_ref {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) /* The domain ID of the grant to be mapped. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) __u32 domid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) /* The grant reference of the grant to be mapped. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) __u32 ref;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) * Inserts the grant references into the mapping table of an instance
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) * of gntdev. N.B. This does not perform the mapping, which is deferred
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) * until mmap() is called with @index as the offset.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) #define IOCTL_GNTDEV_MAP_GRANT_REF \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) _IOC(_IOC_NONE, 'G', 0, sizeof(struct ioctl_gntdev_map_grant_ref))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) struct ioctl_gntdev_map_grant_ref {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) /* IN parameters */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) /* The number of grants to be mapped. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) __u32 count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) __u32 pad;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) /* OUT parameters */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) /* The offset to be used on a subsequent call to mmap(). */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) __u64 index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) /* Variable IN parameter. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) /* Array of grant references, of size @count. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) struct ioctl_gntdev_grant_ref refs[1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) * Removes the grant references from the mapping table of an instance of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) * gntdev. N.B. munmap() must be called on the relevant virtual address(es)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) * before this ioctl is called, or an error will result.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) #define IOCTL_GNTDEV_UNMAP_GRANT_REF \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) _IOC(_IOC_NONE, 'G', 1, sizeof(struct ioctl_gntdev_unmap_grant_ref))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) struct ioctl_gntdev_unmap_grant_ref {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) /* IN parameters */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) /* The offset was returned by the corresponding map operation. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) __u64 index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) /* The number of pages to be unmapped. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) __u32 count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) __u32 pad;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) * Returns the offset in the driver's address space that corresponds
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) * to @vaddr. This can be used to perform a munmap(), followed by an
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) * UNMAP_GRANT_REF ioctl, where no state about the offset is retained by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) * the caller. The number of pages that were allocated at the same time as
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) * @vaddr is returned in @count.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) * N.B. Where more than one page has been mapped into a contiguous range, the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) * supplied @vaddr must correspond to the start of the range; otherwise
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) * an error will result. It is only possible to munmap() the entire
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) * contiguously-allocated range at once, and not any subrange thereof.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) #define IOCTL_GNTDEV_GET_OFFSET_FOR_VADDR \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) _IOC(_IOC_NONE, 'G', 2, sizeof(struct ioctl_gntdev_get_offset_for_vaddr))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) struct ioctl_gntdev_get_offset_for_vaddr {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) /* IN parameters */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) /* The virtual address of the first mapped page in a range. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) __u64 vaddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) /* OUT parameters */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) /* The offset that was used in the initial mmap() operation. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) __u64 offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) /* The number of pages mapped in the VM area that begins at @vaddr. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) __u32 count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) __u32 pad;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) * Sets the maximum number of grants that may mapped at once by this gntdev
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) * instance.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) * N.B. This must be called before any other ioctl is performed on the device.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) #define IOCTL_GNTDEV_SET_MAX_GRANTS \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) _IOC(_IOC_NONE, 'G', 3, sizeof(struct ioctl_gntdev_set_max_grants))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) struct ioctl_gntdev_set_max_grants {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) /* IN parameter */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) /* The maximum number of grants that may be mapped at once. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) __u32 count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) * Sets up an unmap notification within the page, so that the other side can do
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) * cleanup if this side crashes. Required to implement cross-domain robust
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) * mutexes or close notification on communication channels.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) * Each mapped page only supports one notification; multiple calls referring to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) * the same page overwrite the previous notification. You must clear the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) * notification prior to the IOCTL_GNTALLOC_DEALLOC_GREF if you do not want it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) * to occur.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) #define IOCTL_GNTDEV_SET_UNMAP_NOTIFY \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) _IOC(_IOC_NONE, 'G', 7, sizeof(struct ioctl_gntdev_unmap_notify))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) struct ioctl_gntdev_unmap_notify {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) /* IN parameters */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) /* Offset in the file descriptor for a byte within the page (same as
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) * used in mmap). If using UNMAP_NOTIFY_CLEAR_BYTE, this is the byte to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) * be cleared. Otherwise, it can be any byte in the page whose
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) * notification we are adjusting.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) __u64 index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) /* Action(s) to take on unmap */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) __u32 action;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) /* Event channel to notify */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) __u32 event_channel_port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) struct gntdev_grant_copy_segment {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) union {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) void __user *virt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) struct {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) grant_ref_t ref;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) __u16 offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) domid_t domid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) } foreign;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) } source, dest;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) __u16 len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) __u16 flags; /* GNTCOPY_* */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) __s16 status; /* GNTST_* */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) * Copy between grant references and local buffers.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) * The copy is split into @count @segments, each of which can copy
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) * to/from one grant reference.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) * Each segment is similar to struct gnttab_copy in the hypervisor ABI
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) * except the local buffer is specified using a virtual address
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) * (instead of a GFN and offset).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) * The local buffer may cross a Xen page boundary -- the driver will
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) * split segments into multiple ops if required.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) * Returns 0 if all segments have been processed and @status in each
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) * segment is valid. Note that one or more segments may have failed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) * (status != GNTST_okay).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) * If the driver had to split a segment into two or more ops, @status
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) * includes the status of the first failed op for that segment (or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) * GNTST_okay if all ops were successful).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) * If -1 is returned, the status of all segments is undefined.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) * EINVAL: A segment has local buffers for both source and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) * destination.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) * EINVAL: A segment crosses the boundary of a foreign page.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) * EFAULT: A segment's local buffer is not accessible.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) #define IOCTL_GNTDEV_GRANT_COPY \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) _IOC(_IOC_NONE, 'G', 8, sizeof(struct ioctl_gntdev_grant_copy))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) struct ioctl_gntdev_grant_copy {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) unsigned int count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) struct gntdev_grant_copy_segment __user *segments;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) /* Clear (set to zero) the byte specified by index */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) #define UNMAP_NOTIFY_CLEAR_BYTE 0x1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) /* Send an interrupt on the indicated event channel */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) #define UNMAP_NOTIFY_SEND_EVENT 0x2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) * Flags to be used while requesting memory mapping's backing storage
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) * to be allocated with DMA API.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) * The buffer is backed with memory allocated with dma_alloc_wc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) #define GNTDEV_DMA_FLAG_WC (1 << 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) * The buffer is backed with memory allocated with dma_alloc_coherent.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) #define GNTDEV_DMA_FLAG_COHERENT (1 << 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) * Create a dma-buf [1] from grant references @refs of count @count provided
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) * by the foreign domain @domid with flags @flags.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) * By default dma-buf is backed by system memory pages, but by providing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) * one of the GNTDEV_DMA_FLAG_XXX flags it can also be created as
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) * a DMA write-combine or coherent buffer, e.g. allocated with dma_alloc_wc/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) * dma_alloc_coherent.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) * Returns 0 if dma-buf was successfully created and the corresponding
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) * dma-buf's file descriptor is returned in @fd.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) * [1] Documentation/driver-api/dma-buf.rst
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) #define IOCTL_GNTDEV_DMABUF_EXP_FROM_REFS \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) _IOC(_IOC_NONE, 'G', 9, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) sizeof(struct ioctl_gntdev_dmabuf_exp_from_refs))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) struct ioctl_gntdev_dmabuf_exp_from_refs {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) /* IN parameters. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) /* Specific options for this dma-buf: see GNTDEV_DMA_FLAG_XXX. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) __u32 flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) /* Number of grant references in @refs array. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) __u32 count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) /* OUT parameters. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) /* File descriptor of the dma-buf. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) __u32 fd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) /* The domain ID of the grant references to be mapped. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) __u32 domid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) /* Variable IN parameter. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) /* Array of grant references of size @count. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) __u32 refs[1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) * This will block until the dma-buf with the file descriptor @fd is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) * released. This is only valid for buffers created with
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) * IOCTL_GNTDEV_DMABUF_EXP_FROM_REFS.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) * If within @wait_to_ms milliseconds the buffer is not released
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) * then -ETIMEDOUT error is returned.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) * If the buffer with the file descriptor @fd does not exist or has already
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) * been released, then -ENOENT is returned. For valid file descriptors
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) * this must not be treated as error.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) #define IOCTL_GNTDEV_DMABUF_EXP_WAIT_RELEASED \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) _IOC(_IOC_NONE, 'G', 10, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) sizeof(struct ioctl_gntdev_dmabuf_exp_wait_released))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) struct ioctl_gntdev_dmabuf_exp_wait_released {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) /* IN parameters */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) __u32 fd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) __u32 wait_to_ms;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) * Import a dma-buf with file descriptor @fd and export granted references
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) * to the pages of that dma-buf into array @refs of size @count.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) #define IOCTL_GNTDEV_DMABUF_IMP_TO_REFS \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) _IOC(_IOC_NONE, 'G', 11, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) sizeof(struct ioctl_gntdev_dmabuf_imp_to_refs))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) struct ioctl_gntdev_dmabuf_imp_to_refs {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) /* IN parameters. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) /* File descriptor of the dma-buf. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) __u32 fd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) /* Number of grant references in @refs array. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) __u32 count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) /* The domain ID for which references to be granted. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) __u32 domid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) /* Reserved - must be zero. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) __u32 reserved;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) /* OUT parameters. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) /* Array of grant references of size @count. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) __u32 refs[1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) * This will close all references to the imported buffer with file descriptor
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) * @fd, so it can be released by the owner. This is only valid for buffers
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) * created with IOCTL_GNTDEV_DMABUF_IMP_TO_REFS.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) #define IOCTL_GNTDEV_DMABUF_IMP_RELEASE \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) _IOC(_IOC_NONE, 'G', 12, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) sizeof(struct ioctl_gntdev_dmabuf_imp_release))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) struct ioctl_gntdev_dmabuf_imp_release {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) /* IN parameters */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) __u32 fd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) __u32 reserved;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) #endif /* __LINUX_PUBLIC_GNTDEV_H__ */