1 /* SPDX-License-Identifier: GPL-2.0-only */
3 * Copyright (c) 2012-2016, The Linux Foundation. All rights reserved.
4 * Copyright (C) 2017 Linaro Ltd.
7 #ifndef __VENUS_CORE_H_
8 #define __VENUS_CORE_H_
10 #include <linux/list.h>
11 #include <media/videobuf2-v4l2.h>
12 #include <media/v4l2-ctrls.h>
13 #include <media/v4l2-device.h>
17 #include "hfi_platform.h"
19 #define VDBGL "VenusLow : "
20 #define VDBGM "VenusMed : "
21 #define VDBGH "VenusHigh: "
22 #define VDBGFW "VenusFW : "
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
29 extern int venus_fw_debug;
49 struct venus_resources {
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;
77 u32 cp_nonpixel_start;
84 unsigned int num_planes;
90 * struct venus_core - holds core parameters valid for all instances
92 * @base: IO memory base address
93 * @vbif_base: IO memory vbif base address
94 * @cpu_base: IO memory cpu base address
95 * @cpu_cs_base: IO memory cpu_cs base address
96 * @cpu_ic_base: IO memory cpu_ic base address
97 * @wrapper_base: IO memory wrapper base address
98 * @wrapper_tz_base: IO memory wrapper TZ base address
99 * @aon_base: AON base address
101 * @clks: an array of struct clk pointers
102 * @vcodec0_clks: an array of vcodec0 struct clk pointers
103 * @vcodec1_clks: an array of vcodec1 struct clk pointers
104 * @video_path: an interconnect handle to video to/from memory path
105 * @cpucfg_path: an interconnect handle to cpu configuration path
106 * @opp_table: an device OPP table handle
107 * @has_opp_table: does OPP table exist
108 * @pmdomains: an array of pmdomains struct device pointers
109 * @opp_dl_venus: an device-link for device OPP
110 * @opp_pmdomain: an OPP power-domain
111 * @resets: an array of reset signals
112 * @vdev_dec: a reference to video device structure for decoder instances
113 * @vdev_enc: a reference to video device structure for encoder instances
114 * @v4l2_dev: a holder for v4l2 device structure
115 * @res: a reference to venus resources structure
116 * @dev: convenience struct device pointer
117 * @dev_dec: convenience struct device pointer for decoder device
118 * @dev_enc: convenience struct device pointer for encoder device
119 * @use_tz: a flag that suggests presence of trustzone
120 * @fw: structure of firmware parameters
121 * @lock: a lock for this strucure
122 * @instances: a list_head of all instances
123 * @insts_count: num of instances
124 * @state: the state of the venus core
125 * @done: a completion for sync HFI operations
126 * @error: an error returned during last HFI sync operations
127 * @sys_error: an error flag that signal system error event
128 * @core_ops: the core operations
129 * @pm_ops: a pointer to pm operations
130 * @pm_lock: a lock for PM operations
131 * @enc_codecs: encoders supported by this core
132 * @dec_codecs: decoders supported by this core
133 * @max_sessions_supported: holds the maximum number of sessions
134 * @priv: a private filed for HFI operations
135 * @ops: the core HFI operations
136 * @work: a delayed work for handling system fatal error
137 * @caps: an array of supported HFI capabilities
138 * @codecs_count: platform codecs count
139 * @core0_usage_count: usage counter for core0
140 * @core1_usage_count: usage counter for core1
141 * @root: debugfs root directory
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;
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;
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;
168 struct device *dev_dec;
169 struct device *dev_enc;
171 struct video_firmware {
173 struct iommu_domain *iommu_domain;
174 size_t mapped_mem_size;
175 phys_addr_t mem_phys;
179 struct list_head instances;
180 atomic_t insts_count;
182 struct completion done;
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;
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;
201 struct vdec_controls {
202 u32 post_loop_deb_mode;
206 u32 display_delay_enable;
210 struct venc_controls {
222 u32 h264_entropy_mode;
234 u32 h264_loop_filter_mode;
235 s32 h264_loop_filter_alpha;
236 s32 h264_loop_filter_beta;
237 u32 h264_8x8_transform;
254 u32 multi_slice_mode;
255 u32 multi_slice_max_bytes;
256 u32 multi_slice_max_mb;
260 u32 intra_refresh_period;
276 u32 base_priority_id;
278 struct v4l2_ctrl_hdr10_cll_info cll;
279 struct v4l2_ctrl_hdr10_mastering_display mastering;
282 struct venus_buffer {
283 struct vb2_v4l2_buffer vb;
284 struct list_head list;
287 struct list_head reg_list;
289 struct list_head ref_list;
295 unsigned long vpp_freq;
296 unsigned long vsp_freq;
297 unsigned long low_power_freq;
300 #define to_venus_buffer(ptr) container_of(ptr, struct venus_buffer, vb)
302 enum 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,
313 struct venus_ts_metadata {
318 struct v4l2_timecode tc;
321 enum venus_inst_modes {
322 VENUS_LOW_POWER = BIT(0),
326 * struct venus_inst - holds per instance parameters
328 * @list: used for attach an instance to the core
329 * @lock: instance lock
330 * @core: a reference to the core struct
331 * @clk_data: clock data per core ID
332 * @dpbbufs: a list of decoded picture buffers
333 * @internalbufs: a list of internal bufferes
334 * @registeredbufs: a list of registered capture bufferes
335 * @delayed_process: a list of delayed buffers
336 * @delayed_process_work: a work_struct for process delayed buffers
337 * @ctrl_handler: v4l control handler
338 * @controls: a union of decoder and encoder control parameters
339 * @fh: a holder of v4l file handle structure
340 * @streamon_cap: stream on flag for capture queue
341 * @streamon_out: stream on flag for output queue
342 * @width: current capture width
343 * @height: current capture height
344 * @crop: current crop rectangle
345 * @out_width: current output width
346 * @out_height: current output height
347 * @colorspace: current color space
348 * @ycbcr_enc: current YCbCr encoding
349 * @quantization: current quantization
350 * @xfer_func: current xfer function
351 * @codec_state: current codec API state (see DEC/ENC_STATE_)
352 * @reconf_wait: wait queue for resolution change event
353 * @subscriptions: used to hold current events subscriptions
354 * @buf_count: used to count number of buffers (reqbuf(0))
355 * @tss: timestamp metadata
356 * @payloads: cache plane payload to use it for clock/BW scaling
357 * @fps: holds current FPS
358 * @timeperframe: holds current time per frame structure
359 * @fmt_out: a reference to output format structure
360 * @fmt_cap: a reference to capture format structure
361 * @num_input_bufs: holds number of input buffers
362 * @num_output_bufs: holds number of output buffers
363 * @input_buf_size: holds input buffer size
364 * @output_buf_size: holds output buffer size
365 * @output2_buf_size: holds secondary decoder output buffer size
366 * @dpb_buftype: decoded picture buffer type
367 * @dpb_fmt: decoded picture buffer raw format
368 * @opb_buftype: output picture buffer type
369 * @opb_fmt: output picture buffer raw format
370 * @reconfig: a flag raised by decoder when the stream resolution changed
371 * @hfi_codec: current codec for this instance in HFI space
372 * @sequence_cap: a sequence counter for capture queue
373 * @sequence_out: a sequence counter for output queue
374 * @m2m_dev: a reference to m2m device structure
375 * @m2m_ctx: a reference to m2m context structure
376 * @state: current state of the instance
377 * @done: a completion for sync HFI operation
378 * @error: an error returned during last HFI sync operation
379 * @session_error: a flag rised by HFI interface in case of session error
380 * @ops: HFI operations
381 * @priv: a private for HFI operations callbacks
382 * @session_type: the type of the session (decoder or encoder)
383 * @hprop: a union used as a holder by get property
384 * @core_acquired: the Core has been acquired
385 * @bit_depth: current bitstream bit-depth
386 * @pic_struct: bitstream progressive vs interlaced
387 * @next_buf_last: a flag to mark next queued capture buffer as last
388 * @drain_active: Drain sequence is in progress
391 struct list_head list;
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;
401 struct v4l2_ctrl_handler ctrl_handler;
403 struct vdec_controls dec;
404 struct venc_controls enc;
407 unsigned int streamon_cap, streamon_out;
410 struct v4l2_rect crop;
417 enum venus_dec_state codec_state;
418 wait_queue_head_t reconf_wait;
419 unsigned int subscriptions;
421 struct venus_ts_metadata tss[VIDEO_MAX_FRAME];
422 unsigned long payloads[VIDEO_MAX_FRAME];
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;
440 struct v4l2_m2m_dev *m2m_dev;
441 struct v4l2_m2m_ctx *m2m_ctx;
443 struct completion done;
446 const struct hfi_inst_ops *ops;
448 union hfi_get_property hprop;
449 unsigned int core_acquired: 1;
450 unsigned int bit_depth;
451 unsigned int pic_struct;
454 enum venus_inst_modes flags;
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)
462 #define ctrl_to_inst(ctrl) \
463 container_of((ctrl)->handler, struct venus_inst, ctrl_handler)
465 static inline struct venus_inst *to_inst(struct file *filp)
467 return container_of(filp->private_data, struct venus_inst, fh);
470 static inline void *to_hfi_priv(struct venus_core *core)
475 static inline struct hfi_plat_caps *
476 venus_caps_by_codec(struct venus_core *core, u32 codec, u32 domain)
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];