aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPawel Osciak <p.osciak@samsung.com>2010-03-17 03:01:04 -0400
committerMauro Carvalho Chehab <mchehab@redhat.com>2010-05-17 23:50:25 -0400
commit7a02264ca9ec5409e22b9d41f32b431d08eadbce (patch)
tree4c7cd63a863c10f0fbe8d8ec7927e203e9d7577f
parent85e092190b5f7dfe9b78556440472c5590a32b4e (diff)
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>
-rw-r--r--drivers/media/video/videobuf-core.c116
-rw-r--r--drivers/media/video/videobuf-dma-sg.c276
-rw-r--r--drivers/media/video/videobuf-vmalloc.c112
-rw-r--r--include/media/videobuf-core.h10
-rw-r--r--include/media/videobuf-dma-sg.h27
-rw-r--r--include/media/videobuf-vmalloc.h12
6 files changed, 272 insertions, 281 deletions
diff --git a/drivers/media/video/videobuf-core.c b/drivers/media/video/videobuf-core.c
index 471178e17017..63d7043502d6 100644
--- a/drivers/media/video/videobuf-core.c
+++ b/drivers/media/video/videobuf-core.c
@@ -24,10 +24,15 @@
24#include <media/videobuf-core.h> 24#include <media/videobuf-core.h>
25 25
26#define MAGIC_BUFFER 0x20070728 26#define MAGIC_BUFFER 0x20070728
27#define MAGIC_CHECK(is, should) do { \ 27#define MAGIC_CHECK(is, should) \
28 if (unlikely((is) != (should))) { \ 28 do { \
29 printk(KERN_ERR "magic mismatch: %x (expected %x)\n", is, should); \ 29 if (unlikely((is) != (should))) { \
30 BUG(); } } while (0) 30 printk(KERN_ERR \
31 "magic mismatch: %x (expected %x)\n", \
32 is, should); \
33 BUG(); \
34 } \
35 } while (0)
31 36
32static int debug; 37static int debug;
33module_param(debug, int, 0644); 38module_param(debug, int, 0644);
@@ -36,9 +41,11 @@ MODULE_DESCRIPTION("helper module to manage video4linux buffers");
36MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@infradead.org>"); 41MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@infradead.org>");
37MODULE_LICENSE("GPL"); 42MODULE_LICENSE("GPL");
38 43
39#define dprintk(level, fmt, arg...) do { \ 44#define dprintk(level, fmt, arg...) \
40 if (debug >= level) \ 45 do { \
41 printk(KERN_DEBUG "vbuf: " fmt , ## arg); } while (0) 46 if (debug >= level) \
47 printk(KERN_DEBUG "vbuf: " fmt, ## arg); \
48 } while (0)
42 49
43/* --------------------------------------------------------------------- */ 50/* --------------------------------------------------------------------- */
44 51
@@ -57,14 +64,14 @@ void *videobuf_alloc(struct videobuf_queue *q)
57 } 64 }
58 65
59 vb = q->int_ops->alloc(q->msize); 66 vb = q->int_ops->alloc(q->msize);
60
61 if (NULL != vb) { 67 if (NULL != vb) {
62 init_waitqueue_head(&vb->done); 68 init_waitqueue_head(&vb->done);
63 vb->magic = MAGIC_BUFFER; 69 vb->magic = MAGIC_BUFFER;
64 } 70 }
65 71
66 return vb; 72 return vb;
67} 73}
74EXPORT_SYMBOL_GPL(videobuf_alloc);
68 75
69#define WAITON_CONDITION (vb->state != VIDEOBUF_ACTIVE &&\ 76#define WAITON_CONDITION (vb->state != VIDEOBUF_ACTIVE &&\
70 vb->state != VIDEOBUF_QUEUED) 77 vb->state != VIDEOBUF_QUEUED)
@@ -86,6 +93,7 @@ int videobuf_waiton(struct videobuf_buffer *vb, int non_blocking, int intr)
86 93
87 return 0; 94 return 0;
88} 95}
96EXPORT_SYMBOL_GPL(videobuf_waiton);
89 97
90int videobuf_iolock(struct videobuf_queue *q, struct videobuf_buffer *vb, 98int videobuf_iolock(struct videobuf_queue *q, struct videobuf_buffer *vb,
91 struct v4l2_framebuffer *fbuf) 99 struct v4l2_framebuffer *fbuf)
@@ -95,9 +103,10 @@ int videobuf_iolock(struct videobuf_queue *q, struct videobuf_buffer *vb,
95 103
96 return CALL(q, iolock, q, vb, fbuf); 104 return CALL(q, iolock, q, vb, fbuf);
97} 105}
106EXPORT_SYMBOL_GPL(videobuf_iolock);
98 107
99void *videobuf_queue_to_vmalloc (struct videobuf_queue *q, 108void *videobuf_queue_to_vmalloc(struct videobuf_queue *q,
100 struct videobuf_buffer *buf) 109 struct videobuf_buffer *buf)
101{ 110{
102 if (q->int_ops->vmalloc) 111 if (q->int_ops->vmalloc)
103 return q->int_ops->vmalloc(buf); 112 return q->int_ops->vmalloc(buf);
@@ -146,6 +155,7 @@ void videobuf_queue_core_init(struct videobuf_queue *q,
146 init_waitqueue_head(&q->wait); 155 init_waitqueue_head(&q->wait);
147 INIT_LIST_HEAD(&q->stream); 156 INIT_LIST_HEAD(&q->stream);
148} 157}
158EXPORT_SYMBOL_GPL(videobuf_queue_core_init);
149 159
150/* Locking: Only usage in bttv unsafe find way to remove */ 160/* Locking: Only usage in bttv unsafe find way to remove */
151int videobuf_queue_is_busy(struct videobuf_queue *q) 161int videobuf_queue_is_busy(struct videobuf_queue *q)
@@ -184,6 +194,7 @@ int videobuf_queue_is_busy(struct videobuf_queue *q)
184 } 194 }
185 return 0; 195 return 0;
186} 196}
197EXPORT_SYMBOL_GPL(videobuf_queue_is_busy);
187 198
188/* Locking: Caller holds q->vb_lock */ 199/* Locking: Caller holds q->vb_lock */
189void videobuf_queue_cancel(struct videobuf_queue *q) 200void videobuf_queue_cancel(struct videobuf_queue *q)
@@ -216,6 +227,7 @@ void videobuf_queue_cancel(struct videobuf_queue *q)
216 } 227 }
217 INIT_LIST_HEAD(&q->stream); 228 INIT_LIST_HEAD(&q->stream);
218} 229}
230EXPORT_SYMBOL_GPL(videobuf_queue_cancel);
219 231
220/* --------------------------------------------------------------------- */ 232/* --------------------------------------------------------------------- */
221 233
@@ -237,6 +249,7 @@ enum v4l2_field videobuf_next_field(struct videobuf_queue *q)
237 } 249 }
238 return field; 250 return field;
239} 251}
252EXPORT_SYMBOL_GPL(videobuf_next_field);
240 253
241/* Locking: Caller holds q->vb_lock */ 254/* Locking: Caller holds q->vb_lock */
242static void videobuf_status(struct videobuf_queue *q, struct v4l2_buffer *b, 255static void videobuf_status(struct videobuf_queue *q, struct v4l2_buffer *b,
@@ -305,8 +318,7 @@ static int __videobuf_mmap_free(struct videobuf_queue *q)
305 318
306 MAGIC_CHECK(q->int_ops->magic, MAGIC_QTYPE_OPS); 319 MAGIC_CHECK(q->int_ops->magic, MAGIC_QTYPE_OPS);
307 320
308 321 rc = CALL(q, mmap_free, q);
309 rc = CALL(q, mmap_free, q);
310 322
311 q->is_mmapped = 0; 323 q->is_mmapped = 0;
312 324
@@ -332,6 +344,7 @@ int videobuf_mmap_free(struct videobuf_queue *q)
332 mutex_unlock(&q->vb_lock); 344 mutex_unlock(&q->vb_lock);
333 return ret; 345 return ret;
334} 346}
347EXPORT_SYMBOL_GPL(videobuf_mmap_free);
335 348
336/* Locking: Caller holds q->vb_lock */ 349/* Locking: Caller holds q->vb_lock */
337int __videobuf_mmap_setup(struct videobuf_queue *q, 350int __videobuf_mmap_setup(struct videobuf_queue *q,
@@ -351,7 +364,7 @@ int __videobuf_mmap_setup(struct videobuf_queue *q,
351 for (i = 0; i < bcount; i++) { 364 for (i = 0; i < bcount; i++) {
352 q->bufs[i] = videobuf_alloc(q); 365 q->bufs[i] = videobuf_alloc(q);
353 366
354 if (q->bufs[i] == NULL) 367 if (NULL == q->bufs[i])
355 break; 368 break;
356 369
357 q->bufs[i]->i = i; 370 q->bufs[i]->i = i;
@@ -372,11 +385,11 @@ int __videobuf_mmap_setup(struct videobuf_queue *q,
372 if (!i) 385 if (!i)
373 return -ENOMEM; 386 return -ENOMEM;
374 387
375 dprintk(1, "mmap setup: %d buffers, %d bytes each\n", 388 dprintk(1, "mmap setup: %d buffers, %d bytes each\n", i, bsize);
376 i, bsize);
377 389
378 return i; 390 return i;
379} 391}
392EXPORT_SYMBOL_GPL(__videobuf_mmap_setup);
380 393
381int videobuf_mmap_setup(struct videobuf_queue *q, 394int videobuf_mmap_setup(struct videobuf_queue *q,
382 unsigned int bcount, unsigned int bsize, 395 unsigned int bcount, unsigned int bsize,
@@ -388,6 +401,7 @@ int videobuf_mmap_setup(struct videobuf_queue *q,
388 mutex_unlock(&q->vb_lock); 401 mutex_unlock(&q->vb_lock);
389 return ret; 402 return ret;
390} 403}
404EXPORT_SYMBOL_GPL(videobuf_mmap_setup);
391 405
392int videobuf_reqbufs(struct videobuf_queue *q, 406int videobuf_reqbufs(struct videobuf_queue *q,
393 struct v4l2_requestbuffers *req) 407 struct v4l2_requestbuffers *req)
@@ -432,7 +446,7 @@ int videobuf_reqbufs(struct videobuf_queue *q,
432 q->ops->buf_setup(q, &count, &size); 446 q->ops->buf_setup(q, &count, &size);
433 dprintk(1, "reqbufs: bufs=%d, size=0x%x [%u pages total]\n", 447 dprintk(1, "reqbufs: bufs=%d, size=0x%x [%u pages total]\n",
434 count, size, 448 count, size,
435 (unsigned int)((count*PAGE_ALIGN(size))>>PAGE_SHIFT) ); 449 (unsigned int)((count * PAGE_ALIGN(size)) >> PAGE_SHIFT));
436 450
437 retval = __videobuf_mmap_setup(q, count, size, req->memory); 451 retval = __videobuf_mmap_setup(q, count, size, req->memory);
438 if (retval < 0) { 452 if (retval < 0) {
@@ -447,6 +461,7 @@ int videobuf_reqbufs(struct videobuf_queue *q,
447 mutex_unlock(&q->vb_lock); 461 mutex_unlock(&q->vb_lock);
448 return retval; 462 return retval;
449} 463}
464EXPORT_SYMBOL_GPL(videobuf_reqbufs);
450 465
451int videobuf_querybuf(struct videobuf_queue *q, struct v4l2_buffer *b) 466int videobuf_querybuf(struct videobuf_queue *q, struct v4l2_buffer *b)
452{ 467{
@@ -473,9 +488,9 @@ done:
473 mutex_unlock(&q->vb_lock); 488 mutex_unlock(&q->vb_lock);
474 return ret; 489 return ret;
475} 490}
491EXPORT_SYMBOL_GPL(videobuf_querybuf);
476 492
477int videobuf_qbuf(struct videobuf_queue *q, 493int videobuf_qbuf(struct videobuf_queue *q, struct v4l2_buffer *b)
478 struct v4l2_buffer *b)
479{ 494{
480 struct videobuf_buffer *buf; 495 struct videobuf_buffer *buf;
481 enum v4l2_field field; 496 enum v4l2_field field;
@@ -571,7 +586,7 @@ int videobuf_qbuf(struct videobuf_queue *q,
571 retval = 0; 586 retval = 0;
572 wake_up_interruptible_sync(&q->wait); 587 wake_up_interruptible_sync(&q->wait);
573 588
574 done: 589done:
575 mutex_unlock(&q->vb_lock); 590 mutex_unlock(&q->vb_lock);
576 591
577 if (b->memory == V4L2_MEMORY_MMAP) 592 if (b->memory == V4L2_MEMORY_MMAP)
@@ -579,7 +594,7 @@ int videobuf_qbuf(struct videobuf_queue *q,
579 594
580 return retval; 595 return retval;
581} 596}
582 597EXPORT_SYMBOL_GPL(videobuf_qbuf);
583 598
584/* Locking: Caller holds q->vb_lock */ 599/* Locking: Caller holds q->vb_lock */
585static int stream_next_buffer_check_queue(struct videobuf_queue *q, int noblock) 600static int stream_next_buffer_check_queue(struct videobuf_queue *q, int noblock)
@@ -624,7 +639,6 @@ done:
624 return retval; 639 return retval;
625} 640}
626 641
627
628/* Locking: Caller holds q->vb_lock */ 642/* Locking: Caller holds q->vb_lock */
629static int stream_next_buffer(struct videobuf_queue *q, 643static int stream_next_buffer(struct videobuf_queue *q,
630 struct videobuf_buffer **vb, int nonblocking) 644 struct videobuf_buffer **vb, int nonblocking)
@@ -647,7 +661,7 @@ done:
647} 661}
648 662
649int videobuf_dqbuf(struct videobuf_queue *q, 663int videobuf_dqbuf(struct videobuf_queue *q,
650 struct v4l2_buffer *b, int nonblocking) 664 struct v4l2_buffer *b, int nonblocking)
651{ 665{
652 struct videobuf_buffer *buf = NULL; 666 struct videobuf_buffer *buf = NULL;
653 int retval; 667 int retval;
@@ -682,11 +696,11 @@ int videobuf_dqbuf(struct videobuf_queue *q,
682 list_del(&buf->stream); 696 list_del(&buf->stream);
683 memset(b, 0, sizeof(*b)); 697 memset(b, 0, sizeof(*b));
684 videobuf_status(q, b, buf, q->type); 698 videobuf_status(q, b, buf, q->type);
685 699done:
686 done:
687 mutex_unlock(&q->vb_lock); 700 mutex_unlock(&q->vb_lock);
688 return retval; 701 return retval;
689} 702}
703EXPORT_SYMBOL_GPL(videobuf_dqbuf);
690 704
691int videobuf_streamon(struct videobuf_queue *q) 705int videobuf_streamon(struct videobuf_queue *q)
692{ 706{
@@ -709,10 +723,11 @@ int videobuf_streamon(struct videobuf_queue *q)
709 spin_unlock_irqrestore(q->irqlock, flags); 723 spin_unlock_irqrestore(q->irqlock, flags);
710 724
711 wake_up_interruptible_sync(&q->wait); 725 wake_up_interruptible_sync(&q->wait);
712 done: 726done:
713 mutex_unlock(&q->vb_lock); 727 mutex_unlock(&q->vb_lock);
714 return retval; 728 return retval;
715} 729}
730EXPORT_SYMBOL_GPL(videobuf_streamon);
716 731
717/* Locking: Caller holds q->vb_lock */ 732/* Locking: Caller holds q->vb_lock */
718static int __videobuf_streamoff(struct videobuf_queue *q) 733static int __videobuf_streamoff(struct videobuf_queue *q)
@@ -735,6 +750,7 @@ int videobuf_streamoff(struct videobuf_queue *q)
735 750
736 return retval; 751 return retval;
737} 752}
753EXPORT_SYMBOL_GPL(videobuf_streamoff);
738 754
739/* Locking: Caller holds q->vb_lock */ 755/* Locking: Caller holds q->vb_lock */
740static ssize_t videobuf_read_zerocopy(struct videobuf_queue *q, 756static ssize_t videobuf_read_zerocopy(struct videobuf_queue *q,
@@ -774,7 +790,7 @@ static ssize_t videobuf_read_zerocopy(struct videobuf_queue *q,
774 retval = q->read_buf->size; 790 retval = q->read_buf->size;
775 } 791 }
776 792
777 done: 793done:
778 /* cleanup */ 794 /* cleanup */
779 q->ops->buf_release(q, q->read_buf); 795 q->ops->buf_release(q, q->read_buf);
780 kfree(q->read_buf); 796 kfree(q->read_buf);
@@ -862,10 +878,11 @@ ssize_t videobuf_read_one(struct videobuf_queue *q,
862 q->read_buf = NULL; 878 q->read_buf = NULL;
863 } 879 }
864 880
865 done: 881done:
866 mutex_unlock(&q->vb_lock); 882 mutex_unlock(&q->vb_lock);
867 return retval; 883 return retval;
868} 884}
885EXPORT_SYMBOL_GPL(videobuf_read_one);
869 886
870/* Locking: Caller holds q->vb_lock */ 887/* Locking: Caller holds q->vb_lock */
871static int __videobuf_read_start(struct videobuf_queue *q) 888static int __videobuf_read_start(struct videobuf_queue *q)
@@ -917,7 +934,6 @@ static void __videobuf_read_stop(struct videobuf_queue *q)
917 q->bufs[i] = NULL; 934 q->bufs[i] = NULL;
918 } 935 }
919 q->read_buf = NULL; 936 q->read_buf = NULL;
920
921} 937}
922 938
923int videobuf_read_start(struct videobuf_queue *q) 939int videobuf_read_start(struct videobuf_queue *q)
@@ -930,6 +946,7 @@ int videobuf_read_start(struct videobuf_queue *q)
930 946
931 return rc; 947 return rc;
932} 948}
949EXPORT_SYMBOL_GPL(videobuf_read_start);
933 950
934void videobuf_read_stop(struct videobuf_queue *q) 951void videobuf_read_stop(struct videobuf_queue *q)
935{ 952{
@@ -937,6 +954,7 @@ void videobuf_read_stop(struct videobuf_queue *q)
937 __videobuf_read_stop(q); 954 __videobuf_read_stop(q);
938 mutex_unlock(&q->vb_lock); 955 mutex_unlock(&q->vb_lock);
939} 956}
957EXPORT_SYMBOL_GPL(videobuf_read_stop);
940 958
941void videobuf_stop(struct videobuf_queue *q) 959void videobuf_stop(struct videobuf_queue *q)
942{ 960{
@@ -950,7 +968,7 @@ void videobuf_stop(struct videobuf_queue *q)
950 968
951 mutex_unlock(&q->vb_lock); 969 mutex_unlock(&q->vb_lock);
952} 970}
953 971EXPORT_SYMBOL_GPL(videobuf_stop);
954 972
955ssize_t videobuf_read_stream(struct videobuf_queue *q, 973ssize_t videobuf_read_stream(struct videobuf_queue *q,
956 char __user *data, size_t count, loff_t *ppos, 974 char __user *data, size_t count, loff_t *ppos,
@@ -1019,10 +1037,11 @@ ssize_t videobuf_read_stream(struct videobuf_queue *q,
1019 break; 1037 break;
1020 } 1038 }
1021 1039
1022 done: 1040done:
1023 mutex_unlock(&q->vb_lock); 1041 mutex_unlock(&q->vb_lock);
1024 return retval; 1042 return retval;
1025} 1043}
1044EXPORT_SYMBOL_GPL(videobuf_read_stream);
1026 1045
1027unsigned int videobuf_poll_stream(struct file *file, 1046unsigned int videobuf_poll_stream(struct file *file,
1028 struct videobuf_queue *q, 1047 struct videobuf_queue *q,
@@ -1062,9 +1081,9 @@ unsigned int videobuf_poll_stream(struct file *file,
1062 mutex_unlock(&q->vb_lock); 1081 mutex_unlock(&q->vb_lock);
1063 return rc; 1082 return rc;
1064} 1083}
1084EXPORT_SYMBOL_GPL(videobuf_poll_stream);
1065 1085
1066int videobuf_mmap_mapper(struct videobuf_queue *q, 1086int videobuf_mmap_mapper(struct videobuf_queue *q, struct vm_area_struct *vma)
1067 struct vm_area_struct *vma)
1068{ 1087{
1069 int retval; 1088 int retval;
1070 1089
@@ -1077,6 +1096,7 @@ int videobuf_mmap_mapper(struct videobuf_queue *q,
1077 1096
1078 return retval; 1097 return retval;
1079} 1098}
1099EXPORT_SYMBOL_GPL(videobuf_mmap_mapper);
1080 1100
1081#ifdef CONFIG_VIDEO_V4L1_COMPAT 1101#ifdef CONFIG_VIDEO_V4L1_COMPAT
1082int videobuf_cgmbuf(struct videobuf_queue *q, 1102int videobuf_cgmbuf(struct videobuf_queue *q,
@@ -1107,33 +1127,3 @@ int videobuf_cgmbuf(struct videobuf_queue *q,
1107EXPORT_SYMBOL_GPL(videobuf_cgmbuf); 1127EXPORT_SYMBOL_GPL(videobuf_cgmbuf);
1108#endif 1128#endif
1109 1129
1110/* --------------------------------------------------------------------- */
1111
1112EXPORT_SYMBOL_GPL(videobuf_waiton);
1113EXPORT_SYMBOL_GPL(videobuf_iolock);
1114
1115EXPORT_SYMBOL_GPL(videobuf_alloc);
1116
1117EXPORT_SYMBOL_GPL(videobuf_queue_core_init);
1118EXPORT_SYMBOL_GPL(videobuf_queue_cancel);
1119EXPORT_SYMBOL_GPL(videobuf_queue_is_busy);
1120
1121EXPORT_SYMBOL_GPL(videobuf_next_field);
1122EXPORT_SYMBOL_GPL(videobuf_reqbufs);
1123EXPORT_SYMBOL_GPL(videobuf_querybuf);
1124EXPORT_SYMBOL_GPL(videobuf_qbuf);
1125EXPORT_SYMBOL_GPL(videobuf_dqbuf);
1126EXPORT_SYMBOL_GPL(videobuf_streamon);
1127EXPORT_SYMBOL_GPL(videobuf_streamoff);
1128
1129EXPORT_SYMBOL_GPL(videobuf_read_start);
1130EXPORT_SYMBOL_GPL(videobuf_read_stop);
1131EXPORT_SYMBOL_GPL(videobuf_stop);
1132EXPORT_SYMBOL_GPL(videobuf_read_stream);
1133EXPORT_SYMBOL_GPL(videobuf_read_one);
1134EXPORT_SYMBOL_GPL(videobuf_poll_stream);
1135
1136EXPORT_SYMBOL_GPL(__videobuf_mmap_setup);
1137EXPORT_SYMBOL_GPL(videobuf_mmap_setup);
1138EXPORT_SYMBOL_GPL(videobuf_mmap_free);
1139EXPORT_SYMBOL_GPL(videobuf_mmap_mapper);
diff --git a/drivers/media/video/videobuf-dma-sg.c b/drivers/media/video/videobuf-dma-sg.c
index fcd045e7a1c1..c9d946a388e8 100644
--- a/drivers/media/video/videobuf-dma-sg.c
+++ b/drivers/media/video/videobuf-dma-sg.c
@@ -37,8 +37,12 @@
37#define MAGIC_DMABUF 0x19721112 37#define MAGIC_DMABUF 0x19721112
38#define MAGIC_SG_MEM 0x17890714 38#define MAGIC_SG_MEM 0x17890714
39 39
40#define MAGIC_CHECK(is,should) if (unlikely((is) != (should))) \ 40#define MAGIC_CHECK(is, should) \
41 { printk(KERN_ERR "magic mismatch: %x (expected %x)\n",is,should); BUG(); } 41 if (unlikely((is) != (should))) { \
42 printk(KERN_ERR "magic mismatch: %x (expected %x)\n", \
43 is, should); \
44 BUG(); \
45 }
42 46
43static int debug; 47static int debug;
44module_param(debug, int, 0644); 48module_param(debug, int, 0644);
@@ -47,13 +51,13 @@ MODULE_DESCRIPTION("helper module to manage video4linux dma sg buffers");
47MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@infradead.org>"); 51MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@infradead.org>");
48MODULE_LICENSE("GPL"); 52MODULE_LICENSE("GPL");
49 53
50#define dprintk(level, fmt, arg...) if (debug >= level) \ 54#define dprintk(level, fmt, arg...) \
51 printk(KERN_DEBUG "vbuf-sg: " fmt , ## arg) 55 if (debug >= level) \
56 printk(KERN_DEBUG "vbuf-sg: " fmt , ## arg)
52 57
53/* --------------------------------------------------------------------- */ 58/* --------------------------------------------------------------------- */
54 59
55struct scatterlist* 60struct scatterlist *videobuf_vmalloc_to_sg(unsigned char *virt, int nr_pages)
56videobuf_vmalloc_to_sg(unsigned char *virt, int nr_pages)
57{ 61{
58 struct scatterlist *sglist; 62 struct scatterlist *sglist;
59 struct page *pg; 63 struct page *pg;
@@ -73,13 +77,14 @@ videobuf_vmalloc_to_sg(unsigned char *virt, int nr_pages)
73 } 77 }
74 return sglist; 78 return sglist;
75 79
76 err: 80err:
77 vfree(sglist); 81 vfree(sglist);
78 return NULL; 82 return NULL;
79} 83}
84EXPORT_SYMBOL_GPL(videobuf_vmalloc_to_sg);
80 85
81struct scatterlist* 86struct scatterlist *videobuf_pages_to_sg(struct page **pages, int nr_pages,
82videobuf_pages_to_sg(struct page **pages, int nr_pages, int offset) 87 int offset)
83{ 88{
84 struct scatterlist *sglist; 89 struct scatterlist *sglist;
85 int i; 90 int i;
@@ -104,20 +109,20 @@ videobuf_pages_to_sg(struct page **pages, int nr_pages, int offset)
104 } 109 }
105 return sglist; 110 return sglist;
106 111
107 nopage: 112nopage:
108 dprintk(2,"sgl: oops - no page\n"); 113 dprintk(2, "sgl: oops - no page\n");
109 vfree(sglist); 114 vfree(sglist);
110 return NULL; 115 return NULL;
111 116
112 highmem: 117highmem:
113 dprintk(2,"sgl: oops - highmem page\n"); 118 dprintk(2, "sgl: oops - highmem page\n");
114 vfree(sglist); 119 vfree(sglist);
115 return NULL; 120 return NULL;
116} 121}
117 122
118/* --------------------------------------------------------------------- */ 123/* --------------------------------------------------------------------- */
119 124
120struct videobuf_dmabuf *videobuf_to_dma (struct videobuf_buffer *buf) 125struct videobuf_dmabuf *videobuf_to_dma(struct videobuf_buffer *buf)
121{ 126{
122 struct videobuf_dma_sg_memory *mem = buf->priv; 127 struct videobuf_dma_sg_memory *mem = buf->priv;
123 BUG_ON(!mem); 128 BUG_ON(!mem);
@@ -126,17 +131,19 @@ struct videobuf_dmabuf *videobuf_to_dma (struct videobuf_buffer *buf)
126 131
127 return &mem->dma; 132 return &mem->dma;
128} 133}
134EXPORT_SYMBOL_GPL(videobuf_to_dma);
129 135
130void videobuf_dma_init(struct videobuf_dmabuf *dma) 136void videobuf_dma_init(struct videobuf_dmabuf *dma)
131{ 137{
132 memset(dma,0,sizeof(*dma)); 138 memset(dma, 0, sizeof(*dma));
133 dma->magic = MAGIC_DMABUF; 139 dma->magic = MAGIC_DMABUF;
134} 140}
141EXPORT_SYMBOL_GPL(videobuf_dma_init);
135 142
136static int videobuf_dma_init_user_locked(struct videobuf_dmabuf *dma, 143static int videobuf_dma_init_user_locked(struct videobuf_dmabuf *dma,
137 int direction, unsigned long data, unsigned long size) 144 int direction, unsigned long data, unsigned long size)
138{ 145{
139 unsigned long first,last; 146 unsigned long first, last;
140 int err, rw = 0; 147 int err, rw = 0;
141 148
142 dma->direction = direction; 149 dma->direction = direction;
@@ -155,21 +162,21 @@ static int videobuf_dma_init_user_locked(struct videobuf_dmabuf *dma,
155 last = ((data+size-1) & PAGE_MASK) >> PAGE_SHIFT; 162 last = ((data+size-1) & PAGE_MASK) >> PAGE_SHIFT;
156 dma->offset = data & ~PAGE_MASK; 163 dma->offset = data & ~PAGE_MASK;
157 dma->nr_pages = last-first+1; 164 dma->nr_pages = last-first+1;
158 dma->pages = kmalloc(dma->nr_pages * sizeof(struct page*), 165 dma->pages = kmalloc(dma->nr_pages * sizeof(struct page *), GFP_KERNEL);
159 GFP_KERNEL);
160 if (NULL == dma->pages) 166 if (NULL == dma->pages)
161 return -ENOMEM; 167 return -ENOMEM;
162 dprintk(1,"init user [0x%lx+0x%lx => %d pages]\n",
163 data,size,dma->nr_pages);
164 168
165 err = get_user_pages(current,current->mm, 169 dprintk(1, "init user [0x%lx+0x%lx => %d pages]\n",
170 data, size, dma->nr_pages);
171
172 err = get_user_pages(current, current->mm,
166 data & PAGE_MASK, dma->nr_pages, 173 data & PAGE_MASK, dma->nr_pages,
167 rw == READ, 1, /* force */ 174 rw == READ, 1, /* force */
168 dma->pages, NULL); 175 dma->pages, NULL);
169 176
170 if (err != dma->nr_pages) { 177 if (err != dma->nr_pages) {
171 dma->nr_pages = (err >= 0) ? err : 0; 178 dma->nr_pages = (err >= 0) ? err : 0;
172 dprintk(1,"get_user_pages: err=%d [%d]\n",err,dma->nr_pages); 179 dprintk(1, "get_user_pages: err=%d [%d]\n", err, dma->nr_pages);
173 return err < 0 ? err : -EINVAL; 180 return err < 0 ? err : -EINVAL;
174 } 181 }
175 return 0; 182 return 0;
@@ -179,48 +186,58 @@ int videobuf_dma_init_user(struct videobuf_dmabuf *dma, int direction,
179 unsigned long data, unsigned long size) 186 unsigned long data, unsigned long size)
180{ 187{
181 int ret; 188 int ret;
189
182 down_read(&current->mm->mmap_sem); 190 down_read(&current->mm->mmap_sem);
183 ret = videobuf_dma_init_user_locked(dma, direction, data, size); 191 ret = videobuf_dma_init_user_locked(dma, direction, data, size);
184 up_read(&current->mm->mmap_sem); 192 up_read(&current->mm->mmap_sem);
185 193
186 return ret; 194 return ret;
187} 195}
196EXPORT_SYMBOL_GPL(videobuf_dma_init_user);
188 197
189int videobuf_dma_init_kernel(struct videobuf_dmabuf *dma, int direction, 198int videobuf_dma_init_kernel(struct videobuf_dmabuf *dma, int direction,
190 int nr_pages) 199 int nr_pages)
191{ 200{
192 dprintk(1,"init kernel [%d pages]\n",nr_pages); 201 dprintk(1, "init kernel [%d pages]\n", nr_pages);
202
193 dma->direction = direction; 203 dma->direction = direction;
194 dma->vmalloc = vmalloc_32(nr_pages << PAGE_SHIFT); 204 dma->vmalloc = vmalloc_32(nr_pages << PAGE_SHIFT);
195 if (NULL == dma->vmalloc) { 205 if (NULL == dma->vmalloc) {
196 dprintk(1,"vmalloc_32(%d pages) failed\n",nr_pages); 206 dprintk(1, "vmalloc_32(%d pages) failed\n", nr_pages);
197 return -ENOMEM; 207 return -ENOMEM;
198 } 208 }
199 dprintk(1,"vmalloc is at addr 0x%08lx, size=%d\n", 209
210 dprintk(1, "vmalloc is at addr 0x%08lx, size=%d\n",
200 (unsigned long)dma->vmalloc, 211 (unsigned long)dma->vmalloc,
201 nr_pages << PAGE_SHIFT); 212 nr_pages << PAGE_SHIFT);
202 memset(dma->vmalloc,0,nr_pages << PAGE_SHIFT); 213
214 memset(dma->vmalloc, 0, nr_pages << PAGE_SHIFT);
203 dma->nr_pages = nr_pages; 215 dma->nr_pages = nr_pages;
216
204 return 0; 217 return 0;
205} 218}
219EXPORT_SYMBOL_GPL(videobuf_dma_init_kernel);
206 220
207int videobuf_dma_init_overlay(struct videobuf_dmabuf *dma, int direction, 221int videobuf_dma_init_overlay(struct videobuf_dmabuf *dma, int direction,
208 dma_addr_t addr, int nr_pages) 222 dma_addr_t addr, int nr_pages)
209{ 223{
210 dprintk(1,"init overlay [%d pages @ bus 0x%lx]\n", 224 dprintk(1, "init overlay [%d pages @ bus 0x%lx]\n",
211 nr_pages,(unsigned long)addr); 225 nr_pages, (unsigned long)addr);
212 dma->direction = direction; 226 dma->direction = direction;
227
213 if (0 == addr) 228 if (0 == addr)
214 return -EINVAL; 229 return -EINVAL;
215 230
216 dma->bus_addr = addr; 231 dma->bus_addr = addr;
217 dma->nr_pages = nr_pages; 232 dma->nr_pages = nr_pages;
233
218 return 0; 234 return 0;
219} 235}
236EXPORT_SYMBOL_GPL(videobuf_dma_init_overlay);
220 237
221int videobuf_dma_map(struct videobuf_queue* q, struct videobuf_dmabuf *dma) 238int videobuf_dma_map(struct videobuf_queue *q, struct videobuf_dmabuf *dma)
222{ 239{
223 MAGIC_CHECK(dma->magic,MAGIC_DMABUF); 240 MAGIC_CHECK(dma->magic, MAGIC_DMABUF);
224 BUG_ON(0 == dma->nr_pages); 241 BUG_ON(0 == dma->nr_pages);
225 242
226 if (dma->pages) { 243 if (dma->pages) {
@@ -228,20 +245,21 @@ int videobuf_dma_map(struct videobuf_queue* q, struct videobuf_dmabuf *dma)
228 dma->offset); 245 dma->offset);
229 } 246 }
230 if (dma->vmalloc) { 247 if (dma->vmalloc) {
231 dma->sglist = videobuf_vmalloc_to_sg 248 dma->sglist = videobuf_vmalloc_to_sg(dma->vmalloc,
232 (dma->vmalloc,dma->nr_pages); 249 dma->nr_pages);
233 } 250 }
234 if (dma->bus_addr) { 251 if (dma->bus_addr) {
235 dma->sglist = vmalloc(sizeof(*dma->sglist)); 252 dma->sglist = vmalloc(sizeof(*dma->sglist));
236 if (NULL != dma->sglist) { 253 if (NULL != dma->sglist) {
237 dma->sglen = 1; 254 dma->sglen = 1;
238 sg_dma_address(&dma->sglist[0]) = dma->bus_addr & PAGE_MASK; 255 sg_dma_address(&dma->sglist[0]) = dma->bus_addr
239 dma->sglist[0].offset = dma->bus_addr & ~PAGE_MASK; 256 & PAGE_MASK;
240 sg_dma_len(&dma->sglist[0]) = dma->nr_pages * PAGE_SIZE; 257 dma->sglist[0].offset = dma->bus_addr & ~PAGE_MASK;
258 sg_dma_len(&dma->sglist[0]) = dma->nr_pages * PAGE_SIZE;
241 } 259 }
242 } 260 }
243 if (NULL == dma->sglist) { 261 if (NULL == dma->sglist) {
244 dprintk(1,"scatterlist is NULL\n"); 262 dprintk(1, "scatterlist is NULL\n");
245 return -ENOMEM; 263 return -ENOMEM;
246 } 264 }
247 if (!dma->bus_addr) { 265 if (!dma->bus_addr) {
@@ -249,15 +267,17 @@ int videobuf_dma_map(struct videobuf_queue* q, struct videobuf_dmabuf *dma)
249 dma->nr_pages, dma->direction); 267 dma->nr_pages, dma->direction);
250 if (0 == dma->sglen) { 268 if (0 == dma->sglen) {
251 printk(KERN_WARNING 269 printk(KERN_WARNING
252 "%s: videobuf_map_sg failed\n",__func__); 270 "%s: videobuf_map_sg failed\n", __func__);
253 vfree(dma->sglist); 271 vfree(dma->sglist);
254 dma->sglist = NULL; 272 dma->sglist = NULL;
255 dma->sglen = 0; 273 dma->sglen = 0;
256 return -ENOMEM; 274 return -ENOMEM;
257 } 275 }
258 } 276 }
277
259 return 0; 278 return 0;
260} 279}
280EXPORT_SYMBOL_GPL(videobuf_dma_map);
261 281
262int videobuf_dma_sync(struct videobuf_queue *q, struct videobuf_dmabuf *dma) 282int videobuf_dma_sync(struct videobuf_queue *q, struct videobuf_dmabuf *dma)
263{ 283{
@@ -265,12 +285,15 @@ int videobuf_dma_sync(struct videobuf_queue *q, struct videobuf_dmabuf *dma)
265 BUG_ON(!dma->sglen); 285 BUG_ON(!dma->sglen);
266 286
267 dma_sync_sg_for_cpu(q->dev, dma->sglist, dma->nr_pages, dma->direction); 287 dma_sync_sg_for_cpu(q->dev, dma->sglist, dma->nr_pages, dma->direction);
288
268 return 0; 289 return 0;
269} 290}
291EXPORT_SYMBOL_GPL(videobuf_dma_sync);
270 292
271int videobuf_dma_unmap(struct videobuf_queue* q,struct videobuf_dmabuf *dma) 293int videobuf_dma_unmap(struct videobuf_queue *q, struct videobuf_dmabuf *dma)
272{ 294{
273 MAGIC_CHECK(dma->magic, MAGIC_DMABUF); 295 MAGIC_CHECK(dma->magic, MAGIC_DMABUF);
296
274 if (!dma->sglen) 297 if (!dma->sglen)
275 return 0; 298 return 0;
276 299
@@ -279,17 +302,19 @@ int videobuf_dma_unmap(struct videobuf_queue* q,struct videobuf_dmabuf *dma)
279 vfree(dma->sglist); 302 vfree(dma->sglist);
280 dma->sglist = NULL; 303 dma->sglist = NULL;
281 dma->sglen = 0; 304 dma->sglen = 0;
305
282 return 0; 306 return 0;
283} 307}
308EXPORT_SYMBOL_GPL(videobuf_dma_unmap);
284 309
285int videobuf_dma_free(struct videobuf_dmabuf *dma) 310int videobuf_dma_free(struct videobuf_dmabuf *dma)
286{ 311{
287 MAGIC_CHECK(dma->magic,MAGIC_DMABUF); 312 int i;
313 MAGIC_CHECK(dma->magic, MAGIC_DMABUF);
288 BUG_ON(dma->sglen); 314 BUG_ON(dma->sglen);
289 315
290 if (dma->pages) { 316 if (dma->pages) {
291 int i; 317 for (i = 0; i < dma->nr_pages; i++)
292 for (i=0; i < dma->nr_pages; i++)
293 page_cache_release(dma->pages[i]); 318 page_cache_release(dma->pages[i]);
294 kfree(dma->pages); 319 kfree(dma->pages);
295 dma->pages = NULL; 320 dma->pages = NULL;
@@ -298,12 +323,13 @@ int videobuf_dma_free(struct videobuf_dmabuf *dma)
298 vfree(dma->vmalloc); 323 vfree(dma->vmalloc);
299 dma->vmalloc = NULL; 324 dma->vmalloc = NULL;
300 325
301 if (dma->bus_addr) { 326 if (dma->bus_addr)
302 dma->bus_addr = 0; 327 dma->bus_addr = 0;
303 }
304 dma->direction = DMA_NONE; 328 dma->direction = DMA_NONE;
329
305 return 0; 330 return 0;
306} 331}
332EXPORT_SYMBOL_GPL(videobuf_dma_free);
307 333
308/* --------------------------------------------------------------------- */ 334/* --------------------------------------------------------------------- */
309 335
@@ -315,6 +341,7 @@ int videobuf_sg_dma_map(struct device *dev, struct videobuf_dmabuf *dma)
315 341
316 return videobuf_dma_map(&q, dma); 342 return videobuf_dma_map(&q, dma);
317} 343}
344EXPORT_SYMBOL_GPL(videobuf_sg_dma_map);
318 345
319int videobuf_sg_dma_unmap(struct device *dev, struct videobuf_dmabuf *dma) 346int videobuf_sg_dma_unmap(struct device *dev, struct videobuf_dmabuf *dma)
320{ 347{
@@ -324,49 +351,48 @@ int videobuf_sg_dma_unmap(struct device *dev, struct videobuf_dmabuf *dma)
324 351
325 return videobuf_dma_unmap(&q, dma); 352 return videobuf_dma_unmap(&q, dma);
326} 353}
354EXPORT_SYMBOL_GPL(videobuf_sg_dma_unmap);
327 355
328/* --------------------------------------------------------------------- */ 356/* --------------------------------------------------------------------- */
329 357
330static void 358static void videobuf_vm_open(struct vm_area_struct *vma)
331videobuf_vm_open(struct vm_area_struct *vma)
332{ 359{
333 struct videobuf_mapping *map = vma->vm_private_data; 360 struct videobuf_mapping *map = vma->vm_private_data;
334 361
335 dprintk(2,"vm_open %p [count=%d,vma=%08lx-%08lx]\n",map, 362 dprintk(2, "vm_open %p [count=%d,vma=%08lx-%08lx]\n", map,
336 map->count,vma->vm_start,vma->vm_end); 363 map->count, vma->vm_start, vma->vm_end);
364
337 map->count++; 365 map->count++;
338} 366}
339 367
340static void 368static void videobuf_vm_close(struct vm_area_struct *vma)
341videobuf_vm_close(struct vm_area_struct *vma)
342{ 369{
343 struct videobuf_mapping *map = vma->vm_private_data; 370 struct videobuf_mapping *map = vma->vm_private_data;
344 struct videobuf_queue *q = map->q; 371 struct videobuf_queue *q = map->q;
345 struct videobuf_dma_sg_memory *mem; 372 struct videobuf_dma_sg_memory *mem;
346 int i; 373 int i;
347 374
348 dprintk(2,"vm_close %p [count=%d,vma=%08lx-%08lx]\n",map, 375 dprintk(2, "vm_close %p [count=%d,vma=%08lx-%08lx]\n", map,
349 map->count,vma->vm_start,vma->vm_end); 376 map->count, vma->vm_start, vma->vm_end);
350 377
351 map->count--; 378 map->count--;
352 if (0 == map->count) { 379 if (0 == map->count) {
353 dprintk(1,"munmap %p q=%p\n",map,q); 380 dprintk(1, "munmap %p q=%p\n", map, q);
354 mutex_lock(&q->vb_lock); 381 mutex_lock(&q->vb_lock);
355 for (i = 0; i < VIDEO_MAX_FRAME; i++) { 382 for (i = 0; i < VIDEO_MAX_FRAME; i++) {
356 if (NULL == q->bufs[i]) 383 if (NULL == q->bufs[i])
357 continue; 384 continue;
358 mem=q->bufs[i]->priv; 385 mem = q->bufs[i]->priv;
359
360 if (!mem) 386 if (!mem)
361 continue; 387 continue;
362 388
363 MAGIC_CHECK(mem->magic,MAGIC_SG_MEM); 389 MAGIC_CHECK(mem->magic, MAGIC_SG_MEM);
364 390
365 if (q->bufs[i]->map != map) 391 if (q->bufs[i]->map != map)
366 continue; 392 continue;
367 q->bufs[i]->map = NULL; 393 q->bufs[i]->map = NULL;
368 q->bufs[i]->baddr = 0; 394 q->bufs[i]->baddr = 0;
369 q->ops->buf_release(q,q->bufs[i]); 395 q->ops->buf_release(q, q->bufs[i]);
370 } 396 }
371 mutex_unlock(&q->vb_lock); 397 mutex_unlock(&q->vb_lock);
372 kfree(map); 398 kfree(map);
@@ -380,26 +406,27 @@ videobuf_vm_close(struct vm_area_struct *vma)
380 * now ...). Bounce buffers don't work very well for the data rates 406 * now ...). Bounce buffers don't work very well for the data rates
381 * video capture has. 407 * video capture has.
382 */ 408 */
383static int 409static int videobuf_vm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
384videobuf_vm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
385{ 410{
386 struct page *page; 411 struct page *page;
387 412
388 dprintk(3,"fault: fault @ %08lx [vma %08lx-%08lx]\n", 413 dprintk(3, "fault: fault @ %08lx [vma %08lx-%08lx]\n",
389 (unsigned long)vmf->virtual_address,vma->vm_start,vma->vm_end); 414 (unsigned long)vmf->virtual_address,
415 vma->vm_start, vma->vm_end);
416
390 page = alloc_page(GFP_USER | __GFP_DMA32); 417 page = alloc_page(GFP_USER | __GFP_DMA32);
391 if (!page) 418 if (!page)
392 return VM_FAULT_OOM; 419 return VM_FAULT_OOM;
393 clear_user_highpage(page, (unsigned long)vmf->virtual_address); 420 clear_user_highpage(page, (unsigned long)vmf->virtual_address);
394 vmf->page = page; 421 vmf->page = page;
422
395 return 0; 423 return 0;
396} 424}
397 425
398static const struct vm_operations_struct videobuf_vm_ops = 426static const struct vm_operations_struct videobuf_vm_ops = {
399{ 427 .open = videobuf_vm_open,
400 .open = videobuf_vm_open, 428 .close = videobuf_vm_close,
401 .close = videobuf_vm_close, 429 .fault = videobuf_vm_fault,
402 .fault = videobuf_vm_fault,
403}; 430};
404 431
405/* --------------------------------------------------------------------- 432/* ---------------------------------------------------------------------
@@ -417,23 +444,23 @@ static void *__videobuf_alloc(size_t size)
417 struct videobuf_dma_sg_memory *mem; 444 struct videobuf_dma_sg_memory *mem;
418 struct videobuf_buffer *vb; 445 struct videobuf_buffer *vb;
419 446
420 vb = kzalloc(size+sizeof(*mem),GFP_KERNEL); 447 vb = kzalloc(size + sizeof(*mem), GFP_KERNEL);
421 if (!vb) 448 if (!vb)
422 return vb; 449 return vb;
423 450
424 mem = vb->priv = ((char *)vb)+size; 451 mem = vb->priv = ((char *)vb) + size;
425 mem->magic=MAGIC_SG_MEM; 452 mem->magic = MAGIC_SG_MEM;
426 453
427 videobuf_dma_init(&mem->dma); 454 videobuf_dma_init(&mem->dma);
428 455
429 dprintk(1,"%s: allocated at %p(%ld+%ld) & %p(%ld)\n", 456 dprintk(1, "%s: allocated at %p(%ld+%ld) & %p(%ld)\n",
430 __func__,vb,(long)sizeof(*vb),(long)size-sizeof(*vb), 457 __func__, vb, (long)sizeof(*vb), (long)size - sizeof(*vb),
431 mem,(long)sizeof(*mem)); 458 mem, (long)sizeof(*mem));
432 459
433 return vb; 460 return vb;
434} 461}
435 462
436static void *__videobuf_to_vmalloc (struct videobuf_buffer *buf) 463static void *__videobuf_to_vmalloc(struct videobuf_buffer *buf)
437{ 464{
438 struct videobuf_dma_sg_memory *mem = buf->priv; 465 struct videobuf_dma_sg_memory *mem = buf->priv;
439 BUG_ON(!mem); 466 BUG_ON(!mem);
@@ -443,11 +470,11 @@ static void *__videobuf_to_vmalloc (struct videobuf_buffer *buf)
443 return mem->dma.vmalloc; 470 return mem->dma.vmalloc;
444} 471}
445 472
446static int __videobuf_iolock (struct videobuf_queue* q, 473static int __videobuf_iolock(struct videobuf_queue *q,
447 struct videobuf_buffer *vb, 474 struct videobuf_buffer *vb,
448 struct v4l2_framebuffer *fbuf) 475 struct v4l2_framebuffer *fbuf)
449{ 476{
450 int err,pages; 477 int err, pages;
451 dma_addr_t bus; 478 dma_addr_t bus;
452 struct videobuf_dma_sg_memory *mem = vb->priv; 479 struct videobuf_dma_sg_memory *mem = vb->priv;
453 BUG_ON(!mem); 480 BUG_ON(!mem);
@@ -460,16 +487,16 @@ static int __videobuf_iolock (struct videobuf_queue* q,
460 if (0 == vb->baddr) { 487 if (0 == vb->baddr) {
461 /* no userspace addr -- kernel bounce buffer */ 488 /* no userspace addr -- kernel bounce buffer */
462 pages = PAGE_ALIGN(vb->size) >> PAGE_SHIFT; 489 pages = PAGE_ALIGN(vb->size) >> PAGE_SHIFT;
463 err = videobuf_dma_init_kernel( &mem->dma, 490 err = videobuf_dma_init_kernel(&mem->dma,
464 DMA_FROM_DEVICE, 491 DMA_FROM_DEVICE,
465 pages ); 492 pages);
466 if (0 != err) 493 if (0 != err)
467 return err; 494 return err;
468 } else if (vb->memory == V4L2_MEMORY_USERPTR) { 495 } else if (vb->memory == V4L2_MEMORY_USERPTR) {
469 /* dma directly to userspace */ 496 /* dma directly to userspace */
470 err = videobuf_dma_init_user( &mem->dma, 497 err = videobuf_dma_init_user(&mem->dma,
471 DMA_FROM_DEVICE, 498 DMA_FROM_DEVICE,
472 vb->baddr,vb->bsize ); 499 vb->baddr, vb->bsize);
473 if (0 != err) 500 if (0 != err)
474 return err; 501 return err;
475 } else { 502 } else {
@@ -516,9 +543,9 @@ static int __videobuf_sync(struct videobuf_queue *q,
516{ 543{
517 struct videobuf_dma_sg_memory *mem = buf->priv; 544 struct videobuf_dma_sg_memory *mem = buf->priv;
518 BUG_ON(!mem); 545 BUG_ON(!mem);
519 MAGIC_CHECK(mem->magic,MAGIC_SG_MEM); 546 MAGIC_CHECK(mem->magic, MAGIC_SG_MEM);
520 547
521 return videobuf_dma_sync(q,&mem->dma); 548 return videobuf_dma_sync(q, &mem->dma);
522} 549}
523 550
524static int __videobuf_mmap_free(struct videobuf_queue *q) 551static int __videobuf_mmap_free(struct videobuf_queue *q)
@@ -540,16 +567,16 @@ static int __videobuf_mmap_mapper(struct videobuf_queue *q,
540{ 567{
541 struct videobuf_dma_sg_memory *mem; 568 struct videobuf_dma_sg_memory *mem;
542 struct videobuf_mapping *map; 569 struct videobuf_mapping *map;
543 unsigned int first,last,size,i; 570 unsigned int first, last, size, i;
544 int retval; 571 int retval;
545 572
546 retval = -EINVAL; 573 retval = -EINVAL;
547 if (!(vma->vm_flags & VM_WRITE)) { 574 if (!(vma->vm_flags & VM_WRITE)) {
548 dprintk(1,"mmap app bug: PROT_WRITE please\n"); 575 dprintk(1, "mmap app bug: PROT_WRITE please\n");
549 goto done; 576 goto done;
550 } 577 }
551 if (!(vma->vm_flags & VM_SHARED)) { 578 if (!(vma->vm_flags & VM_SHARED)) {
552 dprintk(1,"mmap app bug: MAP_SHARED please\n"); 579 dprintk(1, "mmap app bug: MAP_SHARED please\n");
553 goto done; 580 goto done;
554 } 581 }
555 582
@@ -565,9 +592,9 @@ static int __videobuf_mmap_mapper(struct videobuf_queue *q,
565 for (first = 0; first < VIDEO_MAX_FRAME; first++) { 592 for (first = 0; first < VIDEO_MAX_FRAME; first++) {
566 if (NULL == q->bufs[first]) 593 if (NULL == q->bufs[first])
567 continue; 594 continue;
568 mem=q->bufs[first]->priv; 595 mem = q->bufs[first]->priv;
569 BUG_ON(!mem); 596 BUG_ON(!mem);
570 MAGIC_CHECK(mem->magic,MAGIC_SG_MEM); 597 MAGIC_CHECK(mem->magic, MAGIC_SG_MEM);
571 598
572 if (V4L2_MEMORY_MMAP != q->bufs[first]->memory) 599 if (V4L2_MEMORY_MMAP != q->bufs[first]->memory)
573 continue; 600 continue;
@@ -575,7 +602,7 @@ static int __videobuf_mmap_mapper(struct videobuf_queue *q,
575 break; 602 break;
576 } 603 }
577 if (VIDEO_MAX_FRAME == first) { 604 if (VIDEO_MAX_FRAME == first) {
578 dprintk(1,"mmap app bug: offset invalid [offset=0x%lx]\n", 605 dprintk(1, "mmap app bug: offset invalid [offset=0x%lx]\n",
579 (vma->vm_pgoff << PAGE_SHIFT)); 606 (vma->vm_pgoff << PAGE_SHIFT));
580 goto done; 607 goto done;
581 } 608 }
@@ -595,14 +622,14 @@ static int __videobuf_mmap_mapper(struct videobuf_queue *q,
595 break; 622 break;
596 } 623 }
597 if (VIDEO_MAX_FRAME == last) { 624 if (VIDEO_MAX_FRAME == last) {
598 dprintk(1,"mmap app bug: size invalid [size=0x%lx]\n", 625 dprintk(1, "mmap app bug: size invalid [size=0x%lx]\n",
599 (vma->vm_end - vma->vm_start)); 626 (vma->vm_end - vma->vm_start));
600 goto done; 627 goto done;
601 } 628 }
602 629
603 /* create mapping + update buffer list */ 630 /* create mapping + update buffer list */
604 retval = -ENOMEM; 631 retval = -ENOMEM;
605 map = kmalloc(sizeof(struct videobuf_mapping),GFP_KERNEL); 632 map = kmalloc(sizeof(struct videobuf_mapping), GFP_KERNEL);
606 if (NULL == map) 633 if (NULL == map)
607 goto done; 634 goto done;
608 635
@@ -623,21 +650,21 @@ static int __videobuf_mmap_mapper(struct videobuf_queue *q,
623 vma->vm_flags |= VM_DONTEXPAND | VM_RESERVED; 650 vma->vm_flags |= VM_DONTEXPAND | VM_RESERVED;
624 vma->vm_flags &= ~VM_IO; /* using shared anonymous pages */ 651 vma->vm_flags &= ~VM_IO; /* using shared anonymous pages */
625 vma->vm_private_data = map; 652 vma->vm_private_data = map;
626 dprintk(1,"mmap %p: q=%p %08lx-%08lx pgoff %08lx bufs %d-%d\n", 653 dprintk(1, "mmap %p: q=%p %08lx-%08lx pgoff %08lx bufs %d-%d\n",
627 map,q,vma->vm_start,vma->vm_end,vma->vm_pgoff,first,last); 654 map, q, vma->vm_start, vma->vm_end, vma->vm_pgoff, first, last);
628 retval = 0; 655 retval = 0;
629 656
630 done: 657done:
631 return retval; 658 return retval;
632} 659}
633 660
634static int __videobuf_copy_to_user ( struct videobuf_queue *q, 661static int __videobuf_copy_to_user(struct videobuf_queue *q,
635 char __user *data, size_t count, 662 char __user *data, size_t count,
636 int nonblocking ) 663 int nonblocking)
637{ 664{
638 struct videobuf_dma_sg_memory *mem = q->read_buf->priv; 665 struct videobuf_dma_sg_memory *mem = q->read_buf->priv;
639 BUG_ON(!mem); 666 BUG_ON(!mem);
640 MAGIC_CHECK(mem->magic,MAGIC_SG_MEM); 667 MAGIC_CHECK(mem->magic, MAGIC_SG_MEM);
641 668
642 /* copy to userspace */ 669 /* copy to userspace */
643 if (count > q->read_buf->size - q->read_off) 670 if (count > q->read_buf->size - q->read_off)
@@ -649,30 +676,30 @@ static int __videobuf_copy_to_user ( struct videobuf_queue *q,
649 return count; 676 return count;
650} 677}
651 678
652static int __videobuf_copy_stream ( struct videobuf_queue *q, 679static int __videobuf_copy_stream(struct videobuf_queue *q,
653 char __user *data, size_t count, size_t pos, 680 char __user *data, size_t count, size_t pos,
654 int vbihack, int nonblocking ) 681 int vbihack, int nonblocking)
655{ 682{
656 unsigned int *fc; 683 unsigned int *fc;
657 struct videobuf_dma_sg_memory *mem = q->read_buf->priv; 684 struct videobuf_dma_sg_memory *mem = q->read_buf->priv;
658 BUG_ON(!mem); 685 BUG_ON(!mem);
659 MAGIC_CHECK(mem->magic,MAGIC_SG_MEM); 686 MAGIC_CHECK(mem->magic, MAGIC_SG_MEM);
660 687
661 if (vbihack) { 688 if (vbihack) {
662 /* dirty, undocumented hack -- pass the frame counter 689 /* dirty, undocumented hack -- pass the frame counter
663 * within the last four bytes of each vbi data block. 690 * within the last four bytes of each vbi data block.
664 * We need that one to maintain backward compatibility 691 * We need that one to maintain backward compatibility
665 * to all vbi decoding software out there ... */ 692 * to all vbi decoding software out there ... */
666 fc = (unsigned int*)mem->dma.vmalloc; 693 fc = (unsigned int *)mem->dma.vmalloc;
667 fc += (q->read_buf->size>>2) -1; 694 fc += (q->read_buf->size >> 2) - 1;
668 *fc = q->read_buf->field_count >> 1; 695 *fc = q->read_buf->field_count >> 1;
669 dprintk(1,"vbihack: %d\n",*fc); 696 dprintk(1, "vbihack: %d\n", *fc);
670 } 697 }
671 698
672 /* copy stuff using the common method */ 699 /* copy stuff using the common method */
673 count = __videobuf_copy_to_user (q,data,count,nonblocking); 700 count = __videobuf_copy_to_user(q, data, count, nonblocking);
674 701
675 if ( (count==-EFAULT) && (0 == pos) ) 702 if ((count == -EFAULT) && (0 == pos))
676 return -EFAULT; 703 return -EFAULT;
677 704
678 return count; 705 return count;
@@ -702,8 +729,9 @@ void *videobuf_sg_alloc(size_t size)
702 729
703 return videobuf_alloc(&q); 730 return videobuf_alloc(&q);
704} 731}
732EXPORT_SYMBOL_GPL(videobuf_sg_alloc);
705 733
706void videobuf_queue_sg_init(struct videobuf_queue* q, 734void videobuf_queue_sg_init(struct videobuf_queue *q,
707 const struct videobuf_queue_ops *ops, 735 const struct videobuf_queue_ops *ops,
708 struct device *dev, 736 struct device *dev,
709 spinlock_t *irqlock, 737 spinlock_t *irqlock,
@@ -715,29 +743,5 @@ void videobuf_queue_sg_init(struct videobuf_queue* q,
715 videobuf_queue_core_init(q, ops, dev, irqlock, type, field, msize, 743 videobuf_queue_core_init(q, ops, dev, irqlock, type, field, msize,
716 priv, &sg_ops); 744 priv, &sg_ops);
717} 745}
718
719/* --------------------------------------------------------------------- */
720
721EXPORT_SYMBOL_GPL(videobuf_vmalloc_to_sg);
722
723EXPORT_SYMBOL_GPL(videobuf_to_dma);
724EXPORT_SYMBOL_GPL(videobuf_dma_init);
725EXPORT_SYMBOL_GPL(videobuf_dma_init_user);
726EXPORT_SYMBOL_GPL(videobuf_dma_init_kernel);
727EXPORT_SYMBOL_GPL(videobuf_dma_init_overlay);
728EXPORT_SYMBOL_GPL(videobuf_dma_map);
729EXPORT_SYMBOL_GPL(videobuf_dma_sync);
730EXPORT_SYMBOL_GPL(videobuf_dma_unmap);
731EXPORT_SYMBOL_GPL(videobuf_dma_free);
732
733EXPORT_SYMBOL_GPL(videobuf_sg_dma_map);
734EXPORT_SYMBOL_GPL(videobuf_sg_dma_unmap);
735EXPORT_SYMBOL_GPL(videobuf_sg_alloc);
736
737EXPORT_SYMBOL_GPL(videobuf_queue_sg_init); 746EXPORT_SYMBOL_GPL(videobuf_queue_sg_init);
738 747
739/*
740 * Local variables:
741 * c-basic-offset: 8
742 * End:
743 */
diff --git a/drivers/media/video/videobuf-vmalloc.c b/drivers/media/video/videobuf-vmalloc.c
index 136e09383c06..d6a8a38dc9cb 100644
--- a/drivers/media/video/videobuf-vmalloc.c
+++ b/drivers/media/video/videobuf-vmalloc.c
@@ -30,8 +30,12 @@
30#define MAGIC_DMABUF 0x17760309 30#define MAGIC_DMABUF 0x17760309
31#define MAGIC_VMAL_MEM 0x18221223 31#define MAGIC_VMAL_MEM 0x18221223
32 32
33#define MAGIC_CHECK(is,should) if (unlikely((is) != (should))) \ 33#define MAGIC_CHECK(is, should) \
34 { printk(KERN_ERR "magic mismatch: %x (expected %x)\n",is,should); BUG(); } 34 if (unlikely((is) != (should))) { \
35 printk(KERN_ERR "magic mismatch: %x (expected %x)\n", \
36 is, should); \
37 BUG(); \
38 }
35 39
36static int debug; 40static int debug;
37module_param(debug, int, 0644); 41module_param(debug, int, 0644);
@@ -40,19 +44,19 @@ MODULE_DESCRIPTION("helper module to manage video4linux vmalloc buffers");
40MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@infradead.org>"); 44MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@infradead.org>");
41MODULE_LICENSE("GPL"); 45MODULE_LICENSE("GPL");
42 46
43#define dprintk(level, fmt, arg...) if (debug >= level) \ 47#define dprintk(level, fmt, arg...) \
44 printk(KERN_DEBUG "vbuf-vmalloc: " fmt , ## arg) 48 if (debug >= level) \
49 printk(KERN_DEBUG "vbuf-vmalloc: " fmt , ## arg)
45 50
46 51
47/***************************************************************************/ 52/***************************************************************************/
48 53
49static void 54static void videobuf_vm_open(struct vm_area_struct *vma)
50videobuf_vm_open(struct vm_area_struct *vma)
51{ 55{
52 struct videobuf_mapping *map = vma->vm_private_data; 56 struct videobuf_mapping *map = vma->vm_private_data;
53 57
54 dprintk(2,"vm_open %p [count=%u,vma=%08lx-%08lx]\n",map, 58 dprintk(2, "vm_open %p [count=%u,vma=%08lx-%08lx]\n", map,
55 map->count,vma->vm_start,vma->vm_end); 59 map->count, vma->vm_start, vma->vm_end);
56 60
57 map->count++; 61 map->count++;
58} 62}
@@ -63,7 +67,7 @@ static void videobuf_vm_close(struct vm_area_struct *vma)
63 struct videobuf_queue *q = map->q; 67 struct videobuf_queue *q = map->q;
64 int i; 68 int i;
65 69
66 dprintk(2,"vm_close %p [count=%u,vma=%08lx-%08lx]\n", map, 70 dprintk(2, "vm_close %p [count=%u,vma=%08lx-%08lx]\n", map,
67 map->count, vma->vm_start, vma->vm_end); 71 map->count, vma->vm_start, vma->vm_end);
68 72
69 map->count--; 73 map->count--;
@@ -116,8 +120,7 @@ static void videobuf_vm_close(struct vm_area_struct *vma)
116 return; 120 return;
117} 121}
118 122
119static const struct vm_operations_struct videobuf_vm_ops = 123static const struct vm_operations_struct videobuf_vm_ops = {
120{
121 .open = videobuf_vm_open, 124 .open = videobuf_vm_open,
122 .close = videobuf_vm_close, 125 .close = videobuf_vm_close,
123}; 126};
@@ -137,23 +140,23 @@ static void *__videobuf_alloc(size_t size)
137 struct videobuf_vmalloc_memory *mem; 140 struct videobuf_vmalloc_memory *mem;
138 struct videobuf_buffer *vb; 141 struct videobuf_buffer *vb;
139 142
140 vb = kzalloc(size+sizeof(*mem),GFP_KERNEL); 143 vb = kzalloc(size + sizeof(*mem), GFP_KERNEL);
141 if (!vb) 144 if (!vb)
142 return vb; 145 return vb;
143 146
144 mem = vb->priv = ((char *)vb)+size; 147 mem = vb->priv = ((char *)vb) + size;
145 mem->magic=MAGIC_VMAL_MEM; 148 mem->magic = MAGIC_VMAL_MEM;
146 149
147 dprintk(1,"%s: allocated at %p(%ld+%ld) & %p(%ld)\n", 150 dprintk(1, "%s: allocated at %p(%ld+%ld) & %p(%ld)\n",
148 __func__,vb,(long)sizeof(*vb),(long)size-sizeof(*vb), 151 __func__, vb, (long)sizeof(*vb), (long)size - sizeof(*vb),
149 mem,(long)sizeof(*mem)); 152 mem, (long)sizeof(*mem));
150 153
151 return vb; 154 return vb;
152} 155}
153 156
154static int __videobuf_iolock (struct videobuf_queue* q, 157static int __videobuf_iolock(struct videobuf_queue *q,
155 struct videobuf_buffer *vb, 158 struct videobuf_buffer *vb,
156 struct v4l2_framebuffer *fbuf) 159 struct v4l2_framebuffer *fbuf)
157{ 160{
158 struct videobuf_vmalloc_memory *mem = vb->priv; 161 struct videobuf_vmalloc_memory *mem = vb->priv;
159 int pages; 162 int pages;
@@ -177,15 +180,13 @@ static int __videobuf_iolock (struct videobuf_queue* q,
177 180
178 dprintk(1, "%s memory method USERPTR\n", __func__); 181 dprintk(1, "%s memory method USERPTR\n", __func__);
179 182
180#if 1
181 if (vb->baddr) { 183 if (vb->baddr) {
182 printk(KERN_ERR "USERPTR is currently not supported\n"); 184 printk(KERN_ERR "USERPTR is currently not supported\n");
183 return -EINVAL; 185 return -EINVAL;
184 } 186 }
185#endif
186 187
187 /* The only USERPTR currently supported is the one needed for 188 /* The only USERPTR currently supported is the one needed for
188 read() method. 189 * read() method.
189 */ 190 */
190 191
191 mem->vmalloc = vmalloc_user(pages); 192 mem->vmalloc = vmalloc_user(pages);
@@ -210,7 +211,7 @@ static int __videobuf_iolock (struct videobuf_queue* q,
210 /* Try to remap memory */ 211 /* Try to remap memory */
211 rc = remap_vmalloc_range(mem->vma, (void *)vb->baddr, 0); 212 rc = remap_vmalloc_range(mem->vma, (void *)vb->baddr, 0);
212 if (rc < 0) { 213 if (rc < 0) {
213 printk(KERN_ERR "mmap: remap failed with error %d. ", rc); 214 printk(KERN_ERR "mmap: remap failed with error %d", rc);
214 return -ENOMEM; 215 return -ENOMEM;
215 } 216 }
216#endif 217#endif
@@ -273,7 +274,7 @@ static int __videobuf_mmap_mapper(struct videobuf_queue *q,
273 break; 274 break;
274 } 275 }
275 if (VIDEO_MAX_FRAME == first) { 276 if (VIDEO_MAX_FRAME == first) {
276 dprintk(1,"mmap app bug: offset invalid [offset=0x%lx]\n", 277 dprintk(1, "mmap app bug: offset invalid [offset=0x%lx]\n",
277 (vma->vm_pgoff << PAGE_SHIFT)); 278 (vma->vm_pgoff << PAGE_SHIFT));
278 return -EINVAL; 279 return -EINVAL;
279 } 280 }
@@ -300,8 +301,7 @@ static int __videobuf_mmap_mapper(struct videobuf_queue *q,
300 printk(KERN_ERR "vmalloc (%d pages) failed\n", pages); 301 printk(KERN_ERR "vmalloc (%d pages) failed\n", pages);
301 goto error; 302 goto error;
302 } 303 }
303 dprintk(1, "vmalloc is at addr %p (%d pages)\n", 304 dprintk(1, "vmalloc is at addr %p (%d pages)\n", mem->vmalloc, pages);
304 mem->vmalloc, pages);
305 305
306 /* Try to remap memory */ 306 /* Try to remap memory */
307 retval = remap_vmalloc_range(vma, mem->vmalloc, 0); 307 retval = remap_vmalloc_range(vma, mem->vmalloc, 0);
@@ -315,7 +315,7 @@ static int __videobuf_mmap_mapper(struct videobuf_queue *q,
315 vma->vm_flags |= VM_DONTEXPAND | VM_RESERVED; 315 vma->vm_flags |= VM_DONTEXPAND | VM_RESERVED;
316 vma->vm_private_data = map; 316 vma->vm_private_data = map;
317 317
318 dprintk(1,"mmap %p: q=%p %08lx-%08lx (%lx) pgoff %08lx buf %d\n", 318 dprintk(1, "mmap %p: q=%p %08lx-%08lx (%lx) pgoff %08lx buf %d\n",
319 map, q, vma->vm_start, vma->vm_end, 319 map, q, vma->vm_start, vma->vm_end,
320 (long int) q->bufs[first]->bsize, 320 (long int) q->bufs[first]->bsize,
321 vma->vm_pgoff, first); 321 vma->vm_pgoff, first);
@@ -330,15 +330,15 @@ error:
330 return -ENOMEM; 330 return -ENOMEM;
331} 331}
332 332
333static int __videobuf_copy_to_user ( struct videobuf_queue *q, 333static int __videobuf_copy_to_user(struct videobuf_queue *q,
334 char __user *data, size_t count, 334 char __user *data, size_t count,
335 int nonblocking ) 335 int nonblocking)
336{ 336{
337 struct videobuf_vmalloc_memory *mem=q->read_buf->priv; 337 struct videobuf_vmalloc_memory *mem = q->read_buf->priv;
338 BUG_ON (!mem); 338 BUG_ON(!mem);
339 MAGIC_CHECK(mem->magic,MAGIC_VMAL_MEM); 339 MAGIC_CHECK(mem->magic, MAGIC_VMAL_MEM);
340 340
341 BUG_ON (!mem->vmalloc); 341 BUG_ON(!mem->vmalloc);
342 342
343 /* copy to userspace */ 343 /* copy to userspace */
344 if (count > q->read_buf->size - q->read_off) 344 if (count > q->read_buf->size - q->read_off)
@@ -350,30 +350,30 @@ static int __videobuf_copy_to_user ( struct videobuf_queue *q,
350 return count; 350 return count;
351} 351}
352 352
353static int __videobuf_copy_stream ( struct videobuf_queue *q, 353static int __videobuf_copy_stream(struct videobuf_queue *q,
354 char __user *data, size_t count, size_t pos, 354 char __user *data, size_t count, size_t pos,
355 int vbihack, int nonblocking ) 355 int vbihack, int nonblocking)
356{ 356{
357 unsigned int *fc; 357 unsigned int *fc;
358 struct videobuf_vmalloc_memory *mem=q->read_buf->priv; 358 struct videobuf_vmalloc_memory *mem = q->read_buf->priv;
359 BUG_ON (!mem); 359 BUG_ON(!mem);
360 MAGIC_CHECK(mem->magic,MAGIC_VMAL_MEM); 360 MAGIC_CHECK(mem->magic, MAGIC_VMAL_MEM);
361 361
362 if (vbihack) { 362 if (vbihack) {
363 /* dirty, undocumented hack -- pass the frame counter 363 /* dirty, undocumented hack -- pass the frame counter
364 * within the last four bytes of each vbi data block. 364 * within the last four bytes of each vbi data block.
365 * We need that one to maintain backward compatibility 365 * We need that one to maintain backward compatibility
366 * to all vbi decoding software out there ... */ 366 * to all vbi decoding software out there ... */
367 fc = (unsigned int*)mem->vmalloc; 367 fc = (unsigned int *)mem->vmalloc;
368 fc += (q->read_buf->size>>2) -1; 368 fc += (q->read_buf->size >> 2) - 1;
369 *fc = q->read_buf->field_count >> 1; 369 *fc = q->read_buf->field_count >> 1;
370 dprintk(1,"vbihack: %d\n",*fc); 370 dprintk(1, "vbihack: %d\n", *fc);
371 } 371 }
372 372
373 /* copy stuff using the common method */ 373 /* copy stuff using the common method */
374 count = __videobuf_copy_to_user (q,data,count,nonblocking); 374 count = __videobuf_copy_to_user(q, data, count, nonblocking);
375 375
376 if ( (count==-EFAULT) && (0 == pos) ) 376 if ((count == -EFAULT) && (0 == pos))
377 return -EFAULT; 377 return -EFAULT;
378 378
379 return count; 379 return count;
@@ -392,7 +392,7 @@ static struct videobuf_qtype_ops qops = {
392 .vmalloc = videobuf_to_vmalloc, 392 .vmalloc = videobuf_to_vmalloc,
393}; 393};
394 394
395void videobuf_queue_vmalloc_init(struct videobuf_queue* q, 395void videobuf_queue_vmalloc_init(struct videobuf_queue *q,
396 const struct videobuf_queue_ops *ops, 396 const struct videobuf_queue_ops *ops,
397 struct device *dev, 397 struct device *dev,
398 spinlock_t *irqlock, 398 spinlock_t *irqlock,
@@ -404,20 +404,19 @@ void videobuf_queue_vmalloc_init(struct videobuf_queue* q,
404 videobuf_queue_core_init(q, ops, dev, irqlock, type, field, msize, 404 videobuf_queue_core_init(q, ops, dev, irqlock, type, field, msize,
405 priv, &qops); 405 priv, &qops);
406} 406}
407
408EXPORT_SYMBOL_GPL(videobuf_queue_vmalloc_init); 407EXPORT_SYMBOL_GPL(videobuf_queue_vmalloc_init);
409 408
410void *videobuf_to_vmalloc (struct videobuf_buffer *buf) 409void *videobuf_to_vmalloc(struct videobuf_buffer *buf)
411{ 410{
412 struct videobuf_vmalloc_memory *mem=buf->priv; 411 struct videobuf_vmalloc_memory *mem = buf->priv;
413 BUG_ON (!mem); 412 BUG_ON(!mem);
414 MAGIC_CHECK(mem->magic,MAGIC_VMAL_MEM); 413 MAGIC_CHECK(mem->magic, MAGIC_VMAL_MEM);
415 414
416 return mem->vmalloc; 415 return mem->vmalloc;
417} 416}
418EXPORT_SYMBOL_GPL(videobuf_to_vmalloc); 417EXPORT_SYMBOL_GPL(videobuf_to_vmalloc);
419 418
420void videobuf_vmalloc_free (struct videobuf_buffer *buf) 419void videobuf_vmalloc_free(struct videobuf_buffer *buf)
421{ 420{
422 struct videobuf_vmalloc_memory *mem = buf->priv; 421 struct videobuf_vmalloc_memory *mem = buf->priv;
423 422
@@ -442,8 +441,3 @@ void videobuf_vmalloc_free (struct videobuf_buffer *buf)
442} 441}
443EXPORT_SYMBOL_GPL(videobuf_vmalloc_free); 442EXPORT_SYMBOL_GPL(videobuf_vmalloc_free);
444 443
445/*
446 * Local variables:
447 * c-basic-offset: 8
448 * End:
449 */
diff --git a/include/media/videobuf-core.h b/include/media/videobuf-core.h
index 316fdccdcaa0..b1f7bf423fd3 100644
--- a/include/media/videobuf-core.h
+++ b/include/media/videobuf-core.h
@@ -129,14 +129,14 @@ struct videobuf_qtype_ops {
129 129
130 void *(*alloc) (size_t size); 130 void *(*alloc) (size_t size);
131 void *(*vmalloc) (struct videobuf_buffer *buf); 131 void *(*vmalloc) (struct videobuf_buffer *buf);
132 int (*iolock) (struct videobuf_queue* q, 132 int (*iolock) (struct videobuf_queue *q,
133 struct videobuf_buffer *vb, 133 struct videobuf_buffer *vb,
134 struct v4l2_framebuffer *fbuf); 134 struct v4l2_framebuffer *fbuf);
135 int (*mmap) (struct videobuf_queue *q, 135 int (*mmap) (struct videobuf_queue *q,
136 unsigned int *count, 136 unsigned int *count,
137 unsigned int *size, 137 unsigned int *size,
138 enum v4l2_memory memory); 138 enum v4l2_memory memory);
139 int (*sync) (struct videobuf_queue* q, 139 int (*sync) (struct videobuf_queue *q,
140 struct videobuf_buffer *buf); 140 struct videobuf_buffer *buf);
141 int (*video_copy_to_user)(struct videobuf_queue *q, 141 int (*video_copy_to_user)(struct videobuf_queue *q,
142 char __user *data, 142 char __user *data,
@@ -185,14 +185,14 @@ struct videobuf_queue {
185}; 185};
186 186
187int videobuf_waiton(struct videobuf_buffer *vb, int non_blocking, int intr); 187int videobuf_waiton(struct videobuf_buffer *vb, int non_blocking, int intr);
188int videobuf_iolock(struct videobuf_queue* q, struct videobuf_buffer *vb, 188int videobuf_iolock(struct videobuf_queue *q, struct videobuf_buffer *vb,
189 struct v4l2_framebuffer *fbuf); 189 struct v4l2_framebuffer *fbuf);
190 190
191void *videobuf_alloc(struct videobuf_queue* q); 191void *videobuf_alloc(struct videobuf_queue* q);
192 192
193/* Used on videobuf-dvb */ 193/* Used on videobuf-dvb */
194void *videobuf_queue_to_vmalloc (struct videobuf_queue* q, 194void *videobuf_queue_to_vmalloc(struct videobuf_queue *q,
195 struct videobuf_buffer *buf); 195 struct videobuf_buffer *buf);
196 196
197void videobuf_queue_core_init(struct videobuf_queue *q, 197void videobuf_queue_core_init(struct videobuf_queue *q,
198 const struct videobuf_queue_ops *ops, 198 const struct videobuf_queue_ops *ops,
diff --git a/include/media/videobuf-dma-sg.h b/include/media/videobuf-dma-sg.h
index 53e72f787175..dbfd8cf7b7cb 100644
--- a/include/media/videobuf-dma-sg.h
+++ b/include/media/videobuf-dma-sg.h
@@ -17,6 +17,8 @@
17 * it under the terms of the GNU General Public License as published by 17 * it under the terms of the GNU General Public License as published by
18 * the Free Software Foundation; either version 2 18 * the Free Software Foundation; either version 2
19 */ 19 */
20#ifndef _VIDEOBUF_DMA_SG_H
21#define _VIDEOBUF_DMA_SG_H
20 22
21#include <media/videobuf-core.h> 23#include <media/videobuf-core.h>
22 24
@@ -27,14 +29,14 @@
27 * block (NULL on errors). Memory for the scatterlist is allocated 29 * block (NULL on errors). Memory for the scatterlist is allocated
28 * using kmalloc. The caller must free the memory. 30 * using kmalloc. The caller must free the memory.
29 */ 31 */
30struct scatterlist* videobuf_vmalloc_to_sg(unsigned char *virt, int nr_pages); 32struct scatterlist *videobuf_vmalloc_to_sg(unsigned char *virt, int nr_pages);
31 33
32/* 34/*
33 * Return a scatterlist for a an array of userpages (NULL on errors). 35 * Return a scatterlist for a an array of userpages (NULL on errors).
34 * Memory for the scatterlist is allocated using kmalloc. The caller 36 * Memory for the scatterlist is allocated using kmalloc. The caller
35 * must free the memory. 37 * must free the memory.
36 */ 38 */
37struct scatterlist* videobuf_pages_to_sg(struct page **pages, int nr_pages, 39struct scatterlist *videobuf_pages_to_sg(struct page **pages, int nr_pages,
38 int offset); 40 int offset);
39 41
40/* --------------------------------------------------------------------- */ 42/* --------------------------------------------------------------------- */
@@ -78,8 +80,7 @@ struct videobuf_dmabuf {
78 int direction; 80 int direction;
79}; 81};
80 82
81struct videobuf_dma_sg_memory 83struct videobuf_dma_sg_memory {
82{
83 u32 magic; 84 u32 magic;
84 85
85 /* for mmap'ed buffers */ 86 /* for mmap'ed buffers */
@@ -95,14 +96,14 @@ int videobuf_dma_init_overlay(struct videobuf_dmabuf *dma, int direction,
95 dma_addr_t addr, int nr_pages); 96 dma_addr_t addr, int nr_pages);
96int videobuf_dma_free(struct videobuf_dmabuf *dma); 97int videobuf_dma_free(struct videobuf_dmabuf *dma);
97 98
98int videobuf_dma_map(struct videobuf_queue* q,struct videobuf_dmabuf *dma); 99int videobuf_dma_map(struct videobuf_queue *q, struct videobuf_dmabuf *dma);
99int videobuf_dma_sync(struct videobuf_queue* q,struct videobuf_dmabuf *dma); 100int videobuf_dma_sync(struct videobuf_queue *q, struct videobuf_dmabuf *dma);
100int videobuf_dma_unmap(struct videobuf_queue* q,struct videobuf_dmabuf *dma); 101int videobuf_dma_unmap(struct videobuf_queue *q, struct videobuf_dmabuf *dma);
101struct videobuf_dmabuf *videobuf_to_dma (struct videobuf_buffer *buf); 102struct videobuf_dmabuf *videobuf_to_dma(struct videobuf_buffer *buf);
102 103
103void *videobuf_sg_alloc(size_t size); 104void *videobuf_sg_alloc(size_t size);
104 105
105void videobuf_queue_sg_init(struct videobuf_queue* q, 106void videobuf_queue_sg_init(struct videobuf_queue *q,
106 const struct videobuf_queue_ops *ops, 107 const struct videobuf_queue_ops *ops,
107 struct device *dev, 108 struct device *dev,
108 spinlock_t *irqlock, 109 spinlock_t *irqlock,
@@ -111,9 +112,11 @@ void videobuf_queue_sg_init(struct videobuf_queue* q,
111 unsigned int msize, 112 unsigned int msize,
112 void *priv); 113 void *priv);
113 114
114 /*FIXME: these variants are used only on *-alsa code, where videobuf is 115/*FIXME: these variants are used only on *-alsa code, where videobuf is
115 * used without queue 116 * used without queue
116 */ 117 */
117int videobuf_sg_dma_map(struct device *dev, struct videobuf_dmabuf *dma); 118int videobuf_sg_dma_map(struct device *dev, struct videobuf_dmabuf *dma);
118int videobuf_sg_dma_unmap(struct device *dev, struct videobuf_dmabuf *dma); 119int videobuf_sg_dma_unmap(struct device *dev, struct videobuf_dmabuf *dma);
119 120
121#endif /* _VIDEOBUF_DMA_SG_H */
122
diff --git a/include/media/videobuf-vmalloc.h b/include/media/videobuf-vmalloc.h
index 4b419a257a7d..851eb1a2ff2a 100644
--- a/include/media/videobuf-vmalloc.h
+++ b/include/media/videobuf-vmalloc.h
@@ -19,17 +19,17 @@
19 19
20/* --------------------------------------------------------------------- */ 20/* --------------------------------------------------------------------- */
21 21
22struct videobuf_vmalloc_memory 22struct videobuf_vmalloc_memory {
23{
24 u32 magic; 23 u32 magic;
25 24
26 void *vmalloc; 25 void *vmalloc;
27 26
28 /* remap_vmalloc_range seems to need to run after mmap() on some cases */ 27 /* remap_vmalloc_range seems to need to run
28 * after mmap() on some cases */
29 struct vm_area_struct *vma; 29 struct vm_area_struct *vma;
30}; 30};
31 31
32void videobuf_queue_vmalloc_init(struct videobuf_queue* q, 32void videobuf_queue_vmalloc_init(struct videobuf_queue *q,
33 const struct videobuf_queue_ops *ops, 33 const struct videobuf_queue_ops *ops,
34 struct device *dev, 34 struct device *dev,
35 spinlock_t *irqlock, 35 spinlock_t *irqlock,
@@ -38,8 +38,8 @@ void videobuf_queue_vmalloc_init(struct videobuf_queue* q,
38 unsigned int msize, 38 unsigned int msize,
39 void *priv); 39 void *priv);
40 40
41void *videobuf_to_vmalloc (struct videobuf_buffer *buf); 41void *videobuf_to_vmalloc(struct videobuf_buffer *buf);
42 42
43void videobuf_vmalloc_free (struct videobuf_buffer *buf); 43void videobuf_vmalloc_free(struct videobuf_buffer *buf);
44 44
45#endif 45#endif