mtk_vpu.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. /*
  2. * Copyright (c) 2016 MediaTek Inc.
  3. * Author: Andrew-CT Chen <andrew-ct.chen@mediatek.com>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License version 2 as
  7. * published by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. */
  14. #ifndef _MTK_VPU_H
  15. #define _MTK_VPU_H
  16. #include <linux/platform_device.h>
  17. /**
  18. * VPU (video processor unit) is a tiny processor controlling video hardware
  19. * related to video codec, scaling and color format converting.
  20. * VPU interfaces with other blocks by share memory and interrupt.
  21. **/
  22. typedef void (*ipi_handler_t) (void *data,
  23. unsigned int len,
  24. void *priv);
  25. /**
  26. * enum ipi_id - the id of inter-processor interrupt
  27. *
  28. * @IPI_VPU_INIT: The interrupt from vpu is to notfiy kernel
  29. VPU initialization completed.
  30. IPI_VPU_INIT is sent from VPU when firmware is
  31. loaded. AP doesn't need to send IPI_VPU_INIT
  32. command to VPU.
  33. For other IPI below, AP should send the request
  34. to VPU to trigger the interrupt.
  35. * @IPI_VENC_H264: The interrupt from vpu is to notify kernel to
  36. handle H264 video encoder job, and vice versa.
  37. * @IPI_VENC_VP8: The interrupt fro vpu is to notify kernel to
  38. handle VP8 video encoder job,, and vice versa.
  39. * @IPI_MAX: The maximum IPI number
  40. */
  41. enum ipi_id {
  42. IPI_VPU_INIT = 0,
  43. IPI_VENC_H264,
  44. IPI_VENC_VP8,
  45. IPI_MAX,
  46. };
  47. /**
  48. * enum rst_id - reset id to register reset function for VPU watchdog timeout
  49. *
  50. * @VPU_RST_ENC: encoder reset id
  51. * @VPU_RST_MAX: maximum reset id
  52. */
  53. enum rst_id {
  54. VPU_RST_ENC,
  55. VPU_RST_MAX,
  56. };
  57. /**
  58. * vpu_ipi_register - register an ipi function
  59. *
  60. * @pdev: VPU platform device
  61. * @id: IPI ID
  62. * @handler: IPI handler
  63. * @name: IPI name
  64. * @priv: private data for IPI handler
  65. *
  66. * Register an ipi function to receive ipi interrupt from VPU.
  67. *
  68. * Return: Return 0 if ipi registers successfully, otherwise it is failed.
  69. */
  70. int vpu_ipi_register(struct platform_device *pdev, enum ipi_id id,
  71. ipi_handler_t handler, const char *name, void *priv);
  72. /**
  73. * vpu_ipi_send - send data from AP to vpu.
  74. *
  75. * @pdev: VPU platform device
  76. * @id: IPI ID
  77. * @buf: the data buffer
  78. * @len: the data buffer length
  79. *
  80. * This function is thread-safe. When this function returns,
  81. * VPU has received the data and starts the processing.
  82. * When the processing completes, IPI handler registered
  83. * by vpu_ipi_register will be called in interrupt context.
  84. *
  85. * Return: Return 0 if sending data successfully, otherwise it is failed.
  86. **/
  87. int vpu_ipi_send(struct platform_device *pdev,
  88. enum ipi_id id, void *buf,
  89. unsigned int len);
  90. /**
  91. * vpu_get_plat_device - get VPU's platform device
  92. *
  93. * @pdev: the platform device of the module requesting VPU platform
  94. * device for using VPU API.
  95. *
  96. * Return: Return NULL if it is failed.
  97. * otherwise it is VPU's platform device
  98. **/
  99. struct platform_device *vpu_get_plat_device(struct platform_device *pdev);
  100. /**
  101. * vpu_wdt_reg_handler - register a VPU watchdog handler
  102. *
  103. * @pdev: VPU platform device
  104. * @vpu_wdt_reset_func: the callback reset function
  105. * @private_data: the private data for reset function
  106. * @rst_id: reset id
  107. *
  108. * Register a handler performing own tasks when vpu reset by watchdog
  109. *
  110. * Return: Return 0 if the handler is added successfully,
  111. * otherwise it is failed.
  112. *
  113. **/
  114. int vpu_wdt_reg_handler(struct platform_device *pdev,
  115. void vpu_wdt_reset_func(void *),
  116. void *priv, enum rst_id id);
  117. /**
  118. * vpu_get_venc_hw_capa - get video encoder hardware capability
  119. *
  120. * @pdev: VPU platform device
  121. *
  122. * Return: video encoder hardware capability
  123. **/
  124. unsigned int vpu_get_venc_hw_capa(struct platform_device *pdev);
  125. /**
  126. * vpu_load_firmware - download VPU firmware and boot it
  127. *
  128. * @pdev: VPU platform device
  129. *
  130. * Return: Return 0 if downloading firmware successfully,
  131. * otherwise it is failed
  132. **/
  133. int vpu_load_firmware(struct platform_device *pdev);
  134. /**
  135. * vpu_mapping_dm_addr - Mapping DTCM/DMEM to kernel virtual address
  136. *
  137. * @pdev: VPU platform device
  138. * @dmem_addr: VPU's data memory address
  139. *
  140. * Mapping the VPU's DTCM (Data Tightly-Coupled Memory) /
  141. * DMEM (Data Extended Memory) memory address to
  142. * kernel virtual address.
  143. *
  144. * Return: Return ERR_PTR(-EINVAL) if mapping failed,
  145. * otherwise the mapped kernel virtual address
  146. **/
  147. void *vpu_mapping_dm_addr(struct platform_device *pdev,
  148. u32 dtcm_dmem_addr);
  149. #endif /* _MTK_VPU_H */