123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446 |
- /*
- * Copyright 2015 Advanced Micro Devices, Inc.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
- * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
- * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
- * OTHER DEALINGS IN THE SOFTWARE.
- *
- */
- #include "eventmgr.h"
- #include "eventinit.h"
- #include "eventmanagement.h"
- #include "eventmanager.h"
- #include "hardwaremanager.h"
- #include "eventtasks.h"
- #include "power_state.h"
- #include "hwmgr.h"
- #include "amd_powerplay.h"
- #include "psm.h"
- #define TEMP_RANGE_MIN (90 * 1000)
- #define TEMP_RANGE_MAX (120 * 1000)
- int pem_task_update_allowed_performance_levels(struct pp_eventmgr *eventmgr, struct pem_event_data *event_data)
- {
- if (eventmgr == NULL || eventmgr->hwmgr == NULL)
- return -EINVAL;
- if (pem_is_hw_access_blocked(eventmgr))
- return 0;
- phm_force_dpm_levels(eventmgr->hwmgr, eventmgr->hwmgr->dpm_level);
- return 0;
- }
- /* eventtasks_generic.c */
- int pem_task_adjust_power_state(struct pp_eventmgr *eventmgr, struct pem_event_data *event_data)
- {
- struct pp_hwmgr *hwmgr;
- if (pem_is_hw_access_blocked(eventmgr))
- return 0;
- hwmgr = eventmgr->hwmgr;
- if (event_data->pnew_power_state != NULL)
- hwmgr->request_ps = event_data->pnew_power_state;
- if (phm_cap_enabled(eventmgr->platform_descriptor->platformCaps, PHM_PlatformCaps_DynamicPatchPowerState))
- psm_adjust_power_state_dynamic(eventmgr, event_data->skip_state_adjust_rules);
- else
- psm_adjust_power_state_static(eventmgr, event_data->skip_state_adjust_rules);
- return 0;
- }
- int pem_task_power_down_asic(struct pp_eventmgr *eventmgr, struct pem_event_data *event_data)
- {
- return phm_power_down_asic(eventmgr->hwmgr);
- }
- int pem_task_set_boot_state(struct pp_eventmgr *eventmgr, struct pem_event_data *event_data)
- {
- if (pem_is_event_data_valid(event_data->valid_fields, PEM_EventDataValid_RequestedStateID))
- return psm_set_states(eventmgr, &(event_data->requested_state_id));
- return 0;
- }
- int pem_task_reset_boot_state(struct pp_eventmgr *eventmgr, struct pem_event_data *event_data)
- {
- /* TODO */
- return 0;
- }
- int pem_task_update_new_power_state_clocks(struct pp_eventmgr *eventmgr, struct pem_event_data *event_data)
- {
- /* TODO */
- return 0;
- }
- int pem_task_system_shutdown(struct pp_eventmgr *eventmgr, struct pem_event_data *event_data)
- {
- /* TODO */
- return 0;
- }
- int pem_task_register_interrupts(struct pp_eventmgr *eventmgr, struct pem_event_data *event_data)
- {
- /* TODO */
- return 0;
- }
- int pem_task_unregister_interrupts(struct pp_eventmgr *eventmgr, struct pem_event_data *event_data)
- {
- return pem_unregister_interrupts(eventmgr);
- }
- int pem_task_get_boot_state_id(struct pp_eventmgr *eventmgr, struct pem_event_data *event_data)
- {
- int result;
- result = psm_get_state_by_classification(eventmgr,
- PP_StateClassificationFlag_Boot,
- &(event_data->requested_state_id)
- );
- if (0 == result)
- pem_set_event_data_valid(event_data->valid_fields, PEM_EventDataValid_RequestedStateID);
- else
- pem_unset_event_data_valid(event_data->valid_fields, PEM_EventDataValid_RequestedStateID);
- return result;
- }
- int pem_task_enable_dynamic_state_management(struct pp_eventmgr *eventmgr, struct pem_event_data *event_data)
- {
- return phm_enable_dynamic_state_management(eventmgr->hwmgr);
- }
- int pem_task_disable_dynamic_state_management(struct pp_eventmgr *eventmgr, struct pem_event_data *event_data)
- {
- return phm_disable_dynamic_state_management(eventmgr->hwmgr);
- }
- int pem_task_enable_clock_power_gatings_tasks(struct pp_eventmgr *eventmgr, struct pem_event_data *event_data)
- {
- return phm_enable_clock_power_gatings(eventmgr->hwmgr);
- }
- int pem_task_powerdown_uvd_tasks(struct pp_eventmgr *eventmgr, struct pem_event_data *event_data)
- {
- return phm_powerdown_uvd(eventmgr->hwmgr);
- }
- int pem_task_powerdown_vce_tasks(struct pp_eventmgr *eventmgr, struct pem_event_data *event_data)
- {
- phm_powergate_uvd(eventmgr->hwmgr, true);
- phm_powergate_vce(eventmgr->hwmgr, true);
- return 0;
- }
- int pem_task_disable_clock_power_gatings_tasks(struct pp_eventmgr *eventmgr, struct pem_event_data *event_data)
- {
- phm_disable_clock_power_gatings(eventmgr->hwmgr);
- return 0;
- }
- int pem_task_start_asic_block_usage(struct pp_eventmgr *eventmgr, struct pem_event_data *event_data)
- {
- /* TODO */
- return 0;
- }
- int pem_task_stop_asic_block_usage(struct pp_eventmgr *eventmgr, struct pem_event_data *event_data)
- {
- /* TODO */
- return 0;
- }
- int pem_task_disable_smc_firmware_ctf(struct pp_eventmgr *eventmgr, struct pem_event_data *event_data)
- {
- return phm_disable_smc_firmware_ctf(eventmgr->hwmgr);
- }
- int pem_task_setup_asic(struct pp_eventmgr *eventmgr, struct pem_event_data *event_data)
- {
- return phm_setup_asic(eventmgr->hwmgr);
- }
- int pem_task_cleanup_asic(struct pp_eventmgr *eventmgr, struct pem_event_data *event_data)
- {
- /* TODO */
- return 0;
- }
- int pem_task_store_dal_configuration(struct pp_eventmgr *eventmgr, const struct amd_display_configuration *display_config)
- {
- /* TODO */
- return 0;
- /*phm_store_dal_configuration_data(eventmgr->hwmgr, display_config) */
- }
- int pem_task_notify_hw_mgr_display_configuration_change(struct pp_eventmgr *eventmgr, struct pem_event_data *event_data)
- {
- if (pem_is_hw_access_blocked(eventmgr))
- return 0;
- return phm_display_configuration_changed(eventmgr->hwmgr);
- }
- int pem_task_notify_hw_mgr_pre_display_configuration_change(struct pp_eventmgr *eventmgr, struct pem_event_data *event_data)
- {
- return 0;
- }
- int pem_task_notify_smc_display_config_after_power_state_adjustment(struct pp_eventmgr *eventmgr, struct pem_event_data *event_data)
- {
- if (pem_is_hw_access_blocked(eventmgr))
- return 0;
- return phm_notify_smc_display_config_after_ps_adjustment(eventmgr->hwmgr);
- }
- int pem_task_block_adjust_power_state(struct pp_eventmgr *eventmgr, struct pem_event_data *event_data)
- {
- eventmgr->block_adjust_power_state = true;
- /* to do PHM_ResetIPSCounter(pEventMgr->pHwMgr);*/
- return 0;
- }
- int pem_task_unblock_adjust_power_state(struct pp_eventmgr *eventmgr, struct pem_event_data *event_data)
- {
- eventmgr->block_adjust_power_state = false;
- return 0;
- }
- int pem_task_notify_power_state_change(struct pp_eventmgr *eventmgr, struct pem_event_data *event_data)
- {
- /* TODO */
- return 0;
- }
- int pem_task_block_hw_access(struct pp_eventmgr *eventmgr, struct pem_event_data *event_data)
- {
- /* TODO */
- return 0;
- }
- int pem_task_un_block_hw_access(struct pp_eventmgr *eventmgr, struct pem_event_data *event_data)
- {
- /* TODO */
- return 0;
- }
- int pem_task_reset_display_phys_access(struct pp_eventmgr *eventmgr, struct pem_event_data *event_data)
- {
- /* TODO */
- return 0;
- }
- int pem_task_set_cpu_power_state(struct pp_eventmgr *eventmgr, struct pem_event_data *event_data)
- {
- return phm_set_cpu_power_state(eventmgr->hwmgr);
- }
- /*powersaving*/
- int pem_task_set_power_source(struct pp_eventmgr *eventmgr, struct pem_event_data *event_data)
- {
- /* TODO */
- return 0;
- }
- int pem_task_notify_hw_of_power_source(struct pp_eventmgr *eventmgr, struct pem_event_data *event_data)
- {
- /* TODO */
- return 0;
- }
- int pem_task_get_power_saving_state(struct pp_eventmgr *eventmgr, struct pem_event_data *event_data)
- {
- /* TODO */
- return 0;
- }
- int pem_task_reset_power_saving_state(struct pp_eventmgr *eventmgr, struct pem_event_data *event_data)
- {
- /* TODO */
- return 0;
- }
- int pem_task_set_power_saving_state(struct pp_eventmgr *eventmgr, struct pem_event_data *event_data)
- {
- /* TODO */
- return 0;
- }
- int pem_task_set_screen_state_on(struct pp_eventmgr *eventmgr, struct pem_event_data *event_data)
- {
- /* TODO */
- return 0;
- }
- int pem_task_set_screen_state_off(struct pp_eventmgr *eventmgr, struct pem_event_data *event_data)
- {
- /* TODO */
- return 0;
- }
- int pem_task_enable_voltage_island_power_gating(struct pp_eventmgr *eventmgr, struct pem_event_data *event_data)
- {
- /* TODO */
- return 0;
- }
- int pem_task_disable_voltage_island_power_gating(struct pp_eventmgr *eventmgr, struct pem_event_data *event_data)
- {
- /* TODO */
- return 0;
- }
- int pem_task_enable_cgpg(struct pp_eventmgr *eventmgr, struct pem_event_data *event_data)
- {
- /* TODO */
- return 0;
- }
- int pem_task_disable_cgpg(struct pp_eventmgr *eventmgr, struct pem_event_data *event_data)
- {
- /* TODO */
- return 0;
- }
- int pem_task_enable_clock_power_gating(struct pp_eventmgr *eventmgr, struct pem_event_data *event_data)
- {
- /* TODO */
- return 0;
- }
- int pem_task_enable_gfx_clock_gating(struct pp_eventmgr *eventmgr, struct pem_event_data *event_data)
- {
- /* TODO */
- return 0;
- }
- int pem_task_disable_gfx_clock_gating(struct pp_eventmgr *eventmgr, struct pem_event_data *event_data)
- {
- /* TODO */
- return 0;
- }
- /* performance */
- int pem_task_set_performance_state(struct pp_eventmgr *eventmgr, struct pem_event_data *event_data)
- {
- if (pem_is_event_data_valid(event_data->valid_fields, PEM_EventDataValid_RequestedStateID))
- return psm_set_states(eventmgr, &(event_data->requested_state_id));
- return 0;
- }
- int pem_task_conditionally_force_3d_performance_state(struct pp_eventmgr *eventmgr, struct pem_event_data *event_data)
- {
- /* TODO */
- return 0;
- }
- int pem_task_enable_stutter_mode(struct pp_eventmgr *eventmgr, struct pem_event_data *event_data)
- {
- /* TODO */
- return 0;
- }
- int pem_task_get_2D_performance_state_id(struct pp_eventmgr *eventmgr, struct pem_event_data *event_data)
- {
- int result;
- if (eventmgr->features[PP_Feature_PowerPlay].supported &&
- !(eventmgr->features[PP_Feature_PowerPlay].enabled))
- result = psm_get_state_by_classification(eventmgr,
- PP_StateClassificationFlag_Boot,
- &(event_data->requested_state_id));
- else if (eventmgr->features[PP_Feature_User2DPerformance].enabled)
- result = psm_get_state_by_classification(eventmgr,
- PP_StateClassificationFlag_User2DPerformance,
- &(event_data->requested_state_id));
- else
- result = psm_get_ui_state(eventmgr, PP_StateUILabel_Performance,
- &(event_data->requested_state_id));
- if (0 == result)
- pem_set_event_data_valid(event_data->valid_fields, PEM_EventDataValid_RequestedStateID);
- else
- pem_unset_event_data_valid(event_data->valid_fields, PEM_EventDataValid_RequestedStateID);
- return result;
- }
- int pem_task_create_user_performance_state(struct pp_eventmgr *eventmgr, struct pem_event_data *event_data)
- {
- struct pp_power_state *state;
- int table_entries;
- struct pp_hwmgr *hwmgr = eventmgr->hwmgr;
- int i;
- table_entries = hwmgr->num_ps;
- state = hwmgr->ps;
- restart_search:
- for (i = 0; i < table_entries; i++) {
- if (state->classification.ui_label & event_data->requested_ui_label) {
- event_data->pnew_power_state = state;
- return 0;
- }
- state = (struct pp_power_state *)((unsigned long)state + hwmgr->ps_size);
- }
- switch (event_data->requested_ui_label) {
- case PP_StateUILabel_Battery:
- case PP_StateUILabel_Balanced:
- event_data->requested_ui_label = PP_StateUILabel_Performance;
- goto restart_search;
- default:
- break;
- }
- return -1;
- }
- int pem_task_initialize_thermal_controller(struct pp_eventmgr *eventmgr, struct pem_event_data *event_data)
- {
- struct PP_TemperatureRange range;
- range.max = TEMP_RANGE_MAX;
- range.min = TEMP_RANGE_MIN;
- if (eventmgr == NULL || eventmgr->platform_descriptor == NULL)
- return -EINVAL;
- if (phm_cap_enabled(eventmgr->platform_descriptor->platformCaps, PHM_PlatformCaps_ThermalController))
- return phm_start_thermal_controller(eventmgr->hwmgr, &range);
- return 0;
- }
- int pem_task_uninitialize_thermal_controller(struct pp_eventmgr *eventmgr, struct pem_event_data *event_data)
- {
- return phm_stop_thermal_controller(eventmgr->hwmgr);
- }
|