msm_cvp_dsp.h 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (c) 2018-2021, The Linux Foundation. All rights reserved.
  4. * Copyright (c) 2023 Qualcomm Innovation Center, Inc. All rights reserved.
  5. */
  6. #ifndef MSM_CVP_DSP_H
  7. #define MSM_CVP_DSP_H
  8. #include <linux/types.h>
  9. #include <linux/refcount.h>
  10. #include "msm_cvp_debug.h"
  11. #include "cvp_core_hfi.h"
  12. #include <linux/pid.h>
  13. #include <linux/sched.h>
  14. #ifdef CVP_FASTRPC_ENABLED
  15. #include <fastrpc.h>
  16. #else
  17. struct fastrpc_device {
  18. int handle;
  19. };
  20. enum fastrpc_driver_status {
  21. FASTRPC_CVP_B,
  22. };
  23. enum fastrpc_driver_invoke_nums {
  24. FASTRPC_DEV_MAP_DMA = 1,
  25. FASTRPC_DEV_UNMAP_DMA,
  26. FASTRPC_DEV_GET_HLOS_PID,
  27. };
  28. struct fastrpc_driver {
  29. struct device_driver driver;
  30. int handle;
  31. int (*probe)(struct fastrpc_device *dev);
  32. int (*callback)(struct fastrpc_device *dev,
  33. enum fastrpc_driver_status status);
  34. };
  35. #endif /* End of CVP_FASTRPC_ENABLED */
  36. #define CVP_APPS_DSP_GLINK_GUID "cvp-glink-apps-dsp"
  37. #define CVP_APPS_DSP_SMD_GUID "cvp-smd-apps-dsp"
  38. #define VMID_CDSP_Q6 (30)
  39. #define HLOS_VM_NUM 1
  40. #define DSP_VM_NUM 2
  41. #define CVP_DSP_MAX_RESERVED 5
  42. #define CVP_DSP2CPU_RESERVED 8
  43. #define CVP_DSP_RESPONSE_TIMEOUT 1000
  44. #define CVP_INVALID_RPMSG_TYPE 0xBADDFACE
  45. #define MAX_FRAME_BUF_NUM 16
  46. #define BITPTRSIZE32 (4)
  47. #define BITPTRSIZE64 (8)
  48. #define HIGH32 (0xFFFFFFFF00000000LL)
  49. #define LOW32 (0xFFFFFFFFLL)
  50. #define CVP_FASTRPC_DRIVER_NAME_SIZE 16
  51. /* Supports up to 8 DSP sessions in 8 processes */
  52. #define MAX_DSP_SESSION_NUM (8)
  53. #define MAX_FASTRPC_DRIVER_NUM (MAX_DSP_SESSION_NUM)
  54. int cvp_dsp_device_init(void);
  55. void cvp_dsp_device_exit(void);
  56. void cvp_dsp_send_hfi_queue(void);
  57. void cvp_dsp_init_hfi_queue_hdr(struct iris_hfi_device *device);
  58. enum CPU2DSP_STATUS {
  59. CPU2DSP_SUCCESS = 0,
  60. CPU2DSP_EFAIL = 1,
  61. CPU2DSP_EFATAL = 2,
  62. CPU2DSP_EUNAVAILABLE = 3,
  63. CPU2DSP_EINVALSTATE = 4,
  64. CPU2DSP_EUNSUPPORTED = 5,
  65. };
  66. enum CVP_DSP_COMMAND {
  67. CPU2DSP_SEND_HFI_QUEUE = 0,
  68. CPU2DSP_SUSPEND = 1,
  69. CPU2DSP_RESUME = 2,
  70. CPU2DSP_SHUTDOWN = 3,
  71. CPU2DSP_REGISTER_BUFFER = 4,
  72. CPU2DSP_DEREGISTER_BUFFER = 5,
  73. CPU2DSP_INIT = 6,
  74. CPU2DSP_SET_DEBUG_LEVEL = 7,
  75. CPU2DSP_MAX_CMD = 8,
  76. DSP2CPU_POWERON = 11,
  77. DSP2CPU_POWEROFF = 12,
  78. DSP2CPU_CREATE_SESSION = 13,
  79. DSP2CPU_DETELE_SESSION = 14,
  80. DSP2CPU_POWER_REQUEST = 15,
  81. DSP2CPU_POWER_CANCEL = 16,
  82. DSP2CPU_REGISTER_BUFFER = 17,
  83. DSP2CPU_DEREGISTER_BUFFER = 18,
  84. DSP2CPU_MEM_ALLOC = 19,
  85. DSP2CPU_MEM_FREE = 20,
  86. DSP2CPU_START_SESSION = 21,
  87. DSP2CPU_STOP_SESSION = 22,
  88. CVP_DSP_MAX_CMD = 23,
  89. };
  90. struct eva_power_req {
  91. uint32_t clock_fdu;
  92. uint32_t clock_ica;
  93. uint32_t clock_od;
  94. uint32_t clock_mpu;
  95. uint32_t clock_fw;
  96. uint32_t bw_ddr;
  97. uint32_t bw_sys_cache;
  98. uint32_t op_clock_fdu;
  99. uint32_t op_clock_ica;
  100. uint32_t op_clock_od;
  101. uint32_t op_clock_mpu;
  102. uint32_t op_clock_fw;
  103. uint32_t op_bw_ddr;
  104. uint32_t op_bw_sys_cache;
  105. };
  106. struct eva_mem_remote {
  107. uint32_t type;
  108. uint32_t size;
  109. uint32_t fd;
  110. uint32_t offset;
  111. uint32_t index;
  112. uint32_t iova;
  113. uint32_t dsp_remote_map;
  114. uint64_t v_dsp_addr;
  115. };
  116. /*
  117. * command: defined as a packet initiated from one party.
  118. * message: defined as a packet sent as response to a command
  119. */
  120. /*
  121. * cvp_dsp_cmd_msg contains
  122. * the message sent from CPU to DSP
  123. * or
  124. * the command sent from CPU to DSP
  125. */
  126. struct cvp_dsp_cmd_msg {
  127. uint32_t type;
  128. int32_t ret;
  129. uint64_t msg_ptr;
  130. uint32_t msg_ptr_len;
  131. uint32_t buff_fd_iova;
  132. uint32_t buff_index;
  133. uint32_t buff_size;
  134. uint32_t session_id;
  135. int32_t ddr_type;
  136. uint32_t buff_fd;
  137. uint32_t buff_offset;
  138. uint32_t buff_fd_size;
  139. uint32_t eva_dsp_debug_mask;
  140. /* Create Session */
  141. uint32_t session_cpu_low;
  142. uint32_t session_cpu_high;
  143. struct eva_mem_remote sbuf;
  144. uint32_t reserved1;
  145. uint32_t reserved2;
  146. };
  147. /* cvp_dsp_rsp_msg contains the message sent from DSP to CPU */
  148. struct cvp_dsp_rsp_msg {
  149. uint32_t type;
  150. int32_t ret;
  151. uint32_t dsp_state;
  152. uint32_t reserved[CVP_DSP_MAX_RESERVED - 1];
  153. };
  154. /* cvp_dsp2cpu_cmd contains the command sent from DSP to cpu*/
  155. struct cvp_dsp2cpu_cmd {
  156. uint32_t type;
  157. uint32_t ver;
  158. uint32_t len;
  159. /* Create Session */
  160. uint32_t session_type;
  161. uint32_t kernel_mask;
  162. uint32_t session_prio;
  163. uint32_t is_secure;
  164. uint32_t dsp_access_mask;
  165. uint32_t session_id;
  166. uint32_t session_cpu_low;
  167. uint32_t session_cpu_high;
  168. int32_t pid;
  169. struct eva_power_req power_req;
  170. struct eva_mem_remote sbuf;
  171. uint32_t data[CVP_DSP2CPU_RESERVED];
  172. };
  173. struct driver_name {
  174. uint32_t status;
  175. char name[CVP_FASTRPC_DRIVER_NAME_SIZE];
  176. };
  177. enum DRIVER_NAME_STATUS {
  178. DRIVER_NAME_INVALID = 0,
  179. DRIVER_NAME_AVAILABLE = 1,
  180. DRIVER_NAME_USED = 2,
  181. };
  182. struct cvp_dsp_fastrpc_driver_entry {
  183. struct list_head list;
  184. uint32_t handle; /*handle is not PID*/
  185. uint32_t session_cnt;
  186. uint32_t driver_name_idx;
  187. atomic_t refcount;
  188. struct fastrpc_driver cvp_fastrpc_driver;
  189. struct fastrpc_device *cvp_fastrpc_device;
  190. struct completion fastrpc_probe_completion;
  191. /* all dsp sessions list */
  192. struct msm_cvp_list dsp_sessions;
  193. };
  194. struct cvp_dsp_apps {
  195. /*
  196. * tx_lock for sending CPU2DSP cmds or msgs
  197. * and dsp state change
  198. */
  199. struct mutex tx_lock;
  200. /* rx_lock for receiving DSP2CPU cmds or msgs */
  201. struct mutex rx_lock;
  202. struct mutex driver_name_lock;
  203. struct rpmsg_device *chan;
  204. uint32_t state;
  205. uint32_t debug_mask;
  206. bool hyp_assigned;
  207. uint64_t addr;
  208. uint32_t size;
  209. struct completion completions[CPU2DSP_MAX_CMD + 1];
  210. struct cvp_dsp2cpu_cmd pending_dsp2cpu_cmd;
  211. struct cvp_dsp_rsp_msg pending_dsp2cpu_rsp;
  212. struct task_struct *dsp_thread;
  213. /* dsp buffer mapping, set of dma function pointer */
  214. const struct file_operations *dmabuf_f_op;
  215. uint32_t buf_num;
  216. struct msm_cvp_list fastrpc_driver_list;
  217. struct driver_name cvp_fastrpc_name[MAX_FASTRPC_DRIVER_NUM];
  218. };
  219. #define EVA_TRACE_MAX_SESSION_NUM 16
  220. #define EVA_TRACE_MAX_INSTANCE_NUM 6
  221. #define EVA_TRACE_MAX_BUF_NUM 256
  222. #define CONFIG_SIZE_IN_BYTES 2048
  223. #define CONFIG_SIZE_IN_WORDS (CONFIG_SIZE_IN_BYTES >> 2)
  224. // iova is eva_dsp_buf->iova
  225. // pkt_type is frame packet type using the buffer
  226. // buf_idx is the index of the buffer in a frame packet
  227. // transaction_id is the transaction id of frame packet
  228. struct cvp_dsp_trace_buf {
  229. u32 iova;
  230. u32 pkt_type;
  231. u32 buf_idx;
  232. u32 transaction_id;
  233. u32 fd;
  234. };
  235. // Saving config packet for each intance
  236. struct cvp_dsp_trace_instance {
  237. u32 feature_type;
  238. u32 config_pkt[CONFIG_SIZE_IN_WORDS];
  239. };
  240. struct cvp_dsp_trace_session {
  241. u32 session_id;
  242. u32 buf_cnt;
  243. u32 inst_cnt;
  244. struct cvp_dsp_trace_instance instance[EVA_TRACE_MAX_INSTANCE_NUM];
  245. struct cvp_dsp_trace_buf buf[EVA_TRACE_MAX_BUF_NUM];
  246. };
  247. struct cvp_dsp_trace {
  248. struct cvp_dsp_trace_session sessions[EVA_TRACE_MAX_SESSION_NUM];
  249. };
  250. extern struct cvp_dsp_apps gfa_cv;
  251. /*
  252. * API for CVP driver to suspend CVP session during
  253. * power collapse
  254. */
  255. int cvp_dsp_suspend(bool force);
  256. /*
  257. * API for CVP driver to resume CVP session during
  258. * power collapse
  259. */
  260. int cvp_dsp_resume(void);
  261. /*
  262. * API for CVP driver to shutdown CVP session during
  263. * cvp subsystem error.
  264. */
  265. int cvp_dsp_shutdown(void);
  266. int cvp_dsp_fastrpc_unmap(uint32_t handle, struct cvp_internal_buf *buf);
  267. int cvp_dsp_del_sess(uint32_t handle, struct msm_cvp_inst *inst);
  268. void cvp_dsp_send_debug_mask(void);
  269. #endif // MSM_CVP_DSP_H