drm/amd/pm: add fan acoustic limit OD setting support for SMU13
authorEvan Quan <evan.quan@amd.com>
Fri, 11 Aug 2023 09:53:08 +0000 (17:53 +0800)
committerAlex Deucher <alexander.deucher@amd.com>
Thu, 31 Aug 2023 20:40:25 +0000 (16:40 -0400)
Add SMU13 fan acoustic limit OD setting support.

Signed-off-by: Evan Quan <evan.quan@amd.com>
Reviewed-by: Alex Deucher <alexander.deucher@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
Documentation/gpu/amdgpu/thermal.rst
drivers/gpu/drm/amd/include/kgd_pp_interface.h
drivers/gpu/drm/amd/pm/amdgpu_pm.c
drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c
drivers/gpu/drm/amd/pm/swsmu/inc/smu_types.h
drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_0_ppt.c
drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c

index 08ee33b2acb66a385d12675cb5fdb8f6f59e6d73..8ed888f81d2c960e9469f01cc576522febc53afe 100644 (file)
@@ -70,6 +70,12 @@ fan_curve
 .. kernel-doc:: drivers/gpu/drm/amd/pm/amdgpu_pm.c
    :doc: fan_curve
 
+acoustic_limit_rpm_threshold
+----------------------------
+
+.. kernel-doc:: drivers/gpu/drm/amd/pm/amdgpu_pm.c
+   :doc: acoustic_limit_rpm_threshold
+
 GFXOFF
 ======
 
index 7bdd2bdab970f1c38048a7466f683af18d5d835c..e3dcef8c4ab7d104bf843aa18d57248b769e5b97 100644 (file)
@@ -114,6 +114,7 @@ enum pp_clock_type {
        OD_VDDGFX_OFFSET,
        OD_CCLK,
        OD_FAN_CURVE,
+       OD_ACOUSTIC_LIMIT,
 };
 
 enum amd_pp_sensors {
@@ -189,6 +190,7 @@ enum PP_OD_DPM_TABLE_COMMAND {
        PP_OD_COMMIT_DPM_TABLE,
        PP_OD_EDIT_VDDGFX_OFFSET,
        PP_OD_EDIT_FAN_CURVE,
+       PP_OD_EDIT_ACOUSTIC_LIMIT,
 };
 
 struct pp_states_info {
index 1008d43e9c3fb4d39d6b496cf29a1344ae7fe0d5..1ec8a8c4016afac72dcc63da2413979158642623 100644 (file)
@@ -3575,6 +3575,61 @@ static umode_t fan_curve_visible(struct amdgpu_device *adev)
        return umode;
 }
 
+/**
+ * DOC: acoustic_limit_rpm_threshold
+ *
+ * The amdgpu driver provides a sysfs API for checking and adjusting the
+ * acoustic limit in RPM for fan control.
+ *
+ * Reading back the file shows you the current setting and the permitted
+ * ranges if changable.
+ *
+ * Writing an integer to the file, change the setting accordingly.
+ *
+ * When you have finished the editing, write "c" (commit) to the file to commit
+ * your changes.
+ *
+ * This setting works under auto fan control mode only. It adjusts the PMFW's
+ * behavior about the maximum speed in RPM the fan can spin. Setting via this
+ * interface will switch the fan control to auto mode implicitly.
+ */
+static ssize_t acoustic_limit_threshold_show(struct kobject *kobj,
+                                            struct kobj_attribute *attr,
+                                            char *buf)
+{
+       struct od_kobj *container = container_of(kobj, struct od_kobj, kobj);
+       struct amdgpu_device *adev = (struct amdgpu_device *)container->priv;
+
+       return (ssize_t)amdgpu_retrieve_od_settings(adev, OD_ACOUSTIC_LIMIT, buf);
+}
+
+static ssize_t acoustic_limit_threshold_store(struct kobject *kobj,
+                                             struct kobj_attribute *attr,
+                                             const char *buf,
+                                             size_t count)
+{
+       struct od_kobj *container = container_of(kobj, struct od_kobj, kobj);
+       struct amdgpu_device *adev = (struct amdgpu_device *)container->priv;
+
+       return (ssize_t)amdgpu_distribute_custom_od_settings(adev,
+                                                            PP_OD_EDIT_ACOUSTIC_LIMIT,
+                                                            buf,
+                                                            count);
+}
+
+static umode_t acoustic_limit_threshold_visible(struct amdgpu_device *adev)
+{
+       umode_t umode = 0000;
+
+       if (adev->pm.od_feature_mask & OD_OPS_SUPPORT_ACOUSTIC_LIMIT_THRESHOLD_RETRIEVE)
+               umode |= S_IRUSR | S_IRGRP | S_IROTH;
+
+       if (adev->pm.od_feature_mask & OD_OPS_SUPPORT_ACOUSTIC_LIMIT_THRESHOLD_SET)
+               umode |= S_IWUSR;
+
+       return umode;
+}
+
 static struct od_feature_set amdgpu_od_set = {
        .containers = {
                [0] = {
@@ -3588,6 +3643,14 @@ static struct od_feature_set amdgpu_od_set = {
                                                .store = fan_curve_store,
                                        },
                                },
+                               [1] = {
+                                       .name = "acoustic_limit_rpm_threshold",
+                                       .ops = {
+                                               .is_visible = acoustic_limit_threshold_visible,
+                                               .show = acoustic_limit_threshold_show,
+                                               .store = acoustic_limit_threshold_store,
+                                       },
+                               },
                        },
                },
        },
