diff mbox series

[v4,3/3] media: rockchip: rkisp1: extend uapi array sizes

Message ID 20210115163829.217131-4-heiko@sntech.de (mailing list archive)
State New, archived
Headers show
Series Fix the rkisp1 userspace API for later IP versions | expand

Commit Message

Heiko Stuebner Jan. 15, 2021, 4:38 p.m. UTC
From: Heiko Stuebner <heiko.stuebner@theobroma-systems.com>

Later variants of the rkisp1 block use more entries in some arrays:

RKISP1_CIF_ISP_AE_MEAN_MAX                 25 -> 81
RKISP1_CIF_ISP_HIST_BIN_N_MAX              16 -> 32
RKISP1_CIF_ISP_GAMMA_OUT_MAX_SAMPLES       17 -> 34
RKISP1_CIF_ISP_HISTOGRAM_WEIGHT_GRIDS_SIZE 28 -> 81

and we can still extend the uapi during the 5.11-rc cycle, so do that
now to be on the safe side.

V10 and V11 only need the smaller sizes, while V12 and V13 needed
the larger sizes.

When adding the bigger sizes make sure, values filled from hardware
values and transmitted to userspace don't leak kernel data by zeroing
them beforehand.

Signed-off-by: Heiko Stuebner <heiko.stuebner@theobroma-systems.com>
Reviewed-by: Ezequiel Garcia <ezequiel@collabora.com>
Reviewed-by: Dafna Hirschfeld <dafna.hirschfeld@collabora.com>
---
 .../platform/rockchip/rkisp1/rkisp1-params.c  |  2 +-
 .../platform/rockchip/rkisp1/rkisp1-stats.c   | 12 +++-
 include/uapi/linux/rkisp1-config.h            | 58 ++++++++++++++++---
 3 files changed, 62 insertions(+), 10 deletions(-)

Comments

Dafna Hirschfeld Jan. 15, 2021, 5:41 p.m. UTC | #1
Am 15.01.21 um 17:38 schrieb Heiko Stuebner:
> From: Heiko Stuebner <heiko.stuebner@theobroma-systems.com>
> 
> Later variants of the rkisp1 block use more entries in some arrays:
> 
> RKISP1_CIF_ISP_AE_MEAN_MAX                 25 -> 81
> RKISP1_CIF_ISP_HIST_BIN_N_MAX              16 -> 32
> RKISP1_CIF_ISP_GAMMA_OUT_MAX_SAMPLES       17 -> 34
> RKISP1_CIF_ISP_HISTOGRAM_WEIGHT_GRIDS_SIZE 28 -> 81

I see you didn't change the value for that define.
The usage of it is a bit more complicated.
It is used in function rkisp1_hst_config.
Actually the real number of weight values are 25 (5x5) for rk3399,
the last 3 are not used. I think that in order to support both
5x5 and 9x9 the code in rkisp1-params.c should change. I'll
send a patch fixing it.

