/* SPDX-License-Identifier: GPL-2.0-or-later */1/*2* Video4Linux2 generic ISP parameters and statistics support3*4* Copyright (C) 2025 Ideas On Board Oy5* Author: Jacopo Mondi <[email protected]>6*/78#ifndef _V4L2_ISP_H_9#define _V4L2_ISP_H_1011#include <linux/media/v4l2-isp.h>1213struct device;14struct vb2_buffer;1516/**17* v4l2_isp_params_buffer_size - Calculate size of v4l2_isp_params_buffer18* @max_params_size: The total size of the ISP configuration blocks19*20* Users of the v4l2 extensible parameters will have differing sized data arrays21* depending on their specific parameter buffers. Drivers and userspace will22* need to be able to calculate the appropriate size of the struct to23* accommodate all ISP configuration blocks provided by the platform.24* This macro provides a convenient tool for the calculation.25*/26#define v4l2_isp_params_buffer_size(max_params_size) \27(offsetof(struct v4l2_isp_params_buffer, data) + (max_params_size))2829/**30* v4l2_isp_params_validate_buffer_size - Validate a V4L2 ISP buffer sizes31* @dev: the driver's device pointer32* @vb: the videobuf2 buffer33* @max_size: the maximum allowed buffer size34*35* This function performs validation of the size of a V4L2 ISP parameters buffer36* before the driver can access the actual data buffer content.37*38* After the sizes validation, drivers should copy the buffer content to a39* kernel-only memory area to prevent userspace from modifying it,40* before completing validation using v4l2_isp_params_validate_buffer().41*42* The @vb buffer as received from the vb2 .buf_prepare() operation is checked43* against @max_size and it's validated to be large enough to accommodate at44* least one ISP configuration block.45*/46int v4l2_isp_params_validate_buffer_size(struct device *dev,47struct vb2_buffer *vb,48size_t max_size);4950/**51* struct v4l2_isp_params_block_type_info - V4L2 ISP per-block-type info52* @size: the block type expected size53*54* The v4l2_isp_params_block_type_info collects information of the ISP55* configuration block types for validation purposes. It currently only contains56* the expected block type size.57*58* Drivers shall prepare a list of block type info, indexed by block type, one59* for each supported ISP block type and correctly populate them with the60* expected block type size.61*/62struct v4l2_isp_params_block_type_info {63size_t size;64};6566/**67* v4l2_isp_params_validate_buffer - Validate a V4L2 ISP parameters buffer68* @dev: the driver's device pointer69* @vb: the videobuf2 buffer70* @buffer: the V4L2 ISP parameters buffer71* @type_info: the array of per-block-type validation info72* @num_block_types: the number of block types in the type_info array73*74* This function completes the validation of a V4L2 ISP parameters buffer,75* verifying each configuration block correctness before the driver can use76* them to program the hardware.77*78* Drivers should use this function after having validated the correctness of79* the vb2 buffer sizes by using the v4l2_isp_params_validate_buffer_size()80* helper first. Once the buffer size has been validated, drivers should81* perform a copy of the user provided buffer into a kernel-only memory buffer82* to prevent userspace from modifying its content after it has been submitted83* to the driver, and then call this function to complete validation.84*/85int v4l2_isp_params_validate_buffer(struct device *dev, struct vb2_buffer *vb,86const struct v4l2_isp_params_buffer *buffer,87const struct v4l2_isp_params_block_type_info *type_info,88size_t num_block_types);8990#endif /* _V4L2_ISP_H_ */919293