index 90544a8f450c35c59aaec7f11860a0717e934301..984fda278f1aa5a5d9c8c505650ce8eeebbfb3a6 100644 (file)
@@ -316,6 +316,8 @@ struct config_table_setting
 
 #define OD_OPS_SUPPORT_FAN_CURVE_RETRIEVE              BIT(0)
 #define OD_OPS_SUPPORT_FAN_CURVE_SET                   BIT(1)
+#define OD_OPS_SUPPORT_ACOUSTIC_LIMIT_THRESHOLD_RETRIEVE       BIT(2)
+#define OD_OPS_SUPPORT_ACOUSTIC_LIMIT_THRESHOLD_SET            BIT(3)
 
 struct amdgpu_pm {
        struct mutex            mutex;
index 2d73a63813de88226a7afc5e4cc038248885843f..ca41cfd57d89fac48bb1633af3c2353e52d270bd 100644 (file)
@@ -2483,6 +2483,8 @@ static enum smu_clk_type smu_convert_to_smuclk(enum pp_clock_type type)
                clk_type = SMU_OD_CCLK; break;
        case OD_FAN_CURVE:
                clk_type = SMU_OD_FAN_CURVE; break;
+       case OD_ACOUSTIC_LIMIT:
+               clk_type = SMU_OD_ACOUSTIC_LIMIT; break;
        default:
                clk_type = SMU_CLK_COUNT; break;
        }
index 83e1d43efd2b626192c781dfdb6243909a5cbe05..76bb1cba9b839c33b8025d14b8c9037c23fbff9e 100644 (file)
@@ -281,6 +281,7 @@ enum smu_clk_type {
        SMU_OD_RANGE,
        SMU_OD_VDDGFX_OFFSET,
        SMU_OD_FAN_CURVE,
+       SMU_OD_ACOUSTIC_LIMIT,
        SMU_CLK_COUNT,
 };
 
index 09297dbcbdf19c2e0e79fa88093e5fdaa07b487d..021cff1995daf27bfa4df424fb021ad43da4a5e4 100644 (file)
 #define PP_OD_FEATURE_GFX_VF_CURVE                     4
 #define PP_OD_FEATURE_FAN_CURVE_TEMP                   5
 #define PP_OD_FEATURE_FAN_CURVE_PWM                    6
+#define PP_OD_FEATURE_FAN_ACOUSTIC_LIMIT               7
 
 #define LINK_SPEED_MAX                                 3
 
