Commit d7787cc0 authored by Lyude Paul's avatar Lyude Paul Committed by Ben Skeggs

drm/nouveau/kms/nv50-: Fix clock checking algorithm in nv50_dp_mode_valid()

While I thought I had this correct (since it actually did reject modes
like I expected during testing), Ville Syrjala from Intel pointed out
that the logic here isn't correct. max_clock refers to the max data rate
supported by the DP encoder. So, limiting it to the output of ds_clock (which
refers to the maximum dotclock of the downstream DP device) doesn't make any
sense. Additionally, since we're using the connector's bpc as the canonical BPC
we should use this in mode_valid until we support dynamically setting the bpp
based on bandwidth constraints.

https://lists.freedesktop.org/archives/dri-devel/2020-September/280276.html

For more info.

So, let's rewrite this using Ville's advice.

v2:
* Ville pointed out I mixed up the dotclock and the link rate. So fix that...
* ...and also rename all the variables in this function to be more appropriately
  labeled so I stop mixing them up.
* Reuse the bpp from the connector for now until we have dynamic bpp selection.
* Use use DIV_ROUND_UP for calculating the mode rate like i915 does, which we
  should also have been doing from the start
Signed-off-by: default avatarLyude Paul <lyude@redhat.com>
Fixes: 409d3813 ("drm/nouveau/kms/nv50-: Use downstream DP clock limits for mode validation")
Cc: Ville Syrjälä <ville.syrjala@linux.intel.com>
Cc: Lyude Paul <lyude@redhat.com>
Cc: Ben Skeggs <bskeggs@redhat.com>
Signed-off-by: default avatarBen Skeggs <bskeggs@redhat.com>
parent 2d831155
...@@ -231,8 +231,9 @@ nv50_dp_mode_valid(struct drm_connector *connector, ...@@ -231,8 +231,9 @@ nv50_dp_mode_valid(struct drm_connector *connector,
const struct drm_display_mode *mode, const struct drm_display_mode *mode,
unsigned *out_clock) unsigned *out_clock)
{ {
const unsigned min_clock = 25000; const unsigned int min_clock = 25000;
unsigned max_clock, ds_clock, clock = mode->clock; unsigned int max_rate, mode_rate, ds_max_dotclock, clock = mode->clock;
const u8 bpp = connector->display_info.bpc * 3;
if (mode->flags & DRM_MODE_FLAG_INTERLACE && !outp->caps.dp_interlace) if (mode->flags & DRM_MODE_FLAG_INTERLACE && !outp->caps.dp_interlace)
return MODE_NO_INTERLACE; return MODE_NO_INTERLACE;
...@@ -240,17 +241,17 @@ nv50_dp_mode_valid(struct drm_connector *connector, ...@@ -240,17 +241,17 @@ nv50_dp_mode_valid(struct drm_connector *connector,
if ((mode->flags & DRM_MODE_FLAG_3D_MASK) == DRM_MODE_FLAG_3D_FRAME_PACKING) if ((mode->flags & DRM_MODE_FLAG_3D_MASK) == DRM_MODE_FLAG_3D_FRAME_PACKING)
clock *= 2; clock *= 2;
max_clock = outp->dp.link_nr * outp->dp.link_bw; max_rate = outp->dp.link_nr * outp->dp.link_bw;
ds_clock = drm_dp_downstream_max_dotclock(outp->dp.dpcd, mode_rate = DIV_ROUND_UP(clock * bpp, 8);
outp->dp.downstream_ports); if (mode_rate > max_rate)
if (ds_clock) return MODE_CLOCK_HIGH;
max_clock = min(max_clock, ds_clock);
ds_max_dotclock = drm_dp_downstream_max_dotclock(outp->dp.dpcd, outp->dp.downstream_ports);
if (ds_max_dotclock && clock > ds_max_dotclock)
return MODE_CLOCK_HIGH;
clock = mode->clock * (connector->display_info.bpc * 3) / 10;
if (clock < min_clock) if (clock < min_clock)
return MODE_CLOCK_LOW; return MODE_CLOCK_LOW;
if (clock > max_clock)
return MODE_CLOCK_HIGH;
if (out_clock) if (out_clock)
*out_clock = clock; *out_clock = clock;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment