Skip to contentSkip to conversation

drm/amdgpu: Fix DC scanout position handling

PATCH Superseded Erhan Bilgili 2 participants 3 messages Oct 25 – Oct 26

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drm/amdgpu: Fix DC scanout position handling

dm_crtc_get_scanoutpos() packs decoded DC positions and blanking boundaries into u32 words, shifting the second value by 16 bits.

VRR extends vertical blanking without changing the line clock. For example, a 4K240 mode with vtotal=2250 spans about 9000 lines per refresh at 60 Hz, exceeding the 13 bit range within a 48-240 Hz VRR range.

The 13 bit mask truncates positions above 8191, causing early VRR timestamps and missed vblank count adjustments.

Fixes e806208dc1da ("drm/amd/display: Fix slow FPS.")
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_display.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_display.c +6 -4
index 0a8dd7241750..f78c82ba7f70 100644
@@ -1767,6 +1767,8 @@ int amdgpu_display_get_crtc_scanoutpos(struct drm_device *dev,
 	bool in_vbl = true;
 
 	struct amdgpu_device *adev = drm_to_adev(dev);
+	/* DC packs decoded values into 16 bit fields. */
+	const u32 scanout_mask = adev->dc_enabled ? 0xffff : 0x1fff;
 
 	/* preempt_disable_rt() should go right here in PREEMPT_RT patchset. */
 
@@ -1784,15 +1786,15 @@ int amdgpu_display_get_crtc_scanoutpos(struct drm_device *dev,
 	/* preempt_enable_rt() should go right here in PREEMPT_RT patchset. */
 
 	/* Decode into vertical and horizontal scanout position. */
-	*vpos = position & 0x1fff;
-	*hpos = (position >> 16) & 0x1fff;
+	*vpos = position & scanout_mask;
+	*hpos = (position >> 16) & scanout_mask;
 
 	/* Valid vblank area boundaries from gpu retrieved? */
 	if (vbl > 0) {
 		/* Yes: Decode. */
 		ret |= DRM_SCANOUTPOS_ACCURATE;
-		vbl_start = vbl & 0x1fff;
-		vbl_end = (vbl >> 16) & 0x1fff;
+		vbl_start = vbl & scanout_mask;
+		vbl_end = (vbl >> 16) & scanout_mask;
 	} else {
 		/* No: Fake something reasonable which gives at least ok results. */
 		vbl_start = mode->crtc_vdisplay;
Signature · 1 line
2.56.0
#1 lore raw
Quoted 8 lines · Erhan Bilgili

dm_crtc_get_scanoutpos() packs decoded DC positions and blanking boundaries into u32 words, shifting the second value by 16 bits.

VRR extends vertical blanking without changing the line clock. For example, a 4K240 mode with vtotal=2250 spans about 9000 lines per refresh at 60 Hz, exceeding the 13 bit range within a 48-240 Hz VRR range.

Quoted 4 lines

The 13 bit mask truncates positions above 8191, causing early VRR timestamps and missed vblank count adjustments.

Fixes e806208dc1da ("drm/amd/display: Fix slow FPS.")

I don't see how that commit caused the issue. Rather it fixed a bug which had masked the issue.

drivers/gpu/drm/amd/amdgpu/amdgpu_display.c int amdgpu_display_get_crtc_scanoutpos(struct drm_device *dev, · line 1771

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_display.c +2 -0
index 0a8dd7241750..f78c82ba7f70 100644
@@ -1767,6 +1767,8 @@ int amdgpu_display_get_crtc_scanoutpos(struct drm_device *dev,
 	bool in_vbl = true;
 
 	struct amdgpu_device *adev = drm_to_adev(dev);
+	/* DC packs decoded values into 16 bit fields. */
+	const u32 scanout_mask = adev->dc_enabled ? 0xffff : 0x1fff;

The 0x1fff mask isn't correct for all non-DC cases either. drivers/gpu/drm/amd/include/asic_reg/dce/dce_10_0_sh_mask.h has

#define CRTC_STATUS_POSITION__CRTC_VERT_COUNT_MASK 0x3fff

drivers/gpu/drm/amd/amdgpu/amdgpu_display.c int amdgpu_display_get_crtc_scanoutpos(struct drm_device *dev, · line 1790

Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_display.c +2 -2
@@ -1784,15 +1786,15 @@ int amdgpu_display_get_crtc_scanoutpos(struct drm_device *dev,
 	/* preempt_enable_rt() should go right here in PREEMPT_RT patchset. */
 
 	/* Decode into vertical and horizontal scanout position. */
-	*vpos = position & 0x1fff;
-	*hpos = (position >> 16) & 0x1fff;
+	*vpos = position & scanout_mask;
+	*hpos = (position >> 16) & scanout_mask;

Since no HW generation seems to have any other fields in the CRTC_STATUS_POSITION & CRTC_V_BLANK_START_END registers, maybe just use

	*vpos = lower_16_bits(position);
	*hpos = upper_16_bits(position);

and correspondingly for vbl_start/end.

Signature · 2 lines
Earthling Michel Dänzer       \        GNOME / Xwayland / Mesa developer
https://redhat.com             \               Libre software enthusiast
#2 lore raw

PATCH v2 1/1 drm/amdgpu: Fix DC scanout position handling

In reply to Erhan Bilgili

The scanout position and vblank boundaries were decoded with a 13 bit mask, but the hardware reports wider values. With VRR, the vertical blank can be extended beyond 8191 lines, so the position gets truncated. This results in wrong vblank timestamps.

Decode both values as 16 bit fields. No hardware generation uses the upper bits for anything else.

Fixes d38ceaf99ed0 ("drm/amdgpu: add core driver (v4)")

---
v2: Decode both values as 16 bit fields (Michel).
Point Fixes at the commit which introduced the 13 bit mask (Michel).

 drivers/gpu/drm/amd/amdgpu/amdgpu_display.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_display.c +4 -4
index 0a8dd7241750..9ceb2921ccec 100644
@@ -1784,15 +1784,15 @@ int amdgpu_display_get_crtc_scanoutpos(struct drm_device *dev,
 	/* preempt_enable_rt() should go right here in PREEMPT_RT patchset. */
 
 	/* Decode into vertical and horizontal scanout position. */
-	*vpos = position & 0x1fff;
-	*hpos = (position >> 16) & 0x1fff;
+	*vpos = lower_16_bits(position);
+	*hpos = upper_16_bits(position);
 
 	/* Valid vblank area boundaries from gpu retrieved? */
 	if (vbl > 0) {
 		/* Yes: Decode. */
 		ret |= DRM_SCANOUTPOS_ACCURATE;
-		vbl_start = vbl & 0x1fff;
-		vbl_end = (vbl >> 16) & 0x1fff;
+		vbl_start = lower_16_bits(vbl);
+		vbl_end = upper_16_bits(vbl);
 	} else {
 		/* No: Fake something reasonable which gives at least ok results. */
 		vbl_start = mode->crtc_vdisplay;
Signature · 1 line
2.56.0