AMD-GFX Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] drm/amd/powerplay: Enable "disable dpm" feature to support swSMU debug
@ 2019-05-10  8:48 Chengming Gui
       [not found] ` <1557478117-17823-1-git-send-email-Jack.Gui-5C7GfCeVMHo@public.gmane.org>
  0 siblings, 1 reply; 8+ messages in thread
From: Chengming Gui @ 2019-05-10  8:48 UTC (permalink / raw)
  To: amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW; +Cc: Chengming Gui

add pm_enabled to control the dpm off/on.

Signed-off-by: Chengming Gui <Jack.Gui@amd.com>
---
 drivers/gpu/drm/amd/powerplay/amdgpu_smu.c     | 34 +++++++++++++++++++++++---
 drivers/gpu/drm/amd/powerplay/inc/amdgpu_smu.h |  1 +
 drivers/gpu/drm/amd/powerplay/smu_v11_0.c      | 34 ++++++++++++++++++++++----
 3 files changed, 60 insertions(+), 9 deletions(-)

diff --git a/drivers/gpu/drm/amd/powerplay/amdgpu_smu.c b/drivers/gpu/drm/amd/powerplay/amdgpu_smu.c
index 52d919a..99b2082 100644
--- a/drivers/gpu/drm/amd/powerplay/amdgpu_smu.c
+++ b/drivers/gpu/drm/amd/powerplay/amdgpu_smu.c
@@ -198,6 +198,8 @@ int smu_sys_set_pp_table(struct smu_context *smu,  void *buf, size_t size)
 	ATOM_COMMON_TABLE_HEADER *header = (ATOM_COMMON_TABLE_HEADER *)buf;
 	int ret = 0;
 
+	if (!smu->pm_enabled)
+		return -EINVAL;
 	if (header->usStructureSize != size) {
 		pr_err("pp table size not matched !\n");
 		return -EIO;
@@ -233,6 +235,8 @@ int smu_feature_init_dpm(struct smu_context *smu)
 	int ret = 0;
 	uint32_t unallowed_feature_mask[SMU_FEATURE_MAX/32];
 
+	if (!smu->pm_enabled)
+		return ret;
 	mutex_lock(&feature->mutex);
 	bitmap_fill(feature->allowed, SMU_FEATURE_MAX);
 	mutex_unlock(&feature->mutex);
@@ -344,6 +348,7 @@ static int smu_early_init(void *handle)
 	struct smu_context *smu = &adev->smu;
 
 	smu->adev = adev;
+	smu->pm_enabled = amdgpu_dpm;
 	mutex_init(&smu->mutex);
 
 	return smu_set_funcs(adev);
@@ -353,6 +358,9 @@ static int smu_late_init(void *handle)
 {
 	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
 	struct smu_context *smu = &adev->smu;
+
+	if (!smu->pm_enabled)
+		return 0;
 	mutex_lock(&smu->mutex);
 	smu_handle_task(&adev->smu,
 			smu->smu_dpm.dpm_level,
@@ -746,6 +754,9 @@ static int smu_smc_table_hw_init(struct smu_context *smu,
 	 */
 	ret = smu_set_tool_table_location(smu);
 
+	if (!smu_is_dpm_running(smu))
+		pr_info("dpm has been disabled\n");
+
 	return ret;
 }
 
@@ -861,7 +872,10 @@ static int smu_hw_init(void *handle)
 
 	mutex_unlock(&smu->mutex);
 
-	adev->pm.dpm_enabled = true;
+	if (!smu->pm_enabled)
+		adev->pm.dpm_enabled = false;
+	else
+		adev->pm.dpm_enabled = true;
 
 	pr_info("SMU is initialized successfully!\n");
 
@@ -879,6 +893,8 @@ static int smu_hw_fini(void *handle)
 	struct smu_table_context *table_context = &smu->smu_table;
 	int ret = 0;
 
+	if (!smu->pm_enabled)
+		return ret;
 	if (!is_support_sw_smu(adev))
 		return -EINVAL;
 
@@ -932,10 +948,12 @@ int smu_reset(struct smu_context *smu)
 
 static int smu_suspend(void *handle)
 {
-	int ret;
+	int ret = 0;
 	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
 	struct smu_context *smu = &adev->smu;
 
+	if (!smu->pm_enabled)
+		return ret;
 	if (!is_support_sw_smu(adev))
 		return -EINVAL;
 
@@ -950,10 +968,12 @@ static int smu_suspend(void *handle)
 
 static int smu_resume(void *handle)
 {
-	int ret;
+	int ret = 0;
 	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
 	struct smu_context *smu = &adev->smu;
 
+	if (!smu->pm_enabled)
+		return ret;
 	if (!is_support_sw_smu(adev))
 		return -EINVAL;
 
@@ -985,7 +1005,7 @@ int smu_display_configuration_change(struct smu_context *smu,
 	int index = 0;
 	int num_of_active_display = 0;
 
-	if (!is_support_sw_smu(smu->adev))
+	if (!smu->pm_enabled || !is_support_sw_smu(smu->adev))
 		return -EINVAL;
 
 	if (!display_config)
@@ -1113,6 +1133,8 @@ static int smu_enable_umd_pstate(void *handle,
 
 	struct smu_context *smu = (struct smu_context*)(handle);
 	struct smu_dpm_context *smu_dpm_ctx = &(smu->smu_dpm);
+	if (!smu->pm_enabled)
+		return -EINVAL;
 	if (!smu_dpm_ctx->dpm_context)
 		return -EINVAL;
 
@@ -1156,6 +1178,8 @@ int smu_adjust_power_state_dynamic(struct smu_context *smu,
 	long workload;
 	struct smu_dpm_context *smu_dpm_ctx = &(smu->smu_dpm);
 
+	if (!smu->pm_enabled)
+		return -EINVAL;
 	if (!skip_display_settings) {
 		ret = smu_display_config_changed(smu);
 		if (ret) {
@@ -1164,6 +1188,8 @@ int smu_adjust_power_state_dynamic(struct smu_context *smu,
 		}
 	}
 
+	if (!smu->pm_enabled)
+		return -EINVAL;
 	ret = smu_apply_clocks_adjust_rules(smu);
 	if (ret) {
 		pr_err("Failed to apply clocks adjust rules!");
diff --git a/drivers/gpu/drm/amd/powerplay/inc/amdgpu_smu.h b/drivers/gpu/drm/amd/powerplay/inc/amdgpu_smu.h
index 8905241..56b9812 100644
--- a/drivers/gpu/drm/amd/powerplay/inc/amdgpu_smu.h
+++ b/drivers/gpu/drm/amd/powerplay/inc/amdgpu_smu.h
@@ -401,6 +401,7 @@ struct smu_context
 	uint32_t workload_setting[WORKLOAD_POLICY_MAX];
 	uint32_t power_profile_mode;
 	uint32_t default_power_profile_mode;
+	bool pm_enabled;
 
 	uint32_t smc_if_version;
 };
diff --git a/drivers/gpu/drm/amd/powerplay/smu_v11_0.c b/drivers/gpu/drm/amd/powerplay/smu_v11_0.c
index cd36c42..dee1e91 100644
--- a/drivers/gpu/drm/amd/powerplay/smu_v11_0.c
+++ b/drivers/gpu/drm/amd/powerplay/smu_v11_0.c
@@ -360,6 +360,8 @@ static int smu_v11_0_init_power(struct smu_context *smu)
 {
 	struct smu_power_context *smu_power = &smu->smu_power;
 
+	if (!smu->pm_enabled)
+		return 0;
 	if (smu_power->power_context || smu_power->power_context_size != 0)
 		return -EINVAL;
 
@@ -376,6 +378,8 @@ static int smu_v11_0_fini_power(struct smu_context *smu)
 {
 	struct smu_power_context *smu_power = &smu->smu_power;
 
+	if (!smu->pm_enabled)
+		return 0;
 	if (!smu_power->power_context || smu_power->power_context_size == 0)
 		return -EINVAL;
 
@@ -641,6 +645,8 @@ static int smu_v11_0_set_min_dcef_deep_sleep(struct smu_context *smu)
 {
 	struct smu_table_context *table_context = &smu->smu_table;
 
+	if (!smu->pm_enabled)
+		return 0;
 	if (!table_context)
 		return -EINVAL;
 
@@ -669,6 +675,9 @@ static int smu_v11_0_set_tool_table_location(struct smu_context *smu)
 static int smu_v11_0_init_display(struct smu_context *smu)
 {
 	int ret = 0;
+
+	if (!smu->pm_enabled)
+		return ret;
 	ret = smu_send_smc_msg_with_param(smu, SMU_MSG_NumOfDisplays, 0);
 	return ret;
 }
@@ -678,6 +687,8 @@ static int smu_v11_0_update_feature_enable_state(struct smu_context *smu, uint32
 	uint32_t feature_low = 0, feature_high = 0;
 	int ret = 0;
 
+	if (!smu->pm_enabled)
+		return ret;
 	if (feature_id >= 0 && feature_id < 31)
 		feature_low = (1 << feature_id);
 	else if (feature_id > 31 && feature_id < 63)
@@ -784,10 +795,13 @@ static int smu_v11_0_system_features_control(struct smu_context *smu,
 	uint32_t feature_mask[2];
 	int ret = 0;
 
-	ret = smu_send_smc_msg(smu, (en ? SMU_MSG_EnableAllSmuFeatures :
-				     SMU_MSG_DisableAllSmuFeatures));
-	if (ret)
-		return ret;
+	if (smu->pm_enabled) {
+		ret = smu_send_smc_msg(smu, (en ? SMU_MSG_EnableAllSmuFeatures :
+					     SMU_MSG_DisableAllSmuFeatures));
+		if (ret)
+			return ret;
+	}
+
 	ret = smu_feature_get_enabled_mask(smu, feature_mask, 2);
 	if (ret)
 		return ret;
@@ -804,6 +818,8 @@ static int smu_v11_0_notify_display_change(struct smu_context *smu)
 {
 	int ret = 0;
 
+	if (!smu->pm_enabled)
+		return ret;
 	if (smu_feature_is_enabled(smu, FEATURE_DPM_UCLK_BIT))
 	    ret = smu_send_smc_msg_with_param(smu, SMU_MSG_SetUclkFastSwitch, 1);
 
@@ -816,6 +832,8 @@ smu_v11_0_get_max_sustainable_clock(struct smu_context *smu, uint32_t *clock,
 {
 	int ret = 0;
 
+	if (!smu->pm_enabled)
+		return ret;
 	ret = smu_send_smc_msg_with_param(smu, SMU_MSG_GetDcModeMaxDpmFreq,
 					  clock_select << 16);
 	if (ret) {
@@ -1072,6 +1090,8 @@ static int smu_v11_0_start_thermal_control(struct smu_context *smu)
 	struct PP_TemperatureRange range;
 	struct amdgpu_device *adev = smu->adev;
 
+	if (!smu->pm_enabled)
+		return ret;
 	smu_v11_0_get_thermal_range(smu, &range);
 
 	if (smu->smu_table.thermal_controller_type) {
@@ -1242,6 +1262,8 @@ smu_v11_0_display_clock_voltage_request(struct smu_context *smu,
 	PPCLK_e clk_select = 0;
 	uint32_t clk_freq = clock_req->clock_freq_in_khz / 1000;
 
+	if (!smu->pm_enabled)
+		return -EINVAL;
 	if (smu_feature_is_enabled(smu, FEATURE_DPM_DCEFCLK_BIT)) {
 		switch (clk_type) {
 		case amd_pp_dcef_clock:
@@ -1525,7 +1547,7 @@ static int smu_v11_0_get_power_profile_mode(struct smu_context *smu, char *buf)
 			"PD_Data_error_rate_coeff"};
 	int result = 0;
 
-	if (!buf)
+	if (!smu->pm_enabled || !buf)
 		return -EINVAL;
 
 	size += sprintf(buf + size, "%16s %s %s %s %s %s %s %s %s %s %s\n",
@@ -1612,6 +1634,8 @@ static int smu_v11_0_set_power_profile_mode(struct smu_context *smu, long *input
 
 	smu->power_profile_mode = input[size];
 
+	if (!smu->pm_enabled)
+		return ret;
 	if (smu->power_profile_mode > PP_SMC_POWER_PROFILE_CUSTOM) {
 		pr_err("Invalid power profile mode %d\n", smu->power_profile_mode);
 		return -EINVAL;
-- 
2.7.4

_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

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

* [PATCH 2/2] drm/amd/powerplay: Enable "disable dpm" feature for vega20 power functions.
       [not found] ` <1557478117-17823-1-git-send-email-Jack.Gui-5C7GfCeVMHo@public.gmane.org>
