Path: blob/master/drivers/gpu/drm/amd/pm/powerplay/smumgr/smumgr.c
26552 views
/*1* Copyright 2015 Advanced Micro Devices, Inc.2*3* Permission is hereby granted, free of charge, to any person obtaining a4* copy of this software and associated documentation files (the "Software"),5* to deal in the Software without restriction, including without limitation6* the rights to use, copy, modify, merge, publish, distribute, sublicense,7* and/or sell copies of the Software, and to permit persons to whom the8* Software is furnished to do so, subject to the following conditions:9*10* The above copyright notice and this permission notice shall be included in11* all copies or substantial portions of the Software.12*13* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR14* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,15* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL16* THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR17* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,18* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR19* OTHER DEALINGS IN THE SOFTWARE.20*21*/2223#include <linux/delay.h>24#include <linux/kernel.h>25#include <linux/module.h>26#include <linux/slab.h>27#include <linux/types.h>28#include <drm/amdgpu_drm.h>29#include "smumgr.h"3031MODULE_FIRMWARE("amdgpu/bonaire_smc.bin");32MODULE_FIRMWARE("amdgpu/bonaire_k_smc.bin");33MODULE_FIRMWARE("amdgpu/hawaii_smc.bin");34MODULE_FIRMWARE("amdgpu/hawaii_k_smc.bin");35MODULE_FIRMWARE("amdgpu/topaz_smc.bin");36MODULE_FIRMWARE("amdgpu/topaz_k_smc.bin");37MODULE_FIRMWARE("amdgpu/tonga_smc.bin");38MODULE_FIRMWARE("amdgpu/tonga_k_smc.bin");39MODULE_FIRMWARE("amdgpu/fiji_smc.bin");40MODULE_FIRMWARE("amdgpu/polaris10_smc.bin");41MODULE_FIRMWARE("amdgpu/polaris10_smc_sk.bin");42MODULE_FIRMWARE("amdgpu/polaris10_k_smc.bin");43MODULE_FIRMWARE("amdgpu/polaris10_k2_smc.bin");44MODULE_FIRMWARE("amdgpu/polaris11_smc.bin");45MODULE_FIRMWARE("amdgpu/polaris11_smc_sk.bin");46MODULE_FIRMWARE("amdgpu/polaris11_k_smc.bin");47MODULE_FIRMWARE("amdgpu/polaris11_k2_smc.bin");48MODULE_FIRMWARE("amdgpu/polaris12_smc.bin");49MODULE_FIRMWARE("amdgpu/polaris12_k_smc.bin");50MODULE_FIRMWARE("amdgpu/vegam_smc.bin");51MODULE_FIRMWARE("amdgpu/vega10_smc.bin");52MODULE_FIRMWARE("amdgpu/vega10_acg_smc.bin");53MODULE_FIRMWARE("amdgpu/vega12_smc.bin");54MODULE_FIRMWARE("amdgpu/vega20_smc.bin");5556int smum_thermal_avfs_enable(struct pp_hwmgr *hwmgr)57{58if (NULL != hwmgr->smumgr_funcs->thermal_avfs_enable)59return hwmgr->smumgr_funcs->thermal_avfs_enable(hwmgr);6061return 0;62}6364int smum_thermal_setup_fan_table(struct pp_hwmgr *hwmgr)65{66if (NULL != hwmgr->smumgr_funcs->thermal_setup_fan_table)67return hwmgr->smumgr_funcs->thermal_setup_fan_table(hwmgr);6869return 0;70}7172int smum_update_sclk_threshold(struct pp_hwmgr *hwmgr)73{7475if (NULL != hwmgr->smumgr_funcs->update_sclk_threshold)76return hwmgr->smumgr_funcs->update_sclk_threshold(hwmgr);7778return 0;79}8081int smum_update_smc_table(struct pp_hwmgr *hwmgr, uint32_t type)82{8384if (NULL != hwmgr->smumgr_funcs->update_smc_table)85return hwmgr->smumgr_funcs->update_smc_table(hwmgr, type);8687return 0;88}8990uint32_t smum_get_offsetof(struct pp_hwmgr *hwmgr, uint32_t type, uint32_t member)91{92if (NULL != hwmgr->smumgr_funcs->get_offsetof)93return hwmgr->smumgr_funcs->get_offsetof(type, member);9495return 0;96}9798int smum_process_firmware_header(struct pp_hwmgr *hwmgr)99{100if (NULL != hwmgr->smumgr_funcs->process_firmware_header)101return hwmgr->smumgr_funcs->process_firmware_header(hwmgr);102return 0;103}104105uint32_t smum_get_mac_definition(struct pp_hwmgr *hwmgr, uint32_t value)106{107if (NULL != hwmgr->smumgr_funcs->get_mac_definition)108return hwmgr->smumgr_funcs->get_mac_definition(value);109110return 0;111}112113int smum_download_powerplay_table(struct pp_hwmgr *hwmgr, void **table)114{115if (NULL != hwmgr->smumgr_funcs->download_pptable_settings)116return hwmgr->smumgr_funcs->download_pptable_settings(hwmgr,117table);118return 0;119}120121int smum_upload_powerplay_table(struct pp_hwmgr *hwmgr)122{123if (NULL != hwmgr->smumgr_funcs->upload_pptable_settings)124return hwmgr->smumgr_funcs->upload_pptable_settings(hwmgr);125126return 0;127}128129int smum_send_msg_to_smc(struct pp_hwmgr *hwmgr, uint16_t msg, uint32_t *resp)130{131int ret = 0;132133if (hwmgr == NULL ||134hwmgr->smumgr_funcs->send_msg_to_smc == NULL ||135(resp && !hwmgr->smumgr_funcs->get_argument))136return -EINVAL;137138mutex_lock(&hwmgr->msg_lock);139140ret = hwmgr->smumgr_funcs->send_msg_to_smc(hwmgr, msg);141if (ret) {142mutex_unlock(&hwmgr->msg_lock);143return ret;144}145146if (resp)147*resp = hwmgr->smumgr_funcs->get_argument(hwmgr);148149mutex_unlock(&hwmgr->msg_lock);150151return ret;152}153154int smum_send_msg_to_smc_with_parameter(struct pp_hwmgr *hwmgr,155uint16_t msg,156uint32_t parameter,157uint32_t *resp)158{159int ret = 0;160161if (hwmgr == NULL ||162hwmgr->smumgr_funcs->send_msg_to_smc_with_parameter == NULL ||163(resp && !hwmgr->smumgr_funcs->get_argument))164return -EINVAL;165166mutex_lock(&hwmgr->msg_lock);167168ret = hwmgr->smumgr_funcs->send_msg_to_smc_with_parameter(169hwmgr, msg, parameter);170if (ret) {171mutex_unlock(&hwmgr->msg_lock);172return ret;173}174175if (resp)176*resp = hwmgr->smumgr_funcs->get_argument(hwmgr);177178mutex_unlock(&hwmgr->msg_lock);179180return ret;181}182183int smum_init_smc_table(struct pp_hwmgr *hwmgr)184{185if (NULL != hwmgr->smumgr_funcs->init_smc_table)186return hwmgr->smumgr_funcs->init_smc_table(hwmgr);187188return 0;189}190191int smum_populate_all_graphic_levels(struct pp_hwmgr *hwmgr)192{193if (NULL != hwmgr->smumgr_funcs->populate_all_graphic_levels)194return hwmgr->smumgr_funcs->populate_all_graphic_levels(hwmgr);195196return 0;197}198199int smum_populate_all_memory_levels(struct pp_hwmgr *hwmgr)200{201if (NULL != hwmgr->smumgr_funcs->populate_all_memory_levels)202return hwmgr->smumgr_funcs->populate_all_memory_levels(hwmgr);203204return 0;205}206207/*this interface is needed by island ci/vi */208int smum_initialize_mc_reg_table(struct pp_hwmgr *hwmgr)209{210if (NULL != hwmgr->smumgr_funcs->initialize_mc_reg_table)211return hwmgr->smumgr_funcs->initialize_mc_reg_table(hwmgr);212213return 0;214}215216bool smum_is_dpm_running(struct pp_hwmgr *hwmgr)217{218if (NULL != hwmgr->smumgr_funcs->is_dpm_running)219return hwmgr->smumgr_funcs->is_dpm_running(hwmgr);220221return true;222}223224bool smum_is_hw_avfs_present(struct pp_hwmgr *hwmgr)225{226if (hwmgr->smumgr_funcs->is_hw_avfs_present)227return hwmgr->smumgr_funcs->is_hw_avfs_present(hwmgr);228229return false;230}231232int smum_update_dpm_settings(struct pp_hwmgr *hwmgr, void *profile_setting)233{234if (hwmgr->smumgr_funcs->update_dpm_settings)235return hwmgr->smumgr_funcs->update_dpm_settings(hwmgr, profile_setting);236237return -EINVAL;238}239240int smum_smc_table_manager(struct pp_hwmgr *hwmgr, uint8_t *table, uint16_t table_id, bool rw)241{242if (hwmgr->smumgr_funcs->smc_table_manager)243return hwmgr->smumgr_funcs->smc_table_manager(hwmgr, table, table_id, rw);244245return -EINVAL;246}247248int smum_stop_smc(struct pp_hwmgr *hwmgr)249{250if (hwmgr->smumgr_funcs->stop_smc)251return hwmgr->smumgr_funcs->stop_smc(hwmgr);252253return 0;254}255256257