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 #define VIDC_CLKS_NUM_MAX 4
29 struct venus_resources {
31 const struct freq_tbl *freq_tbl;
32 unsigned int freq_tbl_size;
33 const struct reg_val *reg_tbl;
34 unsigned int reg_tbl_size;
35 const char * const clks[VIDC_CLKS_NUM_MAX];
36 unsigned int clks_num;
37 enum hfi_version hfi_version;
47 unsigned int num_planes;
52 #define MAX_FMT_ENTRIES 32
53 #define MAX_CAP_ENTRIES 32
54 #define MAX_ALLOC_MODE_ENTRIES 16
55 #define MAX_CODEC_NUM 32
65 bool cap_bufs_mode_dynamic;
66 unsigned int num_caps;
67 struct hfi_capability caps[MAX_CAP_ENTRIES];
69 struct hfi_profile_level pl[HFI_MAX_PROFILE_COUNT];
70 unsigned int num_fmts;
71 struct raw_formats fmts[MAX_FMT_ENTRIES];
72 bool valid; /* used only for Venus v1xx */
76 * struct venus_core - holds core parameters valid for all instances
78 * @base: IO memory base address
80 * @clks: an array of struct clk pointers
81 * @core0_clk: a struct clk pointer for core0
82 * @core1_clk: a struct clk pointer for core1
83 * @core0_bus_clk: a struct clk pointer for core0 bus clock
84 * @core1_bus_clk: a struct clk pointer for core1 bus clock
85 * @vdev_dec: a reference to video device structure for decoder instances
86 * @vdev_enc: a reference to video device structure for encoder instances
87 * @v4l2_dev: a holder for v4l2 device structure
88 * @res: a reference to venus resources structure
89 * @dev: convenience struct device pointer
90 * @dev_dec: convenience struct device pointer for decoder device
91 * @dev_enc: convenience struct device pointer for encoder device
92 * @use_tz: a flag that suggests presence of trustzone
93 * @lock: a lock for this strucure
94 * @instances: a list_head of all instances
95 * @insts_count: num of instances
96 * @state: the state of the venus core
97 * @done: a completion for sync HFI operations
98 * @error: an error returned during last HFI sync operations
99 * @sys_error: an error flag that signal system error event
100 * @core_ops: the core operations
101 * @enc_codecs: encoders supported by this core
102 * @dec_codecs: decoders supported by this core
103 * @max_sessions_supported: holds the maximum number of sessions
104 * @core_caps: core capabilities
105 * @priv: a private filed for HFI operations
106 * @ops: the core HFI operations
107 * @work: a delayed work for handling system fatal error
112 struct clk *clks[VIDC_CLKS_NUM_MAX];
113 struct clk *core0_clk;
114 struct clk *core1_clk;
115 struct clk *core0_bus_clk;
116 struct clk *core1_bus_clk;
117 struct video_device *vdev_dec;
118 struct video_device *vdev_enc;
119 struct v4l2_device v4l2_dev;
120 const struct venus_resources *res;
122 struct device *dev_dec;
123 struct device *dev_enc;
125 struct video_firmware {
127 struct iommu_domain *iommu_domain;
128 size_t mapped_mem_size;
131 struct list_head instances;
132 atomic_t insts_count;
134 struct completion done;
137 const struct hfi_core_ops *core_ops;
138 unsigned long enc_codecs;
139 unsigned long dec_codecs;
140 unsigned int max_sessions_supported;
141 #define ENC_ROTATION_CAPABILITY 0x1
142 #define ENC_SCALING_CAPABILITY 0x2
143 #define ENC_DEINTERLACE_CAPABILITY 0x4
144 #define DEC_MULTI_STREAM_CAPABILITY 0x8
145 unsigned int core_caps;
147 const struct hfi_ops *ops;
148 struct delayed_work work;
149 struct venus_caps caps[MAX_CODEC_NUM];
150 unsigned int codecs_count;
153 struct vdec_controls {
154 u32 post_loop_deb_mode;
159 struct venc_controls {
168 u32 h264_entropy_mode;
174 u32 h264_loop_filter_mode;
175 s32 h264_loop_filter_alpha;
176 s32 h264_loop_filter_beta;
181 u32 multi_slice_mode;
182 u32 multi_slice_max_bytes;
183 u32 multi_slice_max_mb;
200 struct venus_buffer {
201 struct vb2_v4l2_buffer vb;
202 struct list_head list;
205 struct list_head reg_list;
207 struct list_head ref_list;
210 #define to_venus_buffer(ptr) container_of(ptr, struct venus_buffer, vb)
213 * struct venus_inst - holds per instance parameters
215 * @list: used for attach an instance to the core
216 * @lock: instance lock
217 * @core: a reference to the core struct
218 * @dpbbufs: a list of decoded picture buffers
219 * @internalbufs: a list of internal bufferes
220 * @registeredbufs: a list of registered capture bufferes
221 * @delayed_process a list of delayed buffers
222 * @delayed_process_work: a work_struct for process delayed buffers
223 * @ctrl_handler: v4l control handler
224 * @controls: a union of decoder and encoder control parameters
225 * @fh: a holder of v4l file handle structure
226 * @streamon_cap: stream on flag for capture queue
227 * @streamon_out: stream on flag for output queue
228 * @width: current capture width
229 * @height: current capture height
230 * @out_width: current output width
231 * @out_height: current output height
232 * @colorspace: current color space
233 * @quantization: current quantization
234 * @xfer_func: current xfer function
235 * @fps: holds current FPS
236 * @timeperframe: holds current time per frame structure
237 * @fmt_out: a reference to output format structure
238 * @fmt_cap: a reference to capture format structure
239 * @num_input_bufs: holds number of input buffers
240 * @num_output_bufs: holds number of output buffers
241 * @input_buf_size holds input buffer size
242 * @output_buf_size: holds output buffer size
243 * @output2_buf_size: holds secondary decoder output buffer size
244 * @dpb_buftype: decoded picture buffer type
245 * @dpb_fmt: decoded picture buffer raw format
246 * @opb_buftype: output picture buffer type
247 * @opb_fmt: output picture buffer raw format
248 * @reconfig: a flag raised by decoder when the stream resolution changed
249 * @reconfig_width: holds the new width
250 * @reconfig_height: holds the new height
251 * @hfi_codec: current codec for this instance in HFI space
252 * @sequence_cap: a sequence counter for capture queue
253 * @sequence_out: a sequence counter for output queue
254 * @m2m_dev: a reference to m2m device structure
255 * @m2m_ctx: a reference to m2m context structure
256 * @state: current state of the instance
257 * @done: a completion for sync HFI operation
258 * @error: an error returned during last HFI sync operation
259 * @session_error: a flag rised by HFI interface in case of session error
260 * @ops: HFI operations
261 * @priv: a private for HFI operations callbacks
262 * @session_type: the type of the session (decoder or encoder)
263 * @hprop: a union used as a holder by get property
266 struct list_head list;
268 struct venus_core *core;
269 struct list_head dpbbufs;
270 struct list_head internalbufs;
271 struct list_head registeredbufs;
272 struct list_head delayed_process;
273 struct work_struct delayed_process_work;
275 struct v4l2_ctrl_handler ctrl_handler;
277 struct vdec_controls dec;
278 struct venc_controls enc;
281 unsigned int streamon_cap, streamon_out;
291 struct v4l2_fract timeperframe;
292 const struct venus_format *fmt_out;
293 const struct venus_format *fmt_cap;
294 unsigned int num_input_bufs;
295 unsigned int num_output_bufs;
296 unsigned int input_buf_size;
297 unsigned int output_buf_size;
298 unsigned int output2_buf_size;
309 struct v4l2_m2m_dev *m2m_dev;
310 struct v4l2_m2m_ctx *m2m_ctx;
312 struct completion done;
315 const struct hfi_inst_ops *ops;
317 union hfi_get_property hprop;
320 #define IS_V1(core) ((core)->res->hfi_version == HFI_VERSION_1XX)
321 #define IS_V3(core) ((core)->res->hfi_version == HFI_VERSION_3XX)
322 #define IS_V4(core) ((core)->res->hfi_version == HFI_VERSION_4XX)
324 #define ctrl_to_inst(ctrl) \
325 container_of((ctrl)->handler, struct venus_inst, ctrl_handler)
327 static inline struct venus_inst *to_inst(struct file *filp)
329 return container_of(filp->private_data, struct venus_inst, fh);
332 static inline void *to_hfi_priv(struct venus_core *core)
337 static inline struct venus_caps *
338 venus_caps_by_codec(struct venus_core *core, u32 codec, u32 domain)
342 for (c = 0; c < core->codecs_count; c++) {
343 if (core->caps[c].codec == codec &&
344 core->caps[c].domain == domain)
345 return &core->caps[c];