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 "[---:----]"
26 extern const struct hva_enc nv12h264enc
;
27 extern const struct hva_enc nv21h264enc
;
30 * struct hva_frameinfo - information about hva frame
32 * @pixelformat: fourcc code for uncompressed video format
33 * @width: width of frame
34 * @height: height of frame
35 * @aligned_width: width of frame (with encoder alignment constraint)
36 * @aligned_height: height of frame (with encoder alignment constraint)
37 * @size: maximum size in bytes required for data
39 struct hva_frameinfo
{
49 * struct hva_streaminfo - information about hva stream
51 * @streamformat: fourcc code of compressed video format (H.264...)
52 * @width: width of stream
53 * @height: height of stream
54 * @profile: profile string
55 * @level: level string
57 struct hva_streaminfo
{
66 * struct hva_controls - hva controls set
68 * @time_per_frame: time per frame in seconds
69 * @bitrate_mode: bitrate mode (constant bitrate or variable bitrate)
70 * @gop_size: groupe of picture size
71 * @bitrate: bitrate (in bps)
72 * @aspect: video aspect
73 * @profile: H.264 profile
75 * @entropy_mode: H.264 entropy mode (CABAC or CVLC)
76 * @cpb_size: coded picture buffer size (in kB)
77 * @dct8x8: transform mode 8x8 enable
78 * @qpmin: minimum quantizer
79 * @qpmax: maximum quantizer
80 * @vui_sar: pixel aspect ratio enable
81 * @vui_sar_idc: pixel aspect ratio identifier
82 * @sei_fp: sei frame packing arrangement enable
83 * @sei_fp_type: sei frame packing arrangement type
86 struct v4l2_fract time_per_frame
;
87 enum v4l2_mpeg_video_bitrate_mode bitrate_mode
;
90 enum v4l2_mpeg_video_aspect aspect
;
91 enum v4l2_mpeg_video_h264_profile profile
;
92 enum v4l2_mpeg_video_h264_level level
;
93 enum v4l2_mpeg_video_h264_entropy_mode entropy_mode
;
99 enum v4l2_mpeg_video_h264_vui_sar_idc vui_sar_idc
;
101 enum v4l2_mpeg_video_h264_sei_fp_arrangement_type sei_fp_type
;
105 * struct hva_frame - hva frame buffer (output)
107 * @vbuf: video buffer information for V4L2
108 * @list: V4L2 m2m list that the frame belongs to
109 * @info: frame information (width, height, format, alignment...)
110 * @paddr: physical address (for hardware)
111 * @vaddr: virtual address (kernel can read/write)
112 * @prepared: true if vaddr/paddr are resolved
115 struct vb2_v4l2_buffer vbuf
;
116 struct list_head list
;
117 struct hva_frameinfo info
;
124 * to_hva_frame() - cast struct vb2_v4l2_buffer * to struct hva_frame *
126 #define to_hva_frame(vb) \
127 container_of(vb, struct hva_frame, vbuf)
130 * struct hva_stream - hva stream buffer (capture)
132 * @v4l2: video buffer information for V4L2
133 * @list: V4L2 m2m list that the frame belongs to
134 * @paddr: physical address (for hardware)
135 * @vaddr: virtual address (kernel can read/write)
136 * @prepared: true if vaddr/paddr are resolved
137 * @size: size of the buffer in bytes
138 * @bytesused: number of bytes occupied by data in the buffer
141 struct vb2_v4l2_buffer vbuf
;
142 struct list_head list
;
147 unsigned int bytesused
;
151 * to_hva_stream() - cast struct vb2_v4l2_buffer * to struct hva_stream *
153 #define to_hva_stream(vb) \
154 container_of(vb, struct hva_stream, vbuf)
160 * struct hva_ctx - context of hva instance
162 * @hva_dev: the device that this instance is associated with
163 * @fh: V4L2 file handle
164 * @ctrl_handler: V4L2 controls handler
165 * @ctrls: hva controls set
166 * @id: instance identifier
167 * @aborting: true if current job aborted
168 * @name: instance name (debug purpose)
169 * @run_work: encode work
170 * @lock: mutex used to lock access of this context
171 * @flags: validity of streaminfo and frameinfo fields
172 * @frame_num: frame number
173 * @stream_num: stream number
174 * @max_stream_size: maximum size in bytes required for stream data
175 * @colorspace: colorspace identifier
176 * @xfer_func: transfer function identifier
177 * @ycbcr_enc: Y'CbCr encoding identifier
178 * @quantization: quantization identifier
179 * @streaminfo: stream properties
180 * @frameinfo: frame properties
181 * @enc: current encoder
182 * @priv: private codec data for this instance, allocated
183 * by encoder @open time
184 * @hw_err: true if hardware error detected
187 struct hva_dev
*hva_dev
;
189 struct v4l2_ctrl_handler ctrl_handler
;
190 struct hva_controls ctrls
;
194 struct work_struct run_work
;
195 /* mutex protecting this data structure */
201 enum v4l2_colorspace colorspace
;
202 enum v4l2_xfer_func xfer_func
;
203 enum v4l2_ycbcr_encoding ycbcr_enc
;
204 enum v4l2_quantization quantization
;
205 struct hva_streaminfo streaminfo
;
206 struct hva_frameinfo frameinfo
;
212 #define HVA_FLAG_STREAMINFO 0x0001
213 #define HVA_FLAG_FRAMEINFO 0x0002
215 #define HVA_MAX_INSTANCES 16
216 #define HVA_MAX_ENCODERS 10
217 #define HVA_MAX_FORMATS HVA_MAX_ENCODERS
220 * struct hva_dev - abstraction for hva entity
222 * @v4l2_dev: V4L2 device
223 * @vdev: video device
224 * @pdev: platform device
226 * @lock: mutex used for critical sections & V4L2 ops
228 * @m2m_dev: memory-to-memory V4L2 device information
229 * @instances: opened instances
230 * @nb_of_instances: number of opened instances
231 * @instance_id: rolling counter identifying an instance (debug purpose)
232 * @regs: register io memory access
233 * @esram_addr: esram address
234 * @esram_size: esram size
236 * @irq_its: status interruption
237 * @irq_err: error interruption
238 * @work_queue: work queue to handle the encode jobs
239 * @protect_mutex: mutex used to lock access of hardware
240 * @interrupt: completion interrupt
241 * @ip_version: IP hardware version
242 * @encoders: registered encoders
243 * @nb_of_encoders: number of registered encoders
244 * @pixelformats: supported uncompressed video formats
245 * @nb_of_pixelformats: number of supported umcompressed video formats
246 * @streamformats: supported compressed video formats
247 * @nb_of_streamformats: number of supported compressed video formats
248 * @sfl_reg: status fifo level register value
249 * @sts_reg: status register value
250 * @lmi_err_reg: local memory interface error register value
251 * @emi_err_reg: external memory interface error register value
252 * @hec_mif_err_reg: HEC memory interface error register value
255 struct v4l2_device v4l2_dev
;
256 struct video_device
*vdev
;
257 struct platform_device
*pdev
;
259 /* mutex protecting vb2_queue structure */
261 struct v4l2_m2m_dev
*m2m_dev
;
262 struct hva_ctx
*instances
[HVA_MAX_INSTANCES
];
263 unsigned int nb_of_instances
;
264 unsigned int instance_id
;
271 struct workqueue_struct
*work_queue
;
272 /* mutex protecting hardware access */
273 struct mutex protect_mutex
;
274 struct completion interrupt
;
275 unsigned long int ip_version
;
276 const struct hva_enc
*encoders
[HVA_MAX_ENCODERS
];
278 u32 pixelformats
[HVA_MAX_FORMATS
];
279 u32 nb_of_pixelformats
;
280 u32 streamformats
[HVA_MAX_FORMATS
];
281 u32 nb_of_streamformats
;
290 * struct hva_enc - hva encoder
292 * @name: encoder name
293 * @streamformat: fourcc code for compressed video format (H.264...)
294 * @pixelformat: fourcc code for uncompressed video format
295 * @max_width: maximum width of frame for this encoder
296 * @max_height: maximum height of frame for this encoder
297 * @open: open encoder
298 * @close: close encoder
299 * @encode: encode a frame (struct hva_frame) in a stream
300 * (struct hva_stream)
309 int (*open
)(struct hva_ctx
*ctx
);
310 int (*close
)(struct hva_ctx
*ctx
);
311 int (*encode
)(struct hva_ctx
*ctx
, struct hva_frame
*frame
,
312 struct hva_stream
*stream
);