[PATCH v3 3/4] drm/amd: Validate gfxoff state for smu12

Mario Limonciello mario.limonciello at amd.com
Wed May 17 06:08:19 UTC 2023


GFXOFF may be flushed at suspend entry and it may be important
to ensure it reaches desired target state.

Signed-off-by: Mario Limonciello <mario.limonciello at amd.com>
---
 .../gpu/drm/amd/pm/swsmu/smu12/smu_v12_0.c    | 26 +++++++++++--------
 1 file changed, 15 insertions(+), 11 deletions(-)

diff --git a/drivers/gpu/drm/amd/pm/swsmu/smu12/smu_v12_0.c b/drivers/gpu/drm/amd/pm/swsmu/smu12/smu_v12_0.c
index c788aa7a99a9..869237cd0c2c 100644
--- a/drivers/gpu/drm/amd/pm/swsmu/smu12/smu_v12_0.c
+++ b/drivers/gpu/drm/amd/pm/swsmu/smu12/smu_v12_0.c
@@ -157,26 +157,30 @@ uint32_t smu_v12_0_get_gfxoff_status(struct smu_context *smu)
 
 int smu_v12_0_gfx_off_control(struct smu_context *smu, bool enable)
 {
-	int ret = 0, timeout = 500;
+	int ret, timeout = 500;
+	int target;
 
 	if (enable) {
 		ret = smu_cmn_send_smc_msg(smu, SMU_MSG_AllowGfxOff, NULL);
-
+		target = 0;
 	} else {
 		ret = smu_cmn_send_smc_msg(smu, SMU_MSG_DisallowGfxOff, NULL);
+		target = 2;
+	}
+	if (ret)
+		return ret;
 
-		/* confirm gfx is back to "on" state, timeout is 0.5 second */
-		while (!(smu_v12_0_get_gfxoff_status(smu) == 2)) {
-			msleep(1);
-			timeout--;
-			if (timeout == 0) {
-				DRM_ERROR("disable gfxoff timeout and failed!\n");
-				break;
-			}
+	/* confirm gfx is back to intended state, timeout is 0.5 second */
+	while ((smu_v12_0_get_gfxoff_status(smu) != target)) {
+		msleep(1);
+		timeout--;
+		if (timeout == 0) {
+			DRM_ERROR("%s gfxoff timeout and failed!\n", enable ? "enable" : "disable");
+			return -ETIMEDOUT;
 		}
 	}
 
-	return ret;
+	return 0;
 }
 
 int smu_v12_0_fini_smc_tables(struct smu_context *smu)
-- 
2.34.1



More information about the amd-gfx mailing list