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