]> git.proxmox.com Git - mirror_ubuntu-eoan-kernel.git/blame - drivers/gpu/drm/amd/powerplay/amd_powerplay.c
drm/amd/powerplay: add CG and PG support for carrizo
[mirror_ubuntu-eoan-kernel.git] / drivers / gpu / drm / amd / powerplay / amd_powerplay.c
CommitLineData
1f7371b2
AD
1/*
2 * Copyright 2015 Advanced Micro Devices, Inc.
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 * OTHER DEALINGS IN THE SOFTWARE.
21 *
22 */
23#include <linux/types.h>
24#include <linux/kernel.h>
25#include <linux/gfp.h>
ac885b3a 26#include <linux/slab.h>
1f7371b2
AD
27#include "amd_shared.h"
28#include "amd_powerplay.h"
ac885b3a 29#include "pp_instance.h"
1f7371b2
AD
30
31static int pp_early_init(void *handle)
32{
33 return 0;
34}
35
36static int pp_sw_init(void *handle)
37{
3bace359
JZ
38 struct pp_instance *pp_handle;
39 struct pp_hwmgr *hwmgr;
40 int ret = 0;
41
42 if (handle == NULL)
43 return -EINVAL;
44
45 pp_handle = (struct pp_instance *)handle;
46 hwmgr = pp_handle->hwmgr;
47
48 if (hwmgr == NULL || hwmgr->pptable_func == NULL ||
49 hwmgr->hwmgr_func == NULL ||
50 hwmgr->pptable_func->pptable_init == NULL ||
51 hwmgr->hwmgr_func->backend_init == NULL)
52 return -EINVAL;
53
54 ret = hwmgr->pptable_func->pptable_init(hwmgr);
55 if (ret == 0)
56 ret = hwmgr->hwmgr_func->backend_init(hwmgr);
57
58 return ret;
1f7371b2
AD
59}
60
61static int pp_sw_fini(void *handle)
62{
3bace359
JZ
63 struct pp_instance *pp_handle;
64 struct pp_hwmgr *hwmgr;
65 int ret = 0;
66
67 if (handle == NULL)
68 return -EINVAL;
69
70 pp_handle = (struct pp_instance *)handle;
71 hwmgr = pp_handle->hwmgr;
72
73 if (hwmgr != NULL || hwmgr->hwmgr_func != NULL ||
74 hwmgr->hwmgr_func->backend_fini != NULL)
75 ret = hwmgr->hwmgr_func->backend_fini(hwmgr);
76
77 return ret;
1f7371b2
AD
78}
79
80static int pp_hw_init(void *handle)
81{
ac885b3a
JZ
82 struct pp_instance *pp_handle;
83 struct pp_smumgr *smumgr;
84 int ret = 0;
85
86 if (handle == NULL)
87 return -EINVAL;
88
89 pp_handle = (struct pp_instance *)handle;
90 smumgr = pp_handle->smu_mgr;
91
92 if (smumgr == NULL || smumgr->smumgr_funcs == NULL ||
93 smumgr->smumgr_funcs->smu_init == NULL ||
94 smumgr->smumgr_funcs->start_smu == NULL)
95 return -EINVAL;
96
97 ret = smumgr->smumgr_funcs->smu_init(smumgr);
98 if (ret) {
99 printk(KERN_ERR "[ powerplay ] smc initialization failed\n");
100 return ret;
101 }
102
103 ret = smumgr->smumgr_funcs->start_smu(smumgr);
104 if (ret) {
105 printk(KERN_ERR "[ powerplay ] smc start failed\n");
106 smumgr->smumgr_funcs->smu_fini(smumgr);
107 return ret;
108 }
3bace359
JZ
109 hw_init_power_state_table(pp_handle->hwmgr);
110
1f7371b2
AD
111 return 0;
112}
113
114static int pp_hw_fini(void *handle)
115{
ac885b3a
JZ
116 struct pp_instance *pp_handle;
117 struct pp_smumgr *smumgr;
118
119 if (handle == NULL)
120 return -EINVAL;
121
122 pp_handle = (struct pp_instance *)handle;
123 smumgr = pp_handle->smu_mgr;
124
125 if (smumgr != NULL || smumgr->smumgr_funcs != NULL ||
126 smumgr->smumgr_funcs->smu_fini != NULL)
127 smumgr->smumgr_funcs->smu_fini(smumgr);
128
1f7371b2
AD
129 return 0;
130}
131
132static bool pp_is_idle(void *handle)
133{
134 return 0;
135}
136
137static int pp_wait_for_idle(void *handle)
138{
139 return 0;
140}
141
142static int pp_sw_reset(void *handle)
143{
144 return 0;
145}
146
147static void pp_print_status(void *handle)
148{
149
150}
151
152static int pp_set_clockgating_state(void *handle,
153 enum amd_clockgating_state state)
154{
155 return 0;
156}
157
158static int pp_set_powergating_state(void *handle,
159 enum amd_powergating_state state)
160{
161 return 0;
162}
163
164static int pp_suspend(void *handle)
165{
166 return 0;
167}
168
169static int pp_resume(void *handle)
170{
171 return 0;
172}
173
174const struct amd_ip_funcs pp_ip_funcs = {
175 .early_init = pp_early_init,
176 .late_init = NULL,
177 .sw_init = pp_sw_init,
178 .sw_fini = pp_sw_fini,
179 .hw_init = pp_hw_init,
180 .hw_fini = pp_hw_fini,
181 .suspend = pp_suspend,
182 .resume = pp_resume,
183 .is_idle = pp_is_idle,
184 .wait_for_idle = pp_wait_for_idle,
185 .soft_reset = pp_sw_reset,
186 .print_status = pp_print_status,
187 .set_clockgating_state = pp_set_clockgating_state,
188 .set_powergating_state = pp_set_powergating_state,
189};
190
191static int pp_dpm_load_fw(void *handle)
192{
193 return 0;
194}
195
196static int pp_dpm_fw_loading_complete(void *handle)
197{
198 return 0;
199}
200
201static int pp_dpm_force_performance_level(void *handle,
202 enum amd_dpm_forced_level level)
203{
204 return 0;
205}
206static enum amd_dpm_forced_level pp_dpm_get_performance_level(
207 void *handle)
208{
209 return 0;
210}
211static int pp_dpm_get_sclk(void *handle, bool low)
212{
213 return 0;
214}
215static int pp_dpm_get_mclk(void *handle, bool low)
216{
217 return 0;
218}
219static int pp_dpm_powergate_vce(void *handle, bool gate)
220{
221 return 0;
222}
223static int pp_dpm_powergate_uvd(void *handle, bool gate)
224{
225 return 0;
226}
227
228int pp_dpm_dispatch_tasks(void *handle, enum amd_pp_event event_id, void *input, void *output)
229{
230 return 0;
231}
232enum amd_pm_state_type pp_dpm_get_current_power_state(void *handle)
233{
234 return 0;
235}
236static void
237pp_debugfs_print_current_performance_level(void *handle,
238 struct seq_file *m)
239{
240 return;
241}
3bace359 242
1f7371b2
AD
243const struct amd_powerplay_funcs pp_dpm_funcs = {
244 .get_temperature = NULL,
245 .load_firmware = pp_dpm_load_fw,
246 .wait_for_fw_loading_complete = pp_dpm_fw_loading_complete,
247 .force_performance_level = pp_dpm_force_performance_level,
248 .get_performance_level = pp_dpm_get_performance_level,
249 .get_current_power_state = pp_dpm_get_current_power_state,
250 .get_sclk = pp_dpm_get_sclk,
251 .get_mclk = pp_dpm_get_mclk,
252 .powergate_vce = pp_dpm_powergate_vce,
253 .powergate_uvd = pp_dpm_powergate_uvd,
254 .dispatch_tasks = pp_dpm_dispatch_tasks,
255 .print_current_performance_level = pp_debugfs_print_current_performance_level,
256};
257
ac885b3a
JZ
258static int amd_pp_instance_init(struct amd_pp_init *pp_init,
259 struct amd_powerplay *amd_pp)
260{
261 int ret;
262 struct pp_instance *handle;
263
264 handle = kzalloc(sizeof(struct pp_instance), GFP_KERNEL);
265 if (handle == NULL)
266 return -ENOMEM;
267
268 ret = smum_init(pp_init, handle);
269 if (ret)
3bace359
JZ
270 goto fail_smum;
271
272 ret = hwmgr_init(pp_init, handle);
273 if (ret)
274 goto fail_hwmgr;
ac885b3a
JZ
275
276 amd_pp->pp_handle = handle;
277 return 0;
3bace359
JZ
278
279fail_hwmgr:
280 smum_fini(handle->smu_mgr);
281fail_smum:
282 kfree(handle);
283 return ret;
ac885b3a
JZ
284}
285
286static int amd_pp_instance_fini(void *handle)
287{
288 struct pp_instance *instance = (struct pp_instance *)handle;
289 if (instance == NULL)
290 return -EINVAL;
291
3bace359
JZ
292 hwmgr_fini(instance->hwmgr);
293
ac885b3a
JZ
294 smum_fini(instance->smu_mgr);
295
296 kfree(handle);
297 return 0;
298}
299
1f7371b2
AD
300int amd_powerplay_init(struct amd_pp_init *pp_init,
301 struct amd_powerplay *amd_pp)
302{
ac885b3a
JZ
303 int ret;
304
1f7371b2
AD
305 if (pp_init == NULL || amd_pp == NULL)
306 return -EINVAL;
307
ac885b3a
JZ
308 ret = amd_pp_instance_init(pp_init, amd_pp);
309
310 if (ret)
311 return ret;
312
1f7371b2
AD
313 amd_pp->ip_funcs = &pp_ip_funcs;
314 amd_pp->pp_funcs = &pp_dpm_funcs;
315
316 return 0;
317}
318
319int amd_powerplay_fini(void *handle)
320{
ac885b3a
JZ
321 amd_pp_instance_fini(handle);
322
1f7371b2
AD
323 return 0;
324}