mtk_vcu.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  1. /*
  2. * Copyright (c) 2016 MediaTek Inc.
  3. * Copyright (C) 2021 XiaoMi, Inc.
  4. * Author: Andrew-CT Chen <andrew-ct.chen@mediatek.com>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License version 2 as
  8. * published by the Free Software Foundation.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. */
  15. #ifndef MTK_VCU_H
  16. #define MTK_VCU_H
  17. #include <aee.h>
  18. #include <linux/fdtable.h>
  19. #include <linux/platform_device.h>
  20. #ifdef CONFIG_MTK_AEE_FEATURE
  21. #define vcu_aee_print(string, args...) do {\
  22. char vcu_name[100];\
  23. int ret;\
  24. ret = snprintf(vcu_name, 100, "[VCU] "string, ##args); \
  25. if (ret > 0)\
  26. aee_kernel_warning_api(__FILE__, __LINE__, \
  27. DB_OPT_MMPROFILE_BUFFER | DB_OPT_NE_JBT_TRACES, \
  28. vcu_name, "[VCU] error:"string, ##args); \
  29. pr_info("[VCU] error:"string, ##args); \
  30. } while (0)
  31. #else
  32. #define vcu_aee_print(string, args...) do {\
  33. pr_info("[VCU] error:"string, ##args); \
  34. } while (0)
  35. #endif
  36. /**
  37. * VCU (Video Communication/Controller Unit)
  38. * is a tiny processor controlling video hardware
  39. * related to video codec, scaling and color format converting.
  40. * VCU interfaces with other blocks by share memory and interrupt.
  41. **/
  42. typedef int (*ipi_handler_t)(void *data,
  43. unsigned int len,
  44. void *priv);
  45. /**
  46. * enum ipi_id - the id of inter-processor interrupt
  47. *
  48. * @IPI_VCU_INIT: The interrupt from vcu is to notfiy kernel
  49. * VCU initialization completed.
  50. * IPI_VCU_INIT is sent from VCU when firmware is
  51. * loaded. AP doesn't need to send IPI_VCU_INIT
  52. * command to VCU.
  53. * For other IPI below, AP should send the request
  54. * to VCU to trigger the interrupt.
  55. * @IPI_VDEC_COMMON: The interrupt from vcu is to notify kernel to
  56. * handle video codecs job, and vice versa.
  57. * @IPI_VDEC_H264: The interrupt from vcu is to notify kernel to
  58. * handle H264 vidoe decoder job, and vice versa.
  59. * Decode output format is always MT21 no matter what
  60. * the input format is.
  61. * @IPI_VDEC_H265: The interrupt from vcu is to notify kernel to
  62. * handle H265 vidoe decoder job, and vice versa.
  63. * Decode output format is always MT21 no matter what
  64. * the input format is.
  65. * @IPI_VDEC_VP8: The interrupt from is to notify kernel to
  66. * handle VP8 video decoder job, and vice versa.
  67. * Decode output format is always MT21 no matter what
  68. * the input format is.
  69. * @IPI_VDEC_VP9: The interrupt from vcu is to notify kernel to
  70. * handle VP9 video decoder job, and vice versa.
  71. * Decode output format is always MT21 no matter what
  72. * the input format is.
  73. * @IPI_VDEC_MPEG4: The interrupt from vcu is to notify kernel to
  74. * handle MPEG4 video decoder job, and vice versa.
  75. * Decode output format is always MT21 no matter what
  76. * the input format is.
  77. * @IPI_VDEC_MPEG12: The interrupt from vcu is to notify kernel to
  78. * handle MPEG1/2 video decoder job, and vice versa.
  79. * Decode output format is always MT21 no matter what
  80. * the input format is.
  81. * @IPI_VDEC_WMV: The interrupt from vcu is to notify kernel to
  82. * handle WMV video decoder job, and vice versa.
  83. * Decode output format is always MT21 no matter what
  84. * the input format is.
  85. * @IPI_VDEC_RV30: The interrupt from vcu is to notify kernel to
  86. * handle RV30 video decoder job, and vice versa.
  87. * Decode output format is always MT21 no matter what
  88. * the input format is.
  89. * @IPI_VDEC_RV40: The interrupt from vcu is to notify kernel to
  90. * handle RV40 video decoder job, and vice versa.
  91. * Decode output format is always MT21 no matter what
  92. * the input format is.
  93. * @IPI_VDEC_AV1: The interrupt from vcu is to notify kernel to
  94. * handle AV1 video decoder job, and vice versa.
  95. * Decode output format is always MT21 no matter what
  96. * the input format is.
  97. * @IPI_VENC_COMMON: The interrupt from vcu is to notify kernel to
  98. * handle video codecs job, and vice versa.
  99. * @IPI_VENC_H264: The interrupt from vcu is to notify kernel to
  100. * handle H264 video encoder job, and vice versa.
  101. * @IPI_VENC_H265: The interrupt from vcu is to notify kernel to
  102. * handle H265 video encoder job, and vice versa.
  103. * @IPI_VENC_VP8: The interrupt fro vcu is to notify kernel to
  104. * handle VP8 video encoder job,, and vice versa.
  105. * @IPI_VENC_MPEG4 The interrupt from vcu is to notify kernel to
  106. * handle MPEG4 video encoder job, and vice versa.
  107. * @IPI_VENC_HYBRID_H264: The interrupt from vcu is to notify kernel
  108. * to handle hybrid H264 video encoder job, and vice versa.
  109. * @IPI_MDP: The interrupt from vcu is to notify kernel to
  110. * handle MDP (Media Data Path) job, and vice versa.
  111. * @IPI_CAMERA: The interrupt from vcu is to notify kernel to
  112. * handle camera job, and vice versa.
  113. * @IPI_MAX: The maximum IPI number
  114. */
  115. enum ipi_id {
  116. IPI_VCU_INIT = 0,
  117. IPI_VDEC_COMMON,
  118. IPI_VDEC_H264,
  119. IPI_VDEC_H265,
  120. IPI_VDEC_HEIF,
  121. IPI_VDEC_VP8,
  122. IPI_VDEC_VP9,
  123. IPI_VDEC_MPEG4,
  124. IPI_VDEC_H263,
  125. IPI_VDEC_S263,
  126. IPI_VDEC_XVID,
  127. IPI_VDEC_MPEG12,
  128. IPI_VDEC_WMV,
  129. IPI_VDEC_RV30,
  130. IPI_VDEC_RV40,
  131. IPI_VDEC_AV1,
  132. IPI_VENC_COMMON,
  133. IPI_VENC_H264,
  134. IPI_VENC_H265,
  135. IPI_VENC_HEIF,
  136. IPI_VENC_VP8,
  137. IPI_VENC_MPEG4,
  138. IPI_VENC_HYBRID_H264,
  139. IPI_VENC_H263,
  140. IPI_MDP,
  141. IPI_MDP_1,
  142. IPI_MDP_2,
  143. IPI_MDP_3,
  144. IPI_CAMERA,
  145. IPI_MAX = 50,
  146. };
  147. enum vcu_codec_type {
  148. VCU_VDEC = 0,
  149. VCU_VENC,
  150. VCU_CODEC_MAX
  151. };
  152. /**
  153. * vcu_ipi_register - register an ipi function
  154. *
  155. * @pdev: VCU platform device
  156. * @id: IPI ID
  157. * @handler: IPI handler
  158. * @name: IPI name
  159. * @priv: private data for IPI handler
  160. *
  161. * Register an ipi function to receive ipi interrupt from VCU.
  162. *
  163. * Return: Return 0 if ipi registers successfully, otherwise it is failed.
  164. */
  165. int vcu_ipi_register(struct platform_device *pdev, enum ipi_id id,
  166. ipi_handler_t handler, const char *name, void *priv);
  167. /**
  168. * vcu_ipi_send - send data from AP to vcu.
  169. *
  170. * @pdev: VCU platform device
  171. * @id: IPI ID
  172. * @buf: the data buffer
  173. * @len: the data buffer length
  174. *
  175. * This function is thread-safe. When this function returns,
  176. * VCU has received the data and starts the processing.
  177. * When the processing completes, IPI handler registered
  178. * by vcu_ipi_register will be called in interrupt context.
  179. *
  180. * Return: Return 0 if sending data successfully, otherwise it is failed.
  181. **/
  182. int vcu_ipi_send(struct platform_device *pdev,
  183. enum ipi_id id, void *buf,
  184. unsigned int len, void *priv);
  185. /**
  186. * vcu_get_plat_device - get VCU's platform device
  187. *
  188. * @pdev: the platform device of the module requesting VCU platform
  189. * device for using VCU API.
  190. *
  191. * Return: Return NULL if it is failed.
  192. * otherwise it is VCU's platform device
  193. **/
  194. struct platform_device *vcu_get_plat_device(struct platform_device *pdev);
  195. /**
  196. * vcu_get_vdec_hw_capa - get video decoder hardware capability
  197. *
  198. * @pdev: VCU platform device
  199. *
  200. * Return: video decoder hardware capability
  201. **/
  202. unsigned int vcu_get_vdec_hw_capa(struct platform_device *pdev);
  203. /**
  204. * vcu_get_venc_hw_capa - get video encoder hardware capability
  205. *
  206. * @pdev: VCU platform device
  207. *
  208. * Return: video encoder hardware capability
  209. **/
  210. unsigned int vcu_get_venc_hw_capa(struct platform_device *pdev);
  211. /**
  212. * vcu_load_firmware - download VCU firmware and boot it
  213. *
  214. * @pdev: VCU platform device
  215. *
  216. * Return: Return 0 if downloading firmware successfully,
  217. * otherwise it is failed
  218. **/
  219. int vcu_load_firmware(struct platform_device *pdev);
  220. /**
  221. * vcu_compare_version - compare firmware version and expected version
  222. *
  223. * @pdev: VCU platform device
  224. * @expected_version: expected version
  225. *
  226. * Return: < 0 if firmware version is older than expected version
  227. * = 0 if firmware version is equal to expected version
  228. * > 0 if firmware version is newer than expected version
  229. **/
  230. int vcu_compare_version(struct platform_device *pdev,
  231. const char *expected_version);
  232. /**
  233. * vcu_mapping_dm_addr - Mapping DTCM/DMEM to kernel virtual address
  234. *
  235. * @pdev: VCU platform device
  236. * @dmem_addr: VCU's data memory address
  237. *
  238. * Mapping the VCU's DTCM (Data Tightly-Coupled Memory) /
  239. * DMEM (Data Extended Memory) memory address to
  240. * kernel virtual address.
  241. *
  242. * Return: Return ERR_PTR(-EINVAL) if mapping failed,
  243. * otherwise the mapped kernel virtual address
  244. **/
  245. void *vcu_mapping_dm_addr(struct platform_device *pdev,
  246. uintptr_t dtcm_dmem_addr);
  247. /**
  248. * vcu_get_task - Get VCUD task information
  249. *
  250. * @task: VCUD task
  251. * @f: VCUD task filie
  252. * @reset: flag to reset task and file
  253. *
  254. * Get VCUD task information from mtk_vcu driver.
  255. *
  256. **/
  257. void vcu_get_task(struct task_struct **task, struct files_struct **f,
  258. int reset);
  259. void vcu_get_file_lock(void);
  260. void vcu_put_file_lock(void);
  261. int vcu_get_sig_lock(unsigned long *flags);
  262. void vcu_put_sig_lock(unsigned long flags);
  263. int vcu_check_vpud_alive(void);
  264. extern void smp_inner_dcache_flush_all(void);
  265. int vcu_get_ctx_ipi_binding_lock(struct platform_device *pdev,
  266. struct mutex **mutex, unsigned long type);
  267. int vcu_set_codec_ctx(struct platform_device *pdev,
  268. void *codec_ctx, struct vb2_buffer *src_vb,
  269. struct vb2_buffer *dst_vb, unsigned long type);
  270. int vcu_clear_codec_ctx(struct platform_device *pdev,
  271. void *codec_ctx, unsigned long type);
  272. extern void venc_encode_prepare(void *ctx_prepare,
  273. unsigned int core_id, unsigned long *flags);
  274. extern void venc_encode_unprepare(void *ctx_prepare,
  275. unsigned int core_id, unsigned long *flags);
  276. extern void venc_encode_pmqos_gce_begin(void *ctx_begin,
  277. unsigned int core_id, int job_cnt);
  278. extern void venc_encode_pmqos_gce_end(void *ctx_end,
  279. unsigned int core_id, int job_cnt);
  280. extern void mtk_vcodec_gce_timeout_dump(void *ctx);
  281. #endif /* _MTK_VCU_H */