Re: [PATCH] drm/amdgpu/smu: add a send message lock

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




On 2/18/20 3:31 PM, Alex Deucher wrote:
The driver uses a scratch register to communicate with the SMU.
Add a lock to make sure we don't try and do this concurrently
by accident.

Signed-off-by: Alex Deucher <alexander.deucher@xxxxxxx>
Acked-by: Nirmoy Das <nirmoy.das@xxxxxxx>
---
  drivers/gpu/drm/amd/powerplay/amdgpu_smu.c     | 1 +
  drivers/gpu/drm/amd/powerplay/inc/amdgpu_smu.h | 1 +
  drivers/gpu/drm/amd/powerplay/smu_v11_0.c      | 7 ++++++-
  drivers/gpu/drm/amd/powerplay/smu_v12_0.c      | 7 ++++++-
  4 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/amd/powerplay/amdgpu_smu.c b/drivers/gpu/drm/amd/powerplay/amdgpu_smu.c
index 437a3e7b36b4..694017740186 100644
--- a/drivers/gpu/drm/amd/powerplay/amdgpu_smu.c
+++ b/drivers/gpu/drm/amd/powerplay/amdgpu_smu.c
@@ -905,6 +905,7 @@ static int smu_sw_init(void *handle)
  	mutex_init(&smu->sensor_lock);
  	mutex_init(&smu->metrics_lock);
  	mutex_init(&smu->update_table_lock);
+	mutex_init(&smu->send_msg_lock);
smu->watermarks_bitmap = 0;
  	smu->power_profile_mode = PP_SMC_POWER_PROFILE_BOOTUP_DEFAULT;
diff --git a/drivers/gpu/drm/amd/powerplay/inc/amdgpu_smu.h b/drivers/gpu/drm/amd/powerplay/inc/amdgpu_smu.h
index 506288072e8e..25fa5c5ed09b 100644
--- a/drivers/gpu/drm/amd/powerplay/inc/amdgpu_smu.h
+++ b/drivers/gpu/drm/amd/powerplay/inc/amdgpu_smu.h
@@ -363,6 +363,7 @@ struct smu_context
  	struct mutex			sensor_lock;
  	struct mutex			metrics_lock;
  	struct mutex			update_table_lock;
+	struct mutex			send_msg_lock;
  	uint64_t pool_size;
struct smu_table_context smu_table;
diff --git a/drivers/gpu/drm/amd/powerplay/smu_v11_0.c b/drivers/gpu/drm/amd/powerplay/smu_v11_0.c
index b06c057a9002..ed5b3afcab66 100644
--- a/drivers/gpu/drm/amd/powerplay/smu_v11_0.c
+++ b/drivers/gpu/drm/amd/powerplay/smu_v11_0.c
@@ -97,12 +97,16 @@ smu_v11_0_send_msg_with_param(struct smu_context *smu,
  	struct amdgpu_device *adev = smu->adev;
  	int ret = 0, index = 0;
+ mutex_lock(&smu->send_msg_lock);
  	index = smu_msg_get_index(smu, msg);
-	if (index < 0)
+	if (index < 0) {
+		mutex_unlock(&smu->send_msg_lock);
  		return index;
+	}
ret = smu_v11_0_wait_for_response(smu);
  	if (ret) {
+		mutex_unlock(&smu->send_msg_lock);
  		pr_err("Msg issuing pre-check failed and "
  		       "SMU may be not in the right state!\n");
  		return ret;
@@ -118,6 +122,7 @@ smu_v11_0_send_msg_with_param(struct smu_context *smu,
  	if (ret)
  		pr_err("failed send message: %10s (%d) \tparam: 0x%08x response %#x\n",
  		       smu_get_message_name(smu, msg), index, param, ret);
+	mutex_unlock(&smu->send_msg_lock);
return ret;
  }
diff --git a/drivers/gpu/drm/amd/powerplay/smu_v12_0.c b/drivers/gpu/drm/amd/powerplay/smu_v12_0.c
index 870e6db2907e..1ca8a8c959b1 100644
--- a/drivers/gpu/drm/amd/powerplay/smu_v12_0.c
+++ b/drivers/gpu/drm/amd/powerplay/smu_v12_0.c
@@ -83,12 +83,16 @@ smu_v12_0_send_msg_with_param(struct smu_context *smu,
  	struct amdgpu_device *adev = smu->adev;
  	int ret = 0, index = 0;
+ mutex_lock(&smu->send_msg_lock);
  	index = smu_msg_get_index(smu, msg);
-	if (index < 0)
+	if (index < 0) {
+		mutex_unlock(&smu->send_msg_lock);
  		return index;
+	}
ret = smu_v12_0_wait_for_response(smu);
  	if (ret) {
+		mutex_unlock(&smu->send_msg_lock);
  		pr_err("Msg issuing pre-check failed and "
  		       "SMU may be not in the right state!\n");
  		return ret;
@@ -104,6 +108,7 @@ smu_v12_0_send_msg_with_param(struct smu_context *smu,
  	if (ret)
  		pr_err("Failed to send message 0x%x, response 0x%x param 0x%x\n",
  		       index, ret, param);
+	mutex_unlock(&smu->send_msg_lock);
return ret;
  }
_______________________________________________
amd-gfx mailing list
amd-gfx@xxxxxxxxxxxxxxxxxxxxx
https://lists.freedesktop.org/mailman/listinfo/amd-gfx



[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux