Skip to contentSkip to conversation

FAILED: patch "[PATCH] drm/nouveau/kms/nv50-: Get rid of bogus" failed to apply to 5.9-stable tree

PATCH In review [email protected] 2 participants 6 messages Nov 5, 2020 – Nov 7, 2020

Subsystems (4)
lore
Share & tools
lore

[email protected]

author maintainer
#0 lore raw

The patch below does not apply to the 5.9-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.

thanks,

greg k-h

------------------ original commit in Linus's tree ------------------

From 2d831155cf0607566e43d8465da33774b2dc7221 Mon Sep 17 00:00:00 2001
From: Lyude Paul <[email protected]>
Date: Tue, 29 Sep 2020 18:31:31 -0400
Subject: [PATCH] drm/nouveau/kms/nv50-: Get rid of bogus
nouveau_conn_mode_valid()
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Ville also pointed out that I got a lot of the logic here wrong as well, whoops. While I don't think anyone's likely using 3D output with nouveau, the next patch will make nouveau_conn_mode_valid() make a lot less sense. So, let's just get rid of it and open-code it like before, while taking care to move the 3D frame packing calculations on the dot clock into the right place.

Fixes d6a9efece724 ("drm/nouveau/kms/nv50-: Share DP SST mode_valid() handling with MST")
Cc Ville Syrjälä <[email protected]>
Cc <[email protected]> # v5.8+
drivers/gpu/drm/nouveau/nouveau_connector.c +10 -26
index 49dd0cbc332f..6f21f36719fc 100644
@@ -1023,29 +1023,6 @@ get_tmds_link_bandwidth(struct drm_connector *connector)
 		return 112000 * duallink_scale;
 }
 
-enum drm_mode_status
-nouveau_conn_mode_clock_valid(const struct drm_display_mode *mode,
-			      const unsigned min_clock,
-			      const unsigned max_clock,
-			      unsigned int *clock_out)
-{
-	unsigned int clock = mode->clock;
-
-	if ((mode->flags & DRM_MODE_FLAG_3D_MASK) ==
-	    DRM_MODE_FLAG_3D_FRAME_PACKING)
-		clock *= 2;
-
-	if (clock < min_clock)
-		return MODE_CLOCK_LOW;
-	if (clock > max_clock)
-		return MODE_CLOCK_HIGH;
-
-	if (clock_out)
-		*clock_out = clock;
-
-	return MODE_OK;
-}
-
 static enum drm_mode_status
 nouveau_connector_mode_valid(struct drm_connector *connector,
 			     struct drm_display_mode *mode)
