From patchwork Sun Jan 9 07:33:30 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vedant Paranjape X-Patchwork-Id: 15262 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 BAC59BE080 for ; Sun, 9 Jan 2022 07:34:01 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id B2E5A60938; Sun, 9 Jan 2022 08:34:00 +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="JKyt1ZC0"; dkim-atps=neutral Received: from mail-pj1-x1032.google.com (mail-pj1-x1032.google.com [IPv6:2607:f8b0:4864:20::1032]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id C1A0F6017E for ; Sun, 9 Jan 2022 08:33:59 +0100 (CET) Received: by mail-pj1-x1032.google.com with SMTP id l16-20020a17090a409000b001b2e9628c9cso12812316pjg.4 for ; Sat, 08 Jan 2022 23:33:59 -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=luV6mm+MmicBfKS9bBddluS5k+rvZ2HkQVHeugY0BPg=; b=JKyt1ZC0fxFxxQjFGIYet6Cia8/GaxUQYIeXxxrcAFf3pJEWPAy+Ath+AwLuwteZTu TxLnTlwbRclOdGvj+ruWAuhBa6M1nCB74sOQSeoo3dVF4gJm8ZYkfhKvG6pTr56X9FR6 B2p1TxSIsfrCH8MmBYJ9gR8q5zr8CHxLv7Fz8nGE01HU7oZh6/5rRsHXLC9Ano3J8L8Z yrdHBMsGnUAk8hAK39Y+1hEQJ3IdfpwVDr2ueoUDvJqYHTxSkQTIS2L/BdFEG5y9S67b DGj+BgXKM4txFOewVVYYga+3W1FyQMuXQiLh9mH8rTwgRjGbfMU3Z8JieZxo8ruITuEa farg== 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=luV6mm+MmicBfKS9bBddluS5k+rvZ2HkQVHeugY0BPg=; b=X8ecPW17Deds6O8lkP2895AeRVMsAkzNqE8cTjF01oaV7XzvhQ7Kw3GXqdOmmpUhXu 73NfY9Jka5i2Jrq8VZ0oz/novRC2Z4EsJAbyCUhnUdn2bvuYgE/Su037KA4o+/cWHn6W bGUF4R/9Pho7yXws1Z1o9c1z4UMQWfhXdKY8Znl46jfkVDK8kBg97PeG+Xovl4OxXRz1 K5M5s5PHbrTdqM4HBQqSK/0FCLXzsndUt5TTwMwB2oyTY5/FkaXj9brNv/X4mgsUDc9k AlPM+kFmMG7nIxU9Tdb+XDhFcLHmr1k3ylR2+qUUh0e+asjmY9Bj9Jhx1FHVabhsZ5LL BOHQ== X-Gm-Message-State: AOAM531CVF0b19lZ+b8v3FckqyZkcxrmZy1EEqt10DsNbKFqgK1Wfawb LnhxSlWpMqg+72mIBxwfuykwG+/tAXw= X-Google-Smtp-Source: ABdhPJw+vz1K6QTZy7RAWdSMDSKy1gGS1GRC5QDelFLplu+z0IAUET9uMgB5+neV6VolLAD06K8LHQ== X-Received: by 2002:a17:90b:3b92:: with SMTP id pc18mr24454559pjb.137.1641713637967; Sat, 08 Jan 2022 23:33:57 -0800 (PST) Received: from veware.localdomain ([1.186.167.81]) by smtp.googlemail.com with ESMTPSA id g9sm3023347pfc.203.2022.01.08.23.33.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 08 Jan 2022 23:33:57 -0800 (PST) From: Vedant Paranjape To: libcamera-devel@lists.libcamera.org Date: Sun, 9 Jan 2022 13:03:30 +0530 Message-Id: <20220109073330.923675-1-vedantparanjape160201@gmail.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Subject: [libcamera-devel] [RFC PATCH v1] v4l2: Add support for PREPARE_BUF 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" Add support for PREPARE_BUF as one of the ioctl. This needs adding the prepare_buf function to the v4l2_camera class as this operation involves passing on the ownership of buffers to the driver. Signed-off-by: Vedant Paranjape --- I have not cargo copied the error checking or the function, I actually went to kernel source and checked what parameters are being checked to give out a error and checked those in my definition as well. https://elixir.bootlin.com/linux/latest/source/drivers/media/common/videobuf2/videobuf2-v4l2.c#L729 Please review the v4l2_camera_proxy part, if the function looks good enough hypothetically assuming vcam_->prepare_buf() has a correct implementation. As for the part in v4l2_camera, prepare_buf. Seeing the pattern of code, any operation that needs exchanging buffers with the drivers needs to have a function to be implemented inside v4l2_camera just like qbuf is. Let me know if my assumption is wrong, and this change is absolutely not needed. I am unable to figure out what is the equivalent of transfering ownership of the buffer in the libcamera compat world. Just like queueing a buffer has an equivalent, camera_->queueRequest(request) (not comparing apples to apples, but to some extent). --- src/v4l2/v4l2_camera.cpp | 10 ++++++++++ src/v4l2/v4l2_camera.h | 1 + src/v4l2/v4l2_camera_proxy.cpp | 32 ++++++++++++++++++++++++++++++++ src/v4l2/v4l2_camera_proxy.h | 1 + 4 files changed, 44 insertions(+) diff --git a/src/v4l2/v4l2_camera.cpp b/src/v4l2/v4l2_camera.cpp index e922b9e6aab2..2c155a63f836 100644 --- a/src/v4l2/v4l2_camera.cpp +++ b/src/v4l2/v4l2_camera.cpp @@ -275,6 +275,16 @@ int V4L2Camera::qbuf(unsigned int index) return 0; } +int V4L2Camera::prepare_buf(unsigned int index, unsigned int memory) +{ + // just a stub for now + // referring to + // https://elixir.bootlin.com/linux/latest/source/drivers/media/common/videobuf2/videobuf2-v4l2.c#L729 + // https://elixir.bootlin.com/linux/latest/source/drivers/media/common/videobuf2/videobuf2-core.c#L1341 + + return 0; +} + void V4L2Camera::waitForBufferAvailable() { MutexLocker locker(bufferMutex_); diff --git a/src/v4l2/v4l2_camera.h b/src/v4l2/v4l2_camera.h index 03e741180e8f..b4e4b65ed701 100644 --- a/src/v4l2/v4l2_camera.h +++ b/src/v4l2/v4l2_camera.h @@ -57,6 +57,7 @@ public: int streamOff(); int qbuf(unsigned int index); + int prepare_buf(unsigned int index, unsigned int memory); void waitForBufferAvailable(); bool isBufferAvailable(); diff --git a/src/v4l2/v4l2_camera_proxy.cpp b/src/v4l2/v4l2_camera_proxy.cpp index 4d529bc29a4d..ae0b0691ca4e 100644 --- a/src/v4l2/v4l2_camera_proxy.cpp +++ b/src/v4l2/v4l2_camera_proxy.cpp @@ -544,6 +544,37 @@ int V4L2CameraProxy::vidioc_querybuf(V4L2CameraFile *file, struct v4l2_buffer *a return 0; } +int V4L2CameraProxy::vidioc_prepare_buf(V4L2CameraFile *file, struct v4l2_buffer *arg) +{ + LOG(V4L2Compat, Debug) << "Servicing vidioc_prepare_buf, index = " + << arg->index << " fd = " << file->efd(); + + if (arg->index >= bufferCount_) + return -EINVAL; + + if (arg->flags & V4L2_BUF_FLAG_REQUEST_FD || + arg->flags & V4L2_BUF_FLAG_PREPARED) + return -EINVAL; + + if (!hasOwnership(file)) + return -EBUSY; + + if (!validateBufferType(arg->type) || + !validateMemoryType(arg->memory)) + return -EINVAL; + + /* \todo when DMABUF memory type is supported, add support here as well */ + int ret = vcam_->prepare_buf(arg->index, arg->memory); + if (ret < 0) + return ret; + + buffers_[arg->index].flags |= V4L2_BUF_FLAG_PREPARED; + + arg->flags = buffers_[arg->index].flags; + + return ret; +} + int V4L2CameraProxy::vidioc_qbuf(V4L2CameraFile *file, struct v4l2_buffer *arg) { LOG(V4L2Compat, Debug) << "Servicing vidioc_qbuf, index = " @@ -709,6 +740,7 @@ const std::set V4L2CameraProxy::supportedIoctls_ = { VIDIOC_S_INPUT, VIDIOC_REQBUFS, VIDIOC_QUERYBUF, + VIDIOC_PREPARE_BUF, VIDIOC_QBUF, VIDIOC_DQBUF, VIDIOC_EXPBUF, diff --git a/src/v4l2/v4l2_camera_proxy.h b/src/v4l2/v4l2_camera_proxy.h index 14e027c3e7d1..6baba94262a9 100644 --- a/src/v4l2/v4l2_camera_proxy.h +++ b/src/v4l2/v4l2_camera_proxy.h @@ -57,6 +57,7 @@ private: int vidioc_s_input(V4L2CameraFile *file, int *arg); int vidioc_reqbufs(V4L2CameraFile *file, struct v4l2_requestbuffers *arg); int vidioc_querybuf(V4L2CameraFile *file, struct v4l2_buffer *arg); + int vidioc_prepare_buf(V4L2CameraFile *file, struct v4l2_buffer *arg); 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);