spcom.h 10.0 KB

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