<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<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:11pt;color:#0078D7;margin:5pt;" align="Left">
[AMD Official Use Only - Internal Distribution Only]<br>
</p>
<br>
<div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<hr tabindex="-1" style="display:inline-block; width:98%">
<div id="divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" color="#000000" style="font-size:11pt"><b>From:</b> amd-gfx <amd-gfx-bounces@lists.freedesktop.org> on behalf of Darren Powell <darren.powell@amd.com><br>
<b>Sent:</b> Saturday, December 19, 2020 8:48 AM<br>
<b>To:</b> amd-gfx@lists.freedesktop.org <amd-gfx@lists.freedesktop.org><br>
<b>Cc:</b> Powell, Darren <Darren.Powell@amd.com><br>
<b>Subject:</b> [PATCH 3/8] amdgpu/pm: Powerplay API for smu , changed 6 pm hwmon fan functions to use API</font>
<div> </div>
</div>
<div class="BodyFragment"><font size="2"><span style="font-size:11pt">
<div class="PlainText">Modified Functions<br>
  smu_set_fan_speed_rpm()     - modifed arg0 to match Powerplay API set_fan_speed_rpm<br>
  smu_get_fan_control_mode()  - modifed signature to match Powerplay API get_fan_control_mode<br>
  smu_set_fan_control_mode()  - modifed signature to match Powerplay API set_fan_control_mode<br>
  smu_get_fan_speed_percent() - modifed signature to match Powerplay API get_fan_speed_percent<br>
  smu_set_fan_speed_percent() - modifed signature to match Powerplay API set_fan_speed_percent<br>
  smu_get_fan_speed_rpm()     - modifed arg0 to match Powerplay API get_fan_speed_rpm<br>
<br>
Other Changes<br>
  added 6 above smu fan Powerplay functions to swsmu_dpm_funcs<br>
  removed special smu handling of above functions and called through Powerplay API<br>
<br>
Signed-off-by: Darren Powell <darren.powell@amd.com><br>
---<br>
 drivers/gpu/drm/amd/pm/amdgpu_pm.c        | 87 +++++++----------------<br>
 drivers/gpu/drm/amd/pm/inc/amdgpu_smu.h   | 12 ++--<br>
 drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c | 33 ++++++---<br>
 3 files changed, 55 insertions(+), 77 deletions(-)<br>
<br>
diff --git a/drivers/gpu/drm/amd/pm/amdgpu_pm.c b/drivers/gpu/drm/amd/pm/amdgpu_pm.c<br>
index 0008bbe971d6..b345c29147b9 100644<br>
--- a/drivers/gpu/drm/amd/pm/amdgpu_pm.c<br>
+++ b/drivers/gpu/drm/amd/pm/amdgpu_pm.c<br>
@@ -2349,18 +2349,14 @@ static ssize_t amdgpu_hwmon_get_pwm1_enable(struct device *dev,<br>
                 return ret;<br>
         }<br>
 <br>
-       if (is_support_sw_smu(adev)) {<br>
-               pwm_mode = smu_get_fan_control_mode(&adev->smu);<br>
-       } else {<br>
-               if (!adev->powerplay.pp_funcs->get_fan_control_mode) {<br>
+       if (!adev->powerplay.pp_funcs->get_fan_control_mode) {<br>
                         pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);<br>
                         pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);<br>
                         return -EINVAL;<br>
-               }<br>
-<br>
-               pwm_mode = amdgpu_dpm_get_fan_control_mode(adev);<br>
         }<br>
 <br>
+       pwm_mode = amdgpu_dpm_get_fan_control_mode(adev);<br>
+<br>
         pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);<br>
         pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);<br>
 <br>
@@ -2389,18 +2385,14 @@ static ssize_t amdgpu_hwmon_set_pwm1_enable(struct device *dev,<br>
                 return ret;<br>
         }<br>
 <br>
