From patchwork Wed Jan 19 05:55:12 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vedant Paranjape X-Patchwork-Id: 15288 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 79791BF415 for ; Wed, 19 Jan 2022 05:55:34 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 8571960944; Wed, 19 Jan 2022 06:55:33 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="LtLO7VnX"; dkim-atps=neutral Received: from mail-pf1-x42a.google.com (mail-pf1-x42a.google.com [IPv6:2607:f8b0:4864:20::42a]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 5AC1C6017D for ; Wed, 19 Jan 2022 06:55:32 +0100 (CET) Received: by mail-pf1-x42a.google.com with SMTP id w204so1564865pfc.7 for ; Tue, 18 Jan 2022 21:55:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=OYMO8G+/b4muA9FspyJl9PuJNrV8eSBIqDQLWfSQzWo=; b=LtLO7VnX1tOILRFY9u58ve6yEEqMFfVgyD3p2bFYYRflDPnBV7g0pqZo79g+CyT0XU 13bK5xbaZ1yF168ccylAjgUYoD1NqNl34EfMxMM01JUp746p0corQfnKb6951xk4Wzoj WfQZ/EkCiM2ygSACQpzKXD7pp7Ni9SSVA3zW0pQWuNh0GLpv1U8VdHuo7IwYqK7EBD1W C71OssZPJsMiz+LLYqz59YgvGI/AzWjaNwIfE2CXybheE3ulLPBsxAfLYOJ2vhVLx8C8 FFy6EfuGo2XEEeuHveCyXOr9aTQ9VAMfggXL4w9X081W9i05n51QgrfeKceO+Mn9XtS7 VtrQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=OYMO8G+/b4muA9FspyJl9PuJNrV8eSBIqDQLWfSQzWo=; b=NhBj1uo5e7VegVhczpi/rdFfwiOSLSEPemRe5FB8+DfrO3A9R+UlQ03IhnRu0DV1ro DeAgIuKdI94h2uWnAU/BhzA424X1MBOYDRZS01+RIR16j6UwVsaqfgkPX4diB+vk4FHb pN9WaDW3ZCOGXouNpfEGjTw51bfydl1BldzODnHMiveCHDFGaidQgToX46uc1sS7lmS+ n9Mb+9dzBFII8OqUoZz/Lrkjx/Jq6VccZJBUYfsqH4HXFTmpzhIsMAgU8DogpDstH83T 4TpCME1cusbgDj9fzfnZETRV/0R2wvvbAyu90995MRnUdp0jtsFghlUSHA3Vo8GYL5Eh V9ZA== X-Gm-Message-State: AOAM531eIELVRQj9Dq8LuPLKvkyafYh2+9F2QT6hK9t1Wki+yd9wisW0 ODVy/JPj7P6R+sHsf/KSSF5yNyOOEeAIs6ST X-Google-Smtp-Source: ABdhPJxfOyE/oq7+FD+WCk7vuA/2Ys/ci+oWcuOy4ERzrC/hyERXfQr1WoKKv7NcWqkUOb9RJh34UA== X-Received: by 2002:a62:7997:0:b0:4bf:508a:2f78 with SMTP id u145-20020a627997000000b004bf508a2f78mr29424954pfc.16.1642571730466; Tue, 18 Jan 2022 21:55:30 -0800 (PST) Received: from veware.localdomain ([1.186.167.236]) by smtp.googlemail.com with ESMTPSA id o64sm18719215pfb.27.2022.01.18.21.55.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Jan 2022 21:55:30 -0800 (PST) From: Vedant Paranjape To: libcamera-devel@lists.libcamera.org Date: Wed, 19 Jan 2022 11:25:12 +0530 Message-Id: <20220119055512.31893-1-vedantparanjape160201@gmail.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3] v4l2: V4L2CameraProxy: Add support for PREPARE_BUF as one of the supported ioctl X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Vedant Paranjape Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Add support for PREPARE_BUF as one of the ioctl. Since this is a compat layer, there doesn't seem to be an equivalent to the "transfer ownership of the buffer to kernel driver" in V4L2Camera class. To match the error checks done by kernel implementation, we'd have to check if dmabuf fd is valid and that the buffer size is large enough. Doing so will not add any particular value to the program as applications most likely don't depend on these conditions being handled correctly. Signed-off-by: Vedant Paranjape Reviewed-by: Laurent Pinchart Reviewed-by: Laurent Pinchart --- src/v4l2/v4l2_camera_proxy.cpp | 35 +++++++++++++++++++++++++++++++++- src/v4l2/v4l2_camera_proxy.h | 1 + 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/src/v4l2/v4l2_camera_proxy.cpp b/src/v4l2/v4l2_camera_proxy.cpp index ec6daac605fb..f3470a6d312a 100644 --- a/src/v4l2/v4l2_camera_proxy.cpp +++ b/src/v4l2/v4l2_camera_proxy.cpp @@ -559,6 +559,38 @@ int V4L2CameraProxy::vidioc_querybuf(V4L2CameraFile *file, struct v4l2_buffer *a return 0; } +int V4L2CameraProxy::vidioc_prepare_buf(V4L2CameraFile *file, struct v4l2_buffer *arg) +{ + LOG(V4L2Compat, Debug) + << "[" << file->description() << "] " << __func__ + << "(index=" << arg->index << ")"; + + if (!hasOwnership(file)) + return -EBUSY; + + if (arg->index >= bufferCount_) + return -EINVAL; + + if (arg->flags & V4L2_BUF_FLAG_REQUEST_FD) + return -EINVAL; + + if (!validateBufferType(arg->type) || + !validateMemoryType(arg->memory)) + return -EINVAL; + + struct v4l2_buffer &buffer = buffers_[arg->index]; + + if (buffer.flags & V4L2_BUF_FLAG_QUEUED || + buffer.flags & V4L2_BUF_FLAG_PREPARED) + return -EINVAL; + + buffer.flags |= V4L2_BUF_FLAG_PREPARED; + + arg->flags = buffer.flags; + + return 0; +} + int V4L2CameraProxy::vidioc_qbuf(V4L2CameraFile *file, struct v4l2_buffer *arg) { LOG(V4L2Compat, Debug) @@ -627,7 +659,7 @@ int V4L2CameraProxy::vidioc_dqbuf(V4L2CameraFile *file, struct v4l2_buffer *arg, struct v4l2_buffer &buf = buffers_[currentBuf_]; - buf.flags &= ~(V4L2_BUF_FLAG_QUEUED | V4L2_BUF_FLAG_DONE); + buf.flags &= ~(V4L2_BUF_FLAG_QUEUED | V4L2_BUF_FLAG_DONE | V4L2_BUF_FLAG_PREPARED); buf.length = sizeimage_; *arg = buf; @@ -729,6 +761,7 @@ const std::set V4L2CameraProxy::supportedIoctls_ = { VIDIOC_S_INPUT, VIDIOC_REQBUFS, VIDIOC_QUERYBUF, + VIDIOC_PREPARE_BUF, VIDIOC_QBUF, VIDIOC_DQBUF, VIDIOC_EXPBUF, diff --git a/src/v4l2/v4l2_camera_proxy.h b/src/v4l2/v4l2_camera_proxy.h index a38b28c744d3..76ca2d8a5558 100644 --- a/src/v4l2/v4l2_camera_proxy.h +++ b/src/v4l2/v4l2_camera_proxy.h @@ -58,6 +58,7 @@ private: int vidioc_s_input(V4L2CameraFile *file, int *arg); int vidioc_reqbufs(V4L2CameraFile *file, struct v4l2_requestbuffers *arg); int vidioc_querybuf(V4L2CameraFile *file, struct v4l2_buffer *arg); + int vidioc_prepare_buf(V4L2CameraFile *file, struct v4l2_buffer *arg); int vidioc_qbuf(V4L2CameraFile *file, struct v4l2_buffer *arg); int vidioc_dqbuf(V4L2CameraFile *file, struct v4l2_buffer *arg, libcamera::Mutex *lock) LIBCAMERA_TSA_REQUIRES(*lock);