msm_cvp_internal.h 9.1 KB

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