From patchwork Sun Nov 28 06:15:56 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vedant Paranjape X-Patchwork-Id: 14814 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 C4D70BF415 for ; Sun, 28 Nov 2021 06:16:37 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id E40326057B; Sun, 28 Nov 2021 07:16:36 +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="BBWeztDL"; dkim-atps=neutral Received: from mail-pj1-x102d.google.com (mail-pj1-x102d.google.com [IPv6:2607:f8b0:4864:20::102d]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 4D1FF6011B for ; Sun, 28 Nov 2021 07:16:35 +0100 (CET) Received: by mail-pj1-x102d.google.com with SMTP id fv9-20020a17090b0e8900b001a6a5ab1392so11146789pjb.1 for ; Sat, 27 Nov 2021 22:16:35 -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=Zt315uIxDO+Gv3HAdxjm813NXGUd6JBOBj3KBlV8D7A=; b=BBWeztDLtueTEgkOi7kCGrFxolQUhRjS/Q4j3QgpIn7DPKReyOAPAdNE0qb57Fk3M+ Qg3Qf2jgM+Fprzcunp9VO4vkcgAGvKhcSjmexa1KaIJi6cVrFkIzgeELd9ufnX+JgDJI jyXCM9ZwFibpHhf5n41JXQRcEcNNZZycl2z4o18NBVk980SRKlGPYtIB1zHvMfJsqkNY lApjWj/avciGYXXZYZdLazHM3ER8/vv0CB+fK2H+N3C+7Dbe8CNoyKXDEshaA5RpqJAy NDsyzsGtsqC8txjQsKkg0WqIgrhBUf0CizpUIHGEVmnHPtzEZ7p6g+uEOUeP52dGVccg aSZQ== 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=Zt315uIxDO+Gv3HAdxjm813NXGUd6JBOBj3KBlV8D7A=; b=MkZCFPQagkqPSDFOFtm8dL8blE2MMNjwieTGJJgb15JOgvDvlEstvjNnia9uxrgQVh 3/vApASnFT3y4w02OlwBqRiMXhyeMEBu7OZE14OW/J4tUX9Cfs7uYmoH9pRa3qLtdUiE /yO93SJUEXcz3SRNemG3rogzkjgXPG1Vc7BXJD3H4MiyAfLYLwt00F1xzsL5cLaEwewG vSVNANxpZZnHkOXKPIYMJNUCRLRWsam3NY5bLTTIvLGK+Fvok29z2J/1WT9fwgLaWkQ6 yLlx5tdSWKsQLTA111jYzZIRTdrSS6puKgYw5orAzELXL2Nhfrxf/23KPHfhlkUKQTAr 6n5A== X-Gm-Message-State: AOAM532Z1CO8Rh++zi1FC1DBihWzqmCc7w0suD7ewMgoAf6md9Ou9CPX PS51g1M5fWUsRWe1DBhZvIEyP9Yaz7+AYQ== X-Google-Smtp-Source: ABdhPJxqC9aol2cTUP9bxPLs2ihZndI6pBkDVN2/kz/EfDvg1aDftA4P8NfQmtLpHXM9l/r5nQIhJw== X-Received: by 2002:a17:902:860b:b0:143:87bf:648f with SMTP id f11-20020a170902860b00b0014387bf648fmr51083487plo.11.1638080193109; Sat, 27 Nov 2021 22:16:33 -0800 (PST) Received: from localhost.localdomain ([1.186.167.22]) by smtp.googlemail.com with ESMTPSA id s4sm2731745pgj.4.2021.11.27.22.16.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 27 Nov 2021 22:16:32 -0800 (PST) From: Vedant Paranjape To: libcamera-devel@lists.libcamera.org Date: Sun, 28 Nov 2021 11:45:56 +0530 Message-Id: <20211128061556.503443-1-vedantparanjape160201@gmail.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2] v4l2: V4L2CameraProxy: Add EXPBUF 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" To support DMABUF as one of the memory buffer, we need to implement EXPBUF in the v4l2 compat layer. This patch implements vidioc_expbuf as one of the supported ioctls. Bug: https://bugs.libcamera.org/show_bug.cgi?id=89 Signed-off-by: Vedant Paranjape --- src/v4l2/v4l2_camera_proxy.cpp | 37 ++++++++++++++++++++++++++++++++++ src/v4l2/v4l2_camera_proxy.h | 1 + 2 files changed, 38 insertions(+) diff --git a/src/v4l2/v4l2_camera_proxy.cpp b/src/v4l2/v4l2_camera_proxy.cpp index 3610e63cade3..cb2f93631ab9 100644 --- a/src/v4l2/v4l2_camera_proxy.cpp +++ b/src/v4l2/v4l2_camera_proxy.cpp @@ -624,6 +624,39 @@ int V4L2CameraProxy::vidioc_dqbuf(V4L2CameraFile *file, struct v4l2_buffer *arg, return 0; } +int V4L2CameraProxy::vidioc_expbuf(V4L2CameraFile *file, struct v4l2_exportbuffer *arg) +{ + LOG(V4L2Compat, Debug) << "Servicing vidioc_expbuf fd = " << file->efd(); + + if (!hasOwnership(file)) + return -EBUSY; + + /* \todo Verify that the memory type is MMAP when adding DMABUF support */ + if (!validateBufferType(arg->type)) + return -EINVAL; + + if (arg->index >= bufferCount_) + return -EINVAL; + + if (arg->flags & ~(O_CLOEXEC | O_ACCMODE)) + return -EINVAL; + + LOG(V4L2Compat, Debug) << arg->index << " : index of the buffer"; + + if (file->priority() < maxPriority()) + return -EBUSY; + + memset(arg->reserved, 0, sizeof(arg->reserved)); + + arg->fd = fcntl(buffers_[arg->index].m.fd, + arg->flags & O_CLOEXEC ? F_DUPFD_CLOEXEC : F_DUPFD, 0); + arg->fd = fcntl(arg->fd, F_SETFL, 0); + + LOG(V4L2Compat, Debug) << "Exported buffer at index: " << arg->index; + + return 0; +} + int V4L2CameraProxy::vidioc_streamon(V4L2CameraFile *file, int *arg) { LOG(V4L2Compat, Debug) << "Servicing vidioc_streamon fd = " << file->efd(); @@ -685,6 +718,7 @@ const std::set V4L2CameraProxy::supportedIoctls_ = { VIDIOC_QUERYBUF, VIDIOC_QBUF, VIDIOC_DQBUF, + VIDIOC_EXPBUF, VIDIOC_STREAMON, VIDIOC_STREAMOFF, }; @@ -755,6 +789,9 @@ int V4L2CameraProxy::ioctl(V4L2CameraFile *file, unsigned long request, void *ar case VIDIOC_DQBUF: ret = vidioc_dqbuf(file, static_cast(arg), &locker); break; + case VIDIOC_EXPBUF: + ret = vidioc_expbuf(file, static_cast(arg)); + break; case VIDIOC_STREAMON: ret = vidioc_streamon(file, static_cast(arg)); break; diff --git a/src/v4l2/v4l2_camera_proxy.h b/src/v4l2/v4l2_camera_proxy.h index fccec241879d..81ef7788e9fe 100644 --- a/src/v4l2/v4l2_camera_proxy.h +++ b/src/v4l2/v4l2_camera_proxy.h @@ -58,6 +58,7 @@ private: int vidioc_qbuf(V4L2CameraFile *file, struct v4l2_buffer *arg); int vidioc_dqbuf(V4L2CameraFile *file, struct v4l2_buffer *arg, libcamera::MutexLocker *locker); + int vidioc_expbuf(V4L2CameraFile *file, struct v4l2_exportbuffer *arg); int vidioc_streamon(V4L2CameraFile *file, int *arg); int vidioc_streamoff(V4L2CameraFile *file, int *arg);