Skip to contentSkip to conversation

drm/atomic: Disable planes on blanked CRTC and enable on unblank

RFC PATCH Superseded Jyri Sarha 2 participants 4 messages Nov 5, 2015 – Nov 18, 2015

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Jyri Sarha

author
#0 lore raw

RFC PATCH 1/1 drm/atomic: Disable planes on blanked CRTC and enable on unblank

Disable planes if they are on to be blanked CRTC and enable them when the CRTC is turned back on by DMPS.

This is desirable on HW that loses its context on blanking. When planes are enabled and disabled with the associated CRTCs, there is no need to restore the plane context in runtime_resume callback.

---
We would need something like this to get rid off OMAPDSS somewhat messy runtime_resume code. How does this look, could this generic solution be refined to be acceptable to mainline, or should we start looking a local solution to omapdrm?

BTW, with this patch the planes are sometimes disabled multiple times. So probably a boolean (or maybe two like on crtc) should be added to drm_plane_state to track and avoid multiple shutdowns.

 drivers/gpu/drm/drm_atomic_helper.c | 19 +++++++++++++++++--
 include/drm/drm_atomic_helper.h     |  7 +++++++
 2 files changed, 24 insertions(+), 2 deletions(-)
drivers/gpu/drm/drm_atomic_helper.c +17 -2
index aecb5d6..92fcaef 100644
@@ -1994,8 +1994,8 @@ EXPORT_SYMBOL(drm_atomic_helper_page_flip);
  *
  * This is the main helper function provided by the atomic helper framework for
  * implementing the legacy DPMS connector interface. It computes the new desired
- * ->active state for the corresponding CRTC (if the connector is enabled) and
- *  updates it.
+ * ->active state for the corresponding CRTC and planes on it (if the connector
+ * is enabled) and updates it.
  *
  * Returns:
  * Returns 0 on success, negative errno numbers on failure.
@@ -2008,6 +2008,7 @@ int drm_atomic_helper_connector_dpms(struct drm_connector *connector,
 	struct drm_crtc_state *crtc_state;
 	struct drm_crtc *crtc;
 	struct drm_connector *tmp_connector;
+	struct drm_plane *tmp_plane;
 	int ret;
 	bool active = false;
 	int old_mode = connector->dpms;
@@ -2046,6 +2047,20 @@ retry:
 	}
 	crtc_state->active = active;
 
+	/* Collect associated plane states to global state object. */
+	list_for_each_entry(tmp_plane, &config->plane_list, head) {
+		struct drm_plane_state *plane_state;
+
+		if (tmp_plane->state->crtc != crtc)
+			continue;
+
+		plane_state = drm_atomic_get_plane_state(state, tmp_plane);
+		if (IS_ERR(plane_state)) {
+			ret = PTR_ERR(plane_state);
+			goto fail;
+		}
+	}
+
 	ret = drm_atomic_commit(state);
 	if (ret != 0)
 		goto fail;
