gntdev.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. /******************************************************************************
  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. #ifndef __LINUX_PUBLIC_GNTDEV_H__
  33. #define __LINUX_PUBLIC_GNTDEV_H__
  34. #include <linux/types.h>
  35. struct ioctl_gntdev_grant_ref {
  36. /* The domain ID of the grant to be mapped. */
  37. __u32 domid;
  38. /* The grant reference of the grant to be mapped. */
  39. __u32 ref;
  40. };
  41. /*
  42. * Inserts the grant references into the mapping table of an instance
  43. * of gntdev. N.B. This does not perform the mapping, which is deferred
  44. * until mmap() is called with @index as the offset.
  45. */
  46. #define IOCTL_GNTDEV_MAP_GRANT_REF \
  47. _IOC(_IOC_NONE, 'G', 0, sizeof(struct ioctl_gntdev_map_grant_ref))
  48. struct ioctl_gntdev_map_grant_ref {
  49. /* IN parameters */
  50. /* The number of grants to be mapped. */
  51. __u32 count;
  52. __u32 pad;
  53. /* OUT parameters */
  54. /* The offset to be used on a subsequent call to mmap(). */
  55. __u64 index;
  56. /* Variable IN parameter. */
  57. /* Array of grant references, of size @count. */
  58. struct ioctl_gntdev_grant_ref refs[1];
  59. };
  60. /*
  61. * Removes the grant references from the mapping table of an instance of
  62. * of gntdev. N.B. munmap() must be called on the relevant virtual address(es)
  63. * before this ioctl is called, or an error will result.
  64. */
  65. #define IOCTL_GNTDEV_UNMAP_GRANT_REF \
  66. _IOC(_IOC_NONE, 'G', 1, sizeof(struct ioctl_gntdev_unmap_grant_ref))
  67. struct ioctl_gntdev_unmap_grant_ref {
  68. /* IN parameters */
  69. /* The offset was returned by the corresponding map operation. */
  70. __u64 index;
  71. /* The number of pages to be unmapped. */
  72. __u32 count;
  73. __u32 pad;
  74. };
  75. /*
  76. * Returns the offset in the driver's address space that corresponds
  77. * to @vaddr. This can be used to perform a munmap(), followed by an
  78. * UNMAP_GRANT_REF ioctl, where no state about the offset is retained by
  79. * the caller. The number of pages that were allocated at the same time as
  80. * @vaddr is returned in @count.
  81. *
  82. * N.B. Where more than one page has been mapped into a contiguous range, the
  83. * supplied @vaddr must correspond to the start of the range; otherwise
  84. * an error will result. It is only possible to munmap() the entire
  85. * contiguously-allocated range at once, and not any subrange thereof.
  86. */
  87. #define IOCTL_GNTDEV_GET_OFFSET_FOR_VADDR \
  88. _IOC(_IOC_NONE, 'G', 2, sizeof(struct ioctl_gntdev_get_offset_for_vaddr))
  89. struct ioctl_gntdev_get_offset_for_vaddr {
  90. /* IN parameters */
  91. /* The virtual address of the first mapped page in a range. */
  92. __u64 vaddr;
  93. /* OUT parameters */
  94. /* The offset that was used in the initial mmap() operation. */
  95. __u64 offset;
  96. /* The number of pages mapped in the VM area that begins at @vaddr. */
  97. __u32 count;
  98. __u32 pad;
  99. };
  100. /*
  101. * Sets the maximum number of grants that may mapped at once by this gntdev
  102. * instance.
  103. *
  104. * N.B. This must be called before any other ioctl is performed on the device.
  105. */
  106. #define IOCTL_GNTDEV_SET_MAX_GRANTS \
  107. _IOC(_IOC_NONE, 'G', 3, sizeof(struct ioctl_gntdev_set_max_grants))
  108. struct ioctl_gntdev_set_max_grants {
  109. /* IN parameter */
  110. /* The maximum number of grants that may be mapped at once. */
  111. __u32 count;
  112. };
  113. /*
  114. * Sets up an unmap notification within the page, so that the other side can do
  115. * cleanup if this side crashes. Required to implement cross-domain robust
  116. * mutexes or close notification on communication channels.
  117. *
  118. * Each mapped page only supports one notification; multiple calls referring to
  119. * the same page overwrite the previous notification. You must clear the
  120. * notification prior to the IOCTL_GNTALLOC_DEALLOC_GREF if you do not want it
  121. * to occur.
  122. */
  123. #define IOCTL_GNTDEV_SET_UNMAP_NOTIFY \
  124. _IOC(_IOC_NONE, 'G', 7, sizeof(struct ioctl_gntdev_unmap_notify))
  125. struct ioctl_gntdev_unmap_notify {
  126. /* IN parameters */
  127. /* Offset in the file descriptor for a byte within the page (same as
  128. * used in mmap). If using UNMAP_NOTIFY_CLEAR_BYTE, this is the byte to
  129. * be cleared. Otherwise, it can be any byte in the page whose
  130. * notification we are adjusting.
  131. */
  132. __u64 index;
  133. /* Action(s) to take on unmap */
  134. __u32 action;
  135. /* Event channel to notify */
  136. __u32 event_channel_port;
  137. };
  138. /* Clear (set to zero) the byte specified by index */
  139. #define UNMAP_NOTIFY_CLEAR_BYTE 0x1
  140. /* Send an interrupt on the indicated event channel */
  141. #define UNMAP_NOTIFY_SEND_EVENT 0x2
  142. #endif /* __LINUX_PUBLIC_GNTDEV_H__ */