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