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