aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorMauro Carvalho Chehab <mchehab@infradead.org>2007-09-27 17:25:44 -0400
committerMauro Carvalho Chehab <mchehab@infradead.org>2007-10-09 23:02:55 -0400
commit851c0c96b2212f48fe51afc1589541b5eae3a544 (patch)
tree0ec4d6019033242fb75e717ca05c1f04d2eca934 /drivers
parentcd4765efdd816ac14075fc7d5adf489502e75e1e (diff)
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>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/media/video/videobuf-core.c4
-rw-r--r--drivers/media/video/videobuf-dma-sg.c24
-rw-r--r--drivers/media/video/videobuf-vmalloc.c36
3 files changed, 17 insertions, 47 deletions
diff --git a/drivers/media/video/videobuf-core.c b/drivers/media/video/videobuf-core.c
index eb3b98400c1b..3bd06bb633a7 100644
--- a/drivers/media/video/videobuf-core.c
+++ b/drivers/media/video/videobuf-core.c
@@ -149,7 +149,7 @@ int videobuf_queue_is_busy(struct videobuf_queue *q)
149 for (i = 0; i < VIDEO_MAX_FRAME; i++) { 149 for (i = 0; i < VIDEO_MAX_FRAME; i++) {
150 if (NULL == q->bufs[i]) 150 if (NULL == q->bufs[i])
151 continue; 151 continue;
152 if (CALL(q,is_mmapped,q->bufs[i])) { 152 if (q->bufs[i]->map) {
153 dprintk(1,"busy: buffer #%d mapped\n",i); 153 dprintk(1,"busy: buffer #%d mapped\n",i);
154 return 1; 154 return 1;
155 } 155 }
@@ -238,7 +238,7 @@ static void videobuf_status(struct videobuf_queue *q, struct v4l2_buffer *b,
238 } 238 }
239 239
240 b->flags = 0; 240 b->flags = 0;
241 if (CALL(q,is_mmapped,vb)) 241 if (vb->map)
242 b->flags |= V4L2_BUF_FLAG_MAPPED; 242 b->flags |= V4L2_BUF_FLAG_MAPPED;
243 243
244 switch (vb->state) { 244 switch (vb->state) {
diff --git a/drivers/media/video/videobuf-dma-sg.c b/drivers/media/video/videobuf-dma-sg.c
index 3345877c47d4..0939ede831ab 100644
--- a/drivers/media/video/videobuf-dma-sg.c
+++ b/drivers/media/video/videobuf-dma-sg.c
@@ -374,9 +374,9 @@ videobuf_vm_close(struct vm_area_struct *vma)
374 374
375 MAGIC_CHECK(mem->magic,MAGIC_SG_MEM); 375 MAGIC_CHECK(mem->magic,MAGIC_SG_MEM);
376 376
377 if (mem->map != map) 377 if (q->bufs[i]->map != map)
378 continue; 378 continue;
379 mem->map = NULL; 379 q->bufs[i]->map = NULL;
380 q->bufs[i]->baddr = 0; 380 q->bufs[i]->baddr = 0;
381 q->ops->buf_release(q,q->bufs[i]); 381 q->ops->buf_release(q,q->bufs[i]);
382 } 382 }
@@ -520,8 +520,7 @@ static int __videobuf_mmap_free(struct videobuf_queue *q)
520 520
521 for (i = 0; i < VIDEO_MAX_FRAME; i++) { 521 for (i = 0; i < VIDEO_MAX_FRAME; i++) {
522 if (q->bufs[i]) { 522 if (q->bufs[i]) {
523 struct videbuf_pci_sg_memory *mem=q->bufs[i]->priv; 523 if (q->bufs[i]->map)
524 if (mem && mem->map)
525 return -EBUSY; 524 return -EBUSY;
526 } 525 }
527 } 526 }
@@ -572,8 +571,7 @@ static int __videobuf_mmap_mapper(struct videobuf_queue *q,
572 continue; 571 continue;
573 if (V4L2_MEMORY_MMAP != q->bufs[last]->memory) 572 if (V4L2_MEMORY_MMAP != q->bufs[last]->memory)
574 continue; 573 continue;
575 mem=q->bufs[last]->priv; 574 if (q->bufs[last]->map) {
576 if (mem->map) {
577 retval = -EBUSY; 575 retval = -EBUSY;
578 goto done; 576 goto done;
579 } 577 }
@@ -593,8 +591,7 @@ static int __videobuf_mmap_mapper(struct videobuf_queue *q,
593 if (NULL == map) 591 if (NULL == map)
594 goto done; 592 goto done;
595 for (size = 0, i = first; i <= last; size += q->bufs[i++]->bsize) { 593 for (size = 0, i = first; i <= last; size += q->bufs[i++]->bsize) {
596 mem=q->bufs[i]->priv; 594 q->bufs[i]->map = map;
597 mem->map = map;
598 q->bufs[i]->baddr = vma->vm_start + size; 595 q->bufs[i]->baddr = vma->vm_start + size;
599 } 596 }
600 map->count = 1; 597 map->count = 1;
@@ -613,16 +610,6 @@ static int __videobuf_mmap_mapper(struct videobuf_queue *q,
613 return retval; 610 return retval;
614} 611}
615 612
616static int __videobuf_is_mmapped (struct videobuf_buffer *buf)
617{
618 struct videbuf_pci_sg_memory *mem=buf->priv;
619
620 BUG_ON (!mem);
621 MAGIC_CHECK(mem->magic,MAGIC_SG_MEM);
622
623 return (mem->map)?1:0;
624}
625
626static int __videobuf_copy_to_user ( struct videobuf_queue *q, 613static int __videobuf_copy_to_user ( struct videobuf_queue *q,
627 char __user *data, size_t count, 614 char __user *data, size_t count,
628 int nonblocking ) 615 int nonblocking )
@@ -678,7 +665,6 @@ static struct videobuf_qtype_ops pci_ops = {
678 .sync = __videobuf_sync, 665 .sync = __videobuf_sync,
679 .mmap_free = __videobuf_mmap_free, 666 .mmap_free = __videobuf_mmap_free,
680 .mmap_mapper = __videobuf_mmap_mapper, 667 .mmap_mapper = __videobuf_mmap_mapper,
681 .is_mmapped = __videobuf_is_mmapped,
682 .copy_to_user = __videobuf_copy_to_user, 668 .copy_to_user = __videobuf_copy_to_user,
683 .copy_stream = __videobuf_copy_stream, 669 .copy_stream = __videobuf_copy_stream,
684}; 670};
diff --git a/drivers/media/video/videobuf-vmalloc.c b/drivers/media/video/videobuf-vmalloc.c
index fd059cde63f4..c9d6ae0d3b49 100644
--- a/drivers/media/video/videobuf-vmalloc.c
+++ b/drivers/media/video/videobuf-vmalloc.c
@@ -62,7 +62,6 @@ videobuf_vm_close(struct vm_area_struct *vma)
62{ 62{
63 struct videobuf_mapping *map = vma->vm_private_data; 63 struct videobuf_mapping *map = vma->vm_private_data;
64 struct videobuf_queue *q = map->q; 64 struct videobuf_queue *q = map->q;
65 struct videbuf_vmalloc_memory *mem;
66 int i; 65 int i;
67 66
68 dprintk(2,"vm_close %p [count=%d,vma=%08lx-%08lx]\n",map, 67 dprintk(2,"vm_close %p [count=%d,vma=%08lx-%08lx]\n",map,
@@ -75,19 +74,13 @@ videobuf_vm_close(struct vm_area_struct *vma)
75 for (i = 0; i < VIDEO_MAX_FRAME; i++) { 74 for (i = 0; i < VIDEO_MAX_FRAME; i++) {
76 if (NULL == q->bufs[i]) 75 if (NULL == q->bufs[i])
77 continue; 76 continue;
78 mem=q->bufs[i]->priv;
79 77
80 if (!mem) 78 if (q->bufs[i]->map != map)
81 continue;
82
83 MAGIC_CHECK(mem->magic,MAGIC_VMAL_MEM);
84
85 if (mem->map != map)
86 continue; 79 continue;
87 80
88 q->ops->buf_release(q,q->bufs[i]); 81 q->ops->buf_release(q,q->bufs[i]);
89 82
90 mem->map = NULL; 83 q->bufs[i]->map = NULL;
91 q->bufs[i]->baddr = 0; 84 q->bufs[i]->baddr = 0;
92 } 85 }
93 mutex_unlock(&q->lock); 86 mutex_unlock(&q->lock);
@@ -191,8 +184,7 @@ static int __videobuf_mmap_free(struct videobuf_queue *q)
191 184
192 for (i = 0; i < VIDEO_MAX_FRAME; i++) { 185 for (i = 0; i < VIDEO_MAX_FRAME; i++) {
193 if (q->bufs[i]) { 186 if (q->bufs[i]) {
194 struct videbuf_vmalloc_memory *mem=q->bufs[i]->priv; 187 if (q->bufs[i]->map)
195 if (mem && mem->map)
196 return -EBUSY; 188 return -EBUSY;
197 } 189 }
198 } 190 }
@@ -227,12 +219,9 @@ static int __videobuf_mmap_mapper(struct videobuf_queue *q,
227 (vma->vm_pgoff << PAGE_SHIFT)); 219 (vma->vm_pgoff << PAGE_SHIFT));
228 return -EINVAL; 220 return -EINVAL;
229 } 221 }
230 mem=q->bufs[first]->priv;
231 BUG_ON (!mem);
232 MAGIC_CHECK(mem->magic,MAGIC_VMAL_MEM);
233 222
234 /* create mapping + update buffer list */ 223 /* create mapping + update buffer list */
235 map = mem->map = kmalloc(sizeof(struct videobuf_mapping),GFP_KERNEL); 224 map = q->bufs[first]->map = kmalloc(sizeof(struct videobuf_mapping),GFP_KERNEL);
236 if (NULL == map) 225 if (NULL == map)
237 return -ENOMEM; 226 return -ENOMEM;
238 227
@@ -246,14 +235,19 @@ static int __videobuf_mmap_mapper(struct videobuf_queue *q,
246 vma->vm_flags |= VM_DONTEXPAND | VM_RESERVED; 235 vma->vm_flags |= VM_DONTEXPAND | VM_RESERVED;
247 vma->vm_private_data = map; 236 vma->vm_private_data = map;
248 237
238 mem=q->bufs[first]->priv;
239 BUG_ON (!mem);
240 MAGIC_CHECK(mem->magic,MAGIC_VMAL_MEM);
241
249 /* Try to remap memory */ 242 /* Try to remap memory */
250 retval=remap_vmalloc_range(vma, mem->vmalloc,0); 243 retval=remap_vmalloc_range(vma, mem->vmalloc,0);
251 if (retval<0) { 244 if (retval<0) {
252 dprintk(1,"mmap: postponing remap_vmalloc_range\n"); 245 dprintk(1,"mmap: postponing remap_vmalloc_range\n");
246
253 mem->vma=kmalloc(sizeof(*vma),GFP_KERNEL); 247 mem->vma=kmalloc(sizeof(*vma),GFP_KERNEL);
254 if (!mem->vma) { 248 if (!mem->vma) {
255 kfree(map); 249 kfree(map);
256 mem->map=NULL; 250 q->bufs[first]->map=NULL;
257 return -ENOMEM; 251 return -ENOMEM;
258 } 252 }
259 memcpy(mem->vma,vma,sizeof(*vma)); 253 memcpy(mem->vma,vma,sizeof(*vma));
@@ -269,15 +263,6 @@ static int __videobuf_mmap_mapper(struct videobuf_queue *q,
269 return (0); 263 return (0);
270} 264}
271 265
272static int __videobuf_is_mmapped (struct videobuf_buffer *buf)
273{
274 struct videbuf_vmalloc_memory *mem=buf->priv;
275 BUG_ON (!mem);
276 MAGIC_CHECK(mem->magic,MAGIC_VMAL_MEM);
277
278 return (mem->map)?1:0;
279}
280
281static int __videobuf_copy_to_user ( struct videobuf_queue *q, 266static int __videobuf_copy_to_user ( struct videobuf_queue *q,
282 char __user *data, size_t count, 267 char __user *data, size_t count,
283 int nonblocking ) 268 int nonblocking )
@@ -335,7 +320,6 @@ static struct videobuf_qtype_ops qops = {
335 .sync = __videobuf_sync, 320 .sync = __videobuf_sync,
336 .mmap_free = __videobuf_mmap_free, 321 .mmap_free = __videobuf_mmap_free,
337 .mmap_mapper = __videobuf_mmap_mapper, 322 .mmap_mapper = __videobuf_mmap_mapper,
338 .is_mmapped = __videobuf_is_mmapped,
339 .copy_to_user = __videobuf_copy_to_user, 323 .copy_to_user = __videobuf_copy_to_user,
340 .copy_stream = __videobuf_copy_stream, 324 .copy_stream = __videobuf_copy_stream,
341}; 325};