Skip to contentSkip to conversation

drm/amd/pm: avoid duplicate powergate/ungate setting

PATCH In review Evan Quan 5 participants 17 messages Nov 8, 2021 – Nov 10, 2021

Subsystems (3)
lore
Share & tools
lore

Evan Quan

author
#0 lore raw

PATCH 1/1 drm/amd/pm: avoid duplicate powergate/ungate setting

Just bail out if the target IP block is already in the desired powergate/ungate state. This can avoid some duplicate settings which sometime may cause unexpected issues.

Change-Id I66346c69f121df0f5ee20182451313ae4fda2d04
---
 drivers/gpu/drm/amd/amdgpu/amdgpu.h              |  7 +++++++
 drivers/gpu/drm/amd/include/amd_shared.h         |  3 ++-
 drivers/gpu/drm/amd/pm/amdgpu_dpm.c              | 13 ++++++++++++-
 drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c |  3 +++
 drivers/gpu/drm/amd/pm/powerplay/kv_dpm.c        |  3 +++
 drivers/gpu/drm/amd/pm/powerplay/si_dpm.c        |  3 +++
 drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c        |  3 +++
 7 files changed, 33 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +7 -0
index b85b67a88a3d..19fa21ad8a44 100644
@@ -767,9 +767,16 @@ enum amd_hw_ip_block_type {
 #define HW_ID_MAX		300
 #define IP_VERSION(mj, mn, rv) (((mj) << 16) | ((mn) << 8) | (rv))
 
+enum amd_ip_powergate_state {
+	POWERGATE_STATE_INITIAL,
+	POWERGATE_STATE_GATE,
+	POWERGATE_STATE_UNGATE,
+};
+
 struct amd_powerplay {
 	void *pp_handle;
 	const struct amd_pm_funcs *pp_funcs;
+	atomic_t pg_state[AMD_IP_BLOCK_TYPE_NUM];
 };
 
 /* polaris10 kickers */
drivers/gpu/drm/amd/include/amd_shared.h +2 -1
index f1a46d16f7ea..4b9e68a79f06 100644
@@ -98,7 +98,8 @@ enum amd_ip_block_type {
 	AMD_IP_BLOCK_TYPE_ACP,
 	AMD_IP_BLOCK_TYPE_VCN,
 	AMD_IP_BLOCK_TYPE_MES,
-	AMD_IP_BLOCK_TYPE_JPEG
+	AMD_IP_BLOCK_TYPE_JPEG,
+	AMD_IP_BLOCK_TYPE_NUM,
 };
 
 enum amd_clockgating_state {
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +12 -1
index 03581d5b1836..a6b337b6f4a9 100644
@@ -927,6 +927,14 @@ int amdgpu_dpm_set_powergating_by_smu(struct amdgpu_device *adev, uint32_t block
 {
 	int ret = 0;
 	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+	enum amd_ip_powergate_state pg_state =
+		gate ? POWERGATE_STATE_GATE : POWERGATE_STATE_UNGATE;
+
+	if (atomic_read(&adev->powerplay.pg_state[block_type]) == pg_state) {
+		dev_dbg(adev->dev, "IP block%d already in the target %s state!",
+				block_type, gate ? "gate" : "ungate");
+		return 0;
+	}
 
 	switch (block_type) {
 	case AMD_IP_BLOCK_TYPE_UVD:
@@ -976,9 +984,12 @@ int amdgpu_dpm_set_powergating_by_smu(struct amdgpu_device *adev, uint32_t block
 		}
 		break;
 	default:
-		break;
+		return -EINVAL;
 	}
 
+	if (!ret)
+		atomic_set(&adev->powerplay.pg_state[block_type], pg_state);
+
 	return ret;
 }
 
drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c +3 -0
index bba7479f6265..8d8a7cf615eb 100644
@@ -38,6 +38,7 @@ static const struct amd_pm_funcs pp_dpm_funcs;
 static int amd_powerplay_create(struct amdgpu_device *adev)
 {
 	struct pp_hwmgr *hwmgr;
+	int i;
 
 	if (adev == NULL)
 		return -EINVAL;
@@ -57,6 +58,8 @@ static int amd_powerplay_create(struct amdgpu_device *adev)
 	hwmgr->display_config = &adev->pm.pm_display_cfg;
 	adev->powerplay.pp_handle = hwmgr;
 	adev->powerplay.pp_funcs = &pp_dpm_funcs;
+	for (i = 0; i < AMD_IP_BLOCK_TYPE_NUM; i++)
+		atomic_set(&adev->powerplay.pg_state[i], POWERGATE_STATE_INITIAL);
 	return 0;
 }
 
drivers/gpu/drm/amd/pm/powerplay/kv_dpm.c +3 -0
index bcae42cef374..f84f56552fd0 100644
@@ -2965,9 +2965,12 @@ static int kv_dpm_get_temp(void *handle)
 static int kv_dpm_early_init(void *handle)
 {
 	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
+	int i;
 
 	adev->powerplay.pp_funcs = &kv_dpm_funcs;
 	adev->powerplay.pp_handle = adev;
+	for (i = 0; i < AMD_IP_BLOCK_TYPE_NUM; i++)
+		atomic_set(&adev->powerplay.pg_state[i], POWERGATE_STATE_INITIAL);
 	kv_dpm_set_irq_funcs(adev);
 
 	return 0;
drivers/gpu/drm/amd/pm/powerplay/si_dpm.c +3 -0
index 81f82aa05ec2..f1eb22c9bb59 100644
@@ -7916,9 +7916,12 @@ static int si_dpm_early_init(void *handle)
 {
 
 	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
+	int i;
 
 	adev->powerplay.pp_funcs = &si_dpm_funcs;
 	adev->powerplay.pp_handle = adev;
+	for (i = 0; i < AMD_IP_BLOCK_TYPE_NUM; i++)
+		atomic_set(&adev->powerplay.pg_state[i], POWERGATE_STATE_INITIAL);
 	si_dpm_set_irq_funcs(adev);
 	return 0;
 }
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +3 -0
index 01168b8955bf..fdc25bae8237 100644
@@ -627,6 +627,7 @@ static int smu_early_init(void *handle)
 {
 	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
 	struct smu_context *smu = &adev->smu;
+	int i;
 
 	smu->adev = adev;
 	smu->pm_enabled = !!amdgpu_dpm;
@@ -639,6 +640,8 @@ static int smu_early_init(void *handle)
 
 	adev->powerplay.pp_handle = smu;
 	adev->powerplay.pp_funcs = &swsmu_pm_funcs;
+	for (i = 0; i < AMD_IP_BLOCK_TYPE_NUM; i++)
+		atomic_set(&adev->powerplay.pg_state[i], POWERGATE_STATE_INITIAL);
 
 	return smu_set_funcs(adev);
 }
Signature · 1 line
2.29.0
#1 lore raw

Dear Evan,

Am 08.11.21 um 05:47 schrieb Evan Quan:

Quoted 3 lines

Just bail out if the target IP block is already in the desired powergate/ungate state. This can avoid some duplicate settings which sometime may cause unexpected issues.

sometime*s*

Please elaborate the kind of issues.

On what systems did you test this? Also, there is a new debug log message.

Quoted 86 lines
Change-Id I66346c69f121df0f5ee20182451313ae4fda2d04
---
  drivers/gpu/drm/amd/amdgpu/amdgpu.h              |  7 +++++++
  drivers/gpu/drm/amd/include/amd_shared.h         |  3 ++-
  drivers/gpu/drm/amd/pm/amdgpu_dpm.c              | 13 ++++++++++++-
  drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c |  3 +++
  drivers/gpu/drm/amd/pm/powerplay/kv_dpm.c        |  3 +++
  drivers/gpu/drm/amd/pm/powerplay/si_dpm.c        |  3 +++
  drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c        |  3 +++
  7 files changed, 33 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +7 -0
index b85b67a88a3d..19fa21ad8a44 100644
@@ -767,9 +767,16 @@ enum amd_hw_ip_block_type {
  #define HW_ID_MAX		300
  #define IP_VERSION(mj, mn, rv) (((mj) << 16) | ((mn) << 8) | (rv))
 
+enum amd_ip_powergate_state {
+	POWERGATE_STATE_INITIAL,
+	POWERGATE_STATE_GATE,
+	POWERGATE_STATE_UNGATE,
+};
+
  struct amd_powerplay {
  	void *pp_handle;
  	const struct amd_pm_funcs *pp_funcs;
+	atomic_t pg_state[AMD_IP_BLOCK_TYPE_NUM];
  };
 
  /* polaris10 kickers */
drivers/gpu/drm/amd/include/amd_shared.h +2 -1
index f1a46d16f7ea..4b9e68a79f06 100644
@@ -98,7 +98,8 @@ enum amd_ip_block_type {
  	AMD_IP_BLOCK_TYPE_ACP,
  	AMD_IP_BLOCK_TYPE_VCN,
  	AMD_IP_BLOCK_TYPE_MES,
-	AMD_IP_BLOCK_TYPE_JPEG
+	AMD_IP_BLOCK_TYPE_JPEG,
+	AMD_IP_BLOCK_TYPE_NUM,
  };
 
  enum amd_clockgating_state {
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +12 -1
index 03581d5b1836..a6b337b6f4a9 100644
@@ -927,6 +927,14 @@ int amdgpu_dpm_set_powergating_by_smu(struct amdgpu_device *adev, uint32_t block
  {
  	int ret = 0;
  	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+	enum amd_ip_powergate_state pg_state =
+		gate ? POWERGATE_STATE_GATE : POWERGATE_STATE_UNGATE;
+
+	if (atomic_read(&adev->powerplay.pg_state[block_type]) == pg_state) {
+		dev_dbg(adev->dev, "IP block%d already in the target %s state!",
+				block_type, gate ? "gate" : "ungate");
+		return 0;
+	}
 
  	switch (block_type) {
  	case AMD_IP_BLOCK_TYPE_UVD:
@@ -976,9 +984,12 @@ int amdgpu_dpm_set_powergating_by_smu(struct amdgpu_device *adev, uint32_t block
  		}
  		break;
  	default:
-		break;
+		return -EINVAL;
  	}
 
+	if (!ret)
+		atomic_set(&adev->powerplay.pg_state[block_type], pg_state);
+
  	return ret;
  }
 
drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c +0 -0
index bba7479f6265..8d8a7cf615eb 100644

drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c static const struct amd_pm_funcs pp_dpm_funcs; · line 41

Quoted 4 lines
drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c +1 -0
@@ -38,6 +38,7 @@ static const struct amd_pm_funcs pp_dpm_funcs;
  static int amd_powerplay_create(struct amdgpu_device *adev)
  {
  	struct pp_hwmgr *hwmgr;
+	int i;

I’d use unsigned int or size_t to make it clear, that they cannot get negative.

Quoted 68 lines
drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c +2 -0
  	if (adev == NULL)
  		return -EINVAL;
@@ -57,6 +58,8 @@ static int amd_powerplay_create(struct amdgpu_device *adev)
  	hwmgr->display_config = &adev->pm.pm_display_cfg;
  	adev->powerplay.pp_handle = hwmgr;
  	adev->powerplay.pp_funcs = &pp_dpm_funcs;
+	for (i = 0; i < AMD_IP_BLOCK_TYPE_NUM; i++)
+		atomic_set(&adev->powerplay.pg_state[i], POWERGATE_STATE_INITIAL);
  	return 0;
  }
 
drivers/gpu/drm/amd/pm/powerplay/kv_dpm.c +3 -0
index bcae42cef374..f84f56552fd0 100644
@@ -2965,9 +2965,12 @@ static int kv_dpm_get_temp(void *handle)
  static int kv_dpm_early_init(void *handle)
  {
  	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
+	int i;
 
  	adev->powerplay.pp_funcs = &kv_dpm_funcs;
  	adev->powerplay.pp_handle = adev;
+	for (i = 0; i < AMD_IP_BLOCK_TYPE_NUM; i++)
+		atomic_set(&adev->powerplay.pg_state[i], POWERGATE_STATE_INITIAL);
  	kv_dpm_set_irq_funcs(adev);
 
  	return 0;
drivers/gpu/drm/amd/pm/powerplay/si_dpm.c +3 -0
index 81f82aa05ec2..f1eb22c9bb59 100644
@@ -7916,9 +7916,12 @@ static int si_dpm_early_init(void *handle)
  {
 
  	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
+	int i;
 
  	adev->powerplay.pp_funcs = &si_dpm_funcs;
  	adev->powerplay.pp_handle = adev;
+	for (i = 0; i < AMD_IP_BLOCK_TYPE_NUM; i++)
+		atomic_set(&adev->powerplay.pg_state[i], POWERGATE_STATE_INITIAL);
  	si_dpm_set_irq_funcs(adev);
  	return 0;
  }
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +3 -0
index 01168b8955bf..fdc25bae8237 100644
@@ -627,6 +627,7 @@ static int smu_early_init(void *handle)
  {
  	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
  	struct smu_context *smu = &adev->smu;
+	int i;
 
  	smu->adev = adev;
  	smu->pm_enabled = !!amdgpu_dpm;
@@ -639,6 +640,8 @@ static int smu_early_init(void *handle)
 
  	adev->powerplay.pp_handle = smu;
  	adev->powerplay.pp_funcs = &swsmu_pm_funcs;
+	for (i = 0; i < AMD_IP_BLOCK_TYPE_NUM; i++)
+		atomic_set(&adev->powerplay.pg_state[i], POWERGATE_STATE_INITIAL);
 
  	return smu_set_funcs(adev);
  }
#2 lore raw
Quoted 1 line · Paul Menzel

Please elaborate the kind of issues.

It fails to reboot on Carrizo-based laptops.

Whoever commits this, pls add

so that it is clear what the whole story way.

Thx.

Signature · 4 lines
Regards/Gruss,
    Boris.

SUSE Software Solutions Germany GmbH, GF: Ivo Totev, HRB 36809, AG Nürnberg
maintainer
#3 lore raw

Am 08.11.21 um 12:15 schrieb Borislav Petkov:

Quoted 3 lines · Paul Menzel
Quoted 1 line

Please elaborate the kind of issues.

It fails to reboot on Carrizo-based laptops.

That doesn't necessary sounds like a good idea to me then.

What exactly is going wrong here? And what is the rational that we must fix this by avoiding updating the current state?

See we usually assume that updating to the already set state is unproblematic and that here sounds like just trying to mitigated some issues instead of fixing the root cause.

Regards,
Christian.

Quoted 9 lines

Whoever commits this, pls add

so that it is clear what the whole story way.

Thx.

#4 lore raw
Quoted 9 lines · Christian König

Am 08.11.21 um 12:15 schrieb Borislav Petkov:

Quoted 3 lines · Paul Menzel
Quoted 1 line

Please elaborate the kind of issues.

It fails to reboot on Carrizo-based laptops.

That doesn't necessary sounds like a good idea to me then.

What exactly is going wrong here? And what is the rational that we must fix this by avoiding updating the current state?

Reboot will trigger a suspend of IPs. As part of UVD/VCE suspend, now there is an added logic to power gate the IP as part of suspend sequence. In case of UVD/VCE, power gating would have already happened as part of idle work execution.

In any case, power gating is done by SMU FW. The assumption here is - the logic to power gate IP could involve register programming. AFAIK, accessing some UVD/VCE regs during powergate state could cause a hang unless the anti-hang mechanism is not programmed. That means either FW or driver needs to track the state of IP before accessing those regs and in this case probably FW is assuming driver to be responsible. i.e., not to call power off again if it's already powered down.

Though that seems to be a bad assumption on part of FW, it is still a possibility. Haven't seen the actual FW code, it's a very old program.

Thanks,
Lijo

Quoted 15 lines

See we usually assume that updating to the already set state is unproblematic and that here sounds like just trying to mitigated some issues instead of fixing the root cause.

Regards,
Christian.

Quoted 9 lines

Whoever commits this, pls add

so that it is clear what the whole story way.

Thx.

author
#5 lore raw

[AMD Official Use Only]

Quoted 20 lines

-----Original Message-----
From: Lazar, Lijo <[email protected]>
Sent: Monday, November 8, 2021 10:41 PM
To: Koenig, Christian <[email protected]>; Borislav Petkov <[email protected]>; Paul Menzel <[email protected]>
Cc: Deucher, Alexander <[email protected]>; Quan, Evan <[email protected]>; [email protected]
Subject: Re: [PATCH] drm/amd/pm: avoid duplicate powergate/ungate setting

Quoted 7 lines · Christian König

Am 08.11.21 um 12:15 schrieb Borislav Petkov:

Quoted 3 lines · Paul Menzel
Quoted 1 line

Please elaborate the kind of issues.

It fails to reboot on Carrizo-based laptops.

That doesn't necessary sounds like a good idea to me then.

Quoted 8 lines
Quoted 3 lines

What exactly is going wrong here? And what is the rational that we must fix this by avoiding updating the current state?

Reboot will trigger a suspend of IPs. As part of UVD/VCE suspend, now there is an added logic to power gate the IP as part of suspend sequence. In case of UVD/VCE, power gating would have already happened as part of idle work execution.

[Quan, Evan] Thanks Lijo. Some supplement for the added-on power gate logic on suspend:
1. if the UVD/VCE is still using on reboot triggered, idle work will be not triggered and the add-on power gate logic can help to put the Ips into correct gate state.
2. If the UVD/VCE is already idle on reboot triggered, then as Lijo mentioned, the idle work will be already triggered and the iP is in gate state. Then the add-on power gate logic on suspend will be extra and even harmful(on Carrizo platform).

So, to address the issue of 2 and not break 1, we will track the pg state internally and just bail out on 2nd consecutive gate request.

P.S. gfxoff feature suffers the same issue. The patch can address it also.

BR
Evan

Quoted 32 lines

In any case, power gating is done by SMU FW. The assumption here is - the logic to power gate IP could involve register programming. AFAIK, accessing some UVD/VCE regs during powergate state could cause a hang unless the anti-hang mechanism is not programmed. That means either FW or driver needs to track the state of IP before accessing those regs and in this case probably FW is assuming driver to be responsible. i.e., not to call power off again if it's already powered down.

Though that seems to be a bad assumption on part of FW, it is still a possibility. Haven't seen the actual FW code, it's a very old program.

Thanks,
Lijo

Quoted 17 lines

See we usually assume that updating to the already set state is unproblematic and that here sounds like just trying to mitigated some issues instead of fixing the root cause.

Regards,
Christian.

Quoted 9 lines

Whoever commits this, pls add

so that it is clear what the whole story way.

Thx.

maintainer Reviewed-by Guchun Chen
#6 lore raw
In reply to Lazar, Lijo

Am 08.11.21 um 15:41 schrieb Lazar, Lijo:

Quoted 10 lines · Christian König
Quoted 7 lines

Am 08.11.21 um 12:15 schrieb Borislav Petkov:

Quoted 3 lines · Paul Menzel
Quoted 1 line

Please elaborate the kind of issues.

It fails to reboot on Carrizo-based laptops.

That doesn't necessary sounds like a good idea to me then.

Quoted 8 lines
Quoted 2 lines

What exactly is going wrong here? And what is the rational that we must fix this by avoiding updating the current state?

Reboot will trigger a suspend of IPs. As part of UVD/VCE suspend, now there is an added logic to power gate the IP as part of suspend sequence. In case of UVD/VCE, power gating would have already happened as part of idle work execution.

In any case, power gating is done by SMU FW. The assumption here is - the logic to power gate IP could involve register programming. AFAIK, accessing some UVD/VCE regs during powergate state could cause a hang unless the anti-hang mechanism is not programmed. That means either FW or driver needs to track the state of IP before accessing those regs and in this case probably FW is assuming driver to be responsible. i.e., not to call power off again if it's already powered down.

Though that seems to be a bad assumption on part of FW, it is still a possibility. Haven't seen the actual FW code, it's a very old program.

Ok guys I've double checked the git history and found that this here is not as it is intended to be.

See the code in question was just added in August by the following commit:

commit 859e4659273f1df3a23e3990826bcb41e85f68a5
Author: Evan Quan <[email protected]>
Date:   Thu Aug 19 12:07:59 2021 +0800

    drm/amdgpu: add missing cleanups for more ASICs on UVD/VCE suspend

    This is a supplement for commit below:
    "drm/amdgpu: add missing cleanups for Polaris12 UVD/VCE on suspend".

Before that we where just not touching the UVD power state at all during suspend and so we won't had a problem in the first place.

So what we should do instead is to just revert commit 859e4659273f1df3a23e3990826bcb41e85f68a5 with a proper fixes Tag and explanation why that is a bad idea.

Regards,
Christian.

Quoted 19 lines

Thanks,
Lijo

Quoted 15 lines

See we usually assume that updating to the already set state is unproblematic and that here sounds like just trying to mitigated some issues instead of fixing the root cause.

Regards,
Christian.

Quoted 9 lines

Whoever commits this, pls add

so that it is clear what the whole story way.

Thx.

#7 lore raw
Quoted 34 lines · Christian König

Am 08.11.21 um 15:41 schrieb Lazar, Lijo:

Quoted 10 lines · Christian König
Quoted 7 lines

Am 08.11.21 um 12:15 schrieb Borislav Petkov:

Quoted 3 lines · Paul Menzel
Quoted 1 line

Please elaborate the kind of issues.

It fails to reboot on Carrizo-based laptops.

That doesn't necessary sounds like a good idea to me then.

Quoted 8 lines
Quoted 2 lines

What exactly is going wrong here? And what is the rational that we must fix this by avoiding updating the current state?

Reboot will trigger a suspend of IPs. As part of UVD/VCE suspend, now there is an added logic to power gate the IP as part of suspend sequence. In case of UVD/VCE, power gating would have already happened as part of idle work execution.

In any case, power gating is done by SMU FW. The assumption here is - the logic to power gate IP could involve register programming. AFAIK, accessing some UVD/VCE regs during powergate state could cause a hang unless the anti-hang mechanism is not programmed. That means either FW or driver needs to track the state of IP before accessing those regs and in this case probably FW is assuming driver to be responsible. i.e., not to call power off again if it's already powered down.

Though that seems to be a bad assumption on part of FW, it is still a possibility. Haven't seen the actual FW code, it's a very old program.

Ok guys I've double checked the git history and found that this here is not as it is intended to be.

See the code in question was just added in August by the following commit:

commit 859e4659273f1df3a23e3990826bcb41e85f68a5
Author: Evan Quan <[email protected]>
Date:   Thu Aug 19 12:07:59 2021 +0800

    drm/amdgpu: add missing cleanups for more ASICs on UVD/VCE suspend

    This is a supplement for commit below:
    "drm/amdgpu: add missing cleanups for Polaris12 UVD/VCE on suspend".

Quoted 8 lines

Before that we where just not touching the UVD power state at all during suspend and so we won't had a problem in the first place.

So what we should do instead is to just revert commit 859e4659273f1df3a23e3990826bcb41e85f68a5 with a proper fixes Tag and explanation why that is a bad idea.

Yeah, right. If I remember correctly, this commit was originally added to fix hangs with S3 suspend/resume cycles triggered during video playback. Reverting could bring back that one. Evan will know more background details.

Thanks,
Lijo

Quoted 24 lines

Regards,
Christian.

Quoted 19 lines

Thanks,
Lijo

Quoted 15 lines

See we usually assume that updating to the already set state is unproblematic and that here sounds like just trying to mitigated some issues instead of fixing the root cause.

Regards,
Christian.

Quoted 9 lines

Whoever commits this, pls add

so that it is clear what the whole story way.

Thx.

maintainer
#8 lore raw

Am 09.11.21 um 08:28 schrieb Lazar, Lijo:

Quoted 19 lines

[SNIP]

Quoted 18 lines

Ok guys I've double checked the git history and found that this here is not as it is intended to be.

See the code in question was just added in August by the following commit:

commit 859e4659273f1df3a23e3990826bcb41e85f68a5
Author: Evan Quan <[email protected]>
Date:   Thu Aug 19 12:07:59 2021 +0800

     drm/amdgpu: add missing cleanups for more ASICs on UVD/VCE suspend

     This is a supplement for commit below:
     "drm/amdgpu: add missing cleanups for Polaris12 UVD/VCE on suspend".

Quoted 6 lines
Quoted 4 lines

Before that we where just not touching the UVD power state at all during suspend and so we won't had a problem in the first place.

So what we should do instead is to just revert commit 859e4659273f1df3a23e3990826bcb41e85f68a5 with a proper fixes Tag and explanation why that is a bad idea.

Yeah, right. If I remember correctly, this commit was originally added to fix hangs with S3 suspend/resume cycles triggered during video playback. Reverting could bring back that one. Evan will know more background details.

Exactly that's my memory as well. So what happens here is that we go in circles with one patch fixing a bug and the next patch effectively reverting it again to fix another bug.

What we need to do is stop this madness and take a look at the underlying problems instead of trying to work around them.

Thanks,
Christian.

Quoted 28 lines

Thanks,
Lijo

Quoted 24 lines

Regards,
Christian.

Quoted 19 lines

Thanks,
Lijo

Quoted 15 lines

See we usually assume that updating to the already set state is unproblematic and that here sounds like just trying to mitigated some issues instead of fixing the root cause.

Regards,
Christian.

Quoted 9 lines

Whoever commits this, pls add

so that it is clear what the whole story way.

Thx.

author
#9 lore raw
In reply to Lazar, Lijo

[AMD Official Use Only]

Quoted 73 lines

-----Original Message-----
From: Lazar, Lijo <[email protected]>
Sent: Tuesday, November 9, 2021 3:29 PM
To: Koenig, Christian <[email protected]>; Borislav Petkov <[email protected]>; Paul Menzel <[email protected]>; Liu, Leo <[email protected]>
Cc: Deucher, Alexander <[email protected]>; Quan, Evan <[email protected]>; [email protected]
Subject: Re: [PATCH] drm/amd/pm: avoid duplicate powergate/ungate setting

Quoted 51 lines · Christian König

Am 08.11.21 um 15:41 schrieb Lazar, Lijo:

Quoted 27 lines · Christian König
Quoted 10 lines

Am 08.11.21 um 12:15 schrieb Borislav Petkov:

Quoted 3 lines · Paul Menzel
Quoted 1 line

Please elaborate the kind of issues.

It fails to reboot on Carrizo-based laptops.

That doesn't necessary sounds like a good idea to me then.

What exactly is going wrong here? And what is the rational that we must fix this by avoiding updating the current state?

Reboot will trigger a suspend of IPs. As part of UVD/VCE suspend, now there is an added logic to power gate the IP as part of suspend sequence. In case of UVD/VCE, power gating would have already happened as part of idle work execution.

In any case, power gating is done by SMU FW. The assumption here is - the logic to power gate IP could involve register programming. AFAIK, accessing some UVD/VCE regs during powergate state could cause a hang unless the anti-hang mechanism is not programmed. That means either FW or driver needs to track the state of IP before accessing those regs and in this case probably FW is assuming driver to be responsible. i.e., not to call power off again if it's already powered down.

Quoted 2 lines

Though that seems to be a bad assumption on part of FW, it is still a possibility. Haven't seen the actual FW code, it's a very old program.

Ok guys I've double checked the git history and found that this here is not as it is intended to be.

See the code in question was just added in August by the following commit:

commit 859e4659273f1df3a23e3990826bcb41e85f68a5
Author: Evan Quan <[email protected]>
Date:   Thu Aug 19 12:07:59 2021 +0800

    drm/amdgpu: add missing cleanups for more ASICs on UVD/VCE
suspend

    This is a supplement for commit below:
    "drm/amdgpu: add missing cleanups for Polaris12 UVD/VCE on suspend".

Quoted 7 lines

Before that we where just not touching the UVD power state at all during suspend and so we won't had a problem in the first place.

So what we should do instead is to just revert commit 859e4659273f1df3a23e3990826bcb41e85f68a5 with a proper fixes Tag and explanation why that is a bad idea.

Quoted 4 lines

Yeah, right. If I remember correctly, this commit was originally added to fix hangs with S3 suspend/resume cycles triggered during video playback. Reverting could bring back that one. Evan will know more background details.

[Quan, Evan] Yes, 859e4659273f1df3a23e3990826bcb41e85f68a5 aimed the issue below. It cannot be reverted.
"If the UVD/VCE is still using on reboot/suspend triggered, idle work will be not triggered and the add-on power gate logic can help to put the Ips into correct gate state."

BR
Evan

Quoted 30 lines

Thanks,
Lijo

Quoted 26 lines

Regards,
Christian.

Quoted 21 lines

Thanks,
Lijo

Quoted 17 lines

See we usually assume that updating to the already set state is unproblematic and that here sounds like just trying to mitigated some issues instead of fixing the root cause.

Regards,
Christian.

Quoted 9 lines

Whoever commits this, pls add

so that it is clear what the whole story way.

Thx.

author
#10 lore raw
In reply to Borislav Petkov

[AMD Official Use Only]

Quoted 26 lines

-----Original Message-----
From: Borislav Petkov <[email protected]>
Sent: Monday, November 8, 2021 7:15 PM
To: Paul Menzel <[email protected]>
Cc: Quan, Evan <[email protected]>; Deucher, Alexander <[email protected]>; Lazar, Lijo <[email protected]>; amd- [email protected]
Subject: Re: [PATCH] drm/amd/pm: avoid duplicate powergate/ungate setting

Quoted 1 line · Paul Menzel

Please elaborate the kind of issues.

It fails to reboot on Carrizo-based laptops.

Whoever commits this, pls add

Link:
https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Flore.
kernel.org%2Fr%2FYV81vidWQLWvATMM%40zn.tnic&amp;data=04%7C01%7 Cevan.quan%40amd.com%7C274191d3b11c4ba6dc5208d9a2a906d4%7C3dd8 961fe4884e608e11a82d994e183d%7C0%7C0%7C637719669118839695%7CUnk nown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6I k1haWwiLCJXVCI6Mn0%3D%7C1000&amp;sdata=JAfoXZHWV6KoCxsSJR4plt5 P%2FeXzTodZJeAUMPU5kYg%3D&amp;reserved=0

Quoted 1 line

so that it is clear what the whole story way.

[Quan, Evan] Thanks. Will add this.

BR
Evan

Quoted 9 lines

Thx.

--
Regards/Gruss,
Boris.

SUSE Software Solutions Germany GmbH, GF: Ivo Totev, HRB 36809, AG Nürnberg

author
#11 lore raw
In reply to Paul Menzel

[AMD Official Use Only]

Quoted 18 lines

-----Original Message-----
From: Paul Menzel <[email protected]>
Sent: Monday, November 8, 2021 4:51 PM
To: Quan, Evan <[email protected]>
Cc: Deucher, Alexander <[email protected]>; Lazar, Lijo <[email protected]>; Borislav Petkov <[email protected]>; amd- [email protected]
Subject: Re: [PATCH] drm/amd/pm: avoid duplicate powergate/ungate setting

Dear Evan,

Am 08.11.21 um 05:47 schrieb Evan Quan:

Quoted 3 lines

Just bail out if the target IP block is already in the desired powergate/ungate state. This can avoid some duplicate settings which sometime may cause unexpected issues.

Quoted 5 lines

sometime*s*

Please elaborate the kind of issues.

On what systems did you test this? Also, there is a new debug log message.

[Quan, Evan] Locally I verified this on my Polaris12 card and Boris helped to verify on his Carrizo platform. Both show positive results. The log message was left intentionally. But I downgraded the log level from INFO to DEBUG to avoid confusing.

Quoted 93 lines

drivers/gpu/drm/amd/pm/amdgpu_dpm.c int

Quoted 57 lines
Change-Id I66346c69f121df0f5ee20182451313ae4fda2d04
---
  drivers/gpu/drm/amd/amdgpu/amdgpu.h              |  7 +++++++
  drivers/gpu/drm/amd/include/amd_shared.h         |  3 ++-
  drivers/gpu/drm/amd/pm/amdgpu_dpm.c              | 13 ++++++++++++-
  drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c |  3 +++
  drivers/gpu/drm/amd/pm/powerplay/kv_dpm.c        |  3 +++
  drivers/gpu/drm/amd/pm/powerplay/si_dpm.c        |  3 +++
  drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c        |  3 +++
  7 files changed, 33 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +7 -0
index b85b67a88a3d..19fa21ad8a44 100644
@@ -767,9 +767,16 @@ enum amd_hw_ip_block_type {
  #define HW_ID_MAX		300
  #define IP_VERSION(mj, mn, rv) (((mj) << 16) | ((mn) << 8) | (rv))
 
+enum amd_ip_powergate_state {
+	POWERGATE_STATE_INITIAL,
+	POWERGATE_STATE_GATE,
+	POWERGATE_STATE_UNGATE,
+};
+
  struct amd_powerplay {
  	void *pp_handle;
  	const struct amd_pm_funcs *pp_funcs;
+	atomic_t pg_state[AMD_IP_BLOCK_TYPE_NUM];
  };
 
  /* polaris10 kickers */
drivers/gpu/drm/amd/include/amd_shared.h +2 -1
index f1a46d16f7ea..4b9e68a79f06 100644
@@ -98,7 +98,8 @@ enum amd_ip_block_type {
  	AMD_IP_BLOCK_TYPE_ACP,
  	AMD_IP_BLOCK_TYPE_VCN,
  	AMD_IP_BLOCK_TYPE_MES,
-	AMD_IP_BLOCK_TYPE_JPEG
+	AMD_IP_BLOCK_TYPE_JPEG,
+	AMD_IP_BLOCK_TYPE_NUM,
  };
 
  enum amd_clockgating_state {
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +0 -0
index 03581d5b1836..a6b337b6f4a9 100644
@@ -927,6 +927,14 @@ int

amdgpu_dpm_set_powergating_by_smu(struct amdgpu_device *adev, uint32_t block

drivers/gpu/drm/amd/pm/amdgpu_dpm.c int amdgpu_dpm_set_powergating_by_smu(struct amdgpu_device *adev, uint32_t block

Quoted 5 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +2 -0
  {
  	int ret = 0;
  	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+	enum amd_ip_powergate_state pg_state =
+		gate ? POWERGATE_STATE_GATE :

POWERGATE_STATE_UNGATE;

drivers/gpu/drm/amd/pm/amdgpu_dpm.c int · line 933

Quoted 2 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +2 -0
+
+	if (atomic_read(&adev->powerplay.pg_state[block_type]) ==

pg_state) {

drivers/gpu/drm/amd/pm/amdgpu_dpm.c int · line 934

Quoted 1 line
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +1 -0
+		dev_dbg(adev->dev, "IP block%d already in the target %s

state!",

drivers/gpu/drm/amd/pm/amdgpu_dpm.c int

Quoted 7 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +3 -0
+				block_type, gate ? "gate" : "ungate");
+		return 0;
+	}
 
  	switch (block_type) {
  	case AMD_IP_BLOCK_TYPE_UVD:
@@ -976,9 +984,12 @@ int

amdgpu_dpm_set_powergating_by_smu(struct amdgpu_device *adev, uint32_t block

drivers/gpu/drm/amd/pm/amdgpu_dpm.c int amdgpu_dpm_set_powergating_by_smu(struct amdgpu_device *adev, uint32_t block

Quoted 9 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +3 -1
  		}
  		break;
  	default:
-		break;
+		return -EINVAL;
  	}
 
+	if (!ret)
+		atomic_set(&adev->powerplay.pg_state[block_type],

pg_state);

Quoted 4 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +1 -0
+
  	return ret;
  }
 
Quoted 13 lines

drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c static const struct amd_pm_funcs pp_dpm_funcs; · line 41

Quoted 10 lines
drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c +1 -0
index bba7479f6265..8d8a7cf615eb 100644
@@ -38,6 +38,7 @@ static const struct amd_pm_funcs pp_dpm_funcs;
  static int amd_powerplay_create(struct amdgpu_device *adev)
  {
  	struct pp_hwmgr *hwmgr;
+	int i;

I’d use unsigned int or size_t to make it clear, that they cannot get negative.

[Quan, Evan] Sure, I can do that.

BR
Evan

Quoted 77 lines

drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c static int amd_powerplay_create(struct

Quoted 5 lines
drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c +0 -0
  	if (adev == NULL)
  		return -EINVAL;
@@ -57,6 +58,8 @@ static int amd_powerplay_create(struct

amdgpu_device *adev)

drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c static int amd_powerplay_create(struct amdgpu_device *adev)

Quoted 5 lines
drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c +2 -0
  	hwmgr->display_config = &adev->pm.pm_display_cfg;
  	adev->powerplay.pp_handle = hwmgr;
  	adev->powerplay.pp_funcs = &pp_dpm_funcs;
+	for (i = 0; i < AMD_IP_BLOCK_TYPE_NUM; i++)
+		atomic_set(&adev->powerplay.pg_state[i],

POWERGATE_STATE_INITIAL);

Quoted 9 lines
drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c +0 -0
  	return 0;
  }
 
drivers/gpu/drm/amd/pm/powerplay/kv_dpm.c +0 -0
index bcae42cef374..f84f56552fd0 100644

drivers/gpu/drm/amd/pm/powerplay/kv_dpm.c static int kv_dpm_get_temp(void *handle) · line 2973

Quoted 9 lines
drivers/gpu/drm/amd/pm/powerplay/kv_dpm.c +3 -0
@@ -2965,9 +2965,12 @@ static int kv_dpm_get_temp(void *handle)
  static int kv_dpm_early_init(void *handle)
  {
  	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
+	int i;
 
  	adev->powerplay.pp_funcs = &kv_dpm_funcs;
  	adev->powerplay.pp_handle = adev;
+	for (i = 0; i < AMD_IP_BLOCK_TYPE_NUM; i++)
+		atomic_set(&adev->powerplay.pg_state[i],

POWERGATE_STATE_INITIAL);

Quoted 9 lines
drivers/gpu/drm/amd/pm/powerplay/kv_dpm.c +0 -0
  	kv_dpm_set_irq_funcs(adev);
 
  	return 0;
drivers/gpu/drm/amd/pm/powerplay/si_dpm.c +0 -0
index 81f82aa05ec2..f1eb22c9bb59 100644

drivers/gpu/drm/amd/pm/powerplay/si_dpm.c static int si_dpm_early_init(void *handle) · line 7924

Quoted 9 lines
drivers/gpu/drm/amd/pm/powerplay/si_dpm.c +3 -0
@@ -7916,9 +7916,12 @@ static int si_dpm_early_init(void *handle)
  {
 
  	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
+	int i;
 
  	adev->powerplay.pp_funcs = &si_dpm_funcs;
  	adev->powerplay.pp_handle = adev;
+	for (i = 0; i < AMD_IP_BLOCK_TYPE_NUM; i++)
+		atomic_set(&adev->powerplay.pg_state[i],

POWERGATE_STATE_INITIAL);

Quoted 17 lines
drivers/gpu/drm/amd/pm/powerplay/si_dpm.c +0 -0
  	si_dpm_set_irq_funcs(adev);
  	return 0;
  }
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +1 -0
index 01168b8955bf..fdc25bae8237 100644
@@ -627,6 +627,7 @@ static int smu_early_init(void *handle)
  {
  	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
  	struct smu_context *smu = &adev->smu;
+	int i;
 
  	smu->adev = adev;
  	smu->pm_enabled = !!amdgpu_dpm;

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c static int smu_early_init(void *handle) · line 644

Quoted 5 lines
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +2 -0
@@ -639,6 +640,8 @@ static int smu_early_init(void *handle)
 
  	adev->powerplay.pp_handle = smu;
  	adev->powerplay.pp_funcs = &swsmu_pm_funcs;
+	for (i = 0; i < AMD_IP_BLOCK_TYPE_NUM; i++)
+		atomic_set(&adev->powerplay.pg_state[i],

POWERGATE_STATE_INITIAL);

Quoted 4 lines
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +0 -0
  	return smu_set_funcs(adev);
  }
 
#12 lore raw
In reply to Evan Quan
Quoted 22 lines · Evan Quan

Just bail out if the target IP block is already in the desired powergate/ungate state. This can avoid some duplicate settings which sometime may cause unexpected issues.

Change-Id I66346c69f121df0f5ee20182451313ae4fda2d04
---
  drivers/gpu/drm/amd/amdgpu/amdgpu.h              |  7 +++++++
  drivers/gpu/drm/amd/include/amd_shared.h         |  3 ++-
  drivers/gpu/drm/amd/pm/amdgpu_dpm.c              | 13 ++++++++++++-
  drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c |  3 +++
  drivers/gpu/drm/amd/pm/powerplay/kv_dpm.c        |  3 +++
  drivers/gpu/drm/amd/pm/powerplay/si_dpm.c        |  3 +++
  drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c        |  3 +++
  7 files changed, 33 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +0 -0
index b85b67a88a3d..19fa21ad8a44 100644

drivers/gpu/drm/amd/amdgpu/amdgpu.h enum amd_hw_ip_block_type { · line 775

Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu.h +6 -0
@@ -767,9 +767,16 @@ enum amd_hw_ip_block_type {
  #define HW_ID_MAX		300
  #define IP_VERSION(mj, mn, rv) (((mj) << 16) | ((mn) << 8) | (rv))
 
+enum amd_ip_powergate_state {
+	POWERGATE_STATE_INITIAL,
+	POWERGATE_STATE_GATE,
+	POWERGATE_STATE_UNGATE,
+};
+

To reflect the current state, they could be named like POWERGATE_STATE_UNKNOWN/ON/OFF.

drivers/gpu/drm/amd/amdgpu/amdgpu.h enum amd_hw_ip_block_type { · line 779

Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu.h +1 -0
  struct amd_powerplay {
  	void *pp_handle;
  	const struct amd_pm_funcs *pp_funcs;
+	atomic_t pg_state[AMD_IP_BLOCK_TYPE_NUM];

Maybe add another field in amdgpu_ip_block_status? Downside is it won't reflect the PG state achieved through paths other than PMFW control and ipblock needs to be queried through amdgpu_device_ip_get_ip_block()

Thanks,
Lijo

Quoted 127 lines
drivers/gpu/drm/amd/amdgpu/amdgpu.h +0 -0
  };
 
  /* polaris10 kickers */
drivers/gpu/drm/amd/include/amd_shared.h +2 -1
index f1a46d16f7ea..4b9e68a79f06 100644
@@ -98,7 +98,8 @@ enum amd_ip_block_type {
  	AMD_IP_BLOCK_TYPE_ACP,
  	AMD_IP_BLOCK_TYPE_VCN,
  	AMD_IP_BLOCK_TYPE_MES,
-	AMD_IP_BLOCK_TYPE_JPEG
+	AMD_IP_BLOCK_TYPE_JPEG,
+	AMD_IP_BLOCK_TYPE_NUM,
  };
 
  enum amd_clockgating_state {
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +12 -1
index 03581d5b1836..a6b337b6f4a9 100644
@@ -927,6 +927,14 @@ int amdgpu_dpm_set_powergating_by_smu(struct amdgpu_device *adev, uint32_t block
  {
  	int ret = 0;
  	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+	enum amd_ip_powergate_state pg_state =
+		gate ? POWERGATE_STATE_GATE : POWERGATE_STATE_UNGATE;
+
+	if (atomic_read(&adev->powerplay.pg_state[block_type]) == pg_state) {
+		dev_dbg(adev->dev, "IP block%d already in the target %s state!",
+				block_type, gate ? "gate" : "ungate");
+		return 0;
+	}
 
  	switch (block_type) {
  	case AMD_IP_BLOCK_TYPE_UVD:
@@ -976,9 +984,12 @@ int amdgpu_dpm_set_powergating_by_smu(struct amdgpu_device *adev, uint32_t block
  		}
  		break;
  	default:
-		break;
+		return -EINVAL;
  	}
 
+	if (!ret)
+		atomic_set(&adev->powerplay.pg_state[block_type], pg_state);
+
  	return ret;
  }
 
drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c +3 -0
index bba7479f6265..8d8a7cf615eb 100644
@@ -38,6 +38,7 @@ static const struct amd_pm_funcs pp_dpm_funcs;
  static int amd_powerplay_create(struct amdgpu_device *adev)
  {
  	struct pp_hwmgr *hwmgr;
+	int i;
 
  	if (adev == NULL)
  		return -EINVAL;
@@ -57,6 +58,8 @@ static int amd_powerplay_create(struct amdgpu_device *adev)
  	hwmgr->display_config = &adev->pm.pm_display_cfg;
  	adev->powerplay.pp_handle = hwmgr;
  	adev->powerplay.pp_funcs = &pp_dpm_funcs;
+	for (i = 0; i < AMD_IP_BLOCK_TYPE_NUM; i++)
+		atomic_set(&adev->powerplay.pg_state[i], POWERGATE_STATE_INITIAL);
  	return 0;
  }
 
drivers/gpu/drm/amd/pm/powerplay/kv_dpm.c +3 -0
index bcae42cef374..f84f56552fd0 100644
@@ -2965,9 +2965,12 @@ static int kv_dpm_get_temp(void *handle)
  static int kv_dpm_early_init(void *handle)
  {
  	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
+	int i;
 
  	adev->powerplay.pp_funcs = &kv_dpm_funcs;
  	adev->powerplay.pp_handle = adev;
+	for (i = 0; i < AMD_IP_BLOCK_TYPE_NUM; i++)
+		atomic_set(&adev->powerplay.pg_state[i], POWERGATE_STATE_INITIAL);
  	kv_dpm_set_irq_funcs(adev);
 
  	return 0;
drivers/gpu/drm/amd/pm/powerplay/si_dpm.c +3 -0
index 81f82aa05ec2..f1eb22c9bb59 100644
@@ -7916,9 +7916,12 @@ static int si_dpm_early_init(void *handle)
  {
 
  	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
+	int i;
 
  	adev->powerplay.pp_funcs = &si_dpm_funcs;
  	adev->powerplay.pp_handle = adev;
+	for (i = 0; i < AMD_IP_BLOCK_TYPE_NUM; i++)
+		atomic_set(&adev->powerplay.pg_state[i], POWERGATE_STATE_INITIAL);
  	si_dpm_set_irq_funcs(adev);
  	return 0;
  }
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +3 -0
index 01168b8955bf..fdc25bae8237 100644
@@ -627,6 +627,7 @@ static int smu_early_init(void *handle)
  {
  	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
  	struct smu_context *smu = &adev->smu;
+	int i;
 
  	smu->adev = adev;
  	smu->pm_enabled = !!amdgpu_dpm;
@@ -639,6 +640,8 @@ static int smu_early_init(void *handle)
 
  	adev->powerplay.pp_handle = smu;
  	adev->powerplay.pp_funcs = &swsmu_pm_funcs;
+	for (i = 0; i < AMD_IP_BLOCK_TYPE_NUM; i++)
+		atomic_set(&adev->powerplay.pg_state[i], POWERGATE_STATE_INITIAL);
 
  	return smu_set_funcs(adev);
  }
author
#13 lore raw

[AMD Official Use Only]

Quoted 38 lines

-----Original Message-----
From: Lazar, Lijo <[email protected]>
Sent: Monday, November 8, 2021 7:16 PM
To: Quan, Evan <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>; Borislav Petkov <[email protected]>
Subject: Re: [PATCH] drm/amd/pm: avoid duplicate powergate/ungate setting

Quoted 26 lines · Evan Quan

Just bail out if the target IP block is already in the desired powergate/ungate state. This can avoid some duplicate settings which sometime may cause unexpected issues.

Change-Id I66346c69f121df0f5ee20182451313ae4fda2d04
---
  drivers/gpu/drm/amd/amdgpu/amdgpu.h              |  7 +++++++
  drivers/gpu/drm/amd/include/amd_shared.h         |  3 ++-
  drivers/gpu/drm/amd/pm/amdgpu_dpm.c              | 13 ++++++++++++-
  drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c |  3 +++
  drivers/gpu/drm/amd/pm/powerplay/kv_dpm.c        |  3 +++
  drivers/gpu/drm/amd/pm/powerplay/si_dpm.c        |  3 +++
  drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c        |  3 +++
  7 files changed, 33 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +0 -0
index b85b67a88a3d..19fa21ad8a44 100644
@@ -767,9 +767,16 @@ enum amd_hw_ip_block_type {
  #define HW_ID_MAX		300
  #define IP_VERSION(mj, mn, rv) (((mj) << 16) | ((mn) << 8) | (rv))
 
Quoted 9 lines

drivers/gpu/drm/amd/amdgpu/amdgpu.h enum amd_hw_ip_block_type { · line 775

Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu.h +6 -0
+enum amd_ip_powergate_state {
+	POWERGATE_STATE_INITIAL,
+	POWERGATE_STATE_GATE,
+	POWERGATE_STATE_UNGATE,
+};
+

To reflect the current state, they could be named like POWERGATE_STATE_UNKNOWN/ON/OFF.

[Quan, Evan] This may be more confusing. POWERGATE_STATE_ON means "gfx on" or "gate on which means gfx off"?

Quoted 10 lines

drivers/gpu/drm/amd/amdgpu/amdgpu.h enum amd_hw_ip_block_type { · line 779

Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu.h +1 -0
  struct amd_powerplay {
  	void *pp_handle;
  	const struct amd_pm_funcs *pp_funcs;
+	atomic_t pg_state[AMD_IP_BLOCK_TYPE_NUM];

Maybe add another field in amdgpu_ip_block_status? Downside is it won't reflect the PG state achieved through paths other than PMFW control and ipblock needs to be queried through amdgpu_device_ip_get_ip_block()

[Quan, Evan] Yes, we will need to track pg state other than PMFW control then.
That will need extra effort and seems unnecessary considering there is no such use case(need to know the PG state out of PMFW control).

BR
Evan

Quoted 150 lines

Thanks,
Lijo

Review

Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu.h +0 -0
  };
 
  /* polaris10 kickers */
(quoted diff) +0 -0

b/drivers/gpu/drm/amd/include/amd_shared.h

Review

Quoted 14 lines

index f1a46d16f7ea..4b9e68a79f06 100644

drivers/gpu/drm/amd/include/amd_shared.h +2 -1
@@ -98,7 +98,8 @@ enum amd_ip_block_type {
  	AMD_IP_BLOCK_TYPE_ACP,
  	AMD_IP_BLOCK_TYPE_VCN,
  	AMD_IP_BLOCK_TYPE_MES,
-	AMD_IP_BLOCK_TYPE_JPEG
+	AMD_IP_BLOCK_TYPE_JPEG,
+	AMD_IP_BLOCK_TYPE_NUM,
  };
 
  enum amd_clockgating_state {
(quoted diff) +0 -0

b/drivers/gpu/drm/amd/pm/amdgpu_dpm.c

drivers/gpu/drm/amd/pm/amdgpu_dpm.c int

Quoted 4 lines

index 03581d5b1836..a6b337b6f4a9 100644

drivers/gpu/drm/amd/pm/amdgpu_dpm.c +0 -0
@@ -927,6 +927,14 @@ int

amdgpu_dpm_set_powergating_by_smu(struct amdgpu_device *adev, uint32_t block

drivers/gpu/drm/amd/pm/amdgpu_dpm.c int amdgpu_dpm_set_powergating_by_smu(struct amdgpu_device *adev, uint32_t block

Quoted 5 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +2 -0
  {
  	int ret = 0;
  	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+	enum amd_ip_powergate_state pg_state =
+		gate ? POWERGATE_STATE_GATE :

POWERGATE_STATE_UNGATE;

drivers/gpu/drm/amd/pm/amdgpu_dpm.c int · line 933

Quoted 2 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +2 -0
+
+	if (atomic_read(&adev->powerplay.pg_state[block_type]) ==

pg_state) {

drivers/gpu/drm/amd/pm/amdgpu_dpm.c int · line 934

Quoted 1 line
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +1 -0
+		dev_dbg(adev->dev, "IP block%d already in the target %s

state!",

drivers/gpu/drm/amd/pm/amdgpu_dpm.c int

Quoted 7 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +3 -0
+				block_type, gate ? "gate" : "ungate");
+		return 0;
+	}
 
  	switch (block_type) {
  	case AMD_IP_BLOCK_TYPE_UVD:
@@ -976,9 +984,12 @@ int

amdgpu_dpm_set_powergating_by_smu(struct amdgpu_device *adev, uint32_t block

drivers/gpu/drm/amd/pm/amdgpu_dpm.c int amdgpu_dpm_set_powergating_by_smu(struct amdgpu_device *adev, uint32_t block

Quoted 9 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +3 -1
  		}
  		break;
  	default:
-		break;
+		return -EINVAL;
  	}
 
+	if (!ret)
+		atomic_set(&adev->powerplay.pg_state[block_type],

pg_state);

Review

Quoted 5 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +1 -0
+
  	return ret;
  }
 
(quoted diff) +0 -0

b/drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c

drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c static int amd_powerplay_create(struct

Quoted 12 lines

index bba7479f6265..8d8a7cf615eb 100644

drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c +1 -0
@@ -38,6 +38,7 @@ static const struct amd_pm_funcs pp_dpm_funcs;
  static int amd_powerplay_create(struct amdgpu_device *adev)
  {
  	struct pp_hwmgr *hwmgr;
+	int i;
 
  	if (adev == NULL)
  		return -EINVAL;
@@ -57,6 +58,8 @@ static int amd_powerplay_create(struct

amdgpu_device *adev)

drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c static int amd_powerplay_create(struct amdgpu_device *adev)

Quoted 5 lines
drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c +2 -0
  	hwmgr->display_config = &adev->pm.pm_display_cfg;
  	adev->powerplay.pp_handle = hwmgr;
  	adev->powerplay.pp_funcs = &pp_dpm_funcs;
+	for (i = 0; i < AMD_IP_BLOCK_TYPE_NUM; i++)
+		atomic_set(&adev->powerplay.pg_state[i],

POWERGATE_STATE_INITIAL);

Review

Quoted 4 lines
drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c +0 -0
  	return 0;
  }
 
(quoted diff) +0 -0

b/drivers/gpu/drm/amd/pm/powerplay/kv_dpm.c

drivers/gpu/drm/amd/pm/powerplay/kv_dpm.c static int kv_dpm_get_temp(void *handle) · line 2973

Quoted 13 lines

index bcae42cef374..f84f56552fd0 100644

drivers/gpu/drm/amd/pm/powerplay/kv_dpm.c +3 -0
@@ -2965,9 +2965,12 @@ static int kv_dpm_get_temp(void *handle)
  static int kv_dpm_early_init(void *handle)
  {
  	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
+	int i;
 
  	adev->powerplay.pp_funcs = &kv_dpm_funcs;
  	adev->powerplay.pp_handle = adev;
+	for (i = 0; i < AMD_IP_BLOCK_TYPE_NUM; i++)
+		atomic_set(&adev->powerplay.pg_state[i],

POWERGATE_STATE_INITIAL);

Review

Quoted 4 lines
drivers/gpu/drm/amd/pm/powerplay/kv_dpm.c +0 -0
  	kv_dpm_set_irq_funcs(adev);
 
  	return 0;
(quoted diff) +0 -0

b/drivers/gpu/drm/amd/pm/powerplay/si_dpm.c

drivers/gpu/drm/amd/pm/powerplay/si_dpm.c static int si_dpm_early_init(void *handle) · line 7924

Quoted 13 lines

index 81f82aa05ec2..f1eb22c9bb59 100644

drivers/gpu/drm/amd/pm/powerplay/si_dpm.c +3 -0
@@ -7916,9 +7916,12 @@ static int si_dpm_early_init(void *handle)
  {
 
  	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
+	int i;
 
  	adev->powerplay.pp_funcs = &si_dpm_funcs;
  	adev->powerplay.pp_handle = adev;
+	for (i = 0; i < AMD_IP_BLOCK_TYPE_NUM; i++)
+		atomic_set(&adev->powerplay.pg_state[i],

POWERGATE_STATE_INITIAL);

Review

Quoted 4 lines
drivers/gpu/drm/amd/pm/powerplay/si_dpm.c +0 -0
  	si_dpm_set_irq_funcs(adev);
  	return 0;
  }
(quoted diff) +0 -0

b/drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c

Quoted 12 lines

index 01168b8955bf..fdc25bae8237 100644

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +1 -0
@@ -627,6 +627,7 @@ static int smu_early_init(void *handle)
  {
  	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
  	struct smu_context *smu = &adev->smu;
+	int i;
 
  	smu->adev = adev;
  	smu->pm_enabled = !!amdgpu_dpm;

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c static int smu_early_init(void *handle) · line 644

Quoted 5 lines
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +2 -0
@@ -639,6 +640,8 @@ static int smu_early_init(void *handle)
 
  	adev->powerplay.pp_handle = smu;
  	adev->powerplay.pp_funcs = &swsmu_pm_funcs;
+	for (i = 0; i < AMD_IP_BLOCK_TYPE_NUM; i++)
+		atomic_set(&adev->powerplay.pg_state[i],

POWERGATE_STATE_INITIAL);

Quoted 4 lines
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +0 -0
  	return smu_set_funcs(adev);
  }
 
#14 lore raw
Quoted 51 lines · Evan

[AMD Official Use Only]

Quoted 38 lines

-----Original Message-----
From: Lazar, Lijo <[email protected]>
Sent: Monday, November 8, 2021 7:16 PM
To: Quan, Evan <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>; Borislav Petkov <[email protected]>
Subject: Re: [PATCH] drm/amd/pm: avoid duplicate powergate/ungate setting

Quoted 26 lines · Evan Quan

Just bail out if the target IP block is already in the desired powergate/ungate state. This can avoid some duplicate settings which sometime may cause unexpected issues.

Change-Id I66346c69f121df0f5ee20182451313ae4fda2d04
---
   drivers/gpu/drm/amd/amdgpu/amdgpu.h              |  7 +++++++
   drivers/gpu/drm/amd/include/amd_shared.h         |  3 ++-
   drivers/gpu/drm/amd/pm/amdgpu_dpm.c              | 13 ++++++++++++-
   drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c |  3 +++
   drivers/gpu/drm/amd/pm/powerplay/kv_dpm.c        |  3 +++
   drivers/gpu/drm/amd/pm/powerplay/si_dpm.c        |  3 +++
   drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c        |  3 +++
   7 files changed, 33 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +0 -0
index b85b67a88a3d..19fa21ad8a44 100644
@@ -767,9 +767,16 @@ enum amd_hw_ip_block_type {
   #define HW_ID_MAX		300
   #define IP_VERSION(mj, mn, rv) (((mj) << 16) | ((mn) << 8) | (rv))
 
Quoted 9 lines

drivers/gpu/drm/amd/amdgpu/amdgpu.h enum amd_hw_ip_block_type { · line 775

Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu.h +6 -0
+enum amd_ip_powergate_state {
+	POWERGATE_STATE_INITIAL,
+	POWERGATE_STATE_GATE,
+	POWERGATE_STATE_UNGATE,
+};
+

To reflect the current state, they could be named like POWERGATE_STATE_UNKNOWN/ON/OFF.

Quoted 1 line

[Quan, Evan] This may be more confusing. POWERGATE_STATE_ON means "gfx on" or "gate on which means gfx off"?

What I meant is -
PG_STATE_ON - Power gated
PG_STATE_OFF - Not power gated
Thanks,
Lijo

Quoted 165 lines
Quoted 10 lines

drivers/gpu/drm/amd/amdgpu/amdgpu.h enum amd_hw_ip_block_type { · line 779

Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu.h +1 -0
   struct amd_powerplay {
   	void *pp_handle;
   	const struct amd_pm_funcs *pp_funcs;
+	atomic_t pg_state[AMD_IP_BLOCK_TYPE_NUM];

Maybe add another field in amdgpu_ip_block_status? Downside is it won't reflect the PG state achieved through paths other than PMFW control and ipblock needs to be queried through amdgpu_device_ip_get_ip_block()

[Quan, Evan] Yes, we will need to track pg state other than PMFW control then.
That will need extra effort and seems unnecessary considering there is no such use case(need to know the PG state out of PMFW control).

BR
Evan

Quoted 150 lines

Thanks,
Lijo

Review

Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu.h +0 -0
   };
 
   /* polaris10 kickers */
(quoted diff) +0 -0

b/drivers/gpu/drm/amd/include/amd_shared.h

Review

Quoted 14 lines

index f1a46d16f7ea..4b9e68a79f06 100644

drivers/gpu/drm/amd/include/amd_shared.h +2 -1
@@ -98,7 +98,8 @@ enum amd_ip_block_type {
   	AMD_IP_BLOCK_TYPE_ACP,
   	AMD_IP_BLOCK_TYPE_VCN,
   	AMD_IP_BLOCK_TYPE_MES,
-	AMD_IP_BLOCK_TYPE_JPEG
+	AMD_IP_BLOCK_TYPE_JPEG,
+	AMD_IP_BLOCK_TYPE_NUM,
   };
 
   enum amd_clockgating_state {
(quoted diff) +0 -0

b/drivers/gpu/drm/amd/pm/amdgpu_dpm.c

drivers/gpu/drm/amd/pm/amdgpu_dpm.c int

Quoted 4 lines

index 03581d5b1836..a6b337b6f4a9 100644

drivers/gpu/drm/amd/pm/amdgpu_dpm.c +0 -0
@@ -927,6 +927,14 @@ int

amdgpu_dpm_set_powergating_by_smu(struct amdgpu_device *adev, uint32_t block

drivers/gpu/drm/amd/pm/amdgpu_dpm.c int amdgpu_dpm_set_powergating_by_smu(struct amdgpu_device *adev, uint32_t block

Quoted 5 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +2 -0
   {
   	int ret = 0;
   	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+	enum amd_ip_powergate_state pg_state =
+		gate ? POWERGATE_STATE_GATE :

POWERGATE_STATE_UNGATE;

drivers/gpu/drm/amd/pm/amdgpu_dpm.c int · line 933

Quoted 2 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +2 -0
+
+	if (atomic_read(&adev->powerplay.pg_state[block_type]) ==

pg_state) {

drivers/gpu/drm/amd/pm/amdgpu_dpm.c int · line 934

Quoted 1 line
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +1 -0
+		dev_dbg(adev->dev, "IP block%d already in the target %s

state!",

drivers/gpu/drm/amd/pm/amdgpu_dpm.c int

Quoted 7 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +3 -0
+				block_type, gate ? "gate" : "ungate");
+		return 0;
+	}
 
   	switch (block_type) {
   	case AMD_IP_BLOCK_TYPE_UVD:
@@ -976,9 +984,12 @@ int

amdgpu_dpm_set_powergating_by_smu(struct amdgpu_device *adev, uint32_t block

drivers/gpu/drm/amd/pm/amdgpu_dpm.c int amdgpu_dpm_set_powergating_by_smu(struct amdgpu_device *adev, uint32_t block

Quoted 9 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +3 -1
   		}
   		break;
   	default:
-		break;
+		return -EINVAL;
   	}
 
+	if (!ret)
+		atomic_set(&adev->powerplay.pg_state[block_type],

pg_state);

Review

Quoted 5 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +1 -0
+
   	return ret;
   }
 
(quoted diff) +0 -0

b/drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c

drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c static int amd_powerplay_create(struct

Quoted 12 lines

index bba7479f6265..8d8a7cf615eb 100644

drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c +1 -0
@@ -38,6 +38,7 @@ static const struct amd_pm_funcs pp_dpm_funcs;
   static int amd_powerplay_create(struct amdgpu_device *adev)
   {
   	struct pp_hwmgr *hwmgr;
+	int i;
 
   	if (adev == NULL)
   		return -EINVAL;
@@ -57,6 +58,8 @@ static int amd_powerplay_create(struct

amdgpu_device *adev)

drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c static int amd_powerplay_create(struct amdgpu_device *adev)

Quoted 5 lines
drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c +2 -0
   	hwmgr->display_config = &adev->pm.pm_display_cfg;
   	adev->powerplay.pp_handle = hwmgr;
   	adev->powerplay.pp_funcs = &pp_dpm_funcs;
+	for (i = 0; i < AMD_IP_BLOCK_TYPE_NUM; i++)
+		atomic_set(&adev->powerplay.pg_state[i],

POWERGATE_STATE_INITIAL);

Review

Quoted 4 lines
drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c +0 -0
   	return 0;
   }
 
(quoted diff) +0 -0

b/drivers/gpu/drm/amd/pm/powerplay/kv_dpm.c

drivers/gpu/drm/amd/pm/powerplay/kv_dpm.c static int kv_dpm_get_temp(void *handle) · line 2973

Quoted 13 lines

index bcae42cef374..f84f56552fd0 100644

drivers/gpu/drm/amd/pm/powerplay/kv_dpm.c +3 -0
@@ -2965,9 +2965,12 @@ static int kv_dpm_get_temp(void *handle)
   static int kv_dpm_early_init(void *handle)
   {
   	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
+	int i;
 
   	adev->powerplay.pp_funcs = &kv_dpm_funcs;
   	adev->powerplay.pp_handle = adev;
+	for (i = 0; i < AMD_IP_BLOCK_TYPE_NUM; i++)
+		atomic_set(&adev->powerplay.pg_state[i],

POWERGATE_STATE_INITIAL);

Review

Quoted 4 lines
drivers/gpu/drm/amd/pm/powerplay/kv_dpm.c +0 -0
   	kv_dpm_set_irq_funcs(adev);
 
   	return 0;
(quoted diff) +0 -0

b/drivers/gpu/drm/amd/pm/powerplay/si_dpm.c

drivers/gpu/drm/amd/pm/powerplay/si_dpm.c static int si_dpm_early_init(void *handle) · line 7924

Quoted 13 lines

index 81f82aa05ec2..f1eb22c9bb59 100644

drivers/gpu/drm/amd/pm/powerplay/si_dpm.c +3 -0
@@ -7916,9 +7916,12 @@ static int si_dpm_early_init(void *handle)
   {
 
   	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
+	int i;
 
   	adev->powerplay.pp_funcs = &si_dpm_funcs;
   	adev->powerplay.pp_handle = adev;
+	for (i = 0; i < AMD_IP_BLOCK_TYPE_NUM; i++)
+		atomic_set(&adev->powerplay.pg_state[i],

POWERGATE_STATE_INITIAL);

Review

Quoted 4 lines
drivers/gpu/drm/amd/pm/powerplay/si_dpm.c +0 -0
   	si_dpm_set_irq_funcs(adev);
   	return 0;
   }
(quoted diff) +0 -0

b/drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c

Quoted 12 lines

index 01168b8955bf..fdc25bae8237 100644

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +1 -0
@@ -627,6 +627,7 @@ static int smu_early_init(void *handle)
   {
   	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
   	struct smu_context *smu = &adev->smu;
+	int i;
 
   	smu->adev = adev;
   	smu->pm_enabled = !!amdgpu_dpm;

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c static int smu_early_init(void *handle) · line 644

Quoted 5 lines
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +2 -0
@@ -639,6 +640,8 @@ static int smu_early_init(void *handle)
 
   	adev->powerplay.pp_handle = smu;
   	adev->powerplay.pp_funcs = &swsmu_pm_funcs;
+	for (i = 0; i < AMD_IP_BLOCK_TYPE_NUM; i++)
+		atomic_set(&adev->powerplay.pg_state[i],

POWERGATE_STATE_INITIAL);

Quoted 4 lines
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +0 -0
   	return smu_set_funcs(adev);
   }
 
author
#15 lore raw

[AMD Official Use Only]

Quoted 64 lines

-----Original Message-----
From: Lazar, Lijo <[email protected]>
Sent: Tuesday, November 9, 2021 12:15 PM
To: Quan, Evan <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>; Borislav Petkov <[email protected]>
Subject: Re: [PATCH] drm/amd/pm: avoid duplicate powergate/ungate setting

Quoted 52 lines · Evan

[AMD Official Use Only]

Quoted 48 lines

-----Original Message-----
From: Lazar, Lijo <[email protected]>
Sent: Monday, November 8, 2021 7:16 PM
To: Quan, Evan <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>; Borislav Petkov <[email protected]>
Subject: Re: [PATCH] drm/amd/pm: avoid duplicate powergate/ungate setting

Quoted 23 lines · Evan Quan

Just bail out if the target IP block is already in the desired powergate/ungate state. This can avoid some duplicate settings which sometime may cause unexpected issues.

Change-Id I66346c69f121df0f5ee20182451313ae4fda2d04
---
   drivers/gpu/drm/amd/amdgpu/amdgpu.h              |  7 +++++++
   drivers/gpu/drm/amd/include/amd_shared.h         |  3 ++-
   drivers/gpu/drm/amd/pm/amdgpu_dpm.c              | 13 ++++++++++++-
   drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c |  3 +++
   drivers/gpu/drm/amd/pm/powerplay/kv_dpm.c        |  3 +++
   drivers/gpu/drm/amd/pm/powerplay/si_dpm.c        |  3 +++
   drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c        |  3 +++
   7 files changed, 33 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +0 -0
index b85b67a88a3d..19fa21ad8a44 100644

drivers/gpu/drm/amd/amdgpu/amdgpu.h enum amd_hw_ip_block_type { · line 776

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu.h +6 -0
@@ -767,9 +767,16 @@ enum amd_hw_ip_block_type {
   #define HW_ID_MAX		300
   #define IP_VERSION(mj, mn, rv) (((mj) << 16) | ((mn) << 8) |
 (rv))
 
+enum amd_ip_powergate_state {
+	POWERGATE_STATE_INITIAL,
+	POWERGATE_STATE_GATE,
+	POWERGATE_STATE_UNGATE,
+};
+

To reflect the current state, they could be named like POWERGATE_STATE_UNKNOWN/ON/OFF.

Quoted 6 lines
Quoted 1 line

[Quan, Evan] This may be more confusing. POWERGATE_STATE_ON means

"gfx on" or "gate on which means gfx off"?

What I meant is -
PG_STATE_ON - Power gated
PG_STATE_OFF - Not power gated

[Quan, Evan] Yeah, but I mean other user may be confusing about these. Since when we take about the PG state, we usually use "Gate" or "Ungate". How about POWER_STATE_ON - Power on/ungate POWER_STATE_OFF - Power off/gate ?

BR
Evan

Quoted 171 lines

Thanks,
Lijo

Quoted 11 lines
Quoted 11 lines

drivers/gpu/drm/amd/amdgpu/amdgpu.h enum amd_hw_ip_block_type { · line 779

Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu.h +1 -0
   struct amd_powerplay {
   	void *pp_handle;
   	const struct amd_pm_funcs *pp_funcs;
+	atomic_t pg_state[AMD_IP_BLOCK_TYPE_NUM];

Maybe add another field in amdgpu_ip_block_status? Downside is it won't reflect the PG state achieved through paths other than PMFW control and ipblock needs to be queried through amdgpu_device_ip_get_ip_block()

Quoted 1 line

[Quan, Evan] Yes, we will need to track pg state other than PMFW control

then.

Quoted 1 line

That will need extra effort and seems unnecessary considering there is no

such use case(need to know the PG state out of PMFW control).

Quoted 153 lines

BR
Evan

Quoted 150 lines

Thanks,
Lijo

Review

Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu.h +0 -0
   };
 
   /* polaris10 kickers */
(quoted diff) +0 -0

b/drivers/gpu/drm/amd/include/amd_shared.h

Review

Quoted 14 lines

index f1a46d16f7ea..4b9e68a79f06 100644

drivers/gpu/drm/amd/include/amd_shared.h +2 -1
@@ -98,7 +98,8 @@ enum amd_ip_block_type {
   	AMD_IP_BLOCK_TYPE_ACP,
   	AMD_IP_BLOCK_TYPE_VCN,
   	AMD_IP_BLOCK_TYPE_MES,
-	AMD_IP_BLOCK_TYPE_JPEG
+	AMD_IP_BLOCK_TYPE_JPEG,
+	AMD_IP_BLOCK_TYPE_NUM,
   };
 
   enum amd_clockgating_state {
(quoted diff) +0 -0

b/drivers/gpu/drm/amd/pm/amdgpu_dpm.c

drivers/gpu/drm/amd/pm/amdgpu_dpm.c int

Quoted 4 lines

index 03581d5b1836..a6b337b6f4a9 100644

drivers/gpu/drm/amd/pm/amdgpu_dpm.c +0 -0
@@ -927,6 +927,14 @@ int

amdgpu_dpm_set_powergating_by_smu(struct amdgpu_device *adev, uint32_t block

drivers/gpu/drm/amd/pm/amdgpu_dpm.c int amdgpu_dpm_set_powergating_by_smu(struct amdgpu_device *adev, uint32_t block

Quoted 5 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +2 -0
   {
   	int ret = 0;
   	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+	enum amd_ip_powergate_state pg_state =
+		gate ? POWERGATE_STATE_GATE :

POWERGATE_STATE_UNGATE;

drivers/gpu/drm/amd/pm/amdgpu_dpm.c int · line 933

Quoted 2 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +2 -0
+
+	if (atomic_read(&adev->powerplay.pg_state[block_type]) ==

pg_state) {

drivers/gpu/drm/amd/pm/amdgpu_dpm.c int · line 934

Quoted 1 line
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +1 -0
+		dev_dbg(adev->dev, "IP block%d already in the target %s

state!",

drivers/gpu/drm/amd/pm/amdgpu_dpm.c int

Quoted 7 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +3 -0
+				block_type, gate ? "gate" : "ungate");
+		return 0;
+	}
 
   	switch (block_type) {
   	case AMD_IP_BLOCK_TYPE_UVD:
@@ -976,9 +984,12 @@ int

amdgpu_dpm_set_powergating_by_smu(struct amdgpu_device *adev, uint32_t block

drivers/gpu/drm/amd/pm/amdgpu_dpm.c int amdgpu_dpm_set_powergating_by_smu(struct amdgpu_device *adev, uint32_t block

Quoted 9 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +3 -1
   		}
   		break;
   	default:
-		break;
+		return -EINVAL;
   	}
 
+	if (!ret)
+		atomic_set(&adev->powerplay.pg_state[block_type],

pg_state);

Review

Quoted 5 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +1 -0
+
   	return ret;
   }
 
(quoted diff) +0 -0

b/drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c

drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c static int amd_powerplay_create(struct

Quoted 12 lines

index bba7479f6265..8d8a7cf615eb 100644

drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c +1 -0
@@ -38,6 +38,7 @@ static const struct amd_pm_funcs pp_dpm_funcs;
   static int amd_powerplay_create(struct amdgpu_device *adev)
   {
   	struct pp_hwmgr *hwmgr;
+	int i;
 
   	if (adev == NULL)
   		return -EINVAL;
@@ -57,6 +58,8 @@ static int amd_powerplay_create(struct

amdgpu_device *adev)

drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c static int amd_powerplay_create(struct amdgpu_device *adev)

Quoted 5 lines
drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c +2 -0
   	hwmgr->display_config = &adev->pm.pm_display_cfg;
   	adev->powerplay.pp_handle = hwmgr;
   	adev->powerplay.pp_funcs = &pp_dpm_funcs;
+	for (i = 0; i < AMD_IP_BLOCK_TYPE_NUM; i++)
+		atomic_set(&adev->powerplay.pg_state[i],

POWERGATE_STATE_INITIAL);

Review

Quoted 4 lines
drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c +0 -0
   	return 0;
   }
 
(quoted diff) +0 -0

b/drivers/gpu/drm/amd/pm/powerplay/kv_dpm.c

drivers/gpu/drm/amd/pm/powerplay/kv_dpm.c static int kv_dpm_get_temp(void *handle) · line 2973

Quoted 13 lines

index bcae42cef374..f84f56552fd0 100644

drivers/gpu/drm/amd/pm/powerplay/kv_dpm.c +3 -0
@@ -2965,9 +2965,12 @@ static int kv_dpm_get_temp(void *handle)
   static int kv_dpm_early_init(void *handle)
   {
   	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
+	int i;
 
   	adev->powerplay.pp_funcs = &kv_dpm_funcs;
   	adev->powerplay.pp_handle = adev;
+	for (i = 0; i < AMD_IP_BLOCK_TYPE_NUM; i++)
+		atomic_set(&adev->powerplay.pg_state[i],

POWERGATE_STATE_INITIAL);

Review

Quoted 4 lines
drivers/gpu/drm/amd/pm/powerplay/kv_dpm.c +0 -0
   	kv_dpm_set_irq_funcs(adev);
 
   	return 0;
(quoted diff) +0 -0

b/drivers/gpu/drm/amd/pm/powerplay/si_dpm.c

drivers/gpu/drm/amd/pm/powerplay/si_dpm.c static int si_dpm_early_init(void *handle) · line 7924

Quoted 13 lines

index 81f82aa05ec2..f1eb22c9bb59 100644

drivers/gpu/drm/amd/pm/powerplay/si_dpm.c +3 -0
@@ -7916,9 +7916,12 @@ static int si_dpm_early_init(void *handle)
   {
 
   	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
+	int i;
 
   	adev->powerplay.pp_funcs = &si_dpm_funcs;
   	adev->powerplay.pp_handle = adev;
+	for (i = 0; i < AMD_IP_BLOCK_TYPE_NUM; i++)
+		atomic_set(&adev->powerplay.pg_state[i],

POWERGATE_STATE_INITIAL);

Review

Quoted 4 lines
drivers/gpu/drm/amd/pm/powerplay/si_dpm.c +0 -0
   	si_dpm_set_irq_funcs(adev);
   	return 0;
   }
(quoted diff) +0 -0

b/drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c

Quoted 12 lines

index 01168b8955bf..fdc25bae8237 100644

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +1 -0
@@ -627,6 +627,7 @@ static int smu_early_init(void *handle)
   {
   	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
   	struct smu_context *smu = &adev->smu;
+	int i;
 
   	smu->adev = adev;
   	smu->pm_enabled = !!amdgpu_dpm;

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c static int smu_early_init(void *handle) · line 644

Quoted 5 lines
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +2 -0
@@ -639,6 +640,8 @@ static int smu_early_init(void *handle)
 
   	adev->powerplay.pp_handle = smu;
   	adev->powerplay.pp_funcs = &swsmu_pm_funcs;
+	for (i = 0; i < AMD_IP_BLOCK_TYPE_NUM; i++)
+		atomic_set(&adev->powerplay.pg_state[i],

POWERGATE_STATE_INITIAL);

Quoted 4 lines
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +0 -0
   	return smu_set_funcs(adev);
   }
 
#16 lore raw
Quoted 68 lines · Evan

[AMD Official Use Only]

Quoted 64 lines

-----Original Message-----
From: Lazar, Lijo <[email protected]>
Sent: Tuesday, November 9, 2021 12:15 PM
To: Quan, Evan <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>; Borislav Petkov <[email protected]>
Subject: Re: [PATCH] drm/amd/pm: avoid duplicate powergate/ungate setting

Quoted 52 lines · Evan

[AMD Official Use Only]

Quoted 48 lines

-----Original Message-----
From: Lazar, Lijo <[email protected]>
Sent: Monday, November 8, 2021 7:16 PM
To: Quan, Evan <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>; Borislav Petkov <[email protected]>
Subject: Re: [PATCH] drm/amd/pm: avoid duplicate powergate/ungate setting

Quoted 23 lines · Evan Quan

Just bail out if the target IP block is already in the desired powergate/ungate state. This can avoid some duplicate settings which sometime may cause unexpected issues.

Change-Id I66346c69f121df0f5ee20182451313ae4fda2d04
---
    drivers/gpu/drm/amd/amdgpu/amdgpu.h              |  7 +++++++
    drivers/gpu/drm/amd/include/amd_shared.h         |  3 ++-
    drivers/gpu/drm/amd/pm/amdgpu_dpm.c              | 13 ++++++++++++-
    drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c |  3 +++
    drivers/gpu/drm/amd/pm/powerplay/kv_dpm.c        |  3 +++
    drivers/gpu/drm/amd/pm/powerplay/si_dpm.c        |  3 +++
    drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c        |  3 +++
    7 files changed, 33 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +0 -0
index b85b67a88a3d..19fa21ad8a44 100644

drivers/gpu/drm/amd/amdgpu/amdgpu.h enum amd_hw_ip_block_type { · line 776

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu.h +6 -0
@@ -767,9 +767,16 @@ enum amd_hw_ip_block_type {
    #define HW_ID_MAX		300
    #define IP_VERSION(mj, mn, rv) (((mj) << 16) | ((mn) << 8) |
 (rv))
 
+enum amd_ip_powergate_state {
+	POWERGATE_STATE_INITIAL,
+	POWERGATE_STATE_GATE,
+	POWERGATE_STATE_UNGATE,
+};
+

To reflect the current state, they could be named like POWERGATE_STATE_UNKNOWN/ON/OFF.

Quoted 9 lines
Quoted 6 lines
Quoted 1 line

[Quan, Evan] This may be more confusing. POWERGATE_STATE_ON means

"gfx on" or "gate on which means gfx off"?

What I meant is -
PG_STATE_ON - Power gated
PG_STATE_OFF - Not power gated

[Quan, Evan] Yeah, but I mean other user may be confusing about these. Since when we take about the PG state, we usually use "Gate" or "Ungate". How about POWER_STATE_ON - Power on/ungate POWER_STATE_OFF - Power off/gate ?

Yes, that looks fine.

Thanks,
Lijo

Quoted 173 lines

BR
Evan

Quoted 171 lines

Thanks,
Lijo

Quoted 11 lines
Quoted 11 lines

drivers/gpu/drm/amd/amdgpu/amdgpu.h enum amd_hw_ip_block_type { · line 779

Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu.h +1 -0
    struct amd_powerplay {
    	void *pp_handle;
    	const struct amd_pm_funcs *pp_funcs;
+	atomic_t pg_state[AMD_IP_BLOCK_TYPE_NUM];

Maybe add another field in amdgpu_ip_block_status? Downside is it won't reflect the PG state achieved through paths other than PMFW control and ipblock needs to be queried through amdgpu_device_ip_get_ip_block()

Quoted 1 line

[Quan, Evan] Yes, we will need to track pg state other than PMFW control

then.

Quoted 1 line

That will need extra effort and seems unnecessary considering there is no

such use case(need to know the PG state out of PMFW control).

Quoted 153 lines

BR
Evan

Quoted 150 lines

Thanks,
Lijo

Review

Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu.h +0 -0
    };
 
    /* polaris10 kickers */
(quoted diff) +0 -0

b/drivers/gpu/drm/amd/include/amd_shared.h

Review

Quoted 14 lines

index f1a46d16f7ea..4b9e68a79f06 100644

drivers/gpu/drm/amd/include/amd_shared.h +2 -1
@@ -98,7 +98,8 @@ enum amd_ip_block_type {
    	AMD_IP_BLOCK_TYPE_ACP,
    	AMD_IP_BLOCK_TYPE_VCN,
    	AMD_IP_BLOCK_TYPE_MES,
-	AMD_IP_BLOCK_TYPE_JPEG
+	AMD_IP_BLOCK_TYPE_JPEG,
+	AMD_IP_BLOCK_TYPE_NUM,
    };
 
    enum amd_clockgating_state {
(quoted diff) +0 -0

b/drivers/gpu/drm/amd/pm/amdgpu_dpm.c

drivers/gpu/drm/amd/pm/amdgpu_dpm.c int

Quoted 4 lines

index 03581d5b1836..a6b337b6f4a9 100644

drivers/gpu/drm/amd/pm/amdgpu_dpm.c +0 -0
@@ -927,6 +927,14 @@ int

amdgpu_dpm_set_powergating_by_smu(struct amdgpu_device *adev, uint32_t block

drivers/gpu/drm/amd/pm/amdgpu_dpm.c int amdgpu_dpm_set_powergating_by_smu(struct amdgpu_device *adev, uint32_t block

Quoted 5 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +2 -0
    {
    	int ret = 0;
    	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+	enum amd_ip_powergate_state pg_state =
+		gate ? POWERGATE_STATE_GATE :

POWERGATE_STATE_UNGATE;

drivers/gpu/drm/amd/pm/amdgpu_dpm.c int · line 933

Quoted 2 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +2 -0
+
+	if (atomic_read(&adev->powerplay.pg_state[block_type]) ==

pg_state) {

drivers/gpu/drm/amd/pm/amdgpu_dpm.c int · line 934

Quoted 1 line
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +1 -0
+		dev_dbg(adev->dev, "IP block%d already in the target %s

state!",

drivers/gpu/drm/amd/pm/amdgpu_dpm.c int

Quoted 7 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +3 -0
+				block_type, gate ? "gate" : "ungate");
+		return 0;
+	}
 
    	switch (block_type) {
    	case AMD_IP_BLOCK_TYPE_UVD:
@@ -976,9 +984,12 @@ int

amdgpu_dpm_set_powergating_by_smu(struct amdgpu_device *adev, uint32_t block

drivers/gpu/drm/amd/pm/amdgpu_dpm.c int amdgpu_dpm_set_powergating_by_smu(struct amdgpu_device *adev, uint32_t block

Quoted 9 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +3 -1
    		}
    		break;
    	default:
-		break;
+		return -EINVAL;
    	}
 
+	if (!ret)
+		atomic_set(&adev->powerplay.pg_state[block_type],

pg_state);

Review

Quoted 5 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +1 -0
+
    	return ret;
    }
 
(quoted diff) +0 -0

b/drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c

drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c static int amd_powerplay_create(struct

Quoted 12 lines

index bba7479f6265..8d8a7cf615eb 100644

drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c +1 -0
@@ -38,6 +38,7 @@ static const struct amd_pm_funcs pp_dpm_funcs;
    static int amd_powerplay_create(struct amdgpu_device *adev)
    {
    	struct pp_hwmgr *hwmgr;
+	int i;
 
    	if (adev == NULL)
    		return -EINVAL;
@@ -57,6 +58,8 @@ static int amd_powerplay_create(struct

amdgpu_device *adev)

drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c static int amd_powerplay_create(struct amdgpu_device *adev)

Quoted 5 lines
drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c +2 -0
    	hwmgr->display_config = &adev->pm.pm_display_cfg;
    	adev->powerplay.pp_handle = hwmgr;
    	adev->powerplay.pp_funcs = &pp_dpm_funcs;
+	for (i = 0; i < AMD_IP_BLOCK_TYPE_NUM; i++)
+		atomic_set(&adev->powerplay.pg_state[i],

POWERGATE_STATE_INITIAL);

Review

Quoted 4 lines
drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c +0 -0
    	return 0;
    }
 
(quoted diff) +0 -0

b/drivers/gpu/drm/amd/pm/powerplay/kv_dpm.c

drivers/gpu/drm/amd/pm/powerplay/kv_dpm.c static int kv_dpm_get_temp(void *handle) · line 2973

Quoted 13 lines

index bcae42cef374..f84f56552fd0 100644

drivers/gpu/drm/amd/pm/powerplay/kv_dpm.c +3 -0
@@ -2965,9 +2965,12 @@ static int kv_dpm_get_temp(void *handle)
    static int kv_dpm_early_init(void *handle)
    {
    	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
+	int i;
 
    	adev->powerplay.pp_funcs = &kv_dpm_funcs;
    	adev->powerplay.pp_handle = adev;
+	for (i = 0; i < AMD_IP_BLOCK_TYPE_NUM; i++)
+		atomic_set(&adev->powerplay.pg_state[i],

POWERGATE_STATE_INITIAL);

Review

Quoted 4 lines
drivers/gpu/drm/amd/pm/powerplay/kv_dpm.c +0 -0
    	kv_dpm_set_irq_funcs(adev);
 
    	return 0;
(quoted diff) +0 -0

b/drivers/gpu/drm/amd/pm/powerplay/si_dpm.c

drivers/gpu/drm/amd/pm/powerplay/si_dpm.c static int si_dpm_early_init(void *handle) · line 7924

Quoted 13 lines

index 81f82aa05ec2..f1eb22c9bb59 100644

drivers/gpu/drm/amd/pm/powerplay/si_dpm.c +3 -0
@@ -7916,9 +7916,12 @@ static int si_dpm_early_init(void *handle)
    {
 
    	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
+	int i;
 
    	adev->powerplay.pp_funcs = &si_dpm_funcs;
    	adev->powerplay.pp_handle = adev;
+	for (i = 0; i < AMD_IP_BLOCK_TYPE_NUM; i++)
+		atomic_set(&adev->powerplay.pg_state[i],

POWERGATE_STATE_INITIAL);

Review

Quoted 4 lines
drivers/gpu/drm/amd/pm/powerplay/si_dpm.c +0 -0
    	si_dpm_set_irq_funcs(adev);
    	return 0;
    }
(quoted diff) +0 -0

b/drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c

Quoted 12 lines

index 01168b8955bf..fdc25bae8237 100644

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +1 -0
@@ -627,6 +627,7 @@ static int smu_early_init(void *handle)
    {
    	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
    	struct smu_context *smu = &adev->smu;
+	int i;
 
    	smu->adev = adev;
    	smu->pm_enabled = !!amdgpu_dpm;

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c static int smu_early_init(void *handle) · line 644

Quoted 5 lines
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +2 -0
@@ -639,6 +640,8 @@ static int smu_early_init(void *handle)
 
    	adev->powerplay.pp_handle = smu;
    	adev->powerplay.pp_funcs = &swsmu_pm_funcs;
+	for (i = 0; i < AMD_IP_BLOCK_TYPE_NUM; i++)
+		atomic_set(&adev->powerplay.pg_state[i],

POWERGATE_STATE_INITIAL);

Quoted 4 lines
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +0 -0
    	return smu_set_funcs(adev);
    }