msm_cvp_dsp.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (c) 2018-2021, The Linux Foundation. All rights reserved.
  4. */
  5. #ifndef MSM_CVP_DSP_H
  6. #define MSM_CVP_DSP_H
  7. #include <linux/types.h>
  8. #include "msm_cvp_debug.h"
  9. #include "cvp_core_hfi.h"
  10. #include <linux/pid.h>
  11. #include <linux/sched.h>
  12. #include <linux/fastrpc.h>
  13. #define CVP_APPS_DSP_GLINK_GUID "cvp-glink-apps-dsp"
  14. #define CVP_APPS_DSP_SMD_GUID "cvp-smd-apps-dsp"
  15. #define VMID_CDSP_Q6 (30)
  16. #define HLOS_VM_NUM 1
  17. #define DSP_VM_NUM 2
  18. #define CVP_DSP_MAX_RESERVED 5
  19. #define CVP_DSP2CPU_RESERVED 8
  20. #define CVP_DSP_RESPONSE_TIMEOUT 300
  21. #define CVP_INVALID_RPMSG_TYPE 0xBADDFACE
  22. #define MAX_FRAME_BUF_NUM 16
  23. #define BITPTRSIZE32 (4)
  24. #define BITPTRSIZE64 (8)
  25. #define HIGH32 (0xFFFFFFFF00000000LL)
  26. #define LOW32 (0xFFFFFFFFLL)
  27. /* Supports up to 8 DSP sessions in 4 processes */
  28. #define MAX_FASTRPC_DRIVER_NUM (4)
  29. #define MAX_DSP_SESSION_NUM (8)
  30. int cvp_dsp_device_init(void);
  31. void cvp_dsp_device_exit(void);
  32. void cvp_dsp_send_hfi_queue(void);
  33. void cvp_dsp_init_hfi_queue_hdr(struct iris_hfi_device *device);
  34. enum CPU2DSP_STATUS {
  35. CPU2DSP_SUCCESS = 0,
  36. CPU2DSP_EFAIL = 1,
  37. CPU2DSP_EFATAL = 2,
  38. CPU2DSP_EUNAVAILABLE = 3,
  39. CPU2DSP_EINVALSTATE = 4,
  40. CPU2DSP_EUNSUPPORTED = 5,
  41. };
  42. enum CVP_DSP_COMMAND {
  43. CPU2DSP_SEND_HFI_QUEUE = 0,
  44. CPU2DSP_SUSPEND = 1,
  45. CPU2DSP_RESUME = 2,
  46. CPU2DSP_SHUTDOWN = 3,
  47. CPU2DSP_REGISTER_BUFFER = 4,
  48. CPU2DSP_DEREGISTER_BUFFER = 5,
  49. CPU2DSP_INIT = 6,
  50. CPU2DSP_SET_DEBUG_LEVEL = 7,
  51. CPU2DSP_MAX_CMD = 8,
  52. DSP2CPU_POWERON = 11,
  53. DSP2CPU_POWEROFF = 12,
  54. DSP2CPU_CREATE_SESSION = 13,
  55. DSP2CPU_DETELE_SESSION = 14,
  56. DSP2CPU_POWER_REQUEST = 15,
  57. DSP2CPU_POWER_CANCEL = 16,
  58. DSP2CPU_REGISTER_BUFFER = 17,
  59. DSP2CPU_DEREGISTER_BUFFER = 18,
  60. DSP2CPU_MEM_ALLOC = 19,
  61. DSP2CPU_MEM_FREE = 20,
  62. CVP_DSP_MAX_CMD = 21,
  63. };
  64. enum eva_dsp_debug_level {
  65. EVA_PORT_INFO_ON = 0,
  66. EVA_PORT_DEBUG_ON = 1,
  67. EVA_QDI_INFO_ON = 2,
  68. EVA_QDI_DEBUG_ON = 3,
  69. EVA_MEM_DEBUG_ON = 4
  70. };
  71. struct eva_power_req {
  72. uint32_t clock_fdu;
  73. uint32_t clock_ica;
  74. uint32_t clock_od;
  75. uint32_t clock_mpu;
  76. uint32_t clock_fw;
  77. uint32_t bw_ddr;
  78. uint32_t bw_sys_cache;
  79. uint32_t op_clock_fdu;
  80. uint32_t op_clock_ica;
  81. uint32_t op_clock_od;
  82. uint32_t op_clock_mpu;
  83. uint32_t op_clock_fw;
  84. uint32_t op_bw_ddr;
  85. uint32_t op_bw_sys_cache;
  86. };
  87. struct eva_mem_remote {
  88. uint32_t type;
  89. uint32_t size;
  90. uint32_t fd;
  91. uint32_t offset;
  92. uint32_t index;
  93. uint32_t iova;
  94. uint32_t dsp_remote_map;
  95. uint64_t v_dsp_addr;
  96. };
  97. struct cvp_dsp_cmd_msg {
  98. uint32_t type;
  99. int32_t ret;
  100. uint64_t msg_ptr;
  101. uint32_t msg_ptr_len;
  102. uint32_t buff_fd_iova;
  103. uint32_t buff_index;
  104. uint32_t buff_size;
  105. uint32_t session_id;
  106. int32_t ddr_type;
  107. uint32_t buff_fd;
  108. uint32_t buff_offset;
  109. uint32_t buff_fd_size;
  110. uint32_t eva_dsp_debug_level;
  111. /* Create Session */
  112. uint32_t session_cpu_low;
  113. uint32_t session_cpu_high;
  114. struct eva_mem_remote sbuf;
  115. uint32_t reserved1;
  116. uint32_t reserved2;
  117. };
  118. struct cvp_dsp_rsp_msg {
  119. uint32_t type;
  120. int32_t ret;
  121. uint32_t dsp_state;
  122. uint32_t reserved[CVP_DSP_MAX_RESERVED - 1];
  123. };
  124. struct cvp_dsp2cpu_cmd_msg {
  125. uint32_t type;
  126. uint32_t ver;
  127. uint32_t len;
  128. /* Create Session */
  129. uint32_t session_type;
  130. uint32_t kernel_mask;
  131. uint32_t session_prio;
  132. uint32_t is_secure;
  133. uint32_t dsp_access_mask;
  134. uint32_t session_id;
  135. uint32_t session_cpu_low;
  136. uint32_t session_cpu_high;
  137. int32_t pid;
  138. struct eva_power_req power_req;
  139. struct eva_mem_remote sbuf;
  140. uint32_t data[CVP_DSP2CPU_RESERVED];
  141. };
  142. struct cvp_dsp_fastrpc_driver_entry {
  143. struct list_head list;
  144. uint32_t handle;
  145. uint32_t session_cnt;
  146. struct fastrpc_driver cvp_fastrpc_driver;
  147. struct fastrpc_device *cvp_fastrpc_device;
  148. struct completion fastrpc_probe_completion;
  149. /* all dsp sessions list */
  150. struct msm_cvp_list dsp_sessions;
  151. };
  152. struct cvp_dsp_apps {
  153. struct mutex lock;
  154. struct rpmsg_device *chan;
  155. uint32_t state;
  156. bool hyp_assigned;
  157. uint64_t addr;
  158. uint32_t size;
  159. struct completion completions[CPU2DSP_MAX_CMD + 1];
  160. struct cvp_dsp2cpu_cmd_msg pending_dsp2cpu_cmd;
  161. struct cvp_dsp_rsp_msg pending_dsp2cpu_rsp;
  162. struct task_struct *dsp_thread;
  163. /* dsp buffer mapping, set of dma function pointer */
  164. const struct file_operations *dmabuf_f_op;
  165. uint32_t buf_num;
  166. struct msm_cvp_list fastrpc_driver_list;
  167. };
  168. extern struct cvp_dsp_apps gfa_cv;
  169. /*
  170. * API for CVP driver to suspend CVP session during
  171. * power collapse
  172. *
  173. * @param session_flag
  174. * Flag to share details of session.
  175. */
  176. int cvp_dsp_suspend(uint32_t session_flag);
  177. /*
  178. * API for CVP driver to resume CVP session during
  179. * power collapse
  180. *
  181. * @param session_flag
  182. * Flag to share details of session.
  183. */
  184. int cvp_dsp_resume(uint32_t session_flag);
  185. /*
  186. * API for CVP driver to shutdown CVP session during
  187. * cvp subsystem error.
  188. *
  189. * @param session_flag
  190. * Flag to share details of session.
  191. */
  192. int cvp_dsp_shutdown(uint32_t session_flag);
  193. /*
  194. * API to register iova buffer address with CDSP
  195. *
  196. * @session_id: cvp session id
  197. * @buff_fd: buffer fd
  198. * @buff_fd_size: total size of fd in bytes
  199. * @buff_size: size in bytes of cvp buffer
  200. * @buff_offset: buffer offset
  201. * @buff_index: buffer index
  202. * @iova_buff_addr: IOVA buffer address
  203. */
  204. int cvp_dsp_register_buffer(uint32_t session_id, uint32_t buff_fd,
  205. uint32_t buff_fd_size, uint32_t buff_size,
  206. uint32_t buff_offset, uint32_t buff_index,
  207. uint32_t buff_fd_iova);
  208. /*
  209. * API to de-register iova buffer address from CDSP
  210. *
  211. * @session_id: cvp session id
  212. * @buff_fd: buffer fd
  213. * @buff_fd_size: total size of fd in bytes
  214. * @buff_size: size in bytes of cvp buffer
  215. * @buff_offset: buffer offset
  216. * @buff_index: buffer index
  217. * @iova_buff_addr: IOVA buffer address
  218. */
  219. int cvp_dsp_deregister_buffer(uint32_t session_id, uint32_t buff_fd,
  220. uint32_t buff_fd_size, uint32_t buff_size,
  221. uint32_t buff_offset, uint32_t buff_index,
  222. uint32_t buff_fd_iova);
  223. int cvp_dsp_fastrpc_unmap(uint32_t process_id, struct cvp_internal_buf *buf);
  224. int cvp_dsp_del_sess(uint32_t process_id, struct msm_cvp_inst *inst);
  225. #endif // MSM_CVP_DSP_H