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
;
104 struct device dev_fw
;
106 struct list_head instances
;
107 atomic_t insts_count
;
109 struct completion done
;
112 const struct hfi_core_ops
*core_ops
;
115 unsigned int max_sessions_supported
;
116 #define ENC_ROTATION_CAPABILITY 0x1
117 #define ENC_SCALING_CAPABILITY 0x2
118 #define ENC_DEINTERLACE_CAPABILITY 0x4
119 #define DEC_MULTI_STREAM_CAPABILITY 0x8
120 unsigned int core_caps
;
122 const struct hfi_ops
*ops
;
123 struct delayed_work work
;
126 struct vdec_controls
{
127 u32 post_loop_deb_mode
;
132 struct venc_controls
{
141 u32 h264_entropy_mode
;
147 u32 h264_loop_filter_mode
;
148 u32 h264_loop_filter_alpha
;
149 u32 h264_loop_filter_beta
;
154 u32 multi_slice_mode
;
155 u32 multi_slice_max_bytes
;
156 u32 multi_slice_max_mb
;
171 struct venus_buffer
{
172 struct vb2_v4l2_buffer vb
;
173 struct list_head list
;
176 struct list_head reg_list
;
178 struct list_head ref_list
;
181 #define to_venus_buffer(ptr) container_of(ptr, struct venus_buffer, vb)
184 * struct venus_inst - holds per instance paramerters
186 * @list: used for attach an instance to the core
187 * @lock: instance lock
188 * @core: a reference to the core struct
189 * @internalbufs: a list of internal bufferes
190 * @registeredbufs: a list of registered capture bufferes
191 * @delayed_process a list of delayed buffers
192 * @delayed_process_work: a work_struct for process delayed buffers
193 * @ctrl_handler: v4l control handler
194 * @controls: a union of decoder and encoder control parameters
195 * @fh: a holder of v4l file handle structure
196 * @streamon_cap: stream on flag for capture queue
197 * @streamon_out: stream on flag for output queue
198 * @cmd_stop: a flag to signal encoder/decoder commands
199 * @width: current capture width
200 * @height: current capture height
201 * @out_width: current output width
202 * @out_height: current output height
203 * @colorspace: current color space
204 * @quantization: current quantization
205 * @xfer_func: current xfer function
206 * @fps: holds current FPS
207 * @timeperframe: holds current time per frame structure
208 * @fmt_out: a reference to output format structure
209 * @fmt_cap: a reference to capture format structure
210 * @num_input_bufs: holds number of input buffers
211 * @num_output_bufs: holds number of output buffers
212 * @input_buf_size holds input buffer size
213 * @output_buf_size: holds output buffer size
214 * @reconfig: a flag raised by decoder when the stream resolution changed
215 * @reconfig_width: holds the new width
216 * @reconfig_height: holds the new height
217 * @sequence_cap: a sequence counter for capture queue
218 * @sequence_out: a sequence counter for output queue
219 * @m2m_dev: a reference to m2m device structure
220 * @m2m_ctx: a reference to m2m context structure
221 * @state: current state of the instance
222 * @done: a completion for sync HFI operation
223 * @error: an error returned during last HFI sync operation
224 * @session_error: a flag rised by HFI interface in case of session error
225 * @ops: HFI operations
226 * @priv: a private for HFI operations callbacks
227 * @session_type: the type of the session (decoder or encoder)
228 * @hprop: a union used as a holder by get property
229 * @cap_width: width capability
230 * @cap_height: height capability
231 * @cap_mbs_per_frame: macroblocks per frame capability
232 * @cap_mbs_per_sec: macroblocks per second capability
233 * @cap_framerate: framerate capability
234 * @cap_scale_x: horizontal scaling capability
235 * @cap_scale_y: vertical scaling capability
236 * @cap_bitrate: bitrate capability
237 * @cap_hier_p: hier capability
238 * @cap_ltr_count: LTR count capability
239 * @cap_secure_output2_threshold: secure OUTPUT2 threshold capability
240 * @cap_bufs_mode_static: buffers allocation mode capability
241 * @cap_bufs_mode_dynamic: buffers allocation mode capability
242 * @pl_count: count of supported profiles/levels
243 * @pl: supported profiles/levels
244 * @bufreq: holds buffer requirements
247 struct list_head list
;
249 struct venus_core
*core
;
250 struct list_head internalbufs
;
251 struct list_head registeredbufs
;
252 struct list_head delayed_process
;
253 struct work_struct delayed_process_work
;
255 struct v4l2_ctrl_handler ctrl_handler
;
257 struct vdec_controls dec
;
258 struct venc_controls enc
;
261 unsigned int streamon_cap
, streamon_out
;
272 struct v4l2_fract timeperframe
;
273 const struct venus_format
*fmt_out
;
274 const struct venus_format
*fmt_cap
;
275 unsigned int num_input_bufs
;
276 unsigned int num_output_bufs
;
277 unsigned int input_buf_size
;
278 unsigned int output_buf_size
;
284 struct v4l2_m2m_dev
*m2m_dev
;
285 struct v4l2_m2m_ctx
*m2m_ctx
;
287 struct completion done
;
290 const struct hfi_inst_ops
*ops
;
292 union hfi_get_property hprop
;
293 struct hfi_capability cap_width
;
294 struct hfi_capability cap_height
;
295 struct hfi_capability cap_mbs_per_frame
;
296 struct hfi_capability cap_mbs_per_sec
;
297 struct hfi_capability cap_framerate
;
298 struct hfi_capability cap_scale_x
;
299 struct hfi_capability cap_scale_y
;
300 struct hfi_capability cap_bitrate
;
301 struct hfi_capability cap_hier_p
;
302 struct hfi_capability cap_ltr_count
;
303 struct hfi_capability cap_secure_output2_threshold
;
304 bool cap_bufs_mode_static
;
305 bool cap_bufs_mode_dynamic
;
306 unsigned int pl_count
;
307 struct hfi_profile_level pl
[HFI_MAX_PROFILE_COUNT
];
308 struct hfi_buffer_requirements bufreq
[HFI_BUFFER_TYPE_MAX
];
311 #define ctrl_to_inst(ctrl) \
312 container_of((ctrl)->handler, struct venus_inst, ctrl_handler)
314 static inline struct venus_inst
*to_inst(struct file
*filp
)
316 return container_of(filp
->private_data
, struct venus_inst
, fh
);
319 static inline void *to_hfi_priv(struct venus_core
*core
)