@@ -1053,7 +1030,7 @@ nouveau_connector_mode_valid(struct drm_connector *connector,
 	struct nouveau_connector *nv_connector = nouveau_connector(connector);
 	struct nouveau_encoder *nv_encoder = nv_connector->detected_encoder;
 	struct drm_encoder *encoder = to_drm_encoder(nv_encoder);
-	unsigned min_clock = 25000, max_clock = min_clock;
+	unsigned int min_clock = 25000, max_clock = min_clock, clock = mode->clock;
 
 	switch (nv_encoder->dcb->type) {
 	case DCB_OUTPUT_LVDS:
@@ -1082,8 +1059,15 @@ nouveau_connector_mode_valid(struct drm_connector *connector,
 		return MODE_BAD;
 	}
 
-	return nouveau_conn_mode_clock_valid(mode, min_clock, max_clock,
-					     NULL);
+	if ((mode->flags & DRM_MODE_FLAG_3D_MASK) == DRM_MODE_FLAG_3D_FRAME_PACKING)
+		clock *= 2;
+
+	if (clock < min_clock)
+		return MODE_CLOCK_LOW;
+	if (clock > max_clock)
+		return MODE_CLOCK_HIGH;
+
+	return MODE_OK;
 }
 
 static struct drm_encoder *
drivers/gpu/drm/nouveau/nouveau_dp.c +11 -5
index 7b640e05bd4c..93e3751ad7f1 100644
@@ -232,12 +232,14 @@ nv50_dp_mode_valid(struct drm_connector *connector,
 		   unsigned *out_clock)
 {
 	const unsigned min_clock = 25000;
-	unsigned max_clock, ds_clock, clock;
-	enum drm_mode_status ret;
+	unsigned max_clock, ds_clock, clock = mode->clock;
 
 	if (mode->flags & DRM_MODE_FLAG_INTERLACE && !outp->caps.dp_interlace)
 		return MODE_NO_INTERLACE;
 
+	if ((mode->flags & DRM_MODE_FLAG_3D_MASK) == DRM_MODE_FLAG_3D_FRAME_PACKING)
+		clock *= 2;
+
 	max_clock = outp->dp.link_nr * outp->dp.link_bw;
 	ds_clock = drm_dp_downstream_max_dotclock(outp->dp.dpcd,
 						  outp->dp.downstream_ports);
@@ -245,9 +247,13 @@ nv50_dp_mode_valid(struct drm_connector *connector,
 		max_clock = min(max_clock, ds_clock);
 
 	clock = mode->clock * (connector->display_info.bpc * 3) / 10;
-	ret = nouveau_conn_mode_clock_valid(mode, min_clock, max_clock,
-					    &clock);
+	if (clock < min_clock)
+		return MODE_CLOCK_LOW;
+	if (clock > max_clock)
+		return MODE_CLOCK_HIGH;
+
 	if (out_clock)
 		*out_clock = clock;
-	return ret;
+
+	return MODE_OK;
 }
maintainer
#1 lore raw

Actually - this fix caused some problems, and there's a follow-up fix in linus's tree now that we want to make sure to apply at the same time. It looks like I forgot to Cc it to stable though, so I'll backport both this and the subsequent fix and send them to you in just a bit

Quoted 144 lines · On Thu, 2020-11-05 at 16:36 +0100, [email protected] wrote:

The patch below does not apply to the 5.9-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.

thanks,

greg k-h

------------------ original commit in Linus's tree ------------------

From 2d831155cf0607566e43d8465da33774b2dc7221 Mon Sep 17 00:00:00 2001
From: Lyude Paul <[email protected]>
Date: Tue, 29 Sep 2020 18:31:31 -0400
Subject: [PATCH] drm/nouveau/kms/nv50-: Get rid of bogus nouveau_conn_mode_valid()
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Ville also pointed out that I got a lot of the logic here wrong as well, whoops.
While I don't think anyone's likely using 3D output with nouveau, the next patch
will make nouveau_conn_mode_valid() make a lot less sense. So, let's just get rid of it and open-code it like before, while taking care to move the 3D frame packing calculations on the dot clock into the right place.

Fixes d6a9efece724 ("drm/nouveau/kms/nv50-: Share DP SST mode_valid()

handling with MST")

Cc Ville Syrjälä <[email protected]>
Cc <[email protected]> # v5.8+
drivers/gpu/drm/nouveau/nouveau_connector.c +0 -0
index 49dd0cbc332f..6f21f36719fc 100644
@@ -1023,29 +1023,6 @@ get_tmds_link_bandwidth(struct drm_connector
 *connector)
                 return 112000 * duallink_scale;
  }

drivers/gpu/drm/nouveau/nouveau_connector.c +0 -23
-enum drm_mode_status
-nouveau_conn_mode_clock_valid(const struct drm_display_mode *mode,
-                             const unsigned min_clock,
-                             const unsigned max_clock,
-                             unsigned int *clock_out)
-{
-       unsigned int clock = mode->clock;
-
-       if ((mode->flags & DRM_MODE_FLAG_3D_MASK) ==
-           DRM_MODE_FLAG_3D_FRAME_PACKING)
-               clock *= 2;
-
-       if (clock < min_clock)
-               return MODE_CLOCK_LOW;
-       if (clock > max_clock)
-               return MODE_CLOCK_HIGH;
-
-       if (clock_out)
-               *clock_out = clock;
-
-       return MODE_OK;
-}
-

 static enum drm_mode_status nouveau_connector_mode_valid(struct drm_connector *connector, struct drm_display_mode *mode)

drivers/gpu/drm/nouveau/nouveau_connector.c +1 -1
@@ -1053,7 +1030,7 @@ nouveau_connector_mode_valid(struct drm_connector
 *connector,
         struct nouveau_connector *nv_connector = nouveau_connector(connector);
         struct nouveau_encoder *nv_encoder = nv_connector->detected_encoder;
         struct drm_encoder *encoder = to_drm_encoder(nv_encoder);
-       unsigned min_clock = 25000, max_clock = min_clock;
+       unsigned int min_clock = 25000, max_clock = min_clock, clock = mode-
 >clock;


        switch (nv_encoder->dcb->type) {
        case DCB_OUTPUT_LVDS:

drivers/gpu/drm/nouveau/nouveau_connector.c +0 -0
@@ -1082,8 +1059,15 @@ nouveau_connector_mode_valid(struct drm_connector
 *connector,
                 return MODE_BAD;
         }


-       return nouveau_conn_mode_clock_valid(mode, min_clock, max_clock, -                                            NULL);
+       if ((mode->flags & DRM_MODE_FLAG_3D_MASK) == DRM_MODE_FLAG_3D_FRAME_PACKING)
+               clock *= 2;

drivers/gpu/drm/nouveau/nouveau_connector.c +7 -0
+
+       if (clock < min_clock)
+               return MODE_CLOCK_LOW;
+       if (clock > max_clock)
+               return MODE_CLOCK_HIGH;
+
+       return MODE_OK;

 }

 static struct drm_encoder *

drivers/gpu/drm/nouveau/nouveau_dp.c +1 -2
index 7b640e05bd4c..93e3751ad7f1 100644
@@ -232,12 +232,14 @@ nv50_dp_mode_valid(struct drm_connector *connector,
                    unsigned *out_clock)
  {
         const unsigned min_clock = 25000;
-       unsigned max_clock, ds_clock, clock;
-       enum drm_mode_status ret;
+       unsigned max_clock, ds_clock, clock = mode->clock;


        if (mode->flags & DRM_MODE_FLAG_INTERLACE && !outp->caps.dp_interlace) return MODE_NO_INTERLACE;

+       if ((mode->flags & DRM_MODE_FLAG_3D_MASK) == DRM_MODE_FLAG_3D_FRAME_PACKING)
+               clock *= 2;
+
        max_clock = outp->dp.link_nr * outp->dp.link_bw;
        ds_clock = drm_dp_downstream_max_dotclock(outp->dp.dpcd, outp->dp.downstream_ports);

drivers/gpu/drm/nouveau/nouveau_dp.c +0 -0
@@ -245,9 +247,13 @@ nv50_dp_mode_valid(struct drm_connector *connector,
                 max_clock = min(max_clock, ds_clock);


        clock = mode->clock * (connector->display_info.bpc * 3) / 10; -       ret = nouveau_conn_mode_clock_valid(mode, min_clock, max_clock, -                                           &clock);
+       if (clock < min_clock)
+               return MODE_CLOCK_LOW;
+       if (clock > max_clock)
+               return MODE_CLOCK_HIGH;
+
        if (out_clock)
                *out_clock = clock;
-       return ret;
+
+       return MODE_OK;
 }

Signature · 8 lines
Sincerely,
   Lyude Paul (she/her)
   Software Engineer at Red Hat
   
Note: I deal with a lot of emails and have a lot of bugs on my plate. If you've
asked me a question, are waiting for a review/merge on a patch, etc. and I
haven't responded in a while, please feel free to send me another email to check
on my status. I don't bite!
maintainer
#2 lore raw

cover drm/nouveau: Stable backport of DP clock fixes for v5.9

In reply to [email protected]

Just a backport of the two patches for v5.9 that you'll want to apply. The first one was Cc'd to stable, but I forgot to Cc the second one as well.

Lyude Paul (2):
drm/nouveau/kms/nv50-: Get rid of bogus nouveau_conn_mode_valid() drm/nouveau/kms/nv50-: Fix clock checking algorithm in

    nv50_dp_mode_valid()
 drivers/gpu/drm/nouveau/nouveau_connector.c | 36 ++++++---------------
 drivers/gpu/drm/nouveau/nouveau_dp.c        | 21 ++++++++----
 2 files changed, 24 insertions(+), 33 deletions(-)
Signature · 1 line
2.28.0
maintainer
#3 lore raw

PATCH 1/2 drm/nouveau/kms/nv50-: Get rid of bogus nouveau_conn_mode_valid()

Ville also pointed out that I got a lot of the logic here wrong as well, whoops. While I don't think anyone's likely using 3D output with nouveau, the next patch will make nouveau_conn_mode_valid() make a lot less sense. So, let's just get rid of it and open-code it like before, while taking care to move the 3D frame packing calculations on the dot clock into the right place.

Fixes d6a9efece724 ("drm/nouveau/kms/nv50-: Share DP SST mode_valid() handling with MST")
Cc Ville Syrjälä <[email protected]>
Cc <[email protected]> # v5.8+
---
 drivers/gpu/drm/nouveau/nouveau_connector.c | 36 ++++++---------------
 drivers/gpu/drm/nouveau/nouveau_dp.c        | 15 ++++++---
 2 files changed, 20 insertions(+), 31 deletions(-)
drivers/gpu/drm/nouveau/nouveau_connector.c +10 -26
index 7674025a4bfe8..1d91d52ee5083 100644
@@ -1035,29 +1035,6 @@ get_tmds_link_bandwidth(struct drm_connector *connector)
 		return 112000 * duallink_scale;
 }
 
-enum drm_mode_status
-nouveau_conn_mode_clock_valid(const struct drm_display_mode *mode,
-			      const unsigned min_clock,
-			      const unsigned max_clock,
-			      unsigned int *clock_out)
-{
-	unsigned int clock = mode->clock;
-
-	if ((mode->flags & DRM_MODE_FLAG_3D_MASK) ==
-	    DRM_MODE_FLAG_3D_FRAME_PACKING)
-		clock *= 2;
-
-	if (clock < min_clock)
-		return MODE_CLOCK_LOW;
-	if (clock > max_clock)
-		return MODE_CLOCK_HIGH;
-
-	if (clock_out)
-		*clock_out = clock;
-
-	return MODE_OK;
-}
-
 static enum drm_mode_status
 nouveau_connector_mode_valid(struct drm_connector *connector,
 			     struct drm_display_mode *mode)
@@ -1065,7 +1042,7 @@ nouveau_connector_mode_valid(struct drm_connector *connector,
 	struct nouveau_connector *nv_connector = nouveau_connector(connector);
 	struct nouveau_encoder *nv_encoder = nv_connector->detected_encoder;
 	struct drm_encoder *encoder = to_drm_encoder(nv_encoder);
-	unsigned min_clock = 25000, max_clock = min_clock;
+	unsigned int min_clock = 25000, max_clock = min_clock, clock = mode->clock;
 
 	switch (nv_encoder->dcb->type) {
 	case DCB_OUTPUT_LVDS:
@@ -1094,8 +1071,15 @@ nouveau_connector_mode_valid(struct drm_connector *connector,
 		return MODE_BAD;
 	}
 
-	return nouveau_conn_mode_clock_valid(mode, min_clock, max_clock,
-					     NULL);
+	if ((mode->flags & DRM_MODE_FLAG_3D_MASK) == DRM_MODE_FLAG_3D_FRAME_PACKING)
+		clock *= 2;
+
+	if (clock < min_clock)
+		return MODE_CLOCK_LOW;
+	if (clock > max_clock)
+		return MODE_CLOCK_HIGH;
+
+	return MODE_OK;
 }
 
 static struct drm_encoder *
drivers/gpu/drm/nouveau/nouveau_dp.c +10 -5
index 8a0f7994e1aeb..40683e1244c3f 100644
@@ -114,18 +114,23 @@ nv50_dp_mode_valid(struct drm_connector *connector,
 		   unsigned *out_clock)
 {
 	const unsigned min_clock = 25000;
-	unsigned max_clock, clock;
-	enum drm_mode_status ret;
+	unsigned max_clock, clock = mode->clock;
 
 	if (mode->flags & DRM_MODE_FLAG_INTERLACE && !outp->caps.dp_interlace)
 		return MODE_NO_INTERLACE;
 
+	if ((mode->flags & DRM_MODE_FLAG_3D_MASK) == DRM_MODE_FLAG_3D_FRAME_PACKING)
+		clock *= 2;
+
 	max_clock = outp->dp.link_nr * outp->dp.link_bw;
 	clock = mode->clock * (connector->display_info.bpc * 3) / 10;
+	if (clock < min_clock)
+		return MODE_CLOCK_LOW;
+	if (clock > max_clock)
+		return MODE_CLOCK_HIGH;
 
-	ret = nouveau_conn_mode_clock_valid(mode, min_clock, max_clock,
-					    &clock);
 	if (out_clock)
 		*out_clock = clock;
-	return ret;
+
+	return MODE_OK;
 }
Signature · 1 line
2.28.0
maintainer
#4 lore raw

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

In reply to Lyude Paul

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.

Changes made for stable backport:
* 5.9 didn't use drm_dp_downstream_max_dotclock() yet, so remove that (the fix is still important regardless)

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

Fixes 409d38139b42 ("drm/nouveau/kms/nv50-: Use downstream DP clock limits for mode validation")
Cc Ville Syrjälä <[email protected]>
Cc Lyude Paul <[email protected]>
Cc Ben Skeggs <[email protected]>
---
 drivers/gpu/drm/nouveau/nouveau_dp.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)
drivers/gpu/drm/nouveau/nouveau_dp.c +7 -5
index 40683e1244c3f..9c06d1cc43905 100644
@@ -114,7 +114,8 @@ nv50_dp_mode_valid(struct drm_connector *connector,
 		   unsigned *out_clock)
 {
 	const unsigned min_clock = 25000;
-	unsigned max_clock, clock = mode->clock;
+	unsigned int max_rate, mode_rate, clock = mode->clock;
+	const u8 bpp = connector->display_info.bpc * 3;
 
 	if (mode->flags & DRM_MODE_FLAG_INTERLACE && !outp->caps.dp_interlace)
 		return MODE_NO_INTERLACE;
@@ -122,12 +123,13 @@ nv50_dp_mode_valid(struct drm_connector *connector,
 	if ((mode->flags & DRM_MODE_FLAG_3D_MASK) == DRM_MODE_FLAG_3D_FRAME_PACKING)
 		clock *= 2;
 
-	max_clock = outp->dp.link_nr * outp->dp.link_bw;
-	clock = mode->clock * (connector->display_info.bpc * 3) / 10;
+	max_rate = outp->dp.link_nr * outp->dp.link_bw;
+	mode_rate = DIV_ROUND_UP(clock * bpp, 8);
+	if (mode_rate > max_rate)
+		return MODE_CLOCK_HIGH;
+
 	if (clock < min_clock)
 		return MODE_CLOCK_LOW;
-	if (clock > max_clock)
-		return MODE_CLOCK_HIGH;
 
 	if (out_clock)
 		*out_clock = clock;
Signature · 1 line
2.28.0
author maintainer
#5 lore raw

Re: [PATCH 0/2] drm/nouveau: Stable backport of DP clock fixes for v5.9

In reply to Lyude Paul
Quoted 4 lines · Lyude Paul

Just a backport of the two patches for v5.9 that you'll want to apply. The first one was Cc'd to stable, but I forgot to Cc the second one as well.

Quoted 8 lines

Lyude Paul (2):
drm/nouveau/kms/nv50-: Get rid of bogus nouveau_conn_mode_valid() drm/nouveau/kms/nv50-: Fix clock checking algorithm in

    nv50_dp_mode_valid()
 drivers/gpu/drm/nouveau/nouveau_connector.c | 36 ++++++---------------
 drivers/gpu/drm/nouveau/nouveau_dp.c        | 21 ++++++++----
 2 files changed, 24 insertions(+), 33 deletions(-)

Thanks for these, now queued up.

Next time if you could include what the upstream git commmit ids they are in Linus's tree, that would help, as I have to list them.

thanks,

greg k-h