From patchwork Tue Dec 28 18:50:14 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vedant Paranjape X-Patchwork-Id: 15225 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 EC331BE080 for ; Tue, 28 Dec 2021 18:50:41 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 48CC46090D; Tue, 28 Dec 2021 19:50:41 +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="Jgsm5pnD"; dkim-atps=neutral Received: from mail-pf1-x429.google.com (mail-pf1-x429.google.com [IPv6:2607:f8b0:4864:20::429]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 1FF6360868 for ; Tue, 28 Dec 2021 19:50:39 +0100 (CET) Received: by mail-pf1-x429.google.com with SMTP id v13so16899315pfi.3 for ; Tue, 28 Dec 2021 10:50:39 -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=tLP0XldOg1Bw18eM0riUCiEGfSJEojf/dBbJZeRVWMM=; b=Jgsm5pnD1Qz+IVkTHfNU1y8BdBudmAys6Qq4+vMEhUmyE7GjnKwgk3tyv4n/yq6rRI GyK5aNViJzNwj+uE9sghWU4hwJ27Bx1wcfX7nr27RVLLpTjlomw9jPJVjTtfohxOB0L0 KeMD1YFPx1/Y55907xAWt24n/Ygvt/bZyRDy3Q0WREA97Dfc34Q5JU4/aP8N0kOkEKO4 4I22k6FXGRbK/fBeznxmXWOgIIstaetnyAlzi7OLnpAi40RI4fcAnAlwHS6+5ec8sxhV TPkZRgfjhYaM8XQZQJN8HwDBp1TrAwLK9L3LH4ngPD6R1lFwzbL65PfY09eD9uXOSsWf 9wGg== 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=tLP0XldOg1Bw18eM0riUCiEGfSJEojf/dBbJZeRVWMM=; b=2VnupVVL1qLnXpKep5OxMaZ9qYttPU+bMWf1IAs+M9q9Tt3g73A06NynZYB6gxSU/G suSiwTUqaELwwlEdmDfuIBnb0Wv1n9LE3OSVsaViiGNdYEkhNwtofGh6y1SURxxyS8UN dICgklr9S6XxFKwznh+Fv4ZAtZBDt+FAxaZ7z4GrU18R9Y3cFvV2HmbftpQpHt7sEHbq sICTVVlQKvvck14Qk5bSqzl0D+drN3V2BeRUnaz89kXCheUQrUbfi8K+ZpZGvegBADDC vJeMQz11RHMMCymvgdz6BBzDh6xdBUdRZaO5lVK1woDfTzcrFKHjOiM6TJInnv0cjDZh ftuQ== X-Gm-Message-State: AOAM533Iqj1J+z4ExSQofX9kOUEfzPQl9eaJCUVnmay4aG0MV9QkKk+f MWcWfIF70wQ4GAe/lfx/5gpDfhiGOGg= X-Google-Smtp-Source: ABdhPJzrqerPyoXhbcvdKJEYIep//LWiJTMvjJucUvjil43dEyPxPjOLB7gJImzPlYLYMl1Z57z/Yg== X-Received: by 2002:a05:6a00:114d:b0:4a2:89e6:659e with SMTP id b13-20020a056a00114d00b004a289e6659emr23309219pfm.38.1640717437204; Tue, 28 Dec 2021 10:50:37 -0800 (PST) Received: from localhost.localdomain ([1.186.167.40]) by smtp.googlemail.com with ESMTPSA id y37sm17364303pga.78.2021.12.28.10.50.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Dec 2021 10:50:36 -0800 (PST) From: Vedant Paranjape To: libcamera-devel@lists.libcamera.org Date: Wed, 29 Dec 2021 00:20:14 +0530 Message-Id: <20211228185014.98895-1-vedantparanjape160201@gmail.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v4] 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 | 30 ++++++++++++++++++++++++++++++ src/v4l2/v4l2_camera_proxy.h | 1 + 2 files changed, 31 insertions(+) diff --git a/src/v4l2/v4l2_camera_proxy.cpp b/src/v4l2/v4l2_camera_proxy.cpp index c1375777c185..4d529bc29a4d 100644 --- a/src/v4l2/v4l2_camera_proxy.cpp +++ b/src/v4l2/v4l2_camera_proxy.cpp @@ -624,6 +624,32 @@ 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; + + memset(arg->reserved, 0, sizeof(arg->reserved)); + + /* \todo honor the O_ACCMODE flags passed to this function */ + arg->fd = fcntl(vcam_->getBufferFd(arg->index), + arg->flags & O_CLOEXEC ? F_DUPFD_CLOEXEC : F_DUPFD, 0); + + return 0; +} + int V4L2CameraProxy::vidioc_streamon(V4L2CameraFile *file, int *arg) { LOG(V4L2Compat, Debug) << "Servicing vidioc_streamon fd = " << file->efd(); @@ -685,6 +711,7 @@ const std::set V4L2CameraProxy::supportedIoctls_ = { VIDIOC_QUERYBUF, VIDIOC_QBUF, VIDIOC_DQBUF, + VIDIOC_EXPBUF, VIDIOC_STREAMON, VIDIOC_STREAMOFF, }; @@ -755,6 +782,9 @@ int V4L2CameraProxy::ioctl(V4L2CameraFile *file, unsigned long request, void *ar case VIDIOC_DQBUF: ret = vidioc_dqbuf(file, static_cast(arg), &proxyMutex_); 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 fa0a49e0439b..14e027c3e7d1 100644 --- a/src/v4l2/v4l2_camera_proxy.h +++ b/src/v4l2/v4l2_camera_proxy.h @@ -60,6 +60,7 @@ private: 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); + int vidioc_expbuf(V4L2CameraFile *file, struct v4l2_exportbuffer *arg); int vidioc_streamon(V4L2CameraFile *file, int *arg); int vidioc_streamoff(V4L2CameraFile *file, int *arg);