@ 2019-05-10  8:48   ` Chengming Gui
       [not found]     ` <1557478117-17823-2-git-send-email-Jack.Gui-5C7GfCeVMHo@public.gmane.org>
  2019-05-12  3:18   ` [PATCH 1/2] drm/amd/powerplay: Enable "disable dpm" feature to support swSMU debug Zhang, Hawking
  1 sibling, 1 reply; 8+ messages in thread
From: Chengming Gui @ 2019-05-10  8:48 UTC (permalink / raw)
  To: amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW; +Cc: Chengming Gui

use pm_enabled to control all power related functions about vega20.

Signed-off-by: Chengming Gui <Jack.Gui@amd.com>
---
 drivers/gpu/drm/amd/powerplay/vega20_ppt.c | 48 +++++++++++++++++++++++-------
 1 file changed, 38 insertions(+), 10 deletions(-)

diff --git a/drivers/gpu/drm/amd/powerplay/vega20_ppt.c b/drivers/gpu/drm/amd/powerplay/vega20_ppt.c
index 8fafcbd..7faa6a1 100644
--- a/drivers/gpu/drm/amd/powerplay/vega20_ppt.c
+++ b/drivers/gpu/drm/amd/powerplay/vega20_ppt.c
@@ -411,7 +411,8 @@ amd_pm_state_type vega20_get_current_power_state(struct smu_context *smu)
 	enum amd_pm_state_type pm_type;
 	struct smu_dpm_context *smu_dpm_ctx = &(smu->smu_dpm);
 
-	if (!smu_dpm_ctx->dpm_context ||
+	if (!smu->pm_enabled ||
+	    !smu_dpm_ctx->dpm_context ||
 	    !smu_dpm_ctx->dpm_current_power_state)
 		return -EINVAL;
 
@@ -491,12 +492,14 @@ static void vega20_init_single_dpm_state(struct vega20_dpm_state *dpm_state)
 
 static int vega20_set_default_dpm_table(struct smu_context *smu)
 {
-	int ret;
+	int ret = 0;
 
 	struct smu_dpm_context *smu_dpm = &smu->smu_dpm;
 	struct vega20_dpm_table *dpm_table = NULL;
 	struct vega20_single_dpm_table *single_dpm_table;
 
+	if (smu->pm_enabled)
+		return ret;
 	dpm_table = smu_dpm->dpm_context;
 
 	/* socclk */
@@ -738,6 +741,8 @@ static int vega20_print_clk_levels(struct smu_context *smu,
 
 	dpm_table = smu_dpm->dpm_context;
 
+	if (!smu->pm_enabled)
+		return -EINVAL;
 	switch (type) {
 	case PP_SCLK:
 		ret = smu_get_current_clk_freq(smu, PPCLK_GFXCLK, &now);
@@ -969,6 +974,8 @@ static int vega20_upload_dpm_level(struct smu_context *smu, bool max,
 	uint32_t freq;
 	int ret = 0;
 
+	if (!smu->pm_enabled)
+		return -EINVAL;
 	dpm_table = smu->smu_dpm.dpm_context;
 
 	if (smu_feature_is_enabled(smu, FEATURE_DPM_GFXCLK_BIT) &&
@@ -1058,6 +1065,8 @@ static int vega20_force_clk_levels(struct smu_context *smu,
 	struct smu_dpm_context *smu_dpm = &smu->smu_dpm;
 	int ret = 0;
 
+	if (!smu->pm_enabled)
+		return -EINVAL;
 	if (smu_dpm->dpm_level != AMD_DPM_FORCED_LEVEL_MANUAL) {
 		pr_info("force clock level is for dpm manual mode only.\n");
 		return -EINVAL;
@@ -1232,8 +1241,9 @@ static int vega20_get_clock_by_type_with_latency(struct smu_context *smu,
 
 	dpm_table = smu_dpm->dpm_context;
 
+	if (!smu->pm_enabled)
+		return -EINVAL;
 	mutex_lock(&smu->mutex);
-
 	switch (type) {
 	case amd_pp_sys_clock:
 		single_dpm_table = &(dpm_table->gfx_table);
@@ -1265,6 +1275,8 @@ static int vega20_overdrive_get_gfx_clk_base_voltage(struct smu_context *smu,
 {
 	int ret;
 
+	if (!smu->pm_enabled)
+		return -EINVAL;
 	ret = smu_send_smc_msg_with_param(smu,
 			SMU_MSG_GetAVFSVoltageByDpm,
 			((AVFS_CURVE << 24) | (OD8_HOTCURVE_TEMPERATURE << 16) | freq));
@@ -1287,7 +1299,7 @@ static int vega20_set_default_od8_setttings(struct smu_context *smu)
 	PPTable_t *smc_pptable = table_context->driver_pptable;
 	int i, ret;
 
-	if (table_context->od8_settings)
+	if (!smu->pm_enabled || table_context->od8_settings)
 		return -EINVAL;
 
 	table_context->od8_settings = kzalloc(sizeof(struct vega20_od8_settings), GFP_KERNEL);
@@ -1474,6 +1486,8 @@ static int vega20_get_od_percentage(struct smu_context *smu,
 	dpm_table = smu_dpm->dpm_context;
 	golden_table = smu_dpm->golden_dpm_context;
 
+	if (!smu->pm_enabled)
+		return -EINVAL;
 	switch (type) {
 	case OD_SCLK:
 		single_dpm_table = &(dpm_table->gfx_table);
@@ -1509,7 +1523,7 @@ vega20_get_profiling_clk_mask(struct smu_context *smu,
 	struct vega20_single_dpm_table *mem_dpm_table;
 	struct vega20_single_dpm_table *soc_dpm_table;
 
-	if (!smu->smu_dpm.dpm_context)
+	if (!smu->pm_enabled || !smu->smu_dpm.dpm_context)
 		return -EINVAL;
 
 	gfx_dpm_table = &dpm_table->gfx_table;
@@ -1579,7 +1593,7 @@ static int vega20_pre_display_config_changed(struct smu_context *smu)
 	int ret = 0;
 	struct vega20_dpm_table *dpm_table = smu->smu_dpm.dpm_context;
 
-	if (!smu->smu_dpm.dpm_context)
+	if (!smu->pm_enabled || !smu->smu_dpm.dpm_context)
 		return -EINVAL;
 
 	smu_send_smc_msg_with_param(smu, SMU_MSG_NumOfDisplays, 0);
@@ -1594,7 +1608,7 @@ static int vega20_display_config_changed(struct smu_context *smu)
 {
 	int ret = 0;
 
-	if (!smu->funcs)
+	if (!smu->pm_enabled || !smu->funcs)
 		return -EINVAL;
 
 	if (!smu->smu_dpm.dpm_context ||
@@ -1632,6 +1646,8 @@ static int vega20_apply_clocks_adjust_rules(struct smu_context *smu)
 	bool disable_mclk_switching;
 	uint32_t i, latency;
 
+	if (!smu->pm_enabled)
+		return -EINVAL;
 	disable_mclk_switching = ((1 < smu->display_config->num_display) &&
 				  !smu->display_config->multi_monitor_in_sync) || vblank_too_short;
 	latency = smu->display_config->dce_tolerable_mclk_in_active_latency;
@@ -1779,6 +1795,8 @@ vega20_notify_smc_dispaly_config(struct smu_context *smu)
 	struct pp_display_clock_request clock_req;
 	int ret = 0;
 
+	if (!smu->pm_enabled)
+		return -EINVAL;
 	min_clocks.dcef_clock = smu->display_config->min_dcef_set_clk;
 	min_clocks.dcef_clock_in_sr = smu->display_config->min_dcef_deep_sleep_set_clk;
 	min_clocks.memory_clock = smu->display_config->min_mem_set_clock;
@@ -1867,6 +1885,8 @@ static int vega20_force_dpm_limit_value(struct smu_context *smu, bool highest)
 	struct vega20_dpm_table *dpm_table =
 		(struct vega20_dpm_table *)smu->smu_dpm.dpm_context;
 
+	if (!smu->pm_enabled)
+		return -EINVAL;
 	if (highest)
 		soft_level = vega20_find_highest_dpm_level(&(dpm_table->gfx_table));
 	else
@@ -1918,6 +1938,8 @@ static int vega20_unforce_dpm_levels(struct smu_context *smu)
 	struct vega20_dpm_table *dpm_table =
 		(struct vega20_dpm_table *)smu->smu_dpm.dpm_context;
 
+	if (!smu->pm_enabled)
+		return -EINVAL;
 	soft_min_level = vega20_find_lowest_dpm_level(&(dpm_table->gfx_table));
 	soft_max_level = vega20_find_highest_dpm_level(&(dpm_table->gfx_table));
 	dpm_table->gfx_table.dpm_state.soft_min_level =
@@ -1957,9 +1979,9 @@ static int vega20_unforce_dpm_levels(struct smu_context *smu)
 static enum amd_dpm_forced_level vega20_get_performance_level(struct smu_context *smu)
 {
 	struct smu_dpm_context *smu_dpm_ctx = &(smu->smu_dpm);
-	if (!smu_dpm_ctx->dpm_context)
-		return -EINVAL;
 
+	if (!smu->pm_enabled || !smu_dpm_ctx->dpm_context)
+		return -EINVAL;
 	if (smu_dpm_ctx->dpm_level != smu_dpm_ctx->saved_dpm_level) {
 		mutex_lock(&(smu->mutex));
 		smu_dpm_ctx->saved_dpm_level = smu_dpm_ctx->dpm_level;
@@ -1975,7 +1997,7 @@ vega20_force_performance_level(struct smu_context *smu, enum amd_dpm_forced_leve
 	int i;
 	struct smu_dpm_context *smu_dpm_ctx = &(smu->smu_dpm);
 
-	if (!smu_dpm_ctx->dpm_context)
+	if (!smu->pm_enabled || !smu_dpm_ctx->dpm_context)
 		return -EINVAL;
 
 	for (i = 0; i < smu->adev->num_ip_blocks; i++) {
@@ -2004,6 +2026,8 @@ static int vega20_update_specified_od8_value(struct smu_context *smu,
 	struct vega20_od8_settings *od8_settings =
 		(struct vega20_od8_settings *)table_context->od8_settings;
 
+	if (!smu->pm_enabled)
+		return -EINVAL;
 	switch (index) {
 	case OD8_SETTING_GFXCLK_FMIN:
 		od_table->GfxclkFmin = (uint16_t)value;
@@ -2085,6 +2109,8 @@ static int vega20_set_od_percentage(struct smu_context *smu,
 	int feature_enabled;
 	PPCLK_e clk_id;
 
+	if (!smu->pm_enabled)
+		return -EINVAL;
 	mutex_lock(&(smu->mutex));
 
 	dpm_table = smu_dpm->dpm_context;
@@ -2163,6 +2189,8 @@ static int vega20_odn_edit_dpm_table(struct smu_context *smu,
 
 	dpm_table = smu_dpm->dpm_context;
 
+	if (!smu->pm_enabled)
+		return -EINVAL;
 	if (!input) {
 		pr_warn("NULL user input for clock and voltage\n");
 		return -EINVAL;
-- 
2.7.4

_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

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

* RE: [PATCH 2/2] drm/amd/powerplay: Enable "disable dpm" feature for vega20 power functions.
       [not found]     ` <1557478117-17823-2-git-send-email-Jack.Gui-5C7GfCeVMHo@public.gmane.org>
@ 2019-05-12  3:18       ` Zhang, Hawking
       [not found]         ` <BYAPR12MB263244237A28E226D34F348EFC0E0-ZGDeBxoHBPk+ukJnzp2+RQdYzm3356FpvxpqHgZTriW3zl9H0oFU5g@public.gmane.org>
  0 siblings, 1 reply; 8+ messages in thread
From: Zhang, Hawking @ 2019-05-12  3:18 UTC (permalink / raw)
  To: amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org; +Cc: Gui, Jack

I'm wondering whether we are able to handle all asic specific ppt function gracefully. Add pm_enable check into ppt functions would be boring since we have to do similar jobs for each ASIC. Instead, is it possible to return early from amdgpu_smu interface level? 

Take smu_handle_task for the example, all the amdgpu_smu level interface invoked from this function could be stopped if we check smu pm_enable flag at the beginning of smu_handle_task. We probably have better approach to eliminate this patch.

Regards,
Hawking 

-----Original Message-----
From: amd-gfx <amd-gfx-bounces@lists.freedesktop.org> On Behalf Of Chengming Gui
Sent: 2019年5月10日 16:49
To: amd-gfx@lists.freedesktop.org
Cc: Gui, Jack <Jack.Gui@amd.com>
Subject: [PATCH 2/2] drm/amd/powerplay: Enable "disable dpm" feature for vega20 power functions.

[CAUTION: External Email]

use pm_enabled to control all power related functions about vega20.

Signed-off-by: Chengming Gui <Jack.Gui@amd.com>
---
 drivers/gpu/drm/amd/powerplay/vega20_ppt.c | 48 +++++++++++++++++++++++-------
 1 file changed, 38 insertions(+), 10 deletions(-)

diff --git a/drivers/gpu/drm/amd/powerplay/vega20_ppt.c b/drivers/gpu/drm/amd/powerplay/vega20_ppt.c
index 8fafcbd..7faa6a1 100644
--- a/drivers/gpu/drm/amd/powerplay/vega20_ppt.c
+++ b/drivers/gpu/drm/amd/powerplay/vega20_ppt.c
@@ -411,7 +411,8 @@ amd_pm_state_type vega20_get_current_power_state(struct smu_context *smu)
        enum amd_pm_state_type pm_type;
        struct smu_dpm_context *smu_dpm_ctx = &(smu->smu_dpm);

