mbox series

[v9,0/12] media: rkisp1: Extensible parameters and companding

Message ID 20240807212253.1667847-1-jacopo.mondi@ideasonboard.com
Headers show
Series media: rkisp1: Extensible parameters and companding | expand

Message

Jacopo Mondi Aug. 7, 2024, 9:22 p.m. UTC
v8->v9:
- Redefine the enable/disable flags as suggested by Hans
- Specify in uAPI doc that 'flags = ENABLE | DISABLE' is not valid
- Check flags validity in rkisp1-params.c

v7->v8:
- uAPI:
  - Make the 'size' field of the header block an u32. Remove the
    __attribute__((aligned(8)) from the header declaration as it's now 8 bytes
    long
  - Make the 'enable' field of the header block a bitmask of flags. I introduced

	enum rkisp1_ext_params_block_flags {
		RKISP1_EXT_PARAMS_BLOCK_DISABLE	= 0x1,
		RKISP1_EXT_PARAMS_BLOCK_ENABLE	= 0x2,
	};

   to allow user-space to configure a block without changing its power state (by
   not setting any flag).

- driver:

  - As the 'enable' field is now a bitmask, the handling of the block enablment
    had to change as well. In example, for BLS:

	@@ -1626,7 +1626,7 @@ rkisp1_ext_params_bls(struct rkisp1_params *params,
	 {
		const struct rkisp1_ext_params_bls_config *bls = &block->bls;

	-       if (bls->header.enable == RKISP1_EXT_PARAMS_BLOCK_DISABLE) {
	+       if (bls->header.flags & RKISP1_EXT_PARAMS_BLOCK_DISABLE) {
			rkisp1_param_clear_bits(params, RKISP1_CIF_ISP_BLS_CTRL,
						RKISP1_CIF_ISP_BLS_ENA);
			return;
	@@ -1634,7 +1634,8 @@ rkisp1_ext_params_bls(struct rkisp1_params *params,

		rkisp1_bls_config(params, &bls->config);

	-       if (!(params->enabled_blocks & BIT(RKISP1_EXT_PARAMS_BLOCK_TYPE_BLS)))
	+       if ((bls->header.flags & RKISP1_EXT_PARAMS_BLOCK_ENABLE) &&
	+           !(params->enabled_blocks & BIT(bls->header.type)))
			rkisp1_param_set_bits(params, RKISP1_CIF_ISP_BLS_CTRL,
					      RKISP1_CIF_ISP_BLS_ENA);
	 }

   this requires userspace to specify the DISABLE/ENABLE flags and not rely
   on the fact that !enable meant 'disable' as in v7

v6->v7:
- Collect [PATCH v2 0/5] media: rkisp1: Add support for the companding block
- Fix GOC handling
- Fix newly introduced errors in checkstyle and documentation reported by
  https://gitlab.freedesktop.org/linux-media/users/jmondi/-/pipelines/1231492

v5->v6:
- Collect [v5.2 6/7] from Laurent
- Collect Paul's tags
- Add extra validation for unexpected data after the payload end as
  suggested by Sakari

v4->v5:
- Refine validation of the ext params buffer following Laurent's suggestion
- perform memcpy of the parameters buffer after sizes validation

v3->v4:
- Introduce 'union rkisp1_ext_params_config' to avoid casts in the block
  handlers

v2->v3:
- Address Laurent's comments on the uAPI:
  - rename $block_config with  just 'config'
  - reduce header size
  - rename a few fields/blocks

- Address Laurent's comment on the params node:
  - Use the plane payload for memcpy() and buffer validation
  - drop buf_out_validate() and use buf_prepare() only
  - validate the total buffer size against the buffer payload
  - use const pointers where possible

v1->v2:
- re-order patches to introduce parameters buffer caching for the existing
  "fixed" format before introducing the "extensible" format
- align all structures to 64-bit boundaries in the uAPI
- remove NO_CHANGE enablement state and cache a bitmask of enabled blocks
- address review comments in documentation

The VeriSilicon ISP8000 IP, supported through the rkisp1 driver in the Linux
kernel, is integrated in several SoCs from different vendors. Different
revisions of the IP differ in the number of supported features and in the
register space location assigned to specific ISP blocks.

The current configuration parameters format, defined in
include/uapi/linux/rkisp1-config.h is realized by a C structure (struct
rkisp1_params_cfg) which wraps other structures that allows to configure
specific ISP blocks. The layout of the parameters buffer is part of the Linux
kernel uAPI and can hardly be extended or modified to adapt it to different
revisions of the same IP.

This series proposes the introduction of a new parameters format for the RkISP1
(without dropping support for the existing one) which is designed with the goals
of being:

1) versioned: can be changed without breaking existing applications
2) extensible: new blocks and parameters can be added without breaking the uABI

To do so, a new 'struct rkisp1_ext_params_cfg' type is introduced. It wraps an
header and a data buffer, which userspace fills with configuration blocks
for each ISP block it intends to configure. The parameters buffer is thus of
different effective sizes, depending on the number of blocks userspace intends
to configure.

The kernel driver parses the data block and decides, based on the versioning
number and the platform it operates on, how to handle each block.

The parameters format is very similar to the parameters format implemented
in the in-review Mali C55 ISP driver [1]

CI pipeline [2]

[1] https://lore.kernel.org/linux-media/20240529152858.183799-15-dan.scally@ideasonboard.com/
[2] https://gitlab.freedesktop.org/linux-media/users/jmondi/-/pipelines/1242260

Jacopo Mondi (7):
  media: uapi: rkisp1-config: Add extensible params format
  media: uapi: videodev2: Add V4L2_META_FMT_RK_ISP1_EXT_PARAMS
  media: rkisp1: Add struct rkisp1_params_buffer
  media: rkisp1: Copy the parameters buffer
  media: rkisp1: Cache the currently active format
  media: rkisp1: Implement extensible params support
  media: rkisp1: Implement s_fmt/try_fmt

Laurent Pinchart (2):
  media: rkisp1: Add helper function to swap colour channels
  media: rkisp1: Add features mask to extensible block handlers

Paul Elder (3):
  media: rkisp1: Add register definitions for the companding block
  media: rkisp1: Add feature flags for BLS and compand
  media: rkisp1: Add support for the companding block

 Documentation/admin-guide/media/rkisp1.rst    |   11 +-
 .../media/v4l/metafmt-rkisp1.rst              |   57 +-
 .../platform/rockchip/rkisp1/rkisp1-common.c  |   14 +
 .../platform/rockchip/rkisp1/rkisp1-common.h  |   38 +-
 .../platform/rockchip/rkisp1/rkisp1-dev.c     |    9 +-
 .../platform/rockchip/rkisp1/rkisp1-params.c  | 1033 +++++++++++++++--
 .../platform/rockchip/rkisp1/rkisp1-regs.h    |   23 +
 .../platform/rockchip/rkisp1/rkisp1-stats.c   |   51 +-
 drivers/media/v4l2-core/v4l2-ioctl.c          |    1 +
 include/uapi/linux/rkisp1-config.h            |  572 +++++++++
 include/uapi/linux/videodev2.h                |    1 +
 11 files changed, 1653 insertions(+), 157 deletions(-)

--
2.45.2

Comments

Hans Verkuil Aug. 8, 2024, 6:31 a.m. UTC | #1
On 07/08/2024 23:22, Jacopo Mondi wrote:
> Add to the rkisp1-config.h header data types and documentation of
> the extensible parameters format.
> 
> Signed-off-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>
> Tested-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
> Acked-by: Sakari Ailus <sakari.ailus@linux.intel.com>
> ---
>  include/uapi/linux/rkisp1-config.h | 485 +++++++++++++++++++++++++++++
>  1 file changed, 485 insertions(+)
> 
> diff --git a/include/uapi/linux/rkisp1-config.h b/include/uapi/linux/rkisp1-config.h
> index 6eeaf8bf2362..14a23fd9a745 100644
> --- a/include/uapi/linux/rkisp1-config.h
> +++ b/include/uapi/linux/rkisp1-config.h
> @@ -996,4 +996,489 @@ struct rkisp1_stat_buffer {
>  	struct rkisp1_cif_isp_stat params;
>  };
>  
> +/*---------- PART3: Extensible Configuration Parameters  ------------*/
> +
> +/**
> + * enum rkisp1_ext_params_block_type - RkISP1 extensible params block type
> + *
> + * @RKISP1_EXT_PARAMS_BLOCK_TYPE_BLS: Black level subtraction
> + * @RKISP1_EXT_PARAMS_BLOCK_TYPE_DPCC: Defect pixel cluster correction
> + * @RKISP1_EXT_PARAMS_BLOCK_TYPE_SDG: Sensor de-gamma
> + * @RKISP1_EXT_PARAMS_BLOCK_TYPE_AWB_GAIN: Auto white balance gains
> + * @RKISP1_EXT_PARAMS_BLOCK_TYPE_FLT: ISP filtering
> + * @RKISP1_EXT_PARAMS_BLOCK_TYPE_BDM: Bayer de-mosaic
> + * @RKISP1_EXT_PARAMS_BLOCK_TYPE_CTK: Cross-talk correction
> + * @RKISP1_EXT_PARAMS_BLOCK_TYPE_GOC: Gamma out correction
> + * @RKISP1_EXT_PARAMS_BLOCK_TYPE_DPF: De-noise pre-filter
> + * @RKISP1_EXT_PARAMS_BLOCK_TYPE_DPF_STRENGTH: De-noise pre-filter strength
> + * @RKISP1_EXT_PARAMS_BLOCK_TYPE_CPROC: Color processing
> + * @RKISP1_EXT_PARAMS_BLOCK_TYPE_IE: Image effects
> + * @RKISP1_EXT_PARAMS_BLOCK_TYPE_LSC: Lens shading correction
> + * @RKISP1_EXT_PARAMS_BLOCK_TYPE_AWB_MEAS: Auto white balance statistics
> + * @RKISP1_EXT_PARAMS_BLOCK_TYPE_HST_MEAS: Histogram statistics
> + * @RKISP1_EXT_PARAMS_BLOCK_TYPE_AEC_MEAS: Auto exposure statistics
> + * @RKISP1_EXT_PARAMS_BLOCK_TYPE_AFC_MEAS: Auto-focus statistics
> + */
> +enum rkisp1_ext_params_block_type {
> +	RKISP1_EXT_PARAMS_BLOCK_TYPE_BLS,
> +	RKISP1_EXT_PARAMS_BLOCK_TYPE_DPCC,
> +	RKISP1_EXT_PARAMS_BLOCK_TYPE_SDG,
> +	RKISP1_EXT_PARAMS_BLOCK_TYPE_AWB_GAIN,
> +	RKISP1_EXT_PARAMS_BLOCK_TYPE_FLT,
> +	RKISP1_EXT_PARAMS_BLOCK_TYPE_BDM,
> +	RKISP1_EXT_PARAMS_BLOCK_TYPE_CTK,
> +	RKISP1_EXT_PARAMS_BLOCK_TYPE_GOC,
> +	RKISP1_EXT_PARAMS_BLOCK_TYPE_DPF,
> +	RKISP1_EXT_PARAMS_BLOCK_TYPE_DPF_STRENGTH,
> +	RKISP1_EXT_PARAMS_BLOCK_TYPE_CPROC,
> +	RKISP1_EXT_PARAMS_BLOCK_TYPE_IE,
> +	RKISP1_EXT_PARAMS_BLOCK_TYPE_LSC,
> +	RKISP1_EXT_PARAMS_BLOCK_TYPE_AWB_MEAS,
> +	RKISP1_EXT_PARAMS_BLOCK_TYPE_HST_MEAS,
> +	RKISP1_EXT_PARAMS_BLOCK_TYPE_AEC_MEAS,
> +	RKISP1_EXT_PARAMS_BLOCK_TYPE_AFC_MEAS,
> +};
> +
> +#define RKISP1_EXT_PARAMS_FL_BLOCK_DISABLE	(1U << 0)
> +#define RKISP1_EXT_PARAMS_FL_BLOCK_ENABLE	(1U << 1)
> +
> +/**
> + * struct rkisp1_ext_params_block_header - RkISP1 extensible parameters 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 size and
> + * properly handle the block content by casting it to the correct block-specific
> + * type.
> + *
> + * The @type field is one of the values enumerated by
> + * :c:type:`rkisp1_ext_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 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. The
> + * driver ignores the rest of the block configuration structure in this case.
> + *
> + * 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_DISABLE 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 allowed
> + * 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:
> + *
> + * .. code-block:: c
> + *
> + *	void populate_bls(struct rkisp1_ext_params_block_header *block) {
> + *		struct rkisp1_ext_params_bls_config *bls =
> + *			(struct rkisp1_ext_params_bls_config *)block;
> + *
> + *		bls->header.type = RKISP1_EXT_PARAMS_BLOCK_ID_BLS;
> + *		bls->header.flags = RKISP1_EXT_PARAMS_FL_BLOCK_ENABLE;
> + *		bls->header.size = sizeof(*bls);
> + *
> + *		bls->config.enable_auto = 0;
> + *		bls->config.fixed_val.r = blackLevelRed_;
> + *		bls->config.fixed_val.gr = blackLevelGreenR_;
> + *		bls->config.fixed_val.gb = blackLevelGreenB_;
> + *		bls->config.fixed_val.b = 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
> + */
> +struct rkisp1_ext_params_block_header {
> +	__u16 type;
> +	__u16 flags;
> +	__u32 size;
> +};
> +
> +/**
> + * struct rkisp1_ext_params_bls_config - RkISP1 extensible params BLS config
> + *
> + * RkISP1 extensible parameters Black Level Subtraction configuration block.
> + * Identified by :c:type:`RKISP1_EXT_PARAMS_BLOCK_TYPE_BLS`.
> + *
> + * @header: The RkISP1 extensible parameters header, see
> + *	    :c:type:`rkisp1_ext_params_block_header`
> + * @config: Black Level Subtraction configuration, see
> + *	    :c:type:`rkisp1_cif_isp_bls_config`
> + */
> +struct rkisp1_ext_params_bls_config {
> +	struct rkisp1_ext_params_block_header header;
> +	struct rkisp1_cif_isp_bls_config config;
> +} __attribute__((aligned(8)));
> +
> +/**
> + * struct rkisp1_ext_params_dpcc_config - RkISP1 extensible params DPCC config
> + *
> + * RkISP1 extensible parameters Defective Pixel Cluster Correction configuration
> + * block. Identified by :c:type:`RKISP1_EXT_PARAMS_BLOCK_TYPE_DPCC`.
> + *
> + * @header: The RkISP1 extensible parameters header, see
> + *	    :c:type:`rkisp1_ext_params_block_header`
> + * @config: Defective Pixel Cluster Correction configuration, see
> + *	    :c:type:`rkisp1_cif_isp_dpcc_config`
> + */
> +struct rkisp1_ext_params_dpcc_config {
> +	struct rkisp1_ext_params_block_header header;
> +	struct rkisp1_cif_isp_dpcc_config config;
> +} __attribute__((aligned(8)));
> +
> +/**
> + * struct rkisp1_ext_params_sdg_config - RkISP1 extensible params SDG config
> + *
> + * RkISP1 extensible parameters Sensor Degamma configuration block. Identified
> + * by :c:type:`RKISP1_EXT_PARAMS_BLOCK_TYPE_SDG`.
> + *
> + * @header: The RkISP1 extensible parameters header, see
> + *	    :c:type:`rkisp1_ext_params_block_header`
> + * @config: Sensor Degamma configuration, see
> + *	    :c:type:`rkisp1_cif_isp_sdg_config`
> + */
> +struct rkisp1_ext_params_sdg_config {
> +	struct rkisp1_ext_params_block_header header;
> +	struct rkisp1_cif_isp_sdg_config config;
> +} __attribute__((aligned(8)));
> +
> +/**
> + * struct rkisp1_ext_params_lsc_config - RkISP1 extensible params LSC config
> + *
> + * RkISP1 extensible parameters Lens Shading Correction configuration block.
> + * Identified by :c:type:`RKISP1_EXT_PARAMS_BLOCK_TYPE_LSC`.
> + *
> + * @header: The RkISP1 extensible parameters header, see
> + *	    :c:type:`rkisp1_ext_params_block_header`
> + * @config: Lens Shading Correction configuration, see
> + *	    :c:type:`rkisp1_cif_isp_lsc_config`
> + */
> +struct rkisp1_ext_params_lsc_config {
> +	struct rkisp1_ext_params_block_header header;
> +	struct rkisp1_cif_isp_lsc_config config;
> +} __attribute__((aligned(8)));
> +
> +/**
> + * struct rkisp1_ext_params_awb_gain_config - RkISP1 extensible params AWB
> + *					      gain config
> + *
> + * RkISP1 extensible parameters Auto-White Balance Gains configuration block.
> + * Identified by :c:type:`RKISP1_EXT_PARAMS_BLOCK_TYPE_AWB_GAIN`.
> + *
> + * @header: The RkISP1 extensible parameters header, see
> + *	    :c:type:`rkisp1_ext_params_block_header`
> + * @config: Auto-White Balance Gains configuration, see
> + *	    :c:type:`rkisp1_cif_isp_awb_gain_config`
> + */
> +struct rkisp1_ext_params_awb_gain_config {
> +	struct rkisp1_ext_params_block_header header;
> +	struct rkisp1_cif_isp_awb_gain_config config;
> +} __attribute__((aligned(8)));
> +
> +/**
> + * struct rkisp1_ext_params_flt_config - RkISP1 extensible params FLT config
> + *
> + * RkISP1 extensible parameters Filter configuration block. Identified by
> + * :c:type:`RKISP1_EXT_PARAMS_BLOCK_TYPE_FLT`.
> + *
> + * @header: The RkISP1 extensible parameters header, see
> + *	    :c:type:`rkisp1_ext_params_block_header`
> + * @config: Filter configuration, see :c:type:`rkisp1_cif_isp_flt_config`
> + */
> +struct rkisp1_ext_params_flt_config {
> +	struct rkisp1_ext_params_block_header header;
> +	struct rkisp1_cif_isp_flt_config config;
> +} __attribute__((aligned(8)));
> +
> +/**
> + * struct rkisp1_ext_params_bdm_config - RkISP1 extensible params BDM config
> + *
> + * RkISP1 extensible parameters Demosaicing configuration block. Identified by
> + * :c:type:`RKISP1_EXT_PARAMS_BLOCK_TYPE_BDM`.
> + *
> + * @header: The RkISP1 extensible parameters header, see
> + *	    :c:type:`rkisp1_ext_params_block_header`
> + * @config: Demosaicing configuration, see :c:type:`rkisp1_cif_isp_bdm_config`
> + */
> +struct rkisp1_ext_params_bdm_config {
> +	struct rkisp1_ext_params_block_header header;
> +	struct rkisp1_cif_isp_bdm_config config;
> +} __attribute__((aligned(8)));
> +
> +/**
> + * struct rkisp1_ext_params_ctk_config - RkISP1 extensible params CTK config
> + *
> + * RkISP1 extensible parameters Cross-Talk configuration block. Identified by
> + * :c:type:`RKISP1_EXT_PARAMS_BLOCK_TYPE_CTK`.
> + *
> + * @header: The RkISP1 extensible parameters header, see
> + *	    :c:type:`rkisp1_ext_params_block_header`
> + * @config: Cross-Talk configuration, see :c:type:`rkisp1_cif_isp_ctk_config`
> + */
> +struct rkisp1_ext_params_ctk_config {
> +	struct rkisp1_ext_params_block_header header;
> +	struct rkisp1_cif_isp_ctk_config config;
> +} __attribute__((aligned(8)));
> +
> +/**
> + * struct rkisp1_ext_params_goc_config - RkISP1 extensible params GOC config
> + *
> + * RkISP1 extensible parameters Gamma-Out configuration block. Identified by
> + * :c:type:`RKISP1_EXT_PARAMS_BLOCK_TYPE_GOC`.
> + *
> + * @header: The RkISP1 extensible parameters header, see
> + *	    :c:type:`rkisp1_ext_params_block_header`
> + * @config: Gamma-Out configuration, see :c:type:`rkisp1_cif_isp_goc_config`
> + */
> +struct rkisp1_ext_params_goc_config {
> +	struct rkisp1_ext_params_block_header header;
> +	struct rkisp1_cif_isp_goc_config config;
> +} __attribute__((aligned(8)));
> +
> +/**
> + * struct rkisp1_ext_params_dpf_config - RkISP1 extensible params DPF config
> + *
> + * RkISP1 extensible parameters De-noise Pre-Filter configuration block.
> + * Identified by :c:type:`RKISP1_EXT_PARAMS_BLOCK_TYPE_DPF`.
> + *
> + * @header: The RkISP1 extensible parameters header, see
> + *	    :c:type:`rkisp1_ext_params_block_header`
> + * @config: De-noise Pre-Filter configuration, see
> + *	    :c:type:`rkisp1_cif_isp_dpf_config`
> + */
> +struct rkisp1_ext_params_dpf_config {
> +	struct rkisp1_ext_params_block_header header;
> +	struct rkisp1_cif_isp_dpf_config config;
> +} __attribute__((aligned(8)));
> +
> +/**
> + * struct rkisp1_ext_params_dpf_strength_config - RkISP1 extensible params DPF
> + *						  strength config
> + *
> + * RkISP1 extensible parameters De-noise Pre-Filter strength configuration
> + * block. Identified by :c:type:`RKISP1_EXT_PARAMS_BLOCK_TYPE_DPF_STRENGTH`.
> + *
> + * @header: The RkISP1 extensible parameters header, see
> + *	    :c:type:`rkisp1_ext_params_block_header`
> + * @config: De-noise Pre-Filter strength configuration, see
> + *	    :c:type:`rkisp1_cif_isp_dpf_strength_config`
> + */
> +struct rkisp1_ext_params_dpf_strength_config {
> +	struct rkisp1_ext_params_block_header header;
> +	struct rkisp1_cif_isp_dpf_strength_config config;
> +} __attribute__((aligned(8)));
> +
> +/**
> + * struct rkisp1_ext_params_cproc_config - RkISP1 extensible params CPROC config
> + *
> + * RkISP1 extensible parameters Color Processing configuration block.
> + * Identified by :c:type:`RKISP1_EXT_PARAMS_BLOCK_TYPE_CPROC`.
> + *
> + * @header: The RkISP1 extensible parameters header, see
> + *	    :c:type:`rkisp1_ext_params_block_header`
> + * @config: Color processing configuration, see
> + *	    :c:type:`rkisp1_cif_isp_cproc_config`
> + */
> +struct rkisp1_ext_params_cproc_config {
> +	struct rkisp1_ext_params_block_header header;
> +	struct rkisp1_cif_isp_cproc_config config;
> +} __attribute__((aligned(8)));
> +
> +/**
> + * struct rkisp1_ext_params_ie_config - RkISP1 extensible params IE config
> + *
> + * RkISP1 extensible parameters Image Effect configuration block. Identified by
> + * :c:type:`RKISP1_EXT_PARAMS_BLOCK_TYPE_IE`.
> + *
> + * @header: The RkISP1 extensible parameters header, see
> + *	    :c:type:`rkisp1_ext_params_block_header`
> + * @config: Image Effect configuration, see :c:type:`rkisp1_cif_isp_ie_config`
> + */
> +struct rkisp1_ext_params_ie_config {
> +	struct rkisp1_ext_params_block_header header;
> +	struct rkisp1_cif_isp_ie_config config;
> +} __attribute__((aligned(8)));
> +
> +/**
> + * struct rkisp1_ext_params_awb_meas_config - RkISP1 extensible params AWB
> + *					      Meas config
> + *
> + * RkISP1 extensible parameters Auto-White Balance Measurement configuration
> + * block. Identified by :c:type:`RKISP1_EXT_PARAMS_BLOCK_TYPE_AWB_MEAS`.
> + *
> + * @header: The RkISP1 extensible parameters header, see
> + *	    :c:type:`rkisp1_ext_params_block_header`
> + * @config: Auto-White Balance measure configuration, see
> + *	    :c:type:`rkisp1_cif_isp_awb_meas_config`
> + */
> +struct rkisp1_ext_params_awb_meas_config {
> +	struct rkisp1_ext_params_block_header header;
> +	struct rkisp1_cif_isp_awb_meas_config config;
> +} __attribute__((aligned(8)));
> +
> +/**
> + * struct rkisp1_ext_params_hst_config - RkISP1 extensible params Histogram config
> + *
> + * RkISP1 extensible parameters Histogram statistics configuration block.
> + * Identified by :c:type:`RKISP1_EXT_PARAMS_BLOCK_TYPE_HST_MEAS`.
> + *
> + * @header: The RkISP1 extensible parameters header, see
> + *	    :c:type:`rkisp1_ext_params_block_header`
> + * @config: Histogram statistics configuration, see
> + *	    :c:type:`rkisp1_cif_isp_hst_config`
> + */
> +struct rkisp1_ext_params_hst_config {
> +	struct rkisp1_ext_params_block_header header;
> +	struct rkisp1_cif_isp_hst_config config;
> +} __attribute__((aligned(8)));
> +
> +/**
> + * struct rkisp1_ext_params_aec_config - RkISP1 extensible params AEC config
> + *
> + * RkISP1 extensible parameters Auto-Exposure statistics configuration block.
> + * Identified by :c:type:`RKISP1_EXT_PARAMS_BLOCK_TYPE_AEC_MEAS`.
> + *
> + * @header: The RkISP1 extensible parameters header, see
> + *	    :c:type:`rkisp1_ext_params_block_header`
> + * @config: Auto-Exposure statistics configuration, see
> + *	    :c:type:`rkisp1_cif_isp_aec_config`
> + */
> +struct rkisp1_ext_params_aec_config {
> +	struct rkisp1_ext_params_block_header header;
> +	struct rkisp1_cif_isp_aec_config config;
> +} __attribute__((aligned(8)));
> +
> +/**
> + * struct rkisp1_ext_params_afc_config - RkISP1 extensible params AFC config
> + *
> + * RkISP1 extensible parameters Auto-Focus statistics configuration block.
> + * Identified by :c:type:`RKISP1_EXT_PARAMS_BLOCK_TYPE_AFC_MEAS`.
> + *
> + * @header: The RkISP1 extensible parameters header, see
> + *	    :c:type:`rkisp1_ext_params_block_header`
> + * @config: Auto-Focus statistics configuration, see
> + *	    :c:type:`rkisp1_cif_isp_afc_config`
> + */
> +struct rkisp1_ext_params_afc_config {
> +	struct rkisp1_ext_params_block_header header;
> +	struct rkisp1_cif_isp_afc_config config;
> +} __attribute__((aligned(8)));
> +
> +#define RKISP1_EXT_PARAMS_MAX_SIZE					\
> +	(sizeof(struct rkisp1_ext_params_bls_config)			+\
> +	sizeof(struct rkisp1_ext_params_dpcc_config)			+\
> +	sizeof(struct rkisp1_ext_params_sdg_config)			+\
> +	sizeof(struct rkisp1_ext_params_lsc_config)			+\
> +	sizeof(struct rkisp1_ext_params_awb_gain_config)		+\
> +	sizeof(struct rkisp1_ext_params_flt_config)			+\
> +	sizeof(struct rkisp1_ext_params_bdm_config)			+\
> +	sizeof(struct rkisp1_ext_params_ctk_config)			+\
> +	sizeof(struct rkisp1_ext_params_goc_config)			+\
> +	sizeof(struct rkisp1_ext_params_dpf_config)			+\
> +	sizeof(struct rkisp1_ext_params_dpf_strength_config)		+\
> +	sizeof(struct rkisp1_ext_params_cproc_config)			+\
> +	sizeof(struct rkisp1_ext_params_ie_config)			+\
> +	sizeof(struct rkisp1_ext_params_awb_meas_config)		+\
> +	sizeof(struct rkisp1_ext_params_hst_config)			+\
> +	sizeof(struct rkisp1_ext_params_aec_config)			+\
> +	sizeof(struct rkisp1_ext_params_afc_config))
> +
> +/**
> + * enum rksip1_ext_param_buffer_version - RkISP1 extensible parameters version
> + *
> + * @RKISP1_EXT_PARAM_BUFFER_V1: First version of RkISP1 extensible parameters
> + */
> +enum rksip1_ext_param_buffer_version {
> +	RKISP1_EXT_PARAM_BUFFER_V1 = 1,

I see no check against this in the rkisp1 code. Shouldn't this be checked?
If the version is unsupported, then just return an error.

Also, how does userspace know which version(s) is/are supported by the driver?

Regards,

	Hans

> +};
> +
> +/**
> + * struct rkisp1_ext_params_cfg - RkISP1 extensible parameters configuration
> + *
> + * This struct contains the configuration parameters of the RkISP1 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:`rkisp1_ext_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.
> + *
> + * 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
> + * 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 @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 -------------------+
> + *	| version = RKISP_EXT_PARAMS_BUFFER_V1;                               |
> + *	| data_size = sizeof(struct rkisp1_ext_params_bls_config)             |
> + *	|           + sizeof(struct rkisp1_ext_params_dpcc_config);           |
> + *	| +------------------------- data  ---------------------------------+ |
> + *	| | +------------- struct rkisp1_ext_params_bls_config -----------+ | |
> + *	| | | +-------- struct rkisp1_ext_params_block_header  ---------+ | | |
> + *	| | | | type = RKISP1_EXT_PARAMS_BLOCK_TYPE_BLS;                | | | |
> + *	| | | | flags = RKISP1_EXT_PARAMS_FL_BLOCK_ENABLE;              | | | |
> + *	| | | | size = sizeof(struct rkisp1_ext_params_bls_config);     | | | |
> + *	| | | +---------------------------------------------------------+ | | |
> + *	| | | +---------- struct rkisp1_cif_isp_bls_config -------------+ | | |
> + *	| | | | enable_auto = 0;                                        | | | |
> + *	| | | | fixed_val.r = 256;                                      | | | |
> + *	| | | | fixed_val.gr = 256;                                     | | | |
> + *	| | | | fixed_val.gb = 256;                                     | | | |
> + *	| | | | fixed_val.b = 256;                                      | | | |
> + *	| | | +---------------------------------------------------------+ | | |
> + *	| | +------------ struct rkisp1_ext_params_dpcc_config -----------+ | |
> + *	| | | +-------- struct rkisp1_ext_params_block_header  ---------+ | | |
> + *	| | | | type = RKISP1_EXT_PARAMS_BLOCK_TYPE_DPCC;               | | | |
> + *	| | | | flags = RKISP1_EXT_PARAMS_FL_BLOCK_ENABLE;              | | | |
> + *	| | | | size = sizeof(struct rkisp1_ext_params_dpcc_config);    | | | |
> + *	| | | +---------------------------------------------------------+ | | |
> + *	| | | +---------- struct rkisp1_cif_isp_dpcc_config ------------+ | | |
> + *	| | | | mode = RKISP1_CIF_ISP_DPCC_MODE_STAGE1_ENABLE;          | | | |
> + *	| | | | output_mode =                                           | | | |
> + *	| | | |   RKISP1_CIF_ISP_DPCC_OUTPUT_MODE_STAGE1_INCL_G_CENTER; | | | |
> + *	| | | | set_use = ... ;                                         | | | |
> + *	| | | | ...  = ... ;                                            | | | |
> + *	| | | +---------------------------------------------------------+ | | |
> + *	| | +-------------------------------------------------------------+ | |
> + *	| +-----------------------------------------------------------------+ |
> + *	+---------------------------------------------------------------------+
> + *
> + * @version: The RkISP1 extensible parameters buffer version, see
> + *	     :c:type:`rksip1_ext_param_buffer_version`
> + * @data_size: The RkISP1 configuration data effective size, excluding this
> + *	       header
> + * @data: The RkISP1 extensible configuration data blocks
> + */
> +struct rkisp1_ext_params_cfg {
> +	__u32 version;
> +	__u32 data_size;
> +	__u8 data[RKISP1_EXT_PARAMS_MAX_SIZE];
> +};
> +
>  #endif /* _UAPI_RKISP1_CONFIG_H */
Jacopo Mondi Aug. 8, 2024, 7:24 a.m. UTC | #2
Hi Hans

On Thu, Aug 08, 2024 at 08:31:58AM GMT, Hans Verkuil wrote:
> On 07/08/2024 23:22, Jacopo Mondi wrote:
> > Add to the rkisp1-config.h header data types and documentation of
> > the extensible parameters format.
> >
> > Signed-off-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
> > Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> > Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>
> > Tested-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
> > Acked-by: Sakari Ailus <sakari.ailus@linux.intel.com>
> > ---
> >  include/uapi/linux/rkisp1-config.h | 485 +++++++++++++++++++++++++++++
> >  1 file changed, 485 insertions(+)
> >
> > diff --git a/include/uapi/linux/rkisp1-config.h b/include/uapi/linux/rkisp1-config.h
> > index 6eeaf8bf2362..14a23fd9a745 100644
> > --- a/include/uapi/linux/rkisp1-config.h
> > +++ b/include/uapi/linux/rkisp1-config.h
> > @@ -996,4 +996,489 @@ struct rkisp1_stat_buffer {
> >  	struct rkisp1_cif_isp_stat params;
> >  };
> >
> > +/*---------- PART3: Extensible Configuration Parameters  ------------*/
> > +
> > +/**
> > + * enum rkisp1_ext_params_block_type - RkISP1 extensible params block type
> > + *
> > + * @RKISP1_EXT_PARAMS_BLOCK_TYPE_BLS: Black level subtraction
> > + * @RKISP1_EXT_PARAMS_BLOCK_TYPE_DPCC: Defect pixel cluster correction
> > + * @RKISP1_EXT_PARAMS_BLOCK_TYPE_SDG: Sensor de-gamma
> > + * @RKISP1_EXT_PARAMS_BLOCK_TYPE_AWB_GAIN: Auto white balance gains
> > + * @RKISP1_EXT_PARAMS_BLOCK_TYPE_FLT: ISP filtering
> > + * @RKISP1_EXT_PARAMS_BLOCK_TYPE_BDM: Bayer de-mosaic
> > + * @RKISP1_EXT_PARAMS_BLOCK_TYPE_CTK: Cross-talk correction
> > + * @RKISP1_EXT_PARAMS_BLOCK_TYPE_GOC: Gamma out correction
> > + * @RKISP1_EXT_PARAMS_BLOCK_TYPE_DPF: De-noise pre-filter
> > + * @RKISP1_EXT_PARAMS_BLOCK_TYPE_DPF_STRENGTH: De-noise pre-filter strength
> > + * @RKISP1_EXT_PARAMS_BLOCK_TYPE_CPROC: Color processing
> > + * @RKISP1_EXT_PARAMS_BLOCK_TYPE_IE: Image effects
> > + * @RKISP1_EXT_PARAMS_BLOCK_TYPE_LSC: Lens shading correction
> > + * @RKISP1_EXT_PARAMS_BLOCK_TYPE_AWB_MEAS: Auto white balance statistics
> > + * @RKISP1_EXT_PARAMS_BLOCK_TYPE_HST_MEAS: Histogram statistics
> > + * @RKISP1_EXT_PARAMS_BLOCK_TYPE_AEC_MEAS: Auto exposure statistics
> > + * @RKISP1_EXT_PARAMS_BLOCK_TYPE_AFC_MEAS: Auto-focus statistics
> > + */
> > +enum rkisp1_ext_params_block_type {
> > +	RKISP1_EXT_PARAMS_BLOCK_TYPE_BLS,
> > +	RKISP1_EXT_PARAMS_BLOCK_TYPE_DPCC,
> > +	RKISP1_EXT_PARAMS_BLOCK_TYPE_SDG,
> > +	RKISP1_EXT_PARAMS_BLOCK_TYPE_AWB_GAIN,
> > +	RKISP1_EXT_PARAMS_BLOCK_TYPE_FLT,
> > +	RKISP1_EXT_PARAMS_BLOCK_TYPE_BDM,
> > +	RKISP1_EXT_PARAMS_BLOCK_TYPE_CTK,
> > +	RKISP1_EXT_PARAMS_BLOCK_TYPE_GOC,
> > +	RKISP1_EXT_PARAMS_BLOCK_TYPE_DPF,
> > +	RKISP1_EXT_PARAMS_BLOCK_TYPE_DPF_STRENGTH,
> > +	RKISP1_EXT_PARAMS_BLOCK_TYPE_CPROC,
> > +	RKISP1_EXT_PARAMS_BLOCK_TYPE_IE,
> > +	RKISP1_EXT_PARAMS_BLOCK_TYPE_LSC,
> > +	RKISP1_EXT_PARAMS_BLOCK_TYPE_AWB_MEAS,
> > +	RKISP1_EXT_PARAMS_BLOCK_TYPE_HST_MEAS,
> > +	RKISP1_EXT_PARAMS_BLOCK_TYPE_AEC_MEAS,
> > +	RKISP1_EXT_PARAMS_BLOCK_TYPE_AFC_MEAS,
> > +};
> > +
> > +#define RKISP1_EXT_PARAMS_FL_BLOCK_DISABLE	(1U << 0)
> > +#define RKISP1_EXT_PARAMS_FL_BLOCK_ENABLE	(1U << 1)
> > +
> > +/**
> > + * struct rkisp1_ext_params_block_header - RkISP1 extensible parameters 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 size and
> > + * properly handle the block content by casting it to the correct block-specific
> > + * type.
> > + *
> > + * The @type field is one of the values enumerated by
> > + * :c:type:`rkisp1_ext_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 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. The
> > + * driver ignores the rest of the block configuration structure in this case.
> > + *
> > + * 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_DISABLE 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 allowed
> > + * 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:
> > + *
> > + * .. code-block:: c
> > + *
> > + *	void populate_bls(struct rkisp1_ext_params_block_header *block) {
> > + *		struct rkisp1_ext_params_bls_config *bls =
> > + *			(struct rkisp1_ext_params_bls_config *)block;
> > + *
> > + *		bls->header.type = RKISP1_EXT_PARAMS_BLOCK_ID_BLS;
> > + *		bls->header.flags = RKISP1_EXT_PARAMS_FL_BLOCK_ENABLE;
> > + *		bls->header.size = sizeof(*bls);
> > + *
> > + *		bls->config.enable_auto = 0;
> > + *		bls->config.fixed_val.r = blackLevelRed_;
> > + *		bls->config.fixed_val.gr = blackLevelGreenR_;
> > + *		bls->config.fixed_val.gb = blackLevelGreenB_;
> > + *		bls->config.fixed_val.b = 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
> > + */
> > +struct rkisp1_ext_params_block_header {
> > +	__u16 type;
> > +	__u16 flags;
> > +	__u32 size;
> > +};
> > +
> > +/**
> > + * struct rkisp1_ext_params_bls_config - RkISP1 extensible params BLS config
> > + *
> > + * RkISP1 extensible parameters Black Level Subtraction configuration block.
> > + * Identified by :c:type:`RKISP1_EXT_PARAMS_BLOCK_TYPE_BLS`.
> > + *
> > + * @header: The RkISP1 extensible parameters header, see
> > + *	    :c:type:`rkisp1_ext_params_block_header`
> > + * @config: Black Level Subtraction configuration, see
> > + *	    :c:type:`rkisp1_cif_isp_bls_config`
> > + */
> > +struct rkisp1_ext_params_bls_config {
> > +	struct rkisp1_ext_params_block_header header;
> > +	struct rkisp1_cif_isp_bls_config config;
> > +} __attribute__((aligned(8)));
> > +
> > +/**
> > + * struct rkisp1_ext_params_dpcc_config - RkISP1 extensible params DPCC config
> > + *
> > + * RkISP1 extensible parameters Defective Pixel Cluster Correction configuration
> > + * block. Identified by :c:type:`RKISP1_EXT_PARAMS_BLOCK_TYPE_DPCC`.
> > + *
> > + * @header: The RkISP1 extensible parameters header, see
> > + *	    :c:type:`rkisp1_ext_params_block_header`
> > + * @config: Defective Pixel Cluster Correction configuration, see
> > + *	    :c:type:`rkisp1_cif_isp_dpcc_config`
> > + */
> > +struct rkisp1_ext_params_dpcc_config {
> > +	struct rkisp1_ext_params_block_header header;
> > +	struct rkisp1_cif_isp_dpcc_config config;
> > +} __attribute__((aligned(8)));
> > +
> > +/**
> > + * struct rkisp1_ext_params_sdg_config - RkISP1 extensible params SDG config
> > + *
> > + * RkISP1 extensible parameters Sensor Degamma configuration block. Identified
> > + * by :c:type:`RKISP1_EXT_PARAMS_BLOCK_TYPE_SDG`.
> > + *
> > + * @header: The RkISP1 extensible parameters header, see
> > + *	    :c:type:`rkisp1_ext_params_block_header`
> > + * @config: Sensor Degamma configuration, see
> > + *	    :c:type:`rkisp1_cif_isp_sdg_config`
> > + */
> > +struct rkisp1_ext_params_sdg_config {
> > +	struct rkisp1_ext_params_block_header header;
> > +	struct rkisp1_cif_isp_sdg_config config;
> > +} __attribute__((aligned(8)));
> > +
> > +/**
> > + * struct rkisp1_ext_params_lsc_config - RkISP1 extensible params LSC config
> > + *
> > + * RkISP1 extensible parameters Lens Shading Correction configuration block.
> > + * Identified by :c:type:`RKISP1_EXT_PARAMS_BLOCK_TYPE_LSC`.
> > + *
> > + * @header: The RkISP1 extensible parameters header, see
> > + *	    :c:type:`rkisp1_ext_params_block_header`
> > + * @config: Lens Shading Correction configuration, see
> > + *	    :c:type:`rkisp1_cif_isp_lsc_config`
> > + */
> > +struct rkisp1_ext_params_lsc_config {
> > +	struct rkisp1_ext_params_block_header header;
> > +	struct rkisp1_cif_isp_lsc_config config;
> > +} __attribute__((aligned(8)));
> > +
> > +/**
> > + * struct rkisp1_ext_params_awb_gain_config - RkISP1 extensible params AWB
> > + *					      gain config
> > + *
> > + * RkISP1 extensible parameters Auto-White Balance Gains configuration block.
> > + * Identified by :c:type:`RKISP1_EXT_PARAMS_BLOCK_TYPE_AWB_GAIN`.
> > + *
> > + * @header: The RkISP1 extensible parameters header, see
> > + *	    :c:type:`rkisp1_ext_params_block_header`
> > + * @config: Auto-White Balance Gains configuration, see
> > + *	    :c:type:`rkisp1_cif_isp_awb_gain_config`
> > + */
> > +struct rkisp1_ext_params_awb_gain_config {
> > +	struct rkisp1_ext_params_block_header header;
> > +	struct rkisp1_cif_isp_awb_gain_config config;
> > +} __attribute__((aligned(8)));
> > +
> > +/**
> > + * struct rkisp1_ext_params_flt_config - RkISP1 extensible params FLT config
> > + *
> > + * RkISP1 extensible parameters Filter configuration block. Identified by
> > + * :c:type:`RKISP1_EXT_PARAMS_BLOCK_TYPE_FLT`.
> > + *
> > + * @header: The RkISP1 extensible parameters header, see
> > + *	    :c:type:`rkisp1_ext_params_block_header`
> > + * @config: Filter configuration, see :c:type:`rkisp1_cif_isp_flt_config`
> > + */
> > +struct rkisp1_ext_params_flt_config {
> > +	struct rkisp1_ext_params_block_header header;
> > +	struct rkisp1_cif_isp_flt_config config;
> > +} __attribute__((aligned(8)));
> > +
> > +/**
> > + * struct rkisp1_ext_params_bdm_config - RkISP1 extensible params BDM config
> > + *
> > + * RkISP1 extensible parameters Demosaicing configuration block. Identified by
> > + * :c:type:`RKISP1_EXT_PARAMS_BLOCK_TYPE_BDM`.
> > + *
> > + * @header: The RkISP1 extensible parameters header, see
> > + *	    :c:type:`rkisp1_ext_params_block_header`
> > + * @config: Demosaicing configuration, see :c:type:`rkisp1_cif_isp_bdm_config`
> > + */
> > +struct rkisp1_ext_params_bdm_config {
> > +	struct rkisp1_ext_params_block_header header;
> > +	struct rkisp1_cif_isp_bdm_config config;
> > +} __attribute__((aligned(8)));
> > +
> > +/**
> > + * struct rkisp1_ext_params_ctk_config - RkISP1 extensible params CTK config
> > + *
> > + * RkISP1 extensible parameters Cross-Talk configuration block. Identified by
> > + * :c:type:`RKISP1_EXT_PARAMS_BLOCK_TYPE_CTK`.
> > + *
> > + * @header: The RkISP1 extensible parameters header, see
> > + *	    :c:type:`rkisp1_ext_params_block_header`
> > + * @config: Cross-Talk configuration, see :c:type:`rkisp1_cif_isp_ctk_config`
> > + */
> > +struct rkisp1_ext_params_ctk_config {
> > +	struct rkisp1_ext_params_block_header header;
> > +	struct rkisp1_cif_isp_ctk_config config;
> > +} __attribute__((aligned(8)));
> > +
> > +/**
> > + * struct rkisp1_ext_params_goc_config - RkISP1 extensible params GOC config
> > + *
> > + * RkISP1 extensible parameters Gamma-Out configuration block. Identified by
> > + * :c:type:`RKISP1_EXT_PARAMS_BLOCK_TYPE_GOC`.
> > + *
> > + * @header: The RkISP1 extensible parameters header, see
> > + *	    :c:type:`rkisp1_ext_params_block_header`
> > + * @config: Gamma-Out configuration, see :c:type:`rkisp1_cif_isp_goc_config`
> > + */
> > +struct rkisp1_ext_params_goc_config {
> > +	struct rkisp1_ext_params_block_header header;
> > +	struct rkisp1_cif_isp_goc_config config;
> > +} __attribute__((aligned(8)));
> > +
> > +/**
> > + * struct rkisp1_ext_params_dpf_config - RkISP1 extensible params DPF config
> > + *
> > + * RkISP1 extensible parameters De-noise Pre-Filter configuration block.
> > + * Identified by :c:type:`RKISP1_EXT_PARAMS_BLOCK_TYPE_DPF`.
> > + *
> > + * @header: The RkISP1 extensible parameters header, see
> > + *	    :c:type:`rkisp1_ext_params_block_header`
> > + * @config: De-noise Pre-Filter configuration, see
> > + *	    :c:type:`rkisp1_cif_isp_dpf_config`
> > + */
> > +struct rkisp1_ext_params_dpf_config {
> > +	struct rkisp1_ext_params_block_header header;
> > +	struct rkisp1_cif_isp_dpf_config config;
> > +} __attribute__((aligned(8)));
> > +
> > +/**
> > + * struct rkisp1_ext_params_dpf_strength_config - RkISP1 extensible params DPF
> > + *						  strength config
> > + *
> > + * RkISP1 extensible parameters De-noise Pre-Filter strength configuration
> > + * block. Identified by :c:type:`RKISP1_EXT_PARAMS_BLOCK_TYPE_DPF_STRENGTH`.
> > + *
> > + * @header: The RkISP1 extensible parameters header, see
> > + *	    :c:type:`rkisp1_ext_params_block_header`
> > + * @config: De-noise Pre-Filter strength configuration, see
> > + *	    :c:type:`rkisp1_cif_isp_dpf_strength_config`
> > + */
> > +struct rkisp1_ext_params_dpf_strength_config {
> > +	struct rkisp1_ext_params_block_header header;
> > +	struct rkisp1_cif_isp_dpf_strength_config config;
> > +} __attribute__((aligned(8)));
> > +
> > +/**
> > + * struct rkisp1_ext_params_cproc_config - RkISP1 extensible params CPROC config
> > + *
> > + * RkISP1 extensible parameters Color Processing configuration block.
> > + * Identified by :c:type:`RKISP1_EXT_PARAMS_BLOCK_TYPE_CPROC`.
> > + *
> > + * @header: The RkISP1 extensible parameters header, see
> > + *	    :c:type:`rkisp1_ext_params_block_header`
> > + * @config: Color processing configuration, see
> > + *	    :c:type:`rkisp1_cif_isp_cproc_config`
> > + */
> > +struct rkisp1_ext_params_cproc_config {
> > +	struct rkisp1_ext_params_block_header header;
> > +	struct rkisp1_cif_isp_cproc_config config;
> > +} __attribute__((aligned(8)));
> > +
> > +/**
> > + * struct rkisp1_ext_params_ie_config - RkISP1 extensible params IE config
> > + *
> > + * RkISP1 extensible parameters Image Effect configuration block. Identified by
> > + * :c:type:`RKISP1_EXT_PARAMS_BLOCK_TYPE_IE`.
> > + *
> > + * @header: The RkISP1 extensible parameters header, see
> > + *	    :c:type:`rkisp1_ext_params_block_header`
> > + * @config: Image Effect configuration, see :c:type:`rkisp1_cif_isp_ie_config`
> > + */
> > +struct rkisp1_ext_params_ie_config {
> > +	struct rkisp1_ext_params_block_header header;
> > +	struct rkisp1_cif_isp_ie_config config;
> > +} __attribute__((aligned(8)));
> > +
> > +/**
> > + * struct rkisp1_ext_params_awb_meas_config - RkISP1 extensible params AWB
> > + *					      Meas config
> > + *
> > + * RkISP1 extensible parameters Auto-White Balance Measurement configuration
> > + * block. Identified by :c:type:`RKISP1_EXT_PARAMS_BLOCK_TYPE_AWB_MEAS`.
> > + *
> > + * @header: The RkISP1 extensible parameters header, see
> > + *	    :c:type:`rkisp1_ext_params_block_header`
> > + * @config: Auto-White Balance measure configuration, see
> > + *	    :c:type:`rkisp1_cif_isp_awb_meas_config`
> > + */
> > +struct rkisp1_ext_params_awb_meas_config {
> > +	struct rkisp1_ext_params_block_header header;
> > +	struct rkisp1_cif_isp_awb_meas_config config;
> > +} __attribute__((aligned(8)));
> > +
> > +/**
> > + * struct rkisp1_ext_params_hst_config - RkISP1 extensible params Histogram config
> > + *
> > + * RkISP1 extensible parameters Histogram statistics configuration block.
> > + * Identified by :c:type:`RKISP1_EXT_PARAMS_BLOCK_TYPE_HST_MEAS`.
> > + *
> > + * @header: The RkISP1 extensible parameters header, see
> > + *	    :c:type:`rkisp1_ext_params_block_header`
> > + * @config: Histogram statistics configuration, see
> > + *	    :c:type:`rkisp1_cif_isp_hst_config`
> > + */
> > +struct rkisp1_ext_params_hst_config {
> > +	struct rkisp1_ext_params_block_header header;
> > +	struct rkisp1_cif_isp_hst_config config;
> > +} __attribute__((aligned(8)));
> > +
> > +/**
> > + * struct rkisp1_ext_params_aec_config - RkISP1 extensible params AEC config
> > + *
> > + * RkISP1 extensible parameters Auto-Exposure statistics configuration block.
> > + * Identified by :c:type:`RKISP1_EXT_PARAMS_BLOCK_TYPE_AEC_MEAS`.
> > + *
> > + * @header: The RkISP1 extensible parameters header, see
> > + *	    :c:type:`rkisp1_ext_params_block_header`
> > + * @config: Auto-Exposure statistics configuration, see
> > + *	    :c:type:`rkisp1_cif_isp_aec_config`
> > + */
> > +struct rkisp1_ext_params_aec_config {
> > +	struct rkisp1_ext_params_block_header header;
> > +	struct rkisp1_cif_isp_aec_config config;
> > +} __attribute__((aligned(8)));
> > +
> > +/**
> > + * struct rkisp1_ext_params_afc_config - RkISP1 extensible params AFC config
> > + *
> > + * RkISP1 extensible parameters Auto-Focus statistics configuration block.
> > + * Identified by :c:type:`RKISP1_EXT_PARAMS_BLOCK_TYPE_AFC_MEAS`.
> > + *
> > + * @header: The RkISP1 extensible parameters header, see
> > + *	    :c:type:`rkisp1_ext_params_block_header`
> > + * @config: Auto-Focus statistics configuration, see
> > + *	    :c:type:`rkisp1_cif_isp_afc_config`
> > + */
> > +struct rkisp1_ext_params_afc_config {
> > +	struct rkisp1_ext_params_block_header header;
> > +	struct rkisp1_cif_isp_afc_config config;
> > +} __attribute__((aligned(8)));
> > +
> > +#define RKISP1_EXT_PARAMS_MAX_SIZE					\
> > +	(sizeof(struct rkisp1_ext_params_bls_config)			+\
> > +	sizeof(struct rkisp1_ext_params_dpcc_config)			+\
> > +	sizeof(struct rkisp1_ext_params_sdg_config)			+\
> > +	sizeof(struct rkisp1_ext_params_lsc_config)			+\
> > +	sizeof(struct rkisp1_ext_params_awb_gain_config)		+\
> > +	sizeof(struct rkisp1_ext_params_flt_config)			+\
> > +	sizeof(struct rkisp1_ext_params_bdm_config)			+\
> > +	sizeof(struct rkisp1_ext_params_ctk_config)			+\
> > +	sizeof(struct rkisp1_ext_params_goc_config)			+\
> > +	sizeof(struct rkisp1_ext_params_dpf_config)			+\
> > +	sizeof(struct rkisp1_ext_params_dpf_strength_config)		+\
> > +	sizeof(struct rkisp1_ext_params_cproc_config)			+\
> > +	sizeof(struct rkisp1_ext_params_ie_config)			+\
> > +	sizeof(struct rkisp1_ext_params_awb_meas_config)		+\
> > +	sizeof(struct rkisp1_ext_params_hst_config)			+\
> > +	sizeof(struct rkisp1_ext_params_aec_config)			+\
> > +	sizeof(struct rkisp1_ext_params_afc_config))
> > +
> > +/**
> > + * enum rksip1_ext_param_buffer_version - RkISP1 extensible parameters version
> > + *
> > + * @RKISP1_EXT_PARAM_BUFFER_V1: First version of RkISP1 extensible parameters
> > + */
> > +enum rksip1_ext_param_buffer_version {
> > +	RKISP1_EXT_PARAM_BUFFER_V1 = 1,
>
> I see no check against this in the rkisp1 code. Shouldn't this be checked?
> If the version is unsupported, then just return an error.
>

Do we need this for the first version ? There are no other versions
userspace can use at the moment. I can add a check during validation
though.

> Also, how does userspace know which version(s) is/are supported by the driver?
>

Good question, there is no API for that atm. Defining a new format
version should only happen when a non-backward compatible change to
the format is made. I understand an application can be compiled
against a newer kernel header that provides a new format version but
then run on an older kernel where the new format is not supported.

Probably userspace should be able to identify what versions are
supported by the driver it runs with and use the most appropriate one
by selecting it at runtime.

What API would you use for that ? Is this something required for this
first version where a single format version is available ?

> Regards,
>
> 	Hans
>
> > +};
> > +
> > +/**
> > + * struct rkisp1_ext_params_cfg - RkISP1 extensible parameters configuration
> > + *
> > + * This struct contains the configuration parameters of the RkISP1 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:`rkisp1_ext_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.
> > + *
> > + * 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
> > + * 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 @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 -------------------+
> > + *	| version = RKISP_EXT_PARAMS_BUFFER_V1;                               |
> > + *	| data_size = sizeof(struct rkisp1_ext_params_bls_config)             |
> > + *	|           + sizeof(struct rkisp1_ext_params_dpcc_config);           |
> > + *	| +------------------------- data  ---------------------------------+ |
> > + *	| | +------------- struct rkisp1_ext_params_bls_config -----------+ | |
> > + *	| | | +-------- struct rkisp1_ext_params_block_header  ---------+ | | |
> > + *	| | | | type = RKISP1_EXT_PARAMS_BLOCK_TYPE_BLS;                | | | |
> > + *	| | | | flags = RKISP1_EXT_PARAMS_FL_BLOCK_ENABLE;              | | | |
> > + *	| | | | size = sizeof(struct rkisp1_ext_params_bls_config);     | | | |
> > + *	| | | +---------------------------------------------------------+ | | |
> > + *	| | | +---------- struct rkisp1_cif_isp_bls_config -------------+ | | |
> > + *	| | | | enable_auto = 0;                                        | | | |
> > + *	| | | | fixed_val.r = 256;                                      | | | |
> > + *	| | | | fixed_val.gr = 256;                                     | | | |
> > + *	| | | | fixed_val.gb = 256;                                     | | | |
> > + *	| | | | fixed_val.b = 256;                                      | | | |
> > + *	| | | +---------------------------------------------------------+ | | |
> > + *	| | +------------ struct rkisp1_ext_params_dpcc_config -----------+ | |
> > + *	| | | +-------- struct rkisp1_ext_params_block_header  ---------+ | | |
> > + *	| | | | type = RKISP1_EXT_PARAMS_BLOCK_TYPE_DPCC;               | | | |
> > + *	| | | | flags = RKISP1_EXT_PARAMS_FL_BLOCK_ENABLE;              | | | |
> > + *	| | | | size = sizeof(struct rkisp1_ext_params_dpcc_config);    | | | |
> > + *	| | | +---------------------------------------------------------+ | | |
> > + *	| | | +---------- struct rkisp1_cif_isp_dpcc_config ------------+ | | |
> > + *	| | | | mode = RKISP1_CIF_ISP_DPCC_MODE_STAGE1_ENABLE;          | | | |
> > + *	| | | | output_mode =                                           | | | |
> > + *	| | | |   RKISP1_CIF_ISP_DPCC_OUTPUT_MODE_STAGE1_INCL_G_CENTER; | | | |
> > + *	| | | | set_use = ... ;                                         | | | |
> > + *	| | | | ...  = ... ;                                            | | | |
> > + *	| | | +---------------------------------------------------------+ | | |
> > + *	| | +-------------------------------------------------------------+ | |
> > + *	| +-----------------------------------------------------------------+ |
> > + *	+---------------------------------------------------------------------+
> > + *
> > + * @version: The RkISP1 extensible parameters buffer version, see
> > + *	     :c:type:`rksip1_ext_param_buffer_version`
> > + * @data_size: The RkISP1 configuration data effective size, excluding this
> > + *	       header
> > + * @data: The RkISP1 extensible configuration data blocks
> > + */
> > +struct rkisp1_ext_params_cfg {
> > +	__u32 version;
> > +	__u32 data_size;
> > +	__u8 data[RKISP1_EXT_PARAMS_MAX_SIZE];
> > +};
> > +
> >  #endif /* _UAPI_RKISP1_CONFIG_H */
>
Hans Verkuil Aug. 8, 2024, 7:41 a.m. UTC | #3
On 08/08/2024 09:24, Jacopo Mondi wrote:
> Hi Hans
> 
> On Thu, Aug 08, 2024 at 08:31:58AM GMT, Hans Verkuil wrote:
>> On 07/08/2024 23:22, Jacopo Mondi wrote:
>>> Add to the rkisp1-config.h header data types and documentation of
>>> the extensible parameters format.
>>>
>>> Signed-off-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
>>> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
>>> Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>
>>> Tested-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
>>> Acked-by: Sakari Ailus <sakari.ailus@linux.intel.com>
>>> ---
>>>  include/uapi/linux/rkisp1-config.h | 485 +++++++++++++++++++++++++++++
>>>  1 file changed, 485 insertions(+)
>>>
>>> diff --git a/include/uapi/linux/rkisp1-config.h b/include/uapi/linux/rkisp1-config.h
>>> index 6eeaf8bf2362..14a23fd9a745 100644
>>> --- a/include/uapi/linux/rkisp1-config.h
>>> +++ b/include/uapi/linux/rkisp1-config.h
>>> @@ -996,4 +996,489 @@ struct rkisp1_stat_buffer {
>>>  	struct rkisp1_cif_isp_stat params;
>>>  };
>>>
>>> +/*---------- PART3: Extensible Configuration Parameters  ------------*/
>>> +
>>> +/**
>>> + * enum rkisp1_ext_params_block_type - RkISP1 extensible params block type
>>> + *
>>> + * @RKISP1_EXT_PARAMS_BLOCK_TYPE_BLS: Black level subtraction
>>> + * @RKISP1_EXT_PARAMS_BLOCK_TYPE_DPCC: Defect pixel cluster correction
>>> + * @RKISP1_EXT_PARAMS_BLOCK_TYPE_SDG: Sensor de-gamma
>>> + * @RKISP1_EXT_PARAMS_BLOCK_TYPE_AWB_GAIN: Auto white balance gains
>>> + * @RKISP1_EXT_PARAMS_BLOCK_TYPE_FLT: ISP filtering
>>> + * @RKISP1_EXT_PARAMS_BLOCK_TYPE_BDM: Bayer de-mosaic
>>> + * @RKISP1_EXT_PARAMS_BLOCK_TYPE_CTK: Cross-talk correction
>>> + * @RKISP1_EXT_PARAMS_BLOCK_TYPE_GOC: Gamma out correction
>>> + * @RKISP1_EXT_PARAMS_BLOCK_TYPE_DPF: De-noise pre-filter
>>> + * @RKISP1_EXT_PARAMS_BLOCK_TYPE_DPF_STRENGTH: De-noise pre-filter strength
>>> + * @RKISP1_EXT_PARAMS_BLOCK_TYPE_CPROC: Color processing
>>> + * @RKISP1_EXT_PARAMS_BLOCK_TYPE_IE: Image effects
>>> + * @RKISP1_EXT_PARAMS_BLOCK_TYPE_LSC: Lens shading correction
>>> + * @RKISP1_EXT_PARAMS_BLOCK_TYPE_AWB_MEAS: Auto white balance statistics
>>> + * @RKISP1_EXT_PARAMS_BLOCK_TYPE_HST_MEAS: Histogram statistics
>>> + * @RKISP1_EXT_PARAMS_BLOCK_TYPE_AEC_MEAS: Auto exposure statistics
>>> + * @RKISP1_EXT_PARAMS_BLOCK_TYPE_AFC_MEAS: Auto-focus statistics
>>> + */
>>> +enum rkisp1_ext_params_block_type {
>>> +	RKISP1_EXT_PARAMS_BLOCK_TYPE_BLS,
>>> +	RKISP1_EXT_PARAMS_BLOCK_TYPE_DPCC,
>>> +	RKISP1_EXT_PARAMS_BLOCK_TYPE_SDG,
>>> +	RKISP1_EXT_PARAMS_BLOCK_TYPE_AWB_GAIN,
>>> +	RKISP1_EXT_PARAMS_BLOCK_TYPE_FLT,
>>> +	RKISP1_EXT_PARAMS_BLOCK_TYPE_BDM,
>>> +	RKISP1_EXT_PARAMS_BLOCK_TYPE_CTK,
>>> +	RKISP1_EXT_PARAMS_BLOCK_TYPE_GOC,
>>> +	RKISP1_EXT_PARAMS_BLOCK_TYPE_DPF,
>>> +	RKISP1_EXT_PARAMS_BLOCK_TYPE_DPF_STRENGTH,
>>> +	RKISP1_EXT_PARAMS_BLOCK_TYPE_CPROC,
>>> +	RKISP1_EXT_PARAMS_BLOCK_TYPE_IE,
>>> +	RKISP1_EXT_PARAMS_BLOCK_TYPE_LSC,
>>> +	RKISP1_EXT_PARAMS_BLOCK_TYPE_AWB_MEAS,
>>> +	RKISP1_EXT_PARAMS_BLOCK_TYPE_HST_MEAS,
>>> +	RKISP1_EXT_PARAMS_BLOCK_TYPE_AEC_MEAS,
>>> +	RKISP1_EXT_PARAMS_BLOCK_TYPE_AFC_MEAS,
>>> +};
>>> +
>>> +#define RKISP1_EXT_PARAMS_FL_BLOCK_DISABLE	(1U << 0)
>>> +#define RKISP1_EXT_PARAMS_FL_BLOCK_ENABLE	(1U << 1)
>>> +
>>> +/**
>>> + * struct rkisp1_ext_params_block_header - RkISP1 extensible parameters 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 size and
>>> + * properly handle the block content by casting it to the correct block-specific
>>> + * type.
>>> + *
>>> + * The @type field is one of the values enumerated by
>>> + * :c:type:`rkisp1_ext_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 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. The
>>> + * driver ignores the rest of the block configuration structure in this case.
>>> + *
>>> + * 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_DISABLE 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 allowed
>>> + * 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:
>>> + *
>>> + * .. code-block:: c
>>> + *
>>> + *	void populate_bls(struct rkisp1_ext_params_block_header *block) {
>>> + *		struct rkisp1_ext_params_bls_config *bls =
>>> + *			(struct rkisp1_ext_params_bls_config *)block;
>>> + *
>>> + *		bls->header.type = RKISP1_EXT_PARAMS_BLOCK_ID_BLS;
>>> + *		bls->header.flags = RKISP1_EXT_PARAMS_FL_BLOCK_ENABLE;
>>> + *		bls->header.size = sizeof(*bls);
>>> + *
>>> + *		bls->config.enable_auto = 0;
>>> + *		bls->config.fixed_val.r = blackLevelRed_;
>>> + *		bls->config.fixed_val.gr = blackLevelGreenR_;
>>> + *		bls->config.fixed_val.gb = blackLevelGreenB_;
>>> + *		bls->config.fixed_val.b = 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
>>> + */
>>> +struct rkisp1_ext_params_block_header {
>>> +	__u16 type;
>>> +	__u16 flags;
>>> +	__u32 size;
>>> +};
>>> +
>>> +/**
>>> + * struct rkisp1_ext_params_bls_config - RkISP1 extensible params BLS config
>>> + *
>>> + * RkISP1 extensible parameters Black Level Subtraction configuration block.
>>> + * Identified by :c:type:`RKISP1_EXT_PARAMS_BLOCK_TYPE_BLS`.
>>> + *
>>> + * @header: The RkISP1 extensible parameters header, see
>>> + *	    :c:type:`rkisp1_ext_params_block_header`
>>> + * @config: Black Level Subtraction configuration, see
>>> + *	    :c:type:`rkisp1_cif_isp_bls_config`
>>> + */
>>> +struct rkisp1_ext_params_bls_config {
>>> +	struct rkisp1_ext_params_block_header header;
>>> +	struct rkisp1_cif_isp_bls_config config;
>>> +} __attribute__((aligned(8)));
>>> +
>>> +/**
>>> + * struct rkisp1_ext_params_dpcc_config - RkISP1 extensible params DPCC config
>>> + *
>>> + * RkISP1 extensible parameters Defective Pixel Cluster Correction configuration
>>> + * block. Identified by :c:type:`RKISP1_EXT_PARAMS_BLOCK_TYPE_DPCC`.
>>> + *
>>> + * @header: The RkISP1 extensible parameters header, see
>>> + *	    :c:type:`rkisp1_ext_params_block_header`
>>> + * @config: Defective Pixel Cluster Correction configuration, see
>>> + *	    :c:type:`rkisp1_cif_isp_dpcc_config`
>>> + */
>>> +struct rkisp1_ext_params_dpcc_config {
>>> +	struct rkisp1_ext_params_block_header header;
>>> +	struct rkisp1_cif_isp_dpcc_config config;
>>> +} __attribute__((aligned(8)));
>>> +
>>> +/**
>>> + * struct rkisp1_ext_params_sdg_config - RkISP1 extensible params SDG config
>>> + *
>>> + * RkISP1 extensible parameters Sensor Degamma configuration block. Identified
>>> + * by :c:type:`RKISP1_EXT_PARAMS_BLOCK_TYPE_SDG`.
>>> + *
>>> + * @header: The RkISP1 extensible parameters header, see
>>> + *	    :c:type:`rkisp1_ext_params_block_header`
>>> + * @config: Sensor Degamma configuration, see
>>> + *	    :c:type:`rkisp1_cif_isp_sdg_config`
>>> + */
>>> +struct rkisp1_ext_params_sdg_config {
>>> +	struct rkisp1_ext_params_block_header header;
>>> +	struct rkisp1_cif_isp_sdg_config config;
>>> +} __attribute__((aligned(8)));
>>> +
>>> +/**
>>> + * struct rkisp1_ext_params_lsc_config - RkISP1 extensible params LSC config
>>> + *
>>> + * RkISP1 extensible parameters Lens Shading Correction configuration block.
>>> + * Identified by :c:type:`RKISP1_EXT_PARAMS_BLOCK_TYPE_LSC`.
>>> + *
>>> + * @header: The RkISP1 extensible parameters header, see
>>> + *	    :c:type:`rkisp1_ext_params_block_header`
>>> + * @config: Lens Shading Correction configuration, see
>>> + *	    :c:type:`rkisp1_cif_isp_lsc_config`
>>> + */
>>> +struct rkisp1_ext_params_lsc_config {
>>> +	struct rkisp1_ext_params_block_header header;
>>> +	struct rkisp1_cif_isp_lsc_config config;
>>> +} __attribute__((aligned(8)));
>>> +
>>> +/**
>>> + * struct rkisp1_ext_params_awb_gain_config - RkISP1 extensible params AWB
>>> + *					      gain config
>>> + *
>>> + * RkISP1 extensible parameters Auto-White Balance Gains configuration block.
>>> + * Identified by :c:type:`RKISP1_EXT_PARAMS_BLOCK_TYPE_AWB_GAIN`.
>>> + *
>>> + * @header: The RkISP1 extensible parameters header, see
>>> + *	    :c:type:`rkisp1_ext_params_block_header`
>>> + * @config: Auto-White Balance Gains configuration, see
>>> + *	    :c:type:`rkisp1_cif_isp_awb_gain_config`
>>> + */
>>> +struct rkisp1_ext_params_awb_gain_config {
>>> +	struct rkisp1_ext_params_block_header header;
>>> +	struct rkisp1_cif_isp_awb_gain_config config;
>>> +} __attribute__((aligned(8)));
>>> +
>>> +/**
>>> + * struct rkisp1_ext_params_flt_config - RkISP1 extensible params FLT config
>>> + *
>>> + * RkISP1 extensible parameters Filter configuration block. Identified by
>>> + * :c:type:`RKISP1_EXT_PARAMS_BLOCK_TYPE_FLT`.
>>> + *
>>> + * @header: The RkISP1 extensible parameters header, see
>>> + *	    :c:type:`rkisp1_ext_params_block_header`
>>> + * @config: Filter configuration, see :c:type:`rkisp1_cif_isp_flt_config`
>>> + */
>>> +struct rkisp1_ext_params_flt_config {
>>> +	struct rkisp1_ext_params_block_header header;
>>> +	struct rkisp1_cif_isp_flt_config config;
>>> +} __attribute__((aligned(8)));
>>> +
>>> +/**
>>> + * struct rkisp1_ext_params_bdm_config - RkISP1 extensible params BDM config
>>> + *
>>> + * RkISP1 extensible parameters Demosaicing configuration block. Identified by
>>> + * :c:type:`RKISP1_EXT_PARAMS_BLOCK_TYPE_BDM`.
>>> + *
>>> + * @header: The RkISP1 extensible parameters header, see
>>> + *	    :c:type:`rkisp1_ext_params_block_header`
>>> + * @config: Demosaicing configuration, see :c:type:`rkisp1_cif_isp_bdm_config`
>>> + */
>>> +struct rkisp1_ext_params_bdm_config {
>>> +	struct rkisp1_ext_params_block_header header;
>>> +	struct rkisp1_cif_isp_bdm_config config;
>>> +} __attribute__((aligned(8)));
>>> +
>>> +/**
>>> + * struct rkisp1_ext_params_ctk_config - RkISP1 extensible params CTK config
>>> + *
>>> + * RkISP1 extensible parameters Cross-Talk configuration block. Identified by
>>> + * :c:type:`RKISP1_EXT_PARAMS_BLOCK_TYPE_CTK`.
>>> + *
>>> + * @header: The RkISP1 extensible parameters header, see
>>> + *	    :c:type:`rkisp1_ext_params_block_header`
>>> + * @config: Cross-Talk configuration, see :c:type:`rkisp1_cif_isp_ctk_config`
>>> + */
>>> +struct rkisp1_ext_params_ctk_config {
>>> +	struct rkisp1_ext_params_block_header header;
>>> +	struct rkisp1_cif_isp_ctk_config config;
>>> +} __attribute__((aligned(8)));
>>> +
>>> +/**
>>> + * struct rkisp1_ext_params_goc_config - RkISP1 extensible params GOC config
>>> + *
>>> + * RkISP1 extensible parameters Gamma-Out configuration block. Identified by
>>> + * :c:type:`RKISP1_EXT_PARAMS_BLOCK_TYPE_GOC`.
>>> + *
>>> + * @header: The RkISP1 extensible parameters header, see
>>> + *	    :c:type:`rkisp1_ext_params_block_header`
>>> + * @config: Gamma-Out configuration, see :c:type:`rkisp1_cif_isp_goc_config`
>>> + */
>>> +struct rkisp1_ext_params_goc_config {
>>> +	struct rkisp1_ext_params_block_header header;
>>> +	struct rkisp1_cif_isp_goc_config config;
>>> +} __attribute__((aligned(8)));
>>> +
>>> +/**
>>> + * struct rkisp1_ext_params_dpf_config - RkISP1 extensible params DPF config
>>> + *
>>> + * RkISP1 extensible parameters De-noise Pre-Filter configuration block.
>>> + * Identified by :c:type:`RKISP1_EXT_PARAMS_BLOCK_TYPE_DPF`.
>>> + *
>>> + * @header: The RkISP1 extensible parameters header, see
>>> + *	    :c:type:`rkisp1_ext_params_block_header`
>>> + * @config: De-noise Pre-Filter configuration, see
>>> + *	    :c:type:`rkisp1_cif_isp_dpf_config`
>>> + */
>>> +struct rkisp1_ext_params_dpf_config {
>>> +	struct rkisp1_ext_params_block_header header;
>>> +	struct rkisp1_cif_isp_dpf_config config;
>>> +} __attribute__((aligned(8)));
>>> +
>>> +/**
>>> + * struct rkisp1_ext_params_dpf_strength_config - RkISP1 extensible params DPF
>>> + *						  strength config
>>> + *
>>> + * RkISP1 extensible parameters De-noise Pre-Filter strength configuration
>>> + * block. Identified by :c:type:`RKISP1_EXT_PARAMS_BLOCK_TYPE_DPF_STRENGTH`.
>>> + *
>>> + * @header: The RkISP1 extensible parameters header, see
>>> + *	    :c:type:`rkisp1_ext_params_block_header`
>>> + * @config: De-noise Pre-Filter strength configuration, see
>>> + *	    :c:type:`rkisp1_cif_isp_dpf_strength_config`
>>> + */
>>> +struct rkisp1_ext_params_dpf_strength_config {
>>> +	struct rkisp1_ext_params_block_header header;
>>> +	struct rkisp1_cif_isp_dpf_strength_config config;
>>> +} __attribute__((aligned(8)));
>>> +
>>> +/**
>>> + * struct rkisp1_ext_params_cproc_config - RkISP1 extensible params CPROC config
>>> + *
>>> + * RkISP1 extensible parameters Color Processing configuration block.
>>> + * Identified by :c:type:`RKISP1_EXT_PARAMS_BLOCK_TYPE_CPROC`.
>>> + *
>>> + * @header: The RkISP1 extensible parameters header, see
>>> + *	    :c:type:`rkisp1_ext_params_block_header`
>>> + * @config: Color processing configuration, see
>>> + *	    :c:type:`rkisp1_cif_isp_cproc_config`
>>> + */
>>> +struct rkisp1_ext_params_cproc_config {
>>> +	struct rkisp1_ext_params_block_header header;
>>> +	struct rkisp1_cif_isp_cproc_config config;
>>> +} __attribute__((aligned(8)));
>>> +
>>> +/**
>>> + * struct rkisp1_ext_params_ie_config - RkISP1 extensible params IE config
>>> + *
>>> + * RkISP1 extensible parameters Image Effect configuration block. Identified by
>>> + * :c:type:`RKISP1_EXT_PARAMS_BLOCK_TYPE_IE`.
>>> + *
>>> + * @header: The RkISP1 extensible parameters header, see
>>> + *	    :c:type:`rkisp1_ext_params_block_header`
>>> + * @config: Image Effect configuration, see :c:type:`rkisp1_cif_isp_ie_config`
>>> + */
>>> +struct rkisp1_ext_params_ie_config {
>>> +	struct rkisp1_ext_params_block_header header;
>>> +	struct rkisp1_cif_isp_ie_config config;
>>> +} __attribute__((aligned(8)));
>>> +
>>> +/**
>>> + * struct rkisp1_ext_params_awb_meas_config - RkISP1 extensible params AWB
>>> + *					      Meas config
>>> + *
>>> + * RkISP1 extensible parameters Auto-White Balance Measurement configuration
>>> + * block. Identified by :c:type:`RKISP1_EXT_PARAMS_BLOCK_TYPE_AWB_MEAS`.
>>> + *
>>> + * @header: The RkISP1 extensible parameters header, see
>>> + *	    :c:type:`rkisp1_ext_params_block_header`
>>> + * @config: Auto-White Balance measure configuration, see
>>> + *	    :c:type:`rkisp1_cif_isp_awb_meas_config`
>>> + */
>>> +struct rkisp1_ext_params_awb_meas_config {
>>> +	struct rkisp1_ext_params_block_header header;
>>> +	struct rkisp1_cif_isp_awb_meas_config config;
>>> +} __attribute__((aligned(8)));
>>> +
>>> +/**
>>> + * struct rkisp1_ext_params_hst_config - RkISP1 extensible params Histogram config
>>> + *
>>> + * RkISP1 extensible parameters Histogram statistics configuration block.
>>> + * Identified by :c:type:`RKISP1_EXT_PARAMS_BLOCK_TYPE_HST_MEAS`.
>>> + *
>>> + * @header: The RkISP1 extensible parameters header, see
>>> + *	    :c:type:`rkisp1_ext_params_block_header`
>>> + * @config: Histogram statistics configuration, see
>>> + *	    :c:type:`rkisp1_cif_isp_hst_config`
>>> + */
>>> +struct rkisp1_ext_params_hst_config {
>>> +	struct rkisp1_ext_params_block_header header;
>>> +	struct rkisp1_cif_isp_hst_config config;
>>> +} __attribute__((aligned(8)));
>>> +
>>> +/**
>>> + * struct rkisp1_ext_params_aec_config - RkISP1 extensible params AEC config
>>> + *
>>> + * RkISP1 extensible parameters Auto-Exposure statistics configuration block.
>>> + * Identified by :c:type:`RKISP1_EXT_PARAMS_BLOCK_TYPE_AEC_MEAS`.
>>> + *
>>> + * @header: The RkISP1 extensible parameters header, see
>>> + *	    :c:type:`rkisp1_ext_params_block_header`
>>> + * @config: Auto-Exposure statistics configuration, see
>>> + *	    :c:type:`rkisp1_cif_isp_aec_config`
>>> + */
>>> +struct rkisp1_ext_params_aec_config {
>>> +	struct rkisp1_ext_params_block_header header;
>>> +	struct rkisp1_cif_isp_aec_config config;
>>> +} __attribute__((aligned(8)));
>>> +
>>> +/**
>>> + * struct rkisp1_ext_params_afc_config - RkISP1 extensible params AFC config
>>> + *
>>> + * RkISP1 extensible parameters Auto-Focus statistics configuration block.
>>> + * Identified by :c:type:`RKISP1_EXT_PARAMS_BLOCK_TYPE_AFC_MEAS`.
>>> + *
>>> + * @header: The RkISP1 extensible parameters header, see
>>> + *	    :c:type:`rkisp1_ext_params_block_header`
>>> + * @config: Auto-Focus statistics configuration, see
>>> + *	    :c:type:`rkisp1_cif_isp_afc_config`
>>> + */
>>> +struct rkisp1_ext_params_afc_config {
>>> +	struct rkisp1_ext_params_block_header header;
>>> +	struct rkisp1_cif_isp_afc_config config;
>>> +} __attribute__((aligned(8)));
>>> +
>>> +#define RKISP1_EXT_PARAMS_MAX_SIZE					\
>>> +	(sizeof(struct rkisp1_ext_params_bls_config)			+\
>>> +	sizeof(struct rkisp1_ext_params_dpcc_config)			+\
>>> +	sizeof(struct rkisp1_ext_params_sdg_config)			+\
>>> +	sizeof(struct rkisp1_ext_params_lsc_config)			+\
>>> +	sizeof(struct rkisp1_ext_params_awb_gain_config)		+\
>>> +	sizeof(struct rkisp1_ext_params_flt_config)			+\
>>> +	sizeof(struct rkisp1_ext_params_bdm_config)			+\
>>> +	sizeof(struct rkisp1_ext_params_ctk_config)			+\
>>> +	sizeof(struct rkisp1_ext_params_goc_config)			+\
>>> +	sizeof(struct rkisp1_ext_params_dpf_config)			+\
>>> +	sizeof(struct rkisp1_ext_params_dpf_strength_config)		+\
>>> +	sizeof(struct rkisp1_ext_params_cproc_config)			+\
>>> +	sizeof(struct rkisp1_ext_params_ie_config)			+\
>>> +	sizeof(struct rkisp1_ext_params_awb_meas_config)		+\
>>> +	sizeof(struct rkisp1_ext_params_hst_config)			+\
>>> +	sizeof(struct rkisp1_ext_params_aec_config)			+\
>>> +	sizeof(struct rkisp1_ext_params_afc_config))
>>> +
>>> +/**
>>> + * enum rksip1_ext_param_buffer_version - RkISP1 extensible parameters version
>>> + *
>>> + * @RKISP1_EXT_PARAM_BUFFER_V1: First version of RkISP1 extensible parameters
>>> + */
>>> +enum rksip1_ext_param_buffer_version {
>>> +	RKISP1_EXT_PARAM_BUFFER_V1 = 1,
>>
>> I see no check against this in the rkisp1 code. Shouldn't this be checked?
>> If the version is unsupported, then just return an error.
>>
> 
> Do we need this for the first version ? There are no other versions
> userspace can use at the moment. I can add a check during validation
> though.

Yes: if a V2 is added in the future, and an application wants to use that
against a driver that only support V1, then that should fail.

> 
>> Also, how does userspace know which version(s) is/are supported by the driver?
>>
> 
> Good question, there is no API for that atm. Defining a new format
> version should only happen when a non-backward compatible change to
> the format is made. I understand an application can be compiled
> against a newer kernel header that provides a new format version but
> then run on an older kernel where the new format is not supported.
> 
> Probably userspace should be able to identify what versions are
> supported by the driver it runs with and use the most appropriate one
> by selecting it at runtime.
> 
> What API would you use for that ? Is this something required for this
> first version where a single format version is available ?

You need this also for this first version for the reason explained above.

Personally I would just make a read-only control that returns the highest
supported version.

Regards,

	Hans

> 
>> Regards,
>>
>> 	Hans
>>
>>> +};
>>> +
>>> +/**
>>> + * struct rkisp1_ext_params_cfg - RkISP1 extensible parameters configuration
>>> + *
>>> + * This struct contains the configuration parameters of the RkISP1 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:`rkisp1_ext_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.
>>> + *
>>> + * 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
>>> + * 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 @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 -------------------+
>>> + *	| version = RKISP_EXT_PARAMS_BUFFER_V1;                               |
>>> + *	| data_size = sizeof(struct rkisp1_ext_params_bls_config)             |
>>> + *	|           + sizeof(struct rkisp1_ext_params_dpcc_config);           |
>>> + *	| +------------------------- data  ---------------------------------+ |
>>> + *	| | +------------- struct rkisp1_ext_params_bls_config -----------+ | |
>>> + *	| | | +-------- struct rkisp1_ext_params_block_header  ---------+ | | |
>>> + *	| | | | type = RKISP1_EXT_PARAMS_BLOCK_TYPE_BLS;                | | | |
>>> + *	| | | | flags = RKISP1_EXT_PARAMS_FL_BLOCK_ENABLE;              | | | |
>>> + *	| | | | size = sizeof(struct rkisp1_ext_params_bls_config);     | | | |
>>> + *	| | | +---------------------------------------------------------+ | | |
>>> + *	| | | +---------- struct rkisp1_cif_isp_bls_config -------------+ | | |
>>> + *	| | | | enable_auto = 0;                                        | | | |
>>> + *	| | | | fixed_val.r = 256;                                      | | | |
>>> + *	| | | | fixed_val.gr = 256;                                     | | | |
>>> + *	| | | | fixed_val.gb = 256;                                     | | | |
>>> + *	| | | | fixed_val.b = 256;                                      | | | |
>>> + *	| | | +---------------------------------------------------------+ | | |
>>> + *	| | +------------ struct rkisp1_ext_params_dpcc_config -----------+ | |
>>> + *	| | | +-------- struct rkisp1_ext_params_block_header  ---------+ | | |
>>> + *	| | | | type = RKISP1_EXT_PARAMS_BLOCK_TYPE_DPCC;               | | | |
>>> + *	| | | | flags = RKISP1_EXT_PARAMS_FL_BLOCK_ENABLE;              | | | |
>>> + *	| | | | size = sizeof(struct rkisp1_ext_params_dpcc_config);    | | | |
>>> + *	| | | +---------------------------------------------------------+ | | |
>>> + *	| | | +---------- struct rkisp1_cif_isp_dpcc_config ------------+ | | |
>>> + *	| | | | mode = RKISP1_CIF_ISP_DPCC_MODE_STAGE1_ENABLE;          | | | |
>>> + *	| | | | output_mode =                                           | | | |
>>> + *	| | | |   RKISP1_CIF_ISP_DPCC_OUTPUT_MODE_STAGE1_INCL_G_CENTER; | | | |
>>> + *	| | | | set_use = ... ;                                         | | | |
>>> + *	| | | | ...  = ... ;                                            | | | |
>>> + *	| | | +---------------------------------------------------------+ | | |
>>> + *	| | +-------------------------------------------------------------+ | |
>>> + *	| +-----------------------------------------------------------------+ |
>>> + *	+---------------------------------------------------------------------+
>>> + *
>>> + * @version: The RkISP1 extensible parameters buffer version, see
>>> + *	     :c:type:`rksip1_ext_param_buffer_version`
>>> + * @data_size: The RkISP1 configuration data effective size, excluding this
>>> + *	       header
>>> + * @data: The RkISP1 extensible configuration data blocks
>>> + */
>>> +struct rkisp1_ext_params_cfg {
>>> +	__u32 version;
>>> +	__u32 data_size;
>>> +	__u8 data[RKISP1_EXT_PARAMS_MAX_SIZE];
>>> +};
>>> +
>>>  #endif /* _UAPI_RKISP1_CONFIG_H */
>>
>
Laurent Pinchart Aug. 8, 2024, 9:54 a.m. UTC | #4
On Thu, Aug 08, 2024 at 09:41:42AM +0200, Hans Verkuil wrote:
> On 08/08/2024 09:24, Jacopo Mondi wrote:
> > On Thu, Aug 08, 2024 at 08:31:58AM GMT, Hans Verkuil wrote:
> >> On 07/08/2024 23:22, Jacopo Mondi wrote:
> >>> Add to the rkisp1-config.h header data types and documentation of
> >>> the extensible parameters format.
> >>>
> >>> Signed-off-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
> >>> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> >>> Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>
> >>> Tested-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
> >>> Acked-by: Sakari Ailus <sakari.ailus@linux.intel.com>
> >>> ---
> >>>  include/uapi/linux/rkisp1-config.h | 485 +++++++++++++++++++++++++++++
> >>>  1 file changed, 485 insertions(+)
> >>>
> >>> diff --git a/include/uapi/linux/rkisp1-config.h b/include/uapi/linux/rkisp1-config.h
> >>> index 6eeaf8bf2362..14a23fd9a745 100644
> >>> --- a/include/uapi/linux/rkisp1-config.h
> >>> +++ b/include/uapi/linux/rkisp1-config.h
> >>> @@ -996,4 +996,489 @@ struct rkisp1_stat_buffer {
> >>>  	struct rkisp1_cif_isp_stat params;
> >>>  };
> >>>
> >>> +/*---------- PART3: Extensible Configuration Parameters  ------------*/
> >>> +
> >>> +/**
> >>> + * enum rkisp1_ext_params_block_type - RkISP1 extensible params block type
> >>> + *
> >>> + * @RKISP1_EXT_PARAMS_BLOCK_TYPE_BLS: Black level subtraction
> >>> + * @RKISP1_EXT_PARAMS_BLOCK_TYPE_DPCC: Defect pixel cluster correction
> >>> + * @RKISP1_EXT_PARAMS_BLOCK_TYPE_SDG: Sensor de-gamma
> >>> + * @RKISP1_EXT_PARAMS_BLOCK_TYPE_AWB_GAIN: Auto white balance gains
> >>> + * @RKISP1_EXT_PARAMS_BLOCK_TYPE_FLT: ISP filtering
> >>> + * @RKISP1_EXT_PARAMS_BLOCK_TYPE_BDM: Bayer de-mosaic
> >>> + * @RKISP1_EXT_PARAMS_BLOCK_TYPE_CTK: Cross-talk correction
> >>> + * @RKISP1_EXT_PARAMS_BLOCK_TYPE_GOC: Gamma out correction
> >>> + * @RKISP1_EXT_PARAMS_BLOCK_TYPE_DPF: De-noise pre-filter
> >>> + * @RKISP1_EXT_PARAMS_BLOCK_TYPE_DPF_STRENGTH: De-noise pre-filter strength
> >>> + * @RKISP1_EXT_PARAMS_BLOCK_TYPE_CPROC: Color processing
> >>> + * @RKISP1_EXT_PARAMS_BLOCK_TYPE_IE: Image effects
> >>> + * @RKISP1_EXT_PARAMS_BLOCK_TYPE_LSC: Lens shading correction
> >>> + * @RKISP1_EXT_PARAMS_BLOCK_TYPE_AWB_MEAS: Auto white balance statistics
> >>> + * @RKISP1_EXT_PARAMS_BLOCK_TYPE_HST_MEAS: Histogram statistics
> >>> + * @RKISP1_EXT_PARAMS_BLOCK_TYPE_AEC_MEAS: Auto exposure statistics
> >>> + * @RKISP1_EXT_PARAMS_BLOCK_TYPE_AFC_MEAS: Auto-focus statistics
> >>> + */
> >>> +enum rkisp1_ext_params_block_type {
> >>> +	RKISP1_EXT_PARAMS_BLOCK_TYPE_BLS,
> >>> +	RKISP1_EXT_PARAMS_BLOCK_TYPE_DPCC,
> >>> +	RKISP1_EXT_PARAMS_BLOCK_TYPE_SDG,
> >>> +	RKISP1_EXT_PARAMS_BLOCK_TYPE_AWB_GAIN,
> >>> +	RKISP1_EXT_PARAMS_BLOCK_TYPE_FLT,
> >>> +	RKISP1_EXT_PARAMS_BLOCK_TYPE_BDM,
> >>> +	RKISP1_EXT_PARAMS_BLOCK_TYPE_CTK,
> >>> +	RKISP1_EXT_PARAMS_BLOCK_TYPE_GOC,
> >>> +	RKISP1_EXT_PARAMS_BLOCK_TYPE_DPF,
> >>> +	RKISP1_EXT_PARAMS_BLOCK_TYPE_DPF_STRENGTH,
> >>> +	RKISP1_EXT_PARAMS_BLOCK_TYPE_CPROC,
> >>> +	RKISP1_EXT_PARAMS_BLOCK_TYPE_IE,
> >>> +	RKISP1_EXT_PARAMS_BLOCK_TYPE_LSC,
> >>> +	RKISP1_EXT_PARAMS_BLOCK_TYPE_AWB_MEAS,
> >>> +	RKISP1_EXT_PARAMS_BLOCK_TYPE_HST_MEAS,
> >>> +	RKISP1_EXT_PARAMS_BLOCK_TYPE_AEC_MEAS,
> >>> +	RKISP1_EXT_PARAMS_BLOCK_TYPE_AFC_MEAS,
> >>> +};
> >>> +
> >>> +#define RKISP1_EXT_PARAMS_FL_BLOCK_DISABLE	(1U << 0)
> >>> +#define RKISP1_EXT_PARAMS_FL_BLOCK_ENABLE	(1U << 1)
> >>> +
> >>> +/**
> >>> + * struct rkisp1_ext_params_block_header - RkISP1 extensible parameters 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 size and
> >>> + * properly handle the block content by casting it to the correct block-specific
> >>> + * type.
> >>> + *
> >>> + * The @type field is one of the values enumerated by
> >>> + * :c:type:`rkisp1_ext_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 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. The
> >>> + * driver ignores the rest of the block configuration structure in this case.
> >>> + *
> >>> + * 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_DISABLE 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 allowed
> >>> + * 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:
> >>> + *
> >>> + * .. code-block:: c
> >>> + *
> >>> + *	void populate_bls(struct rkisp1_ext_params_block_header *block) {
> >>> + *		struct rkisp1_ext_params_bls_config *bls =
> >>> + *			(struct rkisp1_ext_params_bls_config *)block;
> >>> + *
> >>> + *		bls->header.type = RKISP1_EXT_PARAMS_BLOCK_ID_BLS;
> >>> + *		bls->header.flags = RKISP1_EXT_PARAMS_FL_BLOCK_ENABLE;
> >>> + *		bls->header.size = sizeof(*bls);
> >>> + *
> >>> + *		bls->config.enable_auto = 0;
> >>> + *		bls->config.fixed_val.r = blackLevelRed_;
> >>> + *		bls->config.fixed_val.gr = blackLevelGreenR_;
> >>> + *		bls->config.fixed_val.gb = blackLevelGreenB_;
> >>> + *		bls->config.fixed_val.b = 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
> >>> + */
> >>> +struct rkisp1_ext_params_block_header {
> >>> +	__u16 type;
> >>> +	__u16 flags;
> >>> +	__u32 size;
> >>> +};
> >>> +
> >>> +/**
> >>> + * struct rkisp1_ext_params_bls_config - RkISP1 extensible params BLS config
> >>> + *
> >>> + * RkISP1 extensible parameters Black Level Subtraction configuration block.
> >>> + * Identified by :c:type:`RKISP1_EXT_PARAMS_BLOCK_TYPE_BLS`.
> >>> + *
> >>> + * @header: The RkISP1 extensible parameters header, see
> >>> + *	    :c:type:`rkisp1_ext_params_block_header`
> >>> + * @config: Black Level Subtraction configuration, see
> >>> + *	    :c:type:`rkisp1_cif_isp_bls_config`
> >>> + */
> >>> +struct rkisp1_ext_params_bls_config {
> >>> +	struct rkisp1_ext_params_block_header header;
> >>> +	struct rkisp1_cif_isp_bls_config config;
> >>> +} __attribute__((aligned(8)));
> >>> +
> >>> +/**
> >>> + * struct rkisp1_ext_params_dpcc_config - RkISP1 extensible params DPCC config
> >>> + *
> >>> + * RkISP1 extensible parameters Defective Pixel Cluster Correction configuration
> >>> + * block. Identified by :c:type:`RKISP1_EXT_PARAMS_BLOCK_TYPE_DPCC`.
> >>> + *
> >>> + * @header: The RkISP1 extensible parameters header, see
> >>> + *	    :c:type:`rkisp1_ext_params_block_header`
> >>> + * @config: Defective Pixel Cluster Correction configuration, see
> >>> + *	    :c:type:`rkisp1_cif_isp_dpcc_config`
> >>> + */
> >>> +struct rkisp1_ext_params_dpcc_config {
> >>> +	struct rkisp1_ext_params_block_header header;
> >>> +	struct rkisp1_cif_isp_dpcc_config config;
> >>> +} __attribute__((aligned(8)));
> >>> +
> >>> +/**
> >>> + * struct rkisp1_ext_params_sdg_config - RkISP1 extensible params SDG config
> >>> + *
> >>> + * RkISP1 extensible parameters Sensor Degamma configuration block. Identified
> >>> + * by :c:type:`RKISP1_EXT_PARAMS_BLOCK_TYPE_SDG`.
> >>> + *
> >>> + * @header: The RkISP1 extensible parameters header, see
> >>> + *	    :c:type:`rkisp1_ext_params_block_header`
> >>> + * @config: Sensor Degamma configuration, see
> >>> + *	    :c:type:`rkisp1_cif_isp_sdg_config`
> >>> + */
> >>> +struct rkisp1_ext_params_sdg_config {
> >>> +	struct rkisp1_ext_params_block_header header;
> >>> +	struct rkisp1_cif_isp_sdg_config config;
> >>> +} __attribute__((aligned(8)));
> >>> +
> >>> +/**
> >>> + * struct rkisp1_ext_params_lsc_config - RkISP1 extensible params LSC config
> >>> + *
> >>> + * RkISP1 extensible parameters Lens Shading Correction configuration block.
> >>> + * Identified by :c:type:`RKISP1_EXT_PARAMS_BLOCK_TYPE_LSC`.
> >>> + *
> >>> + * @header: The RkISP1 extensible parameters header, see
> >>> + *	    :c:type:`rkisp1_ext_params_block_header`
> >>> + * @config: Lens Shading Correction configuration, see
> >>> + *	    :c:type:`rkisp1_cif_isp_lsc_config`
> >>> + */
> >>> +struct rkisp1_ext_params_lsc_config {
> >>> +	struct rkisp1_ext_params_block_header header;
> >>> +	struct rkisp1_cif_isp_lsc_config config;
> >>> +} __attribute__((aligned(8)));
> >>> +
> >>> +/**
> >>> + * struct rkisp1_ext_params_awb_gain_config - RkISP1 extensible params AWB
> >>> + *					      gain config
> >>> + *
> >>> + * RkISP1 extensible parameters Auto-White Balance Gains configuration block.
> >>> + * Identified by :c:type:`RKISP1_EXT_PARAMS_BLOCK_TYPE_AWB_GAIN`.
> >>> + *
> >>> + * @header: The RkISP1 extensible parameters header, see
> >>> + *	    :c:type:`rkisp1_ext_params_block_header`
> >>> + * @config: Auto-White Balance Gains configuration, see
> >>> + *	    :c:type:`rkisp1_cif_isp_awb_gain_config`
> >>> + */
> >>> +struct rkisp1_ext_params_awb_gain_config {
> >>> +	struct rkisp1_ext_params_block_header header;
> >>> +	struct rkisp1_cif_isp_awb_gain_config config;
> >>> +} __attribute__((aligned(8)));
> >>> +
> >>> +/**
> >>> + * struct rkisp1_ext_params_flt_config - RkISP1 extensible params FLT config
> >>> + *
> >>> + * RkISP1 extensible parameters Filter configuration block. Identified by
> >>> + * :c:type:`RKISP1_EXT_PARAMS_BLOCK_TYPE_FLT`.
> >>> + *
> >>> + * @header: The RkISP1 extensible parameters header, see
> >>> + *	    :c:type:`rkisp1_ext_params_block_header`
> >>> + * @config: Filter configuration, see :c:type:`rkisp1_cif_isp_flt_config`
> >>> + */
> >>> +struct rkisp1_ext_params_flt_config {
> >>> +	struct rkisp1_ext_params_block_header header;
> >>> +	struct rkisp1_cif_isp_flt_config config;
> >>> +} __attribute__((aligned(8)));
> >>> +
> >>> +/**
> >>> + * struct rkisp1_ext_params_bdm_config - RkISP1 extensible params BDM config
> >>> + *
> >>> + * RkISP1 extensible parameters Demosaicing configuration block. Identified by
> >>> + * :c:type:`RKISP1_EXT_PARAMS_BLOCK_TYPE_BDM`.
> >>> + *
> >>> + * @header: The RkISP1 extensible parameters header, see
> >>> + *	    :c:type:`rkisp1_ext_params_block_header`
> >>> + * @config: Demosaicing configuration, see :c:type:`rkisp1_cif_isp_bdm_config`
> >>> + */
> >>> +struct rkisp1_ext_params_bdm_config {
> >>> +	struct rkisp1_ext_params_block_header header;
> >>> +	struct rkisp1_cif_isp_bdm_config config;
> >>> +} __attribute__((aligned(8)));
> >>> +
> >>> +/**
> >>> + * struct rkisp1_ext_params_ctk_config - RkISP1 extensible params CTK config
> >>> + *
> >>> + * RkISP1 extensible parameters Cross-Talk configuration block. Identified by
> >>> + * :c:type:`RKISP1_EXT_PARAMS_BLOCK_TYPE_CTK`.
> >>> + *
> >>> + * @header: The RkISP1 extensible parameters header, see
> >>> + *	    :c:type:`rkisp1_ext_params_block_header`
> >>> + * @config: Cross-Talk configuration, see :c:type:`rkisp1_cif_isp_ctk_config`
> >>> + */
> >>> +struct rkisp1_ext_params_ctk_config {
> >>> +	struct rkisp1_ext_params_block_header header;
> >>> +	struct rkisp1_cif_isp_ctk_config config;
> >>> +} __attribute__((aligned(8)));
> >>> +
> >>> +/**
> >>> + * struct rkisp1_ext_params_goc_config - RkISP1 extensible params GOC config
> >>> + *
> >>> + * RkISP1 extensible parameters Gamma-Out configuration block. Identified by
> >>> + * :c:type:`RKISP1_EXT_PARAMS_BLOCK_TYPE_GOC`.
> >>> + *
> >>> + * @header: The RkISP1 extensible parameters header, see
> >>> + *	    :c:type:`rkisp1_ext_params_block_header`
> >>> + * @config: Gamma-Out configuration, see :c:type:`rkisp1_cif_isp_goc_config`
> >>> + */
> >>> +struct rkisp1_ext_params_goc_config {
> >>> +	struct rkisp1_ext_params_block_header header;
> >>> +	struct rkisp1_cif_isp_goc_config config;
> >>> +} __attribute__((aligned(8)));
> >>> +
> >>> +/**
> >>> + * struct rkisp1_ext_params_dpf_config - RkISP1 extensible params DPF config
> >>> + *
> >>> + * RkISP1 extensible parameters De-noise Pre-Filter configuration block.
> >>> + * Identified by :c:type:`RKISP1_EXT_PARAMS_BLOCK_TYPE_DPF`.
> >>> + *
> >>> + * @header: The RkISP1 extensible parameters header, see
> >>> + *	    :c:type:`rkisp1_ext_params_block_header`
> >>> + * @config: De-noise Pre-Filter configuration, see
> >>> + *	    :c:type:`rkisp1_cif_isp_dpf_config`
> >>> + */
> >>> +struct rkisp1_ext_params_dpf_config {
> >>> +	struct rkisp1_ext_params_block_header header;
> >>> +	struct rkisp1_cif_isp_dpf_config config;
> >>> +} __attribute__((aligned(8)));
> >>> +
> >>> +/**
> >>> + * struct rkisp1_ext_params_dpf_strength_config - RkISP1 extensible params DPF
> >>> + *						  strength config
> >>> + *
> >>> + * RkISP1 extensible parameters De-noise Pre-Filter strength configuration
> >>> + * block. Identified by :c:type:`RKISP1_EXT_PARAMS_BLOCK_TYPE_DPF_STRENGTH`.
> >>> + *
> >>> + * @header: The RkISP1 extensible parameters header, see
> >>> + *	    :c:type:`rkisp1_ext_params_block_header`
> >>> + * @config: De-noise Pre-Filter strength configuration, see
> >>> + *	    :c:type:`rkisp1_cif_isp_dpf_strength_config`
> >>> + */
> >>> +struct rkisp1_ext_params_dpf_strength_config {
> >>> +	struct rkisp1_ext_params_block_header header;
> >>> +	struct rkisp1_cif_isp_dpf_strength_config config;
> >>> +} __attribute__((aligned(8)));
> >>> +
> >>> +/**
> >>> + * struct rkisp1_ext_params_cproc_config - RkISP1 extensible params CPROC config
> >>> + *
> >>> + * RkISP1 extensible parameters Color Processing configuration block.
> >>> + * Identified by :c:type:`RKISP1_EXT_PARAMS_BLOCK_TYPE_CPROC`.
> >>> + *
> >>> + * @header: The RkISP1 extensible parameters header, see
> >>> + *	    :c:type:`rkisp1_ext_params_block_header`
> >>> + * @config: Color processing configuration, see
> >>> + *	    :c:type:`rkisp1_cif_isp_cproc_config`
> >>> + */
> >>> +struct rkisp1_ext_params_cproc_config {
> >>> +	struct rkisp1_ext_params_block_header header;
> >>> +	struct rkisp1_cif_isp_cproc_config config;
> >>> +} __attribute__((aligned(8)));
> >>> +
> >>> +/**
> >>> + * struct rkisp1_ext_params_ie_config - RkISP1 extensible params IE config
> >>> + *
> >>> + * RkISP1 extensible parameters Image Effect configuration block. Identified by
> >>> + * :c:type:`RKISP1_EXT_PARAMS_BLOCK_TYPE_IE`.
> >>> + *
> >>> + * @header: The RkISP1 extensible parameters header, see
> >>> + *	    :c:type:`rkisp1_ext_params_block_header`
> >>> + * @config: Image Effect configuration, see :c:type:`rkisp1_cif_isp_ie_config`
> >>> + */
> >>> +struct rkisp1_ext_params_ie_config {
> >>> +	struct rkisp1_ext_params_block_header header;
> >>> +	struct rkisp1_cif_isp_ie_config config;
> >>> +} __attribute__((aligned(8)));
> >>> +
> >>> +/**
> >>> + * struct rkisp1_ext_params_awb_meas_config - RkISP1 extensible params AWB
> >>> + *					      Meas config
> >>> + *
> >>> + * RkISP1 extensible parameters Auto-White Balance Measurement configuration
> >>> + * block. Identified by :c:type:`RKISP1_EXT_PARAMS_BLOCK_TYPE_AWB_MEAS`.
> >>> + *
> >>> + * @header: The RkISP1 extensible parameters header, see
> >>> + *	    :c:type:`rkisp1_ext_params_block_header`
> >>> + * @config: Auto-White Balance measure configuration, see
> >>> + *	    :c:type:`rkisp1_cif_isp_awb_meas_config`
> >>> + */
> >>> +struct rkisp1_ext_params_awb_meas_config {
> >>> +	struct rkisp1_ext_params_block_header header;
> >>> +	struct rkisp1_cif_isp_awb_meas_config config;
> >>> +} __attribute__((aligned(8)));
> >>> +
> >>> +/**
> >>> + * struct rkisp1_ext_params_hst_config - RkISP1 extensible params Histogram config
> >>> + *
> >>> + * RkISP1 extensible parameters Histogram statistics configuration block.
> >>> + * Identified by :c:type:`RKISP1_EXT_PARAMS_BLOCK_TYPE_HST_MEAS`.
> >>> + *
> >>> + * @header: The RkISP1 extensible parameters header, see
> >>> + *	    :c:type:`rkisp1_ext_params_block_header`
> >>> + * @config: Histogram statistics configuration, see
> >>> + *	    :c:type:`rkisp1_cif_isp_hst_config`
> >>> + */
> >>> +struct rkisp1_ext_params_hst_config {
> >>> +	struct rkisp1_ext_params_block_header header;
> >>> +	struct rkisp1_cif_isp_hst_config config;
> >>> +} __attribute__((aligned(8)));
> >>> +
> >>> +/**
> >>> + * struct rkisp1_ext_params_aec_config - RkISP1 extensible params AEC config
> >>> + *
> >>> + * RkISP1 extensible parameters Auto-Exposure statistics configuration block.
> >>> + * Identified by :c:type:`RKISP1_EXT_PARAMS_BLOCK_TYPE_AEC_MEAS`.
> >>> + *
> >>> + * @header: The RkISP1 extensible parameters header, see
> >>> + *	    :c:type:`rkisp1_ext_params_block_header`
> >>> + * @config: Auto-Exposure statistics configuration, see
> >>> + *	    :c:type:`rkisp1_cif_isp_aec_config`
> >>> + */
> >>> +struct rkisp1_ext_params_aec_config {
> >>> +	struct rkisp1_ext_params_block_header header;
> >>> +	struct rkisp1_cif_isp_aec_config config;
> >>> +} __attribute__((aligned(8)));
> >>> +
> >>> +/**
> >>> + * struct rkisp1_ext_params_afc_config - RkISP1 extensible params AFC config
> >>> + *
> >>> + * RkISP1 extensible parameters Auto-Focus statistics configuration block.
> >>> + * Identified by :c:type:`RKISP1_EXT_PARAMS_BLOCK_TYPE_AFC_MEAS`.
> >>> + *
> >>> + * @header: The RkISP1 extensible parameters header, see
> >>> + *	    :c:type:`rkisp1_ext_params_block_header`
> >>> + * @config: Auto-Focus statistics configuration, see
> >>> + *	    :c:type:`rkisp1_cif_isp_afc_config`
> >>> + */
> >>> +struct rkisp1_ext_params_afc_config {
> >>> +	struct rkisp1_ext_params_block_header header;
> >>> +	struct rkisp1_cif_isp_afc_config config;
> >>> +} __attribute__((aligned(8)));
> >>> +
> >>> +#define RKISP1_EXT_PARAMS_MAX_SIZE					\
> >>> +	(sizeof(struct rkisp1_ext_params_bls_config)			+\
> >>> +	sizeof(struct rkisp1_ext_params_dpcc_config)			+\
> >>> +	sizeof(struct rkisp1_ext_params_sdg_config)			+\
> >>> +	sizeof(struct rkisp1_ext_params_lsc_config)			+\
> >>> +	sizeof(struct rkisp1_ext_params_awb_gain_config)		+\
> >>> +	sizeof(struct rkisp1_ext_params_flt_config)			+\
> >>> +	sizeof(struct rkisp1_ext_params_bdm_config)			+\
> >>> +	sizeof(struct rkisp1_ext_params_ctk_config)			+\
> >>> +	sizeof(struct rkisp1_ext_params_goc_config)			+\
> >>> +	sizeof(struct rkisp1_ext_params_dpf_config)			+\
> >>> +	sizeof(struct rkisp1_ext_params_dpf_strength_config)		+\
> >>> +	sizeof(struct rkisp1_ext_params_cproc_config)			+\
> >>> +	sizeof(struct rkisp1_ext_params_ie_config)			+\
> >>> +	sizeof(struct rkisp1_ext_params_awb_meas_config)		+\
> >>> +	sizeof(struct rkisp1_ext_params_hst_config)			+\
> >>> +	sizeof(struct rkisp1_ext_params_aec_config)			+\
> >>> +	sizeof(struct rkisp1_ext_params_afc_config))
> >>> +
> >>> +/**
> >>> + * enum rksip1_ext_param_buffer_version - RkISP1 extensible parameters version
> >>> + *
> >>> + * @RKISP1_EXT_PARAM_BUFFER_V1: First version of RkISP1 extensible parameters
> >>> + */
> >>> +enum rksip1_ext_param_buffer_version {
> >>> +	RKISP1_EXT_PARAM_BUFFER_V1 = 1,
> >>
> >> I see no check against this in the rkisp1 code. Shouldn't this be checked?
> >> If the version is unsupported, then just return an error.
> > 
> > Do we need this for the first version ? There are no other versions
> > userspace can use at the moment. I can add a check during validation
> > though.
> 
> Yes: if a V2 is added in the future, and an application wants to use that
> against a driver that only support V1, then that should fail.
> 
> >> Also, how does userspace know which version(s) is/are supported by the driver?
> > 
> > Good question, there is no API for that atm. Defining a new format
> > version should only happen when a non-backward compatible change to
> > the format is made. I understand an application can be compiled
> > against a newer kernel header that provides a new format version but
> > then run on an older kernel where the new format is not supported.
> > 
> > Probably userspace should be able to identify what versions are
> > supported by the driver it runs with and use the most appropriate one
> > by selecting it at runtime.
> > 
> > What API would you use for that ? Is this something required for this
> > first version where a single format version is available ?
> 
> You need this also for this first version for the reason explained above.
> 
> Personally I would just make a read-only control that returns the highest
> supported version.

Can't userspace use the version number reported through the media device
to determine the features the driver support ? We've done that in
libcamera for some drivers already, either to work around bugs, or to
make use of new features.

> >>> +};
> >>> +
> >>> +/**
> >>> + * struct rkisp1_ext_params_cfg - RkISP1 extensible parameters configuration
> >>> + *
> >>> + * This struct contains the configuration parameters of the RkISP1 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:`rkisp1_ext_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.
> >>> + *
> >>> + * 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
> >>> + * 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 @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 -------------------+
> >>> + *	| version = RKISP_EXT_PARAMS_BUFFER_V1;                               |
> >>> + *	| data_size = sizeof(struct rkisp1_ext_params_bls_config)             |
> >>> + *	|           + sizeof(struct rkisp1_ext_params_dpcc_config);           |
> >>> + *	| +------------------------- data  ---------------------------------+ |
> >>> + *	| | +------------- struct rkisp1_ext_params_bls_config -----------+ | |
> >>> + *	| | | +-------- struct rkisp1_ext_params_block_header  ---------+ | | |
> >>> + *	| | | | type = RKISP1_EXT_PARAMS_BLOCK_TYPE_BLS;                | | | |
> >>> + *	| | | | flags = RKISP1_EXT_PARAMS_FL_BLOCK_ENABLE;              | | | |
> >>> + *	| | | | size = sizeof(struct rkisp1_ext_params_bls_config);     | | | |
> >>> + *	| | | +---------------------------------------------------------+ | | |
> >>> + *	| | | +---------- struct rkisp1_cif_isp_bls_config -------------+ | | |
> >>> + *	| | | | enable_auto = 0;                                        | | | |
> >>> + *	| | | | fixed_val.r = 256;                                      | | | |
> >>> + *	| | | | fixed_val.gr = 256;                                     | | | |
> >>> + *	| | | | fixed_val.gb = 256;                                     | | | |
> >>> + *	| | | | fixed_val.b = 256;                                      | | | |
> >>> + *	| | | +---------------------------------------------------------+ | | |
> >>> + *	| | +------------ struct rkisp1_ext_params_dpcc_config -----------+ | |
> >>> + *	| | | +-------- struct rkisp1_ext_params_block_header  ---------+ | | |
> >>> + *	| | | | type = RKISP1_EXT_PARAMS_BLOCK_TYPE_DPCC;               | | | |
> >>> + *	| | | | flags = RKISP1_EXT_PARAMS_FL_BLOCK_ENABLE;              | | | |
> >>> + *	| | | | size = sizeof(struct rkisp1_ext_params_dpcc_config);    | | | |
> >>> + *	| | | +---------------------------------------------------------+ | | |
> >>> + *	| | | +---------- struct rkisp1_cif_isp_dpcc_config ------------+ | | |
> >>> + *	| | | | mode = RKISP1_CIF_ISP_DPCC_MODE_STAGE1_ENABLE;          | | | |
> >>> + *	| | | | output_mode =                                           | | | |
> >>> + *	| | | |   RKISP1_CIF_ISP_DPCC_OUTPUT_MODE_STAGE1_INCL_G_CENTER; | | | |
> >>> + *	| | | | set_use = ... ;                                         | | | |
> >>> + *	| | | | ...  = ... ;                                            | | | |
> >>> + *	| | | +---------------------------------------------------------+ | | |
> >>> + *	| | +-------------------------------------------------------------+ | |
> >>> + *	| +-----------------------------------------------------------------+ |
> >>> + *	+---------------------------------------------------------------------+
> >>> + *
> >>> + * @version: The RkISP1 extensible parameters buffer version, see
> >>> + *	     :c:type:`rksip1_ext_param_buffer_version`
> >>> + * @data_size: The RkISP1 configuration data effective size, excluding this
> >>> + *	       header
> >>> + * @data: The RkISP1 extensible configuration data blocks
> >>> + */
> >>> +struct rkisp1_ext_params_cfg {
> >>> +	__u32 version;
> >>> +	__u32 data_size;
> >>> +	__u8 data[RKISP1_EXT_PARAMS_MAX_SIZE];
> >>> +};
> >>> +
> >>>  #endif /* _UAPI_RKISP1_CONFIG_H */
Hans Verkuil Aug. 8, 2024, 10:03 a.m. UTC | #5
On 08/08/2024 11:54, Laurent Pinchart wrote:
> On Thu, Aug 08, 2024 at 09:41:42AM +0200, Hans Verkuil wrote:
>> On 08/08/2024 09:24, Jacopo Mondi wrote:
>>> On Thu, Aug 08, 2024 at 08:31:58AM GMT, Hans Verkuil wrote:
>>>> On 07/08/2024 23:22, Jacopo Mondi wrote:
>>>>> Add to the rkisp1-config.h header data types and documentation of
>>>>> the extensible parameters format.
>>>>>
>>>>> Signed-off-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
>>>>> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
>>>>> Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>
>>>>> Tested-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
>>>>> Acked-by: Sakari Ailus <sakari.ailus@linux.intel.com>
>>>>> ---
>>>>>  include/uapi/linux/rkisp1-config.h | 485 +++++++++++++++++++++++++++++
>>>>>  1 file changed, 485 insertions(+)
>>>>>
>>>>> diff --git a/include/uapi/linux/rkisp1-config.h b/include/uapi/linux/rkisp1-config.h
>>>>> index 6eeaf8bf2362..14a23fd9a745 100644
>>>>> --- a/include/uapi/linux/rkisp1-config.h
>>>>> +++ b/include/uapi/linux/rkisp1-config.h
>>>>> @@ -996,4 +996,489 @@ struct rkisp1_stat_buffer {
>>>>>  	struct rkisp1_cif_isp_stat params;
>>>>>  };
>>>>>
>>>>> +/*---------- PART3: Extensible Configuration Parameters  ------------*/
>>>>> +
>>>>> +/**
>>>>> + * enum rkisp1_ext_params_block_type - RkISP1 extensible params block type
>>>>> + *
>>>>> + * @RKISP1_EXT_PARAMS_BLOCK_TYPE_BLS: Black level subtraction
>>>>> + * @RKISP1_EXT_PARAMS_BLOCK_TYPE_DPCC: Defect pixel cluster correction
>>>>> + * @RKISP1_EXT_PARAMS_BLOCK_TYPE_SDG: Sensor de-gamma
>>>>> + * @RKISP1_EXT_PARAMS_BLOCK_TYPE_AWB_GAIN: Auto white balance gains
>>>>> + * @RKISP1_EXT_PARAMS_BLOCK_TYPE_FLT: ISP filtering
>>>>> + * @RKISP1_EXT_PARAMS_BLOCK_TYPE_BDM: Bayer de-mosaic
>>>>> + * @RKISP1_EXT_PARAMS_BLOCK_TYPE_CTK: Cross-talk correction
>>>>> + * @RKISP1_EXT_PARAMS_BLOCK_TYPE_GOC: Gamma out correction
>>>>> + * @RKISP1_EXT_PARAMS_BLOCK_TYPE_DPF: De-noise pre-filter
>>>>> + * @RKISP1_EXT_PARAMS_BLOCK_TYPE_DPF_STRENGTH: De-noise pre-filter strength
>>>>> + * @RKISP1_EXT_PARAMS_BLOCK_TYPE_CPROC: Color processing
>>>>> + * @RKISP1_EXT_PARAMS_BLOCK_TYPE_IE: Image effects
>>>>> + * @RKISP1_EXT_PARAMS_BLOCK_TYPE_LSC: Lens shading correction
>>>>> + * @RKISP1_EXT_PARAMS_BLOCK_TYPE_AWB_MEAS: Auto white balance statistics
>>>>> + * @RKISP1_EXT_PARAMS_BLOCK_TYPE_HST_MEAS: Histogram statistics
>>>>> + * @RKISP1_EXT_PARAMS_BLOCK_TYPE_AEC_MEAS: Auto exposure statistics
>>>>> + * @RKISP1_EXT_PARAMS_BLOCK_TYPE_AFC_MEAS: Auto-focus statistics
>>>>> + */
>>>>> +enum rkisp1_ext_params_block_type {
>>>>> +	RKISP1_EXT_PARAMS_BLOCK_TYPE_BLS,
>>>>> +	RKISP1_EXT_PARAMS_BLOCK_TYPE_DPCC,
>>>>> +	RKISP1_EXT_PARAMS_BLOCK_TYPE_SDG,
>>>>> +	RKISP1_EXT_PARAMS_BLOCK_TYPE_AWB_GAIN,
>>>>> +	RKISP1_EXT_PARAMS_BLOCK_TYPE_FLT,
>>>>> +	RKISP1_EXT_PARAMS_BLOCK_TYPE_BDM,
>>>>> +	RKISP1_EXT_PARAMS_BLOCK_TYPE_CTK,
>>>>> +	RKISP1_EXT_PARAMS_BLOCK_TYPE_GOC,
>>>>> +	RKISP1_EXT_PARAMS_BLOCK_TYPE_DPF,
>>>>> +	RKISP1_EXT_PARAMS_BLOCK_TYPE_DPF_STRENGTH,
>>>>> +	RKISP1_EXT_PARAMS_BLOCK_TYPE_CPROC,
>>>>> +	RKISP1_EXT_PARAMS_BLOCK_TYPE_IE,
>>>>> +	RKISP1_EXT_PARAMS_BLOCK_TYPE_LSC,
>>>>> +	RKISP1_EXT_PARAMS_BLOCK_TYPE_AWB_MEAS,
>>>>> +	RKISP1_EXT_PARAMS_BLOCK_TYPE_HST_MEAS,
>>>>> +	RKISP1_EXT_PARAMS_BLOCK_TYPE_AEC_MEAS,
>>>>> +	RKISP1_EXT_PARAMS_BLOCK_TYPE_AFC_MEAS,
>>>>> +};
>>>>> +
>>>>> +#define RKISP1_EXT_PARAMS_FL_BLOCK_DISABLE	(1U << 0)
>>>>> +#define RKISP1_EXT_PARAMS_FL_BLOCK_ENABLE	(1U << 1)
>>>>> +
>>>>> +/**
>>>>> + * struct rkisp1_ext_params_block_header - RkISP1 extensible parameters 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 size and
>>>>> + * properly handle the block content by casting it to the correct block-specific
>>>>> + * type.
>>>>> + *
>>>>> + * The @type field is one of the values enumerated by
>>>>> + * :c:type:`rkisp1_ext_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 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. The
>>>>> + * driver ignores the rest of the block configuration structure in this case.
>>>>> + *
>>>>> + * 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_DISABLE 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 allowed
>>>>> + * 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:
>>>>> + *
>>>>> + * .. code-block:: c
>>>>> + *
>>>>> + *	void populate_bls(struct rkisp1_ext_params_block_header *block) {
>>>>> + *		struct rkisp1_ext_params_bls_config *bls =
>>>>> + *			(struct rkisp1_ext_params_bls_config *)block;
>>>>> + *
>>>>> + *		bls->header.type = RKISP1_EXT_PARAMS_BLOCK_ID_BLS;
>>>>> + *		bls->header.flags = RKISP1_EXT_PARAMS_FL_BLOCK_ENABLE;
>>>>> + *		bls->header.size = sizeof(*bls);
>>>>> + *
>>>>> + *		bls->config.enable_auto = 0;
>>>>> + *		bls->config.fixed_val.r = blackLevelRed_;
>>>>> + *		bls->config.fixed_val.gr = blackLevelGreenR_;
>>>>> + *		bls->config.fixed_val.gb = blackLevelGreenB_;
>>>>> + *		bls->config.fixed_val.b = 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
>>>>> + */
>>>>> +struct rkisp1_ext_params_block_header {
>>>>> +	__u16 type;
>>>>> +	__u16 flags;
>>>>> +	__u32 size;
>>>>> +};
>>>>> +
>>>>> +/**
>>>>> + * struct rkisp1_ext_params_bls_config - RkISP1 extensible params BLS config
>>>>> + *
>>>>> + * RkISP1 extensible parameters Black Level Subtraction configuration block.
>>>>> + * Identified by :c:type:`RKISP1_EXT_PARAMS_BLOCK_TYPE_BLS`.
>>>>> + *
>>>>> + * @header: The RkISP1 extensible parameters header, see
>>>>> + *	    :c:type:`rkisp1_ext_params_block_header`
>>>>> + * @config: Black Level Subtraction configuration, see
>>>>> + *	    :c:type:`rkisp1_cif_isp_bls_config`
>>>>> + */
>>>>> +struct rkisp1_ext_params_bls_config {
>>>>> +	struct rkisp1_ext_params_block_header header;
>>>>> +	struct rkisp1_cif_isp_bls_config config;
>>>>> +} __attribute__((aligned(8)));
>>>>> +
>>>>> +/**
>>>>> + * struct rkisp1_ext_params_dpcc_config - RkISP1 extensible params DPCC config
>>>>> + *
>>>>> + * RkISP1 extensible parameters Defective Pixel Cluster Correction configuration
>>>>> + * block. Identified by :c:type:`RKISP1_EXT_PARAMS_BLOCK_TYPE_DPCC`.
>>>>> + *
>>>>> + * @header: The RkISP1 extensible parameters header, see
>>>>> + *	    :c:type:`rkisp1_ext_params_block_header`
>>>>> + * @config: Defective Pixel Cluster Correction configuration, see
>>>>> + *	    :c:type:`rkisp1_cif_isp_dpcc_config`
>>>>> + */
>>>>> +struct rkisp1_ext_params_dpcc_config {
>>>>> +	struct rkisp1_ext_params_block_header header;
>>>>> +	struct rkisp1_cif_isp_dpcc_config config;
>>>>> +} __attribute__((aligned(8)));
>>>>> +
>>>>> +/**
>>>>> + * struct rkisp1_ext_params_sdg_config - RkISP1 extensible params SDG config
>>>>> + *
>>>>> + * RkISP1 extensible parameters Sensor Degamma configuration block. Identified
>>>>> + * by :c:type:`RKISP1_EXT_PARAMS_BLOCK_TYPE_SDG`.
>>>>> + *
>>>>> + * @header: The RkISP1 extensible parameters header, see
>>>>> + *	    :c:type:`rkisp1_ext_params_block_header`
>>>>> + * @config: Sensor Degamma configuration, see
>>>>> + *	    :c:type:`rkisp1_cif_isp_sdg_config`
>>>>> + */
>>>>> +struct rkisp1_ext_params_sdg_config {
>>>>> +	struct rkisp1_ext_params_block_header header;
>>>>> +	struct rkisp1_cif_isp_sdg_config config;
>>>>> +} __attribute__((aligned(8)));
>>>>> +
>>>>> +/**
>>>>> + * struct rkisp1_ext_params_lsc_config - RkISP1 extensible params LSC config
>>>>> + *
>>>>> + * RkISP1 extensible parameters Lens Shading Correction configuration block.
>>>>> + * Identified by :c:type:`RKISP1_EXT_PARAMS_BLOCK_TYPE_LSC`.
>>>>> + *
>>>>> + * @header: The RkISP1 extensible parameters header, see
>>>>> + *	    :c:type:`rkisp1_ext_params_block_header`
>>>>> + * @config: Lens Shading Correction configuration, see
>>>>> + *	    :c:type:`rkisp1_cif_isp_lsc_config`
>>>>> + */
>>>>> +struct rkisp1_ext_params_lsc_config {
>>>>> +	struct rkisp1_ext_params_block_header header;
>>>>> +	struct rkisp1_cif_isp_lsc_config config;
>>>>> +} __attribute__((aligned(8)));
>>>>> +
>>>>> +/**
>>>>> + * struct rkisp1_ext_params_awb_gain_config - RkISP1 extensible params AWB
>>>>> + *					      gain config
>>>>> + *
>>>>> + * RkISP1 extensible parameters Auto-White Balance Gains configuration block.
>>>>> + * Identified by :c:type:`RKISP1_EXT_PARAMS_BLOCK_TYPE_AWB_GAIN`.
>>>>> + *
>>>>> + * @header: The RkISP1 extensible parameters header, see
>>>>> + *	    :c:type:`rkisp1_ext_params_block_header`
>>>>> + * @config: Auto-White Balance Gains configuration, see
>>>>> + *	    :c:type:`rkisp1_cif_isp_awb_gain_config`
>>>>> + */
>>>>> +struct rkisp1_ext_params_awb_gain_config {
>>>>> +	struct rkisp1_ext_params_block_header header;
>>>>> +	struct rkisp1_cif_isp_awb_gain_config config;
>>>>> +} __attribute__((aligned(8)));
>>>>> +
>>>>> +/**
>>>>> + * struct rkisp1_ext_params_flt_config - RkISP1 extensible params FLT config
>>>>> + *
>>>>> + * RkISP1 extensible parameters Filter configuration block. Identified by
>>>>> + * :c:type:`RKISP1_EXT_PARAMS_BLOCK_TYPE_FLT`.
>>>>> + *
>>>>> + * @header: The RkISP1 extensible parameters header, see
>>>>> + *	    :c:type:`rkisp1_ext_params_block_header`
>>>>> + * @config: Filter configuration, see :c:type:`rkisp1_cif_isp_flt_config`
>>>>> + */
>>>>> +struct rkisp1_ext_params_flt_config {
>>>>> +	struct rkisp1_ext_params_block_header header;
>>>>> +	struct rkisp1_cif_isp_flt_config config;
>>>>> +} __attribute__((aligned(8)));
>>>>> +
>>>>> +/**
>>>>> + * struct rkisp1_ext_params_bdm_config - RkISP1 extensible params BDM config
>>>>> + *
>>>>> + * RkISP1 extensible parameters Demosaicing configuration block. Identified by
>>>>> + * :c:type:`RKISP1_EXT_PARAMS_BLOCK_TYPE_BDM`.
>>>>> + *
>>>>> + * @header: The RkISP1 extensible parameters header, see
>>>>> + *	    :c:type:`rkisp1_ext_params_block_header`
>>>>> + * @config: Demosaicing configuration, see :c:type:`rkisp1_cif_isp_bdm_config`
>>>>> + */
>>>>> +struct rkisp1_ext_params_bdm_config {
>>>>> +	struct rkisp1_ext_params_block_header header;
>>>>> +	struct rkisp1_cif_isp_bdm_config config;
>>>>> +} __attribute__((aligned(8)));
>>>>> +
>>>>> +/**
>>>>> + * struct rkisp1_ext_params_ctk_config - RkISP1 extensible params CTK config
>>>>> + *
>>>>> + * RkISP1 extensible parameters Cross-Talk configuration block. Identified by
>>>>> + * :c:type:`RKISP1_EXT_PARAMS_BLOCK_TYPE_CTK`.
>>>>> + *
>>>>> + * @header: The RkISP1 extensible parameters header, see
>>>>> + *	    :c:type:`rkisp1_ext_params_block_header`
>>>>> + * @config: Cross-Talk configuration, see :c:type:`rkisp1_cif_isp_ctk_config`
>>>>> + */
>>>>> +struct rkisp1_ext_params_ctk_config {
>>>>> +	struct rkisp1_ext_params_block_header header;
>>>>> +	struct rkisp1_cif_isp_ctk_config config;
>>>>> +} __attribute__((aligned(8)));
>>>>> +
>>>>> +/**
>>>>> + * struct rkisp1_ext_params_goc_config - RkISP1 extensible params GOC config
>>>>> + *
>>>>> + * RkISP1 extensible parameters Gamma-Out configuration block. Identified by
>>>>> + * :c:type:`RKISP1_EXT_PARAMS_BLOCK_TYPE_GOC`.
>>>>> + *
>>>>> + * @header: The RkISP1 extensible parameters header, see
>>>>> + *	    :c:type:`rkisp1_ext_params_block_header`
>>>>> + * @config: Gamma-Out configuration, see :c:type:`rkisp1_cif_isp_goc_config`
>>>>> + */
>>>>> +struct rkisp1_ext_params_goc_config {
>>>>> +	struct rkisp1_ext_params_block_header header;
>>>>> +	struct rkisp1_cif_isp_goc_config config;
>>>>> +} __attribute__((aligned(8)));
>>>>> +
>>>>> +/**
>>>>> + * struct rkisp1_ext_params_dpf_config - RkISP1 extensible params DPF config
>>>>> + *
>>>>> + * RkISP1 extensible parameters De-noise Pre-Filter configuration block.
>>>>> + * Identified by :c:type:`RKISP1_EXT_PARAMS_BLOCK_TYPE_DPF`.
>>>>> + *
>>>>> + * @header: The RkISP1 extensible parameters header, see
>>>>> + *	    :c:type:`rkisp1_ext_params_block_header`
>>>>> + * @config: De-noise Pre-Filter configuration, see
>>>>> + *	    :c:type:`rkisp1_cif_isp_dpf_config`
>>>>> + */
>>>>> +struct rkisp1_ext_params_dpf_config {
>>>>> +	struct rkisp1_ext_params_block_header header;
>>>>> +	struct rkisp1_cif_isp_dpf_config config;
>>>>> +} __attribute__((aligned(8)));
>>>>> +
>>>>> +/**
>>>>> + * struct rkisp1_ext_params_dpf_strength_config - RkISP1 extensible params DPF
>>>>> + *						  strength config
>>>>> + *
>>>>> + * RkISP1 extensible parameters De-noise Pre-Filter strength configuration
>>>>> + * block. Identified by :c:type:`RKISP1_EXT_PARAMS_BLOCK_TYPE_DPF_STRENGTH`.
>>>>> + *
>>>>> + * @header: The RkISP1 extensible parameters header, see
>>>>> + *	    :c:type:`rkisp1_ext_params_block_header`
>>>>> + * @config: De-noise Pre-Filter strength configuration, see
>>>>> + *	    :c:type:`rkisp1_cif_isp_dpf_strength_config`
>>>>> + */
>>>>> +struct rkisp1_ext_params_dpf_strength_config {
>>>>> +	struct rkisp1_ext_params_block_header header;
>>>>> +	struct rkisp1_cif_isp_dpf_strength_config config;
>>>>> +} __attribute__((aligned(8)));
>>>>> +
>>>>> +/**
>>>>> + * struct rkisp1_ext_params_cproc_config - RkISP1 extensible params CPROC config
>>>>> + *
>>>>> + * RkISP1 extensible parameters Color Processing configuration block.
>>>>> + * Identified by :c:type:`RKISP1_EXT_PARAMS_BLOCK_TYPE_CPROC`.
>>>>> + *
>>>>> + * @header: The RkISP1 extensible parameters header, see
>>>>> + *	    :c:type:`rkisp1_ext_params_block_header`
>>>>> + * @config: Color processing configuration, see
>>>>> + *	    :c:type:`rkisp1_cif_isp_cproc_config`
>>>>> + */
>>>>> +struct rkisp1_ext_params_cproc_config {
>>>>> +	struct rkisp1_ext_params_block_header header;
>>>>> +	struct rkisp1_cif_isp_cproc_config config;
>>>>> +} __attribute__((aligned(8)));
>>>>> +
>>>>> +/**
>>>>> + * struct rkisp1_ext_params_ie_config - RkISP1 extensible params IE config
>>>>> + *
>>>>> + * RkISP1 extensible parameters Image Effect configuration block. Identified by
>>>>> + * :c:type:`RKISP1_EXT_PARAMS_BLOCK_TYPE_IE`.
>>>>> + *
>>>>> + * @header: The RkISP1 extensible parameters header, see
>>>>> + *	    :c:type:`rkisp1_ext_params_block_header`
>>>>> + * @config: Image Effect configuration, see :c:type:`rkisp1_cif_isp_ie_config`
>>>>> + */
>>>>> +struct rkisp1_ext_params_ie_config {
>>>>> +	struct rkisp1_ext_params_block_header header;
>>>>> +	struct rkisp1_cif_isp_ie_config config;
>>>>> +} __attribute__((aligned(8)));
>>>>> +
>>>>> +/**
>>>>> + * struct rkisp1_ext_params_awb_meas_config - RkISP1 extensible params AWB
>>>>> + *					      Meas config
>>>>> + *
>>>>> + * RkISP1 extensible parameters Auto-White Balance Measurement configuration
>>>>> + * block. Identified by :c:type:`RKISP1_EXT_PARAMS_BLOCK_TYPE_AWB_MEAS`.
>>>>> + *
>>>>> + * @header: The RkISP1 extensible parameters header, see
>>>>> + *	    :c:type:`rkisp1_ext_params_block_header`
>>>>> + * @config: Auto-White Balance measure configuration, see
>>>>> + *	    :c:type:`rkisp1_cif_isp_awb_meas_config`
>>>>> + */
>>>>> +struct rkisp1_ext_params_awb_meas_config {
>>>>> +	struct rkisp1_ext_params_block_header header;
>>>>> +	struct rkisp1_cif_isp_awb_meas_config config;
>>>>> +} __attribute__((aligned(8)));
>>>>> +
>>>>> +/**
>>>>> + * struct rkisp1_ext_params_hst_config - RkISP1 extensible params Histogram config
>>>>> + *
>>>>> + * RkISP1 extensible parameters Histogram statistics configuration block.
>>>>> + * Identified by :c:type:`RKISP1_EXT_PARAMS_BLOCK_TYPE_HST_MEAS`.
>>>>> + *
>>>>> + * @header: The RkISP1 extensible parameters header, see
>>>>> + *	    :c:type:`rkisp1_ext_params_block_header`
>>>>> + * @config: Histogram statistics configuration, see
>>>>> + *	    :c:type:`rkisp1_cif_isp_hst_config`
>>>>> + */
>>>>> +struct rkisp1_ext_params_hst_config {
>>>>> +	struct rkisp1_ext_params_block_header header;
>>>>> +	struct rkisp1_cif_isp_hst_config config;
>>>>> +} __attribute__((aligned(8)));
>>>>> +
>>>>> +/**
>>>>> + * struct rkisp1_ext_params_aec_config - RkISP1 extensible params AEC config
>>>>> + *
>>>>> + * RkISP1 extensible parameters Auto-Exposure statistics configuration block.
>>>>> + * Identified by :c:type:`RKISP1_EXT_PARAMS_BLOCK_TYPE_AEC_MEAS`.
>>>>> + *
>>>>> + * @header: The RkISP1 extensible parameters header, see
>>>>> + *	    :c:type:`rkisp1_ext_params_block_header`
>>>>> + * @config: Auto-Exposure statistics configuration, see
>>>>> + *	    :c:type:`rkisp1_cif_isp_aec_config`
>>>>> + */
>>>>> +struct rkisp1_ext_params_aec_config {
>>>>> +	struct rkisp1_ext_params_block_header header;
>>>>> +	struct rkisp1_cif_isp_aec_config config;
>>>>> +} __attribute__((aligned(8)));
>>>>> +
>>>>> +/**
>>>>> + * struct rkisp1_ext_params_afc_config - RkISP1 extensible params AFC config
>>>>> + *
>>>>> + * RkISP1 extensible parameters Auto-Focus statistics configuration block.
>>>>> + * Identified by :c:type:`RKISP1_EXT_PARAMS_BLOCK_TYPE_AFC_MEAS`.
>>>>> + *
>>>>> + * @header: The RkISP1 extensible parameters header, see
>>>>> + *	    :c:type:`rkisp1_ext_params_block_header`
>>>>> + * @config: Auto-Focus statistics configuration, see
>>>>> + *	    :c:type:`rkisp1_cif_isp_afc_config`
>>>>> + */
>>>>> +struct rkisp1_ext_params_afc_config {
>>>>> +	struct rkisp1_ext_params_block_header header;
>>>>> +	struct rkisp1_cif_isp_afc_config config;
>>>>> +} __attribute__((aligned(8)));
>>>>> +
>>>>> +#define RKISP1_EXT_PARAMS_MAX_SIZE					\
>>>>> +	(sizeof(struct rkisp1_ext_params_bls_config)			+\
>>>>> +	sizeof(struct rkisp1_ext_params_dpcc_config)			+\
>>>>> +	sizeof(struct rkisp1_ext_params_sdg_config)			+\
>>>>> +	sizeof(struct rkisp1_ext_params_lsc_config)			+\
>>>>> +	sizeof(struct rkisp1_ext_params_awb_gain_config)		+\
>>>>> +	sizeof(struct rkisp1_ext_params_flt_config)			+\
>>>>> +	sizeof(struct rkisp1_ext_params_bdm_config)			+\
>>>>> +	sizeof(struct rkisp1_ext_params_ctk_config)			+\
>>>>> +	sizeof(struct rkisp1_ext_params_goc_config)			+\
>>>>> +	sizeof(struct rkisp1_ext_params_dpf_config)			+\
>>>>> +	sizeof(struct rkisp1_ext_params_dpf_strength_config)		+\
>>>>> +	sizeof(struct rkisp1_ext_params_cproc_config)			+\
>>>>> +	sizeof(struct rkisp1_ext_params_ie_config)			+\
>>>>> +	sizeof(struct rkisp1_ext_params_awb_meas_config)		+\
>>>>> +	sizeof(struct rkisp1_ext_params_hst_config)			+\
>>>>> +	sizeof(struct rkisp1_ext_params_aec_config)			+\
>>>>> +	sizeof(struct rkisp1_ext_params_afc_config))
>>>>> +
>>>>> +/**
>>>>> + * enum rksip1_ext_param_buffer_version - RkISP1 extensible parameters version
>>>>> + *
>>>>> + * @RKISP1_EXT_PARAM_BUFFER_V1: First version of RkISP1 extensible parameters
>>>>> + */
>>>>> +enum rksip1_ext_param_buffer_version {
>>>>> +	RKISP1_EXT_PARAM_BUFFER_V1 = 1,
>>>>
>>>> I see no check against this in the rkisp1 code. Shouldn't this be checked?
>>>> If the version is unsupported, then just return an error.
>>>
>>> Do we need this for the first version ? There are no other versions
>>> userspace can use at the moment. I can add a check during validation
>>> though.
>>
>> Yes: if a V2 is added in the future, and an application wants to use that
>> against a driver that only support V1, then that should fail.
>>
>>>> Also, how does userspace know which version(s) is/are supported by the driver?
>>>
>>> Good question, there is no API for that atm. Defining a new format
>>> version should only happen when a non-backward compatible change to
>>> the format is made. I understand an application can be compiled
>>> against a newer kernel header that provides a new format version but
>>> then run on an older kernel where the new format is not supported.
>>>
>>> Probably userspace should be able to identify what versions are
>>> supported by the driver it runs with and use the most appropriate one
>>> by selecting it at runtime.
>>>
>>> What API would you use for that ? Is this something required for this
>>> first version where a single format version is available ?
>>
>> You need this also for this first version for the reason explained above.
>>
>> Personally I would just make a read-only control that returns the highest
>> supported version.
> 
> Can't userspace use the version number reported through the media device
> to determine the features the driver support ? We've done that in
> libcamera for some drivers already, either to work around bugs, or to
> make use of new features.

You can, but this will fall down if the driver is backported to an older
kernel for whatever reason. Since the version is just the kernel version,
it will drop back to that older kernel version.

Whether that is acceptable or not is up to you.

In any case, this would have to be documented so you know at which kernel
version a new RKISP1_EXT_PARAM_BUFFER_Vx is introduced.

Regards,

	Hans

> 
>>>>> +};
>>>>> +
>>>>> +/**
>>>>> + * struct rkisp1_ext_params_cfg - RkISP1 extensible parameters configuration
>>>>> + *
>>>>> + * This struct contains the configuration parameters of the RkISP1 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:`rkisp1_ext_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.
>>>>> + *
>>>>> + * 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
>>>>> + * 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 @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 -------------------+
>>>>> + *	| version = RKISP_EXT_PARAMS_BUFFER_V1;                               |
>>>>> + *	| data_size = sizeof(struct rkisp1_ext_params_bls_config)             |
>>>>> + *	|           + sizeof(struct rkisp1_ext_params_dpcc_config);           |
>>>>> + *	| +------------------------- data  ---------------------------------+ |
>>>>> + *	| | +------------- struct rkisp1_ext_params_bls_config -----------+ | |
>>>>> + *	| | | +-------- struct rkisp1_ext_params_block_header  ---------+ | | |
>>>>> + *	| | | | type = RKISP1_EXT_PARAMS_BLOCK_TYPE_BLS;                | | | |
>>>>> + *	| | | | flags = RKISP1_EXT_PARAMS_FL_BLOCK_ENABLE;              | | | |
>>>>> + *	| | | | size = sizeof(struct rkisp1_ext_params_bls_config);     | | | |
>>>>> + *	| | | +---------------------------------------------------------+ | | |
>>>>> + *	| | | +---------- struct rkisp1_cif_isp_bls_config -------------+ | | |
>>>>> + *	| | | | enable_auto = 0;                                        | | | |
>>>>> + *	| | | | fixed_val.r = 256;                                      | | | |
>>>>> + *	| | | | fixed_val.gr = 256;                                     | | | |
>>>>> + *	| | | | fixed_val.gb = 256;                                     | | | |
>>>>> + *	| | | | fixed_val.b = 256;                                      | | | |
>>>>> + *	| | | +---------------------------------------------------------+ | | |
>>>>> + *	| | +------------ struct rkisp1_ext_params_dpcc_config -----------+ | |
>>>>> + *	| | | +-------- struct rkisp1_ext_params_block_header  ---------+ | | |
>>>>> + *	| | | | type = RKISP1_EXT_PARAMS_BLOCK_TYPE_DPCC;               | | | |
>>>>> + *	| | | | flags = RKISP1_EXT_PARAMS_FL_BLOCK_ENABLE;              | | | |
>>>>> + *	| | | | size = sizeof(struct rkisp1_ext_params_dpcc_config);    | | | |
>>>>> + *	| | | +---------------------------------------------------------+ | | |
>>>>> + *	| | | +---------- struct rkisp1_cif_isp_dpcc_config ------------+ | | |
>>>>> + *	| | | | mode = RKISP1_CIF_ISP_DPCC_MODE_STAGE1_ENABLE;          | | | |
>>>>> + *	| | | | output_mode =                                           | | | |
>>>>> + *	| | | |   RKISP1_CIF_ISP_DPCC_OUTPUT_MODE_STAGE1_INCL_G_CENTER; | | | |
>>>>> + *	| | | | set_use = ... ;                                         | | | |
>>>>> + *	| | | | ...  = ... ;                                            | | | |
>>>>> + *	| | | +---------------------------------------------------------+ | | |
>>>>> + *	| | +-------------------------------------------------------------+ | |
>>>>> + *	| +-----------------------------------------------------------------+ |
>>>>> + *	+---------------------------------------------------------------------+
>>>>> + *
>>>>> + * @version: The RkISP1 extensible parameters buffer version, see
>>>>> + *	     :c:type:`rksip1_ext_param_buffer_version`
>>>>> + * @data_size: The RkISP1 configuration data effective size, excluding this
>>>>> + *	       header
>>>>> + * @data: The RkISP1 extensible configuration data blocks
>>>>> + */
>>>>> +struct rkisp1_ext_params_cfg {
>>>>> +	__u32 version;
>>>>> +	__u32 data_size;
>>>>> +	__u8 data[RKISP1_EXT_PARAMS_MAX_SIZE];
>>>>> +};
>>>>> +
>>>>>  #endif /* _UAPI_RKISP1_CONFIG_H */
>
Laurent Pinchart Aug. 8, 2024, 10:51 a.m. UTC | #6
On Thu, Aug 08, 2024 at 12:03:01PM +0200, Hans Verkuil wrote:
> On 08/08/2024 11:54, Laurent Pinchart wrote:
> > On Thu, Aug 08, 2024 at 09:41:42AM +0200, Hans Verkuil wrote:
> >> On 08/08/2024 09:24, Jacopo Mondi wrote:
> >>> On Thu, Aug 08, 2024 at 08:31:58AM GMT, Hans Verkuil wrote:
> >>>> On 07/08/2024 23:22, Jacopo Mondi wrote:
> >>>>> Add to the rkisp1-config.h header data types and documentation of
> >>>>> the extensible parameters format.
> >>>>>
> >>>>> Signed-off-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
> >>>>> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> >>>>> Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>
> >>>>> Tested-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
> >>>>> Acked-by: Sakari Ailus <sakari.ailus@linux.intel.com>
> >>>>> ---
> >>>>>  include/uapi/linux/rkisp1-config.h | 485 +++++++++++++++++++++++++++++
> >>>>>  1 file changed, 485 insertions(+)
> >>>>>
> >>>>> diff --git a/include/uapi/linux/rkisp1-config.h b/include/uapi/linux/rkisp1-config.h
> >>>>> index 6eeaf8bf2362..14a23fd9a745 100644
> >>>>> --- a/include/uapi/linux/rkisp1-config.h
> >>>>> +++ b/include/uapi/linux/rkisp1-config.h
> >>>>> @@ -996,4 +996,489 @@ struct rkisp1_stat_buffer {
> >>>>>  	struct rkisp1_cif_isp_stat params;
> >>>>>  };
> >>>>>
> >>>>> +/*---------- PART3: Extensible Configuration Parameters  ------------*/
> >>>>> +
> >>>>> +/**
> >>>>> + * enum rkisp1_ext_params_block_type - RkISP1 extensible params block type
> >>>>> + *
> >>>>> + * @RKISP1_EXT_PARAMS_BLOCK_TYPE_BLS: Black level subtraction
> >>>>> + * @RKISP1_EXT_PARAMS_BLOCK_TYPE_DPCC: Defect pixel cluster correction
> >>>>> + * @RKISP1_EXT_PARAMS_BLOCK_TYPE_SDG: Sensor de-gamma
> >>>>> + * @RKISP1_EXT_PARAMS_BLOCK_TYPE_AWB_GAIN: Auto white balance gains
> >>>>> + * @RKISP1_EXT_PARAMS_BLOCK_TYPE_FLT: ISP filtering
> >>>>> + * @RKISP1_EXT_PARAMS_BLOCK_TYPE_BDM: Bayer de-mosaic
> >>>>> + * @RKISP1_EXT_PARAMS_BLOCK_TYPE_CTK: Cross-talk correction
> >>>>> + * @RKISP1_EXT_PARAMS_BLOCK_TYPE_GOC: Gamma out correction
> >>>>> + * @RKISP1_EXT_PARAMS_BLOCK_TYPE_DPF: De-noise pre-filter
> >>>>> + * @RKISP1_EXT_PARAMS_BLOCK_TYPE_DPF_STRENGTH: De-noise pre-filter strength
> >>>>> + * @RKISP1_EXT_PARAMS_BLOCK_TYPE_CPROC: Color processing
> >>>>> + * @RKISP1_EXT_PARAMS_BLOCK_TYPE_IE: Image effects
> >>>>> + * @RKISP1_EXT_PARAMS_BLOCK_TYPE_LSC: Lens shading correction
> >>>>> + * @RKISP1_EXT_PARAMS_BLOCK_TYPE_AWB_MEAS: Auto white balance statistics
> >>>>> + * @RKISP1_EXT_PARAMS_BLOCK_TYPE_HST_MEAS: Histogram statistics
> >>>>> + * @RKISP1_EXT_PARAMS_BLOCK_TYPE_AEC_MEAS: Auto exposure statistics
> >>>>> + * @RKISP1_EXT_PARAMS_BLOCK_TYPE_AFC_MEAS: Auto-focus statistics
> >>>>> + */
> >>>>> +enum rkisp1_ext_params_block_type {
> >>>>> +	RKISP1_EXT_PARAMS_BLOCK_TYPE_BLS,
> >>>>> +	RKISP1_EXT_PARAMS_BLOCK_TYPE_DPCC,
> >>>>> +	RKISP1_EXT_PARAMS_BLOCK_TYPE_SDG,
> >>>>> +	RKISP1_EXT_PARAMS_BLOCK_TYPE_AWB_GAIN,
> >>>>> +	RKISP1_EXT_PARAMS_BLOCK_TYPE_FLT,
> >>>>> +	RKISP1_EXT_PARAMS_BLOCK_TYPE_BDM,
> >>>>> +	RKISP1_EXT_PARAMS_BLOCK_TYPE_CTK,
> >>>>> +	RKISP1_EXT_PARAMS_BLOCK_TYPE_GOC,
> >>>>> +	RKISP1_EXT_PARAMS_BLOCK_TYPE_DPF,
> >>>>> +	RKISP1_EXT_PARAMS_BLOCK_TYPE_DPF_STRENGTH,
> >>>>> +	RKISP1_EXT_PARAMS_BLOCK_TYPE_CPROC,
> >>>>> +	RKISP1_EXT_PARAMS_BLOCK_TYPE_IE,
> >>>>> +	RKISP1_EXT_PARAMS_BLOCK_TYPE_LSC,
> >>>>> +	RKISP1_EXT_PARAMS_BLOCK_TYPE_AWB_MEAS,
> >>>>> +	RKISP1_EXT_PARAMS_BLOCK_TYPE_HST_MEAS,
> >>>>> +	RKISP1_EXT_PARAMS_BLOCK_TYPE_AEC_MEAS,
> >>>>> +	RKISP1_EXT_PARAMS_BLOCK_TYPE_AFC_MEAS,
> >>>>> +};
> >>>>> +
> >>>>> +#define RKISP1_EXT_PARAMS_FL_BLOCK_DISABLE	(1U << 0)
> >>>>> +#define RKISP1_EXT_PARAMS_FL_BLOCK_ENABLE	(1U << 1)
> >>>>> +
> >>>>> +/**
> >>>>> + * struct rkisp1_ext_params_block_header - RkISP1 extensible parameters 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 size and
> >>>>> + * properly handle the block content by casting it to the correct block-specific
> >>>>> + * type.
> >>>>> + *
> >>>>> + * The @type field is one of the values enumerated by
> >>>>> + * :c:type:`rkisp1_ext_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 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. The
> >>>>> + * driver ignores the rest of the block configuration structure in this case.
> >>>>> + *
> >>>>> + * 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_DISABLE 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 allowed
> >>>>> + * 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:
> >>>>> + *
> >>>>> + * .. code-block:: c
> >>>>> + *
> >>>>> + *	void populate_bls(struct rkisp1_ext_params_block_header *block) {
> >>>>> + *		struct rkisp1_ext_params_bls_config *bls =
> >>>>> + *			(struct rkisp1_ext_params_bls_config *)block;
> >>>>> + *
> >>>>> + *		bls->header.type = RKISP1_EXT_PARAMS_BLOCK_ID_BLS;
> >>>>> + *		bls->header.flags = RKISP1_EXT_PARAMS_FL_BLOCK_ENABLE;
> >>>>> + *		bls->header.size = sizeof(*bls);
> >>>>> + *
> >>>>> + *		bls->config.enable_auto = 0;
> >>>>> + *		bls->config.fixed_val.r = blackLevelRed_;
> >>>>> + *		bls->config.fixed_val.gr = blackLevelGreenR_;
> >>>>> + *		bls->config.fixed_val.gb = blackLevelGreenB_;
> >>>>> + *		bls->config.fixed_val.b = 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
> >>>>> + */
> >>>>> +struct rkisp1_ext_params_block_header {
> >>>>> +	__u16 type;
> >>>>> +	__u16 flags;
> >>>>> +	__u32 size;
> >>>>> +};
> >>>>> +
> >>>>> +/**
> >>>>> + * struct rkisp1_ext_params_bls_config - RkISP1 extensible params BLS config
> >>>>> + *
> >>>>> + * RkISP1 extensible parameters Black Level Subtraction configuration block.
> >>>>> + * Identified by :c:type:`RKISP1_EXT_PARAMS_BLOCK_TYPE_BLS`.
> >>>>> + *
> >>>>> + * @header: The RkISP1 extensible parameters header, see
> >>>>> + *	    :c:type:`rkisp1_ext_params_block_header`
> >>>>> + * @config: Black Level Subtraction configuration, see
> >>>>> + *	    :c:type:`rkisp1_cif_isp_bls_config`
> >>>>> + */
> >>>>> +struct rkisp1_ext_params_bls_config {
> >>>>> +	struct rkisp1_ext_params_block_header header;
> >>>>> +	struct rkisp1_cif_isp_bls_config config;
> >>>>> +} __attribute__((aligned(8)));
> >>>>> +
> >>>>> +/**
> >>>>> + * struct rkisp1_ext_params_dpcc_config - RkISP1 extensible params DPCC config
> >>>>> + *
> >>>>> + * RkISP1 extensible parameters Defective Pixel Cluster Correction configuration
> >>>>> + * block. Identified by :c:type:`RKISP1_EXT_PARAMS_BLOCK_TYPE_DPCC`.
> >>>>> + *
> >>>>> + * @header: The RkISP1 extensible parameters header, see
> >>>>> + *	    :c:type:`rkisp1_ext_params_block_header`
> >>>>> + * @config: Defective Pixel Cluster Correction configuration, see
> >>>>> + *	    :c:type:`rkisp1_cif_isp_dpcc_config`
> >>>>> + */
> >>>>> +struct rkisp1_ext_params_dpcc_config {
> >>>>> +	struct rkisp1_ext_params_block_header header;
> >>>>> +	struct rkisp1_cif_isp_dpcc_config config;
> >>>>> +} __attribute__((aligned(8)));
> >>>>> +
> >>>>> +/**
> >>>>> + * struct rkisp1_ext_params_sdg_config - RkISP1 extensible params SDG config
> >>>>> + *
> >>>>> + * RkISP1 extensible parameters Sensor Degamma configuration block. Identified
> >>>>> + * by :c:type:`RKISP1_EXT_PARAMS_BLOCK_TYPE_SDG`.
> >>>>> + *
> >>>>> + * @header: The RkISP1 extensible parameters header, see
> >>>>> + *	    :c:type:`rkisp1_ext_params_block_header`
> >>>>> + * @config: Sensor Degamma configuration, see
> >>>>> + *	    :c:type:`rkisp1_cif_isp_sdg_config`
> >>>>> + */
> >>>>> +struct rkisp1_ext_params_sdg_config {
> >>>>> +	struct rkisp1_ext_params_block_header header;
> >>>>> +	struct rkisp1_cif_isp_sdg_config config;
> >>>>> +} __attribute__((aligned(8)));
> >>>>> +
> >>>>> +/**
> >>>>> + * struct rkisp1_ext_params_lsc_config - RkISP1 extensible params LSC config
> >>>>> + *
> >>>>> + * RkISP1 extensible parameters Lens Shading Correction configuration block.
> >>>>> + * Identified by :c:type:`RKISP1_EXT_PARAMS_BLOCK_TYPE_LSC`.
> >>>>> + *
> >>>>> + * @header: The RkISP1 extensible parameters header, see
> >>>>> + *	    :c:type:`rkisp1_ext_params_block_header`
> >>>>> + * @config: Lens Shading Correction configuration, see
> >>>>> + *	    :c:type:`rkisp1_cif_isp_lsc_config`
> >>>>> + */
> >>>>> +struct rkisp1_ext_params_lsc_config {
> >>>>> +	struct rkisp1_ext_params_block_header header;
> >>>>> +	struct rkisp1_cif_isp_lsc_config config;
> >>>>> +} __attribute__((aligned(8)));
> >>>>> +
> >>>>> +/**
> >>>>> + * struct rkisp1_ext_params_awb_gain_config - RkISP1 extensible params AWB
> >>>>> + *					      gain config
> >>>>> + *
> >>>>> + * RkISP1 extensible parameters Auto-White Balance Gains configuration block.
> >>>>> + * Identified by :c:type:`RKISP1_EXT_PARAMS_BLOCK_TYPE_AWB_GAIN`.
> >>>>> + *
> >>>>> + * @header: The RkISP1 extensible parameters header, see
> >>>>> + *	    :c:type:`rkisp1_ext_params_block_header`
> >>>>> + * @config: Auto-White Balance Gains configuration, see
> >>>>> + *	    :c:type:`rkisp1_cif_isp_awb_gain_config`
> >>>>> + */
> >>>>> +struct rkisp1_ext_params_awb_gain_config {
> >>>>> +	struct rkisp1_ext_params_block_header header;
> >>>>> +	struct rkisp1_cif_isp_awb_gain_config config;
> >>>>> +} __attribute__((aligned(8)));
> >>>>> +
> >>>>> +/**
> >>>>> + * struct rkisp1_ext_params_flt_config - RkISP1 extensible params FLT config
> >>>>> + *
> >>>>> + * RkISP1 extensible parameters Filter configuration block. Identified by
> >>>>> + * :c:type:`RKISP1_EXT_PARAMS_BLOCK_TYPE_FLT`.
> >>>>> + *
> >>>>> + * @header: The RkISP1 extensible parameters header, see
> >>>>> + *	    :c:type:`rkisp1_ext_params_block_header`
> >>>>> + * @config: Filter configuration, see :c:type:`rkisp1_cif_isp_flt_config`
> >>>>> + */
> >>>>> +struct rkisp1_ext_params_flt_config {
> >>>>> +	struct rkisp1_ext_params_block_header header;
> >>>>> +	struct rkisp1_cif_isp_flt_config config;
> >>>>> +} __attribute__((aligned(8)));
> >>>>> +
> >>>>> +/**
> >>>>> + * struct rkisp1_ext_params_bdm_config - RkISP1 extensible params BDM config
> >>>>> + *
> >>>>> + * RkISP1 extensible parameters Demosaicing configuration block. Identified by
> >>>>> + * :c:type:`RKISP1_EXT_PARAMS_BLOCK_TYPE_BDM`.
> >>>>> + *
> >>>>> + * @header: The RkISP1 extensible parameters header, see
> >>>>> + *	    :c:type:`rkisp1_ext_params_block_header`
> >>>>> + * @config: Demosaicing configuration, see :c:type:`rkisp1_cif_isp_bdm_config`
> >>>>> + */
> >>>>> +struct rkisp1_ext_params_bdm_config {
> >>>>> +	struct rkisp1_ext_params_block_header header;
> >>>>> +	struct rkisp1_cif_isp_bdm_config config;
> >>>>> +} __attribute__((aligned(8)));
> >>>>> +
> >>>>> +/**
> >>>>> + * struct rkisp1_ext_params_ctk_config - RkISP1 extensible params CTK config
> >>>>> + *
> >>>>> + * RkISP1 extensible parameters Cross-Talk configuration block. Identified by
> >>>>> + * :c:type:`RKISP1_EXT_PARAMS_BLOCK_TYPE_CTK`.
> >>>>> + *
> >>>>> + * @header: The RkISP1 extensible parameters header, see
> >>>>> + *	    :c:type:`rkisp1_ext_params_block_header`
> >>>>> + * @config: Cross-Talk configuration, see :c:type:`rkisp1_cif_isp_ctk_config`
> >>>>> + */
> >>>>> +struct rkisp1_ext_params_ctk_config {
> >>>>> +	struct rkisp1_ext_params_block_header header;
> >>>>> +	struct rkisp1_cif_isp_ctk_config config;
> >>>>> +} __attribute__((aligned(8)));
> >>>>> +
> >>>>> +/**
> >>>>> + * struct rkisp1_ext_params_goc_config - RkISP1 extensible params GOC config
> >>>>> + *
> >>>>> + * RkISP1 extensible parameters Gamma-Out configuration block. Identified by
> >>>>> + * :c:type:`RKISP1_EXT_PARAMS_BLOCK_TYPE_GOC`.
> >>>>> + *
> >>>>> + * @header: The RkISP1 extensible parameters header, see
> >>>>> + *	    :c:type:`rkisp1_ext_params_block_header`
> >>>>> + * @config: Gamma-Out configuration, see :c:type:`rkisp1_cif_isp_goc_config`
> >>>>> + */
> >>>>> +struct rkisp1_ext_params_goc_config {
> >>>>> +	struct rkisp1_ext_params_block_header header;
> >>>>> +	struct rkisp1_cif_isp_goc_config config;
> >>>>> +} __attribute__((aligned(8)));
> >>>>> +
> >>>>> +/**
> >>>>> + * struct rkisp1_ext_params_dpf_config - RkISP1 extensible params DPF config
> >>>>> + *
> >>>>> + * RkISP1 extensible parameters De-noise Pre-Filter configuration block.
> >>>>> + * Identified by :c:type:`RKISP1_EXT_PARAMS_BLOCK_TYPE_DPF`.
> >>>>> + *
> >>>>> + * @header: The RkISP1 extensible parameters header, see
> >>>>> + *	    :c:type:`rkisp1_ext_params_block_header`
> >>>>> + * @config: De-noise Pre-Filter configuration, see
> >>>>> + *	    :c:type:`rkisp1_cif_isp_dpf_config`
> >>>>> + */
> >>>>> +struct rkisp1_ext_params_dpf_config {
> >>>>> +	struct rkisp1_ext_params_block_header header;
> >>>>> +	struct rkisp1_cif_isp_dpf_config config;
> >>>>> +} __attribute__((aligned(8)));
> >>>>> +
> >>>>> +/**
> >>>>> + * struct rkisp1_ext_params_dpf_strength_config - RkISP1 extensible params DPF
> >>>>> + *						  strength config
> >>>>> + *
> >>>>> + * RkISP1 extensible parameters De-noise Pre-Filter strength configuration
> >>>>> + * block. Identified by :c:type:`RKISP1_EXT_PARAMS_BLOCK_TYPE_DPF_STRENGTH`.
> >>>>> + *
> >>>>> + * @header: The RkISP1 extensible parameters header, see
> >>>>> + *	    :c:type:`rkisp1_ext_params_block_header`
> >>>>> + * @config: De-noise Pre-Filter strength configuration, see
> >>>>> + *	    :c:type:`rkisp1_cif_isp_dpf_strength_config`
> >>>>> + */
> >>>>> +struct rkisp1_ext_params_dpf_strength_config {
> >>>>> +	struct rkisp1_ext_params_block_header header;
> >>>>> +	struct rkisp1_cif_isp_dpf_strength_config config;
> >>>>> +} __attribute__((aligned(8)));
> >>>>> +
> >>>>> +/**
> >>>>> + * struct rkisp1_ext_params_cproc_config - RkISP1 extensible params CPROC config
> >>>>> + *
> >>>>> + * RkISP1 extensible parameters Color Processing configuration block.
> >>>>> + * Identified by :c:type:`RKISP1_EXT_PARAMS_BLOCK_TYPE_CPROC`.
> >>>>> + *
> >>>>> + * @header: The RkISP1 extensible parameters header, see
> >>>>> + *	    :c:type:`rkisp1_ext_params_block_header`
> >>>>> + * @config: Color processing configuration, see
> >>>>> + *	    :c:type:`rkisp1_cif_isp_cproc_config`
> >>>>> + */
> >>>>> +struct rkisp1_ext_params_cproc_config {
> >>>>> +	struct rkisp1_ext_params_block_header header;
> >>>>> +	struct rkisp1_cif_isp_cproc_config config;
> >>>>> +} __attribute__((aligned(8)));
> >>>>> +
> >>>>> +/**
> >>>>> + * struct rkisp1_ext_params_ie_config - RkISP1 extensible params IE config
> >>>>> + *
> >>>>> + * RkISP1 extensible parameters Image Effect configuration block. Identified by
> >>>>> + * :c:type:`RKISP1_EXT_PARAMS_BLOCK_TYPE_IE`.
> >>>>> + *
> >>>>> + * @header: The RkISP1 extensible parameters header, see
> >>>>> + *	    :c:type:`rkisp1_ext_params_block_header`
> >>>>> + * @config: Image Effect configuration, see :c:type:`rkisp1_cif_isp_ie_config`
> >>>>> + */
> >>>>> +struct rkisp1_ext_params_ie_config {
> >>>>> +	struct rkisp1_ext_params_block_header header;
> >>>>> +	struct rkisp1_cif_isp_ie_config config;
> >>>>> +} __attribute__((aligned(8)));
> >>>>> +
> >>>>> +/**
> >>>>> + * struct rkisp1_ext_params_awb_meas_config - RkISP1 extensible params AWB
> >>>>> + *					      Meas config
> >>>>> + *
> >>>>> + * RkISP1 extensible parameters Auto-White Balance Measurement configuration
> >>>>> + * block. Identified by :c:type:`RKISP1_EXT_PARAMS_BLOCK_TYPE_AWB_MEAS`.
> >>>>> + *
> >>>>> + * @header: The RkISP1 extensible parameters header, see
> >>>>> + *	    :c:type:`rkisp1_ext_params_block_header`
> >>>>> + * @config: Auto-White Balance measure configuration, see
> >>>>> + *	    :c:type:`rkisp1_cif_isp_awb_meas_config`
> >>>>> + */
> >>>>> +struct rkisp1_ext_params_awb_meas_config {
> >>>>> +	struct rkisp1_ext_params_block_header header;
> >>>>> +	struct rkisp1_cif_isp_awb_meas_config config;
> >>>>> +} __attribute__((aligned(8)));
> >>>>> +
> >>>>> +/**
> >>>>> + * struct rkisp1_ext_params_hst_config - RkISP1 extensible params Histogram config
> >>>>> + *
> >>>>> + * RkISP1 extensible parameters Histogram statistics configuration block.
> >>>>> + * Identified by :c:type:`RKISP1_EXT_PARAMS_BLOCK_TYPE_HST_MEAS`.
> >>>>> + *
> >>>>> + * @header: The RkISP1 extensible parameters header, see
> >>>>> + *	    :c:type:`rkisp1_ext_params_block_header`
> >>>>> + * @config: Histogram statistics configuration, see
> >>>>> + *	    :c:type:`rkisp1_cif_isp_hst_config`
> >>>>> + */
> >>>>> +struct rkisp1_ext_params_hst_config {
> >>>>> +	struct rkisp1_ext_params_block_header header;
> >>>>> +	struct rkisp1_cif_isp_hst_config config;
> >>>>> +} __attribute__((aligned(8)));
> >>>>> +
> >>>>> +/**
> >>>>> + * struct rkisp1_ext_params_aec_config - RkISP1 extensible params AEC config
> >>>>> + *
> >>>>> + * RkISP1 extensible parameters Auto-Exposure statistics configuration block.
> >>>>> + * Identified by :c:type:`RKISP1_EXT_PARAMS_BLOCK_TYPE_AEC_MEAS`.
> >>>>> + *
> >>>>> + * @header: The RkISP1 extensible parameters header, see
> >>>>> + *	    :c:type:`rkisp1_ext_params_block_header`
> >>>>> + * @config: Auto-Exposure statistics configuration, see
> >>>>> + *	    :c:type:`rkisp1_cif_isp_aec_config`
> >>>>> + */
> >>>>> +struct rkisp1_ext_params_aec_config {
> >>>>> +	struct rkisp1_ext_params_block_header header;
> >>>>> +	struct rkisp1_cif_isp_aec_config config;
> >>>>> +} __attribute__((aligned(8)));
> >>>>> +
> >>>>> +/**
> >>>>> + * struct rkisp1_ext_params_afc_config - RkISP1 extensible params AFC config
> >>>>> + *
> >>>>> + * RkISP1 extensible parameters Auto-Focus statistics configuration block.
> >>>>> + * Identified by :c:type:`RKISP1_EXT_PARAMS_BLOCK_TYPE_AFC_MEAS`.
> >>>>> + *
> >>>>> + * @header: The RkISP1 extensible parameters header, see
> >>>>> + *	    :c:type:`rkisp1_ext_params_block_header`
> >>>>> + * @config: Auto-Focus statistics configuration, see
> >>>>> + *	    :c:type:`rkisp1_cif_isp_afc_config`
> >>>>> + */
> >>>>> +struct rkisp1_ext_params_afc_config {
> >>>>> +	struct rkisp1_ext_params_block_header header;
> >>>>> +	struct rkisp1_cif_isp_afc_config config;
> >>>>> +} __attribute__((aligned(8)));
> >>>>> +
> >>>>> +#define RKISP1_EXT_PARAMS_MAX_SIZE					\
> >>>>> +	(sizeof(struct rkisp1_ext_params_bls_config)			+\
> >>>>> +	sizeof(struct rkisp1_ext_params_dpcc_config)			+\
> >>>>> +	sizeof(struct rkisp1_ext_params_sdg_config)			+\
> >>>>> +	sizeof(struct rkisp1_ext_params_lsc_config)			+\
> >>>>> +	sizeof(struct rkisp1_ext_params_awb_gain_config)		+\
> >>>>> +	sizeof(struct rkisp1_ext_params_flt_config)			+\
> >>>>> +	sizeof(struct rkisp1_ext_params_bdm_config)			+\
> >>>>> +	sizeof(struct rkisp1_ext_params_ctk_config)			+\
> >>>>> +	sizeof(struct rkisp1_ext_params_goc_config)			+\
> >>>>> +	sizeof(struct rkisp1_ext_params_dpf_config)			+\
> >>>>> +	sizeof(struct rkisp1_ext_params_dpf_strength_config)		+\
> >>>>> +	sizeof(struct rkisp1_ext_params_cproc_config)			+\
> >>>>> +	sizeof(struct rkisp1_ext_params_ie_config)			+\
> >>>>> +	sizeof(struct rkisp1_ext_params_awb_meas_config)		+\
> >>>>> +	sizeof(struct rkisp1_ext_params_hst_config)			+\
> >>>>> +	sizeof(struct rkisp1_ext_params_aec_config)			+\
> >>>>> +	sizeof(struct rkisp1_ext_params_afc_config))
> >>>>> +
> >>>>> +/**
> >>>>> + * enum rksip1_ext_param_buffer_version - RkISP1 extensible parameters version
> >>>>> + *
> >>>>> + * @RKISP1_EXT_PARAM_BUFFER_V1: First version of RkISP1 extensible parameters
> >>>>> + */
> >>>>> +enum rksip1_ext_param_buffer_version {
> >>>>> +	RKISP1_EXT_PARAM_BUFFER_V1 = 1,
> >>>>
> >>>> I see no check against this in the rkisp1 code. Shouldn't this be checked?
> >>>> If the version is unsupported, then just return an error.
> >>>
> >>> Do we need this for the first version ? There are no other versions
> >>> userspace can use at the moment. I can add a check during validation
> >>> though.
> >>
> >> Yes: if a V2 is added in the future, and an application wants to use that
> >> against a driver that only support V1, then that should fail.
> >>
> >>>> Also, how does userspace know which version(s) is/are supported by the driver?
> >>>
> >>> Good question, there is no API for that atm. Defining a new format
> >>> version should only happen when a non-backward compatible change to
> >>> the format is made. I understand an application can be compiled
> >>> against a newer kernel header that provides a new format version but
> >>> then run on an older kernel where the new format is not supported.
> >>>
> >>> Probably userspace should be able to identify what versions are
> >>> supported by the driver it runs with and use the most appropriate one
> >>> by selecting it at runtime.
> >>>
> >>> What API would you use for that ? Is this something required for this
> >>> first version where a single format version is available ?
> >>
> >> You need this also for this first version for the reason explained above.
> >>
> >> Personally I would just make a read-only control that returns the highest
> >> supported version.
> > 
> > Can't userspace use the version number reported through the media device
> > to determine the features the driver support ? We've done that in
> > libcamera for some drivers already, either to work around bugs, or to
> > make use of new features.
> 
> You can, but this will fall down if the driver is backported to an older
> kernel for whatever reason. Since the version is just the kernel version,
> it will drop back to that older kernel version.

I recall discussing this issue in the past (I'm not sure it was with
you). If my memory doesn't fail me, there was a consensus that, when
backporting the whole V4L2 subsystem, the version number reported would
tbe the one corresponding to the more recent kernel, not the kernel the
code has been backported to.

That would help here, but will not solve the issue of how to deal with
backports of a single driver. Jacopo, what do you think ?

> Whether that is acceptable or not is up to you.
> 
> In any case, this would have to be documented so you know at which kernel
> version a new RKISP1_EXT_PARAM_BUFFER_Vx is introduced.
> 
> >>>>> +};
> >>>>> +
> >>>>> +/**
> >>>>> + * struct rkisp1_ext_params_cfg - RkISP1 extensible parameters configuration
> >>>>> + *
> >>>>> + * This struct contains the configuration parameters of the RkISP1 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:`rkisp1_ext_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.
> >>>>> + *
> >>>>> + * 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
> >>>>> + * 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 @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 -------------------+
> >>>>> + *	| version = RKISP_EXT_PARAMS_BUFFER_V1;                               |
> >>>>> + *	| data_size = sizeof(struct rkisp1_ext_params_bls_config)             |
> >>>>> + *	|           + sizeof(struct rkisp1_ext_params_dpcc_config);           |
> >>>>> + *	| +------------------------- data  ---------------------------------+ |
> >>>>> + *	| | +------------- struct rkisp1_ext_params_bls_config -----------+ | |
> >>>>> + *	| | | +-------- struct rkisp1_ext_params_block_header  ---------+ | | |
> >>>>> + *	| | | | type = RKISP1_EXT_PARAMS_BLOCK_TYPE_BLS;                | | | |
> >>>>> + *	| | | | flags = RKISP1_EXT_PARAMS_FL_BLOCK_ENABLE;              | | | |
> >>>>> + *	| | | | size = sizeof(struct rkisp1_ext_params_bls_config);     | | | |
> >>>>> + *	| | | +---------------------------------------------------------+ | | |
> >>>>> + *	| | | +---------- struct rkisp1_cif_isp_bls_config -------------+ | | |
> >>>>> + *	| | | | enable_auto = 0;                                        | | | |
> >>>>> + *	| | | | fixed_val.r = 256;                                      | | | |
> >>>>> + *	| | | | fixed_val.gr = 256;                                     | | | |
> >>>>> + *	| | | | fixed_val.gb = 256;                                     | | | |
> >>>>> + *	| | | | fixed_val.b = 256;                                      | | | |
> >>>>> + *	| | | +---------------------------------------------------------+ | | |
> >>>>> + *	| | +------------ struct rkisp1_ext_params_dpcc_config -----------+ | |
> >>>>> + *	| | | +-------- struct rkisp1_ext_params_block_header  ---------+ | | |
> >>>>> + *	| | | | type = RKISP1_EXT_PARAMS_BLOCK_TYPE_DPCC;               | | | |
> >>>>> + *	| | | | flags = RKISP1_EXT_PARAMS_FL_BLOCK_ENABLE;              | | | |
> >>>>> + *	| | | | size = sizeof(struct rkisp1_ext_params_dpcc_config);    | | | |
> >>>>> + *	| | | +---------------------------------------------------------+ | | |
> >>>>> + *	| | | +---------- struct rkisp1_cif_isp_dpcc_config ------------+ | | |
> >>>>> + *	| | | | mode = RKISP1_CIF_ISP_DPCC_MODE_STAGE1_ENABLE;          | | | |
> >>>>> + *	| | | | output_mode =                                           | | | |
> >>>>> + *	| | | |   RKISP1_CIF_ISP_DPCC_OUTPUT_MODE_STAGE1_INCL_G_CENTER; | | | |
> >>>>> + *	| | | | set_use = ... ;                                         | | | |
> >>>>> + *	| | | | ...  = ... ;                                            | | | |
> >>>>> + *	| | | +---------------------------------------------------------+ | | |
> >>>>> + *	| | +-------------------------------------------------------------+ | |
> >>>>> + *	| +-----------------------------------------------------------------+ |
> >>>>> + *	+---------------------------------------------------------------------+
> >>>>> + *
> >>>>> + * @version: The RkISP1 extensible parameters buffer version, see
> >>>>> + *	     :c:type:`rksip1_ext_param_buffer_version`
> >>>>> + * @data_size: The RkISP1 configuration data effective size, excluding this
> >>>>> + *	       header
> >>>>> + * @data: The RkISP1 extensible configuration data blocks
> >>>>> + */
> >>>>> +struct rkisp1_ext_params_cfg {
> >>>>> +	__u32 version;
> >>>>> +	__u32 data_size;
> >>>>> +	__u8 data[RKISP1_EXT_PARAMS_MAX_SIZE];
> >>>>> +};
> >>>>> +
> >>>>>  #endif /* _UAPI_RKISP1_CONFIG_H */
> > 
>
Laurent Pinchart Aug. 8, 2024, 10:52 a.m. UTC | #7
On Thu, Aug 08, 2024 at 01:51:25PM +0300, Laurent Pinchart wrote:
> On Thu, Aug 08, 2024 at 12:03:01PM +0200, Hans Verkuil wrote:
> > On 08/08/2024 11:54, Laurent Pinchart wrote:
> > > On Thu, Aug 08, 2024 at 09:41:42AM +0200, Hans Verkuil wrote:
> > >> On 08/08/2024 09:24, Jacopo Mondi wrote:
> > >>> On Thu, Aug 08, 2024 at 08:31:58AM GMT, Hans Verkuil wrote:
> > >>>> On 07/08/2024 23:22, Jacopo Mondi wrote:
> > >>>>> Add to the rkisp1-config.h header data types and documentation of
> > >>>>> the extensible parameters format.
> > >>>>>
> > >>>>> Signed-off-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
> > >>>>> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> > >>>>> Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>
> > >>>>> Tested-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
> > >>>>> Acked-by: Sakari Ailus <sakari.ailus@linux.intel.com>
> > >>>>> ---
> > >>>>>  include/uapi/linux/rkisp1-config.h | 485 +++++++++++++++++++++++++++++
> > >>>>>  1 file changed, 485 insertions(+)
> > >>>>>
> > >>>>> diff --git a/include/uapi/linux/rkisp1-config.h b/include/uapi/linux/rkisp1-config.h
> > >>>>> index 6eeaf8bf2362..14a23fd9a745 100644
> > >>>>> --- a/include/uapi/linux/rkisp1-config.h
> > >>>>> +++ b/include/uapi/linux/rkisp1-config.h
> > >>>>> @@ -996,4 +996,489 @@ struct rkisp1_stat_buffer {
> > >>>>>  	struct rkisp1_cif_isp_stat params;
> > >>>>>  };
> > >>>>>
> > >>>>> +/*---------- PART3: Extensible Configuration Parameters  ------------*/
> > >>>>> +
> > >>>>> +/**
> > >>>>> + * enum rkisp1_ext_params_block_type - RkISP1 extensible params block type
> > >>>>> + *
> > >>>>> + * @RKISP1_EXT_PARAMS_BLOCK_TYPE_BLS: Black level subtraction
> > >>>>> + * @RKISP1_EXT_PARAMS_BLOCK_TYPE_DPCC: Defect pixel cluster correction
> > >>>>> + * @RKISP1_EXT_PARAMS_BLOCK_TYPE_SDG: Sensor de-gamma
> > >>>>> + * @RKISP1_EXT_PARAMS_BLOCK_TYPE_AWB_GAIN: Auto white balance gains
> > >>>>> + * @RKISP1_EXT_PARAMS_BLOCK_TYPE_FLT: ISP filtering
> > >>>>> + * @RKISP1_EXT_PARAMS_BLOCK_TYPE_BDM: Bayer de-mosaic
> > >>>>> + * @RKISP1_EXT_PARAMS_BLOCK_TYPE_CTK: Cross-talk correction
> > >>>>> + * @RKISP1_EXT_PARAMS_BLOCK_TYPE_GOC: Gamma out correction
> > >>>>> + * @RKISP1_EXT_PARAMS_BLOCK_TYPE_DPF: De-noise pre-filter
> > >>>>> + * @RKISP1_EXT_PARAMS_BLOCK_TYPE_DPF_STRENGTH: De-noise pre-filter strength
> > >>>>> + * @RKISP1_EXT_PARAMS_BLOCK_TYPE_CPROC: Color processing
> > >>>>> + * @RKISP1_EXT_PARAMS_BLOCK_TYPE_IE: Image effects
> > >>>>> + * @RKISP1_EXT_PARAMS_BLOCK_TYPE_LSC: Lens shading correction
> > >>>>> + * @RKISP1_EXT_PARAMS_BLOCK_TYPE_AWB_MEAS: Auto white balance statistics
> > >>>>> + * @RKISP1_EXT_PARAMS_BLOCK_TYPE_HST_MEAS: Histogram statistics
> > >>>>> + * @RKISP1_EXT_PARAMS_BLOCK_TYPE_AEC_MEAS: Auto exposure statistics
> > >>>>> + * @RKISP1_EXT_PARAMS_BLOCK_TYPE_AFC_MEAS: Auto-focus statistics
> > >>>>> + */
> > >>>>> +enum rkisp1_ext_params_block_type {
> > >>>>> +	RKISP1_EXT_PARAMS_BLOCK_TYPE_BLS,
> > >>>>> +	RKISP1_EXT_PARAMS_BLOCK_TYPE_DPCC,
> > >>>>> +	RKISP1_EXT_PARAMS_BLOCK_TYPE_SDG,
> > >>>>> +	RKISP1_EXT_PARAMS_BLOCK_TYPE_AWB_GAIN,
> > >>>>> +	RKISP1_EXT_PARAMS_BLOCK_TYPE_FLT,
> > >>>>> +	RKISP1_EXT_PARAMS_BLOCK_TYPE_BDM,
> > >>>>> +	RKISP1_EXT_PARAMS_BLOCK_TYPE_CTK,
> > >>>>> +	RKISP1_EXT_PARAMS_BLOCK_TYPE_GOC,
> > >>>>> +	RKISP1_EXT_PARAMS_BLOCK_TYPE_DPF,
> > >>>>> +	RKISP1_EXT_PARAMS_BLOCK_TYPE_DPF_STRENGTH,
> > >>>>> +	RKISP1_EXT_PARAMS_BLOCK_TYPE_CPROC,
> > >>>>> +	RKISP1_EXT_PARAMS_BLOCK_TYPE_IE,
> > >>>>> +	RKISP1_EXT_PARAMS_BLOCK_TYPE_LSC,
> > >>>>> +	RKISP1_EXT_PARAMS_BLOCK_TYPE_AWB_MEAS,
> > >>>>> +	RKISP1_EXT_PARAMS_BLOCK_TYPE_HST_MEAS,
> > >>>>> +	RKISP1_EXT_PARAMS_BLOCK_TYPE_AEC_MEAS,
> > >>>>> +	RKISP1_EXT_PARAMS_BLOCK_TYPE_AFC_MEAS,
> > >>>>> +};
> > >>>>> +
> > >>>>> +#define RKISP1_EXT_PARAMS_FL_BLOCK_DISABLE	(1U << 0)
> > >>>>> +#define RKISP1_EXT_PARAMS_FL_BLOCK_ENABLE	(1U << 1)
> > >>>>> +
> > >>>>> +/**
> > >>>>> + * struct rkisp1_ext_params_block_header - RkISP1 extensible parameters 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 size and
> > >>>>> + * properly handle the block content by casting it to the correct block-specific
> > >>>>> + * type.
> > >>>>> + *
> > >>>>> + * The @type field is one of the values enumerated by
> > >>>>> + * :c:type:`rkisp1_ext_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 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. The
> > >>>>> + * driver ignores the rest of the block configuration structure in this case.
> > >>>>> + *
> > >>>>> + * 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_DISABLE 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 allowed
> > >>>>> + * 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:
> > >>>>> + *
> > >>>>> + * .. code-block:: c
> > >>>>> + *
> > >>>>> + *	void populate_bls(struct rkisp1_ext_params_block_header *block) {
> > >>>>> + *		struct rkisp1_ext_params_bls_config *bls =
> > >>>>> + *			(struct rkisp1_ext_params_bls_config *)block;
> > >>>>> + *
> > >>>>> + *		bls->header.type = RKISP1_EXT_PARAMS_BLOCK_ID_BLS;
> > >>>>> + *		bls->header.flags = RKISP1_EXT_PARAMS_FL_BLOCK_ENABLE;
> > >>>>> + *		bls->header.size = sizeof(*bls);
> > >>>>> + *
> > >>>>> + *		bls->config.enable_auto = 0;
> > >>>>> + *		bls->config.fixed_val.r = blackLevelRed_;
> > >>>>> + *		bls->config.fixed_val.gr = blackLevelGreenR_;
> > >>>>> + *		bls->config.fixed_val.gb = blackLevelGreenB_;
> > >>>>> + *		bls->config.fixed_val.b = 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
> > >>>>> + */
> > >>>>> +struct rkisp1_ext_params_block_header {
> > >>>>> +	__u16 type;
> > >>>>> +	__u16 flags;
> > >>>>> +	__u32 size;
> > >>>>> +};
> > >>>>> +
> > >>>>> +/**
> > >>>>> + * struct rkisp1_ext_params_bls_config - RkISP1 extensible params BLS config
> > >>>>> + *
> > >>>>> + * RkISP1 extensible parameters Black Level Subtraction configuration block.
> > >>>>> + * Identified by :c:type:`RKISP1_EXT_PARAMS_BLOCK_TYPE_BLS`.
> > >>>>> + *
> > >>>>> + * @header: The RkISP1 extensible parameters header, see
> > >>>>> + *	    :c:type:`rkisp1_ext_params_block_header`
> > >>>>> + * @config: Black Level Subtraction configuration, see
> > >>>>> + *	    :c:type:`rkisp1_cif_isp_bls_config`
> > >>>>> + */
> > >>>>> +struct rkisp1_ext_params_bls_config {
> > >>>>> +	struct rkisp1_ext_params_block_header header;
> > >>>>> +	struct rkisp1_cif_isp_bls_config config;
> > >>>>> +} __attribute__((aligned(8)));
> > >>>>> +
> > >>>>> +/**
> > >>>>> + * struct rkisp1_ext_params_dpcc_config - RkISP1 extensible params DPCC config
> > >>>>> + *
> > >>>>> + * RkISP1 extensible parameters Defective Pixel Cluster Correction configuration
> > >>>>> + * block. Identified by :c:type:`RKISP1_EXT_PARAMS_BLOCK_TYPE_DPCC`.
> > >>>>> + *
> > >>>>> + * @header: The RkISP1 extensible parameters header, see
> > >>>>> + *	    :c:type:`rkisp1_ext_params_block_header`
> > >>>>> + * @config: Defective Pixel Cluster Correction configuration, see
> > >>>>> + *	    :c:type:`rkisp1_cif_isp_dpcc_config`
> > >>>>> + */
> > >>>>> +struct rkisp1_ext_params_dpcc_config {
> > >>>>> +	struct rkisp1_ext_params_block_header header;
> > >>>>> +	struct rkisp1_cif_isp_dpcc_config config;
> > >>>>> +} __attribute__((aligned(8)));
> > >>>>> +
> > >>>>> +/**
> > >>>>> + * struct rkisp1_ext_params_sdg_config - RkISP1 extensible params SDG config
> > >>>>> + *
> > >>>>> + * RkISP1 extensible parameters Sensor Degamma configuration block. Identified
> > >>>>> + * by :c:type:`RKISP1_EXT_PARAMS_BLOCK_TYPE_SDG`.
> > >>>>> + *
> > >>>>> + * @header: The RkISP1 extensible parameters header, see
> > >>>>> + *	    :c:type:`rkisp1_ext_params_block_header`
> > >>>>> + * @config: Sensor Degamma configuration, see
> > >>>>> + *	    :c:type:`rkisp1_cif_isp_sdg_config`
> > >>>>> + */
> > >>>>> +struct rkisp1_ext_params_sdg_config {
> > >>>>> +	struct rkisp1_ext_params_block_header header;
> > >>>>> +	struct rkisp1_cif_isp_sdg_config config;
> > >>>>> +} __attribute__((aligned(8)));
> > >>>>> +
> > >>>>> +/**
> > >>>>> + * struct rkisp1_ext_params_lsc_config - RkISP1 extensible params LSC config
> > >>>>> + *
> > >>>>> + * RkISP1 extensible parameters Lens Shading Correction configuration block.
> > >>>>> + * Identified by :c:type:`RKISP1_EXT_PARAMS_BLOCK_TYPE_LSC`.
> > >>>>> + *
> > >>>>> + * @header: The RkISP1 extensible parameters header, see
> > >>>>> + *	    :c:type:`rkisp1_ext_params_block_header`
> > >>>>> + * @config: Lens Shading Correction configuration, see
> > >>>>> + *	    :c:type:`rkisp1_cif_isp_lsc_config`
> > >>>>> + */
> > >>>>> +struct rkisp1_ext_params_lsc_config {
> > >>>>> +	struct rkisp1_ext_params_block_header header;
> > >>>>> +	struct rkisp1_cif_isp_lsc_config config;
> > >>>>> +} __attribute__((aligned(8)));
> > >>>>> +
> > >>>>> +/**
> > >>>>> + * struct rkisp1_ext_params_awb_gain_config - RkISP1 extensible params AWB
> > >>>>> + *					      gain config
> > >>>>> + *
> > >>>>> + * RkISP1 extensible parameters Auto-White Balance Gains configuration block.
> > >>>>> + * Identified by :c:type:`RKISP1_EXT_PARAMS_BLOCK_TYPE_AWB_GAIN`.
> > >>>>> + *
> > >>>>> + * @header: The RkISP1 extensible parameters header, see
> > >>>>> + *	    :c:type:`rkisp1_ext_params_block_header`
> > >>>>> + * @config: Auto-White Balance Gains configuration, see
> > >>>>> + *	    :c:type:`rkisp1_cif_isp_awb_gain_config`
> > >>>>> + */
> > >>>>> +struct rkisp1_ext_params_awb_gain_config {
> > >>>>> +	struct rkisp1_ext_params_block_header header;
> > >>>>> +	struct rkisp1_cif_isp_awb_gain_config config;
> > >>>>> +} __attribute__((aligned(8)));
> > >>>>> +
> > >>>>> +/**
> > >>>>> + * struct rkisp1_ext_params_flt_config - RkISP1 extensible params FLT config
> > >>>>> + *
> > >>>>> + * RkISP1 extensible parameters Filter configuration block. Identified by
> > >>>>> + * :c:type:`RKISP1_EXT_PARAMS_BLOCK_TYPE_FLT`.
> > >>>>> + *
> > >>>>> + * @header: The RkISP1 extensible parameters header, see
> > >>>>> + *	    :c:type:`rkisp1_ext_params_block_header`
> > >>>>> + * @config: Filter configuration, see :c:type:`rkisp1_cif_isp_flt_config`
> > >>>>> + */
> > >>>>> +struct rkisp1_ext_params_flt_config {
> > >>>>> +	struct rkisp1_ext_params_block_header header;
> > >>>>> +	struct rkisp1_cif_isp_flt_config config;
> > >>>>> +} __attribute__((aligned(8)));
> > >>>>> +
> > >>>>> +/**
> > >>>>> + * struct rkisp1_ext_params_bdm_config - RkISP1 extensible params BDM config
> > >>>>> + *
> > >>>>> + * RkISP1 extensible parameters Demosaicing configuration block. Identified by
> > >>>>> + * :c:type:`RKISP1_EXT_PARAMS_BLOCK_TYPE_BDM`.
> > >>>>> + *
> > >>>>> + * @header: The RkISP1 extensible parameters header, see
> > >>>>> + *	    :c:type:`rkisp1_ext_params_block_header`
> > >>>>> + * @config: Demosaicing configuration, see :c:type:`rkisp1_cif_isp_bdm_config`
> > >>>>> + */
> > >>>>> +struct rkisp1_ext_params_bdm_config {
> > >>>>> +	struct rkisp1_ext_params_block_header header;
> > >>>>> +	struct rkisp1_cif_isp_bdm_config config;
> > >>>>> +} __attribute__((aligned(8)));
> > >>>>> +
> > >>>>> +/**
> > >>>>> + * struct rkisp1_ext_params_ctk_config - RkISP1 extensible params CTK config
> > >>>>> + *
> > >>>>> + * RkISP1 extensible parameters Cross-Talk configuration block. Identified by
> > >>>>> + * :c:type:`RKISP1_EXT_PARAMS_BLOCK_TYPE_CTK`.
> > >>>>> + *
> > >>>>> + * @header: The RkISP1 extensible parameters header, see
> > >>>>> + *	    :c:type:`rkisp1_ext_params_block_header`
> > >>>>> + * @config: Cross-Talk configuration, see :c:type:`rkisp1_cif_isp_ctk_config`
> > >>>>> + */
> > >>>>> +struct rkisp1_ext_params_ctk_config {
> > >>>>> +	struct rkisp1_ext_params_block_header header;
> > >>>>> +	struct rkisp1_cif_isp_ctk_config config;
> > >>>>> +} __attribute__((aligned(8)));
> > >>>>> +
> > >>>>> +/**
> > >>>>> + * struct rkisp1_ext_params_goc_config - RkISP1 extensible params GOC config
> > >>>>> + *
> > >>>>> + * RkISP1 extensible parameters Gamma-Out configuration block. Identified by
> > >>>>> + * :c:type:`RKISP1_EXT_PARAMS_BLOCK_TYPE_GOC`.
> > >>>>> + *
> > >>>>> + * @header: The RkISP1 extensible parameters header, see
> > >>>>> + *	    :c:type:`rkisp1_ext_params_block_header`
> > >>>>> + * @config: Gamma-Out configuration, see :c:type:`rkisp1_cif_isp_goc_config`
> > >>>>> + */
> > >>>>> +struct rkisp1_ext_params_goc_config {
> > >>>>> +	struct rkisp1_ext_params_block_header header;
> > >>>>> +	struct rkisp1_cif_isp_goc_config config;
> > >>>>> +} __attribute__((aligned(8)));
> > >>>>> +
> > >>>>> +/**
> > >>>>> + * struct rkisp1_ext_params_dpf_config - RkISP1 extensible params DPF config
> > >>>>> + *
> > >>>>> + * RkISP1 extensible parameters De-noise Pre-Filter configuration block.
> > >>>>> + * Identified by :c:type:`RKISP1_EXT_PARAMS_BLOCK_TYPE_DPF`.
> > >>>>> + *
> > >>>>> + * @header: The RkISP1 extensible parameters header, see
> > >>>>> + *	    :c:type:`rkisp1_ext_params_block_header`
> > >>>>> + * @config: De-noise Pre-Filter configuration, see
> > >>>>> + *	    :c:type:`rkisp1_cif_isp_dpf_config`
> > >>>>> + */
> > >>>>> +struct rkisp1_ext_params_dpf_config {
> > >>>>> +	struct rkisp1_ext_params_block_header header;
> > >>>>> +	struct rkisp1_cif_isp_dpf_config config;
> > >>>>> +} __attribute__((aligned(8)));
> > >>>>> +
> > >>>>> +/**
> > >>>>> + * struct rkisp1_ext_params_dpf_strength_config - RkISP1 extensible params DPF
> > >>>>> + *						  strength config
> > >>>>> + *
> > >>>>> + * RkISP1 extensible parameters De-noise Pre-Filter strength configuration
> > >>>>> + * block. Identified by :c:type:`RKISP1_EXT_PARAMS_BLOCK_TYPE_DPF_STRENGTH`.
> > >>>>> + *
> > >>>>> + * @header: The RkISP1 extensible parameters header, see
> > >>>>> + *	    :c:type:`rkisp1_ext_params_block_header`
> > >>>>> + * @config: De-noise Pre-Filter strength configuration, see
> > >>>>> + *	    :c:type:`rkisp1_cif_isp_dpf_strength_config`
> > >>>>> + */
> > >>>>> +struct rkisp1_ext_params_dpf_strength_config {
> > >>>>> +	struct rkisp1_ext_params_block_header header;
> > >>>>> +	struct rkisp1_cif_isp_dpf_strength_config config;
> > >>>>> +} __attribute__((aligned(8)));
> > >>>>> +
> > >>>>> +/**
> > >>>>> + * struct rkisp1_ext_params_cproc_config - RkISP1 extensible params CPROC config
> > >>>>> + *
> > >>>>> + * RkISP1 extensible parameters Color Processing configuration block.
> > >>>>> + * Identified by :c:type:`RKISP1_EXT_PARAMS_BLOCK_TYPE_CPROC`.
> > >>>>> + *
> > >>>>> + * @header: The RkISP1 extensible parameters header, see
> > >>>>> + *	    :c:type:`rkisp1_ext_params_block_header`
> > >>>>> + * @config: Color processing configuration, see
> > >>>>> + *	    :c:type:`rkisp1_cif_isp_cproc_config`
> > >>>>> + */
> > >>>>> +struct rkisp1_ext_params_cproc_config {
> > >>>>> +	struct rkisp1_ext_params_block_header header;
> > >>>>> +	struct rkisp1_cif_isp_cproc_config config;
> > >>>>> +} __attribute__((aligned(8)));
> > >>>>> +
> > >>>>> +/**
> > >>>>> + * struct rkisp1_ext_params_ie_config - RkISP1 extensible params IE config
> > >>>>> + *
> > >>>>> + * RkISP1 extensible parameters Image Effect configuration block. Identified by
> > >>>>> + * :c:type:`RKISP1_EXT_PARAMS_BLOCK_TYPE_IE`.
> > >>>>> + *
> > >>>>> + * @header: The RkISP1 extensible parameters header, see
> > >>>>> + *	    :c:type:`rkisp1_ext_params_block_header`
> > >>>>> + * @config: Image Effect configuration, see :c:type:`rkisp1_cif_isp_ie_config`
> > >>>>> + */
> > >>>>> +struct rkisp1_ext_params_ie_config {
> > >>>>> +	struct rkisp1_ext_params_block_header header;
> > >>>>> +	struct rkisp1_cif_isp_ie_config config;
> > >>>>> +} __attribute__((aligned(8)));
> > >>>>> +
> > >>>>> +/**
> > >>>>> + * struct rkisp1_ext_params_awb_meas_config - RkISP1 extensible params AWB
> > >>>>> + *					      Meas config
> > >>>>> + *
> > >>>>> + * RkISP1 extensible parameters Auto-White Balance Measurement configuration
> > >>>>> + * block. Identified by :c:type:`RKISP1_EXT_PARAMS_BLOCK_TYPE_AWB_MEAS`.
> > >>>>> + *
> > >>>>> + * @header: The RkISP1 extensible parameters header, see
> > >>>>> + *	    :c:type:`rkisp1_ext_params_block_header`
> > >>>>> + * @config: Auto-White Balance measure configuration, see
> > >>>>> + *	    :c:type:`rkisp1_cif_isp_awb_meas_config`
> > >>>>> + */
> > >>>>> +struct rkisp1_ext_params_awb_meas_config {
> > >>>>> +	struct rkisp1_ext_params_block_header header;
> > >>>>> +	struct rkisp1_cif_isp_awb_meas_config config;
> > >>>>> +} __attribute__((aligned(8)));
> > >>>>> +
> > >>>>> +/**
> > >>>>> + * struct rkisp1_ext_params_hst_config - RkISP1 extensible params Histogram config
> > >>>>> + *
> > >>>>> + * RkISP1 extensible parameters Histogram statistics configuration block.
> > >>>>> + * Identified by :c:type:`RKISP1_EXT_PARAMS_BLOCK_TYPE_HST_MEAS`.
> > >>>>> + *
> > >>>>> + * @header: The RkISP1 extensible parameters header, see
> > >>>>> + *	    :c:type:`rkisp1_ext_params_block_header`
> > >>>>> + * @config: Histogram statistics configuration, see
> > >>>>> + *	    :c:type:`rkisp1_cif_isp_hst_config`
> > >>>>> + */
> > >>>>> +struct rkisp1_ext_params_hst_config {
> > >>>>> +	struct rkisp1_ext_params_block_header header;
> > >>>>> +	struct rkisp1_cif_isp_hst_config config;
> > >>>>> +} __attribute__((aligned(8)));
> > >>>>> +
> > >>>>> +/**
> > >>>>> + * struct rkisp1_ext_params_aec_config - RkISP1 extensible params AEC config
> > >>>>> + *
> > >>>>> + * RkISP1 extensible parameters Auto-Exposure statistics configuration block.
> > >>>>> + * Identified by :c:type:`RKISP1_EXT_PARAMS_BLOCK_TYPE_AEC_MEAS`.
> > >>>>> + *
> > >>>>> + * @header: The RkISP1 extensible parameters header, see
> > >>>>> + *	    :c:type:`rkisp1_ext_params_block_header`
> > >>>>> + * @config: Auto-Exposure statistics configuration, see
> > >>>>> + *	    :c:type:`rkisp1_cif_isp_aec_config`
> > >>>>> + */
> > >>>>> +struct rkisp1_ext_params_aec_config {
> > >>>>> +	struct rkisp1_ext_params_block_header header;
> > >>>>> +	struct rkisp1_cif_isp_aec_config config;
> > >>>>> +} __attribute__((aligned(8)));
> > >>>>> +
> > >>>>> +/**
> > >>>>> + * struct rkisp1_ext_params_afc_config - RkISP1 extensible params AFC config
> > >>>>> + *
> > >>>>> + * RkISP1 extensible parameters Auto-Focus statistics configuration block.
> > >>>>> + * Identified by :c:type:`RKISP1_EXT_PARAMS_BLOCK_TYPE_AFC_MEAS`.
> > >>>>> + *
> > >>>>> + * @header: The RkISP1 extensible parameters header, see
> > >>>>> + *	    :c:type:`rkisp1_ext_params_block_header`
> > >>>>> + * @config: Auto-Focus statistics configuration, see
> > >>>>> + *	    :c:type:`rkisp1_cif_isp_afc_config`
> > >>>>> + */
> > >>>>> +struct rkisp1_ext_params_afc_config {
> > >>>>> +	struct rkisp1_ext_params_block_header header;
> > >>>>> +	struct rkisp1_cif_isp_afc_config config;
> > >>>>> +} __attribute__((aligned(8)));
> > >>>>> +
> > >>>>> +#define RKISP1_EXT_PARAMS_MAX_SIZE					\
> > >>>>> +	(sizeof(struct rkisp1_ext_params_bls_config)			+\
> > >>>>> +	sizeof(struct rkisp1_ext_params_dpcc_config)			+\
> > >>>>> +	sizeof(struct rkisp1_ext_params_sdg_config)			+\
> > >>>>> +	sizeof(struct rkisp1_ext_params_lsc_config)			+\
> > >>>>> +	sizeof(struct rkisp1_ext_params_awb_gain_config)		+\
> > >>>>> +	sizeof(struct rkisp1_ext_params_flt_config)			+\
> > >>>>> +	sizeof(struct rkisp1_ext_params_bdm_config)			+\
> > >>>>> +	sizeof(struct rkisp1_ext_params_ctk_config)			+\
> > >>>>> +	sizeof(struct rkisp1_ext_params_goc_config)			+\
> > >>>>> +	sizeof(struct rkisp1_ext_params_dpf_config)			+\
> > >>>>> +	sizeof(struct rkisp1_ext_params_dpf_strength_config)		+\
> > >>>>> +	sizeof(struct rkisp1_ext_params_cproc_config)			+\
> > >>>>> +	sizeof(struct rkisp1_ext_params_ie_config)			+\
> > >>>>> +	sizeof(struct rkisp1_ext_params_awb_meas_config)		+\
> > >>>>> +	sizeof(struct rkisp1_ext_params_hst_config)			+\
> > >>>>> +	sizeof(struct rkisp1_ext_params_aec_config)			+\
> > >>>>> +	sizeof(struct rkisp1_ext_params_afc_config))
> > >>>>> +
> > >>>>> +/**
> > >>>>> + * enum rksip1_ext_param_buffer_version - RkISP1 extensible parameters version
> > >>>>> + *
> > >>>>> + * @RKISP1_EXT_PARAM_BUFFER_V1: First version of RkISP1 extensible parameters
> > >>>>> + */
> > >>>>> +enum rksip1_ext_param_buffer_version {
> > >>>>> +	RKISP1_EXT_PARAM_BUFFER_V1 = 1,
> > >>>>
> > >>>> I see no check against this in the rkisp1 code. Shouldn't this be checked?
> > >>>> If the version is unsupported, then just return an error.
> > >>>
> > >>> Do we need this for the first version ? There are no other versions
> > >>> userspace can use at the moment. I can add a check during validation
> > >>> though.
> > >>
> > >> Yes: if a V2 is added in the future, and an application wants to use that
> > >> against a driver that only support V1, then that should fail.
> > >>
> > >>>> Also, how does userspace know which version(s) is/are supported by the driver?
> > >>>
> > >>> Good question, there is no API for that atm. Defining a new format
> > >>> version should only happen when a non-backward compatible change to
> > >>> the format is made. I understand an application can be compiled
> > >>> against a newer kernel header that provides a new format version but
> > >>> then run on an older kernel where the new format is not supported.
> > >>>
> > >>> Probably userspace should be able to identify what versions are
> > >>> supported by the driver it runs with and use the most appropriate one
> > >>> by selecting it at runtime.
> > >>>
> > >>> What API would you use for that ? Is this something required for this
> > >>> first version where a single format version is available ?
> > >>
> > >> You need this also for this first version for the reason explained above.
> > >>
> > >> Personally I would just make a read-only control that returns the highest
> > >> supported version.
> > > 
> > > Can't userspace use the version number reported through the media device
> > > to determine the features the driver support ? We've done that in
> > > libcamera for some drivers already, either to work around bugs, or to
> > > make use of new features.
> > 
> > You can, but this will fall down if the driver is backported to an older
> > kernel for whatever reason. Since the version is just the kernel version,
> > it will drop back to that older kernel version.
> 
> I recall discussing this issue in the past (I'm not sure it was with
> you). If my memory doesn't fail me, there was a consensus that, when
> backporting the whole V4L2 subsystem, the version number reported would
> tbe the one corresponding to the more recent kernel, not the kernel the
> code has been backported to.
> 
> That would help here, but will not solve the issue of how to deal with
> backports of a single driver. Jacopo, what do you think ?
> 
> > Whether that is acceptable or not is up to you.
> > 
> > In any case, this would have to be documented so you know at which kernel
> > version a new RKISP1_EXT_PARAM_BUFFER_Vx is introduced.

If we decide to use a control to report the version, we could also defer
adding that control until a V2 is needed. The absence of the control
would indicate that only V1 is supported.

> > >>>>> +};
> > >>>>> +
> > >>>>> +/**
> > >>>>> + * struct rkisp1_ext_params_cfg - RkISP1 extensible parameters configuration
> > >>>>> + *
> > >>>>> + * This struct contains the configuration parameters of the RkISP1 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:`rkisp1_ext_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.
> > >>>>> + *
> > >>>>> + * 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
> > >>>>> + * 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 @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 -------------------+
> > >>>>> + *	| version = RKISP_EXT_PARAMS_BUFFER_V1;                               |
> > >>>>> + *	| data_size = sizeof(struct rkisp1_ext_params_bls_config)             |
> > >>>>> + *	|           + sizeof(struct rkisp1_ext_params_dpcc_config);           |
> > >>>>> + *	| +------------------------- data  ---------------------------------+ |
> > >>>>> + *	| | +------------- struct rkisp1_ext_params_bls_config -----------+ | |
> > >>>>> + *	| | | +-------- struct rkisp1_ext_params_block_header  ---------+ | | |
> > >>>>> + *	| | | | type = RKISP1_EXT_PARAMS_BLOCK_TYPE_BLS;                | | | |
> > >>>>> + *	| | | | flags = RKISP1_EXT_PARAMS_FL_BLOCK_ENABLE;              | | | |
> > >>>>> + *	| | | | size = sizeof(struct rkisp1_ext_params_bls_config);     | | | |
> > >>>>> + *	| | | +---------------------------------------------------------+ | | |
> > >>>>> + *	| | | +---------- struct rkisp1_cif_isp_bls_config -------------+ | | |
> > >>>>> + *	| | | | enable_auto = 0;                                        | | | |
> > >>>>> + *	| | | | fixed_val.r = 256;                                      | | | |
> > >>>>> + *	| | | | fixed_val.gr = 256;                                     | | | |
> > >>>>> + *	| | | | fixed_val.gb = 256;                                     | | | |
> > >>>>> + *	| | | | fixed_val.b = 256;                                      | | | |
> > >>>>> + *	| | | +---------------------------------------------------------+ | | |
> > >>>>> + *	| | +------------ struct rkisp1_ext_params_dpcc_config -----------+ | |
> > >>>>> + *	| | | +-------- struct rkisp1_ext_params_block_header  ---------+ | | |
> > >>>>> + *	| | | | type = RKISP1_EXT_PARAMS_BLOCK_TYPE_DPCC;               | | | |
> > >>>>> + *	| | | | flags = RKISP1_EXT_PARAMS_FL_BLOCK_ENABLE;              | | | |
> > >>>>> + *	| | | | size = sizeof(struct rkisp1_ext_params_dpcc_config);    | | | |
> > >>>>> + *	| | | +---------------------------------------------------------+ | | |
> > >>>>> + *	| | | +---------- struct rkisp1_cif_isp_dpcc_config ------------+ | | |
> > >>>>> + *	| | | | mode = RKISP1_CIF_ISP_DPCC_MODE_STAGE1_ENABLE;          | | | |
> > >>>>> + *	| | | | output_mode =                                           | | | |
> > >>>>> + *	| | | |   RKISP1_CIF_ISP_DPCC_OUTPUT_MODE_STAGE1_INCL_G_CENTER; | | | |
> > >>>>> + *	| | | | set_use = ... ;                                         | | | |
> > >>>>> + *	| | | | ...  = ... ;                                            | | | |
> > >>>>> + *	| | | +---------------------------------------------------------+ | | |
> > >>>>> + *	| | +-------------------------------------------------------------+ | |
> > >>>>> + *	| +-----------------------------------------------------------------+ |
> > >>>>> + *	+---------------------------------------------------------------------+
> > >>>>> + *
> > >>>>> + * @version: The RkISP1 extensible parameters buffer version, see
> > >>>>> + *	     :c:type:`rksip1_ext_param_buffer_version`
> > >>>>> + * @data_size: The RkISP1 configuration data effective size, excluding this
> > >>>>> + *	       header
> > >>>>> + * @data: The RkISP1 extensible configuration data blocks
> > >>>>> + */
> > >>>>> +struct rkisp1_ext_params_cfg {
> > >>>>> +	__u32 version;
> > >>>>> +	__u32 data_size;
> > >>>>> +	__u8 data[RKISP1_EXT_PARAMS_MAX_SIZE];
> > >>>>> +};
> > >>>>> +
> > >>>>>  #endif /* _UAPI_RKISP1_CONFIG_H */
> > > 
> > 
> 
> -- 
> Regards,
> 
> Laurent Pinchart
Hans Verkuil Aug. 8, 2024, 10:58 a.m. UTC | #8
On 08/08/2024 12:51, Laurent Pinchart wrote:
> On Thu, Aug 08, 2024 at 12:03:01PM +0200, Hans Verkuil wrote:
>> On 08/08/2024 11:54, Laurent Pinchart wrote:
>>> On Thu, Aug 08, 2024 at 09:41:42AM +0200, Hans Verkuil wrote:
>>>> On 08/08/2024 09:24, Jacopo Mondi wrote:
>>>>> On Thu, Aug 08, 2024 at 08:31:58AM GMT, Hans Verkuil wrote:
>>>>>> On 07/08/2024 23:22, Jacopo Mondi wrote:
>>>>>>> Add to the rkisp1-config.h header data types and documentation of
>>>>>>> the extensible parameters format.
>>>>>>>
>>>>>>> Signed-off-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
>>>>>>> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
>>>>>>> Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>
>>>>>>> Tested-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
>>>>>>> Acked-by: Sakari Ailus <sakari.ailus@linux.intel.com>
>>>>>>> ---
>>>>>>>  include/uapi/linux/rkisp1-config.h | 485 +++++++++++++++++++++++++++++
>>>>>>>  1 file changed, 485 insertions(+)
>>>>>>>
>>>>>>> diff --git a/include/uapi/linux/rkisp1-config.h b/include/uapi/linux/rkisp1-config.h
>>>>>>> index 6eeaf8bf2362..14a23fd9a745 100644
>>>>>>> --- a/include/uapi/linux/rkisp1-config.h
>>>>>>> +++ b/include/uapi/linux/rkisp1-config.h
>>>>>>> @@ -996,4 +996,489 @@ struct rkisp1_stat_buffer {
>>>>>>>  	struct rkisp1_cif_isp_stat params;
>>>>>>>  };
>>>>>>>
>>>>>>> +/*---------- PART3: Extensible Configuration Parameters  ------------*/
>>>>>>> +
>>>>>>> +/**
>>>>>>> + * enum rkisp1_ext_params_block_type - RkISP1 extensible params block type
>>>>>>> + *
>>>>>>> + * @RKISP1_EXT_PARAMS_BLOCK_TYPE_BLS: Black level subtraction
>>>>>>> + * @RKISP1_EXT_PARAMS_BLOCK_TYPE_DPCC: Defect pixel cluster correction
>>>>>>> + * @RKISP1_EXT_PARAMS_BLOCK_TYPE_SDG: Sensor de-gamma
>>>>>>> + * @RKISP1_EXT_PARAMS_BLOCK_TYPE_AWB_GAIN: Auto white balance gains
>>>>>>> + * @RKISP1_EXT_PARAMS_BLOCK_TYPE_FLT: ISP filtering
>>>>>>> + * @RKISP1_EXT_PARAMS_BLOCK_TYPE_BDM: Bayer de-mosaic
>>>>>>> + * @RKISP1_EXT_PARAMS_BLOCK_TYPE_CTK: Cross-talk correction
>>>>>>> + * @RKISP1_EXT_PARAMS_BLOCK_TYPE_GOC: Gamma out correction
>>>>>>> + * @RKISP1_EXT_PARAMS_BLOCK_TYPE_DPF: De-noise pre-filter
>>>>>>> + * @RKISP1_EXT_PARAMS_BLOCK_TYPE_DPF_STRENGTH: De-noise pre-filter strength
>>>>>>> + * @RKISP1_EXT_PARAMS_BLOCK_TYPE_CPROC: Color processing
>>>>>>> + * @RKISP1_EXT_PARAMS_BLOCK_TYPE_IE: Image effects
>>>>>>> + * @RKISP1_EXT_PARAMS_BLOCK_TYPE_LSC: Lens shading correction
>>>>>>> + * @RKISP1_EXT_PARAMS_BLOCK_TYPE_AWB_MEAS: Auto white balance statistics
>>>>>>> + * @RKISP1_EXT_PARAMS_BLOCK_TYPE_HST_MEAS: Histogram statistics
>>>>>>> + * @RKISP1_EXT_PARAMS_BLOCK_TYPE_AEC_MEAS: Auto exposure statistics
>>>>>>> + * @RKISP1_EXT_PARAMS_BLOCK_TYPE_AFC_MEAS: Auto-focus statistics
>>>>>>> + */
>>>>>>> +enum rkisp1_ext_params_block_type {
>>>>>>> +	RKISP1_EXT_PARAMS_BLOCK_TYPE_BLS,
>>>>>>> +	RKISP1_EXT_PARAMS_BLOCK_TYPE_DPCC,
>>>>>>> +	RKISP1_EXT_PARAMS_BLOCK_TYPE_SDG,
>>>>>>> +	RKISP1_EXT_PARAMS_BLOCK_TYPE_AWB_GAIN,
>>>>>>> +	RKISP1_EXT_PARAMS_BLOCK_TYPE_FLT,
>>>>>>> +	RKISP1_EXT_PARAMS_BLOCK_TYPE_BDM,
>>>>>>> +	RKISP1_EXT_PARAMS_BLOCK_TYPE_CTK,
>>>>>>> +	RKISP1_EXT_PARAMS_BLOCK_TYPE_GOC,
>>>>>>> +	RKISP1_EXT_PARAMS_BLOCK_TYPE_DPF,
>>>>>>> +	RKISP1_EXT_PARAMS_BLOCK_TYPE_DPF_STRENGTH,
>>>>>>> +	RKISP1_EXT_PARAMS_BLOCK_TYPE_CPROC,
>>>>>>> +	RKISP1_EXT_PARAMS_BLOCK_TYPE_IE,
>>>>>>> +	RKISP1_EXT_PARAMS_BLOCK_TYPE_LSC,
>>>>>>> +	RKISP1_EXT_PARAMS_BLOCK_TYPE_AWB_MEAS,
>>>>>>> +	RKISP1_EXT_PARAMS_BLOCK_TYPE_HST_MEAS,
>>>>>>> +	RKISP1_EXT_PARAMS_BLOCK_TYPE_AEC_MEAS,
>>>>>>> +	RKISP1_EXT_PARAMS_BLOCK_TYPE_AFC_MEAS,
>>>>>>> +};
>>>>>>> +
>>>>>>> +#define RKISP1_EXT_PARAMS_FL_BLOCK_DISABLE	(1U << 0)
>>>>>>> +#define RKISP1_EXT_PARAMS_FL_BLOCK_ENABLE	(1U << 1)
>>>>>>> +
>>>>>>> +/**
>>>>>>> + * struct rkisp1_ext_params_block_header - RkISP1 extensible parameters 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 size and
>>>>>>> + * properly handle the block content by casting it to the correct block-specific
>>>>>>> + * type.
>>>>>>> + *
>>>>>>> + * The @type field is one of the values enumerated by
>>>>>>> + * :c:type:`rkisp1_ext_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 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. The
>>>>>>> + * driver ignores the rest of the block configuration structure in this case.
>>>>>>> + *
>>>>>>> + * 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_DISABLE 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 allowed
>>>>>>> + * 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:
>>>>>>> + *
>>>>>>> + * .. code-block:: c
>>>>>>> + *
>>>>>>> + *	void populate_bls(struct rkisp1_ext_params_block_header *block) {
>>>>>>> + *		struct rkisp1_ext_params_bls_config *bls =
>>>>>>> + *			(struct rkisp1_ext_params_bls_config *)block;
>>>>>>> + *
>>>>>>> + *		bls->header.type = RKISP1_EXT_PARAMS_BLOCK_ID_BLS;
>>>>>>> + *		bls->header.flags = RKISP1_EXT_PARAMS_FL_BLOCK_ENABLE;
>>>>>>> + *		bls->header.size = sizeof(*bls);
>>>>>>> + *
>>>>>>> + *		bls->config.enable_auto = 0;
>>>>>>> + *		bls->config.fixed_val.r = blackLevelRed_;
>>>>>>> + *		bls->config.fixed_val.gr = blackLevelGreenR_;
>>>>>>> + *		bls->config.fixed_val.gb = blackLevelGreenB_;
>>>>>>> + *		bls->config.fixed_val.b = 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
>>>>>>> + */
>>>>>>> +struct rkisp1_ext_params_block_header {
>>>>>>> +	__u16 type;
>>>>>>> +	__u16 flags;
>>>>>>> +	__u32 size;
>>>>>>> +};
>>>>>>> +
>>>>>>> +/**
>>>>>>> + * struct rkisp1_ext_params_bls_config - RkISP1 extensible params BLS config
>>>>>>> + *
>>>>>>> + * RkISP1 extensible parameters Black Level Subtraction configuration block.
>>>>>>> + * Identified by :c:type:`RKISP1_EXT_PARAMS_BLOCK_TYPE_BLS`.
>>>>>>> + *
>>>>>>> + * @header: The RkISP1 extensible parameters header, see
>>>>>>> + *	    :c:type:`rkisp1_ext_params_block_header`
>>>>>>> + * @config: Black Level Subtraction configuration, see
>>>>>>> + *	    :c:type:`rkisp1_cif_isp_bls_config`
>>>>>>> + */
>>>>>>> +struct rkisp1_ext_params_bls_config {
>>>>>>> +	struct rkisp1_ext_params_block_header header;
>>>>>>> +	struct rkisp1_cif_isp_bls_config config;
>>>>>>> +} __attribute__((aligned(8)));
>>>>>>> +
>>>>>>> +/**
>>>>>>> + * struct rkisp1_ext_params_dpcc_config - RkISP1 extensible params DPCC config
>>>>>>> + *
>>>>>>> + * RkISP1 extensible parameters Defective Pixel Cluster Correction configuration
>>>>>>> + * block. Identified by :c:type:`RKISP1_EXT_PARAMS_BLOCK_TYPE_DPCC`.
>>>>>>> + *
>>>>>>> + * @header: The RkISP1 extensible parameters header, see
>>>>>>> + *	    :c:type:`rkisp1_ext_params_block_header`
>>>>>>> + * @config: Defective Pixel Cluster Correction configuration, see
>>>>>>> + *	    :c:type:`rkisp1_cif_isp_dpcc_config`
>>>>>>> + */
>>>>>>> +struct rkisp1_ext_params_dpcc_config {
>>>>>>> +	struct rkisp1_ext_params_block_header header;
>>>>>>> +	struct rkisp1_cif_isp_dpcc_config config;
>>>>>>> +} __attribute__((aligned(8)));
>>>>>>> +
>>>>>>> +/**
>>>>>>> + * struct rkisp1_ext_params_sdg_config - RkISP1 extensible params SDG config
>>>>>>> + *
>>>>>>> + * RkISP1 extensible parameters Sensor Degamma configuration block. Identified
>>>>>>> + * by :c:type:`RKISP1_EXT_PARAMS_BLOCK_TYPE_SDG`.
>>>>>>> + *
>>>>>>> + * @header: The RkISP1 extensible parameters header, see
>>>>>>> + *	    :c:type:`rkisp1_ext_params_block_header`
>>>>>>> + * @config: Sensor Degamma configuration, see
>>>>>>> + *	    :c:type:`rkisp1_cif_isp_sdg_config`
>>>>>>> + */
>>>>>>> +struct rkisp1_ext_params_sdg_config {
>>>>>>> +	struct rkisp1_ext_params_block_header header;
>>>>>>> +	struct rkisp1_cif_isp_sdg_config config;
>>>>>>> +} __attribute__((aligned(8)));
>>>>>>> +
>>>>>>> +/**
>>>>>>> + * struct rkisp1_ext_params_lsc_config - RkISP1 extensible params LSC config
>>>>>>> + *
>>>>>>> + * RkISP1 extensible parameters Lens Shading Correction configuration block.
>>>>>>> + * Identified by :c:type:`RKISP1_EXT_PARAMS_BLOCK_TYPE_LSC`.
>>>>>>> + *
>>>>>>> + * @header: The RkISP1 extensible parameters header, see
>>>>>>> + *	    :c:type:`rkisp1_ext_params_block_header`
>>>>>>> + * @config: Lens Shading Correction configuration, see
>>>>>>> + *	    :c:type:`rkisp1_cif_isp_lsc_config`
>>>>>>> + */
>>>>>>> +struct rkisp1_ext_params_lsc_config {
>>>>>>> +	struct rkisp1_ext_params_block_header header;
>>>>>>> +	struct rkisp1_cif_isp_lsc_config config;
>>>>>>> +} __attribute__((aligned(8)));
>>>>>>> +
>>>>>>> +/**
>>>>>>> + * struct rkisp1_ext_params_awb_gain_config - RkISP1 extensible params AWB
>>>>>>> + *					      gain config
>>>>>>> + *
>>>>>>> + * RkISP1 extensible parameters Auto-White Balance Gains configuration block.
>>>>>>> + * Identified by :c:type:`RKISP1_EXT_PARAMS_BLOCK_TYPE_AWB_GAIN`.
>>>>>>> + *
>>>>>>> + * @header: The RkISP1 extensible parameters header, see
>>>>>>> + *	    :c:type:`rkisp1_ext_params_block_header`
>>>>>>> + * @config: Auto-White Balance Gains configuration, see
>>>>>>> + *	    :c:type:`rkisp1_cif_isp_awb_gain_config`
>>>>>>> + */
>>>>>>> +struct rkisp1_ext_params_awb_gain_config {
>>>>>>> +	struct rkisp1_ext_params_block_header header;
>>>>>>> +	struct rkisp1_cif_isp_awb_gain_config config;
>>>>>>> +} __attribute__((aligned(8)));
>>>>>>> +
>>>>>>> +/**
>>>>>>> + * struct rkisp1_ext_params_flt_config - RkISP1 extensible params FLT config
>>>>>>> + *
>>>>>>> + * RkISP1 extensible parameters Filter configuration block. Identified by
>>>>>>> + * :c:type:`RKISP1_EXT_PARAMS_BLOCK_TYPE_FLT`.
>>>>>>> + *
>>>>>>> + * @header: The RkISP1 extensible parameters header, see
>>>>>>> + *	    :c:type:`rkisp1_ext_params_block_header`
>>>>>>> + * @config: Filter configuration, see :c:type:`rkisp1_cif_isp_flt_config`
>>>>>>> + */
>>>>>>> +struct rkisp1_ext_params_flt_config {
>>>>>>> +	struct rkisp1_ext_params_block_header header;
>>>>>>> +	struct rkisp1_cif_isp_flt_config config;
>>>>>>> +} __attribute__((aligned(8)));
>>>>>>> +
>>>>>>> +/**
>>>>>>> + * struct rkisp1_ext_params_bdm_config - RkISP1 extensible params BDM config
>>>>>>> + *
>>>>>>> + * RkISP1 extensible parameters Demosaicing configuration block. Identified by
>>>>>>> + * :c:type:`RKISP1_EXT_PARAMS_BLOCK_TYPE_BDM`.
>>>>>>> + *
>>>>>>> + * @header: The RkISP1 extensible parameters header, see
>>>>>>> + *	    :c:type:`rkisp1_ext_params_block_header`
>>>>>>> + * @config: Demosaicing configuration, see :c:type:`rkisp1_cif_isp_bdm_config`
>>>>>>> + */
>>>>>>> +struct rkisp1_ext_params_bdm_config {
>>>>>>> +	struct rkisp1_ext_params_block_header header;
>>>>>>> +	struct rkisp1_cif_isp_bdm_config config;
>>>>>>> +} __attribute__((aligned(8)));
>>>>>>> +
>>>>>>> +/**
>>>>>>> + * struct rkisp1_ext_params_ctk_config - RkISP1 extensible params CTK config
>>>>>>> + *
>>>>>>> + * RkISP1 extensible parameters Cross-Talk configuration block. Identified by
>>>>>>> + * :c:type:`RKISP1_EXT_PARAMS_BLOCK_TYPE_CTK`.
>>>>>>> + *
>>>>>>> + * @header: The RkISP1 extensible parameters header, see
>>>>>>> + *	    :c:type:`rkisp1_ext_params_block_header`
>>>>>>> + * @config: Cross-Talk configuration, see :c:type:`rkisp1_cif_isp_ctk_config`
>>>>>>> + */
>>>>>>> +struct rkisp1_ext_params_ctk_config {
>>>>>>> +	struct rkisp1_ext_params_block_header header;
>>>>>>> +	struct rkisp1_cif_isp_ctk_config config;
>>>>>>> +} __attribute__((aligned(8)));
>>>>>>> +
>>>>>>> +/**
>>>>>>> + * struct rkisp1_ext_params_goc_config - RkISP1 extensible params GOC config
>>>>>>> + *
>>>>>>> + * RkISP1 extensible parameters Gamma-Out configuration block. Identified by
>>>>>>> + * :c:type:`RKISP1_EXT_PARAMS_BLOCK_TYPE_GOC`.
>>>>>>> + *
>>>>>>> + * @header: The RkISP1 extensible parameters header, see
>>>>>>> + *	    :c:type:`rkisp1_ext_params_block_header`
>>>>>>> + * @config: Gamma-Out configuration, see :c:type:`rkisp1_cif_isp_goc_config`
>>>>>>> + */
>>>>>>> +struct rkisp1_ext_params_goc_config {
>>>>>>> +	struct rkisp1_ext_params_block_header header;
>>>>>>> +	struct rkisp1_cif_isp_goc_config config;
>>>>>>> +} __attribute__((aligned(8)));
>>>>>>> +
>>>>>>> +/**
>>>>>>> + * struct rkisp1_ext_params_dpf_config - RkISP1 extensible params DPF config
>>>>>>> + *
>>>>>>> + * RkISP1 extensible parameters De-noise Pre-Filter configuration block.
>>>>>>> + * Identified by :c:type:`RKISP1_EXT_PARAMS_BLOCK_TYPE_DPF`.
>>>>>>> + *
>>>>>>> + * @header: The RkISP1 extensible parameters header, see
>>>>>>> + *	    :c:type:`rkisp1_ext_params_block_header`
>>>>>>> + * @config: De-noise Pre-Filter configuration, see
>>>>>>> + *	    :c:type:`rkisp1_cif_isp_dpf_config`
>>>>>>> + */
>>>>>>> +struct rkisp1_ext_params_dpf_config {
>>>>>>> +	struct rkisp1_ext_params_block_header header;
>>>>>>> +	struct rkisp1_cif_isp_dpf_config config;
>>>>>>> +} __attribute__((aligned(8)));
>>>>>>> +
>>>>>>> +/**
>>>>>>> + * struct rkisp1_ext_params_dpf_strength_config - RkISP1 extensible params DPF
>>>>>>> + *						  strength config
>>>>>>> + *
>>>>>>> + * RkISP1 extensible parameters De-noise Pre-Filter strength configuration
>>>>>>> + * block. Identified by :c:type:`RKISP1_EXT_PARAMS_BLOCK_TYPE_DPF_STRENGTH`.
>>>>>>> + *
>>>>>>> + * @header: The RkISP1 extensible parameters header, see
>>>>>>> + *	    :c:type:`rkisp1_ext_params_block_header`
>>>>>>> + * @config: De-noise Pre-Filter strength configuration, see
>>>>>>> + *	    :c:type:`rkisp1_cif_isp_dpf_strength_config`
>>>>>>> + */
>>>>>>> +struct rkisp1_ext_params_dpf_strength_config {
>>>>>>> +	struct rkisp1_ext_params_block_header header;
>>>>>>> +	struct rkisp1_cif_isp_dpf_strength_config config;
>>>>>>> +} __attribute__((aligned(8)));
>>>>>>> +
>>>>>>> +/**
>>>>>>> + * struct rkisp1_ext_params_cproc_config - RkISP1 extensible params CPROC config
>>>>>>> + *
>>>>>>> + * RkISP1 extensible parameters Color Processing configuration block.
>>>>>>> + * Identified by :c:type:`RKISP1_EXT_PARAMS_BLOCK_TYPE_CPROC`.
>>>>>>> + *
>>>>>>> + * @header: The RkISP1 extensible parameters header, see
>>>>>>> + *	    :c:type:`rkisp1_ext_params_block_header`
>>>>>>> + * @config: Color processing configuration, see
>>>>>>> + *	    :c:type:`rkisp1_cif_isp_cproc_config`
>>>>>>> + */
>>>>>>> +struct rkisp1_ext_params_cproc_config {
>>>>>>> +	struct rkisp1_ext_params_block_header header;
>>>>>>> +	struct rkisp1_cif_isp_cproc_config config;
>>>>>>> +} __attribute__((aligned(8)));
>>>>>>> +
>>>>>>> +/**
>>>>>>> + * struct rkisp1_ext_params_ie_config - RkISP1 extensible params IE config
>>>>>>> + *
>>>>>>> + * RkISP1 extensible parameters Image Effect configuration block. Identified by
>>>>>>> + * :c:type:`RKISP1_EXT_PARAMS_BLOCK_TYPE_IE`.
>>>>>>> + *
>>>>>>> + * @header: The RkISP1 extensible parameters header, see
>>>>>>> + *	    :c:type:`rkisp1_ext_params_block_header`
>>>>>>> + * @config: Image Effect configuration, see :c:type:`rkisp1_cif_isp_ie_config`
>>>>>>> + */
>>>>>>> +struct rkisp1_ext_params_ie_config {
>>>>>>> +	struct rkisp1_ext_params_block_header header;
>>>>>>> +	struct rkisp1_cif_isp_ie_config config;
>>>>>>> +} __attribute__((aligned(8)));
>>>>>>> +
>>>>>>> +/**
>>>>>>> + * struct rkisp1_ext_params_awb_meas_config - RkISP1 extensible params AWB
>>>>>>> + *					      Meas config
>>>>>>> + *
>>>>>>> + * RkISP1 extensible parameters Auto-White Balance Measurement configuration
>>>>>>> + * block. Identified by :c:type:`RKISP1_EXT_PARAMS_BLOCK_TYPE_AWB_MEAS`.
>>>>>>> + *
>>>>>>> + * @header: The RkISP1 extensible parameters header, see
>>>>>>> + *	    :c:type:`rkisp1_ext_params_block_header`
>>>>>>> + * @config: Auto-White Balance measure configuration, see
>>>>>>> + *	    :c:type:`rkisp1_cif_isp_awb_meas_config`
>>>>>>> + */
>>>>>>> +struct rkisp1_ext_params_awb_meas_config {
>>>>>>> +	struct rkisp1_ext_params_block_header header;
>>>>>>> +	struct rkisp1_cif_isp_awb_meas_config config;
>>>>>>> +} __attribute__((aligned(8)));
>>>>>>> +
>>>>>>> +/**
>>>>>>> + * struct rkisp1_ext_params_hst_config - RkISP1 extensible params Histogram config
>>>>>>> + *
>>>>>>> + * RkISP1 extensible parameters Histogram statistics configuration block.
>>>>>>> + * Identified by :c:type:`RKISP1_EXT_PARAMS_BLOCK_TYPE_HST_MEAS`.
>>>>>>> + *
>>>>>>> + * @header: The RkISP1 extensible parameters header, see
>>>>>>> + *	    :c:type:`rkisp1_ext_params_block_header`
>>>>>>> + * @config: Histogram statistics configuration, see
>>>>>>> + *	    :c:type:`rkisp1_cif_isp_hst_config`
>>>>>>> + */
>>>>>>> +struct rkisp1_ext_params_hst_config {
>>>>>>> +	struct rkisp1_ext_params_block_header header;
>>>>>>> +	struct rkisp1_cif_isp_hst_config config;
>>>>>>> +} __attribute__((aligned(8)));
>>>>>>> +
>>>>>>> +/**
>>>>>>> + * struct rkisp1_ext_params_aec_config - RkISP1 extensible params AEC config
>>>>>>> + *
>>>>>>> + * RkISP1 extensible parameters Auto-Exposure statistics configuration block.
>>>>>>> + * Identified by :c:type:`RKISP1_EXT_PARAMS_BLOCK_TYPE_AEC_MEAS`.
>>>>>>> + *
>>>>>>> + * @header: The RkISP1 extensible parameters header, see
>>>>>>> + *	    :c:type:`rkisp1_ext_params_block_header`
>>>>>>> + * @config: Auto-Exposure statistics configuration, see
>>>>>>> + *	    :c:type:`rkisp1_cif_isp_aec_config`
>>>>>>> + */
>>>>>>> +struct rkisp1_ext_params_aec_config {
>>>>>>> +	struct rkisp1_ext_params_block_header header;
>>>>>>> +	struct rkisp1_cif_isp_aec_config config;
>>>>>>> +} __attribute__((aligned(8)));
>>>>>>> +
>>>>>>> +/**
>>>>>>> + * struct rkisp1_ext_params_afc_config - RkISP1 extensible params AFC config
>>>>>>> + *
>>>>>>> + * RkISP1 extensible parameters Auto-Focus statistics configuration block.
>>>>>>> + * Identified by :c:type:`RKISP1_EXT_PARAMS_BLOCK_TYPE_AFC_MEAS`.
>>>>>>> + *
>>>>>>> + * @header: The RkISP1 extensible parameters header, see
>>>>>>> + *	    :c:type:`rkisp1_ext_params_block_header`
>>>>>>> + * @config: Auto-Focus statistics configuration, see
>>>>>>> + *	    :c:type:`rkisp1_cif_isp_afc_config`
>>>>>>> + */
>>>>>>> +struct rkisp1_ext_params_afc_config {
>>>>>>> +	struct rkisp1_ext_params_block_header header;
>>>>>>> +	struct rkisp1_cif_isp_afc_config config;
>>>>>>> +} __attribute__((aligned(8)));
>>>>>>> +
>>>>>>> +#define RKISP1_EXT_PARAMS_MAX_SIZE					\
>>>>>>> +	(sizeof(struct rkisp1_ext_params_bls_config)			+\
>>>>>>> +	sizeof(struct rkisp1_ext_params_dpcc_config)			+\
>>>>>>> +	sizeof(struct rkisp1_ext_params_sdg_config)			+\
>>>>>>> +	sizeof(struct rkisp1_ext_params_lsc_config)			+\
>>>>>>> +	sizeof(struct rkisp1_ext_params_awb_gain_config)		+\
>>>>>>> +	sizeof(struct rkisp1_ext_params_flt_config)			+\
>>>>>>> +	sizeof(struct rkisp1_ext_params_bdm_config)			+\
>>>>>>> +	sizeof(struct rkisp1_ext_params_ctk_config)			+\
>>>>>>> +	sizeof(struct rkisp1_ext_params_goc_config)			+\
>>>>>>> +	sizeof(struct rkisp1_ext_params_dpf_config)			+\
>>>>>>> +	sizeof(struct rkisp1_ext_params_dpf_strength_config)		+\
>>>>>>> +	sizeof(struct rkisp1_ext_params_cproc_config)			+\
>>>>>>> +	sizeof(struct rkisp1_ext_params_ie_config)			+\
>>>>>>> +	sizeof(struct rkisp1_ext_params_awb_meas_config)		+\
>>>>>>> +	sizeof(struct rkisp1_ext_params_hst_config)			+\
>>>>>>> +	sizeof(struct rkisp1_ext_params_aec_config)			+\
>>>>>>> +	sizeof(struct rkisp1_ext_params_afc_config))
>>>>>>> +
>>>>>>> +/**
>>>>>>> + * enum rksip1_ext_param_buffer_version - RkISP1 extensible parameters version
>>>>>>> + *
>>>>>>> + * @RKISP1_EXT_PARAM_BUFFER_V1: First version of RkISP1 extensible parameters
>>>>>>> + */
>>>>>>> +enum rksip1_ext_param_buffer_version {
>>>>>>> +	RKISP1_EXT_PARAM_BUFFER_V1 = 1,
>>>>>>
>>>>>> I see no check against this in the rkisp1 code. Shouldn't this be checked?
>>>>>> If the version is unsupported, then just return an error.
>>>>>
>>>>> Do we need this for the first version ? There are no other versions
>>>>> userspace can use at the moment. I can add a check during validation
>>>>> though.
>>>>
>>>> Yes: if a V2 is added in the future, and an application wants to use that
>>>> against a driver that only support V1, then that should fail.
>>>>
>>>>>> Also, how does userspace know which version(s) is/are supported by the driver?
>>>>>
>>>>> Good question, there is no API for that atm. Defining a new format
>>>>> version should only happen when a non-backward compatible change to
>>>>> the format is made. I understand an application can be compiled
>>>>> against a newer kernel header that provides a new format version but
>>>>> then run on an older kernel where the new format is not supported.
>>>>>
>>>>> Probably userspace should be able to identify what versions are
>>>>> supported by the driver it runs with and use the most appropriate one
>>>>> by selecting it at runtime.
>>>>>
>>>>> What API would you use for that ? Is this something required for this
>>>>> first version where a single format version is available ?
>>>>
>>>> You need this also for this first version for the reason explained above.
>>>>
>>>> Personally I would just make a read-only control that returns the highest
>>>> supported version.
>>>
>>> Can't userspace use the version number reported through the media device
>>> to determine the features the driver support ? We've done that in
>>> libcamera for some drivers already, either to work around bugs, or to
>>> make use of new features.
>>
>> You can, but this will fall down if the driver is backported to an older
>> kernel for whatever reason. Since the version is just the kernel version,
>> it will drop back to that older kernel version.
> 
> I recall discussing this issue in the past (I'm not sure it was with
> you). If my memory doesn't fail me, there was a consensus that, when
> backporting the whole V4L2 subsystem, the version number reported would
> tbe the one corresponding to the more recent kernel, not the kernel the
> code has been backported to.

That was when using the old https://git.linuxtv.org/media_build.git/ system.
That's no longer in use.

I'm talking if a vendor is on an old kernel and backports rkisp1 to it (not
exactly uncommon!), then this will not work since the version will be that
of the old kernel.

Regards,

	Hans

> 
> That would help here, but will not solve the issue of how to deal with
> backports of a single driver. Jacopo, what do you think ?
> 
>> Whether that is acceptable or not is up to you.
>>
>> In any case, this would have to be documented so you know at which kernel
>> version a new RKISP1_EXT_PARAM_BUFFER_Vx is introduced.
>>
>>>>>>> +};
>>>>>>> +
>>>>>>> +/**
>>>>>>> + * struct rkisp1_ext_params_cfg - RkISP1 extensible parameters configuration
>>>>>>> + *
>>>>>>> + * This struct contains the configuration parameters of the RkISP1 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:`rkisp1_ext_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.
>>>>>>> + *
>>>>>>> + * 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
>>>>>>> + * 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 @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 -------------------+
>>>>>>> + *	| version = RKISP_EXT_PARAMS_BUFFER_V1;                               |
>>>>>>> + *	| data_size = sizeof(struct rkisp1_ext_params_bls_config)             |
>>>>>>> + *	|           + sizeof(struct rkisp1_ext_params_dpcc_config);           |
>>>>>>> + *	| +------------------------- data  ---------------------------------+ |
>>>>>>> + *	| | +------------- struct rkisp1_ext_params_bls_config -----------+ | |
>>>>>>> + *	| | | +-------- struct rkisp1_ext_params_block_header  ---------+ | | |
>>>>>>> + *	| | | | type = RKISP1_EXT_PARAMS_BLOCK_TYPE_BLS;                | | | |
>>>>>>> + *	| | | | flags = RKISP1_EXT_PARAMS_FL_BLOCK_ENABLE;              | | | |
>>>>>>> + *	| | | | size = sizeof(struct rkisp1_ext_params_bls_config);     | | | |
>>>>>>> + *	| | | +---------------------------------------------------------+ | | |
>>>>>>> + *	| | | +---------- struct rkisp1_cif_isp_bls_config -------------+ | | |
>>>>>>> + *	| | | | enable_auto = 0;                                        | | | |
>>>>>>> + *	| | | | fixed_val.r = 256;                                      | | | |
>>>>>>> + *	| | | | fixed_val.gr = 256;                                     | | | |
>>>>>>> + *	| | | | fixed_val.gb = 256;                                     | | | |
>>>>>>> + *	| | | | fixed_val.b = 256;                                      | | | |
>>>>>>> + *	| | | +---------------------------------------------------------+ | | |
>>>>>>> + *	| | +------------ struct rkisp1_ext_params_dpcc_config -----------+ | |
>>>>>>> + *	| | | +-------- struct rkisp1_ext_params_block_header  ---------+ | | |
>>>>>>> + *	| | | | type = RKISP1_EXT_PARAMS_BLOCK_TYPE_DPCC;               | | | |
>>>>>>> + *	| | | | flags = RKISP1_EXT_PARAMS_FL_BLOCK_ENABLE;              | | | |
>>>>>>> + *	| | | | size = sizeof(struct rkisp1_ext_params_dpcc_config);    | | | |
>>>>>>> + *	| | | +---------------------------------------------------------+ | | |
>>>>>>> + *	| | | +---------- struct rkisp1_cif_isp_dpcc_config ------------+ | | |
>>>>>>> + *	| | | | mode = RKISP1_CIF_ISP_DPCC_MODE_STAGE1_ENABLE;          | | | |
>>>>>>> + *	| | | | output_mode =                                           | | | |
>>>>>>> + *	| | | |   RKISP1_CIF_ISP_DPCC_OUTPUT_MODE_STAGE1_INCL_G_CENTER; | | | |
>>>>>>> + *	| | | | set_use = ... ;                                         | | | |
>>>>>>> + *	| | | | ...  = ... ;                                            | | | |
>>>>>>> + *	| | | +---------------------------------------------------------+ | | |
>>>>>>> + *	| | +-------------------------------------------------------------+ | |
>>>>>>> + *	| +-----------------------------------------------------------------+ |
>>>>>>> + *	+---------------------------------------------------------------------+
>>>>>>> + *
>>>>>>> + * @version: The RkISP1 extensible parameters buffer version, see
>>>>>>> + *	     :c:type:`rksip1_ext_param_buffer_version`
>>>>>>> + * @data_size: The RkISP1 configuration data effective size, excluding this
>>>>>>> + *	       header
>>>>>>> + * @data: The RkISP1 extensible configuration data blocks
>>>>>>> + */
>>>>>>> +struct rkisp1_ext_params_cfg {
>>>>>>> +	__u32 version;
>>>>>>> +	__u32 data_size;
>>>>>>> +	__u8 data[RKISP1_EXT_PARAMS_MAX_SIZE];
>>>>>>> +};
>>>>>>> +
>>>>>>>  #endif /* _UAPI_RKISP1_CONFIG_H */
>>>
>>
>
Jacopo Mondi Aug. 8, 2024, 12:03 p.m. UTC | #9
Hi Hans

On Thu, Aug 08, 2024 at 12:58:46PM GMT, Hans Verkuil wrote:
> On 08/08/2024 12:51, Laurent Pinchart wrote:
> > On Thu, Aug 08, 2024 at 12:03:01PM +0200, Hans Verkuil wrote:
> >> On 08/08/2024 11:54, Laurent Pinchart wrote:
> >>> On Thu, Aug 08, 2024 at 09:41:42AM +0200, Hans Verkuil wrote:
> >>>> On 08/08/2024 09:24, Jacopo Mondi wrote:
> >>>>> On Thu, Aug 08, 2024 at 08:31:58AM GMT, Hans Verkuil wrote:
> >>>>>> On 07/08/2024 23:22, Jacopo Mondi wrote:
> >>>>>>> Add to the rkisp1-config.h header data types and documentation of
> >>>>>>> the extensible parameters format.
> >>>>>>>
> >>>>>>> Signed-off-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
> >>>>>>> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> >>>>>>> Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>
> >>>>>>> Tested-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
> >>>>>>> Acked-by: Sakari Ailus <sakari.ailus@linux.intel.com>
> >>>>>>> ---
> >>>>>>>  include/uapi/linux/rkisp1-config.h | 485 +++++++++++++++++++++++++++++
> >>>>>>>  1 file changed, 485 insertions(+)
> >>>>>>>
> >>>>>>> diff --git a/include/uapi/linux/rkisp1-config.h b/include/uapi/linux/rkisp1-config.h
> >>>>>>> index 6eeaf8bf2362..14a23fd9a745 100644
> >>>>>>> --- a/include/uapi/linux/rkisp1-config.h
> >>>>>>> +++ b/include/uapi/linux/rkisp1-config.h
> >>>>>>> @@ -996,4 +996,489 @@ struct rkisp1_stat_buffer {
> >>>>>>>  	struct rkisp1_cif_isp_stat params;
> >>>>>>>  };
> >>>>>>>
> >>>>>>> +/*---------- PART3: Extensible Configuration Parameters  ------------*/
> >>>>>>> +
> >>>>>>> +/**
> >>>>>>> + * enum rkisp1_ext_params_block_type - RkISP1 extensible params block type
> >>>>>>> + *
> >>>>>>> + * @RKISP1_EXT_PARAMS_BLOCK_TYPE_BLS: Black level subtraction
> >>>>>>> + * @RKISP1_EXT_PARAMS_BLOCK_TYPE_DPCC: Defect pixel cluster correction
> >>>>>>> + * @RKISP1_EXT_PARAMS_BLOCK_TYPE_SDG: Sensor de-gamma
> >>>>>>> + * @RKISP1_EXT_PARAMS_BLOCK_TYPE_AWB_GAIN: Auto white balance gains
> >>>>>>> + * @RKISP1_EXT_PARAMS_BLOCK_TYPE_FLT: ISP filtering
> >>>>>>> + * @RKISP1_EXT_PARAMS_BLOCK_TYPE_BDM: Bayer de-mosaic
> >>>>>>> + * @RKISP1_EXT_PARAMS_BLOCK_TYPE_CTK: Cross-talk correction
> >>>>>>> + * @RKISP1_EXT_PARAMS_BLOCK_TYPE_GOC: Gamma out correction
> >>>>>>> + * @RKISP1_EXT_PARAMS_BLOCK_TYPE_DPF: De-noise pre-filter
> >>>>>>> + * @RKISP1_EXT_PARAMS_BLOCK_TYPE_DPF_STRENGTH: De-noise pre-filter strength
> >>>>>>> + * @RKISP1_EXT_PARAMS_BLOCK_TYPE_CPROC: Color processing
> >>>>>>> + * @RKISP1_EXT_PARAMS_BLOCK_TYPE_IE: Image effects
> >>>>>>> + * @RKISP1_EXT_PARAMS_BLOCK_TYPE_LSC: Lens shading correction
> >>>>>>> + * @RKISP1_EXT_PARAMS_BLOCK_TYPE_AWB_MEAS: Auto white balance statistics
> >>>>>>> + * @RKISP1_EXT_PARAMS_BLOCK_TYPE_HST_MEAS: Histogram statistics
> >>>>>>> + * @RKISP1_EXT_PARAMS_BLOCK_TYPE_AEC_MEAS: Auto exposure statistics
> >>>>>>> + * @RKISP1_EXT_PARAMS_BLOCK_TYPE_AFC_MEAS: Auto-focus statistics
> >>>>>>> + */
> >>>>>>> +enum rkisp1_ext_params_block_type {
> >>>>>>> +	RKISP1_EXT_PARAMS_BLOCK_TYPE_BLS,
> >>>>>>> +	RKISP1_EXT_PARAMS_BLOCK_TYPE_DPCC,
> >>>>>>> +	RKISP1_EXT_PARAMS_BLOCK_TYPE_SDG,
> >>>>>>> +	RKISP1_EXT_PARAMS_BLOCK_TYPE_AWB_GAIN,
> >>>>>>> +	RKISP1_EXT_PARAMS_BLOCK_TYPE_FLT,
> >>>>>>> +	RKISP1_EXT_PARAMS_BLOCK_TYPE_BDM,
> >>>>>>> +	RKISP1_EXT_PARAMS_BLOCK_TYPE_CTK,
> >>>>>>> +	RKISP1_EXT_PARAMS_BLOCK_TYPE_GOC,
> >>>>>>> +	RKISP1_EXT_PARAMS_BLOCK_TYPE_DPF,
> >>>>>>> +	RKISP1_EXT_PARAMS_BLOCK_TYPE_DPF_STRENGTH,
> >>>>>>> +	RKISP1_EXT_PARAMS_BLOCK_TYPE_CPROC,
> >>>>>>> +	RKISP1_EXT_PARAMS_BLOCK_TYPE_IE,
> >>>>>>> +	RKISP1_EXT_PARAMS_BLOCK_TYPE_LSC,
> >>>>>>> +	RKISP1_EXT_PARAMS_BLOCK_TYPE_AWB_MEAS,
> >>>>>>> +	RKISP1_EXT_PARAMS_BLOCK_TYPE_HST_MEAS,
> >>>>>>> +	RKISP1_EXT_PARAMS_BLOCK_TYPE_AEC_MEAS,
> >>>>>>> +	RKISP1_EXT_PARAMS_BLOCK_TYPE_AFC_MEAS,
> >>>>>>> +};
> >>>>>>> +
> >>>>>>> +#define RKISP1_EXT_PARAMS_FL_BLOCK_DISABLE	(1U << 0)
> >>>>>>> +#define RKISP1_EXT_PARAMS_FL_BLOCK_ENABLE	(1U << 1)
> >>>>>>> +
> >>>>>>> +/**
> >>>>>>> + * struct rkisp1_ext_params_block_header - RkISP1 extensible parameters 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 size and
> >>>>>>> + * properly handle the block content by casting it to the correct block-specific
> >>>>>>> + * type.
> >>>>>>> + *
> >>>>>>> + * The @type field is one of the values enumerated by
> >>>>>>> + * :c:type:`rkisp1_ext_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 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. The
> >>>>>>> + * driver ignores the rest of the block configuration structure in this case.
> >>>>>>> + *
> >>>>>>> + * 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_DISABLE 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 allowed
> >>>>>>> + * 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:
> >>>>>>> + *
> >>>>>>> + * .. code-block:: c
> >>>>>>> + *
> >>>>>>> + *	void populate_bls(struct rkisp1_ext_params_block_header *block) {
> >>>>>>> + *		struct rkisp1_ext_params_bls_config *bls =
> >>>>>>> + *			(struct rkisp1_ext_params_bls_config *)block;
> >>>>>>> + *
> >>>>>>> + *		bls->header.type = RKISP1_EXT_PARAMS_BLOCK_ID_BLS;
> >>>>>>> + *		bls->header.flags = RKISP1_EXT_PARAMS_FL_BLOCK_ENABLE;
> >>>>>>> + *		bls->header.size = sizeof(*bls);
> >>>>>>> + *
> >>>>>>> + *		bls->config.enable_auto = 0;
> >>>>>>> + *		bls->config.fixed_val.r = blackLevelRed_;
> >>>>>>> + *		bls->config.fixed_val.gr = blackLevelGreenR_;
> >>>>>>> + *		bls->config.fixed_val.gb = blackLevelGreenB_;
> >>>>>>> + *		bls->config.fixed_val.b = 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
> >>>>>>> + */
> >>>>>>> +struct rkisp1_ext_params_block_header {
> >>>>>>> +	__u16 type;
> >>>>>>> +	__u16 flags;
> >>>>>>> +	__u32 size;
> >>>>>>> +};
> >>>>>>> +
> >>>>>>> +/**
> >>>>>>> + * struct rkisp1_ext_params_bls_config - RkISP1 extensible params BLS config
> >>>>>>> + *
> >>>>>>> + * RkISP1 extensible parameters Black Level Subtraction configuration block.
> >>>>>>> + * Identified by :c:type:`RKISP1_EXT_PARAMS_BLOCK_TYPE_BLS`.
> >>>>>>> + *
> >>>>>>> + * @header: The RkISP1 extensible parameters header, see
> >>>>>>> + *	    :c:type:`rkisp1_ext_params_block_header`
> >>>>>>> + * @config: Black Level Subtraction configuration, see
> >>>>>>> + *	    :c:type:`rkisp1_cif_isp_bls_config`
> >>>>>>> + */
> >>>>>>> +struct rkisp1_ext_params_bls_config {
> >>>>>>> +	struct rkisp1_ext_params_block_header header;
> >>>>>>> +	struct rkisp1_cif_isp_bls_config config;
> >>>>>>> +} __attribute__((aligned(8)));
> >>>>>>> +
> >>>>>>> +/**
> >>>>>>> + * struct rkisp1_ext_params_dpcc_config - RkISP1 extensible params DPCC config
> >>>>>>> + *
> >>>>>>> + * RkISP1 extensible parameters Defective Pixel Cluster Correction configuration
> >>>>>>> + * block. Identified by :c:type:`RKISP1_EXT_PARAMS_BLOCK_TYPE_DPCC`.
> >>>>>>> + *
> >>>>>>> + * @header: The RkISP1 extensible parameters header, see
> >>>>>>> + *	    :c:type:`rkisp1_ext_params_block_header`
> >>>>>>> + * @config: Defective Pixel Cluster Correction configuration, see
> >>>>>>> + *	    :c:type:`rkisp1_cif_isp_dpcc_config`
> >>>>>>> + */
> >>>>>>> +struct rkisp1_ext_params_dpcc_config {
> >>>>>>> +	struct rkisp1_ext_params_block_header header;
> >>>>>>> +	struct rkisp1_cif_isp_dpcc_config config;
> >>>>>>> +} __attribute__((aligned(8)));
> >>>>>>> +
> >>>>>>> +/**
> >>>>>>> + * struct rkisp1_ext_params_sdg_config - RkISP1 extensible params SDG config
> >>>>>>> + *
> >>>>>>> + * RkISP1 extensible parameters Sensor Degamma configuration block. Identified
> >>>>>>> + * by :c:type:`RKISP1_EXT_PARAMS_BLOCK_TYPE_SDG`.
> >>>>>>> + *
> >>>>>>> + * @header: The RkISP1 extensible parameters header, see
> >>>>>>> + *	    :c:type:`rkisp1_ext_params_block_header`
> >>>>>>> + * @config: Sensor Degamma configuration, see
> >>>>>>> + *	    :c:type:`rkisp1_cif_isp_sdg_config`
> >>>>>>> + */
> >>>>>>> +struct rkisp1_ext_params_sdg_config {
> >>>>>>> +	struct rkisp1_ext_params_block_header header;
> >>>>>>> +	struct rkisp1_cif_isp_sdg_config config;
> >>>>>>> +} __attribute__((aligned(8)));
> >>>>>>> +
> >>>>>>> +/**
> >>>>>>> + * struct rkisp1_ext_params_lsc_config - RkISP1 extensible params LSC config
> >>>>>>> + *
> >>>>>>> + * RkISP1 extensible parameters Lens Shading Correction configuration block.
> >>>>>>> + * Identified by :c:type:`RKISP1_EXT_PARAMS_BLOCK_TYPE_LSC`.
> >>>>>>> + *
> >>>>>>> + * @header: The RkISP1 extensible parameters header, see
> >>>>>>> + *	    :c:type:`rkisp1_ext_params_block_header`
> >>>>>>> + * @config: Lens Shading Correction configuration, see
> >>>>>>> + *	    :c:type:`rkisp1_cif_isp_lsc_config`
> >>>>>>> + */
> >>>>>>> +struct rkisp1_ext_params_lsc_config {
> >>>>>>> +	struct rkisp1_ext_params_block_header header;
> >>>>>>> +	struct rkisp1_cif_isp_lsc_config config;
> >>>>>>> +} __attribute__((aligned(8)));
> >>>>>>> +
> >>>>>>> +/**
> >>>>>>> + * struct rkisp1_ext_params_awb_gain_config - RkISP1 extensible params AWB
> >>>>>>> + *					      gain config
> >>>>>>> + *
> >>>>>>> + * RkISP1 extensible parameters Auto-White Balance Gains configuration block.
> >>>>>>> + * Identified by :c:type:`RKISP1_EXT_PARAMS_BLOCK_TYPE_AWB_GAIN`.
> >>>>>>> + *
> >>>>>>> + * @header: The RkISP1 extensible parameters header, see
> >>>>>>> + *	    :c:type:`rkisp1_ext_params_block_header`
> >>>>>>> + * @config: Auto-White Balance Gains configuration, see
> >>>>>>> + *	    :c:type:`rkisp1_cif_isp_awb_gain_config`
> >>>>>>> + */
> >>>>>>> +struct rkisp1_ext_params_awb_gain_config {
> >>>>>>> +	struct rkisp1_ext_params_block_header header;
> >>>>>>> +	struct rkisp1_cif_isp_awb_gain_config config;
> >>>>>>> +} __attribute__((aligned(8)));
> >>>>>>> +
> >>>>>>> +/**
> >>>>>>> + * struct rkisp1_ext_params_flt_config - RkISP1 extensible params FLT config
> >>>>>>> + *
> >>>>>>> + * RkISP1 extensible parameters Filter configuration block. Identified by
> >>>>>>> + * :c:type:`RKISP1_EXT_PARAMS_BLOCK_TYPE_FLT`.
> >>>>>>> + *
> >>>>>>> + * @header: The RkISP1 extensible parameters header, see
> >>>>>>> + *	    :c:type:`rkisp1_ext_params_block_header`
> >>>>>>> + * @config: Filter configuration, see :c:type:`rkisp1_cif_isp_flt_config`
> >>>>>>> + */
> >>>>>>> +struct rkisp1_ext_params_flt_config {
> >>>>>>> +	struct rkisp1_ext_params_block_header header;
> >>>>>>> +	struct rkisp1_cif_isp_flt_config config;
> >>>>>>> +} __attribute__((aligned(8)));
> >>>>>>> +
> >>>>>>> +/**
> >>>>>>> + * struct rkisp1_ext_params_bdm_config - RkISP1 extensible params BDM config
> >>>>>>> + *
> >>>>>>> + * RkISP1 extensible parameters Demosaicing configuration block. Identified by
> >>>>>>> + * :c:type:`RKISP1_EXT_PARAMS_BLOCK_TYPE_BDM`.
> >>>>>>> + *
> >>>>>>> + * @header: The RkISP1 extensible parameters header, see
> >>>>>>> + *	    :c:type:`rkisp1_ext_params_block_header`
> >>>>>>> + * @config: Demosaicing configuration, see :c:type:`rkisp1_cif_isp_bdm_config`
> >>>>>>> + */
> >>>>>>> +struct rkisp1_ext_params_bdm_config {
> >>>>>>> +	struct rkisp1_ext_params_block_header header;
> >>>>>>> +	struct rkisp1_cif_isp_bdm_config config;
> >>>>>>> +} __attribute__((aligned(8)));
> >>>>>>> +
> >>>>>>> +/**
> >>>>>>> + * struct rkisp1_ext_params_ctk_config - RkISP1 extensible params CTK config
> >>>>>>> + *
> >>>>>>> + * RkISP1 extensible parameters Cross-Talk configuration block. Identified by
> >>>>>>> + * :c:type:`RKISP1_EXT_PARAMS_BLOCK_TYPE_CTK`.
> >>>>>>> + *
> >>>>>>> + * @header: The RkISP1 extensible parameters header, see
> >>>>>>> + *	    :c:type:`rkisp1_ext_params_block_header`
> >>>>>>> + * @config: Cross-Talk configuration, see :c:type:`rkisp1_cif_isp_ctk_config`
> >>>>>>> + */
> >>>>>>> +struct rkisp1_ext_params_ctk_config {
> >>>>>>> +	struct rkisp1_ext_params_block_header header;
> >>>>>>> +	struct rkisp1_cif_isp_ctk_config config;
> >>>>>>> +} __attribute__((aligned(8)));
> >>>>>>> +
> >>>>>>> +/**
> >>>>>>> + * struct rkisp1_ext_params_goc_config - RkISP1 extensible params GOC config
> >>>>>>> + *
> >>>>>>> + * RkISP1 extensible parameters Gamma-Out configuration block. Identified by
> >>>>>>> + * :c:type:`RKISP1_EXT_PARAMS_BLOCK_TYPE_GOC`.
> >>>>>>> + *
> >>>>>>> + * @header: The RkISP1 extensible parameters header, see
> >>>>>>> + *	    :c:type:`rkisp1_ext_params_block_header`
> >>>>>>> + * @config: Gamma-Out configuration, see :c:type:`rkisp1_cif_isp_goc_config`
> >>>>>>> + */
> >>>>>>> +struct rkisp1_ext_params_goc_config {
> >>>>>>> +	struct rkisp1_ext_params_block_header header;
> >>>>>>> +	struct rkisp1_cif_isp_goc_config config;
> >>>>>>> +} __attribute__((aligned(8)));
> >>>>>>> +
> >>>>>>> +/**
> >>>>>>> + * struct rkisp1_ext_params_dpf_config - RkISP1 extensible params DPF config
> >>>>>>> + *
> >>>>>>> + * RkISP1 extensible parameters De-noise Pre-Filter configuration block.
> >>>>>>> + * Identified by :c:type:`RKISP1_EXT_PARAMS_BLOCK_TYPE_DPF`.
> >>>>>>> + *
> >>>>>>> + * @header: The RkISP1 extensible parameters header, see
> >>>>>>> + *	    :c:type:`rkisp1_ext_params_block_header`
> >>>>>>> + * @config: De-noise Pre-Filter configuration, see
> >>>>>>> + *	    :c:type:`rkisp1_cif_isp_dpf_config`
> >>>>>>> + */
> >>>>>>> +struct rkisp1_ext_params_dpf_config {
> >>>>>>> +	struct rkisp1_ext_params_block_header header;
> >>>>>>> +	struct rkisp1_cif_isp_dpf_config config;
> >>>>>>> +} __attribute__((aligned(8)));
> >>>>>>> +
> >>>>>>> +/**
> >>>>>>> + * struct rkisp1_ext_params_dpf_strength_config - RkISP1 extensible params DPF
> >>>>>>> + *						  strength config
> >>>>>>> + *
> >>>>>>> + * RkISP1 extensible parameters De-noise Pre-Filter strength configuration
> >>>>>>> + * block. Identified by :c:type:`RKISP1_EXT_PARAMS_BLOCK_TYPE_DPF_STRENGTH`.
> >>>>>>> + *
> >>>>>>> + * @header: The RkISP1 extensible parameters header, see
> >>>>>>> + *	    :c:type:`rkisp1_ext_params_block_header`
> >>>>>>> + * @config: De-noise Pre-Filter strength configuration, see
> >>>>>>> + *	    :c:type:`rkisp1_cif_isp_dpf_strength_config`
> >>>>>>> + */
> >>>>>>> +struct rkisp1_ext_params_dpf_strength_config {
> >>>>>>> +	struct rkisp1_ext_params_block_header header;
> >>>>>>> +	struct rkisp1_cif_isp_dpf_strength_config config;
> >>>>>>> +} __attribute__((aligned(8)));
> >>>>>>> +
> >>>>>>> +/**
> >>>>>>> + * struct rkisp1_ext_params_cproc_config - RkISP1 extensible params CPROC config
> >>>>>>> + *
> >>>>>>> + * RkISP1 extensible parameters Color Processing configuration block.
> >>>>>>> + * Identified by :c:type:`RKISP1_EXT_PARAMS_BLOCK_TYPE_CPROC`.
> >>>>>>> + *
> >>>>>>> + * @header: The RkISP1 extensible parameters header, see
> >>>>>>> + *	    :c:type:`rkisp1_ext_params_block_header`
> >>>>>>> + * @config: Color processing configuration, see
> >>>>>>> + *	    :c:type:`rkisp1_cif_isp_cproc_config`
> >>>>>>> + */
> >>>>>>> +struct rkisp1_ext_params_cproc_config {
> >>>>>>> +	struct rkisp1_ext_params_block_header header;
> >>>>>>> +	struct rkisp1_cif_isp_cproc_config config;
> >>>>>>> +} __attribute__((aligned(8)));
> >>>>>>> +
> >>>>>>> +/**
> >>>>>>> + * struct rkisp1_ext_params_ie_config - RkISP1 extensible params IE config
> >>>>>>> + *
> >>>>>>> + * RkISP1 extensible parameters Image Effect configuration block. Identified by
> >>>>>>> + * :c:type:`RKISP1_EXT_PARAMS_BLOCK_TYPE_IE`.
> >>>>>>> + *
> >>>>>>> + * @header: The RkISP1 extensible parameters header, see
> >>>>>>> + *	    :c:type:`rkisp1_ext_params_block_header`
> >>>>>>> + * @config: Image Effect configuration, see :c:type:`rkisp1_cif_isp_ie_config`
> >>>>>>> + */
> >>>>>>> +struct rkisp1_ext_params_ie_config {
> >>>>>>> +	struct rkisp1_ext_params_block_header header;
> >>>>>>> +	struct rkisp1_cif_isp_ie_config config;
> >>>>>>> +} __attribute__((aligned(8)));
> >>>>>>> +
> >>>>>>> +/**
> >>>>>>> + * struct rkisp1_ext_params_awb_meas_config - RkISP1 extensible params AWB
> >>>>>>> + *					      Meas config
> >>>>>>> + *
> >>>>>>> + * RkISP1 extensible parameters Auto-White Balance Measurement configuration
> >>>>>>> + * block. Identified by :c:type:`RKISP1_EXT_PARAMS_BLOCK_TYPE_AWB_MEAS`.
> >>>>>>> + *
> >>>>>>> + * @header: The RkISP1 extensible parameters header, see
> >>>>>>> + *	    :c:type:`rkisp1_ext_params_block_header`
> >>>>>>> + * @config: Auto-White Balance measure configuration, see
> >>>>>>> + *	    :c:type:`rkisp1_cif_isp_awb_meas_config`
> >>>>>>> + */
> >>>>>>> +struct rkisp1_ext_params_awb_meas_config {
> >>>>>>> +	struct rkisp1_ext_params_block_header header;
> >>>>>>> +	struct rkisp1_cif_isp_awb_meas_config config;
> >>>>>>> +} __attribute__((aligned(8)));
> >>>>>>> +
> >>>>>>> +/**
> >>>>>>> + * struct rkisp1_ext_params_hst_config - RkISP1 extensible params Histogram config
> >>>>>>> + *
> >>>>>>> + * RkISP1 extensible parameters Histogram statistics configuration block.
> >>>>>>> + * Identified by :c:type:`RKISP1_EXT_PARAMS_BLOCK_TYPE_HST_MEAS`.
> >>>>>>> + *
> >>>>>>> + * @header: The RkISP1 extensible parameters header, see
> >>>>>>> + *	    :c:type:`rkisp1_ext_params_block_header`
> >>>>>>> + * @config: Histogram statistics configuration, see
> >>>>>>> + *	    :c:type:`rkisp1_cif_isp_hst_config`
> >>>>>>> + */
> >>>>>>> +struct rkisp1_ext_params_hst_config {
> >>>>>>> +	struct rkisp1_ext_params_block_header header;
> >>>>>>> +	struct rkisp1_cif_isp_hst_config config;
> >>>>>>> +} __attribute__((aligned(8)));
> >>>>>>> +
> >>>>>>> +/**
> >>>>>>> + * struct rkisp1_ext_params_aec_config - RkISP1 extensible params AEC config
> >>>>>>> + *
> >>>>>>> + * RkISP1 extensible parameters Auto-Exposure statistics configuration block.
> >>>>>>> + * Identified by :c:type:`RKISP1_EXT_PARAMS_BLOCK_TYPE_AEC_MEAS`.
> >>>>>>> + *
> >>>>>>> + * @header: The RkISP1 extensible parameters header, see
> >>>>>>> + *	    :c:type:`rkisp1_ext_params_block_header`
> >>>>>>> + * @config: Auto-Exposure statistics configuration, see
> >>>>>>> + *	    :c:type:`rkisp1_cif_isp_aec_config`
> >>>>>>> + */
> >>>>>>> +struct rkisp1_ext_params_aec_config {
> >>>>>>> +	struct rkisp1_ext_params_block_header header;
> >>>>>>> +	struct rkisp1_cif_isp_aec_config config;
> >>>>>>> +} __attribute__((aligned(8)));
> >>>>>>> +
> >>>>>>> +/**
> >>>>>>> + * struct rkisp1_ext_params_afc_config - RkISP1 extensible params AFC config
> >>>>>>> + *
> >>>>>>> + * RkISP1 extensible parameters Auto-Focus statistics configuration block.
> >>>>>>> + * Identified by :c:type:`RKISP1_EXT_PARAMS_BLOCK_TYPE_AFC_MEAS`.
> >>>>>>> + *
> >>>>>>> + * @header: The RkISP1 extensible parameters header, see
> >>>>>>> + *	    :c:type:`rkisp1_ext_params_block_header`
> >>>>>>> + * @config: Auto-Focus statistics configuration, see
> >>>>>>> + *	    :c:type:`rkisp1_cif_isp_afc_config`
> >>>>>>> + */
> >>>>>>> +struct rkisp1_ext_params_afc_config {
> >>>>>>> +	struct rkisp1_ext_params_block_header header;
> >>>>>>> +	struct rkisp1_cif_isp_afc_config config;
> >>>>>>> +} __attribute__((aligned(8)));
> >>>>>>> +
> >>>>>>> +#define RKISP1_EXT_PARAMS_MAX_SIZE					\
> >>>>>>> +	(sizeof(struct rkisp1_ext_params_bls_config)			+\
> >>>>>>> +	sizeof(struct rkisp1_ext_params_dpcc_config)			+\
> >>>>>>> +	sizeof(struct rkisp1_ext_params_sdg_config)			+\
> >>>>>>> +	sizeof(struct rkisp1_ext_params_lsc_config)			+\
> >>>>>>> +	sizeof(struct rkisp1_ext_params_awb_gain_config)		+\
> >>>>>>> +	sizeof(struct rkisp1_ext_params_flt_config)			+\
> >>>>>>> +	sizeof(struct rkisp1_ext_params_bdm_config)			+\
> >>>>>>> +	sizeof(struct rkisp1_ext_params_ctk_config)			+\
> >>>>>>> +	sizeof(struct rkisp1_ext_params_goc_config)			+\
> >>>>>>> +	sizeof(struct rkisp1_ext_params_dpf_config)			+\
> >>>>>>> +	sizeof(struct rkisp1_ext_params_dpf_strength_config)		+\
> >>>>>>> +	sizeof(struct rkisp1_ext_params_cproc_config)			+\
> >>>>>>> +	sizeof(struct rkisp1_ext_params_ie_config)			+\
> >>>>>>> +	sizeof(struct rkisp1_ext_params_awb_meas_config)		+\
> >>>>>>> +	sizeof(struct rkisp1_ext_params_hst_config)			+\
> >>>>>>> +	sizeof(struct rkisp1_ext_params_aec_config)			+\
> >>>>>>> +	sizeof(struct rkisp1_ext_params_afc_config))
> >>>>>>> +
> >>>>>>> +/**
> >>>>>>> + * enum rksip1_ext_param_buffer_version - RkISP1 extensible parameters version
> >>>>>>> + *
> >>>>>>> + * @RKISP1_EXT_PARAM_BUFFER_V1: First version of RkISP1 extensible parameters
> >>>>>>> + */
> >>>>>>> +enum rksip1_ext_param_buffer_version {
> >>>>>>> +	RKISP1_EXT_PARAM_BUFFER_V1 = 1,
> >>>>>>
> >>>>>> I see no check against this in the rkisp1 code. Shouldn't this be checked?
> >>>>>> If the version is unsupported, then just return an error.
> >>>>>
> >>>>> Do we need this for the first version ? There are no other versions
> >>>>> userspace can use at the moment. I can add a check during validation
> >>>>> though.
> >>>>
> >>>> Yes: if a V2 is added in the future, and an application wants to use that
> >>>> against a driver that only support V1, then that should fail.
> >>>>
> >>>>>> Also, how does userspace know which version(s) is/are supported by the driver?
> >>>>>
> >>>>> Good question, there is no API for that atm. Defining a new format
> >>>>> version should only happen when a non-backward compatible change to
> >>>>> the format is made. I understand an application can be compiled
> >>>>> against a newer kernel header that provides a new format version but
> >>>>> then run on an older kernel where the new format is not supported.
> >>>>>
> >>>>> Probably userspace should be able to identify what versions are
> >>>>> supported by the driver it runs with and use the most appropriate one
> >>>>> by selecting it at runtime.
> >>>>>
> >>>>> What API would you use for that ? Is this something required for this
> >>>>> first version where a single format version is available ?
> >>>>
> >>>> You need this also for this first version for the reason explained above.
> >>>>
> >>>> Personally I would just make a read-only control that returns the highest
> >>>> supported version.
> >>>
> >>> Can't userspace use the version number reported through the media device
> >>> to determine the features the driver support ? We've done that in
> >>> libcamera for some drivers already, either to work around bugs, or to
> >>> make use of new features.
> >>
> >> You can, but this will fall down if the driver is backported to an older
> >> kernel for whatever reason. Since the version is just the kernel version,
> >> it will drop back to that older kernel version.
> >
> > I recall discussing this issue in the past (I'm not sure it was with
> > you). If my memory doesn't fail me, there was a consensus that, when
> > backporting the whole V4L2 subsystem, the version number reported would
> > tbe the one corresponding to the more recent kernel, not the kernel the
> > code has been backported to.
>
> That was when using the old https://git.linuxtv.org/media_build.git/ system.
> That's no longer in use.
>
> I'm talking if a vendor is on an old kernel and backports rkisp1 to it (not
> exactly uncommon!), then this will not work since the version will be that
> of the old kernel.
>

In this case it will backport the driver and the uAPI from the same
version, so this shouldn't be an issue.

What is concerning is an application compiled against a uAPI newer
than the kernel it will be run on. The uAPI could advertise newer
format revisions the driver doesn't know about and will fail to
validate. In this case the application should be give a way to know
what version is the most recent one supported by the driver, and a
control might be the way forward. As long as we have a single format
revision I think we might omit implementing the control for now and
only expose it when multiple revisions will be implemented ? If the
control is not there, it means only V1 is available. Should I document
it ?

> Regards,
>
> 	Hans
>
> >
> > That would help here, but will not solve the issue of how to deal with
> > backports of a single driver. Jacopo, what do you think ?
> >
> >> Whether that is acceptable or not is up to you.
> >>
> >> In any case, this would have to be documented so you know at which kernel
> >> version a new RKISP1_EXT_PARAM_BUFFER_Vx is introduced.
> >>
> >>>>>>> +};
> >>>>>>> +
> >>>>>>> +/**
> >>>>>>> + * struct rkisp1_ext_params_cfg - RkISP1 extensible parameters configuration
> >>>>>>> + *
> >>>>>>> + * This struct contains the configuration parameters of the RkISP1 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:`rkisp1_ext_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.
> >>>>>>> + *
> >>>>>>> + * 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
> >>>>>>> + * 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 @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 -------------------+
> >>>>>>> + *	| version = RKISP_EXT_PARAMS_BUFFER_V1;                               |
> >>>>>>> + *	| data_size = sizeof(struct rkisp1_ext_params_bls_config)             |
> >>>>>>> + *	|           + sizeof(struct rkisp1_ext_params_dpcc_config);           |
> >>>>>>> + *	| +------------------------- data  ---------------------------------+ |
> >>>>>>> + *	| | +------------- struct rkisp1_ext_params_bls_config -----------+ | |
> >>>>>>> + *	| | | +-------- struct rkisp1_ext_params_block_header  ---------+ | | |
> >>>>>>> + *	| | | | type = RKISP1_EXT_PARAMS_BLOCK_TYPE_BLS;                | | | |
> >>>>>>> + *	| | | | flags = RKISP1_EXT_PARAMS_FL_BLOCK_ENABLE;              | | | |
> >>>>>>> + *	| | | | size = sizeof(struct rkisp1_ext_params_bls_config);     | | | |
> >>>>>>> + *	| | | +---------------------------------------------------------+ | | |
> >>>>>>> + *	| | | +---------- struct rkisp1_cif_isp_bls_config -------------+ | | |
> >>>>>>> + *	| | | | enable_auto = 0;                                        | | | |
> >>>>>>> + *	| | | | fixed_val.r = 256;                                      | | | |
> >>>>>>> + *	| | | | fixed_val.gr = 256;                                     | | | |
> >>>>>>> + *	| | | | fixed_val.gb = 256;                                     | | | |
> >>>>>>> + *	| | | | fixed_val.b = 256;                                      | | | |
> >>>>>>> + *	| | | +---------------------------------------------------------+ | | |
> >>>>>>> + *	| | +------------ struct rkisp1_ext_params_dpcc_config -----------+ | |
> >>>>>>> + *	| | | +-------- struct rkisp1_ext_params_block_header  ---------+ | | |
> >>>>>>> + *	| | | | type = RKISP1_EXT_PARAMS_BLOCK_TYPE_DPCC;               | | | |
> >>>>>>> + *	| | | | flags = RKISP1_EXT_PARAMS_FL_BLOCK_ENABLE;              | | | |
> >>>>>>> + *	| | | | size = sizeof(struct rkisp1_ext_params_dpcc_config);    | | | |
> >>>>>>> + *	| | | +---------------------------------------------------------+ | | |
> >>>>>>> + *	| | | +---------- struct rkisp1_cif_isp_dpcc_config ------------+ | | |
> >>>>>>> + *	| | | | mode = RKISP1_CIF_ISP_DPCC_MODE_STAGE1_ENABLE;          | | | |
> >>>>>>> + *	| | | | output_mode =                                           | | | |
> >>>>>>> + *	| | | |   RKISP1_CIF_ISP_DPCC_OUTPUT_MODE_STAGE1_INCL_G_CENTER; | | | |
> >>>>>>> + *	| | | | set_use = ... ;                                         | | | |
> >>>>>>> + *	| | | | ...  = ... ;                                            | | | |
> >>>>>>> + *	| | | +---------------------------------------------------------+ | | |
> >>>>>>> + *	| | +-------------------------------------------------------------+ | |
> >>>>>>> + *	| +-----------------------------------------------------------------+ |
> >>>>>>> + *	+---------------------------------------------------------------------+
> >>>>>>> + *
> >>>>>>> + * @version: The RkISP1 extensible parameters buffer version, see
> >>>>>>> + *	     :c:type:`rksip1_ext_param_buffer_version`
> >>>>>>> + * @data_size: The RkISP1 configuration data effective size, excluding this
> >>>>>>> + *	       header
> >>>>>>> + * @data: The RkISP1 extensible configuration data blocks
> >>>>>>> + */
> >>>>>>> +struct rkisp1_ext_params_cfg {
> >>>>>>> +	__u32 version;
> >>>>>>> +	__u32 data_size;
> >>>>>>> +	__u8 data[RKISP1_EXT_PARAMS_MAX_SIZE];
> >>>>>>> +};
> >>>>>>> +
> >>>>>>>  #endif /* _UAPI_RKISP1_CONFIG_H */
> >>>
> >>
> >
>
Hans Verkuil Aug. 8, 2024, 2:01 p.m. UTC | #10
On 08/08/2024 14:03, Jacopo Mondi wrote:
> Hi Hans
> 
> On Thu, Aug 08, 2024 at 12:58:46PM GMT, Hans Verkuil wrote:

<snip>

>>>>>>>> I see no check against this in the rkisp1 code. Shouldn't this be checked?
>>>>>>>> If the version is unsupported, then just return an error.
>>>>>>>
>>>>>>> Do we need this for the first version ? There are no other versions
>>>>>>> userspace can use at the moment. I can add a check during validation
>>>>>>> though.
>>>>>>
>>>>>> Yes: if a V2 is added in the future, and an application wants to use that
>>>>>> against a driver that only support V1, then that should fail.
>>>>>>
>>>>>>>> Also, how does userspace know which version(s) is/are supported by the driver?
>>>>>>>
>>>>>>> Good question, there is no API for that atm. Defining a new format
>>>>>>> version should only happen when a non-backward compatible change to
>>>>>>> the format is made. I understand an application can be compiled
>>>>>>> against a newer kernel header that provides a new format version but
>>>>>>> then run on an older kernel where the new format is not supported.
>>>>>>>
>>>>>>> Probably userspace should be able to identify what versions are
>>>>>>> supported by the driver it runs with and use the most appropriate one
>>>>>>> by selecting it at runtime.
>>>>>>>
>>>>>>> What API would you use for that ? Is this something required for this
>>>>>>> first version where a single format version is available ?
>>>>>>
>>>>>> You need this also for this first version for the reason explained above.
>>>>>>
>>>>>> Personally I would just make a read-only control that returns the highest
>>>>>> supported version.
>>>>>
>>>>> Can't userspace use the version number reported through the media device
>>>>> to determine the features the driver support ? We've done that in
>>>>> libcamera for some drivers already, either to work around bugs, or to
>>>>> make use of new features.
>>>>
>>>> You can, but this will fall down if the driver is backported to an older
>>>> kernel for whatever reason. Since the version is just the kernel version,
>>>> it will drop back to that older kernel version.
>>>
>>> I recall discussing this issue in the past (I'm not sure it was with
>>> you). If my memory doesn't fail me, there was a consensus that, when
>>> backporting the whole V4L2 subsystem, the version number reported would
>>> tbe the one corresponding to the more recent kernel, not the kernel the
>>> code has been backported to.
>>
>> That was when using the old https://git.linuxtv.org/media_build.git/ system.
>> That's no longer in use.
>>
>> I'm talking if a vendor is on an old kernel and backports rkisp1 to it (not
>> exactly uncommon!), then this will not work since the version will be that
>> of the old kernel.
>>
> 
> In this case it will backport the driver and the uAPI from the same
> version, so this shouldn't be an issue.
> 
> What is concerning is an application compiled against a uAPI newer
> than the kernel it will be run on. The uAPI could advertise newer
> format revisions the driver doesn't know about and will fail to
> validate. In this case the application should be give a way to know
> what version is the most recent one supported by the driver, and a
> control might be the way forward. As long as we have a single format
> revision I think we might omit implementing the control for now and
> only expose it when multiple revisions will be implemented ? If the
> control is not there, it means only V1 is available. Should I document
> it ?

