123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498 |
- /*
- * Copyright 2016 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 "smu7_hwmgr.h"
- #include "smu7_clockpowergating.h"
- #include "smu7_common.h"
- static int smu7_enable_disable_uvd_dpm(struct pp_hwmgr *hwmgr, bool enable)
- {
- return smum_send_msg_to_smc(hwmgr->smumgr, enable ?
- PPSMC_MSG_UVDDPM_Enable :
- PPSMC_MSG_UVDDPM_Disable);
- }
- static int smu7_enable_disable_vce_dpm(struct pp_hwmgr *hwmgr, bool enable)
- {
- return smum_send_msg_to_smc(hwmgr->smumgr, enable ?
- PPSMC_MSG_VCEDPM_Enable :
- PPSMC_MSG_VCEDPM_Disable);
- }
- static int smu7_enable_disable_samu_dpm(struct pp_hwmgr *hwmgr, bool enable)
- {
- return smum_send_msg_to_smc(hwmgr->smumgr, enable ?
- PPSMC_MSG_SAMUDPM_Enable :
- PPSMC_MSG_SAMUDPM_Disable);
- }
- static int smu7_update_uvd_dpm(struct pp_hwmgr *hwmgr, bool bgate)
- {
- if (!bgate)
- smum_update_smc_table(hwmgr, SMU_UVD_TABLE);
- return smu7_enable_disable_uvd_dpm(hwmgr, !bgate);
- }
- static int smu7_update_vce_dpm(struct pp_hwmgr *hwmgr, bool bgate)
- {
- if (!bgate)
- smum_update_smc_table(hwmgr, SMU_VCE_TABLE);
- return smu7_enable_disable_vce_dpm(hwmgr, !bgate);
- }
- static int smu7_update_samu_dpm(struct pp_hwmgr *hwmgr, bool bgate)
- {
- if (!bgate)
- smum_update_smc_table(hwmgr, SMU_SAMU_TABLE);
- return smu7_enable_disable_samu_dpm(hwmgr, !bgate);
- }
- int smu7_powerdown_uvd(struct pp_hwmgr *hwmgr)
- {
- if (phm_cf_want_uvd_power_gating(hwmgr))
- return smum_send_msg_to_smc(hwmgr->smumgr,
- PPSMC_MSG_UVDPowerOFF);
- return 0;
- }
- static int smu7_powerup_uvd(struct pp_hwmgr *hwmgr)
- {
- if (phm_cf_want_uvd_power_gating(hwmgr)) {
- if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
- PHM_PlatformCaps_UVDDynamicPowerGating)) {
- return smum_send_msg_to_smc_with_parameter(hwmgr->smumgr,
- PPSMC_MSG_UVDPowerON, 1);
- } else {
- return smum_send_msg_to_smc_with_parameter(hwmgr->smumgr,
- PPSMC_MSG_UVDPowerON, 0);
- }
- }
- return 0;
- }
- static int smu7_powerdown_vce(struct pp_hwmgr *hwmgr)
- {
- if (phm_cf_want_vce_power_gating(hwmgr))
- return smum_send_msg_to_smc(hwmgr->smumgr,
- PPSMC_MSG_VCEPowerOFF);
- return 0;
- }
- static int smu7_powerup_vce(struct pp_hwmgr *hwmgr)
- {
- if (phm_cf_want_vce_power_gating(hwmgr))
- return smum_send_msg_to_smc(hwmgr->smumgr,
- PPSMC_MSG_VCEPowerON);
- return 0;
- }
- static int smu7_powerdown_samu(struct pp_hwmgr *hwmgr)
- {
- if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
- PHM_PlatformCaps_SamuPowerGating))
- return smum_send_msg_to_smc(hwmgr->smumgr,
- PPSMC_MSG_SAMPowerOFF);
- return 0;
- }
- static int smu7_powerup_samu(struct pp_hwmgr *hwmgr)
- {
- if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
- PHM_PlatformCaps_SamuPowerGating))
- return smum_send_msg_to_smc(hwmgr->smumgr,
- PPSMC_MSG_SAMPowerON);
- return 0;
- }
- int smu7_disable_clock_power_gating(struct pp_hwmgr *hwmgr)
- {
- struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
- data->uvd_power_gated = false;
- data->vce_power_gated = false;
- data->samu_power_gated = false;
- smu7_powerup_uvd(hwmgr);
- smu7_powerup_vce(hwmgr);
- smu7_powerup_samu(hwmgr);
- return 0;
- }
- int smu7_powergate_uvd(struct pp_hwmgr *hwmgr, bool bgate)
- {
- struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
- data->uvd_power_gated = bgate;
- if (bgate) {
- cgs_set_powergating_state(hwmgr->device,
- AMD_IP_BLOCK_TYPE_UVD,
- AMD_PG_STATE_GATE);
- cgs_set_clockgating_state(hwmgr->device,
- AMD_IP_BLOCK_TYPE_UVD,
- AMD_CG_STATE_GATE);
- smu7_update_uvd_dpm(hwmgr, true);
- smu7_powerdown_uvd(hwmgr);
- } else {
- smu7_powerup_uvd(hwmgr);
- cgs_set_clockgating_state(hwmgr->device,
- AMD_IP_BLOCK_TYPE_UVD,
- AMD_CG_STATE_UNGATE);
- cgs_set_powergating_state(hwmgr->device,
- AMD_IP_BLOCK_TYPE_UVD,
- AMD_PG_STATE_UNGATE);
- smu7_update_uvd_dpm(hwmgr, false);
- }
- return 0;
- }
- int smu7_powergate_vce(struct pp_hwmgr *hwmgr, bool bgate)
- {
- struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
- data->vce_power_gated = bgate;
- if (bgate) {
- cgs_set_powergating_state(hwmgr->device,
- AMD_IP_BLOCK_TYPE_VCE,
- AMD_PG_STATE_GATE);
- cgs_set_clockgating_state(hwmgr->device,
- AMD_IP_BLOCK_TYPE_VCE,
- AMD_CG_STATE_GATE);
- smu7_update_vce_dpm(hwmgr, true);
- smu7_powerdown_vce(hwmgr);
- } else {
- smu7_powerup_vce(hwmgr);
- cgs_set_clockgating_state(hwmgr->device,
- AMD_IP_BLOCK_TYPE_VCE,
- AMD_CG_STATE_UNGATE);
- cgs_set_powergating_state(hwmgr->device,
- AMD_IP_BLOCK_TYPE_VCE,
- AMD_PG_STATE_UNGATE);
- smu7_update_vce_dpm(hwmgr, false);
- }
- return 0;
- }
- int smu7_powergate_samu(struct pp_hwmgr *hwmgr, bool bgate)
- {
- struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
- if (data->samu_power_gated == bgate)
- return 0;
- data->samu_power_gated = bgate;
- if (bgate) {
- smu7_update_samu_dpm(hwmgr, true);
- smu7_powerdown_samu(hwmgr);
- } else {
- smu7_powerup_samu(hwmgr);
- smu7_update_samu_dpm(hwmgr, false);
- }
- return 0;
- }
- int smu7_update_clock_gatings(struct pp_hwmgr *hwmgr,
- const uint32_t *msg_id)
- {
- PPSMC_Msg msg;
- uint32_t value;
- if (!(hwmgr->feature_mask & PP_ENABLE_GFX_CG_THRU_SMU))
- return 0;
- switch ((*msg_id & PP_GROUP_MASK) >> PP_GROUP_SHIFT) {
- case PP_GROUP_GFX:
- switch ((*msg_id & PP_BLOCK_MASK) >> PP_BLOCK_SHIFT) {
- case PP_BLOCK_GFX_CG:
- if (PP_STATE_SUPPORT_CG & *msg_id) {
- msg = ((*msg_id & PP_STATE_MASK) & PP_STATE_CG) ?
- PPSMC_MSG_EnableClockGatingFeature :
- PPSMC_MSG_DisableClockGatingFeature;
- value = CG_GFX_CGCG_MASK;
- if (smum_send_msg_to_smc_with_parameter(
- hwmgr->smumgr, msg, value))
- return -EINVAL;
- }
- if (PP_STATE_SUPPORT_LS & *msg_id) {
- msg = (*msg_id & PP_STATE_MASK) & PP_STATE_LS
- ? PPSMC_MSG_EnableClockGatingFeature
- : PPSMC_MSG_DisableClockGatingFeature;
- value = CG_GFX_CGLS_MASK;
- if (smum_send_msg_to_smc_with_parameter(
- hwmgr->smumgr, msg, value))
- return -EINVAL;
- }
- break;
- case PP_BLOCK_GFX_3D:
- if (PP_STATE_SUPPORT_CG & *msg_id) {
- msg = ((*msg_id & PP_STATE_MASK) & PP_STATE_CG) ?
- PPSMC_MSG_EnableClockGatingFeature :
- PPSMC_MSG_DisableClockGatingFeature;
- value = CG_GFX_3DCG_MASK;
- if (smum_send_msg_to_smc_with_parameter(
- hwmgr->smumgr, msg, value))
- return -EINVAL;
- }
- if (PP_STATE_SUPPORT_LS & *msg_id) {
- msg = (*msg_id & PP_STATE_MASK) & PP_STATE_LS ?
- PPSMC_MSG_EnableClockGatingFeature :
- PPSMC_MSG_DisableClockGatingFeature;
- value = CG_GFX_3DLS_MASK;
- if (smum_send_msg_to_smc_with_parameter(
- hwmgr->smumgr, msg, value))
- return -EINVAL;
- }
- break;
- case PP_BLOCK_GFX_RLC:
- if (PP_STATE_SUPPORT_LS & *msg_id) {
- msg = (*msg_id & PP_STATE_MASK) & PP_STATE_LS ?
- PPSMC_MSG_EnableClockGatingFeature :
- PPSMC_MSG_DisableClockGatingFeature;
- value = CG_GFX_RLC_LS_MASK;
- if (smum_send_msg_to_smc_with_parameter(
- hwmgr->smumgr, msg, value))
- return -EINVAL;
- }
- break;
- case PP_BLOCK_GFX_CP:
- if (PP_STATE_SUPPORT_LS & *msg_id) {
- msg = (*msg_id & PP_STATE_MASK) & PP_STATE_LS ?
- PPSMC_MSG_EnableClockGatingFeature :
- PPSMC_MSG_DisableClockGatingFeature;
- value = CG_GFX_CP_LS_MASK;
- if (smum_send_msg_to_smc_with_parameter(
- hwmgr->smumgr, msg, value))
- return -EINVAL;
- }
- break;
- case PP_BLOCK_GFX_MG:
- if (PP_STATE_SUPPORT_CG & *msg_id) {
- msg = ((*msg_id & PP_STATE_MASK) & PP_STATE_CG) ?
- PPSMC_MSG_EnableClockGatingFeature :
- PPSMC_MSG_DisableClockGatingFeature;
- value = (CG_CPF_MGCG_MASK | CG_RLC_MGCG_MASK |
- CG_GFX_OTHERS_MGCG_MASK);
- if (smum_send_msg_to_smc_with_parameter(
- hwmgr->smumgr, msg, value))
- return -EINVAL;
- }
- break;
- default:
- return -EINVAL;
- }
- break;
- case PP_GROUP_SYS:
- switch ((*msg_id & PP_BLOCK_MASK) >> PP_BLOCK_SHIFT) {
- case PP_BLOCK_SYS_BIF:
- if (PP_STATE_SUPPORT_CG & *msg_id) {
- msg = (*msg_id & PP_STATE_MASK) & PP_STATE_CG ?
- PPSMC_MSG_EnableClockGatingFeature :
- PPSMC_MSG_DisableClockGatingFeature;
- value = CG_SYS_BIF_MGCG_MASK;
- if (smum_send_msg_to_smc_with_parameter(
- hwmgr->smumgr, msg, value))
- return -EINVAL;
- }
- if (PP_STATE_SUPPORT_LS & *msg_id) {
- msg = (*msg_id & PP_STATE_MASK) & PP_STATE_LS ?
- PPSMC_MSG_EnableClockGatingFeature :
- PPSMC_MSG_DisableClockGatingFeature;
- value = CG_SYS_BIF_MGLS_MASK;
- if (smum_send_msg_to_smc_with_parameter(
- hwmgr->smumgr, msg, value))
- return -EINVAL;
- }
- break;
- case PP_BLOCK_SYS_MC:
- if (PP_STATE_SUPPORT_CG & *msg_id) {
- msg = ((*msg_id & PP_STATE_MASK) & PP_STATE_CG) ?
- PPSMC_MSG_EnableClockGatingFeature :
- PPSMC_MSG_DisableClockGatingFeature;
- value = CG_SYS_MC_MGCG_MASK;
- if (smum_send_msg_to_smc_with_parameter(
- hwmgr->smumgr, msg, value))
- return -EINVAL;
- }
- if (PP_STATE_SUPPORT_LS & *msg_id) {
- msg = (*msg_id & PP_STATE_MASK) & PP_STATE_LS ?
- PPSMC_MSG_EnableClockGatingFeature :
- PPSMC_MSG_DisableClockGatingFeature;
- value = CG_SYS_MC_MGLS_MASK;
- if (smum_send_msg_to_smc_with_parameter(
- hwmgr->smumgr, msg, value))
- return -EINVAL;
- }
- break;
- case PP_BLOCK_SYS_DRM:
- if (PP_STATE_SUPPORT_CG & *msg_id) {
- msg = (*msg_id & PP_STATE_MASK) & PP_STATE_CG ?
- PPSMC_MSG_EnableClockGatingFeature :
- PPSMC_MSG_DisableClockGatingFeature;
- value = CG_SYS_DRM_MGCG_MASK;
- if (smum_send_msg_to_smc_with_parameter(
- hwmgr->smumgr, msg, value))
- return -EINVAL;
- }
- if (PP_STATE_SUPPORT_LS & *msg_id) {
- msg = (*msg_id & PP_STATE_MASK) & PP_STATE_LS ?
- PPSMC_MSG_EnableClockGatingFeature :
- PPSMC_MSG_DisableClockGatingFeature;
- value = CG_SYS_DRM_MGLS_MASK;
- if (smum_send_msg_to_smc_with_parameter(
- hwmgr->smumgr, msg, value))
- return -EINVAL;
- }
- break;
- case PP_BLOCK_SYS_HDP:
- if (PP_STATE_SUPPORT_CG & *msg_id) {
- msg = ((*msg_id & PP_STATE_MASK) & PP_STATE_CG) ?
- PPSMC_MSG_EnableClockGatingFeature :
- PPSMC_MSG_DisableClockGatingFeature;
- value = CG_SYS_HDP_MGCG_MASK;
- if (smum_send_msg_to_smc_with_parameter(
- hwmgr->smumgr, msg, value))
- return -EINVAL;
- }
- if (PP_STATE_SUPPORT_LS & *msg_id) {
- msg = (*msg_id & PP_STATE_MASK) & PP_STATE_LS ?
- PPSMC_MSG_EnableClockGatingFeature :
- PPSMC_MSG_DisableClockGatingFeature;
- value = CG_SYS_HDP_MGLS_MASK;
- if (smum_send_msg_to_smc_with_parameter(
- hwmgr->smumgr, msg, value))
- return -EINVAL;
- }
- break;
- case PP_BLOCK_SYS_SDMA:
- if (PP_STATE_SUPPORT_CG & *msg_id) {
- msg = ((*msg_id & PP_STATE_MASK) & PP_STATE_CG) ?
- PPSMC_MSG_EnableClockGatingFeature :
- PPSMC_MSG_DisableClockGatingFeature;
- value = CG_SYS_SDMA_MGCG_MASK;
- if (smum_send_msg_to_smc_with_parameter(
- hwmgr->smumgr, msg, value))
- return -EINVAL;
- }
- if (PP_STATE_SUPPORT_LS & *msg_id) {
- msg = (*msg_id & PP_STATE_MASK) & PP_STATE_LS ?
- PPSMC_MSG_EnableClockGatingFeature :
- PPSMC_MSG_DisableClockGatingFeature;
- value = CG_SYS_SDMA_MGLS_MASK;
- if (smum_send_msg_to_smc_with_parameter(
- hwmgr->smumgr, msg, value))
- return -EINVAL;
- }
- break;
- case PP_BLOCK_SYS_ROM:
- if (PP_STATE_SUPPORT_CG & *msg_id) {
- msg = ((*msg_id & PP_STATE_MASK) & PP_STATE_CG) ?
- PPSMC_MSG_EnableClockGatingFeature :
- PPSMC_MSG_DisableClockGatingFeature;
- value = CG_SYS_ROM_MASK;
- if (smum_send_msg_to_smc_with_parameter(
- hwmgr->smumgr, msg, value))
- return -EINVAL;
- }
- break;
- default:
- return -EINVAL;
- }
- break;
- default:
- return -EINVAL;
- }
- return 0;
- }
- /* This function is for Polaris11 only for now,
- * Powerplay will only control the static per CU Power Gating.
- * Dynamic per CU Power Gating will be done in gfx.
- */
- int smu7_enable_per_cu_power_gating(struct pp_hwmgr *hwmgr, bool enable)
- {
- struct cgs_system_info sys_info = {0};
- uint32_t active_cus;
- int result;
- sys_info.size = sizeof(struct cgs_system_info);
- sys_info.info_id = CGS_SYSTEM_INFO_GFX_CU_INFO;
- result = cgs_query_system_info(hwmgr->device, &sys_info);
- if (result)
- return -EINVAL;
- active_cus = sys_info.value;
- if (enable)
- return smum_send_msg_to_smc_with_parameter(hwmgr->smumgr,
- PPSMC_MSG_GFX_CU_PG_ENABLE, active_cus);
- else
- return smum_send_msg_to_smc(hwmgr->smumgr,
- PPSMC_MSG_GFX_CU_PG_DISABLE);
- }
|