ion.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
  2. /*
  3. * drivers/staging/android/uapi/ion.h
  4. *
  5. * Copyright (C) 2011 Google, Inc.
  6. */
  7. #ifndef _UAPI_LINUX_ION_H
  8. #define _UAPI_LINUX_ION_H
  9. #include <linux/ioctl.h>
  10. #include <linux/types.h>
  11. /**
  12. * ion_heap_types - list of all possible types of heaps that Android can use
  13. *
  14. * @ION_HEAP_TYPE_SYSTEM: Reserved heap id for ion heap that allocates
  15. * memory using alloc_page(). Also, supports
  16. * deferred free and allocation pools.
  17. * @ION_HEAP_TYPE_DMA: Reserved heap id for ion heap that manages
  18. * single CMA (contiguous memory allocator)
  19. * region. Uses standard DMA APIs for
  20. * managing memory within the CMA region.
  21. */
  22. enum ion_heap_type {
  23. ION_HEAP_TYPE_SYSTEM = 0,
  24. ION_HEAP_TYPE_DMA = 2,
  25. /* reserved range for future standard heap types */
  26. ION_HEAP_TYPE_CUSTOM = 16,
  27. ION_HEAP_TYPE_MAX = 31,
  28. };
  29. /**
  30. * ion_heap_id - list of standard heap ids that Android can use
  31. *
  32. * @ION_HEAP_SYSTEM Id for the ION_HEAP_TYPE_SYSTEM
  33. * @ION_HEAP_DMA_START Start of reserved id range for heaps of type
  34. * ION_HEAP_TYPE_DMA
  35. * @ION_HEAP_DMA_END End of reserved id range for heaps of type
  36. * ION_HEAP_TYPE_DMA
  37. * @ION_HEAP_CUSTOM_START Start of reserved id range for heaps of custom
  38. * type
  39. * @ION_HEAP_CUSTOM_END End of reserved id range for heaps of custom
  40. * type
  41. */
  42. enum ion_heap_id {
  43. ION_HEAP_SYSTEM = (1 << ION_HEAP_TYPE_SYSTEM),
  44. ION_HEAP_DMA_START = (ION_HEAP_SYSTEM << 1),
  45. ION_HEAP_DMA_END = (ION_HEAP_DMA_START << 7),
  46. ION_HEAP_CUSTOM_START = (ION_HEAP_DMA_END << 1),
  47. ION_HEAP_CUSTOM_END = (ION_HEAP_CUSTOM_START << 22),
  48. };
  49. #define ION_NUM_MAX_HEAPS (32)
  50. /**
  51. * allocation flags - the lower 16 bits are used by core ion, the upper 16
  52. * bits are reserved for use by the heaps themselves.
  53. */
  54. /*
  55. * mappings of this buffer should be cached, ion will do cache maintenance
  56. * when the buffer is mapped for dma
  57. */
  58. #define ION_FLAG_CACHED 1
  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. * @heap_id_mask: mask of heap ids to allocate from
  70. * @flags: flags passed to heap
  71. * @handle: pointer that will be populated with a cookie to use to
  72. * refer to this allocation
  73. *
  74. * Provided by userspace as an argument to the ioctl
  75. */
  76. struct ion_allocation_data {
  77. __u64 len;
  78. __u32 heap_id_mask;
  79. __u32 flags;
  80. __u32 fd;
  81. __u32 unused;
  82. };
  83. #define MAX_HEAP_NAME 32
  84. /**
  85. * struct ion_heap_data - data about a heap
  86. * @name - first 32 characters of the heap name
  87. * @type - heap type
  88. * @heap_id - heap id for the heap
  89. */
  90. struct ion_heap_data {
  91. char name[MAX_HEAP_NAME];
  92. __u32 type;
  93. __u32 heap_id;
  94. __u32 reserved0;
  95. __u32 reserved1;
  96. __u32 reserved2;
  97. };
  98. /**
  99. * struct ion_heap_query - collection of data about all heaps
  100. * @cnt - total number of heaps to be copied
  101. * @heaps - buffer to copy heap data
  102. */
  103. struct ion_heap_query {
  104. __u32 cnt; /* Total number of heaps to be copied */
  105. __u32 reserved0; /* align to 64bits */
  106. __u64 heaps; /* buffer to be populated */
  107. __u32 reserved1;
  108. __u32 reserved2;
  109. };
  110. #define ION_IOC_MAGIC 'I'
  111. /**
  112. * DOC: ION_IOC_ALLOC - allocate memory
  113. *
  114. * Takes an ion_allocation_data struct and returns it with the handle field
  115. * populated with the opaque handle for the allocation.
  116. */
  117. #define ION_IOC_ALLOC _IOWR(ION_IOC_MAGIC, 0, \
  118. struct ion_allocation_data)
  119. /**
  120. * DOC: ION_IOC_HEAP_QUERY - information about available heaps
  121. *
  122. * Takes an ion_heap_query structure and populates information about
  123. * available Ion heaps.
  124. */
  125. #define ION_IOC_HEAP_QUERY _IOWR(ION_IOC_MAGIC, 8, \
  126. struct ion_heap_query)
  127. /**
  128. * DOC: ION_IOC_HEAP_ABI_VERSION - return ABI version
  129. *
  130. * Returns ABI version for this driver
  131. */
  132. #define ION_IOC_ABI_VERSION _IOR(ION_IOC_MAGIC, 9, \
  133. __u32)
  134. #endif /* _UAPI_LINUX_ION_H */