From patchwork Mon Mar 13 19:20:35 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gustavo Padovan X-Patchwork-Id: 9621915 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 02FE8604CC for ; Mon, 13 Mar 2017 19:23:59 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DCA6E205F6 for ; Mon, 13 Mar 2017 19:23:58 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CFC1B2850D; Mon, 13 Mar 2017 19:23:58 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.4 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 64AA3205F6 for ; Mon, 13 Mar 2017 19:23:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753733AbdCMTWY (ORCPT ); Mon, 13 Mar 2017 15:22:24 -0400 Received: from mail-qt0-f195.google.com ([209.85.216.195]:34887 "EHLO mail-qt0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753643AbdCMTVL (ORCPT ); Mon, 13 Mar 2017 15:21:11 -0400 Received: by mail-qt0-f195.google.com with SMTP id r5so7502036qtb.2; Mon, 13 Mar 2017 12:21:10 -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=9BiKz1ULFQg9NkDJNtF8e+TJZPFDl8nBpopxRVjOhhk=; b=O/kHJp4lz5fxbQVFv6VIj7nslkOonMtOf0U1e/BJLdjBi8rMhEiTSIfkkm5x10PJuw XWTXjFzGtNhomJk0PuWU0p4ZWfD8+sm0OztKjSOdize2N+3loyXLl7JQbv9ehsw1vguS hNEZXyJlj8sI4UqbSz0CK4A7OavhDKZ45fHiQH7Q0mQC02eoBqko8ryAXn13bczq90P4 XRPyBfPrHr7ASpspKT3C8WTCXCDnt8QE/374KN+fiZaiiFhaCdhpmKUck0J1OwYhmq0L 3LzSIA+w2ij642xbSrP7KqkWQpvn1u3i4rC4dy70vqD9YM1KtjF8vXT2gMp/f9f7/Gsi DxcQ== X-Gm-Message-State: AMke39kN7oP91IrWdnakTSTJ8cAaKAQWwYwMyuged8asNf3tNI3xDNdtcCO1SuMD9o3kQA== X-Received: by 10.237.59.91 with SMTP id q27mr35728798qte.193.1489432870112; Mon, 13 Mar 2017 12:21:10 -0700 (PDT) Received: from localhost.localdomain ([179.159.9.225]) by smtp.gmail.com with ESMTPSA id a19sm12821047qta.48.2017.03.13.12.21.07 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 13 Mar 2017 12:21:09 -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 10/10] [media] vb2: add out-fence support to QBUF Date: Mon, 13 Mar 2017 16:20:35 -0300 Message-Id: <20170313192035.29859-11-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-Virus-Scanned: ClamAV using ClamSMTP From: Gustavo Padovan If V4L2_BUF_FLAG_OUT_FENCE flag is present on the QBUF call we create an out_fence for the buffer and return it to userspace on the fence_fd field. The fence is signaled on buffer_done(), when the job on the buffer is finished. TODO: clean up on __vb2_queue_cancel() Signed-off-by: Gustavo Padovan --- drivers/media/v4l2-core/videobuf2-core.c | 6 ++++++ drivers/media/v4l2-core/videobuf2-v4l2.c | 15 ++++++++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/drivers/media/v4l2-core/videobuf2-core.c b/drivers/media/v4l2-core/videobuf2-core.c index 54b1404..ca8abcc 100644 --- a/drivers/media/v4l2-core/videobuf2-core.c +++ b/drivers/media/v4l2-core/videobuf2-core.c @@ -356,6 +356,7 @@ static int __vb2_queue_alloc(struct vb2_queue *q, enum vb2_memory memory, vb->planes[plane].length = plane_sizes[plane]; vb->planes[plane].min_length = plane_sizes[plane]; } + vb->out_fence_fd = -1; q->bufs[vb->index] = vb; /* Allocate video buffer memory for the MMAP type */ @@ -940,6 +941,11 @@ void vb2_buffer_done(struct vb2_buffer *vb, enum vb2_buffer_state state) __enqueue_in_driver(vb); return; default: + dma_fence_signal(vb->out_fence); + dma_fence_put(vb->out_fence); + vb->out_fence = NULL; + vb->out_fence_fd = -1; + /* Inform any processes that may be waiting for buffers */ wake_up(&q->done_wq); break; diff --git a/drivers/media/v4l2-core/videobuf2-v4l2.c b/drivers/media/v4l2-core/videobuf2-v4l2.c index c164aa0..1b43d9f 100644 --- a/drivers/media/v4l2-core/videobuf2-v4l2.c +++ b/drivers/media/v4l2-core/videobuf2-v4l2.c @@ -204,9 +204,14 @@ static void __fill_v4l2_buffer(struct vb2_buffer *vb, void *pb) b->timestamp = ns_to_timeval(vb->timestamp); b->timecode = vbuf->timecode; b->sequence = vbuf->sequence; - b->fence_fd = -1; + b->fence_fd = vb->out_fence_fd; b->reserved = 0; + if (vb->sync_file) { + fd_install(vb->out_fence_fd, vb->sync_file->file); + vb->sync_file = NULL; + } + if (q->is_multiplanar) { /* * Fill in plane-related data if userspace provided an array @@ -577,6 +582,14 @@ int vb2_qbuf(struct vb2_queue *q, struct v4l2_buffer *b) return -EINVAL; } + if (b->flags & V4L2_BUF_FLAG_OUT_FENCE) { + ret = vb2_setup_out_fence(q, b->index); + if (ret) { + dma_fence_put(fence); + return ret; + } + } + return ret ? ret : vb2_core_qbuf(q, b->index, b, fence); } EXPORT_SYMBOL_GPL(vb2_qbuf);