1
2
3
4
5
6
7#ifndef __VENUS_CORE_H_
8#define __VENUS_CORE_H_
9
10#include <linux/list.h>
11#include <media/videobuf2-v4l2.h>
12#include <media/v4l2-ctrls.h>
13#include <media/v4l2-device.h>
14
15#include "hfi.h"
16
17#define VIDC_CLKS_NUM_MAX 4
18
19struct freq_tbl {
20 unsigned int load;
21 unsigned long freq;
22};
23
24struct reg_val {
25 u32 reg;
26 u32 value;
27};
28
29struct codec_freq_data {
30 u32 pixfmt;
31 u32 session_type;
32 unsigned long vpp_freq;
33 unsigned long vsp_freq;
34};
35
36struct bw_tbl {
37 u32 mbs_per_sec;
38 u32 avg;
39 u32 peak;
40 u32 avg_10bit;
41 u32 peak_10bit;
42};
43
44struct venus_resources {
45 u64 dma_mask;
46 const struct freq_tbl *freq_tbl;
47 unsigned int freq_tbl_size;
48 const struct bw_tbl *bw_tbl_enc;
49 unsigned int bw_tbl_enc_size;
50 const struct bw_tbl *bw_tbl_dec;
51 unsigned int bw_tbl_dec_size;
52 const struct reg_val *reg_tbl;
53 unsigned int reg_tbl_size;
54 const struct codec_freq_data *codec_freq_data;
55 unsigned int codec_freq_data_size;
56 const char * const clks[VIDC_CLKS_NUM_MAX];
57 unsigned int clks_num;
58 enum hfi_version hfi_version;
59 u32 max_load;
60 unsigned int vmem_id;
61 u32 vmem_size;
62 u32 vmem_addr;
63 const char *fwname;
64};
65
66struct venus_format {
67 u32 pixfmt;
68 unsigned int num_planes;
69 u32 type;
70 u32 flags;
71};
72
73#define MAX_PLANES 4
74#define MAX_FMT_ENTRIES 32
75#define MAX_CAP_ENTRIES 32
76#define MAX_ALLOC_MODE_ENTRIES 16
77#define MAX_CODEC_NUM 32
78
79struct raw_formats {
80 u32 buftype;
81 u32 fmt;
82};
83
84struct venus_caps {
85 u32 codec;
86 u32 domain;
87 bool cap_bufs_mode_dynamic;
88 unsigned int num_caps;
89 struct hfi_capability caps[MAX_CAP_ENTRIES];
90 unsigned int num_pl;
91 struct hfi_profile_level pl[HFI_MAX_PROFILE_COUNT];
92 unsigned int num_fmts;
93 struct raw_formats fmts[MAX_FMT_ENTRIES];
94 bool valid;
95};
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131struct venus_core {
132 void __iomem *base;
133 int irq;
134 struct clk *clks[VIDC_CLKS_NUM_MAX];
135 struct clk *core0_clk;
136 struct clk *core1_clk;
137 struct clk *core0_bus_clk;
138 struct clk *core1_bus_clk;
139 struct icc_path *video_path;
140 struct icc_path *cpucfg_path;
141 struct video_device *vdev_dec;
142 struct video_device *vdev_enc;
143 struct v4l2_device v4l2_dev;
144 const struct venus_resources *res;
145 struct device *dev;
146 struct device *dev_dec;
147 struct device *dev_enc;
148 unsigned int use_tz;
149 struct video_firmware {
150 struct device *dev;
151 struct iommu_domain *iommu_domain;
152 size_t mapped_mem_size;
153 } fw;
154 struct mutex lock;
155 struct list_head instances;
156 atomic_t insts_count;
157 unsigned int state;
158 struct completion done;
159 unsigned int error;
160 bool sys_error;
161 const struct hfi_core_ops *core_ops;
162 unsigned long enc_codecs;
163 unsigned long dec_codecs;
164 unsigned int max_sessions_supported;
165#define ENC_ROTATION_CAPABILITY 0x1
166#define ENC_SCALING_CAPABILITY 0x2
167#define ENC_DEINTERLACE_CAPABILITY 0x4
168#define DEC_MULTI_STREAM_CAPABILITY 0x8
169 unsigned int core_caps;
170 void *priv;
171 const struct hfi_ops *ops;
172 struct delayed_work work;
173 struct venus_caps caps[MAX_CODEC_NUM];
174 unsigned int codecs_count;
175};
176
177struct vdec_controls {
178 u32 post_loop_deb_mode;
179 u32 profile;
180 u32 level;
181};
182
183struct venc_controls {
184 u16 gop_size;
185 u32 num_p_frames;
186 u32 num_b_frames;
187 u32 bitrate_mode;
188 u32 bitrate;
189 u32 bitrate_peak;
190
191 u32 h264_i_period;
192 u32 h264_entropy_mode;
193 u32 h264_i_qp;
194 u32 h264_p_qp;
195 u32 h264_b_qp;
196 u32 h264_min_qp;
197 u32 h264_max_qp;
198 u32 h264_loop_filter_mode;
199 s32 h264_loop_filter_alpha;
200 s32 h264_loop_filter_beta;
201
202 u32 vp8_min_qp;
203 u32 vp8_max_qp;
204
205 u32 multi_slice_mode;
206 u32 multi_slice_max_bytes;
207 u32 multi_slice_max_mb;
208
209 u32 header_mode;
210
211 struct {
212 u32 mpeg4;
213 u32 h264;
214 u32 vpx;
215 u32 hevc;
216 } profile;
217 struct {
218 u32 mpeg4;
219 u32 h264;
220 u32 hevc;
221 } level;
222};
223
224struct venus_buffer {
225 struct vb2_v4l2_buffer vb;
226 struct list_head list;
227 dma_addr_t dma_addr;
228 u32 size;
229 struct list_head reg_list;
230 u32 flags;
231 struct list_head ref_list;
232};
233
234struct clock_data {
235 u32 core_id;
236 unsigned long freq;
237 const struct codec_freq_data *codec_freq_data;
238};
239
240#define to_venus_buffer(ptr) container_of(ptr, struct venus_buffer, vb)
241
242enum venus_dec_state {
243 VENUS_DEC_STATE_DEINIT = 0,
244 VENUS_DEC_STATE_INIT = 1,
245 VENUS_DEC_STATE_CAPTURE_SETUP = 2,
246 VENUS_DEC_STATE_STOPPED = 3,
247 VENUS_DEC_STATE_SEEK = 4,
248 VENUS_DEC_STATE_DRAIN = 5,
249 VENUS_DEC_STATE_DECODING = 6,
250 VENUS_DEC_STATE_DRC = 7
251};
252
253struct venus_ts_metadata {
254 bool used;
255 u64 ts_ns;
256 u64 ts_us;
257 u32 flags;
258 struct v4l2_timecode tc;
259};
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316struct venus_inst {
317 struct list_head list;
318 struct mutex lock;
319 struct venus_core *core;
320 struct clock_data clk_data;
321 struct list_head dpbbufs;
322 struct list_head internalbufs;
323 struct list_head registeredbufs;
324 struct list_head delayed_process;
325 struct work_struct delayed_process_work;
326
327 struct v4l2_ctrl_handler ctrl_handler;
328 union {
329 struct vdec_controls dec;
330 struct venc_controls enc;
331 } controls;
332 struct v4l2_fh fh;
333 unsigned int streamon_cap, streamon_out;
334 u32 width;
335 u32 height;
336 u32 out_width;
337 u32 out_height;
338 u32 colorspace;
339 u8 ycbcr_enc;
340 u8 quantization;
341 u8 xfer_func;
342 enum venus_dec_state codec_state;
343 wait_queue_head_t reconf_wait;
344 unsigned int subscriptions;
345 int buf_count;
346 struct venus_ts_metadata tss[VIDEO_MAX_FRAME];
347 u64 fps;
348 struct v4l2_fract timeperframe;
349 const struct venus_format *fmt_out;
350 const struct venus_format *fmt_cap;
351 unsigned int num_input_bufs;
352 unsigned int num_output_bufs;
353 unsigned int input_buf_size;
354 unsigned int output_buf_size;
355 unsigned int output2_buf_size;
356 u32 dpb_buftype;
357 u32 dpb_fmt;
358 u32 opb_buftype;
359 u32 opb_fmt;
360 bool reconfig;
361 u32 hfi_codec;
362 u32 sequence_cap;
363 u32 sequence_out;
364 struct v4l2_m2m_dev *m2m_dev;
365 struct v4l2_m2m_ctx *m2m_ctx;
366 unsigned int state;
367 struct completion done;
368 unsigned int error;
369 bool session_error;
370 const struct hfi_inst_ops *ops;
371 u32 session_type;
372 union hfi_get_property hprop;
373};
374
375#define IS_V1(core) ((core)->res->hfi_version == HFI_VERSION_1XX)
376#define IS_V3(core) ((core)->res->hfi_version == HFI_VERSION_3XX)
377#define IS_V4(core) ((core)->res->hfi_version == HFI_VERSION_4XX)
378
379#define ctrl_to_inst(ctrl) \
380 container_of((ctrl)->handler, struct venus_inst, ctrl_handler)
381
382static inline struct venus_inst *to_inst(struct file *filp)
383{
384 return container_of(filp->private_data, struct venus_inst, fh);
385}
386
387static inline void *to_hfi_priv(struct venus_core *core)
388{
389 return core->priv;
390}
391
392static inline struct venus_caps *
393venus_caps_by_codec(struct venus_core *core, u32 codec, u32 domain)
394{
395 unsigned int c;
396
397 for (c = 0; c < core->codecs_count; c++) {
398 if (core->caps[c].codec == codec &&
399 core->caps[c].domain == domain)
400 return &core->caps[c];
401 }
402
403 return NULL;
404}
405
406#endif
407