From patchwork Mon Nov 29 19:40:31 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vedant Paranjape X-Patchwork-Id: 14851 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 DA420BDB13 for ; Mon, 29 Nov 2021 19:40:49 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 420E9605A4; Mon, 29 Nov 2021 20:40:49 +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="LULegJHj"; dkim-atps=neutral Received: from mail-pl1-x629.google.com (mail-pl1-x629.google.com [IPv6:2607:f8b0:4864:20::629]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id AABD460592 for ; Mon, 29 Nov 2021 20:40:47 +0100 (CET) Received: by mail-pl1-x629.google.com with SMTP id u17so13013839plg.9 for ; Mon, 29 Nov 2021 11:40:47 -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=nyA9U/+rc8LaPo/Tjndn7ffz4hL25lQSguudTP+rbJg=; b=LULegJHjmccqYSlNmtU8t1AJEShZk8fXJk/gUOZepWlRyr+2+onGJmYxgVm1ratafs 19l3g3tTUV8nPDQMcI0DVAHkxLEJeNBXSegbnkjzLPVw7vQEtqCQnMAIVBEuD/hoNun9 LJEiZRAoEMMJLuaIQD9MbIkrf4o/nu2oEY8e43RF6xNov8a74V/4ui5m9ORWFq/kpbtR /ggxxboZvRnjaac7jrwzyndXHeiHk+LLu6WmrsD78FP8/hnlW5KGnO87Wr+XYZV73+EU MwCPt4FJCD2Ba8YhO1ulqoUOUv/uo6D4a8Zw6qJX8Tbb59S8HXjT7RZIbRS6nv4Vu5Mz Ppqg== 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=nyA9U/+rc8LaPo/Tjndn7ffz4hL25lQSguudTP+rbJg=; b=7CPyvIZvsOdxU8R5E4y/ldoUadJRSyYC4Q+J6oLr3eqJ3AlTiDLtEmNtERNWTtZpeF 4rUFJODeDCtPSMOxSp8JOs5egdKGmTqw5eXTvlSr8rMZekbxFw9tHjGymm0vMxblCQ8L rhWF1vSGE0/UtMhalbX5UaWb0eJqlNXPD995DSoe8x5mByIwVZDJZBBO2uZdKJg4/MHe q3a7yOq5loyj9L7Epce2pYCfvcH+fbOCDvijRVbBgZd8qVIikYgepqdvDtlvq0gB6bs0 eJB+jaP9w4PtGDAjxaUVxD78jwGD7mpnR0vqMVFb/S5T9YM+a7mq+evgj2CfsBGb0Pot xxKQ== X-Gm-Message-State: AOAM532Q7Eqh6BdcEjHzt8/IL/sxFo9TNNoTTaHz8vYejCy3f0pakHMl QTUKZmhpaKwyOqg50FMuz+KZy5pmkkxpOQ== X-Google-Smtp-Source: ABdhPJwGg5SEx+xmBCnkHhgii4oLwVAzPz6ha9FYIiTNcs8bvw7TVDIcbQ1leYVgMCo85IP5SgG4og== X-Received: by 2002:a17:90b:4b51:: with SMTP id mi17mr197726pjb.48.1638214845280; Mon, 29 Nov 2021 11:40:45 -0800 (PST) Received: from localhost.localdomain ([1.186.167.22]) by smtp.googlemail.com with ESMTPSA id y190sm18113039pfg.153.2021.11.29.11.40.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Nov 2021 11:40:44 -0800 (PST) From: Vedant Paranjape To: libcamera-devel@lists.libcamera.org Date: Tue, 30 Nov 2021 01:10:31 +0530 Message-Id: <20211129194031.1340933-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 DMABUF buffer I/O in REQBUF 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 importing DMABUF, we need to reqbufs with DMABUF mode. This patch enables using V4L2_MEMORY_DMABUF as one of the memory types in vidioc_reqbuf to initialise DMA Buffer I/O Bug: https://bugs.libcamera.org/show_bug.cgi?id=89 Signed-off-by: Vedant Paranjape --- src/v4l2/v4l2_camera_proxy.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/v4l2/v4l2_camera_proxy.cpp b/src/v4l2/v4l2_camera_proxy.cpp index f194e06345b7..c8861a531399 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) @@ -468,7 +469,8 @@ int V4L2CameraProxy::vidioc_reqbufs(V4L2CameraFile *file, struct v4l2_requestbuf if (!hasOwnership(file) && owner_) return -EBUSY; - arg->capabilities = V4L2_BUF_CAP_SUPPORTS_MMAP; + arg->capabilities = V4L2_BUF_CAP_SUPPORTS_MMAP | + V4L2_BUF_CAP_SUPPORTS_DMABUF; memset(arg->reserved, 0, sizeof(arg->reserved)); if (arg->count == 0) { @@ -511,11 +513,15 @@ int V4L2CameraProxy::vidioc_reqbufs(V4L2CameraFile *file, struct v4l2_requestbuf struct v4l2_buffer buf = {}; buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; buf.length = v4l2PixFormat_.sizeimage; - buf.memory = V4L2_MEMORY_MMAP; - buf.m.offset = i * v4l2PixFormat_.sizeimage; + buf.memory = arg->memory; buf.index = i; buf.flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC; + if (arg->memory == V4L2_MEMORY_MMAP) + buf.m.offset = i * v4l2PixFormat_.sizeimage; + else if (arg->memory == V4L2_MEMORY_DMABUF) + buf.m.fd = vcam_->getBufferFd(i).fd(); + buffers_[i] = buf; }