Merge tag 'xfs-4.13-merge-5' of git://git.kernel.org/pub/scm/fs/xfs/xfs-linux
[sfrench/cifs-2.6.git] / drivers / media / platform / qcom / venus / core.h
1 /*
2  * Copyright (c) 2012-2016, The Linux Foundation. All rights reserved.
3  * Copyright (C) 2017 Linaro Ltd.
4  *
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.
8  *
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.
13  *
14  */
15
16 #ifndef __VENUS_CORE_H_
17 #define __VENUS_CORE_H_
18
19 #include <linux/list.h>
20 #include <media/videobuf2-v4l2.h>
21 #include <media/v4l2-ctrls.h>
22 #include <media/v4l2-device.h>
23
24 #include "hfi.h"
25
26 #define VIDC_CLKS_NUM_MAX       4
27
28 struct freq_tbl {
29         unsigned int load;
30         unsigned long freq;
31 };
32
33 struct reg_val {
34         u32 reg;
35         u32 value;
36 };
37
38 struct venus_resources {
39         u64 dma_mask;
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;
47         u32 max_load;
48         unsigned int vmem_id;
49         u32 vmem_size;
50         u32 vmem_addr;
51         const char *fwname;
52 };
53
54 struct venus_format {
55         u32 pixfmt;
56         unsigned int num_planes;
57         u32 type;
58 };
59
60 /**
61  * struct venus_core - holds core parameters valid for all instances
62  *
63  * @base:       IO memory base address
64  * @irq:                Venus irq
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
90  */
91 struct venus_core {
92         void __iomem *base;
93         int irq;
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;
101         struct device *dev;
102         struct device *dev_dec;
103         struct device *dev_enc;
104         struct device dev_fw;
105         struct mutex lock;
106         struct list_head instances;
107         atomic_t insts_count;
108         unsigned int state;
109         struct completion done;
110         unsigned int error;
111         bool sys_error;
112         const struct hfi_core_ops *core_ops;
113         u32 enc_codecs;
114         u32 dec_codecs;
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;
121         void *priv;
122         const struct hfi_ops *ops;
123         struct delayed_work work;
124 };
125
126 struct vdec_controls {
127         u32 post_loop_deb_mode;
128         u32 profile;
129         u32 level;
130 };
131
132 struct venc_controls {
133         u16 gop_size;
134         u32 num_p_frames;
135         u32 num_b_frames;
136         u32 bitrate_mode;
137         u32 bitrate;
138         u32 bitrate_peak;
139
140         u32 h264_i_period;
141         u32 h264_entropy_mode;
142         u32 h264_i_qp;
143         u32 h264_p_qp;
144         u32 h264_b_qp;
145         u32 h264_min_qp;
146         u32 h264_max_qp;
147         u32 h264_loop_filter_mode;
148         u32 h264_loop_filter_alpha;
149         u32 h264_loop_filter_beta;
150
151         u32 vp8_min_qp;
152         u32 vp8_max_qp;
153
154         u32 multi_slice_mode;
155         u32 multi_slice_max_bytes;
156         u32 multi_slice_max_mb;
157
158         u32 header_mode;
159
160         struct {
161                 u32 mpeg4;
162                 u32 h264;
163                 u32 vpx;
164         } profile;
165         struct {
166                 u32 mpeg4;
167                 u32 h264;
168         } level;
169 };
170
171 struct venus_buffer {
172         struct vb2_v4l2_buffer vb;
173         struct list_head list;
174         dma_addr_t dma_addr;
175         u32 size;
176         struct list_head reg_list;
177         u32 flags;
178         struct list_head ref_list;
179 };
180
181 #define to_venus_buffer(ptr)    container_of(ptr, struct venus_buffer, vb)
182
183 /**
184  * struct venus_inst - holds per instance paramerters
185  *
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
245  */
246 struct venus_inst {
247         struct list_head list;
248         struct mutex lock;
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;
254
255         struct v4l2_ctrl_handler ctrl_handler;
256         union {
257                 struct vdec_controls dec;
258                 struct venc_controls enc;
259         } controls;
260         struct v4l2_fh fh;
261         unsigned int streamon_cap, streamon_out;
262         bool cmd_stop;
263         u32 width;
264         u32 height;
265         u32 out_width;
266         u32 out_height;
267         u32 colorspace;
268         u8 ycbcr_enc;
269         u8 quantization;
270         u8 xfer_func;
271         u64 fps;
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;
279         bool reconfig;
280         u32 reconfig_width;
281         u32 reconfig_height;
282         u32 sequence_cap;
283         u32 sequence_out;
284         struct v4l2_m2m_dev *m2m_dev;
285         struct v4l2_m2m_ctx *m2m_ctx;
286         unsigned int state;
287         struct completion done;
288         unsigned int error;
289         bool session_error;
290         const struct hfi_inst_ops *ops;
291         u32 session_type;
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];
309 };
310
311 #define ctrl_to_inst(ctrl)      \
312         container_of((ctrl)->handler, struct venus_inst, ctrl_handler)
313
314 static inline struct venus_inst *to_inst(struct file *filp)
315 {
316         return container_of(filp->private_data, struct venus_inst, fh);
317 }
318
319 static inline void *to_hfi_priv(struct venus_core *core)
320 {
321         return core->priv;
322 }
323
324 #endif