From nobody Thu Oct 2 14:13:11 2025 Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EA21A285CA4; Mon, 15 Sep 2025 17:18:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=213.167.242.64 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757956720; cv=none; b=nyJV52MdykV3EfTlz6Mpv7Cx0CZRFRREg5H+qJSWP3egp+XGa8qusk9J/1g8izBMU3AcbPidd6TyP4ayQY8+0Dyl4IMFaLAeJhngGMyrwwYhutD4kmT7N114j0iF5RgxBhTQuAjrV/3scU922lxtmB0+3IUUTMT3GPOLPMR6qxI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757956720; c=relaxed/simple; bh=eeqsbZCxS9oe9L1PBM9quXHkAJpq21b3LpH/n1xUbZk=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=h1RJ2sNbPyUFw57crC3DmWCx5rkwSGaIMMXMD/LJ/bOVQxPFeho+cpssgQGvDhwaRqg37GY2l/3pWgOkgix3uzPMr5lRXJSYcJ+DrRylm5xikUMetsOtYcJF/RkkTbl2BzLBEybDYJBJNKIQXjYoYhmbWHCXiKM6zGhKR2BzKjI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=ideasonboard.com; spf=pass smtp.mailfrom=ideasonboard.com; dkim=pass (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.b=vqEbV2Ic; arc=none smtp.client-ip=213.167.242.64 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=ideasonboard.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ideasonboard.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="vqEbV2Ic" Received: from [192.168.0.172] (mob-5-90-56-182.net.vodafone.it [5.90.56.182]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 4764DB0B; Mon, 15 Sep 2025 19:17:18 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1757956639; bh=eeqsbZCxS9oe9L1PBM9quXHkAJpq21b3LpH/n1xUbZk=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=vqEbV2Icbkt/gEUfjxXb7J9IJm4cOt3OyF6m7wYavDGtSfVa8zU2XOWta1yK1JK77 FRUsR4NHYJwIjkn0vN365XX899LDumqAs4DQ0jAWv0m0Lxi4y/NYr8sMoDSebI1r3r 5WuuOUW0YjlzKlo+sCvaFgCmDI8TEWKMGg7j8gjY= From: Jacopo Mondi Date: Mon, 15 Sep 2025 19:18:10 +0200 Subject: [PATCH v5 1/8] media: uapi: Introduce V4L2 generic ISP types Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250915-extensible-parameters-validation-v5-1-e6db94468af3@ideasonboard.com> References: <20250915-extensible-parameters-validation-v5-0-e6db94468af3@ideasonboard.com> In-Reply-To: <20250915-extensible-parameters-validation-v5-0-e6db94468af3@ideasonboard.com> To: Dafna Hirschfeld , Laurent Pinchart , Keke Li , Mauro Carvalho Chehab , Heiko Stuebner , Dan Scally , Sakari Ailus , Antoine Bouyer Cc: linux-kernel@vger.kernel.org, linux-media@vger.kernel.org, linux-rockchip@lists.infradead.org, linux-arm-kernel@lists.infradead.org, Jacopo Mondi X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=6349; i=jacopo.mondi@ideasonboard.com; h=from:subject:message-id; bh=eeqsbZCxS9oe9L1PBM9quXHkAJpq21b3LpH/n1xUbZk=; b=owEBbQKS/ZANAwAKAXI0Bo8WoVY8AcsmYgBoyEppg3cgUFxHN/uhJZUBUODkQMIKpvxbjLUSn PEFjY/K0/uJAjMEAAEKAB0WIQS1xD1IgJogio9YOMByNAaPFqFWPAUCaMhKaQAKCRByNAaPFqFW PFXKEACuiEUbycwT1V1OAqE/ehYJoqmpIumqQxqYwpPV2wbeRhbeJEZY+wWCo3KA1M/Iq+qNzUX gkFcVkow5Tsw3AgaeOwCP7yl6NlK5ixa4nBsyVvqjBk8WxX66Ke4XQRsI8b3TjXnmuRra0s5tB0 I7nNaOqsSZgXigGyFIjbjgZOL2WVcezffXc/IZLpK/tzAkHVXzdkKCXWG2uSYXUpECfwITJAb67 NfK5B5hDqstSsmkz4MaPwqGCmDfRT5pYOj0DgZdEVfuuzgSZYY7Rq2YE3xDzIpa5po+X8KgOoKw zTfmVhs4OuKTTJMiFJshEOuSrGmNbfTpKhy4mozR0mBhFfN4pz95rpWgMi+Qzen7Lgy1D6eMPlr BdsleRFbmvJdizH4pboRKxKMIJ0Wk7qcyhLAeVOgpriTx244ctCMkPhsk6K83oP+No+DnFQ2jf5 wPLThdI5XLm85xqt51xMDtY2Xo66vmoROnRVuh6yDtMQMiR2dKP6HwfJbvjKQ3Au4GHsAVi+a1S cp4DLLodgAGpM/dghFek55rLKZMlhmeoCL1iCcGfQONkdu3bhnSAS1WFYQahD8gd6hCVH+z4pwg sX/jQkMnhJGPkp5jiCEMDHUXUbosBVuVqsXLoKa8SVC0Xl84V6mJOVLNvTeAmlhbRVZrLgOU1pa tS5vLyf0Qv7I9gQ== X-Developer-Key: i=jacopo.mondi@ideasonboard.com; a=openpgp; fpr=72392EDC88144A65C701EA9BA5826A2587AD026B Introduce v4l2-isp.h in the Linux kernel uAPI. The header includes types for generic ISP configuration parameters and will be extended in future with support for generic ISP statistics formats. Generic ISP parameters support is provided by introducing two new types that represent an extensible and versioned buffer of ISP configuration parameters. The v4l2_params_block_header structure represents the header to be prepend to each ISP configuration block and the v4l2_params_buffer type represents the base type for the configuration parameters buffer. The v4l2_params_buffer represents the container for the ISP configuration data block. The generic type is defined with a 0-sized data member that the ISP driver implementations shall properly size according to their capabilities. [Add v4l2_params_buffer_size()] Signed-off-by: Daniel Scally Reviewed-by: Daniel Scally Signed-off-by: Jacopo Mondi Acked-by: Sakari Ailus --- MAINTAINERS | 6 +++ include/uapi/linux/media/v4l2-isp.h | 100 ++++++++++++++++++++++++++++++++= ++++ 2 files changed, 106 insertions(+) diff --git a/MAINTAINERS b/MAINTAINERS index ee8cb2db483f6a5e96b62b6f2edd05b1427b69f5..e82c3d0758d6033fe8fcd56ffde= 2c03c4319fd11 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -26410,6 +26410,12 @@ F: drivers/media/i2c/vd55g1.c F: drivers/media/i2c/vd56g3.c F: drivers/media/i2c/vgxy61.c =20 +V4L2 GENERIC ISP PARAMETERS AND STATISTIC FORMATS +M: Jacopo Mondi +L: linux-media@vger.kernel.org +S: Maintained +F: include/uapi/linux/media/v4l2-isp.h + VF610 NAND DRIVER M: Stefan Agner L: linux-mtd@lists.infradead.org diff --git a/include/uapi/linux/media/v4l2-isp.h b/include/uapi/linux/media= /v4l2-isp.h new file mode 100644 index 0000000000000000000000000000000000000000..b838555dce2b290a14136ab09ea= 4d2dfdc95b26b --- /dev/null +++ b/include/uapi/linux/media/v4l2-isp.h @@ -0,0 +1,100 @@ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ +/* + * Video4Linux2 generic ISP parameters and statistics support + * + * Copyright (C) 2025 Ideas On Board Oy + * Author: Jacopo Mondi + */ + +#ifndef _UAPI_V4L2_ISP_H_ +#define _UAPI_V4L2_ISP_H_ + +#include +#include + +#define V4L2_PARAMS_FL_BLOCK_DISABLE (1U << 0) +#define V4L2_PARAMS_FL_BLOCK_ENABLE (1U << 1) + +/* + * Reserve the first 8 bits for V4L2_PARAMS_FL_* flag. + * + * Driver-specific flags should be defined as: + * #define PLATFORM_SPECIFIC_FLAG0 ((1U << V4L2_PARAMS_FL_DRIVER_FLAGS= (0)) + * #define PLATFORM_SPECIFIC_FLAG1 ((1U << V4L2_PARAMS_FL_DRIVER_FLAGS= (1)) + */ +#define V4L2_PARAMS_FL_DRIVER_FLAGS(n) ((n) + 8) + +/** + * struct v4l2_params_block_header - V4L2 extensible parameters block head= er + * + * This structure represents the common part of all the ISP configuration + * blocks. Each parameters block shall embed an instance of this structure= type + * as its first member, followed by the block-specific configuration data.= The + * driver inspects this common header to discern the block type and its si= ze and + * properly handle the block content. + * + * The @type field is an ISP driver-specific value that identifies the blo= ck + * type. The @size field specifies the size of the parameters block. + * + * The @flags field is a bitmask of per-block flags V4L2_PARAMS_FL_* and + * driver-specific flags specified by the driver header. + * + * @type: The parameters block type (driver-specific) + * @flags: A bitmask of block flags (driver-specific) + * @size: Size (in bytes) of the parameters block, including this header + */ +struct v4l2_params_block_header { + __u16 type; + __u16 flags; + __u32 size; +} __attribute__((aligned(8))); + +/** + * v4l2_params_buffer_size - Calculate size of v4l2_params_buffer for a pl= atform + * + * Users of the v4l2 extensible parameters will have differing sized data = arrays + * depending on their specific parameter buffers. Drivers and userspace wi= ll + * need to be able to calculate the appropriate size of the struct to + * accommodate all ISP configuration blocks provided by the platform. + * This macro provides a convenient tool for the calculation. + * + * @max_params_size: The total size of the ISP configuration blocks + */ +#define v4l2_params_buffer_size(max_params_size) \ + (offsetof(struct v4l2_params_buffer, data) + (max_params_size)) + +/** + * struct v4l2_params_buffer - V4L2 extensible parameters configuration + * + * This struct contains the configuration parameters of the ISP algorithms, + * serialized by userspace into a data buffer. Each configuration parameter + * block is represented by a block-specific structure which contains a + * :c:type:`v4l2_params_block_header` entry as first member. Userspace pop= ulates + * the @data buffer with configuration parameters for the blocks that it i= ntends + * to configure. As a consequence, the data buffer effective size changes + * according to the number of ISP blocks that userspace intends to configu= re and + * is set by userspace in the @data_size field. + * + * The parameters buffer is versioned by the @version field to allow modif= ying + * and extending its definition. Userspace shall populate the @version fie= ld to + * inform the driver about the version it intends to use. The driver will = parse + * and handle the @data buffer according to the data layout specific to the + * indicated version and return an error if the desired version is not + * supported. + * + * For each ISP block that userspace wants to configure, a block-specific + * structure is appended to the @data buffer, one after the other without = gaps + * in between nor overlaps. Userspace shall populate the @data_size field = with + * the effective size, in bytes, of the @data buffer. + * + * @version: The parameters buffer version (driver-specific) + * @data_size: The configuration data effective size, excluding this header + * @data: The configuration data + */ +struct v4l2_params_buffer { + __u32 version; + __u32 data_size; + __u8 data[] __counted_by(data_size); +}; + +#endif /* _UAPI_V4L2_ISP_H_ */ --=20 2.51.0 From nobody Thu Oct 2 14:13:11 2025 Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id ED89E2BE043; Mon, 15 Sep 2025 17:18:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=213.167.242.64 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757956723; cv=none; b=NwSGy1PzqZKU+uN6omCu/obvvXMSsvQfyOxYN7enuATFRsYS/hgNQtbddRWu3PtCQzK+e4TD4HGcha3wX+HOKZ/p57IwapPQJ3MASRnW3B0TiHT/HB8xgmEshVS0e+VVPbRBDRjkr0kbzKebtWg395FfOPPJE9xg2K/YDDsK9nw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757956723; c=relaxed/simple; bh=+cN0Nkg4synqsjTMriyb7/FljLTMktP0+zGLZo/1hjk=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=gJ40puJ7/Racy6qDq0oahlM/xzU+O5iRr3GfZcPLRCU7xVuHArNGK7jTPsF90LGwXQEV7CukkMkSmUI8VUinAxFWXbTExWiEpuIzwGfpAa0/GpNmrIvCGXRTZeZMCOqPICRcZsZqEVgGrgyJnvNGaCK9gXUhvP0Rjr3qsyxrocc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=ideasonboard.com; spf=pass smtp.mailfrom=ideasonboard.com; dkim=pass (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.b=g2vN5oih; arc=none smtp.client-ip=213.167.242.64 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=ideasonboard.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ideasonboard.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="g2vN5oih" Received: from [192.168.0.172] (mob-5-90-56-182.net.vodafone.it [5.90.56.182]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 62D571189; Mon, 15 Sep 2025 19:17:19 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1757956640; bh=+cN0Nkg4synqsjTMriyb7/FljLTMktP0+zGLZo/1hjk=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=g2vN5oihFVCOz5jVLtWhN5k4dRsDVYNxb35Cemiw9e19kh9y82aKJWvWhwzRHMvRW wTy1FmZXWLuTkYFvM0F9uCSMcnkMLY7W50iZmKMUgFixq/UQZuqDTpg3EVH0Zc8M+p VlpI8EQ06kGMvBAGNrnKghcgRUgOhmNtaVWc1+f8= From: Jacopo Mondi Date: Mon, 15 Sep 2025 19:18:11 +0200 Subject: [PATCH v5 2/8] media: uapi: Convert RkISP1 to V4L2 extensible params Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250915-extensible-parameters-validation-v5-2-e6db94468af3@ideasonboard.com> References: <20250915-extensible-parameters-validation-v5-0-e6db94468af3@ideasonboard.com> In-Reply-To: <20250915-extensible-parameters-validation-v5-0-e6db94468af3@ideasonboard.com> To: Dafna Hirschfeld , Laurent Pinchart , Keke Li , Mauro Carvalho Chehab , Heiko Stuebner , Dan Scally , Sakari Ailus , Antoine Bouyer Cc: linux-kernel@vger.kernel.org, linux-media@vger.kernel.org, linux-rockchip@lists.infradead.org, linux-arm-kernel@lists.infradead.org, Jacopo Mondi X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=7688; i=jacopo.mondi@ideasonboard.com; h=from:subject:message-id; bh=+cN0Nkg4synqsjTMriyb7/FljLTMktP0+zGLZo/1hjk=; b=owEBbQKS/ZANAwAKAXI0Bo8WoVY8AcsmYgBoyEpp9AYbOOetgJMFAr+UmQHggPsgRFzpGIcSe pQW65Htmb+JAjMEAAEKAB0WIQS1xD1IgJogio9YOMByNAaPFqFWPAUCaMhKaQAKCRByNAaPFqFW PPwxD/sFecl9kiDsc9xT3r4NpLVKSKWR1eJjTuL8hg9XPerpCs0e+864C9bZQEfSLLpoC5ng1Uf koF5obB5jSLwLZH1OfPCq4ojZrPluMrXDbfLpMUbvwS7IOeEElIOMAWREHI9GbNqH3FczJwtI5U ORz50BxgP1eeh5S7Ou3ZpB0+FhYlrZcnSfYew5cQ+PGiVqFuFbr1cesAaAGF2thlD+himFFRv0E pexk0ZEokAkDkARzAeURfo190bvwzCSF710Q+9e1WpDL8zYLwtNCY28N1cBPR7VEgsqHc7srGXC 1sH8RfLfybm7joc7TwQDGorc8nz5KWyBgtv1iClffHphNjjMgQcIznc83uYGnWpxxbENmhngGVO ux8kLZDt/A6U3I0Tt9WVyPhwNj+fHV1NcJr4hY7fGWnjgvGctQulHF6U9ipbPf3QWKJcbpY9KsE 3ydV2u+5+H1HE9K8cLCkdz785qkE4lc5OF8fa2Ek7OTTbgYqz1LFg0SwD5uc93JBsm1kb2K2iKe cSbppFWcoW7cX+CkBxMnhmM6TbK/8mgC2bbWEuUNI50gdrVpYiGhdFoGSozJJ8xB9Ma1tJ2EcyQ j8juHR1Bi70YwXRAsBBSIlPTqCPcS6nkxKBc7GYAP2jb4FDNIdvM4otMVqPIBh6Bl25nxG5KKdN pUuAVGbzSN0SxUw== X-Developer-Key: i=jacopo.mondi@ideasonboard.com; a=openpgp; fpr=72392EDC88144A65C701EA9BA5826A2587AD026B With the introduction of common types for extensible parameters format, convert the rkisp1-config.h header to use the new types. Factor-out the documentation that is now part of the common header and only keep the driver-specific on in place. The conversion to use common types doesn't impact userspace as the new types are either identical to the ones already existing in the RkISP1 uAPI or are 1-to-1 type convertible. Reviewed-by: Daniel Scally Signed-off-by: Jacopo Mondi Acked-by: Sakari Ailus --- include/uapi/linux/rkisp1-config.h | 104 ++++++++-------------------------= ---- 1 file changed, 22 insertions(+), 82 deletions(-) diff --git a/include/uapi/linux/rkisp1-config.h b/include/uapi/linux/rkisp1= -config.h index 3b060ea6eed71b87d79abc8401eae4e9c9f5323a..b90d94d3a852fb0af0fe4476494= 87e9e80aca795 100644 --- a/include/uapi/linux/rkisp1-config.h +++ b/include/uapi/linux/rkisp1-config.h @@ -7,8 +7,13 @@ #ifndef _UAPI_RKISP1_CONFIG_H #define _UAPI_RKISP1_CONFIG_H =20 +#ifdef __KERNEL__ +#include +#endif /* __KERNEL__ */ #include =20 +#include + /* Defect Pixel Cluster Detection */ #define RKISP1_CIF_ISP_MODULE_DPCC (1U << 0) /* Black Level Subtraction */ @@ -1158,79 +1163,26 @@ enum rkisp1_ext_params_block_type { RKISP1_EXT_PARAMS_BLOCK_TYPE_WDR, }; =20 -#define RKISP1_EXT_PARAMS_FL_BLOCK_DISABLE (1U << 0) -#define RKISP1_EXT_PARAMS_FL_BLOCK_ENABLE (1U << 1) +/* For backward compatibility */ +#define RKISP1_EXT_PARAMS_FL_BLOCK_DISABLE V4L2_PARAMS_FL_BLOCK_DISABLE +#define RKISP1_EXT_PARAMS_FL_BLOCK_ENABLE V4L2_PARAMS_FL_BLOCK_ENABLE =20 /* A bitmask of parameters blocks supported on the current hardware. */ #define RKISP1_CID_SUPPORTED_PARAMS_BLOCKS (V4L2_CID_USER_RKISP1_BASE + 0x= 01) =20 /** - * struct rkisp1_ext_params_block_header - RkISP1 extensible parameters bl= ock - * header + * rkisp1_ext_params_block_header - RkISP1 extensible parameters block hea= der * * This structure represents the common part of all the ISP configuration - * blocks. Each parameters block shall embed an instance of this structure= type - * as its first member, followed by the block-specific configuration data.= The - * driver inspects this common header to discern the block type and its si= ze and - * properly handle the block content by casting it to the correct block-sp= ecific - * type. + * blocks and is identical to :c:type:`v4l2_params_block_header`. * - * The @type field is one of the values enumerated by + * The type field is one of the values enumerated by * :c:type:`rkisp1_ext_params_block_type` and specifies how the data shoul= d be - * interpreted by the driver. The @size field specifies the size of the - * parameters block and is used by the driver for validation purposes. - * - * The @flags field is a bitmask of per-block flags RKISP1_EXT_PARAMS_FL_*. - * - * When userspace wants to configure and enable an ISP block it shall fully - * populate the block configuration and set the - * RKISP1_EXT_PARAMS_FL_BLOCK_ENABLE bit in the @flags field. - * - * When userspace simply wants to disable an ISP block the - * RKISP1_EXT_PARAMS_FL_BLOCK_DISABLE bit should be set in @flags field. T= he - * driver ignores the rest of the block configuration structure in this ca= se. - * - * If a new configuration of an ISP block has to be applied userspace shall - * fully populate the ISP block configuration and omit setting the - * RKISP1_EXT_PARAMS_FL_BLOCK_ENABLE and RKISP1_EXT_PARAMS_FL_BLOCK_DISABL= E bits - * in the @flags field. - * - * Setting both the RKISP1_EXT_PARAMS_FL_BLOCK_ENABLE and - * RKISP1_EXT_PARAMS_FL_BLOCK_DISABLE bits in the @flags field is not allo= wed - * and not accepted by the driver. - * - * Userspace is responsible for correctly populating the parameters block = header - * fields (@type, @flags and @size) and the block-specific parameters. - * - * For example: + * interpreted by the driver. * - * .. code-block:: c - * - * void populate_bls(struct rkisp1_ext_params_block_header *block) { - * struct rkisp1_ext_params_bls_config *bls =3D - * (struct rkisp1_ext_params_bls_config *)block; - * - * bls->header.type =3D RKISP1_EXT_PARAMS_BLOCK_ID_BLS; - * bls->header.flags =3D RKISP1_EXT_PARAMS_FL_BLOCK_ENABLE; - * bls->header.size =3D sizeof(*bls); - * - * bls->config.enable_auto =3D 0; - * bls->config.fixed_val.r =3D blackLevelRed_; - * bls->config.fixed_val.gr =3D blackLevelGreenR_; - * bls->config.fixed_val.gb =3D blackLevelGreenB_; - * bls->config.fixed_val.b =3D blackLevelBlue_; - * } - * - * @type: The parameters block type, see - * :c:type:`rkisp1_ext_params_block_type` - * @flags: A bitmask of block flags - * @size: Size (in bytes) of the parameters block, including this header + * The flags field is a bitmask of per-block flags RKISP1_EXT_PARAMS_FL_*. */ -struct rkisp1_ext_params_block_header { - __u16 type; - __u16 flags; - __u32 size; -}; +#define rkisp1_ext_params_block_header v4l2_params_block_header =20 /** * struct rkisp1_ext_params_bls_config - RkISP1 extensible params BLS conf= ig @@ -1594,21 +1546,7 @@ enum rksip1_ext_param_buffer_version { /** * struct rkisp1_ext_params_cfg - RkISP1 extensible parameters configurati= on * - * This struct contains the configuration parameters of the RkISP1 ISP - * algorithms, serialized by userspace into a data buffer. Each configurat= ion - * parameter block is represented by a block-specific structure which cont= ains a - * :c:type:`rkisp1_ext_params_block_header` entry as first member. Userspa= ce - * populates the @data buffer with configuration parameters for the blocks= that - * it intends to configure. As a consequence, the data buffer effective si= ze - * changes according to the number of ISP blocks that userspace intends to - * configure and is set by userspace in the @data_size field. - * - * The parameters buffer is versioned by the @version field to allow modif= ying - * and extending its definition. Userspace shall populate the @version fie= ld to - * inform the driver about the version it intends to use. The driver will = parse - * and handle the @data buffer according to the data layout specific to the - * indicated version and return an error if the desired version is not - * supported. + * This is the driver-specific implementation of :c:type:`v4l2_params_buff= er`. * * Currently the single RKISP1_EXT_PARAM_BUFFER_V1 version is supported. * When a new format version will be added, a mechanism for userspace to q= uery @@ -1624,11 +1562,6 @@ enum rksip1_ext_param_buffer_version { * the maximum value represents the blocks supported by the kernel driver, * independently of the device instance. * - * For each ISP block that userspace wants to configure, a block-specific - * structure is appended to the @data buffer, one after the other without = gaps - * in between nor overlaps. Userspace shall populate the @data_size field = with - * the effective size, in bytes, of the @data buffer. - * * The expected memory layout of the parameters buffer is:: * * +-------------------- struct rkisp1_ext_params_cfg -------------------+ @@ -1678,4 +1611,11 @@ struct rkisp1_ext_params_cfg { __u8 data[RKISP1_EXT_PARAMS_MAX_SIZE]; }; =20 +#ifdef __KERNEL__ +/* Make sure the header is type-convertible to the generic v4l2 params one= */ +static_assert((sizeof(struct rkisp1_ext_params_cfg) - + RKISP1_EXT_PARAMS_MAX_SIZE) =3D=3D + sizeof(struct v4l2_params_buffer)); +#endif /* __KERNEL__ */ + #endif /* _UAPI_RKISP1_CONFIG_H */ --=20 2.51.0 From nobody Thu Oct 2 14:13:11 2025 Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C82DA2C08BD; Mon, 15 Sep 2025 17:18:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=213.167.242.64 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757956724; cv=none; b=TQQejXcoKw0j0cA9K0FGk+Y8rVH7h6/cfpXXqCnt/R/hjqtYiynGHJWcuCOShKux99ucDNR36Az7Ln+VE+DjFtUmq3aedfvmsoEbd7rrMtsAWnvpZqQRCv7ZWWQ6Zk/sM0dim7WQJfzjbTEVZohyZ0H9tCToAtv+ylkgoSc9jAg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757956724; c=relaxed/simple; bh=H/GK7lEJ75WVhR6Q9Jw/swR31Ip5Ixqo78+hkhaS8UA=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=jPdK5PnvWp6QfePaTAQ4uNkzSa7ggEX/a0JR4nd4yQZiPOwo8Qy/DGbGKXJ+6GlUswWTOITLq1F81GO7KPYAM0bbZkjXxX0vYDNcNOibE/PZ8k+B15USxjrYYxEopHNkYhc/s7A1RyqFqsGQ0W3x6VwWrEVVhZVqudriSX/6Yxg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=ideasonboard.com; spf=pass smtp.mailfrom=ideasonboard.com; dkim=pass (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.b=ICbLOUYp; arc=none smtp.client-ip=213.167.242.64 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=ideasonboard.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ideasonboard.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="ICbLOUYp" Received: from [192.168.0.172] (mob-5-90-56-182.net.vodafone.it [5.90.56.182]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 6C1261440; Mon, 15 Sep 2025 19:17:20 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1757956641; bh=H/GK7lEJ75WVhR6Q9Jw/swR31Ip5Ixqo78+hkhaS8UA=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=ICbLOUYpWIwcf8FiOEvFc690wx6Gxe+ezST0K2ggX30cg4UFvGb25qFDn+Acax3Um +0pueIu7zQa4Fh4YAVC2GRj1CnCcXP1Aju1zMxU1rLd8uZJy5Bukx1uyeDshnN3bod eTu1+lhO9ivzR9TaTuUvEGdbMZdf3zkVdrdaS7uM= From: Jacopo Mondi Date: Mon, 15 Sep 2025 19:18:12 +0200 Subject: [PATCH v5 3/8] media: uapi: Convert Amlogic C3 to V4L2 extensible params Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250915-extensible-parameters-validation-v5-3-e6db94468af3@ideasonboard.com> References: <20250915-extensible-parameters-validation-v5-0-e6db94468af3@ideasonboard.com> In-Reply-To: <20250915-extensible-parameters-validation-v5-0-e6db94468af3@ideasonboard.com> To: Dafna Hirschfeld , Laurent Pinchart , Keke Li , Mauro Carvalho Chehab , Heiko Stuebner , Dan Scally , Sakari Ailus , Antoine Bouyer Cc: linux-kernel@vger.kernel.org, linux-media@vger.kernel.org, linux-rockchip@lists.infradead.org, linux-arm-kernel@lists.infradead.org, Jacopo Mondi X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=6329; i=jacopo.mondi@ideasonboard.com; h=from:subject:message-id; bh=H/GK7lEJ75WVhR6Q9Jw/swR31Ip5Ixqo78+hkhaS8UA=; b=owEBbQKS/ZANAwAKAXI0Bo8WoVY8AcsmYgBoyEpp7I+SZ05eJ7IuLT687k93D4ypGiijh92EC kmd1bfqTO2JAjMEAAEKAB0WIQS1xD1IgJogio9YOMByNAaPFqFWPAUCaMhKaQAKCRByNAaPFqFW PFYVD/sFKmrEww0pDZddfzXP1UFuJN3ybT5PHFtj43CghT4xLdpw+yxo5TaMi7Mwg2VhI4mpk82 DAtT/wZSXYOhGoCmzzpTkuXP5j4GlaBOk2v+eHhruztjcCYpfWU5z+hjyNTuTYb/Z8Mt9TFh1EK FPcevbxgJpDW4LrnhZHx6ghVHLS+qKBM2rIPo6IYJq+JSR/PnBcpP9y5+F0+wfJ9jFaITIsi1sH nojHtRe4w3VaNfs9Vx0+nk6EpEpP2X+2cvuO090+nBoymKsn7qGd4GKjU+KUELZabatJJxNuOvD bjjvdPvOC1RMOLKeX3N9H8bIktOcxzfNlkXaZg315+txD3VkQxJ7EGHMvWHiCjrqLBsykhsaZTq NxTWBGkkvWw4Ip9aI+nv5616v5n2W2XdFZHdqzmPI3YbgejrzGl3gbdaLL/w/Tj3bXVNkuay+U1 /WO0dI5wnTLxkL+Zwy7si9KeZARtL+PTl6RK3BNvFpgy9EvWj+keJkTIvzXmaKG1c8gZvndFxWY jgj53DeovN6hfxSQNZH7ckarwm0NB5RSg/O9/Kxa4JLCTcm2YCf5cE4Npzp39mnmrlL6K1jGj9e vTDL8YvbTnRHqSr80pcaQMWmxS2wagPt2q/WH9KL0PfpTGIRxvYAwPvVphAZ7E7bpH+7F7jRvZ4 YDqo2UFwpMZPuhQ== X-Developer-Key: i=jacopo.mondi@ideasonboard.com; a=openpgp; fpr=72392EDC88144A65C701EA9BA5826A2587AD026B With the introduction of common types for extensible parameters format, convert the c3-isp-config.h header to use the new types. Factor-out the documentation that is now part of the common header and only keep the driver-specific on in place. The conversion to use common types doesn't impact userspace as the new types are either identical to the ones already existing in the C3 ISP uAPI or are 1-to-1 type convertible. Reviewed-by: Daniel Scally Reviewed-by: Keke Li Signed-off-by: Jacopo Mondi Acked-by: Sakari Ailus --- include/uapi/linux/media/amlogic/c3-isp-config.h | 86 ++++++--------------= ---- 1 file changed, 20 insertions(+), 66 deletions(-) diff --git a/include/uapi/linux/media/amlogic/c3-isp-config.h b/include/uap= i/linux/media/amlogic/c3-isp-config.h index ed085ea62a574932c7ad8d59d34b2c5c74a597d8..bf6de55b27a7d4d15effcca5525= 865650d9070fb 100644 --- a/include/uapi/linux/media/amlogic/c3-isp-config.h +++ b/include/uapi/linux/media/amlogic/c3-isp-config.h @@ -6,8 +6,13 @@ #ifndef _UAPI_C3_ISP_CONFIG_H_ #define _UAPI_C3_ISP_CONFIG_H_ =20 +#ifdef __KERNEL__ +#include +#endif /* __KERNEL__ */ #include =20 +#include + /* * Frames are split into zones of almost equal width and height - a zone i= s a * rectangular tile of a frame. The metering blocks within the ISP collect @@ -176,62 +181,22 @@ enum c3_isp_params_block_type { C3_ISP_PARAMS_BLOCK_SENTINEL }; =20 -#define C3_ISP_PARAMS_BLOCK_FL_DISABLE (1U << 0) -#define C3_ISP_PARAMS_BLOCK_FL_ENABLE (1U << 1) +/* For backward compatibility */ +#define C3_ISP_PARAMS_BLOCK_FL_DISABLE V4L2_PARAMS_FL_BLOCK_DISABLE +#define C3_ISP_PARAMS_BLOCK_FL_ENABLE V4L2_PARAMS_FL_BLOCK_ENABLE =20 /** * struct c3_isp_params_block_header - C3 ISP parameter block header * * This structure represents the common part of all the ISP configuration - * blocks. Each parameters block shall embed an instance of this structure= type - * as its first member, followed by the block-specific configuration data.= The - * driver inspects this common header to discern the block type and its si= ze and - * properly handle the block content by casting it to the correct block-sp= ecific - * type. * * The @type field is one of the values enumerated by * :c:type:`c3_isp_params_block_type` and specifies how the data should be - * interpreted by the driver. The @size field specifies the size of the - * parameters block and is used by the driver for validation purposes. The - * @flags field is a bitmask of per-block flags C3_ISP_PARAMS_FL*. - * - * When userspace wants to disable an ISP block the - * C3_ISP_PARAMS_BLOCK_FL_DISABLED bit should be set in the @flags field. = In - * this case userspace may optionally omit the remainder of the configurat= ion - * block, which will be ignored by the driver. - * - * When a new configuration of an ISP block needs to be applied userspace - * shall fully populate the ISP block and omit setting the - * C3_ISP_PARAMS_BLOCK_FL_DISABLED bit in the @flags field. - * - * Userspace is responsible for correctly populating the parameters block = header - * fields (@type, @flags and @size) and the block-specific parameters. - * - * For example: - * - * .. code-block:: c + * interpreted by the driver. * - * void populate_pst_gamma(struct c3_isp_params_block_header *block) { - * struct c3_isp_params_pst_gamma *gamma =3D - * (struct c3_isp_params_pst_gamma *)block; - * - * gamma->header.type =3D C3_ISP_PARAMS_BLOCK_PST_GAMMA; - * gamma->header.flags =3D C3_ISP_PARAMS_BLOCK_FL_ENABLE; - * gamma->header.size =3D sizeof(*gamma); - * - * for (unsigned int i =3D 0; i < 129; i++) - * gamma->pst_gamma_lut[i] =3D i; - * } - * - * @type: The parameters block type from :c:type:`c3_isp_params_block_type` - * @flags: A bitmask of block flags - * @size: Size (in bytes) of the parameters block, including this header + * The flags field is a bitmask of per-block flags C3_ISP_PARAMS_FL_*. */ -struct c3_isp_params_block_header { - __u16 type; - __u16 flags; - __u32 size; -}; +#define c3_isp_params_block_header v4l2_params_block_header =20 /** * struct c3_isp_params_awb_gains - Gains for auto-white balance @@ -498,26 +463,9 @@ struct c3_isp_params_blc { /** * struct c3_isp_params_cfg - C3 ISP configuration parameters * - * This struct contains the configuration parameters of the C3 ISP - * algorithms, serialized by userspace into an opaque data buffer. Each - * configuration parameter block is represented by a block-specific struct= ure - * which contains a :c:type:`c3_isp_param_block_header` entry as first - * member. Userspace populates the @data buffer with configuration paramet= ers - * for the blocks that it intends to configure. As a consequence, the data - * buffer effective size changes according to the number of ISP blocks that - * userspace intends to configure. - * - * The parameters buffer is versioned by the @version field to allow modif= ying - * and extending its definition. Userspace should populate the @version fi= eld to - * inform the driver about the version it intends to use. The driver will = parse - * and handle the @data buffer according to the data layout specific to the - * indicated revision and return an error if the desired revision is not - * supported. - * - * For each ISP block that userspace wants to configure, a block-specific - * structure is appended to the @data buffer, one after the other without = gaps - * in between nor overlaps. Userspace shall populate the @total_size field= with - * the effective size, in bytes, of the @data buffer. + * This is the driver-specific implementation of :c:type:`v4l2_params_buff= er`. + * + * Currently only C3_ISP_PARAM_BUFFER_V0 is supported. * * The expected memory layout of the parameters buffer is:: * @@ -561,4 +509,10 @@ struct c3_isp_params_cfg { __u8 data[C3_ISP_PARAMS_MAX_SIZE]; }; =20 +#ifdef __KERNEL__ +/* Make sure the header is type-convertible to the generic v4l2 params one= */ +static_assert((sizeof(struct c3_isp_params_cfg) - C3_ISP_PARAMS_MAX_SIZE) = =3D=3D + sizeof(struct v4l2_params_buffer)); +#endif /* __KERNEL__ */ + #endif --=20 2.51.0 From nobody Thu Oct 2 14:13:11 2025 Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7EC0D2DC328; Mon, 15 Sep 2025 17:18:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=213.167.242.64 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757956727; cv=none; b=rdw353aARPMH2tXxlusp+YvAPAaSVexef6WOfsqemaidtv72HCTQVablftAPa1Z/ZqNqxjaKSY+aqHKRRMSSBG4wjXi0Bv5WNEmJCDnFbZ1Hcixl2cbbHekqS7EDxB6zvkV5fHDgrO13DGioZdie7YDyyi/t4cqZEn/b0ZW6iqU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757956727; c=relaxed/simple; bh=p5Km38yR3QQGPq5WsXlYQ0p2Qm9Mk6Ika0HPommr0nQ=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=hZNSD2oNUotIHhIGnfB64COxLS0dQXFTLFtTi4Pz6tRK3zDGfTa6mIvYfuiXN0U1f6Rt+TLXnD8YFBZ0Wi1rYubVCuM3QlLELpUI6BP0vvLjOGepzPgd+5QraM1DQcCBYCcgQpwTb0DWVNXgZgneQbpZ0mIG9qAFeeCQbKZC92I= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=ideasonboard.com; spf=pass smtp.mailfrom=ideasonboard.com; dkim=pass (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.b=HM/9r4vC; arc=none smtp.client-ip=213.167.242.64 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=ideasonboard.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ideasonboard.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="HM/9r4vC" Received: from [192.168.0.172] (mob-5-90-56-182.net.vodafone.it [5.90.56.182]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 708631744; Mon, 15 Sep 2025 19:17:21 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1757956643; bh=p5Km38yR3QQGPq5WsXlYQ0p2Qm9Mk6Ika0HPommr0nQ=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=HM/9r4vCeUBhtJnS18NnvOJQGmV8c+lJcTlCESNkxBAlUmUnFPQ9ssFYC4leg7zW4 7zfD/n6MiDax6u4wyT17a7vrEAEBkb+A3zoWR0sYE5bN8UGqjvwmf1wZXZ+v25Kihp vcclg8EH9Wu5vs9QjW3Y8Mar/zH7l5Z1GtZEf8QE= From: Jacopo Mondi Date: Mon, 15 Sep 2025 19:18:13 +0200 Subject: [PATCH v5 4/8] media: Documentation: uapi: Add V4L2 extensible parameters Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250915-extensible-parameters-validation-v5-4-e6db94468af3@ideasonboard.com> References: <20250915-extensible-parameters-validation-v5-0-e6db94468af3@ideasonboard.com> In-Reply-To: <20250915-extensible-parameters-validation-v5-0-e6db94468af3@ideasonboard.com> To: Dafna Hirschfeld , Laurent Pinchart , Keke Li , Mauro Carvalho Chehab , Heiko Stuebner , Dan Scally , Sakari Ailus , Antoine Bouyer Cc: linux-kernel@vger.kernel.org, linux-media@vger.kernel.org, linux-rockchip@lists.infradead.org, linux-arm-kernel@lists.infradead.org, Jacopo Mondi X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=6487; i=jacopo.mondi@ideasonboard.com; h=from:subject:message-id; bh=p5Km38yR3QQGPq5WsXlYQ0p2Qm9Mk6Ika0HPommr0nQ=; b=owEBbQKS/ZANAwAKAXI0Bo8WoVY8AcsmYgBoyEppXxDEFCLv0aWZE6O9yODYZ2ycvWVmRb8VL TUolpstblOJAjMEAAEKAB0WIQS1xD1IgJogio9YOMByNAaPFqFWPAUCaMhKaQAKCRByNAaPFqFW PNb0D/9uk7uJVDBrnmSF3Ttve6rmpYVaFssmwhF/0YixTEo5BGOMFsX/t6ZCEGPcUFd3R7m0KVz buQ9WwuUu11XtAxZVGsrpyJJpIcUuLrA7bq5hyYdIh4AcAVhwIaWEYrjhaN1GpkFcWaR3V7c8kP +VyTIOsS4XwvpxPbP27U0oUFheHBBtc0VeLZ1UShSS3Vx75auTawB+Af49RQzO7KtN4pZeAzg5R Lgt2swF03EE26g15eGgXaa89pwvx2qUuFiOQBAPH8o+Jm6fYg4J0TenureydJqVOqmoYQMDRI4j oL+DMEvlyv3Io20Iyi9Bb4i85fQtOnHh7TnyNDeF2zPVS4o1BOtu8dlGaycvN6nto9aQOi22S+t tQhEdUdjLKWjqKeEvLgnyPtuLVRW6RBkh1BsspY6MKPmfatS/PvC2J1vr8WksKA5+AJEpD3RIPl zRZW0p5vQcUyoB6JieEi/jyHHFtcRxcPFF5pZ7hMx1yM/aFPs4A5jrb1MLyw8aQc0mggAt6T3yg xS7UGf0x4XhzERQJtiQXBtSyd3Z7uxkYfbMqifX+XIsubbLrscFUOkS+61T01H3ZsnXFBOtunQ6 M6FpIpCUQ+/MrfP6Wc6YUS/LUd/gXkX64PR5IC8fX1i+73LbBIyjnWyA40o4grHJx4IZ8c/uxxH QQoWBLpxzfoeiFg== X-Developer-Key: i=jacopo.mondi@ideasonboard.com; a=openpgp; fpr=72392EDC88144A65C701EA9BA5826A2587AD026B Add documentation for extensible parameters format to the V4L2 userspace API documentation. Reviewed-by: Daniel Scally Signed-off-by: Jacopo Mondi Acked-by: Sakari Ailus --- .../media/v4l/extensible-parameters.rst | 97 ++++++++++++++++++= ++++ .../userspace-api/media/v4l/meta-formats.rst | 1 + MAINTAINERS | 1 + 3 files changed, 99 insertions(+) diff --git a/Documentation/userspace-api/media/v4l/extensible-parameters.rs= t b/Documentation/userspace-api/media/v4l/extensible-parameters.rst new file mode 100644 index 0000000000000000000000000000000000000000..e95c84f90c1b472360306d97c9b= 27123cd4bb6af --- /dev/null +++ b/Documentation/userspace-api/media/v4l/extensible-parameters.rst @@ -0,0 +1,97 @@ +.. SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later + +.. _extensible-parameters: + +************************************* +V4L2 extensible ISP parameters format +************************************* + +ISP configuration +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +ISP configuration parameters are computed by userspace and programmed into= a +*parameters buffer* which is queued to the ISP driver on a per-frame basis= . The +layout of the *parameters buffer* generally reflects the ISP peripheral +registers layout and is, for this reason, platform specific. + +The ISP configuration parameters are passed to the ISP driver through a me= tadata +output video node, using the :c:type:`v4l2_meta_format` interface. Each ISP +driver defines a metadata format that implements the configuration paramet= ers +layout. + +Metadata output formats that describe ISP configuration parameters are mos= t of +the time realized by implementing C structures that reflect the registers = layout +and gets populated by userspace before queueing the buffer to the ISP. Each +C structure usually corresponds to one ISP *processing block*, with each b= lock +implementing one of the ISP supported features. + +The uAPI/ABI problem +-------------------- + +By upstreaming data types that describe the configuration parameters layou= t, +driver developers make them part of the Linux kernel ABI. As it sometimes +happens for most peripherals in Linux, ISP drivers development is often an +iterative process, where sometimes not all the hardware features are suppo= rted +in the first version that lands in the kernel, and some parts of the inter= face +have to later be modified for bug-fixes or improvements. + +If any later bug-fix/improvement requires changes to the metadata output f= ormat, +this is considered an ABI-breakage that is strictly forbidden by the Linux +kernel policies. For this reason, each new iteration of an ISP driver supp= ort +would require defining a new metadata output format, implying that drivers= have +to be made ready to handle several different configuration formats. + +Support for generic ISP parameters buffer has been designed with the goal = of +being: + +- Extensible: new features can be added later on without breaking the exis= ting + interface +- Versioned: different versions of the format can be defined without + breaking the existing interface + +The extensible parameters format +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D + +Extensible configuration parameters formats are realized by a defining a s= ingle +C structure that contains a few control parameters and a binary buffer whe= re +userspace programs a variable number of *ISP configuration blocks* data. + +The generic :c:type:`v4l2_params_buffer` defines a base type that each dri= ver +can use by properly sizing the data buffer array by providing a definition= of +maximum supported parameters buffer size. + +Each *ISP configuration block* is identified by an header and contains the +parameters for that specific block. + +The generic :c:type:`v4l2_params_block_header` defines a base type that ea= ch +driver can re-use as it is or extend appropriately. + +Userspace applications are responsible for correctly populating the parame= ters +block header fields (type, flags and size) and the block-specific paramete= rs. + +When userspace wants to configure and enable an ISP block it shall fully +populate the block configuration and set the V4L2_PARAMS_FL_BLOCK_ENABLE +bit in the flags field. + +When userspace simply wants to disable an ISP block the +V4L2_PARAMS_FL_BLOCK_DISABLE bit should be set in flags field. The driver +ignores the rest of the block configuration structure in this case. + +If a new configuration of an ISP block has to be applied, userspace shall = fully +populate the ISP block configuration and omit setting the +V4L2_PARAMS_FL_BLOCK_ENABLE and V4L2_PARAMS_FL_BLOCK_DISABLE bits in +the flags field. + +Setting both the V4L2_PARAMS_FL_BLOCK_ENABLE and V4L2_PARAMS_FL_BLOCK_DISA= BLE +bits in the flags field is not allowed and not accepted. + +Any further development that happens after the ISP driver has been merged = in +Linux and which requires supporting new ISP features can be implemented by +adding new blocks definition without invalidating the existing ones. Simil= arly, +any change to the existing ISP configuration blocks can be handled by vers= ioning +them, again without invalidating the existing ones. + +V4L2 extensible parameters uAPI data types +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +.. kernel-doc:: include/uapi/linux/media/v4l2-isp.h diff --git a/Documentation/userspace-api/media/v4l/meta-formats.rst b/Docum= entation/userspace-api/media/v4l/meta-formats.rst index 0de80328c36bf148051a19abe9e5241234ddfe5c..b900ed6af7bd9ad49baf7b5a9ee= f9423f8abfbcb 100644 --- a/Documentation/userspace-api/media/v4l/meta-formats.rst +++ b/Documentation/userspace-api/media/v4l/meta-formats.rst @@ -12,6 +12,7 @@ These formats are used for the :ref:`metadata` interface = only. .. toctree:: :maxdepth: 1 =20 + extensible-parameters metafmt-c3-isp metafmt-d4xx metafmt-generic diff --git a/MAINTAINERS b/MAINTAINERS index e82c3d0758d6033fe8fcd56ffde2c03c4319fd11..abba872cb63f1430a49a2afbace= 4b9f9958c3991 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -26414,6 +26414,7 @@ V4L2 GENERIC ISP PARAMETERS AND STATISTIC FORMATS M: Jacopo Mondi L: linux-media@vger.kernel.org S: Maintained +F: Documentation/userspace-api/media/v4l/extensible-parameters.rst F: include/uapi/linux/media/v4l2-isp.h =20 VF610 NAND DRIVER --=20 2.51.0 From nobody Thu Oct 2 14:13:11 2025 Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 35BB52DD5F0; Mon, 15 Sep 2025 17:18:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=213.167.242.64 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757956728; cv=none; b=SGnxDAnP71GoQi18+dhqrpAgPSeS0pu2qppw5XY+RDEqzM2ZwibqO6IicUqLYXxIE1rvrLcuk9Ll13AByjhgo0u4cJqkJPGahMX8xuhxM0P5aUMfa23tJQ+CUdv7oy5kI/LzWiozscpxb7aGd6ww0eRMni1/izvLKRUdrspzyCI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757956728; c=relaxed/simple; bh=dBQRMbRcyYg/zn0kFv486waP0cB51OPeZXzibnFMrnE=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=fXLa2Qyo4Wvg55tHhXXHjI5nB668JsTSFTdBw7oQZ70TpRK+B156mFAcpFIQ1w/iMlXKL/MU2C31FLJIVqyz1y0NEz9X2lgPqf4TT44kpDbV9/g+9022VT7MYaQF4TH0pZ8D3dMsLDb4H2/rKp/OCXK8D3E0QPxeDs7MiFudMYo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=ideasonboard.com; spf=pass smtp.mailfrom=ideasonboard.com; dkim=pass (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.b=sfxJZnXZ; arc=none smtp.client-ip=213.167.242.64 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=ideasonboard.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ideasonboard.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="sfxJZnXZ" Received: from [192.168.0.172] (mob-5-90-56-182.net.vodafone.it [5.90.56.182]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 87C9D710; Mon, 15 Sep 2025 19:17:23 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1757956644; bh=dBQRMbRcyYg/zn0kFv486waP0cB51OPeZXzibnFMrnE=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=sfxJZnXZ1njBuwv4ybeXtz7UIrGAISt9Iyq6VOIb0Gzb6Xzs+jWOquGfiLSPCjwRF VfVvVXd/ZtMNkmCSuM0LOgygFHdeaWtNwlh5eMe1btd56FjXnD5/Kgb+fkW/PGnDU4 +OPmporjY8UZz643E1BF9kENxKqw0kfzvTAE3C9Y= From: Jacopo Mondi Date: Mon, 15 Sep 2025 19:18:14 +0200 Subject: [PATCH v5 5/8] media: v4l2-core: Introduce v4l2-isp.c Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250915-extensible-parameters-validation-v5-5-e6db94468af3@ideasonboard.com> References: <20250915-extensible-parameters-validation-v5-0-e6db94468af3@ideasonboard.com> In-Reply-To: <20250915-extensible-parameters-validation-v5-0-e6db94468af3@ideasonboard.com> To: Dafna Hirschfeld , Laurent Pinchart , Keke Li , Mauro Carvalho Chehab , Heiko Stuebner , Dan Scally , Sakari Ailus , Antoine Bouyer Cc: linux-kernel@vger.kernel.org, linux-media@vger.kernel.org, linux-rockchip@lists.infradead.org, linux-arm-kernel@lists.infradead.org, Jacopo Mondi X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=10339; i=jacopo.mondi@ideasonboard.com; h=from:subject:message-id; bh=dBQRMbRcyYg/zn0kFv486waP0cB51OPeZXzibnFMrnE=; b=owEBbQKS/ZANAwAKAXI0Bo8WoVY8AcsmYgBoyEppa14RsLFl+/EdpeZknNHTwssrge035c3Xr ye7wcR0fkqJAjMEAAEKAB0WIQS1xD1IgJogio9YOMByNAaPFqFWPAUCaMhKaQAKCRByNAaPFqFW PODGD/4tHHE4jPaQFVUdgsa/CRP2AzRgWdhgCRChJywWKycY/gqCbXSvxyeFDZtMs7iyq2mG8vs UMZpxGztWWNSE2ViMO3p9qeZSZOpX1Z6wR8zPohD5MvzLsmXsftBKVyGsVRYOxmkf5e8XCsJr74 eDAK+Gt1Jm2E6bL2mAPrOVwBqHrwJfGb1BzXviQK7oDVcexsIk2y1Gy80BPMJevYAXA5Gn3SGRe 3iJB08vLa3LXr2vxU/eX9xupQG9Bu2KxU172N/Gl90rdGRjpmLnQVKwVoV8f8hZcj/+eqdRGaAv Eh7IT7hhj0vvT6bDInH+8B37LHAKFrgfTYRQ8KYjdZvBH9AK7s/dNTWyV3aWWZD4dHJLok8gKW9 9N/Go9wCyoskRBCcWD8kcBokrnTgQPBHrxXlFAgE1BdSJcfXzVKylKywlNMqPXBGx3+zrqazzVk 16UzUNSh7y0NFY95UpRpYdlhZT68iCfPa6Or/sEXkFN7jieaSybLgTOmjAmUeNJ6J+l0cn39hXI QoCkFFxDIY48LDhld2zGZjEAtRPlOYB5ChIrE0mbLl9/vdhcp9hEFPZ43DU9UKNCKgOriYrV0h7 vsZD0gNtY5TLe4mgQ2PXHgjZ+7ZjQsaGs5uv2yulx0/TR5pzLQDmuclL8dsrO1RBW6B1LVq67Z8 mjBOUIQznQ7cwjA== X-Developer-Key: i=jacopo.mondi@ideasonboard.com; a=openpgp; fpr=72392EDC88144A65C701EA9BA5826A2587AD026B Add to the v4l2 framework helper functions to support drivers when validating a buffer of extensible ISP parameters. Introduce new types in include/media/v4l2-isp.h that drivers shall use in order to comply with the generic ISP parameters validation procedure, and add helper functionss to v4l2-isp.c to perform blocks and buffer validation. Reviewed-by: Daniel Scally Signed-off-by: Jacopo Mondi Acked-by: Sakari Ailus --- MAINTAINERS | 2 + drivers/media/v4l2-core/Kconfig | 4 ++ drivers/media/v4l2-core/Makefile | 1 + drivers/media/v4l2-core/v4l2-isp.c | 108 +++++++++++++++++++++++++++++++++= ++++ include/media/v4l2-isp.h | 100 ++++++++++++++++++++++++++++++++++ 5 files changed, 215 insertions(+) diff --git a/MAINTAINERS b/MAINTAINERS index abba872cb63f1430a49a2afbace4b9f9958c3991..5e0e4208ebe6c58a9ea0834e1eb= b36abd2de06e1 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -26415,6 +26415,8 @@ M: Jacopo Mondi L: linux-media@vger.kernel.org S: Maintained F: Documentation/userspace-api/media/v4l/extensible-parameters.rst +F: drivers/media/v4l2-core/v4l2-isp.c +F: include/media/v4l2-isp.h F: include/uapi/linux/media/v4l2-isp.h =20 VF610 NAND DRIVER diff --git a/drivers/media/v4l2-core/Kconfig b/drivers/media/v4l2-core/Kcon= fig index 331b8e535e5bbf33f22638b2ae8bc764ad5fc407..d50ccac9733cc39a43426ae7e79= 96dd0b5b45186 100644 --- a/drivers/media/v4l2-core/Kconfig +++ b/drivers/media/v4l2-core/Kconfig @@ -82,3 +82,7 @@ config V4L2_CCI_I2C depends on I2C select REGMAP_I2C select V4L2_CCI + +config V4L2_ISP + tristate + depends on VIDEOBUF2_CORE diff --git a/drivers/media/v4l2-core/Makefile b/drivers/media/v4l2-core/Mak= efile index 2177b9d63a8ffc1127c5a70118249a2ff63cd759..329f0eadce994cc1c8580beb435= f68fa7e2a7aeb 100644 --- a/drivers/media/v4l2-core/Makefile +++ b/drivers/media/v4l2-core/Makefile @@ -29,6 +29,7 @@ obj-$(CONFIG_V4L2_CCI) +=3D v4l2-cci.o obj-$(CONFIG_V4L2_FLASH_LED_CLASS) +=3D v4l2-flash-led-class.o obj-$(CONFIG_V4L2_FWNODE) +=3D v4l2-fwnode.o obj-$(CONFIG_V4L2_H264) +=3D v4l2-h264.o +obj-$(CONFIG_V4L2_ISP) +=3D v4l2-isp.o obj-$(CONFIG_V4L2_JPEG_HELPER) +=3D v4l2-jpeg.o obj-$(CONFIG_V4L2_MEM2MEM_DEV) +=3D v4l2-mem2mem.o obj-$(CONFIG_V4L2_VP9) +=3D v4l2-vp9.o diff --git a/drivers/media/v4l2-core/v4l2-isp.c b/drivers/media/v4l2-core/v= 4l2-isp.c new file mode 100644 index 0000000000000000000000000000000000000000..e350bdaf53b5502e1ec2a4989c2= 0df1100ab2d2a --- /dev/null +++ b/drivers/media/v4l2-core/v4l2-isp.c @@ -0,0 +1,108 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Video4Linux2 generic ISP parameters and statistics support + * + * Copyright (C) 2025 Ideas On Board Oy + * Author: Jacopo Mondi + */ + +#include +#include + +#include +#include + +int v4l2_params_buffer_validate(struct device *dev, struct vb2_buffer *vb, + size_t max_size) +{ + size_t header_size =3D offsetof(struct v4l2_params_buffer, data); + struct v4l2_params_buffer *buffer =3D vb2_plane_vaddr(vb, 0); + size_t payload_size =3D vb2_get_plane_payload(vb, 0); + size_t buffer_size; + + /* Payload size can't be greater than the destination buffer size */ + if (payload_size > max_size) { + dev_dbg(dev, "Payload size is too large: %zu\n", payload_size); + return -EINVAL; + } + + /* Payload size can't be smaller than the header size */ + if (payload_size < header_size) { + dev_dbg(dev, "Payload size is too small: %zu\n", payload_size); + return -EINVAL; + } + + /* Validate the size reported in the parameter buffer header */ + buffer_size =3D header_size + buffer->data_size; + if (buffer_size !=3D payload_size) { + dev_dbg(dev, "Data size %zu and payload size %zu are different\n", + buffer_size, payload_size); + return -EINVAL; + } + + return 0; +} +EXPORT_SYMBOL_GPL(v4l2_params_buffer_validate); + +int v4l2_params_blocks_validate(struct device *dev, + const struct v4l2_params_buffer *buffer, + const struct v4l2_params_handler *handlers, + size_t num_handlers) +{ + size_t block_offset =3D 0; + size_t buffer_size; + + /* Walk the list of parameter blocks and validate them. */ + buffer_size =3D buffer->data_size; + while (buffer_size >=3D sizeof(struct v4l2_params_block_header)) { + const struct v4l2_params_handler *handler; + const struct v4l2_params_block_header *block; + + /* Validate block sizes and types against the handlers. */ + block =3D (const struct v4l2_params_block_header *) + (buffer->data + block_offset); + + if (block->type >=3D num_handlers) { + dev_dbg(dev, "Invalid parameters block type\n"); + return -EINVAL; + } + + if (block->size > buffer_size) { + dev_dbg(dev, "Premature end of parameters data\n"); + return -EINVAL; + } + + /* It's invalid to specify both ENABLE and DISABLE. */ + if ((block->flags & (V4L2_PARAMS_FL_BLOCK_ENABLE | + V4L2_PARAMS_FL_BLOCK_DISABLE)) =3D=3D + (V4L2_PARAMS_FL_BLOCK_ENABLE | + V4L2_PARAMS_FL_BLOCK_DISABLE)) { + dev_dbg(dev, "Invalid parameters block flags\n"); + return -EINVAL; + } + + /* + * Match the block reported size against the handler's expected + * one, but allow the block to only contain the header in + * case it is going to be disabled. + */ + handler =3D &handlers[block->type]; + if (block->size !=3D handler->size && + (!(block->flags & V4L2_PARAMS_FL_BLOCK_DISABLE) || + block->size !=3D sizeof(*block))) { + dev_dbg(dev, "Invalid parameters block size\n"); + return -EINVAL; + } + + block_offset +=3D block->size; + buffer_size -=3D block->size; + } + + if (buffer_size) { + dev_dbg(dev, "Unexpected data after the parameters buffer end\n"); + return -EINVAL; + } + + return 0; +} +EXPORT_SYMBOL_GPL(v4l2_params_blocks_validate); diff --git a/include/media/v4l2-isp.h b/include/media/v4l2-isp.h new file mode 100644 index 0000000000000000000000000000000000000000..2ad62c6169eef3d0fb8d245de56= cc6bd7e6227e4 --- /dev/null +++ b/include/media/v4l2-isp.h @@ -0,0 +1,100 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* + * Video4Linux2 generic ISP parameters and statistics support + * + * Copyright (C) 2025 Ideas On Board Oy + * Author: Jacopo Mondi + */ + +#ifndef V4L2_PARAMS_H_ +#define V4L2_PARAMS_H_ + +#include + +struct device; +struct vb2_buffer; + +/** + * typedef v4l2_params_block_handler - V4L2 extensible format block handler + * @arg: pointer the driver-specific argument + * @block: the ISP configuration block to handle + * + * Defines the function signature of the functions that handle an ISP block + * configuration. + */ +typedef void (*v4l2_params_block_handler)(void *arg, + const struct v4l2_params_block_header *block); + +/** + * struct v4l2_params_handler - V4L2 extensible format handler + * @size: the block expected size + * @handler: the block handler function + * + * The v4l2_params_handler defines the type that driver making use of the + * V4L2 extensible parameters shall use to define their own ISP block + * handlers. + * + * Drivers shall prepare a list of handlers, one for each supported ISP bl= ock + * and correctly populate the structure's field with the expected block @s= ize + * (used for validation) and a pointer to each block @handler function. + */ +struct v4l2_params_handler { + size_t size; + v4l2_params_block_handler handler; +}; + +/** + * v4l2_params_buffer_validate - Validate a V4L2 extensible parameters buf= fer + * @dev: the driver's device pointer + * @vb: the videobuf2 buffer + * @max_size: the maximum allowed buffer size + * @buffer_validate: callback to the driver-specific buffer validation + * + * Helper function that performs validation of an extensible parameters bu= ffer. + * + * The helper is meant to be used by drivers to perform validation of the + * extensible parameters buffer size correctness. + * + * The @vb buffer as received from the vb2 .buf_prepare() operation is che= cked + * against @max_size and its validated to be large enough to accommodate at + * least one ISP configuration block. The effective buffer size is compared + * with the reported data size to make sure they match. + * + * Drivers should use this function to validate the buffer size correctness + * before performing a copy of the user-provided videobuf2 buffer content = into a + * kernel-only memory buffer to prevent userspace from modifying the buffer + * content after it has been submitted to the driver. + */ +int v4l2_params_buffer_validate(struct device *dev, struct vb2_buffer *vb, + size_t max_size); + +/** + * v4l2_params_blocks_validate - Validate V4L2 extensible parameters ISP + * configuration blocks + * @dev: the driver's device pointer + * @buffer: the extensible parameters configuration buffer + * @handlers: the list of block handlers + * @num_handlers: the number of block handlers + * + * Helper function that performs validation of the ISP configuration block= s in + * an extensible parameters buffer. + * + * The helper is meant to be used by drivers to perform validation of the + * ISP configuration data blocks. For each block in the extensible paramet= ers + * buffer, its size and correctness are validated against its associated h= andler + * in the @handlers list. + * + * Drivers should use this function to validate the ISP configuration bloc= ks + * after having validated the correctness of the vb2 buffer sizes by using= the + * v4l2_params_buffer_validate() helper first. Once the buffer size has be= en + * validated, drivers should perform a copy of the user-provided buffer in= to a + * kernel-only memory buffer to prevent userspace from modifying the buffer + * content after it has been submitted to the driver, and then call this + * function to perform per-block validation. + */ +int v4l2_params_blocks_validate(struct device *dev, + const struct v4l2_params_buffer *buffer, + const struct v4l2_params_handler *handlers, + size_t num_handlers); + +#endif /* V4L2_PARAMS_H_ */ --=20 2.51.0 From nobody Thu Oct 2 14:13:11 2025 Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BC6102BE043; Mon, 15 Sep 2025 17:18:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=213.167.242.64 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757956731; cv=none; b=SsmL5WiZvlYkuEn97ccUMPsjHDq+8o4a4De0NEIiTSkJoLZD8OiHbvl7DWRrKOwgLYMHwzxwqU7vWOjzLoOzier0/54Z6O4OTBEBRzODEUI0EPEcSVUK2qMbzIVTfTWb483FbaXmCfUUidrKY8v9txzgEDFckTROOHIVYestN6A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757956731; c=relaxed/simple; bh=S+MftF0bejoTCtSOL1QHBAYUyqL0Wv5jyt43AvZ3OyM=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=qAuA60IMP/FSrKdmiH8KWXlbITB51nRxQAf1Y4ebMfhTagQkwMgTE9nVYQFiOmHn9en2em2mhuLMfLIr8p1xJVwTpWXJ2viDcD2vyUEiMWKMLxaVximzzd3Lq90IyJouh0TUwpuTD/wrQooZaKxdJAPSwfWMRRJD1e1Ks4JY7wY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=ideasonboard.com; spf=pass smtp.mailfrom=ideasonboard.com; dkim=pass (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.b=BdXYK76J; arc=none smtp.client-ip=213.167.242.64 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=ideasonboard.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ideasonboard.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="BdXYK76J" Received: from [192.168.0.172] (mob-5-90-56-182.net.vodafone.it [5.90.56.182]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 9D1DCB0B; Mon, 15 Sep 2025 19:17:24 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1757956645; bh=S+MftF0bejoTCtSOL1QHBAYUyqL0Wv5jyt43AvZ3OyM=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=BdXYK76JzGngyDMdtgTiWo5pJpu6aUUsKOIKM9q2WSZu0e5lGFV9HRSc7dVL2p3BW 2uyfyoLQIXAmvvX1X8uDSAdGnHPjIUS6aGi5I9E6Kctj/XtkweezOjOlHzHRZRrI1+ kORoeVAoRlQnaHnTMO2ldC7Zkbl/cRXiYMxkrm/A= From: Jacopo Mondi Date: Mon, 15 Sep 2025 19:18:15 +0200 Subject: [PATCH v5 6/8] media: rkisp1: Use v4l2-isp for validation Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250915-extensible-parameters-validation-v5-6-e6db94468af3@ideasonboard.com> References: <20250915-extensible-parameters-validation-v5-0-e6db94468af3@ideasonboard.com> In-Reply-To: <20250915-extensible-parameters-validation-v5-0-e6db94468af3@ideasonboard.com> To: Dafna Hirschfeld , Laurent Pinchart , Keke Li , Mauro Carvalho Chehab , Heiko Stuebner , Dan Scally , Sakari Ailus , Antoine Bouyer Cc: linux-kernel@vger.kernel.org, linux-media@vger.kernel.org, linux-rockchip@lists.infradead.org, linux-arm-kernel@lists.infradead.org, Jacopo Mondi X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=31552; i=jacopo.mondi@ideasonboard.com; h=from:subject:message-id; bh=S+MftF0bejoTCtSOL1QHBAYUyqL0Wv5jyt43AvZ3OyM=; b=owEBbQKS/ZANAwAKAXI0Bo8WoVY8AcsmYgBoyEppg4mIJU8gINfQ9H+KzBSalB1sew3Wl05qJ cGUJGIfmiqJAjMEAAEKAB0WIQS1xD1IgJogio9YOMByNAaPFqFWPAUCaMhKaQAKCRByNAaPFqFW PFYzD/4lbRL31i32arywN793jsMzh6uJvGZvt4J8f3sZeBd+C+s2P23VAeLzcNlLHa3h40bZ8xG +5syaVT3Gabsn8WLWOH93FwkHK+cWcuIYdLRF15ukSG1saTJwBhPmZFVEk+lPyPQV5S68FjGx/v YP9PrED01263iCPePmDLi5JxcjyEjT8+MuHfnUimXWSeGZ8C27XoyCi/KK4uGz3ymVN+rese1Ch n4fKqdAiB17qcX4I1irP6hn8ulzj1iD7RRdK0GZuBAB5qIe6zssBGpmRE2yO6KAEf/OVnpGMCiV ScFcbvT3jLT5c+A46hQ+bGYuBpSsb9fUXq6uq/6zkixezmzHTz+8wzdTqN6qR9y+HYNFRU/zq8o Yq/ynfQ4kAKhyxlIdjJ/LB2LvWjtk7KBftUX7aZuMYF3fP+fkT7xHCLv2Fc01+9zxnSj3ML92Sv Kthzg9QeD7ISTfJ9dJYxC7oNStcKuc3KQMYeRml27Xl47efUc+k7L+yEMOEYRzTdxBJkV4PyImV 8RPWZwt6W2BEK8uJVBBGToND72pOQWS0xeVtVWe44/+g8QavHUe9CHEXXuGF1eHe751GpJlxGWP 5fDD6tsXY7b+Jrt5YEtgqBeAdOZzC1qxtrvgt3KoTJthZGEn74MFGJ0IiJhQqFXXErftqKkShnp kb/fOScd35bOPCA== X-Developer-Key: i=jacopo.mondi@ideasonboard.com; a=openpgp; fpr=72392EDC88144A65C701EA9BA5826A2587AD026B Convert rkisp1-params.c to use the new types for block handlers defined in v4l2-isp.h and use the new helpers from v4l2-isp.c to remove bolierplate code from the driver. Break out from the handlers enumeration the 'group' and 'feature' flags to a separate array and perform driver specific validation of these fields separately. Reviewed-by: Daniel Scally Signed-off-by: Jacopo Mondi Acked-by: Sakari Ailus --- drivers/media/platform/rockchip/rkisp1/Kconfig | 1 + .../media/platform/rockchip/rkisp1/rkisp1-params.c | 441 ++++++++++-------= ---- 2 files changed, 209 insertions(+), 233 deletions(-) diff --git a/drivers/media/platform/rockchip/rkisp1/Kconfig b/drivers/media= /platform/rockchip/rkisp1/Kconfig index 731c9acbf6efa33188617204d441fb0ea59adebc..f53eb1f3f3e7003d8e02c9236ae= abb5ae8844f7b 100644 --- a/drivers/media/platform/rockchip/rkisp1/Kconfig +++ b/drivers/media/platform/rockchip/rkisp1/Kconfig @@ -10,6 +10,7 @@ config VIDEO_ROCKCHIP_ISP1 select VIDEOBUF2_VMALLOC select V4L2_FWNODE select GENERIC_PHY_MIPI_DPHY + select V4L2_ISP default n help Enable this to support the Image Signal Processing (ISP) module diff --git a/drivers/media/platform/rockchip/rkisp1/rkisp1-params.c b/drive= rs/media/platform/rockchip/rkisp1/rkisp1-params.c index f1585f8fa0f478304f74317fd9dd09199c94ec82..de4e459fb556afb08891558dbf9= d55b1973af8da 100644 --- a/drivers/media/platform/rockchip/rkisp1/rkisp1-params.c +++ b/drivers/media/platform/rockchip/rkisp1/rkisp1-params.c @@ -12,6 +12,7 @@ #include #include #include +#include #include #include /* for ISP params */ =20 @@ -40,30 +41,6 @@ #define RKISP1_EXT_PARAMS_BLOCK_GROUP_OTHERS BIT(0) #define RKISP1_EXT_PARAMS_BLOCK_GROUP_LSC BIT(1) =20 -union rkisp1_ext_params_config { - struct rkisp1_ext_params_block_header header; - struct rkisp1_ext_params_bls_config bls; - struct rkisp1_ext_params_dpcc_config dpcc; - struct rkisp1_ext_params_sdg_config sdg; - struct rkisp1_ext_params_lsc_config lsc; - struct rkisp1_ext_params_awb_gain_config awbg; - struct rkisp1_ext_params_flt_config flt; - struct rkisp1_ext_params_bdm_config bdm; - struct rkisp1_ext_params_ctk_config ctk; - struct rkisp1_ext_params_goc_config goc; - struct rkisp1_ext_params_dpf_config dpf; - struct rkisp1_ext_params_dpf_strength_config dpfs; - struct rkisp1_ext_params_cproc_config cproc; - struct rkisp1_ext_params_ie_config ie; - struct rkisp1_ext_params_awb_meas_config awbm; - struct rkisp1_ext_params_hst_config hst; - struct rkisp1_ext_params_aec_config aec; - struct rkisp1_ext_params_afc_config afc; - struct rkisp1_ext_params_compand_bls_config compand_bls; - struct rkisp1_ext_params_compand_curve_config compand_curve; - struct rkisp1_ext_params_wdr_config wdr; -}; - enum rkisp1_params_formats { RKISP1_PARAMS_FIXED, RKISP1_PARAMS_EXTENSIBLE, @@ -1689,11 +1666,12 @@ static void rkisp1_isp_isr_meas_config(struct rkisp= 1_params *params, * Extensible parameters format handling */ =20 -static void -rkisp1_ext_params_bls(struct rkisp1_params *params, - const union rkisp1_ext_params_config *block) +static void rkisp1_ext_params_bls(void *dev, + const struct v4l2_params_block_header *block) { - const struct rkisp1_ext_params_bls_config *bls =3D &block->bls; + const struct rkisp1_ext_params_bls_config *bls =3D + (const struct rkisp1_ext_params_bls_config *)block; + struct rkisp1_params *params =3D dev; =20 if (bls->header.flags & RKISP1_EXT_PARAMS_FL_BLOCK_DISABLE) { rkisp1_param_clear_bits(params, RKISP1_CIF_ISP_BLS_CTRL, @@ -1709,11 +1687,12 @@ rkisp1_ext_params_bls(struct rkisp1_params *params, RKISP1_CIF_ISP_BLS_ENA); } =20 -static void -rkisp1_ext_params_dpcc(struct rkisp1_params *params, - const union rkisp1_ext_params_config *block) +static void rkisp1_ext_params_dpcc(void *dev, + const struct v4l2_params_block_header *block) { - const struct rkisp1_ext_params_dpcc_config *dpcc =3D &block->dpcc; + const struct rkisp1_ext_params_dpcc_config *dpcc =3D + (const struct rkisp1_ext_params_dpcc_config *)block; + struct rkisp1_params *params =3D dev; =20 if (dpcc->header.flags & RKISP1_EXT_PARAMS_FL_BLOCK_DISABLE) { rkisp1_param_clear_bits(params, RKISP1_CIF_ISP_DPCC_MODE, @@ -1729,11 +1708,12 @@ rkisp1_ext_params_dpcc(struct rkisp1_params *params, RKISP1_CIF_ISP_DPCC_MODE_DPCC_ENABLE); } =20 -static void -rkisp1_ext_params_sdg(struct rkisp1_params *params, - const union rkisp1_ext_params_config *block) +static void rkisp1_ext_params_sdg(void *dev, + const struct v4l2_params_block_header *block) { - const struct rkisp1_ext_params_sdg_config *sdg =3D &block->sdg; + const struct rkisp1_ext_params_sdg_config *sdg =3D + (const struct rkisp1_ext_params_sdg_config *)block; + struct rkisp1_params *params =3D dev; =20 if (sdg->header.flags & RKISP1_EXT_PARAMS_FL_BLOCK_DISABLE) { rkisp1_param_clear_bits(params, RKISP1_CIF_ISP_CTRL, @@ -1749,11 +1729,12 @@ rkisp1_ext_params_sdg(struct rkisp1_params *params, RKISP1_CIF_ISP_CTRL_ISP_GAMMA_IN_ENA); } =20 -static void -rkisp1_ext_params_lsc(struct rkisp1_params *params, - const union rkisp1_ext_params_config *block) +static void rkisp1_ext_params_lsc(void *dev, + const struct v4l2_params_block_header *block) { - const struct rkisp1_ext_params_lsc_config *lsc =3D &block->lsc; + const struct rkisp1_ext_params_lsc_config *lsc =3D + (const struct rkisp1_ext_params_lsc_config *)block; + struct rkisp1_params *params =3D dev; =20 if (lsc->header.flags & RKISP1_EXT_PARAMS_FL_BLOCK_DISABLE) { rkisp1_param_clear_bits(params, RKISP1_CIF_ISP_LSC_CTRL, @@ -1769,11 +1750,12 @@ rkisp1_ext_params_lsc(struct rkisp1_params *params, RKISP1_CIF_ISP_LSC_CTRL_ENA); } =20 -static void -rkisp1_ext_params_awbg(struct rkisp1_params *params, - const union rkisp1_ext_params_config *block) +static void rkisp1_ext_params_awbg(void *dev, + const struct v4l2_params_block_header *block) { - const struct rkisp1_ext_params_awb_gain_config *awbg =3D &block->awbg; + const struct rkisp1_ext_params_awb_gain_config *awbg =3D + (const struct rkisp1_ext_params_awb_gain_config *)block; + struct rkisp1_params *params =3D dev; =20 if (awbg->header.flags & RKISP1_EXT_PARAMS_FL_BLOCK_DISABLE) { rkisp1_param_clear_bits(params, RKISP1_CIF_ISP_CTRL, @@ -1789,11 +1771,12 @@ rkisp1_ext_params_awbg(struct rkisp1_params *params, RKISP1_CIF_ISP_CTRL_ISP_AWB_ENA); } =20 -static void -rkisp1_ext_params_flt(struct rkisp1_params *params, - const union rkisp1_ext_params_config *block) +static void rkisp1_ext_params_flt(void *dev, + const struct v4l2_params_block_header *block) { - const struct rkisp1_ext_params_flt_config *flt =3D &block->flt; + const struct rkisp1_ext_params_flt_config *flt =3D + (const struct rkisp1_ext_params_flt_config *)block; + struct rkisp1_params *params =3D dev; =20 if (flt->header.flags & RKISP1_EXT_PARAMS_FL_BLOCK_DISABLE) { rkisp1_param_clear_bits(params, RKISP1_CIF_ISP_FILT_MODE, @@ -1809,11 +1792,12 @@ rkisp1_ext_params_flt(struct rkisp1_params *params, RKISP1_CIF_ISP_FLT_ENA); } =20 -static void -rkisp1_ext_params_bdm(struct rkisp1_params *params, - const union rkisp1_ext_params_config *block) +static void rkisp1_ext_params_bdm(void *dev, + const struct v4l2_params_block_header *block) { - const struct rkisp1_ext_params_bdm_config *bdm =3D &block->bdm; + const struct rkisp1_ext_params_bdm_config *bdm =3D + (const struct rkisp1_ext_params_bdm_config *)block; + struct rkisp1_params *params =3D dev; =20 if (bdm->header.flags & RKISP1_EXT_PARAMS_FL_BLOCK_DISABLE) { rkisp1_param_clear_bits(params, RKISP1_CIF_ISP_DEMOSAIC, @@ -1829,11 +1813,12 @@ rkisp1_ext_params_bdm(struct rkisp1_params *params, RKISP1_CIF_ISP_DEMOSAIC_BYPASS); } =20 -static void -rkisp1_ext_params_ctk(struct rkisp1_params *params, - const union rkisp1_ext_params_config *block) +static void rkisp1_ext_params_ctk(void *dev, + const struct v4l2_params_block_header *block) { - const struct rkisp1_ext_params_ctk_config *ctk =3D &block->ctk; + const struct rkisp1_ext_params_ctk_config *ctk =3D + (const struct rkisp1_ext_params_ctk_config *)block; + struct rkisp1_params *params =3D dev; =20 if (ctk->header.flags & RKISP1_EXT_PARAMS_FL_BLOCK_DISABLE) { rkisp1_ctk_enable(params, false); @@ -1847,11 +1832,12 @@ rkisp1_ext_params_ctk(struct rkisp1_params *params, rkisp1_ctk_enable(params, true); } =20 -static void -rkisp1_ext_params_goc(struct rkisp1_params *params, - const union rkisp1_ext_params_config *block) +static void rkisp1_ext_params_goc(void *dev, + const struct v4l2_params_block_header *block) { - const struct rkisp1_ext_params_goc_config *goc =3D &block->goc; + const struct rkisp1_ext_params_goc_config *goc =3D + (const struct rkisp1_ext_params_goc_config *)block; + struct rkisp1_params *params =3D dev; =20 if (goc->header.flags & RKISP1_EXT_PARAMS_FL_BLOCK_DISABLE) { rkisp1_param_clear_bits(params, RKISP1_CIF_ISP_CTRL, @@ -1869,11 +1855,12 @@ rkisp1_ext_params_goc(struct rkisp1_params *params, RKISP1_CIF_ISP_CTRL_ISP_GAMMA_OUT_ENA); } =20 -static void -rkisp1_ext_params_dpf(struct rkisp1_params *params, - const union rkisp1_ext_params_config *block) +static void rkisp1_ext_params_dpf(void *dev, + const struct v4l2_params_block_header *block) { - const struct rkisp1_ext_params_dpf_config *dpf =3D &block->dpf; + const struct rkisp1_ext_params_dpf_config *dpf =3D + (const struct rkisp1_ext_params_dpf_config *)block; + struct rkisp1_params *params =3D dev; =20 if (dpf->header.flags & RKISP1_EXT_PARAMS_FL_BLOCK_DISABLE) { rkisp1_param_clear_bits(params, RKISP1_CIF_ISP_DPF_MODE, @@ -1889,20 +1876,22 @@ rkisp1_ext_params_dpf(struct rkisp1_params *params, RKISP1_CIF_ISP_DPF_MODE_EN); } =20 -static void -rkisp1_ext_params_dpfs(struct rkisp1_params *params, - const union rkisp1_ext_params_config *block) +static void rkisp1_ext_params_dpfs(void *dev, + const struct v4l2_params_block_header *block) { - const struct rkisp1_ext_params_dpf_strength_config *dpfs =3D &block->dpfs; + const struct rkisp1_ext_params_dpf_strength_config *dpfs =3D + (const struct rkisp1_ext_params_dpf_strength_config *)block; + struct rkisp1_params *params =3D dev; =20 rkisp1_dpf_strength_config(params, &dpfs->config); } =20 -static void -rkisp1_ext_params_cproc(struct rkisp1_params *params, - const union rkisp1_ext_params_config *block) +static void rkisp1_ext_params_cproc(void *dev, + const struct v4l2_params_block_header *block) { - const struct rkisp1_ext_params_cproc_config *cproc =3D &block->cproc; + const struct rkisp1_ext_params_cproc_config *cproc =3D + (const struct rkisp1_ext_params_cproc_config *)block; + struct rkisp1_params *params =3D dev; =20 if (cproc->header.flags & RKISP1_EXT_PARAMS_FL_BLOCK_DISABLE) { rkisp1_param_clear_bits(params, RKISP1_CIF_C_PROC_CTRL, @@ -1918,11 +1907,12 @@ rkisp1_ext_params_cproc(struct rkisp1_params *param= s, RKISP1_CIF_C_PROC_CTR_ENABLE); } =20 -static void -rkisp1_ext_params_ie(struct rkisp1_params *params, - const union rkisp1_ext_params_config *block) +static void rkisp1_ext_params_ie(void *dev, + const struct v4l2_params_block_header *block) { - const struct rkisp1_ext_params_ie_config *ie =3D &block->ie; + const struct rkisp1_ext_params_ie_config *ie =3D + (const struct rkisp1_ext_params_ie_config *)block; + struct rkisp1_params *params =3D dev; =20 if (ie->header.flags & RKISP1_EXT_PARAMS_FL_BLOCK_DISABLE) { rkisp1_ie_enable(params, false); @@ -1936,11 +1926,12 @@ rkisp1_ext_params_ie(struct rkisp1_params *params, rkisp1_ie_enable(params, true); } =20 -static void -rkisp1_ext_params_awbm(struct rkisp1_params *params, - const union rkisp1_ext_params_config *block) +static void rkisp1_ext_params_awbm(void *dev, + const struct v4l2_params_block_header *block) { - const struct rkisp1_ext_params_awb_meas_config *awbm =3D &block->awbm; + const struct rkisp1_ext_params_awb_meas_config *awbm =3D + (const struct rkisp1_ext_params_awb_meas_config *)block; + struct rkisp1_params *params =3D dev; =20 if (awbm->header.flags & RKISP1_EXT_PARAMS_FL_BLOCK_DISABLE) { params->ops->awb_meas_enable(params, &awbm->config, @@ -1956,11 +1947,12 @@ rkisp1_ext_params_awbm(struct rkisp1_params *params, true); } =20 -static void -rkisp1_ext_params_hstm(struct rkisp1_params *params, - const union rkisp1_ext_params_config *block) +static void rkisp1_ext_params_hstm(void *dev, + const struct v4l2_params_block_header *block) { - const struct rkisp1_ext_params_hst_config *hst =3D &block->hst; + const struct rkisp1_ext_params_hst_config *hst =3D + (const struct rkisp1_ext_params_hst_config *)block; + struct rkisp1_params *params =3D dev; =20 if (hst->header.flags & RKISP1_EXT_PARAMS_FL_BLOCK_DISABLE) { params->ops->hst_enable(params, &hst->config, false); @@ -1974,11 +1966,12 @@ rkisp1_ext_params_hstm(struct rkisp1_params *params, params->ops->hst_enable(params, &hst->config, true); } =20 -static void -rkisp1_ext_params_aecm(struct rkisp1_params *params, - const union rkisp1_ext_params_config *block) +static void rkisp1_ext_params_aecm(void *dev, + const struct v4l2_params_block_header *block) { - const struct rkisp1_ext_params_aec_config *aec =3D &block->aec; + const struct rkisp1_ext_params_aec_config *aec =3D + (const struct rkisp1_ext_params_aec_config *)block; + struct rkisp1_params *params =3D dev; =20 if (aec->header.flags & RKISP1_EXT_PARAMS_FL_BLOCK_DISABLE) { rkisp1_param_clear_bits(params, RKISP1_CIF_ISP_EXP_CTRL, @@ -1994,11 +1987,12 @@ rkisp1_ext_params_aecm(struct rkisp1_params *params, RKISP1_CIF_ISP_EXP_ENA); } =20 -static void -rkisp1_ext_params_afcm(struct rkisp1_params *params, - const union rkisp1_ext_params_config *block) +static void rkisp1_ext_params_afcm(void *dev, + const struct v4l2_params_block_header *block) { - const struct rkisp1_ext_params_afc_config *afc =3D &block->afc; + const struct rkisp1_ext_params_afc_config *afc =3D + (const struct rkisp1_ext_params_afc_config *)block; + struct rkisp1_params *params =3D dev; =20 if (afc->header.flags & RKISP1_EXT_PARAMS_FL_BLOCK_DISABLE) { rkisp1_param_clear_bits(params, RKISP1_CIF_ISP_AFM_CTRL, @@ -2014,11 +2008,12 @@ rkisp1_ext_params_afcm(struct rkisp1_params *params, RKISP1_CIF_ISP_AFM_ENA); } =20 -static void rkisp1_ext_params_compand_bls(struct rkisp1_params *params, - const union rkisp1_ext_params_config *block) +static void rkisp1_ext_params_compand_bls(void *dev, + const struct v4l2_params_block_header *block) { const struct rkisp1_ext_params_compand_bls_config *bls =3D - &block->compand_bls; + (const struct rkisp1_ext_params_compand_bls_config *)block; + struct rkisp1_params *params =3D dev; =20 if (bls->header.flags & RKISP1_EXT_PARAMS_FL_BLOCK_DISABLE) { rkisp1_param_clear_bits(params, RKISP1_CIF_ISP_COMPAND_CTRL, @@ -2034,11 +2029,13 @@ static void rkisp1_ext_params_compand_bls(struct rk= isp1_params *params, RKISP1_CIF_ISP_COMPAND_CTRL_BLS_ENABLE); } =20 -static void rkisp1_ext_params_compand_expand(struct rkisp1_params *params, - const union rkisp1_ext_params_config *block) +static void +rkisp1_ext_params_compand_expand(void *dev, + const struct v4l2_params_block_header *block) { const struct rkisp1_ext_params_compand_curve_config *curve =3D - &block->compand_curve; + (const struct rkisp1_ext_params_compand_curve_config *)block; + struct rkisp1_params *params =3D dev; =20 if (curve->header.flags & RKISP1_EXT_PARAMS_FL_BLOCK_DISABLE) { rkisp1_param_clear_bits(params, RKISP1_CIF_ISP_COMPAND_CTRL, @@ -2054,11 +2051,13 @@ static void rkisp1_ext_params_compand_expand(struct= rkisp1_params *params, RKISP1_CIF_ISP_COMPAND_CTRL_EXPAND_ENABLE); } =20 -static void rkisp1_ext_params_compand_compress(struct rkisp1_params *param= s, - const union rkisp1_ext_params_config *block) +static void +rkisp1_ext_params_compand_compress(void *dev, + const struct v4l2_params_block_header *block) { const struct rkisp1_ext_params_compand_curve_config *curve =3D - &block->compand_curve; + (const struct rkisp1_ext_params_compand_curve_config *)block; + struct rkisp1_params *params =3D dev; =20 if (curve->header.flags & RKISP1_EXT_PARAMS_FL_BLOCK_DISABLE) { rkisp1_param_clear_bits(params, RKISP1_CIF_ISP_COMPAND_CTRL, @@ -2074,10 +2073,12 @@ static void rkisp1_ext_params_compand_compress(stru= ct rkisp1_params *params, RKISP1_CIF_ISP_COMPAND_CTRL_COMPRESS_ENABLE); } =20 -static void rkisp1_ext_params_wdr(struct rkisp1_params *params, - const union rkisp1_ext_params_config *block) +static void rkisp1_ext_params_wdr(void *dev, + const struct v4l2_params_block_header *block) { - const struct rkisp1_ext_params_wdr_config *wdr =3D &block->wdr; + const struct rkisp1_ext_params_wdr_config *wdr =3D + (const struct rkisp1_ext_params_wdr_config *)block; + struct rkisp1_params *params =3D dev; =20 if (wdr->header.flags & RKISP1_EXT_PARAMS_FL_BLOCK_DISABLE) { rkisp1_param_clear_bits(params, RKISP1_CIF_ISP_WDR_CTRL, @@ -2093,123 +2094,163 @@ static void rkisp1_ext_params_wdr(struct rkisp1_p= arams *params, RKISP1_CIF_ISP_WDR_CTRL_ENABLE); } =20 -typedef void (*rkisp1_block_handler)(struct rkisp1_params *params, - const union rkisp1_ext_params_config *config); - -static const struct rkisp1_ext_params_handler { - size_t size; - rkisp1_block_handler handler; +static const struct rkisp1_params_block_feature { unsigned int group; unsigned int features; -} rkisp1_ext_params_handlers[] =3D { +} rkisp1_ext_params_features[] =3D { [RKISP1_EXT_PARAMS_BLOCK_TYPE_BLS] =3D { - .size =3D sizeof(struct rkisp1_ext_params_bls_config), - .handler =3D rkisp1_ext_params_bls, .group =3D RKISP1_EXT_PARAMS_BLOCK_GROUP_OTHERS, .features =3D RKISP1_FEATURE_BLS, }, + [RKISP1_EXT_PARAMS_BLOCK_TYPE_DPCC] =3D { + .group =3D RKISP1_EXT_PARAMS_BLOCK_GROUP_OTHERS, + }, + [RKISP1_EXT_PARAMS_BLOCK_TYPE_SDG] =3D { + .group =3D RKISP1_EXT_PARAMS_BLOCK_GROUP_OTHERS, + }, + [RKISP1_EXT_PARAMS_BLOCK_TYPE_AWB_GAIN] =3D { + .group =3D RKISP1_EXT_PARAMS_BLOCK_GROUP_OTHERS, + }, + [RKISP1_EXT_PARAMS_BLOCK_TYPE_FLT] =3D { + .group =3D RKISP1_EXT_PARAMS_BLOCK_GROUP_OTHERS, + }, + [RKISP1_EXT_PARAMS_BLOCK_TYPE_BDM] =3D { + .group =3D RKISP1_EXT_PARAMS_BLOCK_GROUP_OTHERS, + }, + [RKISP1_EXT_PARAMS_BLOCK_TYPE_CTK] =3D { + .group =3D RKISP1_EXT_PARAMS_BLOCK_GROUP_OTHERS, + }, + [RKISP1_EXT_PARAMS_BLOCK_TYPE_GOC] =3D { + .group =3D RKISP1_EXT_PARAMS_BLOCK_GROUP_OTHERS, + }, + [RKISP1_EXT_PARAMS_BLOCK_TYPE_DPF] =3D { + .group =3D RKISP1_EXT_PARAMS_BLOCK_GROUP_OTHERS, + }, + [RKISP1_EXT_PARAMS_BLOCK_TYPE_DPF_STRENGTH] =3D { + .group =3D RKISP1_EXT_PARAMS_BLOCK_GROUP_OTHERS, + }, + [RKISP1_EXT_PARAMS_BLOCK_TYPE_CPROC] =3D { + .group =3D RKISP1_EXT_PARAMS_BLOCK_GROUP_OTHERS, + }, + [RKISP1_EXT_PARAMS_BLOCK_TYPE_IE] =3D { + .group =3D RKISP1_EXT_PARAMS_BLOCK_GROUP_OTHERS, + }, + [RKISP1_EXT_PARAMS_BLOCK_TYPE_LSC] =3D { + .group =3D RKISP1_EXT_PARAMS_BLOCK_GROUP_LSC, + }, + [RKISP1_EXT_PARAMS_BLOCK_TYPE_AWB_MEAS] =3D { + .group =3D RKISP1_EXT_PARAMS_BLOCK_GROUP_OTHERS, + }, + [RKISP1_EXT_PARAMS_BLOCK_TYPE_HST_MEAS] =3D { + .group =3D RKISP1_EXT_PARAMS_BLOCK_GROUP_OTHERS, + }, + [RKISP1_EXT_PARAMS_BLOCK_TYPE_AEC_MEAS] =3D { + .group =3D RKISP1_EXT_PARAMS_BLOCK_GROUP_OTHERS, + }, + [RKISP1_EXT_PARAMS_BLOCK_TYPE_AFC_MEAS] =3D { + .group =3D RKISP1_EXT_PARAMS_BLOCK_GROUP_OTHERS, + }, + [RKISP1_EXT_PARAMS_BLOCK_TYPE_COMPAND_BLS] =3D { + .group =3D RKISP1_EXT_PARAMS_BLOCK_GROUP_OTHERS, + .features =3D RKISP1_FEATURE_COMPAND, + }, + [RKISP1_EXT_PARAMS_BLOCK_TYPE_COMPAND_EXPAND] =3D { + .group =3D RKISP1_EXT_PARAMS_BLOCK_GROUP_OTHERS, + .features =3D RKISP1_FEATURE_COMPAND, + }, + [RKISP1_EXT_PARAMS_BLOCK_TYPE_COMPAND_COMPRESS] =3D { + .group =3D RKISP1_EXT_PARAMS_BLOCK_GROUP_OTHERS, + .features =3D RKISP1_FEATURE_COMPAND, + }, + [RKISP1_EXT_PARAMS_BLOCK_TYPE_WDR] =3D { + .group =3D RKISP1_EXT_PARAMS_BLOCK_GROUP_OTHERS, + }, +}; + +static const struct v4l2_params_handler rkisp1_ext_params_handlers[] =3D { + [RKISP1_EXT_PARAMS_BLOCK_TYPE_BLS] =3D { + .size =3D sizeof(struct rkisp1_ext_params_bls_config), + .handler =3D rkisp1_ext_params_bls, + }, [RKISP1_EXT_PARAMS_BLOCK_TYPE_DPCC] =3D { .size =3D sizeof(struct rkisp1_ext_params_dpcc_config), .handler =3D rkisp1_ext_params_dpcc, - .group =3D RKISP1_EXT_PARAMS_BLOCK_GROUP_OTHERS, }, [RKISP1_EXT_PARAMS_BLOCK_TYPE_SDG] =3D { .size =3D sizeof(struct rkisp1_ext_params_sdg_config), .handler =3D rkisp1_ext_params_sdg, - .group =3D RKISP1_EXT_PARAMS_BLOCK_GROUP_OTHERS, }, [RKISP1_EXT_PARAMS_BLOCK_TYPE_AWB_GAIN] =3D { .size =3D sizeof(struct rkisp1_ext_params_awb_gain_config), .handler =3D rkisp1_ext_params_awbg, - .group =3D RKISP1_EXT_PARAMS_BLOCK_GROUP_OTHERS, }, [RKISP1_EXT_PARAMS_BLOCK_TYPE_FLT] =3D { .size =3D sizeof(struct rkisp1_ext_params_flt_config), .handler =3D rkisp1_ext_params_flt, - .group =3D RKISP1_EXT_PARAMS_BLOCK_GROUP_OTHERS, }, [RKISP1_EXT_PARAMS_BLOCK_TYPE_BDM] =3D { .size =3D sizeof(struct rkisp1_ext_params_bdm_config), .handler =3D rkisp1_ext_params_bdm, - .group =3D RKISP1_EXT_PARAMS_BLOCK_GROUP_OTHERS, }, [RKISP1_EXT_PARAMS_BLOCK_TYPE_CTK] =3D { .size =3D sizeof(struct rkisp1_ext_params_ctk_config), .handler =3D rkisp1_ext_params_ctk, - .group =3D RKISP1_EXT_PARAMS_BLOCK_GROUP_OTHERS, }, [RKISP1_EXT_PARAMS_BLOCK_TYPE_GOC] =3D { .size =3D sizeof(struct rkisp1_ext_params_goc_config), .handler =3D rkisp1_ext_params_goc, - .group =3D RKISP1_EXT_PARAMS_BLOCK_GROUP_OTHERS, }, [RKISP1_EXT_PARAMS_BLOCK_TYPE_DPF] =3D { .size =3D sizeof(struct rkisp1_ext_params_dpf_config), .handler =3D rkisp1_ext_params_dpf, - .group =3D RKISP1_EXT_PARAMS_BLOCK_GROUP_OTHERS, }, [RKISP1_EXT_PARAMS_BLOCK_TYPE_DPF_STRENGTH] =3D { .size =3D sizeof(struct rkisp1_ext_params_dpf_strength_config), .handler =3D rkisp1_ext_params_dpfs, - .group =3D RKISP1_EXT_PARAMS_BLOCK_GROUP_OTHERS, }, [RKISP1_EXT_PARAMS_BLOCK_TYPE_CPROC] =3D { .size =3D sizeof(struct rkisp1_ext_params_cproc_config), .handler =3D rkisp1_ext_params_cproc, - .group =3D RKISP1_EXT_PARAMS_BLOCK_GROUP_OTHERS, }, [RKISP1_EXT_PARAMS_BLOCK_TYPE_IE] =3D { .size =3D sizeof(struct rkisp1_ext_params_ie_config), .handler =3D rkisp1_ext_params_ie, - .group =3D RKISP1_EXT_PARAMS_BLOCK_GROUP_OTHERS, }, [RKISP1_EXT_PARAMS_BLOCK_TYPE_LSC] =3D { .size =3D sizeof(struct rkisp1_ext_params_lsc_config), .handler =3D rkisp1_ext_params_lsc, - .group =3D RKISP1_EXT_PARAMS_BLOCK_GROUP_LSC, }, [RKISP1_EXT_PARAMS_BLOCK_TYPE_AWB_MEAS] =3D { .size =3D sizeof(struct rkisp1_ext_params_awb_meas_config), .handler =3D rkisp1_ext_params_awbm, - .group =3D RKISP1_EXT_PARAMS_BLOCK_GROUP_OTHERS, }, [RKISP1_EXT_PARAMS_BLOCK_TYPE_HST_MEAS] =3D { .size =3D sizeof(struct rkisp1_ext_params_hst_config), .handler =3D rkisp1_ext_params_hstm, - .group =3D RKISP1_EXT_PARAMS_BLOCK_GROUP_OTHERS, }, [RKISP1_EXT_PARAMS_BLOCK_TYPE_AEC_MEAS] =3D { .size =3D sizeof(struct rkisp1_ext_params_aec_config), .handler =3D rkisp1_ext_params_aecm, - .group =3D RKISP1_EXT_PARAMS_BLOCK_GROUP_OTHERS, }, [RKISP1_EXT_PARAMS_BLOCK_TYPE_AFC_MEAS] =3D { .size =3D sizeof(struct rkisp1_ext_params_afc_config), .handler =3D rkisp1_ext_params_afcm, - .group =3D RKISP1_EXT_PARAMS_BLOCK_GROUP_OTHERS, }, [RKISP1_EXT_PARAMS_BLOCK_TYPE_COMPAND_BLS] =3D { .size =3D sizeof(struct rkisp1_ext_params_compand_bls_config), .handler =3D rkisp1_ext_params_compand_bls, - .group =3D RKISP1_EXT_PARAMS_BLOCK_GROUP_OTHERS, - .features =3D RKISP1_FEATURE_COMPAND, }, [RKISP1_EXT_PARAMS_BLOCK_TYPE_COMPAND_EXPAND] =3D { .size =3D sizeof(struct rkisp1_ext_params_compand_curve_config), .handler =3D rkisp1_ext_params_compand_expand, - .group =3D RKISP1_EXT_PARAMS_BLOCK_GROUP_OTHERS, - .features =3D RKISP1_FEATURE_COMPAND, }, [RKISP1_EXT_PARAMS_BLOCK_TYPE_COMPAND_COMPRESS] =3D { .size =3D sizeof(struct rkisp1_ext_params_compand_curve_config), .handler =3D rkisp1_ext_params_compand_compress, - .group =3D RKISP1_EXT_PARAMS_BLOCK_GROUP_OTHERS, - .features =3D RKISP1_FEATURE_COMPAND, }, [RKISP1_EXT_PARAMS_BLOCK_TYPE_WDR] =3D { .size =3D sizeof(struct rkisp1_ext_params_wdr_config), .handler =3D rkisp1_ext_params_wdr, - .group =3D RKISP1_EXT_PARAMS_BLOCK_GROUP_OTHERS, }, }; =20 @@ -2224,31 +2265,33 @@ static void rkisp1_ext_params_config(struct rkisp1_= params *params, =20 /* Walk the list of parameter blocks and process them. */ while (block_offset < cfg->data_size) { - const struct rkisp1_ext_params_handler *block_handler; - const union rkisp1_ext_params_config *block; + const struct rkisp1_params_block_feature *block_features; + const struct v4l2_params_handler *block_handler; + const struct v4l2_params_block_header *block; =20 - block =3D (const union rkisp1_ext_params_config *) + block =3D (const struct v4l2_params_block_header *) &cfg->data[block_offset]; - block_offset +=3D block->header.size; + block_offset +=3D block->size; =20 /* * Make sure the block is supported by the platform and in the * list of groups to configure. */ - block_handler =3D &rkisp1_ext_params_handlers[block->header.type]; - if (!(block_handler->group & block_group_mask)) + block_features =3D &rkisp1_ext_params_features[block->type]; + if (!(block_features->group & block_group_mask)) continue; =20 - if ((params->rkisp1->info->features & block_handler->features) !=3D - block_handler->features) + if ((params->rkisp1->info->features & block_features->features) + !=3D block_features->features) continue; =20 + block_handler =3D &rkisp1_ext_params_handlers[block->type]; block_handler->handler(params, block); =20 - if (block->header.flags & RKISP1_EXT_PARAMS_FL_BLOCK_DISABLE) - params->enabled_blocks &=3D ~BIT(block->header.type); - else if (block->header.flags & RKISP1_EXT_PARAMS_FL_BLOCK_ENABLE) - params->enabled_blocks |=3D BIT(block->header.type); + if (block->flags & RKISP1_EXT_PARAMS_FL_BLOCK_DISABLE) + params->enabled_blocks &=3D ~BIT(block->type); + else if (block->flags & RKISP1_EXT_PARAMS_FL_BLOCK_ENABLE) + params->enabled_blocks |=3D BIT(block->type); } } =20 @@ -2646,31 +2689,24 @@ static int rkisp1_params_prepare_ext_params(struct = rkisp1_params *params, { struct vb2_v4l2_buffer *vbuf =3D to_vb2_v4l2_buffer(vb); struct rkisp1_params_buffer *params_buf =3D to_rkisp1_params_buffer(vbuf); - size_t header_size =3D offsetof(struct rkisp1_ext_params_cfg, data); struct rkisp1_ext_params_cfg *cfg =3D params_buf->cfg; size_t payload_size =3D vb2_get_plane_payload(vb, 0); struct rkisp1_ext_params_cfg *usr_cfg =3D vb2_plane_vaddr(&vbuf->vb2_buf, 0); - size_t block_offset =3D 0; - size_t cfg_size; + int ret; =20 - /* - * Validate the buffer payload size before copying the parameters. The - * payload has to be smaller than the destination buffer size and larger - * than the header size. - */ - if (payload_size > params->metafmt->buffersize) { + /* Only v1 is supported at the moment. */ + if (usr_cfg->version !=3D RKISP1_EXT_PARAM_BUFFER_V1) { dev_dbg(params->rkisp1->dev, - "Too large buffer payload size %zu\n", payload_size); + "Unsupported extensible parameters version: %u\n", + usr_cfg->version); return -EINVAL; } =20 - if (payload_size < header_size) { - dev_dbg(params->rkisp1->dev, - "Buffer payload %zu smaller than header size %zu\n", - payload_size, header_size); - return -EINVAL; - } + ret =3D v4l2_params_buffer_validate(params->rkisp1->dev, vb, + params->metafmt->buffersize); + if (ret) + return ret; =20 /* * Copy the parameters buffer to the internal scratch buffer to avoid @@ -2678,71 +2714,10 @@ static int rkisp1_params_prepare_ext_params(struct = rkisp1_params *params, */ memcpy(cfg, usr_cfg, payload_size); =20 - /* Only v1 is supported at the moment. */ - if (cfg->version !=3D RKISP1_EXT_PARAM_BUFFER_V1) { - dev_dbg(params->rkisp1->dev, - "Unsupported extensible format version: %u\n", - cfg->version); - return -EINVAL; - } - - /* Validate the size reported in the parameters buffer header. */ - cfg_size =3D header_size + cfg->data_size; - if (cfg_size !=3D payload_size) { - dev_dbg(params->rkisp1->dev, - "Data size %zu different than buffer payload size %zu\n", - cfg_size, payload_size); - return -EINVAL; - } - - /* Walk the list of parameter blocks and validate them. */ - cfg_size =3D cfg->data_size; - while (cfg_size >=3D sizeof(struct rkisp1_ext_params_block_header)) { - const struct rkisp1_ext_params_block_header *block; - const struct rkisp1_ext_params_handler *handler; - - block =3D (const struct rkisp1_ext_params_block_header *) - &cfg->data[block_offset]; - - if (block->type >=3D ARRAY_SIZE(rkisp1_ext_params_handlers)) { - dev_dbg(params->rkisp1->dev, - "Invalid parameters block type\n"); - return -EINVAL; - } - - if (block->size > cfg_size) { - dev_dbg(params->rkisp1->dev, - "Premature end of parameters data\n"); - return -EINVAL; - } - - if ((block->flags & (RKISP1_EXT_PARAMS_FL_BLOCK_ENABLE | - RKISP1_EXT_PARAMS_FL_BLOCK_DISABLE)) =3D=3D - (RKISP1_EXT_PARAMS_FL_BLOCK_ENABLE | - RKISP1_EXT_PARAMS_FL_BLOCK_DISABLE)) { - dev_dbg(params->rkisp1->dev, - "Invalid parameters block flags\n"); - return -EINVAL; - } - - handler =3D &rkisp1_ext_params_handlers[block->type]; - if (block->size !=3D handler->size) { - dev_dbg(params->rkisp1->dev, - "Invalid parameters block size\n"); - return -EINVAL; - } - - block_offset +=3D block->size; - cfg_size -=3D block->size; - } - - if (cfg_size) { - dev_dbg(params->rkisp1->dev, - "Unexpected data after the parameters buffer end\n"); - return -EINVAL; - } - - return 0; + return v4l2_params_blocks_validate(params->rkisp1->dev, + (struct v4l2_params_buffer *)cfg, + rkisp1_ext_params_handlers, + ARRAY_SIZE(rkisp1_ext_params_handlers)); } =20 static int rkisp1_params_vb2_buf_prepare(struct vb2_buffer *vb) @@ -2842,13 +2817,13 @@ static int rkisp1_params_ctrl_init(struct rkisp1_pa= rams *params) v4l2_ctrl_handler_init(¶ms->ctrls, 1); =20 for (unsigned int i =3D 0; i < ARRAY_SIZE(rkisp1_ext_params_handlers); i+= +) { - const struct rkisp1_ext_params_handler *block_handler; + const struct rkisp1_params_block_feature *block_features; =20 - block_handler =3D &rkisp1_ext_params_handlers[i]; + block_features =3D &rkisp1_ext_params_features[i]; ctrl_config.max |=3D BIT(i); =20 - if ((params->rkisp1->info->features & block_handler->features) !=3D - block_handler->features) + if ((params->rkisp1->info->features & block_features->features) + !=3D block_features->features) continue; =20 ctrl_config.def |=3D BIT(i); --=20 2.51.0 From nobody Thu Oct 2 14:13:11 2025 Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7146228506A; Mon, 15 Sep 2025 17:18:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=213.167.242.64 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757956731; cv=none; b=GjykBr8pwY3JdmkvPPvJ9/b3T4+eghlwRGDtCE2IVMonrjh4jIS64ExZrJLKskz63DL2y4s1Yo7f+rFdy1XBT4mL5xSbZ3ifHLMzLB+zedU1xnETRXQKDXIR4I4lTmUBIiQb/ZPeOWJn59xgqSDECjvouQCHIMsHYQsOwzFith4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757956731; c=relaxed/simple; bh=/NmDGZQI2lM6SbwdmJ5OKwVIOaLD5M5E4aLs/01NVj8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=BoHrvLDH8N/46lcELOqxID2TPKrHRkJQwhWWBK7QZ+xswCQKqOkVLV6Kq1DBbJmW+QW2R5Twxxvp8rZ387J5SEAsR6oX1EYpT0dA6jLTd3hN7cHkqxlFU6A0xWTZ1Ibi+/cESWmYn+P4aaNP+7X44PAwHZo01JtB9G5edy0FYiA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=ideasonboard.com; spf=pass smtp.mailfrom=ideasonboard.com; dkim=pass (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.b=qQfIpyn/; arc=none smtp.client-ip=213.167.242.64 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=ideasonboard.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ideasonboard.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="qQfIpyn/" Received: from [192.168.0.172] (mob-5-90-56-182.net.vodafone.it [5.90.56.182]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id BEDE71752; Mon, 15 Sep 2025 19:17:25 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1757956646; bh=/NmDGZQI2lM6SbwdmJ5OKwVIOaLD5M5E4aLs/01NVj8=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=qQfIpyn/H5whGlbCGM1Yh8Q4Mzg14vgO26bdc2vh4oCQheX6tDRxNAUZ1otsLdlEc bex+X6R4Wh179IcyH97Gb51kCzxkesmscarSxvj3ya4KmVi929HRPA+KhZfIB5HLjd S0BpBoLvKs0q+B86vrddiD9PnQ83+mtHfz9PcK+Y= From: Jacopo Mondi Date: Mon, 15 Sep 2025 19:18:16 +0200 Subject: [PATCH v5 7/8] media: amlogic-c3: Use v4l2-isp for validation Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250915-extensible-parameters-validation-v5-7-e6db94468af3@ideasonboard.com> References: <20250915-extensible-parameters-validation-v5-0-e6db94468af3@ideasonboard.com> In-Reply-To: <20250915-extensible-parameters-validation-v5-0-e6db94468af3@ideasonboard.com> To: Dafna Hirschfeld , Laurent Pinchart , Keke Li , Mauro Carvalho Chehab , Heiko Stuebner , Dan Scally , Sakari Ailus , Antoine Bouyer Cc: linux-kernel@vger.kernel.org, linux-media@vger.kernel.org, linux-rockchip@lists.infradead.org, linux-arm-kernel@lists.infradead.org, Jacopo Mondi X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=17731; i=jacopo.mondi@ideasonboard.com; h=from:subject:message-id; bh=/NmDGZQI2lM6SbwdmJ5OKwVIOaLD5M5E4aLs/01NVj8=; b=owEBbQKS/ZANAwAKAXI0Bo8WoVY8AcsmYgBoyEppsiyELw5fUbDkUAPZEqDr+Ie6oZcvmG+Mj a9AS9kR7KiJAjMEAAEKAB0WIQS1xD1IgJogio9YOMByNAaPFqFWPAUCaMhKaQAKCRByNAaPFqFW PAH2D/49V3SwXEjUqxWGElftabY5eXRFM9Hdm3RrbpTX+7Kj6EgyvoNHRMqKjyjioxsgnFKD0Mr X0fu2FqiCfSmCNglNHCLp6ApgRG2ZAkZkpeokGmE5o5Pya2c5nl8TIcGdpJ+lb38t97T8gNA52P E6BUKuj/hBIh0mQ43jPg3C8TVFqYDHtojtEoKW/wC2nLG1aKTKNTblgQyntQm8+wgVWmiurXz7Q pt11YhFi1ar6Uo54gb/4wLbiQi0G1LBHJtT8S8cgWt6LopumX7rAF21321d0qfWLsz2mYyrrAVP FH5CBVgpqv2rxCRBa4loJvcAX33nqa8irS0lYQoIi1k+Y5+wRCKlan+Rda3wWv1gDmgCxxo83VD uQKH6P5dWZqEWsS608/ZHEiCc7Nj+D5bxcQoEb/EfFcdJc6OQ3z5G/2VbayBm8OyBLKJ2YO4Lqv ok2W6+zPbIt9RCZc6dq3kNCF6BP1ZrE8PLTbRFBVXuHWqfS0H170hk7JmPYrfRlPq+wzz/HJ42e 0jjlEmZ4Tam/htrkUIsUNhMRKUUJLAtUYWVEFjQCdV4lmXCgI+Y8hn5/xGVbWjzUtYuJZ0dr9TX 9wy2vQWDlurWR8+g3JL9PvQ1yuYXtxqplEaqIK3J5VUMrGte/XRog/S1DhSwXoDfmo8Q5SoIf4B Tl+/ceM/T5+1nhA== X-Developer-Key: i=jacopo.mondi@ideasonboard.com; a=openpgp; fpr=72392EDC88144A65C701EA9BA5826A2587AD026B Convert c3-ispa-params.c to use the new types fro block handlers defined in v4l2-isp.h and use the new helpers from v4l2-isp.c to remove boilerplate code from the driver. Reviewed-by: Keke Li Reviewed-by: Daniel Scally Signed-off-by: Jacopo Mondi Acked-by: Sakari Ailus --- drivers/media/platform/amlogic/c3/isp/Kconfig | 1 + .../media/platform/amlogic/c3/isp/c3-isp-params.c | 248 +++++++----------= ---- 2 files changed, 83 insertions(+), 166 deletions(-) diff --git a/drivers/media/platform/amlogic/c3/isp/Kconfig b/drivers/media/= platform/amlogic/c3/isp/Kconfig index 02c62a50a5e88eac665e27abf163e5d654faed3f..809208cd7e3aa7ca0821cb07366= ec73a47edb278 100644 --- a/drivers/media/platform/amlogic/c3/isp/Kconfig +++ b/drivers/media/platform/amlogic/c3/isp/Kconfig @@ -10,6 +10,7 @@ config VIDEO_C3_ISP select VIDEO_V4L2_SUBDEV_API select VIDEOBUF2_DMA_CONTIG select VIDEOBUF2_VMALLOC + select V4L2_ISP help Video4Linux2 driver for Amlogic C3 ISP pipeline. The C3 ISP is used for processing raw images and diff --git a/drivers/media/platform/amlogic/c3/isp/c3-isp-params.c b/driver= s/media/platform/amlogic/c3/isp/c3-isp-params.c index c80667dd766210d2b2e1ee60c8254a5814b9d81b..0e9d19c84bd429a142aa18fcb49= 0925059d5d77c 100644 --- a/drivers/media/platform/amlogic/c3/isp/c3-isp-params.c +++ b/drivers/media/platform/amlogic/c3/isp/c3-isp-params.c @@ -8,65 +8,27 @@ #include =20 #include +#include #include #include =20 #include "c3-isp-common.h" #include "c3-isp-regs.h" =20 -/* - * union c3_isp_params_block - Generalisation of a parameter block - * - * This union allows the driver to treat a block as a generic struct to th= is - * union and safely access the header and block-specific struct without ha= ving - * to resort to casting. The header member is accessed first, and the type= field - * checked which allows the driver to determine which of the other members - * should be used. - * - * @header: The shared header struct embedded as the first member - * of all the possible other members. This member would be - * accessed first and the type field checked to determine - * which of the other members should be accessed. - * @awb_gains: For header.type =3D=3D C3_ISP_PARAMS_BLOCK_AWB_GAINS - * @awb_cfg: For header.type =3D=3D C3_ISP_PARAMS_BLOCK_AWB_CONFIG - * @ae_cfg: For header.type =3D=3D C3_ISP_PARAMS_BLOCK_AE_CONFIG - * @af_cfg: For header.type =3D=3D C3_ISP_PARAMS_BLOCK_AF_CONFIG - * @pst_gamma: For header.type =3D=3D C3_ISP_PARAMS_BLOCK_PST_GAMMA - * @ccm: For header.type =3D=3D C3_ISP_PARAMS_BLOCK_CCM - * @csc: For header.type =3D=3D C3_ISP_PARAMS_BLOCK_CSC - * @blc: For header.type =3D=3D C3_ISP_PARAMS_BLOCK_BLC - */ -union c3_isp_params_block { - struct c3_isp_params_block_header header; - struct c3_isp_params_awb_gains awb_gains; - struct c3_isp_params_awb_config awb_cfg; - struct c3_isp_params_ae_config ae_cfg; - struct c3_isp_params_af_config af_cfg; - struct c3_isp_params_pst_gamma pst_gamma; - struct c3_isp_params_ccm ccm; - struct c3_isp_params_csc csc; - struct c3_isp_params_blc blc; -}; - -typedef void (*c3_isp_block_handler)(struct c3_isp_device *isp, - const union c3_isp_params_block *block); - -struct c3_isp_params_handler { - size_t size; - c3_isp_block_handler handler; -}; - #define to_c3_isp_params_buffer(vbuf) \ container_of(vbuf, struct c3_isp_params_buffer, vb) =20 /* Hardware configuration */ =20 -static void c3_isp_params_cfg_awb_gains(struct c3_isp_device *isp, - const union c3_isp_params_block *block) +static void +c3_isp_params_cfg_awb_gains(void *dev, + const struct v4l2_params_block_header *block) { - const struct c3_isp_params_awb_gains *awb_gains =3D &block->awb_gains; + const struct c3_isp_params_awb_gains *awb_gains =3D + (const struct c3_isp_params_awb_gains *)block; + struct c3_isp_device *isp =3D dev; =20 - if (block->header.flags & C3_ISP_PARAMS_BLOCK_FL_DISABLE) { + if (block->flags & C3_ISP_PARAMS_BLOCK_FL_DISABLE) { c3_isp_update_bits(isp, ISP_TOP_BEO_CTRL, ISP_TOP_BEO_CTRL_WB_EN_MASK, ISP_TOP_BEO_CTRL_WB_DIS); @@ -89,7 +51,7 @@ static void c3_isp_params_cfg_awb_gains(struct c3_isp_dev= ice *isp, ISP_LSWB_WB_GAIN2_IR_GAIN_MASK, ISP_LSWB_WB_GAIN2_IR_GAIN(awb_gains->gb_gain)); =20 - if (block->header.flags & C3_ISP_PARAMS_BLOCK_FL_ENABLE) + if (block->flags & C3_ISP_PARAMS_BLOCK_FL_ENABLE) c3_isp_update_bits(isp, ISP_TOP_BEO_CTRL, ISP_TOP_BEO_CTRL_WB_EN_MASK, ISP_TOP_BEO_CTRL_WB_EN); @@ -151,12 +113,15 @@ static void c3_isp_params_awb_cood(struct c3_isp_devi= ce *isp, ISP_AWB_IDX_DATA_VIDX_DATA(cfg->vert_coord[i])); } =20 -static void c3_isp_params_cfg_awb_config(struct c3_isp_device *isp, - const union c3_isp_params_block *block) +static void +c3_isp_params_cfg_awb_config(void *dev, + const struct v4l2_params_block_header *block) { - const struct c3_isp_params_awb_config *awb_cfg =3D &block->awb_cfg; + const struct c3_isp_params_awb_config *awb_cfg =3D + (const struct c3_isp_params_awb_config *)block; + struct c3_isp_device *isp =3D dev; =20 - if (block->header.flags & C3_ISP_PARAMS_BLOCK_FL_DISABLE) { + if (block->flags & C3_ISP_PARAMS_BLOCK_FL_DISABLE) { c3_isp_update_bits(isp, ISP_TOP_3A_STAT_CRTL, ISP_TOP_3A_STAT_CRTL_AWB_STAT_EN_MASK, ISP_TOP_3A_STAT_CRTL_AWB_STAT_DIS); @@ -205,7 +170,7 @@ static void c3_isp_params_cfg_awb_config(struct c3_isp_= device *isp, c3_isp_params_awb_wt(isp, awb_cfg); c3_isp_params_awb_cood(isp, awb_cfg); =20 - if (block->header.flags & C3_ISP_PARAMS_BLOCK_FL_ENABLE) + if (block->flags & C3_ISP_PARAMS_BLOCK_FL_ENABLE) c3_isp_update_bits(isp, ISP_TOP_3A_STAT_CRTL, ISP_TOP_3A_STAT_CRTL_AWB_STAT_EN_MASK, ISP_TOP_3A_STAT_CRTL_AWB_STAT_EN); @@ -268,12 +233,15 @@ static void c3_isp_params_ae_cood(struct c3_isp_devic= e *isp, ISP_AE_IDX_DATA_VIDX_DATA(cfg->vert_coord[i])); } =20 -static void c3_isp_params_cfg_ae_config(struct c3_isp_device *isp, - const union c3_isp_params_block *block) +static void +c3_isp_params_cfg_ae_config(void *dev, + const struct v4l2_params_block_header *block) { - const struct c3_isp_params_ae_config *ae_cfg =3D &block->ae_cfg; + const struct c3_isp_params_ae_config *ae_cfg =3D + (const struct c3_isp_params_ae_config *)block; + struct c3_isp_device *isp =3D dev; =20 - if (block->header.flags & C3_ISP_PARAMS_BLOCK_FL_DISABLE) { + if (block->flags & C3_ISP_PARAMS_BLOCK_FL_DISABLE) { c3_isp_update_bits(isp, ISP_TOP_3A_STAT_CRTL, ISP_TOP_3A_STAT_CRTL_AE_STAT_EN_MASK, ISP_TOP_3A_STAT_CRTL_AE_STAT_DIS); @@ -303,7 +271,7 @@ static void c3_isp_params_cfg_ae_config(struct c3_isp_d= evice *isp, c3_isp_params_ae_wt(isp, ae_cfg); c3_isp_params_ae_cood(isp, ae_cfg); =20 - if (block->header.flags & C3_ISP_PARAMS_BLOCK_FL_ENABLE) + if (block->flags & C3_ISP_PARAMS_BLOCK_FL_ENABLE) c3_isp_update_bits(isp, ISP_TOP_3A_STAT_CRTL, ISP_TOP_3A_STAT_CRTL_AE_STAT_EN_MASK, ISP_TOP_3A_STAT_CRTL_AE_STAT_EN); @@ -326,12 +294,15 @@ static void c3_isp_params_af_cood(struct c3_isp_devic= e *isp, ISP_AF_IDX_DATA_VIDX_DATA(cfg->vert_coord[i])); } =20 -static void c3_isp_params_cfg_af_config(struct c3_isp_device *isp, - const union c3_isp_params_block *block) +static void +c3_isp_params_cfg_af_config(void *dev, + const struct v4l2_params_block_header *block) { - const struct c3_isp_params_af_config *af_cfg =3D &block->af_cfg; + const struct c3_isp_params_af_config *af_cfg =3D + (const struct c3_isp_params_af_config *)block; + struct c3_isp_device *isp =3D dev; =20 - if (block->header.flags & C3_ISP_PARAMS_BLOCK_FL_DISABLE) { + if (block->flags & C3_ISP_PARAMS_BLOCK_FL_DISABLE) { c3_isp_update_bits(isp, ISP_TOP_3A_STAT_CRTL, ISP_TOP_3A_STAT_CRTL_AF_STAT_EN_MASK, ISP_TOP_3A_STAT_CRTL_AF_STAT_DIS); @@ -351,20 +322,23 @@ static void c3_isp_params_cfg_af_config(struct c3_isp= _device *isp, =20 c3_isp_params_af_cood(isp, af_cfg); =20 - if (block->header.flags & C3_ISP_PARAMS_BLOCK_FL_ENABLE) + if (block->flags & C3_ISP_PARAMS_BLOCK_FL_ENABLE) c3_isp_update_bits(isp, ISP_TOP_3A_STAT_CRTL, ISP_TOP_3A_STAT_CRTL_AF_STAT_EN_MASK, ISP_TOP_3A_STAT_CRTL_AF_STAT_EN); } =20 -static void c3_isp_params_cfg_pst_gamma(struct c3_isp_device *isp, - const union c3_isp_params_block *block) +static void +c3_isp_params_cfg_pst_gamma(void *dev, + const struct v4l2_params_block_header *block) { - const struct c3_isp_params_pst_gamma *gm =3D &block->pst_gamma; + const struct c3_isp_params_pst_gamma *gm =3D + (const struct c3_isp_params_pst_gamma *)block; + struct c3_isp_device *isp =3D dev; unsigned int base; unsigned int i; =20 - if (block->header.flags & C3_ISP_PARAMS_BLOCK_FL_DISABLE) { + if (block->flags & C3_ISP_PARAMS_BLOCK_FL_DISABLE) { c3_isp_update_bits(isp, ISP_TOP_BED_CTRL, ISP_TOP_BED_CTRL_PST_GAMMA_EN_MASK, ISP_TOP_BED_CTRL_PST_GAMMA_DIS); @@ -393,19 +367,21 @@ static void c3_isp_params_cfg_pst_gamma(struct c3_isp= _device *isp, } } =20 - if (block->header.flags & C3_ISP_PARAMS_BLOCK_FL_ENABLE) + if (block->flags & C3_ISP_PARAMS_BLOCK_FL_ENABLE) c3_isp_update_bits(isp, ISP_TOP_BED_CTRL, ISP_TOP_BED_CTRL_PST_GAMMA_EN_MASK, ISP_TOP_BED_CTRL_PST_GAMMA_EN); } =20 /* Configure 3 x 3 ccm matrix */ -static void c3_isp_params_cfg_ccm(struct c3_isp_device *isp, - const union c3_isp_params_block *block) +static void c3_isp_params_cfg_ccm(void *dev, + const struct v4l2_params_block_header *block) { - const struct c3_isp_params_ccm *ccm =3D &block->ccm; + const struct c3_isp_params_ccm *ccm =3D + (const struct c3_isp_params_ccm *)block; + struct c3_isp_device *isp =3D dev; =20 - if (block->header.flags & C3_ISP_PARAMS_BLOCK_FL_DISABLE) { + if (block->flags & C3_ISP_PARAMS_BLOCK_FL_DISABLE) { c3_isp_update_bits(isp, ISP_TOP_BED_CTRL, ISP_TOP_BED_CTRL_CCM_EN_MASK, ISP_TOP_BED_CTRL_CCM_DIS); @@ -442,19 +418,21 @@ static void c3_isp_params_cfg_ccm(struct c3_isp_devic= e *isp, ISP_CCM_MTX_22_23_RS_MTX_22_MASK, ISP_CCM_MTX_22_23_RS_MTX_22(ccm->matrix[2][2])); =20 - if (block->header.flags & C3_ISP_PARAMS_BLOCK_FL_ENABLE) + if (block->flags & C3_ISP_PARAMS_BLOCK_FL_ENABLE) c3_isp_update_bits(isp, ISP_TOP_BED_CTRL, ISP_TOP_BED_CTRL_CCM_EN_MASK, ISP_TOP_BED_CTRL_CCM_EN); } =20 /* Configure color space conversion matrix parameters */ -static void c3_isp_params_cfg_csc(struct c3_isp_device *isp, - const union c3_isp_params_block *block) +static void c3_isp_params_cfg_csc(void *dev, + const struct v4l2_params_block_header *block) { - const struct c3_isp_params_csc *csc =3D &block->csc; + const struct c3_isp_params_csc *csc =3D + (const struct c3_isp_params_csc *)block; + struct c3_isp_device *isp =3D dev; =20 - if (block->header.flags & C3_ISP_PARAMS_BLOCK_FL_DISABLE) { + if (block->flags & C3_ISP_PARAMS_BLOCK_FL_DISABLE) { c3_isp_update_bits(isp, ISP_TOP_BED_CTRL, ISP_TOP_BED_CTRL_CM0_EN_MASK, ISP_TOP_BED_CTRL_CM0_DIS); @@ -491,19 +469,21 @@ static void c3_isp_params_cfg_csc(struct c3_isp_devic= e *isp, ISP_CM0_COEF22_OUP_OFST0_MTX_22_MASK, ISP_CM0_COEF22_OUP_OFST0_MTX_22(csc->matrix[2][2])); =20 - if (block->header.flags & C3_ISP_PARAMS_BLOCK_FL_ENABLE) + if (block->flags & C3_ISP_PARAMS_BLOCK_FL_ENABLE) c3_isp_update_bits(isp, ISP_TOP_BED_CTRL, ISP_TOP_BED_CTRL_CM0_EN_MASK, ISP_TOP_BED_CTRL_CM0_EN); } =20 /* Set blc offset of each color channel */ -static void c3_isp_params_cfg_blc(struct c3_isp_device *isp, - const union c3_isp_params_block *block) +static void c3_isp_params_cfg_blc(void *dev, + const struct v4l2_params_block_header *block) { - const struct c3_isp_params_blc *blc =3D &block->blc; + const struct c3_isp_params_blc *blc =3D + (const struct c3_isp_params_blc *)block; + struct c3_isp_device *isp =3D dev; =20 - if (block->header.flags & C3_ISP_PARAMS_BLOCK_FL_DISABLE) { + if (block->flags & C3_ISP_PARAMS_BLOCK_FL_DISABLE) { c3_isp_update_bits(isp, ISP_TOP_BEO_CTRL, ISP_TOP_BEO_CTRL_BLC_EN_MASK, ISP_TOP_BEO_CTRL_BLC_DIS); @@ -517,13 +497,13 @@ static void c3_isp_params_cfg_blc(struct c3_isp_devic= e *isp, ISP_LSWB_BLC_OFST1_GB_OFST(blc->gb_ofst) | ISP_LSWB_BLC_OFST1_B_OFST(blc->b_ofst)); =20 - if (block->header.flags & C3_ISP_PARAMS_BLOCK_FL_ENABLE) + if (block->flags & C3_ISP_PARAMS_BLOCK_FL_ENABLE) c3_isp_update_bits(isp, ISP_TOP_BEO_CTRL, ISP_TOP_BEO_CTRL_BLC_EN_MASK, ISP_TOP_BEO_CTRL_BLC_EN); } =20 -static const struct c3_isp_params_handler c3_isp_params_handlers[] =3D { +static const struct v4l2_params_handler c3_isp_params_handlers[] =3D { [C3_ISP_PARAMS_BLOCK_AWB_GAINS] =3D { .size =3D sizeof(struct c3_isp_params_awb_gains), .handler =3D c3_isp_params_cfg_awb_gains, @@ -568,16 +548,16 @@ static void c3_isp_params_cfg_blocks(struct c3_isp_pa= rams *params) =20 /* Walk the list of parameter blocks and process them */ while (block_offset < config->data_size) { - const struct c3_isp_params_handler *block_handler; - const union c3_isp_params_block *block; + const struct v4l2_params_handler *block_handler; + const struct v4l2_params_block_header *block; =20 - block =3D (const union c3_isp_params_block *) + block =3D (const struct v4l2_params_block_header *) &config->data[block_offset]; =20 - block_handler =3D &c3_isp_params_handlers[block->header.type]; + block_handler =3D &c3_isp_params_handlers[block->type]; block_handler->handler(params->isp, block); =20 - block_offset +=3D block->header.size; + block_offset +=3D block->size; } } =20 @@ -771,26 +751,22 @@ static int c3_isp_params_vb2_buf_prepare(struct vb2_b= uffer *vb) struct vb2_v4l2_buffer *vbuf =3D to_vb2_v4l2_buffer(vb); struct c3_isp_params_buffer *buf =3D to_c3_isp_params_buffer(vbuf); struct c3_isp_params *params =3D vb2_get_drv_priv(vb->vb2_queue); - struct c3_isp_params_cfg *cfg =3D buf->cfg; struct c3_isp_params_cfg *usr_cfg =3D vb2_plane_vaddr(vb, 0); size_t payload_size =3D vb2_get_plane_payload(vb, 0); - size_t header_size =3D offsetof(struct c3_isp_params_cfg, data); - size_t block_offset =3D 0; - size_t cfg_size; + struct c3_isp_params_cfg *cfg =3D buf->cfg; + int ret; =20 - /* Payload size can't be greater than the destination buffer size */ - if (payload_size > params->vfmt.fmt.meta.buffersize) { - dev_dbg(params->isp->dev, - "Payload size is too large: %zu\n", payload_size); + /* Only v0 is supported at the moment */ + if (usr_cfg->version !=3D C3_ISP_PARAMS_BUFFER_V0) { + dev_dbg(params->isp->dev, "Invalid params buffer version: %u\n", + usr_cfg->version); return -EINVAL; } =20 - /* Payload size can't be smaller than the header size */ - if (payload_size < header_size) { - dev_dbg(params->isp->dev, - "Payload size is too small: %zu\n", payload_size); - return -EINVAL; - } + ret =3D v4l2_params_buffer_validate(params->isp->dev, vb, + params->vfmt.fmt.meta.buffersize); + if (ret) + return ret; =20 /* * Use the internal scratch buffer to avoid userspace modifying @@ -798,70 +774,10 @@ static int c3_isp_params_vb2_buf_prepare(struct vb2_b= uffer *vb) */ memcpy(cfg, usr_cfg, payload_size); =20 - /* Only v0 is supported at the moment */ - if (cfg->version !=3D C3_ISP_PARAMS_BUFFER_V0) { - dev_dbg(params->isp->dev, - "Invalid params buffer version: %u\n", cfg->version); - return -EINVAL; - } - - /* Validate the size reported in the parameter buffer header */ - cfg_size =3D header_size + cfg->data_size; - if (cfg_size !=3D payload_size) { - dev_dbg(params->isp->dev, - "Data size %zu and payload size %zu are different\n", - cfg_size, payload_size); - return -EINVAL; - } - - /* Walk the list of parameter blocks and validate them */ - cfg_size =3D cfg->data_size; - while (cfg_size >=3D sizeof(struct c3_isp_params_block_header)) { - const struct c3_isp_params_block_header *block; - const struct c3_isp_params_handler *handler; - - block =3D (struct c3_isp_params_block_header *) - &cfg->data[block_offset]; - - if (block->type >=3D ARRAY_SIZE(c3_isp_params_handlers)) { - dev_dbg(params->isp->dev, - "Invalid params block type\n"); - return -EINVAL; - } - - if (block->size > cfg_size) { - dev_dbg(params->isp->dev, - "Block size is greater than cfg size\n"); - return -EINVAL; - } - - if ((block->flags & (C3_ISP_PARAMS_BLOCK_FL_ENABLE | - C3_ISP_PARAMS_BLOCK_FL_DISABLE)) =3D=3D - (C3_ISP_PARAMS_BLOCK_FL_ENABLE | - C3_ISP_PARAMS_BLOCK_FL_DISABLE)) { - dev_dbg(params->isp->dev, - "Invalid parameters block flags\n"); - return -EINVAL; - } - - handler =3D &c3_isp_params_handlers[block->type]; - if (block->size !=3D handler->size) { - dev_dbg(params->isp->dev, - "Invalid params block size\n"); - return -EINVAL; - } - - block_offset +=3D block->size; - cfg_size -=3D block->size; - } - - if (cfg_size) { - dev_dbg(params->isp->dev, - "Unexpected data after the params buffer end\n"); - return -EINVAL; - } - - return 0; + return v4l2_params_blocks_validate(params->isp->dev, + (struct v4l2_params_buffer *)cfg, + c3_isp_params_handlers, + ARRAY_SIZE(c3_isp_params_handlers)); } =20 static int c3_isp_params_vb2_buf_init(struct vb2_buffer *vb) --=20 2.51.0 From nobody Thu Oct 2 14:13:11 2025 Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 150612E88B5; Mon, 15 Sep 2025 17:18:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=213.167.242.64 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757956734; cv=none; b=aTjVpajDTgLRXGVOV5ege2ZMRQpxSNuVqgHCDDuO1pKlqmRVxeY4nmxoIwakyj6iqXZHLjI3W3vGlMlbLa+2hjTLJ8JyQZE9Qqv8rdvQiAUhyuAcA4/MJeZNQKWS0FRbbTuKQ199H5L95M6xt4HE1ygM7TenX178163JW7hPQS4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757956734; c=relaxed/simple; bh=j9hWvCqelAGNvfHC+N6jQ1AbbIgP+Hu8HDlRfTcW5dU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=WExjhakpxZUDMBY9E59HSxBq4g++gOp73AxHcGyVkYo60j1wKmbATERfLQviIY8o6siAgB46B6NoNduLeFGEqtp4IsvhzgIO6SpGTcFwJBifqXmUtygcyx+Hozja8Kc01QynfkuNLaiCgQeBxp19UlzWygscGOWsM/fgnPSx724= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=ideasonboard.com; spf=pass smtp.mailfrom=ideasonboard.com; dkim=pass (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.b=MbD9+nQi; arc=none smtp.client-ip=213.167.242.64 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=ideasonboard.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ideasonboard.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="MbD9+nQi" Received: from [192.168.0.172] (mob-5-90-56-182.net.vodafone.it [5.90.56.182]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id EAF191189; Mon, 15 Sep 2025 19:17:26 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1757956647; bh=j9hWvCqelAGNvfHC+N6jQ1AbbIgP+Hu8HDlRfTcW5dU=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=MbD9+nQiI/UnoiPXoe7w1d82vS1VSty3VjlYeCKIP2pU11BimGoWAYfTbPQidJCPy 3jLhokZ4ZJluH5OBHsQl09t9HBED4jkrO7pRZSNF+TZs5Ck1qwCq2ZpUkyz4p0hYri 86DgX/gic9waEptrV5FrNjngBq9W6Gmfxgz8cy4s= From: Jacopo Mondi Date: Mon, 15 Sep 2025 19:18:17 +0200 Subject: [PATCH v5 8/8] media: Documentation: kapi: Add v4l2 generic ISP support Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250915-extensible-parameters-validation-v5-8-e6db94468af3@ideasonboard.com> References: <20250915-extensible-parameters-validation-v5-0-e6db94468af3@ideasonboard.com> In-Reply-To: <20250915-extensible-parameters-validation-v5-0-e6db94468af3@ideasonboard.com> To: Dafna Hirschfeld , Laurent Pinchart , Keke Li , Mauro Carvalho Chehab , Heiko Stuebner , Dan Scally , Sakari Ailus , Antoine Bouyer Cc: linux-kernel@vger.kernel.org, linux-media@vger.kernel.org, linux-rockchip@lists.infradead.org, linux-arm-kernel@lists.infradead.org, Jacopo Mondi X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=3476; i=jacopo.mondi@ideasonboard.com; h=from:subject:message-id; bh=j9hWvCqelAGNvfHC+N6jQ1AbbIgP+Hu8HDlRfTcW5dU=; b=owEBbQKS/ZANAwAKAXI0Bo8WoVY8AcsmYgBoyEpqg+bIyroqcxI6unLoLO/6bMW1RVPjAUdT1 AClTMvpjHuJAjMEAAEKAB0WIQS1xD1IgJogio9YOMByNAaPFqFWPAUCaMhKagAKCRByNAaPFqFW PFEGD/9eZDpRaBL6tw+rDnhW4TmAaTMX788ap9B0/aPqgNRwhcNVtWLL08+dsEkW9pd5zEPEX8t E69I7kr3zHBN38fXyQFaNDatM2fHPh/G5tXVN1S1U1Xtp/3Aqg4NAR6I2VC/SlH5RJLjAz0htym dhC2VRjluLgVHIZe0Zwe3sj+5k5opgKzKTaUyEsCHEvhEyI0N4NssRtUbcXTXvvOQxTo1buOCVY WAntNNPSQPq6xX6etwjK5BYAI1L39EWAzzIQeYews1F+nN7oZ4umF9Ew5/Oi2dR7hSkYUHsyuEl ee4IiZRvd1lpUjli1EFqgn8yufg8uhPWvICWS5NrLyVYTEBRQ/aM1KqiGFTazHEAizANJd9XkBb b7jTZPgRdN7szXo3VJRqxUq8Ni5F4YCbFA95dBoc3ANsteuWrq0zeUzMTQLSz6LomNl3eGoRNGl t6dj5GyYMnLhBVNfNiGPPHfDcUf2wQjQZR9s2mTKCoNbih5jdeatxC6pYJP/2rMF72kiq+Ei5wt MIL9vZU2/Fd4G9ndWjtEIggnx3lOUZGO25UB3LG9KAt6bwImZpNrTCG9fTg9OZTzpVWr21+BfZf VwWabnY1f7yLtWFR1LTnJ+ngiHRrRl9c9fq+sc/VGiHCnvhjuRFiuQPZ9w/oSthh9ZqOwAbh6JQ 4PENvP4KH1yGaSA== X-Developer-Key: i=jacopo.mondi@ideasonboard.com; a=openpgp; fpr=72392EDC88144A65C701EA9BA5826A2587AD026B Add to the driver-api documentation the v4l2-isp.h types and helpers documentation. Reviewed-by: Daniel Scally Signed-off-by: Jacopo Mondi Acked-by: Sakari Ailus --- Documentation/driver-api/media/v4l2-core.rst | 1 + Documentation/driver-api/media/v4l2-isp.rst | 37 ++++++++++++++++++++++++= ++++ MAINTAINERS | 1 + 3 files changed, 39 insertions(+) diff --git a/Documentation/driver-api/media/v4l2-core.rst b/Documentation/d= river-api/media/v4l2-core.rst index ad987c34ad2a8460bb95e97adc4d850d624e0b81..a5f5102c64cca57b57b54ab9588= 2b26286fb27de 100644 --- a/Documentation/driver-api/media/v4l2-core.rst +++ b/Documentation/driver-api/media/v4l2-core.rst @@ -27,3 +27,4 @@ Video4Linux devices v4l2-common v4l2-tveeprom v4l2-jpeg + v4l2-isp diff --git a/Documentation/driver-api/media/v4l2-isp.rst b/Documentation/dr= iver-api/media/v4l2-isp.rst new file mode 100644 index 0000000000000000000000000000000000000000..d778aa799347bfd0a95bd6887dd= 944ddad0fe4d1 --- /dev/null +++ b/Documentation/driver-api/media/v4l2-isp.rst @@ -0,0 +1,37 @@ +.. SPDX-License-Identifier: GPL-2.0 + +V4L2 generic ISP parameters and statistics support +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +ISP configuration parameters and statistics are processed and collected by +drivers and exchanged with userspace through data types that usually +reflect the ISP peripheral registers layout. + +Each ISP driver defines its own metadata format for parameters and statist= ics, +and exposing the registers layout in the format definition, part of the Li= nux +kernel uAPI/uABI interface, makes it really hard, if not impossible, to ex= tend +the format in a backward compatible way to support new hardware blocks or +different revisions of the same peripheral IP. + +For these reasons Video4Linux2 defines generic types for ISP configuration +parameters and statistics with a set of associated helpers to support driv= ers +and users using generic types. + +Generic ISP configuration parameters +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +Drivers can use the generic and extensible configuration parameters format= by +re-using the types defined in the include/uapi/linux/media/v4l2-isp.h uAPI +header file. + +The uAPI header defines generic types which the driver is expected to re-u= se and +provide definitions for the types of supported ISP blocks, their control +flags and the expected maximum size of a buffer of parameters. + +When a driver receives a buffer of parameters from userspace it shall vali= date +it by using the helper functions and types available in include/media/v4l2= -isp.h +before accessing the buffer to apply the parameters to the hardware regist= ers. + +Generic ISP support driver documentation +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D +.. kernel-doc:: include/media/v4l2-isp.h diff --git a/MAINTAINERS b/MAINTAINERS index 5e0e4208ebe6c58a9ea0834e1ebb36abd2de06e1..b0c5e6c2b21a5d5ebc63d2ae8b5= c1b68fa912b33 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -26414,6 +26414,7 @@ V4L2 GENERIC ISP PARAMETERS AND STATISTIC FORMATS M: Jacopo Mondi L: linux-media@vger.kernel.org S: Maintained +F: Documentation/driver-api/media/v4l2-isp.rst F: Documentation/userspace-api/media/v4l/extensible-parameters.rst F: drivers/media/v4l2-core/v4l2-isp.c F: include/media/v4l2-isp.h --=20 2.51.0