-       if (is_support_sw_smu(adev)) {<br>
-               smu_set_fan_control_mode(&adev->smu, value);<br>
-       } else {<br>
-               if (!adev->powerplay.pp_funcs->set_fan_control_mode) {<br>
-                       pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);<br>
-                       pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);<br>
-                       return -EINVAL;<br>
-               }<br>
-<br>
-               amdgpu_dpm_set_fan_control_mode(adev, value);<br>
+       if (!adev->powerplay.pp_funcs->set_fan_control_mode) {<br>
+               pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);<br>
+               pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);<br>
+               return -EINVAL;<br>
         }<br>
 <br>
+       amdgpu_dpm_set_fan_control_mode(adev, value);<br>
+<br>
         pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);<br>
         pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);<br>
 <br>
@@ -2439,11 +2431,7 @@ static ssize_t amdgpu_hwmon_set_pwm1(struct device *dev,<br>
                 return err;<br>
         }<br>
 <br>
-       if (is_support_sw_smu(adev))<br>
-               pwm_mode = smu_get_fan_control_mode(&adev->smu);<br>
-       else<br>
-               pwm_mode = amdgpu_dpm_get_fan_control_mode(adev);<br>
-<br>
+       pwm_mode = amdgpu_dpm_get_fan_control_mode(adev);<br>
         if (pwm_mode != AMD_FAN_CTRL_MANUAL) {<br>
                 pr_info("manual fan speed control should be enabled first\n");<br>
                 pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);<br>
@@ -2460,9 +2448,7 @@ static ssize_t amdgpu_hwmon_set_pwm1(struct device *dev,<br>
 <br>
         value = (value * 100) / 255;<br>
 <br>
-       if (is_support_sw_smu(adev))<br>
-               err = smu_set_fan_speed_percent(&adev->smu, value);<br>
-       else if (adev->powerplay.pp_funcs->set_fan_speed_percent)<br>
+       if (adev->powerplay.pp_funcs->set_fan_speed_percent)<br>
                 err = amdgpu_dpm_set_fan_speed_percent(adev, value);<br>
         else<br>
                 err = -EINVAL;<br>
@@ -2493,9 +2479,7 @@ static ssize_t amdgpu_hwmon_get_pwm1(struct device *dev,<br>
                 return err;<br>
         }<br>
 <br>
-       if (is_support_sw_smu(adev))<br>
-               err = smu_get_fan_speed_percent(&adev->smu, &speed);<br>
-       else if (adev->powerplay.pp_funcs->get_fan_speed_percent)<br>
+       if (adev->powerplay.pp_funcs->get_fan_speed_percent)<br>
                 err = amdgpu_dpm_get_fan_speed_percent(adev, &speed);<br>
         else<br>
                 err = -EINVAL;<br>
@@ -2528,9 +2512,7 @@ static ssize_t amdgpu_hwmon_get_fan1_input(struct device *dev,<br>
                 return err;<br>
         }<br>
 <br>
-       if (is_support_sw_smu(adev))<br>
-               err = smu_get_fan_speed_rpm(&adev->smu, &speed);<br>
-       else if (adev->powerplay.pp_funcs->get_fan_speed_rpm)<br>
+       if (adev->powerplay.pp_funcs->get_fan_speed_rpm)<br>
                 err = amdgpu_dpm_get_fan_speed_rpm(adev, &speed);<br>
         else<br>
                 err = -EINVAL;<br>
@@ -2621,9 +2603,7 @@ static ssize_t amdgpu_hwmon_get_fan1_target(struct device *dev,<br>
                 return err;<br>
         }<br>
 <br>
-       if (is_support_sw_smu(adev))<br>
-               err = smu_get_fan_speed_rpm(&adev->smu, &rpm);<br>
-       else if (adev->powerplay.pp_funcs->get_fan_speed_rpm)<br>
+       if (adev->powerplay.pp_funcs->get_fan_speed_rpm)<br>
                 err = amdgpu_dpm_get_fan_speed_rpm(adev, &rpm);<br>
         else<br>
                 err = -EINVAL;<br>
@@ -2655,10 +2635,7 @@ static ssize_t amdgpu_hwmon_set_fan1_target(struct device *dev,<br>
                 return err;<br>
         }<br>
 <br>
-       if (is_support_sw_smu(adev))<br>
-               pwm_mode = smu_get_fan_control_mode(&adev->smu);<br>
-       else<br>
-               pwm_mode = amdgpu_dpm_get_fan_control_mode(adev);<br>
+       pwm_mode = amdgpu_dpm_get_fan_control_mode(adev);<br>
 <br>
         if (pwm_mode != AMD_FAN_CTRL_MANUAL) {<br>
                 pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);<br>
@@ -2673,9 +2650,7 @@ static ssize_t amdgpu_hwmon_set_fan1_target(struct device *dev,<br>
                 return err;<br>
         }<br>
 <br>
-       if (is_support_sw_smu(adev))<br>
-               err = smu_set_fan_speed_rpm(&adev->smu, value);<br>
-       else if (adev->powerplay.pp_funcs->set_fan_speed_rpm)<br>
+       if (adev->powerplay.pp_funcs->set_fan_speed_rpm)<br>
                 err = amdgpu_dpm_set_fan_speed_rpm(adev, value);<br>
         else<br>
                 err = -EINVAL;<br>
@@ -2706,18 +2681,14 @@ static ssize_t amdgpu_hwmon_get_fan1_enable(struct device *dev,<br>
                 return ret;<br>
         }<br>
 <br>
-       if (is_support_sw_smu(adev)) {<br>
-               pwm_mode = smu_get_fan_control_mode(&adev->smu);<br>
-       } else {<br>
-               if (!adev->powerplay.pp_funcs->get_fan_control_mode) {<br>
-                       pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);<br>
-                       pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);<br>
-                       return -EINVAL;<br>
-               }<br>
-<br>
-               pwm_mode = amdgpu_dpm_get_fan_control_mode(adev);<br>
+       if (!adev->powerplay.pp_funcs->get_fan_control_mode) {<br>
+               pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);<br>
+               pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);<br>
+               return -EINVAL;<br>
         }<br>
 <br>
