ump-ioctl.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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. #ifndef _UMP_IOCTL_H_
  16. #define _UMP_IOCTL_H
  17. #include <linux/ump-common.h>
  18. /*
  19. * The order and size of the members of these have been chosen so the structures look the same in 32-bit and 64-bit builds.
  20. * If any changes are done build the ump_struct_size_checker test for 32-bit and 64-bit targets. Both must compile successfully to commit.
  21. */
  22. /** 32/64-bit neutral way to represent pointers */
  23. typedef union ump_pointer
  24. {
  25. void * value; /**< client should store their pointers here */
  26. uint32_t compat_value; /**< 64-bit kernels should fetch value here when handling 32-bit clients */
  27. uint64_t sizer; /**< Force 64-bit storage for all clients regardless */
  28. } ump_pointer;
  29. /**
  30. * UMP allocation request.
  31. * Used when performing ump_allocate
  32. */
  33. typedef struct ump_k_allocate
  34. {
  35. uint64_t size; /**< [in] Size in bytes to allocate */
  36. ump_secure_id secure_id; /**< [out] Secure ID of allocation on success */
  37. ump_alloc_flags alloc_flags; /**< [in] Flags to use when allocating */
  38. } ump_k_allocate;
  39. /**
  40. * UMP size query request.
  41. * Used when performing ump_size_get
  42. */
  43. typedef struct ump_k_sizequery
  44. {
  45. uint64_t size; /**< [out] Size of allocation */
  46. ump_secure_id secure_id; /**< [in] ID of allocation to query the size of */
  47. uint32_t padding; /* don't remove */
  48. } ump_k_sizequery;
  49. /**
  50. * UMP cache synchronization request.
  51. * Used when performing ump_cpu_msync_now
  52. */
  53. typedef struct ump_k_msync
  54. {
  55. ump_pointer mapped_ptr; /**< [in] CPU VA to perform cache operation on */
  56. ump_secure_id secure_id; /**< [in] ID of allocation to perform cache operation on */
  57. ump_cpu_msync_op cache_operation; /**< [in] Cache operation to perform */
  58. uint64_t size; /**< [in] Size in bytes of the range to synchronize */
  59. } ump_k_msync;
  60. /**
  61. * UMP memory retain request.
  62. * Used when performing ump_retain
  63. */
  64. typedef struct ump_k_retain
  65. {
  66. ump_secure_id secure_id; /**< [in] ID of allocation to retain a reference to */
  67. uint32_t padding; /* don't remove */
  68. } ump_k_retain;
  69. /**
  70. * UMP memory release request.
  71. * Used when performing ump_release
  72. */
  73. typedef struct ump_k_release
  74. {
  75. ump_secure_id secure_id; /**< [in] ID of allocation to release a reference to */
  76. uint32_t padding; /* don't remove */
  77. } ump_k_release;
  78. typedef struct ump_k_import
  79. {
  80. ump_pointer phandle; /**< [in] Pointer to handle to import */
  81. uint32_t type; /**< [in] Type of handle to import */
  82. ump_alloc_flags alloc_flags; /**< [in] Flags to assign to the imported memory */
  83. ump_secure_id secure_id; /**< [out] UMP ID representing the imported memory */
  84. uint32_t padding; /* don't remove */
  85. } ump_k_import;
  86. /**
  87. * UMP allocation flags request.
  88. * Used when performing umpp_get_allocation_flags
  89. *
  90. * used only by v1 API
  91. */
  92. typedef struct ump_k_allocation_flags
  93. {
  94. ump_secure_id secure_id; /**< [in] Secure ID of allocation on success */
  95. ump_alloc_flags alloc_flags; /**< [out] Flags to use when allocating */
  96. } ump_k_allocation_flags;
  97. #define UMP_CALL_MAX_SIZE 512
  98. /*
  99. * Ioctl definitions
  100. */
  101. /* Use '~' as magic number */
  102. #define UMP_IOC_MAGIC '~'
  103. #define UMP_FUNC_ALLOCATE _IOWR(UMP_IOC_MAGIC, 1, ump_k_allocate)
  104. #define UMP_FUNC_SIZEQUERY _IOWR(UMP_IOC_MAGIC, 2, ump_k_sizequery)
  105. #define UMP_FUNC_MSYNC _IOWR(UMP_IOC_MAGIC, 3, ump_k_msync)
  106. #define UMP_FUNC_RETAIN _IOW(UMP_IOC_MAGIC, 4, ump_k_retain)
  107. #define UMP_FUNC_RELEASE _IOW(UMP_IOC_MAGIC, 5, ump_k_release)
  108. #define UMP_FUNC_ALLOCATION_FLAGS_GET _IOWR(UMP_IOC_MAGIC, 6, ump_k_allocation_flags)
  109. #define UMP_FUNC_IMPORT _IOWR(UMP_IOC_MAGIC, 7, ump_k_import)
  110. /*max ioctl sequential number*/
  111. #define UMP_IOC_MAXNR 7
  112. /* 15 bits for the UMP ID (allowing 32768 IDs) */
  113. #define UMP_LINUX_ID_BITS 15
  114. #define UMP_LINUX_ID_MASK ((1ULL << UMP_LINUX_ID_BITS) - 1ULL)
  115. /* 64-bit (really 52 bits) encoding: 15 bits for the ID, 37 bits for the offset */
  116. #define UMP_LINUX_OFFSET_BITS_64 37
  117. #define UMP_LINUX_OFFSET_MASK_64 ((1ULL << UMP_LINUX_OFFSET_BITS_64)-1)
  118. /* 32-bit encoding: 15 bits for the ID, 17 bits for the offset */
  119. #define UMP_LINUX_OFFSET_BITS_32 17
  120. #define UMP_LINUX_OFFSET_MASK_32 ((1ULL << UMP_LINUX_OFFSET_BITS_32)-1)
  121. #if __SIZEOF_LONG__ == 8
  122. #define UMP_LINUX_OFFSET_BITS UMP_LINUX_OFFSET_BITS_64
  123. #define UMP_LINUX_OFFSET_MASK UMP_LINUX_OFFSET_MASK_64
  124. #else
  125. #define UMP_LINUX_OFFSET_BITS UMP_LINUX_OFFSET_BITS_32
  126. #define UMP_LINUX_OFFSET_MASK UMP_LINUX_OFFSET_MASK_32
  127. #endif
  128. #endif /* _UMP_IOCTL_H_ */