From patchwork Mon Dec 11 18:27:38 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gustavo Padovan X-Patchwork-Id: 10105671 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 64A7E60235 for ; Mon, 11 Dec 2017 18:29:34 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3701C297FF for ; Mon, 11 Dec 2017 18:29:34 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2B01229817; Mon, 11 Dec 2017 18:29:34 +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.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI 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 8412B297FF for ; Mon, 11 Dec 2017 18:29:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752386AbdLKS3Q (ORCPT ); Mon, 11 Dec 2017 13:29:16 -0500 Received: from mail-qt0-f194.google.com ([209.85.216.194]:38134 "EHLO mail-qt0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752576AbdLKS2G (ORCPT ); Mon, 11 Dec 2017 13:28:06 -0500 Received: by mail-qt0-f194.google.com with SMTP id d4so40965997qtj.5; Mon, 11 Dec 2017 10:28:06 -0800 (PST) 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=DW0OVU7Qck1pm/qEHKzN3go3xUkXf0B2H8aqI1EHnUw=; b=fw02ZN47p7+5PqplZ7PkcLI5YicE0SzFvPvz1M3IDZtHu1pH37rJKAH2Ix3Nn2Cg9h tqgE8Zl1P0IfXrBmsmIcVo2LxnhTaiI1mfveaLaezOP03dspOXmYEDE2mxQMtrKMbJXn 1gQJsuT0n8ulhlSmd4SI4JdMzeVIOMVHpEKzNBz5Bsic5H5mC04MmtGMZDB1xUZEkADL Ac0ovDek3suwTMf9zrvYjxKA1l2iSZ8TJo6RYruGwACvS4vHGpXfNp+D+VywgbjBz1bE /baMw32EuXyE0YERC86BzaKzxjgKS3hrAUPsQIKdu5hgBHU+0pppdzuo1DwzmzpBLdkh xjYA== X-Gm-Message-State: AKGB3mL5G80Gd7Tb4D0AJ92eumIi/5dT1YZpYh7+UNAiiL025+7J1PI1 +1F78Ozxdup3c9b4w4gTcVqosenp X-Google-Smtp-Source: ACJfBovRIvt2b11EvM63zRH4MTbY7DRcrLYxU81v3bjxXWXm6bUnibySNXMbhVr6VEX45yHnFgAkfw== X-Received: by 10.200.8.172 with SMTP id v41mr1761668qth.111.1513016885690; Mon, 11 Dec 2017 10:28:05 -0800 (PST) Received: from localhost.localdomain ([177.68.185.72]) by smtp.gmail.com with ESMTPSA id v129sm4547126qkd.42.2017.12.11.10.28.02 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 11 Dec 2017 10:28:05 -0800 (PST) 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 , Thierry Escande , linux-kernel@vger.kernel.org, Gustavo Padovan Subject: [PATCH v6 3/6] [media] vb2: add explicit fence user API Date: Mon, 11 Dec 2017 16:27:38 -0200 Message-Id: <20171211182741.29712-4-gustavo@padovan.org> X-Mailer: git-send-email 2.13.6 In-Reply-To: <20171211182741.29712-1-gustavo@padovan.org> References: <20171211182741.29712-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 Turn the reserved2 field into fence_fd that we will use to send an in-fence to the kernel and return an out-fence from the kernel to userspace. Two new flags were added, V4L2_BUF_FLAG_IN_FENCE, that should be used when sending a fence to the kernel to be waited on, and V4L2_BUF_FLAG_OUT_FENCE, to ask the kernel to give back an out-fence. v4: - make it a union with reserved2 and fence_fd (Hans Verkuil) v3: - make the out_fence refer to the current buffer (Hans Verkuil) v2: add documentation Signed-off-by: Gustavo Padovan --- Documentation/media/uapi/v4l/buffer.rst | 15 +++++++++++++++ drivers/media/usb/cpia2/cpia2_v4l.c | 2 +- drivers/media/v4l2-core/v4l2-compat-ioctl32.c | 4 ++-- drivers/media/v4l2-core/videobuf2-v4l2.c | 2 +- include/uapi/linux/videodev2.h | 7 ++++++- 5 files changed, 25 insertions(+), 5 deletions(-) diff --git a/Documentation/media/uapi/v4l/buffer.rst b/Documentation/media/uapi/v4l/buffer.rst index ae6ee73f151c..eeefbd2547e7 100644 --- a/Documentation/media/uapi/v4l/buffer.rst +++ b/Documentation/media/uapi/v4l/buffer.rst @@ -648,6 +648,21 @@ Buffer Flags - Start Of Exposure. The buffer timestamp has been taken when the exposure of the frame has begun. This is only valid for the ``V4L2_BUF_TYPE_VIDEO_CAPTURE`` buffer type. + * .. _`V4L2-BUF-FLAG-IN-FENCE`: + + - ``V4L2_BUF_FLAG_IN_FENCE`` + - 0x00200000 + - Ask V4L2 to wait on fence passed in ``fence_fd`` field. The buffer + won't be queued to the driver until the fence signals. + + * .. _`V4L2-BUF-FLAG-OUT-FENCE`: + + - ``V4L2_BUF_FLAG_OUT_FENCE`` + - 0x00400000 + - Request a fence to be attached to the buffer. The ``fence_fd`` + field on + :ref:`VIDIOC_QBUF` is used as a return argument to send the out-fence + fd to userspace. diff --git a/drivers/media/usb/cpia2/cpia2_v4l.c b/drivers/media/usb/cpia2/cpia2_v4l.c index a1c59f19cf2d..7d7459fa2077 100644 --- a/drivers/media/usb/cpia2/cpia2_v4l.c +++ b/drivers/media/usb/cpia2/cpia2_v4l.c @@ -948,7 +948,7 @@ static int cpia2_dqbuf(struct file *file, void *fh, struct v4l2_buffer *buf) buf->sequence = cam->buffers[buf->index].seq; buf->m.offset = cam->buffers[buf->index].data - cam->frame_buffer; buf->length = cam->frame_size; - buf->reserved2 = 0; + buf->fence_fd = -1; buf->reserved = 0; memset(&buf->timecode, 0, sizeof(buf->timecode)); diff --git a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c index 821f2aa299ae..3a31d318df2a 100644 --- a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c +++ b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c @@ -370,7 +370,7 @@ struct v4l2_buffer32 { __s32 fd; } m; __u32 length; - __u32 reserved2; + __s32 fence_fd; __u32 reserved; }; @@ -533,7 +533,7 @@ static int put_v4l2_buffer32(struct v4l2_buffer *kp, struct v4l2_buffer32 __user put_user(kp->timestamp.tv_usec, &up->timestamp.tv_usec) || copy_to_user(&up->timecode, &kp->timecode, sizeof(struct v4l2_timecode)) || put_user(kp->sequence, &up->sequence) || - put_user(kp->reserved2, &up->reserved2) || + put_user(kp->fence_fd, &up->fence_fd) || put_user(kp->reserved, &up->reserved) || put_user(kp->length, &up->length)) return -EFAULT; diff --git a/drivers/media/v4l2-core/videobuf2-v4l2.c b/drivers/media/v4l2-core/videobuf2-v4l2.c index 4075314a6989..4a5244ee2c58 100644 --- a/drivers/media/v4l2-core/videobuf2-v4l2.c +++ b/drivers/media/v4l2-core/videobuf2-v4l2.c @@ -203,7 +203,7 @@ 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->reserved2 = 0; + b->fence_fd = -1; b->reserved = 0; if (q->is_multiplanar) { diff --git a/include/uapi/linux/videodev2.h b/include/uapi/linux/videodev2.h index a8ea632c14f0..17e163b5036d 100644 --- a/include/uapi/linux/videodev2.h +++ b/include/uapi/linux/videodev2.h @@ -926,7 +926,10 @@ struct v4l2_buffer { __s32 fd; } m; __u32 length; - __u32 reserved2; + union { + __s32 fence_fd; + __u32 reserved2; + }; __u32 reserved; }; @@ -963,6 +966,8 @@ struct v4l2_buffer { #define V4L2_BUF_FLAG_TSTAMP_SRC_SOE 0x00010000 /* mem2mem encoder/decoder */ #define V4L2_BUF_FLAG_LAST 0x00100000 +#define V4L2_BUF_FLAG_IN_FENCE 0x00200000 +#define V4L2_BUF_FLAG_OUT_FENCE 0x00400000 /** * struct v4l2_exportbuffer - export of video buffer as DMABUF file descriptor