Skip to contentSkip to conversation

drm/amdgpu/vcn5.0.1: use correct dpm helper

PATCH In review Alex Deucher 3 participants 7 messages Feb 10, 2025 – Feb 12, 2025

Subsystems (3)
lore
Share & tools
lore

Alex Deucher

author maintainer
#0 lore raw

PATCH 1/3 drm/amdgpu/vcn5.0.1: use correct dpm helper

The VCN and UVD helpers were split in
commit ff69bba05f08 ("drm/amd/pm: add inst to dpm_set_powergating_by_smu") However, this happened in parallel to the vcn 5.0.1 development so it was missed there.

Fixes 346492f30ce3 ("drm/amdgpu: Add VCN_5_0_1 support")
Cc Sonny Jiang <[email protected]>
Cc Boyuan Zhang <[email protected]>
---
 drivers/gpu/drm/amd/amdgpu/vcn_v5_0_1.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)
drivers/gpu/drm/amd/amdgpu/vcn_v5_0_1.c +8 -4
index 8b463c977d08f..8b0b3739a5377 100644
@@ -575,8 +575,10 @@ static int vcn_v5_0_1_start(struct amdgpu_device *adev)
 	uint32_t tmp;
 	int i, j, k, r, vcn_inst;
 
-	if (adev->pm.dpm_enabled)
-		amdgpu_dpm_enable_uvd(adev, true);
+	for (i = 0; i < adev->vcn.num_vcn_inst; ++i) {
+		if (adev->pm.dpm_enabled)
+			amdgpu_dpm_enable_vcn(adev, true, i);
+	}
 
 	for (i = 0; i < adev->vcn.num_vcn_inst; ++i) {
 		fw_shared = adev->vcn.inst[i].fw_shared.cpu_addr;
@@ -816,8 +818,10 @@ static int vcn_v5_0_1_stop(struct amdgpu_device *adev)
 		WREG32_SOC15(VCN, vcn_inst, regUVD_STATUS, 0);
 	}
 
-	if (adev->pm.dpm_enabled)
-		amdgpu_dpm_enable_uvd(adev, false);
+	for (i = 0; i < adev->vcn.num_vcn_inst; ++i) {
+		if (adev->pm.dpm_enabled)
+			amdgpu_dpm_enable_vcn(adev, false, i);
+	}
 
 	return 0;
 }
Signature · 1 line
2.48.1
author maintainer
#1 lore raw

PATCH 2/3 drm/amdgpu/pm: fix UVD handing in amdgpu_dpm_set_powergating_by_smu()

UVD and VCN were split into separate dpm helpers in commit ff69bba05f08 ("drm/amd/pm: add inst to dpm_set_powergating_by_smu") but the check at the top was still included UVD from an earlier version of the patch. Fix the check.

Fixes ff69bba05f08 ("drm/amd/pm: add inst to dpm_set_powergating_by_smu")
Cc Boyuan Zhang <[email protected]>
---
 drivers/gpu/drm/amd/pm/amdgpu_dpm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +1 -1
