aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJunghak Sung <jh1009.sung@samsung.com>2015-10-06 05:37:47 -0400
committerMauro Carvalho Chehab <mchehab@osg.samsung.com>2015-10-20 12:49:39 -0400
commitbed04f9342473743fc96b71c3130f645c718bd47 (patch)
tree953f937cb8e3ebeca99d84e4eed759eab528db82
parent33119e80c3b96ac81912677a6e86dc1890a5859f (diff)
[media] media: videobuf2: Replace v4l2-specific data with vb2 data
Simple changes that replace v4l2-specific data with vb2 data in videobuf2-core. enum v4l2_buf_type --> int enum v4l2_memory --> enum vb2_memory VIDEO_MAX_FRAME --> VB2_MAX_FRAME VIDEO_MAX_PLANES --> VB2_MAX_PLANES struct v4l2_fh *owner --> void *owner V4L2_TYPE_IS_MULTIPLANAR() --> is_multiplanar V4L2_TYPE_IS_OUTPUT() --> is_output Signed-off-by: Junghak Sung <jh1009.sung@samsung.com> Signed-off-by: Geunyoung Kim <nenggun.kim@samsung.com> Acked-by: Seung-Woo Kim <sw0312.kim@samsung.com> Acked-by: Inki Dae <inki.dae@samsung.com> Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com> Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
-rw-r--r--drivers/media/v4l2-core/videobuf2-core.c131
-rw-r--r--include/media/videobuf2-core.h33
-rw-r--r--include/media/videobuf2-v4l2.h8
-rw-r--r--include/trace/events/v4l2.h5
4 files changed, 106 insertions, 71 deletions
diff --git a/drivers/media/v4l2-core/videobuf2-core.c b/drivers/media/v4l2-core/videobuf2-core.c
index 8c456f7b1995..db685e8a4406 100644
--- a/drivers/media/v4l2-core/videobuf2-core.c
+++ b/drivers/media/v4l2-core/videobuf2-core.c
@@ -193,7 +193,7 @@ static int __vb2_buf_mem_alloc(struct vb2_buffer *vb)
193{ 193{
194 struct vb2_queue *q = vb->vb2_queue; 194 struct vb2_queue *q = vb->vb2_queue;
195 enum dma_data_direction dma_dir = 195 enum dma_data_direction dma_dir =
196 V4L2_TYPE_IS_OUTPUT(q->type) ? DMA_TO_DEVICE : DMA_FROM_DEVICE; 196 q->is_output ? DMA_TO_DEVICE : DMA_FROM_DEVICE;
197 void *mem_priv; 197 void *mem_priv;
198 int plane; 198 int plane;
199 199
@@ -347,7 +347,7 @@ static void __setup_offsets(struct vb2_queue *q, unsigned int n)
347 * 347 *
348 * Returns the number of buffers successfully allocated. 348 * Returns the number of buffers successfully allocated.
349 */ 349 */
350static int __vb2_queue_alloc(struct vb2_queue *q, enum v4l2_memory memory, 350static int __vb2_queue_alloc(struct vb2_queue *q, enum vb2_memory memory,
351 unsigned int num_buffers, unsigned int num_planes) 351 unsigned int num_buffers, unsigned int num_planes)
352{ 352{
353 unsigned int buffer; 353 unsigned int buffer;
@@ -370,7 +370,7 @@ static int __vb2_queue_alloc(struct vb2_queue *q, enum v4l2_memory memory,
370 vb->memory = memory; 370 vb->memory = memory;
371 371
372 /* Allocate video buffer memory for the MMAP type */ 372 /* Allocate video buffer memory for the MMAP type */
373 if (memory == V4L2_MEMORY_MMAP) { 373 if (memory == VB2_MEMORY_MMAP) {
374 ret = __vb2_buf_mem_alloc(vb); 374 ret = __vb2_buf_mem_alloc(vb);
375 if (ret) { 375 if (ret) {
376 dprintk(1, "failed allocating memory for " 376 dprintk(1, "failed allocating memory for "
@@ -397,7 +397,7 @@ static int __vb2_queue_alloc(struct vb2_queue *q, enum v4l2_memory memory,
397 } 397 }
398 398
399 __setup_lengths(q, buffer); 399 __setup_lengths(q, buffer);
400 if (memory == V4L2_MEMORY_MMAP) 400 if (memory == VB2_MEMORY_MMAP)
401 __setup_offsets(q, buffer); 401 __setup_offsets(q, buffer);
402 402
403 dprintk(1, "allocated %d buffers, %d plane(s) each\n", 403 dprintk(1, "allocated %d buffers, %d plane(s) each\n",
@@ -421,9 +421,9 @@ static void __vb2_free_mem(struct vb2_queue *q, unsigned int buffers)
421 continue; 421 continue;
422 422
423 /* Free MMAP buffers or release USERPTR buffers */ 423 /* Free MMAP buffers or release USERPTR buffers */
424 if (q->memory == V4L2_MEMORY_MMAP) 424 if (q->memory == VB2_MEMORY_MMAP)
425 __vb2_buf_mem_free(vb); 425 __vb2_buf_mem_free(vb);
426 else if (q->memory == V4L2_MEMORY_DMABUF) 426 else if (q->memory == VB2_MEMORY_DMABUF)
427 __vb2_buf_dmabuf_put(vb); 427 __vb2_buf_dmabuf_put(vb);
428 else 428 else
429 __vb2_buf_userptr_put(vb); 429 __vb2_buf_userptr_put(vb);
@@ -562,7 +562,7 @@ static int __verify_planes_array(struct vb2_buffer *vb, const struct v4l2_buffer
562 return -EINVAL; 562 return -EINVAL;
563 } 563 }
564 564
565 if (b->length < vb->num_planes || b->length > VIDEO_MAX_PLANES) { 565 if (b->length < vb->num_planes || b->length > VB2_MAX_PLANES) {
566 dprintk(1, "incorrect planes array length, " 566 dprintk(1, "incorrect planes array length, "
567 "expected %d, got %d\n", vb->num_planes, b->length); 567 "expected %d, got %d\n", vb->num_planes, b->length);
568 return -EINVAL; 568 return -EINVAL;
@@ -586,8 +586,8 @@ static int __verify_length(struct vb2_buffer *vb, const struct v4l2_buffer *b)
586 586
587 if (V4L2_TYPE_IS_MULTIPLANAR(b->type)) { 587 if (V4L2_TYPE_IS_MULTIPLANAR(b->type)) {
588 for (plane = 0; plane < vb->num_planes; ++plane) { 588 for (plane = 0; plane < vb->num_planes; ++plane) {
589 length = (b->memory == V4L2_MEMORY_USERPTR || 589 length = (b->memory == VB2_MEMORY_USERPTR ||
590 b->memory == V4L2_MEMORY_DMABUF) 590 b->memory == VB2_MEMORY_DMABUF)
591 ? b->m.planes[plane].length 591 ? b->m.planes[plane].length
592 : vb->planes[plane].length; 592 : vb->planes[plane].length;
593 bytesused = b->m.planes[plane].bytesused 593 bytesused = b->m.planes[plane].bytesused
@@ -601,7 +601,7 @@ static int __verify_length(struct vb2_buffer *vb, const struct v4l2_buffer *b)
601 return -EINVAL; 601 return -EINVAL;
602 } 602 }
603 } else { 603 } else {
604 length = (b->memory == V4L2_MEMORY_USERPTR) 604 length = (b->memory == VB2_MEMORY_USERPTR)
605 ? b->length : vb->planes[0].length; 605 ? b->length : vb->planes[0].length;
606 606
607 if (b->bytesused > length) 607 if (b->bytesused > length)
@@ -670,7 +670,7 @@ static void __fill_v4l2_buffer(struct vb2_buffer *vb, struct v4l2_buffer *b)
670 b->reserved2 = 0; 670 b->reserved2 = 0;
671 b->reserved = 0; 671 b->reserved = 0;
672 672
673 if (V4L2_TYPE_IS_MULTIPLANAR(q->type)) { 673 if (q->is_multiplanar) {
674 /* 674 /*
675 * Fill in plane-related data if userspace provided an array 675 * Fill in plane-related data if userspace provided an array
676 * for it. The caller has already verified memory and size. 676 * for it. The caller has already verified memory and size.
@@ -682,11 +682,11 @@ static void __fill_v4l2_buffer(struct vb2_buffer *vb, struct v4l2_buffer *b)
682 682
683 pdst->bytesused = psrc->bytesused; 683 pdst->bytesused = psrc->bytesused;
684 pdst->length = psrc->length; 684 pdst->length = psrc->length;
685 if (q->memory == V4L2_MEMORY_MMAP) 685 if (q->memory == VB2_MEMORY_MMAP)
686 pdst->m.mem_offset = psrc->m.offset; 686 pdst->m.mem_offset = psrc->m.offset;
687 else if (q->memory == V4L2_MEMORY_USERPTR) 687 else if (q->memory == VB2_MEMORY_USERPTR)
688 pdst->m.userptr = psrc->m.userptr; 688 pdst->m.userptr = psrc->m.userptr;
689 else if (q->memory == V4L2_MEMORY_DMABUF) 689 else if (q->memory == VB2_MEMORY_DMABUF)
690 pdst->m.fd = psrc->m.fd; 690 pdst->m.fd = psrc->m.fd;
691 pdst->data_offset = psrc->data_offset; 691 pdst->data_offset = psrc->data_offset;
692 memset(pdst->reserved, 0, sizeof(pdst->reserved)); 692 memset(pdst->reserved, 0, sizeof(pdst->reserved));
@@ -698,11 +698,11 @@ static void __fill_v4l2_buffer(struct vb2_buffer *vb, struct v4l2_buffer *b)
698 */ 698 */
699 b->length = vb->planes[0].length; 699 b->length = vb->planes[0].length;
700 b->bytesused = vb->planes[0].bytesused; 700 b->bytesused = vb->planes[0].bytesused;
701 if (q->memory == V4L2_MEMORY_MMAP) 701 if (q->memory == VB2_MEMORY_MMAP)
702 b->m.offset = vb->planes[0].m.offset; 702 b->m.offset = vb->planes[0].m.offset;
703 else if (q->memory == V4L2_MEMORY_USERPTR) 703 else if (q->memory == VB2_MEMORY_USERPTR)
704 b->m.userptr = vb->planes[0].m.userptr; 704 b->m.userptr = vb->planes[0].m.userptr;
705 else if (q->memory == V4L2_MEMORY_DMABUF) 705 else if (q->memory == VB2_MEMORY_DMABUF)
706 b->m.fd = vb->planes[0].m.fd; 706 b->m.fd = vb->planes[0].m.fd;
707 } 707 }
708 708
@@ -826,10 +826,10 @@ static int __verify_dmabuf_ops(struct vb2_queue *q)
826 * passed to a buffer operation are compatible with the queue. 826 * passed to a buffer operation are compatible with the queue.
827 */ 827 */
828static int __verify_memory_type(struct vb2_queue *q, 828static int __verify_memory_type(struct vb2_queue *q,
829 enum v4l2_memory memory, enum v4l2_buf_type type) 829 enum vb2_memory memory, unsigned int type)
830{ 830{
831 if (memory != V4L2_MEMORY_MMAP && memory != V4L2_MEMORY_USERPTR && 831 if (memory != VB2_MEMORY_MMAP && memory != VB2_MEMORY_USERPTR &&
832 memory != V4L2_MEMORY_DMABUF) { 832 memory != VB2_MEMORY_DMABUF) {
833 dprintk(1, "unsupported memory type\n"); 833 dprintk(1, "unsupported memory type\n");
834 return -EINVAL; 834 return -EINVAL;
835 } 835 }
@@ -843,17 +843,17 @@ static int __verify_memory_type(struct vb2_queue *q,
843 * Make sure all the required memory ops for given memory type 843 * Make sure all the required memory ops for given memory type
844 * are available. 844 * are available.
845 */ 845 */
846 if (memory == V4L2_MEMORY_MMAP && __verify_mmap_ops(q)) { 846 if (memory == VB2_MEMORY_MMAP && __verify_mmap_ops(q)) {
847 dprintk(1, "MMAP for current setup unsupported\n"); 847 dprintk(1, "MMAP for current setup unsupported\n");
848 return -EINVAL; 848 return -EINVAL;
849 } 849 }
850 850
851 if (memory == V4L2_MEMORY_USERPTR && __verify_userptr_ops(q)) { 851 if (memory == VB2_MEMORY_USERPTR && __verify_userptr_ops(q)) {
852 dprintk(1, "USERPTR for current setup unsupported\n"); 852 dprintk(1, "USERPTR for current setup unsupported\n");
853 return -EINVAL; 853 return -EINVAL;
854 } 854 }
855 855
856 if (memory == V4L2_MEMORY_DMABUF && __verify_dmabuf_ops(q)) { 856 if (memory == VB2_MEMORY_DMABUF && __verify_dmabuf_ops(q)) {
857 dprintk(1, "DMABUF for current setup unsupported\n"); 857 dprintk(1, "DMABUF for current setup unsupported\n");
858 return -EINVAL; 858 return -EINVAL;
859 } 859 }
@@ -909,7 +909,7 @@ static int __reqbufs(struct vb2_queue *q, struct v4l2_requestbuffers *req)
909 * are not in use and can be freed. 909 * are not in use and can be freed.
910 */ 910 */
911 mutex_lock(&q->mmap_lock); 911 mutex_lock(&q->mmap_lock);
912 if (q->memory == V4L2_MEMORY_MMAP && __buffers_in_use(q)) { 912 if (q->memory == VB2_MEMORY_MMAP && __buffers_in_use(q)) {
913 mutex_unlock(&q->mmap_lock); 913 mutex_unlock(&q->mmap_lock);
914 dprintk(1, "memory in use, cannot free\n"); 914 dprintk(1, "memory in use, cannot free\n");
915 return -EBUSY; 915 return -EBUSY;
@@ -937,7 +937,7 @@ static int __reqbufs(struct vb2_queue *q, struct v4l2_requestbuffers *req)
937 /* 937 /*
938 * Make sure the requested values and current defaults are sane. 938 * Make sure the requested values and current defaults are sane.
939 */ 939 */
940 num_buffers = min_t(unsigned int, req->count, VIDEO_MAX_FRAME); 940 num_buffers = min_t(unsigned int, req->count, VB2_MAX_FRAME);
941 num_buffers = max_t(unsigned int, num_buffers, q->min_buffers_needed); 941 num_buffers = max_t(unsigned int, num_buffers, q->min_buffers_needed);
942 memset(q->plane_sizes, 0, sizeof(q->plane_sizes)); 942 memset(q->plane_sizes, 0, sizeof(q->plane_sizes));
943 memset(q->alloc_ctx, 0, sizeof(q->alloc_ctx)); 943 memset(q->alloc_ctx, 0, sizeof(q->alloc_ctx));
@@ -1003,7 +1003,7 @@ static int __reqbufs(struct vb2_queue *q, struct v4l2_requestbuffers *req)
1003 * to the userspace. 1003 * to the userspace.
1004 */ 1004 */
1005 req->count = allocated_buffers; 1005 req->count = allocated_buffers;
1006 q->waiting_for_buffers = !V4L2_TYPE_IS_OUTPUT(q->type); 1006 q->waiting_for_buffers = !q->is_output;
1007 1007
1008 return 0; 1008 return 0;
1009} 1009}
@@ -1042,7 +1042,7 @@ static int __create_bufs(struct vb2_queue *q, struct v4l2_create_buffers *create
1042 unsigned int num_planes = 0, num_buffers, allocated_buffers; 1042 unsigned int num_planes = 0, num_buffers, allocated_buffers;
1043 int ret; 1043 int ret;
1044 1044
1045 if (q->num_buffers == VIDEO_MAX_FRAME) { 1045 if (q->num_buffers == VB2_MAX_FRAME) {
1046 dprintk(1, "maximum number of buffers already allocated\n"); 1046 dprintk(1, "maximum number of buffers already allocated\n");
1047 return -ENOBUFS; 1047 return -ENOBUFS;
1048 } 1048 }
@@ -1051,10 +1051,10 @@ static int __create_bufs(struct vb2_queue *q, struct v4l2_create_buffers *create
1051 memset(q->plane_sizes, 0, sizeof(q->plane_sizes)); 1051 memset(q->plane_sizes, 0, sizeof(q->plane_sizes));
1052 memset(q->alloc_ctx, 0, sizeof(q->alloc_ctx)); 1052 memset(q->alloc_ctx, 0, sizeof(q->alloc_ctx));
1053 q->memory = create->memory; 1053 q->memory = create->memory;
1054 q->waiting_for_buffers = !V4L2_TYPE_IS_OUTPUT(q->type); 1054 q->waiting_for_buffers = !q->is_output;
1055 } 1055 }
1056 1056
1057 num_buffers = min(create->count, VIDEO_MAX_FRAME - q->num_buffers); 1057 num_buffers = min(create->count, VB2_MAX_FRAME - q->num_buffers);
1058 1058
1059 /* 1059 /*
1060 * Ask the driver, whether the requested number of buffers, planes per 1060 * Ask the driver, whether the requested number of buffers, planes per
@@ -1305,7 +1305,7 @@ static void __fill_vb2_buffer(struct vb2_buffer *vb,
1305 unsigned int plane; 1305 unsigned int plane;
1306 1306
1307 if (V4L2_TYPE_IS_MULTIPLANAR(b->type)) { 1307 if (V4L2_TYPE_IS_MULTIPLANAR(b->type)) {
1308 if (b->memory == V4L2_MEMORY_USERPTR) { 1308 if (b->memory == VB2_MEMORY_USERPTR) {
1309 for (plane = 0; plane < vb->num_planes; ++plane) { 1309 for (plane = 0; plane < vb->num_planes; ++plane) {
1310 planes[plane].m.userptr = 1310 planes[plane].m.userptr =
1311 b->m.planes[plane].m.userptr; 1311 b->m.planes[plane].m.userptr;
@@ -1313,7 +1313,7 @@ static void __fill_vb2_buffer(struct vb2_buffer *vb,
1313 b->m.planes[plane].length; 1313 b->m.planes[plane].length;
1314 } 1314 }
1315 } 1315 }
1316 if (b->memory == V4L2_MEMORY_DMABUF) { 1316 if (b->memory == VB2_MEMORY_DMABUF) {
1317 for (plane = 0; plane < vb->num_planes; ++plane) { 1317 for (plane = 0; plane < vb->num_planes; ++plane) {
1318 planes[plane].m.fd = 1318 planes[plane].m.fd =
1319 b->m.planes[plane].m.fd; 1319 b->m.planes[plane].m.fd;
@@ -1370,12 +1370,12 @@ static void __fill_vb2_buffer(struct vb2_buffer *vb,
1370 * the driver should use the allow_zero_bytesused flag to keep 1370 * the driver should use the allow_zero_bytesused flag to keep
1371 * old userspace applications working. 1371 * old userspace applications working.
1372 */ 1372 */
1373 if (b->memory == V4L2_MEMORY_USERPTR) { 1373 if (b->memory == VB2_MEMORY_USERPTR) {
1374 planes[0].m.userptr = b->m.userptr; 1374 planes[0].m.userptr = b->m.userptr;
1375 planes[0].length = b->length; 1375 planes[0].length = b->length;
1376 } 1376 }
1377 1377
1378 if (b->memory == V4L2_MEMORY_DMABUF) { 1378 if (b->memory == VB2_MEMORY_DMABUF) {
1379 planes[0].m.fd = b->m.fd; 1379 planes[0].m.fd = b->m.fd;
1380 planes[0].length = b->length; 1380 planes[0].length = b->length;
1381 } 1381 }
@@ -1435,13 +1435,13 @@ static int __qbuf_mmap(struct vb2_buffer *vb, const struct v4l2_buffer *b)
1435 */ 1435 */
1436static int __qbuf_userptr(struct vb2_buffer *vb, const struct v4l2_buffer *b) 1436static int __qbuf_userptr(struct vb2_buffer *vb, const struct v4l2_buffer *b)
1437{ 1437{
1438 struct vb2_plane planes[VIDEO_MAX_PLANES]; 1438 struct vb2_plane planes[VB2_MAX_PLANES];
1439 struct vb2_queue *q = vb->vb2_queue; 1439 struct vb2_queue *q = vb->vb2_queue;
1440 void *mem_priv; 1440 void *mem_priv;
1441 unsigned int plane; 1441 unsigned int plane;
1442 int ret; 1442 int ret;
1443 enum dma_data_direction dma_dir = 1443 enum dma_data_direction dma_dir =
1444 V4L2_TYPE_IS_OUTPUT(q->type) ? DMA_TO_DEVICE : DMA_FROM_DEVICE; 1444 q->is_output ? DMA_TO_DEVICE : DMA_FROM_DEVICE;
1445 bool reacquired = vb->planes[0].mem_priv == NULL; 1445 bool reacquired = vb->planes[0].mem_priv == NULL;
1446 1446
1447 memset(planes, 0, sizeof(planes[0]) * vb->num_planes); 1447 memset(planes, 0, sizeof(planes[0]) * vb->num_planes);
@@ -1547,13 +1547,13 @@ err:
1547 */ 1547 */
1548static int __qbuf_dmabuf(struct vb2_buffer *vb, const struct v4l2_buffer *b) 1548static int __qbuf_dmabuf(struct vb2_buffer *vb, const struct v4l2_buffer *b)
1549{ 1549{
1550 struct vb2_plane planes[VIDEO_MAX_PLANES]; 1550 struct vb2_plane planes[VB2_MAX_PLANES];
1551 struct vb2_queue *q = vb->vb2_queue; 1551 struct vb2_queue *q = vb->vb2_queue;
1552 void *mem_priv; 1552 void *mem_priv;
1553 unsigned int plane; 1553 unsigned int plane;
1554 int ret; 1554 int ret;
1555 enum dma_data_direction dma_dir = 1555 enum dma_data_direction dma_dir =
1556 V4L2_TYPE_IS_OUTPUT(q->type) ? DMA_TO_DEVICE : DMA_FROM_DEVICE; 1556 q->is_output ? DMA_TO_DEVICE : DMA_FROM_DEVICE;
1557 bool reacquired = vb->planes[0].mem_priv == NULL; 1557 bool reacquired = vb->planes[0].mem_priv == NULL;
1558 1558
1559 memset(planes, 0, sizeof(planes[0]) * vb->num_planes); 1559 memset(planes, 0, sizeof(planes[0]) * vb->num_planes);
@@ -1700,7 +1700,7 @@ static int __buf_prepare(struct vb2_buffer *vb, const struct v4l2_buffer *b)
1700 dprintk(1, "plane parameters verification failed: %d\n", ret); 1700 dprintk(1, "plane parameters verification failed: %d\n", ret);
1701 return ret; 1701 return ret;
1702 } 1702 }
1703 if (b->field == V4L2_FIELD_ALTERNATE && V4L2_TYPE_IS_OUTPUT(q->type)) { 1703 if (b->field == V4L2_FIELD_ALTERNATE && q->is_output) {
1704 /* 1704 /*
1705 * If the format's field is ALTERNATE, then the buffer's field 1705 * If the format's field is ALTERNATE, then the buffer's field
1706 * should be either TOP or BOTTOM, not ALTERNATE since that 1706 * should be either TOP or BOTTOM, not ALTERNATE since that
@@ -1725,13 +1725,13 @@ static int __buf_prepare(struct vb2_buffer *vb, const struct v4l2_buffer *b)
1725 vbuf->sequence = 0; 1725 vbuf->sequence = 0;
1726 1726
1727 switch (q->memory) { 1727 switch (q->memory) {
1728 case V4L2_MEMORY_MMAP: 1728 case VB2_MEMORY_MMAP:
1729 ret = __qbuf_mmap(vb, b); 1729 ret = __qbuf_mmap(vb, b);
1730 break; 1730 break;
1731 case V4L2_MEMORY_USERPTR: 1731 case VB2_MEMORY_USERPTR:
1732 ret = __qbuf_userptr(vb, b); 1732 ret = __qbuf_userptr(vb, b);
1733 break; 1733 break;
1734 case V4L2_MEMORY_DMABUF: 1734 case VB2_MEMORY_DMABUF:
1735 ret = __qbuf_dmabuf(vb, b); 1735 ret = __qbuf_dmabuf(vb, b);
1736 break; 1736 break;
1737 default: 1737 default:
@@ -1919,7 +1919,7 @@ static int vb2_internal_qbuf(struct vb2_queue *q, struct v4l2_buffer *b)
1919 q->queued_count++; 1919 q->queued_count++;
1920 q->waiting_for_buffers = false; 1920 q->waiting_for_buffers = false;
1921 vb->state = VB2_BUF_STATE_QUEUED; 1921 vb->state = VB2_BUF_STATE_QUEUED;
1922 if (V4L2_TYPE_IS_OUTPUT(q->type)) { 1922 if (q->is_output) {
1923 /* 1923 /*
1924 * For output buffers copy the timestamp if needed, 1924 * For output buffers copy the timestamp if needed,
1925 * and the timecode field and flag if needed. 1925 * and the timecode field and flag if needed.
@@ -2138,7 +2138,7 @@ static void __vb2_dqbuf(struct vb2_buffer *vb)
2138 vb->state = VB2_BUF_STATE_DEQUEUED; 2138 vb->state = VB2_BUF_STATE_DEQUEUED;
2139 2139
2140 /* unmap DMABUF buffer */ 2140 /* unmap DMABUF buffer */
2141 if (q->memory == V4L2_MEMORY_DMABUF) 2141 if (q->memory == VB2_MEMORY_DMABUF)
2142 for (i = 0; i < vb->num_planes; ++i) { 2142 for (i = 0; i < vb->num_planes; ++i) {
2143 if (!vb->planes[i].dbuf_mapped) 2143 if (!vb->planes[i].dbuf_mapped)
2144 continue; 2144 continue;
@@ -2185,7 +2185,7 @@ static int vb2_internal_dqbuf(struct vb2_queue *q, struct v4l2_buffer *b,
2185 trace_vb2_dqbuf(q, vb); 2185 trace_vb2_dqbuf(q, vb);
2186 2186
2187 vbuf = to_vb2_v4l2_buffer(vb); 2187 vbuf = to_vb2_v4l2_buffer(vb);
2188 if (!V4L2_TYPE_IS_OUTPUT(q->type) && 2188 if (!q->is_output &&
2189 vbuf->flags & V4L2_BUF_FLAG_LAST) 2189 vbuf->flags & V4L2_BUF_FLAG_LAST)
2190 q->last_buffer_dequeued = true; 2190 q->last_buffer_dequeued = true;
2191 /* go back to dequeued state */ 2191 /* go back to dequeued state */
@@ -2400,7 +2400,7 @@ static int vb2_internal_streamoff(struct vb2_queue *q, enum v4l2_buf_type type)
2400 * their normal dequeued state. 2400 * their normal dequeued state.
2401 */ 2401 */
2402 __vb2_queue_cancel(q); 2402 __vb2_queue_cancel(q);
2403 q->waiting_for_buffers = !V4L2_TYPE_IS_OUTPUT(q->type); 2403 q->waiting_for_buffers = !q->is_output;
2404 q->last_buffer_dequeued = false; 2404 q->last_buffer_dequeued = false;
2405 2405
2406 dprintk(3, "successful\n"); 2406 dprintk(3, "successful\n");
@@ -2477,7 +2477,7 @@ int vb2_expbuf(struct vb2_queue *q, struct v4l2_exportbuffer *eb)
2477 int ret; 2477 int ret;
2478 struct dma_buf *dbuf; 2478 struct dma_buf *dbuf;
2479 2479
2480 if (q->memory != V4L2_MEMORY_MMAP) { 2480 if (q->memory != VB2_MEMORY_MMAP) {
2481 dprintk(1, "queue is not currently set up for mmap\n"); 2481 dprintk(1, "queue is not currently set up for mmap\n");
2482 return -EINVAL; 2482 return -EINVAL;
2483 } 2483 }
@@ -2566,7 +2566,7 @@ int vb2_mmap(struct vb2_queue *q, struct vm_area_struct *vma)
2566 int ret; 2566 int ret;
2567 unsigned long length; 2567 unsigned long length;
2568 2568
2569 if (q->memory != V4L2_MEMORY_MMAP) { 2569 if (q->memory != VB2_MEMORY_MMAP) {
2570 dprintk(1, "queue is not currently set up for mmap\n"); 2570 dprintk(1, "queue is not currently set up for mmap\n");
2571 return -EINVAL; 2571 return -EINVAL;
2572 } 2572 }
@@ -2578,7 +2578,7 @@ int vb2_mmap(struct vb2_queue *q, struct vm_area_struct *vma)
2578 dprintk(1, "invalid vma flags, VM_SHARED needed\n"); 2578 dprintk(1, "invalid vma flags, VM_SHARED needed\n");
2579 return -EINVAL; 2579 return -EINVAL;
2580 } 2580 }
2581 if (V4L2_TYPE_IS_OUTPUT(q->type)) { 2581 if (q->is_output) {
2582 if (!(vma->vm_flags & VM_WRITE)) { 2582 if (!(vma->vm_flags & VM_WRITE)) {
2583 dprintk(1, "invalid vma flags, VM_WRITE needed\n"); 2583 dprintk(1, "invalid vma flags, VM_WRITE needed\n");
2584 return -EINVAL; 2584 return -EINVAL;
@@ -2639,7 +2639,7 @@ unsigned long vb2_get_unmapped_area(struct vb2_queue *q,
2639 void *vaddr; 2639 void *vaddr;
2640 int ret; 2640 int ret;
2641 2641
2642 if (q->memory != V4L2_MEMORY_MMAP) { 2642 if (q->memory != VB2_MEMORY_MMAP) {
2643 dprintk(1, "queue is not currently set up for mmap\n"); 2643 dprintk(1, "queue is not currently set up for mmap\n");
2644 return -EINVAL; 2644 return -EINVAL;
2645 } 2645 }
@@ -2698,21 +2698,21 @@ unsigned int vb2_poll(struct vb2_queue *q, struct file *file, poll_table *wait)
2698 poll_wait(file, &fh->wait, wait); 2698 poll_wait(file, &fh->wait, wait);
2699 } 2699 }
2700 2700
2701 if (!V4L2_TYPE_IS_OUTPUT(q->type) && !(req_events & (POLLIN | POLLRDNORM))) 2701 if (!q->is_output && !(req_events & (POLLIN | POLLRDNORM)))
2702 return res; 2702 return res;
2703 if (V4L2_TYPE_IS_OUTPUT(q->type) && !(req_events & (POLLOUT | POLLWRNORM))) 2703 if (q->is_output && !(req_events & (POLLOUT | POLLWRNORM)))
2704 return res; 2704 return res;
2705 2705
2706 /* 2706 /*
2707 * Start file I/O emulator only if streaming API has not been used yet. 2707 * Start file I/O emulator only if streaming API has not been used yet.
2708 */ 2708 */
2709 if (q->num_buffers == 0 && !vb2_fileio_is_active(q)) { 2709 if (q->num_buffers == 0 && !vb2_fileio_is_active(q)) {
2710 if (!V4L2_TYPE_IS_OUTPUT(q->type) && (q->io_modes & VB2_READ) && 2710 if (!q->is_output && (q->io_modes & VB2_READ) &&
2711 (req_events & (POLLIN | POLLRDNORM))) { 2711 (req_events & (POLLIN | POLLRDNORM))) {
2712 if (__vb2_init_fileio(q, 1)) 2712 if (__vb2_init_fileio(q, 1))
2713 return res | POLLERR; 2713 return res | POLLERR;
2714 } 2714 }
2715 if (V4L2_TYPE_IS_OUTPUT(q->type) && (q->io_modes & VB2_WRITE) && 2715 if (q->is_output && (q->io_modes & VB2_WRITE) &&
2716 (req_events & (POLLOUT | POLLWRNORM))) { 2716 (req_events & (POLLOUT | POLLWRNORM))) {
2717 if (__vb2_init_fileio(q, 0)) 2717 if (__vb2_init_fileio(q, 0))
2718 return res | POLLERR; 2718 return res | POLLERR;
@@ -2741,7 +2741,7 @@ unsigned int vb2_poll(struct vb2_queue *q, struct file *file, poll_table *wait)
2741 * For output streams you can write as long as there are fewer buffers 2741 * For output streams you can write as long as there are fewer buffers
2742 * queued than there are buffers available. 2742 * queued than there are buffers available.
2743 */ 2743 */
2744 if (V4L2_TYPE_IS_OUTPUT(q->type) && q->queued_count < q->num_buffers) 2744 if (q->is_output && q->queued_count < q->num_buffers)
2745 return res | POLLOUT | POLLWRNORM; 2745 return res | POLLOUT | POLLWRNORM;
2746 2746
2747 if (list_empty(&q->done_list)) { 2747 if (list_empty(&q->done_list)) {
@@ -2766,7 +2766,7 @@ unsigned int vb2_poll(struct vb2_queue *q, struct file *file, poll_table *wait)
2766 2766
2767 if (vb && (vb->state == VB2_BUF_STATE_DONE 2767 if (vb && (vb->state == VB2_BUF_STATE_DONE
2768 || vb->state == VB2_BUF_STATE_ERROR)) { 2768 || vb->state == VB2_BUF_STATE_ERROR)) {
2769 return (V4L2_TYPE_IS_OUTPUT(q->type)) ? 2769 return (q->is_output) ?
2770 res | POLLOUT | POLLWRNORM : 2770 res | POLLOUT | POLLWRNORM :
2771 res | POLLIN | POLLRDNORM; 2771 res | POLLIN | POLLRDNORM;
2772 } 2772 }
@@ -2806,6 +2806,12 @@ int vb2_queue_init(struct vb2_queue *q)
2806 WARN_ON((q->timestamp_flags & V4L2_BUF_FLAG_TIMESTAMP_MASK) == 2806 WARN_ON((q->timestamp_flags & V4L2_BUF_FLAG_TIMESTAMP_MASK) ==
2807 V4L2_BUF_FLAG_TIMESTAMP_UNKNOWN); 2807 V4L2_BUF_FLAG_TIMESTAMP_UNKNOWN);
2808 2808
2809 /* Warn that vb2_memory should match with v4l2_memory */
2810 if (WARN_ON(VB2_MEMORY_MMAP != (int)V4L2_MEMORY_MMAP)
2811 || WARN_ON(VB2_MEMORY_USERPTR != (int)V4L2_MEMORY_USERPTR)
2812 || WARN_ON(VB2_MEMORY_DMABUF != (int)V4L2_MEMORY_DMABUF))
2813 return -EINVAL;
2814
2809 INIT_LIST_HEAD(&q->queued_list); 2815 INIT_LIST_HEAD(&q->queued_list);
2810 INIT_LIST_HEAD(&q->done_list); 2816 INIT_LIST_HEAD(&q->done_list);
2811 spin_lock_init(&q->done_lock); 2817 spin_lock_init(&q->done_lock);
@@ -2815,6 +2821,9 @@ int vb2_queue_init(struct vb2_queue *q)
2815 if (q->buf_struct_size == 0) 2821 if (q->buf_struct_size == 0)
2816 q->buf_struct_size = sizeof(struct vb2_v4l2_buffer); 2822 q->buf_struct_size = sizeof(struct vb2_v4l2_buffer);
2817 2823
2824 q->is_multiplanar = V4L2_TYPE_IS_MULTIPLANAR(q->type);
2825 q->is_output = V4L2_TYPE_IS_OUTPUT(q->type);
2826
2818 return 0; 2827 return 0;
2819} 2828}
2820EXPORT_SYMBOL_GPL(vb2_queue_init); 2829EXPORT_SYMBOL_GPL(vb2_queue_init);
@@ -2879,7 +2888,7 @@ struct vb2_fileio_data {
2879 struct v4l2_requestbuffers req; 2888 struct v4l2_requestbuffers req;
2880 struct v4l2_plane p; 2889 struct v4l2_plane p;
2881 struct v4l2_buffer b; 2890 struct v4l2_buffer b;
2882 struct vb2_fileio_buf bufs[VIDEO_MAX_FRAME]; 2891 struct vb2_fileio_buf bufs[VB2_MAX_FRAME];
2883 unsigned int cur_index; 2892 unsigned int cur_index;
2884 unsigned int initial_index; 2893 unsigned int initial_index;
2885 unsigned int q_count; 2894 unsigned int q_count;
@@ -2939,7 +2948,7 @@ static int __vb2_init_fileio(struct vb2_queue *q, int read)
2939 * to allocate buffers by itself. 2948 * to allocate buffers by itself.
2940 */ 2949 */
2941 fileio->req.count = count; 2950 fileio->req.count = count;
2942 fileio->req.memory = V4L2_MEMORY_MMAP; 2951 fileio->req.memory = VB2_MEMORY_MMAP;
2943 fileio->req.type = q->type; 2952 fileio->req.type = q->type;
2944 q->fileio = fileio; 2953 q->fileio = fileio;
2945 ret = __reqbufs(q, &fileio->req); 2954 ret = __reqbufs(q, &fileio->req);
@@ -2971,7 +2980,7 @@ static int __vb2_init_fileio(struct vb2_queue *q, int read)
2971 * Read mode requires pre queuing of all buffers. 2980 * Read mode requires pre queuing of all buffers.
2972 */ 2981 */
2973 if (read) { 2982 if (read) {
2974 bool is_multiplanar = V4L2_TYPE_IS_MULTIPLANAR(q->type); 2983 bool is_multiplanar = q->is_multiplanar;
2975 2984
2976 /* 2985 /*
2977 * Queue all buffers. 2986 * Queue all buffers.
@@ -3053,7 +3062,7 @@ static size_t __vb2_perform_fileio(struct vb2_queue *q, char __user *data, size_
3053{ 3062{
3054 struct vb2_fileio_data *fileio; 3063 struct vb2_fileio_data *fileio;
3055 struct vb2_fileio_buf *buf; 3064 struct vb2_fileio_buf *buf;
3056 bool is_multiplanar = V4L2_TYPE_IS_MULTIPLANAR(q->type); 3065 bool is_multiplanar = q->is_multiplanar;
3057 /* 3066 /*
3058 * When using write() to write data to an output video node the vb2 core 3067 * When using write() to write data to an output video node the vb2 core
3059 * should set timestamps if V4L2_BUF_FLAG_TIMESTAMP_COPY is set. Nobody 3068 * should set timestamps if V4L2_BUF_FLAG_TIMESTAMP_COPY is set. Nobody
@@ -3248,7 +3257,7 @@ static int vb2_thread(void *data)
3248 int index = 0; 3257 int index = 0;
3249 int ret = 0; 3258 int ret = 0;
3250 3259
3251 if (V4L2_TYPE_IS_OUTPUT(q->type)) { 3260 if (q->is_output) {
3252 prequeue = q->num_buffers; 3261 prequeue = q->num_buffers;
3253 set_timestamp = 3262 set_timestamp =
3254 (q->timestamp_flags & V4L2_BUF_FLAG_TIMESTAMP_MASK) == 3263 (q->timestamp_flags & V4L2_BUF_FLAG_TIMESTAMP_MASK) ==
@@ -3326,7 +3335,7 @@ int vb2_thread_start(struct vb2_queue *q, vb2_thread_fnc fnc, void *priv,
3326 threadio->fnc = fnc; 3335 threadio->fnc = fnc;
3327 threadio->priv = priv; 3336 threadio->priv = priv;
3328 3337
3329 ret = __vb2_init_fileio(q, !V4L2_TYPE_IS_OUTPUT(q->type)); 3338 ret = __vb2_init_fileio(q, !q->is_output);
3330 dprintk(3, "file io: vb2_init_fileio result: %d\n", ret); 3339 dprintk(3, "file io: vb2_init_fileio result: %d\n", ret);
3331 if (ret) 3340 if (ret)
3332 goto nomem; 3341 goto nomem;
diff --git a/include/media/videobuf2-core.h b/include/media/videobuf2-core.h
index dce6463d035e..244ea2e36a8a 100644
--- a/include/media/videobuf2-core.h
+++ b/include/media/videobuf2-core.h
@@ -18,6 +18,16 @@
18#include <linux/videodev2.h> 18#include <linux/videodev2.h>
19#include <linux/dma-buf.h> 19#include <linux/dma-buf.h>
20 20
21#define VB2_MAX_FRAME (32)
22#define VB2_MAX_PLANES (8)
23
24enum vb2_memory {
25 VB2_MEMORY_UNKNOWN = 0,
26 VB2_MEMORY_MMAP = 1,
27 VB2_MEMORY_USERPTR = 2,
28 VB2_MEMORY_DMABUF = 4,
29};
30
21struct vb2_alloc_ctx; 31struct vb2_alloc_ctx;
22struct vb2_fileio_data; 32struct vb2_fileio_data;
23struct vb2_threadio_data; 33struct vb2_threadio_data;
@@ -209,7 +219,7 @@ struct vb2_buffer {
209 unsigned int type; 219 unsigned int type;
210 unsigned int memory; 220 unsigned int memory;
211 unsigned int num_planes; 221 unsigned int num_planes;
212 struct vb2_plane planes[VIDEO_MAX_PLANES]; 222 struct vb2_plane planes[VB2_MAX_PLANES];
213 223
214 /* private: internal use only 224 /* private: internal use only
215 * 225 *
@@ -353,12 +363,13 @@ struct vb2_ops {
353 void (*buf_queue)(struct vb2_buffer *vb); 363 void (*buf_queue)(struct vb2_buffer *vb);
354}; 364};
355 365
356struct v4l2_fh;
357 366
358/** 367/**
359 * struct vb2_queue - a videobuf queue 368 * struct vb2_queue - a videobuf queue
360 * 369 *
361 * @type: queue type (see V4L2_BUF_TYPE_* in linux/videodev2.h 370 * @type: private buffer type whose content is defined by the vb2-core
371 * caller. For example, for V4L2, it should match
372 * the V4L2_BUF_TYPE_* in include/uapi/linux/videodev2.h
362 * @io_modes: supported io methods (see vb2_io_modes enum) 373 * @io_modes: supported io methods (see vb2_io_modes enum)
363 * @fileio_read_once: report EOF after reading the first buffer 374 * @fileio_read_once: report EOF after reading the first buffer
364 * @fileio_write_immediately: queue buffer after each write() call 375 * @fileio_write_immediately: queue buffer after each write() call
@@ -409,6 +420,8 @@ struct v4l2_fh;
409 * @waiting_for_buffers: used in poll() to check if vb2 is still waiting for 420 * @waiting_for_buffers: used in poll() to check if vb2 is still waiting for
410 * buffers. Only set for capture queues if qbuf has not yet been 421 * buffers. Only set for capture queues if qbuf has not yet been
411 * called since poll() needs to return POLLERR in that situation. 422 * called since poll() needs to return POLLERR in that situation.
423 * @is_multiplanar: set if buffer type is multiplanar
424 * @is_output: set if buffer type is output
412 * @last_buffer_dequeued: used in poll() and DQBUF to immediately return if the 425 * @last_buffer_dequeued: used in poll() and DQBUF to immediately return if the
413 * last decoded buffer was already dequeued. Set for capture queues 426 * last decoded buffer was already dequeued. Set for capture queues
414 * when a buffer with the V4L2_BUF_FLAG_LAST is dequeued. 427 * when a buffer with the V4L2_BUF_FLAG_LAST is dequeued.
@@ -416,14 +429,14 @@ struct v4l2_fh;
416 * @threadio: thread io internal data, used only if thread is active 429 * @threadio: thread io internal data, used only if thread is active
417 */ 430 */
418struct vb2_queue { 431struct vb2_queue {
419 enum v4l2_buf_type type; 432 unsigned int type;
420 unsigned int io_modes; 433 unsigned int io_modes;
421 unsigned fileio_read_once:1; 434 unsigned fileio_read_once:1;
422 unsigned fileio_write_immediately:1; 435 unsigned fileio_write_immediately:1;
423 unsigned allow_zero_bytesused:1; 436 unsigned allow_zero_bytesused:1;
424 437
425 struct mutex *lock; 438 struct mutex *lock;
426 struct v4l2_fh *owner; 439 void *owner;
427 440
428 const struct vb2_ops *ops; 441 const struct vb2_ops *ops;
429 const struct vb2_mem_ops *mem_ops; 442 const struct vb2_mem_ops *mem_ops;
@@ -435,8 +448,8 @@ struct vb2_queue {
435 448
436 /* private: internal use only */ 449 /* private: internal use only */
437 struct mutex mmap_lock; 450 struct mutex mmap_lock;
438 enum v4l2_memory memory; 451 unsigned int memory;
439 struct vb2_buffer *bufs[VIDEO_MAX_FRAME]; 452 struct vb2_buffer *bufs[VB2_MAX_FRAME];
440 unsigned int num_buffers; 453 unsigned int num_buffers;
441 454
442 struct list_head queued_list; 455 struct list_head queued_list;
@@ -447,13 +460,15 @@ struct vb2_queue {
447 spinlock_t done_lock; 460 spinlock_t done_lock;
448 wait_queue_head_t done_wq; 461 wait_queue_head_t done_wq;
449 462
450 void *alloc_ctx[VIDEO_MAX_PLANES]; 463 void *alloc_ctx[VB2_MAX_PLANES];
451 unsigned int plane_sizes[VIDEO_MAX_PLANES]; 464 unsigned int plane_sizes[VB2_MAX_PLANES];
452 465
453 unsigned int streaming:1; 466 unsigned int streaming:1;
454 unsigned int start_streaming_called:1; 467 unsigned int start_streaming_called:1;
455 unsigned int error:1; 468 unsigned int error:1;
456 unsigned int waiting_for_buffers:1; 469 unsigned int waiting_for_buffers:1;
470 unsigned int is_multiplanar:1;
471 unsigned int is_output:1;
457 unsigned int last_buffer_dequeued:1; 472 unsigned int last_buffer_dequeued:1;
458 473
459 struct vb2_fileio_data *fileio; 474 struct vb2_fileio_data *fileio;
diff --git a/include/media/videobuf2-v4l2.h b/include/media/videobuf2-v4l2.h
index 71f7fe2706b3..9d10e3ae1e3d 100644
--- a/include/media/videobuf2-v4l2.h
+++ b/include/media/videobuf2-v4l2.h
@@ -15,6 +15,14 @@
15#include <linux/videodev2.h> 15#include <linux/videodev2.h>
16#include <media/videobuf2-core.h> 16#include <media/videobuf2-core.h>
17 17
18#if VB2_MAX_FRAME != VIDEO_MAX_FRAME
19#error VB2_MAX_FRAME != VIDEO_MAX_FRAME
20#endif
21
22#if VB2_MAX_PLANES != VIDEO_MAX_PLANES
23#error VB2_MAX_PLANES != VIDEO_MAX_PLANES
24#endif
25
18/** 26/**
19 * struct vb2_v4l2_buffer - video buffer information for v4l2 27 * struct vb2_v4l2_buffer - video buffer information for v4l2
20 * @vb2_buf: video buffer 2 28 * @vb2_buf: video buffer 2
diff --git a/include/trace/events/v4l2.h b/include/trace/events/v4l2.h
index b015b38a4dda..375b1a3138c2 100644
--- a/include/trace/events/v4l2.h
+++ b/include/trace/events/v4l2.h
@@ -5,6 +5,7 @@
5#define _TRACE_V4L2_H 5#define _TRACE_V4L2_H
6 6
7#include <linux/tracepoint.h> 7#include <linux/tracepoint.h>
8#include <media/videobuf2-v4l2.h>
8 9
9/* Enums require being exported to userspace, for user tool parsing */ 10/* Enums require being exported to userspace, for user tool parsing */
10#undef EM 11#undef EM
@@ -203,7 +204,9 @@ DECLARE_EVENT_CLASS(vb2_event_class,
203 204
204 TP_fast_assign( 205 TP_fast_assign(
205 struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb); 206 struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
206 __entry->minor = q->owner ? q->owner->vdev->minor : -1; 207 struct v4l2_fh *owner = q->owner;
208
209 __entry->minor = owner ? owner->vdev->minor : -1;
207 __entry->queued_count = q->queued_count; 210 __entry->queued_count = q->queued_count;
208 __entry->owned_by_drv_count = 211 __entry->owned_by_drv_count =
209 atomic_read(&q->owned_by_drv_count); 212 atomic_read(&q->owned_by_drv_count);