mirror of
				https://github.com/torvalds/linux.git
				synced 2025-11-04 02:30:34 +02:00 
			
		
		
		
	This patch adds support for scatter gather transfers. If the underlying gadgets sg_supported == true, then the videeobuf2-dma-sg is used and the encode routine maps all scatter entries to separate scatterlists for the usb gadget. When streaming 1080p with request size of 1024 times 3 bytes top shows a difference of about 6.4% CPU load applying this patch: PID USER PR NI VIRT RES %CPU %MEM TIME+ S COMMAND 64 root 0 -20 0.0m 0.0m 7.7 0.0 0:01.25 I [kworker/u5:0-uvcvideo] 83 root 0 -20 0.0m 0.0m 4.5 0.0 0:03.71 I [kworker/u5:3-uvcvideo] 307 root -51 0 0.0m 0.0m 3.8 0.0 0:01.05 S [irq/51-dwc3] vs. 64 root 0 -20 0.0m 0.0m 5.8 0.0 0:01.79 I [kworker/u5:0-uvcvideo] 306 root -51 0 0.0m 0.0m 3.2 0.0 0:01.97 S [irq/51-dwc3] 82 root 0 -20 0.0m 0.0m 0.6 0.0 0:01.86 I [kworker/u5:1-uvcvideo] Signed-off-by: Michael Grzeschik <m.grzeschik@pengutronix.de> Link: https://lore.kernel.org/r/20210628155311.16762-5-m.grzeschik@pengutronix.de Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
		
			
				
	
	
		
			102 lines
		
	
	
	
		
			2.5 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
			
		
		
	
	
			102 lines
		
	
	
	
		
			2.5 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
/* SPDX-License-Identifier: GPL-2.0 */
 | 
						|
#ifndef _UVC_QUEUE_H_
 | 
						|
#define _UVC_QUEUE_H_
 | 
						|
 | 
						|
#include <linux/list.h>
 | 
						|
#include <linux/poll.h>
 | 
						|
#include <linux/spinlock.h>
 | 
						|
 | 
						|
#include <media/videobuf2-v4l2.h>
 | 
						|
 | 
						|
struct file;
 | 
						|
struct mutex;
 | 
						|
 | 
						|
/* Maximum frame size in bytes, for sanity checking. */
 | 
						|
#define UVC_MAX_FRAME_SIZE	(16*1024*1024)
 | 
						|
/* Maximum number of video buffers. */
 | 
						|
#define UVC_MAX_VIDEO_BUFFERS	32
 | 
						|
 | 
						|
/* ------------------------------------------------------------------------
 | 
						|
 * Structures.
 | 
						|
 */
 | 
						|
 | 
						|
enum uvc_buffer_state {
 | 
						|
	UVC_BUF_STATE_IDLE	= 0,
 | 
						|
	UVC_BUF_STATE_QUEUED	= 1,
 | 
						|
	UVC_BUF_STATE_ACTIVE	= 2,
 | 
						|
	UVC_BUF_STATE_DONE	= 3,
 | 
						|
	UVC_BUF_STATE_ERROR	= 4,
 | 
						|
};
 | 
						|
 | 
						|
struct uvc_buffer {
 | 
						|
	struct vb2_v4l2_buffer buf;
 | 
						|
	struct list_head queue;
 | 
						|
 | 
						|
	enum uvc_buffer_state state;
 | 
						|
	void *mem;
 | 
						|
	struct sg_table *sgt;
 | 
						|
	struct scatterlist *sg;
 | 
						|
	unsigned int offset;
 | 
						|
	unsigned int length;
 | 
						|
	unsigned int bytesused;
 | 
						|
};
 | 
						|
 | 
						|
#define UVC_QUEUE_DISCONNECTED		(1 << 0)
 | 
						|
#define UVC_QUEUE_DROP_INCOMPLETE	(1 << 1)
 | 
						|
#define UVC_QUEUE_PAUSED		(1 << 2)
 | 
						|
 | 
						|
struct uvc_video_queue {
 | 
						|
	struct vb2_queue queue;
 | 
						|
 | 
						|
	unsigned int flags;
 | 
						|
	__u32 sequence;
 | 
						|
 | 
						|
	unsigned int buf_used;
 | 
						|
 | 
						|
	bool use_sg;
 | 
						|
 | 
						|
	spinlock_t irqlock;	/* Protects flags and irqqueue */
 | 
						|
	struct list_head irqqueue;
 | 
						|
};
 | 
						|
 | 
						|
static inline int uvc_queue_streaming(struct uvc_video_queue *queue)
 | 
						|
{
 | 
						|
	return vb2_is_streaming(&queue->queue);
 | 
						|
}
 | 
						|
 | 
						|
int uvcg_queue_init(struct uvc_video_queue *queue, struct device *dev, enum v4l2_buf_type type,
 | 
						|
		    struct mutex *lock);
 | 
						|
 | 
						|
void uvcg_free_buffers(struct uvc_video_queue *queue);
 | 
						|
 | 
						|
int uvcg_alloc_buffers(struct uvc_video_queue *queue,
 | 
						|
		       struct v4l2_requestbuffers *rb);
 | 
						|
 | 
						|
int uvcg_query_buffer(struct uvc_video_queue *queue, struct v4l2_buffer *buf);
 | 
						|
 | 
						|
int uvcg_queue_buffer(struct uvc_video_queue *queue, struct v4l2_buffer *buf);
 | 
						|
 | 
						|
int uvcg_dequeue_buffer(struct uvc_video_queue *queue,
 | 
						|
			struct v4l2_buffer *buf, int nonblocking);
 | 
						|
 | 
						|
__poll_t uvcg_queue_poll(struct uvc_video_queue *queue,
 | 
						|
			     struct file *file, poll_table *wait);
 | 
						|
 | 
						|
int uvcg_queue_mmap(struct uvc_video_queue *queue, struct vm_area_struct *vma);
 | 
						|
 | 
						|
#ifndef CONFIG_MMU
 | 
						|
unsigned long uvcg_queue_get_unmapped_area(struct uvc_video_queue *queue,
 | 
						|
					   unsigned long pgoff);
 | 
						|
#endif /* CONFIG_MMU */
 | 
						|
 | 
						|
void uvcg_queue_cancel(struct uvc_video_queue *queue, int disconnect);
 | 
						|
 | 
						|
int uvcg_queue_enable(struct uvc_video_queue *queue, int enable);
 | 
						|
 | 
						|
struct uvc_buffer *uvcg_queue_next_buffer(struct uvc_video_queue *queue,
 | 
						|
					  struct uvc_buffer *buf);
 | 
						|
 | 
						|
struct uvc_buffer *uvcg_queue_head(struct uvc_video_queue *queue);
 | 
						|
 | 
						|
#endif /* _UVC_QUEUE_H_ */
 | 
						|
 |