+       pwm_mode = amdgpu_dpm_get_fan_control_mode(adev);<br>
+<br>
         pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);<br>
         pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);<br>
 <br>
@@ -2754,16 +2725,12 @@ static ssize_t amdgpu_hwmon_set_fan1_enable(struct device *dev,<br>
                 return err;<br>
         }<br>
 <br>
-       if (is_support_sw_smu(adev)) {<br>
-               smu_set_fan_control_mode(&adev->smu, pwm_mode);<br>
-       } else {<br>
-               if (!adev->powerplay.pp_funcs->set_fan_control_mode) {<br>
-                       pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);<br>
-                       pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);<br>
-                       return -EINVAL;<br>
-               }<br>
-               amdgpu_dpm_set_fan_control_mode(adev, pwm_mode);<br>
+       if (!adev->powerplay.pp_funcs->set_fan_control_mode) {<br>
+               pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);<br>
+               pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);<br>
+               return -EINVAL;<br>
         }<br>
+       amdgpu_dpm_set_fan_control_mode(adev, pwm_mode);<br>
 <br>
         pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);<br>
         pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);<br>
diff --git a/drivers/gpu/drm/amd/pm/inc/amdgpu_smu.h b/drivers/gpu/drm/amd/pm/inc/amdgpu_smu.h<br>
index 6713f28c5fde..9f739d1b18d5 100644<br>
--- a/drivers/gpu/drm/amd/pm/inc/amdgpu_smu.h<br>
+++ b/drivers/gpu/drm/amd/pm/inc/amdgpu_smu.h<br>
@@ -657,7 +657,7 @@ int smu_check_fw_status(struct smu_context *smu);<br>
 <br>
 int smu_set_gfx_cgpg(struct smu_context *smu, bool enabled);<br>
 <br>
