Skip to contentSkip to conversation

Add support for Panel Power Savings property

PATCH In review Mario Limonciello 4 participants 12 messages May 19, 2024 – May 21, 2024

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

cover Add support for Panel Power Savings property

During the Display Next hackfest 2024 one of the topics discussed was the need for compositor to be able to relay intention to drivers that color fidelity is preferred over power savings.

To accomplish this a new optional DRM property is being introduced called "panel power saving". This property is an enum that can be configured by the compositor to "Allowed" or "Forbidden".

When a driver advertises support for this property and the compositor sets it to "Forbidden" then the driver will disable any power saving features that can compromise color fidelity.

In practice the main feature this currently applies to is the "Adaptive Backlight Modulation" feature within AMD DCN on eDP panels.

When the compositor has marked the property "Forbidden" then this feature will be disabled and any userspace that tries to turn it on will get an -EBUSY return code.

When the compositor has restored the value back to "Allowed" then the previous value that would have been programmed will be restored.

Mario Limonciello (2):
drm: Introduce panel_power_saving drm property drm/amd: Add panel_power_saving drm property to eDP connectors

 drivers/gpu/drm/amd/amdgpu/amdgpu_display.c   |  3 ++
 .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 34 ++++++++++++++---
 .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.h |  1 +
 drivers/gpu/drm/drm_connector.c               | 37 +++++++++++++++++++
 include/drm/drm_connector.h                   |  1 +
 include/drm/drm_mode_config.h                 |  6 +++
 include/uapi/drm/drm_mode.h                   |  4 ++
 7 files changed, 81 insertions(+), 5 deletions(-)
Signature · 1 line
2.45.0
#1 lore raw

PATCH 1/2 drm: Introduce panel_power_saving drm property

The panel_power_saving DRM property is an optional property that can be added to a connector by a driver.

This property is for compositors to indicate intent of allowing policy for the driver to use power saving features that may compromise color fidelity.

---
 drivers/gpu/drm/drm_connector.c | 36 +++++++++++++++++++++++++++++++++
 include/drm/drm_connector.h     |  1 +
 include/drm/drm_mode_config.h   |  6 ++++++
 include/uapi/drm/drm_mode.h     |  4 ++++
 4 files changed, 47 insertions(+)
drivers/gpu/drm/drm_connector.c +36 -0
index 4d2df7f64dc5..ccf672c55e0c 100644
@@ -961,6 +961,11 @@ static const struct drm_prop_enum_list drm_scaling_mode_enum_list[] = {
 	{ DRM_MODE_SCALE_ASPECT, "Full aspect" },
 };
 
+static const struct drm_prop_enum_list drm_panel_power_saving_enum_list[] = {
+	{ DRM_MODE_PANEL_POWER_SAVING_ALLOWED, "Allowed" },
+	{ DRM_MODE_PANEL_POWER_SAVING_FORBIDDEN, "Forbidden" },
+};
+
 static const struct drm_prop_enum_list drm_aspect_ratio_enum_list[] = {
 	{ DRM_MODE_PICTURE_ASPECT_NONE, "Automatic" },
 	{ DRM_MODE_PICTURE_ASPECT_4_3, "4:3" },
@@ -1963,6 +1968,37 @@ int drm_mode_create_scaling_mode_property(struct drm_device *dev)
 }
 EXPORT_SYMBOL(drm_mode_create_scaling_mode_property);
 
+/**
+ * drm_mode_create_panel_power_saving_property - create panel power saving property
+ * @dev: DRM device
+ *
+ * Called by a driver the first time it's needed, must be attached to desired
+ * connectors.
+ *
+ * Atomic drivers should use drm_mode_create_panel_power_saving_property()
+ * instead to correctly assign &drm_connector_state.panel_power_saving
+ * in the atomic state.
+ *
+ * Returns: %0
+ */
+int drm_mode_create_panel_power_saving_property(struct drm_device *dev)
+{
+	struct drm_property *panel_power_saving;
+
+	if (dev->mode_config.panel_power_saving)
+		return 0;
+
+	panel_power_saving =
+		drm_property_create_enum(dev, 0, "panel power saving",
+				drm_panel_power_saving_enum_list,
+				    ARRAY_SIZE(drm_panel_power_saving_enum_list));
+
+	dev->mode_config.panel_power_saving = panel_power_saving;
+
+	return 0;
+}
+EXPORT_SYMBOL(drm_mode_create_panel_power_saving_property);
+
 /**
  * DOC: Variable refresh properties
  *
include/drm/drm_connector.h +1 -0
index fe88d7fc6b8f..4ea3f912c641 100644
@@ -2025,6 +2025,7 @@ int drm_mode_create_dp_colorspace_property(struct drm_connector *connector,
 					   u32 supported_colorspaces);
 int drm_mode_create_content_type_property(struct drm_device *dev);
 int drm_mode_create_suggested_offset_properties(struct drm_device *dev);
+int drm_mode_create_panel_power_saving_property(struct drm_device *dev);
 
 int drm_connector_set_path_property(struct drm_connector *connector,
 				    const char *path);
include/drm/drm_mode_config.h +6 -0
index 973119a9176b..099ad2d8c5c1 100644
@@ -954,6 +954,12 @@ struct drm_mode_config {
 	 */
 	struct drm_atomic_state *suspend_state;
 