index 6a9e26905edfc..7a22aef6e59c3 100644
@@ -78,7 +78,7 @@ int amdgpu_dpm_set_powergating_by_smu(struct amdgpu_device *adev,
 	int ret = 0;
 	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
 	enum ip_power_state pwr_state = gate ? POWER_STATE_OFF : POWER_STATE_ON;
-	bool is_vcn = (block_type == AMD_IP_BLOCK_TYPE_UVD || block_type == AMD_IP_BLOCK_TYPE_VCN);
+	bool is_vcn = block_type == AMD_IP_BLOCK_TYPE_VCN;
 
 	if (atomic_read(&adev->pm.pwr_state[block_type]) == pwr_state &&
 			(!is_vcn || adev->vcn.num_vcn_inst == 1)) {
Signature · 1 line
2.48.1
#2 lore raw

Re: [PATCH 2/3] drm/amdgpu/pm: fix UVD handing in amdgpu_dpm_set_powergating_by_smu()

Ping on this series? This fixes a regression.

Alex

Quoted 31 lines · Alex Deucher

UVD and VCN were split into separate dpm helpers in commit ff69bba05f08 ("drm/amd/pm: add inst to dpm_set_powergating_by_smu") but the check at the top was still included UVD from an earlier version of the patch. Fix the check.

Fixes ff69bba05f08 ("drm/amd/pm: add inst to dpm_set_powergating_by_smu")
Cc Boyuan Zhang <[email protected]>
---
 drivers/gpu/drm/amd/pm/amdgpu_dpm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +1 -2
index 6a9e26905edfc..7a22aef6e59c3 100644
@@ -78,7 +78,7 @@ int amdgpu_dpm_set_powergating_by_smu(struct amdgpu_device *adev,
        int ret = 0;
        const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
        enum ip_power_state pwr_state = gate ? POWER_STATE_OFF : POWER_STATE_ON;
-       bool is_vcn = (block_type == AMD_IP_BLOCK_TYPE_UVD || block_type == AMD_IP_BLOCK_TYPE_VCN);
+       bool is_vcn = block_type == AMD_IP_BLOCK_TYPE_VCN;
 
        if (atomic_read(&adev->pm.pwr_state[block_type]) == pwr_state &&
                        (!is_vcn || adev->vcn.num_vcn_inst == 1)) {
--

2.48.1

Reviewed-by on v1 2/3
#3 lore raw

Re: [PATCH 2/3] drm/amdgpu/pm: fix UVD handing in amdgpu_dpm_set_powergating_by_smu()

In reply to Alex Deucher
Quoted 4 lines · Alex Deucher

UVD and VCN were split into separate dpm helpers in commit ff69bba05f08 ("drm/amd/pm: add inst to dpm_set_powergating_by_smu") but the check at the top was still included UVD from an earlier version of the patch. Fix the check.

This description is not clear -'earlier version of the patch'. I see UVD check is introduced by the same patch.

Quoted 5 lines

Thanks,
Lijo

Quoted 18 lines
Cc Boyuan Zhang <[email protected]>
---
 drivers/gpu/drm/amd/pm/amdgpu_dpm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +1 -1
index 6a9e26905edfc..7a22aef6e59c3 100644
@@ -78,7 +78,7 @@ int amdgpu_dpm_set_powergating_by_smu(struct amdgpu_device *adev,
 	int ret = 0;
 	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
 	enum ip_power_state pwr_state = gate ? POWER_STATE_OFF : POWER_STATE_ON;
-	bool is_vcn = (block_type == AMD_IP_BLOCK_TYPE_UVD || block_type == AMD_IP_BLOCK_TYPE_VCN);
+	bool is_vcn = block_type == AMD_IP_BLOCK_TYPE_VCN;
 
 	if (atomic_read(&adev->pm.pwr_state[block_type]) == pwr_state &&
 			(!is_vcn || adev->vcn.num_vcn_inst == 1)) {
author maintainer
#4 lore raw

PATCH 3/3 drm/amdgpu/pm: store power state per instance

In reply to Alex Deucher

Simplify the driver logic. We support multiple instances now so reflect that in the driver state.

Fixes ff69bba05f08 ("drm/amd/pm: add inst to dpm_set_powergating_by_smu")
Cc Boyuan Zhang <[email protected]>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_device.c |  9 ++++++---
 drivers/gpu/drm/amd/include/amd_shared.h   |  2 ++
 drivers/gpu/drm/amd/pm/amdgpu_dpm.c        | 16 ++++++++++------
 drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h    |  2 +-
 4 files changed, 19 insertions(+), 10 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +6 -3
index 32926458d50ce..7325c21d60fc8 100644
@@ -4184,7 +4184,7 @@ int amdgpu_device_init(struct amdgpu_device *adev,
 {
 	struct drm_device *ddev = adev_to_drm(adev);
 	struct pci_dev *pdev = adev->pdev;
-	int r, i;
+	int r, i, j;
 	bool px = false;
 	u32 max_MBps;
 	int tmp;
@@ -4338,8 +4338,11 @@ int amdgpu_device_init(struct amdgpu_device *adev,
 		adev->rmmio_size = pci_resource_len(adev->pdev, 2);
 	}
 
-	for (i = 0; i < AMD_IP_BLOCK_TYPE_NUM; i++)
-		atomic_set(&adev->pm.pwr_state[i], POWER_STATE_UNKNOWN);
+	for (i = 0; i < AMD_IP_BLOCK_TYPE_NUM; i++) {
+		for (j = 0; j < AMD_IP_BLOCK_MAX_INST; j++) {
+			atomic_set(&adev->pm.pwr_state[i][j], POWER_STATE_UNKNOWN);
+		}
+	}
 
 	adev->rmmio = ioremap(adev->rmmio_base, adev->rmmio_size);
 	if (!adev->rmmio)
drivers/gpu/drm/amd/include/amd_shared.h +2 -0
index 6dccee403a3d1..5dee173485c9f 100644
@@ -112,6 +112,8 @@ enum amd_ip_block_type {
 	AMD_IP_BLOCK_TYPE_NUM,
 };
 
+#define AMD_IP_BLOCK_MAX_INST 8
+
 enum amd_clockgating_state {
 	AMD_CG_STATE_GATE = 0,
 	AMD_CG_STATE_UNGATE,
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +10 -6
index 7a22aef6e59c3..d2f1b27d22d4f 100644
@@ -78,12 +78,16 @@ int amdgpu_dpm_set_powergating_by_smu(struct amdgpu_device *adev,
 	int ret = 0;
 	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
 	enum ip_power_state pwr_state = gate ? POWER_STATE_OFF : POWER_STATE_ON;
-	bool is_vcn = block_type == AMD_IP_BLOCK_TYPE_VCN;
 
-	if (atomic_read(&adev->pm.pwr_state[block_type]) == pwr_state &&
-			(!is_vcn || adev->vcn.num_vcn_inst == 1)) {
-		dev_dbg(adev->dev, "IP block%d already in the target %s state!",
-				block_type, gate ? "gate" : "ungate");
+	if (inst >= AMD_IP_BLOCK_MAX_INST) {
+		dev_err(adev->dev, "IP block %d inst %d invalid!",
+			block_type, inst);
+		return -EINVAL;
+	}
+
+	if (atomic_read(&adev->pm.pwr_state[block_type][inst]) == pwr_state) {
+		dev_dbg(adev->dev, "IP block %d inst %d already in the target %s state!",
+			block_type, inst, gate ? "gate" : "ungate");
 		return 0;
 	}
 
@@ -112,7 +116,7 @@ int amdgpu_dpm_set_powergating_by_smu(struct amdgpu_device *adev,
 	}
 
 	if (!ret)
-		atomic_set(&adev->pm.pwr_state[block_type], pwr_state);
+		atomic_set(&adev->pm.pwr_state[block_type][inst], pwr_state);
 
 	mutex_unlock(&adev->pm.mutex);
 
drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h +1 -1
index 1f5ac7e0230d2..cbb110f0cb898 100644
@@ -370,7 +370,7 @@ struct amdgpu_pm {
 	struct i2c_adapter     *fru_eeprom_i2c_bus;
 	struct list_head	pm_attr_list;
 
-	atomic_t		pwr_state[AMD_IP_BLOCK_TYPE_NUM];
+	atomic_t		pwr_state[AMD_IP_BLOCK_TYPE_NUM][AMD_IP_BLOCK_MAX_INST];
 
 	/*
 	 * 0 = disabled (default), otherwise enable corresponding debug mode
Signature · 1 line
2.48.1
#5 lore raw

Re: [PATCH 3/3] drm/amdgpu/pm: store power state per instance

Quoted 93 lines · Alex Deucher

Simplify the driver logic. We support multiple instances now so reflect that in the driver state.

Fixes ff69bba05f08 ("drm/amd/pm: add inst to dpm_set_powergating_by_smu")
Cc Boyuan Zhang <[email protected]>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_device.c |  9 ++++++---
 drivers/gpu/drm/amd/include/amd_shared.h   |  2 ++
 drivers/gpu/drm/amd/pm/amdgpu_dpm.c        | 16 ++++++++++------
 drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h    |  2 +-
 4 files changed, 19 insertions(+), 10 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +6 -3
index 32926458d50ce..7325c21d60fc8 100644
@@ -4184,7 +4184,7 @@ int amdgpu_device_init(struct amdgpu_device *adev,
 {
 	struct drm_device *ddev = adev_to_drm(adev);
 	struct pci_dev *pdev = adev->pdev;
-	int r, i;
+	int r, i, j;
 	bool px = false;
 	u32 max_MBps;
 	int tmp;
@@ -4338,8 +4338,11 @@ int amdgpu_device_init(struct amdgpu_device *adev,
 		adev->rmmio_size = pci_resource_len(adev->pdev, 2);
 	}
 
-	for (i = 0; i < AMD_IP_BLOCK_TYPE_NUM; i++)
-		atomic_set(&adev->pm.pwr_state[i], POWER_STATE_UNKNOWN);
+	for (i = 0; i < AMD_IP_BLOCK_TYPE_NUM; i++) {
+		for (j = 0; j < AMD_IP_BLOCK_MAX_INST; j++) {
+			atomic_set(&adev->pm.pwr_state[i][j], POWER_STATE_UNKNOWN);
+		}
+	}
 
 	adev->rmmio = ioremap(adev->rmmio_base, adev->rmmio_size);
 	if (!adev->rmmio)
drivers/gpu/drm/amd/include/amd_shared.h +2 -0
index 6dccee403a3d1..5dee173485c9f 100644
@@ -112,6 +112,8 @@ enum amd_ip_block_type {
 	AMD_IP_BLOCK_TYPE_NUM,
 };
 
+#define AMD_IP_BLOCK_MAX_INST 8
+
 enum amd_clockgating_state {
 	AMD_CG_STATE_GATE = 0,
 	AMD_CG_STATE_UNGATE,
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +10 -6
index 7a22aef6e59c3..d2f1b27d22d4f 100644
@@ -78,12 +78,16 @@ int amdgpu_dpm_set_powergating_by_smu(struct amdgpu_device *adev,
 	int ret = 0;
 	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
 	enum ip_power_state pwr_state = gate ? POWER_STATE_OFF : POWER_STATE_ON;
-	bool is_vcn = block_type == AMD_IP_BLOCK_TYPE_VCN;
 
-	if (atomic_read(&adev->pm.pwr_state[block_type]) == pwr_state &&
-			(!is_vcn || adev->vcn.num_vcn_inst == 1)) {
-		dev_dbg(adev->dev, "IP block%d already in the target %s state!",
-				block_type, gate ? "gate" : "ungate");
+	if (inst >= AMD_IP_BLOCK_MAX_INST) {
+		dev_err(adev->dev, "IP block %d inst %d invalid!",
+			block_type, inst);
+		return -EINVAL;
+	}
+
+	if (atomic_read(&adev->pm.pwr_state[block_type][inst]) == pwr_state) {
+		dev_dbg(adev->dev, "IP block %d inst %d already in the target %s state!",
+			block_type, inst, gate ? "gate" : "ungate");
 		return 0;
 	}
 
@@ -112,7 +116,7 @@ int amdgpu_dpm_set_powergating_by_smu(struct amdgpu_device *adev,
 	}
 
 	if (!ret)
-		atomic_set(&adev->pm.pwr_state[block_type], pwr_state);
+		atomic_set(&adev->pm.pwr_state[block_type][inst], pwr_state);
 
 	mutex_unlock(&adev->pm.mutex);
 
drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h +0 -0
index 1f5ac7e0230d2..cbb110f0cb898 100644

drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h struct amdgpu_pm { · line 373

Quoted 5 lines
drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h +1 -1
@@ -370,7 +370,7 @@ struct amdgpu_pm {
 	struct i2c_adapter     *fru_eeprom_i2c_bus;
 	struct list_head	pm_attr_list;
 
-	atomic_t		pwr_state[AMD_IP_BLOCK_TYPE_NUM];
+	atomic_t		pwr_state[AMD_IP_BLOCK_TYPE_NUM][AMD_IP_BLOCK_MAX_INST];

If it's getting refactored, it's better to keep this state in IP block than in pm.

Thanks,
Lijo

Quoted 3 lines
drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h +0 -0
 	/*
 	 * 0 = disabled (default), otherwise enable corresponding debug mode
#6 lore raw
In reply to Alex Deucher
Quoted 18 lines · Alex Deucher

The VCN and UVD helpers were split in
commit ff69bba05f08 ("drm/amd/pm: add inst to dpm_set_powergating_by_smu") However, this happened in parallel to the vcn 5.0.1 development so it was missed there.

Fixes 346492f30ce3 ("drm/amdgpu: Add VCN_5_0_1 support")
Cc Sonny Jiang <[email protected]>
Cc Boyuan Zhang <[email protected]>
---
 drivers/gpu/drm/amd/amdgpu/vcn_v5_0_1.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)
drivers/gpu/drm/amd/amdgpu/vcn_v5_0_1.c +0 -0
index 8b463c977d08f..8b0b3739a5377 100644

drivers/gpu/drm/amd/amdgpu/vcn_v5_0_1.c static int vcn_v5_0_1_start(struct amdgpu_device *adev) · line 582

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/vcn_v5_0_1.c +4 -2
@@ -575,8 +575,10 @@ static int vcn_v5_0_1_start(struct amdgpu_device *adev)
 	uint32_t tmp;
 	int i, j, k, r, vcn_inst;
 
-	if (adev->pm.dpm_enabled)
-		amdgpu_dpm_enable_uvd(adev, true);
+	for (i = 0; i < adev->vcn.num_vcn_inst; ++i) {
+		if (adev->pm.dpm_enabled)
+			amdgpu_dpm_enable_vcn(adev, true, i);
+	}
 

This whole enable/disable vcn power gating can be dropped. This is not supported for vcn 5.0.1.

Thanks,
Lijo

Quoted 15 lines
drivers/gpu/drm/amd/amdgpu/vcn_v5_0_1.c +4 -2
 	for (i = 0; i < adev->vcn.num_vcn_inst; ++i) {
 		fw_shared = adev->vcn.inst[i].fw_shared.cpu_addr;
@@ -816,8 +818,10 @@ static int vcn_v5_0_1_stop(struct amdgpu_device *adev)
 		WREG32_SOC15(VCN, vcn_inst, regUVD_STATUS, 0);
 	}
 
-	if (adev->pm.dpm_enabled)
-		amdgpu_dpm_enable_uvd(adev, false);
+	for (i = 0; i < adev->vcn.num_vcn_inst; ++i) {
+		if (adev->pm.dpm_enabled)
+			amdgpu_dpm_enable_vcn(adev, false, i);
+	}
 
 	return 0;
 }