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#include "hfi_platform.h"
18
19#define VDBGL "VenusLow : "
20#define VDBGM "VenusMed : "
21#define VDBGH "VenusHigh: "
22#define VDBGFW "VenusFW : "
23
24#define VIDC_CLKS_NUM_MAX 4
25#define VIDC_VCODEC_CLKS_NUM_MAX 2
26#define VIDC_PMDOMAINS_NUM_MAX 3
27#define VIDC_RESETS_NUM_MAX 2
28
29extern int venus_fw_debug;
30
31struct freq_tbl {
32 unsigned int load;
33 unsigned long freq;
34};
35
36struct reg_val {
37 u32 reg;
38 u32 value;
39};
40
41struct bw_tbl {
42 u32 mbs_per_sec;
43 u32 avg;
44 u32 peak;
45 u32 avg_10bit;
46 u32 peak_10bit;
47};
48
49struct venus_resources {
50 u64 dma_mask;
51 const struct freq_tbl *freq_tbl;
52 unsigned int freq_tbl_size;
53 const struct bw_tbl *bw_tbl_enc;
54 unsigned int bw_tbl_enc_size;
55 const struct bw_tbl *bw_tbl_dec;
56 unsigned int bw_tbl_dec_size;
57 const struct reg_val *reg_tbl;
58 unsigned int reg_tbl_size;
59 const char * const clks[VIDC_CLKS_NUM_MAX];
60 unsigned int clks_num;
61 const char * const vcodec0_clks[VIDC_VCODEC_CLKS_NUM_MAX];
62 const char * const vcodec1_clks[VIDC_VCODEC_CLKS_NUM_MAX];
63 unsigned int vcodec_clks_num;
64 const char * const vcodec_pmdomains[VIDC_PMDOMAINS_NUM_MAX];
65 unsigned int vcodec_pmdomains_num;
66 const char **opp_pmdomain;
67 unsigned int vcodec_num;
68 const char * const resets[VIDC_RESETS_NUM_MAX];
69 unsigned int resets_num;
70 enum hfi_version hfi_version;
71 u32 max_load;
72 unsigned int vmem_id;
73 u32 vmem_size;
74 u32 vmem_addr;
75 u32 cp_start;
76 u32 cp_size;
77 u32 cp_nonpixel_start;
78 u32 cp_nonpixel_size;
79 const char *fwname;
80};
81
82struct venus_format {
83 u32 pixfmt;
84 unsigned int num_planes;
85 u32 type;
86 u32 flags;
87};
88
89
90
91
92
93
94
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
131
132
133
134
135
136
137
138
139
140
141
142
143struct venus_core {
144 void __iomem *base;
145 void __iomem *vbif_base;
146 void __iomem *cpu_base;
147 void __iomem *cpu_cs_base;
148 void __iomem *cpu_ic_base;
149 void __iomem *wrapper_base;
150 void __iomem *wrapper_tz_base;
151 void __iomem *aon_base;
152 int irq;
153 struct clk *clks[VIDC_CLKS_NUM_MAX];
154 struct clk *vcodec0_clks[VIDC_VCODEC_CLKS_NUM_MAX];
155 struct clk *vcodec1_clks[VIDC_VCODEC_CLKS_NUM_MAX];
156 struct icc_path *video_path;
157 struct icc_path *cpucfg_path;
158 bool has_opp_table;
159 struct device *pmdomains[VIDC_PMDOMAINS_NUM_MAX];
160 struct device_link *opp_dl_venus;
161 struct device *opp_pmdomain;
162 struct reset_control *resets[VIDC_RESETS_NUM_MAX];
163 struct video_device *vdev_dec;
164 struct video_device *vdev_enc;
165 struct v4l2_device v4l2_dev;
166 const struct venus_resources *res;
167 struct device *dev;
168 struct device *dev_dec;
169 struct device *dev_enc;
170 unsigned int use_tz;
171 struct video_firmware {
172 struct device *dev;
173 struct iommu_domain *iommu_domain;
174 size_t mapped_mem_size;
175 phys_addr_t mem_phys;
176 size_t mem_size;
177 } fw;
178 struct mutex lock;
179 struct list_head instances;
180 atomic_t insts_count;
181 unsigned int state;
182 struct completion done;
183 unsigned int error;
184 bool sys_error;
185 const struct hfi_core_ops *core_ops;
186 const struct venus_pm_ops *pm_ops;
187 struct mutex pm_lock;
188 unsigned long enc_codecs;
189 unsigned long dec_codecs;
190 unsigned int max_sessions_supported;
191 void *priv;
192 const struct hfi_ops *ops;
193 struct delayed_work work;
194 struct hfi_plat_caps caps[MAX_CODEC_NUM];
195 unsigned int codecs_count;
196 unsigned int core0_usage_count;
197 unsigned int core1_usage_count;
198 struct dentry *root;
199};
200
201struct vdec_controls {
202 u32 post_loop_deb_mode;
203 u32 profile;
204 u32 level;
205 u32 display_delay;
206 u32 display_delay_enable;
207 u64 conceal_color;
208};
209
210struct venc_controls {
211 u16 gop_size;
212 u32 num_p_frames;
213 u32 num_b_frames;
214 u32 bitrate_mode;
215 u32 bitrate;
216 u32 bitrate_peak;
217 u32 rc_enable;
218 u32 const_quality;
219 u32 frame_skip_mode;
220
221 u32 h264_i_period;
222 u32 h264_entropy_mode;
223 u32 h264_i_qp;
224 u32 h264_p_qp;
225 u32 h264_b_qp;
226 u32 h264_min_qp;
227 u32 h264_max_qp;
228 u32 h264_i_min_qp;
229 u32 h264_i_max_qp;
230 u32 h264_p_min_qp;
231 u32 h264_p_max_qp;
232 u32 h264_b_min_qp;
233 u32 h264_b_max_qp;
234 u32 h264_loop_filter_mode;
235 s32 h264_loop_filter_alpha;
236 s32 h264_loop_filter_beta;
237 u32 h264_8x8_transform;
238
239 u32 hevc_i_qp;
240 u32 hevc_p_qp;
241 u32 hevc_b_qp;
242 u32 hevc_min_qp;
243 u32 hevc_max_qp;
244 u32 hevc_i_min_qp;
245 u32 hevc_i_max_qp;
246 u32 hevc_p_min_qp;
247 u32 hevc_p_max_qp;
248 u32 hevc_b_min_qp;
249 u32 hevc_b_max_qp;
250
251 u32 vp8_min_qp;
252 u32 vp8_max_qp;
253
254 u32 multi_slice_mode;
255 u32 multi_slice_max_bytes;
256 u32 multi_slice_max_mb;
257
258 u32 header_mode;
259 bool aud_enable;
260 u32 intra_refresh_period;
261
262 struct {
263 u32 h264;
264 u32 mpeg4;
265 u32 hevc;
266 u32 vp8;
267 u32 vp9;
268 } profile;
269 struct {
270 u32 h264;
271 u32 mpeg4;
272 u32 hevc;
273 u32 vp9;
274 } level;
275
276 u32 base_priority_id;
277 u32 ltr_count;
278 struct v4l2_ctrl_hdr10_cll_info cll;
279 struct v4l2_ctrl_hdr10_mastering_display mastering;
280};
281
282struct venus_buffer {
283 struct vb2_v4l2_buffer vb;
284 struct list_head list;
285 dma_addr_t dma_addr;
286 u32 size;
287 struct list_head reg_list;
288 u32 flags;
289 struct list_head ref_list;
290};
291
292struct clock_data {
293 u32 core_id;
294 unsigned long freq;
295 unsigned long vpp_freq;
296 unsigned long vsp_freq;
297 unsigned long low_power_freq;
298};
299
300#define to_venus_buffer(ptr) container_of(ptr, struct venus_buffer, vb)
301
302enum venus_dec_state {
303 VENUS_DEC_STATE_DEINIT = 0,
304 VENUS_DEC_STATE_INIT = 1,
305 VENUS_DEC_STATE_CAPTURE_SETUP = 2,
306 VENUS_DEC_STATE_STOPPED = 3,
307 VENUS_DEC_STATE_SEEK = 4,
308 VENUS_DEC_STATE_DRAIN = 5,
309 VENUS_DEC_STATE_DECODING = 6,
310 VENUS_DEC_STATE_DRC = 7,
311};
312
313struct venus_ts_metadata {
314 bool used;
315 u64 ts_ns;
316 u64 ts_us;
317 u32 flags;
318 struct v4l2_timecode tc;
319};
320
321enum venus_inst_modes {
322 VENUS_LOW_POWER = BIT(0),
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
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390struct venus_inst {
391 struct list_head list;
392 struct mutex lock;
393 struct venus_core *core;
394 struct clock_data clk_data;
395 struct list_head dpbbufs;
396 struct list_head internalbufs;
397 struct list_head registeredbufs;
398 struct list_head delayed_process;
399 struct work_struct delayed_process_work;
400
401 struct v4l2_ctrl_handler ctrl_handler;
402 union {
403 struct vdec_controls dec;
404 struct venc_controls enc;
405 } controls;
406 struct v4l2_fh fh;
407 unsigned int streamon_cap, streamon_out;
408 u32 width;
409 u32 height;
410 struct v4l2_rect crop;
411 u32 out_width;
412 u32 out_height;
413 u32 colorspace;
414 u8 ycbcr_enc;
415 u8 quantization;
416 u8 xfer_func;
417 enum venus_dec_state codec_state;
418 wait_queue_head_t reconf_wait;
419 unsigned int subscriptions;
420 int buf_count;
421 struct venus_ts_metadata tss[VIDEO_MAX_FRAME];
422 unsigned long payloads[VIDEO_MAX_FRAME];
423 u64 fps;
424 struct v4l2_fract timeperframe;
425 const struct venus_format *fmt_out;
426 const struct venus_format *fmt_cap;
427 unsigned int num_input_bufs;
428 unsigned int num_output_bufs;
429 unsigned int input_buf_size;
430 unsigned int output_buf_size;
431 unsigned int output2_buf_size;
432 u32 dpb_buftype;
433 u32 dpb_fmt;
434 u32 opb_buftype;
435 u32 opb_fmt;
436 bool reconfig;
437 u32 hfi_codec;
438 u32 sequence_cap;
439 u32 sequence_out;
440 struct v4l2_m2m_dev *m2m_dev;
441 struct v4l2_m2m_ctx *m2m_ctx;
442 unsigned int state;
443 struct completion done;
444 unsigned int error;
445 bool session_error;
446 const struct hfi_inst_ops *ops;
447 u32 session_type;
448 union hfi_get_property hprop;
449 unsigned int core_acquired: 1;
450 unsigned int bit_depth;
451 unsigned int pic_struct;
452 bool next_buf_last;
453 bool drain_active;
454 enum venus_inst_modes flags;
455};
456
457#define IS_V1(core) ((core)->res->hfi_version == HFI_VERSION_1XX)
458#define IS_V3(core) ((core)->res->hfi_version == HFI_VERSION_3XX)
459#define IS_V4(core) ((core)->res->hfi_version == HFI_VERSION_4XX)
460#define IS_V6(core) ((core)->res->hfi_version == HFI_VERSION_6XX)
461
462#define ctrl_to_inst(ctrl) \
463 container_of((ctrl)->handler, struct venus_inst, ctrl_handler)
464
465static inline struct venus_inst *to_inst(struct file *filp)
466{
467 return container_of(filp->private_data, struct venus_inst, fh);
468}
469
470static inline void *to_hfi_priv(struct venus_core *core)
471{
472 return core->priv;
473}
474
475static inline struct hfi_plat_caps *
476venus_caps_by_codec(struct venus_core *core, u32 codec, u32 domain)
477{
478 unsigned int c;
479
480 for (c = 0; c < core->codecs_count; c++) {
481 if (core->caps[c].codec == codec &&
482 core->caps[c].domain == domain)
483 return &core->caps[c];
484 }
485
486 return NULL;
487}
488
489#endif
490