From nobody Tue Oct 7 16:33:57 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 861EB2DA768; Tue, 8 Jul 2025 10:41:14 +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=1751971277; cv=none; b=qvJSxduxuMz6NZ0/2OX5hk5CHAuUWcZBkCfsdi71m5U/sMyuI9+sNRZnih0ovNmRYCD9qMKSmDSmnb0zHBTzJL+IrWJwo47JHfMN6tx1H7l7PmDNleo3wTvIzI6KZeKyQQEbi0Aa5yPg8rJy/c8N6ITXLEiSpfC0F6hAyWzMV+g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751971277; c=relaxed/simple; bh=4rqu3lKXSW/z1GKfzm8g/KZPUVyEVMcyGhy1+aiv3v8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Omaq5I95ZDVVZeZm7RVbSKgAw9gzbJ1fQ2QUzD3pv56qo6WnDH6YkkDFcdAszjZ1WfUUM9FDAZ2wLvlrUtQXEQZPV7GHvmQXeqyLRrmweSDv6hVTM2A4ODsMr0k0wDf+8NukqHE3rsrpxHT6+yoj8r+AvOZi4kE/cBNIEcCLMXI= 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=iyb/w8Ab; 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="iyb/w8Ab" Received: from [192.168.0.172] (mob-5-90-136-241.net.vodafone.it [5.90.136.241]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 1373214B0; Tue, 8 Jul 2025 12:40:39 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1751971239; bh=4rqu3lKXSW/z1GKfzm8g/KZPUVyEVMcyGhy1+aiv3v8=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=iyb/w8AbiPdi0nwUEBnptdpKMDXGQnJco8eB6wL28h0xijseBrUJSGvlUKqvQJZk6 cMqQpydqoilhky+ICKu4JUdhIpHaU1O+ZRDCigZkgUJ3V3fXDWCYxJLuACE9/jgjH7 FfRSlwMexQ/Bqp5PxVHKPAyGVWSyD/UKrfgZxJQo= From: Jacopo Mondi Date: Tue, 08 Jul 2025 12:40:48 +0200 Subject: [PATCH 1/8] media: uapi: Introduce 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: <20250708-extensible-parameters-validation-v1-1-9fc27c9c728c@ideasonboard.com> References: <20250708-extensible-parameters-validation-v1-0-9fc27c9c728c@ideasonboard.com> In-Reply-To: <20250708-extensible-parameters-validation-v1-0-9fc27c9c728c@ideasonboard.com> To: Dafna Hirschfeld , Laurent Pinchart , Keke Li , Mauro Carvalho Chehab , Heiko Stuebner , Dan Scally , Sakari Ailus 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=6273; i=jacopo.mondi@ideasonboard.com; h=from:subject:message-id; bh=4rqu3lKXSW/z1GKfzm8g/KZPUVyEVMcyGhy1+aiv3v8=; b=owEBbQKS/ZANAwAKAXI0Bo8WoVY8AcsmYgBobPXA0fKq+ElETn3DWuXQTzmQBxpkUSWsBLVjQ T+ynlSUnDKJAjMEAAEKAB0WIQS1xD1IgJogio9YOMByNAaPFqFWPAUCaGz1wAAKCRByNAaPFqFW PNHfD/9qd6BjrXX65+NS4vA4pUU0RV86NejPljM9gxLPbx0Wm5ctzZ77drMXGBlIPzfYFjt3Tk1 c+0jnPgmaPX3IkdGfmk3n8MwhBOcGIX0a4EVFZoOp0m8uqpymaRkrLldMHQcSLTXVHlsnJQCv9a VK7xqW5KAqYZ8MiXjLfQ6M/iRNSkG96AkGBc7i5EMeygGncpHLALpgvSJW259/Di+LAK2twPrNc eQR7siA5IytYCk/+wByxExDzPA1jt5H8L7ZNrRRzlAePAsfMGOmsji8pWSdWsRwQY2xPtQbkSHj OAx0YiY0Vy95z2WsVwukGaR/cRg1j5mcVPq+zV01gZCiLV4CKnX32fT6SLd46YGlVfwlCKyFarM 8Af7JgVC6egPiIUrjdihllT/mkcvpix5E3rA9vog41X4UWZhtwnWoG659L3DT02w0X2FMQb6s1/ IBGj1DG+E/XEcv7M0jqx6lyQLH2y8qwRd+Buq6dzSrg/NGGd1SY0/3bF/gqM8LpUgdKe1EsYGn2 PNoupq5DYgQGQ6GMn9hNjG9Ywj7FiTaQImie2S0wjSerNR+dAVlihwolqeaouwaIF4pjVPLHfo/ vujbHcL6losWFZ6neuJqPXcnnzC4uDoKxrD/v1L0CFLV9xBbwlSLn2CT93mzxqXi/O24cNjC79t djmB60FD4+rvhaw== X-Developer-Key: i=jacopo.mondi@ideasonboard.com; a=openpgp; fpr=72392EDC88144A65C701EA9BA5826A2587AD026B Introduce v4l2-extensible-params.h in the Linux kernel uAPI. The header defines two types that all drivers that use the extensible parameters format for ISP configuration shall use to build their own parameters format. The newly introduce type v4l2_params_block represent the header to be prepend to each ISP configuration block and the v4l2_params_buffer type represent the base type for the configuration parameters buffer. The newly introduced header is not meant to be used directly by applications which should instead use the platform-specific ones. Signed-off-by: Jacopo Mondi --- MAINTAINERS | 6 ++ include/uapi/linux/media/v4l2-extensible-params.h | 106 ++++++++++++++++++= ++++ 2 files changed, 112 insertions(+) diff --git a/MAINTAINERS b/MAINTAINERS index 658543062bba3b7e600699d7271ffc89250ba7e5..49a9329e5fe8874bdbaca13946e= a28bd80134cb3 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -25968,6 +25968,12 @@ F: drivers/media/i2c/vd55g1.c F: drivers/media/i2c/vd56g3.c F: drivers/media/i2c/vgxy61.c =20 +V4L2 EXTENSIBLE PARAMETERS FORMAT +M: Jacopo Mondi +L: linux-media@vger.kernel.org +S: Maintained +F: include/uapi/linux/media/v4l2-extensible-params.h + VF610 NAND DRIVER M: Stefan Agner L: linux-mtd@lists.infradead.org diff --git a/include/uapi/linux/media/v4l2-extensible-params.h b/include/ua= pi/linux/media/v4l2-extensible-params.h new file mode 100644 index 0000000000000000000000000000000000000000..ed37da433c6b1a34523b6a9befd= e5c0dee601cfb --- /dev/null +++ b/include/uapi/linux/media/v4l2-extensible-params.h @@ -0,0 +1,106 @@ +/* SPDX-License-Identifier: ((GPL-2.0+ WITH Linux-syscall-note) OR MIT) */ +/* + * Video4Linux2 extensible configuration parameters base types + * + * Copyright (C) 2025 Ideas On Board Oy + * Author: Jacopo Mondi + */ + +#ifndef _UAPI_V4L2_PARAMS_H_ +#define _UAPI_V4L2_PARAMS_H_ + +#ifndef _UAPI_V4L2_EXTENSIBLE_PARAMS_GUARD_ +/* + * Note: each ISP driver exposes a different uAPI, where the types layout + * match (more or less strictly) the hardware registers layout. + * + * This file defines the base types on which each ISP driver can implement= its + * own types that define its uAPI. + * + * This file is not meant to be included directly by applications which sh= all + * instead only include the ISP-specific implementation. + */ +#error "This file should not be included directly by applications" +#endif + +#include + +/** + * struct v4l2_params_block - V4L2 extensible parameters 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 each platform-specif= ic ISP + * block types which specifies how the data should be interpreted by the d= river. + * 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 platform-specific control flags. + * + * Userspace shall never use this type directly but use the platform speci= fic + * one with the associated data types. + * + * - Rockchip RkISP1: :c:type:`rkisp1_ext_params_block_type` + * - Amlogic C3: :c:type:`c3_isp_params_block_type` + * + * @type: The parameters block type (platform-specific) + * @flags: A bitmask of block flags (platform-specific) + * @size: Size (in bytes) of the parameters block, including this header + */ +struct v4l2_params_block { + __u16 type; + __u16 flags; + __u32 size; +} __attribute__((aligned(8))); + +/** + * 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` entry as first member. Userspace populates + * 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. + * + * Each ISP driver using the extensible parameters format shall define a + * type which is type-convertible to this one, with the difference that the + * @data member shall actually a memory buffer of platform-specific size a= nd + * not a pointer. + * + * Userspace shall never use this type directly but use the platform speci= fic + * one with the associated data types. + * + * - Rockchip RkISP1: :c:type:`rkisp1_ext_params_cfg` + * - Amlogic C3: :c:type:`c3_isp_params_cfg` + * + * @version: The parameters buffer version (platform-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[]; +}; + +#endif /* _UAPI_V4L2_PARAMS_H_ */ --=20 2.49.0 From nobody Tue Oct 7 16:33:57 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 E38932DAFCE; Tue, 8 Jul 2025 10:41:17 +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=1751971282; cv=none; b=KBUaoMLymPOLqCbKy+dITtHmyHdUWuxh8FjBpLFWMRU7HTeOE5dRREgQuIjmMs5gSJMsuNOv18VnytmuzhZjga2bIMfpffJ/GZm00bEmnw2at1cjpjiT5x2rijYwz3VdPWH7Fs+Gjarmg/KANnNiFt6qZb4Nu3YzyeKprdhjPAk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751971282; c=relaxed/simple; bh=XwAActjfS4nOKs1fzm6HK5dbJXzBj0DHHjKJDlSxOY0=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=uSvfpivAm3B3xoikiyvIL3jPu7ETQw7rBg8pykVF0Q23nvLwm/JrWSgdxqRw4ofKH92NzXqYOZwq+QzHJPgqch+gIe7hIkmF0SEID/NYeUmjIFJ7O7WWta2zuqDRY77ETRDnLFU6nhdyOtH2HxdhYU/bOdzWUCY6okL4mf7clb4= 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=SSNGuGeB; 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="SSNGuGeB" Received: from [192.168.0.172] (mob-5-90-136-241.net.vodafone.it [5.90.136.241]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 136BA1BAF; Tue, 8 Jul 2025 12:40:40 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1751971240; bh=XwAActjfS4nOKs1fzm6HK5dbJXzBj0DHHjKJDlSxOY0=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=SSNGuGeBEc8QrUmlMEAFY/5QS+GwdIqLi3O70eJ1fWhihs+skEEYDyjF7Oxr4HvLW 0tbhbj7WdZmPtuGUX8wMsLkKrZ7JVIayOFvYaBtNMSiwnTJQd0tnbkpKKrcBTCtnq2 hW8io2ES6+qrlgHkEundmllfPJ58mayPfN+/3sqs= From: Jacopo Mondi Date: Tue, 08 Jul 2025 12:40:49 +0200 Subject: [PATCH 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: <20250708-extensible-parameters-validation-v1-2-9fc27c9c728c@ideasonboard.com> References: <20250708-extensible-parameters-validation-v1-0-9fc27c9c728c@ideasonboard.com> In-Reply-To: <20250708-extensible-parameters-validation-v1-0-9fc27c9c728c@ideasonboard.com> To: Dafna Hirschfeld , Laurent Pinchart , Keke Li , Mauro Carvalho Chehab , Heiko Stuebner , Dan Scally , Sakari Ailus 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=6501; i=jacopo.mondi@ideasonboard.com; h=from:subject:message-id; bh=XwAActjfS4nOKs1fzm6HK5dbJXzBj0DHHjKJDlSxOY0=; b=owEBbQKS/ZANAwAKAXI0Bo8WoVY8AcsmYgBobPXA/XSVnScdHok55ezv/agTY1NJfgWShsoZK 0YmMzPByPWJAjMEAAEKAB0WIQS1xD1IgJogio9YOMByNAaPFqFWPAUCaGz1wAAKCRByNAaPFqFW PHdUEACAatG5wcPTQUMVpaHoum7Uzwq9fPyF+p83SKUDIquu+077MBZBsjYhZ2Znu/7tE2FYwbi os/fZpfv3hpCTkYzrXqP7qoFxufqG75vW0lRiwhLghhDWOLH0QClzpAVY7d3hfXx392n5Cfu2+C neFZHrOEoAv0plURe49HSEsMgaXZyzM8Tt+8Wka9EfHPdSmBylZh87EBIBoMaby9h9ATwSwBfjZ zo1xoi/GsLwIOWRmqZTiSMCdsucd5G+V4ReAeyWcDjrwE+dVkB6ABOoPpNgvRdlfDMRoH7NNt9D 46sLGBEx9vIK4y1wUk8S8IEJ0iRkR/KMp0L84wVs3B16BgPxJ1t+ZpCSWm1ny+2z0XggI8ktMcs y3iLi029VTVS15gzTm3usKKr7Mb1MVkV79yjCEc60EopvepSO/Krbs5hz1VOK0JbmdSD+qtpYlq wusHf2ewiCarn0InTvsPvrIbTZ04FRK7LACukkmoveR7eYNtEdZLg4NMBxX0I7yrjSD//25b9yv GnNCI0JbIN0XKdaS3uEzupQuMOqfrW1WIZVlFEEfoO7pIVlY0wrkAqME9IFCjv9RMIHhpuEWvYj fGqZWbtKriR4bgJadLxpoPduuVKpI30u3J0JmhWaZddr5NBskh2AfDRDnQfbNnfp+JbVTcQ3US9 CoAZQB2TOKMpEBQ== 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. Signed-off-by: Jacopo Mondi --- include/uapi/linux/rkisp1-config.h | 60 ++++++++++++----------------------= ---- 1 file changed, 18 insertions(+), 42 deletions(-) diff --git a/include/uapi/linux/rkisp1-config.h b/include/uapi/linux/rkisp1= -config.h index 3b060ea6eed71b87d79abc8401eae4e9c9f5323a..fe58ff1aed15b0497a9a9fa9a0b= fa1ede3889d3e 100644 --- a/include/uapi/linux/rkisp1-config.h +++ b/include/uapi/linux/rkisp1-config.h @@ -7,8 +7,12 @@ #ifndef _UAPI_RKISP1_CONFIG_H #define _UAPI_RKISP1_CONFIG_H =20 +#include #include =20 +#define _UAPI_V4L2_EXTENSIBLE_PARAMS_GUARD_ +#include + /* Defect Pixel Cluster Detection */ #define RKISP1_CIF_ISP_MODULE_DPCC (1U << 0) /* Black Level Subtraction */ @@ -1165,19 +1169,14 @@ enum rkisp1_ext_params_block_type { #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`. * - * 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 + * 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_*. @@ -1193,14 +1192,14 @@ enum rkisp1_ext_params_block_type { * 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. + * 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 + * RKISP1_EXT_PARAMS_FL_BLOCK_DISABLE bits in the flags field is not allow= ed * 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. + * fields (type, flags and size) and the block-specific parameters. * * For example: * @@ -1220,17 +1219,8 @@ enum rkisp1_ext_params_block_type { * 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 */ -struct rkisp1_ext_params_block_header { - __u16 type; - __u16 flags; - __u32 size; -}; +#define rkisp1_ext_params_block_header v4l2_params_block =20 /** * struct rkisp1_ext_params_bls_config - RkISP1 extensible params BLS conf= ig @@ -1594,21 +1584,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 +1600,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 +1649,9 @@ struct rkisp1_ext_params_cfg { __u8 data[RKISP1_EXT_PARAMS_MAX_SIZE]; }; =20 +/* 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 /* _UAPI_RKISP1_CONFIG_H */ --=20 2.49.0 From nobody Tue Oct 7 16:33:57 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 E390D2DAFCF; Tue, 8 Jul 2025 10:41:18 +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=1751971280; cv=none; b=fB4UPE+5OgCIJVGbLFRa9//K0MRP572BEkvNOkCSlG2Qa6qZMGAgYHqFNy63Z6w7cgMp9GDnDIxfyqoH6L9ZIovCouJ20m/vMP0ZIf/HedRteHckSgt7N87SC/GchMPOVuBDnyz+ntSGSd7NwrGEW6SkYZ0wXk76UbsGShU4zhc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751971280; c=relaxed/simple; bh=p4L6wr15gyO3Czyhf4gFVbw8Kqtw7/NE02pdJDjPsEY=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=AJBU3Vq8Na98wCo3pXJaAdYqEYK95HWsmtlAYMLb5A5r4Ea8aosx+k86YC4vhkImFP2vcKLdVzugx6T9bJYy/XDC3WLrdE+Xr4iuZxGXfdqdwFh7qV/bDDeuV3SENAjkGxIQx4D2vhSqBR8nCYOATu1U80ShFTE4havw78718yQ= 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=Xo1mrj9O; 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="Xo1mrj9O" Received: from [192.168.0.172] (mob-5-90-136-241.net.vodafone.it [5.90.136.241]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 163EC257A; Tue, 8 Jul 2025 12:40:41 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1751971241; bh=p4L6wr15gyO3Czyhf4gFVbw8Kqtw7/NE02pdJDjPsEY=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=Xo1mrj9OXR01XnmaVt91yJFD6LZ+8/nYO61WNfBqtsfLGtKATxplpxms+kbMsCzlI raQxEpXEEzKJYtwTxpSiykZh4xe6mTMCcB97fa6i6mK89zxwvQQaY5ZsOqVNuQFUC+ rqaCiYHrBV6HVa4QKnZuHU4OxUvouo2ifIvmrmuQ= From: Jacopo Mondi Date: Tue, 08 Jul 2025 12:40:50 +0200 Subject: [PATCH 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: <20250708-extensible-parameters-validation-v1-3-9fc27c9c728c@ideasonboard.com> References: <20250708-extensible-parameters-validation-v1-0-9fc27c9c728c@ideasonboard.com> In-Reply-To: <20250708-extensible-parameters-validation-v1-0-9fc27c9c728c@ideasonboard.com> To: Dafna Hirschfeld , Laurent Pinchart , Keke Li , Mauro Carvalho Chehab , Heiko Stuebner , Dan Scally , Sakari Ailus 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=4522; i=jacopo.mondi@ideasonboard.com; h=from:subject:message-id; bh=p4L6wr15gyO3Czyhf4gFVbw8Kqtw7/NE02pdJDjPsEY=; b=owEBbQKS/ZANAwAKAXI0Bo8WoVY8AcsmYgBobPXAjwOgVvHvlTbfdy9z3kjKRUkxCE5oYaghE RL4cNGa8GKJAjMEAAEKAB0WIQS1xD1IgJogio9YOMByNAaPFqFWPAUCaGz1wAAKCRByNAaPFqFW PHMBEAC9hp0LHxG121QpB5kk9BqA0eDQQvoyzrpCcA+cQsHh9D0J+xNUtBrUk1reGM5/OTqpJBb oEz/fduBCbvh8rrDNZXleUq5F+umB3e3CyACyb0Hr6vjMG60zaPlJ/A6Nua358RABr9seMM+yub BBdEWb+vlBLP48actbAnkPFaYQA1SVRAp+OcTk4InGJOQiJOZmW1zwmAYervAUVJT+YOVw72PjB 1keZs3Hevo09wvDF73EdmzROuHKAveVGP9UY/QUNxNF0/v0Hz7WGWYdGbZQBf5PNn+zfxwp1E2i Lcd13NgLG1EcO0qQuMrJ/Du3oyk6sKtT2Nwfh0h8QkJHC+xgJb1CaOb+km05VwyNwApETVKhHqF lFxsDKflK3Mcdq/1TbNmw+BK4jHdC8GB8RIGjW9v3DQC47NfDhR+on/ZXVfNLfljQTjhO/4IJDE nSJbftIX3MxZvwm6V7iFyBlFTwbF0Z1ScguHaTDoEuxU6NiNNaVzLExsUVgk7Ox+2nIte8AgOQ9 kJQcKZKECGxEwUAsrCaY/B5tN7F0ejI0vrBgTcg5/V2JTv26ZxLN+lbNLB8YWZmd5iz9EvBgd9A CyOAZjKDaqg3UwAqEz+NaYGjuSAgCdUyYo/WWLxFrJrLeF+uowC1UdDj4f+g/NDdAp2+0m5M7av XC2Fh/mgc1XxBdw== 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. Signed-off-by: Jacopo Mondi Reviewed-by: Keke Li --- include/uapi/linux/media/amlogic/c3-isp-config.h | 45 +++++++-------------= ---- 1 file changed, 12 insertions(+), 33 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..203116cdfb89356301c16c98cb4= 0e5b83efe71d6 100644 --- a/include/uapi/linux/media/amlogic/c3-isp-config.h +++ b/include/uapi/linux/media/amlogic/c3-isp-config.h @@ -6,8 +6,12 @@ #ifndef _UAPI_C3_ISP_CONFIG_H_ #define _UAPI_C3_ISP_CONFIG_H_ =20 +#include #include =20 +#define _UAPI_V4L2_EXTENSIBLE_PARAMS_GUARD_ +#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 @@ -183,11 +187,6 @@ enum c3_isp_params_block_type { * 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 @@ -223,15 +222,8 @@ enum c3_isp_params_block_type { * 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 */ -struct c3_isp_params_block_header { - __u16 type; - __u16 flags; - __u32 size; -}; +#define c3_isp_params_block_header v4l2_params_block =20 /** * struct c3_isp_params_awb_gains - Gains for auto-white balance @@ -498,26 +490,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 +536,8 @@ struct c3_isp_params_cfg { __u8 data[C3_ISP_PARAMS_MAX_SIZE]; }; =20 +/* 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 --=20 2.49.0 From nobody Tue Oct 7 16:33:57 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 1C5D72DBF5C; Tue, 8 Jul 2025 10:41:22 +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=1751971283; cv=none; b=sWjc8r2X3eeb1CzRTpSFuubC7VwJRap4ZyCglHOKpl1JgkEAQED5e5Z6XZEjjRg1NzT8DY29oyc7v1YF0XKuQezoa6xT6nASeqjo8erWJc0888P/0E4uGp5oQthobPEwMnMWUDdH+xGCxdlUKJBVpaZF7yGrOsTAkJMGpStLQYA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751971283; c=relaxed/simple; bh=R9qA7MNyVAfsHNo8l+6aisRM80FK3G5ZFSPJzZsHil4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=X6sZ3A56gHM2fBrNspX3lPYnJc+YfifNtN6E1Qii3nNRzXJ4nBTSMO+1jGb8R+Jn9/xNQRAl/u1EFdOvK10rEe+JMTBWq5I8SfvilGU6ftRuHWTYFBE6Ya7z+qt7QJkVUwyJ4KUUNlRJP9oD6OhwAdzxuoYeVz6HSzIixxohgK8= 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=ilKdzPcm; 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="ilKdzPcm" Received: from [192.168.0.172] (mob-5-90-136-241.net.vodafone.it [5.90.136.241]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 1D31A2A6E; Tue, 8 Jul 2025 12:40:42 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1751971242; bh=R9qA7MNyVAfsHNo8l+6aisRM80FK3G5ZFSPJzZsHil4=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=ilKdzPcmTmIYXwrIX6eiXQDtEKAv7UPq2wpU2iXfbPY22ioovVWN/pe8VUj/dIPNe LFol441MfnOrP9c6OhNGr20IEhztp1GHRa3u2L69QHzBBPi0+3IcIhxv/ODuKGTP40 zTDLZyyVGsFa8z6eO/Wm3UrKq5uwP+c6ICqSkJVg= From: Jacopo Mondi Date: Tue, 08 Jul 2025 12:40:51 +0200 Subject: [PATCH 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: <20250708-extensible-parameters-validation-v1-4-9fc27c9c728c@ideasonboard.com> References: <20250708-extensible-parameters-validation-v1-0-9fc27c9c728c@ideasonboard.com> In-Reply-To: <20250708-extensible-parameters-validation-v1-0-9fc27c9c728c@ideasonboard.com> To: Dafna Hirschfeld , Laurent Pinchart , Keke Li , Mauro Carvalho Chehab , Heiko Stuebner , Dan Scally , Sakari Ailus 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=5898; i=jacopo.mondi@ideasonboard.com; h=from:subject:message-id; bh=R9qA7MNyVAfsHNo8l+6aisRM80FK3G5ZFSPJzZsHil4=; b=owEBbQKS/ZANAwAKAXI0Bo8WoVY8AcsmYgBobPXAinzzJaS2OSx2ymAzRAGd0xgVImUWJeK3w fR20Mi7/x6JAjMEAAEKAB0WIQS1xD1IgJogio9YOMByNAaPFqFWPAUCaGz1wAAKCRByNAaPFqFW PNzXEAChWjmh+edQ/l61iAp0yuf0mK6venOuMoyyilHNi+DtiQANVJqeGwue4dYevFQq89Cf6t/ e7XEjkYAVncQFCIQJMpW0G2/a1FWfZy4PXI+UyXI27IGrbzOMJsuJH7L4IQcuDd8BL5t7Q/nBci BRiC67dVrSDKdGGVY9SHh0EX+6rFY5/wBi81KvUarku0TksfQSuiNUTwHQ1pf6Czzd6Fx8hLR20 QJDiavfMNbrxHUrEJEJMIS8Z6xLMxs0zKAbPXktxS8/SHvQxpX7Nq6BELJ4DPOe+NNyAytXz1Re a9AEgwdKGYjvoNKJbWP6mLCEVvpijtBoBpPqNBG75WrT4d/AJVyWkyvI1xsGmEOGnOW7w7rxkM0 6bKIbveGj63YRY9nGkTpC/niCQoG9ZjrGuSEeD0m+FKz0LXovjd5cIvu98jXKhCrvJ6XCmEN6XR OFI4N9fxTrnsFTlx75Pj4jcinFOi0LxVSyzJW3D6khl7ikgs3g6BY/4nimTYr3IxLUqLXSZtDf3 +jKUMF9CNQ05NMAWxTi74C1n6DT3KXSqQeLsOIogkPES0RTAGYOtk0Er10CaFp1uQw0k8GDjLbp AkhwqvgIRO2VpT6Veyw8K1aVs7x8yBp4z6j/IgwYCmXjvMLCCW+lLpE9U0mxMah6s9VbIr1y9Nl VS5GHXJinAorLvw== X-Developer-Key: i=jacopo.mondi@ideasonboard.com; a=openpgp; fpr=72392EDC88144A65C701EA9BA5826A2587AD026B Add documentation for extensible parameters format to the V4L2 userspace API documentation. Signed-off-by: Jacopo Mondi --- .../media/v4l/extensible-parameters.rst | 89 ++++++++++++++++++= ++++ .../userspace-api/media/v4l/meta-formats.rst | 1 + MAINTAINERS | 1 + 3 files changed, 91 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..254d4087ae0448d3e545d8533c3= 6d154967e202a --- /dev/null +++ b/Documentation/userspace-api/media/v4l/extensible-parameters.rst @@ -0,0 +1,89 @@ +.. SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later + +.. _extensible-parameters: + +********************************** + V4L2 extensible 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 defining a metadata output format that described the configuration para= meters +layout, 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 +supported in the very first driver version that lands in the kernel, and s= ome +parts of the interface have to later be modified for bug-fixes or improvem= ents. + +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 drivers have= to be +made ready to handle several different formats. + +A new set of metadata output formats has then to be defined, with the desi= gn +goals of being: + +- Extensible: new features can be added later on without breaking the exis= ting + interface +- Versioned: different versions of the interface 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 formats are realized by a defining a single C str= ucture +that contains a few control parameters and a binary buffer where userspace +programs a variable number of *ISP block configuration* data. + +The generic :c:type:`v4l2_params_buffer` defines a base type that each dri= ver +shall extend with a type-convertible implementation + +Each *ISP block configuration* is identified by an header and contains the +parameters for that specific block. + +The generic :c:type:`v4l2_params_block` defines a base type that each driv= er can +re-use as it is or extend appropriately. + +Userspace applications program in the control buffer only the parameters o= f the +ISP whose configuration has changed for the next frame. The ISP driver par= ses +the configuration parameters and apply them to the hardware register. + +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 block definitions 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. + +Implementations +--------------- + +ISP drivers that define an extensible parameters metadata output format: + +- :ref:`RkISP1 ` +- :ref:`Amlogic C3 ISP ` + +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-extensible-params.h diff --git a/Documentation/userspace-api/media/v4l/meta-formats.rst b/Docum= entation/userspace-api/media/v4l/meta-formats.rst index bb6876cfc271e1a0543eee4209d6251e1a6a73cc..58eb3c9c962bee008eee27d9c16= 678213c47baa9 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 49a9329e5fe8874bdbaca13946ea28bd80134cb3..beecac86991d988c48d31366ba5= 201b09ef25715 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -25972,6 +25972,7 @@ V4L2 EXTENSIBLE PARAMETERS FORMAT 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-extensible-params.h =20 VF610 NAND DRIVER --=20 2.49.0 From nobody Tue Oct 7 16:33:57 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 B21CB2DC332; Tue, 8 Jul 2025 10:41:23 +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=1751971285; cv=none; b=Q24Joez3+Kfdd4fNu/YH7rpkGDgUcoq/FPKBhnRd3YhizGCZH41tkvj9Nq+NsrJ69WzG8ncEl7XLZFurp2abDsTGGDw2PinXM2koizDrWz5cefpbFLdNlh5p6D/pdXE/dgZGlJs99RZJXyTP9h0grb5CrgxX6gSxCujxtCRE08U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751971285; c=relaxed/simple; bh=i1c/5TFb95c8rvclWJH24sE0B0SjG1zwpKdjFTFEqUI=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=lwwJK8kGREtudiJ96H4CEx10HJfYsDqwHBw0ggO+1A9bw9XrPc1mFqGp+wyNFr2YdQ6tPfNm/2Q0NcW4SEJp7FV/4bLbTvi3UwUT+XCVa/m+JKtGzOlwZ8XYEXSPo6RNHWjx6eg1t+XPHTRwpBefv2u/qxGrQiVCzDIkS6UhTX4= 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=NFUFThiJ; 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="NFUFThiJ" Received: from [192.168.0.172] (mob-5-90-136-241.net.vodafone.it [5.90.136.241]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 205A84302; Tue, 8 Jul 2025 12:40:43 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1751971243; bh=i1c/5TFb95c8rvclWJH24sE0B0SjG1zwpKdjFTFEqUI=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=NFUFThiJi7YDAPVqPSHD8wNn6uuVuiBkyDowpp2oB4H83Mz2kn1tmXS3LQ14z1ukM bdjajLOhbGnxAA1IUAZdrkmyaxJN3sQKf9lSS5a4Ws2ti6ML5ocspvWqZ/mPMo5Ut0 kxyIzJe9ma+NpGEvXFqYgRegOwzOh8KQA/vzhpTg= From: Jacopo Mondi Date: Tue, 08 Jul 2025 12:40:52 +0200 Subject: [PATCH 5/8] media: v4l2-common: Introduce v4l2-params.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: <20250708-extensible-parameters-validation-v1-5-9fc27c9c728c@ideasonboard.com> References: <20250708-extensible-parameters-validation-v1-0-9fc27c9c728c@ideasonboard.com> In-Reply-To: <20250708-extensible-parameters-validation-v1-0-9fc27c9c728c@ideasonboard.com> To: Dafna Hirschfeld , Laurent Pinchart , Keke Li , Mauro Carvalho Chehab , Heiko Stuebner , Dan Scally , Sakari Ailus 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=12833; i=jacopo.mondi@ideasonboard.com; h=from:subject:message-id; bh=i1c/5TFb95c8rvclWJH24sE0B0SjG1zwpKdjFTFEqUI=; b=owEBbQKS/ZANAwAKAXI0Bo8WoVY8AcsmYgBobPXAUPz1IvYqZGPzqP6Uf8idbysXcLhTKqGvL 6TngxV+rtGJAjMEAAEKAB0WIQS1xD1IgJogio9YOMByNAaPFqFWPAUCaGz1wAAKCRByNAaPFqFW PEo9D/9mnpVdVFbVtugo0Pu3bS0cK9r0+L3k2+FH2ixBP67Un+zZkDY0rlYEOPlPLmaTzrQcIsX nuyvMDnNpR74CzosDiuI4Do+OR9OKm2urBoVbVvkt/5t9aFPwbZyJoVI5DDqS2MiBtHTCkB5PEy PsNUiIX98FQ4LEJCGWoDWlW0+WoMGmzSZSV4asyuKHCYQU1ptkeImR0PYZ0NANNkmG4h9PpRFyH D2fZX30lUpWt9OW5s76gaRVE9Ke77t+aADxlbEGtCUeYiAYB3FFvYev5wL6wsNeyYKP3eS/YhV8 5tAFCJdV4FSHwdpj/TqHYVpBKxgWvIPDe5iuPG3USUBGdVStCgAdv0h8ztk053aA4SP32Nrzkag CcfgFBpvLH1G2EDnMI7r9WxpTcGM2Anz9/k9siZRjus5gLN1ApFxR8YROw9BwTsAJCZ+m5t14K3 YsZu0V5OM4hYCf6QJRtyTgv9g0xyvoj6fHLsMa3ptBFXAJpkLqUo8UdBxT9nVNdOjEzoxbSeVWQ syqzzCueheTa3dzi7DUUruWQQkIRwl90GNF+QUpHBGtOEhIM11sKxvYHA3E52Apkw61SBCbwPqu n5cdK7Grf1GqqhPINy8y2ZzQgjNP+VgzfV3aSvB4Zm4NBz82GosYHkgmFgRIRWr5P/3q7r3DYA8 Uk7h6unJEtb+4zg== X-Developer-Key: i=jacopo.mondi@ideasonboard.com; a=openpgp; fpr=72392EDC88144A65C701EA9BA5826A2587AD026B Add to the v4l2 framework an helper function to support drivers when validating a buffer of extensible parameters. Introduce new types in include/media/v4l2-params.h that driver shall use in order to comply with the v4l2-params validation procedure, and add a single helper function to v4l2-params.c. Signed-off-by: Jacopo Mondi --- MAINTAINERS | 2 + drivers/media/v4l2-core/Makefile | 3 +- drivers/media/v4l2-core/v4l2-params.c | 106 ++++++++++++++++++++++ include/media/v4l2-params.h | 166 ++++++++++++++++++++++++++++++= ++++ 4 files changed, 276 insertions(+), 1 deletion(-) diff --git a/MAINTAINERS b/MAINTAINERS index beecac86991d988c48d31366ba5201b09ef25715..3d9a8e06c59eb08360d1e8eea85= e450a15ee95af 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -25973,6 +25973,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-params.c +F: include/media/v4l2-params.h F: include/uapi/linux/media/v4l2-extensible-params.h =20 VF610 NAND DRIVER diff --git a/drivers/media/v4l2-core/Makefile b/drivers/media/v4l2-core/Mak= efile index 2177b9d63a8ffc1127c5a70118249a2ff63cd759..323330dd359f95c1ae3d0c35bd6= fcb8291a33a07 100644 --- a/drivers/media/v4l2-core/Makefile +++ b/drivers/media/v4l2-core/Makefile @@ -11,7 +11,8 @@ tuner-objs :=3D tuner-core.o videodev-objs :=3D v4l2-dev.o v4l2-ioctl.o v4l2-device.o v4l2-fh.o \ v4l2-event.o v4l2-subdev.o v4l2-common.o \ v4l2-ctrls-core.o v4l2-ctrls-api.o \ - v4l2-ctrls-request.o v4l2-ctrls-defs.o + v4l2-ctrls-request.o v4l2-ctrls-defs.o \ + v4l2-params.o =20 # Please keep it alphabetically sorted by Kconfig name # (e. g. LC_ALL=3DC sort Makefile) diff --git a/drivers/media/v4l2-core/v4l2-params.c b/drivers/media/v4l2-cor= e/v4l2-params.c new file mode 100644 index 0000000000000000000000000000000000000000..3fb320aec900ee4a05c595f2e14= c6ee0d8710669 --- /dev/null +++ b/drivers/media/v4l2-core/v4l2-params.c @@ -0,0 +1,106 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Video4Linux2 extensible parameters helpers + * + * Copyright (C) 2025 Ideas On Board Oy + * Author: Jacopo Mondi + */ + +#include + +int v4l2_params_buffer_validate(struct device *dev, struct vb2_buffer *vb, + size_t max_size, + v4l2_params_validate_buffer buffer_validate) +{ + 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; + int ret; + + /* 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; + } + + /* Driver-specific buffer validation. */ + if (buffer_validate) { + ret =3D buffer_validate(dev, buffer); + if (ret) + return ret; + } + + 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, + v4l2_params_validate_block block_validate) +{ + size_t block_offset =3D 0; + size_t buffer_size; + int ret; + + /* Walk the list of parameter blocks and validate them. */ + buffer_size =3D buffer->data_size; + while (buffer_size >=3D sizeof(struct v4l2_params_block)) { + const struct v4l2_params_handler *handler; + const struct v4l2_params_block *block; + + /* Validate block sizes and types against the handlers. */ + block =3D (const struct v4l2_params_block *) + (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; + } + + handler =3D &handlers[block->type]; + if (block->size !=3D handler->size) { + dev_dbg(dev, "Invalid parameters block size\n"); + return -EINVAL; + } + + /* Driver-specific per-block validation. */ + if (block_validate) { + ret =3D block_validate(dev, block); + if (ret) + return ret; + } + + 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-params.h b/include/media/v4l2-params.h new file mode 100644 index 0000000000000000000000000000000000000000..55f08c646a943fef11eaeddff84= 2fae00b8422d4 --- /dev/null +++ b/include/media/v4l2-params.h @@ -0,0 +1,166 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* + * Video4Linux2 extensible parameters helpers + * + * Copyright (C) 2025 Ideas On Board Oy + * Author: Jacopo Mondi + */ + +#ifndef V4L2_PARAMS_H_ +#define V4L2_PARAMS_H_ + +#define _UAPI_V4L2_EXTENSIBLE_PARAMS_GUARD_ +#include + +#include + +#include + +/** + * 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 *block); + +/** + * struct v4l2_params_handler - V4L2 extensible format handler + * @size: the block expected size + * @handler: the block handler function + * @group: the device-specific group id the block belongs to (optional) + * @features: the device-specific features flags (optional) + * + * 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), a pointer to each block @handler function and an + * optional @group and @feature flags, the driver can use to differentiate= which + * ISP blocks are present on the ISP implementation. + * + * The @group field is intended to be used as a bitmask of driver-specific + * flags to allow the driver to setup certain blocks at different times. A= s an + * example an ISP driver can divide its block handlers in "pre-configure" = blocks + * and "run-time" blocks and use the @group bitmask to identify the ISP bl= ocks + * that have to be pre-configured from the ones that only have to be handl= ed at + * run-time. The usage and definition of the @group field is totally + * driver-specific. + * + * The @features flag can instead be used to differentiate between blocks + * implemented in different revisions of the ISP design. In example some I= SP + * blocks might be present on more recent revision than others. Populating= the + * @features bitmask with the ISP/SoC machine identifier allows the driver= to + * correctly ignore the blocks not supported on the ISP revision it is run= ning + * on. As per the @group bitmask, the usage and definition of the @features + * field is totally driver-specific. + */ +struct v4l2_params_handler { + size_t size; + v4l2_params_block_handler handler; + unsigned int group; + unsigned int features; +}; + +/** + * typedef v4l2_params_validate_buffer - V4L2 extensible parameters buffer + * validation callback + * @dev: the driver's device pointer (as passed by the driver to + * v4l2_params_buffer_validate()) + * @buffer: the extensible parameters buffer + * + * Defines the function prototype for the driver's callback to perform + * driver-specific validation on the extensible parameters buffer + */ +typedef int (*v4l2_params_validate_buffer)(struct device *dev, + const struct v4l2_params_buffer *buffer); + +/** + * 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 check= ed + * against @max_size and its validated to be large enough to accommodate at + * least one ISP configuration block. The effective buffer size is compared + * to the data size reported by @cfg to make sure they match. + * + * If provided, the @buffer_validate callback function is invoked to allow + * drivers to perform driver-specific validation (such as checking that the + * buffer version is supported). + * + * 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. + *. + * Examples of users of this function can be found in + * rkisp1_params_prepare_ext_params() and in c3_isp_params_vb2_buf_prepare= (). + */ +int v4l2_params_buffer_validate(struct device *dev, struct vb2_buffer *vb, + size_t max_size, + v4l2_params_validate_buffer buffer_validate); + +/** + * typedef v4l2_params_validate_block - V4L2 extensible parameters block + * validation callback + * @dev: the driver's device pointer (as passed by the driver to + * v4l2_params_validate()) + * @block: the ISP configuration block to validate + * + * Defines the function prototype for the driver's callback to perform + * driver-specific validation on each ISP block. + */ +typedef int (*v4l2_params_validate_block)(struct device *dev, + const struct v4l2_params_block *block); + +/** + * 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 + * @block_validate: callback to the driver-specific per-block validation + * function + * + * 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. Additionally, if provided, the @block_validate + * callback is invoked on each block to allow drivers to perform driver-sp= ecific + * validation. + * + * Drivers should to use this function to validate the ISP configuration b= locks + * 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 @cfg 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. + * + * Examples of users of this function can be found in + * rkisp1_params_prepare_ext_params() and in c3_isp_params_vb2_buf_prepare= (). + */ +int v4l2_params_blocks_validate(struct device *dev, + const struct v4l2_params_buffer *buffer, + const struct v4l2_params_handler *handlers, + size_t num_handlers, + v4l2_params_validate_block block_validate); + +#endif /* V4L2_PARAMS_H_ */ --=20 2.49.0 From nobody Tue Oct 7 16:33:57 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 601402DCBF9; Tue, 8 Jul 2025 10:41:25 +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=1751971287; cv=none; b=GUKQaQPD58L4Sw9Ez7B4qPEdsDGah8v90E5eIDjsOrrUmq+a1y9lQgLs/ev3t8sd8ZSR0P4j2kFYoDDFJ8nTikNgUljzhkVC7LttpJEz75T0lHBV6NQqz5GLEbZVWyzTI6RrIKNa5AoZnPfQf/5itBoxToQbrLHQ1dgOBnHknIE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751971287; c=relaxed/simple; bh=AK0Tvfn/z7cds9LhgunFnXTPE3ON0GKM+qQa5xNHI2w=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=DMeP5Orh3y2z5ih7AyPZNZe6O5XPGEb+jzTirFTpXRToBvsS9em73tLV1Ye6CXbt5KHq4eUoGCNnuQ1/KrJ5sngiwaGN1D18y7jwuM0OGrVuOL9GinIQjM4gu+RgcASh7bZ2BKpvrpyAl6isZs+BgXQwY0MevHqbdb/rg5Z9ayM= 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=ACAEGlsb; 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="ACAEGlsb" Received: from [192.168.0.172] (mob-5-90-136-241.net.vodafone.it [5.90.136.241]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 889BB54E0; Tue, 8 Jul 2025 12:40:44 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1751971246; bh=AK0Tvfn/z7cds9LhgunFnXTPE3ON0GKM+qQa5xNHI2w=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=ACAEGlsbcR4UHmHaWotc0o1oVRyben1fxLP75zrxSTOCRAYAd4frpuejjXZJPQisA F3xNptJghjKfgIBGT2QggYHHYSHkrMJ3BLjOsF19fq0ufxEOGG8GVwYWRrm4ppFfJj vgKkIJv1ySQSuhGq1p+0eWWY/E+NiEj5xVxVymSw= From: Jacopo Mondi Date: Tue, 08 Jul 2025 12:40:53 +0200 Subject: [PATCH 6/8] media: rkisp1: Use v4l2-params 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: <20250708-extensible-parameters-validation-v1-6-9fc27c9c728c@ideasonboard.com> References: <20250708-extensible-parameters-validation-v1-0-9fc27c9c728c@ideasonboard.com> In-Reply-To: <20250708-extensible-parameters-validation-v1-0-9fc27c9c728c@ideasonboard.com> To: Dafna Hirschfeld , Laurent Pinchart , Keke Li , Mauro Carvalho Chehab , Heiko Stuebner , Dan Scally , Sakari Ailus 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=24030; i=jacopo.mondi@ideasonboard.com; h=from:subject:message-id; bh=AK0Tvfn/z7cds9LhgunFnXTPE3ON0GKM+qQa5xNHI2w=; b=owEBbQKS/ZANAwAKAXI0Bo8WoVY8AcsmYgBobPXA69ife2h1E0MMlwoBm1hpY8ZC+8y7xw40j PGAGIdfXSOJAjMEAAEKAB0WIQS1xD1IgJogio9YOMByNAaPFqFWPAUCaGz1wAAKCRByNAaPFqFW PBRND/wL9H8EDdpmRQkXtFNLoUuEvmIXzHFhg5xetRtQyJ3NWNJlN+jIbyrp2jEQZmiGPKFdKHy blHR0/GS/6ncv1re3Ar+stk/SHuotrTDaaA7sn3LNcdRwL2Bf2k4LWAlkapoveifPAg6KNNWdMx Y5Kdmu0uc+qm9fhEZ0Bbl4lxnbu2j1LSUkQxSvYQIFPEpLI95R95QTGzndIS62tVMn50lfQ3QV/ qzikfsBbX7lVr/Z4GWr7H5MaMmV3PimNZQQVMr5GVNsIhGvufIUdHnAxGTiHXzdRsWSLaZF7CsC Kb0XG00gsQSp2BwA62m25Wm4teK/rJVpaT3/8JpVFwLmhigQoz55/E9CwhbXN7jZYPZ9XA72aM+ 7A29RoNFJ+vOIJQLJfObJRjqE1AJYYKe6UpRsNhtnVG4WUS0YKxn0DJ4kaYNr5v3TF3KdCvp3Cb esnBK9nmF2wT+Bla9Hugk51732+33TrHrJJUOAfveoAKngLlv1L4hMS4SuuM5vg7aI1mX8+KzpC dQBXlsljUwDh8TAsKDWf1ZNhEV3g/iBBnHP18yY1gMYXso1wMsB5Cf3c38IzQGa46zih6rJjJGR Zegpa9uD8Gr/XC5hnh85uutfVYOwi2dYOrJryU9JVdooCdCo1CrgYEQKhgdr7xoneUT7HcRCq7/ KK1bGY7VCsRRvIg== 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-params.h and use the new helpers from v4l2-params.c to remove bolierplate code from the driver. Signed-off-by: Jacopo Mondi --- .../media/platform/rockchip/rkisp1/rkisp1-params.c | 364 +++++++++--------= ---- 1 file changed, 156 insertions(+), 208 deletions(-) diff --git a/drivers/media/platform/rockchip/rkisp1/rkisp1-params.c b/drive= rs/media/platform/rockchip/rkisp1/rkisp1-params.c index f1585f8fa0f478304f74317fd9dd09199c94ec82..36840048e97b4557894cf401210= d1c135de874cc 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 *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 *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 *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 *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 *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 *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 *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 *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 *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 *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 *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 *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 *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 *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 *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 *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 *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 *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 *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 *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 *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,15 +2094,7 @@ static void rkisp1_ext_params_wdr(struct rkisp1_para= ms *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; - unsigned int group; - unsigned int features; -} rkisp1_ext_params_handlers[] =3D { +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, @@ -2224,18 +2217,18 @@ 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 v4l2_params_handler *block_handler; + const struct v4l2_params_block *block; =20 - block =3D (const union rkisp1_ext_params_config *) + block =3D (const struct v4l2_params_block *) &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]; + block_handler =3D &rkisp1_ext_params_handlers[block->type]; if (!(block_handler->group & block_group_mask)) continue; =20 @@ -2245,10 +2238,10 @@ static void rkisp1_ext_params_config(struct rkisp1_= params *params, =20 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 @@ -2641,36 +2634,51 @@ static void rkisp1_params_vb2_buf_queue(struct vb2_= buffer *vb) spin_unlock_irq(¶ms->config_lock); } =20 +static int +rkisp1_ext_params_validate_buffer(struct device *dev, + const struct v4l2_params_buffer *buffer) +{ + /* Only v1 is supported at the moment. */ + if (buffer->version !=3D RKISP1_EXT_PARAM_BUFFER_V1) { + dev_dbg(dev, "Unsupported extensible format version: %u\n", + buffer->version); + return -EINVAL; + } + + return 0; +} + +static int +rkisp1_ext_params_validate_block(struct device *dev, + const struct v4l2_params_block *block) +{ + 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(dev, "Invalid parameters block flags\n"); + return -EINVAL; + } + + return 0; +} + static int rkisp1_params_prepare_ext_params(struct rkisp1_params *params, struct vb2_buffer *vb) { 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; - - /* - * 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) { - dev_dbg(params->rkisp1->dev, - "Too large buffer payload size %zu\n", payload_size); - return -EINVAL; - } + int ret; =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, + rkisp1_ext_params_validate_buffer); + if (ret) + return ret; =20 /* * Copy the parameters buffer to the internal scratch buffer to avoid @@ -2678,71 +2686,11 @@ 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), + rkisp1_ext_params_validate_block); } =20 static int rkisp1_params_vb2_buf_prepare(struct vb2_buffer *vb) @@ -2842,7 +2790,7 @@ static int rkisp1_params_ctrl_init(struct rkisp1_para= ms *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 v4l2_params_handler *block_handler; =20 block_handler =3D &rkisp1_ext_params_handlers[i]; ctrl_config.max |=3D BIT(i); --=20 2.49.0 From nobody Tue Oct 7 16:33:57 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 9DA792DCF74; Tue, 8 Jul 2025 10:41:27 +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=1751971290; cv=none; b=VtIAj0FMpmernwllx/hQRAg+/i7MJnm6BCUkLnSwh2gXCmDD2h/PQn7eqy51/IMDLDZ39iJx2VD08agcp6DfBCfQAPRXyIHxeAVIgxz/40mpZe6elHx2cb2i68waYEIYIatDUOhQAOxQcTFFZ9NRTnZCTqDmeuG082VRbrDgmMY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751971290; c=relaxed/simple; bh=N1RgivZg2OuBkITWbDCoQ3+nocE4wejuSYIZUHxvQ1c=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=nTmLJF3of6wHwr+KSjwBNnSJ+vz0QvePdk78BsQY6hrymzpJnVRoJuN5mxxN8xkpr71UzqS0Q4KBQlfe9GFEQT4gafPNP/JZWMfeHnweh3tdwpcHniwIBx6yYqvTr67daLkEokVSTqW1QJRvDD5N7CyNdOMvHo+5QwuhZsfQX6w= 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=U6PsdwUO; 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="U6PsdwUO" Received: from [192.168.0.172] (mob-5-90-136-241.net.vodafone.it [5.90.136.241]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 77105524E; Tue, 8 Jul 2025 12:40:46 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1751971247; bh=N1RgivZg2OuBkITWbDCoQ3+nocE4wejuSYIZUHxvQ1c=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=U6PsdwUO2N9eWrwe2aX/2JWGkhwSQ6nVZejdI42BfI/Cca6fR6U7L/CnuYOpDYu1A 0E1pY0BmlISBsy5vCMrdH7OJprlEZjNxm2nwqLjA6CS2WeW0E6cEEuyKtB0iOA8MrM lx0Aq8LvVuEIivdPNSdgQJQIae2Np6BpLUTn26Zc= From: Jacopo Mondi Date: Tue, 08 Jul 2025 12:40:54 +0200 Subject: [PATCH 7/8] media: amlogic-c3: Use v4l2-params 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: <20250708-extensible-parameters-validation-v1-7-9fc27c9c728c@ideasonboard.com> References: <20250708-extensible-parameters-validation-v1-0-9fc27c9c728c@ideasonboard.com> In-Reply-To: <20250708-extensible-parameters-validation-v1-0-9fc27c9c728c@ideasonboard.com> To: Dafna Hirschfeld , Laurent Pinchart , Keke Li , Mauro Carvalho Chehab , Heiko Stuebner , Dan Scally , Sakari Ailus 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=17633; i=jacopo.mondi@ideasonboard.com; h=from:subject:message-id; bh=N1RgivZg2OuBkITWbDCoQ3+nocE4wejuSYIZUHxvQ1c=; b=owEBbQKS/ZANAwAKAXI0Bo8WoVY8AcsmYgBobPXACHC8/wG8qYjXEa/Ww6QH/bnp7Zuu0vU6v 4wgW0JeH2CJAjMEAAEKAB0WIQS1xD1IgJogio9YOMByNAaPFqFWPAUCaGz1wAAKCRByNAaPFqFW PJW8EACJ/cmyIcoiGcT/DMeJ9bHXgq4Cnodx12oNlg9uwKFEBZnLS7vH99DxUeQiKWaDQV4A3tN xUR5i0MA8mSgYU4z9Q/E4Ruxdpf4kCV6fYWDMhXW9ylMjqHDn9ANHHb10EyOnsxqAJ/C0FbzKRC GKUzINU+5j5NIgbU0Dk+pKm+uRqNi3ntnrN9mSawFVZDxSJEj6ZCfgPentT7cxcAVVp+PQrLzas R8PWLlQuZ502tk698JubwUNxKOuwixKqxpcippwu5X/MQrShh1PDVlYf6A1sNuS8lswSFp72jQN zbNNuNfuMkUTSM2s+FMEywQdSLPRiuJEHmtmNNuuhZfe5yMkScgK0cqGT3OXOMhbYLnRwQfe3Sf 7eX/TlJIel8I8XPynpkJB+m5K07w7EXyeMeWL1lu933vYiMy9lcuiYHiv/liSpHaTGF1UF/1tuE f1dDClM9MdMcXasWbW7DUjFe8P/8be8AVcuycr3JFdfMaZP+bBAC8ynpjTzNWez72D5MdElUxwB LWu+Ga07GBKYTUUj65Wj72eCw8JiAMyeNdHCqlaKRLwFPGmrWX4Qg22czDkQ+pVqWFBjOBESBRp hjagVuDLCQOc3FsMmJXvTgy0yK71bqQdrUtHgkipOOfQ4uLtmOvIDd9+7eG3JANda2TZqqsdAuC WZnoAwl+uHEC2nA== 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-params.h and use the new helpers from v4l2-params.c to remove boilerplate code from the driver. Signed-off-by: Jacopo Mondi Reviewed-by: Keke Li --- .../media/platform/amlogic/c3/isp/c3-isp-params.c | 272 ++++++++---------= ---- 1 file changed, 103 insertions(+), 169 deletions(-) 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..9555a657fd93e89c846df029af9= de2745d2a5d7c 100644 --- a/drivers/media/platform/amlogic/c3/isp/c3-isp-params.c +++ b/drivers/media/platform/amlogic/c3/isp/c3-isp-params.c @@ -9,64 +9,25 @@ =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 *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 +50,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 +112,14 @@ 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 *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 +168,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 +231,14 @@ 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 *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 +268,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 +291,14 @@ 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 *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 +318,22 @@ 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 *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 +362,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 *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 +413,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 *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 +464,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 *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 +492,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 +543,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 *block; =20 - block =3D (const union c3_isp_params_block *) + block =3D (const struct v4l2_params_block *) &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 @@ -766,31 +741,49 @@ static void c3_isp_params_vb2_buf_queue(struct vb2_bu= ffer *vb) list_add_tail(&buf->list, ¶ms->pending); } =20 +static int +c3_isp_params_validate_buffer(struct device *dev, + const struct v4l2_params_buffer *buffer) +{ + /* Only v0 is supported at the moment */ + if (buffer->version !=3D C3_ISP_PARAMS_BUFFER_V0) { + dev_dbg(dev, "Invalid params buffer version: %u\n", + buffer->version); + return -EINVAL; + } + + return 0; +} + +static int +c3_isp_params_validate_block(struct device *dev, + const struct v4l2_params_block *block) +{ + 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(dev, "Invalid parameters block flags\n"); + return -EINVAL; + } + + return 0; +} + static int c3_isp_params_vb2_buf_prepare(struct vb2_buffer *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; - - /* 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); - return -EINVAL; - } + struct c3_isp_params_cfg *cfg =3D buf->cfg; + int ret; =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, + c3_isp_params_validate_buffer); + if (ret) + return ret; =20 /* * Use the internal scratch buffer to avoid userspace modifying @@ -798,70 +791,11 @@ 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), + c3_isp_params_validate_block); } =20 static int c3_isp_params_vb2_buf_init(struct vb2_buffer *vb) --=20 2.49.0 From nobody Tue Oct 7 16:33:57 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 978A62DCF7B; Tue, 8 Jul 2025 10:41:29 +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=1751971291; cv=none; b=Ngkx6Rm5qVJiU92j2j9N3aBNIxM0kgaEgjZicLl0OLv3oocBFSLYqZm+DoZKMCF0skIrLXF2hwDb7MPtESPKmVkiPp6d++1VLcDXKrvvje9XkKqI6iMpV3r/AZP2Wll8rzpq3Gyxbd5EmZmQgkB2inJ9393Tm/tXsN+3a0waDmo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751971291; c=relaxed/simple; bh=BFyCUyrT0Ujus6OGYnAmCl/GqNuIEDJQSk8MQCzrzmo=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=qXXQUozpsxp3QOGqzGtByh8rUytcmN4yVjsJCYmtBvU4EBNp/BkeoIAx8dhegcix/7pnEXXAbLj/FzuX69E6uwxC3aJI/Nc/2X4IIc+SkLFTfkQOTUeCHq0DNocytc8VWmM25eiN5KXRPTjdloIKRTJU/Ku/1WNxE8N4CLvW9fA= 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=d3XtUyRT; 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="d3XtUyRT" Received: from [192.168.0.172] (mob-5-90-136-241.net.vodafone.it [5.90.136.241]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id AA1625514; Tue, 8 Jul 2025 12:40:47 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1751971248; bh=BFyCUyrT0Ujus6OGYnAmCl/GqNuIEDJQSk8MQCzrzmo=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=d3XtUyRTSlBKWAyEZ9OacY8yb4d0nb/GR0r/dn4FJISgW805syFgLnohyEdJHgtXX jlUsiqut9xE15NX35R+Zf5Vz8SGJaVRCpgk/MhfDwt5i1HpdyoO7dQR9DUVffljJhc wHQ9Z6HI6oJzu3rZ9q3Ltlna7D8kJTFSoxtsHTEg= From: Jacopo Mondi Date: Tue, 08 Jul 2025 12:40:55 +0200 Subject: [PATCH 8/8] media: Documentation: kapi: 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: <20250708-extensible-parameters-validation-v1-8-9fc27c9c728c@ideasonboard.com> References: <20250708-extensible-parameters-validation-v1-0-9fc27c9c728c@ideasonboard.com> In-Reply-To: <20250708-extensible-parameters-validation-v1-0-9fc27c9c728c@ideasonboard.com> To: Dafna Hirschfeld , Laurent Pinchart , Keke Li , Mauro Carvalho Chehab , Heiko Stuebner , Dan Scally , Sakari Ailus 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=1789; i=jacopo.mondi@ideasonboard.com; h=from:subject:message-id; bh=BFyCUyrT0Ujus6OGYnAmCl/GqNuIEDJQSk8MQCzrzmo=; b=owEBbQKS/ZANAwAKAXI0Bo8WoVY8AcsmYgBobPXAuvdLqG+nFbVdQsYLUYtlT4MhvtXvbD/G1 q23FH7dlnyJAjMEAAEKAB0WIQS1xD1IgJogio9YOMByNAaPFqFWPAUCaGz1wAAKCRByNAaPFqFW PNa1EACWDCbdXUMrjjZ3dwSewW2dqOeAYL+/NTASuFxXjqj3O/wzLkc137vzxllzAQOK5ULUVMM DO9MIafzKqFzZz/9JKFFw9ASfu+XFeJItR8JvwCED6TZKBBlIlqrespYcbB8b3I7GNuZnkkTot2 aRqwBe/bOaWMTT4xSxeBNkFfJy+e8aeymuK44B3fEDmSdNz1BGsXo3Dtu9AGSCBJLestNjs8+P4 apT06q3Yd3enoWtZxPnAWhR3KB2dWrA9qnaMswAK5mImZCB1fYZWMRqiOGkR3gkOsWf76r5c3Po EIGWv/fx9jYDkA5ke5K6Tr+SwDwbAm2pbA3YAAdYyJaXD7Z51p3Lm5SndFnuipA3b9pmNDnP7oO yOkz+yrbKIdXAMtDvpf4SgvJBcBSB/3V8NEzYwe/fC4hlaRd8GCov0rHoLd3FFlEv0vrni8aGVV On/NLU5egtXOJzaXdvK7zNCUb4FcZg4sLFKyUHAtyPTj4XmD2hR2GSlySmQ2nV/2fOxiwnIKSfE IzkD+GvQ9bWqgxZFU8laNBYixXaUl+7HrjGNj4CW8j4EaeRfn8/iY/6Z+cAL5mdAWC9IMXOSWbQ IKsfxABSHl62egk0pZ7BjsFmO5XLnbi0qyAijE3ZLRGobRb4GdEXZfJMwX3zii34SRNO0HZrVkd MMS0qSER9ycIf8Q== X-Developer-Key: i=jacopo.mondi@ideasonboard.com; a=openpgp; fpr=72392EDC88144A65C701EA9BA5826A2587AD026B Add to the driver-api documentation the v4l2-params.h types and helpers documentation. Signed-off-by: Jacopo Mondi Reviewed-by: Daniel Scally --- Documentation/driver-api/media/v4l2-core.rst | 1 + Documentation/driver-api/media/v4l2-params.rst | 5 +++++ MAINTAINERS | 1 + 3 files changed, 7 insertions(+) diff --git a/Documentation/driver-api/media/v4l2-core.rst b/Documentation/d= river-api/media/v4l2-core.rst index ad987c34ad2a8460bb95e97adc4d850d624e0b81..2d7793298c6a2046bdd59b185a4= 11e092b659d52 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-params diff --git a/Documentation/driver-api/media/v4l2-params.rst b/Documentation= /driver-api/media/v4l2-params.rst new file mode 100644 index 0000000000000000000000000000000000000000..8d2a5f004d21dfc3a81255cabbc= 6b7cce588db71 --- /dev/null +++ b/Documentation/driver-api/media/v4l2-params.rst @@ -0,0 +1,5 @@ +.. SPDX-License-Identifier: GPL-2.0 + +V4L2 extensible parameters kAPI +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +.. kernel-doc:: include/media/v4l2-params.h diff --git a/MAINTAINERS b/MAINTAINERS index 3d9a8e06c59eb08360d1e8eea85e450a15ee95af..f03c10092a891a06052484b6914= 09f0c459de87d 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -25972,6 +25972,7 @@ V4L2 EXTENSIBLE PARAMETERS FORMAT M: Jacopo Mondi L: linux-media@vger.kernel.org S: Maintained +F: Documentation/driver-api/media/v4l2-params.rst F: Documentation/userspace-api/media/v4l/extensible-parameters.rst F: drivers/media/v4l2-core/v4l2-params.c F: include/media/v4l2-params.h --=20 2.49.0