AMD-GFX Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/7] drm/amd/pm: update pmfw headers for version 85.73.0
@ 2023-09-25  4:27 Le Ma
  2023-09-25  4:27 ` [PATCH 2/7] drm/amd/pm: add plpd_mode in smu_context to indicate current mode Le Ma
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: Le Ma @ 2023-09-25  4:27 UTC (permalink / raw)
  To: amd-gfx; +Cc: Alexander.Deucher, Lijo.Lazar, Asad Kamal, Hawking.Zhang

To add message to select PLPD mode.

Signed-off-by: Le Ma <le.ma@amd.com>
Reviewed-by: Asad Kamal <asad.kamal@amd.com>
---
 drivers/gpu/drm/amd/pm/swsmu/inc/pmfw_if/smu_v13_0_6_ppsmc.h | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/drivers/gpu/drm/amd/pm/swsmu/inc/pmfw_if/smu_v13_0_6_ppsmc.h b/drivers/gpu/drm/amd/pm/swsmu/inc/pmfw_if/smu_v13_0_6_ppsmc.h
index 021dcbe58473..509e3cd483fb 100644
--- a/drivers/gpu/drm/amd/pm/swsmu/inc/pmfw_if/smu_v13_0_6_ppsmc.h
+++ b/drivers/gpu/drm/amd/pm/swsmu/inc/pmfw_if/smu_v13_0_6_ppsmc.h
@@ -90,6 +90,7 @@
 #define PPSMC_MSG_ClearMcaOnRead                    0x39
 #define PPSMC_MSG_QueryValidMcaCeCount              0x3A
 #define PPSMC_MSG_McaBankCeDumpDW                   0x3B
+#define PPSMC_MSG_SelectPLPDMode                    0x40
 #define PPSMC_Message_Count                         0x41
 
 //PPSMC Reset Types for driver msg argument
@@ -107,6 +108,10 @@
 #define PPSMC_XCD_THM_TYPE                          0x3
 #define PPSMC_HBM_THM_TYPE                          0x4
 
+//PLPD modes
+#define PPSMC_PLPD_MODE_DEFAULT                     0x1
+#define PPSMC_PLPD_MODE_OPTIMIZED                   0x2
+
 typedef uint32_t PPSMC_Result;
 typedef uint32_t PPSMC_MSG;
 
-- 
2.38.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH 2/7] drm/amd/pm: add plpd_mode in smu_context to indicate current mode
  2023-09-25  4:27 [PATCH 1/7] drm/amd/pm: update pmfw headers for version 85.73.0 Le Ma
@ 2023-09-25  4:27 ` Le Ma
  2023-09-25  4:27 ` [PATCH 3/7] drm/amd/pm: add xgmi plpd mode selecting interface for smu v13.0.6 Le Ma
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Le Ma @ 2023-09-25  4:27 UTC (permalink / raw)
  To: amd-gfx; +Cc: Alexander.Deucher, Lijo.Lazar, Asad Kamal, Hawking.Zhang

Add enum pp_xgmi_plpd_mode to describe PLPD policies.

v2: move the enum from amdgpu_smu.h to kgd_pp_interface.h

Signed-off-by: Le Ma <le.ma@amd.com>
Reviewed-by: Asad Kamal <asad.kamal@amd.com>
---
 drivers/gpu/drm/amd/include/kgd_pp_interface.h | 8 ++++++++
 drivers/gpu/drm/amd/pm/swsmu/inc/amdgpu_smu.h  | 2 ++
 2 files changed, 10 insertions(+)

diff --git a/drivers/gpu/drm/amd/include/kgd_pp_interface.h b/drivers/gpu/drm/amd/include/kgd_pp_interface.h
index 5a889f733462..e0bb6d39f0c3 100644
--- a/drivers/gpu/drm/amd/include/kgd_pp_interface.h
+++ b/drivers/gpu/drm/amd/include/kgd_pp_interface.h
@@ -265,6 +265,14 @@ enum pp_power_type
 	PP_PWR_TYPE_FAST,
 };
 
+enum pp_xgmi_plpd_mode {
+	XGMI_PLPD_NONE = -1,
+	XGMI_PLPD_DISALLOW,
+	XGMI_PLPD_DEFAULT,
+	XGMI_PLPD_OPTIMIZED,
+	XGMI_PLPD_COUNT,
+};
+
 #define PP_GROUP_MASK        0xF0000000
 #define PP_GROUP_SHIFT       28
 
diff --git a/drivers/gpu/drm/amd/pm/swsmu/inc/amdgpu_smu.h b/drivers/gpu/drm/amd/pm/swsmu/inc/amdgpu_smu.h
index 5a52098bcf16..5356b91c6292 100644
--- a/drivers/gpu/drm/amd/pm/swsmu/inc/amdgpu_smu.h
+++ b/drivers/gpu/drm/amd/pm/swsmu/inc/amdgpu_smu.h
@@ -563,6 +563,8 @@ struct smu_context {
 	u32 debug_resp_reg;
 
 	struct delayed_work		swctf_delayed_work;
+
+	enum pp_xgmi_plpd_mode plpd_mode;
 };
 
 struct i2c_adapter;
-- 
2.38.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH 3/7] drm/amd/pm: add xgmi plpd mode selecting interface for smu v13.0.6
  2023-09-25  4:27 [PATCH 1/7] drm/amd/pm: update pmfw headers for version 85.73.0 Le Ma
  2023-09-25  4:27 ` [PATCH 2/7] drm/amd/pm: add plpd_mode in smu_context to indicate current mode Le Ma
@ 2023-09-25  4:27 ` Le Ma
  2023-09-25  4:27 ` [PATCH 4/7] drm/amd/pm: add xgmi_plpd_policy sysfs node for user to change plpd policy Le Ma
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Le Ma @ 2023-09-25  4:27 UTC (permalink / raw)
  To: amd-gfx; +Cc: Alexander.Deucher, Lijo.Lazar, Asad Kamal, Hawking.Zhang

