Show a patch.

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

{
    "id": 27442,
    "url": "https://patchwork.libcamera.org/api/patches/27442/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/27442/",
    "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": "<20260722-pi4-upstream-v2-7-eb44d3c6fd92@ideasonboard.com>",
    "date": "2026-07-22T11:23:23",
    "name": "[v2,7/8] pipeline/ipa: rpi: vc4: Switch configuration from controls to param buffer",
    "commit_ref": null,
    "pull_url": null,
    "state": "new",
    "archived": false,
    "hash": "429991d60739e568afba745f614199ce68b65c39",
    "submitter": {
        "id": 223,
        "url": "https://patchwork.libcamera.org/api/people/223/?format=api",
        "name": "Jai Luthra",
        "email": "jai.luthra@ideasonboard.com"
    },
    "delegate": null,
    "mbox": "https://patchwork.libcamera.org/patch/27442/mbox/",
    "series": [
        {
            "id": 6072,
            "url": "https://patchwork.libcamera.org/api/series/6072/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=6072",
            "date": "2026-07-22T11:23:16",
            "name": "Raspberry Pi: Update VC4 pipeline for mainline",
            "version": 2,
            "mbox": "https://patchwork.libcamera.org/series/6072/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/27442/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/27442/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 505C6BDE17\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed, 22 Jul 2026 11:25:23 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id F3C4767EA6;\n\tWed, 22 Jul 2026 13:25:22 +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 60A9C67E8A\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 22 Jul 2026 13:25:22 +0200 (CEST)",
            "from mail.ideasonboard.com (unknown\n\t[IPv6:2401:4900:1c68:25d4:fa24:78d1:31:7a56])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id B523F227;\n\tWed, 22 Jul 2026 13:24:21 +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=\"LhtdT3FF\"; dkim-atps=neutral",
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1784719462;\n\tbh=y8j33FOrgj+T6MZNVixp4/FvB4vadVLWSH3lF6GKzdM=;\n\th=From:Date:Subject:References:In-Reply-To:To:Cc:From;\n\tb=LhtdT3FFyWTiNnsoZYqpsIwL0aawRLAscgMGo4hxhTfzSV8NGXgS9Ut7za/FWbhwP\n\taN3KbwVKC9G1b8uUJBfrOi6ajrtCfhxEpbdxYPsPSj9VjKR6Bc7+/mn5cPniKVcyaT\n\tEe03DXq33FcO59BYVekIVpq7MdXLjtqO+U77hZyY=",
        "From": "Jai Luthra <jai.luthra@ideasonboard.com>",
        "Date": "Wed, 22 Jul 2026 16:53:23 +0530",
        "Subject": "[PATCH v2 7/8] pipeline/ipa: rpi: vc4: Switch configuration from\n\tcontrols to param buffer",
        "MIME-Version": "1.0",
        "Content-Type": "text/plain; charset=\"utf-8\"",
        "Content-Transfer-Encoding": "7bit",
        "Message-Id": "<20260722-pi4-upstream-v2-7-eb44d3c6fd92@ideasonboard.com>",
        "References": "<20260722-pi4-upstream-v2-0-eb44d3c6fd92@ideasonboard.com>",
        "In-Reply-To": "<20260722-pi4-upstream-v2-0-eb44d3c6fd92@ideasonboard.com>",
        "To": "libcamera-devel@lists.libcamera.org",
        "Cc": "Naushir Patuck <naush@raspberrypi.com>, \n\tDavid Plowman <david.plowman@raspberrypi.com>, \n\tLaurent Pinchart <laurent.pinchart@ideasonboard.com>, \n\tKieran Bingham <kieran.bingham@ideasonboard.com>, \n\tJacopo Mondi <jacopo.mondi@ideasonboard.com>, \n\tDaniel Scally <dan.scally@ideasonboard.com>, \n\tJai Luthra <jai.luthra@ideasonboard.com>",
        "X-Mailer": "b4 0.14.3",
        "X-Developer-Signature": "v=1; a=openpgp-sha256; l=25001;\n\ti=jai.luthra@ideasonboard.com; h=from:subject:message-id;\n\tbh=y8j33FOrgj+T6MZNVixp4/FvB4vadVLWSH3lF6GKzdM=;\n\tb=owEBbQKS/ZANAwAKAUPekfkkmnFFAcsmYgBqYKhtsCpvteSZNTPgL32zDLZQOSEPIWRIjrHNd\n\ti6mEmpgN5uJAjMEAAEKAB0WIQRN4NgY5dV16NRar8VD3pH5JJpxRQUCamCobQAKCRBD3pH5JJpx\n\tRX8rEADVxWG/fxIYMh6gqeH0keBh8vM6r46hVbDbkMZvsuyWmDzpnJ1+CAZhCjYTUx0GIaed3Ln\n\tMcGJe+uWjC8tlUkQ06Hfhca30h6e6YL8VaNGdDY/2WSQi4lEsPCCRQe19B7AFZJ3fhCyPTBIV6J\n\tKX7coZYpFjxVBjOLW4Mt5BaqXxFw8lMd73KbRlWve5SK3WPECw2dFuqiILW02mXssr+v0TjACCP\n\tmPjgpY7/EkfSSwv8T2UTZis8aOrwMuCprDVk6cxHeifmRRqOggVv2tvHl5Xio5t8seaTn/VY6Iu\n\tdNaXMqniSkbUzSKuELvFGfDuwxsYwFNRGGwuaStRsdeBLHDqliBAs7uCW1ECCfYXIP1tIsha1/a\n\tNmqQgqfKmezMGFRGxk9UHEjjkXmdek3vpI1U6zniyLrOWlnk/2mPnfcpO8dVk5GInj/ZdGD0xH+\n\tWObpLfx3Wb6+iFr5GCab1WxlahMiWoBJVMd1iEGYILI2QEMwmg8PZS0DX+s1f0mt3Dd5G77GR4c\n\ttKtqA465E/BdbkZ1auYV54Q9V54EisuodaZedr1CcIMA7OWICQ1rALiLAAk227aUKGO1Kz/Jrn0\n\tHzis2XCiVooNLcrzN94+WmqG1opn+CmxJ3QRo9itPVuMim9lWKyCmW0NMxc6OqxKwXG+RmEjl19\n\t5KoOkpzRrlLaVEg==",
        "X-Developer-Key": "i=jai.luthra@ideasonboard.com; a=openpgp;\n\tfpr=4DE0D818E5D575E8D45AAFC543DE91F9249A7145",
        "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": "Let each algorithm write directly into typed parameter blocks using the\nBcm2835Params helper. Acquire a parameter buffer in tryRunPipeline(),\npass it to the IPA through BufferIds::params, and queue it back to the\nISP once the IPA reports how many bytes it filled.\n\nAlso patch the lens-shading dmabuf fd in the params buffer, similar to\nwhat setIspControls() did before.\n\nFinally, drop the dead-code that was used to configure the custom V4L2\ncontrols for ISP configuration.\n\nSigned-off-by: Jai Luthra <jai.luthra@ideasonboard.com>\n---\n include/libcamera/ipa/raspberrypi.mojom |  12 --\n src/ipa/rpi/vc4/vc4.cpp                 | 222 ++++++++++++++------------------\n src/libcamera/pipeline/rpi/vc4/vc4.cpp  |  89 +++++++++----\n 3 files changed, 158 insertions(+), 165 deletions(-)",
    "diff": "diff --git a/include/libcamera/ipa/raspberrypi.mojom b/include/libcamera/ipa/raspberrypi.mojom\nindex dcd3b2c66..2b4855e4f 100644\n--- a/include/libcamera/ipa/raspberrypi.mojom\n+++ b/include/libcamera/ipa/raspberrypi.mojom\n@@ -39,7 +39,6 @@ struct BufferIds {\n struct ConfigParams {\n \tuint32 transform;\n \tlibcamera.ControlInfoMap sensorControls;\n-\tlibcamera.ControlInfoMap ispControls;\n \tlibcamera.ControlInfoMap lensControls;\n         /* VC4 specific */\n \tlibcamera.SharedFD lsTableHandle;\n@@ -253,17 +252,6 @@ interface IPARPiEventInterface {\n \t */\n \tmetadataReady(libcamera.ControlList metadata);\n \n-\t/**\n-\t * \\fn setIspControls()\n-\t * \\brief Signal ISP controls to be applied.\n-\t * \\param[in] controls List of controls to be applied.\n-\t *\n-\t * This asynchronous event is signalled to the pipeline handler during\n-\t * the \\a prepareISP signal after all algorithms have been run and the\n-\t * IPA requires ISP controls to be applied for the frame.\n-\t */\n-\tsetIspControls(libcamera.ControlList controls);\n-\n \t/**\n \t * \\fn setDelayedControls()\n \t * \\brief Signal Sensor controls to be applied.\ndiff --git a/src/ipa/rpi/vc4/vc4.cpp b/src/ipa/rpi/vc4/vc4.cpp\nindex 052204d25..50fee538a 100644\n--- a/src/ipa/rpi/vc4/vc4.cpp\n+++ b/src/ipa/rpi/vc4/vc4.cpp\n@@ -5,6 +5,7 @@\n  * Raspberry Pi VC4/BCM2835 ISP IPA.\n  */\n \n+#include <optional>\n #include <string.h>\n #include <sys/mman.h>\n \n@@ -30,6 +31,7 @@\n #include \"controller/lux_status.h\"\n #include \"controller/noise_status.h\"\n #include \"controller/sharpen_status.h\"\n+#include \"params.h\"\n \n namespace libcamera {\n \n@@ -59,34 +61,38 @@ private:\n \tint32_t platformStart(const ControlList &controls, StartResult *result) override;\n \tint32_t platformConfigure(const ConfigParams &params, ConfigResult *result) override;\n \n+\tvoid platformParamsBufferInit(Span<uint8_t> paramsBuffer) override;\n \tvoid platformPrepareIsp(RPiController::Metadata &rpiMetadata) override;\n \tvoid platformPrepareAgc([[maybe_unused]] RPiController::Metadata &rpiMetadata) override;\n \tRPiController::StatisticsPtr platformProcessStats(Span<uint8_t> mem) override;\n \n \tvoid handleControls(const ControlList &controls) override;\n-\tbool validateIspControls();\n \n-\tvoid applyAWB(const struct AwbStatus *awbStatus, ControlList &ctrls);\n-\tvoid applyDG(double digitalGain, const struct AwbStatus *awbStatus, ControlList &ctrls);\n-\tvoid applyCCM(const struct CcmStatus *ccmStatus, ControlList &ctrls);\n-\tvoid applyBlackLevel(const struct BlackLevelStatus *blackLevelStatus, ControlList &ctrls);\n-\tvoid applyGamma(const struct ContrastStatus *contrastStatus, ControlList &ctrls);\n-\tvoid applyGEQ(const struct GeqStatus *geqStatus, ControlList &ctrls);\n-\tvoid applyDenoise(const struct DenoiseStatus *denoiseStatus, ControlList &ctrls);\n-\tvoid applySharpen(const struct SharpenStatus *sharpenStatus, ControlList &ctrls);\n-\tvoid applyDPC(const struct DpcStatus *dpcStatus, ControlList &ctrls);\n-\tvoid applyLS(const struct AlscStatus *lsStatus, ControlList &ctrls);\n+\tvoid applyAWB(const struct AwbStatus *awbStatus, Bcm2835Params &params);\n+\tvoid applyDG(double digitalGain, const struct AwbStatus *awbStatus, Bcm2835Params &params);\n+\tvoid applyCCM(const struct CcmStatus *ccmStatus, Bcm2835Params &params);\n+\tvoid applyBlackLevel(const struct BlackLevelStatus *blackLevelStatus, Bcm2835Params &params);\n+\tvoid applyGamma(const struct ContrastStatus *contrastStatus, Bcm2835Params &params);\n+\tvoid applyGEQ(const struct GeqStatus *geqStatus, Bcm2835Params &params);\n+\tvoid applyDenoise(const struct DenoiseStatus *denoiseStatus, Bcm2835Params &params);\n+\tvoid applySharpen(const struct SharpenStatus *sharpenStatus, Bcm2835Params &params);\n+\tvoid applyDPC(const struct DpcStatus *dpcStatus, Bcm2835Params &params);\n+\tvoid applyLS(const struct AlscStatus *lsStatus, Bcm2835Params &params);\n \tvoid applyAF(const struct AfStatus *afStatus, ControlList &lensCtrls);\n \tvoid resampleTable(uint16_t dest[], const std::vector<double> &src, int destW, int destH);\n \n-\t/* VC4 ISP controls. */\n-\tControlInfoMap ispCtrls_;\n-\tControlList ctrls_;\n+\tsize_t platformParamsBytesUsed() const override\n+\t{\n+\t\treturn (ispParams_.has_value()) ? ispParams_->bytesused() : 0;\n+\t}\n \n \t/* LS table allocation passed in from the pipeline handler. */\n \tSharedFD lsTableHandle_;\n \tvoid *lsTable_;\n \n+\t/* Params buffer for the current frame. */\n+\tstd::optional<Bcm2835Params> ispParams_;\n+\n \t/* Remember the most recent AWB values. */\n \tAwbStatus lastAwbStatus_;\n };\n@@ -113,13 +119,6 @@ int32_t IpaVc4::platformStart([[maybe_unused]] const ControlList &controls,\n \n int32_t IpaVc4::platformConfigure(const ConfigParams &params, [[maybe_unused]] ConfigResult *result)\n {\n-\tispCtrls_ = params.ispControls;\n-\tctrls_ = ControlList(ispCtrls_);\n-\tif (!validateIspControls()) {\n-\t\tLOG(IPARPI, Error) << \"ISP control validation failed.\";\n-\t\treturn -1;\n-\t}\n-\n \t/* Store the lens shading table pointer and handle if available. */\n \tif (params.lsTableHandle.isValid()) {\n \t\t/* Remove any previous table, if there was one. */\n@@ -144,50 +143,54 @@ int32_t IpaVc4::platformConfigure(const ConfigParams &params, [[maybe_unused]] C\n \treturn 0;\n }\n \n+void IpaVc4::platformParamsBufferInit(Span<uint8_t> paramsBuffer)\n+{\n+\t/* Initialize the extensible parameter buffer */\n+\tispParams_.emplace(paramsBuffer);\n+}\n+\n void IpaVc4::platformPrepareIsp(RPiController::Metadata &rpiMetadata)\n {\n-\tControlList &ctrls = ctrls_;\n-\n \t/* Lock the metadata buffer to avoid constant locks/unlocks. */\n \tstd::unique_lock<RPiController::Metadata> lock(rpiMetadata);\n \n \tAwbStatus *awbStatus = rpiMetadata.getLocked<AwbStatus>(\"awb.status\");\n \tif (awbStatus) {\n-\t\tapplyAWB(awbStatus, ctrls);\n+\t\tapplyAWB(awbStatus, *ispParams_);\n \t\tlastAwbStatus_ = *awbStatus;\n \t}\n \n \tCcmStatus *ccmStatus = rpiMetadata.getLocked<CcmStatus>(\"ccm.status\");\n \tif (ccmStatus)\n-\t\tapplyCCM(ccmStatus, ctrls);\n+\t\tapplyCCM(ccmStatus, *ispParams_);\n \n \tAlscStatus *lsStatus = rpiMetadata.getLocked<AlscStatus>(\"alsc.status\");\n \tif (lsStatus)\n-\t\tapplyLS(lsStatus, ctrls);\n+\t\tapplyLS(lsStatus, *ispParams_);\n \n \tContrastStatus *contrastStatus = rpiMetadata.getLocked<ContrastStatus>(\"contrast.status\");\n \tif (contrastStatus)\n-\t\tapplyGamma(contrastStatus, ctrls);\n+\t\tapplyGamma(contrastStatus, *ispParams_);\n \n \tBlackLevelStatus *blackLevelStatus = rpiMetadata.getLocked<BlackLevelStatus>(\"black_level.status\");\n \tif (blackLevelStatus)\n-\t\tapplyBlackLevel(blackLevelStatus, ctrls);\n+\t\tapplyBlackLevel(blackLevelStatus, *ispParams_);\n \n \tGeqStatus *geqStatus = rpiMetadata.getLocked<GeqStatus>(\"geq.status\");\n \tif (geqStatus)\n-\t\tapplyGEQ(geqStatus, ctrls);\n+\t\tapplyGEQ(geqStatus, *ispParams_);\n \n \tDenoiseStatus *denoiseStatus = rpiMetadata.getLocked<DenoiseStatus>(\"denoise.status\");\n \tif (denoiseStatus)\n-\t\tapplyDenoise(denoiseStatus, ctrls);\n+\t\tapplyDenoise(denoiseStatus, *ispParams_);\n \n \tSharpenStatus *sharpenStatus = rpiMetadata.getLocked<SharpenStatus>(\"sharpen.status\");\n \tif (sharpenStatus)\n-\t\tapplySharpen(sharpenStatus, ctrls);\n+\t\tapplySharpen(sharpenStatus, *ispParams_);\n \n \tDpcStatus *dpcStatus = rpiMetadata.getLocked<DpcStatus>(\"dpc.status\");\n \tif (dpcStatus)\n-\t\tapplyDPC(dpcStatus, ctrls);\n+\t\tapplyDPC(dpcStatus, *ispParams_);\n \n \tconst AfStatus *afStatus = rpiMetadata.getLocked<AfStatus>(\"af.status\");\n \tif (afStatus) {\n@@ -204,10 +207,7 @@ void IpaVc4::platformPrepareAgc(RPiController::Metadata &rpiMetadata)\n \tdouble digitalGain = delayedAgcStatus ? delayedAgcStatus->digitalGain : agcStatus_.digitalGain;\n \tAwbStatus *awbStatus = rpiMetadata.getLocked<AwbStatus>(\"awb.status\");\n \n-\tapplyDG(digitalGain, awbStatus, ctrls_);\n-\n-\tsetIspControls.emit(ctrls_);\n-\tctrls_ = ControlList(ispCtrls_);\n+\tapplyDG(digitalGain, awbStatus, *ispParams_);\n }\n \n RPiController::StatisticsPtr IpaVc4::platformProcessStats(Span<uint8_t> mem)\n@@ -324,48 +324,26 @@ void IpaVc4::handleControls(const ControlList &controls)\n \t}\n }\n \n-bool IpaVc4::validateIspControls()\n+void IpaVc4::applyAWB(const struct AwbStatus *awbStatus, Bcm2835Params &params)\n {\n-\tstatic const uint32_t ctrls[] = {\n-\t\tV4L2_CID_RED_BALANCE,\n-\t\tV4L2_CID_BLUE_BALANCE,\n-\t\tV4L2_CID_DIGITAL_GAIN,\n-\t\tV4L2_CID_USER_BCM2835_ISP_CC_MATRIX,\n-\t\tV4L2_CID_USER_BCM2835_ISP_GAMMA,\n-\t\tV4L2_CID_USER_BCM2835_ISP_BLACK_LEVEL,\n-\t\tV4L2_CID_USER_BCM2835_ISP_GEQ,\n-\t\tV4L2_CID_USER_BCM2835_ISP_DENOISE,\n-\t\tV4L2_CID_USER_BCM2835_ISP_SHARPEN,\n-\t\tV4L2_CID_USER_BCM2835_ISP_DPC,\n-\t\tV4L2_CID_USER_BCM2835_ISP_LENS_SHADING,\n-\t\tV4L2_CID_USER_BCM2835_ISP_CDN,\n-\t};\n+\tauto block = params.block<BlockType::AwbGains>();\n \n-\tfor (auto c : ctrls) {\n-\t\tif (ispCtrls_.find(c) == ispCtrls_.end()) {\n-\t\t\tLOG(IPARPI, Error) << \"Unable to find ISP control \"\n-\t\t\t\t\t   << utils::hex(c);\n-\t\t\treturn false;\n-\t\t}\n-\t}\n-\n-\treturn true;\n-}\n-\n-void IpaVc4::applyAWB(const struct AwbStatus *awbStatus, ControlList &ctrls)\n-{\n \tLOG(IPARPI, Debug) << \"Applying WB R: \" << awbStatus->gainR << \" B: \"\n \t\t\t   << awbStatus->gainB;\n \n-\tctrls.set(V4L2_CID_RED_BALANCE,\n-\t\t  static_cast<int32_t>(awbStatus->gainR * 1000));\n-\tctrls.set(V4L2_CID_BLUE_BALANCE,\n-\t\t  static_cast<int32_t>(awbStatus->gainB * 1000));\n+\tblock->awb_gains.r_gain.num = static_cast<int32_t>(awbStatus->gainR * 1000);\n+\tblock->awb_gains.r_gain.den = 1000;\n+\tblock->awb_gains.b_gain.num = static_cast<int32_t>(awbStatus->gainB * 1000);\n+\tblock->awb_gains.b_gain.den = 1000;\n+\n+\tblock.setEnabled(true);\n }\n \n void IpaVc4::applyDG(double digitalGain,\n-\t\t     const struct AwbStatus *awbStatus, ControlList &ctrls)\n+\t\t     const struct AwbStatus *awbStatus, Bcm2835Params &params)\n {\n+\tauto block = params.block<BlockType::DGain>();\n+\n \tif (awbStatus) {\n \t\t/*\n \t\t * We must apply sufficient extra digital gain to stop any of the channel gains being\n@@ -379,13 +357,16 @@ void IpaVc4::applyDG(double digitalGain,\n \t\tdigitalGain *= extraGain;\n \t}\n \n-\tctrls.set(V4L2_CID_DIGITAL_GAIN,\n-\t\t  static_cast<int32_t>(digitalGain * 1000));\n+\tblock->digital_gain.gain.num = static_cast<int32_t>(digitalGain * 1000);\n+\tblock->digital_gain.gain.den = 1000;\n+\n+\tblock.setEnabled(true);\n }\n \n-void IpaVc4::applyCCM(const struct CcmStatus *ccmStatus, ControlList &ctrls)\n+void IpaVc4::applyCCM(const struct CcmStatus *ccmStatus, Bcm2835Params &params)\n {\n-\tbcm2835_isp_custom_ccm ccm;\n+\tauto block = params.block<BlockType::CcMatrix>();\n+\tbcm2835_isp_custom_ccm &ccm = block->ccm;\n \n \tfor (int i = 0; i < 9; i++) {\n \t\tccm.ccm.ccm[i / 3][i % 3].den = 1000;\n@@ -394,30 +375,28 @@ void IpaVc4::applyCCM(const struct CcmStatus *ccmStatus, ControlList &ctrls)\n \n \tccm.enabled = 1;\n \tccm.ccm.offsets[0] = ccm.ccm.offsets[1] = ccm.ccm.offsets[2] = 0;\n-\n-\tControlValue c(Span<const uint8_t>{ reinterpret_cast<uint8_t *>(&ccm),\n-\t\t\t\t\t    sizeof(ccm) });\n-\tctrls.set(V4L2_CID_USER_BCM2835_ISP_CC_MATRIX, c);\n+\tblock.setEnabled(true);\n }\n \n-void IpaVc4::applyBlackLevel(const struct BlackLevelStatus *blackLevelStatus, ControlList &ctrls)\n+void IpaVc4::applyBlackLevel(const struct BlackLevelStatus *blackLevelStatus,\n+\t\t\t     Bcm2835Params &params)\n {\n-\tbcm2835_isp_black_level blackLevel;\n+\tauto block = params.block<BlockType::BlackLevel>();\n+\tbcm2835_isp_black_level &blackLevel = block->black_level;\n \n \tblackLevel.enabled = 1;\n \tblackLevel.black_level_r = blackLevelStatus->blackLevelR;\n \tblackLevel.black_level_g = blackLevelStatus->blackLevelG;\n \tblackLevel.black_level_b = blackLevelStatus->blackLevelB;\n-\n-\tControlValue c(Span<const uint8_t>{ reinterpret_cast<uint8_t *>(&blackLevel),\n-\t\t\t\t\t    sizeof(blackLevel) });\n-\tctrls.set(V4L2_CID_USER_BCM2835_ISP_BLACK_LEVEL, c);\n+\tblock.setEnabled(true);\n }\n \n-void IpaVc4::applyGamma(const struct ContrastStatus *contrastStatus, ControlList &ctrls)\n+void IpaVc4::applyGamma(const struct ContrastStatus *contrastStatus,\n+\t\t\tBcm2835Params &params)\n {\n \tconst unsigned int numGammaPoints = controller_.getHardwareConfig().numGammaPoints;\n-\tstruct bcm2835_isp_gamma gamma;\n+\tauto block = params.block<BlockType::Gamma>();\n+\tstruct bcm2835_isp_gamma &gamma = block->gamma;\n \n \tfor (unsigned int i = 0; i < numGammaPoints - 1; i++) {\n \t\tint x = i < 16 ? i * 1024\n@@ -430,31 +409,27 @@ void IpaVc4::applyGamma(const struct ContrastStatus *contrastStatus, ControlList\n \tgamma.x[numGammaPoints - 1] = 65535;\n \tgamma.y[numGammaPoints - 1] = 65535;\n \tgamma.enabled = 1;\n-\n-\tControlValue c(Span<const uint8_t>{ reinterpret_cast<uint8_t *>(&gamma),\n-\t\t\t\t\t    sizeof(gamma) });\n-\tctrls.set(V4L2_CID_USER_BCM2835_ISP_GAMMA, c);\n+\tblock.setEnabled(true);\n }\n \n-void IpaVc4::applyGEQ(const struct GeqStatus *geqStatus, ControlList &ctrls)\n+void IpaVc4::applyGEQ(const struct GeqStatus *geqStatus, Bcm2835Params &params)\n {\n-\tbcm2835_isp_geq geq;\n+\tauto block = params.block<BlockType::Geq>();\n+\tbcm2835_isp_geq &geq = block->geq;\n \n \tgeq.enabled = 1;\n \tgeq.offset = geqStatus->offset;\n \tgeq.slope.den = 1000;\n \tgeq.slope.num = 1000 * geqStatus->slope;\n-\n-\tControlValue c(Span<const uint8_t>{ reinterpret_cast<uint8_t *>(&geq),\n-\t\t\t\t\t    sizeof(geq) });\n-\tctrls.set(V4L2_CID_USER_BCM2835_ISP_GEQ, c);\n+\tblock.setEnabled(true);\n }\n \n-void IpaVc4::applyDenoise(const struct DenoiseStatus *denoiseStatus, ControlList &ctrls)\n+void IpaVc4::applyDenoise(const struct DenoiseStatus *denoiseStatus, Bcm2835Params &params)\n {\n+\tauto blockDenoise = params.block<BlockType::Denoise>();\n \tusing RPiController::DenoiseMode;\n \n-\tbcm2835_isp_denoise denoise;\n+\tbcm2835_isp_denoise &denoise = blockDenoise->denoise;\n \tDenoiseMode mode = static_cast<DenoiseMode>(denoiseStatus->mode);\n \n \tdenoise.enabled = mode != DenoiseMode::Off;\n@@ -463,9 +438,11 @@ void IpaVc4::applyDenoise(const struct DenoiseStatus *denoiseStatus, ControlList\n \tdenoise.slope.den = 1000;\n \tdenoise.strength.num = 1000 * denoiseStatus->strength;\n \tdenoise.strength.den = 1000;\n+\tblockDenoise.setEnabled(denoise.enabled);\n \n \t/* Set the CDN mode to match the SDN operating mode. */\n-\tbcm2835_isp_cdn cdn;\n+\tauto blockCdn = params.block<BlockType::Cdn>();\n+\tbcm2835_isp_cdn &cdn = blockCdn->cdn;\n \tswitch (mode) {\n \tcase DenoiseMode::ColourFast:\n \t\tcdn.enabled = 1;\n@@ -478,19 +455,13 @@ void IpaVc4::applyDenoise(const struct DenoiseStatus *denoiseStatus, ControlList\n \tdefault:\n \t\tcdn.enabled = 0;\n \t}\n-\n-\tControlValue c(Span<const uint8_t>{ reinterpret_cast<uint8_t *>(&denoise),\n-\t\t\t\t\t    sizeof(denoise) });\n-\tctrls.set(V4L2_CID_USER_BCM2835_ISP_DENOISE, c);\n-\n-\tc = ControlValue(Span<const uint8_t>{ reinterpret_cast<uint8_t *>(&cdn),\n-\t\t\t\t\t      sizeof(cdn) });\n-\tctrls.set(V4L2_CID_USER_BCM2835_ISP_CDN, c);\n+\tblockCdn.setEnabled(cdn.enabled);\n }\n \n-void IpaVc4::applySharpen(const struct SharpenStatus *sharpenStatus, ControlList &ctrls)\n+void IpaVc4::applySharpen(const struct SharpenStatus *sharpenStatus, Bcm2835Params &params)\n {\n-\tbcm2835_isp_sharpen sharpen;\n+\tauto block = params.block<BlockType::Sharpen>();\n+\tbcm2835_isp_sharpen &sharpen = block->sharpen;\n \n \tsharpen.enabled = 1;\n \tsharpen.threshold.num = 1000 * sharpenStatus->threshold;\n@@ -499,25 +470,20 @@ void IpaVc4::applySharpen(const struct SharpenStatus *sharpenStatus, ControlList\n \tsharpen.strength.den = 1000;\n \tsharpen.limit.num = 1000 * sharpenStatus->limit;\n \tsharpen.limit.den = 1000;\n-\n-\tControlValue c(Span<const uint8_t>{ reinterpret_cast<uint8_t *>(&sharpen),\n-\t\t\t\t\t    sizeof(sharpen) });\n-\tctrls.set(V4L2_CID_USER_BCM2835_ISP_SHARPEN, c);\n+\tblock.setEnabled(true);\n }\n \n-void IpaVc4::applyDPC(const struct DpcStatus *dpcStatus, ControlList &ctrls)\n+void IpaVc4::applyDPC(const struct DpcStatus *dpcStatus, Bcm2835Params &params)\n {\n-\tbcm2835_isp_dpc dpc;\n+\tauto block = params.block<BlockType::Dpc>();\n+\tbcm2835_isp_dpc &dpc = block->dpc;\n \n \tdpc.enabled = 1;\n \tdpc.strength = dpcStatus->strength;\n-\n-\tControlValue c(Span<const uint8_t>{ reinterpret_cast<uint8_t *>(&dpc),\n-\t\t\t\t\t    sizeof(dpc) });\n-\tctrls.set(V4L2_CID_USER_BCM2835_ISP_DPC, c);\n+\tblock.setEnabled(true);\n }\n \n-void IpaVc4::applyLS(const struct AlscStatus *lsStatus, ControlList &ctrls)\n+void IpaVc4::applyLS(const struct AlscStatus *lsStatus, Bcm2835Params &params)\n {\n \t/*\n \t * Program lens shading tables into pipeline.\n@@ -541,7 +507,14 @@ void IpaVc4::applyLS(const struct AlscStatus *lsStatus, ControlList &ctrls)\n \n \t/* We're going to supply corner sampled tables, 16 bit samples. */\n \tw++, h++;\n-\tbcm2835_isp_lens_shading ls = {\n+\n+\tif (!lsTableHandle_.isValid() || !lsTable_ || w * h * 4 * sizeof(uint16_t) > MaxLsGridSize) {\n+\t\tLOG(IPARPI, Error) << \"Do not have a correctly allocated lens shading table!\";\n+\t\treturn;\n+\t}\n+\n+\tauto block = params.block<BlockType::LensShading>();\n+\tblock->ls = {\n \t\t.enabled = 1,\n \t\t.grid_cell_size = cellSize,\n \t\t.grid_width = w,\n@@ -554,11 +527,6 @@ void IpaVc4::applyLS(const struct AlscStatus *lsStatus, ControlList &ctrls)\n \t\t.gain_format = GAIN_FORMAT_U4P10\n \t};\n \n-\tif (!lsTable_ || w * h * 4 * sizeof(uint16_t) > MaxLsGridSize) {\n-\t\tLOG(IPARPI, Error) << \"Do not have a correctly allocate lens shading table!\";\n-\t\treturn;\n-\t}\n-\n \tif (lsStatus) {\n \t\t/* Format will be u4.10 */\n \t\tuint16_t *grid = static_cast<uint16_t *>(lsTable_);\n@@ -569,9 +537,7 @@ void IpaVc4::applyLS(const struct AlscStatus *lsStatus, ControlList &ctrls)\n \t\tresampleTable(grid + 3 * w * h, lsStatus->b, w, h);\n \t}\n \n-\tControlValue c(Span<const uint8_t>{ reinterpret_cast<uint8_t *>(&ls),\n-\t\t\t\t\t    sizeof(ls) });\n-\tctrls.set(V4L2_CID_USER_BCM2835_ISP_LENS_SHADING, c);\n+\tblock.setEnabled(true);\n }\n \n void IpaVc4::applyAF(const struct AfStatus *afStatus, ControlList &lensCtrls)\ndiff --git a/src/libcamera/pipeline/rpi/vc4/vc4.cpp b/src/libcamera/pipeline/rpi/vc4/vc4.cpp\nindex e9fae8890..1818e314b 100644\n--- a/src/libcamera/pipeline/rpi/vc4/vc4.cpp\n+++ b/src/libcamera/pipeline/rpi/vc4/vc4.cpp\n@@ -86,7 +86,6 @@ public:\n \tvoid processStatsComplete(const ipa::RPi::BufferIds &buffers);\n \tvoid prepareIspComplete(const ipa::RPi::BufferIds &buffers, bool stitchSwapBuffers,\n \t\t\t\tunsigned int paramsBytesUsed);\n-\tvoid setIspControls(const ControlList &controls);\n \tvoid setCameraTimeout(uint32_t maxFrameLengthMs);\n \n \tstd::unique_ptr<V4L2Subdevice> unicamSubdev_;\n@@ -142,6 +141,8 @@ private:\n \tvoid tryRunPipeline() override;\n \tbool findMatchingBuffers(BayerFrame &bayerFrame, FrameBuffer *&embeddedBuffer);\n \n+\tvoid populateLensShadingFD(const RPi::BufferObject &paramsBufObj);\n+\n \tstd::queue<BayerFrame> bayerQueue_;\n \tstd::queue<FrameBuffer *> embeddedQueue_;\n };\n@@ -412,7 +413,6 @@ int PipelineHandlerVc4::platformRegister(std::unique_ptr<RPi::CameraData> &camer\n \t/* Write up all the IPA connections. */\n \tdata->ipa_->processStatsComplete.connect(data, &Vc4CameraData::processStatsComplete);\n \tdata->ipa_->prepareIspComplete.connect(data, &Vc4CameraData::prepareIspComplete);\n-\tdata->ipa_->setIspControls.connect(data, &Vc4CameraData::setIspControls);\n \tdata->ipa_->setCameraTimeout.connect(data, &Vc4CameraData::setCameraTimeout);\n \n \t/*\n@@ -824,8 +824,6 @@ int Vc4CameraData::platformConfigure(const RPi::RPiCameraConfiguration *rpiConfi\n \n int Vc4CameraData::platformConfigureIpa(ipa::RPi::ConfigParams &params)\n {\n-\tparams.ispControls = isp_[Isp::Input].dev()->controls();\n-\n \t/* Allocate the lens shading table via dmaHeap and pass to the IPA. */\n \tif (!lsTable_.isValid()) {\n \t\tlsTable_ = SharedFD(dmaHeap_.alloc(\"ls_grid\", ipa::RPi::MaxLsGridSize));\n@@ -968,17 +966,65 @@ void Vc4CameraData::processStatsComplete(const ipa::RPi::BufferIds &buffers)\n \thandleState();\n }\n \n+/*\n+ * Populate the lens shading table's dmabuf descriptor inside the params buffer.\n+ *\n+ * While the IPA fills the lens shading table, it may run in an isolated\n+ * process context, so it does not populate the dmabuf file descriptor.\n+ *\n+ * Do that here.\n+ */\n+void Vc4CameraData::populateLensShadingFD(const RPi::BufferObject &paramsBufObj)\n+{\n+\tSpan<uint8_t> plane = paramsBufObj.mapped->planes()[0];\n+\tauto *paramsBuffer =\n+\t\treinterpret_cast<struct v4l2_isp_params_buffer *>(plane.data());\n+\tuint8_t *data = paramsBuffer->data;\n+\tuint32_t offset = 0;\n+\n+\twhile (offset < paramsBuffer->data_size) {\n+\t\tauto *blockHeader =\n+\t\t\treinterpret_cast<struct v4l2_isp_params_block_header *>(data + offset);\n+\n+\t\tif (blockHeader->type == BCM2835_ISP_PARAM_BLOCK_LENS_SHADING) {\n+\t\t\tauto *lsBlock =\n+\t\t\t\treinterpret_cast<struct bcm2835_isp_params_lens_shading *>(blockHeader);\n+\t\t\tlsBlock->ls.dmabuf = lsTable_.get();\n+\t\t\treturn;\n+\t\t}\n+\n+\t\toffset += blockHeader->size;\n+\t}\n+\n+\tLOG(RPI, Error) << \"Unable to populate lens-shading dmabuf fd\";\n+}\n+\n void Vc4CameraData::prepareIspComplete(const ipa::RPi::BufferIds &buffers,\n \t\t\t\t       [[maybe_unused]] bool stitchSwapBuffers,\n-\t\t\t\t       [[maybe_unused]] unsigned int paramsBytesUsed)\n+\t\t\t\t       unsigned int paramsBytesUsed)\n {\n \tunsigned int embeddedId = buffers.embedded & RPi::MaskID;\n+\tunsigned int paramsId = buffers.params & RPi::MaskID;\n \tunsigned int bayer = buffers.bayer & RPi::MaskID;\n \tFrameBuffer *buffer;\n \n \tif (!isRunning())\n \t\treturn;\n \n+\t/* Queue params buffer */\n+\tconst RPi::BufferObject &paramsBufObj = isp_[Isp::Params].getBuffers().at(paramsId);\n+\tASSERT(paramsBufObj.mapped);\n+\tpopulateLensShadingFD(paramsBufObj);\n+\tbuffer = paramsBufObj.buffer;\n+\tbuffer->_d()->metadata().planes()[0].bytesused = paramsBytesUsed;\n+\n+\tLOG(RPI, Debug) << \"Queue params to ISP, buffer id \" << paramsId\n+\t\t\t<< \", timestamp: \" << buffer->metadata().timestamp\n+\t\t\t<< \", bytes used: \" << paramsBytesUsed;\n+\n+\tisp_[Isp::Params].queueBuffer(buffer);\n+\n+\t/* Queue input buffer */\n \tbuffer = unicam_[Unicam::Image].getBuffers().at(bayer & RPi::MaskID).buffer;\n \tLOG(RPI, Debug) << \"Input re-queue to ISP, buffer id \" << (bayer & RPi::MaskID)\n \t\t\t<< \", timestamp: \" << buffer->metadata().timestamp;\n@@ -993,23 +1039,6 @@ void Vc4CameraData::prepareIspComplete(const ipa::RPi::BufferIds &buffers,\n \thandleState();\n }\n \n-void Vc4CameraData::setIspControls(const ControlList &controls)\n-{\n-\tControlList ctrls = controls;\n-\n-\tif (ctrls.contains(V4L2_CID_USER_BCM2835_ISP_LENS_SHADING)) {\n-\t\tControlValue &value =\n-\t\t\tconst_cast<ControlValue &>(ctrls.get(V4L2_CID_USER_BCM2835_ISP_LENS_SHADING));\n-\t\tSpan<uint8_t> s = value.data();\n-\t\tbcm2835_isp_lens_shading *ls =\n-\t\t\treinterpret_cast<bcm2835_isp_lens_shading *>(s.data());\n-\t\tls->dmabuf = lsTable_.get();\n-\t}\n-\n-\tisp_[Isp::Input].dev()->setControls(&ctrls);\n-\thandleState();\n-}\n-\n void Vc4CameraData::setCameraTimeout(uint32_t maxFrameLengthMs)\n {\n \t/*\n@@ -1037,6 +1066,11 @@ void Vc4CameraData::tryRunPipeline()\n \tif (!findMatchingBuffers(bayerFrame, embeddedBuffer))\n \t\treturn;\n \n+\t/* Request a parameter buffer, will be released by ispOutputDequeue */\n+\tconst RPi::BufferObject &paramBufObj = isp_[Isp::Params].acquireBuffer();\n+\tif (!paramBufObj.buffer || !paramBufObj.mapped)\n+\t\treturn;\n+\n \t/* Take the first request from the queue and action the IPA. */\n \tRequest *request = requestQueue_.front();\n \tASSERT(request->metadata().empty());\n@@ -1048,9 +1082,6 @@ void Vc4CameraData::tryRunPipeline()\n \n \tunsigned int bayer = unicam_[Unicam::Image].getBufferId(bayerFrame.buffer);\n \n-\tLOG(RPI, Debug) << \"Signalling prepareIsp:\"\n-\t\t\t<< \" Bayer buffer id: \" << bayer;\n-\n \tipa::RPi::PrepareParams params;\n \tparams.buffers.bayer = RPi::MaskBayerData | bayer;\n \tparams.sensorControls = std::move(bayerFrame.controls);\n@@ -1065,6 +1096,14 @@ void Vc4CameraData::tryRunPipeline()\n \t/* Set our state to say the pipeline is active. */\n \tstate_ = State::Busy;\n \n+\tunsigned int paramId = isp_[Isp::Params].getBufferId(paramBufObj.buffer);\n+\tASSERT(paramId);\n+\tparams.buffers.params = RPi::MaskParams | paramId;\n+\n+\tLOG(RPI, Debug) << \"Signalling prepareIsp:\"\n+\t\t\t<< \" Bayer buffer id: \" << bayer\n+\t\t\t<< \" Param buffer id: \" << paramId;\n+\n \tif (embeddedBuffer) {\n \t\tunsigned int embeddedId = unicam_[Unicam::Embedded].getBufferId(embeddedBuffer);\n \n",
    "prefixes": [
        "v2",
        "7/8"
    ]
}