Merge remote-tracking branch 'regulator/fix/core' into regulator-linus
[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 mutex lock;
105         struct list_head instances;
106         atomic_t insts_count;
107         unsigned int state;
108         struct completion done;
109         unsigned int error;
110         bool sys_error;
111         const struct hfi_core_ops *core_ops;
112         u32 enc_codecs;
113         u32 dec_codecs;
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;
120         void *priv;
121         const struct hfi_ops *ops;
122         struct delayed_work work;
123 };
124
125 struct vdec_controls {
126         u32 post_loop_deb_mode;
127         u32 profile;
128         u32 level;
129 };
130
131 struct venc_controls {
132         u16 gop_size;
133         u32 num_p_frames;
134         u32 num_b_frames;
135         u32 bitrate_mode;
136         u32 bitrate;
137         u32 bitrate_peak;
138
139         u32 h264_i_period;
140         u32 h264_entropy_mode;
141         u32 h264_i_qp;
142         u32 h264_p_qp;
143         u32 h264_b_qp;
144         u32 h264_min_qp;
145         u32 h264_max_qp;
146         u32 h264_loop_filter_mode;
147         u32 h264_loop_filter_alpha;
148         u32 h264_loop_filter_beta;
149
150         u32 vp8_min_qp;
151         u32 vp8_max_qp;
152
153         u32 multi_slice_mode;
154         u32 multi_slice_max_bytes;
155         u32 multi_slice_max_mb;
156
157         u32 header_mode;
158
159         struct {
160                 u32 mpeg4;
161                 u32 h264;
162                 u32 vpx;
163         } profile;
164         struct {
165                 u32 mpeg4;
166                 u32 h264;
167         } level;
168 };
169
170 struct venus_buffer {
171         struct vb2_v4l2_buffer vb;
172         struct list_head list;
173         dma_addr_t dma_addr;
174         u32 size;
175         struct list_head reg_list;
176         u32 flags;
177         struct list_head ref_list;
178 };
179
180 #define to_venus_buffer(ptr)    container_of(ptr, struct venus_buffer, vb)
181
182 /**
183  * struct venus_inst - holds per instance paramerters
184  *
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  * @cmd_stop:   a flag to signal encoder/decoder commands
198  * @width:      current capture width
199  * @height:     current capture height
200  * @out_width:  current output width
201  * @out_height: current output height
202  * @colorspace: current color space
203  * @quantization:       current quantization
204  * @xfer_func:  current xfer function
205  * @fps:                holds current FPS
206  * @timeperframe:       holds current time per frame structure
207  * @fmt_out:    a reference to output format structure
208  * @fmt_cap:    a reference to capture format structure
209  * @num_input_bufs:     holds number of input buffers
210  * @num_output_bufs:    holds number of output buffers
211  * @input_buf_size      holds input buffer size
212  * @output_buf_size:    holds output buffer size
213  * @reconfig:   a flag raised by decoder when the stream resolution changed
214  * @reconfig_width:     holds the new width
215  * @reconfig_height:    holds the new height
216  * @sequence_cap:       a sequence counter for capture queue
217  * @sequence_out:       a sequence counter for output queue
218  * @m2m_dev:    a reference to m2m device structure
219  * @m2m_ctx:    a reference to m2m context structure
220  * @state:      current state of the instance
221  * @done:       a completion for sync HFI operation
222  * @error:      an error returned during last HFI sync operation
223  * @session_error:      a flag rised by HFI interface in case of session error
224  * @ops:                HFI operations
225  * @priv:       a private for HFI operations callbacks
226  * @session_type:       the type of the session (decoder or encoder)
227  * @hprop:      a union used as a holder by get property
228  * @cap_width:  width capability
229  * @cap_height: height capability
230  * @cap_mbs_per_frame:  macroblocks per frame capability
231  * @cap_mbs_per_sec:    macroblocks per second capability
232  * @cap_framerate:      framerate capability
233  * @cap_scale_x:                horizontal scaling capability
234  * @cap_scale_y:                vertical scaling capability
235  * @cap_bitrate:                bitrate capability
236  * @cap_hier_p:         hier capability
237  * @cap_ltr_count:      LTR count capability
238  * @cap_secure_output2_threshold: secure OUTPUT2 threshold capability
239  * @cap_bufs_mode_static:       buffers allocation mode capability
240  * @cap_bufs_mode_dynamic:      buffers allocation mode capability
241  * @pl_count:   count of supported profiles/levels
242  * @pl:         supported profiles/levels
243  * @bufreq:     holds buffer requirements
244  */
245 struct venus_inst {
246         struct list_head list;
247         struct mutex lock;
248         struct venus_core *core;
249         struct list_head internalbufs;
250         struct list_head registeredbufs;
251         struct list_head delayed_process;
252         struct work_struct delayed_process_work;
253
254         struct v4l2_ctrl_handler ctrl_handler;
255         union {
256                 struct vdec_controls dec;
257                 struct venc_controls enc;
258         } controls;
259         struct v4l2_fh fh;
260         unsigned int streamon_cap, streamon_out;
261         bool cmd_stop;
262         u32 width;
263         u32 height;
264         u32 out_width;
265         u32 out_height;
266         u32 colorspace;
267         u8 ycbcr_enc;
268         u8 quantization;
269         u8 xfer_func;
270         u64 fps;
271         struct v4l2_fract timeperframe;
272         const struct venus_format *fmt_out;
273         const struct venus_format *fmt_cap;
274         unsigned int num_input_bufs;
275         unsigned int num_output_bufs;
276         unsigned int input_buf_size;
277         unsigned int output_buf_size;
278         bool reconfig;
279         u32 reconfig_width;
280         u32 reconfig_height;
281         u32 sequence_cap;
282         u32 sequence_out;
283         struct v4l2_m2m_dev *m2m_dev;
284         struct v4l2_m2m_ctx *m2m_ctx;
285         unsigned int state;
286         struct completion done;
287         unsigned int error;
288         bool session_error;
289         const struct hfi_inst_ops *ops;
290         u32 session_type;
291         union hfi_get_property hprop;
292         struct hfi_capability cap_width;
293         struct hfi_capability cap_height;
294         struct hfi_capability cap_mbs_per_frame;
295         struct hfi_capability cap_mbs_per_sec;
296         struct hfi_capability cap_framerate;
297         struct hfi_capability cap_scale_x;
298         struct hfi_capability cap_scale_y;
299         struct hfi_capability cap_bitrate;
300         struct hfi_capability cap_hier_p;
301         struct hfi_capability cap_ltr_count;
302         struct hfi_capability cap_secure_output2_threshold;
303         bool cap_bufs_mode_static;
304         bool cap_bufs_mode_dynamic;
305         unsigned int pl_count;
306         struct hfi_profile_level pl[HFI_MAX_PROFILE_COUNT];
307         struct hfi_buffer_requirements bufreq[HFI_BUFFER_TYPE_MAX];
308 };
309
310 #define ctrl_to_inst(ctrl)      \
311         container_of((ctrl)->handler, struct venus_inst, ctrl_handler)
312
313 static inline struct venus_inst *to_inst(struct file *filp)
314 {
315         return container_of(filp->private_data, struct venus_inst, fh);
316 }
317
318 static inline void *to_hfi_priv(struct venus_core *core)
319 {
320         return core->priv;
321 }
322
323 #endif