Skip to contentSkip to conversation

drm: mxsfb: check framebuffer pitch

PATCH Superseded Stefan Agner 6 participants 13 messages Sep 7, 2020 – Sep 8, 2020

Subsystems (4)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Stefan Agner

author maintainer
#0 lore raw

PATCH 1/1 drm: mxsfb: check framebuffer pitch

The lcdif IP does not support a framebuffer pitch (stride) other than the CRTC width. Check for equality and reject the state otherwise.

This prevents a distorted picture when using 640x800 and running the Mesa graphics stack. Mesa tires to use a cache aligned stride, which leads at that particular resolution to width != stride. Currently Mesa has no fallback behavior, but rejecting this configuration allows userspace to handle the issue correctly.

---
 drivers/gpu/drm/mxsfb/mxsfb_kms.c | 22 ++++++++++++++++++----
 1 file changed, 18 insertions(+), 4 deletions(-)
drivers/gpu/drm/mxsfb/mxsfb_kms.c +18 -4
index b721b8b262ce..79aa14027f91 100644
@@ -403,14 +403,28 @@ static int mxsfb_plane_atomic_check(struct drm_plane *plane,
 {
 	struct mxsfb_drm_private *mxsfb = to_mxsfb_drm_private(plane->dev);
 	struct drm_crtc_state *crtc_state;
+	unsigned int pitch;
+	int ret;
 
 	crtc_state = drm_atomic_get_new_crtc_state(plane_state->state,
 						   &mxsfb->crtc);
 
-	return drm_atomic_helper_check_plane_state(plane_state, crtc_state,
-						   DRM_PLANE_HELPER_NO_SCALING,
-						   DRM_PLANE_HELPER_NO_SCALING,
-						   false, true);
+	ret = drm_atomic_helper_check_plane_state(plane_state, crtc_state,
+						  DRM_PLANE_HELPER_NO_SCALING,
+						  DRM_PLANE_HELPER_NO_SCALING,
+						  false, true);
+	if (ret || !plane_state->visible)
+		return ret;
+
+	pitch = crtc_state->mode.hdisplay *
+		plane_state->fb->format->cpp[0];
+	if (plane_state->fb->pitches[0] != pitch) {
+		dev_err(plane->dev->dev,
+			"Invalid pitch: fb and crtc widths must be the same");
+		return -EINVAL;
+	}
+
+	return 0;
 }
 
 static void mxsfb_plane_primary_atomic_update(struct drm_plane *plane,
Signature · 6 lines
2.28.0

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#1 lore raw

Hi Stefan,

Thank you for the patch.

Quoted 5 lines · Stefan Agner

The lcdif IP does not support a framebuffer pitch (stride) other than the CRTC width. Check for equality and reject the state otherwise.

This prevents a distorted picture when using 640x800 and running the Mesa graphics stack. Mesa tires to use a cache aligned stride, which

s/tires/tries/

Quoted 3 lines

leads at that particular resolution to width != stride. Currently Mesa has no fallback behavior, but rejecting this configuration allows userspace to handle the issue correctly.

I'm increasingly impressed by how featureful this IP core is :-)

Quoted 18 lines
---
 drivers/gpu/drm/mxsfb/mxsfb_kms.c | 22 ++++++++++++++++++----
 1 file changed, 18 insertions(+), 4 deletions(-)
drivers/gpu/drm/mxsfb/mxsfb_kms.c +2 -0
index b721b8b262ce..79aa14027f91 100644
@@ -403,14 +403,28 @@ static int mxsfb_plane_atomic_check(struct drm_plane *plane,
 {
 	struct mxsfb_drm_private *mxsfb = to_mxsfb_drm_private(plane->dev);
 	struct drm_crtc_state *crtc_state;
+	unsigned int pitch;
+	int ret;
 
 	crtc_state = drm_atomic_get_new_crtc_state(plane_state->state,
 						   &mxsfb->crtc);

drivers/gpu/drm/mxsfb/mxsfb_kms.c static int mxsfb_plane_atomic_check(struct drm_plane *plane, · line 416

Quoted 10 lines
drivers/gpu/drm/mxsfb/mxsfb_kms.c +5 -4
 
-	return drm_atomic_helper_check_plane_state(plane_state, crtc_state,
-						   DRM_PLANE_HELPER_NO_SCALING,
-						   DRM_PLANE_HELPER_NO_SCALING,
-						   false, true);
+	ret = drm_atomic_helper_check_plane_state(plane_state, crtc_state,
+						  DRM_PLANE_HELPER_NO_SCALING,
+						  DRM_PLANE_HELPER_NO_SCALING,
+						  false, true);
+	if (ret || !plane_state->visible)

Would it be more explict to check for !plane_state->fb ? Otherwise I'll have to verify that !fb always implies !visible :-)

drivers/gpu/drm/mxsfb/mxsfb_kms.c static int mxsfb_plane_atomic_check(struct drm_plane *plane, · line 420

Quoted 4 lines
drivers/gpu/drm/mxsfb/mxsfb_kms.c +4 -0
+		return ret;
+
+	pitch = crtc_state->mode.hdisplay *
+		plane_state->fb->format->cpp[0];

This holds on a single line.

drivers/gpu/drm/mxsfb/mxsfb_kms.c static int mxsfb_plane_atomic_check(struct drm_plane *plane, · line 423

Quoted 3 lines
drivers/gpu/drm/mxsfb/mxsfb_kms.c +3 -0
+	if (plane_state->fb->pitches[0] != pitch) {
+		dev_err(plane->dev->dev,
+			"Invalid pitch: fb and crtc widths must be the same");

I'd turn this into a dev_dbg(), printing error messages to the kernel log in response to user-triggered conditions is a bit too verbose and could flood the log.

Wouldn't it be best to catch this issue when creating the framebuffer ?

Quoted 7 lines
drivers/gpu/drm/mxsfb/mxsfb_kms.c +4 -0
+		return -EINVAL;
+	}
+
+	return 0;
 }
 
 static void mxsfb_plane_primary_atomic_update(struct drm_plane *plane,
Signature · 7 lines
Regards,

Laurent Pinchart
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#2 lore raw
Quoted 66 lines · Laurent Pinchart

Hi Stefan,

Thank you for the patch.

Quoted 5 lines · Stefan Agner

The lcdif IP does not support a framebuffer pitch (stride) other than the CRTC width. Check for equality and reject the state otherwise.

This prevents a distorted picture when using 640x800 and running the Mesa graphics stack. Mesa tires to use a cache aligned stride, which

s/tires/tries/

Quoted 3 lines

leads at that particular resolution to width != stride. Currently Mesa has no fallback behavior, but rejecting this configuration allows userspace to handle the issue correctly.

I'm increasingly impressed by how featureful this IP core is :-)

Quoted 18 lines
---
 drivers/gpu/drm/mxsfb/mxsfb_kms.c | 22 ++++++++++++++++++----
 1 file changed, 18 insertions(+), 4 deletions(-)
drivers/gpu/drm/mxsfb/mxsfb_kms.c +2 -0
index b721b8b262ce..79aa14027f91 100644
@@ -403,14 +403,28 @@ static int mxsfb_plane_atomic_check(struct drm_plane *plane,
 {
 	struct mxsfb_drm_private *mxsfb = to_mxsfb_drm_private(plane->dev);
 	struct drm_crtc_state *crtc_state;
+	unsigned int pitch;
+	int ret;
 
 	crtc_state = drm_atomic_get_new_crtc_state(plane_state->state,
 						   &mxsfb->crtc);

drivers/gpu/drm/mxsfb/mxsfb_kms.c static int mxsfb_plane_atomic_check(struct drm_plane *plane, · line 416

Quoted 10 lines
drivers/gpu/drm/mxsfb/mxsfb_kms.c +5 -4
 
-	return drm_atomic_helper_check_plane_state(plane_state, crtc_state,
-						   DRM_PLANE_HELPER_NO_SCALING,
-						   DRM_PLANE_HELPER_NO_SCALING,
-						   false, true);
+	ret = drm_atomic_helper_check_plane_state(plane_state, crtc_state,
+						  DRM_PLANE_HELPER_NO_SCALING,
+						  DRM_PLANE_HELPER_NO_SCALING,
+						  false, true);
+	if (ret || !plane_state->visible)

Would it be more explict to check for !plane_state->fb ? Otherwise I'll have to verify that !fb always implies !visible :-)

drivers/gpu/drm/mxsfb/mxsfb_kms.c static int mxsfb_plane_atomic_check(struct drm_plane *plane, · line 420

Quoted 4 lines
drivers/gpu/drm/mxsfb/mxsfb_kms.c +4 -0
+		return ret;
+
+	pitch = crtc_state->mode.hdisplay *
+		plane_state->fb->format->cpp[0];

This holds on a single line.

drivers/gpu/drm/mxsfb/mxsfb_kms.c static int mxsfb_plane_atomic_check(struct drm_plane *plane, · line 423

Quoted 3 lines
drivers/gpu/drm/mxsfb/mxsfb_kms.c +3 -0
+	if (plane_state->fb->pitches[0] != pitch) {
+		dev_err(plane->dev->dev,
+			"Invalid pitch: fb and crtc widths must be the same");

I'd turn this into a dev_dbg(), printing error messages to the kernel log in response to user-triggered conditions is a bit too verbose and could flood the log.

Quoted 1 line

Wouldn't it be best to catch this issue when creating the framebuffer ?

Yeah this should be verified at addfb time. We try to validate as early as possible.
-Daniel

Quoted 13 lines
Quoted 8 lines
drivers/gpu/drm/mxsfb/mxsfb_kms.c +4 -0
+		return -EINVAL;
+	}
+
+	return 0;
 }
 
 static void mxsfb_plane_primary_atomic_update(struct drm_plane *plane,
Signature · 3 lines
Regards,

Laurent Pinchart
Signature · 7 lines
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
author maintainer
#3 lore raw
Quoted 67 lines · Daniel Vetter
Quoted 66 lines · Laurent Pinchart

Hi Stefan,

Thank you for the patch.

Quoted 5 lines · Stefan Agner

The lcdif IP does not support a framebuffer pitch (stride) other than the CRTC width. Check for equality and reject the state otherwise.

This prevents a distorted picture when using 640x800 and running the Mesa graphics stack. Mesa tires to use a cache aligned stride, which

s/tires/tries/

Quoted 3 lines

leads at that particular resolution to width != stride. Currently Mesa has no fallback behavior, but rejecting this configuration allows userspace to handle the issue correctly.

I'm increasingly impressed by how featureful this IP core is :-)

Quoted 18 lines
---
 drivers/gpu/drm/mxsfb/mxsfb_kms.c | 22 ++++++++++++++++++----
 1 file changed, 18 insertions(+), 4 deletions(-)
drivers/gpu/drm/mxsfb/mxsfb_kms.c +2 -0
index b721b8b262ce..79aa14027f91 100644
@@ -403,14 +403,28 @@ static int mxsfb_plane_atomic_check(struct drm_plane *plane,
 {
 	struct mxsfb_drm_private *mxsfb = to_mxsfb_drm_private(plane->dev);
 	struct drm_crtc_state *crtc_state;
+	unsigned int pitch;
+	int ret;
 
 	crtc_state = drm_atomic_get_new_crtc_state(plane_state->state,
 						   &mxsfb->crtc);

drivers/gpu/drm/mxsfb/mxsfb_kms.c static int mxsfb_plane_atomic_check(struct drm_plane *plane, · line 416

Quoted 10 lines
drivers/gpu/drm/mxsfb/mxsfb_kms.c +5 -4
 
-	return drm_atomic_helper_check_plane_state(plane_state, crtc_state,
-						   DRM_PLANE_HELPER_NO_SCALING,
-						   DRM_PLANE_HELPER_NO_SCALING,
-						   false, true);
+	ret = drm_atomic_helper_check_plane_state(plane_state, crtc_state,
+						  DRM_PLANE_HELPER_NO_SCALING,
+						  DRM_PLANE_HELPER_NO_SCALING,
+						  false, true);
+	if (ret || !plane_state->visible)

Would it be more explict to check for !plane_state->fb ? Otherwise I'll have to verify that !fb always implies !visible :-)

drivers/gpu/drm/mxsfb/mxsfb_kms.c static int mxsfb_plane_atomic_check(struct drm_plane *plane, · line 420

Quoted 4 lines
drivers/gpu/drm/mxsfb/mxsfb_kms.c +4 -0
+		return ret;
+
+	pitch = crtc_state->mode.hdisplay *
+		plane_state->fb->format->cpp[0];

This holds on a single line.

drivers/gpu/drm/mxsfb/mxsfb_kms.c static int mxsfb_plane_atomic_check(struct drm_plane *plane, · line 423

Quoted 3 lines
drivers/gpu/drm/mxsfb/mxsfb_kms.c +3 -0
+	if (plane_state->fb->pitches[0] != pitch) {
+		dev_err(plane->dev->dev,
+			"Invalid pitch: fb and crtc widths must be the same");

I'd turn this into a dev_dbg(), printing error messages to the kernel log in response to user-triggered conditions is a bit too verbose and could flood the log.

Quoted 6 lines
Quoted 1 line

Wouldn't it be best to catch this issue when creating the framebuffer ?

Yeah this should be verified at addfb time. We try to validate as early as possible.
-Daniel

Sounds sensible. From what I can tell fb_create is the proper callback to implement this at addfb time. Will give this a try.

FWIW, I got the idea from drivers/gpu/drm/tilcdc/tilcdc_plane.c. Maybe should be moved to addfb there too?

[added Jyri/Tomi]

--
Stefan

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
drivers/gpu/drm/mxsfb/mxsfb_kms.c +4 -0
+		return -EINVAL;
+	}
+
+	return 0;
 }
 
Quoted 6 lines
Quoted 6 lines

drivers/gpu/drm/mxsfb/mxsfb_kms.c static int mxsfb_plane_atomic_check(struct drm_plane *plane, · line 430

Quoted 1 line
drivers/gpu/drm/mxsfb/mxsfb_kms.c +0 -0
 static void mxsfb_plane_primary_atomic_update(struct drm_plane *plane,

--
Regards,

Laurent Pinchart

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#4 lore raw

Hi,

Quoted 75 lines · Stefan Agner
Quoted 67 lines · Daniel Vetter
Quoted 66 lines · Laurent Pinchart

Hi Stefan,

Thank you for the patch.

Quoted 5 lines · Stefan Agner

The lcdif IP does not support a framebuffer pitch (stride) other than the CRTC width. Check for equality and reject the state otherwise.

This prevents a distorted picture when using 640x800 and running the Mesa graphics stack. Mesa tires to use a cache aligned stride, which

s/tires/tries/

Quoted 3 lines

leads at that particular resolution to width != stride. Currently Mesa has no fallback behavior, but rejecting this configuration allows userspace to handle the issue correctly.

I'm increasingly impressed by how featureful this IP core is :-)

Quoted 18 lines
---
 drivers/gpu/drm/mxsfb/mxsfb_kms.c | 22 ++++++++++++++++++----
 1 file changed, 18 insertions(+), 4 deletions(-)
drivers/gpu/drm/mxsfb/mxsfb_kms.c +2 -0
index b721b8b262ce..79aa14027f91 100644
@@ -403,14 +403,28 @@ static int mxsfb_plane_atomic_check(struct drm_plane *plane,
 {
 	struct mxsfb_drm_private *mxsfb = to_mxsfb_drm_private(plane->dev);
 	struct drm_crtc_state *crtc_state;
+	unsigned int pitch;
+	int ret;
 
 	crtc_state = drm_atomic_get_new_crtc_state(plane_state->state,
 						   &mxsfb->crtc);

drivers/gpu/drm/mxsfb/mxsfb_kms.c static int mxsfb_plane_atomic_check(struct drm_plane *plane, · line 416

Quoted 10 lines
drivers/gpu/drm/mxsfb/mxsfb_kms.c +5 -4
 
-	return drm_atomic_helper_check_plane_state(plane_state, crtc_state,
-						   DRM_PLANE_HELPER_NO_SCALING,
-						   DRM_PLANE_HELPER_NO_SCALING,
-						   false, true);
+	ret = drm_atomic_helper_check_plane_state(plane_state, crtc_state,
+						  DRM_PLANE_HELPER_NO_SCALING,
+						  DRM_PLANE_HELPER_NO_SCALING,
+						  false, true);
+	if (ret || !plane_state->visible)

Would it be more explict to check for !plane_state->fb ? Otherwise I'll have to verify that !fb always implies !visible :-)

drivers/gpu/drm/mxsfb/mxsfb_kms.c static int mxsfb_plane_atomic_check(struct drm_plane *plane, · line 420

Quoted 4 lines
drivers/gpu/drm/mxsfb/mxsfb_kms.c +4 -0
+		return ret;
+
+	pitch = crtc_state->mode.hdisplay *
+		plane_state->fb->format->cpp[0];

This holds on a single line.

drivers/gpu/drm/mxsfb/mxsfb_kms.c static int mxsfb_plane_atomic_check(struct drm_plane *plane, · line 423

Quoted 3 lines
drivers/gpu/drm/mxsfb/mxsfb_kms.c +3 -0
+	if (plane_state->fb->pitches[0] != pitch) {
+		dev_err(plane->dev->dev,
+			"Invalid pitch: fb and crtc widths must be the same");

I'd turn this into a dev_dbg(), printing error messages to the kernel log in response to user-triggered conditions is a bit too verbose and could flood the log.

Quoted 6 lines
Quoted 1 line

Wouldn't it be best to catch this issue when creating the framebuffer ?

Yeah this should be verified at addfb time. We try to validate as early as possible.
-Daniel

Quoted 5 lines

Sounds sensible. From what I can tell fb_create is the proper callback to implement this at addfb time. Will give this a try.

FWIW, I got the idea from drivers/gpu/drm/tilcdc/tilcdc_plane.c. Maybe should be moved to addfb there too?

But you don't know the crtc width when creating the framebuffer.

Tomi

Signature · 6 lines
Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki.
Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#5 lore raw
Quoted 78 lines · Tomi Valkeinen

Hi,

Quoted 75 lines · Stefan Agner
Quoted 73 lines · Daniel Vetter
Quoted 66 lines · Laurent Pinchart

Hi Stefan,

Thank you for the patch.

Quoted 5 lines · Stefan Agner

The lcdif IP does not support a framebuffer pitch (stride) other than the CRTC width. Check for equality and reject the state otherwise.

This prevents a distorted picture when using 640x800 and running the Mesa graphics stack. Mesa tires to use a cache aligned stride, which

s/tires/tries/

Quoted 3 lines

leads at that particular resolution to width != stride. Currently Mesa has no fallback behavior, but rejecting this configuration allows userspace to handle the issue correctly.

I'm increasingly impressed by how featureful this IP core is :-)

Quoted 18 lines
---
 drivers/gpu/drm/mxsfb/mxsfb_kms.c | 22 ++++++++++++++++++----
 1 file changed, 18 insertions(+), 4 deletions(-)
drivers/gpu/drm/mxsfb/mxsfb_kms.c +2 -0
index b721b8b262ce..79aa14027f91 100644
@@ -403,14 +403,28 @@ static int mxsfb_plane_atomic_check(struct drm_plane *plane,
 {
 	struct mxsfb_drm_private *mxsfb = to_mxsfb_drm_private(plane->dev);
 	struct drm_crtc_state *crtc_state;
+	unsigned int pitch;
+	int ret;
 
 	crtc_state = drm_atomic_get_new_crtc_state(plane_state->state,
 						   &mxsfb->crtc);

drivers/gpu/drm/mxsfb/mxsfb_kms.c static int mxsfb_plane_atomic_check(struct drm_plane *plane, · line 416

Quoted 10 lines
drivers/gpu/drm/mxsfb/mxsfb_kms.c +5 -4
 
-	return drm_atomic_helper_check_plane_state(plane_state, crtc_state,
-						   DRM_PLANE_HELPER_NO_SCALING,
-						   DRM_PLANE_HELPER_NO_SCALING,
-						   false, true);
+	ret = drm_atomic_helper_check_plane_state(plane_state, crtc_state,
+						  DRM_PLANE_HELPER_NO_SCALING,
+						  DRM_PLANE_HELPER_NO_SCALING,
+						  false, true);
+	if (ret || !plane_state->visible)

Would it be more explict to check for !plane_state->fb ? Otherwise I'll have to verify that !fb always implies !visible :-)

drivers/gpu/drm/mxsfb/mxsfb_kms.c static int mxsfb_plane_atomic_check(struct drm_plane *plane, · line 420

Quoted 4 lines
drivers/gpu/drm/mxsfb/mxsfb_kms.c +4 -0
+		return ret;
+
+	pitch = crtc_state->mode.hdisplay *
+		plane_state->fb->format->cpp[0];

This holds on a single line.

drivers/gpu/drm/mxsfb/mxsfb_kms.c static int mxsfb_plane_atomic_check(struct drm_plane *plane, · line 423

Quoted 3 lines
drivers/gpu/drm/mxsfb/mxsfb_kms.c +3 -0
+	if (plane_state->fb->pitches[0] != pitch) {
+		dev_err(plane->dev->dev,
+			"Invalid pitch: fb and crtc widths must be the same");

I'd turn this into a dev_dbg(), printing error messages to the kernel log in response to user-triggered conditions is a bit too verbose and could flood the log.

Quoted 1 line

Wouldn't it be best to catch this issue when creating the framebuffer ?

Yeah this should be verified at addfb time. We try to validate as early as possible.
-Daniel

Quoted 7 lines
Quoted 5 lines

Sounds sensible. From what I can tell fb_create is the proper callback to implement this at addfb time. Will give this a try.

FWIW, I got the idea from drivers/gpu/drm/tilcdc/tilcdc_plane.c. Maybe should be moved to addfb there too?

But you don't know the crtc width when creating the framebuffer.

Hm right this is a different check. What we could check in fb_create for both is that the logical fb size matches exactly the pitch. That's not sufficient criteria, but it will at least catch some of them already.

But yeah we'd need both here.
-Daniel

Quoted 6 lines

Tomi

Signature · 2 lines
Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki.
Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki
Signature · 7 lines
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
author maintainer
#6 lore raw
Quoted 85 lines · Daniel Vetter
Quoted 84 lines · Tomi Valkeinen

Hi,

Quoted 80 lines · Stefan Agner
Quoted 67 lines · Daniel Vetter
Quoted 66 lines · Laurent Pinchart

Hi Stefan,

Thank you for the patch.

Quoted 5 lines · Stefan Agner

The lcdif IP does not support a framebuffer pitch (stride) other than the CRTC width. Check for equality and reject the state otherwise.

This prevents a distorted picture when using 640x800 and running the Mesa graphics stack. Mesa tires to use a cache aligned stride, which

s/tires/tries/

Quoted 3 lines

leads at that particular resolution to width != stride. Currently Mesa has no fallback behavior, but rejecting this configuration allows userspace to handle the issue correctly.

I'm increasingly impressed by how featureful this IP core is :-)

Quoted 18 lines
---
 drivers/gpu/drm/mxsfb/mxsfb_kms.c | 22 ++++++++++++++++++----
 1 file changed, 18 insertions(+), 4 deletions(-)
drivers/gpu/drm/mxsfb/mxsfb_kms.c +2 -0
index b721b8b262ce..79aa14027f91 100644
@@ -403,14 +403,28 @@ static int mxsfb_plane_atomic_check(struct drm_plane *plane,
 {
 	struct mxsfb_drm_private *mxsfb = to_mxsfb_drm_private(plane->dev);
 	struct drm_crtc_state *crtc_state;
+	unsigned int pitch;
+	int ret;
 
 	crtc_state = drm_atomic_get_new_crtc_state(plane_state->state,
 						   &mxsfb->crtc);

drivers/gpu/drm/mxsfb/mxsfb_kms.c static int mxsfb_plane_atomic_check(struct drm_plane *plane, · line 416

Quoted 10 lines
drivers/gpu/drm/mxsfb/mxsfb_kms.c +5 -4
 
-	return drm_atomic_helper_check_plane_state(plane_state, crtc_state,
-						   DRM_PLANE_HELPER_NO_SCALING,
-						   DRM_PLANE_HELPER_NO_SCALING,
-						   false, true);
+	ret = drm_atomic_helper_check_plane_state(plane_state, crtc_state,
+						  DRM_PLANE_HELPER_NO_SCALING,
+						  DRM_PLANE_HELPER_NO_SCALING,
+						  false, true);
+	if (ret || !plane_state->visible)

Would it be more explict to check for !plane_state->fb ? Otherwise I'll have to verify that !fb always implies !visible :-)

drivers/gpu/drm/mxsfb/mxsfb_kms.c static int mxsfb_plane_atomic_check(struct drm_plane *plane, · line 420

Quoted 4 lines
drivers/gpu/drm/mxsfb/mxsfb_kms.c +4 -0
+		return ret;
+
+	pitch = crtc_state->mode.hdisplay *
+		plane_state->fb->format->cpp[0];

This holds on a single line.

drivers/gpu/drm/mxsfb/mxsfb_kms.c static int mxsfb_plane_atomic_check(struct drm_plane *plane, · line 423

Quoted 3 lines
drivers/gpu/drm/mxsfb/mxsfb_kms.c +3 -0
+	if (plane_state->fb->pitches[0] != pitch) {
+		dev_err(plane->dev->dev,
+			"Invalid pitch: fb and crtc widths must be the same");

I'd turn this into a dev_dbg(), printing error messages to the kernel log in response to user-triggered conditions is a bit too verbose and could flood the log.

Quoted 6 lines
Quoted 1 line

Wouldn't it be best to catch this issue when creating the framebuffer ?

Yeah this should be verified at addfb time. We try to validate as early as possible.
-Daniel

Sounds sensible. From what I can tell fb_create is the proper callback to implement this at addfb time. Will give this a try.

FWIW, I got the idea from drivers/gpu/drm/tilcdc/tilcdc_plane.c. Maybe should be moved to addfb there too?

Quoted 7 lines
Quoted 1 line

But you don't know the crtc width when creating the framebuffer.

Hm right this is a different check. What we could check in fb_create for both is that the logical fb size matches exactly the pitch. That's not sufficient criteria, but it will at least catch some of them already.

But yeah we'd need both here.

After validating width of framebuffer against pitch, the only thing we need to check here is that the width matches. From what I can tell, least for mxsfb, this should be covered by drm_atomic_helper_check_plane_state's can_position parameter set to false.

So I think in my case I can get away by only checking the framebuffer.

--
Stefan

Quoted 8 lines

-Daniel

Quoted 6 lines

Tomi

--
Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki. Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#7 lore raw
Quoted 93 lines · Stefan Agner
Quoted 91 lines · Daniel Vetter
Quoted 78 lines · Tomi Valkeinen

Hi,

Quoted 75 lines · Stefan Agner
Quoted 73 lines · Daniel Vetter
Quoted 62 lines · Laurent Pinchart

Hi Stefan,

Thank you for the patch.

Quoted 5 lines · Stefan Agner

The lcdif IP does not support a framebuffer pitch (stride) other than the CRTC width. Check for equality and reject the state otherwise.

This prevents a distorted picture when using 640x800 and running the Mesa graphics stack. Mesa tires to use a cache aligned stride, which

s/tires/tries/

Quoted 3 lines

leads at that particular resolution to width != stride. Currently Mesa has no fallback behavior, but rejecting this configuration allows userspace to handle the issue correctly.

I'm increasingly impressed by how featureful this IP core is :-)

Quoted 18 lines
---
 drivers/gpu/drm/mxsfb/mxsfb_kms.c | 22 ++++++++++++++++++----
 1 file changed, 18 insertions(+), 4 deletions(-)
drivers/gpu/drm/mxsfb/mxsfb_kms.c +2 -0
index b721b8b262ce..79aa14027f91 100644
@@ -403,14 +403,28 @@ static int mxsfb_plane_atomic_check(struct drm_plane *plane,
 {
        struct mxsfb_drm_private *mxsfb = to_mxsfb_drm_private(plane->dev);
        struct drm_crtc_state *crtc_state;
+       unsigned int pitch;
+       int ret;
 
        crtc_state = drm_atomic_get_new_crtc_state(plane_state->state,
                                                   &mxsfb->crtc);

drivers/gpu/drm/mxsfb/mxsfb_kms.c static int mxsfb_plane_atomic_check(struct drm_plane *plane, · line 416

Quoted 10 lines
drivers/gpu/drm/mxsfb/mxsfb_kms.c +5 -4
 
-       return drm_atomic_helper_check_plane_state(plane_state, crtc_state,
-                                                  DRM_PLANE_HELPER_NO_SCALING,
-                                                  DRM_PLANE_HELPER_NO_SCALING,
-                                                  false, true);
+       ret = drm_atomic_helper_check_plane_state(plane_state, crtc_state,
+                                                 DRM_PLANE_HELPER_NO_SCALING,
+                                                 DRM_PLANE_HELPER_NO_SCALING,
+                                                 false, true);
+       if (ret || !plane_state->visible)

Would it be more explict to check for !plane_state->fb ? Otherwise I'll have to verify that !fb always implies !visible :-)

drivers/gpu/drm/mxsfb/mxsfb_kms.c static int mxsfb_plane_atomic_check(struct drm_plane *plane, · line 420

Quoted 4 lines
drivers/gpu/drm/mxsfb/mxsfb_kms.c +4 -0
+               return ret;
+
+       pitch = crtc_state->mode.hdisplay *
+               plane_state->fb->format->cpp[0];

This holds on a single line.

drivers/gpu/drm/mxsfb/mxsfb_kms.c static int mxsfb_plane_atomic_check(struct drm_plane *plane, · line 423

Quoted 3 lines
drivers/gpu/drm/mxsfb/mxsfb_kms.c +3 -0
+       if (plane_state->fb->pitches[0] != pitch) {
+               dev_err(plane->dev->dev,
+                       "Invalid pitch: fb and crtc widths must be the same");
Quoted 5 lines

I'd turn this into a dev_dbg(), printing error messages to the kernel log in response to user-triggered conditions is a bit too verbose and could flood the log.

Wouldn't it be best to catch this issue when creating the framebuffer ?

Yeah this should be verified at addfb time. We try to validate as early as possible.
-Daniel

Quoted 7 lines
Quoted 5 lines

Sounds sensible. From what I can tell fb_create is the proper callback to implement this at addfb time. Will give this a try.

FWIW, I got the idea from drivers/gpu/drm/tilcdc/tilcdc_plane.c. Maybe should be moved to addfb there too?

But you don't know the crtc width when creating the framebuffer.

Hm right this is a different check. What we could check in fb_create for both is that the logical fb size matches exactly the pitch. That's not sufficient criteria, but it will at least catch some of them already.

Quoted 7 lines
Quoted 1 line

But yeah we'd need both here.

After validating width of framebuffer against pitch, the only thing we need to check here is that the width matches. From what I can tell, least for mxsfb, this should be covered by drm_atomic_helper_check_plane_state's can_position parameter set to false.

This only checks against the src rectangle of the crtc state, there's nothing forcing that the size of the fb matches the src rectangle exactly. I guess we could maybe add that as another parameter for hw like yours or tilcdc. Naming is a bit tricky, maybe require_matching_fb or src_must_match_fb or something like that.

Quoted 1 line

So I think in my case I can get away by only checking the framebuffer.

You still need both I think.
-Daniel

Quoted 13 lines

--
Stefan

Quoted 8 lines

-Daniel

Quoted 6 lines

Tomi

--
Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki. Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki

Signature · 7 lines
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#8 lore raw
Quoted 99 lines · Daniel Vetter
Quoted 90 lines · Stefan Agner
Quoted 89 lines · Daniel Vetter
Quoted 76 lines · Tomi Valkeinen
Quoted 75 lines · Stefan Agner
Quoted 73 lines · Daniel Vetter
Quoted 62 lines · Laurent Pinchart

Hi Stefan,

Thank you for the patch.

Quoted 5 lines · Stefan Agner

The lcdif IP does not support a framebuffer pitch (stride) other than the CRTC width. Check for equality and reject the state otherwise.

This prevents a distorted picture when using 640x800 and running the Mesa graphics stack. Mesa tires to use a cache aligned stride, which

s/tires/tries/

Quoted 3 lines

leads at that particular resolution to width != stride. Currently Mesa has no fallback behavior, but rejecting this configuration allows userspace to handle the issue correctly.

I'm increasingly impressed by how featureful this IP core is :-)

Quoted 18 lines
---
 drivers/gpu/drm/mxsfb/mxsfb_kms.c | 22 ++++++++++++++++++----
 1 file changed, 18 insertions(+), 4 deletions(-)
drivers/gpu/drm/mxsfb/mxsfb_kms.c +2 -0
index b721b8b262ce..79aa14027f91 100644
@@ -403,14 +403,28 @@ static int mxsfb_plane_atomic_check(struct drm_plane *plane,
 {
        struct mxsfb_drm_private *mxsfb = to_mxsfb_drm_private(plane->dev);
        struct drm_crtc_state *crtc_state;
+       unsigned int pitch;
+       int ret;
 
        crtc_state = drm_atomic_get_new_crtc_state(plane_state->state,
                                                   &mxsfb->crtc);

drivers/gpu/drm/mxsfb/mxsfb_kms.c static int mxsfb_plane_atomic_check(struct drm_plane *plane, · line 416

Quoted 10 lines
drivers/gpu/drm/mxsfb/mxsfb_kms.c +5 -4
 
-       return drm_atomic_helper_check_plane_state(plane_state, crtc_state,
-                                                  DRM_PLANE_HELPER_NO_SCALING,
-                                                  DRM_PLANE_HELPER_NO_SCALING,
-                                                  false, true);
+       ret = drm_atomic_helper_check_plane_state(plane_state, crtc_state,
+                                                 DRM_PLANE_HELPER_NO_SCALING,
+                                                 DRM_PLANE_HELPER_NO_SCALING,
+                                                 false, true);
+       if (ret || !plane_state->visible)

Would it be more explict to check for !plane_state->fb ? Otherwise I'll have to verify that !fb always implies !visible :-)

drivers/gpu/drm/mxsfb/mxsfb_kms.c static int mxsfb_plane_atomic_check(struct drm_plane *plane, · line 420

Quoted 4 lines
drivers/gpu/drm/mxsfb/mxsfb_kms.c +4 -0
+               return ret;
+
+       pitch = crtc_state->mode.hdisplay *
+               plane_state->fb->format->cpp[0];

This holds on a single line.

drivers/gpu/drm/mxsfb/mxsfb_kms.c static int mxsfb_plane_atomic_check(struct drm_plane *plane, · line 423

Quoted 3 lines
drivers/gpu/drm/mxsfb/mxsfb_kms.c +3 -0
+       if (plane_state->fb->pitches[0] != pitch) {
+               dev_err(plane->dev->dev,
+                       "Invalid pitch: fb and crtc widths must be the same");
Quoted 5 lines

I'd turn this into a dev_dbg(), printing error messages to the kernel log in response to user-triggered conditions is a bit too verbose and could flood the log.

Wouldn't it be best to catch this issue when creating the framebuffer ?

Yeah this should be verified at addfb time. We try to validate as early as possible.
-Daniel

Quoted 7 lines
Quoted 5 lines

Sounds sensible. From what I can tell fb_create is the proper callback to implement this at addfb time. Will give this a try.

FWIW, I got the idea from drivers/gpu/drm/tilcdc/tilcdc_plane.c. Maybe should be moved to addfb there too?

But you don't know the crtc width when creating the framebuffer.

Hm right this is a different check. What we could check in fb_create for both is that the logical fb size matches exactly the pitch. That's not sufficient criteria, but it will at least catch some of them already.

Quoted 7 lines
Quoted 1 line

But yeah we'd need both here.

After validating width of framebuffer against pitch, the only thing we need to check here is that the width matches. From what I can tell, least for mxsfb, this should be covered by drm_atomic_helper_check_plane_state's can_position parameter set to false.

Quoted 5 lines

This only checks against the src rectangle of the crtc state, there's nothing forcing that the size of the fb matches the src rectangle exactly. I guess we could maybe add that as another parameter for hw like yours or tilcdc. Naming is a bit tricky, maybe require_matching_fb or src_must_match_fb or something like that.

Can we turn those parameters into flags ? false, true, false is hard to read.

Quoted 3 lines
Quoted 1 line

So I think in my case I can get away by only checking the framebuffer.

You still need both I think.

Signature · 7 lines
Regards,

Laurent Pinchart
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#9 lore raw
Quoted 100 lines · Laurent Pinchart
Quoted 99 lines · Daniel Vetter
Quoted 97 lines · Stefan Agner
Quoted 83 lines · Daniel Vetter
Quoted 82 lines · Tomi Valkeinen
Quoted 80 lines · Stefan Agner
Quoted 67 lines · Daniel Vetter
Quoted 66 lines · Laurent Pinchart

Hi Stefan,

Thank you for the patch.

Quoted 5 lines · Stefan Agner

The lcdif IP does not support a framebuffer pitch (stride) other than the CRTC width. Check for equality and reject the state otherwise.

This prevents a distorted picture when using 640x800 and running the Mesa graphics stack. Mesa tires to use a cache aligned stride, which

s/tires/tries/

Quoted 3 lines

leads at that particular resolution to width != stride. Currently Mesa has no fallback behavior, but rejecting this configuration allows userspace to handle the issue correctly.

I'm increasingly impressed by how featureful this IP core is :-)

Quoted 18 lines
---
 drivers/gpu/drm/mxsfb/mxsfb_kms.c | 22 ++++++++++++++++++----
 1 file changed, 18 insertions(+), 4 deletions(-)
drivers/gpu/drm/mxsfb/mxsfb_kms.c +2 -0
index b721b8b262ce..79aa14027f91 100644
@@ -403,14 +403,28 @@ static int mxsfb_plane_atomic_check(struct drm_plane *plane,
 {
        struct mxsfb_drm_private *mxsfb = to_mxsfb_drm_private(plane->dev);
        struct drm_crtc_state *crtc_state;
+       unsigned int pitch;
+       int ret;
 
        crtc_state = drm_atomic_get_new_crtc_state(plane_state->state,
                                                   &mxsfb->crtc);

drivers/gpu/drm/mxsfb/mxsfb_kms.c static int mxsfb_plane_atomic_check(struct drm_plane *plane, · line 416

Quoted 10 lines
drivers/gpu/drm/mxsfb/mxsfb_kms.c +5 -4
 
-       return drm_atomic_helper_check_plane_state(plane_state, crtc_state,
-                                                  DRM_PLANE_HELPER_NO_SCALING,
-                                                  DRM_PLANE_HELPER_NO_SCALING,
-                                                  false, true);
+       ret = drm_atomic_helper_check_plane_state(plane_state, crtc_state,
+                                                 DRM_PLANE_HELPER_NO_SCALING,
+                                                 DRM_PLANE_HELPER_NO_SCALING,
+                                                 false, true);
+       if (ret || !plane_state->visible)

Would it be more explict to check for !plane_state->fb ? Otherwise I'll have to verify that !fb always implies !visible :-)

drivers/gpu/drm/mxsfb/mxsfb_kms.c static int mxsfb_plane_atomic_check(struct drm_plane *plane, · line 420

Quoted 4 lines
drivers/gpu/drm/mxsfb/mxsfb_kms.c +4 -0
+               return ret;
+
+       pitch = crtc_state->mode.hdisplay *
+               plane_state->fb->format->cpp[0];

This holds on a single line.

drivers/gpu/drm/mxsfb/mxsfb_kms.c static int mxsfb_plane_atomic_check(struct drm_plane *plane, · line 423

Quoted 3 lines
drivers/gpu/drm/mxsfb/mxsfb_kms.c +3 -0
+       if (plane_state->fb->pitches[0] != pitch) {
+               dev_err(plane->dev->dev,
+                       "Invalid pitch: fb and crtc widths must be the same");

I'd turn this into a dev_dbg(), printing error messages to the kernel log in response to user-triggered conditions is a bit too verbose and could flood the log.

Quoted 6 lines
Quoted 1 line

Wouldn't it be best to catch this issue when creating the framebuffer ?

Yeah this should be verified at addfb time. We try to validate as early as possible.
-Daniel

Sounds sensible. From what I can tell fb_create is the proper callback to implement this at addfb time. Will give this a try.

FWIW, I got the idea from drivers/gpu/drm/tilcdc/tilcdc_plane.c. Maybe should be moved to addfb there too?

Quoted 7 lines
Quoted 1 line

But you don't know the crtc width when creating the framebuffer.

Hm right this is a different check. What we could check in fb_create for both is that the logical fb size matches exactly the pitch. That's not sufficient criteria, but it will at least catch some of them already.

But yeah we'd need both here.

After validating width of framebuffer against pitch, the only thing we need to check here is that the width matches. From what I can tell, least for mxsfb, this should be covered by drm_atomic_helper_check_plane_state's can_position parameter set to false.

Quoted 8 lines
Quoted 5 lines

This only checks against the src rectangle of the crtc state, there's nothing forcing that the size of the fb matches the src rectangle exactly. I guess we could maybe add that as another parameter for hw like yours or tilcdc. Naming is a bit tricky, maybe require_matching_fb or src_must_match_fb or something like that.

Can we turn those parameters into flags ? false, true, false is hard to read.

Even the flags approach doesn't really scale past some point. Is there a particularly convincing reason for stuffing yet another check into this function as opposed to just introducing a separate function? I prefer clear single purpose functions over swiss army knives.

Quoted 13 lines
Quoted 4 lines
Quoted 2 lines

So I think in my case I can get away by only checking the framebuffer.

You still need both I think.

Signature · 7 lines
Regards,

Laurent Pinchart
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Signature · 6 lines
Ville Syrjälä
Intel
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
author maintainer
#10 lore raw
In reply to Laurent Pinchart
Quoted 100 lines · Laurent Pinchart
Quoted 99 lines · Daniel Vetter
Quoted 97 lines · Stefan Agner
Quoted 83 lines · Daniel Vetter
Quoted 82 lines · Tomi Valkeinen
Quoted 80 lines · Stefan Agner
Quoted 67 lines · Daniel Vetter
Quoted 66 lines · Laurent Pinchart

Hi Stefan,

Thank you for the patch.

Quoted 5 lines · Stefan Agner

The lcdif IP does not support a framebuffer pitch (stride) other than the CRTC width. Check for equality and reject the state otherwise.

This prevents a distorted picture when using 640x800 and running the Mesa graphics stack. Mesa tires to use a cache aligned stride, which

s/tires/tries/

Quoted 3 lines

leads at that particular resolution to width != stride. Currently Mesa has no fallback behavior, but rejecting this configuration allows userspace to handle the issue correctly.

I'm increasingly impressed by how featureful this IP core is :-)

Quoted 18 lines
---
 drivers/gpu/drm/mxsfb/mxsfb_kms.c | 22 ++++++++++++++++++----
 1 file changed, 18 insertions(+), 4 deletions(-)
drivers/gpu/drm/mxsfb/mxsfb_kms.c +2 -0
index b721b8b262ce..79aa14027f91 100644
@@ -403,14 +403,28 @@ static int mxsfb_plane_atomic_check(struct drm_plane *plane,
 {
        struct mxsfb_drm_private *mxsfb = to_mxsfb_drm_private(plane->dev);
        struct drm_crtc_state *crtc_state;
+       unsigned int pitch;
+       int ret;
 
        crtc_state = drm_atomic_get_new_crtc_state(plane_state->state,
                                                   &mxsfb->crtc);

drivers/gpu/drm/mxsfb/mxsfb_kms.c static int mxsfb_plane_atomic_check(struct drm_plane *plane, · line 416

Quoted 10 lines
drivers/gpu/drm/mxsfb/mxsfb_kms.c +5 -4
 
-       return drm_atomic_helper_check_plane_state(plane_state, crtc_state,
-                                                  DRM_PLANE_HELPER_NO_SCALING,
-                                                  DRM_PLANE_HELPER_NO_SCALING,
-                                                  false, true);
+       ret = drm_atomic_helper_check_plane_state(plane_state, crtc_state,
+                                                 DRM_PLANE_HELPER_NO_SCALING,
+                                                 DRM_PLANE_HELPER_NO_SCALING,
+                                                 false, true);
+       if (ret || !plane_state->visible)

Would it be more explict to check for !plane_state->fb ? Otherwise I'll have to verify that !fb always implies !visible :-)

drivers/gpu/drm/mxsfb/mxsfb_kms.c static int mxsfb_plane_atomic_check(struct drm_plane *plane, · line 420

Quoted 4 lines
drivers/gpu/drm/mxsfb/mxsfb_kms.c +4 -0
+               return ret;
+
+       pitch = crtc_state->mode.hdisplay *
+               plane_state->fb->format->cpp[0];

This holds on a single line.

drivers/gpu/drm/mxsfb/mxsfb_kms.c static int mxsfb_plane_atomic_check(struct drm_plane *plane, · line 423

Quoted 3 lines
drivers/gpu/drm/mxsfb/mxsfb_kms.c +3 -0
+       if (plane_state->fb->pitches[0] != pitch) {
+               dev_err(plane->dev->dev,
+                       "Invalid pitch: fb and crtc widths must be the same");

I'd turn this into a dev_dbg(), printing error messages to the kernel log in response to user-triggered conditions is a bit too verbose and could flood the log.

Quoted 6 lines
Quoted 1 line

Wouldn't it be best to catch this issue when creating the framebuffer ?

Yeah this should be verified at addfb time. We try to validate as early as possible.
-Daniel

Sounds sensible. From what I can tell fb_create is the proper callback to implement this at addfb time. Will give this a try.

FWIW, I got the idea from drivers/gpu/drm/tilcdc/tilcdc_plane.c. Maybe should be moved to addfb there too?

Quoted 7 lines
Quoted 1 line

But you don't know the crtc width when creating the framebuffer.

Hm right this is a different check. What we could check in fb_create for both is that the logical fb size matches exactly the pitch. That's not sufficient criteria, but it will at least catch some of them already.

But yeah we'd need both here.

After validating width of framebuffer against pitch, the only thing we need to check here is that the width matches. From what I can tell, least for mxsfb, this should be covered by drm_atomic_helper_check_plane_state's can_position parameter set to false.

Quoted 9 lines
Quoted 5 lines

This only checks against the src rectangle of the crtc state, there's nothing forcing that the size of the fb matches the src rectangle exactly. I guess we could maybe add that as another parameter for hw like yours or tilcdc. Naming is a bit tricky, maybe require_matching_fb or src_must_match_fb or something like that.

Can we turn those parameters into flags ? false, true, false is hard to read.

Since it must match, in this case, it would be false, true, true, obviously ;-)

I guess this would mean to convert the two existing boolean parameters to flags first, and then introduce a new flag handling fb size vs. CRTC src.

Hm, this gets all a bit more involved. It is actually not the issue at hand (in my case the fb width does match the CRTC). Not sure if that case is actually a problem in real world? I can give this a shot still, if preferred. But I would do it independently of the framebuffer pitch validation.

--
Stefan

Quoted 3 lines
Quoted 3 lines
Quoted 1 line

So I think in my case I can get away by only checking the framebuffer.

You still need both I think.

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#11 lore raw
In reply to Daniel Vetter
Quoted 81 lines · Daniel Vetter
Quoted 80 lines · Tomi Valkeinen
Quoted 78 lines · Stefan Agner
Quoted 67 lines · Daniel Vetter
Quoted 66 lines · Laurent Pinchart

Hi Stefan,

Thank you for the patch.

Quoted 5 lines · Stefan Agner

The lcdif IP does not support a framebuffer pitch (stride) other than the CRTC width. Check for equality and reject the state otherwise.

This prevents a distorted picture when using 640x800 and running the Mesa graphics stack. Mesa tires to use a cache aligned stride, which

s/tires/tries/

Quoted 3 lines

leads at that particular resolution to width != stride. Currently Mesa has no fallback behavior, but rejecting this configuration allows userspace to handle the issue correctly.

I'm increasingly impressed by how featureful this IP core is :-)

Quoted 18 lines
---
 drivers/gpu/drm/mxsfb/mxsfb_kms.c | 22 ++++++++++++++++++----
 1 file changed, 18 insertions(+), 4 deletions(-)
drivers/gpu/drm/mxsfb/mxsfb_kms.c +2 -0
index b721b8b262ce..79aa14027f91 100644
@@ -403,14 +403,28 @@ static int mxsfb_plane_atomic_check(struct drm_plane *plane,
 {
 	struct mxsfb_drm_private *mxsfb = to_mxsfb_drm_private(plane->dev);
 	struct drm_crtc_state *crtc_state;
+	unsigned int pitch;
+	int ret;
 
 	crtc_state = drm_atomic_get_new_crtc_state(plane_state->state,
 						   &mxsfb->crtc);

drivers/gpu/drm/mxsfb/mxsfb_kms.c static int mxsfb_plane_atomic_check(struct drm_plane *plane, · line 416

Quoted 10 lines
drivers/gpu/drm/mxsfb/mxsfb_kms.c +5 -4
 
-	return drm_atomic_helper_check_plane_state(plane_state, crtc_state,
-						   DRM_PLANE_HELPER_NO_SCALING,
-						   DRM_PLANE_HELPER_NO_SCALING,
-						   false, true);
+	ret = drm_atomic_helper_check_plane_state(plane_state, crtc_state,
+						  DRM_PLANE_HELPER_NO_SCALING,
+						  DRM_PLANE_HELPER_NO_SCALING,
+						  false, true);
+	if (ret || !plane_state->visible)

Would it be more explict to check for !plane_state->fb ? Otherwise I'll have to verify that !fb always implies !visible :-)

drivers/gpu/drm/mxsfb/mxsfb_kms.c static int mxsfb_plane_atomic_check(struct drm_plane *plane, · line 420

Quoted 4 lines
drivers/gpu/drm/mxsfb/mxsfb_kms.c +4 -0
+		return ret;
+
+	pitch = crtc_state->mode.hdisplay *
+		plane_state->fb->format->cpp[0];

This holds on a single line.

drivers/gpu/drm/mxsfb/mxsfb_kms.c static int mxsfb_plane_atomic_check(struct drm_plane *plane, · line 423

Quoted 3 lines
drivers/gpu/drm/mxsfb/mxsfb_kms.c +3 -0
+	if (plane_state->fb->pitches[0] != pitch) {
+		dev_err(plane->dev->dev,
+			"Invalid pitch: fb and crtc widths must be the same");

I'd turn this into a dev_dbg(), printing error messages to the kernel log in response to user-triggered conditions is a bit too verbose and could flood the log.

Quoted 4 lines
Quoted 1 line

Wouldn't it be best to catch this issue when creating the framebuffer ?

Yeah this should be verified at addfb time. We try to validate as early as possible.

Sounds sensible. From what I can tell fb_create is the proper callback to implement this at addfb time. Will give this a try.

FWIW, I got the idea from drivers/gpu/drm/tilcdc/tilcdc_plane.c. Maybe should be moved to addfb there too?

Quoted 7 lines
Quoted 1 line

But you don't know the crtc width when creating the framebuffer.

Hm right this is a different check. What we could check in fb_create for both is that the logical fb size matches exactly the pitch. That's not sufficient criteria, but it will at least catch some of them already.

But yeah we'd need both here.

Correct. At addfb time we can check the pitch, and at atomic check time we should check that the plane spans the whole CRTC.

Signature · 7 lines
Regards,

Laurent Pinchart
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#12 lore raw
In reply to Stefan Agner

Am 2020-09-07 16:03, schrieb Stefan Agner:

Quoted 2 lines

The lcdif IP does not support a framebuffer pitch (stride) other than the CRTC width.

This may be true for some SOCs, but not for all of them. I used to have this working flawlessly on the imx8mq like so:
http://projects.dpa.li/git/?p=linux.git;a=commitdiff;h=5a7baa8ba7f1f30139cfcd0f9e13b3773f3605ff

That in turn was based on some patches which weren't fully upstreamed yet at the time, and was inspired by another patch I had seen here:
https://lore.kernel.org/linux-arm-kernel/20190722174853.GA31795@bogus/t/#m7ac218480eb1d827ff65f82f2e03a5a84c94a5e0

I had almost forgotten about this already, since I currently don't need it anymore, and I was waiting for the patches it was based on to get taken up. But if anyone else needs this, feel free to do whatever you want with it.
I could also take another look at this and submit some patches if this is preferred, but I'm quiet busy right now, so that could take a while.

In the meantime and for other SOCs, I think checking for an unsupported pitch is still needed regardless. I'm not against this patch, this is just a note to make sure it's known that and how this can be done on the imx8mq.

Regards,
Daniel Abrecht
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel