summaryrefslogtreecommitdiff
path: root/drivers
diff options
context:
space:
mode:
authorJacopo Mondi <jacopo.mondi@ideasonboard.com>2026-06-27 15:42:03 +0200
committerSakari Ailus <sakari.ailus@linux.intel.com>2026-07-30 20:51:13 +0300
commit4ade3af89b2facff395467af1a5d953ea9dfc181 (patch)
treee67280db316e178786b6ee8d37dac742d2948843 /drivers
parent07a4324a81196f4b475b566a79f91f111b2fc4be (diff)
downloadlinux-stable-4ade3af89b2facff395467af1a5d953ea9dfc181.tar.gz
linux-stable-4ade3af89b2facff395467af1a5d953ea9dfc181.zip
media: v4l2-isp: Add helpers for stats buffer
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. Reviewed-by: Niklas Söderlund <niklas.soderlund+renesas@ragnatech.se> Signed-off-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com> Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/media/v4l2-core/v4l2-isp.c52
1 files changed, 52 insertions, 0 deletions
diff --git a/drivers/media/v4l2-core/v4l2-isp.c b/drivers/media/v4l2-core/v4l2-isp.c
index f497471e9f18..1eb46e080afa 100644
--- a/drivers/media/v4l2-core/v4l2-isp.c
+++ b/drivers/media/v4l2-core/v4l2-isp.c
@@ -130,6 +130,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");