]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
drm/amd/pm: Add sysfs node for ubb power
authorAsad Kamal <asad.kamal@amd.com>
Wed, 29 Oct 2025 13:49:59 +0000 (21:49 +0800)
committerAlex Deucher <alexander.deucher@amd.com>
Mon, 8 Dec 2025 18:56:33 +0000 (13:56 -0500)
Add sysfs node to expose ubb power limit for smu_v13_0_12

v2: Update sysfs node name to baseboard_power & baseboard_power_limit to
make it consistent with other node names (Lijo)

Signed-off-by: Asad Kamal <asad.kamal@amd.com>
Reviewed-by: Lijo Lazar <lijo.lazar@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
drivers/gpu/drm/amd/include/kgd_pp_interface.h
drivers/gpu/drm/amd/pm/amdgpu_pm.c

index 2366e68262e685dc061e89e6009d01493a567d06..92477120c28dcf3b56ca778c3737e8b00a728acd 100644 (file)
@@ -166,6 +166,8 @@ enum amd_pp_sensors {
        AMDGPU_PP_SENSOR_NODEPOWER,
        AMDGPU_PP_SENSOR_GPPTRESIDENCY,
        AMDGPU_PP_SENSOR_MAXNODEPOWERLIMIT,
+       AMDGPU_PP_SENSOR_UBB_POWER,
+       AMDGPU_PP_SENSOR_UBB_POWER_LIMIT,
 };
 
 enum amd_pp_task {
index 65296a819e6a12637263c1ed2d6f3f27de94a72d..cfcc85521c95d4c1d9be5891ea3c2d34afe77569 100644 (file)
@@ -2081,9 +2081,10 @@ static int pp_dpm_clk_default_attr_update(struct amdgpu_device *adev, struct amd
  * for user application to monitor various board reated attributes.
  *
  * The amdgpu driver provides a sysfs API for reporting board attributes. Presently,
- * seven types of attributes are reported. Baseboard temperature and
+ * nine types of attributes are reported. Baseboard temperature and
  * gpu board temperature are reported as binary files. Npm status, current node power limit,
- * max node power limit, node power and global ppt residency is reported as ASCII text file.
+ * max node power limit, node power, global ppt residency, baseboard_power, baseboard_power_limit
+ * is reported as ASCII text file.
  *
  * * .. code-block:: console
  *
@@ -2100,6 +2101,10 @@ static int pp_dpm_clk_default_attr_update(struct amdgpu_device *adev, struct amd
  *      hexdump /sys/bus/pci/devices/.../board/node_power
  *
  *      hexdump /sys/bus/pci/devices/.../board/global_ppt_resid
+ *
+ *      hexdump /sys/bus/pci/devices/.../board/baseboard_power
+ *
+ *      hexdump /sys/bus/pci/devices/.../board/baseboard_power_limit
  */
 
 /**
@@ -2294,6 +2299,52 @@ static ssize_t amdgpu_show_max_node_power_limit(struct device *dev,
        return sysfs_emit(buf, "%u\n", max_nplimit);
 }
 
+/**
+ * DOC: baseboard_power
+ *
+ * The amdgpu driver provides a sysfs API for retrieving current ubb power in watts.
+ * The file baseboard_power is used for this.
+ */
+static ssize_t amdgpu_show_baseboard_power(struct device *dev,
+                                          struct device_attribute *attr, char *buf)
+{
+       struct drm_device *ddev = dev_get_drvdata(dev);
+       struct amdgpu_device *adev = drm_to_adev(ddev);
+       u32 ubbpower;
+       int r;
+
+       /* get the ubb power */
+       r = amdgpu_pm_get_sensor_generic(adev, AMDGPU_PP_SENSOR_UBB_POWER,
+                                        (void *)&ubbpower);
+       if (r)
+               return r;
+
+       return sysfs_emit(buf, "%u\n", ubbpower);
+}
+
+/**
+ * DOC: baseboard_power_limit
+ *
+ * The amdgpu driver provides a sysfs API for retrieving threshold ubb power in watts.
+ * The file baseboard_power_limit is used for this.
+ */
+static ssize_t amdgpu_show_baseboard_power_limit(struct device *dev,
+                                                struct device_attribute *attr, char *buf)
+{
+       struct drm_device *ddev = dev_get_drvdata(dev);
+       struct amdgpu_device *adev = drm_to_adev(ddev);
+       u32 ubbpowerlimit;
+       int r;
+
+       /* get the ubb power limit */
+       r = amdgpu_pm_get_sensor_generic(adev, AMDGPU_PP_SENSOR_UBB_POWER_LIMIT,
+                                        (void *)&ubbpowerlimit);
+       if (r)
+               return r;
+
+       return sysfs_emit(buf, "%u\n", ubbpowerlimit);
+}
+
 static DEVICE_ATTR(baseboard_temp, 0444, amdgpu_get_baseboard_temp_metrics, NULL);
 static DEVICE_ATTR(gpuboard_temp, 0444, amdgpu_get_gpuboard_temp_metrics, NULL);
 static DEVICE_ATTR(cur_node_power_limit, 0444, amdgpu_show_cur_node_power_limit, NULL);
@@ -2301,6 +2352,8 @@ static DEVICE_ATTR(node_power, 0444, amdgpu_show_node_power, NULL);
 static DEVICE_ATTR(global_ppt_resid, 0444, amdgpu_show_global_ppt_resid, NULL);
 static DEVICE_ATTR(max_node_power_limit, 0444, amdgpu_show_max_node_power_limit, NULL);
 static DEVICE_ATTR(npm_status, 0444, amdgpu_show_npm_status, NULL);
+static DEVICE_ATTR(baseboard_power, 0444, amdgpu_show_baseboard_power, NULL);
+static DEVICE_ATTR(baseboard_power_limit, 0444, amdgpu_show_baseboard_power_limit, NULL);
 
 static struct attribute *board_attrs[] = {
        &dev_attr_baseboard_temp.attr,
@@ -4756,6 +4809,14 @@ int amdgpu_pm_sysfs_init(struct amdgpu_device *adev)
                        sysfs_add_file_to_group(&adev->dev->kobj, &dev_attr_npm_status.attr,
                                                amdgpu_board_attr_group.name);
                }
+               if (amdgpu_pm_get_sensor_generic(adev, AMDGPU_PP_SENSOR_UBB_POWER_LIMIT,
+                                                (void *)&tmp) != -EOPNOTSUPP) {
+                       sysfs_add_file_to_group(&adev->dev->kobj,
+                                               &dev_attr_baseboard_power_limit.attr,
+                                               amdgpu_board_attr_group.name);
+                       sysfs_add_file_to_group(&adev->dev->kobj, &dev_attr_baseboard_power.attr,
+                                               amdgpu_board_attr_group.name);
+               }
        }
 
        adev->pm.sysfs_initialized = true;