drm/amdgpu: create powerplay by cgs interface
authorRex Zhu <Rex.Zhu@amd.com>
Mon, 25 Sep 2017 12:46:37 +0000 (20:46 +0800)
committerAlex Deucher <alexander.deucher@amd.com>
Thu, 28 Sep 2017 20:03:34 +0000 (16:03 -0400)
Reviewed-by: Alex Deucher <alexander.deucher@amd.com>
Signed-off-by: Rex Zhu <Rex.Zhu@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
drivers/gpu/drm/amd/amdgpu/amdgpu_powerplay.c
drivers/gpu/drm/amd/powerplay/amd_powerplay.c
drivers/gpu/drm/amd/powerplay/inc/amd_powerplay.h

index eb886654ce44c6f2ed885cb024f6de06a94ae52e..1649b1e3f23db08ac331a2fe70f9238ec3cc9d84 100644 (file)
 #include "cik_dpm.h"
 #include "vi_dpm.h"
 
-static int amdgpu_create_pp_handle(struct amdgpu_device *adev)
-{
-       struct amd_pp_init pp_init;
-       struct amd_powerplay *amd_pp;
-       int ret;
-
-       amd_pp = &(adev->powerplay);
-       pp_init.chip_family = adev->family;
-       pp_init.chip_id = adev->asic_type;
-       pp_init.pm_en = (amdgpu_dpm != 0 && !amdgpu_sriov_vf(adev)) ? true : false;
-       pp_init.feature_mask = amdgpu_pp_feature_mask;
-       pp_init.device = amd_pp->cgs_device;
-       ret = amd_powerplay_create(&pp_init, &(amd_pp->pp_handle));
-       if (ret)
-               return -EINVAL;
-       return 0;
-}
-
 static int amdgpu_pp_early_init(void *handle)
 {
        struct amdgpu_device *adev = (struct amdgpu_device *)handle;
@@ -73,8 +55,6 @@ static int amdgpu_pp_early_init(void *handle)
        case CHIP_VEGA10:
        case CHIP_RAVEN:
                amd_pp->cgs_device = amdgpu_cgs_create_device(adev);
-               if (amdgpu_create_pp_handle(adev))
-                       return -EINVAL;
                amd_pp->ip_funcs = &pp_ip_funcs;
                amd_pp->pp_funcs = &pp_dpm_funcs;
                break;
@@ -97,8 +77,6 @@ static int amdgpu_pp_early_init(void *handle)
                        amd_pp->pp_funcs = &ci_dpm_funcs;
                } else {
                        amd_pp->cgs_device = amdgpu_cgs_create_device(adev);
-                       if (amdgpu_create_pp_handle(adev))
-                               return -EINVAL;
                        amd_pp->ip_funcs = &pp_ip_funcs;
                        amd_pp->pp_funcs = &pp_dpm_funcs;
                }
@@ -117,7 +95,8 @@ static int amdgpu_pp_early_init(void *handle)
 
        if (adev->powerplay.ip_funcs->early_init)
                ret = adev->powerplay.ip_funcs->early_init(
-                                       adev->powerplay.pp_handle);
+                                       amd_pp->cgs_device ? amd_pp->cgs_device :
+                                       amd_pp->pp_handle);
 
        if (ret == PP_DPM_DISABLED) {
                adev->pm.dpm_enabled = false;
@@ -206,11 +185,8 @@ static void amdgpu_pp_late_fini(void *handle)
                adev->powerplay.ip_funcs->late_fini(
                          adev->powerplay.pp_handle);
 
-
-       if (adev->powerplay.cgs_device) {
-               amd_powerplay_destroy(adev->powerplay.pp_handle);
+       if (adev->powerplay.cgs_device)
                amdgpu_cgs_destroy_device(adev->powerplay.cgs_device);
-       }
 }
 
 static int amdgpu_pp_suspend(void *handle)
index 5c7415e8fd0ee3d3782c89c7f2c05b409f7ee130..488347a11f011570720e009edd17f72c231b6589 100644 (file)
@@ -50,10 +50,50 @@ static inline int pp_check(struct pp_instance *handle)
        return 0;
 }
 
