From patchwork Tue Jan 11 16:33:29 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vedant Paranjape X-Patchwork-Id: 15271 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 9AF69BE080 for ; Tue, 11 Jan 2022 16:33:56 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id E6B8D604F4; Tue, 11 Jan 2022 17:33:55 +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="h5Yn6891"; dkim-atps=neutral Received: from mail-pj1-x1031.google.com (mail-pj1-x1031.google.com [IPv6:2607:f8b0:4864:20::1031]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 3B0EA60217 for ; Tue, 11 Jan 2022 17:33:53 +0100 (CET) Received: by mail-pj1-x1031.google.com with SMTP id b1-20020a17090a990100b001b14bd47532so6902460pjp.0 for ; Tue, 11 Jan 2022 08:33:53 -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=mGUeGq6evKHForXYdo1fcUpl5aq6IRP3aa3nfI63WWY=; b=h5Yn6891rynMAlbExaYGha9+YjRVlbYfJiWt6KUENBP3sWJdp4jRYGLg47KvdlM6M6 jBwQOMSeDPSy5b+F4upQdCXQ+JVGrQn/0XhL5fjOVew/dOixfI829+/6CPgT0Vx5preS CJ6vUG7IZlRS0HnHcwZPc9ti7wKFHjwV+O12WqcyfOcjSqRdF7/eiwONotvyUPE3n6qs +f0lqOheveg7bmjEm7U+OqLmAOj1+j33J/No1T1jc+pc7Pxh2xkGpdj76Y5bixJopmyp e55wGdYBtn7JEHYWQzm7SREVy6A1Zctx2Rh0cSHEou+w135uJfAEr+rzs0gd17HQECZP rrDg== 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=mGUeGq6evKHForXYdo1fcUpl5aq6IRP3aa3nfI63WWY=; b=xIHLakLGb1cwn7gk+egFCqgcFy0z3gpJx2Dc2JyK0Pm8Z6/kPLHX/ejBJhhkMumUNs ChG3AeypgJl1O5M22TVq7AyKY02qCEFXCSSgjoZJAnDADyhC3c9wvrDvrDYT4IKr7DQJ uVmR96c+uhdB4KIpUn8VbQOAEcvYMOGG/VFrPxn5qip4Gusq0KCvFg4aDO7KkHPml+Ex 4vqarlu4wf3c0OyWfG9JsrIbGk7ywNlHQ035udEuIewifTJIfRN3NZoEKyNV+mkwiRHj YzEBLp1B8zvq57LciWsKNt+lDaQO0LrkUi/YnjKYjL/wPTdslEBAqfrPnibqMfzZcPZj oeEw== X-Gm-Message-State: AOAM533C8szA2djqKugUZhFnwekM6sMrAnQ2kNUskUWVgO0ovWZ3BRdK auDHUQWJSEAK6dmvk1t/quHg59PgIiw= X-Google-Smtp-Source: ABdhPJxK3xrBKjzuCIw5wBv+E9h37zCY8CGd+Y4hu54FjrItmVOm7VduggNpQ/S0XpwkCC8WxFSBUg== X-Received: by 2002:a17:902:e741:b0:14a:5a65:dcdb with SMTP id p1-20020a170902e74100b0014a5a65dcdbmr2173891plf.135.1641918831365; Tue, 11 Jan 2022 08:33:51 -0800 (PST) Received: from veware.localdomain ([1.186.165.49]) by smtp.googlemail.com with ESMTPSA id k9sm8791062pgr.47.2022.01.11.08.33.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Jan 2022 08:33:51 -0800 (PST) From: Vedant Paranjape To: libcamera-devel@lists.libcamera.org Date: Tue, 11 Jan 2022 22:03:29 +0530 Message-Id: <20220111163329.363418-1-vedantparanjape160201@gmail.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v1] 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 don't depend on these conditions being handled correctly. Signed-off-by: Vedant Paranjape Reviewed-by: Laurent Pinchart --- Source builds and tests fine, also passes the v4l2-compliance vedant@pc ~/libcamera$ ./test/v4l2_compat/v4l2_compat_test.py ./build/src/v4l2/v4l2-compat.so Testing /dev/video0 with uvcvideo driver... success Still figuring out how to test this with v4l2-ctl, if you have hints please let me know :) --- src/v4l2/v4l2_camera_proxy.cpp | 28 ++++++++++++++++++++++++++++ src/v4l2/v4l2_camera_proxy.h | 1 + 2 files changed, 29 insertions(+) diff --git a/src/v4l2/v4l2_camera_proxy.cpp b/src/v4l2/v4l2_camera_proxy.cpp index 4d529bc29a4d..8c28e8738a06 100644 --- a/src/v4l2/v4l2_camera_proxy.cpp +++ b/src/v4l2/v4l2_camera_proxy.cpp @@ -544,6 +544,33 @@ 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 (buffers_[arg->index].flags & V4L2_BUF_FLAG_REQUEST_FD || + buffers_[arg->index].flags & V4L2_BUF_FLAG_PREPARED) + return -EINVAL; + + if (buffers_[arg->index].flags & V4L2_BUF_FLAG_QUEUED || + !validateBufferType(arg->type) || + !validateMemoryType(arg->memory)) + return -EINVAL; + + buffers_[arg->index].flags |= V4L2_BUF_FLAG_PREPARED; + + arg->flags = buffers_[arg->index].flags; + + return 0; +} + int V4L2CameraProxy::vidioc_qbuf(V4L2CameraFile *file, struct v4l2_buffer *arg) { LOG(V4L2Compat, Debug) << "Servicing vidioc_qbuf, index = " @@ -709,6 +736,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);