Skip to contentSkip to conversation

drm/amdgpu: Reorganize sysfs ini/fini calls

PATCH In review Lijo Lazar 2 participants 4 messages Oct 8, 2025

Subsystems (3)
lore
Share & tools
lore

Lijo Lazar

author
#0 lore raw

PATCH 1/3 drm/amdgpu: Reorganize sysfs ini/fini calls

Aggregate sysfs ini/fini calls into separate functions. No functional change.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 88 +++++++++++++---------
 1 file changed, 51 insertions(+), 37 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +51 -37
index 7a899fb4de29..7e428e7bffd6 100644
@@ -4384,6 +4384,55 @@ static void amdgpu_device_set_mcbp(struct amdgpu_device *adev)
 		dev_info(adev->dev, "MCBP is enabled\n");
 }
 
+static int amdgpu_device_sys_interface_init(struct amdgpu_device *adev)
+{
+	int r;
+
+	r = amdgpu_atombios_sysfs_init(adev);
+	if (r)
+		drm_err(&adev->ddev,
+			"registering atombios sysfs failed (%d).\n", r);
+
+	r = amdgpu_pm_sysfs_init(adev);
+	if (r)
+		dev_err(adev->dev, "registering pm sysfs failed (%d).\n", r);
+
+	r = amdgpu_ucode_sysfs_init(adev);
+	if (r) {
+		adev->ucode_sysfs_en = false;
+		dev_err(adev->dev, "Creating firmware sysfs failed (%d).\n", r);
+	} else
+		adev->ucode_sysfs_en = true;
+
+	r = amdgpu_device_attr_sysfs_init(adev);
+	if (r)
+		dev_err(adev->dev, "Could not create amdgpu device attr\n");
+
+	r = devm_device_add_group(adev->dev, &amdgpu_board_attrs_group);
+	if (r)
+		dev_err(adev->dev,
+			"Could not create amdgpu board attributes\n");
+
+	amdgpu_fru_sysfs_init(adev);
+	amdgpu_reg_state_sysfs_init(adev);
+	amdgpu_xcp_sysfs_init(adev);
+
+	return r;
+}
+
+static void amdgpu_device_sys_interface_fini(struct amdgpu_device *adev)
+{
+	if (adev->pm.sysfs_initialized)
+		amdgpu_pm_sysfs_fini(adev);
+	if (adev->ucode_sysfs_en)
+		amdgpu_ucode_sysfs_fini(adev);
+	amdgpu_device_attr_sysfs_fini(adev);
+	amdgpu_fru_sysfs_fini(adev);
+
+	amdgpu_reg_state_sysfs_fini(adev);
+	amdgpu_xcp_sysfs_fini(adev);
+}
+
 /**
  * amdgpu_device_init - initialize the driver
  *
@@ -4812,34 +4861,7 @@ int amdgpu_device_init(struct amdgpu_device *adev,
 	 * operations performed in `late_init` might affect the sysfs
 	 * interfaces creating.
 	 */
-	r = amdgpu_atombios_sysfs_init(adev);
-	if (r)
-		drm_err(&adev->ddev,
-			"registering atombios sysfs failed (%d).\n", r);
-
-	r = amdgpu_pm_sysfs_init(adev);
-	if (r)
-		dev_err(adev->dev, "registering pm sysfs failed (%d).\n", r);
-
-	r = amdgpu_ucode_sysfs_init(adev);
-	if (r) {
-		adev->ucode_sysfs_en = false;
-		dev_err(adev->dev, "Creating firmware sysfs failed (%d).\n", r);
-	} else
-		adev->ucode_sysfs_en = true;
-
-	r = amdgpu_device_attr_sysfs_init(adev);
-	if (r)
-		dev_err(adev->dev, "Could not create amdgpu device attr\n");
-
-	r = devm_device_add_group(adev->dev, &amdgpu_board_attrs_group);
-	if (r)
-		dev_err(adev->dev,
-			"Could not create amdgpu board attributes\n");
-
-	amdgpu_fru_sysfs_init(adev);
-	amdgpu_reg_state_sysfs_init(adev);
-	amdgpu_xcp_sysfs_init(adev);
+	r = amdgpu_device_sys_interface_init(adev);
 
 	if (IS_ENABLED(CONFIG_PERF_EVENTS))
 		r = amdgpu_pmu_init(adev);
