From patchwork Sat Nov 27 19:24:40 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vedant Paranjape X-Patchwork-Id: 14813 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 BE5DABF415 for ; Sat, 27 Nov 2021 19:25:21 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id D94316056A; Sat, 27 Nov 2021 20:25:20 +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="ent7D934"; 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 A2F166011E for ; Sat, 27 Nov 2021 20:25:19 +0100 (CET) Received: by mail-pj1-x102d.google.com with SMTP id p18-20020a17090ad31200b001a78bb52876so12117217pju.3 for ; Sat, 27 Nov 2021 11:25:19 -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=A9Lv4dng6DV5RVbFC49/vWpXb1FmCaXCPo2s6qvAxG4=; b=ent7D934oNv5ImoQ1CmAx1S39Trm8D1iXaL+tbq+48hu2TGX9yjHToiuxAUh8mRe/6 ASuPvsXq2UQIrh0Ihy3k0T+FxmbDOHRrJBbTmqgHIrEeq8WAHi5FajY61XxcHb2fhhxe oBf1C2YQQE/be0wRUW1x3/ebkyr8dyZ5ELN/zETqsLoSaTu8JM5QzTq3pa3/fg8sCPsY oFMi8vRiTQXbvsuQ0lwzlxqulvns1FBiECSH19dczAEsnEqZ4twmI9gfmvjUOTsOsFJs K2N2l1QJqxZrPdoyoDNiipv1yWe+7ZY7BSwAOrahUgbJns844YTZZXNsgiEkmNuto3G7 RQMg== 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=A9Lv4dng6DV5RVbFC49/vWpXb1FmCaXCPo2s6qvAxG4=; b=XTWamVxwGED44rkPeUF60vF+o9qIxfiaGlhw1WwvlbDZq4+vSlK4BSkzbhpM+vF2gt 6lCk5JL9MkvbWd9kGSr9EBGWzY+gCPGwAnVGOJNf1kvQgfXByHixVW6nPidOfFkEX1L1 9V47iexaPVN911DSkVyamvR5G+TU5xtFg46svrUm9id6NjbioQ9MOZ/Hbe9vCNMj89eP A/bBf5vReHu5a7OZq8P9Kxze4GmFRQF9Ti2u05EVW4W77YIqPW43BmD+GnYmmRuIiESJ bnGrtlmQhP83PjnaJcuNb8KnTQbRPvs8WbVPFPi8M0tnPN0HyJRCA2HHeitImULyaFp4 WLIA== X-Gm-Message-State: AOAM531No77lDsPv6CCUK0w1W6OXlzHbr859gbWkff6tRQwSO9cPFVmA Y22RisUiyXBz2mLVMngj1UfKW5+zZaQTBg== X-Google-Smtp-Source: ABdhPJxn7umFzLRxALLvG4LVByEYb+c/DFIW99vLwYnr3q3traTYppn76l4PQJv+6mc/raobBaXOjg== X-Received: by 2002:a17:902:7d96:b0:142:87dc:7dd3 with SMTP id a22-20020a1709027d9600b0014287dc7dd3mr46378126plm.11.1638041117453; Sat, 27 Nov 2021 11:25:17 -0800 (PST) Received: from localhost.localdomain ([1.186.167.22]) by smtp.googlemail.com with ESMTPSA id j13sm8141006pgg.5.2021.11.27.11.25.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 27 Nov 2021 11:25:17 -0800 (PST) From: Vedant Paranjape To: libcamera-devel@lists.libcamera.org Date: Sun, 28 Nov 2021 00:54:40 +0530 Message-Id: <20211127192440.389551-1-vedantparanjape160201@gmail.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH] 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. Reference issue: https://bugs.libcamera.org/show_bug.cgi?id=89 Signed-off-by: Vedant Paranjape --- src/v4l2/v4l2_camera_proxy.cpp | 41 +++++++++++++++++++++++++++++++++- src/v4l2/v4l2_camera_proxy.h | 1 + 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/src/v4l2/v4l2_camera_proxy.cpp b/src/v4l2/v4l2_camera_proxy.cpp index 3610e63cade3..03e3564bfed5 100644 --- a/src/v4l2/v4l2_camera_proxy.cpp +++ b/src/v4l2/v4l2_camera_proxy.cpp @@ -160,7 +160,8 @@ bool V4L2CameraProxy::validateBufferType(uint32_t type) bool V4L2CameraProxy::validateMemoryType(uint32_t memory) { - return memory == V4L2_MEMORY_MMAP; + return (memory == V4L2_MEMORY_MMAP) || + (memory == V4L2_MEMORY_DMABUF); } void V4L2CameraProxy::setFmtFromConfig(const StreamConfiguration &streamConfig) @@ -624,6 +625,40 @@ 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(); + /* \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; + + if (!hasOwnership(file) && owner_) + 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; + + acquire(file); + + return 0; +} + int V4L2CameraProxy::vidioc_streamon(V4L2CameraFile *file, int *arg) { LOG(V4L2Compat, Debug) << "Servicing vidioc_streamon fd = " << file->efd(); @@ -685,6 +720,7 @@ const std::set V4L2CameraProxy::supportedIoctls_ = { VIDIOC_QUERYBUF, VIDIOC_QBUF, VIDIOC_DQBUF, + VIDIOC_EXPBUF, VIDIOC_STREAMON, VIDIOC_STREAMOFF, }; @@ -755,6 +791,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);