vde.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. /* SPDX-License-Identifier: GPL-2.0+ */
  2. /*
  3. * NVIDIA Tegra Video decoder driver
  4. *
  5. * Copyright (C) 2016-2019 GRATE-DRIVER project
  6. */
  7. #ifndef TEGRA_VDE_H
  8. #define TEGRA_VDE_H
  9. #include <linux/completion.h>
  10. #include <linux/dma-direction.h>
  11. #include <linux/iova.h>
  12. #include <linux/list.h>
  13. #include <linux/mutex.h>
  14. #include <linux/types.h>
  15. #include <linux/workqueue.h>
  16. #include <media/media-device.h>
  17. #include <media/videobuf2-dma-contig.h>
  18. #include <media/videobuf2-dma-sg.h>
  19. #include <media/v4l2-ctrls.h>
  20. #include <media/v4l2-device.h>
  21. #include <media/v4l2-event.h>
  22. #include <media/v4l2-ioctl.h>
  23. #include <media/v4l2-mem2mem.h>
  24. #define ICMDQUE_WR 0x00
  25. #define CMDQUE_CONTROL 0x08
  26. #define INTR_STATUS 0x18
  27. #define BSE_INT_ENB 0x40
  28. #define BSE_CONFIG 0x44
  29. #define BSE_ICMDQUE_EMPTY BIT(3)
  30. #define BSE_DMA_BUSY BIT(23)
  31. #define BSEV_ALIGN SZ_1
  32. #define FRAMEID_ALIGN SZ_256
  33. #define SXE_BUFFER SZ_32K
  34. #define VDE_ATOM SZ_16
  35. struct clk;
  36. struct dma_buf;
  37. struct gen_pool;
  38. struct tegra_ctx;
  39. struct iommu_group;
  40. struct iommu_domain;
  41. struct reset_control;
  42. struct dma_buf_attachment;
  43. struct tegra_vde_h264_decoder_ctx;
  44. struct tegra_video_frame {
  45. struct dma_buf_attachment *y_dmabuf_attachment;
  46. struct dma_buf_attachment *cb_dmabuf_attachment;
  47. struct dma_buf_attachment *cr_dmabuf_attachment;
  48. struct dma_buf_attachment *aux_dmabuf_attachment;
  49. dma_addr_t y_addr;
  50. dma_addr_t cb_addr;
  51. dma_addr_t cr_addr;
  52. dma_addr_t aux_addr;
  53. u32 frame_num;
  54. u32 flags;
  55. u32 luma_atoms_pitch;
  56. u32 chroma_atoms_pitch;
  57. };
  58. struct tegra_coded_fmt_desc {
  59. u32 fourcc;
  60. struct v4l2_frmsize_stepwise frmsize;
  61. unsigned int num_decoded_fmts;
  62. const u32 *decoded_fmts;
  63. int (*decode_run)(struct tegra_ctx *ctx);
  64. int (*decode_wait)(struct tegra_ctx *ctx);
  65. };
  66. struct tegra_vde_soc {
  67. bool supports_ref_pic_marking;
  68. const struct tegra_coded_fmt_desc *coded_fmts;
  69. u32 num_coded_fmts;
  70. };
  71. struct tegra_vde_bo {
  72. struct iova *iova;
  73. struct sg_table sgt;
  74. struct tegra_vde *vde;
  75. enum dma_data_direction dma_dir;
  76. unsigned long dma_attrs;
  77. dma_addr_t dma_handle;
  78. dma_addr_t dma_addr;
  79. void *dma_cookie;
  80. size_t size;
  81. };
  82. struct tegra_vde {
  83. void __iomem *sxe;
  84. void __iomem *bsev;
  85. void __iomem *mbe;
  86. void __iomem *ppe;
  87. void __iomem *mce;
  88. void __iomem *tfe;
  89. void __iomem *ppb;
  90. void __iomem *vdma;
  91. void __iomem *frameid;
  92. struct device *dev;
  93. struct mutex lock;
  94. struct mutex map_lock;
  95. struct list_head map_list;
  96. struct reset_control *rst;
  97. struct reset_control *rst_mc;
  98. struct gen_pool *iram_pool;
  99. struct completion decode_completion;
  100. struct clk *clk;
  101. struct iommu_domain *domain;
  102. struct iommu_group *group;
  103. struct iova_domain iova;
  104. struct iova *iova_resv_static_addresses;
  105. struct iova *iova_resv_last_page;
  106. const struct tegra_vde_soc *soc;
  107. struct tegra_vde_bo *secure_bo;
  108. dma_addr_t bitstream_data_addr;
  109. dma_addr_t iram_lists_addr;
  110. u32 *iram;
  111. struct v4l2_device v4l2_dev;
  112. struct v4l2_m2m_dev *m2m;
  113. struct media_device mdev;
  114. struct video_device vdev;
  115. struct mutex v4l2_lock;
  116. struct workqueue_struct *wq;
  117. struct tegra_video_frame frames[V4L2_H264_NUM_DPB_ENTRIES + 1];
  118. };
  119. int tegra_vde_alloc_bo(struct tegra_vde *vde,
  120. struct tegra_vde_bo **ret_bo,
  121. enum dma_data_direction dma_dir,
  122. size_t size);
  123. void tegra_vde_free_bo(struct tegra_vde_bo *bo);
  124. struct tegra_ctx_h264 {
  125. const struct v4l2_ctrl_h264_decode_params *decode_params;
  126. const struct v4l2_ctrl_h264_sps *sps;
  127. const struct v4l2_ctrl_h264_pps *pps;
  128. };
  129. struct tegra_ctx {
  130. struct tegra_vde *vde;
  131. struct tegra_ctx_h264 h264;
  132. struct work_struct work;
  133. struct v4l2_fh fh;
  134. struct v4l2_ctrl_handler hdl;
  135. struct v4l2_format coded_fmt;
  136. struct v4l2_format decoded_fmt;
  137. const struct tegra_coded_fmt_desc *coded_fmt_desc;
  138. struct v4l2_ctrl *ctrls[];
  139. };
  140. struct tegra_m2m_buffer {
  141. struct v4l2_m2m_buffer m2m;
  142. struct dma_buf_attachment *a[VB2_MAX_PLANES];
  143. dma_addr_t dma_base[VB2_MAX_PLANES];
  144. dma_addr_t dma_addr[VB2_MAX_PLANES];
  145. struct iova *iova[VB2_MAX_PLANES];
  146. struct tegra_vde_bo *aux;
  147. bool b_frame;
  148. };
  149. static inline struct tegra_m2m_buffer *
  150. vb_to_tegra_buf(struct vb2_buffer *vb)
  151. {
  152. struct v4l2_m2m_buffer *m2m = container_of(vb, struct v4l2_m2m_buffer,
  153. vb.vb2_buf);
  154. return container_of(m2m, struct tegra_m2m_buffer, m2m);
  155. }
  156. void tegra_vde_prepare_control_data(struct tegra_ctx *ctx, u32 id);
  157. void tegra_vde_writel(struct tegra_vde *vde, u32 value, void __iomem *base,
  158. u32 offset);
  159. u32 tegra_vde_readl(struct tegra_vde *vde, void __iomem *base, u32 offset);
  160. void tegra_vde_set_bits(struct tegra_vde *vde, u32 mask, void __iomem *base,
  161. u32 offset);
  162. int tegra_vde_h264_decode_run(struct tegra_ctx *ctx);
  163. int tegra_vde_h264_decode_wait(struct tegra_ctx *ctx);
  164. int tegra_vde_iommu_init(struct tegra_vde *vde);
  165. void tegra_vde_iommu_deinit(struct tegra_vde *vde);
  166. int tegra_vde_iommu_map(struct tegra_vde *vde,
  167. struct sg_table *sgt,
  168. struct iova **iovap,
  169. size_t size);
  170. void tegra_vde_iommu_unmap(struct tegra_vde *vde, struct iova *iova);
  171. int tegra_vde_dmabuf_cache_map(struct tegra_vde *vde,
  172. struct dma_buf *dmabuf,
  173. enum dma_data_direction dma_dir,
  174. struct dma_buf_attachment **ap,
  175. dma_addr_t *addrp);
  176. void tegra_vde_dmabuf_cache_unmap(struct tegra_vde *vde,
  177. struct dma_buf_attachment *a,
  178. bool release);
  179. void tegra_vde_dmabuf_cache_unmap_sync(struct tegra_vde *vde);
  180. void tegra_vde_dmabuf_cache_unmap_all(struct tegra_vde *vde);
  181. static __maybe_unused char const *
  182. tegra_vde_reg_base_name(struct tegra_vde *vde, void __iomem *base)
  183. {
  184. if (vde->sxe == base)
  185. return "SXE";
  186. if (vde->bsev == base)
  187. return "BSEV";
  188. if (vde->mbe == base)
  189. return "MBE";
  190. if (vde->ppe == base)
  191. return "PPE";
  192. if (vde->mce == base)
  193. return "MCE";
  194. if (vde->tfe == base)
  195. return "TFE";
  196. if (vde->ppb == base)
  197. return "PPB";
  198. if (vde->vdma == base)
  199. return "VDMA";
  200. if (vde->frameid == base)
  201. return "FRAMEID";
  202. return "???";
  203. }
  204. int tegra_vde_v4l2_init(struct tegra_vde *vde);
  205. void tegra_vde_v4l2_deinit(struct tegra_vde *vde);
  206. #endif /* TEGRA_VDE_H */