Commit e0638c7a authored by Evan Quan's avatar Evan Quan Committed by Alex Deucher

drm/amd/pm: drop unneeded lock protection smu->mutex

As all those APIs are already protected either by adev->pm.mutex
or smu->message_lock.
Signed-off-by: default avatarEvan Quan <evan.quan@amd.com>
Reviewed-by: default avatarGuchun Chen <guchun.chen@amd.com>
Reviewed-by: default avatarLijo Lazar <lijo.lazar@amd.com>
Signed-off-by: default avatarAlex Deucher <alexander.deucher@amd.com>
parent 239d6de3
...@@ -55,8 +55,7 @@ static int smu_force_smuclk_levels(struct smu_context *smu, ...@@ -55,8 +55,7 @@ static int smu_force_smuclk_levels(struct smu_context *smu,
uint32_t mask); uint32_t mask);
static int smu_handle_task(struct smu_context *smu, static int smu_handle_task(struct smu_context *smu,
enum amd_dpm_forced_level level, enum amd_dpm_forced_level level,
enum amd_pp_task task_id, enum amd_pp_task task_id);
bool lock_needed);
static int smu_reset(struct smu_context *smu); static int smu_reset(struct smu_context *smu);
static int smu_set_fan_speed_pwm(void *handle, u32 speed); static int smu_set_fan_speed_pwm(void *handle, u32 speed);
static int smu_set_fan_control_mode(void *handle, u32 value); static int smu_set_fan_control_mode(void *handle, u32 value);
...@@ -68,36 +67,22 @@ static int smu_sys_get_pp_feature_mask(void *handle, ...@@ -68,36 +67,22 @@ static int smu_sys_get_pp_feature_mask(void *handle,
char *buf) char *buf)
{ {
struct smu_context *smu = handle; struct smu_context *smu = handle;
int size = 0;
if (!smu->pm_enabled || !smu->adev->pm.dpm_enabled) if (!smu->pm_enabled || !smu->adev->pm.dpm_enabled)
return -EOPNOTSUPP; return -EOPNOTSUPP;
mutex_lock(&smu->mutex); return smu_get_pp_feature_mask(smu, buf);
size = smu_get_pp_feature_mask(smu, buf);
mutex_unlock(&smu->mutex);
return size;
} }
static int smu_sys_set_pp_feature_mask(void *handle, static int smu_sys_set_pp_feature_mask(void *handle,
uint64_t new_mask) uint64_t new_mask)
{ {
struct smu_context *smu = handle; struct smu_context *smu = handle;
int ret = 0;
if (!smu->pm_enabled || !smu->adev->pm.dpm_enabled) if (!smu->pm_enabled || !smu->adev->pm.dpm_enabled)
return -EOPNOTSUPP; return -EOPNOTSUPP;
mutex_lock(&smu->mutex); return smu_set_pp_feature_mask(smu, new_mask);
ret = smu_set_pp_feature_mask(smu, new_mask);
mutex_unlock(&smu->mutex);
return ret;
} }
int smu_get_status_gfxoff(struct smu_context *smu, uint32_t *value) int smu_get_status_gfxoff(struct smu_context *smu, uint32_t *value)
...@@ -117,16 +102,12 @@ int smu_set_soft_freq_range(struct smu_context *smu, ...@@ -117,16 +102,12 @@ int smu_set_soft_freq_range(struct smu_context *smu,
{ {
int ret = 0; int ret = 0;
mutex_lock(&smu->mutex);
if (smu->ppt_funcs->set_soft_freq_limited_range) if (smu->ppt_funcs->set_soft_freq_limited_range)
ret = smu->ppt_funcs->set_soft_freq_limited_range(smu, ret = smu->ppt_funcs->set_soft_freq_limited_range(smu,
clk_type, clk_type,
min, min,
max); max);
mutex_unlock(&smu->mutex);
return ret; return ret;
} }
...@@ -140,16 +121,12 @@ int smu_get_dpm_freq_range(struct smu_context *smu, ...@@ -140,16 +121,12 @@ int smu_get_dpm_freq_range(struct smu_context *smu,
if (!min && !max) if (!min && !max)
return -EINVAL; return -EINVAL;
mutex_lock(&smu->mutex);
if (smu->ppt_funcs->get_dpm_ultimate_freq) if (smu->ppt_funcs->get_dpm_ultimate_freq)
ret = smu->ppt_funcs->get_dpm_ultimate_freq(smu, ret = smu->ppt_funcs->get_dpm_ultimate_freq(smu,
clk_type, clk_type,
min, min,
max); max);
mutex_unlock(&smu->mutex);
return ret; return ret;
} }
...@@ -482,7 +459,6 @@ static int smu_sys_get_pp_table(void *handle, ...@@ -482,7 +459,6 @@ static int smu_sys_get_pp_table(void *handle,
{ {
struct smu_context *smu = handle; struct smu_context *smu = handle;
struct smu_table_context *smu_table = &smu->smu_table; struct smu_table_context *smu_table = &smu->smu_table;
uint32_t powerplay_table_size;
if (!smu->pm_enabled || !smu->adev->pm.dpm_enabled) if (!smu->pm_enabled || !smu->adev->pm.dpm_enabled)
return -EOPNOTSUPP; return -EOPNOTSUPP;
...@@ -490,18 +466,12 @@ static int smu_sys_get_pp_table(void *handle, ...@@ -490,18 +466,12 @@ static int smu_sys_get_pp_table(void *handle,
if (!smu_table->power_play_table && !smu_table->hardcode_pptable) if (!smu_table->power_play_table && !smu_table->hardcode_pptable)
return -EINVAL; return -EINVAL;
mutex_lock(&smu->mutex);
if (smu_table->hardcode_pptable) if (smu_table->hardcode_pptable)
*table = smu_table->hardcode_pptable; *table = smu_table->hardcode_pptable;
else else
*table = smu_table->power_play_table; *table = smu_table->power_play_table;
powerplay_table_size = smu_table->power_play_table_size; return smu_table->power_play_table_size;
mutex_unlock(&smu->mutex);
return powerplay_table_size;
} }
static int smu_sys_set_pp_table(void *handle, static int smu_sys_set_pp_table(void *handle,
...@@ -521,12 +491,10 @@ static int smu_sys_set_pp_table(void *handle, ...@@ -521,12 +491,10 @@ static int smu_sys_set_pp_table(void *handle,
return -EIO; return -EIO;
} }
mutex_lock(&smu->mutex);
if (!smu_table->hardcode_pptable)
smu_table->hardcode_pptable = kzalloc(size, GFP_KERNEL);
if (!smu_table->hardcode_pptable) { if (!smu_table->hardcode_pptable) {
ret = -ENOMEM; smu_table->hardcode_pptable = kzalloc(size, GFP_KERNEL);
goto failed; if (!smu_table->hardcode_pptable)
return -ENOMEM;
} }
memcpy(smu_table->hardcode_pptable, buf, size); memcpy(smu_table->hardcode_pptable, buf, size);
...@@ -545,8 +513,6 @@ static int smu_sys_set_pp_table(void *handle, ...@@ -545,8 +513,6 @@ static int smu_sys_set_pp_table(void *handle,
smu->uploading_custom_pp_table = false; smu->uploading_custom_pp_table = false;
failed:
mutex_unlock(&smu->mutex);
return ret; return ret;
} }
...@@ -633,7 +599,6 @@ static int smu_early_init(void *handle) ...@@ -633,7 +599,6 @@ static int smu_early_init(void *handle)
smu->adev = adev; smu->adev = adev;
smu->pm_enabled = !!amdgpu_dpm; smu->pm_enabled = !!amdgpu_dpm;
smu->is_apu = false; smu->is_apu = false;
mutex_init(&smu->mutex);
mutex_init(&smu->smu_baco.mutex); mutex_init(&smu->smu_baco.mutex);
smu->smu_baco.state = SMU_BACO_STATE_EXIT; smu->smu_baco.state = SMU_BACO_STATE_EXIT;
smu->smu_baco.platform_support = false; smu->smu_baco.platform_support = false;
...@@ -736,8 +701,7 @@ static int smu_late_init(void *handle) ...@@ -736,8 +701,7 @@ static int smu_late_init(void *handle)
smu_handle_task(smu, smu_handle_task(smu,
smu->smu_dpm.dpm_level, smu->smu_dpm.dpm_level,
AMD_PP_TASK_COMPLETE_INIT, AMD_PP_TASK_COMPLETE_INIT);
false);
smu_restore_dpm_user_profile(smu); smu_restore_dpm_user_profile(smu);
...@@ -1013,12 +977,8 @@ static void smu_interrupt_work_fn(struct work_struct *work) ...@@ -1013,12 +977,8 @@ static void smu_interrupt_work_fn(struct work_struct *work)
struct smu_context *smu = container_of(work, struct smu_context, struct smu_context *smu = container_of(work, struct smu_context,
interrupt_work); interrupt_work);
mutex_lock(&smu->mutex);
if (smu->ppt_funcs && smu->ppt_funcs->interrupt_work) if (smu->ppt_funcs && smu->ppt_funcs->interrupt_work)
smu->ppt_funcs->interrupt_work(smu); smu->ppt_funcs->interrupt_work(smu);
mutex_unlock(&smu->mutex);
} }
static int smu_sw_init(void *handle) static int smu_sw_init(void *handle)
...@@ -1632,8 +1592,6 @@ static int smu_display_configuration_change(void *handle, ...@@ -1632,8 +1592,6 @@ static int smu_display_configuration_change(void *handle,
if (!display_config) if (!display_config)
return -EINVAL; return -EINVAL;
mutex_lock(&smu->mutex);
smu_set_min_dcef_deep_sleep(smu, smu_set_min_dcef_deep_sleep(smu,
display_config->min_dcef_deep_sleep_set_clk / 100); display_config->min_dcef_deep_sleep_set_clk / 100);
...@@ -1642,8 +1600,6 @@ static int smu_display_configuration_change(void *handle, ...@@ -1642,8 +1600,6 @@ static int smu_display_configuration_change(void *handle,
num_of_active_display++; num_of_active_display++;
} }
mutex_unlock(&smu->mutex);
return 0; return 0;
} }
...@@ -1766,22 +1722,18 @@ static int smu_adjust_power_state_dynamic(struct smu_context *smu, ...@@ -1766,22 +1722,18 @@ static int smu_adjust_power_state_dynamic(struct smu_context *smu,
static int smu_handle_task(struct smu_context *smu, static int smu_handle_task(struct smu_context *smu,
enum amd_dpm_forced_level level, enum amd_dpm_forced_level level,
enum amd_pp_task task_id, enum amd_pp_task task_id)
bool lock_needed)
{ {
int ret = 0; int ret = 0;
if (!smu->pm_enabled || !smu->adev->pm.dpm_enabled) if (!smu->pm_enabled || !smu->adev->pm.dpm_enabled)
return -EOPNOTSUPP; return -EOPNOTSUPP;
if (lock_needed)
mutex_lock(&smu->mutex);
switch (task_id) { switch (task_id) {
case AMD_PP_TASK_DISPLAY_CONFIG_CHANGE: case AMD_PP_TASK_DISPLAY_CONFIG_CHANGE:
ret = smu_pre_display_config_changed(smu); ret = smu_pre_display_config_changed(smu);
if (ret) if (ret)
goto out; return ret;
ret = smu_adjust_power_state_dynamic(smu, level, false); ret = smu_adjust_power_state_dynamic(smu, level, false);
break; break;
case AMD_PP_TASK_COMPLETE_INIT: case AMD_PP_TASK_COMPLETE_INIT:
...@@ -1792,10 +1744,6 @@ static int smu_handle_task(struct smu_context *smu, ...@@ -1792,10 +1744,6 @@ static int smu_handle_task(struct smu_context *smu,
break; break;
} }
out:
if (lock_needed)
mutex_unlock(&smu->mutex);
return ret; return ret;
} }
...@@ -1806,7 +1754,7 @@ static int smu_handle_dpm_task(void *handle, ...@@ -1806,7 +1754,7 @@ static int smu_handle_dpm_task(void *handle,
struct smu_context *smu = handle; struct smu_context *smu = handle;
struct smu_dpm_context *smu_dpm = &smu->smu_dpm; struct smu_dpm_context *smu_dpm = &smu->smu_dpm;
return smu_handle_task(smu, smu_dpm->dpm_level, task_id, true); return smu_handle_task(smu, smu_dpm->dpm_level, task_id);
} }
...@@ -1825,8 +1773,6 @@ static int smu_switch_power_profile(void *handle, ...@@ -1825,8 +1773,6 @@ static int smu_switch_power_profile(void *handle,
if (!(type < PP_SMC_POWER_PROFILE_CUSTOM)) if (!(type < PP_SMC_POWER_PROFILE_CUSTOM))
return -EINVAL; return -EINVAL;
mutex_lock(&smu->mutex);
if (!en) { if (!en) {
smu->workload_mask &= ~(1 << smu->workload_prority[type]); smu->workload_mask &= ~(1 << smu->workload_prority[type]);
index = fls(smu->workload_mask); index = fls(smu->workload_mask);
...@@ -1843,8 +1789,6 @@ static int smu_switch_power_profile(void *handle, ...@@ -1843,8 +1789,6 @@ static int smu_switch_power_profile(void *handle,
smu_dpm_ctx->dpm_level != AMD_DPM_FORCED_LEVEL_PERF_DETERMINISM) smu_dpm_ctx->dpm_level != AMD_DPM_FORCED_LEVEL_PERF_DETERMINISM)
smu_bump_power_profile_mode(smu, &workload, 0); smu_bump_power_profile_mode(smu, &workload, 0);
mutex_unlock(&smu->mutex);
return 0; return 0;
} }
...@@ -1852,7 +1796,6 @@ static enum amd_dpm_forced_level smu_get_performance_level(void *handle) ...@@ -1852,7 +1796,6 @@ static enum amd_dpm_forced_level smu_get_performance_level(void *handle)
{ {
struct smu_context *smu = handle; struct smu_context *smu = handle;
struct smu_dpm_context *smu_dpm_ctx = &(smu->smu_dpm); struct smu_dpm_context *smu_dpm_ctx = &(smu->smu_dpm);
enum amd_dpm_forced_level level;
if (!smu->pm_enabled || !smu->adev->pm.dpm_enabled) if (!smu->pm_enabled || !smu->adev->pm.dpm_enabled)
return -EOPNOTSUPP; return -EOPNOTSUPP;
...@@ -1860,11 +1803,7 @@ static enum amd_dpm_forced_level smu_get_performance_level(void *handle) ...@@ -1860,11 +1803,7 @@ static enum amd_dpm_forced_level smu_get_performance_level(void *handle)
if (!smu->is_apu && !smu_dpm_ctx->dpm_context) if (!smu->is_apu && !smu_dpm_ctx->dpm_context)
return -EINVAL; return -EINVAL;
mutex_lock(&(smu->mutex)); return smu_dpm_ctx->dpm_level;
level = smu_dpm_ctx->dpm_level;
mutex_unlock(&(smu->mutex));
return level;
} }
static int smu_force_performance_level(void *handle, static int smu_force_performance_level(void *handle,
...@@ -1880,19 +1819,12 @@ static int smu_force_performance_level(void *handle, ...@@ -1880,19 +1819,12 @@ static int smu_force_performance_level(void *handle,
if (!smu->is_apu && !smu_dpm_ctx->dpm_context) if (!smu->is_apu && !smu_dpm_ctx->dpm_context)
return -EINVAL; return -EINVAL;
mutex_lock(&smu->mutex);
ret = smu_enable_umd_pstate(smu, &level); ret = smu_enable_umd_pstate(smu, &level);
if (ret) { if (ret)
mutex_unlock(&smu->mutex);
return ret; return ret;
}
ret = smu_handle_task(smu, level, ret = smu_handle_task(smu, level,
AMD_PP_TASK_READJUST_POWER_STATE, AMD_PP_TASK_READJUST_POWER_STATE);
false);
mutex_unlock(&smu->mutex);
/* reset user dpm clock state */ /* reset user dpm clock state */
if (!ret && smu_dpm_ctx->dpm_level != AMD_DPM_FORCED_LEVEL_MANUAL) { if (!ret && smu_dpm_ctx->dpm_level != AMD_DPM_FORCED_LEVEL_MANUAL) {
...@@ -1906,16 +1838,11 @@ static int smu_force_performance_level(void *handle, ...@@ -1906,16 +1838,11 @@ static int smu_force_performance_level(void *handle,
static int smu_set_display_count(void *handle, uint32_t count) static int smu_set_display_count(void *handle, uint32_t count)
{ {
struct smu_context *smu = handle; struct smu_context *smu = handle;
int ret = 0;
if (!smu->pm_enabled || !smu->adev->pm.dpm_enabled) if (!smu->pm_enabled || !smu->adev->pm.dpm_enabled)
return -EOPNOTSUPP; return -EOPNOTSUPP;
mutex_lock(&smu->mutex); return smu_init_display_count(smu, count);
ret = smu_init_display_count(smu, count);
mutex_unlock(&smu->mutex);
return ret;
} }
static int smu_force_smuclk_levels(struct smu_context *smu, static int smu_force_smuclk_levels(struct smu_context *smu,
...@@ -1933,8 +1860,6 @@ static int smu_force_smuclk_levels(struct smu_context *smu, ...@@ -1933,8 +1860,6 @@ static int smu_force_smuclk_levels(struct smu_context *smu,
return -EINVAL; return -EINVAL;
} }
mutex_lock(&smu->mutex);
if (smu->ppt_funcs && smu->ppt_funcs->force_clk_levels) { if (smu->ppt_funcs && smu->ppt_funcs->force_clk_levels) {
ret = smu->ppt_funcs->force_clk_levels(smu, clk_type, mask); ret = smu->ppt_funcs->force_clk_levels(smu, clk_type, mask);
if (!ret && !(smu->user_dpm_profile.flags & SMU_DPM_USER_PROFILE_RESTORE)) { if (!ret && !(smu->user_dpm_profile.flags & SMU_DPM_USER_PROFILE_RESTORE)) {
...@@ -1943,8 +1868,6 @@ static int smu_force_smuclk_levels(struct smu_context *smu, ...@@ -1943,8 +1868,6 @@ static int smu_force_smuclk_levels(struct smu_context *smu,
} }
} }
mutex_unlock(&smu->mutex);
return ret; return ret;
} }
...@@ -2003,14 +1926,10 @@ static int smu_set_mp1_state(void *handle, ...@@ -2003,14 +1926,10 @@ static int smu_set_mp1_state(void *handle,
if (!smu->pm_enabled) if (!smu->pm_enabled)
return -EOPNOTSUPP; return -EOPNOTSUPP;
mutex_lock(&smu->mutex);
if (smu->ppt_funcs && if (smu->ppt_funcs &&
smu->ppt_funcs->set_mp1_state) smu->ppt_funcs->set_mp1_state)
ret = smu->ppt_funcs->set_mp1_state(smu, mp1_state); ret = smu->ppt_funcs->set_mp1_state(smu, mp1_state);
mutex_unlock(&smu->mutex);
return ret; return ret;
} }
...@@ -2026,14 +1945,10 @@ static int smu_set_df_cstate(void *handle, ...@@ -2026,14 +1945,10 @@ static int smu_set_df_cstate(void *handle,
if (!smu->ppt_funcs || !smu->ppt_funcs->set_df_cstate) if (!smu->ppt_funcs || !smu->ppt_funcs->set_df_cstate)
return 0; return 0;
mutex_lock(&smu->mutex);
ret = smu->ppt_funcs->set_df_cstate(smu, state); ret = smu->ppt_funcs->set_df_cstate(smu, state);
if (ret) if (ret)
dev_err(smu->adev->dev, "[SetDfCstate] failed!\n"); dev_err(smu->adev->dev, "[SetDfCstate] failed!\n");
mutex_unlock(&smu->mutex);
return ret; return ret;
} }
...@@ -2047,38 +1962,25 @@ int smu_allow_xgmi_power_down(struct smu_context *smu, bool en) ...@@ -2047,38 +1962,25 @@ int smu_allow_xgmi_power_down(struct smu_context *smu, bool en)
if (!smu->ppt_funcs || !smu->ppt_funcs->allow_xgmi_power_down) if (!smu->ppt_funcs || !smu->ppt_funcs->allow_xgmi_power_down)
return 0; return 0;
mutex_lock(&smu->mutex);
ret = smu->ppt_funcs->allow_xgmi_power_down(smu, en); ret = smu->ppt_funcs->allow_xgmi_power_down(smu, en);
if (ret) if (ret)
dev_err(smu->adev->dev, "[AllowXgmiPowerDown] failed!\n"); dev_err(smu->adev->dev, "[AllowXgmiPowerDown] failed!\n");
mutex_unlock(&smu->mutex);
return ret; return ret;
} }
int smu_write_watermarks_table(struct smu_context *smu) int smu_write_watermarks_table(struct smu_context *smu)
{ {
int ret = 0;
if (!smu->pm_enabled || !smu->adev->pm.dpm_enabled) if (!smu->pm_enabled || !smu->adev->pm.dpm_enabled)
return -EOPNOTSUPP; return -EOPNOTSUPP;
mutex_lock(&smu->mutex); return smu_set_watermarks_table(smu, NULL);
ret = smu_set_watermarks_table(smu, NULL);
mutex_unlock(&smu->mutex);
return ret;
} }
static int smu_set_watermarks_for_clock_ranges(void *handle, static int smu_set_watermarks_for_clock_ranges(void *handle,
struct pp_smu_wm_range_sets *clock_ranges) struct pp_smu_wm_range_sets *clock_ranges)
{ {
struct smu_context *smu = handle; struct smu_context *smu = handle;
int ret = 0;
if (!smu->pm_enabled || !smu->adev->pm.dpm_enabled) if (!smu->pm_enabled || !smu->adev->pm.dpm_enabled)
return -EOPNOTSUPP; return -EOPNOTSUPP;
...@@ -2086,13 +1988,7 @@ static int smu_set_watermarks_for_clock_ranges(void *handle, ...@@ -2086,13 +1988,7 @@ static int smu_set_watermarks_for_clock_ranges(void *handle,
if (smu->disable_watermark) if (smu->disable_watermark)
return 0; return 0;
mutex_lock(&smu->mutex); return smu_set_watermarks_table(smu, clock_ranges);
ret = smu_set_watermarks_table(smu, clock_ranges);
mutex_unlock(&smu->mutex);
return ret;
} }
int smu_set_ac_dc(struct smu_context *smu) int smu_set_ac_dc(struct smu_context *smu)
...@@ -2106,14 +2002,12 @@ int smu_set_ac_dc(struct smu_context *smu) ...@@ -2106,14 +2002,12 @@ int smu_set_ac_dc(struct smu_context *smu)
if (smu->dc_controlled_by_gpio) if (smu->dc_controlled_by_gpio)
return 0; return 0;
mutex_lock(&smu->mutex);
ret = smu_set_power_source(smu, ret = smu_set_power_source(smu,
smu->adev->pm.ac_power ? SMU_POWER_SOURCE_AC : smu->adev->pm.ac_power ? SMU_POWER_SOURCE_AC :
SMU_POWER_SOURCE_DC); SMU_POWER_SOURCE_DC);
if (ret) if (ret)
dev_err(smu->adev->dev, "Failed to switch to %s mode!\n", dev_err(smu->adev->dev, "Failed to switch to %s mode!\n",
smu->adev->pm.ac_power ? "AC" : "DC"); smu->adev->pm.ac_power ? "AC" : "DC");
mutex_unlock(&smu->mutex);
return ret; return ret;
} }
...@@ -2200,13 +2094,9 @@ static int smu_set_gfx_cgpg(struct smu_context *smu, bool enabled) ...@@ -2200,13 +2094,9 @@ static int smu_set_gfx_cgpg(struct smu_context *smu, bool enabled)
{ {
int ret = 0; int ret = 0;
mutex_lock(&smu->mutex);
if (smu->ppt_funcs->set_gfx_cgpg) if (smu->ppt_funcs->set_gfx_cgpg)
ret = smu->ppt_funcs->set_gfx_cgpg(smu, enabled); ret = smu->ppt_funcs->set_gfx_cgpg(smu, enabled);
mutex_unlock(&smu->mutex);
return ret; return ret;
} }
...@@ -2224,8 +2114,6 @@ static int smu_set_fan_speed_rpm(void *handle, uint32_t speed) ...@@ -2224,8 +2114,6 @@ static int smu_set_fan_speed_rpm(void *handle, uint32_t speed)
if (speed == U32_MAX) if (speed == U32_MAX)
return -EINVAL; return -EINVAL;
mutex_lock(&smu->mutex);
ret = smu->ppt_funcs->set_fan_speed_rpm(smu, speed); ret = smu->ppt_funcs->set_fan_speed_rpm(smu, speed);
if (!ret && !(smu->user_dpm_profile.flags & SMU_DPM_USER_PROFILE_RESTORE)) { if (!ret && !(smu->user_dpm_profile.flags & SMU_DPM_USER_PROFILE_RESTORE)) {
smu->user_dpm_profile.flags |= SMU_CUSTOM_FAN_SPEED_RPM; smu->user_dpm_profile.flags |= SMU_CUSTOM_FAN_SPEED_RPM;
...@@ -2236,8 +2124,6 @@ static int smu_set_fan_speed_rpm(void *handle, uint32_t speed) ...@@ -2236,8 +2124,6 @@ static int smu_set_fan_speed_rpm(void *handle, uint32_t speed)
smu->user_dpm_profile.fan_speed_pwm = 0; smu->user_dpm_profile.fan_speed_pwm = 0;
} }
mutex_unlock(&smu->mutex);
return ret; return ret;
} }
...@@ -2293,8 +2179,6 @@ int smu_get_power_limit(void *handle, ...@@ -2293,8 +2179,6 @@ int smu_get_power_limit(void *handle,
break; break;
} }
mutex_lock(&smu->mutex);
if (limit_type != SMU_DEFAULT_PPT_LIMIT) { if (limit_type != SMU_DEFAULT_PPT_LIMIT) {
if (smu->ppt_funcs->get_ppt_limit) if (smu->ppt_funcs->get_ppt_limit)
ret = smu->ppt_funcs->get_ppt_limit(smu, limit, limit_type, limit_level); ret = smu->ppt_funcs->get_ppt_limit(smu, limit, limit_type, limit_level);
...@@ -2328,8 +2212,6 @@ int smu_get_power_limit(void *handle, ...@@ -2328,8 +2212,6 @@ int smu_get_power_limit(void *handle,
} }
} }
mutex_unlock(&smu->mutex);
return ret; return ret;
} }
...@@ -2342,21 +2224,16 @@ static int smu_set_power_limit(void *handle, uint32_t limit) ...@@ -2342,21 +2224,16 @@ static int smu_set_power_limit(void *handle, uint32_t limit)
if (!smu->pm_enabled || !smu->adev->pm.dpm_enabled) if (!smu->pm_enabled || !smu->adev->pm.dpm_enabled)
return -EOPNOTSUPP; return -EOPNOTSUPP;
mutex_lock(&smu->mutex);
limit &= (1<<24)-1; limit &= (1<<24)-1;
if (limit_type != SMU_DEFAULT_PPT_LIMIT) if (limit_type != SMU_DEFAULT_PPT_LIMIT)
if (smu->ppt_funcs->set_power_limit) { if (smu->ppt_funcs->set_power_limit)
ret = smu->ppt_funcs->set_power_limit(smu, limit_type, limit); return smu->ppt_funcs->set_power_limit(smu, limit_type, limit);
goto out;
}
if (limit > smu->max_power_limit) { if (limit > smu->max_power_limit) {
dev_err(smu->adev->dev, dev_err(smu->adev->dev,
"New power limit (%d) is over the max allowed %d\n", "New power limit (%d) is over the max allowed %d\n",
limit, smu->max_power_limit); limit, smu->max_power_limit);
ret = -EINVAL; return -EINVAL;
goto out;
} }
if (!limit) if (!limit)
...@@ -2368,9 +2245,6 @@ static int smu_set_power_limit(void *handle, uint32_t limit) ...@@ -2368,9 +2245,6 @@ static int smu_set_power_limit(void *handle, uint32_t limit)
smu->user_dpm_profile.power_limit = limit; smu->user_dpm_profile.power_limit = limit;
} }
out:
mutex_unlock(&smu->mutex);
return ret; return ret;
} }
...@@ -2381,13 +2255,9 @@ static int smu_print_smuclk_levels(struct smu_context *smu, enum smu_clk_type cl ...@@ -2381,13 +2255,9 @@ static int smu_print_smuclk_levels(struct smu_context *smu, enum smu_clk_type cl
if (!smu->pm_enabled || !smu->adev->pm.dpm_enabled) if (!smu->pm_enabled || !smu->adev->pm.dpm_enabled)
return -EOPNOTSUPP; return -EOPNOTSUPP;
mutex_lock(&smu->mutex);
if (smu->ppt_funcs->print_clk_levels) if (smu->ppt_funcs->print_clk_levels)
ret = smu->ppt_funcs->print_clk_levels(smu, clk_type, buf); ret = smu->ppt_funcs->print_clk_levels(smu, clk_type, buf);
mutex_unlock(&smu->mutex);
return ret; return ret;
} }
...@@ -2444,14 +2314,10 @@ static int smu_od_edit_dpm_table(void *handle, ...@@ -2444,14 +2314,10 @@ static int smu_od_edit_dpm_table(void *handle,
if (!smu->pm_enabled || !smu->adev->pm.dpm_enabled) if (!smu->pm_enabled || !smu->adev->pm.dpm_enabled)
return -EOPNOTSUPP; return -EOPNOTSUPP;
mutex_lock(&smu->mutex);
if (smu->ppt_funcs->od_edit_dpm_table) { if (smu->ppt_funcs->od_edit_dpm_table) {
ret = smu->ppt_funcs->od_edit_dpm_table(smu, type, input, size); ret = smu->ppt_funcs->od_edit_dpm_table(smu, type, input, size);
} }
mutex_unlock(&smu->mutex);
return ret; return ret;
} }
...@@ -2475,8 +2341,6 @@ static int smu_read_sensor(void *handle, ...@@ -2475,8 +2341,6 @@ static int smu_read_sensor(void *handle,
size_val = *size_arg; size_val = *size_arg;
size = &size_val; size = &size_val;
mutex_lock(&smu->mutex);
if (smu->ppt_funcs->read_sensor) if (smu->ppt_funcs->read_sensor)
if (!smu->ppt_funcs->read_sensor(smu, sensor, data, size)) if (!smu->ppt_funcs->read_sensor(smu, sensor, data, size))
goto unlock; goto unlock;
...@@ -2517,8 +2381,6 @@ static int smu_read_sensor(void *handle, ...@@ -2517,8 +2381,6 @@ static int smu_read_sensor(void *handle,
} }
unlock: unlock:
mutex_unlock(&smu->mutex);
// assign uint32_t to int // assign uint32_t to int
*size_arg = size_val; *size_arg = size_val;
...@@ -2528,7 +2390,6 @@ static int smu_read_sensor(void *handle, ...@@ -2528,7 +2390,6 @@ static int smu_read_sensor(void *handle,
static int smu_get_power_profile_mode(void *handle, char *buf) static int smu_get_power_profile_mode(void *handle, char *buf)
{ {
struct smu_context *smu = handle; struct smu_context *smu = handle;
int ret = 0;
if (!smu->pm_enabled || !smu->adev->pm.dpm_enabled || if (!smu->pm_enabled || !smu->adev->pm.dpm_enabled ||
!smu->ppt_funcs->get_power_profile_mode) !smu->ppt_funcs->get_power_profile_mode)
...@@ -2536,13 +2397,7 @@ static int smu_get_power_profile_mode(void *handle, char *buf) ...@@ -2536,13 +2397,7 @@ static int smu_get_power_profile_mode(void *handle, char *buf)
if (!buf) if (!buf)
return -EINVAL; return -EINVAL;
mutex_lock(&smu->mutex); return smu->ppt_funcs->get_power_profile_mode(smu, buf);
ret = smu->ppt_funcs->get_power_profile_mode(smu, buf);
mutex_unlock(&smu->mutex);
return ret;
} }
static int smu_set_power_profile_mode(void *handle, static int smu_set_power_profile_mode(void *handle,
...@@ -2550,19 +2405,12 @@ static int smu_set_power_profile_mode(void *handle, ...@@ -2550,19 +2405,12 @@ static int smu_set_power_profile_mode(void *handle,
uint32_t param_size) uint32_t param_size)
{ {
struct smu_context *smu = handle; struct smu_context *smu = handle;
int ret = 0;
if (!smu->pm_enabled || !smu->adev->pm.dpm_enabled || if (!smu->pm_enabled || !smu->adev->pm.dpm_enabled ||
!smu->ppt_funcs->set_power_profile_mode) !smu->ppt_funcs->set_power_profile_mode)
return -EOPNOTSUPP; return -EOPNOTSUPP;
mutex_lock(&smu->mutex); return smu_bump_power_profile_mode(smu, param, param_size);
smu_bump_power_profile_mode(smu, param, param_size);
mutex_unlock(&smu->mutex);
return ret;
} }
...@@ -2579,12 +2427,8 @@ static int smu_get_fan_control_mode(void *handle, u32 *fan_mode) ...@@ -2579,12 +2427,8 @@ static int smu_get_fan_control_mode(void *handle, u32 *fan_mode)
if (!fan_mode) if (!fan_mode)
return -EINVAL; return -EINVAL;
mutex_lock(&smu->mutex);
*fan_mode = smu->ppt_funcs->get_fan_control_mode(smu); *fan_mode = smu->ppt_funcs->get_fan_control_mode(smu);
mutex_unlock(&smu->mutex);
return 0; return 0;
} }
...@@ -2602,8 +2446,6 @@ static int smu_set_fan_control_mode(void *handle, u32 value) ...@@ -2602,8 +2446,6 @@ static int smu_set_fan_control_mode(void *handle, u32 value)
if (value == U32_MAX) if (value == U32_MAX)
return -EINVAL; return -EINVAL;
mutex_lock(&smu->mutex);
ret = smu->ppt_funcs->set_fan_control_mode(smu, value); ret = smu->ppt_funcs->set_fan_control_mode(smu, value);
if (ret) if (ret)
goto out; goto out;
...@@ -2620,8 +2462,6 @@ static int smu_set_fan_control_mode(void *handle, u32 value) ...@@ -2620,8 +2462,6 @@ static int smu_set_fan_control_mode(void *handle, u32 value)
} }
out: out:
mutex_unlock(&smu->mutex);
return ret; return ret;
} }
...@@ -2639,12 +2479,8 @@ static int smu_get_fan_speed_pwm(void *handle, u32 *speed) ...@@ -2639,12 +2479,8 @@ static int smu_get_fan_speed_pwm(void *handle, u32 *speed)
if (!speed) if (!speed)
return -EINVAL; return -EINVAL;
mutex_lock(&smu->mutex);
ret = smu->ppt_funcs->get_fan_speed_pwm(smu, speed); ret = smu->ppt_funcs->get_fan_speed_pwm(smu, speed);
mutex_unlock(&smu->mutex);
return ret; return ret;
} }
...@@ -2662,8 +2498,6 @@ static int smu_set_fan_speed_pwm(void *handle, u32 speed) ...@@ -2662,8 +2498,6 @@ static int smu_set_fan_speed_pwm(void *handle, u32 speed)
if (speed == U32_MAX) if (speed == U32_MAX)
return -EINVAL; return -EINVAL;
mutex_lock(&smu->mutex);
ret = smu->ppt_funcs->set_fan_speed_pwm(smu, speed); ret = smu->ppt_funcs->set_fan_speed_pwm(smu, speed);
if (!ret && !(smu->user_dpm_profile.flags & SMU_DPM_USER_PROFILE_RESTORE)) { if (!ret && !(smu->user_dpm_profile.flags & SMU_DPM_USER_PROFILE_RESTORE)) {
smu->user_dpm_profile.flags |= SMU_CUSTOM_FAN_SPEED_PWM; smu->user_dpm_profile.flags |= SMU_CUSTOM_FAN_SPEED_PWM;
...@@ -2674,8 +2508,6 @@ static int smu_set_fan_speed_pwm(void *handle, u32 speed) ...@@ -2674,8 +2508,6 @@ static int smu_set_fan_speed_pwm(void *handle, u32 speed)
smu->user_dpm_profile.fan_speed_rpm = 0; smu->user_dpm_profile.fan_speed_rpm = 0;
} }
mutex_unlock(&smu->mutex);
return ret; return ret;
} }
...@@ -2693,30 +2525,19 @@ static int smu_get_fan_speed_rpm(void *handle, uint32_t *speed) ...@@ -2693,30 +2525,19 @@ static int smu_get_fan_speed_rpm(void *handle, uint32_t *speed)
if (!speed) if (!speed)
return -EINVAL; return -EINVAL;
mutex_lock(&smu->mutex);
ret = smu->ppt_funcs->get_fan_speed_rpm(smu, speed); ret = smu->ppt_funcs->get_fan_speed_rpm(smu, speed);
mutex_unlock(&smu->mutex);
return ret; return ret;
} }
static int smu_set_deep_sleep_dcefclk(void *handle, uint32_t clk) static int smu_set_deep_sleep_dcefclk(void *handle, uint32_t clk)
{ {
struct smu_context *smu = handle; struct smu_context *smu = handle;
int ret = 0;
if (!smu->pm_enabled || !smu->adev->pm.dpm_enabled) if (!smu->pm_enabled || !smu->adev->pm.dpm_enabled)
return -EOPNOTSUPP; return -EOPNOTSUPP;
mutex_lock(&smu->mutex); return smu_set_min_dcef_deep_sleep(smu, clk);
ret = smu_set_min_dcef_deep_sleep(smu, clk);
mutex_unlock(&smu->mutex);
return ret;
} }
static int smu_get_clock_by_type_with_latency(void *handle, static int smu_get_clock_by_type_with_latency(void *handle,
...@@ -2730,8 +2551,6 @@ static int smu_get_clock_by_type_with_latency(void *handle, ...@@ -2730,8 +2551,6 @@ static int smu_get_clock_by_type_with_latency(void *handle,
if (!smu->pm_enabled || !smu->adev->pm.dpm_enabled) if (!smu->pm_enabled || !smu->adev->pm.dpm_enabled)
return -EOPNOTSUPP; return -EOPNOTSUPP;
mutex_lock(&smu->mutex);
if (smu->ppt_funcs->get_clock_by_type_with_latency) { if (smu->ppt_funcs->get_clock_by_type_with_latency) {
switch (type) { switch (type) {
case amd_pp_sys_clock: case amd_pp_sys_clock:
...@@ -2748,15 +2567,12 @@ static int smu_get_clock_by_type_with_latency(void *handle, ...@@ -2748,15 +2567,12 @@ static int smu_get_clock_by_type_with_latency(void *handle,
break; break;
default: default:
dev_err(smu->adev->dev, "Invalid clock type!\n"); dev_err(smu->adev->dev, "Invalid clock type!\n");
mutex_unlock(&smu->mutex);
return -EINVAL; return -EINVAL;
} }
ret = smu->ppt_funcs->get_clock_by_type_with_latency(smu, clk_type, clocks); ret = smu->ppt_funcs->get_clock_by_type_with_latency(smu, clk_type, clocks);
} }
mutex_unlock(&smu->mutex);
return ret; return ret;
} }
...@@ -2769,13 +2585,9 @@ static int smu_display_clock_voltage_request(void *handle, ...@@ -2769,13 +2585,9 @@ static int smu_display_clock_voltage_request(void *handle,
if (!smu->pm_enabled || !smu->adev->pm.dpm_enabled) if (!smu->pm_enabled || !smu->adev->pm.dpm_enabled)
return -EOPNOTSUPP; return -EOPNOTSUPP;
mutex_lock(&smu->mutex);
if (smu->ppt_funcs->display_clock_voltage_request) if (smu->ppt_funcs->display_clock_voltage_request)
ret = smu->ppt_funcs->display_clock_voltage_request(smu, clock_req); ret = smu->ppt_funcs->display_clock_voltage_request(smu, clock_req);
mutex_unlock(&smu->mutex);
return ret; return ret;
} }
...@@ -2789,13 +2601,9 @@ static int smu_display_disable_memory_clock_switch(void *handle, ...@@ -2789,13 +2601,9 @@ static int smu_display_disable_memory_clock_switch(void *handle,
if (!smu->pm_enabled || !smu->adev->pm.dpm_enabled) if (!smu->pm_enabled || !smu->adev->pm.dpm_enabled)
return -EOPNOTSUPP; return -EOPNOTSUPP;
mutex_lock(&smu->mutex);
if (smu->ppt_funcs->display_disable_memory_clock_switch) if (smu->ppt_funcs->display_disable_memory_clock_switch)
ret = smu->ppt_funcs->display_disable_memory_clock_switch(smu, disable_memory_clock_switch); ret = smu->ppt_funcs->display_disable_memory_clock_switch(smu, disable_memory_clock_switch);
mutex_unlock(&smu->mutex);
return ret; return ret;
} }
...@@ -2808,13 +2616,9 @@ static int smu_set_xgmi_pstate(void *handle, ...@@ -2808,13 +2616,9 @@ static int smu_set_xgmi_pstate(void *handle,
if (!smu->pm_enabled || !smu->adev->pm.dpm_enabled) if (!smu->pm_enabled || !smu->adev->pm.dpm_enabled)
return -EOPNOTSUPP; return -EOPNOTSUPP;
mutex_lock(&smu->mutex);
if (smu->ppt_funcs->set_xgmi_pstate) if (smu->ppt_funcs->set_xgmi_pstate)
ret = smu->ppt_funcs->set_xgmi_pstate(smu, pstate); ret = smu->ppt_funcs->set_xgmi_pstate(smu, pstate);
mutex_unlock(&smu->mutex);
if(ret) if(ret)
dev_err(smu->adev->dev, "Failed to set XGMI pstate!\n"); dev_err(smu->adev->dev, "Failed to set XGMI pstate!\n");
...@@ -2824,21 +2628,16 @@ static int smu_set_xgmi_pstate(void *handle, ...@@ -2824,21 +2628,16 @@ static int smu_set_xgmi_pstate(void *handle,
static int smu_get_baco_capability(void *handle, bool *cap) static int smu_get_baco_capability(void *handle, bool *cap)
{ {
struct smu_context *smu = handle; struct smu_context *smu = handle;
int ret = 0;
*cap = false; *cap = false;
if (!smu->pm_enabled) if (!smu->pm_enabled)
return 0; return 0;
mutex_lock(&smu->mutex);
if (smu->ppt_funcs && smu->ppt_funcs->baco_is_support) if (smu->ppt_funcs && smu->ppt_funcs->baco_is_support)
*cap = smu->ppt_funcs->baco_is_support(smu); *cap = smu->ppt_funcs->baco_is_support(smu);
mutex_unlock(&smu->mutex); return 0;
return ret;
} }
static int smu_baco_set_state(void *handle, int state) static int smu_baco_set_state(void *handle, int state)
...@@ -2850,20 +2649,11 @@ static int smu_baco_set_state(void *handle, int state) ...@@ -2850,20 +2649,11 @@ static int smu_baco_set_state(void *handle, int state)
return -EOPNOTSUPP; return -EOPNOTSUPP;
if (state == 0) { if (state == 0) {
mutex_lock(&smu->mutex);
if (smu->ppt_funcs->baco_exit) if (smu->ppt_funcs->baco_exit)
ret = smu->ppt_funcs->baco_exit(smu); ret = smu->ppt_funcs->baco_exit(smu);
mutex_unlock(&smu->mutex);
} else if (state == 1) { } else if (state == 1) {
mutex_lock(&smu->mutex);
if (smu->ppt_funcs->baco_enter) if (smu->ppt_funcs->baco_enter)
ret = smu->ppt_funcs->baco_enter(smu); ret = smu->ppt_funcs->baco_enter(smu);
mutex_unlock(&smu->mutex);
} else { } else {
return -EINVAL; return -EINVAL;
} }
...@@ -2882,13 +2672,9 @@ bool smu_mode1_reset_is_support(struct smu_context *smu) ...@@ -2882,13 +2672,9 @@ bool smu_mode1_reset_is_support(struct smu_context *smu)
if (!smu->pm_enabled) if (!smu->pm_enabled)
return false; return false;
mutex_lock(&smu->mutex);
if (smu->ppt_funcs && smu->ppt_funcs->mode1_reset_is_support) if (smu->ppt_funcs && smu->ppt_funcs->mode1_reset_is_support)
ret = smu->ppt_funcs->mode1_reset_is_support(smu); ret = smu->ppt_funcs->mode1_reset_is_support(smu);
mutex_unlock(&smu->mutex);
return ret; return ret;
} }
...@@ -2899,13 +2685,9 @@ bool smu_mode2_reset_is_support(struct smu_context *smu) ...@@ -2899,13 +2685,9 @@ bool smu_mode2_reset_is_support(struct smu_context *smu)
if (!smu->pm_enabled) if (!smu->pm_enabled)
return false; return false;
mutex_lock(&smu->mutex);
if (smu->ppt_funcs && smu->ppt_funcs->mode2_reset_is_support) if (smu->ppt_funcs && smu->ppt_funcs->mode2_reset_is_support)
ret = smu->ppt_funcs->mode2_reset_is_support(smu); ret = smu->ppt_funcs->mode2_reset_is_support(smu);
mutex_unlock(&smu->mutex);
return ret; return ret;
} }
...@@ -2916,13 +2698,9 @@ int smu_mode1_reset(struct smu_context *smu) ...@@ -2916,13 +2698,9 @@ int smu_mode1_reset(struct smu_context *smu)
if (!smu->pm_enabled) if (!smu->pm_enabled)
return -EOPNOTSUPP; return -EOPNOTSUPP;
mutex_lock(&smu->mutex);
if (smu->ppt_funcs->mode1_reset) if (smu->ppt_funcs->mode1_reset)
ret = smu->ppt_funcs->mode1_reset(smu); ret = smu->ppt_funcs->mode1_reset(smu);
mutex_unlock(&smu->mutex);
return ret; return ret;
} }
...@@ -2934,13 +2712,9 @@ static int smu_mode2_reset(void *handle) ...@@ -2934,13 +2712,9 @@ static int smu_mode2_reset(void *handle)
if (!smu->pm_enabled) if (!smu->pm_enabled)
return -EOPNOTSUPP; return -EOPNOTSUPP;
mutex_lock(&smu->mutex);
if (smu->ppt_funcs->mode2_reset) if (smu->ppt_funcs->mode2_reset)
ret = smu->ppt_funcs->mode2_reset(smu); ret = smu->ppt_funcs->mode2_reset(smu);
mutex_unlock(&smu->mutex);
if (ret) if (ret)
dev_err(smu->adev->dev, "Mode2 reset failed!\n"); dev_err(smu->adev->dev, "Mode2 reset failed!\n");
...@@ -2956,13 +2730,9 @@ static int smu_get_max_sustainable_clocks_by_dc(void *handle, ...@@ -2956,13 +2730,9 @@ static int smu_get_max_sustainable_clocks_by_dc(void *handle,
if (!smu->pm_enabled || !smu->adev->pm.dpm_enabled) if (!smu->pm_enabled || !smu->adev->pm.dpm_enabled)
return -EOPNOTSUPP; return -EOPNOTSUPP;
mutex_lock(&smu->mutex);
if (smu->ppt_funcs->get_max_sustainable_clocks_by_dc) if (smu->ppt_funcs->get_max_sustainable_clocks_by_dc)
ret = smu->ppt_funcs->get_max_sustainable_clocks_by_dc(smu, max_clocks); ret = smu->ppt_funcs->get_max_sustainable_clocks_by_dc(smu, max_clocks);
mutex_unlock(&smu->mutex);
return ret; return ret;
} }
...@@ -2976,13 +2746,9 @@ static int smu_get_uclk_dpm_states(void *handle, ...@@ -2976,13 +2746,9 @@ static int smu_get_uclk_dpm_states(void *handle,
if (!smu->pm_enabled || !smu->adev->pm.dpm_enabled) if (!smu->pm_enabled || !smu->adev->pm.dpm_enabled)
return -EOPNOTSUPP; return -EOPNOTSUPP;
mutex_lock(&smu->mutex);
if (smu->ppt_funcs->get_uclk_dpm_states) if (smu->ppt_funcs->get_uclk_dpm_states)
ret = smu->ppt_funcs->get_uclk_dpm_states(smu, clock_values_in_khz, num_states); ret = smu->ppt_funcs->get_uclk_dpm_states(smu, clock_values_in_khz, num_states);
mutex_unlock(&smu->mutex);
return ret; return ret;
} }
...@@ -2994,13 +2760,9 @@ static enum amd_pm_state_type smu_get_current_power_state(void *handle) ...@@ -2994,13 +2760,9 @@ static enum amd_pm_state_type smu_get_current_power_state(void *handle)
if (!smu->pm_enabled || !smu->adev->pm.dpm_enabled) if (!smu->pm_enabled || !smu->adev->pm.dpm_enabled)
return -EOPNOTSUPP; return -EOPNOTSUPP;
mutex_lock(&smu->mutex);
if (smu->ppt_funcs->get_current_power_state) if (smu->ppt_funcs->get_current_power_state)
pm_state = smu->ppt_funcs->get_current_power_state(smu); pm_state = smu->ppt_funcs->get_current_power_state(smu);
mutex_unlock(&smu->mutex);
return pm_state; return pm_state;
} }
...@@ -3013,20 +2775,15 @@ static int smu_get_dpm_clock_table(void *handle, ...@@ -3013,20 +2775,15 @@ static int smu_get_dpm_clock_table(void *handle,
if (!smu->pm_enabled || !smu->adev->pm.dpm_enabled) if (!smu->pm_enabled || !smu->adev->pm.dpm_enabled)
return -EOPNOTSUPP; return -EOPNOTSUPP;
mutex_lock(&smu->mutex);
if (smu->ppt_funcs->get_dpm_clock_table) if (smu->ppt_funcs->get_dpm_clock_table)
ret = smu->ppt_funcs->get_dpm_clock_table(smu, clock_table); ret = smu->ppt_funcs->get_dpm_clock_table(smu, clock_table);
mutex_unlock(&smu->mutex);
return ret; return ret;
} }
static ssize_t smu_sys_get_gpu_metrics(void *handle, void **table) static ssize_t smu_sys_get_gpu_metrics(void *handle, void **table)
{ {
struct smu_context *smu = handle; struct smu_context *smu = handle;
ssize_t size;
if (!smu->pm_enabled || !smu->adev->pm.dpm_enabled) if (!smu->pm_enabled || !smu->adev->pm.dpm_enabled)
return -EOPNOTSUPP; return -EOPNOTSUPP;
...@@ -3034,13 +2791,7 @@ static ssize_t smu_sys_get_gpu_metrics(void *handle, void **table) ...@@ -3034,13 +2791,7 @@ static ssize_t smu_sys_get_gpu_metrics(void *handle, void **table)
if (!smu->ppt_funcs->get_gpu_metrics) if (!smu->ppt_funcs->get_gpu_metrics)
return -EOPNOTSUPP; return -EOPNOTSUPP;
mutex_lock(&smu->mutex); return smu->ppt_funcs->get_gpu_metrics(smu, table);
size = smu->ppt_funcs->get_gpu_metrics(smu, table);
mutex_unlock(&smu->mutex);
return size;
} }
static int smu_enable_mgpu_fan_boost(void *handle) static int smu_enable_mgpu_fan_boost(void *handle)
...@@ -3051,13 +2802,9 @@ static int smu_enable_mgpu_fan_boost(void *handle) ...@@ -3051,13 +2802,9 @@ static int smu_enable_mgpu_fan_boost(void *handle)
if (!smu->pm_enabled || !smu->adev->pm.dpm_enabled) if (!smu->pm_enabled || !smu->adev->pm.dpm_enabled)
return -EOPNOTSUPP; return -EOPNOTSUPP;
mutex_lock(&smu->mutex);
if (smu->ppt_funcs->enable_mgpu_fan_boost) if (smu->ppt_funcs->enable_mgpu_fan_boost)
ret = smu->ppt_funcs->enable_mgpu_fan_boost(smu); ret = smu->ppt_funcs->enable_mgpu_fan_boost(smu);
mutex_unlock(&smu->mutex);
return ret; return ret;
} }
...@@ -3067,10 +2814,8 @@ static int smu_gfx_state_change_set(void *handle, ...@@ -3067,10 +2814,8 @@ static int smu_gfx_state_change_set(void *handle,
struct smu_context *smu = handle; struct smu_context *smu = handle;
int ret = 0; int ret = 0;
mutex_lock(&smu->mutex);
if (smu->ppt_funcs->gfx_state_change_set) if (smu->ppt_funcs->gfx_state_change_set)
ret = smu->ppt_funcs->gfx_state_change_set(smu, state); ret = smu->ppt_funcs->gfx_state_change_set(smu, state);
mutex_unlock(&smu->mutex);
return ret; return ret;
} }
...@@ -3079,10 +2824,8 @@ int smu_handle_passthrough_sbr(struct smu_context *smu, bool enable) ...@@ -3079,10 +2824,8 @@ int smu_handle_passthrough_sbr(struct smu_context *smu, bool enable)
{ {
int ret = 0; int ret = 0;
mutex_lock(&smu->mutex);
if (smu->ppt_funcs->smu_handle_passthrough_sbr) if (smu->ppt_funcs->smu_handle_passthrough_sbr)
ret = smu->ppt_funcs->smu_handle_passthrough_sbr(smu, enable); ret = smu->ppt_funcs->smu_handle_passthrough_sbr(smu, enable);
mutex_unlock(&smu->mutex);
return ret; return ret;
} }
...@@ -3091,11 +2834,9 @@ int smu_get_ecc_info(struct smu_context *smu, void *umc_ecc) ...@@ -3091,11 +2834,9 @@ int smu_get_ecc_info(struct smu_context *smu, void *umc_ecc)
{ {
int ret = -EOPNOTSUPP; int ret = -EOPNOTSUPP;
mutex_lock(&smu->mutex);
if (smu->ppt_funcs && if (smu->ppt_funcs &&
smu->ppt_funcs->get_ecc_info) smu->ppt_funcs->get_ecc_info)
ret = smu->ppt_funcs->get_ecc_info(smu, umc_ecc); ret = smu->ppt_funcs->get_ecc_info(smu, umc_ecc);
mutex_unlock(&smu->mutex);
return ret; return ret;
...@@ -3112,12 +2853,10 @@ static int smu_get_prv_buffer_details(void *handle, void **addr, size_t *size) ...@@ -3112,12 +2853,10 @@ static int smu_get_prv_buffer_details(void *handle, void **addr, size_t *size)
*addr = NULL; *addr = NULL;
*size = 0; *size = 0;
mutex_lock(&smu->mutex);
if (memory_pool->bo) { if (memory_pool->bo) {
*addr = memory_pool->cpu_addr; *addr = memory_pool->cpu_addr;
*size = memory_pool->size; *size = memory_pool->size;
} }
mutex_unlock(&smu->mutex);
return 0; return 0;
} }
...@@ -3181,11 +2920,8 @@ int smu_wait_for_event(struct smu_context *smu, enum smu_event_type event, ...@@ -3181,11 +2920,8 @@ int smu_wait_for_event(struct smu_context *smu, enum smu_event_type event,
{ {
int ret = -EINVAL; int ret = -EINVAL;
if (smu->ppt_funcs->wait_for_event) { if (smu->ppt_funcs->wait_for_event)
mutex_lock(&smu->mutex);
ret = smu->ppt_funcs->wait_for_event(smu, event, event_arg); ret = smu->ppt_funcs->wait_for_event(smu, event, event_arg);
mutex_unlock(&smu->mutex);
}
return ret; return ret;
} }
......
...@@ -488,7 +488,6 @@ struct smu_context ...@@ -488,7 +488,6 @@ struct smu_context
const struct cmn2asic_mapping *table_map; const struct cmn2asic_mapping *table_map;
const struct cmn2asic_mapping *pwr_src_map; const struct cmn2asic_mapping *pwr_src_map;
const struct cmn2asic_mapping *workload_map; const struct cmn2asic_mapping *workload_map;
struct mutex mutex;
struct mutex sensor_lock; struct mutex sensor_lock;
struct mutex metrics_lock; struct mutex metrics_lock;
struct mutex message_lock; struct mutex message_lock;
......
...@@ -2118,9 +2118,9 @@ static int arcturus_i2c_xfer(struct i2c_adapter *i2c_adap, ...@@ -2118,9 +2118,9 @@ static int arcturus_i2c_xfer(struct i2c_adapter *i2c_adap,
} }
} }
} }
mutex_lock(&smu->mutex); mutex_lock(&adev->pm.mutex);
r = smu_cmn_update_table(smu, SMU_TABLE_I2C_COMMANDS, 0, req, true); r = smu_cmn_update_table(smu, SMU_TABLE_I2C_COMMANDS, 0, req, true);
mutex_unlock(&smu->mutex); mutex_unlock(&adev->pm.mutex);
if (r) if (r)
goto fail; goto fail;
......
...@@ -2826,9 +2826,9 @@ static int navi10_i2c_xfer(struct i2c_adapter *i2c_adap, ...@@ -2826,9 +2826,9 @@ static int navi10_i2c_xfer(struct i2c_adapter *i2c_adap,
} }
} }
} }
mutex_lock(&smu->mutex); mutex_lock(&adev->pm.mutex);
r = smu_cmn_update_table(smu, SMU_TABLE_I2C_COMMANDS, 0, req, true); r = smu_cmn_update_table(smu, SMU_TABLE_I2C_COMMANDS, 0, req, true);
mutex_unlock(&smu->mutex); mutex_unlock(&adev->pm.mutex);
if (r) if (r)
goto fail; goto fail;
......
...@@ -3497,9 +3497,9 @@ static int sienna_cichlid_i2c_xfer(struct i2c_adapter *i2c_adap, ...@@ -3497,9 +3497,9 @@ static int sienna_cichlid_i2c_xfer(struct i2c_adapter *i2c_adap,
} }
} }
} }
mutex_lock(&smu->mutex); mutex_lock(&adev->pm.mutex);
r = smu_cmn_update_table(smu, SMU_TABLE_I2C_COMMANDS, 0, req, true); r = smu_cmn_update_table(smu, SMU_TABLE_I2C_COMMANDS, 0, req, true);
mutex_unlock(&smu->mutex); mutex_unlock(&adev->pm.mutex);
if (r) if (r)
goto fail; goto fail;
......
...@@ -1521,9 +1521,9 @@ static int aldebaran_i2c_xfer(struct i2c_adapter *i2c_adap, ...@@ -1521,9 +1521,9 @@ static int aldebaran_i2c_xfer(struct i2c_adapter *i2c_adap,
} }
} }
} }
mutex_lock(&smu->mutex); mutex_lock(&adev->pm.mutex);
r = smu_cmn_update_table(smu, SMU_TABLE_I2C_COMMANDS, 0, req, true); r = smu_cmn_update_table(smu, SMU_TABLE_I2C_COMMANDS, 0, req, true);
mutex_unlock(&smu->mutex); mutex_unlock(&adev->pm.mutex);
if (r) if (r)
goto fail; goto fail;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment