[PATCH 4/4] drm/amd/powerplay: add check before i2c_add_adapter

Wang, Kevin(Yang) Kevin1.Wang at amd.com
Tue May 26 10:18:23 UTC 2020


[AMD Official Use Only - Internal Distribution Only]


________________________________
From: amd-gfx <amd-gfx-bounces at lists.freedesktop.org> on behalf of Wenhui Sheng <Wenhui.Sheng at amd.com>
Sent: Tuesday, May 26, 2020 6:05 PM
To: amd-gfx at lists.freedesktop.org <amd-gfx at lists.freedesktop.org>
Cc: Sheng, Wenhui <Wenhui.Sheng at amd.com>; Zhang, Hawking <Hawking.Zhang at amd.com>
Subject: [PATCH 4/4] drm/amd/powerplay: add check before i2c_add_adapter

smu_i2c_eeprom_init may be invoked twice or more
under sroiv mode, while we don't want to add check
if (!amdgpu_sriov_vf) before we invoke smu_i2c_eeprom_init/fini
each time, so we check if i2c adapter is already added
before we invoke i2c_add_adapter

Signed-off-by: Wenhui Sheng <Wenhui.Sheng at amd.com>
Change-Id: I3500ff474e0f04ea6bd4f9adf9f97b159443dfd9
Reviewed-by: Hawking Zhang <Hawking.Zhang at amd.com>
---
 drivers/gpu/drm/amd/powerplay/amdgpu_smu.c   | 24 +++++++-------------
 drivers/gpu/drm/amd/powerplay/arcturus_ppt.c | 14 ++++++++++++
 2 files changed, 22 insertions(+), 16 deletions(-)

diff --git a/drivers/gpu/drm/amd/powerplay/amdgpu_smu.c b/drivers/gpu/drm/amd/powerplay/amdgpu_smu.c
index 1e9be1dcc62b..8ce907280dc9 100644
--- a/drivers/gpu/drm/amd/powerplay/amdgpu_smu.c
+++ b/drivers/gpu/drm/amd/powerplay/amdgpu_smu.c
@@ -1354,11 +1354,9 @@ static int smu_hw_init(void *handle)
         if (ret)
                 goto failed;

-       if (!amdgpu_sriov_vf(adev)) {
-               ret = smu_i2c_eeprom_init(smu, &adev->pm.smu_i2c);
-               if (ret)
-                       goto failed;
-       }
+       ret = smu_i2c_eeprom_init(smu, &adev->pm.smu_i2c);
+       if (ret)
+               goto failed;

         adev->pm.dpm_enabled = true;

@@ -1396,9 +1394,7 @@ static int smu_hw_fini(void *handle)

         adev->pm.dpm_enabled = false;

-       if (!amdgpu_sriov_vf(adev)) {
-               smu_i2c_eeprom_fini(smu, &adev->pm.smu_i2c);
-       }
+       smu_i2c_eeprom_fini(smu, &adev->pm.smu_i2c);

         ret = smu_stop_thermal_control(smu);
         if (ret) {
@@ -1539,9 +1535,7 @@ static int smu_suspend(void *handle)

         adev->pm.dpm_enabled = false;

-       if (!amdgpu_sriov_vf(adev)) {
-               smu_i2c_eeprom_fini(smu, &adev->pm.smu_i2c);
-       }
+       smu_i2c_eeprom_fini(smu, &adev->pm.smu_i2c);

         ret = smu_disable_dpm(smu);
         if (ret)
@@ -1586,11 +1580,9 @@ static int smu_resume(void *handle)
         if (ret)
                 goto failed;

-       if (!amdgpu_sriov_vf(adev)) {
-               ret = smu_i2c_eeprom_init(smu, &adev->pm.smu_i2c);
-               if (ret)
-                       goto failed;
-       }
+       ret = smu_i2c_eeprom_init(smu, &adev->pm.smu_i2c);
+       if (ret)
+               goto failed;

         if (smu->is_apu)
                 smu_set_gfx_cgpg(&adev->smu, true);
diff --git a/drivers/gpu/drm/amd/powerplay/arcturus_ppt.c b/drivers/gpu/drm/amd/powerplay/arcturus_ppt.c
index 70cc1c12f196..437f8a317838 100644
--- a/drivers/gpu/drm/amd/powerplay/arcturus_ppt.c
+++ b/drivers/gpu/drm/amd/powerplay/arcturus_ppt.c
@@ -2224,11 +2224,22 @@ static const struct i2c_algorithm arcturus_i2c_eeprom_i2c_algo = {
         .functionality = arcturus_i2c_eeprom_i2c_func,
 };

+static bool arcturus_i2c_adapter_is_added(struct i2c_adapter *control)
+{
+       struct amdgpu_device *adev = to_amdgpu_device(control);
+
+       return control->dev.parent == &adev->pdev->dev ? true : false;
[kevin]:
please change code from
"return control->dev.parent == &adev->pdev->dev ? true : false;"
to
"return control->dev.parent == &adev->pdev->dev".

after fixed, Series is
Reviewed-by: Kevin Wang <kevin1.wang at amd.com>

+}


+
 static int arcturus_i2c_eeprom_control_init(struct i2c_adapter *control)
 {
         struct amdgpu_device *adev = to_amdgpu_device(control);
         int res;

+       /* smu_i2c_eeprom_init may be called twice in sriov */
+       if (arcturus_i2c_adapter_is_added(control))
+               return 0;
+
         control->owner = THIS_MODULE;
         control->class = I2C_CLASS_SPD;
         control->dev.parent = &adev->pdev->dev;
@@ -2244,6 +2255,9 @@ static int arcturus_i2c_eeprom_control_init(struct i2c_adapter *control)

 static void arcturus_i2c_eeprom_control_fini(struct i2c_adapter *control)
 {
+       if (!arcturus_i2c_adapter_is_added(control))
+               return;
+
         i2c_del_adapter(control);
 }

--
2.17.1

_______________________________________________
amd-gfx mailing list
amd-gfx at lists.freedesktop.org
https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.freedesktop.org%2Fmailman%2Flistinfo%2Famd-gfx&data=02%7C01%7CKevin1.Wang%40amd.com%7C598c8cf6946745005df908d8015c692b%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637260843721510576&sdata=lQSeaMsfm7pHjDP%2FLo94JqVzSZEIF1NLTNz3fSvkJ3k%3D&reserved=0
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/amd-gfx/attachments/20200526/2e1791ce/attachment.htm>


More information about the amd-gfx mailing list