ump-common.h 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. /*
  2. *
  3. * (C) COPYRIGHT ARM Limited. All rights reserved.
  4. *
  5. * This program is free software and is provided to you under the terms of the
  6. * GNU General Public License version 2 as published by the Free Software
  7. * Foundation, and any use by you of this program is subject to the terms
  8. * of such GNU licence.
  9. *
  10. * A copy of the licence is included with the program, and can also be obtained
  11. * from Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  12. * Boston, MA 02110-1301, USA.
  13. *
  14. */
  15. /**
  16. * @file ump-common.h
  17. *
  18. * This file contains some common enum values used both in both the user and kernel space side of UMP.
  19. */
  20. #ifndef _UMP_COMMON_H_
  21. #define _UMP_COMMON_H_
  22. #ifdef __cplusplus
  23. extern "C"
  24. {
  25. #endif
  26. #ifdef __KERNEL__
  27. #include <linux/types.h>
  28. #else
  29. #include <stdint.h>
  30. #endif
  31. #define UMP_UINT32_MAX (4294967295U)
  32. #define UMP_UINT64_MAX (18446744073709551615ULL)
  33. #ifdef __GNUC__
  34. #define CHECK_RESULT __attribute__((__warn_unused_result__))
  35. #define INLINE __inline__
  36. #else
  37. #define CHECK_RESULT
  38. #define INLINE __inline
  39. #endif
  40. #ifndef STATIC
  41. #define STATIC static
  42. #endif
  43. /**
  44. * Values to identify major and minor version of UMP
  45. */
  46. #define UMP_VERSION_MAJOR 2
  47. #define UMP_VERSION_MINOR 0
  48. /**
  49. * Typedef for a secure ID, a system wide identifier for UMP memory buffers.
  50. */
  51. typedef int32_t ump_secure_id;
  52. /**
  53. * Value to indicate an invalid secure Id.
  54. */
  55. #define UMP_INVALID_SECURE_ID ((ump_secure_id)0)
  56. /**
  57. * UMP error codes.
  58. */
  59. typedef enum
  60. {
  61. UMP_OK = 0, /**< indicates success */
  62. UMP_ERROR = 1 /**< indicates failure */
  63. } ump_result;
  64. /**
  65. * Allocation flag bits.
  66. *
  67. * ump_allocate accepts zero or more flags to specify the type of memory to allocate and how to expose it to devices.
  68. *
  69. * For each supported device there are 4 flags to control access permissions and give usage characteristic hints to optimize the allocation/mapping.
  70. * They are;
  71. * @li @a UMP_PROT_<device>_RD read permission
  72. * @li @a UMP_PROT_<device>_WR write permission
  73. * @li @a UMP_HINT_<device>_RD read often
  74. * @li @a UMP_HINT_<device>_WR written often
  75. *
  76. * 5 devices are currently supported, with a device being the CPU itself.
  77. * The other 4 devices will be mapped to real devices per SoC design.
  78. * They are just named W,X,Y,Z by UMP as it has no knowledge of their real names/identifiers.
  79. * As an example device W could be a camera device while device Z could be an ARM GPU device, leaving X and Y unused.
  80. *
  81. * 2 additional flags control the allocation;
  82. * @li @a UMP_CONSTRAINT_PHYSICALLY_LINEAR the allocation must be physical linear. Typical for devices without an MMU and no IOMMU to help it.
  83. * @li @a UMP_PROT_SHAREABLE the allocation can be shared with other processes on the system. Without this flag the returned allocation won't be resolvable in other processes.
  84. *
  85. * All UMP allocation are growable unless they're @a UMP_PROT_SHAREABLE.
  86. * The hint bits should be used to indicate the access pattern so the driver can select the most optimal memory type and cache settings based on the what the system supports.
  87. */
  88. typedef enum
  89. {
  90. /* Generic helpers */
  91. UMP_PROT_DEVICE_RD = (1u << 0),
  92. UMP_PROT_DEVICE_WR = (1u << 1),
  93. UMP_HINT_DEVICE_RD = (1u << 2),
  94. UMP_HINT_DEVICE_WR = (1u << 3),
  95. UMP_DEVICE_MASK = 0xF,
  96. UMP_DEVICE_CPU_SHIFT = 0,
  97. UMP_DEVICE_W_SHIFT = 4,
  98. UMP_DEVICE_X_SHIFT = 8,
  99. UMP_DEVICE_Y_SHIFT = 12,
  100. UMP_DEVICE_Z_SHIFT = 16,
  101. /* CPU protection and hints. */
  102. UMP_PROT_CPU_RD = (1u << 0),
  103. UMP_PROT_CPU_WR = (1u << 1),
  104. UMP_HINT_CPU_RD = (1u << 2),
  105. UMP_HINT_CPU_WR = (1u << 3),
  106. /* device W */
  107. UMP_PROT_W_RD = (1u << 4),
  108. UMP_PROT_W_WR = (1u << 5),
  109. UMP_HINT_W_RD = (1u << 6),
  110. UMP_HINT_W_WR = (1u << 7),
  111. /* device X */
  112. UMP_PROT_X_RD = (1u << 8),
  113. UMP_PROT_X_WR = (1u << 9),
  114. UMP_HINT_X_RD = (1u << 10),
  115. UMP_HINT_X_WR = (1u << 11),
  116. /* device Y */
  117. UMP_PROT_Y_RD = (1u << 12),
  118. UMP_PROT_Y_WR = (1u << 13),
  119. UMP_HINT_Y_RD = (1u << 14),
  120. UMP_HINT_Y_WR = (1u << 15),
  121. /* device Z */
  122. UMP_PROT_Z_RD = (1u << 16),
  123. UMP_PROT_Z_WR = (1u << 17),
  124. UMP_HINT_Z_RD = (1u << 18),
  125. UMP_HINT_Z_WR = (1u << 19),
  126. /* 20-26 reserved for future use */
  127. UMPP_ALLOCBITS_UNUSED = (0x7Fu << 20),
  128. /** Allocations marked as @ UMP_CONSTRAINT_UNCACHED won't be mapped as cached by the cpu */
  129. UMP_CONSTRAINT_UNCACHED = (1u << 27),
  130. /** Require 32-bit physically addressable memory */
  131. UMP_CONSTRAINT_32BIT_ADDRESSABLE = (1u << 28),
  132. /** For devices without an MMU and with no IOMMU assistance. */
  133. UMP_CONSTRAINT_PHYSICALLY_LINEAR = (1u << 29),
  134. /** Shareable must be set to allow the allocation to be used by other processes, the default is non-shared */
  135. UMP_PROT_SHAREABLE = (1u << 30)
  136. /* (1u << 31) should not be used to ensure compiler portability */
  137. } ump_allocation_bits;
  138. /**
  139. * ump_allocation_bits combination argument type.
  140. *
  141. * Type used to pass zero or more bits from the @ref ump_allocation_bits enum
  142. */
  143. typedef uint32_t ump_alloc_flags;
  144. /**
  145. * Default allocation flags for UMP v1 compatible allocations.
  146. */
  147. #define UMP_V1_API_DEFAULT_ALLOCATION_FLAGS UMP_PROT_CPU_RD | UMP_PROT_CPU_WR | \
  148. UMP_PROT_W_RD | UMP_PROT_W_WR | \
  149. UMP_PROT_X_RD | UMP_PROT_X_WR | \
  150. UMP_PROT_Y_RD | UMP_PROT_Y_WR | \
  151. UMP_PROT_Z_RD | UMP_PROT_Z_WR | \
  152. UMP_PROT_SHAREABLE | \
  153. UMP_CONSTRAINT_32BIT_ADDRESSABLE
  154. /**
  155. * CPU cache sync operations.
  156. *
  157. * Cache synchronization operations to pass to @ref ump_cpu_msync_now
  158. */
  159. enum
  160. {
  161. /**
  162. * Cleans any dirty cache lines to main memory, but the data will still be available in the cache.
  163. * After a clean the contents of memory is considered to be "owned" by the device.
  164. * */
  165. UMP_MSYNC_CLEAN = 1,
  166. /** Cleans any dirty cache lines to main memory and Ejects all lines from the cache.
  167. * After an clean&invalidate the contents of memory is considered to be "owned" by the CPU.
  168. * Any subsequent access will fetch data from main memory.
  169. *
  170. * @note Due to CPUs doing speculative prefetching a UMP_MSYNC_CLEAN_AND_INVALIDATE must be done before and after interacting with hardware.
  171. * */
  172. UMP_MSYNC_CLEAN_AND_INVALIDATE
  173. };
  174. typedef uint32_t ump_cpu_msync_op;
  175. /**
  176. * Memory import types supported.
  177. * If new import types are added they will appear here.
  178. * They must be added before UMPP_EXTERNAL_MEM_COUNT and
  179. * must be assigned an explicit sequantial number.
  180. *
  181. * @li UMP_EXTERNAL_MEM_TYPE_ION - Import an ION allocation
  182. * Takes a int* (pointer to a file descriptor)
  183. * Another ION reference is taken which is released on the final ump_release
  184. */
  185. enum ump_external_memory_type
  186. {
  187. UMPP_EXTERNAL_MEM_TYPE_UNUSED = 0, /* reserve type 0 */
  188. UMP_EXTERNAL_MEM_TYPE_ION = 1,
  189. UMPP_EXTERNAL_MEM_COUNT
  190. };
  191. /** @name UMP v1 API
  192. *
  193. *@{
  194. */
  195. /**
  196. * Allocation constraints.
  197. *
  198. * Allocation flags to pass @ref ump_ref_drv_allocate
  199. *
  200. * UMP v1 API only.
  201. */
  202. typedef enum
  203. {
  204. /** the allocation is mapped as noncached. */
  205. UMP_REF_DRV_CONSTRAINT_NONE = 0,
  206. /** not supported. */
  207. UMP_REF_DRV_CONSTRAINT_PHYSICALLY_LINEAR = 1,
  208. /** the allocation is mapped as cached by the cpu. */
  209. UMP_REF_DRV_CONSTRAINT_USE_CACHE = 4
  210. } ump_alloc_constraints;
  211. /* @} */
  212. #ifdef __cplusplus
  213. }
  214. #endif
  215. #endif /* _UMP_COMMON_H_ */