From: Alex Deucher <alexdeucher@gmail.com>
To: amd-gfx@lists.freedesktop.org
Cc: Alex Deucher <alexander.deucher@amd.com>
Subject: [PATCH] drm/amdgpu/smu: add a send message lock
Date: Tue, 18 Feb 2020 09:31:56 -0500 [thread overview]
Message-ID: <20200218143156.1640434-1-alexander.deucher@amd.com> (raw)
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@amd.com>
---
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;
}
--
2.24.1
_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
next reply other threads:[~2020-02-18 14:32 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-02-18 14:31 Alex Deucher [this message]
2020-02-18 14:37 ` [PATCH] drm/amdgpu/smu: add a send message lock Nirmoy
2020-02-19 19:19 ` [PATCH 0/2] Implement SMU message register protection Matt Coffin
2020-02-19 19:19 ` [PATCH 1/2] drm/amdgpu/powerplay: Refactor SMU message handling for safety Matt Coffin
2020-02-25 19:30 ` Alex Deucher
2020-02-26 0:03 ` Matt Coffin
2020-02-26 16:33 ` Deucher, Alexander
2020-02-26 23:05 ` [PATCH v2 0/3] Implement SMU message register protection Matt Coffin
2020-02-26 23:05 ` [PATCH v2 1/3] drm/amdgpu/powerplay: Refactor SMU message handling for safety Matt Coffin
2020-02-26 23:05 ` [PATCH v2 2/3] drm/amdgpu/powerplay: Remove deprecated smc_read_arg Matt Coffin
2020-02-26 23:05 ` [PATCH v2 3/3] drm/amdgpu/smu: Add message sending lock Matt Coffin
2020-02-26 23:16 ` [PATCH v3 0/3] Implement SMU message register protection Matt Coffin
2020-02-26 23:16 ` [PATCH v3 1/3] drm/amdgpu/powerplay: Refactor SMU message handling for safety Matt Coffin
2020-02-26 23:16 ` [PATCH v3 2/3] drm/amdgpu/powerplay: Remove deprecated smc_read_arg Matt Coffin
2020-02-26 23:16 ` [PATCH v3 3/3] drm/amdgpu/smu: Add message sending lock Matt Coffin
2020-02-27 20:49 ` [PATCH v3 0/3] Implement SMU message register protection Alex Deucher
2020-02-27 21:00 ` Matt Coffin
2020-02-27 21:04 ` Alex Deucher
2020-02-19 19:19 ` [PATCH 2/2] drm/amdgpu/smu: Add message sending lock Matt Coffin
2020-02-25 19:31 ` Alex Deucher
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200218143156.1640434-1-alexander.deucher@amd.com \
--to=alexdeucher@gmail.com \
--cc=alexander.deucher@amd.com \
--cc=amd-gfx@lists.freedesktop.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.