cvp_hfi_api.h 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (c) 2018-2020, The Linux Foundation. All rights reserved.
  4. */
  5. #ifndef __CVP_HFI_API_H__
  6. #define __CVP_HFI_API_H__
  7. #include <linux/log2.h>
  8. #include <linux/platform_device.h>
  9. #include <linux/types.h>
  10. #include <linux/errno.h>
  11. #include <linux/hash.h>
  12. #include "msm_cvp_core.h"
  13. #include "msm_cvp_resources.h"
  14. #include "cvp_hfi_helper.h"
  15. #define CONTAINS(__a, __sz, __t) (\
  16. (__t >= __a) && \
  17. (__t < __a + __sz) \
  18. )
  19. #define OVERLAPS(__t, __tsz, __a, __asz) (\
  20. (__t <= __a) && \
  21. (__t + __tsz >= __a + __asz) \
  22. )
  23. #define CVP_VERSION_LENGTH 128
  24. /* 16 encoder and 16 decoder sessions */
  25. #define CVP_MAX_SESSIONS 32
  26. #define HFI_DFS_CONFIG_CMD_SIZE 38
  27. #define HFI_DFS_FRAME_CMD_SIZE 16
  28. #define HFI_DFS_FRAME_BUFFERS_OFFSET 8
  29. #define HFI_DFS_BUF_NUM 4
  30. #define HFI_DMM_CONFIG_CMD_SIZE 194
  31. #define HFI_DMM_BASIC_CONFIG_CMD_SIZE 51
  32. #define HFI_DMM_FRAME_CMD_SIZE 28
  33. #define HFI_DMM_FRAME_BUFFERS_OFFSET 12
  34. #define HFI_DMM_BUF_NUM 8
  35. #define HFI_PERSIST_CMD_SIZE 11
  36. #define HFI_PERSIST_BUFFERS_OFFSET 7
  37. #define HFI_PERSIST_BUF_NUM 2
  38. #define HFI_DS_CMD_SIZE 50
  39. #define HFI_DS_BUFFERS_OFFSET 44
  40. #define HFI_DS_BUF_NUM 3
  41. #define HFI_OF_CONFIG_CMD_SIZE 34
  42. #define HFI_OF_FRAME_CMD_SIZE 24
  43. #define HFI_OF_BUFFERS_OFFSET 8
  44. #define HFI_OF_BUF_NUM 8
  45. #define HFI_ODT_CONFIG_CMD_SIZE 23
  46. #define HFI_ODT_FRAME_CMD_SIZE 33
  47. #define HFI_ODT_BUFFERS_OFFSET 11
  48. #define HFI_ODT_BUF_NUM 11
  49. #define HFI_OD_CONFIG_CMD_SIZE 24
  50. #define HFI_OD_FRAME_CMD_SIZE 12
  51. #define HFI_OD_BUFFERS_OFFSET 6
  52. #define HFI_OD_BUF_NUM 3
  53. #define HFI_NCC_CONFIG_CMD_SIZE 47
  54. #define HFI_NCC_FRAME_CMD_SIZE 22
  55. #define HFI_NCC_BUFFERS_OFFSET 8
  56. #define HFI_NCC_BUF_NUM 7
  57. #define HFI_ICA_CONFIG_CMD_SIZE 127
  58. #define HFI_ICA_FRAME_CMD_SIZE 14
  59. #define HFI_ICA_BUFFERS_OFFSET 6
  60. #define HFI_ICA_BUF_NUM 4
  61. #define HFI_HCD_CONFIG_CMD_SIZE 46
  62. #define HFI_HCD_FRAME_CMD_SIZE 18
  63. #define HFI_HCD_BUFFERS_OFFSET 12
  64. #define HFI_HCD_BUF_NUM 3
  65. #define HFI_DCM_CONFIG_CMD_SIZE 20
  66. #define HFI_DCM_FRAME_CMD_SIZE 19
  67. #define HFI_DCM_BUFFERS_OFFSET 9
  68. #define HFI_DCM_BUF_NUM 5
  69. #define HFI_PYS_HCD_CONFIG_CMD_SIZE 461
  70. #define HFI_PYS_HCD_FRAME_CMD_SIZE 66
  71. #define HFI_PYS_HCD_BUFFERS_OFFSET 14
  72. #define HFI_PYS_HCD_BUF_NUM 26
  73. #define HFI_FD_CONFIG_CMD_SIZE 28
  74. #define HFI_FD_FRAME_CMD_SIZE 10
  75. #define HFI_FD_BUFFERS_OFFSET 6
  76. #define HFI_FD_BUF_NUM 2
  77. #define HFI_MODEL_CMD_SIZE 9
  78. #define HFI_MODEL_BUFFERS_OFFSET 7
  79. #define HFI_MODEL_BUF_NUM 1
  80. #define HFI_VERSION_MAJOR_MASK 0xFF000000
  81. #define HFI_VERSION_MAJOR_SHFIT 24
  82. #define HFI_VERSION_MINOR_MASK 0x00FFFFE0
  83. #define HFI_VERSION_MINOR_SHIFT 5
  84. #define HFI_VERSION_BRANCH_MASK 0x0000001F
  85. #define HFI_VERSION_BRANCH_SHIFT 0
  86. enum cvp_status {
  87. CVP_ERR_NONE = 0x0,
  88. CVP_ERR_FAIL = 0x80000000,
  89. CVP_ERR_ALLOC_FAIL,
  90. CVP_ERR_ILLEGAL_OP,
  91. CVP_ERR_BAD_PARAM,
  92. CVP_ERR_BAD_HANDLE,
  93. CVP_ERR_NOT_SUPPORTED,
  94. CVP_ERR_BAD_STATE,
  95. CVP_ERR_MAX_CLIENTS,
  96. CVP_ERR_IFRAME_EXPECTED,
  97. CVP_ERR_HW_FATAL,
  98. CVP_ERR_BITSTREAM_ERR,
  99. CVP_ERR_INDEX_NOMORE,
  100. CVP_ERR_SEQHDR_PARSE_FAIL,
  101. CVP_ERR_INSUFFICIENT_BUFFER,
  102. CVP_ERR_BAD_POWER_STATE,
  103. CVP_ERR_NO_VALID_SESSION,
  104. CVP_ERR_TIMEOUT,
  105. CVP_ERR_CMDQFULL,
  106. CVP_ERR_START_CODE_NOT_FOUND,
  107. CVP_ERR_NOC_ERROR,
  108. CVP_ERR_CLIENT_PRESENT = 0x90000001,
  109. CVP_ERR_CLIENT_FATAL,
  110. CVP_ERR_CMD_QUEUE_FULL,
  111. CVP_ERR_UNUSED = 0x10000000
  112. };
  113. enum hal_property {
  114. HAL_UNUSED_PROPERTY = 0xFFFFFFFF,
  115. };
  116. enum hal_ssr_trigger_type {
  117. SSR_ERR_FATAL = 1,
  118. SSR_SW_DIV_BY_ZERO,
  119. SSR_HW_WDOG_IRQ,
  120. SSR_SESSION_ABORT,
  121. };
  122. enum hal_intra_refresh_mode {
  123. HAL_INTRA_REFRESH_NONE,
  124. HAL_INTRA_REFRESH_CYCLIC,
  125. HAL_INTRA_REFRESH_RANDOM,
  126. HAL_UNUSED_INTRA = 0x10000000,
  127. };
  128. enum cvp_resource_id {
  129. CVP_RESOURCE_NONE,
  130. CVP_RESOURCE_SYSCACHE,
  131. CVP_UNUSED_RESOURCE = 0x10000000,
  132. };
  133. struct cvp_resource_hdr {
  134. enum cvp_resource_id resource_id;
  135. void *resource_handle;
  136. };
  137. struct cvp_hal_fw_info {
  138. char version[CVP_VERSION_LENGTH];
  139. phys_addr_t base_addr;
  140. int register_base;
  141. int register_size;
  142. int irq;
  143. };
  144. enum hal_event_type {
  145. HAL_EVENT_SEQ_CHANGED_SUFFICIENT_RESOURCES,
  146. HAL_EVENT_SEQ_CHANGED_INSUFFICIENT_RESOURCES,
  147. HAL_EVENT_RELEASE_BUFFER_REFERENCE,
  148. HAL_UNUSED_SEQCHG = 0x10000000,
  149. };
  150. /* HAL Response */
  151. #define IS_HAL_SYS_CMD(cmd) ((cmd) >= HAL_SYS_INIT_DONE && \
  152. (cmd) <= HAL_SYS_ERROR)
  153. #define IS_HAL_SESSION_CMD(cmd) ((cmd) >= HAL_SESSION_EVENT_CHANGE && \
  154. (cmd) <= HAL_SESSION_ERROR)
  155. enum hal_command_response {
  156. HAL_NO_RESP,
  157. HAL_SYS_INIT_DONE,
  158. HAL_SYS_SET_RESOURCE_DONE,
  159. HAL_SYS_RELEASE_RESOURCE_DONE,
  160. HAL_SYS_PING_ACK_DONE,
  161. HAL_SYS_PC_PREP_DONE,
  162. HAL_SYS_IDLE,
  163. HAL_SYS_DEBUG,
  164. HAL_SYS_WATCHDOG_TIMEOUT,
  165. HAL_SYS_ERROR,
  166. /* SESSION COMMANDS_DONE */
  167. HAL_SESSION_EVENT_CHANGE,
  168. HAL_SESSION_INIT_DONE,
  169. HAL_SESSION_END_DONE,
  170. HAL_SESSION_SET_BUFFER_DONE,
  171. HAL_SESSION_ABORT_DONE,
  172. HAL_SESSION_STOP_DONE,
  173. HAL_SESSION_CVP_OPERATION_CONFIG,
  174. HAL_SESSION_FLUSH_DONE,
  175. HAL_SESSION_SUSPEND_DONE,
  176. HAL_SESSION_RESUME_DONE,
  177. HAL_SESSION_SET_PROP_DONE,
  178. HAL_SESSION_GET_PROP_DONE,
  179. HAL_SESSION_RELEASE_BUFFER_DONE,
  180. HAL_SESSION_REGISTER_BUFFER_DONE,
  181. HAL_SESSION_UNREGISTER_BUFFER_DONE,
  182. HAL_SESSION_RELEASE_RESOURCE_DONE,
  183. HAL_SESSION_DFS_CONFIG_CMD_DONE,
  184. HAL_SESSION_DFS_FRAME_CMD_DONE,
  185. HAL_SESSION_DMM_CONFIG_CMD_DONE,
  186. HAL_SESSION_DMM_PARAMS_CMD_DONE,
  187. HAL_SESSION_DMM_FRAME_CMD_DONE,
  188. HAL_SESSION_WARP_CONFIG_CMD_DONE,
  189. HAL_SESSION_WARP_DS_PARAMS_CMD_DONE,
  190. HAL_SESSION_WARP_FRAME_CMD_DONE,
  191. HAL_SESSION_WARP_NCC_CONFIG_CMD_DONE,
  192. HAL_SESSION_WARP_NCC_FRAME_CMD_DONE,
  193. HAL_SESSION_TME_CONFIG_CMD_DONE,
  194. HAL_SESSION_ODT_CONFIG_CMD_DONE,
  195. HAL_SESSION_OD_CONFIG_CMD_DONE,
  196. HAL_SESSION_NCC_CONFIG_CMD_DONE,
  197. HAL_SESSION_ICA_CONFIG_CMD_DONE,
  198. HAL_SESSION_HCD_CONFIG_CMD_DONE,
  199. HAL_SESSION_DC_CONFIG_CMD_DONE,
  200. HAL_SESSION_DCM_CONFIG_CMD_DONE,
  201. HAL_SESSION_PYS_HCD_CONFIG_CMD_DONE,
  202. HAL_SESSION_FD_CONFIG_CMD_DONE,
  203. HAL_SESSION_PERSIST_SET_DONE,
  204. HAL_SESSION_PERSIST_REL_DONE,
  205. HAL_SESSION_MODEL_BUF_CMD_DONE,
  206. HAL_SESSION_ICA_FRAME_CMD_DONE,
  207. HAL_SESSION_FD_FRAME_CMD_DONE,
  208. HAL_SESSION_PROPERTY_INFO,
  209. HAL_SESSION_ERROR,
  210. HAL_RESPONSE_UNUSED = 0x10000000,
  211. };
  212. struct msm_cvp_capability {
  213. u32 reserved[183];
  214. };
  215. struct cvp_hal_sys_init_done {
  216. u32 dec_codec_supported;
  217. u32 enc_codec_supported;
  218. u32 codec_count;
  219. struct msm_cvp_capability *capabilities;
  220. u32 max_sessions_supported;
  221. };
  222. struct cvp_hal_session_init_done {
  223. struct msm_cvp_capability capability;
  224. };
  225. struct msm_cvp_cb_cmd_done {
  226. u32 device_id;
  227. void *session_id;
  228. enum cvp_status status;
  229. u32 size;
  230. union {
  231. struct cvp_hfi_msg_session_hdr msg_hdr;
  232. struct cvp_resource_hdr resource_hdr;
  233. struct cvp_hal_sys_init_done sys_init_done;
  234. struct cvp_hal_session_init_done session_init_done;
  235. u32 buffer_addr;
  236. } data;
  237. };
  238. struct msm_cvp_cb_data_done {
  239. u32 device_id;
  240. void *session_id;
  241. enum cvp_status status;
  242. u32 size;
  243. u32 client_data;
  244. };
  245. struct msm_cvp_cb_info {
  246. enum hal_command_response response_type;
  247. union {
  248. struct msm_cvp_cb_cmd_done cmd;
  249. struct msm_cvp_cb_data_done data;
  250. } response;
  251. };
  252. enum msm_cvp_hfi_type {
  253. CVP_HFI_IRIS,
  254. };
  255. enum msm_cvp_thermal_level {
  256. CVP_THERMAL_NORMAL = 0,
  257. CVP_THERMAL_LOW,
  258. CVP_THERMAL_HIGH,
  259. CVP_THERMAL_CRITICAL
  260. };
  261. struct msm_cvp_gov_data {
  262. struct cvp_bus_vote_data *data;
  263. u32 data_count;
  264. };
  265. enum msm_cvp_power_mode {
  266. CVP_POWER_NORMAL = 0,
  267. CVP_POWER_LOW,
  268. CVP_POWER_TURBO
  269. };
  270. struct cvp_bus_vote_data {
  271. u32 domain;
  272. u32 ddr_bw;
  273. u32 sys_cache_bw;
  274. enum msm_cvp_power_mode power_mode;
  275. bool use_sys_cache;
  276. };
  277. struct cvp_hal_cmd_sys_get_property_packet {
  278. u32 size;
  279. u32 packet_type;
  280. u32 num_properties;
  281. u32 rg_property_data[1];
  282. };
  283. #define call_hfi_op(q, op, args...) \
  284. (((q) && (q)->op) ? ((q)->op(args)) : 0)
  285. struct msm_cvp_hfi_defs {
  286. unsigned int size;
  287. unsigned int type;
  288. unsigned int buf_offset;
  289. unsigned int buf_num;
  290. enum hal_command_response resp;
  291. };
  292. struct cvp_hfi_device {
  293. void *hfi_device_data;
  294. /*Add function pointers for all the hfi functions below*/
  295. int (*core_init)(void *device);
  296. int (*core_release)(void *device);
  297. int (*core_trigger_ssr)(void *device, enum hal_ssr_trigger_type);
  298. int (*session_init)(void *device, void *session_id, void **new_session);
  299. int (*session_end)(void *session);
  300. int (*session_abort)(void *session);
  301. int (*session_set_buffers)(void *sess, u32 iova, u32 size);
  302. int (*session_release_buffers)(void *sess);
  303. int (*session_send)(void *sess, struct eva_kmd_hfi_packet *in_pkt);
  304. int (*session_flush)(void *sess);
  305. int (*scale_clocks)(void *dev, u32 freq);
  306. int (*vote_bus)(void *dev, struct cvp_bus_vote_data *data,
  307. int num_data);
  308. int (*get_fw_info)(void *dev, struct cvp_hal_fw_info *fw_info);
  309. int (*session_clean)(void *sess);
  310. int (*get_core_capabilities)(void *dev);
  311. int (*suspend)(void *dev);
  312. int (*resume)(void *dev);
  313. int (*flush_debug_queue)(void *dev);
  314. int (*noc_error_info)(void *dev);
  315. int (*validate_session)(void *sess, const char *func);
  316. };
  317. typedef void (*hfi_cmd_response_callback) (enum hal_command_response cmd,
  318. void *data);
  319. typedef void (*msm_cvp_callback) (enum hal_command_response response,
  320. void *callback);
  321. struct cvp_hfi_device *cvp_hfi_initialize(enum msm_cvp_hfi_type hfi_type,
  322. u32 device_id, struct msm_cvp_platform_resources *res,
  323. hfi_cmd_response_callback callback);
  324. void cvp_hfi_deinitialize(enum msm_cvp_hfi_type hfi_type,
  325. struct cvp_hfi_device *hdev);
  326. int get_pkt_index(struct cvp_hal_session_cmd_pkt *hdr);
  327. int get_signal_from_pkt_type(unsigned int type);
  328. int get_hfi_version(void);
  329. unsigned int get_msg_size(struct cvp_hfi_msg_session_hdr *hdr);
  330. unsigned int get_msg_session_id(void *msg);
  331. unsigned int get_msg_errorcode(void *msg);
  332. int get_msg_opconfigs(void *msg, unsigned int *session_id,
  333. unsigned int *error_type, unsigned int *config_id);
  334. extern const struct msm_cvp_hfi_defs cvp_hfi_defs[];
  335. #endif /*__CVP_HFI_API_H__ */