Skip to contentSkip to conversation

drm/modes: Apply video parameters with only reflect option

PATCH Superseded Stephan Gerhold 3 participants 5 messages Dec 16, 2019 – Jan 16, 2020

Subsystems (2)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 drm/modes: Apply video parameters with only reflect option

At the moment, video mode parameters like video=540x960,reflect_x, (without rotation set) are not taken into account when applying the mode in drm_client_modeset.c.

One of the reasons for this is that the calculation that combines the panel_orientation with cmdline->rotation_reflection does not handle the case when cmdline->rotation_reflection does not have any rotation set.
(i.e. cmdline->rotation_reflection & DRM_MODE_ROTATE_MASK == 0)

Example:
*rotation = DRM_MODE_ROTATE_0 (no panel_orientation) cmdline->rotation_reflection = DRM_MODE_REFLECT_X (video=MODE,reflect_x)

The current code does:
panel_rot = ilog2(*rotation & DRM_MODE_ROTATE_MASK); cmdline_rot = ilog2(cmdline->rotation_reflection & DRM_MODE_ROTATE_MASK); sum_rot = (panel_rot + cmdline_rot) % 4;

and therefore:
panel_rot = ilog2(DRM_MODE_ROTATE_0) = ilog2(1) = 0 cmdline_rot = ilog2(0) = -1
sum_rot = (0 + -1) % 4 = -1 % 4 = 3
...
*rotation = DRM_MODE_ROTATE_270 | DRM_MODE_REFLECT_X

So we incorrectly generate DRM_MODE_ROTATE_270 in this case. To prevent cmdline_rot from becoming -1, we need to treat the rotation as DRM_MODE_ROTATE_0.

On the other hand, there is no need to go through that calculation at all if no rotation is set in rotation_reflection.
A simple XOR is enough to combine the reflections.

Finally, also allow DRM_MODE_ROTATE_0 in the if statement below. DRM_MODE_ROTATE_0 means "no rotation" and should therefore not require any special handling (e.g. specific tiling format).

This makes video parameters with only reflect option work correctly.

---
v1: https://lists.freedesktop.org/archives/dri-devel/2019-December/248145.html

Changes in v2:
- Clarified commit message - parameters are parsed correctly, but not taken into account when applying the mode.

---
 drivers/gpu/drm/drm_client_modeset.c | 27 ++++++++++++++++-----------
 1 file changed, 16 insertions(+), 11 deletions(-)
drivers/gpu/drm/drm_client_modeset.c +16 -11
index 895b73f23079..cfebce4f19a5 100644
@@ -859,19 +859,23 @@ bool drm_client_rotation(struct drm_mode_set *modeset, unsigned int *rotation)
 	 */
 	cmdline = &connector->cmdline_mode;
 	if (cmdline->specified && cmdline->rotation_reflection) {
-		unsigned int cmdline_rest, panel_rest;
-		unsigned int cmdline_rot, panel_rot;
-		unsigned int sum_rot, sum_rest;
+		if (cmdline->rotation_reflection & DRM_MODE_ROTATE_MASK) {
+			unsigned int cmdline_rest, panel_rest;
+			unsigned int cmdline_rot, panel_rot;
+			unsigned int sum_rot, sum_rest;
 
-		panel_rot = ilog2(*rotation & DRM_MODE_ROTATE_MASK);
-		cmdline_rot = ilog2(cmdline->rotation_reflection & DRM_MODE_ROTATE_MASK);
-		sum_rot = (panel_rot + cmdline_rot) % 4;
+			panel_rot = ilog2(*rotation & DRM_MODE_ROTATE_MASK);
+			cmdline_rot = ilog2(cmdline->rotation_reflection & DRM_MODE_ROTATE_MASK);
+			sum_rot = (panel_rot + cmdline_rot) % 4;
 
-		panel_rest = *rotation & ~DRM_MODE_ROTATE_MASK;
-		cmdline_rest = cmdline->rotation_reflection & ~DRM_MODE_ROTATE_MASK;
-		sum_rest = panel_rest ^ cmdline_rest;
+			panel_rest = *rotation & ~DRM_MODE_ROTATE_MASK;
+			cmdline_rest = cmdline->rotation_reflection & ~DRM_MODE_ROTATE_MASK;
+			sum_rest = panel_rest ^ cmdline_rest;
 
-		*rotation = (1 << sum_rot) | sum_rest;
+			*rotation = (1 << sum_rot) | sum_rest;
+		} else {
+			*rotation ^= cmdline->rotation_reflection;
+		}
 	}
 
 	/*
@@ -879,7 +883,8 @@ bool drm_client_rotation(struct drm_mode_set *modeset, unsigned int *rotation)
 	 * depending on the hardware this may require the framebuffer
 	 * to be in a specific tiling format.
 	 */
