Yes I agree that this data parsed from EDID/Display ID should be stored in 
structs defined in drm_display_info.
Like for the VRR range that we parse from EDID, we store that in a struct 
monitor_range in drm_display_info.

Manasi

-----Original Message-----
From: dri-devel <dri-devel-boun...@lists.freedesktop.org> On Behalf Of Jani 
Nikula
Sent: Tuesday, April 26, 2022 6:38 AM
To: Hogander, Jouni <jouni.hogan...@intel.com>; dri-devel@lists.freedesktop.org
Cc: Hogander, Jouni <jouni.hogan...@intel.com>; Rodrigo Siqueira 
<rodrigo.sique...@amd.com>; Kahola, Mika <mika.kah...@intel.com>
Subject: Re: [PATCH 1/3] drm: New function to get luminance range based on 
static hdr metadata

On Tue, 26 Apr 2022, Jouni Högander <jouni.hogan...@intel.com> wrote:
> Split luminance min/max calculation using static hdr metadata from 
> drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c:update_connector_ext
> _caps
> into drm/drm_edid.c.

IMO all of this should be computed at EDID parsing time once and stored in the 
metadata. Maybe in drm_parse_hdr_metadata_block().

Over time we've added a bunch of functions to do this type of stuff, and all 
drivers call them at slightly different times and different ways, and it just 
grows complicated.

(Also, I think basically everything that comes out of the EDID or DisplayID 
should be stored in connector->display_info instead of being spread around like 
we currently do. But that's for another patch series, another time.)

BR,
Jani.

>
> Cc: Rodrigo Siqueira <rodrigo.sique...@amd.com>
> Cc: Harry Wentland <harry.wentl...@amd.com>
> Cc: Lyude Paul <ly...@redhat.com>
> Cc: Mika Kahola <mika.kah...@intel.com>
> Cc: Jani Nikula <jani.nik...@intel.com>
> Signed-off-by: Jouni Högander <jouni.hogan...@intel.com>
> ---
>  drivers/gpu/drm/drm_edid.c | 55 ++++++++++++++++++++++++++++++++++++++
>  include/drm/drm_edid.h     |  4 +++
>  2 files changed, 59 insertions(+)
>
> diff --git a/drivers/gpu/drm/drm_edid.c b/drivers/gpu/drm/drm_edid.c 
> index 7a8482b75071..1cb886debbbe 100644
> --- a/drivers/gpu/drm/drm_edid.c
> +++ b/drivers/gpu/drm/drm_edid.c
> @@ -4005,6 +4005,61 @@ drm_display_mode_from_cea_vic(struct drm_device 
> *dev,  }  EXPORT_SYMBOL(drm_display_mode_from_cea_vic);
>  
> +/**
> + * drm_luminance_range_from_static_hdr_metadata() - luminance range 
> +from static hdr
> + * metadata
> + * @connector: connector we're calculating for
> + * @min: Calculated min value
> + * @max: Calculated max value
> + *
> + * Calculates backlight min and max as described in CTA-861-G
> + *
> + * Returns: True when calculation succeeds.
> + */
> +bool
> +drm_luminance_range_from_static_hdr_metadata(struct drm_connector *connector,
> +                                          u32 *min, u32 *max)
> +{
> +     struct hdr_sink_metadata *hdr_metadata = &connector->hdr_sink_metadata;
> +     static const u8 pre_computed_values[] = {
> +             50, 51, 52, 53, 55, 56, 57, 58, 59, 61, 62, 63, 65, 66, 68, 69,
> +             71, 72, 74, 75, 77, 79, 81, 82, 84, 86, 88, 90, 92, 94, 96, 98};
> +     u32 min_cll, max_cll, q, r;
> +
> +     if (!(hdr_metadata->hdmi_type1.metadata_type &
> +           BIT(HDMI_STATIC_METADATA_TYPE1)))
> +             return false;
> +
> +     max_cll = hdr_metadata->hdmi_type1.max_cll;
> +     min_cll = hdr_metadata->hdmi_type1.min_cll;
> +
> +     /* From the specification (CTA-861-G), for calculating the maximum
> +      * luminance we need to use:
> +      *      Luminance = 50*2**(CV/32)
> +      * Where CV is a one-byte value.
> +      * For calculating this expression we may need float point precision;
> +      * to avoid this complexity level, we take advantage that CV is divided
> +      * by a constant. From the Euclids division algorithm, we know that CV
> +      * can be written as: CV = 32*q + r. Next, we replace CV in the
> +      * Luminance expression and get 50*(2**q)*(2**(r/32)), hence we just
> +      * need to pre-compute the value of r/32. For pre-computing the values
> +      * We just used the following Ruby line:
> +      *      (0...32).each {|cv| puts (50*2**(cv/32.0)).round}
> +      * The results of the above expressions can be verified at
> +      * pre_computed_values.
> +      */
> +     q = max_cll >> 5;
> +     r = max_cll % 32;
> +     *max = (1 << q) * pre_computed_values[r];
> +
> +     /* min luminance: maxLum * (CV/255)^2 / 100 */
> +     q = DIV_ROUND_CLOSEST(min_cll, 255);
> +     *min = *max * DIV_ROUND_CLOSEST((q * q), 100);
> +
> +     return true;
> +}
> +EXPORT_SYMBOL(drm_luminance_range_from_static_hdr_metadata);
> +
>  static int
>  do_cea_modes(struct drm_connector *connector, const u8 *db, u8 len)  
> { diff --git a/include/drm/drm_edid.h b/include/drm/drm_edid.h index 
> c3204a58fb09..63e441c84d72 100644
> --- a/include/drm/drm_edid.h
> +++ b/include/drm/drm_edid.h
> @@ -406,6 +406,10 @@ drm_hdmi_avi_infoframe_quant_range(struct 
> hdmi_avi_infoframe *frame,
>                                  const struct drm_display_mode *mode,
>                                  enum hdmi_quantization_range 
> rgb_quant_range);
>  
> +bool
> +drm_luminance_range_from_static_hdr_metadata(struct drm_connector *connector,
> +                                          u32 *min, u32 *max);
> +
>  /**
>   * drm_eld_mnl - Get ELD monitor name length in bytes.
>   * @eld: pointer to an eld memory structure with mnl set

--
Jani Nikula, Intel Open Source Graphics Center

Reply via email to