I think it is sufficient for now to just add a version check in the driver
and return an error if it is not supported.

And when a V2 is introduced, then we can think about using a control. Or
perhaps just rely on the version check.

Regards,

	Hans

> 
>> Regards,
>>
>> 	Hans
>>
>>>
>>> That would help here, but will not solve the issue of how to deal with
>>> backports of a single driver. Jacopo, what do you think ?
>>>
>>>> Whether that is acceptable or not is up to you.
>>>>
>>>> In any case, this would have to be documented so you know at which kernel
>>>> version a new RKISP1_EXT_PARAM_BUFFER_Vx is introduced.
>>>>
>>>>>>>>> +};
>>>>>>>>> +
>>>>>>>>> +/**
>>>>>>>>> + * struct rkisp1_ext_params_cfg - RkISP1 extensible parameters configuration
>>>>>>>>> + *
>>>>>>>>> + * This struct contains the configuration parameters of the RkISP1 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:`rkisp1_ext_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.
>>>>>>>>> + *
>>>>>>>>> + * 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
>>>>>>>>> + * 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 @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 -------------------+
>>>>>>>>> + *	| version = RKISP_EXT_PARAMS_BUFFER_V1;                               |
>>>>>>>>> + *	| data_size = sizeof(struct rkisp1_ext_params_bls_config)             |
>>>>>>>>> + *	|           + sizeof(struct rkisp1_ext_params_dpcc_config);           |
>>>>>>>>> + *	| +------------------------- data  ---------------------------------+ |
>>>>>>>>> + *	| | +------------- struct rkisp1_ext_params_bls_config -----------+ | |
>>>>>>>>> + *	| | | +-------- struct rkisp1_ext_params_block_header  ---------+ | | |
>>>>>>>>> + *	| | | | type = RKISP1_EXT_PARAMS_BLOCK_TYPE_BLS;                | | | |
>>>>>>>>> + *	| | | | flags = RKISP1_EXT_PARAMS_FL_BLOCK_ENABLE;              | | | |
>>>>>>>>> + *	| | | | size = sizeof(struct rkisp1_ext_params_bls_config);     | | | |
>>>>>>>>> + *	| | | +---------------------------------------------------------+ | | |
>>>>>>>>> + *	| | | +---------- struct rkisp1_cif_isp_bls_config -------------+ | | |
>>>>>>>>> + *	| | | | enable_auto = 0;                                        | | | |
>>>>>>>>> + *	| | | | fixed_val.r = 256;                                      | | | |
>>>>>>>>> + *	| | | | fixed_val.gr = 256;                                     | | | |
>>>>>>>>> + *	| | | | fixed_val.gb = 256;                                     | | | |
>>>>>>>>> + *	| | | | fixed_val.b = 256;                                      | | | |
>>>>>>>>> + *	| | | +---------------------------------------------------------+ | | |
>>>>>>>>> + *	| | +------------ struct rkisp1_ext_params_dpcc_config -----------+ | |
>>>>>>>>> + *	| | | +-------- struct rkisp1_ext_params_block_header  ---------+ | | |
>>>>>>>>> + *	| | | | type = RKISP1_EXT_PARAMS_BLOCK_TYPE_DPCC;               | | | |
>>>>>>>>> + *	| | | | flags = RKISP1_EXT_PARAMS_FL_BLOCK_ENABLE;              | | | |
>>>>>>>>> + *	| | | | size = sizeof(struct rkisp1_ext_params_dpcc_config);    | | | |
>>>>>>>>> + *	| | | +---------------------------------------------------------+ | | |
>>>>>>>>> + *	| | | +---------- struct rkisp1_cif_isp_dpcc_config ------------+ | | |
>>>>>>>>> + *	| | | | mode = RKISP1_CIF_ISP_DPCC_MODE_STAGE1_ENABLE;          | | | |
>>>>>>>>> + *	| | | | output_mode =                                           | | | |
>>>>>>>>> + *	| | | |   RKISP1_CIF_ISP_DPCC_OUTPUT_MODE_STAGE1_INCL_G_CENTER; | | | |
>>>>>>>>> + *	| | | | set_use = ... ;                                         | | | |
>>>>>>>>> + *	| | | | ...  = ... ;                                            | | | |
>>>>>>>>> + *	| | | +---------------------------------------------------------+ | | |
>>>>>>>>> + *	| | +-------------------------------------------------------------+ | |
>>>>>>>>> + *	| +-----------------------------------------------------------------+ |
>>>>>>>>> + *	+---------------------------------------------------------------------+
>>>>>>>>> + *
>>>>>>>>> + * @version: The RkISP1 extensible parameters buffer version, see
>>>>>>>>> + *	     :c:type:`rksip1_ext_param_buffer_version`
>>>>>>>>> + * @data_size: The RkISP1 configuration data effective size, excluding this
>>>>>>>>> + *	       header
>>>>>>>>> + * @data: The RkISP1 extensible configuration data blocks
>>>>>>>>> + */
>>>>>>>>> +struct rkisp1_ext_params_cfg {
>>>>>>>>> +	__u32 version;
>>>>>>>>> +	__u32 data_size;
>>>>>>>>> +	__u8 data[RKISP1_EXT_PARAMS_MAX_SIZE];
>>>>>>>>> +};
>>>>>>>>> +
>>>>>>>>>  #endif /* _UAPI_RKISP1_CONFIG_H */
>>>>>
>>>>
>>>
>>