-	if ((*rotation & DRM_MODE_ROTATE_MASK) != DRM_MODE_ROTATE_180 ||
+	if (((*rotation & DRM_MODE_ROTATE_MASK) != DRM_MODE_ROTATE_0 &&
+	     (*rotation & DRM_MODE_ROTATE_MASK) != DRM_MODE_ROTATE_180) ||
 	    !plane->rotation_property)
 		return false;
 
Signature · 6 lines
2.24.1

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#1 lore raw
Quoted 3 lines · Stephan Gerhold

At the moment, video mode parameters like video=540x960,reflect_x, (without rotation set) are not taken into account when applying the mode in drm_client_modeset.c.

A rotation value without exactly one rotation angle is illegal. IMO the code should not generate a value like that in the first place.

Quoted 103 lines

One of the reasons for this is that the calculation that combines the panel_orientation with cmdline->rotation_reflection does not handle the case when cmdline->rotation_reflection does not have any rotation set.
(i.e. cmdline->rotation_reflection & DRM_MODE_ROTATE_MASK == 0)

Example:
*rotation = DRM_MODE_ROTATE_0 (no panel_orientation) cmdline->rotation_reflection = DRM_MODE_REFLECT_X (video=MODE,reflect_x)

The current code does:
panel_rot = ilog2(*rotation & DRM_MODE_ROTATE_MASK); cmdline_rot = ilog2(cmdline->rotation_reflection & DRM_MODE_ROTATE_MASK); sum_rot = (panel_rot + cmdline_rot) % 4;

and therefore:
panel_rot = ilog2(DRM_MODE_ROTATE_0) = ilog2(1) = 0 cmdline_rot = ilog2(0) = -1
sum_rot = (0 + -1) % 4 = -1 % 4 = 3
...
*rotation = DRM_MODE_ROTATE_270 | DRM_MODE_REFLECT_X

So we incorrectly generate DRM_MODE_ROTATE_270 in this case. To prevent cmdline_rot from becoming -1, we need to treat the rotation as DRM_MODE_ROTATE_0.

On the other hand, there is no need to go through that calculation at all if no rotation is set in rotation_reflection.
A simple XOR is enough to combine the reflections.

Finally, also allow DRM_MODE_ROTATE_0 in the if statement below. DRM_MODE_ROTATE_0 means "no rotation" and should therefore not require any special handling (e.g. specific tiling format).

This makes video parameters with only reflect option work correctly.

---
v1: https://lists.freedesktop.org/archives/dri-devel/2019-December/248145.html

Changes in v2:
- Clarified commit message - parameters are parsed correctly, but not taken into account when applying the mode.

---
 drivers/gpu/drm/drm_client_modeset.c | 27 ++++++++++++++++-----------
 1 file changed, 16 insertions(+), 11 deletions(-)
drivers/gpu/drm/drm_client_modeset.c +16 -11
index 895b73f23079..cfebce4f19a5 100644
@@ -859,19 +859,23 @@ bool drm_client_rotation(struct drm_mode_set *modeset, unsigned int *rotation)
 	 */
 	cmdline = &connector->cmdline_mode;
 	if (cmdline->specified && cmdline->rotation_reflection) {
-		unsigned int cmdline_rest, panel_rest;
-		unsigned int cmdline_rot, panel_rot;
-		unsigned int sum_rot, sum_rest;
+		if (cmdline->rotation_reflection & DRM_MODE_ROTATE_MASK) {
+			unsigned int cmdline_rest, panel_rest;
+			unsigned int cmdline_rot, panel_rot;
+			unsigned int sum_rot, sum_rest;
 
-		panel_rot = ilog2(*rotation & DRM_MODE_ROTATE_MASK);
-		cmdline_rot = ilog2(cmdline->rotation_reflection & DRM_MODE_ROTATE_MASK);
-		sum_rot = (panel_rot + cmdline_rot) % 4;
+			panel_rot = ilog2(*rotation & DRM_MODE_ROTATE_MASK);
+			cmdline_rot = ilog2(cmdline->rotation_reflection & DRM_MODE_ROTATE_MASK);
+			sum_rot = (panel_rot + cmdline_rot) % 4;
 
-		panel_rest = *rotation & ~DRM_MODE_ROTATE_MASK;
-		cmdline_rest = cmdline->rotation_reflection & ~DRM_MODE_ROTATE_MASK;
-		sum_rest = panel_rest ^ cmdline_rest;
+			panel_rest = *rotation & ~DRM_MODE_ROTATE_MASK;
+			cmdline_rest = cmdline->rotation_reflection & ~DRM_MODE_ROTATE_MASK;
+			sum_rest = panel_rest ^ cmdline_rest;
 
-		*rotation = (1 << sum_rot) | sum_rest;
+			*rotation = (1 << sum_rot) | sum_rest;
+		} else {
+			*rotation ^= cmdline->rotation_reflection;
+		}
 	}
 
 	/*
@@ -879,7 +883,8 @@ bool drm_client_rotation(struct drm_mode_set *modeset, unsigned int *rotation)
 	 * depending on the hardware this may require the framebuffer
 	 * to be in a specific tiling format.
 	 */
-	if ((*rotation & DRM_MODE_ROTATE_MASK) != DRM_MODE_ROTATE_180 ||
+	if (((*rotation & DRM_MODE_ROTATE_MASK) != DRM_MODE_ROTATE_0 &&
+	     (*rotation & DRM_MODE_ROTATE_MASK) != DRM_MODE_ROTATE_180) ||
 	    !plane->rotation_property)
 		return false;
 
Signature · 6 lines
2.24.1

_______________________________________________
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
#2 lore raw
Quoted 9 lines · Ville Syrjälä
Quoted 3 lines · Stephan Gerhold

At the moment, video mode parameters like video=540x960,reflect_x, (without rotation set) are not taken into account when applying the mode in drm_client_modeset.c.

A rotation value without exactly one rotation angle is illegal. IMO the code should not generate a value like that in the first place.

You're right. I was thinking about this when creating this patch. But then I was not sure if "mode->rotation_reflection" is supposed to be a valid rotation value.The zero value is currently used to check if any rotation/reflection was specified at all:

[...]

Quoted 8 lines

drivers/gpu/drm/drm_client_modeset.c bool drm_client_rotation(struct drm_mode_set *modeset, unsigned int *rotation) · line 861

Quoted 8 lines
drivers/gpu/drm/drm_client_modeset.c +0 -0
index 895b73f23079..cfebce4f19a5 100644
@@ -859,19 +859,23 @@ bool drm_client_rotation(struct drm_mode_set *modeset, unsigned int *rotation)
 	 */
 	cmdline = &connector->cmdline_mode;
 	if (cmdline->specified && cmdline->rotation_reflection) {

I can try to make your suggested change in the cmdline parsing code, but since this sounds like a larger change I would appreciate some other opinions first.

Thanks,
Stephan

Quoted 41 lines
Quoted 41 lines
drivers/gpu/drm/drm_client_modeset.c +16 -11
-		unsigned int cmdline_rest, panel_rest;
-		unsigned int cmdline_rot, panel_rot;
-		unsigned int sum_rot, sum_rest;
+		if (cmdline->rotation_reflection & DRM_MODE_ROTATE_MASK) {
+			unsigned int cmdline_rest, panel_rest;
+			unsigned int cmdline_rot, panel_rot;
+			unsigned int sum_rot, sum_rest;
 
-		panel_rot = ilog2(*rotation & DRM_MODE_ROTATE_MASK);
-		cmdline_rot = ilog2(cmdline->rotation_reflection & DRM_MODE_ROTATE_MASK);
-		sum_rot = (panel_rot + cmdline_rot) % 4;
+			panel_rot = ilog2(*rotation & DRM_MODE_ROTATE_MASK);
+			cmdline_rot = ilog2(cmdline->rotation_reflection & DRM_MODE_ROTATE_MASK);
+			sum_rot = (panel_rot + cmdline_rot) % 4;
 
-		panel_rest = *rotation & ~DRM_MODE_ROTATE_MASK;
-		cmdline_rest = cmdline->rotation_reflection & ~DRM_MODE_ROTATE_MASK;
-		sum_rest = panel_rest ^ cmdline_rest;
+			panel_rest = *rotation & ~DRM_MODE_ROTATE_MASK;
+			cmdline_rest = cmdline->rotation_reflection & ~DRM_MODE_ROTATE_MASK;
+			sum_rest = panel_rest ^ cmdline_rest;
 
-		*rotation = (1 << sum_rot) | sum_rest;
+			*rotation = (1 << sum_rot) | sum_rest;
+		} else {
+			*rotation ^= cmdline->rotation_reflection;
+		}
 	}
 
 	/*
@@ -879,7 +883,8 @@ bool drm_client_rotation(struct drm_mode_set *modeset, unsigned int *rotation)
 	 * depending on the hardware this may require the framebuffer
 	 * to be in a specific tiling format.
 	 */
-	if ((*rotation & DRM_MODE_ROTATE_MASK) != DRM_MODE_ROTATE_180 ||
+	if (((*rotation & DRM_MODE_ROTATE_MASK) != DRM_MODE_ROTATE_0 &&
+	     (*rotation & DRM_MODE_ROTATE_MASK) != DRM_MODE_ROTATE_180) ||
 	    !plane->rotation_property)
 		return false;
 
Quoted 11 lines
Quoted 7 lines
Signature · 6 lines
2.24.1

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Signature · 2 lines
Ville Syrjälä
Intel

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

#3 lore raw

Hi Maxime,

Quoted 10 lines · Stephan Gerhold
Quoted 9 lines · Ville Syrjälä
Quoted 3 lines · Stephan Gerhold

At the moment, video mode parameters like video=540x960,reflect_x, (without rotation set) are not taken into account when applying the mode in drm_client_modeset.c.

A rotation value without exactly one rotation angle is illegal. IMO the code should not generate a value like that in the first place.

What do you think about Ville's comment?
Should we change the command line parser to generate ROTATE_0 when no rotate option is specified? This would also require updating a few of the test cases.

You added the code for parsing the rotation/reflection options, so I thought I'd ask before I start working on this.

Thanks,
Stephan

Quoted 20 lines

You're right. I was thinking about this when creating this patch. But then I was not sure if "mode->rotation_reflection" is supposed to be a valid rotation value.The zero value is currently used to check if any rotation/reflection was specified at all:

[...]

Quoted 8 lines

drivers/gpu/drm/drm_client_modeset.c bool drm_client_rotation(struct drm_mode_set *modeset, unsigned int *rotation) · line 861

Quoted 8 lines
drivers/gpu/drm/drm_client_modeset.c +0 -0
index 895b73f23079..cfebce4f19a5 100644
@@ -859,19 +859,23 @@ bool drm_client_rotation(struct drm_mode_set *modeset, unsigned int *rotation)
 	 */
 	cmdline = &connector->cmdline_mode;
 	if (cmdline->specified && cmdline->rotation_reflection) {

I can try to make your suggested change in the cmdline parsing code, but since this sounds like a larger change I would appreciate some other opinions first.

Quoted 55 lines

Thanks,
Stephan

Quoted 52 lines
Quoted 48 lines
drivers/gpu/drm/drm_client_modeset.c +16 -11
-		unsigned int cmdline_rest, panel_rest;
-		unsigned int cmdline_rot, panel_rot;
-		unsigned int sum_rot, sum_rest;
+		if (cmdline->rotation_reflection & DRM_MODE_ROTATE_MASK) {
+			unsigned int cmdline_rest, panel_rest;
+			unsigned int cmdline_rot, panel_rot;
+			unsigned int sum_rot, sum_rest;
 
-		panel_rot = ilog2(*rotation & DRM_MODE_ROTATE_MASK);
-		cmdline_rot = ilog2(cmdline->rotation_reflection & DRM_MODE_ROTATE_MASK);
-		sum_rot = (panel_rot + cmdline_rot) % 4;
+			panel_rot = ilog2(*rotation & DRM_MODE_ROTATE_MASK);
+			cmdline_rot = ilog2(cmdline->rotation_reflection & DRM_MODE_ROTATE_MASK);
+			sum_rot = (panel_rot + cmdline_rot) % 4;
 
-		panel_rest = *rotation & ~DRM_MODE_ROTATE_MASK;
-		cmdline_rest = cmdline->rotation_reflection & ~DRM_MODE_ROTATE_MASK;
-		sum_rest = panel_rest ^ cmdline_rest;
+			panel_rest = *rotation & ~DRM_MODE_ROTATE_MASK;
+			cmdline_rest = cmdline->rotation_reflection & ~DRM_MODE_ROTATE_MASK;
+			sum_rest = panel_rest ^ cmdline_rest;
 
-		*rotation = (1 << sum_rot) | sum_rest;
+			*rotation = (1 << sum_rot) | sum_rest;
+		} else {
+			*rotation ^= cmdline->rotation_reflection;
+		}
 	}
 
 	/*
@@ -879,7 +883,8 @@ bool drm_client_rotation(struct drm_mode_set *modeset, unsigned int *rotation)
 	 * depending on the hardware this may require the framebuffer
 	 * to be in a specific tiling format.
 	 */
-	if ((*rotation & DRM_MODE_ROTATE_MASK) != DRM_MODE_ROTATE_180 ||
+	if (((*rotation & DRM_MODE_ROTATE_MASK) != DRM_MODE_ROTATE_0 &&
+	     (*rotation & DRM_MODE_ROTATE_MASK) != DRM_MODE_ROTATE_180) ||
 	    !plane->rotation_property)
 		return false;
 
Signature · 6 lines
2.24.1

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Signature · 2 lines
Ville Syrjälä
Intel

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

maintainer
#4 lore raw

Hi Stephan,

Quoted 12 lines · Stephan Gerhold
Quoted 10 lines · Stephan Gerhold
Quoted 9 lines · Ville Syrjälä
Quoted 3 lines · Stephan Gerhold

At the moment, video mode parameters like video=540x960,reflect_x, (without rotation set) are not taken into account when applying the mode in drm_client_modeset.c.

A rotation value without exactly one rotation angle is illegal. IMO the code should not generate a value like that in the first place.

Quoted 4 lines

What do you think about Ville's comment?
Should we change the command line parser to generate ROTATE_0 when no rotate option is specified? This would also require updating a few of the test cases.

I agree with him :)

Maxime

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