Add the interface to change xgmi per-link power down policy.

v2: split from sysfs interface code and miscellaneous updates
v3: check against XGMI_PLPD_DEFAULT/XGMI_PLPD_OPTIMIZED and pass PPSMC param

Signed-off-by: Le Ma <le.ma@amd.com>
Reviewed-by: Asad Kamal <asad.kamal@amd.com>
---
 drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c     | 24 ++++++++++++++
 drivers/gpu/drm/amd/pm/swsmu/inc/amdgpu_smu.h |  9 ++++++
 drivers/gpu/drm/amd/pm/swsmu/inc/smu_types.h  |  3 +-
 .../drm/amd/pm/swsmu/smu13/smu_v13_0_6_ppt.c  | 31 +++++++++++++++++++
 4 files changed, 66 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c b/drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c
index e6f1620acdd4..893359b26418 100644
--- a/drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c
+++ b/drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c
@@ -3157,6 +3157,30 @@ static int smu_get_prv_buffer_details(void *handle, void **addr, size_t *size)
 	return 0;
 }
 
+int smu_set_xgmi_plpd_mode(struct smu_context *smu,
+			   enum pp_xgmi_plpd_mode mode)
+{
+	int ret = -EOPNOTSUPP;
+
+	if (!smu->pm_enabled || !smu->adev->pm.dpm_enabled)
+		return ret;
+
+	/* PLPD policy is not supported if it's NONE */
+	if (smu->plpd_mode == XGMI_PLPD_NONE)
+		return ret;
+
+	if (smu->plpd_mode == mode)
+		return 0;
+
+	if (smu->ppt_funcs && smu->ppt_funcs->select_xgmi_plpd_policy)
+		ret = smu->ppt_funcs->select_xgmi_plpd_policy(smu, mode);
+
+	if (!ret)
+		smu->plpd_mode = mode;
+
+	return ret;
+}
+
 static const struct amd_pm_funcs swsmu_pm_funcs = {
 	/* export for sysfs */
 	.set_fan_control_mode    = smu_set_fan_control_mode,
diff --git a/drivers/gpu/drm/amd/pm/swsmu/inc/amdgpu_smu.h b/drivers/gpu/drm/amd/pm/swsmu/inc/amdgpu_smu.h
index 5356b91c6292..e17169f681e8 100644
--- a/drivers/gpu/drm/amd/pm/swsmu/inc/amdgpu_smu.h
+++ b/drivers/gpu/drm/amd/pm/swsmu/inc/amdgpu_smu.h
@@ -840,6 +840,12 @@ struct pptable_funcs {
 	 */
 	int (*allow_xgmi_power_down)(struct smu_context *smu, bool en);
 
+	/**
+	 * @select_xgmi_plpd_policy: Select xgmi per-link power down policy.
+	 */
+	int (*select_xgmi_plpd_policy)(struct smu_context *smu,
+				       enum pp_xgmi_plpd_mode mode);
+
 	/**
 	 * @update_pcie_parameters: Update and upload the system's PCIe
 	 *                          capabilites to the SMU.
@@ -1487,6 +1493,9 @@ int smu_set_ac_dc(struct smu_context *smu);
 
 int smu_allow_xgmi_power_down(struct smu_context *smu, bool en);
 
+int smu_set_xgmi_plpd_mode(struct smu_context *smu,
+			   enum pp_xgmi_plpd_mode mode);
+
 int smu_get_entrycount_gfxoff(struct smu_context *smu, u64 *value);
 
 int smu_get_residency_gfxoff(struct smu_context *smu, u32 *value);
diff --git a/drivers/gpu/drm/amd/pm/swsmu/inc/smu_types.h b/drivers/gpu/drm/amd/pm/swsmu/inc/smu_types.h
index 7c300b4d95c7..4850e48bbef5 100644
--- a/drivers/gpu/drm/amd/pm/swsmu/inc/smu_types.h
+++ b/drivers/gpu/drm/amd/pm/swsmu/inc/smu_types.h
@@ -252,7 +252,8 @@
 	__SMU_DUMMY_MAP(QueryValidMcaCount),	\
 	__SMU_DUMMY_MAP(QueryValidMcaCeCount),	\
 	__SMU_DUMMY_MAP(McaBankDumpDW),		\
-	__SMU_DUMMY_MAP(McaBankCeDumpDW),
+	__SMU_DUMMY_MAP(McaBankCeDumpDW),	\
+	__SMU_DUMMY_MAP(SelectPLPDMode),
 
 #undef __SMU_DUMMY_MAP
 #define __SMU_DUMMY_MAP(type)	SMU_MSG_##type
diff --git a/drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_6_ppt.c b/drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_6_ppt.c
index 11a6cd96c601..b137c37903fc 100644
--- a/drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_6_ppt.c
+++ b/drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_6_ppt.c
@@ -170,6 +170,7 @@ static const struct cmn2asic_msg_mapping smu_v13_0_6_message_map[SMU_MSG_MAX_COU
 	MSG_MAP(QueryValidMcaCeCount,                PPSMC_MSG_QueryValidMcaCeCount,            0),
 	MSG_MAP(McaBankDumpDW,                       PPSMC_MSG_McaBankDumpDW,                   0),
 	MSG_MAP(McaBankCeDumpDW,                     PPSMC_MSG_McaBankCeDumpDW,                 0),
+	MSG_MAP(SelectPLPDMode,                      PPSMC_MSG_SelectPLPDMode,                  0),
 };
 
 static const struct cmn2asic_mapping smu_v13_0_6_clk_map[SMU_CLK_COUNT] = {
@@ -2716,6 +2717,35 @@ static const struct amdgpu_mca_smu_funcs smu_v13_0_6_mca_smu_funcs = {
 	.mca_get_ras_mca_idx_array = mca_smu_get_ras_mca_idx_array,
 };
 
+static int smu_v13_0_6_select_xgmi_plpd_policy(struct smu_context *smu,
+					       enum pp_xgmi_plpd_mode mode)
+{
+	struct amdgpu_device *adev = smu->adev;
+	int ret, param;
+
+	switch (mode) {
+	case XGMI_PLPD_DEFAULT:
+		param = PPSMC_PLPD_MODE_DEFAULT;
+		break;
+	case XGMI_PLPD_OPTIMIZED:
+		param = PPSMC_PLPD_MODE_OPTIMIZED;
+		break;
+	default:
+		return -EINVAL;
+	}
+
+	/* change xgmi per-link power down policy */
+	ret = smu_cmn_send_smc_msg_with_param(
+		smu, SMU_MSG_SelectPLPDMode, param, NULL);
+
+	if (ret)
+		dev_err(adev->dev,
+			"select xgmi per-link power down policy %d failed\n",
+			mode);
+
+	return ret;
+}
+
 static const struct pptable_funcs smu_v13_0_6_ppt_funcs = {
 	/* init dpm */
 	.get_allowed_feature_mask = smu_v13_0_6_get_allowed_feature_mask,
@@ -2756,6 +2786,7 @@ static const struct pptable_funcs smu_v13_0_6_ppt_funcs = {
 	.od_edit_dpm_table = smu_v13_0_6_usr_edit_dpm_table,
 	.set_df_cstate = smu_v13_0_6_set_df_cstate,
 	.allow_xgmi_power_down = smu_v13_0_6_allow_xgmi_power_down,
+	.select_xgmi_plpd_policy = smu_v13_0_6_select_xgmi_plpd_policy,
 	.log_thermal_throttling_event = smu_v13_0_6_log_thermal_throttling_event,
 	.get_pp_feature_mask = smu_cmn_get_pp_feature_mask,
 	.get_gpu_metrics = smu_v13_0_6_get_gpu_metrics,
-- 
2.38.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH 4/7] drm/amd/pm: add xgmi_plpd_policy sysfs node for user to change plpd policy
  2023-09-25  4:27 [PATCH 1/7] drm/amd/pm: update pmfw headers for version 85.73.0 Le Ma
  2023-09-25  4:27 ` [PATCH 2/7] drm/amd/pm: add plpd_mode in smu_context to indicate current mode Le Ma
  2023-09-25  4:27 ` [PATCH 3/7] drm/amd/pm: add xgmi plpd mode selecting interface for smu v13.0.6 Le Ma
@ 2023-09-25  4:27 ` Le Ma
  2023-09-25  4:27 ` [PATCH 5/7] drm/amd/pm: init plpd_mode properly for different asics Le Ma
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Le Ma @ 2023-09-25  4:27 UTC (permalink / raw)
  To: amd-gfx; +Cc: Alexander.Deucher, Lijo.Lazar, Asad Kamal, Hawking.Zhang

Add xgmi_plpd_policy sysfs node for users to check and select xgmi
per-link power down policy:
  - arg 0: disallow plpd
  - arg 1: default policy
  - arg 2: optimized policy

v2: split from smu v13.0.6 code and miscellaneous updates
v3: add usage comments around set/get functions

Signed-off-by: Le Ma <le.ma@amd.com>
Reviewed-by: Asad Kamal <asad.kamal@amd.com>
---
 drivers/gpu/drm/amd/pm/amdgpu_dpm.c     | 43 ++++++++++++++++
 drivers/gpu/drm/amd/pm/amdgpu_pm.c      | 68 +++++++++++++++++++++++++
 drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h |  5 ++
 3 files changed, 116 insertions(+)

diff --git a/drivers/gpu/drm/amd/pm/amdgpu_dpm.c b/drivers/gpu/drm/amd/pm/amdgpu_dpm.c
index 078aaaa53162..9a157fe4cbc7 100644
--- a/drivers/gpu/drm/amd/pm/amdgpu_dpm.c
+++ b/drivers/gpu/drm/amd/pm/amdgpu_dpm.c
@@ -365,6 +365,49 @@ int amdgpu_dpm_allow_xgmi_power_down(struct amdgpu_device *adev, bool en)
 	return ret;
 }
 
+int amdgpu_dpm_get_xgmi_plpd_mode(struct amdgpu_device *adev, char **mode_desc)
+{
+	struct smu_context *smu = adev->powerplay.pp_handle;
+	int mode = XGMI_PLPD_NONE;
+
+	if (is_support_sw_smu(adev)) {
+		mode = smu->plpd_mode;
+		if (mode_desc == NULL)
+			return mode;
+		switch (smu->plpd_mode) {
+		case XGMI_PLPD_DISALLOW:
+			*mode_desc = "disallow";
+			break;
+		case XGMI_PLPD_DEFAULT:
+			*mode_desc = "default";
+			break;
+		case XGMI_PLPD_OPTIMIZED:
+			*mode_desc = "optimized";
+			break;
+		case XGMI_PLPD_NONE:
+		default:
+			*mode_desc = "none";
+			break;
+		}
+	}
+
+	return mode;
+}
+
+int amdgpu_dpm_set_xgmi_plpd_mode(struct amdgpu_device *adev, int mode)
+{
+	struct smu_context *smu = adev->powerplay.pp_handle;
+	int ret = -EOPNOTSUPP;
+
+	if (is_support_sw_smu(adev)) {
+		mutex_lock(&adev->pm.mutex);
+		ret = smu_set_xgmi_plpd_mode(smu, mode);
+		mutex_unlock(&adev->pm.mutex);
+	}
+
+	return ret;
+}
+
 int amdgpu_dpm_enable_mgpu_fan_boost(struct amdgpu_device *adev)
 {
 	void *pp_handle = adev->powerplay.pp_handle;
diff --git a/drivers/gpu/drm/amd/pm/amdgpu_pm.c b/drivers/gpu/drm/amd/pm/amdgpu_pm.c
index 2807f3bd9ebe..745f5b6a2826 100644
--- a/drivers/gpu/drm/amd/pm/amdgpu_pm.c
+++ b/drivers/gpu/drm/amd/pm/amdgpu_pm.c
@@ -1991,6 +1991,70 @@ static int ss_bias_attr_update(struct amdgpu_device *adev, struct amdgpu_device_
 	return 0;
 }
 
+/* Following items will be read out to indicate current plpd policy:
+ *  - -1: none
+ *  - 0: disallow
+ *  - 1: default
+ *  - 2: optimized
+ */
+static ssize_t amdgpu_get_xgmi_plpd_policy(struct device *dev,
+					   struct device_attribute *attr,
+					   char *buf)
+{
+	struct drm_device *ddev = dev_get_drvdata(dev);
+	struct amdgpu_device *adev = drm_to_adev(ddev);
+	char *mode_desc = "none";
+	int mode;
+
+	if (amdgpu_in_reset(adev))
+		return -EPERM;
+	if (adev->in_suspend && !adev->in_runpm)
+		return -EPERM;
+
+	mode = amdgpu_dpm_get_xgmi_plpd_mode(adev, &mode_desc);
+
+	return sysfs_emit(buf, "%d: %s\n", mode, mode_desc);
+}
+
+/* Following argument value is expected from user to change plpd policy
+ *  - arg 0: disallow plpd
+ *  - arg 1: default policy
+ *  - arg 2: optimized policy
+ */
+static ssize_t amdgpu_set_xgmi_plpd_policy(struct device *dev,
+					   struct device_attribute *attr,
+					   const char *buf, size_t count)
+{
+	struct drm_device *ddev = dev_get_drvdata(dev);
+	struct amdgpu_device *adev = drm_to_adev(ddev);
+	int mode, ret;
+
+	if (amdgpu_in_reset(adev))
+		return -EPERM;
+	if (adev->in_suspend && !adev->in_runpm)
+		return -EPERM;
+
+	ret = kstrtos32(buf, 0, &mode);
+	if (ret)
+		return -EINVAL;
+
+	ret = pm_runtime_get_sync(ddev->dev);
+	if (ret < 0) {
+		pm_runtime_put_autosuspend(ddev->dev);
+		return ret;
+	}
+
+	ret = amdgpu_dpm_set_xgmi_plpd_mode(adev, mode);
+
+	pm_runtime_mark_last_busy(ddev->dev);
+	pm_runtime_put_autosuspend(ddev->dev);
+
+	if (ret)
+		return ret;
+
+	return count;
+}
+
 static struct amdgpu_device_attr amdgpu_device_attrs[] = {
 	AMDGPU_DEVICE_ATTR_RW(power_dpm_state,				ATTR_FLAG_BASIC|ATTR_FLAG_ONEVF),
 	AMDGPU_DEVICE_ATTR_RW(power_dpm_force_performance_level,	ATTR_FLAG_BASIC|ATTR_FLAG_ONEVF),
@@ -2026,6 +2090,7 @@ static struct amdgpu_device_attr amdgpu_device_attrs[] = {
 			      .attr_update = ss_power_attr_update),
 	AMDGPU_DEVICE_ATTR_RW(smartshift_bias,				ATTR_FLAG_BASIC,
 			      .attr_update = ss_bias_attr_update),
+	AMDGPU_DEVICE_ATTR_RW(xgmi_plpd_policy,				ATTR_FLAG_BASIC),
 };
 
 static int default_attr_update(struct amdgpu_device *adev, struct amdgpu_device_attr *attr,
@@ -2123,6 +2188,9 @@ static int default_attr_update(struct amdgpu_device *adev, struct amdgpu_device_
 			*states = ATTR_STATE_UNSUPPORTED;
 		else if (gc_ver == IP_VERSION(10, 3, 0) && amdgpu_sriov_vf(adev))
 			*states = ATTR_STATE_UNSUPPORTED;
+	} else if (DEVICE_ATTR_IS(xgmi_plpd_policy)) {
+		if (amdgpu_dpm_get_xgmi_plpd_mode(adev, NULL) == XGMI_PLPD_NONE)
+			*states = ATTR_STATE_UNSUPPORTED;
 	}
 
 	switch (gc_ver) {
diff --git a/drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h b/drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h
index 5efdba6e358f..564494f29717 100644
--- a/drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h
+++ b/drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h
@@ -426,6 +426,11 @@ int amdgpu_dpm_set_df_cstate(struct amdgpu_device *adev,
 
 int amdgpu_dpm_allow_xgmi_power_down(struct amdgpu_device *adev, bool en);
 
+int amdgpu_dpm_get_xgmi_plpd_mode(struct amdgpu_device *adev,
+				  char **mode);
+
+int amdgpu_dpm_set_xgmi_plpd_mode(struct amdgpu_device *adev, int mode);
+
 int amdgpu_dpm_enable_mgpu_fan_boost(struct amdgpu_device *adev);
 
 int amdgpu_dpm_set_clockgating_by_smu(struct amdgpu_device *adev,
-- 
2.38.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH 5/7] drm/amd/pm: init plpd_mode properly for different asics
  2023-09-25  4:27 [PATCH 1/7] drm/amd/pm: update pmfw headers for version 85.73.0 Le Ma
                   ` (2 preceding siblings ...)
  2023-09-25  4:27 ` [PATCH 4/7] drm/amd/pm: add xgmi_plpd_policy sysfs node for user to change plpd policy Le Ma
@ 2023-09-25  4:27 ` Le Ma
  2023-09-25  4:27 ` [PATCH 6/7] drm/amd/pm: integrate plpd allow/disallow into select_xgmi_plpd_policy in ppt level Le Ma
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Le Ma @ 2023-09-25  4:27 UTC (permalink / raw)
  To: amd-gfx; +Cc: Alexander.Deucher, Lijo.Lazar, Hawking.Zhang

Assign DEFAULT mode if it supports plpd, otherwise keeps NONE

v2: reduce ip version checks

Signed-off-by: Le Ma <le.ma@amd.com>
---
 drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c b/drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c
index 893359b26418..1c6b22638bf4 100644
--- a/drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c
+++ b/drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c
@@ -1130,6 +1130,21 @@ static void smu_swctf_delayed_work_handler(struct work_struct *work)
 	orderly_poweroff(true);
 }
 
+static void smu_init_xgmi_plpd_mode(struct smu_context *smu)
+{
+	if (amdgpu_ip_version(smu->adev, MP1_HWIP, 0) == IP_VERSION(11, 0, 2)) {
+		smu->plpd_mode = XGMI_PLPD_DEFAULT;
+		return;
+	}
+
+	/* PMFW put PLPD into default policy after enabling the feature */
+	if (smu_feature_is_enabled(smu,
+				   SMU_FEATURE_XGMI_PER_LINK_PWR_DWN_BIT))
+		smu->plpd_mode = XGMI_PLPD_DEFAULT;
+	else
+		smu->plpd_mode = XGMI_PLPD_NONE;
+}
+
 static int smu_sw_init(void *handle)
 {
 	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
@@ -1361,6 +1376,8 @@ static int smu_smc_hw_setup(struct smu_context *smu)
 		return ret;
 	}
 
+	smu_init_xgmi_plpd_mode(smu);
+
 	ret = smu_feature_get_enabled_mask(smu, &features_supported);
 	if (ret) {
 		dev_err(adev->dev, "Failed to retrieve supported dpm features!\n");
-- 
2.38.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH 6/7] drm/amd/pm: integrate plpd allow/disallow into select_xgmi_plpd_policy in ppt level
  2023-09-25  4:27 [PATCH 1/7] drm/amd/pm: update pmfw headers for version 85.73.0 Le Ma
                   ` (3 preceding siblings ...)
  2023-09-25  4:27 ` [PATCH 5/7] drm/amd/pm: init plpd_mode properly for different asics Le Ma
@ 2023-09-25  4:27 ` Le Ma
  2023-09-25  4:27 ` [PATCH 7/7] drm/amd/pm: deprecate allow_xgmi_power_down interface Le Ma
  2023-09-26  5:51 ` [PATCH 1/7] drm/amd/pm: update pmfw headers for version 85.73.0 Lazar, Lijo
  6 siblings, 0 replies; 8+ messages in thread
From: Le Ma @ 2023-09-25  4:27 UTC (permalink / raw)
  To: amd-gfx; +Cc: Alexander.Deucher, Lijo.Lazar, Hawking.Zhang

The allow_xgmi_power_down(true/false) will be generally replaced by:
  - allow: select_xgmi_plpd_policy(XGMI_PLPD_DEFAULT)
  - disallow: select_xgmi_plpd_policy(XGMI_PLPD_DISALLOW)

Signed-off-by: Le Ma <le.ma@amd.com>
---
 .../gpu/drm/amd/pm/swsmu/smu11/arcturus_ppt.c | 21 +++++++++--------
 .../drm/amd/pm/swsmu/smu13/aldebaran_ppt.c    | 23 ++++++++++++-------
 .../drm/amd/pm/swsmu/smu13/smu_v13_0_6_ppt.c  | 22 ++++++++++--------
 3 files changed, 38 insertions(+), 28 deletions(-)

diff --git a/drivers/gpu/drm/amd/pm/swsmu/smu11/arcturus_ppt.c b/drivers/gpu/drm/amd/pm/swsmu/smu11/arcturus_ppt.c
index 080140a0f673..6e2e665ad383 100644
--- a/drivers/gpu/drm/amd/pm/swsmu/smu11/arcturus_ppt.c
+++ b/drivers/gpu/drm/amd/pm/swsmu/smu11/arcturus_ppt.c
@@ -2227,7 +2227,8 @@ static int arcturus_set_df_cstate(struct smu_context *smu,
 	return smu_cmn_send_smc_msg_with_param(smu, SMU_MSG_DFCstateControl, state, NULL);
 }
 
-static int arcturus_allow_xgmi_power_down(struct smu_context *smu, bool en)
+static int arcturus_select_xgmi_plpd_policy(struct smu_context *smu,
+					    enum pp_xgmi_plpd_mode mode)
 {
 	uint32_t smu_version;
 	int ret;
@@ -2244,16 +2245,16 @@ static int arcturus_allow_xgmi_power_down(struct smu_context *smu, bool en)
 		return -EINVAL;
 	}
 
-	if (en)
+	if (mode == XGMI_PLPD_DEFAULT)
 		return smu_cmn_send_smc_msg_with_param(smu,
 						   SMU_MSG_GmiPwrDnControl,
-						   1,
-						   NULL);
-
-	return smu_cmn_send_smc_msg_with_param(smu,
-					   SMU_MSG_GmiPwrDnControl,
-					   0,
-					   NULL);
+						   1, NULL);
+	else if (mode == XGMI_PLPD_DISALLOW)
+		return smu_cmn_send_smc_msg_with_param(smu,
+						   SMU_MSG_GmiPwrDnControl,
+						   0, NULL);
+	else
+		return -EINVAL;
 }
 
 static const struct throttling_logging_label {
@@ -2455,7 +2456,7 @@ static const struct pptable_funcs arcturus_ppt_funcs = {
 	.get_dpm_ultimate_freq = smu_v11_0_get_dpm_ultimate_freq,
 	.set_soft_freq_limited_range = smu_v11_0_set_soft_freq_limited_range,
 	.set_df_cstate = arcturus_set_df_cstate,
-	.allow_xgmi_power_down = arcturus_allow_xgmi_power_down,
+	.select_xgmi_plpd_policy = arcturus_select_xgmi_plpd_policy,
 	.log_thermal_throttling_event = arcturus_log_thermal_throttling_event,
 	.get_pp_feature_mask = smu_cmn_get_pp_feature_mask,
 	.set_pp_feature_mask = smu_cmn_set_pp_feature_mask,
diff --git a/drivers/gpu/drm/amd/pm/swsmu/smu13/aldebaran_ppt.c b/drivers/gpu/drm/amd/pm/swsmu/smu13/aldebaran_ppt.c
index 23820204efd7..b57184a3e24f 100644
--- a/drivers/gpu/drm/amd/pm/swsmu/smu13/aldebaran_ppt.c
+++ b/drivers/gpu/drm/amd/pm/swsmu/smu13/aldebaran_ppt.c
@@ -1604,20 +1604,27 @@ static int aldebaran_set_df_cstate(struct smu_context *smu,
 	return smu_cmn_send_smc_msg_with_param(smu, SMU_MSG_DFCstateControl, state, NULL);
 }
 
-static int aldebaran_allow_xgmi_power_down(struct smu_context *smu, bool en)
+static int aldebaran_select_xgmi_plpd_policy(struct smu_context *smu,
+					     enum pp_xgmi_plpd_mode mode)
 {
 	struct amdgpu_device *adev = smu->adev;
 
 	/* The message only works on master die and NACK will be sent
 	   back for other dies, only send it on master die */
-	if (!adev->smuio.funcs->get_socket_id(adev) &&
-	    !adev->smuio.funcs->get_die_id(adev))
+	if (adev->smuio.funcs->get_socket_id(adev) ||
+	    adev->smuio.funcs->get_die_id(adev))
+		return 0;
+
+	if (mode == XGMI_PLPD_DEFAULT)
+		return smu_cmn_send_smc_msg_with_param(smu,
+						       SMU_MSG_GmiPwrDnControl,
+						       0, NULL);
+	else if (mode == XGMI_PLPD_DISALLOW)
 		return smu_cmn_send_smc_msg_with_param(smu,
-				   SMU_MSG_GmiPwrDnControl,
-				   en ? 0 : 1,
-				   NULL);
+						       SMU_MSG_GmiPwrDnControl,
+						       1, NULL);
 	else
-		return 0;
+		return -EINVAL;
 }
 
 static const struct throttling_logging_label {
@@ -2072,7 +2079,7 @@ static const struct pptable_funcs aldebaran_ppt_funcs = {
 	.set_soft_freq_limited_range = aldebaran_set_soft_freq_limited_range,
 	.od_edit_dpm_table = aldebaran_usr_edit_dpm_table,
 	.set_df_cstate = aldebaran_set_df_cstate,
-	.allow_xgmi_power_down = aldebaran_allow_xgmi_power_down,
+	.select_xgmi_plpd_policy = aldebaran_select_xgmi_plpd_policy,
 	.log_thermal_throttling_event = aldebaran_log_thermal_throttling_event,
 	.get_pp_feature_mask = smu_cmn_get_pp_feature_mask,
 	.set_pp_feature_mask = smu_cmn_set_pp_feature_mask,
diff --git a/drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_6_ppt.c b/drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_6_ppt.c
index b137c37903fc..c20537fb9df0 100644
--- a/drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_6_ppt.c
+++ b/drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_6_ppt.c
@@ -1897,12 +1897,6 @@ static int smu_v13_0_6_set_df_cstate(struct smu_context *smu,
 					       state, NULL);
 }
 
-static int smu_v13_0_6_allow_xgmi_power_down(struct smu_context *smu, bool en)
-{
-	return smu_cmn_send_smc_msg_with_param(smu, SMU_MSG_GmiPwrDnControl,
-					       en ? 0 : 1, NULL);
-}
-
 static const char *const throttling_logging_label[] = {
 	[THROTTLER_PROCHOT_BIT] = "Prochot",
 	[THROTTLER_PPT_BIT] = "PPT",
@@ -2730,13 +2724,22 @@ static int smu_v13_0_6_select_xgmi_plpd_policy(struct smu_context *smu,
 	case XGMI_PLPD_OPTIMIZED:
 		param = PPSMC_PLPD_MODE_OPTIMIZED;
 		break;
+	case XGMI_PLPD_DISALLOW:
+		param = 0;
+		break;
 	default:
 		return -EINVAL;
 	}
 
-	/* change xgmi per-link power down policy */
-	ret = smu_cmn_send_smc_msg_with_param(
-		smu, SMU_MSG_SelectPLPDMode, param, NULL);
+	if (mode == XGMI_PLPD_DISALLOW)
+		ret = smu_cmn_send_smc_msg_with_param(smu,
+						      SMU_MSG_GmiPwrDnControl,
+						      param, NULL);
+	else
+		/* change xgmi per-link power down policy */
+		ret = smu_cmn_send_smc_msg_with_param(smu,
+						      SMU_MSG_SelectPLPDMode,
+						      param, NULL);
 
 	if (ret)
 		dev_err(adev->dev,
@@ -2785,7 +2788,6 @@ static const struct pptable_funcs smu_v13_0_6_ppt_funcs = {
 	.set_soft_freq_limited_range = smu_v13_0_6_set_soft_freq_limited_range,
 	.od_edit_dpm_table = smu_v13_0_6_usr_edit_dpm_table,
 	.set_df_cstate = smu_v13_0_6_set_df_cstate,
-	.allow_xgmi_power_down = smu_v13_0_6_allow_xgmi_power_down,
 	.select_xgmi_plpd_policy = smu_v13_0_6_select_xgmi_plpd_policy,
 	.log_thermal_throttling_event = smu_v13_0_6_log_thermal_throttling_event,
 	.get_pp_feature_mask = smu_cmn_get_pp_feature_mask,
-- 
2.38.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH 7/7] drm/amd/pm: deprecate allow_xgmi_power_down interface
  2023-09-25  4:27 [PATCH 1/7] drm/amd/pm: update pmfw headers for version 85.73.0 Le Ma
                   ` (4 preceding siblings ...)
  2023-09-25  4:27 ` [PATCH 6/7] drm/amd/pm: integrate plpd allow/disallow into select_xgmi_plpd_policy in ppt level Le Ma
@ 2023-09-25  4:27 ` Le Ma
  2023-09-26  5:51 ` [PATCH 1/7] drm/amd/pm: update pmfw headers for version 85.73.0 Lazar, Lijo
  6 siblings, 0 replies; 8+ messages in thread
From: Le Ma @ 2023-09-25  4:27 UTC (permalink / raw)
  To: amd-gfx; +Cc: Alexander.Deucher, Lijo.Lazar, Hawking.Zhang

Replace with set_plpd_mode uniformly for places to use.

Signed-off-by: Le Ma <le.ma@amd.com>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.c      |  4 ++--
 drivers/gpu/drm/amd/pm/amdgpu_dpm.c           | 14 --------------
 drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h       |  2 --
 drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c     | 17 -----------------
 drivers/gpu/drm/amd/pm/swsmu/inc/amdgpu_smu.h |  8 --------
 5 files changed, 2 insertions(+), 43 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.c
index 061534e845a7..1fb3f1ecfa7d 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.c
@@ -1072,7 +1072,7 @@ static int amdgpu_ras_error_inject_xgmi(struct amdgpu_device *adev,
 	if (amdgpu_dpm_set_df_cstate(adev, DF_CSTATE_DISALLOW))
 		dev_warn(adev->dev, "Failed to disallow df cstate");
 
-	if (amdgpu_dpm_allow_xgmi_power_down(adev, false))
+	if (amdgpu_dpm_set_xgmi_plpd_mode(adev, XGMI_PLPD_DISALLOW))
 		dev_warn(adev->dev, "Failed to disallow XGMI power down");
 
 	ret = psp_ras_trigger_error(&adev->psp, block_info, instance_mask);
@@ -1080,7 +1080,7 @@ static int amdgpu_ras_error_inject_xgmi(struct amdgpu_device *adev,
 	if (amdgpu_ras_intr_triggered())
 		return ret;
 
-	if (amdgpu_dpm_allow_xgmi_power_down(adev, true))
+	if (amdgpu_dpm_set_xgmi_plpd_mode(adev, XGMI_PLPD_DEFAULT))
 		dev_warn(adev->dev, "Failed to allow XGMI power down");
 
 	if (amdgpu_dpm_set_df_cstate(adev, DF_CSTATE_ALLOW))
diff --git a/drivers/gpu/drm/amd/pm/amdgpu_dpm.c b/drivers/gpu/drm/amd/pm/amdgpu_dpm.c
index 9a157fe4cbc7..1b17a71ed45e 100644
--- a/drivers/gpu/drm/amd/pm/amdgpu_dpm.c
+++ b/drivers/gpu/drm/amd/pm/amdgpu_dpm.c
@@ -351,20 +351,6 @@ int amdgpu_dpm_set_df_cstate(struct amdgpu_device *adev,
 	return ret;
 }
 
-int amdgpu_dpm_allow_xgmi_power_down(struct amdgpu_device *adev, bool en)
-{
-	struct smu_context *smu = adev->powerplay.pp_handle;
-	int ret = 0;
-
-	if (is_support_sw_smu(adev)) {
-		mutex_lock(&adev->pm.mutex);
-		ret = smu_allow_xgmi_power_down(smu, en);
-		mutex_unlock(&adev->pm.mutex);
-	}
-
-	return ret;
-}
-
 int amdgpu_dpm_get_xgmi_plpd_mode(struct amdgpu_device *adev, char **mode_desc)
 {
 	struct smu_context *smu = adev->powerplay.pp_handle;
diff --git a/drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h b/drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h
index 564494f29717..feccd2a7120d 100644
--- a/drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h
+++ b/drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h
@@ -424,8 +424,6 @@ int amdgpu_dpm_baco_enter(struct amdgpu_device *adev);
 int amdgpu_dpm_set_df_cstate(struct amdgpu_device *adev,
 			     uint32_t cstate);
 
-int amdgpu_dpm_allow_xgmi_power_down(struct amdgpu_device *adev, bool en);
-
 int amdgpu_dpm_get_xgmi_plpd_mode(struct amdgpu_device *adev,
 				  char **mode);
 
diff --git a/drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c b/drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c
index 1c6b22638bf4..33eaf0d77163 100644
--- a/drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c
+++ b/drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c
@@ -2178,23 +2178,6 @@ static int smu_set_df_cstate(void *handle,
 	return ret;
 }
 
-int smu_allow_xgmi_power_down(struct smu_context *smu, bool en)
-{
-	int ret = 0;
-
-	if (!smu->pm_enabled || !smu->adev->pm.dpm_enabled)
-		return -EOPNOTSUPP;
-
-	if (!smu->ppt_funcs || !smu->ppt_funcs->allow_xgmi_power_down)
-		return 0;
-
-	ret = smu->ppt_funcs->allow_xgmi_power_down(smu, en);
-	if (ret)
-		dev_err(smu->adev->dev, "[AllowXgmiPowerDown] failed!\n");
-
-	return ret;
-}
-
 int smu_write_watermarks_table(struct smu_context *smu)
 {
 	if (!smu->pm_enabled || !smu->adev->pm.dpm_enabled)
diff --git a/drivers/gpu/drm/amd/pm/swsmu/inc/amdgpu_smu.h b/drivers/gpu/drm/amd/pm/swsmu/inc/amdgpu_smu.h
index e17169f681e8..4f6df3558b9b 100644
--- a/drivers/gpu/drm/amd/pm/swsmu/inc/amdgpu_smu.h
+++ b/drivers/gpu/drm/amd/pm/swsmu/inc/amdgpu_smu.h
@@ -834,12 +834,6 @@ struct pptable_funcs {
 	 */
 	int (*set_df_cstate)(struct smu_context *smu, enum pp_df_cstate state);
 
-	/**
-	 * @allow_xgmi_power_down: Enable/disable external global memory
-	 *                         interconnect power down.
-	 */
-	int (*allow_xgmi_power_down)(struct smu_context *smu, bool en);
-
 	/**
 	 * @select_xgmi_plpd_policy: Select xgmi per-link power down policy.
 	 */
@@ -1491,8 +1485,6 @@ int smu_set_gfx_power_up_by_imu(struct smu_context *smu);
 
 int smu_set_ac_dc(struct smu_context *smu);
 
-int smu_allow_xgmi_power_down(struct smu_context *smu, bool en);
-
 int smu_set_xgmi_plpd_mode(struct smu_context *smu,
 			   enum pp_xgmi_plpd_mode mode);
 
-- 
2.38.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH 1/7] drm/amd/pm: update pmfw headers for version 85.73.0
  2023-09-25  4:27 [PATCH 1/7] drm/amd/pm: update pmfw headers for version 85.73.0 Le Ma
                   ` (5 preceding siblings ...)
  2023-09-25  4:27 ` [PATCH 7/7] drm/amd/pm: deprecate allow_xgmi_power_down interface Le Ma
@ 2023-09-26  5:51 ` Lazar, Lijo
  6 siblings, 0 replies; 8+ messages in thread
From: Lazar, Lijo @ 2023-09-26  5:51 UTC (permalink / raw)
  To: Le Ma, amd-gfx; +Cc: Alexander.Deucher, Asad Kamal, Hawking.Zhang



On 9/25/2023 9:57 AM, Le Ma wrote:
> To add message to select PLPD mode.
> 
> Signed-off-by: Le Ma <le.ma@amd.com>
> Reviewed-by: Asad Kamal <asad.kamal@amd.com>

Series is -
	Reviewed-by: Lijo Lazar <lijo.lazar@amd.com>

Thanks,
Lijo

> ---
>   drivers/gpu/drm/amd/pm/swsmu/inc/pmfw_if/smu_v13_0_6_ppsmc.h | 5 +++++
>   1 file changed, 5 insertions(+)
> 
> diff --git a/drivers/gpu/drm/amd/pm/swsmu/inc/pmfw_if/smu_v13_0_6_ppsmc.h b/drivers/gpu/drm/amd/pm/swsmu/inc/pmfw_if/smu_v13_0_6_ppsmc.h
> index 021dcbe58473..509e3cd483fb 100644
> --- a/drivers/gpu/drm/amd/pm/swsmu/inc/pmfw_if/smu_v13_0_6_ppsmc.h
> +++ b/drivers/gpu/drm/amd/pm/swsmu/inc/pmfw_if/smu_v13_0_6_ppsmc.h
> @@ -90,6 +90,7 @@
>   #define PPSMC_MSG_ClearMcaOnRead                    0x39
>   #define PPSMC_MSG_QueryValidMcaCeCount              0x3A
>   #define PPSMC_MSG_McaBankCeDumpDW                   0x3B
> +#define PPSMC_MSG_SelectPLPDMode                    0x40
>   #define PPSMC_Message_Count                         0x41
>   
>   //PPSMC Reset Types for driver msg argument
> @@ -107,6 +108,10 @@
>   #define PPSMC_XCD_THM_TYPE                          0x3
>   #define PPSMC_HBM_THM_TYPE                          0x4
>   
> +//PLPD modes
> +#define PPSMC_PLPD_MODE_DEFAULT                     0x1
> +#define PPSMC_PLPD_MODE_OPTIMIZED                   0x2
> +
>   typedef uint32_t PPSMC_Result;
>   typedef uint32_t PPSMC_MSG;
>   

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2023-09-26  5:52 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-09-25  4:27 [PATCH 1/7] drm/amd/pm: update pmfw headers for version 85.73.0 Le Ma
2023-09-25  4:27 ` [PATCH 2/7] drm/amd/pm: add plpd_mode in smu_context to indicate current mode Le Ma
2023-09-25  4:27 ` [PATCH 3/7] drm/amd/pm: add xgmi plpd mode selecting interface for smu v13.0.6 Le Ma
2023-09-25  4:27 ` [PATCH 4/7] drm/amd/pm: add xgmi_plpd_policy sysfs node for user to change plpd policy Le Ma
2023-09-25  4:27 ` [PATCH 5/7] drm/amd/pm: init plpd_mode properly for different asics Le Ma
2023-09-25  4:27 ` [PATCH 6/7] drm/amd/pm: integrate plpd allow/disallow into select_xgmi_plpd_policy in ppt level Le Ma
2023-09-25  4:27 ` [PATCH 7/7] drm/amd/pm: deprecate allow_xgmi_power_down interface Le Ma
2023-09-26  5:51 ` [PATCH 1/7] drm/amd/pm: update pmfw headers for version 85.73.0 Lazar, Lijo

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox