drm/amd/powerplay: implement sysfs of pp_cur_state function
authorKevin Wang <Kevin1.Wang@amd.com>
Thu, 17 Jan 2019 05:29:06 +0000 (13:29 +0800)
committerAlex Deucher <alexander.deucher@amd.com>
Tue, 19 Mar 2019 20:03:58 +0000 (15:03 -0500)
add function of smu_get_currente_state for sw-smu.

v2: fix code typo error if (ret);

Signed-off-by: Kevin Wang <Kevin1.Wang@amd.com>
Reviewed-by: Huang Rui <ray.huang@amd.com>
Acked-by: Alex Deucher <alexander.deucher@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c
drivers/gpu/drm/amd/powerplay/amdgpu_smu.c
drivers/gpu/drm/amd/powerplay/inc/amdgpu_smu.h

index 5eda007..569f7be 100644 (file)
@@ -377,23 +377,29 @@ static ssize_t amdgpu_get_pp_cur_state(struct device *dev,
        struct drm_device *ddev = dev_get_drvdata(dev);
        struct amdgpu_device *adev = ddev->dev_private;
        struct pp_states_info data;
+       struct smu_context *smu = &adev->smu;
        enum amd_pm_state_type pm = 0;
-       int i = 0;
+       int i = 0, ret = 0;
 
-       if (adev->powerplay.pp_funcs->get_current_power_state
+       if (is_support_sw_smu(adev)) {
+               pm = smu_get_current_power_state(smu);
+               ret = smu_get_power_num_states(smu, &data);
+               if (ret)
+                       return ret;
+       } else if (adev->powerplay.pp_funcs->get_current_power_state
                 && adev->powerplay.pp_funcs->get_pp_num_states) {
                pm = amdgpu_dpm_get_current_power_state(adev);
                amdgpu_dpm_get_pp_num_states(adev, &data);
+       }
 
-               for (i = 0; i < data.nums; i++) {
-                       if (pm == data.states[i])
-                               break;
-               }
-
-               if (i == data.nums)
-                       i = -EINVAL;
+       for (i = 0; i < data.nums; i++) {
+               if (pm == data.states[i])
+                       break;
        }
 
+       if (i == data.nums)
+               i = -EINVAL;
+
        return snprintf(buf, PAGE_SIZE, "%d\n", i);
 }
 
index b4d6046..dc431f2 100644 (file)
 #include "smu_v11_0.h"
 #include "atom.h"
 
+enum amd_pm_state_type smu_get_current_power_state(struct smu_context *smu)
+{
+       /* not support power state */
+       return POWER_STATE_TYPE_DEFAULT;
+}
+
 int smu_get_power_num_states(struct smu_context *smu,
                             struct pp_states_info *state_info)
 {
index 4498059..085575c 100644 (file)
@@ -382,5 +382,6 @@ int smu_common_read_sensor(struct smu_context *smu, enum amd_pp_sensors sensor,
 int smu_sys_get_pp_table(struct smu_context *smu, void **table);
 int smu_sys_set_pp_table(struct smu_context *smu,  void *buf, size_t size);
 int smu_get_power_num_states(struct smu_context *smu, struct pp_states_info *state_info);
+enum amd_pm_state_type smu_get_current_power_state(struct smu_context *smu);
 
 #endif