uvc_queue.h 2.4 KB

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