Skip to contentSkip to conversation

drm/amd/pm: introduce a new set of OD interfaces

PATCH Superseded Evan Quan 2 participants 14 messages Aug 23, 2023 – Aug 25, 2023

Subsystems (5)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Evan Quan

author
#0 lore raw

PATCH v2 1/8 drm/amd/pm: introduce a new set of OD interfaces

There will be multiple interfaces(sysfs files) exposed with each representing a single OD functionality. And all those interface will be arranged in a tree liked hierarchy with the top dir as "gpu_od". Meanwhile all functionalities for the same component will be arranged under the same directory.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_device.c |   2 +
 drivers/gpu/drm/amd/pm/amdgpu_pm.c         | 264 ++++++++++++++++++++-
 drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h    |   2 +
 3 files changed, 266 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +2 -0
index 533daba2accb..7aae2801b36e 100644
@@ -3623,6 +3623,8 @@ int amdgpu_device_init(struct amdgpu_device *adev,
 
 	INIT_LIST_HEAD(&adev->ras_list);
 
+	INIT_LIST_HEAD(&adev->pm.od_kobj_list);
+
 	INIT_DELAYED_WORK(&adev->delayed_init_work,
 			  amdgpu_device_delayed_init_work_handler);
 	INIT_DELAYED_WORK(&adev->gfx.gfx_off_delay_work,
drivers/gpu/drm/amd/pm/amdgpu_pm.c +262 -2

293 lines not on this page · raw message

drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h +2 -0
index 42172b00be66..4cab6a2efb63 100644
@@ -366,6 +366,8 @@ struct amdgpu_pm {
 	struct config_table_setting config_table;
 	/* runtime mode */
 	enum amdgpu_runpm_mode rpm_mode;
+
+	struct list_head	od_kobj_list;
 };
 
 int amdgpu_dpm_read_sensor(struct amdgpu_device *adev, enum amd_pp_sensors sensor,
Signature · 1 line
2.34.1
author
#1 lore raw

PATCH v2 2/8 drm/amdgpu: revise the device initialization sequences

By placing the sysfs interfaces creation after .late_int. Since some operations performed during .late_init may affect how the sysfs interfaces should be created.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 37 ++++++++++++----------
 1 file changed, 21 insertions(+), 16 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +21 -16
index 7aae2801b36e..92db80089cf4 100644
@@ -3861,22 +3861,6 @@ int amdgpu_device_init(struct amdgpu_device *adev,
 	/* Get a log2 for easy divisions. */
 	adev->mm_stats.log2_max_MBps = ilog2(max(1u, max_MBps));
 
-	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)
-		DRM_ERROR("registering pm sysfs failed (%d).\n", r);
-
-	r = amdgpu_ucode_sysfs_init(adev);
-	if (r) {
-		adev->ucode_sysfs_en = false;
-		DRM_ERROR("Creating firmware sysfs failed (%d).\n", r);
-	} else
-		adev->ucode_sysfs_en = true;
-
 	/*
 	 * Register gpu instance before amdgpu_device_enable_mgpu_fan_boost.
 	 * Otherwise the mgpu fan boost feature will be skipped due to the
@@ -3905,6 +3889,27 @@ int amdgpu_device_init(struct amdgpu_device *adev,
 		flush_delayed_work(&adev->delayed_init_work);
 	}
 
+	/*
+	 * Place those sysfs registering after `late_init`. As some of those
+	 * 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)
+		DRM_ERROR("registering pm sysfs failed (%d).\n", r);
+
+	r = amdgpu_ucode_sysfs_init(adev);
+	if (r) {
+		adev->ucode_sysfs_en = false;
+		DRM_ERROR("Creating firmware sysfs failed (%d).\n", r);
+	} else
+		adev->ucode_sysfs_en = true;
+
 	r = sysfs_create_files(&adev->dev->kobj, amdgpu_dev_attributes);
 	if (r)
 		dev_err(adev->dev, "Could not create amdgpu device attr\n");
Signature · 1 line
2.34.1
author
#2 lore raw

PATCH v2 3/8 drm/amd/pm: add fan mode OD setting support for SMU13

In reply to Evan Quan

Add SMU13 fan mode OD setting support.

--
v1->v2:
- add missing kerneldoc for the new interface(Alex)

---
 Documentation/gpu/amdgpu/thermal.rst          |   6 +
 .../gpu/drm/amd/include/kgd_pp_interface.h    |   4 +-
 drivers/gpu/drm/amd/pm/amdgpu_pm.c            | 200 +++++++++++++++++-
 drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h       |   4 +
 drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c     |   2 +
 drivers/gpu/drm/amd/pm/swsmu/inc/smu_types.h  |   1 +
 .../drm/amd/pm/swsmu/smu13/smu_v13_0_0_ppt.c  |  35 ++-
 .../drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c  |  35 ++-
 8 files changed, 279 insertions(+), 8 deletions(-)
Documentation/gpu/amdgpu/thermal.rst +6 -0
index 5e27e4eb3959..8757ec7f0136 100644
@@ -64,6 +64,12 @@ gpu_metrics
 .. kernel-doc:: drivers/gpu/drm/amd/pm/amdgpu_pm.c
    :doc: gpu_metrics
 
+fan_mode
+--------
+
+.. kernel-doc:: drivers/gpu/drm/amd/pm/amdgpu_pm.c
+   :doc: fan_mode
+
 GFXOFF
 ======
 
drivers/gpu/drm/amd/include/kgd_pp_interface.h +3 -1
index 84c5224d994c..020c9ce1f735 100644
@@ -113,6 +113,7 @@ enum pp_clock_type {
 	OD_RANGE,
 	OD_VDDGFX_OFFSET,
 	OD_CCLK,
+	OD_FAN_MODE,
 };
 
 enum amd_pp_sensors {
@@ -186,7 +187,8 @@ enum PP_OD_DPM_TABLE_COMMAND {
 	PP_OD_EDIT_VDDC_CURVE,
 	PP_OD_RESTORE_DEFAULT_TABLE,
 	PP_OD_COMMIT_DPM_TABLE,
-	PP_OD_EDIT_VDDGFX_OFFSET
+	PP_OD_EDIT_VDDGFX_OFFSET,
+	PP_OD_EDIT_FAN_MODE,
 };
 
 struct pp_states_info {
drivers/gpu/drm/amd/pm/amdgpu_pm.c +199 -1

206 lines not on this page · raw message

drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h +4 -0
index 4cab6a2efb63..b54f84e2408a 100644
@@ -314,6 +314,9 @@ struct config_table_setting
 	uint16_t fclk_average_tau;
 };
 
+#define OD_OPS_SUPPORT_FAN_MODE_RETRIEVE		BIT(0)
+#define OD_OPS_SUPPORT_FAN_MODE_SET			BIT(1)
+
 struct amdgpu_pm {
 	struct mutex		mutex;
 	u32                     current_sclk;
@@ -368,6 +371,7 @@ struct amdgpu_pm {
 	enum amdgpu_runpm_mode rpm_mode;
 
 	struct list_head	od_kobj_list;
+	uint32_t		od_feature_mask;
 };
 
 int amdgpu_dpm_read_sensor(struct amdgpu_device *adev, enum amd_pp_sensors sensor,
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +2 -0
index f005a90c35af..01ccfd219d6b 100644
@@ -2481,6 +2481,8 @@ static enum smu_clk_type smu_convert_to_smuclk(enum pp_clock_type type)
 		clk_type = SMU_OD_VDDGFX_OFFSET; break;
 	case OD_CCLK:
 		clk_type = SMU_OD_CCLK; break;
+	case OD_FAN_MODE:
+		clk_type = SMU_OD_FAN_MODE; break;
 	default:
 		clk_type = SMU_CLK_COUNT; break;
 	}
drivers/gpu/drm/amd/pm/swsmu/inc/smu_types.h +1 -0
index e57265cf637c..498000850212 100644
@@ -280,6 +280,7 @@ enum smu_clk_type {
 	SMU_OD_VDDC_CURVE,
 	SMU_OD_RANGE,
 	SMU_OD_VDDGFX_OFFSET,
+	SMU_OD_FAN_MODE,
 	SMU_CLK_COUNT,
 };
 
drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_0_ppt.c +32 -3
index 1041ba22f8f8..45b42e43f9a3 100644
@@ -101,6 +101,7 @@
 #define PP_OD_FEATURE_UCLK_FMIN				2
 #define PP_OD_FEATURE_UCLK_FMAX				3
 #define PP_OD_FEATURE_GFX_VF_CURVE			4
+#define PP_OD_FEATURE_FAN_MODE				5
 
 #define LINK_SPEED_MAX					3
 
@@ -1110,6 +1111,10 @@ static void smu_v13_0_0_get_od_setting_limits(struct smu_context *smu,
 		od_min_setting = overdrive_lowerlimits->VoltageOffsetPerZoneBoundary;
 		od_max_setting = overdrive_upperlimits->VoltageOffsetPerZoneBoundary;
 		break;
+	case PP_OD_FEATURE_FAN_MODE:
+		od_min_setting = overdrive_lowerlimits->FanMode;
+		od_max_setting = overdrive_upperlimits->FanMode;
+		break;
 	default:
 		od_min_setting = od_max_setting = INT_MAX;
 		break;
@@ -1329,6 +1334,16 @@ static int smu_v13_0_0_print_clk_levels(struct smu_context *smu,
 				      od_table->OverDriveTable.VoltageOffsetPerZoneBoundary[0]);
 		break;
 
+	case SMU_OD_FAN_MODE:
+		if (!smu_v13_0_0_is_od_feature_supported(smu,
+							 PP_OD_FEATURE_FAN_CURVE_BIT))
+			break;
+
+		size += sysfs_emit_at(buf, size, "OD_FAN_MODE:\n");
+		size += sysfs_emit_at(buf, size, "%d\n",
+					(int)od_table->OverDriveTable.FanMode);
+		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) &&
@@ -1789,6 +1804,15 @@ static ssize_t smu_v13_0_0_get_gpu_metrics(struct smu_context *smu,
 	return sizeof(struct gpu_metrics_v1_3);
 }
 
+static void smu_v13_0_0_set_supported_od_feature_mask(struct smu_context *smu)
+{
+	struct amdgpu_device *adev = smu->adev;
+
+	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_MODE_RETRIEVE;
+}
+
 static int smu_v13_0_0_set_default_od_settings(struct smu_context *smu)
 {
 	OverDriveTableExternal_t *od_table =
@@ -1838,8 +1862,12 @@ static int smu_v13_0_0_set_default_od_settings(struct smu_context *smu)
 		for (i = 0; i < PP_NUM_OD_VF_CURVE_POINTS; i++)
 			user_od_table->OverDriveTable.VoltageOffsetPerZoneBoundary[i] =
 				user_od_table_bak.OverDriveTable.VoltageOffsetPerZoneBoundary[i];
+		user_od_table->OverDriveTable.FanMode =
+			user_od_table_bak.OverDriveTable.FanMode;
 	}
 
+	smu_v13_0_0_set_supported_od_feature_mask(smu);
+
 	return 0;
 }
 
@@ -1850,9 +1878,10 @@ static int smu_v13_0_0_restore_user_od_settings(struct smu_context *smu)
 	OverDriveTableExternal_t *user_od_table = table_context->user_overdrive_table;
 	int res;
 
-	user_od_table->OverDriveTable.FeatureCtrlMask = 1U << PP_OD_FEATURE_GFXCLK_BIT |
-							1U << PP_OD_FEATURE_UCLK_BIT |
-							1U << PP_OD_FEATURE_GFX_VF_CURVE_BIT;
+	user_od_table->OverDriveTable.FeatureCtrlMask = BIT(PP_OD_FEATURE_GFXCLK_BIT) |
+							BIT(PP_OD_FEATURE_UCLK_BIT) |
+							BIT(PP_OD_FEATURE_GFX_VF_CURVE_BIT) |
+							BIT(PP_OD_FEATURE_FAN_CURVE_BIT);
 	res = smu_v13_0_0_upload_overdrive_table(smu, user_od_table);
 	user_od_table->OverDriveTable.FeatureCtrlMask = 0;
 	if (res == 0)
drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c +32 -3
index 328765f89c94..28c2e4b0e55d 100644
@@ -77,6 +77,7 @@
 #define PP_OD_FEATURE_UCLK_FMIN				2
 #define PP_OD_FEATURE_UCLK_FMAX				3
 #define PP_OD_FEATURE_GFX_VF_CURVE			4
+#define PP_OD_FEATURE_FAN_MODE				5
 
 #define LINK_SPEED_MAX					3
 
@@ -1096,6 +1097,10 @@ static void smu_v13_0_7_get_od_setting_limits(struct smu_context *smu,
 		od_min_setting = overdrive_lowerlimits->VoltageOffsetPerZoneBoundary;
 		od_max_setting = overdrive_upperlimits->VoltageOffsetPerZoneBoundary;
 		break;
+	case PP_OD_FEATURE_FAN_MODE:
+		od_min_setting = overdrive_lowerlimits->FanMode;
+		od_max_setting = overdrive_upperlimits->FanMode;
+		break;
 	default:
 		od_min_setting = od_max_setting = INT_MAX;
 		break;
@@ -1315,6 +1320,16 @@ static int smu_v13_0_7_print_clk_levels(struct smu_context *smu,
 				      od_table->OverDriveTable.VoltageOffsetPerZoneBoundary[0]);
 		break;
 
+	case SMU_OD_FAN_MODE:
+		if (!smu_v13_0_7_is_od_feature_supported(smu,
+							 PP_OD_FEATURE_FAN_CURVE_BIT))
+			break;
+
+		size += sysfs_emit_at(buf, size, "OD_FAN_MODE:\n");
+		size += sysfs_emit_at(buf, size, "%d\n",
+					(int)od_table->OverDriveTable.FanMode);
+		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) &&
@@ -1770,6 +1785,15 @@ static ssize_t smu_v13_0_7_get_gpu_metrics(struct smu_context *smu,
 	return sizeof(struct gpu_metrics_v1_3);
 }
 
+static void smu_v13_0_7_set_supported_od_feature_mask(struct smu_context *smu)
+{
+	struct amdgpu_device *adev = smu->adev;
+
+	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_MODE_RETRIEVE;
+}
+
 static int smu_v13_0_7_set_default_od_settings(struct smu_context *smu)
 {
 	OverDriveTableExternal_t *od_table =
@@ -1819,8 +1843,12 @@ static int smu_v13_0_7_set_default_od_settings(struct smu_context *smu)
 		for (i = 0; i < PP_NUM_OD_VF_CURVE_POINTS; i++)
 			user_od_table->OverDriveTable.VoltageOffsetPerZoneBoundary[i] =
 				user_od_table_bak.OverDriveTable.VoltageOffsetPerZoneBoundary[i];
+		user_od_table->OverDriveTable.FanMode =
+			user_od_table_bak.OverDriveTable.FanMode;
 	}
 
+	smu_v13_0_7_set_supported_od_feature_mask(smu);
+
 	return 0;
 }
 
@@ -1831,9 +1859,10 @@ static int smu_v13_0_7_restore_user_od_settings(struct smu_context *smu)
 	OverDriveTableExternal_t *user_od_table = table_context->user_overdrive_table;
 	int res;
 
-	user_od_table->OverDriveTable.FeatureCtrlMask = 1U << PP_OD_FEATURE_GFXCLK_BIT |
-							1U << PP_OD_FEATURE_UCLK_BIT |
-							1U << PP_OD_FEATURE_GFX_VF_CURVE_BIT;
+	user_od_table->OverDriveTable.FeatureCtrlMask = BIT(PP_OD_FEATURE_GFXCLK_BIT) |
+							BIT(PP_OD_FEATURE_UCLK_BIT) |
+							BIT(PP_OD_FEATURE_GFX_VF_CURVE_BIT) |
+							BIT(PP_OD_FEATURE_FAN_CURVE_BIT);
 	res = smu_v13_0_7_upload_overdrive_table(smu, user_od_table);
 	user_od_table->OverDriveTable.FeatureCtrlMask = 0;
 	if (res == 0)
Signature · 1 line
2.34.1
#3 lore raw

Re: [V2 3/8] drm/amd/pm: add fan mode OD setting support for SMU13

Quoted 195 lines · Evan Quan

Add SMU13 fan mode OD setting support.

--
v1->v2:
- add missing kerneldoc for the new interface(Alex)

---
 Documentation/gpu/amdgpu/thermal.rst          |   6 +
 .../gpu/drm/amd/include/kgd_pp_interface.h    |   4 +-
 drivers/gpu/drm/amd/pm/amdgpu_pm.c            | 200 +++++++++++++++++-
 drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h       |   4 +
 drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c     |   2 +
 drivers/gpu/drm/amd/pm/swsmu/inc/smu_types.h  |   1 +
 .../drm/amd/pm/swsmu/smu13/smu_v13_0_0_ppt.c  |  35 ++-
 .../drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c  |  35 ++-
 8 files changed, 279 insertions(+), 8 deletions(-)
Documentation/gpu/amdgpu/thermal.rst +6 -0
index 5e27e4eb3959..8757ec7f0136 100644
@@ -64,6 +64,12 @@ gpu_metrics
 .. kernel-doc:: drivers/gpu/drm/amd/pm/amdgpu_pm.c
    :doc: gpu_metrics
 
+fan_mode
+--------
+
+.. kernel-doc:: drivers/gpu/drm/amd/pm/amdgpu_pm.c
+   :doc: fan_mode
+
 GFXOFF
 ======
 
drivers/gpu/drm/amd/include/kgd_pp_interface.h +3 -1
index 84c5224d994c..020c9ce1f735 100644
@@ -113,6 +113,7 @@ enum pp_clock_type {
        OD_RANGE,
        OD_VDDGFX_OFFSET,
        OD_CCLK,
+       OD_FAN_MODE,
 };
 
 enum amd_pp_sensors {
@@ -186,7 +187,8 @@ enum PP_OD_DPM_TABLE_COMMAND {
        PP_OD_EDIT_VDDC_CURVE,
        PP_OD_RESTORE_DEFAULT_TABLE,
        PP_OD_COMMIT_DPM_TABLE,
-       PP_OD_EDIT_VDDGFX_OFFSET
+       PP_OD_EDIT_VDDGFX_OFFSET,
+       PP_OD_EDIT_FAN_MODE,
 };
 
 struct pp_states_info {
drivers/gpu/drm/amd/pm/amdgpu_pm.c +129 -1
index beb3303fc832..d53d60903fe9 100644
@@ -3383,7 +3383,205 @@ static const struct attribute_group *hwmon_groups[] = {
        NULL
 };
 
-static struct od_feature_set amdgpu_od_set;
+static int amdgpu_retrieve_od_settings(struct amdgpu_device *adev,
+                                      enum pp_clock_type od_type,
+                                      char *buf)
+{
+       int size = 0;
+       int ret;
+
+       if (amdgpu_in_reset(adev))
+               return -EPERM;
+       if (adev->in_suspend && !adev->in_runpm)
+               return -EPERM;
+
+       ret = pm_runtime_get_sync(adev->dev);
+       if (ret < 0) {
+               pm_runtime_put_autosuspend(adev->dev);
+               return ret;
+       }
+
+       size = amdgpu_dpm_print_clock_levels(adev, od_type, buf);
+       if (size == 0)
+               size = sysfs_emit(buf, "\n");
+
+       pm_runtime_mark_last_busy(adev->dev);
+       pm_runtime_put_autosuspend(adev->dev);
+
+       return size;
+}
+
+static int parse_input_od_command_lines(const char *buf,
+                                       size_t count,
+                                       u32 *type,
+                                       long *params,
+                                       uint32_t *num_of_params)
+{
+       const char delimiter[3] = {' ', '\n', '\0'};
+       uint32_t parameter_size = 0;
+       char buf_cpy[128] = {0};
+       char *tmp_str, *sub_str;
+       int ret;
+
+       if (count > sizeof(buf_cpy) - 1)
+               return -EINVAL;
+
+       memcpy(buf_cpy, buf, count);
+       tmp_str = buf_cpy;
+
+       /* skip heading spaces */
+       while (isspace(*tmp_str))
+               tmp_str++;
+
+       switch (*tmp_str) {
+       case 'c':
+               *type = PP_OD_COMMIT_DPM_TABLE;
+               return 0;
+       default:
+               break;
+       }
+
+       while ((sub_str = strsep(&tmp_str, delimiter)) != NULL) {
+               if (strlen(sub_str) == 0)
+                       continue;
+
+               ret = kstrtol(sub_str, 0, &params[parameter_size]);
+               if (ret)
+                       return -EINVAL;
+               parameter_size++;
+
+               while (isspace(*tmp_str))
+                       tmp_str++;
+       }
+
+       *num_of_params = parameter_size;
+
+       return 0;
+}
+
+static int
+amdgpu_distribute_custom_od_settings(struct amdgpu_device *adev,
+                                    enum PP_OD_DPM_TABLE_COMMAND cmd_type,
+                                    const char *in_buf,
+                                    size_t count)
+{
+       uint32_t parameter_size = 0;
+       long parameter[64];
+       int ret;
+
+       if (amdgpu_in_reset(adev))
+               return -EPERM;
+       if (adev->in_suspend && !adev->in_runpm)
+               return -EPERM;
+
+       ret = parse_input_od_command_lines(in_buf,
+                                          count,
+                                          &cmd_type,
+                                          parameter,
+                                          &parameter_size);
+       if (ret)
+               return ret;
+
+       ret = pm_runtime_get_sync(adev->dev);
+       if (ret < 0)
+               goto err_out0;
+
+       ret = amdgpu_dpm_odn_edit_dpm_table(adev,
+                                           cmd_type,
+                                           parameter,
+                                           parameter_size);
+       if (ret)
+               goto err_out1;
+
+       if (cmd_type == PP_OD_COMMIT_DPM_TABLE) {
+               ret = amdgpu_dpm_dispatch_task(adev,
+                                              AMD_PP_TASK_READJUST_POWER_STATE,
+                                              NULL);
+               if (ret)
+                       goto err_out1;
+       }
+
+       pm_runtime_mark_last_busy(adev->dev);
+       pm_runtime_put_autosuspend(adev->dev);
+
+       return count;
+
+err_out1:
+       pm_runtime_mark_last_busy(adev->dev);
+err_out0:
+       pm_runtime_put_autosuspend(adev->dev);
+
+       return ret;

drivers/gpu/drm/amd/pm/amdgpu_pm.c static const struct attribute_group *hwmon_groups[] = { · line 3524

Quoted 10 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +10 -0
+}
+
+/**
+ * DOC: fan_mode
+ *
+ * The amdgpu driver provides a sysfs API for checking and adjusting the fan
+ * control mode.
+ *
+ * Reading back the file shows you current fan control mode (e.g. '0' for auto
+ * mode and '1' for manual mode) and permitted settings if changable.

typo: changeable

Also what does manual vs auto mean in this case? Is the idea that you need to switch to manual mode before you make any other adjustments (fan curve or acoustic) or is this some independent setting?

Alex

Quoted 279 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +60 -0
+ *
+ * Writing an integer to the file, sets the fan control mode correspondingly.
+ *
+ * When you have finished the editing, write "c" (commit) to the file to commit
+ * your changes.
+ */
+static ssize_t fan_mode_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_FAN_MODE, buf);
+}
+
+static ssize_t fan_mode_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_FAN_MODE,
+                                                            buf,
+                                                            count);
+}
+
+static umode_t fan_mode_visible(struct amdgpu_device *adev)
+{
+       umode_t umode = 0000;
+
+       if (adev->pm.od_feature_mask & OD_OPS_SUPPORT_FAN_MODE_RETRIEVE)
+               umode |= S_IRUSR | S_IRGRP | S_IROTH;
+
+       if (adev->pm.od_feature_mask & OD_OPS_SUPPORT_FAN_MODE_SET)
+               umode |= S_IWUSR;
+
+       return umode;
+}
+
+static struct od_feature_set amdgpu_od_set = {
+       .containers = {
+               [0] = {
+                       .name = "fan_ctrl",
+                       .sub_feature = {
+                               [0] = {
+                                       .name = "fan_mode",
+                                       .ops = {
+                                               .is_visible = fan_mode_visible,
+                                               .show = fan_mode_show,
+                                               .store = fan_mode_store,
+                                       },
+                               },
+                       },
+               },
+       },
+};
 
 static void od_kobj_release(struct kobject *kobj)
 {
drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h +4 -0
index 4cab6a2efb63..b54f84e2408a 100644
@@ -314,6 +314,9 @@ struct config_table_setting
        uint16_t fclk_average_tau;
 };
 
