From patchwork Tue Jan 11 20:11:02 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vedant Paranjape X-Patchwork-Id: 15272 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 844C7BE080 for ; Tue, 11 Jan 2022 20:11:25 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id BDE97604F8; Tue, 11 Jan 2022 21:11:24 +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="cdG6sFUt"; dkim-atps=neutral Received: from mail-pl1-x62a.google.com (mail-pl1-x62a.google.com [IPv6:2607:f8b0:4864:20::62a]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 2AF8160217 for ; Tue, 11 Jan 2022 21:11:23 +0100 (CET) Received: by mail-pl1-x62a.google.com with SMTP id i6so601373pla.0 for ; Tue, 11 Jan 2022 12:11:23 -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=Anol0dhec9GwRQHBWXA/skFjGLIQpDGigQMRg9HrSxU=; b=cdG6sFUtGkCN3n7CCWZSimI5kWvWI6X6D7mv3/IWMMTJfGTCOBQFpp/SUqOJcVLoeb 1YOILM3XtfpD879AYXOydbhmjpHjopeIf3W1+Kq138m95SqAGp/25uI4MU/bxTSFXFmb zibpMRLboeP8q/KWSkcuEAgeD3m0ap0qdk4T8TDKRF9OiNnVGMDdrTRh6yQTofnlZiB4 24nFy2FvXZU8HDfFaMZbIoF6wIs0oEwB8UFMvppk4Xbbqbk392x5xFRpBJfNJU8Xzx4P FpCsA4dIAk3bD1q2RPJVTvddYAxCaPrbS4ioXBx6nLuf90ndfwjQqBz9jmuKe/3bk6+1 IW+g== 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=Anol0dhec9GwRQHBWXA/skFjGLIQpDGigQMRg9HrSxU=; b=Sc1TxaNIHKcSaU6zfZ58KSbwbmH8hKUp9sSrWZoz1xtTQrvnB2TyAU8hiZAZ9akwX5 JFeXJbx1pe+7wrv/wfNq2wz2wi/2y2F8ZN4MxLOAxpOZT8UDnxXq2c/H/zF0JRBOWn8p Ms2nCJSC9L2pKaisjTd/UWLze0H0OpCsEIDK2A+Emvvaz/Nxe89sNGuAD8KIFDN4Dd9C dVT9b61Gak7jNgMpmFTqpzqC1AusQVrr5oekbbEPaysRPp9VXIMWLwtTRfz7iikuYdNI +IUSOxOrpebzK/aigT7RISGE15pHOoM0EOKsG+aok0AUHIs6Ebbu2JJwnWITHU2ohZak cnPA== X-Gm-Message-State: AOAM530Vj/Zo0Yf4/QOydYwKjwSvBwdfS+dv8aGJ0UU2VN4TXjUW0rJl Tt0G0VzXnQ37uoFlP8RzEag/0qNRKkE= X-Google-Smtp-Source: ABdhPJwIGp/rYbSHKnr7Q5MmR+bLWv94EIZbZ0lm9FP422NH5xqtdd2hXMFZUCtcdN47xKNTjGOQYQ== X-Received: by 2002:a17:902:8d91:b0:14a:486a:ac7 with SMTP id v17-20020a1709028d9100b0014a486a0ac7mr6136760plo.101.1641931881342; Tue, 11 Jan 2022 12:11:21 -0800 (PST) Received: from veware.localdomain ([1.186.165.49]) by smtp.googlemail.com with ESMTPSA id d1sm174992pgd.66.2022.01.11.12.11.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Jan 2022 12:11:20 -0800 (PST) From: Vedant Paranjape To: libcamera-devel@lists.libcamera.org Date: Wed, 12 Jan 2022 01:41:02 +0530 Message-Id: <20220111201102.58256-1-vedantparanjape160201@gmail.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2] 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 --- src/v4l2/v4l2_camera_proxy.cpp | 32 ++++++++++++++++++++++++++++++++ src/v4l2/v4l2_camera_proxy.h | 1 + 2 files changed, 33 insertions(+) diff --git a/src/v4l2/v4l2_camera_proxy.cpp b/src/v4l2/v4l2_camera_proxy.cpp index 4d529bc29a4d..695af5be5c69 100644 --- a/src/v4l2/v4l2_camera_proxy.cpp +++ b/src/v4l2/v4l2_camera_proxy.cpp @@ -544,6 +544,37 @@ 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) << "Servicing vidioc_prepare_buf, index = " + << arg->index << " fd = " << file->efd(); + + 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) << "Servicing vidioc_qbuf, index = " @@ -709,6 +740,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 14e027c3e7d1..6baba94262a9 100644 --- a/src/v4l2/v4l2_camera_proxy.h +++ b/src/v4l2/v4l2_camera_proxy.h @@ -57,6 +57,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);