From nobody Fri Dec 19 17:14:24 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 798BC246BDE; Tue, 14 Oct 2025 08:01: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=1760428879; cv=none; b=SVE0qZXDTL/nutHsm2+Uxmew+k4dRtb6vq2RVDi4W+8fx9P8QPbJTuGEF1r4ieEIGWZVeLp4vvCVICYPgyIpgLWpgtssAalq+SB/Z4FAfhs88DoVy8gh4M+/R3gsQTNS/RCoJydHvKUVLDQ13Fq5A/x9yu+XBTlWekD0NH9Qq40= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760428879; c=relaxed/simple; bh=c5BbO5ZzrMgBc8XtdoZnE46jsbPx01eU8VmxIRnkHYU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=nfiCBEUBAyav8TozB/gfaCfzPYQKnjMZL/gFwCimjvFlWRip+Nz8KRp+siYCdKTg1/817ksVeL7pwWHAJMLzmCWVTwQ5x9VnKszNn7uwRVI/HPjHeeRSEjxZWM0tr5UWQ4rC8NGYUaH2Cbi3NK914OoH1gL0ieRswqROC0vI6wQ= 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=YLKlSu40; 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="YLKlSu40" Received: from [192.168.1.182] (93-46-82-201.ip106.fastwebnet.it [93.46.82.201]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 1F35BC73; Tue, 14 Oct 2025 09:59:34 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1760428774; bh=c5BbO5ZzrMgBc8XtdoZnE46jsbPx01eU8VmxIRnkHYU=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=YLKlSu40+n8wRCn00t33S2L9iG15b58dXqki4bhbDQ6nPfKB0ORfAD+coAbXqe8TC iA0wSmdKEMtHexDPCc3gR2Ojlr7Z6hTDv6RTfvQtNhcGqEItlSCMFl7a2GH2o0CJZb ojNNDKsSlASZcv7S4OEmNgMz42iUmGpfgZXBtTEM= From: Jacopo Mondi Date: Tue, 14 Oct 2025 10:00:53 +0200 Subject: [PATCH v7 1/8] media: uapi: Introduce V4L2 generic ISP types Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20251014-extensible-parameters-validation-v7-1-6628bed5ca98@ideasonboard.com> References: <20251014-extensible-parameters-validation-v7-0-6628bed5ca98@ideasonboard.com> In-Reply-To: <20251014-extensible-parameters-validation-v7-0-6628bed5ca98@ideasonboard.com> To: Dafna Hirschfeld , Laurent Pinchart , Keke Li , Mauro Carvalho Chehab , Heiko Stuebner , Dan Scally , Sakari Ailus , Antoine Bouyer Cc: linux-kernel@vger.kernel.org, linux-media@vger.kernel.org, linux-rockchip@lists.infradead.org, linux-arm-kernel@lists.infradead.org, Jacopo Mondi , Laurent Pinchart X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=6283; i=jacopo.mondi@ideasonboard.com; h=from:subject:message-id; bh=c5BbO5ZzrMgBc8XtdoZnE46jsbPx01eU8VmxIRnkHYU=; b=owEBbQKS/ZANAwAKAXI0Bo8WoVY8AcsmYgBo7gNGATS5FnpmXJkh8fVntvjyb1MJXtKm2dCkL uKblBwX37mJAjMEAAEKAB0WIQS1xD1IgJogio9YOMByNAaPFqFWPAUCaO4DRgAKCRByNAaPFqFW PE0AD/9rtgG0MpiYxkJ7o8K3tu6ztJhAMlr1GUsJT8SuNKq3nX0Ox+ptlwbSeusep6rv44UG95a yVqwUHzHWWvYpZ8wpX2EQXPJmI57Z+ziOMsSePXyv+uSoI9pHIbuy6lMMhS4wTiPhQXL0hli1Iw RF3eJZUaREKDiykp2VOmeb0ghX/3S+aHclWly6txNBcGc94yP7WMezGbTwErILuyIroBd6p3KvV +pbIKuvrbUu+Wb/CDmTiejhepNbDaoGBsKGUGq9ycpjbUUlWAedJOljMQhn8CPQc+aDjWQ+6XAE jpu7rII12NXWCnQDSa0J94BepiN7zpjyU/S0YNHh+Yu4Xcush4+UR5tGVrcKmcC5JGKy44q21Vn hpepiUOhfRc4/wvxcHD3MrJvEzfohhmCz4a2Y/jWv0pz7rxnJGUiLjbbxIhJmuqRWoLl4nH3cwU 93L+45RqNw0PF1BpVDlfJtVWLyTeFo3A85J27gSMLA4Al5/ESWv8ZcBbSTmhcf/tHjVV+Xm4nv4 PefP851j7YfrXXCAwK4SM9AjqITumn8WylCHjx7gzvQ56FG2OrRhtGkP+8Yo3nXDcf5G5H9Kdd0 PBEJWBa3bBOkzv3Mbafsl/+rB6wl4D3BPm/KPEc/OygFzPRWumB2YcCsd2bF3YwTDLbyQp6Qe/E 86o/18hxiwt6IAA== X-Developer-Key: i=jacopo.mondi@ideasonboard.com; a=openpgp; fpr=72392EDC88144A65C701EA9BA5826A2587AD026B Introduce v4l2-isp.h in the Linux kernel uAPI. The header includes types for generic ISP configuration parameters and will be extended in the future with support for generic ISP statistics formats. Generic ISP parameters support is provided by introducing two new types that represent an extensible and versioned buffer of ISP configuration parameters. The v4l2_params_buffer represents the container for the ISP configuration data block. The generic type is defined with a 0-sized data member that the ISP driver implementations shall properly size according to their capabilities. The v4l2_params_block_header structure represents the header to be prepend to each ISP configuration block. Signed-off-by: Daniel Scally Reviewed-by: Daniel Scally Signed-off-by: Jacopo Mondi Reviewed-by: Laurent Pinchart Reviewed-by: Michael Riesch --- MAINTAINERS | 6 +++ include/uapi/linux/media/v4l2-isp.h | 102 ++++++++++++++++++++++++++++++++= ++++ 2 files changed, 108 insertions(+) diff --git a/MAINTAINERS b/MAINTAINERS index 46126ce2f968e4f9260263f1574ee29f5ff0de1c..e9ac834d212f88222437e8d8068= 00b2516d44f01 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -26853,6 +26853,12 @@ F: drivers/media/i2c/vd55g1.c F: drivers/media/i2c/vd56g3.c F: drivers/media/i2c/vgxy61.c =20 +V4L2 GENERIC ISP PARAMETERS AND STATISTIC FORMATS +M: Jacopo Mondi +L: linux-media@vger.kernel.org +S: Maintained +F: include/uapi/linux/media/v4l2-isp.h + VF610 NAND DRIVER M: Stefan Agner L: linux-mtd@lists.infradead.org diff --git a/include/uapi/linux/media/v4l2-isp.h b/include/uapi/linux/media= /v4l2-isp.h new file mode 100644 index 0000000000000000000000000000000000000000..779168f9058e3bcf6451f681e24= 7d34d95676cc0 --- /dev/null +++ b/include/uapi/linux/media/v4l2-isp.h @@ -0,0 +1,102 @@ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ +/* + * Video4Linux2 generic ISP parameters and statistics support + * + * Copyright (C) 2025 Ideas On Board Oy + * Author: Jacopo Mondi + */ + +#ifndef _UAPI_V4L2_ISP_H_ +#define _UAPI_V4L2_ISP_H_ + +#include +#include + +/** + * enum v4l2_isp_params_version - V4L2 ISP parameters versioning + * + * @V4L2_ISP_PARAMS_VERSION_V0: First version of the V4L2 ISP parameters f= ormat + * (for compatibility) + * @V4L2_ISP_PARAMS_VERSION_V1: First version of the V4L2 ISP parameters f= ormat + * + * V0 and V1 are identical in order to support drivers compatible with the= V4L2 + * ISP parameters format already upstreamed which use either 0 or 1 as the= ir + * versioning identifier. Both V0 and V1 refers to the first version of the + * V4L2 ISP parameters format. + * + * Future revisions of the V4L2 ISP parameters format should start from the + * value of 2. + */ +enum v4l2_isp_params_version { + V4L2_ISP_PARAMS_VERSION_V0 =3D 0, + V4L2_ISP_PARAMS_VERSION_V1 +}; + +#define V4L2_ISP_PARAMS_FL_BLOCK_DISABLE (1U << 0) +#define V4L2_ISP_PARAMS_FL_BLOCK_ENABLE (1U << 1) + +/* + * Reserve the first 8 bits for V4L2_ISP_PARAMS_FL_* flag. + * + * Driver-specific flags should be defined as: + * #define DRIVER_SPECIFIC_FLAG0 ((1U << V4L2_ISP_PARAMS_FL_DRIVER_FLA= GS(0)) + * #define DRIVER_SPECIFIC_FLAG1 ((1U << V4L2_ISP_PARAMS_FL_DRIVER_FLA= GS(1)) + */ +#define V4L2_ISP_PARAMS_FL_DRIVER_FLAGS(n) ((n) + 8) + +/** + * struct v4l2_isp_params_block_header - V4L2 extensible parameters block = header + * @type: The parameters block type (driver-specific) + * @flags: A bitmask of block flags (driver-specific) + * @size: Size (in bytes) of the parameters block, including this header + * + * 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 @type field is an ISP driver-specific value that identifies the blo= ck + * type. The @size field specifies the size of the parameters block. + * + * The @flags field is a bitmask of per-block flags V4L2_PARAMS_ISP_FL_* a= nd + * driver-specific flags specified by the driver header. + */ +struct v4l2_isp_params_block_header { + __u16 type; + __u16 flags; + __u32 size; +} __attribute__((aligned(8))); + +/** + * struct v4l2_isp_params_buffer - V4L2 extensible parameters configuration + * @version: The parameters buffer version (driver-specific) + * @data_size: The configuration data effective size, excluding this header + * @data: The configuration data + * + * This structure contains the configuration parameters of the ISP algorit= hms, + * serialized by userspace into a data buffer. Each configuration parameter + * block is represented by a block-specific structure which contains a + * :c:type:`v4l2_isp_params_block_header` entry as first member. Userspace + * 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. + * + * 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. Userspace shall populate the @data_size field with the effe= ctive + * size, in bytes, of the @data buffer. + */ +struct v4l2_isp_params_buffer { + __u32 version; + __u32 data_size; + __u8 data[] __counted_by(data_size); +}; + +#endif /* _UAPI_V4L2_ISP_H_ */ --=20 2.51.0 From nobody Fri Dec 19 17:14:24 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 5A4491D5AC6; Tue, 14 Oct 2025 08:01:21 +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=1760428883; cv=none; b=V96oJpuc5lU3cOqiEqlhwhuaaIagREAkybXKu13EYrmXxNlIWRqnsqGfH+gXDFI5dsmHVPC532AyJi8Om137Z8itonUqJY+PQcFQiLAHGUbxzhiysEMYDFQ6NxQo4efpPfUIjQXEIgKoneSsZo8ZVIfVqs4ffeROFozNBh8YKnE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760428883; c=relaxed/simple; bh=7ktxgAwKbkDVxOZvf+O7nZBZCn134GgJkCvMxSvF7XU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=ZdWs5G1vdEAdzQkQ8BHNmSyXyUDJn8DHaqgW+nwSirQL/jAuOlODJ1E/almQGteFWIc9BvPPPwtlkg0DXSdqt6XhB9VYmd5v2RaDbLTNUAuInYXXDVVtMI+ei8NOxWXWSo+eLTqc23arpmY/zUMHcGO6ZLy48ngy5mTCm7syL/Q= 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=A/12oMO0; 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="A/12oMO0" Received: from [192.168.1.182] (93-46-82-201.ip106.fastwebnet.it [93.46.82.201]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id ABB60DF3; Tue, 14 Oct 2025 09:59:34 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1760428775; bh=7ktxgAwKbkDVxOZvf+O7nZBZCn134GgJkCvMxSvF7XU=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=A/12oMO03XN1PbJQcbmOmva1Ciy/G5ZGQg/obYMIVER1wB4uT0UunJCoJFWjtoHxK cUzZ5kb0ZI7itfRpIvuxPBsos1k1XlHGTCZZN0qbALIZ2NAU//2z4zeuoBXLlqR0Kj v1mNaJbeOB+enwBAjdOTtpiVE61tLMVjuiXm7Rko= From: Jacopo Mondi Date: Tue, 14 Oct 2025 10:00:54 +0200 Subject: [PATCH v7 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: <20251014-extensible-parameters-validation-v7-2-6628bed5ca98@ideasonboard.com> References: <20251014-extensible-parameters-validation-v7-0-6628bed5ca98@ideasonboard.com> In-Reply-To: <20251014-extensible-parameters-validation-v7-0-6628bed5ca98@ideasonboard.com> To: Dafna Hirschfeld , Laurent Pinchart , Keke Li , Mauro Carvalho Chehab , Heiko Stuebner , Dan Scally , Sakari Ailus , Antoine Bouyer Cc: linux-kernel@vger.kernel.org, linux-media@vger.kernel.org, linux-rockchip@lists.infradead.org, linux-arm-kernel@lists.infradead.org, Jacopo Mondi , Laurent Pinchart X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=8022; i=jacopo.mondi@ideasonboard.com; h=from:subject:message-id; bh=7ktxgAwKbkDVxOZvf+O7nZBZCn134GgJkCvMxSvF7XU=; b=owEBbQKS/ZANAwAKAXI0Bo8WoVY8AcsmYgBo7gNGOhiD7mqa+MQRLm6Fy0fjuwAqXRoMl8Vdi +U7sbG7xHGJAjMEAAEKAB0WIQS1xD1IgJogio9YOMByNAaPFqFWPAUCaO4DRgAKCRByNAaPFqFW PPaMD/0SPNK6wtpw7BqxFLw6KDkcP6V6q2CqcIiIlspjXeXjAH9h18NGQZGw8zfd9Pjw2kxNkWD 00NHnk7b+0BCm/6QKKd7UDFTXK7STVr9mCvHxxCWnV/ogYayoQFu0T3CCDxvlfecTdrKVvY5Rf2 EHYzZ72DUSA04sx44dEZP+b/NYti6Mb8E5+dZHnKYoOdMIg1CtLAxsksXrOZk2uwpHo2FV04Hvi g6wHIUo39MceVfaiprI/4cmxE5AlFztOOZo8TOIvbYS0fI4zNKHxJTqJSEvuzRC/LsESxXx+ybc RGAKp4264YTBOgCeD+n+y3NLIdzd+Qa4OqIaVHEvwOWxlY86ZAnX1LSWut4kymHSE0f1k4Sd6dH sNN83AMIh+KVwNLd/VI5hZ1WrA+kHl8k6oe0pIj4tDBqKGSFVhgQCSrh/L2cT+6jOxZLo/2bPuy Pqh6Y/2bfqfFazY5OsAhtEuGlDKdPIX9BnGQscPQxMdzj+TAnVF62iIMASbfVHZTB4Hvd3R5xlx 7JwQmh7b3G2m7bJ2UatYRhsnl2ybD7bOujHt3j8sWDR91AMyaF2esflbA5q3170+bR1fIBr4nCf 2WEtjMrmJ+mX9GxRKmwJx9rGmAkqpbR35ZFMUHsPr4dMXVlsjIF9yAnbcBzbC9b8FjXx9XIZGMl qrz7t/4MC08gpyw== X-Developer-Key: i=jacopo.mondi@ideasonboard.com; a=openpgp; fpr=72392EDC88144A65C701EA9BA5826A2587AD026B With the introduction of common types for extensible parameters format, convert the rkisp1-config.h header to use the new types. Factor-out the documentation that is now part of the common header and only keep the driver-specific on in place. The conversion to use common types doesn't impact userspace as the new types are either identical to the ones already existing in the RkISP1 uAPI or are 1-to-1 type convertible. Reviewed-by: Daniel Scally Signed-off-by: Jacopo Mondi Reviewed-by: Laurent Pinchart Reviewed-by: Michael Riesch --- include/uapi/linux/rkisp1-config.h | 107 +++++++++------------------------= ---- 1 file changed, 24 insertions(+), 83 deletions(-) diff --git a/include/uapi/linux/rkisp1-config.h b/include/uapi/linux/rkisp1= -config.h index 3b060ea6eed71b87d79abc8401eae4e9c9f5323a..b2d2a71f7baff3833b20519264b= 58db7f168af90 100644 --- a/include/uapi/linux/rkisp1-config.h +++ b/include/uapi/linux/rkisp1-config.h @@ -7,8 +7,13 @@ #ifndef _UAPI_RKISP1_CONFIG_H #define _UAPI_RKISP1_CONFIG_H =20 +#ifdef __KERNEL__ +#include +#endif /* __KERNEL__ */ #include =20 +#include + /* Defect Pixel Cluster Detection */ #define RKISP1_CIF_ISP_MODULE_DPCC (1U << 0) /* Black Level Subtraction */ @@ -1158,79 +1163,26 @@ enum rkisp1_ext_params_block_type { RKISP1_EXT_PARAMS_BLOCK_TYPE_WDR, }; =20 -#define RKISP1_EXT_PARAMS_FL_BLOCK_DISABLE (1U << 0) -#define RKISP1_EXT_PARAMS_FL_BLOCK_ENABLE (1U << 1) +/* For backward compatibility */ +#define RKISP1_EXT_PARAMS_FL_BLOCK_DISABLE V4L2_ISP_PARAMS_FL_BLOCK_DISABLE +#define RKISP1_EXT_PARAMS_FL_BLOCK_ENABLE V4L2_ISP_PARAMS_FL_BLOCK_ENABLE =20 /* A bitmask of parameters blocks supported on the current hardware. */ #define RKISP1_CID_SUPPORTED_PARAMS_BLOCKS (V4L2_CID_USER_RKISP1_BASE + 0x= 01) =20 /** - * struct rkisp1_ext_params_block_header - RkISP1 extensible parameters bl= ock - * header + * rkisp1_ext_params_block_header - RkISP1 extensible parameters block hea= der * * This structure represents the common part of all the ISP configuration - * blocks. Each parameters block shall embed an instance of this structure= type - * as its first member, followed by the block-specific configuration data.= The - * driver inspects this common header to discern the block type and its si= ze and - * properly handle the block content by casting it to the correct block-sp= ecific - * type. + * blocks and is identical to :c:type:`v4l2_isp_params_block_header`. * - * The @type field is one of the values enumerated by + * The type field is one of the values enumerated by * :c:type:`rkisp1_ext_params_block_type` and specifies how the data shoul= d be - * interpreted by the driver. The @size field specifies the size of the - * parameters block and is used by the driver for validation purposes. - * - * The @flags field is a bitmask of per-block flags RKISP1_EXT_PARAMS_FL_*. - * - * When userspace wants to configure and enable an ISP block it shall fully - * populate the block configuration and set the - * RKISP1_EXT_PARAMS_FL_BLOCK_ENABLE bit in the @flags field. - * - * When userspace simply wants to disable an ISP block the - * RKISP1_EXT_PARAMS_FL_BLOCK_DISABLE bit should be set in @flags field. T= he - * driver ignores the rest of the block configuration structure in this ca= se. - * - * If a new configuration of an ISP block has to be applied userspace shall - * fully populate the ISP block configuration and omit setting the - * RKISP1_EXT_PARAMS_FL_BLOCK_ENABLE and RKISP1_EXT_PARAMS_FL_BLOCK_DISABL= E bits - * in the @flags field. - * - * Setting both the RKISP1_EXT_PARAMS_FL_BLOCK_ENABLE and - * RKISP1_EXT_PARAMS_FL_BLOCK_DISABLE bits in the @flags field is not allo= wed - * and not accepted by the driver. - * - * Userspace is responsible for correctly populating the parameters block = header - * fields (@type, @flags and @size) and the block-specific parameters. - * - * For example: + * interpreted by the driver. * - * .. code-block:: c - * - * void populate_bls(struct rkisp1_ext_params_block_header *block) { - * struct rkisp1_ext_params_bls_config *bls =3D - * (struct rkisp1_ext_params_bls_config *)block; - * - * bls->header.type =3D RKISP1_EXT_PARAMS_BLOCK_ID_BLS; - * bls->header.flags =3D RKISP1_EXT_PARAMS_FL_BLOCK_ENABLE; - * bls->header.size =3D sizeof(*bls); - * - * bls->config.enable_auto =3D 0; - * bls->config.fixed_val.r =3D blackLevelRed_; - * bls->config.fixed_val.gr =3D blackLevelGreenR_; - * bls->config.fixed_val.gb =3D blackLevelGreenB_; - * bls->config.fixed_val.b =3D blackLevelBlue_; - * } - * - * @type: The parameters block type, see - * :c:type:`rkisp1_ext_params_block_type` - * @flags: A bitmask of block flags - * @size: Size (in bytes) of the parameters block, including this header + * The flags field is a bitmask of per-block flags RKISP1_EXT_PARAMS_FL_*. */ -struct rkisp1_ext_params_block_header { - __u16 type; - __u16 flags; - __u32 size; -}; +#define rkisp1_ext_params_block_header v4l2_isp_params_block_header =20 /** * struct rkisp1_ext_params_bls_config - RkISP1 extensible params BLS conf= ig @@ -1588,27 +1540,14 @@ struct rkisp1_ext_params_wdr_config { * @RKISP1_EXT_PARAM_BUFFER_V1: First version of RkISP1 extensible paramet= ers */ enum rksip1_ext_param_buffer_version { - RKISP1_EXT_PARAM_BUFFER_V1 =3D 1, + RKISP1_EXT_PARAM_BUFFER_V1 =3D V4L2_ISP_PARAMS_VERSION_V1, }; =20 /** * 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_isp_params_buffer`. * * 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 +1563,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 +1612,11 @@ struct rkisp1_ext_params_cfg { __u8 data[RKISP1_EXT_PARAMS_MAX_SIZE]; }; =20 +#ifdef __KERNEL__ +/* Make sure the header is type-convertible to the generic v4l2 params one= */ +static_assert((sizeof(struct rkisp1_ext_params_cfg) - + RKISP1_EXT_PARAMS_MAX_SIZE) =3D=3D + sizeof(struct v4l2_isp_params_buffer)); +#endif /* __KERNEL__ */ + #endif /* _UAPI_RKISP1_CONFIG_H */ --=20 2.51.0 From nobody Fri Dec 19 17:14:24 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 5A4C930F551; Tue, 14 Oct 2025 08:01:21 +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=1760428883; cv=none; b=DVWZL6CSWFfcnfRxztQlpgRcaH2a/7srfWsFyHzvwcxBYtiSWDeQsi7cfXHGTTOltkDOBdACubfVCcm9O6D0FsjUE3G/JhJhLw5treVQm/kafDlkvIF+hfVDx4vsMinD+dIQaZGUqJc3mO5Tj0euX2fwdExIfqxTlq0mBn41lcI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760428883; c=relaxed/simple; bh=v3kCxecTZZjO4f1wnxHon/EzaHjCSwCFdWq9smjYTII=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=XuXKFJNivDokbQVYjMjPHmUHdKnLHjdSVqDfWeFpZ9gslESE90t1uPgYchu06mPcZHFB7Yt2/1EmUQeJoPM0ohy/VbkSE5TblekT2NotJSWmB2TAHzRBp3uMZKynjqq4TwAo4DBZfhATz6DY4/cYRx/jH6SITG0SJ9rScyOS+VY= 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=Ek8Pg1M9; 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="Ek8Pg1M9" Received: from [192.168.1.182] (93-46-82-201.ip106.fastwebnet.it [93.46.82.201]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 41C85E70; Tue, 14 Oct 2025 09:59:35 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1760428775; bh=v3kCxecTZZjO4f1wnxHon/EzaHjCSwCFdWq9smjYTII=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=Ek8Pg1M9nqwnez+l9hyKwWQQIL4i8gkOlQ7CrEcilxWZWUrTQMIIvmR2XNLQztSxJ K+xitslqh73c+SBIsJEKYfJI/99hOHjZ0fn0LQ9f4SUteYA610uXs9P7dlbesVvU4X ZKEkqLpyUQHBV5v6WYY92JkXwcDzJylaYUDrnMdM= From: Jacopo Mondi Date: Tue, 14 Oct 2025 10:00:55 +0200 Subject: [PATCH v7 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: <20251014-extensible-parameters-validation-v7-3-6628bed5ca98@ideasonboard.com> References: <20251014-extensible-parameters-validation-v7-0-6628bed5ca98@ideasonboard.com> In-Reply-To: <20251014-extensible-parameters-validation-v7-0-6628bed5ca98@ideasonboard.com> To: Dafna Hirschfeld , Laurent Pinchart , Keke Li , Mauro Carvalho Chehab , Heiko Stuebner , Dan Scally , Sakari Ailus , Antoine Bouyer Cc: linux-kernel@vger.kernel.org, linux-media@vger.kernel.org, linux-rockchip@lists.infradead.org, linux-arm-kernel@lists.infradead.org, Jacopo Mondi , Laurent Pinchart X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=6820; i=jacopo.mondi@ideasonboard.com; h=from:subject:message-id; bh=v3kCxecTZZjO4f1wnxHon/EzaHjCSwCFdWq9smjYTII=; b=kA0DAAoBcjQGjxahVjwByyZiAGjuA0aiB993IKCXp3n3m3w9WLuXJHixAEG8P2RnJWpCyNPQS 4kCMwQAAQoAHRYhBLXEPUiAmiCKj1g4wHI0Bo8WoVY8BQJo7gNGAAoJEHI0Bo8WoVY8WfYQALlj 8vTagujfPBC+Z7oMVLYRRt73hyFjDfUYcX+3Kd173hLNtNyCquQpJQt4KVjOiTEslnIV/P2OZ4X AtITWai9aOV5STv2cO7h1Z/POPLK1gB5w3Y98PoAUAN58LqDl6QoTiXKGG1cyLQ7XfNUpP2Fw/s ax1oy7VBpi8DIhJHdD86MCn30Fs8zz280yIt2+VCfojAMdZxqyDbQM4tbW9iG9q3DBcx4BGU6c2 gG6anjx6YwIgNKSgnzJMD/I5zl4p/hO/GJP7nVP6/NROSzBanSFdw39tmKha35SFBpwXo7Tpi4s rZvDbpv/88Lqu+yJygy9QwN5lUOVqt6z+VFm5lsVgL5ZDtI282gp30ZMTP8M2MYWupPv/fY9Ld2 upj3UFCiXtLodb4Nhx1EDoVMb8IqpcMPbv/O5zxlkigJniSdq8Tk1BJwcz43DAZlRVM+ddtj8Uq ryIVb1z7popBYdu9TCb6TpuuzKi5SXnb/pijcs/39xS3UikVsBTuc6rGev3rVUOb1qtTMU6VAa+ 2wNdZfutVNg+LaR33zFEAfQ0h+GzW5EBETA7n9sQOMDsHsk2RCpXYbWcGuV6FlvKgxQlWUaN1tR 9PaFOMzxQmuJ+l5Nlx0ks7GplODk8Yss5wooRZO8B2YhoT63tf32iITblyrmOI7AoI0B19uD0kf T4E3u X-Developer-Key: i=jacopo.mondi@ideasonboard.com; a=openpgp; fpr=72392EDC88144A65C701EA9BA5826A2587AD026B With the introduction of common types for extensible parameters format, convert the c3-isp-config.h header to use the new types. Factor-out the documentation that is now part of the common header and only keep the driver-specific on in place. The conversion to use common types doesn't impact userspace as the new types are either identical to the ones already existing in the C3 ISP uAPI or are 1-to-1 type convertible. Reviewed-by: Daniel Scally Reviewed-by: Keke Li Signed-off-by: Jacopo Mondi Reviewed-by: Laurent Pinchart --- include/uapi/linux/media/amlogic/c3-isp-config.h | 92 +++++++-------------= ---- 1 file changed, 24 insertions(+), 68 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..0a3c1cc55ccbbad12f18037d65f= 32ec9ca1a4ec0 100644 --- a/include/uapi/linux/media/amlogic/c3-isp-config.h +++ b/include/uapi/linux/media/amlogic/c3-isp-config.h @@ -6,8 +6,13 @@ #ifndef _UAPI_C3_ISP_CONFIG_H_ #define _UAPI_C3_ISP_CONFIG_H_ =20 +#ifdef __KERNEL__ +#include +#endif /* __KERNEL__ */ #include =20 +#include + /* * Frames are split into zones of almost equal width and height - a zone i= s a * rectangular tile of a frame. The metering blocks within the ISP collect @@ -141,7 +146,7 @@ struct c3_isp_stats_info { * @C3_ISP_PARAMS_BUFFER_V0: First version of C3 ISP parameters block */ enum c3_isp_params_buffer_version { - C3_ISP_PARAMS_BUFFER_V0, + C3_ISP_PARAMS_BUFFER_V0 =3D V4L2_ISP_PARAMS_VERSION_V0, }; =20 /** @@ -176,62 +181,23 @@ enum c3_isp_params_block_type { C3_ISP_PARAMS_BLOCK_SENTINEL }; =20 -#define C3_ISP_PARAMS_BLOCK_FL_DISABLE (1U << 0) -#define C3_ISP_PARAMS_BLOCK_FL_ENABLE (1U << 1) +/* For backward compatibility */ +#define C3_ISP_PARAMS_BLOCK_FL_DISABLE V4L2_ISP_PARAMS_FL_BLOCK_DISABLE +#define C3_ISP_PARAMS_BLOCK_FL_ENABLE V4L2_ISP_PARAMS_FL_BLOCK_ENABLE =20 /** * struct c3_isp_params_block_header - C3 ISP parameter block header * * This structure represents the common part of all the ISP configuration - * blocks. Each parameters block shall embed an instance of this structure= type - * as its first member, followed by the block-specific configuration data.= The - * driver inspects this common header to discern the block type and its si= ze and - * properly handle the block content by casting it to the correct block-sp= ecific - * type. + * blocks and is identical to :c:type:`v4l2_isp_params_block_header`. * - * The @type field is one of the values enumerated by + * The type field is one of the values enumerated by * :c:type:`c3_isp_params_block_type` and specifies how the data should be - * interpreted by the driver. The @size field specifies the size of the - * parameters block and is used by the driver for validation purposes. The - * @flags field is a bitmask of per-block flags C3_ISP_PARAMS_FL*. - * - * When userspace wants to disable an ISP block the - * C3_ISP_PARAMS_BLOCK_FL_DISABLED bit should be set in the @flags field. = In - * this case userspace may optionally omit the remainder of the configurat= ion - * block, which will be ignored by the driver. - * - * When a new configuration of an ISP block needs to be applied userspace - * shall fully populate the ISP block and omit setting the - * C3_ISP_PARAMS_BLOCK_FL_DISABLED bit in the @flags field. - * - * Userspace is responsible for correctly populating the parameters block = header - * fields (@type, @flags and @size) and the block-specific parameters. - * - * For example: - * - * .. code-block:: c + * interpreted by the driver. * - * void populate_pst_gamma(struct c3_isp_params_block_header *block) { - * struct c3_isp_params_pst_gamma *gamma =3D - * (struct c3_isp_params_pst_gamma *)block; - * - * gamma->header.type =3D C3_ISP_PARAMS_BLOCK_PST_GAMMA; - * gamma->header.flags =3D C3_ISP_PARAMS_BLOCK_FL_ENABLE; - * gamma->header.size =3D sizeof(*gamma); - * - * for (unsigned int i =3D 0; i < 129; i++) - * gamma->pst_gamma_lut[i] =3D i; - * } - * - * @type: The parameters block type from :c:type:`c3_isp_params_block_type` - * @flags: A bitmask of block flags - * @size: Size (in bytes) of the parameters block, including this header + * The flags field is a bitmask of per-block flags C3_ISP_PARAMS_FL_*. */ -struct c3_isp_params_block_header { - __u16 type; - __u16 flags; - __u32 size; -}; +#define c3_isp_params_block_header v4l2_isp_params_block_header =20 /** * struct c3_isp_params_awb_gains - Gains for auto-white balance @@ -498,26 +464,10 @@ 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_isp_params_buffer`. + * + * Currently only C3_ISP_PARAM_BUFFER_V0 is supported. * * The expected memory layout of the parameters buffer is:: * @@ -561,4 +511,10 @@ struct c3_isp_params_cfg { __u8 data[C3_ISP_PARAMS_MAX_SIZE]; }; =20 +#ifdef __KERNEL__ +/* Make sure the header is type-convertible to the generic v4l2 params one= */ +static_assert((sizeof(struct c3_isp_params_cfg) - C3_ISP_PARAMS_MAX_SIZE) = =3D=3D + sizeof(struct v4l2_isp_params_buffer)); +#endif /* __KERNEL__ */ + #endif --=20 2.51.0 From nobody Fri Dec 19 17:14:24 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 AD1E030F926; Tue, 14 Oct 2025 08:01:24 +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=1760428886; cv=none; b=KgRf1BRIxfQcTfL8bGDcBttUviaoIiV5ZboaPmsztOw/4jBDIDVEwQwNw1P7mJmxukiuII/mgNYxTkcOZRA6/fxYvJ3PtYHPtIbTWNxXmHoezANZhEsUlic8AbqoLHKGjGAqlXOP08okjHBUK9uFKlOQECjVNnQfdt48jhOg12s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760428886; c=relaxed/simple; bh=XF6muoDpgftcMNaVPGf+dJ0kUhnTFQpZE9vUqI8xmTw=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=SV+V/harf940NDndc6jkMw5nFHAOBTL9ie05eFNRGA9vcouNdVktZBKDCbRriA12tBDzrD6D/KhZkfufuLAr0OuC24KQSZddmQCPX37rUZl0qr6KdcvbhQkk4Iu2ke1b56qCZZzLxHiHd2RcfiJMZ10UrzdIanWZTAFTv0xSKT4= 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=FCyKFkxl; 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="FCyKFkxl" Received: from [192.168.1.182] (93-46-82-201.ip106.fastwebnet.it [93.46.82.201]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id CFB13EAE; Tue, 14 Oct 2025 09:59:35 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1760428776; bh=XF6muoDpgftcMNaVPGf+dJ0kUhnTFQpZE9vUqI8xmTw=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=FCyKFkxly/gxs47ZOdWPJSQ5hgTR+W80/u79ATriQoJM4247+3IV7vi6PVto/Tvoq PAd1IzpKc8wS+EznRdbi30c/rPLl4J+gRL6TsfWtk1/tJcNnKKjqIqCHIs2mnukAAV nsA4XCeBfJpSjE617ujSf1Tgux6dKxTkaocN7tIs= From: Jacopo Mondi Date: Tue, 14 Oct 2025 10:00:56 +0200 Subject: [PATCH v7 4/8] media: Documentation: uapi: Add V4L2 ISP documentation 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: <20251014-extensible-parameters-validation-v7-4-6628bed5ca98@ideasonboard.com> References: <20251014-extensible-parameters-validation-v7-0-6628bed5ca98@ideasonboard.com> In-Reply-To: <20251014-extensible-parameters-validation-v7-0-6628bed5ca98@ideasonboard.com> To: Dafna Hirschfeld , Laurent Pinchart , Keke Li , Mauro Carvalho Chehab , Heiko Stuebner , Dan Scally , Sakari Ailus , Antoine Bouyer Cc: linux-kernel@vger.kernel.org, linux-media@vger.kernel.org, linux-rockchip@lists.infradead.org, linux-arm-kernel@lists.infradead.org, Jacopo Mondi X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=7257; i=jacopo.mondi@ideasonboard.com; h=from:subject:message-id; bh=XF6muoDpgftcMNaVPGf+dJ0kUhnTFQpZE9vUqI8xmTw=; b=owEBbQKS/ZANAwAKAXI0Bo8WoVY8AcsmYgBo7gNGvtweY6kzNxleJHEu684WFSl2vUZCu7ygV nFpmrGNNoaJAjMEAAEKAB0WIQS1xD1IgJogio9YOMByNAaPFqFWPAUCaO4DRgAKCRByNAaPFqFW PEUzD/9sCAs1ULlw3cNj1lmhEEh9OVkC5jKNU/iCyMUUV94KkvWBxfJqueBxYDqM4gSaCwDz3Qw /jD9Zwsks4LmOXBVKejuStgBlIcNVthue4APpf+9w4tfilK6Vm4UBzdydCd+IZNg2IoGdbRoNle NvdaPwRLe8B6IPIOTHqSkpk4dtTNhRHiSF9glq9O9614iTjNLhU5vz1c3duVq8CZQZ4l6vOMygr G7qqg/dMtDIjSlg2i+qNs9GYZAnN6Xurc+y4AKGzM+c6hpuU3os5KGEcgOtf7ViJmIuta7BWsmw rBAMyq8tt+LDjwADEZIl8/Pe72S6vF8uiqtCJ3XqFsF9ZINS5TquBFjd21yxBvfLhISO6MqSQae ppoqMBo12hg+5wGBJWi+Ic0N2NQUUU/3d9+xW5llJF4yvdSiuM9FNs6vOPn3JWLJeCkjIiA1Omz k7U3uBvF+IB004ERxeV1XH3HJRmWQfIIzkuOk22gHI2a+v2qYDRKg3IIDhGuI245sX+q2sa1Qz0 lUwLlowDqBRN3FPj4cbjnvgZbVOnLwIrvb8cZN1rKppGnEKlE1kCTEJTh1cjqhpx7+tTkyh4OUW GOp6zgHAuK6SGZWo075oQ6JDJfXNXRX0rKAQnDhbup8DxUizjFDlnrfAaUjAigGKoDjGS217rFI OJDseE0CU/kdbng== X-Developer-Key: i=jacopo.mondi@ideasonboard.com; a=openpgp; fpr=72392EDC88144A65C701EA9BA5826A2587AD026B Add userspace documentation for V4L2 ISP generic parameters and statistics formats. Reviewed-by: Daniel Scally Signed-off-by: Jacopo Mondi Reviewed-by: Michael Riesch --- .../userspace-api/media/v4l/meta-formats.rst | 1 + Documentation/userspace-api/media/v4l/v4l2-isp.rst | 121 +++++++++++++++++= ++++ MAINTAINERS | 1 + 3 files changed, 123 insertions(+) diff --git a/Documentation/userspace-api/media/v4l/meta-formats.rst b/Docum= entation/userspace-api/media/v4l/meta-formats.rst index 0de80328c36bf148051a19abe9e5241234ddfe5c..261483f8e4d832d3d0ce8aa11df= 4b4eb1645f22f 100644 --- a/Documentation/userspace-api/media/v4l/meta-formats.rst +++ b/Documentation/userspace-api/media/v4l/meta-formats.rst @@ -24,3 +24,4 @@ These formats are used for the :ref:`metadata` interface = only. metafmt-vivid metafmt-vsp1-hgo metafmt-vsp1-hgt + v4l2-isp diff --git a/Documentation/userspace-api/media/v4l/v4l2-isp.rst b/Documenta= tion/userspace-api/media/v4l/v4l2-isp.rst new file mode 100644 index 0000000000000000000000000000000000000000..41078558ba5cc1faf922a9b9112= e64c99ff37080 --- /dev/null +++ b/Documentation/userspace-api/media/v4l/v4l2-isp.rst @@ -0,0 +1,121 @@ +.. SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later + +.. _v4l2-isp: + +************************ +Generic V4L2 ISP formats +************************ + +ISP configuration and statistics: theory of operations +=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=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. + +ISP statistics are collected by the driver at a specific time point and dr= ivers +use them to populate a *statistics buffer* which is then returned to users= pace. + +The parameters and statistics buffers are organized in a driver-specific +way, and their data layout differs between one driver and another. + +ISP drivers generally exchange parameters and statistics with userspace th= rough +a metadata capture and output node respectively, implementing the +:c:type:`v4l2_meta_format` interface. Each ISP driver defines a metadata c= apture +and output format to be used on those video nodes, and the buffer layout a= nd +organization is fixed by the format definition. + +The uAPI/ABI problem +-------------------- + +By upstreaming the metadata formats that describe the parameters and stati= stics +buffers 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 first version that lands in the kernel, and some parts of= the +interface have to later be modified for bug-fixes or improvements. + +If any later bug-fix/improvement requires changes to the metadata formats, +this is considered an ABI-breakage that is strictly forbidden by the Linux +kernel policies. For this reason, any change in the ISP parameters and +statistics buffer layout would require defining a new metadata format. + +For these reasons Video4Linux2 has introduced support for generic ISP para= meters +and statistics data types, designed with the goal of being: + +- Extensible: new features can be added later on without breaking the exis= ting + interface +- Versioned: different versions of the format can be defined without + breaking the existing interface + +ISP configuration +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +Before the introduction of generic formats +------------------------------------------ + +Metadata cature formats that describe ISP configuration parameters were mo= st +the time realized by defining C structures that reflect the ISP 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 number of supported ISP blocks, the layout of their configuration data= are +fixed by the format definition, incurring the in the above described uAPI/= uABI +problems. + +Generic ISP parameters +---------------------- + +The generic ISP configuration parameters format is realized by a defining a +single C structure that contains an header, followed by a binary buffer wh= ere +userspace programs a variable number of ISP configuration data block, one = for +each supported ISP feature. + +The :c:type:`v4l2_isp_params_buffer` structure defines the parameters buff= er +header which is followed by a binary buffer of ISP configuration parameter= s. +Userspace shall correctly populate the buffer header with the versioning +information and with the size (in bytes) of the binary data buffer where i= t will +store the ISP blocks configuration. + +Each *ISP configuration block* is preceded by an header implemented by the +:c:type:`v4l2_isp_params_block_header` structure, followed by the configur= ation +parameters for that specific block, defined by the ISP driver specific data +types. + +Userspace applications are responsible for correctly populating each block= 's +header fields (type, flags and size) and the block-specific parameters. + +ISP Block enabling, disabling and configuration +----------------------------------------------- + +When userspace wants to configure and enable an ISP block it shall fully +populate the block configuration and set the V4L2_ISP_PARAMS_FL_BLOCK_ENAB= LE +bit in the block header's `flags` field. + +When userspace simply wants to disable an ISP block the +V4L2_ISP_PARAMS_FL_BLOCK_DISABLE bit should be set in block header's `flag= s` +field. Drivers accept a configuration parameters block with no additional +data after the header in this case. + +If the configuration of an already active ISP block has to be updated, +userspace shall fully populate the ISP block parameters and omit setting t= he +V4L2_ISP_PARAMS_FL_BLOCK_ENABLE and V4L2_ISP_PARAMS_FL_BLOCK_DISABLE bits = in the +header's `flags` field. + +Setting both the V4L2_ISP_PARAMS_FL_BLOCK_ENABLE and +V4L2_ISP_PARAMS_FL_BLOCK_DISABLE bits in the flags field is not allowed an= d not +accepted. + +Any further extension to the parameters layout that happens after the ISP = driver +has been merged in Linux can be implemented by adding new blocks definition +without invalidating the existing ones. + +ISP statistics +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +Support for generic statistics format is not yet implemented in Video4Linu= x2. + +V4L2 ISP 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 + +.. kernel-doc:: include/uapi/linux/media/v4l2-isp.h diff --git a/MAINTAINERS b/MAINTAINERS index e9ac834d212f88222437e8d806800b2516d44f01..340353334299cd5eebf1f72132b= 7e91b6f5fdbfe 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -26857,6 +26857,7 @@ V4L2 GENERIC ISP PARAMETERS AND STATISTIC FORMATS M: Jacopo Mondi L: linux-media@vger.kernel.org S: Maintained +F: Documentation/userspace-api/media/v4l/v4l2-isp.rst F: include/uapi/linux/media/v4l2-isp.h =20 VF610 NAND DRIVER --=20 2.51.0 From nobody Fri Dec 19 17:14:24 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 0A85830F94A; Tue, 14 Oct 2025 08:01:24 +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=1760428888; cv=none; b=lZUY/UlvCZqd78iguOjYRLifYg+RvHAYeionX6F5D80z7SKVPVfQx45lGiIp4FsRaiuGBP5HM8wFKEJHgRnf1SbYUYWmFufIUEGbpuLGGfb3ALfmGaZkrifBqwUgdJhtfoQJqAj6BZly0mwq00h1370aN99ZACFmO3OedwTCwbg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760428888; c=relaxed/simple; bh=OgIwRrIQRBzj9481fixzaM0BqZmrVQNqE/YGhNXZuhM=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=BnSRZIkJ7AlmL3u7ZOYJq4fv2AAWi/pTaED62fTj3+7cNzBt1i3SL7crFwl+KVn6qe8IQy9r/f7EKwm6cbnMAug/+LTo+hOWI7LLaDoJdlnmB1+IZE3BQsWbDuWm6tAFAyldWTMz2IUqpTaHDU3fRJNlnuAFNx39rTR3VpfLAc0= 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=WhYQdKBD; 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="WhYQdKBD" Received: from [192.168.1.182] (93-46-82-201.ip106.fastwebnet.it [93.46.82.201]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 6A147F09; Tue, 14 Oct 2025 09:59:36 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1760428776; bh=OgIwRrIQRBzj9481fixzaM0BqZmrVQNqE/YGhNXZuhM=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=WhYQdKBDqyIDe9z6V90qjkc9KGo8+n21u/GaY/0DuY7lrGJnWyvL+cMGSCFGbJC7o j5cMh3brXilFCyvaaTxIGkvaSUHlI+87vGlAHyO1SHbhFQcWOWoaK7LzrE8XOJ1gER WlVoQgIznElPxDdYUU5wJqmdrvLNWQ8HQwFoWets= From: Jacopo Mondi Date: Tue, 14 Oct 2025 10:00:57 +0200 Subject: [PATCH v7 5/8] media: v4l2-core: Introduce v4l2-isp.c Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20251014-extensible-parameters-validation-v7-5-6628bed5ca98@ideasonboard.com> References: <20251014-extensible-parameters-validation-v7-0-6628bed5ca98@ideasonboard.com> In-Reply-To: <20251014-extensible-parameters-validation-v7-0-6628bed5ca98@ideasonboard.com> To: Dafna Hirschfeld , Laurent Pinchart , Keke Li , Mauro Carvalho Chehab , Heiko Stuebner , Dan Scally , Sakari Ailus , Antoine Bouyer Cc: linux-kernel@vger.kernel.org, linux-media@vger.kernel.org, linux-rockchip@lists.infradead.org, linux-arm-kernel@lists.infradead.org, Jacopo Mondi , Laurent Pinchart X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=10784; i=jacopo.mondi@ideasonboard.com; h=from:subject:message-id; bh=OgIwRrIQRBzj9481fixzaM0BqZmrVQNqE/YGhNXZuhM=; b=owEBbQKS/ZANAwAKAXI0Bo8WoVY8AcsmYgBo7gNGhTryvD51w90R5q4GhmavpkW7sKKiONRjO F2jI1DmR/GJAjMEAAEKAB0WIQS1xD1IgJogio9YOMByNAaPFqFWPAUCaO4DRgAKCRByNAaPFqFW PDoYD/4rEnrYB1kWwfaDEJO9Jo7wlez4y9700w0u3iXMevxDQVmFVNW02snLjW4Xe8MjHZJxpCr qknA5my0HbODHXEvuPuOHUwF/IB6V2N1GBVD2WepUM5nuC33lRKkKFGZnUlDfqOmaLWNoPIYpIp 05kg4GeAi6TeKduCiwJ9S6q0ILWhmZVXRyypxJ0z/3S2H14GhEdVB9lFYsM645/BSCEkPnJMrKS DklvpuzfmhoLWRIwM2lvX7XKLizjwb/Vft/l//Qj27YiTAcOxiHC9qWKPDv0Z/Tje5GkuGvLik+ DEPdNWkiNjs4ch5TfweD06PA+ubIsnhK2NTALHbw2HPZghA8jWPX2+YBNF4s32ZlLrA3kUanvsC I315iMcHL2rI46JO4amqBS4RHKQLZQfQNFd5v9Zcve2JeT61gsYIKbowUzowiG3LbUNMPF/okFE 6WFPayrcJbRo+5A1yqEttl9bL7QOkUEeozQUhbsGgkk7TvVOVz4jH5fB79IAWIDYFwduEhowjZM ZCFpp9bjFPhcDlxcQEV+cJdZZ6jIMjddEffhXCGQV8CtPQzfF/hBfshB3VzG/iXPZ7zs+xS8cWi mYShRuMbA7X8NMQNMd956/GUIA+ayNJ2MfhgssBem5aFiq7ZE32RNBqenACyJta28geLZBDuF+s gz/kR8WVbtvmbqQ== X-Developer-Key: i=jacopo.mondi@ideasonboard.com; a=openpgp; fpr=72392EDC88144A65C701EA9BA5826A2587AD026B Add to the V4L2 framework helper functions to support drivers when validating a buffer of V4L2 ISP parameters. Driver shall use v4l2_isp_params_validate_buffer_size() to verify the size correctness of the data received from userspace, and after having copied the data to a kernel-only memory location, complete the validation by calling v4l2_isp_params_validate_buffer(). Reviewed-by: Daniel Scally Signed-off-by: Jacopo Mondi Reviewed-by: Laurent Pinchart Reviewed-by: Michael Riesch --- MAINTAINERS | 2 + drivers/media/v4l2-core/Kconfig | 4 ++ drivers/media/v4l2-core/Makefile | 1 + drivers/media/v4l2-core/v4l2-isp.c | 128 +++++++++++++++++++++++++++++++++= ++++ include/media/v4l2-isp.h | 91 ++++++++++++++++++++++++++ 5 files changed, 226 insertions(+) diff --git a/MAINTAINERS b/MAINTAINERS index 340353334299cd5eebf1f72132b7e91b6f5fdbfe..59ab4a34f72c0430a8d7966942a= cb2242ad923ca 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -26858,6 +26858,8 @@ M: Jacopo Mondi L: linux-media@vger.kernel.org S: Maintained F: Documentation/userspace-api/media/v4l/v4l2-isp.rst +F: drivers/media/v4l2-core/v4l2-isp.c +F: include/media/v4l2-isp.h F: include/uapi/linux/media/v4l2-isp.h =20 VF610 NAND DRIVER diff --git a/drivers/media/v4l2-core/Kconfig b/drivers/media/v4l2-core/Kcon= fig index 331b8e535e5bbf33f22638b2ae8bc764ad5fc407..d50ccac9733cc39a43426ae7e79= 96dd0b5b45186 100644 --- a/drivers/media/v4l2-core/Kconfig +++ b/drivers/media/v4l2-core/Kconfig @@ -82,3 +82,7 @@ config V4L2_CCI_I2C depends on I2C select REGMAP_I2C select V4L2_CCI + +config V4L2_ISP + tristate + depends on VIDEOBUF2_CORE diff --git a/drivers/media/v4l2-core/Makefile b/drivers/media/v4l2-core/Mak= efile index 2177b9d63a8ffc1127c5a70118249a2ff63cd759..329f0eadce994cc1c8580beb435= f68fa7e2a7aeb 100644 --- a/drivers/media/v4l2-core/Makefile +++ b/drivers/media/v4l2-core/Makefile @@ -29,6 +29,7 @@ obj-$(CONFIG_V4L2_CCI) +=3D v4l2-cci.o obj-$(CONFIG_V4L2_FLASH_LED_CLASS) +=3D v4l2-flash-led-class.o obj-$(CONFIG_V4L2_FWNODE) +=3D v4l2-fwnode.o obj-$(CONFIG_V4L2_H264) +=3D v4l2-h264.o +obj-$(CONFIG_V4L2_ISP) +=3D v4l2-isp.o obj-$(CONFIG_V4L2_JPEG_HELPER) +=3D v4l2-jpeg.o obj-$(CONFIG_V4L2_MEM2MEM_DEV) +=3D v4l2-mem2mem.o obj-$(CONFIG_V4L2_VP9) +=3D v4l2-vp9.o diff --git a/drivers/media/v4l2-core/v4l2-isp.c b/drivers/media/v4l2-core/v= 4l2-isp.c new file mode 100644 index 0000000000000000000000000000000000000000..35f0b701f1729c3c0ccc34b1c89= 189b179e0b684 --- /dev/null +++ b/drivers/media/v4l2-core/v4l2-isp.c @@ -0,0 +1,128 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Video4Linux2 generic ISP parameters and statistics support + * + * Copyright (C) 2025 Ideas On Board Oy + * Author: Jacopo Mondi + */ + +#include + +#include +#include + +#include + +int v4l2_isp_params_validate_buffer_size(struct device *dev, + struct vb2_buffer *vb, + size_t max_size) +{ + size_t header_size =3D offsetof(struct v4l2_isp_params_buffer, data); + size_t payload_size =3D vb2_get_plane_payload(vb, 0); + + /* 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; + } + + return 0; +} +EXPORT_SYMBOL_GPL(v4l2_isp_params_validate_buffer_size); + +int v4l2_isp_params_validate_buffer(struct device *dev, struct vb2_buffer = *vb, + const struct v4l2_isp_params_buffer *buffer, + const struct v4l2_isp_params_block_info *info, + size_t num_blocks) +{ + size_t header_size =3D offsetof(struct v4l2_isp_params_buffer, data); + size_t payload_size =3D vb2_get_plane_payload(vb, 0); + size_t block_offset =3D 0; + size_t buffer_size; + + /* + * Currently only the first version of the V4L2 ISP parameters format is + * supported. We accept both V0 and V1 to support existing drivers + * compatible with V4L2 ISP that use either 0 or 1 as their "first + * version" identifiers. + */ + if (buffer->version !=3D V4L2_ISP_PARAMS_VERSION_V0 && + buffer->version !=3D V4L2_ISP_PARAMS_VERSION_V1) { + dev_dbg(dev, + "Unsupported V4L2 ISP parameters format version: %u\n", + buffer->version); + return -EINVAL; + } + + /* Validate the size reported in the 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; + } + + /* Walk the list of ISP configuration blocks and validate them. */ + buffer_size =3D buffer->data_size; + while (buffer_size >=3D sizeof(struct v4l2_isp_params_block_header)) { + const struct v4l2_isp_params_block_info *block_info; + const struct v4l2_isp_params_block_header *block; + + block =3D (const struct v4l2_isp_params_block_header *) + (buffer->data + block_offset); + + if (block->type >=3D num_blocks) { + dev_dbg(dev, + "Invalid block type %u at offset %zu\n", + block->type, block_offset); + return -EINVAL; + } + + if (block->size > buffer_size) { + dev_dbg(dev, "Premature end of parameters data\n"); + return -EINVAL; + } + + /* It's invalid to specify both ENABLE and DISABLE. */ + if ((block->flags & (V4L2_ISP_PARAMS_FL_BLOCK_ENABLE | + V4L2_ISP_PARAMS_FL_BLOCK_DISABLE)) =3D=3D + (V4L2_ISP_PARAMS_FL_BLOCK_ENABLE | + V4L2_ISP_PARAMS_FL_BLOCK_DISABLE)) { + dev_dbg(dev, "Invalid block flags %x at offset %zu\n", + block->flags, block_offset); + return -EINVAL; + } + + /* + * Match the block reported size against the info provided + * one, but allow the block to only contain the header in + * case it is going to be disabled. + */ + block_info =3D &info[block->type]; + if (block->size !=3D block_info->size && + (!(block->flags & V4L2_ISP_PARAMS_FL_BLOCK_DISABLE) || + block->size !=3D sizeof(*block))) { + dev_dbg(dev, + "Invalid block size %u (expected %zu) at offset %zu\n", + block->size, block_info->size, block_offset); + return -EINVAL; + } + + block_offset +=3D block->size; + buffer_size -=3D block->size; + } + + if (buffer_size) { + dev_dbg(dev, "Unexpected data after the parameters buffer end\n"); + return -EINVAL; + } + + return 0; +} +EXPORT_SYMBOL_GPL(v4l2_isp_params_validate_buffer); diff --git a/include/media/v4l2-isp.h b/include/media/v4l2-isp.h new file mode 100644 index 0000000000000000000000000000000000000000..8b4695663699e7f176384739cf5= 4ed7fa2c578f8 --- /dev/null +++ b/include/media/v4l2-isp.h @@ -0,0 +1,91 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* + * Video4Linux2 generic ISP parameters and statistics support + * + * Copyright (C) 2025 Ideas On Board Oy + * Author: Jacopo Mondi + */ + +#ifndef _V4L2_ISP_H_ +#define _V4L2_ISP_H_ + +#include + +struct device; +struct vb2_buffer; + +/** + * v4l2_isp_params_buffer_size - Calculate size of v4l2_isp_params_buffer + * @max_params_size: The total size of the ISP configuration blocks + * + * Users of the v4l2 extensible parameters will have differing sized data = arrays + * depending on their specific parameter buffers. Drivers and userspace wi= ll + * need to be able to calculate the appropriate size of the struct to + * accommodate all ISP configuration blocks provided by the platform. + * This macro provides a convenient tool for the calculation. + */ +#define v4l2_isp_params_buffer_size(max_params_size) \ + (offsetof(struct v4l2_isp_params_buffer, data) + (max_params_size)) + +/** + * v4l2_isp_params_validate_buffer_size - Validate a V4L2 ISP buffer sizes + * @dev: the driver's device pointer + * @vb: the videobuf2 buffer + * @max_size: the maximum allowed buffer size + * + * This function performs validation of the size of a V4L2 ISP parameters = buffer + * before the driver can access the actual data buffer content. + * + * After the sizes validation, drivers should copy the buffer content to a + * kernel-only memory area to prevent userspace from modifying it, + * before completing validation using v4l2_isp_params_validate_buffer(). + * + * The @vb buffer as received from the vb2 .buf_prepare() operation is che= cked + * against @max_size and it's validated to be large enough to accommodate = at + * least one ISP configuration block. + */ +int v4l2_isp_params_validate_buffer_size(struct device *dev, + struct vb2_buffer *vb, + size_t max_size); + +/** + * struct v4l2_isp_params_block_info - V4L2 ISP per-block info + * @size: the block expected size + * + * The v4l2_isp_params_block_info collects information of the ISP configur= ation + * blocks for validation purposes. It currently only contains the expected + * block size. + * + * Drivers shall prepare a list of block info, indexed by block type, one = for + * each supported ISP block and correctly populate them with the expected = block + * size. + */ +struct v4l2_isp_params_block_info { + size_t size; +}; + +/** + * v4l2_isp_params_validate_buffer - Validate a V4L2 ISP parameters buffer + * @dev: the driver's device pointer + * @vb: the videobuf2 buffer + * @buffer: the V4L2 ISP parameters buffer + * @info: the list of per-block validation info + * @num_blocks: the number of blocks + * + * This function completes the validation of a V4L2 ISP parameters buffer, + * verifying each configuration block correctness before the driver can use + * them to program the hardware. + * + * Drivers should use this function after having validated the correctness= of + * the vb2 buffer sizes by using the v4l2_isp_params_validate_buffer_size() + * helper first. Once the buffer size has been validated, drivers should + * perform a copy of the user provided buffer into a kernel-only memory bu= ffer + * to prevent userspace from modifying its content after it has been submi= tted + * to the driver, and then call this function to complete validation. + */ +int v4l2_isp_params_validate_buffer(struct device *dev, struct vb2_buffer = *vb, + const struct v4l2_isp_params_buffer *buffer, + const struct v4l2_isp_params_block_info *info, + size_t num_blocks); + +#endif /* _V4L2_ISP_H_ */ --=20 2.51.0 From nobody Fri Dec 19 17:14:24 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 0A6412DC768; Tue, 14 Oct 2025 08:01: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=1760428890; cv=none; b=qmM5T4T60xkCJKpU4wl9MqSL/zTITVtr0hKo+AhYowqZMSElhetgkhGYsrOi/9xCp8KXiKcaovyTHIXFhidppqKVKdmwuflACYW4us/BnxXSsXBDJgJotwJkmtqYjWPpuCpDxblv28F+6bRPp55cMCZKxMIfrsoPByzqSJxU5TQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760428890; c=relaxed/simple; bh=H9glGWs+tZBu1vv1PdSeEUPSbMrGZr2Onk1XH09PPQg=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=cBmS+Xzei+8AiZyjaUD6nbmsB8M3tfe4dqOG08XaTVJkSS/T7uX1JnBgGCEgIzxBrUn5rEAlcpjD19I8aC4bYDjXGUz91GPPlkYuFOANFnjlis5n723Sc1Gm4xQN4wdkxU+reDc25ZOyiU1cJVdu+zDXZ4kndnz0qgsKNN/gDIA= 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=F+GLN1pH; 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="F+GLN1pH" Received: from [192.168.1.182] (93-46-82-201.ip106.fastwebnet.it [93.46.82.201]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 0854811D5; Tue, 14 Oct 2025 09:59:37 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1760428777; bh=H9glGWs+tZBu1vv1PdSeEUPSbMrGZr2Onk1XH09PPQg=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=F+GLN1pHt8NR6u2C8aXzXv1AtXlHo150GzF1jvTY3lqXUXVGMEzGf+GkvqPi7pZkh 0c96gML99G97DwskMEFk2V2sfgUIwnqTaavdJ2+azz7reXNxewHEekaJ0+HhWgnkMX KVj+vr/jvZnLHszJ2rh0FdUzpr+ZX2QtVr1iCuw8= From: Jacopo Mondi Date: Tue, 14 Oct 2025 10:00:58 +0200 Subject: [PATCH v7 6/8] media: rkisp1: Use v4l2-isp for validation Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20251014-extensible-parameters-validation-v7-6-6628bed5ca98@ideasonboard.com> References: <20251014-extensible-parameters-validation-v7-0-6628bed5ca98@ideasonboard.com> In-Reply-To: <20251014-extensible-parameters-validation-v7-0-6628bed5ca98@ideasonboard.com> To: Dafna Hirschfeld , Laurent Pinchart , Keke Li , Mauro Carvalho Chehab , Heiko Stuebner , Dan Scally , Sakari Ailus , Antoine Bouyer Cc: linux-kernel@vger.kernel.org, linux-media@vger.kernel.org, linux-rockchip@lists.infradead.org, linux-arm-kernel@lists.infradead.org, Jacopo Mondi X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=12668; i=jacopo.mondi@ideasonboard.com; h=from:subject:message-id; bh=H9glGWs+tZBu1vv1PdSeEUPSbMrGZr2Onk1XH09PPQg=; b=owEBbQKS/ZANAwAKAXI0Bo8WoVY8AcsmYgBo7gNGqwzaoh7uKg6PzQo+GpNvyX1V/K1yMhUje 25H5NieYb+JAjMEAAEKAB0WIQS1xD1IgJogio9YOMByNAaPFqFWPAUCaO4DRgAKCRByNAaPFqFW PLoZD/9YnpYw1ndM/0H1fx55BwTkVoCEPBNKiHaEiDF/QQynENyPt6h6Ae2Sy85AlLJWzTEw9xA ffwnZDlMgHTFjPliBErXx+bfU22tObrDIIULqnzvvbwCCBlt5s0gHDNaqu2U6ESpbjTqSjp1aCI eRVusw3nyN+yJ6DXa6umRKXWdbYgEUumNHsxQGQDBgrxMj74FHbJ/5EdBZ+6d1oTcBfUDUY2iuI gRrvgukGYyBqXMJecPpeGMkIi5lagoUK0yO9xVKI5Hb6FhLGuphn8WeX1Q8/WepdTE9u6tzJeIj x8vOPAFNHrifg4Kv/shgd4Vu7HNZR7XiEvQHWvigdCFtahhUGA1glscMskH8cgPDpyf4XPyP4Ao GkXcSyA5k7BgenstNy3gAMrLPmOXlKIwnM3qnRk/AZUJqMWGbBQPmCqv5VZTyy64a9K5UDRXfGk MWlzwNmBP2MfUgH/C9AgVbUC7J15/lJfqJ1YDZV74dVszTX7bGFBVQgAwmuttma+GB8OK3YQFhM LJB3Iqe3WDUeC5DlLUCaaZAcAXw1JOHvCrbUBKqSAXCwQwSKQsip87hmWXI1OSyh/znAihGX/9g Vw1X4WSMHOOljog9RDMoXvmQHIw94tT/a/gjTD7aBTuxpxllNz2iAnsBJ7Z54YctKiozFS/cIlY 6VGlYiEcwCDwULw== X-Developer-Key: i=jacopo.mondi@ideasonboard.com; a=openpgp; fpr=72392EDC88144A65C701EA9BA5826A2587AD026B Convert rkisp1-params.c to use the helpers defined in v4l2-isp.h to perform validation of a ISP parameters buffer. Reviewed-by: Daniel Scally Signed-off-by: Jacopo Mondi --- drivers/media/platform/rockchip/rkisp1/Kconfig | 1 + .../media/platform/rockchip/rkisp1/rkisp1-params.c | 183 +++++++++--------= ---- 2 files changed, 77 insertions(+), 107 deletions(-) diff --git a/drivers/media/platform/rockchip/rkisp1/Kconfig b/drivers/media= /platform/rockchip/rkisp1/Kconfig index 731c9acbf6efa33188617204d441fb0ea59adebc..f53eb1f3f3e7003d8e02c9236ae= abb5ae8844f7b 100644 --- a/drivers/media/platform/rockchip/rkisp1/Kconfig +++ b/drivers/media/platform/rockchip/rkisp1/Kconfig @@ -10,6 +10,7 @@ config VIDEO_ROCKCHIP_ISP1 select VIDEOBUF2_VMALLOC select V4L2_FWNODE select GENERIC_PHY_MIPI_DPHY + select V4L2_ISP default n help Enable this to support the Image Signal Processing (ISP) module diff --git a/drivers/media/platform/rockchip/rkisp1/rkisp1-params.c b/drive= rs/media/platform/rockchip/rkisp1/rkisp1-params.c index f1585f8fa0f478304f74317fd9dd09199c94ec82..a880a46d2eefefc6474b36dc5aa= 69b4f3dce51d1 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 @@ -2097,122 +2098,166 @@ typedef void (*rkisp1_block_handler)(struct rkisp= 1_params *params, const union rkisp1_ext_params_config *config); =20 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 { [RKISP1_EXT_PARAMS_BLOCK_TYPE_BLS] =3D { - .size =3D sizeof(struct rkisp1_ext_params_bls_config), .handler =3D rkisp1_ext_params_bls, .group =3D RKISP1_EXT_PARAMS_BLOCK_GROUP_OTHERS, .features =3D RKISP1_FEATURE_BLS, }, [RKISP1_EXT_PARAMS_BLOCK_TYPE_DPCC] =3D { - .size =3D sizeof(struct rkisp1_ext_params_dpcc_config), .handler =3D rkisp1_ext_params_dpcc, .group =3D RKISP1_EXT_PARAMS_BLOCK_GROUP_OTHERS, }, [RKISP1_EXT_PARAMS_BLOCK_TYPE_SDG] =3D { - .size =3D sizeof(struct rkisp1_ext_params_sdg_config), .handler =3D rkisp1_ext_params_sdg, .group =3D RKISP1_EXT_PARAMS_BLOCK_GROUP_OTHERS, }, [RKISP1_EXT_PARAMS_BLOCK_TYPE_AWB_GAIN] =3D { - .size =3D sizeof(struct rkisp1_ext_params_awb_gain_config), .handler =3D rkisp1_ext_params_awbg, .group =3D RKISP1_EXT_PARAMS_BLOCK_GROUP_OTHERS, }, [RKISP1_EXT_PARAMS_BLOCK_TYPE_FLT] =3D { - .size =3D sizeof(struct rkisp1_ext_params_flt_config), .handler =3D rkisp1_ext_params_flt, .group =3D RKISP1_EXT_PARAMS_BLOCK_GROUP_OTHERS, }, [RKISP1_EXT_PARAMS_BLOCK_TYPE_BDM] =3D { - .size =3D sizeof(struct rkisp1_ext_params_bdm_config), .handler =3D rkisp1_ext_params_bdm, .group =3D RKISP1_EXT_PARAMS_BLOCK_GROUP_OTHERS, }, [RKISP1_EXT_PARAMS_BLOCK_TYPE_CTK] =3D { - .size =3D sizeof(struct rkisp1_ext_params_ctk_config), .handler =3D rkisp1_ext_params_ctk, .group =3D RKISP1_EXT_PARAMS_BLOCK_GROUP_OTHERS, }, [RKISP1_EXT_PARAMS_BLOCK_TYPE_GOC] =3D { - .size =3D sizeof(struct rkisp1_ext_params_goc_config), .handler =3D rkisp1_ext_params_goc, .group =3D RKISP1_EXT_PARAMS_BLOCK_GROUP_OTHERS, }, [RKISP1_EXT_PARAMS_BLOCK_TYPE_DPF] =3D { - .size =3D sizeof(struct rkisp1_ext_params_dpf_config), .handler =3D rkisp1_ext_params_dpf, .group =3D RKISP1_EXT_PARAMS_BLOCK_GROUP_OTHERS, }, [RKISP1_EXT_PARAMS_BLOCK_TYPE_DPF_STRENGTH] =3D { - .size =3D sizeof(struct rkisp1_ext_params_dpf_strength_config), .handler =3D rkisp1_ext_params_dpfs, .group =3D RKISP1_EXT_PARAMS_BLOCK_GROUP_OTHERS, }, [RKISP1_EXT_PARAMS_BLOCK_TYPE_CPROC] =3D { - .size =3D sizeof(struct rkisp1_ext_params_cproc_config), .handler =3D rkisp1_ext_params_cproc, .group =3D RKISP1_EXT_PARAMS_BLOCK_GROUP_OTHERS, }, [RKISP1_EXT_PARAMS_BLOCK_TYPE_IE] =3D { - .size =3D sizeof(struct rkisp1_ext_params_ie_config), .handler =3D rkisp1_ext_params_ie, .group =3D RKISP1_EXT_PARAMS_BLOCK_GROUP_OTHERS, }, [RKISP1_EXT_PARAMS_BLOCK_TYPE_LSC] =3D { - .size =3D sizeof(struct rkisp1_ext_params_lsc_config), .handler =3D rkisp1_ext_params_lsc, .group =3D RKISP1_EXT_PARAMS_BLOCK_GROUP_LSC, }, [RKISP1_EXT_PARAMS_BLOCK_TYPE_AWB_MEAS] =3D { - .size =3D sizeof(struct rkisp1_ext_params_awb_meas_config), .handler =3D rkisp1_ext_params_awbm, .group =3D RKISP1_EXT_PARAMS_BLOCK_GROUP_OTHERS, }, [RKISP1_EXT_PARAMS_BLOCK_TYPE_HST_MEAS] =3D { - .size =3D sizeof(struct rkisp1_ext_params_hst_config), .handler =3D rkisp1_ext_params_hstm, .group =3D RKISP1_EXT_PARAMS_BLOCK_GROUP_OTHERS, }, [RKISP1_EXT_PARAMS_BLOCK_TYPE_AEC_MEAS] =3D { - .size =3D sizeof(struct rkisp1_ext_params_aec_config), .handler =3D rkisp1_ext_params_aecm, .group =3D RKISP1_EXT_PARAMS_BLOCK_GROUP_OTHERS, }, [RKISP1_EXT_PARAMS_BLOCK_TYPE_AFC_MEAS] =3D { - .size =3D sizeof(struct rkisp1_ext_params_afc_config), .handler =3D rkisp1_ext_params_afcm, .group =3D RKISP1_EXT_PARAMS_BLOCK_GROUP_OTHERS, }, [RKISP1_EXT_PARAMS_BLOCK_TYPE_COMPAND_BLS] =3D { - .size =3D sizeof(struct rkisp1_ext_params_compand_bls_config), .handler =3D rkisp1_ext_params_compand_bls, .group =3D RKISP1_EXT_PARAMS_BLOCK_GROUP_OTHERS, .features =3D RKISP1_FEATURE_COMPAND, }, [RKISP1_EXT_PARAMS_BLOCK_TYPE_COMPAND_EXPAND] =3D { - .size =3D sizeof(struct rkisp1_ext_params_compand_curve_config), .handler =3D rkisp1_ext_params_compand_expand, .group =3D RKISP1_EXT_PARAMS_BLOCK_GROUP_OTHERS, .features =3D RKISP1_FEATURE_COMPAND, }, [RKISP1_EXT_PARAMS_BLOCK_TYPE_COMPAND_COMPRESS] =3D { - .size =3D sizeof(struct rkisp1_ext_params_compand_curve_config), .handler =3D rkisp1_ext_params_compand_compress, .group =3D RKISP1_EXT_PARAMS_BLOCK_GROUP_OTHERS, .features =3D RKISP1_FEATURE_COMPAND, }, [RKISP1_EXT_PARAMS_BLOCK_TYPE_WDR] =3D { - .size =3D sizeof(struct rkisp1_ext_params_wdr_config), .handler =3D rkisp1_ext_params_wdr, .group =3D RKISP1_EXT_PARAMS_BLOCK_GROUP_OTHERS, }, }; =20 +static const struct v4l2_isp_params_block_info rkisp1_ext_params_blocks_in= fo[] =3D { + [RKISP1_EXT_PARAMS_BLOCK_TYPE_BLS] =3D { + .size =3D sizeof(struct rkisp1_ext_params_bls_config), + }, + [RKISP1_EXT_PARAMS_BLOCK_TYPE_DPCC] =3D { + .size =3D sizeof(struct rkisp1_ext_params_dpcc_config), + }, + [RKISP1_EXT_PARAMS_BLOCK_TYPE_SDG] =3D { + .size =3D sizeof(struct rkisp1_ext_params_sdg_config), + }, + [RKISP1_EXT_PARAMS_BLOCK_TYPE_AWB_GAIN] =3D { + .size =3D sizeof(struct rkisp1_ext_params_awb_gain_config), + }, + [RKISP1_EXT_PARAMS_BLOCK_TYPE_FLT] =3D { + .size =3D sizeof(struct rkisp1_ext_params_flt_config), + }, + [RKISP1_EXT_PARAMS_BLOCK_TYPE_BDM] =3D { + .size =3D sizeof(struct rkisp1_ext_params_bdm_config), + }, + [RKISP1_EXT_PARAMS_BLOCK_TYPE_CTK] =3D { + .size =3D sizeof(struct rkisp1_ext_params_ctk_config), + }, + [RKISP1_EXT_PARAMS_BLOCK_TYPE_GOC] =3D { + .size =3D sizeof(struct rkisp1_ext_params_goc_config), + }, + [RKISP1_EXT_PARAMS_BLOCK_TYPE_DPF] =3D { + .size =3D sizeof(struct rkisp1_ext_params_dpf_config), + }, + [RKISP1_EXT_PARAMS_BLOCK_TYPE_DPF_STRENGTH] =3D { + .size =3D sizeof(struct rkisp1_ext_params_dpf_strength_config), + }, + [RKISP1_EXT_PARAMS_BLOCK_TYPE_CPROC] =3D { + .size =3D sizeof(struct rkisp1_ext_params_cproc_config), + }, + [RKISP1_EXT_PARAMS_BLOCK_TYPE_IE] =3D { + .size =3D sizeof(struct rkisp1_ext_params_ie_config), + }, + [RKISP1_EXT_PARAMS_BLOCK_TYPE_LSC] =3D { + .size =3D sizeof(struct rkisp1_ext_params_lsc_config), + }, + [RKISP1_EXT_PARAMS_BLOCK_TYPE_AWB_MEAS] =3D { + .size =3D sizeof(struct rkisp1_ext_params_awb_meas_config), + }, + [RKISP1_EXT_PARAMS_BLOCK_TYPE_HST_MEAS] =3D { + .size =3D sizeof(struct rkisp1_ext_params_hst_config), + }, + [RKISP1_EXT_PARAMS_BLOCK_TYPE_AEC_MEAS] =3D { + .size =3D sizeof(struct rkisp1_ext_params_aec_config), + }, + [RKISP1_EXT_PARAMS_BLOCK_TYPE_AFC_MEAS] =3D { + .size =3D sizeof(struct rkisp1_ext_params_afc_config), + }, + [RKISP1_EXT_PARAMS_BLOCK_TYPE_COMPAND_BLS] =3D { + .size =3D sizeof(struct rkisp1_ext_params_compand_bls_config), + }, + [RKISP1_EXT_PARAMS_BLOCK_TYPE_COMPAND_EXPAND] =3D { + .size =3D sizeof(struct rkisp1_ext_params_compand_curve_config), + }, + [RKISP1_EXT_PARAMS_BLOCK_TYPE_COMPAND_COMPRESS] =3D { + .size =3D sizeof(struct rkisp1_ext_params_compand_curve_config), + }, + [RKISP1_EXT_PARAMS_BLOCK_TYPE_WDR] =3D { + .size =3D sizeof(struct rkisp1_ext_params_wdr_config), + }, +}; + static void rkisp1_ext_params_config(struct rkisp1_params *params, struct rkisp1_ext_params_cfg *cfg, u32 block_group_mask) @@ -2646,31 +2691,16 @@ static int rkisp1_params_prepare_ext_params(struct = rkisp1_params *params, { struct vb2_v4l2_buffer *vbuf =3D to_vb2_v4l2_buffer(vb); struct rkisp1_params_buffer *params_buf =3D to_rkisp1_params_buffer(vbuf); - size_t header_size =3D offsetof(struct rkisp1_ext_params_cfg, data); struct rkisp1_ext_params_cfg *cfg =3D params_buf->cfg; size_t payload_size =3D vb2_get_plane_payload(vb, 0); struct rkisp1_ext_params_cfg *usr_cfg =3D vb2_plane_vaddr(&vbuf->vb2_buf, 0); - size_t block_offset =3D 0; - size_t cfg_size; - - /* - * 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_isp_params_validate_buffer_size(params->rkisp1->dev, vb, + params->metafmt->buffersize); + if (ret) + return ret; =20 /* * Copy the parameters buffer to the internal scratch buffer to avoid @@ -2678,71 +2708,10 @@ static int rkisp1_params_prepare_ext_params(struct = rkisp1_params *params, */ memcpy(cfg, usr_cfg, payload_size); =20 - /* Only v1 is supported at the moment. */ - if (cfg->version !=3D RKISP1_EXT_PARAM_BUFFER_V1) { - dev_dbg(params->rkisp1->dev, - "Unsupported extensible format version: %u\n", - cfg->version); - return -EINVAL; - } - - /* Validate the size reported in the parameters buffer header. */ - cfg_size =3D header_size + cfg->data_size; - if (cfg_size !=3D payload_size) { - dev_dbg(params->rkisp1->dev, - "Data size %zu different than buffer payload size %zu\n", - cfg_size, payload_size); - return -EINVAL; - } - - /* Walk the list of parameter blocks and validate them. */ - cfg_size =3D cfg->data_size; - while (cfg_size >=3D sizeof(struct rkisp1_ext_params_block_header)) { - const struct rkisp1_ext_params_block_header *block; - const struct rkisp1_ext_params_handler *handler; - - block =3D (const struct rkisp1_ext_params_block_header *) - &cfg->data[block_offset]; - - if (block->type >=3D ARRAY_SIZE(rkisp1_ext_params_handlers)) { - dev_dbg(params->rkisp1->dev, - "Invalid parameters block type\n"); - return -EINVAL; - } - - if (block->size > cfg_size) { - dev_dbg(params->rkisp1->dev, - "Premature end of parameters data\n"); - return -EINVAL; - } - - if ((block->flags & (RKISP1_EXT_PARAMS_FL_BLOCK_ENABLE | - RKISP1_EXT_PARAMS_FL_BLOCK_DISABLE)) =3D=3D - (RKISP1_EXT_PARAMS_FL_BLOCK_ENABLE | - RKISP1_EXT_PARAMS_FL_BLOCK_DISABLE)) { - dev_dbg(params->rkisp1->dev, - "Invalid parameters block flags\n"); - return -EINVAL; - } - - handler =3D &rkisp1_ext_params_handlers[block->type]; - if (block->size !=3D handler->size) { - dev_dbg(params->rkisp1->dev, - "Invalid parameters block size\n"); - return -EINVAL; - } - - block_offset +=3D block->size; - cfg_size -=3D block->size; - } - - if (cfg_size) { - dev_dbg(params->rkisp1->dev, - "Unexpected data after the parameters buffer end\n"); - return -EINVAL; - } - - return 0; + return v4l2_isp_params_validate_buffer(params->rkisp1->dev, vb, + (struct v4l2_isp_params_buffer *)cfg, + rkisp1_ext_params_blocks_info, + ARRAY_SIZE(rkisp1_ext_params_blocks_info)); } =20 static int rkisp1_params_vb2_buf_prepare(struct vb2_buffer *vb) --=20 2.51.0 From nobody Fri Dec 19 17:14:24 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 7B56F30FC20; Tue, 14 Oct 2025 08:01:30 +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=1760428892; cv=none; b=IWAbcDP8GBqnTZFEM4fts/KSfOmKdxL2ELnkPxVLBbcX9aiaqcgmrg9I1NBr9qRwa+N+jw2Iy5SzzRgl71mER814pG1yvLqV4tuHZrvbTalKWmAbKmuLhSvhY8KfQ7VWXNPl/r+RLyWWOjz9J2UgZPw4abid/MUNpaKL4nEeYuI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760428892; c=relaxed/simple; bh=Rcnbc5GQWRE3nXnwQde2olvlVlFTfb1KEB0nxjBJ878=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=IUZ1zN2477WFIoln6wpI5KobftSq6TxZoJ3iZpFFQfYwY+YF54imBwEKC5kJUxfMh9A2uQK/EelNGLJ2sbY6Ss68/WtJIZxKUM43CbLWPdn9cr+2jEhZXP0fCx+XNJ/o5LRjqHAt/7AWNGrdcwSr0MeM1cHZSIDt3q8+naME6ak= 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=hX+rENfy; 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="hX+rENfy" Received: from [192.168.1.182] (93-46-82-201.ip106.fastwebnet.it [93.46.82.201]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 8B88411DA; Tue, 14 Oct 2025 09:59:37 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1760428778; bh=Rcnbc5GQWRE3nXnwQde2olvlVlFTfb1KEB0nxjBJ878=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=hX+rENfyd48m5NJj6fK8yOr/XLRVn5VlH3Q70OBiota80jLxoTe1+QzEIUkQHCF94 z1xqGHyiVEAIG1BN69jWQMqlX1nsPVvgSi7VYh8kY7IhS/eR8UAfV1RkxACN4aNHW3 K7Iy0zhWG4Xfq0QnJx0GDHdwZcHeIMPRzGUxP4S0= From: Jacopo Mondi Date: Tue, 14 Oct 2025 10:00:59 +0200 Subject: [PATCH v7 7/8] media: amlogic-c3: Use v4l2-isp for validation Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20251014-extensible-parameters-validation-v7-7-6628bed5ca98@ideasonboard.com> References: <20251014-extensible-parameters-validation-v7-0-6628bed5ca98@ideasonboard.com> In-Reply-To: <20251014-extensible-parameters-validation-v7-0-6628bed5ca98@ideasonboard.com> To: Dafna Hirschfeld , Laurent Pinchart , Keke Li , Mauro Carvalho Chehab , Heiko Stuebner , Dan Scally , Sakari Ailus , Antoine Bouyer Cc: linux-kernel@vger.kernel.org, linux-media@vger.kernel.org, linux-rockchip@lists.infradead.org, linux-arm-kernel@lists.infradead.org, Jacopo Mondi X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=8121; i=jacopo.mondi@ideasonboard.com; h=from:subject:message-id; bh=Rcnbc5GQWRE3nXnwQde2olvlVlFTfb1KEB0nxjBJ878=; b=owEBbQKS/ZANAwAKAXI0Bo8WoVY8AcsmYgBo7gNHTlxyaJDla9v2J2v74o6KyKj76iqmIbGhj PamIRFcAmWJAjMEAAEKAB0WIQS1xD1IgJogio9YOMByNAaPFqFWPAUCaO4DRwAKCRByNAaPFqFW PBoeEACy4dVmrdtK5jWTpaNcpFTDUWYZAT7ridVb0769G+VL0kqxP1nNmzBLlMsflF0Ua1jRQkR +qXOK4Ewx27bEj7yOhxfczZnQIf+1+6ffTwl2e9aoTeef4GYMsM/z8yJwHVk1cy7P7LRACIcncD Wrp/df6lxR7r2cKaP7VQk0egXsB8C0MHhfr8WhbNXSU2daLLKU0JpC/4/ZqmeO+tLIWgp7tNQpz NsS1XPrl2wd4noRJN70mUUs5xZAMamGz0EC8CjeYZawqCN1zyxVmI4MGqaBxcmzIr4sKsbXelDU 5zUysWzkimqHsVu9FLPpne85I2K988h9gBa3NDvOUo903cFn2HHymX876XJzjaEY8F8YPBGkt9r QnLZDStm25J/lzH4gTo732bDX/fpSVoUUZb8wNDXmi/acbfMyF0rFJl2hq6UAzAQuEMkkmGdnbm q2i0McaNMrjXBfad4MmVGejwVTcNhhok9NaUJOluXxRTmCjdUoR+o9tcOcJSkfKLlRhYtdaaZHG vHIQ7Wbper+pVORzQTasqieOh3W3e3OLdEtMnWx9iAt5tyiBwnWCBFz2Tv5WCxRkT4VOkO8FdOP VLgSDZ/ullhKbvKrYU0a2GuzHUEo5aWDDUXPrkk3aWYkvae6rxC8dLmFYnww01dWgBgJnBnJfGF i0l3JYOgWcV3A3Q== X-Developer-Key: i=jacopo.mondi@ideasonboard.com; a=openpgp; fpr=72392EDC88144A65C701EA9BA5826A2587AD026B Convert c3-isp-params.c to use the helpers defined in v4l2-isp.h to perform validation of a ISP parameters buffer. Reviewed-by: Keke Li Reviewed-by: Daniel Scally Signed-off-by: Jacopo Mondi --- drivers/media/platform/amlogic/c3/isp/Kconfig | 1 + .../media/platform/amlogic/c3/isp/c3-isp-params.c | 124 +++++------------= ---- 2 files changed, 27 insertions(+), 98 deletions(-) diff --git a/drivers/media/platform/amlogic/c3/isp/Kconfig b/drivers/media/= platform/amlogic/c3/isp/Kconfig index 02c62a50a5e88eac665e27abf163e5d654faed3f..809208cd7e3aa7ca0821cb07366= ec73a47edb278 100644 --- a/drivers/media/platform/amlogic/c3/isp/Kconfig +++ b/drivers/media/platform/amlogic/c3/isp/Kconfig @@ -10,6 +10,7 @@ config VIDEO_C3_ISP select VIDEO_V4L2_SUBDEV_API select VIDEOBUF2_DMA_CONTIG select VIDEOBUF2_VMALLOC + select V4L2_ISP help Video4Linux2 driver for Amlogic C3 ISP pipeline. The C3 ISP is used for processing raw images and diff --git a/drivers/media/platform/amlogic/c3/isp/c3-isp-params.c b/driver= s/media/platform/amlogic/c3/isp/c3-isp-params.c index c80667dd766210d2b2e1ee60c8254a5814b9d81b..0e031d64de312cfdf0a52a46f70= edbaf07563359 100644 --- a/drivers/media/platform/amlogic/c3/isp/c3-isp-params.c +++ b/drivers/media/platform/amlogic/c3/isp/c3-isp-params.c @@ -8,6 +8,7 @@ #include =20 #include +#include #include #include =20 @@ -51,11 +52,6 @@ union c3_isp_params_block { typedef void (*c3_isp_block_handler)(struct c3_isp_device *isp, const union c3_isp_params_block *block); =20 -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 @@ -523,38 +519,41 @@ static void c3_isp_params_cfg_blc(struct c3_isp_devic= e *isp, ISP_TOP_BEO_CTRL_BLC_EN); } =20 -static const struct c3_isp_params_handler c3_isp_params_handlers[] =3D { +static const c3_isp_block_handler c3_isp_params_handlers[] =3D { + [C3_ISP_PARAMS_BLOCK_AWB_GAINS] =3D c3_isp_params_cfg_awb_gains, + [C3_ISP_PARAMS_BLOCK_AWB_CONFIG] =3D c3_isp_params_cfg_awb_config, + [C3_ISP_PARAMS_BLOCK_AE_CONFIG] =3D c3_isp_params_cfg_ae_config, + [C3_ISP_PARAMS_BLOCK_AF_CONFIG] =3D c3_isp_params_cfg_af_config, + [C3_ISP_PARAMS_BLOCK_PST_GAMMA] =3D c3_isp_params_cfg_pst_gamma, + [C3_ISP_PARAMS_BLOCK_CCM] =3D c3_isp_params_cfg_ccm, + [C3_ISP_PARAMS_BLOCK_CSC] =3D c3_isp_params_cfg_csc, + [C3_ISP_PARAMS_BLOCK_BLC] =3D c3_isp_params_cfg_blc, +}; + +static const struct v4l2_isp_params_block_info c3_isp_params_blocks_info[]= =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, }, [C3_ISP_PARAMS_BLOCK_AWB_CONFIG] =3D { .size =3D sizeof(struct c3_isp_params_awb_config), - .handler =3D c3_isp_params_cfg_awb_config, }, [C3_ISP_PARAMS_BLOCK_AE_CONFIG] =3D { .size =3D sizeof(struct c3_isp_params_ae_config), - .handler =3D c3_isp_params_cfg_ae_config, }, [C3_ISP_PARAMS_BLOCK_AF_CONFIG] =3D { .size =3D sizeof(struct c3_isp_params_af_config), - .handler =3D c3_isp_params_cfg_af_config, }, [C3_ISP_PARAMS_BLOCK_PST_GAMMA] =3D { .size =3D sizeof(struct c3_isp_params_pst_gamma), - .handler =3D c3_isp_params_cfg_pst_gamma, }, [C3_ISP_PARAMS_BLOCK_CCM] =3D { .size =3D sizeof(struct c3_isp_params_ccm), - .handler =3D c3_isp_params_cfg_ccm, }, [C3_ISP_PARAMS_BLOCK_CSC] =3D { .size =3D sizeof(struct c3_isp_params_csc), - .handler =3D c3_isp_params_cfg_csc, }, [C3_ISP_PARAMS_BLOCK_BLC] =3D { .size =3D sizeof(struct c3_isp_params_blc), - .handler =3D c3_isp_params_cfg_blc, }, }; =20 @@ -568,14 +567,14 @@ 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; + c3_isp_block_handler block_handler; =20 block =3D (const union c3_isp_params_block *) &config->data[block_offset]; =20 - block_handler =3D &c3_isp_params_handlers[block->header.type]; - block_handler->handler(params->isp, block); + block_handler =3D c3_isp_params_handlers[block->header.type]; + block_handler(params->isp, block); =20 block_offset +=3D block->header.size; } @@ -771,26 +770,15 @@ static int c3_isp_params_vb2_buf_prepare(struct vb2_b= uffer *vb) struct vb2_v4l2_buffer *vbuf =3D to_vb2_v4l2_buffer(vb); struct c3_isp_params_buffer *buf =3D to_c3_isp_params_buffer(vbuf); struct c3_isp_params *params =3D vb2_get_drv_priv(vb->vb2_queue); - struct c3_isp_params_cfg *cfg =3D buf->cfg; struct c3_isp_params_cfg *usr_cfg =3D vb2_plane_vaddr(vb, 0); size_t payload_size =3D vb2_get_plane_payload(vb, 0); - size_t header_size =3D offsetof(struct c3_isp_params_cfg, data); - size_t block_offset =3D 0; - size_t cfg_size; - - /* 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_isp_params_validate_buffer_size(params->isp->dev, vb, + params->vfmt.fmt.meta.buffersize); + if (ret) + return ret; =20 /* * Use the internal scratch buffer to avoid userspace modifying @@ -798,70 +786,10 @@ static int c3_isp_params_vb2_buf_prepare(struct vb2_b= uffer *vb) */ memcpy(cfg, usr_cfg, payload_size); =20 - /* Only v0 is supported at the moment */ - if (cfg->version !=3D C3_ISP_PARAMS_BUFFER_V0) { - dev_dbg(params->isp->dev, - "Invalid params buffer version: %u\n", cfg->version); - return -EINVAL; - } - - /* Validate the size reported in the parameter buffer header */ - cfg_size =3D header_size + cfg->data_size; - if (cfg_size !=3D payload_size) { - dev_dbg(params->isp->dev, - "Data size %zu and payload size %zu are different\n", - cfg_size, payload_size); - return -EINVAL; - } - - /* Walk the list of parameter blocks and validate them */ - cfg_size =3D cfg->data_size; - while (cfg_size >=3D sizeof(struct c3_isp_params_block_header)) { - const struct c3_isp_params_block_header *block; - const struct c3_isp_params_handler *handler; - - block =3D (struct c3_isp_params_block_header *) - &cfg->data[block_offset]; - - if (block->type >=3D ARRAY_SIZE(c3_isp_params_handlers)) { - dev_dbg(params->isp->dev, - "Invalid params block type\n"); - return -EINVAL; - } - - if (block->size > cfg_size) { - dev_dbg(params->isp->dev, - "Block size is greater than cfg size\n"); - return -EINVAL; - } - - if ((block->flags & (C3_ISP_PARAMS_BLOCK_FL_ENABLE | - C3_ISP_PARAMS_BLOCK_FL_DISABLE)) =3D=3D - (C3_ISP_PARAMS_BLOCK_FL_ENABLE | - C3_ISP_PARAMS_BLOCK_FL_DISABLE)) { - dev_dbg(params->isp->dev, - "Invalid parameters block flags\n"); - return -EINVAL; - } - - handler =3D &c3_isp_params_handlers[block->type]; - if (block->size !=3D handler->size) { - dev_dbg(params->isp->dev, - "Invalid params block size\n"); - return -EINVAL; - } - - block_offset +=3D block->size; - cfg_size -=3D block->size; - } - - if (cfg_size) { - dev_dbg(params->isp->dev, - "Unexpected data after the params buffer end\n"); - return -EINVAL; - } - - return 0; + return v4l2_isp_params_validate_buffer(params->isp->dev, vb, + (struct v4l2_isp_params_buffer *)cfg, + c3_isp_params_blocks_info, + ARRAY_SIZE(c3_isp_params_blocks_info)); } =20 static int c3_isp_params_vb2_buf_init(struct vb2_buffer *vb) --=20 2.51.0 From nobody Fri Dec 19 17:14:24 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 B4F0B30FC34; Tue, 14 Oct 2025 08:01:31 +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=1760428893; cv=none; b=qpw6CF+LDlg2awd0OhlBRGNaeUds+AIbl+4DiOn+32vXTbNMOJ+xBqu/vlFMjpqEdU+ZXdp+nWsnMlWQPHRWohSNvdEbmd/p5Rlt/1G9wrjJ+HRc15kqQpcXy5eC029HgBjUg8PQKZOof7XWQQUSCKC78EeKwgO4Uu02fh+xgYM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760428893; c=relaxed/simple; bh=6nIA8PMBxNyMFZpIPqZNTn55txgmaas6G6JxqTpnEHo=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=V8xwNDnBQ/dyPCLOvabNaWR70uE+vNg9DQGOnF4y0fibyDsiH96x8u3XLaVjiav80uQg15PvAJRqc9OpYioHHkB8/5YZH3zOIw+nEUhdEER9O+cI7Xqsm0Lc9fi3lGE9aON1LD1gzYAwiPaoJfmqbb3aYktCOiDRcXaadcjmH2c= 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=KOq5kxys; 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="KOq5kxys" Received: from [192.168.1.182] (93-46-82-201.ip106.fastwebnet.it [93.46.82.201]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 214F711DD; Tue, 14 Oct 2025 09:59:38 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1760428778; bh=6nIA8PMBxNyMFZpIPqZNTn55txgmaas6G6JxqTpnEHo=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=KOq5kxys/GQVjZaTmVcPbI7GlewLn7ndBht/nkIoU/Pp9XZpzmb6zeqwvlPtTP0c2 x2x2x500os0ib8eIcMQX8Jgw7GeoD0QDW895QAfUaAh8gotqvC4ExvPiWsixN27Iiu y4tKDd3lBfsmaueDRK+tGmKyLovK1Y8dQ9OVE+uQ= From: Jacopo Mondi Date: Tue, 14 Oct 2025 10:01:00 +0200 Subject: [PATCH v7 8/8] media: Documentation: kapi: Add v4l2 generic ISP support Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20251014-extensible-parameters-validation-v7-8-6628bed5ca98@ideasonboard.com> References: <20251014-extensible-parameters-validation-v7-0-6628bed5ca98@ideasonboard.com> In-Reply-To: <20251014-extensible-parameters-validation-v7-0-6628bed5ca98@ideasonboard.com> To: Dafna Hirschfeld , Laurent Pinchart , Keke Li , Mauro Carvalho Chehab , Heiko Stuebner , Dan Scally , Sakari Ailus , Antoine Bouyer Cc: linux-kernel@vger.kernel.org, linux-media@vger.kernel.org, linux-rockchip@lists.infradead.org, linux-arm-kernel@lists.infradead.org, Jacopo Mondi X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=4037; i=jacopo.mondi@ideasonboard.com; h=from:subject:message-id; bh=6nIA8PMBxNyMFZpIPqZNTn55txgmaas6G6JxqTpnEHo=; b=owEBbQKS/ZANAwAKAXI0Bo8WoVY8AcsmYgBo7gNHjvfYwLqh8xguj4uruLNRXZauUpFikLfZE 0nOZoHG6R2JAjMEAAEKAB0WIQS1xD1IgJogio9YOMByNAaPFqFWPAUCaO4DRwAKCRByNAaPFqFW PAEcD/9+utt/ZXzF0biLyHM02WwO32AyOewfdWDaVTIeh8P+7PWTZGaoESXUtbB9ms+ZrnY80cd RsSwZlxkVwah7tnGqiEtgTnVi5uhuhVL09w0ueV7EOXYcwEmI/GlcW1ri4cZLrKPj2oP/d2+gOu cK1qizym1P0R8+O4MUrVWTRiyqZiRdXUZYcHkxojLiSWRmg7Rd+nwf1BkwgvJiNuSi9oQuTHejJ tYuE06/EAfAtu6L69lxbt/hpbXHOh8wtQnsK/EzbU1qmMj4QdnrczmxEQlWH5PrRGJZ11sCaChd Op8akjgIzC/BnV754MalKFo/+DKyIOf6jbD3aMSaWTfKvvw9iD8v3kd1Z0eWZXfXEkWTnz2LVmz K/BVuGlI5a5VRpc0CY64HmNQh6j+qQDR1EWNsN7vNY2h+1f3Cpyxau2FVvrxHCpMDFLFybVIioh FIyWQc1jnCiGMdxcwv8wdI1MGK/kiMsdCYXXovIFLmll3qrKnuE4J7QBDLIy6lTSYyU4PTY6kx/ iRa3a6NNqxlK4d+z+9ZFc5uA1OprvNT+baMKKS1ywW4zSf0KDuAYyeKLdC7I0ZSPClZdEYKMYYI 2J2jh5qkIf0J1D2RgDG3hrT4wkERipEQE4vLfi2sLd5W+AMCqYifM5M85oeVn9nYz9exyi2+EZ+ 3xUs9y3ZEtl56YA== X-Developer-Key: i=jacopo.mondi@ideasonboard.com; a=openpgp; fpr=72392EDC88144A65C701EA9BA5826A2587AD026B Add to the driver-api documentation the v4l2-isp.h types and helpers documentation. Reviewed-by: Daniel Scally Signed-off-by: Jacopo Mondi --- Documentation/driver-api/media/v4l2-core.rst | 1 + Documentation/driver-api/media/v4l2-isp.rst | 49 ++++++++++++++++++++++++= ++++ MAINTAINERS | 1 + 3 files changed, 51 insertions(+) diff --git a/Documentation/driver-api/media/v4l2-core.rst b/Documentation/d= river-api/media/v4l2-core.rst index ad987c34ad2a8460bb95e97adc4d850d624e0b81..a5f5102c64cca57b57b54ab9588= 2b26286fb27de 100644 --- a/Documentation/driver-api/media/v4l2-core.rst +++ b/Documentation/driver-api/media/v4l2-core.rst @@ -27,3 +27,4 @@ Video4Linux devices v4l2-common v4l2-tveeprom v4l2-jpeg + v4l2-isp diff --git a/Documentation/driver-api/media/v4l2-isp.rst b/Documentation/dr= iver-api/media/v4l2-isp.rst new file mode 100644 index 0000000000000000000000000000000000000000..42c2550602979609e92a09e3cd1= fe3dcbafd6416 --- /dev/null +++ b/Documentation/driver-api/media/v4l2-isp.rst @@ -0,0 +1,49 @@ +.. SPDX-License-Identifier: GPL-2.0 + +V4L2 generic ISP parameters and statistics support +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +Design rationale +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +ISP configuration parameters and statistics are processed and collected by +drivers and exchanged with userspace through data types that usually +reflect the ISP peripheral registers layout. + +Each ISP driver defines its own metadata capture format for parameters and +a metadata output format for statistics. The buffer layout is realized by a +set of C structures that reflects the registers layout. The number and typ= es +of C structures is fixed by the format definition and becomes part of the = Linux +kernel uAPI/uABI interface. + +Because of the hard requirement of backward compatibility when extending t= he +user API/ABI interface, modifying an ISP driver capture or output metadata +format after it has been accepted by mainline is very hard if not impossib= le. + +It generally happens, in facts, that after the first accepted revision of = an +ISP driver the buffer layout need to be modified, either to support new ha= rdware +blocks, fix bugs found later on or support different revisions of the same= IP. + +Each of these situation would require defining a new metadata format, maki= ng it +really hard to maintain and extend drivers and requiring userspace to use a +the correct format depending on the kernel revision in use. + +V4L2 ISP configuration parameters +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D + +For these reasons, Video4Linux2 defines generic types for ISP configuration +parameters and statistics. Drivers are still expected to define their own +formats for their metadata output and capture nodes, but the buffer layout= can +be defined using the extensible and versioned types defined by +include/uapi/linux/media/v4l2-isp.h. + +Drivers are expected to provide the definitions of their supported ISP blo= cks, +the control flags and the expected maximum size of a buffer. + +For driver developers a set of helper functions to assist them with valida= tion +of the buffer received from userspace is available in the form of helper +functions in drivers/media/v4l2-core/v4l2-isp.c + +V4L2 ISP support driver documentation +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D +.. kernel-doc:: include/media/v4l2-isp.h diff --git a/MAINTAINERS b/MAINTAINERS index 59ab4a34f72c0430a8d7966942acb2242ad923ca..3cc24092995bcb01051cc301ca2= 12c32938cf745 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -26857,6 +26857,7 @@ V4L2 GENERIC ISP PARAMETERS AND STATISTIC FORMATS M: Jacopo Mondi L: linux-media@vger.kernel.org S: Maintained +F: Documentation/driver-api/media/v4l2-isp.rst F: Documentation/userspace-api/media/v4l/v4l2-isp.rst F: drivers/media/v4l2-core/v4l2-isp.c F: include/media/v4l2-isp.h --=20 2.51.0