summaryrefslogtreecommitdiff
path: root/drivers/amvdec_ports/aml_vcodec_dec.h (plain)
blob: 68f878a54a4d6277df107dbe3ec4a5bce2fc4cc6
1/*
2* Copyright (C) 2017 Amlogic, Inc. All rights reserved.
3*
4* This program is free software; you can redistribute it and/or modify
5* it under the terms of the GNU General Public License as published by
6* the Free Software Foundation; either version 2 of the License, or
7* (at your option) any later version.
8*
9* This program is distributed in the hope that it will be useful, but WITHOUT
10* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12* more details.
13*
14* You should have received a copy of the GNU General Public License along
15* with this program; if not, write to the Free Software Foundation, Inc.,
16* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17*
18* Description:
19*/
20#ifndef _AML_VCODEC_DEC_H_
21#define _AML_VCODEC_DEC_H_
22
23#include <media/videobuf2-core.h>
24#include <media/videobuf2-v4l2.h>
25#include <linux/amlogic/media/codec_mm/codec_mm.h>
26#include <linux/amlogic/media/video_sink/v4lvideo_ext.h>
27#include "aml_vcodec_util.h"
28
29#define VCODEC_CAPABILITY_4K_DISABLED 0x10
30#define VCODEC_DEC_4K_CODED_WIDTH 4096U
31#define VCODEC_DEC_4K_CODED_HEIGHT 2304U
32#define AML_VDEC_MAX_W 2048U
33#define AML_VDEC_MAX_H 1088U
34
35#define AML_VDEC_IRQ_STATUS_DEC_SUCCESS 0x10000
36#define V4L2_BUF_FLAG_LAST 0x00100000
37
38#define VDEC_GATHER_MEMORY_TYPE 0
39#define VDEC_SCATTER_MEMORY_TYPE 1
40
41#define AML_V4L2_SET_DECMODE (V4L2_CID_USER_AMLOGIC_BASE + 0)
42
43/**
44 * struct vdec_fb - decoder frame buffer
45 * @mem_type : gather or scatter memory.
46 * @num_planes : used number of the plane
47 * @mem[4] : array mem for used planes,
48 * mem[0]: Y, mem[1]: C/U, mem[2]: V
49 * @vf_fd : the file handle of video frame
50 * @vf_handle : video frame handle
51 * @status : frame buffer status (vdec_fb_status)
52 */
53
54struct vdec_v4l2_buffer {
55 int mem_type;
56 int num_planes;
57 union {
58 struct aml_vcodec_mem mem[4];
59 u32 vf_fd;
60 } m;
61 ulong vf_handle;
62 u32 status;
63};
64
65
66/**
67 * struct aml_video_dec_buf - Private data related to each VB2 buffer.
68 * @b: VB2 buffer
69 * @list: link list
70 * @used: Capture buffer contain decoded frame data and keep in
71 * codec data structure
72 * @ready_to_display: Capture buffer not display yet
73 * @queued_in_vb2: Capture buffer is queue in vb2
74 * @queued_in_v4l2: Capture buffer is in v4l2 driver, but not in vb2
75 * queue yet
76 * @lastframe: Intput buffer is last buffer - EOS
77 * @error: An unrecoverable error occurs on this buffer.
78 * @frame_buffer: Decode status, and buffer information of Capture buffer
79 *
80 * Note : These status information help us track and debug buffer state
81 */
82struct aml_video_dec_buf {
83 struct vb2_v4l2_buffer vb;
84 struct list_head list;
85
86 struct vdec_v4l2_buffer frame_buffer;
87 struct file_private_data privdata;
88 struct codec_mm_s *mem[2];
89 char mem_onwer[32];
90 bool used;
91 bool ready_to_display;
92 bool que_in_m2m;
93 bool queued_in_vb2;
94 bool queued_in_v4l2;
95 bool lastframe;
96 bool error;
97};
98
99extern const struct v4l2_ioctl_ops aml_vdec_ioctl_ops;
100extern const struct v4l2_m2m_ops aml_vdec_m2m_ops;
101
102/*
103 * aml_vdec_lock/aml_vdec_unlock are for ctx instance to
104 * get/release lock before/after access decoder hw.
105 * aml_vdec_lock get decoder hw lock and set curr_ctx
106 * to ctx instance that get lock
107 */
108void aml_vdec_unlock(struct aml_vcodec_ctx *ctx);
109void aml_vdec_lock(struct aml_vcodec_ctx *ctx);
110int aml_vcodec_dec_queue_init(void *priv, struct vb2_queue *src_vq,
111 struct vb2_queue *dst_vq);
112void aml_vcodec_dec_set_default_params(struct aml_vcodec_ctx *ctx);
113void aml_vcodec_dec_release(struct aml_vcodec_ctx *ctx);
114int aml_vcodec_dec_ctrls_setup(struct aml_vcodec_ctx *ctx);
115void vdec_device_vf_run(struct aml_vcodec_ctx *ctx);
116void try_to_capture(struct aml_vcodec_ctx *ctx);
117void aml_thread_notify(struct aml_vcodec_ctx *ctx,
118 enum aml_thread_type type);
119int aml_thread_start(struct aml_vcodec_ctx *ctx, aml_thread_func func,
120 enum aml_thread_type type, const char *thread_name);
121void aml_thread_stop(struct aml_vcodec_ctx *ctx);
122void wait_vcodec_ending(struct aml_vcodec_ctx *ctx);
123void vdec_frame_buffer_release(void *data);
124void aml_vdec_dispatch_event(struct aml_vcodec_ctx *ctx, u32 changes);
125void* v4l_get_vf_handle(int fd);
126
127#endif /* _AML_VCODEC_DEC_H_ */
128