mirror of
https://github.com/AuxXxilium/linux_dsm_epyc7002.git
synced 2025-04-04 07:48:03 +07:00
V4L/DVB: v4l: videobuf: code cleanup
Make videobuf pass checkpatch; minor code cleanups. Signed-off-by: Pawel Osciak <p.osciak@samsung.com> Reviewed-by: Kyungmin Park <kyungmin.park@samsung.com> Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
This commit is contained in:
parent
85e092190b
commit
7a02264ca9
@ -24,10 +24,15 @@
|
||||
#include <media/videobuf-core.h>
|
||||
|
||||
#define MAGIC_BUFFER 0x20070728
|
||||
#define MAGIC_CHECK(is, should) do { \
|
||||
#define MAGIC_CHECK(is, should) \
|
||||
do { \
|
||||
if (unlikely((is) != (should))) { \
|
||||
printk(KERN_ERR "magic mismatch: %x (expected %x)\n", is, should); \
|
||||
BUG(); } } while (0)
|
||||
printk(KERN_ERR \
|
||||
"magic mismatch: %x (expected %x)\n", \
|
||||
is, should); \
|
||||
BUG(); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
static int debug;
|
||||
module_param(debug, int, 0644);
|
||||
@ -36,9 +41,11 @@ MODULE_DESCRIPTION("helper module to manage video4linux buffers");
|
||||
MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@infradead.org>");
|
||||
MODULE_LICENSE("GPL");
|
||||
|
||||
#define dprintk(level, fmt, arg...) do { \
|
||||
#define dprintk(level, fmt, arg...) \
|
||||
do { \
|
||||
if (debug >= level) \
|
||||
printk(KERN_DEBUG "vbuf: " fmt , ## arg); } while (0)
|
||||
printk(KERN_DEBUG "vbuf: " fmt, ## arg); \
|
||||
} while (0)
|
||||
|
||||
/* --------------------------------------------------------------------- */
|
||||
|
||||
@ -57,7 +64,6 @@ void *videobuf_alloc(struct videobuf_queue *q)
|
||||
}
|
||||
|
||||
vb = q->int_ops->alloc(q->msize);
|
||||
|
||||
if (NULL != vb) {
|
||||
init_waitqueue_head(&vb->done);
|
||||
vb->magic = MAGIC_BUFFER;
|
||||
@ -65,6 +71,7 @@ void *videobuf_alloc(struct videobuf_queue *q)
|
||||
|
||||
return vb;
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(videobuf_alloc);
|
||||
|
||||
#define WAITON_CONDITION (vb->state != VIDEOBUF_ACTIVE &&\
|
||||
vb->state != VIDEOBUF_QUEUED)
|
||||
@ -86,6 +93,7 @@ int videobuf_waiton(struct videobuf_buffer *vb, int non_blocking, int intr)
|
||||
|
||||
return 0;
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(videobuf_waiton);
|
||||
|
||||
int videobuf_iolock(struct videobuf_queue *q, struct videobuf_buffer *vb,
|
||||
struct v4l2_framebuffer *fbuf)
|
||||
@ -95,6 +103,7 @@ int videobuf_iolock(struct videobuf_queue *q, struct videobuf_buffer *vb,
|
||||
|
||||
return CALL(q, iolock, q, vb, fbuf);
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(videobuf_iolock);
|
||||
|
||||
void *videobuf_queue_to_vmalloc(struct videobuf_queue *q,
|
||||
struct videobuf_buffer *buf)
|
||||
@ -146,6 +155,7 @@ void videobuf_queue_core_init(struct videobuf_queue *q,
|
||||
init_waitqueue_head(&q->wait);
|
||||
INIT_LIST_HEAD(&q->stream);
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(videobuf_queue_core_init);
|
||||
|
||||
/* Locking: Only usage in bttv unsafe find way to remove */
|
||||
int videobuf_queue_is_busy(struct videobuf_queue *q)
|
||||
@ -184,6 +194,7 @@ int videobuf_queue_is_busy(struct videobuf_queue *q)
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(videobuf_queue_is_busy);
|
||||
|
||||
/* Locking: Caller holds q->vb_lock */
|
||||
void videobuf_queue_cancel(struct videobuf_queue *q)
|
||||
@ -216,6 +227,7 @@ void videobuf_queue_cancel(struct videobuf_queue *q)
|
||||
}
|
||||
INIT_LIST_HEAD(&q->stream);
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(videobuf_queue_cancel);
|
||||
|
||||
/* --------------------------------------------------------------------- */
|
||||
|
||||
@ -237,6 +249,7 @@ enum v4l2_field videobuf_next_field(struct videobuf_queue *q)
|
||||
}
|
||||
return field;
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(videobuf_next_field);
|
||||
|
||||
/* Locking: Caller holds q->vb_lock */
|
||||
static void videobuf_status(struct videobuf_queue *q, struct v4l2_buffer *b,
|
||||
@ -305,7 +318,6 @@ static int __videobuf_mmap_free(struct videobuf_queue *q)
|
||||
|
||||
MAGIC_CHECK(q->int_ops->magic, MAGIC_QTYPE_OPS);
|
||||
|
||||
|
||||
rc = CALL(q, mmap_free, q);
|
||||
|
||||
q->is_mmapped = 0;
|
||||
@ -332,6 +344,7 @@ int videobuf_mmap_free(struct videobuf_queue *q)
|
||||
mutex_unlock(&q->vb_lock);
|
||||
return ret;
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(videobuf_mmap_free);
|
||||
|
||||
/* Locking: Caller holds q->vb_lock */
|
||||
int __videobuf_mmap_setup(struct videobuf_queue *q,
|
||||
@ -351,7 +364,7 @@ int __videobuf_mmap_setup(struct videobuf_queue *q,
|
||||
for (i = 0; i < bcount; i++) {
|
||||
q->bufs[i] = videobuf_alloc(q);
|
||||
|
||||
if (q->bufs[i] == NULL)
|
||||
if (NULL == q->bufs[i])
|
||||
break;
|
||||
|
||||
q->bufs[i]->i = i;
|
||||
@ -372,11 +385,11 @@ int __videobuf_mmap_setup(struct videobuf_queue *q,
|
||||
if (!i)
|
||||
return -ENOMEM;
|
||||
|
||||
dprintk(1, "mmap setup: %d buffers, %d bytes each\n",
|
||||
i, bsize);
|
||||
dprintk(1, "mmap setup: %d buffers, %d bytes each\n", i, bsize);
|
||||
|
||||
return i;
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(__videobuf_mmap_setup);
|
||||
|
||||
int videobuf_mmap_setup(struct videobuf_queue *q,
|
||||
unsigned int bcount, unsigned int bsize,
|
||||
@ -388,6 +401,7 @@ int videobuf_mmap_setup(struct videobuf_queue *q,
|
||||
mutex_unlock(&q->vb_lock);
|
||||
return ret;
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(videobuf_mmap_setup);
|
||||
|
||||
int videobuf_reqbufs(struct videobuf_queue *q,
|
||||
struct v4l2_requestbuffers *req)
|
||||
@ -447,6 +461,7 @@ int videobuf_reqbufs(struct videobuf_queue *q,
|
||||
mutex_unlock(&q->vb_lock);
|
||||
return retval;
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(videobuf_reqbufs);
|
||||
|
||||
int videobuf_querybuf(struct videobuf_queue *q, struct v4l2_buffer *b)
|
||||
{
|
||||
@ -473,9 +488,9 @@ int videobuf_querybuf(struct videobuf_queue *q, struct v4l2_buffer *b)
|
||||
mutex_unlock(&q->vb_lock);
|
||||
return ret;
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(videobuf_querybuf);
|
||||
|
||||
int videobuf_qbuf(struct videobuf_queue *q,
|
||||
struct v4l2_buffer *b)
|
||||
int videobuf_qbuf(struct videobuf_queue *q, struct v4l2_buffer *b)
|
||||
{
|
||||
struct videobuf_buffer *buf;
|
||||
enum v4l2_field field;
|
||||
@ -579,7 +594,7 @@ int videobuf_qbuf(struct videobuf_queue *q,
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
EXPORT_SYMBOL_GPL(videobuf_qbuf);
|
||||
|
||||
/* Locking: Caller holds q->vb_lock */
|
||||
static int stream_next_buffer_check_queue(struct videobuf_queue *q, int noblock)
|
||||
@ -624,7 +639,6 @@ static int stream_next_buffer_check_queue(struct videobuf_queue *q, int noblock)
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
||||
/* Locking: Caller holds q->vb_lock */
|
||||
static int stream_next_buffer(struct videobuf_queue *q,
|
||||
struct videobuf_buffer **vb, int nonblocking)
|
||||
@ -682,11 +696,11 @@ int videobuf_dqbuf(struct videobuf_queue *q,
|
||||
list_del(&buf->stream);
|
||||
memset(b, 0, sizeof(*b));
|
||||
videobuf_status(q, b, buf, q->type);
|
||||
|
||||
done:
|
||||
mutex_unlock(&q->vb_lock);
|
||||
return retval;
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(videobuf_dqbuf);
|
||||
|
||||
int videobuf_streamon(struct videobuf_queue *q)
|
||||
{
|
||||
@ -713,6 +727,7 @@ int videobuf_streamon(struct videobuf_queue *q)
|
||||
mutex_unlock(&q->vb_lock);
|
||||
return retval;
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(videobuf_streamon);
|
||||
|
||||
/* Locking: Caller holds q->vb_lock */
|
||||
static int __videobuf_streamoff(struct videobuf_queue *q)
|
||||
@ -735,6 +750,7 @@ int videobuf_streamoff(struct videobuf_queue *q)
|
||||
|
||||
return retval;
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(videobuf_streamoff);
|
||||
|
||||
/* Locking: Caller holds q->vb_lock */
|
||||
static ssize_t videobuf_read_zerocopy(struct videobuf_queue *q,
|
||||
@ -866,6 +882,7 @@ ssize_t videobuf_read_one(struct videobuf_queue *q,
|
||||
mutex_unlock(&q->vb_lock);
|
||||
return retval;
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(videobuf_read_one);
|
||||
|
||||
/* Locking: Caller holds q->vb_lock */
|
||||
static int __videobuf_read_start(struct videobuf_queue *q)
|
||||
@ -917,7 +934,6 @@ static void __videobuf_read_stop(struct videobuf_queue *q)
|
||||
q->bufs[i] = NULL;
|
||||
}
|
||||
q->read_buf = NULL;
|
||||
|
||||
}
|
||||
|
||||
int videobuf_read_start(struct videobuf_queue *q)
|
||||
@ -930,6 +946,7 @@ int videobuf_read_start(struct videobuf_queue *q)
|
||||
|
||||
return rc;
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(videobuf_read_start);
|
||||
|
||||
void videobuf_read_stop(struct videobuf_queue *q)
|
||||
{
|
||||
@ -937,6 +954,7 @@ void videobuf_read_stop(struct videobuf_queue *q)
|
||||
__videobuf_read_stop(q);
|
||||
mutex_unlock(&q->vb_lock);
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(videobuf_read_stop);
|
||||
|
||||
void videobuf_stop(struct videobuf_queue *q)
|
||||
{
|
||||
@ -950,7 +968,7 @@ void videobuf_stop(struct videobuf_queue *q)
|
||||
|
||||
mutex_unlock(&q->vb_lock);
|
||||
}
|
||||
|
||||
EXPORT_SYMBOL_GPL(videobuf_stop);
|
||||
|
||||
ssize_t videobuf_read_stream(struct videobuf_queue *q,
|
||||
char __user *data, size_t count, loff_t *ppos,
|
||||
@ -1023,6 +1041,7 @@ ssize_t videobuf_read_stream(struct videobuf_queue *q,
|
||||
mutex_unlock(&q->vb_lock);
|
||||
return retval;
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(videobuf_read_stream);
|
||||
|
||||
unsigned int videobuf_poll_stream(struct file *file,
|
||||
struct videobuf_queue *q,
|
||||
@ -1062,9 +1081,9 @@ unsigned int videobuf_poll_stream(struct file *file,
|
||||
mutex_unlock(&q->vb_lock);
|
||||
return rc;
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(videobuf_poll_stream);
|
||||
|
||||
int videobuf_mmap_mapper(struct videobuf_queue *q,
|
||||
struct vm_area_struct *vma)
|
||||
int videobuf_mmap_mapper(struct videobuf_queue *q, struct vm_area_struct *vma)
|
||||
{
|
||||
int retval;
|
||||
|
||||
@ -1077,6 +1096,7 @@ int videobuf_mmap_mapper(struct videobuf_queue *q,
|
||||
|
||||
return retval;
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(videobuf_mmap_mapper);
|
||||
|
||||
#ifdef CONFIG_VIDEO_V4L1_COMPAT
|
||||
int videobuf_cgmbuf(struct videobuf_queue *q,
|
||||
@ -1107,33 +1127,3 @@ int videobuf_cgmbuf(struct videobuf_queue *q,
|
||||
EXPORT_SYMBOL_GPL(videobuf_cgmbuf);
|
||||
#endif
|
||||
|
||||
/* --------------------------------------------------------------------- */
|
||||
|
||||
EXPORT_SYMBOL_GPL(videobuf_waiton);
|
||||
EXPORT_SYMBOL_GPL(videobuf_iolock);
|
||||
|
||||
EXPORT_SYMBOL_GPL(videobuf_alloc);
|
||||
|
||||
EXPORT_SYMBOL_GPL(videobuf_queue_core_init);
|
||||
EXPORT_SYMBOL_GPL(videobuf_queue_cancel);
|
||||
EXPORT_SYMBOL_GPL(videobuf_queue_is_busy);
|
||||
|
||||
EXPORT_SYMBOL_GPL(videobuf_next_field);
|
||||
EXPORT_SYMBOL_GPL(videobuf_reqbufs);
|
||||
EXPORT_SYMBOL_GPL(videobuf_querybuf);
|
||||
EXPORT_SYMBOL_GPL(videobuf_qbuf);
|
||||
EXPORT_SYMBOL_GPL(videobuf_dqbuf);
|
||||
EXPORT_SYMBOL_GPL(videobuf_streamon);
|
||||
EXPORT_SYMBOL_GPL(videobuf_streamoff);
|
||||
|
||||
EXPORT_SYMBOL_GPL(videobuf_read_start);
|
||||
EXPORT_SYMBOL_GPL(videobuf_read_stop);
|
||||
EXPORT_SYMBOL_GPL(videobuf_stop);
|
||||
EXPORT_SYMBOL_GPL(videobuf_read_stream);
|
||||
EXPORT_SYMBOL_GPL(videobuf_read_one);
|
||||
EXPORT_SYMBOL_GPL(videobuf_poll_stream);
|
||||
|
||||
EXPORT_SYMBOL_GPL(__videobuf_mmap_setup);
|
||||
EXPORT_SYMBOL_GPL(videobuf_mmap_setup);
|
||||
EXPORT_SYMBOL_GPL(videobuf_mmap_free);
|
||||
EXPORT_SYMBOL_GPL(videobuf_mmap_mapper);
|
||||
|
@ -37,8 +37,12 @@
|
||||
#define MAGIC_DMABUF 0x19721112
|
||||
#define MAGIC_SG_MEM 0x17890714
|
||||
|
||||
#define MAGIC_CHECK(is,should) if (unlikely((is) != (should))) \
|
||||
{ printk(KERN_ERR "magic mismatch: %x (expected %x)\n",is,should); BUG(); }
|
||||
#define MAGIC_CHECK(is, should) \
|
||||
if (unlikely((is) != (should))) { \
|
||||
printk(KERN_ERR "magic mismatch: %x (expected %x)\n", \
|
||||
is, should); \
|
||||
BUG(); \
|
||||
}
|
||||
|
||||
static int debug;
|
||||
module_param(debug, int, 0644);
|
||||
@ -47,13 +51,13 @@ MODULE_DESCRIPTION("helper module to manage video4linux dma sg buffers");
|
||||
MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@infradead.org>");
|
||||
MODULE_LICENSE("GPL");
|
||||
|
||||
#define dprintk(level, fmt, arg...) if (debug >= level) \
|
||||
#define dprintk(level, fmt, arg...) \
|
||||
if (debug >= level) \
|
||||
printk(KERN_DEBUG "vbuf-sg: " fmt , ## arg)
|
||||
|
||||
/* --------------------------------------------------------------------- */
|
||||
|
||||
struct scatterlist*
|
||||
videobuf_vmalloc_to_sg(unsigned char *virt, int nr_pages)
|
||||
struct scatterlist *videobuf_vmalloc_to_sg(unsigned char *virt, int nr_pages)
|
||||
{
|
||||
struct scatterlist *sglist;
|
||||
struct page *pg;
|
||||
@ -77,9 +81,10 @@ videobuf_vmalloc_to_sg(unsigned char *virt, int nr_pages)
|
||||
vfree(sglist);
|
||||
return NULL;
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(videobuf_vmalloc_to_sg);
|
||||
|
||||
struct scatterlist*
|
||||
videobuf_pages_to_sg(struct page **pages, int nr_pages, int offset)
|
||||
struct scatterlist *videobuf_pages_to_sg(struct page **pages, int nr_pages,
|
||||
int offset)
|
||||
{
|
||||
struct scatterlist *sglist;
|
||||
int i;
|
||||
@ -126,12 +131,14 @@ struct videobuf_dmabuf *videobuf_to_dma (struct videobuf_buffer *buf)
|
||||
|
||||
return &mem->dma;
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(videobuf_to_dma);
|
||||
|
||||
void videobuf_dma_init(struct videobuf_dmabuf *dma)
|
||||
{
|
||||
memset(dma, 0, sizeof(*dma));
|
||||
dma->magic = MAGIC_DMABUF;
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(videobuf_dma_init);
|
||||
|
||||
static int videobuf_dma_init_user_locked(struct videobuf_dmabuf *dma,
|
||||
int direction, unsigned long data, unsigned long size)
|
||||
@ -155,10 +162,10 @@ static int videobuf_dma_init_user_locked(struct videobuf_dmabuf *dma,
|
||||
last = ((data+size-1) & PAGE_MASK) >> PAGE_SHIFT;
|
||||
dma->offset = data & ~PAGE_MASK;
|
||||
dma->nr_pages = last-first+1;
|
||||
dma->pages = kmalloc(dma->nr_pages * sizeof(struct page*),
|
||||
GFP_KERNEL);
|
||||
dma->pages = kmalloc(dma->nr_pages * sizeof(struct page *), GFP_KERNEL);
|
||||
if (NULL == dma->pages)
|
||||
return -ENOMEM;
|
||||
|
||||
dprintk(1, "init user [0x%lx+0x%lx => %d pages]\n",
|
||||
data, size, dma->nr_pages);
|
||||
|
||||
@ -179,30 +186,37 @@ int videobuf_dma_init_user(struct videobuf_dmabuf *dma, int direction,
|
||||
unsigned long data, unsigned long size)
|
||||
{
|
||||
int ret;
|
||||
|
||||
down_read(¤t->mm->mmap_sem);
|
||||
ret = videobuf_dma_init_user_locked(dma, direction, data, size);
|
||||
up_read(¤t->mm->mmap_sem);
|
||||
|
||||
return ret;
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(videobuf_dma_init_user);
|
||||
|
||||
int videobuf_dma_init_kernel(struct videobuf_dmabuf *dma, int direction,
|
||||
int nr_pages)
|
||||
{
|
||||
dprintk(1, "init kernel [%d pages]\n", nr_pages);
|
||||
|
||||
dma->direction = direction;
|
||||
dma->vmalloc = vmalloc_32(nr_pages << PAGE_SHIFT);
|
||||
if (NULL == dma->vmalloc) {
|
||||
dprintk(1, "vmalloc_32(%d pages) failed\n", nr_pages);
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
dprintk(1, "vmalloc is at addr 0x%08lx, size=%d\n",
|
||||
(unsigned long)dma->vmalloc,
|
||||
nr_pages << PAGE_SHIFT);
|
||||
|
||||
memset(dma->vmalloc, 0, nr_pages << PAGE_SHIFT);
|
||||
dma->nr_pages = nr_pages;
|
||||
|
||||
return 0;
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(videobuf_dma_init_kernel);
|
||||
|
||||
int videobuf_dma_init_overlay(struct videobuf_dmabuf *dma, int direction,
|
||||
dma_addr_t addr, int nr_pages)
|
||||
@ -210,13 +224,16 @@ int videobuf_dma_init_overlay(struct videobuf_dmabuf *dma, int direction,
|
||||
dprintk(1, "init overlay [%d pages @ bus 0x%lx]\n",
|
||||
nr_pages, (unsigned long)addr);
|
||||
dma->direction = direction;
|
||||
|
||||
if (0 == addr)
|
||||
return -EINVAL;
|
||||
|
||||
dma->bus_addr = addr;
|
||||
dma->nr_pages = nr_pages;
|
||||
|
||||
return 0;
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(videobuf_dma_init_overlay);
|
||||
|
||||
int videobuf_dma_map(struct videobuf_queue *q, struct videobuf_dmabuf *dma)
|
||||
{
|
||||
@ -228,14 +245,15 @@ int videobuf_dma_map(struct videobuf_queue* q, struct videobuf_dmabuf *dma)
|
||||
dma->offset);
|
||||
}
|
||||
if (dma->vmalloc) {
|
||||
dma->sglist = videobuf_vmalloc_to_sg
|
||||
(dma->vmalloc,dma->nr_pages);
|
||||
dma->sglist = videobuf_vmalloc_to_sg(dma->vmalloc,
|
||||
dma->nr_pages);
|
||||
}
|
||||
if (dma->bus_addr) {
|
||||
dma->sglist = vmalloc(sizeof(*dma->sglist));
|
||||
if (NULL != dma->sglist) {
|
||||
dma->sglen = 1;
|
||||
sg_dma_address(&dma->sglist[0]) = dma->bus_addr & PAGE_MASK;
|
||||
sg_dma_address(&dma->sglist[0]) = dma->bus_addr
|
||||
& PAGE_MASK;
|
||||
dma->sglist[0].offset = dma->bus_addr & ~PAGE_MASK;
|
||||
sg_dma_len(&dma->sglist[0]) = dma->nr_pages * PAGE_SIZE;
|
||||
}
|
||||
@ -256,8 +274,10 @@ int videobuf_dma_map(struct videobuf_queue* q, struct videobuf_dmabuf *dma)
|
||||
return -ENOMEM;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(videobuf_dma_map);
|
||||
|
||||
int videobuf_dma_sync(struct videobuf_queue *q, struct videobuf_dmabuf *dma)
|
||||
{
|
||||
@ -265,12 +285,15 @@ int videobuf_dma_sync(struct videobuf_queue *q, struct videobuf_dmabuf *dma)
|
||||
BUG_ON(!dma->sglen);
|
||||
|
||||
dma_sync_sg_for_cpu(q->dev, dma->sglist, dma->nr_pages, dma->direction);
|
||||
|
||||
return 0;
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(videobuf_dma_sync);
|
||||
|
||||
int videobuf_dma_unmap(struct videobuf_queue *q, struct videobuf_dmabuf *dma)
|
||||
{
|
||||
MAGIC_CHECK(dma->magic, MAGIC_DMABUF);
|
||||
|
||||
if (!dma->sglen)
|
||||
return 0;
|
||||
|
||||
@ -279,16 +302,18 @@ int videobuf_dma_unmap(struct videobuf_queue* q,struct videobuf_dmabuf *dma)
|
||||
vfree(dma->sglist);
|
||||
dma->sglist = NULL;
|
||||
dma->sglen = 0;
|
||||
|
||||
return 0;
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(videobuf_dma_unmap);
|
||||
|
||||
int videobuf_dma_free(struct videobuf_dmabuf *dma)
|
||||
{
|
||||
int i;
|
||||
MAGIC_CHECK(dma->magic, MAGIC_DMABUF);
|
||||
BUG_ON(dma->sglen);
|
||||
|
||||
if (dma->pages) {
|
||||
int i;
|
||||
for (i = 0; i < dma->nr_pages; i++)
|
||||
page_cache_release(dma->pages[i]);
|
||||
kfree(dma->pages);
|
||||
@ -298,12 +323,13 @@ int videobuf_dma_free(struct videobuf_dmabuf *dma)
|
||||
vfree(dma->vmalloc);
|
||||
dma->vmalloc = NULL;
|
||||
|
||||
if (dma->bus_addr) {
|
||||
if (dma->bus_addr)
|
||||
dma->bus_addr = 0;
|
||||
}
|
||||
dma->direction = DMA_NONE;
|
||||
|
||||
return 0;
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(videobuf_dma_free);
|
||||
|
||||
/* --------------------------------------------------------------------- */
|
||||
|
||||
@ -315,6 +341,7 @@ int videobuf_sg_dma_map(struct device *dev, struct videobuf_dmabuf *dma)
|
||||
|
||||
return videobuf_dma_map(&q, dma);
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(videobuf_sg_dma_map);
|
||||
|
||||
int videobuf_sg_dma_unmap(struct device *dev, struct videobuf_dmabuf *dma)
|
||||
{
|
||||
@ -324,21 +351,21 @@ int videobuf_sg_dma_unmap(struct device *dev, struct videobuf_dmabuf *dma)
|
||||
|
||||
return videobuf_dma_unmap(&q, dma);
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(videobuf_sg_dma_unmap);
|
||||
|
||||
/* --------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
videobuf_vm_open(struct vm_area_struct *vma)
|
||||
static void videobuf_vm_open(struct vm_area_struct *vma)
|
||||
{
|
||||
struct videobuf_mapping *map = vma->vm_private_data;
|
||||
|
||||
dprintk(2, "vm_open %p [count=%d,vma=%08lx-%08lx]\n", map,
|
||||
map->count, vma->vm_start, vma->vm_end);
|
||||
|
||||
map->count++;
|
||||
}
|
||||
|
||||
static void
|
||||
videobuf_vm_close(struct vm_area_struct *vma)
|
||||
static void videobuf_vm_close(struct vm_area_struct *vma)
|
||||
{
|
||||
struct videobuf_mapping *map = vma->vm_private_data;
|
||||
struct videobuf_queue *q = map->q;
|
||||
@ -356,7 +383,6 @@ videobuf_vm_close(struct vm_area_struct *vma)
|
||||
if (NULL == q->bufs[i])
|
||||
continue;
|
||||
mem = q->bufs[i]->priv;
|
||||
|
||||
if (!mem)
|
||||
continue;
|
||||
|
||||
@ -380,23 +406,24 @@ videobuf_vm_close(struct vm_area_struct *vma)
|
||||
* now ...). Bounce buffers don't work very well for the data rates
|
||||
* video capture has.
|
||||
*/
|
||||
static int
|
||||
videobuf_vm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
|
||||
static int videobuf_vm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
|
||||
{
|
||||
struct page *page;
|
||||
|
||||
dprintk(3, "fault: fault @ %08lx [vma %08lx-%08lx]\n",
|
||||
(unsigned long)vmf->virtual_address,vma->vm_start,vma->vm_end);
|
||||
(unsigned long)vmf->virtual_address,
|
||||
vma->vm_start, vma->vm_end);
|
||||
|
||||
page = alloc_page(GFP_USER | __GFP_DMA32);
|
||||
if (!page)
|
||||
return VM_FAULT_OOM;
|
||||
clear_user_highpage(page, (unsigned long)vmf->virtual_address);
|
||||
vmf->page = page;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const struct vm_operations_struct videobuf_vm_ops =
|
||||
{
|
||||
static const struct vm_operations_struct videobuf_vm_ops = {
|
||||
.open = videobuf_vm_open,
|
||||
.close = videobuf_vm_close,
|
||||
.fault = videobuf_vm_fault,
|
||||
@ -702,6 +729,7 @@ void *videobuf_sg_alloc(size_t size)
|
||||
|
||||
return videobuf_alloc(&q);
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(videobuf_sg_alloc);
|
||||
|
||||
void videobuf_queue_sg_init(struct videobuf_queue *q,
|
||||
const struct videobuf_queue_ops *ops,
|
||||
@ -715,29 +743,5 @@ void videobuf_queue_sg_init(struct videobuf_queue* q,
|
||||
videobuf_queue_core_init(q, ops, dev, irqlock, type, field, msize,
|
||||
priv, &sg_ops);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------- */
|
||||
|
||||
EXPORT_SYMBOL_GPL(videobuf_vmalloc_to_sg);
|
||||
|
||||
EXPORT_SYMBOL_GPL(videobuf_to_dma);
|
||||
EXPORT_SYMBOL_GPL(videobuf_dma_init);
|
||||
EXPORT_SYMBOL_GPL(videobuf_dma_init_user);
|
||||
EXPORT_SYMBOL_GPL(videobuf_dma_init_kernel);
|
||||
EXPORT_SYMBOL_GPL(videobuf_dma_init_overlay);
|
||||
EXPORT_SYMBOL_GPL(videobuf_dma_map);
|
||||
EXPORT_SYMBOL_GPL(videobuf_dma_sync);
|
||||
EXPORT_SYMBOL_GPL(videobuf_dma_unmap);
|
||||
EXPORT_SYMBOL_GPL(videobuf_dma_free);
|
||||
|
||||
EXPORT_SYMBOL_GPL(videobuf_sg_dma_map);
|
||||
EXPORT_SYMBOL_GPL(videobuf_sg_dma_unmap);
|
||||
EXPORT_SYMBOL_GPL(videobuf_sg_alloc);
|
||||
|
||||
EXPORT_SYMBOL_GPL(videobuf_queue_sg_init);
|
||||
|
||||
/*
|
||||
* Local variables:
|
||||
* c-basic-offset: 8
|
||||
* End:
|
||||
*/
|
||||
|
@ -30,8 +30,12 @@
|
||||
#define MAGIC_DMABUF 0x17760309
|
||||
#define MAGIC_VMAL_MEM 0x18221223
|
||||
|
||||
#define MAGIC_CHECK(is,should) if (unlikely((is) != (should))) \
|
||||
{ printk(KERN_ERR "magic mismatch: %x (expected %x)\n",is,should); BUG(); }
|
||||
#define MAGIC_CHECK(is, should) \
|
||||
if (unlikely((is) != (should))) { \
|
||||
printk(KERN_ERR "magic mismatch: %x (expected %x)\n", \
|
||||
is, should); \
|
||||
BUG(); \
|
||||
}
|
||||
|
||||
static int debug;
|
||||
module_param(debug, int, 0644);
|
||||
@ -40,14 +44,14 @@ MODULE_DESCRIPTION("helper module to manage video4linux vmalloc buffers");
|
||||
MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@infradead.org>");
|
||||
MODULE_LICENSE("GPL");
|
||||
|
||||
#define dprintk(level, fmt, arg...) if (debug >= level) \
|
||||
#define dprintk(level, fmt, arg...) \
|
||||
if (debug >= level) \
|
||||
printk(KERN_DEBUG "vbuf-vmalloc: " fmt , ## arg)
|
||||
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
static void
|
||||
videobuf_vm_open(struct vm_area_struct *vma)
|
||||
static void videobuf_vm_open(struct vm_area_struct *vma)
|
||||
{
|
||||
struct videobuf_mapping *map = vma->vm_private_data;
|
||||
|
||||
@ -116,8 +120,7 @@ static void videobuf_vm_close(struct vm_area_struct *vma)
|
||||
return;
|
||||
}
|
||||
|
||||
static const struct vm_operations_struct videobuf_vm_ops =
|
||||
{
|
||||
static const struct vm_operations_struct videobuf_vm_ops = {
|
||||
.open = videobuf_vm_open,
|
||||
.close = videobuf_vm_close,
|
||||
};
|
||||
@ -177,15 +180,13 @@ static int __videobuf_iolock (struct videobuf_queue* q,
|
||||
|
||||
dprintk(1, "%s memory method USERPTR\n", __func__);
|
||||
|
||||
#if 1
|
||||
if (vb->baddr) {
|
||||
printk(KERN_ERR "USERPTR is currently not supported\n");
|
||||
return -EINVAL;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* The only USERPTR currently supported is the one needed for
|
||||
read() method.
|
||||
* read() method.
|
||||
*/
|
||||
|
||||
mem->vmalloc = vmalloc_user(pages);
|
||||
@ -210,7 +211,7 @@ static int __videobuf_iolock (struct videobuf_queue* q,
|
||||
/* Try to remap memory */
|
||||
rc = remap_vmalloc_range(mem->vma, (void *)vb->baddr, 0);
|
||||
if (rc < 0) {
|
||||
printk(KERN_ERR "mmap: remap failed with error %d. ", rc);
|
||||
printk(KERN_ERR "mmap: remap failed with error %d", rc);
|
||||
return -ENOMEM;
|
||||
}
|
||||
#endif
|
||||
@ -300,8 +301,7 @@ static int __videobuf_mmap_mapper(struct videobuf_queue *q,
|
||||
printk(KERN_ERR "vmalloc (%d pages) failed\n", pages);
|
||||
goto error;
|
||||
}
|
||||
dprintk(1, "vmalloc is at addr %p (%d pages)\n",
|
||||
mem->vmalloc, pages);
|
||||
dprintk(1, "vmalloc is at addr %p (%d pages)\n", mem->vmalloc, pages);
|
||||
|
||||
/* Try to remap memory */
|
||||
retval = remap_vmalloc_range(vma, mem->vmalloc, 0);
|
||||
@ -404,7 +404,6 @@ void videobuf_queue_vmalloc_init(struct videobuf_queue* q,
|
||||
videobuf_queue_core_init(q, ops, dev, irqlock, type, field, msize,
|
||||
priv, &qops);
|
||||
}
|
||||
|
||||
EXPORT_SYMBOL_GPL(videobuf_queue_vmalloc_init);
|
||||
|
||||
void *videobuf_to_vmalloc(struct videobuf_buffer *buf)
|
||||
@ -442,8 +441,3 @@ void videobuf_vmalloc_free (struct videobuf_buffer *buf)
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(videobuf_vmalloc_free);
|
||||
|
||||
/*
|
||||
* Local variables:
|
||||
* c-basic-offset: 8
|
||||
* End:
|
||||
*/
|
||||
|
@ -17,6 +17,8 @@
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2
|
||||
*/
|
||||
#ifndef _VIDEOBUF_DMA_SG_H
|
||||
#define _VIDEOBUF_DMA_SG_H
|
||||
|
||||
#include <media/videobuf-core.h>
|
||||
|
||||
@ -78,8 +80,7 @@ struct videobuf_dmabuf {
|
||||
int direction;
|
||||
};
|
||||
|
||||
struct videobuf_dma_sg_memory
|
||||
{
|
||||
struct videobuf_dma_sg_memory {
|
||||
u32 magic;
|
||||
|
||||
/* for mmap'ed buffers */
|
||||
@ -117,3 +118,5 @@ void videobuf_queue_sg_init(struct videobuf_queue* q,
|
||||
int videobuf_sg_dma_map(struct device *dev, struct videobuf_dmabuf *dma);
|
||||
int videobuf_sg_dma_unmap(struct device *dev, struct videobuf_dmabuf *dma);
|
||||
|
||||
#endif /* _VIDEOBUF_DMA_SG_H */
|
||||
|
||||
|
@ -19,13 +19,13 @@
|
||||
|
||||
/* --------------------------------------------------------------------- */
|
||||
|
||||
struct videobuf_vmalloc_memory
|
||||
{
|
||||
struct videobuf_vmalloc_memory {
|
||||
u32 magic;
|
||||
|
||||
void *vmalloc;
|
||||
|
||||
/* remap_vmalloc_range seems to need to run after mmap() on some cases */
|
||||
/* remap_vmalloc_range seems to need to run
|
||||
* after mmap() on some cases */
|
||||
struct vm_area_struct *vma;
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user