-int smu_set_fan_speed_rpm(struct smu_context *smu, uint32_t speed);<br>
+int smu_set_fan_speed_rpm(void *handle, uint32_t speed);<br>
 <br>
 int smu_get_power_limit(struct smu_context *smu,<br>
                         uint32_t *limit,<br>
@@ -679,11 +679,11 @@ int smu_set_power_profile_mode(struct smu_context *smu,<br>
                                long *param,<br>
                                uint32_t param_size,<br>
                                bool lock_needed);<br>
-int smu_get_fan_control_mode(struct smu_context *smu);<br>
-int smu_set_fan_control_mode(struct smu_context *smu, int value);<br>
-int smu_get_fan_speed_percent(struct smu_context *smu, uint32_t *speed);<br>
-int smu_set_fan_speed_percent(struct smu_context *smu, uint32_t speed);<br>
-int smu_get_fan_speed_rpm(struct smu_context *smu, uint32_t *speed);<br>
+u32 smu_get_fan_control_mode(void *handle);<br>
+void smu_set_fan_control_mode(void *handle, u32 value);<br>
+int smu_get_fan_speed_percent(void *handle, u32 *speed);<br>
+int smu_set_fan_speed_percent(void *handle, u32 speed);<br>
+int smu_get_fan_speed_rpm(void *handle, uint32_t *speed);<br>
 <br>
 int smu_set_deep_sleep_dcefclk(struct smu_context *smu, int clk);<br>
 <br>
diff --git a/drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c b/drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c<br>
index 5f33439782c4..acde0e831bb8 100644<br>
--- a/drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c<br>
+++ b/drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c<br>
@@ -1896,8 +1896,9 @@ int smu_set_gfx_cgpg(struct smu_context *smu, bool enabled)<br>
         return ret;<br>
 }<br>
 <br>