+	/**
+	 * @panel_power_saving: DRM ENUM property for type of
+	 * Panel Power Saving.
+	 */
+	struct drm_property *panel_power_saving;
+
 	const struct drm_mode_config_helper_funcs *helper_private;
 };
 
include/uapi/drm/drm_mode.h +4 -0
index 7040e7ea80c7..82e565cc76fb 100644
@@ -152,6 +152,10 @@ extern "C" {
 #define DRM_MODE_SCALE_CENTER		2 /* Centered, no scaling */
 #define DRM_MODE_SCALE_ASPECT		3 /* Full screen, preserve aspect */
 
+/* Panel power saving options */
+#define DRM_MODE_PANEL_POWER_SAVING_ALLOWED	0 /* Panel power savings features allowed */
+#define DRM_MODE_PANEL_POWER_SAVING_FORBIDDEN	1 /* Panel power savings features not allowed */
+
 /* Dithering mode options */
 #define DRM_MODE_DITHERING_OFF	0
 #define DRM_MODE_DITHERING_ON	1
Signature · 1 line
2.45.0
#2 lore raw

PATCH 2/2 drm/amd: Add panel_power_saving drm property to eDP connectors

In reply to Mario Limonciello

When the panel_power_saving property is set to "Forbidden" ABM should be disabled immediately and any requests by sysfs to update will return an -EBUSY error.

When the property is restored to "Allowed" the previous value of ABM will be restored.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_display.c   |  3 ++
 .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 36 ++++++++++++++++---
 .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.h |  1 +
 3 files changed, 35 insertions(+), 5 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_display.c +3 -0
index 3ecc7ef95172..6e6531c93d81 100644
@@ -1350,6 +1350,9 @@ int amdgpu_display_modeset_create_props(struct amdgpu_device *adev)
 					 "dither",
 					 amdgpu_dither_enum_list, sz);
 
+	if (adev->dc_enabled)
+		drm_mode_create_panel_power_saving_property(adev_to_drm(adev));
+
 	return 0;
 }
 
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +31 -5
index 01b0a331e4a6..f6b80018b136 100644
@@ -6421,6 +6421,12 @@ int amdgpu_dm_connector_atomic_set_property(struct drm_connector *connector,
 	} else if (property == adev->mode_info.underscan_property) {
 		dm_new_state->underscan_enable = val;
 		ret = 0;
+	} else if (property == dev->mode_config.panel_power_saving) {
+		dm_new_state->abm_forbidden = val;
+		dm_new_state->abm_level = (val || !amdgpu_dm_abm_level) ?
+						ABM_LEVEL_IMMEDIATE_DISABLE :
+						amdgpu_dm_abm_level;
+		ret = 0;
 	}
 
 	return ret;
@@ -6463,6 +6469,9 @@ int amdgpu_dm_connector_atomic_get_property(struct drm_connector *connector,
 	} else if (property == adev->mode_info.underscan_property) {
 		*val = dm_state->underscan_enable;
 		ret = 0;
+	} else if (property == dev->mode_config.panel_power_saving) {
+		*val = dm_state->abm_forbidden;
+		ret = 0;
 	}
 
 	return ret;
