Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

[media] mem2mem_testdev: Use mem-to-mem ioctl and vb2 helpers

Simplify the driver by using the m2m ioctl and vb2 helpers.

Signed-off-by: Sylwester Nawrocki <s.nawrocki@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
Acked-by: Hans Verkuil <hans.verkuil@cisco.com>
Acked-by: Kamil Debski <k.debski@samsung.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>

authored by

Sylwester Nawrocki and committed by
Mauro Carvalho Chehab
20702ebc 8e6e8f93

+28 -124
+28 -124
drivers/media/platform/mem2mem_testdev.c
··· 177 177 178 178 enum v4l2_colorspace colorspace; 179 179 180 - struct v4l2_m2m_ctx *m2m_ctx; 181 - 182 180 /* Source and destination queue data */ 183 181 struct m2mtest_q_data q_data[2]; 184 182 }; ··· 340 342 { 341 343 struct m2mtest_ctx *ctx = priv; 342 344 343 - if (v4l2_m2m_num_src_bufs_ready(ctx->m2m_ctx) < ctx->translen 344 - || v4l2_m2m_num_dst_bufs_ready(ctx->m2m_ctx) < ctx->translen) { 345 + if (v4l2_m2m_num_src_bufs_ready(ctx->fh.m2m_ctx) < ctx->translen 346 + || v4l2_m2m_num_dst_bufs_ready(ctx->fh.m2m_ctx) < ctx->translen) { 345 347 dprintk(ctx->dev, "Not enough buffers available\n"); 346 348 return 0; 347 349 } ··· 357 359 ctx->aborting = 1; 358 360 } 359 361 360 - static void m2mtest_lock(void *priv) 361 - { 362 - struct m2mtest_ctx *ctx = priv; 363 - struct m2mtest_dev *dev = ctx->dev; 364 - mutex_lock(&dev->dev_mutex); 365 - } 366 - 367 - static void m2mtest_unlock(void *priv) 368 - { 369 - struct m2mtest_ctx *ctx = priv; 370 - struct m2mtest_dev *dev = ctx->dev; 371 - mutex_unlock(&dev->dev_mutex); 372 - } 373 - 374 - 375 362 /* device_run() - prepares and starts the device 376 363 * 377 364 * This simulates all the immediate preparations required before starting ··· 369 386 struct m2mtest_dev *dev = ctx->dev; 370 387 struct vb2_buffer *src_buf, *dst_buf; 371 388 372 - src_buf = v4l2_m2m_next_src_buf(ctx->m2m_ctx); 373 - dst_buf = v4l2_m2m_next_dst_buf(ctx->m2m_ctx); 389 + src_buf = v4l2_m2m_next_src_buf(ctx->fh.m2m_ctx); 390 + dst_buf = v4l2_m2m_next_dst_buf(ctx->fh.m2m_ctx); 374 391 375 392 device_process(ctx, src_buf, dst_buf); 376 393 ··· 392 409 return; 393 410 } 394 411 395 - src_vb = v4l2_m2m_src_buf_remove(curr_ctx->m2m_ctx); 396 - dst_vb = v4l2_m2m_dst_buf_remove(curr_ctx->m2m_ctx); 412 + src_vb = v4l2_m2m_src_buf_remove(curr_ctx->fh.m2m_ctx); 413 + dst_vb = v4l2_m2m_dst_buf_remove(curr_ctx->fh.m2m_ctx); 397 414 398 415 curr_ctx->num_processed++; 399 416 ··· 406 423 || curr_ctx->aborting) { 407 424 dprintk(curr_ctx->dev, "Finishing transaction\n"); 408 425 curr_ctx->num_processed = 0; 409 - v4l2_m2m_job_finish(m2mtest_dev->m2m_dev, curr_ctx->m2m_ctx); 426 + v4l2_m2m_job_finish(m2mtest_dev->m2m_dev, curr_ctx->fh.m2m_ctx); 410 427 } else { 411 428 device_run(curr_ctx); 412 429 } ··· 474 491 struct vb2_queue *vq; 475 492 struct m2mtest_q_data *q_data; 476 493 477 - vq = v4l2_m2m_get_vq(ctx->m2m_ctx, f->type); 494 + vq = v4l2_m2m_get_vq(ctx->fh.m2m_ctx, f->type); 478 495 if (!vq) 479 496 return -EINVAL; 480 497 ··· 577 594 struct m2mtest_q_data *q_data; 578 595 struct vb2_queue *vq; 579 596 580 - vq = v4l2_m2m_get_vq(ctx->m2m_ctx, f->type); 597 + vq = v4l2_m2m_get_vq(ctx->fh.m2m_ctx, f->type); 581 598 if (!vq) 582 599 return -EINVAL; 583 600 ··· 629 646 if (!ret) 630 647 ctx->colorspace = f->fmt.pix.colorspace; 631 648 return ret; 632 - } 633 - 634 - static int vidioc_reqbufs(struct file *file, void *priv, 635 - struct v4l2_requestbuffers *reqbufs) 636 - { 637 - struct m2mtest_ctx *ctx = file2ctx(file); 638 - 639 - return v4l2_m2m_reqbufs(file, ctx->m2m_ctx, reqbufs); 640 - } 641 - 642 - static int vidioc_querybuf(struct file *file, void *priv, 643 - struct v4l2_buffer *buf) 644 - { 645 - struct m2mtest_ctx *ctx = file2ctx(file); 646 - 647 - return v4l2_m2m_querybuf(file, ctx->m2m_ctx, buf); 648 - } 649 - 650 - static int vidioc_qbuf(struct file *file, void *priv, struct v4l2_buffer *buf) 651 - { 652 - struct m2mtest_ctx *ctx = file2ctx(file); 653 - 654 - return v4l2_m2m_qbuf(file, ctx->m2m_ctx, buf); 655 - } 656 - 657 - static int vidioc_dqbuf(struct file *file, void *priv, struct v4l2_buffer *buf) 658 - { 659 - struct m2mtest_ctx *ctx = file2ctx(file); 660 - 661 - return v4l2_m2m_dqbuf(file, ctx->m2m_ctx, buf); 662 - } 663 - 664 - static int vidioc_streamon(struct file *file, void *priv, 665 - enum v4l2_buf_type type) 666 - { 667 - struct m2mtest_ctx *ctx = file2ctx(file); 668 - 669 - return v4l2_m2m_streamon(file, ctx->m2m_ctx, type); 670 - } 671 - 672 - static int vidioc_streamoff(struct file *file, void *priv, 673 - enum v4l2_buf_type type) 674 - { 675 - struct m2mtest_ctx *ctx = file2ctx(file); 676 - 677 - return v4l2_m2m_streamoff(file, ctx->m2m_ctx, type); 678 649 } 679 650 680 651 static int m2mtest_s_ctrl(struct v4l2_ctrl *ctrl) ··· 685 748 .vidioc_try_fmt_vid_out = vidioc_try_fmt_vid_out, 686 749 .vidioc_s_fmt_vid_out = vidioc_s_fmt_vid_out, 687 750 688 - .vidioc_reqbufs = vidioc_reqbufs, 689 - .vidioc_querybuf = vidioc_querybuf, 751 + .vidioc_reqbufs = v4l2_m2m_ioctl_reqbufs, 752 + .vidioc_querybuf = v4l2_m2m_ioctl_querybuf, 753 + .vidioc_qbuf = v4l2_m2m_ioctl_qbuf, 754 + .vidioc_dqbuf = v4l2_m2m_ioctl_dqbuf, 690 755 691 - .vidioc_qbuf = vidioc_qbuf, 692 - .vidioc_dqbuf = vidioc_dqbuf, 756 + .vidioc_streamon = v4l2_m2m_ioctl_streamon, 757 + .vidioc_streamoff = v4l2_m2m_ioctl_streamoff, 693 758 694 - .vidioc_streamon = vidioc_streamon, 695 - .vidioc_streamoff = vidioc_streamoff, 696 759 .vidioc_subscribe_event = v4l2_ctrl_subscribe_event, 697 760 .vidioc_unsubscribe_event = v4l2_event_unsubscribe, 698 761 }; ··· 755 818 static void m2mtest_buf_queue(struct vb2_buffer *vb) 756 819 { 757 820 struct m2mtest_ctx *ctx = vb2_get_drv_priv(vb->vb2_queue); 758 - v4l2_m2m_buf_queue(ctx->m2m_ctx, vb); 759 - } 760 - 761 - static void m2mtest_wait_prepare(struct vb2_queue *q) 762 - { 763 - struct m2mtest_ctx *ctx = vb2_get_drv_priv(q); 764 - m2mtest_unlock(ctx); 765 - } 766 - 767 - static void m2mtest_wait_finish(struct vb2_queue *q) 768 - { 769 - struct m2mtest_ctx *ctx = vb2_get_drv_priv(q); 770 - m2mtest_lock(ctx); 821 + v4l2_m2m_buf_queue(ctx->fh.m2m_ctx, vb); 771 822 } 772 823 773 824 static struct vb2_ops m2mtest_qops = { 774 825 .queue_setup = m2mtest_queue_setup, 775 826 .buf_prepare = m2mtest_buf_prepare, 776 827 .buf_queue = m2mtest_buf_queue, 777 - .wait_prepare = m2mtest_wait_prepare, 778 - .wait_finish = m2mtest_wait_finish, 828 + .wait_prepare = vb2_ops_wait_prepare, 829 + .wait_finish = vb2_ops_wait_finish, 779 830 }; 780 831 781 832 static int queue_init(void *priv, struct vb2_queue *src_vq, struct vb2_queue *dst_vq) ··· 778 853 src_vq->ops = &m2mtest_qops; 779 854 src_vq->mem_ops = &vb2_vmalloc_memops; 780 855 src_vq->timestamp_type = V4L2_BUF_FLAG_TIMESTAMP_COPY; 856 + src_vq->lock = &ctx->dev->dev_mutex; 781 857 782 858 ret = vb2_queue_init(src_vq); 783 859 if (ret) ··· 791 865 dst_vq->ops = &m2mtest_qops; 792 866 dst_vq->mem_ops = &vb2_vmalloc_memops; 793 867 dst_vq->timestamp_type = V4L2_BUF_FLAG_TIMESTAMP_COPY; 868 + dst_vq->lock = &ctx->dev->dev_mutex; 794 869 795 870 return vb2_queue_init(dst_vq); 796 871 } ··· 863 936 ctx->q_data[V4L2_M2M_DST] = ctx->q_data[V4L2_M2M_SRC]; 864 937 ctx->colorspace = V4L2_COLORSPACE_REC709; 865 938 866 - ctx->m2m_ctx = v4l2_m2m_ctx_init(dev->m2m_dev, ctx, &queue_init); 939 + ctx->fh.m2m_ctx = v4l2_m2m_ctx_init(dev->m2m_dev, ctx, &queue_init); 867 940 868 - if (IS_ERR(ctx->m2m_ctx)) { 869 - rc = PTR_ERR(ctx->m2m_ctx); 941 + if (IS_ERR(ctx->fh.m2m_ctx)) { 942 + rc = PTR_ERR(ctx->fh.m2m_ctx); 870 943 871 944 v4l2_ctrl_handler_free(hdl); 872 945 kfree(ctx); ··· 876 949 v4l2_fh_add(&ctx->fh); 877 950 atomic_inc(&dev->num_inst); 878 951 879 - dprintk(dev, "Created instance %p, m2m_ctx: %p\n", ctx, ctx->m2m_ctx); 952 + dprintk(dev, "Created instance: %p, m2m_ctx: %p\n", 953 + ctx, ctx->fh.m2m_ctx); 880 954 881 955 open_unlock: 882 956 mutex_unlock(&dev->dev_mutex); ··· 895 967 v4l2_fh_exit(&ctx->fh); 896 968 v4l2_ctrl_handler_free(&ctx->hdl); 897 969 mutex_lock(&dev->dev_mutex); 898 - v4l2_m2m_ctx_release(ctx->m2m_ctx); 970 + v4l2_m2m_ctx_release(ctx->fh.m2m_ctx); 899 971 mutex_unlock(&dev->dev_mutex); 900 972 kfree(ctx); 901 973 ··· 904 976 return 0; 905 977 } 906 978 907 - static unsigned int m2mtest_poll(struct file *file, 908 - struct poll_table_struct *wait) 909 - { 910 - struct m2mtest_ctx *ctx = file2ctx(file); 911 - 912 - return v4l2_m2m_poll(file, ctx->m2m_ctx, wait); 913 - } 914 - 915 - static int m2mtest_mmap(struct file *file, struct vm_area_struct *vma) 916 - { 917 - struct m2mtest_dev *dev = video_drvdata(file); 918 - struct m2mtest_ctx *ctx = file2ctx(file); 919 - int res; 920 - 921 - if (mutex_lock_interruptible(&dev->dev_mutex)) 922 - return -ERESTARTSYS; 923 - res = v4l2_m2m_mmap(file, ctx->m2m_ctx, vma); 924 - mutex_unlock(&dev->dev_mutex); 925 - return res; 926 - } 927 - 928 979 static const struct v4l2_file_operations m2mtest_fops = { 929 980 .owner = THIS_MODULE, 930 981 .open = m2mtest_open, 931 982 .release = m2mtest_release, 932 - .poll = m2mtest_poll, 983 + .poll = v4l2_m2m_fop_poll, 933 984 .unlocked_ioctl = video_ioctl2, 934 - .mmap = m2mtest_mmap, 985 + .mmap = v4l2_m2m_fop_mmap, 935 986 }; 936 987 937 988 static struct video_device m2mtest_videodev = { ··· 926 1019 .device_run = device_run, 927 1020 .job_ready = job_ready, 928 1021 .job_abort = job_abort, 929 - .lock = m2mtest_lock, 930 - .unlock = m2mtest_unlock, 931 1022 }; 932 1023 933 1024 static int m2mtest_probe(struct platform_device *pdev) ··· 1038 1133 1039 1134 module_init(m2mtest_init); 1040 1135 module_exit(m2mtest_exit); 1041 -