Loading...
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
11struct file;
12struct 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
23enum 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
31struct uvc_buffer {
32 struct vb2_v4l2_buffer buf;
33 struct list_head queue;
34
35 enum uvc_buffer_state state;
36 void *mem;
37 struct sg_table *sgt;
38 struct scatterlist *sg;
39 unsigned int offset;
40 unsigned int length;
41 unsigned int bytesused;
42};
43
44#define UVC_QUEUE_DISCONNECTED (1 << 0)
45#define UVC_QUEUE_DROP_INCOMPLETE (1 << 1)
46
47struct uvc_video_queue {
48 struct vb2_queue queue;
49
50 unsigned int flags;
51 __u32 sequence;
52
53 unsigned int buf_used;
54
55 bool use_sg;
56
57 spinlock_t irqlock; /* Protects flags and irqqueue */
58 struct list_head irqqueue;
59};
60
61static inline int uvc_queue_streaming(struct uvc_video_queue *queue)
62{
63 return vb2_is_streaming(&queue->queue);
64}
65
66int uvcg_queue_init(struct uvc_video_queue *queue, struct device *dev, enum v4l2_buf_type type,
67 struct mutex *lock);
68
69void uvcg_free_buffers(struct uvc_video_queue *queue);
70
71int uvcg_alloc_buffers(struct uvc_video_queue *queue,
72 struct v4l2_requestbuffers *rb);
73
74int uvcg_query_buffer(struct uvc_video_queue *queue, struct v4l2_buffer *buf);
75
76int uvcg_queue_buffer(struct uvc_video_queue *queue, struct v4l2_buffer *buf);
77
78int uvcg_dequeue_buffer(struct uvc_video_queue *queue,
79 struct v4l2_buffer *buf, int nonblocking);
80
81__poll_t uvcg_queue_poll(struct uvc_video_queue *queue,
82 struct file *file, poll_table *wait);
83
84int uvcg_queue_mmap(struct uvc_video_queue *queue, struct vm_area_struct *vma);
85
86#ifndef CONFIG_MMU
87unsigned long uvcg_queue_get_unmapped_area(struct uvc_video_queue *queue,
88 unsigned long pgoff);
89#endif /* CONFIG_MMU */
90
91void uvcg_queue_cancel(struct uvc_video_queue *queue, int disconnect);
92
93int uvcg_queue_enable(struct uvc_video_queue *queue, int enable);
94
95void uvcg_complete_buffer(struct uvc_video_queue *queue,
96 struct uvc_buffer *buf);
97
98struct uvc_buffer *uvcg_queue_head(struct uvc_video_queue *queue);
99
100#endif /* _UVC_QUEUE_H_ */
101
1/* SPDX-License-Identifier: GPL-2.0 */
2#ifndef _UVC_QUEUE_H_
3#define _UVC_QUEUE_H_
4
5#ifdef __KERNEL__
6
7#include <linux/kernel.h>
8#include <linux/poll.h>
9#include <linux/videodev2.h>
10#include <media/videobuf2-v4l2.h>
11
12/* Maximum frame size in bytes, for sanity checking. */
13#define UVC_MAX_FRAME_SIZE (16*1024*1024)
14/* Maximum number of video buffers. */
15#define UVC_MAX_VIDEO_BUFFERS 32
16
17/* ------------------------------------------------------------------------
18 * Structures.
19 */
20
21enum uvc_buffer_state {
22 UVC_BUF_STATE_IDLE = 0,
23 UVC_BUF_STATE_QUEUED = 1,
24 UVC_BUF_STATE_ACTIVE = 2,
25 UVC_BUF_STATE_DONE = 3,
26 UVC_BUF_STATE_ERROR = 4,
27};
28
29struct uvc_buffer {
30 struct vb2_v4l2_buffer buf;
31 struct list_head queue;
32
33 enum uvc_buffer_state state;
34 void *mem;
35 unsigned int length;
36 unsigned int bytesused;
37};
38
39#define UVC_QUEUE_DISCONNECTED (1 << 0)
40#define UVC_QUEUE_DROP_INCOMPLETE (1 << 1)
41#define UVC_QUEUE_PAUSED (1 << 2)
42
43struct uvc_video_queue {
44 struct vb2_queue queue;
45
46 unsigned int flags;
47 __u32 sequence;
48
49 unsigned int buf_used;
50
51 spinlock_t irqlock; /* Protects flags and irqqueue */
52 struct list_head irqqueue;
53};
54
55static inline int uvc_queue_streaming(struct uvc_video_queue *queue)
56{
57 return vb2_is_streaming(&queue->queue);
58}
59
60int uvcg_queue_init(struct uvc_video_queue *queue, enum v4l2_buf_type type,
61 struct mutex *lock);
62
63void uvcg_free_buffers(struct uvc_video_queue *queue);
64
65int uvcg_alloc_buffers(struct uvc_video_queue *queue,
66 struct v4l2_requestbuffers *rb);
67
68int uvcg_query_buffer(struct uvc_video_queue *queue, struct v4l2_buffer *buf);
69
70int uvcg_queue_buffer(struct uvc_video_queue *queue, struct v4l2_buffer *buf);
71
72int uvcg_dequeue_buffer(struct uvc_video_queue *queue,
73 struct v4l2_buffer *buf, int nonblocking);
74
75__poll_t uvcg_queue_poll(struct uvc_video_queue *queue,
76 struct file *file, poll_table *wait);
77
78int uvcg_queue_mmap(struct uvc_video_queue *queue, struct vm_area_struct *vma);
79
80#ifndef CONFIG_MMU
81unsigned long uvcg_queue_get_unmapped_area(struct uvc_video_queue *queue,
82 unsigned long pgoff);
83#endif /* CONFIG_MMU */
84
85void uvcg_queue_cancel(struct uvc_video_queue *queue, int disconnect);
86
87int uvcg_queue_enable(struct uvc_video_queue *queue, int enable);
88
89struct uvc_buffer *uvcg_queue_next_buffer(struct uvc_video_queue *queue,
90 struct uvc_buffer *buf);
91
92struct uvc_buffer *uvcg_queue_head(struct uvc_video_queue *queue);
93
94#endif /* __KERNEL__ */
95
96#endif /* _UVC_QUEUE_H_ */
97