2019-06-03 08:44:53 +03:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0-only */
|
2007-08-23 23:26:14 +04:00
|
|
|
/*
|
|
|
|
* generic helper functions for handling video4linux capture buffers
|
|
|
|
*
|
MAINTAINERS & files: Canonize the e-mails I use at files
From now on, I'll start using my @kernel.org as my development e-mail.
As such, let's remove the entries that point to the old
mchehab@s-opensource.com at MAINTAINERS file.
For the files written with a copyright with mchehab@s-opensource,
let's keep Samsung on their names, using mchehab+samsung@kernel.org,
in order to keep pointing to my employer, with sponsors the work.
For the files written before I join Samsung (on July, 4 2013),
let's just use mchehab@kernel.org.
For bug reports, we can simply point to just kernel.org, as
this will reach my mchehab+samsung inbox anyway.
Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>
Signed-off-by: Brian Warner <brian.warner@samsung.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>
2018-04-25 12:34:48 +03:00
|
|
|
* (c) 2007 Mauro Carvalho Chehab, <mchehab@kernel.org>
|
2007-08-23 23:26:14 +04:00
|
|
|
*
|
|
|
|
* Highly based on video-buf written originally by:
|
|
|
|
* (c) 2001,02 Gerd Knorr <kraxel@bytesex.org>
|
MAINTAINERS & files: Canonize the e-mails I use at files
From now on, I'll start using my @kernel.org as my development e-mail.
As such, let's remove the entries that point to the old
mchehab@s-opensource.com at MAINTAINERS file.
For the files written with a copyright with mchehab@s-opensource,
let's keep Samsung on their names, using mchehab+samsung@kernel.org,
in order to keep pointing to my employer, with sponsors the work.
For the files written before I join Samsung (on July, 4 2013),
let's just use mchehab@kernel.org.
For bug reports, we can simply point to just kernel.org, as
this will reach my mchehab+samsung inbox anyway.
Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>
Signed-off-by: Brian Warner <brian.warner@samsung.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>
2018-04-25 12:34:48 +03:00
|
|
|
* (c) 2006 Mauro Carvalho Chehab, <mchehab@kernel.org>
|
2007-08-23 23:26:14 +04:00
|
|
|
* (c) 2006 Ted Walther and John Sokol
|
|
|
|
*/
|
|
|
|
|
2008-04-13 22:10:00 +04:00
|
|
|
#ifndef _VIDEOBUF_CORE_H
|
|
|
|
#define _VIDEOBUF_CORE_H
|
|
|
|
|
2007-08-23 23:26:14 +04:00
|
|
|
#include <linux/poll.h>
|
|
|
|
#include <linux/videodev2.h>
|
|
|
|
|
|
|
|
#define UNSET (-1U)
|
|
|
|
|
|
|
|
|
|
|
|
struct videobuf_buffer;
|
|
|
|
struct videobuf_queue;
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* A small set of helper functions to manage video4linux buffers.
|
|
|
|
*
|
|
|
|
* struct videobuf_buffer holds the data structures used by the helper
|
|
|
|
* functions, additionally some commonly used fields for v4l buffers
|
|
|
|
* (width, height, lists, waitqueue) are in there. That struct should
|
|
|
|
* be used as first element in the drivers buffer struct.
|
|
|
|
*
|
|
|
|
* about the mmap helpers (videobuf_mmap_*):
|
|
|
|
*
|
2015-07-07 04:14:59 +03:00
|
|
|
* The mmaper function allows to map any subset of contiguous buffers.
|
2007-08-23 23:26:14 +04:00
|
|
|
* This includes one mmap() call for all buffers (which the original
|
|
|
|
* video4linux API uses) as well as one mmap() for every single buffer
|
|
|
|
* (which v4l2 uses).
|
|
|
|
*
|
|
|
|
* If there is a valid mapping for a buffer, buffer->baddr/bsize holds
|
2019-02-18 22:29:06 +03:00
|
|
|
* userspace address + size which can be fed into the
|
2007-08-23 23:26:14 +04:00
|
|
|
* videobuf_dma_init_user function listed above.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
struct videobuf_mapping {
|
|
|
|
unsigned int count;
|
|
|
|
struct videobuf_queue *q;
|
|
|
|
};
|
|
|
|
|
|
|
|
enum videobuf_state {
|
2007-11-07 02:02:36 +03:00
|
|
|
VIDEOBUF_NEEDS_INIT = 0,
|
|
|
|
VIDEOBUF_PREPARED = 1,
|
|
|
|
VIDEOBUF_QUEUED = 2,
|
|
|
|
VIDEOBUF_ACTIVE = 3,
|
|
|
|
VIDEOBUF_DONE = 4,
|
|
|
|
VIDEOBUF_ERROR = 5,
|
|
|
|
VIDEOBUF_IDLE = 6,
|
2007-08-23 23:26:14 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
struct videobuf_buffer {
|
|
|
|
unsigned int i;
|
|
|
|
u32 magic;
|
|
|
|
|
|
|
|
/* info about the buffer */
|
|
|
|
unsigned int width;
|
|
|
|
unsigned int height;
|
|
|
|
unsigned int bytesperline; /* use only if != 0 */
|
|
|
|
unsigned long size;
|
|
|
|
enum v4l2_field field;
|
|
|
|
enum videobuf_state state;
|
|
|
|
struct list_head stream; /* QBUF/DQBUF list */
|
|
|
|
|
|
|
|
/* touched by irq handler */
|
|
|
|
struct list_head queue;
|
|
|
|
wait_queue_head_t done;
|
|
|
|
unsigned int field_count;
|
2019-01-21 16:32:23 +03:00
|
|
|
u64 ts;
|
2007-08-23 23:26:14 +04:00
|
|
|
|
|
|
|
/* Memory type */
|
|
|
|
enum v4l2_memory memory;
|
|
|
|
|
|
|
|
/* buffer size */
|
|
|
|
size_t bsize;
|
|
|
|
|
|
|
|
/* buffer offset (mmap + overlay) */
|
|
|
|
size_t boff;
|
|
|
|
|
|
|
|
/* buffer addr (userland ptr!) */
|
|
|
|
unsigned long baddr;
|
|
|
|
|
2007-09-28 01:25:44 +04:00
|
|
|
/* for mmap'ed buffers */
|
|
|
|
struct videobuf_mapping *map;
|
|
|
|
|
2007-08-23 23:26:14 +04:00
|
|
|
/* Private pointer to allow specific methods to store their data */
|
|
|
|
int privsize;
|
|
|
|
void *priv;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct videobuf_queue_ops {
|
|
|
|
int (*buf_setup)(struct videobuf_queue *q,
|
|
|
|
unsigned int *count, unsigned int *size);
|
|
|
|
int (*buf_prepare)(struct videobuf_queue *q,
|
|
|
|
struct videobuf_buffer *vb,
|
|
|
|
enum v4l2_field field);
|
|
|
|
void (*buf_queue)(struct videobuf_queue *q,
|
|
|
|
struct videobuf_buffer *vb);
|
|
|
|
void (*buf_release)(struct videobuf_queue *q,
|
|
|
|
struct videobuf_buffer *vb);
|
|
|
|
};
|
|
|
|
|
|
|
|
#define MAGIC_QTYPE_OPS 0x12261003
|
|
|
|
|
|
|
|
/* Helper operations - device type dependent */
|
|
|
|
struct videobuf_qtype_ops {
|
|
|
|
u32 magic;
|
|
|
|
|
2010-05-11 17:36:28 +04:00
|
|
|
struct videobuf_buffer *(*alloc_vb)(size_t size);
|
2010-03-28 15:18:37 +04:00
|
|
|
void *(*vaddr) (struct videobuf_buffer *buf);
|
2010-03-17 10:01:04 +03:00
|
|
|
int (*iolock) (struct videobuf_queue *q,
|
2007-08-23 23:26:14 +04:00
|
|
|
struct videobuf_buffer *vb,
|
|
|
|
struct v4l2_framebuffer *fbuf);
|
2010-03-17 10:01:04 +03:00
|
|
|
int (*sync) (struct videobuf_queue *q,
|
2007-08-23 23:26:14 +04:00
|
|
|
struct videobuf_buffer *buf);
|
|
|
|
int (*mmap_mapper) (struct videobuf_queue *q,
|
2010-03-28 16:09:05 +04:00
|
|
|
struct videobuf_buffer *buf,
|
|
|
|
struct vm_area_struct *vma);
|
2007-08-23 23:26:14 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
struct videobuf_queue {
|
2008-01-31 19:57:53 +03:00
|
|
|
struct mutex vb_lock;
|
2010-09-21 00:24:30 +04:00
|
|
|
struct mutex *ext_lock;
|
2007-08-23 23:26:14 +04:00
|
|
|
spinlock_t *irqlock;
|
2008-04-22 21:46:02 +04:00
|
|
|
struct device *dev;
|
2007-08-23 23:26:14 +04:00
|
|
|
|
2008-04-03 01:10:59 +04:00
|
|
|
wait_queue_head_t wait; /* wait if queue is empty */
|
|
|
|
|
2007-08-23 23:26:14 +04:00
|
|
|
enum v4l2_buf_type type;
|
|
|
|
unsigned int msize;
|
|
|
|
enum v4l2_field field;
|
|
|
|
enum v4l2_field last; /* for field=V4L2_FIELD_ALTERNATE */
|
|
|
|
struct videobuf_buffer *bufs[VIDEO_MAX_FRAME];
|
2009-11-18 01:43:41 +03:00
|
|
|
const struct videobuf_queue_ops *ops;
|
2007-08-23 23:26:14 +04:00
|
|
|
struct videobuf_qtype_ops *int_ops;
|
|
|
|
|
2007-11-07 02:23:08 +03:00
|
|
|
unsigned int streaming:1;
|
|
|
|
unsigned int reading:1;
|
2008-01-10 13:33:03 +03:00
|
|
|
|
2007-08-23 23:26:14 +04:00
|
|
|
/* capture via mmap() + ioctl(QBUF/DQBUF) */
|
|
|
|
struct list_head stream;
|
|
|
|
|
|
|
|
/* capture via read() */
|
|
|
|
unsigned int read_off;
|
|
|
|
struct videobuf_buffer *read_buf;
|
|
|
|
|
|
|
|
/* driver private data */
|
|
|
|
void *priv_data;
|
|
|
|
};
|
|
|
|
|
2010-09-21 00:24:30 +04:00
|
|
|
static inline void videobuf_queue_lock(struct videobuf_queue *q)
|
|
|
|
{
|
|
|
|
if (!q->ext_lock)
|
|
|
|
mutex_lock(&q->vb_lock);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void videobuf_queue_unlock(struct videobuf_queue *q)
|
|
|
|
{
|
|
|
|
if (!q->ext_lock)
|
|
|
|
mutex_unlock(&q->vb_lock);
|
|
|
|
}
|
|
|
|
|
2010-09-26 16:01:26 +04:00
|
|
|
int videobuf_waiton(struct videobuf_queue *q, struct videobuf_buffer *vb,
|
|
|
|
int non_blocking, int intr);
|
2010-03-17 10:01:04 +03:00
|
|
|
int videobuf_iolock(struct videobuf_queue *q, struct videobuf_buffer *vb,
|
2007-08-23 23:26:14 +04:00
|
|
|
struct v4l2_framebuffer *fbuf);
|
|
|
|
|
2010-05-11 17:36:28 +04:00
|
|
|
struct videobuf_buffer *videobuf_alloc_vb(struct videobuf_queue *q);
|
2007-08-23 23:26:14 +04:00
|
|
|
|
2008-04-13 22:10:00 +04:00
|
|
|
/* Used on videobuf-dvb */
|
2010-03-28 15:33:23 +04:00
|
|
|
void *videobuf_queue_to_vaddr(struct videobuf_queue *q,
|
|
|
|
struct videobuf_buffer *buf);
|
2008-04-13 22:10:00 +04:00
|
|
|
|
2007-10-08 19:20:02 +04:00
|
|
|
void videobuf_queue_core_init(struct videobuf_queue *q,
|
2009-11-18 01:43:41 +03:00
|
|
|
const struct videobuf_queue_ops *ops,
|
2008-04-22 21:46:02 +04:00
|
|
|
struct device *dev,
|
2007-08-23 23:26:14 +04:00
|
|
|
spinlock_t *irqlock,
|
|
|
|
enum v4l2_buf_type type,
|
|
|
|
enum v4l2_field field,
|
|
|
|
unsigned int msize,
|
2007-10-08 19:20:02 +04:00
|
|
|
void *priv,
|
2010-09-21 00:39:46 +04:00
|
|
|
struct videobuf_qtype_ops *int_ops,
|
|
|
|
struct mutex *ext_lock);
|
2007-08-23 23:26:14 +04:00
|
|
|
int videobuf_queue_is_busy(struct videobuf_queue *q);
|
|
|
|
void videobuf_queue_cancel(struct videobuf_queue *q);
|
|
|
|
|
|
|
|
enum v4l2_field videobuf_next_field(struct videobuf_queue *q);
|
|
|
|
int videobuf_reqbufs(struct videobuf_queue *q,
|
|
|
|
struct v4l2_requestbuffers *req);
|
|
|
|
int videobuf_querybuf(struct videobuf_queue *q, struct v4l2_buffer *b);
|
|
|
|
int videobuf_qbuf(struct videobuf_queue *q,
|
|
|
|
struct v4l2_buffer *b);
|
|
|
|
int videobuf_dqbuf(struct videobuf_queue *q,
|
|
|
|
struct v4l2_buffer *b, int nonblocking);
|
|
|
|
int videobuf_streamon(struct videobuf_queue *q);
|
|
|
|
int videobuf_streamoff(struct videobuf_queue *q);
|
|
|
|
|
2007-11-14 02:05:38 +03:00
|
|
|
void videobuf_stop(struct videobuf_queue *q);
|
|
|
|
|
2007-08-23 23:26:14 +04:00
|
|
|
int videobuf_read_start(struct videobuf_queue *q);
|
|
|
|
void videobuf_read_stop(struct videobuf_queue *q);
|
|
|
|
ssize_t videobuf_read_stream(struct videobuf_queue *q,
|
|
|
|
char __user *data, size_t count, loff_t *ppos,
|
|
|
|
int vbihack, int nonblocking);
|
|
|
|
ssize_t videobuf_read_one(struct videobuf_queue *q,
|
|
|
|
char __user *data, size_t count, loff_t *ppos,
|
|
|
|
int nonblocking);
|
2017-07-03 10:02:56 +03:00
|
|
|
__poll_t videobuf_poll_stream(struct file *file,
|
2007-08-23 23:26:14 +04:00
|
|
|
struct videobuf_queue *q,
|
|
|
|
poll_table *wait);
|
|
|
|
|
|
|
|
int videobuf_mmap_setup(struct videobuf_queue *q,
|
|
|
|
unsigned int bcount, unsigned int bsize,
|
|
|
|
enum v4l2_memory memory);
|
2008-05-20 20:53:52 +04:00
|
|
|
int __videobuf_mmap_setup(struct videobuf_queue *q,
|
|
|
|
unsigned int bcount, unsigned int bsize,
|
|
|
|
enum v4l2_memory memory);
|
2007-08-23 23:26:14 +04:00
|
|
|
int videobuf_mmap_free(struct videobuf_queue *q);
|
|
|
|
int videobuf_mmap_mapper(struct videobuf_queue *q,
|
|
|
|
struct vm_area_struct *vma);
|
|
|
|
|
2008-04-13 22:10:00 +04:00
|
|
|
#endif
|