<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<style type="text/css" style="display:none;"> P {margin-top:0;margin-bottom:0;} </style>
</head>
<body dir="ltr">
<p style="font-family:Arial;font-size:10pt;color:#317100;margin:15pt;" align="Left">
[AMD Public Use]<br>
</p>
<br>
<div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Series is:</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Reviewed-by: Alex Deucher <alexander.deucher@amd.com><br>
</div>
<div id="appendonsend"></div>
<hr style="display:inline-block;width:98%" tabindex="-1">
<div id="divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" style="font-size:11pt" color="#000000"><b>From:</b> Jivin, Alex <Alex.Jivin@amd.com><br>
<b>Sent:</b> Wednesday, June 24, 2020 4:31 PM<br>
<b>To:</b> amd-gfx@lists.freedesktop.org <amd-gfx@lists.freedesktop.org><br>
<b>Cc:</b> Deucher, Alexander <Alexander.Deucher@amd.com><br>
<b>Subject:</b> [PATCH 3/3] drm/amdgpu: SI support for UVD and VCE power managment</font>
<div> </div>
</div>
<div class="BodyFragment"><font size="2"><span style="font-size:11pt;">
<div class="PlainText">Port functionality from the Radeon driver to support<br>
UVD and VCE power management.<br>
<br>
Signed-off-by: Alex Jivin <alex.jivin@amd.com><br>
---<br>
 drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c | 67 +++++++++++++++++++-------<br>
 drivers/gpu/drm/amd/amdgpu/si_dpm.c    | 19 ++++++++<br>
 2 files changed, 68 insertions(+), 18 deletions(-)<br>
<br>
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c<br>
index 347b06d3c140..26c8e39a78bd 100644<br>
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c<br>
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c<br>
@@ -3558,21 +3558,36 @@ void amdgpu_dpm_enable_uvd(struct amdgpu_device *adev, bool enable)<br>
 {<br>
         int ret = 0;<br>
 <br>
-       ret = amdgpu_dpm_set_powergating_by_smu(adev, AMD_IP_BLOCK_TYPE_UVD, !enable);<br>
-       if (ret)<br>
-               DRM_ERROR("Dpm %s uvd failed, ret = %d. \n",<br>
-                         enable ? "enable" : "disable", ret);<br>
-<br>
-       /* enable/disable Low Memory PState for UVD (4k videos) */<br>
-       if (adev->asic_type == CHIP_STONEY &&<br>
-               adev->uvd.decode_image_width >= WIDTH_4K) {<br>
-               struct pp_hwmgr *hwmgr = adev->powerplay.pp_handle;<br>
+       if (adev->family == AMDGPU_FAMILY_SI) {<br>
+               if (enable) {<br>
+                       mutex_lock(&adev->pm.mutex);<br>
+                       adev->pm.dpm.uvd_active = true;<br>
+                       adev->pm.dpm.state = POWER_STATE_TYPE_INTERNAL_UVD;<br>
+                       mutex_unlock(&adev->pm.mutex);<br>
+               } else {<br>
+                       mutex_lock(&adev->pm.mutex);<br>
+                       adev->pm.dpm.uvd_active = false;<br>
+                       mutex_unlock(&adev->pm.mutex);<br>
+               }<br>
 <br>
-               if (hwmgr && hwmgr->hwmgr_func &&<br>
-                   hwmgr->hwmgr_func->update_nbdpm_pstate)<br>
-                       hwmgr->hwmgr_func->update_nbdpm_pstate(hwmgr,<br>
-                                                              !enable,<br>
-                                                              true);<br>
+               amdgpu_pm_compute_clocks(adev);<br>
+       } else {<br>
+               ret = amdgpu_dpm_set_powergating_by_smu(adev, AMD_IP_BLOCK_TYPE_UVD, !enable);<br>
+               if (ret)<br>
+                       DRM_ERROR("Dpm %s uvd failed, ret = %d. \n",<br>
+                                 enable ? "enable" : "disable", ret);<br>
+<br>
+               /* enable/disable Low Memory PState for UVD (4k videos) */<br>
+               if (adev->asic_type == CHIP_STONEY &&<br>
+                       adev->uvd.decode_image_width >= WIDTH_4K) {<br>
+                       struct pp_hwmgr *hwmgr = adev->powerplay.pp_handle;<br>
+<br>
+                       if (hwmgr && hwmgr->hwmgr_func &&<br>
+                           hwmgr->hwmgr_func->update_nbdpm_pstate)<br>
+                               hwmgr->hwmgr_func->update_nbdpm_pstate(hwmgr,<br>
+                                                                      !enable,<br>
+                                                                      true);<br>
+               }<br>
         }<br>
 }<br>
 <br>
@@ -3580,10 +3595,26 @@ void amdgpu_dpm_enable_vce(struct amdgpu_device *adev, bool enable)<br>
 {<br>
         int ret = 0;<br>
 <br>
-       ret = amdgpu_dpm_set_powergating_by_smu(adev, AMD_IP_BLOCK_TYPE_VCE, !enable);<br>
-       if (ret)<br>
-               DRM_ERROR("Dpm %s vce failed, ret = %d. \n",<br>
-                         enable ? "enable" : "disable", ret);<br>
+       if (adev->family == AMDGPU_FAMILY_SI) {<br>
+               if (enable) {<br>
+                       mutex_lock(&adev->pm.mutex);<br>
+                       adev->pm.dpm.vce_active = true;<br>
+                       /* XXX select vce level based on ring/task */<br>
+                       adev->pm.dpm.vce_level = AMD_VCE_LEVEL_AC_ALL;<br>
+                       mutex_unlock(&adev->pm.mutex);<br>
+               } else {<br>
+                       mutex_lock(&adev->pm.mutex);<br>
+                       adev->pm.dpm.vce_active = false;<br>
+                       mutex_unlock(&adev->pm.mutex);<br>
+               }<br>
+<br>
+               amdgpu_pm_compute_clocks(adev);<br>
+       } else {<br>
+               ret = amdgpu_dpm_set_powergating_by_smu(adev, AMD_IP_BLOCK_TYPE_VCE, !enable);<br>
+               if (ret)<br>
+                       DRM_ERROR("Dpm %s vce failed, ret = %d. \n",<br>
+                                 enable ? "enable" : "disable", ret);<br>
+       }<br>
 }<br>
 <br>
 void amdgpu_pm_print_power_states(struct amdgpu_device *adev)<br>
diff --git a/drivers/gpu/drm/amd/amdgpu/si_dpm.c b/drivers/gpu/drm/amd/amdgpu/si_dpm.c<br>
index c00ba4b23c9a..ea914b256ebd 100644<br>
--- a/drivers/gpu/drm/amd/amdgpu/si_dpm.c<br>
+++ b/drivers/gpu/drm/amd/amdgpu/si_dpm.c<br>
@@ -6953,6 +6953,24 @@ static int si_power_control_set_level(struct amdgpu_device *adev)<br>
         return 0;<br>
 }<br>
 <br>
