Skip to contentSkip to conversation

drm/amd/display: Add power_state member into current_state

PATCH New Mario Limonciello 1 participant 3 messages Jan 6, 2022

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

PATCH v4 1/3 drm/amd/display: Add power_state member into current_state

This can be used by the display core to let decisions be made based upon the requested power state.

---
changes from v3->v4:
* Initialize power_state when context is created (0 shouldn't be a valid state)
changes from v2->v3:
* New patch

 drivers/gpu/drm/amd/display/dc/core/dc.c        | 3 +++
 drivers/gpu/drm/amd/display/dc/inc/core_types.h | 1 +
 2 files changed, 4 insertions(+)
drivers/gpu/drm/amd/display/dc/core/dc.c +3 -0
index 91c4874473d6..8edbb6c70512 100644
@@ -1960,6 +1960,7 @@ static void init_state(struct dc *dc, struct dc_state *context)
 #ifdef CONFIG_DRM_AMD_DC_DCN
 	memcpy(&context->bw_ctx.dml, &dc->dml, sizeof(struct display_mode_lib));
 #endif
+	context->power_state = DC_ACPI_CM_POWER_STATE_D0;
 }
 
 struct dc_state *dc_create_state(struct dc *dc)
@@ -3281,6 +3282,8 @@ void dc_set_power_state(
 	if (!dc->current_state)
 		return;
 
+	dc->current_state->power_state = power_state;
+
 	switch (power_state) {
 	case DC_ACPI_CM_POWER_STATE_D0:
 		dc_resource_state_construct(dc, dc->current_state);
drivers/gpu/drm/amd/display/dc/inc/core_types.h +1 -0
index 943240e2809e..6bd0aeed1856 100644
@@ -506,6 +506,7 @@ struct dc_state {
 	struct {
 		unsigned int stutter_period_us;
 	} perf_params;
+	enum dc_acpi_cm_power_state power_state;
 };
 
 #endif /* _CORE_TYPES_H_ */
Signature · 1 line
2.25.1
#1 lore raw

PATCH v4 2/3 drm/amd/display: Split out checks for applying HPD WA into a separate function

This will make it cleaner to read through the logic for an upcoming change.

---
Changes from v3->v4:
* New patch

 .../amd/display/dc/clk_mgr/dcn21/rn_clk_mgr.c | 30 +++++++++++--------
 1 file changed, 18 insertions(+), 12 deletions(-)
drivers/gpu/drm/amd/display/dc/clk_mgr/dcn21/rn_clk_mgr.c +18 -12
index fbda42313bfe..20974829f304 100644
@@ -120,6 +120,23 @@ static void rn_update_clocks_update_dpp_dto(struct clk_mgr_internal *clk_mgr,
 	}
 }
 
+static bool check_really_safe_to_lower(struct dc *dc, struct dc_state *context)
+{
+	int display_count = rn_get_active_display_cnt_wa(dc, context);
+	uint32_t hpd_state;
+	int irq_src;
+
+	if (display_count > 0)
+		return false;
+
+	for (irq_src = DC_IRQ_SOURCE_HPD1; irq_src <= DC_IRQ_SOURCE_HPD5; irq_src++) {
+		hpd_state = dc_get_hpd_state_dcn21(dc->res_pool->irqs, irq_src);
+		if (hpd_state)
+			break;
+	}
+
+	return !hpd_state;
+}
 
 static void rn_update_clocks(struct clk_mgr *clk_mgr_base,
 			struct dc_state *context,
@@ -128,12 +145,9 @@ static void rn_update_clocks(struct clk_mgr *clk_mgr_base,
 	struct clk_mgr_internal *clk_mgr = TO_CLK_MGR_INTERNAL(clk_mgr_base);
 	struct dc_clocks *new_clocks = &context->bw_ctx.bw.dcn.clk;
 	struct dc *dc = clk_mgr_base->ctx->dc;
-	int display_count;
-	int irq_src;
 	bool update_dppclk = false;
 	bool update_dispclk = false;
 	bool dpp_clock_lowered = false;
-	uint32_t hpd_state;
 
 	struct dmcu *dmcu = clk_mgr_base->ctx->dc->res_pool->dmcu;
 
@@ -148,16 +162,8 @@ static void rn_update_clocks(struct clk_mgr *clk_mgr_base,
 		/* check that we're not already in lower */
 		if (clk_mgr_base->clks.pwr_state != DCN_PWR_STATE_LOW_POWER) {
 
-			display_count = rn_get_active_display_cnt_wa(dc, context);
-
-			for (irq_src = DC_IRQ_SOURCE_HPD1; irq_src <= DC_IRQ_SOURCE_HPD5; irq_src++) {
-				hpd_state = dc_get_hpd_state_dcn21(dc->res_pool->irqs, irq_src);
-				if (hpd_state)
-					break;
-			}
-
 			/* if we can go lower, go lower */
-			if (display_count == 0 && !hpd_state) {
+			if (check_really_safe_to_lower(dc, context)) {
 				rn_vbios_smu_set_dcn_low_power_state(clk_mgr, DCN_PWR_STATE_LOW_POWER);
 				/* update power state */
 				clk_mgr_base->clks.pwr_state = DCN_PWR_STATE_LOW_POWER;
Signature · 1 line
2.25.1
#2 lore raw

PATCH v4 3/3 drm/amd/display: Use requested power state to avoid HPD WA during s0ix

In reply to Mario Limonciello

The WA from commit 5965280abd30 ("drm/amd/display: Apply w/a for hard hang on HPD") causes a regression in s0ix where the system will fail to resume properly. This may be because an HPD was active the last time clocks were updated but clocks didn't get updated again during s0ix.

So add an extra call to update clocks as part of the suspend routine:
dm_suspend->dc_set_power_state->clk_mgr_optimize_pwr_state

In case HPD is set during this time, also check if the call happened during suspend to allow overriding the WA.

Cc Qingqing Zhuo <[email protected]>
Reported-by [email protected]
Fixes 5965280abd30 ("drm/amd/display: Apply w/a for hard hang on HPD")
Fixes 1bd3bc745e7f ("drm/amd/display: Extend w/a for hard hang on HPD to dcn20")

---
changes from v3->v4:
* Move into new function
* Explicitly check that current_state is active for safety
* Change metadata from BugLink to Link
changes from v2->v3:
* stop depending on adev, get value of power state from display core
changes from v1->v2:
* Add fallthrough statement
* Extend case to check if call was explicitly in s0ix since #1852 showed hpd_state can be set at this time too
* Adjust commit message and title
* Add extra commit and bug fixed to metadata

 drivers/gpu/drm/amd/display/dc/clk_mgr/dcn21/rn_clk_mgr.c | 4 ++++
 drivers/gpu/drm/amd/display/dc/core/dc.c                  | 3 +++
 2 files changed, 7 insertions(+)
drivers/gpu/drm/amd/display/dc/clk_mgr/dcn21/rn_clk_mgr.c +4 -0
index 20974829f304..d2e1938555dc 100644
@@ -129,6 +129,10 @@ static bool check_really_safe_to_lower(struct dc *dc, struct dc_state *context)
 	if (display_count > 0)
 		return false;
 
+	if (dc->current_state &&
+	    dc->current_state->power_state == DC_ACPI_CM_POWER_STATE_D3)
+		return true;
+
 	for (irq_src = DC_IRQ_SOURCE_HPD1; irq_src <= DC_IRQ_SOURCE_HPD5; irq_src++) {
 		hpd_state = dc_get_hpd_state_dcn21(dc->res_pool->irqs, irq_src);
 		if (hpd_state)
drivers/gpu/drm/amd/display/dc/core/dc.c +3 -0
index 8edbb6c70512..716e055a61c9 100644
@@ -3302,6 +3302,9 @@ void dc_set_power_state(
 		}
 
 		break;
+	case DC_ACPI_CM_POWER_STATE_D3:
+		clk_mgr_optimize_pwr_state(dc, dc->clk_mgr);
+		fallthrough;
 	default:
 		ASSERT(dc->current_state->stream_count == 0);
 		/* Zero out the current context so that on resume we start with
Signature · 1 line
2.25.1