Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
Laurent Pinchart | cdda479 | 2010-05-02 20:57:41 +0200 | [diff] [blame] | 2 | #ifndef _UVC_QUEUE_H_ |
| 3 | #define _UVC_QUEUE_H_ |
| 4 | |
Laurent Pinchart | 284eb166 | 2018-05-21 11:28:52 +0300 | [diff] [blame] | 5 | #include <linux/list.h> |
Laurent Pinchart | cdda479 | 2010-05-02 20:57:41 +0200 | [diff] [blame] | 6 | #include <linux/poll.h> |
Laurent Pinchart | 284eb166 | 2018-05-21 11:28:52 +0300 | [diff] [blame] | 7 | #include <linux/spinlock.h> |
| 8 | |
Junghak Sung | c139990 | 2015-09-22 10:30:29 -0300 | [diff] [blame] | 9 | #include <media/videobuf2-v4l2.h> |
Laurent Pinchart | cdda479 | 2010-05-02 20:57:41 +0200 | [diff] [blame] | 10 | |
Laurent Pinchart | 284eb166 | 2018-05-21 11:28:52 +0300 | [diff] [blame] | 11 | struct file; |
| 12 | struct mutex; |
| 13 | |
Laurent Pinchart | cdda479 | 2010-05-02 20:57:41 +0200 | [diff] [blame] | 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 { |
Junghak Sung | 2d70071 | 2015-09-22 10:30:30 -0300 | [diff] [blame] | 32 | struct vb2_v4l2_buffer buf; |
Laurent Pinchart | cdda479 | 2010-05-02 20:57:41 +0200 | [diff] [blame] | 33 | struct list_head queue; |
Bhupesh Sharma | d692522 | 2013-03-28 15:11:52 +0530 | [diff] [blame] | 34 | |
Laurent Pinchart | cdda479 | 2010-05-02 20:57:41 +0200 | [diff] [blame] | 35 | enum uvc_buffer_state state; |
Bhupesh Sharma | d692522 | 2013-03-28 15:11:52 +0530 | [diff] [blame] | 36 | void *mem; |
Michael Grzeschik | e81e7f9 | 2021-06-28 17:53:10 +0200 | [diff] [blame] | 37 | struct sg_table *sgt; |
| 38 | struct scatterlist *sg; |
| 39 | unsigned int offset; |
Bhupesh Sharma | d692522 | 2013-03-28 15:11:52 +0530 | [diff] [blame] | 40 | unsigned int length; |
| 41 | unsigned int bytesused; |
Laurent Pinchart | cdda479 | 2010-05-02 20:57:41 +0200 | [diff] [blame] | 42 | }; |
| 43 | |
Bhupesh Sharma | d692522 | 2013-03-28 15:11:52 +0530 | [diff] [blame] | 44 | #define UVC_QUEUE_DISCONNECTED (1 << 0) |
| 45 | #define UVC_QUEUE_DROP_INCOMPLETE (1 << 1) |
| 46 | #define UVC_QUEUE_PAUSED (1 << 2) |
Laurent Pinchart | cdda479 | 2010-05-02 20:57:41 +0200 | [diff] [blame] | 47 | |
| 48 | struct uvc_video_queue { |
Bhupesh Sharma | d692522 | 2013-03-28 15:11:52 +0530 | [diff] [blame] | 49 | struct vb2_queue queue; |
Laurent Pinchart | cdda479 | 2010-05-02 20:57:41 +0200 | [diff] [blame] | 50 | |
Laurent Pinchart | cdda479 | 2010-05-02 20:57:41 +0200 | [diff] [blame] | 51 | unsigned int flags; |
| 52 | __u32 sequence; |
| 53 | |
Laurent Pinchart | cdda479 | 2010-05-02 20:57:41 +0200 | [diff] [blame] | 54 | unsigned int buf_used; |
Laurent Pinchart | cdda479 | 2010-05-02 20:57:41 +0200 | [diff] [blame] | 55 | |
Michael Grzeschik | e81e7f9 | 2021-06-28 17:53:10 +0200 | [diff] [blame] | 56 | bool use_sg; |
| 57 | |
Bhupesh Sharma | d692522 | 2013-03-28 15:11:52 +0530 | [diff] [blame] | 58 | spinlock_t irqlock; /* Protects flags and irqqueue */ |
Laurent Pinchart | cdda479 | 2010-05-02 20:57:41 +0200 | [diff] [blame] | 59 | struct list_head irqqueue; |
| 60 | }; |
| 61 | |
Laurent Pinchart | cdda479 | 2010-05-02 20:57:41 +0200 | [diff] [blame] | 62 | static inline int uvc_queue_streaming(struct uvc_video_queue *queue) |
| 63 | { |
Bhupesh Sharma | d692522 | 2013-03-28 15:11:52 +0530 | [diff] [blame] | 64 | return vb2_is_streaming(&queue->queue); |
Laurent Pinchart | cdda479 | 2010-05-02 20:57:41 +0200 | [diff] [blame] | 65 | } |
Laurent Pinchart | cdda479 | 2010-05-02 20:57:41 +0200 | [diff] [blame] | 66 | |
Michael Grzeschik | e81e7f9 | 2021-06-28 17:53:10 +0200 | [diff] [blame] | 67 | int uvcg_queue_init(struct uvc_video_queue *queue, struct device *dev, enum v4l2_buf_type type, |
Hans Verkuil | d8e96c4 | 2015-02-17 05:44:06 -0300 | [diff] [blame] | 68 | struct mutex *lock); |
Andrzej Pietrasiewicz | 3a83c16 | 2014-09-09 02:02:09 +0300 | [diff] [blame] | 69 | |
| 70 | void uvcg_free_buffers(struct uvc_video_queue *queue); |
| 71 | |
| 72 | int uvcg_alloc_buffers(struct uvc_video_queue *queue, |
| 73 | struct v4l2_requestbuffers *rb); |
| 74 | |
| 75 | int uvcg_query_buffer(struct uvc_video_queue *queue, struct v4l2_buffer *buf); |
| 76 | |
| 77 | int uvcg_queue_buffer(struct uvc_video_queue *queue, struct v4l2_buffer *buf); |
| 78 | |
| 79 | int uvcg_dequeue_buffer(struct uvc_video_queue *queue, |
| 80 | struct v4l2_buffer *buf, int nonblocking); |
| 81 | |
Al Viro | c23e0cb | 2017-07-03 03:02:56 -0400 | [diff] [blame] | 82 | __poll_t uvcg_queue_poll(struct uvc_video_queue *queue, |
Andrzej Pietrasiewicz | 3a83c16 | 2014-09-09 02:02:09 +0300 | [diff] [blame] | 83 | struct file *file, poll_table *wait); |
| 84 | |
| 85 | int uvcg_queue_mmap(struct uvc_video_queue *queue, struct vm_area_struct *vma); |
| 86 | |
| 87 | #ifndef CONFIG_MMU |
| 88 | unsigned long uvcg_queue_get_unmapped_area(struct uvc_video_queue *queue, |
| 89 | unsigned long pgoff); |
| 90 | #endif /* CONFIG_MMU */ |
| 91 | |
| 92 | void uvcg_queue_cancel(struct uvc_video_queue *queue, int disconnect); |
| 93 | |
| 94 | int uvcg_queue_enable(struct uvc_video_queue *queue, int enable); |
| 95 | |
| 96 | struct uvc_buffer *uvcg_queue_next_buffer(struct uvc_video_queue *queue, |
| 97 | struct uvc_buffer *buf); |
| 98 | |
| 99 | struct uvc_buffer *uvcg_queue_head(struct uvc_video_queue *queue); |
| 100 | |
Laurent Pinchart | cdda479 | 2010-05-02 20:57:41 +0200 | [diff] [blame] | 101 | #endif /* _UVC_QUEUE_H_ */ |
| 102 | |