blob: 05360a0767f61f8f4e20010e4a70a8a5cee7928b [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
Laurent Pinchartcdda4792010-05-02 20:57:41 +02002#ifndef _UVC_QUEUE_H_
3#define _UVC_QUEUE_H_
4
Laurent Pinchart284eb1662018-05-21 11:28:52 +03005#include <linux/list.h>
Laurent Pinchartcdda4792010-05-02 20:57:41 +02006#include <linux/poll.h>
Laurent Pinchart284eb1662018-05-21 11:28:52 +03007#include <linux/spinlock.h>
8
Junghak Sungc1399902015-09-22 10:30:29 -03009#include <media/videobuf2-v4l2.h>
Laurent Pinchartcdda4792010-05-02 20:57:41 +020010
Laurent Pinchart284eb1662018-05-21 11:28:52 +030011struct file;
12struct mutex;
13
Laurent Pinchartcdda4792010-05-02 20:57:41 +020014/* 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 {
Junghak Sung2d700712015-09-22 10:30:30 -030032 struct vb2_v4l2_buffer buf;
Laurent Pinchartcdda4792010-05-02 20:57:41 +020033 struct list_head queue;
Bhupesh Sharmad6925222013-03-28 15:11:52 +053034
Laurent Pinchartcdda4792010-05-02 20:57:41 +020035 enum uvc_buffer_state state;
Bhupesh Sharmad6925222013-03-28 15:11:52 +053036 void *mem;
Michael Grzeschike81e7f92021-06-28 17:53:10 +020037 struct sg_table *sgt;
38 struct scatterlist *sg;
39 unsigned int offset;
Bhupesh Sharmad6925222013-03-28 15:11:52 +053040 unsigned int length;
41 unsigned int bytesused;
Laurent Pinchartcdda4792010-05-02 20:57:41 +020042};
43
Bhupesh Sharmad6925222013-03-28 15:11:52 +053044#define UVC_QUEUE_DISCONNECTED (1 << 0)
45#define UVC_QUEUE_DROP_INCOMPLETE (1 << 1)
46#define UVC_QUEUE_PAUSED (1 << 2)
Laurent Pinchartcdda4792010-05-02 20:57:41 +020047
48struct uvc_video_queue {
Bhupesh Sharmad6925222013-03-28 15:11:52 +053049 struct vb2_queue queue;
Laurent Pinchartcdda4792010-05-02 20:57:41 +020050
Laurent Pinchartcdda4792010-05-02 20:57:41 +020051 unsigned int flags;
52 __u32 sequence;
53
Laurent Pinchartcdda4792010-05-02 20:57:41 +020054 unsigned int buf_used;
Laurent Pinchartcdda4792010-05-02 20:57:41 +020055
Michael Grzeschike81e7f92021-06-28 17:53:10 +020056 bool use_sg;
57
Bhupesh Sharmad6925222013-03-28 15:11:52 +053058 spinlock_t irqlock; /* Protects flags and irqqueue */
Laurent Pinchartcdda4792010-05-02 20:57:41 +020059 struct list_head irqqueue;
60};
61
Laurent Pinchartcdda4792010-05-02 20:57:41 +020062static inline int uvc_queue_streaming(struct uvc_video_queue *queue)
63{
Bhupesh Sharmad6925222013-03-28 15:11:52 +053064 return vb2_is_streaming(&queue->queue);
Laurent Pinchartcdda4792010-05-02 20:57:41 +020065}
Laurent Pinchartcdda4792010-05-02 20:57:41 +020066
Michael Grzeschike81e7f92021-06-28 17:53:10 +020067int uvcg_queue_init(struct uvc_video_queue *queue, struct device *dev, enum v4l2_buf_type type,
Hans Verkuild8e96c42015-02-17 05:44:06 -030068 struct mutex *lock);
Andrzej Pietrasiewicz3a83c162014-09-09 02:02:09 +030069
70void uvcg_free_buffers(struct uvc_video_queue *queue);
71
72int uvcg_alloc_buffers(struct uvc_video_queue *queue,
73 struct v4l2_requestbuffers *rb);
74
75int uvcg_query_buffer(struct uvc_video_queue *queue, struct v4l2_buffer *buf);
76
77int uvcg_queue_buffer(struct uvc_video_queue *queue, struct v4l2_buffer *buf);
78
79int uvcg_dequeue_buffer(struct uvc_video_queue *queue,
80 struct v4l2_buffer *buf, int nonblocking);
81
Al Viroc23e0cb2017-07-03 03:02:56 -040082__poll_t uvcg_queue_poll(struct uvc_video_queue *queue,
Andrzej Pietrasiewicz3a83c162014-09-09 02:02:09 +030083 struct file *file, poll_table *wait);
84
85int uvcg_queue_mmap(struct uvc_video_queue *queue, struct vm_area_struct *vma);
86
87#ifndef CONFIG_MMU
88unsigned long uvcg_queue_get_unmapped_area(struct uvc_video_queue *queue,
89 unsigned long pgoff);
90#endif /* CONFIG_MMU */
91
92void uvcg_queue_cancel(struct uvc_video_queue *queue, int disconnect);
93
94int uvcg_queue_enable(struct uvc_video_queue *queue, int enable);
95
96struct uvc_buffer *uvcg_queue_next_buffer(struct uvc_video_queue *queue,
97 struct uvc_buffer *buf);
98
99struct uvc_buffer *uvcg_queue_head(struct uvc_video_queue *queue);
100
Laurent Pinchartcdda4792010-05-02 20:57:41 +0200101#endif /* _UVC_QUEUE_H_ */
102