From patchwork Mon Mar 13 19:20:28 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Gustavo F. Padovan" X-Patchwork-Id: 40020 Received: from mail.tu-berlin.de ([130.149.7.33]) by www.linuxtv.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cnVZb-0004QQ-7V; Mon, 13 Mar 2017 19:24:03 +0000 X-tubIT-Incoming-IP: 209.132.180.67 Received: from vger.kernel.org ([209.132.180.67]) by mail.tu-berlin.de (exim-4.84_2/mailfrontend-6) with esmtp id 1cnVZZ-0005tm-3R; Mon, 13 Mar 2017 20:24:03 +0100 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751141AbdCMTUz (ORCPT + 1 other); Mon, 13 Mar 2017 15:20:55 -0400 Received: from mail-qt0-f196.google.com ([209.85.216.196]:34397 "EHLO mail-qt0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752577AbdCMTUw (ORCPT ); Mon, 13 Mar 2017 15:20:52 -0400 Received: by mail-qt0-f196.google.com with SMTP id x35so7471736qtc.1; Mon, 13 Mar 2017 12:20:51 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=+tZTiCYUgFYUfUBjCd8xIoZrDchfjn+wH4N2QFk7C7E=; b=O7tuW5nLftOk15IrW3ToFmCuXEQvq8W+QOy8a1tbXGGx1CfHAX39HAHGxx0nTBS1Jy qjx19ADqguDu/0sIPrDBumHHoZ2Yo4z17gJnnxl0KIyAMn2aiIpgAKKn6BzmFQ5ZXvmz ys9tbpPA1uGLhVqW1gkGFDmk7fQJfrxpMTvKvO4Oz2nF/2kd3d20uEv4jXzMpGTCShxN 7WYzQm4b4e6jsDod2myoI6E0ejAFFiZcKh7mU3phR+TKakkqpy1gQDwBGfWQKg3IIkPZ WfMOf3xbDiapiMNrT+iGPMLho5A9MeeZopwXFcVbKzkejOrtrm0c95qiffu4DKbFH0ST aJ8w== X-Gm-Message-State: AMke39nfZwlwv9QWHLyYHHrpTMKGXTLd+XGf7fCYVQCIqPHmp6b+pBNkCPM3I/vPoo05PA== X-Received: by 10.237.32.240 with SMTP id 103mr34594370qtb.93.1489432850791; Mon, 13 Mar 2017 12:20:50 -0700 (PDT) Received: from localhost.localdomain ([179.159.9.225]) by smtp.gmail.com with ESMTPSA id a19sm12821047qta.48.2017.03.13.12.20.48 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 13 Mar 2017 12:20:50 -0700 (PDT) From: Gustavo Padovan To: linux-media@vger.kernel.org Cc: Hans Verkuil , Mauro Carvalho Chehab , Laurent Pinchart , Javier Martinez Canillas , linux-kernel@vger.kernel.org, Gustavo Padovan Subject: [RFC 03/10] [media] vb2: add in-fence support to QBUF Date: Mon, 13 Mar 2017 16:20:28 -0300 Message-Id: <20170313192035.29859-4-gustavo@padovan.org> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20170313192035.29859-1-gustavo@padovan.org> References: <20170313192035.29859-1-gustavo@padovan.org> Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-PMX-Version: 6.0.0.2142326, Antispam-Engine: 2.7.2.2107409, Antispam-Data: 2017.3.13.191516 X-PMX-Spam: Gauge=IIIIIIII, Probability=8%, Report=' MULTIPLE_RCPTS 0.1, HTML_00_01 0.05, HTML_00_10 0.05, BODY_SIZE_5000_5999 0, BODY_SIZE_7000_LESS 0, IN_REP_TO 0, LEGITIMATE_SIGNS 0, MSG_THREAD 0, MULTIPLE_REAL_RCPTS 0, NO_URI_HTTPS 0, REFERENCES 0, __ANY_URI 0, __CC_NAME 0, __CC_NAME_DIFF_FROM_ACC 0, __CC_REAL_NAMES 0, __CP_MEDIA_BODY 0, __HAS_CC_HDR 0, __HAS_FROM 0, __HAS_LIST_ID 0, __HAS_MSGID 0, __HAS_X_MAILER 0, __HAS_X_MAILING_LIST 0, __INT_PROD_TV 0, __IN_REP_TO 0, __MIME_TEXT_ONLY 0, __MIME_TEXT_P 0, __MIME_TEXT_P1 0, __MULTIPLE_RCPTS_CC_X2 0, __NO_HTML_TAG_RAW 0, __REFERENCES 0, __SANE_MSGID 0, __SUBJ_ALPHA_END 0, __TO_MALFORMED_2 0, __TO_NO_NAME 0, __URI_NO_WWW 0, __URI_NS , __YOUTUBE_RCVD 0' From: Gustavo Padovan Receive in-fence from userspace and support for waiting on them before queueing the buffer for the driver. Signed-off-by: Gustavo Padovan --- drivers/media/Kconfig | 1 + drivers/media/v4l2-core/videobuf2-core.c | 24 ++++++++++++++++++++---- drivers/media/v4l2-core/videobuf2-v4l2.c | 14 +++++++++++++- include/media/videobuf2-core.h | 7 ++++++- 4 files changed, 40 insertions(+), 6 deletions(-) diff --git a/drivers/media/Kconfig b/drivers/media/Kconfig index 3512316..7c5a0e0 100644 --- a/drivers/media/Kconfig +++ b/drivers/media/Kconfig @@ -5,6 +5,7 @@ menuconfig MEDIA_SUPPORT tristate "Multimedia support" depends on HAS_IOMEM + select SYNC_FILE help If you want to use Webcams, Video grabber devices and/or TV devices enable this option and other options below. diff --git a/drivers/media/v4l2-core/videobuf2-core.c b/drivers/media/v4l2-core/videobuf2-core.c index 0e30fcd..e0e7109 100644 --- a/drivers/media/v4l2-core/videobuf2-core.c +++ b/drivers/media/v4l2-core/videobuf2-core.c @@ -1400,7 +1400,18 @@ static int __vb2_core_qbuf(struct vb2_buffer *vb, struct vb2_queue *q) return 0; } -int vb2_core_qbuf(struct vb2_queue *q, unsigned int index, void *pb) +static void vb2_qbuf_fence_cb(struct dma_fence *f, struct dma_fence_cb *cb) +{ + struct vb2_buffer *vb = container_of(cb, struct vb2_buffer, fence_cb); + + dma_fence_put(vb->in_fence); + vb->in_fence = NULL; + + __vb2_core_qbuf(vb, vb->vb2_queue); +} + +int vb2_core_qbuf(struct vb2_queue *q, unsigned int index, void *pb, + struct dma_fence *fence) { struct vb2_buffer *vb; int ret; @@ -1432,6 +1443,11 @@ int vb2_core_qbuf(struct vb2_queue *q, unsigned int index, void *pb) if (pb) call_void_bufop(q, fill_user_buffer, vb, pb); + vb->in_fence = fence; + if (fence && !dma_fence_add_callback(fence, &vb->fence_cb, + vb2_qbuf_fence_cb)) + return 0; + return __vb2_core_qbuf(vb, q); } EXPORT_SYMBOL_GPL(vb2_core_qbuf); @@ -2246,7 +2262,7 @@ static int __vb2_init_fileio(struct vb2_queue *q, int read) * Queue all buffers. */ for (i = 0; i < q->num_buffers; i++) { - ret = vb2_core_qbuf(q, i, NULL); + ret = vb2_core_qbuf(q, i, NULL, NULL); if (ret) goto err_reqbufs; fileio->bufs[i].queued = 1; @@ -2425,7 +2441,7 @@ static size_t __vb2_perform_fileio(struct vb2_queue *q, char __user *data, size_ if (copy_timestamp) b->timestamp = ktime_get_ns(); - ret = vb2_core_qbuf(q, index, NULL); + ret = vb2_core_qbuf(q, index, NULL, NULL); dprintk(5, "vb2_dbuf result: %d\n", ret); if (ret) return ret; @@ -2528,7 +2544,7 @@ static int vb2_thread(void *data) if (copy_timestamp) vb->timestamp = ktime_get_ns();; if (!threadio->stop) - ret = vb2_core_qbuf(q, vb->index, NULL); + ret = vb2_core_qbuf(q, vb->index, NULL, NULL); call_void_qop(q, wait_prepare, q); if (ret || threadio->stop) break; diff --git a/drivers/media/v4l2-core/videobuf2-v4l2.c b/drivers/media/v4l2-core/videobuf2-v4l2.c index d23c1bf..c164aa0 100644 --- a/drivers/media/v4l2-core/videobuf2-v4l2.c +++ b/drivers/media/v4l2-core/videobuf2-v4l2.c @@ -23,6 +23,7 @@ #include #include #include +#include #include #include @@ -557,6 +558,7 @@ EXPORT_SYMBOL_GPL(vb2_create_bufs); int vb2_qbuf(struct vb2_queue *q, struct v4l2_buffer *b) { + struct dma_fence *fence = NULL; int ret; if (vb2_fileio_is_active(q)) { @@ -565,7 +567,17 @@ int vb2_qbuf(struct vb2_queue *q, struct v4l2_buffer *b) } ret = vb2_queue_or_prepare_buf(q, b, "qbuf"); - return ret ? ret : vb2_core_qbuf(q, b->index, b); + + if (b->flags & V4L2_BUF_FLAG_IN_FENCE) { + if (b->memory != VB2_MEMORY_DMABUF) + return -EINVAL; + + fence = sync_file_get_fence(b->fence_fd); + if (!fence) + return -EINVAL; + } + + return ret ? ret : vb2_core_qbuf(q, b->index, b, fence); } EXPORT_SYMBOL_GPL(vb2_qbuf); diff --git a/include/media/videobuf2-core.h b/include/media/videobuf2-core.h index ac5898a..fe2de99 100644 --- a/include/media/videobuf2-core.h +++ b/include/media/videobuf2-core.h @@ -16,6 +16,7 @@ #include #include #include +#include #define VB2_MAX_FRAME (32) #define VB2_MAX_PLANES (8) @@ -259,6 +260,9 @@ struct vb2_buffer { struct list_head queued_entry; struct list_head done_entry; + + struct dma_fence *in_fence; + struct dma_fence_cb fence_cb; #ifdef CONFIG_VIDEO_ADV_DEBUG /* * Counters for how often these buffer-related ops are @@ -727,7 +731,8 @@ int vb2_core_prepare_buf(struct vb2_queue *q, unsigned int index, void *pb); * The return values from this function are intended to be directly returned * from vidioc_qbuf handler in driver. */ -int vb2_core_qbuf(struct vb2_queue *q, unsigned int index, void *pb); +int vb2_core_qbuf(struct vb2_queue *q, unsigned int index, void *pb, + struct dma_fence *fence); /** * vb2_core_dqbuf() - Dequeue a buffer to the userspace