1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _UVC_QUEUE_H_
3 #define _UVC_QUEUE_H_
4
5 #include <linux/list.h>
6 #include <linux/poll.h>
7 #include <linux/spinlock.h>
8
9 #include <media/videobuf2-v4l2.h>
10
11 struct file;
12 struct mutex;
13
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
18
19 /* ------------------------------------------------------------------------
20 * Structures.
21 */
22
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,
29 };
30
31 struct uvc_buffer {
32 struct vb2_v4l2_buffer buf;
33 struct list_head queue;
34
35 enum uvc_buffer_state state;
36 void *mem;
37 unsigned int length;
38 unsigned int bytesused;
39 };
40
41 #define UVC_QUEUE_DISCONNECTED (1 << 0)
42 #define UVC_QUEUE_DROP_INCOMPLETE (1 << 1)
43
44 struct uvc_video_queue {
45 struct vb2_queue queue;
46
47 unsigned int flags;
48 __u32 sequence;
49
50 unsigned int buf_used;
51
52 spinlock_t irqlock; /* Protects flags and irqqueue */
53 struct list_head irqqueue;
54 };
55
uvc_queue_streaming(struct uvc_video_queue * queue)56 static inline int uvc_queue_streaming(struct uvc_video_queue *queue)
57 {
58 return vb2_is_streaming(&queue->queue);
59 }
60
61 int uvcg_queue_init(struct uvc_video_queue *queue, enum v4l2_buf_type type,
62 struct mutex *lock);
63
64 void uvcg_free_buffers(struct uvc_video_queue *queue);
65
66 int uvcg_alloc_buffers(struct uvc_video_queue *queue,
67 struct v4l2_requestbuffers *rb);
68
69 int uvcg_query_buffer(struct uvc_video_queue *queue, struct v4l2_buffer *buf);
70
71 int uvcg_queue_buffer(struct uvc_video_queue *queue, struct v4l2_buffer *buf);
72
73 int uvcg_dequeue_buffer(struct uvc_video_queue *queue,
74 struct v4l2_buffer *buf, int nonblocking);
75
76 __poll_t uvcg_queue_poll(struct uvc_video_queue *queue,
77 struct file *file, poll_table *wait);
78
79 int uvcg_queue_mmap(struct uvc_video_queue *queue, struct vm_area_struct *vma);
80
81 #ifndef CONFIG_MMU
82 unsigned long uvcg_queue_get_unmapped_area(struct uvc_video_queue *queue,
83 unsigned long pgoff);
84 #endif /* CONFIG_MMU */
85
86 void uvcg_queue_cancel(struct uvc_video_queue *queue, int disconnect);
87
88 int uvcg_queue_enable(struct uvc_video_queue *queue, int enable);
89
90 struct uvc_buffer *uvcg_queue_next_buffer(struct uvc_video_queue *queue,
91 struct uvc_buffer *buf);
92
93 struct uvc_buffer *uvcg_queue_head(struct uvc_video_queue *queue);
94
95 #endif /* _UVC_QUEUE_H_ */
96
97