@@ -4961,15 +4983,7 @@ void amdgpu_device_fini_hw(struct amdgpu_device *adev)
 	}
 	amdgpu_fence_driver_hw_fini(adev);
 
-	if (adev->pm.sysfs_initialized)
-		amdgpu_pm_sysfs_fini(adev);
-	if (adev->ucode_sysfs_en)
-		amdgpu_ucode_sysfs_fini(adev);
-	amdgpu_device_attr_sysfs_fini(adev);
-	amdgpu_fru_sysfs_fini(adev);
-
-	amdgpu_reg_state_sysfs_fini(adev);
-	amdgpu_xcp_sysfs_fini(adev);
+	amdgpu_device_sys_interface_fini(adev);
 
 	/* disable ras feature must before hw fini */
 	amdgpu_ras_pre_fini(adev);
Signature · 1 line
2.49.0
author
#1 lore raw

PATCH 2/3 drm/amdgpu: Move reset-on-init sequence earlier

Complete reset-on-init sequence before sysfs interfaces are created. Devices get properly initiaized only after reset, and then only sysfs interfaces should be made available.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +2 -3
index 7e428e7bffd6..3bc2bc0d525d 100644
@@ -4856,6 +4856,8 @@ int amdgpu_device_init(struct amdgpu_device *adev,
 		flush_delayed_work(&adev->delayed_init_work);
 	}
 
+	if (adev->init_lvl->level == AMDGPU_INIT_LEVEL_MINIMAL_XGMI)
+		amdgpu_xgmi_reset_on_init(adev);
 	/*
 	 * Place those sysfs registering after `late_init`. As some of those
 	 * operations performed in `late_init` might affect the sysfs
@@ -4889,9 +4891,6 @@ int amdgpu_device_init(struct amdgpu_device *adev,
 	if (px)
 		vga_switcheroo_init_domain_pm_ops(adev->dev, &adev->vga_pm_domain);
 
-	if (adev->init_lvl->level == AMDGPU_INIT_LEVEL_MINIMAL_XGMI)
-		amdgpu_xgmi_reset_on_init(adev);
-
 	amdgpu_device_check_iommu_direct_map(adev);
 
 	adev->pm_nb.notifier_call = amdgpu_device_pm_notifier;
Signature · 1 line
2.49.0
author
#2 lore raw

PATCH 3/3 drm/amd/pm: Grant interface access after full init

In reply to Lijo Lazar

Allow access to user interfaces like sysfs/hwmon only after full initialization of the device. When device is part of XGMI hive and a reset is required during initialization, the inteface files will be created as part of minimal device initialization. Full initialization of the device will be done only after all devices in XGMI hive are probed and a reset is done together on all.

---
 drivers/gpu/drm/amd/pm/amdgpu_pm.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/pm/amdgpu_pm.c +2 -1
index b5fbb0fd1dc0..c49884b318b3 100644
@@ -108,8 +108,9 @@ const char * const amdgpu_pp_profile_name[] = {
 static int amdgpu_pm_dev_state_check(struct amdgpu_device *adev, bool runpm)
 {
 	bool runpm_check = runpm ? adev->in_runpm : false;
+	bool full_init = (adev->init_lvl->level == AMDGPU_INIT_LEVEL_DEFAULT);
 
-	if (amdgpu_in_reset(adev))
+	if (amdgpu_in_reset(adev) || !full_init)
 		return -EBUSY;
 
 	if (adev->in_suspend && !runpm_check)
Signature · 1 line
2.49.0
Reviewed-by on v1 1/3
#3 lore raw
In reply to Lijo Lazar

[AMD Official Use Only - AMD Internal Distribution Only]

Series is

Thanks & Regards
Asad

-----Original Message-----
From: Lazar, Lijo <[email protected]>
Sent: Wednesday, October 8, 2025 1:40 PM
To: [email protected]
Cc: Zhang, Hawking <[email protected]>; Deucher, Alexander <[email protected]>; Kamal, Asad <[email protected]>
Subject: [PATCH 1/3] drm/amdgpu: Reorganize sysfs ini/fini calls

Aggregate sysfs ini/fini calls into separate functions. No functional change.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 88 +++++++++++++---------
 1 file changed, 51 insertions(+), 37 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +51 -37
index 7a899fb4de29..7e428e7bffd6 100644
@@ -4384,6 +4384,55 @@ static void amdgpu_device_set_mcbp(struct amdgpu_device *adev)
                dev_info(adev->dev, "MCBP is enabled\n");  }
 
+static int amdgpu_device_sys_interface_init(struct amdgpu_device *adev)
+{
+       int r;
+
+       r = amdgpu_atombios_sysfs_init(adev);
+       if (r)
+               drm_err(&adev->ddev,
+                       "registering atombios sysfs failed (%d).\n", r);
+
+       r = amdgpu_pm_sysfs_init(adev);
+       if (r)
+               dev_err(adev->dev, "registering pm sysfs failed (%d).\n", r);
+
+       r = amdgpu_ucode_sysfs_init(adev);
+       if (r) {
+               adev->ucode_sysfs_en = false;
+               dev_err(adev->dev, "Creating firmware sysfs failed (%d).\n", r);
+       } else
+               adev->ucode_sysfs_en = true;
+
+       r = amdgpu_device_attr_sysfs_init(adev);
+       if (r)
+               dev_err(adev->dev, "Could not create amdgpu device attr\n");
+
+       r = devm_device_add_group(adev->dev, &amdgpu_board_attrs_group);
+       if (r)
+               dev_err(adev->dev,
+                       "Could not create amdgpu board attributes\n");
+
+       amdgpu_fru_sysfs_init(adev);
+       amdgpu_reg_state_sysfs_init(adev);
+       amdgpu_xcp_sysfs_init(adev);
+
+       return r;
+}
+
+static void amdgpu_device_sys_interface_fini(struct amdgpu_device
+*adev) {
+       if (adev->pm.sysfs_initialized)
+               amdgpu_pm_sysfs_fini(adev);
+       if (adev->ucode_sysfs_en)
+               amdgpu_ucode_sysfs_fini(adev);
+       amdgpu_device_attr_sysfs_fini(adev);
+       amdgpu_fru_sysfs_fini(adev);
+
+       amdgpu_reg_state_sysfs_fini(adev);
+       amdgpu_xcp_sysfs_fini(adev);
+}
+
 /**
  * amdgpu_device_init - initialize the driver
  *
@@ -4812,34 +4861,7 @@ int amdgpu_device_init(struct amdgpu_device *adev,
         * operations performed in `late_init` might affect the sysfs
         * interfaces creating.
         */
