* [PATCH 0/6] media: v4l2-isp: Add support for extensible statistics
@ 2026-05-05 14:12 Jacopo Mondi
2026-05-05 14:12 ` [PATCH 1/6] media: uapi: v4l2-isp: Add " Jacopo Mondi
` (6 more replies)
0 siblings, 7 replies; 8+ messages in thread
From: Jacopo Mondi @ 2026-05-05 14:12 UTC (permalink / raw)
To: Mauro Carvalho Chehab, Daniel Scally, Keke Li, Antoine Bouyer,
Jai Luthra, Niklas Söderlund, Ricardo Ribalda
Cc: Laurent Pinchart, Sakari Ailus, Hans Verkuil, linux-media,
linux-kernel, Jacopo Mondi
This series breaks out from Antonie's
https://patchwork.linuxtv.org/project/linux-media/list/?series=24043
the extensible stats support and adds a few more patches on top to:
- add support for per-block validation as suggested during the review of
Ricardo's
https://patchwork.linuxtv.org/project/linux-media/patch/20260504-smatch-7-1-v3-6-fda125c30058@chromium.org/
- add two helper functions to v4l2-isp to ease handling of extensible
statistics for drivers. An early user, based on a preliminary version
of the patches is available here as a reference:
https://patchwork.linuxtv.org/project/linux-media/list/?series=24703
Antonie: I took the liberty to fold in your patches changes to address
my comments on your v1. I pushed an un-squased version of the patches
here:
https://gitlab.freedesktop.org/linux-media/users/jmondi/-/tree/b4/extensible-stats-unsquashed
so you can easily get the diff from this and your version. Please feel
free to comment on these as you're the original author.
Signed-off-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
---
Antoine Bouyer (2):
media: uapi: v4l2-isp: Add extensible statistics
media: Documentation: uapi: Update V4L2 ISP for extensible stats
Jacopo Mondi (4):
media: v4l2-isp: Rename v4l2_isp_params_buffer_size
media: v4l2-isp: Add per-block validation callback
media: amlogic-c3: Implement per-block validation
media: v4l2-isp: Add helpers for stats buffer
Documentation/userspace-api/media/v4l/v4l2-isp.rst | 45 ++++++--
.../media/platform/amlogic/c3/isp/c3-isp-params.c | 42 ++++++-
.../media/platform/arm/mali-c55/mali-c55-params.c | 12 +-
drivers/media/v4l2-core/v4l2-isp.c | 56 +++++++++
include/media/v4l2-isp.h | 94 +++++++++++++---
include/uapi/linux/media/v4l2-isp.h | 125 +++++++++++++--------
6 files changed, 294 insertions(+), 80 deletions(-)
---
base-commit: d9c8c4adf23d17549c0ec9c85b99d85a0ee6cf18
change-id: 20260504-extensible-stats-f2d6befcc1ce
Best regards,
--
Jacopo Mondi <jacopo.mondi@ideasonboard.com>
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH 1/6] media: uapi: v4l2-isp: Add extensible statistics
2026-05-05 14:12 [PATCH 0/6] media: v4l2-isp: Add support for extensible statistics Jacopo Mondi
@ 2026-05-05 14:12 ` Jacopo Mondi
2026-05-05 14:12 ` [PATCH 2/6] media: Documentation: uapi: Update V4L2 ISP for extensible stats Jacopo Mondi
` (5 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: Jacopo Mondi @ 2026-05-05 14:12 UTC (permalink / raw)
To: Mauro Carvalho Chehab, Daniel Scally, Keke Li, Antoine Bouyer,
Jai Luthra, Niklas Söderlund, Ricardo Ribalda
Cc: Laurent Pinchart, Sakari Ailus, Hans Verkuil, linux-media,
linux-kernel, Jacopo Mondi
From: Antoine Bouyer <antoine.bouyer@nxp.com>
Extend the v4l2-isp extensible format introduced for isp parameters buffers
to the support buffers of ISP statistic.
Like for ISP configuration purpose, that will help supporting various ISP
hardware versions reporting different statistics data with less impact on
userspace.
Rename all 'v4l2_isp_params' types to generic 'v4l2_isp' types to
prepare to use them for statistics as well and maintain the existing
types for compatibility with existing userspace only.
Signed-off-by: Antoine Bouyer <antoine.bouyer@nxp.com>
[Rework to remove 'v4l2_isp_stats' and unify types]
Signed-off-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
---
include/uapi/linux/media/v4l2-isp.h | 125 +++++++++++++++++++++++-------------
1 file changed, 79 insertions(+), 46 deletions(-)
diff --git a/include/uapi/linux/media/v4l2-isp.h b/include/uapi/linux/media/v4l2-isp.h
index 779168f9058e..e4607e1217e1 100644
--- a/include/uapi/linux/media/v4l2-isp.h
+++ b/include/uapi/linux/media/v4l2-isp.h
@@ -13,25 +13,33 @@
#include <linux/types.h>
/**
- * enum v4l2_isp_params_version - V4L2 ISP parameters versioning
+ * enum v4l2_isp_version - V4L2 ISP serialization format versioning
*
- * @V4L2_ISP_PARAMS_VERSION_V0: First version of the V4L2 ISP parameters format
- * (for compatibility)
- * @V4L2_ISP_PARAMS_VERSION_V1: First version of the V4L2 ISP parameters format
+ * @V4L2_ISP_VERSION_V0: First version of the V4L2 ISP serialization format
+ * (for compatibility)
+ * @V4L2_ISP_VERSION_V1: First version of the V4L2 ISP serialization format
*
* 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 their
- * versioning identifier. Both V0 and V1 refers to the first version of the
- * V4L2 ISP parameters format.
+ * ISP format already upstreamed which use either 0 or 1 as their versioning
+ * identifier. Both V0 and V1 refers to the first version of the V4L2 ISP
+ * serialization format.
*
- * Future revisions of the V4L2 ISP parameters format should start from the
+ * Future revisions of the V4L2 ISP serialization format should start from the
* value of 2.
*/
-enum v4l2_isp_params_version {
- V4L2_ISP_PARAMS_VERSION_V0 = 0,
- V4L2_ISP_PARAMS_VERSION_V1
+enum v4l2_isp_version {
+ V4L2_ISP_VERSION_V0 = 0,
+ V4L2_ISP_VERSION_V1
};
+/*
+ * Compatibility with existing users of v4l2_isp_params which pre-date the
+ * introduction of v4l2_isp_stats.
+ */
+#define v4l2_isp_params_version v4l2_isp_version
+#define V4L2_ISP_PARAMS_VERSION_V0 V4L2_ISP_VERSION_V0
+#define V4L2_ISP_PARAMS_VERSION_V1 V4L2_ISP_VERSION_V1
+
#define V4L2_ISP_PARAMS_FL_BLOCK_DISABLE (1U << 0)
#define V4L2_ISP_PARAMS_FL_BLOCK_ENABLE (1U << 1)
@@ -39,64 +47,89 @@ enum v4l2_isp_params_version {
* 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_FLAGS(0))
- * #define DRIVER_SPECIFIC_FLAG1 ((1U << V4L2_ISP_PARAMS_FL_DRIVER_FLAGS(1))
+ * #define DRIVER_SPECIFIC_FLAG0 ((1U << V4L2_ISP_FL_DRIVER_FLAGS(0))
+ * #define DRIVER_SPECIFIC_FLAG1 ((1U << V4L2_ISP_FL_DRIVER_FLAGS(1))
*/
-#define V4L2_ISP_PARAMS_FL_DRIVER_FLAGS(n) ((n) + 8)
+#define V4L2_ISP_FL_DRIVER_FLAGS(n) ((n) + 8)
/**
- * struct v4l2_isp_params_block_header - V4L2 extensible parameters block header
- * @type: The parameters block type (driver-specific)
+ * struct v4l2_isp_block_header - V4L2 extensible block header
+ * @type: The parameters or statistics block type (driver-specific)
* @flags: A bitmask of block flags (driver-specific)
- * @size: Size (in bytes) of the parameters block, including this header
+ * @size: Size (in bytes) of the 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.
+ * This structure represents the common part of all the ISP configuration or
+ * statistic blocks. Each block shall embed an instance of this structure type
+ * as its first member, followed by the block-specific configuration or
+ * statistic data.
*
* The @type field is an ISP driver-specific value that identifies the block
- * type. The @size field specifies the size of the parameters block.
+ * type. The @size field specifies the size of the block, including this
+ * header.
*
- * The @flags field is a bitmask of per-block flags V4L2_PARAMS_ISP_FL_* and
- * driver-specific flags specified by the driver header.
+ * The @flags field is a bitmask of per-block flags. If a block is used for
+ * configuration parameters this field can be a combination of
+ * V4L2_ISP_PARAMS_FL_* and driver-specific flags. If a block is used
+ * for statistics this fields is used to report optional
+ * driver-specific flags, if any.
*/
-struct v4l2_isp_params_block_header {
+struct v4l2_isp_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
+ * v4l2_isp_params_block_header - V4L2 extensible parameters block header
+ *
+ * Compatibility with existing users of v4l2_isp_params_block_header
+ * which pre-date the introduction of v4l2_isp_block_header.
+ */
+#define v4l2_isp_params_block_header v4l2_isp_block_header
+
+/**
+ * struct v4l2_isp_buffer - V4L2 extensible buffer
+ * @version: The extensible buffer version (driver-specific)
+ * @data_size: The data effective size, excluding this header
+ * @data: The configuration or statistics data
*
- * This structure contains the configuration parameters of the ISP algorithms,
- * serialized by userspace into a data buffer. Each configuration parameter
- * block is represented by a block-specific structure which contains a
- * :c:type:`v4l2_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 size
- * changes according to the number of ISP blocks that userspace intends to
- * configure and is set by userspace in the @data_size field.
+ * This structure contains ISP configuration parameters or ISP hardware
+ * statistics serialized into a data buffer. Each block is represented by a
+ * block-specific structure which contains a :c:type:`v4l2_isp_block_header`
+ * entry as first member.
*
- * The parameters buffer is versioned by the @version field to allow modifying
- * and extending its definition. Userspace shall populate the @version field 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
+ * When used for ISP parameters, userspace populates the @data buffer with
+ * configuration parameters 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.
+ *
+ * When used to report ISP statistics, the driver populates the @data buffer
+ * with statistics for each supported measurement block.
+ *
+ * The buffer is versioned by the @version field to allow modifying
+ * and extending its definition. The writer shall populate the @version field
+ * to inform the reader about the version it intends to use. The reader 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 effective
- * size, in bytes, of the @data buffer.
+ * For each ISP block, a block-specific structure is appended to the @data
+ * buffer, one after the other without gaps in between. The writer shall
+ * populate the @data_size field with the effective size, in bytes, of the
+ * @data buffer.
*/
-struct v4l2_isp_params_buffer {
+struct v4l2_isp_buffer {
__u32 version;
__u32 data_size;
__u8 data[] __counted_by(data_size);
};
+/**
+ * v4l2_isp_params_buffer - V4L2 extensible parameters compatibility
+ *
+ * Compatibility with existing users of v4l2_isp_params_buffer which
+ * pre-date the introduction of v4l2_isp_buffer.
+ */
+#define v4l2_isp_params_buffer v4l2_isp_buffer
+
#endif /* _UAPI_V4L2_ISP_H_ */
--
2.53.0
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH 2/6] media: Documentation: uapi: Update V4L2 ISP for extensible stats
2026-05-05 14:12 [PATCH 0/6] media: v4l2-isp: Add support for extensible statistics Jacopo Mondi
2026-05-05 14:12 ` [PATCH 1/6] media: uapi: v4l2-isp: Add " Jacopo Mondi
@ 2026-05-05 14:12 ` Jacopo Mondi
2026-05-05 14:12 ` [PATCH 3/6] media: v4l2-isp: Rename v4l2_isp_params_buffer_size Jacopo Mondi
` (4 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: Jacopo Mondi @ 2026-05-05 14:12 UTC (permalink / raw)
To: Mauro Carvalho Chehab, Daniel Scally, Keke Li, Antoine Bouyer,
Jai Luthra, Niklas Söderlund, Ricardo Ribalda
Cc: Laurent Pinchart, Sakari Ailus, Hans Verkuil, linux-media,
linux-kernel, Jacopo Mondi
From: Antoine Bouyer <antoine.bouyer@nxp.com>
Rework the userspace-api documentation of V4L2 ISP to support
statistics.
Update all occurences of 'v4l2_isp_param' types to match the uAPI
changes and add a section to document the statistics serialization
format.
Signed-off-by: Antoine Bouyer <antoine.bouyer@nxp.com>
[Update on uAPI changes]
Signed-off-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
---
Documentation/userspace-api/media/v4l/v4l2-isp.rst | 45 ++++++++++++++++------
1 file changed, 34 insertions(+), 11 deletions(-)
diff --git a/Documentation/userspace-api/media/v4l/v4l2-isp.rst b/Documentation/userspace-api/media/v4l/v4l2-isp.rst
index facf6dba1ca7..8a3f05b5e85f 100644
--- a/Documentation/userspace-api/media/v4l/v4l2-isp.rst
+++ b/Documentation/userspace-api/media/v4l/v4l2-isp.rst
@@ -18,22 +18,22 @@ single C structure that contains a header, followed by a binary buffer where
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 buffer header which
-is followed by a binary buffer of ISP configuration data. Userspace shall
-correctly populate the buffer header with the generic parameters format version
-and with the size (in bytes) of the binary data buffer where it 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 configuration
+The :c:type:`v4l2_isp_buffer` structure defines the buffer header which is
+followed by a binary buffer of ISP configuration data. Userspace shall correctly
+populate the buffer header with the serialization format version and with the
+size (in bytes) of the binary data buffer where it will store the ISP blocks
+configuration.
+
+Each *ISP configuration block* is preceded by a header implemented by the
+:c:type:`v4l2_isp_block_header` structure, followed by the configuration
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
------------------------------------------------
+ISP parameters 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_ENABLE
@@ -59,7 +59,30 @@ definition without invalidating the existing ones.
ISP statistics
==============
-Support for generic statistics format is not yet implemented in Video4Linux2.
+The generic ISP statistics format is identical to the generic ISP configuration
+parameters format. It is realized by defining a C structure that contains a
+header, followed by binary buffer where the ISP driver copies a variable number
+of ISP statistics blocks.
+
+Extensible statistics buffers have :c:type:`v4l2_isp_buffer` header followed by
+a binary buffer of ISP statistics data. ISP drivers populate the buffer header
+with the serialization format version and with the size (in bytes) of the binary
+data buffer where ISP statistics data are serialized. Applications shall
+validate that the serialization format version matches the expected one and that
+the buffer size doesn't exceed the maximum size for a statistics buffer as
+declared by the driver's uAPI header.
+
+Each *ISP statistics block* is preceded by a header implemented by the
+:c:type:`v4l2_isp_block_header` structure, followed by the statistics data for
+that specific block. The driver might optionally report platform-specific flags
+associated with each statistics block.
+
+Applications inspect the statistics block type as reported in the header and
+validates the reported size matches the block's expected size before accessing
+the ISP statistics data.
+
+Extension to the statistics format can be implemented by adding new blocks
+definition without invalidating the existing ones.
V4L2 ISP uAPI data types
========================
--
2.53.0
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH 3/6] media: v4l2-isp: Rename v4l2_isp_params_buffer_size
2026-05-05 14:12 [PATCH 0/6] media: v4l2-isp: Add support for extensible statistics Jacopo Mondi
2026-05-05 14:12 ` [PATCH 1/6] media: uapi: v4l2-isp: Add " Jacopo Mondi
2026-05-05 14:12 ` [PATCH 2/6] media: Documentation: uapi: Update V4L2 ISP for extensible stats Jacopo Mondi
@ 2026-05-05 14:12 ` Jacopo Mondi
2026-05-05 14:12 ` [PATCH 4/6] media: v4l2-isp: Add per-block validation callback Jacopo Mondi
` (3 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: Jacopo Mondi @ 2026-05-05 14:12 UTC (permalink / raw)
To: Mauro Carvalho Chehab, Daniel Scally, Keke Li, Antoine Bouyer,
Jai Luthra, Niklas Söderlund, Ricardo Ribalda
Cc: Laurent Pinchart, Sakari Ailus, Hans Verkuil, linux-media,
linux-kernel, Jacopo Mondi
Rename v4l2_isp_params_buffer_size() to v4l2_isp_buffer_size() to
support statistics.
Signed-off-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
---
.../media/platform/arm/mali-c55/mali-c55-params.c | 12 ++++++------
include/media/v4l2-isp.h | 22 +++++++++++++---------
2 files changed, 19 insertions(+), 15 deletions(-)
diff --git a/drivers/media/platform/arm/mali-c55/mali-c55-params.c b/drivers/media/platform/arm/mali-c55/mali-c55-params.c
index de0e9d898db7..dc483f0322d6 100644
--- a/drivers/media/platform/arm/mali-c55/mali-c55-params.c
+++ b/drivers/media/platform/arm/mali-c55/mali-c55-params.c
@@ -487,7 +487,7 @@ static int mali_c55_params_g_fmt_meta_out(struct file *file, void *fh,
{
static const struct v4l2_meta_format mfmt = {
.dataformat = V4L2_META_FMT_MALI_C55_PARAMS,
- .buffersize = v4l2_isp_params_buffer_size(MALI_C55_PARAMS_MAX_SIZE),
+ .buffersize = v4l2_isp_buffer_size(MALI_C55_PARAMS_MAX_SIZE),
};
f->fmt.meta = mfmt;
@@ -540,13 +540,13 @@ mali_c55_params_queue_setup(struct vb2_queue *q, unsigned int *num_buffers,
if (*num_planes && *num_planes > 1)
return -EINVAL;
- if (sizes[0] && sizes[0] < v4l2_isp_params_buffer_size(MALI_C55_PARAMS_MAX_SIZE))
+ if (sizes[0] && sizes[0] < v4l2_isp_buffer_size(MALI_C55_PARAMS_MAX_SIZE))
return -EINVAL;
*num_planes = 1;
if (!sizes[0])
- sizes[0] = v4l2_isp_params_buffer_size(MALI_C55_PARAMS_MAX_SIZE);
+ sizes[0] = v4l2_isp_buffer_size(MALI_C55_PARAMS_MAX_SIZE);
return 0;
}
@@ -556,7 +556,7 @@ static int mali_c55_params_buf_init(struct vb2_buffer *vb)
struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
struct mali_c55_params_buf *buf = to_mali_c55_params_buf(vbuf);
- buf->config = kvmalloc(v4l2_isp_params_buffer_size(MALI_C55_PARAMS_MAX_SIZE),
+ buf->config = kvmalloc(v4l2_isp_buffer_size(MALI_C55_PARAMS_MAX_SIZE),
GFP_KERNEL);
if (!buf->config)
return -ENOMEM;
@@ -583,7 +583,7 @@ static int mali_c55_params_buf_prepare(struct vb2_buffer *vb)
int ret;
ret = v4l2_isp_params_validate_buffer_size(mali_c55->dev, vb,
- v4l2_isp_params_buffer_size(MALI_C55_PARAMS_MAX_SIZE));
+ v4l2_isp_buffer_size(MALI_C55_PARAMS_MAX_SIZE));
if (ret)
return ret;
@@ -593,7 +593,7 @@ static int mali_c55_params_buf_prepare(struct vb2_buffer *vb)
* changed to the buffer content whilst the driver processes it.
*/
- memcpy(buf->config, config, v4l2_isp_params_buffer_size(MALI_C55_PARAMS_MAX_SIZE));
+ memcpy(buf->config, config, v4l2_isp_buffer_size(MALI_C55_PARAMS_MAX_SIZE));
return v4l2_isp_params_validate_buffer(mali_c55->dev, vb, buf->config,
mali_c55_params_block_types_info,
diff --git a/include/media/v4l2-isp.h b/include/media/v4l2-isp.h
index f3a6d0edcb24..d70ed6b431e7 100644
--- a/include/media/v4l2-isp.h
+++ b/include/media/v4l2-isp.h
@@ -15,17 +15,21 @@ 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
+ * v4l2_isp_buffer_size - Calculate size of v4l2_isp_buffer
+ * @max_size: The total size of the ISP configuration or statistics blocks
+ *
+ * Users of v4l2-isp will have differing sized data arrays for parameters and
+ * statistics, depending on their specific blocks. Drivers need to be able to
+ * calculate the appropriate size of the buffer to accommodate all ISP blocks
+ * supported by the platform. This macro provides a convenient tool for the
+ * calculation.
+ *
+ * The intended users of this function are drivers initializing the size
+ * of their metadata (parameters and statistics) buffers.
*
- * Users of the v4l2 extensible parameters will have differing sized data arrays
- * depending on their specific parameter buffers. Drivers and userspace will
- * 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))
+#define v4l2_isp_buffer_size(max_size) \
+ (offsetof(struct v4l2_isp_buffer, data) + (max_size))
/**
* v4l2_isp_params_validate_buffer_size - Validate a V4L2 ISP buffer sizes
--
2.53.0
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH 4/6] media: v4l2-isp: Add per-block validation callback
2026-05-05 14:12 [PATCH 0/6] media: v4l2-isp: Add support for extensible statistics Jacopo Mondi
` (2 preceding siblings ...)
2026-05-05 14:12 ` [PATCH 3/6] media: v4l2-isp: Rename v4l2_isp_params_buffer_size Jacopo Mondi
@ 2026-05-05 14:12 ` Jacopo Mondi
2026-05-05 14:12 ` [PATCH 5/6] media: amlogic-c3: Implement per-block validation Jacopo Mondi
` (2 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: Jacopo Mondi @ 2026-05-05 14:12 UTC (permalink / raw)
To: Mauro Carvalho Chehab, Daniel Scally, Keke Li, Antoine Bouyer,
Jai Luthra, Niklas Söderlund, Ricardo Ribalda
Cc: Laurent Pinchart, Sakari Ailus, Hans Verkuil, linux-media,
linux-kernel, Jacopo Mondi
Drivers are expected to provide to the helper function
v4l2_isp_params_validate_buffer() a list of 'struct
v4l2_isp_params_block_type_info' entries, one for each supported ISP block.
The type 'struct v4l2_isp_params_block_type_info' so far only contained the
expected block size for the core framework to validate the declared block
size against the expected one.
For some blocks, drivers might want to implement more precise per-block
validations. Add a function pointer member to 'struct
v4l2_isp_params_block_type_info' to allow drivers to register a callback
and call it from the core framework during validation.
Signed-off-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
---
drivers/media/v4l2-core/v4l2-isp.c | 4 ++++
include/media/v4l2-isp.h | 11 ++++++++---
2 files changed, 12 insertions(+), 3 deletions(-)
diff --git a/drivers/media/v4l2-core/v4l2-isp.c b/drivers/media/v4l2-core/v4l2-isp.c
index 29831f7032e9..10760659f8a3 100644
--- a/drivers/media/v4l2-core/v4l2-isp.c
+++ b/drivers/media/v4l2-core/v4l2-isp.c
@@ -114,6 +114,10 @@ int v4l2_isp_params_validate_buffer(struct device *dev, struct vb2_buffer *vb,
return -EINVAL;
}
+ if (type_info->block_validate &&
+ type_info->block_validate(dev, block))
+ return -EINVAL;
+
block_offset += block->size;
buffer_size -= block->size;
}
diff --git a/include/media/v4l2-isp.h b/include/media/v4l2-isp.h
index d70ed6b431e7..1f35a52f978a 100644
--- a/include/media/v4l2-isp.h
+++ b/include/media/v4l2-isp.h
@@ -55,17 +55,22 @@ int v4l2_isp_params_validate_buffer_size(struct device *dev,
/**
* struct v4l2_isp_params_block_type_info - V4L2 ISP per-block-type info
* @size: the block type expected size
+ * @block_validate: driver's callback to implement per-block validation
*
* The v4l2_isp_params_block_type_info collects information of the ISP
- * configuration block types for validation purposes. It currently only contains
- * the expected block type size.
+ * configuration block types for validation purposes. It contains the expected
+ * block type size and a function pointer where drivers can register a callback
+ * for additional per-block validation purposes. The validation function is
+ * expected to return 0 on success or a negative error number for errors.
*
* Drivers shall prepare a list of block type info, indexed by block type, one
* for each supported ISP block type and correctly populate them with the
- * expected block type size.
+ * expected block type size and the optional callback.
*/
struct v4l2_isp_params_block_type_info {
size_t size;
+ int (*block_validate)(struct device *dev,
+ const struct v4l2_isp_block_header *block);
};
/**
--
2.53.0
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH 5/6] media: amlogic-c3: Implement per-block validation
2026-05-05 14:12 [PATCH 0/6] media: v4l2-isp: Add support for extensible statistics Jacopo Mondi
` (3 preceding siblings ...)
2026-05-05 14:12 ` [PATCH 4/6] media: v4l2-isp: Add per-block validation callback Jacopo Mondi
@ 2026-05-05 14:12 ` Jacopo Mondi
2026-05-05 14:12 ` [PATCH 6/6] media: v4l2-isp: Add helpers for stats buffer Jacopo Mondi
2026-05-05 16:49 ` [PATCH 0/6] media: v4l2-isp: Add support for extensible statistics Antoine Bouyer
6 siblings, 0 replies; 8+ messages in thread
From: Jacopo Mondi @ 2026-05-05 14:12 UTC (permalink / raw)
To: Mauro Carvalho Chehab, Daniel Scally, Keke Li, Antoine Bouyer,
Jai Luthra, Niklas Söderlund, Ricardo Ribalda
Cc: Laurent Pinchart, Sakari Ailus, Hans Verkuil, linux-media,
linux-kernel, Jacopo Mondi
Use the newly introduced per-block validation in v4l2-isp framework to
implement a validation callback for the AWB and AE configuration blocks
to make sure the configured metering zones do not exceed the hardware
capabilities.
Signed-off-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
---
.../media/platform/amlogic/c3/isp/c3-isp-params.c | 42 ++++++++++++++++++++--
1 file changed, 39 insertions(+), 3 deletions(-)
diff --git a/drivers/media/platform/amlogic/c3/isp/c3-isp-params.c b/drivers/media/platform/amlogic/c3/isp/c3-isp-params.c
index 6f9ca7a7dd88..6d5d332599df 100644
--- a/drivers/media/platform/amlogic/c3/isp/c3-isp-params.c
+++ b/drivers/media/platform/amlogic/c3/isp/c3-isp-params.c
@@ -531,16 +531,52 @@ static const c3_isp_block_handler c3_isp_params_handlers[] = {
[C3_ISP_PARAMS_BLOCK_BLC] = c3_isp_params_cfg_blc,
};
-#define C3_ISP_PARAMS_BLOCK_INFO(block, data) \
+static int
+c3_isp_params_awb_config_validate(struct device *dev,
+ const struct v4l2_isp_block_header *block)
+{
+ const struct c3_isp_params_awb_config *cfg =
+ (const struct c3_isp_params_awb_config *)block;
+
+ if (cfg->horiz_zones_num * cfg->vert_zones_num > C3_ISP_AWB_MAX_ZONES) {
+ dev_dbg(dev, "Invalid number of AWB measurement zones\n");
+ return -EINVAL;
+ }
+
+ return 0;
+}
+
+static int
+c3_isp_params_ae_config_validate(struct device *dev,
+ const struct v4l2_isp_block_header *block)
+{
+ const struct c3_isp_params_ae_config *cfg =
+ (const struct c3_isp_params_ae_config *)block;
+
+ if (cfg->horiz_zones_num * cfg->vert_zones_num > C3_ISP_AE_MAX_ZONES) {
+ dev_dbg(dev, "Invalid number of AE measurement zones\n");
+ return -EINVAL;
+ }
+
+ return 0;
+}
+
+#define C3_ISP_PARAMS_BLOCK_INFO_CBK(block, data, cbk) \
[C3_ISP_PARAMS_BLOCK_ ## block] = { \
.size = sizeof(struct c3_isp_params_ ## data), \
+ .block_validate = (cbk)\
}
+#define C3_ISP_PARAMS_BLOCK_INFO(block, data) \
+ C3_ISP_PARAMS_BLOCK_INFO_CBK(block, data, NULL)
+
static const struct v4l2_isp_params_block_type_info
c3_isp_params_block_types_info[] = {
C3_ISP_PARAMS_BLOCK_INFO(AWB_GAINS, awb_gains),
- C3_ISP_PARAMS_BLOCK_INFO(AWB_CONFIG, awb_config),
- C3_ISP_PARAMS_BLOCK_INFO(AE_CONFIG, ae_config),
+ C3_ISP_PARAMS_BLOCK_INFO_CBK(AWB_CONFIG, awb_config,
+ &c3_isp_params_awb_config_validate),
+ C3_ISP_PARAMS_BLOCK_INFO_CBK(AE_CONFIG, ae_config,
+ &c3_isp_params_ae_config_validate),
C3_ISP_PARAMS_BLOCK_INFO(AF_CONFIG, af_config),
C3_ISP_PARAMS_BLOCK_INFO(PST_GAMMA, pst_gamma),
C3_ISP_PARAMS_BLOCK_INFO(CCM, ccm),
--
2.53.0
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH 6/6] media: v4l2-isp: Add helpers for stats buffer
2026-05-05 14:12 [PATCH 0/6] media: v4l2-isp: Add support for extensible statistics Jacopo Mondi
` (4 preceding siblings ...)
2026-05-05 14:12 ` [PATCH 5/6] media: amlogic-c3: Implement per-block validation Jacopo Mondi
@ 2026-05-05 14:12 ` Jacopo Mondi
2026-05-05 16:49 ` [PATCH 0/6] media: v4l2-isp: Add support for extensible statistics Antoine Bouyer
6 siblings, 0 replies; 8+ messages in thread
From: Jacopo Mondi @ 2026-05-05 14:12 UTC (permalink / raw)
To: Mauro Carvalho Chehab, Daniel Scally, Keke Li, Antoine Bouyer,
Jai Luthra, Niklas Söderlund, Ricardo Ribalda
Cc: Laurent Pinchart, Sakari Ailus, Hans Verkuil, linux-media,
linux-kernel, Jacopo Mondi
Add two helper functions to v4l2-isp to handle statistics:
- v4l2_isp_stats_init_buffer() to initialize a statistics buffer
- v4l2_isp_stats_init_block() to initialize a statistics block in the
next available memory location of a buffer
The v4l2_isp_stats_init_buffer() resets the data size counter of the
buffer and initializes its 'version' field.
The v4l2_isp_stats_init_block() helper accepts the type of the stats
block about to be populated, an array of per-block-type information and
the maximum size of the v4l2-isp buffer. If enough space for the new
block is available, the function increments the
v4l2_isp_buffer.data_size counter, initializes the new stats block
header and returns a pointer to the block for the driver to populate it.
Signed-off-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
---
drivers/media/v4l2-core/v4l2-isp.c | 52 +++++++++++++++++++++++++++++++++
include/media/v4l2-isp.h | 59 +++++++++++++++++++++++++++++++++++++-
2 files changed, 110 insertions(+), 1 deletion(-)
diff --git a/drivers/media/v4l2-core/v4l2-isp.c b/drivers/media/v4l2-core/v4l2-isp.c
index 10760659f8a3..8482010776d4 100644
--- a/drivers/media/v4l2-core/v4l2-isp.c
+++ b/drivers/media/v4l2-core/v4l2-isp.c
@@ -131,6 +131,58 @@ int v4l2_isp_params_validate_buffer(struct device *dev, struct vb2_buffer *vb,
}
EXPORT_SYMBOL_GPL(v4l2_isp_params_validate_buffer);
+void v4l2_isp_stats_init_buffer(struct v4l2_isp_buffer *buf,
+ enum v4l2_isp_version version)
+{
+ if (WARN_ON(!buf))
+ return;
+
+ if (WARN_ON(version > V4L2_ISP_VERSION_V1))
+ return;
+
+ buf->version = version;
+ buf->data_size = 0;
+}
+EXPORT_SYMBOL_GPL(v4l2_isp_stats_init_buffer);
+
+struct v4l2_isp_block_header *
+v4l2_isp_stats_init_block(struct device *dev, struct v4l2_isp_buffer *buf,
+ const struct v4l2_isp_stats_block_type_info *type_info,
+ size_t num_block_types, unsigned int block_type,
+ size_t max_size)
+{
+ const struct v4l2_isp_stats_block_type_info *block_info;
+ struct v4l2_isp_block_header *header;
+ size_t used;
+
+ if (WARN_ON(!dev || !buf || !type_info))
+ return ERR_PTR(-EINVAL);
+
+ if (block_type >= num_block_types) {
+ dev_err(dev, "Invalid block type %u\n", block_type);
+ return ERR_PTR(-EINVAL);
+ }
+
+ block_info = &type_info[block_type];
+ used = buf->data_size;
+
+ if (used + block_info->size > max_size) {
+ dev_err(dev, "No space for stats block type %u of size %zu\n",
+ block_type, block_info->size);
+ return ERR_PTR(-ENOMEM);
+ }
+
+ buf->data_size += block_info->size;
+
+ header = (struct v4l2_isp_block_header *)&buf->data[used];
+ header->type = block_type;
+ header->size = block_info->size;
+ header->flags = 0;
+
+ return header;
+}
+EXPORT_SYMBOL_GPL(v4l2_isp_stats_init_block);
+
MODULE_LICENSE("GPL");
MODULE_AUTHOR("Jacopo Mondi <jacopo.mondi@ideasonboard.com");
MODULE_DESCRIPTION("V4L2 generic ISP parameters and statistics helpers");
diff --git a/include/media/v4l2-isp.h b/include/media/v4l2-isp.h
index 1f35a52f978a..7a54cf98c79a 100644
--- a/include/media/v4l2-isp.h
+++ b/include/media/v4l2-isp.h
@@ -53,7 +53,7 @@ int v4l2_isp_params_validate_buffer_size(struct device *dev,
size_t max_size);
/**
- * struct v4l2_isp_params_block_type_info - V4L2 ISP per-block-type info
+ * struct v4l2_isp_params_block_type_info - V4L2 ISP params per-block-type info
* @size: the block type expected size
* @block_validate: driver's callback to implement per-block validation
*
@@ -97,4 +97,61 @@ int v4l2_isp_params_validate_buffer(struct device *dev, struct vb2_buffer *vb,
const struct v4l2_isp_params_block_type_info *type_info,
size_t num_block_types);
+/**
+ * struct v4l2_isp_stats_block_type_info - V4L2 ISP stats per-block-type info
+ * @size: the block type expected size
+ *
+ * The v4l2_isp_stats_block_type_info collects information of the ISP
+ * statistics block types for validation purposes. It currently only contains
+ * the expected block size.
+ *
+ * Drivers shall prepare a list of statistics block type info, indexed by block
+ * type, one for each supported ISP statistics block type and correctly populate
+ * them with the expected block size.
+ */
+struct v4l2_isp_stats_block_type_info {
+ size_t size;
+};
+
+/**
+ * v4l2_isp_stats_init_buffer - Initialize a statistics buffer
+ *
+ * Initialize a buffer of statistics. Only set the 'version' field and reset
+ * 'data_size' to 0.
+ *
+ * @buf: the v4l2_isp_buffer to initialize
+ * @version: the v4l2-isp serialization format version used by the driver
+ */
+void v4l2_isp_stats_init_buffer(struct v4l2_isp_buffer *buf,
+ enum v4l2_isp_version version);
+
+/**
+ * v4l2_isp_stats_init_block - Create and initialize a new block in a statistics
+ * buffer
+ * @dev: the driver's device pointer
+ * @buf: the v4l2_isp_buffer where statistics are serialized
+ * @type_info: the array of per-block-type validation info
+ * @num_block_types: the number of block types in the type_info array
+ * @block_type: the type of the statistics block to initialize
+ * @max_size: the maximum size of the data[] member of @buf
+ *
+ * This function locates and initialize a new statistics block in @buf for the
+ * driver to populate its content. The function checks that enough space for the
+ * requested @block_type is available in @buf and increments the 'data_size'
+ * member of @buf. The newly created statistics block's header is initialized
+ * with the size and type information provided by the caller in @type_info.
+ *
+ * Drivers should call this function before populating a new statistics block
+ * content.
+ *
+ * Returns a pointer to the next available location in @buf, or an error pointer
+ * if the requested @block_size is not available in @buf or @block_type is not
+ * valid.
+ */
+struct v4l2_isp_block_header *
+v4l2_isp_stats_init_block(struct device *dev, struct v4l2_isp_buffer *buf,
+ const struct v4l2_isp_stats_block_type_info *type_info,
+ size_t num_block_types, unsigned int block_type,
+ size_t max_size);
+
#endif /* _V4L2_ISP_H_ */
--
2.53.0
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH 0/6] media: v4l2-isp: Add support for extensible statistics
2026-05-05 14:12 [PATCH 0/6] media: v4l2-isp: Add support for extensible statistics Jacopo Mondi
` (5 preceding siblings ...)
2026-05-05 14:12 ` [PATCH 6/6] media: v4l2-isp: Add helpers for stats buffer Jacopo Mondi
@ 2026-05-05 16:49 ` Antoine Bouyer
6 siblings, 0 replies; 8+ messages in thread
From: Antoine Bouyer @ 2026-05-05 16:49 UTC (permalink / raw)
To: Jacopo Mondi, Mauro Carvalho Chehab, Daniel Scally, Keke Li,
Jai Luthra, Niklas Söderlund, Ricardo Ribalda
Cc: Laurent Pinchart, Sakari Ailus, Hans Verkuil, linux-media,
linux-kernel
On 5/5/26 4:12 PM, Jacopo Mondi wrote:
>
>
> This series breaks out from Antonie's
> https://patchwork.linuxtv.org/project/linux-media/list/?series=24043
> the extensible stats support and adds a few more patches on top to:
>
> - add support for per-block validation as suggested during the review of
> Ricardo's
> https://patchwork.linuxtv.org/project/linux-media/patch/20260504-smatch-7-1-v3-6-fda125c30058@chromium.org/
>
> - add two helper functions to v4l2-isp to ease handling of extensible
> statistics for drivers. An early user, based on a preliminary version
> of the patches is available here as a reference:
> https://patchwork.linuxtv.org/project/linux-media/list/?series=24703
>
> Antonie: I took the liberty to fold in your patches changes to address
> my comments on your v1. I pushed an un-squased version of the patches
> here:
> https://gitlab.freedesktop.org/linux-media/users/jmondi/-/tree/b4/extensible-stats-unsquashed
> so you can easily get the diff from this and your version. Please feel
> free to comment on these as you're the original author.
Hi Jacopo
Thanks for the rework and the links. I'm fine with your [SQUASH] commits.
If there are no other comments, I assume I can reuse the common patches
in my v2 then, and also apply the new helpers to neoisp driver changes.
They look very useful (especially to prevent out-of-bounds crashes I
observed when data_size was not set before filling stats :( ). I'll
check in your user example.
BR
Antoine
>
> Signed-off-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
> ---
> Antoine Bouyer (2):
> media: uapi: v4l2-isp: Add extensible statistics
> media: Documentation: uapi: Update V4L2 ISP for extensible stats
>
> Jacopo Mondi (4):
> media: v4l2-isp: Rename v4l2_isp_params_buffer_size
> media: v4l2-isp: Add per-block validation callback
> media: amlogic-c3: Implement per-block validation
> media: v4l2-isp: Add helpers for stats buffer
>
> Documentation/userspace-api/media/v4l/v4l2-isp.rst | 45 ++++++--
> .../media/platform/amlogic/c3/isp/c3-isp-params.c | 42 ++++++-
> .../media/platform/arm/mali-c55/mali-c55-params.c | 12 +-
> drivers/media/v4l2-core/v4l2-isp.c | 56 +++++++++
> include/media/v4l2-isp.h | 94 +++++++++++++---
> include/uapi/linux/media/v4l2-isp.h | 125 +++++++++++++--------
> 6 files changed, 294 insertions(+), 80 deletions(-)
> ---
> base-commit: d9c8c4adf23d17549c0ec9c85b99d85a0ee6cf18
> change-id: 20260504-extensible-stats-f2d6befcc1ce
>
> Best regards,
> --
> Jacopo Mondi <jacopo.mondi@ideasonboard.com>
>
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2026-05-05 16:49 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-05-05 14:12 [PATCH 0/6] media: v4l2-isp: Add support for extensible statistics Jacopo Mondi
2026-05-05 14:12 ` [PATCH 1/6] media: uapi: v4l2-isp: Add " Jacopo Mondi
2026-05-05 14:12 ` [PATCH 2/6] media: Documentation: uapi: Update V4L2 ISP for extensible stats Jacopo Mondi
2026-05-05 14:12 ` [PATCH 3/6] media: v4l2-isp: Rename v4l2_isp_params_buffer_size Jacopo Mondi
2026-05-05 14:12 ` [PATCH 4/6] media: v4l2-isp: Add per-block validation callback Jacopo Mondi
2026-05-05 14:12 ` [PATCH 5/6] media: amlogic-c3: Implement per-block validation Jacopo Mondi
2026-05-05 14:12 ` [PATCH 6/6] media: v4l2-isp: Add helpers for stats buffer Jacopo Mondi
2026-05-05 16:49 ` [PATCH 0/6] media: v4l2-isp: Add support for extensible statistics Antoine Bouyer
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox