linux/drivers/media/common/videobuf2/videobuf2-core.c

/*
 * videobuf2-core.c - video buffer 2 core framework
 *
 * Copyright (C) 2010 Samsung Electronics
 *
 * Author: Pawel Osciak <[email protected]>
 *	   Marek Szyprowski <[email protected]>
 *
 * The vb2_thread implementation was based on code from videobuf-dvb.c:
 *	(c) 2004 Gerd Knorr <[email protected]> [SUSE Labs]
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation.
 */

#define pr_fmt(fmt)

#include <linux/err.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/mm.h>
#include <linux/poll.h>
#include <linux/slab.h>
#include <linux/sched.h>
#include <linux/freezer.h>
#include <linux/kthread.h>

#include <media/videobuf2-core.h>
#include <media/v4l2-mc.h>

#include <trace/events/vb2.h>

#define PLANE_INDEX_BITS
#define PLANE_INDEX_SHIFT
#define PLANE_INDEX_MASK
#define MAX_BUFFER_INDEX
#define BUFFER_INDEX_MASK

#if BIT(PLANE_INDEX_BITS) != VIDEO_MAX_PLANES
#error PLANE_INDEX_BITS order must be equal to VIDEO_MAX_PLANES
#endif

static int debug;
module_param(debug, int, 0644);

#define dprintk(q, level, fmt, arg...)

#ifdef CONFIG_VIDEO_ADV_DEBUG

/*
 * If advanced debugging is on, then count how often each op is called
 * successfully, which can either be per-buffer or per-queue.
 *
 * This makes it easy to check that the 'init' and 'cleanup'
 * (and variations thereof) stay balanced.
 */

#define log_memop(vb, op)

#define call_memop(vb, op, args...)

#define call_ptr_memop(op, vb, args...)

#define call_void_memop(vb, op, args...)

#define log_qop(q, op)

#define call_qop(q, op, args...)

#define call_void_qop(q, op, args...)

#define log_vb_qop(vb, op, args...)

#define call_vb_qop(vb, op, args...)

#define call_void_vb_qop(vb, op, args...)

#else

#define call_memop

#define call_ptr_memop

#define call_void_memop

#define call_qop

#define call_void_qop

#define call_vb_qop

#define call_void_vb_qop

#endif

#define call_bufop(q, op, args...)

#define call_void_bufop(q, op, args...)

static void __vb2_queue_cancel(struct vb2_queue *q);

static const char *vb2_state_name(enum vb2_buffer_state s)
{}

/*
 * __vb2_buf_mem_alloc() - allocate video memory for the given buffer
 */
static int __vb2_buf_mem_alloc(struct vb2_buffer *vb)
{}

/*
 * __vb2_buf_mem_free() - free memory of the given buffer
 */
static void __vb2_buf_mem_free(struct vb2_buffer *vb)
{}

/*
 * __vb2_buf_userptr_put() - release userspace memory associated with
 * a USERPTR buffer
 */
static void __vb2_buf_userptr_put(struct vb2_buffer *vb)
{}

/*
 * __vb2_plane_dmabuf_put() - release memory associated with
 * a DMABUF shared plane
 */
static void __vb2_plane_dmabuf_put(struct vb2_buffer *vb, struct vb2_plane *p)
{}

/*
 * __vb2_buf_dmabuf_put() - release memory associated with
 * a DMABUF shared buffer
 */
static void __vb2_buf_dmabuf_put(struct vb2_buffer *vb)
{}

/*
 * __vb2_buf_mem_prepare() - call ->prepare() on buffer's private memory
 * to sync caches
 */
static void __vb2_buf_mem_prepare(struct vb2_buffer *vb)
{}

/*
 * __vb2_buf_mem_finish() - call ->finish on buffer's private memory
 * to sync caches
 */
static void __vb2_buf_mem_finish(struct vb2_buffer *vb)
{}

/*
 * __setup_offsets() - setup unique offsets ("cookies") for every plane in
 * the buffer.
 */
static void __setup_offsets(struct vb2_buffer *vb)
{}

static void init_buffer_cache_hints(struct vb2_queue *q, struct vb2_buffer *vb)
{}

/**
 * vb2_queue_add_buffer() - add a buffer to a queue
 * @q:	pointer to &struct vb2_queue with videobuf2 queue.
 * @vb:	pointer to &struct vb2_buffer to be added to the queue.
 * @index: index where add vb2_buffer in the queue
 */
static void vb2_queue_add_buffer(struct vb2_queue *q, struct vb2_buffer *vb, unsigned int index)
{}

