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

[media] s5p-g2d: Use mem-to-mem ioctl 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
febeaa45 718cf4a9

+21 -104
+21 -103
drivers/media/platform/s5p-g2d/g2d.c
··· 136 136 static void g2d_buf_queue(struct vb2_buffer *vb) 137 137 { 138 138 struct g2d_ctx *ctx = vb2_get_drv_priv(vb->vb2_queue); 139 - v4l2_m2m_buf_queue(ctx->m2m_ctx, vb); 139 + v4l2_m2m_buf_queue(ctx->fh.m2m_ctx, vb); 140 140 } 141 - 142 141 143 142 static struct vb2_ops g2d_qops = { 144 143 .queue_setup = g2d_queue_setup, ··· 158 159 src_vq->mem_ops = &vb2_dma_contig_memops; 159 160 src_vq->buf_struct_size = sizeof(struct v4l2_m2m_buffer); 160 161 src_vq->timestamp_type = V4L2_BUF_FLAG_TIMESTAMP_COPY; 162 + src_vq->lock = &ctx->dev->mutex; 161 163 162 164 ret = vb2_queue_init(src_vq); 163 165 if (ret) ··· 171 171 dst_vq->mem_ops = &vb2_dma_contig_memops; 172 172 dst_vq->buf_struct_size = sizeof(struct v4l2_m2m_buffer); 173 173 dst_vq->timestamp_type = V4L2_BUF_FLAG_TIMESTAMP_COPY; 174 + dst_vq->lock = &ctx->dev->mutex; 174 175 175 176 return vb2_queue_init(dst_vq); 176 177 } ··· 254 253 kfree(ctx); 255 254 return -ERESTARTSYS; 256 255 } 257 - ctx->m2m_ctx = v4l2_m2m_ctx_init(dev->m2m_dev, ctx, &queue_init); 258 - if (IS_ERR(ctx->m2m_ctx)) { 259 - ret = PTR_ERR(ctx->m2m_ctx); 256 + ctx->fh.m2m_ctx = v4l2_m2m_ctx_init(dev->m2m_dev, ctx, &queue_init); 257 + if (IS_ERR(ctx->fh.m2m_ctx)) { 258 + ret = PTR_ERR(ctx->fh.m2m_ctx); 260 259 mutex_unlock(&dev->mutex); 261 260 kfree(ctx); 262 261 return ret; ··· 325 324 struct vb2_queue *vq; 326 325 struct g2d_frame *frm; 327 326 328 - vq = v4l2_m2m_get_vq(ctx->m2m_ctx, f->type); 327 + vq = v4l2_m2m_get_vq(ctx->fh.m2m_ctx, f->type); 329 328 if (!vq) 330 329 return -EINVAL; 331 330 frm = get_frame(ctx, f->type); ··· 385 384 ret = vidioc_try_fmt(file, prv, f); 386 385 if (ret) 387 386 return ret; 388 - vq = v4l2_m2m_get_vq(ctx->m2m_ctx, f->type); 387 + vq = v4l2_m2m_get_vq(ctx->fh.m2m_ctx, f->type); 389 388 if (vb2_is_busy(vq)) { 390 389 v4l2_err(&dev->v4l2_dev, "queue (%d) bust\n", f->type); 391 390 return -EBUSY; ··· 409 408 frm->fmt = fmt; 410 409 frm->stride = f->fmt.pix.bytesperline; 411 410 return 0; 412 - } 413 - 414 - static unsigned int g2d_poll(struct file *file, struct poll_table_struct *wait) 415 - { 416 - struct g2d_ctx *ctx = fh2ctx(file->private_data); 417 - struct g2d_dev *dev = ctx->dev; 418 - unsigned int res; 419 - 420 - mutex_lock(&dev->mutex); 421 - res = v4l2_m2m_poll(file, ctx->m2m_ctx, wait); 422 - mutex_unlock(&dev->mutex); 423 - return res; 424 - } 425 - 426 - static int g2d_mmap(struct file *file, struct vm_area_struct *vma) 427 - { 428 - struct g2d_ctx *ctx = fh2ctx(file->private_data); 429 - struct g2d_dev *dev = ctx->dev; 430 - int ret; 431 - 432 - if (mutex_lock_interruptible(&dev->mutex)) 433 - return -ERESTARTSYS; 434 - ret = v4l2_m2m_mmap(file, ctx->m2m_ctx, vma); 435 - mutex_unlock(&dev->mutex); 436 - return ret; 437 - } 438 - 439 - static int vidioc_reqbufs(struct file *file, void *priv, 440 - struct v4l2_requestbuffers *reqbufs) 441 - { 442 - struct g2d_ctx *ctx = priv; 443 - return v4l2_m2m_reqbufs(file, ctx->m2m_ctx, reqbufs); 444 - } 445 - 446 - static int vidioc_querybuf(struct file *file, void *priv, 447 - struct v4l2_buffer *buf) 448 - { 449 - struct g2d_ctx *ctx = priv; 450 - return v4l2_m2m_querybuf(file, ctx->m2m_ctx, buf); 451 - } 452 - 453 - static int vidioc_qbuf(struct file *file, void *priv, struct v4l2_buffer *buf) 454 - { 455 - struct g2d_ctx *ctx = priv; 456 - return v4l2_m2m_qbuf(file, ctx->m2m_ctx, buf); 457 - } 458 - 459 - static int vidioc_dqbuf(struct file *file, void *priv, struct v4l2_buffer *buf) 460 - { 461 - struct g2d_ctx *ctx = priv; 462 - return v4l2_m2m_dqbuf(file, ctx->m2m_ctx, buf); 463 - } 464 - 465 - 466 - static int vidioc_streamon(struct file *file, void *priv, 467 - enum v4l2_buf_type type) 468 - { 469 - struct g2d_ctx *ctx = priv; 470 - return v4l2_m2m_streamon(file, ctx->m2m_ctx, type); 471 - } 472 - 473 - static int vidioc_streamoff(struct file *file, void *priv, 474 - enum v4l2_buf_type type) 475 - { 476 - struct g2d_ctx *ctx = priv; 477 - return v4l2_m2m_streamoff(file, ctx->m2m_ctx, type); 478 411 } 479 412 480 413 static int vidioc_cropcap(struct file *file, void *priv, ··· 486 551 return 0; 487 552 } 488 553 489 - static void g2d_lock(void *prv) 490 - { 491 - struct g2d_ctx *ctx = prv; 492 - struct g2d_dev *dev = ctx->dev; 493 - mutex_lock(&dev->mutex); 494 - } 495 - 496 - static void g2d_unlock(void *prv) 497 - { 498 - struct g2d_ctx *ctx = prv; 499 - struct g2d_dev *dev = ctx->dev; 500 - mutex_unlock(&dev->mutex); 501 - } 502 - 503 554 static void job_abort(void *prv) 504 555 { 505 556 struct g2d_ctx *ctx = prv; ··· 510 589 511 590 dev->curr = ctx; 512 591 513 - src = v4l2_m2m_next_src_buf(ctx->m2m_ctx); 514 - dst = v4l2_m2m_next_dst_buf(ctx->m2m_ctx); 592 + src = v4l2_m2m_next_src_buf(ctx->fh.m2m_ctx); 593 + dst = v4l2_m2m_next_dst_buf(ctx->fh.m2m_ctx); 515 594 516 595 clk_enable(dev->gate); 517 596 g2d_reset(dev); ··· 552 631 553 632 BUG_ON(ctx == NULL); 554 633 555 - src = v4l2_m2m_src_buf_remove(ctx->m2m_ctx); 556 - dst = v4l2_m2m_dst_buf_remove(ctx->m2m_ctx); 634 + src = v4l2_m2m_src_buf_remove(ctx->fh.m2m_ctx); 635 + dst = v4l2_m2m_dst_buf_remove(ctx->fh.m2m_ctx); 557 636 558 637 BUG_ON(src == NULL); 559 638 BUG_ON(dst == NULL); ··· 563 642 564 643 v4l2_m2m_buf_done(src, VB2_BUF_STATE_DONE); 565 644 v4l2_m2m_buf_done(dst, VB2_BUF_STATE_DONE); 566 - v4l2_m2m_job_finish(dev->m2m_dev, ctx->m2m_ctx); 645 + v4l2_m2m_job_finish(dev->m2m_dev, ctx->fh.m2m_ctx); 567 646 568 647 dev->curr = NULL; 569 648 wake_up(&dev->irq_queue); ··· 574 653 .owner = THIS_MODULE, 575 654 .open = g2d_open, 576 655 .release = g2d_release, 577 - .poll = g2d_poll, 656 + .poll = v4l2_m2m_fop_poll, 578 657 .unlocked_ioctl = video_ioctl2, 579 - .mmap = g2d_mmap, 658 + .mmap = v4l2_m2m_fop_mmap, 580 659 }; 581 660 582 661 static const struct v4l2_ioctl_ops g2d_ioctl_ops = { ··· 592 671 .vidioc_try_fmt_vid_out = vidioc_try_fmt, 593 672 .vidioc_s_fmt_vid_out = vidioc_s_fmt, 594 673 595 - .vidioc_reqbufs = vidioc_reqbufs, 596 - .vidioc_querybuf = vidioc_querybuf, 674 + .vidioc_reqbufs = v4l2_m2m_ioctl_reqbufs, 675 + .vidioc_querybuf = v4l2_m2m_ioctl_querybuf, 676 + .vidioc_qbuf = v4l2_m2m_ioctl_qbuf, 677 + .vidioc_dqbuf = v4l2_m2m_ioctl_dqbuf, 597 678 598 - .vidioc_qbuf = vidioc_qbuf, 599 - .vidioc_dqbuf = vidioc_dqbuf, 600 - 601 - .vidioc_streamon = vidioc_streamon, 602 - .vidioc_streamoff = vidioc_streamoff, 679 + .vidioc_streamon = v4l2_m2m_ioctl_streamon, 680 + .vidioc_streamoff = v4l2_m2m_ioctl_streamoff, 603 681 604 682 .vidioc_g_crop = vidioc_g_crop, 605 683 .vidioc_s_crop = vidioc_s_crop, ··· 617 697 static struct v4l2_m2m_ops g2d_m2m_ops = { 618 698 .device_run = device_run, 619 699 .job_abort = job_abort, 620 - .lock = g2d_lock, 621 - .unlock = g2d_unlock, 622 700 }; 623 701 624 702 static const struct of_device_id exynos_g2d_match[];
-1
drivers/media/platform/s5p-g2d/g2d.h
··· 57 57 struct g2d_ctx { 58 58 struct v4l2_fh fh; 59 59 struct g2d_dev *dev; 60 - struct v4l2_m2m_ctx *m2m_ctx; 61 60 struct g2d_frame in; 62 61 struct g2d_frame out; 63 62 struct v4l2_ctrl *ctrl_hflip;