2 * Copyright 2015 Advanced Micro Devices, Inc.
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:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
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.
23 #include <linux/types.h>
24 #include <linux/kernel.h>
25 #include <linux/gfp.h>
26 #include <linux/slab.h>
27 #include "amd_shared.h"
28 #include "amd_powerplay.h"
29 #include "pp_instance.h"
30 #include "power_state.h"
31 #include "eventmanager.h"
35 #define PP_CHECK(handle) \
37 if ((handle) == NULL || (handle)->pp_valid != PP_VALID) \
41 #define PP_CHECK_HW(hwmgr) \
43 if ((hwmgr) == NULL || (hwmgr)->hwmgr_func == NULL) \
47 static int pp_early_init(void *handle
)
52 static int pp_sw_init(void *handle
)
54 struct pp_instance
*pp_handle
;
55 struct pp_hwmgr
*hwmgr
;
61 pp_handle
= (struct pp_instance
*)handle
;
62 hwmgr
= pp_handle
->hwmgr
;
66 if (hwmgr
->pptable_func
== NULL
||
67 hwmgr
->pptable_func
->pptable_init
== NULL
||
68 hwmgr
->hwmgr_func
->backend_init
== NULL
)
71 ret
= hwmgr
->pptable_func
->pptable_init(hwmgr
);
75 ret
= hwmgr
->hwmgr_func
->backend_init(hwmgr
);
79 pr_info("amdgpu: powerplay initialized\n");
83 if (hwmgr
->pptable_func
->pptable_fini
)
84 hwmgr
->pptable_func
->pptable_fini(hwmgr
);
86 pr_err("amdgpu: powerplay initialization failed\n");
90 static int pp_sw_fini(void *handle
)
92 struct pp_instance
*pp_handle
;
93 struct pp_hwmgr
*hwmgr
;
99 pp_handle
= (struct pp_instance
*)handle
;
100 hwmgr
= pp_handle
->hwmgr
;
104 if (hwmgr
->hwmgr_func
->backend_fini
!= NULL
)
105 ret
= hwmgr
->hwmgr_func
->backend_fini(hwmgr
);
107 if (hwmgr
->pptable_func
->pptable_fini
)
108 hwmgr
->pptable_func
->pptable_fini(hwmgr
);
113 static int pp_hw_init(void *handle
)
115 struct pp_instance
*pp_handle
;
116 struct pp_smumgr
*smumgr
;
117 struct pp_eventmgr
*eventmgr
;
123 pp_handle
= (struct pp_instance
*)handle
;
124 smumgr
= pp_handle
->smu_mgr
;
126 if (smumgr
== NULL
|| smumgr
->smumgr_funcs
== NULL
||
127 smumgr
->smumgr_funcs
->smu_init
== NULL
||
128 smumgr
->smumgr_funcs
->start_smu
== NULL
)
131 ret
= smumgr
->smumgr_funcs
->smu_init(smumgr
);
133 printk(KERN_ERR
"[ powerplay ] smc initialization failed\n");
137 ret
= smumgr
->smumgr_funcs
->start_smu(smumgr
);
139 printk(KERN_ERR
"[ powerplay ] smc start failed\n");
140 smumgr
->smumgr_funcs
->smu_fini(smumgr
);
144 hw_init_power_state_table(pp_handle
->hwmgr
);
145 eventmgr
= pp_handle
->eventmgr
;
147 if (eventmgr
== NULL
|| eventmgr
->pp_eventmgr_init
== NULL
)
150 ret
= eventmgr
->pp_eventmgr_init(eventmgr
);
154 static int pp_hw_fini(void *handle
)
156 struct pp_instance
*pp_handle
;
157 struct pp_smumgr
*smumgr
;
158 struct pp_eventmgr
*eventmgr
;
163 pp_handle
= (struct pp_instance
*)handle
;
164 eventmgr
= pp_handle
->eventmgr
;
166 if (eventmgr
!= NULL
&& eventmgr
->pp_eventmgr_fini
!= NULL
)
167 eventmgr
->pp_eventmgr_fini(eventmgr
);
169 smumgr
= pp_handle
->smu_mgr
;
171 if (smumgr
!= NULL
&& smumgr
->smumgr_funcs
!= NULL
&&
172 smumgr
->smumgr_funcs
->smu_fini
!= NULL
)
173 smumgr
->smumgr_funcs
->smu_fini(smumgr
);
178 static bool pp_is_idle(void *handle
)
183 static int pp_wait_for_idle(void *handle
)
188 static int pp_sw_reset(void *handle
)
194 static int pp_set_clockgating_state(void *handle
,
195 enum amd_clockgating_state state
)
197 struct pp_hwmgr
*hwmgr
;
198 uint32_t msg_id
, pp_state
;
203 hwmgr
= ((struct pp_instance
*)handle
)->hwmgr
;
207 if (hwmgr
->hwmgr_func
->update_clock_gatings
== NULL
) {
208 printk(KERN_INFO
"%s was not implemented.\n", __func__
);
212 if (state
== AMD_CG_STATE_UNGATE
)
215 pp_state
= PP_STATE_CG
| PP_STATE_LS
;
217 /* Enable/disable GFX blocks clock gating through SMU */
218 msg_id
= PP_CG_MSG_ID(PP_GROUP_GFX
,
220 PP_STATE_SUPPORT_CG
| PP_STATE_SUPPORT_LS
,
222 hwmgr
->hwmgr_func
->update_clock_gatings(hwmgr
, &msg_id
);
223 msg_id
= PP_CG_MSG_ID(PP_GROUP_GFX
,
225 PP_STATE_SUPPORT_CG
| PP_STATE_SUPPORT_LS
,
227 hwmgr
->hwmgr_func
->update_clock_gatings(hwmgr
, &msg_id
);
228 msg_id
= PP_CG_MSG_ID(PP_GROUP_GFX
,
230 PP_STATE_SUPPORT_CG
| PP_STATE_SUPPORT_LS
,
232 hwmgr
->hwmgr_func
->update_clock_gatings(hwmgr
, &msg_id
);
233 msg_id
= PP_CG_MSG_ID(PP_GROUP_GFX
,
235 PP_STATE_SUPPORT_CG
| PP_STATE_SUPPORT_LS
,
237 hwmgr
->hwmgr_func
->update_clock_gatings(hwmgr
, &msg_id
);
238 msg_id
= PP_CG_MSG_ID(PP_GROUP_GFX
,
240 PP_STATE_SUPPORT_CG
| PP_STATE_SUPPORT_LS
,
242 hwmgr
->hwmgr_func
->update_clock_gatings(hwmgr
, &msg_id
);
244 /* Enable/disable System blocks clock gating through SMU */
245 msg_id
= PP_CG_MSG_ID(PP_GROUP_SYS
,
247 PP_STATE_SUPPORT_CG
| PP_STATE_SUPPORT_LS
,
249 hwmgr
->hwmgr_func
->update_clock_gatings(hwmgr
, &msg_id
);
250 msg_id
= PP_CG_MSG_ID(PP_GROUP_SYS
,
252 PP_STATE_SUPPORT_CG
| PP_STATE_SUPPORT_LS
,
254 hwmgr
->hwmgr_func
->update_clock_gatings(hwmgr
, &msg_id
);
255 msg_id
= PP_CG_MSG_ID(PP_GROUP_SYS
,
257 PP_STATE_SUPPORT_CG
| PP_STATE_SUPPORT_LS
,
259 hwmgr
->hwmgr_func
->update_clock_gatings(hwmgr
, &msg_id
);
260 msg_id
= PP_CG_MSG_ID(PP_GROUP_SYS
,
262 PP_STATE_SUPPORT_CG
| PP_STATE_SUPPORT_LS
,
264 hwmgr
->hwmgr_func
->update_clock_gatings(hwmgr
, &msg_id
);
265 msg_id
= PP_CG_MSG_ID(PP_GROUP_SYS
,
267 PP_STATE_SUPPORT_CG
| PP_STATE_SUPPORT_LS
,
269 hwmgr
->hwmgr_func
->update_clock_gatings(hwmgr
, &msg_id
);
270 msg_id
= PP_CG_MSG_ID(PP_GROUP_SYS
,
272 PP_STATE_SUPPORT_CG
| PP_STATE_SUPPORT_LS
,
274 hwmgr
->hwmgr_func
->update_clock_gatings(hwmgr
, &msg_id
);
275 msg_id
= PP_CG_MSG_ID(PP_GROUP_SYS
,
277 PP_STATE_SUPPORT_CG
| PP_STATE_SUPPORT_LS
,
279 hwmgr
->hwmgr_func
->update_clock_gatings(hwmgr
, &msg_id
);
284 static int pp_set_powergating_state(void *handle
,
285 enum amd_powergating_state state
)
287 struct pp_hwmgr
*hwmgr
;
292 hwmgr
= ((struct pp_instance
*)handle
)->hwmgr
;
296 if (hwmgr
->hwmgr_func
->enable_per_cu_power_gating
== NULL
) {
297 printk(KERN_INFO
"%s was not implemented.\n", __func__
);
301 /* Enable/disable GFX per cu powergating through SMU */
302 return hwmgr
->hwmgr_func
->enable_per_cu_power_gating(hwmgr
,
303 state
== AMD_PG_STATE_GATE
? true : false);
306 static int pp_suspend(void *handle
)
308 struct pp_instance
*pp_handle
;
309 struct pp_eventmgr
*eventmgr
;
310 struct pem_event_data event_data
= { {0} };
315 pp_handle
= (struct pp_instance
*)handle
;
316 eventmgr
= pp_handle
->eventmgr
;
317 pem_handle_event(eventmgr
, AMD_PP_EVENT_SUSPEND
, &event_data
);
321 static int pp_resume(void *handle
)
323 struct pp_instance
*pp_handle
;
324 struct pp_eventmgr
*eventmgr
;
325 struct pem_event_data event_data
= { {0} };
326 struct pp_smumgr
*smumgr
;
332 pp_handle
= (struct pp_instance
*)handle
;
333 smumgr
= pp_handle
->smu_mgr
;
335 if (smumgr
== NULL
|| smumgr
->smumgr_funcs
== NULL
||
336 smumgr
->smumgr_funcs
->start_smu
== NULL
)
339 ret
= smumgr
->smumgr_funcs
->start_smu(smumgr
);
341 printk(KERN_ERR
"[ powerplay ] smc start failed\n");
342 smumgr
->smumgr_funcs
->smu_fini(smumgr
);
346 eventmgr
= pp_handle
->eventmgr
;
347 pem_handle_event(eventmgr
, AMD_PP_EVENT_RESUME
, &event_data
);
352 const struct amd_ip_funcs pp_ip_funcs
= {
354 .early_init
= pp_early_init
,
356 .sw_init
= pp_sw_init
,
357 .sw_fini
= pp_sw_fini
,
358 .hw_init
= pp_hw_init
,
359 .hw_fini
= pp_hw_fini
,
360 .suspend
= pp_suspend
,
362 .is_idle
= pp_is_idle
,
363 .wait_for_idle
= pp_wait_for_idle
,
364 .soft_reset
= pp_sw_reset
,
365 .set_clockgating_state
= pp_set_clockgating_state
,
366 .set_powergating_state
= pp_set_powergating_state
,
369 static int pp_dpm_load_fw(void *handle
)
374 static int pp_dpm_fw_loading_complete(void *handle
)
379 static int pp_dpm_force_performance_level(void *handle
,
380 enum amd_dpm_forced_level level
)
382 struct pp_instance
*pp_handle
;
383 struct pp_hwmgr
*hwmgr
;
388 pp_handle
= (struct pp_instance
*)handle
;
390 hwmgr
= pp_handle
->hwmgr
;
394 if (hwmgr
->hwmgr_func
->force_dpm_level
== NULL
) {
395 printk(KERN_INFO
"%s was not implemented.\n", __func__
);
399 hwmgr
->hwmgr_func
->force_dpm_level(hwmgr
, level
);
404 static enum amd_dpm_forced_level
pp_dpm_get_performance_level(
407 struct pp_hwmgr
*hwmgr
;
412 hwmgr
= ((struct pp_instance
*)handle
)->hwmgr
;
417 return (((struct pp_instance
*)handle
)->hwmgr
->dpm_level
);
420 static int pp_dpm_get_sclk(void *handle
, bool low
)
422 struct pp_hwmgr
*hwmgr
;
427 hwmgr
= ((struct pp_instance
*)handle
)->hwmgr
;
431 if (hwmgr
->hwmgr_func
->get_sclk
== NULL
) {
432 printk(KERN_INFO
"%s was not implemented.\n", __func__
);
436 return hwmgr
->hwmgr_func
->get_sclk(hwmgr
, low
);
439 static int pp_dpm_get_mclk(void *handle
, bool low
)
441 struct pp_hwmgr
*hwmgr
;
446 hwmgr
= ((struct pp_instance
*)handle
)->hwmgr
;
450 if (hwmgr
->hwmgr_func
->get_mclk
== NULL
) {
451 printk(KERN_INFO
"%s was not implemented.\n", __func__
);
455 return hwmgr
->hwmgr_func
->get_mclk(hwmgr
, low
);
458 static int pp_dpm_powergate_vce(void *handle
, bool gate
)
460 struct pp_hwmgr
*hwmgr
;
465 hwmgr
= ((struct pp_instance
*)handle
)->hwmgr
;
469 if (hwmgr
->hwmgr_func
->powergate_vce
== NULL
) {
470 printk(KERN_INFO
"%s was not implemented.\n", __func__
);
474 return hwmgr
->hwmgr_func
->powergate_vce(hwmgr
, gate
);
477 static int pp_dpm_powergate_uvd(void *handle
, bool gate
)
479 struct pp_hwmgr
*hwmgr
;
484 hwmgr
= ((struct pp_instance
*)handle
)->hwmgr
;
488 if (hwmgr
->hwmgr_func
->powergate_uvd
== NULL
) {
489 printk(KERN_INFO
"%s was not implemented.\n", __func__
);
493 return hwmgr
->hwmgr_func
->powergate_uvd(hwmgr
, gate
);
496 static enum PP_StateUILabel
power_state_convert(enum amd_pm_state_type state
)
499 case POWER_STATE_TYPE_BATTERY
:
500 return PP_StateUILabel_Battery
;
501 case POWER_STATE_TYPE_BALANCED
:
502 return PP_StateUILabel_Balanced
;
503 case POWER_STATE_TYPE_PERFORMANCE
:
504 return PP_StateUILabel_Performance
;
506 return PP_StateUILabel_None
;
510 int pp_dpm_dispatch_tasks(void *handle
, enum amd_pp_event event_id
, void *input
, void *output
)
513 struct pp_instance
*pp_handle
;
514 struct pem_event_data data
= { {0} };
516 pp_handle
= (struct pp_instance
*)handle
;
518 if (pp_handle
== NULL
)
522 case AMD_PP_EVENT_DISPLAY_CONFIG_CHANGE
:
523 ret
= pem_handle_event(pp_handle
->eventmgr
, event_id
, &data
);
525 case AMD_PP_EVENT_ENABLE_USER_STATE
:
527 enum amd_pm_state_type ps
;
531 ps
= *(unsigned long *)input
;
533 data
.requested_ui_label
= power_state_convert(ps
);
534 ret
= pem_handle_event(pp_handle
->eventmgr
, event_id
, &data
);
537 case AMD_PP_EVENT_COMPLETE_INIT
:
538 ret
= pem_handle_event(pp_handle
->eventmgr
, event_id
, &data
);
540 case AMD_PP_EVENT_READJUST_POWER_STATE
:
541 pp_handle
->hwmgr
->current_ps
= pp_handle
->hwmgr
->boot_ps
;
542 ret
= pem_handle_event(pp_handle
->eventmgr
, event_id
, &data
);
550 enum amd_pm_state_type
pp_dpm_get_current_power_state(void *handle
)
552 struct pp_hwmgr
*hwmgr
;
553 struct pp_power_state
*state
;
558 hwmgr
= ((struct pp_instance
*)handle
)->hwmgr
;
560 if (hwmgr
== NULL
|| hwmgr
->current_ps
== NULL
)
563 state
= hwmgr
->current_ps
;
565 switch (state
->classification
.ui_label
) {
566 case PP_StateUILabel_Battery
:
567 return POWER_STATE_TYPE_BATTERY
;
568 case PP_StateUILabel_Balanced
:
569 return POWER_STATE_TYPE_BALANCED
;
570 case PP_StateUILabel_Performance
:
571 return POWER_STATE_TYPE_PERFORMANCE
;
573 if (state
->classification
.flags
& PP_StateClassificationFlag_Boot
)
574 return POWER_STATE_TYPE_INTERNAL_BOOT
;
576 return POWER_STATE_TYPE_DEFAULT
;
581 pp_debugfs_print_current_performance_level(void *handle
,
584 struct pp_hwmgr
*hwmgr
;
589 hwmgr
= ((struct pp_instance
*)handle
)->hwmgr
;
591 if (hwmgr
== NULL
|| hwmgr
->hwmgr_func
== NULL
)
594 if (hwmgr
->hwmgr_func
->print_current_perforce_level
== NULL
) {
595 printk(KERN_INFO
"%s was not implemented.\n", __func__
);
599 hwmgr
->hwmgr_func
->print_current_perforce_level(hwmgr
, m
);
602 static int pp_dpm_set_fan_control_mode(void *handle
, uint32_t mode
)
604 struct pp_hwmgr
*hwmgr
;
609 hwmgr
= ((struct pp_instance
*)handle
)->hwmgr
;
613 if (hwmgr
->hwmgr_func
->set_fan_control_mode
== NULL
) {
614 printk(KERN_INFO
"%s was not implemented.\n", __func__
);
618 return hwmgr
->hwmgr_func
->set_fan_control_mode(hwmgr
, mode
);
621 static int pp_dpm_get_fan_control_mode(void *handle
)
623 struct pp_hwmgr
*hwmgr
;
628 hwmgr
= ((struct pp_instance
*)handle
)->hwmgr
;
632 if (hwmgr
->hwmgr_func
->get_fan_control_mode
== NULL
) {
633 printk(KERN_INFO
"%s was not implemented.\n", __func__
);
637 return hwmgr
->hwmgr_func
->get_fan_control_mode(hwmgr
);
640 static int pp_dpm_set_fan_speed_percent(void *handle
, uint32_t percent
)
642 struct pp_hwmgr
*hwmgr
;
647 hwmgr
= ((struct pp_instance
*)handle
)->hwmgr
;
651 if (hwmgr
->hwmgr_func
->set_fan_speed_percent
== NULL
) {
652 printk(KERN_INFO
"%s was not implemented.\n", __func__
);
656 return hwmgr
->hwmgr_func
->set_fan_speed_percent(hwmgr
, percent
);
659 static int pp_dpm_get_fan_speed_percent(void *handle
, uint32_t *speed
)
661 struct pp_hwmgr
*hwmgr
;
666 hwmgr
= ((struct pp_instance
*)handle
)->hwmgr
;
670 if (hwmgr
->hwmgr_func
->get_fan_speed_percent
== NULL
) {
671 printk(KERN_INFO
"%s was not implemented.\n", __func__
);
675 return hwmgr
->hwmgr_func
->get_fan_speed_percent(hwmgr
, speed
);
678 static int pp_dpm_get_temperature(void *handle
)
680 struct pp_hwmgr
*hwmgr
;
685 hwmgr
= ((struct pp_instance
*)handle
)->hwmgr
;
689 if (hwmgr
->hwmgr_func
->get_temperature
== NULL
) {
690 printk(KERN_INFO
"%s was not implemented.\n", __func__
);
694 return hwmgr
->hwmgr_func
->get_temperature(hwmgr
);
697 static int pp_dpm_get_pp_num_states(void *handle
,
698 struct pp_states_info
*data
)
700 struct pp_hwmgr
*hwmgr
;
706 hwmgr
= ((struct pp_instance
*)handle
)->hwmgr
;
708 if (hwmgr
== NULL
|| hwmgr
->ps
== NULL
)
711 data
->nums
= hwmgr
->num_ps
;
713 for (i
= 0; i
< hwmgr
->num_ps
; i
++) {
714 struct pp_power_state
*state
= (struct pp_power_state
*)
715 ((unsigned long)hwmgr
->ps
+ i
* hwmgr
->ps_size
);
716 switch (state
->classification
.ui_label
) {
717 case PP_StateUILabel_Battery
:
718 data
->states
[i
] = POWER_STATE_TYPE_BATTERY
;
720 case PP_StateUILabel_Balanced
:
721 data
->states
[i
] = POWER_STATE_TYPE_BALANCED
;
723 case PP_StateUILabel_Performance
:
724 data
->states
[i
] = POWER_STATE_TYPE_PERFORMANCE
;
727 if (state
->classification
.flags
& PP_StateClassificationFlag_Boot
)
728 data
->states
[i
] = POWER_STATE_TYPE_INTERNAL_BOOT
;
730 data
->states
[i
] = POWER_STATE_TYPE_DEFAULT
;
737 static int pp_dpm_get_pp_table(void *handle
, char **table
)
739 struct pp_hwmgr
*hwmgr
;
744 hwmgr
= ((struct pp_instance
*)handle
)->hwmgr
;
748 if (!hwmgr
->soft_pp_table
)
751 *table
= (char *)hwmgr
->soft_pp_table
;
753 return hwmgr
->soft_pp_table_size
;
756 static int pp_dpm_set_pp_table(void *handle
, const char *buf
, size_t size
)
758 struct pp_hwmgr
*hwmgr
;
763 hwmgr
= ((struct pp_instance
*)handle
)->hwmgr
;
767 if (!hwmgr
->hardcode_pp_table
) {
768 hwmgr
->hardcode_pp_table
=
769 kzalloc(hwmgr
->soft_pp_table_size
, GFP_KERNEL
);
771 if (!hwmgr
->hardcode_pp_table
)
774 /* to avoid powerplay crash when hardcode pptable is empty */
775 memcpy(hwmgr
->hardcode_pp_table
, hwmgr
->soft_pp_table
,
776 hwmgr
->soft_pp_table_size
);
779 memcpy(hwmgr
->hardcode_pp_table
, buf
, size
);
781 hwmgr
->soft_pp_table
= hwmgr
->hardcode_pp_table
;
783 return amd_powerplay_reset(handle
);
786 static int pp_dpm_force_clock_level(void *handle
,
787 enum pp_clock_type type
, uint32_t mask
)
789 struct pp_hwmgr
*hwmgr
;
794 hwmgr
= ((struct pp_instance
*)handle
)->hwmgr
;
798 if (hwmgr
->hwmgr_func
->force_clock_level
== NULL
) {
799 printk(KERN_INFO
"%s was not implemented.\n", __func__
);
803 return hwmgr
->hwmgr_func
->force_clock_level(hwmgr
, type
, mask
);
806 static int pp_dpm_print_clock_levels(void *handle
,
807 enum pp_clock_type type
, char *buf
)
809 struct pp_hwmgr
*hwmgr
;
814 hwmgr
= ((struct pp_instance
*)handle
)->hwmgr
;
818 if (hwmgr
->hwmgr_func
->print_clock_levels
== NULL
) {
819 printk(KERN_INFO
"%s was not implemented.\n", __func__
);
822 return hwmgr
->hwmgr_func
->print_clock_levels(hwmgr
, type
, buf
);
825 static int pp_dpm_get_sclk_od(void *handle
)
827 struct pp_hwmgr
*hwmgr
;
832 hwmgr
= ((struct pp_instance
*)handle
)->hwmgr
;
836 if (hwmgr
->hwmgr_func
->get_sclk_od
== NULL
) {
837 printk(KERN_INFO
"%s was not implemented.\n", __func__
);
841 return hwmgr
->hwmgr_func
->get_sclk_od(hwmgr
);
844 static int pp_dpm_set_sclk_od(void *handle
, uint32_t value
)
846 struct pp_hwmgr
*hwmgr
;
851 hwmgr
= ((struct pp_instance
*)handle
)->hwmgr
;
855 if (hwmgr
->hwmgr_func
->set_sclk_od
== NULL
) {
856 printk(KERN_INFO
"%s was not implemented.\n", __func__
);
860 return hwmgr
->hwmgr_func
->set_sclk_od(hwmgr
, value
);
863 static int pp_dpm_get_mclk_od(void *handle
)
865 struct pp_hwmgr
*hwmgr
;
870 hwmgr
= ((struct pp_instance
*)handle
)->hwmgr
;
874 if (hwmgr
->hwmgr_func
->get_mclk_od
== NULL
) {
875 printk(KERN_INFO
"%s was not implemented.\n", __func__
);
879 return hwmgr
->hwmgr_func
->get_mclk_od(hwmgr
);
882 static int pp_dpm_set_mclk_od(void *handle
, uint32_t value
)
884 struct pp_hwmgr
*hwmgr
;
889 hwmgr
= ((struct pp_instance
*)handle
)->hwmgr
;
893 if (hwmgr
->hwmgr_func
->set_mclk_od
== NULL
) {
894 printk(KERN_INFO
"%s was not implemented.\n", __func__
);
898 return hwmgr
->hwmgr_func
->set_mclk_od(hwmgr
, value
);
901 const struct amd_powerplay_funcs pp_dpm_funcs
= {
902 .get_temperature
= pp_dpm_get_temperature
,
903 .load_firmware
= pp_dpm_load_fw
,
904 .wait_for_fw_loading_complete
= pp_dpm_fw_loading_complete
,
905 .force_performance_level
= pp_dpm_force_performance_level
,
906 .get_performance_level
= pp_dpm_get_performance_level
,
907 .get_current_power_state
= pp_dpm_get_current_power_state
,
908 .get_sclk
= pp_dpm_get_sclk
,
909 .get_mclk
= pp_dpm_get_mclk
,
910 .powergate_vce
= pp_dpm_powergate_vce
,
911 .powergate_uvd
= pp_dpm_powergate_uvd
,
912 .dispatch_tasks
= pp_dpm_dispatch_tasks
,
913 .print_current_performance_level
= pp_debugfs_print_current_performance_level
,
914 .set_fan_control_mode
= pp_dpm_set_fan_control_mode
,
915 .get_fan_control_mode
= pp_dpm_get_fan_control_mode
,
916 .set_fan_speed_percent
= pp_dpm_set_fan_speed_percent
,
917 .get_fan_speed_percent
= pp_dpm_get_fan_speed_percent
,
918 .get_pp_num_states
= pp_dpm_get_pp_num_states
,
919 .get_pp_table
= pp_dpm_get_pp_table
,
920 .set_pp_table
= pp_dpm_set_pp_table
,
921 .force_clock_level
= pp_dpm_force_clock_level
,
922 .print_clock_levels
= pp_dpm_print_clock_levels
,
923 .get_sclk_od
= pp_dpm_get_sclk_od
,
924 .set_sclk_od
= pp_dpm_set_sclk_od
,
925 .get_mclk_od
= pp_dpm_get_mclk_od
,
926 .set_mclk_od
= pp_dpm_set_mclk_od
,
929 static int amd_pp_instance_init(struct amd_pp_init
*pp_init
,
930 struct amd_powerplay
*amd_pp
)
933 struct pp_instance
*handle
;
935 handle
= kzalloc(sizeof(struct pp_instance
), GFP_KERNEL
);
939 handle
->pp_valid
= PP_VALID
;
941 ret
= smum_init(pp_init
, handle
);
945 ret
= hwmgr_init(pp_init
, handle
);
949 ret
= eventmgr_init(handle
);
953 amd_pp
->pp_handle
= handle
;
957 hwmgr_fini(handle
->hwmgr
);
959 smum_fini(handle
->smu_mgr
);
965 static int amd_pp_instance_fini(void *handle
)
967 struct pp_instance
*instance
= (struct pp_instance
*)handle
;
969 if (instance
== NULL
)
972 eventmgr_fini(instance
->eventmgr
);
974 hwmgr_fini(instance
->hwmgr
);
976 smum_fini(instance
->smu_mgr
);
982 int amd_powerplay_init(struct amd_pp_init
*pp_init
,
983 struct amd_powerplay
*amd_pp
)
987 if (pp_init
== NULL
|| amd_pp
== NULL
)
990 ret
= amd_pp_instance_init(pp_init
, amd_pp
);
995 amd_pp
->ip_funcs
= &pp_ip_funcs
;
996 amd_pp
->pp_funcs
= &pp_dpm_funcs
;
1001 int amd_powerplay_fini(void *handle
)
1003 amd_pp_instance_fini(handle
);
1008 int amd_powerplay_reset(void *handle
)
1010 struct pp_instance
*instance
= (struct pp_instance
*)handle
;
1011 struct pp_eventmgr
*eventmgr
;
1012 struct pem_event_data event_data
= { {0} };
1015 if (instance
== NULL
)
1018 eventmgr
= instance
->eventmgr
;
1019 if (!eventmgr
|| !eventmgr
->pp_eventmgr_fini
)
1022 eventmgr
->pp_eventmgr_fini(eventmgr
);
1024 ret
= pp_sw_fini(handle
);
1028 kfree(instance
->hwmgr
->ps
);
1030 ret
= pp_sw_init(handle
);
1034 hw_init_power_state_table(instance
->hwmgr
);
1036 if (eventmgr
== NULL
|| eventmgr
->pp_eventmgr_init
== NULL
)
1039 ret
= eventmgr
->pp_eventmgr_init(eventmgr
);
1043 return pem_handle_event(eventmgr
, AMD_PP_EVENT_COMPLETE_INIT
, &event_data
);
1046 /* export this function to DAL */
1048 int amd_powerplay_display_configuration_change(void *handle
,
1049 const struct amd_pp_display_configuration
*display_config
)
1051 struct pp_hwmgr
*hwmgr
;
1053 PP_CHECK((struct pp_instance
*)handle
);
1055 hwmgr
= ((struct pp_instance
*)handle
)->hwmgr
;
1057 phm_store_dal_configuration_data(hwmgr
, display_config
);
1062 int amd_powerplay_get_display_power_level(void *handle
,
1063 struct amd_pp_simple_clock_info
*output
)
1065 struct pp_hwmgr
*hwmgr
;
1067 PP_CHECK((struct pp_instance
*)handle
);
1072 hwmgr
= ((struct pp_instance
*)handle
)->hwmgr
;
1074 return phm_get_dal_power_level(hwmgr
, output
);
1077 int amd_powerplay_get_current_clocks(void *handle
,
1078 struct amd_pp_clock_info
*clocks
)
1080 struct pp_hwmgr
*hwmgr
;
1081 struct amd_pp_simple_clock_info simple_clocks
;
1082 struct pp_clock_info hw_clocks
;
1084 PP_CHECK((struct pp_instance
*)handle
);
1089 hwmgr
= ((struct pp_instance
*)handle
)->hwmgr
;
1091 phm_get_dal_power_level(hwmgr
, &simple_clocks
);
1093 if (phm_cap_enabled(hwmgr
->platform_descriptor
.platformCaps
, PHM_PlatformCaps_PowerContainment
)) {
1094 if (0 != phm_get_clock_info(hwmgr
, &hwmgr
->current_ps
->hardware
, &hw_clocks
, PHM_PerformanceLevelDesignation_PowerContainment
))
1095 PP_ASSERT_WITH_CODE(0, "Error in PHM_GetPowerContainmentClockInfo", return -1);
1097 if (0 != phm_get_clock_info(hwmgr
, &hwmgr
->current_ps
->hardware
, &hw_clocks
, PHM_PerformanceLevelDesignation_Activity
))
1098 PP_ASSERT_WITH_CODE(0, "Error in PHM_GetClockInfo", return -1);
1101 clocks
->min_engine_clock
= hw_clocks
.min_eng_clk
;
1102 clocks
->max_engine_clock
= hw_clocks
.max_eng_clk
;
1103 clocks
->min_memory_clock
= hw_clocks
.min_mem_clk
;
1104 clocks
->max_memory_clock
= hw_clocks
.max_mem_clk
;
1105 clocks
->min_bus_bandwidth
= hw_clocks
.min_bus_bandwidth
;
1106 clocks
->max_bus_bandwidth
= hw_clocks
.max_bus_bandwidth
;
1108 clocks
->max_engine_clock_in_sr
= hw_clocks
.max_eng_clk
;
1109 clocks
->min_engine_clock_in_sr
= hw_clocks
.min_eng_clk
;
1111 clocks
->max_clocks_state
= simple_clocks
.level
;
1113 if (0 == phm_get_current_shallow_sleep_clocks(hwmgr
, &hwmgr
->current_ps
->hardware
, &hw_clocks
)) {
1114 clocks
->max_engine_clock_in_sr
= hw_clocks
.max_eng_clk
;
1115 clocks
->min_engine_clock_in_sr
= hw_clocks
.min_eng_clk
;
1122 int amd_powerplay_get_clock_by_type(void *handle
, enum amd_pp_clock_type type
, struct amd_pp_clocks
*clocks
)
1126 struct pp_hwmgr
*hwmgr
;
1128 PP_CHECK((struct pp_instance
*)handle
);
1133 hwmgr
= ((struct pp_instance
*)handle
)->hwmgr
;
1135 result
= phm_get_clock_by_type(hwmgr
, type
, clocks
);
1140 int amd_powerplay_get_display_mode_validation_clocks(void *handle
,
1141 struct amd_pp_simple_clock_info
*clocks
)
1144 struct pp_hwmgr
*hwmgr
;
1146 PP_CHECK((struct pp_instance
*)handle
);
1151 hwmgr
= ((struct pp_instance
*)handle
)->hwmgr
;
1153 if (phm_cap_enabled(hwmgr
->platform_descriptor
.platformCaps
, PHM_PlatformCaps_DynamicPatchPowerState
))
1154 result
= phm_get_max_high_clocks(hwmgr
, clocks
);