/**
 * vb2_queue_remove_buffer() - remove a buffer from a queue
 * @vb:	pointer to &struct vb2_buffer to be removed from the queue.
 */
static void vb2_queue_remove_buffer(struct vb2_buffer *vb)
{}

/*
 * __vb2_queue_alloc() - allocate vb2 buffer structures and (for MMAP type)
 * video buffer memory for all buffers/planes on the queue and initializes the
 * queue
 * @first_index: index of the first created buffer, all newly allocated buffers
 *		 have indices in the range [first_index..first_index+count-1]
 *
 * Returns the number of buffers successfully allocated.
 */
static int __vb2_queue_alloc(struct vb2_queue *q, enum vb2_memory memory,
			     unsigned int num_buffers, unsigned int num_planes,
			     const unsigned int plane_sizes[VB2_MAX_PLANES],
			     unsigned int *first_index)
{}

/*
 * __vb2_free_mem() - release video buffer memory for a given range of
 * buffers in a given queue
 */
static void __vb2_free_mem(struct vb2_queue *q, unsigned int start, unsigned int count)
{}

/*
 * __vb2_queue_free() - free @count buffers from @start index of the queue - video memory and
 * related information, if no buffers are left return the queue to an
 * uninitialized state. Might be called even if the queue has already been freed.
 */
static void __vb2_queue_free(struct vb2_queue *q, unsigned int start, unsigned int count)
{}

bool vb2_buffer_in_use(struct vb2_queue *q, struct vb2_buffer *vb)
{}
EXPORT_SYMBOL();

/*
 * __buffers_in_use() - return true if any buffers on the queue are in use and
 * the queue cannot be freed (by the means of REQBUFS(0)) call
 */
static bool __buffers_in_use(struct vb2_queue *q)
{}

void vb2_core_querybuf(struct vb2_queue *q, struct vb2_buffer *vb, void *pb)
{}
EXPORT_SYMBOL_GPL();

/*
 * __verify_userptr_ops() - verify that all memory operations required for
 * USERPTR queue type have been provided
 */
static int __verify_userptr_ops(struct vb2_queue *q)
{}

/*
 * __verify_mmap_ops() - verify that all memory operations required for
 * MMAP queue type have been provided
 */
static int __verify_mmap_ops(struct vb2_queue *q)
{}

/*
 * __verify_dmabuf_ops() - verify that all memory operations required for
 * DMABUF queue type have been provided
 */
static int __verify_dmabuf_ops(struct vb2_queue *q)
{}

int vb2_verify_memory_type(struct vb2_queue *q,
		enum vb2_memory memory, unsigned int type)
{}
EXPORT_SYMBOL();

static void set_queue_coherency(struct vb2_queue *q, bool non_coherent_mem)
{}

static bool verify_coherency_flags(struct vb2_queue *q, bool non_coherent_mem)
{}

static int vb2_core_allocated_buffers_storage(struct vb2_queue *q)
{}

static void vb2_core_free_buffers_storage(struct vb2_queue *q)
{}

int vb2_core_reqbufs(struct vb2_queue *q, enum vb2_memory memory,
		     unsigned int flags, unsigned int *count)
{}
EXPORT_SYMBOL_GPL();

int vb2_core_create_bufs(struct vb2_queue *q, enum vb2_memory memory,
			 unsigned int flags, unsigned int *count,
			 unsigned int requested_planes,
			 const unsigned int requested_sizes[],
			 unsigned int *first_index)
{}
EXPORT_SYMBOL_GPL();

void *vb2_plane_vaddr(struct vb2_buffer *vb, unsigned int plane_no)
{}
EXPORT_SYMBOL_GPL();

void *vb2_plane_cookie(struct vb2_buffer *vb, unsigned int plane_no)
{}
EXPORT_SYMBOL_GPL();

void vb2_buffer_done(struct vb2_buffer *vb, enum vb2_buffer_state state)
{}
EXPORT_SYMBOL_GPL();

void vb2_discard_done(struct vb2_queue *q)
{}
EXPORT_SYMBOL_GPL();

/*
 * __prepare_mmap() - prepare an MMAP buffer
 */
static int __prepare_mmap(struct vb2_buffer *vb)
{}

/*
 * __prepare_userptr() - prepare a USERPTR buffer
 */
static int __prepare_userptr(struct vb2_buffer *vb)
{}

/*
 * __prepare_dmabuf() - prepare a DMABUF buffer
 */
static int __prepare_dmabuf(struct vb2_buffer *vb)
{}

/*
 * __enqueue_in_driver() - enqueue a vb2_buffer in driver for processing
 */
static void __enqueue_in_driver(struct vb2_buffer *vb)
{}

