From patchwork Fri Oct 20 21:50:10 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gustavo Padovan X-Patchwork-Id: 10021025 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 481F860234 for ; Fri, 20 Oct 2017 21:52:26 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3B73228F6A for ; Fri, 20 Oct 2017 21:52:26 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3023B28F6F; Fri, 20 Oct 2017 21:52:26 +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=-4.9 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, RCVD_IN_SORBS_WEB 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 B0E1428F6A for ; Fri, 20 Oct 2017 21:52:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753380AbdJTVwE (ORCPT ); Fri, 20 Oct 2017 17:52:04 -0400 Received: from mail-qk0-f196.google.com ([209.85.220.196]:48070 "EHLO mail-qk0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753431AbdJTVvL (ORCPT ); Fri, 20 Oct 2017 17:51:11 -0400 Received: by mail-qk0-f196.google.com with SMTP id m189so15979058qke.4; Fri, 20 Oct 2017 14:51:11 -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=ptf7Q0Fd9bIN5pdGEr9UK0jdfOMKKIiUmD1yst0gpIg=; b=ts/qt+TpeIL7qms/CKZ2HHRMuIXiDeIywaiefOqbcM8sFrdFea0fuYONebATwaQI5E ROuk0bolEpk4n8YCZ6r14hnxjls6qX5bVbzMFZx2AGyCKmmzV66pkyHZ7LUk6X4ktSt7 lTX14nc/PDG/fMNpkzSLHvmDIrcaFp7EIABu6U6iAhBeY3FVHfVrmYV9TmEfI50XXJb/ YPlrEh4y3prWsHqCAy6JPOxOucHXxf0cTbJaekqHqjM4WrTj3X4lDGbdUl0QKD0Y+lve JmIDVu31/FKsYWFZgv4NipsMP7nsROffuTp9/wFNkeyw8COhuBb4YdmVVFXI/CCB5WAz xv2w== X-Gm-Message-State: AMCzsaW5UDqfKfG8XRvfVV7on6GPxEwU1AQCgjJCwkLftYx2JpDsQ8B+ r8miDjvlM/vRjY4Fk4TDVO+9J8H5 X-Google-Smtp-Source: ABhQp+QJLtnez1dv+uDToPPnRp2JMvjvIbxYEKzzhGvi4DBM35JYtmYgS3GzUQzsBh4hq7VCP3lqrQ== X-Received: by 10.55.125.196 with SMTP id y187mr9611463qkc.180.1508536270785; Fri, 20 Oct 2017 14:51:10 -0700 (PDT) Received: from localhost.localdomain (189-19-125-192.dsl.telesp.net.br. [189.19.125.192]) by smtp.gmail.com with ESMTPSA id j4sm1167039qkf.75.2017.10.20.14.51.08 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 20 Oct 2017 14:51:10 -0700 (PDT) From: Gustavo Padovan To: linux-media@vger.kernel.org Cc: Hans Verkuil , Mauro Carvalho Chehab , Shuah Khan , Pawel Osciak , Alexandre Courbot , Sakari Ailus , Brian Starkey , linux-kernel@vger.kernel.org, Gustavo Padovan Subject: [RFC v4 15/17] [media] vb2: add infrastructure to support out-fences Date: Fri, 20 Oct 2017 19:50:10 -0200 Message-Id: <20171020215012.20646-16-gustavo@padovan.org> X-Mailer: git-send-email 2.13.6 In-Reply-To: <20171020215012.20646-1-gustavo@padovan.org> References: <20171020215012.20646-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 Add vb2_setup_out_fence() and the needed members to struct vb2_buffer. v2: - change it to reflect fd_install at DQEVENT - add fence context for out-fences Signed-off-by: Gustavo Padovan --- drivers/media/v4l2-core/videobuf2-core.c | 31 +++++++++++++++++++++++++++++++ include/media/videobuf2-core.h | 20 ++++++++++++++++++++ 2 files changed, 51 insertions(+) diff --git a/drivers/media/v4l2-core/videobuf2-core.c b/drivers/media/v4l2-core/videobuf2-core.c index 78f369dba3e3..c7ba67bda5ac 100644 --- a/drivers/media/v4l2-core/videobuf2-core.c +++ b/drivers/media/v4l2-core/videobuf2-core.c @@ -23,8 +23,11 @@ #include #include #include +#include +#include #include +#include #include #include @@ -1316,6 +1319,34 @@ int vb2_core_prepare_buf(struct vb2_queue *q, unsigned int index, void *pb) } EXPORT_SYMBOL_GPL(vb2_core_prepare_buf); +int vb2_setup_out_fence(struct vb2_queue *q, unsigned int index) +{ + struct vb2_buffer *vb; + struct dma_fence *fence; + + vb = q->bufs[index]; + + vb->out_fence_fd = get_unused_fd_flags(O_CLOEXEC); + + fence = vb2_fence_alloc(q->out_fence_context); + if (!fence) { + put_unused_fd(vb->out_fence_fd); + return -ENOMEM; + } + + vb->sync_file = sync_file_create(fence); + if (!vb->sync_file) { + dma_fence_put(fence); + put_unused_fd(vb->out_fence_fd); + return -ENOMEM; + } + + vb->out_fence = dma_fence_get(fence); + + return 0; +} +EXPORT_SYMBOL_GPL(vb2_setup_out_fence); + /** * vb2_start_streaming() - Attempt to start streaming. * @q: videobuf2 queue diff --git a/include/media/videobuf2-core.h b/include/media/videobuf2-core.h index 624ca2dce9ea..1925ede73804 100644 --- a/include/media/videobuf2-core.h +++ b/include/media/videobuf2-core.h @@ -259,6 +259,10 @@ struct vb2_buffer { * using the buffer (queueing to the driver) * fence_cb: fence callback information * fence_cb_lock: protect callback signal/remove + * out_fence_fd: the out_fence_fd to be shared with userspace. + * out_fence: the out-fence associated with the buffer once + * it is queued to the driver. + * sync_file: the sync file to wrap the out fence */ enum vb2_buffer_state state; @@ -269,6 +273,10 @@ struct vb2_buffer { struct dma_fence_cb fence_cb; spinlock_t fence_cb_lock; + int out_fence_fd; + struct dma_fence *out_fence; + struct sync_file *sync_file; + #ifdef CONFIG_VIDEO_ADV_DEBUG /* * Counters for how often these buffer-related ops are @@ -518,6 +526,7 @@ struct vb2_buf_ops { * @ordered_in_vb2: set by the driver to tell vb2 te guarantee the order * of buffer queue from userspace with QBUF() until they are * queued to the driver. + * @out_fence_context: the fence context for the out fences * @last_fence: last in-fence received. Used to keep ordering. * @fileio: file io emulator internal data, used only if emulator is active * @threadio: thread io internal data, used only if thread is active @@ -574,6 +583,7 @@ struct vb2_queue { unsigned int ordered_in_driver:1; unsigned int ordered_in_vb2:1; + u64 out_fence_context; struct dma_fence *last_fence; struct vb2_fileio_data *fileio; @@ -745,6 +755,16 @@ int vb2_core_create_bufs(struct vb2_queue *q, enum vb2_memory memory, int vb2_core_prepare_buf(struct vb2_queue *q, unsigned int index, void *pb); /** + * vb2_setup_out_fence() - setup new out-fence + * @q: The vb2_queue where to setup it + * @index: index of the buffer + * + * Setup the file descriptor, the fence and the sync_file for the next + * buffer to be queued and add everything to the tail of the q->out_fence_list. + */ +int vb2_setup_out_fence(struct vb2_queue *q, unsigned int index); + +/** * vb2_core_qbuf() - Queue a buffer from userspace * * @q: videobuf2 queue