Skip to content

Commit 1c86380

Browse files
Rex Zhualexdeucher
authored andcommitted
drm/amd/powerplay: refine powerplay interface.
v2: add pp_check function to check pp_instance valid. 1. powerplay export two new interface to amdgpu, amd_powerplay_create/amd_powerplay_destroy. 2. create pp_instance/smumgr/hwmgr/eventmgr in early init, destroy them when lata_fini. 3. in sw_init, create and init asic private smumgr data, and free them when sw_fini. 4. in hw_init, create and init asic private hwmgr data, and free them when hw_fini. 5. export powerplay state: PP_DPM_DISABLED. when user disabled powerplay or hwmgr/eventmgr init failed, powerplay return this state to amdgpu. Signed-off-by: Rex Zhu <[email protected]> Reviewed-by: Alex Deucher <[email protected]> Signed-off-by: Alex Deucher <[email protected]>
1 parent ae6a58e commit 1c86380

File tree

10 files changed

+518
-479
lines changed

10 files changed

+518
-479
lines changed

drivers/gpu/drm/amd/amdgpu/amdgpu_powerplay.c

Lines changed: 52 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -34,63 +34,34 @@
3434
#include "cik_dpm.h"
3535
#include "vi_dpm.h"
3636

37-
static int amdgpu_powerplay_init(struct amdgpu_device *adev)
37+
static int amdgpu_create_pp_handle(struct amdgpu_device *adev)
3838
{
39-
int ret = 0;
39+
struct amd_pp_init pp_init;
4040
struct amd_powerplay *amd_pp;
41+
int ret;
4142

4243
amd_pp = &(adev->powerplay);
43-
44-
if (adev->pp_enabled) {
45-
struct amd_pp_init *pp_init;
46-
47-
pp_init = kzalloc(sizeof(struct amd_pp_init), GFP_KERNEL);
48-
49-
if (pp_init == NULL)
50-
return -ENOMEM;
51-
52-
pp_init->chip_family = adev->family;
53-
pp_init->chip_id = adev->asic_type;
54-
pp_init->device = amdgpu_cgs_create_device(adev);
55-
ret = amd_powerplay_init(pp_init, amd_pp);
56-
kfree(pp_init);
57-
} else {
58-
amd_pp->pp_handle = (void *)adev;
59-
60-
switch (adev->asic_type) {
61-
#ifdef CONFIG_DRM_AMDGPU_SI
62-
case CHIP_TAHITI:
63-
case CHIP_PITCAIRN:
64-
case CHIP_VERDE:
65-
case CHIP_OLAND:
66-
case CHIP_HAINAN:
67-
amd_pp->ip_funcs = &si_dpm_ip_funcs;
68-
break;
69-
#endif
70-
#ifdef CONFIG_DRM_AMDGPU_CIK
71-
case CHIP_BONAIRE:
72-
case CHIP_HAWAII:
73-
amd_pp->ip_funcs = &ci_dpm_ip_funcs;
74-
break;
75-
case CHIP_KABINI:
76-
case CHIP_MULLINS:
77-
case CHIP_KAVERI:
78-
amd_pp->ip_funcs = &kv_dpm_ip_funcs;
79-
break;
80-
#endif
81-
default:
82-
ret = -EINVAL;
83-
break;
84-
}
85-
}
86-
return ret;
44+
pp_init.chip_family = adev->family;
45+
pp_init.chip_id = adev->asic_type;
46+
pp_init.pm_en = amdgpu_dpm != 0 ? true : false;
47+
pp_init.feature_mask = amdgpu_pp_feature_mask;
48+
pp_init.device = amdgpu_cgs_create_device(adev);
49+
ret = amd_powerplay_create(&pp_init, &(amd_pp->pp_handle));
50+
if (ret)
51+
return -EINVAL;
52+
return 0;
8753
}
8854

