Skip to contentSkip to conversation

drm/amdgpu/vpe: fix vpe dpm clk ratio setup failed

PATCH In review Peyton Lee 3 participants 3 messages Apr 29, 2024 – Apr 30, 2024

Subsystems (2)
lore
Share & tools
lore

Peyton Lee

author
#0 lore raw

PATCH 1/1 drm/amdgpu/vpe: fix vpe dpm clk ratio setup failed

Some version of BIOS does not enable all clock levels, resulting in high level clock frequency of 0. The number of valid CLKs must be confirmed in advance.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_vpe.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_vpe.c +11 -2
index c23d97d34b7e..49881073ff58 100644
@@ -128,6 +128,7 @@ int amdgpu_vpe_configure_dpm(struct amdgpu_vpe *vpe)
 		struct dpm_clock *VPEClks;
 		struct dpm_clock *SOCClks;
 		uint32_t idx;
+		uint32_t vpeclk_enalbled_num = 0;
 		uint32_t pratio_vmax_vnorm = 0, pratio_vnorm_vmid = 0, pratio_vmid_vmin = 0;
 		uint16_t pratio_vmin_freq = 0, pratio_vmid_freq = 0, pratio_vnorm_freq = 0, pratio_vmax_freq = 0;
 
@@ -144,6 +145,14 @@ int amdgpu_vpe_configure_dpm(struct amdgpu_vpe *vpe)
 		SOCClks = clock_table.SocClocks;
 		VPEClks = clock_table.VPEClocks;
 