@@ -6489,9 +6498,12 @@ static ssize_t panel_power_savings_show(struct device *device,
 	u8 val;
 
 	drm_modeset_lock(&dev->mode_config.connection_mutex, NULL);
-	val = to_dm_connector_state(connector->state)->abm_level ==
-		ABM_LEVEL_IMMEDIATE_DISABLE ? 0 :
-		to_dm_connector_state(connector->state)->abm_level;
+	if (to_dm_connector_state(connector->state)->abm_forbidden)
+		val = 0;
+	else
+		val = to_dm_connector_state(connector->state)->abm_level ==
+			ABM_LEVEL_IMMEDIATE_DISABLE ? 0 :
+			to_dm_connector_state(connector->state)->abm_level;
 	drm_modeset_unlock(&dev->mode_config.connection_mutex);
 
 	return sysfs_emit(buf, "%u\n", val);
@@ -6515,10 +6527,16 @@ static ssize_t panel_power_savings_store(struct device *device,
 		return -EINVAL;
 
 	drm_modeset_lock(&dev->mode_config.connection_mutex, NULL);
-	to_dm_connector_state(connector->state)->abm_level = val ?:
-		ABM_LEVEL_IMMEDIATE_DISABLE;
+	if (to_dm_connector_state(connector->state)->abm_forbidden)
+		ret = -EBUSY;
+	else
+		to_dm_connector_state(connector->state)->abm_level = val ?:
+			ABM_LEVEL_IMMEDIATE_DISABLE;
 	drm_modeset_unlock(&dev->mode_config.connection_mutex);
 
+	if (ret)
+		return ret;
+
 	drm_kms_helper_hotplug_event(dev);
 
 	return count;
@@ -7689,6 +7707,14 @@ void amdgpu_dm_connector_init_helper(struct amdgpu_display_manager *dm,
 	aconnector->base.state->max_bpc = 16;
 	aconnector->base.state->max_requested_bpc = aconnector->base.state->max_bpc;
 
+	if (connector_type == DRM_MODE_CONNECTOR_eDP &&
+	    (dc_is_dmcu_initialized(adev->dm.dc) ||
+	     adev->dm.dc->ctx->dmub_srv) && amdgpu_dm_abm_level < 0) {
+		drm_object_attach_property(&aconnector->base.base,
+				dm->ddev->mode_config.panel_power_saving,
+				DRM_MODE_PANEL_POWER_SAVING_ALLOWED);
+	}
+
 	if (connector_type == DRM_MODE_CONNECTOR_HDMIA) {
 		/* Content Type is currently only implemented for HDMI. */
 		drm_connector_attach_content_type_property(&aconnector->base);
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.h +1 -0
index 09519b7abf67..43c3e5845a94 100644
@@ -873,6 +873,7 @@ struct dm_connector_state {
 	bool underscan_enable;
 	bool freesync_capable;
 	bool update_hdcp;
+	bool abm_forbidden;
 	uint8_t abm_level;
 	int vcpi_slots;
 	uint64_t pbn;
Signature · 1 line
2.45.0
#3 lore raw
In reply to Mario Limonciello

This makes sense to me in general. I like the fact that it's simple and vendor-neutral.

Do we want to hardcode "panel" in the name? Are we sure that this will ever only apply to panels?

Do we want to use a name which reflects the intent, rather than the mechanism? In other words, something like "color fidelity" = "preferred" maybe? (I don't know, just throwing ideas around.)

Would be nice to add documentation for the property in the "standard connector properties" section.

#4 lore raw
Quoted 9 lines · Simon Ser

This makes sense to me in general. I like the fact that it's simple and vendor-neutral.

Do we want to hardcode "panel" in the name? Are we sure that this will ever only apply to panels?

Do we want to use a name which reflects the intent, rather than the mechanism? In other words, something like "color fidelity" = "preferred" maybe? (I don't know, just throwing ideas around.)

In that vein, how about:

"power saving policy"
--> "power saving"
--> "color fidelity"

Quoted 3 lines

Would be nice to add documentation for the property in the "standard connector properties" section.

Ack.

#5 lore raw

Am Di., 21. Mai 2024 um 16:00 Uhr schrieb Mario Limonciello <[email protected]>:

Quoted 12 lines · Simon Ser
Quoted 9 lines

This makes sense to me in general. I like the fact that it's simple and vendor-neutral.

Do we want to hardcode "panel" in the name? Are we sure that this will ever only apply to panels?

Do we want to use a name which reflects the intent, rather than the mechanism? In other words, something like "color fidelity" = "preferred" maybe? (I don't know, just throwing ideas around.)

Quoted 5 lines

In that vein, how about:

"power saving policy"
--> "power saving"
--> "color fidelity"

It's not just about colors though, is it? The compositor might want to disable it to increase the backlight brightness in bright environments, so "color fidelity" doesn't really sound right

Quoted 6 lines
Quoted 3 lines

Would be nice to add documentation for the property in the "standard connector properties" section.

Ack.

#6 lore raw
Quoted 16 lines · Xaver Hugl

Am Di., 21. Mai 2024 um 16:00 Uhr schrieb Mario Limonciello <[email protected]>:

Quoted 14 lines · Simon Ser
Quoted 9 lines

This makes sense to me in general. I like the fact that it's simple and vendor-neutral.

Do we want to hardcode "panel" in the name? Are we sure that this will ever only apply to panels?

Do we want to use a name which reflects the intent, rather than the mechanism? In other words, something like "color fidelity" = "preferred" maybe? (I don't know, just throwing ideas around.)

In that vein, how about:

Quoted 7 lines
Quoted 3 lines

"power saving policy"
--> "power saving"
--> "color fidelity"

It's not just about colors though, is it? The compositor might want to disable it to increase the backlight brightness in bright environments, so "color fidelity" doesn't really sound right

Either of these better?

"power saving policy"
--> "power saving"
--> "accuracy"

"power saving policy"
--> "allowed"
--> "forbidden"

Or any other idea?

Quoted 7 lines
Quoted 7 lines
Quoted 4 lines

Would be nice to add documentation for the property in the "standard connector properties" section.

Ack.

maintainer
#7 lore raw
Quoted 31 lines · Mario Limonciello
Quoted 16 lines · Xaver Hugl

Am Di., 21. Mai 2024 um 16:00 Uhr schrieb Mario Limonciello <[email protected]>:

Quoted 14 lines · Simon Ser
Quoted 9 lines

This makes sense to me in general. I like the fact that it's simple and vendor-neutral.

Do we want to hardcode "panel" in the name? Are we sure that this will ever only apply to panels?

Do we want to use a name which reflects the intent, rather than the mechanism? In other words, something like "color fidelity" = "preferred" maybe? (I don't know, just throwing ideas around.)

In that vein, how about:

Quoted 7 lines
Quoted 3 lines

"power saving policy"
--> "power saving"
--> "color fidelity"

It's not just about colors though, is it? The compositor might want to disable it to increase the backlight brightness in bright environments, so "color fidelity" doesn't really sound right

Either of these better?

"power saving policy"
--> "power saving"
--> "accuracy"

Quoted 5 lines

"power saving policy"
--> "allowed"
--> "forbidden"

Or any other idea?

Another consideration in addition to accuracy is latency.

I suppose a compositor may want to disable features such as PSR for use-cases requiring low latency. Touch and stylus input are some examples.

I wonder if flags would work better than enums? A compositor can set something like REQUIRE_ACCURACY & REQUIRE_LOW_LATENCY, for example.

- Leo

Quoted 9 lines
Quoted 8 lines
Quoted 8 lines
Quoted 5 lines

Would be nice to add documentation for the property in the "standard connector properties" section.

Ack.

#8 lore raw
Quoted 38 lines · Leo Li
Quoted 35 lines · Mario Limonciello
Quoted 16 lines · Xaver Hugl

Am Di., 21. Mai 2024 um 16:00 Uhr schrieb Mario Limonciello <[email protected]>:

Quoted 14 lines · Simon Ser
Quoted 9 lines

This makes sense to me in general. I like the fact that it's simple and vendor-neutral.

Do we want to hardcode "panel" in the name? Are we sure that this will ever only apply to panels?

Do we want to use a name which reflects the intent, rather than the mechanism? In other words, something like "color fidelity" = "preferred" maybe? (I don't know, just throwing ideas around.)

In that vein, how about:

Quoted 7 lines
Quoted 3 lines

"power saving policy"
--> "power saving"
--> "color fidelity"

It's not just about colors though, is it? The compositor might want to disable it to increase the backlight brightness in bright environments, so "color fidelity" doesn't really sound right

Either of these better?

"power saving policy"
--> "power saving"
--> "accuracy"

"power saving policy"
--> "allowed"
--> "forbidden"

Quoted 8 lines
Quoted 1 line

Or any other idea?

Another consideration in addition to accuracy is latency.

I suppose a compositor may want to disable features such as PSR for use-cases requiring low latency. Touch and stylus input are some examples.

I wonder if flags would work better than enums? A compositor can set something like REQUIRE_ACCURACY & REQUIRE_LOW_LATENCY, for example.

I thought we had said the PSR latency issue discussed at the hackfest was likely just a bug and that nominally it won't matter?

If it really will matter enough then yeah I think you're right that flags would be better. More drivers would probably want to opt into the property for the purpose of turning off PSR/PSR2/panel replay as well then.

Quoted 11 lines

- Leo

Quoted 9 lines
Quoted 8 lines
Quoted 8 lines
Quoted 5 lines

Would be nice to add documentation for the property in the "standard connector properties" section.

Ack.

maintainer
#9 lore raw
Quoted 41 lines · Mario Limonciello
Quoted 40 lines · Leo Li
Quoted 36 lines · Mario Limonciello
Quoted 16 lines · Xaver Hugl

Am Di., 21. Mai 2024 um 16:00 Uhr schrieb Mario Limonciello <[email protected]>:

Quoted 14 lines · Simon Ser
Quoted 9 lines

This makes sense to me in general. I like the fact that it's simple and vendor-neutral.

Do we want to hardcode "panel" in the name? Are we sure that this will ever only apply to panels?

Do we want to use a name which reflects the intent, rather than the mechanism? In other words, something like "color fidelity" = "preferred" maybe? (I don't know, just throwing ideas around.)

In that vein, how about:

Quoted 7 lines
Quoted 3 lines

"power saving policy"
--> "power saving"
--> "color fidelity"

It's not just about colors though, is it? The compositor might want to disable it to increase the backlight brightness in bright environments, so "color fidelity" doesn't really sound right

Either of these better?

"power saving policy"
--> "power saving"
--> "accuracy"

"power saving policy"
--> "allowed"
--> "forbidden"

Or any other idea?

Quoted 8 lines
Quoted 6 lines

Another consideration in addition to accuracy is latency.

I suppose a compositor may want to disable features such as PSR for use-cases requiring low latency. Touch and stylus input are some examples.

I wonder if flags would work better than enums? A compositor can set something like REQUIRE_ACCURACY & REQUIRE_LOW_LATENCY, for example.

I thought we had said the PSR latency issue discussed at the hackfest was likely just a bug and that nominally it won't matter?

Ah, either my memory failed, or I failed to clarify. Let me fix that below.

Quoted 2 lines

If it really will matter enough then yeah I think you're right that flags would be better.  More drivers would probably want to opt into the property for the purpose of turning off PSR/PSR2/panel replay as well then.

Latency technically shouldn't be a problem for Panel Replay, but is a problem for PSR/PSR2 due to their design. At least it is a problem for amdgpu, not sure about other drivers.

FWIU, in short, when a panel (DPRX) goes into self-refresh, it's clock can drift from the gpu (DPTX). Since there's no resync mechanism in PSR/PSR2, it is possible for the panel to lag behind by 1-frame-time(ms) for a noticeable period of time. Panel replay has a resync mechanism, so it theoretically can resync within 1 frame.

Since, fwict, replay panels are still rare, I think it'll be nice for compositors that care about latency to have the option to temporarily disable PSR/PSR2.

- Leo

Quoted 13 lines
Quoted 12 lines

- Leo

Quoted 9 lines
Quoted 8 lines
Quoted 8 lines
Quoted 5 lines

Would be nice to add documentation for the property in the "standard connector properties" section.

Ack.

#10 lore raw
In reply to Leo Li

Am Di., 21. Mai 2024 um 19:28 Uhr schrieb Leo Li <[email protected]>:

Quoted 41 lines · Mario Limonciello
Quoted 31 lines · Xaver Hugl
Quoted 16 lines

Am Di., 21. Mai 2024 um 16:00 Uhr schrieb Mario Limonciello <[email protected]>:

Quoted 14 lines · Simon Ser
Quoted 9 lines

This makes sense to me in general. I like the fact that it's simple and vendor-neutral.

Do we want to hardcode "panel" in the name? Are we sure that this will ever only apply to panels?

Do we want to use a name which reflects the intent, rather than the mechanism? In other words, something like "color fidelity" = "preferred" maybe? (I don't know, just throwing ideas around.)

In that vein, how about:

Quoted 7 lines
Quoted 3 lines

"power saving policy"
--> "power saving"
--> "color fidelity"

It's not just about colors though, is it? The compositor might want to disable it to increase the backlight brightness in bright environments, so "color fidelity" doesn't really sound right

Either of these better?

"power saving policy"
--> "power saving"
--> "accuracy"

Quoted 5 lines

"power saving policy"
--> "allowed"
--> "forbidden"

Or any other idea?

Quoted 7 lines

Another consideration in addition to accuracy is latency.

I suppose a compositor may want to disable features such as PSR for use-cases requiring low latency. Touch and stylus input are some examples.

I wonder if flags would work better than enums? A compositor can set something like REQUIRE_ACCURACY & REQUIRE_LOW_LATENCY, for example.

I think that's a good idea. With a flag for color accuracy and one for brightness, the compositor's intent would be communicated well.

Quoted 11 lines

- Leo

Quoted 9 lines
Quoted 8 lines
Quoted 8 lines
Quoted 5 lines

Would be nice to add documentation for the property in the "standard connector properties" section.

Ack.

#11 lore raw
In reply to Leo Li
Quoted 2 lines · Leo Li

I wonder if flags would work better than enums? A compositor can set something like REQUIRE_ACCURACY & REQUIRE_LOW_LATENCY, for example.

(FWIW, the KMS uAPI has first-class support for bitfields.)