+static int amd_powerplay_create(struct amd_pp_init *pp_init,
+                               void **handle)
+{
+       struct pp_instance *instance;
+
+       if (pp_init == NULL || handle == NULL)
+               return -EINVAL;
+
+       instance = kzalloc(sizeof(struct pp_instance), GFP_KERNEL);
+       if (instance == NULL)
+               return -ENOMEM;
+
+       instance->pp_valid = PP_VALID;
+       instance->chip_family = pp_init->chip_family;
+       instance->chip_id = pp_init->chip_id;
+       instance->pm_en = pp_init->pm_en;
+       instance->feature_mask = pp_init->feature_mask;
+       instance->device = pp_init->device;
+       mutex_init(&instance->pp_lock);
+       *handle = instance;
+       return 0;
+}
+
+static int amd_powerplay_destroy(void *handle)
+{
+       struct pp_instance *instance = (struct pp_instance *)handle;
+
+       kfree(instance->hwmgr);
+       instance->hwmgr = NULL;
+
+       kfree(instance);
+       instance = NULL;
+       return 0;
+}
+
 static int pp_early_init(void *handle)
 {
        int ret;
-       struct pp_instance *pp_handle = (struct pp_instance *)handle;
+       struct pp_instance *pp_handle = NULL;
+
+       pp_handle = cgs_register_pp_handle(handle, amd_powerplay_create);
+
+       if (!pp_handle)
+               return -EINVAL;
 
        ret = hwmgr_early_init(pp_handle);
        if (ret)
@@ -162,6 +202,12 @@ static int pp_late_init(void *handle)
        return 0;
 }
 
+static void pp_late_fini(void *handle)
+{
+       amd_powerplay_destroy(handle);
+}
+
+
 static bool pp_is_idle(void *handle)
 {
        return false;
@@ -275,6 +321,7 @@ const struct amd_ip_funcs pp_ip_funcs = {
        .sw_fini = pp_sw_fini,
        .hw_init = pp_hw_init,
        .hw_fini = pp_hw_fini,
+       .late_fini = pp_late_fini,
        .suspend = pp_suspend,
        .resume = pp_resume,
        .is_idle = pp_is_idle,
@@ -1138,41 +1185,6 @@ const struct amd_pm_funcs pp_dpm_funcs = {
        .switch_power_profile = pp_dpm_switch_power_profile,
 };
 
-int amd_powerplay_create(struct amd_pp_init *pp_init,
-                               void **handle)
-{
-       struct pp_instance *instance;
-
-       if (pp_init == NULL || handle == NULL)
-               return -EINVAL;
-
-       instance = kzalloc(sizeof(struct pp_instance), GFP_KERNEL);
-       if (instance == NULL)
-               return -ENOMEM;
-
-       instance->pp_valid = PP_VALID;
-       instance->chip_family = pp_init->chip_family;
-       instance->chip_id = pp_init->chip_id;
-       instance->pm_en = pp_init->pm_en;
-       instance->feature_mask = pp_init->feature_mask;
-       instance->device = pp_init->device;
-       mutex_init(&instance->pp_lock);
-       *handle = instance;
-       return 0;
-}
-
-int amd_powerplay_destroy(void *handle)
-{
-       struct pp_instance *instance = (struct pp_instance *)handle;
-
-       kfree(instance->hwmgr);
-       instance->hwmgr = NULL;
-
-       kfree(instance);
-       instance = NULL;
-       return 0;
-}
-
 int amd_powerplay_reset(void *handle)
 {
        struct pp_instance *instance = (struct pp_instance *)handle;
index 437d78558a0bfb0405bad659ae1ceb10a7738b16..916b6c420ea4e986f14b2a53c54b082a0e9dd06e 100644 (file)
@@ -274,11 +274,6 @@ struct amd_powerplay {
        const struct amd_pm_funcs *pp_funcs;
 };
 
-int amd_powerplay_create(struct amd_pp_init *pp_init,
-                               void **handle);
-
-int amd_powerplay_destroy(void *handle);
-
 int amd_powerplay_reset(void *handle);
 
 int amd_powerplay_display_configuration_change(void *handle,