1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * Copyright (c) 2016 MediaTek Inc.
4  * Author: PC Chen <pc.chen@mediatek.com>
5  *         Tiffany Lin <tiffany.lin@mediatek.com>
6  */
7 
8 #ifndef _MTK_VCODEC_DEC_H_
9 #define _MTK_VCODEC_DEC_H_
10 
11 #include <media/videobuf2-core.h>
12 #include <media/v4l2-mem2mem.h>
13 
14 #include "mtk_vcodec_dec_drv.h"
15 
16 #define VCODEC_DEC_ALIGNED_64 64
17 #define VCODEC_CAPABILITY_4K_DISABLED	0x10
18 #define VCODEC_DEC_4K_CODED_WIDTH	4096U
19 #define VCODEC_DEC_4K_CODED_HEIGHT	2304U
20 #define MTK_VDEC_MAX_W	2048U
21 #define MTK_VDEC_MAX_H	1088U
22 #define MTK_VDEC_MIN_W	64U
23 #define MTK_VDEC_MIN_H	64U
24 
25 #define MTK_VDEC_IRQ_STATUS_DEC_SUCCESS        0x10000
26 
27 /**
28  * struct vdec_fb  - decoder frame buffer
29  * @base_y	: Y plane memory info
30  * @base_c	: C plane memory info
31  * @status      : frame buffer status (vdec_fb_status)
32  */
33 struct vdec_fb {
34 	struct mtk_vcodec_mem	base_y;
35 	struct mtk_vcodec_mem	base_c;
36 	unsigned int	status;
37 };
38 
39 /**
40  * struct mtk_video_dec_buf - Private data related to each VB2 buffer.
41  * @m2m_buf:	M2M buffer
42  * @list:	link list
43  * @used:	Capture buffer contain decoded frame data and keep in
44  *			codec data structure
45  * @queued_in_vb2:	Capture buffer is queue in vb2
46  * @queued_in_v4l2:	Capture buffer is in v4l2 driver, but not in vb2
47  *			queue yet
48  * @error:		An unrecoverable error occurs on this buffer.
49  * @frame_buffer:	Decode status, and buffer information of Capture buffer
50  * @bs_buffer:	Output buffer info
51  *
52  * Note : These status information help us track and debug buffer state
53  */
54 struct mtk_video_dec_buf {
55 	struct v4l2_m2m_buffer	m2m_buf;
56 
57 	bool	used;
58 	bool	queued_in_vb2;
59 	bool	queued_in_v4l2;
60 	bool	error;
61 
62 	union {
63 		struct vdec_fb	frame_buffer;
64 		struct mtk_vcodec_mem	bs_buffer;
65 	};
66 };
67 
68 extern const struct v4l2_ioctl_ops mtk_vdec_ioctl_ops;
69 extern const struct v4l2_m2m_ops mtk_vdec_m2m_ops;
70 extern const struct media_device_ops mtk_vcodec_media_ops;
71 extern const struct mtk_vcodec_dec_pdata mtk_vdec_8173_pdata;
72 extern const struct mtk_vcodec_dec_pdata mtk_vdec_8183_pdata;
73 extern const struct mtk_vcodec_dec_pdata mtk_lat_sig_core_pdata;
74 extern const struct mtk_vcodec_dec_pdata mtk_vdec_single_core_pdata;
75 
76 
77 /*
78  * mtk_vdec_lock/mtk_vdec_unlock are for ctx instance to
79  * get/release lock before/after access decoder hw.
80  * mtk_vdec_lock get decoder hw lock and set curr_ctx
81  * to ctx instance that get lock
82  */
83 void mtk_vdec_unlock(struct mtk_vcodec_dec_ctx *ctx);
84 void mtk_vdec_lock(struct mtk_vcodec_dec_ctx *ctx);
85 int mtk_vcodec_dec_queue_init(void *priv, struct vb2_queue *src_vq,
86 			   struct vb2_queue *dst_vq);
87 void mtk_vcodec_dec_set_default_params(struct mtk_vcodec_dec_ctx *ctx);
88 void mtk_vcodec_dec_release(struct mtk_vcodec_dec_ctx *ctx);
89 
90 /*
91  * VB2 ops
92  */
93 int vb2ops_vdec_queue_setup(struct vb2_queue *vq, unsigned int *nbuffers,
94 			    unsigned int *nplanes, unsigned int sizes[],
95 			    struct device *alloc_devs[]);
96 int vb2ops_vdec_buf_prepare(struct vb2_buffer *vb);
97 void vb2ops_vdec_buf_finish(struct vb2_buffer *vb);
98 int vb2ops_vdec_buf_init(struct vb2_buffer *vb);
99 int vb2ops_vdec_start_streaming(struct vb2_queue *q, unsigned int count);
100 void vb2ops_vdec_stop_streaming(struct vb2_queue *q);
101 
102 
103 #endif /* _MTK_VCODEC_DEC_H_ */
104