public inbox for amd-gfx@lists.freedesktop.org
 help / color / mirror / Atom feed
From: Rex Zhu <Rex.Zhu-5C7GfCeVMHo@public.gmane.org>
To: amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org
Cc: Rex Zhu <Rex.Zhu-5C7GfCeVMHo@public.gmane.org>
Subject: [PATCH 2/3] drm/amd/pp: Refine get_gpu_power for VI
Date: Wed, 11 Apr 2018 14:31:46 +0800	[thread overview]
Message-ID: <1523428307-7969-2-git-send-email-Rex.Zhu@amd.com> (raw)
In-Reply-To: <1523428307-7969-1-git-send-email-Rex.Zhu-5C7GfCeVMHo@public.gmane.org>

pkgpwr is the average gpu power of 100ms. it is calculated by
firmware in real time.

1. we can send smu message PPSMC_MSG_GetCurrPkgPwr to read currentpkgpwr directly.

2. On Fiji/tonga/bonaire/hawwii, without PPSMC_MSG_GetCurrPkgPwr support.
   Send PPSMC_MSG_PmStatusLogStart/Sample to let smu write currentpkgpwr
   to ixSMU_PM_STATUS_94. driver can read pkgpwr from ixSMU_PM_STATUS_94.

Signed-off-by: Rex Zhu <Rex.Zhu@amd.com>
---
 drivers/gpu/drm/amd/powerplay/hwmgr/smu7_hwmgr.c   | 51 ++++++++++++----------
 drivers/gpu/drm/amd/powerplay/smumgr/smu7_smumgr.c | 10 +++--
 2 files changed, 34 insertions(+), 27 deletions(-)

diff --git a/drivers/gpu/drm/amd/powerplay/hwmgr/smu7_hwmgr.c b/drivers/gpu/drm/amd/powerplay/hwmgr/smu7_hwmgr.c
index 388184e..20f5a6f 100644
--- a/drivers/gpu/drm/amd/powerplay/hwmgr/smu7_hwmgr.c
+++ b/drivers/gpu/drm/amd/powerplay/hwmgr/smu7_hwmgr.c
@@ -3359,30 +3359,33 @@ static int smu7_get_pp_table_entry(struct pp_hwmgr *hwmgr,
 static int smu7_get_gpu_power(struct pp_hwmgr *hwmgr,
 		struct pp_gpu_power *query)
 {
-	PP_ASSERT_WITH_CODE(!smum_send_msg_to_smc(hwmgr,
-			PPSMC_MSG_PmStatusLogStart),
-			"Failed to start pm status log!",
-			return -1);
-
-	msleep_interruptible(20);
-
-	PP_ASSERT_WITH_CODE(!smum_send_msg_to_smc(hwmgr,
-			PPSMC_MSG_PmStatusLogSample),
-			"Failed to sample pm status log!",
-			return -1);
-
-	query->vddc_power = cgs_read_ind_register(hwmgr->device,
-			CGS_IND_REG__SMC,
-			ixSMU_PM_STATUS_40);
-	query->vddci_power = cgs_read_ind_register(hwmgr->device,
-			CGS_IND_REG__SMC,
-			ixSMU_PM_STATUS_49);
-	query->max_gpu_power = cgs_read_ind_register(hwmgr->device,
-			CGS_IND_REG__SMC,
-			ixSMU_PM_STATUS_94);
-	query->average_gpu_power = cgs_read_ind_register(hwmgr->device,
-			CGS_IND_REG__SMC,
-			ixSMU_PM_STATUS_95);
+	int i;
+
+	if (!query)
+		return -EINVAL;
+
+
+	memset(query, 0, sizeof *query);
+
+	smum_send_msg_to_smc_with_parameter(hwmgr, PPSMC_MSG_GetCurrPkgPwr, 0);
+	query->average_gpu_power = cgs_read_register(hwmgr->device, mmSMC_MSG_ARG_0);
+
+	if (query->average_gpu_power != 0)
+		return 0;
+
+	smum_send_msg_to_smc(hwmgr, PPSMC_MSG_PmStatusLogStart);
+	cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
+							ixSMU_PM_STATUS_94, 0);
+
+	for (i = 0; i < 20; i++) {
+		mdelay(1);
+		smum_send_msg_to_smc(hwmgr, PPSMC_MSG_PmStatusLogSample);
+		query->average_gpu_power = cgs_read_ind_register(hwmgr->device,
+						CGS_IND_REG__SMC,
+						ixSMU_PM_STATUS_94);
+		if (query->average_gpu_power != 0)
+			break;
+	}
 
 	return 0;
 }
