spcom.h 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338
  1. /* SPDX-License-Identifier: GPL-2.0-only WITH Linux-syscall-note */
  2. /*
  3. * Copyright (c) 2015-2021, The Linux Foundation. All rights reserved.
  4. * Copyright (c) 2021 Qualcomm Innovation Center, Inc. All rights reserved.
  5. */
  6. #ifndef _UAPI_SPCOM_H_
  7. #define _UAPI_SPCOM_H_
  8. #include <linux/types.h> /* __u32, bool */
  9. #ifndef BIT
  10. #define BIT(x) (1 << x)
  11. #endif
  12. #ifndef PAGE_SIZE
  13. #define PAGE_SIZE 4096
  14. #endif
  15. /**
  16. * @brief - Secure Processor Communication interface to user space spcomlib.
  17. *
  18. * Sending data and control commands by write() file operation.
  19. * Receiving data by read() file operation.
  20. * Getting the next request size by read() file operation,
  21. * with special size SPCOM_GET_NEXT_REQUEST_SIZE.
  22. */
  23. /*
  24. * Maximum number of channel between Secure Processor and HLOS.
  25. * including predefined channels, like "sp_kernel".
  26. */
  27. #define SPCOM_MAX_CHANNELS 0x20
  28. /* Maximum size (including null) for channel names */
  29. #define SPCOM_CHANNEL_NAME_SIZE 32
  30. /*
  31. * file read(fd, buf, size) with this size,
  32. * hints the kernel that user space wants to read the next-req-size.
  33. * This size is bigger than both SPCOM_MAX_REQUEST_SIZE and
  34. * SPCOM_MAX_RESPONSE_SIZE , so it is not a valid data size.
  35. */
  36. #define SPCOM_GET_NEXT_REQUEST_SIZE (PAGE_SIZE-1)
  37. /* Command Id between spcomlib and spcom driver, on write() */
  38. enum spcom_cmd_id {
  39. SPCOM_CMD_LOAD_APP = 0x4C4F4144, /* "LOAD" = 0x4C4F4144 */
  40. SPCOM_CMD_RESET_SP = 0x52455354, /* "REST" = 0x52455354 */
  41. SPCOM_CMD_SEND = 0x53454E44, /* "SEND" = 0x53454E44 */
  42. SPCOM_CMD_SEND_MODIFIED = 0x534E444D, /* "SNDM" = 0x534E444D */
  43. SPCOM_CMD_LOCK_ION_BUF = 0x4C4F434B, /* "LOCK" = 0x4C4F434B */
  44. SPCOM_CMD_UNLOCK_ION_BUF = 0x554C434B, /* "ULCK" = 0x4C4F434B */
  45. SPCOM_CMD_FSSR = 0x46535352, /* "FSSR" = 0x46535352 */
  46. SPCOM_CMD_CREATE_CHANNEL = 0x43524554, /* "CRET" = 0x43524554 */
  47. #define SPCOM_CMD_ENABLE_SSR \
  48. SPCOM_CMD_ENABLE_SSR
  49. SPCOM_CMD_ENABLE_SSR = 0x45535352, /* "ESSR" =0x45535352*/
  50. #define SPCOM_CMD_RESTART_SP \
  51. SPCOM_CMD_RESTART_SP
  52. SPCOM_CMD_RESTART_SP = 0x52535452, /* "RSTR" = 0x52535452 */
  53. };
  54. /*
  55. * @note: Event types that are always implicitly polled:
  56. * POLLERR=0x08 | POLLHUP=0x10 | POLLNVAL=0x20
  57. * so bits 3,4,5 can't be used
  58. */
  59. enum spcom_poll_events {
  60. SPCOM_POLL_LINK_STATE = BIT(1),
  61. SPCOM_POLL_CH_CONNECT = BIT(2),
  62. SPCOM_POLL_READY_FLAG = BIT(14), /* output */
  63. SPCOM_POLL_WAIT_FLAG = BIT(15), /* if set , wait for the event */
  64. };
  65. /* Common Command structure between User Space and spcom driver, on write() */
  66. struct spcom_user_command {
  67. enum spcom_cmd_id cmd_id;
  68. __u32 arg;
  69. } __packed;
  70. /* Command structure between User Space and spcom driver, on write() */
  71. struct spcom_send_command {
  72. enum spcom_cmd_id cmd_id;
  73. __u32 timeout_msec;
  74. __u32 buf_size;
  75. char buf[0]; /* Variable buffer size - must be last field */
  76. } __packed;
  77. /* Command structure between userspace spcomlib and spcom driver, on write() */
  78. struct spcom_user_create_channel_command {
  79. enum spcom_cmd_id cmd_id;
  80. char ch_name[SPCOM_CHANNEL_NAME_SIZE];
  81. #define SPCOM_IS_SHARABLE_SUPPORTED
  82. _Bool is_sharable;
  83. } __packed;
  84. /* Command structure between userspace spcomlib and spcom driver, on write() */
  85. #define SPCOM_USER_RESTART_SP_CMD
  86. struct spcom_user_restart_sp_command {
  87. enum spcom_cmd_id cmd_id;
  88. __u32 arg;
  89. #define SPCOM_IS_UPDATED_SUPPORETED
  90. __u32 is_updated;
  91. } __packed;
  92. /* maximum ION buf for send-modfied-command */
  93. #define SPCOM_MAX_ION_BUF 4
  94. struct spcom_ion_info {
  95. __s32 fd; /* ION buffer File Descriptor, set -1 for invalid fd */
  96. __u32 buf_offset; /* virtual address offset in request/response */
  97. };
  98. /* Pass this FD to unlock all ION buffer for the specific channel */
  99. #define SPCOM_ION_FD_UNLOCK_ALL 0xFFFF
  100. struct spcom_ion_handle {
  101. __s32 fd; /* File Descriptor associated with the buffer */
  102. };
  103. struct spcom_rmb_error_info {
  104. __u32 rmb_error;
  105. __u32 padding;
  106. } __packed;
  107. /* Command structure between User Space and spcom driver, on write() */
  108. struct spcom_user_send_modified_command {
  109. enum spcom_cmd_id cmd_id;
  110. struct spcom_ion_info ion_info[SPCOM_MAX_ION_BUF];
  111. __u32 timeout_msec;
  112. __u32 buf_size;
  113. char buf[0]; /* Variable buffer size - must be last field */
  114. } __packed;
  115. enum {
  116. SPCOM_IONFD_CMD,
  117. SPCOM_POLL_CMD,
  118. SPCOM_GET_RMB_CMD,
  119. };
  120. enum spcom_poll_cmd_id {
  121. SPCOM_LINK_STATE_REQ,
  122. SPCOM_CH_CONN_STATE_REQ,
  123. };
  124. struct spcom_poll_param {
  125. /* input parameters */
  126. _Bool wait;
  127. enum spcom_poll_cmd_id cmd_id;
  128. /* output parameter */
  129. int retval;
  130. } __packed;
  131. #define SPCOM_IOCTL_MAGIC 'S'
  132. #define SPCOM_GET_IONFD _IOR(SPCOM_IOCTL_MAGIC, SPCOM_IONFD_CMD, \
  133. struct spcom_ion_handle)
  134. #define SPCOM_SET_IONFD _IOW(SPCOM_IOCTL_MAGIC, SPCOM_IONFD_CMD, \
  135. struct spcom_ion_handle)
  136. #define SPCOM_POLL_STATE _IOWR(SPCOM_IOCTL_MAGIC, SPCOM_POLL_CMD, \
  137. struct spcom_poll_param)
  138. #define SPCOM_GET_RMB_ERROR _IOR(SPCOM_IOCTL_MAGIC, SPCOM_GET_RMB_CMD, \
  139. struct spcom_rmb_error_info)
  140. /* Maximum number of DMA buffer for sending modified message */
  141. #define SPCOM_MAX_DMA_BUF SPCOM_MAX_ION_BUF
  142. /* Pass this FD to unlock all DMA buffer for the specific channel */
  143. #define SPCOM_DMABUF_FD_UNLOCK_ALL 0xFFFF
  144. /* SPCOM events enum */
  145. enum spcom_event_id {
  146. SPCOM_EVENT_LINK_STATE = 100
  147. };
  148. /* SPCOM IOCTL commands */
  149. enum spcom_ioctl_enum {
  150. SPCOM_IOCTL_STATE_POLL_CMD = 1000,
  151. SPCOM_IOCTL_SHARED_CH_CREATE_CMD,
  152. SPCOM_IOCTL_CH_REGISTER_CMD,
  153. SPCOM_IOCTL_CH_UNREGISTER_CMD,
  154. SPCOM_IOCTL_CH_IS_CONNECTED_CMD,
  155. SPCOM_IOCTL_SEND_MSG_CMD,
  156. SPCOM_IOCTL_SEND_MOD_MSG_CMD,
  157. SPCOM_IOCTL_GET_NEXT_REQ_SZ_CMD,
  158. SPCOM_IOCTL_GET_MSG_CMD,
  159. SPCOM_IOCTL_DMABUF_LOCK_CMD,
  160. SPCOM_IOCTL_DMABUF_UNLOCK_CMD,
  161. SPCOM_IOCTL_RESTART_SPU_CMD,
  162. SPCOM_IOCTL_ENABLE_SSR_CMD
  163. };
  164. /* SPCOM dma buffer info struct */
  165. struct spcom_dma_buf_info {
  166. __s32 fd; /* DMA buffer File Descriptor */
  167. __u32 offset; /* Address offset in request or response buffer*/
  168. } __packed;
  169. /* SPCOM dma buffers info table */
  170. struct spcom_dma_buf_info_table {
  171. struct spcom_dma_buf_info info[SPCOM_MAX_DMA_BUF];
  172. } __packed;
  173. /* SPCOM poll on event cmd struct */
  174. struct spcom_ioctl_poll_event {
  175. __u32 event_id; /* spcom_ioctl_enum */
  176. __u32 wait; /* wait for event, zero for no wait, positive number otherwise */
  177. __s32 retval; /* updated by spcom driver */
  178. __u32 padding; /* 64-bit alignment, unused */
  179. } __packed;
  180. /* SPCOM register/unregister channel cmd struct */
  181. struct spcom_ioctl_ch {
  182. char ch_name[SPCOM_CHANNEL_NAME_SIZE]; /* 4 * 64-bit */
  183. } __packed;
  184. /* SPCOM message cmd struct */
  185. struct spcom_ioctl_message {
  186. char ch_name[SPCOM_CHANNEL_NAME_SIZE]; /* 4 * 64-bit */
  187. __u32 timeout_msec;
  188. __u32 buffer_size;
  189. char buffer[0]; /* Variable buffer size - must be last field */
  190. } __packed;
  191. /* SPCOM modified message cmd struct */
  192. struct spcom_ioctl_modified_message {
  193. char ch_name[SPCOM_CHANNEL_NAME_SIZE]; /* 4 * 64-bit */
  194. __u32 timeout_msec;
  195. __u32 buffer_size;
  196. struct spcom_dma_buf_info info[SPCOM_MAX_DMA_BUF];
  197. char buffer[0]; /* Variable buffer size - must be last field */
  198. } __packed;
  199. /* SPCOM ioctl get next request size command struct */
  200. struct spcom_ioctl_next_request_size {
  201. char ch_name[SPCOM_CHANNEL_NAME_SIZE]; /* 4 * 64-bit */
  202. __u32 size;
  203. __u32 padding; /* 64-bit alignment, unused */
  204. } __packed;
  205. /* SPCOM ioctl buffer lock or unlock command struct */
  206. struct spcom_ioctl_dmabuf_lock {
  207. char ch_name[SPCOM_CHANNEL_NAME_SIZE]; /* 4 * 64-bit */
  208. __s32 fd;
  209. __u32 padding; /* 64-bit alignment, unused */
  210. } __packed;
  211. /* SPCOM ioctl command to handle event poll */
  212. #define SPCOM_IOCTL_STATE_POLL _IOWR( \
  213. SPCOM_IOCTL_MAGIC, \
  214. SPCOM_IOCTL_STATE_POLL_CMD, \
  215. struct spcom_ioctl_poll_event \
  216. )
  217. /* SPCOM ioctl command to handle SPCOM shared channel create */
  218. #define SPCOM_IOCTL_SHARED_CH_CREATE _IOW( \
  219. SPCOM_IOCTL_MAGIC, \
  220. SPCOM_IOCTL_SHARED_CH_CREATE_CMD, \
  221. struct spcom_ioctl_ch \
  222. )
  223. /* SPCOM ioctl command to handle SPCOM channel register */
  224. #define SPCOM_IOCTL_CH_REGISTER _IOW( \
  225. SPCOM_IOCTL_MAGIC, \
  226. SPCOM_IOCTL_CH_REGISTER_CMD, \
  227. struct spcom_ioctl_ch \
  228. )
  229. /* IOCTL to handle SPCOM channel unregister */
  230. #define SPCOM_IOCTL_CH_UNREGISTER _IOW( \
  231. SPCOM_IOCTL_MAGIC, \
  232. SPCOM_IOCTL_CH_UNREGISTER_CMD, \
  233. struct spcom_ioctl_ch \
  234. )
  235. /* IOCTL to check SPCOM channel connectivity with remote edge */
  236. #define SPCOM_IOCTL_CH_IS_CONNECTED _IOW( \
  237. SPCOM_IOCTL_MAGIC, \
  238. SPCOM_IOCTL_CH_IS_CONNECTED_CMD, \
  239. struct spcom_ioctl_ch \
  240. )
  241. /* IOCTL to handle SPCOM send message */
  242. #define SPCOM_IOCTL_SEND_MSG _IOW( \
  243. SPCOM_IOCTL_MAGIC, \
  244. SPCOM_IOCTL_SEND_MSG_CMD, \
  245. struct spcom_ioctl_message \
  246. )
  247. /* IOCTL to handle SPCOM send modified message */
  248. #define SPCOM_IOCTL_SEND_MOD_MSG _IOW( \
  249. SPCOM_IOCTL_MAGIC, \
  250. SPCOM_IOCTL_SEND_MOD_MSG_CMD, \
  251. struct spcom_ioctl_modified_message \
  252. )
  253. /* IOCTL to handle SPCOM get next request message size */
  254. #define SPCOM_IOCTL_GET_NEXT_REQ_SZ _IOWR( \
  255. SPCOM_IOCTL_MAGIC, \
  256. SPCOM_IOCTL_GET_NEXT_REQ_SZ_CMD, \
  257. struct spcom_ioctl_next_request_size \
  258. )
  259. /* IOCTL to handle SPCOM get request */
  260. #define SPCOM_IOCTL_GET_MSG _IOWR( \
  261. SPCOM_IOCTL_MAGIC, \
  262. SPCOM_IOCTL_GET_MSG_CMD, \
  263. struct spcom_ioctl_message \
  264. )
  265. /* IOCTL to handle DMA buffer lock/unlock */
  266. #define SPCOM_IOCTL_DMABUF_LOCK _IOW( \
  267. SPCOM_IOCTL_MAGIC, \
  268. SPCOM_IOCTL_DMABUF_LOCK_CMD, \
  269. struct spcom_ioctl_dmabuf_lock \
  270. )
  271. /* IOCTL to handle DMA buffer unlock */
  272. #define SPCOM_IOCTL_DMABUF_UNLOCK _IOW( \
  273. SPCOM_IOCTL_MAGIC, \
  274. SPCOM_IOCTL_DMABUF_UNLOCK_CMD, \
  275. struct spcom_ioctl_dmabuf_lock \
  276. )
  277. /* IOCTL to handle SPU restart */
  278. #define SPCOM_IOCTL_RESTART_SPU _IO( \
  279. SPCOM_IOCTL_MAGIC, \
  280. SPCOM_IOCTL_RESTART_SPU_CMD \
  281. )
  282. /* IOCTL to enable SSR */
  283. #define SPCOM_IOCTL_ENABLE_SSR _IO( \
  284. SPCOM_IOCTL_MAGIC, \
  285. SPCOM_IOCTL_ENABLE_SSR_CMD \
  286. )
  287. #endif /* _UAPI_SPCOM_H_ */