static int __buf_prepare(struct vb2_buffer *vb)
{}

static int vb2_req_prepare(struct media_request_object *obj)
{}

static void __vb2_dqbuf(struct vb2_buffer *vb);

static void vb2_req_unprepare(struct media_request_object *obj)
{}

static void vb2_req_queue(struct media_request_object *obj)
{}

static void vb2_req_unbind(struct media_request_object *obj)
{}

static void vb2_req_release(struct media_request_object *obj)
{}

static const struct media_request_object_ops vb2_core_req_ops =;

bool vb2_request_object_is_buffer(struct media_request_object *obj)
{}
EXPORT_SYMBOL_GPL();

unsigned int vb2_request_buffer_cnt(struct media_request *req)
{}
EXPORT_SYMBOL_GPL();

int vb2_core_prepare_buf(struct vb2_queue *q, struct vb2_buffer *vb, void *pb)
{}
EXPORT_SYMBOL_GPL();

int vb2_core_remove_bufs(struct vb2_queue *q, unsigned int start, unsigned int count)
{}
EXPORT_SYMBOL_GPL();

/*
 * vb2_start_streaming() - Attempt to start streaming.
 * @q:		videobuf2 queue
 *
 * Attempt to start streaming. When this function is called there must be
 * at least q->min_queued_buffers queued up (i.e. the minimum
 * number of buffers required for the DMA engine to function). If the
 * @start_streaming op fails it is supposed to return all the driver-owned
 * buffers back to vb2 in state QUEUED. Check if that happened and if
 * not warn and reclaim them forcefully.
 */
static int vb2_start_streaming(struct vb2_queue *q)
{}

int vb2_core_qbuf(struct vb2_queue *q, struct vb2_buffer *vb, void *pb,
		  struct media_request *req)
{}
EXPORT_SYMBOL_GPL();

/*
 * __vb2_wait_for_done_vb() - wait for a buffer to become available
 * for dequeuing
 *
 * Will sleep if required for nonblocking == false.
 */
static int __vb2_wait_for_done_vb(struct vb2_queue *q, int nonblocking)
{}

/*
 * __vb2_get_done_vb() - get a buffer ready for dequeuing
 *
 * Will sleep if required for nonblocking == false.
 */
static int __vb2_get_done_vb(struct vb2_queue *q, struct vb2_buffer **vb,
			     void *pb, int nonblocking)
{}

int vb2_wait_for_all_buffers(struct vb2_queue *q)
{}
EXPORT_SYMBOL_GPL();

/*
 * __vb2_dqbuf() - bring back the buffer to the DEQUEUED state
 */
static void __vb2_dqbuf(struct vb2_buffer *vb)
{}

int vb2_core_dqbuf(struct vb2_queue *q, unsigned int *pindex, void *pb,
		   bool nonblocking)
{}
EXPORT_SYMBOL_GPL();

/*
 * __vb2_queue_cancel() - cancel and stop (pause) streaming
 *
 * Removes all queued buffers from driver's queue and all buffers queued by
 * userspace from vb2's queue. Returns to state after reqbufs.
 */
static void __vb2_queue_cancel(struct vb2_queue *q)
{}

int vb2_core_streamon(struct vb2_queue *q, unsigned int type)
{}
EXPORT_SYMBOL_GPL();

void vb2_queue_error(struct vb2_queue *q)
{}
EXPORT_SYMBOL_GPL();

int vb2_core_streamoff(struct vb2_queue *q, unsigned int type)
{}
EXPORT_SYMBOL_GPL();

/*
 * __find_plane_by_offset() - find plane associated with the given offset
 */
static int __find_plane_by_offset(struct vb2_queue *q, unsigned long offset,
			struct vb2_buffer **vb, unsigned int *plane)
{}

int vb2_core_expbuf(struct vb2_queue *q, int *fd, unsigned int type,
		    struct vb2_buffer *vb, unsigned int plane, unsigned int flags)
{}
EXPORT_SYMBOL_GPL();

int vb2_mmap(struct vb2_queue *q, struct vm_area_struct *vma)
{}
EXPORT_SYMBOL_GPL();

