v4l2-isp.h 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. /*
  3. * Video4Linux2 generic ISP parameters and statistics support
  4. *
  5. * Copyright (C) 2025 Ideas On Board Oy
  6. * Author: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
  7. */
  8. #ifndef _V4L2_ISP_H_
  9. #define _V4L2_ISP_H_
  10. #include <linux/media/v4l2-isp.h>
  11. struct device;
  12. struct vb2_buffer;
  13. /**
  14. * v4l2_isp_params_buffer_size - Calculate size of v4l2_isp_params_buffer
  15. * @max_params_size: The total size of the ISP configuration blocks
  16. *
  17. * Users of the v4l2 extensible parameters will have differing sized data arrays
  18. * depending on their specific parameter buffers. Drivers and userspace will
  19. * need to be able to calculate the appropriate size of the struct to
  20. * accommodate all ISP configuration blocks provided by the platform.
  21. * This macro provides a convenient tool for the calculation.
  22. */
  23. #define v4l2_isp_params_buffer_size(max_params_size) \
  24. (offsetof(struct v4l2_isp_params_buffer, data) + (max_params_size))
  25. /**
  26. * v4l2_isp_params_validate_buffer_size - Validate a V4L2 ISP buffer sizes
  27. * @dev: the driver's device pointer
  28. * @vb: the videobuf2 buffer
  29. * @max_size: the maximum allowed buffer size
  30. *
  31. * This function performs validation of the size of a V4L2 ISP parameters buffer
  32. * before the driver can access the actual data buffer content.
  33. *
  34. * After the sizes validation, drivers should copy the buffer content to a
  35. * kernel-only memory area to prevent userspace from modifying it,
  36. * before completing validation using v4l2_isp_params_validate_buffer().
  37. *
  38. * The @vb buffer as received from the vb2 .buf_prepare() operation is checked
  39. * against @max_size and it's validated to be large enough to accommodate at
  40. * least one ISP configuration block.
  41. */
  42. int v4l2_isp_params_validate_buffer_size(struct device *dev,
  43. struct vb2_buffer *vb,
  44. size_t max_size);
  45. /**
  46. * struct v4l2_isp_params_block_type_info - V4L2 ISP per-block-type info
  47. * @size: the block type expected size
  48. *
  49. * The v4l2_isp_params_block_type_info collects information of the ISP
  50. * configuration block types for validation purposes. It currently only contains
  51. * the expected block type size.
  52. *
  53. * Drivers shall prepare a list of block type info, indexed by block type, one
  54. * for each supported ISP block type and correctly populate them with the
  55. * expected block type size.
  56. */
  57. struct v4l2_isp_params_block_type_info {
  58. size_t size;
  59. };
  60. /**
  61. * v4l2_isp_params_validate_buffer - Validate a V4L2 ISP parameters buffer
  62. * @dev: the driver's device pointer
  63. * @vb: the videobuf2 buffer
  64. * @buffer: the V4L2 ISP parameters buffer
  65. * @type_info: the array of per-block-type validation info
  66. * @num_block_types: the number of block types in the type_info array
  67. *
  68. * This function completes the validation of a V4L2 ISP parameters buffer,
  69. * verifying each configuration block correctness before the driver can use
  70. * them to program the hardware.
  71. *
  72. * Drivers should use this function after having validated the correctness of
  73. * the vb2 buffer sizes by using the v4l2_isp_params_validate_buffer_size()
  74. * helper first. Once the buffer size has been validated, drivers should
  75. * perform a copy of the user provided buffer into a kernel-only memory buffer
  76. * to prevent userspace from modifying its content after it has been submitted
  77. * to the driver, and then call this function to complete validation.
  78. */
  79. int v4l2_isp_params_validate_buffer(struct device *dev, struct vb2_buffer *vb,
  80. const struct v4l2_isp_params_buffer *buffer,
  81. const struct v4l2_isp_params_block_type_info *type_info,
  82. size_t num_block_types);
  83. #endif /* _V4L2_ISP_H_ */