1
2
3
4
5
6
7
8
9#ifndef HANTRO_HW_H_
10#define HANTRO_HW_H_
11
12#include <linux/interrupt.h>
13#include <linux/v4l2-controls.h>
14#include <media/v4l2-ctrls.h>
15#include <media/videobuf2-core.h>
16
17#define DEC_8190_ALIGN_MASK 0x07U
18
19#define MB_DIM 16
20#define MB_WIDTH(w) DIV_ROUND_UP(w, MB_DIM)
21#define MB_HEIGHT(h) DIV_ROUND_UP(h, MB_DIM)
22
23#define NUM_REF_PICTURES (V4L2_HEVC_DPB_ENTRIES_NUM_MAX + 1)
24
25struct hantro_dev;
26struct hantro_ctx;
27struct hantro_buf;
28struct hantro_variant;
29
30
31
32
33
34
35
36
37
38struct hantro_aux_buf {
39 void *cpu;
40 dma_addr_t dma;
41 size_t size;
42 unsigned long attrs;
43};
44
45
46
47
48
49
50struct hantro_jpeg_enc_hw_ctx {
51 struct hantro_aux_buf bounce_buffer;
52};
53
54
55#define HANTRO_H264_DPB_SIZE 16
56
57
58
59
60
61
62
63
64
65struct hantro_h264_dec_ctrls {
66 const struct v4l2_ctrl_h264_decode_params *decode;
67 const struct v4l2_ctrl_h264_scaling_matrix *scaling;
68 const struct v4l2_ctrl_h264_sps *sps;
69 const struct v4l2_ctrl_h264_pps *pps;
70};
71
72
73
74
75
76
77
78
79struct hantro_h264_dec_reflists {
80 u8 p[HANTRO_H264_DPB_SIZE];
81 u8 b0[HANTRO_H264_DPB_SIZE];
82 u8 b1[HANTRO_H264_DPB_SIZE];
83};
84
85
86
87
88
89
90
91
92
93
94
95struct hantro_h264_dec_hw_ctx {
96 struct hantro_aux_buf priv;
97 struct v4l2_h264_dpb_entry dpb[HANTRO_H264_DPB_SIZE];
98 struct hantro_h264_dec_reflists reflists;
99 struct hantro_h264_dec_ctrls ctrls;
100 u32 dpb_longterm;
101 u32 dpb_valid;
102};
103
104
105
106
107
108
109
110
111
112
113struct hantro_hevc_dec_ctrls {
114 const struct v4l2_ctrl_hevc_decode_params *decode_params;
115 const struct v4l2_ctrl_hevc_sps *sps;
116 const struct v4l2_ctrl_hevc_pps *pps;
117 u32 hevc_hdr_skip_length;
118};
119
120
121
122
123
124
125
126
127
128
129
130
131
132struct hantro_hevc_dec_hw_ctx {
133 struct hantro_aux_buf tile_sizes;
134 struct hantro_aux_buf tile_filter;
135 struct hantro_aux_buf tile_sao;
136 struct hantro_aux_buf tile_bsd;
137 struct hantro_aux_buf ref_bufs[NUM_REF_PICTURES];
138 int ref_bufs_poc[NUM_REF_PICTURES];
139 u32 ref_bufs_used;
140 struct hantro_hevc_dec_ctrls ctrls;
141 unsigned int num_tile_cols_allocated;
142};
143
144
145
146
147
148
149struct hantro_mpeg2_dec_hw_ctx {
150 struct hantro_aux_buf qtable;
151};
152
153
154
155
156
157
158
159struct hantro_vp8_dec_hw_ctx {
160 struct hantro_aux_buf segment_map;
161 struct hantro_aux_buf prob_tbl;
162};
163
164
165
166
167
168
169struct hantro_postproc_ctx {
170 struct hantro_aux_buf dec_q[VB2_MAX_FRAME];
171};
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187struct hantro_codec_ops {
188 int (*init)(struct hantro_ctx *ctx);
189 void (*exit)(struct hantro_ctx *ctx);
190 int (*run)(struct hantro_ctx *ctx);
191 void (*done)(struct hantro_ctx *ctx);
192 void (*reset)(struct hantro_ctx *ctx);
193};
194
195
196
197
198
199
200
201
202
203enum hantro_enc_fmt {
204 ROCKCHIP_VPU_ENC_FMT_YUV420P = 0,
205 ROCKCHIP_VPU_ENC_FMT_YUV420SP = 1,
206 ROCKCHIP_VPU_ENC_FMT_YUYV422 = 2,
207 ROCKCHIP_VPU_ENC_FMT_UYVY422 = 3,
208};
209
210extern const struct hantro_variant imx8mq_vpu_g2_variant;
211extern const struct hantro_variant imx8mq_vpu_variant;
212extern const struct hantro_variant px30_vpu_variant;
213extern const struct hantro_variant rk3036_vpu_variant;
214extern const struct hantro_variant rk3066_vpu_variant;
215extern const struct hantro_variant rk3288_vpu_variant;
216extern const struct hantro_variant rk3328_vpu_variant;
217extern const struct hantro_variant rk3399_vpu_variant;
218extern const struct hantro_variant sama5d4_vdec_variant;
219
220extern const struct hantro_postproc_regs hantro_g1_postproc_regs;
221
222extern const u32 hantro_vp8_dec_mc_filter[8][6];
223
224void hantro_watchdog(struct work_struct *work);
225void hantro_run(struct hantro_ctx *ctx);
226void hantro_irq_done(struct hantro_dev *vpu,
227 enum vb2_buffer_state result);
228void hantro_start_prepare_run(struct hantro_ctx *ctx);
229void hantro_end_prepare_run(struct hantro_ctx *ctx);
230
231irqreturn_t hantro_g1_irq(int irq, void *dev_id);
232void hantro_g1_reset(struct hantro_ctx *ctx);
233
234int hantro_h1_jpeg_enc_run(struct hantro_ctx *ctx);
235int rockchip_vpu2_jpeg_enc_run(struct hantro_ctx *ctx);
236int hantro_jpeg_enc_init(struct hantro_ctx *ctx);
237void hantro_jpeg_enc_exit(struct hantro_ctx *ctx);
238void hantro_jpeg_enc_done(struct hantro_ctx *ctx);
239
240dma_addr_t hantro_h264_get_ref_buf(struct hantro_ctx *ctx,
241 unsigned int dpb_idx);
242u16 hantro_h264_get_ref_nbr(struct hantro_ctx *ctx,
243 unsigned int dpb_idx);
244int hantro_h264_dec_prepare_run(struct hantro_ctx *ctx);
245int rockchip_vpu2_h264_dec_run(struct hantro_ctx *ctx);
246int hantro_g1_h264_dec_run(struct hantro_ctx *ctx);
247int hantro_h264_dec_init(struct hantro_ctx *ctx);
248void hantro_h264_dec_exit(struct hantro_ctx *ctx);
249
250int hantro_hevc_dec_init(struct hantro_ctx *ctx);
251void hantro_hevc_dec_exit(struct hantro_ctx *ctx);
252int hantro_g2_hevc_dec_run(struct hantro_ctx *ctx);
253int hantro_hevc_dec_prepare_run(struct hantro_ctx *ctx);
254dma_addr_t hantro_hevc_get_ref_buf(struct hantro_ctx *ctx, int poc);
255void hantro_hevc_ref_remove_unused(struct hantro_ctx *ctx);
256size_t hantro_hevc_chroma_offset(const struct v4l2_ctrl_hevc_sps *sps);
257size_t hantro_hevc_motion_vectors_offset(const struct v4l2_ctrl_hevc_sps *sps);
258
259static inline size_t
260hantro_h264_mv_size(unsigned int width, unsigned int height)
261{
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283 return 64 * MB_WIDTH(width) * MB_WIDTH(height) + 32;
284}
285
286int hantro_g1_mpeg2_dec_run(struct hantro_ctx *ctx);
287int rockchip_vpu2_mpeg2_dec_run(struct hantro_ctx *ctx);
288void hantro_mpeg2_dec_copy_qtable(u8 *qtable,
289 const struct v4l2_ctrl_mpeg2_quantisation *ctrl);
290int hantro_mpeg2_dec_init(struct hantro_ctx *ctx);
291void hantro_mpeg2_dec_exit(struct hantro_ctx *ctx);
292
293int hantro_g1_vp8_dec_run(struct hantro_ctx *ctx);
294int rockchip_vpu2_vp8_dec_run(struct hantro_ctx *ctx);
295int hantro_vp8_dec_init(struct hantro_ctx *ctx);
296void hantro_vp8_dec_exit(struct hantro_ctx *ctx);
297void hantro_vp8_prob_update(struct hantro_ctx *ctx,
298 const struct v4l2_ctrl_vp8_frame *hdr);
299
300#endif
301