summaryrefslogtreecommitdiff
path: root/drivers/amvdec_ports/aml_vcodec_dec.h (plain)
blob: 7ca3337654329628ba458eee5798cbf872e60bc4
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 "aml_vcodec_util.h"
27
28#define VCODEC_CAPABILITY_4K_DISABLED 0x10
29#define VCODEC_DEC_4K_CODED_WIDTH 4096U
30#define VCODEC_DEC_4K_CODED_HEIGHT 2304U
31#define AML_VDEC_MAX_W 2048U
32#define AML_VDEC_MAX_H 1088U
33
34#define AML_VDEC_IRQ_STATUS_DEC_SUCCESS 0x10000
35#define V4L2_BUF_FLAG_LAST 0x00100000
36
37#define VDEC_GATHER_MEMORY_TYPE 0
38#define VDEC_SCATTER_MEMORY_TYPE 1
39
40#define AML_V4L2_SET_DECMODE (V4L2_CID_USER_AMLOGIC_BASE + 0)
41
42/* for video composer metafd private_data struct */
43struct file_privdata {
44 struct vframe_s vf;
45 struct vframe_s *vf_p;
46 bool is_keep;
47 int keep_id;
48 int keep_head_id;
49 bool is_install;
50};
51
52/**
53 * struct vdec_fb - decoder frame buffer
54 * @mem_type : gather or scatter memory.
55 * @num_planes : used number of the plane
56 * @mem[4] : array mem for used planes,
57 * mem[0]: Y, mem[1]: C/U, mem[2]: V
58 * @vf_fd : the file handle of video frame
59 * @vf_handle : video frame handle
60 * @status : frame buffer status (vdec_fb_status)
61 */
62
63struct vdec_v4l2_buffer {
64 int mem_type;
65 int num_planes;
66 union {
67 struct aml_vcodec_mem mem[4];
68 u32 vf_fd;
69 } m;
70 ulong vf_handle;
71 u32 status;
72};
73
74
75/**
76 * struct aml_video_dec_buf - Private data related to each VB2 buffer.
77 * @b: VB2 buffer
78 * @list: link list
79 * @used: Capture buffer contain decoded frame data and keep in
80 * codec data structure
81 * @ready_to_display: Capture buffer not display yet
82 * @queued_in_vb2: Capture buffer is queue in vb2
83 * @queued_in_v4l2: Capture buffer is in v4l2 driver, but not in vb2
84 * queue yet
85 * @lastframe: Intput buffer is last buffer - EOS
86 * @error: An unrecoverable error occurs on this buffer.
87 * @frame_buffer: Decode status, and buffer information of Capture buffer
88 *
89 * Note : These status information help us track and debug buffer state
90 */
91struct aml_video_dec_buf {
92 struct vb2_v4l2_buffer vb;
93 struct list_head list;
94
95 struct vdec_v4l2_buffer frame_buffer;
96 struct file_privdata privdata;
97 struct codec_mm_s *mem[2];
98 char mem_onwer[32];
99 bool used;
100 bool ready_to_display;
101 bool que_in_m2m;
102 bool queued_in_vb2;
103 bool queued_in_v4l2;
104 bool lastframe;
105 bool error;
106};
107
108extern const struct v4l2_ioctl_ops aml_vdec_ioctl_ops;
109extern const struct v4l2_m2m_ops aml_vdec_m2m_ops;
110
111/*
112 * aml_vdec_lock/aml_vdec_unlock are for ctx instance to
113 * get/release lock before/after access decoder hw.
114 * aml_vdec_lock get decoder hw lock and set curr_ctx
115 * to ctx instance that get lock
116 */
117void aml_vdec_unlock(struct aml_vcodec_ctx *ctx);
118void aml_vdec_lock(struct aml_vcodec_ctx *ctx);
119int aml_vcodec_dec_queue_init(void *priv, struct vb2_queue *src_vq,
120 struct vb2_queue *dst_vq);
121void aml_vcodec_dec_set_default_params(struct aml_vcodec_ctx *ctx);
122void aml_vcodec_dec_release(struct aml_vcodec_ctx *ctx);
123int aml_vcodec_dec_ctrls_setup(struct aml_vcodec_ctx *ctx);
124void vdec_device_vf_run(struct aml_vcodec_ctx *ctx);
125void try_to_capture(struct aml_vcodec_ctx *ctx);
126void aml_thread_notify(struct aml_vcodec_ctx *ctx,
127 enum aml_thread_type type);
128int aml_thread_start(struct aml_vcodec_ctx *ctx, aml_thread_func func,
129 enum aml_thread_type type, const char *thread_name);
130void aml_thread_stop(struct aml_vcodec_ctx *ctx);
131void wait_vcodec_ending(struct aml_vcodec_ctx *ctx);
132void vdec_frame_buffer_release(void *data);
133void aml_vdec_dispatch_event(struct aml_vcodec_ctx *ctx, u32 changes);
134
135#endif /* _AML_VCODEC_DEC_H_ */
136