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.
25 #include "eventinit.h"
26 #include "eventmanagement.h"
27 #include "eventmanager.h"
28 #include "hardwaremanager.h"
29 #include "eventtasks.h"
30 #include "power_state.h"
32 #include "amd_powerplay.h"
35 #define TEMP_RANGE_MIN (90 * 1000)
36 #define TEMP_RANGE_MAX (120 * 1000)
38 int pem_task_update_allowed_performance_levels(struct pp_eventmgr
*eventmgr
, struct pem_event_data
*event_data
)
41 if (pem_is_hw_access_blocked(eventmgr
))
44 phm_force_dpm_levels(eventmgr
->hwmgr
, AMD_DPM_FORCED_LEVEL_AUTO
);
49 /* eventtasks_generic.c */
50 int pem_task_adjust_power_state(struct pp_eventmgr
*eventmgr
, struct pem_event_data
*event_data
)
52 struct pp_hwmgr
*hwmgr
;
54 if (pem_is_hw_access_blocked(eventmgr
))
57 hwmgr
= eventmgr
->hwmgr
;
58 if (event_data
->pnew_power_state
!= NULL
)
59 hwmgr
->request_ps
= event_data
->pnew_power_state
;
61 if (phm_cap_enabled(eventmgr
->platform_descriptor
->platformCaps
, PHM_PlatformCaps_DynamicPatchPowerState
))
62 psm_adjust_power_state_dynamic(eventmgr
, event_data
->skip_state_adjust_rules
);
64 psm_adjust_power_state_static(eventmgr
, event_data
->skip_state_adjust_rules
);
69 int pem_task_power_down_asic(struct pp_eventmgr
*eventmgr
, struct pem_event_data
*event_data
)
71 return phm_power_down_asic(eventmgr
->hwmgr
);
74 int pem_task_set_boot_state(struct pp_eventmgr
*eventmgr
, struct pem_event_data
*event_data
)
76 if (pem_is_event_data_valid(event_data
->valid_fields
, PEM_EventDataValid_RequestedStateID
))
77 return psm_set_states(eventmgr
, &(event_data
->requested_state_id
));
82 int pem_task_reset_boot_state(struct pp_eventmgr
*eventmgr
, struct pem_event_data
*event_data
)
88 int pem_task_update_new_power_state_clocks(struct pp_eventmgr
*eventmgr
, struct pem_event_data
*event_data
)
94 int pem_task_system_shutdown(struct pp_eventmgr
*eventmgr
, struct pem_event_data
*event_data
)
100 int pem_task_register_interrupts(struct pp_eventmgr
*eventmgr
, struct pem_event_data
*event_data
)
106 int pem_task_unregister_interrupts(struct pp_eventmgr
*eventmgr
, struct pem_event_data
*event_data
)
108 return pem_unregister_interrupts(eventmgr
);
111 int pem_task_get_boot_state_id(struct pp_eventmgr
*eventmgr
, struct pem_event_data
*event_data
)
115 result
= psm_get_state_by_classification(eventmgr
,
116 PP_StateClassificationFlag_Boot
,
117 &(event_data
->requested_state_id
)
121 pem_set_event_data_valid(event_data
->valid_fields
, PEM_EventDataValid_RequestedStateID
);
123 pem_unset_event_data_valid(event_data
->valid_fields
, PEM_EventDataValid_RequestedStateID
);
128 int pem_task_enable_dynamic_state_management(struct pp_eventmgr
*eventmgr
, struct pem_event_data
*event_data
)
130 return phm_enable_dynamic_state_management(eventmgr
->hwmgr
);
133 int pem_task_disable_dynamic_state_management(struct pp_eventmgr
*eventmgr
, struct pem_event_data
*event_data
)
135 return phm_disable_dynamic_state_management(eventmgr
->hwmgr
);
138 int pem_task_enable_clock_power_gatings_tasks(struct pp_eventmgr
*eventmgr
, struct pem_event_data
*event_data
)
140 return phm_enable_clock_power_gatings(eventmgr
->hwmgr
);
143 int pem_task_powerdown_uvd_tasks(struct pp_eventmgr
*eventmgr
, struct pem_event_data
*event_data
)
145 return phm_powerdown_uvd(eventmgr
->hwmgr
);
148 int pem_task_powerdown_vce_tasks(struct pp_eventmgr
*eventmgr
, struct pem_event_data
*event_data
)
150 phm_powergate_uvd(eventmgr
->hwmgr
, true);
151 phm_powergate_vce(eventmgr
->hwmgr
, true);
155 int pem_task_disable_clock_power_gatings_tasks(struct pp_eventmgr
*eventmgr
, struct pem_event_data
*event_data
)
157 phm_disable_clock_power_gatings(eventmgr
->hwmgr
);
161 int pem_task_start_asic_block_usage(struct pp_eventmgr
*eventmgr
, struct pem_event_data
*event_data
)
167 int pem_task_stop_asic_block_usage(struct pp_eventmgr
*eventmgr
, struct pem_event_data
*event_data
)
173 int pem_task_setup_asic(struct pp_eventmgr
*eventmgr
, struct pem_event_data
*event_data
)
175 return phm_setup_asic(eventmgr
->hwmgr
);
178 int pem_task_cleanup_asic(struct pp_eventmgr
*eventmgr
, struct pem_event_data
*event_data
)
184 int pem_task_store_dal_configuration(struct pp_eventmgr
*eventmgr
, const struct amd_display_configuration
*display_config
)
188 /*phm_store_dal_configuration_data(eventmgr->hwmgr, display_config) */
191 int pem_task_notify_hw_mgr_display_configuration_change(struct pp_eventmgr
*eventmgr
, struct pem_event_data
*event_data
)
193 if (pem_is_hw_access_blocked(eventmgr
))
196 return phm_display_configuration_changed(eventmgr
->hwmgr
);
199 int pem_task_notify_hw_mgr_pre_display_configuration_change(struct pp_eventmgr
*eventmgr
, struct pem_event_data
*event_data
)
204 int pem_task_notify_smc_display_config_after_power_state_adjustment(struct pp_eventmgr
*eventmgr
, struct pem_event_data
*event_data
)
206 if (pem_is_hw_access_blocked(eventmgr
))
209 return phm_notify_smc_display_config_after_ps_adjustment(eventmgr
->hwmgr
);
212 int pem_task_block_adjust_power_state(struct pp_eventmgr
*eventmgr
, struct pem_event_data
*event_data
)
214 eventmgr
->block_adjust_power_state
= true;
215 /* to do PHM_ResetIPSCounter(pEventMgr->pHwMgr);*/
219 int pem_task_unblock_adjust_power_state(struct pp_eventmgr
*eventmgr
, struct pem_event_data
*event_data
)
221 eventmgr
->block_adjust_power_state
= false;
225 int pem_task_notify_power_state_change(struct pp_eventmgr
*eventmgr
, struct pem_event_data
*event_data
)
231 int pem_task_block_hw_access(struct pp_eventmgr
*eventmgr
, struct pem_event_data
*event_data
)
237 int pem_task_un_block_hw_access(struct pp_eventmgr
*eventmgr
, struct pem_event_data
*event_data
)
243 int pem_task_reset_display_phys_access(struct pp_eventmgr
*eventmgr
, struct pem_event_data
*event_data
)
249 int pem_task_set_cpu_power_state(struct pp_eventmgr
*eventmgr
, struct pem_event_data
*event_data
)
251 return phm_set_cpu_power_state(eventmgr
->hwmgr
);
256 int pem_task_set_power_source(struct pp_eventmgr
*eventmgr
, struct pem_event_data
*event_data
)
262 int pem_task_notify_hw_of_power_source(struct pp_eventmgr
*eventmgr
, struct pem_event_data
*event_data
)
268 int pem_task_get_power_saving_state(struct pp_eventmgr
*eventmgr
, struct pem_event_data
*event_data
)
274 int pem_task_reset_power_saving_state(struct pp_eventmgr
*eventmgr
, struct pem_event_data
*event_data
)
280 int pem_task_set_power_saving_state(struct pp_eventmgr
*eventmgr
, struct pem_event_data
*event_data
)
286 int pem_task_set_screen_state_on(struct pp_eventmgr
*eventmgr
, struct pem_event_data
*event_data
)
292 int pem_task_set_screen_state_off(struct pp_eventmgr
*eventmgr
, struct pem_event_data
*event_data
)
298 int pem_task_enable_voltage_island_power_gating(struct pp_eventmgr
*eventmgr
, struct pem_event_data
*event_data
)
304 int pem_task_disable_voltage_island_power_gating(struct pp_eventmgr
*eventmgr
, struct pem_event_data
*event_data
)
310 int pem_task_enable_cgpg(struct pp_eventmgr
*eventmgr
, struct pem_event_data
*event_data
)
316 int pem_task_disable_cgpg(struct pp_eventmgr
*eventmgr
, struct pem_event_data
*event_data
)
322 int pem_task_enable_clock_power_gating(struct pp_eventmgr
*eventmgr
, struct pem_event_data
*event_data
)
329 int pem_task_enable_gfx_clock_gating(struct pp_eventmgr
*eventmgr
, struct pem_event_data
*event_data
)
335 int pem_task_disable_gfx_clock_gating(struct pp_eventmgr
*eventmgr
, struct pem_event_data
*event_data
)
343 int pem_task_set_performance_state(struct pp_eventmgr
*eventmgr
, struct pem_event_data
*event_data
)
345 if (pem_is_event_data_valid(event_data
->valid_fields
, PEM_EventDataValid_RequestedStateID
))
346 return psm_set_states(eventmgr
, &(event_data
->requested_state_id
));
351 int pem_task_conditionally_force_3d_performance_state(struct pp_eventmgr
*eventmgr
, struct pem_event_data
*event_data
)
357 int pem_task_enable_stutter_mode(struct pp_eventmgr
*eventmgr
, struct pem_event_data
*event_data
)
363 int pem_task_get_2D_performance_state_id(struct pp_eventmgr
*eventmgr
, struct pem_event_data
*event_data
)
367 if (eventmgr
->features
[PP_Feature_PowerPlay
].supported
&&
368 !(eventmgr
->features
[PP_Feature_PowerPlay
].enabled
))
369 result
= psm_get_state_by_classification(eventmgr
,
370 PP_StateClassificationFlag_Boot
,
371 &(event_data
->requested_state_id
));
372 else if (eventmgr
->features
[PP_Feature_User2DPerformance
].enabled
)
373 result
= psm_get_state_by_classification(eventmgr
,
374 PP_StateClassificationFlag_User2DPerformance
,
375 &(event_data
->requested_state_id
));
377 result
= psm_get_ui_state(eventmgr
, PP_StateUILabel_Performance
,
378 &(event_data
->requested_state_id
));
381 pem_set_event_data_valid(event_data
->valid_fields
, PEM_EventDataValid_RequestedStateID
);
383 pem_unset_event_data_valid(event_data
->valid_fields
, PEM_EventDataValid_RequestedStateID
);
388 int pem_task_create_user_performance_state(struct pp_eventmgr
*eventmgr
, struct pem_event_data
*event_data
)
390 struct pp_power_state
*state
;
392 struct pp_hwmgr
*hwmgr
= eventmgr
->hwmgr
;
395 table_entries
= hwmgr
->num_ps
;
399 for (i
= 0; i
< table_entries
; i
++) {
400 if (state
->classification
.ui_label
& event_data
->requested_ui_label
) {
401 event_data
->pnew_power_state
= state
;
404 state
= (struct pp_power_state
*)((unsigned long)state
+ hwmgr
->ps_size
);
407 switch (event_data
->requested_ui_label
) {
408 case PP_StateUILabel_Battery
:
409 case PP_StateUILabel_Balanced
:
410 event_data
->requested_ui_label
= PP_StateUILabel_Performance
;
418 int pem_task_initialize_thermal_controller(struct pp_eventmgr
*eventmgr
, struct pem_event_data
*event_data
)
420 struct PP_TemperatureRange range
;
422 range
.max
= TEMP_RANGE_MAX
;
423 range
.min
= TEMP_RANGE_MIN
;
425 if (eventmgr
== NULL
|| eventmgr
->platform_descriptor
== NULL
)
428 if (phm_cap_enabled(eventmgr
->platform_descriptor
->platformCaps
, PHM_PlatformCaps_ThermalController
))
429 return phm_start_thermal_controller(eventmgr
->hwmgr
, &range
);
434 int pem_task_uninitialize_thermal_controller(struct pp_eventmgr
*eventmgr
, struct pem_event_data
*event_data
)
436 return phm_stop_thermal_controller(eventmgr
->hwmgr
);