]> git.proxmox.com Git - mirror_ubuntu-kernels.git/commitdiff
drm/amdgpu: add a mutex for the smu11 i2c bus (v2)
authorAlex Deucher <alexander.deucher@amd.com>
Thu, 21 Jan 2021 21:39:59 +0000 (16:39 -0500)
committerAlex Deucher <alexander.deucher@amd.com>
Thu, 1 Jul 2021 04:24:39 +0000 (00:24 -0400)
So we lock software as well as hardware access to the bus.

v2: fix mutex handling.

Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
Reviewed-by: Luben Tuikov <luben.tuikov@amd.com>
drivers/gpu/drm/amd/amdgpu/smu_v11_0_i2c.c
drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h

index 5c7d769aee3fbadd25fa16dc38ea5fafa674f24e..1d8f6d5180e0994f37083780d7ed5d05ed916875 100644 (file)
@@ -584,12 +584,11 @@ static void lock_bus(struct i2c_adapter *i2c, unsigned int flags)
 {
        struct amdgpu_device *adev = to_amdgpu_device(i2c);
 
-       if (!smu_v11_0_i2c_bus_lock(i2c)) {
+       mutex_lock(&adev->pm.smu_i2c_mutex);
+       if (!smu_v11_0_i2c_bus_lock(i2c))
                DRM_ERROR("Failed to lock the bus from SMU");
-               return;
-       }
-
-       adev->pm.bus_locked = true;
+       else
+               adev->pm.bus_locked = true;
 }
 
 static int trylock_bus(struct i2c_adapter *i2c, unsigned int flags)
@@ -602,12 +601,11 @@ static void unlock_bus(struct i2c_adapter *i2c, unsigned int flags)
 {
        struct amdgpu_device *adev = to_amdgpu_device(i2c);
 
-       if (!smu_v11_0_i2c_bus_unlock(i2c)) {
+       if (!smu_v11_0_i2c_bus_unlock(i2c))
                DRM_ERROR("Failed to unlock the bus from SMU");
-               return;
-       }
-
-       adev->pm.bus_locked = false;
+       else
+               adev->pm.bus_locked = false;
+       mutex_unlock(&adev->pm.smu_i2c_mutex);
 }
 
 static const struct i2c_lock_operations smu_v11_0_i2c_i2c_lock_ops = {
@@ -665,6 +663,7 @@ int smu_v11_0_i2c_control_init(struct i2c_adapter *control)
        struct amdgpu_device *adev = to_amdgpu_device(control);
        int res;
 
+       mutex_init(&adev->pm.smu_i2c_mutex);
        control->owner = THIS_MODULE;
        control->class = I2C_CLASS_SPD;
        control->dev.parent = &adev->pdev->dev;
index f6e0e7d8a00771ada7cc280a34ee737fa6d4ec00..d03e6fa2bf1adf269367843ea52a21cb4285cf05 100644 (file)
@@ -450,6 +450,7 @@ struct amdgpu_pm {
 
        /* Used for I2C access to various EEPROMs on relevant ASICs */
        struct i2c_adapter smu_i2c;
+       struct mutex            smu_i2c_mutex;
        struct list_head        pm_attr_list;
 };