cvp_hfi_api.h 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379
  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_SGM_OF_CONFIG_CMD_DONE,
  184. HAL_SESSION_DFS_CONFIG_CMD_DONE,
  185. HAL_SESSION_DMM_CONFIG_CMD_DONE,
  186. HAL_SESSION_DMM_PARAMS_CMD_DONE,
  187. HAL_SESSION_WARP_CONFIG_CMD_DONE,
  188. HAL_SESSION_WARP_DS_PARAMS_CMD_DONE,
  189. HAL_SESSION_WARP_NCC_CONFIG_CMD_DONE,
  190. HAL_SESSION_TME_CONFIG_CMD_DONE,
  191. HAL_SESSION_ODT_CONFIG_CMD_DONE,
  192. HAL_SESSION_OD_CONFIG_CMD_DONE,
  193. HAL_SESSION_NCC_CONFIG_CMD_DONE,
  194. HAL_SESSION_ICA_CONFIG_CMD_DONE,
  195. HAL_SESSION_HCD_CONFIG_CMD_DONE,
  196. HAL_SESSION_DC_CONFIG_CMD_DONE,
  197. HAL_SESSION_DCM_CONFIG_CMD_DONE,
  198. HAL_SESSION_PYS_HCD_CONFIG_CMD_DONE,
  199. HAL_SESSION_FD_CONFIG_CMD_DONE,
  200. HAL_SESSION_PERSIST_SET_DONE,
  201. HAL_SESSION_PERSIST_REL_DONE,
  202. HAL_SESSION_MODEL_BUF_CMD_DONE,
  203. HAL_SESSION_PROPERTY_INFO,
  204. HAL_SESSION_ERROR,
  205. HAL_RESPONSE_UNUSED = 0x10000000,
  206. };
  207. struct msm_cvp_capability {
  208. u32 reserved[183];
  209. };
  210. struct cvp_hal_sys_init_done {
  211. u32 dec_codec_supported;
  212. u32 enc_codec_supported;
  213. u32 codec_count;
  214. struct msm_cvp_capability *capabilities;
  215. u32 max_sessions_supported;
  216. };
  217. struct cvp_hal_session_init_done {
  218. struct msm_cvp_capability capability;
  219. };
  220. struct msm_cvp_cb_cmd_done {
  221. u32 device_id;
  222. void *session_id;
  223. enum cvp_status status;
  224. u32 size;
  225. union {
  226. struct cvp_hfi_msg_session_hdr msg_hdr;
  227. struct cvp_resource_hdr resource_hdr;
  228. struct cvp_hal_sys_init_done sys_init_done;
  229. struct cvp_hal_session_init_done session_init_done;
  230. u32 buffer_addr;
  231. } data;
  232. };
  233. struct msm_cvp_cb_data_done {
  234. u32 device_id;
  235. void *session_id;
  236. enum cvp_status status;
  237. u32 size;
  238. u32 client_data;
  239. };
  240. struct msm_cvp_cb_info {
  241. enum hal_command_response response_type;
  242. union {
  243. struct msm_cvp_cb_cmd_done cmd;
  244. struct msm_cvp_cb_data_done data;
  245. } response;
  246. };
  247. enum msm_cvp_hfi_type {
  248. CVP_HFI_IRIS,
  249. };
  250. enum msm_cvp_thermal_level {
  251. CVP_THERMAL_NORMAL = 0,
  252. CVP_THERMAL_LOW,
  253. CVP_THERMAL_HIGH,
  254. CVP_THERMAL_CRITICAL
  255. };
  256. struct msm_cvp_gov_data {
  257. struct cvp_bus_vote_data *data;
  258. u32 data_count;
  259. };
  260. enum msm_cvp_power_mode {
  261. CVP_POWER_NORMAL = 0,
  262. CVP_POWER_LOW,
  263. CVP_POWER_TURBO
  264. };
  265. struct cvp_bus_vote_data {
  266. u32 domain;
  267. u32 ddr_bw;
  268. u32 sys_cache_bw;
  269. enum msm_cvp_power_mode power_mode;
  270. bool use_sys_cache;
  271. };
  272. struct cvp_hal_cmd_sys_get_property_packet {
  273. u32 size;
  274. u32 packet_type;
  275. u32 num_properties;
  276. u32 rg_property_data[1];
  277. };
  278. #define call_hfi_op(q, op, args...) \
  279. (((q) && (q)->op) ? ((q)->op(args)) : 0)
  280. struct msm_cvp_hfi_defs {
  281. unsigned int size;
  282. unsigned int type;
  283. unsigned int buf_offset;
  284. unsigned int buf_num;
  285. enum hal_command_response resp;
  286. };
  287. struct cvp_hfi_device {
  288. void *hfi_device_data;
  289. /*Add function pointers for all the hfi functions below*/
  290. int (*core_init)(void *device);
  291. int (*core_release)(void *device);
  292. int (*core_trigger_ssr)(void *device, enum hal_ssr_trigger_type);
  293. int (*session_init)(void *device, void *session_id, void **new_session);
  294. int (*session_end)(void *session);
  295. int (*session_abort)(void *session);
  296. int (*session_set_buffers)(void *sess, u32 iova, u32 size);
  297. int (*session_release_buffers)(void *sess);
  298. int (*session_send)(void *sess, struct eva_kmd_hfi_packet *in_pkt);
  299. int (*session_flush)(void *sess);
  300. int (*scale_clocks)(void *dev, u32 freq);
  301. int (*vote_bus)(void *dev, struct cvp_bus_vote_data *data,
  302. int num_data);
  303. int (*get_fw_info)(void *dev, struct cvp_hal_fw_info *fw_info);
  304. int (*session_clean)(void *sess);
  305. int (*get_core_capabilities)(void *dev);
  306. int (*suspend)(void *dev);
  307. int (*resume)(void *dev);
  308. int (*flush_debug_queue)(void *dev);
  309. int (*noc_error_info)(void *dev);
  310. int (*validate_session)(void *sess, const char *func);
  311. };
  312. typedef void (*hfi_cmd_response_callback) (enum hal_command_response cmd,
  313. void *data);
  314. typedef void (*msm_cvp_callback) (enum hal_command_response response,
  315. void *callback);
  316. struct cvp_hfi_device *cvp_hfi_initialize(enum msm_cvp_hfi_type hfi_type,
  317. u32 device_id, struct msm_cvp_platform_resources *res,
  318. hfi_cmd_response_callback callback);
  319. void cvp_hfi_deinitialize(enum msm_cvp_hfi_type hfi_type,
  320. struct cvp_hfi_device *hdev);
  321. int get_pkt_index(struct cvp_hal_session_cmd_pkt *hdr);
  322. int get_signal_from_pkt_type(unsigned int type);
  323. int get_hfi_version(void);
  324. unsigned int get_msg_size(struct cvp_hfi_msg_session_hdr *hdr);
  325. unsigned int get_msg_session_id(void *msg);
  326. unsigned int get_msg_errorcode(void *msg);
  327. int get_msg_opconfigs(void *msg, unsigned int *session_id,
  328. unsigned int *error_type, unsigned int *config_id);
  329. extern const struct msm_cvp_hfi_defs cvp_hfi_defs[];
  330. #endif /*__CVP_HFI_API_H__ */