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/bitops.h>
11 #include <linux/list.h>
12 #include <media/videobuf2-v4l2.h>
13 #include <media/v4l2-ctrls.h>
14 #include <media/v4l2-device.h>
18 #include "hfi_platform.h"
19 #include "hfi_helper.h"
21 #define VDBGL "VenusLow : "
22 #define VDBGM "VenusMed : "
23 #define VDBGH "VenusHigh: "
24 #define VDBGFW "VenusFW : "
26 #define VIDC_CLKS_NUM_MAX 4
27 #define VIDC_VCODEC_CLKS_NUM_MAX 2
28 #define VIDC_PMDOMAINS_NUM_MAX 3
29 #define VIDC_RESETS_NUM_MAX 2
31 extern int venus_fw_debug;
51 struct venus_resources {
53 const struct freq_tbl *freq_tbl;
54 unsigned int freq_tbl_size;
55 const struct bw_tbl *bw_tbl_enc;
56 unsigned int bw_tbl_enc_size;
57 const struct bw_tbl *bw_tbl_dec;
58 unsigned int bw_tbl_dec_size;
59 const struct reg_val *reg_tbl;
60 unsigned int reg_tbl_size;
61 const struct hfi_ubwc_config *ubwc_conf;
62 const char * const clks[VIDC_CLKS_NUM_MAX];
63 unsigned int clks_num;
64 const char * const vcodec0_clks[VIDC_VCODEC_CLKS_NUM_MAX];
65 const char * const vcodec1_clks[VIDC_VCODEC_CLKS_NUM_MAX];
66 unsigned int vcodec_clks_num;
67 const char * const vcodec_pmdomains[VIDC_PMDOMAINS_NUM_MAX];
68 unsigned int vcodec_pmdomains_num;
69 const char **opp_pmdomain;
70 unsigned int vcodec_num;
71 const char * const resets[VIDC_RESETS_NUM_MAX];
72 unsigned int resets_num;
73 enum hfi_version hfi_version;
81 u32 cp_nonpixel_start;
88 unsigned int num_planes;
94 * struct venus_core - holds core parameters valid for all instances
96 * @base: IO memory base address
97 * @vbif_base: IO memory vbif base address
98 * @cpu_base: IO memory cpu base address
99 * @cpu_cs_base: IO memory cpu_cs base address
100 * @cpu_ic_base: IO memory cpu_ic base address
101 * @wrapper_base: IO memory wrapper base address
102 * @wrapper_tz_base: IO memory wrapper TZ base address
103 * @aon_base: AON base address
105 * @clks: an array of struct clk pointers
106 * @vcodec0_clks: an array of vcodec0 struct clk pointers
107 * @vcodec1_clks: an array of vcodec1 struct clk pointers
108 * @video_path: an interconnect handle to video to/from memory path
109 * @cpucfg_path: an interconnect handle to cpu configuration path
110 * @has_opp_table: does OPP table exist
111 * @pmdomains: an array of pmdomains struct device pointers
112 * @opp_dl_venus: an device-link for device OPP
113 * @opp_pmdomain: an OPP power-domain
114 * @resets: an array of reset signals
115 * @vdev_dec: a reference to video device structure for decoder instances
116 * @vdev_enc: a reference to video device structure for encoder instances
117 * @v4l2_dev: a holder for v4l2 device structure
118 * @res: a reference to venus resources structure
119 * @dev: convenience struct device pointer
120 * @dev_dec: convenience struct device pointer for decoder device
121 * @dev_enc: convenience struct device pointer for encoder device
122 * @use_tz: a flag that suggests presence of trustzone
123 * @fw: structure of firmware parameters
124 * @lock: a lock for this strucure
125 * @instances: a list_head of all instances
126 * @insts_count: num of instances
127 * @state: the state of the venus core
128 * @done: a completion for sync HFI operations
129 * @error: an error returned during last HFI sync operations
130 * @sys_error: an error flag that signal system error event
131 * @sys_err_done: a waitqueue to wait for system error recovery end
132 * @core_ops: the core operations
133 * @pm_ops: a pointer to pm operations
134 * @pm_lock: a lock for PM operations
135 * @enc_codecs: encoders supported by this core
136 * @dec_codecs: decoders supported by this core
137 * @max_sessions_supported: holds the maximum number of sessions
138 * @priv: a private filed for HFI operations
139 * @ops: the core HFI operations
140 * @work: a delayed work for handling system fatal error
141 * @caps: an array of supported HFI capabilities
142 * @codecs_count: platform codecs count
143 * @core0_usage_count: usage counter for core0
144 * @core1_usage_count: usage counter for core1
145 * @root: debugfs root directory
149 void __iomem *vbif_base;
150 void __iomem *cpu_base;
151 void __iomem *cpu_cs_base;
152 void __iomem *cpu_ic_base;
153 void __iomem *wrapper_base;
154 void __iomem *wrapper_tz_base;
155 void __iomem *aon_base;
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;
163 struct device *pmdomains[VIDC_PMDOMAINS_NUM_MAX];
164 struct device_link *opp_dl_venus;
165 struct device *opp_pmdomain;
166 struct reset_control *resets[VIDC_RESETS_NUM_MAX];
167 struct video_device *vdev_dec;
168 struct video_device *vdev_enc;
169 struct v4l2_device v4l2_dev;
170 const struct venus_resources *res;
172 struct device *dev_dec;
173 struct device *dev_enc;
175 struct video_firmware {
177 struct iommu_domain *iommu_domain;
178 size_t mapped_mem_size;
179 phys_addr_t mem_phys;
183 struct list_head instances;
184 atomic_t insts_count;
186 struct completion done;
188 unsigned long sys_error;
189 wait_queue_head_t sys_err_done;
190 const struct hfi_core_ops *core_ops;
191 const struct venus_pm_ops *pm_ops;
192 struct mutex pm_lock;
193 unsigned long enc_codecs;
194 unsigned long dec_codecs;
195 unsigned int max_sessions_supported;
197 const struct hfi_ops *ops;
198 struct delayed_work work;
199 struct hfi_plat_caps caps[MAX_CODEC_NUM];
200 unsigned int codecs_count;
201 unsigned int core0_usage_count;
202 unsigned int core1_usage_count;
206 struct vdec_controls {
207 u32 post_loop_deb_mode;
211 u32 display_delay_enable;
215 struct venc_controls {
227 u32 h264_entropy_mode;
239 u32 h264_loop_filter_mode;
240 s32 h264_loop_filter_alpha;
241 s32 h264_loop_filter_beta;
242 u32 h264_8x8_transform;
259 u32 multi_slice_mode;
260 u32 multi_slice_max_bytes;
261 u32 multi_slice_max_mb;
265 u32 intra_refresh_type;
266 u32 intra_refresh_period;
282 u32 base_priority_id;
284 struct v4l2_ctrl_hdr10_cll_info cll;
285 struct v4l2_ctrl_hdr10_mastering_display mastering;
288 struct venus_buffer {
289 struct vb2_v4l2_buffer vb;
290 struct list_head list;
293 struct list_head reg_list;
295 struct list_head ref_list;
301 unsigned long vpp_freq;
302 unsigned long vsp_freq;
303 unsigned long low_power_freq;
306 #define to_venus_buffer(ptr) container_of(ptr, struct venus_buffer, vb)
308 enum venus_dec_state {
309 VENUS_DEC_STATE_DEINIT = 0,
310 VENUS_DEC_STATE_INIT = 1,
311 VENUS_DEC_STATE_CAPTURE_SETUP = 2,
312 VENUS_DEC_STATE_STOPPED = 3,
313 VENUS_DEC_STATE_SEEK = 4,
314 VENUS_DEC_STATE_DRAIN = 5,
315 VENUS_DEC_STATE_DECODING = 6,
316 VENUS_DEC_STATE_DRC = 7,
319 enum venus_enc_state {
320 VENUS_ENC_STATE_DEINIT = 0,
321 VENUS_ENC_STATE_INIT = 1,
322 VENUS_ENC_STATE_ENCODING = 2,
323 VENUS_ENC_STATE_STOPPED = 3,
324 VENUS_ENC_STATE_DRAIN = 4,
327 struct venus_ts_metadata {
332 struct v4l2_timecode tc;
335 enum venus_inst_modes {
336 VENUS_LOW_POWER = BIT(0),
340 * struct venus_inst - holds per instance parameters
342 * @list: used for attach an instance to the core
343 * @lock: instance lock
344 * @core: a reference to the core struct
345 * @clk_data: clock data per core ID
346 * @dpbbufs: a list of decoded picture buffers
347 * @internalbufs: a list of internal bufferes
348 * @registeredbufs: a list of registered capture bufferes
349 * @delayed_process: a list of delayed buffers
350 * @delayed_process_work: a work_struct for process delayed buffers
351 * @nonblock: nonblocking flag
352 * @ctrl_handler: v4l control handler
353 * @controls: a union of decoder and encoder control parameters
354 * @fh: a holder of v4l file handle structure
355 * @streamon_cap: stream on flag for capture queue
356 * @streamon_out: stream on flag for output queue
357 * @width: current capture width
358 * @height: current capture height
359 * @crop: current crop rectangle
360 * @fw_min_cnt: firmware minimum buffer count
361 * @out_width: current output width
362 * @out_height: current output height
363 * @colorspace: current color space
364 * @ycbcr_enc: current YCbCr encoding
365 * @quantization: current quantization
366 * @xfer_func: current xfer function
367 * @codec_state: current codec API state (see DEC/ENC_STATE_)
368 * @reconf_wait: wait queue for resolution change event
369 * @subscriptions: used to hold current events subscriptions
370 * @buf_count: used to count number of buffers (reqbuf(0))
371 * @tss: timestamp metadata
372 * @payloads: cache plane payload to use it for clock/BW scaling
373 * @fps: holds current FPS
374 * @timeperframe: holds current time per frame structure
375 * @fmt_out: a reference to output format structure
376 * @fmt_cap: a reference to capture format structure
377 * @num_input_bufs: holds number of input buffers
378 * @num_output_bufs: holds number of output buffers
379 * @input_buf_size: holds input buffer size
380 * @output_buf_size: holds output buffer size
381 * @output2_buf_size: holds secondary decoder output buffer size
382 * @dpb_buftype: decoded picture buffer type
383 * @dpb_fmt: decoded picture buffer raw format
384 * @opb_buftype: output picture buffer type
385 * @opb_fmt: output picture buffer raw format
386 * @reconfig: a flag raised by decoder when the stream resolution changed
387 * @hfi_codec: current codec for this instance in HFI space
388 * @sequence_cap: a sequence counter for capture queue
389 * @sequence_out: a sequence counter for output queue
390 * @m2m_dev: a reference to m2m device structure
391 * @m2m_ctx: a reference to m2m context structure
392 * @state: current state of the instance
393 * @done: a completion for sync HFI operation
394 * @error: an error returned during last HFI sync operation
395 * @session_error: a flag rised by HFI interface in case of session error
396 * @ops: HFI operations
397 * @priv: a private for HFI operations callbacks
398 * @session_type: the type of the session (decoder or encoder)
399 * @hprop: a union used as a holder by get property
400 * @core_acquired: the Core has been acquired
401 * @bit_depth: current bitstream bit-depth
402 * @pic_struct: bitstream progressive vs interlaced
403 * @next_buf_last: a flag to mark next queued capture buffer as last
404 * @drain_active: Drain sequence is in progress
405 * @flags: bitmask flags describing current instance mode
406 * @dpb_ids: DPB buffer ID's
409 struct list_head list;
411 struct venus_core *core;
412 struct clock_data clk_data;
413 struct list_head dpbbufs;
414 struct list_head internalbufs;
415 struct list_head registeredbufs;
416 struct list_head delayed_process;
417 struct work_struct delayed_process_work;
420 struct v4l2_ctrl_handler ctrl_handler;
422 struct vdec_controls dec;
423 struct venc_controls enc;
426 unsigned int streamon_cap, streamon_out;
429 struct v4l2_rect crop;
437 enum venus_dec_state codec_state;
438 enum venus_enc_state enc_state;
439 wait_queue_head_t reconf_wait;
440 unsigned int subscriptions;
442 struct venus_ts_metadata tss[VIDEO_MAX_FRAME];
443 unsigned long payloads[VIDEO_MAX_FRAME];
445 struct v4l2_fract timeperframe;
446 const struct venus_format *fmt_out;
447 const struct venus_format *fmt_cap;
448 unsigned int num_input_bufs;
449 unsigned int num_output_bufs;
450 unsigned int input_buf_size;
451 unsigned int output_buf_size;
452 unsigned int output2_buf_size;
461 struct v4l2_m2m_dev *m2m_dev;
462 struct v4l2_m2m_ctx *m2m_ctx;
464 struct completion done;
467 const struct hfi_inst_ops *ops;
469 union hfi_get_property hprop;
470 unsigned int core_acquired: 1;
471 unsigned int bit_depth;
472 unsigned int pic_struct;
475 enum venus_inst_modes flags;
479 #define IS_V1(core) ((core)->res->hfi_version == HFI_VERSION_1XX)
480 #define IS_V3(core) ((core)->res->hfi_version == HFI_VERSION_3XX)
481 #define IS_V4(core) ((core)->res->hfi_version == HFI_VERSION_4XX)
482 #define IS_V6(core) ((core)->res->hfi_version == HFI_VERSION_6XX)
484 #define ctrl_to_inst(ctrl) \
485 container_of((ctrl)->handler, struct venus_inst, ctrl_handler)
487 static inline struct venus_inst *to_inst(struct file *filp)
489 return container_of(filp->private_data, struct venus_inst, fh);
492 static inline void *to_hfi_priv(struct venus_core *core)
497 static inline struct hfi_plat_caps *
498 venus_caps_by_codec(struct venus_core *core, u32 codec, u32 domain)
502 for (c = 0; c < core->codecs_count; c++) {
503 if (core->caps[c].codec == codec &&
504 core->caps[c].domain == domain)
505 return &core->caps[c];