ion.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. /*
  2. * drivers/staging/android/uapi/ion.h
  3. *
  4. * Copyright (C) 2011 Google, Inc.
  5. *
  6. * This software is licensed under the terms of the GNU General Public
  7. * License version 2, as published by the Free Software Foundation, and
  8. * may be copied, distributed, and modified under those terms.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. */
  16. #ifndef _UAPI_LINUX_ION_H
  17. #define _UAPI_LINUX_ION_H
  18. #include <linux/ioctl.h>
  19. #include <linux/types.h>
  20. typedef int ion_user_handle_t;
  21. /**
  22. * enum ion_heap_types - list of all possible types of heaps
  23. * @ION_HEAP_TYPE_SYSTEM: memory allocated via vmalloc
  24. * @ION_HEAP_TYPE_SYSTEM_CONTIG: memory allocated via kmalloc
  25. * @ION_HEAP_TYPE_CARVEOUT: memory allocated from a prereserved
  26. * carveout heap, allocations are physically
  27. * contiguous
  28. * @ION_HEAP_TYPE_DMA: memory allocated via DMA API
  29. * @ION_NUM_HEAPS: helper for iterating over heaps, a bit mask
  30. * is used to identify the heaps, so only 32
  31. * total heap types are supported
  32. */
  33. enum ion_heap_type {
  34. ION_HEAP_TYPE_SYSTEM,
  35. ION_HEAP_TYPE_SYSTEM_CONTIG,
  36. ION_HEAP_TYPE_CARVEOUT,
  37. ION_HEAP_TYPE_CHUNK,
  38. ION_HEAP_TYPE_DMA,
  39. ION_HEAP_TYPE_CUSTOM, /* must be last so device specific heaps always
  40. are at the end of this enum */
  41. ION_NUM_HEAPS = 16,
  42. };
  43. #define ION_HEAP_SYSTEM_MASK (1 << ION_HEAP_TYPE_SYSTEM)
  44. #define ION_HEAP_SYSTEM_CONTIG_MASK (1 << ION_HEAP_TYPE_SYSTEM_CONTIG)
  45. #define ION_HEAP_CARVEOUT_MASK (1 << ION_HEAP_TYPE_CARVEOUT)
  46. #define ION_HEAP_TYPE_DMA_MASK (1 << ION_HEAP_TYPE_DMA)
  47. #define ION_NUM_HEAP_IDS sizeof(unsigned int) * 8
  48. /**
  49. * allocation flags - the lower 16 bits are used by core ion, the upper 16
  50. * bits are reserved for use by the heaps themselves.
  51. */
  52. #define ION_FLAG_CACHED 1 /* mappings of this buffer should be
  53. cached, ion will do cache
  54. maintenance when the buffer is
  55. mapped for dma */
  56. #define ION_FLAG_CACHED_NEEDS_SYNC 2 /* mappings of this buffer will created
  57. at mmap time, if this is set
  58. caches must be managed manually */
  59. /**
  60. * DOC: Ion Userspace API
  61. *
  62. * create a client by opening /dev/ion
  63. * most operations handled via following ioctls
  64. *
  65. */
  66. /**
  67. * struct ion_allocation_data - metadata passed from userspace for allocations
  68. * @len: size of the allocation
  69. * @align: required alignment of the allocation
  70. * @heap_id_mask: mask of heap ids to allocate from
  71. * @flags: flags passed to heap
  72. * @handle: pointer that will be populated with a cookie to use to
  73. * refer to this allocation
  74. *
  75. * Provided by userspace as an argument to the ioctl
  76. */
  77. struct ion_allocation_data {
  78. size_t len;
  79. size_t align;
  80. unsigned int heap_id_mask;
  81. unsigned int flags;
  82. ion_user_handle_t handle;
  83. };
  84. /**
  85. * struct ion_fd_data - metadata passed to/from userspace for a handle/fd pair
  86. * @handle: a handle
  87. * @fd: a file descriptor representing that handle
  88. *
  89. * For ION_IOC_SHARE or ION_IOC_MAP userspace populates the handle field with
  90. * the handle returned from ion alloc, and the kernel returns the file
  91. * descriptor to share or map in the fd field. For ION_IOC_IMPORT, userspace
  92. * provides the file descriptor and the kernel returns the handle.
  93. */
  94. struct ion_fd_data {
  95. ion_user_handle_t handle;
  96. int fd;
  97. };
  98. /**
  99. * struct ion_handle_data - a handle passed to/from the kernel
  100. * @handle: a handle
  101. */
  102. struct ion_handle_data {
  103. ion_user_handle_t handle;
  104. };
  105. /**
  106. * struct ion_custom_data - metadata passed to/from userspace for a custom ioctl
  107. * @cmd: the custom ioctl function to call
  108. * @arg: additional data to pass to the custom ioctl, typically a user
  109. * pointer to a predefined structure
  110. *
  111. * This works just like the regular cmd and arg fields of an ioctl.
  112. */
  113. struct ion_custom_data {
  114. unsigned int cmd;
  115. unsigned long arg;
  116. };
  117. #define ION_IOC_MAGIC 'I'
  118. /**
  119. * DOC: ION_IOC_ALLOC - allocate memory
  120. *
  121. * Takes an ion_allocation_data struct and returns it with the handle field
  122. * populated with the opaque handle for the allocation.
  123. */
  124. #define ION_IOC_ALLOC _IOWR(ION_IOC_MAGIC, 0, \
  125. struct ion_allocation_data)
  126. /**
  127. * DOC: ION_IOC_FREE - free memory
  128. *
  129. * Takes an ion_handle_data struct and frees the handle.
  130. */
  131. #define ION_IOC_FREE _IOWR(ION_IOC_MAGIC, 1, struct ion_handle_data)
  132. /**
  133. * DOC: ION_IOC_MAP - get a file descriptor to mmap
  134. *
  135. * Takes an ion_fd_data struct with the handle field populated with a valid
  136. * opaque handle. Returns the struct with the fd field set to a file
  137. * descriptor open in the current address space. This file descriptor
  138. * can then be used as an argument to mmap.
  139. */
  140. #define ION_IOC_MAP _IOWR(ION_IOC_MAGIC, 2, struct ion_fd_data)
  141. /**
  142. * DOC: ION_IOC_SHARE - creates a file descriptor to use to share an allocation
  143. *
  144. * Takes an ion_fd_data struct with the handle field populated with a valid
  145. * opaque handle. Returns the struct with the fd field set to a file
  146. * descriptor open in the current address space. This file descriptor
  147. * can then be passed to another process. The corresponding opaque handle can
  148. * be retrieved via ION_IOC_IMPORT.
  149. */
  150. #define ION_IOC_SHARE _IOWR(ION_IOC_MAGIC, 4, struct ion_fd_data)
  151. /**
  152. * DOC: ION_IOC_IMPORT - imports a shared file descriptor
  153. *
  154. * Takes an ion_fd_data struct with the fd field populated with a valid file
  155. * descriptor obtained from ION_IOC_SHARE and returns the struct with the handle
  156. * filed set to the corresponding opaque handle.
  157. */
  158. #define ION_IOC_IMPORT _IOWR(ION_IOC_MAGIC, 5, struct ion_fd_data)
  159. /**
  160. * DOC: ION_IOC_SYNC - syncs a shared file descriptors to memory
  161. *
  162. * Deprecated in favor of using the dma_buf api's correctly (syncing
  163. * will happend automatically when the buffer is mapped to a device).
  164. * If necessary should be used after touching a cached buffer from the cpu,
  165. * this will make the buffer in memory coherent.
  166. */
  167. #define ION_IOC_SYNC _IOWR(ION_IOC_MAGIC, 7, struct ion_fd_data)
  168. /**
  169. * DOC: ION_IOC_CUSTOM - call architecture specific ion ioctl
  170. *
  171. * Takes the argument of the architecture specific ioctl to call and
  172. * passes appropriate userdata for that ioctl
  173. */
  174. #define ION_IOC_CUSTOM _IOWR(ION_IOC_MAGIC, 6, struct ion_custom_data)
  175. #endif /* _UAPI_LINUX_ION_H */