hc
2024-05-13 9d77db3c730780c8ef5ccd4b66403ff5675cfe4e
kernel/include/media/videobuf2-core.h
....@@ -17,6 +17,7 @@
1717 #include <linux/poll.h>
1818 #include <linux/dma-buf.h>
1919 #include <linux/bitops.h>
20
+#include <media/media-request.h>
2021
2122 #define VB2_MAX_FRAME (64)
2223 #define VB2_MAX_PLANES (8)
....@@ -53,7 +54,8 @@
5354 * will then be passed as @buf_priv argument to other ops in this
5455 * structure. Additional gfp_flags to use when allocating the
5556 * are also passed to this operation. These flags are from the
56
- * gfp_flags field of vb2_queue.
57
+ * gfp_flags field of vb2_queue. The size argument to this function
58
+ * shall be *page aligned*.
5759 * @put: inform the allocator that the buffer will no longer be used;
5860 * usually will result in the allocator freeing the buffer (if
5961 * no other users of this buffer are present); the @buf_priv
....@@ -203,10 +205,9 @@
203205 /**
204206 * enum vb2_buffer_state - current video buffer state.
205207 * @VB2_BUF_STATE_DEQUEUED: buffer under userspace control.
208
+ * @VB2_BUF_STATE_IN_REQUEST: buffer is queued in media request.
206209 * @VB2_BUF_STATE_PREPARING: buffer is being prepared in videobuf.
207
- * @VB2_BUF_STATE_PREPARED: buffer prepared in videobuf and by the driver.
208210 * @VB2_BUF_STATE_QUEUED: buffer queued in videobuf, but not in driver.
209
- * @VB2_BUF_STATE_REQUEUEING: re-queue a buffer to the driver.
210211 * @VB2_BUF_STATE_ACTIVE: buffer queued in driver and possibly used
211212 * in a hardware operation.
212213 * @VB2_BUF_STATE_DONE: buffer returned from driver to videobuf, but
....@@ -217,10 +218,9 @@
217218 */
218219 enum vb2_buffer_state {
219220 VB2_BUF_STATE_DEQUEUED,
221
+ VB2_BUF_STATE_IN_REQUEST,
220222 VB2_BUF_STATE_PREPARING,
221
- VB2_BUF_STATE_PREPARED,
222223 VB2_BUF_STATE_QUEUED,
223
- VB2_BUF_STATE_REQUEUEING,
224224 VB2_BUF_STATE_ACTIVE,
225225 VB2_BUF_STATE_DONE,
226226 VB2_BUF_STATE_ERROR,
....@@ -238,6 +238,9 @@
238238 * @num_planes: number of planes in the buffer
239239 * on an internal driver queue.
240240 * @timestamp: frame timestamp in ns.
241
+ * @request: the request this buffer is associated with.
242
+ * @req_obj: used to bind this buffer to a request. This
243
+ * request object has a refcount.
241244 */
242245 struct vb2_buffer {
243246 struct vb2_queue *vb2_queue;
....@@ -246,10 +249,20 @@
246249 unsigned int memory;
247250 unsigned int num_planes;
248251 u64 timestamp;
252
+ struct media_request *request;
253
+ struct media_request_object req_obj;
249254
250255 /* private: internal use only
251256 *
252257 * state: current buffer state; do not change
258
+ * synced: this buffer has been synced for DMA, i.e. the
259
+ * 'prepare' memop was called. It is cleared again
260
+ * after the 'finish' memop is called.
261
+ * prepared: this buffer has been prepared, i.e. the
262
+ * buf_prepare op was called. It is cleared again
263
+ * after the 'buf_finish' op is called.
264
+ * copied_timestamp: the timestamp of this capture buffer was copied
265
+ * from an output buffer.
253266 * need_cache_sync_on_prepare: when set buffer's ->prepare() function
254267 * performs cache sync/invalidation.
255268 * need_cache_sync_on_finish: when set buffer's ->finish() function
....@@ -261,6 +274,9 @@
261274 * vb2_plane: per-plane information; do not change
262275 */
263276 enum vb2_buffer_state state;
277
+ unsigned int synced:1;
278
+ unsigned int prepared:1;
279
+ unsigned int copied_timestamp:1;
264280 unsigned int need_cache_sync_on_prepare:1;
265281 unsigned int need_cache_sync_on_finish:1;
266282
....@@ -288,11 +304,13 @@
288304 u32 cnt_mem_num_users;
289305 u32 cnt_mem_mmap;
290306
307
+ u32 cnt_buf_out_validate;
291308 u32 cnt_buf_init;
292309 u32 cnt_buf_prepare;
293310 u32 cnt_buf_finish;
294311 u32 cnt_buf_cleanup;
295312 u32 cnt_buf_queue;
313
+ u32 cnt_buf_request_complete;
296314
297315 /* This counts the number of calls to vb2_buffer_done() */
298316 u32 cnt_buf_done;
....@@ -333,6 +351,10 @@
333351 * @wait_finish: reacquire all locks released in the previous callback;
334352 * required to continue operation after sleeping while
335353 * waiting for a new buffer to arrive.
354
+ * @buf_out_validate: called when the output buffer is prepared or queued
355
+ * to a request; drivers can use this to validate
356
+ * userspace-provided information; this is required only
357
+ * for OUTPUT queues.
336358 * @buf_init: called once after allocating a buffer (in MMAP case)
337359 * or after acquiring a new USERPTR buffer; drivers may
338360 * perform additional buffer-related initialization;
....@@ -367,10 +389,10 @@
367389 * driver can return an error if hardware fails, in that
368390 * case all buffers that have been already given by
369391 * the @buf_queue callback are to be returned by the driver
370
- * by calling vb2_buffer_done() with %VB2_BUF_STATE_QUEUED
371
- * or %VB2_BUF_STATE_REQUEUEING. If you need a minimum
372
- * number of buffers before you can start streaming, then
373
- * set &vb2_queue->min_buffers_needed. If that is non-zero
392
+ * by calling vb2_buffer_done() with %VB2_BUF_STATE_QUEUED.
393
+ * If you need a minimum number of buffers before you can
394
+ * start streaming, then set
395
+ * &vb2_queue->min_buffers_needed. If that is non-zero
374396 * then @start_streaming won't be called until at least
375397 * that many buffers have been queued up by userspace.
376398 * @stop_streaming: called when 'streaming' state must be disabled; driver
....@@ -382,10 +404,15 @@
382404 * @buf_queue: passes buffer vb to the driver; driver may start
383405 * hardware operation on this buffer; driver should give
384406 * the buffer back by calling vb2_buffer_done() function;
385
- * it is allways called after calling VIDIOC_STREAMON()
407
+ * it is always called after calling VIDIOC_STREAMON()
386408 * ioctl; might be called before @start_streaming callback
387409 * if user pre-queued buffers before calling
388410 * VIDIOC_STREAMON().
411
+ * @buf_request_complete: a buffer that was never queued to the driver but is
412
+ * associated with a queued request was canceled.
413
+ * The driver will have to mark associated objects in the
414
+ * request as completed; required if requests are
415
+ * supported.
389416 */
390417 struct vb2_ops {
391418 int (*queue_setup)(struct vb2_queue *q,
....@@ -395,6 +422,7 @@
395422 void (*wait_prepare)(struct vb2_queue *q);
396423 void (*wait_finish)(struct vb2_queue *q);
397424
425
+ int (*buf_out_validate)(struct vb2_buffer *vb);
398426 int (*buf_init)(struct vb2_buffer *vb);
399427 int (*buf_prepare)(struct vb2_buffer *vb);
400428 void (*buf_finish)(struct vb2_buffer *vb);
....@@ -404,6 +432,8 @@
404432 void (*stop_streaming)(struct vb2_queue *q);
405433
406434 void (*buf_queue)(struct vb2_buffer *vb);
435
+
436
+ void (*buf_request_complete)(struct vb2_buffer *vb);
407437 };
408438
409439 /**
....@@ -412,6 +442,9 @@
412442 * @verify_planes_array: Verify that a given user space structure contains
413443 * enough planes for the buffer. This is called
414444 * for each dequeued buffer.
445
+ * @init_buffer: given a &vb2_buffer initialize the extra data after
446
+ * struct vb2_buffer.
447
+ * For V4L2 this is a &struct vb2_v4l2_buffer.
415448 * @fill_user_buffer: given a &vb2_buffer fill in the userspace structure.
416449 * For V4L2 this is a &struct v4l2_buffer.
417450 * @fill_vb2_buffer: given a userspace structure, fill in the &vb2_buffer.
....@@ -422,9 +455,9 @@
422455 */
423456 struct vb2_buf_ops {
424457 int (*verify_planes_array)(struct vb2_buffer *vb, const void *pb);
458
+ void (*init_buffer)(struct vb2_buffer *vb);
425459 void (*fill_user_buffer)(struct vb2_buffer *vb, void *pb);
426
- int (*fill_vb2_buffer)(struct vb2_buffer *vb, const void *pb,
427
- struct vb2_plane *planes);
460
+ int (*fill_vb2_buffer)(struct vb2_buffer *vb, struct vb2_plane *planes);
428461 void (*copy_timestamp)(struct vb2_buffer *vb, const void *pb);
429462 };
430463
....@@ -455,6 +488,15 @@
455488 * @quirk_poll_must_check_waiting_for_buffers: Return %EPOLLERR at poll when QBUF
456489 * has not been called. This is a vb1 idiom that has been adopted
457490 * also by vb2.
491
+ * @supports_requests: this queue supports the Request API.
492
+ * @requires_requests: this queue requires the Request API. If this is set to 1,
493
+ * then supports_requests must be set to 1 as well.
494
+ * @uses_qbuf: qbuf was used directly for this queue. Set to 1 the first
495
+ * time this is called. Set to 0 when the queue is canceled.
496
+ * If this is 1, then you cannot queue buffers from a request.
497
+ * @uses_requests: requests are used for this queue. Set to 1 the first time
498
+ * a request is queued. Set to 0 when the queue is canceled.
499
+ * If this is 1, then you cannot queue buffers directly.
458500 * @allow_cache_hints: when set user-space can pass cache management hints in
459501 * order to skip cache flush/invalidation on ->prepare() or/and
460502 * ->finish().
....@@ -472,10 +514,15 @@
472514 * @buf_ops: callbacks to deliver buffer information.
473515 * between user-space and kernel-space.
474516 * @drv_priv: driver private data.
517
+ * @subsystem_flags: Flags specific to the subsystem (V4L2/DVB/etc.). Not used
518
+ * by the vb2 core.
475519 * @buf_struct_size: size of the driver-specific buffer structure;
476520 * "0" indicates the driver doesn't want to use a custom buffer
477
- * structure type. for example, ``sizeof(struct vb2_v4l2_buffer)``
478
- * will be used for v4l2.
521
+ * structure type. In that case a subsystem-specific struct
522
+ * will be used (in the case of V4L2 that is
523
+ * ``sizeof(struct vb2_v4l2_buffer)``). The first field of the
524
+ * driver-specific buffer structure must be the subsystem-specific
525
+ * struct (vb2_v4l2_buffer in the case of V4L2).
479526 * @timestamp_flags: Timestamp flags; ``V4L2_BUF_FLAG_TIMESTAMP_*`` and
480527 * ``V4L2_BUF_FLAG_TSTAMP_SRC_*``
481528 * @gfp_flags: additional gfp flags used when allocating the buffers.
....@@ -514,17 +561,23 @@
514561 * when a buffer with the %V4L2_BUF_FLAG_LAST is dequeued.
515562 * @fileio: file io emulator internal data, used only if emulator is active
516563 * @threadio: thread io internal data, used only if thread is active
564
+ * @name: queue name, used for logging purpose. Initialized automatically
565
+ * if left empty by drivers.
517566 */
518567 struct vb2_queue {
519568 unsigned int type;
520569 unsigned int io_modes;
521570 struct device *dev;
522571 unsigned long dma_attrs;
523
- unsigned bidirectional:1;
524
- unsigned fileio_read_once:1;
525
- unsigned fileio_write_immediately:1;
526
- unsigned allow_zero_bytesused:1;
527
- unsigned quirk_poll_must_check_waiting_for_buffers:1;
572
+ unsigned int bidirectional:1;
573
+ unsigned int fileio_read_once:1;
574
+ unsigned int fileio_write_immediately:1;
575
+ unsigned int allow_zero_bytesused:1;
576
+ unsigned int quirk_poll_must_check_waiting_for_buffers:1;
577
+ unsigned int supports_requests:1;
578
+ unsigned int requires_requests:1;
579
+ unsigned int uses_qbuf:1;
580
+ unsigned int uses_requests:1;
528581 unsigned int allow_cache_hints:1;
529582
530583 struct mutex *lock;
....@@ -535,6 +588,7 @@
535588 const struct vb2_buf_ops *buf_ops;
536589
537590 void *drv_priv;
591
+ u32 subsystem_flags;
538592 unsigned int buf_struct_size;
539593 u32 timestamp_flags;
540594 gfp_t gfp_flags;
....@@ -569,6 +623,8 @@
569623
570624 struct vb2_fileio_data *fileio;
571625 struct vb2_threadio_data *threadio;
626
+
627
+ char name[32];
572628
573629 #ifdef CONFIG_VIDEO_ADV_DEBUG
574630 /*
....@@ -626,9 +682,7 @@
626682 * @state: state of the buffer, as defined by &enum vb2_buffer_state.
627683 * Either %VB2_BUF_STATE_DONE if the operation finished
628684 * successfully, %VB2_BUF_STATE_ERROR if the operation finished
629
- * with an error or any of %VB2_BUF_STATE_QUEUED or
630
- * %VB2_BUF_STATE_REQUEUEING if the driver wants to
631
- * requeue buffers (see below).
685
+ * with an error or %VB2_BUF_STATE_QUEUED.
632686 *
633687 * This function should be called by the driver after a hardware operation on
634688 * a buffer is finished and the buffer may be returned to userspace. The driver
....@@ -639,12 +693,7 @@
639693 * While streaming a buffer can only be returned in state DONE or ERROR.
640694 * The &vb2_ops->start_streaming op can also return them in case the DMA engine
641695 * cannot be started for some reason. In that case the buffers should be
642
- * returned with state QUEUED or REQUEUEING to put them back into the queue.
643
- *
644
- * %VB2_BUF_STATE_REQUEUEING is like %VB2_BUF_STATE_QUEUED, but it also calls
645
- * &vb2_ops->buf_queue to queue buffers back to the driver. Note that calling
646
- * vb2_buffer_done(..., VB2_BUF_STATE_REQUEUEING) from interrupt context will
647
- * result in &vb2_ops->buf_queue being called in interrupt context as well.
696
+ * returned with state QUEUED to put them back into the queue.
648697 */
649698 void vb2_buffer_done(struct vb2_buffer *vb, enum vb2_buffer_state state);
650699
....@@ -719,7 +768,7 @@
719768 * Return: returns zero on success; an error code otherwise.
720769 */
721770 int vb2_core_reqbufs(struct vb2_queue *q, enum vb2_memory memory,
722
- unsigned int *count);
771
+ unsigned int *count);
723772
724773 /**
725774 * vb2_core_create_bufs() - Allocate buffers and any required auxiliary structs
....@@ -742,7 +791,8 @@
742791 * Return: returns zero on success; an error code otherwise.
743792 */
744793 int vb2_core_create_bufs(struct vb2_queue *q, enum vb2_memory memory,
745
- unsigned int *count, unsigned int requested_planes,
794
+ unsigned int *count,
795
+ unsigned int requested_planes,
746796 const unsigned int requested_sizes[]);
747797
748798 /**
....@@ -774,12 +824,17 @@
774824 * @index: id number of the buffer
775825 * @pb: buffer structure passed from userspace to
776826 * v4l2_ioctl_ops->vidioc_qbuf handler in driver
827
+ * @req: pointer to &struct media_request, may be NULL.
777828 *
778829 * Videobuf2 core helper to implement VIDIOC_QBUF() operation. It is called
779830 * internally by VB2 by an API-specific handler, like ``videobuf2-v4l2.h``.
780831 *
781832 * This function:
782833 *
834
+ * #) If @req is non-NULL, then the buffer will be bound to this
835
+ * media request and it returns. The buffer will be prepared and
836
+ * queued to the driver (i.e. the next two steps) when the request
837
+ * itself is queued.
783838 * #) if necessary, calls &vb2_ops->buf_prepare callback in the driver
784839 * (if provided), in which driver-specific buffer initialization can
785840 * be performed;
....@@ -788,7 +843,8 @@
788843 *
789844 * Return: returns zero on success; an error code otherwise.
790845 */
791
-int vb2_core_qbuf(struct vb2_queue *q, unsigned int index, void *pb);
846
+int vb2_core_qbuf(struct vb2_queue *q, unsigned int index, void *pb,
847
+ struct media_request *req);
792848
793849 /**
794850 * vb2_core_dqbuf() - Dequeue a buffer to the userspace
....@@ -1121,6 +1177,22 @@
11211177 return 0;
11221178 }
11231179
1180
+#if defined(CONFIG_ARCH_ROCKCHIP) && IS_ENABLED(CONFIG_USB_F_UVC)
1181
+/**
1182
+ * vb2_plane_data_offset() - return plane data_offset in bytes.
1183
+ * @vb: pointer to &struct vb2_buffer to which the plane in
1184
+ * question belongs to.
1185
+ * @plane_no: plane number for which size should be returned.
1186
+ */
1187
+static inline unsigned long
1188
+vb2_plane_data_offset(struct vb2_buffer *vb, unsigned int plane_no)
1189
+{
1190
+ if (plane_no < vb->num_planes)
1191
+ return vb->planes[plane_no].data_offset;
1192
+ return 0;
1193
+}
1194
+#endif
1195
+
11241196 /**
11251197 * vb2_start_streaming_called() - return streaming status of driver.
11261198 * @q: pointer to &struct vb2_queue with videobuf2 queue.
....@@ -1137,6 +1209,24 @@
11371209 static inline void vb2_clear_last_buffer_dequeued(struct vb2_queue *q)
11381210 {
11391211 q->last_buffer_dequeued = false;
1212
+}
1213
+
1214
+/**
1215
+ * vb2_get_buffer() - get a buffer from a queue
1216
+ * @q: pointer to &struct vb2_queue with videobuf2 queue.
1217
+ * @index: buffer index
1218
+ *
1219
+ * This function obtains a buffer from a queue, by its index.
1220
+ * Keep in mind that there is no refcounting involved in this
1221
+ * operation, so the buffer lifetime should be taken into
1222
+ * consideration.
1223
+ */
1224
+static inline struct vb2_buffer *vb2_get_buffer(struct vb2_queue *q,
1225
+ unsigned int index)
1226
+{
1227
+ if (index < q->num_buffers)
1228
+ return q->bufs[index];
1229
+ return NULL;
11401230 }
11411231
11421232 /*
....@@ -1165,4 +1255,19 @@
11651255 */
11661256 int vb2_verify_memory_type(struct vb2_queue *q,
11671257 enum vb2_memory memory, unsigned int type);
1258
+
1259
+/**
1260
+ * vb2_request_object_is_buffer() - return true if the object is a buffer
1261
+ *
1262
+ * @obj: the request object.
1263
+ */
1264
+bool vb2_request_object_is_buffer(struct media_request_object *obj);
1265
+
1266
+/**
1267
+ * vb2_request_buffer_cnt() - return the number of buffers in the request
1268
+ *
1269
+ * @req: the request.
1270
+ */
1271
+unsigned int vb2_request_buffer_cnt(struct media_request *req);
1272
+
11681273 #endif /* _MEDIA_VIDEOBUF2_CORE_H */