From: Janghyuck Kim Date: Fri, 23 Mar 2018 09:34:10 +0000 (+0900) Subject: [media] vb2: add explicit fence user API X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=47a545ff451e0f1da277b13b975a6a6bc432ed37;p=GitHub%2FLineageOS%2Fandroid_kernel_motorola_exynos9610.git [media] vb2: add explicit fence user API Turn the reserved2 field into fence_fd that we will use to send an in-fence to the kernel or 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. v6: - big improvement on doc (Hans Verkuil) v5: - keep using reserved2 field for cpia2 - set fence_fd to 0 for now, for compat with userspace(Mauro) 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 Change-Id: Ic52ac856718b716c0eda3cae983e32817f09991e Signed-off-by: Gustavo Padovan Signed-off-by: Janghyuck Kim --- diff --git a/Documentation/media/uapi/v4l/buffer.rst b/Documentation/media/uapi/v4l/buffer.rst index ae6ee73f151c..597bcc418df4 100644 --- a/Documentation/media/uapi/v4l/buffer.rst +++ b/Documentation/media/uapi/v4l/buffer.rst @@ -301,10 +301,22 @@ struct v4l2_buffer elements in the ``planes`` array. The driver will fill in the actual number of valid elements in that array. * - __u32 - - ``reserved2`` + - ``fence_fd`` - - - A place holder for future extensions. Drivers and applications - must set this to 0. + - Used to communicate fences file descriptors from userspace to kernel + and vice-versa. On :ref:`VIDIOC_QBUF ` when sending + an in-fence for V4L2 to wait on, the ``V4L2_BUF_FLAG_IN_FENCE`` flag must + be used and this field set to the fence file descriptor of the in-fence + If the in-fence is not valid ` VIDIOC_QBUF`` returns an error. + + To get an out-fence back from V4L2 the ``V4L2_BUF_FLAG_OUT_FENCE`` + must be set, the kernel will return the out-fence file descriptor on + this field. If it fails to create the out-fence ``VIDIOC_QBUF` returns + an error. + + In all other ioctls V4L2 sets this field to -1 if + ``V4L2_BUF_FLAG_IN_FENCE`` and/or ``V4L2_BUF_FLAG_OUT_FENCE`` are set, + otherwise this field is set to 0 for backward compatibility. * - __u32 - ``reserved`` - @@ -648,6 +660,33 @@ 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 the fence passed in the ``fence_fd`` field. The + buffer won't be queued to the driver until the fence signals. The order + in which buffers are queued is guaranteed to be preserved, so any + buffers queued after this buffer will also be blocked until this fence + signals. This flag must be set before calling ``VIDIOC_QBUF``. For + other ioctls the driver just report the value of the flag. + + If the fence signals the flag is cleared and not reported anymore. + If the fence is not valid ``VIDIOC_QBUF`` returns an error. + + + * .. _`V4L2-BUF-FLAG-OUT-FENCE`: + + - ``V4L2_BUF_FLAG_OUT_FENCE`` + - 0x00400000 + - Request for a fence to be attached to the buffer. The driver will fill + in the out-fence fd in the ``fence_fd`` field when :ref:`VIDIOC_QBUF + ` returns. This flag must be set before calling + ``VIDIOC_QBUF``. For other ioctls the driver just report the value of + the flag. + + If the creation of the out-fence fails ``VIDIOC_QBUF`` returns an + error. diff --git a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c index 3905c4277574..c717f265e4fe 100644 --- a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c +++ b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c @@ -388,7 +388,7 @@ struct v4l2_buffer32 { __s32 fd; } m; __u32 length; - __u32 reserved2; + __s32 fence_fd; __u32 reserved; }; @@ -607,7 +607,7 @@ static int put_v4l2_buffer32(struct v4l2_buffer __user *kp, assign_in_user(&up->timestamp.tv_usec, &kp->timestamp.tv_usec) || copy_in_user(&up->timecode, &kp->timecode, sizeof(kp->timecode)) || assign_in_user(&up->sequence, &kp->sequence) || - assign_in_user(&up->reserved2, &kp->reserved2) || + assign_in_user(&up->fence_fd, &kp->fence_fd) || assign_in_user(&up->reserved, &kp->reserved) || get_user(length, &kp->length) || put_user(length, &up->length)) diff --git a/include/uapi/linux/videodev2.h b/include/uapi/linux/videodev2.h index d1daba6178d9..ffd441711b35 100644 --- a/include/uapi/linux/videodev2.h +++ b/include/uapi/linux/videodev2.h @@ -925,7 +925,10 @@ struct v4l2_buffer { __s32 fd; } m; __u32 length; - __u32 reserved2; + union { + __s32 fence_fd; + __u32 reserved2; + }; __u32 reserved; }; @@ -962,6 +965,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