+		/* Comfirm enabled vpe clk num
+		 * Enabled VPE clocks are ordered from low to high in VPEClks
+		 * The highest valid clock index+1 is the number of VPEClks
+		 */
+		for (idx = PP_SMU_NUM_VPECLK_DPM_LEVELS; idx && !vpeclk_enalbled_num; idx--)
+			if (VPEClks[idx-1].Freq)
+				vpeclk_enalbled_num = idx;
+
 		/* vpe dpm only cares 4 levels. */
 		for (idx = 0; idx < VPE_MAX_DPM_LEVEL; idx++) {
 			uint32_t soc_dpm_level;
@@ -155,8 +164,8 @@ int amdgpu_vpe_configure_dpm(struct amdgpu_vpe *vpe)
 				soc_dpm_level = (idx * 2) + 1;
 
 			/* clamp the max level */
-			if (soc_dpm_level > PP_SMU_NUM_VPECLK_DPM_LEVELS - 1)
-				soc_dpm_level = PP_SMU_NUM_VPECLK_DPM_LEVELS - 1;
+			if (soc_dpm_level > vpeclk_enalbled_num - 1)
+				soc_dpm_level = vpeclk_enalbled_num - 1;
 
 			min_freq = (SOCClks[soc_dpm_level].Freq < VPEClks[soc_dpm_level].Freq) ?
 				   SOCClks[soc_dpm_level].Freq : VPEClks[soc_dpm_level].Freq;
Signature · 1 line
2.34.1
Acked-by on v1 1/1
#1 lore raw
Quoted 6 lines · Peyton Lee

Some version of BIOS does not enable all clock levels, resulting in high level clock frequency of 0. The number of valid CLKs must be confirmed in advance.

Quoted 45 lines
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_vpe.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_vpe.c +11 -3
index c23d97d34b7e..49881073ff58 100644
@@ -128,6 +128,7 @@ int amdgpu_vpe_configure_dpm(struct amdgpu_vpe *vpe)
                struct dpm_clock *VPEClks;
                struct dpm_clock *SOCClks;
                uint32_t idx;
+               uint32_t vpeclk_enalbled_num = 0;
                uint32_t pratio_vmax_vnorm = 0, pratio_vnorm_vmid = 0, pratio_vmid_vmin = 0;
                uint16_t pratio_vmin_freq = 0, pratio_vmid_freq = 0, pratio_vnorm_freq = 0, pratio_vmax_freq = 0;
 
@@ -144,6 +145,14 @@ int amdgpu_vpe_configure_dpm(struct amdgpu_vpe *vpe)
                SOCClks = clock_table.SocClocks;
                VPEClks = clock_table.VPEClocks;
 
+               /* Comfirm enabled vpe clk num
+                * Enabled VPE clocks are ordered from low to high in VPEClks
+                * The highest valid clock index+1 is the number of VPEClks
+                */
+               for (idx = PP_SMU_NUM_VPECLK_DPM_LEVELS; idx && !vpeclk_enalbled_num; idx--)
+                       if (VPEClks[idx-1].Freq)
+                               vpeclk_enalbled_num = idx;
+
                /* vpe dpm only cares 4 levels. */
                for (idx = 0; idx < VPE_MAX_DPM_LEVEL; idx++) {
                        uint32_t soc_dpm_level;
@@ -155,8 +164,8 @@ int amdgpu_vpe_configure_dpm(struct amdgpu_vpe *vpe)
                                soc_dpm_level = (idx * 2) + 1;
 
                        /* clamp the max level */
-                       if (soc_dpm_level > PP_SMU_NUM_VPECLK_DPM_LEVELS - 1)
-                               soc_dpm_level = PP_SMU_NUM_VPECLK_DPM_LEVELS - 1;
+                       if (soc_dpm_level > vpeclk_enalbled_num - 1)
+                               soc_dpm_level = vpeclk_enalbled_num - 1;
 
                        min_freq = (SOCClks[soc_dpm_level].Freq < VPEClks[soc_dpm_level].Freq) ?
                                   SOCClks[soc_dpm_level].Freq : VPEClks[soc_dpm_level].Freq;
--

2.34.1

Reviewed-by on v1 1/1
#2 lore raw
In reply to Peyton Lee

[Public]

Quoted 67 lines

-----Original Message-----
From: Lee, Peyton <[email protected]>
Sent: Monday, April 29, 2024 2:53 PM
To: [email protected]
Cc: Deucher, Alexander <[email protected]>; Yu, Lang <[email protected]>; Liu, HaoPing (Alan) <[email protected]>; Lee, Peyton <[email protected]>
Subject: [PATCH] drm/amdgpu/vpe: fix vpe dpm clk ratio setup failed

Some version of BIOS does not enable all clock levels, resulting in high level clock frequency of 0.
The number of valid CLKs must be confirmed in advance.

---
drivers/gpu/drm/amd/amdgpu/amdgpu_vpe.c | 13 +++++++++++--

1 file changed, 11 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_vpe.c +1 -0
index c23d97d34b7e..49881073ff58 100644
@@ -128,6 +128,7 @@ int amdgpu_vpe_configure_dpm(struct amdgpu_vpe *vpe)
              struct dpm_clock *VPEClks;
              struct dpm_clock *SOCClks;
              uint32_t idx;
+              uint32_t vpeclk_enalbled_num = 0;
              uint32_t pratio_vmax_vnorm = 0, pratio_vnorm_vmid = 0,
 pratio_vmid_vmin = 0;
              uint16_t pratio_vmin_freq = 0, pratio_vmid_freq = 0,

pratio_vnorm_freq = 0, pratio_vmax_freq = 0;

drivers/gpu/drm/amd/amdgpu/amdgpu_vpe.c +8 -0
@@ -144,6 +145,14 @@ int amdgpu_vpe_configure_dpm(struct amdgpu_vpe
 *vpe)
              SOCClks = clock_table.SocClocks;
              VPEClks = clock_table.VPEClocks;
 
+              /* Comfirm enabled vpe clk num
+               * Enabled VPE clocks are ordered from low to high in VPEClks
+               * The highest valid clock index+1 is the number of VPEClks
+               */
+              for (idx = PP_SMU_NUM_VPECLK_DPM_LEVELS; idx
 && !vpeclk_enalbled_num; idx--)
+                      if (VPEClks[idx-1].Freq)
+                              vpeclk_enalbled_num = idx;
+
              /* vpe dpm only cares 4 levels. */
              for (idx = 0; idx < VPE_MAX_DPM_LEVEL; idx++) {
                      uint32_t soc_dpm_level;
drivers/gpu/drm/amd/amdgpu/amdgpu_vpe.c +2 -2
@@ -155,8 +164,8 @@ int amdgpu_vpe_configure_dpm(struct amdgpu_vpe *vpe)
                              soc_dpm_level = (idx * 2) + 1;
 
                      /* clamp the max level */
-                      if (soc_dpm_level >
 PP_SMU_NUM_VPECLK_DPM_LEVELS - 1)
-                              soc_dpm_level =
 PP_SMU_NUM_VPECLK_DPM_LEVELS - 1;
+                      if (soc_dpm_level > vpeclk_enalbled_num - 1)
+                              soc_dpm_level = vpeclk_enalbled_num - 1;
 

min_freq = (SOCClks[soc_dpm_level].Freq <
VPEClks[soc_dpm_level].Freq) ?
SOCClks[soc_dpm_level].Freq :
VPEClks[soc_dpm_level].Freq;
--
2.34.1