+#define OD_OPS_SUPPORT_FAN_MODE_RETRIEVE               BIT(0)
+#define OD_OPS_SUPPORT_FAN_MODE_SET                    BIT(1)
+
 struct amdgpu_pm {
        struct mutex            mutex;
        u32                     current_sclk;
@@ -368,6 +371,7 @@ struct amdgpu_pm {
        enum amdgpu_runpm_mode rpm_mode;
 
        struct list_head        od_kobj_list;
+       uint32_t                od_feature_mask;
 };
 
 int amdgpu_dpm_read_sensor(struct amdgpu_device *adev, enum amd_pp_sensors sensor,
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +2 -0
index f005a90c35af..01ccfd219d6b 100644
@@ -2481,6 +2481,8 @@ static enum smu_clk_type smu_convert_to_smuclk(enum pp_clock_type type)
                clk_type = SMU_OD_VDDGFX_OFFSET; break;
        case OD_CCLK:
                clk_type = SMU_OD_CCLK; break;
+       case OD_FAN_MODE:
+               clk_type = SMU_OD_FAN_MODE; break;
        default:
                clk_type = SMU_CLK_COUNT; break;
        }
drivers/gpu/drm/amd/pm/swsmu/inc/smu_types.h +1 -0
index e57265cf637c..498000850212 100644
@@ -280,6 +280,7 @@ enum smu_clk_type {
        SMU_OD_VDDC_CURVE,
        SMU_OD_RANGE,
        SMU_OD_VDDGFX_OFFSET,
+       SMU_OD_FAN_MODE,
        SMU_CLK_COUNT,
 };
 
drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_0_ppt.c +32 -3
index 1041ba22f8f8..45b42e43f9a3 100644
@@ -101,6 +101,7 @@
 #define PP_OD_FEATURE_UCLK_FMIN                                2
 #define PP_OD_FEATURE_UCLK_FMAX                                3
 #define PP_OD_FEATURE_GFX_VF_CURVE                     4
+#define PP_OD_FEATURE_FAN_MODE                         5
 
 #define LINK_SPEED_MAX                                 3
 
@@ -1110,6 +1111,10 @@ static void smu_v13_0_0_get_od_setting_limits(struct smu_context *smu,
                od_min_setting = overdrive_lowerlimits->VoltageOffsetPerZoneBoundary;
                od_max_setting = overdrive_upperlimits->VoltageOffsetPerZoneBoundary;
                break;
+       case PP_OD_FEATURE_FAN_MODE:
+               od_min_setting = overdrive_lowerlimits->FanMode;
+               od_max_setting = overdrive_upperlimits->FanMode;
+               break;
        default:
                od_min_setting = od_max_setting = INT_MAX;
                break;
@@ -1329,6 +1334,16 @@ static int smu_v13_0_0_print_clk_levels(struct smu_context *smu,
                                      od_table->OverDriveTable.VoltageOffsetPerZoneBoundary[0]);
                break;
 
+       case SMU_OD_FAN_MODE:
+               if (!smu_v13_0_0_is_od_feature_supported(smu,
+                                                        PP_OD_FEATURE_FAN_CURVE_BIT))
+                       break;
+
+               size += sysfs_emit_at(buf, size, "OD_FAN_MODE:\n");
+               size += sysfs_emit_at(buf, size, "%d\n",
+                                       (int)od_table->OverDriveTable.FanMode);
+               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) &&
@@ -1789,6 +1804,15 @@ static ssize_t smu_v13_0_0_get_gpu_metrics(struct smu_context *smu,
        return sizeof(struct gpu_metrics_v1_3);
 }
 
+static void smu_v13_0_0_set_supported_od_feature_mask(struct smu_context *smu)
+{
+       struct amdgpu_device *adev = smu->adev;
+
+       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_MODE_RETRIEVE;
+}
+
 static int smu_v13_0_0_set_default_od_settings(struct smu_context *smu)
 {
        OverDriveTableExternal_t *od_table =
@@ -1838,8 +1862,12 @@ static int smu_v13_0_0_set_default_od_settings(struct smu_context *smu)
                for (i = 0; i < PP_NUM_OD_VF_CURVE_POINTS; i++)
                        user_od_table->OverDriveTable.VoltageOffsetPerZoneBoundary[i] =
                                user_od_table_bak.OverDriveTable.VoltageOffsetPerZoneBoundary[i];
+               user_od_table->OverDriveTable.FanMode =
+                       user_od_table_bak.OverDriveTable.FanMode;
        }
 
+       smu_v13_0_0_set_supported_od_feature_mask(smu);
+
        return 0;
 }
 
@@ -1850,9 +1878,10 @@ static int smu_v13_0_0_restore_user_od_settings(struct smu_context *smu)
        OverDriveTableExternal_t *user_od_table = table_context->user_overdrive_table;
        int res;
 
-       user_od_table->OverDriveTable.FeatureCtrlMask = 1U << PP_OD_FEATURE_GFXCLK_BIT |
-                                                       1U << PP_OD_FEATURE_UCLK_BIT |
-                                                       1U << PP_OD_FEATURE_GFX_VF_CURVE_BIT;
+       user_od_table->OverDriveTable.FeatureCtrlMask = BIT(PP_OD_FEATURE_GFXCLK_BIT) |
+                                                       BIT(PP_OD_FEATURE_UCLK_BIT) |
+                                                       BIT(PP_OD_FEATURE_GFX_VF_CURVE_BIT) |
+                                                       BIT(PP_OD_FEATURE_FAN_CURVE_BIT);
        res = smu_v13_0_0_upload_overdrive_table(smu, user_od_table);
        user_od_table->OverDriveTable.FeatureCtrlMask = 0;
        if (res == 0)
drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c +32 -4
index 328765f89c94..28c2e4b0e55d 100644
@@ -77,6 +77,7 @@
 #define PP_OD_FEATURE_UCLK_FMIN                                2
 #define PP_OD_FEATURE_UCLK_FMAX                                3
 #define PP_OD_FEATURE_GFX_VF_CURVE                     4
+#define PP_OD_FEATURE_FAN_MODE                         5
 
 #define LINK_SPEED_MAX                                 3
 
@@ -1096,6 +1097,10 @@ static void smu_v13_0_7_get_od_setting_limits(struct smu_context *smu,
                od_min_setting = overdrive_lowerlimits->VoltageOffsetPerZoneBoundary;
                od_max_setting = overdrive_upperlimits->VoltageOffsetPerZoneBoundary;
                break;
+       case PP_OD_FEATURE_FAN_MODE:
+               od_min_setting = overdrive_lowerlimits->FanMode;
+               od_max_setting = overdrive_upperlimits->FanMode;
+               break;
        default:
                od_min_setting = od_max_setting = INT_MAX;
                break;
@@ -1315,6 +1320,16 @@ static int smu_v13_0_7_print_clk_levels(struct smu_context *smu,
                                      od_table->OverDriveTable.VoltageOffsetPerZoneBoundary[0]);
                break;
 
+       case SMU_OD_FAN_MODE:
+               if (!smu_v13_0_7_is_od_feature_supported(smu,
+                                                        PP_OD_FEATURE_FAN_CURVE_BIT))
+                       break;
+
+               size += sysfs_emit_at(buf, size, "OD_FAN_MODE:\n");
+               size += sysfs_emit_at(buf, size, "%d\n",
+                                       (int)od_table->OverDriveTable.FanMode);
+               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) &&
@@ -1770,6 +1785,15 @@ static ssize_t smu_v13_0_7_get_gpu_metrics(struct smu_context *smu,
        return sizeof(struct gpu_metrics_v1_3);
 }
 
+static void smu_v13_0_7_set_supported_od_feature_mask(struct smu_context *smu)
+{
+       struct amdgpu_device *adev = smu->adev;
+
+       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_MODE_RETRIEVE;
+}
+
 static int smu_v13_0_7_set_default_od_settings(struct smu_context *smu)
 {
        OverDriveTableExternal_t *od_table =
@@ -1819,8 +1843,12 @@ static int smu_v13_0_7_set_default_od_settings(struct smu_context *smu)
                for (i = 0; i < PP_NUM_OD_VF_CURVE_POINTS; i++)
                        user_od_table->OverDriveTable.VoltageOffsetPerZoneBoundary[i] =
                                user_od_table_bak.OverDriveTable.VoltageOffsetPerZoneBoundary[i];
+               user_od_table->OverDriveTable.FanMode =
+                       user_od_table_bak.OverDriveTable.FanMode;
        }
 
+       smu_v13_0_7_set_supported_od_feature_mask(smu);
+
        return 0;
 }
 
@@ -1831,9 +1859,10 @@ static int smu_v13_0_7_restore_user_od_settings(struct smu_context *smu)
        OverDriveTableExternal_t *user_od_table = table_context->user_overdrive_table;
        int res;
 
-       user_od_table->OverDriveTable.FeatureCtrlMask = 1U << PP_OD_FEATURE_GFXCLK_BIT |
-                                                       1U << PP_OD_FEATURE_UCLK_BIT |
-                                                       1U << PP_OD_FEATURE_GFX_VF_CURVE_BIT;
+       user_od_table->OverDriveTable.FeatureCtrlMask = BIT(PP_OD_FEATURE_GFXCLK_BIT) |
+                                                       BIT(PP_OD_FEATURE_UCLK_BIT) |
+                                                       BIT(PP_OD_FEATURE_GFX_VF_CURVE_BIT) |
+                                                       BIT(PP_OD_FEATURE_FAN_CURVE_BIT);
        res = smu_v13_0_7_upload_overdrive_table(smu, user_od_table);
        user_od_table->OverDriveTable.FeatureCtrlMask = 0;
        if (res == 0)
--

2.34.1

author
#4 lore raw

RE: [V2 3/8] drm/amd/pm: add fan mode OD setting support for SMU13

[AMD Official Use Only - General]

Quoted 223 lines

-----Original Message-----
From: Alex Deucher <[email protected]>
Sent: Wednesday, August 23, 2023 9:29 PM
To: Quan, Evan <[email protected]>
Cc: [email protected]; Deucher, Alexander <[email protected]>
Subject: Re: [V2 3/8] drm/amd/pm: add fan mode OD setting support for SMU13

Quoted 11 lines · Evan Quan

Add SMU13 fan mode OD setting support.

--
v1->v2:
- add missing kerneldoc for the new interface(Alex)

---
 Documentation/gpu/amdgpu/thermal.rst          |   6 +
 .../gpu/drm/amd/include/kgd_pp_interface.h    |   4 +-
 drivers/gpu/drm/amd/pm/amdgpu_pm.c            | 200

+++++++++++++++++-

drivers/gpu/drm/amd/pm/amdgpu_pm.c static const struct attribute_group

Quoted 54 lines
 drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h       |   4 +
 drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c     |   2 +
 drivers/gpu/drm/amd/pm/swsmu/inc/smu_types.h  |   1 +
 .../drm/amd/pm/swsmu/smu13/smu_v13_0_0_ppt.c  |  35 ++-
.../drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c  |  35 ++-
 8 files changed, 279 insertions(+), 8 deletions(-)
Documentation/gpu/amdgpu/thermal.rst +6 -0
index 5e27e4eb3959..8757ec7f0136 100644
@@ -64,6 +64,12 @@ gpu_metrics
 .. kernel-doc:: drivers/gpu/drm/amd/pm/amdgpu_pm.c
    :doc: gpu_metrics
 
+fan_mode
+--------
+
+.. kernel-doc:: drivers/gpu/drm/amd/pm/amdgpu_pm.c
+   :doc: fan_mode
+
 GFXOFF
 ======
 