8955
static int amdgpu_pp_early_init(void *handle)
9056
{
9157
struct amdgpu_device *adev = (struct amdgpu_device *)handle;
58+
struct amd_powerplay *amd_pp;
9259
int ret = 0;
9360

61+
amd_pp = &(adev->powerplay);
62+
adev->pp_enabled = false;
63+
amd_pp->pp_handle = (void *)adev;
64+
9465
switch (adev->asic_type) {
9566
case CHIP_POLARIS11:
9667
case CHIP_POLARIS10:
@@ -101,25 +72,45 @@ static int amdgpu_pp_early_init(void *handle)
10172
case CHIP_CARRIZO:
10273
case CHIP_STONEY:
10374
adev->pp_enabled = true;
75+
if (amdgpu_create_pp_handle(adev))
76+
return -EINVAL;
77+
amd_pp->ip_funcs = &pp_ip_funcs;
78+
amd_pp->pp_funcs = &pp_dpm_funcs;
10479
break;
10580
/* These chips don't have powerplay implemenations */
81+
#ifdef CONFIG_DRM_AMDGPU_SI
82+
case CHIP_TAHITI:
83+
case CHIP_PITCAIRN:
84+
case CHIP_VERDE:
85+
case CHIP_OLAND:
86+
case CHIP_HAINAN:
87+
amd_pp->ip_funcs = &si_dpm_ip_funcs;
88+
break;
89+
#endif
90+
#ifdef CONFIG_DRM_AMDGPU_CIK
10691
case CHIP_BONAIRE:
10792
case CHIP_HAWAII:
93+
amd_pp->ip_funcs = &ci_dpm_ip_funcs;
94+
break;
10895
case CHIP_KABINI:
10996
case CHIP_MULLINS:
11097
case CHIP_KAVERI:
98+
amd_pp->ip_funcs = &kv_dpm_ip_funcs;
99+
break;
100+
#endif
111101
default:
112-
adev->pp_enabled = false;
102+
ret = -EINVAL;
113103
break;
114104
}
115105

116-
ret = amdgpu_powerplay_init(adev);
117-
if (ret)
118-
return ret;
119-
120106
if (adev->powerplay.ip_funcs->early_init)
121107
ret = adev->powerplay.ip_funcs->early_init(
122108
adev->powerplay.pp_handle);
109+
110+
if (ret == PP_DPM_DISABLED) {
111+
adev->pm.dpm_enabled = false;
112+
return 0;
113+
}
123114
return ret;
124115
}
125116

@@ -179,6 +170,11 @@ static int amdgpu_pp_hw_init(void *handle)
179170
ret = adev->powerplay.ip_funcs->hw_init(
180171
adev->powerplay.pp_handle);
181172

173+
if (ret == PP_DPM_DISABLED) {
174+
adev->pm.dpm_enabled = false;
175+
return 0;
176+
}
177+
182178
if ((amdgpu_dpm != 0) && !amdgpu_sriov_vf(adev))
183179
adev->pm.dpm_enabled = true;
184180

@@ -204,14 +200,14 @@ static void amdgpu_pp_late_fini(void *handle)
204200
{
205201
struct amdgpu_device *adev = (struct amdgpu_device *)handle;
206202

207-
if (adev->pp_enabled) {
208-
amdgpu_pm_sysfs_fini(adev);
209-
amd_powerplay_fini(adev->powerplay.pp_handle);
210-
}
211-
212203
if (adev->powerplay.ip_funcs->late_fini)
213204
adev->powerplay.ip_funcs->late_fini(
214205
adev->powerplay.pp_handle);
206+
207+
if (adev->pp_enabled && adev->pm.dpm_enabled)
208+
amdgpu_pm_sysfs_fini(adev);
209+
210+
amd_powerplay_destroy(adev->powerplay.pp_handle);
215211
}
216212

217213
static int amdgpu_pp_suspend(void *handle)

0 commit comments

Comments
 (0)