include/drm/drm_atomic_helper.h +7 -0
index 11266d14..89c327f 100644
@@ -173,6 +173,13 @@ drm_atomic_plane_disabling(struct drm_plane *plane,
 		(plane->state->crtc != NULL && plane->state->fb == NULL));
 
 	/*
+	 * If the plane is on a crtc that is not going to be active the plane
+	 * it self can be disabled too.
+	 */
+	if (plane->state->crtc && !plane->state->crtc->state->active)
+		return true;
+
+	/*
 	 * When using the transitional helpers, old_state may be NULL. If so,
 	 * we know nothing about the current state and have to assume that it
 	 * might be enabled.
Signature · 6 lines
1.9.1

_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel
#1 lore raw
Quoted 14 lines · Jyri Sarha

Disable planes if they are on to be blanked CRTC and enable them when the CRTC is turned back on by DMPS.

This is desirable on HW that loses its context on blanking. When planes are enabled and disabled with the associated CRTCs, there is no need to restore the plane context in runtime_resume callback.

---
We would need something like this to get rid off OMAPDSS somewhat messy runtime_resume code. How does this look, could this generic solution be refined to be acceptable to mainline, or should we start looking a local solution to omapdrm?

Quoted 3 lines

BTW, with this patch the planes are sometimes disabled multiple times. So probably a boolean (or maybe two like on crtc) should be added to drm_plane_state to track and avoid multiple shutdowns.

The recommended way to do this is to call drm_atomic_add_affected_planes from your crtc's atomic_check callback when active_changed is set. This will also take care of enabling all planes again. For disabling we don't yet have a helper yet, but it would be easy to create a drm_atomic_helper_disable_planes(crtc) which just walks over all planes in an atomic update that are currently using the given crtc and disables it using plane_helper_funcs->atomic_disable. That would again require drm_atomic_add_affected_planes to be called first.

This way current helper behaviour is unchanged, but it'd be easy to construct the behaviour you want using helpers with drm_atomic_add_affected_planes called from the crtc->disable hook.

I thought there was an rfc patch somewhere for this, but I can't find it any more.

Cheers, Daniel

Quoted 74 lines
 drivers/gpu/drm/drm_atomic_helper.c | 19 +++++++++++++++++--
 include/drm/drm_atomic_helper.h     |  7 +++++++
 2 files changed, 24 insertions(+), 2 deletions(-)
drivers/gpu/drm/drm_atomic_helper.c +17 -2
index aecb5d6..92fcaef 100644
@@ -1994,8 +1994,8 @@ EXPORT_SYMBOL(drm_atomic_helper_page_flip);
  *
  * This is the main helper function provided by the atomic helper framework for
  * implementing the legacy DPMS connector interface. It computes the new desired
- * ->active state for the corresponding CRTC (if the connector is enabled) and
- *  updates it.
+ * ->active state for the corresponding CRTC and planes on it (if the connector
+ * is enabled) and updates it.
  *
  * Returns:
  * Returns 0 on success, negative errno numbers on failure.
@@ -2008,6 +2008,7 @@ int drm_atomic_helper_connector_dpms(struct drm_connector *connector,
 	struct drm_crtc_state *crtc_state;
 	struct drm_crtc *crtc;
 	struct drm_connector *tmp_connector;
+	struct drm_plane *tmp_plane;
 	int ret;
 	bool active = false;
 	int old_mode = connector->dpms;
@@ -2046,6 +2047,20 @@ retry:
 	}
 	crtc_state->active = active;
 
+	/* Collect associated plane states to global state object. */
+	list_for_each_entry(tmp_plane, &config->plane_list, head) {
+		struct drm_plane_state *plane_state;
+
+		if (tmp_plane->state->crtc != crtc)
+			continue;
+
+		plane_state = drm_atomic_get_plane_state(state, tmp_plane);
+		if (IS_ERR(plane_state)) {
+			ret = PTR_ERR(plane_state);
+			goto fail;
+		}
+	}
+
 	ret = drm_atomic_commit(state);
 	if (ret != 0)
 		goto fail;