-       r = amdgpu_atombios_sysfs_init(adev);
-       if (r)
-               drm_err(&adev->ddev,
-                       "registering atombios sysfs failed (%d).\n", r);
-
-       r = amdgpu_pm_sysfs_init(adev);
-       if (r)
-               dev_err(adev->dev, "registering pm sysfs failed (%d).\n", r);
-
-       r = amdgpu_ucode_sysfs_init(adev);
-       if (r) {
-               adev->ucode_sysfs_en = false;
-               dev_err(adev->dev, "Creating firmware sysfs failed (%d).\n", r);
-       } else
-               adev->ucode_sysfs_en = true;
-
-       r = amdgpu_device_attr_sysfs_init(adev);
-       if (r)
-               dev_err(adev->dev, "Could not create amdgpu device attr\n");
-
-       r = devm_device_add_group(adev->dev, &amdgpu_board_attrs_group);
-       if (r)
-               dev_err(adev->dev,
-                       "Could not create amdgpu board attributes\n");
-
-       amdgpu_fru_sysfs_init(adev);
-       amdgpu_reg_state_sysfs_init(adev);
-       amdgpu_xcp_sysfs_init(adev);
+       r = amdgpu_device_sys_interface_init(adev);
 
        if (IS_ENABLED(CONFIG_PERF_EVENTS))
                r = amdgpu_pmu_init(adev);
@@ -4961,15 +4983,7 @@ void amdgpu_device_fini_hw(struct amdgpu_device *adev)
        }
        amdgpu_fence_driver_hw_fini(adev);
 
-       if (adev->pm.sysfs_initialized)
-               amdgpu_pm_sysfs_fini(adev);
-       if (adev->ucode_sysfs_en)
-               amdgpu_ucode_sysfs_fini(adev);
-       amdgpu_device_attr_sysfs_fini(adev);
-       amdgpu_fru_sysfs_fini(adev);
-
-       amdgpu_reg_state_sysfs_fini(adev);
-       amdgpu_xcp_sysfs_fini(adev);
+       amdgpu_device_sys_interface_fini(adev);
 
        /* disable ras feature must before hw fini */
        amdgpu_ras_pre_fini(adev);

--
2.49.0