aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--drivers/gpu/drm/amd/amdgpu/amdgpu_powerplay.c30
-rw-r--r--drivers/gpu/drm/amd/powerplay/amd_powerplay.c84
-rw-r--r--drivers/gpu/drm/amd/powerplay/inc/amd_powerplay.h5
3 files changed, 51 insertions, 68 deletions
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_powerplay.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_powerplay.c
index eb886654ce44..1649b1e3f23d 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_powerplay.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_powerplay.c
@@ -34,24 +34,6 @@
34#include "cik_dpm.h" 34#include "cik_dpm.h"
35#include "vi_dpm.h" 35#include "vi_dpm.h"
36 36
37static int amdgpu_create_pp_handle(struct amdgpu_device *adev)
38{
39 struct amd_pp_init pp_init;
40 struct amd_powerplay *amd_pp;
41 int ret;
42
43 amd_pp = &(adev->powerplay);
44 pp_init.chip_family = adev->family;
45 pp_init.chip_id = adev->asic_type;
46 pp_init.pm_en = (amdgpu_dpm != 0 && !amdgpu_sriov_vf(adev)) ? true : false;
47 pp_init.feature_mask = amdgpu_pp_feature_mask;
48 pp_init.device = amd_pp->cgs_device;
49 ret = amd_powerplay_create(&pp_init, &(amd_pp->pp_handle));
50 if (ret)
51 return -EINVAL;
52 return 0;
53}
54
55static int amdgpu_pp_early_init(void *handle) 37static int amdgpu_pp_early_init(void *handle)
56{ 38{
57 struct amdgpu_device *adev = (struct amdgpu_device *)handle; 39 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
@@ -73,8 +55,6 @@ static int amdgpu_pp_early_init(void *handle)
73 case CHIP_VEGA10: 55 case CHIP_VEGA10:
74 case CHIP_RAVEN: 56 case CHIP_RAVEN:
75 amd_pp->cgs_device = amdgpu_cgs_create_device(adev); 57 amd_pp->cgs_device = amdgpu_cgs_create_device(adev);
76 if (amdgpu_create_pp_handle(adev))
77 return -EINVAL;
78 amd_pp->ip_funcs = &pp_ip_funcs; 58 amd_pp->ip_funcs = &pp_ip_funcs;
79 amd_pp->pp_funcs = &pp_dpm_funcs; 59 amd_pp->pp_funcs = &pp_dpm_funcs;
80 break; 60 break;
@@ -97,8 +77,6 @@ static int amdgpu_pp_early_init(void *handle)
97 amd_pp->pp_funcs = &ci_dpm_funcs; 77 amd_pp->pp_funcs = &ci_dpm_funcs;
98 } else { 78 } else {
99 amd_pp->cgs_device = amdgpu_cgs_create_device(adev); 79 amd_pp->cgs_device = amdgpu_cgs_create_device(adev);
100 if (amdgpu_create_pp_handle(adev))
101 return -EINVAL;
102 amd_pp->ip_funcs = &pp_ip_funcs; 80 amd_pp->ip_funcs = &pp_ip_funcs;
103 amd_pp->pp_funcs = &pp_dpm_funcs; 81 amd_pp->pp_funcs = &pp_dpm_funcs;
104 } 82 }
@@ -117,7 +95,8 @@ static int amdgpu_pp_early_init(void *handle)
117 95
118 if (adev->powerplay.ip_funcs->early_init) 96 if (adev->powerplay.ip_funcs->early_init)
119 ret = adev->powerplay.ip_funcs->early_init( 97 ret = adev->powerplay.ip_funcs->early_init(
120 adev->powerplay.pp_handle); 98 amd_pp->cgs_device ? amd_pp->cgs_device :
99 amd_pp->pp_handle);
121 100
122 if (ret == PP_DPM_DISABLED) { 101 if (ret == PP_DPM_DISABLED) {
123 adev->pm.dpm_enabled = false; 102 adev->pm.dpm_enabled = false;
@@ -206,11 +185,8 @@ static void amdgpu_pp_late_fini(void *handle)
206 adev->powerplay.ip_funcs->late_fini( 185 adev->powerplay.ip_funcs->late_fini(
207 adev->powerplay.pp_handle); 186 adev->powerplay.pp_handle);
208 187
209 188 if (adev->powerplay.cgs_device)
210 if (adev->powerplay.cgs_device) {
211 amd_powerplay_destroy(adev->powerplay.pp_handle);
212 amdgpu_cgs_destroy_device(adev->powerplay.cgs_device); 189 amdgpu_cgs_destroy_device(adev->powerplay.cgs_device);
213 }
214} 190}
215 191
216static int amdgpu_pp_suspend(void *handle) 192static int amdgpu_pp_suspend(void *handle)
diff --git a/drivers/gpu/drm/amd/powerplay/amd_powerplay.c b/drivers/gpu/drm/amd/powerplay/amd_powerplay.c
index 5c7415e8fd0e..488347a11f01 100644
--- a/drivers/gpu/drm/amd/powerplay/amd_powerplay.c
+++ b/drivers/gpu/drm/amd/powerplay/amd_powerplay.c
@@ -50,10 +50,50 @@ static inline int pp_check(struct pp_instance *handle)
50 return 0; 50 return 0;
51} 51}
52 52
53static int amd_powerplay_create(struct amd_pp_init *pp_init,
54 void **handle)
55{
56 struct pp_instance *instance;
57
58 if (pp_init == NULL || handle == NULL)
59 return -EINVAL;
60
61 instance = kzalloc(sizeof(struct pp_instance), GFP_KERNEL);
62 if (instance == NULL)
63 return -ENOMEM;
64
65 instance->pp_valid = PP_VALID;
66 instance->chip_family = pp_init->chip_family;
67 instance->chip_id = pp_init->chip_id;
68 instance->pm_en = pp_init->pm_en;
69 instance->feature_mask = pp_init->feature_mask;
70 instance->device = pp_init->device;
71 mutex_init(&instance->pp_lock);
72 *handle = instance;
73 return 0;
74}
75
76static int amd_powerplay_destroy(void *handle)
77{
78 struct pp_instance *instance = (struct pp_instance *)handle;
79
80 kfree(instance->hwmgr);
81 instance->hwmgr = NULL;
82
83 kfree(instance);
84 instance = NULL;
85 return 0;
86}
87
53static int pp_early_init(void *handle) 88static int pp_early_init(void *handle)
54{ 89{
55 int ret; 90 int ret;
56 struct pp_instance *pp_handle = (struct pp_instance *)handle; 91 struct pp_instance *pp_handle = NULL;
92
93 pp_handle = cgs_register_pp_handle(handle, amd_powerplay_create);
94
95 if (!pp_handle)
96 return -EINVAL;
57 97
58 ret = hwmgr_early_init(pp_handle); 98 ret = hwmgr_early_init(pp_handle);
59 if (ret) 99 if (ret)
@@ -162,6 +202,12 @@ static int pp_late_init(void *handle)
162 return 0; 202 return 0;
163} 203}
164 204
205static void pp_late_fini(void *handle)
206{
207 amd_powerplay_destroy(handle);
208}
209
210
165static bool pp_is_idle(void *handle) 211static bool pp_is_idle(void *handle)
166{ 212{
167 return false; 213 return false;
@@ -275,6 +321,7 @@ const struct amd_ip_funcs pp_ip_funcs = {
275 .sw_fini = pp_sw_fini, 321 .sw_fini = pp_sw_fini,
276 .hw_init = pp_hw_init, 322 .hw_init = pp_hw_init,
277 .hw_fini = pp_hw_fini, 323 .hw_fini = pp_hw_fini,
324 .late_fini = pp_late_fini,
278 .suspend = pp_suspend, 325 .suspend = pp_suspend,
279 .resume = pp_resume, 326 .resume = pp_resume,
280 .is_idle = pp_is_idle, 327 .is_idle = pp_is_idle,
@@ -1138,41 +1185,6 @@ const struct amd_pm_funcs pp_dpm_funcs = {
1138 .switch_power_profile = pp_dpm_switch_power_profile, 1185 .switch_power_profile = pp_dpm_switch_power_profile,
1139}; 1186};
1140 1187
1141int amd_powerplay_create(struct amd_pp_init *pp_init,
1142 void **handle)
1143{
1144 struct pp_instance *instance;
1145
1146 if (pp_init == NULL || handle == NULL)
1147 return -EINVAL;
1148
1149 instance = kzalloc(sizeof(struct pp_instance), GFP_KERNEL);
1150 if (instance == NULL)
1151 return -ENOMEM;
1152
1153 instance->pp_valid = PP_VALID;
1154 instance->chip_family = pp_init->chip_family;
1155 instance->chip_id = pp_init->chip_id;
1156 instance->pm_en = pp_init->pm_en;
1157 instance->feature_mask = pp_init->feature_mask;
1158 instance->device = pp_init->device;
1159 mutex_init(&instance->pp_lock);
1160 *handle = instance;
1161 return 0;
1162}
1163
1164int amd_powerplay_destroy(void *handle)
1165{
1166 struct pp_instance *instance = (struct pp_instance *)handle;
1167
1168 kfree(instance->hwmgr);
1169 instance->hwmgr = NULL;
1170
1171 kfree(instance);
1172 instance = NULL;
1173 return 0;
1174}
1175
1176int amd_powerplay_reset(void *handle) 1188int amd_powerplay_reset(void *handle)
1177{ 1189{
1178 struct pp_instance *instance = (struct pp_instance *)handle; 1190 struct pp_instance *instance = (struct pp_instance *)handle;
diff --git a/drivers/gpu/drm/amd/powerplay/inc/amd_powerplay.h b/drivers/gpu/drm/amd/powerplay/inc/amd_powerplay.h
index 437d78558a0b..916b6c420ea4 100644
--- a/drivers/gpu/drm/amd/powerplay/inc/amd_powerplay.h
+++ b/drivers/gpu/drm/amd/powerplay/inc/amd_powerplay.h
@@ -274,11 +274,6 @@ struct amd_powerplay {
274 const struct amd_pm_funcs *pp_funcs; 274 const struct amd_pm_funcs *pp_funcs;
275}; 275};
276 276
277int amd_powerplay_create(struct amd_pp_init *pp_init,
278 void **handle);
279
280int amd_powerplay_destroy(void *handle);
281
282int amd_powerplay_reset(void *handle); 277int amd_powerplay_reset(void *handle);
283 278
284int amd_powerplay_display_configuration_change(void *handle, 279int amd_powerplay_display_configuration_change(void *handle,