gntdev.h 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. /* SPDX-License-Identifier: ((GPL-2.0 WITH Linux-syscall-note) OR MIT) */
  2. /******************************************************************************
  3. * gntdev.h
  4. *
  5. * Interface to /dev/xen/gntdev.
  6. *
  7. * Copyright (c) 2007, D G Murray
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public License version 2
  11. * as published by the Free Software Foundation; or, when distributed
  12. * separately from the Linux kernel or incorporated into other
  13. * software packages, subject to the following license:
  14. *
  15. * Permission is hereby granted, free of charge, to any person obtaining a copy
  16. * of this source file (the "Software"), to deal in the Software without
  17. * restriction, including without limitation the rights to use, copy, modify,
  18. * merge, publish, distribute, sublicense, and/or sell copies of the Software,
  19. * and to permit persons to whom the Software is furnished to do so, subject to
  20. * the following conditions:
  21. *
  22. * The above copyright notice and this permission notice shall be included in
  23. * all copies or substantial portions of the Software.
  24. *
  25. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  26. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  27. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  28. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  29. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  30. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  31. * IN THE SOFTWARE.
  32. */
  33. #ifndef __LINUX_PUBLIC_GNTDEV_H__
  34. #define __LINUX_PUBLIC_GNTDEV_H__
  35. #include <linux/types.h>
  36. struct ioctl_gntdev_grant_ref {
  37. /* The domain ID of the grant to be mapped. */
  38. __u32 domid;
  39. /* The grant reference of the grant to be mapped. */
  40. __u32 ref;
  41. };
  42. /*
  43. * Inserts the grant references into the mapping table of an instance
  44. * of gntdev. N.B. This does not perform the mapping, which is deferred
  45. * until mmap() is called with @index as the offset.
  46. */
  47. #define IOCTL_GNTDEV_MAP_GRANT_REF \
  48. _IOC(_IOC_NONE, 'G', 0, sizeof(struct ioctl_gntdev_map_grant_ref))
  49. struct ioctl_gntdev_map_grant_ref {
  50. /* IN parameters */
  51. /* The number of grants to be mapped. */
  52. __u32 count;
  53. __u32 pad;
  54. /* OUT parameters */
  55. /* The offset to be used on a subsequent call to mmap(). */
  56. __u64 index;
  57. /* Variable IN parameter. */
  58. /* Array of grant references, of size @count. */
  59. struct ioctl_gntdev_grant_ref refs[1];
  60. };
  61. /*
  62. * Removes the grant references from the mapping table of an instance of
  63. * of gntdev. N.B. munmap() must be called on the relevant virtual address(es)
  64. * before this ioctl is called, or an error will result.
  65. */
  66. #define IOCTL_GNTDEV_UNMAP_GRANT_REF \
  67. _IOC(_IOC_NONE, 'G', 1, sizeof(struct ioctl_gntdev_unmap_grant_ref))
  68. struct ioctl_gntdev_unmap_grant_ref {
  69. /* IN parameters */
  70. /* The offset was returned by the corresponding map operation. */
  71. __u64 index;
  72. /* The number of pages to be unmapped. */
  73. __u32 count;
  74. __u32 pad;
  75. };
  76. /*
  77. * Returns the offset in the driver's address space that corresponds
  78. * to @vaddr. This can be used to perform a munmap(), followed by an
  79. * UNMAP_GRANT_REF ioctl, where no state about the offset is retained by
  80. * the caller. The number of pages that were allocated at the same time as
  81. * @vaddr is returned in @count.
  82. *
  83. * N.B. Where more than one page has been mapped into a contiguous range, the
  84. * supplied @vaddr must correspond to the start of the range; otherwise
  85. * an error will result. It is only possible to munmap() the entire
  86. * contiguously-allocated range at once, and not any subrange thereof.
  87. */
  88. #define IOCTL_GNTDEV_GET_OFFSET_FOR_VADDR \
  89. _IOC(_IOC_NONE, 'G', 2, sizeof(struct ioctl_gntdev_get_offset_for_vaddr))
  90. struct ioctl_gntdev_get_offset_for_vaddr {
  91. /* IN parameters */
  92. /* The virtual address of the first mapped page in a range. */
  93. __u64 vaddr;
  94. /* OUT parameters */
  95. /* The offset that was used in the initial mmap() operation. */
  96. __u64 offset;
  97. /* The number of pages mapped in the VM area that begins at @vaddr. */
  98. __u32 count;
  99. __u32 pad;
  100. };
  101. /*
  102. * Sets the maximum number of grants that may mapped at once by this gntdev
  103. * instance.
  104. *
  105. * N.B. This must be called before any other ioctl is performed on the device.
  106. */
  107. #define IOCTL_GNTDEV_SET_MAX_GRANTS \
  108. _IOC(_IOC_NONE, 'G', 3, sizeof(struct ioctl_gntdev_set_max_grants))
  109. struct ioctl_gntdev_set_max_grants {
  110. /* IN parameter */
  111. /* The maximum number of grants that may be mapped at once. */
  112. __u32 count;
  113. };
  114. /*
  115. * Sets up an unmap notification within the page, so that the other side can do
  116. * cleanup if this side crashes. Required to implement cross-domain robust
  117. * mutexes or close notification on communication channels.
  118. *
  119. * Each mapped page only supports one notification; multiple calls referring to
  120. * the same page overwrite the previous notification. You must clear the
  121. * notification prior to the IOCTL_GNTALLOC_DEALLOC_GREF if you do not want it
  122. * to occur.
  123. */
  124. #define IOCTL_GNTDEV_SET_UNMAP_NOTIFY \
  125. _IOC(_IOC_NONE, 'G', 7, sizeof(struct ioctl_gntdev_unmap_notify))
  126. struct ioctl_gntdev_unmap_notify {
  127. /* IN parameters */
  128. /* Offset in the file descriptor for a byte within the page (same as
  129. * used in mmap). If using UNMAP_NOTIFY_CLEAR_BYTE, this is the byte to
  130. * be cleared. Otherwise, it can be any byte in the page whose
  131. * notification we are adjusting.
  132. */
  133. __u64 index;
  134. /* Action(s) to take on unmap */
  135. __u32 action;
  136. /* Event channel to notify */
  137. __u32 event_channel_port;
  138. };
  139. struct gntdev_grant_copy_segment {
  140. union {
  141. void __user *virt;
  142. struct {
  143. grant_ref_t ref;
  144. __u16 offset;
  145. domid_t domid;
  146. } foreign;
  147. } source, dest;
  148. __u16 len;
  149. __u16 flags; /* GNTCOPY_* */
  150. __s16 status; /* GNTST_* */
  151. };
  152. /*
  153. * Copy between grant references and local buffers.
  154. *
  155. * The copy is split into @count @segments, each of which can copy
  156. * to/from one grant reference.
  157. *
  158. * Each segment is similar to struct gnttab_copy in the hypervisor ABI
  159. * except the local buffer is specified using a virtual address
  160. * (instead of a GFN and offset).
  161. *
  162. * The local buffer may cross a Xen page boundary -- the driver will
  163. * split segments into multiple ops if required.
  164. *
  165. * Returns 0 if all segments have been processed and @status in each
  166. * segment is valid. Note that one or more segments may have failed
  167. * (status != GNTST_okay).
  168. *
  169. * If the driver had to split a segment into two or more ops, @status
  170. * includes the status of the first failed op for that segment (or
  171. * GNTST_okay if all ops were successful).
  172. *
  173. * If -1 is returned, the status of all segments is undefined.
  174. *
  175. * EINVAL: A segment has local buffers for both source and
  176. * destination.
  177. * EINVAL: A segment crosses the boundary of a foreign page.
  178. * EFAULT: A segment's local buffer is not accessible.
  179. */
  180. #define IOCTL_GNTDEV_GRANT_COPY \
  181. _IOC(_IOC_NONE, 'G', 8, sizeof(struct ioctl_gntdev_grant_copy))
  182. struct ioctl_gntdev_grant_copy {
  183. unsigned int count;
  184. struct gntdev_grant_copy_segment __user *segments;
  185. };
  186. /* Clear (set to zero) the byte specified by index */
  187. #define UNMAP_NOTIFY_CLEAR_BYTE 0x1
  188. /* Send an interrupt on the indicated event channel */
  189. #define UNMAP_NOTIFY_SEND_EVENT 0x2
  190. #endif /* __LINUX_PUBLIC_GNTDEV_H__ */