msm_cvp_internal.h 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412
  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_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. struct msm_cvp_ubwc_config_data *ubwc_config;
  111. };
  112. struct msm_cvp_drv {
  113. struct mutex lock;
  114. struct list_head cores;
  115. int num_cores;
  116. struct dentry *debugfs_root;
  117. int thermal_level;
  118. u32 sku_version;
  119. struct kmem_cache *msg_cache;
  120. struct kmem_cache *frame_cache;
  121. struct kmem_cache *buf_cache;
  122. struct kmem_cache *smem_cache;
  123. char fw_version[CVP_VERSION_LENGTH];
  124. };
  125. enum profiling_points {
  126. SYS_INIT = 0,
  127. SESSION_INIT,
  128. LOAD_RESOURCES,
  129. FRAME_PROCESSING,
  130. FW_IDLE,
  131. MAX_PROFILING_POINTS,
  132. };
  133. struct cvp_clock_data {
  134. int buffer_counter;
  135. int load;
  136. int load_low;
  137. int load_norm;
  138. int load_high;
  139. int min_threshold;
  140. int max_threshold;
  141. unsigned long bitrate;
  142. unsigned long min_freq;
  143. unsigned long curr_freq;
  144. u32 ddr_bw;
  145. u32 sys_cache_bw;
  146. u32 operating_rate;
  147. u32 core_id;
  148. bool low_latency_mode;
  149. bool turbo_mode;
  150. };
  151. struct cvp_profile_data {
  152. int start;
  153. int stop;
  154. int cumulative;
  155. char name[64];
  156. int sampling;
  157. int average;
  158. };
  159. struct msm_cvp_debug {
  160. struct cvp_profile_data pdata[MAX_PROFILING_POINTS];
  161. int profile;
  162. int samples;
  163. };
  164. enum msm_cvp_modes {
  165. CVP_SECURE = BIT(0),
  166. CVP_TURBO = BIT(1),
  167. CVP_THUMBNAIL = BIT(2),
  168. CVP_LOW_POWER = BIT(3),
  169. CVP_REALTIME = BIT(4),
  170. };
  171. #define MAX_NUM_MSGS_PER_SESSION 128
  172. #define CVP_MAX_WAIT_TIME 2000
  173. struct cvp_session_msg {
  174. struct list_head node;
  175. struct cvp_hfi_msg_session_hdr_ext pkt;
  176. };
  177. struct cvp_session_queue {
  178. spinlock_t lock;
  179. enum queue_state state;
  180. unsigned int msg_count;
  181. struct list_head msgs;
  182. wait_queue_head_t wq;
  183. };
  184. #define CVP_CYCLE_STAT_SIZE 8
  185. struct cvp_cycle_stat {
  186. u32 busy[CVP_CYCLE_STAT_SIZE];
  187. u32 total;
  188. u32 idx;
  189. u32 size;
  190. };
  191. struct cvp_cycle_info {
  192. u32 sum_fps[HFI_MAX_HW_THREADS];
  193. u32 hi_ctrl_lim[HFI_MAX_HW_THREADS];
  194. u32 lo_ctrl_lim[HFI_MAX_HW_THREADS];
  195. struct cvp_cycle_stat cycle[HFI_MAX_HW_THREADS];
  196. unsigned long conf_freq;
  197. };
  198. struct cvp_session_prop {
  199. u32 type;
  200. u32 kernel_mask;
  201. u32 priority;
  202. u32 is_secure;
  203. u32 dsp_mask;
  204. u32 fthread_nr;
  205. u32 fdu_cycles;
  206. u32 od_cycles;
  207. u32 mpu_cycles;
  208. u32 ica_cycles;
  209. u32 fw_cycles;
  210. u32 fdu_op_cycles;
  211. u32 od_op_cycles;
  212. u32 mpu_op_cycles;
  213. u32 ica_op_cycles;
  214. u32 fw_op_cycles;
  215. u32 ddr_bw;
  216. u32 ddr_op_bw;
  217. u32 ddr_cache;
  218. u32 ddr_op_cache;
  219. u32 fps[HFI_MAX_HW_THREADS];
  220. u32 dump_offset;
  221. u32 dump_size;
  222. };
  223. enum cvp_event_t {
  224. CVP_NO_EVENT,
  225. CVP_SSR_EVENT = 1,
  226. CVP_SYS_ERROR_EVENT,
  227. CVP_MAX_CLIENTS_EVENT,
  228. CVP_HW_UNSUPPORTED_EVENT,
  229. CVP_INVALID_EVENT,
  230. CVP_DUMP_EVENT,
  231. };
  232. struct cvp_session_event {
  233. spinlock_t lock;
  234. enum cvp_event_t event;
  235. wait_queue_head_t wq;
  236. };
  237. #define MAX_ENTRIES 64
  238. struct smem_data {
  239. u32 size;
  240. u32 flags;
  241. u32 device_addr;
  242. u32 bitmap_index;
  243. u32 refcount;
  244. };
  245. struct cvp_buf_data {
  246. u32 device_addr;
  247. u32 size;
  248. };
  249. struct inst_snapshot {
  250. void *session;
  251. u32 smem_index;
  252. u32 dsp_index;
  253. u32 persist_index;
  254. struct smem_data smem_log[MAX_ENTRIES];
  255. struct cvp_buf_data dsp_buf_log[MAX_ENTRIES];
  256. struct cvp_buf_data persist_buf_log[MAX_ENTRIES];
  257. };
  258. struct cvp_noc_log {
  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 list_head instances;
  305. struct dentry *debugfs_root;
  306. enum cvp_core_state state;
  307. struct completion completions[SYS_MSG_END - SYS_MSG_START + 1];
  308. enum msm_cvp_hfi_type hfi_type;
  309. struct msm_cvp_platform_resources resources;
  310. struct msm_cvp_capability *capabilities;
  311. struct delayed_work fw_unload_work;
  312. struct work_struct ssr_work;
  313. enum hal_ssr_trigger_type ssr_type;
  314. u32 smmu_fault_count;
  315. u32 last_fault_addr;
  316. u32 ssr_count;
  317. bool trigger_ssr;
  318. unsigned long curr_freq;
  319. unsigned long orig_core_sum;
  320. struct cvp_cycle_info dyn_clk;
  321. atomic64_t kernel_trans_id;
  322. struct cvp_debug_log log;
  323. };
  324. struct msm_cvp_inst {
  325. struct list_head list;
  326. struct list_head dsp_list;
  327. struct mutex sync_lock, lock;
  328. struct msm_cvp_core *core;
  329. enum session_type session_type;
  330. u32 process_id;
  331. struct task_struct *task;
  332. struct cvp_session_queue session_queue;
  333. struct cvp_session_queue session_queue_fence;
  334. struct cvp_session_event event_handler;
  335. void *session;
  336. enum instance_state state;
  337. struct msm_cvp_list freqs;
  338. struct msm_cvp_list persistbufs;
  339. struct cvp_dmamap_cache dma_cache;
  340. struct msm_cvp_list cvpdspbufs;
  341. struct msm_cvp_list frames;
  342. struct completion completions[SESSION_MSG_END - SESSION_MSG_START + 1];
  343. struct dentry *debugfs_root;
  344. struct msm_cvp_debug debug;
  345. struct cvp_clock_data clk_data;
  346. enum msm_cvp_modes flags;
  347. struct msm_cvp_capability capability;
  348. struct kref kref;
  349. struct cvp_session_prop prop;
  350. u32 cur_cmd_type;
  351. struct synx_session synx_session_id;
  352. struct cvp_fence_queue fence_cmd_queue;
  353. };
  354. extern struct msm_cvp_drv *cvp_driver;
  355. void cvp_handle_cmd_response(enum hal_command_response cmd, void *data);
  356. int msm_cvp_trigger_ssr(struct msm_cvp_core *core,
  357. enum hal_ssr_trigger_type type);
  358. int msm_cvp_noc_error_info(struct msm_cvp_core *core);
  359. void msm_cvp_comm_handle_thermal_event(void);
  360. void msm_cvp_fw_unload_handler(struct work_struct *work);
  361. void msm_cvp_ssr_handler(struct work_struct *work);
  362. /*
  363. * XXX: normally should be in msm_cvp_core.h, but that's meant for public APIs,
  364. * whereas this is private
  365. */
  366. int msm_cvp_destroy(struct msm_cvp_inst *inst);
  367. void *cvp_get_drv_data(struct device *dev);
  368. #endif