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 36*a36012beSMikko Rapeli #include <linux/types.h> 37*a36012beSMikko Rapeli 38564eb714SDavid Vrabel struct ioctl_gntdev_grant_ref { 39564eb714SDavid Vrabel /* The domain ID of the grant to be mapped. */ 40*a36012beSMikko Rapeli __u32 domid; 41564eb714SDavid Vrabel /* The grant reference of the grant to be mapped. */ 42*a36012beSMikko 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. */ 55*a36012beSMikko Rapeli __u32 count; 56*a36012beSMikko Rapeli __u32 pad; 57564eb714SDavid Vrabel /* OUT parameters */ 58564eb714SDavid Vrabel /* The offset to be used on a subsequent call to mmap(). */ 59*a36012beSMikko 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. */ 75*a36012beSMikko Rapeli __u64 index; 76564eb714SDavid Vrabel /* The number of pages to be unmapped. */ 77*a36012beSMikko Rapeli __u32 count; 78*a36012beSMikko 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. */ 98*a36012beSMikko Rapeli __u64 vaddr; 99564eb714SDavid Vrabel /* OUT parameters */ 100564eb714SDavid Vrabel /* The offset that was used in the initial mmap() operation. */ 101*a36012beSMikko Rapeli __u64 offset; 102564eb714SDavid Vrabel /* The number of pages mapped in the VM area that begins at @vaddr. */ 103*a36012beSMikko Rapeli __u32 count; 104*a36012beSMikko 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. */ 118*a36012beSMikko 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 */ 140*a36012beSMikko Rapeli __u64 index; 141564eb714SDavid Vrabel /* Action(s) to take on unmap */ 142*a36012beSMikko Rapeli __u32 action; 143564eb714SDavid Vrabel /* Event channel to notify */ 144*a36012beSMikko Rapeli __u32 event_channel_port; 145564eb714SDavid Vrabel }; 146564eb714SDavid Vrabel 147564eb714SDavid Vrabel /* Clear (set to zero) the byte specified by index */ 148564eb714SDavid Vrabel #define UNMAP_NOTIFY_CLEAR_BYTE 0x1 149564eb714SDavid Vrabel /* Send an interrupt on the indicated event channel */ 150564eb714SDavid Vrabel #define UNMAP_NOTIFY_SEND_EVENT 0x2 151564eb714SDavid Vrabel 152564eb714SDavid Vrabel #endif /* __LINUX_PUBLIC_GNTDEV_H__ */ 153