compat_qcedev.h 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. /*
  2. * Copyright (c) 2014, 2017 The Linux Foundation. All rights reserved.
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License version 2 and
  6. * only version 2 as published by the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. */
  13. #ifndef _UAPI_COMPAT_QCEDEV__H
  14. #define _UAPI_COMPAT_QCEDEV__H
  15. #include <linux/types.h>
  16. #include <linux/ioctl.h>
  17. #if IS_ENABLED(CONFIG_COMPAT)
  18. #include <linux/compat.h>
  19. /**
  20. * struct compat_buf_info - Buffer information
  21. * @offset: Offset from the base address of the buffer
  22. * (Used when buffer is allocated using PMEM)
  23. * @vaddr: Virtual buffer address pointer
  24. * @len: Size of the buffer
  25. */
  26. struct compat_buf_info {
  27. union {
  28. compat_ulong_t offset;
  29. compat_uptr_t vaddr;
  30. };
  31. compat_ulong_t len;
  32. };
  33. /**
  34. * struct compat_qcedev_vbuf_info - Source and destination Buffer information
  35. * @src: Array of buf_info for input/source
  36. * @dst: Array of buf_info for output/destination
  37. */
  38. struct compat_qcedev_vbuf_info {
  39. struct compat_buf_info src[QCEDEV_MAX_BUFFERS];
  40. struct compat_buf_info dst[QCEDEV_MAX_BUFFERS];
  41. };
  42. /**
  43. * struct compat_qcedev_pmem_info - Stores PMEM buffer information
  44. * @fd_src: Handle to /dev/adsp_pmem used to allocate
  45. * memory for input/src buffer
  46. * @src: Array of buf_info for input/source
  47. * @fd_dst: Handle to /dev/adsp_pmem used to allocate
  48. * memory for output/dst buffer
  49. * @dst: Array of buf_info for output/destination
  50. * @pmem_src_offset: The offset from input/src buffer
  51. * (allocated by PMEM)
  52. */
  53. struct compat_qcedev_pmem_info {
  54. compat_int_t fd_src;
  55. struct compat_buf_info src[QCEDEV_MAX_BUFFERS];
  56. compat_int_t fd_dst;
  57. struct compat_buf_info dst[QCEDEV_MAX_BUFFERS];
  58. };
  59. /**
  60. * struct compat_qcedev_cipher_op_req - Holds the ciphering request information
  61. * @use_pmem (IN): Flag to indicate if buffer source is PMEM
  62. * QCEDEV_USE_PMEM/QCEDEV_NO_PMEM
  63. * @pmem (IN): Stores PMEM buffer information.
  64. * Refer struct qcedev_pmem_info
  65. * @vbuf (IN/OUT): Stores Source and destination Buffer information
  66. * Refer to struct qcedev_vbuf_info
  67. * @data_len (IN): Total Length of input/src and output/dst in bytes
  68. * @in_place_op (IN): Indicates whether the operation is inplace where
  69. * source == destination
  70. * When using PMEM allocated memory, must set this to 1
  71. * @enckey (IN): 128 bits of confidentiality key
  72. * enckey[0] bit 127-120, enckey[1] bit 119-112,..
  73. * enckey[15] bit 7-0
  74. * @encklen (IN): Length of the encryption key(set to 128 bits/16
  75. * bytes in the driver)
  76. * @iv (IN/OUT): Initialization vector data
  77. * This is updated by the driver, incremented by
  78. * number of blocks encrypted/decrypted.
  79. * @ivlen (IN): Length of the IV
  80. * @byteoffset (IN): Offset in the Cipher BLOCK (applicable and to be set
  81. * for AES-128 CTR mode only)
  82. * @alg (IN): Type of ciphering algorithm: AES/DES/3DES
  83. * @mode (IN): Mode use when using AES algorithm: ECB/CBC/CTR
  84. * Applicable when using AES algorithm only
  85. * @op (IN): Type of operation: QCEDEV_OPER_DEC/QCEDEV_OPER_ENC or
  86. * QCEDEV_OPER_ENC_NO_KEY/QCEDEV_OPER_DEC_NO_KEY
  87. *
  88. * If use_pmem is set to 0, the driver assumes that memory was not allocated
  89. * via PMEM, and kernel will need to allocate memory and copy data from user
  90. * space buffer (data_src/dta_dst) and process accordingly and copy data back
  91. * to the user space buffer
  92. *
  93. * If use_pmem is set to 1, the driver assumes that memory was allocated via
  94. * PMEM.
  95. * The kernel driver will use the fd_src to determine the kernel virtual address
  96. * base that maps to the user space virtual address base for the buffer
  97. * allocated in user space.
  98. * The final input/src and output/dst buffer pointer will be determined
  99. * by adding the offsets to the kernel virtual addr.
  100. *
  101. * If use of hardware key is supported in the target, user can configure the
  102. * key parameters (encklen, enckey) to use the hardware key.
  103. * In order to use the hardware key, set encklen to 0 and set the enckey
  104. * data array to 0.
  105. */
  106. struct compat_qcedev_cipher_op_req {
  107. uint8_t use_pmem;
  108. union {
  109. struct compat_qcedev_pmem_info pmem;
  110. struct compat_qcedev_vbuf_info vbuf;
  111. };
  112. compat_ulong_t entries;
  113. compat_ulong_t data_len;
  114. uint8_t in_place_op;
  115. uint8_t enckey[QCEDEV_MAX_KEY_SIZE];
  116. compat_ulong_t encklen;
  117. uint8_t iv[QCEDEV_MAX_IV_SIZE];
  118. compat_ulong_t ivlen;
  119. compat_ulong_t byteoffset;
  120. enum qcedev_cipher_alg_enum alg;
  121. enum qcedev_cipher_mode_enum mode;
  122. enum qcedev_oper_enum op;
  123. };
  124. /**
  125. * struct qcedev_sha_op_req - Holds the hashing request information
  126. * @data (IN): Array of pointers to the data to be hashed
  127. * @entries (IN): Number of buf_info entries in the data array
  128. * @data_len (IN): Length of data to be hashed
  129. * @digest (IN/OUT): Returns the hashed data information
  130. * @diglen (OUT): Size of the hashed/digest data
  131. * @authkey (IN): Pointer to authentication key for HMAC
  132. * @authklen (IN): Size of the authentication key
  133. * @alg (IN): Secure Hash algorithm
  134. */
  135. struct compat_qcedev_sha_op_req {
  136. struct compat_buf_info data[QCEDEV_MAX_BUFFERS];
  137. compat_ulong_t entries;
  138. compat_ulong_t data_len;
  139. uint8_t digest[QCEDEV_MAX_SHA_DIGEST];
  140. compat_ulong_t diglen;
  141. compat_uptr_t authkey;
  142. compat_ulong_t authklen;
  143. enum qcedev_sha_alg_enum alg;
  144. };
  145. /**
  146. * struct compact_qcedev_map_buf_req - Holds the mapping request information
  147. * fd (IN): Array of fds.
  148. * num_fds (IN): Number of fds in fd[].
  149. * fd_size (IN): Array of sizes corresponding to each fd in fd[].
  150. * fd_offset (IN): Array of offset corresponding to each fd in fd[].
  151. * vaddr (OUT): Array of mapped virtual address corresponding to
  152. * each fd in fd[].
  153. */
  154. struct compat_qcedev_map_buf_req {
  155. compat_long_t fd[QCEDEV_MAX_BUFFERS];
  156. compat_ulong_t num_fds;
  157. compat_ulong_t fd_size[QCEDEV_MAX_BUFFERS];
  158. compat_ulong_t fd_offset[QCEDEV_MAX_BUFFERS];
  159. compat_u64 buf_vaddr[QCEDEV_MAX_BUFFERS];
  160. };
  161. /**
  162. * struct compat_qcedev_unmap_buf_req - Holds the hashing request information
  163. * fd (IN): Array of fds to unmap
  164. * num_fds (IN): Number of fds in fd[].
  165. */
  166. struct compat_qcedev_unmap_buf_req {
  167. compat_long_t fd[QCEDEV_MAX_BUFFERS];
  168. compat_ulong_t num_fds;
  169. };
  170. struct file;
  171. extern long compat_qcedev_ioctl(struct file *file,
  172. unsigned int cmd, unsigned long arg);
  173. #define COMPAT_QCEDEV_IOCTL_ENC_REQ \
  174. _IOWR(QCEDEV_IOC_MAGIC, 1, struct compat_qcedev_cipher_op_req)
  175. #define COMPAT_QCEDEV_IOCTL_DEC_REQ \
  176. _IOWR(QCEDEV_IOC_MAGIC, 2, struct compat_qcedev_cipher_op_req)
  177. #define COMPAT_QCEDEV_IOCTL_SHA_INIT_REQ \
  178. _IOWR(QCEDEV_IOC_MAGIC, 3, struct compat_qcedev_sha_op_req)
  179. #define COMPAT_QCEDEV_IOCTL_SHA_UPDATE_REQ \
  180. _IOWR(QCEDEV_IOC_MAGIC, 4, struct compat_qcedev_sha_op_req)
  181. #define COMPAT_QCEDEV_IOCTL_SHA_FINAL_REQ \
  182. _IOWR(QCEDEV_IOC_MAGIC, 5, struct compat_qcedev_sha_op_req)
  183. #define COMPAT_QCEDEV_IOCTL_GET_SHA_REQ \
  184. _IOWR(QCEDEV_IOC_MAGIC, 6, struct compat_qcedev_sha_op_req)
  185. #define COMPAT_QCEDEV_IOCTL_LOCK_CE \
  186. _IO(QCEDEV_IOC_MAGIC, 7)
  187. #define COMPAT_QCEDEV_IOCTL_UNLOCK_CE \
  188. _IO(QCEDEV_IOC_MAGIC, 8)
  189. #define COMPAT_QCEDEV_IOCTL_GET_CMAC_REQ \
  190. _IOWR(QCEDEV_IOC_MAGIC, 9, struct compat_qcedev_sha_op_req)
  191. #define COMPAT_QCEDEV_IOCTL_MAP_BUF_REQ \
  192. _IOWR(QCEDEV_IOC_MAGIC, 10, struct compat_qcedev_map_buf_req)
  193. #define COMPAT_QCEDEV_IOCTL_UNMAP_BUF_REQ \
  194. _IOWR(QCEDEV_IOC_MAGIC, 11, struct compat_qcedev_unmap_buf_req)
  195. #endif /* CONFIG_COMPAT */
  196. #endif /* _UAPI_COMPAT_QCEDEV__H */