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 #define MAX_FMT_ENTRIES 32
62 #define MAX_CAP_ENTRIES 32
63 #define MAX_ALLOC_MODE_ENTRIES 16
64 #define MAX_CODEC_NUM 32
74 bool cap_bufs_mode_dynamic
;
75 unsigned int num_caps
;
76 struct hfi_capability caps
[MAX_CAP_ENTRIES
];
78 struct hfi_profile_level pl
[HFI_MAX_PROFILE_COUNT
];
79 unsigned int num_fmts
;
80 struct raw_formats fmts
[MAX_FMT_ENTRIES
];
81 bool valid
; /* used only for Venus v1xx */
85 * struct venus_core - holds core parameters valid for all instances
87 * @base: IO memory base address
89 * @clks: an array of struct clk pointers
90 * @core0_clk: a struct clk pointer for core0
91 * @core1_clk: a struct clk pointer for core1
92 * @core0_bus_clk: a struct clk pointer for core0 bus clock
93 * @core1_bus_clk: a struct clk pointer for core1 bus clock
94 * @vdev_dec: a reference to video device structure for decoder instances
95 * @vdev_enc: a reference to video device structure for encoder instances
96 * @v4l2_dev: a holder for v4l2 device structure
97 * @res: a reference to venus resources structure
98 * @dev: convenience struct device pointer
99 * @dev_dec: convenience struct device pointer for decoder device
100 * @dev_enc: convenience struct device pointer for encoder device
101 * @lock: a lock for this strucure
102 * @instances: a list_head of all instances
103 * @insts_count: num of instances
104 * @state: the state of the venus core
105 * @done: a completion for sync HFI operations
106 * @error: an error returned during last HFI sync operations
107 * @sys_error: an error flag that signal system error event
108 * @core_ops: the core operations
109 * @enc_codecs: encoders supported by this core
110 * @dec_codecs: decoders supported by this core
111 * @max_sessions_supported: holds the maximum number of sessions
112 * @core_caps: core capabilities
113 * @priv: a private filed for HFI operations
114 * @ops: the core HFI operations
115 * @work: a delayed work for handling system fatal error
120 struct clk
*clks
[VIDC_CLKS_NUM_MAX
];
121 struct clk
*core0_clk
;
122 struct clk
*core1_clk
;
123 struct clk
*core0_bus_clk
;
124 struct clk
*core1_bus_clk
;
125 struct video_device
*vdev_dec
;
126 struct video_device
*vdev_enc
;
127 struct v4l2_device v4l2_dev
;
128 const struct venus_resources
*res
;
130 struct device
*dev_dec
;
131 struct device
*dev_enc
;
133 struct list_head instances
;
134 atomic_t insts_count
;
136 struct completion done
;
139 const struct hfi_core_ops
*core_ops
;
140 unsigned long enc_codecs
;
141 unsigned long dec_codecs
;
142 unsigned int max_sessions_supported
;
143 #define ENC_ROTATION_CAPABILITY 0x1
144 #define ENC_SCALING_CAPABILITY 0x2
145 #define ENC_DEINTERLACE_CAPABILITY 0x4
146 #define DEC_MULTI_STREAM_CAPABILITY 0x8
147 unsigned int core_caps
;
149 const struct hfi_ops
*ops
;
150 struct delayed_work work
;
151 struct venus_caps caps
[MAX_CODEC_NUM
];
152 unsigned int codecs_count
;
155 struct vdec_controls
{
156 u32 post_loop_deb_mode
;
161 struct venc_controls
{
170 u32 h264_entropy_mode
;
176 u32 h264_loop_filter_mode
;
177 s32 h264_loop_filter_alpha
;
178 s32 h264_loop_filter_beta
;
183 u32 multi_slice_mode
;
184 u32 multi_slice_max_bytes
;
185 u32 multi_slice_max_mb
;
202 struct venus_buffer
{
203 struct vb2_v4l2_buffer vb
;
204 struct list_head list
;
207 struct list_head reg_list
;
209 struct list_head ref_list
;
212 #define to_venus_buffer(ptr) container_of(ptr, struct venus_buffer, vb)
215 * struct venus_inst - holds per instance paramerters
217 * @list: used for attach an instance to the core
218 * @lock: instance lock
219 * @core: a reference to the core struct
220 * @dpbbufs: a list of decoded picture buffers
221 * @internalbufs: a list of internal bufferes
222 * @registeredbufs: a list of registered capture bufferes
223 * @delayed_process a list of delayed buffers
224 * @delayed_process_work: a work_struct for process delayed buffers
225 * @ctrl_handler: v4l control handler
226 * @controls: a union of decoder and encoder control parameters
227 * @fh: a holder of v4l file handle structure
228 * @streamon_cap: stream on flag for capture queue
229 * @streamon_out: stream on flag for output queue
230 * @width: current capture width
231 * @height: current capture height
232 * @out_width: current output width
233 * @out_height: current output height
234 * @colorspace: current color space
235 * @quantization: current quantization
236 * @xfer_func: current xfer function
237 * @fps: holds current FPS
238 * @timeperframe: holds current time per frame structure
239 * @fmt_out: a reference to output format structure
240 * @fmt_cap: a reference to capture format structure
241 * @num_input_bufs: holds number of input buffers
242 * @num_output_bufs: holds number of output buffers
243 * @input_buf_size holds input buffer size
244 * @output_buf_size: holds output buffer size
245 * @output2_buf_size: holds secondary decoder output buffer size
246 * @dpb_buftype: decoded picture buffer type
247 * @dpb_fmt: decoded picture buffer raw format
248 * @opb_buftype: output picture buffer type
249 * @opb_fmt: output picture buffer raw format
250 * @reconfig: a flag raised by decoder when the stream resolution changed
251 * @reconfig_width: holds the new width
252 * @reconfig_height: holds the new height
253 * @hfi_codec: current codec for this instance in HFI space
254 * @sequence_cap: a sequence counter for capture queue
255 * @sequence_out: a sequence counter for output queue
256 * @m2m_dev: a reference to m2m device structure
257 * @m2m_ctx: a reference to m2m context structure
258 * @state: current state of the instance
259 * @done: a completion for sync HFI operation
260 * @error: an error returned during last HFI sync operation
261 * @session_error: a flag rised by HFI interface in case of session error
262 * @ops: HFI operations
263 * @priv: a private for HFI operations callbacks
264 * @session_type: the type of the session (decoder or encoder)
265 * @hprop: a union used as a holder by get property
268 struct list_head list
;
270 struct venus_core
*core
;
271 struct list_head dpbbufs
;
272 struct list_head internalbufs
;
273 struct list_head registeredbufs
;
274 struct list_head delayed_process
;
275 struct work_struct delayed_process_work
;
277 struct v4l2_ctrl_handler ctrl_handler
;
279 struct vdec_controls dec
;
280 struct venc_controls enc
;
283 unsigned int streamon_cap
, streamon_out
;
293 struct v4l2_fract timeperframe
;
294 const struct venus_format
*fmt_out
;
295 const struct venus_format
*fmt_cap
;
296 unsigned int num_input_bufs
;
297 unsigned int num_output_bufs
;
298 unsigned int input_buf_size
;
299 unsigned int output_buf_size
;
300 unsigned int output2_buf_size
;
311 struct v4l2_m2m_dev
*m2m_dev
;
312 struct v4l2_m2m_ctx
*m2m_ctx
;
314 struct completion done
;
317 const struct hfi_inst_ops
*ops
;
319 union hfi_get_property hprop
;
322 #define IS_V1(core) ((core)->res->hfi_version == HFI_VERSION_1XX)
323 #define IS_V3(core) ((core)->res->hfi_version == HFI_VERSION_3XX)
324 #define IS_V4(core) ((core)->res->hfi_version == HFI_VERSION_4XX)
326 #define ctrl_to_inst(ctrl) \
327 container_of((ctrl)->handler, struct venus_inst, ctrl_handler)
329 static inline struct venus_inst
*to_inst(struct file
*filp
)
331 return container_of(filp
->private_data
, struct venus_inst
, fh
);
334 static inline void *to_hfi_priv(struct venus_core
*core
)
339 static inline struct venus_caps
*
340 venus_caps_by_codec(struct venus_core
*core
, u32 codec
, u32 domain
)
344 for (c
= 0; c
< core
->codecs_count
; c
++) {
345 if (core
->caps
[c
].codec
== codec
&&
346 core
->caps
[c
].domain
== domain
)
347 return &core
->caps
[c
];