-int smu_set_fan_speed_rpm(struct smu_context *smu, uint32_t speed)<br>
+int smu_set_fan_speed_rpm(void *handle, uint32_t speed)<br>
 {<br>
+       struct smu_context *smu = handle;<br>
         int ret = 0;<br>
 <br>
         if (!smu->pm_enabled || !smu->adev->pm.dpm_enabled)<br>
@@ -2100,9 +2101,10 @@ int smu_set_power_profile_mode(struct smu_context *smu,<br>
 }<br>
 <br>
 <br>
-int smu_get_fan_control_mode(struct smu_context *smu)<br>
+u32 smu_get_fan_control_mode(void *handle)<br>
 {<br>
-       int ret = 0;<br>
+       struct smu_context *smu = handle;<br>
+       u32 ret = 0;<br>
 <br>
         if (!smu->pm_enabled || !smu->adev->pm.dpm_enabled)<br>
                 return -EOPNOTSUPP;</div>
<div class="PlainText">[kevin]:</div>
<div class="PlainText">after change function return type to 'u32", the return value of  '-EOPNOTSUPP' maybe not work.</div>
<div class="PlainText">other patches have the same problems.</div>
<div class="PlainText"><br>
</div>
<div class="PlainText">@@ -2117,25 +2119,26 @@ int smu_get_fan_control_mode(struct smu_context *smu)<br>
         return ret;<br>
 }<br>
 <br>
-int smu_set_fan_control_mode(struct smu_context *smu, int value)<br>
+void smu_set_fan_control_mode(void *handle, u32 value)<br>
 {<br>
-       int ret = 0;<br>
+       struct smu_context *smu = handle;<br>
 <br>
         if (!smu->pm_enabled || !smu->adev->pm.dpm_enabled)<br>
-               return -EOPNOTSUPP;<br>
+               return;<br>
 <br>
         mutex_lock(&smu->mutex);<br>
 <br>
         if (smu->ppt_funcs->set_fan_control_mode)<br>
-               ret = smu->ppt_funcs->set_fan_control_mode(smu, value);<br>
+               smu->ppt_funcs->set_fan_control_mode(smu, value);<br>
 <br>
         mutex_unlock(&smu->mutex);<br>
 <br>
-       return ret;<br>
+       return;<br>
 }<br>
 <br>
-int smu_get_fan_speed_percent(struct smu_context *smu, uint32_t *speed)<br>
+int smu_get_fan_speed_percent(void *handle, u32 *speed)<br>
 {<br>
+       struct smu_context *smu = handle;<br>
         int ret = 0;<br>
         uint32_t percent;<br>
         uint32_t current_rpm;<br>
@@ -2159,8 +2162,9 @@ int smu_get_fan_speed_percent(struct smu_context *smu, uint32_t *speed)<br>
         return ret;<br>
 }<br>
 <br>
-int smu_set_fan_speed_percent(struct smu_context *smu, uint32_t speed)<br>
+int smu_set_fan_speed_percent(void *handle, u32 speed)<br>
 {<br>
+       struct smu_context *smu = handle;<br>
         int ret = 0;<br>
         uint32_t rpm;<br>
 <br>
@@ -2181,8 +2185,9 @@ int smu_set_fan_speed_percent(struct smu_context *smu, uint32_t speed)<br>
         return ret;<br>
 }<br>
 <br>
-int smu_get_fan_speed_rpm(struct smu_context *smu, uint32_t *speed)<br>
+int smu_get_fan_speed_rpm(void *handle, uint32_t *speed)<br>
 {<br>
+       struct smu_context *smu = handle;<br>
         int ret = 0;<br>
 <br>
         if (!smu->pm_enabled || !smu->adev->pm.dpm_enabled)<br>
@@ -2564,7 +2569,13 @@ int smu_gfx_state_change_set(struct smu_context *smu, uint32_t state)<br>
 <br>
 static const struct amd_pm_funcs swsmu_dpm_funcs = {<br>
         /* export for sysfs */<br>
+       .set_fan_control_mode  = smu_set_fan_control_mode,<br>
+       .get_fan_control_mode  = smu_get_fan_control_mode,<br>
+       .set_fan_speed_percent = smu_set_fan_speed_percent,<br>
+       .get_fan_speed_percent = smu_get_fan_speed_percent,<br>
         .get_performance_level = smu_get_performance_level,<br>
+       .get_fan_speed_rpm     = smu_get_fan_speed_rpm,<br>
+       .set_fan_speed_rpm     = smu_set_fan_speed_rpm,<br>
         .switch_power_profile  = smu_switch_power_profile,<br>
         /* export to amdgpu */<br>
         .set_mp1_state         = smu_set_mp1_state,<br>
-- <br>
2.25.1<br>
<br>
_______________________________________________<br>
amd-gfx mailing list<br>
amd-gfx@lists.freedesktop.org<br>
<a href="https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.freedesktop.org%2Fmailman%2Flistinfo%2Famd-gfx&amp;data=04%7C01%7CKevin1.Wang%40amd.com%7C5e2363bd852d4f676cfe08d8a3b7e638%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637439357534767356%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&amp;sdata=ncJ6EcwqNogU9oiPX%2BbA99o%2FST67HR3r7e4cMiKZiY8%3D&amp;reserved=0">https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.freedesktop.org%2Fmailman%2Flistinfo%2Famd-gfx&amp;data=04%7C01%7CKevin1.Wang%40amd.com%7C5e2363bd852d4f676cfe08d8a3b7e638%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637439357534767356%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&amp;sdata=ncJ6EcwqNogU9oiPX%2BbA99o%2FST67HR3r7e4cMiKZiY8%3D&amp;reserved=0</a><br>
</div>
</span></font></div>
</div>
</body>
</html>