-       if (!smu_dpm_ctx->dpm_context ||
+       if (!smu->pm_enabled ||
+           !smu_dpm_ctx->dpm_context ||
            !smu_dpm_ctx->dpm_current_power_state)
                return -EINVAL;

@@ -491,12 +492,14 @@ static void vega20_init_single_dpm_state(struct vega20_dpm_state *dpm_state)

 static int vega20_set_default_dpm_table(struct smu_context *smu)  {
-       int ret;
+       int ret = 0;

        struct smu_dpm_context *smu_dpm = &smu->smu_dpm;
        struct vega20_dpm_table *dpm_table = NULL;
        struct vega20_single_dpm_table *single_dpm_table;

+       if (smu->pm_enabled)
+               return ret;
        dpm_table = smu_dpm->dpm_context;

        /* socclk */
@@ -738,6 +741,8 @@ static int vega20_print_clk_levels(struct smu_context *smu,

        dpm_table = smu_dpm->dpm_context;

+       if (!smu->pm_enabled)
+               return -EINVAL;
        switch (type) {
        case PP_SCLK:
                ret = smu_get_current_clk_freq(smu, PPCLK_GFXCLK, &now); @@ -969,6 +974,8 @@ static int vega20_upload_dpm_level(struct smu_context *smu, bool max,
        uint32_t freq;
        int ret = 0;

+       if (!smu->pm_enabled)
+               return -EINVAL;
        dpm_table = smu->smu_dpm.dpm_context;

        if (smu_feature_is_enabled(smu, FEATURE_DPM_GFXCLK_BIT) && @@ -1058,6 +1065,8 @@ static int vega20_force_clk_levels(struct smu_context *smu,
        struct smu_dpm_context *smu_dpm = &smu->smu_dpm;
        int ret = 0;

+       if (!smu->pm_enabled)
+               return -EINVAL;
        if (smu_dpm->dpm_level != AMD_DPM_FORCED_LEVEL_MANUAL) {
                pr_info("force clock level is for dpm manual mode only.\n");
                return -EINVAL;
@@ -1232,8 +1241,9 @@ static int vega20_get_clock_by_type_with_latency(struct smu_context *smu,

        dpm_table = smu_dpm->dpm_context;

+       if (!smu->pm_enabled)
+               return -EINVAL;
        mutex_lock(&smu->mutex);
-
        switch (type) {
        case amd_pp_sys_clock:
                single_dpm_table = &(dpm_table->gfx_table); @@ -1265,6 +1275,8 @@ static int vega20_overdrive_get_gfx_clk_base_voltage(struct smu_context *smu,  {
        int ret;

+       if (!smu->pm_enabled)
+               return -EINVAL;
        ret = smu_send_smc_msg_with_param(smu,
                        SMU_MSG_GetAVFSVoltageByDpm,
                        ((AVFS_CURVE << 24) | (OD8_HOTCURVE_TEMPERATURE << 16) | freq)); @@ -1287,7 +1299,7 @@ static int vega20_set_default_od8_setttings(struct smu_context *smu)
        PPTable_t *smc_pptable = table_context->driver_pptable;
        int i, ret;

-       if (table_context->od8_settings)
+       if (!smu->pm_enabled || table_context->od8_settings)
                return -EINVAL;

        table_context->od8_settings = kzalloc(sizeof(struct vega20_od8_settings), GFP_KERNEL); @@ -1474,6 +1486,8 @@ static int vega20_get_od_percentage(struct smu_context *smu,
        dpm_table = smu_dpm->dpm_context;
        golden_table = smu_dpm->golden_dpm_context;

+       if (!smu->pm_enabled)
+               return -EINVAL;
        switch (type) {
        case OD_SCLK:
                single_dpm_table = &(dpm_table->gfx_table); @@ -1509,7 +1523,7 @@ vega20_get_profiling_clk_mask(struct smu_context *smu,
        struct vega20_single_dpm_table *mem_dpm_table;
        struct vega20_single_dpm_table *soc_dpm_table;

-       if (!smu->smu_dpm.dpm_context)
+       if (!smu->pm_enabled || !smu->smu_dpm.dpm_context)
                return -EINVAL;

        gfx_dpm_table = &dpm_table->gfx_table; @@ -1579,7 +1593,7 @@ static int vega20_pre_display_config_changed(struct smu_context *smu)
        int ret = 0;
        struct vega20_dpm_table *dpm_table = smu->smu_dpm.dpm_context;

-       if (!smu->smu_dpm.dpm_context)
+       if (!smu->pm_enabled || !smu->smu_dpm.dpm_context)
                return -EINVAL;

        smu_send_smc_msg_with_param(smu, SMU_MSG_NumOfDisplays, 0); @@ -1594,7 +1608,7 @@ static int vega20_display_config_changed(struct smu_context *smu)  {
        int ret = 0;

-       if (!smu->funcs)
+       if (!smu->pm_enabled || !smu->funcs)
                return -EINVAL;

        if (!smu->smu_dpm.dpm_context || @@ -1632,6 +1646,8 @@ static int vega20_apply_clocks_adjust_rules(struct smu_context *smu)
        bool disable_mclk_switching;
        uint32_t i, latency;

+       if (!smu->pm_enabled)
+               return -EINVAL;
        disable_mclk_switching = ((1 < smu->display_config->num_display) &&
                                  !smu->display_config->multi_monitor_in_sync) || vblank_too_short;
        latency = smu->display_config->dce_tolerable_mclk_in_active_latency;
@@ -1779,6 +1795,8 @@ vega20_notify_smc_dispaly_config(struct smu_context *smu)
        struct pp_display_clock_request clock_req;
        int ret = 0;

+       if (!smu->pm_enabled)
+               return -EINVAL;
        min_clocks.dcef_clock = smu->display_config->min_dcef_set_clk;
        min_clocks.dcef_clock_in_sr = smu->display_config->min_dcef_deep_sleep_set_clk;
        min_clocks.memory_clock = smu->display_config->min_mem_set_clock;
@@ -1867,6 +1885,8 @@ static int vega20_force_dpm_limit_value(struct smu_context *smu, bool highest)
        struct vega20_dpm_table *dpm_table =
                (struct vega20_dpm_table *)smu->smu_dpm.dpm_context;

+       if (!smu->pm_enabled)
+               return -EINVAL;
        if (highest)
                soft_level = vega20_find_highest_dpm_level(&(dpm_table->gfx_table));
        else
@@ -1918,6 +1938,8 @@ static int vega20_unforce_dpm_levels(struct smu_context *smu)
        struct vega20_dpm_table *dpm_table =
                (struct vega20_dpm_table *)smu->smu_dpm.dpm_context;

+       if (!smu->pm_enabled)
+               return -EINVAL;
        soft_min_level = vega20_find_lowest_dpm_level(&(dpm_table->gfx_table));
        soft_max_level = vega20_find_highest_dpm_level(&(dpm_table->gfx_table));
        dpm_table->gfx_table.dpm_state.soft_min_level = @@ -1957,9 +1979,9 @@ static int vega20_unforce_dpm_levels(struct smu_context *smu)  static enum amd_dpm_forced_level vega20_get_performance_level(struct smu_context *smu)  {
        struct smu_dpm_context *smu_dpm_ctx = &(smu->smu_dpm);
-       if (!smu_dpm_ctx->dpm_context)
-               return -EINVAL;

+       if (!smu->pm_enabled || !smu_dpm_ctx->dpm_context)
+               return -EINVAL;
        if (smu_dpm_ctx->dpm_level != smu_dpm_ctx->saved_dpm_level) {
                mutex_lock(&(smu->mutex));
                smu_dpm_ctx->saved_dpm_level = smu_dpm_ctx->dpm_level; @@ -1975,7 +1997,7 @@ vega20_force_performance_level(struct smu_context *smu, enum amd_dpm_forced_leve
        int i;
        struct smu_dpm_context *smu_dpm_ctx = &(smu->smu_dpm);

-       if (!smu_dpm_ctx->dpm_context)
+       if (!smu->pm_enabled || !smu_dpm_ctx->dpm_context)
                return -EINVAL;

        for (i = 0; i < smu->adev->num_ip_blocks; i++) { @@ -2004,6 +2026,8 @@ static int vega20_update_specified_od8_value(struct smu_context *smu,
        struct vega20_od8_settings *od8_settings =
                (struct vega20_od8_settings *)table_context->od8_settings;

+       if (!smu->pm_enabled)
+               return -EINVAL;
        switch (index) {
        case OD8_SETTING_GFXCLK_FMIN:
                od_table->GfxclkFmin = (uint16_t)value; @@ -2085,6 +2109,8 @@ static int vega20_set_od_percentage(struct smu_context *smu,
        int feature_enabled;
        PPCLK_e clk_id;

+       if (!smu->pm_enabled)
+               return -EINVAL;
        mutex_lock(&(smu->mutex));

        dpm_table = smu_dpm->dpm_context; @@ -2163,6 +2189,8 @@ static int vega20_odn_edit_dpm_table(struct smu_context *smu,

        dpm_table = smu_dpm->dpm_context;

+       if (!smu->pm_enabled)
+               return -EINVAL;
        if (!input) {
                pr_warn("NULL user input for clock and voltage\n");
                return -EINVAL;
--
2.7.4

_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

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

* RE: [PATCH 1/2] drm/amd/powerplay: Enable "disable dpm" feature to support swSMU debug
       [not found] ` <1557478117-17823-1-git-send-email-Jack.Gui-5C7GfCeVMHo@public.gmane.org>
  2019-05-10  8:48   ` [PATCH 2/2] drm/amd/powerplay: Enable "disable dpm" feature for vega20 power functions Chengming Gui
@ 2019-05-12  3:18   ` Zhang, Hawking
       [not found]     ` <BYAPR12MB263278FD5AB7F03B991DEA43FC0E0-ZGDeBxoHBPk+ukJnzp2+RQdYzm3356FpvxpqHgZTriW3zl9H0oFU5g@public.gmane.org>
  1 sibling, 1 reply; 8+ messages in thread
From: Zhang, Hawking @ 2019-05-12  3:18 UTC (permalink / raw)
  To: amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org; +Cc: Gui, Jack


[-- Attachment #1.1: Type: text/plain, Size: 11165 bytes --]

Please check my comments inline.

Regards,
Hawking
-----Original Message-----
From: amd-gfx <amd-gfx-bounces@lists.freedesktop.org> On Behalf Of Chengming Gui
Sent: 2019年5月10日 16:49
To: amd-gfx@lists.freedesktop.org
Cc: Gui, Jack <Jack.Gui@amd.com>
Subject: [PATCH 1/2] drm/amd/powerplay: Enable "disable dpm" feature to support swSMU debug

[CAUTION: External Email]

add pm_enabled to control the dpm off/on.

Signed-off-by: Chengming Gui <Jack.Gui@amd.com<mailto:Jack.Gui@amd.com>>
---
 drivers/gpu/drm/amd/powerplay/amdgpu_smu.c     | 34 +++++++++++++++++++++++---
 drivers/gpu/drm/amd/powerplay/inc/amdgpu_smu.h |  1 +
 drivers/gpu/drm/amd/powerplay/smu_v11_0.c      | 34 ++++++++++++++++++++++----
 3 files changed, 60 insertions(+), 9 deletions(-)

diff --git a/drivers/gpu/drm/amd/powerplay/amdgpu_smu.c b/drivers/gpu/drm/amd/powerplay/amdgpu_smu.c
index 52d919a..99b2082 100644
--- a/drivers/gpu/drm/amd/powerplay/amdgpu_smu.c
+++ b/drivers/gpu/drm/amd/powerplay/amdgpu_smu.c
@@ -198,6 +198,8 @@ int smu_sys_set_pp_table(struct smu_context *smu,  void *buf, size_t size)
        ATOM_COMMON_TABLE_HEADER *header = (ATOM_COMMON_TABLE_HEADER *)buf;
        int ret = 0;

+       if (!smu->pm_enabled)
+               return -EINVAL;
        if (header->usStructureSize != size) {
                pr_err("pp table size not matched !\n");
                return -EIO;
@@ -233,6 +235,8 @@ int smu_feature_init_dpm(struct smu_context *smu)
        int ret = 0;
        uint32_t unallowed_feature_mask[SMU_FEATURE_MAX/32];

+       if (!smu->pm_enabled)
+               return ret;
        mutex_lock(&feature->mutex);
        bitmap_fill(feature->allowed, SMU_FEATURE_MAX);
        mutex_unlock(&feature->mutex);
@@ -344,6 +348,7 @@ static int smu_early_init(void *handle)
        struct smu_context *smu = &adev->smu;

        smu->adev = adev;
+       smu->pm_enabled = amdgpu_dpm;
        mutex_init(&smu->mutex);

        return smu_set_funcs(adev);
@@ -353,6 +358,9 @@ static int smu_late_init(void *handle)  {
        struct amdgpu_device *adev = (struct amdgpu_device *)handle;
        struct smu_context *smu = &adev->smu;
+
+       if (!smu->pm_enabled)
+               return 0;
        mutex_lock(&smu->mutex);
        smu_handle_task(&adev->smu,
                        smu->smu_dpm.dpm_level, @@ -746,6 +754,9 @@ static int smu_smc_table_hw_init(struct smu_context *smu,
         */
        ret = smu_set_tool_table_location(smu);

+       if (!smu_is_dpm_running(smu))
+               pr_info("dpm has been disabled\n");
+
        return ret;
 }

@@ -861,7 +872,10 @@ static int smu_hw_init(void *handle)

        mutex_unlock(&smu->mutex);

-       adev->pm.dpm_enabled = true;
+       if (!smu->pm_enabled)
+               adev->pm.dpm_enabled = false;
+       else
+               adev->pm.dpm_enabled = true;

        pr_info("SMU is initialized successfully!\n");

@@ -879,6 +893,8 @@ static int smu_hw_fini(void *handle)
        struct smu_table_context *table_context = &smu->smu_table;
        int ret = 0;

+       if (!smu->pm_enabled)
+               return ret;
        if (!is_support_sw_smu(adev))
                return -EINVAL;

@@ -932,10 +948,12 @@ int smu_reset(struct smu_context *smu)

 static int smu_suspend(void *handle)
 {
-       int ret;
+       int ret = 0;
        struct amdgpu_device *adev = (struct amdgpu_device *)handle;
        struct smu_context *smu = &adev->smu;

+       if (!smu->pm_enabled)
+               return ret;
[Hawking]: Just return 0 directly if dpm was disabled. Don't change the default return value to 0 which means resume complete successfully

        if (!is_support_sw_smu(adev))
                return -EINVAL;

@@ -950,10 +968,12 @@ static int smu_suspend(void *handle)

 static int smu_resume(void *handle)
 {
-       int ret;
+       int ret = 0;
        struct amdgpu_device *adev = (struct amdgpu_device *)handle;
        struct smu_context *smu = &adev->smu;

+       if (!smu->pm_enabled)
+               return ret;
[Hawking]: similar as suspend, directly return 0 if dpm was disabled.

        if (!is_support_sw_smu(adev))
                return -EINVAL;

@@ -985,7 +1005,7 @@ int smu_display_configuration_change(struct smu_context *smu,
        int index = 0;
        int num_of_active_display = 0;

-       if (!is_support_sw_smu(smu->adev))
+       if (!smu->pm_enabled || !is_support_sw_smu(smu->adev))
                return -EINVAL;

        if (!display_config)
@@ -1113,6 +1133,8 @@ static int smu_enable_umd_pstate(void *handle,

        struct smu_context *smu = (struct smu_context*)(handle);
        struct smu_dpm_context *smu_dpm_ctx = &(smu->smu_dpm);
+       if (!smu->pm_enabled)
+               return -EINVAL;
[Hawking]: please merge this with the dpm_context check

        if (!smu_dpm_ctx->dpm_context)
                return -EINVAL;

@@ -1156,6 +1178,8 @@ int smu_adjust_power_state_dynamic(struct smu_context *smu,
        long workload;
        struct smu_dpm_context *smu_dpm_ctx = &(smu->smu_dpm);

+       if (!smu->pm_enabled)
+               return -EINVAL;
        if (!skip_display_settings) {
                ret = smu_display_config_changed(smu);
                if (ret) {
@@ -1164,6 +1188,8 @@ int smu_adjust_power_state_dynamic(struct smu_context *smu,
                }
        }

+       if (!smu->pm_enabled)
+               return -EINVAL;
        ret = smu_apply_clocks_adjust_rules(smu);
        if (ret) {
                pr_err("Failed to apply clocks adjust rules!"); diff --git a/drivers/gpu/drm/amd/powerplay/inc/amdgpu_smu.h b/drivers/gpu/drm/amd/powerplay/inc/amdgpu_smu.h
index 8905241..56b9812 100644
--- a/drivers/gpu/drm/amd/powerplay/inc/amdgpu_smu.h
+++ b/drivers/gpu/drm/amd/powerplay/inc/amdgpu_smu.h
@@ -401,6 +401,7 @@ struct smu_context
        uint32_t workload_setting[WORKLOAD_POLICY_MAX];
        uint32_t power_profile_mode;
        uint32_t default_power_profile_mode;
+       bool pm_enabled;

        uint32_t smc_if_version;
 };
diff --git a/drivers/gpu/drm/amd/powerplay/smu_v11_0.c b/drivers/gpu/drm/amd/powerplay/smu_v11_0.c
index cd36c42..dee1e91 100644
--- a/drivers/gpu/drm/amd/powerplay/smu_v11_0.c
+++ b/drivers/gpu/drm/amd/powerplay/smu_v11_0.c
@@ -360,6 +360,8 @@ static int smu_v11_0_init_power(struct smu_context *smu)  {
        struct smu_power_context *smu_power = &smu->smu_power;

+       if (!smu->pm_enabled)
+               return 0;
        if (smu_power->power_context || smu_power->power_context_size != 0)
                return -EINVAL;

@@ -376,6 +378,8 @@ static int smu_v11_0_fini_power(struct smu_context *smu)  {
        struct smu_power_context *smu_power = &smu->smu_power;

+       if (!smu->pm_enabled)
+               return 0;
        if (!smu_power->power_context || smu_power->power_context_size == 0)
                return -EINVAL;

@@ -641,6 +645,8 @@ static int smu_v11_0_set_min_dcef_deep_sleep(struct smu_context *smu)  {
        struct smu_table_context *table_context = &smu->smu_table;

+       if (!smu->pm_enabled)
+               return 0;
        if (!table_context)
                return -EINVAL;

@@ -669,6 +675,9 @@ static int smu_v11_0_set_tool_table_location(struct smu_context *smu)  static int smu_v11_0_init_display(struct smu_context *smu)  {
        int ret = 0;
+
+       if (!smu->pm_enabled)
+               return ret;
        ret = smu_send_smc_msg_with_param(smu, SMU_MSG_NumOfDisplays, 0);
        return ret;
 }
@@ -678,6 +687,8 @@ static int smu_v11_0_update_feature_enable_state(struct smu_context *smu, uint32
        uint32_t feature_low = 0, feature_high = 0;
        int ret = 0;

+       if (!smu->pm_enabled)
+               return ret;
        if (feature_id >= 0 && feature_id < 31)
                feature_low = (1 << feature_id);
        else if (feature_id > 31 && feature_id < 63) @@ -784,10 +795,13 @@ static int smu_v11_0_system_features_control(struct smu_context *smu,
        uint32_t feature_mask[2];
        int ret = 0;

-       ret = smu_send_smc_msg(smu, (en ? SMU_MSG_EnableAllSmuFeatures :
-                                    SMU_MSG_DisableAllSmuFeatures));
-       if (ret)
-               return ret;
+       if (smu->pm_enabled) {
+               ret = smu_send_smc_msg(smu, (en ? SMU_MSG_EnableAllSmuFeatures :
+                                            SMU_MSG_DisableAllSmuFeatures));
+               if (ret)
+                       return ret;
+       }
+
        ret = smu_feature_get_enabled_mask(smu, feature_mask, 2);
        if (ret)
                return ret;
@@ -804,6 +818,8 @@ static int smu_v11_0_notify_display_change(struct smu_context *smu)  {
        int ret = 0;

+       if (!smu->pm_enabled)
+               return ret;
        if (smu_feature_is_enabled(smu, FEATURE_DPM_UCLK_BIT))
            ret = smu_send_smc_msg_with_param(smu, SMU_MSG_SetUclkFastSwitch, 1);

@@ -816,6 +832,8 @@ smu_v11_0_get_max_sustainable_clock(struct smu_context *smu, uint32_t *clock,  {
        int ret = 0;

+       if (!smu->pm_enabled)
+               return ret;
        ret = smu_send_smc_msg_with_param(smu, SMU_MSG_GetDcModeMaxDpmFreq,
                                          clock_select << 16);
        if (ret) {
@@ -1072,6 +1090,8 @@ static int smu_v11_0_start_thermal_control(struct smu_context *smu)
        struct PP_TemperatureRange range;
        struct amdgpu_device *adev = smu->adev;

+       if (!smu->pm_enabled)
+               return ret;
        smu_v11_0_get_thermal_range(smu, &range);

        if (smu->smu_table.thermal_controller_type) { @@ -1242,6 +1262,8 @@ smu_v11_0_display_clock_voltage_request(struct smu_context *smu,
        PPCLK_e clk_select = 0;
        uint32_t clk_freq = clock_req->clock_freq_in_khz / 1000;

+       if (!smu->pm_enabled)
+               return -EINVAL;
        if (smu_feature_is_enabled(smu, FEATURE_DPM_DCEFCLK_BIT)) {
                switch (clk_type) {
                case amd_pp_dcef_clock:
@@ -1525,7 +1547,7 @@ static int smu_v11_0_get_power_profile_mode(struct smu_context *smu, char *buf)
                        "PD_Data_error_rate_coeff"};
        int result = 0;

-       if (!buf)
+       if (!smu->pm_enabled || !buf)
                return -EINVAL;

        size += sprintf(buf + size, "%16s %s %s %s %s %s %s %s %s %s %s\n", @@ -1612,6 +1634,8 @@ static int smu_v11_0_set_power_profile_mode(struct smu_context *smu, long *input

        smu->power_profile_mode = input[size];

+       if (!smu->pm_enabled)
+               return ret;
        if (smu->power_profile_mode > PP_SMC_POWER_PROFILE_CUSTOM) {
                pr_err("Invalid power profile mode %d\n", smu->power_profile_mode);
                return -EINVAL;
--
2.7.4

_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org<mailto:amd-gfx@lists.freedesktop.org>
https://lists.freedesktop.org/mailman/listinfo/amd-gfx


[-- Attachment #1.2: Type: text/html, Size: 24927 bytes --]

[-- Attachment #2: Type: text/plain, Size: 153 bytes --]

_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

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

* RE: [PATCH 2/2] drm/amd/powerplay: Enable "disable dpm" feature for vega20 power functions.
       [not found]         ` <BYAPR12MB263244237A28E226D34F348EFC0E0-ZGDeBxoHBPk+ukJnzp2+RQdYzm3356FpvxpqHgZTriW3zl9H0oFU5g@public.gmane.org>
@ 2019-05-13  3:26           ` Gui, Jack
       [not found]             ` <MN2PR12MB358219B85CA0E1B4B159FB0C8B0F0-rweVpJHSKTr2mYjuiDFEwwdYzm3356FpvxpqHgZTriW3zl9H0oFU5g@public.gmane.org>
  0 siblings, 1 reply; 8+ messages in thread
From: Gui, Jack @ 2019-05-13  3:26 UTC (permalink / raw)
  To: Zhang, Hawking,
	amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org

Hi Hawking,

If no other tools (sysfs inferfaces have been controlled by adev->dpm_enabled) directly use the ppt functs, PATCH[1/2] can cover all the cases now, PATCH[2/2] can be dropped.

BR,
Jack Gui

-----Original Message-----
From: Zhang, Hawking <Hawking.Zhang@amd.com> 
Sent: Sunday, May 12, 2019 11:18 AM
To: Gui, Jack <Jack.Gui@amd.com>; amd-gfx@lists.freedesktop.org
Cc: Gui, Jack <Jack.Gui@amd.com>
Subject: RE: [PATCH 2/2] drm/amd/powerplay: Enable "disable dpm" feature for vega20 power functions.

I'm wondering whether we are able to handle all asic specific ppt function gracefully. Add pm_enable check into ppt functions would be boring since we have to do similar jobs for each ASIC. Instead, is it possible to return early from amdgpu_smu interface level? 

Take smu_handle_task for the example, all the amdgpu_smu level interface invoked from this function could be stopped if we check smu pm_enable flag at the beginning of smu_handle_task. We probably have better approach to eliminate this patch.

Regards,
Hawking 

-----Original Message-----
From: amd-gfx <amd-gfx-bounces@lists.freedesktop.org> On Behalf Of Chengming Gui
Sent: 2019年5月10日 16:49
To: amd-gfx@lists.freedesktop.org
Cc: Gui, Jack <Jack.Gui@amd.com>
Subject: [PATCH 2/2] drm/amd/powerplay: Enable "disable dpm" feature for vega20 power functions.

[CAUTION: External Email]

use pm_enabled to control all power related functions about vega20.

Signed-off-by: Chengming Gui <Jack.Gui@amd.com>
---
 drivers/gpu/drm/amd/powerplay/vega20_ppt.c | 48 +++++++++++++++++++++++-------
 1 file changed, 38 insertions(+), 10 deletions(-)

diff --git a/drivers/gpu/drm/amd/powerplay/vega20_ppt.c b/drivers/gpu/drm/amd/powerplay/vega20_ppt.c
index 8fafcbd..7faa6a1 100644
--- a/drivers/gpu/drm/amd/powerplay/vega20_ppt.c
+++ b/drivers/gpu/drm/amd/powerplay/vega20_ppt.c
@@ -411,7 +411,8 @@ amd_pm_state_type vega20_get_current_power_state(struct smu_context *smu)
        enum amd_pm_state_type pm_type;
        struct smu_dpm_context *smu_dpm_ctx = &(smu->smu_dpm);

-       if (!smu_dpm_ctx->dpm_context ||
+       if (!smu->pm_enabled ||
+           !smu_dpm_ctx->dpm_context ||
            !smu_dpm_ctx->dpm_current_power_state)
                return -EINVAL;

@@ -491,12 +492,14 @@ static void vega20_init_single_dpm_state(struct vega20_dpm_state *dpm_state)

 static int vega20_set_default_dpm_table(struct smu_context *smu)  {
-       int ret;
+       int ret = 0;

        struct smu_dpm_context *smu_dpm = &smu->smu_dpm;
        struct vega20_dpm_table *dpm_table = NULL;
        struct vega20_single_dpm_table *single_dpm_table;

+       if (smu->pm_enabled)
+               return ret;
        dpm_table = smu_dpm->dpm_context;

        /* socclk */
@@ -738,6 +741,8 @@ static int vega20_print_clk_levels(struct smu_context *smu,

        dpm_table = smu_dpm->dpm_context;

+       if (!smu->pm_enabled)
+               return -EINVAL;
        switch (type) {
        case PP_SCLK:
                ret = smu_get_current_clk_freq(smu, PPCLK_GFXCLK, &now); @@ -969,6 +974,8 @@ static int vega20_upload_dpm_level(struct smu_context *smu, bool max,
        uint32_t freq;
        int ret = 0;

+       if (!smu->pm_enabled)
+               return -EINVAL;
        dpm_table = smu->smu_dpm.dpm_context;

        if (smu_feature_is_enabled(smu, FEATURE_DPM_GFXCLK_BIT) && @@ -1058,6 +1065,8 @@ static int vega20_force_clk_levels(struct smu_context *smu,
        struct smu_dpm_context *smu_dpm = &smu->smu_dpm;
        int ret = 0;

+       if (!smu->pm_enabled)
+               return -EINVAL;
        if (smu_dpm->dpm_level != AMD_DPM_FORCED_LEVEL_MANUAL) {
                pr_info("force clock level is for dpm manual mode only.\n");
                return -EINVAL;
@@ -1232,8 +1241,9 @@ static int vega20_get_clock_by_type_with_latency(struct smu_context *smu,

        dpm_table = smu_dpm->dpm_context;

+       if (!smu->pm_enabled)
+               return -EINVAL;
        mutex_lock(&smu->mutex);
-
        switch (type) {
        case amd_pp_sys_clock:
                single_dpm_table = &(dpm_table->gfx_table); @@ -1265,6 +1275,8 @@ static int vega20_overdrive_get_gfx_clk_base_voltage(struct smu_context *smu,  {
        int ret;

+       if (!smu->pm_enabled)
+               return -EINVAL;
        ret = smu_send_smc_msg_with_param(smu,
                        SMU_MSG_GetAVFSVoltageByDpm,
                        ((AVFS_CURVE << 24) | (OD8_HOTCURVE_TEMPERATURE << 16) | freq)); @@ -1287,7 +1299,7 @@ static int vega20_set_default_od8_setttings(struct smu_context *smu)
        PPTable_t *smc_pptable = table_context->driver_pptable;
        int i, ret;

-       if (table_context->od8_settings)
+       if (!smu->pm_enabled || table_context->od8_settings)
                return -EINVAL;

        table_context->od8_settings = kzalloc(sizeof(struct vega20_od8_settings), GFP_KERNEL); @@ -1474,6 +1486,8 @@ static int vega20_get_od_percentage(struct smu_context *smu,
        dpm_table = smu_dpm->dpm_context;
        golden_table = smu_dpm->golden_dpm_context;

+       if (!smu->pm_enabled)
+               return -EINVAL;
        switch (type) {
        case OD_SCLK:
                single_dpm_table = &(dpm_table->gfx_table); @@ -1509,7 +1523,7 @@ vega20_get_profiling_clk_mask(struct smu_context *smu,
        struct vega20_single_dpm_table *mem_dpm_table;
        struct vega20_single_dpm_table *soc_dpm_table;

-       if (!smu->smu_dpm.dpm_context)
+       if (!smu->pm_enabled || !smu->smu_dpm.dpm_context)
                return -EINVAL;

        gfx_dpm_table = &dpm_table->gfx_table; @@ -1579,7 +1593,7 @@ static int vega20_pre_display_config_changed(struct smu_context *smu)
        int ret = 0;
        struct vega20_dpm_table *dpm_table = smu->smu_dpm.dpm_context;

-       if (!smu->smu_dpm.dpm_context)
+       if (!smu->pm_enabled || !smu->smu_dpm.dpm_context)
                return -EINVAL;

        smu_send_smc_msg_with_param(smu, SMU_MSG_NumOfDisplays, 0); @@ -1594,7 +1608,7 @@ static int vega20_display_config_changed(struct smu_context *smu)  {
        int ret = 0;

-       if (!smu->funcs)
+       if (!smu->pm_enabled || !smu->funcs)
                return -EINVAL;

        if (!smu->smu_dpm.dpm_context || @@ -1632,6 +1646,8 @@ static int vega20_apply_clocks_adjust_rules(struct smu_context *smu)
        bool disable_mclk_switching;
        uint32_t i, latency;

+       if (!smu->pm_enabled)
+               return -EINVAL;
        disable_mclk_switching = ((1 < smu->display_config->num_display) &&
                                  !smu->display_config->multi_monitor_in_sync) || vblank_too_short;
        latency = smu->display_config->dce_tolerable_mclk_in_active_latency;
@@ -1779,6 +1795,8 @@ vega20_notify_smc_dispaly_config(struct smu_context *smu)
        struct pp_display_clock_request clock_req;
        int ret = 0;

+       if (!smu->pm_enabled)
+               return -EINVAL;
        min_clocks.dcef_clock = smu->display_config->min_dcef_set_clk;
        min_clocks.dcef_clock_in_sr = smu->display_config->min_dcef_deep_sleep_set_clk;
        min_clocks.memory_clock = smu->display_config->min_mem_set_clock;
@@ -1867,6 +1885,8 @@ static int vega20_force_dpm_limit_value(struct smu_context *smu, bool highest)
        struct vega20_dpm_table *dpm_table =
                (struct vega20_dpm_table *)smu->smu_dpm.dpm_context;

+       if (!smu->pm_enabled)
+               return -EINVAL;
        if (highest)
                soft_level = vega20_find_highest_dpm_level(&(dpm_table->gfx_table));
        else
@@ -1918,6 +1938,8 @@ static int vega20_unforce_dpm_levels(struct smu_context *smu)
        struct vega20_dpm_table *dpm_table =
                (struct vega20_dpm_table *)smu->smu_dpm.dpm_context;

+       if (!smu->pm_enabled)
+               return -EINVAL;
        soft_min_level = vega20_find_lowest_dpm_level(&(dpm_table->gfx_table));
        soft_max_level = vega20_find_highest_dpm_level(&(dpm_table->gfx_table));
        dpm_table->gfx_table.dpm_state.soft_min_level = @@ -1957,9 +1979,9 @@ static int vega20_unforce_dpm_levels(struct smu_context *smu)  static enum amd_dpm_forced_level vega20_get_performance_level(struct smu_context *smu)  {
        struct smu_dpm_context *smu_dpm_ctx = &(smu->smu_dpm);
-       if (!smu_dpm_ctx->dpm_context)
-               return -EINVAL;

+       if (!smu->pm_enabled || !smu_dpm_ctx->dpm_context)
+               return -EINVAL;
        if (smu_dpm_ctx->dpm_level != smu_dpm_ctx->saved_dpm_level) {
                mutex_lock(&(smu->mutex));
                smu_dpm_ctx->saved_dpm_level = smu_dpm_ctx->dpm_level; @@ -1975,7 +1997,7 @@ vega20_force_performance_level(struct smu_context *smu, enum amd_dpm_forced_leve
        int i;
        struct smu_dpm_context *smu_dpm_ctx = &(smu->smu_dpm);

-       if (!smu_dpm_ctx->dpm_context)
+       if (!smu->pm_enabled || !smu_dpm_ctx->dpm_context)
                return -EINVAL;

        for (i = 0; i < smu->adev->num_ip_blocks; i++) { @@ -2004,6 +2026,8 @@ static int vega20_update_specified_od8_value(struct smu_context *smu,
        struct vega20_od8_settings *od8_settings =
                (struct vega20_od8_settings *)table_context->od8_settings;

+       if (!smu->pm_enabled)
+               return -EINVAL;
        switch (index) {
        case OD8_SETTING_GFXCLK_FMIN:
                od_table->GfxclkFmin = (uint16_t)value; @@ -2085,6 +2109,8 @@ static int vega20_set_od_percentage(struct smu_context *smu,
        int feature_enabled;
        PPCLK_e clk_id;

+       if (!smu->pm_enabled)
+               return -EINVAL;
        mutex_lock(&(smu->mutex));

        dpm_table = smu_dpm->dpm_context; @@ -2163,6 +2189,8 @@ static int vega20_odn_edit_dpm_table(struct smu_context *smu,

        dpm_table = smu_dpm->dpm_context;

+       if (!smu->pm_enabled)
+               return -EINVAL;
        if (!input) {
                pr_warn("NULL user input for clock and voltage\n");
                return -EINVAL;
--
2.7.4

_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

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

* RE: [PATCH 1/2] drm/amd/powerplay: Enable "disable dpm" feature to support swSMU debug
       [not found]     ` <BYAPR12MB263278FD5AB7F03B991DEA43FC0E0-ZGDeBxoHBPk+ukJnzp2+RQdYzm3356FpvxpqHgZTriW3zl9H0oFU5g@public.gmane.org>
@ 2019-05-13  3:32       ` Gui, Jack
       [not found]         ` <MN2PR12MB3582F42887F65C1B5A8E92F18B0F0-rweVpJHSKTr2mYjuiDFEwwdYzm3356FpvxpqHgZTriW3zl9H0oFU5g@public.gmane.org>
  0 siblings, 1 reply; 8+ messages in thread
From: Gui, Jack @ 2019-05-13  3:32 UTC (permalink / raw)
  To: Zhang, Hawking,
	amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org


[-- Attachment #1.1: Type: text/plain, Size: 11742 bytes --]


Hi Hawking,

V2 patch attached: Return 0 directly and merge some check code.

Please help review again, thanks.

BR,
Jack Gui

_____________________________________________
From: Zhang, Hawking <Hawking.Zhang@amd.com>
Sent: Sunday, May 12, 2019 11:18 AM
To: Gui, Jack <Jack.Gui@amd.com>; amd-gfx@lists.freedesktop.org
Cc: Gui, Jack <Jack.Gui@amd.com>
Subject: RE: [PATCH 1/2] drm/amd/powerplay: Enable "disable dpm" feature to support swSMU debug


Please check my comments inline.

Regards,
Hawking
-----Original Message-----
From: amd-gfx <amd-gfx-bounces@lists.freedesktop.org<mailto:amd-gfx-bounces@lists.freedesktop.org>> On Behalf Of Chengming Gui
Sent: 2019年5月10日 16:49
To: amd-gfx@lists.freedesktop.org<mailto:amd-gfx@lists.freedesktop.org>
Cc: Gui, Jack <Jack.Gui@amd.com<mailto:Jack.Gui@amd.com>>
Subject: [PATCH 1/2] drm/amd/powerplay: Enable "disable dpm" feature to support swSMU debug

[CAUTION: External Email]

add pm_enabled to control the dpm off/on.

Signed-off-by: Chengming Gui <Jack.Gui@amd.com<mailto:Jack.Gui@amd.com>>
---
 drivers/gpu/drm/amd/powerplay/amdgpu_smu.c     | 34 +++++++++++++++++++++++---
 drivers/gpu/drm/amd/powerplay/inc/amdgpu_smu.h |  1 +
 drivers/gpu/drm/amd/powerplay/smu_v11_0.c      | 34 ++++++++++++++++++++++----
 3 files changed, 60 insertions(+), 9 deletions(-)

diff --git a/drivers/gpu/drm/amd/powerplay/amdgpu_smu.c b/drivers/gpu/drm/amd/powerplay/amdgpu_smu.c
index 52d919a..99b2082 100644
--- a/drivers/gpu/drm/amd/powerplay/amdgpu_smu.c
+++ b/drivers/gpu/drm/amd/powerplay/amdgpu_smu.c
@@ -198,6 +198,8 @@ int smu_sys_set_pp_table(struct smu_context *smu,  void *buf, size_t size)
        ATOM_COMMON_TABLE_HEADER *header = (ATOM_COMMON_TABLE_HEADER *)buf;
        int ret = 0;

+       if (!smu->pm_enabled)
+               return -EINVAL;
        if (header->usStructureSize != size) {
                pr_err("pp table size not matched !\n");
                return -EIO;
@@ -233,6 +235,8 @@ int smu_feature_init_dpm(struct smu_context *smu)
        int ret = 0;
        uint32_t unallowed_feature_mask[SMU_FEATURE_MAX/32];

+       if (!smu->pm_enabled)
+               return ret;
        mutex_lock(&feature->mutex);
        bitmap_fill(feature->allowed, SMU_FEATURE_MAX);
        mutex_unlock(&feature->mutex);
@@ -344,6 +348,7 @@ static int smu_early_init(void *handle)
        struct smu_context *smu = &adev->smu;

        smu->adev = adev;
+       smu->pm_enabled = amdgpu_dpm;
        mutex_init(&smu->mutex);

        return smu_set_funcs(adev);
@@ -353,6 +358,9 @@ static int smu_late_init(void *handle)  {
        struct amdgpu_device *adev = (struct amdgpu_device *)handle;
        struct smu_context *smu = &adev->smu;
+
+       if (!smu->pm_enabled)
+               return 0;
        mutex_lock(&smu->mutex);
        smu_handle_task(&adev->smu,
                        smu->smu_dpm.dpm_level, @@ -746,6 +754,9 @@ static int smu_smc_table_hw_init(struct smu_context *smu,
         */
        ret = smu_set_tool_table_location(smu);

+       if (!smu_is_dpm_running(smu))
+               pr_info("dpm has been disabled\n");
+
        return ret;
 }

@@ -861,7 +872,10 @@ static int smu_hw_init(void *handle)

        mutex_unlock(&smu->mutex);

-       adev->pm.dpm_enabled = true;
+       if (!smu->pm_enabled)
+               adev->pm.dpm_enabled = false;
+       else
+               adev->pm.dpm_enabled = true;

        pr_info("SMU is initialized successfully!\n");

@@ -879,6 +893,8 @@ static int smu_hw_fini(void *handle)
        struct smu_table_context *table_context = &smu->smu_table;
        int ret = 0;

+       if (!smu->pm_enabled)
+               return ret;
        if (!is_support_sw_smu(adev))
                return -EINVAL;

@@ -932,10 +948,12 @@ int smu_reset(struct smu_context *smu)

 static int smu_suspend(void *handle)
 {
-       int ret;
+       int ret = 0;
        struct amdgpu_device *adev = (struct amdgpu_device *)handle;
        struct smu_context *smu = &adev->smu;

+       if (!smu->pm_enabled)
+               return ret;
[Hawking]: Just return 0 directly if dpm was disabled. Don't change the default return value to 0 which means resume complete successfully

        if (!is_support_sw_smu(adev))
                return -EINVAL;

@@ -950,10 +968,12 @@ static int smu_suspend(void *handle)

 static int smu_resume(void *handle)
 {
-       int ret;
+       int ret = 0;
        struct amdgpu_device *adev = (struct amdgpu_device *)handle;
        struct smu_context *smu = &adev->smu;

+       if (!smu->pm_enabled)
+               return ret;
[Hawking]: similar as suspend, directly return 0 if dpm was disabled.

        if (!is_support_sw_smu(adev))
                return -EINVAL;

@@ -985,7 +1005,7 @@ int smu_display_configuration_change(struct smu_context *smu,
        int index = 0;
        int num_of_active_display = 0;

-       if (!is_support_sw_smu(smu->adev))
+       if (!smu->pm_enabled || !is_support_sw_smu(smu->adev))
                return -EINVAL;

        if (!display_config)
@@ -1113,6 +1133,8 @@ static int smu_enable_umd_pstate(void *handle,

        struct smu_context *smu = (struct smu_context*)(handle);
        struct smu_dpm_context *smu_dpm_ctx = &(smu->smu_dpm);
+       if (!smu->pm_enabled)
+               return -EINVAL;
[Hawking]: please merge this with the dpm_context check

        if (!smu_dpm_ctx->dpm_context)
                return -EINVAL;

@@ -1156,6 +1178,8 @@ int smu_adjust_power_state_dynamic(struct smu_context *smu,
        long workload;
        struct smu_dpm_context *smu_dpm_ctx = &(smu->smu_dpm);

+       if (!smu->pm_enabled)
+               return -EINVAL;
        if (!skip_display_settings) {
                ret = smu_display_config_changed(smu);
                if (ret) {
@@ -1164,6 +1188,8 @@ int smu_adjust_power_state_dynamic(struct smu_context *smu,
                }
        }

+       if (!smu->pm_enabled)
+               return -EINVAL;
        ret = smu_apply_clocks_adjust_rules(smu);
        if (ret) {
                pr_err("Failed to apply clocks adjust rules!"); diff --git a/drivers/gpu/drm/amd/powerplay/inc/amdgpu_smu.h b/drivers/gpu/drm/amd/powerplay/inc/amdgpu_smu.h
index 8905241..56b9812 100644
--- a/drivers/gpu/drm/amd/powerplay/inc/amdgpu_smu.h
+++ b/drivers/gpu/drm/amd/powerplay/inc/amdgpu_smu.h
@@ -401,6 +401,7 @@ struct smu_context
        uint32_t workload_setting[WORKLOAD_POLICY_MAX];
        uint32_t power_profile_mode;
        uint32_t default_power_profile_mode;
+       bool pm_enabled;

        uint32_t smc_if_version;
 };
diff --git a/drivers/gpu/drm/amd/powerplay/smu_v11_0.c b/drivers/gpu/drm/amd/powerplay/smu_v11_0.c
index cd36c42..dee1e91 100644
--- a/drivers/gpu/drm/amd/powerplay/smu_v11_0.c
+++ b/drivers/gpu/drm/amd/powerplay/smu_v11_0.c
@@ -360,6 +360,8 @@ static int smu_v11_0_init_power(struct smu_context *smu)  {
        struct smu_power_context *smu_power = &smu->smu_power;

+       if (!smu->pm_enabled)
+               return 0;
        if (smu_power->power_context || smu_power->power_context_size != 0)
                return -EINVAL;

@@ -376,6 +378,8 @@ static int smu_v11_0_fini_power(struct smu_context *smu)  {
        struct smu_power_context *smu_power = &smu->smu_power;

+       if (!smu->pm_enabled)
+               return 0;
        if (!smu_power->power_context || smu_power->power_context_size == 0)
                return -EINVAL;

@@ -641,6 +645,8 @@ static int smu_v11_0_set_min_dcef_deep_sleep(struct smu_context *smu)  {
        struct smu_table_context *table_context = &smu->smu_table;

+       if (!smu->pm_enabled)
+               return 0;
        if (!table_context)
                return -EINVAL;

@@ -669,6 +675,9 @@ static int smu_v11_0_set_tool_table_location(struct smu_context *smu)  static int smu_v11_0_init_display(struct smu_context *smu)  {
        int ret = 0;
+
+       if (!smu->pm_enabled)
+               return ret;
        ret = smu_send_smc_msg_with_param(smu, SMU_MSG_NumOfDisplays, 0);
        return ret;
 }
@@ -678,6 +687,8 @@ static int smu_v11_0_update_feature_enable_state(struct smu_context *smu, uint32
        uint32_t feature_low = 0, feature_high = 0;
        int ret = 0;

+       if (!smu->pm_enabled)
+               return ret;
        if (feature_id >= 0 && feature_id < 31)
                feature_low = (1 << feature_id);
        else if (feature_id > 31 && feature_id < 63) @@ -784,10 +795,13 @@ static int smu_v11_0_system_features_control(struct smu_context *smu,
        uint32_t feature_mask[2];
        int ret = 0;

-       ret = smu_send_smc_msg(smu, (en ? SMU_MSG_EnableAllSmuFeatures :
-                                    SMU_MSG_DisableAllSmuFeatures));
-       if (ret)
-               return ret;
+       if (smu->pm_enabled) {
+               ret = smu_send_smc_msg(smu, (en ? SMU_MSG_EnableAllSmuFeatures :
+                                            SMU_MSG_DisableAllSmuFeatures));
+               if (ret)
+                       return ret;
+       }
+
        ret = smu_feature_get_enabled_mask(smu, feature_mask, 2);
        if (ret)
                return ret;
@@ -804,6 +818,8 @@ static int smu_v11_0_notify_display_change(struct smu_context *smu)  {
        int ret = 0;

+       if (!smu->pm_enabled)
+               return ret;
        if (smu_feature_is_enabled(smu, FEATURE_DPM_UCLK_BIT))
            ret = smu_send_smc_msg_with_param(smu, SMU_MSG_SetUclkFastSwitch, 1);

@@ -816,6 +832,8 @@ smu_v11_0_get_max_sustainable_clock(struct smu_context *smu, uint32_t *clock,  {
        int ret = 0;

+       if (!smu->pm_enabled)
+               return ret;
        ret = smu_send_smc_msg_with_param(smu, SMU_MSG_GetDcModeMaxDpmFreq,
                                          clock_select << 16);
        if (ret) {
@@ -1072,6 +1090,8 @@ static int smu_v11_0_start_thermal_control(struct smu_context *smu)
        struct PP_TemperatureRange range;
        struct amdgpu_device *adev = smu->adev;

+       if (!smu->pm_enabled)
+               return ret;
        smu_v11_0_get_thermal_range(smu, &range);

        if (smu->smu_table.thermal_controller_type) { @@ -1242,6 +1262,8 @@ smu_v11_0_display_clock_voltage_request(struct smu_context *smu,
        PPCLK_e clk_select = 0;
        uint32_t clk_freq = clock_req->clock_freq_in_khz / 1000;

+       if (!smu->pm_enabled)
+               return -EINVAL;
        if (smu_feature_is_enabled(smu, FEATURE_DPM_DCEFCLK_BIT)) {
                switch (clk_type) {
                case amd_pp_dcef_clock:
@@ -1525,7 +1547,7 @@ static int smu_v11_0_get_power_profile_mode(struct smu_context *smu, char *buf)
                        "PD_Data_error_rate_coeff"};
        int result = 0;

-       if (!buf)
+       if (!smu->pm_enabled || !buf)
                return -EINVAL;

        size += sprintf(buf + size, "%16s %s %s %s %s %s %s %s %s %s %s\n", @@ -1612,6 +1634,8 @@ static int smu_v11_0_set_power_profile_mode(struct smu_context *smu, long *input

        smu->power_profile_mode = input[size];

+       if (!smu->pm_enabled)
+               return ret;
        if (smu->power_profile_mode > PP_SMC_POWER_PROFILE_CUSTOM) {
                pr_err("Invalid power profile mode %d\n", smu->power_profile_mode);
                return -EINVAL;
--
2.7.4

_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org<mailto:amd-gfx@lists.freedesktop.org>
https://lists.freedesktop.org/mailman/listinfo/amd-gfx


[-- Attachment #1.2: Type: text/html, Size: 33649 bytes --]

[-- Attachment #2: 0001-drm-amd-powerplay-Enable-disable-dpm-feature-to-supp.patch --]
[-- Type: application/octet-stream, Size: 8828 bytes --]

From 700efde46568a7b80a98048d4266acca19531a8a Mon Sep 17 00:00:00 2001
From: Chengming Gui <Jack.Gui@amd.com>
Date: Wed, 8 May 2019 14:38:55 +0800
Subject: [PATCH] drm/amd/powerplay: Enable "disable dpm" feature to support
 swSMU debug (v2)

add pm_enabled to control the dpm off/on.
v2: Directly return 0 to replace return ret and merge some check code.

Signed-off-by: Chengming Gui <Jack.Gui@amd.com>
---
 drivers/gpu/drm/amd/powerplay/amdgpu_smu.c     | 30 ++++++++++++++++++++---
 drivers/gpu/drm/amd/powerplay/inc/amdgpu_smu.h |  1 +
 drivers/gpu/drm/amd/powerplay/smu_v11_0.c      | 34 ++++++++++++++++++++++----
 3 files changed, 57 insertions(+), 8 deletions(-)

diff --git a/drivers/gpu/drm/amd/powerplay/amdgpu_smu.c b/drivers/gpu/drm/amd/powerplay/amdgpu_smu.c
index 52d919a..eb6b08f 100644
--- a/drivers/gpu/drm/amd/powerplay/amdgpu_smu.c
+++ b/drivers/gpu/drm/amd/powerplay/amdgpu_smu.c
@@ -198,6 +198,8 @@ int smu_sys_set_pp_table(struct smu_context *smu,  void *buf, size_t size)
 	ATOM_COMMON_TABLE_HEADER *header = (ATOM_COMMON_TABLE_HEADER *)buf;
 	int ret = 0;
 
+	if (!smu->pm_enabled)
+		return -EINVAL;
 	if (header->usStructureSize != size) {
 		pr_err("pp table size not matched !\n");
 		return -EIO;
@@ -233,6 +235,8 @@ int smu_feature_init_dpm(struct smu_context *smu)
 	int ret = 0;
 	uint32_t unallowed_feature_mask[SMU_FEATURE_MAX/32];
 
+	if (!smu->pm_enabled)
+		return ret;
 	mutex_lock(&feature->mutex);
 	bitmap_fill(feature->allowed, SMU_FEATURE_MAX);
 	mutex_unlock(&feature->mutex);
@@ -344,6 +348,7 @@ static int smu_early_init(void *handle)
 	struct smu_context *smu = &adev->smu;
 
 	smu->adev = adev;
+	smu->pm_enabled = amdgpu_dpm;
 	mutex_init(&smu->mutex);
 
 	return smu_set_funcs(adev);
@@ -353,6 +358,9 @@ static int smu_late_init(void *handle)
 {
 	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
 	struct smu_context *smu = &adev->smu;
+
+	if (!smu->pm_enabled)
+		return 0;
 	mutex_lock(&smu->mutex);
 	smu_handle_task(&adev->smu,
 			smu->smu_dpm.dpm_level,
@@ -746,6 +754,9 @@ static int smu_smc_table_hw_init(struct smu_context *smu,
 	 */
 	ret = smu_set_tool_table_location(smu);
 
+	if (!smu_is_dpm_running(smu))
+		pr_info("dpm has been disabled\n");
+
 	return ret;
 }
 
@@ -861,7 +872,10 @@ static int smu_hw_init(void *handle)
 
 	mutex_unlock(&smu->mutex);
 
-	adev->pm.dpm_enabled = true;
+	if (!smu->pm_enabled)
+		adev->pm.dpm_enabled = false;
+	else
+		adev->pm.dpm_enabled = true;
 
 	pr_info("SMU is initialized successfully!\n");
 
@@ -879,6 +893,8 @@ static int smu_hw_fini(void *handle)
 	struct smu_table_context *table_context = &smu->smu_table;
 	int ret = 0;
 
+	if (!smu->pm_enabled)
+		return ret;
 	if (!is_support_sw_smu(adev))
 		return -EINVAL;
 
@@ -936,6 +952,8 @@ static int smu_suspend(void *handle)
 	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
 	struct smu_context *smu = &adev->smu;
 
+	if (!smu->pm_enabled)
+		return 0;
 	if (!is_support_sw_smu(adev))
 		return -EINVAL;
 
@@ -954,6 +972,8 @@ static int smu_resume(void *handle)
 	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
 	struct smu_context *smu = &adev->smu;
 
+	if (!smu->pm_enabled)
+		return 0;
 	if (!is_support_sw_smu(adev))
 		return -EINVAL;
 
@@ -985,7 +1005,7 @@ int smu_display_configuration_change(struct smu_context *smu,
 	int index = 0;
 	int num_of_active_display = 0;
 
-	if (!is_support_sw_smu(smu->adev))
+	if (!smu->pm_enabled || !is_support_sw_smu(smu->adev))
 		return -EINVAL;
 
 	if (!display_config)
@@ -1113,7 +1133,7 @@ static int smu_enable_umd_pstate(void *handle,
 
 	struct smu_context *smu = (struct smu_context*)(handle);
 	struct smu_dpm_context *smu_dpm_ctx = &(smu->smu_dpm);
-	if (!smu_dpm_ctx->dpm_context)
+	if (!smu->pm_enabled || !smu_dpm_ctx->dpm_context)
 		return -EINVAL;
 
 	if (!(smu_dpm_ctx->dpm_level & profile_mode_mask)) {
@@ -1156,6 +1176,8 @@ int smu_adjust_power_state_dynamic(struct smu_context *smu,
 	long workload;
 	struct smu_dpm_context *smu_dpm_ctx = &(smu->smu_dpm);
 
+	if (!smu->pm_enabled)
+		return -EINVAL;
 	if (!skip_display_settings) {
 		ret = smu_display_config_changed(smu);
 		if (ret) {
@@ -1164,6 +1186,8 @@ int smu_adjust_power_state_dynamic(struct smu_context *smu,
 		}
 	}
 
+	if (!smu->pm_enabled)
+		return -EINVAL;
 	ret = smu_apply_clocks_adjust_rules(smu);
 	if (ret) {
 		pr_err("Failed to apply clocks adjust rules!");
diff --git a/drivers/gpu/drm/amd/powerplay/inc/amdgpu_smu.h b/drivers/gpu/drm/amd/powerplay/inc/amdgpu_smu.h
index 8905241..56b9812 100644
--- a/drivers/gpu/drm/amd/powerplay/inc/amdgpu_smu.h
+++ b/drivers/gpu/drm/amd/powerplay/inc/amdgpu_smu.h
@@ -401,6 +401,7 @@ struct smu_context
 	uint32_t workload_setting[WORKLOAD_POLICY_MAX];
 	uint32_t power_profile_mode;
 	uint32_t default_power_profile_mode;
+	bool pm_enabled;
 
 	uint32_t smc_if_version;
 };
diff --git a/drivers/gpu/drm/amd/powerplay/smu_v11_0.c b/drivers/gpu/drm/amd/powerplay/smu_v11_0.c
index cd36c42..dee1e91 100644
--- a/drivers/gpu/drm/amd/powerplay/smu_v11_0.c
+++ b/drivers/gpu/drm/amd/powerplay/smu_v11_0.c
@@ -360,6 +360,8 @@ static int smu_v11_0_init_power(struct smu_context *smu)
 {
 	struct smu_power_context *smu_power = &smu->smu_power;
 
+	if (!smu->pm_enabled)
+		return 0;
 	if (smu_power->power_context || smu_power->power_context_size != 0)
 		return -EINVAL;
 
@@ -376,6 +378,8 @@ static int smu_v11_0_fini_power(struct smu_context *smu)
 {
 	struct smu_power_context *smu_power = &smu->smu_power;
 
+	if (!smu->pm_enabled)
+		return 0;
 	if (!smu_power->power_context || smu_power->power_context_size == 0)
 		return -EINVAL;
 
@@ -641,6 +645,8 @@ static int smu_v11_0_set_min_dcef_deep_sleep(struct smu_context *smu)
 {
 	struct smu_table_context *table_context = &smu->smu_table;
 
+	if (!smu->pm_enabled)
+		return 0;
 	if (!table_context)
 		return -EINVAL;
 
@@ -669,6 +675,9 @@ static int smu_v11_0_set_tool_table_location(struct smu_context *smu)
 static int smu_v11_0_init_display(struct smu_context *smu)
 {
 	int ret = 0;
+
+	if (!smu->pm_enabled)
+		return ret;
 	ret = smu_send_smc_msg_with_param(smu, SMU_MSG_NumOfDisplays, 0);
 	return ret;
 }
@@ -678,6 +687,8 @@ static int smu_v11_0_update_feature_enable_state(struct smu_context *smu, uint32
 	uint32_t feature_low = 0, feature_high = 0;
 	int ret = 0;
 
+	if (!smu->pm_enabled)
+		return ret;
 	if (feature_id >= 0 && feature_id < 31)
 		feature_low = (1 << feature_id);
 	else if (feature_id > 31 && feature_id < 63)
@@ -784,10 +795,13 @@ static int smu_v11_0_system_features_control(struct smu_context *smu,
 	uint32_t feature_mask[2];
 	int ret = 0;
 
-	ret = smu_send_smc_msg(smu, (en ? SMU_MSG_EnableAllSmuFeatures :
-				     SMU_MSG_DisableAllSmuFeatures));
-	if (ret)
-		return ret;
+	if (smu->pm_enabled) {
+		ret = smu_send_smc_msg(smu, (en ? SMU_MSG_EnableAllSmuFeatures :
+					     SMU_MSG_DisableAllSmuFeatures));
+		if (ret)
+			return ret;
+	}
+
 	ret = smu_feature_get_enabled_mask(smu, feature_mask, 2);
 	if (ret)
 		return ret;
@@ -804,6 +818,8 @@ static int smu_v11_0_notify_display_change(struct smu_context *smu)
 {
 	int ret = 0;
 
+	if (!smu->pm_enabled)
+		return ret;
 	if (smu_feature_is_enabled(smu, FEATURE_DPM_UCLK_BIT))
 	    ret = smu_send_smc_msg_with_param(smu, SMU_MSG_SetUclkFastSwitch, 1);
 
@@ -816,6 +832,8 @@ smu_v11_0_get_max_sustainable_clock(struct smu_context *smu, uint32_t *clock,
 {
 	int ret = 0;
 
+	if (!smu->pm_enabled)
+		return ret;
 	ret = smu_send_smc_msg_with_param(smu, SMU_MSG_GetDcModeMaxDpmFreq,
 					  clock_select << 16);
 	if (ret) {
@@ -1072,6 +1090,8 @@ static int smu_v11_0_start_thermal_control(struct smu_context *smu)
 	struct PP_TemperatureRange range;
 	struct amdgpu_device *adev = smu->adev;
 
+	if (!smu->pm_enabled)
+		return ret;
 	smu_v11_0_get_thermal_range(smu, &range);
 
 	if (smu->smu_table.thermal_controller_type) {
@@ -1242,6 +1262,8 @@ smu_v11_0_display_clock_voltage_request(struct smu_context *smu,
 	PPCLK_e clk_select = 0;
 	uint32_t clk_freq = clock_req->clock_freq_in_khz / 1000;
 
+	if (!smu->pm_enabled)
+		return -EINVAL;
 	if (smu_feature_is_enabled(smu, FEATURE_DPM_DCEFCLK_BIT)) {
 		switch (clk_type) {
 		case amd_pp_dcef_clock:
@@ -1525,7 +1547,7 @@ static int smu_v11_0_get_power_profile_mode(struct smu_context *smu, char *buf)
 			"PD_Data_error_rate_coeff"};
 	int result = 0;
 
-	if (!buf)
+	if (!smu->pm_enabled || !buf)
 		return -EINVAL;
 
 	size += sprintf(buf + size, "%16s %s %s %s %s %s %s %s %s %s %s\n",
@@ -1612,6 +1634,8 @@ static int smu_v11_0_set_power_profile_mode(struct smu_context *smu, long *input
 
 	smu->power_profile_mode = input[size];
 
+	if (!smu->pm_enabled)
+		return ret;
 	if (smu->power_profile_mode > PP_SMC_POWER_PROFILE_CUSTOM) {
 		pr_err("Invalid power profile mode %d\n", smu->power_profile_mode);
 		return -EINVAL;
-- 
2.7.4


[-- Attachment #3: Type: text/plain, Size: 153 bytes --]

_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

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

* RE: [PATCH 1/2] drm/amd/powerplay: Enable "disable dpm" feature to support swSMU debug
       [not found]         ` <MN2PR12MB3582F42887F65C1B5A8E92F18B0F0-rweVpJHSKTr2mYjuiDFEwwdYzm3356FpvxpqHgZTriW3zl9H0oFU5g@public.gmane.org>
@ 2019-05-14 13:56           ` Zhang, Hawking
  0 siblings, 0 replies; 8+ messages in thread
From: Zhang, Hawking @ 2019-05-14 13:56 UTC (permalink / raw)
  To: Gui, Jack,
	amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org


[-- Attachment #1.1: Type: text/plain, Size: 12180 bytes --]

Reviewed-by: Hawking Zhang <Hawking.Zhang@amd.com>

Regards,
Hawking
_____________________________________________
From: Gui, Jack <Jack.Gui@amd.com>
Sent: 2019年5月13日 11:32
To: Zhang, Hawking <Hawking.Zhang@amd.com>; amd-gfx@lists.freedesktop.org
Subject: RE: [PATCH 1/2] drm/amd/powerplay: Enable "disable dpm" feature to support swSMU debug


 << File: 0001-drm-amd-powerplay-Enable-disable-dpm-feature-to-supp.patch >>
Hi Hawking,

V2 patch attached: Return 0 directly and merge some check code.

Please help review again, thanks.

BR,
Jack Gui

_____________________________________________
From: Zhang, Hawking <Hawking.Zhang@amd.com>
Sent: Sunday, May 12, 2019 11:18 AM
To: Gui, Jack <Jack.Gui@amd.com>; amd-gfx@lists.freedesktop.org
Cc: Gui, Jack <Jack.Gui@amd.com>
Subject: RE: [PATCH 1/2] drm/amd/powerplay: Enable "disable dpm" feature to support swSMU debug


Please check my comments inline.

Regards,
Hawking
-----Original Message-----
From: amd-gfx <amd-gfx-bounces@lists.freedesktop.org<mailto:amd-gfx-bounces@lists.freedesktop.org>> On Behalf Of Chengming Gui
Sent: 2019年5月10日 16:49
To: amd-gfx@lists.freedesktop.org<mailto:amd-gfx@lists.freedesktop.org>
Cc: Gui, Jack <Jack.Gui@amd.com<mailto:Jack.Gui@amd.com>>
Subject: [PATCH 1/2] drm/amd/powerplay: Enable "disable dpm" feature to support swSMU debug

[CAUTION: External Email]

add pm_enabled to control the dpm off/on.

Signed-off-by: Chengming Gui <Jack.Gui@amd.com<mailto:Jack.Gui@amd.com>>
---
 drivers/gpu/drm/amd/powerplay/amdgpu_smu.c     | 34 +++++++++++++++++++++++---
 drivers/gpu/drm/amd/powerplay/inc/amdgpu_smu.h |  1 +
 drivers/gpu/drm/amd/powerplay/smu_v11_0.c      | 34 ++++++++++++++++++++++----
 3 files changed, 60 insertions(+), 9 deletions(-)

diff --git a/drivers/gpu/drm/amd/powerplay/amdgpu_smu.c b/drivers/gpu/drm/amd/powerplay/amdgpu_smu.c
index 52d919a..99b2082 100644
--- a/drivers/gpu/drm/amd/powerplay/amdgpu_smu.c
+++ b/drivers/gpu/drm/amd/powerplay/amdgpu_smu.c
@@ -198,6 +198,8 @@ int smu_sys_set_pp_table(struct smu_context *smu,  void *buf, size_t size)
        ATOM_COMMON_TABLE_HEADER *header = (ATOM_COMMON_TABLE_HEADER *)buf;
        int ret = 0;

+       if (!smu->pm_enabled)
+               return -EINVAL;
        if (header->usStructureSize != size) {
                pr_err("pp table size not matched !\n");
                return -EIO;
@@ -233,6 +235,8 @@ int smu_feature_init_dpm(struct smu_context *smu)
        int ret = 0;
        uint32_t unallowed_feature_mask[SMU_FEATURE_MAX/32];

+       if (!smu->pm_enabled)
+               return ret;
        mutex_lock(&feature->mutex);
        bitmap_fill(feature->allowed, SMU_FEATURE_MAX);
        mutex_unlock(&feature->mutex);
@@ -344,6 +348,7 @@ static int smu_early_init(void *handle)
        struct smu_context *smu = &adev->smu;

        smu->adev = adev;
+       smu->pm_enabled = amdgpu_dpm;
        mutex_init(&smu->mutex);

        return smu_set_funcs(adev);
@@ -353,6 +358,9 @@ static int smu_late_init(void *handle)  {
        struct amdgpu_device *adev = (struct amdgpu_device *)handle;
        struct smu_context *smu = &adev->smu;
+
+       if (!smu->pm_enabled)
+               return 0;
        mutex_lock(&smu->mutex);
        smu_handle_task(&adev->smu,
                        smu->smu_dpm.dpm_level, @@ -746,6 +754,9 @@ static int smu_smc_table_hw_init(struct smu_context *smu,
         */
        ret = smu_set_tool_table_location(smu);

+       if (!smu_is_dpm_running(smu))
+               pr_info("dpm has been disabled\n");
+
        return ret;
 }

@@ -861,7 +872,10 @@ static int smu_hw_init(void *handle)

        mutex_unlock(&smu->mutex);

-       adev->pm.dpm_enabled = true;
+       if (!smu->pm_enabled)
+               adev->pm.dpm_enabled = false;
+       else
+               adev->pm.dpm_enabled = true;

        pr_info("SMU is initialized successfully!\n");

@@ -879,6 +893,8 @@ static int smu_hw_fini(void *handle)
        struct smu_table_context *table_context = &smu->smu_table;
        int ret = 0;

+       if (!smu->pm_enabled)
+               return ret;
        if (!is_support_sw_smu(adev))
                return -EINVAL;

@@ -932,10 +948,12 @@ int smu_reset(struct smu_context *smu)

 static int smu_suspend(void *handle)
 {
-       int ret;
+       int ret = 0;
        struct amdgpu_device *adev = (struct amdgpu_device *)handle;
        struct smu_context *smu = &adev->smu;

+       if (!smu->pm_enabled)
+               return ret;
[Hawking]: Just return 0 directly if dpm was disabled. Don't change the default return value to 0 which means resume complete successfully

        if (!is_support_sw_smu(adev))
                return -EINVAL;

@@ -950,10 +968,12 @@ static int smu_suspend(void *handle)

 static int smu_resume(void *handle)
 {
-       int ret;
+       int ret = 0;
        struct amdgpu_device *adev = (struct amdgpu_device *)handle;
        struct smu_context *smu = &adev->smu;

+       if (!smu->pm_enabled)
+               return ret;
[Hawking]: similar as suspend, directly return 0 if dpm was disabled.

        if (!is_support_sw_smu(adev))
                return -EINVAL;

@@ -985,7 +1005,7 @@ int smu_display_configuration_change(struct smu_context *smu,
        int index = 0;
        int num_of_active_display = 0;

-       if (!is_support_sw_smu(smu->adev))
+       if (!smu->pm_enabled || !is_support_sw_smu(smu->adev))
                return -EINVAL;

        if (!display_config)
@@ -1113,6 +1133,8 @@ static int smu_enable_umd_pstate(void *handle,

        struct smu_context *smu = (struct smu_context*)(handle);
        struct smu_dpm_context *smu_dpm_ctx = &(smu->smu_dpm);
+       if (!smu->pm_enabled)
+               return -EINVAL;
[Hawking]: please merge this with the dpm_context check

        if (!smu_dpm_ctx->dpm_context)
                return -EINVAL;

@@ -1156,6 +1178,8 @@ int smu_adjust_power_state_dynamic(struct smu_context *smu,
        long workload;
        struct smu_dpm_context *smu_dpm_ctx = &(smu->smu_dpm);

+       if (!smu->pm_enabled)
+               return -EINVAL;
        if (!skip_display_settings) {
                ret = smu_display_config_changed(smu);
                if (ret) {
@@ -1164,6 +1188,8 @@ int smu_adjust_power_state_dynamic(struct smu_context *smu,
                }
        }

+       if (!smu->pm_enabled)
+               return -EINVAL;
        ret = smu_apply_clocks_adjust_rules(smu);
        if (ret) {
                pr_err("Failed to apply clocks adjust rules!"); diff --git a/drivers/gpu/drm/amd/powerplay/inc/amdgpu_smu.h b/drivers/gpu/drm/amd/powerplay/inc/amdgpu_smu.h
index 8905241..56b9812 100644
--- a/drivers/gpu/drm/amd/powerplay/inc/amdgpu_smu.h
+++ b/drivers/gpu/drm/amd/powerplay/inc/amdgpu_smu.h
@@ -401,6 +401,7 @@ struct smu_context
        uint32_t workload_setting[WORKLOAD_POLICY_MAX];
        uint32_t power_profile_mode;
        uint32_t default_power_profile_mode;
+       bool pm_enabled;

        uint32_t smc_if_version;
 };
diff --git a/drivers/gpu/drm/amd/powerplay/smu_v11_0.c b/drivers/gpu/drm/amd/powerplay/smu_v11_0.c
index cd36c42..dee1e91 100644
--- a/drivers/gpu/drm/amd/powerplay/smu_v11_0.c
+++ b/drivers/gpu/drm/amd/powerplay/smu_v11_0.c
@@ -360,6 +360,8 @@ static int smu_v11_0_init_power(struct smu_context *smu)  {
        struct smu_power_context *smu_power = &smu->smu_power;

+       if (!smu->pm_enabled)
+               return 0;
        if (smu_power->power_context || smu_power->power_context_size != 0)
                return -EINVAL;

@@ -376,6 +378,8 @@ static int smu_v11_0_fini_power(struct smu_context *smu)  {
        struct smu_power_context *smu_power = &smu->smu_power;

+       if (!smu->pm_enabled)
+               return 0;
        if (!smu_power->power_context || smu_power->power_context_size == 0)
                return -EINVAL;

@@ -641,6 +645,8 @@ static int smu_v11_0_set_min_dcef_deep_sleep(struct smu_context *smu)  {
        struct smu_table_context *table_context = &smu->smu_table;

+       if (!smu->pm_enabled)
+               return 0;
        if (!table_context)
                return -EINVAL;

@@ -669,6 +675,9 @@ static int smu_v11_0_set_tool_table_location(struct smu_context *smu)  static int smu_v11_0_init_display(struct smu_context *smu)  {
        int ret = 0;
+
+       if (!smu->pm_enabled)
+               return ret;
        ret = smu_send_smc_msg_with_param(smu, SMU_MSG_NumOfDisplays, 0);
        return ret;
 }
@@ -678,6 +687,8 @@ static int smu_v11_0_update_feature_enable_state(struct smu_context *smu, uint32
        uint32_t feature_low = 0, feature_high = 0;
        int ret = 0;

+       if (!smu->pm_enabled)
+               return ret;
        if (feature_id >= 0 && feature_id < 31)
                feature_low = (1 << feature_id);
        else if (feature_id > 31 && feature_id < 63) @@ -784,10 +795,13 @@ static int smu_v11_0_system_features_control(struct smu_context *smu,
        uint32_t feature_mask[2];
        int ret = 0;

-       ret = smu_send_smc_msg(smu, (en ? SMU_MSG_EnableAllSmuFeatures :
-                                    SMU_MSG_DisableAllSmuFeatures));
-       if (ret)
-               return ret;
+       if (smu->pm_enabled) {
+               ret = smu_send_smc_msg(smu, (en ? SMU_MSG_EnableAllSmuFeatures :
+                                            SMU_MSG_DisableAllSmuFeatures));
+               if (ret)
+                       return ret;
+       }
+
        ret = smu_feature_get_enabled_mask(smu, feature_mask, 2);
        if (ret)
                return ret;
@@ -804,6 +818,8 @@ static int smu_v11_0_notify_display_change(struct smu_context *smu)  {
        int ret = 0;

+       if (!smu->pm_enabled)
+               return ret;
        if (smu_feature_is_enabled(smu, FEATURE_DPM_UCLK_BIT))
            ret = smu_send_smc_msg_with_param(smu, SMU_MSG_SetUclkFastSwitch, 1);

@@ -816,6 +832,8 @@ smu_v11_0_get_max_sustainable_clock(struct smu_context *smu, uint32_t *clock,  {
        int ret = 0;

+       if (!smu->pm_enabled)
+               return ret;
        ret = smu_send_smc_msg_with_param(smu, SMU_MSG_GetDcModeMaxDpmFreq,
                                          clock_select << 16);
        if (ret) {
@@ -1072,6 +1090,8 @@ static int smu_v11_0_start_thermal_control(struct smu_context *smu)
        struct PP_TemperatureRange range;
        struct amdgpu_device *adev = smu->adev;

+       if (!smu->pm_enabled)
+               return ret;
        smu_v11_0_get_thermal_range(smu, &range);

        if (smu->smu_table.thermal_controller_type) { @@ -1242,6 +1262,8 @@ smu_v11_0_display_clock_voltage_request(struct smu_context *smu,
        PPCLK_e clk_select = 0;
        uint32_t clk_freq = clock_req->clock_freq_in_khz / 1000;

+       if (!smu->pm_enabled)
+               return -EINVAL;
        if (smu_feature_is_enabled(smu, FEATURE_DPM_DCEFCLK_BIT)) {
                switch (clk_type) {
                case amd_pp_dcef_clock:
@@ -1525,7 +1547,7 @@ static int smu_v11_0_get_power_profile_mode(struct smu_context *smu, char *buf)
                        "PD_Data_error_rate_coeff"};
        int result = 0;

-       if (!buf)
+       if (!smu->pm_enabled || !buf)
                return -EINVAL;

        size += sprintf(buf + size, "%16s %s %s %s %s %s %s %s %s %s %s\n", @@ -1612,6 +1634,8 @@ static int smu_v11_0_set_power_profile_mode(struct smu_context *smu, long *input

        smu->power_profile_mode = input[size];

+       if (!smu->pm_enabled)
+               return ret;
        if (smu->power_profile_mode > PP_SMC_POWER_PROFILE_CUSTOM) {
                pr_err("Invalid power profile mode %d\n", smu->power_profile_mode);
                return -EINVAL;
--
2.7.4

_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org<mailto:amd-gfx@lists.freedesktop.org>
https://lists.freedesktop.org/mailman/listinfo/amd-gfx


[-- Attachment #1.2: Type: text/html, Size: 34896 bytes --]

[-- Attachment #2: Type: text/plain, Size: 153 bytes --]

_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

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

* RE: [PATCH 2/2] drm/amd/powerplay: Enable "disable dpm" feature for vega20 power functions.
       [not found]             ` <MN2PR12MB358219B85CA0E1B4B159FB0C8B0F0-rweVpJHSKTr2mYjuiDFEwwdYzm3356FpvxpqHgZTriW3zl9H0oFU5g@public.gmane.org>
@ 2019-05-14 14:26               ` Zhang, Hawking
  0 siblings, 0 replies; 8+ messages in thread
From: Zhang, Hawking @ 2019-05-14 14:26 UTC (permalink / raw)
  To: Gui, Jack,
	amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org

Hi Jack,

Let's hold on patch #2 for now. I'd prefer to gracefully deal with dpm_disabled in amdgpu_pm interface level (or at least amdgpu_smu level) so that we don't need to maintain the case for each ASIC since ppt is asic specific ones. 

Regards,
Hawking
-----Original Message-----
From: Gui, Jack <Jack.Gui@amd.com> 
Sent: 2019年5月13日 11:26
To: Zhang, Hawking <Hawking.Zhang@amd.com>; amd-gfx@lists.freedesktop.org
Subject: RE: [PATCH 2/2] drm/amd/powerplay: Enable "disable dpm" feature for vega20 power functions.

Hi Hawking,

If no other tools (sysfs inferfaces have been controlled by adev->dpm_enabled) directly use the ppt functs, PATCH[1/2] can cover all the cases now, PATCH[2/2] can be dropped.

BR,
Jack Gui

-----Original Message-----
From: Zhang, Hawking <Hawking.Zhang@amd.com> 
Sent: Sunday, May 12, 2019 11:18 AM
To: Gui, Jack <Jack.Gui@amd.com>; amd-gfx@lists.freedesktop.org
Cc: Gui, Jack <Jack.Gui@amd.com>
Subject: RE: [PATCH 2/2] drm/amd/powerplay: Enable "disable dpm" feature for vega20 power functions.

I'm wondering whether we are able to handle all asic specific ppt function gracefully. Add pm_enable check into ppt functions would be boring since we have to do similar jobs for each ASIC. Instead, is it possible to return early from amdgpu_smu interface level? 

Take smu_handle_task for the example, all the amdgpu_smu level interface invoked from this function could be stopped if we check smu pm_enable flag at the beginning of smu_handle_task. We probably have better approach to eliminate this patch.

Regards,
Hawking 

-----Original Message-----
From: amd-gfx <amd-gfx-bounces@lists.freedesktop.org> On Behalf Of Chengming Gui
Sent: 2019年5月10日 16:49
To: amd-gfx@lists.freedesktop.org
Cc: Gui, Jack <Jack.Gui@amd.com>
Subject: [PATCH 2/2] drm/amd/powerplay: Enable "disable dpm" feature for vega20 power functions.

[CAUTION: External Email]

use pm_enabled to control all power related functions about vega20.

Signed-off-by: Chengming Gui <Jack.Gui@amd.com>
---
 drivers/gpu/drm/amd/powerplay/vega20_ppt.c | 48 +++++++++++++++++++++++-------
 1 file changed, 38 insertions(+), 10 deletions(-)

diff --git a/drivers/gpu/drm/amd/powerplay/vega20_ppt.c b/drivers/gpu/drm/amd/powerplay/vega20_ppt.c
index 8fafcbd..7faa6a1 100644
--- a/drivers/gpu/drm/amd/powerplay/vega20_ppt.c
+++ b/drivers/gpu/drm/amd/powerplay/vega20_ppt.c
@@ -411,7 +411,8 @@ amd_pm_state_type vega20_get_current_power_state(struct smu_context *smu)
        enum amd_pm_state_type pm_type;
        struct smu_dpm_context *smu_dpm_ctx = &(smu->smu_dpm);

-       if (!smu_dpm_ctx->dpm_context ||
+       if (!smu->pm_enabled ||
+           !smu_dpm_ctx->dpm_context ||
            !smu_dpm_ctx->dpm_current_power_state)
                return -EINVAL;

@@ -491,12 +492,14 @@ static void vega20_init_single_dpm_state(struct vega20_dpm_state *dpm_state)

 static int vega20_set_default_dpm_table(struct smu_context *smu)  {
-       int ret;
+       int ret = 0;

        struct smu_dpm_context *smu_dpm = &smu->smu_dpm;
        struct vega20_dpm_table *dpm_table = NULL;
        struct vega20_single_dpm_table *single_dpm_table;

+       if (smu->pm_enabled)
+               return ret;
        dpm_table = smu_dpm->dpm_context;

        /* socclk */
@@ -738,6 +741,8 @@ static int vega20_print_clk_levels(struct smu_context *smu,

        dpm_table = smu_dpm->dpm_context;

+       if (!smu->pm_enabled)
+               return -EINVAL;
        switch (type) {
        case PP_SCLK:
                ret = smu_get_current_clk_freq(smu, PPCLK_GFXCLK, &now); @@ -969,6 +974,8 @@ static int vega20_upload_dpm_level(struct smu_context *smu, bool max,
        uint32_t freq;
        int ret = 0;

+       if (!smu->pm_enabled)
+               return -EINVAL;
        dpm_table = smu->smu_dpm.dpm_context;

        if (smu_feature_is_enabled(smu, FEATURE_DPM_GFXCLK_BIT) && @@ -1058,6 +1065,8 @@ static int vega20_force_clk_levels(struct smu_context *smu,
        struct smu_dpm_context *smu_dpm = &smu->smu_dpm;
        int ret = 0;

+       if (!smu->pm_enabled)
+               return -EINVAL;
        if (smu_dpm->dpm_level != AMD_DPM_FORCED_LEVEL_MANUAL) {
                pr_info("force clock level is for dpm manual mode only.\n");
                return -EINVAL;
@@ -1232,8 +1241,9 @@ static int vega20_get_clock_by_type_with_latency(struct smu_context *smu,

        dpm_table = smu_dpm->dpm_context;

+       if (!smu->pm_enabled)
+               return -EINVAL;
        mutex_lock(&smu->mutex);
-
        switch (type) {
        case amd_pp_sys_clock:
                single_dpm_table = &(dpm_table->gfx_table); @@ -1265,6 +1275,8 @@ static int vega20_overdrive_get_gfx_clk_base_voltage(struct smu_context *smu,  {
        int ret;

+       if (!smu->pm_enabled)
+               return -EINVAL;
        ret = smu_send_smc_msg_with_param(smu,
                        SMU_MSG_GetAVFSVoltageByDpm,
                        ((AVFS_CURVE << 24) | (OD8_HOTCURVE_TEMPERATURE << 16) | freq)); @@ -1287,7 +1299,7 @@ static int vega20_set_default_od8_setttings(struct smu_context *smu)
        PPTable_t *smc_pptable = table_context->driver_pptable;
        int i, ret;

-       if (table_context->od8_settings)
+       if (!smu->pm_enabled || table_context->od8_settings)
                return -EINVAL;

        table_context->od8_settings = kzalloc(sizeof(struct vega20_od8_settings), GFP_KERNEL); @@ -1474,6 +1486,8 @@ static int vega20_get_od_percentage(struct smu_context *smu,
        dpm_table = smu_dpm->dpm_context;
        golden_table = smu_dpm->golden_dpm_context;

+       if (!smu->pm_enabled)
+               return -EINVAL;
        switch (type) {
        case OD_SCLK:
                single_dpm_table = &(dpm_table->gfx_table); @@ -1509,7 +1523,7 @@ vega20_get_profiling_clk_mask(struct smu_context *smu,
        struct vega20_single_dpm_table *mem_dpm_table;
        struct vega20_single_dpm_table *soc_dpm_table;

-       if (!smu->smu_dpm.dpm_context)
+       if (!smu->pm_enabled || !smu->smu_dpm.dpm_context)
                return -EINVAL;

        gfx_dpm_table = &dpm_table->gfx_table; @@ -1579,7 +1593,7 @@ static int vega20_pre_display_config_changed(struct smu_context *smu)
        int ret = 0;
        struct vega20_dpm_table *dpm_table = smu->smu_dpm.dpm_context;

-       if (!smu->smu_dpm.dpm_context)
+       if (!smu->pm_enabled || !smu->smu_dpm.dpm_context)
                return -EINVAL;

        smu_send_smc_msg_with_param(smu, SMU_MSG_NumOfDisplays, 0); @@ -1594,7 +1608,7 @@ static int vega20_display_config_changed(struct smu_context *smu)  {
        int ret = 0;

-       if (!smu->funcs)
+       if (!smu->pm_enabled || !smu->funcs)
                return -EINVAL;

        if (!smu->smu_dpm.dpm_context || @@ -1632,6 +1646,8 @@ static int vega20_apply_clocks_adjust_rules(struct smu_context *smu)
        bool disable_mclk_switching;
        uint32_t i, latency;

+       if (!smu->pm_enabled)
+               return -EINVAL;
        disable_mclk_switching = ((1 < smu->display_config->num_display) &&
                                  !smu->display_config->multi_monitor_in_sync) || vblank_too_short;
        latency = smu->display_config->dce_tolerable_mclk_in_active_latency;
@@ -1779,6 +1795,8 @@ vega20_notify_smc_dispaly_config(struct smu_context *smu)
        struct pp_display_clock_request clock_req;
        int ret = 0;

+       if (!smu->pm_enabled)
+               return -EINVAL;
        min_clocks.dcef_clock = smu->display_config->min_dcef_set_clk;
        min_clocks.dcef_clock_in_sr = smu->display_config->min_dcef_deep_sleep_set_clk;
        min_clocks.memory_clock = smu->display_config->min_mem_set_clock;
@@ -1867,6 +1885,8 @@ static int vega20_force_dpm_limit_value(struct smu_context *smu, bool highest)
        struct vega20_dpm_table *dpm_table =
                (struct vega20_dpm_table *)smu->smu_dpm.dpm_context;

+       if (!smu->pm_enabled)
+               return -EINVAL;
        if (highest)
                soft_level = vega20_find_highest_dpm_level(&(dpm_table->gfx_table));
        else
@@ -1918,6 +1938,8 @@ static int vega20_unforce_dpm_levels(struct smu_context *smu)
        struct vega20_dpm_table *dpm_table =
                (struct vega20_dpm_table *)smu->smu_dpm.dpm_context;

+       if (!smu->pm_enabled)
+               return -EINVAL;
        soft_min_level = vega20_find_lowest_dpm_level(&(dpm_table->gfx_table));
        soft_max_level = vega20_find_highest_dpm_level(&(dpm_table->gfx_table));
        dpm_table->gfx_table.dpm_state.soft_min_level = @@ -1957,9 +1979,9 @@ static int vega20_unforce_dpm_levels(struct smu_context *smu)  static enum amd_dpm_forced_level vega20_get_performance_level(struct smu_context *smu)  {
        struct smu_dpm_context *smu_dpm_ctx = &(smu->smu_dpm);
-       if (!smu_dpm_ctx->dpm_context)
-               return -EINVAL;

+       if (!smu->pm_enabled || !smu_dpm_ctx->dpm_context)
+               return -EINVAL;
        if (smu_dpm_ctx->dpm_level != smu_dpm_ctx->saved_dpm_level) {
                mutex_lock(&(smu->mutex));
                smu_dpm_ctx->saved_dpm_level = smu_dpm_ctx->dpm_level; @@ -1975,7 +1997,7 @@ vega20_force_performance_level(struct smu_context *smu, enum amd_dpm_forced_leve
        int i;
        struct smu_dpm_context *smu_dpm_ctx = &(smu->smu_dpm);

-       if (!smu_dpm_ctx->dpm_context)
+       if (!smu->pm_enabled || !smu_dpm_ctx->dpm_context)
                return -EINVAL;

        for (i = 0; i < smu->adev->num_ip_blocks; i++) { @@ -2004,6 +2026,8 @@ static int vega20_update_specified_od8_value(struct smu_context *smu,
        struct vega20_od8_settings *od8_settings =
                (struct vega20_od8_settings *)table_context->od8_settings;

+       if (!smu->pm_enabled)
+               return -EINVAL;
        switch (index) {
        case OD8_SETTING_GFXCLK_FMIN:
                od_table->GfxclkFmin = (uint16_t)value; @@ -2085,6 +2109,8 @@ static int vega20_set_od_percentage(struct smu_context *smu,
        int feature_enabled;
        PPCLK_e clk_id;

+       if (!smu->pm_enabled)
+               return -EINVAL;
        mutex_lock(&(smu->mutex));

        dpm_table = smu_dpm->dpm_context; @@ -2163,6 +2189,8 @@ static int vega20_odn_edit_dpm_table(struct smu_context *smu,

        dpm_table = smu_dpm->dpm_context;

+       if (!smu->pm_enabled)
+               return -EINVAL;
        if (!input) {
                pr_warn("NULL user input for clock and voltage\n");
                return -EINVAL;
--
2.7.4

_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

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

end of thread, other threads:[~2019-05-14 14:26 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-05-10  8:48 [PATCH 1/2] drm/amd/powerplay: Enable "disable dpm" feature to support swSMU debug Chengming Gui
     [not found] ` <1557478117-17823-1-git-send-email-Jack.Gui-5C7GfCeVMHo@public.gmane.org>
2019-05-10  8:48   ` [PATCH 2/2] drm/amd/powerplay: Enable "disable dpm" feature for vega20 power functions Chengming Gui
     [not found]     ` <1557478117-17823-2-git-send-email-Jack.Gui-5C7GfCeVMHo@public.gmane.org>
2019-05-12  3:18       ` Zhang, Hawking
     [not found]         ` <BYAPR12MB263244237A28E226D34F348EFC0E0-ZGDeBxoHBPk+ukJnzp2+RQdYzm3356FpvxpqHgZTriW3zl9H0oFU5g@public.gmane.org>
2019-05-13  3:26           ` Gui, Jack
     [not found]             ` <MN2PR12MB358219B85CA0E1B4B159FB0C8B0F0-rweVpJHSKTr2mYjuiDFEwwdYzm3356FpvxpqHgZTriW3zl9H0oFU5g@public.gmane.org>
2019-05-14 14:26               ` Zhang, Hawking
2019-05-12  3:18   ` [PATCH 1/2] drm/amd/powerplay: Enable "disable dpm" feature to support swSMU debug Zhang, Hawking
     [not found]     ` <BYAPR12MB263278FD5AB7F03B991DEA43FC0E0-ZGDeBxoHBPk+ukJnzp2+RQdYzm3356FpvxpqHgZTriW3zl9H0oFU5g@public.gmane.org>
2019-05-13  3:32       ` Gui, Jack
     [not found]         ` <MN2PR12MB3582F42887F65C1B5A8E92F18B0F0-rweVpJHSKTr2mYjuiDFEwwdYzm3356FpvxpqHgZTriW3zl9H0oFU5g@public.gmane.org>
2019-05-14 13:56           ` Zhang, Hawking

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