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