1 /* SPDX-License-Identifier: GPL-2.0 */
5 #include <linux/list.h>
6 #include <linux/poll.h>
7 #include <linux/spinlock.h>
9 #include <media/videobuf2-v4l2.h>
14 /* Maximum frame size in bytes, for sanity checking. */
15 #define UVC_MAX_FRAME_SIZE (16*1024*1024)
16 /* Maximum number of video buffers. */
17 #define UVC_MAX_VIDEO_BUFFERS 32
19 /* ------------------------------------------------------------------------
23 enum uvc_buffer_state {
24 UVC_BUF_STATE_IDLE = 0,
25 UVC_BUF_STATE_QUEUED = 1,
26 UVC_BUF_STATE_ACTIVE = 2,
27 UVC_BUF_STATE_DONE = 3,
28 UVC_BUF_STATE_ERROR = 4,
32 struct vb2_v4l2_buffer buf;
33 struct list_head queue;
35 enum uvc_buffer_state state;
38 struct scatterlist *sg;
41 unsigned int bytesused;
42 /* req_payload_size: only used with isoc */
43 unsigned int req_payload_size;
46 #define UVC_QUEUE_DISCONNECTED (1 << 0)
47 #define UVC_QUEUE_DROP_INCOMPLETE (1 << 1)
49 struct uvc_video_queue {
50 struct vb2_queue queue;
55 unsigned int buf_used;
59 spinlock_t irqlock; /* Protects flags and irqqueue */
60 struct list_head irqqueue;
63 static inline int uvc_queue_streaming(struct uvc_video_queue *queue)
65 return vb2_is_streaming(&queue->queue);
68 int uvcg_queue_init(struct uvc_video_queue *queue, struct device *dev, enum v4l2_buf_type type,
71 void uvcg_free_buffers(struct uvc_video_queue *queue);
73 int uvcg_alloc_buffers(struct uvc_video_queue *queue,
74 struct v4l2_requestbuffers *rb);
76 int uvcg_query_buffer(struct uvc_video_queue *queue, struct v4l2_buffer *buf);
78 int uvcg_queue_buffer(struct uvc_video_queue *queue, struct v4l2_buffer *buf);
80 int uvcg_dequeue_buffer(struct uvc_video_queue *queue,
81 struct v4l2_buffer *buf, int nonblocking);
83 __poll_t uvcg_queue_poll(struct uvc_video_queue *queue,
84 struct file *file, poll_table *wait);
86 int uvcg_queue_mmap(struct uvc_video_queue *queue, struct vm_area_struct *vma);
89 unsigned long uvcg_queue_get_unmapped_area(struct uvc_video_queue *queue,
91 #endif /* CONFIG_MMU */
93 void uvcg_queue_cancel(struct uvc_video_queue *queue, int disconnect);
95 int uvcg_queue_enable(struct uvc_video_queue *queue, int enable);
97 void uvcg_complete_buffer(struct uvc_video_queue *queue,
98 struct uvc_buffer *buf);
100 struct uvc_buffer *uvcg_queue_head(struct uvc_video_queue *queue);
102 #endif /* _UVC_QUEUE_H_ */