@@ -1132,6 +1133,10 @@ static void smu_v13_0_0_get_od_setting_limits(struct smu_context *smu,
                od_min_setting = overdrive_lowerlimits->FanLinearPwmPoints;
                od_max_setting = overdrive_upperlimits->FanLinearPwmPoints;
                break;
+       case PP_OD_FEATURE_FAN_ACOUSTIC_LIMIT:
+               od_min_setting = overdrive_lowerlimits->AcousticLimitRpmThreshold;
+               od_max_setting = overdrive_upperlimits->AcousticLimitRpmThreshold;
+               break;
        default:
                od_min_setting = od_max_setting = INT_MAX;
                break;
@@ -1380,6 +1385,24 @@ static int smu_v13_0_0_print_clk_levels(struct smu_context *smu,
 
                break;
 
+       case SMU_OD_ACOUSTIC_LIMIT:
+               if (!smu_v13_0_0_is_od_feature_supported(smu,
+                                                        PP_OD_FEATURE_FAN_CURVE_BIT))
+                       break;
+
+               size += sysfs_emit_at(buf, size, "OD_ACOUSTIC_LIMIT:\n");
+               size += sysfs_emit_at(buf, size, "%d\n",
+                                       (int)od_table->OverDriveTable.AcousticLimitRpmThreshold);
+
+               size += sysfs_emit_at(buf, size, "%s:\n", "OD_RANGE");
+               smu_v13_0_0_get_od_setting_limits(smu,
+                                                 PP_OD_FEATURE_FAN_ACOUSTIC_LIMIT,
+                                                 &min_value,
+                                                 &max_value);
+               size += sysfs_emit_at(buf, size, "ACOUSTIC_LIMIT: %u %u\n",
+                                     min_value, max_value);
+               break;
+
        case SMU_OD_RANGE:
                if (!smu_v13_0_0_is_od_feature_supported(smu, PP_OD_FEATURE_GFXCLK_BIT) &&
                    !smu_v13_0_0_is_od_feature_supported(smu, PP_OD_FEATURE_UCLK_BIT) &&
@@ -1628,6 +1651,28 @@ static int smu_v13_0_0_od_edit_dpm_table(struct smu_context *smu,
                od_table->OverDriveTable.FeatureCtrlMask |= BIT(PP_OD_FEATURE_FAN_CURVE_BIT);
                break;
 
+       case PP_OD_EDIT_ACOUSTIC_LIMIT:
+               if (!smu_v13_0_0_is_od_feature_supported(smu, PP_OD_FEATURE_FAN_CURVE_BIT)) {
+                       dev_warn(adev->dev, "Fan curve setting not supported!\n");
+                       return -ENOTSUPP;
+               }
+
+               smu_v13_0_0_get_od_setting_limits(smu,
+                                                 PP_OD_FEATURE_FAN_ACOUSTIC_LIMIT,
+                                                 &minimum,
+                                                 &maximum);
+               if (input[0] < minimum ||
+                   input[0] > maximum) {
+                       dev_info(adev->dev, "acoustic limit threshold setting(%ld) must be within [%d, %d]!\n",
+                                input[0], minimum, maximum);
+                       return -EINVAL;
+               }
+
+               od_table->OverDriveTable.AcousticLimitRpmThreshold = input[0];
+               od_table->OverDriveTable.FanMode = FAN_MODE_AUTO;
+               od_table->OverDriveTable.FeatureCtrlMask |= BIT(PP_OD_FEATURE_FAN_CURVE_BIT);
+               break;
+
        case PP_OD_RESTORE_DEFAULT_TABLE:
                feature_ctrlmask = od_table->OverDriveTable.FeatureCtrlMask;
                memcpy(od_table,
@@ -1885,7 +1930,9 @@ static void smu_v13_0_0_set_supported_od_feature_mask(struct smu_context *smu)
        if (smu_v13_0_0_is_od_feature_supported(smu,
                                                PP_OD_FEATURE_FAN_CURVE_BIT))
                adev->pm.od_feature_mask |= OD_OPS_SUPPORT_FAN_CURVE_RETRIEVE |
-                                           OD_OPS_SUPPORT_FAN_CURVE_SET;
+                                           OD_OPS_SUPPORT_FAN_CURVE_SET |
+                                           OD_OPS_SUPPORT_ACOUSTIC_LIMIT_THRESHOLD_RETRIEVE |
+                                           OD_OPS_SUPPORT_ACOUSTIC_LIMIT_THRESHOLD_SET;
 }
 
 static int smu_v13_0_0_set_default_od_settings(struct smu_context *smu)
@@ -1943,6 +1990,8 @@ static int smu_v13_0_0_set_default_od_settings(struct smu_context *smu)
                        user_od_table->OverDriveTable.FanLinearPwmPoints[i] =
                                user_od_table_bak.OverDriveTable.FanLinearPwmPoints[i];
                }
+               user_od_table->OverDriveTable.AcousticLimitRpmThreshold =
+                       user_od_table_bak.OverDriveTable.AcousticLimitRpmThreshold;
        }
 
        smu_v13_0_0_set_supported_od_feature_mask(smu);
index 3e852bf6177e87d469d569660b22b35996154ae0..f9486c7e26bf779d778db2cd8e5b3cfdab077d77 100644 (file)
@@ -79,6 +79,7 @@
 #define PP_OD_FEATURE_GFX_VF_CURVE                     4
 #define PP_OD_FEATURE_FAN_CURVE_TEMP                   5
 #define PP_OD_FEATURE_FAN_CURVE_PWM                    6
+#define PP_OD_FEATURE_FAN_ACOUSTIC_LIMIT               7
 
 #define LINK_SPEED_MAX                                 3
 
@@ -1112,6 +1113,10 @@ static void smu_v13_0_7_get_od_setting_limits(struct smu_context *smu,
                od_min_setting = overdrive_lowerlimits->FanLinearPwmPoints;
                od_max_setting = overdrive_upperlimits->FanLinearPwmPoints;
                break;
+       case PP_OD_FEATURE_FAN_ACOUSTIC_LIMIT:
+               od_min_setting = overdrive_lowerlimits->AcousticLimitRpmThreshold;
+               od_max_setting = overdrive_upperlimits->AcousticLimitRpmThreshold;
+               break;
        default:
                od_min_setting = od_max_setting = INT_MAX;
                break;
@@ -1360,6 +1365,24 @@ static int smu_v13_0_7_print_clk_levels(struct smu_context *smu,
 
                break;
 
+       case SMU_OD_ACOUSTIC_LIMIT:
+               if (!smu_v13_0_7_is_od_feature_supported(smu,
+                                                        PP_OD_FEATURE_FAN_CURVE_BIT))
+                       break;
+
+               size += sysfs_emit_at(buf, size, "OD_ACOUSTIC_LIMIT:\n");
+               size += sysfs_emit_at(buf, size, "%d\n",
+                                       (int)od_table->OverDriveTable.AcousticLimitRpmThreshold);
+
+               size += sysfs_emit_at(buf, size, "%s:\n", "OD_RANGE");
+               smu_v13_0_7_get_od_setting_limits(smu,
+                                                 PP_OD_FEATURE_FAN_ACOUSTIC_LIMIT,
+                                                 &min_value,
+                                                 &max_value);
+               size += sysfs_emit_at(buf, size, "ACOUSTIC_LIMIT: %u %u\n",
+                                     min_value, max_value);
+               break;
+
        case SMU_OD_RANGE:
                if (!smu_v13_0_7_is_od_feature_supported(smu, PP_OD_FEATURE_GFXCLK_BIT) &&
                    !smu_v13_0_7_is_od_feature_supported(smu, PP_OD_FEATURE_UCLK_BIT) &&
@@ -1608,6 +1631,28 @@ static int smu_v13_0_7_od_edit_dpm_table(struct smu_context *smu,
                od_table->OverDriveTable.FeatureCtrlMask |= BIT(PP_OD_FEATURE_FAN_CURVE_BIT);
                break;
 
+       case PP_OD_EDIT_ACOUSTIC_LIMIT:
+               if (!smu_v13_0_7_is_od_feature_supported(smu, PP_OD_FEATURE_FAN_CURVE_BIT)) {
+                       dev_warn(adev->dev, "Fan curve setting not supported!\n");
+                       return -ENOTSUPP;
+               }
+
+               smu_v13_0_7_get_od_setting_limits(smu,
+                                                 PP_OD_FEATURE_FAN_ACOUSTIC_LIMIT,
+                                                 &minimum,
+                                                 &maximum);
+               if (input[0] < minimum ||
+                   input[0] > maximum) {
+                       dev_info(adev->dev, "acoustic limit threshold setting(%ld) must be within [%d, %d]!\n",
+                                input[0], minimum, maximum);
+                       return -EINVAL;
+               }
+
+               od_table->OverDriveTable.AcousticLimitRpmThreshold = input[0];
+               od_table->OverDriveTable.FanMode = FAN_MODE_AUTO;
+               od_table->OverDriveTable.FeatureCtrlMask |= BIT(PP_OD_FEATURE_FAN_CURVE_BIT);
+               break;
+
        case PP_OD_RESTORE_DEFAULT_TABLE:
                feature_ctrlmask = od_table->OverDriveTable.FeatureCtrlMask;
                memcpy(od_table,
@@ -1860,7 +1905,9 @@ static void smu_v13_0_7_set_supported_od_feature_mask(struct smu_context *smu)
        if (smu_v13_0_7_is_od_feature_supported(smu,
                                                PP_OD_FEATURE_FAN_CURVE_BIT))
                adev->pm.od_feature_mask |= OD_OPS_SUPPORT_FAN_CURVE_RETRIEVE |
-                                           OD_OPS_SUPPORT_FAN_CURVE_SET;
+                                           OD_OPS_SUPPORT_FAN_CURVE_SET |
+                                           OD_OPS_SUPPORT_ACOUSTIC_LIMIT_THRESHOLD_RETRIEVE |
+                                           OD_OPS_SUPPORT_ACOUSTIC_LIMIT_THRESHOLD_SET;
 }
 
 static int smu_v13_0_7_set_default_od_settings(struct smu_context *smu)
@@ -1918,6 +1965,8 @@ static int smu_v13_0_7_set_default_od_settings(struct smu_context *smu)
                        user_od_table->OverDriveTable.FanLinearPwmPoints[i] =
                                user_od_table_bak.OverDriveTable.FanLinearPwmPoints[i];
                }
+               user_od_table->OverDriveTable.AcousticLimitRpmThreshold =
+                       user_od_table_bak.OverDriveTable.AcousticLimitRpmThreshold;
        }
 
        smu_v13_0_7_set_supported_od_feature_mask(smu);