From patchwork Mon Nov 29 16:13:36 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vedant Paranjape X-Patchwork-Id: 14849 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 096E1BF415 for ; Mon, 29 Nov 2021 16:14:25 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 2ECC2605A4; Mon, 29 Nov 2021 17:14: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="Uj7uubmS"; dkim-atps=neutral Received: from mail-pj1-x102b.google.com (mail-pj1-x102b.google.com [IPv6:2607:f8b0:4864:20::102b]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 7D13860592 for ; Mon, 29 Nov 2021 17:14:23 +0100 (CET) Received: by mail-pj1-x102b.google.com with SMTP id o6-20020a17090a0a0600b001a64b9a11aeso14643304pjo.3 for ; Mon, 29 Nov 2021 08:14: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=vbDv8gqwB80fRZtvOL3n45EDyJArTKuosRQKZ2mPm0M=; b=Uj7uubmS5EaHyNvAn5mlT9EI9jqWyv8jB6uHKLN0BPRk98sUjW/lfx1AIhWF1oRYWs dLi26Qfsjj1NJAoCCgsS3hCq2nyid+y/ziyJbtScb/TnS1RuCsLoxVAXLQmLk1Gxdwqy WUTQ22ljfCNfSvXi50rEc4F5E1AzsEzS9H6h9BpCa03Gj69s7sxzBmbF7yF8GjUG9jFh aBsotwu6mLDcJwDHJIH0z06itGddREeLjyPO7i1fX0pOkfGGbLWlaN/kroKqEplPTom3 uVHB7poLiJ+RVnLeAOj2chZqHEw/KZQHzwxN6+v7usSuPYa0sq1wQHfcBHj7Wv3o2ATg /UvQ== 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=vbDv8gqwB80fRZtvOL3n45EDyJArTKuosRQKZ2mPm0M=; b=nWjNtWstZ1F4wuYtgONadFPp2yclFgWMBnpBJv1W+77pWXkfP/yw845oAmaaQ2tWnF 6LoHp8yYD4mvZUFO+0N9E0coO6uvafYWj7SXht5fZvy9TEwZr68ydS6dxKTk6Mk7K88r nLzp0Xg/irV5PWACjKGb3eRHNOeFLQX1wHBBPmwAqLnzTahCy+8ZwjRxzM1hLfb7mDQx QZxGv2MtQaXpr8wB0hInULGjta4sBs07Pp+aM1kldgphPYXb3EMjJ3F5dS5j0a5p5S+u 4/jBNBc7rbDZZl57ukM7dgY/hno3lK4xaieSRsHVPfiCgw5MpUmMl5pnomAlpNALHeH1 elyQ== X-Gm-Message-State: AOAM532BlXQNc5w3ZiE0teiN3tLbASoX8+CxlMYAqxXbsrkMYSaJJpyC wDiRemjS+rY0VUOCn9JoWaNiswSitqc0iA== X-Google-Smtp-Source: ABdhPJxdkwSaN5QDpnLKbdxJhjMR0jSpjLXVyXYWoVeBpwAuabpvtY37dEPyoD+f6TErpE61Kfdqrw== X-Received: by 2002:a17:902:bd06:b0:143:aa76:faf0 with SMTP id p6-20020a170902bd0600b00143aa76faf0mr59842913pls.88.1638202461550; Mon, 29 Nov 2021 08:14:21 -0800 (PST) Received: from localhost.localdomain ([1.186.167.22]) by smtp.googlemail.com with ESMTPSA id c81sm17194086pfb.166.2021.11.29.08.14.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Nov 2021 08:14:21 -0800 (PST) From: Vedant Paranjape To: libcamera-devel@lists.libcamera.org Date: Mon, 29 Nov 2021 21:43:36 +0530 Message-Id: <20211129161336.1113408-1-vedantparanjape160201@gmail.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3] 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 Reviewed-by: Laurent Pinchart Reviewed-by: Paul Elder --- 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 3610e63cade3..f194e06345b7 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).fd(), + 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), &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);