msm_cvp_internal.h 8.6 KB

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