drm/amdgpu/smu: Add message sending lock
authorMatt Coffin <mcoffin13@gmail.com>
Wed, 26 Feb 2020 23:16:14 +0000 (16:16 -0700)
committerAlex Deucher <alexander.deucher@amd.com>
Fri, 28 Feb 2020 21:59:23 +0000 (16:59 -0500)
This adds a message lock to the smu_send_smc_msg* implementations to
protect against concurrent access to the mmu registers used to
communicate with the SMU

v2: Implement for smu_v12_0 as well

v3: Add mutex_init for message_lock

Signed-off-by: Matt Coffin <mcoffin13@gmail.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
drivers/gpu/drm/amd/powerplay/amdgpu_smu.c
drivers/gpu/drm/amd/powerplay/inc/amdgpu_smu.h
drivers/gpu/drm/amd/powerplay/smu_v11_0.c
drivers/gpu/drm/amd/powerplay/smu_v12_0.c

index f3505bb632efd0cb5ac2773c326c65edf3de5212..9f6da26be90b8ad1041faa28f391fc3f314397c2 100644 (file)
@@ -889,6 +889,7 @@ static int smu_sw_init(void *handle)
 
        mutex_init(&smu->sensor_lock);
        mutex_init(&smu->metrics_lock);
+       mutex_init(&smu->message_lock);
 
        smu->watermarks_bitmap = 0;
        smu->power_profile_mode = PP_SMC_POWER_PROFILE_BOOTUP_DEFAULT;
index 573929114617c45450fa3fb928a05f8dac949f78..d652f920a65aa76be136e333f8b93a7c54157454 100644 (file)
@@ -362,6 +362,7 @@ struct smu_context
        struct mutex                    mutex;
        struct mutex                    sensor_lock;
        struct mutex                    metrics_lock;
+       struct mutex                    message_lock;
        uint64_t pool_size;
 
        struct smu_table_context        smu_table;
index 2f8ea65cf3fa15e738b0169d384fe8363275b073..b12d9ec10639058385d71bf2f60ae31b3d493176 100644 (file)
@@ -102,11 +102,12 @@ smu_v11_0_send_msg_with_param(struct smu_context *smu,
        if (index < 0)
                return index;
 
+       mutex_lock(&smu->message_lock);
        ret = smu_v11_0_wait_for_response(smu);
        if (ret) {
                pr_err("Msg issuing pre-check failed and "
                       "SMU may be not in the right state!\n");
-               return ret;
+               goto out;
        }
 
        WREG32_SOC15(MP1, 0, mmMP1_SMN_C2PMSG_90, 0);
@@ -119,18 +120,19 @@ 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);
-               return ret;
+               goto out;
        }
        if (read_arg) {
                ret = smu_v11_0_read_arg(smu, read_arg);
                if (ret) {
                        pr_err("failed to read message arg: %10s (%d) \tparam: 0x%08x response %#x\n",
                               smu_get_message_name(smu, msg), index, param, ret);
-                       return ret;
+                       goto out;
                }
        }
-
-       return 0;
+out:
+       mutex_unlock(&smu->message_lock);
+       return ret;
 }
 
 int smu_v11_0_init_microcode(struct smu_context *smu)
index c18b08c8cb9ada24f867829e245c487838b358fb..93b85585fd26421dd03b05429a50dc2870b41430 100644 (file)
@@ -88,11 +88,12 @@ smu_v12_0_send_msg_with_param(struct smu_context *smu,
        if (index < 0)
                return index;
 
+       mutex_lock(&smu->message_lock);
        ret = smu_v12_0_wait_for_response(smu);
        if (ret) {
                pr_err("Msg issuing pre-check failed and "
                       "SMU may be not in the right state!\n");
-               return ret;
+               goto out;
        }
 
        WREG32_SOC15(MP1, 0, mmMP1_SMN_C2PMSG_90, 0);
@@ -105,17 +106,18 @@ 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);
-               return ret;
+               goto out;
        }
        if (read_arg) {
                ret = smu_v12_0_read_arg(smu, read_arg);
                if (ret) {
                        pr_err("Failed to read message arg 0x%x, response 0x%x param 0x%x\n",
                               index, ret, param);
-                       return ret;
+                       goto out;
                }
        }
-
+out:
+       mutex_unlock(&smu->message_lock);
        return ret;
 }