diff options
author | Hans Verkuil <hans.verkuil@cisco.com> | 2012-06-27 16:10:30 -0400 |
---|---|---|
committer | Mauro Carvalho Chehab <mchehab@redhat.com> | 2012-07-06 16:28:48 -0400 |
commit | 37d9ed94b97efdacf1cbff91216920d1a620b8cd (patch) | |
tree | 18ebf49d54e1a3ed2dce69d5c1f7e94a1655fd8e | |
parent | dcaded7e5f7c66facfd0ced5b368e757cbf576ed (diff) |
[media] vb2-core: refactor reqbufs/create_bufs
Split off the memory and type validation. This is done both from reqbufs
and create_bufs, and will also be done by vb2 helpers in a later patch.
Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
-rw-r--r-- | drivers/media/video/videobuf2-core.c | 145 |
1 files changed, 77 insertions, 68 deletions
diff --git a/drivers/media/video/videobuf2-core.c b/drivers/media/video/videobuf2-core.c index ec24718b3ed0..60e7bc78d190 100644 --- a/drivers/media/video/videobuf2-core.c +++ b/drivers/media/video/videobuf2-core.c | |||
@@ -454,7 +454,50 @@ static int __verify_mmap_ops(struct vb2_queue *q) | |||
454 | } | 454 | } |
455 | 455 | ||
456 | /** | 456 | /** |
457 | * vb2_reqbufs() - Initiate streaming | 457 | * __verify_memory_type() - Check whether the memory type and buffer type |
458 | * passed to a buffer operation are compatible with the queue. | ||
459 | */ | ||
460 | static int __verify_memory_type(struct vb2_queue *q, | ||
461 | enum v4l2_memory memory, enum v4l2_buf_type type) | ||
462 | { | ||
463 | if (memory != V4L2_MEMORY_MMAP && memory != V4L2_MEMORY_USERPTR) { | ||
464 | dprintk(1, "reqbufs: unsupported memory type\n"); | ||
465 | return -EINVAL; | ||
466 | } | ||
467 | |||
468 | if (type != q->type) { | ||
469 | dprintk(1, "reqbufs: requested type is incorrect\n"); | ||
470 | return -EINVAL; | ||
471 | } | ||
472 | |||
473 | /* | ||
474 | * Make sure all the required memory ops for given memory type | ||
475 | * are available. | ||
476 | */ | ||
477 | if (memory == V4L2_MEMORY_MMAP && __verify_mmap_ops(q)) { | ||
478 | dprintk(1, "reqbufs: MMAP for current setup unsupported\n"); | ||
479 | return -EINVAL; | ||
480 | } | ||
481 | |||
482 | if (memory == V4L2_MEMORY_USERPTR && __verify_userptr_ops(q)) { | ||
483 | dprintk(1, "reqbufs: USERPTR for current setup unsupported\n"); | ||
484 | return -EINVAL; | ||
485 | } | ||
486 | |||
487 | /* | ||
488 | * Place the busy tests at the end: -EBUSY can be ignored when | ||
489 | * create_bufs is called with count == 0, but count == 0 should still | ||
490 | * do the memory and type validation. | ||
491 | */ | ||
492 | if (q->fileio) { | ||
493 | dprintk(1, "reqbufs: file io in progress\n"); | ||
494 | return -EBUSY; | ||
495 | } | ||
496 | return 0; | ||
497 | } | ||
498 | |||
499 | /** | ||
500 | * __reqbufs() - Initiate streaming | ||
458 | * @q: videobuf2 queue | 501 | * @q: videobuf2 queue |
459 | * @req: struct passed from userspace to vidioc_reqbufs handler in driver | 502 | * @req: struct passed from userspace to vidioc_reqbufs handler in driver |
460 | * | 503 | * |
@@ -476,46 +519,16 @@ static int __verify_mmap_ops(struct vb2_queue *q) | |||
476 | * The return values from this function are intended to be directly returned | 519 | * The return values from this function are intended to be directly returned |
477 | * from vidioc_reqbufs handler in driver. | 520 | * from vidioc_reqbufs handler in driver. |
478 | */ | 521 | */ |
479 | int vb2_reqbufs(struct vb2_queue *q, struct v4l2_requestbuffers *req) | 522 | static int __reqbufs(struct vb2_queue *q, struct v4l2_requestbuffers *req) |
480 | { | 523 | { |
481 | unsigned int num_buffers, allocated_buffers, num_planes = 0; | 524 | unsigned int num_buffers, allocated_buffers, num_planes = 0; |
482 | int ret = 0; | 525 | int ret; |
483 | |||
484 | if (q->fileio) { | ||
485 | dprintk(1, "reqbufs: file io in progress\n"); | ||
486 | return -EBUSY; | ||
487 | } | ||
488 | |||
489 | if (req->memory != V4L2_MEMORY_MMAP | ||
490 | && req->memory != V4L2_MEMORY_USERPTR) { | ||
491 | dprintk(1, "reqbufs: unsupported memory type\n"); | ||
492 | return -EINVAL; | ||
493 | } | ||
494 | |||
495 | if (req->type != q->type) { | ||
496 | dprintk(1, "reqbufs: requested type is incorrect\n"); | ||
497 | return -EINVAL; | ||
498 | } | ||
499 | 526 | ||
500 | if (q->streaming) { | 527 | if (q->streaming) { |
501 | dprintk(1, "reqbufs: streaming active\n"); | 528 | dprintk(1, "reqbufs: streaming active\n"); |
502 | return -EBUSY; | 529 | return -EBUSY; |
503 | } | 530 | } |
504 | 531 | ||
505 | /* | ||
506 | * Make sure all the required memory ops for given memory type | ||
507 | * are available. | ||
508 | */ | ||
509 | if (req->memory == V4L2_MEMORY_MMAP && __verify_mmap_ops(q)) { | ||
510 | dprintk(1, "reqbufs: MMAP for current setup unsupported\n"); | ||
511 | return -EINVAL; | ||
512 | } | ||
513 | |||
514 | if (req->memory == V4L2_MEMORY_USERPTR && __verify_userptr_ops(q)) { | ||
515 | dprintk(1, "reqbufs: USERPTR for current setup unsupported\n"); | ||
516 | return -EINVAL; | ||
517 | } | ||
518 | |||
519 | if (req->count == 0 || q->num_buffers != 0 || q->memory != req->memory) { | 532 | if (req->count == 0 || q->num_buffers != 0 || q->memory != req->memory) { |
520 | /* | 533 | /* |
521 | * We already have buffers allocated, so first check if they | 534 | * We already have buffers allocated, so first check if they |
@@ -595,10 +608,23 @@ int vb2_reqbufs(struct vb2_queue *q, struct v4l2_requestbuffers *req) | |||
595 | 608 | ||
596 | return 0; | 609 | return 0; |
597 | } | 610 | } |
611 | |||
612 | /** | ||
613 | * vb2_reqbufs() - Wrapper for __reqbufs() that also verifies the memory and | ||
614 | * type values. | ||
615 | * @q: videobuf2 queue | ||
616 | * @req: struct passed from userspace to vidioc_reqbufs handler in driver | ||
617 | */ | ||
618 | int vb2_reqbufs(struct vb2_queue *q, struct v4l2_requestbuffers *req) | ||
619 | { | ||
620 | int ret = __verify_memory_type(q, req->memory, req->type); | ||
621 | |||
622 | return ret ? ret : __reqbufs(q, req); | ||
623 | } | ||
598 | EXPORT_SYMBOL_GPL(vb2_reqbufs); | 624 | EXPORT_SYMBOL_GPL(vb2_reqbufs); |
599 | 625 | ||
600 | /** | 626 | /** |
601 | * vb2_create_bufs() - Allocate buffers and any required auxiliary structs | 627 | * __create_bufs() - Allocate buffers and any required auxiliary structs |
602 | * @q: videobuf2 queue | 628 | * @q: videobuf2 queue |
603 | * @create: creation parameters, passed from userspace to vidioc_create_bufs | 629 | * @create: creation parameters, passed from userspace to vidioc_create_bufs |
604 | * handler in driver | 630 | * handler in driver |
@@ -612,40 +638,10 @@ EXPORT_SYMBOL_GPL(vb2_reqbufs); | |||
612 | * The return values from this function are intended to be directly returned | 638 | * The return values from this function are intended to be directly returned |
613 | * from vidioc_create_bufs handler in driver. | 639 | * from vidioc_create_bufs handler in driver. |
614 | */ | 640 | */ |
615 | int vb2_create_bufs(struct vb2_queue *q, struct v4l2_create_buffers *create) | 641 | static int __create_bufs(struct vb2_queue *q, struct v4l2_create_buffers *create) |
616 | { | 642 | { |
617 | unsigned int num_planes = 0, num_buffers, allocated_buffers; | 643 | unsigned int num_planes = 0, num_buffers, allocated_buffers; |
618 | int ret = 0; | 644 | int ret; |
619 | |||
620 | if (q->fileio) { | ||
621 | dprintk(1, "%s(): file io in progress\n", __func__); | ||
622 | return -EBUSY; | ||
623 | } | ||
624 | |||
625 | if (create->memory != V4L2_MEMORY_MMAP | ||
626 | && create->memory != V4L2_MEMORY_USERPTR) { | ||
627 | dprintk(1, "%s(): unsupported memory type\n", __func__); | ||
628 | return -EINVAL; | ||
629 | } | ||
630 | |||
631 | if (create->format.type != q->type) { | ||
632 | dprintk(1, "%s(): requested type is incorrect\n", __func__); | ||
633 | return -EINVAL; | ||
634 | } | ||
635 | |||
636 | /* | ||
637 | * Make sure all the required memory ops for given memory type | ||
638 | * are available. | ||
639 | */ | ||
640 | if (create->memory == V4L2_MEMORY_MMAP && __verify_mmap_ops(q)) { | ||
641 | dprintk(1, "%s(): MMAP for current setup unsupported\n", __func__); | ||
642 | return -EINVAL; | ||
643 | } | ||
644 | |||
645 | if (create->memory == V4L2_MEMORY_USERPTR && __verify_userptr_ops(q)) { | ||
646 | dprintk(1, "%s(): USERPTR for current setup unsupported\n", __func__); | ||
647 | return -EINVAL; | ||
648 | } | ||
649 | 645 | ||
650 | if (q->num_buffers == VIDEO_MAX_FRAME) { | 646 | if (q->num_buffers == VIDEO_MAX_FRAME) { |
651 | dprintk(1, "%s(): maximum number of buffers already allocated\n", | 647 | dprintk(1, "%s(): maximum number of buffers already allocated\n", |
@@ -653,8 +649,6 @@ int vb2_create_bufs(struct vb2_queue *q, struct v4l2_create_buffers *create) | |||
653 | return -ENOBUFS; | 649 | return -ENOBUFS; |
654 | } | 650 | } |
655 | 651 | ||
656 | create->index = q->num_buffers; | ||
657 | |||
658 | if (!q->num_buffers) { | 652 | if (!q->num_buffers) { |
659 | memset(q->plane_sizes, 0, sizeof(q->plane_sizes)); | 653 | memset(q->plane_sizes, 0, sizeof(q->plane_sizes)); |
660 | memset(q->alloc_ctx, 0, sizeof(q->alloc_ctx)); | 654 | memset(q->alloc_ctx, 0, sizeof(q->alloc_ctx)); |
@@ -719,6 +713,21 @@ int vb2_create_bufs(struct vb2_queue *q, struct v4l2_create_buffers *create) | |||
719 | 713 | ||
720 | return 0; | 714 | return 0; |
721 | } | 715 | } |
716 | |||
717 | /** | ||
718 | * vb2_reqbufs() - Wrapper for __reqbufs() that also verifies the memory and | ||
719 | * type values. | ||
720 | * @q: videobuf2 queue | ||
721 | * @create: creation parameters, passed from userspace to vidioc_create_bufs | ||
722 | * handler in driver | ||
723 | */ | ||
724 | int vb2_create_bufs(struct vb2_queue *q, struct v4l2_create_buffers *create) | ||
725 | { | ||
726 | int ret = __verify_memory_type(q, create->memory, create->format.type); | ||
727 | |||
728 | create->index = q->num_buffers; | ||
729 | return ret ? ret : __create_bufs(q, create); | ||
730 | } | ||
722 | EXPORT_SYMBOL_GPL(vb2_create_bufs); | 731 | EXPORT_SYMBOL_GPL(vb2_create_bufs); |
723 | 732 | ||
724 | /** | 733 | /** |