drm/exynos: Stop using drm_framebuffer_unregister_private
[linux/fpc-iii.git] / drivers / gpu / drm / amd / powerplay / eventmgr / eventtasks.c
blobec36c0e28388105e75e294de99300c8dac5a6218
1 /*
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.
24 #include "eventmgr.h"
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"
31 #include "hwmgr.h"
32 #include "amd_powerplay.h"
33 #include "psm.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))
42 return 0;
44 phm_force_dpm_levels(eventmgr->hwmgr, AMD_DPM_FORCED_LEVEL_AUTO);
46 return 0;
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))
55 return 0;
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);
63 else
64 psm_adjust_power_state_static(eventmgr, event_data->skip_state_adjust_rules);
66 return 0;
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));
79 return 0;
82 int pem_task_reset_boot_state(struct pp_eventmgr *eventmgr, struct pem_event_data *event_data)
84 /* TODO */
85 return 0;
88 int pem_task_update_new_power_state_clocks(struct pp_eventmgr *eventmgr, struct pem_event_data *event_data)
90 /* TODO */
91 return 0;
94 int pem_task_system_shutdown(struct pp_eventmgr *eventmgr, struct pem_event_data *event_data)
96 /* TODO */
97 return 0;
100 int pem_task_register_interrupts(struct pp_eventmgr *eventmgr, struct pem_event_data *event_data)
102 /* TODO */
103 return 0;
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)
113 int result;
115 result = psm_get_state_by_classification(eventmgr,
116 PP_StateClassificationFlag_Boot,
117 &(event_data->requested_state_id)
120 if (0 == result)
121 pem_set_event_data_valid(event_data->valid_fields, PEM_EventDataValid_RequestedStateID);
122 else
123 pem_unset_event_data_valid(event_data->valid_fields, PEM_EventDataValid_RequestedStateID);
125 return result;
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);
152 return 0;
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);
158 return 0;
161 int pem_task_start_asic_block_usage(struct pp_eventmgr *eventmgr, struct pem_event_data *event_data)
163 /* TODO */
164 return 0;
167 int pem_task_stop_asic_block_usage(struct pp_eventmgr *eventmgr, struct pem_event_data *event_data)
169 /* TODO */
170 return 0;
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)
180 /* TODO */
181 return 0;
184 int pem_task_store_dal_configuration(struct pp_eventmgr *eventmgr, const struct amd_display_configuration *display_config)
186 /* TODO */
187 return 0;
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))
194 return 0;
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)
201 return 0;
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))
207 return 0;
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);*/
216 return 0;
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;
222 return 0;
225 int pem_task_notify_power_state_change(struct pp_eventmgr *eventmgr, struct pem_event_data *event_data)
227 /* TODO */
228 return 0;
231 int pem_task_block_hw_access(struct pp_eventmgr *eventmgr, struct pem_event_data *event_data)
233 /* TODO */
234 return 0;
237 int pem_task_un_block_hw_access(struct pp_eventmgr *eventmgr, struct pem_event_data *event_data)
239 /* TODO */
240 return 0;
243 int pem_task_reset_display_phys_access(struct pp_eventmgr *eventmgr, struct pem_event_data *event_data)
245 /* TODO */
246 return 0;
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);
254 /*powersaving*/
256 int pem_task_set_power_source(struct pp_eventmgr *eventmgr, struct pem_event_data *event_data)
258 /* TODO */
259 return 0;
262 int pem_task_notify_hw_of_power_source(struct pp_eventmgr *eventmgr, struct pem_event_data *event_data)
264 /* TODO */
265 return 0;
268 int pem_task_get_power_saving_state(struct pp_eventmgr *eventmgr, struct pem_event_data *event_data)
270 /* TODO */
271 return 0;
274 int pem_task_reset_power_saving_state(struct pp_eventmgr *eventmgr, struct pem_event_data *event_data)
276 /* TODO */
277 return 0;
280 int pem_task_set_power_saving_state(struct pp_eventmgr *eventmgr, struct pem_event_data *event_data)
282 /* TODO */
283 return 0;
286 int pem_task_set_screen_state_on(struct pp_eventmgr *eventmgr, struct pem_event_data *event_data)
288 /* TODO */
289 return 0;
292 int pem_task_set_screen_state_off(struct pp_eventmgr *eventmgr, struct pem_event_data *event_data)
294 /* TODO */
295 return 0;
298 int pem_task_enable_voltage_island_power_gating(struct pp_eventmgr *eventmgr, struct pem_event_data *event_data)
300 /* TODO */
301 return 0;
304 int pem_task_disable_voltage_island_power_gating(struct pp_eventmgr *eventmgr, struct pem_event_data *event_data)
306 /* TODO */
307 return 0;
310 int pem_task_enable_cgpg(struct pp_eventmgr *eventmgr, struct pem_event_data *event_data)
312 /* TODO */
313 return 0;
316 int pem_task_disable_cgpg(struct pp_eventmgr *eventmgr, struct pem_event_data *event_data)
318 /* TODO */
319 return 0;
322 int pem_task_enable_clock_power_gating(struct pp_eventmgr *eventmgr, struct pem_event_data *event_data)
324 /* TODO */
325 return 0;
329 int pem_task_enable_gfx_clock_gating(struct pp_eventmgr *eventmgr, struct pem_event_data *event_data)
331 /* TODO */
332 return 0;
335 int pem_task_disable_gfx_clock_gating(struct pp_eventmgr *eventmgr, struct pem_event_data *event_data)
337 /* TODO */
338 return 0;
342 /* performance */
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));
348 return 0;
351 int pem_task_conditionally_force_3d_performance_state(struct pp_eventmgr *eventmgr, struct pem_event_data *event_data)
353 /* TODO */
354 return 0;
357 int pem_task_enable_stutter_mode(struct pp_eventmgr *eventmgr, struct pem_event_data *event_data)
359 /* TODO */
360 return 0;
363 int pem_task_get_2D_performance_state_id(struct pp_eventmgr *eventmgr, struct pem_event_data *event_data)
365 int result;
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));
376 else
377 result = psm_get_ui_state(eventmgr, PP_StateUILabel_Performance,
378 &(event_data->requested_state_id));
380 if (0 == result)
381 pem_set_event_data_valid(event_data->valid_fields, PEM_EventDataValid_RequestedStateID);
382 else
383 pem_unset_event_data_valid(event_data->valid_fields, PEM_EventDataValid_RequestedStateID);
385 return result;
388 int pem_task_create_user_performance_state(struct pp_eventmgr *eventmgr, struct pem_event_data *event_data)
390 struct pp_power_state *state;
391 int table_entries;
392 struct pp_hwmgr *hwmgr = eventmgr->hwmgr;
393 int i;
395 table_entries = hwmgr->num_ps;
396 state = hwmgr->ps;
398 restart_search:
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;
402 return 0;
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;
411 goto restart_search;
412 default:
413 break;
415 return -1;
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)
426 return -EINVAL;
428 if (phm_cap_enabled(eventmgr->platform_descriptor->platformCaps, PHM_PlatformCaps_ThermalController))
429 return phm_start_thermal_controller(eventmgr->hwmgr, &range);
431 return 0;
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);