#ifndef CONFIG_MMU
unsigned long vb2_get_unmapped_area(struct vb2_queue *q,
				    unsigned long addr,
				    unsigned long len,
				    unsigned long pgoff,
				    unsigned long flags)
{
	unsigned long offset = pgoff << PAGE_SHIFT;
	struct vb2_buffer *vb;
	unsigned int plane;
	void *vaddr;
	int ret;

	mutex_lock(&q->mmap_lock);

	/*
	 * Find the plane corresponding to the offset passed by userspace. This
	 * will return an error if not MEMORY_MMAP or file I/O is in progress.
	 */
	ret = __find_plane_by_offset(q, offset, &vb, &plane);
	if (ret)
		goto unlock;

	vaddr = vb2_plane_vaddr(vb, plane);
	mutex_unlock(&q->mmap_lock);
	return vaddr ? (unsigned long)vaddr : -EINVAL;

unlock:
	mutex_unlock(&q->mmap_lock);
	return ret;
}
EXPORT_SYMBOL_GPL(vb2_get_unmapped_area);
#endif

int vb2_core_queue_init(struct vb2_queue *q)
{}
EXPORT_SYMBOL_GPL();

static int __vb2_init_fileio(struct vb2_queue *q, int read);
static int __vb2_cleanup_fileio(struct vb2_queue *q);
void vb2_core_queue_release(struct vb2_queue *q)
{}
EXPORT_SYMBOL_GPL();

__poll_t vb2_core_poll(struct vb2_queue *q, struct file *file,
		poll_table *wait)
{}
EXPORT_SYMBOL_GPL();

/*
 * struct vb2_fileio_buf - buffer context used by file io emulator
 *
 * vb2 provides a compatibility layer and emulator of file io (read and
 * write) calls on top of streaming API. This structure is used for
 * tracking context related to the buffers.
 */
struct vb2_fileio_buf {};

/*
 * struct vb2_fileio_data - queue context used by file io emulator
 *
 * @cur_index:	the index of the buffer currently being read from or
 *		written to. If equal to number of buffers in the vb2_queue
 *		then a new buffer must be dequeued.
 * @initial_index: in the read() case all buffers are queued up immediately
 *		in __vb2_init_fileio() and __vb2_perform_fileio() just cycles
 *		buffers. However, in the write() case no buffers are initially
 *		queued, instead whenever a buffer is full it is queued up by
 *		__vb2_perform_fileio(). Only once all available buffers have
 *		been queued up will __vb2_perform_fileio() start to dequeue
 *		buffers. This means that initially __vb2_perform_fileio()
 *		needs to know what buffer index to use when it is queuing up
 *		the buffers for the first time. That initial index is stored
 *		in this field. Once it is equal to number of buffers in the
 *		vb2_queue all available buffers have been queued and
 *		__vb2_perform_fileio() should start the normal dequeue/queue cycle.
 *
 * vb2 provides a compatibility layer and emulator of file io (read and
 * write) calls on top of streaming API. For proper operation it required
 * this structure to save the driver state between each call of the read
 * or write function.
 */
struct vb2_fileio_data {};

/*
 * __vb2_init_fileio() - initialize file io emulator
 * @q:		videobuf2 queue
 * @read:	mode selector (1 means read, 0 means write)
 */
static int __vb2_init_fileio(struct vb2_queue *q, int read)
{}

/*
 * __vb2_cleanup_fileio() - free resourced used by file io emulator
 * @q:		videobuf2 queue
 */
static int __vb2_cleanup_fileio(struct vb2_queue *q)
{}

/*
 * __vb2_perform_fileio() - perform a single file io (read or write) operation
 * @q:		videobuf2 queue
 * @data:	pointed to target userspace buffer
 * @count:	number of bytes to read or write
 * @ppos:	file handle position tracking pointer
 * @nonblock:	mode selector (1 means blocking calls, 0 means nonblocking)
 * @read:	access mode selector (1 means read, 0 means write)
 */
static size_t __vb2_perform_fileio(struct vb2_queue *q, char __user *data, size_t count,
		loff_t *ppos, int nonblock, int read)
{}

size_t vb2_read(struct vb2_queue *q, char __user *data, size_t count,
		loff_t *ppos, int nonblocking)
{}
EXPORT_SYMBOL_GPL();

size_t vb2_write(struct vb2_queue *q, const char __user *data, size_t count,
		loff_t *ppos, int nonblocking)
{}
EXPORT_SYMBOL_GPL();

struct vb2_threadio_data {};

static int vb2_thread(void *data)
{}

/*
 * This function should not be used for anything else but the videobuf2-dvb
 * support. If you think you have another good use-case for this, then please
 * contact the linux-media mailinglist first.
 */
int vb2_thread_start(struct vb2_queue *q, vb2_thread_fnc fnc, void *priv,
		     const char *thread_name)
{}
EXPORT_SYMBOL_GPL();

int vb2_thread_stop(struct vb2_queue *q)
{}
EXPORT_SYMBOL_GPL();

MODULE_DESCRIPTION();
MODULE_AUTHOR();
MODULE_LICENSE();
MODULE_IMPORT_NS();