msm_cvp_internal.h 9.3 KB

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