<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">
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Ah, yeah, missed that. It was wrong before as well. I'll send a follow up patch to fix that up.</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Alex</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<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> Quan, Evan <Evan.Quan@amd.com><br>
<b>Sent:</b> Monday, January 13, 2020 8:27 PM<br>
<b>To:</b> Alex Deucher <alexdeucher@gmail.com><br>
<b>Cc:</b> amd-gfx@lists.freedesktop.org <amd-gfx@lists.freedesktop.org>; Deucher, Alexander <Alexander.Deucher@amd.com><br>
<b>Subject:</b> RE: [PATCH 1/2] drm/amdgpu/pm: properly handle runtime pm</font>
<div> </div>
</div>
<div class="BodyFragment"><font size="2"><span style="font-size:11pt;">
<div class="PlainText">Yes, 'ssize_t' is fine. But 'count' comes with type of 'size_t'.<br>
Although it should not bring any true problem. I'm not sure whether there will be compile warnings.<br>
<br>
Regards,<br>
Evan<br>
> -----Original Message-----<br>
> From: Alex Deucher <alexdeucher@gmail.com><br>
> Sent: Tuesday, January 14, 2020 4:27 AM<br>
> To: Quan, Evan <Evan.Quan@amd.com><br>
> Cc: amd-gfx@lists.freedesktop.org; Deucher, Alexander<br>
> <Alexander.Deucher@amd.com><br>
> Subject: Re: [PATCH 1/2] drm/amdgpu/pm: properly handle runtime pm<br>
> <br>
> On Sun, Jan 12, 2020 at 10:35 PM Quan, Evan <Evan.Quan@amd.com> wrote:<br>
> ><br>
> > The "count" from amdgpu_set_pp_feature_status() seems with type of size_t.<br>
> > Then assignment "count = -EINVAL" may be improper.<br>
> <br>
> It's fine. ssize_t is signed. We've been doing it long before this patch.<br>
> <br>
> Alex<br>
> <br>
> > With that confirmed, the patch is reviewed-by: Evan Quan<br>
> <evan.quan@amd.com><br>
> ><br>
> > > -----Original Message-----<br>
> > > From: amd-gfx <amd-gfx-bounces@lists.freedesktop.org> On Behalf Of Alex<br>
> > > Deucher<br>
> > > Sent: Saturday, January 11, 2020 7:45 AM<br>
> > > To: amd-gfx@lists.freedesktop.org<br>
> > > Cc: Deucher, Alexander <Alexander.Deucher@amd.com><br>
> > > Subject: [PATCH 1/2] drm/amdgpu/pm: properly handle runtime pm<br>
> > ><br>
> > > If power management sysfs or debugfs files are accessed, power up the<br>
> GPU<br>
> > > when necessary.<br>
> > ><br>
> > > Signed-off-by: Alex Deucher <alexander.deucher@amd.com><br>
> > > ---<br>
> > > drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c | 822<br>
> ++++++++++++++++++-----<br>
> > > --<br>
> > > 1 file changed, 614 insertions(+), 208 deletions(-)<br>
> > ><br>
> > > diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c<br>
> > > b/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c<br>
> > > index 285d460624c8..806e731c1ff4 100644<br>
> > > --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c<br>
> > > +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c<br>
> > > @@ -37,6 +37,7 @@<br>
> > > #include <linux/hwmon.h><br>
> > > #include <linux/hwmon-sysfs.h><br>
> > > #include <linux/nospec.h><br>
> > > +#include <linux/pm_runtime.h><br>
> > > #include "hwmgr.h"<br>
> > > #define WIDTH_4K 3840<br>
> > ><br>
> > > @@ -158,10 +159,15 @@ static ssize_t amdgpu_get_dpm_state(struct<br>
> device<br>
> > > *dev,<br>
> > > struct drm_device *ddev = dev_get_drvdata(dev);<br>
> > > struct amdgpu_device *adev = ddev->dev_private;<br>
> > > enum amd_pm_state_type pm;<br>
> > > + int ret;<br>
> > ><br>
> > > if (amdgpu_sriov_vf(adev) && !amdgpu_sriov_is_pp_one_vf(adev))<br>
> > > return 0;<br>
> > ><br>
> > > + ret = pm_runtime_get_sync(ddev->dev);<br>
> > > + if (ret < 0)<br>
> > > + return ret;<br>
> > > +<br>
> > > if (is_support_sw_smu(adev)) {<br>
> > > if (adev->smu.ppt_funcs->get_current_power_state)<br>
> > > pm = smu_get_current_power_state(&adev->smu);<br>
> > > @@ -173,6 +179,9 @@ static ssize_t amdgpu_get_dpm_state(struct device<br>
> > > *dev,<br>
> > > pm = adev->pm.dpm.user_state;<br>
> > > }<br>
> > ><br>
> > > + pm_runtime_mark_last_busy(ddev->dev);<br>
> > > + pm_runtime_put_autosuspend(ddev->dev);<br>
> > > +<br>
> > > return snprintf(buf, PAGE_SIZE, "%s\n",<br>
> > > (pm == POWER_STATE_TYPE_BATTERY) ? "battery" :<br>
> > > (pm == POWER_STATE_TYPE_BALANCED) ?<br>
> > > "balanced" : "performance"); @@ -186,6 +195,7 @@ static ssize_t<br>
> > > amdgpu_set_dpm_state(struct device *dev,<br>
> > > struct drm_device *ddev = dev_get_drvdata(dev);<br>
> > > struct amdgpu_device *adev = ddev->dev_private;<br>
> > > enum amd_pm_state_type state;<br>
> > > + int ret;<br>
> > ><br>
> > > if (amdgpu_sriov_vf(adev) && !amdgpu_sriov_is_pp_one_vf(adev))<br>
> > > return -EINVAL;<br>
> > > @@ -201,6 +211,10 @@ static ssize_t amdgpu_set_dpm_state(struct<br>
> device<br>
> > > *dev,<br>
> > > goto fail;<br>
> > > }<br>
> > ><br>
> > > + ret = pm_runtime_get_sync(ddev->dev);<br>
> > > + if (ret < 0)<br>
> > > + return ret;<br>
> > > +<br>
> > > if (is_support_sw_smu(adev)) {<br>
> > > mutex_lock(&adev->pm.mutex);<br>
> > > adev->pm.dpm.user_state = state;<br>
> > > @@ -212,11 +226,12 @@ static ssize_t amdgpu_set_dpm_state(struct<br>
> device<br>
> > > *dev,<br>
> > > adev->pm.dpm.user_state = state;<br>
> > > mutex_unlock(&adev->pm.mutex);<br>
> > ><br>
> > > - /* Can't set dpm state when the card is off */<br>
> > > - if (!(adev->flags & AMD_IS_PX) ||<br>
> > > - (ddev->switch_power_state == DRM_SWITCH_POWER_ON))<br>
> > > - amdgpu_pm_compute_clocks(adev);<br>
> > > + amdgpu_pm_compute_clocks(adev);<br>
> > > }<br>
> > > + pm_runtime_mark_last_busy(ddev->dev);<br>
> > > + pm_runtime_put_autosuspend(ddev->dev);<br>
> > > +<br>
> > > +<br>
> > > fail:<br>
> > > return count;<br>
> > > }<br>
> > > @@ -288,13 +303,14 @@ static ssize_t<br>
> > > amdgpu_get_dpm_forced_performance_level(struct device *dev,<br>
> > > struct drm_device *ddev = dev_get_drvdata(dev);<br>
> > > struct amdgpu_device *adev = ddev->dev_private;<br>
> > > enum amd_dpm_forced_level level = 0xff;<br>
> > > + int ret;<br>
> > ><br>
> > > if (amdgpu_sriov_vf(adev) && !amdgpu_sriov_is_pp_one_vf(adev))<br>
> > > return 0;<br>
> > ><br>
> > > - if ((adev->flags & AMD_IS_PX) &&<br>
> > > - (ddev->switch_power_state != DRM_SWITCH_POWER_ON))<br>
> > > - return snprintf(buf, PAGE_SIZE, "off\n");<br>
> > > + ret = pm_runtime_get_sync(ddev->dev);<br>
> > > + if (ret < 0)<br>
> > > + return ret;<br>
> > ><br>
> > > if (is_support_sw_smu(adev))<br>
> > > level = smu_get_performance_level(&adev->smu);<br>
> > > @@ -303,6 +319,9 @@ static ssize_t<br>
> > > amdgpu_get_dpm_forced_performance_level(struct device *dev,<br>
> > > else<br>
> > > level = adev->pm.dpm.forced_level;<br>
> > ><br>
> > > + pm_runtime_mark_last_busy(ddev->dev);<br>
> > > + pm_runtime_put_autosuspend(ddev->dev);<br>
> > > +<br>
> > > return snprintf(buf, PAGE_SIZE, "%s\n",<br>
> > > (level == AMD_DPM_FORCED_LEVEL_AUTO) ? "auto" :<br>
> > > (level == AMD_DPM_FORCED_LEVEL_LOW) ? "low" :<br>
> > > @@ -329,11 +348,6 @@ static ssize_t<br>
> > > amdgpu_set_dpm_forced_performance_level(struct device *dev,<br>
> > > if (amdgpu_sriov_vf(adev) && !amdgpu_sriov_is_pp_one_vf(adev))<br>
> > > return -EINVAL;<br>
> > ><br>
> > > - /* Can't force performance level when the card is off */<br>
> > > - if ((adev->flags & AMD_IS_PX) &&<br>
> > > - (ddev->switch_power_state != DRM_SWITCH_POWER_ON))<br>
> > > - return -EINVAL;<br>
> > > -<br>
> > > if (strncmp("low", buf, strlen("low")) == 0) {<br>
> > > level = AMD_DPM_FORCED_LEVEL_LOW;<br>
> > > } else if (strncmp("high", buf, strlen("high")) == 0) { @@ -353,17<br>
> > > +367,23 @@ static ssize_t<br>
> amdgpu_set_dpm_forced_performance_level(struct<br>
> > > device *dev,<br>
> > > } else if (strncmp("profile_peak", buf, strlen("profile_peak")) == 0) {<br>
> > > level = AMD_DPM_FORCED_LEVEL_PROFILE_PEAK;<br>
> > > } else {<br>
> > > - count = -EINVAL;<br>
> > > - goto fail;<br>
> > > + return -EINVAL;<br>
> > > }<br>
> > ><br>
> > > + ret = pm_runtime_get_sync(ddev->dev);<br>
> > > + if (ret < 0)<br>
> > > + return ret;<br>
> > > +<br>
> > > if (is_support_sw_smu(adev))<br>
> > > current_level = smu_get_performance_level(&adev->smu);<br>
> > > else if (adev->powerplay.pp_funcs->get_performance_level)<br>
> > > current_level = amdgpu_dpm_get_performance_level(adev);<br>
> > ><br>
> > > - if (current_level == level)<br>
> > > + if (current_level == level) {<br>
> > > + pm_runtime_mark_last_busy(ddev->dev);<br>
> > > + pm_runtime_put_autosuspend(ddev->dev);<br>
> > > return count;<br>
> > > + }<br>
> > ><br>
> > > /* profile_exit setting is valid only when current mode is in profile<br>
> > > mode */<br>
> > > if (!(current_level & (AMD_DPM_FORCED_LEVEL_PROFILE_STANDARD<br>
> > > | @@ -372,6 +392,8 @@ static ssize_t<br>
> > > amdgpu_set_dpm_forced_performance_level(struct device *dev,<br>
> > > AMD_DPM_FORCED_LEVEL_PROFILE_PEAK)) &&<br>
> > > (level == AMD_DPM_FORCED_LEVEL_PROFILE_EXIT)) {<br>
> > > pr_err("Currently not in any profile mode!\n");<br>
> > > + pm_runtime_mark_last_busy(ddev->dev);<br>
> > > + pm_runtime_put_autosuspend(ddev->dev);<br>
> > > return -EINVAL;<br>
> > > }<br>
> > ><br>
> > > @@ -382,9 +404,10 @@ static ssize_t<br>
> > > amdgpu_set_dpm_forced_performance_level(struct device *dev,<br>
> > > } else if (adev->powerplay.pp_funcs->force_performance_level) {<br>
> > > mutex_lock(&adev->pm.mutex);<br>
> > > if (adev->pm.dpm.thermal_active) {<br>
> > > - count = -EINVAL;<br>
> > > mutex_unlock(&adev->pm.mutex);<br>
> > > - goto fail;<br>
> > > + pm_runtime_mark_last_busy(ddev->dev);<br>
> > > + pm_runtime_put_autosuspend(ddev->dev);<br>
> > > + return -EINVAL;<br>
> > > }<br>
> > > ret = amdgpu_dpm_force_performance_level(adev, level);<br>
> > > if (ret)<br>
> > > @@ -393,8 +416,9 @@ static ssize_t<br>
> > > amdgpu_set_dpm_forced_performance_level(struct device *dev,<br>
> > > adev->pm.dpm.forced_level = level;<br>
> > > mutex_unlock(&adev->pm.mutex);<br>
> > > }<br>
> > > + pm_runtime_mark_last_busy(ddev->dev);<br>
> > > + pm_runtime_put_autosuspend(ddev->dev);<br>
> > ><br>
> > > -fail:<br>
> > > return count;<br>
> > > }<br>
> > ><br>
> > > @@ -407,6 +431,10 @@ static ssize_t amdgpu_get_pp_num_states(struct<br>
> > > device *dev,<br>
> > > struct pp_states_info data;<br>
> > > int i, buf_len, ret;<br>
> > ><br>
> > > + ret = pm_runtime_get_sync(ddev->dev);<br>
> > > + if (ret < 0)<br>
> > > + return ret;<br>
> > > +<br>
> > > if (is_support_sw_smu(adev)) {<br>
> > > ret = smu_get_power_num_states(&adev->smu, &data);<br>
> > > if (ret)<br>
> > > @@ -414,6 +442,9 @@ static ssize_t amdgpu_get_pp_num_states(struct<br>
> > > device *dev,<br>
> > > } else if (adev->powerplay.pp_funcs->get_pp_num_states)<br>
> > > amdgpu_dpm_get_pp_num_states(adev, &data);<br>
> > ><br>
> > > + pm_runtime_mark_last_busy(ddev->dev);<br>
> > > + pm_runtime_put_autosuspend(ddev->dev);<br>
> > > +<br>
> > > buf_len = snprintf(buf, PAGE_SIZE, "states: %d\n", data.nums);<br>
> > > for (i = 0; i < data.nums; i++)<br>
> > > buf_len += snprintf(buf + buf_len, PAGE_SIZE, "%d %s\n", i,<br>
> > > @@ -439,6 +470,10 @@ static ssize_t amdgpu_get_pp_cur_state(struct<br>
> device<br>
> > > *dev,<br>
> > > if (amdgpu_sriov_vf(adev) && !amdgpu_sriov_is_pp_one_vf(adev))<br>
> > > return 0;<br>
> > ><br>
> > > + ret = pm_runtime_get_sync(ddev->dev);<br>
> > > + if (ret < 0)<br>
> > > + return ret;<br>
> > > +<br>
> > > if (is_support_sw_smu(adev)) {<br>
> > > pm = smu_get_current_power_state(smu);<br>
> > > ret = smu_get_power_num_states(smu, &data); @@ -450,6<br>
> > > +485,9 @@ static ssize_t amdgpu_get_pp_cur_state(struct device *dev,<br>
> > > amdgpu_dpm_get_pp_num_states(adev, &data);<br>
> > > }<br>
> > ><br>
> > > + pm_runtime_mark_last_busy(ddev->dev);<br>
> > > + pm_runtime_put_autosuspend(ddev->dev);<br>
> > > +<br>
> > > for (i = 0; i < data.nums; i++) {<br>
> > > if (pm == data.states[i])<br>
> > > break;<br>
> > > @@ -500,14 +538,18 @@ static ssize_t amdgpu_set_pp_force_state(struct<br>
> > > device *dev,<br>
> > > struct pp_states_info data;<br>
> > ><br>
> > > ret = kstrtoul(buf, 0, &idx);<br>
> > > - if (ret || idx >= ARRAY_SIZE(data.states)) {<br>
> > > - count = -EINVAL;<br>
> > > - goto fail;<br>
> > > - }<br>
> > > + if (ret || idx >= ARRAY_SIZE(data.states))<br>
> > > + return -EINVAL;<br>
> > > +<br>
> > > idx = array_index_nospec(idx, ARRAY_SIZE(data.states));<br>
> > ><br>
> > > amdgpu_dpm_get_pp_num_states(adev, &data);<br>
> > > state = data.states[idx];<br>
> > > +<br>
> > > + ret = pm_runtime_get_sync(ddev->dev);<br>
> > > + if (ret < 0)<br>
> > > + return ret;<br>
> > > +<br>
> > > /* only set user selected power states */<br>
> > > if (state != POWER_STATE_TYPE_INTERNAL_BOOT &&<br>
> > > state != POWER_STATE_TYPE_DEFAULT) { @@ -515,8<br>
> > > +557,10 @@ static ssize_t amdgpu_set_pp_force_state(struct device *dev,<br>
> > > AMD_PP_TASK_ENABLE_USER_STATE,<br>
> > > &state);<br>
> > > adev->pp_force_state_enabled = true;<br>
> > > }<br>
> > > + pm_runtime_mark_last_busy(ddev->dev);<br>
> > > + pm_runtime_put_autosuspend(ddev->dev);<br>
> > > }<br>
> > > -fail:<br>
> > > +<br>
> > > return count;<br>
> > > }<br>
> > ><br>
> > > @@ -538,20 +582,32 @@ static ssize_t amdgpu_get_pp_table(struct device<br>
> > > *dev,<br>
> > > struct drm_device *ddev = dev_get_drvdata(dev);<br>
> > > struct amdgpu_device *adev = ddev->dev_private;<br>
> > > char *table = NULL;<br>
> > > - int size;<br>
> > > + int size, ret;<br>
> > ><br>
> > > if (amdgpu_sriov_vf(adev) && !amdgpu_sriov_is_pp_one_vf(adev))<br>
> > > return 0;<br>
> > ><br>
> > > + ret = pm_runtime_get_sync(ddev->dev);<br>
> > > + if (ret < 0)<br>
> > > + return ret;<br>
> > > +<br>
> > > if (is_support_sw_smu(adev)) {<br>
> > > size = smu_sys_get_pp_table(&adev->smu, (void **)&table);<br>
> > > + pm_runtime_mark_last_busy(ddev->dev);<br>
> > > + pm_runtime_put_autosuspend(ddev->dev);<br>
> > > if (size < 0)<br>
> > > return size;<br>
> > > - }<br>
> > > - else if (adev->powerplay.pp_funcs->get_pp_table)<br>
> > > + } else if (adev->powerplay.pp_funcs->get_pp_table) {<br>
> > > size = amdgpu_dpm_get_pp_table(adev, &table);<br>
> > > - else<br>
> > > + pm_runtime_mark_last_busy(ddev->dev);<br>
> > > + pm_runtime_put_autosuspend(ddev->dev);<br>
> > > + if (size < 0)<br>
> > > + return size;<br>
> > > + } else {<br>
> > > + pm_runtime_mark_last_busy(ddev->dev);<br>
> > > + pm_runtime_put_autosuspend(ddev->dev);<br>
> > > return 0;<br>
> > > + }<br>
> > ><br>
> > > if (size >= PAGE_SIZE)<br>
> > > size = PAGE_SIZE - 1;<br>
> > > @@ -573,13 +629,23 @@ static ssize_t amdgpu_set_pp_table(struct device<br>
> > > *dev,<br>
> > > if (amdgpu_sriov_vf(adev) && !amdgpu_sriov_is_pp_one_vf(adev))<br>
> > > return -EINVAL;<br>
> > ><br>
> > > + ret = pm_runtime_get_sync(ddev->dev);<br>
> > > + if (ret < 0)<br>
> > > + return ret;<br>
> > > +<br>
> > > if (is_support_sw_smu(adev)) {<br>
> > > ret = smu_sys_set_pp_table(&adev->smu, (void *)buf, count);<br>
> > > - if (ret)<br>
> > > + if (ret) {<br>
> > > + pm_runtime_mark_last_busy(ddev->dev);<br>
> > > + pm_runtime_put_autosuspend(ddev->dev);<br>
> > > return ret;<br>
> > > + }<br>
> > > } else if (adev->powerplay.pp_funcs->set_pp_table)<br>
> > > amdgpu_dpm_set_pp_table(adev, buf, count);<br>
> > ><br>
> > > + pm_runtime_mark_last_busy(ddev->dev);<br>
> > > + pm_runtime_put_autosuspend(ddev->dev);<br>
> > > +<br>
> > > return count;<br>
> > > }<br>
> > ><br>
> > > @@ -703,18 +769,28 @@ static ssize_t<br>
> amdgpu_set_pp_od_clk_voltage(struct<br>
> > > device *dev,<br>
> > > tmp_str++;<br>
> > > }<br>
> > ><br>
> > > + ret = pm_runtime_get_sync(ddev->dev);<br>
> > > + if (ret < 0)<br>
> > > + return ret;<br>
> > > +<br>
> > > if (is_support_sw_smu(adev)) {<br>
> > > ret = smu_od_edit_dpm_table(&adev->smu, type,<br>
> > > parameter, parameter_size);<br>
> > ><br>
> > > - if (ret)<br>
> > > + if (ret) {<br>
> > > + pm_runtime_mark_last_busy(ddev->dev);<br>
> > > + pm_runtime_put_autosuspend(ddev->dev);<br>
> > > return -EINVAL;<br>
> > > + }<br>
> > > } else {<br>
> > > if (adev->powerplay.pp_funcs->odn_edit_dpm_table) {<br>
> > > ret = amdgpu_dpm_odn_edit_dpm_table(adev, type,<br>
> > > parameter, parameter_size);<br>
> > > - if (ret)<br>
> > > + if (ret) {<br>
> > > + pm_runtime_mark_last_busy(ddev->dev);<br>
> > > + pm_runtime_put_autosuspend(ddev->dev);<br>
> > > return -EINVAL;<br>
> > > + }<br>
> > > }<br>
> > ><br>
> > > if (type == PP_OD_COMMIT_DPM_TABLE) { @@ -722,12<br>
> > > +798,18 @@ static ssize_t amdgpu_set_pp_od_clk_voltage(struct device<br>
> *dev,<br>
> > > amdgpu_dpm_dispatch_task(adev,<br>
> > ><br>
> > > AMD_PP_TASK_READJUST_POWER_STATE,<br>
> > > NULL);<br>
> > > + pm_runtime_mark_last_busy(ddev->dev);<br>
> > > + pm_runtime_put_autosuspend(ddev->dev);<br>
> > > return count;<br>
> > > } else {<br>
> > > + pm_runtime_mark_last_busy(ddev->dev);<br>
> > > + pm_runtime_put_autosuspend(ddev->dev);<br>
> > > return -EINVAL;<br>
> > > }<br>
> > > }<br>
> > > }<br>
> > > + pm_runtime_mark_last_busy(ddev->dev);<br>
> > > + pm_runtime_put_autosuspend(ddev->dev);<br>
> > ><br>
> > > return count;<br>
> > > }<br>
> > > @@ -738,27 +820,33 @@ static ssize_t<br>
> amdgpu_get_pp_od_clk_voltage(struct<br>
> > > device *dev, {<br>
> > > struct drm_device *ddev = dev_get_drvdata(dev);<br>
> > > struct amdgpu_device *adev = ddev->dev_private;<br>
> > > - uint32_t size = 0;<br>
> > > + ssize_t size;<br>
> > > + int ret;<br>
> > ><br>
> > > if (amdgpu_sriov_vf(adev))<br>
> > > return 0;<br>
> > ><br>
> > > + ret = pm_runtime_get_sync(ddev->dev);<br>
> > > + if (ret < 0)<br>
> > > + return ret;<br>
> > > +<br>
> > > if (is_support_sw_smu(adev)) {<br>
> > > size = smu_print_clk_levels(&adev->smu, SMU_OD_SCLK, buf);<br>
> > > size += smu_print_clk_levels(&adev->smu, SMU_OD_MCLK,<br>
> > > buf+size);<br>
> > > size += smu_print_clk_levels(&adev->smu,<br>
> > > SMU_OD_VDDC_CURVE, buf+size);<br>
> > > size += smu_print_clk_levels(&adev->smu, SMU_OD_RANGE,<br>
> > > buf+size);<br>
> > > - return size;<br>
> > > } else if (adev->powerplay.pp_funcs->print_clock_levels) {<br>
> > > size = amdgpu_dpm_print_clock_levels(adev, OD_SCLK, buf);<br>
> > > size += amdgpu_dpm_print_clock_levels(adev, OD_MCLK,<br>
> > > buf+size);<br>
> > > size += amdgpu_dpm_print_clock_levels(adev,<br>
> > > OD_VDDC_CURVE, buf+size);<br>
> > > size += amdgpu_dpm_print_clock_levels(adev, OD_RANGE,<br>
> > > buf+size);<br>
> > > - return size;<br>
> > > } else {<br>
> > > - return snprintf(buf, PAGE_SIZE, "\n");<br>
> > > + size = snprintf(buf, PAGE_SIZE, "\n");<br>
> > > }<br>
> > > + pm_runtime_mark_last_busy(ddev->dev);<br>
> > > + pm_runtime_put_autosuspend(ddev->dev);<br>
> > ><br>
> > > + return size;<br>
> > > }<br>
> > ><br>
> > > /**<br>
> > > @@ -796,15 +884,21 @@ static ssize_t<br>
> amdgpu_set_pp_feature_status(struct<br>
> > > device *dev,<br>
> > ><br>
> > > pr_debug("featuremask = 0x%llx\n", featuremask);<br>
> > ><br>
> > > + ret = pm_runtime_get_sync(ddev->dev);<br>
> > > + if (ret < 0)<br>
> > > + return ret;<br>
> > > +<br>
> > > if (is_support_sw_smu(adev)) {<br>
> > > ret = smu_sys_set_pp_feature_mask(&adev->smu,<br>
> > > featuremask);<br>
> > > if (ret)<br>
> > > - return -EINVAL;<br>
> > > + count = -EINVAL;<br>
> > > } else if (adev->powerplay.pp_funcs->set_ppfeature_status) {<br>
> > > ret = amdgpu_dpm_set_ppfeature_status(adev, featuremask);<br>
> > > if (ret)<br>
> > > - return -EINVAL;<br>
> > > + count = -EINVAL;<br>
> > > }<br>
> > > + pm_runtime_mark_last_busy(ddev->dev);<br>
> > > + pm_runtime_put_autosuspend(ddev->dev);<br>
> > ><br>
> > > return count;<br>
> > > }<br>
> > > @@ -815,16 +909,27 @@ static ssize_t<br>
> amdgpu_get_pp_feature_status(struct<br>
> > > device *dev, {<br>
> > > struct drm_device *ddev = dev_get_drvdata(dev);<br>
> > > struct amdgpu_device *adev = ddev->dev_private;<br>
> > > + ssize_t size;<br>
> > > + int ret;<br>
> > ><br>
> > > if (amdgpu_sriov_vf(adev))<br>
> > > return 0;<br>
> > ><br>
> > > - if (is_support_sw_smu(adev)) {<br>
> > > - return smu_sys_get_pp_feature_mask(&adev->smu, buf);<br>
> > > - } else if (adev->powerplay.pp_funcs->get_ppfeature_status)<br>
> > > - return amdgpu_dpm_get_ppfeature_status(adev, buf);<br>
> > > + ret = pm_runtime_get_sync(ddev->dev);<br>
> > > + if (ret < 0)<br>
> > > + return ret;<br>
> > > +<br>
> > > + if (is_support_sw_smu(adev))<br>
> > > + size = smu_sys_get_pp_feature_mask(&adev->smu, buf);<br>
> > > + else if (adev->powerplay.pp_funcs->get_ppfeature_status)<br>
> > > + size = amdgpu_dpm_get_ppfeature_status(adev, buf);<br>
> > > + else<br>
> > > + size = snprintf(buf, PAGE_SIZE, "\n");<br>
> > > +<br>
> > > + pm_runtime_mark_last_busy(ddev->dev);<br>
> > > + pm_runtime_put_autosuspend(ddev->dev);<br>
> > ><br>
> > > - return snprintf(buf, PAGE_SIZE, "\n");<br>
> > > + return size;<br>
> > > }<br>
> > ><br>
> > > /**<br>
> > > @@ -863,16 +968,27 @@ static ssize_t amdgpu_get_pp_dpm_sclk(struct<br>
> > > device *dev, {<br>
> > > struct drm_device *ddev = dev_get_drvdata(dev);<br>
> > > struct amdgpu_device *adev = ddev->dev_private;<br>
> > > + ssize_t size;<br>
> > > + int ret;<br>
> > ><br>
> > > if (amdgpu_sriov_vf(adev) && !amdgpu_sriov_is_pp_one_vf(adev))<br>
> > > return 0;<br>
> > ><br>
> > > + ret = pm_runtime_get_sync(ddev->dev);<br>
> > > + if (ret < 0)<br>
> > > + return ret;<br>
> > > +<br>
> > > if (is_support_sw_smu(adev))<br>
> > > - return smu_print_clk_levels(&adev->smu, SMU_SCLK, buf);<br>
> > > + size = smu_print_clk_levels(&adev->smu, SMU_SCLK, buf);<br>
> > > else if (adev->powerplay.pp_funcs->print_clock_levels)<br>
> > > - return amdgpu_dpm_print_clock_levels(adev, PP_SCLK, buf);<br>
> > > + size = amdgpu_dpm_print_clock_levels(adev, PP_SCLK, buf);<br>
> > > else<br>
> > > - return snprintf(buf, PAGE_SIZE, "\n");<br>
> > > + size = snprintf(buf, PAGE_SIZE, "\n");<br>
> > > +<br>
> > > + pm_runtime_mark_last_busy(ddev->dev);<br>
> > > + pm_runtime_put_autosuspend(ddev->dev);<br>
> > > +<br>
> > > + return size;<br>
> > > }<br>
> > ><br>
> > > /*<br>
> > > @@ -928,11 +1044,18 @@ static ssize_t amdgpu_set_pp_dpm_sclk(struct<br>
> > > device *dev,<br>
> > > if (ret)<br>
> > > return ret;<br>
> > ><br>
> > > + ret = pm_runtime_get_sync(ddev->dev);<br>
> > > + if (ret < 0)<br>
> > > + return ret;<br>
> > > +<br>
> > > if (is_support_sw_smu(adev))<br>
> > > ret = smu_force_clk_levels(&adev->smu, SMU_SCLK, mask,<br>
> > > true);<br>
> > > else if (adev->powerplay.pp_funcs->force_clock_level)<br>
> > > ret = amdgpu_dpm_force_clock_level(adev, PP_SCLK, mask);<br>
> > ><br>
> > > + pm_runtime_mark_last_busy(ddev->dev);<br>
> > > + pm_runtime_put_autosuspend(ddev->dev);<br>
> > > +<br>
> > > if (ret)<br>
> > > return -EINVAL;<br>
> > ><br>
> > > @@ -945,16 +1068,27 @@ static ssize_t amdgpu_get_pp_dpm_mclk(struct<br>
> > > device *dev, {<br>
> > > struct drm_device *ddev = dev_get_drvdata(dev);<br>
> > > struct amdgpu_device *adev = ddev->dev_private;<br>
> > > + ssize_t size;<br>
> > > + int ret;<br>
> > ><br>
> > > if (amdgpu_sriov_vf(adev) && !amdgpu_sriov_is_pp_one_vf(adev))<br>
> > > return 0;<br>
> > ><br>
> > > + ret = pm_runtime_get_sync(ddev->dev);<br>
> > > + if (ret < 0)<br>
> > > + return ret;<br>
> > > +<br>
> > > if (is_support_sw_smu(adev))<br>
> > > - return smu_print_clk_levels(&adev->smu, SMU_MCLK, buf);<br>
> > > + size = smu_print_clk_levels(&adev->smu, SMU_MCLK, buf);<br>
> > > else if (adev->powerplay.pp_funcs->print_clock_levels)<br>
> > > - return amdgpu_dpm_print_clock_levels(adev, PP_MCLK, buf);<br>
> > > + size = amdgpu_dpm_print_clock_levels(adev, PP_MCLK, buf);<br>
> > > else<br>
> > > - return snprintf(buf, PAGE_SIZE, "\n");<br>
> > > + size = snprintf(buf, PAGE_SIZE, "\n");<br>
> > > +<br>
> > > + pm_runtime_mark_last_busy(ddev->dev);<br>
> > > + pm_runtime_put_autosuspend(ddev->dev);<br>
> > > +<br>
> > > + return size;<br>
> > > }<br>
> > ><br>
> > > static ssize_t amdgpu_set_pp_dpm_mclk(struct device *dev, @@ -964,8<br>
> > > +1098,8 @@ static ssize_t amdgpu_set_pp_dpm_mclk(struct device *dev, {<br>
> > > struct drm_device *ddev = dev_get_drvdata(dev);<br>
> > > struct amdgpu_device *adev = ddev->dev_private;<br>
> > > - int ret;<br>
> > > uint32_t mask = 0;<br>
> > > + int ret;<br>
> > ><br>
> > > if (amdgpu_sriov_vf(adev) && !amdgpu_sriov_is_pp_one_vf(adev))<br>
> > > return -EINVAL;<br>
> > > @@ -974,11 +1108,18 @@ static ssize_t amdgpu_set_pp_dpm_mclk(struct<br>
> > > device *dev,<br>
> > > if (ret)<br>
> > > return ret;<br>
> > ><br>
> > > + ret = pm_runtime_get_sync(ddev->dev);<br>
> > > + if (ret < 0)<br>
> > > + return ret;<br>
> > > +<br>
> > > if (is_support_sw_smu(adev))<br>
> > > ret = smu_force_clk_levels(&adev->smu, SMU_MCLK, mask,<br>
> > > true);<br>
> > > else if (adev->powerplay.pp_funcs->force_clock_level)<br>
> > > ret = amdgpu_dpm_force_clock_level(adev, PP_MCLK, mask);<br>
> > ><br>
> > > + pm_runtime_mark_last_busy(ddev->dev);<br>
> > > + pm_runtime_put_autosuspend(ddev->dev);<br>
> > > +<br>
> > > if (ret)<br>
> > > return -EINVAL;<br>
> > ><br>
> > > @@ -991,16 +1132,27 @@ static ssize_t<br>
> amdgpu_get_pp_dpm_socclk(struct<br>
> > > device *dev, {<br>
> > > struct drm_device *ddev = dev_get_drvdata(dev);<br>
> > > struct amdgpu_device *adev = ddev->dev_private;<br>
> > > + ssize_t size;<br>
> > > + int ret;<br>
> > ><br>
> > > if (amdgpu_sriov_vf(adev) && !amdgpu_sriov_is_pp_one_vf(adev))<br>
> > > return 0;<br>
> > ><br>
> > > + ret = pm_runtime_get_sync(ddev->dev);<br>
> > > + if (ret < 0)<br>
> > > + return ret;<br>
> > > +<br>
> > > if (is_support_sw_smu(adev))<br>
> > > - return smu_print_clk_levels(&adev->smu, SMU_SOCCLK, buf);<br>
> > > + size = smu_print_clk_levels(&adev->smu, SMU_SOCCLK, buf);<br>
> > > else if (adev->powerplay.pp_funcs->print_clock_levels)<br>
> > > - return amdgpu_dpm_print_clock_levels(adev, PP_SOCCLK, buf);<br>
> > > + size = amdgpu_dpm_print_clock_levels(adev, PP_SOCCLK, buf);<br>
> > > else<br>
> > > - return snprintf(buf, PAGE_SIZE, "\n");<br>
> > > + size = snprintf(buf, PAGE_SIZE, "\n");<br>
> > > +<br>
> > > + pm_runtime_mark_last_busy(ddev->dev);<br>
> > > + pm_runtime_put_autosuspend(ddev->dev);<br>
> > > +<br>
> > > + return size;<br>
> > > }<br>
> > ><br>
> > > static ssize_t amdgpu_set_pp_dpm_socclk(struct device *dev, @@ -<br>
> 1020,10<br>
> > > +1172,19 @@ static ssize_t amdgpu_set_pp_dpm_socclk(struct device *dev,<br>
> > > if (ret)<br>
> > > return ret;<br>
> > ><br>
> > > + ret = pm_runtime_get_sync(ddev->dev);<br>
> > > + if (ret < 0)<br>
> > > + return ret;<br>
> > > +<br>
> > > if (is_support_sw_smu(adev))<br>
> > > ret = smu_force_clk_levels(&adev->smu, SMU_SOCCLK, mask,<br>
> > > true);<br>
> > > else if (adev->powerplay.pp_funcs->force_clock_level)<br>
> > > ret = amdgpu_dpm_force_clock_level(adev, PP_SOCCLK, mask);<br>
> > > + else<br>
> > > + ret = 0;<br>
> > > +<br>
> > > + pm_runtime_mark_last_busy(ddev->dev);<br>
> > > + pm_runtime_put_autosuspend(ddev->dev);<br>
> > ><br>
> > > if (ret)<br>
> > > return -EINVAL;<br>
> > > @@ -1037,16 +1198,27 @@ static ssize_t amdgpu_get_pp_dpm_fclk(struct<br>
> > > device *dev, {<br>
> > > struct drm_device *ddev = dev_get_drvdata(dev);<br>
> > > struct amdgpu_device *adev = ddev->dev_private;<br>
> > > + ssize_t size;<br>
> > > + int ret;<br>
> > ><br>
> > > if (amdgpu_sriov_vf(adev) && !amdgpu_sriov_is_pp_one_vf(adev))<br>
> > > return 0;<br>
> > ><br>
> > > + ret = pm_runtime_get_sync(ddev->dev);<br>
> > > + if (ret < 0)<br>
> > > + return ret;<br>
> > > +<br>
> > > if (is_support_sw_smu(adev))<br>
> > > - return smu_print_clk_levels(&adev->smu, SMU_FCLK, buf);<br>
> > > + size = smu_print_clk_levels(&adev->smu, SMU_FCLK, buf);<br>
> > > else if (adev->powerplay.pp_funcs->print_clock_levels)<br>
> > > - return amdgpu_dpm_print_clock_levels(adev, PP_FCLK, buf);<br>
> > > + size = amdgpu_dpm_print_clock_levels(adev, PP_FCLK, buf);<br>
> > > else<br>
> > > - return snprintf(buf, PAGE_SIZE, "\n");<br>
> > > + size = snprintf(buf, PAGE_SIZE, "\n");<br>
> > > +<br>
> > > + pm_runtime_mark_last_busy(ddev->dev);<br>
> > > + pm_runtime_put_autosuspend(ddev->dev);<br>
> > > +<br>
> > > + return size;<br>
> > > }<br>
> > ><br>
> > > static ssize_t amdgpu_set_pp_dpm_fclk(struct device *dev, @@ -1066,10<br>
> > > +1238,19 @@ static ssize_t amdgpu_set_pp_dpm_fclk(struct device *dev,<br>
> > > if (ret)<br>
> > > return ret;<br>
> > ><br>
> > > + ret = pm_runtime_get_sync(ddev->dev);<br>
> > > + if (ret < 0)<br>
> > > + return ret;<br>
> > > +<br>
> > > if (is_support_sw_smu(adev))<br>
> > > ret = smu_force_clk_levels(&adev->smu, SMU_FCLK, mask,<br>
> > > true);<br>
> > > else if (adev->powerplay.pp_funcs->force_clock_level)<br>
> > > ret = amdgpu_dpm_force_clock_level(adev, PP_FCLK, mask);<br>
> > > + else<br>
> > > + ret = 0;<br>
> > > +<br>
> > > + pm_runtime_mark_last_busy(ddev->dev);<br>
> > > + pm_runtime_put_autosuspend(ddev->dev);<br>
> > ><br>
> > > if (ret)<br>
> > > return -EINVAL;<br>
> > > @@ -1083,16 +1264,27 @@ static ssize_t<br>
> amdgpu_get_pp_dpm_dcefclk(struct<br>
> > > device *dev, {<br>
> > > struct drm_device *ddev = dev_get_drvdata(dev);<br>
> > > struct amdgpu_device *adev = ddev->dev_private;<br>
> > > + ssize_t size;<br>
> > > + int ret;<br>
> > ><br>
> > > if (amdgpu_sriov_vf(adev))<br>
> > > return 0;<br>
> > ><br>
> > > + ret = pm_runtime_get_sync(ddev->dev);<br>
> > > + if (ret < 0)<br>
> > > + return ret;<br>
> > > +<br>
> > > if (is_support_sw_smu(adev))<br>
> > > - return smu_print_clk_levels(&adev->smu, SMU_DCEFCLK, buf);<br>
> > > + size = smu_print_clk_levels(&adev->smu, SMU_DCEFCLK, buf);<br>
> > > else if (adev->powerplay.pp_funcs->print_clock_levels)<br>
> > > - return amdgpu_dpm_print_clock_levels(adev, PP_DCEFCLK,<br>
> > > buf);<br>
> > > + size = amdgpu_dpm_print_clock_levels(adev, PP_DCEFCLK,<br>
> > > buf);<br>
> > > else<br>
> > > - return snprintf(buf, PAGE_SIZE, "\n");<br>
> > > + size = snprintf(buf, PAGE_SIZE, "\n");<br>
> > > +<br>
> > > + pm_runtime_mark_last_busy(ddev->dev);<br>
> > > + pm_runtime_put_autosuspend(ddev->dev);<br>
> > > +<br>
> > > + return size;<br>
> > > }<br>
> > ><br>
> > > static ssize_t amdgpu_set_pp_dpm_dcefclk(struct device *dev, @@ -<br>
> 1112,10<br>
> > > +1304,19 @@ static ssize_t amdgpu_set_pp_dpm_dcefclk(struct device<br>
> *dev,<br>
> > > if (ret)<br>
> > > return ret;<br>
> > ><br>
> > > + ret = pm_runtime_get_sync(ddev->dev);<br>
> > > + if (ret < 0)<br>
> > > + return ret;<br>
> > > +<br>
> > > if (is_support_sw_smu(adev))<br>
> > > ret = smu_force_clk_levels(&adev->smu, SMU_DCEFCLK, mask,<br>
> > > true);<br>
> > > else if (adev->powerplay.pp_funcs->force_clock_level)<br>
> > > ret = amdgpu_dpm_force_clock_level(adev, PP_DCEFCLK,<br>
> > > mask);<br>
> > > + else<br>
> > > + ret = 0;<br>
> > > +<br>
> > > + pm_runtime_mark_last_busy(ddev->dev);<br>
> > > + pm_runtime_put_autosuspend(ddev->dev);<br>
> > ><br>
> > > if (ret)<br>
> > > return -EINVAL;<br>
> > > @@ -1129,16 +1330,27 @@ static ssize_t amdgpu_get_pp_dpm_pcie(struct<br>
> > > device *dev, {<br>
> > > struct drm_device *ddev = dev_get_drvdata(dev);<br>
> > > struct amdgpu_device *adev = ddev->dev_private;<br>
> > > + ssize_t size;<br>
> > > + int ret;<br>
> > ><br>
> > > if (amdgpu_sriov_vf(adev) && !amdgpu_sriov_is_pp_one_vf(adev))<br>
> > > return 0;<br>
> > ><br>
> > > + ret = pm_runtime_get_sync(ddev->dev);<br>
> > > + if (ret < 0)<br>
> > > + return ret;<br>
> > > +<br>
> > > if (is_support_sw_smu(adev))<br>
> > > - return smu_print_clk_levels(&adev->smu, SMU_PCIE, buf);<br>
> > > + size = smu_print_clk_levels(&adev->smu, SMU_PCIE, buf);<br>
> > > else if (adev->powerplay.pp_funcs->print_clock_levels)<br>
> > > - return amdgpu_dpm_print_clock_levels(adev, PP_PCIE, buf);<br>
> > > + size = amdgpu_dpm_print_clock_levels(adev, PP_PCIE, buf);<br>
> > > else<br>
> > > - return snprintf(buf, PAGE_SIZE, "\n");<br>
> > > + size = snprintf(buf, PAGE_SIZE, "\n");<br>
> > > +<br>
> > > + pm_runtime_mark_last_busy(ddev->dev);<br>
> > > + pm_runtime_put_autosuspend(ddev->dev);<br>
> > > +<br>
> > > + return size;<br>
> > > }<br>
> > ><br>
> > > static ssize_t amdgpu_set_pp_dpm_pcie(struct device *dev, @@ -1158,10<br>
> > > +1370,19 @@ static ssize_t amdgpu_set_pp_dpm_pcie(struct device *dev,<br>
> > > if (ret)<br>
> > > return ret;<br>
> > ><br>
> > > + ret = pm_runtime_get_sync(ddev->dev);<br>
> > > + if (ret < 0)<br>
> > > + return ret;<br>
> > > +<br>
> > > if (is_support_sw_smu(adev))<br>
> > > ret = smu_force_clk_levels(&adev->smu, SMU_PCIE, mask,<br>
> > > true);<br>
> > > else if (adev->powerplay.pp_funcs->force_clock_level)<br>
> > > ret = amdgpu_dpm_force_clock_level(adev, PP_PCIE, mask);<br>
> > > + else<br>
> > > + ret = 0;<br>
> > > +<br>
> > > + pm_runtime_mark_last_busy(ddev->dev);<br>
> > > + pm_runtime_put_autosuspend(ddev->dev);<br>
> > ><br>
> > > if (ret)<br>
> > > return -EINVAL;<br>
> > > @@ -1176,15 +1397,23 @@ static ssize_t amdgpu_get_pp_sclk_od(struct<br>
> > > device *dev,<br>
> > > struct drm_device *ddev = dev_get_drvdata(dev);<br>
> > > struct amdgpu_device *adev = ddev->dev_private;<br>
> > > uint32_t value = 0;<br>
> > > + int ret;<br>
> > ><br>
> > > if (amdgpu_sriov_vf(adev))<br>
> > > return 0;<br>
> > ><br>
> > > + ret = pm_runtime_get_sync(ddev->dev);<br>
> > > + if (ret < 0)<br>
> > > + return ret;<br>
> > > +<br>
> > > if (is_support_sw_smu(adev))<br>
> > > value = smu_get_od_percentage(&(adev->smu),<br>
> > > SMU_OD_SCLK);<br>
> > > else if (adev->powerplay.pp_funcs->get_sclk_od)<br>
> > > value = amdgpu_dpm_get_sclk_od(adev);<br>
> > ><br>
> > > + pm_runtime_mark_last_busy(ddev->dev);<br>
> > > + pm_runtime_put_autosuspend(ddev->dev);<br>
> > > +<br>
> > > return snprintf(buf, PAGE_SIZE, "%d\n", value); }<br>
> > ><br>
> > > @@ -1203,10 +1432,12 @@ static ssize_t amdgpu_set_pp_sclk_od(struct<br>
> > > device *dev,<br>
> > ><br>
> > > ret = kstrtol(buf, 0, &value);<br>
> > ><br>
> > > - if (ret) {<br>
> > > - count = -EINVAL;<br>
> > > - goto fail;<br>
> > > - }<br>
> > > + if (ret)<br>
> > > + return -EINVAL;<br>
> > > +<br>
> > > + ret = pm_runtime_get_sync(ddev->dev);<br>
> > > + if (ret < 0)<br>
> > > + return ret;<br>
> > ><br>
> > > if (is_support_sw_smu(adev)) {<br>
> > > value = smu_set_od_percentage(&(adev->smu),<br>
> > > SMU_OD_SCLK, (uint32_t)value); @@ -1222,7 +1453,9 @@ static ssize_t<br>
> > > amdgpu_set_pp_sclk_od(struct device *dev,<br>
> > > }<br>
> > > }<br>
> > ><br>
> > > -fail:<br>
> > > + pm_runtime_mark_last_busy(ddev->dev);<br>
> > > + pm_runtime_put_autosuspend(ddev->dev);<br>
> > > +<br>
> > > return count;<br>
> > > }<br>
> > ><br>
> > > @@ -1233,15 +1466,23 @@ static ssize_t amdgpu_get_pp_mclk_od(struct<br>
> > > device *dev,<br>
> > > struct drm_device *ddev = dev_get_drvdata(dev);<br>
> > > struct amdgpu_device *adev = ddev->dev_private;<br>
> > > uint32_t value = 0;<br>
> > > + int ret;<br>
> > ><br>
> > > if (amdgpu_sriov_vf(adev))<br>
> > > return 0;<br>
> > ><br>
> > > + ret = pm_runtime_get_sync(ddev->dev);<br>
> > > + if (ret < 0)<br>
> > > + return ret;<br>
> > > +<br>
> > > if (is_support_sw_smu(adev))<br>
> > > value = smu_get_od_percentage(&(adev->smu),<br>
> > > SMU_OD_MCLK);<br>
> > > else if (adev->powerplay.pp_funcs->get_mclk_od)<br>
> > > value = amdgpu_dpm_get_mclk_od(adev);<br>
> > ><br>
> > > + pm_runtime_mark_last_busy(ddev->dev);<br>
> > > + pm_runtime_put_autosuspend(ddev->dev);<br>
> > > +<br>
> > > return snprintf(buf, PAGE_SIZE, "%d\n", value); }<br>
> > ><br>
> > > @@ -1260,10 +1501,12 @@ static ssize_t amdgpu_set_pp_mclk_od(struct<br>
> > > device *dev,<br>
> > ><br>
> > > ret = kstrtol(buf, 0, &value);<br>
> > ><br>
> > > - if (ret) {<br>
> > > - count = -EINVAL;<br>
> > > - goto fail;<br>
> > > - }<br>
> > > + if (ret)<br>
> > > + return -EINVAL;<br>
> > > +<br>
> > > + ret = pm_runtime_get_sync(ddev->dev);<br>
> > > + if (ret < 0)<br>
> > > + return ret;<br>
> > ><br>
> > > if (is_support_sw_smu(adev)) {<br>
> > > value = smu_set_od_percentage(&(adev->smu),<br>
> > > SMU_OD_MCLK, (uint32_t)value); @@ -1279,7 +1522,9 @@ static ssize_t<br>
> > > amdgpu_set_pp_mclk_od(struct device *dev,<br>
> > > }<br>
> > > }<br>
> > ><br>
> > > -fail:<br>
> > > + pm_runtime_mark_last_busy(ddev->dev);<br>
> > > + pm_runtime_put_autosuspend(ddev->dev);<br>
> > > +<br>
> > > return count;<br>
> > > }<br>
> > ><br>
> > > @@ -1309,16 +1554,27 @@ static ssize_t<br>
> > > amdgpu_get_pp_power_profile_mode(struct device *dev, {<br>
> > > struct drm_device *ddev = dev_get_drvdata(dev);<br>
> > > struct amdgpu_device *adev = ddev->dev_private;<br>
> > > + ssize_t size;<br>
> > > + int ret;<br>
> > ><br>
> > > if (amdgpu_sriov_vf(adev) && !amdgpu_sriov_is_pp_one_vf(adev))<br>
> > > return 0;<br>
> > ><br>
> > > + ret = pm_runtime_get_sync(ddev->dev);<br>
> > > + if (ret < 0)<br>
> > > + return ret;<br>
> > > +<br>
> > > if (is_support_sw_smu(adev))<br>
> > > - return smu_get_power_profile_mode(&adev->smu, buf);<br>
> > > + size = smu_get_power_profile_mode(&adev->smu, buf);<br>
> > > else if (adev->powerplay.pp_funcs->get_power_profile_mode)<br>
> > > - return amdgpu_dpm_get_power_profile_mode(adev, buf);<br>
> > > + size = amdgpu_dpm_get_power_profile_mode(adev, buf);<br>
> > > + else<br>
> > > + size = snprintf(buf, PAGE_SIZE, "\n");<br>
> > > +<br>
> > > + pm_runtime_mark_last_busy(ddev->dev);<br>
> > > + pm_runtime_put_autosuspend(ddev->dev);<br>
> > ><br>
> > > - return snprintf(buf, PAGE_SIZE, "\n");<br>
> > > + return size;<br>
> > > }<br>
> > ><br>
> > ><br>
> > > @@ -1343,7 +1599,7 @@ static ssize_t<br>
> > > amdgpu_set_pp_power_profile_mode(struct device *dev,<br>
> > > tmp[1] = '\0';<br>
> > > ret = kstrtol(tmp, 0, &profile_mode);<br>
> > > if (ret)<br>
> > > - goto fail;<br>
> > > + return -EINVAL;<br>
> > ><br>
> > > if (amdgpu_sriov_vf(adev) && !amdgpu_sriov_is_pp_one_vf(adev))<br>
> > > return -EINVAL;<br>
> > > @@ -1358,23 +1614,30 @@ static ssize_t<br>
> > > amdgpu_set_pp_power_profile_mode(struct device *dev,<br>
> > > while (tmp_str[0]) {<br>
> > > sub_str = strsep(&tmp_str, delimiter);<br>
> > > ret = kstrtol(sub_str, 0, ¶meter[parameter_size]);<br>
> > > - if (ret) {<br>
> > > - count = -EINVAL;<br>
> > > - goto fail;<br>
> > > - }<br>
> > > + if (ret)<br>
> > > + return -EINVAL;<br>
> > > parameter_size++;<br>
> > > while (isspace(*tmp_str))<br>
> > > tmp_str++;<br>
> > > }<br>
> > > }<br>
> > > parameter[parameter_size] = profile_mode;<br>
> > > +<br>
> > > + ret = pm_runtime_get_sync(ddev->dev);<br>
> > > + if (ret < 0)<br>
> > > + return ret;<br>
> > > +<br>
> > > if (is_support_sw_smu(adev))<br>
> > > ret = smu_set_power_profile_mode(&adev->smu, parameter,<br>
> > > parameter_size, true);<br>
> > > else if (adev->powerplay.pp_funcs->set_power_profile_mode)<br>
> > > ret = amdgpu_dpm_set_power_profile_mode(adev, parameter,<br>
> > > parameter_size);<br>
> > > +<br>
> > > + pm_runtime_mark_last_busy(ddev->dev);<br>
> > > + pm_runtime_put_autosuspend(ddev->dev);<br>
> > > +<br>
> > > if (!ret)<br>
> > > return count;<br>
> > > -fail:<br>
> > > +<br>
> > > return -EINVAL;<br>
> > > }<br>
> > ><br>
> > > @@ -1397,10 +1660,17 @@ static ssize_t amdgpu_get_busy_percent(struct<br>
> > > device *dev,<br>
> > > if (amdgpu_sriov_vf(adev) && !amdgpu_sriov_is_pp_one_vf(adev))<br>
> > > return 0;<br>
> > ><br>
> > > + r = pm_runtime_get_sync(ddev->dev);<br>
> > > + if (r < 0)<br>
> > > + return r;<br>
> > > +<br>
> > > /* read the IP busy sensor */<br>
> > > r = amdgpu_dpm_read_sensor(adev,<br>
> > > AMDGPU_PP_SENSOR_GPU_LOAD,<br>
> > > (void *)&value, &size);<br>
> > ><br>
> > > + pm_runtime_mark_last_busy(ddev->dev);<br>
> > > + pm_runtime_put_autosuspend(ddev->dev);<br>
> > > +<br>
> > > if (r)<br>
> > > return r;<br>
> > ><br>
> > > @@ -1426,10 +1696,17 @@ static ssize_t<br>
> > > amdgpu_get_memory_busy_percent(struct device *dev,<br>
> > > if (amdgpu_sriov_vf(adev) && !amdgpu_sriov_is_pp_one_vf(adev))<br>
> > > return 0;<br>
> > ><br>
> > > + r = pm_runtime_get_sync(ddev->dev);<br>
> > > + if (r < 0)<br>
> > > + return r;<br>
> > > +<br>
> > > /* read the IP busy sensor */<br>
> > > r = amdgpu_dpm_read_sensor(adev,<br>
> > > AMDGPU_PP_SENSOR_MEM_LOAD,<br>
> > > (void *)&value, &size);<br>
> > ><br>
> > > + pm_runtime_mark_last_busy(ddev->dev);<br>
> > > + pm_runtime_put_autosuspend(ddev->dev);<br>
> > > +<br>
> > > if (r)<br>
> > > return r;<br>
> > ><br>
> > > @@ -1455,11 +1732,20 @@ static ssize_t amdgpu_get_pcie_bw(struct<br>
> device<br>
> > > *dev,<br>
> > > struct drm_device *ddev = dev_get_drvdata(dev);<br>
> > > struct amdgpu_device *adev = ddev->dev_private;<br>
> > > uint64_t count0, count1;<br>
> > > + int ret;<br>
> > ><br>
> > > if (amdgpu_sriov_vf(adev) && !amdgpu_sriov_is_pp_one_vf(adev))<br>
> > > return 0;<br>
> > ><br>
> > > + ret = pm_runtime_get_sync(ddev->dev);<br>
> > > + if (ret < 0)<br>
> > > + return ret;<br>
> > > +<br>
> > > amdgpu_asic_get_pcie_usage(adev, &count0, &count1);<br>
> > > +<br>
> > > + pm_runtime_mark_last_busy(ddev->dev);<br>
> > > + pm_runtime_put_autosuspend(ddev->dev);<br>
> > > +<br>
> > > return snprintf(buf, PAGE_SIZE, "%llu %llu %i\n",<br>
> > > count0, count1, pcie_get_mps(adev->pdev)); } @@ -<br>
> > > 1547,42 +1833,43 @@ static ssize_t amdgpu_hwmon_show_temp(struct<br>
> device<br>
> > > *dev,<br>
> > > char *buf)<br>
> > > {<br>
> > > struct amdgpu_device *adev = dev_get_drvdata(dev);<br>
> > > - struct drm_device *ddev = adev->ddev;<br>
> > > int channel = to_sensor_dev_attr(attr)->index;<br>
> > > int r, temp = 0, size = sizeof(temp);<br>
> > ><br>
> > > - /* Can't get temperature when the card is off */<br>
> > > - if ((adev->flags & AMD_IS_PX) &&<br>
> > > - (ddev->switch_power_state != DRM_SWITCH_POWER_ON))<br>
> > > - return -EINVAL;<br>
> > > -<br>
> > > if (channel >= PP_TEMP_MAX)<br>
> > > return -EINVAL;<br>
> > ><br>
> > > + r = pm_runtime_get_sync(adev->ddev->dev);<br>
> > > + if (r < 0)<br>
> > > + return r;<br>
> > > +<br>
> > > switch (channel) {<br>
> > > case PP_TEMP_JUNCTION:<br>
> > > /* get current junction temperature */<br>
> > > r = amdgpu_dpm_read_sensor(adev,<br>
> > > AMDGPU_PP_SENSOR_HOTSPOT_TEMP,<br>
> > > (void *)&temp, &size);<br>
> > > - if (r)<br>
> > > - return r;<br>
> > > break;<br>
> > > case PP_TEMP_EDGE:<br>
> > > /* get current edge temperature */<br>
> > > r = amdgpu_dpm_read_sensor(adev,<br>
> > > AMDGPU_PP_SENSOR_EDGE_TEMP,<br>
> > > (void *)&temp, &size);<br>
> > > - if (r)<br>
> > > - return r;<br>
> > > break;<br>
> > > case PP_TEMP_MEM:<br>
> > > /* get current memory temperature */<br>
> > > r = amdgpu_dpm_read_sensor(adev,<br>
> > > AMDGPU_PP_SENSOR_MEM_TEMP,<br>
> > > (void *)&temp, &size);<br>
> > > - if (r)<br>
> > > - return r;<br>
> > > + break;<br>
> > > + default:<br>
> > > + r = -EINVAL;<br>
> > > break;<br>
> > > }<br>
> > ><br>
> > > + pm_runtime_mark_last_busy(adev->ddev->dev);<br>
> > > + pm_runtime_put_autosuspend(adev->ddev->dev);<br>
> > > +<br>
> > > + if (r)<br>
> > > + return r;<br>
> > > +<br>
> > > return snprintf(buf, PAGE_SIZE, "%d\n", temp); }<br>
> > ><br>
> > > @@ -1678,16 +1965,27 @@ static ssize_t<br>
> > > amdgpu_hwmon_get_pwm1_enable(struct device *dev, {<br>
> > > struct amdgpu_device *adev = dev_get_drvdata(dev);<br>
> > > u32 pwm_mode = 0;<br>
> > > + int ret;<br>
> > > +<br>
> > > + ret = pm_runtime_get_sync(adev->ddev->dev);<br>
> > > + if (ret < 0)<br>
> > > + return ret;<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->ddev->dev);<br>
> > > + pm_runtime_put_autosuspend(adev->ddev->dev);<br>
> > > return -EINVAL;<br>
> > > + }<br>
> > ><br>
> > > pwm_mode = amdgpu_dpm_get_fan_control_mode(adev);<br>
> > > }<br>
> > ><br>
> > > + pm_runtime_mark_last_busy(adev->ddev->dev);<br>
> > > + pm_runtime_put_autosuspend(adev->ddev->dev);<br>
> > > +<br>
> > > return sprintf(buf, "%i\n", pwm_mode); }<br>
> > ><br>
> > > @@ -1697,27 +1995,32 @@ static ssize_t<br>
> > > amdgpu_hwmon_set_pwm1_enable(struct device *dev,<br>
> > > size_t count)<br>
> > > {<br>
> > > struct amdgpu_device *adev = dev_get_drvdata(dev);<br>
> > > - int err;<br>
> > > + int err, ret;<br>
> > > int value;<br>
> > ><br>
> > > - /* Can't adjust fan when the card is off */<br>
> > > - if ((adev->flags & AMD_IS_PX) &&<br>
> > > - (adev->ddev->switch_power_state != DRM_SWITCH_POWER_ON))<br>
> > > - return -EINVAL;<br>
> > > -<br>
> > > err = kstrtoint(buf, 10, &value);<br>
> > > if (err)<br>
> > > return err;<br>
> > ><br>
> > > + ret = pm_runtime_get_sync(adev->ddev->dev);<br>
> > > + if (ret < 0)<br>
> > > + return ret;<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>
> > > + if (!adev->powerplay.pp_funcs->set_fan_control_mode) {<br>
> > > + pm_runtime_mark_last_busy(adev->ddev->dev);<br>
> > > + pm_runtime_put_autosuspend(adev->ddev->dev);<br>
> > > return -EINVAL;<br>
> > > + }<br>
> > ><br>
> > > amdgpu_dpm_set_fan_control_mode(adev, value);<br>
> > > }<br>
> > ><br>
> > > + pm_runtime_mark_last_busy(adev->ddev->dev);<br>
> > > + pm_runtime_put_autosuspend(adev->ddev->dev);<br>
> > > +<br>
> > > return count;<br>
> > > }<br>
> > ><br>
> > > @@ -1744,34 +2047,43 @@ static ssize_t<br>
> amdgpu_hwmon_set_pwm1(struct<br>
> > > device *dev,<br>
> > > u32 value;<br>
> > > u32 pwm_mode;<br>
> > ><br>
> > > - /* Can't adjust fan when the card is off */<br>
> > > - if ((adev->flags & AMD_IS_PX) &&<br>
> > > - (adev->ddev->switch_power_state != DRM_SWITCH_POWER_ON))<br>
> > > - return -EINVAL;<br>
> > > + err = pm_runtime_get_sync(adev->ddev->dev);<br>
> > > + if (err < 0)<br>
> > > + return err;<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>
> > > 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->ddev->dev);<br>
> > > + pm_runtime_put_autosuspend(adev->ddev->dev);<br>
> > > return -EINVAL;<br>
> > > }<br>
> > ><br>
> > > err = kstrtou32(buf, 10, &value);<br>
> > > - if (err)<br>
> > > + if (err) {<br>
> > > + pm_runtime_mark_last_busy(adev->ddev->dev);<br>
> > > + pm_runtime_put_autosuspend(adev->ddev->dev);<br>
> > > return err;<br>
> > > + }<br>
> > ><br>
> > > value = (value * 100) / 255;<br>
> > ><br>
> > > - if (is_support_sw_smu(adev)) {<br>
> > > + if (is_support_sw_smu(adev))<br>
> > > err = smu_set_fan_speed_percent(&adev->smu, value);<br>
> > > - if (err)<br>
> > > - return err;<br>
> > > - } else if (adev->powerplay.pp_funcs->set_fan_speed_percent) {<br>
> > > + else if (adev->powerplay.pp_funcs->set_fan_speed_percent)<br>
> > > err = amdgpu_dpm_set_fan_speed_percent(adev, value);<br>
> > > - if (err)<br>
> > > - return err;<br>
> > > - }<br>
> > > + else<br>
> > > + err = -EINVAL;<br>
> > > +<br>
> > > + pm_runtime_mark_last_busy(adev->ddev->dev);<br>
> > > + pm_runtime_put_autosuspend(adev->ddev->dev);<br>
> > > +<br>
> > > + if (err)<br>
> > > + return err;<br>
> > ><br>
> > > return count;<br>
> > > }<br>
> > > @@ -1784,20 +2096,22 @@ static ssize_t<br>
> amdgpu_hwmon_get_pwm1(struct<br>
> > > device *dev,<br>
> > > int err;<br>
> > > u32 speed = 0;<br>
> > ><br>
> > > - /* Can't adjust fan when the card is off */<br>
> > > - if ((adev->flags & AMD_IS_PX) &&<br>
> > > - (adev->ddev->switch_power_state != DRM_SWITCH_POWER_ON))<br>
> > > - return -EINVAL;<br>
> > > + err = pm_runtime_get_sync(adev->ddev->dev);<br>
> > > + if (err < 0)<br>
> > > + return err;<br>
> > ><br>
> > > - if (is_support_sw_smu(adev)) {<br>
> > > + if (is_support_sw_smu(adev))<br>
> > > err = smu_get_fan_speed_percent(&adev->smu, &speed);<br>
> > > - if (err)<br>
> > > - return err;<br>
> > > - } else if (adev->powerplay.pp_funcs->get_fan_speed_percent) {<br>
> > > + else if (adev->powerplay.pp_funcs->get_fan_speed_percent)<br>
> > > err = amdgpu_dpm_get_fan_speed_percent(adev, &speed);<br>
> > > - if (err)<br>
> > > - return err;<br>
> > > - }<br>
> > > + else<br>
> > > + err = -EINVAL;<br>
> > > +<br>
> > > + pm_runtime_mark_last_busy(adev->ddev->dev);<br>
> > > + pm_runtime_put_autosuspend(adev->ddev->dev);<br>
> > > +<br>
> > > + if (err)<br>
> > > + return err;<br>
> > ><br>
> > > speed = (speed * 255) / 100;<br>
> > ><br>
> > > @@ -1812,20 +2126,22 @@ static ssize_t<br>
> > > amdgpu_hwmon_get_fan1_input(struct device *dev,<br>
> > > int err;<br>
> > > u32 speed = 0;<br>
> > ><br>
> > > - /* Can't adjust fan when the card is off */<br>
> > > - if ((adev->flags & AMD_IS_PX) &&<br>
> > > - (adev->ddev->switch_power_state != DRM_SWITCH_POWER_ON))<br>
> > > - return -EINVAL;<br>
> > > + err = pm_runtime_get_sync(adev->ddev->dev);<br>
> > > + if (err < 0)<br>
> > > + return err;<br>
> > ><br>
> > > - if (is_support_sw_smu(adev)) {<br>
> > > + if (is_support_sw_smu(adev))<br>
> > > err = smu_get_fan_speed_rpm(&adev->smu, &speed);<br>
> > > - if (err)<br>
> > > - return err;<br>
> > > - } else if (adev->powerplay.pp_funcs->get_fan_speed_rpm) {<br>
> > > + else if (adev->powerplay.pp_funcs->get_fan_speed_rpm)<br>
> > > err = amdgpu_dpm_get_fan_speed_rpm(adev, &speed);<br>
> > > - if (err)<br>
> > > - return err;<br>
> > > - }<br>
> > > + else<br>
> > > + err = -EINVAL;<br>
> > > +<br>
> > > + pm_runtime_mark_last_busy(adev->ddev->dev);<br>
> > > + pm_runtime_put_autosuspend(adev->ddev->dev);<br>
> > > +<br>
> > > + if (err)<br>
> > > + return err;<br>
> > ><br>
> > > return sprintf(buf, "%i\n", speed);<br>
> > > }<br>
> > > @@ -1839,8 +2155,16 @@ static ssize_t<br>
> amdgpu_hwmon_get_fan1_min(struct<br>
> > > device *dev,<br>
> > > u32 size = sizeof(min_rpm);<br>
> > > int r;<br>
> > ><br>
> > > + r = pm_runtime_get_sync(adev->ddev->dev);<br>
> > > + if (r < 0)<br>
> > > + return r;<br>
> > > +<br>
> > > r = amdgpu_dpm_read_sensor(adev,<br>
> > > AMDGPU_PP_SENSOR_MIN_FAN_RPM,<br>
> > > (void *)&min_rpm, &size);<br>
> > > +<br>
> > > + pm_runtime_mark_last_busy(adev->ddev->dev);<br>
> > > + pm_runtime_put_autosuspend(adev->ddev->dev);<br>
> > > +<br>
> > > if (r)<br>
> > > return r;<br>
> > ><br>
> > > @@ -1856,8 +2180,16 @@ static ssize_t<br>
> > > amdgpu_hwmon_get_fan1_max(struct device *dev,<br>
> > > u32 size = sizeof(max_rpm);<br>
> > > int r;<br>
> > ><br>
> > > + r = pm_runtime_get_sync(adev->ddev->dev);<br>
> > > + if (r < 0)<br>
> > > + return r;<br>
> > > +<br>
> > > r = amdgpu_dpm_read_sensor(adev,<br>
> > > AMDGPU_PP_SENSOR_MAX_FAN_RPM,<br>
> > > (void *)&max_rpm, &size);<br>
> > > +<br>
> > > + pm_runtime_mark_last_busy(adev->ddev->dev);<br>
> > > + pm_runtime_put_autosuspend(adev->ddev->dev);<br>
> > > +<br>
> > > if (r)<br>
> > > return r;<br>
> > ><br>
> > > @@ -1872,20 +2204,22 @@ static ssize_t<br>
> > > amdgpu_hwmon_get_fan1_target(struct device *dev,<br>
> > > int err;<br>
> > > u32 rpm = 0;<br>
> > ><br>
> > > - /* Can't adjust fan when the card is off */<br>
> > > - if ((adev->flags & AMD_IS_PX) &&<br>
> > > - (adev->ddev->switch_power_state != DRM_SWITCH_POWER_ON))<br>
> > > - return -EINVAL;<br>
> > > + err = pm_runtime_get_sync(adev->ddev->dev);<br>
> > > + if (err < 0)<br>
> > > + return err;<br>
> > ><br>
> > > - if (is_support_sw_smu(adev)) {<br>
> > > + if (is_support_sw_smu(adev))<br>
> > > err = smu_get_fan_speed_rpm(&adev->smu, &rpm);<br>
> > > - if (err)<br>
> > > - return err;<br>
> > > - } else if (adev->powerplay.pp_funcs->get_fan_speed_rpm) {<br>
> > > + else if (adev->powerplay.pp_funcs->get_fan_speed_rpm)<br>
> > > err = amdgpu_dpm_get_fan_speed_rpm(adev, &rpm);<br>
> > > - if (err)<br>
> > > - return err;<br>
> > > - }<br>
> > > + else<br>
> > > + err = -EINVAL;<br>
> > > +<br>
> > > + pm_runtime_mark_last_busy(adev->ddev->dev);<br>
> > > + pm_runtime_put_autosuspend(adev->ddev->dev);<br>
> > > +<br>
> > > + if (err)<br>
> > > + return err;<br>
> > ><br>
> > > return sprintf(buf, "%i\n", rpm);<br>
> > > }<br>
> > > @@ -1899,32 +2233,40 @@ static ssize_t<br>
> > > amdgpu_hwmon_set_fan1_target(struct device *dev,<br>
> > > u32 value;<br>
> > > u32 pwm_mode;<br>
> > ><br>
> > > + err = pm_runtime_get_sync(adev->ddev->dev);<br>
> > > + if (err < 0)<br>
> > > + return err;<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>
> > > - if (pwm_mode != AMD_FAN_CTRL_MANUAL)<br>
> > > + if (pwm_mode != AMD_FAN_CTRL_MANUAL) {<br>
> > > + pm_runtime_mark_last_busy(adev->ddev->dev);<br>
> > > + pm_runtime_put_autosuspend(adev->ddev->dev);<br>
> > > return -ENODATA;<br>
> > > -<br>
> > > - /* Can't adjust fan when the card is off */<br>
> > > - if ((adev->flags & AMD_IS_PX) &&<br>
> > > - (adev->ddev->switch_power_state != DRM_SWITCH_POWER_ON))<br>
> > > - return -EINVAL;<br>
> > > + }<br>
> > ><br>
> > > err = kstrtou32(buf, 10, &value);<br>
> > > - if (err)<br>
> > > + if (err) {<br>
> > > + pm_runtime_mark_last_busy(adev->ddev->dev);<br>
> > > + pm_runtime_put_autosuspend(adev->ddev->dev);<br>
> > > return err;<br>
> > > + }<br>
> > ><br>
> > > - if (is_support_sw_smu(adev)) {<br>
> > > + if (is_support_sw_smu(adev))<br>
> > > err = smu_set_fan_speed_rpm(&adev->smu, value);<br>
> > > - if (err)<br>
> > > - return err;<br>
> > > - } else if (adev->powerplay.pp_funcs->set_fan_speed_rpm) {<br>
> > > + else if (adev->powerplay.pp_funcs->set_fan_speed_rpm)<br>
> > > err = amdgpu_dpm_set_fan_speed_rpm(adev, value);<br>
> > > - if (err)<br>
> > > - return err;<br>
> > > - }<br>
> > > + else<br>
> > > + err = -EINVAL;<br>
> > > +<br>
> > > + pm_runtime_mark_last_busy(adev->ddev->dev);<br>
> > > + pm_runtime_put_autosuspend(adev->ddev->dev);<br>
> > > +<br>
> > > + if (err)<br>
> > > + return err;<br>
> > ><br>
> > > return count;<br>
> > > }<br>
> > > @@ -1935,15 +2277,27 @@ static ssize_t<br>
> > > amdgpu_hwmon_get_fan1_enable(struct device *dev, {<br>
> > > struct amdgpu_device *adev = dev_get_drvdata(dev);<br>
> > > u32 pwm_mode = 0;<br>
> > > + int ret;<br>
> > > +<br>
> > > + ret = pm_runtime_get_sync(adev->ddev->dev);<br>
> > > + if (ret < 0)<br>
> > > + return ret;<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->ddev->dev);<br>
> > > + pm_runtime_put_autosuspend(adev->ddev->dev);<br>
> > > return -EINVAL;<br>
> > > + }<br>
> > ><br>
> > > pwm_mode = amdgpu_dpm_get_fan_control_mode(adev);<br>
> > > }<br>
> > > +<br>
> > > + pm_runtime_mark_last_busy(adev->ddev->dev);<br>
> > > + pm_runtime_put_autosuspend(adev->ddev->dev);<br>
> > > +<br>
> > > return sprintf(buf, "%i\n", pwm_mode == AMD_FAN_CTRL_AUTO ? 0 :<br>
> > > 1); }<br>
> > ><br>
> > > @@ -1957,12 +2311,6 @@ static ssize_t<br>
> > > amdgpu_hwmon_set_fan1_enable(struct device *dev,<br>
> > > int value;<br>
> > > u32 pwm_mode;<br>
> > ><br>
> > > - /* Can't adjust fan when the card is off */<br>
> > > - if ((adev->flags & AMD_IS_PX) &&<br>
> > > - (adev->ddev->switch_power_state != DRM_SWITCH_POWER_ON))<br>
> > > - return -EINVAL;<br>
> > > -<br>
> > > -<br>
> > > err = kstrtoint(buf, 10, &value);<br>
> > > if (err)<br>
> > > return err;<br>
> > > @@ -1974,14 +2322,24 @@ static ssize_t<br>
> > > amdgpu_hwmon_set_fan1_enable(struct device *dev,<br>
> > > else<br>
> > > return -EINVAL;<br>
> > ><br>
> > > + err = pm_runtime_get_sync(adev->ddev->dev);<br>
> > > + if (err < 0)<br>
> > > + return err;<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>
> > > + if (!adev->powerplay.pp_funcs->set_fan_control_mode) {<br>
> > > + pm_runtime_mark_last_busy(adev->ddev->dev);<br>
> > > + pm_runtime_put_autosuspend(adev->ddev->dev);<br>
> > > return -EINVAL;<br>
> > > + }<br>
> > > amdgpu_dpm_set_fan_control_mode(adev, pwm_mode);<br>
> > > }<br>
> > ><br>
> > > + pm_runtime_mark_last_busy(adev->ddev->dev);<br>
> > > + pm_runtime_put_autosuspend(adev->ddev->dev);<br>
> > > +<br>
> > > return count;<br>
> > > }<br>
> > ><br>
> > > @@ -1990,18 +2348,20 @@ static ssize_t<br>
> amdgpu_hwmon_show_vddgfx(struct<br>
> > > device *dev,<br>
> > > char *buf)<br>
> > > {<br>
> > > struct amdgpu_device *adev = dev_get_drvdata(dev);<br>
> > > - struct drm_device *ddev = adev->ddev;<br>
> > > u32 vddgfx;<br>
> > > int r, size = sizeof(vddgfx);<br>
> > ><br>
> > > - /* Can't get voltage when the card is off */<br>
> > > - if ((adev->flags & AMD_IS_PX) &&<br>
> > > - (ddev->switch_power_state != DRM_SWITCH_POWER_ON))<br>
> > > - return -EINVAL;<br>
> > > + r = pm_runtime_get_sync(adev->ddev->dev);<br>
> > > + if (r < 0)<br>
> > > + return r;<br>
> > ><br>
> > > /* get the voltage */<br>
> > > r = amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_VDDGFX,<br>
> > > (void *)&vddgfx, &size);<br>
> > > +<br>
> > > + pm_runtime_mark_last_busy(adev->ddev->dev);<br>
> > > + pm_runtime_put_autosuspend(adev->ddev->dev);<br>
> > > +<br>
> > > if (r)<br>
> > > return r;<br>
> > ><br>
> > > @@ -2020,7 +2380,6 @@ static ssize_t<br>
> amdgpu_hwmon_show_vddnb(struct<br>
> > > device *dev,<br>
> > > char *buf)<br>
> > > {<br>
> > > struct amdgpu_device *adev = dev_get_drvdata(dev);<br>
> > > - struct drm_device *ddev = adev->ddev;<br>
> > > u32 vddnb;<br>
> > > int r, size = sizeof(vddnb);<br>
> > ><br>
> > > @@ -2028,14 +2387,17 @@ static ssize_t<br>
> amdgpu_hwmon_show_vddnb(struct<br>
> > > device *dev,<br>
> > > if (!(adev->flags & AMD_IS_APU))<br>
> > > return -EINVAL;<br>
> > ><br>
> > > - /* Can't get voltage when the card is off */<br>
> > > - if ((adev->flags & AMD_IS_PX) &&<br>
> > > - (ddev->switch_power_state != DRM_SWITCH_POWER_ON))<br>
> > > - return -EINVAL;<br>
> > > + r = pm_runtime_get_sync(adev->ddev->dev);<br>
> > > + if (r < 0)<br>
> > > + return r;<br>
> > ><br>
> > > /* get the voltage */<br>
> > > r = amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_VDDNB,<br>
> > > (void *)&vddnb, &size);<br>
> > > +<br>
> > > + pm_runtime_mark_last_busy(adev->ddev->dev);<br>
> > > + pm_runtime_put_autosuspend(adev->ddev->dev);<br>
> > > +<br>
> > > if (r)<br>
> > > return r;<br>
> > ><br>
> > > @@ -2054,19 +2416,21 @@ static ssize_t<br>
> > > amdgpu_hwmon_show_power_avg(struct device *dev,<br>
> > > char *buf)<br>
> > > {<br>
> > > struct amdgpu_device *adev = dev_get_drvdata(dev);<br>
> > > - struct drm_device *ddev = adev->ddev;<br>
> > > u32 query = 0;<br>
> > > int r, size = sizeof(u32);<br>
> > > unsigned uw;<br>
> > ><br>
> > > - /* Can't get power when the card is off */<br>
> > > - if ((adev->flags & AMD_IS_PX) &&<br>
> > > - (ddev->switch_power_state != DRM_SWITCH_POWER_ON))<br>
> > > - return -EINVAL;<br>
> > > + r = pm_runtime_get_sync(adev->ddev->dev);<br>
> > > + if (r < 0)<br>
> > > + return r;<br>
> > ><br>
> > > /* get the voltage */<br>
> > > r = amdgpu_dpm_read_sensor(adev,<br>
> > > AMDGPU_PP_SENSOR_GPU_POWER,<br>
> > > (void *)&query, &size);<br>
> > > +<br>
> > > + pm_runtime_mark_last_busy(adev->ddev->dev);<br>
> > > + pm_runtime_put_autosuspend(adev->ddev->dev);<br>
> > > +<br>
> > > if (r)<br>
> > > return r;<br>
> > ><br>
> > > @@ -2089,16 +2453,27 @@ static ssize_t<br>
> > > amdgpu_hwmon_show_power_cap_max(struct device *dev, {<br>
> > > struct amdgpu_device *adev = dev_get_drvdata(dev);<br>
> > > uint32_t limit = 0;<br>
> > > + ssize_t size;<br>
> > > + int r;<br>
> > > +<br>
> > > + r = pm_runtime_get_sync(adev->ddev->dev);<br>
> > > + if (r < 0)<br>
> > > + return r;<br>
> > ><br>
> > > if (is_support_sw_smu(adev)) {<br>
> > > smu_get_power_limit(&adev->smu, &limit, true, true);<br>
> > > - return snprintf(buf, PAGE_SIZE, "%u\n", limit * 1000000);<br>
> > > + size = snprintf(buf, PAGE_SIZE, "%u\n", limit * 1000000);<br>
> > > } else if (adev->powerplay.pp_funcs && adev->powerplay.pp_funcs-<br>
> > > >get_power_limit) {<br>
> > > adev->powerplay.pp_funcs->get_power_limit(adev-<br>
> > > >powerplay.pp_handle, &limit, true);<br>
> > > - return snprintf(buf, PAGE_SIZE, "%u\n", limit * 1000000);<br>
> > > + size = snprintf(buf, PAGE_SIZE, "%u\n", limit * 1000000);<br>
> > > } else {<br>
> > > - return snprintf(buf, PAGE_SIZE, "\n");<br>
> > > + size = snprintf(buf, PAGE_SIZE, "\n");<br>
> > > }<br>
> > > +<br>
> > > + pm_runtime_mark_last_busy(adev->ddev->dev);<br>
> > > + pm_runtime_put_autosuspend(adev->ddev->dev);<br>
> > > +<br>
> > > + return size;<br>
> > > }<br>
> > ><br>
> > > static ssize_t amdgpu_hwmon_show_power_cap(struct device *dev, @@ -<br>
> > > 2107,16 +2482,27 @@ static ssize_t<br>
> amdgpu_hwmon_show_power_cap(struct<br>
> > > device *dev, {<br>
> > > struct amdgpu_device *adev = dev_get_drvdata(dev);<br>
> > > uint32_t limit = 0;<br>
> > > + ssize_t size;<br>
> > > + int r;<br>
> > > +<br>
> > > + r = pm_runtime_get_sync(adev->ddev->dev);<br>
> > > + if (r < 0)<br>
> > > + return r;<br>
> > ><br>
> > > if (is_support_sw_smu(adev)) {<br>
> > > smu_get_power_limit(&adev->smu, &limit, false, true);<br>
> > > - return snprintf(buf, PAGE_SIZE, "%u\n", limit * 1000000);<br>
> > > + size = snprintf(buf, PAGE_SIZE, "%u\n", limit * 1000000);<br>
> > > } else if (adev->powerplay.pp_funcs && adev->powerplay.pp_funcs-<br>
> > > >get_power_limit) {<br>
> > > adev->powerplay.pp_funcs->get_power_limit(adev-<br>
> > > >powerplay.pp_handle, &limit, false);<br>
> > > - return snprintf(buf, PAGE_SIZE, "%u\n", limit * 1000000);<br>
> > > + size = snprintf(buf, PAGE_SIZE, "%u\n", limit * 1000000);<br>
> > > } else {<br>
> > > - return snprintf(buf, PAGE_SIZE, "\n");<br>
> > > + size = snprintf(buf, PAGE_SIZE, "\n");<br>
> > > }<br>
> > > +<br>
> > > + pm_runtime_mark_last_busy(adev->ddev->dev);<br>
> > > + pm_runtime_put_autosuspend(adev->ddev->dev);<br>
> > > +<br>
> > > + return size;<br>
> > > }<br>
> > ><br>
> > ><br>
> > > @@ -2138,13 +2524,20 @@ static ssize_t<br>
> > > amdgpu_hwmon_set_power_cap(struct device *dev,<br>
> > ><br>
> > > value = value / 1000000; /* convert to Watt */<br>
> > ><br>
> > > - if (is_support_sw_smu(adev)) {<br>
> > > +<br>
> > > + err = pm_runtime_get_sync(adev->ddev->dev);<br>
> > > + if (err < 0)<br>
> > > + return err;<br>
> > > +<br>
> > > + if (is_support_sw_smu(adev))<br>
> > > err = smu_set_power_limit(&adev->smu, value);<br>
> > > - } else if (adev->powerplay.pp_funcs && adev->powerplay.pp_funcs-<br>
> > > >set_power_limit) {<br>
> > > + else if (adev->powerplay.pp_funcs &&<br>
> > > +adev->powerplay.pp_funcs->set_power_limit)<br>
> > > err = adev->powerplay.pp_funcs->set_power_limit(adev-<br>
> > > >powerplay.pp_handle, value);<br>
> > > - } else {<br>
> > > + else<br>
> > > err = -EINVAL;<br>
> > > - }<br>
> > > +<br>
> > > + pm_runtime_mark_last_busy(adev->ddev->dev);<br>
> > > + pm_runtime_put_autosuspend(adev->ddev->dev);<br>
> > ><br>
> > > if (err)<br>
> > > return err;<br>
> > > @@ -2157,18 +2550,20 @@ static ssize_t<br>
> amdgpu_hwmon_show_sclk(struct<br>
> > > device *dev,<br>
> > > char *buf)<br>
> > > {<br>
> > > struct amdgpu_device *adev = dev_get_drvdata(dev);<br>
> > > - struct drm_device *ddev = adev->ddev;<br>
> > > uint32_t sclk;<br>
> > > int r, size = sizeof(sclk);<br>
> > ><br>
> > > - /* Can't get voltage when the card is off */<br>
> > > - if ((adev->flags & AMD_IS_PX) &&<br>
> > > - (ddev->switch_power_state != DRM_SWITCH_POWER_ON))<br>
> > > - return -EINVAL;<br>
> > > + r = pm_runtime_get_sync(adev->ddev->dev);<br>
> > > + if (r < 0)<br>
> > > + return r;<br>
> > ><br>
> > > /* get the sclk */<br>
> > > r = amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_GFX_SCLK,<br>
> > > (void *)&sclk, &size);<br>
> > > +<br>
> > > + pm_runtime_mark_last_busy(adev->ddev->dev);<br>
> > > + pm_runtime_put_autosuspend(adev->ddev->dev);<br>
> > > +<br>
> > > if (r)<br>
> > > return r;<br>
> > ><br>
> > > @@ -2187,18 +2582,20 @@ static ssize_t<br>
> amdgpu_hwmon_show_mclk(struct<br>
> > > device *dev,<br>
> > > char *buf)<br>
> > > {<br>
> > > struct amdgpu_device *adev = dev_get_drvdata(dev);<br>
> > > - struct drm_device *ddev = adev->ddev;<br>
> > > uint32_t mclk;<br>
> > > int r, size = sizeof(mclk);<br>
> > ><br>
> > > - /* Can't get voltage when the card is off */<br>
> > > - if ((adev->flags & AMD_IS_PX) &&<br>
> > > - (ddev->switch_power_state != DRM_SWITCH_POWER_ON))<br>
> > > - return -EINVAL;<br>
> > > + r = pm_runtime_get_sync(adev->ddev->dev);<br>
> > > + if (r < 0)<br>
> > > + return r;<br>
> > ><br>
> > > /* get the sclk */<br>
> > > r = amdgpu_dpm_read_sensor(adev,<br>
> > > AMDGPU_PP_SENSOR_GFX_MCLK,<br>
> > > (void *)&mclk, &size);<br>
> > > +<br>
> > > + pm_runtime_mark_last_busy(adev->ddev->dev);<br>
> > > + pm_runtime_put_autosuspend(adev->ddev->dev);<br>
> > > +<br>
> > > if (r)<br>
> > > return r;<br>
> > ><br>
> > > @@ -3220,8 +3617,12 @@ static int amdgpu_debugfs_pm_info(struct<br>
> seq_file<br>
> > > *m, void *data)<br>
> > > struct drm_info_node *node = (struct drm_info_node *) m->private;<br>
> > > struct drm_device *dev = node->minor->dev;<br>
> > > struct amdgpu_device *adev = dev->dev_private;<br>
> > > - struct drm_device *ddev = adev->ddev;<br>
> > > u32 flags = 0;<br>
> > > + int r;<br>
> > > +<br>
> > > + r = pm_runtime_get_sync(dev->dev);<br>
> > > + if (r < 0)<br>
> > > + return r;<br>
> > ><br>
> > > amdgpu_device_ip_get_clockgating_state(adev, &flags);<br>
> > > seq_printf(m, "Clock Gating Flags Mask: 0x%x\n", flags); @@ -3230,23<br>
> > > +3631,28 @@ static int amdgpu_debugfs_pm_info(struct seq_file *m, void<br>
> > > *data)<br>
> > ><br>
> > > if (!adev->pm.dpm_enabled) {<br>
> > > seq_printf(m, "dpm not enabled\n");<br>
> > > + pm_runtime_mark_last_busy(dev->dev);<br>
> > > + pm_runtime_put_autosuspend(dev->dev);<br>
> > > return 0;<br>
> > > }<br>
> > > - if ((adev->flags & AMD_IS_PX) &&<br>
> > > - (ddev->switch_power_state != DRM_SWITCH_POWER_ON)) {<br>
> > > - seq_printf(m, "PX asic powered off\n");<br>
> > > - } else if (!is_support_sw_smu(adev) && adev->powerplay.pp_funcs-<br>
> > > >debugfs_print_current_performance_level) {<br>
> > > +<br>
> > > + if (!is_support_sw_smu(adev) &&<br>
> > > + adev->powerplay.pp_funcs-<br>
> > > >debugfs_print_current_performance_level)<br>
> > > +{<br>
> > > mutex_lock(&adev->pm.mutex);<br>
> > > if (adev->powerplay.pp_funcs-<br>
> > > >debugfs_print_current_performance_level)<br>
> > > adev->powerplay.pp_funcs-<br>
> > > >debugfs_print_current_performance_level(adev, m);<br>
> > > else<br>
> > > seq_printf(m, "Debugfs support not implemented for<br>
> > > this asic\n");<br>
> > > mutex_unlock(&adev->pm.mutex);<br>
> > > + r = 0;<br>
> > > } else {<br>
> > > - return amdgpu_debugfs_pm_info_pp(m, adev);<br>
> > > + r = amdgpu_debugfs_pm_info_pp(m, adev);<br>
> > > }<br>
> > ><br>
> > > - return 0;<br>
> > > + pm_runtime_mark_last_busy(dev->dev);<br>
> > > + pm_runtime_put_autosuspend(dev->dev);<br>
> > > +<br>
> > > + return r;<br>
> > > }<br>
> > ><br>
> > > static const struct drm_info_list amdgpu_pm_info_list[] = {<br>
> > > --<br>
> > > 2.24.1<br>
> > ><br>
> > > _______________________________________________<br>
> > > amd-gfx mailing list<br>
> > > amd-gfx@lists.freedesktop.org<br>
> > ><br>
> <a href="https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.free">
https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.free</a><br>
> > > desktop.org%2Fmailman%2Flistinfo%2Famd-<br>
> > ><br>
> gfx&data=02%7C01%7Cevan.quan%40amd.com%7C238a3b3424e54410d5<br>
> > ><br>
> 4b08d796272999%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637<br>
> > ><br>
> 142967374684544&sdata=oFtEwMdJl2KVMiwz9y5GBcwwheE%2FKeg80C4<br>
> > > LqfjZf08%3D&reserved=0<br>
</div>
</span></font></div>
</body>
</html>