msm_cvp_internal.h 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408
  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_INTERNAL_H_
  7. #define _MSM_CVP_INTERNAL_H_
  8. #include <linux/atomic.h>
  9. #include <linux/sched.h>
  10. #include <linux/list.h>
  11. #include <linux/time.h>
  12. #include <linux/types.h>
  13. #include <linux/completion.h>
  14. #include <linux/wait.h>
  15. #include <linux/workqueue.h>
  16. #include <linux/interconnect.h>
  17. #include <linux/kref.h>
  18. #include <linux/cdev.h>
  19. #include <linux/slab.h>
  20. #include <linux/kthread.h>
  21. #include <linux/dma-mapping.h>
  22. #include "msm_cvp_core.h"
  23. #include <media/msm_eva_private.h>
  24. #include "cvp_hfi_api.h"
  25. #include "cvp_hfi_helper.h"
  26. #define MAX_SUPPORTED_INSTANCES 16
  27. #define MAX_DEBUGFS_NAME 50
  28. #define MAX_DSP_INIT_ATTEMPTS 16
  29. #define FENCE_WAIT_SIGNAL_TIMEOUT 100
  30. #define FENCE_WAIT_SIGNAL_RETRY_TIMES 20
  31. #define FENCE_BIT (1ULL << 63)
  32. #define FENCE_DMM_ICA_ENABLED_IDX 0
  33. #define FENCE_DMM_DS_IDX 1
  34. #define FENCE_DMM_OUTPUT_IDX 7
  35. #define SYS_MSG_START HAL_SYS_INIT_DONE
  36. #define SYS_MSG_END HAL_SYS_ERROR
  37. #define SESSION_MSG_START HAL_SESSION_EVENT_CHANGE
  38. #define SESSION_MSG_END HAL_SESSION_ERROR
  39. #define SYS_MSG_INDEX(__msg) (__msg - SYS_MSG_START)
  40. #define SESSION_MSG_INDEX(__msg) (__msg - SESSION_MSG_START)
  41. #define ARP_BUF_SIZE 0x300000
  42. #define CVP_RT_PRIO_THRESHOLD 1
  43. struct msm_cvp_inst;
  44. enum cvp_core_state {
  45. CVP_CORE_UNINIT = 0,
  46. CVP_CORE_INIT,
  47. CVP_CORE_INIT_DONE,
  48. };
  49. enum instance_state {
  50. MSM_CVP_CORE_UNINIT_DONE = 0x0001,
  51. MSM_CVP_CORE_INIT,
  52. MSM_CVP_CORE_INIT_DONE,
  53. MSM_CVP_OPEN,
  54. MSM_CVP_OPEN_DONE,
  55. MSM_CVP_CLOSE,
  56. MSM_CVP_CLOSE_DONE,
  57. MSM_CVP_CORE_UNINIT,
  58. MSM_CVP_CORE_INVALID
  59. };
  60. enum dsp_state {
  61. DSP_INVALID,
  62. DSP_UNINIT,
  63. DSP_PROBED,
  64. DSP_READY,
  65. DSP_SUSPEND,
  66. DSP_INACTIVE,
  67. };
  68. struct msm_cvp_common_data {
  69. char key[128];
  70. int value;
  71. };
  72. enum sku_version {
  73. SKU_VERSION_0 = 0,
  74. SKU_VERSION_1,
  75. SKU_VERSION_2,
  76. };
  77. enum vpu_version {
  78. VPU_VERSION_4 = 1,
  79. VPU_VERSION_5,
  80. };
  81. struct msm_cvp_ubwc_config_data {
  82. struct {
  83. u32 max_channel_override : 1;
  84. u32 mal_length_override : 1;
  85. u32 hb_override : 1;
  86. u32 bank_swzl_level_override : 1;
  87. u32 bank_spreading_override : 1;
  88. u32 reserved : 27;
  89. } override_bit_info;
  90. u32 max_channels;
  91. u32 mal_length;
  92. u32 highest_bank_bit;
  93. u32 bank_swzl_level;
  94. u32 bank_spreading;
  95. };
  96. struct msm_cvp_qos_setting {
  97. u32 axi_qos;
  98. u32 prioritylut_low;
  99. u32 prioritylut_high;
  100. u32 urgency_low;
  101. u32 urgency_low_ro;
  102. u32 dangerlut_low;
  103. u32 safelut_low;
  104. };
  105. struct msm_cvp_platform_data {
  106. struct msm_cvp_common_data *common_data;
  107. unsigned int common_data_length;
  108. unsigned int sku_version;
  109. uint32_t vpu_ver;
  110. unsigned int vm_id; /* pvm: 1; tvm: 2 */
  111. struct msm_cvp_ubwc_config_data *ubwc_config;
  112. struct msm_cvp_qos_setting *noc_qos;
  113. };
  114. struct cvp_kmem_cache {
  115. struct kmem_cache *cache;
  116. atomic_t nr_objs;
  117. };
  118. struct msm_cvp_drv {
  119. struct mutex lock;
  120. struct msm_cvp_core *cvp_core;
  121. struct dentry *debugfs_root;
  122. int thermal_level;
  123. u32 sku_version;
  124. struct cvp_kmem_cache msg_cache;
  125. struct cvp_kmem_cache frame_cache;
  126. struct cvp_kmem_cache buf_cache;
  127. struct cvp_kmem_cache smem_cache;
  128. char fw_version[CVP_VERSION_LENGTH];
  129. };
  130. enum profiling_points {
  131. SYS_INIT = 0,
  132. SESSION_INIT,
  133. LOAD_RESOURCES,
  134. FRAME_PROCESSING,
  135. FW_IDLE,
  136. MAX_PROFILING_POINTS,
  137. };
  138. struct cvp_clock_data {
  139. int buffer_counter;
  140. int load;
  141. int load_low;
  142. int load_norm;
  143. int load_high;
  144. int min_threshold;
  145. int max_threshold;
  146. unsigned long bitrate;
  147. unsigned long min_freq;
  148. unsigned long curr_freq;
  149. u32 ddr_bw;
  150. u32 sys_cache_bw;
  151. u32 operating_rate;
  152. bool low_latency_mode;
  153. bool turbo_mode;
  154. };
  155. struct cvp_profile_data {
  156. int start;
  157. int stop;
  158. int cumulative;
  159. char name[64];
  160. int sampling;
  161. int average;
  162. };
  163. struct msm_cvp_debug {
  164. struct cvp_profile_data pdata[MAX_PROFILING_POINTS];
  165. int profile;
  166. int samples;
  167. };
  168. enum msm_cvp_modes {
  169. CVP_SECURE = BIT(0),
  170. CVP_TURBO = BIT(1),
  171. CVP_THUMBNAIL = BIT(2),
  172. CVP_LOW_POWER = BIT(3),
  173. CVP_REALTIME = BIT(4),
  174. };
  175. #define MAX_NUM_MSGS_PER_SESSION 128
  176. struct cvp_session_msg {
  177. struct list_head node;
  178. struct cvp_hfi_msg_session_hdr_ext pkt;
  179. };
  180. struct cvp_session_queue {
  181. spinlock_t lock;
  182. enum queue_state state;
  183. unsigned int msg_count;
  184. struct list_head msgs;
  185. wait_queue_head_t wq;
  186. };
  187. struct cvp_session_prop {
  188. u32 type;
  189. u32 kernel_mask;
  190. u32 priority;
  191. u32 is_secure;
  192. u32 dsp_mask;
  193. u32 fthread_nr;
  194. u32 cycles[HFI_MAX_HW_THREADS];
  195. u32 fw_cycles;
  196. u32 op_cycles[HFI_MAX_HW_THREADS];
  197. u32 fw_op_cycles;
  198. u32 ddr_bw;
  199. u32 ddr_op_bw;
  200. u32 ddr_cache;
  201. u32 ddr_op_cache;
  202. u32 fps[HFI_MAX_HW_THREADS];
  203. u32 dump_offset;
  204. u32 dump_size;
  205. };
  206. enum cvp_event_t {
  207. CVP_NO_EVENT,
  208. CVP_SSR_EVENT = 1,
  209. CVP_SYS_ERROR_EVENT,
  210. CVP_MAX_CLIENTS_EVENT,
  211. CVP_HW_UNSUPPORTED_EVENT,
  212. CVP_INVALID_EVENT,
  213. CVP_DUMP_EVENT,
  214. };
  215. struct cvp_session_event {
  216. spinlock_t lock;
  217. enum cvp_event_t event;
  218. wait_queue_head_t wq;
  219. };
  220. #define MAX_ENTRIES 64
  221. struct smem_data {
  222. u32 size;
  223. u32 flags;
  224. u32 device_addr;
  225. u32 bitmap_index;
  226. u32 refcount;
  227. u32 pkt_type;
  228. u32 buf_idx;
  229. };
  230. struct cvp_buf_data {
  231. u32 device_addr;
  232. u32 size;
  233. };
  234. struct inst_snapshot {
  235. void *session;
  236. u32 smem_index;
  237. u32 dsp_index;
  238. u32 persist_index;
  239. struct smem_data smem_log[MAX_ENTRIES];
  240. struct cvp_buf_data dsp_buf_log[MAX_ENTRIES];
  241. struct cvp_buf_data persist_buf_log[MAX_ENTRIES];
  242. };
  243. struct cvp_noc_log {
  244. u32 used;
  245. u32 err_ctrl_swid_low;
  246. u32 err_ctrl_swid_high;
  247. u32 err_ctrl_mainctl_low;
  248. u32 err_ctrl_errvld_low;
  249. u32 err_ctrl_errclr_low;
  250. u32 err_ctrl_errlog0_low;
  251. u32 err_ctrl_errlog0_high;
  252. u32 err_ctrl_errlog1_low;
  253. u32 err_ctrl_errlog1_high;
  254. u32 err_ctrl_errlog2_low;
  255. u32 err_ctrl_errlog2_high;
  256. u32 err_ctrl_errlog3_low;
  257. u32 err_ctrl_errlog3_high;
  258. u32 err_core_swid_low;
  259. u32 err_core_swid_high;
  260. u32 err_core_mainctl_low;
  261. u32 err_core_errvld_low;
  262. u32 err_core_errclr_low;
  263. u32 err_core_errlog0_low;
  264. u32 err_core_errlog0_high;
  265. u32 err_core_errlog1_low;
  266. u32 err_core_errlog1_high;
  267. u32 err_core_errlog2_low;
  268. u32 err_core_errlog2_high;
  269. u32 err_core_errlog3_low;
  270. u32 err_core_errlog3_high;
  271. u32 arp_test_bus[16];
  272. u32 dma_test_bus[512];
  273. };
  274. struct cvp_debug_log {
  275. struct cvp_noc_log noc_log;
  276. u32 snapshot_index;
  277. struct inst_snapshot snapshot[16];
  278. };
  279. struct msm_cvp_core {
  280. struct mutex lock;
  281. struct mutex clk_lock;
  282. dev_t dev_num;
  283. struct cdev cdev;
  284. struct class *class;
  285. struct device *dev;
  286. struct cvp_hfi_ops *dev_ops;
  287. struct msm_cvp_platform_data *platform_data;
  288. struct msm_cvp_synx_ops *synx_ftbl;
  289. struct list_head instances;
  290. struct dentry *debugfs_root;
  291. enum cvp_core_state state;
  292. struct completion completions[SYS_MSG_END - SYS_MSG_START + 1];
  293. enum msm_cvp_hfi_type hfi_type;
  294. struct msm_cvp_platform_resources resources;
  295. struct msm_cvp_capability *capabilities;
  296. struct delayed_work fw_unload_work;
  297. struct work_struct ssr_work;
  298. enum hal_ssr_trigger_type ssr_type;
  299. u32 smmu_fault_count;
  300. u32 last_fault_addr;
  301. u32 ssr_count;
  302. u32 smem_leak_count;
  303. bool trigger_ssr;
  304. unsigned long curr_freq;
  305. unsigned long orig_core_sum;
  306. unsigned long bw_sum;
  307. atomic64_t kernel_trans_id;
  308. struct cvp_debug_log log;
  309. };
  310. struct msm_cvp_inst {
  311. struct list_head list;
  312. struct list_head dsp_list;
  313. struct mutex sync_lock, lock;
  314. struct msm_cvp_core *core;
  315. enum session_type session_type;
  316. u32 dsp_handle;
  317. struct task_struct *task;
  318. atomic_t smem_count;
  319. struct cvp_session_queue session_queue;
  320. struct cvp_session_queue session_queue_fence;
  321. struct cvp_session_event event_handler;
  322. void *session;
  323. enum instance_state state;
  324. struct msm_cvp_list freqs;
  325. struct msm_cvp_list persistbufs;
  326. struct cvp_dmamap_cache dma_cache;
  327. struct msm_cvp_list cvpdspbufs;
  328. struct msm_cvp_list cvpwnccbufs;
  329. struct msm_cvp_list frames;
  330. struct cvp_frame_bufs last_frame;
  331. struct cvp_frame_bufs unused_dsp_bufs;
  332. struct cvp_frame_bufs unused_wncc_bufs;
  333. u32 cvpwnccbufs_num;
  334. struct msm_cvp_wncc_buffer* cvpwnccbufs_table;
  335. struct completion completions[SESSION_MSG_END - SESSION_MSG_START + 1];
  336. struct dentry *debugfs_root;
  337. struct msm_cvp_debug debug;
  338. struct cvp_clock_data clk_data;
  339. enum msm_cvp_modes flags;
  340. struct msm_cvp_capability capability;
  341. struct kref kref;
  342. struct cvp_session_prop prop;
  343. /* error_code will be cleared after being returned to user mode */
  344. u32 error_code;
  345. /* prev_error_code saves value of error_code before it's cleared */
  346. u32 prev_error_code;
  347. struct synx_session *synx_session_id;
  348. struct cvp_fence_queue fence_cmd_queue;
  349. char proc_name[TASK_COMM_LEN];
  350. };
  351. extern struct msm_cvp_drv *cvp_driver;
  352. void cvp_handle_cmd_response(enum hal_command_response cmd, void *data);
  353. int msm_cvp_trigger_ssr(struct msm_cvp_core *core,
  354. enum hal_ssr_trigger_type type);
  355. int msm_cvp_noc_error_info(struct msm_cvp_core *core);
  356. void msm_cvp_comm_handle_thermal_event(void);
  357. void msm_cvp_ssr_handler(struct work_struct *work);
  358. /*
  359. * XXX: normally should be in msm_cvp_core.h, but that's meant for public APIs,
  360. * whereas this is private
  361. */
  362. int msm_cvp_destroy(struct msm_cvp_inst *inst);
  363. void *cvp_get_drv_data(struct device *dev);
  364. void *cvp_kmem_cache_zalloc(struct cvp_kmem_cache *k, gfp_t flags);
  365. void cvp_kmem_cache_free(struct cvp_kmem_cache *k, void *obj);
  366. #endif