+static void si_set_vce_clock(struct amdgpu_device *adev,<br>
+                            struct amdgpu_ps *new_rps,<br>
+                            struct amdgpu_ps *old_rps)<br>
+{<br>
+       if ((old_rps->evclk != new_rps->evclk) ||<br>
+           (old_rps->ecclk != new_rps->ecclk)) {<br>
+               /* Turn the clocks on when encoding, off otherwise */<br>
+               if (new_rps->evclk || new_rps->ecclk) {<br>
+                       /* Place holder for future VCE1.0 porting to amdgpu<br>
+                       vce_v1_0_enable_mgcg(adev, false, false);*/<br>
+               } else {<br>
+                       /* Place holder for future VCE1.0 porting to amdgpu<br>
+                       vce_v1_0_enable_mgcg(adev, true, false);<br>
+                       amdgpu_asic_set_vce_clocks(adev, new_rps->evclk, new_rps->ecclk);*/<br>
+               }<br>
+       }<br>
+}<br>
+<br>
 static int si_dpm_set_power_state(void *handle)<br>
 {<br>
         struct amdgpu_device *adev = (struct amdgpu_device *)handle;<br>
@@ -7029,6 +7047,7 @@ static int si_dpm_set_power_state(void *handle)<br>
                 return ret;<br>
         }<br>
         ni_set_uvd_clock_after_set_eng_clock(adev, new_ps, old_ps);<br>
+       si_set_vce_clock(adev, new_ps, old_ps);<br>
         if (eg_pi->pcie_performance_request)<br>
                 si_notify_link_speed_change_after_state_change(adev, new_ps, old_ps);<br>
         ret = si_set_power_state_conditionally_enable_ulv(adev, new_ps);<br>
-- <br>
2.17.1<br>
<br>
</div>
</span></font></div>
</div>
</body>
</html>