Show a patch.

GET /api/patches/24572/?format=api
HTTP 200 OK
Allow: GET, PUT, PATCH, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "id": 24572,
    "url": "https://patchwork.libcamera.org/api/patches/24572/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/24572/",
    "project": {
        "id": 1,
        "url": "https://patchwork.libcamera.org/api/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": "<20251007-v4l2-params-v5-4-8db451a81398@ideasonboard.com>",
    "date": "2025-10-07T18:17:46",
    "name": "[v5,4/5] ipa: libipa: Introduce V4L2Params",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": false,
    "hash": "c8a763b32ad748017dacab679d9d311585a5ca11",
    "submitter": {
        "id": 143,
        "url": "https://patchwork.libcamera.org/api/people/143/?format=api",
        "name": "Jacopo Mondi",
        "email": "jacopo.mondi@ideasonboard.com"
    },
    "delegate": null,
    "mbox": "https://patchwork.libcamera.org/patch/24572/mbox/",
    "series": [
        {
            "id": 5480,
            "url": "https://patchwork.libcamera.org/api/series/5480/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=5480",
            "date": "2025-10-07T18:17:42",
            "name": "ipa: libipa: Introduce V4L2Params",
            "version": 5,
            "mbox": "https://patchwork.libcamera.org/series/5480/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/24572/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/24572/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 0387BC3331\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue,  7 Oct 2025 18:18:06 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id AD3496B5FB;\n\tTue,  7 Oct 2025 20:18:02 +0200 (CEST)",
            "from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 984D869367\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue,  7 Oct 2025 20:17:54 +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 D507A929;\n\tTue,  7 Oct 2025 20:16:20 +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=\"qgNdtOVj\"; dkim-atps=neutral",
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1759860981;\n\tbh=QL3MTLEBQm/qYiMts0LIodVBCXeBkVxpuN+oz2tSuqw=;\n\th=From:Date:Subject:References:In-Reply-To:To:Cc:From;\n\tb=qgNdtOVjIfwkZY9HaFxPpFwbw6yWpKRv2esga7ELr/KPuqhEVJd/5a0ySjVSKgw3o\n\tXnB3jzs9lX3dZPhLfS6o7q4KwXKMn3RR6MHiopKOpMF3RBCeIHN50bkujRmmD4P6lD\n\tpV5+Oad3bSTXIpoV9tn9crwS53mB9DrZS08qGHTc=",
        "From": "Jacopo Mondi <jacopo.mondi@ideasonboard.com>",
        "Date": "Tue, 07 Oct 2025 20:17:46 +0200",
        "Subject": "[PATCH v5 4/5] ipa: libipa: Introduce V4L2Params",
        "MIME-Version": "1.0",
        "Content-Type": "text/plain; charset=\"utf-8\"",
        "Content-Transfer-Encoding": "7bit",
        "Message-Id": "<20251007-v4l2-params-v5-4-8db451a81398@ideasonboard.com>",
        "References": "<20251007-v4l2-params-v5-0-8db451a81398@ideasonboard.com>",
        "In-Reply-To": "<20251007-v4l2-params-v5-0-8db451a81398@ideasonboard.com>",
        "To": "libcamera-devel@lists.libcamera.org",
        "Cc": "Jacopo Mondi <jacopo.mondi@ideasonboard.com>, \n\tAntoine Bouyer <antoine.bouyer@nxp.com>",
        "X-Mailer": "b4 0.14.2",
        "X-Developer-Signature": "v=1; a=openpgp-sha256; l=25310;\n\ti=jacopo.mondi@ideasonboard.com; h=from:subject:message-id;\n\tbh=QL3MTLEBQm/qYiMts0LIodVBCXeBkVxpuN+oz2tSuqw=;\n\tb=owEBbQKS/ZANAwAKAXI0Bo8WoVY8AcsmYgBo5VlQ/B56byzq/qvKRSBSn3h4sJ3Aki4WRffg2\n\tHZ+8EWw6vKJAjMEAAEKAB0WIQS1xD1IgJogio9YOMByNAaPFqFWPAUCaOVZUAAKCRByNAaPFqFW\n\tPMAfD/9plf4l2C4fKBI+CnWMGeEEpqDmWhNSlhiIWg8m76SU70aYo4CyE/CUldrNZ4N417YpL1H\n\ts+0nd+5UEnBQpk9z/wgrVwZAKEDr10WTPoLcVHPNRQL/qucDD5FE9pn8brsfTlETQKtpAGlJSAY\n\tze+afcJQxYrM0QkGIYQjZ4UpU5FOqAfAJL19XUUZ4NGopT8ApggHWOZ9oXNruiC9l3RpWjg1crM\n\ttFF6SLQhIA5w3RYfGto3EXntltbtlUSSMzXU5UszDX97G08i7QvjFYjlk6l9zOoLspTtD6GQS43\n\t3XBJTagHGaHlsx3e7ci1+jJFOGtGx6ovEDqylOQjqg0tS7Hgc8N5sV9JlhJeuyQNlCzzSHVFmUm\n\tDOIliHXdL5jaZ81botcpZBeqKDrHYDYj6q1gNJKFeMuY1S7Jar7QaIPkYDfOmNxaRy6F5xzogk+\n\tBpOG5xkPjPop1dLHRE72G2xc1JPLbAanlrAumP8U2tMEyysF7S7yuLdE8gTN7MXmAFBb+z1xETZ\n\ttf9ebZky9VcUPObInWMURH+jikEau1o6G8qunZlFSEVbKtYvKy6zPj0vNK+aqr6iw5ENTB04kml\n\t7hIYwrUySYYgpGr3LOO1LhUW6Pc8pGqMBKrNGpycV93i5qiSRwBuKVOVMJ1lcx7CoLwW+BZUfpc\n\tQwofAYyLpGrQoJQ==",
        "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 class allows the RkISP1 IPA to handle\nboth the extensible parameters format and the legacy fixed-size format.\n\nWith the introduction of v4l2-isp.h 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 parameters buffer compatible with v4l2-isp.h.\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>\nTested-by: Antoine Bouyer <antoine.bouyer@nxp.com>\n---\n src/ipa/libipa/meson.build     |   2 +\n src/ipa/libipa/v4l2_params.cpp | 254 +++++++++++++++++++++++++++++++++++++++++\n src/ipa/libipa/v4l2_params.h   | 142 +++++++++++++++++++++++\n src/ipa/rkisp1/params.cpp      |  93 +--------------\n src/ipa/rkisp1/params.h        | 175 ++++++++++++++++------------\n 5 files changed, 501 insertions(+), 165 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..278b5e4259be4798d0f719c8b1876ef654a14c75\n--- /dev/null\n+++ b/src/ipa/libipa/v4l2_params.cpp\n@@ -0,0 +1,254 @@\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 an ISP configuration buffer compatible with\n+ * the generic V4L2 ISP format\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 ISP generic parameters. The\n+ * V4L2 ISP parameters define a serialization format for ISP parameters that\n+ * allows userspace to populate a buffer of configuration data by appending them\n+ * one after the other in a binary buffer.\n+ *\n+ * The V4L2Params class implementes support for working with V4L2 ISP parameters\n+ * buffer and allows users to populate the ISP configuration blocks, represented\n+ * as 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 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::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 shall not create a V4L2ParamsBlock manually but should\n+ * use 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+ * \\var V4L2ParamsBlock::data_\n+ * \\brief Memory area reserved for the ISP configuration block\n+ */\n+\n+ /**\n+  * \\class V4L2Params\n+  * \\brief Helper class that represent an ISP configuration buffer\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+ * driver.\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 by providing a 'param_traits' type the helps the class associate\n+ * a block type with the actual memory area that represents the ISP\n+ * configuration block.\n+ *\n+ * \\code{.cpp}\n+ *\n+ * // Define the supported ISP blocks\n+ * enum class myISPBlocks {\n+ *\tAgc,\n+ *\tAwb,\n+ *\t...\n+ * };\n+ *\n+ * // Maps the C++ enum type to the kernel enum type and concrete parameter type\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+ *\tstatic constexpr kernel_enum_type blockType = MY_ISP_TYPE_AGC;\n+ * };\n+ *\n+ * template<>\n+ * struct block_type<myISPBlock::Awb> {\n+ *\tusing type = struct my_isp_kernel_config_type_awb;\n+ *\tstatic constexpr kernel_enum_type blockType = MY_ISP_TYPE_AWB;\n+ * };\n+ *\n+ *\n+ * // Convenience type to associate a block id to the 'block_type' overload\n+ * struct params_traits {\n+ * \tusing id_type = myISPBlocks;\n+ * \ttemplate<id_type Id> using id_to_details = block_type<Id>;\n+ * };\n+ *\n+ * ...\n+ *\n+ * // Derive the V4L2Params class by providing params_traits\n+ * class MyISPParams : public V4L2Params<params_traits>\n+ * {\n+ * public:\n+ * \tMyISPParams::MyISPParams(Span<uint8_t> data)\n+ * \t\t: V4L2Params(data, kVersion)\n+ * \t{\n+ * \t}\n+ * };\n+ *\n+ * \\endcode\n+ *\n+ * Users of this class can then easily access an ISP configuration block as a\n+ * V4L2ParamsBlock instance.\n+ *\n+ * \\code{.cpp}\n+ *\n+ * MyISPParams params(data);\n+ *\n+ * auto awb = params.block<myISPBlocks::AWB>();\n+ * awb->gain00 = ...;\n+ * awb->gain01 = ...;\n+ * awb->gain10 = ...;\n+ * awb->gain11 = ...;\n+ * \\endcode\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 Retrieve the location of an ISP configuration block a returns it\n+ * \\return A V4L2ParamsBlock instance that points to the ISP configuration block\n+ */\n+\n+/**\n+ * \\fn V4L2Params::block(typename Traits::id_type type, unsigned int blockType, size_t blockSize)\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+ * 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..bf98bb2aba88506e3ad304a995505deba8e0712a\n--- /dev/null\n+++ b/src/ipa/libipa/v4l2_params.h\n@@ -0,0 +1,142 @@\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-isp.h>\n+\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\t: data_(data)\n+\t{\n+\t}\n+\n+\tvirtual ~V4L2ParamsBlock() {}\n+\n+\tvirtual void setEnabled(bool enabled)\n+\t{\n+\t\tstruct v4l2_isp_params_block_header *header =\n+\t\t\treinterpret_cast<struct v4l2_isp_params_block_header *>(data_.data());\n+\n+\t\theader->flags &= ~(V4L2_ISP_PARAMS_FL_BLOCK_ENABLE |\n+\t\t\t\t   V4L2_ISP_PARAMS_FL_BLOCK_DISABLE);\n+\t\theader->flags |= enabled ? V4L2_ISP_PARAMS_FL_BLOCK_ENABLE\n+\t\t\t\t\t : V4L2_ISP_PARAMS_FL_BLOCK_DISABLE;\n+\t}\n+\n+\tvirtual const T *operator->() const\n+\t{\n+\t\treturn reinterpret_cast<const T *>(data_.data());\n+\t}\n+\n+\tvirtual T *operator->()\n+\t{\n+\t\treturn reinterpret_cast<T *>(data_.data());\n+\t}\n+\n+\tvirtual const T &operator*() const\n+\t{\n+\t\treturn *reinterpret_cast<const T *>(data_.data());\n+\t}\n+\n+\tvirtual T &operator*()\n+\t{\n+\t\treturn *reinterpret_cast<T *>(data_.data());\n+\t}\n+\n+protected:\n+\tSpan<uint8_t> data_;\n+};\n+\n+template<typename Traits>\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_isp_params_buffer *cfg =\n+\t\t\treinterpret_cast<struct v4l2_isp_params_buffer *>(data_.data());\n+\t\tcfg->data_size = 0;\n+\t\tcfg->version = version;\n+\t\tused_ = offsetof(struct v4l2_isp_params_buffer, data);\n+\t}\n+\n+\tsize_t size() const { return used_; }\n+\n+\ttemplate<typename Traits::id_type Id>\n+\tauto block()\n+\t{\n+\t\tusing Details = typename Traits::template id_to_details<Id>;\n+\n+\t\tusing Type = typename Details::type;\n+\t\tconstexpr auto kernelId = Details::blockType;\n+\n+\t\tauto data = block(Id, kernelId, sizeof(Type));\n+\t\treturn V4L2ParamsBlock<Type>(data);\n+\t}\n+\n+protected:\n+\tSpan<uint8_t> block(typename Traits::id_type type,\n+\t\t\t    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_isp_params_buffer *cfg =\n+\t\t\treinterpret_cast<struct v4l2_isp_params_buffer *>(data_.data());\n+\t\tcfg->data_size += blockSize;\n+\n+\t\tmemset(block.data(), 0, block.size());\n+\n+\t\tstruct v4l2_isp_params_block_header *header =\n+\t\t\treinterpret_cast<struct v4l2_isp_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<typename Traits::id_type, 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 5edb36c91b87859d02c0a8b41efe977ff048def5..7040207c26557aa278050a1f7232cc6c380505b1 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@@ -79,56 +79,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@@ -178,44 +128,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 2e60528d102ec44a31417d4b146e74cace363efa..eddb37d5c000b6b1de1c698ad915f2b42da58b81 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@@ -49,115 +46,143 @@ template<BlockType B>\n struct block_type {\n };\n \n-#define RKISP1_DEFINE_BLOCK_TYPE(blockType, blockStruct)\t\t\\\n+#define RKISP1_DEFINE_BLOCK_TYPE(blockType, blockStruct, id)\t\t\\\n template<>\t\t\t\t\t\t\t\t\\\n struct block_type<BlockType::blockType> {\t\t\t\t\\\n \tusing type = struct rkisp1_cif_isp_##blockStruct##_config;\t\\\n+\tstatic constexpr rkisp1_ext_params_block_type blockType =\t\\\n+\t\tRKISP1_EXT_PARAMS_BLOCK_TYPE_##id;\t\t\t\\\n };\n \n-RKISP1_DEFINE_BLOCK_TYPE(Bls, bls)\n-RKISP1_DEFINE_BLOCK_TYPE(Dpcc, dpcc)\n-RKISP1_DEFINE_BLOCK_TYPE(Sdg, sdg)\n-RKISP1_DEFINE_BLOCK_TYPE(AwbGain, awb_gain)\n-RKISP1_DEFINE_BLOCK_TYPE(Flt, flt)\n-RKISP1_DEFINE_BLOCK_TYPE(Bdm, bdm)\n-RKISP1_DEFINE_BLOCK_TYPE(Ctk, ctk)\n-RKISP1_DEFINE_BLOCK_TYPE(Goc, goc)\n-RKISP1_DEFINE_BLOCK_TYPE(Dpf, dpf)\n-RKISP1_DEFINE_BLOCK_TYPE(DpfStrength, dpf_strength)\n-RKISP1_DEFINE_BLOCK_TYPE(Cproc, cproc)\n-RKISP1_DEFINE_BLOCK_TYPE(Ie, ie)\n-RKISP1_DEFINE_BLOCK_TYPE(Lsc, lsc)\n-RKISP1_DEFINE_BLOCK_TYPE(Awb, awb_meas)\n-RKISP1_DEFINE_BLOCK_TYPE(Hst, hst)\n-RKISP1_DEFINE_BLOCK_TYPE(Aec, aec)\n-RKISP1_DEFINE_BLOCK_TYPE(Afc, afc)\n-RKISP1_DEFINE_BLOCK_TYPE(CompandBls, compand_bls)\n-RKISP1_DEFINE_BLOCK_TYPE(CompandExpand, compand_curve)\n-RKISP1_DEFINE_BLOCK_TYPE(CompandCompress, compand_curve)\n-RKISP1_DEFINE_BLOCK_TYPE(Wdr, wdr)\n+RKISP1_DEFINE_BLOCK_TYPE(Bls, bls, BLS)\n+RKISP1_DEFINE_BLOCK_TYPE(Dpcc, dpcc, DPCC)\n+RKISP1_DEFINE_BLOCK_TYPE(Sdg, sdg, SDG)\n+RKISP1_DEFINE_BLOCK_TYPE(AwbGain, awb_gain, AWB_GAIN)\n+RKISP1_DEFINE_BLOCK_TYPE(Flt, flt, FLT)\n+RKISP1_DEFINE_BLOCK_TYPE(Bdm, bdm, BDM)\n+RKISP1_DEFINE_BLOCK_TYPE(Ctk, ctk, CTK)\n+RKISP1_DEFINE_BLOCK_TYPE(Goc, goc, GOC)\n+RKISP1_DEFINE_BLOCK_TYPE(Dpf, dpf, DPF)\n+RKISP1_DEFINE_BLOCK_TYPE(DpfStrength, dpf_strength, DPF_STRENGTH)\n+RKISP1_DEFINE_BLOCK_TYPE(Cproc, cproc, CPROC)\n+RKISP1_DEFINE_BLOCK_TYPE(Ie, ie, IE)\n+RKISP1_DEFINE_BLOCK_TYPE(Lsc, lsc, LSC)\n+RKISP1_DEFINE_BLOCK_TYPE(Awb, awb_meas, AWB_MEAS)\n+RKISP1_DEFINE_BLOCK_TYPE(Hst, hst, HST_MEAS)\n+RKISP1_DEFINE_BLOCK_TYPE(Aec, aec, AEC_MEAS)\n+RKISP1_DEFINE_BLOCK_TYPE(Afc, afc, AFC_MEAS)\n+RKISP1_DEFINE_BLOCK_TYPE(CompandBls, compand_bls, COMPAND_BLS)\n+RKISP1_DEFINE_BLOCK_TYPE(CompandExpand, compand_curve, COMPAND_EXPAND)\n+RKISP1_DEFINE_BLOCK_TYPE(CompandCompress, compand_curve, COMPAND_COMPRESS)\n+RKISP1_DEFINE_BLOCK_TYPE(Wdr, wdr, WDR)\n+\n+struct params_traits {\n+\tusing id_type = BlockType;\n+\n+\ttemplate<id_type Id>\n+\tusing id_to_details = block_type<Id>;\n+};\n \n } /* namespace details */\n \n-class RkISP1Params;\n+template<typename T>\n+class RkISP1ParamsBlock;\n \n-class RkISP1ParamsBlockBase\n+class RkISP1Params : public V4L2Params<details::params_traits>\n {\n public:\n-\tRkISP1ParamsBlockBase(RkISP1Params *params, BlockType type,\n-\t\t\t      const Span<uint8_t> &data);\n+\tstatic constexpr unsigned int kVersion = RKISP1_EXT_PARAM_BUFFER_V1;\n+\n+\tRkISP1Params(uint32_t format, Span<uint8_t> data)\n+\t\t: V4L2Params(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+\ttemplate<details::params_traits::id_type id>\n+\tauto block()\n+\t{\n+\t\tusing Type = typename details::block_type<id>::type;\n \n-\tSpan<uint8_t> data() const { return data_; }\n+\t\treturn RkISP1ParamsBlock<Type>(this, id, block(id));\n+\t}\n \n-\tvoid setEnabled(bool enabled);\n+\tuint32_t format() const { return format_; }\n+\tvoid setBlockEnabled(BlockType type, bool enabled);\n \n private:\n-\tLIBCAMERA_DISABLE_COPY(RkISP1ParamsBlockBase)\n+\tSpan<uint8_t> block(BlockType type);\n \n-\tRkISP1Params *params_;\n-\tBlockType type_;\n-\tSpan<uint8_t> header_;\n-\tSpan<uint8_t> data_;\n+\tuint32_t format_;\n };\n \n-template<BlockType B>\n-class RkISP1ParamsBlock : public RkISP1ParamsBlockBase\n+template<typename T>\n+class RkISP1ParamsBlock final : public V4L2ParamsBlock<T>\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+\tRkISP1ParamsBlock(RkISP1Params *params, BlockType type,\n+\t\t\t  const Span<uint8_t> data)\n+\t\t: V4L2ParamsBlock<T>(data)\n \t{\n+\t\tparams_ = params;\n+\t\ttype_ = type;\n+\n+\t\t/*\n+\t\t * cifData_ points to the actual configuration data\n+\t\t * (struct rkisp1_cif_isp_*) which is not prefixed by any header,\n+\t\t * for the legacy fixed format.\n+\t\t */\n+\t\tif (params_->format() == V4L2_META_FMT_RK_ISP1_PARAMS)\n+\t\t\tcifData_ = data;\n+\t\telse\n+\t\t\tcifData_ = data.subspan(sizeof(v4l2_isp_params_block_header));\n \t}\n \n-\tconst Type *operator->() const\n+\tvoid setEnabled(bool enabled) override\n \t{\n-\t\treturn reinterpret_cast<const Type *>(data().data());\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-\tType *operator->()\n+\t/*\n+\t * Override the dereference operators to return a reference to the\n+\t * actual configuration data (struct rkisp1_cif_isp_*) skipping the\n+\t * 'v4l2_isp_params_block_header' header.\n+\t */\n+\n+\tvirtual const T *operator->() const override\n \t{\n-\t\treturn reinterpret_cast<Type *>(data().data());\n+\t\treturn reinterpret_cast<const T *>(cifData_.data());\n \t}\n \n-\tconst Type &operator*() const &\n+\tvirtual T *operator->() override\n \t{\n-\t\treturn *reinterpret_cast<const Type *>(data().data());\n+\t\treturn reinterpret_cast<T *>(cifData_.data());\n \t}\n \n-\tType &operator*() &\n+\tvirtual const T &operator*() const override\n \t{\n-\t\treturn *reinterpret_cast<Type *>(data().data());\n+\t\treturn *reinterpret_cast<const T *>(cifData_.data());\n \t}\n-};\n-\n-class RkISP1Params\n-{\n-public:\n-\tRkISP1Params(uint32_t format, Span<uint8_t> data);\n \n-\ttemplate<BlockType B>\n-\tRkISP1ParamsBlock<B> block()\n+\tvirtual T &operator*() override\n \t{\n-\t\treturn RkISP1ParamsBlock<B>(this, block(B));\n+\t\treturn *reinterpret_cast<T *>(cifData_.data());\n \t}\n \n-\tuint32_t format() const { return format_; }\n-\tsize_t size() const { return used_; }\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-\tSpan<uint8_t> data_;\n-\tsize_t used_;\n-\n-\tstd::map<BlockType, Span<uint8_t>> blocks_;\n+\tRkISP1Params *params_;\n+\tBlockType type_;\n+\tSpan<uint8_t> cifData_;\n };\n \n } /* namespace ipa::rkisp1 */\n",
    "prefixes": [
        "v5",
        "4/5"
    ]
}