amdgpu not care powerplay or dpm is enabled.
just check ip functions and pp functions

Change-Id: I972700055e2ee4655ac1b24fe7ff2dacdaf49979
Signed-off-by: Rex Zhu <[email protected]>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu.h           |  1 -
 drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c        | 77 ++++++++++++---------------
 drivers/gpu/drm/amd/amdgpu/amdgpu_powerplay.c |  7 +--
 drivers/gpu/drm/amd/powerplay/amd_powerplay.c | 18 ++++++-
 4 files changed, 53 insertions(+), 50 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu.h 
b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
index a5b0b67..518ba7c 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
@@ -1529,7 +1529,6 @@ struct amdgpu_device {
 
        /* powerplay */
        struct amd_powerplay            powerplay;
-       bool                            pp_enabled;
        bool                            pp_force_state_enabled;
 
        /* dpm */
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c
index 723fc16..f3b23f9 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c
@@ -64,10 +64,6 @@
 
 void amdgpu_pm_acpi_event_handler(struct amdgpu_device *adev)
 {
-       if (adev->pp_enabled)
-               /* TODO */
-               return;
-
        if (adev->pm.dpm_enabled) {
                mutex_lock(&adev->pm.mutex);
                if (power_supply_is_system_supplied() > 0)
@@ -118,7 +114,7 @@ static ssize_t amdgpu_set_dpm_state(struct device *dev,
                goto fail;
        }
 
-       if (adev->pp_enabled) {
+       if (adev->powerplay.pp_funcs->dispatch_tasks) {
                amdgpu_dpm_dispatch_task(adev, AMD_PP_TASK_ENABLE_USER_STATE, 
&state, NULL);
        } else {
                mutex_lock(&adev->pm.mutex);
@@ -303,7 +299,8 @@ static ssize_t amdgpu_set_pp_force_state(struct device *dev,
 
        if (strlen(buf) == 1)
                adev->pp_force_state_enabled = false;
-       else if (adev->pp_enabled) {
+       else if (adev->powerplay.pp_funcs->dispatch_tasks &&
+                       adev->powerplay.pp_funcs->get_pp_num_states) {
                struct pp_states_info data;
 
                ret = kstrtoul(buf, 0, &idx);
@@ -531,7 +528,7 @@ static ssize_t amdgpu_set_pp_sclk_od(struct device *dev,
        if (adev->powerplay.pp_funcs->set_sclk_od)
                amdgpu_dpm_set_sclk_od(adev, (uint32_t)value);
 
-       if (adev->pp_enabled) {
+       if (adev->powerplay.pp_funcs->dispatch_tasks) {
                amdgpu_dpm_dispatch_task(adev, 
AMD_PP_TASK_READJUST_POWER_STATE, NULL, NULL);
        } else {
                adev->pm.dpm.current_ps = adev->pm.dpm.boot_ps;
@@ -575,7 +572,7 @@ static ssize_t amdgpu_set_pp_mclk_od(struct device *dev,
        if (adev->powerplay.pp_funcs->set_mclk_od)
                amdgpu_dpm_set_mclk_od(adev, (uint32_t)value);
 
-       if (adev->pp_enabled) {
+       if (adev->powerplay.pp_funcs->dispatch_tasks) {
                amdgpu_dpm_dispatch_task(adev, 
AMD_PP_TASK_READJUST_POWER_STATE, NULL, NULL);
        } else {
                adev->pm.dpm.current_ps = adev->pm.dpm.boot_ps;
@@ -959,9 +956,6 @@ static umode_t hwmon_attributes_visible(struct kobject 
*kobj,
             attr == &sensor_dev_attr_pwm1_min.dev_attr.attr))
                return 0;
 
-       if (adev->pp_enabled)
-               return effective_mode;
-
        /* Skip fan attributes if fan is not present */
        if (adev->pm.no_fan &&
            (attr == &sensor_dev_attr_pwm1.dev_attr.attr ||
@@ -1343,27 +1337,26 @@ int amdgpu_pm_sysfs_init(struct amdgpu_device *adev)
                return ret;
        }
 
-       if (adev->pp_enabled) {
-               ret = device_create_file(adev->dev, &dev_attr_pp_num_states);
-               if (ret) {
-                       DRM_ERROR("failed to create device file 
pp_num_states\n");
-                       return ret;
-               }
-               ret = device_create_file(adev->dev, &dev_attr_pp_cur_state);
-               if (ret) {
-                       DRM_ERROR("failed to create device file 
pp_cur_state\n");
-                       return ret;
-               }
-               ret = device_create_file(adev->dev, &dev_attr_pp_force_state);
-               if (ret) {
-                       DRM_ERROR("failed to create device file 
pp_force_state\n");
-                       return ret;
-               }
-               ret = device_create_file(adev->dev, &dev_attr_pp_table);
-               if (ret) {
-                       DRM_ERROR("failed to create device file pp_table\n");
-                       return ret;
-               }
+
+       ret = device_create_file(adev->dev, &dev_attr_pp_num_states);
+       if (ret) {
+               DRM_ERROR("failed to create device file pp_num_states\n");
+               return ret;
+       }
+       ret = device_create_file(adev->dev, &dev_attr_pp_cur_state);
+       if (ret) {
+               DRM_ERROR("failed to create device file pp_cur_state\n");
+               return ret;
+       }
+       ret = device_create_file(adev->dev, &dev_attr_pp_force_state);
+       if (ret) {
+               DRM_ERROR("failed to create device file pp_force_state\n");
+               return ret;
+       }
+       ret = device_create_file(adev->dev, &dev_attr_pp_table);
+       if (ret) {
+               DRM_ERROR("failed to create device file pp_table\n");
+               return ret;
        }
 
        ret = device_create_file(adev->dev, &dev_attr_pp_dpm_sclk);
@@ -1426,12 +1419,12 @@ void amdgpu_pm_sysfs_fini(struct amdgpu_device *adev)
                hwmon_device_unregister(adev->pm.int_hwmon_dev);
        device_remove_file(adev->dev, &dev_attr_power_dpm_state);
        device_remove_file(adev->dev, 
&dev_attr_power_dpm_force_performance_level);
-       if (adev->pp_enabled) {
-               device_remove_file(adev->dev, &dev_attr_pp_num_states);
-               device_remove_file(adev->dev, &dev_attr_pp_cur_state);
-               device_remove_file(adev->dev, &dev_attr_pp_force_state);
-               device_remove_file(adev->dev, &dev_attr_pp_table);
-       }
+
+       device_remove_file(adev->dev, &dev_attr_pp_num_states);
+       device_remove_file(adev->dev, &dev_attr_pp_cur_state);
+       device_remove_file(adev->dev, &dev_attr_pp_force_state);
+       device_remove_file(adev->dev, &dev_attr_pp_table);
+
        device_remove_file(adev->dev, &dev_attr_pp_dpm_sclk);
        device_remove_file(adev->dev, &dev_attr_pp_dpm_mclk);
        device_remove_file(adev->dev, &dev_attr_pp_dpm_pcie);
@@ -1462,7 +1455,7 @@ void amdgpu_pm_compute_clocks(struct amdgpu_device *adev)
                        amdgpu_fence_wait_empty(ring);
        }
 
-       if (adev->pp_enabled) {
+       if (adev->powerplay.pp_funcs->dispatch_tasks) {
                amdgpu_dpm_dispatch_task(adev, 
AMD_PP_TASK_DISPLAY_CONFIG_CHANGE, NULL, NULL);
        } else {
                mutex_lock(&adev->pm.mutex);
@@ -1597,15 +1590,15 @@ static int amdgpu_debugfs_pm_info(struct seq_file *m, 
void *data)
        if  ((adev->flags & AMD_IS_PX) &&
             (ddev->switch_power_state != DRM_SWITCH_POWER_ON)) {
                seq_printf(m, "PX asic powered off\n");
-       } else if (adev->pp_enabled) {
-               return amdgpu_debugfs_pm_info_pp(m, adev);
-       } else {
+       } else if 
(adev->powerplay.pp_funcs->debugfs_print_current_performance_level) {
                mutex_lock(&adev->pm.mutex);
                if 
(adev->powerplay.pp_funcs->debugfs_print_current_performance_level)
                        
adev->powerplay.pp_funcs->debugfs_print_current_performance_level(adev, m);
                else
                        seq_printf(m, "Debugfs support not implemented for this 
asic\n");
                mutex_unlock(&adev->pm.mutex);
+       } else {
+               return amdgpu_debugfs_pm_info_pp(m, adev);
        }
 
        return 0;
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_powerplay.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_powerplay.c
index 2ed81cd..eb88665 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_powerplay.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_powerplay.c
@@ -59,7 +59,6 @@ static int amdgpu_pp_early_init(void *handle)
        int ret = 0;
 
        amd_pp = &(adev->powerplay);
-       adev->pp_enabled = false;
        amd_pp->pp_handle = (void *)adev;
 
        switch (adev->asic_type) {
@@ -73,7 +72,6 @@ static int amdgpu_pp_early_init(void *handle)
        case CHIP_STONEY:
        case CHIP_VEGA10:
        case CHIP_RAVEN:
-               adev->pp_enabled = true;
                amd_pp->cgs_device = amdgpu_cgs_create_device(adev);
                if (amdgpu_create_pp_handle(adev))
                        return -EINVAL;
@@ -138,9 +136,6 @@ static int amdgpu_pp_late_init(void *handle)
                ret = adev->powerplay.ip_funcs->late_init(
                                        adev->powerplay.pp_handle);
 
-       if (adev->pp_enabled && adev->pm.dpm_enabled)
-               amdgpu_dpm_dispatch_task(adev, AMD_PP_TASK_COMPLETE_INIT, NULL, 
NULL);
-
        return ret;
 }
 
@@ -212,7 +207,7 @@ static void amdgpu_pp_late_fini(void *handle)
                          adev->powerplay.pp_handle);
 
 
-       if (adev->pp_enabled) {
+       if (adev->powerplay.cgs_device) {
                amd_powerplay_destroy(adev->powerplay.pp_handle);
                amdgpu_cgs_destroy_device(adev->powerplay.cgs_device);
        }
diff --git a/drivers/gpu/drm/amd/powerplay/amd_powerplay.c 
b/drivers/gpu/drm/amd/powerplay/amd_powerplay.c
index 9f3f3b8..5c7415e 100644
--- a/drivers/gpu/drm/amd/powerplay/amd_powerplay.c
+++ b/drivers/gpu/drm/amd/powerplay/amd_powerplay.c
@@ -30,6 +30,9 @@
 #include "pp_instance.h"
 #include "power_state.h"
 
+static int pp_dpm_dispatch_tasks(void *handle, enum amd_pp_task task_id,
+               void *input, void *output);
+
 static inline int pp_check(struct pp_instance *handle)
 {
        if (handle == NULL || handle->pp_valid != PP_VALID)
@@ -146,6 +149,19 @@ static int pp_hw_fini(void *handle)
        return 0;
 }
 
+static int pp_late_init(void *handle)
+{
+       struct pp_instance *pp_handle = (struct pp_instance *)handle;
+       int ret = 0;
+
+       ret = pp_check(pp_handle);
+       if (ret == 0)
+               pp_dpm_dispatch_tasks(pp_handle,
+                                       AMD_PP_TASK_COMPLETE_INIT, NULL, NULL);
+
+       return 0;
+}
+
 static bool pp_is_idle(void *handle)
 {
        return false;
@@ -254,7 +270,7 @@ static int pp_resume(void *handle)
 const struct amd_ip_funcs pp_ip_funcs = {
        .name = "powerplay",
        .early_init = pp_early_init,
-       .late_init = NULL,
+       .late_init = pp_late_init,
        .sw_init = pp_sw_init,
        .sw_fini = pp_sw_fini,
        .hw_init = pp_hw_init,
-- 
1.9.1

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

Reply via email to