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

[media] exynos4-is: Use mem-to-mem ioctl helpers

Simplify the FIMC mem-to-mem 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
43894d84 20702ebc

+26 -124
-2
drivers/media/platform/exynos4-is/fimc-core.h
··· 481 481 * @flags: additional flags for image conversion 482 482 * @state: flags to keep track of user configuration 483 483 * @fimc_dev: the FIMC device this context applies to 484 - * @m2m_ctx: memory-to-memory device context 485 484 * @fh: v4l2 file handle 486 485 * @ctrls: v4l2 controls structure 487 486 */ ··· 501 502 u32 flags; 502 503 u32 state; 503 504 struct fimc_dev *fimc_dev; 504 - struct v4l2_m2m_ctx *m2m_ctx; 505 505 struct v4l2_fh fh; 506 506 struct fimc_ctrls ctrls; 507 507 };
+26 -122
drivers/media/platform/exynos4-is/fimc-m2m.c
··· 44 44 { 45 45 struct vb2_buffer *src_vb, *dst_vb; 46 46 47 - if (!ctx || !ctx->m2m_ctx) 47 + if (!ctx || !ctx->fh.m2m_ctx) 48 48 return; 49 49 50 - src_vb = v4l2_m2m_src_buf_remove(ctx->m2m_ctx); 51 - dst_vb = v4l2_m2m_dst_buf_remove(ctx->m2m_ctx); 50 + src_vb = v4l2_m2m_src_buf_remove(ctx->fh.m2m_ctx); 51 + dst_vb = v4l2_m2m_dst_buf_remove(ctx->fh.m2m_ctx); 52 52 53 53 if (src_vb && dst_vb) { 54 54 v4l2_m2m_buf_done(src_vb, vb_state); 55 55 v4l2_m2m_buf_done(dst_vb, vb_state); 56 56 v4l2_m2m_job_finish(ctx->fimc_dev->m2m.m2m_dev, 57 - ctx->m2m_ctx); 57 + ctx->fh.m2m_ctx); 58 58 } 59 59 } 60 60 ··· 123 123 fimc_prepare_dma_offset(ctx, df); 124 124 } 125 125 126 - src_vb = v4l2_m2m_next_src_buf(ctx->m2m_ctx); 126 + src_vb = v4l2_m2m_next_src_buf(ctx->fh.m2m_ctx); 127 127 ret = fimc_prepare_addr(ctx, src_vb, sf, &sf->paddr); 128 128 if (ret) 129 129 goto dma_unlock; 130 130 131 - dst_vb = v4l2_m2m_next_dst_buf(ctx->m2m_ctx); 131 + dst_vb = v4l2_m2m_next_dst_buf(ctx->fh.m2m_ctx); 132 132 ret = fimc_prepare_addr(ctx, dst_vb, df, &df->paddr); 133 133 if (ret) 134 134 goto dma_unlock; ··· 219 219 static void fimc_buf_queue(struct vb2_buffer *vb) 220 220 { 221 221 struct fimc_ctx *ctx = vb2_get_drv_priv(vb->vb2_queue); 222 - 223 - dbg("ctx: %p, ctx->state: 0x%x", ctx, ctx->state); 224 - 225 - if (ctx->m2m_ctx) 226 - v4l2_m2m_buf_queue(ctx->m2m_ctx, vb); 227 - } 228 - 229 - static void fimc_lock(struct vb2_queue *vq) 230 - { 231 - struct fimc_ctx *ctx = vb2_get_drv_priv(vq); 232 - mutex_lock(&ctx->fimc_dev->lock); 233 - } 234 - 235 - static void fimc_unlock(struct vb2_queue *vq) 236 - { 237 - struct fimc_ctx *ctx = vb2_get_drv_priv(vq); 238 - mutex_unlock(&ctx->fimc_dev->lock); 222 + v4l2_m2m_buf_queue(ctx->fh.m2m_ctx, vb); 239 223 } 240 224 241 225 static struct vb2_ops fimc_qops = { 242 226 .queue_setup = fimc_queue_setup, 243 227 .buf_prepare = fimc_buf_prepare, 244 228 .buf_queue = fimc_buf_queue, 245 - .wait_prepare = fimc_unlock, 246 - .wait_finish = fimc_lock, 229 + .wait_prepare = vb2_ops_wait_prepare, 230 + .wait_finish = vb2_ops_wait_finish, 247 231 .stop_streaming = stop_streaming, 248 232 .start_streaming = start_streaming, 249 233 }; ··· 369 385 if (ret) 370 386 return ret; 371 387 372 - vq = v4l2_m2m_get_vq(ctx->m2m_ctx, f->type); 388 + vq = v4l2_m2m_get_vq(ctx->fh.m2m_ctx, f->type); 373 389 374 390 if (vb2_is_busy(vq)) { 375 391 v4l2_err(&fimc->m2m.vfd, "queue (%d) busy\n", f->type); ··· 392 408 fimc_alpha_ctrl_update(ctx); 393 409 394 410 return 0; 395 - } 396 - 397 - static int fimc_m2m_reqbufs(struct file *file, void *fh, 398 - struct v4l2_requestbuffers *reqbufs) 399 - { 400 - struct fimc_ctx *ctx = fh_to_ctx(fh); 401 - return v4l2_m2m_reqbufs(file, ctx->m2m_ctx, reqbufs); 402 - } 403 - 404 - static int fimc_m2m_querybuf(struct file *file, void *fh, 405 - struct v4l2_buffer *buf) 406 - { 407 - struct fimc_ctx *ctx = fh_to_ctx(fh); 408 - return v4l2_m2m_querybuf(file, ctx->m2m_ctx, buf); 409 - } 410 - 411 - static int fimc_m2m_qbuf(struct file *file, void *fh, 412 - struct v4l2_buffer *buf) 413 - { 414 - struct fimc_ctx *ctx = fh_to_ctx(fh); 415 - return v4l2_m2m_qbuf(file, ctx->m2m_ctx, buf); 416 - } 417 - 418 - static int fimc_m2m_dqbuf(struct file *file, void *fh, 419 - struct v4l2_buffer *buf) 420 - { 421 - struct fimc_ctx *ctx = fh_to_ctx(fh); 422 - return v4l2_m2m_dqbuf(file, ctx->m2m_ctx, buf); 423 - } 424 - 425 - static int fimc_m2m_expbuf(struct file *file, void *fh, 426 - struct v4l2_exportbuffer *eb) 427 - { 428 - struct fimc_ctx *ctx = fh_to_ctx(fh); 429 - return v4l2_m2m_expbuf(file, ctx->m2m_ctx, eb); 430 - } 431 - 432 - 433 - static int fimc_m2m_streamon(struct file *file, void *fh, 434 - enum v4l2_buf_type type) 435 - { 436 - struct fimc_ctx *ctx = fh_to_ctx(fh); 437 - return v4l2_m2m_streamon(file, ctx->m2m_ctx, type); 438 - } 439 - 440 - static int fimc_m2m_streamoff(struct file *file, void *fh, 441 - enum v4l2_buf_type type) 442 - { 443 - struct fimc_ctx *ctx = fh_to_ctx(fh); 444 - return v4l2_m2m_streamoff(file, ctx->m2m_ctx, type); 445 411 } 446 412 447 413 static int fimc_m2m_cropcap(struct file *file, void *fh, ··· 532 598 .vidioc_try_fmt_vid_out_mplane = fimc_m2m_try_fmt_mplane, 533 599 .vidioc_s_fmt_vid_cap_mplane = fimc_m2m_s_fmt_mplane, 534 600 .vidioc_s_fmt_vid_out_mplane = fimc_m2m_s_fmt_mplane, 535 - .vidioc_reqbufs = fimc_m2m_reqbufs, 536 - .vidioc_querybuf = fimc_m2m_querybuf, 537 - .vidioc_qbuf = fimc_m2m_qbuf, 538 - .vidioc_dqbuf = fimc_m2m_dqbuf, 539 - .vidioc_expbuf = fimc_m2m_expbuf, 540 - .vidioc_streamon = fimc_m2m_streamon, 541 - .vidioc_streamoff = fimc_m2m_streamoff, 601 + .vidioc_reqbufs = v4l2_m2m_ioctl_reqbufs, 602 + .vidioc_querybuf = v4l2_m2m_ioctl_querybuf, 603 + .vidioc_qbuf = v4l2_m2m_ioctl_qbuf, 604 + .vidioc_dqbuf = v4l2_m2m_ioctl_dqbuf, 605 + .vidioc_expbuf = v4l2_m2m_ioctl_expbuf, 606 + .vidioc_streamon = v4l2_m2m_ioctl_streamon, 607 + .vidioc_streamoff = v4l2_m2m_ioctl_streamoff, 542 608 .vidioc_g_crop = fimc_m2m_g_crop, 543 609 .vidioc_s_crop = fimc_m2m_s_crop, 544 610 .vidioc_cropcap = fimc_m2m_cropcap ··· 558 624 src_vq->mem_ops = &vb2_dma_contig_memops; 559 625 src_vq->buf_struct_size = sizeof(struct v4l2_m2m_buffer); 560 626 src_vq->timestamp_type = V4L2_BUF_FLAG_TIMESTAMP_COPY; 627 + src_vq->lock = &ctx->fimc_dev->lock; 561 628 562 629 ret = vb2_queue_init(src_vq); 563 630 if (ret) ··· 571 636 dst_vq->mem_ops = &vb2_dma_contig_memops; 572 637 dst_vq->buf_struct_size = sizeof(struct v4l2_m2m_buffer); 573 638 dst_vq->timestamp_type = V4L2_BUF_FLAG_TIMESTAMP_COPY; 639 + dst_vq->lock = &ctx->fimc_dev->lock; 574 640 575 641 return vb2_queue_init(dst_vq); 576 642 } ··· 644 708 ctx->out_path = FIMC_IO_DMA; 645 709 ctx->scaler.enabled = 1; 646 710 647 - ctx->m2m_ctx = v4l2_m2m_ctx_init(fimc->m2m.m2m_dev, ctx, queue_init); 648 - if (IS_ERR(ctx->m2m_ctx)) { 649 - ret = PTR_ERR(ctx->m2m_ctx); 711 + ctx->fh.m2m_ctx = v4l2_m2m_ctx_init(fimc->m2m.m2m_dev, ctx, queue_init); 712 + if (IS_ERR(ctx->fh.m2m_ctx)) { 713 + ret = PTR_ERR(ctx->fh.m2m_ctx); 650 714 goto error_c; 651 715 } 652 716 ··· 661 725 return 0; 662 726 663 727 error_m2m_ctx: 664 - v4l2_m2m_ctx_release(ctx->m2m_ctx); 728 + v4l2_m2m_ctx_release(ctx->fh.m2m_ctx); 665 729 error_c: 666 730 fimc_ctrls_delete(ctx); 667 731 error_fh: ··· 683 747 684 748 mutex_lock(&fimc->lock); 685 749 686 - v4l2_m2m_ctx_release(ctx->m2m_ctx); 750 + v4l2_m2m_ctx_release(ctx->fh.m2m_ctx); 687 751 fimc_ctrls_delete(ctx); 688 752 v4l2_fh_del(&ctx->fh); 689 753 v4l2_fh_exit(&ctx->fh); ··· 696 760 return 0; 697 761 } 698 762 699 - static unsigned int fimc_m2m_poll(struct file *file, 700 - struct poll_table_struct *wait) 701 - { 702 - struct fimc_ctx *ctx = fh_to_ctx(file->private_data); 703 - struct fimc_dev *fimc = ctx->fimc_dev; 704 - int ret; 705 - 706 - if (mutex_lock_interruptible(&fimc->lock)) 707 - return -ERESTARTSYS; 708 - 709 - ret = v4l2_m2m_poll(file, ctx->m2m_ctx, wait); 710 - mutex_unlock(&fimc->lock); 711 - 712 - return ret; 713 - } 714 - 715 - 716 - static int fimc_m2m_mmap(struct file *file, struct vm_area_struct *vma) 717 - { 718 - struct fimc_ctx *ctx = fh_to_ctx(file->private_data); 719 - struct fimc_dev *fimc = ctx->fimc_dev; 720 - int ret; 721 - 722 - if (mutex_lock_interruptible(&fimc->lock)) 723 - return -ERESTARTSYS; 724 - 725 - ret = v4l2_m2m_mmap(file, ctx->m2m_ctx, vma); 726 - mutex_unlock(&fimc->lock); 727 - 728 - return ret; 729 - } 730 - 731 763 static const struct v4l2_file_operations fimc_m2m_fops = { 732 764 .owner = THIS_MODULE, 733 765 .open = fimc_m2m_open, 734 766 .release = fimc_m2m_release, 735 - .poll = fimc_m2m_poll, 767 + .poll = v4l2_m2m_fop_poll, 736 768 .unlocked_ioctl = video_ioctl2, 737 - .mmap = fimc_m2m_mmap, 769 + .mmap = v4l2_m2m_fop_mmap, 738 770 }; 739 771 740 772 static struct v4l2_m2m_ops m2m_ops = {