V4L/DVB (6266): videobuf cleanup: mmap check is common to all videobuf. Make it at core

Signed-off-by: Mauro Carvalho Chehab <mchehab@infradead.org>
http://thread.gmane.org/gmane.comp.video.video4linux/34978/focus=34981
Reviewed-by: Ricardo Cerqueira <v4l@cerqueira.org>
This commit is contained in:
Mauro Carvalho Chehab 2007-09-27 18:25:44 -03:00
parent cd4765efdd
commit 851c0c96b2
6 changed files with 20 additions and 52 deletions

View file

@ -149,7 +149,7 @@ int videobuf_queue_is_busy(struct videobuf_queue *q)
for (i = 0; i < VIDEO_MAX_FRAME; i++) { for (i = 0; i < VIDEO_MAX_FRAME; i++) {
if (NULL == q->bufs[i]) if (NULL == q->bufs[i])
continue; continue;
if (CALL(q,is_mmapped,q->bufs[i])) { if (q->bufs[i]->map) {
dprintk(1,"busy: buffer #%d mapped\n",i); dprintk(1,"busy: buffer #%d mapped\n",i);
return 1; return 1;
} }
@ -238,7 +238,7 @@ static void videobuf_status(struct videobuf_queue *q, struct v4l2_buffer *b,
} }
b->flags = 0; b->flags = 0;
if (CALL(q,is_mmapped,vb)) if (vb->map)
b->flags |= V4L2_BUF_FLAG_MAPPED; b->flags |= V4L2_BUF_FLAG_MAPPED;
switch (vb->state) { switch (vb->state) {

View file

@ -374,9 +374,9 @@ videobuf_vm_close(struct vm_area_struct *vma)
MAGIC_CHECK(mem->magic,MAGIC_SG_MEM); MAGIC_CHECK(mem->magic,MAGIC_SG_MEM);
if (mem->map != map) if (q->bufs[i]->map != map)
continue; continue;
mem->map = NULL; q->bufs[i]->map = NULL;
q->bufs[i]->baddr = 0; q->bufs[i]->baddr = 0;
q->ops->buf_release(q,q->bufs[i]); q->ops->buf_release(q,q->bufs[i]);
} }
@ -520,8 +520,7 @@ static int __videobuf_mmap_free(struct videobuf_queue *q)
for (i = 0; i < VIDEO_MAX_FRAME; i++) { for (i = 0; i < VIDEO_MAX_FRAME; i++) {
if (q->bufs[i]) { if (q->bufs[i]) {
struct videbuf_pci_sg_memory *mem=q->bufs[i]->priv; if (q->bufs[i]->map)
if (mem && mem->map)
return -EBUSY; return -EBUSY;
} }
} }
@ -572,8 +571,7 @@ static int __videobuf_mmap_mapper(struct videobuf_queue *q,
continue; continue;
if (V4L2_MEMORY_MMAP != q->bufs[last]->memory) if (V4L2_MEMORY_MMAP != q->bufs[last]->memory)
continue; continue;
mem=q->bufs[last]->priv; if (q->bufs[last]->map) {
if (mem->map) {
retval = -EBUSY; retval = -EBUSY;
goto done; goto done;
} }
@ -593,8 +591,7 @@ static int __videobuf_mmap_mapper(struct videobuf_queue *q,
if (NULL == map) if (NULL == map)
goto done; goto done;
for (size = 0, i = first; i <= last; size += q->bufs[i++]->bsize) { for (size = 0, i = first; i <= last; size += q->bufs[i++]->bsize) {
mem=q->bufs[i]->priv; q->bufs[i]->map = map;
mem->map = map;
q->bufs[i]->baddr = vma->vm_start + size; q->bufs[i]->baddr = vma->vm_start + size;
} }
map->count = 1; map->count = 1;
@ -613,16 +610,6 @@ static int __videobuf_mmap_mapper(struct videobuf_queue *q,
return retval; return retval;
} }
static int __videobuf_is_mmapped (struct videobuf_buffer *buf)
{
struct videbuf_pci_sg_memory *mem=buf->priv;
BUG_ON (!mem);
MAGIC_CHECK(mem->magic,MAGIC_SG_MEM);
return (mem->map)?1:0;
}
static int __videobuf_copy_to_user ( struct videobuf_queue *q, static int __videobuf_copy_to_user ( struct videobuf_queue *q,
char __user *data, size_t count, char __user *data, size_t count,
int nonblocking ) int nonblocking )
@ -678,7 +665,6 @@ static struct videobuf_qtype_ops pci_ops = {
.sync = __videobuf_sync, .sync = __videobuf_sync,
.mmap_free = __videobuf_mmap_free, .mmap_free = __videobuf_mmap_free,
.mmap_mapper = __videobuf_mmap_mapper, .mmap_mapper = __videobuf_mmap_mapper,
.is_mmapped = __videobuf_is_mmapped,
.copy_to_user = __videobuf_copy_to_user, .copy_to_user = __videobuf_copy_to_user,
.copy_stream = __videobuf_copy_stream, .copy_stream = __videobuf_copy_stream,
}; };

View file

@ -62,7 +62,6 @@ videobuf_vm_close(struct vm_area_struct *vma)
{ {
struct videobuf_mapping *map = vma->vm_private_data; struct videobuf_mapping *map = vma->vm_private_data;
struct videobuf_queue *q = map->q; struct videobuf_queue *q = map->q;
struct videbuf_vmalloc_memory *mem;
int i; int i;
dprintk(2,"vm_close %p [count=%d,vma=%08lx-%08lx]\n",map, dprintk(2,"vm_close %p [count=%d,vma=%08lx-%08lx]\n",map,
@ -75,19 +74,13 @@ videobuf_vm_close(struct vm_area_struct *vma)
for (i = 0; i < VIDEO_MAX_FRAME; i++) { for (i = 0; i < VIDEO_MAX_FRAME; i++) {
if (NULL == q->bufs[i]) if (NULL == q->bufs[i])
continue; continue;
mem=q->bufs[i]->priv;
if (!mem) if (q->bufs[i]->map != map)
continue;
MAGIC_CHECK(mem->magic,MAGIC_VMAL_MEM);
if (mem->map != map)
continue; continue;
q->ops->buf_release(q,q->bufs[i]); q->ops->buf_release(q,q->bufs[i]);
mem->map = NULL; q->bufs[i]->map = NULL;
q->bufs[i]->baddr = 0; q->bufs[i]->baddr = 0;
} }
mutex_unlock(&q->lock); mutex_unlock(&q->lock);
@ -191,8 +184,7 @@ static int __videobuf_mmap_free(struct videobuf_queue *q)
for (i = 0; i < VIDEO_MAX_FRAME; i++) { for (i = 0; i < VIDEO_MAX_FRAME; i++) {
if (q->bufs[i]) { if (q->bufs[i]) {
struct videbuf_vmalloc_memory *mem=q->bufs[i]->priv; if (q->bufs[i]->map)
if (mem && mem->map)
return -EBUSY; return -EBUSY;
} }
} }
@ -227,12 +219,9 @@ static int __videobuf_mmap_mapper(struct videobuf_queue *q,
(vma->vm_pgoff << PAGE_SHIFT)); (vma->vm_pgoff << PAGE_SHIFT));
return -EINVAL; return -EINVAL;
} }
mem=q->bufs[first]->priv;
BUG_ON (!mem);
MAGIC_CHECK(mem->magic,MAGIC_VMAL_MEM);
/* create mapping + update buffer list */ /* create mapping + update buffer list */
map = mem->map = kmalloc(sizeof(struct videobuf_mapping),GFP_KERNEL); map = q->bufs[first]->map = kmalloc(sizeof(struct videobuf_mapping),GFP_KERNEL);
if (NULL == map) if (NULL == map)
return -ENOMEM; return -ENOMEM;
@ -246,14 +235,19 @@ static int __videobuf_mmap_mapper(struct videobuf_queue *q,
vma->vm_flags |= VM_DONTEXPAND | VM_RESERVED; vma->vm_flags |= VM_DONTEXPAND | VM_RESERVED;
vma->vm_private_data = map; vma->vm_private_data = map;
mem=q->bufs[first]->priv;
BUG_ON (!mem);
MAGIC_CHECK(mem->magic,MAGIC_VMAL_MEM);
/* Try to remap memory */ /* Try to remap memory */
retval=remap_vmalloc_range(vma, mem->vmalloc,0); retval=remap_vmalloc_range(vma, mem->vmalloc,0);
if (retval<0) { if (retval<0) {
dprintk(1,"mmap: postponing remap_vmalloc_range\n"); dprintk(1,"mmap: postponing remap_vmalloc_range\n");
mem->vma=kmalloc(sizeof(*vma),GFP_KERNEL); mem->vma=kmalloc(sizeof(*vma),GFP_KERNEL);
if (!mem->vma) { if (!mem->vma) {
kfree(map); kfree(map);
mem->map=NULL; q->bufs[first]->map=NULL;
return -ENOMEM; return -ENOMEM;
} }
memcpy(mem->vma,vma,sizeof(*vma)); memcpy(mem->vma,vma,sizeof(*vma));
@ -269,15 +263,6 @@ static int __videobuf_mmap_mapper(struct videobuf_queue *q,
return (0); return (0);
} }
static int __videobuf_is_mmapped (struct videobuf_buffer *buf)
{
struct videbuf_vmalloc_memory *mem=buf->priv;
BUG_ON (!mem);
MAGIC_CHECK(mem->magic,MAGIC_VMAL_MEM);
return (mem->map)?1:0;
}
static int __videobuf_copy_to_user ( struct videobuf_queue *q, static int __videobuf_copy_to_user ( struct videobuf_queue *q,
char __user *data, size_t count, char __user *data, size_t count,
int nonblocking ) int nonblocking )
@ -335,7 +320,6 @@ static struct videobuf_qtype_ops qops = {
.sync = __videobuf_sync, .sync = __videobuf_sync,
.mmap_free = __videobuf_mmap_free, .mmap_free = __videobuf_mmap_free,
.mmap_mapper = __videobuf_mmap_mapper, .mmap_mapper = __videobuf_mmap_mapper,
.is_mmapped = __videobuf_is_mmapped,
.copy_to_user = __videobuf_copy_to_user, .copy_to_user = __videobuf_copy_to_user,
.copy_stream = __videobuf_copy_stream, .copy_stream = __videobuf_copy_stream,
}; };

View file

@ -97,6 +97,9 @@ struct videobuf_buffer {
/* buffer addr (userland ptr!) */ /* buffer addr (userland ptr!) */
unsigned long baddr; unsigned long baddr;
/* for mmap'ed buffers */
struct videobuf_mapping *map;
/* Private pointer to allow specific methods to store their data */ /* Private pointer to allow specific methods to store their data */
int privsize; int privsize;
void *priv; void *priv;
@ -143,7 +146,6 @@ struct videobuf_qtype_ops {
int (*mmap_free) (struct videobuf_queue *q); int (*mmap_free) (struct videobuf_queue *q);
int (*mmap_mapper) (struct videobuf_queue *q, int (*mmap_mapper) (struct videobuf_queue *q,
struct vm_area_struct *vma); struct vm_area_struct *vma);
int (*is_mmapped) (struct videobuf_buffer *buf);
}; };
struct videobuf_queue { struct videobuf_queue {

View file

@ -86,7 +86,6 @@ struct videbuf_pci_sg_memory
u32 magic; u32 magic;
/* for mmap'ed buffers */ /* for mmap'ed buffers */
struct videobuf_mapping *map;
struct videobuf_dmabuf dma; struct videobuf_dmabuf dma;
}; };

View file

@ -21,9 +21,6 @@ struct videbuf_vmalloc_memory
{ {
u32 magic; u32 magic;
/* for mmap'ed buffers */
struct videobuf_mapping *map;
void *vmalloc; 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 */