2 * Copyright (c) 2012-2016, The Linux Foundation. All rights reserved.
3 * Copyright (C) 2017 Linaro Ltd.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 and
7 * only version 2 as published by the Free Software Foundation.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
16 #ifndef __VENUS_CORE_H_
17 #define __VENUS_CORE_H_
19 #include <linux/list.h>
20 #include <media/videobuf2-v4l2.h>
21 #include <media/v4l2-ctrls.h>
22 #include <media/v4l2-device.h>
26 #define VIDC_CLKS_NUM_MAX 4
38 struct venus_resources
{
40 const struct freq_tbl
*freq_tbl
;
41 unsigned int freq_tbl_size
;
42 const struct reg_val
*reg_tbl
;
43 unsigned int reg_tbl_size
;
44 const char * const clks
[VIDC_CLKS_NUM_MAX
];
45 unsigned int clks_num
;
46 enum hfi_version hfi_version
;
56 unsigned int num_planes
;
61 * struct venus_core - holds core parameters valid for all instances
63 * @base: IO memory base address
65 * @clks: an array of struct clk pointers
66 * @core0_clk: a struct clk pointer for core0
67 * @core1_clk: a struct clk pointer for core1
68 * @vdev_dec: a reference to video device structure for decoder instances
69 * @vdev_enc: a reference to video device structure for encoder instances
70 * @v4l2_dev: a holder for v4l2 device structure
71 * @res: a reference to venus resources structure
72 * @dev: convenience struct device pointer
73 * @dev_dec: convenience struct device pointer for decoder device
74 * @dev_enc: convenience struct device pointer for encoder device
75 * @lock: a lock for this strucure
76 * @instances: a list_head of all instances
77 * @insts_count: num of instances
78 * @state: the state of the venus core
79 * @done: a completion for sync HFI operations
80 * @error: an error returned during last HFI sync operations
81 * @sys_error: an error flag that signal system error event
82 * @core_ops: the core operations
83 * @enc_codecs: encoders supported by this core
84 * @dec_codecs: decoders supported by this core
85 * @max_sessions_supported: holds the maximum number of sessions
86 * @core_caps: core capabilities
87 * @priv: a private filed for HFI operations
88 * @ops: the core HFI operations
89 * @work: a delayed work for handling system fatal error
94 struct clk
*clks
[VIDC_CLKS_NUM_MAX
];
95 struct clk
*core0_clk
;
96 struct clk
*core1_clk
;
97 struct video_device
*vdev_dec
;
98 struct video_device
*vdev_enc
;
99 struct v4l2_device v4l2_dev
;
100 const struct venus_resources
*res
;
102 struct device
*dev_dec
;
103 struct device
*dev_enc
;
105 struct list_head instances
;
106 atomic_t insts_count
;
108 struct completion done
;
111 const struct hfi_core_ops
*core_ops
;
114 unsigned int max_sessions_supported
;
115 #define ENC_ROTATION_CAPABILITY 0x1
116 #define ENC_SCALING_CAPABILITY 0x2
117 #define ENC_DEINTERLACE_CAPABILITY 0x4
118 #define DEC_MULTI_STREAM_CAPABILITY 0x8
119 unsigned int core_caps
;
121 const struct hfi_ops
*ops
;
122 struct delayed_work work
;
125 struct vdec_controls
{
126 u32 post_loop_deb_mode
;
131 struct venc_controls
{
140 u32 h264_entropy_mode
;
146 u32 h264_loop_filter_mode
;
147 s32 h264_loop_filter_alpha
;
148 s32 h264_loop_filter_beta
;
153 u32 multi_slice_mode
;
154 u32 multi_slice_max_bytes
;
155 u32 multi_slice_max_mb
;
170 struct venus_buffer
{
171 struct vb2_v4l2_buffer vb
;
172 struct list_head list
;
175 struct list_head reg_list
;
177 struct list_head ref_list
;
180 #define to_venus_buffer(ptr) container_of(ptr, struct venus_buffer, vb)
183 * struct venus_inst - holds per instance paramerters
185 * @list: used for attach an instance to the core
186 * @lock: instance lock
187 * @core: a reference to the core struct
188 * @internalbufs: a list of internal bufferes
189 * @registeredbufs: a list of registered capture bufferes
190 * @delayed_process a list of delayed buffers
191 * @delayed_process_work: a work_struct for process delayed buffers
192 * @ctrl_handler: v4l control handler
193 * @controls: a union of decoder and encoder control parameters
194 * @fh: a holder of v4l file handle structure
195 * @streamon_cap: stream on flag for capture queue
196 * @streamon_out: stream on flag for output queue
197 * @width: current capture width
198 * @height: current capture height
199 * @out_width: current output width
200 * @out_height: current output height
201 * @colorspace: current color space
202 * @quantization: current quantization
203 * @xfer_func: current xfer function
204 * @fps: holds current FPS
205 * @timeperframe: holds current time per frame structure
206 * @fmt_out: a reference to output format structure
207 * @fmt_cap: a reference to capture format structure
208 * @num_input_bufs: holds number of input buffers
209 * @num_output_bufs: holds number of output buffers
210 * @input_buf_size holds input buffer size
211 * @output_buf_size: holds output buffer size
212 * @reconfig: a flag raised by decoder when the stream resolution changed
213 * @reconfig_width: holds the new width
214 * @reconfig_height: holds the new height
215 * @sequence_cap: a sequence counter for capture queue
216 * @sequence_out: a sequence counter for output queue
217 * @m2m_dev: a reference to m2m device structure
218 * @m2m_ctx: a reference to m2m context structure
219 * @state: current state of the instance
220 * @done: a completion for sync HFI operation
221 * @error: an error returned during last HFI sync operation
222 * @session_error: a flag rised by HFI interface in case of session error
223 * @ops: HFI operations
224 * @priv: a private for HFI operations callbacks
225 * @session_type: the type of the session (decoder or encoder)
226 * @hprop: a union used as a holder by get property
227 * @cap_width: width capability
228 * @cap_height: height capability
229 * @cap_mbs_per_frame: macroblocks per frame capability
230 * @cap_mbs_per_sec: macroblocks per second capability
231 * @cap_framerate: framerate capability
232 * @cap_scale_x: horizontal scaling capability
233 * @cap_scale_y: vertical scaling capability
234 * @cap_bitrate: bitrate capability
235 * @cap_hier_p: hier capability
236 * @cap_ltr_count: LTR count capability
237 * @cap_secure_output2_threshold: secure OUTPUT2 threshold capability
238 * @cap_bufs_mode_static: buffers allocation mode capability
239 * @cap_bufs_mode_dynamic: buffers allocation mode capability
240 * @pl_count: count of supported profiles/levels
241 * @pl: supported profiles/levels
242 * @bufreq: holds buffer requirements
245 struct list_head list
;
247 struct venus_core
*core
;
248 struct list_head internalbufs
;
249 struct list_head registeredbufs
;
250 struct list_head delayed_process
;
251 struct work_struct delayed_process_work
;
253 struct v4l2_ctrl_handler ctrl_handler
;
255 struct vdec_controls dec
;
256 struct venc_controls enc
;
259 unsigned int streamon_cap
, streamon_out
;
269 struct v4l2_fract timeperframe
;
270 const struct venus_format
*fmt_out
;
271 const struct venus_format
*fmt_cap
;
272 unsigned int num_input_bufs
;
273 unsigned int num_output_bufs
;
274 unsigned int input_buf_size
;
275 unsigned int output_buf_size
;
281 struct v4l2_m2m_dev
*m2m_dev
;
282 struct v4l2_m2m_ctx
*m2m_ctx
;
284 struct completion done
;
287 const struct hfi_inst_ops
*ops
;
289 union hfi_get_property hprop
;
290 struct hfi_capability cap_width
;
291 struct hfi_capability cap_height
;
292 struct hfi_capability cap_mbs_per_frame
;
293 struct hfi_capability cap_mbs_per_sec
;
294 struct hfi_capability cap_framerate
;
295 struct hfi_capability cap_scale_x
;
296 struct hfi_capability cap_scale_y
;
297 struct hfi_capability cap_bitrate
;
298 struct hfi_capability cap_hier_p
;
299 struct hfi_capability cap_ltr_count
;
300 struct hfi_capability cap_secure_output2_threshold
;
301 bool cap_bufs_mode_static
;
302 bool cap_bufs_mode_dynamic
;
303 unsigned int pl_count
;
304 struct hfi_profile_level pl
[HFI_MAX_PROFILE_COUNT
];
305 struct hfi_buffer_requirements bufreq
[HFI_BUFFER_TYPE_MAX
];
308 #define ctrl_to_inst(ctrl) \
309 container_of((ctrl)->handler, struct venus_inst, ctrl_handler)
311 static inline struct venus_inst
*to_inst(struct file
*filp
)
313 return container_of(filp
->private_data
, struct venus_inst
, fh
);
316 static inline void *to_hfi_priv(struct venus_core
*core
)