Skip to contentSkip to conversation

drm/amd/pm: do not expose implementation details to other blocks out of power

PATCH Superseded Evan Quan 5 participants 45 messages Dec 3, 2021 – Apr 8, 2022 Page 1 of 2

Subsystems (6)

v4 of 5 Superseded Latest is v5 →

lore
Share & tools
lore

Evan Quan

author
#0 lore raw

PATCH v4 1/17 drm/amd/pm: do not expose implementation details to other blocks out of power

Those implementation details(whether swsmu supported, some ppt_funcs supported, accessing internal statistics ...)should be kept internally. It's not a good practice and even error prone to expose implementation details.

Change-Id Ibca3462ceaa26a27a9145282b60c6ce5deca7752
---
 drivers/gpu/drm/amd/amdgpu/aldebaran.c        |  2 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c   | 25 +++---
 drivers/gpu/drm/amd/amdgpu/amdgpu_device.c    |  6 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c       | 18 +---
 drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h       |  7 --
 drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c       |  5 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu_umc.c       |  5 +-
 drivers/gpu/drm/amd/amdkfd/kfd_smi_events.c   |  2 +-
 .../gpu/drm/amd/include/kgd_pp_interface.h    |  4 +
 drivers/gpu/drm/amd/pm/amdgpu_dpm.c           | 90 +++++++++++++++++++
 drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h       | 25 +++++-
 drivers/gpu/drm/amd/pm/inc/amdgpu_smu.h       | 11 +--
 drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c     | 26 +++---
 13 files changed, 161 insertions(+), 65 deletions(-)
drivers/gpu/drm/amd/amdgpu/aldebaran.c +1 -1
index bcfdb63b1d42..a545df4efce1 100644
@@ -260,7 +260,7 @@ static int aldebaran_mode2_restore_ip(struct amdgpu_device *adev)
 	adev->gfx.rlc.funcs->resume(adev);
 
 	/* Wait for FW reset event complete */
-	r = smu_wait_for_event(adev, SMU_EVENT_RESET_COMPLETE, 0);
+	r = amdgpu_dpm_wait_for_event(adev, SMU_EVENT_RESET_COMPLETE, 0);
 	if (r) {
 		dev_err(adev->dev,
 			"Failed to get response from firmware after reset\n");
drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c +14 -11
index 164d6a9e9fbb..0d1f00b24aae 100644
@@ -1585,22 +1585,25 @@ static int amdgpu_debugfs_sclk_set(void *data, u64 val)
 		return ret;
 	}
 
-	if (is_support_sw_smu(adev)) {
-		ret = smu_get_dpm_freq_range(&adev->smu, SMU_SCLK, &min_freq, &max_freq);
-		if (ret || val > max_freq || val < min_freq)
-			return -EINVAL;
-		ret = smu_set_soft_freq_range(&adev->smu, SMU_SCLK, (uint32_t)val, (uint32_t)val);
-	} else {
-		return 0;
+	ret = amdgpu_dpm_get_dpm_freq_range(adev, PP_SCLK, &min_freq, &max_freq);
+	if (ret == -EOPNOTSUPP) {
+		ret = 0;
+		goto out;
 	}
+	if (ret || val > max_freq || val < min_freq) {
+		ret = -EINVAL;
+		goto out;
+	}
+
+	ret = amdgpu_dpm_set_soft_freq_range(adev, PP_SCLK, (uint32_t)val, (uint32_t)val);
+	if (ret)
+		ret = -EINVAL;
 
+out:
 	pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
 	pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
 
-	if (ret)
-		return -EINVAL;
-
-	return 0;
+	return ret;
 }
 
 DEFINE_DEBUGFS_ATTRIBUTE(fops_ib_preempt, NULL,
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +3 -3
index 3c5afa45173c..fd18b05452af 100644
@@ -2617,7 +2617,7 @@ static int amdgpu_device_ip_late_init(struct amdgpu_device *adev)
 	if (adev->asic_type == CHIP_ARCTURUS &&
 	    amdgpu_passthrough(adev) &&
 	    adev->gmc.xgmi.num_physical_nodes > 1)
-		smu_set_light_sbr(&adev->smu, true);
+		amdgpu_dpm_set_light_sbr(adev, true);
 
 	if (adev->gmc.xgmi.num_physical_nodes > 1) {
 		mutex_lock(&mgpu_info.mutex);
@@ -2857,7 +2857,7 @@ static int amdgpu_device_ip_suspend_phase2(struct amdgpu_device *adev)
 	int i, r;
 
 	if (adev->in_s0ix)
-		amdgpu_gfx_state_change_set(adev, sGpuChangeState_D3Entry);
+		amdgpu_dpm_gfx_state_change(adev, sGpuChangeState_D3Entry);
 
 	for (i = adev->num_ip_blocks - 1; i >= 0; i--) {
 		if (!adev->ip_blocks[i].status.valid)
@@ -3982,7 +3982,7 @@ int amdgpu_device_resume(struct drm_device *dev, bool fbcon)
 		return 0;
 
 	if (adev->in_s0ix)
-		amdgpu_gfx_state_change_set(adev, sGpuChangeState_D0Entry);
+		amdgpu_dpm_gfx_state_change(adev, sGpuChangeState_D0Entry);
 
 	/* post card */
 	if (amdgpu_device_need_post(adev)) {
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c +1 -17
index 1916ec84dd71..3d8f82dc8c97 100644
@@ -615,7 +615,7 @@ int amdgpu_get_gfx_off_status(struct amdgpu_device *adev, uint32_t *value)
 
 	mutex_lock(&adev->gfx.gfx_off_mutex);
 
-	r = smu_get_status_gfxoff(adev, value);
+	r = amdgpu_dpm_get_status_gfxoff(adev, value);
 
 	mutex_unlock(&adev->gfx.gfx_off_mutex);
 
@@ -852,19 +852,3 @@ int amdgpu_gfx_get_num_kcq(struct amdgpu_device *adev)
 	}
 	return amdgpu_num_kcq;
 }
-
-/* amdgpu_gfx_state_change_set - Handle gfx power state change set
- * @adev: amdgpu_device pointer
- * @state: gfx power state(1 -sGpuChangeState_D0Entry and 2 -sGpuChangeState_D3Entry)
- *
- */
-
-void amdgpu_gfx_state_change_set(struct amdgpu_device *adev, enum gfx_change_state state)
-{
-	mutex_lock(&adev->pm.mutex);
-	if (adev->powerplay.pp_funcs &&
-	    adev->powerplay.pp_funcs->gfx_state_change_set)
-		((adev)->powerplay.pp_funcs->gfx_state_change_set(
-			(adev)->powerplay.pp_handle, state));
-	mutex_unlock(&adev->pm.mutex);
-}
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h +0 -7
index f851196c83a5..776c886fd94a 100644
@@ -47,12 +47,6 @@ enum amdgpu_gfx_pipe_priority {
 	AMDGPU_GFX_PIPE_PRIO_HIGH = AMDGPU_RING_PRIO_2
 };
 
-/* Argument for PPSMC_MSG_GpuChangeState */
-enum gfx_change_state {
-	sGpuChangeState_D0Entry = 1,
-	sGpuChangeState_D3Entry,
-};
-
 #define AMDGPU_GFX_QUEUE_PRIORITY_MINIMUM  0
 #define AMDGPU_GFX_QUEUE_PRIORITY_MAXIMUM  15
 
@@ -410,5 +404,4 @@ int amdgpu_gfx_cp_ecc_error_irq(struct amdgpu_device *adev,
 uint32_t amdgpu_kiq_rreg(struct amdgpu_device *adev, uint32_t reg);
 void amdgpu_kiq_wreg(struct amdgpu_device *adev, uint32_t reg, uint32_t v);
 int amdgpu_gfx_get_num_kcq(struct amdgpu_device *adev);
-void amdgpu_gfx_state_change_set(struct amdgpu_device *adev, enum gfx_change_state state);
 #endif
drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c +2 -3
index 3c623e589b79..35c4aec04a7e 100644
@@ -901,7 +901,7 @@ static void amdgpu_ras_get_ecc_info(struct amdgpu_device *adev, struct ras_err_d
 	 * choosing right query method according to
 	 * whether smu support query error information
 	 */
-	ret = smu_get_ecc_info(&adev->smu, (void *)&(ras->umc_ecc));
+	ret = amdgpu_dpm_get_ecc_info(adev, (void *)&(ras->umc_ecc));
 	if (ret == -EOPNOTSUPP) {
 		if (adev->umc.ras_funcs &&
 			adev->umc.ras_funcs->query_ras_error_count)
@@ -2132,8 +2132,7 @@ int amdgpu_ras_recovery_init(struct amdgpu_device *adev)
 		if (ret)
 			goto free;
 
-		if (adev->smu.ppt_funcs && adev->smu.ppt_funcs->send_hbm_bad_pages_num)
-			adev->smu.ppt_funcs->send_hbm_bad_pages_num(&adev->smu, con->eeprom_control.ras_num_recs);
+		amdgpu_dpm_send_hbm_bad_pages_num(adev, con->eeprom_control.ras_num_recs);
 	}
 
 #ifdef CONFIG_X86_MCE_AMD
drivers/gpu/drm/amd/amdgpu/amdgpu_umc.c +2 -3
index 6e4bea012ea4..5fed26c8db44 100644
@@ -97,7 +97,7 @@ int amdgpu_umc_process_ras_data_cb(struct amdgpu_device *adev,
 	int ret = 0;
 
 	kgd2kfd_set_sram_ecc_flag(adev->kfd.dev);
-	ret = smu_get_ecc_info(&adev->smu, (void *)&(con->umc_ecc));
+	ret = amdgpu_dpm_get_ecc_info(adev, (void *)&(con->umc_ecc));
 	if (ret == -EOPNOTSUPP) {
 		if (adev->umc.ras_funcs &&
 		    adev->umc.ras_funcs->query_ras_error_count)
@@ -160,8 +160,7 @@ int amdgpu_umc_process_ras_data_cb(struct amdgpu_device *adev,
 						err_data->err_addr_cnt);
 			amdgpu_ras_save_bad_pages(adev);
 
-			if (adev->smu.ppt_funcs && adev->smu.ppt_funcs->send_hbm_bad_pages_num)
-				adev->smu.ppt_funcs->send_hbm_bad_pages_num(&adev->smu, con->eeprom_control.ras_num_recs);
+			amdgpu_dpm_send_hbm_bad_pages_num(adev, con->eeprom_control.ras_num_recs);
 		}
 
 		amdgpu_ras_reset_gpu(adev);
drivers/gpu/drm/amd/amdkfd/kfd_smi_events.c +1 -1
index deae12dc777d..329a4c89f1e6 100644
@@ -222,7 +222,7 @@ void kfd_smi_event_update_thermal_throttling(struct kfd_dev *dev,
 
 	len = snprintf(fifo_in, sizeof(fifo_in), "%x %llx:%llx\n",
 		       KFD_SMI_EVENT_THERMAL_THROTTLE, throttle_bitmask,
-		       atomic64_read(&dev->adev->smu.throttle_int_counter));
+		       amdgpu_dpm_get_thermal_throttling_counter(dev->adev));
 
 	add_event_to_kfifo(dev, KFD_SMI_EVENT_THERMAL_THROTTLE,	fifo_in, len);
 }
drivers/gpu/drm/amd/include/kgd_pp_interface.h +4 -0
index 5c0867ebcfce..2e295facd086 100644
@@ -26,6 +26,10 @@
 
 extern const struct amdgpu_ip_block_version pp_smu_ip_block;
 
+enum smu_event_type {
+	SMU_EVENT_RESET_COMPLETE = 0,
+};
+
 struct amd_vce_state {
 	/* vce clocks */
 	u32 evclk;
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +90 -0

93 lines not on this page · raw message

drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h +24 -1
index 16e3f72d31b9..7289d379a9fb 100644
@@ -23,6 +23,12 @@
 #ifndef __AMDGPU_DPM_H__
 #define __AMDGPU_DPM_H__
 
+/* Argument for PPSMC_MSG_GpuChangeState */
+enum gfx_change_state {
+	sGpuChangeState_D0Entry = 1,
+	sGpuChangeState_D3Entry,
+};
+
 enum amdgpu_int_thermal_type {
 	THERMAL_TYPE_NONE,
 	THERMAL_TYPE_EXTERNAL,
@@ -574,5 +580,22 @@ void amdgpu_dpm_enable_vce(struct amdgpu_device *adev, bool enable);
 void amdgpu_dpm_enable_jpeg(struct amdgpu_device *adev, bool enable);
 void amdgpu_pm_print_power_states(struct amdgpu_device *adev);
 int amdgpu_pm_load_smu_firmware(struct amdgpu_device *adev, uint32_t *smu_version);
-
+int amdgpu_dpm_set_light_sbr(struct amdgpu_device *adev, bool enable);
+int amdgpu_dpm_send_hbm_bad_pages_num(struct amdgpu_device *adev, uint32_t size);
+int amdgpu_dpm_get_dpm_freq_range(struct amdgpu_device *adev,
+				       enum pp_clock_type type,
+				       uint32_t *min,
+				       uint32_t *max);
+int amdgpu_dpm_set_soft_freq_range(struct amdgpu_device *adev,
+				        enum pp_clock_type type,
+				        uint32_t min,
+				        uint32_t max);
+int amdgpu_dpm_wait_for_event(struct amdgpu_device *adev, enum smu_event_type event,
+		       uint64_t event_arg);
+int amdgpu_dpm_get_status_gfxoff(struct amdgpu_device *adev, uint32_t *value);
+uint64_t amdgpu_dpm_get_thermal_throttling_counter(struct amdgpu_device *adev);
+void amdgpu_dpm_gfx_state_change(struct amdgpu_device *adev,
+				 enum gfx_change_state state);
+int amdgpu_dpm_get_ecc_info(struct amdgpu_device *adev,
+			    void *umc_ecc);
 #endif
drivers/gpu/drm/amd/pm/inc/amdgpu_smu.h +3 -8
index f738f7dc20c9..942297c69de0 100644
@@ -241,11 +241,6 @@ struct smu_user_dpm_profile {
 	uint32_t clk_dependency;
 };
 
-enum smu_event_type {
-
-	SMU_EVENT_RESET_COMPLETE = 0,
-};
-
 #define SMU_TABLE_INIT(tables, table_id, s, a, d)	\
 	do {						\
 		tables[table_id].size = s;		\
@@ -1412,15 +1407,15 @@ int smu_set_ac_dc(struct smu_context *smu);
 
 int smu_allow_xgmi_power_down(struct smu_context *smu, bool en);
 
-int smu_get_status_gfxoff(struct amdgpu_device *adev, uint32_t *value);
+int smu_get_status_gfxoff(struct smu_context *smu, uint32_t *value);
 
 int smu_set_light_sbr(struct smu_context *smu, bool enable);
 
-int smu_wait_for_event(struct amdgpu_device *adev, enum smu_event_type event,
+int smu_wait_for_event(struct smu_context *smu, enum smu_event_type event,
 		       uint64_t event_arg);
 int smu_get_ecc_info(struct smu_context *smu, void *umc_ecc);
 int smu_stb_collect_info(struct smu_context *smu, void *buff, uint32_t size);
 void amdgpu_smu_stb_debug_fs_init(struct amdgpu_device *adev);
-
+int smu_send_hbm_bad_pages_num(struct smu_context *smu, uint32_t size);
 #endif
 #endif
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +16 -10
index 5839918cb574..d8cd7c8c4479 100644
@@ -100,17 +100,14 @@ static int smu_sys_set_pp_feature_mask(void *handle,
 	return ret;
 }
 
-int smu_get_status_gfxoff(struct amdgpu_device *adev, uint32_t *value)
+int smu_get_status_gfxoff(struct smu_context *smu, uint32_t *value)
 {
-	int ret = 0;
-	struct smu_context *smu = &adev->smu;
+	if (!smu->ppt_funcs->get_gfx_off_status)
+		return -EINVAL;
 
-	if (is_support_sw_smu(adev) && smu->ppt_funcs->get_gfx_off_status)
-		*value = smu_get_gfx_off_status(smu);
-	else
-		ret = -EINVAL;
+	*value = smu_get_gfx_off_status(smu);
 
-	return ret;
+	return 0;
 }
 
 int smu_set_soft_freq_range(struct smu_context *smu,
@@ -3167,11 +3164,10 @@ static const struct amd_pm_funcs swsmu_pm_funcs = {
 	.get_smu_prv_buf_details = smu_get_prv_buffer_details,
 };
 
-int smu_wait_for_event(struct amdgpu_device *adev, enum smu_event_type event,
+int smu_wait_for_event(struct smu_context *smu, enum smu_event_type event,
 		       uint64_t event_arg)
 {
 	int ret = -EINVAL;
-	struct smu_context *smu = &adev->smu;
 
 	if (smu->ppt_funcs->wait_for_event) {
 		mutex_lock(&smu->mutex);
@@ -3285,3 +3281,13 @@ void amdgpu_smu_stb_debug_fs_init(struct amdgpu_device *adev)
 #endif
 
 }
+
+int smu_send_hbm_bad_pages_num(struct smu_context *smu, uint32_t size)
+{
+	int ret = 0;
+
+	if (smu->ppt_funcs && smu->ppt_funcs->send_hbm_bad_pages_num)
+		ret = smu->ppt_funcs->send_hbm_bad_pages_num(smu, size);
+
+	return ret;
+}
Signature · 1 line
2.29.0
author
#1 lore raw

PATCH v4 2/17 drm/amd/pm: do not expose power implementation details to amdgpu_pm.c

amdgpu_pm.c holds all the user sysfs/hwmon interfaces. It's another client of our power APIs. It's not proper to spike into power implementation details there.

Change-Id I397853ddb13eacfce841366de2a623535422df9a

--
v1->v2:
- drop unneeded "return;" in amdgpu_dpm_get_current_power_state(Guchun)

---
 drivers/gpu/drm/amd/pm/amdgpu_dpm.c       | 456 ++++++++++++++++++-
 drivers/gpu/drm/amd/pm/amdgpu_pm.c        | 519 ++++++++--------------
 drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h   | 160 +++----
 drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c |   3 -
 4 files changed, 707 insertions(+), 431 deletions(-)
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +455 -1
index 54abdf7080de..2c789eb5d066 100644
@@ -1453,7 +1453,9 @@ static void amdgpu_dpm_change_power_state_locked(struct amdgpu_device *adev)
 	if (equal)
 		return;
 
-	amdgpu_dpm_set_power_state(adev);
+	if (adev->powerplay.pp_funcs->set_power_state)
+		adev->powerplay.pp_funcs->set_power_state(adev->powerplay.pp_handle);
+
 	amdgpu_dpm_post_set_power_state(adev);
 
 	adev->pm.dpm.current_active_crtcs = adev->pm.dpm.new_active_crtcs;
@@ -1704,3 +1706,455 @@ int amdgpu_dpm_get_ecc_info(struct amdgpu_device *adev,
 
 	return smu_get_ecc_info(&adev->smu, umc_ecc);
 }
+
+struct amd_vce_state *amdgpu_dpm_get_vce_clock_state(struct amdgpu_device *adev,
+						     uint32_t idx)
+{
+	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+
+	if (!pp_funcs->get_vce_clock_state)
+		return NULL;
+
+	return pp_funcs->get_vce_clock_state(adev->powerplay.pp_handle,
+					     idx);
+}
+
+void amdgpu_dpm_get_current_power_state(struct amdgpu_device *adev,
+					enum amd_pm_state_type *state)
+{
+	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+
+	if (!pp_funcs->get_current_power_state) {
+		*state = adev->pm.dpm.user_state;
+		return;
+	}
+
+	*state = pp_funcs->get_current_power_state(adev->powerplay.pp_handle);
+	if (*state < POWER_STATE_TYPE_DEFAULT ||
+	    *state > POWER_STATE_TYPE_INTERNAL_3DPERF)
+		*state = adev->pm.dpm.user_state;
+}
+
+void amdgpu_dpm_set_power_state(struct amdgpu_device *adev,
+				enum amd_pm_state_type state)
+{
+	adev->pm.dpm.user_state = state;
+
+	if (adev->powerplay.pp_funcs->dispatch_tasks)
+		amdgpu_dpm_dispatch_task(adev, AMD_PP_TASK_ENABLE_USER_STATE, &state);
+	else
+		amdgpu_pm_compute_clocks(adev);
+}
+
+enum amd_dpm_forced_level amdgpu_dpm_get_performance_level(struct amdgpu_device *adev)
+{
+	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+	enum amd_dpm_forced_level level;
+
+	if (pp_funcs->get_performance_level)
+		level = pp_funcs->get_performance_level(adev->powerplay.pp_handle);
+	else
+		level = adev->pm.dpm.forced_level;
+
+	return level;
+}
+
+int amdgpu_dpm_force_performance_level(struct amdgpu_device *adev,
+				       enum amd_dpm_forced_level level)
+{
+	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+
+	if (pp_funcs->force_performance_level) {
+		if (adev->pm.dpm.thermal_active)
+			return -EINVAL;
+
+		if (pp_funcs->force_performance_level(adev->powerplay.pp_handle,
+						      level))
+			return -EINVAL;
+	}
+
+	adev->pm.dpm.forced_level = level;
+
+	return 0;
+}
+
+int amdgpu_dpm_get_pp_num_states(struct amdgpu_device *adev,
+				 struct pp_states_info *states)
+{
+	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+
+	if (!pp_funcs->get_pp_num_states)
+		return -EOPNOTSUPP;
+
+	return pp_funcs->get_pp_num_states(adev->powerplay.pp_handle, states);
+}
+
+int amdgpu_dpm_dispatch_task(struct amdgpu_device *adev,
+			      enum amd_pp_task task_id,
+			      enum amd_pm_state_type *user_state)
+{
+	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+
+	if (!pp_funcs->dispatch_tasks)
+		return -EOPNOTSUPP;
+
+	return pp_funcs->dispatch_tasks(adev->powerplay.pp_handle, task_id, user_state);
+}
+
+int amdgpu_dpm_get_pp_table(struct amdgpu_device *adev, char **table)
+{
+	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+
+	if (!pp_funcs->get_pp_table)
+		return 0;
+
+	return pp_funcs->get_pp_table(adev->powerplay.pp_handle, table);
+}
+
+int amdgpu_dpm_set_fine_grain_clk_vol(struct amdgpu_device *adev,
+				      uint32_t type,
+				      long *input,
+				      uint32_t size)
+{
+	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+
+	if (!pp_funcs->set_fine_grain_clk_vol)
+		return 0;
+
+	return pp_funcs->set_fine_grain_clk_vol(adev->powerplay.pp_handle,
+						type,
+						input,
+						size);
+}
+
+int amdgpu_dpm_odn_edit_dpm_table(struct amdgpu_device *adev,
+				  uint32_t type,
+				  long *input,
+				  uint32_t size)
+{
+	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+
+	if (!pp_funcs->odn_edit_dpm_table)
+		return 0;
+
+	return pp_funcs->odn_edit_dpm_table(adev->powerplay.pp_handle,
+					    type,
+					    input,
+					    size);
+}
+
+int amdgpu_dpm_print_clock_levels(struct amdgpu_device *adev,
+				  enum pp_clock_type type,
+				  char *buf)
+{
+	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+
+	if (!pp_funcs->print_clock_levels)
+		return 0;
+
+	return pp_funcs->print_clock_levels(adev->powerplay.pp_handle,
+					    type,
+					    buf);
+}
+
+int amdgpu_dpm_set_ppfeature_status(struct amdgpu_device *adev,
+				    uint64_t ppfeature_masks)
+{
+	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+
+	if (!pp_funcs->set_ppfeature_status)
+		return 0;
+
+	return pp_funcs->set_ppfeature_status(adev->powerplay.pp_handle,
+					      ppfeature_masks);
+}
+
+int amdgpu_dpm_get_ppfeature_status(struct amdgpu_device *adev, char *buf)
+{
+	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+
+	if (!pp_funcs->get_ppfeature_status)
+		return 0;
+
+	return pp_funcs->get_ppfeature_status(adev->powerplay.pp_handle,
+					      buf);
+}
+
+int amdgpu_dpm_force_clock_level(struct amdgpu_device *adev,
+				 enum pp_clock_type type,
+				 uint32_t mask)
+{
+	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+
+	if (!pp_funcs->force_clock_level)
+		return 0;
+
+	return pp_funcs->force_clock_level(adev->powerplay.pp_handle,
+					   type,
+					   mask);
+}
+
+int amdgpu_dpm_get_sclk_od(struct amdgpu_device *adev)
+{
+	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+
+	if (!pp_funcs->get_sclk_od)
+		return 0;
+
+	return pp_funcs->get_sclk_od(adev->powerplay.pp_handle);
+}
+
+int amdgpu_dpm_set_sclk_od(struct amdgpu_device *adev, uint32_t value)
+{
+	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+
+	if (!pp_funcs->set_sclk_od)
+		return -EOPNOTSUPP;
+
+	pp_funcs->set_sclk_od(adev->powerplay.pp_handle, value);
+
+	if (amdgpu_dpm_dispatch_task(adev,
+				     AMD_PP_TASK_READJUST_POWER_STATE,
+				     NULL) == -EOPNOTSUPP) {
+		adev->pm.dpm.current_ps = adev->pm.dpm.boot_ps;
+		amdgpu_pm_compute_clocks(adev);
+	}
+
+	return 0;
+}
+
+int amdgpu_dpm_get_mclk_od(struct amdgpu_device *adev)
+{
+	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+
+	if (!pp_funcs->get_mclk_od)
+		return 0;
+
+	return pp_funcs->get_mclk_od(adev->powerplay.pp_handle);
+}
+
+int amdgpu_dpm_set_mclk_od(struct amdgpu_device *adev, uint32_t value)
+{
+	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+
+	if (!pp_funcs->set_mclk_od)
+		return -EOPNOTSUPP;
+
+	pp_funcs->set_mclk_od(adev->powerplay.pp_handle, value);
+
+	if (amdgpu_dpm_dispatch_task(adev,
+				     AMD_PP_TASK_READJUST_POWER_STATE,
+				     NULL) == -EOPNOTSUPP) {
+		adev->pm.dpm.current_ps = adev->pm.dpm.boot_ps;
+		amdgpu_pm_compute_clocks(adev);
+	}
+
+	return 0;
+}
+
+int amdgpu_dpm_get_power_profile_mode(struct amdgpu_device *adev,
+				      char *buf)
+{
+	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+
+	if (!pp_funcs->get_power_profile_mode)
+		return -EOPNOTSUPP;
+
+	return pp_funcs->get_power_profile_mode(adev->powerplay.pp_handle,
+						buf);
+}
+
+int amdgpu_dpm_set_power_profile_mode(struct amdgpu_device *adev,
+				      long *input, uint32_t size)
+{
+	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+
+	if (!pp_funcs->set_power_profile_mode)
+		return 0;
+
+	return pp_funcs->set_power_profile_mode(adev->powerplay.pp_handle,
+						input,
+						size);
+}
+
+int amdgpu_dpm_get_gpu_metrics(struct amdgpu_device *adev, void **table)
+{
+	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+
+	if (!pp_funcs->get_gpu_metrics)
+		return 0;
+
+	return pp_funcs->get_gpu_metrics(adev->powerplay.pp_handle, table);
+}
+
+int amdgpu_dpm_get_fan_control_mode(struct amdgpu_device *adev,
+				    uint32_t *fan_mode)
+{
+	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+
+	if (!pp_funcs->get_fan_control_mode)
+		return -EOPNOTSUPP;
+
+	*fan_mode = pp_funcs->get_fan_control_mode(adev->powerplay.pp_handle);
+
+	return 0;
+}
+
+int amdgpu_dpm_set_fan_speed_pwm(struct amdgpu_device *adev,
+				 uint32_t speed)
+{
+	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+
+	if (!pp_funcs->set_fan_speed_pwm)
+		return -EINVAL;
+
+	return pp_funcs->set_fan_speed_pwm(adev->powerplay.pp_handle, speed);
+}
+
+int amdgpu_dpm_get_fan_speed_pwm(struct amdgpu_device *adev,
+				 uint32_t *speed)
+{
+	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+
+	if (!pp_funcs->get_fan_speed_pwm)
+		return -EINVAL;
+
+	return pp_funcs->get_fan_speed_pwm(adev->powerplay.pp_handle, speed);
+}
+
+int amdgpu_dpm_get_fan_speed_rpm(struct amdgpu_device *adev,
+				 uint32_t *speed)
+{
+	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+
+	if (!pp_funcs->get_fan_speed_rpm)
+		return -EINVAL;
+
+	return pp_funcs->get_fan_speed_rpm(adev->powerplay.pp_handle, speed);
+}
+
+int amdgpu_dpm_set_fan_speed_rpm(struct amdgpu_device *adev,
+				 uint32_t speed)
+{
+	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+
+	if (!pp_funcs->set_fan_speed_rpm)
+		return -EINVAL;
+
+	return pp_funcs->set_fan_speed_rpm(adev->powerplay.pp_handle, speed);
+}
+
+int amdgpu_dpm_set_fan_control_mode(struct amdgpu_device *adev,
+				    uint32_t mode)
+{
+	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+
+	if (!pp_funcs->set_fan_control_mode)
+		return -EOPNOTSUPP;
+
+	pp_funcs->set_fan_control_mode(adev->powerplay.pp_handle, mode);
+
+	return 0;
+}
+
+int amdgpu_dpm_get_power_limit(struct amdgpu_device *adev,
+			       uint32_t *limit,
+			       enum pp_power_limit_level pp_limit_level,
+			       enum pp_power_type power_type)
+{
+	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+
+	if (!pp_funcs->get_power_limit)
+		return -ENODATA;
+
+	return pp_funcs->get_power_limit(adev->powerplay.pp_handle,
+					 limit,
+					 pp_limit_level,
+					 power_type);
+}
+
+int amdgpu_dpm_set_power_limit(struct amdgpu_device *adev,
+			       uint32_t limit)
+{
+	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+
+	if (!pp_funcs->set_power_limit)
+		return -EINVAL;
+
+	return pp_funcs->set_power_limit(adev->powerplay.pp_handle, limit);
+}
+
+int amdgpu_dpm_is_cclk_dpm_supported(struct amdgpu_device *adev)
+{
+	if (!is_support_sw_smu(adev))
+		return false;
+
+	return is_support_cclk_dpm(adev);
+}
+
+int amdgpu_dpm_debugfs_print_current_performance_level(struct amdgpu_device *adev,
+						       struct seq_file *m)
+{
+	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+
+	if (!pp_funcs->debugfs_print_current_performance_level)
+		return -EOPNOTSUPP;
+
+	pp_funcs->debugfs_print_current_performance_level(adev->powerplay.pp_handle,
+							  m);
+
+	return 0;
+}
+
+int amdgpu_dpm_get_smu_prv_buf_details(struct amdgpu_device *adev,
+				       void **addr,
+				       size_t *size)
+{
+	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+
+	if (!pp_funcs->get_smu_prv_buf_details)
+		return -ENOSYS;
+
+	return pp_funcs->get_smu_prv_buf_details(adev->powerplay.pp_handle,
+						 addr,
+						 size);
+}
+
+int amdgpu_dpm_is_overdrive_supported(struct amdgpu_device *adev)
+{
+	struct pp_hwmgr *hwmgr = adev->powerplay.pp_handle;
+
+	if ((is_support_sw_smu(adev) && adev->smu.od_enabled) ||
+	    (is_support_sw_smu(adev) && adev->smu.is_apu) ||
+		(!is_support_sw_smu(adev) && hwmgr->od_enabled))
+		return true;
+
+	return false;
+}
+
+int amdgpu_dpm_set_pp_table(struct amdgpu_device *adev,
+			    const char *buf,
+			    size_t size)
+{
+	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+
+	if (!pp_funcs->set_pp_table)
+		return -EOPNOTSUPP;
+
+	return pp_funcs->set_pp_table(adev->powerplay.pp_handle,
+				      buf,
+				      size);
+}
+
+int amdgpu_dpm_get_num_cpu_cores(struct amdgpu_device *adev)
+{
+	return adev->smu.cpu_core_num;
+}
+
+void amdgpu_dpm_stb_debug_fs_init(struct amdgpu_device *adev)
+{
+	if (!is_support_sw_smu(adev))
+		return;
+
+	amdgpu_smu_stb_debug_fs_init(adev);
+}
drivers/gpu/drm/amd/pm/amdgpu_pm.c +182 -337

922 lines not on this page · raw message

drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h +70 -90

183 lines not on this page · raw message

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +0 -3
index d8cd7c8c4479..51358383f672 100644
@@ -470,9 +470,6 @@ bool is_support_cclk_dpm(struct amdgpu_device *adev)
 {
 	struct smu_context *smu = &adev->smu;
 
-	if (!is_support_sw_smu(adev))
-		return false;
-
 	if (!smu_feature_is_enabled(smu, SMU_FEATURE_CCLK_DPM_BIT))
 		return false;
 
Signature · 1 line
2.29.0
#2 lore raw

Re: [PATCH V4 02/17] drm/amd/pm: do not expose power implementation details to amdgpu_pm.c

Quoted 94 lines · Evan Quan

amdgpu_pm.c holds all the user sysfs/hwmon interfaces. It's another client of our power APIs. It's not proper to spike into power implementation details there.

Change-Id I397853ddb13eacfce841366de2a623535422df9a

--
v1->v2:
- drop unneeded "return;" in amdgpu_dpm_get_current_power_state(Guchun)

---
  drivers/gpu/drm/amd/pm/amdgpu_dpm.c       | 456 ++++++++++++++++++-
  drivers/gpu/drm/amd/pm/amdgpu_pm.c        | 519 ++++++++--------------
  drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h   | 160 +++----
  drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c |   3 -
  4 files changed, 707 insertions(+), 431 deletions(-)
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +62 -1
index 54abdf7080de..2c789eb5d066 100644
@@ -1453,7 +1453,9 @@ static void amdgpu_dpm_change_power_state_locked(struct amdgpu_device *adev)
  	if (equal)
  		return;
 
-	amdgpu_dpm_set_power_state(adev);
+	if (adev->powerplay.pp_funcs->set_power_state)
+		adev->powerplay.pp_funcs->set_power_state(adev->powerplay.pp_handle);
+
  	amdgpu_dpm_post_set_power_state(adev);
 
  	adev->pm.dpm.current_active_crtcs = adev->pm.dpm.new_active_crtcs;
@@ -1704,3 +1706,455 @@ int amdgpu_dpm_get_ecc_info(struct amdgpu_device *adev,
 
  	return smu_get_ecc_info(&adev->smu, umc_ecc);
  }
+
+struct amd_vce_state *amdgpu_dpm_get_vce_clock_state(struct amdgpu_device *adev,
+						     uint32_t idx)
+{
+	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+
+	if (!pp_funcs->get_vce_clock_state)
+		return NULL;
+
+	return pp_funcs->get_vce_clock_state(adev->powerplay.pp_handle,
+					     idx);
+}
+
+void amdgpu_dpm_get_current_power_state(struct amdgpu_device *adev,
+					enum amd_pm_state_type *state)
+{
+	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+
+	if (!pp_funcs->get_current_power_state) {
+		*state = adev->pm.dpm.user_state;
+		return;
+	}
+
+	*state = pp_funcs->get_current_power_state(adev->powerplay.pp_handle);
+	if (*state < POWER_STATE_TYPE_DEFAULT ||
+	    *state > POWER_STATE_TYPE_INTERNAL_3DPERF)
+		*state = adev->pm.dpm.user_state;
+}
+
+void amdgpu_dpm_set_power_state(struct amdgpu_device *adev,
+				enum amd_pm_state_type state)
+{
+	adev->pm.dpm.user_state = state;
+
+	if (adev->powerplay.pp_funcs->dispatch_tasks)
+		amdgpu_dpm_dispatch_task(adev, AMD_PP_TASK_ENABLE_USER_STATE, &state);
+	else
+		amdgpu_pm_compute_clocks(adev);
+}
+
+enum amd_dpm_forced_level amdgpu_dpm_get_performance_level(struct amdgpu_device *adev)
+{
+	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+	enum amd_dpm_forced_level level;
+
+	if (pp_funcs->get_performance_level)
+		level = pp_funcs->get_performance_level(adev->powerplay.pp_handle);
+	else
+		level = adev->pm.dpm.forced_level;
+
+	return level;
+}
+
+int amdgpu_dpm_force_performance_level(struct amdgpu_device *adev,
+				       enum amd_dpm_forced_level level)
+{
+	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+
+	if (pp_funcs->force_performance_level) {

drivers/gpu/drm/amd/pm/amdgpu_dpm.c int amdgpu_dpm_get_ecc_info(struct amdgpu_device *adev, · line 1777

Quoted 10 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +10 -0
+		if (adev->pm.dpm.thermal_active)
+			return -EINVAL;
+
+		if (pp_funcs->force_performance_level(adev->powerplay.pp_handle,
+						      level))
+			return -EINVAL;
+	}
+
+	adev->pm.dpm.forced_level = level;
+

If the function is not implemented, why change the force level and return success?

Quoted 36 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +36 -0
+	return 0;
+}
+
+int amdgpu_dpm_get_pp_num_states(struct amdgpu_device *adev,
+				 struct pp_states_info *states)
+{
+	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+
+	if (!pp_funcs->get_pp_num_states)
+		return -EOPNOTSUPP;
+
+	return pp_funcs->get_pp_num_states(adev->powerplay.pp_handle, states);
+}
+
+int amdgpu_dpm_dispatch_task(struct amdgpu_device *adev,
+			      enum amd_pp_task task_id,
+			      enum amd_pm_state_type *user_state)
+{
+	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+
+	if (!pp_funcs->dispatch_tasks)
+		return -EOPNOTSUPP;
+
+	return pp_funcs->dispatch_tasks(adev->powerplay.pp_handle, task_id, user_state);
+}
+
+int amdgpu_dpm_get_pp_table(struct amdgpu_device *adev, char **table)
+{
+	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+
+	if (!pp_funcs->get_pp_table)
+		return 0;
+
+	return pp_funcs->get_pp_table(adev->powerplay.pp_handle, table);
+}
+

drivers/gpu/drm/amd/pm/amdgpu_dpm.c int amdgpu_dpm_get_ecc_info(struct amdgpu_device *adev, · line 1823

Quoted 10 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +10 -0
+int amdgpu_dpm_set_fine_grain_clk_vol(struct amdgpu_device *adev,
+				      uint32_t type,
+				      long *input,
+				      uint32_t size)
+{
+	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+
+	if (!pp_funcs->set_fine_grain_clk_vol)
+		return 0;
+

Better for this also to return -EOPNOTSUPP. There are a few other funcs below also which returns 0, instead they should return EOPNOTSUPP. Let the caller decide what to do when not supported instead of returning 'fake success'.

Quoted 176 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +176 -0
+	return pp_funcs->set_fine_grain_clk_vol(adev->powerplay.pp_handle,
+						type,
+						input,
+						size);
+}
+
+int amdgpu_dpm_odn_edit_dpm_table(struct amdgpu_device *adev,
+				  uint32_t type,
+				  long *input,
+				  uint32_t size)
+{
+	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+
+	if (!pp_funcs->odn_edit_dpm_table)
+		return 0;
+
+	return pp_funcs->odn_edit_dpm_table(adev->powerplay.pp_handle,
+					    type,
+					    input,
+					    size);
+}
+
+int amdgpu_dpm_print_clock_levels(struct amdgpu_device *adev,
+				  enum pp_clock_type type,
+				  char *buf)
+{
+	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+
+	if (!pp_funcs->print_clock_levels)
+		return 0;
+
+	return pp_funcs->print_clock_levels(adev->powerplay.pp_handle,
+					    type,
+					    buf);
+}
+
+int amdgpu_dpm_set_ppfeature_status(struct amdgpu_device *adev,
+				    uint64_t ppfeature_masks)
+{
+	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+
+	if (!pp_funcs->set_ppfeature_status)
+		return 0;
+
+	return pp_funcs->set_ppfeature_status(adev->powerplay.pp_handle,
+					      ppfeature_masks);
+}
+
+int amdgpu_dpm_get_ppfeature_status(struct amdgpu_device *adev, char *buf)
+{
+	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+
+	if (!pp_funcs->get_ppfeature_status)
+		return 0;
+
+	return pp_funcs->get_ppfeature_status(adev->powerplay.pp_handle,
+					      buf);
+}
+
+int amdgpu_dpm_force_clock_level(struct amdgpu_device *adev,
+				 enum pp_clock_type type,
+				 uint32_t mask)
+{
+	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+
+	if (!pp_funcs->force_clock_level)
+		return 0;
+
+	return pp_funcs->force_clock_level(adev->powerplay.pp_handle,
+					   type,
+					   mask);
+}
+
+int amdgpu_dpm_get_sclk_od(struct amdgpu_device *adev)
+{
+	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+
+	if (!pp_funcs->get_sclk_od)
+		return 0;
+
+	return pp_funcs->get_sclk_od(adev->powerplay.pp_handle);
+}
+
+int amdgpu_dpm_set_sclk_od(struct amdgpu_device *adev, uint32_t value)
+{
+	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+
+	if (!pp_funcs->set_sclk_od)
+		return -EOPNOTSUPP;
+
+	pp_funcs->set_sclk_od(adev->powerplay.pp_handle, value);
+
+	if (amdgpu_dpm_dispatch_task(adev,
+				     AMD_PP_TASK_READJUST_POWER_STATE,
+				     NULL) == -EOPNOTSUPP) {
+		adev->pm.dpm.current_ps = adev->pm.dpm.boot_ps;
+		amdgpu_pm_compute_clocks(adev);
+	}
+
+	return 0;
+}
+
+int amdgpu_dpm_get_mclk_od(struct amdgpu_device *adev)
+{
+	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+
+	if (!pp_funcs->get_mclk_od)
+		return 0;
+
+	return pp_funcs->get_mclk_od(adev->powerplay.pp_handle);
+}
+
+int amdgpu_dpm_set_mclk_od(struct amdgpu_device *adev, uint32_t value)
+{
+	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+
+	if (!pp_funcs->set_mclk_od)
+		return -EOPNOTSUPP;
+
+	pp_funcs->set_mclk_od(adev->powerplay.pp_handle, value);
+
+	if (amdgpu_dpm_dispatch_task(adev,
+				     AMD_PP_TASK_READJUST_POWER_STATE,
+				     NULL) == -EOPNOTSUPP) {
+		adev->pm.dpm.current_ps = adev->pm.dpm.boot_ps;
+		amdgpu_pm_compute_clocks(adev);
+	}
+
+	return 0;
+}
+
+int amdgpu_dpm_get_power_profile_mode(struct amdgpu_device *adev,
+				      char *buf)
+{
+	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+
+	if (!pp_funcs->get_power_profile_mode)
+		return -EOPNOTSUPP;
+
+	return pp_funcs->get_power_profile_mode(adev->powerplay.pp_handle,
+						buf);
+}
+
+int amdgpu_dpm_set_power_profile_mode(struct amdgpu_device *adev,
+				      long *input, uint32_t size)
+{
+	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+
+	if (!pp_funcs->set_power_profile_mode)
+		return 0;
+
+	return pp_funcs->set_power_profile_mode(adev->powerplay.pp_handle,
+						input,
+						size);
+}
+
+int amdgpu_dpm_get_gpu_metrics(struct amdgpu_device *adev, void **table)
+{
+	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+
+	if (!pp_funcs->get_gpu_metrics)
+		return 0;
+
+	return pp_funcs->get_gpu_metrics(adev->powerplay.pp_handle, table);
+}
+
+int amdgpu_dpm_get_fan_control_mode(struct amdgpu_device *adev,
+				    uint32_t *fan_mode)
+{
+	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+
+	if (!pp_funcs->get_fan_control_mode)
+		return -EOPNOTSUPP;
+
+	*fan_mode = pp_funcs->get_fan_control_mode(adev->powerplay.pp_handle);
+

drivers/gpu/drm/amd/pm/amdgpu_dpm.c int amdgpu_dpm_get_ecc_info(struct amdgpu_device *adev, · line 2009

Quoted 10 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +10 -0
+	return 0;
+}
+
+int amdgpu_dpm_set_fan_speed_pwm(struct amdgpu_device *adev,
+				 uint32_t speed)
+{
+	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+
+	if (!pp_funcs->set_fan_speed_pwm)
+		return -EINVAL;

To be consistent, use EOPNOTSUPP when the function is not implemented. The return of EINVAL from actual function call shouldn't be mixed with this.

Quoted 50 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +50 -0
+
+	return pp_funcs->set_fan_speed_pwm(adev->powerplay.pp_handle, speed);
+}
+
+int amdgpu_dpm_get_fan_speed_pwm(struct amdgpu_device *adev,
+				 uint32_t *speed)
+{
+	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+
+	if (!pp_funcs->get_fan_speed_pwm)
+		return -EINVAL;
+
+	return pp_funcs->get_fan_speed_pwm(adev->powerplay.pp_handle, speed);
+}
+
+int amdgpu_dpm_get_fan_speed_rpm(struct amdgpu_device *adev,
+				 uint32_t *speed)
+{
+	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+
+	if (!pp_funcs->get_fan_speed_rpm)
+		return -EINVAL;
+
+	return pp_funcs->get_fan_speed_rpm(adev->powerplay.pp_handle, speed);
+}
+
+int amdgpu_dpm_set_fan_speed_rpm(struct amdgpu_device *adev,
+				 uint32_t speed)
+{
+	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+
+	if (!pp_funcs->set_fan_speed_rpm)
+		return -EINVAL;
+
+	return pp_funcs->set_fan_speed_rpm(adev->powerplay.pp_handle, speed);
+}
+
+int amdgpu_dpm_set_fan_control_mode(struct amdgpu_device *adev,
+				    uint32_t mode)
+{
+	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+
+	if (!pp_funcs->set_fan_control_mode)
+		return -EOPNOTSUPP;
+
+	pp_funcs->set_fan_control_mode(adev->powerplay.pp_handle, mode);
+
+	return 0;
+}
+

drivers/gpu/drm/amd/pm/amdgpu_dpm.c int amdgpu_dpm_get_ecc_info(struct amdgpu_device *adev, · line 2069

Quoted 10 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +10 -0
+int amdgpu_dpm_get_power_limit(struct amdgpu_device *adev,
+			       uint32_t *limit,
+			       enum pp_power_limit_level pp_limit_level,
+			       enum pp_power_type power_type)
+{
+	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+
+	if (!pp_funcs->get_power_limit)
+		return -ENODATA;
+

Again, this is mixing API error code based on caller's usage. In standalone implementatoin, this should also just return EOPNOTSUPP. hwmon API implementation can decide what to return when there is no API support.

Quoted 125 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +91 -0
+	return pp_funcs->get_power_limit(adev->powerplay.pp_handle,
+					 limit,
+					 pp_limit_level,
+					 power_type);
+}
+
+int amdgpu_dpm_set_power_limit(struct amdgpu_device *adev,
+			       uint32_t limit)
+{
+	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+
+	if (!pp_funcs->set_power_limit)
+		return -EINVAL;
+
+	return pp_funcs->set_power_limit(adev->powerplay.pp_handle, limit);
+}
+
+int amdgpu_dpm_is_cclk_dpm_supported(struct amdgpu_device *adev)
+{
+	if (!is_support_sw_smu(adev))
+		return false;
+
+	return is_support_cclk_dpm(adev);
+}
+
+int amdgpu_dpm_debugfs_print_current_performance_level(struct amdgpu_device *adev,
+						       struct seq_file *m)
+{
+	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+
+	if (!pp_funcs->debugfs_print_current_performance_level)
+		return -EOPNOTSUPP;
+
+	pp_funcs->debugfs_print_current_performance_level(adev->powerplay.pp_handle,
+							  m);
+
+	return 0;
+}
+
+int amdgpu_dpm_get_smu_prv_buf_details(struct amdgpu_device *adev,
+				       void **addr,
+				       size_t *size)
+{
+	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+
+	if (!pp_funcs->get_smu_prv_buf_details)
+		return -ENOSYS;
+
+	return pp_funcs->get_smu_prv_buf_details(adev->powerplay.pp_handle,
+						 addr,
+						 size);
+}
+
+int amdgpu_dpm_is_overdrive_supported(struct amdgpu_device *adev)
+{
+	struct pp_hwmgr *hwmgr = adev->powerplay.pp_handle;
+
+	if ((is_support_sw_smu(adev) && adev->smu.od_enabled) ||
+	    (is_support_sw_smu(adev) && adev->smu.is_apu) ||
+		(!is_support_sw_smu(adev) && hwmgr->od_enabled))
+		return true;
+
+	return false;
+}
+
+int amdgpu_dpm_set_pp_table(struct amdgpu_device *adev,
+			    const char *buf,
+			    size_t size)
+{
+	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+
+	if (!pp_funcs->set_pp_table)
+		return -EOPNOTSUPP;
+
+	return pp_funcs->set_pp_table(adev->powerplay.pp_handle,
+				      buf,
+				      size);
+}
+
+int amdgpu_dpm_get_num_cpu_cores(struct amdgpu_device *adev)
+{
+	return adev->smu.cpu_core_num;
+}
+
+void amdgpu_dpm_stb_debug_fs_init(struct amdgpu_device *adev)
+{
+	if (!is_support_sw_smu(adev))
+		return;
+
+	amdgpu_smu_stb_debug_fs_init(adev);
+}
drivers/gpu/drm/amd/pm/amdgpu_pm.c +1 -7
index 082539c70fd4..3382d30b5d90 100644
@@ -34,7 +34,6 @@
  #include <linux/nospec.h>
  #include <linux/pm_runtime.h>
  #include <asm/processor.h>
-#include "hwmgr.h"
 
  static const struct cg_flag_name clocks[] = {
  	{AMD_CG_SUPPORT_GFX_FGCG, "Graphics Fine Grain Clock Gating"},
@@ -132,7 +131,6 @@ static ssize_t amdgpu_get_power_dpm_state(struct device *dev,
  {
  	struct drm_device *ddev = dev_get_drvdata(dev);
  	struct amdgpu_device *adev = drm_to_adev(ddev);
-	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
  	enum amd_pm_state_type pm;
  	int ret;
 
@@ -147,11 +145,7 @@ static ssize_t amdgpu_get_power_dpm_state(struct device *dev,
  		return ret;
  	}
 
-	if (pp_funcs->get_current_power_state) {
-		pm = amdgpu_dpm_get_current_power_state(adev);
-	} else {
-		pm = adev->pm.dpm.user_state;
-	}
+	amdgpu_dpm_get_current_power_state(adev, &pm);
 
  	pm_runtime_mark_last_busy(ddev->dev);
  	pm_runtime_put_autosuspend(ddev->dev);

drivers/gpu/drm/amd/pm/amdgpu_pm.c static ssize_t amdgpu_set_power_dpm_state(struct device *dev, · line 197

Quoted 7 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +0 -4
@@ -191,19 +185,8 @@ static ssize_t amdgpu_set_power_dpm_state(struct device *dev,
  		return ret;
  	}
 
-	if (is_support_sw_smu(adev)) {
-		mutex_lock(&adev->pm.mutex);
-		adev->pm.dpm.user_state = state;
-		mutex_unlock(&adev->pm.mutex);

Here the code just sets the state and exits. However, when moved to refactored function, it is calling pm_compute_clocks.

Quoted 280 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +66 -103
-	} else if (adev->powerplay.pp_funcs->dispatch_tasks) {
-		amdgpu_dpm_dispatch_task(adev, AMD_PP_TASK_ENABLE_USER_STATE, &state);
-	} else {
-		mutex_lock(&adev->pm.mutex);
-		adev->pm.dpm.user_state = state;
-		mutex_unlock(&adev->pm.mutex);
+	amdgpu_dpm_set_power_state(adev, state);
 
-		amdgpu_pm_compute_clocks(adev);
-	}
  	pm_runtime_mark_last_busy(ddev->dev);
  	pm_runtime_put_autosuspend(ddev->dev);
 
@@ -290,10 +273,7 @@ static ssize_t amdgpu_get_power_dpm_force_performance_level(struct device *dev,
  		return ret;
  	}
 
-	if (adev->powerplay.pp_funcs->get_performance_level)
-		level = amdgpu_dpm_get_performance_level(adev);
-	else
-		level = adev->pm.dpm.forced_level;
+	level = amdgpu_dpm_get_performance_level(adev);
 
  	pm_runtime_mark_last_busy(ddev->dev);
  	pm_runtime_put_autosuspend(ddev->dev);
@@ -318,7 +298,6 @@ static ssize_t amdgpu_set_power_dpm_force_performance_level(struct device *dev,
  {
  	struct drm_device *ddev = dev_get_drvdata(dev);
  	struct amdgpu_device *adev = drm_to_adev(ddev);
-	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
  	enum amd_dpm_forced_level level;
  	enum amd_dpm_forced_level current_level;
  	int ret = 0;
@@ -358,11 +337,7 @@ static ssize_t amdgpu_set_power_dpm_force_performance_level(struct device *dev,
  		return ret;
  	}
 
-	if (pp_funcs->get_performance_level)
-		current_level = amdgpu_dpm_get_performance_level(adev);
-	else
-		current_level = adev->pm.dpm.forced_level;
-
+	current_level = amdgpu_dpm_get_performance_level(adev);
  	if (current_level == level) {
  		pm_runtime_mark_last_busy(ddev->dev);
  		pm_runtime_put_autosuspend(ddev->dev);
@@ -390,25 +365,12 @@ static ssize_t amdgpu_set_power_dpm_force_performance_level(struct device *dev,
  		return -EINVAL;
  	}
 
-	if (pp_funcs->force_performance_level) {
-		mutex_lock(&adev->pm.mutex);
-		if (adev->pm.dpm.thermal_active) {
-			mutex_unlock(&adev->pm.mutex);
-			pm_runtime_mark_last_busy(ddev->dev);
-			pm_runtime_put_autosuspend(ddev->dev);
-			return -EINVAL;
-		}
-		ret = amdgpu_dpm_force_performance_level(adev, level);
-		if (ret) {
-			mutex_unlock(&adev->pm.mutex);
-			pm_runtime_mark_last_busy(ddev->dev);
-			pm_runtime_put_autosuspend(ddev->dev);
-			return -EINVAL;
-		} else {
-			adev->pm.dpm.forced_level = level;
-		}
-		mutex_unlock(&adev->pm.mutex);
+	if (amdgpu_dpm_force_performance_level(adev, level)) {
+		pm_runtime_mark_last_busy(ddev->dev);
+		pm_runtime_put_autosuspend(ddev->dev);
+		return -EINVAL;
  	}
+
  	pm_runtime_mark_last_busy(ddev->dev);
  	pm_runtime_put_autosuspend(ddev->dev);
 
@@ -421,7 +383,6 @@ static ssize_t amdgpu_get_pp_num_states(struct device *dev,
  {
  	struct drm_device *ddev = dev_get_drvdata(dev);
  	struct amdgpu_device *adev = drm_to_adev(ddev);
-	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
  	struct pp_states_info data;
  	uint32_t i;
  	int buf_len, ret;
@@ -437,11 +398,8 @@ static ssize_t amdgpu_get_pp_num_states(struct device *dev,
  		return ret;
  	}
 
-	if (pp_funcs->get_pp_num_states) {
-		amdgpu_dpm_get_pp_num_states(adev, &data);
-	} else {
+	if (amdgpu_dpm_get_pp_num_states(adev, &data))
  		memset(&data, 0, sizeof(data));
-	}
 
  	pm_runtime_mark_last_busy(ddev->dev);
  	pm_runtime_put_autosuspend(ddev->dev);
@@ -463,7 +421,6 @@ static ssize_t amdgpu_get_pp_cur_state(struct device *dev,
  {
  	struct drm_device *ddev = dev_get_drvdata(dev);
  	struct amdgpu_device *adev = drm_to_adev(ddev);
-	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
  	struct pp_states_info data = {0};
  	enum amd_pm_state_type pm = 0;
  	int i = 0, ret = 0;
@@ -479,15 +436,16 @@ static ssize_t amdgpu_get_pp_cur_state(struct device *dev,
  		return ret;
  	}
 
-	if (pp_funcs->get_current_power_state
-		 && pp_funcs->get_pp_num_states) {
-		pm = amdgpu_dpm_get_current_power_state(adev);
-		amdgpu_dpm_get_pp_num_states(adev, &data);
-	}
+	amdgpu_dpm_get_current_power_state(adev, &pm);
+
+	ret = amdgpu_dpm_get_pp_num_states(adev, &data);
 
  	pm_runtime_mark_last_busy(ddev->dev);
  	pm_runtime_put_autosuspend(ddev->dev);
 
+	if (ret)
+		return ret;
+
  	for (i = 0; i < data.nums; i++) {
  		if (pm == data.states[i])
  			break;
@@ -525,6 +483,7 @@ static ssize_t amdgpu_set_pp_force_state(struct device *dev,
  	struct drm_device *ddev = dev_get_drvdata(dev);
  	struct amdgpu_device *adev = drm_to_adev(ddev);
  	enum amd_pm_state_type state = 0;
+	struct pp_states_info data;
  	unsigned long idx;
  	int ret;
 
@@ -533,41 +492,49 @@ static ssize_t amdgpu_set_pp_force_state(struct device *dev,
  	if (adev->in_suspend && !adev->in_runpm)
  		return -EPERM;
 
-	if (strlen(buf) == 1)
-		adev->pp_force_state_enabled = false;
-	else if (is_support_sw_smu(adev))
-		adev->pp_force_state_enabled = false;
-	else if (adev->powerplay.pp_funcs->dispatch_tasks &&
-			adev->powerplay.pp_funcs->get_pp_num_states) {
-		struct pp_states_info data;
-
-		ret = kstrtoul(buf, 0, &idx);
-		if (ret || idx >= ARRAY_SIZE(data.states))
-			return -EINVAL;
+	adev->pp_force_state_enabled = false;
 
-		idx = array_index_nospec(idx, ARRAY_SIZE(data.states));
+	if (strlen(buf) == 1)
+		return count;
 
-		amdgpu_dpm_get_pp_num_states(adev, &data);
-		state = data.states[idx];
+	ret = kstrtoul(buf, 0, &idx);
+	if (ret || idx >= ARRAY_SIZE(data.states))
+		return -EINVAL;
 
-		ret = pm_runtime_get_sync(ddev->dev);
-		if (ret < 0) {
-			pm_runtime_put_autosuspend(ddev->dev);
-			return ret;
-		}
+	idx = array_index_nospec(idx, ARRAY_SIZE(data.states));
 
-		/* only set user selected power states */
-		if (state != POWER_STATE_TYPE_INTERNAL_BOOT &&
-		    state != POWER_STATE_TYPE_DEFAULT) {
-			amdgpu_dpm_dispatch_task(adev,
-					AMD_PP_TASK_ENABLE_USER_STATE, &state);
-			adev->pp_force_state_enabled = true;
-		}
-		pm_runtime_mark_last_busy(ddev->dev);
+	ret = pm_runtime_get_sync(ddev->dev);
+	if (ret < 0) {
  		pm_runtime_put_autosuspend(ddev->dev);
+		return ret;
+	}
+
+	ret = amdgpu_dpm_get_pp_num_states(adev, &data);
+	if (ret)
+		goto err_out;
+
+	state = data.states[idx];
+
+	/* only set user selected power states */
+	if (state != POWER_STATE_TYPE_INTERNAL_BOOT &&
+	    state != POWER_STATE_TYPE_DEFAULT) {
+		ret = amdgpu_dpm_dispatch_task(adev,
+				AMD_PP_TASK_ENABLE_USER_STATE, &state);
+		if (ret)
+			goto err_out;
+
+		adev->pp_force_state_enabled = true;
  	}
 
+	pm_runtime_mark_last_busy(ddev->dev);
+	pm_runtime_put_autosuspend(ddev->dev);
+
  	return count;
+
+err_out:
+	pm_runtime_mark_last_busy(ddev->dev);
+	pm_runtime_put_autosuspend(ddev->dev);
+	return ret;
  }
 
  /**
@@ -601,17 +568,13 @@ static ssize_t amdgpu_get_pp_table(struct device *dev,
  		return ret;
  	}
 
-	if (adev->powerplay.pp_funcs->get_pp_table) {
-		size = amdgpu_dpm_get_pp_table(adev, &table);
-		pm_runtime_mark_last_busy(ddev->dev);
-		pm_runtime_put_autosuspend(ddev->dev);
-		if (size < 0)
-			return size;
-	} else {
-		pm_runtime_mark_last_busy(ddev->dev);
-		pm_runtime_put_autosuspend(ddev->dev);
-		return 0;
-	}
+	size = amdgpu_dpm_get_pp_table(adev, &table);
+
+	pm_runtime_mark_last_busy(ddev->dev);
+	pm_runtime_put_autosuspend(ddev->dev);
+
+	if (size <= 0)
+		return size;
 
  	if (size >= PAGE_SIZE)
  		size = PAGE_SIZE - 1;
@@ -642,15 +605,13 @@ static ssize_t amdgpu_set_pp_table(struct device *dev,
  	}
 
  	ret = amdgpu_dpm_set_pp_table(adev, buf, count);
-	if (ret) {
-		pm_runtime_mark_last_busy(ddev->dev);
-		pm_runtime_put_autosuspend(ddev->dev);
-		return ret;
-	}
 
  	pm_runtime_mark_last_busy(ddev->dev);
  	pm_runtime_put_autosuspend(ddev->dev);
 
+	if (ret)
+		return ret;
+
  	return count;
  }
 
@@ -866,46 +827,32 @@ static ssize_t amdgpu_set_pp_od_clk_voltage(struct device *dev,
  		return ret;
  	}
 
-	if (adev->powerplay.pp_funcs->set_fine_grain_clk_vol) {
-		ret = amdgpu_dpm_set_fine_grain_clk_vol(adev, type,
-							parameter,
-							parameter_size);
-		if (ret) {
-			pm_runtime_mark_last_busy(ddev->dev);
-			pm_runtime_put_autosuspend(ddev->dev);
-			return -EINVAL;
-		}
-	}
+	if (amdgpu_dpm_set_fine_grain_clk_vol(adev,
+					      type,
+					      parameter,
+					      parameter_size))
+		goto err_out;
 
-	if (adev->powerplay.pp_funcs->odn_edit_dpm_table) {
-		ret = amdgpu_dpm_odn_edit_dpm_table(adev, type,
-						    parameter, parameter_size);

drivers/gpu/drm/amd/pm/amdgpu_pm.c static ssize_t amdgpu_set_pp_od_clk_voltage(struct device *dev, · line 839

Quoted 10 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +3 -6
-		if (ret) {
-			pm_runtime_mark_last_busy(ddev->dev);
-			pm_runtime_put_autosuspend(ddev->dev);
-			return -EINVAL;
-		}
-	}
+	if (amdgpu_dpm_odn_edit_dpm_table(adev, type,
+					  parameter, parameter_size))
+		goto err_out;
 

This is one example of returning 'fake success' effect. If the function is not implemented it proceeds. There is no need to proceed if there is no support.

Thanks,
Lijo

Quoted 852 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +112 -217
  	if (type == PP_OD_COMMIT_DPM_TABLE) {
-		if (adev->powerplay.pp_funcs->dispatch_tasks) {
-			amdgpu_dpm_dispatch_task(adev,
-						 AMD_PP_TASK_READJUST_POWER_STATE,
-						 NULL);
-			pm_runtime_mark_last_busy(ddev->dev);
-			pm_runtime_put_autosuspend(ddev->dev);
-			return count;
-		} else {
-			pm_runtime_mark_last_busy(ddev->dev);
-			pm_runtime_put_autosuspend(ddev->dev);
-			return -EINVAL;
-		}
+		if (amdgpu_dpm_dispatch_task(adev,
+					     AMD_PP_TASK_READJUST_POWER_STATE,
+					     NULL))
+			goto err_out;
  	}
 
  	pm_runtime_mark_last_busy(ddev->dev);
  	pm_runtime_put_autosuspend(ddev->dev);
 
  	return count;
+
+err_out:
+	pm_runtime_mark_last_busy(ddev->dev);
+	pm_runtime_put_autosuspend(ddev->dev);
+	return -EINVAL;
  }
 
  static ssize_t amdgpu_get_pp_od_clk_voltage(struct device *dev,
@@ -928,8 +875,8 @@ static ssize_t amdgpu_get_pp_od_clk_voltage(struct device *dev,
  		return ret;
  	}
 
-	if (adev->powerplay.pp_funcs->print_clock_levels) {
-		size = amdgpu_dpm_print_clock_levels(adev, OD_SCLK, buf);
+	size = amdgpu_dpm_print_clock_levels(adev, OD_SCLK, buf);
+	if (size > 0) {
  		size += amdgpu_dpm_print_clock_levels(adev, OD_MCLK, buf+size);
  		size += amdgpu_dpm_print_clock_levels(adev, OD_VDDC_CURVE, buf+size);
  		size += amdgpu_dpm_print_clock_levels(adev, OD_VDDGFX_OFFSET, buf+size);
@@ -985,17 +932,14 @@ static ssize_t amdgpu_set_pp_features(struct device *dev,
  		return ret;
  	}
 
-	if (adev->powerplay.pp_funcs->set_ppfeature_status) {
-		ret = amdgpu_dpm_set_ppfeature_status(adev, featuremask);
-		if (ret) {
-			pm_runtime_mark_last_busy(ddev->dev);
-			pm_runtime_put_autosuspend(ddev->dev);
-			return -EINVAL;
-		}
-	}
+	ret = amdgpu_dpm_set_ppfeature_status(adev, featuremask);
+
  	pm_runtime_mark_last_busy(ddev->dev);
  	pm_runtime_put_autosuspend(ddev->dev);
 
+	if (ret)
+		return -EINVAL;
+
  	return count;
  }
 
@@ -1019,9 +963,8 @@ static ssize_t amdgpu_get_pp_features(struct device *dev,
  		return ret;
  	}
 
-	if (adev->powerplay.pp_funcs->get_ppfeature_status)
-		size = amdgpu_dpm_get_ppfeature_status(adev, buf);
-	else
+	size = amdgpu_dpm_get_ppfeature_status(adev, buf);
+	if (size <= 0)
  		size = sysfs_emit(buf, "\n");
 
  	pm_runtime_mark_last_busy(ddev->dev);
@@ -1080,9 +1023,8 @@ static ssize_t amdgpu_get_pp_dpm_clock(struct device *dev,
  		return ret;
  	}
 
-	if (adev->powerplay.pp_funcs->print_clock_levels)
-		size = amdgpu_dpm_print_clock_levels(adev, type, buf);
-	else
+	size = amdgpu_dpm_print_clock_levels(adev, type, buf);
+	if (size <= 0)
  		size = sysfs_emit(buf, "\n");
 
  	pm_runtime_mark_last_busy(ddev->dev);
@@ -1151,10 +1093,7 @@ static ssize_t amdgpu_set_pp_dpm_clock(struct device *dev,
  		return ret;
  	}
 
-	if (adev->powerplay.pp_funcs->force_clock_level)
-		ret = amdgpu_dpm_force_clock_level(adev, type, mask);
-	else
-		ret = 0;
+	ret = amdgpu_dpm_force_clock_level(adev, type, mask);
 
  	pm_runtime_mark_last_busy(ddev->dev);
  	pm_runtime_put_autosuspend(ddev->dev);
@@ -1305,10 +1244,7 @@ static ssize_t amdgpu_get_pp_sclk_od(struct device *dev,
  		return ret;
  	}
 
-	if (is_support_sw_smu(adev))
-		value = 0;
-	else if (adev->powerplay.pp_funcs->get_sclk_od)
-		value = amdgpu_dpm_get_sclk_od(adev);
+	value = amdgpu_dpm_get_sclk_od(adev);
 
  	pm_runtime_mark_last_busy(ddev->dev);
  	pm_runtime_put_autosuspend(ddev->dev);
@@ -1342,19 +1278,7 @@ static ssize_t amdgpu_set_pp_sclk_od(struct device *dev,
  		return ret;
  	}
 
-	if (is_support_sw_smu(adev)) {
-		value = 0;
-	} else {
-		if (adev->powerplay.pp_funcs->set_sclk_od)
-			amdgpu_dpm_set_sclk_od(adev, (uint32_t)value);
-
-		if (adev->powerplay.pp_funcs->dispatch_tasks) {
-			amdgpu_dpm_dispatch_task(adev, AMD_PP_TASK_READJUST_POWER_STATE, NULL);
-		} else {
-			adev->pm.dpm.current_ps = adev->pm.dpm.boot_ps;
-			amdgpu_pm_compute_clocks(adev);
-		}
-	}
+	amdgpu_dpm_set_sclk_od(adev, (uint32_t)value);
 
  	pm_runtime_mark_last_busy(ddev->dev);
  	pm_runtime_put_autosuspend(ddev->dev);
@@ -1382,10 +1306,7 @@ static ssize_t amdgpu_get_pp_mclk_od(struct device *dev,
  		return ret;
  	}
 
-	if (is_support_sw_smu(adev))
-		value = 0;
-	else if (adev->powerplay.pp_funcs->get_mclk_od)
-		value = amdgpu_dpm_get_mclk_od(adev);
+	value = amdgpu_dpm_get_mclk_od(adev);
 
  	pm_runtime_mark_last_busy(ddev->dev);
  	pm_runtime_put_autosuspend(ddev->dev);
@@ -1419,19 +1340,7 @@ static ssize_t amdgpu_set_pp_mclk_od(struct device *dev,
  		return ret;
  	}
 
-	if (is_support_sw_smu(adev)) {
-		value = 0;
-	} else {
-		if (adev->powerplay.pp_funcs->set_mclk_od)
-			amdgpu_dpm_set_mclk_od(adev, (uint32_t)value);
-
-		if (adev->powerplay.pp_funcs->dispatch_tasks) {
-			amdgpu_dpm_dispatch_task(adev, AMD_PP_TASK_READJUST_POWER_STATE, NULL);
-		} else {
-			adev->pm.dpm.current_ps = adev->pm.dpm.boot_ps;
-			amdgpu_pm_compute_clocks(adev);
-		}
-	}
+	amdgpu_dpm_set_mclk_od(adev, (uint32_t)value);
 
  	pm_runtime_mark_last_busy(ddev->dev);
  	pm_runtime_put_autosuspend(ddev->dev);
@@ -1479,9 +1388,8 @@ static ssize_t amdgpu_get_pp_power_profile_mode(struct device *dev,
  		return ret;
  	}
 
-	if (adev->powerplay.pp_funcs->get_power_profile_mode)
-		size = amdgpu_dpm_get_power_profile_mode(adev, buf);
-	else
+	size = amdgpu_dpm_get_power_profile_mode(adev, buf);
+	if (size <= 0)
  		size = sysfs_emit(buf, "\n");
 
  	pm_runtime_mark_last_busy(ddev->dev);
@@ -1545,8 +1453,7 @@ static ssize_t amdgpu_set_pp_power_profile_mode(struct device *dev,
  		return ret;
  	}
 
-	if (adev->powerplay.pp_funcs->set_power_profile_mode)
-		ret = amdgpu_dpm_set_power_profile_mode(adev, parameter, parameter_size);
+	ret = amdgpu_dpm_set_power_profile_mode(adev, parameter, parameter_size);
 
  	pm_runtime_mark_last_busy(ddev->dev);
  	pm_runtime_put_autosuspend(ddev->dev);
@@ -1812,9 +1719,7 @@ static ssize_t amdgpu_get_gpu_metrics(struct device *dev,
  		return ret;
  	}
 
-	if (adev->powerplay.pp_funcs->get_gpu_metrics)
-		size = amdgpu_dpm_get_gpu_metrics(adev, &gpu_metrics);
-
+	size = amdgpu_dpm_get_gpu_metrics(adev, &gpu_metrics);
  	if (size <= 0)
  		goto out;
 
@@ -2053,7 +1958,6 @@ static int default_attr_update(struct amdgpu_device *adev, struct amdgpu_device_
  {
  	struct device_attribute *dev_attr = &attr->dev_attr;
  	const char *attr_name = dev_attr->attr.name;
-	struct pp_hwmgr *hwmgr = adev->powerplay.pp_handle;
  	enum amd_asic_type asic_type = adev->asic_type;
 
  	if (!(attr->flags & mask)) {
@@ -2076,9 +1980,7 @@ static int default_attr_update(struct amdgpu_device *adev, struct amdgpu_device_
  			*states = ATTR_STATE_UNSUPPORTED;
  	} else if (DEVICE_ATTR_IS(pp_od_clk_voltage)) {
  		*states = ATTR_STATE_UNSUPPORTED;
-		if ((is_support_sw_smu(adev) && adev->smu.od_enabled) ||
-		    (is_support_sw_smu(adev) && adev->smu.is_apu) ||
-			(!is_support_sw_smu(adev) && hwmgr->od_enabled))
+		if (amdgpu_dpm_is_overdrive_supported(adev))
  			*states = ATTR_STATE_SUPPORTED;
  	} else if (DEVICE_ATTR_IS(mem_busy_percent)) {
  		if (adev->flags & AMD_IS_APU || asic_type == CHIP_VEGA10)
@@ -2105,8 +2007,7 @@ static int default_attr_update(struct amdgpu_device *adev, struct amdgpu_device_
  		if (!(asic_type == CHIP_VANGOGH || asic_type == CHIP_SIENNA_CICHLID))
  			*states = ATTR_STATE_UNSUPPORTED;
  	} else if (DEVICE_ATTR_IS(pp_power_profile_mode)) {
-		if (!adev->powerplay.pp_funcs->get_power_profile_mode ||
-		    amdgpu_dpm_get_power_profile_mode(adev, NULL) == -EOPNOTSUPP)
+		if (amdgpu_dpm_get_power_profile_mode(adev, NULL) == -EOPNOTSUPP)
  			*states = ATTR_STATE_UNSUPPORTED;
  	}
 
@@ -2389,17 +2290,14 @@ static ssize_t amdgpu_hwmon_get_pwm1_enable(struct device *dev,
  		return ret;
  	}
 
-	if (!adev->powerplay.pp_funcs->get_fan_control_mode) {
-		pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
-		pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
-		return -EINVAL;
-	}
-
-	pwm_mode = amdgpu_dpm_get_fan_control_mode(adev);
+	ret = amdgpu_dpm_get_fan_control_mode(adev, &pwm_mode);
 
  	pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
  	pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
 
+	if (ret)
+		return -EINVAL;
+
  	return sysfs_emit(buf, "%u\n", pwm_mode);
  }
 
@@ -2427,17 +2325,14 @@ static ssize_t amdgpu_hwmon_set_pwm1_enable(struct device *dev,
  		return ret;
  	}
 
-	if (!adev->powerplay.pp_funcs->set_fan_control_mode) {
-		pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
-		pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
-		return -EINVAL;
-	}
-
-	amdgpu_dpm_set_fan_control_mode(adev, value);
+	ret = amdgpu_dpm_set_fan_control_mode(adev, value);
 
  	pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
  	pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
 
+	if (ret)
+		return -EINVAL;
+
  	return count;
  }
 
@@ -2469,32 +2364,29 @@ static ssize_t amdgpu_hwmon_set_pwm1(struct device *dev,
  	if (adev->in_suspend && !adev->in_runpm)
  		return -EPERM;
 
+	err = kstrtou32(buf, 10, &value);
+	if (err)
+		return err;
+
  	err = pm_runtime_get_sync(adev_to_drm(adev)->dev);
  	if (err < 0) {
  		pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
  		return err;
  	}
 
-	pwm_mode = amdgpu_dpm_get_fan_control_mode(adev);
+	err = amdgpu_dpm_get_fan_control_mode(adev, &pwm_mode);
+	if (err)
+		goto out;
+
  	if (pwm_mode != AMD_FAN_CTRL_MANUAL) {
  		pr_info("manual fan speed control should be enabled first\n");
-		pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
-		pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
-		return -EINVAL;
+		err = -EINVAL;
+		goto out;
  	}
 
-	err = kstrtou32(buf, 10, &value);
-	if (err) {
-		pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
-		pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
-		return err;
-	}
-
-	if (adev->powerplay.pp_funcs->set_fan_speed_pwm)
-		err = amdgpu_dpm_set_fan_speed_pwm(adev, value);
-	else
-		err = -EINVAL;
+	err = amdgpu_dpm_set_fan_speed_pwm(adev, value);
 
+out:
  	pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
  	pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
 
@@ -2523,10 +2415,7 @@ static ssize_t amdgpu_hwmon_get_pwm1(struct device *dev,
  		return err;
  	}
 
-	if (adev->powerplay.pp_funcs->get_fan_speed_pwm)
-		err = amdgpu_dpm_get_fan_speed_pwm(adev, &speed);
-	else
-		err = -EINVAL;
+	err = amdgpu_dpm_get_fan_speed_pwm(adev, &speed);
 
  	pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
  	pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
@@ -2556,10 +2445,7 @@ static ssize_t amdgpu_hwmon_get_fan1_input(struct device *dev,
  		return err;
  	}
 
-	if (adev->powerplay.pp_funcs->get_fan_speed_rpm)
-		err = amdgpu_dpm_get_fan_speed_rpm(adev, &speed);
-	else
-		err = -EINVAL;
+	err = amdgpu_dpm_get_fan_speed_rpm(adev, &speed);
 
  	pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
  	pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
@@ -2653,10 +2539,7 @@ static ssize_t amdgpu_hwmon_get_fan1_target(struct device *dev,
  		return err;
  	}
 
-	if (adev->powerplay.pp_funcs->get_fan_speed_rpm)
-		err = amdgpu_dpm_get_fan_speed_rpm(adev, &rpm);
-	else
-		err = -EINVAL;
+	err = amdgpu_dpm_get_fan_speed_rpm(adev, &rpm);
 
  	pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
  	pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
@@ -2681,32 +2564,28 @@ static ssize_t amdgpu_hwmon_set_fan1_target(struct device *dev,
  	if (adev->in_suspend && !adev->in_runpm)
  		return -EPERM;
 
+	err = kstrtou32(buf, 10, &value);
+	if (err)
+		return err;
+
  	err = pm_runtime_get_sync(adev_to_drm(adev)->dev);
  	if (err < 0) {
  		pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
  		return err;
  	}
 
-	pwm_mode = amdgpu_dpm_get_fan_control_mode(adev);
+	err = amdgpu_dpm_get_fan_control_mode(adev, &pwm_mode);
+	if (err)
+		goto out;
 
  	if (pwm_mode != AMD_FAN_CTRL_MANUAL) {
-		pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
-		pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
-		return -ENODATA;
-	}
-
-	err = kstrtou32(buf, 10, &value);
-	if (err) {
-		pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
-		pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
-		return err;
+		err = -ENODATA;
+		goto out;
  	}
 
-	if (adev->powerplay.pp_funcs->set_fan_speed_rpm)
-		err = amdgpu_dpm_set_fan_speed_rpm(adev, value);
-	else
-		err = -EINVAL;
+	err = amdgpu_dpm_set_fan_speed_rpm(adev, value);
 
+out:
  	pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
  	pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
 
@@ -2735,17 +2614,14 @@ static ssize_t amdgpu_hwmon_get_fan1_enable(struct device *dev,
  		return ret;
  	}
 
-	if (!adev->powerplay.pp_funcs->get_fan_control_mode) {
-		pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
-		pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
-		return -EINVAL;
-	}
-
-	pwm_mode = amdgpu_dpm_get_fan_control_mode(adev);
+	ret = amdgpu_dpm_get_fan_control_mode(adev, &pwm_mode);
 
  	pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
  	pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
 
+	if (ret)
+		return -EINVAL;
+
  	return sysfs_emit(buf, "%i\n", pwm_mode == AMD_FAN_CTRL_AUTO ? 0 : 1);
  }
 
@@ -2781,16 +2657,14 @@ static ssize_t amdgpu_hwmon_set_fan1_enable(struct device *dev,
  		return err;
  	}
 
-	if (!adev->powerplay.pp_funcs->set_fan_control_mode) {
-		pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
-		pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
-		return -EINVAL;
-	}
-	amdgpu_dpm_set_fan_control_mode(adev, pwm_mode);
+	err = amdgpu_dpm_set_fan_control_mode(adev, pwm_mode);
 
  	pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
  	pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
 
+	if (err)
+		return -EINVAL;
+
  	return count;
  }
 
@@ -2926,7 +2800,6 @@ static ssize_t amdgpu_hwmon_show_power_cap_generic(struct device *dev,
  					enum pp_power_limit_level pp_limit_level)
  {
  	struct amdgpu_device *adev = dev_get_drvdata(dev);
-	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
  	enum pp_power_type power_type = to_sensor_dev_attr(attr)->index;
  	uint32_t limit;
  	ssize_t size;
@@ -2937,16 +2810,13 @@ static ssize_t amdgpu_hwmon_show_power_cap_generic(struct device *dev,
  	if (adev->in_suspend && !adev->in_runpm)
  		return -EPERM;
 
-	if ( !(pp_funcs && pp_funcs->get_power_limit))
-		return -ENODATA;
-
  	r = pm_runtime_get_sync(adev_to_drm(adev)->dev);
  	if (r < 0) {
  		pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
  		return r;
  	}
 
-	r = pp_funcs->get_power_limit(adev->powerplay.pp_handle, &limit,
+	r = amdgpu_dpm_get_power_limit(adev, &limit,
  				      pp_limit_level, power_type);
 
  	if (!r)
@@ -3001,7 +2871,6 @@ static ssize_t amdgpu_hwmon_set_power_cap(struct device *dev,
  		size_t count)
  {
  	struct amdgpu_device *adev = dev_get_drvdata(dev);
-	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
  	int limit_type = to_sensor_dev_attr(attr)->index;
  	int err;
  	u32 value;
@@ -3027,10 +2896,7 @@ static ssize_t amdgpu_hwmon_set_power_cap(struct device *dev,
  		return err;
  	}
 
-	if (pp_funcs && pp_funcs->set_power_limit)
-		err = pp_funcs->set_power_limit(adev->powerplay.pp_handle, value);
-	else
-		err = -EINVAL;
+	err = amdgpu_dpm_set_power_limit(adev, value);
 
  	pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
  	pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
@@ -3303,6 +3169,7 @@ static umode_t hwmon_attributes_visible(struct kobject *kobj,
  	struct device *dev = kobj_to_dev(kobj);
  	struct amdgpu_device *adev = dev_get_drvdata(dev);
  	umode_t effective_mode = attr->mode;
+	uint32_t speed = 0;
 
  	/* under multi-vf mode, the hwmon attributes are all not supported */
  	if (amdgpu_sriov_vf(adev) && !amdgpu_sriov_is_pp_one_vf(adev))
@@ -3367,20 +3234,18 @@ static umode_t hwmon_attributes_visible(struct kobject *kobj,
  	     attr == &sensor_dev_attr_fan1_enable.dev_attr.attr))
  		return 0;
 
-	if (!is_support_sw_smu(adev)) {
-		/* mask fan attributes if we have no bindings for this asic to expose */
-		if ((!adev->powerplay.pp_funcs->get_fan_speed_pwm &&
-		     attr == &sensor_dev_attr_pwm1.dev_attr.attr) || /* can't query fan */
-		    (!adev->powerplay.pp_funcs->get_fan_control_mode &&
-		     attr == &sensor_dev_attr_pwm1_enable.dev_attr.attr)) /* can't query state */
-			effective_mode &= ~S_IRUGO;
+	/* mask fan attributes if we have no bindings for this asic to expose */
+	if (((amdgpu_dpm_get_fan_speed_pwm(adev, &speed) == -EINVAL) &&
+	      attr == &sensor_dev_attr_pwm1.dev_attr.attr) || /* can't query fan */
+	    ((amdgpu_dpm_get_fan_control_mode(adev, &speed) == -EOPNOTSUPP) &&
+	     attr == &sensor_dev_attr_pwm1_enable.dev_attr.attr)) /* can't query state */
+		effective_mode &= ~S_IRUGO;
 
-		if ((!adev->powerplay.pp_funcs->set_fan_speed_pwm &&
-		     attr == &sensor_dev_attr_pwm1.dev_attr.attr) || /* can't manage fan */
-		    (!adev->powerplay.pp_funcs->set_fan_control_mode &&
-		     attr == &sensor_dev_attr_pwm1_enable.dev_attr.attr)) /* can't manage state */
-			effective_mode &= ~S_IWUSR;
-	}
+	if (((amdgpu_dpm_set_fan_speed_pwm(adev, speed) == -EINVAL) &&
+	      attr == &sensor_dev_attr_pwm1.dev_attr.attr) || /* can't manage fan */
+	      ((amdgpu_dpm_set_fan_control_mode(adev, speed) == -EOPNOTSUPP) &&
+	      attr == &sensor_dev_attr_pwm1_enable.dev_attr.attr)) /* can't manage state */
+		effective_mode &= ~S_IWUSR;
 
  	if (((adev->family == AMDGPU_FAMILY_SI) ||
  		 ((adev->flags & AMD_IS_APU) &&
@@ -3397,22 +3262,20 @@ static umode_t hwmon_attributes_visible(struct kobject *kobj,
  	    (attr == &sensor_dev_attr_power1_average.dev_attr.attr))
  		return 0;
 
-	if (!is_support_sw_smu(adev)) {
-		/* hide max/min values if we can't both query and manage the fan */
-		if ((!adev->powerplay.pp_funcs->set_fan_speed_pwm &&
-		     !adev->powerplay.pp_funcs->get_fan_speed_pwm) &&
-		     (!adev->powerplay.pp_funcs->set_fan_speed_rpm &&
-		     !adev->powerplay.pp_funcs->get_fan_speed_rpm) &&
-		    (attr == &sensor_dev_attr_pwm1_max.dev_attr.attr ||
-		     attr == &sensor_dev_attr_pwm1_min.dev_attr.attr))
-			return 0;
+	/* hide max/min values if we can't both query and manage the fan */
+	if (((amdgpu_dpm_set_fan_speed_pwm(adev, speed) == -EINVAL) &&
+	      (amdgpu_dpm_get_fan_speed_pwm(adev, &speed) == -EINVAL) &&
+	      (amdgpu_dpm_set_fan_speed_rpm(adev, speed) == -EINVAL) &&
+	      (amdgpu_dpm_get_fan_speed_rpm(adev, &speed) == -EINVAL)) &&
+	    (attr == &sensor_dev_attr_pwm1_max.dev_attr.attr ||
+	     attr == &sensor_dev_attr_pwm1_min.dev_attr.attr))
+		return 0;
 
-		if ((!adev->powerplay.pp_funcs->set_fan_speed_rpm &&
-		     !adev->powerplay.pp_funcs->get_fan_speed_rpm) &&
-		    (attr == &sensor_dev_attr_fan1_max.dev_attr.attr ||
-		     attr == &sensor_dev_attr_fan1_min.dev_attr.attr))
-			return 0;
-	}
+	if ((amdgpu_dpm_set_fan_speed_rpm(adev, speed) == -EINVAL) &&
+	     (amdgpu_dpm_get_fan_speed_rpm(adev, &speed) == -EINVAL) &&
+	     (attr == &sensor_dev_attr_fan1_max.dev_attr.attr ||
+	     attr == &sensor_dev_attr_fan1_min.dev_attr.attr))
+		return 0;
 
  	if ((adev->family == AMDGPU_FAMILY_SI ||	/* not implemented yet */
  	     adev->family == AMDGPU_FAMILY_KV) &&	/* not implemented yet */
@@ -3542,14 +3405,15 @@ static void amdgpu_debugfs_prints_cpu_info(struct seq_file *m,
  	uint16_t *p_val;
  	uint32_t size;
  	int i;
+	uint32_t num_cpu_cores = amdgpu_dpm_get_num_cpu_cores(adev);
 
-	if (is_support_cclk_dpm(adev)) {
-		p_val = kcalloc(adev->smu.cpu_core_num, sizeof(uint16_t),
+	if (amdgpu_dpm_is_cclk_dpm_supported(adev)) {
+		p_val = kcalloc(num_cpu_cores, sizeof(uint16_t),
  				GFP_KERNEL);
 
  		if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_CPU_CLK,
  					    (void *)p_val, &size)) {
-			for (i = 0; i < adev->smu.cpu_core_num; i++)
+			for (i = 0; i < num_cpu_cores; i++)
  				seq_printf(m, "\t%u MHz (CPU%d)\n",
  					   *(p_val + i), i);
  		}
@@ -3677,27 +3541,11 @@ static int amdgpu_debugfs_pm_info_show(struct seq_file *m, void *unused)
  		return r;
  	}
 
-	if (!adev->pm.dpm_enabled) {
-		seq_printf(m, "dpm not enabled\n");
-		pm_runtime_mark_last_busy(dev->dev);
-		pm_runtime_put_autosuspend(dev->dev);
-		return 0;
-	}
-
-	if (!is_support_sw_smu(adev) &&
-	    adev->powerplay.pp_funcs->debugfs_print_current_performance_level) {
-		mutex_lock(&adev->pm.mutex);
-		if (adev->powerplay.pp_funcs->debugfs_print_current_performance_level)
-			adev->powerplay.pp_funcs->debugfs_print_current_performance_level(adev, m);
-		else
-			seq_printf(m, "Debugfs support not implemented for this asic\n");
-		mutex_unlock(&adev->pm.mutex);
-		r = 0;
-	} else {
+	if (amdgpu_dpm_debugfs_print_current_performance_level(adev, m)) {
  		r = amdgpu_debugfs_pm_info_pp(m, adev);
+		if (r)
+			goto out;
  	}
-	if (r)
-		goto out;
 
  	amdgpu_device_ip_get_clockgating_state(adev, &flags);
 
@@ -3723,21 +3571,18 @@ static ssize_t amdgpu_pm_prv_buffer_read(struct file *f, char __user *buf,
  					 size_t size, loff_t *pos)
  {
  	struct amdgpu_device *adev = file_inode(f)->i_private;
-	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
-	void *pp_handle = adev->powerplay.pp_handle;
  	size_t smu_prv_buf_size;
  	void *smu_prv_buf;
+	int ret = 0;
 
  	if (amdgpu_in_reset(adev))
  		return -EPERM;
  	if (adev->in_suspend && !adev->in_runpm)
  		return -EPERM;
 
-	if (pp_funcs && pp_funcs->get_smu_prv_buf_details)
-		pp_funcs->get_smu_prv_buf_details(pp_handle, &smu_prv_buf,
-						  &smu_prv_buf_size);
-	else
-		return -ENOSYS;
+	ret = amdgpu_dpm_get_smu_prv_buf_details(adev, &smu_prv_buf, &smu_prv_buf_size);
+	if (ret)
+		return ret;
 
  	if (!smu_prv_buf || !smu_prv_buf_size)
  		return -EINVAL;
@@ -3770,6 +3615,6 @@ void amdgpu_debugfs_pm_init(struct amdgpu_device *adev)
  					 &amdgpu_debugfs_pm_prv_buffer_fops,
  					 adev->pm.smu_prv_buffer_size);
 
-	amdgpu_smu_stb_debug_fs_init(adev);
+	amdgpu_dpm_stb_debug_fs_init(adev);
  #endif
  }
drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h +70 -90
index 7289d379a9fb..039c40b1d0cb 100644
@@ -262,9 +262,6 @@ enum amdgpu_pcie_gen {
  #define amdgpu_dpm_pre_set_power_state(adev) \
  		((adev)->powerplay.pp_funcs->pre_set_power_state((adev)->powerplay.pp_handle))
 
-#define amdgpu_dpm_set_power_state(adev) \
-		((adev)->powerplay.pp_funcs->set_power_state((adev)->powerplay.pp_handle))
-
  #define amdgpu_dpm_post_set_power_state(adev) \
  		((adev)->powerplay.pp_funcs->post_set_power_state((adev)->powerplay.pp_handle))
 
@@ -280,100 +277,13 @@ enum amdgpu_pcie_gen {
  #define amdgpu_dpm_enable_bapm(adev, e) \
  		((adev)->powerplay.pp_funcs->enable_bapm((adev)->powerplay.pp_handle, (e)))
 
-#define amdgpu_dpm_set_fan_control_mode(adev, m) \
-		((adev)->powerplay.pp_funcs->set_fan_control_mode((adev)->powerplay.pp_handle, (m)))
-
-#define amdgpu_dpm_get_fan_control_mode(adev) \
-		((adev)->powerplay.pp_funcs->get_fan_control_mode((adev)->powerplay.pp_handle))
-
-#define amdgpu_dpm_set_fan_speed_pwm(adev, s) \
-		((adev)->powerplay.pp_funcs->set_fan_speed_pwm((adev)->powerplay.pp_handle, (s)))
-
-#define amdgpu_dpm_get_fan_speed_pwm(adev, s) \
-		((adev)->powerplay.pp_funcs->get_fan_speed_pwm((adev)->powerplay.pp_handle, (s)))
-
-#define amdgpu_dpm_get_fan_speed_rpm(adev, s) \
-		((adev)->powerplay.pp_funcs->get_fan_speed_rpm)((adev)->powerplay.pp_handle, (s))
-
-#define amdgpu_dpm_set_fan_speed_rpm(adev, s) \
-		((adev)->powerplay.pp_funcs->set_fan_speed_rpm)((adev)->powerplay.pp_handle, (s))
-
-#define amdgpu_dpm_force_performance_level(adev, l) \
-		((adev)->powerplay.pp_funcs->force_performance_level((adev)->powerplay.pp_handle, (l)))
-
-#define amdgpu_dpm_get_current_power_state(adev) \
-		((adev)->powerplay.pp_funcs->get_current_power_state((adev)->powerplay.pp_handle))
-
-#define amdgpu_dpm_get_pp_num_states(adev, data) \
-		((adev)->powerplay.pp_funcs->get_pp_num_states((adev)->powerplay.pp_handle, data))
-
-#define amdgpu_dpm_get_pp_table(adev, table) \
-		((adev)->powerplay.pp_funcs->get_pp_table((adev)->powerplay.pp_handle, table))
-
-#define amdgpu_dpm_set_pp_table(adev, buf, size) \
-		((adev)->powerplay.pp_funcs->set_pp_table((adev)->powerplay.pp_handle, buf, size))
-
-#define amdgpu_dpm_print_clock_levels(adev, type, buf) \
-		((adev)->powerplay.pp_funcs->print_clock_levels((adev)->powerplay.pp_handle, type, buf))
-
-#define amdgpu_dpm_force_clock_level(adev, type, level) \
-		((adev)->powerplay.pp_funcs->force_clock_level((adev)->powerplay.pp_handle, type, level))
-
-#define amdgpu_dpm_get_sclk_od(adev) \
-		((adev)->powerplay.pp_funcs->get_sclk_od((adev)->powerplay.pp_handle))
-
-#define amdgpu_dpm_set_sclk_od(adev, value) \
-		((adev)->powerplay.pp_funcs->set_sclk_od((adev)->powerplay.pp_handle, value))
-
-#define amdgpu_dpm_get_mclk_od(adev) \
-		((adev)->powerplay.pp_funcs->get_mclk_od((adev)->powerplay.pp_handle))
-
-#define amdgpu_dpm_set_mclk_od(adev, value) \
-		((adev)->powerplay.pp_funcs->set_mclk_od((adev)->powerplay.pp_handle, value))
-
-#define amdgpu_dpm_dispatch_task(adev, task_id, user_state)		\
-		((adev)->powerplay.pp_funcs->dispatch_tasks)((adev)->powerplay.pp_handle, (task_id), (user_state))
-
  #define amdgpu_dpm_check_state_equal(adev, cps, rps, equal) \
  		((adev)->powerplay.pp_funcs->check_state_equal((adev)->powerplay.pp_handle, (cps), (rps), (equal)))
 
-#define amdgpu_dpm_get_vce_clock_state(adev, i)				\
-		((adev)->powerplay.pp_funcs->get_vce_clock_state((adev)->powerplay.pp_handle, (i)))
-
-#define amdgpu_dpm_get_performance_level(adev)				\
-		((adev)->powerplay.pp_funcs->get_performance_level((adev)->powerplay.pp_handle))
-
  #define amdgpu_dpm_reset_power_profile_state(adev, request) \
  		((adev)->powerplay.pp_funcs->reset_power_profile_state(\
  			(adev)->powerplay.pp_handle, request))
 
-#define amdgpu_dpm_get_power_profile_mode(adev, buf) \
-		((adev)->powerplay.pp_funcs->get_power_profile_mode(\
-			(adev)->powerplay.pp_handle, buf))
-
-#define amdgpu_dpm_set_power_profile_mode(adev, parameter, size) \
-		((adev)->powerplay.pp_funcs->set_power_profile_mode(\
-			(adev)->powerplay.pp_handle, parameter, size))
-
-#define amdgpu_dpm_set_fine_grain_clk_vol(adev, type, parameter, size) \
-		((adev)->powerplay.pp_funcs->set_fine_grain_clk_vol(\
-			(adev)->powerplay.pp_handle, type, parameter, size))
-
-#define amdgpu_dpm_odn_edit_dpm_table(adev, type, parameter, size) \
-		((adev)->powerplay.pp_funcs->odn_edit_dpm_table(\
-			(adev)->powerplay.pp_handle, type, parameter, size))
-
-#define amdgpu_dpm_get_ppfeature_status(adev, buf) \
-		((adev)->powerplay.pp_funcs->get_ppfeature_status(\
-			(adev)->powerplay.pp_handle, (buf)))
-
-#define amdgpu_dpm_set_ppfeature_status(adev, ppfeatures) \
-		((adev)->powerplay.pp_funcs->set_ppfeature_status(\
-			(adev)->powerplay.pp_handle, (ppfeatures)))
-
-#define amdgpu_dpm_get_gpu_metrics(adev, table) \
-		((adev)->powerplay.pp_funcs->get_gpu_metrics((adev)->powerplay.pp_handle, table))
-
  struct amdgpu_dpm {
  	struct amdgpu_ps        *ps;
  	/* number of valid power states */
@@ -598,4 +508,74 @@ void amdgpu_dpm_gfx_state_change(struct amdgpu_device *adev,
  				 enum gfx_change_state state);
  int amdgpu_dpm_get_ecc_info(struct amdgpu_device *adev,
  			    void *umc_ecc);
+struct amd_vce_state *amdgpu_dpm_get_vce_clock_state(struct amdgpu_device *adev,
+						     uint32_t idx);
+void amdgpu_dpm_get_current_power_state(struct amdgpu_device *adev, enum amd_pm_state_type *state);
+void amdgpu_dpm_set_power_state(struct amdgpu_device *adev,
+				enum amd_pm_state_type state);
+enum amd_dpm_forced_level amdgpu_dpm_get_performance_level(struct amdgpu_device *adev);
+int amdgpu_dpm_force_performance_level(struct amdgpu_device *adev,
+				       enum amd_dpm_forced_level level);
+int amdgpu_dpm_get_pp_num_states(struct amdgpu_device *adev,
+				 struct pp_states_info *states);
+int amdgpu_dpm_dispatch_task(struct amdgpu_device *adev,
+			      enum amd_pp_task task_id,
+			      enum amd_pm_state_type *user_state);
+int amdgpu_dpm_get_pp_table(struct amdgpu_device *adev, char **table);
+int amdgpu_dpm_set_fine_grain_clk_vol(struct amdgpu_device *adev,
+				      uint32_t type,
+				      long *input,
+				      uint32_t size);
+int amdgpu_dpm_odn_edit_dpm_table(struct amdgpu_device *adev,
+				  uint32_t type,
+				  long *input,
+				  uint32_t size);
+int amdgpu_dpm_print_clock_levels(struct amdgpu_device *adev,
+				  enum pp_clock_type type,
+				  char *buf);
+int amdgpu_dpm_set_ppfeature_status(struct amdgpu_device *adev,
+				    uint64_t ppfeature_masks);
+int amdgpu_dpm_get_ppfeature_status(struct amdgpu_device *adev, char *buf);
+int amdgpu_dpm_force_clock_level(struct amdgpu_device *adev,
+				 enum pp_clock_type type,
+				 uint32_t mask);
+int amdgpu_dpm_get_sclk_od(struct amdgpu_device *adev);
+int amdgpu_dpm_set_sclk_od(struct amdgpu_device *adev, uint32_t value);
+int amdgpu_dpm_get_mclk_od(struct amdgpu_device *adev);
+int amdgpu_dpm_set_mclk_od(struct amdgpu_device *adev, uint32_t value);
+int amdgpu_dpm_get_power_profile_mode(struct amdgpu_device *adev,
+				      char *buf);
+int amdgpu_dpm_set_power_profile_mode(struct amdgpu_device *adev,
+				      long *input, uint32_t size);
+int amdgpu_dpm_get_gpu_metrics(struct amdgpu_device *adev, void **table);
+int amdgpu_dpm_get_fan_control_mode(struct amdgpu_device *adev,
+				    uint32_t *fan_mode);
+int amdgpu_dpm_set_fan_speed_pwm(struct amdgpu_device *adev,
+				 uint32_t speed);
+int amdgpu_dpm_get_fan_speed_pwm(struct amdgpu_device *adev,
+				 uint32_t *speed);
+int amdgpu_dpm_get_fan_speed_rpm(struct amdgpu_device *adev,
+				 uint32_t *speed);
+int amdgpu_dpm_set_fan_speed_rpm(struct amdgpu_device *adev,
+				 uint32_t speed);
+int amdgpu_dpm_set_fan_control_mode(struct amdgpu_device *adev,
+				    uint32_t mode);
+int amdgpu_dpm_get_power_limit(struct amdgpu_device *adev,
+			       uint32_t *limit,
+			       enum pp_power_limit_level pp_limit_level,
+			       enum pp_power_type power_type);
+int amdgpu_dpm_set_power_limit(struct amdgpu_device *adev,
+			       uint32_t limit);
+int amdgpu_dpm_is_cclk_dpm_supported(struct amdgpu_device *adev);
+int amdgpu_dpm_debugfs_print_current_performance_level(struct amdgpu_device *adev,
+						       struct seq_file *m);
+int amdgpu_dpm_get_smu_prv_buf_details(struct amdgpu_device *adev,
+				       void **addr,
+				       size_t *size);
+int amdgpu_dpm_is_overdrive_supported(struct amdgpu_device *adev);
+int amdgpu_dpm_set_pp_table(struct amdgpu_device *adev,
+			    const char *buf,
+			    size_t size);
+int amdgpu_dpm_get_num_cpu_cores(struct amdgpu_device *adev);
+void amdgpu_dpm_stb_debug_fs_init(struct amdgpu_device *adev);
  #endif
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +0 -3
index d8cd7c8c4479..51358383f672 100644
@@ -470,9 +470,6 @@ bool is_support_cclk_dpm(struct amdgpu_device *adev)
  {
  	struct smu_context *smu = &adev->smu;
 
-	if (!is_support_sw_smu(adev))
-		return false;
-
  	if (!smu_feature_is_enabled(smu, SMU_FEATURE_CCLK_DPM_BIT))
  		return false;
 
author
#3 lore raw

RE: [PATCH V4 02/17] drm/amd/pm: do not expose power implementation details to amdgpu_pm.c

[AMD Official Use Only]

Quoted 126 lines

-----Original Message-----
From: Lazar, Lijo <[email protected]>
Sent: Thursday, December 9, 2021 7:58 PM
To: Quan, Evan <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>; Feng, Kenneth <[email protected]>
Subject: Re: [PATCH V4 02/17] drm/amd/pm: do not expose power implementation details to amdgpu_pm.c

Quoted 9 lines · Evan Quan

amdgpu_pm.c holds all the user sysfs/hwmon interfaces. It's another client of our power APIs. It's not proper to spike into power implementation details there.

Change-Id I397853ddb13eacfce841366de2a623535422df9a

--
v1->v2:
- drop unneeded "return;" in

amdgpu_dpm_get_current_power_state(Guchun)

Quoted 2 lines
---
  drivers/gpu/drm/amd/pm/amdgpu_dpm.c       | 456

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

Review

Quoted 6 lines
  drivers/gpu/drm/amd/pm/amdgpu_pm.c        | 519 ++++++++--------------
  drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h   | 160 +++----
  drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c |   3 -
  4 files changed, 707 insertions(+), 431 deletions(-)
(quoted diff) +0 -0

b/drivers/gpu/drm/amd/pm/amdgpu_dpm.c

drivers/gpu/drm/amd/pm/amdgpu_dpm.c static void

Quoted 4 lines

index 54abdf7080de..2c789eb5d066 100644

drivers/gpu/drm/amd/pm/amdgpu_dpm.c +0 -0
@@ -1453,7 +1453,9 @@ static void

amdgpu_dpm_change_power_state_locked(struct amdgpu_device *adev)

drivers/gpu/drm/amd/pm/amdgpu_dpm.c int amdgpu_dpm_get_ecc_info(struct

Quoted 13 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +3 -1
  	if (equal)
  		return;
 
-	amdgpu_dpm_set_power_state(adev);
+	if (adev->powerplay.pp_funcs->set_power_state)
+		adev->powerplay.pp_funcs->set_power_state(adev-
 powerplay.pp_handle);
+
  	amdgpu_dpm_post_set_power_state(adev);
 

adev->pm.dpm.current_active_crtcs = adev-
pm.dpm.new_active_crtcs;

drivers/gpu/drm/amd/pm/amdgpu_dpm.c +0 -0
@@ -1704,3 +1706,455 @@ int amdgpu_dpm_get_ecc_info(struct

amdgpu_device *adev,

drivers/gpu/drm/amd/pm/amdgpu_dpm.c int amdgpu_dpm_get_ecc_info(struct amdgpu_device *adev,

Quoted 5 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +2 -0
  	return smu_get_ecc_info(&adev->smu, umc_ecc);
  }
+
+struct amd_vce_state *amdgpu_dpm_get_vce_clock_state(struct

amdgpu_device *adev,

drivers/gpu/drm/amd/pm/amdgpu_dpm.c int amdgpu_dpm_get_ecc_info(struct amdgpu_device *adev,

Quoted 12 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +12 -0
+						     uint32_t idx)
+{
+	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+
+	if (!pp_funcs->get_vce_clock_state)
+		return NULL;
+
+	return pp_funcs->get_vce_clock_state(adev->powerplay.pp_handle,
+					     idx);
+}
+
+void amdgpu_dpm_get_current_power_state(struct amdgpu_device

*adev,

Quoted 13 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +12 -0
+					enum amd_pm_state_type *state)
+{
+	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+
+	if (!pp_funcs->get_current_power_state) {
+		*state = adev->pm.dpm.user_state;
+		return;
+	}
+
+	*state = pp_funcs->get_current_power_state(adev-
 powerplay.pp_handle);
+	if (*state < POWER_STATE_TYPE_DEFAULT ||
+	    *state > POWER_STATE_TYPE_INTERNAL_3DPERF)

drivers/gpu/drm/amd/pm/amdgpu_dpm.c int amdgpu_dpm_get_ecc_info(struct amdgpu_device *adev,

Quoted 10 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +10 -0
+		*state = adev->pm.dpm.user_state;
+}
+
+void amdgpu_dpm_set_power_state(struct amdgpu_device *adev,
+				enum amd_pm_state_type state)
+{
+	adev->pm.dpm.user_state = state;
+
+	if (adev->powerplay.pp_funcs->dispatch_tasks)
+		amdgpu_dpm_dispatch_task(adev,

AMD_PP_TASK_ENABLE_USER_STATE, &state);

drivers/gpu/drm/amd/pm/amdgpu_dpm.c int amdgpu_dpm_get_ecc_info(struct amdgpu_device *adev,

Quoted 5 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +5 -0
+	else
+		amdgpu_pm_compute_clocks(adev);
+}
+
+enum amd_dpm_forced_level

amdgpu_dpm_get_performance_level(struct amdgpu_device *adev)

Quoted 7 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +6 -0
+{
+	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+	enum amd_dpm_forced_level level;
+
+	if (pp_funcs->get_performance_level)
+		level = pp_funcs->get_performance_level(adev-

powerplay.pp_handle);

drivers/gpu/drm/amd/pm/amdgpu_dpm.c int amdgpu_dpm_get_ecc_info(struct amdgpu_device *adev,

Quoted 7 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +7 -0
+	else
+		level = adev->pm.dpm.forced_level;
+
+	return level;
+}
+
+int amdgpu_dpm_force_performance_level(struct amdgpu_device

*adev,

Quoted 11 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +9 -0
+				       enum amd_dpm_forced_level level)
+{
+	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+
+	if (pp_funcs->force_performance_level) {
+		if (adev->pm.dpm.thermal_active)
+			return -EINVAL;
+
+		if (pp_funcs->force_performance_level(adev-

powerplay.pp_handle,

drivers/gpu/drm/amd/pm/amdgpu_dpm.c +1 -0
+						      level))
Quoted 8 lines

drivers/gpu/drm/amd/pm/amdgpu_dpm.c int amdgpu_dpm_get_ecc_info(struct amdgpu_device *adev, · line 1777

Quoted 5 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +5 -0
+			return -EINVAL;
+	}
+
+	adev->pm.dpm.forced_level = level;
+

If the function is not implemented, why change the force level and return success?

[Quan, Evan] Thanks! Will update that.

Quoted 47 lines

drivers/gpu/drm/amd/pm/amdgpu_dpm.c int amdgpu_dpm_get_ecc_info(struct amdgpu_device *adev,

Quoted 13 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +12 -0
+	return 0;
+}
+
+int amdgpu_dpm_get_pp_num_states(struct amdgpu_device *adev,
+				 struct pp_states_info *states)
+{
+	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+
+	if (!pp_funcs->get_pp_num_states)
+		return -EOPNOTSUPP;
+
+	return pp_funcs->get_pp_num_states(adev->powerplay.pp_handle,

states);

drivers/gpu/drm/amd/pm/amdgpu_dpm.c int amdgpu_dpm_get_ecc_info(struct amdgpu_device *adev,

Quoted 12 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +12 -0
+}
+
+int amdgpu_dpm_dispatch_task(struct amdgpu_device *adev,
+			      enum amd_pp_task task_id,
+			      enum amd_pm_state_type *user_state)
+{
+	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+
+	if (!pp_funcs->dispatch_tasks)
+		return -EOPNOTSUPP;
+
+	return pp_funcs->dispatch_tasks(adev->powerplay.pp_handle,

task_id, user_state);

drivers/gpu/drm/amd/pm/amdgpu_dpm.c int amdgpu_dpm_get_ecc_info(struct amdgpu_device *adev,

Quoted 3 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +3 -0
+}
+
+int amdgpu_dpm_get_pp_table(struct amdgpu_device *adev, char

**table)

Quoted 16 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +16 -0
+{
+	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+
+	if (!pp_funcs->get_pp_table)
+		return 0;
+
+	return pp_funcs->get_pp_table(adev->powerplay.pp_handle, table);
+}
+
+int amdgpu_dpm_set_fine_grain_clk_vol(struct amdgpu_device *adev,
+				      uint32_t type,
+				      long *input,
+				      uint32_t size)
+{
+	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+
Quoted 8 lines

drivers/gpu/drm/amd/pm/amdgpu_dpm.c int amdgpu_dpm_get_ecc_info(struct amdgpu_device *adev, · line 1823

Quoted 3 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +3 -0
+	if (!pp_funcs->set_fine_grain_clk_vol)
+		return 0;
+

Better for this also to return -EOPNOTSUPP. There are a few other funcs below also which returns 0, instead they should return EOPNOTSUPP. Let the caller decide what to do when not supported instead of returning 'fake success'.

[Quan, Evan] Yeah, I know some(this and others mentioned below) of them seem with different/weird error return code. But unfortunately, that's how the original logic. We need to fix them in future. But for this patch series, it is not intended to bring any real logic change.

Quoted 414 lines
Quoted 49 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +1 -0
+	return pp_funcs->set_fine_grain_clk_vol(adev-

powerplay.pp_handle,

drivers/gpu/drm/amd/pm/amdgpu_dpm.c +16 -0
+						type,
+						input,
+						size);
+}
+
+int amdgpu_dpm_odn_edit_dpm_table(struct amdgpu_device *adev,
+				  uint32_t type,
+				  long *input,
+				  uint32_t size)
+{
+	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+
+	if (!pp_funcs->odn_edit_dpm_table)
+		return 0;
+
+	return pp_funcs->odn_edit_dpm_table(adev-

powerplay.pp_handle,

drivers/gpu/drm/amd/pm/amdgpu_dpm.c +28 -0
+					    type,
+					    input,
+					    size);
+}
+
+int amdgpu_dpm_print_clock_levels(struct amdgpu_device *adev,
+				  enum pp_clock_type type,
+				  char *buf)
+{
+	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+
+	if (!pp_funcs->print_clock_levels)
+		return 0;
+
+	return pp_funcs->print_clock_levels(adev->powerplay.pp_handle,
+					    type,
+					    buf);
+}
+
+int amdgpu_dpm_set_ppfeature_status(struct amdgpu_device *adev,
+				    uint64_t ppfeature_masks)
+{
+	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+
+	if (!pp_funcs->set_ppfeature_status)
+		return 0;
+
+	return pp_funcs->set_ppfeature_status(adev-

powerplay.pp_handle,

drivers/gpu/drm/amd/pm/amdgpu_dpm.c int amdgpu_dpm_get_ecc_info(struct amdgpu_device *adev,

Quoted 4 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +4 -0
+					      ppfeature_masks);
+}
+
+int amdgpu_dpm_get_ppfeature_status(struct amdgpu_device *adev,

char *buf)

Quoted 26 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +7 -0
+{
+	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+
+	if (!pp_funcs->get_ppfeature_status)
+		return 0;
+
+	return pp_funcs->get_ppfeature_status(adev-

powerplay.pp_handle,

drivers/gpu/drm/amd/pm/amdgpu_dpm.c +18 -0
+					      buf);
+}
+
+int amdgpu_dpm_force_clock_level(struct amdgpu_device *adev,
+				 enum pp_clock_type type,
+				 uint32_t mask)
+{
+	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+
+	if (!pp_funcs->force_clock_level)
+		return 0;
+
+	return pp_funcs->force_clock_level(adev->powerplay.pp_handle,
+					   type,
+					   mask);
+}
+
+int amdgpu_dpm_get_sclk_od(struct amdgpu_device *adev)

drivers/gpu/drm/amd/pm/amdgpu_dpm.c int amdgpu_dpm_get_ecc_info(struct amdgpu_device *adev,

Quoted 10 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +10 -0
+{
+	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+
+	if (!pp_funcs->get_sclk_od)
+		return 0;
+
+	return pp_funcs->get_sclk_od(adev->powerplay.pp_handle);
+}
+
+int amdgpu_dpm_set_sclk_od(struct amdgpu_device *adev, uint32_t

value)

Quoted 19 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +19 -0
+{
+	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+
+	if (!pp_funcs->set_sclk_od)
+		return -EOPNOTSUPP;
+
+	pp_funcs->set_sclk_od(adev->powerplay.pp_handle, value);
+
+	if (amdgpu_dpm_dispatch_task(adev,
+				     AMD_PP_TASK_READJUST_POWER_STATE,
+				     NULL) == -EOPNOTSUPP) {
+		adev->pm.dpm.current_ps = adev->pm.dpm.boot_ps;
+		amdgpu_pm_compute_clocks(adev);
+	}
+
+	return 0;
+}
+
+int amdgpu_dpm_get_mclk_od(struct amdgpu_device *adev)

drivers/gpu/drm/amd/pm/amdgpu_dpm.c int amdgpu_dpm_get_ecc_info(struct amdgpu_device *adev,

Quoted 10 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +10 -0
+{
+	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+
+	if (!pp_funcs->get_mclk_od)
+		return 0;
+
+	return pp_funcs->get_mclk_od(adev->powerplay.pp_handle);
+}
+
+int amdgpu_dpm_set_mclk_od(struct amdgpu_device *adev, uint32_t

value)

Quoted 9 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +9 -0
+{
+	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+
+	if (!pp_funcs->set_mclk_od)
+		return -EOPNOTSUPP;
+
+	pp_funcs->set_mclk_od(adev->powerplay.pp_handle, value);
+
+	if (amdgpu_dpm_dispatch_task(adev,

drivers/gpu/drm/amd/pm/amdgpu_dpm.c int amdgpu_dpm_get_ecc_info(struct amdgpu_device *adev,

Quoted 10 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +10 -0
+				     AMD_PP_TASK_READJUST_POWER_STATE,
+				     NULL) == -EOPNOTSUPP) {
+		adev->pm.dpm.current_ps = adev->pm.dpm.boot_ps;
+		amdgpu_pm_compute_clocks(adev);
+	}
+
+	return 0;
+}
+
+int amdgpu_dpm_get_power_profile_mode(struct amdgpu_device

*adev,

drivers/gpu/drm/amd/pm/amdgpu_dpm.c int amdgpu_dpm_get_ecc_info(struct amdgpu_device *adev,

Quoted 13 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +8 -0
+				      char *buf)
+{
+	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+
+	if (!pp_funcs->get_power_profile_mode)
+		return -EOPNOTSUPP;
+
+	return pp_funcs->get_power_profile_mode(adev-

powerplay.pp_handle,

drivers/gpu/drm/amd/pm/amdgpu_dpm.c +4 -0
+						buf);
+}
+
+int amdgpu_dpm_set_power_profile_mode(struct amdgpu_device

*adev,

Quoted 9 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +8 -0
+				      long *input, uint32_t size)
+{
+	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+
+	if (!pp_funcs->set_power_profile_mode)
+		return 0;
+
+	return pp_funcs->set_power_profile_mode(adev-

powerplay.pp_handle,

drivers/gpu/drm/amd/pm/amdgpu_dpm.c int amdgpu_dpm_get_ecc_info(struct amdgpu_device *adev,

Quoted 5 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +5 -0
+						input,
+						size);
+}
+
+int amdgpu_dpm_get_gpu_metrics(struct amdgpu_device *adev, void

**table)

drivers/gpu/drm/amd/pm/amdgpu_dpm.c int amdgpu_dpm_get_ecc_info(struct amdgpu_device *adev,

Quoted 7 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +7 -0
+{
+	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+
+	if (!pp_funcs->get_gpu_metrics)
+		return 0;
+
+	return pp_funcs->get_gpu_metrics(adev->powerplay.pp_handle,

table);

Quoted 13 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +11 -0
+}
+
+int amdgpu_dpm_get_fan_control_mode(struct amdgpu_device *adev,
+				    uint32_t *fan_mode)
+{
+	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+
+	if (!pp_funcs->get_fan_control_mode)
+		return -EOPNOTSUPP;
+
+	*fan_mode = pp_funcs->get_fan_control_mode(adev-

powerplay.pp_handle);

drivers/gpu/drm/amd/pm/amdgpu_dpm.c +1 -0
+

drivers/gpu/drm/amd/pm/amdgpu_dpm.c int amdgpu_dpm_get_ecc_info(struct amdgpu_device *adev, · line 2009

Quoted 10 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +10 -0
+	return 0;
+}
+
+int amdgpu_dpm_set_fan_speed_pwm(struct amdgpu_device *adev,
+				 uint32_t speed)
+{
+	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+
+	if (!pp_funcs->set_fan_speed_pwm)
+		return -EINVAL;

To be consistent, use EOPNOTSUPP when the function is not implemented. The return of EINVAL from actual function call shouldn't be mixed with this.

Quoted 16 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +2 -0
+
+	return pp_funcs->set_fan_speed_pwm(adev-

powerplay.pp_handle, speed);

drivers/gpu/drm/amd/pm/amdgpu_dpm.c +11 -0
+}
+
+int amdgpu_dpm_get_fan_speed_pwm(struct amdgpu_device *adev,
+				 uint32_t *speed)
+{
+	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+
+	if (!pp_funcs->get_fan_speed_pwm)
+		return -EINVAL;
+
+	return pp_funcs->get_fan_speed_pwm(adev-

powerplay.pp_handle, speed);

drivers/gpu/drm/amd/pm/amdgpu_dpm.c +1 -0
+}

drivers/gpu/drm/amd/pm/amdgpu_dpm.c int amdgpu_dpm_get_ecc_info(struct amdgpu_device *adev,

Quoted 10 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +10 -0
+
+int amdgpu_dpm_get_fan_speed_rpm(struct amdgpu_device *adev,
+				 uint32_t *speed)
+{
+	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+
+	if (!pp_funcs->get_fan_speed_rpm)
+		return -EINVAL;
+
+	return pp_funcs->get_fan_speed_rpm(adev->powerplay.pp_handle,

speed);

drivers/gpu/drm/amd/pm/amdgpu_dpm.c int amdgpu_dpm_get_ecc_info(struct amdgpu_device *adev,

Quoted 11 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +11 -0
+}
+
+int amdgpu_dpm_set_fan_speed_rpm(struct amdgpu_device *adev,
+				 uint32_t speed)
+{
+	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+
+	if (!pp_funcs->set_fan_speed_rpm)
+		return -EINVAL;
+
+	return pp_funcs->set_fan_speed_rpm(adev->powerplay.pp_handle,

speed);

drivers/gpu/drm/amd/pm/amdgpu_dpm.c int amdgpu_dpm_get_ecc_info(struct amdgpu_device *adev,

Quoted 11 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +11 -0
+}
+
+int amdgpu_dpm_set_fan_control_mode(struct amdgpu_device *adev,
+				    uint32_t mode)
+{
+	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+
+	if (!pp_funcs->set_fan_control_mode)
+		return -EOPNOTSUPP;
+
+	pp_funcs->set_fan_control_mode(adev->powerplay.pp_handle,

mode);

Quoted 4 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +4 -0
+
+	return 0;
+}
+

drivers/gpu/drm/amd/pm/amdgpu_dpm.c int amdgpu_dpm_get_ecc_info(struct amdgpu_device *adev, · line 2069

Quoted 10 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +10 -0
+int amdgpu_dpm_get_power_limit(struct amdgpu_device *adev,
+			       uint32_t *limit,
+			       enum pp_power_limit_level pp_limit_level,
+			       enum pp_power_type power_type)
+{
+	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+
+	if (!pp_funcs->get_power_limit)
+		return -ENODATA;
+

Again, this is mixing API error code based on caller's usage. In standalone implementatoin, this should also just return EOPNOTSUPP. hwmon API implementation can decide what to return when there is no API support.

Quoted 5 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +5 -0
+	return pp_funcs->get_power_limit(adev->powerplay.pp_handle,
+					 limit,
+					 pp_limit_level,
+					 power_type);
+}

drivers/gpu/drm/amd/pm/amdgpu_dpm.c int amdgpu_dpm_get_ecc_info(struct amdgpu_device *adev,

Quoted 10 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +10 -0
+
+int amdgpu_dpm_set_power_limit(struct amdgpu_device *adev,
+			       uint32_t limit)
+{
+	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+
+	if (!pp_funcs->set_power_limit)
+		return -EINVAL;
+
+	return pp_funcs->set_power_limit(adev->powerplay.pp_handle,

limit);

drivers/gpu/drm/amd/pm/amdgpu_dpm.c int amdgpu_dpm_get_ecc_info(struct amdgpu_device *adev,

Quoted 11 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +11 -0
+}
+
+int amdgpu_dpm_is_cclk_dpm_supported(struct amdgpu_device *adev)
+{
+	if (!is_support_sw_smu(adev))
+		return false;
+
+	return is_support_cclk_dpm(adev);
+}
+
+int amdgpu_dpm_debugfs_print_current_performance_level(struct

amdgpu_device *adev,

Quoted 9 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +8 -0
+						       struct seq_file *m)
+{
+	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+
+	if (!pp_funcs->debugfs_print_current_performance_level)
+		return -EOPNOTSUPP;
+
+	pp_funcs->debugfs_print_current_performance_level(adev-

powerplay.pp_handle,

drivers/gpu/drm/amd/pm/amdgpu_dpm.c int amdgpu_dpm_get_ecc_info(struct amdgpu_device *adev,

Quoted 6 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +6 -0
+							  m);
+
+	return 0;
+}
+
+int amdgpu_dpm_get_smu_prv_buf_details(struct amdgpu_device

*adev,

Review

Quoted 53 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +9 -0
+				       void **addr,
+				       size_t *size)
+{
+	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+
+	if (!pp_funcs->get_smu_prv_buf_details)
+		return -ENOSYS;
+
+	return pp_funcs->get_smu_prv_buf_details(adev-

powerplay.pp_handle,

drivers/gpu/drm/amd/pm/amdgpu_dpm.c +42 -0
+						 addr,
+						 size);
+}
+
+int amdgpu_dpm_is_overdrive_supported(struct amdgpu_device *adev)
+{
+	struct pp_hwmgr *hwmgr = adev->powerplay.pp_handle;
+
+	if ((is_support_sw_smu(adev) && adev->smu.od_enabled) ||
+	    (is_support_sw_smu(adev) && adev->smu.is_apu) ||
+		(!is_support_sw_smu(adev) && hwmgr->od_enabled))
+		return true;
+
+	return false;
+}
+
+int amdgpu_dpm_set_pp_table(struct amdgpu_device *adev,
+			    const char *buf,
+			    size_t size)
+{
+	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+
+	if (!pp_funcs->set_pp_table)
+		return -EOPNOTSUPP;
+
+	return pp_funcs->set_pp_table(adev->powerplay.pp_handle,
+				      buf,
+				      size);
+}
+
+int amdgpu_dpm_get_num_cpu_cores(struct amdgpu_device *adev)
+{
+	return adev->smu.cpu_core_num;
+}
+
+void amdgpu_dpm_stb_debug_fs_init(struct amdgpu_device *adev)
+{
+	if (!is_support_sw_smu(adev))
+		return;
+
+	amdgpu_smu_stb_debug_fs_init(adev);
+}
(quoted diff) +0 -0

b/drivers/gpu/drm/amd/pm/amdgpu_pm.c

drivers/gpu/drm/amd/pm/amdgpu_pm.c line 39

Quoted 11 lines

index 082539c70fd4..3382d30b5d90 100644

drivers/gpu/drm/amd/pm/amdgpu_pm.c +0 -1
@@ -34,7 +34,6 @@
  #include <linux/nospec.h>
  #include <linux/pm_runtime.h>
  #include <asm/processor.h>
-#include "hwmgr.h"
 
  static const struct cg_flag_name clocks[] = {
  	{AMD_CG_SUPPORT_GFX_FGCG, "Graphics Fine Grain Clock

Gating"},

drivers/gpu/drm/amd/pm/amdgpu_pm.c static ssize_t

Quoted 1 line
drivers/gpu/drm/amd/pm/amdgpu_pm.c +0 -0
@@ -132,7 +131,6 @@ static ssize_t

amdgpu_get_power_dpm_state(struct device *dev,

drivers/gpu/drm/amd/pm/amdgpu_pm.c static ssize_t

Quoted 8 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +0 -1
  {
  	struct drm_device *ddev = dev_get_drvdata(dev);
  	struct amdgpu_device *adev = drm_to_adev(ddev);
-	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
  	enum amd_pm_state_type pm;
  	int ret;
 
@@ -147,11 +145,7 @@ static ssize_t

amdgpu_get_power_dpm_state(struct device *dev,

drivers/gpu/drm/amd/pm/amdgpu_pm.c static ssize_t

Quoted 13 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +1 -5
  		return ret;
  	}
 
-	if (pp_funcs->get_current_power_state) {
-		pm = amdgpu_dpm_get_current_power_state(adev);
-	} else {
-		pm = adev->pm.dpm.user_state;
-	}
+	amdgpu_dpm_get_current_power_state(adev, &pm);
 
  	pm_runtime_mark_last_busy(ddev->dev);
  	pm_runtime_put_autosuspend(ddev->dev);
@@ -191,19 +185,8 @@ static ssize_t

amdgpu_set_power_dpm_state(struct device *dev,

Quoted 3 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +0 -0
  		return ret;
  	}
 
Quoted 7 lines

drivers/gpu/drm/amd/pm/amdgpu_pm.c static ssize_t amdgpu_set_power_dpm_state(struct device *dev, · line 197

Quoted 4 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +0 -4
-	if (is_support_sw_smu(adev)) {
-		mutex_lock(&adev->pm.mutex);
-		adev->pm.dpm.user_state = state;
-		mutex_unlock(&adev->pm.mutex);

Here the code just sets the state and exits. However, when moved to refactored function, it is calling pm_compute_clocks.

[Quan, Evan] Thanks! Will fix this.

BR
Evan

Quoted 1,314 lines

drivers/gpu/drm/amd/pm/amdgpu_pm.c static ssize_t · line 199

Quoted 3 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +0 -2
-	} else if (adev->powerplay.pp_funcs->dispatch_tasks) {
-		amdgpu_dpm_dispatch_task(adev,

AMD_PP_TASK_ENABLE_USER_STATE, &state);

drivers/gpu/drm/amd/pm/amdgpu_pm.c static ssize_t

Quoted 12 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +1 -6
-	} else {
-		mutex_lock(&adev->pm.mutex);
-		adev->pm.dpm.user_state = state;
-		mutex_unlock(&adev->pm.mutex);
+	amdgpu_dpm_set_power_state(adev, state);
 
-		amdgpu_pm_compute_clocks(adev);
-	}
  	pm_runtime_mark_last_busy(ddev->dev);
  	pm_runtime_put_autosuspend(ddev->dev);
 
@@ -290,10 +273,7 @@ static ssize_t

amdgpu_get_power_dpm_force_performance_level(struct device *dev,

drivers/gpu/drm/amd/pm/amdgpu_pm.c static ssize_t

Quoted 12 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +1 -4
  		return ret;
  	}
 
-	if (adev->powerplay.pp_funcs->get_performance_level)
-		level = amdgpu_dpm_get_performance_level(adev);
-	else
-		level = adev->pm.dpm.forced_level;
+	level = amdgpu_dpm_get_performance_level(adev);
 
  	pm_runtime_mark_last_busy(ddev->dev);
  	pm_runtime_put_autosuspend(ddev->dev);
@@ -318,7 +298,6 @@ static ssize_t

amdgpu_set_power_dpm_force_performance_level(struct device *dev,

drivers/gpu/drm/amd/pm/amdgpu_pm.c static ssize_t

Quoted 8 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +0 -1
  {
  	struct drm_device *ddev = dev_get_drvdata(dev);
  	struct amdgpu_device *adev = drm_to_adev(ddev);
-	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
  	enum amd_dpm_forced_level level;
  	enum amd_dpm_forced_level current_level;
  	int ret = 0;
@@ -358,11 +337,7 @@ static ssize_t

amdgpu_set_power_dpm_force_performance_level(struct device *dev,

drivers/gpu/drm/amd/pm/amdgpu_pm.c static ssize_t amdgpu_set_power_dpm_force_performance_level(struct device *dev,

Quoted 5 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +0 -2
  		return ret;
  	}
 
-	if (pp_funcs->get_performance_level)
-		current_level =

amdgpu_dpm_get_performance_level(adev);

drivers/gpu/drm/amd/pm/amdgpu_pm.c static ssize_t

Quoted 8 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +1 -3
-	else
-		current_level = adev->pm.dpm.forced_level;
-
+	current_level = amdgpu_dpm_get_performance_level(adev);
  	if (current_level == level) {
  		pm_runtime_mark_last_busy(ddev->dev);
  		pm_runtime_put_autosuspend(ddev->dev);
@@ -390,25 +365,12 @@ static ssize_t

amdgpu_set_power_dpm_force_performance_level(struct device *dev,

drivers/gpu/drm/amd/pm/amdgpu_pm.c static ssize_t amdgpu_get_pp_num_states(struct

Quoted 31 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +5 -18
  		return -EINVAL;
  	}
 
-	if (pp_funcs->force_performance_level) {
-		mutex_lock(&adev->pm.mutex);
-		if (adev->pm.dpm.thermal_active) {
-			mutex_unlock(&adev->pm.mutex);
-			pm_runtime_mark_last_busy(ddev->dev);
-			pm_runtime_put_autosuspend(ddev->dev);
-			return -EINVAL;
-		}
-		ret = amdgpu_dpm_force_performance_level(adev, level);
-		if (ret) {
-			mutex_unlock(&adev->pm.mutex);
-			pm_runtime_mark_last_busy(ddev->dev);
-			pm_runtime_put_autosuspend(ddev->dev);
-			return -EINVAL;
-		} else {
-			adev->pm.dpm.forced_level = level;
-		}
-		mutex_unlock(&adev->pm.mutex);
+	if (amdgpu_dpm_force_performance_level(adev, level)) {
+		pm_runtime_mark_last_busy(ddev->dev);
+		pm_runtime_put_autosuspend(ddev->dev);
+		return -EINVAL;
  	}
+
  	pm_runtime_mark_last_busy(ddev->dev);
  	pm_runtime_put_autosuspend(ddev->dev);
 
@@ -421,7 +383,6 @@ static ssize_t amdgpu_get_pp_num_states(struct

device *dev,

drivers/gpu/drm/amd/pm/amdgpu_pm.c static ssize_t amdgpu_get_pp_num_states(struct

Quoted 8 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +0 -1
  {
  	struct drm_device *ddev = dev_get_drvdata(dev);
  	struct amdgpu_device *adev = drm_to_adev(ddev);
-	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
  	struct pp_states_info data;
  	uint32_t i;
  	int buf_len, ret;
@@ -437,11 +398,8 @@ static ssize_t amdgpu_get_pp_num_states(struct

device *dev,

drivers/gpu/drm/amd/pm/amdgpu_pm.c static ssize_t amdgpu_get_pp_cur_state(struct

Quoted 13 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +1 -4
  		return ret;
  	}
 
-	if (pp_funcs->get_pp_num_states) {
-		amdgpu_dpm_get_pp_num_states(adev, &data);
-	} else {
+	if (amdgpu_dpm_get_pp_num_states(adev, &data))
  		memset(&data, 0, sizeof(data));
-	}
 
  	pm_runtime_mark_last_busy(ddev->dev);
  	pm_runtime_put_autosuspend(ddev->dev);
@@ -463,7 +421,6 @@ static ssize_t amdgpu_get_pp_cur_state(struct

device *dev,

drivers/gpu/drm/amd/pm/amdgpu_pm.c static ssize_t amdgpu_get_pp_cur_state(struct

Quoted 8 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +0 -1
  {
  	struct drm_device *ddev = dev_get_drvdata(dev);
  	struct amdgpu_device *adev = drm_to_adev(ddev);
-	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
  	struct pp_states_info data = {0};
  	enum amd_pm_state_type pm = 0;
  	int i = 0, ret = 0;
@@ -479,15 +436,16 @@ static ssize_t amdgpu_get_pp_cur_state(struct

device *dev,

drivers/gpu/drm/amd/pm/amdgpu_pm.c static ssize_t amdgpu_set_pp_force_state(struct

Quoted 22 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +6 -5
  		return ret;
  	}
 
-	if (pp_funcs->get_current_power_state
-		 && pp_funcs->get_pp_num_states) {
-		pm = amdgpu_dpm_get_current_power_state(adev);
-		amdgpu_dpm_get_pp_num_states(adev, &data);
-	}
+	amdgpu_dpm_get_current_power_state(adev, &pm);
+
+	ret = amdgpu_dpm_get_pp_num_states(adev, &data);
 
  	pm_runtime_mark_last_busy(ddev->dev);
  	pm_runtime_put_autosuspend(ddev->dev);
 
+	if (ret)
+		return ret;
+
  	for (i = 0; i < data.nums; i++) {
  		if (pm == data.states[i])
  			break;
@@ -525,6 +483,7 @@ static ssize_t amdgpu_set_pp_force_state(struct

device *dev,

drivers/gpu/drm/amd/pm/amdgpu_pm.c static ssize_t amdgpu_set_pp_force_state(struct

Quoted 8 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +1 -0
  	struct drm_device *ddev = dev_get_drvdata(dev);
  	struct amdgpu_device *adev = drm_to_adev(ddev);
  	enum amd_pm_state_type state = 0;
+	struct pp_states_info data;
  	unsigned long idx;
  	int ret;
 
@@ -533,41 +492,49 @@ static ssize_t amdgpu_set_pp_force_state(struct

device *dev,

Quoted 28 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +6 -16
  	if (adev->in_suspend && !adev->in_runpm)
  		return -EPERM;
 
-	if (strlen(buf) == 1)
-		adev->pp_force_state_enabled = false;
-	else if (is_support_sw_smu(adev))
-		adev->pp_force_state_enabled = false;
-	else if (adev->powerplay.pp_funcs->dispatch_tasks &&
-			adev->powerplay.pp_funcs->get_pp_num_states) {
-		struct pp_states_info data;
-
-		ret = kstrtoul(buf, 0, &idx);
-		if (ret || idx >= ARRAY_SIZE(data.states))
-			return -EINVAL;
+	adev->pp_force_state_enabled = false;
 
-		idx = array_index_nospec(idx, ARRAY_SIZE(data.states));
+	if (strlen(buf) == 1)
+		return count;
 
-		amdgpu_dpm_get_pp_num_states(adev, &data);
-		state = data.states[idx];
+	ret = kstrtoul(buf, 0, &idx);
+	if (ret || idx >= ARRAY_SIZE(data.states))
+		return -EINVAL;
 
-		ret = pm_runtime_get_sync(ddev->dev);
-		if (ret < 0) {

drivers/gpu/drm/amd/pm/amdgpu_pm.c static ssize_t amdgpu_set_pp_force_state(struct device *dev,

Quoted 10 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +1 -8
-			pm_runtime_put_autosuspend(ddev->dev);
-			return ret;
-		}
+	idx = array_index_nospec(idx, ARRAY_SIZE(data.states));
 
-		/* only set user selected power states */
-		if (state != POWER_STATE_TYPE_INTERNAL_BOOT &&
-		    state != POWER_STATE_TYPE_DEFAULT) {
-			amdgpu_dpm_dispatch_task(adev,
-
	AMD_PP_TASK_ENABLE_USER_STATE, &state);
Quoted 10 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +6 -3
-			adev->pp_force_state_enabled = true;
-		}
-		pm_runtime_mark_last_busy(ddev->dev);
+	ret = pm_runtime_get_sync(ddev->dev);
+	if (ret < 0) {
  		pm_runtime_put_autosuspend(ddev->dev);
+		return ret;
+	}
+
+	ret = amdgpu_dpm_get_pp_num_states(adev, &data);

drivers/gpu/drm/amd/pm/amdgpu_pm.c static ssize_t amdgpu_set_pp_force_state(struct device *dev,

Quoted 10 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +10 -0
+	if (ret)
+		goto err_out;
+
+	state = data.states[idx];
+
+	/* only set user selected power states */
+	if (state != POWER_STATE_TYPE_INTERNAL_BOOT &&
+	    state != POWER_STATE_TYPE_DEFAULT) {
+		ret = amdgpu_dpm_dispatch_task(adev,
+				AMD_PP_TASK_ENABLE_USER_STATE,

&state);

drivers/gpu/drm/amd/pm/amdgpu_pm.c static ssize_t amdgpu_get_pp_table(struct device

Quoted 19 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +12 -0
+		if (ret)
+			goto err_out;
+
+		adev->pp_force_state_enabled = true;
  	}
 
+	pm_runtime_mark_last_busy(ddev->dev);
+	pm_runtime_put_autosuspend(ddev->dev);
+
  	return count;
+
+err_out:
+	pm_runtime_mark_last_busy(ddev->dev);
+	pm_runtime_put_autosuspend(ddev->dev);
+	return ret;
  }
 
  /**
@@ -601,17 +568,13 @@ static ssize_t amdgpu_get_pp_table(struct device

*dev,

drivers/gpu/drm/amd/pm/amdgpu_pm.c static ssize_t amdgpu_set_pp_table(struct device

Quoted 25 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +7 -11
  		return ret;
  	}
 
-	if (adev->powerplay.pp_funcs->get_pp_table) {
-		size = amdgpu_dpm_get_pp_table(adev, &table);
-		pm_runtime_mark_last_busy(ddev->dev);
-		pm_runtime_put_autosuspend(ddev->dev);
-		if (size < 0)
-			return size;
-	} else {
-		pm_runtime_mark_last_busy(ddev->dev);
-		pm_runtime_put_autosuspend(ddev->dev);
-		return 0;
-	}
+	size = amdgpu_dpm_get_pp_table(adev, &table);
+
+	pm_runtime_mark_last_busy(ddev->dev);
+	pm_runtime_put_autosuspend(ddev->dev);
+
+	if (size <= 0)
+		return size;
 
  	if (size >= PAGE_SIZE)
  		size = PAGE_SIZE - 1;
@@ -642,15 +605,13 @@ static ssize_t amdgpu_set_pp_table(struct device

*dev,

drivers/gpu/drm/amd/pm/amdgpu_pm.c static ssize_t

Quoted 19 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +3 -5
  	}
 
  	ret = amdgpu_dpm_set_pp_table(adev, buf, count);
-	if (ret) {
-		pm_runtime_mark_last_busy(ddev->dev);
-		pm_runtime_put_autosuspend(ddev->dev);
-		return ret;
-	}
 
  	pm_runtime_mark_last_busy(ddev->dev);
  	pm_runtime_put_autosuspend(ddev->dev);
 
+	if (ret)
+		return ret;
+
  	return count;
  }
 
@@ -866,46 +827,32 @@ static ssize_t

amdgpu_set_pp_od_clk_voltage(struct device *dev,

Quoted 12 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +0 -9
  		return ret;
  	}
 
-	if (adev->powerplay.pp_funcs->set_fine_grain_clk_vol) {
-		ret = amdgpu_dpm_set_fine_grain_clk_vol(adev, type,
-							parameter,
-							parameter_size);
-		if (ret) {
-			pm_runtime_mark_last_busy(ddev->dev);
-			pm_runtime_put_autosuspend(ddev->dev);
-			return -EINVAL;
-		}

drivers/gpu/drm/amd/pm/amdgpu_pm.c static ssize_t amdgpu_set_pp_od_clk_voltage(struct device *dev,

Quoted 10 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +5 -4
-	}
+	if (amdgpu_dpm_set_fine_grain_clk_vol(adev,
+					      type,
+					      parameter,
+					      parameter_size))
+		goto err_out;
 
-	if (adev->powerplay.pp_funcs->odn_edit_dpm_table) {
-		ret = amdgpu_dpm_odn_edit_dpm_table(adev, type,
-						    parameter,

parameter_size);

drivers/gpu/drm/amd/pm/amdgpu_pm.c static ssize_t amdgpu_set_pp_od_clk_voltage(struct device *dev, · line 839

Quoted 10 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +3 -6
-		if (ret) {
-			pm_runtime_mark_last_busy(ddev->dev);
-			pm_runtime_put_autosuspend(ddev->dev);
-			return -EINVAL;
-		}
-	}
+	if (amdgpu_dpm_odn_edit_dpm_table(adev, type,
+					  parameter, parameter_size))
+		goto err_out;
 

This is one example of returning 'fake success' effect. If the function is not implemented it proceeds. There is no need to proceed if there is no support.

Thanks,
Lijo

drivers/gpu/drm/amd/pm/amdgpu_pm.c static ssize_t amdgpu_set_pp_od_clk_voltage(struct device *dev,

Quoted 4 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +0 -3
  	if (type == PP_OD_COMMIT_DPM_TABLE) {
-		if (adev->powerplay.pp_funcs->dispatch_tasks) {
-			amdgpu_dpm_dispatch_task(adev,
-

AMD_PP_TASK_READJUST_POWER_STATE,

drivers/gpu/drm/amd/pm/amdgpu_pm.c static ssize_t amdgpu_set_pp_od_clk_voltage(struct device *dev, · line 851

Quoted 11 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +2 -9
-						 NULL);
-			pm_runtime_mark_last_busy(ddev->dev);
-			pm_runtime_put_autosuspend(ddev->dev);
-			return count;
-		} else {
-			pm_runtime_mark_last_busy(ddev->dev);
-			pm_runtime_put_autosuspend(ddev->dev);
-			return -EINVAL;
-		}
+		if (amdgpu_dpm_dispatch_task(adev,
+

AMD_PP_TASK_READJUST_POWER_STATE,

drivers/gpu/drm/amd/pm/amdgpu_pm.c static ssize_t

Quoted 17 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +7 -0
+					     NULL))
+			goto err_out;
  	}
 
  	pm_runtime_mark_last_busy(ddev->dev);
  	pm_runtime_put_autosuspend(ddev->dev);
 
  	return count;
+
+err_out:
+	pm_runtime_mark_last_busy(ddev->dev);
+	pm_runtime_put_autosuspend(ddev->dev);
+	return -EINVAL;
  }
 
  static ssize_t amdgpu_get_pp_od_clk_voltage(struct device *dev,
@@ -928,8 +875,8 @@ static ssize_t

amdgpu_get_pp_od_clk_voltage(struct device *dev,

drivers/gpu/drm/amd/pm/amdgpu_pm.c static ssize_t amdgpu_get_pp_od_clk_voltage(struct device *dev,

Quoted 8 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +2 -2
  		return ret;
  	}
 
-	if (adev->powerplay.pp_funcs->print_clock_levels) {
-		size = amdgpu_dpm_print_clock_levels(adev, OD_SCLK, buf);
+	size = amdgpu_dpm_print_clock_levels(adev, OD_SCLK, buf);
+	if (size > 0) {
  		size += amdgpu_dpm_print_clock_levels(adev, OD_MCLK,

buf+size);

drivers/gpu/drm/amd/pm/amdgpu_pm.c static ssize_t · line 881

Quoted 1 line
drivers/gpu/drm/amd/pm/amdgpu_pm.c +0 -0
  		size += amdgpu_dpm_print_clock_levels(adev,

OD_VDDC_CURVE, buf+size);

drivers/gpu/drm/amd/pm/amdgpu_pm.c static ssize_t · line 882

Quoted 1 line
drivers/gpu/drm/amd/pm/amdgpu_pm.c +0 -0
  		size += amdgpu_dpm_print_clock_levels(adev,

OD_VDDGFX_OFFSET, buf+size);

drivers/gpu/drm/amd/pm/amdgpu_pm.c static ssize_t amdgpu_set_pp_features(struct

Quoted 1 line
drivers/gpu/drm/amd/pm/amdgpu_pm.c +0 -0
@@ -985,17 +932,14 @@ static ssize_t amdgpu_set_pp_features(struct

device *dev,

drivers/gpu/drm/amd/pm/amdgpu_pm.c static ssize_t amdgpu_set_pp_features(struct device *dev,

Quoted 5 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +0 -2
  		return ret;
  	}
 
-	if (adev->powerplay.pp_funcs->set_ppfeature_status) {
-		ret = amdgpu_dpm_set_ppfeature_status(adev,

featuremask);

drivers/gpu/drm/amd/pm/amdgpu_pm.c static ssize_t amdgpu_get_pp_features(struct

Quoted 18 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +5 -6
-		if (ret) {
-			pm_runtime_mark_last_busy(ddev->dev);
-			pm_runtime_put_autosuspend(ddev->dev);
-			return -EINVAL;
-		}
-	}
+	ret = amdgpu_dpm_set_ppfeature_status(adev, featuremask);
+
  	pm_runtime_mark_last_busy(ddev->dev);
  	pm_runtime_put_autosuspend(ddev->dev);
 
+	if (ret)
+		return -EINVAL;
+
  	return count;
  }
 
@@ -1019,9 +963,8 @@ static ssize_t amdgpu_get_pp_features(struct

device *dev,

drivers/gpu/drm/amd/pm/amdgpu_pm.c static ssize_t amdgpu_get_pp_dpm_clock(struct

Quoted 12 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +2 -3
  		return ret;
  	}
 
-	if (adev->powerplay.pp_funcs->get_ppfeature_status)
-		size = amdgpu_dpm_get_ppfeature_status(adev, buf);
-	else
+	size = amdgpu_dpm_get_ppfeature_status(adev, buf);
+	if (size <= 0)
  		size = sysfs_emit(buf, "\n");
 
  	pm_runtime_mark_last_busy(ddev->dev);
@@ -1080,9 +1023,8 @@ static ssize_t amdgpu_get_pp_dpm_clock(struct

device *dev,

drivers/gpu/drm/amd/pm/amdgpu_pm.c static ssize_t amdgpu_set_pp_dpm_clock(struct

Quoted 12 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +2 -3
  		return ret;
  	}
 
-	if (adev->powerplay.pp_funcs->print_clock_levels)
-		size = amdgpu_dpm_print_clock_levels(adev, type, buf);
-	else
+	size = amdgpu_dpm_print_clock_levels(adev, type, buf);
+	if (size <= 0)
  		size = sysfs_emit(buf, "\n");
 
  	pm_runtime_mark_last_busy(ddev->dev);
@@ -1151,10 +1093,7 @@ static ssize_t amdgpu_set_pp_dpm_clock(struct

device *dev,

drivers/gpu/drm/amd/pm/amdgpu_pm.c static ssize_t amdgpu_get_pp_sclk_od(struct

Quoted 12 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +1 -4
  		return ret;
  	}
 
-	if (adev->powerplay.pp_funcs->force_clock_level)
-		ret = amdgpu_dpm_force_clock_level(adev, type, mask);
-	else
-		ret = 0;
+	ret = amdgpu_dpm_force_clock_level(adev, type, mask);
 
  	pm_runtime_mark_last_busy(ddev->dev);
  	pm_runtime_put_autosuspend(ddev->dev);
@@ -1305,10 +1244,7 @@ static ssize_t amdgpu_get_pp_sclk_od(struct

device *dev,

drivers/gpu/drm/amd/pm/amdgpu_pm.c static ssize_t amdgpu_set_pp_sclk_od(struct

Quoted 12 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +1 -4
  		return ret;
  	}
 
-	if (is_support_sw_smu(adev))
-		value = 0;
-	else if (adev->powerplay.pp_funcs->get_sclk_od)
-		value = amdgpu_dpm_get_sclk_od(adev);
+	value = amdgpu_dpm_get_sclk_od(adev);
 
  	pm_runtime_mark_last_busy(ddev->dev);
  	pm_runtime_put_autosuspend(ddev->dev);
@@ -1342,19 +1278,7 @@ static ssize_t amdgpu_set_pp_sclk_od(struct

device *dev,

drivers/gpu/drm/amd/pm/amdgpu_pm.c static ssize_t amdgpu_set_pp_sclk_od(struct device *dev,

Quoted 11 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +0 -8
  		return ret;
  	}
 
-	if (is_support_sw_smu(adev)) {
-		value = 0;
-	} else {
-		if (adev->powerplay.pp_funcs->set_sclk_od)
-			amdgpu_dpm_set_sclk_od(adev, (uint32_t)value);
-
-		if (adev->powerplay.pp_funcs->dispatch_tasks) {
-			amdgpu_dpm_dispatch_task(adev,

AMD_PP_TASK_READJUST_POWER_STATE, NULL);

drivers/gpu/drm/amd/pm/amdgpu_pm.c static ssize_t amdgpu_get_pp_mclk_od(struct

Quoted 11 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +1 -5
-		} else {
-			adev->pm.dpm.current_ps = adev-
 pm.dpm.boot_ps;
-			amdgpu_pm_compute_clocks(adev);
-		}
-	}
+	amdgpu_dpm_set_sclk_od(adev, (uint32_t)value);
 
  	pm_runtime_mark_last_busy(ddev->dev);
  	pm_runtime_put_autosuspend(ddev->dev);
drivers/gpu/drm/amd/pm/amdgpu_pm.c +0 -0
@@ -1382,10 +1306,7 @@ static ssize_t amdgpu_get_pp_mclk_od(struct

device *dev,

drivers/gpu/drm/amd/pm/amdgpu_pm.c static ssize_t amdgpu_set_pp_mclk_od(struct

Quoted 12 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +1 -4
  		return ret;
  	}
 
-	if (is_support_sw_smu(adev))
-		value = 0;
-	else if (adev->powerplay.pp_funcs->get_mclk_od)
-		value = amdgpu_dpm_get_mclk_od(adev);
+	value = amdgpu_dpm_get_mclk_od(adev);
 
  	pm_runtime_mark_last_busy(ddev->dev);
  	pm_runtime_put_autosuspend(ddev->dev);
@@ -1419,19 +1340,7 @@ static ssize_t amdgpu_set_pp_mclk_od(struct

device *dev,

drivers/gpu/drm/amd/pm/amdgpu_pm.c static ssize_t amdgpu_set_pp_mclk_od(struct device *dev,

Quoted 11 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +0 -8
  		return ret;
  	}
 
-	if (is_support_sw_smu(adev)) {
-		value = 0;
-	} else {
-		if (adev->powerplay.pp_funcs->set_mclk_od)
-			amdgpu_dpm_set_mclk_od(adev, (uint32_t)value);
-
-		if (adev->powerplay.pp_funcs->dispatch_tasks) {
-			amdgpu_dpm_dispatch_task(adev,

AMD_PP_TASK_READJUST_POWER_STATE, NULL);

drivers/gpu/drm/amd/pm/amdgpu_pm.c static ssize_t

Quoted 11 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +1 -5
-		} else {
-			adev->pm.dpm.current_ps = adev-
 pm.dpm.boot_ps;
-			amdgpu_pm_compute_clocks(adev);
-		}
-	}
+	amdgpu_dpm_set_mclk_od(adev, (uint32_t)value);
 
  	pm_runtime_mark_last_busy(ddev->dev);
  	pm_runtime_put_autosuspend(ddev->dev);
drivers/gpu/drm/amd/pm/amdgpu_pm.c +0 -0
@@ -1479,9 +1388,8 @@ static ssize_t

amdgpu_get_pp_power_profile_mode(struct device *dev,

drivers/gpu/drm/amd/pm/amdgpu_pm.c static ssize_t

Quoted 12 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +2 -3
  		return ret;
  	}
 
-	if (adev->powerplay.pp_funcs->get_power_profile_mode)
-		size = amdgpu_dpm_get_power_profile_mode(adev, buf);
-	else
+	size = amdgpu_dpm_get_power_profile_mode(adev, buf);
+	if (size <= 0)
  		size = sysfs_emit(buf, "\n");
 
  	pm_runtime_mark_last_busy(ddev->dev);
@@ -1545,8 +1453,7 @@ static ssize_t

amdgpu_set_pp_power_profile_mode(struct device *dev,

drivers/gpu/drm/amd/pm/amdgpu_pm.c static ssize_t amdgpu_set_pp_power_profile_mode(struct device *dev,

Quoted 5 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +0 -2
  		return ret;
  	}
 
-	if (adev->powerplay.pp_funcs->set_power_profile_mode)
-		ret = amdgpu_dpm_set_power_profile_mode(adev,

parameter, parameter_size);

drivers/gpu/drm/amd/pm/amdgpu_pm.c static ssize_t · line 1456

Quoted 1 line
drivers/gpu/drm/amd/pm/amdgpu_pm.c +1 -0
+	ret = amdgpu_dpm_set_power_profile_mode(adev, parameter,

parameter_size);

drivers/gpu/drm/amd/pm/amdgpu_pm.c static ssize_t amdgpu_get_gpu_metrics(struct

Quoted 4 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +0 -0
  	pm_runtime_mark_last_busy(ddev->dev);
  	pm_runtime_put_autosuspend(ddev->dev);
@@ -1812,9 +1719,7 @@ static ssize_t amdgpu_get_gpu_metrics(struct

device *dev,

drivers/gpu/drm/amd/pm/amdgpu_pm.c static int default_attr_update(struct

Quoted 11 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +1 -3
  		return ret;
  	}
 
-	if (adev->powerplay.pp_funcs->get_gpu_metrics)
-		size = amdgpu_dpm_get_gpu_metrics(adev, &gpu_metrics);
-
+	size = amdgpu_dpm_get_gpu_metrics(adev, &gpu_metrics);
  	if (size <= 0)
  		goto out;
 
@@ -2053,7 +1958,6 @@ static int default_attr_update(struct

amdgpu_device *adev, struct amdgpu_device_

drivers/gpu/drm/amd/pm/amdgpu_pm.c static int default_attr_update(struct

Quoted 8 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +0 -1
  {
  	struct device_attribute *dev_attr = &attr->dev_attr;
  	const char *attr_name = dev_attr->attr.name;
-	struct pp_hwmgr *hwmgr = adev->powerplay.pp_handle;
  	enum amd_asic_type asic_type = adev->asic_type;
 
  	if (!(attr->flags & mask)) {
@@ -2076,9 +1980,7 @@ static int default_attr_update(struct

amdgpu_device *adev, struct amdgpu_device_

drivers/gpu/drm/amd/pm/amdgpu_pm.c static int default_attr_update(struct amdgpu_device *adev, struct amdgpu_device_

Quoted 4 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +0 -1
  			*states = ATTR_STATE_UNSUPPORTED;
  	} else if (DEVICE_ATTR_IS(pp_od_clk_voltage)) {
  		*states = ATTR_STATE_UNSUPPORTED;
-		if ((is_support_sw_smu(adev) && adev->smu.od_enabled)
||
> -		    (is_support_sw_smu(adev) && adev->smu.is_apu) ||

drivers/gpu/drm/amd/pm/amdgpu_pm.c static int default_attr_update(struct

Quoted 7 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +1 -1
-			(!is_support_sw_smu(adev) && hwmgr-
 od_enabled))
+		if (amdgpu_dpm_is_overdrive_supported(adev))
  			*states = ATTR_STATE_SUPPORTED;
  	} else if (DEVICE_ATTR_IS(mem_busy_percent)) {
  		if (adev->flags & AMD_IS_APU || asic_type == CHIP_VEGA10)
@@ -2105,8 +2007,7 @@ static int default_attr_update(struct

amdgpu_device *adev, struct amdgpu_device_

drivers/gpu/drm/amd/pm/amdgpu_pm.c static int default_attr_update(struct · line 2007

Quoted 1 line
drivers/gpu/drm/amd/pm/amdgpu_pm.c +0 -0
  		if (!(asic_type == CHIP_VANGOGH || asic_type ==

CHIP_SIENNA_CICHLID))

drivers/gpu/drm/amd/pm/amdgpu_pm.c static int default_attr_update(struct amdgpu_device *adev, struct amdgpu_device_

Quoted 3 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +0 -1
  			*states = ATTR_STATE_UNSUPPORTED;
  	} else if (DEVICE_ATTR_IS(pp_power_profile_mode)) {
-		if (!adev->powerplay.pp_funcs->get_power_profile_mode
||
> -		    amdgpu_dpm_get_power_profile_mode(adev, NULL) == -

EOPNOTSUPP)

drivers/gpu/drm/amd/pm/amdgpu_pm.c static int default_attr_update(struct · line 2010

Quoted 1 line
drivers/gpu/drm/amd/pm/amdgpu_pm.c +1 -0
+		if (amdgpu_dpm_get_power_profile_mode(adev, NULL) ==

-EOPNOTSUPP)

drivers/gpu/drm/amd/pm/amdgpu_pm.c static ssize_t

Quoted 4 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +0 -0
  			*states = ATTR_STATE_UNSUPPORTED;
  	}
 
@@ -2389,17 +2290,14 @@ static ssize_t

amdgpu_hwmon_get_pwm1_enable(struct device *dev,

drivers/gpu/drm/amd/pm/amdgpu_pm.c static ssize_t

Quoted 22 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +4 -7
  		return ret;
  	}
 
-	if (!adev->powerplay.pp_funcs->get_fan_control_mode) {
-		pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
-		pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
-		return -EINVAL;
-	}
-
-	pwm_mode = amdgpu_dpm_get_fan_control_mode(adev);
+	ret = amdgpu_dpm_get_fan_control_mode(adev, &pwm_mode);
 
  	pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
  	pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
 
+	if (ret)
+		return -EINVAL;
+
  	return sysfs_emit(buf, "%u\n", pwm_mode);
  }
 
@@ -2427,17 +2325,14 @@ static ssize_t

amdgpu_hwmon_set_pwm1_enable(struct device *dev,

drivers/gpu/drm/amd/pm/amdgpu_pm.c static ssize_t

Quoted 22 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +4 -7
  		return ret;
  	}
 
-	if (!adev->powerplay.pp_funcs->set_fan_control_mode) {
-		pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
-		pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
-		return -EINVAL;
-	}
-
-	amdgpu_dpm_set_fan_control_mode(adev, value);
+	ret = amdgpu_dpm_set_fan_control_mode(adev, value);
 
  	pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
  	pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
 
+	if (ret)
+		return -EINVAL;
+
  	return count;
  }
 
@@ -2469,32 +2364,29 @@ static ssize_t

amdgpu_hwmon_set_pwm1(struct device *dev,

Quoted 10 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +4 -0
  	if (adev->in_suspend && !adev->in_runpm)
  		return -EPERM;
 
+	err = kstrtou32(buf, 10, &value);
+	if (err)
+		return err;
+
  	err = pm_runtime_get_sync(adev_to_drm(adev)->dev);
  	if (err < 0) {
  		pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);

drivers/gpu/drm/amd/pm/amdgpu_pm.c static ssize_t amdgpu_hwmon_set_pwm1(struct device *dev,

Quoted 10 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +4 -1
  		return err;
  	}
 
-	pwm_mode = amdgpu_dpm_get_fan_control_mode(adev);
+	err = amdgpu_dpm_get_fan_control_mode(adev, &pwm_mode);
+	if (err)
+		goto out;
+
  	if (pwm_mode != AMD_FAN_CTRL_MANUAL) {
  		pr_info("manual fan speed control should be enabled

first\n");

drivers/gpu/drm/amd/pm/amdgpu_pm.c static ssize_t

Quoted 25 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +4 -14
-		pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
-		pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
-		return -EINVAL;
+		err = -EINVAL;
+		goto out;
  	}
 
-	err = kstrtou32(buf, 10, &value);
-	if (err) {
-		pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
-		pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
-		return err;
-	}
-
-	if (adev->powerplay.pp_funcs->set_fan_speed_pwm)
-		err = amdgpu_dpm_set_fan_speed_pwm(adev, value);
-	else
-		err = -EINVAL;
+	err = amdgpu_dpm_set_fan_speed_pwm(adev, value);
 
+out:
  	pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
  	pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
 
@@ -2523,10 +2415,7 @@ static ssize_t

amdgpu_hwmon_get_pwm1(struct device *dev,

drivers/gpu/drm/amd/pm/amdgpu_pm.c static ssize_t

Quoted 12 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +1 -4
  		return err;
  	}
 
-	if (adev->powerplay.pp_funcs->get_fan_speed_pwm)
-		err = amdgpu_dpm_get_fan_speed_pwm(adev, &speed);
-	else
-		err = -EINVAL;
+	err = amdgpu_dpm_get_fan_speed_pwm(adev, &speed);
 
  	pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
  	pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
@@ -2556,10 +2445,7 @@ static ssize_t

amdgpu_hwmon_get_fan1_input(struct device *dev,

drivers/gpu/drm/amd/pm/amdgpu_pm.c static ssize_t

Quoted 12 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +1 -4
  		return err;
  	}
 
-	if (adev->powerplay.pp_funcs->get_fan_speed_rpm)
-		err = amdgpu_dpm_get_fan_speed_rpm(adev, &speed);
-	else
-		err = -EINVAL;
+	err = amdgpu_dpm_get_fan_speed_rpm(adev, &speed);
 
  	pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
  	pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
@@ -2653,10 +2539,7 @@ static ssize_t

amdgpu_hwmon_get_fan1_target(struct device *dev,

drivers/gpu/drm/amd/pm/amdgpu_pm.c static ssize_t

Quoted 12 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +1 -4
@@ -2681,32 +2564,28 @@ static ssize_t

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

amdgpu_hwmon_set_fan1_target(struct device *dev,

drivers/gpu/drm/amd/pm/amdgpu_pm.c static ssize_t

Quoted 44 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +11 -15
@@ -2735,17 +2614,14 @@ static ssize_t

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

amdgpu_hwmon_get_fan1_enable(struct device *dev,

drivers/gpu/drm/amd/pm/amdgpu_pm.c

Quoted 19 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +4 -7

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

AMD_FAN_CTRL_AUTO ? 0 : 1);

drivers/gpu/drm/amd/pm/amdgpu_pm.c static ssize_t

Quoted 3 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +0 -0
@@ -2781,16 +2657,14 @@ static ssize_t

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

amdgpu_hwmon_set_fan1_enable(struct device *dev,

drivers/gpu/drm/amd/pm/amdgpu_pm.c static ssize_t

Quoted 21 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +4 -6
@@ -2926,7 +2800,6 @@ static ssize_t

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

amdgpu_hwmon_show_power_cap_generic(struct device *dev,

drivers/gpu/drm/amd/pm/amdgpu_pm.c

Quoted 1 line
drivers/gpu/drm/amd/pm/amdgpu_pm.c +0 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

pp_limit_level)

drivers/gpu/drm/amd/pm/amdgpu_pm.c static ssize_t

Quoted 8 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +0 -1

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

ssize_t size;

drivers/gpu/drm/amd/pm/amdgpu_pm.c +0 -0
@@ -2937,16 +2810,13 @@ static ssize_t

amdgpu_hwmon_show_power_cap_generic(struct device *dev,

drivers/gpu/drm/amd/pm/amdgpu_pm.c static ssize_t

Quoted 18 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +1 -4
@@ -3001,7 +2871,6 @@ static ssize_t

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

amdgpu_hwmon_set_power_cap(struct device *dev,

drivers/gpu/drm/amd/pm/amdgpu_pm.c static ssize_t

Quoted 8 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +0 -1
@@ -3027,10 +2896,7 @@ static ssize_t

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

amdgpu_hwmon_set_power_cap(struct device *dev,

drivers/gpu/drm/amd/pm/amdgpu_pm.c static umode_t hwmon_attributes_visible(struct

Quoted 13 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +1 -4

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

  	pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
drivers/gpu/drm/amd/pm/amdgpu_pm.c +0 -0
@@ -3303,6 +3169,7 @@ static umode_t hwmon_attributes_visible(struct

kobject *kobj,

drivers/gpu/drm/amd/pm/amdgpu_pm.c

Quoted 6 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +1 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

*/

drivers/gpu/drm/amd/pm/amdgpu_pm.c static umode_t

Quoted 2 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +0 -0
@@ -3367,20 +3234,18 @@ static umode_t

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

hwmon_attributes_visible(struct kobject *kobj,

drivers/gpu/drm/amd/pm/amdgpu_pm.c

Quoted 5 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +0 -2

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

expose */

drivers/gpu/drm/amd/pm/amdgpu_pm.c

Quoted 2 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +0 -2

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

query fan */

drivers/gpu/drm/amd/pm/amdgpu_pm.c

Quoted 2 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +0 -2

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

/* can't query state */

drivers/gpu/drm/amd/pm/amdgpu_pm.c

Quoted 2 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +1 -1

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

*/

drivers/gpu/drm/amd/pm/amdgpu_pm.c

Quoted 1 line
drivers/gpu/drm/amd/pm/amdgpu_pm.c +1 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

&&

drivers/gpu/drm/amd/pm/amdgpu_pm.c

Quoted 1 line
drivers/gpu/drm/amd/pm/amdgpu_pm.c +1 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

fan */

drivers/gpu/drm/amd/pm/amdgpu_pm.c

Quoted 1 line
drivers/gpu/drm/amd/pm/amdgpu_pm.c +1 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

EOPNOTSUPP) &&

drivers/gpu/drm/amd/pm/amdgpu_pm.c

Quoted 1 line
drivers/gpu/drm/amd/pm/amdgpu_pm.c +1 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

query state */

drivers/gpu/drm/amd/pm/amdgpu_pm.c

Quoted 4 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +1 -2

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

manage fan */

drivers/gpu/drm/amd/pm/amdgpu_pm.c

Quoted 2 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +0 -2

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

/* can't manage state */

drivers/gpu/drm/amd/pm/amdgpu_pm.c

Quoted 3 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +1 -2

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

&&

411 lines not shown · raw message

Parts of this message are not shown here. View the raw message.

#4 lore raw

Re: [PATCH V4 02/17] drm/amd/pm: do not expose power implementation details to amdgpu_pm.c

Quoted 194 lines · Evan

[AMD Official Use Only]

Quoted 126 lines

-----Original Message-----
From: Lazar, Lijo <[email protected]>
Sent: Thursday, December 9, 2021 7:58 PM
To: Quan, Evan <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>; Feng, Kenneth <[email protected]>
Subject: Re: [PATCH V4 02/17] drm/amd/pm: do not expose power implementation details to amdgpu_pm.c

Quoted 9 lines · Evan Quan

amdgpu_pm.c holds all the user sysfs/hwmon interfaces. It's another client of our power APIs. It's not proper to spike into power implementation details there.

Change-Id I397853ddb13eacfce841366de2a623535422df9a

--
v1->v2:
- drop unneeded "return;" in

amdgpu_dpm_get_current_power_state(Guchun)

Quoted 2 lines
---
   drivers/gpu/drm/amd/pm/amdgpu_dpm.c       | 456

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

Review

Quoted 6 lines
   drivers/gpu/drm/amd/pm/amdgpu_pm.c        | 519 ++++++++--------------
   drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h   | 160 +++----
   drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c |   3 -
   4 files changed, 707 insertions(+), 431 deletions(-)
(quoted diff) +0 -0

b/drivers/gpu/drm/amd/pm/amdgpu_dpm.c

drivers/gpu/drm/amd/pm/amdgpu_dpm.c static void

Quoted 4 lines

index 54abdf7080de..2c789eb5d066 100644

drivers/gpu/drm/amd/pm/amdgpu_dpm.c +0 -0
@@ -1453,7 +1453,9 @@ static void

amdgpu_dpm_change_power_state_locked(struct amdgpu_device *adev)

drivers/gpu/drm/amd/pm/amdgpu_dpm.c int amdgpu_dpm_get_ecc_info(struct

Quoted 13 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +3 -1
   	if (equal)
   		return;
 
-	amdgpu_dpm_set_power_state(adev);
+	if (adev->powerplay.pp_funcs->set_power_state)
+		adev->powerplay.pp_funcs->set_power_state(adev-
 powerplay.pp_handle);
+
   	amdgpu_dpm_post_set_power_state(adev);
 
   	adev->pm.dpm.current_active_crtcs = adev-

pm.dpm.new_active_crtcs;

drivers/gpu/drm/amd/pm/amdgpu_dpm.c +0 -0
@@ -1704,3 +1706,455 @@ int amdgpu_dpm_get_ecc_info(struct

amdgpu_device *adev,

drivers/gpu/drm/amd/pm/amdgpu_dpm.c int amdgpu_dpm_get_ecc_info(struct amdgpu_device *adev,

Quoted 5 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +2 -0
   	return smu_get_ecc_info(&adev->smu, umc_ecc);
   }
+
+struct amd_vce_state *amdgpu_dpm_get_vce_clock_state(struct

amdgpu_device *adev,

drivers/gpu/drm/amd/pm/amdgpu_dpm.c int amdgpu_dpm_get_ecc_info(struct amdgpu_device *adev,

Quoted 12 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +12 -0
+						     uint32_t idx)
+{
+	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+
+	if (!pp_funcs->get_vce_clock_state)
+		return NULL;
+
+	return pp_funcs->get_vce_clock_state(adev->powerplay.pp_handle,
+					     idx);
+}
+
+void amdgpu_dpm_get_current_power_state(struct amdgpu_device

*adev,

Quoted 13 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +12 -0
+					enum amd_pm_state_type *state)
+{
+	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+
+	if (!pp_funcs->get_current_power_state) {
+		*state = adev->pm.dpm.user_state;
+		return;
+	}
+
+	*state = pp_funcs->get_current_power_state(adev-
 powerplay.pp_handle);
+	if (*state < POWER_STATE_TYPE_DEFAULT ||
+	    *state > POWER_STATE_TYPE_INTERNAL_3DPERF)

drivers/gpu/drm/amd/pm/amdgpu_dpm.c int amdgpu_dpm_get_ecc_info(struct amdgpu_device *adev,

Quoted 10 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +10 -0
+		*state = adev->pm.dpm.user_state;
+}
+
+void amdgpu_dpm_set_power_state(struct amdgpu_device *adev,
+				enum amd_pm_state_type state)
+{
+	adev->pm.dpm.user_state = state;
+
+	if (adev->powerplay.pp_funcs->dispatch_tasks)
+		amdgpu_dpm_dispatch_task(adev,

AMD_PP_TASK_ENABLE_USER_STATE, &state);

drivers/gpu/drm/amd/pm/amdgpu_dpm.c int amdgpu_dpm_get_ecc_info(struct amdgpu_device *adev,

Quoted 5 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +5 -0
+	else
+		amdgpu_pm_compute_clocks(adev);
+}
+
+enum amd_dpm_forced_level

amdgpu_dpm_get_performance_level(struct amdgpu_device *adev)

Quoted 7 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +6 -0
+{
+	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+	enum amd_dpm_forced_level level;
+
+	if (pp_funcs->get_performance_level)
+		level = pp_funcs->get_performance_level(adev-

powerplay.pp_handle);

drivers/gpu/drm/amd/pm/amdgpu_dpm.c int amdgpu_dpm_get_ecc_info(struct amdgpu_device *adev,

Quoted 7 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +7 -0
+	else
+		level = adev->pm.dpm.forced_level;
+
+	return level;
+}
+
+int amdgpu_dpm_force_performance_level(struct amdgpu_device

*adev,

Quoted 11 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +9 -0
+				       enum amd_dpm_forced_level level)
+{
+	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+
+	if (pp_funcs->force_performance_level) {
+		if (adev->pm.dpm.thermal_active)
+			return -EINVAL;
+
+		if (pp_funcs->force_performance_level(adev-

powerplay.pp_handle,

drivers/gpu/drm/amd/pm/amdgpu_dpm.c +1 -0
+						      level))
Quoted 8 lines

drivers/gpu/drm/amd/pm/amdgpu_dpm.c int amdgpu_dpm_get_ecc_info(struct amdgpu_device *adev, · line 1777

Quoted 5 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +5 -0
+			return -EINVAL;
+	}
+
+	adev->pm.dpm.forced_level = level;
+

If the function is not implemented, why change the force level and return success?

[Quan, Evan] Thanks! Will update that.

Quoted 47 lines

drivers/gpu/drm/amd/pm/amdgpu_dpm.c int amdgpu_dpm_get_ecc_info(struct amdgpu_device *adev,

Quoted 13 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +12 -0
+	return 0;
+}
+
+int amdgpu_dpm_get_pp_num_states(struct amdgpu_device *adev,
+				 struct pp_states_info *states)
+{
+	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+
+	if (!pp_funcs->get_pp_num_states)
+		return -EOPNOTSUPP;
+
+	return pp_funcs->get_pp_num_states(adev->powerplay.pp_handle,

states);

drivers/gpu/drm/amd/pm/amdgpu_dpm.c int amdgpu_dpm_get_ecc_info(struct amdgpu_device *adev,

Quoted 12 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +12 -0
+}
+
+int amdgpu_dpm_dispatch_task(struct amdgpu_device *adev,
+			      enum amd_pp_task task_id,
+			      enum amd_pm_state_type *user_state)
+{
+	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+
+	if (!pp_funcs->dispatch_tasks)
+		return -EOPNOTSUPP;
+
+	return pp_funcs->dispatch_tasks(adev->powerplay.pp_handle,

task_id, user_state);

drivers/gpu/drm/amd/pm/amdgpu_dpm.c int amdgpu_dpm_get_ecc_info(struct amdgpu_device *adev,

Quoted 3 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +3 -0
+}
+
+int amdgpu_dpm_get_pp_table(struct amdgpu_device *adev, char

**table)

Quoted 16 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +16 -0
+{
+	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+
+	if (!pp_funcs->get_pp_table)
+		return 0;
+
+	return pp_funcs->get_pp_table(adev->powerplay.pp_handle, table);
+}
+
+int amdgpu_dpm_set_fine_grain_clk_vol(struct amdgpu_device *adev,
+				      uint32_t type,
+				      long *input,
+				      uint32_t size)
+{
+	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+
Quoted 8 lines

drivers/gpu/drm/amd/pm/amdgpu_dpm.c int amdgpu_dpm_get_ecc_info(struct amdgpu_device *adev, · line 1823

Quoted 3 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +3 -0
+	if (!pp_funcs->set_fine_grain_clk_vol)
+		return 0;
+

Better for this also to return -EOPNOTSUPP. There are a few other funcs below also which returns 0, instead they should return EOPNOTSUPP. Let the caller decide what to do when not supported instead of returning 'fake success'.

Quoted 2 lines

[Quan, Evan] Yeah, I know some(this and others mentioned below) of them seem with different/weird error return code. But unfortunately, that's how the original logic. We need to fix them in future. But for this patch series, it is not intended to bring any real logic change.

What I meant is let the API implementation be standalone. Let it return EOPNOTSUPP and f that is the error code, caller retains the existing logic.

Ex:

	if (!pp_funcs->set_fine_grain_clk_vol) logic in caller is replaced by
	if (amdgpu_dpm_set_fine_grain_clk_vol() == -EOPNOTSUPP)

and then it retains the existing logic for that error code.

Thanks,
Lijo

Quoted 1,739 lines
Quoted 414 lines
Quoted 49 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +1 -0
+	return pp_funcs->set_fine_grain_clk_vol(adev-

powerplay.pp_handle,

drivers/gpu/drm/amd/pm/amdgpu_dpm.c +16 -0
+						type,
+						input,
+						size);
+}
+
+int amdgpu_dpm_odn_edit_dpm_table(struct amdgpu_device *adev,
+				  uint32_t type,
+				  long *input,
+				  uint32_t size)
+{
+	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+
+	if (!pp_funcs->odn_edit_dpm_table)
+		return 0;
+
+	return pp_funcs->odn_edit_dpm_table(adev-

powerplay.pp_handle,

drivers/gpu/drm/amd/pm/amdgpu_dpm.c +28 -0
+					    type,
+					    input,
+					    size);
+}
+
+int amdgpu_dpm_print_clock_levels(struct amdgpu_device *adev,
+				  enum pp_clock_type type,
+				  char *buf)
+{
+	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+
+	if (!pp_funcs->print_clock_levels)
+		return 0;
+
+	return pp_funcs->print_clock_levels(adev->powerplay.pp_handle,
+					    type,
+					    buf);
+}
+
+int amdgpu_dpm_set_ppfeature_status(struct amdgpu_device *adev,
+				    uint64_t ppfeature_masks)
+{
+	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+
+	if (!pp_funcs->set_ppfeature_status)
+		return 0;
+
+	return pp_funcs->set_ppfeature_status(adev-

powerplay.pp_handle,

drivers/gpu/drm/amd/pm/amdgpu_dpm.c int amdgpu_dpm_get_ecc_info(struct amdgpu_device *adev,

Quoted 4 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +4 -0
+					      ppfeature_masks);
+}
+
+int amdgpu_dpm_get_ppfeature_status(struct amdgpu_device *adev,

char *buf)

Quoted 26 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +7 -0
+{
+	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+
+	if (!pp_funcs->get_ppfeature_status)
+		return 0;
+
+	return pp_funcs->get_ppfeature_status(adev-

powerplay.pp_handle,

drivers/gpu/drm/amd/pm/amdgpu_dpm.c +18 -0
+					      buf);
+}
+
+int amdgpu_dpm_force_clock_level(struct amdgpu_device *adev,
+				 enum pp_clock_type type,
+				 uint32_t mask)
+{
+	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+
+	if (!pp_funcs->force_clock_level)
+		return 0;
+
+	return pp_funcs->force_clock_level(adev->powerplay.pp_handle,
+					   type,
+					   mask);
+}
+
+int amdgpu_dpm_get_sclk_od(struct amdgpu_device *adev)

drivers/gpu/drm/amd/pm/amdgpu_dpm.c int amdgpu_dpm_get_ecc_info(struct amdgpu_device *adev,

Quoted 10 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +10 -0
+{
+	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+
+	if (!pp_funcs->get_sclk_od)
+		return 0;
+
+	return pp_funcs->get_sclk_od(adev->powerplay.pp_handle);
+}
+
+int amdgpu_dpm_set_sclk_od(struct amdgpu_device *adev, uint32_t

value)

Quoted 19 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +19 -0
+{
+	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+
+	if (!pp_funcs->set_sclk_od)
+		return -EOPNOTSUPP;
+
+	pp_funcs->set_sclk_od(adev->powerplay.pp_handle, value);
+
+	if (amdgpu_dpm_dispatch_task(adev,
+				     AMD_PP_TASK_READJUST_POWER_STATE,
+				     NULL) == -EOPNOTSUPP) {
+		adev->pm.dpm.current_ps = adev->pm.dpm.boot_ps;
+		amdgpu_pm_compute_clocks(adev);
+	}
+
+	return 0;
+}
+
+int amdgpu_dpm_get_mclk_od(struct amdgpu_device *adev)

drivers/gpu/drm/amd/pm/amdgpu_dpm.c int amdgpu_dpm_get_ecc_info(struct amdgpu_device *adev,

Quoted 10 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +10 -0
+{
+	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+
+	if (!pp_funcs->get_mclk_od)
+		return 0;
+
+	return pp_funcs->get_mclk_od(adev->powerplay.pp_handle);
+}
+
+int amdgpu_dpm_set_mclk_od(struct amdgpu_device *adev, uint32_t

value)

Quoted 9 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +9 -0
+{
+	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+
+	if (!pp_funcs->set_mclk_od)
+		return -EOPNOTSUPP;
+
+	pp_funcs->set_mclk_od(adev->powerplay.pp_handle, value);
+
+	if (amdgpu_dpm_dispatch_task(adev,

drivers/gpu/drm/amd/pm/amdgpu_dpm.c int amdgpu_dpm_get_ecc_info(struct amdgpu_device *adev,

Quoted 10 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +10 -0
+				     AMD_PP_TASK_READJUST_POWER_STATE,
+				     NULL) == -EOPNOTSUPP) {
+		adev->pm.dpm.current_ps = adev->pm.dpm.boot_ps;
+		amdgpu_pm_compute_clocks(adev);
+	}
+
+	return 0;
+}
+
+int amdgpu_dpm_get_power_profile_mode(struct amdgpu_device

*adev,

drivers/gpu/drm/amd/pm/amdgpu_dpm.c int amdgpu_dpm_get_ecc_info(struct amdgpu_device *adev,

Quoted 13 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +8 -0
+				      char *buf)
+{
+	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+
+	if (!pp_funcs->get_power_profile_mode)
+		return -EOPNOTSUPP;
+
+	return pp_funcs->get_power_profile_mode(adev-

powerplay.pp_handle,

drivers/gpu/drm/amd/pm/amdgpu_dpm.c +4 -0
+						buf);
+}
+
+int amdgpu_dpm_set_power_profile_mode(struct amdgpu_device

*adev,

Quoted 9 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +8 -0
+				      long *input, uint32_t size)
+{
+	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+
+	if (!pp_funcs->set_power_profile_mode)
+		return 0;
+
+	return pp_funcs->set_power_profile_mode(adev-

powerplay.pp_handle,

drivers/gpu/drm/amd/pm/amdgpu_dpm.c int amdgpu_dpm_get_ecc_info(struct amdgpu_device *adev,

Quoted 5 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +5 -0
+						input,
+						size);
+}
+
+int amdgpu_dpm_get_gpu_metrics(struct amdgpu_device *adev, void

**table)

drivers/gpu/drm/amd/pm/amdgpu_dpm.c int amdgpu_dpm_get_ecc_info(struct amdgpu_device *adev,

Quoted 7 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +7 -0
+{
+	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+
+	if (!pp_funcs->get_gpu_metrics)
+		return 0;
+
+	return pp_funcs->get_gpu_metrics(adev->powerplay.pp_handle,

table);

Quoted 13 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +11 -0
+}
+
+int amdgpu_dpm_get_fan_control_mode(struct amdgpu_device *adev,
+				    uint32_t *fan_mode)
+{
+	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+
+	if (!pp_funcs->get_fan_control_mode)
+		return -EOPNOTSUPP;
+
+	*fan_mode = pp_funcs->get_fan_control_mode(adev-

powerplay.pp_handle);

drivers/gpu/drm/amd/pm/amdgpu_dpm.c +1 -0
+

drivers/gpu/drm/amd/pm/amdgpu_dpm.c int amdgpu_dpm_get_ecc_info(struct amdgpu_device *adev, · line 2009

Quoted 10 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +10 -0
+	return 0;
+}
+
+int amdgpu_dpm_set_fan_speed_pwm(struct amdgpu_device *adev,
+				 uint32_t speed)
+{
+	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+
+	if (!pp_funcs->set_fan_speed_pwm)
+		return -EINVAL;

To be consistent, use EOPNOTSUPP when the function is not implemented. The return of EINVAL from actual function call shouldn't be mixed with this.

Quoted 16 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +2 -0
+
+	return pp_funcs->set_fan_speed_pwm(adev-

powerplay.pp_handle, speed);

drivers/gpu/drm/amd/pm/amdgpu_dpm.c +11 -0
+}
+
+int amdgpu_dpm_get_fan_speed_pwm(struct amdgpu_device *adev,
+				 uint32_t *speed)
+{
+	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+
+	if (!pp_funcs->get_fan_speed_pwm)
+		return -EINVAL;
+
+	return pp_funcs->get_fan_speed_pwm(adev-

powerplay.pp_handle, speed);

drivers/gpu/drm/amd/pm/amdgpu_dpm.c +1 -0
+}

drivers/gpu/drm/amd/pm/amdgpu_dpm.c int amdgpu_dpm_get_ecc_info(struct amdgpu_device *adev,

Quoted 10 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +10 -0
+
+int amdgpu_dpm_get_fan_speed_rpm(struct amdgpu_device *adev,
+				 uint32_t *speed)
+{
+	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+
+	if (!pp_funcs->get_fan_speed_rpm)
+		return -EINVAL;
+
+	return pp_funcs->get_fan_speed_rpm(adev->powerplay.pp_handle,

speed);

drivers/gpu/drm/amd/pm/amdgpu_dpm.c int amdgpu_dpm_get_ecc_info(struct amdgpu_device *adev,

Quoted 11 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +11 -0
+}
+
+int amdgpu_dpm_set_fan_speed_rpm(struct amdgpu_device *adev,
+				 uint32_t speed)
+{
+	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+
+	if (!pp_funcs->set_fan_speed_rpm)
+		return -EINVAL;
+
+	return pp_funcs->set_fan_speed_rpm(adev->powerplay.pp_handle,

speed);

drivers/gpu/drm/amd/pm/amdgpu_dpm.c int amdgpu_dpm_get_ecc_info(struct amdgpu_device *adev,

Quoted 11 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +11 -0
+}
+
+int amdgpu_dpm_set_fan_control_mode(struct amdgpu_device *adev,
+				    uint32_t mode)
+{
+	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+
+	if (!pp_funcs->set_fan_control_mode)
+		return -EOPNOTSUPP;
+
+	pp_funcs->set_fan_control_mode(adev->powerplay.pp_handle,

mode);

Quoted 4 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +4 -0
+
+	return 0;
+}
+

drivers/gpu/drm/amd/pm/amdgpu_dpm.c int amdgpu_dpm_get_ecc_info(struct amdgpu_device *adev, · line 2069

Quoted 10 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +10 -0
+int amdgpu_dpm_get_power_limit(struct amdgpu_device *adev,
+			       uint32_t *limit,
+			       enum pp_power_limit_level pp_limit_level,
+			       enum pp_power_type power_type)
+{
+	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+
+	if (!pp_funcs->get_power_limit)
+		return -ENODATA;
+

Again, this is mixing API error code based on caller's usage. In standalone implementatoin, this should also just return EOPNOTSUPP. hwmon API implementation can decide what to return when there is no API support.

Quoted 5 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +5 -0
+	return pp_funcs->get_power_limit(adev->powerplay.pp_handle,
+					 limit,
+					 pp_limit_level,
+					 power_type);
+}

drivers/gpu/drm/amd/pm/amdgpu_dpm.c int amdgpu_dpm_get_ecc_info(struct amdgpu_device *adev,

Quoted 10 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +10 -0
+
+int amdgpu_dpm_set_power_limit(struct amdgpu_device *adev,
+			       uint32_t limit)
+{
+	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+
+	if (!pp_funcs->set_power_limit)
+		return -EINVAL;
+
+	return pp_funcs->set_power_limit(adev->powerplay.pp_handle,

limit);

drivers/gpu/drm/amd/pm/amdgpu_dpm.c int amdgpu_dpm_get_ecc_info(struct amdgpu_device *adev,

Quoted 11 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +11 -0
+}
+
+int amdgpu_dpm_is_cclk_dpm_supported(struct amdgpu_device *adev)
+{
+	if (!is_support_sw_smu(adev))
+		return false;
+
+	return is_support_cclk_dpm(adev);
+}
+
+int amdgpu_dpm_debugfs_print_current_performance_level(struct

amdgpu_device *adev,

Quoted 9 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +8 -0
+						       struct seq_file *m)
+{
+	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+
+	if (!pp_funcs->debugfs_print_current_performance_level)
+		return -EOPNOTSUPP;
+
+	pp_funcs->debugfs_print_current_performance_level(adev-

powerplay.pp_handle,

drivers/gpu/drm/amd/pm/amdgpu_dpm.c int amdgpu_dpm_get_ecc_info(struct amdgpu_device *adev,

Quoted 6 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +6 -0
+							  m);
+
+	return 0;
+}
+
+int amdgpu_dpm_get_smu_prv_buf_details(struct amdgpu_device

*adev,

Review

Quoted 53 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +9 -0
+				       void **addr,
+				       size_t *size)
+{
+	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+
+	if (!pp_funcs->get_smu_prv_buf_details)
+		return -ENOSYS;
+
+	return pp_funcs->get_smu_prv_buf_details(adev-

powerplay.pp_handle,

drivers/gpu/drm/amd/pm/amdgpu_dpm.c +42 -0
+						 addr,
+						 size);
+}
+
+int amdgpu_dpm_is_overdrive_supported(struct amdgpu_device *adev)
+{
+	struct pp_hwmgr *hwmgr = adev->powerplay.pp_handle;
+
+	if ((is_support_sw_smu(adev) && adev->smu.od_enabled) ||
+	    (is_support_sw_smu(adev) && adev->smu.is_apu) ||
+		(!is_support_sw_smu(adev) && hwmgr->od_enabled))
+		return true;
+
+	return false;
+}
+
+int amdgpu_dpm_set_pp_table(struct amdgpu_device *adev,
+			    const char *buf,
+			    size_t size)
+{
+	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+
+	if (!pp_funcs->set_pp_table)
+		return -EOPNOTSUPP;
+
+	return pp_funcs->set_pp_table(adev->powerplay.pp_handle,
+				      buf,
+				      size);
+}
+
+int amdgpu_dpm_get_num_cpu_cores(struct amdgpu_device *adev)
+{
+	return adev->smu.cpu_core_num;
+}
+
+void amdgpu_dpm_stb_debug_fs_init(struct amdgpu_device *adev)
+{
+	if (!is_support_sw_smu(adev))
+		return;
+
+	amdgpu_smu_stb_debug_fs_init(adev);
+}
(quoted diff) +0 -0

b/drivers/gpu/drm/amd/pm/amdgpu_pm.c

drivers/gpu/drm/amd/pm/amdgpu_pm.c line 39

Quoted 11 lines

index 082539c70fd4..3382d30b5d90 100644

drivers/gpu/drm/amd/pm/amdgpu_pm.c +0 -1
@@ -34,7 +34,6 @@
   #include <linux/nospec.h>
   #include <linux/pm_runtime.h>
   #include <asm/processor.h>
-#include "hwmgr.h"
 
   static const struct cg_flag_name clocks[] = {
   	{AMD_CG_SUPPORT_GFX_FGCG, "Graphics Fine Grain Clock

Gating"},

drivers/gpu/drm/amd/pm/amdgpu_pm.c static ssize_t

Quoted 1 line
drivers/gpu/drm/amd/pm/amdgpu_pm.c +0 -0
@@ -132,7 +131,6 @@ static ssize_t

amdgpu_get_power_dpm_state(struct device *dev,

drivers/gpu/drm/amd/pm/amdgpu_pm.c static ssize_t

Quoted 8 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +0 -1
   {
   	struct drm_device *ddev = dev_get_drvdata(dev);
   	struct amdgpu_device *adev = drm_to_adev(ddev);
-	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
   	enum amd_pm_state_type pm;
   	int ret;
 
@@ -147,11 +145,7 @@ static ssize_t

amdgpu_get_power_dpm_state(struct device *dev,

drivers/gpu/drm/amd/pm/amdgpu_pm.c static ssize_t

Quoted 13 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +1 -5
   		return ret;
   	}
 
-	if (pp_funcs->get_current_power_state) {
-		pm = amdgpu_dpm_get_current_power_state(adev);
-	} else {
-		pm = adev->pm.dpm.user_state;
-	}
+	amdgpu_dpm_get_current_power_state(adev, &pm);
 
   	pm_runtime_mark_last_busy(ddev->dev);
   	pm_runtime_put_autosuspend(ddev->dev);
@@ -191,19 +185,8 @@ static ssize_t

amdgpu_set_power_dpm_state(struct device *dev,

Quoted 3 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +0 -0
   		return ret;
   	}
 
Quoted 7 lines

drivers/gpu/drm/amd/pm/amdgpu_pm.c static ssize_t amdgpu_set_power_dpm_state(struct device *dev, · line 197

Quoted 4 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +0 -4
-	if (is_support_sw_smu(adev)) {
-		mutex_lock(&adev->pm.mutex);
-		adev->pm.dpm.user_state = state;
-		mutex_unlock(&adev->pm.mutex);

Here the code just sets the state and exits. However, when moved to refactored function, it is calling pm_compute_clocks.

[Quan, Evan] Thanks! Will fix this.

BR
Evan

Quoted 1,314 lines

drivers/gpu/drm/amd/pm/amdgpu_pm.c static ssize_t · line 199

Quoted 3 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +0 -2
-	} else if (adev->powerplay.pp_funcs->dispatch_tasks) {
-		amdgpu_dpm_dispatch_task(adev,

AMD_PP_TASK_ENABLE_USER_STATE, &state);

drivers/gpu/drm/amd/pm/amdgpu_pm.c static ssize_t

Quoted 12 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +1 -6
-	} else {
-		mutex_lock(&adev->pm.mutex);
-		adev->pm.dpm.user_state = state;
-		mutex_unlock(&adev->pm.mutex);
+	amdgpu_dpm_set_power_state(adev, state);
 
-		amdgpu_pm_compute_clocks(adev);
-	}
   	pm_runtime_mark_last_busy(ddev->dev);
   	pm_runtime_put_autosuspend(ddev->dev);
 
@@ -290,10 +273,7 @@ static ssize_t

amdgpu_get_power_dpm_force_performance_level(struct device *dev,

drivers/gpu/drm/amd/pm/amdgpu_pm.c static ssize_t

Quoted 12 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +1 -4
   		return ret;
   	}
 
-	if (adev->powerplay.pp_funcs->get_performance_level)
-		level = amdgpu_dpm_get_performance_level(adev);
-	else
-		level = adev->pm.dpm.forced_level;
+	level = amdgpu_dpm_get_performance_level(adev);
 
   	pm_runtime_mark_last_busy(ddev->dev);
   	pm_runtime_put_autosuspend(ddev->dev);
@@ -318,7 +298,6 @@ static ssize_t

amdgpu_set_power_dpm_force_performance_level(struct device *dev,

drivers/gpu/drm/amd/pm/amdgpu_pm.c static ssize_t

Quoted 8 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +0 -1
   {
   	struct drm_device *ddev = dev_get_drvdata(dev);
   	struct amdgpu_device *adev = drm_to_adev(ddev);
-	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
   	enum amd_dpm_forced_level level;
   	enum amd_dpm_forced_level current_level;
   	int ret = 0;
@@ -358,11 +337,7 @@ static ssize_t

amdgpu_set_power_dpm_force_performance_level(struct device *dev,

drivers/gpu/drm/amd/pm/amdgpu_pm.c static ssize_t amdgpu_set_power_dpm_force_performance_level(struct device *dev,

Quoted 5 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +0 -2
   		return ret;
   	}
 
-	if (pp_funcs->get_performance_level)
-		current_level =

amdgpu_dpm_get_performance_level(adev);

drivers/gpu/drm/amd/pm/amdgpu_pm.c static ssize_t

Quoted 8 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +1 -3
-	else
-		current_level = adev->pm.dpm.forced_level;
-
+	current_level = amdgpu_dpm_get_performance_level(adev);
   	if (current_level == level) {
   		pm_runtime_mark_last_busy(ddev->dev);
   		pm_runtime_put_autosuspend(ddev->dev);
@@ -390,25 +365,12 @@ static ssize_t

amdgpu_set_power_dpm_force_performance_level(struct device *dev,

drivers/gpu/drm/amd/pm/amdgpu_pm.c static ssize_t amdgpu_get_pp_num_states(struct

Quoted 31 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +5 -18
   		return -EINVAL;
   	}
 
-	if (pp_funcs->force_performance_level) {
-		mutex_lock(&adev->pm.mutex);
-		if (adev->pm.dpm.thermal_active) {
-			mutex_unlock(&adev->pm.mutex);
-			pm_runtime_mark_last_busy(ddev->dev);
-			pm_runtime_put_autosuspend(ddev->dev);
-			return -EINVAL;
-		}
-		ret = amdgpu_dpm_force_performance_level(adev, level);
-		if (ret) {
-			mutex_unlock(&adev->pm.mutex);
-			pm_runtime_mark_last_busy(ddev->dev);
-			pm_runtime_put_autosuspend(ddev->dev);
-			return -EINVAL;
-		} else {
-			adev->pm.dpm.forced_level = level;
-		}
-		mutex_unlock(&adev->pm.mutex);
+	if (amdgpu_dpm_force_performance_level(adev, level)) {
+		pm_runtime_mark_last_busy(ddev->dev);
+		pm_runtime_put_autosuspend(ddev->dev);
+		return -EINVAL;
   	}
+
   	pm_runtime_mark_last_busy(ddev->dev);
   	pm_runtime_put_autosuspend(ddev->dev);
 
@@ -421,7 +383,6 @@ static ssize_t amdgpu_get_pp_num_states(struct

device *dev,

drivers/gpu/drm/amd/pm/amdgpu_pm.c static ssize_t amdgpu_get_pp_num_states(struct

Quoted 8 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +0 -1
   {
   	struct drm_device *ddev = dev_get_drvdata(dev);
   	struct amdgpu_device *adev = drm_to_adev(ddev);
-	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
   	struct pp_states_info data;
   	uint32_t i;
   	int buf_len, ret;
@@ -437,11 +398,8 @@ static ssize_t amdgpu_get_pp_num_states(struct

device *dev,

drivers/gpu/drm/amd/pm/amdgpu_pm.c static ssize_t amdgpu_get_pp_cur_state(struct

Quoted 13 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +1 -4
   		return ret;
   	}
 
-	if (pp_funcs->get_pp_num_states) {
-		amdgpu_dpm_get_pp_num_states(adev, &data);
-	} else {
+	if (amdgpu_dpm_get_pp_num_states(adev, &data))
   		memset(&data, 0, sizeof(data));
-	}
 
   	pm_runtime_mark_last_busy(ddev->dev);
   	pm_runtime_put_autosuspend(ddev->dev);
@@ -463,7 +421,6 @@ static ssize_t amdgpu_get_pp_cur_state(struct

device *dev,

drivers/gpu/drm/amd/pm/amdgpu_pm.c static ssize_t amdgpu_get_pp_cur_state(struct

Quoted 8 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +0 -1
   {
   	struct drm_device *ddev = dev_get_drvdata(dev);
   	struct amdgpu_device *adev = drm_to_adev(ddev);
-	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
   	struct pp_states_info data = {0};
   	enum amd_pm_state_type pm = 0;
   	int i = 0, ret = 0;
@@ -479,15 +436,16 @@ static ssize_t amdgpu_get_pp_cur_state(struct

device *dev,

drivers/gpu/drm/amd/pm/amdgpu_pm.c static ssize_t amdgpu_set_pp_force_state(struct

Quoted 22 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +6 -5
   		return ret;
   	}
 
-	if (pp_funcs->get_current_power_state
-		 && pp_funcs->get_pp_num_states) {
-		pm = amdgpu_dpm_get_current_power_state(adev);
-		amdgpu_dpm_get_pp_num_states(adev, &data);
-	}
+	amdgpu_dpm_get_current_power_state(adev, &pm);
+
+	ret = amdgpu_dpm_get_pp_num_states(adev, &data);
 
   	pm_runtime_mark_last_busy(ddev->dev);
   	pm_runtime_put_autosuspend(ddev->dev);
 
+	if (ret)
+		return ret;
+
   	for (i = 0; i < data.nums; i++) {
   		if (pm == data.states[i])
   			break;
@@ -525,6 +483,7 @@ static ssize_t amdgpu_set_pp_force_state(struct

device *dev,

drivers/gpu/drm/amd/pm/amdgpu_pm.c static ssize_t amdgpu_set_pp_force_state(struct

Quoted 8 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +1 -0
   	struct drm_device *ddev = dev_get_drvdata(dev);
   	struct amdgpu_device *adev = drm_to_adev(ddev);
   	enum amd_pm_state_type state = 0;
+	struct pp_states_info data;
   	unsigned long idx;
   	int ret;
 
@@ -533,41 +492,49 @@ static ssize_t amdgpu_set_pp_force_state(struct

device *dev,

Quoted 28 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +6 -16
   	if (adev->in_suspend && !adev->in_runpm)
   		return -EPERM;
 
-	if (strlen(buf) == 1)
-		adev->pp_force_state_enabled = false;
-	else if (is_support_sw_smu(adev))
-		adev->pp_force_state_enabled = false;
-	else if (adev->powerplay.pp_funcs->dispatch_tasks &&
-			adev->powerplay.pp_funcs->get_pp_num_states) {
-		struct pp_states_info data;
-
-		ret = kstrtoul(buf, 0, &idx);
-		if (ret || idx >= ARRAY_SIZE(data.states))
-			return -EINVAL;
+	adev->pp_force_state_enabled = false;
 
-		idx = array_index_nospec(idx, ARRAY_SIZE(data.states));
+	if (strlen(buf) == 1)
+		return count;
 
-		amdgpu_dpm_get_pp_num_states(adev, &data);
-		state = data.states[idx];
+	ret = kstrtoul(buf, 0, &idx);
+	if (ret || idx >= ARRAY_SIZE(data.states))
+		return -EINVAL;
 
-		ret = pm_runtime_get_sync(ddev->dev);
-		if (ret < 0) {

drivers/gpu/drm/amd/pm/amdgpu_pm.c static ssize_t amdgpu_set_pp_force_state(struct device *dev,

Quoted 10 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +1 -8
-			pm_runtime_put_autosuspend(ddev->dev);
-			return ret;
-		}
+	idx = array_index_nospec(idx, ARRAY_SIZE(data.states));
 
-		/* only set user selected power states */
-		if (state != POWER_STATE_TYPE_INTERNAL_BOOT &&
-		    state != POWER_STATE_TYPE_DEFAULT) {
-			amdgpu_dpm_dispatch_task(adev,
-
	AMD_PP_TASK_ENABLE_USER_STATE, &state);
Quoted 10 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +6 -3
-			adev->pp_force_state_enabled = true;
-		}
-		pm_runtime_mark_last_busy(ddev->dev);
+	ret = pm_runtime_get_sync(ddev->dev);
+	if (ret < 0) {
   		pm_runtime_put_autosuspend(ddev->dev);
+		return ret;
+	}
+
+	ret = amdgpu_dpm_get_pp_num_states(adev, &data);

drivers/gpu/drm/amd/pm/amdgpu_pm.c static ssize_t amdgpu_set_pp_force_state(struct device *dev,

Quoted 10 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +10 -0
+	if (ret)
+		goto err_out;
+
+	state = data.states[idx];
+
+	/* only set user selected power states */
+	if (state != POWER_STATE_TYPE_INTERNAL_BOOT &&
+	    state != POWER_STATE_TYPE_DEFAULT) {
+		ret = amdgpu_dpm_dispatch_task(adev,
+				AMD_PP_TASK_ENABLE_USER_STATE,

&state);

drivers/gpu/drm/amd/pm/amdgpu_pm.c static ssize_t amdgpu_get_pp_table(struct device

Quoted 19 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +12 -0
+		if (ret)
+			goto err_out;
+
+		adev->pp_force_state_enabled = true;
   	}
 
+	pm_runtime_mark_last_busy(ddev->dev);
+	pm_runtime_put_autosuspend(ddev->dev);
+
   	return count;
+
+err_out:
+	pm_runtime_mark_last_busy(ddev->dev);
+	pm_runtime_put_autosuspend(ddev->dev);
+	return ret;
   }
 
   /**
@@ -601,17 +568,13 @@ static ssize_t amdgpu_get_pp_table(struct device

*dev,

drivers/gpu/drm/amd/pm/amdgpu_pm.c static ssize_t amdgpu_set_pp_table(struct device

Quoted 25 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +7 -11
   		return ret;
   	}
 
-	if (adev->powerplay.pp_funcs->get_pp_table) {
-		size = amdgpu_dpm_get_pp_table(adev, &table);
-		pm_runtime_mark_last_busy(ddev->dev);
-		pm_runtime_put_autosuspend(ddev->dev);
-		if (size < 0)
-			return size;
-	} else {
-		pm_runtime_mark_last_busy(ddev->dev);
-		pm_runtime_put_autosuspend(ddev->dev);
-		return 0;
-	}
+	size = amdgpu_dpm_get_pp_table(adev, &table);
+
+	pm_runtime_mark_last_busy(ddev->dev);
+	pm_runtime_put_autosuspend(ddev->dev);
+
+	if (size <= 0)
+		return size;
 
   	if (size >= PAGE_SIZE)
   		size = PAGE_SIZE - 1;
@@ -642,15 +605,13 @@ static ssize_t amdgpu_set_pp_table(struct device

*dev,

drivers/gpu/drm/amd/pm/amdgpu_pm.c static ssize_t

Quoted 19 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +3 -5
   	}
 
   	ret = amdgpu_dpm_set_pp_table(adev, buf, count);
-	if (ret) {
-		pm_runtime_mark_last_busy(ddev->dev);
-		pm_runtime_put_autosuspend(ddev->dev);
-		return ret;
-	}
 
   	pm_runtime_mark_last_busy(ddev->dev);
   	pm_runtime_put_autosuspend(ddev->dev);
 
+	if (ret)
+		return ret;
+
   	return count;
   }
 
@@ -866,46 +827,32 @@ static ssize_t

amdgpu_set_pp_od_clk_voltage(struct device *dev,

Quoted 12 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +0 -9
   		return ret;
   	}
 
-	if (adev->powerplay.pp_funcs->set_fine_grain_clk_vol) {
-		ret = amdgpu_dpm_set_fine_grain_clk_vol(adev, type,
-							parameter,
-							parameter_size);
-		if (ret) {
-			pm_runtime_mark_last_busy(ddev->dev);
-			pm_runtime_put_autosuspend(ddev->dev);
-			return -EINVAL;
-		}

drivers/gpu/drm/amd/pm/amdgpu_pm.c static ssize_t amdgpu_set_pp_od_clk_voltage(struct device *dev,

Quoted 10 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +5 -4
-	}
+	if (amdgpu_dpm_set_fine_grain_clk_vol(adev,
+					      type,
+					      parameter,
+					      parameter_size))
+		goto err_out;
 
-	if (adev->powerplay.pp_funcs->odn_edit_dpm_table) {
-		ret = amdgpu_dpm_odn_edit_dpm_table(adev, type,
-						    parameter,

parameter_size);

drivers/gpu/drm/amd/pm/amdgpu_pm.c static ssize_t amdgpu_set_pp_od_clk_voltage(struct device *dev, · line 839

Quoted 10 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +3 -6
-		if (ret) {
-			pm_runtime_mark_last_busy(ddev->dev);
-			pm_runtime_put_autosuspend(ddev->dev);
-			return -EINVAL;
-		}
-	}
+	if (amdgpu_dpm_odn_edit_dpm_table(adev, type,
+					  parameter, parameter_size))
+		goto err_out;
 

This is one example of returning 'fake success' effect. If the function is not implemented it proceeds. There is no need to proceed if there is no support.

Thanks,
Lijo

drivers/gpu/drm/amd/pm/amdgpu_pm.c static ssize_t amdgpu_set_pp_od_clk_voltage(struct device *dev,

Quoted 4 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +0 -3
   	if (type == PP_OD_COMMIT_DPM_TABLE) {
-		if (adev->powerplay.pp_funcs->dispatch_tasks) {
-			amdgpu_dpm_dispatch_task(adev,
-

AMD_PP_TASK_READJUST_POWER_STATE,

drivers/gpu/drm/amd/pm/amdgpu_pm.c static ssize_t amdgpu_set_pp_od_clk_voltage(struct device *dev, · line 851

Quoted 11 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +2 -9
-						 NULL);
-			pm_runtime_mark_last_busy(ddev->dev);
-			pm_runtime_put_autosuspend(ddev->dev);
-			return count;
-		} else {
-			pm_runtime_mark_last_busy(ddev->dev);
-			pm_runtime_put_autosuspend(ddev->dev);
-			return -EINVAL;
-		}
+		if (amdgpu_dpm_dispatch_task(adev,
+

AMD_PP_TASK_READJUST_POWER_STATE,

drivers/gpu/drm/amd/pm/amdgpu_pm.c static ssize_t

Quoted 17 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +7 -0
+					     NULL))
+			goto err_out;
   	}
 
   	pm_runtime_mark_last_busy(ddev->dev);
   	pm_runtime_put_autosuspend(ddev->dev);
 
   	return count;
+
+err_out:
+	pm_runtime_mark_last_busy(ddev->dev);
+	pm_runtime_put_autosuspend(ddev->dev);
+	return -EINVAL;
   }
 
   static ssize_t amdgpu_get_pp_od_clk_voltage(struct device *dev,
@@ -928,8 +875,8 @@ static ssize_t

amdgpu_get_pp_od_clk_voltage(struct device *dev,

drivers/gpu/drm/amd/pm/amdgpu_pm.c static ssize_t amdgpu_get_pp_od_clk_voltage(struct device *dev,

Quoted 8 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +2 -2
   		return ret;
   	}
 
-	if (adev->powerplay.pp_funcs->print_clock_levels) {
-		size = amdgpu_dpm_print_clock_levels(adev, OD_SCLK, buf);
+	size = amdgpu_dpm_print_clock_levels(adev, OD_SCLK, buf);
+	if (size > 0) {
   		size += amdgpu_dpm_print_clock_levels(adev, OD_MCLK,

buf+size);

drivers/gpu/drm/amd/pm/amdgpu_pm.c static ssize_t · line 881

Quoted 1 line
drivers/gpu/drm/amd/pm/amdgpu_pm.c +0 -0
   		size += amdgpu_dpm_print_clock_levels(adev,

OD_VDDC_CURVE, buf+size);

drivers/gpu/drm/amd/pm/amdgpu_pm.c static ssize_t · line 882

Quoted 1 line
drivers/gpu/drm/amd/pm/amdgpu_pm.c +0 -0
   		size += amdgpu_dpm_print_clock_levels(adev,

OD_VDDGFX_OFFSET, buf+size);

drivers/gpu/drm/amd/pm/amdgpu_pm.c static ssize_t amdgpu_set_pp_features(struct

Quoted 1 line
drivers/gpu/drm/amd/pm/amdgpu_pm.c +0 -0
@@ -985,17 +932,14 @@ static ssize_t amdgpu_set_pp_features(struct

device *dev,

drivers/gpu/drm/amd/pm/amdgpu_pm.c static ssize_t amdgpu_set_pp_features(struct device *dev,

Quoted 5 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +0 -2
   		return ret;
   	}
 
-	if (adev->powerplay.pp_funcs->set_ppfeature_status) {
-		ret = amdgpu_dpm_set_ppfeature_status(adev,

featuremask);

drivers/gpu/drm/amd/pm/amdgpu_pm.c static ssize_t amdgpu_get_pp_features(struct

Quoted 18 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +5 -6
-		if (ret) {
-			pm_runtime_mark_last_busy(ddev->dev);
-			pm_runtime_put_autosuspend(ddev->dev);
-			return -EINVAL;
-		}
-	}
+	ret = amdgpu_dpm_set_ppfeature_status(adev, featuremask);
+
   	pm_runtime_mark_last_busy(ddev->dev);
   	pm_runtime_put_autosuspend(ddev->dev);
 
+	if (ret)
+		return -EINVAL;
+
   	return count;
   }
 
@@ -1019,9 +963,8 @@ static ssize_t amdgpu_get_pp_features(struct

device *dev,

drivers/gpu/drm/amd/pm/amdgpu_pm.c static ssize_t amdgpu_get_pp_dpm_clock(struct

Quoted 12 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +2 -3
   		return ret;
   	}
 
-	if (adev->powerplay.pp_funcs->get_ppfeature_status)
-		size = amdgpu_dpm_get_ppfeature_status(adev, buf);
-	else
+	size = amdgpu_dpm_get_ppfeature_status(adev, buf);
+	if (size <= 0)
   		size = sysfs_emit(buf, "\n");
 
   	pm_runtime_mark_last_busy(ddev->dev);
@@ -1080,9 +1023,8 @@ static ssize_t amdgpu_get_pp_dpm_clock(struct

device *dev,

drivers/gpu/drm/amd/pm/amdgpu_pm.c static ssize_t amdgpu_set_pp_dpm_clock(struct

Quoted 12 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +2 -3
   		return ret;
   	}
 
-	if (adev->powerplay.pp_funcs->print_clock_levels)
-		size = amdgpu_dpm_print_clock_levels(adev, type, buf);
-	else
+	size = amdgpu_dpm_print_clock_levels(adev, type, buf);
+	if (size <= 0)
   		size = sysfs_emit(buf, "\n");
 
   	pm_runtime_mark_last_busy(ddev->dev);
@@ -1151,10 +1093,7 @@ static ssize_t amdgpu_set_pp_dpm_clock(struct

device *dev,

drivers/gpu/drm/amd/pm/amdgpu_pm.c static ssize_t amdgpu_get_pp_sclk_od(struct

Quoted 12 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +1 -4
   		return ret;
   	}
 
-	if (adev->powerplay.pp_funcs->force_clock_level)
-		ret = amdgpu_dpm_force_clock_level(adev, type, mask);
-	else
-		ret = 0;
+	ret = amdgpu_dpm_force_clock_level(adev, type, mask);
 
   	pm_runtime_mark_last_busy(ddev->dev);
   	pm_runtime_put_autosuspend(ddev->dev);
@@ -1305,10 +1244,7 @@ static ssize_t amdgpu_get_pp_sclk_od(struct

device *dev,

drivers/gpu/drm/amd/pm/amdgpu_pm.c static ssize_t amdgpu_set_pp_sclk_od(struct

Quoted 12 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +1 -4
   		return ret;
   	}
 
-	if (is_support_sw_smu(adev))
-		value = 0;
-	else if (adev->powerplay.pp_funcs->get_sclk_od)
-		value = amdgpu_dpm_get_sclk_od(adev);
+	value = amdgpu_dpm_get_sclk_od(adev);
 
   	pm_runtime_mark_last_busy(ddev->dev);
   	pm_runtime_put_autosuspend(ddev->dev);
@@ -1342,19 +1278,7 @@ static ssize_t amdgpu_set_pp_sclk_od(struct

device *dev,

drivers/gpu/drm/amd/pm/amdgpu_pm.c static ssize_t amdgpu_set_pp_sclk_od(struct device *dev,

Quoted 11 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +0 -8
   		return ret;
   	}
 
-	if (is_support_sw_smu(adev)) {
-		value = 0;
-	} else {
-		if (adev->powerplay.pp_funcs->set_sclk_od)
-			amdgpu_dpm_set_sclk_od(adev, (uint32_t)value);
-
-		if (adev->powerplay.pp_funcs->dispatch_tasks) {
-			amdgpu_dpm_dispatch_task(adev,

AMD_PP_TASK_READJUST_POWER_STATE, NULL);

drivers/gpu/drm/amd/pm/amdgpu_pm.c static ssize_t amdgpu_get_pp_mclk_od(struct

Quoted 11 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +1 -5
-		} else {
-			adev->pm.dpm.current_ps = adev-
 pm.dpm.boot_ps;
-			amdgpu_pm_compute_clocks(adev);
-		}
-	}
+	amdgpu_dpm_set_sclk_od(adev, (uint32_t)value);
 
   	pm_runtime_mark_last_busy(ddev->dev);
   	pm_runtime_put_autosuspend(ddev->dev);
drivers/gpu/drm/amd/pm/amdgpu_pm.c +0 -0
@@ -1382,10 +1306,7 @@ static ssize_t amdgpu_get_pp_mclk_od(struct

device *dev,

drivers/gpu/drm/amd/pm/amdgpu_pm.c static ssize_t amdgpu_set_pp_mclk_od(struct

Quoted 12 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +1 -4
   		return ret;
   	}
 
-	if (is_support_sw_smu(adev))
-		value = 0;
-	else if (adev->powerplay.pp_funcs->get_mclk_od)
-		value = amdgpu_dpm_get_mclk_od(adev);
+	value = amdgpu_dpm_get_mclk_od(adev);
 
   	pm_runtime_mark_last_busy(ddev->dev);
   	pm_runtime_put_autosuspend(ddev->dev);
@@ -1419,19 +1340,7 @@ static ssize_t amdgpu_set_pp_mclk_od(struct

device *dev,

drivers/gpu/drm/amd/pm/amdgpu_pm.c static ssize_t amdgpu_set_pp_mclk_od(struct device *dev,

Quoted 11 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +0 -8
   		return ret;
   	}
 
-	if (is_support_sw_smu(adev)) {
-		value = 0;
-	} else {
-		if (adev->powerplay.pp_funcs->set_mclk_od)
-			amdgpu_dpm_set_mclk_od(adev, (uint32_t)value);
-
-		if (adev->powerplay.pp_funcs->dispatch_tasks) {
-			amdgpu_dpm_dispatch_task(adev,

AMD_PP_TASK_READJUST_POWER_STATE, NULL);

drivers/gpu/drm/amd/pm/amdgpu_pm.c static ssize_t

Quoted 11 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +1 -5
-		} else {
-			adev->pm.dpm.current_ps = adev-
 pm.dpm.boot_ps;
-			amdgpu_pm_compute_clocks(adev);
-		}
-	}
+	amdgpu_dpm_set_mclk_od(adev, (uint32_t)value);
 
   	pm_runtime_mark_last_busy(ddev->dev);
   	pm_runtime_put_autosuspend(ddev->dev);
drivers/gpu/drm/amd/pm/amdgpu_pm.c +0 -0
@@ -1479,9 +1388,8 @@ static ssize_t

amdgpu_get_pp_power_profile_mode(struct device *dev,

drivers/gpu/drm/amd/pm/amdgpu_pm.c static ssize_t

Quoted 12 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +2 -3
   		return ret;
   	}
 
-	if (adev->powerplay.pp_funcs->get_power_profile_mode)
-		size = amdgpu_dpm_get_power_profile_mode(adev, buf);
-	else
+	size = amdgpu_dpm_get_power_profile_mode(adev, buf);
+	if (size <= 0)
   		size = sysfs_emit(buf, "\n");
 
   	pm_runtime_mark_last_busy(ddev->dev);
@@ -1545,8 +1453,7 @@ static ssize_t

amdgpu_set_pp_power_profile_mode(struct device *dev,

drivers/gpu/drm/amd/pm/amdgpu_pm.c static ssize_t amdgpu_set_pp_power_profile_mode(struct device *dev,

Quoted 5 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +0 -2
   		return ret;
   	}
 
-	if (adev->powerplay.pp_funcs->set_power_profile_mode)
-		ret = amdgpu_dpm_set_power_profile_mode(adev,

parameter, parameter_size);

drivers/gpu/drm/amd/pm/amdgpu_pm.c static ssize_t · line 1456

Quoted 1 line
drivers/gpu/drm/amd/pm/amdgpu_pm.c +1 -0
+	ret = amdgpu_dpm_set_power_profile_mode(adev, parameter,

parameter_size);

drivers/gpu/drm/amd/pm/amdgpu_pm.c static ssize_t amdgpu_get_gpu_metrics(struct

Quoted 4 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +0 -0
   	pm_runtime_mark_last_busy(ddev->dev);
   	pm_runtime_put_autosuspend(ddev->dev);
@@ -1812,9 +1719,7 @@ static ssize_t amdgpu_get_gpu_metrics(struct

device *dev,

drivers/gpu/drm/amd/pm/amdgpu_pm.c static int default_attr_update(struct

Quoted 11 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +1 -3
   		return ret;
   	}
 
-	if (adev->powerplay.pp_funcs->get_gpu_metrics)
-		size = amdgpu_dpm_get_gpu_metrics(adev, &gpu_metrics);
-
+	size = amdgpu_dpm_get_gpu_metrics(adev, &gpu_metrics);
   	if (size <= 0)
   		goto out;
 
@@ -2053,7 +1958,6 @@ static int default_attr_update(struct

amdgpu_device *adev, struct amdgpu_device_

drivers/gpu/drm/amd/pm/amdgpu_pm.c static int default_attr_update(struct

Quoted 8 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +0 -1
   {
   	struct device_attribute *dev_attr = &attr->dev_attr;
   	const char *attr_name = dev_attr->attr.name;
-	struct pp_hwmgr *hwmgr = adev->powerplay.pp_handle;
   	enum amd_asic_type asic_type = adev->asic_type;
 
   	if (!(attr->flags & mask)) {
@@ -2076,9 +1980,7 @@ static int default_attr_update(struct

amdgpu_device *adev, struct amdgpu_device_

drivers/gpu/drm/amd/pm/amdgpu_pm.c static int default_attr_update(struct amdgpu_device *adev, struct amdgpu_device_

Quoted 4 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +0 -1
   			*states = ATTR_STATE_UNSUPPORTED;
   	} else if (DEVICE_ATTR_IS(pp_od_clk_voltage)) {
   		*states = ATTR_STATE_UNSUPPORTED;
-		if ((is_support_sw_smu(adev) && adev->smu.od_enabled)
||
> -		    (is_support_sw_smu(adev) && adev->smu.is_apu) ||

drivers/gpu/drm/amd/pm/amdgpu_pm.c static int default_attr_update(struct

Quoted 7 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +1 -1
-			(!is_support_sw_smu(adev) && hwmgr-
 od_enabled))
+		if (amdgpu_dpm_is_overdrive_supported(adev))
   			*states = ATTR_STATE_SUPPORTED;
   	} else if (DEVICE_ATTR_IS(mem_busy_percent)) {
   		if (adev->flags & AMD_IS_APU || asic_type == CHIP_VEGA10)
@@ -2105,8 +2007,7 @@ static int default_attr_update(struct

amdgpu_device *adev, struct amdgpu_device_

drivers/gpu/drm/amd/pm/amdgpu_pm.c static int default_attr_update(struct · line 2007

Quoted 1 line
drivers/gpu/drm/amd/pm/amdgpu_pm.c +0 -0
   		if (!(asic_type == CHIP_VANGOGH || asic_type ==

CHIP_SIENNA_CICHLID))

drivers/gpu/drm/amd/pm/amdgpu_pm.c static int default_attr_update(struct amdgpu_device *adev, struct amdgpu_device_

Quoted 3 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +0 -1
   			*states = ATTR_STATE_UNSUPPORTED;
   	} else if (DEVICE_ATTR_IS(pp_power_profile_mode)) {
-		if (!adev->powerplay.pp_funcs->get_power_profile_mode
||
> -		    amdgpu_dpm_get_power_profile_mode(adev, NULL) == -

EOPNOTSUPP)

drivers/gpu/drm/amd/pm/amdgpu_pm.c static int default_attr_update(struct · line 2010

Quoted 1 line
drivers/gpu/drm/amd/pm/amdgpu_pm.c +1 -0
+		if (amdgpu_dpm_get_power_profile_mode(adev, NULL) ==

-EOPNOTSUPP)

drivers/gpu/drm/amd/pm/amdgpu_pm.c static ssize_t

Quoted 4 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +0 -0
   			*states = ATTR_STATE_UNSUPPORTED;
   	}
 
@@ -2389,17 +2290,14 @@ static ssize_t

amdgpu_hwmon_get_pwm1_enable(struct device *dev,

drivers/gpu/drm/amd/pm/amdgpu_pm.c static ssize_t

Quoted 22 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +4 -7
   		return ret;
   	}
 
-	if (!adev->powerplay.pp_funcs->get_fan_control_mode) {
-		pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
-		pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
-		return -EINVAL;
-	}
-
-	pwm_mode = amdgpu_dpm_get_fan_control_mode(adev);
+	ret = amdgpu_dpm_get_fan_control_mode(adev, &pwm_mode);
 
   	pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
   	pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
 
+	if (ret)
+		return -EINVAL;
+
   	return sysfs_emit(buf, "%u\n", pwm_mode);
   }
 
@@ -2427,17 +2325,14 @@ static ssize_t

amdgpu_hwmon_set_pwm1_enable(struct device *dev,

drivers/gpu/drm/amd/pm/amdgpu_pm.c static ssize_t

Quoted 22 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +4 -7
   		return ret;
   	}
 
-	if (!adev->powerplay.pp_funcs->set_fan_control_mode) {
-		pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
-		pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
-		return -EINVAL;
-	}
-
-	amdgpu_dpm_set_fan_control_mode(adev, value);
+	ret = amdgpu_dpm_set_fan_control_mode(adev, value);
 
   	pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
   	pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
 
+	if (ret)
+		return -EINVAL;
+
   	return count;
   }
 
@@ -2469,32 +2364,29 @@ static ssize_t

amdgpu_hwmon_set_pwm1(struct device *dev,

Quoted 10 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +4 -0
   	if (adev->in_suspend && !adev->in_runpm)
   		return -EPERM;
 
+	err = kstrtou32(buf, 10, &value);
+	if (err)
+		return err;
+
   	err = pm_runtime_get_sync(adev_to_drm(adev)->dev);
   	if (err < 0) {
   		pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);

drivers/gpu/drm/amd/pm/amdgpu_pm.c static ssize_t amdgpu_hwmon_set_pwm1(struct device *dev,

Quoted 10 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +4 -1
   		return err;
   	}
 
-	pwm_mode = amdgpu_dpm_get_fan_control_mode(adev);
+	err = amdgpu_dpm_get_fan_control_mode(adev, &pwm_mode);
+	if (err)
+		goto out;
+
   	if (pwm_mode != AMD_FAN_CTRL_MANUAL) {
   		pr_info("manual fan speed control should be enabled

first\n");

drivers/gpu/drm/amd/pm/amdgpu_pm.c static ssize_t

Quoted 25 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +4 -14
-		pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
-		pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
-		return -EINVAL;
+		err = -EINVAL;
+		goto out;
   	}
 
-	err = kstrtou32(buf, 10, &value);
-	if (err) {
-		pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
-		pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
-		return err;
-	}
-
-	if (adev->powerplay.pp_funcs->set_fan_speed_pwm)
-		err = amdgpu_dpm_set_fan_speed_pwm(adev, value);
-	else
-		err = -EINVAL;
+	err = amdgpu_dpm_set_fan_speed_pwm(adev, value);
 
+out:
   	pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
   	pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
 
@@ -2523,10 +2415,7 @@ static ssize_t

amdgpu_hwmon_get_pwm1(struct device *dev,

drivers/gpu/drm/amd/pm/amdgpu_pm.c static ssize_t

Quoted 12 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +1 -4
   		return err;
   	}
 
-	if (adev->powerplay.pp_funcs->get_fan_speed_pwm)
-		err = amdgpu_dpm_get_fan_speed_pwm(adev, &speed);
-	else
-		err = -EINVAL;
+	err = amdgpu_dpm_get_fan_speed_pwm(adev, &speed);
 
   	pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
   	pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
@@ -2556,10 +2445,7 @@ static ssize_t

amdgpu_hwmon_get_fan1_input(struct device *dev,

drivers/gpu/drm/amd/pm/amdgpu_pm.c static ssize_t

Quoted 12 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +1 -4
   		return err;
   	}
 
-	if (adev->powerplay.pp_funcs->get_fan_speed_rpm)
-		err = amdgpu_dpm_get_fan_speed_rpm(adev, &speed);
-	else
-		err = -EINVAL;
+	err = amdgpu_dpm_get_fan_speed_rpm(adev, &speed);
 
   	pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
   	pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
@@ -2653,10 +2539,7 @@ static ssize_t

amdgpu_hwmon_get_fan1_target(struct device *dev,

drivers/gpu/drm/amd/pm/amdgpu_pm.c static ssize_t

Quoted 12 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +1 -4
   		return err;
   	}
 
-	if (adev->powerplay.pp_funcs->get_fan_speed_rpm)
-		err = amdgpu_dpm_get_fan_speed_rpm(adev, &rpm);
-	else
-		err = -EINVAL;
+	err = amdgpu_dpm_get_fan_speed_rpm(adev, &rpm);
 
   	pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
   	pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
@@ -2681,32 +2564,28 @@ static ssize_t

amdgpu_hwmon_set_fan1_target(struct device *dev,

drivers/gpu/drm/amd/pm/amdgpu_pm.c static ssize_t

Quoted 44 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +11 -15
   	if (adev->in_suspend && !adev->in_runpm)
   		return -EPERM;
 
+	err = kstrtou32(buf, 10, &value);
+	if (err)
+		return err;
+
   	err = pm_runtime_get_sync(adev_to_drm(adev)->dev);
   	if (err < 0) {
   		pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
   		return err;
   	}
 
-	pwm_mode = amdgpu_dpm_get_fan_control_mode(adev);
+	err = amdgpu_dpm_get_fan_control_mode(adev, &pwm_mode);
+	if (err)
+		goto out;
 
   	if (pwm_mode != AMD_FAN_CTRL_MANUAL) {
-		pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
-		pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
-		return -ENODATA;
-	}
-
-	err = kstrtou32(buf, 10, &value);
-	if (err) {
-		pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
-		pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
-		return err;
+		err = -ENODATA;
+		goto out;
   	}
 
-	if (adev->powerplay.pp_funcs->set_fan_speed_rpm)
-		err = amdgpu_dpm_set_fan_speed_rpm(adev, value);
-	else
-		err = -EINVAL;
+	err = amdgpu_dpm_set_fan_speed_rpm(adev, value);
 
+out:
   	pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
   	pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
 
@@ -2735,17 +2614,14 @@ static ssize_t

amdgpu_hwmon_get_fan1_enable(struct device *dev,

Quoted 9 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +0 -6
   		return ret;
   	}
 
-	if (!adev->powerplay.pp_funcs->get_fan_control_mode) {
-		pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
-		pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
-		return -EINVAL;
-	}
-

drivers/gpu/drm/amd/pm/amdgpu_pm.c static ssize_t amdgpu_hwmon_get_pwm1_enable(struct device *dev,

Quoted 10 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +4 -1
-	pwm_mode = amdgpu_dpm_get_fan_control_mode(adev);
+	ret = amdgpu_dpm_get_fan_control_mode(adev, &pwm_mode);
 
   	pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
   	pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
 
+	if (ret)
+		return -EINVAL;
+
   	return sysfs_emit(buf, "%i\n", pwm_mode ==

AMD_FAN_CTRL_AUTO ? 0 : 1);

drivers/gpu/drm/amd/pm/amdgpu_pm.c static ssize_t

Quoted 3 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +0 -0
   }
 
@@ -2781,16 +2657,14 @@ static ssize_t

amdgpu_hwmon_set_fan1_enable(struct device *dev,

drivers/gpu/drm/amd/pm/amdgpu_pm.c static ssize_t

Quoted 21 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +4 -6
   		return err;
   	}
 
-	if (!adev->powerplay.pp_funcs->set_fan_control_mode) {
-		pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
-		pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
-		return -EINVAL;
-	}
-	amdgpu_dpm_set_fan_control_mode(adev, pwm_mode);
+	err = amdgpu_dpm_set_fan_control_mode(adev, pwm_mode);
 
   	pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
   	pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
 
+	if (err)
+		return -EINVAL;
+
   	return count;
   }
 
@@ -2926,7 +2800,6 @@ static ssize_t

amdgpu_hwmon_show_power_cap_generic(struct device *dev,

drivers/gpu/drm/amd/pm/amdgpu_pm.c static ssize_t · line 2800

Quoted 1 line
drivers/gpu/drm/amd/pm/amdgpu_pm.c +0 -0
   					enum pp_power_limit_level

pp_limit_level)

drivers/gpu/drm/amd/pm/amdgpu_pm.c static ssize_t

Quoted 8 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +0 -1
   {
   	struct amdgpu_device *adev = dev_get_drvdata(dev);
-	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
   	enum pp_power_type power_type = to_sensor_dev_attr(attr)-
 index;
   	uint32_t limit;
   	ssize_t size;
drivers/gpu/drm/amd/pm/amdgpu_pm.c +0 -0
@@ -2937,16 +2810,13 @@ static ssize_t

amdgpu_hwmon_show_power_cap_generic(struct device *dev,

drivers/gpu/drm/amd/pm/amdgpu_pm.c static ssize_t

Quoted 18 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +1 -4
   	if (adev->in_suspend && !adev->in_runpm)
   		return -EPERM;
 
-	if ( !(pp_funcs && pp_funcs->get_power_limit))
-		return -ENODATA;
-
   	r = pm_runtime_get_sync(adev_to_drm(adev)->dev);
   	if (r < 0) {
   		pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
   		return r;
   	}
 
-	r = pp_funcs->get_power_limit(adev->powerplay.pp_handle, &limit,
+	r = amdgpu_dpm_get_power_limit(adev, &limit,
[… more lines in the raw message]
@@ -3001,7 +2871,6 @@ static ssize_t

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

amdgpu_hwmon_set_power_cap(struct device *dev,

drivers/gpu/drm/amd/pm/amdgpu_pm.c static ssize_t

Quoted 8 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +0 -1
@@ -3027,10 +2896,7 @@ static ssize_t

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

amdgpu_hwmon_set_power_cap(struct device *dev,

drivers/gpu/drm/amd/pm/amdgpu_pm.c static umode_t hwmon_attributes_visible(struct

Quoted 13 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +1 -4

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

   	pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
drivers/gpu/drm/amd/pm/amdgpu_pm.c +0 -0
@@ -3303,6 +3169,7 @@ static umode_t hwmon_attributes_visible(struct

kobject *kobj,

drivers/gpu/drm/amd/pm/amdgpu_pm.c

Quoted 6 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +1 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

*/

drivers/gpu/drm/amd/pm/amdgpu_pm.c static umode_t

Quoted 2 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +0 -0
@@ -3367,20 +3234,18 @@ static umode_t

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

hwmon_attributes_visible(struct kobject *kobj,

drivers/gpu/drm/amd/pm/amdgpu_pm.c

Quoted 5 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +0 -2

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

expose */

drivers/gpu/drm/amd/pm/amdgpu_pm.c

Quoted 2 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +0 -2

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

query fan */

drivers/gpu/drm/amd/pm/amdgpu_pm.c

Quoted 2 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +0 -2

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

/* can't query state */

drivers/gpu/drm/amd/pm/amdgpu_pm.c

Quoted 2 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +1 -1

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

*/

drivers/gpu/drm/amd/pm/amdgpu_pm.c

Quoted 1 line
drivers/gpu/drm/amd/pm/amdgpu_pm.c +1 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

&&

drivers/gpu/drm/amd/pm/amdgpu_pm.c

Quoted 1 line
drivers/gpu/drm/amd/pm/amdgpu_pm.c +1 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

fan */

drivers/gpu/drm/amd/pm/amdgpu_pm.c

Quoted 1 line
drivers/gpu/drm/amd/pm/amdgpu_pm.c +1 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

EOPNOTSUPP) &&

drivers/gpu/drm/amd/pm/amdgpu_pm.c

Quoted 1 line
drivers/gpu/drm/amd/pm/amdgpu_pm.c +1 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

query state */

drivers/gpu/drm/amd/pm/amdgpu_pm.c

Quoted 4 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +1 -2

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

manage fan */

drivers/gpu/drm/amd/pm/amdgpu_pm.c

Quoted 2 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +0 -2

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

/* can't manage state */

drivers/gpu/drm/amd/pm/amdgpu_pm.c

Quoted 3 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +1 -2

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

&&

drivers/gpu/drm/amd/pm/amdgpu_pm.c

Quoted 1 line
drivers/gpu/drm/amd/pm/amdgpu_pm.c +1 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

manage fan */

drivers/gpu/drm/amd/pm/amdgpu_pm.c

Quoted 1 line
drivers/gpu/drm/amd/pm/amdgpu_pm.c +1 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

EOPNOTSUPP) &&

drivers/gpu/drm/amd/pm/amdgpu_pm.c

Quoted 1 line
drivers/gpu/drm/amd/pm/amdgpu_pm.c +1 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

manage state */

drivers/gpu/drm/amd/pm/amdgpu_pm.c static umode_t

Quoted 5 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +1 -0
@@ -3397,22 +3262,20 @@ static umode_t

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

hwmon_attributes_visible(struct kobject *kobj,

drivers/gpu/drm/amd/pm/amdgpu_pm.c

Quoted 5 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +0 -2

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

the fan */

drivers/gpu/drm/amd/pm/amdgpu_pm.c

Quoted 9 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +2 -7

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

&&

drivers/gpu/drm/amd/pm/amdgpu_pm.c

Quoted 1 line
drivers/gpu/drm/amd/pm/amdgpu_pm.c +1 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

&&

drivers/gpu/drm/amd/pm/amdgpu_pm.c

Quoted 1 line
drivers/gpu/drm/amd/pm/amdgpu_pm.c +1 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

&&

drivers/gpu/drm/amd/pm/amdgpu_pm.c

Quoted 1 line
drivers/gpu/drm/amd/pm/amdgpu_pm.c +1 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

&&

drivers/gpu/drm/amd/pm/amdgpu_pm.c

Quoted 11 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +4 -6

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

&&

drivers/gpu/drm/amd/pm/amdgpu_pm.c

Quoted 1 line
drivers/gpu/drm/amd/pm/amdgpu_pm.c +1 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

&&

drivers/gpu/drm/amd/pm/amdgpu_pm.c

Quoted 5 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +3 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

yet */

drivers/gpu/drm/amd/pm/amdgpu_pm.c

Quoted 1 line
drivers/gpu/drm/amd/pm/amdgpu_pm.c +0 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

yet */

drivers/gpu/drm/amd/pm/amdgpu_pm.c static void

Quoted 1 line
drivers/gpu/drm/amd/pm/amdgpu_pm.c +0 -0
@@ -3542,14 +3405,15 @@ static void

amdgpu_debugfs_prints_cpu_info(struct seq_file *m,

drivers/gpu/drm/amd/pm/amdgpu_pm.c

Quoted 4 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +1 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

amdgpu_dpm_get_num_cpu_cores(adev);

drivers/gpu/drm/amd/pm/amdgpu_pm.c

Quoted 8 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +2 -2

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

AMDGPU_PP_SENSOR_CPU_CLK,

drivers/gpu/drm/amd/pm/amdgpu_pm.c static int

Quoted 7 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +1 -1
@@ -3677,27 +3541,11 @@ static int

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

amdgpu_debugfs_pm_info_show(struct seq_file *m, void *unused)

drivers/gpu/drm/amd/pm/amdgpu_pm.c

Quoted 20 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +0 -14

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

for this asic\n");

310 lines not shown · raw message

Parts of this message are not shown here. View the raw message.

author
#5 lore raw

RE: [PATCH V4 02/17] drm/amd/pm: do not expose power implementation details to amdgpu_pm.c

[AMD Official Use Only]

Quoted 215 lines

-----Original Message-----
From: Lazar, Lijo <[email protected]>
Sent: Friday, December 10, 2021 1:53 PM
To: Quan, Evan <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>; Feng, Kenneth <[email protected]>
Subject: Re: [PATCH V4 02/17] drm/amd/pm: do not expose power implementation details to amdgpu_pm.c

Quoted 9 lines · Evan

[AMD Official Use Only]

Quoted 5 lines

-----Original Message-----
From: Lazar, Lijo <[email protected]>
Sent: Thursday, December 9, 2021 7:58 PM
To: Quan, Evan <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>; Koenig,

Christian

Quoted 16 lines
Quoted 16 lines

<[email protected]>; Feng, Kenneth <[email protected]>
Subject: Re: [PATCH V4 02/17] drm/amd/pm: do not expose power implementation details to amdgpu_pm.c

Quoted 9 lines · Evan Quan

amdgpu_pm.c holds all the user sysfs/hwmon interfaces. It's another client of our power APIs. It's not proper to spike into power implementation details there.

Change-Id I397853ddb13eacfce841366de2a623535422df9a

--
v1->v2:
- drop unneeded "return;" in

Quoted 5 lines
Quoted 5 lines

amdgpu_dpm_get_current_power_state(Guchun)

Quoted 2 lines
---
   drivers/gpu/drm/amd/pm/amdgpu_dpm.c       | 456

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

Quoted 1 line
   drivers/gpu/drm/amd/pm/amdgpu_pm.c        | 519 ++++++++-----------

---

Quoted 11 lines
Quoted 11 lines

Review

Quoted 5 lines
   drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h   | 160 +++----
   drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c |   3 -
   4 files changed, 707 insertions(+), 431 deletions(-)
(quoted diff) +0 -0

b/drivers/gpu/drm/amd/pm/amdgpu_dpm.c

drivers/gpu/drm/amd/pm/amdgpu_dpm.c static void

Quoted 4 lines

index 54abdf7080de..2c789eb5d066 100644

drivers/gpu/drm/amd/pm/amdgpu_dpm.c +0 -0
@@ -1453,7 +1453,9 @@ static void

amdgpu_dpm_change_power_state_locked(struct amdgpu_device

*adev)

Quoted 153 lines
Quoted 89 lines

drivers/gpu/drm/amd/pm/amdgpu_dpm.c int amdgpu_dpm_get_ecc_info(struct

Quoted 13 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +3 -1
   	if (equal)
   		return;
 
-	amdgpu_dpm_set_power_state(adev);
+	if (adev->powerplay.pp_funcs->set_power_state)
+		adev->powerplay.pp_funcs->set_power_state(adev-
 powerplay.pp_handle);
+
   	amdgpu_dpm_post_set_power_state(adev);
 
   	adev->pm.dpm.current_active_crtcs = adev-

pm.dpm.new_active_crtcs;

drivers/gpu/drm/amd/pm/amdgpu_dpm.c +0 -0
@@ -1704,3 +1706,455 @@ int amdgpu_dpm_get_ecc_info(struct

amdgpu_device *adev,

drivers/gpu/drm/amd/pm/amdgpu_dpm.c int amdgpu_dpm_get_ecc_info(struct amdgpu_device *adev,

Quoted 5 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +2 -0
   	return smu_get_ecc_info(&adev->smu, umc_ecc);
   }
+
+struct amd_vce_state *amdgpu_dpm_get_vce_clock_state(struct

amdgpu_device *adev,

drivers/gpu/drm/amd/pm/amdgpu_dpm.c int amdgpu_dpm_get_ecc_info(struct amdgpu_device *adev,

Quoted 12 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +12 -0
+						     uint32_t idx)
+{
+	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+
+	if (!pp_funcs->get_vce_clock_state)
+		return NULL;
+
+	return pp_funcs->get_vce_clock_state(adev->powerplay.pp_handle,
+					     idx);
+}
+
+void amdgpu_dpm_get_current_power_state(struct amdgpu_device

*adev,

Quoted 13 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +12 -0
+					enum amd_pm_state_type *state)
+{
+	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+
+	if (!pp_funcs->get_current_power_state) {
+		*state = adev->pm.dpm.user_state;
+		return;
+	}
+
+	*state = pp_funcs->get_current_power_state(adev-
 powerplay.pp_handle);
+	if (*state < POWER_STATE_TYPE_DEFAULT ||
+	    *state > POWER_STATE_TYPE_INTERNAL_3DPERF)

drivers/gpu/drm/amd/pm/amdgpu_dpm.c int amdgpu_dpm_get_ecc_info(struct amdgpu_device *adev,

Quoted 10 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +10 -0
+		*state = adev->pm.dpm.user_state;
+}
+
+void amdgpu_dpm_set_power_state(struct amdgpu_device *adev,
+				enum amd_pm_state_type state)
+{
+	adev->pm.dpm.user_state = state;
+
+	if (adev->powerplay.pp_funcs->dispatch_tasks)
+		amdgpu_dpm_dispatch_task(adev,

AMD_PP_TASK_ENABLE_USER_STATE, &state);

drivers/gpu/drm/amd/pm/amdgpu_dpm.c int amdgpu_dpm_get_ecc_info(struct amdgpu_device *adev,

Quoted 5 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +5 -0
+	else
+		amdgpu_pm_compute_clocks(adev);
+}
+
+enum amd_dpm_forced_level

amdgpu_dpm_get_performance_level(struct amdgpu_device *adev)

Quoted 7 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +6 -0
+{
+	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+	enum amd_dpm_forced_level level;
+
+	if (pp_funcs->get_performance_level)
+		level = pp_funcs->get_performance_level(adev-

powerplay.pp_handle);

drivers/gpu/drm/amd/pm/amdgpu_dpm.c int amdgpu_dpm_get_ecc_info(struct amdgpu_device *adev,

Quoted 7 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +7 -0
+	else
+		level = adev->pm.dpm.forced_level;
+
+	return level;
+}
+
+int amdgpu_dpm_force_performance_level(struct amdgpu_device

*adev,

Quoted 11 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +9 -0
+				       enum amd_dpm_forced_level level)
+{
+	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+
+	if (pp_funcs->force_performance_level) {
+		if (adev->pm.dpm.thermal_active)
+			return -EINVAL;
+
+		if (pp_funcs->force_performance_level(adev-

powerplay.pp_handle,

drivers/gpu/drm/amd/pm/amdgpu_dpm.c +1 -0
+						      level))
Quoted 8 lines

drivers/gpu/drm/amd/pm/amdgpu_dpm.c int amdgpu_dpm_get_ecc_info(struct amdgpu_device *adev, · line 1777

Quoted 5 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +5 -0
+			return -EINVAL;
+	}
+
+	adev->pm.dpm.forced_level = level;
+

If the function is not implemented, why change the force level and return success?

[Quan, Evan] Thanks! Will update that.

Quoted 47 lines

drivers/gpu/drm/amd/pm/amdgpu_dpm.c int amdgpu_dpm_get_ecc_info(struct amdgpu_device *adev,

Quoted 13 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +12 -0
+	return 0;
+}
+
+int amdgpu_dpm_get_pp_num_states(struct amdgpu_device *adev,
+				 struct pp_states_info *states)
+{
+	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+
+	if (!pp_funcs->get_pp_num_states)
+		return -EOPNOTSUPP;
+
+	return pp_funcs->get_pp_num_states(adev->powerplay.pp_handle,

states);

drivers/gpu/drm/amd/pm/amdgpu_dpm.c int amdgpu_dpm_get_ecc_info(struct amdgpu_device *adev,

Quoted 12 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +12 -0
+}
+
+int amdgpu_dpm_dispatch_task(struct amdgpu_device *adev,
+			      enum amd_pp_task task_id,
+			      enum amd_pm_state_type *user_state)
+{
+	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+
+	if (!pp_funcs->dispatch_tasks)
+		return -EOPNOTSUPP;
+
+	return pp_funcs->dispatch_tasks(adev->powerplay.pp_handle,

task_id, user_state);

drivers/gpu/drm/amd/pm/amdgpu_dpm.c int amdgpu_dpm_get_ecc_info(struct amdgpu_device *adev,

Quoted 3 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +3 -0
+}
+
+int amdgpu_dpm_get_pp_table(struct amdgpu_device *adev, char

**table)

Quoted 16 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +16 -0
+{
+	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+
+	if (!pp_funcs->get_pp_table)
+		return 0;
+
+	return pp_funcs->get_pp_table(adev->powerplay.pp_handle, table);
+}
+
+int amdgpu_dpm_set_fine_grain_clk_vol(struct amdgpu_device *adev,
+				      uint32_t type,
+				      long *input,
+				      uint32_t size)
+{
+	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+
Quoted 8 lines

drivers/gpu/drm/amd/pm/amdgpu_dpm.c int amdgpu_dpm_get_ecc_info(struct amdgpu_device *adev, · line 1823

Quoted 3 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +3 -0
+	if (!pp_funcs->set_fine_grain_clk_vol)
+		return 0;
+

Better for this also to return -EOPNOTSUPP. There are a few other funcs below also which returns 0, instead they should return EOPNOTSUPP. Let the caller decide what to do when not supported instead of returning 'fake success'.

Quoted 1 line

[Quan, Evan] Yeah, I know some(this and others mentioned below) of

them seem with different/weird error return code. But unfortunately, that's how the original logic.

Quoted 1 line

We need to fix them in future. But for this patch series, it is not intended to

bring any real logic change.

Quoted 8 lines

What I meant is let the API implementation be standalone. Let it return EOPNOTSUPP and f that is the error code, caller retains the existing logic.

Ex:

	if (!pp_funcs->set_fine_grain_clk_vol) logic in caller is replaced by
	if (amdgpu_dpm_set_fine_grain_clk_vol() == -EOPNOTSUPP)

and then it retains the existing logic for that error code.

[Quan, Evan] OK, I see. Yep, it makes sense to me to unify the return value as EOPNOTSUPP and let the caller decide what to do. However, that may take some effort. As for now, there are bunch of APIs do not have their return value set as EOPNOTSUPP on API not implemented:
1. some report the result as succeed but actually do nothing(return 0)
2. some report other failures(like ENOENT, ENODATA, ENOSYS..)
Considering the extra efforts may needed, is it OK to stick the current design in this patch and follow that with new patches?

BR
Evan

Quoted 1,765 lines

Thanks,
Lijo

Quoted 178 lines
Quoted 178 lines
Quoted 49 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +1 -0
+	return pp_funcs->set_fine_grain_clk_vol(adev-

powerplay.pp_handle,

drivers/gpu/drm/amd/pm/amdgpu_dpm.c +16 -0
+						type,
+						input,
+						size);
+}
+
+int amdgpu_dpm_odn_edit_dpm_table(struct amdgpu_device *adev,
+				  uint32_t type,
+				  long *input,
+				  uint32_t size)
+{
+	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+
+	if (!pp_funcs->odn_edit_dpm_table)
+		return 0;
+
+	return pp_funcs->odn_edit_dpm_table(adev-

powerplay.pp_handle,

drivers/gpu/drm/amd/pm/amdgpu_dpm.c +28 -0
+					    type,
+					    input,
+					    size);
+}
+
+int amdgpu_dpm_print_clock_levels(struct amdgpu_device *adev,
+				  enum pp_clock_type type,
+				  char *buf)
+{
+	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+
+	if (!pp_funcs->print_clock_levels)
+		return 0;
+
+	return pp_funcs->print_clock_levels(adev->powerplay.pp_handle,
+					    type,
+					    buf);
+}
+
+int amdgpu_dpm_set_ppfeature_status(struct amdgpu_device *adev,
+				    uint64_t ppfeature_masks)
+{
+	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+
+	if (!pp_funcs->set_ppfeature_status)
+		return 0;
+
+	return pp_funcs->set_ppfeature_status(adev-

powerplay.pp_handle,

drivers/gpu/drm/amd/pm/amdgpu_dpm.c int amdgpu_dpm_get_ecc_info(struct amdgpu_device *adev,

Quoted 4 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +4 -0
+					      ppfeature_masks);
+}
+
+int amdgpu_dpm_get_ppfeature_status(struct amdgpu_device *adev,

char *buf)

Quoted 26 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +7 -0
+{
+	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+
+	if (!pp_funcs->get_ppfeature_status)
+		return 0;
+
+	return pp_funcs->get_ppfeature_status(adev-

powerplay.pp_handle,

drivers/gpu/drm/amd/pm/amdgpu_dpm.c +18 -0
+					      buf);
+}
+
+int amdgpu_dpm_force_clock_level(struct amdgpu_device *adev,
+				 enum pp_clock_type type,
+				 uint32_t mask)
+{
+	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+
+	if (!pp_funcs->force_clock_level)
+		return 0;
+
+	return pp_funcs->force_clock_level(adev->powerplay.pp_handle,
+					   type,
+					   mask);
+}
+
+int amdgpu_dpm_get_sclk_od(struct amdgpu_device *adev)

drivers/gpu/drm/amd/pm/amdgpu_dpm.c int amdgpu_dpm_get_ecc_info(struct amdgpu_device *adev,

Quoted 10 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +10 -0
+{
+	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+
+	if (!pp_funcs->get_sclk_od)
+		return 0;
+
+	return pp_funcs->get_sclk_od(adev->powerplay.pp_handle);
+}
+
+int amdgpu_dpm_set_sclk_od(struct amdgpu_device *adev, uint32_t

value)

Quoted 19 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +19 -0
+{
+	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+
+	if (!pp_funcs->set_sclk_od)
+		return -EOPNOTSUPP;
+
+	pp_funcs->set_sclk_od(adev->powerplay.pp_handle, value);
+
+	if (amdgpu_dpm_dispatch_task(adev,
+				     AMD_PP_TASK_READJUST_POWER_STATE,
+				     NULL) == -EOPNOTSUPP) {
+		adev->pm.dpm.current_ps = adev->pm.dpm.boot_ps;
+		amdgpu_pm_compute_clocks(adev);
+	}
+
+	return 0;
+}
+
+int amdgpu_dpm_get_mclk_od(struct amdgpu_device *adev)

drivers/gpu/drm/amd/pm/amdgpu_dpm.c int amdgpu_dpm_get_ecc_info(struct amdgpu_device *adev,

Quoted 10 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +10 -0
+{
+	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+
+	if (!pp_funcs->get_mclk_od)
+		return 0;
+
+	return pp_funcs->get_mclk_od(adev->powerplay.pp_handle);
+}
+
+int amdgpu_dpm_set_mclk_od(struct amdgpu_device *adev, uint32_t

value)

Quoted 9 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +9 -0
+{
+	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+
+	if (!pp_funcs->set_mclk_od)
+		return -EOPNOTSUPP;
+
+	pp_funcs->set_mclk_od(adev->powerplay.pp_handle, value);
+
+	if (amdgpu_dpm_dispatch_task(adev,

drivers/gpu/drm/amd/pm/amdgpu_dpm.c int amdgpu_dpm_get_ecc_info(struct amdgpu_device *adev,

Quoted 10 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +10 -0
+				     AMD_PP_TASK_READJUST_POWER_STATE,
+				     NULL) == -EOPNOTSUPP) {
+		adev->pm.dpm.current_ps = adev->pm.dpm.boot_ps;
+		amdgpu_pm_compute_clocks(adev);
+	}
+
+	return 0;
+}
+
+int amdgpu_dpm_get_power_profile_mode(struct amdgpu_device

*adev,

drivers/gpu/drm/amd/pm/amdgpu_dpm.c int amdgpu_dpm_get_ecc_info(struct amdgpu_device *adev,

Quoted 13 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +8 -0
+				      char *buf)
+{
+	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+
+	if (!pp_funcs->get_power_profile_mode)
+		return -EOPNOTSUPP;
+
+	return pp_funcs->get_power_profile_mode(adev-

powerplay.pp_handle,

drivers/gpu/drm/amd/pm/amdgpu_dpm.c +4 -0
+						buf);
+}
+
+int amdgpu_dpm_set_power_profile_mode(struct amdgpu_device

*adev,

Quoted 9 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +8 -0
+				      long *input, uint32_t size)
+{
+	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+
+	if (!pp_funcs->set_power_profile_mode)
+		return 0;
+
+	return pp_funcs->set_power_profile_mode(adev-

powerplay.pp_handle,

drivers/gpu/drm/amd/pm/amdgpu_dpm.c int amdgpu_dpm_get_ecc_info(struct amdgpu_device *adev,

Quoted 5 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +5 -0
+						input,
+						size);
+}
+
+int amdgpu_dpm_get_gpu_metrics(struct amdgpu_device *adev, void

**table)

drivers/gpu/drm/amd/pm/amdgpu_dpm.c int amdgpu_dpm_get_ecc_info(struct amdgpu_device *adev,

Quoted 7 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +7 -0
+{
+	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+
+	if (!pp_funcs->get_gpu_metrics)
+		return 0;
+
+	return pp_funcs->get_gpu_metrics(adev->powerplay.pp_handle,

table);

Quoted 3 lines
Quoted 3 lines

drivers/gpu/drm/amd/pm/amdgpu_dpm.c int amdgpu_dpm_get_ecc_info(struct amdgpu_device *adev,

Quoted 3 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +3 -0
+}
+
+int amdgpu_dpm_get_fan_control_mode(struct amdgpu_device

*adev,

Quoted 14 lines
Quoted 14 lines
Quoted 14 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +8 -0
+				    uint32_t *fan_mode)
+{
+	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+
+	if (!pp_funcs->get_fan_control_mode)
+		return -EOPNOTSUPP;
+
+	*fan_mode = pp_funcs->get_fan_control_mode(adev-

powerplay.pp_handle);

drivers/gpu/drm/amd/pm/amdgpu_dpm.c +5 -0
+
+	return 0;
+}
+
+int amdgpu_dpm_set_fan_speed_pwm(struct amdgpu_device *adev,
Quoted 8 lines
Quoted 8 lines

drivers/gpu/drm/amd/pm/amdgpu_dpm.c int amdgpu_dpm_get_ecc_info(struct amdgpu_device *adev, · line 2009

Quoted 6 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +6 -0
+				 uint32_t speed)
+{
+	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+
+	if (!pp_funcs->set_fan_speed_pwm)
+		return -EINVAL;

To be consistent, use EOPNOTSUPP when the function is not

implemented.

Quoted 1 line
Quoted 1 line

The return of EINVAL from actual function call shouldn't be mixed with

this.

Quoted 40 lines
Quoted 40 lines
Quoted 17 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +2 -0
+
+	return pp_funcs->set_fan_speed_pwm(adev-

powerplay.pp_handle, speed);

drivers/gpu/drm/amd/pm/amdgpu_dpm.c +11 -0
+}
+
+int amdgpu_dpm_get_fan_speed_pwm(struct amdgpu_device *adev,
+				 uint32_t *speed)
+{
+	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+
+	if (!pp_funcs->get_fan_speed_pwm)
+		return -EINVAL;
+
+	return pp_funcs->get_fan_speed_pwm(adev-

powerplay.pp_handle, speed);

drivers/gpu/drm/amd/pm/amdgpu_dpm.c +1 -0
+}

drivers/gpu/drm/amd/pm/amdgpu_dpm.c int amdgpu_dpm_get_ecc_info(struct amdgpu_device *adev,

Quoted 10 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +10 -0
+
+int amdgpu_dpm_get_fan_speed_rpm(struct amdgpu_device *adev,
+				 uint32_t *speed)
+{
+	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+
+	if (!pp_funcs->get_fan_speed_rpm)
+		return -EINVAL;
+
+	return pp_funcs->get_fan_speed_rpm(adev->powerplay.pp_handle,

speed);

drivers/gpu/drm/amd/pm/amdgpu_dpm.c int amdgpu_dpm_get_ecc_info(struct amdgpu_device *adev,

Quoted 11 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +11 -0
+}
+
+int amdgpu_dpm_set_fan_speed_rpm(struct amdgpu_device *adev,
+				 uint32_t speed)
+{
+	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+
+	if (!pp_funcs->set_fan_speed_rpm)
+		return -EINVAL;
+
+	return pp_funcs->set_fan_speed_rpm(adev->powerplay.pp_handle,

speed);

Quoted 3 lines
Quoted 3 lines

drivers/gpu/drm/amd/pm/amdgpu_dpm.c int amdgpu_dpm_get_ecc_info(struct amdgpu_device *adev,

Quoted 3 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +3 -0
+}
+
+int amdgpu_dpm_set_fan_control_mode(struct amdgpu_device

*adev,

Quoted 19 lines
Quoted 19 lines

drivers/gpu/drm/amd/pm/amdgpu_dpm.c int amdgpu_dpm_get_ecc_info(struct amdgpu_device *adev,

Quoted 8 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +8 -0
+				    uint32_t mode)
+{
+	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+
+	if (!pp_funcs->set_fan_control_mode)
+		return -EOPNOTSUPP;
+
+	pp_funcs->set_fan_control_mode(adev->powerplay.pp_handle,

mode);

Quoted 10 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +10 -0
+
+	return 0;
+}
+
+int amdgpu_dpm_get_power_limit(struct amdgpu_device *adev,
+			       uint32_t *limit,
+			       enum pp_power_limit_level pp_limit_level,
+			       enum pp_power_type power_type)
+{
+	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
Quoted 8 lines
Quoted 8 lines

drivers/gpu/drm/amd/pm/amdgpu_dpm.c int amdgpu_dpm_get_ecc_info(struct amdgpu_device *adev, · line 2069

Quoted 4 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +4 -0
+
+	if (!pp_funcs->get_power_limit)
+		return -ENODATA;
+

Again, this is mixing API error code based on caller's usage. In standalone implementatoin, this should also just return EOPNOTSUPP. hwmon API implementation can decide what to return when there is no

API

Quoted 18 lines
Quoted 18 lines

support.

Quoted 5 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +5 -0
+	return pp_funcs->get_power_limit(adev->powerplay.pp_handle,
+					 limit,
+					 pp_limit_level,
+					 power_type);
+}

drivers/gpu/drm/amd/pm/amdgpu_dpm.c int amdgpu_dpm_get_ecc_info(struct amdgpu_device *adev,

Quoted 10 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +10 -0
+
+int amdgpu_dpm_set_power_limit(struct amdgpu_device *adev,
+			       uint32_t limit)
+{
+	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+
+	if (!pp_funcs->set_power_limit)
+		return -EINVAL;
+
+	return pp_funcs->set_power_limit(adev->powerplay.pp_handle,

limit);

Quoted 3 lines
Quoted 3 lines

drivers/gpu/drm/amd/pm/amdgpu_dpm.c int amdgpu_dpm_get_ecc_info(struct amdgpu_device *adev,

Quoted 3 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +3 -0
+}
+
+int amdgpu_dpm_is_cclk_dpm_supported(struct amdgpu_device

*adev)

Quoted 25 lines
Quoted 25 lines

drivers/gpu/drm/amd/pm/amdgpu_dpm.c int amdgpu_dpm_get_ecc_info(struct amdgpu_device *adev,

Quoted 8 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +8 -0
+{
+	if (!is_support_sw_smu(adev))
+		return false;
+
+	return is_support_cclk_dpm(adev);
+}
+
+int amdgpu_dpm_debugfs_print_current_performance_level(struct

amdgpu_device *adev,

Quoted 9 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +8 -0
+						       struct seq_file *m)
+{
+	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+
+	if (!pp_funcs->debugfs_print_current_performance_level)
+		return -EOPNOTSUPP;
+
+	pp_funcs->debugfs_print_current_performance_level(adev-

powerplay.pp_handle,

drivers/gpu/drm/amd/pm/amdgpu_dpm.c int amdgpu_dpm_get_ecc_info(struct amdgpu_device *adev,

Quoted 6 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +6 -0
+							  m);
+
+	return 0;
+}
+
+int amdgpu_dpm_get_smu_prv_buf_details(struct amdgpu_device

*adev,

Quoted 15 lines
Quoted 7 lines
Quoted 7 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +7 -0
+				       void **addr,
+				       size_t *size)
+{
+	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+
+	if (!pp_funcs->get_smu_prv_buf_details)
+		return -ENOSYS;
Quoted 8 lines

drivers/gpu/drm/amd/pm/amdgpu_dpm.c int amdgpu_dpm_get_ecc_info(struct amdgpu_device *adev,

Quoted 8 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +2 -0
+
+	return pp_funcs->get_smu_prv_buf_details(adev-

powerplay.pp_handle,

drivers/gpu/drm/amd/pm/amdgpu_dpm.c +5 -0
+						 addr,
+						 size);
+}
+
+int amdgpu_dpm_is_overdrive_supported(struct amdgpu_device

*adev)

Quoted 174 lines
Quoted 79 lines

Review

Quoted 38 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +37 -0
+{
+	struct pp_hwmgr *hwmgr = adev->powerplay.pp_handle;
+
+	if ((is_support_sw_smu(adev) && adev->smu.od_enabled) ||
+	    (is_support_sw_smu(adev) && adev->smu.is_apu) ||
+		(!is_support_sw_smu(adev) && hwmgr->od_enabled))
+		return true;
+
+	return false;
+}
+
+int amdgpu_dpm_set_pp_table(struct amdgpu_device *adev,
+			    const char *buf,
+			    size_t size)
+{
+	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+
+	if (!pp_funcs->set_pp_table)
+		return -EOPNOTSUPP;
+
+	return pp_funcs->set_pp_table(adev->powerplay.pp_handle,
+				      buf,
+				      size);
+}
+
+int amdgpu_dpm_get_num_cpu_cores(struct amdgpu_device *adev)
+{
+	return adev->smu.cpu_core_num;
+}
+
+void amdgpu_dpm_stb_debug_fs_init(struct amdgpu_device *adev)
+{
+	if (!is_support_sw_smu(adev))
+		return;
+
+	amdgpu_smu_stb_debug_fs_init(adev);
+}
(quoted diff) +0 -0

b/drivers/gpu/drm/amd/pm/amdgpu_pm.c

drivers/gpu/drm/amd/pm/amdgpu_pm.c line 39

Quoted 11 lines

index 082539c70fd4..3382d30b5d90 100644

drivers/gpu/drm/amd/pm/amdgpu_pm.c +0 -1
@@ -34,7 +34,6 @@
   #include <linux/nospec.h>
   #include <linux/pm_runtime.h>
   #include <asm/processor.h>
-#include "hwmgr.h"
 
   static const struct cg_flag_name clocks[] = {
   	{AMD_CG_SUPPORT_GFX_FGCG, "Graphics Fine Grain Clock

Gating"},

drivers/gpu/drm/amd/pm/amdgpu_pm.c static ssize_t

Quoted 1 line
drivers/gpu/drm/amd/pm/amdgpu_pm.c +0 -0
@@ -132,7 +131,6 @@ static ssize_t

amdgpu_get_power_dpm_state(struct device *dev,

drivers/gpu/drm/amd/pm/amdgpu_pm.c static ssize_t

Quoted 8 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +0 -1
   {
   	struct drm_device *ddev = dev_get_drvdata(dev);
   	struct amdgpu_device *adev = drm_to_adev(ddev);
-	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
   	enum amd_pm_state_type pm;
   	int ret;
 
@@ -147,11 +145,7 @@ static ssize_t

amdgpu_get_power_dpm_state(struct device *dev,

drivers/gpu/drm/amd/pm/amdgpu_pm.c static ssize_t

Quoted 13 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +1 -5
   		return ret;
   	}
 
-	if (pp_funcs->get_current_power_state) {
-		pm = amdgpu_dpm_get_current_power_state(adev);
-	} else {
-		pm = adev->pm.dpm.user_state;
-	}
+	amdgpu_dpm_get_current_power_state(adev, &pm);
 
   	pm_runtime_mark_last_busy(ddev->dev);
   	pm_runtime_put_autosuspend(ddev->dev);
@@ -191,19 +185,8 @@ static ssize_t

amdgpu_set_power_dpm_state(struct device *dev,

Quoted 3 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +0 -0
   		return ret;
   	}
 
Quoted 7 lines

drivers/gpu/drm/amd/pm/amdgpu_pm.c static ssize_t amdgpu_set_power_dpm_state(struct device *dev, · line 197

Quoted 4 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +0 -4
-	if (is_support_sw_smu(adev)) {
-		mutex_lock(&adev->pm.mutex);
-		adev->pm.dpm.user_state = state;
-		mutex_unlock(&adev->pm.mutex);

Here the code just sets the state and exits. However, when moved to refactored function, it is calling pm_compute_clocks.

[Quan, Evan] Thanks! Will fix this.

BR
Evan

Quoted 84 lines

drivers/gpu/drm/amd/pm/amdgpu_pm.c static ssize_t · line 199

Quoted 3 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +0 -2
-	} else if (adev->powerplay.pp_funcs->dispatch_tasks) {
-		amdgpu_dpm_dispatch_task(adev,

AMD_PP_TASK_ENABLE_USER_STATE, &state);

drivers/gpu/drm/amd/pm/amdgpu_pm.c static ssize_t

Quoted 12 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +1 -6
-	} else {
-		mutex_lock(&adev->pm.mutex);
-		adev->pm.dpm.user_state = state;
-		mutex_unlock(&adev->pm.mutex);
+	amdgpu_dpm_set_power_state(adev, state);
 
-		amdgpu_pm_compute_clocks(adev);
-	}
   	pm_runtime_mark_last_busy(ddev->dev);
   	pm_runtime_put_autosuspend(ddev->dev);
 
@@ -290,10 +273,7 @@ static ssize_t

amdgpu_get_power_dpm_force_performance_level(struct device *dev,

drivers/gpu/drm/amd/pm/amdgpu_pm.c static ssize_t

Quoted 12 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +1 -4
   		return ret;
   	}
 
-	if (adev->powerplay.pp_funcs->get_performance_level)
-		level = amdgpu_dpm_get_performance_level(adev);
-	else
-		level = adev->pm.dpm.forced_level;
+	level = amdgpu_dpm_get_performance_level(adev);
 
   	pm_runtime_mark_last_busy(ddev->dev);
   	pm_runtime_put_autosuspend(ddev->dev);
@@ -318,7 +298,6 @@ static ssize_t

amdgpu_set_power_dpm_force_performance_level(struct device *dev,

drivers/gpu/drm/amd/pm/amdgpu_pm.c static ssize_t

Quoted 8 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +0 -1
   {
   	struct drm_device *ddev = dev_get_drvdata(dev);
   	struct amdgpu_device *adev = drm_to_adev(ddev);
-	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
   	enum amd_dpm_forced_level level;
   	enum amd_dpm_forced_level current_level;
   	int ret = 0;
@@ -358,11 +337,7 @@ static ssize_t

amdgpu_set_power_dpm_force_performance_level(struct device *dev,

drivers/gpu/drm/amd/pm/amdgpu_pm.c static ssize_t amdgpu_set_power_dpm_force_performance_level(struct device *dev,

Quoted 5 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +0 -2
   		return ret;
   	}
 
-	if (pp_funcs->get_performance_level)
-		current_level =

amdgpu_dpm_get_performance_level(adev);

drivers/gpu/drm/amd/pm/amdgpu_pm.c static ssize_t

Quoted 8 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +1 -3
-	else
-		current_level = adev->pm.dpm.forced_level;
-
+	current_level = amdgpu_dpm_get_performance_level(adev);
   	if (current_level == level) {
   		pm_runtime_mark_last_busy(ddev->dev);
   		pm_runtime_put_autosuspend(ddev->dev);
@@ -390,25 +365,12 @@ static ssize_t

amdgpu_set_power_dpm_force_performance_level(struct device *dev,

Quoted 30 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +5 -18
   		return -EINVAL;
   	}
 
-	if (pp_funcs->force_performance_level) {
-		mutex_lock(&adev->pm.mutex);
-		if (adev->pm.dpm.thermal_active) {
-			mutex_unlock(&adev->pm.mutex);
-			pm_runtime_mark_last_busy(ddev->dev);
-			pm_runtime_put_autosuspend(ddev->dev);
-			return -EINVAL;
-		}
-		ret = amdgpu_dpm_force_performance_level(adev, level);
-		if (ret) {
-			mutex_unlock(&adev->pm.mutex);
-			pm_runtime_mark_last_busy(ddev->dev);
-			pm_runtime_put_autosuspend(ddev->dev);
-			return -EINVAL;
-		} else {
-			adev->pm.dpm.forced_level = level;
-		}
-		mutex_unlock(&adev->pm.mutex);
+	if (amdgpu_dpm_force_performance_level(adev, level)) {
+		pm_runtime_mark_last_busy(ddev->dev);
+		pm_runtime_put_autosuspend(ddev->dev);
+		return -EINVAL;
   	}
+
   	pm_runtime_mark_last_busy(ddev->dev);
   	pm_runtime_put_autosuspend(ddev->dev);
 
Quoted 1 line
Quoted 1 line

drivers/gpu/drm/amd/pm/amdgpu_pm.c static ssize_t

Quoted 1 line
drivers/gpu/drm/amd/pm/amdgpu_pm.c +0 -0
@@ -421,7 +383,6 @@ static ssize_t

amdgpu_get_pp_num_states(struct

Quoted 9 lines
Quoted 9 lines

device *dev,

drivers/gpu/drm/amd/pm/amdgpu_pm.c static ssize_t

Quoted 8 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +0 -1
   {
   	struct drm_device *ddev = dev_get_drvdata(dev);
   	struct amdgpu_device *adev = drm_to_adev(ddev);
-	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
   	struct pp_states_info data;
   	uint32_t i;
   	int buf_len, ret;
@@ -437,11 +398,8 @@ static ssize_t

amdgpu_get_pp_num_states(struct

Quoted 47 lines
Quoted 47 lines

device *dev,

drivers/gpu/drm/amd/pm/amdgpu_pm.c static ssize_t amdgpu_get_pp_cur_state(struct

Quoted 13 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +1 -4
   		return ret;
   	}
 
-	if (pp_funcs->get_pp_num_states) {
-		amdgpu_dpm_get_pp_num_states(adev, &data);
-	} else {
+	if (amdgpu_dpm_get_pp_num_states(adev, &data))
   		memset(&data, 0, sizeof(data));
-	}
 
   	pm_runtime_mark_last_busy(ddev->dev);
   	pm_runtime_put_autosuspend(ddev->dev);
@@ -463,7 +421,6 @@ static ssize_t amdgpu_get_pp_cur_state(struct

device *dev,

drivers/gpu/drm/amd/pm/amdgpu_pm.c static ssize_t amdgpu_get_pp_cur_state(struct

Quoted 8 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +0 -1
   {
   	struct drm_device *ddev = dev_get_drvdata(dev);
   	struct amdgpu_device *adev = drm_to_adev(ddev);
-	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
   	struct pp_states_info data = {0};
   	enum amd_pm_state_type pm = 0;
   	int i = 0, ret = 0;
@@ -479,15 +436,16 @@ static ssize_t amdgpu_get_pp_cur_state(struct

device *dev,

drivers/gpu/drm/amd/pm/amdgpu_pm.c static ssize_t amdgpu_set_pp_force_state(struct

Quoted 22 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +6 -5
   		return ret;
   	}
 
-	if (pp_funcs->get_current_power_state
-		 && pp_funcs->get_pp_num_states) {
-		pm = amdgpu_dpm_get_current_power_state(adev);
-		amdgpu_dpm_get_pp_num_states(adev, &data);
-	}
+	amdgpu_dpm_get_current_power_state(adev, &pm);
+
+	ret = amdgpu_dpm_get_pp_num_states(adev, &data);
 
   	pm_runtime_mark_last_busy(ddev->dev);
   	pm_runtime_put_autosuspend(ddev->dev);
 
+	if (ret)
+		return ret;
+
   	for (i = 0; i < data.nums; i++) {
   		if (pm == data.states[i])
   			break;
@@ -525,6 +483,7 @@ static ssize_t amdgpu_set_pp_force_state(struct

device *dev,

Quoted 8 lines
Quoted 8 lines

drivers/gpu/drm/amd/pm/amdgpu_pm.c static ssize_t

Quoted 8 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +1 -0
   	struct drm_device *ddev = dev_get_drvdata(dev);
   	struct amdgpu_device *adev = drm_to_adev(ddev);
   	enum amd_pm_state_type state = 0;
+	struct pp_states_info data;
   	unsigned long idx;
   	int ret;
 
@@ -533,41 +492,49 @@ static ssize_t

amdgpu_set_pp_force_state(struct

Quoted 78 lines
Quoted 78 lines

device *dev,

Quoted 28 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +6 -16
   	if (adev->in_suspend && !adev->in_runpm)
   		return -EPERM;
 
-	if (strlen(buf) == 1)
-		adev->pp_force_state_enabled = false;
-	else if (is_support_sw_smu(adev))
-		adev->pp_force_state_enabled = false;
-	else if (adev->powerplay.pp_funcs->dispatch_tasks &&
-			adev->powerplay.pp_funcs->get_pp_num_states) {
-		struct pp_states_info data;
-
-		ret = kstrtoul(buf, 0, &idx);
-		if (ret || idx >= ARRAY_SIZE(data.states))
-			return -EINVAL;
+	adev->pp_force_state_enabled = false;
 
-		idx = array_index_nospec(idx, ARRAY_SIZE(data.states));
+	if (strlen(buf) == 1)
+		return count;
 
-		amdgpu_dpm_get_pp_num_states(adev, &data);
-		state = data.states[idx];
+	ret = kstrtoul(buf, 0, &idx);
+	if (ret || idx >= ARRAY_SIZE(data.states))
+		return -EINVAL;
 
-		ret = pm_runtime_get_sync(ddev->dev);
-		if (ret < 0) {

drivers/gpu/drm/amd/pm/amdgpu_pm.c static ssize_t amdgpu_set_pp_force_state(struct device *dev,

Quoted 10 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +1 -8
-			pm_runtime_put_autosuspend(ddev->dev);
-			return ret;
-		}
+	idx = array_index_nospec(idx, ARRAY_SIZE(data.states));
 
-		/* only set user selected power states */
-		if (state != POWER_STATE_TYPE_INTERNAL_BOOT &&
-		    state != POWER_STATE_TYPE_DEFAULT) {
-			amdgpu_dpm_dispatch_task(adev,
-
	AMD_PP_TASK_ENABLE_USER_STATE, &state);
Quoted 10 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +6 -3
-			adev->pp_force_state_enabled = true;
-		}
-		pm_runtime_mark_last_busy(ddev->dev);
+	ret = pm_runtime_get_sync(ddev->dev);
+	if (ret < 0) {
   		pm_runtime_put_autosuspend(ddev->dev);
+		return ret;
+	}
+
+	ret = amdgpu_dpm_get_pp_num_states(adev, &data);

drivers/gpu/drm/amd/pm/amdgpu_pm.c static ssize_t amdgpu_set_pp_force_state(struct device *dev,

Quoted 10 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +10 -0
+	if (ret)
+		goto err_out;
+
+	state = data.states[idx];
+
+	/* only set user selected power states */
+	if (state != POWER_STATE_TYPE_INTERNAL_BOOT &&
+	    state != POWER_STATE_TYPE_DEFAULT) {
+		ret = amdgpu_dpm_dispatch_task(adev,
+				AMD_PP_TASK_ENABLE_USER_STATE,

&state);

Quoted 17 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +12 -0
+		if (ret)
+			goto err_out;
+
+		adev->pp_force_state_enabled = true;
   	}
 
+	pm_runtime_mark_last_busy(ddev->dev);
+	pm_runtime_put_autosuspend(ddev->dev);
+
   	return count;
+
+err_out:
+	pm_runtime_mark_last_busy(ddev->dev);
+	pm_runtime_put_autosuspend(ddev->dev);
+	return ret;
   }
 
Quoted 2 lines
Quoted 2 lines

drivers/gpu/drm/amd/pm/amdgpu_pm.c static ssize_t amdgpu_get_pp_table(struct

Quoted 2 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +0 -0
   /**
@@ -601,17 +568,13 @@ static ssize_t amdgpu_get_pp_table(struct

device

Quoted 23 lines
Quoted 23 lines

*dev,

Quoted 22 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +7 -11
   		return ret;
   	}
 
-	if (adev->powerplay.pp_funcs->get_pp_table) {
-		size = amdgpu_dpm_get_pp_table(adev, &table);
-		pm_runtime_mark_last_busy(ddev->dev);
-		pm_runtime_put_autosuspend(ddev->dev);
-		if (size < 0)
-			return size;
-	} else {
-		pm_runtime_mark_last_busy(ddev->dev);
-		pm_runtime_put_autosuspend(ddev->dev);
-		return 0;
-	}
+	size = amdgpu_dpm_get_pp_table(adev, &table);
+
+	pm_runtime_mark_last_busy(ddev->dev);
+	pm_runtime_put_autosuspend(ddev->dev);
+
+	if (size <= 0)
+		return size;
 
Quoted 3 lines
Quoted 3 lines

drivers/gpu/drm/amd/pm/amdgpu_pm.c static ssize_t amdgpu_set_pp_table(struct

Quoted 3 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +0 -0
   	if (size >= PAGE_SIZE)
   		size = PAGE_SIZE - 1;
@@ -642,15 +605,13 @@ static ssize_t amdgpu_set_pp_table(struct

device

Quoted 148 lines
Quoted 148 lines

*dev,

drivers/gpu/drm/amd/pm/amdgpu_pm.c static ssize_t

Quoted 19 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +3 -5
   	}
 
   	ret = amdgpu_dpm_set_pp_table(adev, buf, count);
-	if (ret) {
-		pm_runtime_mark_last_busy(ddev->dev);
-		pm_runtime_put_autosuspend(ddev->dev);
-		return ret;
-	}
 
   	pm_runtime_mark_last_busy(ddev->dev);
   	pm_runtime_put_autosuspend(ddev->dev);
 
+	if (ret)
+		return ret;
+
   	return count;
   }
 
@@ -866,46 +827,32 @@ static ssize_t

amdgpu_set_pp_od_clk_voltage(struct device *dev,

Quoted 12 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +0 -9
   		return ret;
   	}
 
-	if (adev->powerplay.pp_funcs->set_fine_grain_clk_vol) {
-		ret = amdgpu_dpm_set_fine_grain_clk_vol(adev, type,
-							parameter,
-							parameter_size);
-		if (ret) {
-			pm_runtime_mark_last_busy(ddev->dev);
-			pm_runtime_put_autosuspend(ddev->dev);
-			return -EINVAL;
-		}

drivers/gpu/drm/amd/pm/amdgpu_pm.c static ssize_t amdgpu_set_pp_od_clk_voltage(struct device *dev,

Quoted 10 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +5 -4
-	}
+	if (amdgpu_dpm_set_fine_grain_clk_vol(adev,
+					      type,
+					      parameter,
+					      parameter_size))
+		goto err_out;
 
-	if (adev->powerplay.pp_funcs->odn_edit_dpm_table) {
-		ret = amdgpu_dpm_odn_edit_dpm_table(adev, type,
-						    parameter,

parameter_size);

drivers/gpu/drm/amd/pm/amdgpu_pm.c static ssize_t amdgpu_set_pp_od_clk_voltage(struct device *dev, · line 839

Quoted 10 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +3 -6
-		if (ret) {
-			pm_runtime_mark_last_busy(ddev->dev);
-			pm_runtime_put_autosuspend(ddev->dev);
-			return -EINVAL;
-		}
-	}
+	if (amdgpu_dpm_odn_edit_dpm_table(adev, type,
+					  parameter, parameter_size))
+		goto err_out;
 

This is one example of returning 'fake success' effect. If the function is not implemented it proceeds. There is no need to proceed if there is no support.

Thanks,
Lijo

drivers/gpu/drm/amd/pm/amdgpu_pm.c static ssize_t amdgpu_set_pp_od_clk_voltage(struct device *dev,

Quoted 4 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +0 -3
   	if (type == PP_OD_COMMIT_DPM_TABLE) {
-		if (adev->powerplay.pp_funcs->dispatch_tasks) {
-			amdgpu_dpm_dispatch_task(adev,
-

AMD_PP_TASK_READJUST_POWER_STATE,

drivers/gpu/drm/amd/pm/amdgpu_pm.c static ssize_t amdgpu_set_pp_od_clk_voltage(struct device *dev, · line 851

Quoted 11 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +2 -9
-						 NULL);
-			pm_runtime_mark_last_busy(ddev->dev);
-			pm_runtime_put_autosuspend(ddev->dev);
-			return count;
-		} else {
-			pm_runtime_mark_last_busy(ddev->dev);
-			pm_runtime_put_autosuspend(ddev->dev);
-			return -EINVAL;
-		}
+		if (amdgpu_dpm_dispatch_task(adev,
+

AMD_PP_TASK_READJUST_POWER_STATE,

drivers/gpu/drm/amd/pm/amdgpu_pm.c static ssize_t

Quoted 17 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +7 -0
+					     NULL))
+			goto err_out;
   	}
 
   	pm_runtime_mark_last_busy(ddev->dev);
   	pm_runtime_put_autosuspend(ddev->dev);
 
   	return count;
+
+err_out:
+	pm_runtime_mark_last_busy(ddev->dev);
+	pm_runtime_put_autosuspend(ddev->dev);
+	return -EINVAL;
   }
 
   static ssize_t amdgpu_get_pp_od_clk_voltage(struct device *dev,
@@ -928,8 +875,8 @@ static ssize_t

amdgpu_get_pp_od_clk_voltage(struct device *dev,

drivers/gpu/drm/amd/pm/amdgpu_pm.c static ssize_t amdgpu_get_pp_od_clk_voltage(struct device *dev,

Quoted 8 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +2 -2
   		return ret;
   	}
 
-	if (adev->powerplay.pp_funcs->print_clock_levels) {
-		size = amdgpu_dpm_print_clock_levels(adev, OD_SCLK, buf);
+	size = amdgpu_dpm_print_clock_levels(adev, OD_SCLK, buf);
+	if (size > 0) {
   		size += amdgpu_dpm_print_clock_levels(adev, OD_MCLK,

buf+size);

drivers/gpu/drm/amd/pm/amdgpu_pm.c static ssize_t · line 881

Quoted 1 line
drivers/gpu/drm/amd/pm/amdgpu_pm.c +0 -0
   		size += amdgpu_dpm_print_clock_levels(adev,

OD_VDDC_CURVE, buf+size);

drivers/gpu/drm/amd/pm/amdgpu_pm.c static ssize_t · line 882

Quoted 1 line
drivers/gpu/drm/amd/pm/amdgpu_pm.c +0 -0
   		size += amdgpu_dpm_print_clock_levels(adev,

OD_VDDGFX_OFFSET, buf+size);

drivers/gpu/drm/amd/pm/amdgpu_pm.c static ssize_t amdgpu_set_pp_features(struct

Quoted 1 line
drivers/gpu/drm/amd/pm/amdgpu_pm.c +0 -0
@@ -985,17 +932,14 @@ static ssize_t amdgpu_set_pp_features(struct

device *dev,

drivers/gpu/drm/amd/pm/amdgpu_pm.c static ssize_t amdgpu_set_pp_features(struct device *dev,

Quoted 5 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +0 -2
   		return ret;
   	}
 
-	if (adev->powerplay.pp_funcs->set_ppfeature_status) {
-		ret = amdgpu_dpm_set_ppfeature_status(adev,

featuremask);

drivers/gpu/drm/amd/pm/amdgpu_pm.c static ssize_t amdgpu_get_pp_features(struct

Quoted 18 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +5 -6
-		if (ret) {
-			pm_runtime_mark_last_busy(ddev->dev);
-			pm_runtime_put_autosuspend(ddev->dev);
-			return -EINVAL;
-		}
-	}
+	ret = amdgpu_dpm_set_ppfeature_status(adev, featuremask);
+
   	pm_runtime_mark_last_busy(ddev->dev);
   	pm_runtime_put_autosuspend(ddev->dev);
 
+	if (ret)
+		return -EINVAL;
+
   	return count;
   }
 
@@ -1019,9 +963,8 @@ static ssize_t amdgpu_get_pp_features(struct

device *dev,

Quoted 10 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +2 -3
   		return ret;
   	}
 
-	if (adev->powerplay.pp_funcs->get_ppfeature_status)
-		size = amdgpu_dpm_get_ppfeature_status(adev, buf);
-	else
+	size = amdgpu_dpm_get_ppfeature_status(adev, buf);
+	if (size <= 0)
   		size = sysfs_emit(buf, "\n");
 
Quoted 2 lines
Quoted 2 lines

drivers/gpu/drm/amd/pm/amdgpu_pm.c static ssize_t

Quoted 2 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +0 -0
   	pm_runtime_mark_last_busy(ddev->dev);
@@ -1080,9 +1023,8 @@ static ssize_t

amdgpu_get_pp_dpm_clock(struct

Quoted 11 lines
Quoted 11 lines

device *dev,

Quoted 10 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +2 -3
   		return ret;
   	}
 
-	if (adev->powerplay.pp_funcs->print_clock_levels)
-		size = amdgpu_dpm_print_clock_levels(adev, type, buf);
-	else
+	size = amdgpu_dpm_print_clock_levels(adev, type, buf);
+	if (size <= 0)
   		size = sysfs_emit(buf, "\n");
 
Quoted 2 lines
Quoted 2 lines

drivers/gpu/drm/amd/pm/amdgpu_pm.c static ssize_t

Quoted 2 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +0 -0
   	pm_runtime_mark_last_busy(ddev->dev);
@@ -1151,10 +1093,7 @@ static ssize_t

amdgpu_set_pp_dpm_clock(struct

Quoted 47 lines
Quoted 47 lines

device *dev,

drivers/gpu/drm/amd/pm/amdgpu_pm.c static ssize_t amdgpu_get_pp_sclk_od(struct

Quoted 12 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +1 -4
   		return ret;
   	}
 
-	if (adev->powerplay.pp_funcs->force_clock_level)
-		ret = amdgpu_dpm_force_clock_level(adev, type, mask);
-	else
-		ret = 0;
+	ret = amdgpu_dpm_force_clock_level(adev, type, mask);
 
   	pm_runtime_mark_last_busy(ddev->dev);
   	pm_runtime_put_autosuspend(ddev->dev);
@@ -1305,10 +1244,7 @@ static ssize_t amdgpu_get_pp_sclk_od(struct

device *dev,

drivers/gpu/drm/amd/pm/amdgpu_pm.c static ssize_t amdgpu_set_pp_sclk_od(struct

Quoted 12 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +1 -4
   		return ret;
   	}
 
-	if (is_support_sw_smu(adev))
-		value = 0;
-	else if (adev->powerplay.pp_funcs->get_sclk_od)
-		value = amdgpu_dpm_get_sclk_od(adev);
+	value = amdgpu_dpm_get_sclk_od(adev);
 
   	pm_runtime_mark_last_busy(ddev->dev);
   	pm_runtime_put_autosuspend(ddev->dev);
@@ -1342,19 +1278,7 @@ static ssize_t amdgpu_set_pp_sclk_od(struct

device *dev,

drivers/gpu/drm/amd/pm/amdgpu_pm.c static ssize_t amdgpu_set_pp_sclk_od(struct device *dev,

Quoted 11 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +0 -8
   		return ret;
   	}
 
-	if (is_support_sw_smu(adev)) {
-		value = 0;
-	} else {
-		if (adev->powerplay.pp_funcs->set_sclk_od)
-			amdgpu_dpm_set_sclk_od(adev, (uint32_t)value);
-
-		if (adev->powerplay.pp_funcs->dispatch_tasks) {
-			amdgpu_dpm_dispatch_task(adev,

AMD_PP_TASK_READJUST_POWER_STATE, NULL);

Quoted 8 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +1 -5
-		} else {
-			adev->pm.dpm.current_ps = adev-
 pm.dpm.boot_ps;
-			amdgpu_pm_compute_clocks(adev);
-		}
-	}
+	amdgpu_dpm_set_sclk_od(adev, (uint32_t)value);
 
Quoted 3 lines
Quoted 3 lines

drivers/gpu/drm/amd/pm/amdgpu_pm.c static ssize_t

Quoted 3 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +0 -0
   	pm_runtime_mark_last_busy(ddev->dev);
   	pm_runtime_put_autosuspend(ddev->dev);
drivers/gpu/drm/amd/pm/amdgpu_pm.c +0 -0
@@ -1382,10 +1306,7 @@ static ssize_t

amdgpu_get_pp_mclk_od(struct

Quoted 386 lines
Quoted 386 lines

device *dev,

drivers/gpu/drm/amd/pm/amdgpu_pm.c static ssize_t amdgpu_set_pp_mclk_od(struct

Quoted 12 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +1 -4
   		return ret;
   	}
 
-	if (is_support_sw_smu(adev))
-		value = 0;
-	else if (adev->powerplay.pp_funcs->get_mclk_od)
-		value = amdgpu_dpm_get_mclk_od(adev);
+	value = amdgpu_dpm_get_mclk_od(adev);
 
   	pm_runtime_mark_last_busy(ddev->dev);
   	pm_runtime_put_autosuspend(ddev->dev);
@@ -1419,19 +1340,7 @@ static ssize_t amdgpu_set_pp_mclk_od(struct

device *dev,

drivers/gpu/drm/amd/pm/amdgpu_pm.c static ssize_t amdgpu_set_pp_mclk_od(struct device *dev,

Quoted 11 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +0 -8
   		return ret;
   	}
 
-	if (is_support_sw_smu(adev)) {
-		value = 0;
-	} else {
-		if (adev->powerplay.pp_funcs->set_mclk_od)
-			amdgpu_dpm_set_mclk_od(adev, (uint32_t)value);
-
-		if (adev->powerplay.pp_funcs->dispatch_tasks) {
-			amdgpu_dpm_dispatch_task(adev,

AMD_PP_TASK_READJUST_POWER_STATE, NULL);

drivers/gpu/drm/amd/pm/amdgpu_pm.c static ssize_t

Quoted 11 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +1 -5
-		} else {
-			adev->pm.dpm.current_ps = adev-
 pm.dpm.boot_ps;
-			amdgpu_pm_compute_clocks(adev);
-		}
-	}
+	amdgpu_dpm_set_mclk_od(adev, (uint32_t)value);
 
   	pm_runtime_mark_last_busy(ddev->dev);
   	pm_runtime_put_autosuspend(ddev->dev);
drivers/gpu/drm/amd/pm/amdgpu_pm.c +0 -0
@@ -1479,9 +1388,8 @@ static ssize_t

amdgpu_get_pp_power_profile_mode(struct device *dev,

drivers/gpu/drm/amd/pm/amdgpu_pm.c static ssize_t

Quoted 12 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +2 -3
   		return ret;
   	}
 
-	if (adev->powerplay.pp_funcs->get_power_profile_mode)
-		size = amdgpu_dpm_get_power_profile_mode(adev, buf);
-	else
+	size = amdgpu_dpm_get_power_profile_mode(adev, buf);
+	if (size <= 0)
   		size = sysfs_emit(buf, "\n");
 
   	pm_runtime_mark_last_busy(ddev->dev);
@@ -1545,8 +1453,7 @@ static ssize_t

amdgpu_set_pp_power_profile_mode(struct device *dev,

drivers/gpu/drm/amd/pm/amdgpu_pm.c static ssize_t amdgpu_set_pp_power_profile_mode(struct device *dev,

Quoted 5 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +0 -2
   		return ret;
   	}
 
-	if (adev->powerplay.pp_funcs->set_power_profile_mode)
-		ret = amdgpu_dpm_set_power_profile_mode(adev,

parameter, parameter_size);

drivers/gpu/drm/amd/pm/amdgpu_pm.c static ssize_t · line 1456

Quoted 1 line
drivers/gpu/drm/amd/pm/amdgpu_pm.c +1 -0
+	ret = amdgpu_dpm_set_power_profile_mode(adev, parameter,

parameter_size);

drivers/gpu/drm/amd/pm/amdgpu_pm.c static ssize_t amdgpu_get_gpu_metrics(struct

Quoted 4 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +0 -0
   	pm_runtime_mark_last_busy(ddev->dev);
   	pm_runtime_put_autosuspend(ddev->dev);
@@ -1812,9 +1719,7 @@ static ssize_t amdgpu_get_gpu_metrics(struct

device *dev,

drivers/gpu/drm/amd/pm/amdgpu_pm.c static int default_attr_update(struct

Quoted 11 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +1 -3
   		return ret;
   	}
 
-	if (adev->powerplay.pp_funcs->get_gpu_metrics)
-		size = amdgpu_dpm_get_gpu_metrics(adev, &gpu_metrics);
-
+	size = amdgpu_dpm_get_gpu_metrics(adev, &gpu_metrics);
   	if (size <= 0)
   		goto out;
 
@@ -2053,7 +1958,6 @@ static int default_attr_update(struct

amdgpu_device *adev, struct amdgpu_device_

drivers/gpu/drm/amd/pm/amdgpu_pm.c static int default_attr_update(struct

Quoted 8 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +0 -1
   {
   	struct device_attribute *dev_attr = &attr->dev_attr;
   	const char *attr_name = dev_attr->attr.name;
-	struct pp_hwmgr *hwmgr = adev->powerplay.pp_handle;
   	enum amd_asic_type asic_type = adev->asic_type;
 
   	if (!(attr->flags & mask)) {
@@ -2076,9 +1980,7 @@ static int default_attr_update(struct

amdgpu_device *adev, struct amdgpu_device_

drivers/gpu/drm/amd/pm/amdgpu_pm.c static int default_attr_update(struct amdgpu_device *adev, struct amdgpu_device_

Quoted 4 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +0 -1
   			*states = ATTR_STATE_UNSUPPORTED;
   	} else if (DEVICE_ATTR_IS(pp_od_clk_voltage)) {
   		*states = ATTR_STATE_UNSUPPORTED;
-		if ((is_support_sw_smu(adev) && adev->smu.od_enabled)
||
> -		    (is_support_sw_smu(adev) && adev->smu.is_apu) ||

drivers/gpu/drm/amd/pm/amdgpu_pm.c static int default_attr_update(struct

Quoted 7 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +1 -1
-			(!is_support_sw_smu(adev) && hwmgr-
 od_enabled))
+		if (amdgpu_dpm_is_overdrive_supported(adev))
   			*states = ATTR_STATE_SUPPORTED;
   	} else if (DEVICE_ATTR_IS(mem_busy_percent)) {
   		if (adev->flags & AMD_IS_APU || asic_type == CHIP_VEGA10)
@@ -2105,8 +2007,7 @@ static int default_attr_update(struct

amdgpu_device *adev, struct amdgpu_device_

drivers/gpu/drm/amd/pm/amdgpu_pm.c static int default_attr_update(struct · line 2007

Quoted 1 line
drivers/gpu/drm/amd/pm/amdgpu_pm.c +0 -0
   		if (!(asic_type == CHIP_VANGOGH || asic_type ==

CHIP_SIENNA_CICHLID))

drivers/gpu/drm/amd/pm/amdgpu_pm.c static int default_attr_update(struct amdgpu_device *adev, struct amdgpu_device_

Quoted 3 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +0 -1
   			*states = ATTR_STATE_UNSUPPORTED;
   	} else if (DEVICE_ATTR_IS(pp_power_profile_mode)) {
-		if (!adev->powerplay.pp_funcs->get_power_profile_mode
||
> -		    amdgpu_dpm_get_power_profile_mode(adev, NULL) == -

EOPNOTSUPP)

drivers/gpu/drm/amd/pm/amdgpu_pm.c static int default_attr_update(struct · line 2010

Quoted 1 line
drivers/gpu/drm/amd/pm/amdgpu_pm.c +1 -0
+		if (amdgpu_dpm_get_power_profile_mode(adev, NULL) ==

-EOPNOTSUPP)

drivers/gpu/drm/amd/pm/amdgpu_pm.c static ssize_t

Quoted 4 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +0 -0
   			*states = ATTR_STATE_UNSUPPORTED;
   	}
 
@@ -2389,17 +2290,14 @@ static ssize_t

amdgpu_hwmon_get_pwm1_enable(struct device *dev,

drivers/gpu/drm/amd/pm/amdgpu_pm.c static ssize_t

Quoted 22 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +4 -7
   		return ret;
   	}
 
-	if (!adev->powerplay.pp_funcs->get_fan_control_mode) {
-		pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
-		pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
-		return -EINVAL;
-	}
-
-	pwm_mode = amdgpu_dpm_get_fan_control_mode(adev);
+	ret = amdgpu_dpm_get_fan_control_mode(adev, &pwm_mode);
 
   	pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
   	pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
 
+	if (ret)
+		return -EINVAL;
+
   	return sysfs_emit(buf, "%u\n", pwm_mode);
   }
 
@@ -2427,17 +2325,14 @@ static ssize_t

amdgpu_hwmon_set_pwm1_enable(struct device *dev,

drivers/gpu/drm/amd/pm/amdgpu_pm.c static ssize_t

Quoted 22 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +4 -7
   		return ret;
   	}
 
-	if (!adev->powerplay.pp_funcs->set_fan_control_mode) {
-		pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
-		pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
-		return -EINVAL;
-	}
-
-	amdgpu_dpm_set_fan_control_mode(adev, value);
+	ret = amdgpu_dpm_set_fan_control_mode(adev, value);
 
   	pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
   	pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
 
+	if (ret)
+		return -EINVAL;
+
   	return count;
   }
 
@@ -2469,32 +2364,29 @@ static ssize_t

amdgpu_hwmon_set_pwm1(struct device *dev,

Quoted 10 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +4 -0
   	if (adev->in_suspend && !adev->in_runpm)
   		return -EPERM;
 
+	err = kstrtou32(buf, 10, &value);
+	if (err)
+		return err;
+
   	err = pm_runtime_get_sync(adev_to_drm(adev)->dev);
   	if (err < 0) {
   		pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);

drivers/gpu/drm/amd/pm/amdgpu_pm.c static ssize_t amdgpu_hwmon_set_pwm1(struct device *dev,

Quoted 10 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +4 -1
   		return err;
   	}
 
-	pwm_mode = amdgpu_dpm_get_fan_control_mode(adev);
+	err = amdgpu_dpm_get_fan_control_mode(adev, &pwm_mode);
+	if (err)
+		goto out;
+
   	if (pwm_mode != AMD_FAN_CTRL_MANUAL) {
   		pr_info("manual fan speed control should be enabled

first\n");

drivers/gpu/drm/amd/pm/amdgpu_pm.c static ssize_t

Quoted 25 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +4 -14
-		pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
-		pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
-		return -EINVAL;
+		err = -EINVAL;
+		goto out;
   	}
 
-	err = kstrtou32(buf, 10, &value);
-	if (err) {
-		pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
-		pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
-		return err;
-	}
-
-	if (adev->powerplay.pp_funcs->set_fan_speed_pwm)
-		err = amdgpu_dpm_set_fan_speed_pwm(adev, value);
-	else
-		err = -EINVAL;
+	err = amdgpu_dpm_set_fan_speed_pwm(adev, value);
 
+out:
   	pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
   	pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
 
@@ -2523,10 +2415,7 @@ static ssize_t

amdgpu_hwmon_get_pwm1(struct device *dev,

drivers/gpu/drm/amd/pm/amdgpu_pm.c static ssize_t

Quoted 12 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +1 -4
   		return err;
   	}
 
-	if (adev->powerplay.pp_funcs->get_fan_speed_pwm)
-		err = amdgpu_dpm_get_fan_speed_pwm(adev, &speed);
-	else
-		err = -EINVAL;
+	err = amdgpu_dpm_get_fan_speed_pwm(adev, &speed);
 
   	pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
   	pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
@@ -2556,10 +2445,7 @@ static ssize_t

amdgpu_hwmon_get_fan1_input(struct device *dev,

drivers/gpu/drm/amd/pm/amdgpu_pm.c static ssize_t

Quoted 12 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +1 -4
   		return err;
   	}
 
-	if (adev->powerplay.pp_funcs->get_fan_speed_rpm)
-		err = amdgpu_dpm_get_fan_speed_rpm(adev, &speed);
-	else
-		err = -EINVAL;
+	err = amdgpu_dpm_get_fan_speed_rpm(adev, &speed);
 
   	pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
   	pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
@@ -2653,10 +2539,7 @@ static ssize_t

amdgpu_hwmon_get_fan1_target(struct device *dev,

drivers/gpu/drm/amd/pm/amdgpu_pm.c static ssize_t

Quoted 12 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +1 -4
   		return err;
   	}
 
-	if (adev->powerplay.pp_funcs->get_fan_speed_rpm)
-		err = amdgpu_dpm_get_fan_speed_rpm(adev, &rpm);
-	else
-		err = -EINVAL;
+	err = amdgpu_dpm_get_fan_speed_rpm(adev, &rpm);
 
   	pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
   	pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
@@ -2681,32 +2564,28 @@ static ssize_t

amdgpu_hwmon_set_fan1_target(struct device *dev,

drivers/gpu/drm/amd/pm/amdgpu_pm.c static ssize_t

Quoted 44 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +11 -15
   	if (adev->in_suspend && !adev->in_runpm)
   		return -EPERM;
 
+	err = kstrtou32(buf, 10, &value);
+	if (err)
+		return err;
+
   	err = pm_runtime_get_sync(adev_to_drm(adev)->dev);
   	if (err < 0) {
   		pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
   		return err;
   	}
 
-	pwm_mode = amdgpu_dpm_get_fan_control_mode(adev);
+	err = amdgpu_dpm_get_fan_control_mode(adev, &pwm_mode);
+	if (err)
+		goto out;
 
   	if (pwm_mode != AMD_FAN_CTRL_MANUAL) {
-		pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
-		pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
-		return -ENODATA;
[… more lines in the raw message]
@@ -2735,17 +2614,14 @@ static ssize_t

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

amdgpu_hwmon_get_fan1_enable(struct device *dev,

drivers/gpu/drm/amd/pm/amdgpu_pm.c

Quoted 19 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +4 -7

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

AMD_FAN_CTRL_AUTO ? 0 : 1);

drivers/gpu/drm/amd/pm/amdgpu_pm.c static ssize_t

Quoted 3 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +0 -0
@@ -2781,16 +2657,14 @@ static ssize_t

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

amdgpu_hwmon_set_fan1_enable(struct device *dev,

drivers/gpu/drm/amd/pm/amdgpu_pm.c static ssize_t

Quoted 21 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +4 -6
@@ -2926,7 +2800,6 @@ static ssize_t

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

amdgpu_hwmon_show_power_cap_generic(struct device *dev,

drivers/gpu/drm/amd/pm/amdgpu_pm.c

Quoted 1 line
drivers/gpu/drm/amd/pm/amdgpu_pm.c +0 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

pp_limit_level)

drivers/gpu/drm/amd/pm/amdgpu_pm.c static ssize_t

Quoted 8 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +0 -1

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

   	ssize_t size;
drivers/gpu/drm/amd/pm/amdgpu_pm.c +0 -0
@@ -2937,16 +2810,13 @@ static ssize_t

amdgpu_hwmon_show_power_cap_generic(struct device *dev,

drivers/gpu/drm/amd/pm/amdgpu_pm.c static ssize_t

Quoted 18 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +1 -4
@@ -3001,7 +2871,6 @@ static ssize_t

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

amdgpu_hwmon_set_power_cap(struct device *dev,

drivers/gpu/drm/amd/pm/amdgpu_pm.c static ssize_t

Quoted 8 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +0 -1
@@ -3027,10 +2896,7 @@ static ssize_t

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

amdgpu_hwmon_set_power_cap(struct device *dev,

Quoted 10 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +1 -4

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Quoted 3 lines
Quoted 3 lines

drivers/gpu/drm/amd/pm/amdgpu_pm.c static umode_t

Quoted 3 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +0 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

   	pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
drivers/gpu/drm/amd/pm/amdgpu_pm.c +0 -0
@@ -3303,6 +3169,7 @@ static umode_t

hwmon_attributes_visible(struct

Quoted 315 lines
Quoted 315 lines

kobject *kobj,

drivers/gpu/drm/amd/pm/amdgpu_pm.c

Quoted 6 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +1 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

*/

drivers/gpu/drm/amd/pm/amdgpu_pm.c static umode_t

Quoted 2 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +0 -0
@@ -3367,20 +3234,18 @@ static umode_t

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

hwmon_attributes_visible(struct kobject *kobj,

drivers/gpu/drm/amd/pm/amdgpu_pm.c

Quoted 5 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +0 -2

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

expose */

drivers/gpu/drm/amd/pm/amdgpu_pm.c

Quoted 2 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +0 -2

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

query fan */

drivers/gpu/drm/amd/pm/amdgpu_pm.c

Quoted 2 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +0 -2

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

/* can't query state */

drivers/gpu/drm/amd/pm/amdgpu_pm.c

Quoted 2 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +1 -1

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

*/

drivers/gpu/drm/amd/pm/amdgpu_pm.c

Quoted 1 line
drivers/gpu/drm/amd/pm/amdgpu_pm.c +1 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

&&

drivers/gpu/drm/amd/pm/amdgpu_pm.c

Quoted 1 line
drivers/gpu/drm/amd/pm/amdgpu_pm.c +1 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

fan */

drivers/gpu/drm/amd/pm/amdgpu_pm.c

Quoted 1 line
drivers/gpu/drm/amd/pm/amdgpu_pm.c +1 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

EOPNOTSUPP) &&

drivers/gpu/drm/amd/pm/amdgpu_pm.c

Quoted 1 line
drivers/gpu/drm/amd/pm/amdgpu_pm.c +1 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

query state */

281 lines not shown · raw message

Quoted 5 lines

5 lines not shown · raw message

143 lines not shown · raw message

Parts of this message are not shown here. View the raw message.

author
#6 lore raw

PATCH v4 3/17 drm/amd/pm: do not expose power implementation details to display

In reply to Evan Quan

Display is another client of our power APIs. It's not proper to spike into power implementation details there.

Change-Id Ic897131e16473ed29d3d7586d822a55c64e6574a
---
 .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c |   6 +-
 .../amd/display/amdgpu_dm/amdgpu_dm_pp_smu.c  | 246 +++++++-----------
 drivers/gpu/drm/amd/pm/amdgpu_dpm.c           | 218 ++++++++++++++++
 drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h       |  38 +++
 4 files changed, 344 insertions(+), 164 deletions(-)
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +1 -5
index 7837e0613717..2c6c840e14a1 100644
@@ -2136,12 +2136,8 @@ static void s3_handle_mst(struct drm_device *dev, bool suspend)
 
 static int amdgpu_dm_smu_write_watermarks_table(struct amdgpu_device *adev)
 {
-	struct smu_context *smu = &adev->smu;
 	int ret = 0;
 
-	if (!is_support_sw_smu(adev))
-		return 0;
-
 	/* This interface is for dGPU Navi1x.Linux dc-pplib interface depends
 	 * on window driver dc implementation.
 	 * For Navi1x, clock settings of dcn watermarks are fixed. the settings
@@ -2180,7 +2176,7 @@ static int amdgpu_dm_smu_write_watermarks_table(struct amdgpu_device *adev)
 		return 0;
 	}
 
-	ret = smu_write_watermarks_table(smu);
+	ret = amdgpu_dpm_write_watermarks_table(adev);
 	if (ret) {
 		DRM_ERROR("Failed to update WMTABLE!\n");
 		return ret;
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_pp_smu.c +87 -159

461 lines not on this page · raw message

drivers/gpu/drm/amd/pm/amdgpu_dpm.c +218 -0

227 lines not on this page · raw message

drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h +38 -0
index 039c40b1d0cb..fea203a79cb4 100644
@@ -500,6 +500,7 @@ int amdgpu_dpm_set_soft_freq_range(struct amdgpu_device *adev,
 				        enum pp_clock_type type,
 				        uint32_t min,
 				        uint32_t max);
+int amdgpu_dpm_write_watermarks_table(struct amdgpu_device *adev);
 int amdgpu_dpm_wait_for_event(struct amdgpu_device *adev, enum smu_event_type event,
 		       uint64_t event_arg);
 int amdgpu_dpm_get_status_gfxoff(struct amdgpu_device *adev, uint32_t *value);
@@ -578,4 +579,41 @@ int amdgpu_dpm_set_pp_table(struct amdgpu_device *adev,
 			    size_t size);
 int amdgpu_dpm_get_num_cpu_cores(struct amdgpu_device *adev);
 void amdgpu_dpm_stb_debug_fs_init(struct amdgpu_device *adev);
+int amdgpu_dpm_display_configuration_change(struct amdgpu_device *adev,
+					    const struct amd_pp_display_configuration *input);
+int amdgpu_dpm_get_clock_by_type(struct amdgpu_device *adev,
+				 enum amd_pp_clock_type type,
+				 struct amd_pp_clocks *clocks);
+int amdgpu_dpm_get_display_mode_validation_clks(struct amdgpu_device *adev,
+						struct amd_pp_simple_clock_info *clocks);
+int amdgpu_dpm_get_clock_by_type_with_latency(struct amdgpu_device *adev,
+					      enum amd_pp_clock_type type,
+					      struct pp_clock_levels_with_latency *clocks);
+int amdgpu_dpm_get_clock_by_type_with_voltage(struct amdgpu_device *adev,
+					      enum amd_pp_clock_type type,
+					      struct pp_clock_levels_with_voltage *clocks);
+int amdgpu_dpm_set_watermarks_for_clocks_ranges(struct amdgpu_device *adev,
+					       void *clock_ranges);
+int amdgpu_dpm_display_clock_voltage_request(struct amdgpu_device *adev,
+					     struct pp_display_clock_request *clock);
+int amdgpu_dpm_get_current_clocks(struct amdgpu_device *adev,
+				  struct amd_pp_clock_info *clocks);
+void amdgpu_dpm_notify_smu_enable_pwe(struct amdgpu_device *adev);
+int amdgpu_dpm_set_active_display_count(struct amdgpu_device *adev,
+					uint32_t count);
+int amdgpu_dpm_set_min_deep_sleep_dcefclk(struct amdgpu_device *adev,
+					  uint32_t clock);
+void amdgpu_dpm_set_hard_min_dcefclk_by_freq(struct amdgpu_device *adev,
+					     uint32_t clock);
+void amdgpu_dpm_set_hard_min_fclk_by_freq(struct amdgpu_device *adev,
+					  uint32_t clock);
+int amdgpu_dpm_display_disable_memory_clock_switch(struct amdgpu_device *adev,
+						   bool disable_memory_clock_switch);
+int amdgpu_dpm_get_max_sustainable_clocks_by_dc(struct amdgpu_device *adev,
+						struct pp_smu_nv_clock_table *max_clocks);
+enum pp_smu_status amdgpu_dpm_get_uclk_dpm_states(struct amdgpu_device *adev,
+						  unsigned int *clock_values_in_khz,
+						  unsigned int *num_states);
+int amdgpu_dpm_get_dpm_clock_table(struct amdgpu_device *adev,
+				   struct dpm_clocks *clock_table);
 #endif
Signature · 1 line
2.29.0
#7 lore raw

Re: [PATCH V4 03/17] drm/amd/pm: do not expose power implementation details to display

Quoted 548 lines · Evan Quan

Display is another client of our power APIs. It's not proper to spike into power implementation details there.

Change-Id Ic897131e16473ed29d3d7586d822a55c64e6574a
---
  .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c |   6 +-
  .../amd/display/amdgpu_dm/amdgpu_dm_pp_smu.c  | 246 +++++++-----------
  drivers/gpu/drm/amd/pm/amdgpu_dpm.c           | 218 ++++++++++++++++
  drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h       |  38 +++
  4 files changed, 344 insertions(+), 164 deletions(-)
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +1 -5
index 7837e0613717..2c6c840e14a1 100644
@@ -2136,12 +2136,8 @@ static void s3_handle_mst(struct drm_device *dev, bool suspend)
 
  static int amdgpu_dm_smu_write_watermarks_table(struct amdgpu_device *adev)
  {
-	struct smu_context *smu = &adev->smu;
  	int ret = 0;
 
-	if (!is_support_sw_smu(adev))
-		return 0;
-
  	/* This interface is for dGPU Navi1x.Linux dc-pplib interface depends
  	 * on window driver dc implementation.
  	 * For Navi1x, clock settings of dcn watermarks are fixed. the settings
@@ -2180,7 +2176,7 @@ static int amdgpu_dm_smu_write_watermarks_table(struct amdgpu_device *adev)
  		return 0;
  	}
 
-	ret = smu_write_watermarks_table(smu);
+	ret = amdgpu_dpm_write_watermarks_table(adev);
  	if (ret) {
  		DRM_ERROR("Failed to update WMTABLE!\n");
  		return ret;
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_pp_smu.c +87 -159
index eba270121698..46550811da00 100644
@@ -99,10 +99,7 @@ bool dm_pp_apply_display_requirements(
  			adev->pm.pm_display_cfg.displays[i].controller_id = dc_cfg->pipe_idx + 1;
  		}
 
-		if (adev->powerplay.pp_funcs && adev->powerplay.pp_funcs->display_configuration_change)
-			adev->powerplay.pp_funcs->display_configuration_change(
-				adev->powerplay.pp_handle,
-				&adev->pm.pm_display_cfg);
+		amdgpu_dpm_display_configuration_change(adev, &adev->pm.pm_display_cfg);
 
  		amdgpu_pm_compute_clocks(adev);
  	}
@@ -298,31 +295,25 @@ bool dm_pp_get_clock_levels_by_type(
  		struct dm_pp_clock_levels *dc_clks)
  {
  	struct amdgpu_device *adev = ctx->driver_context;
-	void *pp_handle = adev->powerplay.pp_handle;
  	struct amd_pp_clocks pp_clks = { 0 };
  	struct amd_pp_simple_clock_info validation_clks = { 0 };
  	uint32_t i;
 
-	if (adev->powerplay.pp_funcs && adev->powerplay.pp_funcs->get_clock_by_type) {
-		if (adev->powerplay.pp_funcs->get_clock_by_type(pp_handle,
-			dc_to_pp_clock_type(clk_type), &pp_clks)) {
-			/* Error in pplib. Provide default values. */
-			get_default_clock_levels(clk_type, dc_clks);
-			return true;
-		}
+	if (amdgpu_dpm_get_clock_by_type(adev,
+		dc_to_pp_clock_type(clk_type), &pp_clks)) {
+		/* Error in pplib. Provide default values. */
+		get_default_clock_levels(clk_type, dc_clks);
+		return true;
  	}
 
  	pp_to_dc_clock_levels(&pp_clks, dc_clks, clk_type);
 
-	if (adev->powerplay.pp_funcs && adev->powerplay.pp_funcs->get_display_mode_validation_clocks) {
-		if (adev->powerplay.pp_funcs->get_display_mode_validation_clocks(
-						pp_handle, &validation_clks)) {
-			/* Error in pplib. Provide default values. */
-			DRM_INFO("DM_PPLIB: Warning: using default validation clocks!\n");
-			validation_clks.engine_max_clock = 72000;
-			validation_clks.memory_max_clock = 80000;
-			validation_clks.level = 0;
-		}
+	if (amdgpu_dpm_get_display_mode_validation_clks(adev, &validation_clks)) {
+		/* Error in pplib. Provide default values. */
+		DRM_INFO("DM_PPLIB: Warning: using default validation clocks!\n");
+		validation_clks.engine_max_clock = 72000;
+		validation_clks.memory_max_clock = 80000;
+		validation_clks.level = 0;
  	}
 
  	DRM_INFO("DM_PPLIB: Validation clocks:\n");
@@ -370,18 +361,14 @@ bool dm_pp_get_clock_levels_by_type_with_latency(
  	struct dm_pp_clock_levels_with_latency *clk_level_info)
  {
  	struct amdgpu_device *adev = ctx->driver_context;
-	void *pp_handle = adev->powerplay.pp_handle;
  	struct pp_clock_levels_with_latency pp_clks = { 0 };
-	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
  	int ret;
 
-	if (pp_funcs && pp_funcs->get_clock_by_type_with_latency) {
-		ret = pp_funcs->get_clock_by_type_with_latency(pp_handle,
-						dc_to_pp_clock_type(clk_type),
-						&pp_clks);
-		if (ret)
-			return false;
-	}
+	ret = amdgpu_dpm_get_clock_by_type_with_latency(adev,
+					dc_to_pp_clock_type(clk_type),
+					&pp_clks);
+	if (ret)
+		return false;
 
  	pp_to_dc_clock_levels_with_latency(&pp_clks, clk_level_info, clk_type);
 
@@ -394,18 +381,14 @@ bool dm_pp_get_clock_levels_by_type_with_voltage(
  	struct dm_pp_clock_levels_with_voltage *clk_level_info)
  {
  	struct amdgpu_device *adev = ctx->driver_context;
-	void *pp_handle = adev->powerplay.pp_handle;
  	struct pp_clock_levels_with_voltage pp_clk_info = {0};
-	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
  	int ret;
 
-	if (pp_funcs && pp_funcs->get_clock_by_type_with_voltage) {
-		ret = pp_funcs->get_clock_by_type_with_voltage(pp_handle,
-						dc_to_pp_clock_type(clk_type),
-						&pp_clk_info);
-		if (ret)
-			return false;
-	}
+	ret = amdgpu_dpm_get_clock_by_type_with_voltage(adev,
+					dc_to_pp_clock_type(clk_type),
+					&pp_clk_info);
+	if (ret)
+		return false;
 
  	pp_to_dc_clock_levels_with_voltage(&pp_clk_info, clk_level_info, clk_type);
 
@@ -417,19 +400,16 @@ bool dm_pp_notify_wm_clock_changes(
  	struct dm_pp_wm_sets_with_clock_ranges *wm_with_clock_ranges)
  {
  	struct amdgpu_device *adev = ctx->driver_context;
-	void *pp_handle = adev->powerplay.pp_handle;
-	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
 
  	/*
  	 * Limit this watermark setting for Polaris for now
  	 * TODO: expand this to other ASICs
  	 */
-	if ((adev->asic_type >= CHIP_POLARIS10) && (adev->asic_type <= CHIP_VEGAM)
-	     && pp_funcs && pp_funcs->set_watermarks_for_clocks_ranges) {
-		if (!pp_funcs->set_watermarks_for_clocks_ranges(pp_handle,
+	if ((adev->asic_type >= CHIP_POLARIS10) &&
+	     (adev->asic_type <= CHIP_VEGAM) &&
+	     !amdgpu_dpm_set_watermarks_for_clocks_ranges(adev,
  						(void *)wm_with_clock_ranges))
  			return true;
-	}
 
  	return false;
  }
@@ -456,12 +436,10 @@ bool dm_pp_apply_clock_for_voltage_request(
  	if (!pp_clock_request.clock_type)
  		return false;
 
-	if (adev->powerplay.pp_funcs && adev->powerplay.pp_funcs->display_clock_voltage_request)
-		ret = adev->powerplay.pp_funcs->display_clock_voltage_request(
-			adev->powerplay.pp_handle,
-			&pp_clock_request);
-	if (ret)
+	ret = amdgpu_dpm_display_clock_voltage_request(adev, &pp_clock_request);
+	if (ret && (ret != -EOPNOTSUPP))
  		return false;
+
  	return true;
  }
 
@@ -471,15 +449,8 @@ bool dm_pp_get_static_clocks(
  {
  	struct amdgpu_device *adev = ctx->driver_context;
  	struct amd_pp_clock_info pp_clk_info = {0};
-	int ret = 0;
 
-	if (adev->powerplay.pp_funcs && adev->powerplay.pp_funcs->get_current_clocks)
-		ret = adev->powerplay.pp_funcs->get_current_clocks(
-			adev->powerplay.pp_handle,
-			&pp_clk_info);
-	else
-		return false;
-	if (ret)
+	if (amdgpu_dpm_get_current_clocks(adev, &pp_clk_info))
  		return false;
 
  	static_clk_info->max_clocks_state = pp_to_dc_powerlevel_state(pp_clk_info.max_clocks_state);
@@ -494,8 +465,6 @@ static void pp_rv_set_wm_ranges(struct pp_smu *pp,
  {
  	const struct dc_context *ctx = pp->dm;
  	struct amdgpu_device *adev = ctx->driver_context;
-	void *pp_handle = adev->powerplay.pp_handle;
-	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
  	struct dm_pp_wm_sets_with_clock_ranges_soc15 wm_with_clock_ranges;
  	struct dm_pp_clock_range_for_dmif_wm_set_soc15 *wm_dce_clocks = wm_with_clock_ranges.wm_dmif_clocks_ranges;
  	struct dm_pp_clock_range_for_mcif_wm_set_soc15 *wm_soc_clocks = wm_with_clock_ranges.wm_mcif_clocks_ranges;
@@ -536,72 +505,48 @@ static void pp_rv_set_wm_ranges(struct pp_smu *pp,
  				ranges->writer_wm_sets[i].min_drain_clk_mhz * 1000;
  	}
 
-	if (pp_funcs && pp_funcs->set_watermarks_for_clocks_ranges)
-		pp_funcs->set_watermarks_for_clocks_ranges(pp_handle,
-							   &wm_with_clock_ranges);
+	amdgpu_dpm_set_watermarks_for_clocks_ranges(adev,
+						    &wm_with_clock_ranges);
  }
 
  static void pp_rv_set_pme_wa_enable(struct pp_smu *pp)
  {
  	const struct dc_context *ctx = pp->dm;
  	struct amdgpu_device *adev = ctx->driver_context;
-	void *pp_handle = adev->powerplay.pp_handle;
-	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
 
-	if (pp_funcs && pp_funcs->notify_smu_enable_pwe)
-		pp_funcs->notify_smu_enable_pwe(pp_handle);
+	amdgpu_dpm_notify_smu_enable_pwe(adev);
  }
 
  static void pp_rv_set_active_display_count(struct pp_smu *pp, int count)
  {
  	const struct dc_context *ctx = pp->dm;
  	struct amdgpu_device *adev = ctx->driver_context;
-	void *pp_handle = adev->powerplay.pp_handle;
-	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
 
-	if (!pp_funcs || !pp_funcs->set_active_display_count)
-		return;
-
-	pp_funcs->set_active_display_count(pp_handle, count);
+	amdgpu_dpm_set_active_display_count(adev, count);
  }
 
  static void pp_rv_set_min_deep_sleep_dcfclk(struct pp_smu *pp, int clock)
  {
  	const struct dc_context *ctx = pp->dm;
  	struct amdgpu_device *adev = ctx->driver_context;
-	void *pp_handle = adev->powerplay.pp_handle;
-	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
-
-	if (!pp_funcs || !pp_funcs->set_min_deep_sleep_dcefclk)
-		return;
 
-	pp_funcs->set_min_deep_sleep_dcefclk(pp_handle, clock);
+	amdgpu_dpm_set_min_deep_sleep_dcefclk(adev, clock);
  }
 
  static void pp_rv_set_hard_min_dcefclk_by_freq(struct pp_smu *pp, int clock)
  {
  	const struct dc_context *ctx = pp->dm;
  	struct amdgpu_device *adev = ctx->driver_context;
-	void *pp_handle = adev->powerplay.pp_handle;
-	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
 
-	if (!pp_funcs || !pp_funcs->set_hard_min_dcefclk_by_freq)
-		return;
-
-	pp_funcs->set_hard_min_dcefclk_by_freq(pp_handle, clock);
+	amdgpu_dpm_set_hard_min_dcefclk_by_freq(adev, clock);
  }
 
  static void pp_rv_set_hard_min_fclk_by_freq(struct pp_smu *pp, int mhz)
  {
  	const struct dc_context *ctx = pp->dm;
  	struct amdgpu_device *adev = ctx->driver_context;
-	void *pp_handle = adev->powerplay.pp_handle;
-	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
-
-	if (!pp_funcs || !pp_funcs->set_hard_min_fclk_by_freq)
-		return;
 
-	pp_funcs->set_hard_min_fclk_by_freq(pp_handle, mhz);
+	amdgpu_dpm_set_hard_min_fclk_by_freq(adev, mhz);
  }
 
  static enum pp_smu_status pp_nv_set_wm_ranges(struct pp_smu *pp,
@@ -609,11 +554,8 @@ static enum pp_smu_status pp_nv_set_wm_ranges(struct pp_smu *pp,
  {
  	const struct dc_context *ctx = pp->dm;
  	struct amdgpu_device *adev = ctx->driver_context;
-	void *pp_handle = adev->powerplay.pp_handle;
-	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
 
-	if (pp_funcs && pp_funcs->set_watermarks_for_clocks_ranges)
-		pp_funcs->set_watermarks_for_clocks_ranges(pp_handle, ranges);
+	amdgpu_dpm_set_watermarks_for_clocks_ranges(adev, ranges);
 
  	return PP_SMU_RESULT_OK;
  }
@@ -622,14 +564,13 @@ static enum pp_smu_status pp_nv_set_display_count(struct pp_smu *pp, int count)
  {
  	const struct dc_context *ctx = pp->dm;
  	struct amdgpu_device *adev = ctx->driver_context;
-	void *pp_handle = adev->powerplay.pp_handle;
-	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+	int ret = 0;
 
-	if (!pp_funcs || !pp_funcs->set_active_display_count)
+	ret = amdgpu_dpm_set_active_display_count(adev, count);
+	if (ret == -EOPNOTSUPP)
  		return PP_SMU_RESULT_UNSUPPORTED;
-
-	/* 0: successful or smu.ppt_funcs->set_display_count = NULL;  1: fail */
-	if (pp_funcs->set_active_display_count(pp_handle, count))
+	else if (ret)
+		/* 0: successful or smu.ppt_funcs->set_display_count = NULL;  1: fail */
  		return PP_SMU_RESULT_FAIL;
 
  	return PP_SMU_RESULT_OK;
@@ -640,14 +581,13 @@ pp_nv_set_min_deep_sleep_dcfclk(struct pp_smu *pp, int mhz)
  {
  	const struct dc_context *ctx = pp->dm;
  	struct amdgpu_device *adev = ctx->driver_context;
-	void *pp_handle = adev->powerplay.pp_handle;
-	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
-
-	if (!pp_funcs || !pp_funcs->set_min_deep_sleep_dcefclk)
-		return PP_SMU_RESULT_UNSUPPORTED;
+	int ret = 0;
 
  	/* 0: successful or smu.ppt_funcs->set_deep_sleep_dcefclk = NULL;1: fail */
-	if (pp_funcs->set_min_deep_sleep_dcefclk(pp_handle, mhz))
+	ret = amdgpu_dpm_set_min_deep_sleep_dcefclk(adev, mhz);
+	if (ret == -EOPNOTSUPP)
+		return PP_SMU_RESULT_UNSUPPORTED;
+	else if (ret)
  		return PP_SMU_RESULT_FAIL;
 
  	return PP_SMU_RESULT_OK;
@@ -658,12 +598,8 @@ static enum pp_smu_status pp_nv_set_hard_min_dcefclk_by_freq(
  {
  	const struct dc_context *ctx = pp->dm;
  	struct amdgpu_device *adev = ctx->driver_context;
-	void *pp_handle = adev->powerplay.pp_handle;
-	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
  	struct pp_display_clock_request clock_req;
-
-	if (!pp_funcs || !pp_funcs->display_clock_voltage_request)
-		return PP_SMU_RESULT_UNSUPPORTED;
+	int ret = 0;
 
  	clock_req.clock_type = amd_pp_dcef_clock;
  	clock_req.clock_freq_in_khz = mhz * 1000;
@@ -671,7 +607,10 @@ static enum pp_smu_status pp_nv_set_hard_min_dcefclk_by_freq(
  	/* 0: successful or smu.ppt_funcs->display_clock_voltage_request = NULL
  	 * 1: fail
  	 */
-	if (pp_funcs->display_clock_voltage_request(pp_handle, &clock_req))
+	ret = amdgpu_dpm_display_clock_voltage_request(adev, &clock_req);
+	if (ret == -EOPNOTSUPP)
+		return PP_SMU_RESULT_UNSUPPORTED;
+	else if (ret)
  		return PP_SMU_RESULT_FAIL;
 
  	return PP_SMU_RESULT_OK;
@@ -682,12 +621,8 @@ pp_nv_set_hard_min_uclk_by_freq(struct pp_smu *pp, int mhz)
  {
  	const struct dc_context *ctx = pp->dm;
  	struct amdgpu_device *adev = ctx->driver_context;
-	void *pp_handle = adev->powerplay.pp_handle;
-	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
  	struct pp_display_clock_request clock_req;
-
-	if (!pp_funcs || !pp_funcs->display_clock_voltage_request)
-		return PP_SMU_RESULT_UNSUPPORTED;
+	int ret = 0;
 
  	clock_req.clock_type = amd_pp_mem_clock;
  	clock_req.clock_freq_in_khz = mhz * 1000;
@@ -695,7 +630,10 @@ pp_nv_set_hard_min_uclk_by_freq(struct pp_smu *pp, int mhz)
  	/* 0: successful or smu.ppt_funcs->display_clock_voltage_request = NULL
  	 * 1: fail
  	 */
-	if (pp_funcs->display_clock_voltage_request(pp_handle, &clock_req))
+	ret = amdgpu_dpm_display_clock_voltage_request(adev, &clock_req);
+	if (ret == -EOPNOTSUPP)
+		return PP_SMU_RESULT_UNSUPPORTED;
+	else if (ret)
  		return PP_SMU_RESULT_FAIL;
 
  	return PP_SMU_RESULT_OK;
@@ -706,14 +644,10 @@ static enum pp_smu_status pp_nv_set_pstate_handshake_support(
  {
  	const struct dc_context *ctx = pp->dm;
  	struct amdgpu_device *adev = ctx->driver_context;
-	void *pp_handle = adev->powerplay.pp_handle;
-	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
 
-	if (pp_funcs && pp_funcs->display_disable_memory_clock_switch) {
-		if (pp_funcs->display_disable_memory_clock_switch(pp_handle,
-								  !pstate_handshake_supported))
-			return PP_SMU_RESULT_FAIL;
-	}
+	if (amdgpu_dpm_display_disable_memory_clock_switch(adev,
+							  !pstate_handshake_supported))
+		return PP_SMU_RESULT_FAIL;
 
  	return PP_SMU_RESULT_OK;
  }
@@ -723,12 +657,8 @@ static enum pp_smu_status pp_nv_set_voltage_by_freq(struct pp_smu *pp,
  {
  	const struct dc_context *ctx = pp->dm;
  	struct amdgpu_device *adev = ctx->driver_context;
-	void *pp_handle = adev->powerplay.pp_handle;
-	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
  	struct pp_display_clock_request clock_req;
-
-	if (!pp_funcs || !pp_funcs->display_clock_voltage_request)
-		return PP_SMU_RESULT_UNSUPPORTED;
+	int ret = 0;
 
  	switch (clock_id) {
  	case PP_SMU_NV_DISPCLK:
@@ -748,7 +678,10 @@ static enum pp_smu_status pp_nv_set_voltage_by_freq(struct pp_smu *pp,
  	/* 0: successful or smu.ppt_funcs->display_clock_voltage_request = NULL
  	 * 1: fail
  	 */
-	if (pp_funcs->display_clock_voltage_request(pp_handle, &clock_req))
+	ret = amdgpu_dpm_display_clock_voltage_request(adev, &clock_req);
+	if (ret == -EOPNOTSUPP)
+		return PP_SMU_RESULT_UNSUPPORTED;
+	else if (ret)
  		return PP_SMU_RESULT_FAIL;
 
  	return PP_SMU_RESULT_OK;
@@ -759,16 +692,16 @@ static enum pp_smu_status pp_nv_get_maximum_sustainable_clocks(
  {
  	const struct dc_context *ctx = pp->dm;
  	struct amdgpu_device *adev = ctx->driver_context;
-	void *pp_handle = adev->powerplay.pp_handle;
-	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+	int ret = 0;
 
-	if (!pp_funcs || !pp_funcs->get_max_sustainable_clocks_by_dc)
+	ret = amdgpu_dpm_get_max_sustainable_clocks_by_dc(adev,
+							  max_clocks);
+	if (ret == -EOPNOTSUPP)
  		return PP_SMU_RESULT_UNSUPPORTED;
+	else if (ret)
+		return PP_SMU_RESULT_FAIL;
 
-	if (!pp_funcs->get_max_sustainable_clocks_by_dc(pp_handle, max_clocks))
-		return PP_SMU_RESULT_OK;
-
-	return PP_SMU_RESULT_FAIL;
+	return PP_SMU_RESULT_OK;
  }
 
  static enum pp_smu_status pp_nv_get_uclk_dpm_states(struct pp_smu *pp,
@@ -776,18 +709,17 @@ static enum pp_smu_status pp_nv_get_uclk_dpm_states(struct pp_smu *pp,
  {
  	const struct dc_context *ctx = pp->dm;
  	struct amdgpu_device *adev = ctx->driver_context;
-	void *pp_handle = adev->powerplay.pp_handle;
-	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+	int ret = 0;
 
-	if (!pp_funcs || !pp_funcs->get_uclk_dpm_states)
+	ret = amdgpu_dpm_get_uclk_dpm_states(adev,
+					     clock_values_in_khz,
+					    num_states);
+	if (ret == -EOPNOTSUPP)
  		return PP_SMU_RESULT_UNSUPPORTED;
+	else if (ret)
+		return PP_SMU_RESULT_FAIL;
 
-	if (!pp_funcs->get_uclk_dpm_states(pp_handle,
-					   clock_values_in_khz,
-					   num_states))
-		return PP_SMU_RESULT_OK;
-
-	return PP_SMU_RESULT_FAIL;
+	return PP_SMU_RESULT_OK;
  }
 
  static enum pp_smu_status pp_rn_get_dpm_clock_table(
@@ -795,16 +727,15 @@ static enum pp_smu_status pp_rn_get_dpm_clock_table(
  {
  	const struct dc_context *ctx = pp->dm;
  	struct amdgpu_device *adev = ctx->driver_context;
-	void *pp_handle = adev->powerplay.pp_handle;
-	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+	int ret = 0;
 
-	if (!pp_funcs || !pp_funcs->get_dpm_clock_table)
+	ret = amdgpu_dpm_get_dpm_clock_table(adev, clock_table);
+	if (ret == -EOPNOTSUPP)
  		return PP_SMU_RESULT_UNSUPPORTED;
+	else if (ret)
+		return PP_SMU_RESULT_FAIL;
 
-	if (!pp_funcs->get_dpm_clock_table(pp_handle, clock_table))
-		return PP_SMU_RESULT_OK;
-
-	return PP_SMU_RESULT_FAIL;
+	return PP_SMU_RESULT_OK;
  }
 
  static enum pp_smu_status pp_rn_set_wm_ranges(struct pp_smu *pp,
@@ -812,11 +743,8 @@ static enum pp_smu_status pp_rn_set_wm_ranges(struct pp_smu *pp,
  {
  	const struct dc_context *ctx = pp->dm;
  	struct amdgpu_device *adev = ctx->driver_context;
-	void *pp_handle = adev->powerplay.pp_handle;
-	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
 
-	if (pp_funcs && pp_funcs->set_watermarks_for_clocks_ranges)
-		pp_funcs->set_watermarks_for_clocks_ranges(pp_handle, ranges);
+	amdgpu_dpm_set_watermarks_for_clocks_ranges(adev, ranges);
 
  	return PP_SMU_RESULT_OK;
  }
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +8 -0
index 2c789eb5d066..3a84c3995f2d 100644
@@ -1659,6 +1659,14 @@ int amdgpu_dpm_set_soft_freq_range(struct amdgpu_device *adev,
  	}
  }
 
+int amdgpu_dpm_write_watermarks_table(struct amdgpu_device *adev)
+{
+	if (!is_support_sw_smu(adev))
+		return 0;
+
+	return smu_write_watermarks_table(&adev->smu);
+}
+
  int amdgpu_dpm_wait_for_event(struct amdgpu_device *adev,
  			      enum smu_event_type event,
  			      uint64_t event_arg)
@@ -2158,3 +2166,213 @@ void amdgpu_dpm_stb_debug_fs_init(struct amdgpu_device *adev)
 
  	amdgpu_smu_stb_debug_fs_init(adev);

drivers/gpu/drm/amd/pm/amdgpu_dpm.c void amdgpu_dpm_stb_debug_fs_init(struct amdgpu_device *adev) · line 2177

Quoted 10 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +9 -0
  }
+
+int amdgpu_dpm_display_configuration_change(struct amdgpu_device *adev,
+					    const struct amd_pp_display_configuration *input)
+{
+	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+
+	if (!pp_funcs->display_configuration_change)
+		return 0;
+

Same comments as in the other patch. Let the caller decide what to do when operation is not supported.

Quoted 91 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +91 -0
+	return pp_funcs->display_configuration_change(adev->powerplay.pp_handle,
+						      input);
+}
+
+int amdgpu_dpm_get_clock_by_type(struct amdgpu_device *adev,
+				 enum amd_pp_clock_type type,
+				 struct amd_pp_clocks *clocks)
+{
+	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+
+	if (!pp_funcs->get_clock_by_type)
+		return 0;
+
+	return pp_funcs->get_clock_by_type(adev->powerplay.pp_handle,
+					   type,
+					   clocks);
+}
+
+int amdgpu_dpm_get_display_mode_validation_clks(struct amdgpu_device *adev,
+						struct amd_pp_simple_clock_info *clocks)
+{
+	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+
+	if (!pp_funcs->get_display_mode_validation_clocks)
+		return 0;
+
+	return pp_funcs->get_display_mode_validation_clocks(adev->powerplay.pp_handle,
+							    clocks);
+}
+
+int amdgpu_dpm_get_clock_by_type_with_latency(struct amdgpu_device *adev,
+					      enum amd_pp_clock_type type,
+					      struct pp_clock_levels_with_latency *clocks)
+{
+	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+
+	if (!pp_funcs->get_clock_by_type_with_latency)
+		return 0;
+
+	return pp_funcs->get_clock_by_type_with_latency(adev->powerplay.pp_handle,
+							type,
+							clocks);
+}
+
+int amdgpu_dpm_get_clock_by_type_with_voltage(struct amdgpu_device *adev,
+					      enum amd_pp_clock_type type,
+					      struct pp_clock_levels_with_voltage *clocks)
+{
+	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+
+	if (!pp_funcs->get_clock_by_type_with_voltage)
+		return 0;
+
+	return pp_funcs->get_clock_by_type_with_voltage(adev->powerplay.pp_handle,
+							type,
+							clocks);
+}
+
+int amdgpu_dpm_set_watermarks_for_clocks_ranges(struct amdgpu_device *adev,
+					       void *clock_ranges)
+{
+	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+
+	if (!pp_funcs->set_watermarks_for_clocks_ranges)
+		return -EOPNOTSUPP;
+
+	return pp_funcs->set_watermarks_for_clocks_ranges(adev->powerplay.pp_handle,
+							  clock_ranges);
+}
+
+int amdgpu_dpm_display_clock_voltage_request(struct amdgpu_device *adev,
+					     struct pp_display_clock_request *clock)
+{
+	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+
+	if (!pp_funcs->display_clock_voltage_request)
+		return -EOPNOTSUPP;
+
+	return pp_funcs->display_clock_voltage_request(adev->powerplay.pp_handle,
+						       clock);
+}
+
+int amdgpu_dpm_get_current_clocks(struct amdgpu_device *adev,
+				  struct amd_pp_clock_info *clocks)
+{
+	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+
+	if (!pp_funcs->get_current_clocks)
+		return -EOPNOTSUPP;
+
+	return pp_funcs->get_current_clocks(adev->powerplay.pp_handle,

drivers/gpu/drm/amd/pm/amdgpu_dpm.c void amdgpu_dpm_stb_debug_fs_init(struct amdgpu_device *adev) · line 2278

Quoted 10 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +10 -0
+					    clocks);
+}
+
+void amdgpu_dpm_notify_smu_enable_pwe(struct amdgpu_device *adev)
+{
+	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+
+	if (!pp_funcs->notify_smu_enable_pwe)
+		return;
+

These void funcs also need to have valid return value and if operation is not supported, let the caller know. Implementation in a particular context vs when refactored into standalone APIs need not be the same.

Thanks,
Lijo

Quoted 155 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +100 -0
+	pp_funcs->notify_smu_enable_pwe(adev->powerplay.pp_handle);
+}
+
+int amdgpu_dpm_set_active_display_count(struct amdgpu_device *adev,
+					uint32_t count)
+{
+	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+
+	if (!pp_funcs->set_active_display_count)
+		return -EOPNOTSUPP;
+
+	return pp_funcs->set_active_display_count(adev->powerplay.pp_handle,
+						  count);
+}
+
+int amdgpu_dpm_set_min_deep_sleep_dcefclk(struct amdgpu_device *adev,
+					  uint32_t clock)
+{
+	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+
+	if (!pp_funcs->set_min_deep_sleep_dcefclk)
+		return -EOPNOTSUPP;
+
+	return pp_funcs->set_min_deep_sleep_dcefclk(adev->powerplay.pp_handle,
+						    clock);
+}
+
+void amdgpu_dpm_set_hard_min_dcefclk_by_freq(struct amdgpu_device *adev,
+					     uint32_t clock)
+{
+	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+
+	if (!pp_funcs->set_hard_min_dcefclk_by_freq)
+		return;
+
+	pp_funcs->set_hard_min_dcefclk_by_freq(adev->powerplay.pp_handle,
+					       clock);
+}
+
+void amdgpu_dpm_set_hard_min_fclk_by_freq(struct amdgpu_device *adev,
+					  uint32_t clock)
+{
+	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+
+	if (!pp_funcs->set_hard_min_fclk_by_freq)
+		return;
+
+	pp_funcs->set_hard_min_fclk_by_freq(adev->powerplay.pp_handle,
+					    clock);
+}
+
+int amdgpu_dpm_display_disable_memory_clock_switch(struct amdgpu_device *adev,
+						   bool disable_memory_clock_switch)
+{
+	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+
+	if (!pp_funcs->display_disable_memory_clock_switch)
+		return 0;
+
+	return pp_funcs->display_disable_memory_clock_switch(adev->powerplay.pp_handle,
+							     disable_memory_clock_switch);
+}
+
+int amdgpu_dpm_get_max_sustainable_clocks_by_dc(struct amdgpu_device *adev,
+						struct pp_smu_nv_clock_table *max_clocks)
+{
+	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+
+	if (!pp_funcs->get_max_sustainable_clocks_by_dc)
+		return -EOPNOTSUPP;
+
+	return pp_funcs->get_max_sustainable_clocks_by_dc(adev->powerplay.pp_handle,
+							  max_clocks);
+}
+
+enum pp_smu_status amdgpu_dpm_get_uclk_dpm_states(struct amdgpu_device *adev,
+						  unsigned int *clock_values_in_khz,
+						  unsigned int *num_states)
+{
+	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+
+	if (!pp_funcs->get_uclk_dpm_states)
+		return -EOPNOTSUPP;
+
+	return pp_funcs->get_uclk_dpm_states(adev->powerplay.pp_handle,
+					     clock_values_in_khz,
+					     num_states);
+}
+
+int amdgpu_dpm_get_dpm_clock_table(struct amdgpu_device *adev,
+				   struct dpm_clocks *clock_table)
+{
+	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+
+	if (!pp_funcs->get_dpm_clock_table)
+		return -EOPNOTSUPP;
+
+	return pp_funcs->get_dpm_clock_table(adev->powerplay.pp_handle,
+					     clock_table);
+}
drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h +38 -0
index 039c40b1d0cb..fea203a79cb4 100644
@@ -500,6 +500,7 @@ int amdgpu_dpm_set_soft_freq_range(struct amdgpu_device *adev,
  				        enum pp_clock_type type,
  				        uint32_t min,
  				        uint32_t max);
+int amdgpu_dpm_write_watermarks_table(struct amdgpu_device *adev);
  int amdgpu_dpm_wait_for_event(struct amdgpu_device *adev, enum smu_event_type event,
  		       uint64_t event_arg);
  int amdgpu_dpm_get_status_gfxoff(struct amdgpu_device *adev, uint32_t *value);
@@ -578,4 +579,41 @@ int amdgpu_dpm_set_pp_table(struct amdgpu_device *adev,
  			    size_t size);
  int amdgpu_dpm_get_num_cpu_cores(struct amdgpu_device *adev);
  void amdgpu_dpm_stb_debug_fs_init(struct amdgpu_device *adev);
+int amdgpu_dpm_display_configuration_change(struct amdgpu_device *adev,
+					    const struct amd_pp_display_configuration *input);
+int amdgpu_dpm_get_clock_by_type(struct amdgpu_device *adev,
+				 enum amd_pp_clock_type type,
+				 struct amd_pp_clocks *clocks);
+int amdgpu_dpm_get_display_mode_validation_clks(struct amdgpu_device *adev,
+						struct amd_pp_simple_clock_info *clocks);
+int amdgpu_dpm_get_clock_by_type_with_latency(struct amdgpu_device *adev,
+					      enum amd_pp_clock_type type,
+					      struct pp_clock_levels_with_latency *clocks);
+int amdgpu_dpm_get_clock_by_type_with_voltage(struct amdgpu_device *adev,
+					      enum amd_pp_clock_type type,
+					      struct pp_clock_levels_with_voltage *clocks);
+int amdgpu_dpm_set_watermarks_for_clocks_ranges(struct amdgpu_device *adev,
+					       void *clock_ranges);
+int amdgpu_dpm_display_clock_voltage_request(struct amdgpu_device *adev,
+					     struct pp_display_clock_request *clock);
+int amdgpu_dpm_get_current_clocks(struct amdgpu_device *adev,
+				  struct amd_pp_clock_info *clocks);
+void amdgpu_dpm_notify_smu_enable_pwe(struct amdgpu_device *adev);
+int amdgpu_dpm_set_active_display_count(struct amdgpu_device *adev,
+					uint32_t count);
+int amdgpu_dpm_set_min_deep_sleep_dcefclk(struct amdgpu_device *adev,
+					  uint32_t clock);
+void amdgpu_dpm_set_hard_min_dcefclk_by_freq(struct amdgpu_device *adev,
+					     uint32_t clock);
+void amdgpu_dpm_set_hard_min_fclk_by_freq(struct amdgpu_device *adev,
+					  uint32_t clock);
+int amdgpu_dpm_display_disable_memory_clock_switch(struct amdgpu_device *adev,
+						   bool disable_memory_clock_switch);
+int amdgpu_dpm_get_max_sustainable_clocks_by_dc(struct amdgpu_device *adev,
+						struct pp_smu_nv_clock_table *max_clocks);
+enum pp_smu_status amdgpu_dpm_get_uclk_dpm_states(struct amdgpu_device *adev,
+						  unsigned int *clock_values_in_khz,
+						  unsigned int *num_states);
+int amdgpu_dpm_get_dpm_clock_table(struct amdgpu_device *adev,
+				   struct dpm_clocks *clock_table);
  #endif
author
#8 lore raw

RE: [PATCH V4 03/17] drm/amd/pm: do not expose power implementation details to display

[AMD Official Use Only]

Quoted 764 lines

-----Original Message-----
From: Lazar, Lijo <[email protected]>
Sent: Thursday, December 9, 2021 8:05 PM
To: Quan, Evan <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>; Feng, Kenneth <[email protected]>
Subject: Re: [PATCH V4 03/17] drm/amd/pm: do not expose power implementation details to display

Quoted 8 lines · Evan Quan

Display is another client of our power APIs. It's not proper to spike into power implementation details there.

Change-Id Ic897131e16473ed29d3d7586d822a55c64e6574a
---
  .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c |   6 +-
  .../amd/display/amdgpu_dm/amdgpu_dm_pp_smu.c  | 246 +++++++-----

------

Quoted 1 line
  drivers/gpu/drm/amd/pm/amdgpu_dpm.c           | 218

++++++++++++++++

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c static void s3_handle_mst(struct drm_device · line 2138

Quoted 12 lines
  drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h       |  38 +++
  4 files changed, 344 insertions(+), 164 deletions(-)
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +0 -0
index 7837e0613717..2c6c840e14a1 100644
@@ -2136,12 +2136,8 @@ static void s3_handle_mst(struct drm_device
 *dev, bool suspend)
 
  static int amdgpu_dm_smu_write_watermarks_table(struct

amdgpu_device *adev)

Quoted 11 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +0 -4
  {
-	struct smu_context *smu = &adev->smu;
  	int ret = 0;
 
-	if (!is_support_sw_smu(adev))
-		return 0;
-
  	/* This interface is for dGPU Navi1x.Linux dc-pplib interface depends
  	 * on window driver dc implementation.

* For Navi1x, clock settings of dcn watermarks are fixed. the
settings @@ -2180,7 +2176,7 @@ static int

amdgpu_dm_smu_write_watermarks_table(struct amdgpu_device *adev)

Quoted 9 lines
  		return 0;
  	}
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +1 -1
-	ret = smu_write_watermarks_table(smu);
+	ret = amdgpu_dpm_write_watermarks_table(adev);
  	if (ret) {
  		DRM_ERROR("Failed to update WMTABLE!\n");
  		return ret;

diff --git

a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_pp_smu.c

Quoted 4 lines

b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_pp_smu.c index eba270121698..46550811da00 100644
--- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_pp_smu.c
+++

b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_pp_smu.c

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c bool dm_pp_apply_display_requirements( · line 99

Quoted 2 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +0 -0
@@ -99,10 +99,7 @@ bool dm_pp_apply_display_requirements(
  			adev->pm.pm_display_cfg.displays[i].controller_id =

dc_cfg->pipe_idx + 1;

Quoted 44 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +0 -2
  		}
 
-		if (adev->powerplay.pp_funcs && adev-
 powerplay.pp_funcs->display_configuration_change)
-			adev->powerplay.pp_funcs-

display_configuration_change(

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +7 -12
-				adev->powerplay.pp_handle,
-				&adev->pm.pm_display_cfg);
+		amdgpu_dpm_display_configuration_change(adev,
+&adev->pm.pm_display_cfg);
 
  		amdgpu_pm_compute_clocks(adev);
  	}
@@ -298,31 +295,25 @@ bool dm_pp_get_clock_levels_by_type(
  		struct dm_pp_clock_levels *dc_clks)
  {
  	struct amdgpu_device *adev = ctx->driver_context;
-	void *pp_handle = adev->powerplay.pp_handle;
  	struct amd_pp_clocks pp_clks = { 0 };
  	struct amd_pp_simple_clock_info validation_clks = { 0 };
  	uint32_t i;
 
-	if (adev->powerplay.pp_funcs && adev->powerplay.pp_funcs-
 get_clock_by_type) {
-		if (adev->powerplay.pp_funcs-
 get_clock_by_type(pp_handle,
-			dc_to_pp_clock_type(clk_type), &pp_clks)) {
-			/* Error in pplib. Provide default values. */
-			get_default_clock_levels(clk_type, dc_clks);
-			return true;
-		}
+	if (amdgpu_dpm_get_clock_by_type(adev,
+		dc_to_pp_clock_type(clk_type), &pp_clks)) {
+		/* Error in pplib. Provide default values. */
+		get_default_clock_levels(clk_type, dc_clks);
+		return true;
  	}
 
  	pp_to_dc_clock_levels(&pp_clks, dc_clks, clk_type);
 
-	if (adev->powerplay.pp_funcs && adev->powerplay.pp_funcs-
 get_display_mode_validation_clocks) {
-		if (adev->powerplay.pp_funcs-

get_display_mode_validation_clocks(

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c

Quoted 1 line
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +0 -1
-						pp_handle, &validation_clks))

{

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c

Quoted 2 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +0 -2
-			/* Error in pplib. Provide default values. */
-			DRM_INFO("DM_PPLIB: Warning: using default

validation clocks!\n");

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c

Quoted 5 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +1 -4
-			validation_clks.engine_max_clock = 72000;
-			validation_clks.memory_max_clock = 80000;
-			validation_clks.level = 0;
-		}
+	if (amdgpu_dpm_get_display_mode_validation_clks(adev,

&validation_clks)) {

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c

Quoted 2 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +2 -0
+		/* Error in pplib. Provide default values. */
+		DRM_INFO("DM_PPLIB: Warning: using default validation

clocks!\n");

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c

Quoted 6 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +3 -0
+		validation_clks.engine_max_clock = 72000;
+		validation_clks.memory_max_clock = 80000;
+		validation_clks.level = 0;
  	}
 
  	DRM_INFO("DM_PPLIB: Validation clocks:\n"); @@ -370,18 +361,14

@@

Quoted 11 lines

bool dm_pp_get_clock_levels_by_type_with_latency(
struct dm_pp_clock_levels_with_latency *clk_level_info)
{
struct amdgpu_device *adev = ctx->driver_context;

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +0 -4
-	void *pp_handle = adev->powerplay.pp_handle;
  	struct pp_clock_levels_with_latency pp_clks = { 0 };
-	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
  	int ret;
 
-	if (pp_funcs && pp_funcs->get_clock_by_type_with_latency) {
-		ret = pp_funcs-
Quoted 2 lines

get_clock_by_type_with_latency(pp_handle,
-

	dc_to_pp_clock_type(clk_type),

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c bool

Quoted 14 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +5 -4
-						&pp_clks);
-		if (ret)
-			return false;
-	}
+	ret = amdgpu_dpm_get_clock_by_type_with_latency(adev,
+					dc_to_pp_clock_type(clk_type),
+					&pp_clks);
+	if (ret)
+		return false;
 
  	pp_to_dc_clock_levels_with_latency(&pp_clks, clk_level_info,

clk_type);

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +0 -0
@@ -394,18 +381,14 @@ bool

dm_pp_get_clock_levels_by_type_with_voltage(

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c bool · line 405

Quoted 12 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +0 -5
  	struct dm_pp_clock_levels_with_voltage *clk_level_info)
  {
  	struct amdgpu_device *adev = ctx->driver_context;
-	void *pp_handle = adev->powerplay.pp_handle;
  	struct pp_clock_levels_with_voltage pp_clk_info = {0};
-	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
  	int ret;
 
-	if (pp_funcs && pp_funcs->get_clock_by_type_with_voltage) {
-		ret = pp_funcs-
 get_clock_by_type_with_voltage(pp_handle,
-
	dc_to_pp_clock_type(clk_type),
Quoted 14 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +5 -4
-						&pp_clk_info);
-		if (ret)
-			return false;
-	}
+	ret = amdgpu_dpm_get_clock_by_type_with_voltage(adev,
+					dc_to_pp_clock_type(clk_type),
+					&pp_clk_info);
+	if (ret)
+		return false;
 
  	pp_to_dc_clock_levels_with_voltage(&pp_clk_info, clk_level_info,

clk_type);

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c bool dm_pp_notify_wm_clock_changes( · line 400

Quoted 1 line
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +0 -0
@@ -417,19 +400,16 @@ bool dm_pp_notify_wm_clock_changes(
  	struct dm_pp_wm_sets_with_clock_ranges

*wm_with_clock_ranges)

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c bool dm_pp_notify_wm_clock_changes( · line 427

Quoted 10 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +0 -3
  {
  	struct amdgpu_device *adev = ctx->driver_context;
-	void *pp_handle = adev->powerplay.pp_handle;
-	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
 
  	/*
  	 * Limit this watermark setting for Polaris for now
  	 * TODO: expand this to other ASICs
  	 */
-	if ((adev->asic_type >= CHIP_POLARIS10) && (adev->asic_type <=

CHIP_VEGAM)

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c bool dm_pp_notify_wm_clock_changes( · line 428

Quoted 1 line
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +0 -1
-	     && pp_funcs && pp_funcs->set_watermarks_for_clocks_ranges)

{

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c bool dm_pp_notify_wm_clock_changes( · line 412

Quoted 6 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +3 -1
-		if (!pp_funcs-
 set_watermarks_for_clocks_ranges(pp_handle,
+	if ((adev->asic_type >= CHIP_POLARIS10) &&
+	     (adev->asic_type <= CHIP_VEGAM) &&
+	     !amdgpu_dpm_set_watermarks_for_clocks_ranges(adev,
  						(void

*)wm_with_clock_ranges))

Quoted 13 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +0 -1
  			return true;
-	}
 
  	return false;
  }
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +0 -2
@@ -456,12 +436,10 @@ bool dm_pp_apply_clock_for_voltage_request(
  	if (!pp_clock_request.clock_type)
  		return false;
 
-	if (adev->powerplay.pp_funcs && adev->powerplay.pp_funcs-
 display_clock_voltage_request)
-		ret = adev->powerplay.pp_funcs-

display_clock_voltage_request(

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c

Quoted 4 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +1 -3
-			adev->powerplay.pp_handle,
-			&pp_clock_request);
-	if (ret)
+	ret = amdgpu_dpm_display_clock_voltage_request(adev,

&pp_clock_request);

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c static void pp_rv_set_wm_ranges(struct pp_smu

Quoted 26 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +3 -8
+	if (ret && (ret != -EOPNOTSUPP))
  		return false;
+
  	return true;
  }
@@ -471,15 +449,8 @@ bool dm_pp_get_static_clocks(
  {
  	struct amdgpu_device *adev = ctx->driver_context;
  	struct amd_pp_clock_info pp_clk_info = {0};
-	int ret = 0;
 
-	if (adev->powerplay.pp_funcs && adev->powerplay.pp_funcs-
 get_current_clocks)
-		ret = adev->powerplay.pp_funcs->get_current_clocks(
-			adev->powerplay.pp_handle,
-			&pp_clk_info);
-	else
-		return false;
-	if (ret)
+	if (amdgpu_dpm_get_current_clocks(adev, &pp_clk_info))
  		return false;
 

static_clk_info->max_clocks_state =
pp_to_dc_powerlevel_state(pp_clk_info.max_clocks_state);

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +0 -0
@@ -494,8 +465,6 @@ static void pp_rv_set_wm_ranges(struct pp_smu

*pp,

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c static void pp_rv_set_wm_ranges(struct pp_smu · line 468

Quoted 6 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +0 -2
  {
  	const struct dc_context *ctx = pp->dm;
  	struct amdgpu_device *adev = ctx->driver_context;
-	void *pp_handle = adev->powerplay.pp_handle;
-	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
  	struct dm_pp_wm_sets_with_clock_ranges_soc15

wm_with_clock_ranges;

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c static void pp_rv_set_wm_ranges(struct pp_smu · line 469

Quoted 1 line
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +0 -0
  	struct dm_pp_clock_range_for_dmif_wm_set_soc15

*wm_dce_clocks = wm_with_clock_ranges.wm_dmif_clocks_ranges;

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c static void pp_rv_set_wm_ranges(struct pp_smu · line 470

Quoted 1 line
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +0 -0
  	struct dm_pp_clock_range_for_mcif_wm_set_soc15

*wm_soc_clocks =

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c static void pp_rv_set_wm_ranges(struct pp_smu

Quoted 2 lines

wm_with_clock_ranges.wm_mcif_clocks_ranges;

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +0 -0
@@ -536,72 +505,48 @@ static void pp_rv_set_wm_ranges(struct pp_smu

*pp,

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c static void pp_rv_set_wm_ranges(struct pp_smu · line 542

Quoted 7 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +0 -3
  				ranges-
 writer_wm_sets[i].min_drain_clk_mhz * 1000;
  	}
 
-	if (pp_funcs && pp_funcs->set_watermarks_for_clocks_ranges)
-		pp_funcs->set_watermarks_for_clocks_ranges(pp_handle,
-

&wm_with_clock_ranges);

Quoted 21 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +3 -5
+	amdgpu_dpm_set_watermarks_for_clocks_ranges(adev,
+						    &wm_with_clock_ranges);
  }
 
  static void pp_rv_set_pme_wa_enable(struct pp_smu *pp)
  {
  	const struct dc_context *ctx = pp->dm;
  	struct amdgpu_device *adev = ctx->driver_context;
-	void *pp_handle = adev->powerplay.pp_handle;
-	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
 
-	if (pp_funcs && pp_funcs->notify_smu_enable_pwe)
-		pp_funcs->notify_smu_enable_pwe(pp_handle);
+	amdgpu_dpm_notify_smu_enable_pwe(adev);
  }
 
  static void pp_rv_set_active_display_count(struct pp_smu *pp, int count)
  {
  	const struct dc_context *ctx = pp->dm;
  	struct amdgpu_device *adev = ctx->driver_context;
-	void *pp_handle = adev->powerplay.pp_handle;

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c static void pp_rv_set_wm_ranges(struct pp_smu · line 529

Quoted 10 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +1 -5
-	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
 
-	if (!pp_funcs || !pp_funcs->set_active_display_count)
-		return;
-
-	pp_funcs->set_active_display_count(pp_handle, count);
+	amdgpu_dpm_set_active_display_count(adev, count);
  }
 
  static void pp_rv_set_min_deep_sleep_dcfclk(struct pp_smu *pp, int

clock)

Quoted 4 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +0 -1
  {
  	const struct dc_context *ctx = pp->dm;
  	struct amdgpu_device *adev = ctx->driver_context;
-	void *pp_handle = adev->powerplay.pp_handle;

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c static void pp_rv_set_wm_ranges(struct pp_smu · line 537

Quoted 10 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +1 -5
-	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
-
-	if (!pp_funcs || !pp_funcs->set_min_deep_sleep_dcefclk)
-		return;
 
-	pp_funcs->set_min_deep_sleep_dcefclk(pp_handle, clock);
+	amdgpu_dpm_set_min_deep_sleep_dcefclk(adev, clock);
  }
 
  static void pp_rv_set_hard_min_dcefclk_by_freq(struct pp_smu *pp, int

clock)

Quoted 27 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +2 -12
  {
  	const struct dc_context *ctx = pp->dm;
  	struct amdgpu_device *adev = ctx->driver_context;
-	void *pp_handle = adev->powerplay.pp_handle;
-	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
 
-	if (!pp_funcs || !pp_funcs->set_hard_min_dcefclk_by_freq)
-		return;
-
-	pp_funcs->set_hard_min_dcefclk_by_freq(pp_handle, clock);
+	amdgpu_dpm_set_hard_min_dcefclk_by_freq(adev, clock);
  }
 
  static void pp_rv_set_hard_min_fclk_by_freq(struct pp_smu *pp, int mhz)
  {
  	const struct dc_context *ctx = pp->dm;
  	struct amdgpu_device *adev = ctx->driver_context;
-	void *pp_handle = adev->powerplay.pp_handle;
-	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
-
-	if (!pp_funcs || !pp_funcs->set_hard_min_fclk_by_freq)
-		return;
 
-	pp_funcs->set_hard_min_fclk_by_freq(pp_handle, mhz);
+	amdgpu_dpm_set_hard_min_fclk_by_freq(adev, mhz);
  }
 
Quoted 1 line

static enum pp_smu_status pp_nv_set_wm_ranges(struct pp_smu *pp,

@@

Quoted 1 line

-609,11 +554,8 @@ static enum pp_smu_status

pp_nv_set_wm_ranges(struct pp_smu *pp,

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c

Quoted 8 lines
  {
  	const struct dc_context *ctx = pp->dm;
  	struct amdgpu_device *adev = ctx->driver_context;
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +0 -4
-	void *pp_handle = adev->powerplay.pp_handle;
-	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
 
-	if (pp_funcs && pp_funcs->set_watermarks_for_clocks_ranges)
-		pp_funcs->set_watermarks_for_clocks_ranges(pp_handle,

ranges);

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c static enum pp_smu_status

Quoted 5 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +1 -0
+	amdgpu_dpm_set_watermarks_for_clocks_ranges(adev, ranges);
 
  	return PP_SMU_RESULT_OK;
  }
@@ -622,14 +564,13 @@ static enum pp_smu_status

pp_nv_set_display_count(struct pp_smu *pp, int count)

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c static enum pp_smu_status · line 631

Quoted 13 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +3 -5
  {
  	const struct dc_context *ctx = pp->dm;
  	struct amdgpu_device *adev = ctx->driver_context;
-	void *pp_handle = adev->powerplay.pp_handle;
-	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+	int ret = 0;
 
-	if (!pp_funcs || !pp_funcs->set_active_display_count)
+	ret = amdgpu_dpm_set_active_display_count(adev, count);
+	if (ret == -EOPNOTSUPP)
  		return PP_SMU_RESULT_UNSUPPORTED;
-
-	/* 0: successful or smu.ppt_funcs->set_display_count = NULL;  1: fail

*/

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c static enum pp_smu_status · line 573

Quoted 3 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +2 -1
-	if (pp_funcs->set_active_display_count(pp_handle, count))
+	else if (ret)
+		/* 0: successful or smu.ppt_funcs->set_display_count =

NULL; 1:

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c pp_nv_set_min_deep_sleep_dcfclk(struct

Quoted 5 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +1 -0
+fail */
  		return PP_SMU_RESULT_FAIL;
 
  	return PP_SMU_RESULT_OK;
@@ -640,14 +581,13 @@ pp_nv_set_min_deep_sleep_dcfclk(struct

pp_smu *pp, int mhz)

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c pp_nv_set_min_deep_sleep_dcfclk(struct · line 586

Quoted 11 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +1 -5
  {
  	const struct dc_context *ctx = pp->dm;
  	struct amdgpu_device *adev = ctx->driver_context;
-	void *pp_handle = adev->powerplay.pp_handle;
-	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
-
-	if (!pp_funcs || !pp_funcs->set_min_deep_sleep_dcefclk)
-		return PP_SMU_RESULT_UNSUPPORTED;
+	int ret = 0;
 
  	/* 0: successful or smu.ppt_funcs->set_deep_sleep_dcefclk =

NULL;1: fail */

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c static enum pp_smu_status

Quoted 9 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +4 -1
-	if (pp_funcs->set_min_deep_sleep_dcefclk(pp_handle, mhz))
+	ret = amdgpu_dpm_set_min_deep_sleep_dcefclk(adev, mhz);
+	if (ret == -EOPNOTSUPP)
+		return PP_SMU_RESULT_UNSUPPORTED;
+	else if (ret)
  		return PP_SMU_RESULT_FAIL;
 
  	return PP_SMU_RESULT_OK;
@@ -658,12 +598,8 @@ static enum pp_smu_status

pp_nv_set_hard_min_dcefclk_by_freq(

Quoted 13 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +1 -5
  {
  	const struct dc_context *ctx = pp->dm;
  	struct amdgpu_device *adev = ctx->driver_context;
-	void *pp_handle = adev->powerplay.pp_handle;
-	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
  	struct pp_display_clock_request clock_req;
-
-	if (!pp_funcs || !pp_funcs->display_clock_voltage_request)
-		return PP_SMU_RESULT_UNSUPPORTED;
+	int ret = 0;
 
  	clock_req.clock_type = amd_pp_dcef_clock;
  	clock_req.clock_freq_in_khz = mhz * 1000; @@ -671,7 +607,10 @@
Quoted 2 lines

static enum pp_smu_status pp_nv_set_hard_min_dcefclk_by_freq(
/* 0: successful or smu.ppt_funcs->display_clock_voltage_request =

NULL

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c

Quoted 3 lines

* 1: fail
*/

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +0 -1
-	if (pp_funcs->display_clock_voltage_request(pp_handle,

&clock_req))

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c

Quoted 1 line
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +1 -0
+	ret = amdgpu_dpm_display_clock_voltage_request(adev,

&clock_req);

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c pp_nv_set_hard_min_uclk_by_freq(struct

Quoted 7 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +3 -0
+	if (ret == -EOPNOTSUPP)
+		return PP_SMU_RESULT_UNSUPPORTED;
+	else if (ret)
  		return PP_SMU_RESULT_FAIL;
 
  	return PP_SMU_RESULT_OK;
@@ -682,12 +621,8 @@ pp_nv_set_hard_min_uclk_by_freq(struct

pp_smu *pp, int mhz)

Quoted 13 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +1 -5
  {
  	const struct dc_context *ctx = pp->dm;
  	struct amdgpu_device *adev = ctx->driver_context;
-	void *pp_handle = adev->powerplay.pp_handle;
-	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
  	struct pp_display_clock_request clock_req;
-
-	if (!pp_funcs || !pp_funcs->display_clock_voltage_request)
-		return PP_SMU_RESULT_UNSUPPORTED;
+	int ret = 0;
 
  	clock_req.clock_type = amd_pp_mem_clock;
  	clock_req.clock_freq_in_khz = mhz * 1000; @@ -695,7 +630,10 @@
Quoted 2 lines

pp_nv_set_hard_min_uclk_by_freq(struct pp_smu *pp, int mhz)
/* 0: successful or smu.ppt_funcs->display_clock_voltage_request =

NULL

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c

Quoted 3 lines

* 1: fail
*/

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +0 -1
-	if (pp_funcs->display_clock_voltage_request(pp_handle,

&clock_req))

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c

Quoted 1 line
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +1 -0
+	ret = amdgpu_dpm_display_clock_voltage_request(adev,

&clock_req);

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c static enum pp_smu_status

Quoted 7 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +3 -0
+	if (ret == -EOPNOTSUPP)
+		return PP_SMU_RESULT_UNSUPPORTED;
+	else if (ret)
  		return PP_SMU_RESULT_FAIL;
 
  	return PP_SMU_RESULT_OK;
@@ -706,14 +644,10 @@ static enum pp_smu_status

pp_nv_set_pstate_handshake_support(

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c static enum pp_smu_status · line 715

Quoted 10 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +0 -5
  {
  	const struct dc_context *ctx = pp->dm;
  	struct amdgpu_device *adev = ctx->driver_context;
-	void *pp_handle = adev->powerplay.pp_handle;
-	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
 
-	if (pp_funcs && pp_funcs->display_disable_memory_clock_switch) {
-		if (pp_funcs-
 display_disable_memory_clock_switch(pp_handle,
-

!pstate_handshake_supported))

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c static enum pp_smu_status · line 650

Quoted 4 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +2 -2
-			return PP_SMU_RESULT_FAIL;
-	}
+	if (amdgpu_dpm_display_disable_memory_clock_switch(adev,
+

!pstate_handshake_supported))

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c static enum pp_smu_status

Quoted 5 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +1 -0
+		return PP_SMU_RESULT_FAIL;
 
  	return PP_SMU_RESULT_OK;
  }
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +0 -0
@@ -723,12 +657,8 @@ static enum pp_smu_status

pp_nv_set_voltage_by_freq(struct pp_smu *pp,

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c static enum pp_smu_status

Quoted 14 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +1 -5
  {
  	const struct dc_context *ctx = pp->dm;
  	struct amdgpu_device *adev = ctx->driver_context;
-	void *pp_handle = adev->powerplay.pp_handle;
-	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
  	struct pp_display_clock_request clock_req;
-
-	if (!pp_funcs || !pp_funcs->display_clock_voltage_request)
-		return PP_SMU_RESULT_UNSUPPORTED;
+	int ret = 0;
 
  	switch (clock_id) {
  	case PP_SMU_NV_DISPCLK:
@@ -748,7 +678,10 @@ static enum pp_smu_status

pp_nv_set_voltage_by_freq(struct pp_smu *pp,

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c static enum pp_smu_status · line 678

Quoted 1 line
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +0 -0
  	/* 0: successful or smu.ppt_funcs->display_clock_voltage_request =

NULL

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c static enum pp_smu_status · line 751

Quoted 3 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +0 -1
  	 * 1: fail
  	 */
-	if (pp_funcs->display_clock_voltage_request(pp_handle,

&clock_req))

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c static enum pp_smu_status · line 681

Quoted 1 line
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +1 -0
+	ret = amdgpu_dpm_display_clock_voltage_request(adev,

&clock_req);

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c static enum pp_smu_status

Quoted 7 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +3 -0
+	if (ret == -EOPNOTSUPP)
+		return PP_SMU_RESULT_UNSUPPORTED;
+	else if (ret)
  		return PP_SMU_RESULT_FAIL;
 
  	return PP_SMU_RESULT_OK;
@@ -759,16 +692,16 @@ static enum pp_smu_status

pp_nv_get_maximum_sustainable_clocks(

Quoted 6 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +1 -2
  {
  	const struct dc_context *ctx = pp->dm;
  	struct amdgpu_device *adev = ctx->driver_context;
-	void *pp_handle = adev->powerplay.pp_handle;
-	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+	int ret = 0;

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c static enum pp_smu_status · line 768

Quoted 10 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +5 -2
 
-	if (!pp_funcs || !pp_funcs->get_max_sustainable_clocks_by_dc)
+	ret = amdgpu_dpm_get_max_sustainable_clocks_by_dc(adev,
+							  max_clocks);
+	if (ret == -EOPNOTSUPP)
  		return PP_SMU_RESULT_UNSUPPORTED;
+	else if (ret)
+		return PP_SMU_RESULT_FAIL;
 
-	if (!pp_funcs->get_max_sustainable_clocks_by_dc(pp_handle,

max_clocks))

Quoted 8 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +1 -3
-		return PP_SMU_RESULT_OK;
-
-	return PP_SMU_RESULT_FAIL;
+	return PP_SMU_RESULT_OK;
  }
 
  static enum pp_smu_status pp_nv_get_uclk_dpm_states(struct pp_smu

*pp, @@ -776,18 +709,17 @@ static enum pp_smu_status

pp_nv_get_uclk_dpm_states(struct pp_smu *pp,

Quoted 39 lines
  {
  	const struct dc_context *ctx = pp->dm;
  	struct amdgpu_device *adev = ctx->driver_context;
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +13 -12
-	void *pp_handle = adev->powerplay.pp_handle;
-	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+	int ret = 0;
 
-	if (!pp_funcs || !pp_funcs->get_uclk_dpm_states)
+	ret = amdgpu_dpm_get_uclk_dpm_states(adev,
+					     clock_values_in_khz,
+					    num_states);
+	if (ret == -EOPNOTSUPP)
  		return PP_SMU_RESULT_UNSUPPORTED;
+	else if (ret)
+		return PP_SMU_RESULT_FAIL;
 
-	if (!pp_funcs->get_uclk_dpm_states(pp_handle,
-					   clock_values_in_khz,
-					   num_states))
-		return PP_SMU_RESULT_OK;
-
-	return PP_SMU_RESULT_FAIL;
+	return PP_SMU_RESULT_OK;
  }
 
  static enum pp_smu_status pp_rn_get_dpm_clock_table( @@ -795,16
+727,15 @@ static enum pp_smu_status pp_rn_get_dpm_clock_table(
  {
  	const struct dc_context *ctx = pp->dm;
  	struct amdgpu_device *adev = ctx->driver_context;
-	void *pp_handle = adev->powerplay.pp_handle;
-	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+	int ret = 0;
 
-	if (!pp_funcs || !pp_funcs->get_dpm_clock_table)
+	ret = amdgpu_dpm_get_dpm_clock_table(adev, clock_table);
+	if (ret == -EOPNOTSUPP)
  		return PP_SMU_RESULT_UNSUPPORTED;
+	else if (ret)

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c

Quoted 10 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +2 -4
+		return PP_SMU_RESULT_FAIL;
 
-	if (!pp_funcs->get_dpm_clock_table(pp_handle, clock_table))
-		return PP_SMU_RESULT_OK;
-
-	return PP_SMU_RESULT_FAIL;
+	return PP_SMU_RESULT_OK;
  }
 
  static enum pp_smu_status pp_rn_set_wm_ranges(struct pp_smu *pp,

@@

Quoted 1 line

-812,11 +743,8 @@ static enum pp_smu_status

pp_rn_set_wm_ranges(struct pp_smu *pp,

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c

Quoted 8 lines
  {
  	const struct dc_context *ctx = pp->dm;
  	struct amdgpu_device *adev = ctx->driver_context;
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +0 -4
-	void *pp_handle = adev->powerplay.pp_handle;
-	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
 
-	if (pp_funcs && pp_funcs->set_watermarks_for_clocks_ranges)
-		pp_funcs->set_watermarks_for_clocks_ranges(pp_handle,

ranges);

drivers/gpu/drm/amd/pm/amdgpu_dpm.c int amdgpu_dpm_set_soft_freq_range(struct

Quoted 10 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +1 -0
+	amdgpu_dpm_set_watermarks_for_clocks_ranges(adev, ranges);
 
  	return PP_SMU_RESULT_OK;
  }
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +0 -0
index 2c789eb5d066..3a84c3995f2d 100644
@@ -1659,6 +1659,14 @@ int amdgpu_dpm_set_soft_freq_range(struct

amdgpu_device *adev,

drivers/gpu/drm/amd/pm/amdgpu_dpm.c int amdgpu_dpm_set_soft_freq_range(struct amdgpu_device *adev, · line 1662

Quoted 4 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +1 -0
  	}
  }
 
+int amdgpu_dpm_write_watermarks_table(struct amdgpu_device *adev)

{

Quoted 10 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +6 -0
+	if (!is_support_sw_smu(adev))
+		return 0;
+
+	return smu_write_watermarks_table(&adev->smu);
+}
+
  int amdgpu_dpm_wait_for_event(struct amdgpu_device *adev,
  			      enum smu_event_type event,
  			      uint64_t event_arg)

drivers/gpu/drm/amd/pm/amdgpu_dpm.c void amdgpu_dpm_stb_debug_fs_init(struct

Quoted 6 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +2 -0
@@ -2158,3 +2166,213 @@ void amdgpu_dpm_stb_debug_fs_init(struct
 amdgpu_device *adev)
 
  	amdgpu_smu_stb_debug_fs_init(adev);
  }
+
+int amdgpu_dpm_display_configuration_change(struct amdgpu_device

*adev,

drivers/gpu/drm/amd/pm/amdgpu_dpm.c

Quoted 1 line
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +1 -0
+					    const struct

amd_pp_display_configuration *input) {

drivers/gpu/drm/amd/pm/amdgpu_dpm.c void amdgpu_dpm_stb_debug_fs_init(struct amdgpu_device *adev) · line 2177

Quoted 5 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +5 -0
+	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+
+	if (!pp_funcs->display_configuration_change)
+		return 0;
+

Same comments as in the other patch. Let the caller decide what to do when operation is not supported.

Quoted 10 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +1 -0
+	return pp_funcs->display_configuration_change(adev-

powerplay.pp_handle,

drivers/gpu/drm/amd/pm/amdgpu_dpm.c +8 -0
+						      input);
+}
+
+int amdgpu_dpm_get_clock_by_type(struct amdgpu_device *adev,
+				 enum amd_pp_clock_type type,
+				 struct amd_pp_clocks *clocks)
+{
+	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;

drivers/gpu/drm/amd/pm/amdgpu_dpm.c void amdgpu_dpm_stb_debug_fs_init(struct amdgpu_device *adev)

Quoted 10 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +10 -0
+
+	if (!pp_funcs->get_clock_by_type)
+		return 0;
+
+	return pp_funcs->get_clock_by_type(adev->powerplay.pp_handle,
+					   type,
+					   clocks);
+}
+
+int amdgpu_dpm_get_display_mode_validation_clks(struct

amdgpu_device *adev,

drivers/gpu/drm/amd/pm/amdgpu_dpm.c

Quoted 1 line
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +1 -0
+						struct

amd_pp_simple_clock_info *clocks) {

drivers/gpu/drm/amd/pm/amdgpu_dpm.c void amdgpu_dpm_stb_debug_fs_init(struct amdgpu_device *adev)

Quoted 11 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +6 -0
+	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+
+	if (!pp_funcs->get_display_mode_validation_clocks)
+		return 0;
+
+	return pp_funcs->get_display_mode_validation_clocks(adev-

powerplay.pp_handle,

drivers/gpu/drm/amd/pm/amdgpu_dpm.c +4 -0
+							    clocks);
+}
+
+int amdgpu_dpm_get_clock_by_type_with_latency(struct

amdgpu_device *adev,

drivers/gpu/drm/amd/pm/amdgpu_dpm.c

Quoted 2 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +2 -0
+					      enum amd_pp_clock_type type,
+					      struct

pp_clock_levels_with_latency *clocks) {

drivers/gpu/drm/amd/pm/amdgpu_dpm.c void amdgpu_dpm_stb_debug_fs_init(struct amdgpu_device *adev)

Quoted 12 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +6 -0
+	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+
+	if (!pp_funcs->get_clock_by_type_with_latency)
+		return 0;
+
+	return pp_funcs->get_clock_by_type_with_latency(adev-

powerplay.pp_handle,

drivers/gpu/drm/amd/pm/amdgpu_dpm.c +5 -0
+							type,
+							clocks);
+}
+
+int amdgpu_dpm_get_clock_by_type_with_voltage(struct

amdgpu_device *adev,

drivers/gpu/drm/amd/pm/amdgpu_dpm.c

Quoted 2 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +2 -0
+					      enum amd_pp_clock_type type,
+					      struct

pp_clock_levels_with_voltage *clocks) {

drivers/gpu/drm/amd/pm/amdgpu_dpm.c void amdgpu_dpm_stb_debug_fs_init(struct amdgpu_device *adev)

Quoted 12 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +6 -0
+	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+
+	if (!pp_funcs->get_clock_by_type_with_voltage)
+		return 0;
+
+	return pp_funcs->get_clock_by_type_with_voltage(adev-

powerplay.pp_handle,

drivers/gpu/drm/amd/pm/amdgpu_dpm.c +5 -0
+							type,
+							clocks);
+}
+
+int amdgpu_dpm_set_watermarks_for_clocks_ranges(struct

amdgpu_device *adev,

drivers/gpu/drm/amd/pm/amdgpu_dpm.c void amdgpu_dpm_stb_debug_fs_init(struct amdgpu_device *adev)

Quoted 13 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +8 -0
+					       void *clock_ranges)
+{
+	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+
+	if (!pp_funcs->set_watermarks_for_clocks_ranges)
+		return -EOPNOTSUPP;
+
+	return pp_funcs->set_watermarks_for_clocks_ranges(adev-

powerplay.pp_handle,

drivers/gpu/drm/amd/pm/amdgpu_dpm.c +4 -0
+							  clock_ranges);
+}
+
+int amdgpu_dpm_display_clock_voltage_request(struct amdgpu_device

*adev,

drivers/gpu/drm/amd/pm/amdgpu_dpm.c

Quoted 1 line
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +1 -0
+					     struct pp_display_clock_request

*clock) {

Quoted 12 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +6 -0
+	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+
+	if (!pp_funcs->display_clock_voltage_request)
+		return -EOPNOTSUPP;
+
+	return pp_funcs->display_clock_voltage_request(adev-

powerplay.pp_handle,

drivers/gpu/drm/amd/pm/amdgpu_dpm.c +5 -0
+						       clock);
+}
+
+int amdgpu_dpm_get_current_clocks(struct amdgpu_device *adev,
+				  struct amd_pp_clock_info *clocks) {

drivers/gpu/drm/amd/pm/amdgpu_dpm.c void amdgpu_dpm_stb_debug_fs_init(struct amdgpu_device *adev)

Quoted 10 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +10 -0
+	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+
+	if (!pp_funcs->get_current_clocks)
+		return -EOPNOTSUPP;
+
+	return pp_funcs->get_current_clocks(adev->powerplay.pp_handle,
+					    clocks);
+}
+
+void amdgpu_dpm_notify_smu_enable_pwe(struct amdgpu_device

*adev) {

Quoted 9 lines

drivers/gpu/drm/amd/pm/amdgpu_dpm.c void amdgpu_dpm_stb_debug_fs_init(struct amdgpu_device *adev) · line 2278

Quoted 5 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +5 -0
+	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+
+	if (!pp_funcs->notify_smu_enable_pwe)
+		return;
+

These void funcs also need to have valid return value and if operation is not supported, let the caller know. Implementation in a particular context vs when refactored into standalone APIs need not be the same.

[Quan, Evan] I agree we can change the return values here. But I would like to do that in follow-up patches. For this patch series, let's just stick to original logics/return values.
We do not have to involve extra changes/risk here as this patch series itself is already quite a big chunk(with quite risk).

BR
Evan

Quoted 198 lines

Thanks,
Lijo

Quoted 13 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +12 -0
+	pp_funcs->notify_smu_enable_pwe(adev->powerplay.pp_handle);
+}
+
+int amdgpu_dpm_set_active_display_count(struct amdgpu_device *adev,
+					uint32_t count)
+{
+	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+
+	if (!pp_funcs->set_active_display_count)
+		return -EOPNOTSUPP;
+
+	return pp_funcs->set_active_display_count(adev-

powerplay.pp_handle,

drivers/gpu/drm/amd/pm/amdgpu_dpm.c void amdgpu_dpm_stb_debug_fs_init(struct amdgpu_device *adev)

Quoted 4 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +4 -0
+						  count);
+}
+
+int amdgpu_dpm_set_min_deep_sleep_dcefclk(struct amdgpu_device

*adev,

drivers/gpu/drm/amd/pm/amdgpu_dpm.c void amdgpu_dpm_stb_debug_fs_init(struct amdgpu_device *adev)

Quoted 13 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +8 -0
+					  uint32_t clock)
+{
+	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+
+	if (!pp_funcs->set_min_deep_sleep_dcefclk)
+		return -EOPNOTSUPP;
+
+	return pp_funcs->set_min_deep_sleep_dcefclk(adev-

powerplay.pp_handle,

drivers/gpu/drm/amd/pm/amdgpu_dpm.c +4 -0
+						    clock);
+}
+
+void amdgpu_dpm_set_hard_min_dcefclk_by_freq(struct

amdgpu_device *adev,

drivers/gpu/drm/amd/pm/amdgpu_dpm.c void amdgpu_dpm_stb_debug_fs_init(struct amdgpu_device *adev)

Quoted 13 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +8 -0
+					     uint32_t clock)
+{
+	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+
+	if (!pp_funcs->set_hard_min_dcefclk_by_freq)
+		return;
+
+	pp_funcs->set_hard_min_dcefclk_by_freq(adev-

powerplay.pp_handle,

drivers/gpu/drm/amd/pm/amdgpu_dpm.c +4 -0
+					       clock);
+}
+
+void amdgpu_dpm_set_hard_min_fclk_by_freq(struct amdgpu_device

*adev,

drivers/gpu/drm/amd/pm/amdgpu_dpm.c void amdgpu_dpm_stb_debug_fs_init(struct amdgpu_device *adev)

Quoted 13 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +8 -0
+					  uint32_t clock)
+{
+	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+
+	if (!pp_funcs->set_hard_min_fclk_by_freq)
+		return;
+
+	pp_funcs->set_hard_min_fclk_by_freq(adev-

powerplay.pp_handle,

drivers/gpu/drm/amd/pm/amdgpu_dpm.c +4 -0
+					    clock);
+}
+
+int amdgpu_dpm_display_disable_memory_clock_switch(struct

amdgpu_device *adev,

drivers/gpu/drm/amd/pm/amdgpu_dpm.c

Quoted 1 line
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +1 -0
+						   bool

disable_memory_clock_switch) {

Quoted 8 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +6 -0
+	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+
+	if (!pp_funcs->display_disable_memory_clock_switch)
+		return 0;
+
+	return pp_funcs->display_disable_memory_clock_switch(adev-

powerplay.pp_handle,
+

disable_memory_clock_switch); }

drivers/gpu/drm/amd/pm/amdgpu_dpm.c

Quoted 2 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +2 -0
+
+int amdgpu_dpm_get_max_sustainable_clocks_by_dc(struct

amdgpu_device *adev,

drivers/gpu/drm/amd/pm/amdgpu_dpm.c

Quoted 1 line
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +1 -0
+						struct

pp_smu_nv_clock_table *max_clocks) {

drivers/gpu/drm/amd/pm/amdgpu_dpm.c void amdgpu_dpm_stb_debug_fs_init(struct amdgpu_device *adev)

Quoted 11 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +6 -0
+	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+
+	if (!pp_funcs->get_max_sustainable_clocks_by_dc)
+		return -EOPNOTSUPP;
+
+	return pp_funcs->get_max_sustainable_clocks_by_dc(adev-

powerplay.pp_handle,

drivers/gpu/drm/amd/pm/amdgpu_dpm.c +4 -0
+							  max_clocks);
+}
+
+enum pp_smu_status amdgpu_dpm_get_uclk_dpm_states(struct

amdgpu_device *adev,

drivers/gpu/drm/amd/pm/amdgpu_dpm.c

Quoted 1 line
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +1 -0
+						  unsigned int

*clock_values_in_khz,

drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h int amdgpu_dpm_set_soft_freq_range(struct

Quoted 30 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +8 -0
+						  unsigned int *num_states)
+{
+	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+
+	if (!pp_funcs->get_uclk_dpm_states)
+		return -EOPNOTSUPP;
+
+	return pp_funcs->get_uclk_dpm_states(adev-

powerplay.pp_handle,

drivers/gpu/drm/amd/pm/amdgpu_dpm.c +12 -0
+					     clock_values_in_khz,
+					     num_states);
+}
+
+int amdgpu_dpm_get_dpm_clock_table(struct amdgpu_device *adev,
+				   struct dpm_clocks *clock_table) {
+	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+
+	if (!pp_funcs->get_dpm_clock_table)
+		return -EOPNOTSUPP;
+
+	return pp_funcs->get_dpm_clock_table(adev-

powerplay.pp_handle,

drivers/gpu/drm/amd/pm/amdgpu_dpm.c +2 -0
+					     clock_table);
+}
drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h +0 -0
index 039c40b1d0cb..fea203a79cb4 100644
@@ -500,6 +500,7 @@ int amdgpu_dpm_set_soft_freq_range(struct

amdgpu_device *adev,

drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h int amdgpu_dpm_set_soft_freq_range(struct amdgpu_device *adev,

Quoted 4 lines
drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h +1 -0
  				        enum pp_clock_type type,
  				        uint32_t min,
  				        uint32_t max);
+int amdgpu_dpm_write_watermarks_table(struct amdgpu_device

*adev);

drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h int amdgpu_dpm_set_soft_freq_range(struct · line 504

Quoted 1 line
drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h +0 -0
  int amdgpu_dpm_wait_for_event(struct amdgpu_device *adev, enum

smu_event_type event,

Quoted 3 lines
drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h +0 -0
  		       uint64_t event_arg);
  int amdgpu_dpm_get_status_gfxoff(struct amdgpu_device *adev,

uint32_t *value); @@ -578,4 +579,41 @@ int

amdgpu_dpm_set_pp_table(struct amdgpu_device *adev,

Quoted 4 lines

size_t size);
int amdgpu_dpm_get_num_cpu_cores(struct amdgpu_device *adev); void amdgpu_dpm_stb_debug_fs_init(struct amdgpu_device *adev);
+int amdgpu_dpm_display_configuration_change(struct amdgpu_device

*adev,

drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h

Quoted 1 line
drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h +1 -0
+					    const struct

amd_pp_display_configuration *input); int

drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h int amdgpu_dpm_set_pp_table(struct amdgpu_device *adev,

Quoted 4 lines
drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h +4 -0
+amdgpu_dpm_get_clock_by_type(struct amdgpu_device *adev,
+				 enum amd_pp_clock_type type,
+				 struct amd_pp_clocks *clocks);
+int amdgpu_dpm_get_display_mode_validation_clks(struct

amdgpu_device *adev,

drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h

Quoted 1 line
drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h +1 -0
+						struct

amd_pp_simple_clock_info *clocks); int

Quoted 1 line

+amdgpu_dpm_get_clock_by_type_with_latency(struct amdgpu_device

*adev,

drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h

Quoted 2 lines
drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h +2 -0
+					      enum amd_pp_clock_type type,
+					      struct

pp_clock_levels_with_latency *clocks); int

Quoted 1 line

+amdgpu_dpm_get_clock_by_type_with_voltage(struct amdgpu_device

*adev,

drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h

Quoted 2 lines
drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h +2 -0
+					      enum amd_pp_clock_type type,
+					      struct

pp_clock_levels_with_voltage *clocks); int

Quoted 1 line

+amdgpu_dpm_set_watermarks_for_clocks_ranges(struct

amdgpu_device *adev,

drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h

Quoted 2 lines
drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h +2 -0
+					       void *clock_ranges);
+int amdgpu_dpm_display_clock_voltage_request(struct amdgpu_device

*adev,

drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h

Quoted 1 line
drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h +1 -0
+					     struct pp_display_clock_request

*clock); int

drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h

Quoted 3 lines
drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h +3 -0
+amdgpu_dpm_get_current_clocks(struct amdgpu_device *adev,
+				  struct amd_pp_clock_info *clocks); void
+amdgpu_dpm_notify_smu_enable_pwe(struct amdgpu_device *adev);

int

drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h

Quoted 3 lines
drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h +3 -0
+amdgpu_dpm_set_active_display_count(struct amdgpu_device *adev,
+					uint32_t count);
+int amdgpu_dpm_set_min_deep_sleep_dcefclk(struct amdgpu_device

*adev,

drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h

Quoted 2 lines
drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h +2 -0
+					  uint32_t clock);
+void amdgpu_dpm_set_hard_min_dcefclk_by_freq(struct

amdgpu_device *adev,

drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h

Quoted 2 lines
drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h +2 -0
+					     uint32_t clock);
+void amdgpu_dpm_set_hard_min_fclk_by_freq(struct amdgpu_device

*adev,

drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h

Quoted 2 lines
drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h +2 -0
+					  uint32_t clock);
+int amdgpu_dpm_display_disable_memory_clock_switch(struct

amdgpu_device *adev,

drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h

Quoted 1 line
drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h +1 -0
+						   bool

disable_memory_clock_switch); int

Quoted 1 line

+amdgpu_dpm_get_max_sustainable_clocks_by_dc(struct

amdgpu_device *adev,

drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h

Quoted 1 line
drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h +1 -0
+						struct

pp_smu_nv_clock_table *max_clocks); enum pp_smu_status

drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h

Quoted 2 lines
drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h +2 -0
+amdgpu_dpm_get_uclk_dpm_states(struct amdgpu_device *adev,
+						  unsigned int

*clock_values_in_khz,

Quoted 5 lines
drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h +3 -0
+						  unsigned int *num_states);
+int amdgpu_dpm_get_dpm_clock_table(struct amdgpu_device *adev,
+				   struct dpm_clocks *clock_table);
  #endif
author
#9 lore raw

PATCH v4 4/17 drm/amd/pm: do not expose those APIs used internally only in amdgpu_dpm.c

In reply to Evan Quan

Move them to amdgpu_dpm.c instead.

Change-Id I59fe0efcb47c18ec7254f3624db7a2eb78d91b8c
---
 drivers/gpu/drm/amd/pm/amdgpu_dpm.c     | 25 +++++++++++++++++++++++--
 drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h | 23 -----------------------
 2 files changed, 23 insertions(+), 25 deletions(-)
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +23 -2
index 3a84c3995f2d..72a8cb70d36b 100644
@@ -34,6 +34,27 @@
 
 #define WIDTH_4K 3840
 
+#define amdgpu_dpm_pre_set_power_state(adev) \
+		((adev)->powerplay.pp_funcs->pre_set_power_state((adev)->powerplay.pp_handle))
+
+#define amdgpu_dpm_post_set_power_state(adev) \
+		((adev)->powerplay.pp_funcs->post_set_power_state((adev)->powerplay.pp_handle))
+
+#define amdgpu_dpm_display_configuration_changed(adev) \
+		((adev)->powerplay.pp_funcs->display_configuration_changed((adev)->powerplay.pp_handle))
+
+#define amdgpu_dpm_print_power_state(adev, ps) \
+		((adev)->powerplay.pp_funcs->print_power_state((adev)->powerplay.pp_handle, (ps)))
+
+#define amdgpu_dpm_vblank_too_short(adev) \
+		((adev)->powerplay.pp_funcs->vblank_too_short((adev)->powerplay.pp_handle))
+
+#define amdgpu_dpm_enable_bapm(adev, e) \
+		((adev)->powerplay.pp_funcs->enable_bapm((adev)->powerplay.pp_handle, (e)))
+
+#define amdgpu_dpm_check_state_equal(adev, cps, rps, equal) \
+		((adev)->powerplay.pp_funcs->check_state_equal((adev)->powerplay.pp_handle, (cps), (rps), (equal)))
+
 void amdgpu_dpm_print_class_info(u32 class, u32 class2)
 {
 	const char *s;
@@ -120,7 +141,7 @@ void amdgpu_dpm_print_ps_status(struct amdgpu_device *adev,
 	pr_cont("\n");
 }
 
-void amdgpu_dpm_get_active_displays(struct amdgpu_device *adev)
+static void amdgpu_dpm_get_active_displays(struct amdgpu_device *adev)
 {
 	struct drm_device *ddev = adev_to_drm(adev);
 	struct drm_crtc *crtc;
@@ -168,7 +189,7 @@ u32 amdgpu_dpm_get_vblank_time(struct amdgpu_device *adev)
 	return vblank_time_us;
 }
 
-u32 amdgpu_dpm_get_vrefresh(struct amdgpu_device *adev)
+static u32 amdgpu_dpm_get_vrefresh(struct amdgpu_device *adev)
 {
 	struct drm_device *dev = adev_to_drm(adev);
 	struct drm_crtc *crtc;
drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h +0 -23
index fea203a79cb4..6681b878e75f 100644
@@ -259,27 +259,6 @@ enum amdgpu_pcie_gen {
 	AMDGPU_PCIE_GEN_INVALID = 0xffff
 };
 
-#define amdgpu_dpm_pre_set_power_state(adev) \
-		((adev)->powerplay.pp_funcs->pre_set_power_state((adev)->powerplay.pp_handle))
-
-#define amdgpu_dpm_post_set_power_state(adev) \
-		((adev)->powerplay.pp_funcs->post_set_power_state((adev)->powerplay.pp_handle))
-
-#define amdgpu_dpm_display_configuration_changed(adev) \
-		((adev)->powerplay.pp_funcs->display_configuration_changed((adev)->powerplay.pp_handle))
-
-#define amdgpu_dpm_print_power_state(adev, ps) \
-		((adev)->powerplay.pp_funcs->print_power_state((adev)->powerplay.pp_handle, (ps)))
-
-#define amdgpu_dpm_vblank_too_short(adev) \
-		((adev)->powerplay.pp_funcs->vblank_too_short((adev)->powerplay.pp_handle))
-
-#define amdgpu_dpm_enable_bapm(adev, e) \
-		((adev)->powerplay.pp_funcs->enable_bapm((adev)->powerplay.pp_handle, (e)))
-
-#define amdgpu_dpm_check_state_equal(adev, cps, rps, equal) \
-		((adev)->powerplay.pp_funcs->check_state_equal((adev)->powerplay.pp_handle, (cps), (rps), (equal)))
-
 #define amdgpu_dpm_reset_power_profile_state(adev, request) \
 		((adev)->powerplay.pp_funcs->reset_power_profile_state(\
 			(adev)->powerplay.pp_handle, request))
@@ -412,8 +391,6 @@ void amdgpu_dpm_print_cap_info(u32 caps);
 void amdgpu_dpm_print_ps_status(struct amdgpu_device *adev,
 				struct amdgpu_ps *rps);
 u32 amdgpu_dpm_get_vblank_time(struct amdgpu_device *adev);
-u32 amdgpu_dpm_get_vrefresh(struct amdgpu_device *adev);
-void amdgpu_dpm_get_active_displays(struct amdgpu_device *adev);
 int amdgpu_dpm_read_sensor(struct amdgpu_device *adev, enum amd_pp_sensors sensor,
 			   void *data, uint32_t *size);
 
Signature · 1 line
2.29.0
author
#10 lore raw

PATCH v4 5/17 drm/amd/pm: do not expose those APIs used internally only in si_dpm.c

In reply to Evan Quan

Move them to si_dpm.c instead.

Change-Id I288205cfd7c6ba09cfb22626ff70360d61ff0c67

--
v1->v2:
- rename the API with "si_" prefix(Alex)
v2->v3:
- rename other data structures used only in si_dpm.c(Lijo)

---
 drivers/gpu/drm/amd/pm/amdgpu_dpm.c       |  25 -----
 drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h   |  25 -----
 drivers/gpu/drm/amd/pm/powerplay/si_dpm.c | 106 +++++++++++++++-------
 drivers/gpu/drm/amd/pm/powerplay/si_dpm.h |  15 ++-
 4 files changed, 83 insertions(+), 88 deletions(-)
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +0 -25
index 72a8cb70d36b..b31858ad9b83 100644
@@ -894,31 +894,6 @@ void amdgpu_add_thermal_controller(struct amdgpu_device *adev)
 	}
 }
 
-enum amdgpu_pcie_gen amdgpu_get_pcie_gen_support(struct amdgpu_device *adev,
-						 u32 sys_mask,
-						 enum amdgpu_pcie_gen asic_gen,
-						 enum amdgpu_pcie_gen default_gen)
-{
-	switch (asic_gen) {
-	case AMDGPU_PCIE_GEN1:
-		return AMDGPU_PCIE_GEN1;
-	case AMDGPU_PCIE_GEN2:
-		return AMDGPU_PCIE_GEN2;
-	case AMDGPU_PCIE_GEN3:
-		return AMDGPU_PCIE_GEN3;
-	default:
-		if ((sys_mask & CAIL_PCIE_LINK_SPEED_SUPPORT_GEN3) &&
-		    (default_gen == AMDGPU_PCIE_GEN3))
-			return AMDGPU_PCIE_GEN3;
-		else if ((sys_mask & CAIL_PCIE_LINK_SPEED_SUPPORT_GEN2) &&
-			 (default_gen == AMDGPU_PCIE_GEN2))
-			return AMDGPU_PCIE_GEN2;
-		else
-			return AMDGPU_PCIE_GEN1;
-	}
-	return AMDGPU_PCIE_GEN1;
-}
-
 struct amd_vce_state*
 amdgpu_get_vce_clock_state(void *handle, u32 idx)
 {
drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h +0 -25
index 6681b878e75f..f43b96dfe9d8 100644
@@ -45,19 +45,6 @@ enum amdgpu_int_thermal_type {
 	THERMAL_TYPE_KV,
 };
 
-enum amdgpu_dpm_auto_throttle_src {
-	AMDGPU_DPM_AUTO_THROTTLE_SRC_THERMAL,
-	AMDGPU_DPM_AUTO_THROTTLE_SRC_EXTERNAL
-};
-
-enum amdgpu_dpm_event_src {
-	AMDGPU_DPM_EVENT_SRC_ANALOG = 0,
-	AMDGPU_DPM_EVENT_SRC_EXTERNAL = 1,
-	AMDGPU_DPM_EVENT_SRC_DIGITAL = 2,
-	AMDGPU_DPM_EVENT_SRC_ANALOG_OR_EXTERNAL = 3,
-	AMDGPU_DPM_EVENT_SRC_DIGIAL_OR_EXTERNAL = 4
-};
-
 struct amdgpu_ps {
 	u32 caps; /* vbios flags */
 	u32 class; /* vbios flags */
@@ -252,13 +239,6 @@ struct amdgpu_dpm_fan {
 	bool ucode_fan_control;
 };
 
-enum amdgpu_pcie_gen {
-	AMDGPU_PCIE_GEN1 = 0,
-	AMDGPU_PCIE_GEN2 = 1,
-	AMDGPU_PCIE_GEN3 = 2,
-	AMDGPU_PCIE_GEN_INVALID = 0xffff
-};
-
 #define amdgpu_dpm_reset_power_profile_state(adev, request) \
 		((adev)->powerplay.pp_funcs->reset_power_profile_state(\
 			(adev)->powerplay.pp_handle, request))
@@ -403,11 +383,6 @@ void amdgpu_free_extended_power_table(struct amdgpu_device *adev);
 
 void amdgpu_add_thermal_controller(struct amdgpu_device *adev);
 
-enum amdgpu_pcie_gen amdgpu_get_pcie_gen_support(struct amdgpu_device *adev,
-						 u32 sys_mask,
-						 enum amdgpu_pcie_gen asic_gen,
-						 enum amdgpu_pcie_gen default_gen);
-
 struct amd_vce_state*
 amdgpu_get_vce_clock_state(void *handle, u32 idx);
 
drivers/gpu/drm/amd/pm/powerplay/si_dpm.c +72 -34

212 lines not on this page · raw message

drivers/gpu/drm/amd/pm/powerplay/si_dpm.h +11 -4
index bc0be6818e21..77614ff10df6 100644
@@ -595,13 +595,20 @@ struct rv7xx_power_info {
 	RV770_SMC_STATETABLE smc_statetable;
 };
 
+enum si_pcie_gen {
+	PCIE_GEN1 = 0,
+	PCIE_GEN2 = 1,
+	PCIE_GEN3 = 2,
+	PCIE_GEN_INVALID = 0xffff
+};
+
 struct rv7xx_pl {
 	u32 sclk;
 	u32 mclk;
 	u16 vddc;
 	u16 vddci; /* eg+ only */
 	u32 flags;
-	enum amdgpu_pcie_gen pcie_gen; /* si+ only */
+	enum si_pcie_gen pcie_gen; /* si+ only */
 };
 
 struct rv7xx_ps {
@@ -967,9 +974,9 @@ struct si_power_info {
 	struct si_ulv_param ulv;
 	u32 max_cu;
 	/* pcie gen */
-	enum amdgpu_pcie_gen force_pcie_gen;
-	enum amdgpu_pcie_gen boot_pcie_gen;
-	enum amdgpu_pcie_gen acpi_pcie_gen;
+	enum si_pcie_gen force_pcie_gen;
+	enum si_pcie_gen boot_pcie_gen;
+	enum si_pcie_gen acpi_pcie_gen;
 	u32 sys_pcie_mask;
 	/* flags */
 	bool enable_dte;
Signature · 1 line
2.29.0
#11 lore raw

Re: [PATCH V4 05/17] drm/amd/pm: do not expose those APIs used internally only in si_dpm.c

Quoted 107 lines · Evan Quan

Move them to si_dpm.c instead.

Change-Id I288205cfd7c6ba09cfb22626ff70360d61ff0c67

--
v1->v2:
- rename the API with "si_" prefix(Alex)
v2->v3:
- rename other data structures used only in si_dpm.c(Lijo)

---
  drivers/gpu/drm/amd/pm/amdgpu_dpm.c       |  25 -----
  drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h   |  25 -----
  drivers/gpu/drm/amd/pm/powerplay/si_dpm.c | 106 +++++++++++++++-------
  drivers/gpu/drm/amd/pm/powerplay/si_dpm.h |  15 ++-
  4 files changed, 83 insertions(+), 88 deletions(-)
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +0 -25
index 72a8cb70d36b..b31858ad9b83 100644
@@ -894,31 +894,6 @@ void amdgpu_add_thermal_controller(struct amdgpu_device *adev)
  	}
  }
 
-enum amdgpu_pcie_gen amdgpu_get_pcie_gen_support(struct amdgpu_device *adev,
-						 u32 sys_mask,
-						 enum amdgpu_pcie_gen asic_gen,
-						 enum amdgpu_pcie_gen default_gen)
-{
-	switch (asic_gen) {
-	case AMDGPU_PCIE_GEN1:
-		return AMDGPU_PCIE_GEN1;
-	case AMDGPU_PCIE_GEN2:
-		return AMDGPU_PCIE_GEN2;
-	case AMDGPU_PCIE_GEN3:
-		return AMDGPU_PCIE_GEN3;
-	default:
-		if ((sys_mask & CAIL_PCIE_LINK_SPEED_SUPPORT_GEN3) &&
-		    (default_gen == AMDGPU_PCIE_GEN3))
-			return AMDGPU_PCIE_GEN3;
-		else if ((sys_mask & CAIL_PCIE_LINK_SPEED_SUPPORT_GEN2) &&
-			 (default_gen == AMDGPU_PCIE_GEN2))
-			return AMDGPU_PCIE_GEN2;
-		else
-			return AMDGPU_PCIE_GEN1;
-	}
-	return AMDGPU_PCIE_GEN1;
-}
-
  struct amd_vce_state*
  amdgpu_get_vce_clock_state(void *handle, u32 idx)
  {
drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h +0 -25
index 6681b878e75f..f43b96dfe9d8 100644
@@ -45,19 +45,6 @@ enum amdgpu_int_thermal_type {
  	THERMAL_TYPE_KV,
  };
 
-enum amdgpu_dpm_auto_throttle_src {
-	AMDGPU_DPM_AUTO_THROTTLE_SRC_THERMAL,
-	AMDGPU_DPM_AUTO_THROTTLE_SRC_EXTERNAL
-};
-
-enum amdgpu_dpm_event_src {
-	AMDGPU_DPM_EVENT_SRC_ANALOG = 0,
-	AMDGPU_DPM_EVENT_SRC_EXTERNAL = 1,
-	AMDGPU_DPM_EVENT_SRC_DIGITAL = 2,
-	AMDGPU_DPM_EVENT_SRC_ANALOG_OR_EXTERNAL = 3,
-	AMDGPU_DPM_EVENT_SRC_DIGIAL_OR_EXTERNAL = 4
-};
-
  struct amdgpu_ps {
  	u32 caps; /* vbios flags */
  	u32 class; /* vbios flags */
@@ -252,13 +239,6 @@ struct amdgpu_dpm_fan {
  	bool ucode_fan_control;
  };
 
-enum amdgpu_pcie_gen {
-	AMDGPU_PCIE_GEN1 = 0,
-	AMDGPU_PCIE_GEN2 = 1,
-	AMDGPU_PCIE_GEN3 = 2,
-	AMDGPU_PCIE_GEN_INVALID = 0xffff
-};
-
  #define amdgpu_dpm_reset_power_profile_state(adev, request) \
  		((adev)->powerplay.pp_funcs->reset_power_profile_state(\
  			(adev)->powerplay.pp_handle, request))
@@ -403,11 +383,6 @@ void amdgpu_free_extended_power_table(struct amdgpu_device *adev);
 
  void amdgpu_add_thermal_controller(struct amdgpu_device *adev);
 
-enum amdgpu_pcie_gen amdgpu_get_pcie_gen_support(struct amdgpu_device *adev,
-						 u32 sys_mask,
-						 enum amdgpu_pcie_gen asic_gen,
-						 enum amdgpu_pcie_gen default_gen);
-
  struct amd_vce_state*
  amdgpu_get_vce_clock_state(void *handle, u32 idx);
 
drivers/gpu/drm/amd/pm/powerplay/si_dpm.c +0 -0
index 81f82aa05ec2..ab0fa6c79255 100644

drivers/gpu/drm/amd/pm/powerplay/si_dpm.c union pplib_clock_info { · line 103

Quoted 8 lines
drivers/gpu/drm/amd/pm/powerplay/si_dpm.c +5 -0
@@ -96,6 +96,19 @@ union pplib_clock_info {
  	struct _ATOM_PPLIB_SI_CLOCK_INFO si;
  };
 
+enum si_dpm_auto_throttle_src {
+	DPM_AUTO_THROTTLE_SRC_THERMAL,
+	DPM_AUTO_THROTTLE_SRC_EXTERNAL
+};
+

Since the final usage is something like (1 << DPM_AUTO_THROTTLE_SRC_EXTERNAL), it's better to associate the SI context also along with that - SI_DPM_AUTO_THROTTLE_SRC_EXTERNAL - to denote that these are SI specific values.

Thanks,
Lijo

Quoted 256 lines
drivers/gpu/drm/amd/pm/powerplay/si_dpm.c +67 -34
+enum si_dpm_event_src {
+	DPM_EVENT_SRC_ANALOG = 0,
+	DPM_EVENT_SRC_EXTERNAL = 1,
+	DPM_EVENT_SRC_DIGITAL = 2,
+	DPM_EVENT_SRC_ANALOG_OR_EXTERNAL = 3,
+	DPM_EVENT_SRC_DIGIAL_OR_EXTERNAL = 4
+};
+
  static const u32 r600_utc[R600_PM_NUMBER_OF_TC] =
  {
  	R600_UTC_DFLT_00,
@@ -3718,25 +3731,25 @@ static void si_set_dpm_event_sources(struct amdgpu_device *adev, u32 sources)
  {
  	struct rv7xx_power_info *pi = rv770_get_pi(adev);
  	bool want_thermal_protection;
-	enum amdgpu_dpm_event_src dpm_event_src;
+	enum si_dpm_event_src dpm_event_src;
 
  	switch (sources) {
  	case 0:
  	default:
  		want_thermal_protection = false;
  		break;
-	case (1 << AMDGPU_DPM_AUTO_THROTTLE_SRC_THERMAL):
+	case (1 << DPM_AUTO_THROTTLE_SRC_THERMAL):
  		want_thermal_protection = true;
-		dpm_event_src = AMDGPU_DPM_EVENT_SRC_DIGITAL;
+		dpm_event_src = DPM_EVENT_SRC_DIGITAL;
  		break;
-	case (1 << AMDGPU_DPM_AUTO_THROTTLE_SRC_EXTERNAL):
+	case (1 << DPM_AUTO_THROTTLE_SRC_EXTERNAL):
  		want_thermal_protection = true;
-		dpm_event_src = AMDGPU_DPM_EVENT_SRC_EXTERNAL;
+		dpm_event_src = DPM_EVENT_SRC_EXTERNAL;
  		break;
-	case ((1 << AMDGPU_DPM_AUTO_THROTTLE_SRC_EXTERNAL) |
-	      (1 << AMDGPU_DPM_AUTO_THROTTLE_SRC_THERMAL)):
+	case ((1 << DPM_AUTO_THROTTLE_SRC_EXTERNAL) |
+	      (1 << DPM_AUTO_THROTTLE_SRC_THERMAL)):
  		want_thermal_protection = true;
-		dpm_event_src = AMDGPU_DPM_EVENT_SRC_DIGIAL_OR_EXTERNAL;
+		dpm_event_src = DPM_EVENT_SRC_DIGIAL_OR_EXTERNAL;
  		break;
  	}
 
@@ -3750,7 +3763,7 @@ static void si_set_dpm_event_sources(struct amdgpu_device *adev, u32 sources)
  }
 
  static void si_enable_auto_throttle_source(struct amdgpu_device *adev,
-					   enum amdgpu_dpm_auto_throttle_src source,
+					   enum si_dpm_auto_throttle_src source,
  					   bool enable)
  {
  	struct rv7xx_power_info *pi = rv770_get_pi(adev);
@@ -4927,6 +4940,31 @@ static int si_populate_smc_initial_state(struct amdgpu_device *adev,
  	return 0;
  }
 
+static enum si_pcie_gen si_gen_pcie_gen_support(struct amdgpu_device *adev,
+						u32 sys_mask,
+						enum si_pcie_gen asic_gen,
+						enum si_pcie_gen default_gen)
+{
+	switch (asic_gen) {
+	case PCIE_GEN1:
+		return PCIE_GEN1;
+	case PCIE_GEN2:
+		return PCIE_GEN2;
+	case PCIE_GEN3:
+		return PCIE_GEN3;
+	default:
+		if ((sys_mask & CAIL_PCIE_LINK_SPEED_SUPPORT_GEN3) &&
+		    (default_gen == PCIE_GEN3))
+			return PCIE_GEN3;
+		else if ((sys_mask & CAIL_PCIE_LINK_SPEED_SUPPORT_GEN2) &&
+			 (default_gen == PCIE_GEN2))
+			return PCIE_GEN2;
+		else
+			return PCIE_GEN1;
+	}
+	return PCIE_GEN1;
+}
+
  static int si_populate_smc_acpi_state(struct amdgpu_device *adev,
  				      SISLANDS_SMC_STATETABLE *table)
  {
@@ -4989,10 +5027,10 @@ static int si_populate_smc_acpi_state(struct amdgpu_device *adev,
  							      &table->ACPIState.level.std_vddc);
  		}
  		table->ACPIState.level.gen2PCIE =
-			(u8)amdgpu_get_pcie_gen_support(adev,
-							si_pi->sys_pcie_mask,
-							si_pi->boot_pcie_gen,
-							AMDGPU_PCIE_GEN1);
+			(u8)si_gen_pcie_gen_support(adev,
+						    si_pi->sys_pcie_mask,
+						    si_pi->boot_pcie_gen,
+						    PCIE_GEN1);
 
  		if (si_pi->vddc_phase_shed_control)
  			si_populate_phase_shedding_value(adev,
@@ -5430,7 +5468,7 @@ static int si_convert_power_level_to_smc(struct amdgpu_device *adev,
  	bool gmc_pg = false;
 
  	if (eg_pi->pcie_performance_request &&
-	    (si_pi->force_pcie_gen != AMDGPU_PCIE_GEN_INVALID))
+	    (si_pi->force_pcie_gen != PCIE_GEN_INVALID))
  		level->gen2PCIE = (u8)si_pi->force_pcie_gen;
  	else
  		level->gen2PCIE = (u8)pl->pcie_gen;
@@ -6147,8 +6185,8 @@ static void si_enable_voltage_control(struct amdgpu_device *adev, bool enable)
  		WREG32_P(GENERAL_PWRMGT, 0, ~VOLT_PWRMGT_EN);
  }
 
-static enum amdgpu_pcie_gen si_get_maximum_link_speed(struct amdgpu_device *adev,
-						      struct amdgpu_ps *amdgpu_state)
+static enum si_pcie_gen si_get_maximum_link_speed(struct amdgpu_device *adev,
+						  struct amdgpu_ps *amdgpu_state)
  {
  	struct si_ps *state = si_get_ps(amdgpu_state);
  	int i;
@@ -6177,27 +6215,27 @@ static void si_request_link_speed_change_before_state_change(struct amdgpu_devic
  							     struct amdgpu_ps *amdgpu_current_state)
  {
  	struct si_power_info *si_pi = si_get_pi(adev);
-	enum amdgpu_pcie_gen target_link_speed = si_get_maximum_link_speed(adev, amdgpu_new_state);
-	enum amdgpu_pcie_gen current_link_speed;
+	enum si_pcie_gen target_link_speed = si_get_maximum_link_speed(adev, amdgpu_new_state);
+	enum si_pcie_gen current_link_speed;
 
-	if (si_pi->force_pcie_gen == AMDGPU_PCIE_GEN_INVALID)
+	if (si_pi->force_pcie_gen == PCIE_GEN_INVALID)
  		current_link_speed = si_get_maximum_link_speed(adev, amdgpu_current_state);
  	else
  		current_link_speed = si_pi->force_pcie_gen;
 
-	si_pi->force_pcie_gen = AMDGPU_PCIE_GEN_INVALID;
+	si_pi->force_pcie_gen = PCIE_GEN_INVALID;
  	si_pi->pspp_notify_required = false;
  	if (target_link_speed > current_link_speed) {
  		switch (target_link_speed) {
  #if defined(CONFIG_ACPI)
-		case AMDGPU_PCIE_GEN3:
+		case PCIE_GEN3:
  			if (amdgpu_acpi_pcie_performance_request(adev, PCIE_PERF_REQ_PECI_GEN3, false) == 0)
  				break;
-			si_pi->force_pcie_gen = AMDGPU_PCIE_GEN2;
-			if (current_link_speed == AMDGPU_PCIE_GEN2)
+			si_pi->force_pcie_gen = PCIE_GEN2;
+			if (current_link_speed == PCIE_GEN2)
  				break;
  			fallthrough;
-		case AMDGPU_PCIE_GEN2:
+		case PCIE_GEN2:
  			if (amdgpu_acpi_pcie_performance_request(adev, PCIE_PERF_REQ_PECI_GEN2, false) == 0)
  				break;
  			fallthrough;
@@ -6217,13 +6255,13 @@ static void si_notify_link_speed_change_after_state_change(struct amdgpu_device
  							   struct amdgpu_ps *amdgpu_current_state)
  {
  	struct si_power_info *si_pi = si_get_pi(adev);
-	enum amdgpu_pcie_gen target_link_speed = si_get_maximum_link_speed(adev, amdgpu_new_state);
+	enum si_pcie_gen target_link_speed = si_get_maximum_link_speed(adev, amdgpu_new_state);
  	u8 request;
 
  	if (si_pi->pspp_notify_required) {
-		if (target_link_speed == AMDGPU_PCIE_GEN3)
+		if (target_link_speed == PCIE_GEN3)
  			request = PCIE_PERF_REQ_PECI_GEN3;
-		else if (target_link_speed == AMDGPU_PCIE_GEN2)
+		else if (target_link_speed == PCIE_GEN2)
  			request = PCIE_PERF_REQ_PECI_GEN2;
  		else
  			request = PCIE_PERF_REQ_PECI_GEN1;
@@ -6864,7 +6902,7 @@ static int si_dpm_enable(struct amdgpu_device *adev)
  	si_enable_sclk_control(adev, true);
  	si_start_dpm(adev);
 
-	si_enable_auto_throttle_source(adev, AMDGPU_DPM_AUTO_THROTTLE_SRC_THERMAL, true);
+	si_enable_auto_throttle_source(adev, DPM_AUTO_THROTTLE_SRC_THERMAL, true);
  	si_thermal_start_thermal_controller(adev);
 
  	ni_update_current_ps(adev, boot_ps);
@@ -6904,7 +6942,7 @@ static void si_dpm_disable(struct amdgpu_device *adev)
  	si_enable_power_containment(adev, boot_ps, false);
  	si_enable_smc_cac(adev, boot_ps, false);
  	si_enable_spread_spectrum(adev, false);
-	si_enable_auto_throttle_source(adev, AMDGPU_DPM_AUTO_THROTTLE_SRC_THERMAL, false);
+	si_enable_auto_throttle_source(adev, DPM_AUTO_THROTTLE_SRC_THERMAL, false);
  	si_stop_dpm(adev);
  	si_reset_to_default(adev);
  	si_dpm_stop_smc(adev);
@@ -7148,10 +7186,10 @@ static void si_parse_pplib_clock_info(struct amdgpu_device *adev,
  	pl->vddc = le16_to_cpu(clock_info->si.usVDDC);
  	pl->vddci = le16_to_cpu(clock_info->si.usVDDCI);
  	pl->flags = le32_to_cpu(clock_info->si.ulFlags);
-	pl->pcie_gen = amdgpu_get_pcie_gen_support(adev,
-						   si_pi->sys_pcie_mask,
-						   si_pi->boot_pcie_gen,
-						   clock_info->si.ucPCIEGen);
+	pl->pcie_gen = si_gen_pcie_gen_support(adev,
+					       si_pi->sys_pcie_mask,
+					       si_pi->boot_pcie_gen,
+					       clock_info->si.ucPCIEGen);
 
  	/* patch up vddc if necessary */
  	ret = si_get_leakage_voltage_from_leakage_index(adev, pl->vddc,
@@ -7318,7 +7356,7 @@ static int si_dpm_init(struct amdgpu_device *adev)
 
  	si_pi->sys_pcie_mask =
  		adev->pm.pcie_gen_mask & CAIL_PCIE_LINK_SPEED_SUPPORT_MASK;
-	si_pi->force_pcie_gen = AMDGPU_PCIE_GEN_INVALID;
+	si_pi->force_pcie_gen = PCIE_GEN_INVALID;
  	si_pi->boot_pcie_gen = si_get_current_pcie_speed(adev);
 
  	si_set_max_cu_value(adev);
drivers/gpu/drm/amd/pm/powerplay/si_dpm.h +11 -4
index bc0be6818e21..77614ff10df6 100644
@@ -595,13 +595,20 @@ struct rv7xx_power_info {
  	RV770_SMC_STATETABLE smc_statetable;
  };
 
+enum si_pcie_gen {
+	PCIE_GEN1 = 0,
+	PCIE_GEN2 = 1,
+	PCIE_GEN3 = 2,
+	PCIE_GEN_INVALID = 0xffff
+};
+
  struct rv7xx_pl {
  	u32 sclk;
  	u32 mclk;
  	u16 vddc;
  	u16 vddci; /* eg+ only */
  	u32 flags;
-	enum amdgpu_pcie_gen pcie_gen; /* si+ only */
+	enum si_pcie_gen pcie_gen; /* si+ only */
  };
 
  struct rv7xx_ps {
@@ -967,9 +974,9 @@ struct si_power_info {
  	struct si_ulv_param ulv;
  	u32 max_cu;
  	/* pcie gen */
-	enum amdgpu_pcie_gen force_pcie_gen;
-	enum amdgpu_pcie_gen boot_pcie_gen;
-	enum amdgpu_pcie_gen acpi_pcie_gen;
+	enum si_pcie_gen force_pcie_gen;
+	enum si_pcie_gen boot_pcie_gen;
+	enum si_pcie_gen acpi_pcie_gen;
  	u32 sys_pcie_mask;
  	/* flags */
  	bool enable_dte;
author
#12 lore raw

RE: [PATCH V4 05/17] drm/amd/pm: do not expose those APIs used internally only in si_dpm.c

[AMD Official Use Only]

Quoted 137 lines

-----Original Message-----
From: Lazar, Lijo <[email protected]>
Sent: Thursday, December 9, 2021 8:09 PM
To: Quan, Evan <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>; Feng, Kenneth <[email protected]>
Subject: Re: [PATCH V4 05/17] drm/amd/pm: do not expose those APIs used internally only in si_dpm.c

Quoted 9 lines · Evan Quan

Move them to si_dpm.c instead.

Change-Id I288205cfd7c6ba09cfb22626ff70360d61ff0c67

--
v1->v2:
- rename the API with "si_" prefix(Alex)
v2->v3:
- rename other data structures used only in si_dpm.c(Lijo)

Quoted 4 lines
---
  drivers/gpu/drm/amd/pm/amdgpu_dpm.c       |  25 -----
  drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h   |  25 -----
  drivers/gpu/drm/amd/pm/powerplay/si_dpm.c | 106

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

drivers/gpu/drm/amd/pm/amdgpu_dpm.c void amdgpu_add_thermal_controller(struct

Quoted 9 lines
  drivers/gpu/drm/amd/pm/powerplay/si_dpm.h |  15 ++-
  4 files changed, 83 insertions(+), 88 deletions(-)
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +0 -0
index 72a8cb70d36b..b31858ad9b83 100644
@@ -894,31 +894,6 @@ void amdgpu_add_thermal_controller(struct

amdgpu_device *adev)

drivers/gpu/drm/amd/pm/amdgpu_dpm.c void amdgpu_add_thermal_controller(struct · line 897

Quoted 4 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +0 -1
  	}
  }
 
-enum amdgpu_pcie_gen amdgpu_get_pcie_gen_support(struct

amdgpu_device *adev,

drivers/gpu/drm/amd/pm/amdgpu_dpm.c void amdgpu_add_thermal_controller(struct · line 899

Quoted 2 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +0 -2
-						 u32 sys_mask,
-						 enum amdgpu_pcie_gen

asic_gen,

drivers/gpu/drm/amd/pm/amdgpu_dpm.c void amdgpu_add_thermal_controller(struct · line 900

Quoted 1 line
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +0 -1
-						 enum amdgpu_pcie_gen

default_gen)

drivers/gpu/drm/amd/pm/amdgpu_dpm.c void amdgpu_add_thermal_controller(struct amdgpu_device *adev)

Quoted 10 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +0 -10
-{
-	switch (asic_gen) {
-	case AMDGPU_PCIE_GEN1:
-		return AMDGPU_PCIE_GEN1;
-	case AMDGPU_PCIE_GEN2:
-		return AMDGPU_PCIE_GEN2;
-	case AMDGPU_PCIE_GEN3:
-		return AMDGPU_PCIE_GEN3;
-	default:
-		if ((sys_mask & CAIL_PCIE_LINK_SPEED_SUPPORT_GEN3)

&&

drivers/gpu/drm/amd/pm/amdgpu_dpm.c void amdgpu_add_thermal_controller(struct amdgpu_device *adev)

Quoted 3 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +0 -3
-		    (default_gen == AMDGPU_PCIE_GEN3))
-			return AMDGPU_PCIE_GEN3;
-		else if ((sys_mask &

CAIL_PCIE_LINK_SPEED_SUPPORT_GEN2) &&

Quoted 50 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +0 -8
-			 (default_gen == AMDGPU_PCIE_GEN2))
-			return AMDGPU_PCIE_GEN2;
-		else
-			return AMDGPU_PCIE_GEN1;
-	}
-	return AMDGPU_PCIE_GEN1;
-}
-
  struct amd_vce_state*
  amdgpu_get_vce_clock_state(void *handle, u32 idx)
  {
drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h +0 -20
index 6681b878e75f..f43b96dfe9d8 100644
@@ -45,19 +45,6 @@ enum amdgpu_int_thermal_type {
  	THERMAL_TYPE_KV,
  };
 
-enum amdgpu_dpm_auto_throttle_src {
-	AMDGPU_DPM_AUTO_THROTTLE_SRC_THERMAL,
-	AMDGPU_DPM_AUTO_THROTTLE_SRC_EXTERNAL
-};
-
-enum amdgpu_dpm_event_src {
-	AMDGPU_DPM_EVENT_SRC_ANALOG = 0,
-	AMDGPU_DPM_EVENT_SRC_EXTERNAL = 1,
-	AMDGPU_DPM_EVENT_SRC_DIGITAL = 2,
-	AMDGPU_DPM_EVENT_SRC_ANALOG_OR_EXTERNAL = 3,
-	AMDGPU_DPM_EVENT_SRC_DIGIAL_OR_EXTERNAL = 4
-};
-
  struct amdgpu_ps {
  	u32 caps; /* vbios flags */
  	u32 class; /* vbios flags */
@@ -252,13 +239,6 @@ struct amdgpu_dpm_fan {
  	bool ucode_fan_control;
  };
 
-enum amdgpu_pcie_gen {
-	AMDGPU_PCIE_GEN1 = 0,
-	AMDGPU_PCIE_GEN2 = 1,
-	AMDGPU_PCIE_GEN3 = 2,
-	AMDGPU_PCIE_GEN_INVALID = 0xffff
-};
-
  #define amdgpu_dpm_reset_power_profile_state(adev, request) \
  		((adev)->powerplay.pp_funcs-
 reset_power_profile_state(\
Quoted 1 line

(adev)->powerplay.pp_handle, request)) @@ -

403,11 +383,6 @@ void

Quoted 5 lines

amdgpu_free_extended_power_table(struct amdgpu_device *adev);

  void amdgpu_add_thermal_controller(struct amdgpu_device *adev);

-enum amdgpu_pcie_gen amdgpu_get_pcie_gen_support(struct

amdgpu_device *adev,

drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h

Quoted 2 lines
drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h +0 -2
-						 u32 sys_mask,
-						 enum amdgpu_pcie_gen

asic_gen,

drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h

Quoted 1 line
drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h +0 -1
-						 enum amdgpu_pcie_gen

default_gen);

Quoted 13 lines
drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h +0 -1
-
  struct amd_vce_state*
  amdgpu_get_vce_clock_state(void *handle, u32 idx);
drivers/gpu/drm/amd/pm/powerplay/si_dpm.c +0 -0
index 81f82aa05ec2..ab0fa6c79255 100644
@@ -96,6 +96,19 @@ union pplib_clock_info {
  	struct _ATOM_PPLIB_SI_CLOCK_INFO si;
  };
 
Quoted 10 lines

drivers/gpu/drm/amd/pm/powerplay/si_dpm.c union pplib_clock_info { · line 103

Quoted 5 lines
drivers/gpu/drm/amd/pm/powerplay/si_dpm.c +5 -0
+enum si_dpm_auto_throttle_src {
+	DPM_AUTO_THROTTLE_SRC_THERMAL,
+	DPM_AUTO_THROTTLE_SRC_EXTERNAL
+};
+

Since the final usage is something like (1 << DPM_AUTO_THROTTLE_SRC_EXTERNAL), it's better to associate the SI context also along with that - SI_DPM_AUTO_THROTTLE_SRC_EXTERNAL - to denote that these are SI specific values.

[Quan, Evan] Sure, I can do that.

BR
Evan

Quoted 302 lines

Thanks,
Lijo

drivers/gpu/drm/amd/pm/powerplay/si_dpm.c static void si_set_dpm_event_sources(struct

Quoted 11 lines
drivers/gpu/drm/amd/pm/powerplay/si_dpm.c +7 -0
+enum si_dpm_event_src {
+	DPM_EVENT_SRC_ANALOG = 0,
+	DPM_EVENT_SRC_EXTERNAL = 1,
+	DPM_EVENT_SRC_DIGITAL = 2,
+	DPM_EVENT_SRC_ANALOG_OR_EXTERNAL = 3,
+	DPM_EVENT_SRC_DIGIAL_OR_EXTERNAL = 4 };
+
  static const u32 r600_utc[R600_PM_NUMBER_OF_TC] =
  {
  	R600_UTC_DFLT_00,
@@ -3718,25 +3731,25 @@ static void si_set_dpm_event_sources(struct

amdgpu_device *adev, u32 sources)

Quoted 19 lines
drivers/gpu/drm/amd/pm/powerplay/si_dpm.c +4 -4
  {
  	struct rv7xx_power_info *pi = rv770_get_pi(adev);
  	bool want_thermal_protection;
-	enum amdgpu_dpm_event_src dpm_event_src;
+	enum si_dpm_event_src dpm_event_src;
 
  	switch (sources) {
  	case 0:
  	default:
  		want_thermal_protection = false;
  		break;
-	case (1 << AMDGPU_DPM_AUTO_THROTTLE_SRC_THERMAL):
+	case (1 << DPM_AUTO_THROTTLE_SRC_THERMAL):
  		want_thermal_protection = true;
-		dpm_event_src = AMDGPU_DPM_EVENT_SRC_DIGITAL;
+		dpm_event_src = DPM_EVENT_SRC_DIGITAL;
  		break;
-	case (1 << AMDGPU_DPM_AUTO_THROTTLE_SRC_EXTERNAL):
+	case (1 << DPM_AUTO_THROTTLE_SRC_EXTERNAL):

drivers/gpu/drm/amd/pm/powerplay/si_dpm.c static void si_set_dpm_event_sources(struct amdgpu_device *adev, u32 sources)

Quoted 10 lines
drivers/gpu/drm/amd/pm/powerplay/si_dpm.c +3 -4
  		want_thermal_protection = true;
-		dpm_event_src = AMDGPU_DPM_EVENT_SRC_EXTERNAL;
+		dpm_event_src = DPM_EVENT_SRC_EXTERNAL;
  		break;
-	case ((1 << AMDGPU_DPM_AUTO_THROTTLE_SRC_EXTERNAL) |
-	      (1 << AMDGPU_DPM_AUTO_THROTTLE_SRC_THERMAL)):
+	case ((1 << DPM_AUTO_THROTTLE_SRC_EXTERNAL) |
+	      (1 << DPM_AUTO_THROTTLE_SRC_THERMAL)):
  		want_thermal_protection = true;
-		dpm_event_src =

AMDGPU_DPM_EVENT_SRC_DIGIAL_OR_EXTERNAL;

drivers/gpu/drm/amd/pm/powerplay/si_dpm.c static void si_set_dpm_event_sources(struct

Quoted 5 lines
drivers/gpu/drm/amd/pm/powerplay/si_dpm.c +1 -0
+		dpm_event_src = DPM_EVENT_SRC_DIGIAL_OR_EXTERNAL;
  		break;
  	}
 
@@ -3750,7 +3763,7 @@ static void si_set_dpm_event_sources(struct

amdgpu_device *adev, u32 sources)

drivers/gpu/drm/amd/pm/powerplay/si_dpm.c static void si_set_dpm_event_sources(struct amdgpu_device *adev, u32 sources)

Quoted 4 lines
drivers/gpu/drm/amd/pm/powerplay/si_dpm.c +0 -1
  }
 
  static void si_enable_auto_throttle_source(struct amdgpu_device *adev,
-					   enum

amdgpu_dpm_auto_throttle_src source,

drivers/gpu/drm/amd/pm/powerplay/si_dpm.c static void si_set_dpm_event_sources(struct · line 3766

Quoted 1 line
drivers/gpu/drm/amd/pm/powerplay/si_dpm.c +1 -0
+					   enum si_dpm_auto_throttle_src

source,

drivers/gpu/drm/amd/pm/powerplay/si_dpm.c static void si_set_dpm_event_sources(struct amdgpu_device *adev, u32 sources)

Quoted 4 lines
drivers/gpu/drm/amd/pm/powerplay/si_dpm.c +1 -0
  					   bool enable)
  {
  	struct rv7xx_power_info *pi = rv770_get_pi(adev); @@ -4927,6
+4940,31 @@ static int si_populate_smc_initial_state(struct

amdgpu_device *adev,

Quoted 4 lines
  	return 0;
  }

+static enum si_pcie_gen si_gen_pcie_gen_support(struct amdgpu_device

*adev,

drivers/gpu/drm/amd/pm/powerplay/si_dpm.c static int si_populate_smc_initial_state(struct amdgpu_device *adev,

Quoted 3 lines
drivers/gpu/drm/amd/pm/powerplay/si_dpm.c +3 -0
+						u32 sys_mask,
+						enum si_pcie_gen asic_gen,
+						enum si_pcie_gen

default_gen)

drivers/gpu/drm/amd/pm/powerplay/si_dpm.c static int si_populate_smc_initial_state(struct amdgpu_device *adev,

Quoted 10 lines
drivers/gpu/drm/amd/pm/powerplay/si_dpm.c +10 -0
+{
+	switch (asic_gen) {
+	case PCIE_GEN1:
+		return PCIE_GEN1;
+	case PCIE_GEN2:
+		return PCIE_GEN2;
+	case PCIE_GEN3:
+		return PCIE_GEN3;
+	default:
+		if ((sys_mask & CAIL_PCIE_LINK_SPEED_SUPPORT_GEN3)

&&

drivers/gpu/drm/amd/pm/powerplay/si_dpm.c static int si_populate_smc_initial_state(struct amdgpu_device *adev,

Quoted 3 lines
drivers/gpu/drm/amd/pm/powerplay/si_dpm.c +3 -0
+		    (default_gen == PCIE_GEN3))
+			return PCIE_GEN3;
+		else if ((sys_mask &

CAIL_PCIE_LINK_SPEED_SUPPORT_GEN2) &&

drivers/gpu/drm/amd/pm/powerplay/si_dpm.c static int si_populate_smc_acpi_state(struct

Quoted 12 lines
drivers/gpu/drm/amd/pm/powerplay/si_dpm.c +8 -0
+			 (default_gen == PCIE_GEN2))
+			return PCIE_GEN2;
+		else
+			return PCIE_GEN1;
+	}
+	return PCIE_GEN1;
+}
+
  static int si_populate_smc_acpi_state(struct amdgpu_device *adev,
  				      SISLANDS_SMC_STATETABLE *table)
  {
@@ -4989,10 +5027,10 @@ static int si_populate_smc_acpi_state(struct

amdgpu_device *adev,

drivers/gpu/drm/amd/pm/powerplay/si_dpm.c static int si_populate_smc_acpi_state(struct amdgpu_device *adev,

Quoted 8 lines
drivers/gpu/drm/amd/pm/powerplay/si_dpm.c +0 -4
  							      &table-
 ACPIState.level.std_vddc);
  		}
  		table->ACPIState.level.gen2PCIE =
-			(u8)amdgpu_get_pcie_gen_support(adev,
-							si_pi->sys_pcie_mask,
-							si_pi->boot_pcie_gen,
-
	AMDGPU_PCIE_GEN1);

drivers/gpu/drm/amd/pm/powerplay/si_dpm.c static int si_convert_power_level_to_smc(struct

Quoted 8 lines
drivers/gpu/drm/amd/pm/powerplay/si_dpm.c +4 -0
+			(u8)si_gen_pcie_gen_support(adev,
+						    si_pi->sys_pcie_mask,
+						    si_pi->boot_pcie_gen,
+						    PCIE_GEN1);
 
  		if (si_pi->vddc_phase_shed_control)

si_populate_phase_shedding_value(adev,

drivers/gpu/drm/amd/pm/powerplay/si_dpm.c +0 -0
@@ -5430,7 +5468,7 @@ static int si_convert_power_level_to_smc(struct

amdgpu_device *adev,

drivers/gpu/drm/amd/pm/powerplay/si_dpm.c static int si_convert_power_level_to_smc(struct amdgpu_device *adev,

Quoted 8 lines
drivers/gpu/drm/amd/pm/powerplay/si_dpm.c +1 -1
  	bool gmc_pg = false;
 
  	if (eg_pi->pcie_performance_request &&
-	    (si_pi->force_pcie_gen != AMDGPU_PCIE_GEN_INVALID))
+	    (si_pi->force_pcie_gen != PCIE_GEN_INVALID))
  		level->gen2PCIE = (u8)si_pi->force_pcie_gen;
  	else
  		level->gen2PCIE = (u8)pl->pcie_gen; @@ -6147,8 +6185,8

@@ static

Quoted 5 lines

void si_enable_voltage_control(struct amdgpu_device *adev, bool enable)
WREG32_P(GENERAL_PWRMGT, 0, ~VOLT_PWRMGT_EN);
}

-static enum amdgpu_pcie_gen si_get_maximum_link_speed(struct

amdgpu_device *adev,

drivers/gpu/drm/amd/pm/powerplay/si_dpm.c

Quoted 1 line
drivers/gpu/drm/amd/pm/powerplay/si_dpm.c +0 -1
-						      struct amdgpu_ps

*amdgpu_state)

Quoted 1 line

+static enum si_pcie_gen si_get_maximum_link_speed(struct

amdgpu_device *adev,

drivers/gpu/drm/amd/pm/powerplay/si_dpm.c

Quoted 1 line
drivers/gpu/drm/amd/pm/powerplay/si_dpm.c +1 -0
+						  struct amdgpu_ps

*amdgpu_state)

drivers/gpu/drm/amd/pm/powerplay/si_dpm.c static void

Quoted 4 lines
  {
  	struct si_ps *state = si_get_ps(amdgpu_state);
  	int i;
drivers/gpu/drm/amd/pm/powerplay/si_dpm.c +0 -0
@@ -6177,27 +6215,27 @@ static void

si_request_link_speed_change_before_state_change(struct amdgpu_devic

drivers/gpu/drm/amd/pm/powerplay/si_dpm.c static void · line 6215

Quoted 1 line
drivers/gpu/drm/amd/pm/powerplay/si_dpm.c +0 -0
  							     struct amdgpu_ps

*amdgpu_current_state)

drivers/gpu/drm/amd/pm/powerplay/si_dpm.c static void si_request_link_speed_change_before_state_change(struct amdgpu_devic

Quoted 3 lines
drivers/gpu/drm/amd/pm/powerplay/si_dpm.c +0 -1
  {
  	struct si_power_info *si_pi = si_get_pi(adev);
-	enum amdgpu_pcie_gen target_link_speed =

si_get_maximum_link_speed(adev, amdgpu_new_state);

drivers/gpu/drm/amd/pm/powerplay/si_dpm.c static void · line 6218

Quoted 2 lines
drivers/gpu/drm/amd/pm/powerplay/si_dpm.c +1 -1
-	enum amdgpu_pcie_gen current_link_speed;
+	enum si_pcie_gen target_link_speed =

si_get_maximum_link_speed(adev, amdgpu_new_state);

drivers/gpu/drm/amd/pm/powerplay/si_dpm.c static void si_request_link_speed_change_before_state_change(struct amdgpu_devic

Quoted 5 lines
drivers/gpu/drm/amd/pm/powerplay/si_dpm.c +2 -1
+	enum si_pcie_gen current_link_speed;
 
-	if (si_pi->force_pcie_gen == AMDGPU_PCIE_GEN_INVALID)
+	if (si_pi->force_pcie_gen == PCIE_GEN_INVALID)
  		current_link_speed = si_get_maximum_link_speed(adev,

amdgpu_current_state);

drivers/gpu/drm/amd/pm/powerplay/si_dpm.c static void si_request_link_speed_change_before_state_change(struct amdgpu_devic

Quoted 12 lines
drivers/gpu/drm/amd/pm/powerplay/si_dpm.c +2 -2
  	else
  		current_link_speed = si_pi->force_pcie_gen;
 
-	si_pi->force_pcie_gen = AMDGPU_PCIE_GEN_INVALID;
+	si_pi->force_pcie_gen = PCIE_GEN_INVALID;
  	si_pi->pspp_notify_required = false;
  	if (target_link_speed > current_link_speed) {
  		switch (target_link_speed) {
  #if defined(CONFIG_ACPI)
-		case AMDGPU_PCIE_GEN3:
+		case PCIE_GEN3:
  			if (amdgpu_acpi_pcie_performance_request(adev,

PCIE_PERF_REQ_PECI_GEN3, false) == 0)

drivers/gpu/drm/amd/pm/powerplay/si_dpm.c static void si_request_link_speed_change_before_state_change(struct amdgpu_devic

Quoted 10 lines
drivers/gpu/drm/amd/pm/powerplay/si_dpm.c +3 -3
  				break;
-			si_pi->force_pcie_gen = AMDGPU_PCIE_GEN2;
-			if (current_link_speed == AMDGPU_PCIE_GEN2)
+			si_pi->force_pcie_gen = PCIE_GEN2;
+			if (current_link_speed == PCIE_GEN2)
  				break;
  			fallthrough;
-		case AMDGPU_PCIE_GEN2:
+		case PCIE_GEN2:
  			if (amdgpu_acpi_pcie_performance_request(adev,

PCIE_PERF_REQ_PECI_GEN2, false) == 0)

drivers/gpu/drm/amd/pm/powerplay/si_dpm.c static void

Quoted 3 lines
drivers/gpu/drm/amd/pm/powerplay/si_dpm.c +0 -0
  				break;
  			fallthrough;
@@ -6217,13 +6255,13 @@ static void

si_notify_link_speed_change_after_state_change(struct amdgpu_device

drivers/gpu/drm/amd/pm/powerplay/si_dpm.c static void · line 6255

Quoted 1 line
drivers/gpu/drm/amd/pm/powerplay/si_dpm.c +0 -0
  							   struct amdgpu_ps

*amdgpu_current_state)

drivers/gpu/drm/amd/pm/powerplay/si_dpm.c static void si_request_link_speed_change_before_state_change(struct amdgpu_devic

Quoted 3 lines
drivers/gpu/drm/amd/pm/powerplay/si_dpm.c +0 -1
  {
  	struct si_power_info *si_pi = si_get_pi(adev);
-	enum amdgpu_pcie_gen target_link_speed =

si_get_maximum_link_speed(adev, amdgpu_new_state);

drivers/gpu/drm/amd/pm/powerplay/si_dpm.c static void · line 6258

Quoted 1 line
drivers/gpu/drm/amd/pm/powerplay/si_dpm.c +1 -0
+	enum si_pcie_gen target_link_speed =

si_get_maximum_link_speed(adev,

drivers/gpu/drm/amd/pm/powerplay/si_dpm.c static void si_notify_link_speed_change_after_state_change(struct amdgpu_device

Quoted 12 lines
drivers/gpu/drm/amd/pm/powerplay/si_dpm.c +3 -2
+amdgpu_new_state);
  	u8 request;
 
  	if (si_pi->pspp_notify_required) {
-		if (target_link_speed == AMDGPU_PCIE_GEN3)
+		if (target_link_speed == PCIE_GEN3)
  			request = PCIE_PERF_REQ_PECI_GEN3;
-		else if (target_link_speed == AMDGPU_PCIE_GEN2)
+		else if (target_link_speed == PCIE_GEN2)
  			request = PCIE_PERF_REQ_PECI_GEN2;
  		else
  			request = PCIE_PERF_REQ_PECI_GEN1; @@ -6864,7

+6902,7 @@ static

drivers/gpu/drm/amd/pm/powerplay/si_dpm.c

Quoted 5 lines

int si_dpm_enable(struct amdgpu_device *adev)
si_enable_sclk_control(adev, true);
si_start_dpm(adev);

drivers/gpu/drm/amd/pm/powerplay/si_dpm.c +0 -1
-	si_enable_auto_throttle_source(adev,

AMDGPU_DPM_AUTO_THROTTLE_SRC_THERMAL, true);

drivers/gpu/drm/amd/pm/powerplay/si_dpm.c

Quoted 1 line
drivers/gpu/drm/amd/pm/powerplay/si_dpm.c +1 -0
+	si_enable_auto_throttle_source(adev,

DPM_AUTO_THROTTLE_SRC_THERMAL,

Quoted 4 lines

+true);
si_thermal_start_thermal_controller(adev);

ni_update_current_ps(adev, boot_ps); @@ -6904,7 +6942,7 @@

static

drivers/gpu/drm/amd/pm/powerplay/si_dpm.c

Quoted 5 lines

void si_dpm_disable(struct amdgpu_device *adev)
si_enable_power_containment(adev, boot_ps, false); si_enable_smc_cac(adev, boot_ps, false); si_enable_spread_spectrum(adev, false);

drivers/gpu/drm/amd/pm/powerplay/si_dpm.c +0 -1
-	si_enable_auto_throttle_source(adev,

AMDGPU_DPM_AUTO_THROTTLE_SRC_THERMAL, false);

drivers/gpu/drm/amd/pm/powerplay/si_dpm.c

Quoted 1 line
drivers/gpu/drm/amd/pm/powerplay/si_dpm.c +1 -0
+	si_enable_auto_throttle_source(adev,

DPM_AUTO_THROTTLE_SRC_THERMAL,

drivers/gpu/drm/amd/pm/powerplay/si_dpm.c static void si_parse_pplib_clock_info(struct

Quoted 5 lines
drivers/gpu/drm/amd/pm/powerplay/si_dpm.c +1 -0
+false);
  	si_stop_dpm(adev);
  	si_reset_to_default(adev);
  	si_dpm_stop_smc(adev);
@@ -7148,10 +7186,10 @@ static void si_parse_pplib_clock_info(struct

amdgpu_device *adev,

Quoted 4 lines
drivers/gpu/drm/amd/pm/powerplay/si_dpm.c +0 -1
  	pl->vddc = le16_to_cpu(clock_info->si.usVDDC);
  	pl->vddci = le16_to_cpu(clock_info->si.usVDDCI);
  	pl->flags = le32_to_cpu(clock_info->si.ulFlags);
-	pl->pcie_gen = amdgpu_get_pcie_gen_support(adev,

drivers/gpu/drm/amd/pm/powerplay/si_dpm.c static void si_parse_pplib_clock_info(struct amdgpu_device *adev, · line 7195

Quoted 10 lines
drivers/gpu/drm/amd/pm/powerplay/si_dpm.c +4 -3
-						   si_pi->sys_pcie_mask,
-						   si_pi->boot_pcie_gen,
-						   clock_info->si.ucPCIEGen);
+	pl->pcie_gen = si_gen_pcie_gen_support(adev,
+					       si_pi->sys_pcie_mask,
+					       si_pi->boot_pcie_gen,
+					       clock_info->si.ucPCIEGen);
 
  	/* patch up vddc if necessary */
  	ret = si_get_leakage_voltage_from_leakage_index(adev, pl->vddc,

@@

Quoted 4 lines

-7318,7 +7356,7 @@ static int si_dpm_init(struct amdgpu_device *adev)

si_pi->sys_pcie_mask =
adev->pm.pcie_gen_mask &

CAIL_PCIE_LINK_SPEED_SUPPORT_MASK;

Quoted 46 lines
drivers/gpu/drm/amd/pm/powerplay/si_dpm.c +1 -1
-	si_pi->force_pcie_gen = AMDGPU_PCIE_GEN_INVALID;
+	si_pi->force_pcie_gen = PCIE_GEN_INVALID;
  	si_pi->boot_pcie_gen = si_get_current_pcie_speed(adev);
 
  	si_set_max_cu_value(adev);
drivers/gpu/drm/amd/pm/powerplay/si_dpm.h +11 -4
index bc0be6818e21..77614ff10df6 100644
@@ -595,13 +595,20 @@ struct rv7xx_power_info {
  	RV770_SMC_STATETABLE smc_statetable;
  };
 
+enum si_pcie_gen {
+	PCIE_GEN1 = 0,
+	PCIE_GEN2 = 1,
+	PCIE_GEN3 = 2,
+	PCIE_GEN_INVALID = 0xffff
+};
+
  struct rv7xx_pl {
  	u32 sclk;
  	u32 mclk;
  	u16 vddc;
  	u16 vddci; /* eg+ only */
  	u32 flags;
-	enum amdgpu_pcie_gen pcie_gen; /* si+ only */
+	enum si_pcie_gen pcie_gen; /* si+ only */
  };
 
  struct rv7xx_ps {
@@ -967,9 +974,9 @@ struct si_power_info {
  	struct si_ulv_param ulv;
  	u32 max_cu;
  	/* pcie gen */
-	enum amdgpu_pcie_gen force_pcie_gen;
-	enum amdgpu_pcie_gen boot_pcie_gen;
-	enum amdgpu_pcie_gen acpi_pcie_gen;
+	enum si_pcie_gen force_pcie_gen;
+	enum si_pcie_gen boot_pcie_gen;
+	enum si_pcie_gen acpi_pcie_gen;
  	u32 sys_pcie_mask;
  	/* flags */
  	bool enable_dte;
author
#13 lore raw

PATCH v4 6/17 drm/amd/pm: do not expose the API used internally only in kv_dpm.c

In reply to Evan Quan

Move it to kv_dpm.c instead.

Change-Id I554332b386491a79b7913f72786f1e2cb1f8165b

--
v1->v2:
- rename the API with "kv_" prefix(Alex)

---
 drivers/gpu/drm/amd/pm/amdgpu_dpm.c       | 23 ---------------------
 drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h   |  2 --
 drivers/gpu/drm/amd/pm/powerplay/kv_dpm.c | 25 ++++++++++++++++++++++-
 3 files changed, 24 insertions(+), 26 deletions(-)
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +0 -23
index b31858ad9b83..efe6f8129c06 100644
@@ -209,29 +209,6 @@ static u32 amdgpu_dpm_get_vrefresh(struct amdgpu_device *adev)
 	return vrefresh;
 }
 
-bool amdgpu_is_internal_thermal_sensor(enum amdgpu_int_thermal_type sensor)
-{
-	switch (sensor) {
-	case THERMAL_TYPE_RV6XX:
-	case THERMAL_TYPE_RV770:
-	case THERMAL_TYPE_EVERGREEN:
-	case THERMAL_TYPE_SUMO:
-	case THERMAL_TYPE_NI:
-	case THERMAL_TYPE_SI:
-	case THERMAL_TYPE_CI:
-	case THERMAL_TYPE_KV:
-		return true;
-	case THERMAL_TYPE_ADT7473_WITH_INTERNAL:
-	case THERMAL_TYPE_EMC2103_WITH_INTERNAL:
-		return false; /* need special handling */
-	case THERMAL_TYPE_NONE:
-	case THERMAL_TYPE_EXTERNAL:
-	case THERMAL_TYPE_EXTERNAL_GPIO:
-	default:
-		return false;
-	}
-}
-
 union power_info {
 	struct _ATOM_POWERPLAY_INFO info;
 	struct _ATOM_POWERPLAY_INFO_V2 info_2;
drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h +0 -2
index f43b96dfe9d8..01120b302590 100644
@@ -374,8 +374,6 @@ u32 amdgpu_dpm_get_vblank_time(struct amdgpu_device *adev);
 int amdgpu_dpm_read_sensor(struct amdgpu_device *adev, enum amd_pp_sensors sensor,
 			   void *data, uint32_t *size);
 
-bool amdgpu_is_internal_thermal_sensor(enum amdgpu_int_thermal_type sensor);
-
 int amdgpu_get_platform_caps(struct amdgpu_device *adev);
 
 int amdgpu_parse_extended_power_table(struct amdgpu_device *adev);
drivers/gpu/drm/amd/pm/powerplay/kv_dpm.c +24 -1
index bcae42cef374..380a5336c74f 100644
@@ -1256,6 +1256,29 @@ static void kv_dpm_enable_bapm(void *handle, bool enable)
 	}
 }
 
+static bool kv_is_internal_thermal_sensor(enum amdgpu_int_thermal_type sensor)
+{
+	switch (sensor) {
+	case THERMAL_TYPE_RV6XX:
+	case THERMAL_TYPE_RV770:
+	case THERMAL_TYPE_EVERGREEN:
+	case THERMAL_TYPE_SUMO:
+	case THERMAL_TYPE_NI:
+	case THERMAL_TYPE_SI:
+	case THERMAL_TYPE_CI:
+	case THERMAL_TYPE_KV:
+		return true;
+	case THERMAL_TYPE_ADT7473_WITH_INTERNAL:
+	case THERMAL_TYPE_EMC2103_WITH_INTERNAL:
+		return false; /* need special handling */
+	case THERMAL_TYPE_NONE:
+	case THERMAL_TYPE_EXTERNAL:
+	case THERMAL_TYPE_EXTERNAL_GPIO:
+	default:
+		return false;
+	}
+}
+
 static int kv_dpm_enable(struct amdgpu_device *adev)
 {
 	struct kv_power_info *pi = kv_get_pi(adev);
@@ -1352,7 +1375,7 @@ static int kv_dpm_enable(struct amdgpu_device *adev)
 	}
 
 	if (adev->irq.installed &&
-	    amdgpu_is_internal_thermal_sensor(adev->pm.int_thermal_type)) {
+	    kv_is_internal_thermal_sensor(adev->pm.int_thermal_type)) {
 		ret = kv_set_thermal_temperature_range(adev, KV_TEMP_RANGE_MIN, KV_TEMP_RANGE_MAX);
 		if (ret) {
 			DRM_ERROR("kv_set_thermal_temperature_range failed\n");
Signature · 1 line
2.29.0
author
#14 lore raw

PATCH v4 7/17 drm/amd/pm: create a new holder for those APIs used only by legacy ASICs(si/kv)

In reply to Evan Quan

Those APIs are used only by legacy ASICs(si/kv). They cannot be shared by other ASICs. So, we create a new holder for them.

Change-Id I555dfa37e783a267b1d3b3a7db5c87fcc3f1556f

--
v1->v2:
- rename amdgpu_pm_compute_clocks as amdgpu_dpm_compute_clocks(Lijo)
v2->v3:
- add back the lock protections dropped unintentionally(Lijo)

---
 drivers/gpu/drm/amd/amdgpu/dce_v10_0.c        |    2 +-
 drivers/gpu/drm/amd/amdgpu/dce_v11_0.c        |    2 +-
 drivers/gpu/drm/amd/amdgpu/dce_v6_0.c         |    2 +-
 drivers/gpu/drm/amd/amdgpu/dce_v8_0.c         |    2 +-
 .../amd/display/amdgpu_dm/amdgpu_dm_pp_smu.c  |    2 +-
 .../gpu/drm/amd/include/kgd_pp_interface.h    |    1 +
 drivers/gpu/drm/amd/pm/amdgpu_dpm.c           | 1022 +---------------
 drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h       |   17 +-
 drivers/gpu/drm/amd/pm/powerplay/Makefile     |    2 +-
 drivers/gpu/drm/amd/pm/powerplay/kv_dpm.c     |    6 +-
 drivers/gpu/drm/amd/pm/powerplay/legacy_dpm.c | 1024 +++++++++++++++++
 drivers/gpu/drm/amd/pm/powerplay/legacy_dpm.h |   37 +
 drivers/gpu/drm/amd/pm/powerplay/si_dpm.c     |    6 +-
 13 files changed, 1091 insertions(+), 1034 deletions(-)
 create mode 100644 drivers/gpu/drm/amd/pm/powerplay/legacy_dpm.c
 create mode 100644 drivers/gpu/drm/amd/pm/powerplay/legacy_dpm.h
drivers/gpu/drm/amd/amdgpu/dce_v10_0.c +1 -1
index d1570a462a51..5d5205870861 100644
@@ -2532,7 +2532,7 @@ static void dce_v10_0_crtc_dpms(struct drm_crtc *crtc, int mode)
 		break;
 	}
 	/* adjust pm to dpms */
-	amdgpu_pm_compute_clocks(adev);
+	amdgpu_dpm_compute_clocks(adev);
 }
 
 static void dce_v10_0_crtc_prepare(struct drm_crtc *crtc)
drivers/gpu/drm/amd/amdgpu/dce_v11_0.c +1 -1
index 18a7b3bd633b..4d812b22c54f 100644
@@ -2608,7 +2608,7 @@ static void dce_v11_0_crtc_dpms(struct drm_crtc *crtc, int mode)
 		break;
 	}
 	/* adjust pm to dpms */
-	amdgpu_pm_compute_clocks(adev);
+	amdgpu_dpm_compute_clocks(adev);
 }
 
 static void dce_v11_0_crtc_prepare(struct drm_crtc *crtc)
drivers/gpu/drm/amd/amdgpu/dce_v6_0.c +1 -1
index c7803dc2b2d5..b90bc2adf778 100644
@@ -2424,7 +2424,7 @@ static void dce_v6_0_crtc_dpms(struct drm_crtc *crtc, int mode)
 		break;
 	}
 	/* adjust pm to dpms */
-	amdgpu_pm_compute_clocks(adev);
+	amdgpu_dpm_compute_clocks(adev);
 }
 
 static void dce_v6_0_crtc_prepare(struct drm_crtc *crtc)
drivers/gpu/drm/amd/amdgpu/dce_v8_0.c +1 -1
index 8318ee8339f1..7c1379b02f94 100644
@@ -2433,7 +2433,7 @@ static void dce_v8_0_crtc_dpms(struct drm_crtc *crtc, int mode)
 		break;
 	}
 	/* adjust pm to dpms */
-	amdgpu_pm_compute_clocks(adev);
+	amdgpu_dpm_compute_clocks(adev);
 }
 
 static void dce_v8_0_crtc_prepare(struct drm_crtc *crtc)
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_pp_smu.c +1 -1
index 46550811da00..75284e2cec74 100644
@@ -101,7 +101,7 @@ bool dm_pp_apply_display_requirements(
 
 		amdgpu_dpm_display_configuration_change(adev, &adev->pm.pm_display_cfg);
 
-		amdgpu_pm_compute_clocks(adev);
+		amdgpu_dpm_compute_clocks(adev);
 	}
 
 	return true;
drivers/gpu/drm/amd/include/kgd_pp_interface.h +1 -0
index 2e295facd086..cdf724dcf832 100644
@@ -404,6 +404,7 @@ struct amd_pm_funcs {
 	int (*get_dpm_clock_table)(void *handle,
 				   struct dpm_clocks *clock_table);
 	int (*get_smu_prv_buf_details)(void *handle, void **addr, size_t *size);
+	int (*change_power_state)(void *handle);
 };
 
 struct metrics_table_header {
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +14 -1008

1,099 lines not on this page · raw message

drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h +1 -16
index 01120b302590..89caece4ab3e 100644
@@ -366,24 +366,10 @@ enum amdgpu_display_gap
     AMDGPU_PM_DISPLAY_GAP_IGNORE       = 3,
 };
 
-void amdgpu_dpm_print_class_info(u32 class, u32 class2);
-void amdgpu_dpm_print_cap_info(u32 caps);
-void amdgpu_dpm_print_ps_status(struct amdgpu_device *adev,
-				struct amdgpu_ps *rps);
 u32 amdgpu_dpm_get_vblank_time(struct amdgpu_device *adev);
 int amdgpu_dpm_read_sensor(struct amdgpu_device *adev, enum amd_pp_sensors sensor,
 			   void *data, uint32_t *size);
 
-int amdgpu_get_platform_caps(struct amdgpu_device *adev);
-
-int amdgpu_parse_extended_power_table(struct amdgpu_device *adev);
-void amdgpu_free_extended_power_table(struct amdgpu_device *adev);
-
-void amdgpu_add_thermal_controller(struct amdgpu_device *adev);
-
-struct amd_vce_state*
-amdgpu_get_vce_clock_state(void *handle, u32 idx);
-
 int amdgpu_dpm_set_powergating_by_smu(struct amdgpu_device *adev,
 				      uint32_t block_type, bool gate);
 
@@ -434,11 +420,10 @@ int amdgpu_dpm_read_sensor(struct amdgpu_device *adev, enum amd_pp_sensors senso
 
 void amdgpu_dpm_thermal_work_handler(struct work_struct *work);
 
-void amdgpu_pm_compute_clocks(struct amdgpu_device *adev);
+void amdgpu_dpm_compute_clocks(struct amdgpu_device *adev);
 void amdgpu_dpm_enable_uvd(struct amdgpu_device *adev, bool enable);
 void amdgpu_dpm_enable_vce(struct amdgpu_device *adev, bool enable);
 void amdgpu_dpm_enable_jpeg(struct amdgpu_device *adev, bool enable);
-void amdgpu_pm_print_power_states(struct amdgpu_device *adev);
 int amdgpu_pm_load_smu_firmware(struct amdgpu_device *adev, uint32_t *smu_version);
 int amdgpu_dpm_set_light_sbr(struct amdgpu_device *adev, bool enable);
 int amdgpu_dpm_send_hbm_bad_pages_num(struct amdgpu_device *adev, uint32_t size);
drivers/gpu/drm/amd/pm/powerplay/Makefile +1 -1
index 0fb114adc79f..614d8b6a58ad 100644
@@ -28,7 +28,7 @@ AMD_POWERPLAY = $(addsuffix /Makefile,$(addprefix $(FULL_AMD_PATH)/pm/powerplay/
 
 include $(AMD_POWERPLAY)
 
-POWER_MGR-y = amd_powerplay.o
+POWER_MGR-y = amd_powerplay.o legacy_dpm.o
 
 POWER_MGR-$(CONFIG_DRM_AMDGPU_CIK)+= kv_dpm.o kv_smc.o
 
drivers/gpu/drm/amd/pm/powerplay/kv_dpm.c +4 -2
index 380a5336c74f..eed89835231c 100644
@@ -36,6 +36,7 @@
 
 #include "gca/gfx_7_2_d.h"
 #include "gca/gfx_7_2_sh_mask.h"
+#include "legacy_dpm.h"
 
 #define KV_MAX_DEEPSLEEP_DIVIDER_ID     5
 #define KV_MINIMUM_ENGINE_CLOCK         800
@@ -3087,7 +3088,7 @@ static int kv_dpm_hw_init(void *handle)
 	else
 		adev->pm.dpm_enabled = true;
 	mutex_unlock(&adev->pm.mutex);
-	amdgpu_pm_compute_clocks(adev);
+	amdgpu_dpm_compute_clocks(adev);
 	return ret;
 }
 
@@ -3135,7 +3136,7 @@ static int kv_dpm_resume(void *handle)
 			adev->pm.dpm_enabled = true;
 		mutex_unlock(&adev->pm.mutex);
 		if (adev->pm.dpm_enabled)
-			amdgpu_pm_compute_clocks(adev);
+			amdgpu_dpm_compute_clocks(adev);
 	}
 	return 0;
 }
@@ -3389,6 +3390,7 @@ static const struct amd_pm_funcs kv_dpm_funcs = {
 	.get_vce_clock_state = amdgpu_get_vce_clock_state,
 	.check_state_equal = kv_check_state_equal,
 	.read_sensor = &kv_dpm_read_sensor,
+	.change_power_state = amdgpu_dpm_change_power_state_locked,
 };
 
 static const struct amdgpu_irq_src_funcs kv_dpm_irq_funcs = {
drivers/gpu/drm/amd/pm/powerplay/legacy_dpm.c new file +1024 -0

1,024 lines not on this page · raw message

drivers/gpu/drm/amd/pm/powerplay/legacy_dpm.h new file +37 -0
new file mode 100644
index 000000000000..7ac30f1aed20
@@ -0,0 +1,37 @@
+/*
+ * Copyright 2021 Advanced Micro Devices, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ *
+ */
+#ifndef __LEGACY_DPM_H__
+#define __LEGACY_DPM_H__
+
+void amdgpu_dpm_print_class_info(u32 class, u32 class2);
+void amdgpu_dpm_print_cap_info(u32 caps);
+void amdgpu_dpm_print_ps_status(struct amdgpu_device *adev,
+				struct amdgpu_ps *rps);
+int amdgpu_get_platform_caps(struct amdgpu_device *adev);
+int amdgpu_parse_extended_power_table(struct amdgpu_device *adev);
+void amdgpu_free_extended_power_table(struct amdgpu_device *adev);
+void amdgpu_add_thermal_controller(struct amdgpu_device *adev);
+struct amd_vce_state* amdgpu_get_vce_clock_state(void *handle, u32 idx);
+int amdgpu_dpm_change_power_state_locked(void *handle);
+void amdgpu_pm_print_power_states(struct amdgpu_device *adev);
+#endif
drivers/gpu/drm/amd/pm/powerplay/si_dpm.c +4 -2
index ab0fa6c79255..35d287903aea 100644
@@ -37,6 +37,7 @@
 #include <linux/math64.h>
 #include <linux/seq_file.h>
 #include <linux/firmware.h>
+#include <legacy_dpm.h>
 
 #define MC_CG_ARB_FREQ_F0           0x0a
 #define MC_CG_ARB_FREQ_F1           0x0b
@@ -7800,7 +7801,7 @@ static int si_dpm_hw_init(void *handle)
 	else
 		adev->pm.dpm_enabled = true;
 	mutex_unlock(&adev->pm.mutex);
-	amdgpu_pm_compute_clocks(adev);
+	amdgpu_dpm_compute_clocks(adev);
 	return ret;
 }
 
@@ -7848,7 +7849,7 @@ static int si_dpm_resume(void *handle)
 			adev->pm.dpm_enabled = true;
 		mutex_unlock(&adev->pm.mutex);
 		if (adev->pm.dpm_enabled)
-			amdgpu_pm_compute_clocks(adev);
+			amdgpu_dpm_compute_clocks(adev);
 	}
 	return 0;
 }
@@ -8101,6 +8102,7 @@ static const struct amd_pm_funcs si_dpm_funcs = {
 	.check_state_equal = &si_check_state_equal,
 	.get_vce_clock_state = amdgpu_get_vce_clock_state,
 	.read_sensor = &si_dpm_read_sensor,
+	.change_power_state = amdgpu_dpm_change_power_state_locked,
 };
 
 static const struct amdgpu_irq_src_funcs si_dpm_irq_funcs = {
Signature · 1 line
2.29.0
author
#15 lore raw

PATCH v4 8/17 drm/amd/pm: move pp_force_state_enabled member to amdgpu_pm structure

In reply to Evan Quan

As it lables an internal pm state and amdgpu_pm structure is the more proper place than amdgpu_device structure for it.

Change-Id I7890e8fe7af2ecd8591d30442340deb8773bacc3
---
 drivers/gpu/drm/amd/amdgpu/amdgpu.h     | 1 -
 drivers/gpu/drm/amd/pm/amdgpu_pm.c      | 6 +++---
 drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h | 2 ++
 3 files changed, 5 insertions(+), 4 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +0 -1
index c5cfe2926ca1..c987813a4996 100644
@@ -950,7 +950,6 @@ struct amdgpu_device {
 
 	/* powerplay */
 	struct amd_powerplay		powerplay;
-	bool				pp_force_state_enabled;
 
 	/* smu */
 	struct smu_context		smu;
drivers/gpu/drm/amd/pm/amdgpu_pm.c +3 -3
index 3382d30b5d90..fa2f4e11e94e 100644
@@ -469,7 +469,7 @@ static ssize_t amdgpu_get_pp_force_state(struct device *dev,
 	if (adev->in_suspend && !adev->in_runpm)
 		return -EPERM;
 
-	if (adev->pp_force_state_enabled)
+	if (adev->pm.pp_force_state_enabled)
 		return amdgpu_get_pp_cur_state(dev, attr, buf);
 	else
 		return sysfs_emit(buf, "\n");
@@ -492,7 +492,7 @@ static ssize_t amdgpu_set_pp_force_state(struct device *dev,
 	if (adev->in_suspend && !adev->in_runpm)
 		return -EPERM;
 
-	adev->pp_force_state_enabled = false;
+	adev->pm.pp_force_state_enabled = false;
 
 	if (strlen(buf) == 1)
 		return count;
@@ -523,7 +523,7 @@ static ssize_t amdgpu_set_pp_force_state(struct device *dev,
 		if (ret)
 			goto err_out;
 
-		adev->pp_force_state_enabled = true;
+		adev->pm.pp_force_state_enabled = true;
 	}
 
 	pm_runtime_mark_last_busy(ddev->dev);
drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h +2 -0
index 89caece4ab3e..b7841a989d59 100644
@@ -335,6 +335,8 @@ struct amdgpu_pm {
 	struct list_head	pm_attr_list;
 
 	atomic_t		pwr_state[AMD_IP_BLOCK_TYPE_NUM];
+
+	bool			pp_force_state_enabled;
 };
 
 #define R600_SSTU_DFLT                               0
Signature · 1 line
2.29.0
author
#16 lore raw

PATCH v4 9/17 drm/amd/pm: optimize the amdgpu_pm_compute_clocks() implementations

In reply to Evan Quan

Drop cross callings and multi-function APIs. Also avoid exposing internal implementations details.

Change-Id I55e5ab3da6a70482f5f5d8c256eed2f754feae20

--
v1->v2:
- add back the adev->pm.dpm_enabled check(Lijo)

---
 .../gpu/drm/amd/include/kgd_pp_interface.h    |   2 +-
 drivers/gpu/drm/amd/pm/Makefile               |   2 +-
 drivers/gpu/drm/amd/pm/amdgpu_dpm.c           | 225 +++---------------
 drivers/gpu/drm/amd/pm/amdgpu_dpm_internal.c  |  94 ++++++++
 drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h       |   2 -
 .../gpu/drm/amd/pm/inc/amdgpu_dpm_internal.h  |  32 +++
 .../gpu/drm/amd/pm/powerplay/amd_powerplay.c  |  39 ++-
 drivers/gpu/drm/amd/pm/powerplay/kv_dpm.c     |   6 +-
 drivers/gpu/drm/amd/pm/powerplay/legacy_dpm.c |  60 ++++-
 drivers/gpu/drm/amd/pm/powerplay/legacy_dpm.h |   3 +-
 drivers/gpu/drm/amd/pm/powerplay/si_dpm.c     |  41 +++-
 11 files changed, 296 insertions(+), 210 deletions(-)
 create mode 100644 drivers/gpu/drm/amd/pm/amdgpu_dpm_internal.c
 create mode 100644 drivers/gpu/drm/amd/pm/inc/amdgpu_dpm_internal.h
drivers/gpu/drm/amd/include/kgd_pp_interface.h +1 -1
index cdf724dcf832..7919e96e772b 100644
@@ -404,7 +404,7 @@ struct amd_pm_funcs {
 	int (*get_dpm_clock_table)(void *handle,
 				   struct dpm_clocks *clock_table);
 	int (*get_smu_prv_buf_details)(void *handle, void **addr, size_t *size);
-	int (*change_power_state)(void *handle);
+	void (*pm_compute_clocks)(void *handle);
 };
 
 struct metrics_table_header {
drivers/gpu/drm/amd/pm/Makefile +1 -1
index 8cf6eff1ea93..d35ffde387f1 100644
@@ -40,7 +40,7 @@ AMD_PM = $(addsuffix /Makefile,$(addprefix $(FULL_AMD_PATH)/pm/,$(PM_LIBS)))
 
 include $(AMD_PM)
 
-PM_MGR = amdgpu_dpm.o amdgpu_pm.o
+PM_MGR = amdgpu_dpm.o amdgpu_pm.o amdgpu_dpm_internal.o
 
 AMD_PM_POWER = $(addprefix $(AMD_PM_PATH)/,$(PM_MGR))
 
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +29 -196

275 lines not on this page · raw message

drivers/gpu/drm/amd/pm/amdgpu_dpm_internal.c new file +94 -0

94 lines not on this page · raw message

drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h +0 -2
index b7841a989d59..b0791e855ad3 100644
@@ -420,8 +420,6 @@ void amdgpu_pm_acpi_event_handler(struct amdgpu_device *adev);
 int amdgpu_dpm_read_sensor(struct amdgpu_device *adev, enum amd_pp_sensors sensor,
 			   void *data, uint32_t *size);
 
-void amdgpu_dpm_thermal_work_handler(struct work_struct *work);
-
 void amdgpu_dpm_compute_clocks(struct amdgpu_device *adev);
 void amdgpu_dpm_enable_uvd(struct amdgpu_device *adev, bool enable);
 void amdgpu_dpm_enable_vce(struct amdgpu_device *adev, bool enable);
drivers/gpu/drm/amd/pm/inc/amdgpu_dpm_internal.h new file +32 -0
new file mode 100644
index 000000000000..5c2a89f0d5d5
@@ -0,0 +1,32 @@
+/*
+ * Copyright 2021 Advanced Micro Devices, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ *
+ */
+#ifndef __AMDGPU_DPM_INTERNAL_H__
+#define __AMDGPU_DPM_INTERNAL_H__
+
+void amdgpu_dpm_get_active_displays(struct amdgpu_device *adev);
+
+u32 amdgpu_dpm_get_vblank_time(struct amdgpu_device *adev);
+
+u32 amdgpu_dpm_get_vrefresh(struct amdgpu_device *adev);
+
+#endif
drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c +38 -1
index 20cb234d5061..d57d5c28c013 100644
@@ -31,7 +31,8 @@
 #include "power_state.h"
 #include "amdgpu.h"
 #include "hwmgr.h"
-
+#include "amdgpu_dpm_internal.h"
+#include "amdgpu_display.h"
 
 static const struct amd_pm_funcs pp_dpm_funcs;
 
@@ -1678,6 +1679,41 @@ static int pp_get_prv_buffer_details(void *handle, void **addr, size_t *size)
 	return 0;
 }
 
+static void pp_pm_compute_clocks(void *handle)
+{
+	struct pp_hwmgr *hwmgr = handle;
+	struct amdgpu_device *adev = hwmgr->adev;
+	int i = 0;
+
+	if (adev->mode_info.num_crtc)
+		amdgpu_display_bandwidth_update(adev);
+
+	for (i = 0; i < AMDGPU_MAX_RINGS; i++) {
+		struct amdgpu_ring *ring = adev->rings[i];
+		if (ring && ring->sched.ready)
+			amdgpu_fence_wait_empty(ring);
+	}
+
+	if (!amdgpu_device_has_dc_support(adev)) {
+		amdgpu_dpm_get_active_displays(adev);
+		adev->pm.pm_display_cfg.num_display = adev->pm.dpm.new_active_crtc_count;
+		adev->pm.pm_display_cfg.vrefresh = amdgpu_dpm_get_vrefresh(adev);
+		adev->pm.pm_display_cfg.min_vblank_time = amdgpu_dpm_get_vblank_time(adev);
+		/* we have issues with mclk switching with
+		 * refresh rates over 120 hz on the non-DC code.
+		 */
+		if (adev->pm.pm_display_cfg.vrefresh > 120)
+			adev->pm.pm_display_cfg.min_vblank_time = 0;
+
+		pp_display_configuration_change(handle,
+						&adev->pm.pm_display_cfg);
+	}
+
+	pp_dpm_dispatch_tasks(handle,
+			      AMD_PP_TASK_DISPLAY_CONFIG_CHANGE,
+			      NULL);
+}
+
 static const struct amd_pm_funcs pp_dpm_funcs = {
 	.load_firmware = pp_dpm_load_fw,
 	.wait_for_fw_loading_complete = pp_dpm_fw_loading_complete,
@@ -1742,4 +1778,5 @@ static const struct amd_pm_funcs pp_dpm_funcs = {
 	.get_gpu_metrics = pp_get_gpu_metrics,
 	.gfx_state_change_set = pp_gfx_state_change_set,
 	.get_smu_prv_buf_details = pp_get_prv_buffer_details,
+	.pm_compute_clocks = pp_pm_compute_clocks,
 };
drivers/gpu/drm/amd/pm/powerplay/kv_dpm.c +3 -3
index eed89835231c..72824ef61edd 100644
@@ -3088,7 +3088,7 @@ static int kv_dpm_hw_init(void *handle)
 	else
 		adev->pm.dpm_enabled = true;
 	mutex_unlock(&adev->pm.mutex);
-	amdgpu_dpm_compute_clocks(adev);
+	amdgpu_legacy_dpm_compute_clocks(adev);
 	return ret;
 }
 
@@ -3136,7 +3136,7 @@ static int kv_dpm_resume(void *handle)
 			adev->pm.dpm_enabled = true;
 		mutex_unlock(&adev->pm.mutex);
 		if (adev->pm.dpm_enabled)
-			amdgpu_dpm_compute_clocks(adev);
+			amdgpu_legacy_dpm_compute_clocks(adev);
 	}
 	return 0;
 }
@@ -3390,7 +3390,7 @@ static const struct amd_pm_funcs kv_dpm_funcs = {
 	.get_vce_clock_state = amdgpu_get_vce_clock_state,
 	.check_state_equal = kv_check_state_equal,
 	.read_sensor = &kv_dpm_read_sensor,
-	.change_power_state = amdgpu_dpm_change_power_state_locked,
+	.pm_compute_clocks = amdgpu_legacy_dpm_compute_clocks,
 };
 
 static const struct amdgpu_irq_src_funcs kv_dpm_irq_funcs = {
drivers/gpu/drm/amd/pm/powerplay/legacy_dpm.c +58 -2

76 lines not on this page · raw message

drivers/gpu/drm/amd/pm/powerplay/legacy_dpm.h +2 -1
index 7ac30f1aed20..93bd3973330c 100644
@@ -32,6 +32,7 @@ int amdgpu_parse_extended_power_table(struct amdgpu_device *adev);
 void amdgpu_free_extended_power_table(struct amdgpu_device *adev);
 void amdgpu_add_thermal_controller(struct amdgpu_device *adev);
 struct amd_vce_state* amdgpu_get_vce_clock_state(void *handle, u32 idx);
-int amdgpu_dpm_change_power_state_locked(void *handle);
 void amdgpu_pm_print_power_states(struct amdgpu_device *adev);
+void amdgpu_legacy_dpm_compute_clocks(void *handle);
+void amdgpu_dpm_thermal_work_handler(struct work_struct *work);
 #endif
drivers/gpu/drm/amd/pm/powerplay/si_dpm.c +38 -3

71 lines not on this page · raw message

Signature · 1 line
2.29.0
#17 lore raw

Re: [PATCH V4 09/17] drm/amd/pm: optimize the amdgpu_pm_compute_clocks() implementations

Quoted 292 lines · Evan Quan

Drop cross callings and multi-function APIs. Also avoid exposing internal implementations details.

Change-Id I55e5ab3da6a70482f5f5d8c256eed2f754feae20

--
v1->v2:
- add back the adev->pm.dpm_enabled check(Lijo)

---
  .../gpu/drm/amd/include/kgd_pp_interface.h    |   2 +-
  drivers/gpu/drm/amd/pm/Makefile               |   2 +-
  drivers/gpu/drm/amd/pm/amdgpu_dpm.c           | 225 +++---------------
  drivers/gpu/drm/amd/pm/amdgpu_dpm_internal.c  |  94 ++++++++
  drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h       |   2 -
  .../gpu/drm/amd/pm/inc/amdgpu_dpm_internal.h  |  32 +++
  .../gpu/drm/amd/pm/powerplay/amd_powerplay.c  |  39 ++-
  drivers/gpu/drm/amd/pm/powerplay/kv_dpm.c     |   6 +-
  drivers/gpu/drm/amd/pm/powerplay/legacy_dpm.c |  60 ++++-
  drivers/gpu/drm/amd/pm/powerplay/legacy_dpm.h |   3 +-
  drivers/gpu/drm/amd/pm/powerplay/si_dpm.c     |  41 +++-
  11 files changed, 296 insertions(+), 210 deletions(-)

create mode 100644 drivers/gpu/drm/amd/pm/amdgpu_dpm_internal.c create mode 100644 drivers/gpu/drm/amd/pm/inc/amdgpu_dpm_internal.h

drivers/gpu/drm/amd/include/kgd_pp_interface.h +1 -1
index cdf724dcf832..7919e96e772b 100644
@@ -404,7 +404,7 @@ struct amd_pm_funcs {
  	int (*get_dpm_clock_table)(void *handle,
  				   struct dpm_clocks *clock_table);
  	int (*get_smu_prv_buf_details)(void *handle, void **addr, size_t *size);
-	int (*change_power_state)(void *handle);
+	void (*pm_compute_clocks)(void *handle);
  };
 
  struct metrics_table_header {
drivers/gpu/drm/amd/pm/Makefile +1 -1
index 8cf6eff1ea93..d35ffde387f1 100644
@@ -40,7 +40,7 @@ AMD_PM = $(addsuffix /Makefile,$(addprefix $(FULL_AMD_PATH)/pm/,$(PM_LIBS)))
 
  include $(AMD_PM)
 
-PM_MGR = amdgpu_dpm.o amdgpu_pm.o
+PM_MGR = amdgpu_dpm.o amdgpu_pm.o amdgpu_dpm_internal.o
 
  AMD_PM_POWER = $(addprefix $(AMD_PM_PATH)/,$(PM_MGR))
 
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +22 -180
index fe6bf5d950c2..952fd865db13 100644
@@ -37,73 +37,6 @@
  #define amdgpu_dpm_enable_bapm(adev, e) \
  		((adev)->powerplay.pp_funcs->enable_bapm((adev)->powerplay.pp_handle, (e)))
 
-static void amdgpu_dpm_get_active_displays(struct amdgpu_device *adev)
-{
-	struct drm_device *ddev = adev_to_drm(adev);
-	struct drm_crtc *crtc;
-	struct amdgpu_crtc *amdgpu_crtc;
-
-	adev->pm.dpm.new_active_crtcs = 0;
-	adev->pm.dpm.new_active_crtc_count = 0;
-	if (adev->mode_info.num_crtc && adev->mode_info.mode_config_initialized) {
-		list_for_each_entry(crtc,
-				    &ddev->mode_config.crtc_list, head) {
-			amdgpu_crtc = to_amdgpu_crtc(crtc);
-			if (amdgpu_crtc->enabled) {
-				adev->pm.dpm.new_active_crtcs |= (1 << amdgpu_crtc->crtc_id);
-				adev->pm.dpm.new_active_crtc_count++;
-			}
-		}
-	}
-}
-
-u32 amdgpu_dpm_get_vblank_time(struct amdgpu_device *adev)
-{
-	struct drm_device *dev = adev_to_drm(adev);
-	struct drm_crtc *crtc;
-	struct amdgpu_crtc *amdgpu_crtc;
-	u32 vblank_in_pixels;
-	u32 vblank_time_us = 0xffffffff; /* if the displays are off, vblank time is max */
-
-	if (adev->mode_info.num_crtc && adev->mode_info.mode_config_initialized) {
-		list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
-			amdgpu_crtc = to_amdgpu_crtc(crtc);
-			if (crtc->enabled && amdgpu_crtc->enabled && amdgpu_crtc->hw_mode.clock) {
-				vblank_in_pixels =
-					amdgpu_crtc->hw_mode.crtc_htotal *
-					(amdgpu_crtc->hw_mode.crtc_vblank_end -
-					amdgpu_crtc->hw_mode.crtc_vdisplay +
-					(amdgpu_crtc->v_border * 2));
-
-				vblank_time_us = vblank_in_pixels * 1000 / amdgpu_crtc->hw_mode.clock;
-				break;
-			}
-		}
-	}
-
-	return vblank_time_us;
-}
-
-static u32 amdgpu_dpm_get_vrefresh(struct amdgpu_device *adev)
-{
-	struct drm_device *dev = adev_to_drm(adev);
-	struct drm_crtc *crtc;
-	struct amdgpu_crtc *amdgpu_crtc;
-	u32 vrefresh = 0;
-
-	if (adev->mode_info.num_crtc && adev->mode_info.mode_config_initialized) {
-		list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
-			amdgpu_crtc = to_amdgpu_crtc(crtc);
-			if (crtc->enabled && amdgpu_crtc->enabled && amdgpu_crtc->hw_mode.clock) {
-				vrefresh = drm_mode_vrefresh(&amdgpu_crtc->hw_mode);
-				break;
-			}
-		}
-	}
-
-	return vrefresh;
-}
-
  int amdgpu_dpm_get_sclk(struct amdgpu_device *adev, bool low)
  {
  	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
@@ -432,115 +365,38 @@ int amdgpu_dpm_read_sensor(struct amdgpu_device *adev, enum amd_pp_sensors senso
  	return ret;
  }
 
-void amdgpu_dpm_thermal_work_handler(struct work_struct *work)
-{
-	struct amdgpu_device *adev =
-		container_of(work, struct amdgpu_device,
-			     pm.dpm.thermal.work);
-	/* switch to the thermal state */
-	enum amd_pm_state_type dpm_state = POWER_STATE_TYPE_INTERNAL_THERMAL;
-	int temp, size = sizeof(temp);
-
-	if (!adev->pm.dpm_enabled)
-		return;
-
-	if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_GPU_TEMP,
-				    (void *)&temp, &size)) {
-		if (temp < adev->pm.dpm.thermal.min_temp)
-			/* switch back the user state */
-			dpm_state = adev->pm.dpm.user_state;
-	} else {
-		if (adev->pm.dpm.thermal.high_to_low)
-			/* switch back the user state */
-			dpm_state = adev->pm.dpm.user_state;
-	}
-	mutex_lock(&adev->pm.mutex);
-	if (dpm_state == POWER_STATE_TYPE_INTERNAL_THERMAL)
-		adev->pm.dpm.thermal_active = true;
-	else
-		adev->pm.dpm.thermal_active = false;
-	adev->pm.dpm.state = dpm_state;
-	mutex_unlock(&adev->pm.mutex);
-
-	amdgpu_dpm_compute_clocks(adev);
-}
-
  void amdgpu_dpm_compute_clocks(struct amdgpu_device *adev)
  {
-	int i = 0;
+	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
 
  	if (!adev->pm.dpm_enabled)
  		return;
 
-	if (adev->mode_info.num_crtc)
-		amdgpu_display_bandwidth_update(adev);
-
-	for (i = 0; i < AMDGPU_MAX_RINGS; i++) {
-		struct amdgpu_ring *ring = adev->rings[i];
-		if (ring && ring->sched.ready)
-			amdgpu_fence_wait_empty(ring);
-	}
+	if (!pp_funcs->pm_compute_clocks)
+		return;
 
-	if ((adev->family == AMDGPU_FAMILY_SI) ||
-	     (adev->family == AMDGPU_FAMILY_KV)) {
-		mutex_lock(&adev->pm.mutex);
-		amdgpu_dpm_get_active_displays(adev);
-		adev->powerplay.pp_funcs->change_power_state(adev->powerplay.pp_handle);
-		mutex_unlock(&adev->pm.mutex);
-	} else {
-		if (!amdgpu_device_has_dc_support(adev)) {
-			mutex_lock(&adev->pm.mutex);
-			amdgpu_dpm_get_active_displays(adev);
-			adev->pm.pm_display_cfg.num_display = adev->pm.dpm.new_active_crtc_count;
-			adev->pm.pm_display_cfg.vrefresh = amdgpu_dpm_get_vrefresh(adev);
-			adev->pm.pm_display_cfg.min_vblank_time = amdgpu_dpm_get_vblank_time(adev);
-			/* we have issues with mclk switching with
-			 * refresh rates over 120 hz on the non-DC code.
-			 */
-			if (adev->pm.pm_display_cfg.vrefresh > 120)
-				adev->pm.pm_display_cfg.min_vblank_time = 0;
-			if (adev->powerplay.pp_funcs->display_configuration_change)
-				adev->powerplay.pp_funcs->display_configuration_change(
-							adev->powerplay.pp_handle,
-							&adev->pm.pm_display_cfg);
-			mutex_unlock(&adev->pm.mutex);
-		}
-		amdgpu_dpm_dispatch_task(adev, AMD_PP_TASK_DISPLAY_CONFIG_CHANGE, NULL);
-	}
+	pp_funcs->pm_compute_clocks(adev->powerplay.pp_handle);
  }
 
  void amdgpu_dpm_enable_uvd(struct amdgpu_device *adev, bool enable)
  {
  	int ret = 0;
 
-	if (adev->family == AMDGPU_FAMILY_SI) {
-		mutex_lock(&adev->pm.mutex);
-		if (enable) {
-			adev->pm.dpm.uvd_active = true;
-			adev->pm.dpm.state = POWER_STATE_TYPE_INTERNAL_UVD;
-		} else {
-			adev->pm.dpm.uvd_active = false;
-		}
-		mutex_unlock(&adev->pm.mutex);
+	ret = amdgpu_dpm_set_powergating_by_smu(adev, AMD_IP_BLOCK_TYPE_UVD, !enable);
+	if (ret)
+		DRM_ERROR("Dpm %s uvd failed, ret = %d. \n",
+			  enable ? "enable" : "disable", ret);
 
-		amdgpu_dpm_compute_clocks(adev);
-	} else {
-		ret = amdgpu_dpm_set_powergating_by_smu(adev, AMD_IP_BLOCK_TYPE_UVD, !enable);
-		if (ret)
-			DRM_ERROR("Dpm %s uvd failed, ret = %d. \n",
-				  enable ? "enable" : "disable", ret);
-
-		/* enable/disable Low Memory PState for UVD (4k videos) */
-		if (adev->asic_type == CHIP_STONEY &&
-			adev->uvd.decode_image_width >= WIDTH_4K) {
-			struct pp_hwmgr *hwmgr = adev->powerplay.pp_handle;
-
-			if (hwmgr && hwmgr->hwmgr_func &&
-			    hwmgr->hwmgr_func->update_nbdpm_pstate)
-				hwmgr->hwmgr_func->update_nbdpm_pstate(hwmgr,
-								       !enable,
-								       true);
-		}
+	/* enable/disable Low Memory PState for UVD (4k videos) */
+	if (adev->asic_type == CHIP_STONEY &&
+		adev->uvd.decode_image_width >= WIDTH_4K) {
+		struct pp_hwmgr *hwmgr = adev->powerplay.pp_handle;
+
+		if (hwmgr && hwmgr->hwmgr_func &&
+		    hwmgr->hwmgr_func->update_nbdpm_pstate)
+			hwmgr->hwmgr_func->update_nbdpm_pstate(hwmgr,
+							       !enable,
+							       true);
  	}
  }
 
@@ -548,24 +404,10 @@ void amdgpu_dpm_enable_vce(struct amdgpu_device *adev, bool enable)
  {
  	int ret = 0;
 
-	if (adev->family == AMDGPU_FAMILY_SI) {
-		mutex_lock(&adev->pm.mutex);
-		if (enable) {
-			adev->pm.dpm.vce_active = true;
-			/* XXX select vce level based on ring/task */
-			adev->pm.dpm.vce_level = AMD_VCE_LEVEL_AC_ALL;
-		} else {
-			adev->pm.dpm.vce_active = false;
-		}
-		mutex_unlock(&adev->pm.mutex);
-
-		amdgpu_dpm_compute_clocks(adev);
-	} else {
-		ret = amdgpu_dpm_set_powergating_by_smu(adev, AMD_IP_BLOCK_TYPE_VCE, !enable);
-		if (ret)
-			DRM_ERROR("Dpm %s vce failed, ret = %d. \n",
-				  enable ? "enable" : "disable", ret);
-	}
+	ret = amdgpu_dpm_set_powergating_by_smu(adev, AMD_IP_BLOCK_TYPE_VCE, !enable);
+	if (ret)
+		DRM_ERROR("Dpm %s vce failed, ret = %d. \n",
+			  enable ? "enable" : "disable", ret);
  }
 
  void amdgpu_dpm_enable_jpeg(struct amdgpu_device *adev, bool enable)

drivers/gpu/drm/amd/pm/amdgpu_dpm.c void amdgpu_dpm_set_power_state(struct amdgpu_device *adev, · line 733

Quoted 7 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +0 -4
@@ -727,10 +569,7 @@ void amdgpu_dpm_set_power_state(struct amdgpu_device *adev,
  {
  	adev->pm.dpm.user_state = state;
 
-	if (adev->powerplay.pp_funcs->dispatch_tasks)
-		amdgpu_dpm_dispatch_task(adev, AMD_PP_TASK_ENABLE_USER_STATE, &state);
-	else
-		amdgpu_dpm_compute_clocks(adev);

Where is this handled now?

drivers/gpu/drm/amd/pm/amdgpu_dpm.c int amdgpu_dpm_set_sclk_od(struct amdgpu_device *adev, uint32_t value) · line 907

Quoted 12 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +1 -5
+	amdgpu_dpm_dispatch_task(adev, AMD_PP_TASK_ENABLE_USER_STATE, &state); >   }
 
  enum amd_dpm_forced_level amdgpu_dpm_get_performance_level(struct amdgpu_device *adev)
@@ -900,12 +739,9 @@ int amdgpu_dpm_set_sclk_od(struct amdgpu_device *adev, uint32_t value)
 
  	pp_funcs->set_sclk_od(adev->powerplay.pp_handle, value);
 
-	if (amdgpu_dpm_dispatch_task(adev,
-				     AMD_PP_TASK_READJUST_POWER_STATE,
-				     NULL) == -EOPNOTSUPP) {
-		adev->pm.dpm.current_ps = adev->pm.dpm.boot_ps;
-		amdgpu_dpm_compute_clocks(adev);

As per the earlier logic, it changes back to boot state clocks if it couldn't set the clocks. Where is this done now? Same for mclk also.

Thanks,
Lijo

Quoted 444 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +6 -7
-	}
+	amdgpu_dpm_dispatch_task(adev,
+				 AMD_PP_TASK_READJUST_POWER_STATE,
+				 NULL);
 
  	return 0;
  }
@@ -929,12 +765,9 @@ int amdgpu_dpm_set_mclk_od(struct amdgpu_device *adev, uint32_t value)
 
  	pp_funcs->set_mclk_od(adev->powerplay.pp_handle, value);
 
-	if (amdgpu_dpm_dispatch_task(adev,
-				     AMD_PP_TASK_READJUST_POWER_STATE,
-				     NULL) == -EOPNOTSUPP) {
-		adev->pm.dpm.current_ps = adev->pm.dpm.boot_ps;
-		amdgpu_dpm_compute_clocks(adev);
-	}
+	amdgpu_dpm_dispatch_task(adev,
+				 AMD_PP_TASK_READJUST_POWER_STATE,
+				 NULL);
 
  	return 0;
  }
drivers/gpu/drm/amd/pm/amdgpu_dpm_internal.c new file +94 -0
new file mode 100644
index 000000000000..ba5f6413412d
@@ -0,0 +1,94 @@
+/*
+ * Copyright 2021 Advanced Micro Devices, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ *
+ */
+
+#include "amdgpu.h"
+#include "amdgpu_display.h"
+#include "hwmgr.h"
+#include "amdgpu_smu.h"
+
+void amdgpu_dpm_get_active_displays(struct amdgpu_device *adev)
+{
+	struct drm_device *ddev = adev_to_drm(adev);
+	struct drm_crtc *crtc;
+	struct amdgpu_crtc *amdgpu_crtc;
+
+	adev->pm.dpm.new_active_crtcs = 0;
+	adev->pm.dpm.new_active_crtc_count = 0;
+	if (adev->mode_info.num_crtc && adev->mode_info.mode_config_initialized) {
+		list_for_each_entry(crtc,
+				    &ddev->mode_config.crtc_list, head) {
+			amdgpu_crtc = to_amdgpu_crtc(crtc);
+			if (amdgpu_crtc->enabled) {
+				adev->pm.dpm.new_active_crtcs |= (1 << amdgpu_crtc->crtc_id);
+				adev->pm.dpm.new_active_crtc_count++;
+			}
+		}
+	}
+}
+
+u32 amdgpu_dpm_get_vblank_time(struct amdgpu_device *adev)
+{
+	struct drm_device *dev = adev_to_drm(adev);
+	struct drm_crtc *crtc;
+	struct amdgpu_crtc *amdgpu_crtc;
+	u32 vblank_in_pixels;
+	u32 vblank_time_us = 0xffffffff; /* if the displays are off, vblank time is max */
+
+	if (adev->mode_info.num_crtc && adev->mode_info.mode_config_initialized) {
+		list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
+			amdgpu_crtc = to_amdgpu_crtc(crtc);
+			if (crtc->enabled && amdgpu_crtc->enabled && amdgpu_crtc->hw_mode.clock) {
+				vblank_in_pixels =
+					amdgpu_crtc->hw_mode.crtc_htotal *
+					(amdgpu_crtc->hw_mode.crtc_vblank_end -
+					amdgpu_crtc->hw_mode.crtc_vdisplay +
+					(amdgpu_crtc->v_border * 2));
+
+				vblank_time_us = vblank_in_pixels * 1000 / amdgpu_crtc->hw_mode.clock;
+				break;
+			}
+		}
+	}
+
+	return vblank_time_us;
+}
+
+u32 amdgpu_dpm_get_vrefresh(struct amdgpu_device *adev)
+{
+	struct drm_device *dev = adev_to_drm(adev);
+	struct drm_crtc *crtc;
+	struct amdgpu_crtc *amdgpu_crtc;
+	u32 vrefresh = 0;
+
+	if (adev->mode_info.num_crtc && adev->mode_info.mode_config_initialized) {
+		list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
+			amdgpu_crtc = to_amdgpu_crtc(crtc);
+			if (crtc->enabled && amdgpu_crtc->enabled && amdgpu_crtc->hw_mode.clock) {
+				vrefresh = drm_mode_vrefresh(&amdgpu_crtc->hw_mode);
+				break;
+			}
+		}
+	}
+
+	return vrefresh;
+}
drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h +0 -2
index b7841a989d59..b0791e855ad3 100644
@@ -420,8 +420,6 @@ void amdgpu_pm_acpi_event_handler(struct amdgpu_device *adev);
  int amdgpu_dpm_read_sensor(struct amdgpu_device *adev, enum amd_pp_sensors sensor,
  			   void *data, uint32_t *size);
 
-void amdgpu_dpm_thermal_work_handler(struct work_struct *work);
-
  void amdgpu_dpm_compute_clocks(struct amdgpu_device *adev);
  void amdgpu_dpm_enable_uvd(struct amdgpu_device *adev, bool enable);
  void amdgpu_dpm_enable_vce(struct amdgpu_device *adev, bool enable);
drivers/gpu/drm/amd/pm/inc/amdgpu_dpm_internal.h new file +32 -0
new file mode 100644
index 000000000000..5c2a89f0d5d5
@@ -0,0 +1,32 @@
+/*
+ * Copyright 2021 Advanced Micro Devices, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ *
+ */
+#ifndef __AMDGPU_DPM_INTERNAL_H__
+#define __AMDGPU_DPM_INTERNAL_H__
+
+void amdgpu_dpm_get_active_displays(struct amdgpu_device *adev);
+
+u32 amdgpu_dpm_get_vblank_time(struct amdgpu_device *adev);
+
+u32 amdgpu_dpm_get_vrefresh(struct amdgpu_device *adev);
+
+#endif
drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c +38 -1
index 20cb234d5061..d57d5c28c013 100644
@@ -31,7 +31,8 @@
  #include "power_state.h"
  #include "amdgpu.h"
  #include "hwmgr.h"
-
+#include "amdgpu_dpm_internal.h"
+#include "amdgpu_display.h"
 
  static const struct amd_pm_funcs pp_dpm_funcs;
 
@@ -1678,6 +1679,41 @@ static int pp_get_prv_buffer_details(void *handle, void **addr, size_t *size)
  	return 0;
  }
 
+static void pp_pm_compute_clocks(void *handle)
+{
+	struct pp_hwmgr *hwmgr = handle;
+	struct amdgpu_device *adev = hwmgr->adev;
+	int i = 0;
+
+	if (adev->mode_info.num_crtc)
+		amdgpu_display_bandwidth_update(adev);
+
+	for (i = 0; i < AMDGPU_MAX_RINGS; i++) {
+		struct amdgpu_ring *ring = adev->rings[i];
+		if (ring && ring->sched.ready)
+			amdgpu_fence_wait_empty(ring);
+	}
+
+	if (!amdgpu_device_has_dc_support(adev)) {
+		amdgpu_dpm_get_active_displays(adev);
+		adev->pm.pm_display_cfg.num_display = adev->pm.dpm.new_active_crtc_count;
+		adev->pm.pm_display_cfg.vrefresh = amdgpu_dpm_get_vrefresh(adev);
+		adev->pm.pm_display_cfg.min_vblank_time = amdgpu_dpm_get_vblank_time(adev);
+		/* we have issues with mclk switching with
+		 * refresh rates over 120 hz on the non-DC code.
+		 */
+		if (adev->pm.pm_display_cfg.vrefresh > 120)
+			adev->pm.pm_display_cfg.min_vblank_time = 0;
+
+		pp_display_configuration_change(handle,
+						&adev->pm.pm_display_cfg);
+	}
+
+	pp_dpm_dispatch_tasks(handle,
+			      AMD_PP_TASK_DISPLAY_CONFIG_CHANGE,
+			      NULL);
+}
+
  static const struct amd_pm_funcs pp_dpm_funcs = {
  	.load_firmware = pp_dpm_load_fw,
  	.wait_for_fw_loading_complete = pp_dpm_fw_loading_complete,
@@ -1742,4 +1778,5 @@ static const struct amd_pm_funcs pp_dpm_funcs = {
  	.get_gpu_metrics = pp_get_gpu_metrics,
  	.gfx_state_change_set = pp_gfx_state_change_set,
  	.get_smu_prv_buf_details = pp_get_prv_buffer_details,
+	.pm_compute_clocks = pp_pm_compute_clocks,
  };
drivers/gpu/drm/amd/pm/powerplay/kv_dpm.c +3 -3
index eed89835231c..72824ef61edd 100644
@@ -3088,7 +3088,7 @@ static int kv_dpm_hw_init(void *handle)
  	else
  		adev->pm.dpm_enabled = true;
  	mutex_unlock(&adev->pm.mutex);
-	amdgpu_dpm_compute_clocks(adev);
+	amdgpu_legacy_dpm_compute_clocks(adev);
  	return ret;
  }
 
@@ -3136,7 +3136,7 @@ static int kv_dpm_resume(void *handle)
  			adev->pm.dpm_enabled = true;
  		mutex_unlock(&adev->pm.mutex);
  		if (adev->pm.dpm_enabled)
-			amdgpu_dpm_compute_clocks(adev);
+			amdgpu_legacy_dpm_compute_clocks(adev);
  	}
  	return 0;
  }
@@ -3390,7 +3390,7 @@ static const struct amd_pm_funcs kv_dpm_funcs = {
  	.get_vce_clock_state = amdgpu_get_vce_clock_state,
  	.check_state_equal = kv_check_state_equal,
  	.read_sensor = &kv_dpm_read_sensor,
-	.change_power_state = amdgpu_dpm_change_power_state_locked,
+	.pm_compute_clocks = amdgpu_legacy_dpm_compute_clocks,
  };
 
  static const struct amdgpu_irq_src_funcs kv_dpm_irq_funcs = {
drivers/gpu/drm/amd/pm/powerplay/legacy_dpm.c +58 -2
index 67c84b7ad8e7..3c6ee493e410 100644
@@ -26,6 +26,8 @@
  #include "atom.h"
  #include "amd_pcie.h"
  #include "legacy_dpm.h"
+#include "amdgpu_dpm_internal.h"
+#include "amdgpu_display.h"
 
  #define amdgpu_dpm_pre_set_power_state(adev) \
  		((adev)->powerplay.pp_funcs->pre_set_power_state((adev)->powerplay.pp_handle))
@@ -949,9 +951,8 @@ static struct amdgpu_ps *amdgpu_dpm_pick_power_state(struct amdgpu_device *adev,
  	return NULL;
  }
 
-int amdgpu_dpm_change_power_state_locked(void *handle)
+static int amdgpu_dpm_change_power_state_locked(struct amdgpu_device *adev)
  {
-	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
  	struct amdgpu_ps *ps;
  	enum amd_pm_state_type dpm_state;
  	int ret;
@@ -1022,3 +1023,58 @@ int amdgpu_dpm_change_power_state_locked(void *handle)
 
  	return 0;
  }
+
+void amdgpu_legacy_dpm_compute_clocks(void *handle)
+{
+	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
+	int i = 0;
+
+	if (adev->mode_info.num_crtc)
+		amdgpu_display_bandwidth_update(adev);
+
+	for (i = 0; i < AMDGPU_MAX_RINGS; i++) {
+		struct amdgpu_ring *ring = adev->rings[i];
+		if (ring && ring->sched.ready)
+			amdgpu_fence_wait_empty(ring);
+	}
+
+	amdgpu_dpm_get_active_displays(adev);
+
+	amdgpu_dpm_change_power_state_locked(adev);
+}
+
+void amdgpu_dpm_thermal_work_handler(struct work_struct *work)
+{
+	struct amdgpu_device *adev =
+		container_of(work, struct amdgpu_device,
+			     pm.dpm.thermal.work);
+	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+	/* switch to the thermal state */
+	enum amd_pm_state_type dpm_state = POWER_STATE_TYPE_INTERNAL_THERMAL;
+	int temp, size = sizeof(temp);
+
+	if (!adev->pm.dpm_enabled)
+		return;
+
+	if (!pp_funcs->read_sensor(adev->powerplay.pp_handle,
+				   AMDGPU_PP_SENSOR_GPU_TEMP,
+				   (void *)&temp,
+				   &size)) {
+		if (temp < adev->pm.dpm.thermal.min_temp)
+			/* switch back the user state */
+			dpm_state = adev->pm.dpm.user_state;
+	} else {
+		if (adev->pm.dpm.thermal.high_to_low)
+			/* switch back the user state */
+			dpm_state = adev->pm.dpm.user_state;
+	}
+
+	if (dpm_state == POWER_STATE_TYPE_INTERNAL_THERMAL)
+		adev->pm.dpm.thermal_active = true;
+	else
+		adev->pm.dpm.thermal_active = false;
+
+	adev->pm.dpm.state = dpm_state;
+
+	amdgpu_legacy_dpm_compute_clocks(adev->powerplay.pp_handle);
+}
drivers/gpu/drm/amd/pm/powerplay/legacy_dpm.h +2 -1
index 7ac30f1aed20..93bd3973330c 100644
@@ -32,6 +32,7 @@ int amdgpu_parse_extended_power_table(struct amdgpu_device *adev);
  void amdgpu_free_extended_power_table(struct amdgpu_device *adev);
  void amdgpu_add_thermal_controller(struct amdgpu_device *adev);
  struct amd_vce_state* amdgpu_get_vce_clock_state(void *handle, u32 idx);
-int amdgpu_dpm_change_power_state_locked(void *handle);
  void amdgpu_pm_print_power_states(struct amdgpu_device *adev);
+void amdgpu_legacy_dpm_compute_clocks(void *handle);
+void amdgpu_dpm_thermal_work_handler(struct work_struct *work);
  #endif
drivers/gpu/drm/amd/pm/powerplay/si_dpm.c +38 -3
index 35d287903aea..e3b58249c6f4 100644
@@ -3891,6 +3891,40 @@ static int si_set_boot_state(struct amdgpu_device *adev)
  }
  #endif
 
+static int si_set_powergating_by_smu(void *handle,
+				     uint32_t block_type,
+				     bool gate)
+{
+	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
+
+	switch (block_type) {
+	case AMD_IP_BLOCK_TYPE_UVD:
+		if (!gate) {
+			adev->pm.dpm.uvd_active = true;
+			adev->pm.dpm.state = POWER_STATE_TYPE_INTERNAL_UVD;
+		} else {
+			adev->pm.dpm.uvd_active = false;
+		}
+
+		amdgpu_legacy_dpm_compute_clocks(handle);
+		break;
+	case AMD_IP_BLOCK_TYPE_VCE:
+		if (!gate) {
+			adev->pm.dpm.vce_active = true;
+			/* XXX select vce level based on ring/task */
+			adev->pm.dpm.vce_level = AMD_VCE_LEVEL_AC_ALL;
+		} else {
+			adev->pm.dpm.vce_active = false;
+		}
+
+		amdgpu_legacy_dpm_compute_clocks(handle);
+		break;
+	default:
+		break;
+	}
+	return 0;
+}
+
  static int si_set_sw_state(struct amdgpu_device *adev)
  {
  	return (amdgpu_si_send_msg_to_smc(adev, PPSMC_MSG_SwitchToSwState) == PPSMC_Result_OK) ?
@@ -7801,7 +7835,7 @@ static int si_dpm_hw_init(void *handle)
  	else
  		adev->pm.dpm_enabled = true;
  	mutex_unlock(&adev->pm.mutex);
-	amdgpu_dpm_compute_clocks(adev);
+	amdgpu_legacy_dpm_compute_clocks(adev);
  	return ret;
  }
 
@@ -7849,7 +7883,7 @@ static int si_dpm_resume(void *handle)
  			adev->pm.dpm_enabled = true;
  		mutex_unlock(&adev->pm.mutex);
  		if (adev->pm.dpm_enabled)
-			amdgpu_dpm_compute_clocks(adev);
+			amdgpu_legacy_dpm_compute_clocks(adev);
  	}
  	return 0;
  }
@@ -8094,6 +8128,7 @@ static const struct amd_pm_funcs si_dpm_funcs = {
  	.print_power_state = &si_dpm_print_power_state,
  	.debugfs_print_current_performance_level = &si_dpm_debugfs_print_current_performance_level,
  	.force_performance_level = &si_dpm_force_performance_level,
+	.set_powergating_by_smu = &si_set_powergating_by_smu,
  	.vblank_too_short = &si_dpm_vblank_too_short,
  	.set_fan_control_mode = &si_dpm_set_fan_control_mode,
  	.get_fan_control_mode = &si_dpm_get_fan_control_mode,
@@ -8102,7 +8137,7 @@ static const struct amd_pm_funcs si_dpm_funcs = {
  	.check_state_equal = &si_check_state_equal,
  	.get_vce_clock_state = amdgpu_get_vce_clock_state,
  	.read_sensor = &si_dpm_read_sensor,
-	.change_power_state = amdgpu_dpm_change_power_state_locked,
+	.pm_compute_clocks = amdgpu_legacy_dpm_compute_clocks,
  };
 
  static const struct amdgpu_irq_src_funcs si_dpm_irq_funcs = {
author
#18 lore raw

RE: [PATCH V4 09/17] drm/amd/pm: optimize the amdgpu_pm_compute_clocks() implementations

[AMD Official Use Only]

Quoted 354 lines

-----Original Message-----
From: Lazar, Lijo <[email protected]>
Sent: Thursday, December 9, 2021 8:32 PM
To: Quan, Evan <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>; Feng, Kenneth <[email protected]>
Subject: Re: [PATCH V4 09/17] drm/amd/pm: optimize the amdgpu_pm_compute_clocks() implementations

Quoted 21 lines · Evan Quan

Drop cross callings and multi-function APIs. Also avoid exposing internal implementations details.

Change-Id I55e5ab3da6a70482f5f5d8c256eed2f754feae20

--
v1->v2:
- add back the adev->pm.dpm_enabled check(Lijo)

---
  .../gpu/drm/amd/include/kgd_pp_interface.h    |   2 +-
  drivers/gpu/drm/amd/pm/Makefile               |   2 +-
  drivers/gpu/drm/amd/pm/amdgpu_dpm.c           | 225 +++---------------
  drivers/gpu/drm/amd/pm/amdgpu_dpm_internal.c  |  94 ++++++++
  drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h       |   2 -
  .../gpu/drm/amd/pm/inc/amdgpu_dpm_internal.h  |  32 +++
  .../gpu/drm/amd/pm/powerplay/amd_powerplay.c  |  39 ++-
  drivers/gpu/drm/amd/pm/powerplay/kv_dpm.c     |   6 +-
  drivers/gpu/drm/amd/pm/powerplay/legacy_dpm.c |  60 ++++-
  drivers/gpu/drm/amd/pm/powerplay/legacy_dpm.h |   3 +-
  drivers/gpu/drm/amd/pm/powerplay/si_dpm.c     |  41 +++-
  11 files changed, 296 insertions(+), 210 deletions(-)
Quoted 2 lines

create mode 100644 drivers/gpu/drm/amd/pm/amdgpu_dpm_internal.c create mode 100644

drivers/gpu/drm/amd/pm/inc/amdgpu_dpm_internal.h

drivers/gpu/drm/amd/include/kgd_pp_interface.h struct amd_pm_funcs { · line 406

Quoted 10 lines
drivers/gpu/drm/amd/include/kgd_pp_interface.h +0 -0
index cdf724dcf832..7919e96e772b 100644
@@ -404,7 +404,7 @@ struct amd_pm_funcs {
  	int (*get_dpm_clock_table)(void *handle,
  				   struct dpm_clocks *clock_table);
  	int (*get_smu_prv_buf_details)(void *handle, void **addr, size_t

*size);

Quoted 42 lines
drivers/gpu/drm/amd/include/kgd_pp_interface.h +1 -1
-	int (*change_power_state)(void *handle);
+	void (*pm_compute_clocks)(void *handle);
  };
 
  struct metrics_table_header {
(quoted diff) +0 -0

b/drivers/gpu/drm/amd/pm/Makefile index 8cf6eff1ea93..d35ffde387f1 100644

drivers/gpu/drm/amd/pm/Makefile +1 -1
@@ -40,7 +40,7 @@ AMD_PM = $(addsuffix /Makefile,$(addprefix
 $(FULL_AMD_PATH)/pm/,$(PM_LIBS)))
 
  include $(AMD_PM)
 
-PM_MGR = amdgpu_dpm.o amdgpu_pm.o
+PM_MGR = amdgpu_dpm.o amdgpu_pm.o amdgpu_dpm_internal.o
 
  AMD_PM_POWER = $(addprefix $(AMD_PM_PATH)/,$(PM_MGR))
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +0 -0
index fe6bf5d950c2..952fd865db13 100644
@@ -37,73 +37,6 @@
  #define amdgpu_dpm_enable_bapm(adev, e) \
 

((adev)->powerplay.pp_funcs->enable_bapm((adev)-
powerplay.pp_handle,
(e)))

-static void amdgpu_dpm_get_active_displays(struct amdgpu_device *adev) -{

drivers/gpu/drm/amd/pm/amdgpu_dpm.c +0 -7
-	struct drm_device *ddev = adev_to_drm(adev);
-	struct drm_crtc *crtc;
-	struct amdgpu_crtc *amdgpu_crtc;
-
-	adev->pm.dpm.new_active_crtcs = 0;
-	adev->pm.dpm.new_active_crtc_count = 0;
-	if (adev->mode_info.num_crtc && adev-

mode_info.mode_config_initialized) {

drivers/gpu/drm/amd/pm/amdgpu_dpm.c

Quoted 5 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +0 -5
-		list_for_each_entry(crtc,
-				    &ddev->mode_config.crtc_list, head) {
-			amdgpu_crtc = to_amdgpu_crtc(crtc);
-			if (amdgpu_crtc->enabled) {
-				adev->pm.dpm.new_active_crtcs |= (1 <<

amdgpu_crtc->crtc_id);

drivers/gpu/drm/amd/pm/amdgpu_dpm.c

Quoted 12 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +0 -12
-				adev->pm.dpm.new_active_crtc_count++;
-			}
-		}
-	}
-}
-
-u32 amdgpu_dpm_get_vblank_time(struct amdgpu_device *adev) -{
-	struct drm_device *dev = adev_to_drm(adev);
-	struct drm_crtc *crtc;
-	struct amdgpu_crtc *amdgpu_crtc;
-	u32 vblank_in_pixels;
-	u32 vblank_time_us = 0xffffffff; /* if the displays are off, vblank time

is max */

drivers/gpu/drm/amd/pm/amdgpu_dpm.c

Quoted 4 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +0 -2
-
-	if (adev->mode_info.num_crtc && adev-

mode_info.mode_config_initialized) {

drivers/gpu/drm/amd/pm/amdgpu_dpm.c +0 -1
-		list_for_each_entry(crtc, &dev->mode_config.crtc_list, head)

{

drivers/gpu/drm/amd/pm/amdgpu_dpm.c

Quoted 2 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +0 -2
-			amdgpu_crtc = to_amdgpu_crtc(crtc);
-			if (crtc->enabled && amdgpu_crtc->enabled &&

amdgpu_crtc->hw_mode.clock) {

drivers/gpu/drm/amd/pm/amdgpu_dpm.c

Quoted 2 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +0 -2
-				vblank_in_pixels =
-					amdgpu_crtc->hw_mode.crtc_htotal

*

drivers/gpu/drm/amd/pm/amdgpu_dpm.c

Quoted 7 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +0 -1
-					(amdgpu_crtc-

hw_mode.crtc_vblank_end -

drivers/gpu/drm/amd/pm/amdgpu_dpm.c +0 -1
-					amdgpu_crtc-

hw_mode.crtc_vdisplay +

drivers/gpu/drm/amd/pm/amdgpu_dpm.c +0 -3
-					(amdgpu_crtc->v_border * 2));
-
-				vblank_time_us = vblank_in_pixels * 1000 /

amdgpu_crtc->hw_mode.clock;

Quoted 16 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +0 -15
-				break;
-			}
-		}
-	}
-
-	return vblank_time_us;
-}
-
-static u32 amdgpu_dpm_get_vrefresh(struct amdgpu_device *adev) -{
-	struct drm_device *dev = adev_to_drm(adev);
-	struct drm_crtc *crtc;
-	struct amdgpu_crtc *amdgpu_crtc;
-	u32 vrefresh = 0;
-
-	if (adev->mode_info.num_crtc && adev-

mode_info.mode_config_initialized) {

drivers/gpu/drm/amd/pm/amdgpu_dpm.c

Quoted 1 line
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +0 -1
-		list_for_each_entry(crtc, &dev->mode_config.crtc_list, head)

{

drivers/gpu/drm/amd/pm/amdgpu_dpm.c

Quoted 2 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +0 -2
-			amdgpu_crtc = to_amdgpu_crtc(crtc);
-			if (crtc->enabled && amdgpu_crtc->enabled &&

amdgpu_crtc->hw_mode.clock) {

drivers/gpu/drm/amd/pm/amdgpu_dpm.c

Quoted 1 line
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +0 -1
-				vrefresh =

drm_mode_vrefresh(&amdgpu_crtc->hw_mode);

drivers/gpu/drm/amd/pm/amdgpu_dpm.c line 42

Quoted 11 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +0 -8
-				break;
-			}
-		}
-	}
-
-	return vrefresh;
-}
-
  int amdgpu_dpm_get_sclk(struct amdgpu_device *adev, bool low)
  {
  	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;

@@

Quoted 1 line

-432,115 +365,38 @@ int amdgpu_dpm_read_sensor(struct

amdgpu_device *adev, enum amd_pp_sensors senso

drivers/gpu/drm/amd/pm/amdgpu_dpm.c int amdgpu_dpm_read_sensor(struct amdgpu_device *adev, enum amd_pp_sensors senso

Quoted 9 lines
  	return ret;
  }
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +0 -6
-void amdgpu_dpm_thermal_work_handler(struct work_struct *work) -{
-	struct amdgpu_device *adev =
-		container_of(work, struct amdgpu_device,
-			     pm.dpm.thermal.work);
-	/* switch to the thermal state */
-	enum amd_pm_state_type dpm_state =

POWER_STATE_TYPE_INTERNAL_THERMAL;

drivers/gpu/drm/amd/pm/amdgpu_dpm.c int amdgpu_dpm_read_sensor(struct amdgpu_device *adev, enum amd_pp_sensors senso

Quoted 6 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +0 -6
-	int temp, size = sizeof(temp);
-
-	if (!adev->pm.dpm_enabled)
-		return;
-
-	if (!amdgpu_dpm_read_sensor(adev,

AMDGPU_PP_SENSOR_GPU_TEMP,

Quoted 52 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +3 -34
-				    (void *)&temp, &size)) {
-		if (temp < adev->pm.dpm.thermal.min_temp)
-			/* switch back the user state */
-			dpm_state = adev->pm.dpm.user_state;
-	} else {
-		if (adev->pm.dpm.thermal.high_to_low)
-			/* switch back the user state */
-			dpm_state = adev->pm.dpm.user_state;
-	}
-	mutex_lock(&adev->pm.mutex);
-	if (dpm_state == POWER_STATE_TYPE_INTERNAL_THERMAL)
-		adev->pm.dpm.thermal_active = true;
-	else
-		adev->pm.dpm.thermal_active = false;
-	adev->pm.dpm.state = dpm_state;
-	mutex_unlock(&adev->pm.mutex);
-
-	amdgpu_dpm_compute_clocks(adev);
-}
-
  void amdgpu_dpm_compute_clocks(struct amdgpu_device *adev)
  {
-	int i = 0;
+	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
 
  	if (!adev->pm.dpm_enabled)
  		return;
 
-	if (adev->mode_info.num_crtc)
-		amdgpu_display_bandwidth_update(adev);
-
-	for (i = 0; i < AMDGPU_MAX_RINGS; i++) {
-		struct amdgpu_ring *ring = adev->rings[i];
-		if (ring && ring->sched.ready)
-			amdgpu_fence_wait_empty(ring);
-	}
+	if (!pp_funcs->pm_compute_clocks)
+		return;
 
-	if ((adev->family == AMDGPU_FAMILY_SI) ||
-	     (adev->family == AMDGPU_FAMILY_KV)) {
-		mutex_lock(&adev->pm.mutex);
-		amdgpu_dpm_get_active_displays(adev);
-		adev->powerplay.pp_funcs->change_power_state(adev-

powerplay.pp_handle);

drivers/gpu/drm/amd/pm/amdgpu_dpm.c +0 -6
-		mutex_unlock(&adev->pm.mutex);
-	} else {
-		if (!amdgpu_device_has_dc_support(adev)) {
-			mutex_lock(&adev->pm.mutex);
-			amdgpu_dpm_get_active_displays(adev);
-			adev->pm.pm_display_cfg.num_display = adev-

pm.dpm.new_active_crtc_count;

drivers/gpu/drm/amd/pm/amdgpu_dpm.c

Quoted 1 line
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +0 -1
-			adev->pm.pm_display_cfg.vrefresh =

amdgpu_dpm_get_vrefresh(adev);

drivers/gpu/drm/amd/pm/amdgpu_dpm.c

Quoted 1 line
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +0 -1
-			adev->pm.pm_display_cfg.min_vblank_time =

amdgpu_dpm_get_vblank_time(adev);

drivers/gpu/drm/amd/pm/amdgpu_dpm.c int amdgpu_dpm_read_sensor(struct amdgpu_device *adev, enum amd_pp_sensors senso

Quoted 5 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +0 -5
-			/* we have issues with mclk switching with
-			 * refresh rates over 120 hz on the non-DC code.
-			 */
-			if (adev->pm.pm_display_cfg.vrefresh > 120)
-				adev->pm.pm_display_cfg.min_vblank_time

= 0;

drivers/gpu/drm/amd/pm/amdgpu_dpm.c int amdgpu_dpm_read_sensor(struct amdgpu_device *adev, enum amd_pp_sensors senso

Quoted 11 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +0 -1
-			if (adev->powerplay.pp_funcs-

display_configuration_change)

drivers/gpu/drm/amd/pm/amdgpu_dpm.c +0 -1
-				adev->powerplay.pp_funcs-

display_configuration_change(

drivers/gpu/drm/amd/pm/amdgpu_dpm.c +0 -1
-							adev-

powerplay.pp_handle,

drivers/gpu/drm/amd/pm/amdgpu_dpm.c +0 -1
-							&adev-

pm.pm_display_cfg);

drivers/gpu/drm/amd/pm/amdgpu_dpm.c +0 -3
-			mutex_unlock(&adev->pm.mutex);
-		}
-		amdgpu_dpm_dispatch_task(adev,

AMD_PP_TASK_DISPLAY_CONFIG_CHANGE, NULL);

drivers/gpu/drm/amd/pm/amdgpu_dpm.c int amdgpu_dpm_read_sensor(struct amdgpu_device *adev, enum amd_pp_sensors senso

Quoted 5 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +1 -1
-	}
+	pp_funcs->pm_compute_clocks(adev->powerplay.pp_handle);
  }
 
  void amdgpu_dpm_enable_uvd(struct amdgpu_device *adev, bool

enable)

drivers/gpu/drm/amd/pm/amdgpu_dpm.c int amdgpu_dpm_read_sensor(struct amdgpu_device *adev, enum amd_pp_sensors senso

Quoted 8 lines
  {
  	int ret = 0;
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +0 -5
-	if (adev->family == AMDGPU_FAMILY_SI) {
-		mutex_lock(&adev->pm.mutex);
-		if (enable) {
-			adev->pm.dpm.uvd_active = true;
-			adev->pm.dpm.state =

POWER_STATE_TYPE_INTERNAL_UVD;

drivers/gpu/drm/amd/pm/amdgpu_dpm.c int amdgpu_dpm_read_sensor(struct amdgpu_device *adev, enum amd_pp_sensors senso

Quoted 5 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +1 -4
-		} else {
-			adev->pm.dpm.uvd_active = false;
-		}
-		mutex_unlock(&adev->pm.mutex);
+	ret = amdgpu_dpm_set_powergating_by_smu(adev,

AMD_IP_BLOCK_TYPE_UVD, !enable);

drivers/gpu/drm/amd/pm/amdgpu_dpm.c int amdgpu_dpm_read_sensor(struct amdgpu_device *adev, enum amd_pp_sensors senso

Quoted 7 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +3 -3
+	if (ret)
+		DRM_ERROR("Dpm %s uvd failed, ret = %d. \n",
+			  enable ? "enable" : "disable", ret);
 
-		amdgpu_dpm_compute_clocks(adev);
-	} else {
-		ret = amdgpu_dpm_set_powergating_by_smu(adev,

AMD_IP_BLOCK_TYPE_UVD, !enable);

drivers/gpu/drm/amd/pm/amdgpu_dpm.c void amdgpu_dpm_enable_vce(struct

Quoted 32 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +0 -8
-		if (ret)
-			DRM_ERROR("Dpm %s uvd failed, ret = %d. \n",
-				  enable ? "enable" : "disable", ret);
-
-		/* enable/disable Low Memory PState for UVD (4k videos) */
-		if (adev->asic_type == CHIP_STONEY &&
-			adev->uvd.decode_image_width >= WIDTH_4K) {
-			struct pp_hwmgr *hwmgr = adev-

powerplay.pp_handle;

drivers/gpu/drm/amd/pm/amdgpu_dpm.c +0 -4
-
-			if (hwmgr && hwmgr->hwmgr_func &&
-			    hwmgr->hwmgr_func->update_nbdpm_pstate)
-				hwmgr->hwmgr_func-

update_nbdpm_pstate(hwmgr,

drivers/gpu/drm/amd/pm/amdgpu_dpm.c +8 -3
-								       !enable,
-								       true);
-		}
+	/* enable/disable Low Memory PState for UVD (4k videos) */
+	if (adev->asic_type == CHIP_STONEY &&
+		adev->uvd.decode_image_width >= WIDTH_4K) {
+		struct pp_hwmgr *hwmgr = adev->powerplay.pp_handle;
+
+		if (hwmgr && hwmgr->hwmgr_func &&
+		    hwmgr->hwmgr_func->update_nbdpm_pstate)
+			hwmgr->hwmgr_func-

update_nbdpm_pstate(hwmgr,

drivers/gpu/drm/amd/pm/amdgpu_dpm.c +2 -0
+							       !enable,
+							       true);
  	}
  }
@@ -548,24 +404,10 @@ void amdgpu_dpm_enable_vce(struct

amdgpu_device *adev, bool enable)

drivers/gpu/drm/amd/pm/amdgpu_dpm.c void amdgpu_dpm_enable_vce(struct amdgpu_device *adev, bool enable)

Quoted 9 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +0 -6
  {
  	int ret = 0;
 
-	if (adev->family == AMDGPU_FAMILY_SI) {
-		mutex_lock(&adev->pm.mutex);
-		if (enable) {
-			adev->pm.dpm.vce_active = true;
-			/* XXX select vce level based on ring/task */
-			adev->pm.dpm.vce_level =

AMD_VCE_LEVEL_AC_ALL;

drivers/gpu/drm/amd/pm/amdgpu_dpm.c void amdgpu_dpm_enable_vce(struct amdgpu_device *adev, bool enable)

Quoted 8 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +0 -8
-		} else {
-			adev->pm.dpm.vce_active = false;
-		}
-		mutex_unlock(&adev->pm.mutex);
-
-		amdgpu_dpm_compute_clocks(adev);
-	} else {
-		ret = amdgpu_dpm_set_powergating_by_smu(adev,

AMD_IP_BLOCK_TYPE_VCE, !enable);

drivers/gpu/drm/amd/pm/amdgpu_dpm.c void amdgpu_dpm_enable_vce(struct amdgpu_device *adev, bool enable)

Quoted 5 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +1 -4
-		if (ret)
-			DRM_ERROR("Dpm %s vce failed, ret = %d. \n",
-				  enable ? "enable" : "disable", ret);
-	}
+	ret = amdgpu_dpm_set_powergating_by_smu(adev,

AMD_IP_BLOCK_TYPE_VCE, !enable);

drivers/gpu/drm/amd/pm/amdgpu_dpm.c void amdgpu_dpm_enable_vce(struct amdgpu_device *adev, bool enable)

Quoted 6 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +3 -0
+	if (ret)
+		DRM_ERROR("Dpm %s vce failed, ret = %d. \n",
+			  enable ? "enable" : "disable", ret);
  }
 
  void amdgpu_dpm_enable_jpeg(struct amdgpu_device *adev, bool

enable)

drivers/gpu/drm/amd/pm/amdgpu_dpm.c void amdgpu_dpm_set_power_state(struct

Quoted 1 line
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +0 -0
@@ -727,10 +569,7 @@ void amdgpu_dpm_set_power_state(struct

amdgpu_device *adev,

Quoted 3 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +0 -0
  {
  	adev->pm.dpm.user_state = state;
 
Quoted 7 lines

drivers/gpu/drm/amd/pm/amdgpu_dpm.c void amdgpu_dpm_set_power_state(struct · line 731

Quoted 2 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +0 -2
-	if (adev->powerplay.pp_funcs->dispatch_tasks)
-		amdgpu_dpm_dispatch_task(adev,

AMD_PP_TASK_ENABLE_USER_STATE, &state);

drivers/gpu/drm/amd/pm/amdgpu_dpm.c void amdgpu_dpm_set_power_state(struct · line 733

Quoted 2 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +0 -2
-	else
-		amdgpu_dpm_compute_clocks(adev);

Where is this handled now?

[Quan, Evan] Thanks! This will be fixed in patch2 with your another comment there.

Quoted 11 lines

drivers/gpu/drm/amd/pm/amdgpu_dpm.c void amdgpu_dpm_set_power_state(struct · line 572

Quoted 2 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +1 -0
+	amdgpu_dpm_dispatch_task(adev,

AMD_PP_TASK_ENABLE_USER_STATE, &state); > }

drivers/gpu/drm/amd/pm/amdgpu_dpm.c void amdgpu_dpm_set_power_state(struct · line 573

Quoted 2 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +0 -0
  enum amd_dpm_forced_level

amdgpu_dpm_get_performance_level(struct

Quoted 5 lines

amdgpu_device *adev) @@ -900,12 +739,9 @@ int amdgpu_dpm_set_sclk_od(struct amdgpu_device *adev, uint32_t value)

  	pp_funcs->set_sclk_od(adev->powerplay.pp_handle, value);
Quoted 8 lines

drivers/gpu/drm/amd/pm/amdgpu_dpm.c int amdgpu_dpm_set_sclk_od(struct amdgpu_device *adev, uint32_t value) · line 907

Quoted 5 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +0 -5
-	if (amdgpu_dpm_dispatch_task(adev,
-				     AMD_PP_TASK_READJUST_POWER_STATE,
-				     NULL) == -EOPNOTSUPP) {
-		adev->pm.dpm.current_ps = adev->pm.dpm.boot_ps;
-		amdgpu_dpm_compute_clocks(adev);

As per the earlier logic, it changes back to boot state clocks if it couldn't set the clocks. Where is this done now? Same for mclk also.

[Quan, Evan] The problem was brought in by the 2dn patch of the series.
There on !pp_funcs->set_sclk_od, EOPNOTSUPP will be returned. To stick to original logic, no error should be returned on that. Will fix that in patch2.

BR
Evan

Quoted 524 lines

Thanks,
Lijo

drivers/gpu/drm/amd/pm/amdgpu_dpm.c int amdgpu_dpm_set_mclk_od(struct

Quoted 8 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +3 -1
-	}
+	amdgpu_dpm_dispatch_task(adev,
+				 AMD_PP_TASK_READJUST_POWER_STATE,
+				 NULL);
 
  	return 0;
  }
@@ -929,12 +765,9 @@ int amdgpu_dpm_set_mclk_od(struct

amdgpu_device

Quoted 33 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +3 -6
 *adev, uint32_t value)
 
  	pp_funcs->set_mclk_od(adev->powerplay.pp_handle, value);
 
-	if (amdgpu_dpm_dispatch_task(adev,
-				     AMD_PP_TASK_READJUST_POWER_STATE,
-				     NULL) == -EOPNOTSUPP) {
-		adev->pm.dpm.current_ps = adev->pm.dpm.boot_ps;
-		amdgpu_dpm_compute_clocks(adev);
-	}
+	amdgpu_dpm_dispatch_task(adev,
+				 AMD_PP_TASK_READJUST_POWER_STATE,
+				 NULL);
 
  	return 0;
  }
drivers/gpu/drm/amd/pm/amdgpu_dpm_internal.c new file +10 -0
new file mode 100644
index 000000000000..ba5f6413412d
@@ -0,0 +1,94 @@
+/*
+ * Copyright 2021 Advanced Micro Devices, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person
+obtaining a
+ * copy of this software and associated documentation files (the
+"Software"),
+ * to deal in the Software without restriction, including without
+limitation
+ * the rights to use, copy, modify, merge, publish, distribute,

drivers/gpu/drm/amd/pm/amdgpu_dpm_internal.c line 20

Quoted 10 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm_internal.c new file +10 -0
+sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom
+the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY

KIND,

drivers/gpu/drm/amd/pm/amdgpu_dpm_internal.c line 24

Quoted 4 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm_internal.c new file +4 -0
+EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN

NO EVENT

drivers/gpu/drm/amd/pm/amdgpu_dpm_internal.c line 30

Quoted 6 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm_internal.c new file +6 -0
+SHALL
+ * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM,
+DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR

THE USE

Quoted 19 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm_internal.c new file +18 -0
+OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ *
+ */
+
+#include "amdgpu.h"
+#include "amdgpu_display.h"
+#include "hwmgr.h"
+#include "amdgpu_smu.h"
+
+void amdgpu_dpm_get_active_displays(struct amdgpu_device *adev) {
+	struct drm_device *ddev = adev_to_drm(adev);
+	struct drm_crtc *crtc;
+	struct amdgpu_crtc *amdgpu_crtc;
+
+	adev->pm.dpm.new_active_crtcs = 0;
+	adev->pm.dpm.new_active_crtc_count = 0;
+	if (adev->mode_info.num_crtc && adev-

mode_info.mode_config_initialized) {

drivers/gpu/drm/amd/pm/amdgpu_dpm_internal.c

Quoted 5 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm_internal.c new file +5 -0
+		list_for_each_entry(crtc,
+				    &ddev->mode_config.crtc_list, head) {
+			amdgpu_crtc = to_amdgpu_crtc(crtc);
+			if (amdgpu_crtc->enabled) {
+				adev->pm.dpm.new_active_crtcs |= (1 <<

amdgpu_crtc->crtc_id);

Quoted 16 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm_internal.c new file +15 -0
+				adev->pm.dpm.new_active_crtc_count++;
+			}
+		}
+	}
+}
+
+u32 amdgpu_dpm_get_vblank_time(struct amdgpu_device *adev) {
+	struct drm_device *dev = adev_to_drm(adev);
+	struct drm_crtc *crtc;
+	struct amdgpu_crtc *amdgpu_crtc;
+	u32 vblank_in_pixels;
+	u32 vblank_time_us = 0xffffffff; /* if the displays are off, vblank
+time is max */
+
+	if (adev->mode_info.num_crtc && adev-

mode_info.mode_config_initialized) {

drivers/gpu/drm/amd/pm/amdgpu_dpm_internal.c

Quoted 1 line
drivers/gpu/drm/amd/pm/amdgpu_dpm_internal.c new file +1 -0
+		list_for_each_entry(crtc, &dev->mode_config.crtc_list, head)

{

drivers/gpu/drm/amd/pm/amdgpu_dpm_internal.c

Quoted 2 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm_internal.c new file +2 -0
+			amdgpu_crtc = to_amdgpu_crtc(crtc);
+			if (crtc->enabled && amdgpu_crtc->enabled &&

amdgpu_crtc->hw_mode.clock) {

drivers/gpu/drm/amd/pm/amdgpu_dpm_internal.c

Quoted 2 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm_internal.c new file +2 -0
+				vblank_in_pixels =
+					amdgpu_crtc->hw_mode.crtc_htotal

*

drivers/gpu/drm/amd/pm/amdgpu_dpm_internal.c

Quoted 7 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm_internal.c new file +1 -0
+					(amdgpu_crtc-

hw_mode.crtc_vblank_end -

drivers/gpu/drm/amd/pm/amdgpu_dpm_internal.c new file +1 -0
+					amdgpu_crtc-

hw_mode.crtc_vdisplay +

drivers/gpu/drm/amd/pm/amdgpu_dpm_internal.c new file +3 -0
+					(amdgpu_crtc->v_border * 2));
+
+				vblank_time_us = vblank_in_pixels * 1000 /

amdgpu_crtc->hw_mode.clock;

Quoted 16 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm_internal.c new file +15 -0
+				break;
+			}
+		}
+	}
+
+	return vblank_time_us;
+}
+
+u32 amdgpu_dpm_get_vrefresh(struct amdgpu_device *adev) {
+	struct drm_device *dev = adev_to_drm(adev);
+	struct drm_crtc *crtc;
+	struct amdgpu_crtc *amdgpu_crtc;
+	u32 vrefresh = 0;
+
+	if (adev->mode_info.num_crtc && adev-

mode_info.mode_config_initialized) {

drivers/gpu/drm/amd/pm/amdgpu_dpm_internal.c

Quoted 1 line
drivers/gpu/drm/amd/pm/amdgpu_dpm_internal.c new file +1 -0
+		list_for_each_entry(crtc, &dev->mode_config.crtc_list, head)

{

drivers/gpu/drm/amd/pm/amdgpu_dpm_internal.c

Quoted 2 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm_internal.c new file +2 -0
+			amdgpu_crtc = to_amdgpu_crtc(crtc);
+			if (crtc->enabled && amdgpu_crtc->enabled &&

amdgpu_crtc->hw_mode.clock) {

drivers/gpu/drm/amd/pm/amdgpu_dpm_internal.c

Quoted 1 line
drivers/gpu/drm/amd/pm/amdgpu_dpm_internal.c new file +1 -0
+				vrefresh =

drm_mode_vrefresh(&amdgpu_crtc->hw_mode);

drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h void amdgpu_pm_acpi_event_handler(struct

Quoted 13 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm_internal.c new file +7 -0
+				break;
+			}
+		}
+	}
+
+	return vrefresh;
+}
drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h +0 -0
index b7841a989d59..b0791e855ad3 100644
@@ -420,8 +420,6 @@ void amdgpu_pm_acpi_event_handler(struct

amdgpu_device *adev);

drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h void amdgpu_pm_acpi_event_handler(struct · line 420

Quoted 1 line
drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h +0 -0
  int amdgpu_dpm_read_sensor(struct amdgpu_device *adev, enum

amd_pp_sensors sensor,

drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h void amdgpu_pm_acpi_event_handler(struct amdgpu_device *adev);

Quoted 6 lines
drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h +0 -2
  			   void *data, uint32_t *size);
 
-void amdgpu_dpm_thermal_work_handler(struct work_struct *work);
-
  void amdgpu_dpm_compute_clocks(struct amdgpu_device *adev);
  void amdgpu_dpm_enable_uvd(struct amdgpu_device *adev, bool

enable);

drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h void amdgpu_pm_acpi_event_handler(struct · line 425

Quoted 1 line
drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h +0 -0
  void amdgpu_dpm_enable_vce(struct amdgpu_device *adev, bool

enable);

Quoted 17 lines
drivers/gpu/drm/amd/pm/inc/amdgpu_dpm_internal.h new file +10 -0
new file mode 100644
index 000000000000..5c2a89f0d5d5
@@ -0,0 +1,32 @@
+/*
+ * Copyright 2021 Advanced Micro Devices, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person
+obtaining a
+ * copy of this software and associated documentation files (the
+"Software"),
+ * to deal in the Software without restriction, including without
+limitation
+ * the rights to use, copy, modify, merge, publish, distribute,

drivers/gpu/drm/amd/pm/inc/amdgpu_dpm_internal.h line 20

Quoted 10 lines
drivers/gpu/drm/amd/pm/inc/amdgpu_dpm_internal.h new file +10 -0
+sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom
+the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY

KIND,

drivers/gpu/drm/amd/pm/inc/amdgpu_dpm_internal.h line 24

Quoted 4 lines
drivers/gpu/drm/amd/pm/inc/amdgpu_dpm_internal.h new file +4 -0
+EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN

NO EVENT

drivers/gpu/drm/amd/pm/inc/amdgpu_dpm_internal.h line 30

Quoted 6 lines
drivers/gpu/drm/amd/pm/inc/amdgpu_dpm_internal.h new file +6 -0
+SHALL
+ * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM,
+DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR

THE USE

drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c static int pp_get_prv_buffer_details(void

Quoted 30 lines
drivers/gpu/drm/amd/pm/inc/amdgpu_dpm_internal.h new file +14 -0
+OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ *
+ */
+#ifndef __AMDGPU_DPM_INTERNAL_H__
+#define __AMDGPU_DPM_INTERNAL_H__
+
+void amdgpu_dpm_get_active_displays(struct amdgpu_device *adev);
+
+u32 amdgpu_dpm_get_vblank_time(struct amdgpu_device *adev);
+
+u32 amdgpu_dpm_get_vrefresh(struct amdgpu_device *adev);
+
+#endif
drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c +2 -1
index 20cb234d5061..d57d5c28c013 100644
@@ -31,7 +31,8 @@
  #include "power_state.h"
  #include "amdgpu.h"
  #include "hwmgr.h"
-
+#include "amdgpu_dpm_internal.h"
+#include "amdgpu_display.h"
 
  static const struct amd_pm_funcs pp_dpm_funcs;
 
@@ -1678,6 +1679,41 @@ static int pp_get_prv_buffer_details(void

*handle, void **addr, size_t *size)

Quoted 12 lines
drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c +9 -0
  	return 0;
  }
 
+static void pp_pm_compute_clocks(void *handle) {
+	struct pp_hwmgr *hwmgr = handle;
+	struct amdgpu_device *adev = hwmgr->adev;
+	int i = 0;
+
+	if (adev->mode_info.num_crtc)
+		amdgpu_display_bandwidth_update(adev);
+
+	for (i = 0; i < AMDGPU_MAX_RINGS; i++) {

drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c static int pp_get_prv_buffer_details(void *handle, void **addr, size_t *size)

Quoted 10 lines
drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c +9 -0
+		struct amdgpu_ring *ring = adev->rings[i];
+		if (ring && ring->sched.ready)
+			amdgpu_fence_wait_empty(ring);
+	}
+
+	if (!amdgpu_device_has_dc_support(adev)) {
+		amdgpu_dpm_get_active_displays(adev);
+		adev->pm.pm_display_cfg.num_display = adev-
 pm.dpm.new_active_crtc_count;
+		adev->pm.pm_display_cfg.vrefresh =

amdgpu_dpm_get_vrefresh(adev);

drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c static int pp_get_prv_buffer_details(void · line 1701

Quoted 1 line
drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c +1 -0
+		adev->pm.pm_display_cfg.min_vblank_time =

amdgpu_dpm_get_vblank_time(adev);

Quoted 8 lines
drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c +8 -0
+		/* we have issues with mclk switching with
+		 * refresh rates over 120 hz on the non-DC code.
+		 */
+		if (adev->pm.pm_display_cfg.vrefresh > 120)
+			adev->pm.pm_display_cfg.min_vblank_time = 0;
+
+		pp_display_configuration_change(handle,
+						&adev->pm.pm_display_cfg);

drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c static int pp_get_prv_buffer_details(void *handle, void **addr, size_t *size) · line 1719

Quoted 10 lines
drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c +7 -0
+	}
+
+	pp_dpm_dispatch_tasks(handle,
+			      AMD_PP_TASK_DISPLAY_CONFIG_CHANGE,
+			      NULL);
+}
+
  static const struct amd_pm_funcs pp_dpm_funcs = {
  	.load_firmware = pp_dpm_load_fw,
  	.wait_for_fw_loading_complete = pp_dpm_fw_loading_complete,

@@

drivers/gpu/drm/amd/pm/powerplay/kv_dpm.c static const struct amd_pm_funcs kv_dpm_funcs

Quoted 30 lines

-1742,4 +1778,5 @@ static const struct amd_pm_funcs pp_dpm_funcs = {
.get_gpu_metrics = pp_get_gpu_metrics, .gfx_state_change_set = pp_gfx_state_change_set, .get_smu_prv_buf_details = pp_get_prv_buffer_details,

drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c +1 -0
+	.pm_compute_clocks = pp_pm_compute_clocks,
  };
drivers/gpu/drm/amd/pm/powerplay/kv_dpm.c +2 -2
index eed89835231c..72824ef61edd 100644
@@ -3088,7 +3088,7 @@ static int kv_dpm_hw_init(void *handle)
  	else
  		adev->pm.dpm_enabled = true;
  	mutex_unlock(&adev->pm.mutex);
-	amdgpu_dpm_compute_clocks(adev);
+	amdgpu_legacy_dpm_compute_clocks(adev);
  	return ret;
  }
 
@@ -3136,7 +3136,7 @@ static int kv_dpm_resume(void *handle)
  			adev->pm.dpm_enabled = true;
  		mutex_unlock(&adev->pm.mutex);
  		if (adev->pm.dpm_enabled)
-			amdgpu_dpm_compute_clocks(adev);
+			amdgpu_legacy_dpm_compute_clocks(adev);
  	}
  	return 0;
  }
@@ -3390,7 +3390,7 @@ static const struct amd_pm_funcs kv_dpm_funcs

= {

Quoted 29 lines
drivers/gpu/drm/amd/pm/powerplay/kv_dpm.c +1 -2
  	.get_vce_clock_state = amdgpu_get_vce_clock_state,
  	.check_state_equal = kv_check_state_equal,
  	.read_sensor = &kv_dpm_read_sensor,
-	.change_power_state = amdgpu_dpm_change_power_state_locked,
+	.pm_compute_clocks = amdgpu_legacy_dpm_compute_clocks,
  };
 
  static const struct amdgpu_irq_src_funcs kv_dpm_irq_funcs = { diff
--git a/drivers/gpu/drm/amd/pm/powerplay/legacy_dpm.c

b/drivers/gpu/drm/amd/pm/powerplay/legacy_dpm.c
index 67c84b7ad8e7..3c6ee493e410 100644

drivers/gpu/drm/amd/pm/powerplay/legacy_dpm.c +2 -0
@@ -26,6 +26,8 @@
  #include "atom.h"
  #include "amd_pcie.h"
  #include "legacy_dpm.h"
+#include "amdgpu_dpm_internal.h"
+#include "amdgpu_display.h"
 
  #define amdgpu_dpm_pre_set_power_state(adev) \
 

((adev)->powerplay.pp_funcs->pre_set_power_state((adev)- powerplay.pp_
handle)) @@ -949,9 +951,8 @@ static struct amdgpu_ps *amdgpu_dpm_pick_power_state(struct amdgpu_device *adev,
return NULL;
}

drivers/gpu/drm/amd/pm/powerplay/legacy_dpm.c

Quoted 2 lines
drivers/gpu/drm/amd/pm/powerplay/legacy_dpm.c +1 -1
-int amdgpu_dpm_change_power_state_locked(void *handle)
+static int amdgpu_dpm_change_power_state_locked(struct

amdgpu_device

drivers/gpu/drm/amd/pm/powerplay/legacy_dpm.c int

Quoted 7 lines
drivers/gpu/drm/amd/pm/powerplay/legacy_dpm.c +1 -1
+*adev)
  {
-	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
  	struct amdgpu_ps *ps;
  	enum amd_pm_state_type dpm_state;
  	int ret;
@@ -1022,3 +1023,58 @@ int

amdgpu_dpm_change_power_state_locked(void

Quoted 20 lines
drivers/gpu/drm/amd/pm/powerplay/legacy_dpm.c +16 -0
 *handle)
 
  	return 0;
  }
+
+void amdgpu_legacy_dpm_compute_clocks(void *handle) {
+	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
+	int i = 0;
+
+	if (adev->mode_info.num_crtc)
+		amdgpu_display_bandwidth_update(adev);
+
+	for (i = 0; i < AMDGPU_MAX_RINGS; i++) {
+		struct amdgpu_ring *ring = adev->rings[i];
+		if (ring && ring->sched.ready)
+			amdgpu_fence_wait_empty(ring);
+	}
+
+	amdgpu_dpm_get_active_displays(adev);
+

drivers/gpu/drm/amd/pm/powerplay/legacy_dpm.c int amdgpu_dpm_change_power_state_locked(void *handle)

Quoted 10 lines
drivers/gpu/drm/amd/pm/powerplay/legacy_dpm.c +10 -0
+	amdgpu_dpm_change_power_state_locked(adev);
+}
+
+void amdgpu_dpm_thermal_work_handler(struct work_struct *work) {
+	struct amdgpu_device *adev =
+		container_of(work, struct amdgpu_device,
+			     pm.dpm.thermal.work);
+	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+	/* switch to the thermal state */
+	enum amd_pm_state_type dpm_state =

POWER_STATE_TYPE_INTERNAL_THERMAL;

drivers/gpu/drm/amd/pm/powerplay/legacy_dpm.h int amdgpu_parse_extended_power_table(struct

Quoted 34 lines
drivers/gpu/drm/amd/pm/powerplay/legacy_dpm.c +26 -0
+	int temp, size = sizeof(temp);
+
+	if (!adev->pm.dpm_enabled)
+		return;
+
+	if (!pp_funcs->read_sensor(adev->powerplay.pp_handle,
+				   AMDGPU_PP_SENSOR_GPU_TEMP,
+				   (void *)&temp,
+				   &size)) {
+		if (temp < adev->pm.dpm.thermal.min_temp)
+			/* switch back the user state */
+			dpm_state = adev->pm.dpm.user_state;
+	} else {
+		if (adev->pm.dpm.thermal.high_to_low)
+			/* switch back the user state */
+			dpm_state = adev->pm.dpm.user_state;
+	}
+
+	if (dpm_state == POWER_STATE_TYPE_INTERNAL_THERMAL)
+		adev->pm.dpm.thermal_active = true;
+	else
+		adev->pm.dpm.thermal_active = false;
+
+	adev->pm.dpm.state = dpm_state;
+
+	amdgpu_legacy_dpm_compute_clocks(adev-

powerplay.pp_handle);

drivers/gpu/drm/amd/pm/powerplay/legacy_dpm.c +1 -0
+}
drivers/gpu/drm/amd/pm/powerplay/legacy_dpm.h +0 -0
index 7ac30f1aed20..93bd3973330c 100644
@@ -32,6 +32,7 @@ int amdgpu_parse_extended_power_table(struct

amdgpu_device *adev);

drivers/gpu/drm/amd/pm/powerplay/legacy_dpm.h int amdgpu_parse_extended_power_table(struct · line 32

Quoted 1 line
drivers/gpu/drm/amd/pm/powerplay/legacy_dpm.h +0 -0
  void amdgpu_free_extended_power_table(struct amdgpu_device

*adev);

drivers/gpu/drm/amd/pm/powerplay/si_dpm.c static int si_set_boot_state(struct

Quoted 13 lines
drivers/gpu/drm/amd/pm/powerplay/legacy_dpm.h +2 -0
  void amdgpu_add_thermal_controller(struct amdgpu_device *adev);
  struct amd_vce_state* amdgpu_get_vce_clock_state(void *handle, u32
 idx); -int amdgpu_dpm_change_power_state_locked(void *handle);
  void amdgpu_pm_print_power_states(struct amdgpu_device *adev);
+void amdgpu_legacy_dpm_compute_clocks(void *handle); void
+amdgpu_dpm_thermal_work_handler(struct work_struct *work);
  #endif
drivers/gpu/drm/amd/pm/powerplay/si_dpm.c +0 -0
index 35d287903aea..e3b58249c6f4 100644
@@ -3891,6 +3891,40 @@ static int si_set_boot_state(struct

amdgpu_device *adev)

Quoted 4 lines
drivers/gpu/drm/amd/pm/powerplay/si_dpm.c +1 -0
  }
  #endif
 
+static int si_set_powergating_by_smu(void *handle,

drivers/gpu/drm/amd/pm/powerplay/si_dpm.c static int si_set_boot_state(struct amdgpu_device *adev)

Quoted 10 lines
drivers/gpu/drm/amd/pm/powerplay/si_dpm.c +10 -0
+				     uint32_t block_type,
+				     bool gate)
+{
+	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
+
+	switch (block_type) {
+	case AMD_IP_BLOCK_TYPE_UVD:
+		if (!gate) {
+			adev->pm.dpm.uvd_active = true;
+			adev->pm.dpm.state =

POWER_STATE_TYPE_INTERNAL_UVD;

drivers/gpu/drm/amd/pm/powerplay/si_dpm.c static int si_set_boot_state(struct amdgpu_device *adev)

Quoted 11 lines
drivers/gpu/drm/amd/pm/powerplay/si_dpm.c +11 -0
+		} else {
+			adev->pm.dpm.uvd_active = false;
+		}
+
+		amdgpu_legacy_dpm_compute_clocks(handle);
+		break;
+	case AMD_IP_BLOCK_TYPE_VCE:
+		if (!gate) {
+			adev->pm.dpm.vce_active = true;
+			/* XXX select vce level based on ring/task */
+			adev->pm.dpm.vce_level =

AMD_VCE_LEVEL_AC_ALL;

Quoted 5 lines
drivers/gpu/drm/amd/pm/powerplay/si_dpm.c +5 -0
+		} else {
+			adev->pm.dpm.vce_active = false;
+		}
+
+		amdgpu_legacy_dpm_compute_clocks(handle);

drivers/gpu/drm/amd/pm/powerplay/si_dpm.c static int si_set_boot_state(struct amdgpu_device *adev)

Quoted 10 lines
drivers/gpu/drm/amd/pm/powerplay/si_dpm.c +7 -0
+		break;
+	default:
+		break;
+	}
+	return 0;
+}
+
  static int si_set_sw_state(struct amdgpu_device *adev)
  {
  	return (amdgpu_si_send_msg_to_smc(adev,

PPSMC_MSG_SwitchToSwState) == PPSMC_Result_OK) ?

drivers/gpu/drm/amd/pm/powerplay/si_dpm.c static const struct amd_pm_funcs si_dpm_funcs

Quoted 19 lines
drivers/gpu/drm/amd/pm/powerplay/si_dpm.c +2 -2
@@ -7801,7 +7835,7 @@ static int si_dpm_hw_init(void *handle)
  	else
  		adev->pm.dpm_enabled = true;
  	mutex_unlock(&adev->pm.mutex);
-	amdgpu_dpm_compute_clocks(adev);
+	amdgpu_legacy_dpm_compute_clocks(adev);
  	return ret;
  }
 
@@ -7849,7 +7883,7 @@ static int si_dpm_resume(void *handle)
  			adev->pm.dpm_enabled = true;
  		mutex_unlock(&adev->pm.mutex);
  		if (adev->pm.dpm_enabled)
-			amdgpu_dpm_compute_clocks(adev);
+			amdgpu_legacy_dpm_compute_clocks(adev);
  	}
  	return 0;
  }
@@ -8094,6 +8128,7 @@ static const struct amd_pm_funcs si_dpm_funcs

= {

drivers/gpu/drm/amd/pm/powerplay/si_dpm.c static const struct amd_pm_funcs si_dpm_funcs · line 8129

Quoted 2 lines
drivers/gpu/drm/amd/pm/powerplay/si_dpm.c +0 -0
  	.print_power_state = &si_dpm_print_power_state,
  	.debugfs_print_current_performance_level =

&si_dpm_debugfs_print_current_performance_level,

drivers/gpu/drm/amd/pm/powerplay/si_dpm.c static const struct amd_pm_funcs si_dpm_funcs = {

Quoted 5 lines
drivers/gpu/drm/amd/pm/powerplay/si_dpm.c +1 -0
  	.force_performance_level = &si_dpm_force_performance_level,
+	.set_powergating_by_smu = &si_set_powergating_by_smu,
  	.vblank_too_short = &si_dpm_vblank_too_short,
  	.set_fan_control_mode = &si_dpm_set_fan_control_mode,
  	.get_fan_control_mode = &si_dpm_get_fan_control_mode, @@ -

8102,7

Quoted 10 lines

+8137,7 @@ static const struct amd_pm_funcs si_dpm_funcs = {
.check_state_equal = &si_check_state_equal, .get_vce_clock_state = amdgpu_get_vce_clock_state, .read_sensor = &si_dpm_read_sensor,

drivers/gpu/drm/amd/pm/powerplay/si_dpm.c +1 -1
-	.change_power_state = amdgpu_dpm_change_power_state_locked,
+	.pm_compute_clocks = amdgpu_legacy_dpm_compute_clocks,
  };
 
  static const struct amdgpu_irq_src_funcs si_dpm_irq_funcs = {