18c2ecf20Sopenharmony_ci/*
28c2ecf20Sopenharmony_ci * videobuf2-core.h - Video Buffer 2 Core Framework
38c2ecf20Sopenharmony_ci *
48c2ecf20Sopenharmony_ci * Copyright (C) 2010 Samsung Electronics
58c2ecf20Sopenharmony_ci *
68c2ecf20Sopenharmony_ci * Author: Pawel Osciak <pawel@osciak.com>
78c2ecf20Sopenharmony_ci *
88c2ecf20Sopenharmony_ci * This program is free software; you can redistribute it and/or modify
98c2ecf20Sopenharmony_ci * it under the terms of the GNU General Public License as published by
108c2ecf20Sopenharmony_ci * the Free Software Foundation.
118c2ecf20Sopenharmony_ci */
128c2ecf20Sopenharmony_ci#ifndef _MEDIA_VIDEOBUF2_CORE_H
138c2ecf20Sopenharmony_ci#define _MEDIA_VIDEOBUF2_CORE_H
148c2ecf20Sopenharmony_ci
158c2ecf20Sopenharmony_ci#include <linux/mm_types.h>
168c2ecf20Sopenharmony_ci#include <linux/mutex.h>
178c2ecf20Sopenharmony_ci#include <linux/poll.h>
188c2ecf20Sopenharmony_ci#include <linux/dma-buf.h>
198c2ecf20Sopenharmony_ci#include <linux/bitops.h>
208c2ecf20Sopenharmony_ci#include <media/media-request.h>
218c2ecf20Sopenharmony_ci
228c2ecf20Sopenharmony_ci#define VB2_MAX_FRAME	(32)
238c2ecf20Sopenharmony_ci#define VB2_MAX_PLANES	(8)
248c2ecf20Sopenharmony_ci
258c2ecf20Sopenharmony_ci/**
268c2ecf20Sopenharmony_ci * enum vb2_memory - type of memory model used to make the buffers visible
278c2ecf20Sopenharmony_ci *	on userspace.
288c2ecf20Sopenharmony_ci *
298c2ecf20Sopenharmony_ci * @VB2_MEMORY_UNKNOWN:	Buffer status is unknown or it is not used yet on
308c2ecf20Sopenharmony_ci *			userspace.
318c2ecf20Sopenharmony_ci * @VB2_MEMORY_MMAP:	The buffers are allocated by the Kernel and it is
328c2ecf20Sopenharmony_ci *			memory mapped via mmap() ioctl. This model is
338c2ecf20Sopenharmony_ci *			also used when the user is using the buffers via
348c2ecf20Sopenharmony_ci *			read() or write() system calls.
358c2ecf20Sopenharmony_ci * @VB2_MEMORY_USERPTR:	The buffers was allocated in userspace and it is
368c2ecf20Sopenharmony_ci *			memory mapped via mmap() ioctl.
378c2ecf20Sopenharmony_ci * @VB2_MEMORY_DMABUF:	The buffers are passed to userspace via DMA buffer.
388c2ecf20Sopenharmony_ci */
398c2ecf20Sopenharmony_cienum vb2_memory {
408c2ecf20Sopenharmony_ci	VB2_MEMORY_UNKNOWN	= 0,
418c2ecf20Sopenharmony_ci	VB2_MEMORY_MMAP		= 1,
428c2ecf20Sopenharmony_ci	VB2_MEMORY_USERPTR	= 2,
438c2ecf20Sopenharmony_ci	VB2_MEMORY_DMABUF	= 4,
448c2ecf20Sopenharmony_ci};
458c2ecf20Sopenharmony_ci
468c2ecf20Sopenharmony_cistruct vb2_fileio_data;
478c2ecf20Sopenharmony_cistruct vb2_threadio_data;
488c2ecf20Sopenharmony_ci
498c2ecf20Sopenharmony_ci/**
508c2ecf20Sopenharmony_ci * struct vb2_mem_ops - memory handling/memory allocator operations.
518c2ecf20Sopenharmony_ci * @alloc:	allocate video memory and, optionally, allocator private data,
528c2ecf20Sopenharmony_ci *		return ERR_PTR() on failure or a pointer to allocator private,
538c2ecf20Sopenharmony_ci *		per-buffer data on success; the returned private structure
548c2ecf20Sopenharmony_ci *		will then be passed as @buf_priv argument to other ops in this
558c2ecf20Sopenharmony_ci *		structure. Additional gfp_flags to use when allocating the
568c2ecf20Sopenharmony_ci *		are also passed to this operation. These flags are from the
578c2ecf20Sopenharmony_ci *		gfp_flags field of vb2_queue. The size argument to this function
588c2ecf20Sopenharmony_ci *		shall be *page aligned*.
598c2ecf20Sopenharmony_ci * @put:	inform the allocator that the buffer will no longer be used;
608c2ecf20Sopenharmony_ci *		usually will result in the allocator freeing the buffer (if
618c2ecf20Sopenharmony_ci *		no other users of this buffer are present); the @buf_priv
628c2ecf20Sopenharmony_ci *		argument is the allocator private per-buffer structure
638c2ecf20Sopenharmony_ci *		previously returned from the alloc callback.
648c2ecf20Sopenharmony_ci * @get_dmabuf: acquire userspace memory for a hardware operation; used for
658c2ecf20Sopenharmony_ci *		 DMABUF memory types.
668c2ecf20Sopenharmony_ci * @get_userptr: acquire userspace memory for a hardware operation; used for
678c2ecf20Sopenharmony_ci *		 USERPTR memory types; vaddr is the address passed to the
688c2ecf20Sopenharmony_ci *		 videobuf layer when queuing a video buffer of USERPTR type;
698c2ecf20Sopenharmony_ci *		 should return an allocator private per-buffer structure
708c2ecf20Sopenharmony_ci *		 associated with the buffer on success, ERR_PTR() on failure;
718c2ecf20Sopenharmony_ci *		 the returned private structure will then be passed as @buf_priv
728c2ecf20Sopenharmony_ci *		 argument to other ops in this structure.
738c2ecf20Sopenharmony_ci * @put_userptr: inform the allocator that a USERPTR buffer will no longer
748c2ecf20Sopenharmony_ci *		 be used.
758c2ecf20Sopenharmony_ci * @attach_dmabuf: attach a shared &struct dma_buf for a hardware operation;
768c2ecf20Sopenharmony_ci *		   used for DMABUF memory types; dev is the alloc device
778c2ecf20Sopenharmony_ci *		   dbuf is the shared dma_buf; returns ERR_PTR() on failure;
788c2ecf20Sopenharmony_ci *		   allocator private per-buffer structure on success;
798c2ecf20Sopenharmony_ci *		   this needs to be used for further accesses to the buffer.
808c2ecf20Sopenharmony_ci * @detach_dmabuf: inform the exporter of the buffer that the current DMABUF
818c2ecf20Sopenharmony_ci *		   buffer is no longer used; the @buf_priv argument is the
828c2ecf20Sopenharmony_ci *		   allocator private per-buffer structure previously returned
838c2ecf20Sopenharmony_ci *		   from the attach_dmabuf callback.
848c2ecf20Sopenharmony_ci * @map_dmabuf: request for access to the dmabuf from allocator; the allocator
858c2ecf20Sopenharmony_ci *		of dmabuf is informed that this driver is going to use the
868c2ecf20Sopenharmony_ci *		dmabuf.
878c2ecf20Sopenharmony_ci * @unmap_dmabuf: releases access control to the dmabuf - allocator is notified
888c2ecf20Sopenharmony_ci *		  that this driver is done using the dmabuf for now.
898c2ecf20Sopenharmony_ci * @prepare:	called every time the buffer is passed from userspace to the
908c2ecf20Sopenharmony_ci *		driver, useful for cache synchronisation, optional.
918c2ecf20Sopenharmony_ci * @finish:	called every time the buffer is passed back from the driver
928c2ecf20Sopenharmony_ci *		to the userspace, also optional.
938c2ecf20Sopenharmony_ci * @vaddr:	return a kernel virtual address to a given memory buffer
948c2ecf20Sopenharmony_ci *		associated with the passed private structure or NULL if no
958c2ecf20Sopenharmony_ci *		such mapping exists.
968c2ecf20Sopenharmony_ci * @cookie:	return allocator specific cookie for a given memory buffer
978c2ecf20Sopenharmony_ci *		associated with the passed private structure or NULL if not
988c2ecf20Sopenharmony_ci *		available.
998c2ecf20Sopenharmony_ci * @num_users:	return the current number of users of a memory buffer;
1008c2ecf20Sopenharmony_ci *		return 1 if the videobuf layer (or actually the driver using
1018c2ecf20Sopenharmony_ci *		it) is the only user.
1028c2ecf20Sopenharmony_ci * @mmap:	setup a userspace mapping for a given memory buffer under
1038c2ecf20Sopenharmony_ci *		the provided virtual memory region.
1048c2ecf20Sopenharmony_ci *
1058c2ecf20Sopenharmony_ci * Those operations are used by the videobuf2 core to implement the memory
1068c2ecf20Sopenharmony_ci * handling/memory allocators for each type of supported streaming I/O method.
1078c2ecf20Sopenharmony_ci *
1088c2ecf20Sopenharmony_ci * .. note::
1098c2ecf20Sopenharmony_ci *    #) Required ops for USERPTR types: get_userptr, put_userptr.
1108c2ecf20Sopenharmony_ci *
1118c2ecf20Sopenharmony_ci *    #) Required ops for MMAP types: alloc, put, num_users, mmap.
1128c2ecf20Sopenharmony_ci *
1138c2ecf20Sopenharmony_ci *    #) Required ops for read/write access types: alloc, put, num_users, vaddr.
1148c2ecf20Sopenharmony_ci *
1158c2ecf20Sopenharmony_ci *    #) Required ops for DMABUF types: attach_dmabuf, detach_dmabuf,
1168c2ecf20Sopenharmony_ci *       map_dmabuf, unmap_dmabuf.
1178c2ecf20Sopenharmony_ci */
1188c2ecf20Sopenharmony_cistruct vb2_mem_ops {
1198c2ecf20Sopenharmony_ci	void		*(*alloc)(struct device *dev, unsigned long attrs,
1208c2ecf20Sopenharmony_ci				  unsigned long size,
1218c2ecf20Sopenharmony_ci				  enum dma_data_direction dma_dir,
1228c2ecf20Sopenharmony_ci				  gfp_t gfp_flags);
1238c2ecf20Sopenharmony_ci	void		(*put)(void *buf_priv);
1248c2ecf20Sopenharmony_ci	struct dma_buf *(*get_dmabuf)(void *buf_priv, unsigned long flags);
1258c2ecf20Sopenharmony_ci
1268c2ecf20Sopenharmony_ci	void		*(*get_userptr)(struct device *dev, unsigned long vaddr,
1278c2ecf20Sopenharmony_ci					unsigned long size,
1288c2ecf20Sopenharmony_ci					enum dma_data_direction dma_dir);
1298c2ecf20Sopenharmony_ci	void		(*put_userptr)(void *buf_priv);
1308c2ecf20Sopenharmony_ci
1318c2ecf20Sopenharmony_ci	void		(*prepare)(void *buf_priv);
1328c2ecf20Sopenharmony_ci	void		(*finish)(void *buf_priv);
1338c2ecf20Sopenharmony_ci
1348c2ecf20Sopenharmony_ci	void		*(*attach_dmabuf)(struct device *dev,
1358c2ecf20Sopenharmony_ci					  struct dma_buf *dbuf,
1368c2ecf20Sopenharmony_ci					  unsigned long size,
1378c2ecf20Sopenharmony_ci					  enum dma_data_direction dma_dir);
1388c2ecf20Sopenharmony_ci	void		(*detach_dmabuf)(void *buf_priv);
1398c2ecf20Sopenharmony_ci	int		(*map_dmabuf)(void *buf_priv);
1408c2ecf20Sopenharmony_ci	void		(*unmap_dmabuf)(void *buf_priv);
1418c2ecf20Sopenharmony_ci
1428c2ecf20Sopenharmony_ci	void		*(*vaddr)(void *buf_priv);
1438c2ecf20Sopenharmony_ci	void		*(*cookie)(void *buf_priv);
1448c2ecf20Sopenharmony_ci
1458c2ecf20Sopenharmony_ci	unsigned int	(*num_users)(void *buf_priv);
1468c2ecf20Sopenharmony_ci
1478c2ecf20Sopenharmony_ci	int		(*mmap)(void *buf_priv, struct vm_area_struct *vma);
1488c2ecf20Sopenharmony_ci};
1498c2ecf20Sopenharmony_ci
1508c2ecf20Sopenharmony_ci/**
1518c2ecf20Sopenharmony_ci * struct vb2_plane - plane information.
1528c2ecf20Sopenharmony_ci * @mem_priv:	private data with this plane.
1538c2ecf20Sopenharmony_ci * @dbuf:	dma_buf - shared buffer object.
1548c2ecf20Sopenharmony_ci * @dbuf_mapped:	flag to show whether dbuf is mapped or not
1558c2ecf20Sopenharmony_ci * @bytesused:	number of bytes occupied by data in the plane (payload).
1568c2ecf20Sopenharmony_ci * @length:	size of this plane (NOT the payload) in bytes.
1578c2ecf20Sopenharmony_ci * @min_length:	minimum required size of this plane (NOT the payload) in bytes.
1588c2ecf20Sopenharmony_ci *		@length is always greater or equal to @min_length.
1598c2ecf20Sopenharmony_ci * @m:		Union with memtype-specific data.
1608c2ecf20Sopenharmony_ci * @m.offset:	when memory in the associated struct vb2_buffer is
1618c2ecf20Sopenharmony_ci *		%VB2_MEMORY_MMAP, equals the offset from the start of
1628c2ecf20Sopenharmony_ci *		the device memory for this plane (or is a "cookie" that
1638c2ecf20Sopenharmony_ci *		should be passed to mmap() called on the video node).
1648c2ecf20Sopenharmony_ci * @m.userptr:	when memory is %VB2_MEMORY_USERPTR, a userspace pointer
1658c2ecf20Sopenharmony_ci *		pointing to this plane.
1668c2ecf20Sopenharmony_ci * @m.fd:	when memory is %VB2_MEMORY_DMABUF, a userspace file
1678c2ecf20Sopenharmony_ci *		descriptor associated with this plane.
1688c2ecf20Sopenharmony_ci * @data_offset:	offset in the plane to the start of data; usually 0,
1698c2ecf20Sopenharmony_ci *		unless there is a header in front of the data.
1708c2ecf20Sopenharmony_ci *
1718c2ecf20Sopenharmony_ci * Should contain enough information to be able to cover all the fields
1728c2ecf20Sopenharmony_ci * of &struct v4l2_plane at videodev2.h.
1738c2ecf20Sopenharmony_ci */
1748c2ecf20Sopenharmony_cistruct vb2_plane {
1758c2ecf20Sopenharmony_ci	void			*mem_priv;
1768c2ecf20Sopenharmony_ci	struct dma_buf		*dbuf;
1778c2ecf20Sopenharmony_ci	unsigned int		dbuf_mapped;
1788c2ecf20Sopenharmony_ci	unsigned int		bytesused;
1798c2ecf20Sopenharmony_ci	unsigned int		length;
1808c2ecf20Sopenharmony_ci	unsigned int		min_length;
1818c2ecf20Sopenharmony_ci	union {
1828c2ecf20Sopenharmony_ci		unsigned int	offset;
1838c2ecf20Sopenharmony_ci		unsigned long	userptr;
1848c2ecf20Sopenharmony_ci		int		fd;
1858c2ecf20Sopenharmony_ci	} m;
1868c2ecf20Sopenharmony_ci	unsigned int		data_offset;
1878c2ecf20Sopenharmony_ci};
1888c2ecf20Sopenharmony_ci
1898c2ecf20Sopenharmony_ci/**
1908c2ecf20Sopenharmony_ci * enum vb2_io_modes - queue access methods.
1918c2ecf20Sopenharmony_ci * @VB2_MMAP:		driver supports MMAP with streaming API.
1928c2ecf20Sopenharmony_ci * @VB2_USERPTR:	driver supports USERPTR with streaming API.
1938c2ecf20Sopenharmony_ci * @VB2_READ:		driver supports read() style access.
1948c2ecf20Sopenharmony_ci * @VB2_WRITE:		driver supports write() style access.
1958c2ecf20Sopenharmony_ci * @VB2_DMABUF:		driver supports DMABUF with streaming API.
1968c2ecf20Sopenharmony_ci */
1978c2ecf20Sopenharmony_cienum vb2_io_modes {
1988c2ecf20Sopenharmony_ci	VB2_MMAP	= BIT(0),
1998c2ecf20Sopenharmony_ci	VB2_USERPTR	= BIT(1),
2008c2ecf20Sopenharmony_ci	VB2_READ	= BIT(2),
2018c2ecf20Sopenharmony_ci	VB2_WRITE	= BIT(3),
2028c2ecf20Sopenharmony_ci	VB2_DMABUF	= BIT(4),
2038c2ecf20Sopenharmony_ci};
2048c2ecf20Sopenharmony_ci
2058c2ecf20Sopenharmony_ci/**
2068c2ecf20Sopenharmony_ci * enum vb2_buffer_state - current video buffer state.
2078c2ecf20Sopenharmony_ci * @VB2_BUF_STATE_DEQUEUED:	buffer under userspace control.
2088c2ecf20Sopenharmony_ci * @VB2_BUF_STATE_IN_REQUEST:	buffer is queued in media request.
2098c2ecf20Sopenharmony_ci * @VB2_BUF_STATE_PREPARING:	buffer is being prepared in videobuf.
2108c2ecf20Sopenharmony_ci * @VB2_BUF_STATE_QUEUED:	buffer queued in videobuf, but not in driver.
2118c2ecf20Sopenharmony_ci * @VB2_BUF_STATE_ACTIVE:	buffer queued in driver and possibly used
2128c2ecf20Sopenharmony_ci *				in a hardware operation.
2138c2ecf20Sopenharmony_ci * @VB2_BUF_STATE_DONE:		buffer returned from driver to videobuf, but
2148c2ecf20Sopenharmony_ci *				not yet dequeued to userspace.
2158c2ecf20Sopenharmony_ci * @VB2_BUF_STATE_ERROR:	same as above, but the operation on the buffer
2168c2ecf20Sopenharmony_ci *				has ended with an error, which will be reported
2178c2ecf20Sopenharmony_ci *				to the userspace when it is dequeued.
2188c2ecf20Sopenharmony_ci */
2198c2ecf20Sopenharmony_cienum vb2_buffer_state {
2208c2ecf20Sopenharmony_ci	VB2_BUF_STATE_DEQUEUED,
2218c2ecf20Sopenharmony_ci	VB2_BUF_STATE_IN_REQUEST,
2228c2ecf20Sopenharmony_ci	VB2_BUF_STATE_PREPARING,
2238c2ecf20Sopenharmony_ci	VB2_BUF_STATE_QUEUED,
2248c2ecf20Sopenharmony_ci	VB2_BUF_STATE_ACTIVE,
2258c2ecf20Sopenharmony_ci	VB2_BUF_STATE_DONE,
2268c2ecf20Sopenharmony_ci	VB2_BUF_STATE_ERROR,
2278c2ecf20Sopenharmony_ci};
2288c2ecf20Sopenharmony_ci
2298c2ecf20Sopenharmony_cistruct vb2_queue;
2308c2ecf20Sopenharmony_ci
2318c2ecf20Sopenharmony_ci/**
2328c2ecf20Sopenharmony_ci * struct vb2_buffer - represents a video buffer.
2338c2ecf20Sopenharmony_ci * @vb2_queue:		pointer to &struct vb2_queue with the queue to
2348c2ecf20Sopenharmony_ci *			which this driver belongs.
2358c2ecf20Sopenharmony_ci * @index:		id number of the buffer.
2368c2ecf20Sopenharmony_ci * @type:		buffer type.
2378c2ecf20Sopenharmony_ci * @memory:		the method, in which the actual data is passed.
2388c2ecf20Sopenharmony_ci * @num_planes:		number of planes in the buffer
2398c2ecf20Sopenharmony_ci *			on an internal driver queue.
2408c2ecf20Sopenharmony_ci * @timestamp:		frame timestamp in ns.
2418c2ecf20Sopenharmony_ci * @request:		the request this buffer is associated with.
2428c2ecf20Sopenharmony_ci * @req_obj:		used to bind this buffer to a request. This
2438c2ecf20Sopenharmony_ci *			request object has a refcount.
2448c2ecf20Sopenharmony_ci */
2458c2ecf20Sopenharmony_cistruct vb2_buffer {
2468c2ecf20Sopenharmony_ci	struct vb2_queue	*vb2_queue;
2478c2ecf20Sopenharmony_ci	unsigned int		index;
2488c2ecf20Sopenharmony_ci	unsigned int		type;
2498c2ecf20Sopenharmony_ci	unsigned int		memory;
2508c2ecf20Sopenharmony_ci	unsigned int		num_planes;
2518c2ecf20Sopenharmony_ci	u64			timestamp;
2528c2ecf20Sopenharmony_ci	struct media_request	*request;
2538c2ecf20Sopenharmony_ci	struct media_request_object	req_obj;
2548c2ecf20Sopenharmony_ci
2558c2ecf20Sopenharmony_ci	/* private: internal use only
2568c2ecf20Sopenharmony_ci	 *
2578c2ecf20Sopenharmony_ci	 * state:		current buffer state; do not change
2588c2ecf20Sopenharmony_ci	 * synced:		this buffer has been synced for DMA, i.e. the
2598c2ecf20Sopenharmony_ci	 *			'prepare' memop was called. It is cleared again
2608c2ecf20Sopenharmony_ci	 *			after the 'finish' memop is called.
2618c2ecf20Sopenharmony_ci	 * prepared:		this buffer has been prepared, i.e. the
2628c2ecf20Sopenharmony_ci	 *			buf_prepare op was called. It is cleared again
2638c2ecf20Sopenharmony_ci	 *			after the 'buf_finish' op is called.
2648c2ecf20Sopenharmony_ci	 * copied_timestamp:	the timestamp of this capture buffer was copied
2658c2ecf20Sopenharmony_ci	 *			from an output buffer.
2668c2ecf20Sopenharmony_ci	 * need_cache_sync_on_prepare: when set buffer's ->prepare() function
2678c2ecf20Sopenharmony_ci	 *			performs cache sync/invalidation.
2688c2ecf20Sopenharmony_ci	 * need_cache_sync_on_finish: when set buffer's ->finish() function
2698c2ecf20Sopenharmony_ci	 *			performs cache sync/invalidation.
2708c2ecf20Sopenharmony_ci	 * queued_entry:	entry on the queued buffers list, which holds
2718c2ecf20Sopenharmony_ci	 *			all buffers queued from userspace
2728c2ecf20Sopenharmony_ci	 * done_entry:		entry on the list that stores all buffers ready
2738c2ecf20Sopenharmony_ci	 *			to be dequeued to userspace
2748c2ecf20Sopenharmony_ci	 * vb2_plane:		per-plane information; do not change
2758c2ecf20Sopenharmony_ci	 */
2768c2ecf20Sopenharmony_ci	enum vb2_buffer_state	state;
2778c2ecf20Sopenharmony_ci	unsigned int		synced:1;
2788c2ecf20Sopenharmony_ci	unsigned int		prepared:1;
2798c2ecf20Sopenharmony_ci	unsigned int		copied_timestamp:1;
2808c2ecf20Sopenharmony_ci	unsigned int		need_cache_sync_on_prepare:1;
2818c2ecf20Sopenharmony_ci	unsigned int		need_cache_sync_on_finish:1;
2828c2ecf20Sopenharmony_ci
2838c2ecf20Sopenharmony_ci	struct vb2_plane	planes[VB2_MAX_PLANES];
2848c2ecf20Sopenharmony_ci	struct list_head	queued_entry;
2858c2ecf20Sopenharmony_ci	struct list_head	done_entry;
2868c2ecf20Sopenharmony_ci#ifdef CONFIG_VIDEO_ADV_DEBUG
2878c2ecf20Sopenharmony_ci	/*
2888c2ecf20Sopenharmony_ci	 * Counters for how often these buffer-related ops are
2898c2ecf20Sopenharmony_ci	 * called. Used to check for unbalanced ops.
2908c2ecf20Sopenharmony_ci	 */
2918c2ecf20Sopenharmony_ci	u32		cnt_mem_alloc;
2928c2ecf20Sopenharmony_ci	u32		cnt_mem_put;
2938c2ecf20Sopenharmony_ci	u32		cnt_mem_get_dmabuf;
2948c2ecf20Sopenharmony_ci	u32		cnt_mem_get_userptr;
2958c2ecf20Sopenharmony_ci	u32		cnt_mem_put_userptr;
2968c2ecf20Sopenharmony_ci	u32		cnt_mem_prepare;
2978c2ecf20Sopenharmony_ci	u32		cnt_mem_finish;
2988c2ecf20Sopenharmony_ci	u32		cnt_mem_attach_dmabuf;
2998c2ecf20Sopenharmony_ci	u32		cnt_mem_detach_dmabuf;
3008c2ecf20Sopenharmony_ci	u32		cnt_mem_map_dmabuf;
3018c2ecf20Sopenharmony_ci	u32		cnt_mem_unmap_dmabuf;
3028c2ecf20Sopenharmony_ci	u32		cnt_mem_vaddr;
3038c2ecf20Sopenharmony_ci	u32		cnt_mem_cookie;
3048c2ecf20Sopenharmony_ci	u32		cnt_mem_num_users;
3058c2ecf20Sopenharmony_ci	u32		cnt_mem_mmap;
3068c2ecf20Sopenharmony_ci
3078c2ecf20Sopenharmony_ci	u32		cnt_buf_out_validate;
3088c2ecf20Sopenharmony_ci	u32		cnt_buf_init;
3098c2ecf20Sopenharmony_ci	u32		cnt_buf_prepare;
3108c2ecf20Sopenharmony_ci	u32		cnt_buf_finish;
3118c2ecf20Sopenharmony_ci	u32		cnt_buf_cleanup;
3128c2ecf20Sopenharmony_ci	u32		cnt_buf_queue;
3138c2ecf20Sopenharmony_ci	u32		cnt_buf_request_complete;
3148c2ecf20Sopenharmony_ci
3158c2ecf20Sopenharmony_ci	/* This counts the number of calls to vb2_buffer_done() */
3168c2ecf20Sopenharmony_ci	u32		cnt_buf_done;
3178c2ecf20Sopenharmony_ci#endif
3188c2ecf20Sopenharmony_ci};
3198c2ecf20Sopenharmony_ci
3208c2ecf20Sopenharmony_ci/**
3218c2ecf20Sopenharmony_ci * struct vb2_ops - driver-specific callbacks.
3228c2ecf20Sopenharmony_ci *
3238c2ecf20Sopenharmony_ci * These operations are not called from interrupt context except where
3248c2ecf20Sopenharmony_ci * mentioned specifically.
3258c2ecf20Sopenharmony_ci *
3268c2ecf20Sopenharmony_ci * @queue_setup:	called from VIDIOC_REQBUFS() and VIDIOC_CREATE_BUFS()
3278c2ecf20Sopenharmony_ci *			handlers before memory allocation. It can be called
3288c2ecf20Sopenharmony_ci *			twice: if the original number of requested buffers
3298c2ecf20Sopenharmony_ci *			could not be allocated, then it will be called a
3308c2ecf20Sopenharmony_ci *			second time with the actually allocated number of
3318c2ecf20Sopenharmony_ci *			buffers to verify if that is OK.
3328c2ecf20Sopenharmony_ci *			The driver should return the required number of buffers
3338c2ecf20Sopenharmony_ci *			in \*num_buffers, the required number of planes per
3348c2ecf20Sopenharmony_ci *			buffer in \*num_planes, the size of each plane should be
3358c2ecf20Sopenharmony_ci *			set in the sizes\[\] array and optional per-plane
3368c2ecf20Sopenharmony_ci *			allocator specific device in the alloc_devs\[\] array.
3378c2ecf20Sopenharmony_ci *			When called from VIDIOC_REQBUFS(), \*num_planes == 0,
3388c2ecf20Sopenharmony_ci *			the driver has to use the currently configured format to
3398c2ecf20Sopenharmony_ci *			determine the plane sizes and \*num_buffers is the total
3408c2ecf20Sopenharmony_ci *			number of buffers that are being allocated. When called
3418c2ecf20Sopenharmony_ci *			from VIDIOC_CREATE_BUFS(), \*num_planes != 0 and it
3428c2ecf20Sopenharmony_ci *			describes the requested number of planes and sizes\[\]
3438c2ecf20Sopenharmony_ci *			contains the requested plane sizes. In this case
3448c2ecf20Sopenharmony_ci *			\*num_buffers are being allocated additionally to
3458c2ecf20Sopenharmony_ci *			q->num_buffers. If either \*num_planes or the requested
3468c2ecf20Sopenharmony_ci *			sizes are invalid callback must return %-EINVAL.
3478c2ecf20Sopenharmony_ci * @wait_prepare:	release any locks taken while calling vb2 functions;
3488c2ecf20Sopenharmony_ci *			it is called before an ioctl needs to wait for a new
3498c2ecf20Sopenharmony_ci *			buffer to arrive; required to avoid a deadlock in
3508c2ecf20Sopenharmony_ci *			blocking access type.
3518c2ecf20Sopenharmony_ci * @wait_finish:	reacquire all locks released in the previous callback;
3528c2ecf20Sopenharmony_ci *			required to continue operation after sleeping while
3538c2ecf20Sopenharmony_ci *			waiting for a new buffer to arrive.
3548c2ecf20Sopenharmony_ci * @buf_out_validate:	called when the output buffer is prepared or queued
3558c2ecf20Sopenharmony_ci *			to a request; drivers can use this to validate
3568c2ecf20Sopenharmony_ci *			userspace-provided information; this is required only
3578c2ecf20Sopenharmony_ci *			for OUTPUT queues.
3588c2ecf20Sopenharmony_ci * @buf_init:		called once after allocating a buffer (in MMAP case)
3598c2ecf20Sopenharmony_ci *			or after acquiring a new USERPTR buffer; drivers may
3608c2ecf20Sopenharmony_ci *			perform additional buffer-related initialization;
3618c2ecf20Sopenharmony_ci *			initialization failure (return != 0) will prevent
3628c2ecf20Sopenharmony_ci *			queue setup from completing successfully; optional.
3638c2ecf20Sopenharmony_ci * @buf_prepare:	called every time the buffer is queued from userspace
3648c2ecf20Sopenharmony_ci *			and from the VIDIOC_PREPARE_BUF() ioctl; drivers may
3658c2ecf20Sopenharmony_ci *			perform any initialization required before each
3668c2ecf20Sopenharmony_ci *			hardware operation in this callback; drivers can
3678c2ecf20Sopenharmony_ci *			access/modify the buffer here as it is still synced for
3688c2ecf20Sopenharmony_ci *			the CPU; drivers that support VIDIOC_CREATE_BUFS() must
3698c2ecf20Sopenharmony_ci *			also validate the buffer size; if an error is returned,
3708c2ecf20Sopenharmony_ci *			the buffer will not be queued in driver; optional.
3718c2ecf20Sopenharmony_ci * @buf_finish:		called before every dequeue of the buffer back to
3728c2ecf20Sopenharmony_ci *			userspace; the buffer is synced for the CPU, so drivers
3738c2ecf20Sopenharmony_ci *			can access/modify the buffer contents; drivers may
3748c2ecf20Sopenharmony_ci *			perform any operations required before userspace
3758c2ecf20Sopenharmony_ci *			accesses the buffer; optional. The buffer state can be
3768c2ecf20Sopenharmony_ci *			one of the following: %DONE and %ERROR occur while
3778c2ecf20Sopenharmony_ci *			streaming is in progress, and the %PREPARED state occurs
3788c2ecf20Sopenharmony_ci *			when the queue has been canceled and all pending
3798c2ecf20Sopenharmony_ci *			buffers are being returned to their default %DEQUEUED
3808c2ecf20Sopenharmony_ci *			state. Typically you only have to do something if the
3818c2ecf20Sopenharmony_ci *			state is %VB2_BUF_STATE_DONE, since in all other cases
3828c2ecf20Sopenharmony_ci *			the buffer contents will be ignored anyway.
3838c2ecf20Sopenharmony_ci * @buf_cleanup:	called once before the buffer is freed; drivers may
3848c2ecf20Sopenharmony_ci *			perform any additional cleanup; optional.
3858c2ecf20Sopenharmony_ci * @start_streaming:	called once to enter 'streaming' state; the driver may
3868c2ecf20Sopenharmony_ci *			receive buffers with @buf_queue callback
3878c2ecf20Sopenharmony_ci *			before @start_streaming is called; the driver gets the
3888c2ecf20Sopenharmony_ci *			number of already queued buffers in count parameter;
3898c2ecf20Sopenharmony_ci *			driver can return an error if hardware fails, in that
3908c2ecf20Sopenharmony_ci *			case all buffers that have been already given by
3918c2ecf20Sopenharmony_ci *			the @buf_queue callback are to be returned by the driver
3928c2ecf20Sopenharmony_ci *			by calling vb2_buffer_done() with %VB2_BUF_STATE_QUEUED.
3938c2ecf20Sopenharmony_ci *			If you need a minimum number of buffers before you can
3948c2ecf20Sopenharmony_ci *			start streaming, then set
3958c2ecf20Sopenharmony_ci *			&vb2_queue->min_buffers_needed. If that is non-zero
3968c2ecf20Sopenharmony_ci *			then @start_streaming won't be called until at least
3978c2ecf20Sopenharmony_ci *			that many buffers have been queued up by userspace.
3988c2ecf20Sopenharmony_ci * @stop_streaming:	called when 'streaming' state must be disabled; driver
3998c2ecf20Sopenharmony_ci *			should stop any DMA transactions or wait until they
4008c2ecf20Sopenharmony_ci *			finish and give back all buffers it got from &buf_queue
4018c2ecf20Sopenharmony_ci *			callback by calling vb2_buffer_done() with either
4028c2ecf20Sopenharmony_ci *			%VB2_BUF_STATE_DONE or %VB2_BUF_STATE_ERROR; may use
4038c2ecf20Sopenharmony_ci *			vb2_wait_for_all_buffers() function
4048c2ecf20Sopenharmony_ci * @buf_queue:		passes buffer vb to the driver; driver may start
4058c2ecf20Sopenharmony_ci *			hardware operation on this buffer; driver should give
4068c2ecf20Sopenharmony_ci *			the buffer back by calling vb2_buffer_done() function;
4078c2ecf20Sopenharmony_ci *			it is always called after calling VIDIOC_STREAMON()
4088c2ecf20Sopenharmony_ci *			ioctl; might be called before @start_streaming callback
4098c2ecf20Sopenharmony_ci *			if user pre-queued buffers before calling
4108c2ecf20Sopenharmony_ci *			VIDIOC_STREAMON().
4118c2ecf20Sopenharmony_ci * @buf_request_complete: a buffer that was never queued to the driver but is
4128c2ecf20Sopenharmony_ci *			associated with a queued request was canceled.
4138c2ecf20Sopenharmony_ci *			The driver will have to mark associated objects in the
4148c2ecf20Sopenharmony_ci *			request as completed; required if requests are
4158c2ecf20Sopenharmony_ci *			supported.
4168c2ecf20Sopenharmony_ci */
4178c2ecf20Sopenharmony_cistruct vb2_ops {
4188c2ecf20Sopenharmony_ci	int (*queue_setup)(struct vb2_queue *q,
4198c2ecf20Sopenharmony_ci			   unsigned int *num_buffers, unsigned int *num_planes,
4208c2ecf20Sopenharmony_ci			   unsigned int sizes[], struct device *alloc_devs[]);
4218c2ecf20Sopenharmony_ci
4228c2ecf20Sopenharmony_ci	void (*wait_prepare)(struct vb2_queue *q);
4238c2ecf20Sopenharmony_ci	void (*wait_finish)(struct vb2_queue *q);
4248c2ecf20Sopenharmony_ci
4258c2ecf20Sopenharmony_ci	int (*buf_out_validate)(struct vb2_buffer *vb);
4268c2ecf20Sopenharmony_ci	int (*buf_init)(struct vb2_buffer *vb);
4278c2ecf20Sopenharmony_ci	int (*buf_prepare)(struct vb2_buffer *vb);
4288c2ecf20Sopenharmony_ci	void (*buf_finish)(struct vb2_buffer *vb);
4298c2ecf20Sopenharmony_ci	void (*buf_cleanup)(struct vb2_buffer *vb);
4308c2ecf20Sopenharmony_ci
4318c2ecf20Sopenharmony_ci	int (*start_streaming)(struct vb2_queue *q, unsigned int count);
4328c2ecf20Sopenharmony_ci	void (*stop_streaming)(struct vb2_queue *q);
4338c2ecf20Sopenharmony_ci
4348c2ecf20Sopenharmony_ci	void (*buf_queue)(struct vb2_buffer *vb);
4358c2ecf20Sopenharmony_ci
4368c2ecf20Sopenharmony_ci	void (*buf_request_complete)(struct vb2_buffer *vb);
4378c2ecf20Sopenharmony_ci};
4388c2ecf20Sopenharmony_ci
4398c2ecf20Sopenharmony_ci/**
4408c2ecf20Sopenharmony_ci * struct vb2_buf_ops - driver-specific callbacks.
4418c2ecf20Sopenharmony_ci *
4428c2ecf20Sopenharmony_ci * @verify_planes_array: Verify that a given user space structure contains
4438c2ecf20Sopenharmony_ci *			enough planes for the buffer. This is called
4448c2ecf20Sopenharmony_ci *			for each dequeued buffer.
4458c2ecf20Sopenharmony_ci * @init_buffer:	given a &vb2_buffer initialize the extra data after
4468c2ecf20Sopenharmony_ci *			struct vb2_buffer.
4478c2ecf20Sopenharmony_ci *			For V4L2 this is a &struct vb2_v4l2_buffer.
4488c2ecf20Sopenharmony_ci * @fill_user_buffer:	given a &vb2_buffer fill in the userspace structure.
4498c2ecf20Sopenharmony_ci *			For V4L2 this is a &struct v4l2_buffer.
4508c2ecf20Sopenharmony_ci * @fill_vb2_buffer:	given a userspace structure, fill in the &vb2_buffer.
4518c2ecf20Sopenharmony_ci *			If the userspace structure is invalid, then this op
4528c2ecf20Sopenharmony_ci *			will return an error.
4538c2ecf20Sopenharmony_ci * @copy_timestamp:	copy the timestamp from a userspace structure to
4548c2ecf20Sopenharmony_ci *			the &struct vb2_buffer.
4558c2ecf20Sopenharmony_ci */
4568c2ecf20Sopenharmony_cistruct vb2_buf_ops {
4578c2ecf20Sopenharmony_ci	int (*verify_planes_array)(struct vb2_buffer *vb, const void *pb);
4588c2ecf20Sopenharmony_ci	void (*init_buffer)(struct vb2_buffer *vb);
4598c2ecf20Sopenharmony_ci	void (*fill_user_buffer)(struct vb2_buffer *vb, void *pb);
4608c2ecf20Sopenharmony_ci	int (*fill_vb2_buffer)(struct vb2_buffer *vb, struct vb2_plane *planes);
4618c2ecf20Sopenharmony_ci	void (*copy_timestamp)(struct vb2_buffer *vb, const void *pb);
4628c2ecf20Sopenharmony_ci};
4638c2ecf20Sopenharmony_ci
4648c2ecf20Sopenharmony_ci/**
4658c2ecf20Sopenharmony_ci * struct vb2_queue - a videobuf queue.
4668c2ecf20Sopenharmony_ci *
4678c2ecf20Sopenharmony_ci * @type:	private buffer type whose content is defined by the vb2-core
4688c2ecf20Sopenharmony_ci *		caller. For example, for V4L2, it should match
4698c2ecf20Sopenharmony_ci *		the types defined on &enum v4l2_buf_type.
4708c2ecf20Sopenharmony_ci * @io_modes:	supported io methods (see &enum vb2_io_modes).
4718c2ecf20Sopenharmony_ci * @alloc_devs:	&struct device memory type/allocator-specific per-plane device
4728c2ecf20Sopenharmony_ci * @dev:	device to use for the default allocation context if the driver
4738c2ecf20Sopenharmony_ci *		doesn't fill in the @alloc_devs array.
4748c2ecf20Sopenharmony_ci * @dma_attrs:	DMA attributes to use for the DMA.
4758c2ecf20Sopenharmony_ci * @bidirectional: when this flag is set the DMA direction for the buffers of
4768c2ecf20Sopenharmony_ci *		this queue will be overridden with %DMA_BIDIRECTIONAL direction.
4778c2ecf20Sopenharmony_ci *		This is useful in cases where the hardware (firmware) writes to
4788c2ecf20Sopenharmony_ci *		a buffer which is mapped as read (%DMA_TO_DEVICE), or reads from
4798c2ecf20Sopenharmony_ci *		buffer which is mapped for write (%DMA_FROM_DEVICE) in order
4808c2ecf20Sopenharmony_ci *		to satisfy some internal hardware restrictions or adds a padding
4818c2ecf20Sopenharmony_ci *		needed by the processing algorithm. In case the DMA mapping is
4828c2ecf20Sopenharmony_ci *		not bidirectional but the hardware (firmware) trying to access
4838c2ecf20Sopenharmony_ci *		the buffer (in the opposite direction) this could lead to an
4848c2ecf20Sopenharmony_ci *		IOMMU protection faults.
4858c2ecf20Sopenharmony_ci * @fileio_read_once:		report EOF after reading the first buffer
4868c2ecf20Sopenharmony_ci * @fileio_write_immediately:	queue buffer after each write() call
4878c2ecf20Sopenharmony_ci * @allow_zero_bytesused:	allow bytesused == 0 to be passed to the driver
4888c2ecf20Sopenharmony_ci * @quirk_poll_must_check_waiting_for_buffers: Return %EPOLLERR at poll when QBUF
4898c2ecf20Sopenharmony_ci *              has not been called. This is a vb1 idiom that has been adopted
4908c2ecf20Sopenharmony_ci *              also by vb2.
4918c2ecf20Sopenharmony_ci * @supports_requests: this queue supports the Request API.
4928c2ecf20Sopenharmony_ci * @requires_requests: this queue requires the Request API. If this is set to 1,
4938c2ecf20Sopenharmony_ci *		then supports_requests must be set to 1 as well.
4948c2ecf20Sopenharmony_ci * @uses_qbuf:	qbuf was used directly for this queue. Set to 1 the first
4958c2ecf20Sopenharmony_ci *		time this is called. Set to 0 when the queue is canceled.
4968c2ecf20Sopenharmony_ci *		If this is 1, then you cannot queue buffers from a request.
4978c2ecf20Sopenharmony_ci * @uses_requests: requests are used for this queue. Set to 1 the first time
4988c2ecf20Sopenharmony_ci *		a request is queued. Set to 0 when the queue is canceled.
4998c2ecf20Sopenharmony_ci *		If this is 1, then you cannot queue buffers directly.
5008c2ecf20Sopenharmony_ci * @allow_cache_hints: when set user-space can pass cache management hints in
5018c2ecf20Sopenharmony_ci *		order to skip cache flush/invalidation on ->prepare() or/and
5028c2ecf20Sopenharmony_ci *		->finish().
5038c2ecf20Sopenharmony_ci * @lock:	pointer to a mutex that protects the &struct vb2_queue. The
5048c2ecf20Sopenharmony_ci *		driver can set this to a mutex to let the v4l2 core serialize
5058c2ecf20Sopenharmony_ci *		the queuing ioctls. If the driver wants to handle locking
5068c2ecf20Sopenharmony_ci *		itself, then this should be set to NULL. This lock is not used
5078c2ecf20Sopenharmony_ci *		by the videobuf2 core API.
5088c2ecf20Sopenharmony_ci * @owner:	The filehandle that 'owns' the buffers, i.e. the filehandle
5098c2ecf20Sopenharmony_ci *		that called reqbufs, create_buffers or started fileio.
5108c2ecf20Sopenharmony_ci *		This field is not used by the videobuf2 core API, but it allows
5118c2ecf20Sopenharmony_ci *		drivers to easily associate an owner filehandle with the queue.
5128c2ecf20Sopenharmony_ci * @ops:	driver-specific callbacks
5138c2ecf20Sopenharmony_ci * @mem_ops:	memory allocator specific callbacks
5148c2ecf20Sopenharmony_ci * @buf_ops:	callbacks to deliver buffer information.
5158c2ecf20Sopenharmony_ci *		between user-space and kernel-space.
5168c2ecf20Sopenharmony_ci * @drv_priv:	driver private data.
5178c2ecf20Sopenharmony_ci * @subsystem_flags: Flags specific to the subsystem (V4L2/DVB/etc.). Not used
5188c2ecf20Sopenharmony_ci *		by the vb2 core.
5198c2ecf20Sopenharmony_ci * @buf_struct_size: size of the driver-specific buffer structure;
5208c2ecf20Sopenharmony_ci *		"0" indicates the driver doesn't want to use a custom buffer
5218c2ecf20Sopenharmony_ci *		structure type. In that case a subsystem-specific struct
5228c2ecf20Sopenharmony_ci *		will be used (in the case of V4L2 that is
5238c2ecf20Sopenharmony_ci *		``sizeof(struct vb2_v4l2_buffer)``). The first field of the
5248c2ecf20Sopenharmony_ci *		driver-specific buffer structure must be the subsystem-specific
5258c2ecf20Sopenharmony_ci *		struct (vb2_v4l2_buffer in the case of V4L2).
5268c2ecf20Sopenharmony_ci * @timestamp_flags: Timestamp flags; ``V4L2_BUF_FLAG_TIMESTAMP_*`` and
5278c2ecf20Sopenharmony_ci *		``V4L2_BUF_FLAG_TSTAMP_SRC_*``
5288c2ecf20Sopenharmony_ci * @gfp_flags:	additional gfp flags used when allocating the buffers.
5298c2ecf20Sopenharmony_ci *		Typically this is 0, but it may be e.g. %GFP_DMA or %__GFP_DMA32
5308c2ecf20Sopenharmony_ci *		to force the buffer allocation to a specific memory zone.
5318c2ecf20Sopenharmony_ci * @min_buffers_needed: the minimum number of buffers needed before
5328c2ecf20Sopenharmony_ci *		@start_streaming can be called. Used when a DMA engine
5338c2ecf20Sopenharmony_ci *		cannot be started unless at least this number of buffers
5348c2ecf20Sopenharmony_ci *		have been queued into the driver.
5358c2ecf20Sopenharmony_ci */
5368c2ecf20Sopenharmony_ci/*
5378c2ecf20Sopenharmony_ci * Private elements (won't appear at the uAPI book):
5388c2ecf20Sopenharmony_ci * @mmap_lock:	private mutex used when buffers are allocated/freed/mmapped
5398c2ecf20Sopenharmony_ci * @memory:	current memory type used
5408c2ecf20Sopenharmony_ci * @dma_dir:	DMA mapping direction.
5418c2ecf20Sopenharmony_ci * @bufs:	videobuf buffer structures
5428c2ecf20Sopenharmony_ci * @num_buffers: number of allocated/used buffers
5438c2ecf20Sopenharmony_ci * @queued_list: list of buffers currently queued from userspace
5448c2ecf20Sopenharmony_ci * @queued_count: number of buffers queued and ready for streaming.
5458c2ecf20Sopenharmony_ci * @owned_by_drv_count: number of buffers owned by the driver
5468c2ecf20Sopenharmony_ci * @done_list:	list of buffers ready to be dequeued to userspace
5478c2ecf20Sopenharmony_ci * @done_lock:	lock to protect done_list list
5488c2ecf20Sopenharmony_ci * @done_wq:	waitqueue for processes waiting for buffers ready to be dequeued
5498c2ecf20Sopenharmony_ci * @streaming:	current streaming state
5508c2ecf20Sopenharmony_ci * @start_streaming_called: @start_streaming was called successfully and we
5518c2ecf20Sopenharmony_ci *		started streaming.
5528c2ecf20Sopenharmony_ci * @error:	a fatal error occurred on the queue
5538c2ecf20Sopenharmony_ci * @waiting_for_buffers: used in poll() to check if vb2 is still waiting for
5548c2ecf20Sopenharmony_ci *		buffers. Only set for capture queues if qbuf has not yet been
5558c2ecf20Sopenharmony_ci *		called since poll() needs to return %EPOLLERR in that situation.
5568c2ecf20Sopenharmony_ci * @is_multiplanar: set if buffer type is multiplanar
5578c2ecf20Sopenharmony_ci * @is_output:	set if buffer type is output
5588c2ecf20Sopenharmony_ci * @copy_timestamp: set if vb2-core should set timestamps
5598c2ecf20Sopenharmony_ci * @last_buffer_dequeued: used in poll() and DQBUF to immediately return if the
5608c2ecf20Sopenharmony_ci *		last decoded buffer was already dequeued. Set for capture queues
5618c2ecf20Sopenharmony_ci *		when a buffer with the %V4L2_BUF_FLAG_LAST is dequeued.
5628c2ecf20Sopenharmony_ci * @fileio:	file io emulator internal data, used only if emulator is active
5638c2ecf20Sopenharmony_ci * @threadio:	thread io internal data, used only if thread is active
5648c2ecf20Sopenharmony_ci * @name:	queue name, used for logging purpose. Initialized automatically
5658c2ecf20Sopenharmony_ci *		if left empty by drivers.
5668c2ecf20Sopenharmony_ci */
5678c2ecf20Sopenharmony_cistruct vb2_queue {
5688c2ecf20Sopenharmony_ci	unsigned int			type;
5698c2ecf20Sopenharmony_ci	unsigned int			io_modes;
5708c2ecf20Sopenharmony_ci	struct device			*dev;
5718c2ecf20Sopenharmony_ci	unsigned long			dma_attrs;
5728c2ecf20Sopenharmony_ci	unsigned int			bidirectional:1;
5738c2ecf20Sopenharmony_ci	unsigned int			fileio_read_once:1;
5748c2ecf20Sopenharmony_ci	unsigned int			fileio_write_immediately:1;
5758c2ecf20Sopenharmony_ci	unsigned int			allow_zero_bytesused:1;
5768c2ecf20Sopenharmony_ci	unsigned int		   quirk_poll_must_check_waiting_for_buffers:1;
5778c2ecf20Sopenharmony_ci	unsigned int			supports_requests:1;
5788c2ecf20Sopenharmony_ci	unsigned int			requires_requests:1;
5798c2ecf20Sopenharmony_ci	unsigned int			uses_qbuf:1;
5808c2ecf20Sopenharmony_ci	unsigned int			uses_requests:1;
5818c2ecf20Sopenharmony_ci	unsigned int			allow_cache_hints:1;
5828c2ecf20Sopenharmony_ci
5838c2ecf20Sopenharmony_ci	struct mutex			*lock;
5848c2ecf20Sopenharmony_ci	void				*owner;
5858c2ecf20Sopenharmony_ci
5868c2ecf20Sopenharmony_ci	const struct vb2_ops		*ops;
5878c2ecf20Sopenharmony_ci	const struct vb2_mem_ops	*mem_ops;
5888c2ecf20Sopenharmony_ci	const struct vb2_buf_ops	*buf_ops;
5898c2ecf20Sopenharmony_ci
5908c2ecf20Sopenharmony_ci	void				*drv_priv;
5918c2ecf20Sopenharmony_ci	u32				subsystem_flags;
5928c2ecf20Sopenharmony_ci	unsigned int			buf_struct_size;
5938c2ecf20Sopenharmony_ci	u32				timestamp_flags;
5948c2ecf20Sopenharmony_ci	gfp_t				gfp_flags;
5958c2ecf20Sopenharmony_ci	u32				min_buffers_needed;
5968c2ecf20Sopenharmony_ci
5978c2ecf20Sopenharmony_ci	struct device			*alloc_devs[VB2_MAX_PLANES];
5988c2ecf20Sopenharmony_ci
5998c2ecf20Sopenharmony_ci	/* private: internal use only */
6008c2ecf20Sopenharmony_ci	struct mutex			mmap_lock;
6018c2ecf20Sopenharmony_ci	unsigned int			memory;
6028c2ecf20Sopenharmony_ci	enum dma_data_direction		dma_dir;
6038c2ecf20Sopenharmony_ci	struct vb2_buffer		*bufs[VB2_MAX_FRAME];
6048c2ecf20Sopenharmony_ci	unsigned int			num_buffers;
6058c2ecf20Sopenharmony_ci
6068c2ecf20Sopenharmony_ci	struct list_head		queued_list;
6078c2ecf20Sopenharmony_ci	unsigned int			queued_count;
6088c2ecf20Sopenharmony_ci
6098c2ecf20Sopenharmony_ci	atomic_t			owned_by_drv_count;
6108c2ecf20Sopenharmony_ci	struct list_head		done_list;
6118c2ecf20Sopenharmony_ci	spinlock_t			done_lock;
6128c2ecf20Sopenharmony_ci	wait_queue_head_t		done_wq;
6138c2ecf20Sopenharmony_ci
6148c2ecf20Sopenharmony_ci	unsigned int			streaming:1;
6158c2ecf20Sopenharmony_ci	unsigned int			start_streaming_called:1;
6168c2ecf20Sopenharmony_ci	unsigned int			error:1;
6178c2ecf20Sopenharmony_ci	unsigned int			waiting_for_buffers:1;
6188c2ecf20Sopenharmony_ci	unsigned int			waiting_in_dqbuf:1;
6198c2ecf20Sopenharmony_ci	unsigned int			is_multiplanar:1;
6208c2ecf20Sopenharmony_ci	unsigned int			is_output:1;
6218c2ecf20Sopenharmony_ci	unsigned int			copy_timestamp:1;
6228c2ecf20Sopenharmony_ci	unsigned int			last_buffer_dequeued:1;
6238c2ecf20Sopenharmony_ci
6248c2ecf20Sopenharmony_ci	struct vb2_fileio_data		*fileio;
6258c2ecf20Sopenharmony_ci	struct vb2_threadio_data	*threadio;
6268c2ecf20Sopenharmony_ci
6278c2ecf20Sopenharmony_ci	char				name[32];
6288c2ecf20Sopenharmony_ci
6298c2ecf20Sopenharmony_ci#ifdef CONFIG_VIDEO_ADV_DEBUG
6308c2ecf20Sopenharmony_ci	/*
6318c2ecf20Sopenharmony_ci	 * Counters for how often these queue-related ops are
6328c2ecf20Sopenharmony_ci	 * called. Used to check for unbalanced ops.
6338c2ecf20Sopenharmony_ci	 */
6348c2ecf20Sopenharmony_ci	u32				cnt_queue_setup;
6358c2ecf20Sopenharmony_ci	u32				cnt_wait_prepare;
6368c2ecf20Sopenharmony_ci	u32				cnt_wait_finish;
6378c2ecf20Sopenharmony_ci	u32				cnt_start_streaming;
6388c2ecf20Sopenharmony_ci	u32				cnt_stop_streaming;
6398c2ecf20Sopenharmony_ci#endif
6408c2ecf20Sopenharmony_ci};
6418c2ecf20Sopenharmony_ci
6428c2ecf20Sopenharmony_ci/**
6438c2ecf20Sopenharmony_ci * vb2_queue_allows_cache_hints() - Return true if the queue allows cache
6448c2ecf20Sopenharmony_ci * and memory consistency hints.
6458c2ecf20Sopenharmony_ci *
6468c2ecf20Sopenharmony_ci * @q:		pointer to &struct vb2_queue with videobuf2 queue
6478c2ecf20Sopenharmony_ci */
6488c2ecf20Sopenharmony_cistatic inline bool vb2_queue_allows_cache_hints(struct vb2_queue *q)
6498c2ecf20Sopenharmony_ci{
6508c2ecf20Sopenharmony_ci	return q->allow_cache_hints && q->memory == VB2_MEMORY_MMAP;
6518c2ecf20Sopenharmony_ci}
6528c2ecf20Sopenharmony_ci
6538c2ecf20Sopenharmony_ci/**
6548c2ecf20Sopenharmony_ci * vb2_plane_vaddr() - Return a kernel virtual address of a given plane.
6558c2ecf20Sopenharmony_ci * @vb:		pointer to &struct vb2_buffer to which the plane in
6568c2ecf20Sopenharmony_ci *		question belongs to.
6578c2ecf20Sopenharmony_ci * @plane_no:	plane number for which the address is to be returned.
6588c2ecf20Sopenharmony_ci *
6598c2ecf20Sopenharmony_ci * This function returns a kernel virtual address of a given plane if
6608c2ecf20Sopenharmony_ci * such a mapping exist, NULL otherwise.
6618c2ecf20Sopenharmony_ci */
6628c2ecf20Sopenharmony_civoid *vb2_plane_vaddr(struct vb2_buffer *vb, unsigned int plane_no);
6638c2ecf20Sopenharmony_ci
6648c2ecf20Sopenharmony_ci/**
6658c2ecf20Sopenharmony_ci * vb2_plane_cookie() - Return allocator specific cookie for the given plane.
6668c2ecf20Sopenharmony_ci * @vb:		pointer to &struct vb2_buffer to which the plane in
6678c2ecf20Sopenharmony_ci *		question belongs to.
6688c2ecf20Sopenharmony_ci * @plane_no:	plane number for which the cookie is to be returned.
6698c2ecf20Sopenharmony_ci *
6708c2ecf20Sopenharmony_ci * This function returns an allocator specific cookie for a given plane if
6718c2ecf20Sopenharmony_ci * available, NULL otherwise. The allocator should provide some simple static
6728c2ecf20Sopenharmony_ci * inline function, which would convert this cookie to the allocator specific
6738c2ecf20Sopenharmony_ci * type that can be used directly by the driver to access the buffer. This can
6748c2ecf20Sopenharmony_ci * be for example physical address, pointer to scatter list or IOMMU mapping.
6758c2ecf20Sopenharmony_ci */
6768c2ecf20Sopenharmony_civoid *vb2_plane_cookie(struct vb2_buffer *vb, unsigned int plane_no);
6778c2ecf20Sopenharmony_ci
6788c2ecf20Sopenharmony_ci/**
6798c2ecf20Sopenharmony_ci * vb2_buffer_done() - inform videobuf that an operation on a buffer
6808c2ecf20Sopenharmony_ci *	is finished.
6818c2ecf20Sopenharmony_ci * @vb:		pointer to &struct vb2_buffer to be used.
6828c2ecf20Sopenharmony_ci * @state:	state of the buffer, as defined by &enum vb2_buffer_state.
6838c2ecf20Sopenharmony_ci *		Either %VB2_BUF_STATE_DONE if the operation finished
6848c2ecf20Sopenharmony_ci *		successfully, %VB2_BUF_STATE_ERROR if the operation finished
6858c2ecf20Sopenharmony_ci *		with an error or %VB2_BUF_STATE_QUEUED.
6868c2ecf20Sopenharmony_ci *
6878c2ecf20Sopenharmony_ci * This function should be called by the driver after a hardware operation on
6888c2ecf20Sopenharmony_ci * a buffer is finished and the buffer may be returned to userspace. The driver
6898c2ecf20Sopenharmony_ci * cannot use this buffer anymore until it is queued back to it by videobuf
6908c2ecf20Sopenharmony_ci * by the means of &vb2_ops->buf_queue callback. Only buffers previously queued
6918c2ecf20Sopenharmony_ci * to the driver by &vb2_ops->buf_queue can be passed to this function.
6928c2ecf20Sopenharmony_ci *
6938c2ecf20Sopenharmony_ci * While streaming a buffer can only be returned in state DONE or ERROR.
6948c2ecf20Sopenharmony_ci * The &vb2_ops->start_streaming op can also return them in case the DMA engine
6958c2ecf20Sopenharmony_ci * cannot be started for some reason. In that case the buffers should be
6968c2ecf20Sopenharmony_ci * returned with state QUEUED to put them back into the queue.
6978c2ecf20Sopenharmony_ci */
6988c2ecf20Sopenharmony_civoid vb2_buffer_done(struct vb2_buffer *vb, enum vb2_buffer_state state);
6998c2ecf20Sopenharmony_ci
7008c2ecf20Sopenharmony_ci/**
7018c2ecf20Sopenharmony_ci * vb2_discard_done() - discard all buffers marked as DONE.
7028c2ecf20Sopenharmony_ci * @q:		pointer to &struct vb2_queue with videobuf2 queue.
7038c2ecf20Sopenharmony_ci *
7048c2ecf20Sopenharmony_ci * This function is intended to be used with suspend/resume operations. It
7058c2ecf20Sopenharmony_ci * discards all 'done' buffers as they would be too old to be requested after
7068c2ecf20Sopenharmony_ci * resume.
7078c2ecf20Sopenharmony_ci *
7088c2ecf20Sopenharmony_ci * Drivers must stop the hardware and synchronize with interrupt handlers and/or
7098c2ecf20Sopenharmony_ci * delayed works before calling this function to make sure no buffer will be
7108c2ecf20Sopenharmony_ci * touched by the driver and/or hardware.
7118c2ecf20Sopenharmony_ci */
7128c2ecf20Sopenharmony_civoid vb2_discard_done(struct vb2_queue *q);
7138c2ecf20Sopenharmony_ci
7148c2ecf20Sopenharmony_ci/**
7158c2ecf20Sopenharmony_ci * vb2_wait_for_all_buffers() - wait until all buffers are given back to vb2.
7168c2ecf20Sopenharmony_ci * @q:		pointer to &struct vb2_queue with videobuf2 queue.
7178c2ecf20Sopenharmony_ci *
7188c2ecf20Sopenharmony_ci * This function will wait until all buffers that have been given to the driver
7198c2ecf20Sopenharmony_ci * by &vb2_ops->buf_queue are given back to vb2 with vb2_buffer_done(). It
7208c2ecf20Sopenharmony_ci * doesn't call &vb2_ops->wait_prepare/&vb2_ops->wait_finish pair.
7218c2ecf20Sopenharmony_ci * It is intended to be called with all locks taken, for example from
7228c2ecf20Sopenharmony_ci * &vb2_ops->stop_streaming callback.
7238c2ecf20Sopenharmony_ci */
7248c2ecf20Sopenharmony_ciint vb2_wait_for_all_buffers(struct vb2_queue *q);
7258c2ecf20Sopenharmony_ci
7268c2ecf20Sopenharmony_ci/**
7278c2ecf20Sopenharmony_ci * vb2_core_querybuf() - query video buffer information.
7288c2ecf20Sopenharmony_ci * @q:		pointer to &struct vb2_queue with videobuf2 queue.
7298c2ecf20Sopenharmony_ci * @index:	id number of the buffer.
7308c2ecf20Sopenharmony_ci * @pb:		buffer struct passed from userspace.
7318c2ecf20Sopenharmony_ci *
7328c2ecf20Sopenharmony_ci * Videobuf2 core helper to implement VIDIOC_QUERYBUF() operation. It is called
7338c2ecf20Sopenharmony_ci * internally by VB2 by an API-specific handler, like ``videobuf2-v4l2.h``.
7348c2ecf20Sopenharmony_ci *
7358c2ecf20Sopenharmony_ci * The passed buffer should have been verified.
7368c2ecf20Sopenharmony_ci *
7378c2ecf20Sopenharmony_ci * This function fills the relevant information for the userspace.
7388c2ecf20Sopenharmony_ci *
7398c2ecf20Sopenharmony_ci * Return: returns zero on success; an error code otherwise.
7408c2ecf20Sopenharmony_ci */
7418c2ecf20Sopenharmony_civoid vb2_core_querybuf(struct vb2_queue *q, unsigned int index, void *pb);
7428c2ecf20Sopenharmony_ci
7438c2ecf20Sopenharmony_ci/**
7448c2ecf20Sopenharmony_ci * vb2_core_reqbufs() - Initiate streaming.
7458c2ecf20Sopenharmony_ci * @q:		pointer to &struct vb2_queue with videobuf2 queue.
7468c2ecf20Sopenharmony_ci * @memory:	memory type, as defined by &enum vb2_memory.
7478c2ecf20Sopenharmony_ci * @count:	requested buffer count.
7488c2ecf20Sopenharmony_ci *
7498c2ecf20Sopenharmony_ci * Videobuf2 core helper to implement VIDIOC_REQBUF() operation. It is called
7508c2ecf20Sopenharmony_ci * internally by VB2 by an API-specific handler, like ``videobuf2-v4l2.h``.
7518c2ecf20Sopenharmony_ci *
7528c2ecf20Sopenharmony_ci * This function:
7538c2ecf20Sopenharmony_ci *
7548c2ecf20Sopenharmony_ci * #) verifies streaming parameters passed from the userspace;
7558c2ecf20Sopenharmony_ci * #) sets up the queue;
7568c2ecf20Sopenharmony_ci * #) negotiates number of buffers and planes per buffer with the driver
7578c2ecf20Sopenharmony_ci *    to be used during streaming;
7588c2ecf20Sopenharmony_ci * #) allocates internal buffer structures (&struct vb2_buffer), according to
7598c2ecf20Sopenharmony_ci *    the agreed parameters;
7608c2ecf20Sopenharmony_ci * #) for MMAP memory type, allocates actual video memory, using the
7618c2ecf20Sopenharmony_ci *    memory handling/allocation routines provided during queue initialization.
7628c2ecf20Sopenharmony_ci *
7638c2ecf20Sopenharmony_ci * If req->count is 0, all the memory will be freed instead.
7648c2ecf20Sopenharmony_ci *
7658c2ecf20Sopenharmony_ci * If the queue has been allocated previously by a previous vb2_core_reqbufs()
7668c2ecf20Sopenharmony_ci * call and the queue is not busy, memory will be reallocated.
7678c2ecf20Sopenharmony_ci *
7688c2ecf20Sopenharmony_ci * Return: returns zero on success; an error code otherwise.
7698c2ecf20Sopenharmony_ci */
7708c2ecf20Sopenharmony_ciint vb2_core_reqbufs(struct vb2_queue *q, enum vb2_memory memory,
7718c2ecf20Sopenharmony_ci		    unsigned int *count);
7728c2ecf20Sopenharmony_ci
7738c2ecf20Sopenharmony_ci/**
7748c2ecf20Sopenharmony_ci * vb2_core_create_bufs() - Allocate buffers and any required auxiliary structs
7758c2ecf20Sopenharmony_ci * @q: pointer to &struct vb2_queue with videobuf2 queue.
7768c2ecf20Sopenharmony_ci * @memory: memory type, as defined by &enum vb2_memory.
7778c2ecf20Sopenharmony_ci * @count: requested buffer count.
7788c2ecf20Sopenharmony_ci * @requested_planes: number of planes requested.
7798c2ecf20Sopenharmony_ci * @requested_sizes: array with the size of the planes.
7808c2ecf20Sopenharmony_ci *
7818c2ecf20Sopenharmony_ci * Videobuf2 core helper to implement VIDIOC_CREATE_BUFS() operation. It is
7828c2ecf20Sopenharmony_ci * called internally by VB2 by an API-specific handler, like
7838c2ecf20Sopenharmony_ci * ``videobuf2-v4l2.h``.
7848c2ecf20Sopenharmony_ci *
7858c2ecf20Sopenharmony_ci * This function:
7868c2ecf20Sopenharmony_ci *
7878c2ecf20Sopenharmony_ci * #) verifies parameter sanity;
7888c2ecf20Sopenharmony_ci * #) calls the &vb2_ops->queue_setup queue operation;
7898c2ecf20Sopenharmony_ci * #) performs any necessary memory allocations.
7908c2ecf20Sopenharmony_ci *
7918c2ecf20Sopenharmony_ci * Return: returns zero on success; an error code otherwise.
7928c2ecf20Sopenharmony_ci */
7938c2ecf20Sopenharmony_ciint vb2_core_create_bufs(struct vb2_queue *q, enum vb2_memory memory,
7948c2ecf20Sopenharmony_ci			 unsigned int *count,
7958c2ecf20Sopenharmony_ci			 unsigned int requested_planes,
7968c2ecf20Sopenharmony_ci			 const unsigned int requested_sizes[]);
7978c2ecf20Sopenharmony_ci
7988c2ecf20Sopenharmony_ci/**
7998c2ecf20Sopenharmony_ci * vb2_core_prepare_buf() - Pass ownership of a buffer from userspace
8008c2ecf20Sopenharmony_ci *			to the kernel.
8018c2ecf20Sopenharmony_ci * @q:		pointer to &struct vb2_queue with videobuf2 queue.
8028c2ecf20Sopenharmony_ci * @index:	id number of the buffer.
8038c2ecf20Sopenharmony_ci * @pb:		buffer structure passed from userspace to
8048c2ecf20Sopenharmony_ci *		&v4l2_ioctl_ops->vidioc_prepare_buf handler in driver.
8058c2ecf20Sopenharmony_ci *
8068c2ecf20Sopenharmony_ci * Videobuf2 core helper to implement VIDIOC_PREPARE_BUF() operation. It is
8078c2ecf20Sopenharmony_ci * called internally by VB2 by an API-specific handler, like
8088c2ecf20Sopenharmony_ci * ``videobuf2-v4l2.h``.
8098c2ecf20Sopenharmony_ci *
8108c2ecf20Sopenharmony_ci * The passed buffer should have been verified.
8118c2ecf20Sopenharmony_ci *
8128c2ecf20Sopenharmony_ci * This function calls vb2_ops->buf_prepare callback in the driver
8138c2ecf20Sopenharmony_ci * (if provided), in which driver-specific buffer initialization can
8148c2ecf20Sopenharmony_ci * be performed.
8158c2ecf20Sopenharmony_ci *
8168c2ecf20Sopenharmony_ci * Return: returns zero on success; an error code otherwise.
8178c2ecf20Sopenharmony_ci */
8188c2ecf20Sopenharmony_ciint vb2_core_prepare_buf(struct vb2_queue *q, unsigned int index, void *pb);
8198c2ecf20Sopenharmony_ci
8208c2ecf20Sopenharmony_ci/**
8218c2ecf20Sopenharmony_ci * vb2_core_qbuf() - Queue a buffer from userspace
8228c2ecf20Sopenharmony_ci *
8238c2ecf20Sopenharmony_ci * @q:		pointer to &struct vb2_queue with videobuf2 queue.
8248c2ecf20Sopenharmony_ci * @index:	id number of the buffer
8258c2ecf20Sopenharmony_ci * @pb:		buffer structure passed from userspace to
8268c2ecf20Sopenharmony_ci *		v4l2_ioctl_ops->vidioc_qbuf handler in driver
8278c2ecf20Sopenharmony_ci * @req:	pointer to &struct media_request, may be NULL.
8288c2ecf20Sopenharmony_ci *
8298c2ecf20Sopenharmony_ci * Videobuf2 core helper to implement VIDIOC_QBUF() operation. It is called
8308c2ecf20Sopenharmony_ci * internally by VB2 by an API-specific handler, like ``videobuf2-v4l2.h``.
8318c2ecf20Sopenharmony_ci *
8328c2ecf20Sopenharmony_ci * This function:
8338c2ecf20Sopenharmony_ci *
8348c2ecf20Sopenharmony_ci * #) If @req is non-NULL, then the buffer will be bound to this
8358c2ecf20Sopenharmony_ci *    media request and it returns. The buffer will be prepared and
8368c2ecf20Sopenharmony_ci *    queued to the driver (i.e. the next two steps) when the request
8378c2ecf20Sopenharmony_ci *    itself is queued.
8388c2ecf20Sopenharmony_ci * #) if necessary, calls &vb2_ops->buf_prepare callback in the driver
8398c2ecf20Sopenharmony_ci *    (if provided), in which driver-specific buffer initialization can
8408c2ecf20Sopenharmony_ci *    be performed;
8418c2ecf20Sopenharmony_ci * #) if streaming is on, queues the buffer in driver by the means of
8428c2ecf20Sopenharmony_ci *    &vb2_ops->buf_queue callback for processing.
8438c2ecf20Sopenharmony_ci *
8448c2ecf20Sopenharmony_ci * Return: returns zero on success; an error code otherwise.
8458c2ecf20Sopenharmony_ci */
8468c2ecf20Sopenharmony_ciint vb2_core_qbuf(struct vb2_queue *q, unsigned int index, void *pb,
8478c2ecf20Sopenharmony_ci		  struct media_request *req);
8488c2ecf20Sopenharmony_ci
8498c2ecf20Sopenharmony_ci/**
8508c2ecf20Sopenharmony_ci * vb2_core_dqbuf() - Dequeue a buffer to the userspace
8518c2ecf20Sopenharmony_ci * @q:		pointer to &struct vb2_queue with videobuf2 queue
8528c2ecf20Sopenharmony_ci * @pindex:	pointer to the buffer index. May be NULL
8538c2ecf20Sopenharmony_ci * @pb:		buffer structure passed from userspace to
8548c2ecf20Sopenharmony_ci *		v4l2_ioctl_ops->vidioc_dqbuf handler in driver.
8558c2ecf20Sopenharmony_ci * @nonblocking: if true, this call will not sleep waiting for a buffer if no
8568c2ecf20Sopenharmony_ci *		 buffers ready for dequeuing are present. Normally the driver
8578c2ecf20Sopenharmony_ci *		 would be passing (file->f_flags & O_NONBLOCK) here.
8588c2ecf20Sopenharmony_ci *
8598c2ecf20Sopenharmony_ci * Videobuf2 core helper to implement VIDIOC_DQBUF() operation. It is called
8608c2ecf20Sopenharmony_ci * internally by VB2 by an API-specific handler, like ``videobuf2-v4l2.h``.
8618c2ecf20Sopenharmony_ci *
8628c2ecf20Sopenharmony_ci * This function:
8638c2ecf20Sopenharmony_ci *
8648c2ecf20Sopenharmony_ci * #) calls buf_finish callback in the driver (if provided), in which
8658c2ecf20Sopenharmony_ci *    driver can perform any additional operations that may be required before
8668c2ecf20Sopenharmony_ci *    returning the buffer to userspace, such as cache sync,
8678c2ecf20Sopenharmony_ci * #) the buffer struct members are filled with relevant information for
8688c2ecf20Sopenharmony_ci *    the userspace.
8698c2ecf20Sopenharmony_ci *
8708c2ecf20Sopenharmony_ci * Return: returns zero on success; an error code otherwise.
8718c2ecf20Sopenharmony_ci */
8728c2ecf20Sopenharmony_ciint vb2_core_dqbuf(struct vb2_queue *q, unsigned int *pindex, void *pb,
8738c2ecf20Sopenharmony_ci		   bool nonblocking);
8748c2ecf20Sopenharmony_ci
8758c2ecf20Sopenharmony_ci/**
8768c2ecf20Sopenharmony_ci * vb2_core_streamon() - Implements VB2 stream ON logic
8778c2ecf20Sopenharmony_ci *
8788c2ecf20Sopenharmony_ci * @q:		pointer to &struct vb2_queue with videobuf2 queue
8798c2ecf20Sopenharmony_ci * @type:	type of the queue to be started.
8808c2ecf20Sopenharmony_ci *		For V4L2, this is defined by &enum v4l2_buf_type type.
8818c2ecf20Sopenharmony_ci *
8828c2ecf20Sopenharmony_ci * Videobuf2 core helper to implement VIDIOC_STREAMON() operation. It is called
8838c2ecf20Sopenharmony_ci * internally by VB2 by an API-specific handler, like ``videobuf2-v4l2.h``.
8848c2ecf20Sopenharmony_ci *
8858c2ecf20Sopenharmony_ci * Return: returns zero on success; an error code otherwise.
8868c2ecf20Sopenharmony_ci */
8878c2ecf20Sopenharmony_ciint vb2_core_streamon(struct vb2_queue *q, unsigned int type);
8888c2ecf20Sopenharmony_ci
8898c2ecf20Sopenharmony_ci/**
8908c2ecf20Sopenharmony_ci * vb2_core_streamoff() - Implements VB2 stream OFF logic
8918c2ecf20Sopenharmony_ci *
8928c2ecf20Sopenharmony_ci * @q:		pointer to &struct vb2_queue with videobuf2 queue
8938c2ecf20Sopenharmony_ci * @type:	type of the queue to be started.
8948c2ecf20Sopenharmony_ci *		For V4L2, this is defined by &enum v4l2_buf_type type.
8958c2ecf20Sopenharmony_ci *
8968c2ecf20Sopenharmony_ci * Videobuf2 core helper to implement VIDIOC_STREAMOFF() operation. It is
8978c2ecf20Sopenharmony_ci * called internally by VB2 by an API-specific handler, like
8988c2ecf20Sopenharmony_ci * ``videobuf2-v4l2.h``.
8998c2ecf20Sopenharmony_ci *
9008c2ecf20Sopenharmony_ci * Return: returns zero on success; an error code otherwise.
9018c2ecf20Sopenharmony_ci */
9028c2ecf20Sopenharmony_ciint vb2_core_streamoff(struct vb2_queue *q, unsigned int type);
9038c2ecf20Sopenharmony_ci
9048c2ecf20Sopenharmony_ci/**
9058c2ecf20Sopenharmony_ci * vb2_core_expbuf() - Export a buffer as a file descriptor.
9068c2ecf20Sopenharmony_ci * @q:		pointer to &struct vb2_queue with videobuf2 queue.
9078c2ecf20Sopenharmony_ci * @fd:		pointer to the file descriptor associated with DMABUF
9088c2ecf20Sopenharmony_ci *		(set by driver).
9098c2ecf20Sopenharmony_ci * @type:	buffer type.
9108c2ecf20Sopenharmony_ci * @index:	id number of the buffer.
9118c2ecf20Sopenharmony_ci * @plane:	index of the plane to be exported, 0 for single plane queues
9128c2ecf20Sopenharmony_ci * @flags:	file flags for newly created file, as defined at
9138c2ecf20Sopenharmony_ci *		include/uapi/asm-generic/fcntl.h.
9148c2ecf20Sopenharmony_ci *		Currently, the only used flag is %O_CLOEXEC.
9158c2ecf20Sopenharmony_ci *		is supported, refer to manual of open syscall for more details.
9168c2ecf20Sopenharmony_ci *
9178c2ecf20Sopenharmony_ci *
9188c2ecf20Sopenharmony_ci * Videobuf2 core helper to implement VIDIOC_EXPBUF() operation. It is called
9198c2ecf20Sopenharmony_ci * internally by VB2 by an API-specific handler, like ``videobuf2-v4l2.h``.
9208c2ecf20Sopenharmony_ci *
9218c2ecf20Sopenharmony_ci * Return: returns zero on success; an error code otherwise.
9228c2ecf20Sopenharmony_ci */
9238c2ecf20Sopenharmony_ciint vb2_core_expbuf(struct vb2_queue *q, int *fd, unsigned int type,
9248c2ecf20Sopenharmony_ci		unsigned int index, unsigned int plane, unsigned int flags);
9258c2ecf20Sopenharmony_ci
9268c2ecf20Sopenharmony_ci/**
9278c2ecf20Sopenharmony_ci * vb2_core_queue_init() - initialize a videobuf2 queue
9288c2ecf20Sopenharmony_ci * @q:		pointer to &struct vb2_queue with videobuf2 queue.
9298c2ecf20Sopenharmony_ci *		This structure should be allocated in driver
9308c2ecf20Sopenharmony_ci *
9318c2ecf20Sopenharmony_ci * The &vb2_queue structure should be allocated by the driver. The driver is
9328c2ecf20Sopenharmony_ci * responsible of clearing it's content and setting initial values for some
9338c2ecf20Sopenharmony_ci * required entries before calling this function.
9348c2ecf20Sopenharmony_ci *
9358c2ecf20Sopenharmony_ci * .. note::
9368c2ecf20Sopenharmony_ci *
9378c2ecf20Sopenharmony_ci *    The following fields at @q should be set before calling this function:
9388c2ecf20Sopenharmony_ci *    &vb2_queue->ops, &vb2_queue->mem_ops, &vb2_queue->type.
9398c2ecf20Sopenharmony_ci */
9408c2ecf20Sopenharmony_ciint vb2_core_queue_init(struct vb2_queue *q);
9418c2ecf20Sopenharmony_ci
9428c2ecf20Sopenharmony_ci/**
9438c2ecf20Sopenharmony_ci * vb2_core_queue_release() - stop streaming, release the queue and free memory
9448c2ecf20Sopenharmony_ci * @q:		pointer to &struct vb2_queue with videobuf2 queue.
9458c2ecf20Sopenharmony_ci *
9468c2ecf20Sopenharmony_ci * This function stops streaming and performs necessary clean ups, including
9478c2ecf20Sopenharmony_ci * freeing video buffer memory. The driver is responsible for freeing
9488c2ecf20Sopenharmony_ci * the &struct vb2_queue itself.
9498c2ecf20Sopenharmony_ci */
9508c2ecf20Sopenharmony_civoid vb2_core_queue_release(struct vb2_queue *q);
9518c2ecf20Sopenharmony_ci
9528c2ecf20Sopenharmony_ci/**
9538c2ecf20Sopenharmony_ci * vb2_queue_error() - signal a fatal error on the queue
9548c2ecf20Sopenharmony_ci * @q:		pointer to &struct vb2_queue with videobuf2 queue.
9558c2ecf20Sopenharmony_ci *
9568c2ecf20Sopenharmony_ci * Flag that a fatal unrecoverable error has occurred and wake up all processes
9578c2ecf20Sopenharmony_ci * waiting on the queue. Polling will now set %EPOLLERR and queuing and dequeuing
9588c2ecf20Sopenharmony_ci * buffers will return %-EIO.
9598c2ecf20Sopenharmony_ci *
9608c2ecf20Sopenharmony_ci * The error flag will be cleared when canceling the queue, either from
9618c2ecf20Sopenharmony_ci * vb2_streamoff() or vb2_queue_release(). Drivers should thus not call this
9628c2ecf20Sopenharmony_ci * function before starting the stream, otherwise the error flag will remain set
9638c2ecf20Sopenharmony_ci * until the queue is released when closing the device node.
9648c2ecf20Sopenharmony_ci */
9658c2ecf20Sopenharmony_civoid vb2_queue_error(struct vb2_queue *q);
9668c2ecf20Sopenharmony_ci
9678c2ecf20Sopenharmony_ci/**
9688c2ecf20Sopenharmony_ci * vb2_mmap() - map video buffers into application address space.
9698c2ecf20Sopenharmony_ci * @q:		pointer to &struct vb2_queue with videobuf2 queue.
9708c2ecf20Sopenharmony_ci * @vma:	pointer to &struct vm_area_struct with the vma passed
9718c2ecf20Sopenharmony_ci *		to the mmap file operation handler in the driver.
9728c2ecf20Sopenharmony_ci *
9738c2ecf20Sopenharmony_ci * Should be called from mmap file operation handler of a driver.
9748c2ecf20Sopenharmony_ci * This function maps one plane of one of the available video buffers to
9758c2ecf20Sopenharmony_ci * userspace. To map whole video memory allocated on reqbufs, this function
9768c2ecf20Sopenharmony_ci * has to be called once per each plane per each buffer previously allocated.
9778c2ecf20Sopenharmony_ci *
9788c2ecf20Sopenharmony_ci * When the userspace application calls mmap, it passes to it an offset returned
9798c2ecf20Sopenharmony_ci * to it earlier by the means of &v4l2_ioctl_ops->vidioc_querybuf handler.
9808c2ecf20Sopenharmony_ci * That offset acts as a "cookie", which is then used to identify the plane
9818c2ecf20Sopenharmony_ci * to be mapped.
9828c2ecf20Sopenharmony_ci *
9838c2ecf20Sopenharmony_ci * This function finds a plane with a matching offset and a mapping is performed
9848c2ecf20Sopenharmony_ci * by the means of a provided memory operation.
9858c2ecf20Sopenharmony_ci *
9868c2ecf20Sopenharmony_ci * The return values from this function are intended to be directly returned
9878c2ecf20Sopenharmony_ci * from the mmap handler in driver.
9888c2ecf20Sopenharmony_ci */
9898c2ecf20Sopenharmony_ciint vb2_mmap(struct vb2_queue *q, struct vm_area_struct *vma);
9908c2ecf20Sopenharmony_ci
9918c2ecf20Sopenharmony_ci#ifndef CONFIG_MMU
9928c2ecf20Sopenharmony_ci/**
9938c2ecf20Sopenharmony_ci * vb2_get_unmapped_area - map video buffers into application address space.
9948c2ecf20Sopenharmony_ci * @q:		pointer to &struct vb2_queue with videobuf2 queue.
9958c2ecf20Sopenharmony_ci * @addr:	memory address.
9968c2ecf20Sopenharmony_ci * @len:	buffer size.
9978c2ecf20Sopenharmony_ci * @pgoff:	page offset.
9988c2ecf20Sopenharmony_ci * @flags:	memory flags.
9998c2ecf20Sopenharmony_ci *
10008c2ecf20Sopenharmony_ci * This function is used in noMMU platforms to propose address mapping
10018c2ecf20Sopenharmony_ci * for a given buffer. It's intended to be used as a handler for the
10028c2ecf20Sopenharmony_ci * &file_operations->get_unmapped_area operation.
10038c2ecf20Sopenharmony_ci *
10048c2ecf20Sopenharmony_ci * This is called by the mmap() syscall routines will call this
10058c2ecf20Sopenharmony_ci * to get a proposed address for the mapping, when ``!CONFIG_MMU``.
10068c2ecf20Sopenharmony_ci */
10078c2ecf20Sopenharmony_ciunsigned long vb2_get_unmapped_area(struct vb2_queue *q,
10088c2ecf20Sopenharmony_ci				    unsigned long addr,
10098c2ecf20Sopenharmony_ci				    unsigned long len,
10108c2ecf20Sopenharmony_ci				    unsigned long pgoff,
10118c2ecf20Sopenharmony_ci				    unsigned long flags);
10128c2ecf20Sopenharmony_ci#endif
10138c2ecf20Sopenharmony_ci
10148c2ecf20Sopenharmony_ci/**
10158c2ecf20Sopenharmony_ci * vb2_core_poll() - implements poll syscall() logic.
10168c2ecf20Sopenharmony_ci * @q:		pointer to &struct vb2_queue with videobuf2 queue.
10178c2ecf20Sopenharmony_ci * @file:	&struct file argument passed to the poll
10188c2ecf20Sopenharmony_ci *		file operation handler.
10198c2ecf20Sopenharmony_ci * @wait:	&poll_table wait argument passed to the poll
10208c2ecf20Sopenharmony_ci *		file operation handler.
10218c2ecf20Sopenharmony_ci *
10228c2ecf20Sopenharmony_ci * This function implements poll file operation handler for a driver.
10238c2ecf20Sopenharmony_ci * For CAPTURE queues, if a buffer is ready to be dequeued, the userspace will
10248c2ecf20Sopenharmony_ci * be informed that the file descriptor of a video device is available for
10258c2ecf20Sopenharmony_ci * reading.
10268c2ecf20Sopenharmony_ci * For OUTPUT queues, if a buffer is ready to be dequeued, the file descriptor
10278c2ecf20Sopenharmony_ci * will be reported as available for writing.
10288c2ecf20Sopenharmony_ci *
10298c2ecf20Sopenharmony_ci * The return values from this function are intended to be directly returned
10308c2ecf20Sopenharmony_ci * from poll handler in driver.
10318c2ecf20Sopenharmony_ci */
10328c2ecf20Sopenharmony_ci__poll_t vb2_core_poll(struct vb2_queue *q, struct file *file,
10338c2ecf20Sopenharmony_ci			   poll_table *wait);
10348c2ecf20Sopenharmony_ci
10358c2ecf20Sopenharmony_ci/**
10368c2ecf20Sopenharmony_ci * vb2_read() - implements read() syscall logic.
10378c2ecf20Sopenharmony_ci * @q:		pointer to &struct vb2_queue with videobuf2 queue.
10388c2ecf20Sopenharmony_ci * @data:	pointed to target userspace buffer
10398c2ecf20Sopenharmony_ci * @count:	number of bytes to read
10408c2ecf20Sopenharmony_ci * @ppos:	file handle position tracking pointer
10418c2ecf20Sopenharmony_ci * @nonblock:	mode selector (1 means blocking calls, 0 means nonblocking)
10428c2ecf20Sopenharmony_ci */
10438c2ecf20Sopenharmony_cisize_t vb2_read(struct vb2_queue *q, char __user *data, size_t count,
10448c2ecf20Sopenharmony_ci		loff_t *ppos, int nonblock);
10458c2ecf20Sopenharmony_ci/**
10468c2ecf20Sopenharmony_ci * vb2_read() - implements write() syscall logic.
10478c2ecf20Sopenharmony_ci * @q:		pointer to &struct vb2_queue with videobuf2 queue.
10488c2ecf20Sopenharmony_ci * @data:	pointed to target userspace buffer
10498c2ecf20Sopenharmony_ci * @count:	number of bytes to write
10508c2ecf20Sopenharmony_ci * @ppos:	file handle position tracking pointer
10518c2ecf20Sopenharmony_ci * @nonblock:	mode selector (1 means blocking calls, 0 means nonblocking)
10528c2ecf20Sopenharmony_ci */
10538c2ecf20Sopenharmony_cisize_t vb2_write(struct vb2_queue *q, const char __user *data, size_t count,
10548c2ecf20Sopenharmony_ci		loff_t *ppos, int nonblock);
10558c2ecf20Sopenharmony_ci
10568c2ecf20Sopenharmony_ci/**
10578c2ecf20Sopenharmony_ci * typedef vb2_thread_fnc - callback function for use with vb2_thread.
10588c2ecf20Sopenharmony_ci *
10598c2ecf20Sopenharmony_ci * @vb: pointer to struct &vb2_buffer.
10608c2ecf20Sopenharmony_ci * @priv: pointer to a private data.
10618c2ecf20Sopenharmony_ci *
10628c2ecf20Sopenharmony_ci * This is called whenever a buffer is dequeued in the thread.
10638c2ecf20Sopenharmony_ci */
10648c2ecf20Sopenharmony_citypedef int (*vb2_thread_fnc)(struct vb2_buffer *vb, void *priv);
10658c2ecf20Sopenharmony_ci
10668c2ecf20Sopenharmony_ci/**
10678c2ecf20Sopenharmony_ci * vb2_thread_start() - start a thread for the given queue.
10688c2ecf20Sopenharmony_ci * @q:		pointer to &struct vb2_queue with videobuf2 queue.
10698c2ecf20Sopenharmony_ci * @fnc:	&vb2_thread_fnc callback function.
10708c2ecf20Sopenharmony_ci * @priv:	priv pointer passed to the callback function.
10718c2ecf20Sopenharmony_ci * @thread_name:the name of the thread. This will be prefixed with "vb2-".
10728c2ecf20Sopenharmony_ci *
10738c2ecf20Sopenharmony_ci * This starts a thread that will queue and dequeue until an error occurs
10748c2ecf20Sopenharmony_ci * or vb2_thread_stop() is called.
10758c2ecf20Sopenharmony_ci *
10768c2ecf20Sopenharmony_ci * .. attention::
10778c2ecf20Sopenharmony_ci *
10788c2ecf20Sopenharmony_ci *   This function should not be used for anything else but the videobuf2-dvb
10798c2ecf20Sopenharmony_ci *   support. If you think you have another good use-case for this, then please
10808c2ecf20Sopenharmony_ci *   contact the linux-media mailing list first.
10818c2ecf20Sopenharmony_ci */
10828c2ecf20Sopenharmony_ciint vb2_thread_start(struct vb2_queue *q, vb2_thread_fnc fnc, void *priv,
10838c2ecf20Sopenharmony_ci		     const char *thread_name);
10848c2ecf20Sopenharmony_ci
10858c2ecf20Sopenharmony_ci/**
10868c2ecf20Sopenharmony_ci * vb2_thread_stop() - stop the thread for the given queue.
10878c2ecf20Sopenharmony_ci * @q:		pointer to &struct vb2_queue with videobuf2 queue.
10888c2ecf20Sopenharmony_ci */
10898c2ecf20Sopenharmony_ciint vb2_thread_stop(struct vb2_queue *q);
10908c2ecf20Sopenharmony_ci
10918c2ecf20Sopenharmony_ci/**
10928c2ecf20Sopenharmony_ci * vb2_is_streaming() - return streaming status of the queue.
10938c2ecf20Sopenharmony_ci * @q:		pointer to &struct vb2_queue with videobuf2 queue.
10948c2ecf20Sopenharmony_ci */
10958c2ecf20Sopenharmony_cistatic inline bool vb2_is_streaming(struct vb2_queue *q)
10968c2ecf20Sopenharmony_ci{
10978c2ecf20Sopenharmony_ci	return q->streaming;
10988c2ecf20Sopenharmony_ci}
10998c2ecf20Sopenharmony_ci
11008c2ecf20Sopenharmony_ci/**
11018c2ecf20Sopenharmony_ci * vb2_fileio_is_active() - return true if fileio is active.
11028c2ecf20Sopenharmony_ci * @q:		pointer to &struct vb2_queue with videobuf2 queue.
11038c2ecf20Sopenharmony_ci *
11048c2ecf20Sopenharmony_ci * This returns true if read() or write() is used to stream the data
11058c2ecf20Sopenharmony_ci * as opposed to stream I/O. This is almost never an important distinction,
11068c2ecf20Sopenharmony_ci * except in rare cases. One such case is that using read() or write() to
11078c2ecf20Sopenharmony_ci * stream a format using %V4L2_FIELD_ALTERNATE is not allowed since there
11088c2ecf20Sopenharmony_ci * is no way you can pass the field information of each buffer to/from
11098c2ecf20Sopenharmony_ci * userspace. A driver that supports this field format should check for
11108c2ecf20Sopenharmony_ci * this in the &vb2_ops->queue_setup op and reject it if this function returns
11118c2ecf20Sopenharmony_ci * true.
11128c2ecf20Sopenharmony_ci */
11138c2ecf20Sopenharmony_cistatic inline bool vb2_fileio_is_active(struct vb2_queue *q)
11148c2ecf20Sopenharmony_ci{
11158c2ecf20Sopenharmony_ci	return q->fileio;
11168c2ecf20Sopenharmony_ci}
11178c2ecf20Sopenharmony_ci
11188c2ecf20Sopenharmony_ci/**
11198c2ecf20Sopenharmony_ci * vb2_is_busy() - return busy status of the queue.
11208c2ecf20Sopenharmony_ci * @q:		pointer to &struct vb2_queue with videobuf2 queue.
11218c2ecf20Sopenharmony_ci *
11228c2ecf20Sopenharmony_ci * This function checks if queue has any buffers allocated.
11238c2ecf20Sopenharmony_ci */
11248c2ecf20Sopenharmony_cistatic inline bool vb2_is_busy(struct vb2_queue *q)
11258c2ecf20Sopenharmony_ci{
11268c2ecf20Sopenharmony_ci	return (q->num_buffers > 0);
11278c2ecf20Sopenharmony_ci}
11288c2ecf20Sopenharmony_ci
11298c2ecf20Sopenharmony_ci/**
11308c2ecf20Sopenharmony_ci * vb2_get_drv_priv() - return driver private data associated with the queue.
11318c2ecf20Sopenharmony_ci * @q:		pointer to &struct vb2_queue with videobuf2 queue.
11328c2ecf20Sopenharmony_ci */
11338c2ecf20Sopenharmony_cistatic inline void *vb2_get_drv_priv(struct vb2_queue *q)
11348c2ecf20Sopenharmony_ci{
11358c2ecf20Sopenharmony_ci	return q->drv_priv;
11368c2ecf20Sopenharmony_ci}
11378c2ecf20Sopenharmony_ci
11388c2ecf20Sopenharmony_ci/**
11398c2ecf20Sopenharmony_ci * vb2_set_plane_payload() - set bytesused for the plane @plane_no.
11408c2ecf20Sopenharmony_ci * @vb:		pointer to &struct vb2_buffer to which the plane in
11418c2ecf20Sopenharmony_ci *		question belongs to.
11428c2ecf20Sopenharmony_ci * @plane_no:	plane number for which payload should be set.
11438c2ecf20Sopenharmony_ci * @size:	payload in bytes.
11448c2ecf20Sopenharmony_ci */
11458c2ecf20Sopenharmony_cistatic inline void vb2_set_plane_payload(struct vb2_buffer *vb,
11468c2ecf20Sopenharmony_ci				 unsigned int plane_no, unsigned long size)
11478c2ecf20Sopenharmony_ci{
11488c2ecf20Sopenharmony_ci	if (plane_no < vb->num_planes)
11498c2ecf20Sopenharmony_ci		vb->planes[plane_no].bytesused = size;
11508c2ecf20Sopenharmony_ci}
11518c2ecf20Sopenharmony_ci
11528c2ecf20Sopenharmony_ci/**
11538c2ecf20Sopenharmony_ci * vb2_get_plane_payload() - get bytesused for the plane plane_no
11548c2ecf20Sopenharmony_ci * @vb:		pointer to &struct vb2_buffer to which the plane in
11558c2ecf20Sopenharmony_ci *		question belongs to.
11568c2ecf20Sopenharmony_ci * @plane_no:	plane number for which payload should be set.
11578c2ecf20Sopenharmony_ci */
11588c2ecf20Sopenharmony_cistatic inline unsigned long vb2_get_plane_payload(struct vb2_buffer *vb,
11598c2ecf20Sopenharmony_ci				 unsigned int plane_no)
11608c2ecf20Sopenharmony_ci{
11618c2ecf20Sopenharmony_ci	if (plane_no < vb->num_planes)
11628c2ecf20Sopenharmony_ci		return vb->planes[plane_no].bytesused;
11638c2ecf20Sopenharmony_ci	return 0;
11648c2ecf20Sopenharmony_ci}
11658c2ecf20Sopenharmony_ci
11668c2ecf20Sopenharmony_ci/**
11678c2ecf20Sopenharmony_ci * vb2_plane_size() - return plane size in bytes.
11688c2ecf20Sopenharmony_ci * @vb:		pointer to &struct vb2_buffer to which the plane in
11698c2ecf20Sopenharmony_ci *		question belongs to.
11708c2ecf20Sopenharmony_ci * @plane_no:	plane number for which size should be returned.
11718c2ecf20Sopenharmony_ci */
11728c2ecf20Sopenharmony_cistatic inline unsigned long
11738c2ecf20Sopenharmony_civb2_plane_size(struct vb2_buffer *vb, unsigned int plane_no)
11748c2ecf20Sopenharmony_ci{
11758c2ecf20Sopenharmony_ci	if (plane_no < vb->num_planes)
11768c2ecf20Sopenharmony_ci		return vb->planes[plane_no].length;
11778c2ecf20Sopenharmony_ci	return 0;
11788c2ecf20Sopenharmony_ci}
11798c2ecf20Sopenharmony_ci
11808c2ecf20Sopenharmony_ci/**
11818c2ecf20Sopenharmony_ci * vb2_start_streaming_called() - return streaming status of driver.
11828c2ecf20Sopenharmony_ci * @q:		pointer to &struct vb2_queue with videobuf2 queue.
11838c2ecf20Sopenharmony_ci */
11848c2ecf20Sopenharmony_cistatic inline bool vb2_start_streaming_called(struct vb2_queue *q)
11858c2ecf20Sopenharmony_ci{
11868c2ecf20Sopenharmony_ci	return q->start_streaming_called;
11878c2ecf20Sopenharmony_ci}
11888c2ecf20Sopenharmony_ci
11898c2ecf20Sopenharmony_ci/**
11908c2ecf20Sopenharmony_ci * vb2_clear_last_buffer_dequeued() - clear last buffer dequeued flag of queue.
11918c2ecf20Sopenharmony_ci * @q:		pointer to &struct vb2_queue with videobuf2 queue.
11928c2ecf20Sopenharmony_ci */
11938c2ecf20Sopenharmony_cistatic inline void vb2_clear_last_buffer_dequeued(struct vb2_queue *q)
11948c2ecf20Sopenharmony_ci{
11958c2ecf20Sopenharmony_ci	q->last_buffer_dequeued = false;
11968c2ecf20Sopenharmony_ci}
11978c2ecf20Sopenharmony_ci
11988c2ecf20Sopenharmony_ci/**
11998c2ecf20Sopenharmony_ci * vb2_get_buffer() - get a buffer from a queue
12008c2ecf20Sopenharmony_ci * @q:		pointer to &struct vb2_queue with videobuf2 queue.
12018c2ecf20Sopenharmony_ci * @index:	buffer index
12028c2ecf20Sopenharmony_ci *
12038c2ecf20Sopenharmony_ci * This function obtains a buffer from a queue, by its index.
12048c2ecf20Sopenharmony_ci * Keep in mind that there is no refcounting involved in this
12058c2ecf20Sopenharmony_ci * operation, so the buffer lifetime should be taken into
12068c2ecf20Sopenharmony_ci * consideration.
12078c2ecf20Sopenharmony_ci */
12088c2ecf20Sopenharmony_cistatic inline struct vb2_buffer *vb2_get_buffer(struct vb2_queue *q,
12098c2ecf20Sopenharmony_ci						unsigned int index)
12108c2ecf20Sopenharmony_ci{
12118c2ecf20Sopenharmony_ci	if (index < q->num_buffers)
12128c2ecf20Sopenharmony_ci		return q->bufs[index];
12138c2ecf20Sopenharmony_ci	return NULL;
12148c2ecf20Sopenharmony_ci}
12158c2ecf20Sopenharmony_ci
12168c2ecf20Sopenharmony_ci/*
12178c2ecf20Sopenharmony_ci * The following functions are not part of the vb2 core API, but are useful
12188c2ecf20Sopenharmony_ci * functions for videobuf2-*.
12198c2ecf20Sopenharmony_ci */
12208c2ecf20Sopenharmony_ci
12218c2ecf20Sopenharmony_ci/**
12228c2ecf20Sopenharmony_ci * vb2_buffer_in_use() - return true if the buffer is in use and
12238c2ecf20Sopenharmony_ci * the queue cannot be freed (by the means of VIDIOC_REQBUFS(0)) call.
12248c2ecf20Sopenharmony_ci *
12258c2ecf20Sopenharmony_ci * @vb:		buffer for which plane size should be returned.
12268c2ecf20Sopenharmony_ci * @q:		pointer to &struct vb2_queue with videobuf2 queue.
12278c2ecf20Sopenharmony_ci */
12288c2ecf20Sopenharmony_cibool vb2_buffer_in_use(struct vb2_queue *q, struct vb2_buffer *vb);
12298c2ecf20Sopenharmony_ci
12308c2ecf20Sopenharmony_ci/**
12318c2ecf20Sopenharmony_ci * vb2_verify_memory_type() - Check whether the memory type and buffer type
12328c2ecf20Sopenharmony_ci * passed to a buffer operation are compatible with the queue.
12338c2ecf20Sopenharmony_ci *
12348c2ecf20Sopenharmony_ci * @q:		pointer to &struct vb2_queue with videobuf2 queue.
12358c2ecf20Sopenharmony_ci * @memory:	memory model, as defined by enum &vb2_memory.
12368c2ecf20Sopenharmony_ci * @type:	private buffer type whose content is defined by the vb2-core
12378c2ecf20Sopenharmony_ci *		caller. For example, for V4L2, it should match
12388c2ecf20Sopenharmony_ci *		the types defined on enum &v4l2_buf_type.
12398c2ecf20Sopenharmony_ci */
12408c2ecf20Sopenharmony_ciint vb2_verify_memory_type(struct vb2_queue *q,
12418c2ecf20Sopenharmony_ci		enum vb2_memory memory, unsigned int type);
12428c2ecf20Sopenharmony_ci
12438c2ecf20Sopenharmony_ci/**
12448c2ecf20Sopenharmony_ci * vb2_request_object_is_buffer() - return true if the object is a buffer
12458c2ecf20Sopenharmony_ci *
12468c2ecf20Sopenharmony_ci * @obj:	the request object.
12478c2ecf20Sopenharmony_ci */
12488c2ecf20Sopenharmony_cibool vb2_request_object_is_buffer(struct media_request_object *obj);
12498c2ecf20Sopenharmony_ci
12508c2ecf20Sopenharmony_ci/**
12518c2ecf20Sopenharmony_ci * vb2_request_buffer_cnt() - return the number of buffers in the request
12528c2ecf20Sopenharmony_ci *
12538c2ecf20Sopenharmony_ci * @req:	the request.
12548c2ecf20Sopenharmony_ci */
12558c2ecf20Sopenharmony_ciunsigned int vb2_request_buffer_cnt(struct media_request *req);
12568c2ecf20Sopenharmony_ci
12578c2ecf20Sopenharmony_ci#endif /* _MEDIA_VIDEOBUF2_CORE_H */
1258