drivers/gpu/drm/amd/include/kgd_pp_interface.h +3 -1
index 84c5224d994c..020c9ce1f735 100644
@@ -113,6 +113,7 @@ enum pp_clock_type {
        OD_RANGE,
        OD_VDDGFX_OFFSET,
        OD_CCLK,
+       OD_FAN_MODE,
 };
 
 enum amd_pp_sensors {
@@ -186,7 +187,8 @@ enum PP_OD_DPM_TABLE_COMMAND {
        PP_OD_EDIT_VDDC_CURVE,
        PP_OD_RESTORE_DEFAULT_TABLE,
        PP_OD_COMMIT_DPM_TABLE,
-       PP_OD_EDIT_VDDGFX_OFFSET
+       PP_OD_EDIT_VDDGFX_OFFSET,
+       PP_OD_EDIT_FAN_MODE,
 };
 
 struct pp_states_info {
drivers/gpu/drm/amd/pm/amdgpu_pm.c +0 -0
index beb3303fc832..d53d60903fe9 100644
@@ -3383,7 +3383,205 @@ static const struct attribute_group

*hwmon_groups[] = {

Quoted 132 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +128 -1
        NULL
 };
 
-static struct od_feature_set amdgpu_od_set;
+static int amdgpu_retrieve_od_settings(struct amdgpu_device *adev,
+                                      enum pp_clock_type od_type,
+                                      char *buf) {
+       int size = 0;
+       int ret;
+
+       if (amdgpu_in_reset(adev))
+               return -EPERM;
+       if (adev->in_suspend && !adev->in_runpm)
+               return -EPERM;
+
+       ret = pm_runtime_get_sync(adev->dev);
+       if (ret < 0) {
+               pm_runtime_put_autosuspend(adev->dev);
+               return ret;
+       }
+
+       size = amdgpu_dpm_print_clock_levels(adev, od_type, buf);
+       if (size == 0)
+               size = sysfs_emit(buf, "\n");
+
+       pm_runtime_mark_last_busy(adev->dev);
+       pm_runtime_put_autosuspend(adev->dev);
+
+       return size;
+}
+
+static int parse_input_od_command_lines(const char *buf,
+                                       size_t count,
+                                       u32 *type,
+                                       long *params,
+                                       uint32_t *num_of_params) {
+       const char delimiter[3] = {' ', '\n', '\0'};
+       uint32_t parameter_size = 0;
+       char buf_cpy[128] = {0};
+       char *tmp_str, *sub_str;
+       int ret;
+
+       if (count > sizeof(buf_cpy) - 1)
+               return -EINVAL;
+
+       memcpy(buf_cpy, buf, count);
+       tmp_str = buf_cpy;
+
+       /* skip heading spaces */
+       while (isspace(*tmp_str))
+               tmp_str++;
+
+       switch (*tmp_str) {
+       case 'c':
+               *type = PP_OD_COMMIT_DPM_TABLE;
+               return 0;
+       default:
+               break;
+       }
+
+       while ((sub_str = strsep(&tmp_str, delimiter)) != NULL) {
+               if (strlen(sub_str) == 0)
+                       continue;
+
+               ret = kstrtol(sub_str, 0, &params[parameter_size]);
+               if (ret)
+                       return -EINVAL;
+               parameter_size++;
+
+               while (isspace(*tmp_str))
+                       tmp_str++;
+       }
+
+       *num_of_params = parameter_size;
+
+       return 0;
+}
+
+static int
+amdgpu_distribute_custom_od_settings(struct amdgpu_device *adev,
+                                    enum PP_OD_DPM_TABLE_COMMAND cmd_type,
+                                    const char *in_buf,
+                                    size_t count) {
+       uint32_t parameter_size = 0;
+       long parameter[64];
+       int ret;
+
+       if (amdgpu_in_reset(adev))
+               return -EPERM;
+       if (adev->in_suspend && !adev->in_runpm)
+               return -EPERM;
+
+       ret = parse_input_od_command_lines(in_buf,
+                                          count,
+                                          &cmd_type,
+                                          parameter,
+                                          &parameter_size);
+       if (ret)
+               return ret;
+
+       ret = pm_runtime_get_sync(adev->dev);
+       if (ret < 0)
+               goto err_out0;
+
+       ret = amdgpu_dpm_odn_edit_dpm_table(adev,
+                                           cmd_type,
+                                           parameter,
+                                           parameter_size);
+       if (ret)
+               goto err_out1;
+
+       if (cmd_type == PP_OD_COMMIT_DPM_TABLE) {
+               ret = amdgpu_dpm_dispatch_task(adev,
+                                              AMD_PP_TASK_READJUST_POWER_STATE,
+                                              NULL);
+               if (ret)
+                       goto err_out1;
+       }
+
+       pm_runtime_mark_last_busy(adev->dev);
+       pm_runtime_put_autosuspend(adev->dev);
+
+       return count;
+
+err_out1:
+       pm_runtime_mark_last_busy(adev->dev);
+err_out0:
+       pm_runtime_put_autosuspend(adev->dev);
+
+       return ret;
+}
+

drivers/gpu/drm/amd/pm/amdgpu_pm.c static const struct attribute_group *hwmon_groups[] = { · line 3524

Quoted 10 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +10 -0
+/**
+ * DOC: fan_mode
+ *
+ * The amdgpu driver provides a sysfs API for checking and adjusting
+the fan
+ * control mode.
+ *
+ * Reading back the file shows you current fan control mode (e.g. '0'
+for auto
+ * mode and '1' for manual mode) and permitted settings if changable.

typo: changeable

Quoted 3 lines

Also what does manual vs auto mean in this case? Is the idea that you need to switch to manual mode before you make any other adjustments (fan curve or acoustic) or is this some independent setting?

Auto mode here means PMFW handling the fan speed control in response to the asic temperature. While driver/user can do some fine tuning like acoustic limit/target, fan target-temperature and minimum pwm. Manual mode here means the fan curve setting specifically. Driver/user can customize how the fan speed in response to the asic temperature.
The two modes are mutually exclusive. Switching to one mode will invalid all those settings installed for the other mode.
Per current implementation for SMU13.0.0 and 13.0.7, user does not need to adjust the fan mode manually. Driver will handle that. For example, on user's setting of fan curve, driver will handle the fan mode switching to manual mode.

Please check whether the explanations above make sense to you. I can add them in the code comment part.

Evan

Quoted 314 lines

Alex

Quoted 24 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +24 -0
+ *
+ * Writing an integer to the file, sets the fan control mode correspondingly.
+ *
+ * When you have finished the editing, write "c" (commit) to the file
+to commit
+ * your changes.
+ */
+static ssize_t fan_mode_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_FAN_MODE,
+buf); }
+
+static ssize_t fan_mode_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;

drivers/gpu/drm/amd/pm/amdgpu_pm.c static const struct attribute_group *hwmon_groups[] = {

Quoted 10 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +10 -0
+
+       return (ssize_t)amdgpu_distribute_custom_od_settings(adev,
+                                                            PP_OD_EDIT_FAN_MODE,
+                                                            buf,
+                                                            count); }
+
+static umode_t fan_mode_visible(struct amdgpu_device *adev) {
+       umode_t umode = 0000;
+
+       if (adev->pm.od_feature_mask &

OD_OPS_SUPPORT_FAN_MODE_RETRIEVE)

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c static enum smu_clk_type

Quoted 57 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +25 -0
+               umode |= S_IRUSR | S_IRGRP | S_IROTH;
+
+       if (adev->pm.od_feature_mask & OD_OPS_SUPPORT_FAN_MODE_SET)
+               umode |= S_IWUSR;
+
+       return umode;
+}
+
+static struct od_feature_set amdgpu_od_set = {
+       .containers = {
+               [0] = {
+                       .name = "fan_ctrl",
+                       .sub_feature = {
+                               [0] = {
+                                       .name = "fan_mode",
+                                       .ops = {
+                                               .is_visible = fan_mode_visible,
+                                               .show = fan_mode_show,
+                                               .store = fan_mode_store,
+                                       },
+                               },
+                       },
+               },
+       },
+};
 
 static void od_kobj_release(struct kobject *kobj)  { diff --git

a/drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h
b/drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h
index 4cab6a2efb63..b54f84e2408a 100644

drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h +4 -0
@@ -314,6 +314,9 @@ struct config_table_setting
        uint16_t fclk_average_tau;
 };
 
+#define OD_OPS_SUPPORT_FAN_MODE_RETRIEVE               BIT(0)
+#define OD_OPS_SUPPORT_FAN_MODE_SET                    BIT(1)
+
 struct amdgpu_pm {
        struct mutex            mutex;
        u32                     current_sclk;
@@ -368,6 +371,7 @@ struct amdgpu_pm {
        enum amdgpu_runpm_mode rpm_mode;
 
        struct list_head        od_kobj_list;
+       uint32_t                od_feature_mask;
 };
 
 int amdgpu_dpm_read_sensor(struct amdgpu_device *adev, enum

amd_pp_sensors sensor, diff --git
a/drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c
b/drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c
index f005a90c35af..01ccfd219d6b 100644

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +0 -0
@@ -2481,6 +2481,8 @@ static enum smu_clk_type

smu_convert_to_smuclk(enum pp_clock_type type)

drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_0_ppt.c static void

Quoted 35 lines
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +2 -0
                clk_type = SMU_OD_VDDGFX_OFFSET; break;
        case OD_CCLK:
                clk_type = SMU_OD_CCLK; break;
+       case OD_FAN_MODE:
+               clk_type = SMU_OD_FAN_MODE; break;
        default:
                clk_type = SMU_CLK_COUNT; break;
        }
drivers/gpu/drm/amd/pm/swsmu/inc/smu_types.h +1 -0
index e57265cf637c..498000850212 100644
@@ -280,6 +280,7 @@ enum smu_clk_type {
        SMU_OD_VDDC_CURVE,
        SMU_OD_RANGE,
        SMU_OD_VDDGFX_OFFSET,
+       SMU_OD_FAN_MODE,
        SMU_CLK_COUNT,
 };
 
drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_0_ppt.c +1 -0
index 1041ba22f8f8..45b42e43f9a3 100644
@@ -101,6 +101,7 @@
 #define PP_OD_FEATURE_UCLK_FMIN                                2
 #define PP_OD_FEATURE_UCLK_FMAX                                3
 #define PP_OD_FEATURE_GFX_VF_CURVE                     4
+#define PP_OD_FEATURE_FAN_MODE                         5
 
 #define LINK_SPEED_MAX                                 3
 
@@ -1110,6 +1111,10 @@ static void

smu_v13_0_0_get_od_setting_limits(struct smu_context *smu,

drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_0_ppt.c static int smu_v13_0_0_print_clk_levels(struct

Quoted 13 lines
drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_0_ppt.c +4 -0
                od_min_setting = overdrive_lowerlimits-
 VoltageOffsetPerZoneBoundary;
                od_max_setting = overdrive_upperlimits-
 VoltageOffsetPerZoneBoundary;
                break;
+       case PP_OD_FEATURE_FAN_MODE:
+               od_min_setting = overdrive_lowerlimits->FanMode;
+               od_max_setting = overdrive_upperlimits->FanMode;
+               break;
        default:
                od_min_setting = od_max_setting = INT_MAX;
                break;
drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_0_ppt.c +0 -0
@@ -1329,6 +1334,16 @@ static int smu_v13_0_0_print_clk_levels(struct

smu_context *smu,

Quoted 6 lines
drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_0_ppt.c +2 -0
                                      od_table-
 OverDriveTable.VoltageOffsetPerZoneBoundary[0]);
                break;
 
+       case SMU_OD_FAN_MODE:
+               if (!smu_v13_0_0_is_od_feature_supported(smu,

drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_0_ppt.c static int smu_v13_0_0_print_clk_levels(struct smu_context *smu,

Quoted 10 lines
drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_0_ppt.c +8 -0
+                                                        PP_OD_FEATURE_FAN_CURVE_BIT))
+                       break;
+
+               size += sysfs_emit_at(buf, size, "OD_FAN_MODE:\n");
+               size += sysfs_emit_at(buf, size, "%d\n",
+                                       (int)od_table->OverDriveTable.FanMode);
+               break;
+
        case SMU_OD_RANGE:
                if (!smu_v13_0_0_is_od_feature_supported(smu,

PP_OD_FEATURE_GFXCLK_BIT) &&

Quoted 2 lines
                    !smu_v13_0_0_is_od_feature_supported(smu,

PP_OD_FEATURE_UCLK_BIT) && @@ -1789,6 +1804,15 @@ static ssize_t

smu_v13_0_0_get_gpu_metrics(struct smu_context *smu,

drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_0_ppt.c static int

Quoted 30 lines
        return sizeof(struct gpu_metrics_v1_3);  }
drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_0_ppt.c +9 -0
+static void smu_v13_0_0_set_supported_od_feature_mask(struct
+smu_context *smu) {
+       struct amdgpu_device *adev = smu->adev;
+
+       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_MODE_RETRIEVE; }
+
 static int smu_v13_0_0_set_default_od_settings(struct smu_context
*smu)  {
        OverDriveTableExternal_t *od_table = @@ -1838,8 +1862,12 @@
static int smu_v13_0_0_set_default_od_settings(struct smu_context *smu)
                for (i = 0; i < PP_NUM_OD_VF_CURVE_POINTS; i++)
                        user_od_table-

OverDriveTable.VoltageOffsetPerZoneBoundary[i] =

user_od_table_bak.OverDriveTable.VoltageOffsetPerZoneBoundary[i];

drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_0_ppt.c +4 -0
+               user_od_table->OverDriveTable.FanMode =
+                       user_od_table_bak.OverDriveTable.FanMode;
        }
 
+       smu_v13_0_0_set_supported_od_feature_mask(smu);
+
        return 0;
 }
@@ -1850,9 +1878,10 @@ static int

smu_v13_0_0_restore_user_od_settings(struct smu_context *smu)

drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_0_ppt.c static int · line 1854

Quoted 5 lines
drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_0_ppt.c +0 -1
        OverDriveTableExternal_t *user_od_table = table_context-
 user_overdrive_table;
        int res;
 
-       user_od_table->OverDriveTable.FeatureCtrlMask = 1U <<

PP_OD_FEATURE_GFXCLK_BIT |

drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_0_ppt.c static int smu_v13_0_0_restore_user_od_settings(struct smu_context *smu)

Quoted 3 lines
drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_0_ppt.c +1 -2
-                                                       1U << PP_OD_FEATURE_UCLK_BIT |
-                                                       1U << PP_OD_FEATURE_GFX_VF_CURVE_BIT;
+       user_od_table->OverDriveTable.FeatureCtrlMask =

BIT(PP_OD_FEATURE_GFXCLK_BIT) |

drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c static void

Quoted 21 lines
drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_0_ppt.c +4 -0
+                                                       BIT(PP_OD_FEATURE_UCLK_BIT) |
+                                                       BIT(PP_OD_FEATURE_GFX_VF_CURVE_BIT) |
+
+ BIT(PP_OD_FEATURE_FAN_CURVE_BIT);
        res = smu_v13_0_0_upload_overdrive_table(smu, user_od_table);
        user_od_table->OverDriveTable.FeatureCtrlMask = 0;
        if (res == 0)
drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c +1 -0
index 328765f89c94..28c2e4b0e55d 100644
@@ -77,6 +77,7 @@
 #define PP_OD_FEATURE_UCLK_FMIN                                2
 #define PP_OD_FEATURE_UCLK_FMAX                                3
 #define PP_OD_FEATURE_GFX_VF_CURVE                     4
+#define PP_OD_FEATURE_FAN_MODE                         5
 
 #define LINK_SPEED_MAX                                 3
 
@@ -1096,6 +1097,10 @@ static void

smu_v13_0_7_get_od_setting_limits(struct smu_context *smu,

drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c static int smu_v13_0_7_print_clk_levels(struct

Quoted 13 lines
drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c +4 -0
                od_min_setting = overdrive_lowerlimits-
 VoltageOffsetPerZoneBoundary;
                od_max_setting = overdrive_upperlimits-
 VoltageOffsetPerZoneBoundary;
                break;
+       case PP_OD_FEATURE_FAN_MODE:
+               od_min_setting = overdrive_lowerlimits->FanMode;
+               od_max_setting = overdrive_upperlimits->FanMode;
+               break;
        default:
                od_min_setting = od_max_setting = INT_MAX;
                break;
drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c +0 -0
@@ -1315,6 +1320,16 @@ static int smu_v13_0_7_print_clk_levels(struct

smu_context *smu,

Quoted 6 lines
drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c +2 -0
                                      od_table-
 OverDriveTable.VoltageOffsetPerZoneBoundary[0]);
                break;
 
+       case SMU_OD_FAN_MODE:
+               if (!smu_v13_0_7_is_od_feature_supported(smu,

drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c static int smu_v13_0_7_print_clk_levels(struct smu_context *smu,

Quoted 10 lines
drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c +8 -0
+                                                        PP_OD_FEATURE_FAN_CURVE_BIT))
+                       break;
+
+               size += sysfs_emit_at(buf, size, "OD_FAN_MODE:\n");
+               size += sysfs_emit_at(buf, size, "%d\n",
+                                       (int)od_table->OverDriveTable.FanMode);
+               break;
+
        case SMU_OD_RANGE:
                if (!smu_v13_0_7_is_od_feature_supported(smu,

PP_OD_FEATURE_GFXCLK_BIT) &&

Quoted 2 lines
                    !smu_v13_0_7_is_od_feature_supported(smu,

PP_OD_FEATURE_UCLK_BIT) && @@ -1770,6 +1785,15 @@ static ssize_t

smu_v13_0_7_get_gpu_metrics(struct smu_context *smu,

drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c static int

Quoted 30 lines
        return sizeof(struct gpu_metrics_v1_3);  }
drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c +9 -0
+static void smu_v13_0_7_set_supported_od_feature_mask(struct
+smu_context *smu) {
+       struct amdgpu_device *adev = smu->adev;
+
+       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_MODE_RETRIEVE; }
+
 static int smu_v13_0_7_set_default_od_settings(struct smu_context
*smu)  {
        OverDriveTableExternal_t *od_table = @@ -1819,8 +1843,12 @@
static int smu_v13_0_7_set_default_od_settings(struct smu_context *smu)
                for (i = 0; i < PP_NUM_OD_VF_CURVE_POINTS; i++)
                        user_od_table-

OverDriveTable.VoltageOffsetPerZoneBoundary[i] =

user_od_table_bak.OverDriveTable.VoltageOffsetPerZoneBoundary[i];

drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c +4 -0
+               user_od_table->OverDriveTable.FanMode =
+                       user_od_table_bak.OverDriveTable.FanMode;
        }
 
+       smu_v13_0_7_set_supported_od_feature_mask(smu);
+
        return 0;
 }
@@ -1831,9 +1859,10 @@ static int

smu_v13_0_7_restore_user_od_settings(struct smu_context *smu)

drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c static int · line 1835

Quoted 5 lines
drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c +0 -1
        OverDriveTableExternal_t *user_od_table = table_context-
 user_overdrive_table;
        int res;
 
-       user_od_table->OverDriveTable.FeatureCtrlMask = 1U <<

PP_OD_FEATURE_GFXCLK_BIT |

drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c static int · line 1863

Quoted 3 lines
drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c +1 -2
-                                                       1U << PP_OD_FEATURE_UCLK_BIT |
-                                                       1U << PP_OD_FEATURE_GFX_VF_CURVE_BIT;
+       user_od_table->OverDriveTable.FeatureCtrlMask =

BIT(PP_OD_FEATURE_GFXCLK_BIT) |

Quoted 10 lines
drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c +4 -1
+                                                       BIT(PP_OD_FEATURE_UCLK_BIT) |
+                                                       BIT(PP_OD_FEATURE_GFX_VF_CURVE_BIT) |
+
+ BIT(PP_OD_FEATURE_FAN_CURVE_BIT);
        res = smu_v13_0_7_upload_overdrive_table(smu, user_od_table);
        user_od_table->OverDriveTable.FeatureCtrlMask = 0;
        if (res == 0)
--

2.34.1

#5 lore raw

Re: [V2 3/8] drm/amd/pm: add fan mode OD setting support for SMU13

Quoted 226 lines · Evan

[AMD Official Use Only - General]

Quoted 223 lines

-----Original Message-----
From: Alex Deucher <[email protected]>
Sent: Wednesday, August 23, 2023 9:29 PM
To: Quan, Evan <[email protected]>
Cc: [email protected]; Deucher, Alexander <[email protected]>
Subject: Re: [V2 3/8] drm/amd/pm: add fan mode OD setting support for SMU13

Quoted 11 lines · Evan Quan

Add SMU13 fan mode OD setting support.

--
v1->v2:
- add missing kerneldoc for the new interface(Alex)

---
 Documentation/gpu/amdgpu/thermal.rst          |   6 +
 .../gpu/drm/amd/include/kgd_pp_interface.h    |   4 +-
 drivers/gpu/drm/amd/pm/amdgpu_pm.c            | 200

+++++++++++++++++-

drivers/gpu/drm/amd/pm/amdgpu_pm.c static const struct attribute_group

Quoted 54 lines
 drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h       |   4 +
 drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c     |   2 +
 drivers/gpu/drm/amd/pm/swsmu/inc/smu_types.h  |   1 +
 .../drm/amd/pm/swsmu/smu13/smu_v13_0_0_ppt.c  |  35 ++-
.../drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c  |  35 ++-
 8 files changed, 279 insertions(+), 8 deletions(-)
Documentation/gpu/amdgpu/thermal.rst +6 -0
index 5e27e4eb3959..8757ec7f0136 100644
@@ -64,6 +64,12 @@ gpu_metrics
 .. kernel-doc:: drivers/gpu/drm/amd/pm/amdgpu_pm.c
    :doc: gpu_metrics
 
+fan_mode
+--------
+
+.. kernel-doc:: drivers/gpu/drm/amd/pm/amdgpu_pm.c
+   :doc: fan_mode
+
 GFXOFF
 ======
 
drivers/gpu/drm/amd/include/kgd_pp_interface.h +3 -1
index 84c5224d994c..020c9ce1f735 100644
@@ -113,6 +113,7 @@ enum pp_clock_type {
        OD_RANGE,
        OD_VDDGFX_OFFSET,
        OD_CCLK,
+       OD_FAN_MODE,
 };
 
 enum amd_pp_sensors {
@@ -186,7 +187,8 @@ enum PP_OD_DPM_TABLE_COMMAND {
        PP_OD_EDIT_VDDC_CURVE,
        PP_OD_RESTORE_DEFAULT_TABLE,
        PP_OD_COMMIT_DPM_TABLE,
-       PP_OD_EDIT_VDDGFX_OFFSET
+       PP_OD_EDIT_VDDGFX_OFFSET,
+       PP_OD_EDIT_FAN_MODE,
 };
 
 struct pp_states_info {
drivers/gpu/drm/amd/pm/amdgpu_pm.c +0 -0
index beb3303fc832..d53d60903fe9 100644
@@ -3383,7 +3383,205 @@ static const struct attribute_group

*hwmon_groups[] = {

Quoted 132 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +128 -1
        NULL
 };
 
-static struct od_feature_set amdgpu_od_set;
+static int amdgpu_retrieve_od_settings(struct amdgpu_device *adev,
+                                      enum pp_clock_type od_type,
+                                      char *buf) {
+       int size = 0;
+       int ret;
+
+       if (amdgpu_in_reset(adev))
+               return -EPERM;
+       if (adev->in_suspend && !adev->in_runpm)
+               return -EPERM;
+
+       ret = pm_runtime_get_sync(adev->dev);
+       if (ret < 0) {
+               pm_runtime_put_autosuspend(adev->dev);
+               return ret;
+       }
+
+       size = amdgpu_dpm_print_clock_levels(adev, od_type, buf);
+       if (size == 0)
+               size = sysfs_emit(buf, "\n");
+
+       pm_runtime_mark_last_busy(adev->dev);
+       pm_runtime_put_autosuspend(adev->dev);
+
+       return size;
+}
+
+static int parse_input_od_command_lines(const char *buf,
+                                       size_t count,
+                                       u32 *type,
+                                       long *params,
+                                       uint32_t *num_of_params) {
+       const char delimiter[3] = {' ', '\n', '\0'};
+       uint32_t parameter_size = 0;
+       char buf_cpy[128] = {0};
+       char *tmp_str, *sub_str;
+       int ret;
+
+       if (count > sizeof(buf_cpy) - 1)
+               return -EINVAL;
+
+       memcpy(buf_cpy, buf, count);
+       tmp_str = buf_cpy;
+
+       /* skip heading spaces */
+       while (isspace(*tmp_str))
+               tmp_str++;
+
+       switch (*tmp_str) {
+       case 'c':
+               *type = PP_OD_COMMIT_DPM_TABLE;
+               return 0;
+       default:
+               break;
+       }
+
+       while ((sub_str = strsep(&tmp_str, delimiter)) != NULL) {
+               if (strlen(sub_str) == 0)
+                       continue;
+
+               ret = kstrtol(sub_str, 0, &params[parameter_size]);
+               if (ret)
+                       return -EINVAL;
+               parameter_size++;
+
+               while (isspace(*tmp_str))
+                       tmp_str++;
+       }
+
+       *num_of_params = parameter_size;
+
+       return 0;
+}
+
+static int
+amdgpu_distribute_custom_od_settings(struct amdgpu_device *adev,
+                                    enum PP_OD_DPM_TABLE_COMMAND cmd_type,
+                                    const char *in_buf,
+                                    size_t count) {
+       uint32_t parameter_size = 0;
+       long parameter[64];
+       int ret;
+
+       if (amdgpu_in_reset(adev))
+               return -EPERM;
+       if (adev->in_suspend && !adev->in_runpm)
+               return -EPERM;
+
+       ret = parse_input_od_command_lines(in_buf,
+                                          count,
+                                          &cmd_type,
+                                          parameter,
+                                          &parameter_size);
+       if (ret)
+               return ret;
+
+       ret = pm_runtime_get_sync(adev->dev);
+       if (ret < 0)
+               goto err_out0;
+
+       ret = amdgpu_dpm_odn_edit_dpm_table(adev,
+                                           cmd_type,
+                                           parameter,
+                                           parameter_size);
+       if (ret)
+               goto err_out1;
+
+       if (cmd_type == PP_OD_COMMIT_DPM_TABLE) {
+               ret = amdgpu_dpm_dispatch_task(adev,
+                                              AMD_PP_TASK_READJUST_POWER_STATE,
+                                              NULL);
+               if (ret)
+                       goto err_out1;
+       }
+
+       pm_runtime_mark_last_busy(adev->dev);
+       pm_runtime_put_autosuspend(adev->dev);
+
+       return count;
+
+err_out1:
+       pm_runtime_mark_last_busy(adev->dev);
+err_out0:
+       pm_runtime_put_autosuspend(adev->dev);
+
+       return ret;
+}
+

drivers/gpu/drm/amd/pm/amdgpu_pm.c static const struct attribute_group *hwmon_groups[] = { · line 3524

Quoted 10 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +10 -0
+/**
+ * DOC: fan_mode
+ *
+ * The amdgpu driver provides a sysfs API for checking and adjusting
+the fan
+ * control mode.
+ *
+ * Reading back the file shows you current fan control mode (e.g. '0'
+for auto
+ * mode and '1' for manual mode) and permitted settings if changable.

typo: changeable

Quoted 8 lines
Quoted 3 lines

Also what does manual vs auto mean in this case? Is the idea that you need to switch to manual mode before you make any other adjustments (fan curve or acoustic) or is this some independent setting?

Auto mode here means PMFW handling the fan speed control in response to the asic temperature. While driver/user can do some fine tuning like acoustic limit/target, fan target-temperature and minimum pwm. Manual mode here means the fan curve setting specifically. Driver/user can customize how the fan speed in response to the asic temperature.
The two modes are mutually exclusive. Switching to one mode will invalid all those settings installed for the other mode.
Per current implementation for SMU13.0.0 and 13.0.7, user does not need to adjust the fan mode manually. Driver will handle that. For example, on user's setting of fan curve, driver will handle the fan mode switching to manual mode.

If I understand things correctly, the driver will automatically set manual mode if the user adjusts the fan curve? If so, do we need a separate attribute for manual vs automatic? For the documentation, I'd like to see all of the fan options and what sets are required to enable them and what combinations are allowed.

1. temp/pwm fan curve - requires setting manual mode. Mutually exclusive with 2, 3.
2. acoustic targets - requires setting manual mode. Mutually exclusive with 1, 3.
3. temperature targets - requires setting manual mode. Mutually exclusive with 1, 2.
4. minimum fan speed - requires setting manual mode. works with 1,2,3.

If the first 3 are mutually exclusive, then maybe we need a fan mode attribute with the following options:
0. auto - let the SMU manage the fan
1. manual - temp/pwm curve
2. manual - acoustic targets
3. manual - temp targets

If they are not mutually exclusive, then how do they interact? E.g., what happens if you set a custom temp/pwm curve and acoustic targets and they are not compatible? Does that make sense?

Alex

Quoted 317 lines

Please check whether the explanations above make sense to you. I can add them in the code comment part.

Evan

Quoted 314 lines

Alex

Quoted 24 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +24 -0
+ *
+ * Writing an integer to the file, sets the fan control mode correspondingly.
+ *
+ * When you have finished the editing, write "c" (commit) to the file
+to commit
+ * your changes.
+ */
+static ssize_t fan_mode_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_FAN_MODE,
+buf); }
+
+static ssize_t fan_mode_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;

drivers/gpu/drm/amd/pm/amdgpu_pm.c static const struct attribute_group *hwmon_groups[] = {

Quoted 10 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +10 -0
+
+       return (ssize_t)amdgpu_distribute_custom_od_settings(adev,
+                                                            PP_OD_EDIT_FAN_MODE,
+                                                            buf,
+                                                            count); }
+
+static umode_t fan_mode_visible(struct amdgpu_device *adev) {
+       umode_t umode = 0000;
+
+       if (adev->pm.od_feature_mask &

OD_OPS_SUPPORT_FAN_MODE_RETRIEVE)

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c static enum smu_clk_type

Quoted 57 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +25 -0
+               umode |= S_IRUSR | S_IRGRP | S_IROTH;
+
+       if (adev->pm.od_feature_mask & OD_OPS_SUPPORT_FAN_MODE_SET)
+               umode |= S_IWUSR;
+
+       return umode;
+}
+
+static struct od_feature_set amdgpu_od_set = {
+       .containers = {
+               [0] = {
+                       .name = "fan_ctrl",
+                       .sub_feature = {
+                               [0] = {
+                                       .name = "fan_mode",
+                                       .ops = {
+                                               .is_visible = fan_mode_visible,
+                                               .show = fan_mode_show,
+                                               .store = fan_mode_store,
+                                       },
+                               },
+                       },
+               },
+       },
+};
 
 static void od_kobj_release(struct kobject *kobj)  { diff --git

a/drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h
b/drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h
index 4cab6a2efb63..b54f84e2408a 100644

drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h +4 -0
@@ -314,6 +314,9 @@ struct config_table_setting
        uint16_t fclk_average_tau;
 };
 
+#define OD_OPS_SUPPORT_FAN_MODE_RETRIEVE               BIT(0)
+#define OD_OPS_SUPPORT_FAN_MODE_SET                    BIT(1)
+
 struct amdgpu_pm {
        struct mutex            mutex;
        u32                     current_sclk;
@@ -368,6 +371,7 @@ struct amdgpu_pm {
        enum amdgpu_runpm_mode rpm_mode;
 
        struct list_head        od_kobj_list;
+       uint32_t                od_feature_mask;
 };
 
 int amdgpu_dpm_read_sensor(struct amdgpu_device *adev, enum

amd_pp_sensors sensor, diff --git
a/drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c
b/drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c
index f005a90c35af..01ccfd219d6b 100644

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +0 -0
@@ -2481,6 +2481,8 @@ static enum smu_clk_type

smu_convert_to_smuclk(enum pp_clock_type type)

drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_0_ppt.c static void

Quoted 35 lines
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +2 -0
                clk_type = SMU_OD_VDDGFX_OFFSET; break;
        case OD_CCLK:
                clk_type = SMU_OD_CCLK; break;
+       case OD_FAN_MODE:
+               clk_type = SMU_OD_FAN_MODE; break;
        default:
                clk_type = SMU_CLK_COUNT; break;
        }
drivers/gpu/drm/amd/pm/swsmu/inc/smu_types.h +1 -0
index e57265cf637c..498000850212 100644
@@ -280,6 +280,7 @@ enum smu_clk_type {
        SMU_OD_VDDC_CURVE,
        SMU_OD_RANGE,
        SMU_OD_VDDGFX_OFFSET,
+       SMU_OD_FAN_MODE,
        SMU_CLK_COUNT,
 };
 
drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_0_ppt.c +1 -0
index 1041ba22f8f8..45b42e43f9a3 100644
@@ -101,6 +101,7 @@
 #define PP_OD_FEATURE_UCLK_FMIN                                2
 #define PP_OD_FEATURE_UCLK_FMAX                                3
 #define PP_OD_FEATURE_GFX_VF_CURVE                     4
+#define PP_OD_FEATURE_FAN_MODE                         5
 
 #define LINK_SPEED_MAX                                 3
 
@@ -1110,6 +1111,10 @@ static void

smu_v13_0_0_get_od_setting_limits(struct smu_context *smu,

drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_0_ppt.c static int smu_v13_0_0_print_clk_levels(struct

Quoted 13 lines
drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_0_ppt.c +4 -0
                od_min_setting = overdrive_lowerlimits-
 VoltageOffsetPerZoneBoundary;
                od_max_setting = overdrive_upperlimits-
 VoltageOffsetPerZoneBoundary;
                break;
+       case PP_OD_FEATURE_FAN_MODE:
+               od_min_setting = overdrive_lowerlimits->FanMode;
+               od_max_setting = overdrive_upperlimits->FanMode;
+               break;
        default:
                od_min_setting = od_max_setting = INT_MAX;
                break;
drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_0_ppt.c +0 -0
@@ -1329,6 +1334,16 @@ static int smu_v13_0_0_print_clk_levels(struct

smu_context *smu,

Quoted 6 lines
drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_0_ppt.c +2 -0
                                      od_table-
 OverDriveTable.VoltageOffsetPerZoneBoundary[0]);
                break;
 
+       case SMU_OD_FAN_MODE:
+               if (!smu_v13_0_0_is_od_feature_supported(smu,

drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_0_ppt.c static int smu_v13_0_0_print_clk_levels(struct smu_context *smu,

Quoted 10 lines
drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_0_ppt.c +8 -0
+                                                        PP_OD_FEATURE_FAN_CURVE_BIT))
+                       break;
+
+               size += sysfs_emit_at(buf, size, "OD_FAN_MODE:\n");
+               size += sysfs_emit_at(buf, size, "%d\n",
+                                       (int)od_table->OverDriveTable.FanMode);
+               break;
+
        case SMU_OD_RANGE:
                if (!smu_v13_0_0_is_od_feature_supported(smu,

PP_OD_FEATURE_GFXCLK_BIT) &&

Quoted 2 lines
                    !smu_v13_0_0_is_od_feature_supported(smu,

PP_OD_FEATURE_UCLK_BIT) && @@ -1789,6 +1804,15 @@ static ssize_t

smu_v13_0_0_get_gpu_metrics(struct smu_context *smu,

drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_0_ppt.c static int

Quoted 30 lines
        return sizeof(struct gpu_metrics_v1_3);  }
drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_0_ppt.c +9 -0
+static void smu_v13_0_0_set_supported_od_feature_mask(struct
+smu_context *smu) {
+       struct amdgpu_device *adev = smu->adev;
+
+       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_MODE_RETRIEVE; }
+
 static int smu_v13_0_0_set_default_od_settings(struct smu_context
*smu)  {
        OverDriveTableExternal_t *od_table = @@ -1838,8 +1862,12 @@
static int smu_v13_0_0_set_default_od_settings(struct smu_context *smu)
                for (i = 0; i < PP_NUM_OD_VF_CURVE_POINTS; i++)
                        user_od_table-

OverDriveTable.VoltageOffsetPerZoneBoundary[i] =

user_od_table_bak.OverDriveTable.VoltageOffsetPerZoneBoundary[i];

drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_0_ppt.c +4 -0
+               user_od_table->OverDriveTable.FanMode =
+                       user_od_table_bak.OverDriveTable.FanMode;
        }
 
+       smu_v13_0_0_set_supported_od_feature_mask(smu);
+
        return 0;
 }
@@ -1850,9 +1878,10 @@ static int

smu_v13_0_0_restore_user_od_settings(struct smu_context *smu)

drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_0_ppt.c static int · line 1854

Quoted 5 lines
drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_0_ppt.c +0 -1
        OverDriveTableExternal_t *user_od_table = table_context-
 user_overdrive_table;
        int res;
 
-       user_od_table->OverDriveTable.FeatureCtrlMask = 1U <<

PP_OD_FEATURE_GFXCLK_BIT |

drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_0_ppt.c static int smu_v13_0_0_restore_user_od_settings(struct smu_context *smu)

Quoted 3 lines
drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_0_ppt.c +1 -2
-                                                       1U << PP_OD_FEATURE_UCLK_BIT |
-                                                       1U << PP_OD_FEATURE_GFX_VF_CURVE_BIT;
+       user_od_table->OverDriveTable.FeatureCtrlMask =

BIT(PP_OD_FEATURE_GFXCLK_BIT) |

drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c static void

Quoted 21 lines
drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_0_ppt.c +4 -0
+                                                       BIT(PP_OD_FEATURE_UCLK_BIT) |
+                                                       BIT(PP_OD_FEATURE_GFX_VF_CURVE_BIT) |
+
+ BIT(PP_OD_FEATURE_FAN_CURVE_BIT);
        res = smu_v13_0_0_upload_overdrive_table(smu, user_od_table);
        user_od_table->OverDriveTable.FeatureCtrlMask = 0;
        if (res == 0)
drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c +1 -0
index 328765f89c94..28c2e4b0e55d 100644
@@ -77,6 +77,7 @@
 #define PP_OD_FEATURE_UCLK_FMIN                                2
 #define PP_OD_FEATURE_UCLK_FMAX                                3
 #define PP_OD_FEATURE_GFX_VF_CURVE                     4
+#define PP_OD_FEATURE_FAN_MODE                         5
 
 #define LINK_SPEED_MAX                                 3
 
@@ -1096,6 +1097,10 @@ static void

smu_v13_0_7_get_od_setting_limits(struct smu_context *smu,

drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c static int smu_v13_0_7_print_clk_levels(struct

Quoted 13 lines
drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c +4 -0
                od_min_setting = overdrive_lowerlimits-
 VoltageOffsetPerZoneBoundary;
                od_max_setting = overdrive_upperlimits-
 VoltageOffsetPerZoneBoundary;
                break;
+       case PP_OD_FEATURE_FAN_MODE:
+               od_min_setting = overdrive_lowerlimits->FanMode;
+               od_max_setting = overdrive_upperlimits->FanMode;
+               break;
        default:
                od_min_setting = od_max_setting = INT_MAX;
                break;
drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c +0 -0
@@ -1315,6 +1320,16 @@ static int smu_v13_0_7_print_clk_levels(struct

smu_context *smu,

Quoted 6 lines
drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c +2 -0
                                      od_table-
 OverDriveTable.VoltageOffsetPerZoneBoundary[0]);
                break;
 
+       case SMU_OD_FAN_MODE:
+               if (!smu_v13_0_7_is_od_feature_supported(smu,

drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c static int smu_v13_0_7_print_clk_levels(struct smu_context *smu,

Quoted 10 lines
drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c +8 -0
+                                                        PP_OD_FEATURE_FAN_CURVE_BIT))
+                       break;
+
+               size += sysfs_emit_at(buf, size, "OD_FAN_MODE:\n");
+               size += sysfs_emit_at(buf, size, "%d\n",
+                                       (int)od_table->OverDriveTable.FanMode);
+               break;
+
        case SMU_OD_RANGE:
                if (!smu_v13_0_7_is_od_feature_supported(smu,

PP_OD_FEATURE_GFXCLK_BIT) &&

Quoted 2 lines
                    !smu_v13_0_7_is_od_feature_supported(smu,

PP_OD_FEATURE_UCLK_BIT) && @@ -1770,6 +1785,15 @@ static ssize_t

smu_v13_0_7_get_gpu_metrics(struct smu_context *smu,

drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c static int

Quoted 30 lines
        return sizeof(struct gpu_metrics_v1_3);  }
drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c +9 -0
+static void smu_v13_0_7_set_supported_od_feature_mask(struct
+smu_context *smu) {
+       struct amdgpu_device *adev = smu->adev;
+
+       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_MODE_RETRIEVE; }
+
 static int smu_v13_0_7_set_default_od_settings(struct smu_context
*smu)  {
        OverDriveTableExternal_t *od_table = @@ -1819,8 +1843,12 @@
static int smu_v13_0_7_set_default_od_settings(struct smu_context *smu)
                for (i = 0; i < PP_NUM_OD_VF_CURVE_POINTS; i++)
                        user_od_table-

OverDriveTable.VoltageOffsetPerZoneBoundary[i] =

user_od_table_bak.OverDriveTable.VoltageOffsetPerZoneBoundary[i];

drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c +4 -0
+               user_od_table->OverDriveTable.FanMode =
+                       user_od_table_bak.OverDriveTable.FanMode;
        }
 
+       smu_v13_0_7_set_supported_od_feature_mask(smu);
+
        return 0;
 }
@@ -1831,9 +1859,10 @@ static int

smu_v13_0_7_restore_user_od_settings(struct smu_context *smu)

drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c static int · line 1835

Quoted 5 lines
drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c +0 -1
        OverDriveTableExternal_t *user_od_table = table_context-
 user_overdrive_table;
        int res;
 
-       user_od_table->OverDriveTable.FeatureCtrlMask = 1U <<

PP_OD_FEATURE_GFXCLK_BIT |

drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c static int · line 1863

Quoted 3 lines
drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c +1 -2
-                                                       1U << PP_OD_FEATURE_UCLK_BIT |
-                                                       1U << PP_OD_FEATURE_GFX_VF_CURVE_BIT;
+       user_od_table->OverDriveTable.FeatureCtrlMask =

BIT(PP_OD_FEATURE_GFXCLK_BIT) |

Quoted 10 lines
drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c +4 -1
+                                                       BIT(PP_OD_FEATURE_UCLK_BIT) |
+                                                       BIT(PP_OD_FEATURE_GFX_VF_CURVE_BIT) |
+
+ BIT(PP_OD_FEATURE_FAN_CURVE_BIT);
        res = smu_v13_0_7_upload_overdrive_table(smu, user_od_table);
        user_od_table->OverDriveTable.FeatureCtrlMask = 0;
        if (res == 0)
--

2.34.1

author
#6 lore raw

RE: [V2 3/8] drm/amd/pm: add fan mode OD setting support for SMU13

[AMD Official Use Only - General]

Quoted 269 lines

-----Original Message-----
From: Alex Deucher <[email protected]>
Sent: Thursday, August 24, 2023 10:51 PM
To: Quan, Evan <[email protected]>
Cc: [email protected]; Deucher, Alexander <[email protected]>
Subject: Re: [V2 3/8] drm/amd/pm: add fan mode OD setting support for SMU13

Quoted 227 lines · Evan

[AMD Official Use Only - General]

Quoted 224 lines

-----Original Message-----
From: Alex Deucher <[email protected]>
Sent: Wednesday, August 23, 2023 9:29 PM
To: Quan, Evan <[email protected]>
Cc: [email protected]; Deucher, Alexander <[email protected]>
Subject: Re: [V2 3/8] drm/amd/pm: add fan mode OD setting support for
SMU13

Quoted 11 lines · Evan Quan

Add SMU13 fan mode OD setting support.

--
v1->v2:
- add missing kerneldoc for the new interface(Alex)

---
 Documentation/gpu/amdgpu/thermal.rst          |   6 +
 .../gpu/drm/amd/include/kgd_pp_interface.h    |   4 +-
 drivers/gpu/drm/amd/pm/amdgpu_pm.c            | 200

+++++++++++++++++-

drivers/gpu/drm/amd/pm/amdgpu_pm.c static const struct attribute_group

Quoted 54 lines
 drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h       |   4 +
 drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c     |   2 +
 drivers/gpu/drm/amd/pm/swsmu/inc/smu_types.h  |   1 +
 .../drm/amd/pm/swsmu/smu13/smu_v13_0_0_ppt.c  |  35 ++-
.../drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c  |  35 ++-
 8 files changed, 279 insertions(+), 8 deletions(-)
Documentation/gpu/amdgpu/thermal.rst +6 -0
index 5e27e4eb3959..8757ec7f0136 100644
@@ -64,6 +64,12 @@ gpu_metrics
 .. kernel-doc:: drivers/gpu/drm/amd/pm/amdgpu_pm.c
    :doc: gpu_metrics
 
+fan_mode
+--------
+
+.. kernel-doc:: drivers/gpu/drm/amd/pm/amdgpu_pm.c
+   :doc: fan_mode
+
 GFXOFF
 ======
 
drivers/gpu/drm/amd/include/kgd_pp_interface.h +3 -1
index 84c5224d994c..020c9ce1f735 100644
@@ -113,6 +113,7 @@ enum pp_clock_type {
        OD_RANGE,
        OD_VDDGFX_OFFSET,
        OD_CCLK,
+       OD_FAN_MODE,
 };
 
 enum amd_pp_sensors {
@@ -186,7 +187,8 @@ enum PP_OD_DPM_TABLE_COMMAND {
        PP_OD_EDIT_VDDC_CURVE,
        PP_OD_RESTORE_DEFAULT_TABLE,
        PP_OD_COMMIT_DPM_TABLE,
-       PP_OD_EDIT_VDDGFX_OFFSET
+       PP_OD_EDIT_VDDGFX_OFFSET,
+       PP_OD_EDIT_FAN_MODE,
 };
 
 struct pp_states_info {
drivers/gpu/drm/amd/pm/amdgpu_pm.c +0 -0
index beb3303fc832..d53d60903fe9 100644
@@ -3383,7 +3383,205 @@ static const struct attribute_group

*hwmon_groups[] = {

Quoted 132 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +128 -1
        NULL
 };
 
-static struct od_feature_set amdgpu_od_set;
+static int amdgpu_retrieve_od_settings(struct amdgpu_device *adev,
+                                      enum pp_clock_type od_type,
+                                      char *buf) {
+       int size = 0;
+       int ret;
+
+       if (amdgpu_in_reset(adev))
+               return -EPERM;
+       if (adev->in_suspend && !adev->in_runpm)
+               return -EPERM;
+
+       ret = pm_runtime_get_sync(adev->dev);
+       if (ret < 0) {
+               pm_runtime_put_autosuspend(adev->dev);
+               return ret;
+       }
+
+       size = amdgpu_dpm_print_clock_levels(adev, od_type, buf);
+       if (size == 0)
+               size = sysfs_emit(buf, "\n");
+
+       pm_runtime_mark_last_busy(adev->dev);
+       pm_runtime_put_autosuspend(adev->dev);
+
+       return size;
+}
+
+static int parse_input_od_command_lines(const char *buf,
+                                       size_t count,
+                                       u32 *type,
+                                       long *params,
+                                       uint32_t *num_of_params) {
+       const char delimiter[3] = {' ', '\n', '\0'};
+       uint32_t parameter_size = 0;
+       char buf_cpy[128] = {0};
+       char *tmp_str, *sub_str;
+       int ret;
+
+       if (count > sizeof(buf_cpy) - 1)
+               return -EINVAL;
+
+       memcpy(buf_cpy, buf, count);
+       tmp_str = buf_cpy;
+
+       /* skip heading spaces */
+       while (isspace(*tmp_str))
+               tmp_str++;
+
+       switch (*tmp_str) {
+       case 'c':
+               *type = PP_OD_COMMIT_DPM_TABLE;
+               return 0;
+       default:
+               break;
+       }
+
+       while ((sub_str = strsep(&tmp_str, delimiter)) != NULL) {
+               if (strlen(sub_str) == 0)
+                       continue;
+
+               ret = kstrtol(sub_str, 0, &params[parameter_size]);
+               if (ret)
+                       return -EINVAL;
+               parameter_size++;
+
+               while (isspace(*tmp_str))
+                       tmp_str++;
+       }
+
+       *num_of_params = parameter_size;
+
+       return 0;
+}
+
+static int
+amdgpu_distribute_custom_od_settings(struct amdgpu_device *adev,
+                                    enum PP_OD_DPM_TABLE_COMMAND cmd_type,
+                                    const char *in_buf,
+                                    size_t count) {
+       uint32_t parameter_size = 0;
+       long parameter[64];
+       int ret;
+
+       if (amdgpu_in_reset(adev))
+               return -EPERM;
+       if (adev->in_suspend && !adev->in_runpm)
+               return -EPERM;
+
+       ret = parse_input_od_command_lines(in_buf,
+                                          count,
+                                          &cmd_type,
+                                          parameter,
+                                          &parameter_size);
+       if (ret)
+               return ret;
+
+       ret = pm_runtime_get_sync(adev->dev);
+       if (ret < 0)
+               goto err_out0;
+
+       ret = amdgpu_dpm_odn_edit_dpm_table(adev,
+                                           cmd_type,
+                                           parameter,
+                                           parameter_size);
+       if (ret)
+               goto err_out1;
+
+       if (cmd_type == PP_OD_COMMIT_DPM_TABLE) {
+               ret = amdgpu_dpm_dispatch_task(adev,
+                                              AMD_PP_TASK_READJUST_POWER_STATE,
+                                              NULL);
+               if (ret)
+                       goto err_out1;
+       }
+
+       pm_runtime_mark_last_busy(adev->dev);
+       pm_runtime_put_autosuspend(adev->dev);
+
+       return count;
+
+err_out1:
+       pm_runtime_mark_last_busy(adev->dev);
+err_out0:
+       pm_runtime_put_autosuspend(adev->dev);
+
+       return ret;
+}
+

drivers/gpu/drm/amd/pm/amdgpu_pm.c static const struct attribute_group *hwmon_groups[] = { · line 3524

Quoted 10 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +10 -0
+/**
+ * DOC: fan_mode
+ *
+ * The amdgpu driver provides a sysfs API for checking and
+adjusting the fan
+ * control mode.
+ *
+ * Reading back the file shows you current fan control mode (e.g. '0'
+for auto
+ * mode and '1' for manual mode) and permitted settings if changable.

typo: changeable

Quoted 5 lines
Quoted 4 lines

Also what does manual vs auto mean in this case? Is the idea that you need to switch to manual mode before you make any other adjustments (fan curve or
acoustic) or is this some independent setting?

Auto mode here means PMFW handling the fan speed control in response to

the asic temperature. While driver/user can do some fine tuning like acoustic limit/target, fan target-temperature and minimum pwm.

Quoted 1 line

Manual mode here means the fan curve setting specifically. Driver/user can

customize how the fan speed in response to the asic temperature.

Quoted 1 line

The two modes are mutually exclusive. Switching to one mode will invalid all

those settings installed for the other mode.

Quoted 1 line

Per current implementation for SMU13.0.0 and 13.0.7, user does not need

to adjust the fan mode manually. Driver will handle that. For example, on user's setting of fan curve, driver will handle the fan mode switching to manual mode.

Quoted 1 line

If I understand things correctly, the driver will automatically set manual mode if the user adjusts the fan curve? If so, do we need a separate attribute for manual vs automatic? For the documentation, I'd like to see all of the fan options and what sets are required to enable them and what combinations are allowed.

1. temp/pwm fan curve - requires setting manual mode. Mutually exclusive with 2, 3.
2. acoustic targets - requires setting manual mode. Mutually exclusive with 1, 3.
3. temperature targets - requires setting manual mode. Mutually exclusive with 1, 2.
4. minimum fan speed - requires setting manual mode. works with 1,2,3.

Quoted 6 lines

If the first 3 are mutually exclusive, then maybe we need a fan mode attribute with the following options:
0. auto - let the SMU manage the fan
1. manual - temp/pwm curve
2. manual - acoustic targets
3. manual - temp targets

[Quan, Evan] No, not such complicated. There are only two fan control mode: auto and manual.
The settings working under manual mode: temp/pwm curve settings
The settings working under auto mode: all others (acoustic limit/target, temperature target, minimum pwm...)
And those settings for auto mode can co-work with each other. They affect the auto fan control via different manners and are not mutually exclusive.

Quoted 4 lines

If they are not mutually exclusive, then how do they interact? E.g., what happens if you set a custom temp/pwm curve and acoustic targets and they are not compatible? Does that make sense?

[Quan, Evan] For the sequence above:
1. set a custom temp/pwm curve
- this will switch the fan control to manual mode in order to make the settings to take effect
- this will invalid all other settings working under auto mode only
2. acoustic targets
- this will switch the fan control to auto mode in order to make the setting to take effect
- this will invalid the temp/pwm curve settings working under manual mode only

Evan

Quoted 337 lines

Alex

Quoted 1 line

Please check whether the explanations above make sense to you. I can add

them in the code comment part.

Quoted 7 lines

Evan

Quoted 5 lines

Alex

Quoted 2 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +2 -0
+ *
+ * Writing an integer to the file, sets the fan control mode

correspondingly.

Quoted 34 lines
Quoted 34 lines
Quoted 23 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +23 -0
+ *
+ * When you have finished the editing, write "c" (commit) to the
+file to commit
+ * your changes.
+ */
+static ssize_t fan_mode_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_FAN_MODE, buf); }
+
+static ssize_t fan_mode_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;
+

drivers/gpu/drm/amd/pm/amdgpu_pm.c static const struct attribute_group *hwmon_groups[] = {

Quoted 10 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +10 -0
+       return (ssize_t)amdgpu_distribute_custom_od_settings(adev,
+                                                            PP_OD_EDIT_FAN_MODE,
+                                                            buf,
+
+ count); }
+
+static umode_t fan_mode_visible(struct amdgpu_device *adev) {
+       umode_t umode = 0000;
+
+       if (adev->pm.od_feature_mask &

OD_OPS_SUPPORT_FAN_MODE_RETRIEVE)

Quoted 3 lines
Quoted 3 lines

drivers/gpu/drm/amd/pm/amdgpu_pm.c static const struct attribute_group *hwmon_groups[] = {

Quoted 3 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +3 -0
+               umode |= S_IRUSR | S_IRGRP | S_IROTH;
+
+       if (adev->pm.od_feature_mask &

OD_OPS_SUPPORT_FAN_MODE_SET)

Quoted 75 lines
Quoted 75 lines

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c static enum smu_clk_type

Quoted 53 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +22 -0
+               umode |= S_IWUSR;
+
+       return umode;
+}
+
+static struct od_feature_set amdgpu_od_set = {
+       .containers = {
+               [0] = {
+                       .name = "fan_ctrl",
+                       .sub_feature = {
+                               [0] = {
+                                       .name = "fan_mode",
+                                       .ops = {
+                                               .is_visible = fan_mode_visible,
+                                               .show = fan_mode_show,
+                                               .store = fan_mode_store,
+                                       },
+                               },
+                       },
+               },
+       },
+};
 
 static void od_kobj_release(struct kobject *kobj)  { diff --git

a/drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h
b/drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h
index 4cab6a2efb63..b54f84e2408a 100644

drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h +4 -0
@@ -314,6 +314,9 @@ struct config_table_setting
        uint16_t fclk_average_tau;  };
 
+#define OD_OPS_SUPPORT_FAN_MODE_RETRIEVE               BIT(0)
+#define OD_OPS_SUPPORT_FAN_MODE_SET                    BIT(1)
+
 struct amdgpu_pm {
        struct mutex            mutex;
        u32                     current_sclk;
@@ -368,6 +371,7 @@ struct amdgpu_pm {
        enum amdgpu_runpm_mode rpm_mode;
 
        struct list_head        od_kobj_list;
+       uint32_t                od_feature_mask;
 };
 
 int amdgpu_dpm_read_sensor(struct amdgpu_device *adev, enum

amd_pp_sensors sensor, diff --git
a/drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c
b/drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c
index f005a90c35af..01ccfd219d6b 100644

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +0 -0
@@ -2481,6 +2481,8 @@ static enum smu_clk_type

smu_convert_to_smuclk(enum pp_clock_type type)

Quoted 21 lines
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +2 -0
                clk_type = SMU_OD_VDDGFX_OFFSET; break;
        case OD_CCLK:
                clk_type = SMU_OD_CCLK; break;
+       case OD_FAN_MODE:
+               clk_type = SMU_OD_FAN_MODE; break;
        default:
                clk_type = SMU_CLK_COUNT; break;
        }
drivers/gpu/drm/amd/pm/swsmu/inc/smu_types.h +1 -0
index e57265cf637c..498000850212 100644
@@ -280,6 +280,7 @@ enum smu_clk_type {
        SMU_OD_VDDC_CURVE,
        SMU_OD_RANGE,
        SMU_OD_VDDGFX_OFFSET,
+       SMU_OD_FAN_MODE,
        SMU_CLK_COUNT,
 };
 
Quoted 1 line
Quoted 1 line
Quoted 1 line

diff --git

a/drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_0_ppt.c

Quoted 46 lines
Quoted 46 lines

drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_0_ppt.c static void

Quoted 13 lines

b/drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_0_ppt.c index 1041ba22f8f8..45b42e43f9a3 100644

drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_0_ppt.c +1 -0
@@ -101,6 +101,7 @@
 #define PP_OD_FEATURE_UCLK_FMIN                                2
 #define PP_OD_FEATURE_UCLK_FMAX                                3
 #define PP_OD_FEATURE_GFX_VF_CURVE                     4
+#define PP_OD_FEATURE_FAN_MODE                         5
 
 #define LINK_SPEED_MAX                                 3
 
@@ -1110,6 +1111,10 @@ static void

smu_v13_0_0_get_od_setting_limits(struct smu_context *smu,

Quoted 13 lines
drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_0_ppt.c +4 -0
                od_min_setting = overdrive_lowerlimits-
 VoltageOffsetPerZoneBoundary;
                od_max_setting = overdrive_upperlimits-
 VoltageOffsetPerZoneBoundary;
                break;
+       case PP_OD_FEATURE_FAN_MODE:
+               od_min_setting = overdrive_lowerlimits->FanMode;
+               od_max_setting = overdrive_upperlimits->FanMode;
+               break;
        default:
                od_min_setting = od_max_setting = INT_MAX;
                break;
drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_0_ppt.c +0 -0
@@ -1329,6 +1334,16 @@ static int
Quoted 1 line

smu_v13_0_0_print_clk_levels(struct

smu_context *smu,

Quoted 6 lines

od_table-

OverDriveTable.VoltageOffsetPerZoneBoundary[0]);
                break;
drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_0_ppt.c +2 -0
+       case SMU_OD_FAN_MODE:
+               if (!smu_v13_0_0_is_od_feature_supported(smu,

drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_0_ppt.c static int smu_v13_0_0_print_clk_levels(struct smu_context *smu,

Quoted 10 lines
drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_0_ppt.c +8 -0
+                                                        PP_OD_FEATURE_FAN_CURVE_BIT))
+                       break;
+
+               size += sysfs_emit_at(buf, size, "OD_FAN_MODE:\n");
+               size += sysfs_emit_at(buf, size, "%d\n",
+                                       (int)od_table->OverDriveTable.FanMode);
+               break;
+
        case SMU_OD_RANGE:
                if (!smu_v13_0_0_is_od_feature_supported(smu,

PP_OD_FEATURE_GFXCLK_BIT) &&

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
                    !smu_v13_0_0_is_od_feature_supported(smu,

PP_OD_FEATURE_UCLK_BIT) && @@ -1789,6 +1804,15 @@ static

ssize_t

Quoted 16 lines
Quoted 16 lines

smu_v13_0_0_get_gpu_metrics(struct smu_context *smu,

Quoted 14 lines
        return sizeof(struct gpu_metrics_v1_3);  }
drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_0_ppt.c +9 -0
+static void smu_v13_0_0_set_supported_od_feature_mask(struct
+smu_context *smu) {
+       struct amdgpu_device *adev = smu->adev;
+
+       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_MODE_RETRIEVE; }
+
 static int smu_v13_0_0_set_default_od_settings(struct smu_context
*smu)  {
        OverDriveTableExternal_t *od_table = @@ -1838,8 +1862,12
Quoted 1 line

@@ static int smu_v13_0_0_set_default_od_settings(struct

smu_context *smu)

Quoted 16 lines
Quoted 16 lines

drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_0_ppt.c static int

Quoted 15 lines
                for (i = 0; i < PP_NUM_OD_VF_CURVE_POINTS; i++)
                        user_od_table-

OverDriveTable.VoltageOffsetPerZoneBoundary[i] =

user_od_table_bak.OverDriveTable.VoltageOffsetPerZoneBoundary[i];

drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_0_ppt.c +4 -0
+               user_od_table->OverDriveTable.FanMode =
+                       user_od_table_bak.OverDriveTable.FanMode;
        }
 
+       smu_v13_0_0_set_supported_od_feature_mask(smu);
+
        return 0;
 }
@@ -1850,9 +1878,10 @@ static int

smu_v13_0_0_restore_user_od_settings(struct smu_context *smu)

Quoted 8 lines
Quoted 8 lines

drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_0_ppt.c static int · line 1854

Quoted 5 lines
drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_0_ppt.c +0 -1
        OverDriveTableExternal_t *user_od_table = table_context-
 user_overdrive_table;
        int res;
 
-       user_od_table->OverDriveTable.FeatureCtrlMask = 1U <<

PP_OD_FEATURE_GFXCLK_BIT |

Quoted 2 lines
drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_0_ppt.c +0 -2
-                                                       1U << PP_OD_FEATURE_UCLK_BIT |
-                                                       1U <<

PP_OD_FEATURE_GFX_VF_CURVE_BIT;

Quoted 11 lines
Quoted 11 lines

drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_0_ppt.c static int · line 1882

Quoted 1 line
drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_0_ppt.c +1 -0
+       user_od_table->OverDriveTable.FeatureCtrlMask =

BIT(PP_OD_FEATURE_GFXCLK_BIT) |

Quoted 9 lines
drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_0_ppt.c +5 -0
+                                                       BIT(PP_OD_FEATURE_UCLK_BIT) |
+
+ BIT(PP_OD_FEATURE_GFX_VF_CURVE_BIT) |
+
+ BIT(PP_OD_FEATURE_FAN_CURVE_BIT);
        res = smu_v13_0_0_upload_overdrive_table(smu, user_od_table);
        user_od_table->OverDriveTable.FeatureCtrlMask = 0;
        if (res == 0)

diff --git

a/drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c

Quoted 46 lines
Quoted 46 lines

drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c static void

Quoted 13 lines

b/drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c index 328765f89c94..28c2e4b0e55d 100644

drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c +1 -0
@@ -77,6 +77,7 @@
 #define PP_OD_FEATURE_UCLK_FMIN                                2
 #define PP_OD_FEATURE_UCLK_FMAX                                3
 #define PP_OD_FEATURE_GFX_VF_CURVE                     4
+#define PP_OD_FEATURE_FAN_MODE                         5
 
 #define LINK_SPEED_MAX                                 3
 
@@ -1096,6 +1097,10 @@ static void

smu_v13_0_7_get_od_setting_limits(struct smu_context *smu,

Quoted 13 lines
drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c +4 -0
                od_min_setting = overdrive_lowerlimits-
 VoltageOffsetPerZoneBoundary;
                od_max_setting = overdrive_upperlimits-
 VoltageOffsetPerZoneBoundary;
                break;
+       case PP_OD_FEATURE_FAN_MODE:
+               od_min_setting = overdrive_lowerlimits->FanMode;
+               od_max_setting = overdrive_upperlimits->FanMode;
+               break;
        default:
                od_min_setting = od_max_setting = INT_MAX;
                break;
drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c +0 -0
@@ -1315,6 +1320,16 @@ static int
Quoted 1 line

smu_v13_0_7_print_clk_levels(struct

smu_context *smu,

Quoted 6 lines

od_table-

OverDriveTable.VoltageOffsetPerZoneBoundary[0]);
                break;
drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c +2 -0
+       case SMU_OD_FAN_MODE:
+               if (!smu_v13_0_7_is_od_feature_supported(smu,

drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c static int smu_v13_0_7_print_clk_levels(struct smu_context *smu,

Quoted 10 lines
drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c +8 -0
+                                                        PP_OD_FEATURE_FAN_CURVE_BIT))
+                       break;
+
+               size += sysfs_emit_at(buf, size, "OD_FAN_MODE:\n");
+               size += sysfs_emit_at(buf, size, "%d\n",
+                                       (int)od_table->OverDriveTable.FanMode);
+               break;
+
        case SMU_OD_RANGE:
                if (!smu_v13_0_7_is_od_feature_supported(smu,

PP_OD_FEATURE_GFXCLK_BIT) &&

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
                    !smu_v13_0_7_is_od_feature_supported(smu,

PP_OD_FEATURE_UCLK_BIT) && @@ -1770,6 +1785,15 @@ static

ssize_t

Quoted 16 lines
Quoted 16 lines

smu_v13_0_7_get_gpu_metrics(struct smu_context *smu,

Quoted 14 lines
        return sizeof(struct gpu_metrics_v1_3);  }
drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c +9 -0
+static void smu_v13_0_7_set_supported_od_feature_mask(struct
+smu_context *smu) {
+       struct amdgpu_device *adev = smu->adev;
+
+       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_MODE_RETRIEVE; }
+
 static int smu_v13_0_7_set_default_od_settings(struct smu_context
*smu)  {
        OverDriveTableExternal_t *od_table = @@ -1819,8 +1843,12
Quoted 1 line

@@ static int smu_v13_0_7_set_default_od_settings(struct

smu_context *smu)

Quoted 16 lines
Quoted 16 lines

drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c static int

Quoted 15 lines
                for (i = 0; i < PP_NUM_OD_VF_CURVE_POINTS; i++)
                        user_od_table-

OverDriveTable.VoltageOffsetPerZoneBoundary[i] =

user_od_table_bak.OverDriveTable.VoltageOffsetPerZoneBoundary[i];

drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c +4 -0
+               user_od_table->OverDriveTable.FanMode =
+                       user_od_table_bak.OverDriveTable.FanMode;
        }
 
+       smu_v13_0_7_set_supported_od_feature_mask(smu);
+
        return 0;
 }
@@ -1831,9 +1859,10 @@ static int

smu_v13_0_7_restore_user_od_settings(struct smu_context *smu)

Quoted 8 lines
Quoted 8 lines

drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c static int · line 1835

Quoted 5 lines
drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c +0 -1
        OverDriveTableExternal_t *user_od_table = table_context-
 user_overdrive_table;
        int res;
 
-       user_od_table->OverDriveTable.FeatureCtrlMask = 1U <<

PP_OD_FEATURE_GFXCLK_BIT |

Quoted 2 lines
drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c +0 -2
-                                                       1U << PP_OD_FEATURE_UCLK_BIT |
-                                                       1U <<

PP_OD_FEATURE_GFX_VF_CURVE_BIT;

Quoted 13 lines
Quoted 13 lines

drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c static int · line 1863

Quoted 1 line
drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c +1 -0
+       user_od_table->OverDriveTable.FeatureCtrlMask =

BIT(PP_OD_FEATURE_GFXCLK_BIT) |

Quoted 11 lines
drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c +5 -1
+                                                       BIT(PP_OD_FEATURE_UCLK_BIT) |
+
+ BIT(PP_OD_FEATURE_GFX_VF_CURVE_BIT) |
+
+ BIT(PP_OD_FEATURE_FAN_CURVE_BIT);
        res = smu_v13_0_7_upload_overdrive_table(smu, user_od_table);
        user_od_table->OverDriveTable.FeatureCtrlMask = 0;
        if (res == 0)
--

2.34.1

#7 lore raw

Re: [V2 3/8] drm/amd/pm: add fan mode OD setting support for SMU13

Quoted 286 lines · Evan

[AMD Official Use Only - General]

Quoted 269 lines

-----Original Message-----
From: Alex Deucher <[email protected]>
Sent: Thursday, August 24, 2023 10:51 PM
To: Quan, Evan <[email protected]>
Cc: [email protected]; Deucher, Alexander <[email protected]>
Subject: Re: [V2 3/8] drm/amd/pm: add fan mode OD setting support for SMU13

Quoted 227 lines · Evan

[AMD Official Use Only - General]

Quoted 224 lines

-----Original Message-----
From: Alex Deucher <[email protected]>
Sent: Wednesday, August 23, 2023 9:29 PM
To: Quan, Evan <[email protected]>
Cc: [email protected]; Deucher, Alexander <[email protected]>
Subject: Re: [V2 3/8] drm/amd/pm: add fan mode OD setting support for
SMU13

Quoted 11 lines · Evan Quan

Add SMU13 fan mode OD setting support.

--
v1->v2:
- add missing kerneldoc for the new interface(Alex)

---
 Documentation/gpu/amdgpu/thermal.rst          |   6 +
 .../gpu/drm/amd/include/kgd_pp_interface.h    |   4 +-
 drivers/gpu/drm/amd/pm/amdgpu_pm.c            | 200

+++++++++++++++++-

drivers/gpu/drm/amd/pm/amdgpu_pm.c static const struct attribute_group

Quoted 54 lines
 drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h       |   4 +
 drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c     |   2 +
 drivers/gpu/drm/amd/pm/swsmu/inc/smu_types.h  |   1 +
 .../drm/amd/pm/swsmu/smu13/smu_v13_0_0_ppt.c  |  35 ++-
.../drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c  |  35 ++-
 8 files changed, 279 insertions(+), 8 deletions(-)
Documentation/gpu/amdgpu/thermal.rst +6 -0
index 5e27e4eb3959..8757ec7f0136 100644
@@ -64,6 +64,12 @@ gpu_metrics
 .. kernel-doc:: drivers/gpu/drm/amd/pm/amdgpu_pm.c
    :doc: gpu_metrics
 
+fan_mode
+--------
+
+.. kernel-doc:: drivers/gpu/drm/amd/pm/amdgpu_pm.c
+   :doc: fan_mode
+
 GFXOFF
 ======
 
drivers/gpu/drm/amd/include/kgd_pp_interface.h +3 -1
index 84c5224d994c..020c9ce1f735 100644
@@ -113,6 +113,7 @@ enum pp_clock_type {
        OD_RANGE,
        OD_VDDGFX_OFFSET,
        OD_CCLK,
+       OD_FAN_MODE,
 };
 
 enum amd_pp_sensors {
@@ -186,7 +187,8 @@ enum PP_OD_DPM_TABLE_COMMAND {
        PP_OD_EDIT_VDDC_CURVE,
        PP_OD_RESTORE_DEFAULT_TABLE,
        PP_OD_COMMIT_DPM_TABLE,
-       PP_OD_EDIT_VDDGFX_OFFSET
+       PP_OD_EDIT_VDDGFX_OFFSET,
+       PP_OD_EDIT_FAN_MODE,
 };
 
 struct pp_states_info {
drivers/gpu/drm/amd/pm/amdgpu_pm.c +0 -0
index beb3303fc832..d53d60903fe9 100644
@@ -3383,7 +3383,205 @@ static const struct attribute_group

*hwmon_groups[] = {

Quoted 132 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +128 -1
        NULL
 };
 
-static struct od_feature_set amdgpu_od_set;
+static int amdgpu_retrieve_od_settings(struct amdgpu_device *adev,
+                                      enum pp_clock_type od_type,
+                                      char *buf) {
+       int size = 0;
+       int ret;
+
+       if (amdgpu_in_reset(adev))
+               return -EPERM;
+       if (adev->in_suspend && !adev->in_runpm)
+               return -EPERM;
+
+       ret = pm_runtime_get_sync(adev->dev);
+       if (ret < 0) {
+               pm_runtime_put_autosuspend(adev->dev);
+               return ret;
+       }
+
+       size = amdgpu_dpm_print_clock_levels(adev, od_type, buf);
+       if (size == 0)
+               size = sysfs_emit(buf, "\n");
+
+       pm_runtime_mark_last_busy(adev->dev);
+       pm_runtime_put_autosuspend(adev->dev);
+
+       return size;
+}
+
+static int parse_input_od_command_lines(const char *buf,
+                                       size_t count,
+                                       u32 *type,
+                                       long *params,
+                                       uint32_t *num_of_params) {
+       const char delimiter[3] = {' ', '\n', '\0'};
+       uint32_t parameter_size = 0;
+       char buf_cpy[128] = {0};
+       char *tmp_str, *sub_str;
+       int ret;
+
+       if (count > sizeof(buf_cpy) - 1)
+               return -EINVAL;
+
+       memcpy(buf_cpy, buf, count);
+       tmp_str = buf_cpy;
+
+       /* skip heading spaces */
+       while (isspace(*tmp_str))
+               tmp_str++;
+
+       switch (*tmp_str) {
+       case 'c':
+               *type = PP_OD_COMMIT_DPM_TABLE;
+               return 0;
+       default:
+               break;
+       }
+
+       while ((sub_str = strsep(&tmp_str, delimiter)) != NULL) {
+               if (strlen(sub_str) == 0)
+                       continue;
+
+               ret = kstrtol(sub_str, 0, &params[parameter_size]);
+               if (ret)
+                       return -EINVAL;
+               parameter_size++;
+
+               while (isspace(*tmp_str))
+                       tmp_str++;
+       }
+
+       *num_of_params = parameter_size;
+
+       return 0;
+}
+
+static int
+amdgpu_distribute_custom_od_settings(struct amdgpu_device *adev,
+                                    enum PP_OD_DPM_TABLE_COMMAND cmd_type,
+                                    const char *in_buf,
+                                    size_t count) {
+       uint32_t parameter_size = 0;
+       long parameter[64];
+       int ret;
+
+       if (amdgpu_in_reset(adev))
+               return -EPERM;
+       if (adev->in_suspend && !adev->in_runpm)
+               return -EPERM;
+
+       ret = parse_input_od_command_lines(in_buf,
+                                          count,
+                                          &cmd_type,
+                                          parameter,
+                                          &parameter_size);
+       if (ret)
+               return ret;
+
+       ret = pm_runtime_get_sync(adev->dev);
+       if (ret < 0)
+               goto err_out0;
+
+       ret = amdgpu_dpm_odn_edit_dpm_table(adev,
+                                           cmd_type,
+                                           parameter,
+                                           parameter_size);
+       if (ret)
+               goto err_out1;
+
+       if (cmd_type == PP_OD_COMMIT_DPM_TABLE) {
+               ret = amdgpu_dpm_dispatch_task(adev,
+                                              AMD_PP_TASK_READJUST_POWER_STATE,
+                                              NULL);
+               if (ret)
+                       goto err_out1;
+       }
+
+       pm_runtime_mark_last_busy(adev->dev);
+       pm_runtime_put_autosuspend(adev->dev);
+
+       return count;
+
+err_out1:
+       pm_runtime_mark_last_busy(adev->dev);
+err_out0:
+       pm_runtime_put_autosuspend(adev->dev);
+
+       return ret;
+}
+

drivers/gpu/drm/amd/pm/amdgpu_pm.c static const struct attribute_group *hwmon_groups[] = { · line 3524

Quoted 10 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +10 -0
+/**
+ * DOC: fan_mode
+ *
+ * The amdgpu driver provides a sysfs API for checking and
+adjusting the fan
+ * control mode.
+ *
+ * Reading back the file shows you current fan control mode (e.g. '0'
+for auto
+ * mode and '1' for manual mode) and permitted settings if changable.

typo: changeable

Quoted 5 lines
Quoted 4 lines

Also what does manual vs auto mean in this case? Is the idea that you need to switch to manual mode before you make any other adjustments (fan curve or
acoustic) or is this some independent setting?

Auto mode here means PMFW handling the fan speed control in response to

the asic temperature. While driver/user can do some fine tuning like acoustic limit/target, fan target-temperature and minimum pwm.

Quoted 1 line

Manual mode here means the fan curve setting specifically. Driver/user can

customize how the fan speed in response to the asic temperature.

Quoted 1 line

The two modes are mutually exclusive. Switching to one mode will invalid all

those settings installed for the other mode.

Quoted 1 line

Per current implementation for SMU13.0.0 and 13.0.7, user does not need

to adjust the fan mode manually. Driver will handle that. For example, on user's setting of fan curve, driver will handle the fan mode switching to manual mode.

Quoted 1 line

If I understand things correctly, the driver will automatically set manual mode if the user adjusts the fan curve? If so, do we need a separate attribute for manual vs automatic? For the documentation, I'd like to see all of the fan options and what sets are required to enable them and what combinations are allowed.

1. temp/pwm fan curve - requires setting manual mode. Mutually exclusive with 2, 3.
2. acoustic targets - requires setting manual mode. Mutually exclusive with 1, 3.
3. temperature targets - requires setting manual mode. Mutually exclusive with 1, 2.
4. minimum fan speed - requires setting manual mode. works with 1,2,3.

Quoted 6 lines

If the first 3 are mutually exclusive, then maybe we need a fan mode attribute with the following options:
0. auto - let the SMU manage the fan
1. manual - temp/pwm curve
2. manual - acoustic targets
3. manual - temp targets

[Quan, Evan] No, not such complicated. There are only two fan control mode: auto and manual.
The settings working under manual mode: temp/pwm curve settings
The settings working under auto mode: all others (acoustic limit/target, temperature target, minimum pwm...)
And those settings for auto mode can co-work with each other. They affect the auto fan control via different manners and are not mutually exclusive.

Quoted 4 lines

If they are not mutually exclusive, then how do they interact? E.g., what happens if you set a custom temp/pwm curve and acoustic targets and they are not compatible? Does that make sense?

Quoted 8 lines

[Quan, Evan] For the sequence above:
1. set a custom temp/pwm curve
- this will switch the fan control to manual mode in order to make the settings to take effect
- this will invalid all other settings working under auto mode only
2. acoustic targets
- this will switch the fan control to auto mode in order to make the setting to take effect
- this will invalid the temp/pwm curve settings working under manual mode only

Thanks for clarifying. Can you include this information in the kerneldoc? Also, I think we should either:
1. make the auto/manual required to select enable their respective subfeatures. (e.g., fail to set the fan curve if auto and vice versa for the other features)
2. remove the auto/manual attribute and make whatever was last set take priority.
and document it.

I think 1 is the most obvious from a user perspective, but I don't have that strong of an opinion.

Alex

Quoted 338 lines

Evan

Quoted 337 lines

Alex

Quoted 1 line

Please check whether the explanations above make sense to you. I can add

them in the code comment part.

Quoted 7 lines

Evan

Quoted 5 lines

Alex

Quoted 2 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +2 -0
+ *
+ * Writing an integer to the file, sets the fan control mode

correspondingly.

Quoted 34 lines
Quoted 34 lines
Quoted 23 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +23 -0
+ *
+ * When you have finished the editing, write "c" (commit) to the
+file to commit
+ * your changes.
+ */
+static ssize_t fan_mode_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_FAN_MODE, buf); }
+
+static ssize_t fan_mode_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;
+

drivers/gpu/drm/amd/pm/amdgpu_pm.c static const struct attribute_group *hwmon_groups[] = {

Quoted 10 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +10 -0
+       return (ssize_t)amdgpu_distribute_custom_od_settings(adev,
+                                                            PP_OD_EDIT_FAN_MODE,
+                                                            buf,
+
+ count); }
+
+static umode_t fan_mode_visible(struct amdgpu_device *adev) {
+       umode_t umode = 0000;
+
+       if (adev->pm.od_feature_mask &

OD_OPS_SUPPORT_FAN_MODE_RETRIEVE)

Quoted 3 lines
Quoted 3 lines

drivers/gpu/drm/amd/pm/amdgpu_pm.c static const struct attribute_group *hwmon_groups[] = {

Quoted 3 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +3 -0
+               umode |= S_IRUSR | S_IRGRP | S_IROTH;
+
+       if (adev->pm.od_feature_mask &

OD_OPS_SUPPORT_FAN_MODE_SET)

Quoted 75 lines
Quoted 75 lines

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c static enum smu_clk_type

Quoted 53 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +22 -0
+               umode |= S_IWUSR;
+
+       return umode;
+}
+
+static struct od_feature_set amdgpu_od_set = {
+       .containers = {
+               [0] = {
+                       .name = "fan_ctrl",
+                       .sub_feature = {
+                               [0] = {
+                                       .name = "fan_mode",
+                                       .ops = {
+                                               .is_visible = fan_mode_visible,
+                                               .show = fan_mode_show,
+                                               .store = fan_mode_store,
+                                       },
+                               },
+                       },
+               },
+       },
+};
 
 static void od_kobj_release(struct kobject *kobj)  { diff --git

a/drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h
b/drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h
index 4cab6a2efb63..b54f84e2408a 100644

drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h +4 -0
@@ -314,6 +314,9 @@ struct config_table_setting
        uint16_t fclk_average_tau;  };
 
+#define OD_OPS_SUPPORT_FAN_MODE_RETRIEVE               BIT(0)
+#define OD_OPS_SUPPORT_FAN_MODE_SET                    BIT(1)
+
 struct amdgpu_pm {
        struct mutex            mutex;
        u32                     current_sclk;
@@ -368,6 +371,7 @@ struct amdgpu_pm {
        enum amdgpu_runpm_mode rpm_mode;
 
        struct list_head        od_kobj_list;
+       uint32_t                od_feature_mask;
 };
 
 int amdgpu_dpm_read_sensor(struct amdgpu_device *adev, enum

amd_pp_sensors sensor, diff --git
a/drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c
b/drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c
index f005a90c35af..01ccfd219d6b 100644

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +0 -0
@@ -2481,6 +2481,8 @@ static enum smu_clk_type

smu_convert_to_smuclk(enum pp_clock_type type)

Quoted 21 lines
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +2 -0
                clk_type = SMU_OD_VDDGFX_OFFSET; break;
        case OD_CCLK:
                clk_type = SMU_OD_CCLK; break;
+       case OD_FAN_MODE:
+               clk_type = SMU_OD_FAN_MODE; break;
        default:
                clk_type = SMU_CLK_COUNT; break;
        }
drivers/gpu/drm/amd/pm/swsmu/inc/smu_types.h +1 -0
index e57265cf637c..498000850212 100644
@@ -280,6 +280,7 @@ enum smu_clk_type {
        SMU_OD_VDDC_CURVE,
        SMU_OD_RANGE,
        SMU_OD_VDDGFX_OFFSET,
+       SMU_OD_FAN_MODE,
        SMU_CLK_COUNT,
 };
 
Quoted 1 line
Quoted 1 line
Quoted 1 line

diff --git

a/drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_0_ppt.c

Quoted 46 lines
Quoted 46 lines

drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_0_ppt.c static void

Quoted 13 lines

b/drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_0_ppt.c index 1041ba22f8f8..45b42e43f9a3 100644

drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_0_ppt.c +1 -0
@@ -101,6 +101,7 @@
 #define PP_OD_FEATURE_UCLK_FMIN                                2
 #define PP_OD_FEATURE_UCLK_FMAX                                3
 #define PP_OD_FEATURE_GFX_VF_CURVE                     4
+#define PP_OD_FEATURE_FAN_MODE                         5
 
 #define LINK_SPEED_MAX                                 3
 
@@ -1110,6 +1111,10 @@ static void

smu_v13_0_0_get_od_setting_limits(struct smu_context *smu,

Quoted 13 lines
drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_0_ppt.c +4 -0
                od_min_setting = overdrive_lowerlimits-
 VoltageOffsetPerZoneBoundary;
                od_max_setting = overdrive_upperlimits-
 VoltageOffsetPerZoneBoundary;
                break;
+       case PP_OD_FEATURE_FAN_MODE:
+               od_min_setting = overdrive_lowerlimits->FanMode;
+               od_max_setting = overdrive_upperlimits->FanMode;
+               break;
        default:
                od_min_setting = od_max_setting = INT_MAX;
                break;
drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_0_ppt.c +0 -0
@@ -1329,6 +1334,16 @@ static int
Quoted 1 line

smu_v13_0_0_print_clk_levels(struct

smu_context *smu,

Quoted 6 lines

od_table-

OverDriveTable.VoltageOffsetPerZoneBoundary[0]);
                break;
drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_0_ppt.c +2 -0
+       case SMU_OD_FAN_MODE:
+               if (!smu_v13_0_0_is_od_feature_supported(smu,

drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_0_ppt.c static int smu_v13_0_0_print_clk_levels(struct smu_context *smu,

Quoted 10 lines
drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_0_ppt.c +8 -0
+                                                        PP_OD_FEATURE_FAN_CURVE_BIT))
+                       break;
+
+               size += sysfs_emit_at(buf, size, "OD_FAN_MODE:\n");
+               size += sysfs_emit_at(buf, size, "%d\n",
+                                       (int)od_table->OverDriveTable.FanMode);
+               break;
+
        case SMU_OD_RANGE:
                if (!smu_v13_0_0_is_od_feature_supported(smu,

PP_OD_FEATURE_GFXCLK_BIT) &&

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
                    !smu_v13_0_0_is_od_feature_supported(smu,

PP_OD_FEATURE_UCLK_BIT) && @@ -1789,6 +1804,15 @@ static

ssize_t

Quoted 16 lines
Quoted 16 lines

smu_v13_0_0_get_gpu_metrics(struct smu_context *smu,

Quoted 14 lines
        return sizeof(struct gpu_metrics_v1_3);  }
drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_0_ppt.c +9 -0
+static void smu_v13_0_0_set_supported_od_feature_mask(struct
+smu_context *smu) {
+       struct amdgpu_device *adev = smu->adev;
+
+       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_MODE_RETRIEVE; }
+
 static int smu_v13_0_0_set_default_od_settings(struct smu_context
*smu)  {
        OverDriveTableExternal_t *od_table = @@ -1838,8 +1862,12
Quoted 1 line

@@ static int smu_v13_0_0_set_default_od_settings(struct

smu_context *smu)

Quoted 16 lines
Quoted 16 lines

drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_0_ppt.c static int

Quoted 15 lines
                for (i = 0; i < PP_NUM_OD_VF_CURVE_POINTS; i++)
                        user_od_table-

OverDriveTable.VoltageOffsetPerZoneBoundary[i] =

user_od_table_bak.OverDriveTable.VoltageOffsetPerZoneBoundary[i];

drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_0_ppt.c +4 -0
+               user_od_table->OverDriveTable.FanMode =
+                       user_od_table_bak.OverDriveTable.FanMode;
        }
 
+       smu_v13_0_0_set_supported_od_feature_mask(smu);
+
        return 0;
 }
@@ -1850,9 +1878,10 @@ static int

smu_v13_0_0_restore_user_od_settings(struct smu_context *smu)

Quoted 8 lines
Quoted 8 lines

drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_0_ppt.c static int · line 1854

Quoted 5 lines
drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_0_ppt.c +0 -1
        OverDriveTableExternal_t *user_od_table = table_context-
 user_overdrive_table;
        int res;
 
-       user_od_table->OverDriveTable.FeatureCtrlMask = 1U <<

PP_OD_FEATURE_GFXCLK_BIT |

Quoted 2 lines
drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_0_ppt.c +0 -2
-                                                       1U << PP_OD_FEATURE_UCLK_BIT |
-                                                       1U <<

PP_OD_FEATURE_GFX_VF_CURVE_BIT;

Quoted 11 lines
Quoted 11 lines

drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_0_ppt.c static int · line 1882

Quoted 1 line
drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_0_ppt.c +1 -0
+       user_od_table->OverDriveTable.FeatureCtrlMask =

BIT(PP_OD_FEATURE_GFXCLK_BIT) |

Quoted 9 lines
drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_0_ppt.c +5 -0
+                                                       BIT(PP_OD_FEATURE_UCLK_BIT) |
+
+ BIT(PP_OD_FEATURE_GFX_VF_CURVE_BIT) |
+
+ BIT(PP_OD_FEATURE_FAN_CURVE_BIT);
        res = smu_v13_0_0_upload_overdrive_table(smu, user_od_table);
        user_od_table->OverDriveTable.FeatureCtrlMask = 0;
        if (res == 0)

diff --git

a/drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c

Quoted 46 lines
Quoted 46 lines

drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c static void

Quoted 13 lines

b/drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c index 328765f89c94..28c2e4b0e55d 100644

drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c +1 -0
@@ -77,6 +77,7 @@
 #define PP_OD_FEATURE_UCLK_FMIN                                2
 #define PP_OD_FEATURE_UCLK_FMAX                                3
 #define PP_OD_FEATURE_GFX_VF_CURVE                     4
+#define PP_OD_FEATURE_FAN_MODE                         5
 
 #define LINK_SPEED_MAX                                 3
 
@@ -1096,6 +1097,10 @@ static void

smu_v13_0_7_get_od_setting_limits(struct smu_context *smu,

Quoted 13 lines
drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c +4 -0
                od_min_setting = overdrive_lowerlimits-
 VoltageOffsetPerZoneBoundary;
                od_max_setting = overdrive_upperlimits-
 VoltageOffsetPerZoneBoundary;
                break;
+       case PP_OD_FEATURE_FAN_MODE:
+               od_min_setting = overdrive_lowerlimits->FanMode;
+               od_max_setting = overdrive_upperlimits->FanMode;
+               break;
        default:
                od_min_setting = od_max_setting = INT_MAX;
                break;
drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c +0 -0
@@ -1315,6 +1320,16 @@ static int
Quoted 1 line

smu_v13_0_7_print_clk_levels(struct

smu_context *smu,

Quoted 6 lines

od_table-

OverDriveTable.VoltageOffsetPerZoneBoundary[0]);
                break;
drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c +2 -0
+       case SMU_OD_FAN_MODE:
+               if (!smu_v13_0_7_is_od_feature_supported(smu,

drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c static int smu_v13_0_7_print_clk_levels(struct smu_context *smu,

Quoted 10 lines
drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c +8 -0
+                                                        PP_OD_FEATURE_FAN_CURVE_BIT))
+                       break;
+
+               size += sysfs_emit_at(buf, size, "OD_FAN_MODE:\n");
+               size += sysfs_emit_at(buf, size, "%d\n",
+                                       (int)od_table->OverDriveTable.FanMode);
+               break;
+
        case SMU_OD_RANGE:
                if (!smu_v13_0_7_is_od_feature_supported(smu,

PP_OD_FEATURE_GFXCLK_BIT) &&

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
                    !smu_v13_0_7_is_od_feature_supported(smu,

PP_OD_FEATURE_UCLK_BIT) && @@ -1770,6 +1785,15 @@ static

ssize_t

Quoted 16 lines
Quoted 16 lines

smu_v13_0_7_get_gpu_metrics(struct smu_context *smu,

Quoted 14 lines
        return sizeof(struct gpu_metrics_v1_3);  }
drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c +9 -0
+static void smu_v13_0_7_set_supported_od_feature_mask(struct
+smu_context *smu) {
+       struct amdgpu_device *adev = smu->adev;
+
+       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_MODE_RETRIEVE; }
+
 static int smu_v13_0_7_set_default_od_settings(struct smu_context
*smu)  {
        OverDriveTableExternal_t *od_table = @@ -1819,8 +1843,12
Quoted 1 line

@@ static int smu_v13_0_7_set_default_od_settings(struct

smu_context *smu)

Quoted 16 lines
Quoted 16 lines

drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c static int

Quoted 15 lines
                for (i = 0; i < PP_NUM_OD_VF_CURVE_POINTS; i++)
                        user_od_table-

OverDriveTable.VoltageOffsetPerZoneBoundary[i] =

user_od_table_bak.OverDriveTable.VoltageOffsetPerZoneBoundary[i];

drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c +4 -0
+               user_od_table->OverDriveTable.FanMode =
+                       user_od_table_bak.OverDriveTable.FanMode;
        }
 
+       smu_v13_0_7_set_supported_od_feature_mask(smu);
+
        return 0;
 }
@@ -1831,9 +1859,10 @@ static int

smu_v13_0_7_restore_user_od_settings(struct smu_context *smu)

Quoted 8 lines
Quoted 8 lines

drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c static int · line 1835

Quoted 5 lines
drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c +0 -1
        OverDriveTableExternal_t *user_od_table = table_context-
 user_overdrive_table;
        int res;
 
-       user_od_table->OverDriveTable.FeatureCtrlMask = 1U <<

PP_OD_FEATURE_GFXCLK_BIT |

Quoted 2 lines
drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c +0 -2
-                                                       1U << PP_OD_FEATURE_UCLK_BIT |
-                                                       1U <<

PP_OD_FEATURE_GFX_VF_CURVE_BIT;

Quoted 13 lines
Quoted 13 lines

drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c static int · line 1863

Quoted 1 line
drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c +1 -0
+       user_od_table->OverDriveTable.FeatureCtrlMask =

BIT(PP_OD_FEATURE_GFXCLK_BIT) |

Quoted 11 lines
drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c +5 -1
+                                                       BIT(PP_OD_FEATURE_UCLK_BIT) |
+
+ BIT(PP_OD_FEATURE_GFX_VF_CURVE_BIT) |
+
+ BIT(PP_OD_FEATURE_FAN_CURVE_BIT);
        res = smu_v13_0_7_upload_overdrive_table(smu, user_od_table);
        user_od_table->OverDriveTable.FeatureCtrlMask = 0;
        if (res == 0)
--

2.34.1

author
#8 lore raw

PATCH v2 4/8 drm/amd/pm: add fan temperature/pwm curve OD setting support for SMU13

In reply to Evan Quan

Add SMU13 fan temperature/pwm curve OD setting support.

--
v1->v2:
- add missing kerneldoc for the new interface(Alex)

---
 Documentation/gpu/amdgpu/thermal.rst          |  6 ++
 .../gpu/drm/amd/include/kgd_pp_interface.h    |  2 +
 drivers/gpu/drm/amd/pm/amdgpu_pm.c            | 62 +++++++++++++
 drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h       |  2 +
 drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c     |  2 +
 drivers/gpu/drm/amd/pm/swsmu/inc/smu_types.h  |  1 +
 .../drm/amd/pm/swsmu/smu13/smu_v13_0_0_ppt.c  | 87 ++++++++++++++++++-
 .../drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c  | 87 ++++++++++++++++++-
 8 files changed, 247 insertions(+), 2 deletions(-)
Documentation/gpu/amdgpu/thermal.rst +6 -0
index 8757ec7f0136..48b4b89f2ffb 100644
@@ -70,6 +70,12 @@ fan_mode
 .. kernel-doc:: drivers/gpu/drm/amd/pm/amdgpu_pm.c
    :doc: fan_mode
 
+fan_cuve
+--------
+
+.. kernel-doc:: drivers/gpu/drm/amd/pm/amdgpu_pm.c
+   :doc: fan_curve
+
 GFXOFF
 ======
 
drivers/gpu/drm/amd/include/kgd_pp_interface.h +2 -0
index 020c9ce1f735..6d0d37dfb28b 100644
@@ -114,6 +114,7 @@ enum pp_clock_type {
 	OD_VDDGFX_OFFSET,
 	OD_CCLK,
 	OD_FAN_MODE,
+	OD_FAN_CURVE,
 };
 
 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_MODE,
+	PP_OD_EDIT_FAN_CURVE,
 };
 
 struct pp_states_info {
drivers/gpu/drm/amd/pm/amdgpu_pm.c +62 -0

74 lines not on this page · raw message

drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h +2 -0
index b54f84e2408a..4463c60b710a 100644
@@ -316,6 +316,8 @@ struct config_table_setting
 
 #define OD_OPS_SUPPORT_FAN_MODE_RETRIEVE		BIT(0)
 #define OD_OPS_SUPPORT_FAN_MODE_SET			BIT(1)
+#define OD_OPS_SUPPORT_FAN_CURVE_RETRIEVE		BIT(2)
+#define OD_OPS_SUPPORT_FAN_CURVE_SET			BIT(3)
 
 struct amdgpu_pm {
 	struct mutex		mutex;
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +2 -0
index 01ccfd219d6b..fe998df9dca2 100644
@@ -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_MODE:
 		clk_type = SMU_OD_FAN_MODE; break;
+	case OD_FAN_CURVE:
+		clk_type = SMU_OD_FAN_CURVE; break;
 	default:
 		clk_type = SMU_CLK_COUNT; break;
 	}
drivers/gpu/drm/amd/pm/swsmu/inc/smu_types.h +1 -0
index 498000850212..f17127c50238 100644
@@ -281,6 +281,7 @@ enum smu_clk_type {
 	SMU_OD_RANGE,
 	SMU_OD_VDDGFX_OFFSET,
 	SMU_OD_FAN_MODE,
+	SMU_OD_FAN_CURVE,
 	SMU_CLK_COUNT,
 };
 
drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_0_ppt.c +86 -1

123 lines not on this page · raw message

drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c +86 -1

123 lines not on this page · raw message

Signature · 1 line
2.34.1
author
#9 lore raw

PATCH v2 5/8 drm/amd/pm: add fan acoustic limit OD setting support for SMU13

In reply to Evan Quan

Add SMU13 fan acoustic limit OD setting support.

--
v1->v2:
- add missing kerneldoc for the new interface(Alex)

---
 Documentation/gpu/amdgpu/thermal.rst          |  6 ++
 .../gpu/drm/amd/include/kgd_pp_interface.h    |  2 +
 drivers/gpu/drm/amd/pm/amdgpu_pm.c            | 59 +++++++++++++++++++
 drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h       |  2 +
 drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c     |  2 +
 drivers/gpu/drm/amd/pm/swsmu/inc/smu_types.h  |  1 +
 .../drm/amd/pm/swsmu/smu13/smu_v13_0_0_ppt.c  | 51 +++++++++++++++-
 .../drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c  | 51 +++++++++++++++-
 8 files changed, 172 insertions(+), 2 deletions(-)
Documentation/gpu/amdgpu/thermal.rst +6 -0
index 48b4b89f2ffb..4fa2971ec02a 100644
@@ -76,6 +76,12 @@ fan_cuve
 .. 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
 ======
 
drivers/gpu/drm/amd/include/kgd_pp_interface.h +2 -0
index 6d0d37dfb28b..f657882974ee 100644
@@ -115,6 +115,7 @@ enum pp_clock_type {
 	OD_CCLK,
 	OD_FAN_MODE,
 	OD_FAN_CURVE,
+	OD_ACOUSTIC_LIMIT,
 };
 
 enum amd_pp_sensors {
@@ -191,6 +192,7 @@ enum PP_OD_DPM_TABLE_COMMAND {
 	PP_OD_EDIT_VDDGFX_OFFSET,
 	PP_OD_EDIT_FAN_MODE,
 	PP_OD_EDIT_FAN_CURVE,
+	PP_OD_EDIT_ACOUSTIC_LIMIT,
 };
 
 struct pp_states_info {
drivers/gpu/drm/amd/pm/amdgpu_pm.c +59 -0

71 lines not on this page · raw message

drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h +2 -0
index 4463c60b710a..17ffcef34e61 100644
@@ -318,6 +318,8 @@ struct config_table_setting
 #define OD_OPS_SUPPORT_FAN_MODE_SET			BIT(1)
 #define OD_OPS_SUPPORT_FAN_CURVE_RETRIEVE		BIT(2)
 #define OD_OPS_SUPPORT_FAN_CURVE_SET			BIT(3)
+#define OD_OPS_SUPPORT_ACOUSTIC_LIMIT_THRESHOLD_RETRIEVE	BIT(4)
+#define OD_OPS_SUPPORT_ACOUSTIC_LIMIT_THRESHOLD_SET		BIT(5)
 
 struct amdgpu_pm {
 	struct mutex		mutex;
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +2 -0
index fe998df9dca2..3db6bd49b73c 100644
@@ -2485,6 +2485,8 @@ static enum smu_clk_type smu_convert_to_smuclk(enum pp_clock_type type)
 		clk_type = SMU_OD_FAN_MODE; 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;
 	}
drivers/gpu/drm/amd/pm/swsmu/inc/smu_types.h +1 -0
index f17127c50238..1485dd42f078 100644
@@ -282,6 +282,7 @@ enum smu_clk_type {
 	SMU_OD_VDDGFX_OFFSET,
 	SMU_OD_FAN_MODE,
 	SMU_OD_FAN_CURVE,
+	SMU_OD_ACOUSTIC_LIMIT,
 	SMU_CLK_COUNT,
 };
 
drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_0_ppt.c +50 -1

87 lines not on this page · raw message

drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c +50 -1

87 lines not on this page · raw message

Signature · 1 line
2.34.1
author
#10 lore raw

PATCH v2 6/8 drm/amd/pm: add fan acoustic target OD setting support for SMU13

In reply to Evan Quan

Add SMU13 fan acoustic target OD setting support.

--
v1->v2:
- add missing kerneldoc for the new interface(Alex)

---
 Documentation/gpu/amdgpu/thermal.rst          |  6 ++
 .../gpu/drm/amd/include/kgd_pp_interface.h    |  2 +
 drivers/gpu/drm/amd/pm/amdgpu_pm.c            | 59 +++++++++++++++++++
 drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h       |  2 +
 drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c     |  2 +
 drivers/gpu/drm/amd/pm/swsmu/inc/smu_types.h  |  1 +
 .../drm/amd/pm/swsmu/smu13/smu_v13_0_0_ppt.c  | 51 +++++++++++++++-
 .../drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c  | 51 +++++++++++++++-
 8 files changed, 172 insertions(+), 2 deletions(-)
Documentation/gpu/amdgpu/thermal.rst +6 -0
index 4fa2971ec02a..25774032cc16 100644
@@ -82,6 +82,12 @@ acoustic_limit_rpm_threshold
 .. kernel-doc:: drivers/gpu/drm/amd/pm/amdgpu_pm.c
    :doc: acoustic_limit_rpm_threshold
 
+acoustic_target_rpm_threshold
+-----------------------------
+
+.. kernel-doc:: drivers/gpu/drm/amd/pm/amdgpu_pm.c
+   :doc: acoustic_target_rpm_threshold
+
 GFXOFF
 ======
 
drivers/gpu/drm/amd/include/kgd_pp_interface.h +2 -0
index f657882974ee..ca44e5bea2e5 100644
@@ -116,6 +116,7 @@ enum pp_clock_type {
 	OD_FAN_MODE,
 	OD_FAN_CURVE,
 	OD_ACOUSTIC_LIMIT,
+	OD_ACOUSTIC_TARGET,
 };
 
 enum amd_pp_sensors {
@@ -193,6 +194,7 @@ enum PP_OD_DPM_TABLE_COMMAND {
 	PP_OD_EDIT_FAN_MODE,
 	PP_OD_EDIT_FAN_CURVE,
 	PP_OD_EDIT_ACOUSTIC_LIMIT,
+	PP_OD_EDIT_ACOUSTIC_TARGET,
 };
 
 struct pp_states_info {
drivers/gpu/drm/amd/pm/amdgpu_pm.c +59 -0

71 lines not on this page · raw message

drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h +2 -0
index 17ffcef34e61..6b2bbd13db09 100644
@@ -320,6 +320,8 @@ struct config_table_setting
 #define OD_OPS_SUPPORT_FAN_CURVE_SET			BIT(3)
 #define OD_OPS_SUPPORT_ACOUSTIC_LIMIT_THRESHOLD_RETRIEVE	BIT(4)
 #define OD_OPS_SUPPORT_ACOUSTIC_LIMIT_THRESHOLD_SET		BIT(5)
+#define OD_OPS_SUPPORT_ACOUSTIC_TARGET_THRESHOLD_RETRIEVE	BIT(6)
+#define OD_OPS_SUPPORT_ACOUSTIC_TARGET_THRESHOLD_SET		BIT(7)
 
 struct amdgpu_pm {
 	struct mutex		mutex;
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +2 -0
index 3db6bd49b73c..3bfa9b9bb247 100644
@@ -2487,6 +2487,8 @@ static enum smu_clk_type smu_convert_to_smuclk(enum pp_clock_type type)
 		clk_type = SMU_OD_FAN_CURVE; break;
 	case OD_ACOUSTIC_LIMIT:
 		clk_type = SMU_OD_ACOUSTIC_LIMIT; break;
+	case OD_ACOUSTIC_TARGET:
+		clk_type = SMU_OD_ACOUSTIC_TARGET; break;
 	default:
 		clk_type = SMU_CLK_COUNT; break;
 	}
drivers/gpu/drm/amd/pm/swsmu/inc/smu_types.h +1 -0
index 1485dd42f078..8049c20c1e66 100644
@@ -283,6 +283,7 @@ enum smu_clk_type {
 	SMU_OD_FAN_MODE,
 	SMU_OD_FAN_CURVE,
 	SMU_OD_ACOUSTIC_LIMIT,
+	SMU_OD_ACOUSTIC_TARGET,
 	SMU_CLK_COUNT,
 };
 
drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_0_ppt.c +50 -1

87 lines not on this page · raw message

drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c +50 -1

87 lines not on this page · raw message

Signature · 1 line
2.34.1
author
#11 lore raw

PATCH v2 7/8 drm/amd/pm: add fan target temperature OD setting support for SMU13

In reply to Evan Quan

Add SMU13 fan target temperature OD setting support.

--
v1->v2:
- add missing kerneldoc for the new interface(Alex)

---
 Documentation/gpu/amdgpu/thermal.rst          |  6 ++
 .../gpu/drm/amd/include/kgd_pp_interface.h    |  2 +
 drivers/gpu/drm/amd/pm/amdgpu_pm.c            | 59 +++++++++++++++++++
 drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h       |  2 +
 drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c     |  2 +
 drivers/gpu/drm/amd/pm/swsmu/inc/smu_types.h  |  1 +
 .../drm/amd/pm/swsmu/smu13/smu_v13_0_0_ppt.c  | 51 +++++++++++++++-
 .../drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c  | 51 +++++++++++++++-
 8 files changed, 172 insertions(+), 2 deletions(-)
Documentation/gpu/amdgpu/thermal.rst +6 -0
index 25774032cc16..073ab9e418b1 100644
@@ -88,6 +88,12 @@ acoustic_target_rpm_threshold
 .. kernel-doc:: drivers/gpu/drm/amd/pm/amdgpu_pm.c
    :doc: acoustic_target_rpm_threshold
 
+fan_target_temperature
+----------------------
+
+.. kernel-doc:: drivers/gpu/drm/amd/pm/amdgpu_pm.c
+   :doc: fan_target_temperature
+
 GFXOFF
 ======
 
drivers/gpu/drm/amd/include/kgd_pp_interface.h +2 -0
index ca44e5bea2e5..c1065136f527 100644
@@ -117,6 +117,7 @@ enum pp_clock_type {
 	OD_FAN_CURVE,
 	OD_ACOUSTIC_LIMIT,
 	OD_ACOUSTIC_TARGET,
+	OD_FAN_TARGET_TEMPERATURE,
 };
 
 enum amd_pp_sensors {
@@ -195,6 +196,7 @@ enum PP_OD_DPM_TABLE_COMMAND {
 	PP_OD_EDIT_FAN_CURVE,
 	PP_OD_EDIT_ACOUSTIC_LIMIT,
 	PP_OD_EDIT_ACOUSTIC_TARGET,
+	PP_OD_EDIT_FAN_TARGET_TEMPERATURE,
 };
 
 struct pp_states_info {
drivers/gpu/drm/amd/pm/amdgpu_pm.c +59 -0

71 lines not on this page · raw message

drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h +2 -0
index 6b2bbd13db09..80d2ac1ecb9f 100644
@@ -322,6 +322,8 @@ struct config_table_setting
 #define OD_OPS_SUPPORT_ACOUSTIC_LIMIT_THRESHOLD_SET		BIT(5)
 #define OD_OPS_SUPPORT_ACOUSTIC_TARGET_THRESHOLD_RETRIEVE	BIT(6)
 #define OD_OPS_SUPPORT_ACOUSTIC_TARGET_THRESHOLD_SET		BIT(7)
+#define OD_OPS_SUPPORT_FAN_TARGET_TEMPERATURE_RETRIEVE	BIT(8)
+#define OD_OPS_SUPPORT_FAN_TARGET_TEMPERATURE_SET	BIT(9)
 
 struct amdgpu_pm {
 	struct mutex		mutex;
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +2 -0
index 3bfa9b9bb247..22a6527139a6 100644
@@ -2489,6 +2489,8 @@ static enum smu_clk_type smu_convert_to_smuclk(enum pp_clock_type type)
 		clk_type = SMU_OD_ACOUSTIC_LIMIT; break;
 	case OD_ACOUSTIC_TARGET:
 		clk_type = SMU_OD_ACOUSTIC_TARGET; break;
+	case OD_FAN_TARGET_TEMPERATURE:
+		clk_type = SMU_OD_FAN_TARGET_TEMPERATURE; break;
 	default:
 		clk_type = SMU_CLK_COUNT; break;
 	}
drivers/gpu/drm/amd/pm/swsmu/inc/smu_types.h +1 -0
index 8049c20c1e66..1a00f807fb09 100644
@@ -284,6 +284,7 @@ enum smu_clk_type {
 	SMU_OD_FAN_CURVE,
 	SMU_OD_ACOUSTIC_LIMIT,
 	SMU_OD_ACOUSTIC_TARGET,
+	SMU_OD_FAN_TARGET_TEMPERATURE,
 	SMU_CLK_COUNT,
 };
 
drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_0_ppt.c +50 -1

87 lines not on this page · raw message

drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c +50 -1

87 lines not on this page · raw message

Signature · 1 line
2.34.1
author
#12 lore raw

PATCH v2 8/8 drm/amd/pm: add fan minimum pwm OD setting support for SMU13

In reply to Evan Quan

Add SMU13 fan minimum pwm OD setting support.

--
v1->v2:
- add missing kerneldoc for the new interface(Alex)

---
 Documentation/gpu/amdgpu/thermal.rst          |  6 ++
 .../gpu/drm/amd/include/kgd_pp_interface.h    |  2 +
 drivers/gpu/drm/amd/pm/amdgpu_pm.c            | 59 +++++++++++++++++++
 drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h       |  2 +
 drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c     |  2 +
 drivers/gpu/drm/amd/pm/swsmu/inc/smu_types.h  |  1 +
 .../drm/amd/pm/swsmu/smu13/smu_v13_0_0_ppt.c  | 51 +++++++++++++++-
 .../drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c  | 51 +++++++++++++++-
 8 files changed, 172 insertions(+), 2 deletions(-)
Documentation/gpu/amdgpu/thermal.rst +6 -0
index 073ab9e418b1..940f723472b8 100644
@@ -94,6 +94,12 @@ fan_target_temperature
 .. kernel-doc:: drivers/gpu/drm/amd/pm/amdgpu_pm.c
    :doc: fan_target_temperature
 
+fan_minimum_pwm
+---------------
+
+.. kernel-doc:: drivers/gpu/drm/amd/pm/amdgpu_pm.c
+   :doc: fan_minimum_pwm
+
 GFXOFF
 ======
 
drivers/gpu/drm/amd/include/kgd_pp_interface.h +2 -0
index c1065136f527..528c892f7c4b 100644
@@ -118,6 +118,7 @@ enum pp_clock_type {
 	OD_ACOUSTIC_LIMIT,
 	OD_ACOUSTIC_TARGET,
 	OD_FAN_TARGET_TEMPERATURE,
+	OD_FAN_MINIMUM_PWM,
 };
 
 enum amd_pp_sensors {
@@ -197,6 +198,7 @@ enum PP_OD_DPM_TABLE_COMMAND {
 	PP_OD_EDIT_ACOUSTIC_LIMIT,
 	PP_OD_EDIT_ACOUSTIC_TARGET,
 	PP_OD_EDIT_FAN_TARGET_TEMPERATURE,
+	PP_OD_EDIT_FAN_MINIMUM_PWM,
 };
 
 struct pp_states_info {
drivers/gpu/drm/amd/pm/amdgpu_pm.c +59 -0

71 lines not on this page · raw message

drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h +2 -0
index 80d2ac1ecb9f..342c4d8318dc 100644
@@ -324,6 +324,8 @@ struct config_table_setting
 #define OD_OPS_SUPPORT_ACOUSTIC_TARGET_THRESHOLD_SET		BIT(7)
 #define OD_OPS_SUPPORT_FAN_TARGET_TEMPERATURE_RETRIEVE	BIT(8)
 #define OD_OPS_SUPPORT_FAN_TARGET_TEMPERATURE_SET	BIT(9)
+#define OD_OPS_SUPPORT_FAN_MINIMUM_PWM_RETRIEVE		BIT(10)
+#define OD_OPS_SUPPORT_FAN_MINIMUM_PWM_SET		BIT(11)
 
 struct amdgpu_pm {
 	struct mutex		mutex;
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +2 -0
index 22a6527139a6..d22ed5a272ce 100644
@@ -2491,6 +2491,8 @@ static enum smu_clk_type smu_convert_to_smuclk(enum pp_clock_type type)
 		clk_type = SMU_OD_ACOUSTIC_TARGET; break;
 	case OD_FAN_TARGET_TEMPERATURE:
 		clk_type = SMU_OD_FAN_TARGET_TEMPERATURE; break;
+	case OD_FAN_MINIMUM_PWM:
+		clk_type = SMU_OD_FAN_MINIMUM_PWM; break;
 	default:
 		clk_type = SMU_CLK_COUNT; break;
 	}
drivers/gpu/drm/amd/pm/swsmu/inc/smu_types.h +1 -0
index 1a00f807fb09..5c8f30f600f8 100644
@@ -285,6 +285,7 @@ enum smu_clk_type {
 	SMU_OD_ACOUSTIC_LIMIT,
 	SMU_OD_ACOUSTIC_TARGET,
 	SMU_OD_FAN_TARGET_TEMPERATURE,
+	SMU_OD_FAN_MINIMUM_PWM,
 	SMU_CLK_COUNT,
 };
 
drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_0_ppt.c +50 -1

87 lines not on this page · raw message

drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c +50 -1

87 lines not on this page · raw message

Signature · 1 line
2.34.1
#13 lore raw

Re: [V2 8/8] drm/amd/pm: add fan minimum pwm OD setting support for SMU13

Are there any restrictions on which fan control options you can enable? I.e., can you mess with all of these or are there several discrete fan modes (acoustic, curve, min fan, etc.) that you have to set up independently? We should document the restrictions.

Alex

Quoted 367 lines · Evan Quan

Add SMU13 fan minimum pwm OD setting support.

--
v1->v2:
- add missing kerneldoc for the new interface(Alex)

---
 Documentation/gpu/amdgpu/thermal.rst          |  6 ++
 .../gpu/drm/amd/include/kgd_pp_interface.h    |  2 +
 drivers/gpu/drm/amd/pm/amdgpu_pm.c            | 59 +++++++++++++++++++
 drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h       |  2 +
 drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c     |  2 +
 drivers/gpu/drm/amd/pm/swsmu/inc/smu_types.h  |  1 +
 .../drm/amd/pm/swsmu/smu13/smu_v13_0_0_ppt.c  | 51 +++++++++++++++-
 .../drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c  | 51 +++++++++++++++-
 8 files changed, 172 insertions(+), 2 deletions(-)
Documentation/gpu/amdgpu/thermal.rst +6 -0
index 073ab9e418b1..940f723472b8 100644
@@ -94,6 +94,12 @@ fan_target_temperature
 .. kernel-doc:: drivers/gpu/drm/amd/pm/amdgpu_pm.c
    :doc: fan_target_temperature
 
+fan_minimum_pwm
+---------------
+
+.. kernel-doc:: drivers/gpu/drm/amd/pm/amdgpu_pm.c
+   :doc: fan_minimum_pwm
+
 GFXOFF
 ======
 
drivers/gpu/drm/amd/include/kgd_pp_interface.h +2 -0
index c1065136f527..528c892f7c4b 100644
@@ -118,6 +118,7 @@ enum pp_clock_type {
        OD_ACOUSTIC_LIMIT,
        OD_ACOUSTIC_TARGET,
        OD_FAN_TARGET_TEMPERATURE,
+       OD_FAN_MINIMUM_PWM,
 };
 
 enum amd_pp_sensors {
@@ -197,6 +198,7 @@ enum PP_OD_DPM_TABLE_COMMAND {
        PP_OD_EDIT_ACOUSTIC_LIMIT,
        PP_OD_EDIT_ACOUSTIC_TARGET,
        PP_OD_EDIT_FAN_TARGET_TEMPERATURE,
+       PP_OD_EDIT_FAN_MINIMUM_PWM,
 };
 
 struct pp_states_info {
drivers/gpu/drm/amd/pm/amdgpu_pm.c +59 -0
index 682eef0c0eeb..fa6c4ab16ccf 100644
@@ -3772,6 +3772,57 @@ static umode_t fan_target_temperature_visible(struct amdgpu_device *adev)
        return umode;
 }
 
+/**
+ * DOC: fan_minimum_pwm
+ *
+ * The amdgpu driver provides a sysfs API for checking and adjusting the
+ * minimum fan speed in PWM.
+ *
+ * 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. NOTE: this will switch the fan control to auto mode.
+ */
+static ssize_t fan_minimum_pwm_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_FAN_MINIMUM_PWM, buf);
+}
+
+static ssize_t fan_minimum_pwm_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_FAN_MINIMUM_PWM,
+                                                            buf,
+                                                            count);
+}
+
+static umode_t fan_minimum_pwm_visible(struct amdgpu_device *adev)
+{
+       umode_t umode = 0000;
+
+       if (adev->pm.od_feature_mask & OD_OPS_SUPPORT_FAN_MINIMUM_PWM_RETRIEVE)
+               umode |= S_IRUSR | S_IRGRP | S_IROTH;
+
+       if (adev->pm.od_feature_mask & OD_OPS_SUPPORT_FAN_MINIMUM_PWM_SET)
+               umode |= S_IWUSR;
+
+       return umode;
+}
+
 static struct od_feature_set amdgpu_od_set = {
        .containers = {
                [0] = {
@@ -3817,6 +3868,14 @@ static struct od_feature_set amdgpu_od_set = {
                                                .store = fan_target_temperature_store,
                                        },
                                },
+                               [5] = {
+                                       .name = "fan_minimum_pwm",
+                                       .ops = {
+                                               .is_visible = fan_minimum_pwm_visible,
+                                               .show = fan_minimum_pwm_show,
+                                               .store = fan_minimum_pwm_store,
+                                       },
+                               },
                        },
                },
        },
drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h +2 -0
index 80d2ac1ecb9f..342c4d8318dc 100644
@@ -324,6 +324,8 @@ struct config_table_setting
 #define OD_OPS_SUPPORT_ACOUSTIC_TARGET_THRESHOLD_SET           BIT(7)
 #define OD_OPS_SUPPORT_FAN_TARGET_TEMPERATURE_RETRIEVE BIT(8)
 #define OD_OPS_SUPPORT_FAN_TARGET_TEMPERATURE_SET      BIT(9)
+#define OD_OPS_SUPPORT_FAN_MINIMUM_PWM_RETRIEVE                BIT(10)
+#define OD_OPS_SUPPORT_FAN_MINIMUM_PWM_SET             BIT(11)
 
 struct amdgpu_pm {
        struct mutex            mutex;
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +2 -0
index 22a6527139a6..d22ed5a272ce 100644
@@ -2491,6 +2491,8 @@ static enum smu_clk_type smu_convert_to_smuclk(enum pp_clock_type type)
                clk_type = SMU_OD_ACOUSTIC_TARGET; break;
        case OD_FAN_TARGET_TEMPERATURE:
                clk_type = SMU_OD_FAN_TARGET_TEMPERATURE; break;
+       case OD_FAN_MINIMUM_PWM:
+               clk_type = SMU_OD_FAN_MINIMUM_PWM; break;
        default:
                clk_type = SMU_CLK_COUNT; break;
        }
drivers/gpu/drm/amd/pm/swsmu/inc/smu_types.h +1 -0
index 1a00f807fb09..5c8f30f600f8 100644
@@ -285,6 +285,7 @@ enum smu_clk_type {
        SMU_OD_ACOUSTIC_LIMIT,
        SMU_OD_ACOUSTIC_TARGET,
        SMU_OD_FAN_TARGET_TEMPERATURE,
+       SMU_OD_FAN_MINIMUM_PWM,
        SMU_CLK_COUNT,
 };
 
drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_0_ppt.c +50 -1
index 953620f95abc..bedd9ca3605c 100644
@@ -107,6 +107,7 @@
 #define PP_OD_FEATURE_FAN_ACOUSTIC_LIMIT               8
 #define PP_OD_FEATURE_FAN_ACOUSTIC_TARGET              9
 #define PP_OD_FEATURE_FAN_TARGET_TEMPERATURE           10
+#define PP_OD_FEATURE_FAN_MINIMUM_PWM                  11
 
 #define LINK_SPEED_MAX                                 3
 
@@ -1140,6 +1141,10 @@ static void smu_v13_0_0_get_od_setting_limits(struct smu_context *smu,
                od_min_setting = overdrive_lowerlimits->FanTargetTemperature;
                od_max_setting = overdrive_upperlimits->FanTargetTemperature;
                break;
+       case PP_OD_FEATURE_FAN_MINIMUM_PWM:
+               od_min_setting = overdrive_lowerlimits->FanMinimumPwm;
+               od_max_setting = overdrive_upperlimits->FanMinimumPwm;
+               break;
        default:
                od_min_setting = od_max_setting = INT_MAX;
                break;
@@ -1452,6 +1457,24 @@ static int smu_v13_0_0_print_clk_levels(struct smu_context *smu,
                                      min_value, max_value);
                break;
 
+       case SMU_OD_FAN_MINIMUM_PWM:
+               if (!smu_v13_0_0_is_od_feature_supported(smu,
+                                                        PP_OD_FEATURE_FAN_CURVE_BIT))
+                       break;
+
+               size += sysfs_emit_at(buf, size, "FAN_MINIMUM_PWM:\n");
+               size += sysfs_emit_at(buf, size, "%d\n",
+                                       (int)od_table->OverDriveTable.FanMinimumPwm);
+
+               size += sysfs_emit_at(buf, size, "%s:\n", "OD_RANGE");
+               smu_v13_0_0_get_od_setting_limits(smu,
+                                                 PP_OD_FEATURE_FAN_MINIMUM_PWM,
+                                                 &min_value,
+                                                 &max_value);
+               size += sysfs_emit_at(buf, size, "MINIMUM_PWM: %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) &&
@@ -1766,6 +1789,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_FAN_MINIMUM_PWM:
+               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_MINIMUM_PWM,
+                                                 &minimum,
+                                                 &maximum);
+               if (input[0] < minimum ||
+                   input[0] > maximum) {
+                       dev_info(adev->dev, "fan minimum pwm setting(%ld) must be within [%d, %d]!\n",
+                                input[0], minimum, maximum);
+                       return -EINVAL;
+               }
+
+               od_table->OverDriveTable.FanMinimumPwm = 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,
@@ -2030,7 +2075,9 @@ static void smu_v13_0_0_set_supported_od_feature_mask(struct smu_context *smu)
                                            OD_OPS_SUPPORT_ACOUSTIC_TARGET_THRESHOLD_RETRIEVE |
                                            OD_OPS_SUPPORT_ACOUSTIC_TARGET_THRESHOLD_SET |
                                            OD_OPS_SUPPORT_FAN_TARGET_TEMPERATURE_RETRIEVE |
-                                           OD_OPS_SUPPORT_FAN_TARGET_TEMPERATURE_SET;
+                                           OD_OPS_SUPPORT_FAN_TARGET_TEMPERATURE_SET |
+                                           OD_OPS_SUPPORT_FAN_MINIMUM_PWM_RETRIEVE |
+                                           OD_OPS_SUPPORT_FAN_MINIMUM_PWM_SET;
 }
 
 static int smu_v13_0_0_set_default_od_settings(struct smu_context *smu)
@@ -2096,6 +2143,8 @@ static int smu_v13_0_0_set_default_od_settings(struct smu_context *smu)
                        user_od_table_bak.OverDriveTable.AcousticTargetRpmThreshold;
                user_od_table->OverDriveTable.FanTargetTemperature =
                        user_od_table_bak.OverDriveTable.FanTargetTemperature;
+               user_od_table->OverDriveTable.FanMinimumPwm =
+                       user_od_table_bak.OverDriveTable.FanMinimumPwm;
        }
 
        smu_v13_0_0_set_supported_od_feature_mask(smu);
drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c +50 -2
index a4d48ef5aaa7..c2ca5f228dd5 100644
@@ -83,6 +83,7 @@
 #define PP_OD_FEATURE_FAN_ACOUSTIC_LIMIT               8
 #define PP_OD_FEATURE_FAN_ACOUSTIC_TARGET              9
 #define PP_OD_FEATURE_FAN_TARGET_TEMPERATURE           10
+#define PP_OD_FEATURE_FAN_MINIMUM_PWM                  11
 
 #define LINK_SPEED_MAX                                 3
 
@@ -1126,6 +1127,10 @@ static void smu_v13_0_7_get_od_setting_limits(struct smu_context *smu,
                od_min_setting = overdrive_lowerlimits->FanTargetTemperature;
                od_max_setting = overdrive_upperlimits->FanTargetTemperature;
                break;
+       case PP_OD_FEATURE_FAN_MINIMUM_PWM:
+               od_min_setting = overdrive_lowerlimits->FanMinimumPwm;
+               od_max_setting = overdrive_upperlimits->FanMinimumPwm;
+               break;
        default:
                od_min_setting = od_max_setting = INT_MAX;
                break;
@@ -1438,6 +1443,24 @@ static int smu_v13_0_7_print_clk_levels(struct smu_context *smu,
                                      min_value, max_value);
                break;
 
+       case SMU_OD_FAN_MINIMUM_PWM:
+               if (!smu_v13_0_7_is_od_feature_supported(smu,
+                                                        PP_OD_FEATURE_FAN_CURVE_BIT))
+                       break;
+
+               size += sysfs_emit_at(buf, size, "FAN_MINIMUM_PWM:\n");
+               size += sysfs_emit_at(buf, size, "%d\n",
+                                       (int)od_table->OverDriveTable.FanMinimumPwm);
+
+               size += sysfs_emit_at(buf, size, "%s:\n", "OD_RANGE");
+               smu_v13_0_7_get_od_setting_limits(smu,
+                                                 PP_OD_FEATURE_FAN_MINIMUM_PWM,
+                                                 &min_value,
+                                                 &max_value);
+               size += sysfs_emit_at(buf, size, "MINIMUM_PWM: %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) &&
@@ -1752,6 +1775,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_FAN_MINIMUM_PWM:
+               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_MINIMUM_PWM,
+                                                 &minimum,
+                                                 &maximum);
+               if (input[0] < minimum ||
+                   input[0] > maximum) {
+                       dev_info(adev->dev, "fan minimum pwm setting(%ld) must be within [%d, %d]!\n",
+                                input[0], minimum, maximum);
+                       return -EINVAL;
+               }
+
+               od_table->OverDriveTable.FanMinimumPwm = 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,
@@ -2011,7 +2056,9 @@ static void smu_v13_0_7_set_supported_od_feature_mask(struct smu_context *smu)
                                            OD_OPS_SUPPORT_ACOUSTIC_TARGET_THRESHOLD_RETRIEVE |
                                            OD_OPS_SUPPORT_ACOUSTIC_TARGET_THRESHOLD_SET |
                                            OD_OPS_SUPPORT_FAN_TARGET_TEMPERATURE_RETRIEVE |
-                                           OD_OPS_SUPPORT_FAN_TARGET_TEMPERATURE_SET;
+                                           OD_OPS_SUPPORT_FAN_TARGET_TEMPERATURE_SET |
+                                           OD_OPS_SUPPORT_FAN_MINIMUM_PWM_RETRIEVE |
+                                           OD_OPS_SUPPORT_FAN_MINIMUM_PWM_SET;
 }
 
 static int smu_v13_0_7_set_default_od_settings(struct smu_context *smu)
@@ -2077,6 +2124,8 @@ static int smu_v13_0_7_set_default_od_settings(struct smu_context *smu)
                        user_od_table_bak.OverDriveTable.AcousticTargetRpmThreshold;
                user_od_table->OverDriveTable.FanTargetTemperature =
                        user_od_table_bak.OverDriveTable.FanTargetTemperature;
+               user_od_table->OverDriveTable.FanMinimumPwm =
+                       user_od_table_bak.OverDriveTable.FanMinimumPwm;
        }
 
        smu_v13_0_7_set_supported_od_feature_mask(smu);
--

2.34.1