From patchwork Thu May 7 21:37:19 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 26683 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by patchwork.libcamera.org (Postfix) with ESMTPS id B02C3BDCBD for ; Fri, 8 May 2026 08:21:44 +0000 (UTC) Received: from monstersaurus.ideasonboard.com (cpc89244-aztw30-2-0-cust6594.18-1.cable.virginm.net [86.31.185.195]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id DA2F0ABF for ; Fri, 8 May 2026 10:21:39 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1778228500; bh=ndWgKnmZU6IhXy/Y/qqSpv0QmggHsu3f5ZBXZ8Vgw1I=; h=From:To:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: Resent-From:Resent-To:From; b=M1KhHP3sQjDFivxS1QjBFjWsGjNyZB/w8/7vgsteNq4zkkZhK7jLZhL0duIY337J+ AaWoFWutBQ4Y8YnrXkz1WWk2KjfiEWbLHAy92lBO0G7GF+LfJAqc6lbVQKcBf1P4NG Bf3bT4mCiK31IOQDQ3uJeihjpi0FWNHCsH79kzM8= Delivered-To: kbingham@ideasonboard.com Received: from perceval.ideasonboard.com by perceval.ideasonboard.com with LMTP id 6E8DLhQG/WmqahUA4E0KoQ (envelope-from ) for ; Thu, 07 May 2026 23:37:24 +0200 Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by perceval.ideasonboard.com (Postfix) with ESMTPS id 926BD2072; Thu, 7 May 2026 23:37:24 +0200 (CEST) Authentication-Results: perceval.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.a=rsa-sha256 header.s=mail header.b=UdKd8X1W; dkim-atps=neutral Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 27EDF6301E; Thu, 7 May 2026 23:37:28 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="UdKd8X1W"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 3A2E362010 for ; Thu, 7 May 2026 23:37:24 +0200 (CEST) Received: from killaraus.ideasonboard.com (2001-14ba-70f3-e800--a06.rev.dnainternet.fi [IPv6:2001:14ba:70f3:e800::a06]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id CD34A1121 for ; Thu, 7 May 2026 23:37:19 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1778189840; bh=ndWgKnmZU6IhXy/Y/qqSpv0QmggHsu3f5ZBXZ8Vgw1I=; h=From:To:Subject:Date:In-Reply-To:References:From; b=UdKd8X1W6Yv28jCWRo11r7J0sc1B9dYtvCJ7qBQpr57wu1WAe8XfVF6o6a3UehepT UCaW6WeKhUQ0EWahVHfkc9/yAgcALMVmnXr59ajNEyYkpAPS4SUJk+nkYHbxpQiZPv OhhFpha/TFMaE0fDR0eZxapzyzRBBAg+OGTlwuEU= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Subject: [PATCH 1/3] ipa: libipa: v4l2_params: Mention ISP in file one-line description Date: Fri, 8 May 2026 00:37:19 +0300 Message-ID: <20260507213721.2137448-2-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260507213721.2137448-1-laurent.pinchart@ideasonboard.com> References: <20260507213721.2137448-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 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: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" X-TUID: ws4KQV2V/og5 Resent-From: Kieran Bingham Resent-To: parsemail@patchwork.libcamera.org The v4l2_params.{cpp,h} files are helpers classes for the V4L2 ISP parameters buffers. Mention "ISP" in the one-line file description to clarify this. Signed-off-by: Laurent Pinchart Reviewed-by: Barnabás Pőcze Reviewed-by: Kieran Bingham --- src/ipa/libipa/v4l2_params.cpp | 2 +- src/ipa/libipa/v4l2_params.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ipa/libipa/v4l2_params.cpp b/src/ipa/libipa/v4l2_params.cpp index a1eeeb1b0e6a..c2971f1caf28 100644 --- a/src/ipa/libipa/v4l2_params.cpp +++ b/src/ipa/libipa/v4l2_params.cpp @@ -2,7 +2,7 @@ /* * Copyright (C) 2025, Ideas On Board * - * V4L2 Parameters + * V4L2 ISP Parameters */ #include "v4l2_params.h" diff --git a/src/ipa/libipa/v4l2_params.h b/src/ipa/libipa/v4l2_params.h index b9ef6cfb3b5b..f400b37d74b5 100644 --- a/src/ipa/libipa/v4l2_params.h +++ b/src/ipa/libipa/v4l2_params.h @@ -2,7 +2,7 @@ /* * Copyright (C) 2025, Ideas On Board * - * V4L2 Parameters + * V4L2 ISP Parameters */ #pragma once From patchwork Thu May 7 21:37:20 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 26684 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by patchwork.libcamera.org (Postfix) with ESMTPS id 1700FBDCBD for ; Fri, 8 May 2026 08:21:48 +0000 (UTC) Received: from monstersaurus.ideasonboard.com (cpc89244-aztw30-2-0-cust6594.18-1.cable.virginm.net [86.31.185.195]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 62967ABF for ; Fri, 8 May 2026 10:21:43 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1778228503; bh=9DBr/npHvLuQCKSmhepiDwkLsz+KI8uRPUPyBNSEsB8=; h=From:To:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: Resent-From:Resent-To:From; b=WQBDHUjeGZ5TXKEf6u1tqkriNlqHSpgU+QTMzVJVmysi6h+0Lmy5WcPwMtPWSkGxD KF4LgjvMiyoReCV7w9Ip8O2t9rJytXUPKlc6YdjLF33EGuQguVi3s8EDid+ESCTuL0 4xaNBn4hz/K500dz2zUiEOfW0ndX5DsVeQj78aeA= Delivered-To: kbingham@ideasonboard.com Received: from perceval.ideasonboard.com by perceval.ideasonboard.com with LMTP id 6IWcExYG/WkpahUA4E0KoQ (envelope-from ) for ; Thu, 07 May 2026 23:37:26 +0200 Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by perceval.ideasonboard.com (Postfix) with ESMTPS id 2BD4E1121; Thu, 7 May 2026 23:37:26 +0200 (CEST) Authentication-Results: perceval.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.a=rsa-sha256 header.s=mail header.b=L4FewWsP; dkim-atps=neutral Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id A40B56302A; Thu, 7 May 2026 23:37:28 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="L4FewWsP"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id E0BED62010 for ; Thu, 7 May 2026 23:37:25 +0200 (CEST) Received: from killaraus.ideasonboard.com (2001-14ba-70f3-e800--a06.rev.dnainternet.fi [IPv6:2001:14ba:70f3:e800::a06]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 263841121 for ; Thu, 7 May 2026 23:37:21 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1778189841; bh=9DBr/npHvLuQCKSmhepiDwkLsz+KI8uRPUPyBNSEsB8=; h=From:To:Subject:Date:In-Reply-To:References:From; b=L4FewWsPQRHVofFIS9ULu1UiiLGGTRfKhjXHNC//v7LZuDgWI8X3c5oeE1Xws/STr 2BzU/QeAegiCe/ADCajiBr/oux2Q4SsH/XcluebLZXOw1DgISurReDiXR2Awc/m/FP 7uAh1ZlH/hZSCPz/umEc7MhAXmn7dyKhvSYUrJ7M= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Subject: [PATCH 2/3] ipa: libipa: v4l2_params: Enforce uint16_t for id_type underlying type Date: Fri, 8 May 2026 00:37:20 +0300 Message-ID: <20260507213721.2137448-3-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260507213721.2137448-1-laurent.pinchart@ideasonboard.com> References: <20260507213721.2137448-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 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: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" X-TUID: o8uLq+KHvbF1 Resent-From: Kieran Bingham Resent-To: parsemail@patchwork.libcamera.org The Linux kernel V4L2 extensible ISP parameters API uses a 16-bit integer for the block type. We can therefore standardize on the same type for the underlying type of the Traits::id_type enum class, as there will never be more block types in libcamera than in the kernel. This will help sharing code between different specializations of V4L2Params. Signed-off-by: Laurent Pinchart Reviewed-by: Barnabás Pőcze Reviewed-by: Kieran Bingham --- src/ipa/libipa/v4l2_params.cpp | 2 +- src/ipa/libipa/v4l2_params.h | 11 +++++++---- src/ipa/mali-c55/params.h | 4 +++- src/ipa/rkisp1/params.cpp | 3 ++- src/ipa/rkisp1/params.h | 4 +++- 5 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/ipa/libipa/v4l2_params.cpp b/src/ipa/libipa/v4l2_params.cpp index c2971f1caf28..d44a366a60b8 100644 --- a/src/ipa/libipa/v4l2_params.cpp +++ b/src/ipa/libipa/v4l2_params.cpp @@ -217,7 +217,7 @@ namespace ipa { */ /** - * \fn V4L2Params::block(typename Traits::id_type type, unsigned int blockType, size_t blockSize) + * \fn V4L2Params::block(uint16_t type, unsigned int blockType, size_t blockSize) * \brief Populate an ISP configuration block a returns a reference to its * memory * \param[in] type The ISP block identifier enumerated by the IPA module diff --git a/src/ipa/libipa/v4l2_params.h b/src/ipa/libipa/v4l2_params.h index f400b37d74b5..4f84360ee449 100644 --- a/src/ipa/libipa/v4l2_params.h +++ b/src/ipa/libipa/v4l2_params.h @@ -15,6 +15,7 @@ #include #include +#include namespace libcamera { @@ -72,6 +73,8 @@ template class V4L2Params { public: + static_assert(std::is_same_v, uint16_t>); + V4L2Params(Span data, unsigned int version) : data_(data) { @@ -93,13 +96,13 @@ public: using Type = typename Details::type; constexpr auto kernelId = Details::blockType; - auto data = block(Id, kernelId, sizeof(Type)); + auto data = block(utils::to_underlying(Id), kernelId, sizeof(Type)); return V4L2ParamsBlock(data); } protected: - Span block(typename Traits::id_type type, - unsigned int blockType, size_t blockSize) + Span block(uint16_t type, unsigned int blockType, + size_t blockSize) { /* * Look up the block in the cache first. If an algorithm @@ -144,7 +147,7 @@ protected: Span data_; size_t used_; - std::map> blocks_; + std::map> blocks_; }; } /* namespace ipa */ diff --git a/src/ipa/mali-c55/params.h b/src/ipa/mali-c55/params.h index 64be68583ddb..3abcb7f94916 100644 --- a/src/ipa/mali-c55/params.h +++ b/src/ipa/mali-c55/params.h @@ -7,6 +7,8 @@ #pragma once +#include + #include #include @@ -16,7 +18,7 @@ namespace libcamera { namespace ipa::mali_c55 { -enum class MaliC55Blocks { +enum class MaliC55Blocks : uint16_t { Bls, AexpHist, AexpHistWeights, diff --git a/src/ipa/rkisp1/params.cpp b/src/ipa/rkisp1/params.cpp index 7040207c2655..b8abbdf6ec66 100644 --- a/src/ipa/rkisp1/params.cpp +++ b/src/ipa/rkisp1/params.cpp @@ -128,7 +128,8 @@ Span RkISP1Params::block(BlockType type) return data_.subspan(info.offset, info.size); } - return V4L2Params::block(type, info.type, info.size); + return V4L2Params::block(utils::to_underlying(type), info.type, + info.size); } } /* namespace ipa::rkisp1 */ diff --git a/src/ipa/rkisp1/params.h b/src/ipa/rkisp1/params.h index eddb37d5c000..8e3672ca8340 100644 --- a/src/ipa/rkisp1/params.h +++ b/src/ipa/rkisp1/params.h @@ -7,6 +7,8 @@ #pragma once +#include + #include #include @@ -16,7 +18,7 @@ namespace libcamera { namespace ipa::rkisp1 { -enum class BlockType { +enum class BlockType : uint16_t { Bls, Dpcc, Sdg, From patchwork Thu May 7 21:37:21 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 26685 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by patchwork.libcamera.org (Postfix) with ESMTPS id 533D5BDCBD for ; Fri, 8 May 2026 08:21:51 +0000 (UTC) Received: from monstersaurus.ideasonboard.com (cpc89244-aztw30-2-0-cust6594.18-1.cable.virginm.net [86.31.185.195]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 9E505ABF for ; Fri, 8 May 2026 10:21:46 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1778228506; bh=TPZiJEsWevzE7x+EjZgJuVTh1odB3TVAeX8S7243qvc=; h=From:To:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: Resent-From:Resent-To:From; b=PPlXQgIOJYo5TBDJMvnW1klWwfyoQJ76ftaxu1PcJ6FHklHswXD/ZS94sgyUkSbaU v1jlqUlyC6PhrnSO31LEhU7g+oK7+wGlFWqRo5gfsv07kiUnHIHWiE2TqcgrFFLX6N deTTnsL3BuMNGxxdnpK++9QiJckbHQaCSABIZlKI= Delivered-To: kbingham@ideasonboard.com Received: from perceval.ideasonboard.com by perceval.ideasonboard.com with LMTP id INU/ERcG/WmmahUA4E0KoQ (envelope-from ) for ; Thu, 07 May 2026 23:37:27 +0200 Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by perceval.ideasonboard.com (Postfix) with ESMTPS id 19BA02072; Thu, 7 May 2026 23:37:27 +0200 (CEST) Authentication-Results: perceval.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.a=rsa-sha256 header.s=mail header.b=dBTjk+CS; dkim-atps=neutral Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 845AA62FE1; Thu, 7 May 2026 23:37:29 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="dBTjk+CS"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id DAA6962010 for ; Thu, 7 May 2026 23:37:26 +0200 (CEST) Received: from killaraus.ideasonboard.com (2001-14ba-70f3-e800--a06.rev.dnainternet.fi [IPv6:2001:14ba:70f3:e800::a06]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 74C9E1121 for ; Thu, 7 May 2026 23:37:22 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1778189842; bh=TPZiJEsWevzE7x+EjZgJuVTh1odB3TVAeX8S7243qvc=; h=From:To:Subject:Date:In-Reply-To:References:From; b=dBTjk+CS1I10K0HA8JLqb7vBJbaeO77Bc8O+8d2I6ByxnHO1sISYtsGRjjf8zK0PI RjleHXU2x+sKwGhx9Ud1D4fSQg04OrE6ObBZE8lw7RoXgbndWEHFoiEURgEHcEyJBs ySmMEAJFtYToghdQLwE7JEQcOiJeivfYRMY4c7zs= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Subject: [PATCH 3/3] ipa: libipa: v4l2_params: Move non-template code to new base class Date: Fri, 8 May 2026 00:37:21 +0300 Message-ID: <20260507213721.2137448-4-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260507213721.2137448-1-laurent.pinchart@ideasonboard.com> References: <20260507213721.2137448-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 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: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" X-TUID: XjDRYnAro6x4 Resent-From: Kieran Bingham Resent-To: parsemail@patchwork.libcamera.org The implementation of multiple V4L2Params member functions does not depend on the class template argument. Move them to a base class, to avoid inlining them. Signed-off-by: Laurent Pinchart Reviewed-by: Barnabás Pőcze Reviewed-by: Kieran Bingham --- src/ipa/libipa/v4l2_params.cpp | 151 ++++++++++++++++++++++++--------- src/ipa/libipa/v4l2_params.h | 81 +++++------------- src/ipa/rkisp1/params.cpp | 4 +- 3 files changed, 132 insertions(+), 104 deletions(-) diff --git a/src/ipa/libipa/v4l2_params.cpp b/src/ipa/libipa/v4l2_params.cpp index d44a366a60b8..476dc0281448 100644 --- a/src/ipa/libipa/v4l2_params.cpp +++ b/src/ipa/libipa/v4l2_params.cpp @@ -117,6 +117,115 @@ namespace ipa { * \brief Memory area reserved for the ISP configuration block */ +/** + * \class V4L2ParamsBase + * \brief Base class for V4L2Params + * + * The V4L2ParamsBase is an integral part of V4L2Params. It serves as a + * container for all code that does not depend on the V4L2Params template + * arguments, to avoid duplicate copies of inline code. + */ + +/** + * \brief Construct an instance of V4L2ParamsBase + * \param[in] data Reference to the v4l2-buffer memory mapped area + * \param[in] version The ISP parameters version the implementation supports + */ +V4L2ParamsBase::V4L2ParamsBase(Span data, unsigned int version) + : data_(data) +{ + struct v4l2_isp_params_buffer *params = + reinterpret_cast(data_.data()); + params->data_size = 0; + params->version = version; + + used_ = offsetof(struct v4l2_isp_params_buffer, data); +} + +/** + * \fn V4L2ParamsBase::bytesused() + * \brief Retrieve the used size of the parameters buffer (in bytes) + * + * The parameters buffer size is mostly used to populate the v4l2_buffer + * bytesused field before queueing the buffer to the ISP. + * + * \return The number of bytes occupied by the ISP configuration parameters + */ + +/** + * \brief Populate an ISP configuration block a returns a reference to its + * memory + * \param[in] type The ISP block identifier enumerated by the IPA module + * \param[in] blockType The kernel-defined ISP block identifier, used to + * populate the block header + * \param[in] blockSize The ISP block size, used to populate the block header + * + * Initialize the block header with \a blockType and \a blockSize and + * returns a reference to the memory used to store an ISP configuration block. + * + * IPA modules that derive the V4L2Params class shall use this function to + * retrieve the memory area that will be used to construct a V4L2ParamsBlock + * before returning it to the caller. + */ +Span V4L2ParamsBase::block(uint16_t type, unsigned int blockType, + size_t blockSize) +{ + /* + * Look up the block in the cache first. If an algorithm + * requests the same block type twice, it should get the same + * block. + */ + auto cacheIt = blocks_.find(type); + if (cacheIt != blocks_.end()) + return cacheIt->second; + + /* + * Make sure we don't run out of space. Assert as otherwise + * we get a segfault as soon as someone tries to access the + * empty Span<> returned from here. + */ + if (blockSize > data_.size() - used_) { + LOG(Fatal) + << "Parameters buffer out of space; potential version mismatch between driver and libcamera"; + return {}; + } + + /* Allocate a new block, clear its memory, and initialize its header. */ + Span block = data_.subspan(used_, blockSize); + memset(block.data(), 0, block.size()); + + struct v4l2_isp_params_block_header *header = + reinterpret_cast(block.data()); + header->type = blockType; + header->size = block.size(); + + used_ += block.size(); + + struct v4l2_isp_params_buffer *buffer = + reinterpret_cast(data_.data()); + buffer->data_size += block.size(); + + /* Update the cache. */ + blocks_[type] = block; + + return block; +} + +/** + * \var V4L2ParamsBase::data_ + * \brief The ISP parameters buffer memory + */ + +/** + * \var V4L2ParamsBase::used_ + * \brief The number of bytes used in the parameters buffer + */ + +/** + * \var V4L2ParamsBase::blocks_ + * \brief Cache of ISP configuration blocks + */ + /** * \class V4L2Params * \brief Helper class that represent an ISP configuration buffer @@ -200,54 +309,12 @@ namespace ipa { * \param[in] version The ISP parameters version the implementation supports */ -/** - * \fn V4L2Params::bytesused() - * \brief Retrieve the used size of the parameters buffer (in bytes) - * - * The parameters buffer size is mostly used to populate the v4l2_buffer - * bytesused field before queueing the buffer to the ISP. - * - * \return The number of bytes occupied by the ISP configuration parameters - */ - /** * \fn V4L2Params::block() * \brief Retrieve the location of an ISP configuration block a return it * \return A V4L2ParamsBlock instance that points to the ISP configuration block */ -/** - * \fn V4L2Params::block(uint16_t type, unsigned int blockType, size_t blockSize) - * \brief Populate an ISP configuration block a returns a reference to its - * memory - * \param[in] type The ISP block identifier enumerated by the IPA module - * \param[in] blockType The kernel-defined ISP block identifier, used to - * populate the block header - * \param[in] blockSize The ISP block size, used to populate the block header - * - * Initialize the block header with \a blockType and \a blockSize and - * returns a reference to the memory used to store an ISP configuration block. - * - * IPA modules that derive the V4L2Params class shall use this function to - * retrieve the memory area that will be used to construct a V4L2ParamsBlock - * before returning it to the caller. - */ - -/** - * \var V4L2Params::data_ - * \brief The ISP parameters buffer memory - */ - -/** - * \var V4L2Params::used_ - * \brief The number of bytes used in the parameters buffer - */ - -/** - * \var V4L2Params::blocks_ - * \brief Cache of ISP configuration blocks - */ - } /* namespace ipa */ } /* namespace libcamera */ diff --git a/src/ipa/libipa/v4l2_params.h b/src/ipa/libipa/v4l2_params.h index 4f84360ee449..5f57167d7646 100644 --- a/src/ipa/libipa/v4l2_params.h +++ b/src/ipa/libipa/v4l2_params.h @@ -69,25 +69,34 @@ protected: Span data_; }; +class V4L2ParamsBase +{ +public: + V4L2ParamsBase(Span data, unsigned int version); + + size_t bytesused() const { return used_; } + +protected: + Span block(uint16_t type, unsigned int blockType, + size_t blockSize); + + Span data_; + size_t used_; + + std::map> blocks_; +}; + template -class V4L2Params +class V4L2Params : public V4L2ParamsBase { public: static_assert(std::is_same_v, uint16_t>); V4L2Params(Span data, unsigned int version) - : data_(data) + : V4L2ParamsBase(data, version) { - struct v4l2_isp_params_buffer *params = - reinterpret_cast(data_.data()); - params->data_size = 0; - params->version = version; - - used_ = offsetof(struct v4l2_isp_params_buffer, data); } - size_t bytesused() const { return used_; } - template auto block() { @@ -96,58 +105,10 @@ public: using Type = typename Details::type; constexpr auto kernelId = Details::blockType; - auto data = block(utils::to_underlying(Id), kernelId, sizeof(Type)); + auto data = V4L2ParamsBase::block(utils::to_underlying(Id), + kernelId, sizeof(Type)); return V4L2ParamsBlock(data); } - -protected: - Span block(uint16_t type, unsigned int blockType, - size_t blockSize) - { - /* - * Look up the block in the cache first. If an algorithm - * requests the same block type twice, it should get the same - * block. - */ - auto cacheIt = blocks_.find(type); - if (cacheIt != blocks_.end()) - return cacheIt->second; - - /* - * Make sure we don't run out of space. Assert as otherwise - * we get a segfault as soon as someone tries to access the - * empty Span<> returned from here. - */ - if (blockSize > data_.size() - used_) { - LOG(Fatal) - << "Parameters buffer out of space; potential version mismatch between driver and libcamera"; - return {}; - } - - /* Allocate a new block, clear its memory, and initialize its header. */ - Span block = data_.subspan(used_, blockSize); - memset(block.data(), 0, block.size()); - - struct v4l2_isp_params_block_header *header = - reinterpret_cast(block.data()); - header->type = blockType; - header->size = block.size(); - - used_ += block.size(); - - reinterpret_cast - (data_.data())->data_size += block.size(); - - /* Update the cache. */ - blocks_[type] = block; - - return block; - } - - Span data_; - size_t used_; - - std::map> blocks_; }; } /* namespace ipa */ diff --git a/src/ipa/rkisp1/params.cpp b/src/ipa/rkisp1/params.cpp index b8abbdf6ec66..71df0a939de2 100644 --- a/src/ipa/rkisp1/params.cpp +++ b/src/ipa/rkisp1/params.cpp @@ -128,8 +128,8 @@ Span RkISP1Params::block(BlockType type) return data_.subspan(info.offset, info.size); } - return V4L2Params::block(utils::to_underlying(type), info.type, - info.size); + return V4L2ParamsBase::block(utils::to_underlying(type), info.type, + info.size); } } /* namespace ipa::rkisp1 */