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
23struct hantro_dev;
24struct hantro_ctx;
25struct hantro_buf;
26struct hantro_variant;
27
28
29
30
31
32
33
34
35struct hantro_aux_buf {
36 void *cpu;
37 dma_addr_t dma;
38 size_t size;
39 unsigned long attrs;
40};
41
42
43
44
45
46struct hantro_jpeg_enc_hw_ctx {
47 struct hantro_aux_buf bounce_buffer;
48};
49
50
51#define HANTRO_H264_DPB_SIZE 16
52
53
54
55
56
57
58
59
60struct hantro_h264_dec_ctrls {
61 const struct v4l2_ctrl_h264_decode_params *decode;
62 const struct v4l2_ctrl_h264_scaling_matrix *scaling;
63 const struct v4l2_ctrl_h264_sps *sps;
64 const struct v4l2_ctrl_h264_pps *pps;
65};
66
67
68
69
70
71
72
73struct hantro_h264_dec_reflists {
74 u8 p[HANTRO_H264_DPB_SIZE];
75 u8 b0[HANTRO_H264_DPB_SIZE];
76 u8 b1[HANTRO_H264_DPB_SIZE];
77};
78
79
80
81
82
83
84
85
86struct hantro_h264_dec_hw_ctx {
87 struct hantro_aux_buf priv;
88 struct v4l2_h264_dpb_entry dpb[HANTRO_H264_DPB_SIZE];
89 struct hantro_h264_dec_reflists reflists;
90 struct hantro_h264_dec_ctrls ctrls;
91};
92
93
94
95
96
97struct hantro_mpeg2_dec_hw_ctx {
98 struct hantro_aux_buf qtable;
99};
100
101
102
103
104
105
106struct hantro_vp8_dec_hw_ctx {
107 struct hantro_aux_buf segment_map;
108 struct hantro_aux_buf prob_tbl;
109};
110
111
112
113
114
115
116struct hantro_postproc_ctx {
117 struct hantro_aux_buf dec_q[VB2_MAX_FRAME];
118};
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133struct hantro_codec_ops {
134 int (*init)(struct hantro_ctx *ctx);
135 void (*exit)(struct hantro_ctx *ctx);
136 void (*run)(struct hantro_ctx *ctx);
137 void (*done)(struct hantro_ctx *ctx);
138 void (*reset)(struct hantro_ctx *ctx);
139};
140
141
142
143
144enum hantro_enc_fmt {
145 RK3288_VPU_ENC_FMT_YUV420P = 0,
146 RK3288_VPU_ENC_FMT_YUV420SP = 1,
147 RK3288_VPU_ENC_FMT_YUYV422 = 2,
148 RK3288_VPU_ENC_FMT_UYVY422 = 3,
149};
150
151extern const struct hantro_variant rk3399_vpu_variant;
152extern const struct hantro_variant rk3328_vpu_variant;
153extern const struct hantro_variant rk3288_vpu_variant;
154extern const struct hantro_variant imx8mq_vpu_variant;
155
156extern const struct hantro_postproc_regs hantro_g1_postproc_regs;
157
158extern const u32 hantro_vp8_dec_mc_filter[8][6];
159
160void hantro_watchdog(struct work_struct *work);
161void hantro_run(struct hantro_ctx *ctx);
162void hantro_irq_done(struct hantro_dev *vpu,
163 enum vb2_buffer_state result);
164void hantro_start_prepare_run(struct hantro_ctx *ctx);
165void hantro_end_prepare_run(struct hantro_ctx *ctx);
166
167void hantro_h1_jpeg_enc_run(struct hantro_ctx *ctx);
168void rk3399_vpu_jpeg_enc_run(struct hantro_ctx *ctx);
169int hantro_jpeg_enc_init(struct hantro_ctx *ctx);
170void hantro_jpeg_enc_exit(struct hantro_ctx *ctx);
171void hantro_jpeg_enc_done(struct hantro_ctx *ctx);
172
173dma_addr_t hantro_h264_get_ref_buf(struct hantro_ctx *ctx,
174 unsigned int dpb_idx);
175int hantro_h264_dec_prepare_run(struct hantro_ctx *ctx);
176void hantro_g1_h264_dec_run(struct hantro_ctx *ctx);
177int hantro_h264_dec_init(struct hantro_ctx *ctx);
178void hantro_h264_dec_exit(struct hantro_ctx *ctx);
179
180static inline size_t
181hantro_h264_mv_size(unsigned int width, unsigned int height)
182{
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204 return 64 * MB_WIDTH(width) * MB_WIDTH(height) + 32;
205}
206
207void hantro_g1_mpeg2_dec_run(struct hantro_ctx *ctx);
208void rk3399_vpu_mpeg2_dec_run(struct hantro_ctx *ctx);
209void hantro_mpeg2_dec_copy_qtable(u8 *qtable,
210 const struct v4l2_ctrl_mpeg2_quantization *ctrl);
211int hantro_mpeg2_dec_init(struct hantro_ctx *ctx);
212void hantro_mpeg2_dec_exit(struct hantro_ctx *ctx);
213
214void hantro_g1_vp8_dec_run(struct hantro_ctx *ctx);
215void rk3399_vpu_vp8_dec_run(struct hantro_ctx *ctx);
216int hantro_vp8_dec_init(struct hantro_ctx *ctx);
217void hantro_vp8_dec_exit(struct hantro_ctx *ctx);
218void hantro_vp8_prob_update(struct hantro_ctx *ctx,
219 const struct v4l2_ctrl_vp8_frame_header *hdr);
220
221#endif
222