msm_cvp_dsp.h 5.9 KB

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