Patch Detail
Show a patch.
GET /api/1.1/patches/24267/?format=api
{ "id": 24267, "url": "https://patchwork.libcamera.org/api/1.1/patches/24267/?format=api", "web_url": "https://patchwork.libcamera.org/patch/24267/", "project": { "id": 1, "url": "https://patchwork.libcamera.org/api/1.1/projects/1/?format=api", "name": "libcamera", "link_name": "libcamera", "list_id": "libcamera_core", "list_email": "libcamera-devel@lists.libcamera.org", "web_url": "", "scm_url": "", "webscm_url": "" }, "msgid": "<20250829-v4l2-params-v1-3-340773fb69ff@ideasonboard.com>", "date": "2025-08-29T11:54:00", "name": "[3/4] ipa: libipa: Introduce V4L2Params", "commit_ref": null, "pull_url": null, "state": "superseded", "archived": false, "hash": "a7b7fbff2f7d55e7d22f9f675cc49fa5a8113b6f", "submitter": { "id": 143, "url": "https://patchwork.libcamera.org/api/1.1/people/143/?format=api", "name": "Jacopo Mondi", "email": "jacopo.mondi@ideasonboard.com" }, "delegate": null, "mbox": "https://patchwork.libcamera.org/patch/24267/mbox/", "series": [ { "id": 5413, "url": "https://patchwork.libcamera.org/api/1.1/series/5413/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=5413", "date": "2025-08-29T11:53:57", "name": "ipa: libipa: Introduce V4L2Params", "version": 1, "mbox": "https://patchwork.libcamera.org/series/5413/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/24267/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/24267/checks/", "tags": {}, "headers": { "Return-Path": "<libcamera-devel-bounces@lists.libcamera.org>", "X-Original-To": "parsemail@patchwork.libcamera.org", "Delivered-To": "parsemail@patchwork.libcamera.org", "Received": [ "from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 8080DC32BB\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri, 29 Aug 2025 11:54:34 +0000 (UTC)", "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 716A469324;\n\tFri, 29 Aug 2025 13:54:33 +0200 (CEST)", "from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 5B3796931D\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 29 Aug 2025 13:54:24 +0200 (CEST)", "from [192.168.1.102] (93-61-96-190.ip145.fastwebnet.it\n\t[93.61.96.190])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 3AF073BEE;\n\tFri, 29 Aug 2025 13:53:19 +0200 (CEST)" ], "Authentication-Results": "lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"vYahlJtQ\"; dkim-atps=neutral", "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1756468399;\n\tbh=VaO6RxmH8AFIDeT03ooF/ZaktlSstVrtUodhVbflVZE=;\n\th=From:Date:Subject:References:In-Reply-To:To:Cc:From;\n\tb=vYahlJtQidSoHXXW83yEPLXmKil1AWS6YHCfHAKb1vr2cx7KiBtUB65V1qzG2RLRg\n\tsum9+mMONS3pfqfIaOrZl36ZjkVPpqReqaxLtcEBCRezeURdK40GLsF/eghgXAqYZU\n\t6uUTUG6y89/cOVbH+nrvvWhuCj8RssflBIbaFpGo=", "From": "Jacopo Mondi <jacopo.mondi@ideasonboard.com>", "Date": "Fri, 29 Aug 2025 13:54:00 +0200", "Subject": "[PATCH 3/4] ipa: libipa: Introduce V4L2Params", "MIME-Version": "1.0", "Content-Type": "text/plain; charset=\"utf-8\"", "Content-Transfer-Encoding": "7bit", "Message-Id": "<20250829-v4l2-params-v1-3-340773fb69ff@ideasonboard.com>", "References": "<20250829-v4l2-params-v1-0-340773fb69ff@ideasonboard.com>", "In-Reply-To": "<20250829-v4l2-params-v1-0-340773fb69ff@ideasonboard.com>", "To": "libcamera-devel@lists.libcamera.org", "Cc": "Jacopo Mondi <jacopo.mondi@ideasonboard.com>", "X-Mailer": "b4 0.14.2", "X-Developer-Signature": "v=1; a=openpgp-sha256; l=21834;\n\ti=jacopo.mondi@ideasonboard.com; h=from:subject:message-id;\n\tbh=VaO6RxmH8AFIDeT03ooF/ZaktlSstVrtUodhVbflVZE=;\n\tb=owEBbQKS/ZANAwAKAXI0Bo8WoVY8AcsmYgBosZTundzgBDFNHodfC1jRqNKh5qmHRFxIu0riE\n\t0eUghvds/GJAjMEAAEKAB0WIQS1xD1IgJogio9YOMByNAaPFqFWPAUCaLGU7gAKCRByNAaPFqFW\n\tPJm/D/4lofnwlEiYqHx17XQBhuTY1yP+NrStAAgTnP+iMKS6mMsPmxfyHQyXRvGvpf+6cupKnYG\n\tlOYaJ0Aj2c75FeRUR78mbeMjpd6Fjy7wiz6zfaEsuqlfMExiPvYv1CL48iPCnwTvdBSl4xaIjAm\n\tuM/WWou5AEnmeAWYXzXoydBiiJTRKC5VdMtT9icvLFqog+iT5S1Bm3qUTfoT/vQRuLZ6HU055K/\n\t3kpckAgxFQSvHQlTK4gRu2Jq0nwn8dCDE/P5ieN7okydx2XvQN425SnkYxw4FFPLifk30+Mj4BZ\n\tFHV6PjhOeOPyANSd0qN5Mznb/P4A88DjzHKTnf7Y6ujctTCYZVKXEBNbWB0TRJ010ZZDWuLT8m6\n\tQowyvrIfyxbr44bURbHPJ0gDEpyg7ytlqhVbsHIE4slrjiL2HSbhCP6MZK0IySeTKese6mfl+Qh\n\tU3c8zgGRFwjtlYh1Di01TGetCkMHoVe72g77jCH1d17OcclnCacYU+wq5atp61DJzw56uFE9J7R\n\thVXF6Piuo36hs0gQcC1Vdj+E3Mkg1HV19JWACh/X1kvfcSnMGG6bVnmQTOQohOXNqNUdD0TvxpK\n\t+k41OANNXnRLKMtp2DiWJWtq0RyEw1A1AxJTRRlchRIZN8jf0F1HY9SOnlsAuCHLtw1ey7kLyjn\n\tIHc5B4hGuoU9TLQ==", "X-Developer-Key": "i=jacopo.mondi@ideasonboard.com; a=openpgp;\n\tfpr=72392EDC88144A65C701EA9BA5826A2587AD026B", "X-BeenThere": "libcamera-devel@lists.libcamera.org", "X-Mailman-Version": "2.1.29", "Precedence": "list", "List-Id": "<libcamera-devel.lists.libcamera.org>", "List-Unsubscribe": "<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>", "List-Archive": "<https://lists.libcamera.org/pipermail/libcamera-devel/>", "List-Post": "<mailto:libcamera-devel@lists.libcamera.org>", "List-Help": "<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>", "List-Subscribe": "<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>", "Errors-To": "libcamera-devel-bounces@lists.libcamera.org", "Sender": "\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>" }, "content": "The existing RkISP1Params helper classes allows the RkISP1 to handle\nV4L2 extensible parameters format and the legacy RkIPS1-specific\nfixed-size parameters format.\n\nWith the introduction of v4l2-params in the Linux kernel the part of\nthe RkISP1Params helper class that handles extensible parameters can\nbe generalized so that other IPA modules can use the same helpers\nto populate a v4l2-params compatible buffer.\n\nGeneralize the RkISP1Params class to a new libipa component named\nV4L2Params and derive the existing RkISP1Params from it, leaving\nin the RkISP1-specific implementation the handling of the legacy format.\n\nDeriving RkISP1Params from V4L2Params requires changing the size\nassociated to each block to include the size of v4l2_params_block_header\nin the ipa:rkisp1::kBlockTypeInfo map as the V4L2Params::block()\nimplementation doesn't account for that as RkIS1Params::block()\nimplementation did.\n\nSigned-off-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>\n---\n src/ipa/libipa/meson.build | 2 +\n src/ipa/libipa/v4l2_params.cpp | 252 +++++++++++++++++++++++++++++++++++++++++\n src/ipa/libipa/v4l2_params.h | 135 ++++++++++++++++++++++\n src/ipa/rkisp1/params.cpp | 93 +--------------\n src/ipa/rkisp1/params.h | 108 ++++++++----------\n 5 files changed, 438 insertions(+), 152 deletions(-)", "diff": "diff --git a/src/ipa/libipa/meson.build b/src/ipa/libipa/meson.build\nindex 660be94054fa98b714b6bc586039081e45a6b4bc..4010739e710eb38aa6108eb8258c574a616bf3c0 100644\n--- a/src/ipa/libipa/meson.build\n+++ b/src/ipa/libipa/meson.build\n@@ -16,6 +16,7 @@ libipa_headers = files([\n 'lsc_polynomial.h',\n 'lux.h',\n 'module.h',\n+ 'v4l2_params.h',\n 'pwl.h',\n ])\n \n@@ -35,6 +36,7 @@ libipa_sources = files([\n 'lsc_polynomial.cpp',\n 'lux.cpp',\n 'module.cpp',\n+ 'v4l2_params.cpp',\n 'pwl.cpp',\n ])\n \ndiff --git a/src/ipa/libipa/v4l2_params.cpp b/src/ipa/libipa/v4l2_params.cpp\nnew file mode 100644\nindex 0000000000000000000000000000000000000000..674018065ace0e1b6b48b1630e556cef590d1e84\n--- /dev/null\n+++ b/src/ipa/libipa/v4l2_params.cpp\n@@ -0,0 +1,252 @@\n+/* SPDX-License-Identifier: LGPL-2.1-or-later */\n+/*\n+ * Copyright (C) 2025, Ideas On Board\n+ *\n+ * V4L2 Parameters\n+ */\n+\n+#include \"v4l2_params.h\"\n+\n+namespace libcamera {\n+\n+namespace ipa {\n+\n+/**\n+ * \\file v4l2_params.cpp\n+ * \\brief Helper class to populate a v4l2-params compatible parameters buffer\n+ *\n+ * The Linux kernel defines a generic buffer format for configuring ISP devices\n+ * through a set of parameters in the form of V4L2 extensible parameters. The\n+ * V4L2 extensible parameters define a serialization format for ISP parameters\n+ * that allows userspace to populate a buffer of configuration data by appending\n+ * them one after the other in a binary buffer.\n+ *\n+ * Each ISP driver compatible with the v4l2-params format will define its own\n+ * meta-output format identifier and defines the types of the configuration data\n+ * of each ISP block that usually match the registers layout.\n+ *\n+ * The V4L2Params class represent the V4L2 extensible parameters buffer and\n+ * allows users to populate the ISP configuration blocks, represented by the\n+ * V4L2ParamBlock class instances.\n+ *\n+ * IPA implementations using this helpers should define an enumeration of ISP\n+ * blocks the IPA module supports and use a set of common abstraction to help\n+ * their derived implementation of V4L2Params translate the enumerated ISP block\n+ * identifier to the actual type of the configuration data as defined by the\n+ * kernel interface.\n+ *\n+ * As an example of this see the RkISP1 and Mali-C55 implementations.\n+ */\n+\n+/**\n+ * \\class V4L2ParamsBlock\n+ * \\brief Helper class that represents a ISP configuration block\n+ *\n+ * Each ISP function is associated with a set of configuration parameters\n+ * defined by the kernel interface.\n+ *\n+ * This class represents an ISP block configuration entry. It is constructed\n+ * with a reference to the memory area where the block configuration will be\n+ * stored in the parameters buffer. The template parameter represents\n+ * the underlying kernel-defined ISP block configuration type and allow its\n+ * user to easily cast it to said type to populate and read the configuration\n+ * parameters.\n+ *\n+ * \\sa V4L2Params::block()\n+ */\n+\n+/**\n+ * \\fn V4L2ParamsBlock::V4L2ParamsBlock()\n+ * \\brief Construct a V4L2ParamsBlock with memory represented by \\a data\n+ * \\param[in] data A view on the memory area where the ISP block is located\n+ */\n+\n+/**\n+ * \\fn V4L2ParamsBlock::setEnabled()\n+ * \\brief Enable/disable an ISP configuration block\n+ * \\param[in] enabled The enable flag\n+ */\n+\n+/**\n+ * \\fn V4L2ParamsBlock::header()\n+ * \\brief Retrieve a reference to the header (struct v4l2_params_block_header)\n+ * \\return The block header\n+ */\n+\n+/**\n+ * \\fn V4L2ParamsBlock::data()\n+ * \\brief Retrieve a reference to block configuration data memory area\n+ * \\return The block data\n+ */\n+\n+/**\n+ * \\fn V4L2ParamsBlock::operator->()\n+ * \\brief Access the ISP configuration block casting it to the kernel-defined\n+ * ISP configuration type\n+ *\n+ * The V4L2ParamsBlock is templated with the kernel defined ISP configuration\n+ * block type. This function allows users to easily cast a V4L2ParamsBlock to\n+ * the underlying kernel-defined type in order to easily populate or read\n+ * the ISP configuration data.\n+ *\n+ * \\code{.cpp}\n+ *\n+ * // The kernel header defines the ISP configuration types, in example\n+ * // struct my_isp_awb_config_data {\n+ * //\t\tu16 gain_ch00;\n+ * //\t\tu16 gain_ch01;\n+ * //\t\tu16 gain_ch10;\n+ * //\t\tu16 gain_ch11;\n+ * //\n+ * // }\n+ *\n+ * template<> V4L2ParamsBlock<struct my_isp_awb_config_data> awbBlock\n+ *\n+ * awbBlock->gain_ch00 = ...;\n+ * awbBlock->gain_ch01 = ...;\n+ * awbBlock->gain_ch10 = ...;\n+ * awbBlock->gain_ch11 = ...;\n+ *\n+ * \\endcode\n+ *\n+ * Users of this class are not expected to create a V4L2ParamsBlock manually but\n+ * should rather use V4L2Params::block() to retrieve a reference to the memory\n+ * area used to construct a V4L2ParamsBlock<T> in their overloaded\n+ * implementation of V4L2Params::block().\n+ */\n+\n+/**\n+ * \\fn V4L2ParamsBlock::operator->() const\n+ * \\copydoc V4L2ParamsBlock::operator->()\n+ */\n+\n+/**\n+ * \\fn V4L2ParamsBlock::operator*() const\n+ * \\copydoc V4L2ParamsBlock::operator->()\n+ */\n+\n+/**\n+ * \\fn V4L2ParamsBlock::operator*()\n+ * \\copydoc V4L2ParamsBlock::operator->()\n+ */\n+\n+ /**\n+ * \\class V4L2Params\n+ * \\brief Helper class that represent an ISP configuration buffer\n+ *\n+ * ISP implementation compatible with v4l2-params define their ISP configuration\n+ * buffer types compatible with the struct v4l2_params_buffer type.\n+ *\n+ * This class represents an ISP configuration buffer. It is constructed\n+ * with a reference to the memory mapped buffer that will be queued to the ISP.\n+ *\n+ * This class is templated with the type of the enumeration of ISP blocks that\n+ * each IPA module is expected to support. IPA modules are expected to derive\n+ * this class and use the V4L2Params::block() function to retrieve the memory\n+ * area for each ISP configuration block and use it to construct a\n+ * V4L2ParamsBlock<T> with it before returning it to the user.\n+ *\n+ * \\code{.cpp}\n+ *\n+ * enum class myISPBlocks {\n+ *\tAgc,\n+ *\tAwb,\n+ *\t...\n+ * };\n+ *\n+ * template<myISPBlocks B>\n+ * struct block_type {\n+ * };\n+ *\n+ * template<>\n+ * struct block_type<myISPBlock::Agc> {\n+ *\tusing type = struct my_isp_kernel_config_type_agc;\n+ * };\n+ *\n+ * template<>\n+ * struct block_type<myISPBlock::Awb> {\n+ *\tusing type = struct my_isp_kernel_config_type_awb;\n+ * };\n+ *\n+ * ...\n+ *\n+ * class MyISPParams : public V4L2Params<myISPBlocks>\n+ * {\n+ * public:\n+ * \ttemplate<myISPBlocks B>\n+ * \tauto block()\n+ * \t{\n+ *\n+ * \t\t// Use the kernel defined configuration type as template\n+ * \t\t// argument to V4L2ParamsBlock.\n+ * \t\tusing Type = typename details::block_type<B>::type;\n+ *\n+ * \t\t// Each IPA module should provide the information required\n+ * \t\t// to populate the block header\n+ *\n+ * \t\t...\n+ *\n+ * \t\tauto data = V4L2Params::block(B, blockType, blockSize);\n+ *\n+ * \t\treturn V4L2ParamsBlock<Type>(data);\n+ * \t}\n+ * };\n+ *\n+ * \\endcode\n+ *\n+ * As an example, see the RkISP1Params and MaliC55Params implementations.\n+ */\n+\n+/**\n+ * \\fn V4L2Params::V4L2Params()\n+ * \\brief Construct a V4L2Params\n+ * \\param[in] data Reference to the v4l2-buffer memory mapped area\n+ * \\param[in] version The ISP parameters version the implementation supports\n+ */\n+\n+/**\n+ * \\fn V4L2Params::size()\n+ * \\brief Retrieve the used size of the parameters buffer (in bytes)\n+ *\n+ * The parameters buffer size is mostly used to populate the v4l2_buffer\n+ * bytesused field before queueing the buffer to the ISP.\n+ *\n+ * \\return The number of bytes occupied by the ISP configuration parameters\n+ */\n+\n+/**\n+ * \\fn V4L2Params::block()\n+ * \\brief Populate an ISP configuration block a returns a reference to its\n+ * memory\n+ * \\param[in] type The ISP block identifier enumerated by the IPA module\n+ * \\param[in] blockType The kernel-defined ISP block identifier, used to\n+ * populate the block header\n+ * \\param[in] blockSize The ISP block size, used to populate the block header\n+ *\n+ *\n+ * Initialize the block header with \\a blockType and \\a blockSize and\n+ * returns a reference to the memory used to store an ISP configuration block.\n+ *\n+ * IPA modules that derive the V4L2Params class shall use this function to\n+ * retrieve the memory area that will be used to construct a V4L2ParamsBlock<T>\n+ * before returning it to the caller.\n+ */\n+\n+/**\n+ * \\var V4L2Params::data_\n+ * \\brief The ISP parameters buffer memory\n+ */\n+\n+/**\n+ * \\var V4L2Params::used_\n+ * \\brief The number of bytes used in the parameters buffer\n+ */\n+\n+/**\n+ * \\var V4L2Params::blocks_\n+ * \\brief Cache of ISP configuration blocks\n+ */\n+\n+} /* namespace ipa */\n+\n+} /* namespace libcamera */\ndiff --git a/src/ipa/libipa/v4l2_params.h b/src/ipa/libipa/v4l2_params.h\nnew file mode 100644\nindex 0000000000000000000000000000000000000000..5586096c7ee8a2d20877838564e8074e0fc3d1ce\n--- /dev/null\n+++ b/src/ipa/libipa/v4l2_params.h\n@@ -0,0 +1,135 @@\n+/* SPDX-License-Identifier: LGPL-2.1-or-later */\n+/*\n+ * Copyright (C) 2025, Ideas On Board\n+ *\n+ * V4L2 Parameters\n+ */\n+\n+#pragma once\n+\n+#include <map>\n+#include <stdint.h>\n+#include <string.h>\n+\n+#include <linux/media/v4l2-extensible-params.h>\n+\n+#include <libcamera/base/class.h>\n+#include <libcamera/base/span.h>\n+\n+namespace libcamera {\n+\n+namespace ipa {\n+\n+template<typename T>\n+class V4L2ParamsBlock\n+{\n+public:\n+\tV4L2ParamsBlock(const Span<uint8_t> &data)\n+\t{\n+\t\theader_ = data.subspan(0, sizeof(v4l2_params_block_header));\n+\t\tdata_ = data.subspan(sizeof(v4l2_params_block_header));\n+\t}\n+\n+\tvoid setEnabled(bool enabled)\n+\t{\n+\t\tstruct v4l2_params_block_header *header =\n+\t\t\treinterpret_cast<struct v4l2_params_block_header *>(header_.data());\n+\n+\t\theader->flags &= ~(V4L2_PARAMS_FL_BLOCK_ENABLE |\n+\t\t\t\t V4L2_PARAMS_FL_BLOCK_DISABLE);\n+\t\theader->flags |= enabled ? V4L2_PARAMS_FL_BLOCK_ENABLE\n+\t\t\t\t\t : V4L2_PARAMS_FL_BLOCK_DISABLE;\n+\t}\n+\n+\tSpan<uint8_t> header() const { return header_; }\n+\tSpan<uint8_t> data() const { return data_; }\n+\n+\tconst T *operator->() const\n+\t{\n+\t\treturn reinterpret_cast<const T *>(data().data());\n+\t}\n+\n+\tT *operator->()\n+\t{\n+\t\treturn reinterpret_cast<T *>(data().data());\n+\t}\n+\n+\tconst T &operator*() const\n+\t{\n+\t\treturn *reinterpret_cast<const T *>(data().data());\n+\t}\n+\n+\tT &operator*()\n+\t{\n+\t\treturn *reinterpret_cast<T *>(data().data());\n+\t}\n+\n+private:\n+\tLIBCAMERA_DISABLE_COPY(V4L2ParamsBlock)\n+\n+\tSpan<uint8_t> header_;\n+\tSpan<uint8_t> data_;\n+};\n+\n+template<typename T>\n+class V4L2Params\n+{\n+public:\n+\tV4L2Params(Span<uint8_t> data, unsigned int version)\n+\t\t: data_(data)\n+\t{\n+\t\tstruct v4l2_params_buffer *cfg =\n+\t\t\treinterpret_cast<struct v4l2_params_buffer *>(data_.data());\n+\t\tcfg->data_size = 0;\n+\t\tcfg->version = version;\n+\t\tused_ = offsetof(struct v4l2_params_buffer, data);\n+\t}\n+\n+\tsize_t size() const { return used_; }\n+\n+protected:\n+\tSpan<uint8_t> block(T type, unsigned int blockType, size_t blockSize)\n+\t{\n+\t\t/*\n+\t\t * Look up the block in the cache first. If an algorithm\n+\t\t * requests the same block type twice, it should get the same\n+\t\t * block.\n+\t\t */\n+\t\tauto cacheIt = blocks_.find(type);\n+\t\tif (cacheIt != blocks_.end())\n+\t\t\treturn cacheIt->second;\n+\n+\t\t/* Make sure we don't run out of space. */\n+\t\tif (blockSize > data_.size() - used_)\n+\t\t\treturn {};\n+\n+\t\t/* Allocate a new block, clear its memory, and initialize its header. */\n+\t\tSpan<uint8_t> block = data_.subspan(used_, blockSize);\n+\t\tused_ += blockSize;\n+\n+\t\tstruct v4l2_params_buffer *cfg =\n+\t\t\treinterpret_cast<struct v4l2_params_buffer *>(data_.data());\n+\t\tcfg->data_size += blockSize;\n+\n+\t\tmemset(block.data(), 0, block.size());\n+\n+\t\tstruct v4l2_params_block_header *header =\n+\t\t\treinterpret_cast<struct v4l2_params_block_header *>(block.data());\n+\t\theader->type = blockType;\n+\t\theader->size = block.size();\n+\n+\t\t/* Update the cache. */\n+\t\tblocks_[type] = block;\n+\n+\t\treturn block;\n+\t}\n+\n+\tSpan<uint8_t> data_;\n+\tsize_t used_;\n+\n+\tstd::map<T, Span<uint8_t>> blocks_;\n+};\n+\n+} /* namespace ipa */\n+\n+} /* namespace libcamera */\ndiff --git a/src/ipa/rkisp1/params.cpp b/src/ipa/rkisp1/params.cpp\nindex 4c0b051ce65da1686323ee9c66b82e12669a754d..2b692e1a1f199d6c118af0938e1aaecef6186a2c 100644\n--- a/src/ipa/rkisp1/params.cpp\n+++ b/src/ipa/rkisp1/params.cpp\n@@ -35,7 +35,7 @@ struct BlockTypeInfo {\n #define RKISP1_BLOCK_TYPE_ENTRY(block, id, type, category, bit)\t\t\t\\\n \t{ BlockType::block, {\t\t\t\t\t\t\t\\\n \t\tRKISP1_EXT_PARAMS_BLOCK_TYPE_##id,\t\t\t\t\\\n-\t\tsizeof(struct rkisp1_cif_isp_##type##_config),\t\t\t\\\n+\t\tsizeof(struct rkisp1_ext_params_##type##_config),\t\t\\\n \t\toffsetof(struct rkisp1_params_cfg, category.type##_config),\t\\\n \t\tRKISP1_CIF_ISP_MODULE_##bit,\t\t\t\t\t\\\n \t} }\n@@ -49,7 +49,7 @@ struct BlockTypeInfo {\n #define RKISP1_BLOCK_TYPE_ENTRY_EXT(block, id, type)\t\t\t\t\\\n \t{ BlockType::block, {\t\t\t\t\t\t\t\\\n \t\tRKISP1_EXT_PARAMS_BLOCK_TYPE_##id,\t\t\t\t\\\n-\t\tsizeof(struct rkisp1_cif_isp_##type##_config),\t\t\t\\\n+\t\tsizeof(struct rkisp1_ext_params_##type##_config),\t\t\\\n \t\t0, 0,\t\t\t\t\t\t\t\t\\\n \t} }\n \n@@ -78,56 +78,6 @@ const std::map<BlockType, BlockTypeInfo> kBlockTypeInfo = {\n \n } /* namespace */\n \n-RkISP1ParamsBlockBase::RkISP1ParamsBlockBase(RkISP1Params *params, BlockType type,\n-\t\t\t\t\t const Span<uint8_t> &data)\n-\t: params_(params), type_(type)\n-{\n-\tif (params_->format() == V4L2_META_FMT_RK_ISP1_EXT_PARAMS) {\n-\t\theader_ = data.subspan(0, sizeof(rkisp1_ext_params_block_header));\n-\t\tdata_ = data.subspan(sizeof(rkisp1_ext_params_block_header));\n-\t} else {\n-\t\tdata_ = data;\n-\t}\n-}\n-\n-void RkISP1ParamsBlockBase::setEnabled(bool enabled)\n-{\n-\t/*\n-\t * For the legacy fixed format, blocks are enabled in the top-level\n-\t * header. Delegate to the RkISP1Params class.\n-\t */\n-\tif (params_->format() == V4L2_META_FMT_RK_ISP1_PARAMS)\n-\t\treturn params_->setBlockEnabled(type_, enabled);\n-\n-\t/*\n-\t * For the extensible format, set the enable and disable flags in the\n-\t * block header directly.\n-\t */\n-\tstruct rkisp1_ext_params_block_header *header =\n-\t\treinterpret_cast<struct rkisp1_ext_params_block_header *>(header_.data());\n-\theader->flags &= ~(RKISP1_EXT_PARAMS_FL_BLOCK_ENABLE |\n-\t\t\t RKISP1_EXT_PARAMS_FL_BLOCK_DISABLE);\n-\theader->flags |= enabled ? RKISP1_EXT_PARAMS_FL_BLOCK_ENABLE\n-\t\t\t\t : RKISP1_EXT_PARAMS_FL_BLOCK_DISABLE;\n-}\n-\n-RkISP1Params::RkISP1Params(uint32_t format, Span<uint8_t> data)\n-\t: format_(format), data_(data), used_(0)\n-{\n-\tif (format_ == V4L2_META_FMT_RK_ISP1_EXT_PARAMS) {\n-\t\tstruct rkisp1_ext_params_cfg *cfg =\n-\t\t\treinterpret_cast<struct rkisp1_ext_params_cfg *>(data.data());\n-\n-\t\tcfg->version = RKISP1_EXT_PARAM_BUFFER_V1;\n-\t\tcfg->data_size = 0;\n-\n-\t\tused_ += offsetof(struct rkisp1_ext_params_cfg, data);\n-\t} else {\n-\t\tmemset(data.data(), 0, data.size());\n-\t\tused_ = sizeof(struct rkisp1_params_cfg);\n-\t}\n-}\n-\n void RkISP1Params::setBlockEnabled(BlockType type, bool enabled)\n {\n \tconst BlockTypeInfo &info = kBlockTypeInfo.at(type);\n@@ -177,44 +127,7 @@ Span<uint8_t> RkISP1Params::block(BlockType type)\n \t\treturn data_.subspan(info.offset, info.size);\n \t}\n \n-\t/*\n-\t * For the extensible format, allocate memory for the block, including\n-\t * the header. Look up the block in the cache first. If an algorithm\n-\t * requests the same block type twice, it should get the same block.\n-\t */\n-\tauto cacheIt = blocks_.find(type);\n-\tif (cacheIt != blocks_.end())\n-\t\treturn cacheIt->second;\n-\n-\t/* Make sure we don't run out of space. */\n-\tsize_t size = sizeof(struct rkisp1_ext_params_block_header)\n-\t\t + ((info.size + 7) & ~7);\n-\tif (size > data_.size() - used_) {\n-\t\tLOG(RkISP1Params, Error)\n-\t\t\t<< \"Out of memory to allocate block type \"\n-\t\t\t<< utils::to_underlying(type);\n-\t\treturn {};\n-\t}\n-\n-\t/* Allocate a new block, clear its memory, and initialize its header. */\n-\tSpan<uint8_t> block = data_.subspan(used_, size);\n-\tused_ += size;\n-\n-\tstruct rkisp1_ext_params_cfg *cfg =\n-\t\treinterpret_cast<struct rkisp1_ext_params_cfg *>(data_.data());\n-\tcfg->data_size += size;\n-\n-\tmemset(block.data(), 0, block.size());\n-\n-\tstruct rkisp1_ext_params_block_header *header =\n-\t\treinterpret_cast<struct rkisp1_ext_params_block_header *>(block.data());\n-\theader->type = info.type;\n-\theader->size = block.size();\n-\n-\t/* Update the cache. */\n-\tblocks_[type] = block;\n-\n-\treturn block;\n+\treturn V4L2Params::block(type, info.type, info.size);\n }\n \n } /* namespace ipa::rkisp1 */\ndiff --git a/src/ipa/rkisp1/params.h b/src/ipa/rkisp1/params.h\nindex 40450e34497a3aa71b5b0cda2bf045a1cc0e012f..7a21276648162a127317c75cb01d1c0059b96ee1 100644\n--- a/src/ipa/rkisp1/params.h\n+++ b/src/ipa/rkisp1/params.h\n@@ -7,13 +7,10 @@\n \n #pragma once\n \n-#include <map>\n-#include <stdint.h>\n-\n #include <linux/rkisp1-config.h>\n+#include <linux/videodev2.h>\n \n-#include <libcamera/base/class.h>\n-#include <libcamera/base/span.h>\n+#include <libipa/v4l2_params.h>\n \n namespace libcamera {\n \n@@ -77,85 +74,72 @@ RKISP1_DEFINE_BLOCK_TYPE(CompandCompress, compand_curve)\n \n } /* namespace details */\n \n-class RkISP1Params;\n+template<typename T>\n+class RkISP1ParamsBlock;\n \n-class RkISP1ParamsBlockBase\n+class RkISP1Params : public V4L2Params<BlockType>\n {\n public:\n-\tRkISP1ParamsBlockBase(RkISP1Params *params, BlockType type,\n-\t\t\t const Span<uint8_t> &data);\n-\n-\tSpan<uint8_t> data() const { return data_; }\n-\n-\tvoid setEnabled(bool enabled);\n+\tstatic constexpr unsigned int kVersion = RKISP1_EXT_PARAM_BUFFER_V1;\n \n-private:\n-\tLIBCAMERA_DISABLE_COPY(RkISP1ParamsBlockBase)\n-\n-\tRkISP1Params *params_;\n-\tBlockType type_;\n-\tSpan<uint8_t> header_;\n-\tSpan<uint8_t> data_;\n-};\n-\n-template<BlockType B>\n-class RkISP1ParamsBlock : public RkISP1ParamsBlockBase\n-{\n-public:\n-\tusing Type = typename details::block_type<B>::type;\n-\n-\tRkISP1ParamsBlock(RkISP1Params *params, const Span<uint8_t> &data)\n-\t\t: RkISP1ParamsBlockBase(params, B, data)\n+\tRkISP1Params(uint32_t format, Span<uint8_t> data)\n+\t\t: V4L2Params<BlockType>(data, kVersion), format_(format)\n \t{\n+\t\tif (format_ == V4L2_META_FMT_RK_ISP1_PARAMS) {\n+\t\t\tmemset(data.data(), 0, data.size());\n+\t\t\tused_ = sizeof(struct rkisp1_params_cfg);\n+\t\t}\n \t}\n \n-\tconst Type *operator->() const\n+\ttemplate<BlockType B>\n+\tauto block()\n \t{\n-\t\treturn reinterpret_cast<const Type *>(data().data());\n-\t}\n+\t\tusing Type = typename details::block_type<B>::type;\n \n-\tType *operator->()\n-\t{\n-\t\treturn reinterpret_cast<Type *>(data().data());\n+\t\treturn RkISP1ParamsBlock<Type>(this, B, block(B));\n \t}\n \n-\tconst Type &operator*() const &\n-\t{\n-\t\treturn *reinterpret_cast<const Type *>(data().data());\n-\t}\n+\tuint32_t format() const { return format_; }\n+\tvoid setBlockEnabled(BlockType type, bool enabled);\n \n-\tType &operator*() &\n-\t{\n-\t\treturn *reinterpret_cast<Type *>(data().data());\n-\t}\n+private:\n+\tSpan<uint8_t> block(BlockType type);\n+\n+\tuint32_t format_;\n };\n \n-class RkISP1Params\n+template<typename T>\n+class RkISP1ParamsBlock : public V4L2ParamsBlock<T>\n {\n public:\n-\tRkISP1Params(uint32_t format, Span<uint8_t> data);\n-\n-\ttemplate<BlockType B>\n-\tRkISP1ParamsBlock<B> block()\n+\tRkISP1ParamsBlock(RkISP1Params *params, BlockType type,\n+\t\t\t const Span<uint8_t> &data)\n+\t\t: V4L2ParamsBlock<T>(data)\n \t{\n-\t\treturn RkISP1ParamsBlock<B>(this, block(B));\n+\t\tparams_ = params;\n+\t\ttype_ = type;\n+\n+\t\t/* Legacy param format has no header */\n+\t\tif (params_->format() == V4L2_META_FMT_RK_ISP1_PARAMS)\n+\t\t\tdata_ = data;\n \t}\n \n-\tuint32_t format() const { return format_; }\n-\tsize_t size() const { return used_; }\n+\tvoid setEnabled(bool enabled)\n+\t{\n+\t\t/*\n+\t\t * For the legacy fixed format, blocks are enabled in the\n+\t\t * top-level header. Delegate to the RkISP1Params class.\n+\t\t */\n+\t\tif (params_->format() == V4L2_META_FMT_RK_ISP1_PARAMS)\n+\t\t\treturn params_->setBlockEnabled(type_, enabled);\n+\n+\t\treturn V4L2ParamsBlock<T>::setEnabled(enabled);\n+\t}\n \n private:\n-\tfriend class RkISP1ParamsBlockBase;\n-\n-\tSpan<uint8_t> block(BlockType type);\n-\tvoid setBlockEnabled(BlockType type, bool enabled);\n-\n-\tuint32_t format_;\n-\n+\tRkISP1Params *params_;\n+\tBlockType type_;\n \tSpan<uint8_t> data_;\n-\tsize_t used_;\n-\n-\tstd::map<BlockType, Span<uint8_t>> blocks_;\n };\n \n } /* namespace ipa::rkisp1 */\n", "prefixes": [ "3/4" ] }