> 
> and we can still extend the uapi during the 5.11-rc cycle, so do that
> now to be on the safe side.
> 
> V10 and V11 only need the smaller sizes, while V12 and V13 needed
> the larger sizes.
> 
> When adding the bigger sizes make sure, values filled from hardware
> values and transmitted to userspace don't leak kernel data by zeroing
> them beforehand.
> 
> Signed-off-by: Heiko Stuebner <heiko.stuebner@theobroma-systems.com>
> Reviewed-by: Ezequiel Garcia <ezequiel@collabora.com>
> Reviewed-by: Dafna Hirschfeld <dafna.hirschfeld@collabora.com>
> ---
>   .../platform/rockchip/rkisp1/rkisp1-params.c  |  2 +-
>   .../platform/rockchip/rkisp1/rkisp1-stats.c   | 12 +++-
>   include/uapi/linux/rkisp1-config.h            | 58 ++++++++++++++++---
>   3 files changed, 62 insertions(+), 10 deletions(-)
> 
> diff --git a/drivers/media/platform/rockchip/rkisp1/rkisp1-params.c b/drivers/media/platform/rockchip/rkisp1/rkisp1-params.c
> index 6af4d551ffb5..fa47fe2a02d0 100644
> --- a/drivers/media/platform/rockchip/rkisp1/rkisp1-params.c
> +++ b/drivers/media/platform/rockchip/rkisp1/rkisp1-params.c
> @@ -391,7 +391,7 @@ static void rkisp1_goc_config(struct rkisp1_params *params,
>   				RKISP1_CIF_ISP_CTRL_ISP_GAMMA_OUT_ENA);
>   	rkisp1_write(params->rkisp1, arg->mode, RKISP1_CIF_ISP_GAMMA_OUT_MODE);
>   
> -	for (i = 0; i < RKISP1_CIF_ISP_GAMMA_OUT_MAX_SAMPLES; i++)
> +	for (i = 0; i < RKISP1_CIF_ISP_GAMMA_OUT_MAX_SAMPLES_V10; i++)
>   		rkisp1_write(params->rkisp1, arg->gamma_y[i],
>   			     RKISP1_CIF_ISP_GAMMA_OUT_Y_0 + i * 4);
>   }
> diff --git a/drivers/media/platform/rockchip/rkisp1/rkisp1-stats.c b/drivers/media/platform/rockchip/rkisp1/rkisp1-stats.c
> index 3ddab8fa8f2d..a26de388ca13 100644
> --- a/drivers/media/platform/rockchip/rkisp1/rkisp1-stats.c
> +++ b/drivers/media/platform/rockchip/rkisp1/rkisp1-stats.c
> @@ -202,8 +202,12 @@ static void rkisp1_stats_get_aec_meas(struct rkisp1_stats *stats,
>   	struct rkisp1_device *rkisp1 = stats->rkisp1;
>   	unsigned int i;
>   
> +	/* the global max can be bigger than the version-specific one */
> +	memset(pbuf->params.ae.exp_mean, 0, RKISP1_CIF_ISP_AE_MEAN_MAX *
> +					    sizeof(*pbuf->params.ae.exp_mean));
> +
>   	pbuf->meas_type |= RKISP1_CIF_ISP_STAT_AUTOEXP;
> -	for (i = 0; i < RKISP1_CIF_ISP_AE_MEAN_MAX; i++)
> +	for (i = 0; i < RKISP1_CIF_ISP_AE_MEAN_MAX_V10; i++)
>   		pbuf->params.ae.exp_mean[i] =
>   			(u8)rkisp1_read(rkisp1,
>   					RKISP1_CIF_ISP_EXP_MEAN_00 + i * 4);
> @@ -232,8 +236,12 @@ static void rkisp1_stats_get_hst_meas(struct rkisp1_stats *stats,
>   	struct rkisp1_device *rkisp1 = stats->rkisp1;
>   	unsigned int i;
>   
> +	/* the global max can be bigger then the version-specific one */
> +	memset(pbuf->params.hist.hist_bins, 0, RKISP1_CIF_ISP_HIST_BIN_N_MAX *
> +					       sizeof(*pbuf->params.hist.hist_bins));
> +
>   	pbuf->meas_type |= RKISP1_CIF_ISP_STAT_HIST;
> -	for (i = 0; i < RKISP1_CIF_ISP_HIST_BIN_N_MAX; i++)
> +	for (i = 0; i < RKISP1_CIF_ISP_HIST_BIN_N_MAX_V10; i++)
>   		pbuf->params.hist.hist_bins[i] =
>   			(u8)rkisp1_read(rkisp1,
>   					RKISP1_CIF_ISP_HIST_BIN_0 + i * 4);
> diff --git a/include/uapi/linux/rkisp1-config.h b/include/uapi/linux/rkisp1-config.h
> index 9fecb6bc457d..e566069275cf 100644
> --- a/include/uapi/linux/rkisp1-config.h
> +++ b/include/uapi/linux/rkisp1-config.h
> @@ -49,8 +49,14 @@
>   #define RKISP1_CIF_ISP_CTK_COEFF_MAX            0x100
>   #define RKISP1_CIF_ISP_CTK_OFFSET_MAX           0x800
>   
> -#define RKISP1_CIF_ISP_AE_MEAN_MAX              25
> -#define RKISP1_CIF_ISP_HIST_BIN_N_MAX           16
> +#define RKISP1_CIF_ISP_AE_MEAN_MAX_V10		25
> +#define RKISP1_CIF_ISP_AE_MEAN_MAX_V12		81
> +#define RKISP1_CIF_ISP_AE_MEAN_MAX		RKISP1_CIF_ISP_AE_MEAN_MAX_V12
> +
> +#define RKISP1_CIF_ISP_HIST_BIN_N_MAX_V10	16
> +#define RKISP1_CIF_ISP_HIST_BIN_N_MAX_V12	32
> +#define RKISP1_CIF_ISP_HIST_BIN_N_MAX		RKISP1_CIF_ISP_HIST_BIN_N_MAX_V12
> +
>   #define RKISP1_CIF_ISP_AFM_MAX_WINDOWS          3
>   #define RKISP1_CIF_ISP_DEGAMMA_CURVE_SIZE       17
>   
> @@ -86,7 +92,9 @@
>    * Gamma out
>    */
>   /* Maximum number of color samples supported */
> -#define RKISP1_CIF_ISP_GAMMA_OUT_MAX_SAMPLES       17
> +#define RKISP1_CIF_ISP_GAMMA_OUT_MAX_SAMPLES_V10   17
> +#define RKISP1_CIF_ISP_GAMMA_OUT_MAX_SAMPLES_V12   34
> +#define RKISP1_CIF_ISP_GAMMA_OUT_MAX_SAMPLES       RKISP1_CIF_ISP_GAMMA_OUT_MAX_SAMPLES_V12
>   
>   /*
>    * Lens shade correction
> @@ -103,7 +111,9 @@
>    * Histogram calculation
>    */
>   /* Last 3 values unused. */
> -#define RKISP1_CIF_ISP_HISTOGRAM_WEIGHT_GRIDS_SIZE 28
> +#define RKISP1_CIF_ISP_HISTOGRAM_WEIGHT_GRIDS_SIZE_V10 28
> +#define RKISP1_CIF_ISP_HISTOGRAM_WEIGHT_GRIDS_SIZE_V12 81
> +#define RKISP1_CIF_ISP_HISTOGRAM_WEIGHT_GRIDS_SIZE     RKISP1_CIF_ISP_HISTOGRAM_WEIGHT_GRIDS_SIZE_V12
>   
>   /*
>    * Defect Pixel Cluster Correction
> @@ -526,6 +536,15 @@ enum rkisp1_cif_isp_goc_mode {
>    *
>    * @mode: goc mode (from enum rkisp1_cif_isp_goc_mode)
>    * @gamma_y: gamma out curve y-axis for all color components
> + *
> + * The number of entries of @gamma_y depends on the hardware revision
> + * as is reported by the hw_revision field of the struct media_device_info
> + * that is returned by ioctl MEDIA_IOC_DEVICE_INFO.
> + *
> + * Versions <= V11 have RKISP1_CIF_ISP_GAMMA_OUT_MAX_SAMPLES_V10
> + * entries, versions >= V12 have RKISP1_CIF_ISP_GAMMA_OUT_MAX_SAMPLES_V12
> + * entries. RKISP1_CIF_ISP_GAMMA_OUT_MAX_SAMPLES is equal to the maximum
> + * of the two.
>    */
>   struct rkisp1_cif_isp_goc_config {
>   	__u32 mode;
> @@ -540,6 +559,15 @@ struct rkisp1_cif_isp_goc_config {
>    *			  skipped
>    * @meas_window: coordinates of the measure window
>    * @hist_weight: weighting factor for sub-windows
> + *
> + * The number of entries of @hist_weight depends on the hardware revision
> + * as is reported by the hw_revision field of the struct media_device_info
> + * that is returned by ioctl MEDIA_IOC_DEVICE_INFO.
> + *
> + * Versions <= V11 have RKISP1_CIF_ISP_HISTOGRAM_WEIGHT_GRIDS_SIZE_V10
> + * entries, versions >= V12 have RKISP1_CIF_ISP_HISTOGRAM_WEIGHT_GRIDS_SIZE_V12
> + * entries. RKISP1_CIF_ISP_HISTOGRAM_WEIGHT_GRIDS_SIZE is equal to the maximum
> + * of the two.
>    */
>   struct rkisp1_cif_isp_hst_config {
>   	__u32 mode;
> @@ -827,7 +855,15 @@ struct rkisp1_cif_isp_bls_meas_val {
>    * @exp_mean: Mean luminance value of block xx
>    * @bls_val:  BLS measured values
>    *
> - * Image is divided into 5x5 blocks.
> + * The number of entries of @exp_mean depends on the hardware revision
> + * as is reported by the hw_revision field of the struct media_device_info
> + * that is returned by ioctl MEDIA_IOC_DEVICE_INFO.
> + *
> + * Versions <= V11 have RKISP1_CIF_ISP_AE_MEAN_MAX_V10 entries,
> + * versions >= V12 have RKISP1_CIF_ISP_AE_MEAN_MAX_V12 entries.
> + * RKISP1_CIF_ISP_AE_MEAN_MAX is equal to the maximum of the two.
> + *
> + * Image is divided into 5x5 blocks on V10 and 9x9 blocks on V12.
>    */
>   struct rkisp1_cif_isp_ae_stat {
>   	__u8 exp_mean[RKISP1_CIF_ISP_AE_MEAN_MAX];
> @@ -862,8 +898,16 @@ struct rkisp1_cif_isp_af_stat {
>    *
>    * @hist_bins: measured bin counters
>    *
> - * Measurement window divided into 16 sub-windows, set
> - * with ISP_HIST_XXX
> + * Measurement window divided into 16 sub-windows for V10/V10
> + * and 32 sub-windows for V12/V13, set with ISP_HIST_XXX

It is actually not windows but histogram bins. Could you change it to:
"The histogram values divided into 16 bins for V10/V11 and 32 bins
for V12/V13. It is configured within the struct rkisp1_cif_isp_hst_config.

Thanks,
Dafna


> + *
> + * The number of entries of @hist_bins depends on the hardware revision
> + * as is reported by the hw_revision field of the struct media_device_info
> + * that is returned by ioctl MEDIA_IOC_DEVICE_INFO.
> + *
> + * Versions <= V11 have RKISP1_CIF_ISP_HIST_BIN_N_MAX_V10 entries,
> + * versions >= V12 have RKISP1_CIF_ISP_HIST_BIN_N_MAX_V12 entries.
> + * RKISP1_CIF_ISP_HIST_BIN_N_MAX is equal to the maximum of the two.
>    */
>   struct rkisp1_cif_isp_hist_stat {
>   	__u16 hist_bins[RKISP1_CIF_ISP_HIST_BIN_N_MAX];
>
Heiko Stuebner Jan. 15, 2021, 11:52 p.m. UTC | #2
Hi Dafna,

Am Freitag, 15. Januar 2021, 18:41:06 CET schrieb Dafna Hirschfeld:
> 
> Am 15.01.21 um 17:38 schrieb Heiko Stuebner:
> > From: Heiko Stuebner <heiko.stuebner@theobroma-systems.com>
> > 
> > Later variants of the rkisp1 block use more entries in some arrays:
> > 
> > RKISP1_CIF_ISP_AE_MEAN_MAX                 25 -> 81
> > RKISP1_CIF_ISP_HIST_BIN_N_MAX              16 -> 32
> > RKISP1_CIF_ISP_GAMMA_OUT_MAX_SAMPLES       17 -> 34
> > RKISP1_CIF_ISP_HISTOGRAM_WEIGHT_GRIDS_SIZE 28 -> 81
> 
> I see you didn't change the value for that define.

In the below patch I find

@@ -103,7 +111,9 @@
* Histogram calculation
*/
/* Last 3 values unused. */
-#define RKISP1_CIF_ISP_HISTOGRAM_WEIGHT_GRIDS_SIZE 28
+#define RKISP1_CIF_ISP_HISTOGRAM_WEIGHT_GRIDS_SIZE_V10 28
+#define RKISP1_CIF_ISP_HISTOGRAM_WEIGHT_GRIDS_SIZE_V12 81
+#define RKISP1_CIF_ISP_HISTOGRAM_WEIGHT_GRIDS_SIZE     RKISP1_CIF_ISP_HISTOGRAM_WEIGHT_GRIDS_SIZE_V12

so I'm not sure I understand what you mean except this.

> The usage of it is a bit more complicated.
> It is used in function rkisp1_hst_config.

Yeah, though the for-loop iterates over 4*7 entry values, so stays
below the RKISP1_CIF_ISP_HISTOGRAM_WEIGHT_GRIDS_SIZE_V10 in all cases.


> Actually the real number of weight values are 25 (5x5) for rk3399,
> the last 3 are not used. I think that in order to support both
> 5x5 and 9x9 the code in rkisp1-params.c should change. I'll
> send a patch fixing it.

If you look at my V12-patch [0] the weight handling is done different there
and from the registers, it looks like they exchanges that part of the isp.

[0] https://lore.kernel.org/linux-media/20210108193311.3423236-11-heiko@sntech.de/
void rkisp1_hst_config_v12() as a search term

[...]

> > @@ -862,8 +898,16 @@ struct rkisp1_cif_isp_af_stat {
> >    *
> >    * @hist_bins: measured bin counters
> >    *
> > - * Measurement window divided into 16 sub-windows, set
> > - * with ISP_HIST_XXX
> > + * Measurement window divided into 16 sub-windows for V10/V10
> > + * and 32 sub-windows for V12/V13, set with ISP_HIST_XXX
> 
> It is actually not windows but histogram bins. Could you change it to:
> "The histogram values divided into 16 bins for V10/V11 and 32 bins
> for V12/V13. It is configured within the struct rkisp1_cif_isp_hst_config.

I've changed this like your suggestions and will give a bit of time for
the stuff above. But I guess I can send a v5 some time tomorrow?


Thanks for your input
Heiko
Dafna Hirschfeld Jan. 16, 2021, 9:05 a.m. UTC | #3
Am 16.01.21 um 00:52 schrieb Heiko Stübner:
> Hi Dafna,
> 
> Am Freitag, 15. Januar 2021, 18:41:06 CET schrieb Dafna Hirschfeld:
>>
>> Am 15.01.21 um 17:38 schrieb Heiko Stuebner:
>>> From: Heiko Stuebner <heiko.stuebner@theobroma-systems.com>
>>>
>>> Later variants of the rkisp1 block use more entries in some arrays:
>>>
>>> RKISP1_CIF_ISP_AE_MEAN_MAX                 25 -> 81
>>> RKISP1_CIF_ISP_HIST_BIN_N_MAX              16 -> 32
>>> RKISP1_CIF_ISP_GAMMA_OUT_MAX_SAMPLES       17 -> 34
>>> RKISP1_CIF_ISP_HISTOGRAM_WEIGHT_GRIDS_SIZE 28 -> 81
>>
>> I see you didn't change the value for that define.
> 
> In the below patch I find
> 
> @@ -103,7 +111,9 @@
> * Histogram calculation
> */
> /* Last 3 values unused. */
> -#define RKISP1_CIF_ISP_HISTOGRAM_WEIGHT_GRIDS_SIZE 28
> +#define RKISP1_CIF_ISP_HISTOGRAM_WEIGHT_GRIDS_SIZE_V10 28
> +#define RKISP1_CIF_ISP_HISTOGRAM_WEIGHT_GRIDS_SIZE_V12 81
> +#define RKISP1_CIF_ISP_HISTOGRAM_WEIGHT_GRIDS_SIZE     RKISP1_CIF_ISP_HISTOGRAM_WEIGHT_GRIDS_SIZE_V12
> 
> so I'm not sure I understand what you mean except this.

Opps, I somehow missed that.
But now since we have 81 entries, it makes no sense to
define it to 28 for V10 and documenting "Last 3 values unused" (see just above the definition).
We can set it just to 25, we have 56 (81-25) unused values anyway.

> 
>> The usage of it is a bit more complicated.
>> It is used in function rkisp1_hst_config.
> 
> Yeah, though the for-loop iterates over 4*7 entry values, so stays
> below the RKISP1_CIF_ISP_HISTOGRAM_WEIGHT_GRIDS_SIZE_V10 in all cases.
> 
> 
>> Actually the real number of weight values are 25 (5x5) for rk3399,
>> the last 3 are not used. I think that in order to support both
>> 5x5 and 9x9 the code in rkisp1-params.c should change. I'll
>> send a patch fixing it.
> 
> If you look at my V12-patch [0] the weight handling is done different there
> and from the registers, it looks like they exchanges that part of the isp.
> 
> [0] https://lore.kernel.org/linux-media/20210108193311.3423236-11-heiko@sntech.de/
> void rkisp1_hst_config_v12() as a search term
> 
> [...]

Right, there is no need to change the relevant code in rkisp1-param.c when setting the
RKISP1_CIF_ISP_HISTOGRAM_WEIGHT_GRIDS_SIZE to 25.

Thanks,
Dafna

> 
>>> @@ -862,8 +898,16 @@ struct rkisp1_cif_isp_af_stat {
>>>     *
>>>     * @hist_bins: measured bin counters
>>>     *
>>> - * Measurement window divided into 16 sub-windows, set
>>> - * with ISP_HIST_XXX
>>> + * Measurement window divided into 16 sub-windows for V10/V10
>>> + * and 32 sub-windows for V12/V13, set with ISP_HIST_XXX
>>
>> It is actually not windows but histogram bins. Could you change it to:
>> "The histogram values divided into 16 bins for V10/V11 and 32 bins
>> for V12/V13. It is configured within the struct rkisp1_cif_isp_hst_config.
> 
> I've changed this like your suggestions and will give a bit of time for
> the stuff above. But I guess I can send a v5 some time tomorrow?
> 
> 
> Thanks for your input
> Heiko
> 
>
Heiko Stuebner Jan. 16, 2021, 11:57 a.m. UTC | #4
Hi Dafna,

Am Samstag, 16. Januar 2021, 10:05:39 CET schrieb Dafna Hirschfeld:
> Am 16.01.21 um 00:52 schrieb Heiko Stübner:
> > Am Freitag, 15. Januar 2021, 18:41:06 CET schrieb Dafna Hirschfeld:
> >> Am 15.01.21 um 17:38 schrieb Heiko Stuebner:
> >>> From: Heiko Stuebner <heiko.stuebner@theobroma-systems.com>
> >>>
> >>> Later variants of the rkisp1 block use more entries in some arrays:
> >>>
> >>> RKISP1_CIF_ISP_AE_MEAN_MAX                 25 -> 81
> >>> RKISP1_CIF_ISP_HIST_BIN_N_MAX              16 -> 32
> >>> RKISP1_CIF_ISP_GAMMA_OUT_MAX_SAMPLES       17 -> 34
> >>> RKISP1_CIF_ISP_HISTOGRAM_WEIGHT_GRIDS_SIZE 28 -> 81
> >>
> >> I see you didn't change the value for that define.
> > 
> > In the below patch I find
> > 
> > @@ -103,7 +111,9 @@
> > * Histogram calculation
> > */
> > /* Last 3 values unused. */
> > -#define RKISP1_CIF_ISP_HISTOGRAM_WEIGHT_GRIDS_SIZE 28
> > +#define RKISP1_CIF_ISP_HISTOGRAM_WEIGHT_GRIDS_SIZE_V10 28
> > +#define RKISP1_CIF_ISP_HISTOGRAM_WEIGHT_GRIDS_SIZE_V12 81
> > +#define RKISP1_CIF_ISP_HISTOGRAM_WEIGHT_GRIDS_SIZE     RKISP1_CIF_ISP_HISTOGRAM_WEIGHT_GRIDS_SIZE_V12
> > 
> > so I'm not sure I understand what you mean except this.
> 
> Opps, I somehow missed that.
> But now since we have 81 entries, it makes no sense to
> define it to 28 for V10 and documenting "Last 3 values unused" (see just above the definition).
> We can set it just to 25, we have 56 (81-25) unused values anyway.

The rkisp1_hst_config() function iterates over its regs-array and accesses
4 weight values in each step and writing them to the register:

static const u32 hist_weight_regs[] = {
	RKISP1_CIF_ISP_HIST_WEIGHT_00TO30_V10, ... weight0-3
	RKISP1_CIF_ISP_HIST_WEIGHT_40TO21_V10, ... weight4-7
	RKISP1_CIF_ISP_HIST_WEIGHT_31TO12_V10, ... weight8-11
	RKISP1_CIF_ISP_HIST_WEIGHT_22TO03_V10, ... weight12-15
	RKISP1_CIF_ISP_HIST_WEIGHT_13TO43_V10, ... weight16-19
	RKISP1_CIF_ISP_HIST_WEIGHT_04TO34_V10, ... weight20-23
	RKISP1_CIF_ISP_HIST_WEIGHT_44_V10, ... weight24-27
};

and yes the last step only uses 1 value to write to the register.
But I guess if we really want to reduce the max value, we should move
that last part into a separate write, so that we don't access parts we claim
to not access ;-)

> >> The usage of it is a bit more complicated.
> >> It is used in function rkisp1_hst_config.
> > 
> > Yeah, though the for-loop iterates over 4*7 entry values, so stays
> > below the RKISP1_CIF_ISP_HISTOGRAM_WEIGHT_GRIDS_SIZE_V10 in all cases.
> > 
> > 
> >> Actually the real number of weight values are 25 (5x5) for rk3399,
> >> the last 3 are not used. I think that in order to support both
> >> 5x5 and 9x9 the code in rkisp1-params.c should change. I'll
> >> send a patch fixing it.
> > 
> > If you look at my V12-patch [0] the weight handling is done different there
> > and from the registers, it looks like they exchanges that part of the isp.
> > 
> > [0] https://lore.kernel.org/linux-media/20210108193311.3423236-11-heiko@sntech.de/
> > void rkisp1_hst_config_v12() as a search term
> > 
> > [...]
> 
> Right, there is no need to change the relevant code in rkisp1-param.c when setting the
> RKISP1_CIF_ISP_HISTOGRAM_WEIGHT_GRIDS_SIZE to 25.

ok, should we add a 4th patch fixing that and moving the last write out of the loop?


Heiko

> >>> @@ -862,8 +898,16 @@ struct rkisp1_cif_isp_af_stat {
> >>>     *
> >>>     * @hist_bins: measured bin counters
> >>>     *
> >>> - * Measurement window divided into 16 sub-windows, set
> >>> - * with ISP_HIST_XXX
> >>> + * Measurement window divided into 16 sub-windows for V10/V10
> >>> + * and 32 sub-windows for V12/V13, set with ISP_HIST_XXX
> >>
> >> It is actually not windows but histogram bins. Could you change it to:
> >> "The histogram values divided into 16 bins for V10/V11 and 32 bins
> >> for V12/V13. It is configured within the struct rkisp1_cif_isp_hst_config.
> > 
> > I've changed this like your suggestions and will give a bit of time for
> > the stuff above. But I guess I can send a v5 some time tomorrow?
> > 
> > 
> > Thanks for your input
> > Heiko
> > 
> > 
>
Dafna Hirschfeld Jan. 16, 2021, 1:34 p.m. UTC | #5
Am 16.01.21 um 12:57 schrieb Heiko Stübner:
> Hi Dafna,
> 
> Am Samstag, 16. Januar 2021, 10:05:39 CET schrieb Dafna Hirschfeld:
>> Am 16.01.21 um 00:52 schrieb Heiko Stübner:
>>> Am Freitag, 15. Januar 2021, 18:41:06 CET schrieb Dafna Hirschfeld:
>>>> Am 15.01.21 um 17:38 schrieb Heiko Stuebner:
>>>>> From: Heiko Stuebner <heiko.stuebner@theobroma-systems.com>
>>>>>
>>>>> Later variants of the rkisp1 block use more entries in some arrays:
>>>>>
>>>>> RKISP1_CIF_ISP_AE_MEAN_MAX                 25 -> 81
>>>>> RKISP1_CIF_ISP_HIST_BIN_N_MAX              16 -> 32
>>>>> RKISP1_CIF_ISP_GAMMA_OUT_MAX_SAMPLES       17 -> 34
>>>>> RKISP1_CIF_ISP_HISTOGRAM_WEIGHT_GRIDS_SIZE 28 -> 81
>>>>
>>>> I see you didn't change the value for that define.
>>>
>>> In the below patch I find
>>>
>>> @@ -103,7 +111,9 @@
>>> * Histogram calculation
>>> */
>>> /* Last 3 values unused. */
>>> -#define RKISP1_CIF_ISP_HISTOGRAM_WEIGHT_GRIDS_SIZE 28
>>> +#define RKISP1_CIF_ISP_HISTOGRAM_WEIGHT_GRIDS_SIZE_V10 28
>>> +#define RKISP1_CIF_ISP_HISTOGRAM_WEIGHT_GRIDS_SIZE_V12 81
>>> +#define RKISP1_CIF_ISP_HISTOGRAM_WEIGHT_GRIDS_SIZE     RKISP1_CIF_ISP_HISTOGRAM_WEIGHT_GRIDS_SIZE_V12
>>>
>>> so I'm not sure I understand what you mean except this.
>>
>> Opps, I somehow missed that.
>> But now since we have 81 entries, it makes no sense to
>> define it to 28 for V10 and documenting "Last 3 values unused" (see just above the definition).
>> We can set it just to 25, we have 56 (81-25) unused values anyway.
> 
> The rkisp1_hst_config() function iterates over its regs-array and accesses
> 4 weight values in each step and writing them to the register:
> 
> static const u32 hist_weight_regs[] = {
> 	RKISP1_CIF_ISP_HIST_WEIGHT_00TO30_V10, ... weight0-3
> 	RKISP1_CIF_ISP_HIST_WEIGHT_40TO21_V10, ... weight4-7
> 	RKISP1_CIF_ISP_HIST_WEIGHT_31TO12_V10, ... weight8-11
> 	RKISP1_CIF_ISP_HIST_WEIGHT_22TO03_V10, ... weight12-15
> 	RKISP1_CIF_ISP_HIST_WEIGHT_13TO43_V10, ... weight16-19
> 	RKISP1_CIF_ISP_HIST_WEIGHT_04TO34_V10, ... weight20-23
> 	RKISP1_CIF_ISP_HIST_WEIGHT_44_V10, ... weight24-27
> };
> 
> and yes the last step only uses 1 value to write to the register.
> But I guess if we really want to reduce the max value, we should move
> that last part into a separate write, so that we don't access parts we claim
> to not access ;-)
> 
>>>> The usage of it is a bit more complicated.
>>>> It is used in function rkisp1_hst_config.
>>>
>>> Yeah, though the for-loop iterates over 4*7 entry values, so stays
>>> below the RKISP1_CIF_ISP_HISTOGRAM_WEIGHT_GRIDS_SIZE_V10 in all cases.
>>>
>>>
>>>> Actually the real number of weight values are 25 (5x5) for rk3399,
>>>> the last 3 are not used. I think that in order to support both
>>>> 5x5 and 9x9 the code in rkisp1-params.c should change. I'll
>>>> send a patch fixing it.
>>>
>>> If you look at my V12-patch [0] the weight handling is done different there
>>> and from the registers, it looks like they exchanges that part of the isp.
>>>
>>> [0] https://lore.kernel.org/linux-media/20210108193311.3423236-11-heiko@sntech.de/
>>> void rkisp1_hst_config_v12() as a search term
>>>
>>> [...]
>>
>> Right, there is no need to change the relevant code in rkisp1-param.c when setting the
>> RKISP1_CIF_ISP_HISTOGRAM_WEIGHT_GRIDS_SIZE to 25.
> 
> ok, should we add a 4th patch fixing that and moving the last write out of the loop?

I think changing the related code in the rkisp1-params.c can be done later in a separate patch.
I think you can change it to 25 in the same patch that adds V12 support and write in the commit message
that because the array size is now 81, there is no point defining the grid size for V10 to 28
and in addition documenting that the last 3 values are not used.

Thanks,
Dafna

> 
> 
> Heiko
> 
>>>>> @@ -862,8 +898,16 @@ struct rkisp1_cif_isp_af_stat {
>>>>>      *
>>>>>      * @hist_bins: measured bin counters
>>>>>      *
>>>>> - * Measurement window divided into 16 sub-windows, set
>>>>> - * with ISP_HIST_XXX
>>>>> + * Measurement window divided into 16 sub-windows for V10/V10
>>>>> + * and 32 sub-windows for V12/V13, set with ISP_HIST_XXX
>>>>
>>>> It is actually not windows but histogram bins. Could you change it to:
>>>> "The histogram values divided into 16 bins for V10/V11 and 32 bins
>>>> for V12/V13. It is configured within the struct rkisp1_cif_isp_hst_config.
>>>
>>> I've changed this like your suggestions and will give a bit of time for
>>> the stuff above. But I guess I can send a v5 some time tomorrow?
>>>
>>>
>>> Thanks for your input
>>> Heiko
>>>
>>>
>>
> 
> 
> 
>
diff mbox series

Patch

diff --git a/drivers/media/platform/rockchip/rkisp1/rkisp1-params.c b/drivers/media/platform/rockchip/rkisp1/rkisp1-params.c
index 6af4d551ffb5..fa47fe2a02d0 100644
--- a/drivers/media/platform/rockchip/rkisp1/rkisp1-params.c
+++ b/drivers/media/platform/rockchip/rkisp1/rkisp1-params.c
@@ -391,7 +391,7 @@  static void rkisp1_goc_config(struct rkisp1_params *params,
 				RKISP1_CIF_ISP_CTRL_ISP_GAMMA_OUT_ENA);
 	rkisp1_write(params->rkisp1, arg->mode, RKISP1_CIF_ISP_GAMMA_OUT_MODE);
 
-	for (i = 0; i < RKISP1_CIF_ISP_GAMMA_OUT_MAX_SAMPLES; i++)
+	for (i = 0; i < RKISP1_CIF_ISP_GAMMA_OUT_MAX_SAMPLES_V10; i++)
 		rkisp1_write(params->rkisp1, arg->gamma_y[i],
 			     RKISP1_CIF_ISP_GAMMA_OUT_Y_0 + i * 4);
 }
diff --git a/drivers/media/platform/rockchip/rkisp1/rkisp1-stats.c b/drivers/media/platform/rockchip/rkisp1/rkisp1-stats.c
index 3ddab8fa8f2d..a26de388ca13 100644
--- a/drivers/media/platform/rockchip/rkisp1/rkisp1-stats.c
+++ b/drivers/media/platform/rockchip/rkisp1/rkisp1-stats.c
@@ -202,8 +202,12 @@  static void rkisp1_stats_get_aec_meas(struct rkisp1_stats *stats,
 	struct rkisp1_device *rkisp1 = stats->rkisp1;
 	unsigned int i;
 
+	/* the global max can be bigger than the version-specific one */
+	memset(pbuf->params.ae.exp_mean, 0, RKISP1_CIF_ISP_AE_MEAN_MAX *
+					    sizeof(*pbuf->params.ae.exp_mean));
+
 	pbuf->meas_type |= RKISP1_CIF_ISP_STAT_AUTOEXP;
-	for (i = 0; i < RKISP1_CIF_ISP_AE_MEAN_MAX; i++)
+	for (i = 0; i < RKISP1_CIF_ISP_AE_MEAN_MAX_V10; i++)
 		pbuf->params.ae.exp_mean[i] =
 			(u8)rkisp1_read(rkisp1,
 					RKISP1_CIF_ISP_EXP_MEAN_00 + i * 4);
@@ -232,8 +236,12 @@  static void rkisp1_stats_get_hst_meas(struct rkisp1_stats *stats,
 	struct rkisp1_device *rkisp1 = stats->rkisp1;
 	unsigned int i;
 
+	/* the global max can be bigger then the version-specific one */
+	memset(pbuf->params.hist.hist_bins, 0, RKISP1_CIF_ISP_HIST_BIN_N_MAX *
+					       sizeof(*pbuf->params.hist.hist_bins));
+
 	pbuf->meas_type |= RKISP1_CIF_ISP_STAT_HIST;
-	for (i = 0; i < RKISP1_CIF_ISP_HIST_BIN_N_MAX; i++)
+	for (i = 0; i < RKISP1_CIF_ISP_HIST_BIN_N_MAX_V10; i++)
 		pbuf->params.hist.hist_bins[i] =
 			(u8)rkisp1_read(rkisp1,
 					RKISP1_CIF_ISP_HIST_BIN_0 + i * 4);
diff --git a/include/uapi/linux/rkisp1-config.h b/include/uapi/linux/rkisp1-config.h
index 9fecb6bc457d..e566069275cf 100644
--- a/include/uapi/linux/rkisp1-config.h
+++ b/include/uapi/linux/rkisp1-config.h
@@ -49,8 +49,14 @@ 
 #define RKISP1_CIF_ISP_CTK_COEFF_MAX            0x100
 #define RKISP1_CIF_ISP_CTK_OFFSET_MAX           0x800
 
-#define RKISP1_CIF_ISP_AE_MEAN_MAX              25
-#define RKISP1_CIF_ISP_HIST_BIN_N_MAX           16
+#define RKISP1_CIF_ISP_AE_MEAN_MAX_V10		25
+#define RKISP1_CIF_ISP_AE_MEAN_MAX_V12		81
+#define RKISP1_CIF_ISP_AE_MEAN_MAX		RKISP1_CIF_ISP_AE_MEAN_MAX_V12
+
+#define RKISP1_CIF_ISP_HIST_BIN_N_MAX_V10	16
+#define RKISP1_CIF_ISP_HIST_BIN_N_MAX_V12	32
+#define RKISP1_CIF_ISP_HIST_BIN_N_MAX		RKISP1_CIF_ISP_HIST_BIN_N_MAX_V12
+
 #define RKISP1_CIF_ISP_AFM_MAX_WINDOWS          3
 #define RKISP1_CIF_ISP_DEGAMMA_CURVE_SIZE       17
 
@@ -86,7 +92,9 @@ 
  * Gamma out
  */
 /* Maximum number of color samples supported */
-#define RKISP1_CIF_ISP_GAMMA_OUT_MAX_SAMPLES       17
+#define RKISP1_CIF_ISP_GAMMA_OUT_MAX_SAMPLES_V10   17
+#define RKISP1_CIF_ISP_GAMMA_OUT_MAX_SAMPLES_V12   34
+#define RKISP1_CIF_ISP_GAMMA_OUT_MAX_SAMPLES       RKISP1_CIF_ISP_GAMMA_OUT_MAX_SAMPLES_V12
 
 /*
  * Lens shade correction
@@ -103,7 +111,9 @@ 
  * Histogram calculation
  */
 /* Last 3 values unused. */
-#define RKISP1_CIF_ISP_HISTOGRAM_WEIGHT_GRIDS_SIZE 28
+#define RKISP1_CIF_ISP_HISTOGRAM_WEIGHT_GRIDS_SIZE_V10 28
+#define RKISP1_CIF_ISP_HISTOGRAM_WEIGHT_GRIDS_SIZE_V12 81
+#define RKISP1_CIF_ISP_HISTOGRAM_WEIGHT_GRIDS_SIZE     RKISP1_CIF_ISP_HISTOGRAM_WEIGHT_GRIDS_SIZE_V12
 
 /*
  * Defect Pixel Cluster Correction
@@ -526,6 +536,15 @@  enum rkisp1_cif_isp_goc_mode {
  *
  * @mode: goc mode (from enum rkisp1_cif_isp_goc_mode)
  * @gamma_y: gamma out curve y-axis for all color components
+ *
+ * The number of entries of @gamma_y depends on the hardware revision
+ * as is reported by the hw_revision field of the struct media_device_info
+ * that is returned by ioctl MEDIA_IOC_DEVICE_INFO.
+ *
+ * Versions <= V11 have RKISP1_CIF_ISP_GAMMA_OUT_MAX_SAMPLES_V10
+ * entries, versions >= V12 have RKISP1_CIF_ISP_GAMMA_OUT_MAX_SAMPLES_V12
+ * entries. RKISP1_CIF_ISP_GAMMA_OUT_MAX_SAMPLES is equal to the maximum
+ * of the two.
  */
 struct rkisp1_cif_isp_goc_config {
 	__u32 mode;
@@ -540,6 +559,15 @@  struct rkisp1_cif_isp_goc_config {
  *			  skipped
  * @meas_window: coordinates of the measure window
  * @hist_weight: weighting factor for sub-windows
+ *
+ * The number of entries of @hist_weight depends on the hardware revision
+ * as is reported by the hw_revision field of the struct media_device_info
+ * that is returned by ioctl MEDIA_IOC_DEVICE_INFO.
+ *
+ * Versions <= V11 have RKISP1_CIF_ISP_HISTOGRAM_WEIGHT_GRIDS_SIZE_V10
+ * entries, versions >= V12 have RKISP1_CIF_ISP_HISTOGRAM_WEIGHT_GRIDS_SIZE_V12
+ * entries. RKISP1_CIF_ISP_HISTOGRAM_WEIGHT_GRIDS_SIZE is equal to the maximum
+ * of the two.
  */
 struct rkisp1_cif_isp_hst_config {
 	__u32 mode;
@@ -827,7 +855,15 @@  struct rkisp1_cif_isp_bls_meas_val {
  * @exp_mean: Mean luminance value of block xx
  * @bls_val:  BLS measured values
  *
- * Image is divided into 5x5 blocks.
+ * The number of entries of @exp_mean depends on the hardware revision
+ * as is reported by the hw_revision field of the struct media_device_info
+ * that is returned by ioctl MEDIA_IOC_DEVICE_INFO.
+ *
+ * Versions <= V11 have RKISP1_CIF_ISP_AE_MEAN_MAX_V10 entries,
+ * versions >= V12 have RKISP1_CIF_ISP_AE_MEAN_MAX_V12 entries.
+ * RKISP1_CIF_ISP_AE_MEAN_MAX is equal to the maximum of the two.
+ *
+ * Image is divided into 5x5 blocks on V10 and 9x9 blocks on V12.
  */
 struct rkisp1_cif_isp_ae_stat {
 	__u8 exp_mean[RKISP1_CIF_ISP_AE_MEAN_MAX];
@@ -862,8 +898,16 @@  struct rkisp1_cif_isp_af_stat {
  *
  * @hist_bins: measured bin counters
  *
- * Measurement window divided into 16 sub-windows, set
- * with ISP_HIST_XXX
+ * Measurement window divided into 16 sub-windows for V10/V10
+ * and 32 sub-windows for V12/V13, set with ISP_HIST_XXX
+ *
+ * The number of entries of @hist_bins depends on the hardware revision
+ * as is reported by the hw_revision field of the struct media_device_info
+ * that is returned by ioctl MEDIA_IOC_DEVICE_INFO.
+ *
+ * Versions <= V11 have RKISP1_CIF_ISP_HIST_BIN_N_MAX_V10 entries,
+ * versions >= V12 have RKISP1_CIF_ISP_HIST_BIN_N_MAX_V12 entries.
+ * RKISP1_CIF_ISP_HIST_BIN_N_MAX is equal to the maximum of the two.
  */
 struct rkisp1_cif_isp_hist_stat {
 	__u16 hist_bins[RKISP1_CIF_ISP_HIST_BIN_N_MAX];