include/drm/drm_atomic_helper.h +7 -0
index 11266d14..89c327f 100644
@@ -173,6 +173,13 @@ drm_atomic_plane_disabling(struct drm_plane *plane,
 		(plane->state->crtc != NULL && plane->state->fb == NULL));
 
 	/*
+	 * If the plane is on a crtc that is not going to be active the plane
+	 * it self can be disabled too.
+	 */
+	if (plane->state->crtc && !plane->state->crtc->state->active)
+		return true;
+
+	/*
 	 * When using the transitional helpers, old_state may be NULL. If so,
 	 * we know nothing about the current state and have to assume that it
 	 * might be enabled.
Signature · 6 lines
1.9.1

_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel
Signature · 7 lines
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel
author
#2 lore raw
Quoted 28 lines · Daniel Vetter
Quoted 14 lines · Jyri Sarha

Disable planes if they are on to be blanked CRTC and enable them when the CRTC is turned back on by DMPS.

This is desirable on HW that loses its context on blanking. When planes are enabled and disabled with the associated CRTCs, there is no need to restore the plane context in runtime_resume callback.

---
We would need something like this to get rid off OMAPDSS somewhat messy runtime_resume code. How does this look, could this generic solution be refined to be acceptable to mainline, or should we start looking a local solution to omapdrm?

Quoted 3 lines

BTW, with this patch the planes are sometimes disabled multiple times. So probably a boolean (or maybe two like on crtc) should be added to drm_plane_state to track and avoid multiple shutdowns.

The recommended way to do this is to call drm_atomic_add_affected_planes from your crtc's atomic_check callback when active_changed is set. This will also take care of enabling all planes again. For disabling we don't yet have a helper yet, but it would be easy to create a drm_atomic_helper_disable_planes(crtc) which just walks over all planes in an atomic update that are currently using the given crtc and disables it using plane_helper_funcs->atomic_disable. That would again require drm_atomic_add_affected_planes to be called first.

Quoted 6 lines

This way current helper behaviour is unchanged, but it'd be easy to construct the behaviour you want using helpers with drm_atomic_add_affected_planes called from the crtc->disable hook.

I thought there was an rfc patch somewhere for this, but I can't find it any more.

It appears that in the end these instructions were really all I needed.

There is only one thing that still bothers me. When implementing the feature you described above, I had a print in the code to see if it actually did anything. At first - because of my mistake - it did not, but the plane context was still restored just fine on drm_next and mainline linux. However the same omapdrm code did not restore the plane context on our 4.1 based Linux branch.

So something similar to what I tried to accomplish has been implemented some where between Linux 4.1 and 4.3?

Anyway, after back-porting the above fix works perfectly on our 4.1 based branch.

Thanks,
Jyri

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

#3 lore raw
Quoted 45 lines · Jyri Sarha
Quoted 28 lines · Daniel Vetter
Quoted 14 lines · Jyri Sarha

Disable planes if they are on to be blanked CRTC and enable them when the CRTC is turned back on by DMPS.

This is desirable on HW that loses its context on blanking. When planes are enabled and disabled with the associated CRTCs, there is no need to restore the plane context in runtime_resume callback.

---
We would need something like this to get rid off OMAPDSS somewhat messy runtime_resume code. How does this look, could this generic solution be refined to be acceptable to mainline, or should we start looking a local solution to omapdrm?

Quoted 3 lines

BTW, with this patch the planes are sometimes disabled multiple times. So probably a boolean (or maybe two like on crtc) should be added to drm_plane_state to track and avoid multiple shutdowns.

The recommended way to do this is to call drm_atomic_add_affected_planes from your crtc's atomic_check callback when active_changed is set. This will also take care of enabling all planes again. For disabling we don't yet have a helper yet, but it would be easy to create a drm_atomic_helper_disable_planes(crtc) which just walks over all planes in an atomic update that are currently using the given crtc and disables it using plane_helper_funcs->atomic_disable. That would again require drm_atomic_add_affected_planes to be called first.

Quoted 6 lines

This way current helper behaviour is unchanged, but it'd be easy to construct the behaviour you want using helpers with drm_atomic_add_affected_planes called from the crtc->disable hook.

I thought there was an rfc patch somewhere for this, but I can't find it any more.

It appears that in the end these instructions were really all I needed.

There is only one thing that still bothers me. When implementing the feature you described above, I had a print in the code to see if it actually did anything. At first - because of my mistake - it did not, but the plane context was still restored just fine on drm_next and mainline linux. However the same omapdrm code did not restore the plane context on our 4.1 based Linux branch.

Quoted 5 lines

So something similar to what I tried to accomplish has been implemented some where between Linux 4.1 and 4.3?

Anyway, after back-porting the above fix works perfectly on our 4.1 based branch.

commit 57744aa7cfb5969c5a0621f4cfa45bb83d391064

Author: Maarten Lankhorst <[email protected]>
Date:   Tue May 19 16:41:03 2015 +0200

drm/atomic: add all affected planes in drm_atomic_helper_check_modeset>

is the commit I've forgotten about too ;-)

So the only thing left (I think) is some helper to disable all the planes currently on the crtc, which drivers can use in their crtc->disable hook. The enabling side is indeed already taken care of.

Cheers, Daniel

Signature · 7 lines
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel