2 * Copyright (C) STMicroelectronics SA 2015
3 * Authors: Yannick Fertre <yannick.fertre@st.com>
4 * Hugues Fruchet <hugues.fruchet@st.com>
5 * License terms: GNU General Public License (GPL), version 2
11 #include <media/v4l2-ctrls.h>
12 #include <media/v4l2-device.h>
13 #include <media/videobuf2-v4l2.h>
14 #include <media/v4l2-mem2mem.h>
16 #define fh_to_ctx(f) (container_of(f, struct hva_ctx, fh))
18 #define hva_to_dev(h) (h->dev)
20 #define ctx_to_dev(c) (c->hva_dev->dev)
22 #define ctx_to_hdev(c) (c->hva_dev)
24 #define HVA_PREFIX "[---:----]"
27 * struct hva_frameinfo - information about hva frame
29 * @pixelformat: fourcc code for uncompressed video format
30 * @width: width of frame
31 * @height: height of frame
32 * @aligned_width: width of frame (with encoder alignment constraint)
33 * @aligned_height: height of frame (with encoder alignment constraint)
34 * @size: maximum size in bytes required for data
36 struct hva_frameinfo {
46 * struct hva_streaminfo - information about hva stream
48 * @streamformat: fourcc code of compressed video format (H.264...)
49 * @width: width of stream
50 * @height: height of stream
51 * @profile: profile string
52 * @level: level string
54 struct hva_streaminfo {
63 * struct hva_controls - hva controls set
65 * @time_per_frame: time per frame in seconds
66 * @bitrate_mode: bitrate mode (constant bitrate or variable bitrate)
67 * @gop_size: groupe of picture size
68 * @bitrate: bitrate (in bps)
69 * @aspect: video aspect
72 struct v4l2_fract time_per_frame;
73 enum v4l2_mpeg_video_bitrate_mode bitrate_mode;
76 enum v4l2_mpeg_video_aspect aspect;
80 * struct hva_frame - hva frame buffer (output)
82 * @vbuf: video buffer information for V4L2
83 * @list: V4L2 m2m list that the frame belongs to
84 * @info: frame information (width, height, format, alignment...)
85 * @paddr: physical address (for hardware)
86 * @vaddr: virtual address (kernel can read/write)
87 * @prepared: true if vaddr/paddr are resolved
90 struct vb2_v4l2_buffer vbuf;
91 struct list_head list;
92 struct hva_frameinfo info;
99 * to_hva_frame() - cast struct vb2_v4l2_buffer * to struct hva_frame *
101 #define to_hva_frame(vb) \
102 container_of(vb, struct hva_frame, vbuf)
105 * struct hva_stream - hva stream buffer (capture)
107 * @v4l2: video buffer information for V4L2
108 * @list: V4L2 m2m list that the frame belongs to
109 * @paddr: physical address (for hardware)
110 * @vaddr: virtual address (kernel can read/write)
111 * @prepared: true if vaddr/paddr are resolved
112 * @size: size of the buffer in bytes
113 * @bytesused: number of bytes occupied by data in the buffer
116 struct vb2_v4l2_buffer vbuf;
117 struct list_head list;
122 unsigned int bytesused;
126 * to_hva_stream() - cast struct vb2_v4l2_buffer * to struct hva_stream *
128 #define to_hva_stream(vb) \
129 container_of(vb, struct hva_stream, vbuf)
135 * struct hva_ctx - context of hva instance
137 * @hva_dev: the device that this instance is associated with
138 * @fh: V4L2 file handle
139 * @ctrl_handler: V4L2 controls handler
140 * @ctrls: hva controls set
141 * @id: instance identifier
142 * @aborting: true if current job aborted
143 * @name: instance name (debug purpose)
144 * @run_work: encode work
145 * @lock: mutex used to lock access of this context
146 * @flags: validity of streaminfo and frameinfo fields
147 * @frame_num: frame number
148 * @stream_num: stream number
149 * @max_stream_size: maximum size in bytes required for stream data
150 * @colorspace: colorspace identifier
151 * @xfer_func: transfer function identifier
152 * @ycbcr_enc: Y'CbCr encoding identifier
153 * @quantization: quantization identifier
154 * @streaminfo: stream properties
155 * @frameinfo: frame properties
156 * @enc: current encoder
157 * @priv: private codec data for this instance, allocated
158 * by encoder @open time
159 * @hw_err: true if hardware error detected
162 struct hva_dev *hva_dev;
164 struct v4l2_ctrl_handler ctrl_handler;
165 struct hva_controls ctrls;
169 struct work_struct run_work;
170 /* mutex protecting this data structure */
176 enum v4l2_colorspace colorspace;
177 enum v4l2_xfer_func xfer_func;
178 enum v4l2_ycbcr_encoding ycbcr_enc;
179 enum v4l2_quantization quantization;
180 struct hva_streaminfo streaminfo;
181 struct hva_frameinfo frameinfo;
187 #define HVA_FLAG_STREAMINFO 0x0001
188 #define HVA_FLAG_FRAMEINFO 0x0002
190 #define HVA_MAX_INSTANCES 16
191 #define HVA_MAX_ENCODERS 10
192 #define HVA_MAX_FORMATS HVA_MAX_ENCODERS
195 * struct hva_dev - abstraction for hva entity
197 * @v4l2_dev: V4L2 device
198 * @vdev: video device
199 * @pdev: platform device
201 * @lock: mutex used for critical sections & V4L2 ops
203 * @m2m_dev: memory-to-memory V4L2 device information
204 * @instances: opened instances
205 * @nb_of_instances: number of opened instances
206 * @instance_id: rolling counter identifying an instance (debug purpose)
207 * @regs: register io memory access
208 * @esram_addr: esram address
209 * @esram_size: esram size
211 * @irq_its: status interruption
212 * @irq_err: error interruption
213 * @work_queue: work queue to handle the encode jobs
214 * @protect_mutex: mutex used to lock access of hardware
215 * @interrupt: completion interrupt
216 * @ip_version: IP hardware version
217 * @encoders: registered encoders
218 * @nb_of_encoders: number of registered encoders
219 * @pixelformats: supported uncompressed video formats
220 * @nb_of_pixelformats: number of supported umcompressed video formats
221 * @streamformats: supported compressed video formats
222 * @nb_of_streamformats: number of supported compressed video formats
223 * @sfl_reg: status fifo level register value
224 * @sts_reg: status register value
225 * @lmi_err_reg: local memory interface error register value
226 * @emi_err_reg: external memory interface error register value
227 * @hec_mif_err_reg: HEC memory interface error register value
230 struct v4l2_device v4l2_dev;
231 struct video_device *vdev;
232 struct platform_device *pdev;
234 /* mutex protecting vb2_queue structure */
236 struct v4l2_m2m_dev *m2m_dev;
237 struct hva_ctx *instances[HVA_MAX_INSTANCES];
238 unsigned int nb_of_instances;
239 unsigned int instance_id;
246 struct workqueue_struct *work_queue;
247 /* mutex protecting hardware access */
248 struct mutex protect_mutex;
249 struct completion interrupt;
250 unsigned long int ip_version;
251 const struct hva_enc *encoders[HVA_MAX_ENCODERS];
253 u32 pixelformats[HVA_MAX_FORMATS];
254 u32 nb_of_pixelformats;
255 u32 streamformats[HVA_MAX_FORMATS];
256 u32 nb_of_streamformats;
265 * struct hva_enc - hva encoder
267 * @name: encoder name
268 * @streamformat: fourcc code for compressed video format (H.264...)
269 * @pixelformat: fourcc code for uncompressed video format
270 * @max_width: maximum width of frame for this encoder
271 * @max_height: maximum height of frame for this encoder
272 * @open: open encoder
273 * @close: close encoder
274 * @encode: encode a frame (struct hva_frame) in a stream
275 * (struct hva_stream)
284 int (*open)(struct hva_ctx *ctx);
285 int (*close)(struct hva_ctx *ctx);
286 int (*encode)(struct hva_ctx *ctx, struct hva_frame *frame,
287 struct hva_stream *stream);