diff --git a/drivers/gpu/drm/amd/powerplay/smumgr/smu7_smumgr.c b/drivers/gpu/drm/amd/powerplay/smumgr/smu7_smumgr.c
index fb32a3f..10a1123 100644
--- a/drivers/gpu/drm/amd/powerplay/smumgr/smu7_smumgr.c
+++ b/drivers/gpu/drm/amd/powerplay/smumgr/smu7_smumgr.c
@@ -171,8 +171,10 @@ int smu7_send_msg_to_smc(struct pp_hwmgr *hwmgr, uint16_t msg)
 
 	ret = PHM_READ_FIELD(hwmgr->device, SMC_RESP_0, SMC_RESP);
 
-	if (ret != 1)
-		pr_info("\n failed to send pre message %x ret is %d \n",  msg, ret);
+	if (ret == 0xFE)
+		pr_debug("last message was not supported\n");
+	else if (ret != 1)
+		pr_info("\n last message was failed ret is %d\n", ret);
 
 	cgs_write_register(hwmgr->device, mmSMC_MESSAGE_0, msg);
 
@@ -180,7 +182,9 @@ int smu7_send_msg_to_smc(struct pp_hwmgr *hwmgr, uint16_t msg)
 
 	ret = PHM_READ_FIELD(hwmgr->device, SMC_RESP_0, SMC_RESP);
 
-	if (ret != 1)
+	if (ret == 0xFE)
+		pr_debug("message %x was not supported\n", msg);
+	else if (ret != 1)
 		pr_info("\n failed to send message %x ret is %d \n",  msg, ret);
 
 	return 0;
-- 
1.9.1

_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

  parent reply	other threads:[~2018-04-11  6:31 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-04-11  6:31 [PATCH 1/3] Revert "drm/amd/powerply: fix power reading on Fiji" Rex Zhu
     [not found] ` <1523428307-7969-1-git-send-email-Rex.Zhu-5C7GfCeVMHo@public.gmane.org>
2018-04-11  6:31   ` Rex Zhu [this message]
     [not found]     ` <1523428307-7969-2-git-send-email-Rex.Zhu-5C7GfCeVMHo@public.gmane.org>
2018-04-11 17:21       ` [PATCH 2/3] drm/amd/pp: Refine get_gpu_power for VI Alex Deucher
     [not found]         ` <CADnq5_Mysj0jkxyA+v1BcBDFrdqKNdaH0o4f8wEWcCNa8isoMA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2018-04-11 17:38           ` Eric Huang
2018-04-11  6:31   ` [PATCH 3/3] drm/amd/pp: Remove struct pp_gpu_power Rex Zhu
     [not found]     ` <1523428307-7969-3-git-send-email-Rex.Zhu-5C7GfCeVMHo@public.gmane.org>
2018-04-11 17:23       ` Alex Deucher
     [not found]         ` <CADnq5_O_17bzfKfvd+6aaeQB=NS5Nz=Ot+0DMyKbZKVAK9p8Xg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2018-04-11 17:25           ` Tom St Denis
     [not found]             ` <8bf7fad4-ba8f-793e-4cfa-25eb2084be3d-5C7GfCeVMHo@public.gmane.org>
2018-04-11 17:40               ` Eric Huang
2018-04-11 17:19   ` [PATCH 1/3] Revert "drm/amd/powerply: fix power reading on Fiji" Alex Deucher
     [not found]     ` <CADnq5_PjDQ1LkTM-=h6k6WJt1Auukq1tAnM77Vz579wxVyP4oQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2018-04-11 17:33       ` Eric Huang
  -- strict thread matches above, loose matches on Subject: below --
2018-04-04  8:25 Rex Zhu
     [not found] ` <1522830304-15505-1-git-send-email-Rex.Zhu-5C7GfCeVMHo@public.gmane.org>
2018-04-04  8:25   ` [PATCH 2/3] drm/amd/pp: Refine get_gpu_power for VI Rex Zhu
     [not found]     ` <1522830304-15505-2-git-send-email-Rex.Zhu-5C7GfCeVMHo@public.gmane.org>
2018-04-04 15:36       ` Eric Huang
     [not found]         ` <a3566d2f-4b35-00b4-1df1-ab50076f704c-5C7GfCeVMHo@public.gmane.org>
2018-04-04 15:50           ` Zhu, Rex
     [not found]             ` <CY4PR12MB1687C34CD0753343A795544CFBA40-rpdhrqHFk06Y0SjTqZDccQdYzm3356FpvxpqHgZTriW3zl9H0oFU5g@public.gmane.org>
2018-04-04 16:00               ` Eric Huang
     [not found]                 ` <dfcb5127-c6ad-2a09-793e-42ca3cdcff1d-5C7GfCeVMHo@public.gmane.org>
2018-04-04 16:05                   ` Zhu, Rex

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1523428307-7969-2-git-send-email-Rex.Zhu@amd.com \
    --to=rex.zhu-5c7gfcevmho@public.gmane.org \
    --cc=amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox