Commit 3712e7a4 authored by Evan Quan's avatar Evan Quan Committed by Alex Deucher

drm/amd/pm: unified lock protections in amdgpu_dpm.c

As the only entry point, it's now safe and reasonable to
enforce the lock protections in amdgpu_dpm.c. And with
this, we can drop other internal used power locks.
Signed-off-by: default avatarEvan Quan <evan.quan@amd.com>
Reviewed-by: default avatarLijo Lazar <lijo.lazar@amd.com>
Signed-off-by: default avatarAlex Deucher <alexander.deucher@amd.com>
parent 61d7d0d5
This diff is collapsed.
...@@ -3040,21 +3040,18 @@ static int kv_dpm_sw_init(void *handle) ...@@ -3040,21 +3040,18 @@ static int kv_dpm_sw_init(void *handle)
return 0; return 0;
INIT_WORK(&adev->pm.dpm.thermal.work, amdgpu_dpm_thermal_work_handler); INIT_WORK(&adev->pm.dpm.thermal.work, amdgpu_dpm_thermal_work_handler);
mutex_lock(&adev->pm.mutex);
ret = kv_dpm_init(adev); ret = kv_dpm_init(adev);
if (ret) if (ret)
goto dpm_failed; goto dpm_failed;
adev->pm.dpm.current_ps = adev->pm.dpm.requested_ps = adev->pm.dpm.boot_ps; adev->pm.dpm.current_ps = adev->pm.dpm.requested_ps = adev->pm.dpm.boot_ps;
if (amdgpu_dpm == 1) if (amdgpu_dpm == 1)
amdgpu_pm_print_power_states(adev); amdgpu_pm_print_power_states(adev);
mutex_unlock(&adev->pm.mutex);
DRM_INFO("amdgpu: dpm initialized\n"); DRM_INFO("amdgpu: dpm initialized\n");
return 0; return 0;
dpm_failed: dpm_failed:
kv_dpm_fini(adev); kv_dpm_fini(adev);
mutex_unlock(&adev->pm.mutex);
DRM_ERROR("amdgpu: dpm initialization failed\n"); DRM_ERROR("amdgpu: dpm initialization failed\n");
return ret; return ret;
} }
...@@ -3065,9 +3062,7 @@ static int kv_dpm_sw_fini(void *handle) ...@@ -3065,9 +3062,7 @@ static int kv_dpm_sw_fini(void *handle)
flush_work(&adev->pm.dpm.thermal.work); flush_work(&adev->pm.dpm.thermal.work);
mutex_lock(&adev->pm.mutex);
kv_dpm_fini(adev); kv_dpm_fini(adev);
mutex_unlock(&adev->pm.mutex);
return 0; return 0;
} }
...@@ -3080,14 +3075,12 @@ static int kv_dpm_hw_init(void *handle) ...@@ -3080,14 +3075,12 @@ static int kv_dpm_hw_init(void *handle)
if (!amdgpu_dpm) if (!amdgpu_dpm)
return 0; return 0;
mutex_lock(&adev->pm.mutex);
kv_dpm_setup_asic(adev); kv_dpm_setup_asic(adev);
ret = kv_dpm_enable(adev); ret = kv_dpm_enable(adev);
if (ret) if (ret)
adev->pm.dpm_enabled = false; adev->pm.dpm_enabled = false;
else else
adev->pm.dpm_enabled = true; adev->pm.dpm_enabled = true;
mutex_unlock(&adev->pm.mutex);
amdgpu_legacy_dpm_compute_clocks(adev); amdgpu_legacy_dpm_compute_clocks(adev);
return ret; return ret;
} }
...@@ -3096,11 +3089,8 @@ static int kv_dpm_hw_fini(void *handle) ...@@ -3096,11 +3089,8 @@ static int kv_dpm_hw_fini(void *handle)
{ {
struct amdgpu_device *adev = (struct amdgpu_device *)handle; struct amdgpu_device *adev = (struct amdgpu_device *)handle;
if (adev->pm.dpm_enabled) { if (adev->pm.dpm_enabled)
mutex_lock(&adev->pm.mutex);
kv_dpm_disable(adev); kv_dpm_disable(adev);
mutex_unlock(&adev->pm.mutex);
}
return 0; return 0;
} }
...@@ -3110,12 +3100,10 @@ static int kv_dpm_suspend(void *handle) ...@@ -3110,12 +3100,10 @@ static int kv_dpm_suspend(void *handle)
struct amdgpu_device *adev = (struct amdgpu_device *)handle; struct amdgpu_device *adev = (struct amdgpu_device *)handle;
if (adev->pm.dpm_enabled) { if (adev->pm.dpm_enabled) {
mutex_lock(&adev->pm.mutex);
/* disable dpm */ /* disable dpm */
kv_dpm_disable(adev); kv_dpm_disable(adev);
/* reset the power state */ /* reset the power state */
adev->pm.dpm.current_ps = adev->pm.dpm.requested_ps = adev->pm.dpm.boot_ps; adev->pm.dpm.current_ps = adev->pm.dpm.requested_ps = adev->pm.dpm.boot_ps;
mutex_unlock(&adev->pm.mutex);
} }
return 0; return 0;
} }
...@@ -3127,14 +3115,12 @@ static int kv_dpm_resume(void *handle) ...@@ -3127,14 +3115,12 @@ static int kv_dpm_resume(void *handle)
if (adev->pm.dpm_enabled) { if (adev->pm.dpm_enabled) {
/* asic init will reset to the boot state */ /* asic init will reset to the boot state */
mutex_lock(&adev->pm.mutex);
kv_dpm_setup_asic(adev); kv_dpm_setup_asic(adev);
ret = kv_dpm_enable(adev); ret = kv_dpm_enable(adev);
if (ret) if (ret)
adev->pm.dpm_enabled = false; adev->pm.dpm_enabled = false;
else else
adev->pm.dpm_enabled = true; adev->pm.dpm_enabled = true;
mutex_unlock(&adev->pm.mutex);
if (adev->pm.dpm_enabled) if (adev->pm.dpm_enabled)
amdgpu_legacy_dpm_compute_clocks(adev); amdgpu_legacy_dpm_compute_clocks(adev);
} }
......
...@@ -7786,21 +7786,18 @@ static int si_dpm_sw_init(void *handle) ...@@ -7786,21 +7786,18 @@ static int si_dpm_sw_init(void *handle)
return ret; return ret;
INIT_WORK(&adev->pm.dpm.thermal.work, amdgpu_dpm_thermal_work_handler); INIT_WORK(&adev->pm.dpm.thermal.work, amdgpu_dpm_thermal_work_handler);
mutex_lock(&adev->pm.mutex);
ret = si_dpm_init(adev); ret = si_dpm_init(adev);
if (ret) if (ret)
goto dpm_failed; goto dpm_failed;
adev->pm.dpm.current_ps = adev->pm.dpm.requested_ps = adev->pm.dpm.boot_ps; adev->pm.dpm.current_ps = adev->pm.dpm.requested_ps = adev->pm.dpm.boot_ps;
if (amdgpu_dpm == 1) if (amdgpu_dpm == 1)
amdgpu_pm_print_power_states(adev); amdgpu_pm_print_power_states(adev);
mutex_unlock(&adev->pm.mutex);
DRM_INFO("amdgpu: dpm initialized\n"); DRM_INFO("amdgpu: dpm initialized\n");
return 0; return 0;
dpm_failed: dpm_failed:
si_dpm_fini(adev); si_dpm_fini(adev);
mutex_unlock(&adev->pm.mutex);
DRM_ERROR("amdgpu: dpm initialization failed\n"); DRM_ERROR("amdgpu: dpm initialization failed\n");
return ret; return ret;
} }
...@@ -7811,9 +7808,7 @@ static int si_dpm_sw_fini(void *handle) ...@@ -7811,9 +7808,7 @@ static int si_dpm_sw_fini(void *handle)
flush_work(&adev->pm.dpm.thermal.work); flush_work(&adev->pm.dpm.thermal.work);
mutex_lock(&adev->pm.mutex);
si_dpm_fini(adev); si_dpm_fini(adev);
mutex_unlock(&adev->pm.mutex);
return 0; return 0;
} }
...@@ -7827,14 +7822,12 @@ static int si_dpm_hw_init(void *handle) ...@@ -7827,14 +7822,12 @@ static int si_dpm_hw_init(void *handle)
if (!amdgpu_dpm) if (!amdgpu_dpm)
return 0; return 0;
mutex_lock(&adev->pm.mutex);
si_dpm_setup_asic(adev); si_dpm_setup_asic(adev);
ret = si_dpm_enable(adev); ret = si_dpm_enable(adev);
if (ret) if (ret)
adev->pm.dpm_enabled = false; adev->pm.dpm_enabled = false;
else else
adev->pm.dpm_enabled = true; adev->pm.dpm_enabled = true;
mutex_unlock(&adev->pm.mutex);
amdgpu_legacy_dpm_compute_clocks(adev); amdgpu_legacy_dpm_compute_clocks(adev);
return ret; return ret;
} }
...@@ -7843,11 +7836,8 @@ static int si_dpm_hw_fini(void *handle) ...@@ -7843,11 +7836,8 @@ static int si_dpm_hw_fini(void *handle)
{ {
struct amdgpu_device *adev = (struct amdgpu_device *)handle; struct amdgpu_device *adev = (struct amdgpu_device *)handle;
if (adev->pm.dpm_enabled) { if (adev->pm.dpm_enabled)
mutex_lock(&adev->pm.mutex);
si_dpm_disable(adev); si_dpm_disable(adev);
mutex_unlock(&adev->pm.mutex);
}
return 0; return 0;
} }
...@@ -7857,12 +7847,10 @@ static int si_dpm_suspend(void *handle) ...@@ -7857,12 +7847,10 @@ static int si_dpm_suspend(void *handle)
struct amdgpu_device *adev = (struct amdgpu_device *)handle; struct amdgpu_device *adev = (struct amdgpu_device *)handle;
if (adev->pm.dpm_enabled) { if (adev->pm.dpm_enabled) {
mutex_lock(&adev->pm.mutex);
/* disable dpm */ /* disable dpm */
si_dpm_disable(adev); si_dpm_disable(adev);
/* reset the power state */ /* reset the power state */
adev->pm.dpm.current_ps = adev->pm.dpm.requested_ps = adev->pm.dpm.boot_ps; adev->pm.dpm.current_ps = adev->pm.dpm.requested_ps = adev->pm.dpm.boot_ps;
mutex_unlock(&adev->pm.mutex);
} }
return 0; return 0;
} }
...@@ -7874,14 +7862,12 @@ static int si_dpm_resume(void *handle) ...@@ -7874,14 +7862,12 @@ static int si_dpm_resume(void *handle)
if (adev->pm.dpm_enabled) { if (adev->pm.dpm_enabled) {
/* asic init will reset to the boot state */ /* asic init will reset to the boot state */
mutex_lock(&adev->pm.mutex);
si_dpm_setup_asic(adev); si_dpm_setup_asic(adev);
ret = si_dpm_enable(adev); ret = si_dpm_enable(adev);
if (ret) if (ret)
adev->pm.dpm_enabled = false; adev->pm.dpm_enabled = false;
else else
adev->pm.dpm_enabled = true; adev->pm.dpm_enabled = true;
mutex_unlock(&adev->pm.mutex);
if (adev->pm.dpm_enabled) if (adev->pm.dpm_enabled)
amdgpu_legacy_dpm_compute_clocks(adev); amdgpu_legacy_dpm_compute_clocks(adev);
} }
......
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