Skip to contentSkip to conversation

drm/amd/pp: clean header file hwmgr.h

PATCH In review Rex Zhu 3 participants 19 messages Mar 22, 2018 – Mar 23, 2018 11 messages not in the archive

Subsystems (2)
lore
Share & tools
lore

Rex Zhu

author
#0 lore raw

PATCH 1/6 drm/amd/pp: clean header file hwmgr.h

Change-Id I087bcdc56977a8434706362f4e05593c5e7c2522
---
 drivers/gpu/drm/amd/powerplay/hwmgr/smu_helper.h |  3 +++
 drivers/gpu/drm/amd/powerplay/inc/hwmgr.h        | 15 ++++++---------
 2 files changed, 9 insertions(+), 9 deletions(-)
drivers/gpu/drm/amd/powerplay/hwmgr/smu_helper.h +3 -0
index 6429dc2..d37d16e 100644
@@ -27,6 +27,9 @@
 struct pp_hwmgr;
 struct phm_ppt_v1_voltage_lookup_table;
 
+uint8_t convert_to_vid(uint16_t vddc);
+uint16_t convert_to_vddc(uint8_t vid);
+
 extern int phm_wait_for_register_unequal(struct pp_hwmgr *hwmgr,
 					uint32_t index,
 					uint32_t value, uint32_t mask);
drivers/gpu/drm/amd/powerplay/inc/hwmgr.h +6 -9
index d742d9d..17f811d 100644
@@ -39,9 +39,6 @@
 
 #define VOLTAGE_SCALE 4
 
-uint8_t convert_to_vid(uint16_t vddc);
-uint16_t convert_to_vddc(uint8_t vid);
-
 enum DISPLAY_GAP {
 	DISPLAY_GAP_VBLANK_OR_WM = 0,   /* Wait for vblank or MCHG watermark. */
 	DISPLAY_GAP_VBLANK       = 1,   /* Wait for vblank. */
@@ -784,12 +781,12 @@ struct pp_hwmgr {
 	uint32_t workload_setting[Workload_Policy_Max];
 };
 
-extern int hwmgr_early_init(struct pp_hwmgr *hwmgr);
-extern int hwmgr_hw_init(struct pp_hwmgr *hwmgr);
-extern int hwmgr_hw_fini(struct pp_hwmgr *hwmgr);
-extern int hwmgr_hw_suspend(struct pp_hwmgr *hwmgr);
-extern int hwmgr_hw_resume(struct pp_hwmgr *hwmgr);
-extern int hwmgr_handle_task(struct pp_hwmgr *hwmgr,
+int hwmgr_early_init(struct pp_hwmgr *hwmgr);
+int hwmgr_hw_init(struct pp_hwmgr *hwmgr);
+int hwmgr_hw_fini(struct pp_hwmgr *hwmgr);
+int hwmgr_hw_suspend(struct pp_hwmgr *hwmgr);
+int hwmgr_hw_resume(struct pp_hwmgr *hwmgr);
+int hwmgr_handle_task(struct pp_hwmgr *hwmgr,
 				enum amd_pp_task task_id,
 				enum amd_pm_state_type *user_state);
 
Signature · 6 lines
1.9.1

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
author
#2 lore raw

PATCH 2/6 drm/amd/pp: Add hwmgr_sw_init/fini functioins

In reply to a message not in the archive

Clean up pp ip functions

Change-Id Id06159202edabdfcb19fcc20e1291ce93db56d5d
---
 drivers/gpu/drm/amd/powerplay/amd_powerplay.c | 368 ++++++--------------------
 drivers/gpu/drm/amd/powerplay/hwmgr/hwmgr.c   |  74 ++++--
 drivers/gpu/drm/amd/powerplay/inc/hwmgr.h     |   7 +-
 3 files changed, 145 insertions(+), 304 deletions(-)
drivers/gpu/drm/amd/powerplay/amd_powerplay.c +83 -285
index 7e8ad30..5d7d9ec 100644
@@ -31,24 +31,11 @@
 #include "amdgpu.h"
 #include "hwmgr.h"
 
-#define PP_DPM_DISABLED 0xCCCC
-
 static int pp_dpm_dispatch_tasks(void *handle, enum amd_pp_task task_id,
 		enum amd_pm_state_type *user_state);
 
 static const struct amd_pm_funcs pp_dpm_funcs;
 
-static inline int pp_check(struct pp_hwmgr *hwmgr)
-{
-	if (hwmgr == NULL || hwmgr->smumgr_funcs == NULL)
-		return -EINVAL;
-
-	if (hwmgr->pm_en == 0 || hwmgr->hwmgr_func == NULL)
-		return PP_DPM_DISABLED;
-
-	return 0;
-}
-
 static int amd_powerplay_create(struct amdgpu_device *adev)
 {
 	struct pp_hwmgr *hwmgr;
@@ -73,7 +60,7 @@ static int amd_powerplay_create(struct amdgpu_device *adev)
 }
 
 
-static int amd_powerplay_destroy(struct amdgpu_device *adev)
+static void amd_powerplay_destroy(struct amdgpu_device *adev)
 {
 	struct pp_hwmgr *hwmgr = adev->powerplay.pp_handle;
 
@@ -82,8 +69,6 @@ static int amd_powerplay_destroy(struct amdgpu_device *adev)
 
 	kfree(hwmgr);
 	hwmgr = NULL;
-
-	return 0;
 }
 
 static int pp_early_init(void *handle)
@@ -109,18 +94,9 @@ static int pp_sw_init(void *handle)
 	struct pp_hwmgr *hwmgr = adev->powerplay.pp_handle;
 	int ret = 0;
 
-	ret = pp_check(hwmgr);
-
-	if (ret >= 0) {
-		if (hwmgr->smumgr_funcs->smu_init == NULL)
-			return -EINVAL;
+	ret = hwmgr_sw_init(hwmgr);
 
-		ret = hwmgr->smumgr_funcs->smu_init(hwmgr);
-
-		phm_register_irq_handlers(hwmgr);
-
-		pr_debug("amdgpu: powerplay sw initialized\n");
-	}
+	pr_debug("amdgpu: powerplay sw init %s\n", ret ? "failed" : "successfully");
 
 	return ret;
 }
@@ -129,13 +105,8 @@ static int pp_sw_fini(void *handle)
 {
 	struct amdgpu_device *adev = handle;
 	struct pp_hwmgr *hwmgr = adev->powerplay.pp_handle;
-	int ret = 0;
 
-	ret = pp_check(hwmgr);
-	if (ret >= 0) {
-		if (hwmgr->smumgr_funcs->smu_fini != NULL)
-			hwmgr->smumgr_funcs->smu_fini(hwmgr);
-	}
+	hwmgr_sw_fini(hwmgr);
 
 	if (adev->firmware.load_type == AMDGPU_FW_LOAD_SMU)
 		amdgpu_ucode_fini_bo(adev);
@@ -152,40 +123,20 @@ static int pp_hw_init(void *handle)
 	if (adev->firmware.load_type == AMDGPU_FW_LOAD_SMU)
 		amdgpu_ucode_init_bo(adev);
 
-	ret = pp_check(hwmgr);
+	ret = hwmgr_hw_init(hwmgr);
 
-	if (ret >= 0) {
-		if (hwmgr->smumgr_funcs->start_smu == NULL)
-			return -EINVAL;
+	if (ret)
+		pr_err("amdgpu: powerplay hw init failed\n");
 
-		if (hwmgr->smumgr_funcs->start_smu(hwmgr)) {
-			pr_err("smc start failed\n");
-			hwmgr->smumgr_funcs->smu_fini(hwmgr);
-			return -EINVAL;
-		}
-		if (ret == PP_DPM_DISABLED)
-			goto exit;
-		ret = hwmgr_hw_init(hwmgr);
-		if (ret)
-			goto exit;
-	}
 	return ret;
-exit:
-	hwmgr->pm_en = 0;
-	cgs_notify_dpm_enabled(hwmgr->device, false);
-	return 0;
-
 }
 
 static int pp_hw_fini(void *handle)
 {
 	struct amdgpu_device *adev = handle;
 	struct pp_hwmgr *hwmgr = adev->powerplay.pp_handle;
-	int ret = 0;
 
-	ret = pp_check(hwmgr);
-	if (ret == 0)
-		hwmgr_hw_fini(hwmgr);
+	hwmgr_hw_fini(hwmgr);
 
 	return 0;
 }
@@ -194,11 +145,8 @@ static int pp_late_init(void *handle)
 {
 	struct amdgpu_device *adev = handle;
 	struct pp_hwmgr *hwmgr = adev->powerplay.pp_handle;
-	int ret = 0;
-
-	ret = pp_check(hwmgr);
 
-	if (ret == 0)
+	if (hwmgr && hwmgr->pm_en)
 		pp_dpm_dispatch_tasks(hwmgr,
 					AMD_PP_TASK_COMPLETE_INIT, NULL);
 
@@ -233,12 +181,9 @@ static int pp_set_powergating_state(void *handle,
 {
 	struct amdgpu_device *adev = handle;
 	struct pp_hwmgr *hwmgr = adev->powerplay.pp_handle;
-	int ret = 0;
 
-	ret = pp_check(hwmgr);
-
-	if (ret)
-		return ret;
+	if (!hwmgr || !hwmgr->pm_en)
+		return 0;
 
 	if (hwmgr->hwmgr_func->enable_per_cu_power_gating == NULL) {
 		pr_info("%s was not implemented.\n", __func__);
@@ -254,38 +199,16 @@ static int pp_suspend(void *handle)
 {
 	struct amdgpu_device *adev = handle;
 	struct pp_hwmgr *hwmgr = adev->powerplay.pp_handle;
-	int ret = 0;
 
-	ret = pp_check(hwmgr);
-	if (ret == 0)
-		hwmgr_hw_suspend(hwmgr);
-	return 0;
+	return hwmgr_suspend(hwmgr);
 }
 
 static int pp_resume(void *handle)
 {
 	struct amdgpu_device *adev = handle;
 	struct pp_hwmgr *hwmgr = adev->powerplay.pp_handle;
-	int ret;
-
-	ret = pp_check(hwmgr);
-
-	if (ret < 0)
-		return ret;
-
-	if (hwmgr->smumgr_funcs->start_smu == NULL)
-		return -EINVAL;
-
-	if (hwmgr->smumgr_funcs->start_smu(hwmgr)) {
-		pr_err("smc start failed\n");
-		hwmgr->smumgr_funcs->smu_fini(hwmgr);
-		return -EINVAL;
-	}
-
-	if (ret == PP_DPM_DISABLED)
-		return 0;
 
-	return hwmgr_hw_resume(hwmgr);
+	return hwmgr_resume(hwmgr);
 }
 
 static int pp_set_clockgating_state(void *handle,
@@ -334,12 +257,9 @@ static int pp_dpm_fw_loading_complete(void *handle)
 static int pp_set_clockgating_by_smu(void *handle, uint32_t msg_id)
 {
 	struct pp_hwmgr *hwmgr = handle;
-	int ret = 0;
-
-	ret = pp_check(hwmgr);
 
-	if (ret)
-		return ret;
+	if (!hwmgr || !hwmgr->pm_en)
+		return -EINVAL;
 
 	if (hwmgr->hwmgr_func->update_clock_gatings == NULL) {
 		pr_info("%s was not implemented.\n", __func__);
@@ -389,12 +309,9 @@ static int pp_dpm_force_performance_level(void *handle,
 					enum amd_dpm_forced_level level)
 {
 	struct pp_hwmgr *hwmgr = handle;
-	int ret = 0;
 
-	ret = pp_check(hwmgr);
-
-	if (ret)
-		return ret;
+	if (!hwmgr || !hwmgr->pm_en)
+		return -EINVAL;
 
 	if (level == hwmgr->dpm_level)
 		return 0;
@@ -412,13 +329,10 @@ static enum amd_dpm_forced_level pp_dpm_get_performance_level(
 								void *handle)
 {
 	struct pp_hwmgr *hwmgr = handle;
-	int ret = 0;
 	enum amd_dpm_forced_level level;
 
-	ret = pp_check(hwmgr);
-
-	if (ret)
-		return ret;
+	if (!hwmgr || !hwmgr->pm_en)
+		return -EINVAL;
 
 	mutex_lock(&hwmgr->smu_lock);
 	level = hwmgr->dpm_level;
@@ -429,13 +343,10 @@ static enum amd_dpm_forced_level pp_dpm_get_performance_level(
 static uint32_t pp_dpm_get_sclk(void *handle, bool low)
 {
 	struct pp_hwmgr *hwmgr = handle;
-	int ret = 0;
 	uint32_t clk = 0;
 
-	ret = pp_check(hwmgr);
-
-	if (ret)
-		return ret;
+	if (!hwmgr || !hwmgr->pm_en)
+		return 0;
 
 	if (hwmgr->hwmgr_func->get_sclk == NULL) {
 		pr_info("%s was not implemented.\n", __func__);
@@ -450,13 +361,10 @@ static uint32_t pp_dpm_get_sclk(void *handle, bool low)
 static uint32_t pp_dpm_get_mclk(void *handle, bool low)
 {
 	struct pp_hwmgr *hwmgr = handle;
-	int ret = 0;
 	uint32_t clk = 0;
 
-	ret = pp_check(hwmgr);
-
-	if (ret)
-		return ret;
+	if (!hwmgr || !hwmgr->pm_en)
+		return 0;
 
 	if (hwmgr->hwmgr_func->get_mclk == NULL) {
 		pr_info("%s was not implemented.\n", __func__);
@@ -471,11 +379,8 @@ static uint32_t pp_dpm_get_mclk(void *handle, bool low)
 static void pp_dpm_powergate_vce(void *handle, bool gate)
 {
 	struct pp_hwmgr *hwmgr = handle;
-	int ret = 0;
-
-	ret = pp_check(hwmgr);
 
-	if (ret)
+	if (!hwmgr || !hwmgr->pm_en)
 		return;
 
 	if (hwmgr->hwmgr_func->powergate_vce == NULL) {
@@ -490,11 +395,8 @@ static void pp_dpm_powergate_vce(void *handle, bool gate)
 static void pp_dpm_powergate_uvd(void *handle, bool gate)
 {
 	struct pp_hwmgr *hwmgr = handle;
-	int ret = 0;
-
-	ret = pp_check(hwmgr);
 
-	if (ret)
+	if (!hwmgr || !hwmgr->pm_en)
 		return;
 
 	if (hwmgr->hwmgr_func->powergate_uvd == NULL) {
@@ -512,10 +414,8 @@ static int pp_dpm_dispatch_tasks(void *handle, enum amd_pp_task task_id,
 	int ret = 0;
 	struct pp_hwmgr *hwmgr = handle;
 
-	ret = pp_check(hwmgr);
-
-	if (ret)
-		return ret;
+	if (!hwmgr || !hwmgr->pm_en)
+		return -EINVAL;
 
 	mutex_lock(&hwmgr->smu_lock);
 	ret = hwmgr_handle_task(hwmgr, task_id, user_state);
@@ -528,15 +428,9 @@ static enum amd_pm_state_type pp_dpm_get_current_power_state(void *handle)
 {
 	struct pp_hwmgr *hwmgr = handle;
 	struct pp_power_state *state;
-	int ret = 0;
 	enum amd_pm_state_type pm_type;
 
-	ret = pp_check(hwmgr);
-
-	if (ret)
-		return ret;
-
-	if (hwmgr->current_ps == NULL)
+	if (!hwmgr || !hwmgr->pm_en || !hwmgr->current_ps)
 		return -EINVAL;
 
 	mutex_lock(&hwmgr->smu_lock);
@@ -568,11 +462,8 @@ static enum amd_pm_state_type pp_dpm_get_current_power_state(void *handle)
 static void pp_dpm_set_fan_control_mode(void *handle, uint32_t mode)
 {
 	struct pp_hwmgr *hwmgr = handle;
-	int ret = 0;
-
-	ret = pp_check(hwmgr);
 
-	if (ret)
+	if (!hwmgr || !hwmgr->pm_en)
 		return;
 
 	if (hwmgr->hwmgr_func->set_fan_control_mode == NULL) {
@@ -587,13 +478,10 @@ static void pp_dpm_set_fan_control_mode(void *handle, uint32_t mode)
 static uint32_t pp_dpm_get_fan_control_mode(void *handle)
 {
 	struct pp_hwmgr *hwmgr = handle;
-	int ret = 0;
 	uint32_t mode = 0;
 
-	ret = pp_check(hwmgr);
-
-	if (ret)
-		return ret;
+	if (!hwmgr || !hwmgr->pm_en)
+		return 0;
 
 	if (hwmgr->hwmgr_func->get_fan_control_mode == NULL) {
 		pr_info("%s was not implemented.\n", __func__);
@@ -610,10 +498,8 @@ static int pp_dpm_set_fan_speed_percent(void *handle, uint32_t percent)
 	struct pp_hwmgr *hwmgr = handle;
 	int ret = 0;
 
-	ret = pp_check(hwmgr);
-
-	if (ret)
-		return ret;
+	if (!hwmgr || !hwmgr->pm_en)
+		return -EINVAL;
 
 	if (hwmgr->hwmgr_func->set_fan_speed_percent == NULL) {
 		pr_info("%s was not implemented.\n", __func__);
@@ -630,10 +516,8 @@ static int pp_dpm_get_fan_speed_percent(void *handle, uint32_t *speed)
 	struct pp_hwmgr *hwmgr = handle;
 	int ret = 0;
 
-	ret = pp_check(hwmgr);
-
-	if (ret)
-		return ret;
+	if (!hwmgr || !hwmgr->pm_en)
+		return -EINVAL;
 
 	if (hwmgr->hwmgr_func->get_fan_speed_percent == NULL) {
 		pr_info("%s was not implemented.\n", __func__);
@@ -651,10 +535,8 @@ static int pp_dpm_get_fan_speed_rpm(void *handle, uint32_t *rpm)
 	struct pp_hwmgr *hwmgr = handle;
 	int ret = 0;
 
-	ret = pp_check(hwmgr);
-
-	if (ret)
-		return ret;
+	if (!hwmgr || !hwmgr->pm_en)
+		return -EINVAL;
 
 	if (hwmgr->hwmgr_func->get_fan_speed_rpm == NULL)
 		return -EINVAL;
@@ -670,16 +552,10 @@ static int pp_dpm_get_pp_num_states(void *handle,
 {
 	struct pp_hwmgr *hwmgr = handle;
 	int i;
-	int ret = 0;
 
 	memset(data, 0, sizeof(*data));
 
-	ret = pp_check(hwmgr);
-
-	if (ret)
-		return ret;
-
-	if (hwmgr->ps == NULL)
+	if (!hwmgr || !hwmgr->pm_en ||!hwmgr->ps)
 		return -EINVAL;
 
 	mutex_lock(&hwmgr->smu_lock);
@@ -713,15 +589,9 @@ static int pp_dpm_get_pp_num_states(void *handle,
 static int pp_dpm_get_pp_table(void *handle, char **table)
 {
 	struct pp_hwmgr *hwmgr = handle;
-	int ret = 0;
 	int size = 0;
 
-	ret = pp_check(hwmgr);
-
-	if (ret)
-		return ret;
-
-	if (!hwmgr->soft_pp_table)
+	if (!hwmgr || !hwmgr->pm_en ||!hwmgr->soft_pp_table)
 		return -EINVAL;
 
 	mutex_lock(&hwmgr->smu_lock);
@@ -736,10 +606,6 @@ static int amd_powerplay_reset(void *handle)
 	struct pp_hwmgr *hwmgr = handle;
 	int ret;
 
-	ret = pp_check(hwmgr);
-	if (ret)
-		return ret;
-
 	ret = hwmgr_hw_fini(hwmgr);
 	if (ret)
 		return ret;
@@ -756,10 +622,8 @@ static int pp_dpm_set_pp_table(void *handle, const char *buf, size_t size)
 	struct pp_hwmgr *hwmgr = handle;
 	int ret = 0;
 
-	ret = pp_check(hwmgr);
-
-	if (ret)
-		return ret;
+	if (!hwmgr || !hwmgr->pm_en)
+		return -EINVAL;
 
 	mutex_lock(&hwmgr->smu_lock);
 	if (!hwmgr->hardcode_pp_table) {
@@ -796,10 +660,8 @@ static int pp_dpm_force_clock_level(void *handle,
 	struct pp_hwmgr *hwmgr = handle;
 	int ret = 0;
 
-	ret = pp_check(hwmgr);
-
-	if (ret)
-		return ret;
+	if (!hwmgr || !hwmgr->pm_en)
+		return -EINVAL;
 
 	if (hwmgr->hwmgr_func->force_clock_level == NULL) {
 		pr_info("%s was not implemented.\n", __func__);
@@ -820,10 +682,8 @@ static int pp_dpm_print_clock_levels(void *handle,
 	struct pp_hwmgr *hwmgr = handle;
 	int ret = 0;
 
-	ret = pp_check(hwmgr);
-
-	if (ret)
-		return ret;
+	if (!hwmgr || !hwmgr->pm_en)
+		return -EINVAL;
 
 	if (hwmgr->hwmgr_func->print_clock_levels == NULL) {
 		pr_info("%s was not implemented.\n", __func__);
@@ -840,10 +700,8 @@ static int pp_dpm_get_sclk_od(void *handle)
 	struct pp_hwmgr *hwmgr = handle;
 	int ret = 0;
 
-	ret = pp_check(hwmgr);
-
-	if (ret)
-		return ret;
+	if (!hwmgr || !hwmgr->pm_en)
+		return -EINVAL;
 
 	if (hwmgr->hwmgr_func->get_sclk_od == NULL) {
 		pr_info("%s was not implemented.\n", __func__);
@@ -860,10 +718,8 @@ static int pp_dpm_set_sclk_od(void *handle, uint32_t value)
 	struct pp_hwmgr *hwmgr = handle;
 	int ret = 0;
 
-	ret = pp_check(hwmgr);
-
-	if (ret)
-		return ret;
+	if (!hwmgr || !hwmgr->pm_en)
+		return -EINVAL;
 
 	if (hwmgr->hwmgr_func->set_sclk_od == NULL) {
 		pr_info("%s was not implemented.\n", __func__);
@@ -881,10 +737,8 @@ static int pp_dpm_get_mclk_od(void *handle)
 	struct pp_hwmgr *hwmgr = handle;
 	int ret = 0;
 
-	ret = pp_check(hwmgr);
-
-	if (ret)
-		return ret;
+	if (!hwmgr || !hwmgr->pm_en)
+		return -EINVAL;
 
 	if (hwmgr->hwmgr_func->get_mclk_od == NULL) {
 		pr_info("%s was not implemented.\n", __func__);
@@ -901,10 +755,8 @@ static int pp_dpm_set_mclk_od(void *handle, uint32_t value)
 	struct pp_hwmgr *hwmgr = handle;
 	int ret = 0;
 
-	ret = pp_check(hwmgr);
-
-	if (ret)
-		return ret;
+	if (!hwmgr || !hwmgr->pm_en)
+		return -EINVAL;
 
 	if (hwmgr->hwmgr_func->set_mclk_od == NULL) {
 		pr_info("%s was not implemented.\n", __func__);
@@ -922,11 +774,7 @@ static int pp_dpm_read_sensor(void *handle, int idx,
 	struct pp_hwmgr *hwmgr = handle;
 	int ret = 0;
 
-	ret = pp_check(hwmgr);
-	if (ret)
-		return ret;
-
-	if (value == NULL)
+	if (!hwmgr || !hwmgr->pm_en || !value)
 		return -EINVAL;
 
 	switch (idx) {
@@ -948,14 +796,11 @@ static int pp_dpm_read_sensor(void *handle, int idx,
 pp_dpm_get_vce_clock_state(void *handle, unsigned idx)
 {
 	struct pp_hwmgr *hwmgr = handle;
-	int ret = 0;
-
-	ret = pp_check(hwmgr);
 
-	if (ret)
+	if (!hwmgr || !hwmgr->pm_en)
 		return NULL;
 
-	if (hwmgr && idx < hwmgr->num_vce_state_tables)
+	if (idx < hwmgr->num_vce_state_tables)
 		return &hwmgr->vce_states[idx];
 	return NULL;
 }
@@ -964,7 +809,7 @@ static int pp_get_power_profile_mode(void *handle, char *buf)
 {
 	struct pp_hwmgr *hwmgr = handle;
 
-	if (!buf || pp_check(hwmgr))
+	if (!hwmgr || !hwmgr->pm_en || !buf)
 		return -EINVAL;
 
 	if (hwmgr->hwmgr_func->get_power_profile_mode == NULL) {
@@ -980,12 +825,12 @@ static int pp_set_power_profile_mode(void *handle, long *input, uint32_t size)
 	struct pp_hwmgr *hwmgr = handle;
 	int ret = -EINVAL;
 
-	if (pp_check(hwmgr))
-		return -EINVAL;
+	if (!hwmgr || !hwmgr->pm_en)
+		return ret;
 
 	if (hwmgr->hwmgr_func->set_power_profile_mode == NULL) {
 		pr_info("%s was not implemented.\n", __func__);
-		return -EINVAL;
+		return ret;
 	}
 	mutex_lock(&hwmgr->smu_lock);
 	if (hwmgr->dpm_level == AMD_DPM_FORCED_LEVEL_MANUAL)
@@ -998,7 +843,7 @@ static int pp_odn_edit_dpm_table(void *handle, uint32_t type, long *input, uint3
 {
 	struct pp_hwmgr *hwmgr = handle;
 
-	if (pp_check(hwmgr))
+	if (!hwmgr || !hwmgr->pm_en)
 		return -EINVAL;
 
 	if (hwmgr->hwmgr_func->odn_edit_dpm_table == NULL) {
@@ -1016,7 +861,7 @@ static int pp_dpm_switch_power_profile(void *handle,
 	long workload;
 	uint32_t index;
 
-	if (pp_check(hwmgr))
+	if (!hwmgr || !hwmgr->pm_en)
 		return -EINVAL;
 
 	if (hwmgr->hwmgr_func->set_power_profile_mode == NULL) {
@@ -1058,10 +903,8 @@ static int pp_dpm_notify_smu_memory_info(void *handle,
 	struct pp_hwmgr *hwmgr = handle;
 	int ret = 0;
 
-	ret = pp_check(hwmgr);
-
-	if (ret)
-		return ret;
+	if (!hwmgr || !hwmgr->pm_en)
+		return -EINVAL;
 
 	if (hwmgr->hwmgr_func->notify_cac_buffer_info == NULL) {
 		pr_info("%s was not implemented.\n", __func__);
@@ -1082,12 +925,9 @@ static int pp_dpm_notify_smu_memory_info(void *handle,
 static int pp_set_power_limit(void *handle, uint32_t limit)
 {
 	struct pp_hwmgr *hwmgr = handle;
-	int ret = 0;
-
-	ret = pp_check(hwmgr);
 
-	if (ret)
-		return ret;
+	if (!hwmgr || !hwmgr->pm_en)
+		return -EINVAL;
 
 	if (hwmgr->hwmgr_func->set_power_limit == NULL) {
 		pr_info("%s was not implemented.\n", __func__);
@@ -1104,20 +944,14 @@ static int pp_set_power_limit(void *handle, uint32_t limit)
 	hwmgr->hwmgr_func->set_power_limit(hwmgr, limit);
 	hwmgr->power_limit = limit;
 	mutex_unlock(&hwmgr->smu_lock);
-	return ret;
+	return 0;
 }
 
 static int pp_get_power_limit(void *handle, uint32_t *limit, bool default_limit)
 {
 	struct pp_hwmgr *hwmgr = handle;
-	int ret = 0;
-
-	ret = pp_check(hwmgr);
 
-	if (ret)
-		return ret;
-
-	if (limit == NULL)
+	if (!hwmgr || !hwmgr->pm_en ||!limit)
 		return -EINVAL;
 
 	mutex_lock(&hwmgr->smu_lock);
@@ -1129,19 +963,16 @@ static int pp_get_power_limit(void *handle, uint32_t *limit, bool default_limit)
 
 	mutex_unlock(&hwmgr->smu_lock);
 
-	return ret;
+	return 0;
 }
 
 static int pp_display_configuration_change(void *handle,
 	const struct amd_pp_display_configuration *display_config)
 {
 	struct pp_hwmgr *hwmgr = handle;
-	int ret = 0;
-
-	ret = pp_check(hwmgr);
 
-	if (ret)
-		return ret;
+	if (!hwmgr || !hwmgr->pm_en)
+		return -EINVAL;
 
 	mutex_lock(&hwmgr->smu_lock);
 	phm_store_dal_configuration_data(hwmgr, display_config);
@@ -1155,12 +986,7 @@ static int pp_get_display_power_level(void *handle,
 	struct pp_hwmgr *hwmgr = handle;
 	int ret = 0;
 
-	ret = pp_check(hwmgr);
-
-	if (ret)
-		return ret;
-
-	if (output == NULL)
+	if (!hwmgr || !hwmgr->pm_en ||!output)
 		return -EINVAL;
 
 	mutex_lock(&hwmgr->smu_lock);
@@ -1177,10 +1003,8 @@ static int pp_get_current_clocks(void *handle,
 	struct pp_hwmgr *hwmgr = handle;
 	int ret = 0;
 
-	ret = pp_check(hwmgr);
-
-	if (ret)
-		return ret;
+	if (!hwmgr || !hwmgr->pm_en)
+		return -EINVAL;
 
 	mutex_lock(&hwmgr->smu_lock);
 
@@ -1225,10 +1049,8 @@ static int pp_get_clock_by_type(void *handle, enum amd_pp_clock_type type, struc
 	struct pp_hwmgr *hwmgr = handle;
 	int ret = 0;
 
-	ret = pp_check(hwmgr);
-
-	if (ret)
-		return ret;
+	if (!hwmgr || !hwmgr->pm_en)
+		return -EINVAL;
 
 	if (clocks == NULL)
 		return -EINVAL;
@@ -1246,11 +1068,7 @@ static int pp_get_clock_by_type_with_latency(void *handle,
 	struct pp_hwmgr *hwmgr = handle;
 	int ret = 0;
 
-	ret = pp_check(hwmgr);
-	if (ret)
-		return ret;
-
-	if (!clocks)
+	if (!hwmgr || !hwmgr->pm_en ||!clocks)
 		return -EINVAL;
 
 	mutex_lock(&hwmgr->smu_lock);
@@ -1266,11 +1084,7 @@ static int pp_get_clock_by_type_with_voltage(void *handle,
 	struct pp_hwmgr *hwmgr = handle;
 	int ret = 0;
 
-	ret = pp_check(hwmgr);
-	if (ret)
-		return ret;
-
-	if (!clocks)
+	if (!hwmgr || !hwmgr->pm_en ||!clocks)
 		return -EINVAL;
 
 	mutex_lock(&hwmgr->smu_lock);
@@ -1287,11 +1101,7 @@ static int pp_set_watermarks_for_clocks_ranges(void *handle,
 	struct pp_hwmgr *hwmgr = handle;
 	int ret = 0;
 
-	ret = pp_check(hwmgr);
-	if (ret)
-		return ret;
-
-	if (!wm_with_clock_ranges)
+	if (!hwmgr || !hwmgr->pm_en ||!wm_with_clock_ranges)
 		return -EINVAL;
 
 	mutex_lock(&hwmgr->smu_lock);
@@ -1308,11 +1118,7 @@ static int pp_display_clock_voltage_request(void *handle,
 	struct pp_hwmgr *hwmgr = handle;
 	int ret = 0;
 
-	ret = pp_check(hwmgr);
-	if (ret)
-		return ret;
-
-	if (!clock)
+	if (!hwmgr || !hwmgr->pm_en ||!clock)
 		return -EINVAL;
 
 	mutex_lock(&hwmgr->smu_lock);
@@ -1328,12 +1134,7 @@ static int pp_get_display_mode_validation_clocks(void *handle,
 	struct pp_hwmgr *hwmgr = handle;
 	int ret = 0;
 
-	ret = pp_check(hwmgr);
-
-	if (ret)
-		return ret;
-
-	if (clocks == NULL)
+	if (!hwmgr || !hwmgr->pm_en ||!clocks)
 		return -EINVAL;
 
 	mutex_lock(&hwmgr->smu_lock);
@@ -1348,12 +1149,9 @@ static int pp_get_display_mode_validation_clocks(void *handle,
 static int pp_set_mmhub_powergating_by_smu(void *handle)
 {
 	struct pp_hwmgr *hwmgr = handle;
-	int ret = 0;
-
-	ret = pp_check(hwmgr);
 
-	if (ret)
-		return ret;
+	if (!hwmgr || !hwmgr->pm_en)
+		return -EINVAL;
 
 	if (hwmgr->hwmgr_func->set_mmhub_powergating_by_smu == NULL) {
 		pr_info("%s was not implemented.\n", __func__);
drivers/gpu/drm/amd/powerplay/hwmgr/hwmgr.c +57 -17

129 lines not on this page · raw message

drivers/gpu/drm/amd/powerplay/inc/hwmgr.h +5 -2
index 17f811d..d6c9a3b 100644
@@ -782,10 +782,13 @@ struct pp_hwmgr {
 };
 
 int hwmgr_early_init(struct pp_hwmgr *hwmgr);
+int hwmgr_sw_init(struct pp_hwmgr *hwmgr);
+int hwmgr_sw_fini(struct pp_hwmgr *hwmgr);
 int hwmgr_hw_init(struct pp_hwmgr *hwmgr);
 int hwmgr_hw_fini(struct pp_hwmgr *hwmgr);
-int hwmgr_hw_suspend(struct pp_hwmgr *hwmgr);
-int hwmgr_hw_resume(struct pp_hwmgr *hwmgr);
+int hwmgr_suspend(struct pp_hwmgr *hwmgr);
+int hwmgr_resume(struct pp_hwmgr *hwmgr);
+
 int hwmgr_handle_task(struct pp_hwmgr *hwmgr,
 				enum amd_pp_task task_id,
 				enum amd_pm_state_type *user_state);
Signature · 6 lines
1.9.1

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
author
#13 lore raw

PATCH 3/6 drm/amd/pp: Lock powerplay when reset pp table

In reply to a message not in the archive
Change-Id Ib02cd71593bee9606822a466a56f2d01ac2e04cc
---
 drivers/gpu/drm/amd/powerplay/amd_powerplay.c | 28 +++++++++++++--------------
 1 file changed, 14 insertions(+), 14 deletions(-)
drivers/gpu/drm/amd/powerplay/amd_powerplay.c +14 -14
index 5d7d9ec..1ae4905 100644
@@ -31,8 +31,6 @@
 #include "amdgpu.h"
 #include "hwmgr.h"
 
-static int pp_dpm_dispatch_tasks(void *handle, enum amd_pp_task task_id,
-		enum amd_pm_state_type *user_state);
 
 static const struct amd_pm_funcs pp_dpm_funcs;
 
@@ -146,10 +144,12 @@ static int pp_late_init(void *handle)
 	struct amdgpu_device *adev = handle;
 	struct pp_hwmgr *hwmgr = adev->powerplay.pp_handle;
 
-	if (hwmgr && hwmgr->pm_en)
-		pp_dpm_dispatch_tasks(hwmgr,
+	if (hwmgr && hwmgr->pm_en) {
+		mutex_lock(&hwmgr->smu_lock);
+		hwmgr_handle_task(hwmgr,
 					AMD_PP_TASK_COMPLETE_INIT, NULL);
-
+		mutex_unlock(&hwmgr->smu_lock);
+	}
 	return 0;
 }
 
@@ -620,7 +620,7 @@ static int amd_powerplay_reset(void *handle)
 static int pp_dpm_set_pp_table(void *handle, const char *buf, size_t size)
 {
 	struct pp_hwmgr *hwmgr = handle;
-	int ret = 0;
+	int ret = -ENOMEM;
 
 	if (!hwmgr || !hwmgr->pm_en)
 		return -EINVAL;
@@ -630,28 +630,28 @@ static int pp_dpm_set_pp_table(void *handle, const char *buf, size_t size)
 		hwmgr->hardcode_pp_table = kmemdup(hwmgr->soft_pp_table,
 						   hwmgr->soft_pp_table_size,
 						   GFP_KERNEL);
-		if (!hwmgr->hardcode_pp_table) {
-			mutex_unlock(&hwmgr->smu_lock);
-			return -ENOMEM;
-		}
+		if (!hwmgr->hardcode_pp_table)
+			goto err;
 	}
 
 	memcpy(hwmgr->hardcode_pp_table, buf, size);
 
 	hwmgr->soft_pp_table = hwmgr->hardcode_pp_table;
-	mutex_unlock(&hwmgr->smu_lock);
 
 	ret = amd_powerplay_reset(handle);
 	if (ret)
-		return ret;
+		goto err;
 
 	if (hwmgr->hwmgr_func->avfs_control) {
 		ret = hwmgr->hwmgr_func->avfs_control(hwmgr, false);
 		if (ret)
-			return ret;
+			goto err;
 	}
-
+	mutex_unlock(&hwmgr->smu_lock);
 	return 0;
+err:
+	mutex_unlock(&hwmgr->smu_lock);
+	return ret;
 }
 
 static int pp_dpm_force_clock_level(void *handle,
Signature · 6 lines
1.9.1

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
author
#20 lore raw

PATCH 4/6 drm/amd/pp: Save vf state in pp context

In reply to a message not in the archive
Change-Id Ic77e961317113942023b25523df6a4399535fb06
---
 drivers/gpu/drm/amd/powerplay/amd_powerplay.c           |  3 ++-
 drivers/gpu/drm/amd/powerplay/inc/hwmgr.h               |  1 +
 drivers/gpu/drm/amd/powerplay/smumgr/fiji_smumgr.c      |  7 +++----
 drivers/gpu/drm/amd/powerplay/smumgr/polaris10_smumgr.c |  3 +--
 drivers/gpu/drm/amd/powerplay/smumgr/smu7_smumgr.c      | 10 +++++-----
 drivers/gpu/drm/amd/powerplay/smumgr/tonga_smumgr.c     |  3 +--
 6 files changed, 13 insertions(+), 14 deletions(-)
drivers/gpu/drm/amd/powerplay/amd_powerplay.c +2 -1
index 1ae4905..5717859 100644
@@ -46,7 +46,8 @@ static int amd_powerplay_create(struct amdgpu_device *adev)
 		return -ENOMEM;
 
 	hwmgr->adev = adev;
-	hwmgr->pm_en = (amdgpu_dpm != 0 && !amdgpu_sriov_vf(adev)) ? true : false;
+	hwmgr->not_vf = !amdgpu_sriov_vf(adev);
+	hwmgr->pm_en = (amdgpu_dpm && hwmgr->not_vf) ? true : false;
 	hwmgr->device = amdgpu_cgs_create_device(adev);
 	mutex_init(&hwmgr->smu_lock);
 	hwmgr->chip_family = adev->family;
drivers/gpu/drm/amd/powerplay/inc/hwmgr.h +1 -0
index d6c9a3b..d5cadc6 100644
@@ -718,6 +718,7 @@ struct pp_hwmgr {
 	uint32_t chip_family;
 	uint32_t chip_id;
 	uint32_t smu_version;
+	bool not_vf;
 	bool pm_en;
 	struct mutex smu_lock;
 
drivers/gpu/drm/amd/powerplay/smumgr/fiji_smumgr.c +3 -4
index faef783..35b947e 100644
@@ -288,8 +288,7 @@ static int fiji_start_smu(struct pp_hwmgr *hwmgr)
 	struct fiji_smumgr *priv = (struct fiji_smumgr *)(hwmgr->smu_backend);
 
 	/* Only start SMC if SMC RAM is not running */
-	if (!(smu7_is_smc_ram_running(hwmgr)
-		|| cgs_is_virtualization_enabled(hwmgr->device))) {
+	if (!smu7_is_smc_ram_running(hwmgr) && hwmgr->not_vf) {
 		/* Check if SMU is running in protected mode */
 		if (0 == PHM_READ_VFPF_INDIRECT_FIELD(hwmgr->device,
 				CGS_IND_REG__SMC,
@@ -335,8 +334,8 @@ static bool fiji_is_hw_avfs_present(struct pp_hwmgr *hwmgr)
 	uint32_t efuse = 0;
 	uint32_t mask = (1 << ((AVFS_EN_MSB - AVFS_EN_LSB) + 1)) - 1;
 
-	if (cgs_is_virtualization_enabled(hwmgr->device))
-		return 0;
+	if (!hwmgr->not_vf)
+		return false;
 
 	if (!atomctrl_read_efuse(hwmgr->device, AVFS_EN_LSB, AVFS_EN_MSB,
 			mask, &efuse)) {
drivers/gpu/drm/amd/powerplay/smumgr/polaris10_smumgr.c +1 -2
index 997a777..b861c26 100644
@@ -295,8 +295,7 @@ static int polaris10_start_smu(struct pp_hwmgr *hwmgr)
 	struct polaris10_smumgr *smu_data = (struct polaris10_smumgr *)(hwmgr->smu_backend);
 
 	/* Only start SMC if SMC RAM is not running */
-	if (!(smu7_is_smc_ram_running(hwmgr)
-		|| cgs_is_virtualization_enabled(hwmgr->device))) {
+	if (!smu7_is_smc_ram_running(hwmgr) && hwmgr->not_vf) {
 		smu_data->protected_mode = (uint8_t) (PHM_READ_VFPF_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC, SMU_FIRMWARE, SMU_MODE));
 		smu_data->smu7_data.security_hard_key = (uint8_t) (PHM_READ_VFPF_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC, SMU_FIRMWARE, SMU_SEL));
 
drivers/gpu/drm/amd/powerplay/smumgr/smu7_smumgr.c +5 -5
index 0399c10..3684822 100644
@@ -375,7 +375,7 @@ static int smu7_populate_single_firmware_entry(struct pp_hwmgr *hwmgr,
 		entry->meta_data_addr_low = 0;
 
 		/* digest need be excluded out */
-		if (cgs_is_virtualization_enabled(hwmgr->device))
+		if (!hwmgr->not_vf)
 			info.image_size -= 20;
 		entry->data_size_byte = info.image_size;
 		entry->num_register_entries = 0;
@@ -409,7 +409,7 @@ int smu7_request_smu_load_fw(struct pp_hwmgr *hwmgr)
 					0x0);
 
 	if (hwmgr->chip_id > CHIP_TOPAZ) { /* add support for Topaz */
-		if (!cgs_is_virtualization_enabled(hwmgr->device)) {
+		if (hwmgr->not_vf) {
 			smu7_send_msg_to_smc_with_parameter(hwmgr,
 						PPSMC_MSG_SMU_DRAM_ADDR_HI,
 						upper_32_bits(smu_data->smu_buffer.mc_addr));
@@ -467,7 +467,7 @@ int smu7_request_smu_load_fw(struct pp_hwmgr *hwmgr)
 	PP_ASSERT_WITH_CODE(0 == smu7_populate_single_firmware_entry(hwmgr,
 				UCODE_ID_SDMA1, &toc->entry[toc->num_entries++]),
 				"Failed to Get Firmware Entry.", return -EINVAL);
-	if (cgs_is_virtualization_enabled(hwmgr->device))
+	if (!hwmgr->not_vf)
 		PP_ASSERT_WITH_CODE(0 == smu7_populate_single_firmware_entry(hwmgr,
 				UCODE_ID_MEC_STORAGE, &toc->entry[toc->num_entries++]),
 				"Failed to Get Firmware Entry.", return -EINVAL);
@@ -608,7 +608,7 @@ int smu7_init(struct pp_hwmgr *hwmgr)
 	smu_data->header = smu_data->header_buffer.kaddr;
 	smu_data->header_buffer.mc_addr = mc_addr;
 
-	if (cgs_is_virtualization_enabled(hwmgr->device))
+	if (!hwmgr->not_vf)
 		return 0;
 
 	smu_data->smu_buffer.data_size = 200*4096;
@@ -643,7 +643,7 @@ int smu7_smu_fini(struct pp_hwmgr *hwmgr)
 					&smu_data->header_buffer.mc_addr,
 					&smu_data->header_buffer.kaddr);
 
-	if (!cgs_is_virtualization_enabled(hwmgr->device))
+	if (hwmgr->not_vf)
 		amdgpu_bo_free_kernel(&smu_data->smu_buffer.handle,
 					&smu_data->smu_buffer.mc_addr,
 					&smu_data->smu_buffer.kaddr);
drivers/gpu/drm/amd/powerplay/smumgr/tonga_smumgr.c +1 -2
index b51d746..2ba05d2 100644
@@ -199,8 +199,7 @@ static int tonga_start_smu(struct pp_hwmgr *hwmgr)
 	int result;
 
 	/* Only start SMC if SMC RAM is not running */
-	if (!(smu7_is_smc_ram_running(hwmgr) ||
-		cgs_is_virtualization_enabled(hwmgr->device))) {
+	if (!smu7_is_smc_ram_running(hwmgr) && hwmgr->not_vf) {
 		/*Check if SMU is running in protected mode*/
 		if (0 == PHM_READ_VFPF_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC,
 					SMU_FIRMWARE, SMU_MODE)) {
Signature · 6 lines
1.9.1

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
author
#23 lore raw

PATCH 5/6 drm/amd/pp: Use release_firmware function directly in powerplay

In reply to a message not in the archive
Change-Id I7e3c01d0d413bbada67c044b88f2e5f0a53f0b38
---
 drivers/gpu/drm/amd/powerplay/amd_powerplay.c           | 5 ++++-
 drivers/gpu/drm/amd/powerplay/inc/amd_powerplay.h       | 1 +
 drivers/gpu/drm/amd/powerplay/smumgr/ci_smumgr.c        | 1 -
 drivers/gpu/drm/amd/powerplay/smumgr/polaris10_smumgr.c | 3 ++-
 drivers/gpu/drm/amd/powerplay/smumgr/smu7_smumgr.c      | 1 -
 5 files changed, 7 insertions(+), 4 deletions(-)
drivers/gpu/drm/amd/powerplay/amd_powerplay.c +4 -1
index 5717859..315e25c 100644
@@ -107,8 +107,11 @@ static int pp_sw_fini(void *handle)
 
 	hwmgr_sw_fini(hwmgr);
 
-	if (adev->firmware.load_type == AMDGPU_FW_LOAD_SMU)
+	if (adev->firmware.load_type == AMDGPU_FW_LOAD_SMU) {
+		release_firmware(adev->pm.fw);
+		adev->pm.fw = NULL;
 		amdgpu_ucode_fini_bo(adev);
+	}
 
 	return 0;
 }
drivers/gpu/drm/amd/powerplay/inc/amd_powerplay.h +1 -0
index fe36659..c7d6533 100644
@@ -31,5 +31,6 @@
 #include "dm_pp_interface.h"
 #include "kgd_pp_interface.h"
 #include "amdgpu.h"
+#include <linux/firmware.h>
 
 #endif /* _AMD_POWERPLAY_H_ */
drivers/gpu/drm/amd/powerplay/smumgr/ci_smumgr.c +0 -1
index 08d0001..e30a2ee 100644
@@ -2784,7 +2784,6 @@ static int ci_smu_fini(struct pp_hwmgr *hwmgr)
 {
 	kfree(hwmgr->smu_backend);
 	hwmgr->smu_backend = NULL;
-	cgs_rel_firmware(hwmgr->device, CGS_UCODE_ID_SMU);
 	return 0;
 }
 
drivers/gpu/drm/amd/powerplay/smumgr/polaris10_smumgr.c +2 -1
index b861c26..3e80d61 100644
@@ -308,7 +308,8 @@ static int polaris10_start_smu(struct pp_hwmgr *hwmgr)
 			/* If failed, try with different security Key. */
 			if (result != 0) {
 				smu_data->smu7_data.security_hard_key ^= 1;
-				cgs_rel_firmware(hwmgr->device, CGS_UCODE_ID_SMU);
+				release_firmware(((struct amdgpu_device *)hwmgr->adev)->pm.fw);
+				((struct amdgpu_device *)hwmgr->adev)->pm.fw = NULL;
 				result = polaris10_start_smu_in_protection_mode(hwmgr);
 			}
 		}
drivers/gpu/drm/amd/powerplay/smumgr/smu7_smumgr.c +0 -1
index 3684822..41fab2d 100644
@@ -650,6 +650,5 @@ int smu7_smu_fini(struct pp_hwmgr *hwmgr)
 
 	kfree(hwmgr->smu_backend);
 	hwmgr->smu_backend = NULL;
-	cgs_rel_firmware(hwmgr->device, CGS_UCODE_ID_SMU);
 	return 0;
 }
Signature · 6 lines
1.9.1

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
author
#26 lore raw

PATCH 6/6 drm/amd/pp: Delete some cgs functions

In reply to a message not in the archive
Change-Id If90e946b915a30e14123f9892f12ddcf6c653095
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_cgs.c            | 30 ----------------------
 drivers/gpu/drm/amd/include/cgs_common.h           | 19 +-------------
 .../gpu/drm/amd/powerplay/hwmgr/hardwaremanager.c  | 14 ++--------
 drivers/gpu/drm/amd/powerplay/hwmgr/hwmgr.c        |  2 +-
 4 files changed, 4 insertions(+), 61 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_cgs.c +0 -30
index 71a57b2..1da6c17 100644
@@ -271,18 +271,6 @@ static uint32_t fw_type_convert(struct cgs_device *cgs_device, uint32_t fw_type)
 	return result;
 }
 
-static int amdgpu_cgs_rel_firmware(struct cgs_device *cgs_device, enum cgs_ucode_id type)
-{
-	CGS_FUNC_ADEV;
-	if ((CGS_UCODE_ID_SMU == type) || (CGS_UCODE_ID_SMU_SK == type)) {
-		release_firmware(adev->pm.fw);
-		adev->pm.fw = NULL;
-		return 0;
-	}
-	/* cannot release other firmware because they are not created by cgs */
-	return -EINVAL;
-}
-
 static uint16_t amdgpu_get_firmware_version(struct cgs_device *cgs_device,
 					enum cgs_ucode_id type)
 {
@@ -598,11 +586,6 @@ static int amdgpu_cgs_get_firmware_info(struct cgs_device *cgs_device,
 	return 0;
 }
 
-static int amdgpu_cgs_is_virtualization_enabled(void *cgs_device)
-{
-	CGS_FUNC_ADEV;
-	return amdgpu_sriov_vf(adev);
-}
 
 static int amdgpu_cgs_get_active_displays_info(struct cgs_device *cgs_device,
 					  struct cgs_display_info *info)
@@ -661,16 +644,6 @@ static int amdgpu_cgs_get_active_displays_info(struct cgs_device *cgs_device,
 	return 0;
 }
 
-
-static int amdgpu_cgs_notify_dpm_enabled(struct cgs_device *cgs_device, bool enabled)
-{
-	CGS_FUNC_ADEV;
-
-	adev->pm.dpm_enabled = enabled;
-
-	return 0;
-}
-
 static const struct cgs_ops amdgpu_cgs_ops = {
 	.read_register = amdgpu_cgs_read_register,
 	.write_register = amdgpu_cgs_write_register,
@@ -681,12 +654,9 @@ static int amdgpu_cgs_notify_dpm_enabled(struct cgs_device *cgs_device, bool ena
 	.atom_get_cmd_table_revs = amdgpu_cgs_atom_get_cmd_table_revs,
 	.atom_exec_cmd_table = amdgpu_cgs_atom_exec_cmd_table,
 	.get_firmware_info = amdgpu_cgs_get_firmware_info,
-	.rel_firmware = amdgpu_cgs_rel_firmware,
 	.set_powergating_state = amdgpu_cgs_set_powergating_state,
 	.set_clockgating_state = amdgpu_cgs_set_clockgating_state,
 	.get_active_displays_info = amdgpu_cgs_get_active_displays_info,
-	.notify_dpm_enabled = amdgpu_cgs_notify_dpm_enabled,
-	.is_virtualization_enabled = amdgpu_cgs_is_virtualization_enabled,
 	.enter_safe_mode = amdgpu_cgs_enter_safe_mode,
 	.lock_grbm_idx = amdgpu_cgs_lock_grbm_idx,
 };
drivers/gpu/drm/amd/include/cgs_common.h +1 -18
index f2814ae..69109a0e 100644
@@ -235,9 +235,6 @@ typedef int (*cgs_get_firmware_info)(struct cgs_device *cgs_device,
 				     enum cgs_ucode_id type,
 				     struct cgs_firmware_info *info);
 
-typedef int (*cgs_rel_firmware)(struct cgs_device *cgs_device,
-					 enum cgs_ucode_id type);
-
 typedef int(*cgs_set_powergating_state)(struct cgs_device *cgs_device,
 				  enum amd_ip_block_type block_type,
 				  enum amd_powergating_state state);
@@ -250,10 +247,6 @@ typedef int(*cgs_get_active_displays_info)(
 					struct cgs_device *cgs_device,
 					struct cgs_display_info *info);
 
-typedef int (*cgs_notify_dpm_enabled)(struct cgs_device *cgs_device, bool enabled);
-
-typedef int (*cgs_is_virtualization_enabled_t)(void *cgs_device);
-
 typedef int (*cgs_enter_safe_mode)(struct cgs_device *cgs_device, bool en);
 
 typedef void (*cgs_lock_grbm_idx)(struct cgs_device *cgs_device, bool lock);
@@ -272,15 +265,11 @@ struct cgs_ops {
 	cgs_atom_exec_cmd_table_t atom_exec_cmd_table;
 	/* Firmware Info */
 	cgs_get_firmware_info get_firmware_info;
-	cgs_rel_firmware rel_firmware;
 	/* cg pg interface*/
 	cgs_set_powergating_state set_powergating_state;
 	cgs_set_clockgating_state set_clockgating_state;
 	/* display manager */
 	cgs_get_active_displays_info get_active_displays_info;
-	/* notify dpm enabled */
-	cgs_notify_dpm_enabled notify_dpm_enabled;
-	cgs_is_virtualization_enabled_t is_virtualization_enabled;
 	cgs_enter_safe_mode enter_safe_mode;
 	cgs_lock_grbm_idx lock_grbm_idx;
 };
@@ -318,14 +307,11 @@ struct cgs_device
 
 #define cgs_get_firmware_info(dev, type, info)	\
 	CGS_CALL(get_firmware_info, dev, type, info)
-#define cgs_rel_firmware(dev, type)	\
-	CGS_CALL(rel_firmware, dev, type)
 #define cgs_set_powergating_state(dev, block_type, state)	\
 	CGS_CALL(set_powergating_state, dev, block_type, state)
 #define cgs_set_clockgating_state(dev, block_type, state)	\
 	CGS_CALL(set_clockgating_state, dev, block_type, state)
-#define cgs_notify_dpm_enabled(dev, enabled)	\
-	CGS_CALL(notify_dpm_enabled, dev, enabled)
+
 
 #define cgs_get_active_displays_info(dev, info)	\
 	CGS_CALL(get_active_displays_info, dev, info)
@@ -335,9 +321,6 @@ struct cgs_device
 	CGS_CALL(get_pci_resource, cgs_device, resource_type, size, offset, \
 	resource_base)
 
-#define cgs_is_virtualization_enabled(cgs_device) \
-		CGS_CALL(is_virtualization_enabled, cgs_device)
-
 #define cgs_enter_safe_mode(cgs_device, en) \
 		CGS_CALL(enter_safe_mode, cgs_device, en)
 
drivers/gpu/drm/amd/powerplay/hwmgr/hardwaremanager.c +2 -12
index ae2e933..dcceadb 100644
@@ -75,8 +75,7 @@ int phm_set_power_state(struct pp_hwmgr *hwmgr,
 
 int phm_enable_dynamic_state_management(struct pp_hwmgr *hwmgr)
 {
-	int ret = 1;
-	bool enabled;
+	int ret = -EINVAL;;
 	PHM_FUNC_CHECK(hwmgr);
 
 	if (smum_is_dpm_running(hwmgr)) {
@@ -87,17 +86,12 @@ int phm_enable_dynamic_state_management(struct pp_hwmgr *hwmgr)
 	if (NULL != hwmgr->hwmgr_func->dynamic_state_management_enable)
 		ret = hwmgr->hwmgr_func->dynamic_state_management_enable(hwmgr);
 
-	enabled = ret == 0;
-
-	cgs_notify_dpm_enabled(hwmgr->device, enabled);
-
 	return ret;
 }
 
 int phm_disable_dynamic_state_management(struct pp_hwmgr *hwmgr)
 {
-	int ret = -1;
-	bool enabled;
+	int ret = -EINVAL;
 
 	PHM_FUNC_CHECK(hwmgr);
 
@@ -109,10 +103,6 @@ int phm_disable_dynamic_state_management(struct pp_hwmgr *hwmgr)
 	if (hwmgr->hwmgr_func->dynamic_state_management_disable)
 		ret = hwmgr->hwmgr_func->dynamic_state_management_disable(hwmgr);
 
-	enabled = ret == 0 ? false : true;
-
-	cgs_notify_dpm_enabled(hwmgr->device, enabled);
-
 	return ret;
 }
 
drivers/gpu/drm/amd/powerplay/hwmgr/hwmgr.c +1 -1
index 96a2d01..30ff8a9 100644
@@ -211,7 +211,7 @@ int hwmgr_hw_init(struct pp_hwmgr *hwmgr)
 	    !hwmgr->pptable_func->pptable_init ||
 	    !hwmgr->hwmgr_func->backend_init) {
 		hwmgr->pm_en = false;
-		cgs_notify_dpm_enabled(hwmgr->device, false);
+		((struct amdgpu_device *)hwmgr->adev)->pm.dpm_enabled = false;
 		pr_info("dpm not supported \n");
 		return 0;
 	}
Signature · 6 lines
1.9.1

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
Reviewed-by
#29 lore raw
In reply to a message not in the archive
Quoted 2 lines · Rex Zhu
Change-Id I087bcdc56977a8434706362f4e05593c5e7c2522
Quoted 55 lines
---
 drivers/gpu/drm/amd/powerplay/hwmgr/smu_helper.h |  3 +++
 drivers/gpu/drm/amd/powerplay/inc/hwmgr.h        | 15 ++++++---------
 2 files changed, 9 insertions(+), 9 deletions(-)
drivers/gpu/drm/amd/powerplay/hwmgr/smu_helper.h +3 -0
index 6429dc2..d37d16e 100644
@@ -27,6 +27,9 @@
 struct pp_hwmgr;
 struct phm_ppt_v1_voltage_lookup_table;
 
+uint8_t convert_to_vid(uint16_t vddc);
+uint16_t convert_to_vddc(uint8_t vid);
+
 extern int phm_wait_for_register_unequal(struct pp_hwmgr *hwmgr,
                                        uint32_t index,
                                        uint32_t value, uint32_t mask);
drivers/gpu/drm/amd/powerplay/inc/hwmgr.h +6 -10
index d742d9d..17f811d 100644
@@ -39,9 +39,6 @@
 
 #define VOLTAGE_SCALE 4
 
-uint8_t convert_to_vid(uint16_t vddc);
-uint16_t convert_to_vddc(uint8_t vid);
-
 enum DISPLAY_GAP {
        DISPLAY_GAP_VBLANK_OR_WM = 0,   /* Wait for vblank or MCHG watermark. */
        DISPLAY_GAP_VBLANK       = 1,   /* Wait for vblank. */
@@ -784,12 +781,12 @@ struct pp_hwmgr {
        uint32_t workload_setting[Workload_Policy_Max];
 };
 
-extern int hwmgr_early_init(struct pp_hwmgr *hwmgr);
-extern int hwmgr_hw_init(struct pp_hwmgr *hwmgr);
-extern int hwmgr_hw_fini(struct pp_hwmgr *hwmgr);
-extern int hwmgr_hw_suspend(struct pp_hwmgr *hwmgr);
-extern int hwmgr_hw_resume(struct pp_hwmgr *hwmgr);
-extern int hwmgr_handle_task(struct pp_hwmgr *hwmgr,
+int hwmgr_early_init(struct pp_hwmgr *hwmgr);
+int hwmgr_hw_init(struct pp_hwmgr *hwmgr);
+int hwmgr_hw_fini(struct pp_hwmgr *hwmgr);
+int hwmgr_hw_suspend(struct pp_hwmgr *hwmgr);
+int hwmgr_hw_resume(struct pp_hwmgr *hwmgr);
+int hwmgr_handle_task(struct pp_hwmgr *hwmgr,
                                enum amd_pp_task task_id,
                                enum amd_pm_state_type *user_state);
 
--

1.9.1

Quoted 4 lines

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

Reviewed-by
#4 lore raw

Re: [PATCH 2/6] drm/amd/pp: Add hwmgr_sw_init/fini functioins

In reply to a message not in the archive
Quoted 4 lines · Rex Zhu

Clean up pp ip functions

Change-Id Id06159202edabdfcb19fcc20e1291ce93db56d5d
Quoted 972 lines
---
 drivers/gpu/drm/amd/powerplay/amd_powerplay.c | 368 ++++++--------------------
 drivers/gpu/drm/amd/powerplay/hwmgr/hwmgr.c   |  74 ++++--
 drivers/gpu/drm/amd/powerplay/inc/hwmgr.h     |   7 +-
 3 files changed, 145 insertions(+), 304 deletions(-)
drivers/gpu/drm/amd/powerplay/amd_powerplay.c +83 -285
index 7e8ad30..5d7d9ec 100644
@@ -31,24 +31,11 @@
 #include "amdgpu.h"
 #include "hwmgr.h"
 
-#define PP_DPM_DISABLED 0xCCCC
-
 static int pp_dpm_dispatch_tasks(void *handle, enum amd_pp_task task_id,
                enum amd_pm_state_type *user_state);
 
 static const struct amd_pm_funcs pp_dpm_funcs;
 
-static inline int pp_check(struct pp_hwmgr *hwmgr)
-{
-       if (hwmgr == NULL || hwmgr->smumgr_funcs == NULL)
-               return -EINVAL;
-
-       if (hwmgr->pm_en == 0 || hwmgr->hwmgr_func == NULL)
-               return PP_DPM_DISABLED;
-
-       return 0;
-}
-
 static int amd_powerplay_create(struct amdgpu_device *adev)
 {
        struct pp_hwmgr *hwmgr;
@@ -73,7 +60,7 @@ static int amd_powerplay_create(struct amdgpu_device *adev)
 }
 
 
-static int amd_powerplay_destroy(struct amdgpu_device *adev)
+static void amd_powerplay_destroy(struct amdgpu_device *adev)
 {
        struct pp_hwmgr *hwmgr = adev->powerplay.pp_handle;
 
@@ -82,8 +69,6 @@ static int amd_powerplay_destroy(struct amdgpu_device *adev)
 
        kfree(hwmgr);
        hwmgr = NULL;
-
-       return 0;
 }
 
 static int pp_early_init(void *handle)
@@ -109,18 +94,9 @@ static int pp_sw_init(void *handle)
        struct pp_hwmgr *hwmgr = adev->powerplay.pp_handle;
        int ret = 0;
 
-       ret = pp_check(hwmgr);
-
-       if (ret >= 0) {
-               if (hwmgr->smumgr_funcs->smu_init == NULL)
-                       return -EINVAL;
+       ret = hwmgr_sw_init(hwmgr);
 
-               ret = hwmgr->smumgr_funcs->smu_init(hwmgr);
-
-               phm_register_irq_handlers(hwmgr);
-
-               pr_debug("amdgpu: powerplay sw initialized\n");
-       }
+       pr_debug("amdgpu: powerplay sw init %s\n", ret ? "failed" : "successfully");
 
        return ret;
 }
@@ -129,13 +105,8 @@ static int pp_sw_fini(void *handle)
 {
        struct amdgpu_device *adev = handle;
        struct pp_hwmgr *hwmgr = adev->powerplay.pp_handle;
-       int ret = 0;
 
-       ret = pp_check(hwmgr);
-       if (ret >= 0) {
-               if (hwmgr->smumgr_funcs->smu_fini != NULL)
-                       hwmgr->smumgr_funcs->smu_fini(hwmgr);
-       }
+       hwmgr_sw_fini(hwmgr);
 
        if (adev->firmware.load_type == AMDGPU_FW_LOAD_SMU)
                amdgpu_ucode_fini_bo(adev);
@@ -152,40 +123,20 @@ static int pp_hw_init(void *handle)
        if (adev->firmware.load_type == AMDGPU_FW_LOAD_SMU)
                amdgpu_ucode_init_bo(adev);
 
-       ret = pp_check(hwmgr);
+       ret = hwmgr_hw_init(hwmgr);
 
-       if (ret >= 0) {
-               if (hwmgr->smumgr_funcs->start_smu == NULL)
-                       return -EINVAL;
+       if (ret)
+               pr_err("amdgpu: powerplay hw init failed\n");
 
-               if (hwmgr->smumgr_funcs->start_smu(hwmgr)) {
-                       pr_err("smc start failed\n");
-                       hwmgr->smumgr_funcs->smu_fini(hwmgr);
-                       return -EINVAL;
-               }
-               if (ret == PP_DPM_DISABLED)
-                       goto exit;
-               ret = hwmgr_hw_init(hwmgr);
-               if (ret)
-                       goto exit;
-       }
        return ret;
-exit:
-       hwmgr->pm_en = 0;
-       cgs_notify_dpm_enabled(hwmgr->device, false);
-       return 0;
-
 }
 
 static int pp_hw_fini(void *handle)
 {
        struct amdgpu_device *adev = handle;
        struct pp_hwmgr *hwmgr = adev->powerplay.pp_handle;
-       int ret = 0;
 
-       ret = pp_check(hwmgr);
-       if (ret == 0)
-               hwmgr_hw_fini(hwmgr);
+       hwmgr_hw_fini(hwmgr);
 
        return 0;
 }
@@ -194,11 +145,8 @@ static int pp_late_init(void *handle)
 {
        struct amdgpu_device *adev = handle;
        struct pp_hwmgr *hwmgr = adev->powerplay.pp_handle;
-       int ret = 0;
-
-       ret = pp_check(hwmgr);
 
-       if (ret == 0)
+       if (hwmgr && hwmgr->pm_en)
                pp_dpm_dispatch_tasks(hwmgr,
                                        AMD_PP_TASK_COMPLETE_INIT, NULL);
 
@@ -233,12 +181,9 @@ static int pp_set_powergating_state(void *handle,
 {
        struct amdgpu_device *adev = handle;
        struct pp_hwmgr *hwmgr = adev->powerplay.pp_handle;
-       int ret = 0;
 
-       ret = pp_check(hwmgr);
-
-       if (ret)
-               return ret;
+       if (!hwmgr || !hwmgr->pm_en)
+               return 0;
 
        if (hwmgr->hwmgr_func->enable_per_cu_power_gating == NULL) {
                pr_info("%s was not implemented.\n", __func__);
@@ -254,38 +199,16 @@ static int pp_suspend(void *handle)
 {
        struct amdgpu_device *adev = handle;
        struct pp_hwmgr *hwmgr = adev->powerplay.pp_handle;
-       int ret = 0;
 
-       ret = pp_check(hwmgr);
-       if (ret == 0)
-               hwmgr_hw_suspend(hwmgr);
-       return 0;
+       return hwmgr_suspend(hwmgr);
 }
 
 static int pp_resume(void *handle)
 {
        struct amdgpu_device *adev = handle;
        struct pp_hwmgr *hwmgr = adev->powerplay.pp_handle;
-       int ret;
-
-       ret = pp_check(hwmgr);
-
-       if (ret < 0)
-               return ret;
-
-       if (hwmgr->smumgr_funcs->start_smu == NULL)
-               return -EINVAL;
-
-       if (hwmgr->smumgr_funcs->start_smu(hwmgr)) {
-               pr_err("smc start failed\n");
-               hwmgr->smumgr_funcs->smu_fini(hwmgr);
-               return -EINVAL;
-       }
-
-       if (ret == PP_DPM_DISABLED)
-               return 0;
 
-       return hwmgr_hw_resume(hwmgr);
+       return hwmgr_resume(hwmgr);
 }
 
 static int pp_set_clockgating_state(void *handle,
@@ -334,12 +257,9 @@ static int pp_dpm_fw_loading_complete(void *handle)
 static int pp_set_clockgating_by_smu(void *handle, uint32_t msg_id)
 {
        struct pp_hwmgr *hwmgr = handle;
-       int ret = 0;
-
-       ret = pp_check(hwmgr);
 
-       if (ret)
-               return ret;
+       if (!hwmgr || !hwmgr->pm_en)
+               return -EINVAL;
 
        if (hwmgr->hwmgr_func->update_clock_gatings == NULL) {
                pr_info("%s was not implemented.\n", __func__);
@@ -389,12 +309,9 @@ static int pp_dpm_force_performance_level(void *handle,
                                        enum amd_dpm_forced_level level)
 {
        struct pp_hwmgr *hwmgr = handle;
-       int ret = 0;
 
-       ret = pp_check(hwmgr);
-
-       if (ret)
-               return ret;
+       if (!hwmgr || !hwmgr->pm_en)
+               return -EINVAL;
 
        if (level == hwmgr->dpm_level)
                return 0;
@@ -412,13 +329,10 @@ static enum amd_dpm_forced_level pp_dpm_get_performance_level(
                                                                void *handle)
 {
        struct pp_hwmgr *hwmgr = handle;
-       int ret = 0;
        enum amd_dpm_forced_level level;
 
-       ret = pp_check(hwmgr);
-
-       if (ret)
-               return ret;
+       if (!hwmgr || !hwmgr->pm_en)
+               return -EINVAL;
 
        mutex_lock(&hwmgr->smu_lock);
        level = hwmgr->dpm_level;
@@ -429,13 +343,10 @@ static enum amd_dpm_forced_level pp_dpm_get_performance_level(
 static uint32_t pp_dpm_get_sclk(void *handle, bool low)
 {
        struct pp_hwmgr *hwmgr = handle;
-       int ret = 0;
        uint32_t clk = 0;
 
-       ret = pp_check(hwmgr);
-
-       if (ret)
-               return ret;
+       if (!hwmgr || !hwmgr->pm_en)
+               return 0;
 
        if (hwmgr->hwmgr_func->get_sclk == NULL) {
                pr_info("%s was not implemented.\n", __func__);
@@ -450,13 +361,10 @@ static uint32_t pp_dpm_get_sclk(void *handle, bool low)
 static uint32_t pp_dpm_get_mclk(void *handle, bool low)
 {
        struct pp_hwmgr *hwmgr = handle;
-       int ret = 0;
        uint32_t clk = 0;
 
-       ret = pp_check(hwmgr);
-
-       if (ret)
-               return ret;
+       if (!hwmgr || !hwmgr->pm_en)
+               return 0;
 
        if (hwmgr->hwmgr_func->get_mclk == NULL) {
                pr_info("%s was not implemented.\n", __func__);
@@ -471,11 +379,8 @@ static uint32_t pp_dpm_get_mclk(void *handle, bool low)
 static void pp_dpm_powergate_vce(void *handle, bool gate)
 {
        struct pp_hwmgr *hwmgr = handle;
-       int ret = 0;
-
-       ret = pp_check(hwmgr);
 
-       if (ret)
+       if (!hwmgr || !hwmgr->pm_en)
                return;
 
        if (hwmgr->hwmgr_func->powergate_vce == NULL) {
@@ -490,11 +395,8 @@ static void pp_dpm_powergate_vce(void *handle, bool gate)
 static void pp_dpm_powergate_uvd(void *handle, bool gate)
 {
        struct pp_hwmgr *hwmgr = handle;
-       int ret = 0;
-
-       ret = pp_check(hwmgr);
 
-       if (ret)
+       if (!hwmgr || !hwmgr->pm_en)
                return;
 
        if (hwmgr->hwmgr_func->powergate_uvd == NULL) {
@@ -512,10 +414,8 @@ static int pp_dpm_dispatch_tasks(void *handle, enum amd_pp_task task_id,
        int ret = 0;
        struct pp_hwmgr *hwmgr = handle;
 
-       ret = pp_check(hwmgr);
-
-       if (ret)
-               return ret;
+       if (!hwmgr || !hwmgr->pm_en)
+               return -EINVAL;
 
        mutex_lock(&hwmgr->smu_lock);
        ret = hwmgr_handle_task(hwmgr, task_id, user_state);
@@ -528,15 +428,9 @@ static enum amd_pm_state_type pp_dpm_get_current_power_state(void *handle)
 {
        struct pp_hwmgr *hwmgr = handle;
        struct pp_power_state *state;
-       int ret = 0;
        enum amd_pm_state_type pm_type;
 
-       ret = pp_check(hwmgr);
-
-       if (ret)
-               return ret;
-
-       if (hwmgr->current_ps == NULL)
+       if (!hwmgr || !hwmgr->pm_en || !hwmgr->current_ps)
                return -EINVAL;
 
        mutex_lock(&hwmgr->smu_lock);
@@ -568,11 +462,8 @@ static enum amd_pm_state_type pp_dpm_get_current_power_state(void *handle)
 static void pp_dpm_set_fan_control_mode(void *handle, uint32_t mode)
 {
        struct pp_hwmgr *hwmgr = handle;
-       int ret = 0;
-
-       ret = pp_check(hwmgr);
 
-       if (ret)
+       if (!hwmgr || !hwmgr->pm_en)
                return;
 
        if (hwmgr->hwmgr_func->set_fan_control_mode == NULL) {
@@ -587,13 +478,10 @@ static void pp_dpm_set_fan_control_mode(void *handle, uint32_t mode)
 static uint32_t pp_dpm_get_fan_control_mode(void *handle)
 {
        struct pp_hwmgr *hwmgr = handle;
-       int ret = 0;
        uint32_t mode = 0;
 
-       ret = pp_check(hwmgr);
-
-       if (ret)
-               return ret;
+       if (!hwmgr || !hwmgr->pm_en)
+               return 0;
 
        if (hwmgr->hwmgr_func->get_fan_control_mode == NULL) {
                pr_info("%s was not implemented.\n", __func__);
@@ -610,10 +498,8 @@ static int pp_dpm_set_fan_speed_percent(void *handle, uint32_t percent)
        struct pp_hwmgr *hwmgr = handle;
        int ret = 0;
 
-       ret = pp_check(hwmgr);
-
-       if (ret)
-               return ret;
+       if (!hwmgr || !hwmgr->pm_en)
+               return -EINVAL;
 
        if (hwmgr->hwmgr_func->set_fan_speed_percent == NULL) {
                pr_info("%s was not implemented.\n", __func__);
@@ -630,10 +516,8 @@ static int pp_dpm_get_fan_speed_percent(void *handle, uint32_t *speed)
        struct pp_hwmgr *hwmgr = handle;
        int ret = 0;
 
-       ret = pp_check(hwmgr);
-
-       if (ret)
-               return ret;
+       if (!hwmgr || !hwmgr->pm_en)
+               return -EINVAL;
 
        if (hwmgr->hwmgr_func->get_fan_speed_percent == NULL) {
                pr_info("%s was not implemented.\n", __func__);
@@ -651,10 +535,8 @@ static int pp_dpm_get_fan_speed_rpm(void *handle, uint32_t *rpm)
        struct pp_hwmgr *hwmgr = handle;
        int ret = 0;
 
-       ret = pp_check(hwmgr);
-
-       if (ret)
-               return ret;
+       if (!hwmgr || !hwmgr->pm_en)
+               return -EINVAL;
 
        if (hwmgr->hwmgr_func->get_fan_speed_rpm == NULL)
                return -EINVAL;
@@ -670,16 +552,10 @@ static int pp_dpm_get_pp_num_states(void *handle,
 {
        struct pp_hwmgr *hwmgr = handle;
        int i;
-       int ret = 0;
 
        memset(data, 0, sizeof(*data));
 
-       ret = pp_check(hwmgr);
-
-       if (ret)
-               return ret;
-
-       if (hwmgr->ps == NULL)
+       if (!hwmgr || !hwmgr->pm_en ||!hwmgr->ps)
                return -EINVAL;
 
        mutex_lock(&hwmgr->smu_lock);
@@ -713,15 +589,9 @@ static int pp_dpm_get_pp_num_states(void *handle,
 static int pp_dpm_get_pp_table(void *handle, char **table)
 {
        struct pp_hwmgr *hwmgr = handle;
-       int ret = 0;
        int size = 0;
 
-       ret = pp_check(hwmgr);
-
-       if (ret)
-               return ret;
-
-       if (!hwmgr->soft_pp_table)
+       if (!hwmgr || !hwmgr->pm_en ||!hwmgr->soft_pp_table)
                return -EINVAL;
 
        mutex_lock(&hwmgr->smu_lock);
@@ -736,10 +606,6 @@ static int amd_powerplay_reset(void *handle)
        struct pp_hwmgr *hwmgr = handle;
        int ret;
 
-       ret = pp_check(hwmgr);
-       if (ret)
-               return ret;
-
        ret = hwmgr_hw_fini(hwmgr);
        if (ret)
                return ret;
@@ -756,10 +622,8 @@ static int pp_dpm_set_pp_table(void *handle, const char *buf, size_t size)
        struct pp_hwmgr *hwmgr = handle;
        int ret = 0;
 
-       ret = pp_check(hwmgr);
-
-       if (ret)
-               return ret;
+       if (!hwmgr || !hwmgr->pm_en)
+               return -EINVAL;
 
        mutex_lock(&hwmgr->smu_lock);
        if (!hwmgr->hardcode_pp_table) {
@@ -796,10 +660,8 @@ static int pp_dpm_force_clock_level(void *handle,
        struct pp_hwmgr *hwmgr = handle;
        int ret = 0;
 
-       ret = pp_check(hwmgr);
-
-       if (ret)
-               return ret;
+       if (!hwmgr || !hwmgr->pm_en)
+               return -EINVAL;
 
        if (hwmgr->hwmgr_func->force_clock_level == NULL) {
                pr_info("%s was not implemented.\n", __func__);
@@ -820,10 +682,8 @@ static int pp_dpm_print_clock_levels(void *handle,
        struct pp_hwmgr *hwmgr = handle;
        int ret = 0;
 
-       ret = pp_check(hwmgr);
-
-       if (ret)
-               return ret;
+       if (!hwmgr || !hwmgr->pm_en)
+               return -EINVAL;
 
        if (hwmgr->hwmgr_func->print_clock_levels == NULL) {
                pr_info("%s was not implemented.\n", __func__);
@@ -840,10 +700,8 @@ static int pp_dpm_get_sclk_od(void *handle)
        struct pp_hwmgr *hwmgr = handle;
        int ret = 0;
 
-       ret = pp_check(hwmgr);
-
-       if (ret)
-               return ret;
+       if (!hwmgr || !hwmgr->pm_en)
+               return -EINVAL;
 
        if (hwmgr->hwmgr_func->get_sclk_od == NULL) {
                pr_info("%s was not implemented.\n", __func__);
@@ -860,10 +718,8 @@ static int pp_dpm_set_sclk_od(void *handle, uint32_t value)
        struct pp_hwmgr *hwmgr = handle;
        int ret = 0;
 
-       ret = pp_check(hwmgr);
-
-       if (ret)
-               return ret;
+       if (!hwmgr || !hwmgr->pm_en)
+               return -EINVAL;
 
        if (hwmgr->hwmgr_func->set_sclk_od == NULL) {
                pr_info("%s was not implemented.\n", __func__);
@@ -881,10 +737,8 @@ static int pp_dpm_get_mclk_od(void *handle)
        struct pp_hwmgr *hwmgr = handle;
        int ret = 0;
 
-       ret = pp_check(hwmgr);
-
-       if (ret)
-               return ret;
+       if (!hwmgr || !hwmgr->pm_en)
+               return -EINVAL;
 
        if (hwmgr->hwmgr_func->get_mclk_od == NULL) {
                pr_info("%s was not implemented.\n", __func__);
@@ -901,10 +755,8 @@ static int pp_dpm_set_mclk_od(void *handle, uint32_t value)
        struct pp_hwmgr *hwmgr = handle;
        int ret = 0;
 
-       ret = pp_check(hwmgr);
-
-       if (ret)
-               return ret;
+       if (!hwmgr || !hwmgr->pm_en)
+               return -EINVAL;
 
        if (hwmgr->hwmgr_func->set_mclk_od == NULL) {
                pr_info("%s was not implemented.\n", __func__);
@@ -922,11 +774,7 @@ static int pp_dpm_read_sensor(void *handle, int idx,
        struct pp_hwmgr *hwmgr = handle;
        int ret = 0;
 
-       ret = pp_check(hwmgr);
-       if (ret)
-               return ret;
-
-       if (value == NULL)
+       if (!hwmgr || !hwmgr->pm_en || !value)
                return -EINVAL;
 
        switch (idx) {
@@ -948,14 +796,11 @@ static int pp_dpm_read_sensor(void *handle, int idx,
 pp_dpm_get_vce_clock_state(void *handle, unsigned idx)
 {
        struct pp_hwmgr *hwmgr = handle;
-       int ret = 0;
-
-       ret = pp_check(hwmgr);
 
-       if (ret)
+       if (!hwmgr || !hwmgr->pm_en)
                return NULL;
 
-       if (hwmgr && idx < hwmgr->num_vce_state_tables)
+       if (idx < hwmgr->num_vce_state_tables)
                return &hwmgr->vce_states[idx];
        return NULL;
 }
@@ -964,7 +809,7 @@ static int pp_get_power_profile_mode(void *handle, char *buf)
 {
        struct pp_hwmgr *hwmgr = handle;
 
-       if (!buf || pp_check(hwmgr))
+       if (!hwmgr || !hwmgr->pm_en || !buf)
                return -EINVAL;
 
        if (hwmgr->hwmgr_func->get_power_profile_mode == NULL) {
@@ -980,12 +825,12 @@ static int pp_set_power_profile_mode(void *handle, long *input, uint32_t size)
        struct pp_hwmgr *hwmgr = handle;
        int ret = -EINVAL;
 
-       if (pp_check(hwmgr))
-               return -EINVAL;
+       if (!hwmgr || !hwmgr->pm_en)
+               return ret;
 
        if (hwmgr->hwmgr_func->set_power_profile_mode == NULL) {
                pr_info("%s was not implemented.\n", __func__);
-               return -EINVAL;
+               return ret;
        }
        mutex_lock(&hwmgr->smu_lock);
        if (hwmgr->dpm_level == AMD_DPM_FORCED_LEVEL_MANUAL)
@@ -998,7 +843,7 @@ static int pp_odn_edit_dpm_table(void *handle, uint32_t type, long *input, uint3
 {
        struct pp_hwmgr *hwmgr = handle;
 
-       if (pp_check(hwmgr))
+       if (!hwmgr || !hwmgr->pm_en)
                return -EINVAL;
 
        if (hwmgr->hwmgr_func->odn_edit_dpm_table == NULL) {
@@ -1016,7 +861,7 @@ static int pp_dpm_switch_power_profile(void *handle,
        long workload;
        uint32_t index;
 
-       if (pp_check(hwmgr))
+       if (!hwmgr || !hwmgr->pm_en)
                return -EINVAL;
 
        if (hwmgr->hwmgr_func->set_power_profile_mode == NULL) {
@@ -1058,10 +903,8 @@ static int pp_dpm_notify_smu_memory_info(void *handle,
        struct pp_hwmgr *hwmgr = handle;
        int ret = 0;
 
-       ret = pp_check(hwmgr);
-
-       if (ret)
-               return ret;
+       if (!hwmgr || !hwmgr->pm_en)
+               return -EINVAL;
 
        if (hwmgr->hwmgr_func->notify_cac_buffer_info == NULL) {
                pr_info("%s was not implemented.\n", __func__);
@@ -1082,12 +925,9 @@ static int pp_dpm_notify_smu_memory_info(void *handle,
 static int pp_set_power_limit(void *handle, uint32_t limit)
 {
        struct pp_hwmgr *hwmgr = handle;
-       int ret = 0;
-
-       ret = pp_check(hwmgr);
 
-       if (ret)
-               return ret;
+       if (!hwmgr || !hwmgr->pm_en)
+               return -EINVAL;
 
        if (hwmgr->hwmgr_func->set_power_limit == NULL) {
                pr_info("%s was not implemented.\n", __func__);
@@ -1104,20 +944,14 @@ static int pp_set_power_limit(void *handle, uint32_t limit)
        hwmgr->hwmgr_func->set_power_limit(hwmgr, limit);
        hwmgr->power_limit = limit;
        mutex_unlock(&hwmgr->smu_lock);
-       return ret;
+       return 0;
 }
 
 static int pp_get_power_limit(void *handle, uint32_t *limit, bool default_limit)
 {
        struct pp_hwmgr *hwmgr = handle;
-       int ret = 0;
-
-       ret = pp_check(hwmgr);
 
-       if (ret)
-               return ret;
-
-       if (limit == NULL)
+       if (!hwmgr || !hwmgr->pm_en ||!limit)
                return -EINVAL;
 
        mutex_lock(&hwmgr->smu_lock);
@@ -1129,19 +963,16 @@ static int pp_get_power_limit(void *handle, uint32_t *limit, bool default_limit)
 
        mutex_unlock(&hwmgr->smu_lock);
 
-       return ret;
+       return 0;
 }
 
 static int pp_display_configuration_change(void *handle,
        const struct amd_pp_display_configuration *display_config)
 {
        struct pp_hwmgr *hwmgr = handle;
-       int ret = 0;
-
-       ret = pp_check(hwmgr);
 
-       if (ret)
-               return ret;
+       if (!hwmgr || !hwmgr->pm_en)
+               return -EINVAL;
 
        mutex_lock(&hwmgr->smu_lock);
        phm_store_dal_configuration_data(hwmgr, display_config);
@@ -1155,12 +986,7 @@ static int pp_get_display_power_level(void *handle,
        struct pp_hwmgr *hwmgr = handle;
        int ret = 0;
 
-       ret = pp_check(hwmgr);
-
-       if (ret)
-               return ret;
-
-       if (output == NULL)
+       if (!hwmgr || !hwmgr->pm_en ||!output)
                return -EINVAL;
 
        mutex_lock(&hwmgr->smu_lock);
@@ -1177,10 +1003,8 @@ static int pp_get_current_clocks(void *handle,
        struct pp_hwmgr *hwmgr = handle;
        int ret = 0;
 
-       ret = pp_check(hwmgr);
-
-       if (ret)
-               return ret;
+       if (!hwmgr || !hwmgr->pm_en)
+               return -EINVAL;
 
        mutex_lock(&hwmgr->smu_lock);
 
@@ -1225,10 +1049,8 @@ static int pp_get_clock_by_type(void *handle, enum amd_pp_clock_type type, struc
        struct pp_hwmgr *hwmgr = handle;
        int ret = 0;
 
-       ret = pp_check(hwmgr);
-
-       if (ret)
-               return ret;
+       if (!hwmgr || !hwmgr->pm_en)
+               return -EINVAL;
 
        if (clocks == NULL)
                return -EINVAL;
@@ -1246,11 +1068,7 @@ static int pp_get_clock_by_type_with_latency(void *handle,
        struct pp_hwmgr *hwmgr = handle;
        int ret = 0;
 
-       ret = pp_check(hwmgr);
-       if (ret)
-               return ret;
-
-       if (!clocks)
+       if (!hwmgr || !hwmgr->pm_en ||!clocks)
                return -EINVAL;
 
        mutex_lock(&hwmgr->smu_lock);
@@ -1266,11 +1084,7 @@ static int pp_get_clock_by_type_with_voltage(void *handle,
        struct pp_hwmgr *hwmgr = handle;
        int ret = 0;
 
-       ret = pp_check(hwmgr);
-       if (ret)
-               return ret;
-
-       if (!clocks)
+       if (!hwmgr || !hwmgr->pm_en ||!clocks)
                return -EINVAL;
 
        mutex_lock(&hwmgr->smu_lock);
@@ -1287,11 +1101,7 @@ static int pp_set_watermarks_for_clocks_ranges(void *handle,
        struct pp_hwmgr *hwmgr = handle;
        int ret = 0;
 
-       ret = pp_check(hwmgr);
-       if (ret)
-               return ret;
-
-       if (!wm_with_clock_ranges)
+       if (!hwmgr || !hwmgr->pm_en ||!wm_with_clock_ranges)
                return -EINVAL;
 
        mutex_lock(&hwmgr->smu_lock);
@@ -1308,11 +1118,7 @@ static int pp_display_clock_voltage_request(void *handle,
        struct pp_hwmgr *hwmgr = handle;
        int ret = 0;
 
-       ret = pp_check(hwmgr);
-       if (ret)
-               return ret;
-
-       if (!clock)
+       if (!hwmgr || !hwmgr->pm_en ||!clock)
                return -EINVAL;
 
        mutex_lock(&hwmgr->smu_lock);
@@ -1328,12 +1134,7 @@ static int pp_get_display_mode_validation_clocks(void *handle,
        struct pp_hwmgr *hwmgr = handle;
        int ret = 0;
 
-       ret = pp_check(hwmgr);
-
-       if (ret)
-               return ret;
-
-       if (clocks == NULL)
+       if (!hwmgr || !hwmgr->pm_en ||!clocks)
                return -EINVAL;
 
        mutex_lock(&hwmgr->smu_lock);
@@ -1348,12 +1149,9 @@ static int pp_get_display_mode_validation_clocks(void *handle,
 static int pp_set_mmhub_powergating_by_smu(void *handle)
 {
        struct pp_hwmgr *hwmgr = handle;
-       int ret = 0;
-
-       ret = pp_check(hwmgr);
 
-       if (ret)
-               return ret;
+       if (!hwmgr || !hwmgr->pm_en)
+               return -EINVAL;
 
        if (hwmgr->hwmgr_func->set_mmhub_powergating_by_smu == NULL) {
                pr_info("%s was not implemented.\n", __func__);
drivers/gpu/drm/amd/powerplay/hwmgr/hwmgr.c +57 -17
index 4298205..96a2d01 100644
@@ -76,7 +76,7 @@ static void hwmgr_init_workload_prority(struct pp_hwmgr *hwmgr)
 
 int hwmgr_early_init(struct pp_hwmgr *hwmgr)
 {
-       if (hwmgr == NULL)
+       if (!hwmgr)
                return -EINVAL;
 
        hwmgr->usec_timeout = AMD_MAX_USEC_TIMEOUT;
@@ -170,17 +170,51 @@ int hwmgr_early_init(struct pp_hwmgr *hwmgr)
        return 0;
 }
 
+int hwmgr_sw_init(struct pp_hwmgr *hwmgr)
+{
+       if (!hwmgr|| !hwmgr->smumgr_funcs || !hwmgr->smumgr_funcs->smu_init)
+               return -EINVAL;
+
+       phm_register_irq_handlers(hwmgr);
+
+       return hwmgr->smumgr_funcs->smu_init(hwmgr);
+}
+
+
+int hwmgr_sw_fini(struct pp_hwmgr *hwmgr)
+{
+       if (hwmgr && hwmgr->smumgr_funcs && hwmgr->smumgr_funcs->smu_fini)
+               hwmgr->smumgr_funcs->smu_fini(hwmgr);
+
+       return 0;
+}
+
 int hwmgr_hw_init(struct pp_hwmgr *hwmgr)
 {
        int ret = 0;
 
-       if (hwmgr == NULL)
+       if (!hwmgr || !hwmgr->smumgr_funcs)
                return -EINVAL;
 
-       if (hwmgr->pptable_func == NULL ||
-           hwmgr->pptable_func->pptable_init == NULL ||
-           hwmgr->hwmgr_func->backend_init == NULL)
-               return -EINVAL;
+       if (hwmgr->smumgr_funcs->start_smu) {
+               ret = hwmgr->smumgr_funcs->start_smu(hwmgr);
+               if (ret) {
+                       pr_err("smc start failed\n");
+                       return -EINVAL;
+               }
+       }
+
+       if (!hwmgr->pm_en)
+               return 0;
+
+       if (!hwmgr->pptable_func ||
+           !hwmgr->pptable_func->pptable_init ||
+           !hwmgr->hwmgr_func->backend_init) {
+               hwmgr->pm_en = false;
+               cgs_notify_dpm_enabled(hwmgr->device, false);
+               pr_info("dpm not supported \n");
+               return 0;
+       }
 
        ret = hwmgr->pptable_func->pptable_init(hwmgr);
        if (ret)
@@ -214,14 +248,13 @@ int hwmgr_hw_init(struct pp_hwmgr *hwmgr)
        if (hwmgr->pptable_func->pptable_fini)
                hwmgr->pptable_func->pptable_fini(hwmgr);
 err:
-       pr_err("amdgpu: powerplay initialization failed\n");
        return ret;
 }
 
 int hwmgr_hw_fini(struct pp_hwmgr *hwmgr)
 {
-       if (hwmgr == NULL)
-               return -EINVAL;
+       if (!hwmgr || !hwmgr->pm_en)
+               return 0;
 
        phm_stop_thermal_controller(hwmgr);
        psm_set_boot_states(hwmgr);
@@ -236,12 +269,12 @@ int hwmgr_hw_fini(struct pp_hwmgr *hwmgr)
        return psm_fini_power_state_table(hwmgr);
 }
 
-int hwmgr_hw_suspend(struct pp_hwmgr *hwmgr)
+int hwmgr_suspend(struct pp_hwmgr *hwmgr)
 {
        int ret = 0;
 
-       if (hwmgr == NULL)
-               return -EINVAL;
+       if (!hwmgr || !hwmgr->pm_en)
+               return 0;
 
        phm_disable_smc_firmware_ctf(hwmgr);
        ret = psm_set_boot_states(hwmgr);
@@ -255,13 +288,23 @@ int hwmgr_hw_suspend(struct pp_hwmgr *hwmgr)
        return ret;
 }
 
-int hwmgr_hw_resume(struct pp_hwmgr *hwmgr)
+int hwmgr_resume(struct pp_hwmgr *hwmgr)
 {
        int ret = 0;
 
-       if (hwmgr == NULL)
+       if (!hwmgr)
                return -EINVAL;
 
+       if (hwmgr->smumgr_funcs && hwmgr->smumgr_funcs->start_smu) {
+               if (hwmgr->smumgr_funcs->start_smu(hwmgr)) {
+                       pr_err("smc start failed\n");
+                       return -EINVAL;
+               }
+       }
+
+       if (!hwmgr->pm_en)
+               return 0;
+
        ret = phm_setup_asic(hwmgr);
        if (ret)
                return ret;
@@ -270,9 +313,6 @@ int hwmgr_hw_resume(struct pp_hwmgr *hwmgr)
        if (ret)
                return ret;
        ret = phm_start_thermal_controller(hwmgr);
-       if (ret)
-               return ret;
-
        ret |= psm_set_performance_states(hwmgr);
        if (ret)
                return ret;
drivers/gpu/drm/amd/powerplay/inc/hwmgr.h +5 -3
index 17f811d..d6c9a3b 100644
@@ -782,10 +782,13 @@ struct pp_hwmgr {
 };
 
 int hwmgr_early_init(struct pp_hwmgr *hwmgr);
+int hwmgr_sw_init(struct pp_hwmgr *hwmgr);
+int hwmgr_sw_fini(struct pp_hwmgr *hwmgr);
 int hwmgr_hw_init(struct pp_hwmgr *hwmgr);
 int hwmgr_hw_fini(struct pp_hwmgr *hwmgr);
-int hwmgr_hw_suspend(struct pp_hwmgr *hwmgr);
-int hwmgr_hw_resume(struct pp_hwmgr *hwmgr);
+int hwmgr_suspend(struct pp_hwmgr *hwmgr);
+int hwmgr_resume(struct pp_hwmgr *hwmgr);
+
 int hwmgr_handle_task(struct pp_hwmgr *hwmgr,
                                enum amd_pp_task task_id,
                                enum amd_pm_state_type *user_state);
--

1.9.1

Quoted 4 lines

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

Reviewed-by
#6 lore raw

Re: [PATCH 2/6] drm/amd/pp: Add hwmgr_sw_init/fini functioins

In reply to a message not in the archive
Quoted 7 lines · Alex Deucher
Quoted 4 lines · Rex Zhu

Clean up pp ip functions

Change-Id Id06159202edabdfcb19fcc20e1291ce93db56d5d

Actually, doesn't this patch have a dependency on patch 3? I think this part of patch 3:
+ hwmgr->pm_en = (amdgpu_dpm && hwmgr->not_vf) ? true : false;
should be in this patch rather than the other patch. With that fixed:

Quoted 973 lines
Quoted 973 lines
---
 drivers/gpu/drm/amd/powerplay/amd_powerplay.c | 368 ++++++--------------------
 drivers/gpu/drm/amd/powerplay/hwmgr/hwmgr.c   |  74 ++++--
 drivers/gpu/drm/amd/powerplay/inc/hwmgr.h     |   7 +-
 3 files changed, 145 insertions(+), 304 deletions(-)
drivers/gpu/drm/amd/powerplay/amd_powerplay.c +83 -285
index 7e8ad30..5d7d9ec 100644
@@ -31,24 +31,11 @@
 #include "amdgpu.h"
 #include "hwmgr.h"
 
-#define PP_DPM_DISABLED 0xCCCC
-
 static int pp_dpm_dispatch_tasks(void *handle, enum amd_pp_task task_id,
                enum amd_pm_state_type *user_state);
 
 static const struct amd_pm_funcs pp_dpm_funcs;
 
-static inline int pp_check(struct pp_hwmgr *hwmgr)
-{
-       if (hwmgr == NULL || hwmgr->smumgr_funcs == NULL)
-               return -EINVAL;
-
-       if (hwmgr->pm_en == 0 || hwmgr->hwmgr_func == NULL)
-               return PP_DPM_DISABLED;
-
-       return 0;
-}
-
 static int amd_powerplay_create(struct amdgpu_device *adev)
 {
        struct pp_hwmgr *hwmgr;
@@ -73,7 +60,7 @@ static int amd_powerplay_create(struct amdgpu_device *adev)
 }
 
 
-static int amd_powerplay_destroy(struct amdgpu_device *adev)
+static void amd_powerplay_destroy(struct amdgpu_device *adev)
 {
        struct pp_hwmgr *hwmgr = adev->powerplay.pp_handle;
 
@@ -82,8 +69,6 @@ static int amd_powerplay_destroy(struct amdgpu_device *adev)
 
        kfree(hwmgr);
        hwmgr = NULL;
-
-       return 0;
 }
 
 static int pp_early_init(void *handle)
@@ -109,18 +94,9 @@ static int pp_sw_init(void *handle)
        struct pp_hwmgr *hwmgr = adev->powerplay.pp_handle;
        int ret = 0;
 
-       ret = pp_check(hwmgr);
-
-       if (ret >= 0) {
-               if (hwmgr->smumgr_funcs->smu_init == NULL)
-                       return -EINVAL;
+       ret = hwmgr_sw_init(hwmgr);
 
-               ret = hwmgr->smumgr_funcs->smu_init(hwmgr);
-
-               phm_register_irq_handlers(hwmgr);
-
-               pr_debug("amdgpu: powerplay sw initialized\n");
-       }
+       pr_debug("amdgpu: powerplay sw init %s\n", ret ? "failed" : "successfully");
 
        return ret;
 }
@@ -129,13 +105,8 @@ static int pp_sw_fini(void *handle)
 {
        struct amdgpu_device *adev = handle;
        struct pp_hwmgr *hwmgr = adev->powerplay.pp_handle;
-       int ret = 0;
 
-       ret = pp_check(hwmgr);
-       if (ret >= 0) {
-               if (hwmgr->smumgr_funcs->smu_fini != NULL)
-                       hwmgr->smumgr_funcs->smu_fini(hwmgr);
-       }
+       hwmgr_sw_fini(hwmgr);
 
        if (adev->firmware.load_type == AMDGPU_FW_LOAD_SMU)
                amdgpu_ucode_fini_bo(adev);
@@ -152,40 +123,20 @@ static int pp_hw_init(void *handle)
        if (adev->firmware.load_type == AMDGPU_FW_LOAD_SMU)
                amdgpu_ucode_init_bo(adev);
 
-       ret = pp_check(hwmgr);
+       ret = hwmgr_hw_init(hwmgr);
 
-       if (ret >= 0) {
-               if (hwmgr->smumgr_funcs->start_smu == NULL)
-                       return -EINVAL;
+       if (ret)
+               pr_err("amdgpu: powerplay hw init failed\n");
 
-               if (hwmgr->smumgr_funcs->start_smu(hwmgr)) {
-                       pr_err("smc start failed\n");
-                       hwmgr->smumgr_funcs->smu_fini(hwmgr);
-                       return -EINVAL;
-               }
-               if (ret == PP_DPM_DISABLED)
-                       goto exit;
-               ret = hwmgr_hw_init(hwmgr);
-               if (ret)
-                       goto exit;
-       }
        return ret;
-exit:
-       hwmgr->pm_en = 0;
-       cgs_notify_dpm_enabled(hwmgr->device, false);
-       return 0;
-
 }
 
 static int pp_hw_fini(void *handle)
 {
        struct amdgpu_device *adev = handle;
        struct pp_hwmgr *hwmgr = adev->powerplay.pp_handle;
-       int ret = 0;
 
-       ret = pp_check(hwmgr);
-       if (ret == 0)
-               hwmgr_hw_fini(hwmgr);
+       hwmgr_hw_fini(hwmgr);
 
        return 0;
 }
@@ -194,11 +145,8 @@ static int pp_late_init(void *handle)
 {
        struct amdgpu_device *adev = handle;
        struct pp_hwmgr *hwmgr = adev->powerplay.pp_handle;
-       int ret = 0;
-
-       ret = pp_check(hwmgr);
 
-       if (ret == 0)
+       if (hwmgr && hwmgr->pm_en)
                pp_dpm_dispatch_tasks(hwmgr,
                                        AMD_PP_TASK_COMPLETE_INIT, NULL);
 
@@ -233,12 +181,9 @@ static int pp_set_powergating_state(void *handle,
 {
        struct amdgpu_device *adev = handle;
        struct pp_hwmgr *hwmgr = adev->powerplay.pp_handle;
-       int ret = 0;
 
-       ret = pp_check(hwmgr);
-
-       if (ret)
-               return ret;
+       if (!hwmgr || !hwmgr->pm_en)
+               return 0;
 
        if (hwmgr->hwmgr_func->enable_per_cu_power_gating == NULL) {
                pr_info("%s was not implemented.\n", __func__);
@@ -254,38 +199,16 @@ static int pp_suspend(void *handle)
 {
        struct amdgpu_device *adev = handle;
        struct pp_hwmgr *hwmgr = adev->powerplay.pp_handle;
-       int ret = 0;
 
-       ret = pp_check(hwmgr);
-       if (ret == 0)
-               hwmgr_hw_suspend(hwmgr);
-       return 0;
+       return hwmgr_suspend(hwmgr);
 }
 
 static int pp_resume(void *handle)
 {
        struct amdgpu_device *adev = handle;
        struct pp_hwmgr *hwmgr = adev->powerplay.pp_handle;
-       int ret;
-
-       ret = pp_check(hwmgr);
-
-       if (ret < 0)
-               return ret;
-
-       if (hwmgr->smumgr_funcs->start_smu == NULL)
-               return -EINVAL;
-
-       if (hwmgr->smumgr_funcs->start_smu(hwmgr)) {
-               pr_err("smc start failed\n");
-               hwmgr->smumgr_funcs->smu_fini(hwmgr);
-               return -EINVAL;
-       }
-
-       if (ret == PP_DPM_DISABLED)
-               return 0;
 
-       return hwmgr_hw_resume(hwmgr);
+       return hwmgr_resume(hwmgr);
 }
 
 static int pp_set_clockgating_state(void *handle,
@@ -334,12 +257,9 @@ static int pp_dpm_fw_loading_complete(void *handle)
 static int pp_set_clockgating_by_smu(void *handle, uint32_t msg_id)
 {
        struct pp_hwmgr *hwmgr = handle;
-       int ret = 0;
-
-       ret = pp_check(hwmgr);
 
-       if (ret)
-               return ret;
+       if (!hwmgr || !hwmgr->pm_en)
+               return -EINVAL;
 
        if (hwmgr->hwmgr_func->update_clock_gatings == NULL) {
                pr_info("%s was not implemented.\n", __func__);
@@ -389,12 +309,9 @@ static int pp_dpm_force_performance_level(void *handle,
                                        enum amd_dpm_forced_level level)
 {
        struct pp_hwmgr *hwmgr = handle;
-       int ret = 0;
 
-       ret = pp_check(hwmgr);
-
-       if (ret)
-               return ret;
+       if (!hwmgr || !hwmgr->pm_en)
+               return -EINVAL;
 
        if (level == hwmgr->dpm_level)
                return 0;
@@ -412,13 +329,10 @@ static enum amd_dpm_forced_level pp_dpm_get_performance_level(
                                                                void *handle)
 {
        struct pp_hwmgr *hwmgr = handle;
-       int ret = 0;
        enum amd_dpm_forced_level level;
 
-       ret = pp_check(hwmgr);
-
-       if (ret)
-               return ret;
+       if (!hwmgr || !hwmgr->pm_en)
+               return -EINVAL;
 
        mutex_lock(&hwmgr->smu_lock);
        level = hwmgr->dpm_level;
@@ -429,13 +343,10 @@ static enum amd_dpm_forced_level pp_dpm_get_performance_level(
 static uint32_t pp_dpm_get_sclk(void *handle, bool low)
 {
        struct pp_hwmgr *hwmgr = handle;
-       int ret = 0;
        uint32_t clk = 0;
 
-       ret = pp_check(hwmgr);
-
-       if (ret)
-               return ret;
+       if (!hwmgr || !hwmgr->pm_en)
+               return 0;
 
        if (hwmgr->hwmgr_func->get_sclk == NULL) {
                pr_info("%s was not implemented.\n", __func__);
@@ -450,13 +361,10 @@ static uint32_t pp_dpm_get_sclk(void *handle, bool low)
 static uint32_t pp_dpm_get_mclk(void *handle, bool low)
 {
        struct pp_hwmgr *hwmgr = handle;
-       int ret = 0;
        uint32_t clk = 0;
 
-       ret = pp_check(hwmgr);
-
-       if (ret)
-               return ret;
+       if (!hwmgr || !hwmgr->pm_en)
+               return 0;
 
        if (hwmgr->hwmgr_func->get_mclk == NULL) {
                pr_info("%s was not implemented.\n", __func__);
@@ -471,11 +379,8 @@ static uint32_t pp_dpm_get_mclk(void *handle, bool low)
 static void pp_dpm_powergate_vce(void *handle, bool gate)
 {
        struct pp_hwmgr *hwmgr = handle;
-       int ret = 0;
-
-       ret = pp_check(hwmgr);
 
-       if (ret)
+       if (!hwmgr || !hwmgr->pm_en)
                return;
 
        if (hwmgr->hwmgr_func->powergate_vce == NULL) {
@@ -490,11 +395,8 @@ static void pp_dpm_powergate_vce(void *handle, bool gate)
 static void pp_dpm_powergate_uvd(void *handle, bool gate)
 {
        struct pp_hwmgr *hwmgr = handle;
-       int ret = 0;
-
-       ret = pp_check(hwmgr);
 
-       if (ret)
+       if (!hwmgr || !hwmgr->pm_en)
                return;
 
        if (hwmgr->hwmgr_func->powergate_uvd == NULL) {
@@ -512,10 +414,8 @@ static int pp_dpm_dispatch_tasks(void *handle, enum amd_pp_task task_id,
        int ret = 0;
        struct pp_hwmgr *hwmgr = handle;
 
-       ret = pp_check(hwmgr);
-
-       if (ret)
-               return ret;
+       if (!hwmgr || !hwmgr->pm_en)
+               return -EINVAL;
 
        mutex_lock(&hwmgr->smu_lock);
        ret = hwmgr_handle_task(hwmgr, task_id, user_state);
@@ -528,15 +428,9 @@ static enum amd_pm_state_type pp_dpm_get_current_power_state(void *handle)
 {
        struct pp_hwmgr *hwmgr = handle;
        struct pp_power_state *state;
-       int ret = 0;
        enum amd_pm_state_type pm_type;
 
-       ret = pp_check(hwmgr);
-
-       if (ret)
-               return ret;
-
-       if (hwmgr->current_ps == NULL)
+       if (!hwmgr || !hwmgr->pm_en || !hwmgr->current_ps)
                return -EINVAL;
 
        mutex_lock(&hwmgr->smu_lock);
@@ -568,11 +462,8 @@ static enum amd_pm_state_type pp_dpm_get_current_power_state(void *handle)
 static void pp_dpm_set_fan_control_mode(void *handle, uint32_t mode)
 {
        struct pp_hwmgr *hwmgr = handle;
-       int ret = 0;
-
-       ret = pp_check(hwmgr);
 
-       if (ret)
+       if (!hwmgr || !hwmgr->pm_en)
                return;
 
        if (hwmgr->hwmgr_func->set_fan_control_mode == NULL) {
@@ -587,13 +478,10 @@ static void pp_dpm_set_fan_control_mode(void *handle, uint32_t mode)
 static uint32_t pp_dpm_get_fan_control_mode(void *handle)
 {
        struct pp_hwmgr *hwmgr = handle;
-       int ret = 0;
        uint32_t mode = 0;
 
-       ret = pp_check(hwmgr);
-
-       if (ret)
-               return ret;
+       if (!hwmgr || !hwmgr->pm_en)
+               return 0;
 
        if (hwmgr->hwmgr_func->get_fan_control_mode == NULL) {
                pr_info("%s was not implemented.\n", __func__);
@@ -610,10 +498,8 @@ static int pp_dpm_set_fan_speed_percent(void *handle, uint32_t percent)
        struct pp_hwmgr *hwmgr = handle;
        int ret = 0;
 
-       ret = pp_check(hwmgr);
-
-       if (ret)
-               return ret;
+       if (!hwmgr || !hwmgr->pm_en)
+               return -EINVAL;
 
        if (hwmgr->hwmgr_func->set_fan_speed_percent == NULL) {
                pr_info("%s was not implemented.\n", __func__);
@@ -630,10 +516,8 @@ static int pp_dpm_get_fan_speed_percent(void *handle, uint32_t *speed)
        struct pp_hwmgr *hwmgr = handle;
        int ret = 0;
 
-       ret = pp_check(hwmgr);
-
-       if (ret)
-               return ret;
+       if (!hwmgr || !hwmgr->pm_en)
+               return -EINVAL;
 
        if (hwmgr->hwmgr_func->get_fan_speed_percent == NULL) {
                pr_info("%s was not implemented.\n", __func__);
@@ -651,10 +535,8 @@ static int pp_dpm_get_fan_speed_rpm(void *handle, uint32_t *rpm)
        struct pp_hwmgr *hwmgr = handle;
        int ret = 0;
 
-       ret = pp_check(hwmgr);
-
-       if (ret)
-               return ret;
+       if (!hwmgr || !hwmgr->pm_en)
+               return -EINVAL;
 
        if (hwmgr->hwmgr_func->get_fan_speed_rpm == NULL)
                return -EINVAL;
@@ -670,16 +552,10 @@ static int pp_dpm_get_pp_num_states(void *handle,
 {
        struct pp_hwmgr *hwmgr = handle;
        int i;
-       int ret = 0;
 
        memset(data, 0, sizeof(*data));
 
-       ret = pp_check(hwmgr);
-
-       if (ret)
-               return ret;
-
-       if (hwmgr->ps == NULL)
+       if (!hwmgr || !hwmgr->pm_en ||!hwmgr->ps)
                return -EINVAL;
 
        mutex_lock(&hwmgr->smu_lock);
@@ -713,15 +589,9 @@ static int pp_dpm_get_pp_num_states(void *handle,
 static int pp_dpm_get_pp_table(void *handle, char **table)
 {
        struct pp_hwmgr *hwmgr = handle;
-       int ret = 0;
        int size = 0;
 
-       ret = pp_check(hwmgr);
-
-       if (ret)
-               return ret;
-
-       if (!hwmgr->soft_pp_table)
+       if (!hwmgr || !hwmgr->pm_en ||!hwmgr->soft_pp_table)
                return -EINVAL;
 
        mutex_lock(&hwmgr->smu_lock);
@@ -736,10 +606,6 @@ static int amd_powerplay_reset(void *handle)
        struct pp_hwmgr *hwmgr = handle;
        int ret;
 
-       ret = pp_check(hwmgr);
-       if (ret)
-               return ret;
-
        ret = hwmgr_hw_fini(hwmgr);
        if (ret)
                return ret;
@@ -756,10 +622,8 @@ static int pp_dpm_set_pp_table(void *handle, const char *buf, size_t size)
        struct pp_hwmgr *hwmgr = handle;
        int ret = 0;
 
-       ret = pp_check(hwmgr);
-
-       if (ret)
-               return ret;
+       if (!hwmgr || !hwmgr->pm_en)
+               return -EINVAL;
 
        mutex_lock(&hwmgr->smu_lock);
        if (!hwmgr->hardcode_pp_table) {
@@ -796,10 +660,8 @@ static int pp_dpm_force_clock_level(void *handle,
        struct pp_hwmgr *hwmgr = handle;
        int ret = 0;
 
-       ret = pp_check(hwmgr);
-
-       if (ret)
-               return ret;
+       if (!hwmgr || !hwmgr->pm_en)
+               return -EINVAL;
 
        if (hwmgr->hwmgr_func->force_clock_level == NULL) {
                pr_info("%s was not implemented.\n", __func__);
@@ -820,10 +682,8 @@ static int pp_dpm_print_clock_levels(void *handle,
        struct pp_hwmgr *hwmgr = handle;
        int ret = 0;
 
-       ret = pp_check(hwmgr);
-
-       if (ret)
-               return ret;
+       if (!hwmgr || !hwmgr->pm_en)
+               return -EINVAL;
 
        if (hwmgr->hwmgr_func->print_clock_levels == NULL) {
                pr_info("%s was not implemented.\n", __func__);
@@ -840,10 +700,8 @@ static int pp_dpm_get_sclk_od(void *handle)
        struct pp_hwmgr *hwmgr = handle;
        int ret = 0;
 
-       ret = pp_check(hwmgr);
-
-       if (ret)
-               return ret;
+       if (!hwmgr || !hwmgr->pm_en)
+               return -EINVAL;
 
        if (hwmgr->hwmgr_func->get_sclk_od == NULL) {
                pr_info("%s was not implemented.\n", __func__);
@@ -860,10 +718,8 @@ static int pp_dpm_set_sclk_od(void *handle, uint32_t value)
        struct pp_hwmgr *hwmgr = handle;
        int ret = 0;
 
-       ret = pp_check(hwmgr);
-
-       if (ret)
-               return ret;
+       if (!hwmgr || !hwmgr->pm_en)
+               return -EINVAL;
 
        if (hwmgr->hwmgr_func->set_sclk_od == NULL) {
                pr_info("%s was not implemented.\n", __func__);
@@ -881,10 +737,8 @@ static int pp_dpm_get_mclk_od(void *handle)
        struct pp_hwmgr *hwmgr = handle;
        int ret = 0;
 
-       ret = pp_check(hwmgr);
-
-       if (ret)
-               return ret;
+       if (!hwmgr || !hwmgr->pm_en)
+               return -EINVAL;
 
        if (hwmgr->hwmgr_func->get_mclk_od == NULL) {
                pr_info("%s was not implemented.\n", __func__);
@@ -901,10 +755,8 @@ static int pp_dpm_set_mclk_od(void *handle, uint32_t value)
        struct pp_hwmgr *hwmgr = handle;
        int ret = 0;
 
-       ret = pp_check(hwmgr);
-
-       if (ret)
-               return ret;
+       if (!hwmgr || !hwmgr->pm_en)
+               return -EINVAL;
 
        if (hwmgr->hwmgr_func->set_mclk_od == NULL) {
                pr_info("%s was not implemented.\n", __func__);
@@ -922,11 +774,7 @@ static int pp_dpm_read_sensor(void *handle, int idx,
        struct pp_hwmgr *hwmgr = handle;
        int ret = 0;
 
-       ret = pp_check(hwmgr);
-       if (ret)
-               return ret;
-
-       if (value == NULL)
+       if (!hwmgr || !hwmgr->pm_en || !value)
                return -EINVAL;
 
        switch (idx) {
@@ -948,14 +796,11 @@ static int pp_dpm_read_sensor(void *handle, int idx,
 pp_dpm_get_vce_clock_state(void *handle, unsigned idx)
 {
        struct pp_hwmgr *hwmgr = handle;
-       int ret = 0;
-
-       ret = pp_check(hwmgr);
 
-       if (ret)
+       if (!hwmgr || !hwmgr->pm_en)
                return NULL;
 
-       if (hwmgr && idx < hwmgr->num_vce_state_tables)
+       if (idx < hwmgr->num_vce_state_tables)
                return &hwmgr->vce_states[idx];
        return NULL;
 }
@@ -964,7 +809,7 @@ static int pp_get_power_profile_mode(void *handle, char *buf)
 {
        struct pp_hwmgr *hwmgr = handle;
 
-       if (!buf || pp_check(hwmgr))
+       if (!hwmgr || !hwmgr->pm_en || !buf)
                return -EINVAL;
 
        if (hwmgr->hwmgr_func->get_power_profile_mode == NULL) {
@@ -980,12 +825,12 @@ static int pp_set_power_profile_mode(void *handle, long *input, uint32_t size)
        struct pp_hwmgr *hwmgr = handle;
        int ret = -EINVAL;
 
-       if (pp_check(hwmgr))
-               return -EINVAL;
+       if (!hwmgr || !hwmgr->pm_en)
+               return ret;
 
        if (hwmgr->hwmgr_func->set_power_profile_mode == NULL) {
                pr_info("%s was not implemented.\n", __func__);
-               return -EINVAL;
+               return ret;
        }
        mutex_lock(&hwmgr->smu_lock);
        if (hwmgr->dpm_level == AMD_DPM_FORCED_LEVEL_MANUAL)
@@ -998,7 +843,7 @@ static int pp_odn_edit_dpm_table(void *handle, uint32_t type, long *input, uint3
 {
        struct pp_hwmgr *hwmgr = handle;
 
-       if (pp_check(hwmgr))
+       if (!hwmgr || !hwmgr->pm_en)
                return -EINVAL;
 
        if (hwmgr->hwmgr_func->odn_edit_dpm_table == NULL) {
@@ -1016,7 +861,7 @@ static int pp_dpm_switch_power_profile(void *handle,
        long workload;
        uint32_t index;
 
-       if (pp_check(hwmgr))
+       if (!hwmgr || !hwmgr->pm_en)
                return -EINVAL;
 
        if (hwmgr->hwmgr_func->set_power_profile_mode == NULL) {
@@ -1058,10 +903,8 @@ static int pp_dpm_notify_smu_memory_info(void *handle,
        struct pp_hwmgr *hwmgr = handle;
        int ret = 0;
 
-       ret = pp_check(hwmgr);
-
-       if (ret)
-               return ret;
+       if (!hwmgr || !hwmgr->pm_en)
+               return -EINVAL;
 
        if (hwmgr->hwmgr_func->notify_cac_buffer_info == NULL) {
                pr_info("%s was not implemented.\n", __func__);
@@ -1082,12 +925,9 @@ static int pp_dpm_notify_smu_memory_info(void *handle,
 static int pp_set_power_limit(void *handle, uint32_t limit)
 {
        struct pp_hwmgr *hwmgr = handle;
-       int ret = 0;
-
-       ret = pp_check(hwmgr);
 
-       if (ret)
-               return ret;
+       if (!hwmgr || !hwmgr->pm_en)
+               return -EINVAL;
 
        if (hwmgr->hwmgr_func->set_power_limit == NULL) {
                pr_info("%s was not implemented.\n", __func__);
@@ -1104,20 +944,14 @@ static int pp_set_power_limit(void *handle, uint32_t limit)
        hwmgr->hwmgr_func->set_power_limit(hwmgr, limit);
        hwmgr->power_limit = limit;
        mutex_unlock(&hwmgr->smu_lock);
-       return ret;
+       return 0;
 }
 
 static int pp_get_power_limit(void *handle, uint32_t *limit, bool default_limit)
 {
        struct pp_hwmgr *hwmgr = handle;
-       int ret = 0;
-
-       ret = pp_check(hwmgr);
 
-       if (ret)
-               return ret;
-
-       if (limit == NULL)
+       if (!hwmgr || !hwmgr->pm_en ||!limit)
                return -EINVAL;
 
        mutex_lock(&hwmgr->smu_lock);
@@ -1129,19 +963,16 @@ static int pp_get_power_limit(void *handle, uint32_t *limit, bool default_limit)
 
        mutex_unlock(&hwmgr->smu_lock);
 
-       return ret;
+       return 0;
 }
 
 static int pp_display_configuration_change(void *handle,
        const struct amd_pp_display_configuration *display_config)
 {
        struct pp_hwmgr *hwmgr = handle;
-       int ret = 0;
-
-       ret = pp_check(hwmgr);
 
-       if (ret)
-               return ret;
+       if (!hwmgr || !hwmgr->pm_en)
+               return -EINVAL;
 
        mutex_lock(&hwmgr->smu_lock);
        phm_store_dal_configuration_data(hwmgr, display_config);
@@ -1155,12 +986,7 @@ static int pp_get_display_power_level(void *handle,
        struct pp_hwmgr *hwmgr = handle;
        int ret = 0;
 
-       ret = pp_check(hwmgr);
-
-       if (ret)
-               return ret;
-
-       if (output == NULL)
+       if (!hwmgr || !hwmgr->pm_en ||!output)
                return -EINVAL;
 
        mutex_lock(&hwmgr->smu_lock);
@@ -1177,10 +1003,8 @@ static int pp_get_current_clocks(void *handle,
        struct pp_hwmgr *hwmgr = handle;
        int ret = 0;
 
-       ret = pp_check(hwmgr);
-
-       if (ret)
-               return ret;
+       if (!hwmgr || !hwmgr->pm_en)
+               return -EINVAL;
 
        mutex_lock(&hwmgr->smu_lock);
 
@@ -1225,10 +1049,8 @@ static int pp_get_clock_by_type(void *handle, enum amd_pp_clock_type type, struc
        struct pp_hwmgr *hwmgr = handle;
        int ret = 0;
 
-       ret = pp_check(hwmgr);
-
-       if (ret)
-               return ret;
+       if (!hwmgr || !hwmgr->pm_en)
+               return -EINVAL;
 
        if (clocks == NULL)
                return -EINVAL;
@@ -1246,11 +1068,7 @@ static int pp_get_clock_by_type_with_latency(void *handle,
        struct pp_hwmgr *hwmgr = handle;
        int ret = 0;
 
-       ret = pp_check(hwmgr);
-       if (ret)
-               return ret;
-
-       if (!clocks)
+       if (!hwmgr || !hwmgr->pm_en ||!clocks)
                return -EINVAL;
 
        mutex_lock(&hwmgr->smu_lock);
@@ -1266,11 +1084,7 @@ static int pp_get_clock_by_type_with_voltage(void *handle,
        struct pp_hwmgr *hwmgr = handle;
        int ret = 0;
 
-       ret = pp_check(hwmgr);
-       if (ret)
-               return ret;
-
-       if (!clocks)
+       if (!hwmgr || !hwmgr->pm_en ||!clocks)
                return -EINVAL;
 
        mutex_lock(&hwmgr->smu_lock);
@@ -1287,11 +1101,7 @@ static int pp_set_watermarks_for_clocks_ranges(void *handle,
        struct pp_hwmgr *hwmgr = handle;
        int ret = 0;
 
-       ret = pp_check(hwmgr);
-       if (ret)
-               return ret;
-
-       if (!wm_with_clock_ranges)
+       if (!hwmgr || !hwmgr->pm_en ||!wm_with_clock_ranges)
                return -EINVAL;
 
        mutex_lock(&hwmgr->smu_lock);
@@ -1308,11 +1118,7 @@ static int pp_display_clock_voltage_request(void *handle,
        struct pp_hwmgr *hwmgr = handle;
        int ret = 0;
 
-       ret = pp_check(hwmgr);
-       if (ret)
-               return ret;
-
-       if (!clock)
+       if (!hwmgr || !hwmgr->pm_en ||!clock)
                return -EINVAL;
 
        mutex_lock(&hwmgr->smu_lock);
@@ -1328,12 +1134,7 @@ static int pp_get_display_mode_validation_clocks(void *handle,
        struct pp_hwmgr *hwmgr = handle;
        int ret = 0;
 
-       ret = pp_check(hwmgr);
-
-       if (ret)
-               return ret;
-
-       if (clocks == NULL)
+       if (!hwmgr || !hwmgr->pm_en ||!clocks)
                return -EINVAL;
 
        mutex_lock(&hwmgr->smu_lock);
@@ -1348,12 +1149,9 @@ static int pp_get_display_mode_validation_clocks(void *handle,
 static int pp_set_mmhub_powergating_by_smu(void *handle)
 {
        struct pp_hwmgr *hwmgr = handle;
-       int ret = 0;
-
-       ret = pp_check(hwmgr);
 
-       if (ret)
-               return ret;
+       if (!hwmgr || !hwmgr->pm_en)
+               return -EINVAL;
 
        if (hwmgr->hwmgr_func->set_mmhub_powergating_by_smu == NULL) {
                pr_info("%s was not implemented.\n", __func__);
drivers/gpu/drm/amd/powerplay/hwmgr/hwmgr.c +57 -17
index 4298205..96a2d01 100644
@@ -76,7 +76,7 @@ static void hwmgr_init_workload_prority(struct pp_hwmgr *hwmgr)
 
 int hwmgr_early_init(struct pp_hwmgr *hwmgr)
 {
-       if (hwmgr == NULL)
+       if (!hwmgr)
                return -EINVAL;
 
        hwmgr->usec_timeout = AMD_MAX_USEC_TIMEOUT;
@@ -170,17 +170,51 @@ int hwmgr_early_init(struct pp_hwmgr *hwmgr)
        return 0;
 }
 
+int hwmgr_sw_init(struct pp_hwmgr *hwmgr)
+{
+       if (!hwmgr|| !hwmgr->smumgr_funcs || !hwmgr->smumgr_funcs->smu_init)
+               return -EINVAL;
+
+       phm_register_irq_handlers(hwmgr);
+
+       return hwmgr->smumgr_funcs->smu_init(hwmgr);
+}
+
+
+int hwmgr_sw_fini(struct pp_hwmgr *hwmgr)
+{
+       if (hwmgr && hwmgr->smumgr_funcs && hwmgr->smumgr_funcs->smu_fini)
+               hwmgr->smumgr_funcs->smu_fini(hwmgr);
+
+       return 0;
+}
+
 int hwmgr_hw_init(struct pp_hwmgr *hwmgr)
 {
        int ret = 0;
 
-       if (hwmgr == NULL)
+       if (!hwmgr || !hwmgr->smumgr_funcs)
                return -EINVAL;
 
-       if (hwmgr->pptable_func == NULL ||
-           hwmgr->pptable_func->pptable_init == NULL ||
-           hwmgr->hwmgr_func->backend_init == NULL)
-               return -EINVAL;
+       if (hwmgr->smumgr_funcs->start_smu) {
+               ret = hwmgr->smumgr_funcs->start_smu(hwmgr);
+               if (ret) {
+                       pr_err("smc start failed\n");
+                       return -EINVAL;
+               }
+       }
+
+       if (!hwmgr->pm_en)
+               return 0;
+
+       if (!hwmgr->pptable_func ||
+           !hwmgr->pptable_func->pptable_init ||
+           !hwmgr->hwmgr_func->backend_init) {
+               hwmgr->pm_en = false;
+               cgs_notify_dpm_enabled(hwmgr->device, false);
+               pr_info("dpm not supported \n");
+               return 0;
+       }
 
        ret = hwmgr->pptable_func->pptable_init(hwmgr);
        if (ret)
@@ -214,14 +248,13 @@ int hwmgr_hw_init(struct pp_hwmgr *hwmgr)
        if (hwmgr->pptable_func->pptable_fini)
                hwmgr->pptable_func->pptable_fini(hwmgr);
 err:
-       pr_err("amdgpu: powerplay initialization failed\n");
        return ret;
 }
 
 int hwmgr_hw_fini(struct pp_hwmgr *hwmgr)
 {
-       if (hwmgr == NULL)
-               return -EINVAL;
+       if (!hwmgr || !hwmgr->pm_en)
+               return 0;
 
        phm_stop_thermal_controller(hwmgr);
        psm_set_boot_states(hwmgr);
@@ -236,12 +269,12 @@ int hwmgr_hw_fini(struct pp_hwmgr *hwmgr)
        return psm_fini_power_state_table(hwmgr);
 }
 
-int hwmgr_hw_suspend(struct pp_hwmgr *hwmgr)
+int hwmgr_suspend(struct pp_hwmgr *hwmgr)
 {
        int ret = 0;
 
-       if (hwmgr == NULL)
-               return -EINVAL;
+       if (!hwmgr || !hwmgr->pm_en)
+               return 0;
 
        phm_disable_smc_firmware_ctf(hwmgr);
        ret = psm_set_boot_states(hwmgr);
@@ -255,13 +288,23 @@ int hwmgr_hw_suspend(struct pp_hwmgr *hwmgr)
        return ret;
 }
 
-int hwmgr_hw_resume(struct pp_hwmgr *hwmgr)
+int hwmgr_resume(struct pp_hwmgr *hwmgr)
 {
        int ret = 0;
 
-       if (hwmgr == NULL)
+       if (!hwmgr)
                return -EINVAL;
 
+       if (hwmgr->smumgr_funcs && hwmgr->smumgr_funcs->start_smu) {
+               if (hwmgr->smumgr_funcs->start_smu(hwmgr)) {
+                       pr_err("smc start failed\n");
+                       return -EINVAL;
+               }
+       }
+
+       if (!hwmgr->pm_en)
+               return 0;
+
        ret = phm_setup_asic(hwmgr);
        if (ret)
                return ret;
@@ -270,9 +313,6 @@ int hwmgr_hw_resume(struct pp_hwmgr *hwmgr)
        if (ret)
                return ret;
        ret = phm_start_thermal_controller(hwmgr);
-       if (ret)
-               return ret;
-
        ret |= psm_set_performance_states(hwmgr);
        if (ret)
                return ret;
drivers/gpu/drm/amd/powerplay/inc/hwmgr.h +5 -3
index 17f811d..d6c9a3b 100644
@@ -782,10 +782,13 @@ struct pp_hwmgr {
 };
 
 int hwmgr_early_init(struct pp_hwmgr *hwmgr);
+int hwmgr_sw_init(struct pp_hwmgr *hwmgr);
+int hwmgr_sw_fini(struct pp_hwmgr *hwmgr);
 int hwmgr_hw_init(struct pp_hwmgr *hwmgr);
 int hwmgr_hw_fini(struct pp_hwmgr *hwmgr);
-int hwmgr_hw_suspend(struct pp_hwmgr *hwmgr);
-int hwmgr_hw_resume(struct pp_hwmgr *hwmgr);
+int hwmgr_suspend(struct pp_hwmgr *hwmgr);
+int hwmgr_resume(struct pp_hwmgr *hwmgr);
+
 int hwmgr_handle_task(struct pp_hwmgr *hwmgr,
                                enum amd_pp_task task_id,
                                enum amd_pm_state_type *user_state);
--

1.9.1

Quoted 4 lines
Quoted 4 lines

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

#8 lore raw

Re: [PATCH 2/6] drm/amd/pp: Add hwmgr_sw_init/fini functioins

In reply to a message not in the archive
Quoted 11 lines · Alex Deucher
Quoted 7 lines · Alex Deucher
Quoted 4 lines · Rex Zhu

Clean up pp ip functions

Change-Id Id06159202edabdfcb19fcc20e1291ce93db56d5d

Actually, doesn't this patch have a dependency on patch 3? I think this part of patch 3:

Sorry, patch 4.

Quoted 977 lines

+ hwmgr->pm_en = (amdgpu_dpm && hwmgr->not_vf) ? true : false;
should be in this patch rather than the other patch. With that fixed:

Quoted 973 lines
Quoted 973 lines
---
 drivers/gpu/drm/amd/powerplay/amd_powerplay.c | 368 ++++++--------------------
 drivers/gpu/drm/amd/powerplay/hwmgr/hwmgr.c   |  74 ++++--
 drivers/gpu/drm/amd/powerplay/inc/hwmgr.h     |   7 +-
 3 files changed, 145 insertions(+), 304 deletions(-)
drivers/gpu/drm/amd/powerplay/amd_powerplay.c +83 -285
index 7e8ad30..5d7d9ec 100644
@@ -31,24 +31,11 @@
 #include "amdgpu.h"
 #include "hwmgr.h"
 
-#define PP_DPM_DISABLED 0xCCCC
-
 static int pp_dpm_dispatch_tasks(void *handle, enum amd_pp_task task_id,
                enum amd_pm_state_type *user_state);
 
 static const struct amd_pm_funcs pp_dpm_funcs;
 
-static inline int pp_check(struct pp_hwmgr *hwmgr)
-{
-       if (hwmgr == NULL || hwmgr->smumgr_funcs == NULL)
-               return -EINVAL;
-
-       if (hwmgr->pm_en == 0 || hwmgr->hwmgr_func == NULL)
-               return PP_DPM_DISABLED;
-
-       return 0;
-}
-
 static int amd_powerplay_create(struct amdgpu_device *adev)
 {
        struct pp_hwmgr *hwmgr;
@@ -73,7 +60,7 @@ static int amd_powerplay_create(struct amdgpu_device *adev)
 }
 
 
-static int amd_powerplay_destroy(struct amdgpu_device *adev)
+static void amd_powerplay_destroy(struct amdgpu_device *adev)
 {
        struct pp_hwmgr *hwmgr = adev->powerplay.pp_handle;
 
@@ -82,8 +69,6 @@ static int amd_powerplay_destroy(struct amdgpu_device *adev)
 
        kfree(hwmgr);
        hwmgr = NULL;
-
-       return 0;
 }
 
 static int pp_early_init(void *handle)
@@ -109,18 +94,9 @@ static int pp_sw_init(void *handle)
        struct pp_hwmgr *hwmgr = adev->powerplay.pp_handle;
        int ret = 0;
 
-       ret = pp_check(hwmgr);
-
-       if (ret >= 0) {
-               if (hwmgr->smumgr_funcs->smu_init == NULL)
-                       return -EINVAL;
+       ret = hwmgr_sw_init(hwmgr);
 
-               ret = hwmgr->smumgr_funcs->smu_init(hwmgr);
-
-               phm_register_irq_handlers(hwmgr);
-
-               pr_debug("amdgpu: powerplay sw initialized\n");
-       }
+       pr_debug("amdgpu: powerplay sw init %s\n", ret ? "failed" : "successfully");
 
        return ret;
 }
@@ -129,13 +105,8 @@ static int pp_sw_fini(void *handle)
 {
        struct amdgpu_device *adev = handle;
        struct pp_hwmgr *hwmgr = adev->powerplay.pp_handle;
-       int ret = 0;
 
-       ret = pp_check(hwmgr);
-       if (ret >= 0) {
-               if (hwmgr->smumgr_funcs->smu_fini != NULL)
-                       hwmgr->smumgr_funcs->smu_fini(hwmgr);
-       }
+       hwmgr_sw_fini(hwmgr);
 
        if (adev->firmware.load_type == AMDGPU_FW_LOAD_SMU)
                amdgpu_ucode_fini_bo(adev);
@@ -152,40 +123,20 @@ static int pp_hw_init(void *handle)
        if (adev->firmware.load_type == AMDGPU_FW_LOAD_SMU)
                amdgpu_ucode_init_bo(adev);
 
-       ret = pp_check(hwmgr);
+       ret = hwmgr_hw_init(hwmgr);
 
-       if (ret >= 0) {
-               if (hwmgr->smumgr_funcs->start_smu == NULL)
-                       return -EINVAL;
+       if (ret)
+               pr_err("amdgpu: powerplay hw init failed\n");
 
-               if (hwmgr->smumgr_funcs->start_smu(hwmgr)) {
-                       pr_err("smc start failed\n");
-                       hwmgr->smumgr_funcs->smu_fini(hwmgr);
-                       return -EINVAL;
-               }
-               if (ret == PP_DPM_DISABLED)
-                       goto exit;
-               ret = hwmgr_hw_init(hwmgr);
-               if (ret)
-                       goto exit;
-       }
        return ret;
-exit:
-       hwmgr->pm_en = 0;
-       cgs_notify_dpm_enabled(hwmgr->device, false);
-       return 0;
-
 }
 
 static int pp_hw_fini(void *handle)
 {
        struct amdgpu_device *adev = handle;
        struct pp_hwmgr *hwmgr = adev->powerplay.pp_handle;
-       int ret = 0;
 
-       ret = pp_check(hwmgr);
-       if (ret == 0)
-               hwmgr_hw_fini(hwmgr);
+       hwmgr_hw_fini(hwmgr);
 
        return 0;
 }
@@ -194,11 +145,8 @@ static int pp_late_init(void *handle)
 {
        struct amdgpu_device *adev = handle;
        struct pp_hwmgr *hwmgr = adev->powerplay.pp_handle;
-       int ret = 0;
-
-       ret = pp_check(hwmgr);
 
-       if (ret == 0)
+       if (hwmgr && hwmgr->pm_en)
                pp_dpm_dispatch_tasks(hwmgr,
                                        AMD_PP_TASK_COMPLETE_INIT, NULL);
 
@@ -233,12 +181,9 @@ static int pp_set_powergating_state(void *handle,
 {
        struct amdgpu_device *adev = handle;
        struct pp_hwmgr *hwmgr = adev->powerplay.pp_handle;
-       int ret = 0;
 
-       ret = pp_check(hwmgr);
-
-       if (ret)
-               return ret;
+       if (!hwmgr || !hwmgr->pm_en)
+               return 0;
 
        if (hwmgr->hwmgr_func->enable_per_cu_power_gating == NULL) {
                pr_info("%s was not implemented.\n", __func__);
@@ -254,38 +199,16 @@ static int pp_suspend(void *handle)
 {
        struct amdgpu_device *adev = handle;
        struct pp_hwmgr *hwmgr = adev->powerplay.pp_handle;
-       int ret = 0;
 
-       ret = pp_check(hwmgr);
-       if (ret == 0)
-               hwmgr_hw_suspend(hwmgr);
-       return 0;
+       return hwmgr_suspend(hwmgr);
 }
 
 static int pp_resume(void *handle)
 {
        struct amdgpu_device *adev = handle;
        struct pp_hwmgr *hwmgr = adev->powerplay.pp_handle;
-       int ret;
-
-       ret = pp_check(hwmgr);
-
-       if (ret < 0)
-               return ret;
-
-       if (hwmgr->smumgr_funcs->start_smu == NULL)
-               return -EINVAL;
-
-       if (hwmgr->smumgr_funcs->start_smu(hwmgr)) {
-               pr_err("smc start failed\n");
-               hwmgr->smumgr_funcs->smu_fini(hwmgr);
-               return -EINVAL;
-       }
-
-       if (ret == PP_DPM_DISABLED)
-               return 0;
 
-       return hwmgr_hw_resume(hwmgr);
+       return hwmgr_resume(hwmgr);
 }
 
 static int pp_set_clockgating_state(void *handle,
@@ -334,12 +257,9 @@ static int pp_dpm_fw_loading_complete(void *handle)
 static int pp_set_clockgating_by_smu(void *handle, uint32_t msg_id)
 {
        struct pp_hwmgr *hwmgr = handle;
-       int ret = 0;
-
-       ret = pp_check(hwmgr);
 
-       if (ret)
-               return ret;
+       if (!hwmgr || !hwmgr->pm_en)
+               return -EINVAL;
 
        if (hwmgr->hwmgr_func->update_clock_gatings == NULL) {
                pr_info("%s was not implemented.\n", __func__);
@@ -389,12 +309,9 @@ static int pp_dpm_force_performance_level(void *handle,
                                        enum amd_dpm_forced_level level)
 {
        struct pp_hwmgr *hwmgr = handle;
-       int ret = 0;
 
-       ret = pp_check(hwmgr);
-
-       if (ret)
-               return ret;
+       if (!hwmgr || !hwmgr->pm_en)
+               return -EINVAL;
 
        if (level == hwmgr->dpm_level)
                return 0;
@@ -412,13 +329,10 @@ static enum amd_dpm_forced_level pp_dpm_get_performance_level(
                                                                void *handle)
 {
        struct pp_hwmgr *hwmgr = handle;
-       int ret = 0;
        enum amd_dpm_forced_level level;
 
-       ret = pp_check(hwmgr);
-
-       if (ret)
-               return ret;
+       if (!hwmgr || !hwmgr->pm_en)
+               return -EINVAL;
 
        mutex_lock(&hwmgr->smu_lock);
        level = hwmgr->dpm_level;
@@ -429,13 +343,10 @@ static enum amd_dpm_forced_level pp_dpm_get_performance_level(
 static uint32_t pp_dpm_get_sclk(void *handle, bool low)
 {
        struct pp_hwmgr *hwmgr = handle;
-       int ret = 0;
        uint32_t clk = 0;
 
-       ret = pp_check(hwmgr);
-
-       if (ret)
-               return ret;
+       if (!hwmgr || !hwmgr->pm_en)
+               return 0;
 
        if (hwmgr->hwmgr_func->get_sclk == NULL) {
                pr_info("%s was not implemented.\n", __func__);
@@ -450,13 +361,10 @@ static uint32_t pp_dpm_get_sclk(void *handle, bool low)
 static uint32_t pp_dpm_get_mclk(void *handle, bool low)
 {
        struct pp_hwmgr *hwmgr = handle;
-       int ret = 0;
        uint32_t clk = 0;
 
-       ret = pp_check(hwmgr);
-
-       if (ret)
-               return ret;
+       if (!hwmgr || !hwmgr->pm_en)
+               return 0;
 
        if (hwmgr->hwmgr_func->get_mclk == NULL) {
                pr_info("%s was not implemented.\n", __func__);
@@ -471,11 +379,8 @@ static uint32_t pp_dpm_get_mclk(void *handle, bool low)
 static void pp_dpm_powergate_vce(void *handle, bool gate)
 {
        struct pp_hwmgr *hwmgr = handle;
-       int ret = 0;
-
-       ret = pp_check(hwmgr);
 
-       if (ret)
+       if (!hwmgr || !hwmgr->pm_en)
                return;
 
        if (hwmgr->hwmgr_func->powergate_vce == NULL) {
@@ -490,11 +395,8 @@ static void pp_dpm_powergate_vce(void *handle, bool gate)
 static void pp_dpm_powergate_uvd(void *handle, bool gate)
 {
        struct pp_hwmgr *hwmgr = handle;
-       int ret = 0;
-
-       ret = pp_check(hwmgr);
 
-       if (ret)
+       if (!hwmgr || !hwmgr->pm_en)
                return;
 
        if (hwmgr->hwmgr_func->powergate_uvd == NULL) {
@@ -512,10 +414,8 @@ static int pp_dpm_dispatch_tasks(void *handle, enum amd_pp_task task_id,
        int ret = 0;
        struct pp_hwmgr *hwmgr = handle;
 
-       ret = pp_check(hwmgr);
-
-       if (ret)
-               return ret;
+       if (!hwmgr || !hwmgr->pm_en)
+               return -EINVAL;
 
        mutex_lock(&hwmgr->smu_lock);
        ret = hwmgr_handle_task(hwmgr, task_id, user_state);
@@ -528,15 +428,9 @@ static enum amd_pm_state_type pp_dpm_get_current_power_state(void *handle)
 {
        struct pp_hwmgr *hwmgr = handle;
        struct pp_power_state *state;
-       int ret = 0;
        enum amd_pm_state_type pm_type;
 
-       ret = pp_check(hwmgr);
-
-       if (ret)
-               return ret;
-
-       if (hwmgr->current_ps == NULL)
+       if (!hwmgr || !hwmgr->pm_en || !hwmgr->current_ps)
                return -EINVAL;
 
        mutex_lock(&hwmgr->smu_lock);
@@ -568,11 +462,8 @@ static enum amd_pm_state_type pp_dpm_get_current_power_state(void *handle)
 static void pp_dpm_set_fan_control_mode(void *handle, uint32_t mode)
 {
        struct pp_hwmgr *hwmgr = handle;
-       int ret = 0;
-
-       ret = pp_check(hwmgr);
 
-       if (ret)
+       if (!hwmgr || !hwmgr->pm_en)
                return;
 
        if (hwmgr->hwmgr_func->set_fan_control_mode == NULL) {
@@ -587,13 +478,10 @@ static void pp_dpm_set_fan_control_mode(void *handle, uint32_t mode)
 static uint32_t pp_dpm_get_fan_control_mode(void *handle)
 {
        struct pp_hwmgr *hwmgr = handle;
-       int ret = 0;
        uint32_t mode = 0;
 
-       ret = pp_check(hwmgr);
-
-       if (ret)
-               return ret;
+       if (!hwmgr || !hwmgr->pm_en)
+               return 0;
 
        if (hwmgr->hwmgr_func->get_fan_control_mode == NULL) {
                pr_info("%s was not implemented.\n", __func__);
@@ -610,10 +498,8 @@ static int pp_dpm_set_fan_speed_percent(void *handle, uint32_t percent)
        struct pp_hwmgr *hwmgr = handle;
        int ret = 0;
 
-       ret = pp_check(hwmgr);
-
-       if (ret)
-               return ret;
+       if (!hwmgr || !hwmgr->pm_en)
+               return -EINVAL;
 
        if (hwmgr->hwmgr_func->set_fan_speed_percent == NULL) {
                pr_info("%s was not implemented.\n", __func__);
@@ -630,10 +516,8 @@ static int pp_dpm_get_fan_speed_percent(void *handle, uint32_t *speed)
        struct pp_hwmgr *hwmgr = handle;
        int ret = 0;
 
-       ret = pp_check(hwmgr);
-
-       if (ret)
-               return ret;
+       if (!hwmgr || !hwmgr->pm_en)
+               return -EINVAL;
 
        if (hwmgr->hwmgr_func->get_fan_speed_percent == NULL) {
                pr_info("%s was not implemented.\n", __func__);
@@ -651,10 +535,8 @@ static int pp_dpm_get_fan_speed_rpm(void *handle, uint32_t *rpm)
        struct pp_hwmgr *hwmgr = handle;
        int ret = 0;
 
-       ret = pp_check(hwmgr);
-
-       if (ret)
-               return ret;
+       if (!hwmgr || !hwmgr->pm_en)
+               return -EINVAL;
 
        if (hwmgr->hwmgr_func->get_fan_speed_rpm == NULL)
                return -EINVAL;
@@ -670,16 +552,10 @@ static int pp_dpm_get_pp_num_states(void *handle,
 {
        struct pp_hwmgr *hwmgr = handle;
        int i;
-       int ret = 0;
 
        memset(data, 0, sizeof(*data));
 
-       ret = pp_check(hwmgr);
-
-       if (ret)
-               return ret;
-
-       if (hwmgr->ps == NULL)
+       if (!hwmgr || !hwmgr->pm_en ||!hwmgr->ps)
                return -EINVAL;
 
        mutex_lock(&hwmgr->smu_lock);
@@ -713,15 +589,9 @@ static int pp_dpm_get_pp_num_states(void *handle,
 static int pp_dpm_get_pp_table(void *handle, char **table)
 {
        struct pp_hwmgr *hwmgr = handle;
-       int ret = 0;
        int size = 0;
 
-       ret = pp_check(hwmgr);
-
-       if (ret)
-               return ret;
-
-       if (!hwmgr->soft_pp_table)
+       if (!hwmgr || !hwmgr->pm_en ||!hwmgr->soft_pp_table)
                return -EINVAL;
 
        mutex_lock(&hwmgr->smu_lock);
@@ -736,10 +606,6 @@ static int amd_powerplay_reset(void *handle)
        struct pp_hwmgr *hwmgr = handle;
        int ret;
 
-       ret = pp_check(hwmgr);
-       if (ret)
-               return ret;
-
        ret = hwmgr_hw_fini(hwmgr);
        if (ret)
                return ret;
@@ -756,10 +622,8 @@ static int pp_dpm_set_pp_table(void *handle, const char *buf, size_t size)
        struct pp_hwmgr *hwmgr = handle;
        int ret = 0;
 
-       ret = pp_check(hwmgr);
-
-       if (ret)
-               return ret;
+       if (!hwmgr || !hwmgr->pm_en)
+               return -EINVAL;
 
        mutex_lock(&hwmgr->smu_lock);
        if (!hwmgr->hardcode_pp_table) {
@@ -796,10 +660,8 @@ static int pp_dpm_force_clock_level(void *handle,
        struct pp_hwmgr *hwmgr = handle;
        int ret = 0;
 
-       ret = pp_check(hwmgr);
-
-       if (ret)
-               return ret;
+       if (!hwmgr || !hwmgr->pm_en)
+               return -EINVAL;
 
        if (hwmgr->hwmgr_func->force_clock_level == NULL) {
                pr_info("%s was not implemented.\n", __func__);
@@ -820,10 +682,8 @@ static int pp_dpm_print_clock_levels(void *handle,
        struct pp_hwmgr *hwmgr = handle;
        int ret = 0;
 
-       ret = pp_check(hwmgr);
-
-       if (ret)
-               return ret;
+       if (!hwmgr || !hwmgr->pm_en)
+               return -EINVAL;
 
        if (hwmgr->hwmgr_func->print_clock_levels == NULL) {
                pr_info("%s was not implemented.\n", __func__);
@@ -840,10 +700,8 @@ static int pp_dpm_get_sclk_od(void *handle)
        struct pp_hwmgr *hwmgr = handle;
        int ret = 0;
 
-       ret = pp_check(hwmgr);
-
-       if (ret)
-               return ret;
+       if (!hwmgr || !hwmgr->pm_en)
+               return -EINVAL;
 
        if (hwmgr->hwmgr_func->get_sclk_od == NULL) {
                pr_info("%s was not implemented.\n", __func__);
@@ -860,10 +718,8 @@ static int pp_dpm_set_sclk_od(void *handle, uint32_t value)
        struct pp_hwmgr *hwmgr = handle;
        int ret = 0;
 
-       ret = pp_check(hwmgr);
-
-       if (ret)
-               return ret;
+       if (!hwmgr || !hwmgr->pm_en)
+               return -EINVAL;
 
        if (hwmgr->hwmgr_func->set_sclk_od == NULL) {
                pr_info("%s was not implemented.\n", __func__);
@@ -881,10 +737,8 @@ static int pp_dpm_get_mclk_od(void *handle)
        struct pp_hwmgr *hwmgr = handle;
        int ret = 0;
 
-       ret = pp_check(hwmgr);
-
-       if (ret)
-               return ret;
+       if (!hwmgr || !hwmgr->pm_en)
+               return -EINVAL;
 
        if (hwmgr->hwmgr_func->get_mclk_od == NULL) {
                pr_info("%s was not implemented.\n", __func__);
@@ -901,10 +755,8 @@ static int pp_dpm_set_mclk_od(void *handle, uint32_t value)
        struct pp_hwmgr *hwmgr = handle;
        int ret = 0;
 
-       ret = pp_check(hwmgr);
-
-       if (ret)
-               return ret;
+       if (!hwmgr || !hwmgr->pm_en)
+               return -EINVAL;
 
        if (hwmgr->hwmgr_func->set_mclk_od == NULL) {
                pr_info("%s was not implemented.\n", __func__);
@@ -922,11 +774,7 @@ static int pp_dpm_read_sensor(void *handle, int idx,
        struct pp_hwmgr *hwmgr = handle;
        int ret = 0;
 
-       ret = pp_check(hwmgr);
-       if (ret)
-               return ret;
-
-       if (value == NULL)
+       if (!hwmgr || !hwmgr->pm_en || !value)
                return -EINVAL;
 
        switch (idx) {
@@ -948,14 +796,11 @@ static int pp_dpm_read_sensor(void *handle, int idx,
 pp_dpm_get_vce_clock_state(void *handle, unsigned idx)
 {
        struct pp_hwmgr *hwmgr = handle;
-       int ret = 0;
-
-       ret = pp_check(hwmgr);
 
-       if (ret)
+       if (!hwmgr || !hwmgr->pm_en)
                return NULL;
 
-       if (hwmgr && idx < hwmgr->num_vce_state_tables)
+       if (idx < hwmgr->num_vce_state_tables)
                return &hwmgr->vce_states[idx];
        return NULL;
 }
@@ -964,7 +809,7 @@ static int pp_get_power_profile_mode(void *handle, char *buf)
 {
        struct pp_hwmgr *hwmgr = handle;
 
-       if (!buf || pp_check(hwmgr))
+       if (!hwmgr || !hwmgr->pm_en || !buf)
                return -EINVAL;
 
        if (hwmgr->hwmgr_func->get_power_profile_mode == NULL) {
@@ -980,12 +825,12 @@ static int pp_set_power_profile_mode(void *handle, long *input, uint32_t size)
        struct pp_hwmgr *hwmgr = handle;
        int ret = -EINVAL;
 
-       if (pp_check(hwmgr))
-               return -EINVAL;
+       if (!hwmgr || !hwmgr->pm_en)
+               return ret;
 
        if (hwmgr->hwmgr_func->set_power_profile_mode == NULL) {
                pr_info("%s was not implemented.\n", __func__);
-               return -EINVAL;
+               return ret;
        }
        mutex_lock(&hwmgr->smu_lock);
        if (hwmgr->dpm_level == AMD_DPM_FORCED_LEVEL_MANUAL)
@@ -998,7 +843,7 @@ static int pp_odn_edit_dpm_table(void *handle, uint32_t type, long *input, uint3
 {
        struct pp_hwmgr *hwmgr = handle;
 
-       if (pp_check(hwmgr))
+       if (!hwmgr || !hwmgr->pm_en)
                return -EINVAL;
 
        if (hwmgr->hwmgr_func->odn_edit_dpm_table == NULL) {
@@ -1016,7 +861,7 @@ static int pp_dpm_switch_power_profile(void *handle,
        long workload;
        uint32_t index;
 
-       if (pp_check(hwmgr))
+       if (!hwmgr || !hwmgr->pm_en)
                return -EINVAL;
 
        if (hwmgr->hwmgr_func->set_power_profile_mode == NULL) {
@@ -1058,10 +903,8 @@ static int pp_dpm_notify_smu_memory_info(void *handle,
        struct pp_hwmgr *hwmgr = handle;
        int ret = 0;
 
-       ret = pp_check(hwmgr);
-
-       if (ret)
-               return ret;
+       if (!hwmgr || !hwmgr->pm_en)
+               return -EINVAL;
 
        if (hwmgr->hwmgr_func->notify_cac_buffer_info == NULL) {
                pr_info("%s was not implemented.\n", __func__);
@@ -1082,12 +925,9 @@ static int pp_dpm_notify_smu_memory_info(void *handle,
 static int pp_set_power_limit(void *handle, uint32_t limit)
 {
        struct pp_hwmgr *hwmgr = handle;
-       int ret = 0;
-
-       ret = pp_check(hwmgr);
 
-       if (ret)
-               return ret;
+       if (!hwmgr || !hwmgr->pm_en)
+               return -EINVAL;
 
        if (hwmgr->hwmgr_func->set_power_limit == NULL) {
                pr_info("%s was not implemented.\n", __func__);
@@ -1104,20 +944,14 @@ static int pp_set_power_limit(void *handle, uint32_t limit)
        hwmgr->hwmgr_func->set_power_limit(hwmgr, limit);
        hwmgr->power_limit = limit;
        mutex_unlock(&hwmgr->smu_lock);
-       return ret;
+       return 0;
 }
 
 static int pp_get_power_limit(void *handle, uint32_t *limit, bool default_limit)
 {
        struct pp_hwmgr *hwmgr = handle;
-       int ret = 0;
-
-       ret = pp_check(hwmgr);
 
-       if (ret)
-               return ret;
-
-       if (limit == NULL)
+       if (!hwmgr || !hwmgr->pm_en ||!limit)
                return -EINVAL;
 
        mutex_lock(&hwmgr->smu_lock);
@@ -1129,19 +963,16 @@ static int pp_get_power_limit(void *handle, uint32_t *limit, bool default_limit)
 
        mutex_unlock(&hwmgr->smu_lock);
 
-       return ret;
+       return 0;
 }
 
 static int pp_display_configuration_change(void *handle,
        const struct amd_pp_display_configuration *display_config)
 {
        struct pp_hwmgr *hwmgr = handle;
-       int ret = 0;
-
-       ret = pp_check(hwmgr);
 
-       if (ret)
-               return ret;
+       if (!hwmgr || !hwmgr->pm_en)
+               return -EINVAL;
 
        mutex_lock(&hwmgr->smu_lock);
        phm_store_dal_configuration_data(hwmgr, display_config);
@@ -1155,12 +986,7 @@ static int pp_get_display_power_level(void *handle,
        struct pp_hwmgr *hwmgr = handle;
        int ret = 0;
 
-       ret = pp_check(hwmgr);
-
-       if (ret)
-               return ret;
-
-       if (output == NULL)
+       if (!hwmgr || !hwmgr->pm_en ||!output)
                return -EINVAL;
 
        mutex_lock(&hwmgr->smu_lock);
@@ -1177,10 +1003,8 @@ static int pp_get_current_clocks(void *handle,
        struct pp_hwmgr *hwmgr = handle;
        int ret = 0;
 
-       ret = pp_check(hwmgr);
-
-       if (ret)
-               return ret;
+       if (!hwmgr || !hwmgr->pm_en)
+               return -EINVAL;
 
        mutex_lock(&hwmgr->smu_lock);
 
@@ -1225,10 +1049,8 @@ static int pp_get_clock_by_type(void *handle, enum amd_pp_clock_type type, struc
        struct pp_hwmgr *hwmgr = handle;
        int ret = 0;
 
-       ret = pp_check(hwmgr);
-
-       if (ret)
-               return ret;
+       if (!hwmgr || !hwmgr->pm_en)
+               return -EINVAL;
 
        if (clocks == NULL)
                return -EINVAL;
@@ -1246,11 +1068,7 @@ static int pp_get_clock_by_type_with_latency(void *handle,
        struct pp_hwmgr *hwmgr = handle;
        int ret = 0;
 
-       ret = pp_check(hwmgr);
-       if (ret)
-               return ret;
-
-       if (!clocks)
+       if (!hwmgr || !hwmgr->pm_en ||!clocks)
                return -EINVAL;
 
        mutex_lock(&hwmgr->smu_lock);
@@ -1266,11 +1084,7 @@ static int pp_get_clock_by_type_with_voltage(void *handle,
        struct pp_hwmgr *hwmgr = handle;
        int ret = 0;
 
-       ret = pp_check(hwmgr);
-       if (ret)
-               return ret;
-
-       if (!clocks)
+       if (!hwmgr || !hwmgr->pm_en ||!clocks)
                return -EINVAL;
 
        mutex_lock(&hwmgr->smu_lock);
@@ -1287,11 +1101,7 @@ static int pp_set_watermarks_for_clocks_ranges(void *handle,
        struct pp_hwmgr *hwmgr = handle;
        int ret = 0;
 
-       ret = pp_check(hwmgr);
-       if (ret)
-               return ret;
-
-       if (!wm_with_clock_ranges)
+       if (!hwmgr || !hwmgr->pm_en ||!wm_with_clock_ranges)
                return -EINVAL;
 
        mutex_lock(&hwmgr->smu_lock);
@@ -1308,11 +1118,7 @@ static int pp_display_clock_voltage_request(void *handle,
        struct pp_hwmgr *hwmgr = handle;
        int ret = 0;
 
-       ret = pp_check(hwmgr);
-       if (ret)
-               return ret;
-
-       if (!clock)
+       if (!hwmgr || !hwmgr->pm_en ||!clock)
                return -EINVAL;
 
        mutex_lock(&hwmgr->smu_lock);
@@ -1328,12 +1134,7 @@ static int pp_get_display_mode_validation_clocks(void *handle,
        struct pp_hwmgr *hwmgr = handle;
        int ret = 0;
 
-       ret = pp_check(hwmgr);
-
-       if (ret)
-               return ret;
-
-       if (clocks == NULL)
+       if (!hwmgr || !hwmgr->pm_en ||!clocks)
                return -EINVAL;
 
        mutex_lock(&hwmgr->smu_lock);
@@ -1348,12 +1149,9 @@ static int pp_get_display_mode_validation_clocks(void *handle,
 static int pp_set_mmhub_powergating_by_smu(void *handle)
 {
        struct pp_hwmgr *hwmgr = handle;
-       int ret = 0;
-
-       ret = pp_check(hwmgr);
 
-       if (ret)
-               return ret;
+       if (!hwmgr || !hwmgr->pm_en)
+               return -EINVAL;
 
        if (hwmgr->hwmgr_func->set_mmhub_powergating_by_smu == NULL) {
                pr_info("%s was not implemented.\n", __func__);
drivers/gpu/drm/amd/powerplay/hwmgr/hwmgr.c +57 -17
index 4298205..96a2d01 100644
@@ -76,7 +76,7 @@ static void hwmgr_init_workload_prority(struct pp_hwmgr *hwmgr)
 
 int hwmgr_early_init(struct pp_hwmgr *hwmgr)
 {
-       if (hwmgr == NULL)
+       if (!hwmgr)
                return -EINVAL;
 
        hwmgr->usec_timeout = AMD_MAX_USEC_TIMEOUT;
@@ -170,17 +170,51 @@ int hwmgr_early_init(struct pp_hwmgr *hwmgr)
        return 0;
 }
 
+int hwmgr_sw_init(struct pp_hwmgr *hwmgr)
+{
+       if (!hwmgr|| !hwmgr->smumgr_funcs || !hwmgr->smumgr_funcs->smu_init)
+               return -EINVAL;
+
+       phm_register_irq_handlers(hwmgr);
+
+       return hwmgr->smumgr_funcs->smu_init(hwmgr);
+}
+
+
+int hwmgr_sw_fini(struct pp_hwmgr *hwmgr)
+{
+       if (hwmgr && hwmgr->smumgr_funcs && hwmgr->smumgr_funcs->smu_fini)
+               hwmgr->smumgr_funcs->smu_fini(hwmgr);
+
+       return 0;
+}
+
 int hwmgr_hw_init(struct pp_hwmgr *hwmgr)
 {
        int ret = 0;
 
-       if (hwmgr == NULL)
+       if (!hwmgr || !hwmgr->smumgr_funcs)
                return -EINVAL;
 
-       if (hwmgr->pptable_func == NULL ||
-           hwmgr->pptable_func->pptable_init == NULL ||
-           hwmgr->hwmgr_func->backend_init == NULL)
-               return -EINVAL;
+       if (hwmgr->smumgr_funcs->start_smu) {
+               ret = hwmgr->smumgr_funcs->start_smu(hwmgr);
+               if (ret) {
+                       pr_err("smc start failed\n");
+                       return -EINVAL;
+               }
+       }
+
+       if (!hwmgr->pm_en)
+               return 0;
+
+       if (!hwmgr->pptable_func ||
+           !hwmgr->pptable_func->pptable_init ||
+           !hwmgr->hwmgr_func->backend_init) {
+               hwmgr->pm_en = false;
+               cgs_notify_dpm_enabled(hwmgr->device, false);
+               pr_info("dpm not supported \n");
+               return 0;
+       }
 
        ret = hwmgr->pptable_func->pptable_init(hwmgr);
        if (ret)
@@ -214,14 +248,13 @@ int hwmgr_hw_init(struct pp_hwmgr *hwmgr)
        if (hwmgr->pptable_func->pptable_fini)
                hwmgr->pptable_func->pptable_fini(hwmgr);
 err:
-       pr_err("amdgpu: powerplay initialization failed\n");
        return ret;
 }
 
 int hwmgr_hw_fini(struct pp_hwmgr *hwmgr)
 {
-       if (hwmgr == NULL)
-               return -EINVAL;
+       if (!hwmgr || !hwmgr->pm_en)
+               return 0;
 
        phm_stop_thermal_controller(hwmgr);
        psm_set_boot_states(hwmgr);
@@ -236,12 +269,12 @@ int hwmgr_hw_fini(struct pp_hwmgr *hwmgr)
        return psm_fini_power_state_table(hwmgr);
 }
 
-int hwmgr_hw_suspend(struct pp_hwmgr *hwmgr)
+int hwmgr_suspend(struct pp_hwmgr *hwmgr)
 {
        int ret = 0;
 
-       if (hwmgr == NULL)
-               return -EINVAL;
+       if (!hwmgr || !hwmgr->pm_en)
+               return 0;
 
        phm_disable_smc_firmware_ctf(hwmgr);
        ret = psm_set_boot_states(hwmgr);
@@ -255,13 +288,23 @@ int hwmgr_hw_suspend(struct pp_hwmgr *hwmgr)
        return ret;
 }
 
-int hwmgr_hw_resume(struct pp_hwmgr *hwmgr)
+int hwmgr_resume(struct pp_hwmgr *hwmgr)
 {
        int ret = 0;
 
-       if (hwmgr == NULL)
+       if (!hwmgr)
                return -EINVAL;
 
+       if (hwmgr->smumgr_funcs && hwmgr->smumgr_funcs->start_smu) {
+               if (hwmgr->smumgr_funcs->start_smu(hwmgr)) {
+                       pr_err("smc start failed\n");
+                       return -EINVAL;
+               }
+       }
+
+       if (!hwmgr->pm_en)
+               return 0;
+
        ret = phm_setup_asic(hwmgr);
        if (ret)
                return ret;
@@ -270,9 +313,6 @@ int hwmgr_hw_resume(struct pp_hwmgr *hwmgr)
        if (ret)
                return ret;
        ret = phm_start_thermal_controller(hwmgr);
-       if (ret)
-               return ret;
-
        ret |= psm_set_performance_states(hwmgr);
        if (ret)
                return ret;
drivers/gpu/drm/amd/powerplay/inc/hwmgr.h +5 -3
index 17f811d..d6c9a3b 100644
@@ -782,10 +782,13 @@ struct pp_hwmgr {
 };
 
 int hwmgr_early_init(struct pp_hwmgr *hwmgr);
+int hwmgr_sw_init(struct pp_hwmgr *hwmgr);
+int hwmgr_sw_fini(struct pp_hwmgr *hwmgr);
 int hwmgr_hw_init(struct pp_hwmgr *hwmgr);
 int hwmgr_hw_fini(struct pp_hwmgr *hwmgr);
-int hwmgr_hw_suspend(struct pp_hwmgr *hwmgr);
-int hwmgr_hw_resume(struct pp_hwmgr *hwmgr);
+int hwmgr_suspend(struct pp_hwmgr *hwmgr);
+int hwmgr_resume(struct pp_hwmgr *hwmgr);
+
 int hwmgr_handle_task(struct pp_hwmgr *hwmgr,
                                enum amd_pp_task task_id,
                                enum amd_pm_state_type *user_state);
--

1.9.1

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

#15 lore raw

Re: [PATCH 3/6] drm/amd/pp: Lock powerplay when reset pp table

In reply to a message not in the archive
Quoted 2 lines · Rex Zhu
Change-Id Ib02cd71593bee9606822a466a56f2d01ac2e04cc

Please include a commit description. It's not clear to me what's happening here.

Alex

Quoted 82 lines
---
 drivers/gpu/drm/amd/powerplay/amd_powerplay.c | 28 +++++++++++++--------------
 1 file changed, 14 insertions(+), 14 deletions(-)
drivers/gpu/drm/amd/powerplay/amd_powerplay.c +14 -15
index 5d7d9ec..1ae4905 100644
@@ -31,8 +31,6 @@
 #include "amdgpu.h"
 #include "hwmgr.h"
 
-static int pp_dpm_dispatch_tasks(void *handle, enum amd_pp_task task_id,
-               enum amd_pm_state_type *user_state);
 
 static const struct amd_pm_funcs pp_dpm_funcs;
 
@@ -146,10 +144,12 @@ static int pp_late_init(void *handle)
        struct amdgpu_device *adev = handle;
        struct pp_hwmgr *hwmgr = adev->powerplay.pp_handle;
 
-       if (hwmgr && hwmgr->pm_en)
-               pp_dpm_dispatch_tasks(hwmgr,
+       if (hwmgr && hwmgr->pm_en) {
+               mutex_lock(&hwmgr->smu_lock);
+               hwmgr_handle_task(hwmgr,
                                        AMD_PP_TASK_COMPLETE_INIT, NULL);
-
+               mutex_unlock(&hwmgr->smu_lock);
+       }
        return 0;
 }
 
@@ -620,7 +620,7 @@ static int amd_powerplay_reset(void *handle)
 static int pp_dpm_set_pp_table(void *handle, const char *buf, size_t size)
 {
        struct pp_hwmgr *hwmgr = handle;
-       int ret = 0;
+       int ret = -ENOMEM;
 
        if (!hwmgr || !hwmgr->pm_en)
                return -EINVAL;
@@ -630,28 +630,28 @@ static int pp_dpm_set_pp_table(void *handle, const char *buf, size_t size)
                hwmgr->hardcode_pp_table = kmemdup(hwmgr->soft_pp_table,
                                                   hwmgr->soft_pp_table_size,
                                                   GFP_KERNEL);
-               if (!hwmgr->hardcode_pp_table) {
-                       mutex_unlock(&hwmgr->smu_lock);
-                       return -ENOMEM;
-               }
+               if (!hwmgr->hardcode_pp_table)
+                       goto err;
        }
 
        memcpy(hwmgr->hardcode_pp_table, buf, size);
 
        hwmgr->soft_pp_table = hwmgr->hardcode_pp_table;
-       mutex_unlock(&hwmgr->smu_lock);
 
        ret = amd_powerplay_reset(handle);
        if (ret)
-               return ret;
+               goto err;
 
        if (hwmgr->hwmgr_func->avfs_control) {
                ret = hwmgr->hwmgr_func->avfs_control(hwmgr, false);
                if (ret)
-                       return ret;
+                       goto err;
        }
-
+       mutex_unlock(&hwmgr->smu_lock);
        return 0;
+err:
+       mutex_unlock(&hwmgr->smu_lock);
+       return ret;
 }
 
 static int pp_dpm_force_clock_level(void *handle,
--

1.9.1

Quoted 4 lines

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

Reviewed-by
#22 lore raw

Re: [PATCH 4/6] drm/amd/pp: Save vf state in pp context

In reply to a message not in the archive
Quoted 2 lines · Rex Zhu
Change-Id Ic77e961317113942023b25523df6a4399535fb06

Please include a patch description. E.g.,
Store vf state in pp_context so we can deprecate the cgs interface.

Quoted 14 lines
---
 drivers/gpu/drm/amd/powerplay/amd_powerplay.c           |  3 ++-
 drivers/gpu/drm/amd/powerplay/inc/hwmgr.h               |  1 +
 drivers/gpu/drm/amd/powerplay/smumgr/fiji_smumgr.c      |  7 +++----
 drivers/gpu/drm/amd/powerplay/smumgr/polaris10_smumgr.c |  3 +--
 drivers/gpu/drm/amd/powerplay/smumgr/smu7_smumgr.c      | 10 +++++-----
 drivers/gpu/drm/amd/powerplay/smumgr/tonga_smumgr.c     |  3 +--
 6 files changed, 13 insertions(+), 14 deletions(-)
drivers/gpu/drm/amd/powerplay/amd_powerplay.c +0 -0
index 1ae4905..5717859 100644

drivers/gpu/drm/amd/powerplay/amd_powerplay.c static int amd_powerplay_create(struct amdgpu_device *adev) · line 50

Quoted 6 lines
drivers/gpu/drm/amd/powerplay/amd_powerplay.c +2 -1
@@ -46,7 +46,8 @@ static int amd_powerplay_create(struct amdgpu_device *adev)
                return -ENOMEM;
 
        hwmgr->adev = adev;
-       hwmgr->pm_en = (amdgpu_dpm != 0 && !amdgpu_sriov_vf(adev)) ? true : false;
+       hwmgr->not_vf = !amdgpu_sriov_vf(adev);
+       hwmgr->pm_en = (amdgpu_dpm && hwmgr->not_vf) ? true : false;

This should be part of patch 2. With these comments addressed the patch is:

Quoted 120 lines
drivers/gpu/drm/amd/powerplay/amd_powerplay.c +0 -0
        hwmgr->device = amdgpu_cgs_create_device(adev);
        mutex_init(&hwmgr->smu_lock);
        hwmgr->chip_family = adev->family;
drivers/gpu/drm/amd/powerplay/inc/hwmgr.h +1 -0
index d6c9a3b..d5cadc6 100644
@@ -718,6 +718,7 @@ struct pp_hwmgr {
        uint32_t chip_family;
        uint32_t chip_id;
        uint32_t smu_version;
+       bool not_vf;
        bool pm_en;
        struct mutex smu_lock;
 
drivers/gpu/drm/amd/powerplay/smumgr/fiji_smumgr.c +3 -4
index faef783..35b947e 100644
@@ -288,8 +288,7 @@ static int fiji_start_smu(struct pp_hwmgr *hwmgr)
        struct fiji_smumgr *priv = (struct fiji_smumgr *)(hwmgr->smu_backend);
 
        /* Only start SMC if SMC RAM is not running */
-       if (!(smu7_is_smc_ram_running(hwmgr)
-               || cgs_is_virtualization_enabled(hwmgr->device))) {
+       if (!smu7_is_smc_ram_running(hwmgr) && hwmgr->not_vf) {
                /* Check if SMU is running in protected mode */
                if (0 == PHM_READ_VFPF_INDIRECT_FIELD(hwmgr->device,
                                CGS_IND_REG__SMC,
@@ -335,8 +334,8 @@ static bool fiji_is_hw_avfs_present(struct pp_hwmgr *hwmgr)
        uint32_t efuse = 0;
        uint32_t mask = (1 << ((AVFS_EN_MSB - AVFS_EN_LSB) + 1)) - 1;
 
-       if (cgs_is_virtualization_enabled(hwmgr->device))
-               return 0;
+       if (!hwmgr->not_vf)
+               return false;
 
        if (!atomctrl_read_efuse(hwmgr->device, AVFS_EN_LSB, AVFS_EN_MSB,
                        mask, &efuse)) {
drivers/gpu/drm/amd/powerplay/smumgr/polaris10_smumgr.c +1 -2
index 997a777..b861c26 100644
@@ -295,8 +295,7 @@ static int polaris10_start_smu(struct pp_hwmgr *hwmgr)
        struct polaris10_smumgr *smu_data = (struct polaris10_smumgr *)(hwmgr->smu_backend);
 
        /* Only start SMC if SMC RAM is not running */
-       if (!(smu7_is_smc_ram_running(hwmgr)
-               || cgs_is_virtualization_enabled(hwmgr->device))) {
+       if (!smu7_is_smc_ram_running(hwmgr) && hwmgr->not_vf) {
                smu_data->protected_mode = (uint8_t) (PHM_READ_VFPF_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC, SMU_FIRMWARE, SMU_MODE));
                smu_data->smu7_data.security_hard_key = (uint8_t) (PHM_READ_VFPF_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC, SMU_FIRMWARE, SMU_SEL));
 
drivers/gpu/drm/amd/powerplay/smumgr/smu7_smumgr.c +5 -5
index 0399c10..3684822 100644
@@ -375,7 +375,7 @@ static int smu7_populate_single_firmware_entry(struct pp_hwmgr *hwmgr,
                entry->meta_data_addr_low = 0;
 
                /* digest need be excluded out */
-               if (cgs_is_virtualization_enabled(hwmgr->device))
+               if (!hwmgr->not_vf)
                        info.image_size -= 20;
                entry->data_size_byte = info.image_size;
                entry->num_register_entries = 0;
@@ -409,7 +409,7 @@ int smu7_request_smu_load_fw(struct pp_hwmgr *hwmgr)
                                        0x0);
 
        if (hwmgr->chip_id > CHIP_TOPAZ) { /* add support for Topaz */
-               if (!cgs_is_virtualization_enabled(hwmgr->device)) {
+               if (hwmgr->not_vf) {
                        smu7_send_msg_to_smc_with_parameter(hwmgr,
                                                PPSMC_MSG_SMU_DRAM_ADDR_HI,
                                                upper_32_bits(smu_data->smu_buffer.mc_addr));
@@ -467,7 +467,7 @@ int smu7_request_smu_load_fw(struct pp_hwmgr *hwmgr)
        PP_ASSERT_WITH_CODE(0 == smu7_populate_single_firmware_entry(hwmgr,
                                UCODE_ID_SDMA1, &toc->entry[toc->num_entries++]),
                                "Failed to Get Firmware Entry.", return -EINVAL);
-       if (cgs_is_virtualization_enabled(hwmgr->device))
+       if (!hwmgr->not_vf)
                PP_ASSERT_WITH_CODE(0 == smu7_populate_single_firmware_entry(hwmgr,
                                UCODE_ID_MEC_STORAGE, &toc->entry[toc->num_entries++]),
                                "Failed to Get Firmware Entry.", return -EINVAL);
@@ -608,7 +608,7 @@ int smu7_init(struct pp_hwmgr *hwmgr)
        smu_data->header = smu_data->header_buffer.kaddr;
        smu_data->header_buffer.mc_addr = mc_addr;
 
-       if (cgs_is_virtualization_enabled(hwmgr->device))
+       if (!hwmgr->not_vf)
                return 0;
 
        smu_data->smu_buffer.data_size = 200*4096;
@@ -643,7 +643,7 @@ int smu7_smu_fini(struct pp_hwmgr *hwmgr)
                                        &smu_data->header_buffer.mc_addr,
                                        &smu_data->header_buffer.kaddr);
 
-       if (!cgs_is_virtualization_enabled(hwmgr->device))
+       if (hwmgr->not_vf)
                amdgpu_bo_free_kernel(&smu_data->smu_buffer.handle,
                                        &smu_data->smu_buffer.mc_addr,
                                        &smu_data->smu_buffer.kaddr);
drivers/gpu/drm/amd/powerplay/smumgr/tonga_smumgr.c +1 -3
index b51d746..2ba05d2 100644
@@ -199,8 +199,7 @@ static int tonga_start_smu(struct pp_hwmgr *hwmgr)
        int result;
 
        /* Only start SMC if SMC RAM is not running */
-       if (!(smu7_is_smc_ram_running(hwmgr) ||
-               cgs_is_virtualization_enabled(hwmgr->device))) {
+       if (!smu7_is_smc_ram_running(hwmgr) && hwmgr->not_vf) {
                /*Check if SMU is running in protected mode*/
                if (0 == PHM_READ_VFPF_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC,
                                        SMU_FIRMWARE, SMU_MODE)) {
--

1.9.1

Quoted 4 lines

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

Reviewed-by
#25 lore raw

Re: [PATCH 5/6] drm/amd/pp: Use release_firmware function directly in powerplay

In reply to a message not in the archive
Quoted 2 lines · Rex Zhu
Change-Id I7e3c01d0d413bbada67c044b88f2e5f0a53f0b38

Please include a patch description. E.g.,
Use release_firmware directly so we can remove the cgs firmware wrapper.

With that fixed:

Quoted 76 lines
---
 drivers/gpu/drm/amd/powerplay/amd_powerplay.c           | 5 ++++-
 drivers/gpu/drm/amd/powerplay/inc/amd_powerplay.h       | 1 +
 drivers/gpu/drm/amd/powerplay/smumgr/ci_smumgr.c        | 1 -
 drivers/gpu/drm/amd/powerplay/smumgr/polaris10_smumgr.c | 3 ++-
 drivers/gpu/drm/amd/powerplay/smumgr/smu7_smumgr.c      | 1 -
 5 files changed, 7 insertions(+), 4 deletions(-)
drivers/gpu/drm/amd/powerplay/amd_powerplay.c +4 -1
index 5717859..315e25c 100644
@@ -107,8 +107,11 @@ static int pp_sw_fini(void *handle)
 
        hwmgr_sw_fini(hwmgr);
 
-       if (adev->firmware.load_type == AMDGPU_FW_LOAD_SMU)
+       if (adev->firmware.load_type == AMDGPU_FW_LOAD_SMU) {
+               release_firmware(adev->pm.fw);
+               adev->pm.fw = NULL;
                amdgpu_ucode_fini_bo(adev);
+       }
 
        return 0;
 }
drivers/gpu/drm/amd/powerplay/inc/amd_powerplay.h +1 -0
index fe36659..c7d6533 100644
@@ -31,5 +31,6 @@
 #include "dm_pp_interface.h"
 #include "kgd_pp_interface.h"
 #include "amdgpu.h"
+#include <linux/firmware.h>
 
 #endif /* _AMD_POWERPLAY_H_ */
drivers/gpu/drm/amd/powerplay/smumgr/ci_smumgr.c +0 -1
index 08d0001..e30a2ee 100644
@@ -2784,7 +2784,6 @@ static int ci_smu_fini(struct pp_hwmgr *hwmgr)
 {
        kfree(hwmgr->smu_backend);
        hwmgr->smu_backend = NULL;
-       cgs_rel_firmware(hwmgr->device, CGS_UCODE_ID_SMU);
        return 0;
 }
 
drivers/gpu/drm/amd/powerplay/smumgr/polaris10_smumgr.c +2 -1
index b861c26..3e80d61 100644
@@ -308,7 +308,8 @@ static int polaris10_start_smu(struct pp_hwmgr *hwmgr)
                        /* If failed, try with different security Key. */
                        if (result != 0) {
                                smu_data->smu7_data.security_hard_key ^= 1;
-                               cgs_rel_firmware(hwmgr->device, CGS_UCODE_ID_SMU);
+                               release_firmware(((struct amdgpu_device *)hwmgr->adev)->pm.fw);
+                               ((struct amdgpu_device *)hwmgr->adev)->pm.fw = NULL;
                                result = polaris10_start_smu_in_protection_mode(hwmgr);
                        }
                }
drivers/gpu/drm/amd/powerplay/smumgr/smu7_smumgr.c +0 -2
index 3684822..41fab2d 100644
@@ -650,6 +650,5 @@ int smu7_smu_fini(struct pp_hwmgr *hwmgr)
 
        kfree(hwmgr->smu_backend);
        hwmgr->smu_backend = NULL;
-       cgs_rel_firmware(hwmgr->device, CGS_UCODE_ID_SMU);
        return 0;
 }
--

1.9.1

Quoted 4 lines

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

Reviewed-by
#28 lore raw

Re: [PATCH 6/6] drm/amd/pp: Delete some cgs functions

In reply to a message not in the archive
Quoted 2 lines · Rex Zhu
Change-Id If90e946b915a30e14123f9892f12ddcf6c653095

Please include a patch description. E.g.,
Drop cgs wrappers that are no longer uses.
With that fixed:

Quoted 199 lines
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_cgs.c            | 30 ----------------------
 drivers/gpu/drm/amd/include/cgs_common.h           | 19 +-------------
 .../gpu/drm/amd/powerplay/hwmgr/hardwaremanager.c  | 14 ++--------
 drivers/gpu/drm/amd/powerplay/hwmgr/hwmgr.c        |  2 +-
 4 files changed, 4 insertions(+), 61 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_cgs.c +0 -30
index 71a57b2..1da6c17 100644
@@ -271,18 +271,6 @@ static uint32_t fw_type_convert(struct cgs_device *cgs_device, uint32_t fw_type)
        return result;
 }
 
-static int amdgpu_cgs_rel_firmware(struct cgs_device *cgs_device, enum cgs_ucode_id type)
-{
-       CGS_FUNC_ADEV;
-       if ((CGS_UCODE_ID_SMU == type) || (CGS_UCODE_ID_SMU_SK == type)) {
-               release_firmware(adev->pm.fw);
-               adev->pm.fw = NULL;
-               return 0;
-       }
-       /* cannot release other firmware because they are not created by cgs */
-       return -EINVAL;
-}
-
 static uint16_t amdgpu_get_firmware_version(struct cgs_device *cgs_device,
                                        enum cgs_ucode_id type)
 {
@@ -598,11 +586,6 @@ static int amdgpu_cgs_get_firmware_info(struct cgs_device *cgs_device,
        return 0;
 }
 
-static int amdgpu_cgs_is_virtualization_enabled(void *cgs_device)
-{
-       CGS_FUNC_ADEV;
-       return amdgpu_sriov_vf(adev);
-}
 
 static int amdgpu_cgs_get_active_displays_info(struct cgs_device *cgs_device,
                                          struct cgs_display_info *info)
@@ -661,16 +644,6 @@ static int amdgpu_cgs_get_active_displays_info(struct cgs_device *cgs_device,
        return 0;
 }
 
-
-static int amdgpu_cgs_notify_dpm_enabled(struct cgs_device *cgs_device, bool enabled)
-{
-       CGS_FUNC_ADEV;
-
-       adev->pm.dpm_enabled = enabled;
-
-       return 0;
-}
-
 static const struct cgs_ops amdgpu_cgs_ops = {
        .read_register = amdgpu_cgs_read_register,
        .write_register = amdgpu_cgs_write_register,
@@ -681,12 +654,9 @@ static int amdgpu_cgs_notify_dpm_enabled(struct cgs_device *cgs_device, bool ena
        .atom_get_cmd_table_revs = amdgpu_cgs_atom_get_cmd_table_revs,
        .atom_exec_cmd_table = amdgpu_cgs_atom_exec_cmd_table,
        .get_firmware_info = amdgpu_cgs_get_firmware_info,
-       .rel_firmware = amdgpu_cgs_rel_firmware,
        .set_powergating_state = amdgpu_cgs_set_powergating_state,
        .set_clockgating_state = amdgpu_cgs_set_clockgating_state,
        .get_active_displays_info = amdgpu_cgs_get_active_displays_info,
-       .notify_dpm_enabled = amdgpu_cgs_notify_dpm_enabled,
-       .is_virtualization_enabled = amdgpu_cgs_is_virtualization_enabled,
        .enter_safe_mode = amdgpu_cgs_enter_safe_mode,
        .lock_grbm_idx = amdgpu_cgs_lock_grbm_idx,
 };
drivers/gpu/drm/amd/include/cgs_common.h +1 -18
index f2814ae..69109a0e 100644
@@ -235,9 +235,6 @@ typedef int (*cgs_get_firmware_info)(struct cgs_device *cgs_device,
                                     enum cgs_ucode_id type,
                                     struct cgs_firmware_info *info);
 
-typedef int (*cgs_rel_firmware)(struct cgs_device *cgs_device,
-                                        enum cgs_ucode_id type);
-
 typedef int(*cgs_set_powergating_state)(struct cgs_device *cgs_device,
                                  enum amd_ip_block_type block_type,
                                  enum amd_powergating_state state);
@@ -250,10 +247,6 @@ typedef int(*cgs_get_active_displays_info)(
                                        struct cgs_device *cgs_device,
                                        struct cgs_display_info *info);
 
-typedef int (*cgs_notify_dpm_enabled)(struct cgs_device *cgs_device, bool enabled);
-
-typedef int (*cgs_is_virtualization_enabled_t)(void *cgs_device);
-
 typedef int (*cgs_enter_safe_mode)(struct cgs_device *cgs_device, bool en);
 
 typedef void (*cgs_lock_grbm_idx)(struct cgs_device *cgs_device, bool lock);
@@ -272,15 +265,11 @@ struct cgs_ops {
        cgs_atom_exec_cmd_table_t atom_exec_cmd_table;
        /* Firmware Info */
        cgs_get_firmware_info get_firmware_info;
-       cgs_rel_firmware rel_firmware;
        /* cg pg interface*/
        cgs_set_powergating_state set_powergating_state;
        cgs_set_clockgating_state set_clockgating_state;
        /* display manager */
        cgs_get_active_displays_info get_active_displays_info;
-       /* notify dpm enabled */
-       cgs_notify_dpm_enabled notify_dpm_enabled;
-       cgs_is_virtualization_enabled_t is_virtualization_enabled;
        cgs_enter_safe_mode enter_safe_mode;
        cgs_lock_grbm_idx lock_grbm_idx;
 };
@@ -318,14 +307,11 @@ struct cgs_device
 
 #define cgs_get_firmware_info(dev, type, info) \
        CGS_CALL(get_firmware_info, dev, type, info)
-#define cgs_rel_firmware(dev, type)    \
-       CGS_CALL(rel_firmware, dev, type)
 #define cgs_set_powergating_state(dev, block_type, state)      \
        CGS_CALL(set_powergating_state, dev, block_type, state)
 #define cgs_set_clockgating_state(dev, block_type, state)      \
        CGS_CALL(set_clockgating_state, dev, block_type, state)
-#define cgs_notify_dpm_enabled(dev, enabled)   \
-       CGS_CALL(notify_dpm_enabled, dev, enabled)
+
 
 #define cgs_get_active_displays_info(dev, info)        \
        CGS_CALL(get_active_displays_info, dev, info)
@@ -335,9 +321,6 @@ struct cgs_device
        CGS_CALL(get_pci_resource, cgs_device, resource_type, size, offset, \
        resource_base)
 
-#define cgs_is_virtualization_enabled(cgs_device) \
-               CGS_CALL(is_virtualization_enabled, cgs_device)
-
 #define cgs_enter_safe_mode(cgs_device, en) \
                CGS_CALL(enter_safe_mode, cgs_device, en)
 
drivers/gpu/drm/amd/powerplay/hwmgr/hardwaremanager.c +2 -12
index ae2e933..dcceadb 100644
@@ -75,8 +75,7 @@ int phm_set_power_state(struct pp_hwmgr *hwmgr,
 
 int phm_enable_dynamic_state_management(struct pp_hwmgr *hwmgr)
 {
-       int ret = 1;
-       bool enabled;
+       int ret = -EINVAL;;
        PHM_FUNC_CHECK(hwmgr);
 
        if (smum_is_dpm_running(hwmgr)) {
@@ -87,17 +86,12 @@ int phm_enable_dynamic_state_management(struct pp_hwmgr *hwmgr)
        if (NULL != hwmgr->hwmgr_func->dynamic_state_management_enable)
                ret = hwmgr->hwmgr_func->dynamic_state_management_enable(hwmgr);
 
-       enabled = ret == 0;
-
-       cgs_notify_dpm_enabled(hwmgr->device, enabled);
-
        return ret;
 }
 
 int phm_disable_dynamic_state_management(struct pp_hwmgr *hwmgr)
 {
-       int ret = -1;
-       bool enabled;
+       int ret = -EINVAL;
 
        PHM_FUNC_CHECK(hwmgr);
 
@@ -109,10 +103,6 @@ int phm_disable_dynamic_state_management(struct pp_hwmgr *hwmgr)
        if (hwmgr->hwmgr_func->dynamic_state_management_disable)
                ret = hwmgr->hwmgr_func->dynamic_state_management_disable(hwmgr);
 
-       enabled = ret == 0 ? false : true;
-
-       cgs_notify_dpm_enabled(hwmgr->device, enabled);
-
        return ret;
 }
 
drivers/gpu/drm/amd/powerplay/hwmgr/hwmgr.c +1 -2
index 96a2d01..30ff8a9 100644
@@ -211,7 +211,7 @@ int hwmgr_hw_init(struct pp_hwmgr *hwmgr)
            !hwmgr->pptable_func->pptable_init ||
            !hwmgr->hwmgr_func->backend_init) {
                hwmgr->pm_en = false;
-               cgs_notify_dpm_enabled(hwmgr->device, false);
+               ((struct amdgpu_device *)hwmgr->adev)->pm.dpm_enabled = false;
                pr_info("dpm not supported \n");
                return 0;
        }
--

1.9.1

Quoted 4 lines

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

author
#17 lore raw

Re: [PATCH 3/6] drm/amd/pp: Lock powerplay when reset pp table

In reply to a message not in the archive

Please see inline.

Best Regards
Rex
________________________________
From: Alex Deucher <[email protected]>
Sent: Thursday, March 22, 2018 9:17 PM
To: Zhu, Rex
Cc: amd-gfx list
Subject: Re: [PATCH 3/6] drm/amd/pp: Lock powerplay when reset pp table

Quoted 2 lines · Rex Zhu
Change-Id Ib02cd71593bee9606822a466a56f2d01ac2e04cc

Please include a commit description. It's not clear to me what's happening here.

Alex

Quoted 22 lines
---
 drivers/gpu/drm/amd/powerplay/amd_powerplay.c | 28 +++++++++++++--------------
 1 file changed, 14 insertions(+), 14 deletions(-)
drivers/gpu/drm/amd/powerplay/amd_powerplay.c +0 -3
index 5d7d9ec..1ae4905 100644
@@ -31,8 +31,6 @@
 #include "amdgpu.h"
 #include "hwmgr.h"
 
-static int pp_dpm_dispatch_tasks(void *handle, enum amd_pp_task task_id,
-               enum amd_pm_state_type *user_state);
 
 static const struct amd_pm_funcs pp_dpm_funcs;
 
@@ -146,10 +144,12 @@ static int pp_late_init(void *handle)
        struct amdgpu_device *adev = handle;
        struct pp_hwmgr *hwmgr = adev->powerplay.pp_handle;
 
-       if (hwmgr && hwmgr->pm_en)

drivers/gpu/drm/amd/powerplay/amd_powerplay.c static int pp_late_init(void *handle) · line 154

Quoted 10 lines
drivers/gpu/drm/amd/powerplay/amd_powerplay.c +5 -2
-               pp_dpm_dispatch_tasks(hwmgr,
+       if (hwmgr && hwmgr->pm_en) {
+               mutex_lock(&hwmgr->smu_lock);
+               hwmgr_handle_task(hwmgr,
                                        AMD_PP_TASK_COMPLETE_INIT, NULL);
-
+               mutex_unlock(&hwmgr->smu_lock);
+       }
        return 0;
 }

Rex : use hwmgr_handle_task instand of pp_dpm_dispatch_tasks. because i think it is not make sense that call pp_function in ip_function.

Quoted 34 lines
drivers/gpu/drm/amd/powerplay/amd_powerplay.c +4 -7
@@ -620,7 +620,7 @@ static int amd_powerplay_reset(void *handle)
 static int pp_dpm_set_pp_table(void *handle, const char *buf, size_t size)
 {
        struct pp_hwmgr *hwmgr = handle;
-       int ret = 0;
+       int ret = -ENOMEM;
 
        if (!hwmgr || !hwmgr->pm_en)
                return -EINVAL;
@@ -630,28 +630,28 @@ static int pp_dpm_set_pp_table(void *handle, const char *buf, size_t size)
                hwmgr->hardcode_pp_table = kmemdup(hwmgr->soft_pp_table,
                                                   hwmgr->soft_pp_table_size,
                                                   GFP_KERNEL);
-               if (!hwmgr->hardcode_pp_table) {
-                       mutex_unlock(&hwmgr->smu_lock);
-                       return -ENOMEM;
-               }
+               if (!hwmgr->hardcode_pp_table)
+                       goto err;
        }
 
        memcpy(hwmgr->hardcode_pp_table, buf, size);
 
        hwmgr->soft_pp_table = hwmgr->hardcode_pp_table;
-       mutex_unlock(&hwmgr->smu_lock);
 
        ret = amd_powerplay_reset(handle);
        if (ret)
-               return ret;
+               goto err;
 
        if (hwmgr->hwmgr_func->avfs_control) {
                ret = hwmgr->hwmgr_func->avfs_control(hwmgr, false);
                if (ret)

drivers/gpu/drm/amd/powerplay/amd_powerplay.c static int pp_dpm_set_pp_table(void *handle, const char *buf, size_t size) · line 655

Quoted 10 lines
drivers/gpu/drm/amd/powerplay/amd_powerplay.c +5 -2
-                       return ret;
+                       goto err;
        }
-
+       mutex_unlock(&hwmgr->smu_lock);
        return 0;
+err:
+       mutex_unlock(&hwmgr->smu_lock);
+       return ret;
 }

Rex: unlock mutex until set pp table complete to avoid other pp functions were called simultaneously<http://www.baidu.com/link?url=8RpXVOm53HQyZI9h-ZIs8Ipio9NEDj98vxJiiM0Wx4hbUUpanLuj7jZHEnm0Javd7_rpySIGVAwaxX_ICV-y2nDz_TZqF8mzUGZT8RPrw2WCcNsGFsoAh9nirArCSm9s>.

Quoted 8 lines
drivers/gpu/drm/amd/powerplay/amd_powerplay.c +0 -1
 static int pp_dpm_force_clock_level(void *handle,
--

1.9.1

_______________________________________________
amd-gfx mailing list [email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

amd-gfx Info Page - freedesktop.org<https://lists.freedesktop.org/mailman/listinfo/amd-gfx>
lists.freedesktop.org
Subscribing to amd-gfx: Subscribe to amd-gfx by filling out the following form. Use of all freedesktop.org lists is subject to our Code of ...

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

Reviewed-by
#19 lore raw

Re: [PATCH 3/6] drm/amd/pp: Lock powerplay when reset pp table

In reply to a message not in the archive
Quoted 105 lines · Rex

Please see inline.

Best Regards
Rex
------------------------------
*From:* Alex Deucher <[email protected]> *Sent:* Thursday, March 22, 2018 9:17 PM
*To:* Zhu, Rex
*Cc:* amd-gfx list
*Subject:* Re: [PATCH 3/6] drm/amd/pp: Lock powerplay when reset pp table

Quoted 2 lines · Rex Zhu
Change-Id Ib02cd71593bee9606822a466a56f2d01ac2e04cc

Please include a commit description. It's not clear to me what's happening here.

Alex

Quoted 2 lines
---
 drivers/gpu/drm/amd/powerplay/amd_powerplay.c | 28

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

Review

Quoted 3 lines
 1 file changed, 14 insertions(+), 14 deletions(-)
(quoted diff) +0 -0

b/drivers/gpu/drm/amd/powerplay/amd_powerplay.c

Quoted 13 lines

index 5d7d9ec..1ae4905 100644

drivers/gpu/drm/amd/powerplay/amd_powerplay.c +0 -2
@@ -31,8 +31,6 @@
 #include "amdgpu.h"
 #include "hwmgr.h"
 
-static int pp_dpm_dispatch_tasks(void *handle, enum amd_pp_task task_id,
-               enum amd_pm_state_type *user_state);
 
 static const struct amd_pm_funcs pp_dpm_funcs;
 

drivers/gpu/drm/amd/powerplay/amd_powerplay.c static int pp_late_init(void *handle) · line 150

Quoted 9 lines
drivers/gpu/drm/amd/powerplay/amd_powerplay.c +3 -2
@@ -146,10 +144,12 @@ static int pp_late_init(void *handle)
        struct amdgpu_device *adev = handle;
        struct pp_hwmgr *hwmgr = adev->powerplay.pp_handle;
 
-       if (hwmgr && hwmgr->pm_en)
-               pp_dpm_dispatch_tasks(hwmgr,
+       if (hwmgr && hwmgr->pm_en) {
+               mutex_lock(&hwmgr->smu_lock);
+               hwmgr_handle_task(hwmgr,
                                        AMD_PP_TASK_COMPLETE_INIT,

NULL);

drivers/gpu/drm/amd/powerplay/amd_powerplay.c static int pp_late_init(void *handle) · line 154

Quoted 5 lines
drivers/gpu/drm/amd/powerplay/amd_powerplay.c +2 -1
-
+               mutex_unlock(&hwmgr->smu_lock);
+       }
        return 0;
 }

Rex : use hwmgr_handle_task instand of pp_dpm_dispatch_tasks. because i think it is not make sense that call
pp_function in ip_function.

drivers/gpu/drm/amd/powerplay/amd_powerplay.c static int amd_powerplay_reset(void *handle) · line 620

Quoted 2 lines
drivers/gpu/drm/amd/powerplay/amd_powerplay.c +0 -0
@@ -620,7 +620,7 @@ static int amd_powerplay_reset(void *handle)
 static int pp_dpm_set_pp_table(void *handle, const char *buf, size_t

size)

drivers/gpu/drm/amd/powerplay/amd_powerplay.c static int pp_dpm_set_pp_table(void *handle, const

Quoted 8 lines
drivers/gpu/drm/amd/powerplay/amd_powerplay.c +1 -1
 {
        struct pp_hwmgr *hwmgr = handle;
-       int ret = 0;
+       int ret = -ENOMEM;
 
        if (!hwmgr || !hwmgr->pm_en)
                return -EINVAL;
@@ -630,28 +630,28 @@ static int pp_dpm_set_pp_table(void *handle, const

char *buf, size_t size)

drivers/gpu/drm/amd/powerplay/amd_powerplay.c static int pp_dpm_set_pp_table(void *handle, const char *buf, size_t size) · line 636

Quoted 2 lines
drivers/gpu/drm/amd/powerplay/amd_powerplay.c +0 -0
                hwmgr->hardcode_pp_table = kmemdup(hwmgr->soft_pp_table,
 

hwmgr->soft_pp_table_size,

Quoted 30 lines
drivers/gpu/drm/amd/powerplay/amd_powerplay.c +7 -8
                                                   GFP_KERNEL);
-               if (!hwmgr->hardcode_pp_table) {
-                       mutex_unlock(&hwmgr->smu_lock);
-                       return -ENOMEM;
-               }
+               if (!hwmgr->hardcode_pp_table)
+                       goto err;
        }
 
        memcpy(hwmgr->hardcode_pp_table, buf, size);
 
        hwmgr->soft_pp_table = hwmgr->hardcode_pp_table;
-       mutex_unlock(&hwmgr->smu_lock);
 
        ret = amd_powerplay_reset(handle);
        if (ret)
-               return ret;
+               goto err;
 
        if (hwmgr->hwmgr_func->avfs_control) {
                ret = hwmgr->hwmgr_func->avfs_control(hwmgr, false);
                if (ret)
-                       return ret;
+                       goto err;
        }
-
+       mutex_unlock(&hwmgr->smu_lock);
        return 0;
+err:
+       mutex_unlock(&hwmgr->smu_lock);
Quoted 9 lines

drivers/gpu/drm/amd/powerplay/amd_powerplay.c static int pp_dpm_set_pp_table(void *handle, const char *buf, size_t size) · line 655

Quoted 2 lines
drivers/gpu/drm/amd/powerplay/amd_powerplay.c +1 -0
+       return ret;
 }

Rex: unlock mutex until set pp table complete to avoid other pp functions were called simultaneously
<http://www.baidu.com/link?url=8RpXVOm53HQyZI9h-ZIs8Ipio9NEDj98vxJiiM0Wx4hbUUpanLuj7jZHEnm0Javd7_rpySIGVAwaxX_ICV-y2nDz_TZqF8mzUGZT8RPrw2WCcNsGFsoAh9nirArCSm9s>
.

Thanks. Please include these comments in the patch description. With that fixed:

Quoted 10 lines
Quoted 10 lines
drivers/gpu/drm/amd/powerplay/amd_powerplay.c +0 -1
 static int pp_dpm_force_clock_level(void *handle,
--

1.9.1

_______________________________________________
amd-gfx mailing list [email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

Quoted 8 lines

amd-gfx Info Page - freedesktop.org
<https://lists.freedesktop.org/mailman/listinfo/amd-gfx>
lists.freedesktop.org
Subscribing to amd-gfx: Subscribe to amd-gfx by filling out the following form. Use of all freedesktop.org lists is subject to our Code of ...

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

author
#10 lore raw

Re: [PATCH 2/6] drm/amd/pp: Add hwmgr_sw_init/fini functioins

In reply to a message not in the archive

Thanks Alex.

I should be more careful when reorder patches .

Best Regards

Rex

________________________________
From: Alex Deucher <[email protected]>
Sent: Thursday, March 22, 2018 9:13 PM
To: Zhu, Rex
Cc: amd-gfx list
Subject: Re: [PATCH 2/6] drm/amd/pp: Add hwmgr_sw_init/fini functioins

Quoted 11 lines · Alex Deucher
Quoted 7 lines · Alex Deucher
Quoted 4 lines · Rex Zhu

Clean up pp ip functions

Change-Id Id06159202edabdfcb19fcc20e1291ce93db56d5d

Actually, doesn't this patch have a dependency on patch 3? I think this part of patch 3:

Sorry, patch 4.

Quoted 977 lines

+ hwmgr->pm_en = (amdgpu_dpm && hwmgr->not_vf) ? true : false;
should be in this patch rather than the other patch. With that fixed:

Quoted 973 lines
Quoted 973 lines
---
 drivers/gpu/drm/amd/powerplay/amd_powerplay.c | 368 ++++++--------------------
 drivers/gpu/drm/amd/powerplay/hwmgr/hwmgr.c   |  74 ++++--
 drivers/gpu/drm/amd/powerplay/inc/hwmgr.h     |   7 +-
 3 files changed, 145 insertions(+), 304 deletions(-)
drivers/gpu/drm/amd/powerplay/amd_powerplay.c +83 -285
index 7e8ad30..5d7d9ec 100644
@@ -31,24 +31,11 @@
 #include "amdgpu.h"
 #include "hwmgr.h"
 
-#define PP_DPM_DISABLED 0xCCCC
-
 static int pp_dpm_dispatch_tasks(void *handle, enum amd_pp_task task_id,
                enum amd_pm_state_type *user_state);
 
 static const struct amd_pm_funcs pp_dpm_funcs;
 
-static inline int pp_check(struct pp_hwmgr *hwmgr)
-{
-       if (hwmgr == NULL || hwmgr->smumgr_funcs == NULL)
-               return -EINVAL;
-
-       if (hwmgr->pm_en == 0 || hwmgr->hwmgr_func == NULL)
-               return PP_DPM_DISABLED;
-
-       return 0;
-}
-
 static int amd_powerplay_create(struct amdgpu_device *adev)
 {
        struct pp_hwmgr *hwmgr;
@@ -73,7 +60,7 @@ static int amd_powerplay_create(struct amdgpu_device *adev)
 }
 
 
-static int amd_powerplay_destroy(struct amdgpu_device *adev)
+static void amd_powerplay_destroy(struct amdgpu_device *adev)
 {
        struct pp_hwmgr *hwmgr = adev->powerplay.pp_handle;
 
@@ -82,8 +69,6 @@ static int amd_powerplay_destroy(struct amdgpu_device *adev)
 
        kfree(hwmgr);
        hwmgr = NULL;
-
-       return 0;
 }
 
 static int pp_early_init(void *handle)
@@ -109,18 +94,9 @@ static int pp_sw_init(void *handle)
        struct pp_hwmgr *hwmgr = adev->powerplay.pp_handle;
        int ret = 0;
 
-       ret = pp_check(hwmgr);
-
-       if (ret >= 0) {
-               if (hwmgr->smumgr_funcs->smu_init == NULL)
-                       return -EINVAL;
+       ret = hwmgr_sw_init(hwmgr);
 
-               ret = hwmgr->smumgr_funcs->smu_init(hwmgr);
-
-               phm_register_irq_handlers(hwmgr);
-
-               pr_debug("amdgpu: powerplay sw initialized\n");
-       }
+       pr_debug("amdgpu: powerplay sw init %s\n", ret ? "failed" : "successfully");
 
        return ret;
 }
@@ -129,13 +105,8 @@ static int pp_sw_fini(void *handle)
 {
        struct amdgpu_device *adev = handle;
        struct pp_hwmgr *hwmgr = adev->powerplay.pp_handle;
-       int ret = 0;
 
-       ret = pp_check(hwmgr);
-       if (ret >= 0) {
-               if (hwmgr->smumgr_funcs->smu_fini != NULL)
-                       hwmgr->smumgr_funcs->smu_fini(hwmgr);
-       }
+       hwmgr_sw_fini(hwmgr);
 
        if (adev->firmware.load_type == AMDGPU_FW_LOAD_SMU)
                amdgpu_ucode_fini_bo(adev);
@@ -152,40 +123,20 @@ static int pp_hw_init(void *handle)
        if (adev->firmware.load_type == AMDGPU_FW_LOAD_SMU)
                amdgpu_ucode_init_bo(adev);
 
-       ret = pp_check(hwmgr);
+       ret = hwmgr_hw_init(hwmgr);
 
-       if (ret >= 0) {
-               if (hwmgr->smumgr_funcs->start_smu == NULL)
-                       return -EINVAL;
+       if (ret)
+               pr_err("amdgpu: powerplay hw init failed\n");
 
-               if (hwmgr->smumgr_funcs->start_smu(hwmgr)) {
-                       pr_err("smc start failed\n");
-                       hwmgr->smumgr_funcs->smu_fini(hwmgr);
-                       return -EINVAL;
-               }
-               if (ret == PP_DPM_DISABLED)
-                       goto exit;
-               ret = hwmgr_hw_init(hwmgr);
-               if (ret)
-                       goto exit;
-       }
        return ret;
-exit:
-       hwmgr->pm_en = 0;
-       cgs_notify_dpm_enabled(hwmgr->device, false);
-       return 0;
-
 }
 
 static int pp_hw_fini(void *handle)
 {
        struct amdgpu_device *adev = handle;
        struct pp_hwmgr *hwmgr = adev->powerplay.pp_handle;
-       int ret = 0;
 
-       ret = pp_check(hwmgr);
-       if (ret == 0)
-               hwmgr_hw_fini(hwmgr);
+       hwmgr_hw_fini(hwmgr);
 
        return 0;
 }
@@ -194,11 +145,8 @@ static int pp_late_init(void *handle)
 {
        struct amdgpu_device *adev = handle;
        struct pp_hwmgr *hwmgr = adev->powerplay.pp_handle;
-       int ret = 0;
-
-       ret = pp_check(hwmgr);
 
-       if (ret == 0)
+       if (hwmgr && hwmgr->pm_en)
                pp_dpm_dispatch_tasks(hwmgr,
                                        AMD_PP_TASK_COMPLETE_INIT, NULL);
 
@@ -233,12 +181,9 @@ static int pp_set_powergating_state(void *handle,
 {
        struct amdgpu_device *adev = handle;
        struct pp_hwmgr *hwmgr = adev->powerplay.pp_handle;
-       int ret = 0;
 
-       ret = pp_check(hwmgr);
-
-       if (ret)
-               return ret;
+       if (!hwmgr || !hwmgr->pm_en)
+               return 0;
 
        if (hwmgr->hwmgr_func->enable_per_cu_power_gating == NULL) {
                pr_info("%s was not implemented.\n", __func__);
@@ -254,38 +199,16 @@ static int pp_suspend(void *handle)
 {
        struct amdgpu_device *adev = handle;
        struct pp_hwmgr *hwmgr = adev->powerplay.pp_handle;
-       int ret = 0;
 
-       ret = pp_check(hwmgr);
-       if (ret == 0)
-               hwmgr_hw_suspend(hwmgr);
-       return 0;
+       return hwmgr_suspend(hwmgr);
 }
 
 static int pp_resume(void *handle)
 {
        struct amdgpu_device *adev = handle;
        struct pp_hwmgr *hwmgr = adev->powerplay.pp_handle;
-       int ret;
-
-       ret = pp_check(hwmgr);
-
-       if (ret < 0)
-               return ret;
-
-       if (hwmgr->smumgr_funcs->start_smu == NULL)
-               return -EINVAL;
-
-       if (hwmgr->smumgr_funcs->start_smu(hwmgr)) {
-               pr_err("smc start failed\n");
-               hwmgr->smumgr_funcs->smu_fini(hwmgr);
-               return -EINVAL;
-       }
-
-       if (ret == PP_DPM_DISABLED)
-               return 0;
 
-       return hwmgr_hw_resume(hwmgr);
+       return hwmgr_resume(hwmgr);
 }
 
 static int pp_set_clockgating_state(void *handle,
@@ -334,12 +257,9 @@ static int pp_dpm_fw_loading_complete(void *handle)
 static int pp_set_clockgating_by_smu(void *handle, uint32_t msg_id)
 {
        struct pp_hwmgr *hwmgr = handle;
-       int ret = 0;
-
-       ret = pp_check(hwmgr);
 
-       if (ret)
-               return ret;
+       if (!hwmgr || !hwmgr->pm_en)
+               return -EINVAL;
 
        if (hwmgr->hwmgr_func->update_clock_gatings == NULL) {
                pr_info("%s was not implemented.\n", __func__);
@@ -389,12 +309,9 @@ static int pp_dpm_force_performance_level(void *handle,
                                        enum amd_dpm_forced_level level)
 {
        struct pp_hwmgr *hwmgr = handle;
-       int ret = 0;
 
-       ret = pp_check(hwmgr);
-
-       if (ret)
-               return ret;
+       if (!hwmgr || !hwmgr->pm_en)
+               return -EINVAL;
 
        if (level == hwmgr->dpm_level)
                return 0;
@@ -412,13 +329,10 @@ static enum amd_dpm_forced_level pp_dpm_get_performance_level(
                                                                void *handle)
 {
        struct pp_hwmgr *hwmgr = handle;
-       int ret = 0;
        enum amd_dpm_forced_level level;
 
-       ret = pp_check(hwmgr);
-
-       if (ret)
-               return ret;
+       if (!hwmgr || !hwmgr->pm_en)
+               return -EINVAL;
 
        mutex_lock(&hwmgr->smu_lock);
        level = hwmgr->dpm_level;
@@ -429,13 +343,10 @@ static enum amd_dpm_forced_level pp_dpm_get_performance_level(
 static uint32_t pp_dpm_get_sclk(void *handle, bool low)
 {
        struct pp_hwmgr *hwmgr = handle;
-       int ret = 0;
        uint32_t clk = 0;
 
-       ret = pp_check(hwmgr);
-
-       if (ret)
-               return ret;
+       if (!hwmgr || !hwmgr->pm_en)
+               return 0;
 
        if (hwmgr->hwmgr_func->get_sclk == NULL) {
                pr_info("%s was not implemented.\n", __func__);
@@ -450,13 +361,10 @@ static uint32_t pp_dpm_get_sclk(void *handle, bool low)
 static uint32_t pp_dpm_get_mclk(void *handle, bool low)
 {
        struct pp_hwmgr *hwmgr = handle;
-       int ret = 0;
        uint32_t clk = 0;
 
-       ret = pp_check(hwmgr);
-
-       if (ret)
-               return ret;
+       if (!hwmgr || !hwmgr->pm_en)
+               return 0;
 
        if (hwmgr->hwmgr_func->get_mclk == NULL) {
                pr_info("%s was not implemented.\n", __func__);
@@ -471,11 +379,8 @@ static uint32_t pp_dpm_get_mclk(void *handle, bool low)
 static void pp_dpm_powergate_vce(void *handle, bool gate)
 {
        struct pp_hwmgr *hwmgr = handle;
-       int ret = 0;
-
-       ret = pp_check(hwmgr);
 
-       if (ret)
+       if (!hwmgr || !hwmgr->pm_en)
                return;
 
        if (hwmgr->hwmgr_func->powergate_vce == NULL) {
@@ -490,11 +395,8 @@ static void pp_dpm_powergate_vce(void *handle, bool gate)
 static void pp_dpm_powergate_uvd(void *handle, bool gate)
 {
        struct pp_hwmgr *hwmgr = handle;
-       int ret = 0;
-
-       ret = pp_check(hwmgr);
 
-       if (ret)
+       if (!hwmgr || !hwmgr->pm_en)
                return;
 
        if (hwmgr->hwmgr_func->powergate_uvd == NULL) {
@@ -512,10 +414,8 @@ static int pp_dpm_dispatch_tasks(void *handle, enum amd_pp_task task_id,
        int ret = 0;
        struct pp_hwmgr *hwmgr = handle;
 
-       ret = pp_check(hwmgr);
-
-       if (ret)
-               return ret;
+       if (!hwmgr || !hwmgr->pm_en)
+               return -EINVAL;
 
        mutex_lock(&hwmgr->smu_lock);
        ret = hwmgr_handle_task(hwmgr, task_id, user_state);
@@ -528,15 +428,9 @@ static enum amd_pm_state_type pp_dpm_get_current_power_state(void *handle)
 {
        struct pp_hwmgr *hwmgr = handle;
        struct pp_power_state *state;
-       int ret = 0;
        enum amd_pm_state_type pm_type;
 
-       ret = pp_check(hwmgr);
-
-       if (ret)
-               return ret;
-
-       if (hwmgr->current_ps == NULL)
+       if (!hwmgr || !hwmgr->pm_en || !hwmgr->current_ps)
                return -EINVAL;
 
        mutex_lock(&hwmgr->smu_lock);
@@ -568,11 +462,8 @@ static enum amd_pm_state_type pp_dpm_get_current_power_state(void *handle)
 static void pp_dpm_set_fan_control_mode(void *handle, uint32_t mode)
 {
        struct pp_hwmgr *hwmgr = handle;
-       int ret = 0;
-
-       ret = pp_check(hwmgr);
 
-       if (ret)
+       if (!hwmgr || !hwmgr->pm_en)
                return;
 
        if (hwmgr->hwmgr_func->set_fan_control_mode == NULL) {
@@ -587,13 +478,10 @@ static void pp_dpm_set_fan_control_mode(void *handle, uint32_t mode)
 static uint32_t pp_dpm_get_fan_control_mode(void *handle)
 {
        struct pp_hwmgr *hwmgr = handle;
-       int ret = 0;
        uint32_t mode = 0;
 
-       ret = pp_check(hwmgr);
-
-       if (ret)
-               return ret;
+       if (!hwmgr || !hwmgr->pm_en)
+               return 0;
 
        if (hwmgr->hwmgr_func->get_fan_control_mode == NULL) {
                pr_info("%s was not implemented.\n", __func__);
@@ -610,10 +498,8 @@ static int pp_dpm_set_fan_speed_percent(void *handle, uint32_t percent)
        struct pp_hwmgr *hwmgr = handle;
        int ret = 0;
 
-       ret = pp_check(hwmgr);
-
-       if (ret)
-               return ret;
+       if (!hwmgr || !hwmgr->pm_en)
+               return -EINVAL;
 
        if (hwmgr->hwmgr_func->set_fan_speed_percent == NULL) {
                pr_info("%s was not implemented.\n", __func__);
@@ -630,10 +516,8 @@ static int pp_dpm_get_fan_speed_percent(void *handle, uint32_t *speed)
        struct pp_hwmgr *hwmgr = handle;
        int ret = 0;
 
-       ret = pp_check(hwmgr);
-
-       if (ret)
-               return ret;
+       if (!hwmgr || !hwmgr->pm_en)
+               return -EINVAL;
 
        if (hwmgr->hwmgr_func->get_fan_speed_percent == NULL) {
                pr_info("%s was not implemented.\n", __func__);
@@ -651,10 +535,8 @@ static int pp_dpm_get_fan_speed_rpm(void *handle, uint32_t *rpm)
        struct pp_hwmgr *hwmgr = handle;
        int ret = 0;
 
-       ret = pp_check(hwmgr);
-
-       if (ret)
-               return ret;
+       if (!hwmgr || !hwmgr->pm_en)
+               return -EINVAL;
 
        if (hwmgr->hwmgr_func->get_fan_speed_rpm == NULL)
                return -EINVAL;
@@ -670,16 +552,10 @@ static int pp_dpm_get_pp_num_states(void *handle,
 {
        struct pp_hwmgr *hwmgr = handle;
        int i;
-       int ret = 0;
 
        memset(data, 0, sizeof(*data));
 
-       ret = pp_check(hwmgr);
-
-       if (ret)
-               return ret;
-
-       if (hwmgr->ps == NULL)
+       if (!hwmgr || !hwmgr->pm_en ||!hwmgr->ps)
                return -EINVAL;
 
        mutex_lock(&hwmgr->smu_lock);
@@ -713,15 +589,9 @@ static int pp_dpm_get_pp_num_states(void *handle,
 static int pp_dpm_get_pp_table(void *handle, char **table)
 {
        struct pp_hwmgr *hwmgr = handle;
-       int ret = 0;
        int size = 0;
 
-       ret = pp_check(hwmgr);
-
-       if (ret)
-               return ret;
-
-       if (!hwmgr->soft_pp_table)
+       if (!hwmgr || !hwmgr->pm_en ||!hwmgr->soft_pp_table)
                return -EINVAL;
 
        mutex_lock(&hwmgr->smu_lock);
@@ -736,10 +606,6 @@ static int amd_powerplay_reset(void *handle)
        struct pp_hwmgr *hwmgr = handle;
        int ret;
 
-       ret = pp_check(hwmgr);
-       if (ret)
-               return ret;
-
        ret = hwmgr_hw_fini(hwmgr);
        if (ret)
                return ret;
@@ -756,10 +622,8 @@ static int pp_dpm_set_pp_table(void *handle, const char *buf, size_t size)
        struct pp_hwmgr *hwmgr = handle;
        int ret = 0;
 
-       ret = pp_check(hwmgr);
-
-       if (ret)
-               return ret;
+       if (!hwmgr || !hwmgr->pm_en)
+               return -EINVAL;
 
        mutex_lock(&hwmgr->smu_lock);
        if (!hwmgr->hardcode_pp_table) {
@@ -796,10 +660,8 @@ static int pp_dpm_force_clock_level(void *handle,
        struct pp_hwmgr *hwmgr = handle;
        int ret = 0;
 
-       ret = pp_check(hwmgr);
-
-       if (ret)
-               return ret;
+       if (!hwmgr || !hwmgr->pm_en)
+               return -EINVAL;
 
        if (hwmgr->hwmgr_func->force_clock_level == NULL) {
                pr_info("%s was not implemented.\n", __func__);
@@ -820,10 +682,8 @@ static int pp_dpm_print_clock_levels(void *handle,
        struct pp_hwmgr *hwmgr = handle;
        int ret = 0;
 
-       ret = pp_check(hwmgr);
-
-       if (ret)
-               return ret;
+       if (!hwmgr || !hwmgr->pm_en)
+               return -EINVAL;
 
        if (hwmgr->hwmgr_func->print_clock_levels == NULL) {
                pr_info("%s was not implemented.\n", __func__);
@@ -840,10 +700,8 @@ static int pp_dpm_get_sclk_od(void *handle)
        struct pp_hwmgr *hwmgr = handle;
        int ret = 0;
 
-       ret = pp_check(hwmgr);
-
-       if (ret)
-               return ret;
+       if (!hwmgr || !hwmgr->pm_en)
+               return -EINVAL;
 
        if (hwmgr->hwmgr_func->get_sclk_od == NULL) {
                pr_info("%s was not implemented.\n", __func__);
@@ -860,10 +718,8 @@ static int pp_dpm_set_sclk_od(void *handle, uint32_t value)
        struct pp_hwmgr *hwmgr = handle;
        int ret = 0;
 
-       ret = pp_check(hwmgr);
-
-       if (ret)
-               return ret;
+       if (!hwmgr || !hwmgr->pm_en)
+               return -EINVAL;
 
        if (hwmgr->hwmgr_func->set_sclk_od == NULL) {
                pr_info("%s was not implemented.\n", __func__);
@@ -881,10 +737,8 @@ static int pp_dpm_get_mclk_od(void *handle)
        struct pp_hwmgr *hwmgr = handle;
        int ret = 0;
 
-       ret = pp_check(hwmgr);
-
-       if (ret)
-               return ret;
+       if (!hwmgr || !hwmgr->pm_en)
+               return -EINVAL;
 
        if (hwmgr->hwmgr_func->get_mclk_od == NULL) {
                pr_info("%s was not implemented.\n", __func__);
@@ -901,10 +755,8 @@ static int pp_dpm_set_mclk_od(void *handle, uint32_t value)
        struct pp_hwmgr *hwmgr = handle;
        int ret = 0;
 
-       ret = pp_check(hwmgr);
-
-       if (ret)
-               return ret;
+       if (!hwmgr || !hwmgr->pm_en)
+               return -EINVAL;
 
        if (hwmgr->hwmgr_func->set_mclk_od == NULL) {
                pr_info("%s was not implemented.\n", __func__);
@@ -922,11 +774,7 @@ static int pp_dpm_read_sensor(void *handle, int idx,
        struct pp_hwmgr *hwmgr = handle;
        int ret = 0;
 
-       ret = pp_check(hwmgr);
-       if (ret)
-               return ret;
-
-       if (value == NULL)
+       if (!hwmgr || !hwmgr->pm_en || !value)
                return -EINVAL;
 
        switch (idx) {
@@ -948,14 +796,11 @@ static int pp_dpm_read_sensor(void *handle, int idx,
 pp_dpm_get_vce_clock_state(void *handle, unsigned idx)
 {
        struct pp_hwmgr *hwmgr = handle;
-       int ret = 0;
-
-       ret = pp_check(hwmgr);
 
-       if (ret)
+       if (!hwmgr || !hwmgr->pm_en)
                return NULL;
 
-       if (hwmgr && idx < hwmgr->num_vce_state_tables)
+       if (idx < hwmgr->num_vce_state_tables)
                return &hwmgr->vce_states[idx];
        return NULL;
 }
@@ -964,7 +809,7 @@ static int pp_get_power_profile_mode(void *handle, char *buf)
 {
        struct pp_hwmgr *hwmgr = handle;
 
-       if (!buf || pp_check(hwmgr))
+       if (!hwmgr || !hwmgr->pm_en || !buf)
                return -EINVAL;
 
        if (hwmgr->hwmgr_func->get_power_profile_mode == NULL) {
@@ -980,12 +825,12 @@ static int pp_set_power_profile_mode(void *handle, long *input, uint32_t size)
        struct pp_hwmgr *hwmgr = handle;
        int ret = -EINVAL;
 
-       if (pp_check(hwmgr))
-               return -EINVAL;
+       if (!hwmgr || !hwmgr->pm_en)
+               return ret;
 
        if (hwmgr->hwmgr_func->set_power_profile_mode == NULL) {
                pr_info("%s was not implemented.\n", __func__);
-               return -EINVAL;
+               return ret;
        }
        mutex_lock(&hwmgr->smu_lock);
        if (hwmgr->dpm_level == AMD_DPM_FORCED_LEVEL_MANUAL)
@@ -998,7 +843,7 @@ static int pp_odn_edit_dpm_table(void *handle, uint32_t type, long *input, uint3
 {
        struct pp_hwmgr *hwmgr = handle;
 
-       if (pp_check(hwmgr))
+       if (!hwmgr || !hwmgr->pm_en)
                return -EINVAL;
 
        if (hwmgr->hwmgr_func->odn_edit_dpm_table == NULL) {
@@ -1016,7 +861,7 @@ static int pp_dpm_switch_power_profile(void *handle,
        long workload;
        uint32_t index;
 
-       if (pp_check(hwmgr))
+       if (!hwmgr || !hwmgr->pm_en)
                return -EINVAL;
 
        if (hwmgr->hwmgr_func->set_power_profile_mode == NULL) {
@@ -1058,10 +903,8 @@ static int pp_dpm_notify_smu_memory_info(void *handle,
        struct pp_hwmgr *hwmgr = handle;
        int ret = 0;
 
-       ret = pp_check(hwmgr);
-
-       if (ret)
-               return ret;
+       if (!hwmgr || !hwmgr->pm_en)
+               return -EINVAL;
 
        if (hwmgr->hwmgr_func->notify_cac_buffer_info == NULL) {
                pr_info("%s was not implemented.\n", __func__);
@@ -1082,12 +925,9 @@ static int pp_dpm_notify_smu_memory_info(void *handle,
 static int pp_set_power_limit(void *handle, uint32_t limit)
 {
        struct pp_hwmgr *hwmgr = handle;
-       int ret = 0;
-
-       ret = pp_check(hwmgr);
 
-       if (ret)
-               return ret;
+       if (!hwmgr || !hwmgr->pm_en)
+               return -EINVAL;
 
        if (hwmgr->hwmgr_func->set_power_limit == NULL) {
                pr_info("%s was not implemented.\n", __func__);
@@ -1104,20 +944,14 @@ static int pp_set_power_limit(void *handle, uint32_t limit)
        hwmgr->hwmgr_func->set_power_limit(hwmgr, limit);
        hwmgr->power_limit = limit;
        mutex_unlock(&hwmgr->smu_lock);
-       return ret;
+       return 0;
 }
 
 static int pp_get_power_limit(void *handle, uint32_t *limit, bool default_limit)
 {
        struct pp_hwmgr *hwmgr = handle;
-       int ret = 0;
-
-       ret = pp_check(hwmgr);
 
-       if (ret)
-               return ret;
-
-       if (limit == NULL)
+       if (!hwmgr || !hwmgr->pm_en ||!limit)
                return -EINVAL;
 
        mutex_lock(&hwmgr->smu_lock);
@@ -1129,19 +963,16 @@ static int pp_get_power_limit(void *handle, uint32_t *limit, bool default_limit)
 
        mutex_unlock(&hwmgr->smu_lock);
 
-       return ret;
+       return 0;
 }
 
 static int pp_display_configuration_change(void *handle,
        const struct amd_pp_display_configuration *display_config)
 {
        struct pp_hwmgr *hwmgr = handle;
-       int ret = 0;
-
-       ret = pp_check(hwmgr);
 
-       if (ret)
-               return ret;
+       if (!hwmgr || !hwmgr->pm_en)
+               return -EINVAL;
 
        mutex_lock(&hwmgr->smu_lock);
        phm_store_dal_configuration_data(hwmgr, display_config);
@@ -1155,12 +986,7 @@ static int pp_get_display_power_level(void *handle,
        struct pp_hwmgr *hwmgr = handle;
        int ret = 0;
 
-       ret = pp_check(hwmgr);
-
-       if (ret)
-               return ret;
-
-       if (output == NULL)
+       if (!hwmgr || !hwmgr->pm_en ||!output)
                return -EINVAL;
 
        mutex_lock(&hwmgr->smu_lock);
@@ -1177,10 +1003,8 @@ static int pp_get_current_clocks(void *handle,
        struct pp_hwmgr *hwmgr = handle;
        int ret = 0;
 
-       ret = pp_check(hwmgr);
-
-       if (ret)
-               return ret;
+       if (!hwmgr || !hwmgr->pm_en)
+               return -EINVAL;
 
        mutex_lock(&hwmgr->smu_lock);
 
@@ -1225,10 +1049,8 @@ static int pp_get_clock_by_type(void *handle, enum amd_pp_clock_type type, struc
        struct pp_hwmgr *hwmgr = handle;
        int ret = 0;
 
-       ret = pp_check(hwmgr);
-
-       if (ret)
-               return ret;
+       if (!hwmgr || !hwmgr->pm_en)
+               return -EINVAL;
 
        if (clocks == NULL)
                return -EINVAL;
@@ -1246,11 +1068,7 @@ static int pp_get_clock_by_type_with_latency(void *handle,
        struct pp_hwmgr *hwmgr = handle;
        int ret = 0;
 
-       ret = pp_check(hwmgr);
-       if (ret)
-               return ret;
-
-       if (!clocks)
+       if (!hwmgr || !hwmgr->pm_en ||!clocks)
                return -EINVAL;
 
        mutex_lock(&hwmgr->smu_lock);
@@ -1266,11 +1084,7 @@ static int pp_get_clock_by_type_with_voltage(void *handle,
        struct pp_hwmgr *hwmgr = handle;
        int ret = 0;
 
-       ret = pp_check(hwmgr);
-       if (ret)
-               return ret;
-
-       if (!clocks)
+       if (!hwmgr || !hwmgr->pm_en ||!clocks)
                return -EINVAL;
 
        mutex_lock(&hwmgr->smu_lock);
@@ -1287,11 +1101,7 @@ static int pp_set_watermarks_for_clocks_ranges(void *handle,
        struct pp_hwmgr *hwmgr = handle;
        int ret = 0;
 
-       ret = pp_check(hwmgr);
-       if (ret)
-               return ret;
-
-       if (!wm_with_clock_ranges)
+       if (!hwmgr || !hwmgr->pm_en ||!wm_with_clock_ranges)
                return -EINVAL;
 
        mutex_lock(&hwmgr->smu_lock);
@@ -1308,11 +1118,7 @@ static int pp_display_clock_voltage_request(void *handle,
        struct pp_hwmgr *hwmgr = handle;
        int ret = 0;
 
-       ret = pp_check(hwmgr);
-       if (ret)
-               return ret;
-
-       if (!clock)
+       if (!hwmgr || !hwmgr->pm_en ||!clock)
                return -EINVAL;
 
        mutex_lock(&hwmgr->smu_lock);
@@ -1328,12 +1134,7 @@ static int pp_get_display_mode_validation_clocks(void *handle,
        struct pp_hwmgr *hwmgr = handle;
        int ret = 0;
 
-       ret = pp_check(hwmgr);
-
-       if (ret)
-               return ret;
-
-       if (clocks == NULL)
+       if (!hwmgr || !hwmgr->pm_en ||!clocks)
                return -EINVAL;
 
        mutex_lock(&hwmgr->smu_lock);
@@ -1348,12 +1149,9 @@ static int pp_get_display_mode_validation_clocks(void *handle,
 static int pp_set_mmhub_powergating_by_smu(void *handle)
 {
        struct pp_hwmgr *hwmgr = handle;
-       int ret = 0;
-
-       ret = pp_check(hwmgr);
 
-       if (ret)
-               return ret;
+       if (!hwmgr || !hwmgr->pm_en)
+               return -EINVAL;
 
        if (hwmgr->hwmgr_func->set_mmhub_powergating_by_smu == NULL) {
                pr_info("%s was not implemented.\n", __func__);
drivers/gpu/drm/amd/powerplay/hwmgr/hwmgr.c +57 -17
index 4298205..96a2d01 100644
@@ -76,7 +76,7 @@ static void hwmgr_init_workload_prority(struct pp_hwmgr *hwmgr)
 
 int hwmgr_early_init(struct pp_hwmgr *hwmgr)
 {
-       if (hwmgr == NULL)
+       if (!hwmgr)
                return -EINVAL;
 
        hwmgr->usec_timeout = AMD_MAX_USEC_TIMEOUT;
@@ -170,17 +170,51 @@ int hwmgr_early_init(struct pp_hwmgr *hwmgr)
        return 0;
 }
 
+int hwmgr_sw_init(struct pp_hwmgr *hwmgr)
+{
+       if (!hwmgr|| !hwmgr->smumgr_funcs || !hwmgr->smumgr_funcs->smu_init)
+               return -EINVAL;
+
+       phm_register_irq_handlers(hwmgr);
+
+       return hwmgr->smumgr_funcs->smu_init(hwmgr);
+}
+
+
+int hwmgr_sw_fini(struct pp_hwmgr *hwmgr)
+{
+       if (hwmgr && hwmgr->smumgr_funcs && hwmgr->smumgr_funcs->smu_fini)
+               hwmgr->smumgr_funcs->smu_fini(hwmgr);
+
+       return 0;
+}
+
 int hwmgr_hw_init(struct pp_hwmgr *hwmgr)
 {
        int ret = 0;
 
-       if (hwmgr == NULL)
+       if (!hwmgr || !hwmgr->smumgr_funcs)
                return -EINVAL;
 
-       if (hwmgr->pptable_func == NULL ||
-           hwmgr->pptable_func->pptable_init == NULL ||
-           hwmgr->hwmgr_func->backend_init == NULL)
-               return -EINVAL;
+       if (hwmgr->smumgr_funcs->start_smu) {
+               ret = hwmgr->smumgr_funcs->start_smu(hwmgr);
+               if (ret) {
+                       pr_err("smc start failed\n");
+                       return -EINVAL;
+               }
+       }
+
+       if (!hwmgr->pm_en)
+               return 0;
+
+       if (!hwmgr->pptable_func ||
+           !hwmgr->pptable_func->pptable_init ||
+           !hwmgr->hwmgr_func->backend_init) {
+               hwmgr->pm_en = false;
+               cgs_notify_dpm_enabled(hwmgr->device, false);
+               pr_info("dpm not supported \n");
+               return 0;
+       }
 
        ret = hwmgr->pptable_func->pptable_init(hwmgr);
        if (ret)
@@ -214,14 +248,13 @@ int hwmgr_hw_init(struct pp_hwmgr *hwmgr)
        if (hwmgr->pptable_func->pptable_fini)
                hwmgr->pptable_func->pptable_fini(hwmgr);
 err:
-       pr_err("amdgpu: powerplay initialization failed\n");
        return ret;
 }
 
 int hwmgr_hw_fini(struct pp_hwmgr *hwmgr)
 {
-       if (hwmgr == NULL)
-               return -EINVAL;
+       if (!hwmgr || !hwmgr->pm_en)
+               return 0;
 
        phm_stop_thermal_controller(hwmgr);
        psm_set_boot_states(hwmgr);
@@ -236,12 +269,12 @@ int hwmgr_hw_fini(struct pp_hwmgr *hwmgr)
        return psm_fini_power_state_table(hwmgr);
 }
 
-int hwmgr_hw_suspend(struct pp_hwmgr *hwmgr)
+int hwmgr_suspend(struct pp_hwmgr *hwmgr)
 {
        int ret = 0;
 
-       if (hwmgr == NULL)
-               return -EINVAL;
+       if (!hwmgr || !hwmgr->pm_en)
+               return 0;
 
        phm_disable_smc_firmware_ctf(hwmgr);
        ret = psm_set_boot_states(hwmgr);
@@ -255,13 +288,23 @@ int hwmgr_hw_suspend(struct pp_hwmgr *hwmgr)
        return ret;
 }
 
-int hwmgr_hw_resume(struct pp_hwmgr *hwmgr)
+int hwmgr_resume(struct pp_hwmgr *hwmgr)
 {
        int ret = 0;
 
-       if (hwmgr == NULL)
+       if (!hwmgr)
                return -EINVAL;
 
+       if (hwmgr->smumgr_funcs && hwmgr->smumgr_funcs->start_smu) {
+               if (hwmgr->smumgr_funcs->start_smu(hwmgr)) {
+                       pr_err("smc start failed\n");
+                       return -EINVAL;
+               }
+       }
+
+       if (!hwmgr->pm_en)
+               return 0;
+
        ret = phm_setup_asic(hwmgr);
        if (ret)
                return ret;
@@ -270,9 +313,6 @@ int hwmgr_hw_resume(struct pp_hwmgr *hwmgr)
        if (ret)
                return ret;
        ret = phm_start_thermal_controller(hwmgr);
-       if (ret)
-               return ret;
-
        ret |= psm_set_performance_states(hwmgr);
        if (ret)
                return ret;
drivers/gpu/drm/amd/powerplay/inc/hwmgr.h +5 -3
index 17f811d..d6c9a3b 100644
@@ -782,10 +782,13 @@ struct pp_hwmgr {
 };
 
 int hwmgr_early_init(struct pp_hwmgr *hwmgr);
+int hwmgr_sw_init(struct pp_hwmgr *hwmgr);
+int hwmgr_sw_fini(struct pp_hwmgr *hwmgr);
 int hwmgr_hw_init(struct pp_hwmgr *hwmgr);
 int hwmgr_hw_fini(struct pp_hwmgr *hwmgr);
-int hwmgr_hw_suspend(struct pp_hwmgr *hwmgr);
-int hwmgr_hw_resume(struct pp_hwmgr *hwmgr);
+int hwmgr_suspend(struct pp_hwmgr *hwmgr);
+int hwmgr_resume(struct pp_hwmgr *hwmgr);
+
 int hwmgr_handle_task(struct pp_hwmgr *hwmgr,
                                enum amd_pp_task task_id,
                                enum amd_pm_state_type *user_state);
--

1.9.1

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

_______________________________________________
amd-gfx mailing list [email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

amd-gfx Info Page - freedesktop.org<https://lists.freedesktop.org/mailman/listinfo/amd-gfx>
lists.freedesktop.org
Subscribing to amd-gfx: Subscribe to amd-gfx by filling out the following form. Use of all freedesktop.org lists is subject to our Code of ...

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

#11 lore raw

Re: [PATCH 2/6] drm/amd/pp: Add hwmgr_sw_init/fini functioins

In reply to a message not in the archive
Quoted 65 lines · Rex Zhu

Clean up pp ip functions

Change-Id Id06159202edabdfcb19fcc20e1291ce93db56d5d
---
 drivers/gpu/drm/amd/powerplay/amd_powerplay.c | 368 ++++++--------------------
 drivers/gpu/drm/amd/powerplay/hwmgr/hwmgr.c   |  74 ++++--
 drivers/gpu/drm/amd/powerplay/inc/hwmgr.h     |   7 +-
 3 files changed, 145 insertions(+), 304 deletions(-)
drivers/gpu/drm/amd/powerplay/amd_powerplay.c +1 -20
index 7e8ad30..5d7d9ec 100644
@@ -31,24 +31,11 @@
 #include "amdgpu.h"
 #include "hwmgr.h"
 
-#define PP_DPM_DISABLED 0xCCCC
-
 static int pp_dpm_dispatch_tasks(void *handle, enum amd_pp_task task_id,
 		enum amd_pm_state_type *user_state);
 
 static const struct amd_pm_funcs pp_dpm_funcs;
 
-static inline int pp_check(struct pp_hwmgr *hwmgr)
-{
-	if (hwmgr == NULL || hwmgr->smumgr_funcs == NULL)
-		return -EINVAL;
-
-	if (hwmgr->pm_en == 0 || hwmgr->hwmgr_func == NULL)
-		return PP_DPM_DISABLED;
-
-	return 0;
-}
-
 static int amd_powerplay_create(struct amdgpu_device *adev)
 {
 	struct pp_hwmgr *hwmgr;
@@ -73,7 +60,7 @@ static int amd_powerplay_create(struct amdgpu_device *adev)
 }
 
 
-static int amd_powerplay_destroy(struct amdgpu_device *adev)
+static void amd_powerplay_destroy(struct amdgpu_device *adev)
 {
 	struct pp_hwmgr *hwmgr = adev->powerplay.pp_handle;
 
@@ -82,8 +69,6 @@ static int amd_powerplay_destroy(struct amdgpu_device *adev)
 
 	kfree(hwmgr);
 	hwmgr = NULL;
-
-	return 0;
 }
 
 static int pp_early_init(void *handle)
@@ -109,18 +94,9 @@ static int pp_sw_init(void *handle)
 	struct pp_hwmgr *hwmgr = adev->powerplay.pp_handle;
 	int ret = 0;
 
-	ret = pp_check(hwmgr);
-
-	if (ret >= 0) {
-		if (hwmgr->smumgr_funcs->smu_init == NULL)

drivers/gpu/drm/amd/powerplay/amd_powerplay.c static int pp_sw_init(void *handle) · line 99

Quoted 10 lines
drivers/gpu/drm/amd/powerplay/amd_powerplay.c +2 -7
-			return -EINVAL;
+	ret = hwmgr_sw_init(hwmgr);
 
-		ret = hwmgr->smumgr_funcs->smu_init(hwmgr);
-
-		phm_register_irq_handlers(hwmgr);
-
-		pr_debug("amdgpu: powerplay sw initialized\n");
-	}
+	pr_debug("amdgpu: powerplay sw init %s\n", ret ? "failed" : "successfully");

Actually, we don't need to add the prefix like "amdgpu: ", because in pr_* prints, we already added the powerplay specific prefix.

[  105.758104] amdgpu: [powerplay] amdgpu: powerplay sw initialized
                                   ^^^^^^^

The same with comments with other part of this patch.

Thanks,
Ray

Quoted 907 lines
drivers/gpu/drm/amd/powerplay/amd_powerplay.c +5 -30
 	return ret;
 }
@@ -129,13 +105,8 @@ static int pp_sw_fini(void *handle)
 {
 	struct amdgpu_device *adev = handle;
 	struct pp_hwmgr *hwmgr = adev->powerplay.pp_handle;
-	int ret = 0;
 
-	ret = pp_check(hwmgr);
-	if (ret >= 0) {
-		if (hwmgr->smumgr_funcs->smu_fini != NULL)
-			hwmgr->smumgr_funcs->smu_fini(hwmgr);
-	}
+	hwmgr_sw_fini(hwmgr);
 
 	if (adev->firmware.load_type == AMDGPU_FW_LOAD_SMU)
 		amdgpu_ucode_fini_bo(adev);
@@ -152,40 +123,20 @@ static int pp_hw_init(void *handle)
 	if (adev->firmware.load_type == AMDGPU_FW_LOAD_SMU)
 		amdgpu_ucode_init_bo(adev);
 
-	ret = pp_check(hwmgr);
+	ret = hwmgr_hw_init(hwmgr);
 
-	if (ret >= 0) {
-		if (hwmgr->smumgr_funcs->start_smu == NULL)
-			return -EINVAL;
+	if (ret)
+		pr_err("amdgpu: powerplay hw init failed\n");
 
 
 
-		if (hwmgr->smumgr_funcs->start_smu(hwmgr)) {
-			pr_err("smc start failed\n");
-			hwmgr->smumgr_funcs->smu_fini(hwmgr);
-			return -EINVAL;
-		}
-		if (ret == PP_DPM_DISABLED)
-			goto exit;
-		ret = hwmgr_hw_init(hwmgr);
-		if (ret)
-			goto exit;
-	}
 	return ret;
-exit:
-	hwmgr->pm_en = 0;
-	cgs_notify_dpm_enabled(hwmgr->device, false);
-	return 0;
-
 }
 
 static int pp_hw_fini(void *handle)
 {
 	struct amdgpu_device *adev = handle;
 	struct pp_hwmgr *hwmgr = adev->powerplay.pp_handle;
-	int ret = 0;
 
-	ret = pp_check(hwmgr);
-	if (ret == 0)
-		hwmgr_hw_fini(hwmgr);
+	hwmgr_hw_fini(hwmgr);
 
drivers/gpu/drm/amd/powerplay/amd_powerplay.c +75 -228
 	return 0;
 }
@@ -194,11 +145,8 @@ static int pp_late_init(void *handle)
 {
 	struct amdgpu_device *adev = handle;
 	struct pp_hwmgr *hwmgr = adev->powerplay.pp_handle;
-	int ret = 0;
-
-	ret = pp_check(hwmgr);
 
-	if (ret == 0)
+	if (hwmgr && hwmgr->pm_en)
 		pp_dpm_dispatch_tasks(hwmgr,
 					AMD_PP_TASK_COMPLETE_INIT, NULL);
 
@@ -233,12 +181,9 @@ static int pp_set_powergating_state(void *handle,
 {
 	struct amdgpu_device *adev = handle;
 	struct pp_hwmgr *hwmgr = adev->powerplay.pp_handle;
-	int ret = 0;
 
-	ret = pp_check(hwmgr);
-
-	if (ret)
-		return ret;
+	if (!hwmgr || !hwmgr->pm_en)
+		return 0;
 
 	if (hwmgr->hwmgr_func->enable_per_cu_power_gating == NULL) {
 		pr_info("%s was not implemented.\n", __func__);
@@ -254,38 +199,16 @@ static int pp_suspend(void *handle)
 {
 	struct amdgpu_device *adev = handle;
 	struct pp_hwmgr *hwmgr = adev->powerplay.pp_handle;
-	int ret = 0;
 
-	ret = pp_check(hwmgr);
-	if (ret == 0)
-		hwmgr_hw_suspend(hwmgr);
-	return 0;
+	return hwmgr_suspend(hwmgr);
 }
 
 static int pp_resume(void *handle)
 {
 	struct amdgpu_device *adev = handle;
 	struct pp_hwmgr *hwmgr = adev->powerplay.pp_handle;
-	int ret;
-
-	ret = pp_check(hwmgr);
-
-	if (ret < 0)
-		return ret;
-
-	if (hwmgr->smumgr_funcs->start_smu == NULL)
-		return -EINVAL;
-
-	if (hwmgr->smumgr_funcs->start_smu(hwmgr)) {
-		pr_err("smc start failed\n");
-		hwmgr->smumgr_funcs->smu_fini(hwmgr);
-		return -EINVAL;
-	}
-
-	if (ret == PP_DPM_DISABLED)
-		return 0;
 
-	return hwmgr_hw_resume(hwmgr);
+	return hwmgr_resume(hwmgr);
 }
 
 static int pp_set_clockgating_state(void *handle,
@@ -334,12 +257,9 @@ static int pp_dpm_fw_loading_complete(void *handle)
 static int pp_set_clockgating_by_smu(void *handle, uint32_t msg_id)
 {
 	struct pp_hwmgr *hwmgr = handle;
-	int ret = 0;
-
-	ret = pp_check(hwmgr);
 
-	if (ret)
-		return ret;
+	if (!hwmgr || !hwmgr->pm_en)
+		return -EINVAL;
 
 	if (hwmgr->hwmgr_func->update_clock_gatings == NULL) {
 		pr_info("%s was not implemented.\n", __func__);
@@ -389,12 +309,9 @@ static int pp_dpm_force_performance_level(void *handle,
 					enum amd_dpm_forced_level level)
 {
 	struct pp_hwmgr *hwmgr = handle;
-	int ret = 0;
 
-	ret = pp_check(hwmgr);
-
-	if (ret)
-		return ret;
+	if (!hwmgr || !hwmgr->pm_en)
+		return -EINVAL;
 
 	if (level == hwmgr->dpm_level)
 		return 0;
@@ -412,13 +329,10 @@ static enum amd_dpm_forced_level pp_dpm_get_performance_level(
 								void *handle)
 {
 	struct pp_hwmgr *hwmgr = handle;
-	int ret = 0;
 	enum amd_dpm_forced_level level;
 
-	ret = pp_check(hwmgr);
-
-	if (ret)
-		return ret;
+	if (!hwmgr || !hwmgr->pm_en)
+		return -EINVAL;
 
 	mutex_lock(&hwmgr->smu_lock);
 	level = hwmgr->dpm_level;
@@ -429,13 +343,10 @@ static enum amd_dpm_forced_level pp_dpm_get_performance_level(
 static uint32_t pp_dpm_get_sclk(void *handle, bool low)
 {
 	struct pp_hwmgr *hwmgr = handle;
-	int ret = 0;
 	uint32_t clk = 0;
 
-	ret = pp_check(hwmgr);
-
-	if (ret)
-		return ret;
+	if (!hwmgr || !hwmgr->pm_en)
+		return 0;
 
 	if (hwmgr->hwmgr_func->get_sclk == NULL) {
 		pr_info("%s was not implemented.\n", __func__);
@@ -450,13 +361,10 @@ static uint32_t pp_dpm_get_sclk(void *handle, bool low)
 static uint32_t pp_dpm_get_mclk(void *handle, bool low)
 {
 	struct pp_hwmgr *hwmgr = handle;
-	int ret = 0;
 	uint32_t clk = 0;
 
-	ret = pp_check(hwmgr);
-
-	if (ret)
-		return ret;
+	if (!hwmgr || !hwmgr->pm_en)
+		return 0;
 
 	if (hwmgr->hwmgr_func->get_mclk == NULL) {
 		pr_info("%s was not implemented.\n", __func__);
@@ -471,11 +379,8 @@ static uint32_t pp_dpm_get_mclk(void *handle, bool low)
 static void pp_dpm_powergate_vce(void *handle, bool gate)
 {
 	struct pp_hwmgr *hwmgr = handle;
-	int ret = 0;
-
-	ret = pp_check(hwmgr);
 
-	if (ret)
+	if (!hwmgr || !hwmgr->pm_en)
 		return;
 
 	if (hwmgr->hwmgr_func->powergate_vce == NULL) {
@@ -490,11 +395,8 @@ static void pp_dpm_powergate_vce(void *handle, bool gate)
 static void pp_dpm_powergate_uvd(void *handle, bool gate)
 {
 	struct pp_hwmgr *hwmgr = handle;
-	int ret = 0;
-
-	ret = pp_check(hwmgr);
 
-	if (ret)
+	if (!hwmgr || !hwmgr->pm_en)
 		return;
 
 	if (hwmgr->hwmgr_func->powergate_uvd == NULL) {
@@ -512,10 +414,8 @@ static int pp_dpm_dispatch_tasks(void *handle, enum amd_pp_task task_id,
 	int ret = 0;
 	struct pp_hwmgr *hwmgr = handle;
 
-	ret = pp_check(hwmgr);
-
-	if (ret)
-		return ret;
+	if (!hwmgr || !hwmgr->pm_en)
+		return -EINVAL;
 
 	mutex_lock(&hwmgr->smu_lock);
 	ret = hwmgr_handle_task(hwmgr, task_id, user_state);
@@ -528,15 +428,9 @@ static enum amd_pm_state_type pp_dpm_get_current_power_state(void *handle)
 {
 	struct pp_hwmgr *hwmgr = handle;
 	struct pp_power_state *state;
-	int ret = 0;
 	enum amd_pm_state_type pm_type;
 
-	ret = pp_check(hwmgr);
-
-	if (ret)
-		return ret;
-
-	if (hwmgr->current_ps == NULL)
+	if (!hwmgr || !hwmgr->pm_en || !hwmgr->current_ps)
 		return -EINVAL;
 
 	mutex_lock(&hwmgr->smu_lock);
@@ -568,11 +462,8 @@ static enum amd_pm_state_type pp_dpm_get_current_power_state(void *handle)
 static void pp_dpm_set_fan_control_mode(void *handle, uint32_t mode)
 {
 	struct pp_hwmgr *hwmgr = handle;
-	int ret = 0;
-
-	ret = pp_check(hwmgr);
 
-	if (ret)
+	if (!hwmgr || !hwmgr->pm_en)
 		return;
 
 	if (hwmgr->hwmgr_func->set_fan_control_mode == NULL) {
@@ -587,13 +478,10 @@ static void pp_dpm_set_fan_control_mode(void *handle, uint32_t mode)
 static uint32_t pp_dpm_get_fan_control_mode(void *handle)
 {
 	struct pp_hwmgr *hwmgr = handle;
-	int ret = 0;
 	uint32_t mode = 0;
 
-	ret = pp_check(hwmgr);
-
-	if (ret)
-		return ret;
+	if (!hwmgr || !hwmgr->pm_en)
+		return 0;
 
 	if (hwmgr->hwmgr_func->get_fan_control_mode == NULL) {
 		pr_info("%s was not implemented.\n", __func__);
@@ -610,10 +498,8 @@ static int pp_dpm_set_fan_speed_percent(void *handle, uint32_t percent)
 	struct pp_hwmgr *hwmgr = handle;
 	int ret = 0;
 
-	ret = pp_check(hwmgr);
-
-	if (ret)
-		return ret;
+	if (!hwmgr || !hwmgr->pm_en)
+		return -EINVAL;
 
 	if (hwmgr->hwmgr_func->set_fan_speed_percent == NULL) {
 		pr_info("%s was not implemented.\n", __func__);
@@ -630,10 +516,8 @@ static int pp_dpm_get_fan_speed_percent(void *handle, uint32_t *speed)
 	struct pp_hwmgr *hwmgr = handle;
 	int ret = 0;
 
-	ret = pp_check(hwmgr);
-
-	if (ret)
-		return ret;
+	if (!hwmgr || !hwmgr->pm_en)
+		return -EINVAL;
 
 	if (hwmgr->hwmgr_func->get_fan_speed_percent == NULL) {
 		pr_info("%s was not implemented.\n", __func__);
@@ -651,10 +535,8 @@ static int pp_dpm_get_fan_speed_rpm(void *handle, uint32_t *rpm)
 	struct pp_hwmgr *hwmgr = handle;
 	int ret = 0;
 
-	ret = pp_check(hwmgr);
-
-	if (ret)
-		return ret;
+	if (!hwmgr || !hwmgr->pm_en)
+		return -EINVAL;
 
 	if (hwmgr->hwmgr_func->get_fan_speed_rpm == NULL)
 		return -EINVAL;
@@ -670,16 +552,10 @@ static int pp_dpm_get_pp_num_states(void *handle,
 {
 	struct pp_hwmgr *hwmgr = handle;
 	int i;
-	int ret = 0;
 
 	memset(data, 0, sizeof(*data));
 
-	ret = pp_check(hwmgr);
-
-	if (ret)
-		return ret;
-
-	if (hwmgr->ps == NULL)
+	if (!hwmgr || !hwmgr->pm_en ||!hwmgr->ps)
 		return -EINVAL;
 
 	mutex_lock(&hwmgr->smu_lock);
@@ -713,15 +589,9 @@ static int pp_dpm_get_pp_num_states(void *handle,
 static int pp_dpm_get_pp_table(void *handle, char **table)
 {
 	struct pp_hwmgr *hwmgr = handle;
-	int ret = 0;
 	int size = 0;
 
-	ret = pp_check(hwmgr);
-
-	if (ret)
-		return ret;
-
-	if (!hwmgr->soft_pp_table)
+	if (!hwmgr || !hwmgr->pm_en ||!hwmgr->soft_pp_table)
 		return -EINVAL;
 
 	mutex_lock(&hwmgr->smu_lock);
@@ -736,10 +606,6 @@ static int amd_powerplay_reset(void *handle)
 	struct pp_hwmgr *hwmgr = handle;
 	int ret;
 
-	ret = pp_check(hwmgr);
-	if (ret)
-		return ret;
-
 	ret = hwmgr_hw_fini(hwmgr);
 	if (ret)
 		return ret;
@@ -756,10 +622,8 @@ static int pp_dpm_set_pp_table(void *handle, const char *buf, size_t size)
 	struct pp_hwmgr *hwmgr = handle;
 	int ret = 0;
 
-	ret = pp_check(hwmgr);
-
-	if (ret)
-		return ret;
+	if (!hwmgr || !hwmgr->pm_en)
+		return -EINVAL;
 
 	mutex_lock(&hwmgr->smu_lock);
 	if (!hwmgr->hardcode_pp_table) {
@@ -796,10 +660,8 @@ static int pp_dpm_force_clock_level(void *handle,
 	struct pp_hwmgr *hwmgr = handle;
 	int ret = 0;
 
-	ret = pp_check(hwmgr);
-
-	if (ret)
-		return ret;
+	if (!hwmgr || !hwmgr->pm_en)
+		return -EINVAL;
 
 	if (hwmgr->hwmgr_func->force_clock_level == NULL) {
 		pr_info("%s was not implemented.\n", __func__);
@@ -820,10 +682,8 @@ static int pp_dpm_print_clock_levels(void *handle,
 	struct pp_hwmgr *hwmgr = handle;
 	int ret = 0;
 
-	ret = pp_check(hwmgr);
-
-	if (ret)
-		return ret;
+	if (!hwmgr || !hwmgr->pm_en)
+		return -EINVAL;
 
 	if (hwmgr->hwmgr_func->print_clock_levels == NULL) {
 		pr_info("%s was not implemented.\n", __func__);
@@ -840,10 +700,8 @@ static int pp_dpm_get_sclk_od(void *handle)
 	struct pp_hwmgr *hwmgr = handle;
 	int ret = 0;
 
-	ret = pp_check(hwmgr);
-
-	if (ret)
-		return ret;
+	if (!hwmgr || !hwmgr->pm_en)
+		return -EINVAL;
 
 	if (hwmgr->hwmgr_func->get_sclk_od == NULL) {
 		pr_info("%s was not implemented.\n", __func__);
@@ -860,10 +718,8 @@ static int pp_dpm_set_sclk_od(void *handle, uint32_t value)
 	struct pp_hwmgr *hwmgr = handle;
 	int ret = 0;
 
-	ret = pp_check(hwmgr);
-
-	if (ret)
-		return ret;
+	if (!hwmgr || !hwmgr->pm_en)
+		return -EINVAL;
 
 	if (hwmgr->hwmgr_func->set_sclk_od == NULL) {
 		pr_info("%s was not implemented.\n", __func__);
@@ -881,10 +737,8 @@ static int pp_dpm_get_mclk_od(void *handle)
 	struct pp_hwmgr *hwmgr = handle;
 	int ret = 0;
 
-	ret = pp_check(hwmgr);
-
-	if (ret)
-		return ret;
+	if (!hwmgr || !hwmgr->pm_en)
+		return -EINVAL;
 
 	if (hwmgr->hwmgr_func->get_mclk_od == NULL) {
 		pr_info("%s was not implemented.\n", __func__);
@@ -901,10 +755,8 @@ static int pp_dpm_set_mclk_od(void *handle, uint32_t value)
 	struct pp_hwmgr *hwmgr = handle;
 	int ret = 0;
 
-	ret = pp_check(hwmgr);
-
-	if (ret)
-		return ret;
+	if (!hwmgr || !hwmgr->pm_en)
+		return -EINVAL;
 
 	if (hwmgr->hwmgr_func->set_mclk_od == NULL) {
 		pr_info("%s was not implemented.\n", __func__);
@@ -922,11 +774,7 @@ static int pp_dpm_read_sensor(void *handle, int idx,
 	struct pp_hwmgr *hwmgr = handle;
 	int ret = 0;
 
-	ret = pp_check(hwmgr);
-	if (ret)
-		return ret;
-
-	if (value == NULL)
+	if (!hwmgr || !hwmgr->pm_en || !value)
 		return -EINVAL;
 
 	switch (idx) {
@@ -948,14 +796,11 @@ static int pp_dpm_read_sensor(void *handle, int idx,
 pp_dpm_get_vce_clock_state(void *handle, unsigned idx)
 {
 	struct pp_hwmgr *hwmgr = handle;
-	int ret = 0;
-
-	ret = pp_check(hwmgr);
 
-	if (ret)
+	if (!hwmgr || !hwmgr->pm_en)
 		return NULL;
 
-	if (hwmgr && idx < hwmgr->num_vce_state_tables)
+	if (idx < hwmgr->num_vce_state_tables)
 		return &hwmgr->vce_states[idx];
 	return NULL;
 }
@@ -964,7 +809,7 @@ static int pp_get_power_profile_mode(void *handle, char *buf)
 {
 	struct pp_hwmgr *hwmgr = handle;
 
-	if (!buf || pp_check(hwmgr))
+	if (!hwmgr || !hwmgr->pm_en || !buf)
 		return -EINVAL;
 
 	if (hwmgr->hwmgr_func->get_power_profile_mode == NULL) {
@@ -980,12 +825,12 @@ static int pp_set_power_profile_mode(void *handle, long *input, uint32_t size)
 	struct pp_hwmgr *hwmgr = handle;
 	int ret = -EINVAL;
 
-	if (pp_check(hwmgr))
-		return -EINVAL;
+	if (!hwmgr || !hwmgr->pm_en)
+		return ret;
 
 	if (hwmgr->hwmgr_func->set_power_profile_mode == NULL) {
 		pr_info("%s was not implemented.\n", __func__);
-		return -EINVAL;
+		return ret;
 	}
 	mutex_lock(&hwmgr->smu_lock);
 	if (hwmgr->dpm_level == AMD_DPM_FORCED_LEVEL_MANUAL)
@@ -998,7 +843,7 @@ static int pp_odn_edit_dpm_table(void *handle, uint32_t type, long *input, uint3
 {
 	struct pp_hwmgr *hwmgr = handle;
 
-	if (pp_check(hwmgr))
+	if (!hwmgr || !hwmgr->pm_en)
 		return -EINVAL;
 
 	if (hwmgr->hwmgr_func->odn_edit_dpm_table == NULL) {
@@ -1016,7 +861,7 @@ static int pp_dpm_switch_power_profile(void *handle,
 	long workload;
 	uint32_t index;
 
-	if (pp_check(hwmgr))
+	if (!hwmgr || !hwmgr->pm_en)
 		return -EINVAL;
 
 	if (hwmgr->hwmgr_func->set_power_profile_mode == NULL) {
@@ -1058,10 +903,8 @@ static int pp_dpm_notify_smu_memory_info(void *handle,
 	struct pp_hwmgr *hwmgr = handle;
 	int ret = 0;
 
-	ret = pp_check(hwmgr);
-
-	if (ret)
-		return ret;
+	if (!hwmgr || !hwmgr->pm_en)
+		return -EINVAL;
 
 	if (hwmgr->hwmgr_func->notify_cac_buffer_info == NULL) {
 		pr_info("%s was not implemented.\n", __func__);
@@ -1082,12 +925,9 @@ static int pp_dpm_notify_smu_memory_info(void *handle,
 static int pp_set_power_limit(void *handle, uint32_t limit)
 {
 	struct pp_hwmgr *hwmgr = handle;
-	int ret = 0;
-
-	ret = pp_check(hwmgr);
 
-	if (ret)
-		return ret;
+	if (!hwmgr || !hwmgr->pm_en)
+		return -EINVAL;
 
 	if (hwmgr->hwmgr_func->set_power_limit == NULL) {
 		pr_info("%s was not implemented.\n", __func__);
@@ -1104,20 +944,14 @@ static int pp_set_power_limit(void *handle, uint32_t limit)
 	hwmgr->hwmgr_func->set_power_limit(hwmgr, limit);
 	hwmgr->power_limit = limit;
 	mutex_unlock(&hwmgr->smu_lock);
-	return ret;
+	return 0;
 }
 
 static int pp_get_power_limit(void *handle, uint32_t *limit, bool default_limit)
 {
 	struct pp_hwmgr *hwmgr = handle;
-	int ret = 0;
-
-	ret = pp_check(hwmgr);
 
-	if (ret)
-		return ret;
-
-	if (limit == NULL)
+	if (!hwmgr || !hwmgr->pm_en ||!limit)
 		return -EINVAL;
 
 	mutex_lock(&hwmgr->smu_lock);
@@ -1129,19 +963,16 @@ static int pp_get_power_limit(void *handle, uint32_t *limit, bool default_limit)
 
 	mutex_unlock(&hwmgr->smu_lock);
 
-	return ret;
+	return 0;
 }
 
 static int pp_display_configuration_change(void *handle,
 	const struct amd_pp_display_configuration *display_config)
 {
 	struct pp_hwmgr *hwmgr = handle;
-	int ret = 0;
-
-	ret = pp_check(hwmgr);
 
-	if (ret)
-		return ret;
+	if (!hwmgr || !hwmgr->pm_en)
+		return -EINVAL;
 
 	mutex_lock(&hwmgr->smu_lock);
 	phm_store_dal_configuration_data(hwmgr, display_config);
@@ -1155,12 +986,7 @@ static int pp_get_display_power_level(void *handle,
 	struct pp_hwmgr *hwmgr = handle;
 	int ret = 0;
 
-	ret = pp_check(hwmgr);
-
-	if (ret)
-		return ret;
-
-	if (output == NULL)
+	if (!hwmgr || !hwmgr->pm_en ||!output)
 		return -EINVAL;
 
 	mutex_lock(&hwmgr->smu_lock);
@@ -1177,10 +1003,8 @@ static int pp_get_current_clocks(void *handle,
 	struct pp_hwmgr *hwmgr = handle;
 	int ret = 0;
 
-	ret = pp_check(hwmgr);
-
-	if (ret)
-		return ret;
+	if (!hwmgr || !hwmgr->pm_en)
+		return -EINVAL;
 
 	mutex_lock(&hwmgr->smu_lock);
 
@@ -1225,10 +1049,8 @@ static int pp_get_clock_by_type(void *handle, enum amd_pp_clock_type type, struc
 	struct pp_hwmgr *hwmgr = handle;
 	int ret = 0;
 
-	ret = pp_check(hwmgr);
-
-	if (ret)
-		return ret;
+	if (!hwmgr || !hwmgr->pm_en)
+		return -EINVAL;
 
 	if (clocks == NULL)
 		return -EINVAL;
@@ -1246,11 +1068,7 @@ static int pp_get_clock_by_type_with_latency(void *handle,
 	struct pp_hwmgr *hwmgr = handle;
 	int ret = 0;
 
-	ret = pp_check(hwmgr);
-	if (ret)
-		return ret;
-
-	if (!clocks)
+	if (!hwmgr || !hwmgr->pm_en ||!clocks)
 		return -EINVAL;
 
 	mutex_lock(&hwmgr->smu_lock);
@@ -1266,11 +1084,7 @@ static int pp_get_clock_by_type_with_voltage(void *handle,
 	struct pp_hwmgr *hwmgr = handle;
 	int ret = 0;
 
-	ret = pp_check(hwmgr);
-	if (ret)
-		return ret;
-
-	if (!clocks)
+	if (!hwmgr || !hwmgr->pm_en ||!clocks)
 		return -EINVAL;
 
 	mutex_lock(&hwmgr->smu_lock);
@@ -1287,11 +1101,7 @@ static int pp_set_watermarks_for_clocks_ranges(void *handle,
 	struct pp_hwmgr *hwmgr = handle;
 	int ret = 0;
 
-	ret = pp_check(hwmgr);
-	if (ret)
-		return ret;
-
-	if (!wm_with_clock_ranges)
+	if (!hwmgr || !hwmgr->pm_en ||!wm_with_clock_ranges)
 		return -EINVAL;
 
 	mutex_lock(&hwmgr->smu_lock);
@@ -1308,11 +1118,7 @@ static int pp_display_clock_voltage_request(void *handle,
 	struct pp_hwmgr *hwmgr = handle;
 	int ret = 0;
 
-	ret = pp_check(hwmgr);
-	if (ret)
-		return ret;
-
-	if (!clock)
+	if (!hwmgr || !hwmgr->pm_en ||!clock)
 		return -EINVAL;
 
 	mutex_lock(&hwmgr->smu_lock);
@@ -1328,12 +1134,7 @@ static int pp_get_display_mode_validation_clocks(void *handle,
 	struct pp_hwmgr *hwmgr = handle;
 	int ret = 0;
 
-	ret = pp_check(hwmgr);
-
-	if (ret)
-		return ret;
-
-	if (clocks == NULL)
+	if (!hwmgr || !hwmgr->pm_en ||!clocks)
 		return -EINVAL;
 
 	mutex_lock(&hwmgr->smu_lock);
@@ -1348,12 +1149,9 @@ static int pp_get_display_mode_validation_clocks(void *handle,
 static int pp_set_mmhub_powergating_by_smu(void *handle)
 {
 	struct pp_hwmgr *hwmgr = handle;
-	int ret = 0;
-
-	ret = pp_check(hwmgr);
 
-	if (ret)
-		return ret;
+	if (!hwmgr || !hwmgr->pm_en)
+		return -EINVAL;
 
 	if (hwmgr->hwmgr_func->set_mmhub_powergating_by_smu == NULL) {
 		pr_info("%s was not implemented.\n", __func__);
drivers/gpu/drm/amd/powerplay/hwmgr/hwmgr.c +57 -17
index 4298205..96a2d01 100644
@@ -76,7 +76,7 @@ static void hwmgr_init_workload_prority(struct pp_hwmgr *hwmgr)
 
 int hwmgr_early_init(struct pp_hwmgr *hwmgr)
 {
-	if (hwmgr == NULL)
+	if (!hwmgr)
 		return -EINVAL;
 
 	hwmgr->usec_timeout = AMD_MAX_USEC_TIMEOUT;
@@ -170,17 +170,51 @@ int hwmgr_early_init(struct pp_hwmgr *hwmgr)
 	return 0;
 }
 
+int hwmgr_sw_init(struct pp_hwmgr *hwmgr)
+{
+	if (!hwmgr|| !hwmgr->smumgr_funcs || !hwmgr->smumgr_funcs->smu_init)
+		return -EINVAL;
+
+	phm_register_irq_handlers(hwmgr);
+
+	return hwmgr->smumgr_funcs->smu_init(hwmgr);
+}
+
+
+int hwmgr_sw_fini(struct pp_hwmgr *hwmgr)
+{
+	if (hwmgr && hwmgr->smumgr_funcs && hwmgr->smumgr_funcs->smu_fini)
+		hwmgr->smumgr_funcs->smu_fini(hwmgr);
+
+	return 0;
+}
+
 int hwmgr_hw_init(struct pp_hwmgr *hwmgr)
 {
 	int ret = 0;
 
-	if (hwmgr == NULL)
+	if (!hwmgr || !hwmgr->smumgr_funcs)
 		return -EINVAL;
 
-	if (hwmgr->pptable_func == NULL ||
-	    hwmgr->pptable_func->pptable_init == NULL ||
-	    hwmgr->hwmgr_func->backend_init == NULL)
-		return -EINVAL;
+	if (hwmgr->smumgr_funcs->start_smu) {
+		ret = hwmgr->smumgr_funcs->start_smu(hwmgr);
+		if (ret) {
+			pr_err("smc start failed\n");
+			return -EINVAL;
+		}
+	}
+
+	if (!hwmgr->pm_en)
+		return 0;
+
+	if (!hwmgr->pptable_func ||
+	    !hwmgr->pptable_func->pptable_init ||
+	    !hwmgr->hwmgr_func->backend_init) {
+		hwmgr->pm_en = false;
+		cgs_notify_dpm_enabled(hwmgr->device, false);
+		pr_info("dpm not supported \n");
+		return 0;
+	}
 
 	ret = hwmgr->pptable_func->pptable_init(hwmgr);
 	if (ret)
@@ -214,14 +248,13 @@ int hwmgr_hw_init(struct pp_hwmgr *hwmgr)
 	if (hwmgr->pptable_func->pptable_fini)
 		hwmgr->pptable_func->pptable_fini(hwmgr);
 err:
-	pr_err("amdgpu: powerplay initialization failed\n");
 	return ret;
 }
 
 int hwmgr_hw_fini(struct pp_hwmgr *hwmgr)
 {
-	if (hwmgr == NULL)
-		return -EINVAL;
+	if (!hwmgr || !hwmgr->pm_en)
+		return 0;
 
 	phm_stop_thermal_controller(hwmgr);
 	psm_set_boot_states(hwmgr);
@@ -236,12 +269,12 @@ int hwmgr_hw_fini(struct pp_hwmgr *hwmgr)
 	return psm_fini_power_state_table(hwmgr);
 }
 
-int hwmgr_hw_suspend(struct pp_hwmgr *hwmgr)
+int hwmgr_suspend(struct pp_hwmgr *hwmgr)
 {
 	int ret = 0;
 
-	if (hwmgr == NULL)
-		return -EINVAL;
+	if (!hwmgr || !hwmgr->pm_en)
+		return 0;
 
 	phm_disable_smc_firmware_ctf(hwmgr);
 	ret = psm_set_boot_states(hwmgr);
@@ -255,13 +288,23 @@ int hwmgr_hw_suspend(struct pp_hwmgr *hwmgr)
 	return ret;
 }
 
-int hwmgr_hw_resume(struct pp_hwmgr *hwmgr)
+int hwmgr_resume(struct pp_hwmgr *hwmgr)
 {
 	int ret = 0;
 
-	if (hwmgr == NULL)
+	if (!hwmgr)
 		return -EINVAL;
 
+	if (hwmgr->smumgr_funcs && hwmgr->smumgr_funcs->start_smu) {
+		if (hwmgr->smumgr_funcs->start_smu(hwmgr)) {
+			pr_err("smc start failed\n");
+			return -EINVAL;
+		}
+	}
+
+	if (!hwmgr->pm_en)
+		return 0;
+
 	ret = phm_setup_asic(hwmgr);
 	if (ret)
 		return ret;
@@ -270,9 +313,6 @@ int hwmgr_hw_resume(struct pp_hwmgr *hwmgr)
 	if (ret)
 		return ret;
 	ret = phm_start_thermal_controller(hwmgr);
-	if (ret)
-		return ret;
-
 	ret |= psm_set_performance_states(hwmgr);
 	if (ret)
 		return ret;
drivers/gpu/drm/amd/powerplay/inc/hwmgr.h +5 -2
index 17f811d..d6c9a3b 100644
@@ -782,10 +782,13 @@ struct pp_hwmgr {
 };
 
 int hwmgr_early_init(struct pp_hwmgr *hwmgr);
+int hwmgr_sw_init(struct pp_hwmgr *hwmgr);
+int hwmgr_sw_fini(struct pp_hwmgr *hwmgr);
 int hwmgr_hw_init(struct pp_hwmgr *hwmgr);
 int hwmgr_hw_fini(struct pp_hwmgr *hwmgr);
-int hwmgr_hw_suspend(struct pp_hwmgr *hwmgr);
-int hwmgr_hw_resume(struct pp_hwmgr *hwmgr);
+int hwmgr_suspend(struct pp_hwmgr *hwmgr);
+int hwmgr_resume(struct pp_hwmgr *hwmgr);
+
 int hwmgr_handle_task(struct pp_hwmgr *hwmgr,
 				enum amd_pp_task task_id,
 				enum amd_pm_state_type *user_state);
Signature · 6 lines
1.9.1

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

author
#12 lore raw

RE: [PATCH 2/6] drm/amd/pp: Add hwmgr_sw_init/fini functioins

Good.
Thanks

Best Regards
Rex

-----Original Message-----
From: Huang Rui [mailto:[email protected]]
Sent: Friday, March 23, 2018 9:49 AM
To: Zhu, Rex
Cc: [email protected]
Subject: Re: [PATCH 2/6] drm/amd/pp: Add hwmgr_sw_init/fini functioins

Quoted 66 lines · Rex Zhu

Clean up pp ip functions

Change-Id Id06159202edabdfcb19fcc20e1291ce93db56d5d
---
 drivers/gpu/drm/amd/powerplay/amd_powerplay.c | 368 ++++++--------------------
 drivers/gpu/drm/amd/powerplay/hwmgr/hwmgr.c   |  74 ++++--
 drivers/gpu/drm/amd/powerplay/inc/hwmgr.h     |   7 +-
 3 files changed, 145 insertions(+), 304 deletions(-)
drivers/gpu/drm/amd/powerplay/amd_powerplay.c +1 -15
index 7e8ad30..5d7d9ec 100644
@@ -31,24 +31,11 @@
 #include "amdgpu.h"
 #include "hwmgr.h"
 
-#define PP_DPM_DISABLED 0xCCCC
-
 static int pp_dpm_dispatch_tasks(void *handle, enum amd_pp_task task_id,
 		enum amd_pm_state_type *user_state);
 
 static const struct amd_pm_funcs pp_dpm_funcs;
 
-static inline int pp_check(struct pp_hwmgr *hwmgr) -{
-	if (hwmgr == NULL || hwmgr->smumgr_funcs == NULL)
-		return -EINVAL;
-
-	if (hwmgr->pm_en == 0 || hwmgr->hwmgr_func == NULL)
-		return PP_DPM_DISABLED;
-
-	return 0;
-}
-
 static int amd_powerplay_create(struct amdgpu_device *adev)  {
 	struct pp_hwmgr *hwmgr;
@@ -73,7 +60,7 @@ static int amd_powerplay_create(struct amdgpu_device 
 *adev)  }
 
 
-static int amd_powerplay_destroy(struct amdgpu_device *adev)
+static void amd_powerplay_destroy(struct amdgpu_device *adev)
 {
 	struct pp_hwmgr *hwmgr = adev->powerplay.pp_handle;
 
@@ -82,8 +69,6 @@ static int amd_powerplay_destroy(struct 
 amdgpu_device *adev)
 
 	kfree(hwmgr);
 	hwmgr = NULL;
-
-	return 0;
 }
 

static int pp_early_init(void *handle) @@ -109,18 +94,9 @@ static int
pp_sw_init(void *handle)

drivers/gpu/drm/amd/powerplay/amd_powerplay.c +0 -5
 	struct pp_hwmgr *hwmgr = adev->powerplay.pp_handle;
 	int ret = 0;
 
-	ret = pp_check(hwmgr);
-
-	if (ret >= 0) {
-		if (hwmgr->smumgr_funcs->smu_init == NULL)
-			return -EINVAL;

drivers/gpu/drm/amd/powerplay/amd_powerplay.c static int pp_sw_init(void *handle)

Quoted 10 lines
drivers/gpu/drm/amd/powerplay/amd_powerplay.c +3 -6
+	ret = hwmgr_sw_init(hwmgr);
 
-		ret = hwmgr->smumgr_funcs->smu_init(hwmgr);
-
-		phm_register_irq_handlers(hwmgr);
-
-		pr_debug("amdgpu: powerplay sw initialized\n");
-	}
+	pr_debug("amdgpu: powerplay sw init %s\n", ret ? "failed" : 
+"successfully");

Actually, we don't need to add the prefix like "amdgpu: ", because in pr_* prints, we already added the powerplay specific prefix.

[  105.758104] amdgpu: [powerplay] amdgpu: powerplay sw initialized
                                   ^^^^^^^

The same with comments with other part of this patch.

Thanks,
Ray

Quoted 888 lines
drivers/gpu/drm/amd/powerplay/amd_powerplay.c +5 -30
 	return ret;
 }
@@ -129,13 +105,8 @@ static int pp_sw_fini(void *handle)  {
 	struct amdgpu_device *adev = handle;
 	struct pp_hwmgr *hwmgr = adev->powerplay.pp_handle;
-	int ret = 0;
 
-	ret = pp_check(hwmgr);
-	if (ret >= 0) {
-		if (hwmgr->smumgr_funcs->smu_fini != NULL)
-			hwmgr->smumgr_funcs->smu_fini(hwmgr);
-	}
+	hwmgr_sw_fini(hwmgr);
 
 	if (adev->firmware.load_type == AMDGPU_FW_LOAD_SMU)
 		amdgpu_ucode_fini_bo(adev);
@@ -152,40 +123,20 @@ static int pp_hw_init(void *handle)
 	if (adev->firmware.load_type == AMDGPU_FW_LOAD_SMU)
 		amdgpu_ucode_init_bo(adev);
 
-	ret = pp_check(hwmgr);
+	ret = hwmgr_hw_init(hwmgr);
 
-	if (ret >= 0) {
-		if (hwmgr->smumgr_funcs->start_smu == NULL)
-			return -EINVAL;
+	if (ret)
+		pr_err("amdgpu: powerplay hw init failed\n");
 
 
 
-		if (hwmgr->smumgr_funcs->start_smu(hwmgr)) {
-			pr_err("smc start failed\n");
-			hwmgr->smumgr_funcs->smu_fini(hwmgr);
-			return -EINVAL;
-		}
-		if (ret == PP_DPM_DISABLED)
-			goto exit;
-		ret = hwmgr_hw_init(hwmgr);
-		if (ret)
-			goto exit;
-	}
 	return ret;
-exit:
-	hwmgr->pm_en = 0;
-	cgs_notify_dpm_enabled(hwmgr->device, false);
-	return 0;
-
 }
 
 static int pp_hw_fini(void *handle)
 {
 	struct amdgpu_device *adev = handle;
 	struct pp_hwmgr *hwmgr = adev->powerplay.pp_handle;
-	int ret = 0;
 
-	ret = pp_check(hwmgr);
-	if (ret == 0)
-		hwmgr_hw_fini(hwmgr);
+	hwmgr_hw_fini(hwmgr);
 
drivers/gpu/drm/amd/powerplay/amd_powerplay.c +3 -9
 	return 0;
 }
@@ -194,11 +145,8 @@ static int pp_late_init(void *handle)  {
 	struct amdgpu_device *adev = handle;
 	struct pp_hwmgr *hwmgr = adev->powerplay.pp_handle;
-	int ret = 0;
-
-	ret = pp_check(hwmgr);
 
-	if (ret == 0)
+	if (hwmgr && hwmgr->pm_en)
 		pp_dpm_dispatch_tasks(hwmgr,
 					AMD_PP_TASK_COMPLETE_INIT, NULL);
 
@@ -233,12 +181,9 @@ static int pp_set_powergating_state(void *handle,  
 {
 	struct amdgpu_device *adev = handle;
 	struct pp_hwmgr *hwmgr = adev->powerplay.pp_handle;
-	int ret = 0;
 
-	ret = pp_check(hwmgr);
-
-	if (ret)
-		return ret;
+	if (!hwmgr || !hwmgr->pm_en)
+		return 0;
 
 	if (hwmgr->hwmgr_func->enable_per_cu_power_gating == NULL) {
 		pr_info("%s was not implemented.\n", __func__); @@ -254,38 +199,16 

@@ static int pp_suspend(void *handle) {

drivers/gpu/drm/amd/powerplay/amd_powerplay.c +2 -24
 	struct amdgpu_device *adev = handle;
 	struct pp_hwmgr *hwmgr = adev->powerplay.pp_handle;
-	int ret = 0;
 
-	ret = pp_check(hwmgr);
-	if (ret == 0)
-		hwmgr_hw_suspend(hwmgr);
-	return 0;
+	return hwmgr_suspend(hwmgr);
 }
 
 static int pp_resume(void *handle)
 {
 	struct amdgpu_device *adev = handle;
 	struct pp_hwmgr *hwmgr = adev->powerplay.pp_handle;
-	int ret;
-
-	ret = pp_check(hwmgr);
-
-	if (ret < 0)
-		return ret;
-
-	if (hwmgr->smumgr_funcs->start_smu == NULL)
-		return -EINVAL;
-
-	if (hwmgr->smumgr_funcs->start_smu(hwmgr)) {
-		pr_err("smc start failed\n");
-		hwmgr->smumgr_funcs->smu_fini(hwmgr);
-		return -EINVAL;
-	}
-
-	if (ret == PP_DPM_DISABLED)
-		return 0;
 
-	return hwmgr_hw_resume(hwmgr);
+	return hwmgr_resume(hwmgr);
 }
 
 static int pp_set_clockgating_state(void *handle, @@ -334,12 +257,9 

@@ static int pp_dpm_fw_loading_complete(void *handle) static int pp_set_clockgating_by_smu(void *handle, uint32_t msg_id) {

drivers/gpu/drm/amd/powerplay/amd_powerplay.c +2 -5
 	struct pp_hwmgr *hwmgr = handle;
-	int ret = 0;
-
-	ret = pp_check(hwmgr);
 
-	if (ret)
-		return ret;
+	if (!hwmgr || !hwmgr->pm_en)
+		return -EINVAL;
 
 	if (hwmgr->hwmgr_func->update_clock_gatings == NULL) {
 		pr_info("%s was not implemented.\n", __func__); @@ -389,12 +309,9 

@@ static int pp_dpm_force_performance_level(void *handle,

drivers/gpu/drm/amd/powerplay/amd_powerplay.c +4 -10
 					enum amd_dpm_forced_level level)  {
 	struct pp_hwmgr *hwmgr = handle;
-	int ret = 0;
 
-	ret = pp_check(hwmgr);
-
-	if (ret)
-		return ret;
+	if (!hwmgr || !hwmgr->pm_en)
+		return -EINVAL;
 
 	if (level == hwmgr->dpm_level)
 		return 0;
@@ -412,13 +329,10 @@ static enum amd_dpm_forced_level pp_dpm_get_performance_level(
 								void *handle)
 {
 	struct pp_hwmgr *hwmgr = handle;
-	int ret = 0;
 	enum amd_dpm_forced_level level;
 
-	ret = pp_check(hwmgr);
-
-	if (ret)
-		return ret;
+	if (!hwmgr || !hwmgr->pm_en)
+		return -EINVAL;
 
 	mutex_lock(&hwmgr->smu_lock);
 	level = hwmgr->dpm_level;
@@ -429,13 +343,10 @@ static enum amd_dpm_forced_level 

pp_dpm_get_performance_level( static uint32_t pp_dpm_get_sclk(void *handle, bool low) {

drivers/gpu/drm/amd/powerplay/amd_powerplay.c +2 -5
 	struct pp_hwmgr *hwmgr = handle;
-	int ret = 0;
 	uint32_t clk = 0;
 
-	ret = pp_check(hwmgr);
-
-	if (ret)
-		return ret;
+	if (!hwmgr || !hwmgr->pm_en)
+		return 0;
 
 	if (hwmgr->hwmgr_func->get_sclk == NULL) {
 		pr_info("%s was not implemented.\n", __func__); @@ -450,13 +361,10 

@@ static uint32_t pp_dpm_get_sclk(void *handle, bool low) static uint32_t pp_dpm_get_mclk(void *handle, bool low) {

drivers/gpu/drm/amd/powerplay/amd_powerplay.c +2 -5
 	struct pp_hwmgr *hwmgr = handle;
-	int ret = 0;
 	uint32_t clk = 0;
 
-	ret = pp_check(hwmgr);
-
-	if (ret)
-		return ret;
+	if (!hwmgr || !hwmgr->pm_en)
+		return 0;
 
 	if (hwmgr->hwmgr_func->get_mclk == NULL) {
 		pr_info("%s was not implemented.\n", __func__); @@ -471,11 +379,8 

@@ static uint32_t pp_dpm_get_mclk(void *handle, bool low) static void pp_dpm_powergate_vce(void *handle, bool gate) {

drivers/gpu/drm/amd/powerplay/amd_powerplay.c +1 -4
 	struct pp_hwmgr *hwmgr = handle;
-	int ret = 0;
-
-	ret = pp_check(hwmgr);
 
-	if (ret)
+	if (!hwmgr || !hwmgr->pm_en)
 		return;
 
 	if (hwmgr->hwmgr_func->powergate_vce == NULL) { @@ -490,11 +395,8 @@ 

static void pp_dpm_powergate_vce(void *handle, bool gate) static void pp_dpm_powergate_uvd(void *handle, bool gate) {

drivers/gpu/drm/amd/powerplay/amd_powerplay.c +1 -4
 	struct pp_hwmgr *hwmgr = handle;
-	int ret = 0;
-
-	ret = pp_check(hwmgr);
 
-	if (ret)
+	if (!hwmgr || !hwmgr->pm_en)
 		return;
 
 	if (hwmgr->hwmgr_func->powergate_uvd == NULL) { @@ -512,10 +414,8 @@ 

static int pp_dpm_dispatch_tasks(void *handle, enum amd_pp_task task_id,

drivers/gpu/drm/amd/powerplay/amd_powerplay.c +3 -4
 	int ret = 0;
 	struct pp_hwmgr *hwmgr = handle;
 
-	ret = pp_check(hwmgr);
-
-	if (ret)
-		return ret;
+	if (!hwmgr || !hwmgr->pm_en)
+		return -EINVAL;
 
 	mutex_lock(&hwmgr->smu_lock);
 	ret = hwmgr_handle_task(hwmgr, task_id, user_state); @@ -528,15 
+428,9 @@ static enum amd_pm_state_type 

pp_dpm_get_current_power_state(void *handle) {

drivers/gpu/drm/amd/powerplay/amd_powerplay.c +1 -7
 	struct pp_hwmgr *hwmgr = handle;
 	struct pp_power_state *state;
-	int ret = 0;
 	enum amd_pm_state_type pm_type;
 
-	ret = pp_check(hwmgr);
-
-	if (ret)
-		return ret;
-
-	if (hwmgr->current_ps == NULL)
+	if (!hwmgr || !hwmgr->pm_en || !hwmgr->current_ps)
 		return -EINVAL;
 
 	mutex_lock(&hwmgr->smu_lock);
@@ -568,11 +462,8 @@ static enum amd_pm_state_type 

pp_dpm_get_current_power_state(void *handle) static void pp_dpm_set_fan_control_mode(void *handle, uint32_t mode) {

drivers/gpu/drm/amd/powerplay/amd_powerplay.c +2 -4
 	struct pp_hwmgr *hwmgr = handle;
-	int ret = 0;
-
-	ret = pp_check(hwmgr);
 
-	if (ret)
+	if (!hwmgr || !hwmgr->pm_en)
 		return;
 
 	if (hwmgr->hwmgr_func->set_fan_control_mode == NULL) { @@ -587,13 
+478,10 @@ static void pp_dpm_set_fan_control_mode(void *handle, 

uint32_t mode) static uint32_t pp_dpm_get_fan_control_mode(void *handle) {

drivers/gpu/drm/amd/powerplay/amd_powerplay.c +2 -5
 	struct pp_hwmgr *hwmgr = handle;
-	int ret = 0;
 	uint32_t mode = 0;
 
-	ret = pp_check(hwmgr);
-
-	if (ret)
-		return ret;
+	if (!hwmgr || !hwmgr->pm_en)
+		return 0;
 
 	if (hwmgr->hwmgr_func->get_fan_control_mode == NULL) {
 		pr_info("%s was not implemented.\n", __func__); @@ -610,10 +498,8 

@@ static int pp_dpm_set_fan_speed_percent(void *handle, uint32_t percent)

drivers/gpu/drm/amd/powerplay/amd_powerplay.c +2 -4
 	struct pp_hwmgr *hwmgr = handle;
 	int ret = 0;
 
-	ret = pp_check(hwmgr);
-
-	if (ret)
-		return ret;
+	if (!hwmgr || !hwmgr->pm_en)
+		return -EINVAL;
 
 	if (hwmgr->hwmgr_func->set_fan_speed_percent == NULL) {
 		pr_info("%s was not implemented.\n", __func__); @@ -630,10 +516,8 

@@ static int pp_dpm_get_fan_speed_percent(void *handle, uint32_t *speed)

drivers/gpu/drm/amd/powerplay/amd_powerplay.c +2 -4
 	struct pp_hwmgr *hwmgr = handle;
 	int ret = 0;
 
-	ret = pp_check(hwmgr);
-
-	if (ret)
-		return ret;
+	if (!hwmgr || !hwmgr->pm_en)
+		return -EINVAL;
 
 	if (hwmgr->hwmgr_func->get_fan_speed_percent == NULL) {
 		pr_info("%s was not implemented.\n", __func__); @@ -651,10 +535,8 

@@ static int pp_dpm_get_fan_speed_rpm(void *handle, uint32_t *rpm)

drivers/gpu/drm/amd/powerplay/amd_powerplay.c +8 -30
 	struct pp_hwmgr *hwmgr = handle;
 	int ret = 0;
 
-	ret = pp_check(hwmgr);
-
-	if (ret)
-		return ret;
+	if (!hwmgr || !hwmgr->pm_en)
+		return -EINVAL;
 
 	if (hwmgr->hwmgr_func->get_fan_speed_rpm == NULL)
 		return -EINVAL;
@@ -670,16 +552,10 @@ static int pp_dpm_get_pp_num_states(void 
 *handle,  {
 	struct pp_hwmgr *hwmgr = handle;
 	int i;
-	int ret = 0;
 
 	memset(data, 0, sizeof(*data));
 
-	ret = pp_check(hwmgr);
-
-	if (ret)
-		return ret;
-
-	if (hwmgr->ps == NULL)
+	if (!hwmgr || !hwmgr->pm_en ||!hwmgr->ps)
 		return -EINVAL;
 
 	mutex_lock(&hwmgr->smu_lock);
@@ -713,15 +589,9 @@ static int pp_dpm_get_pp_num_states(void *handle,  
 static int pp_dpm_get_pp_table(void *handle, char **table)  {
 	struct pp_hwmgr *hwmgr = handle;
-	int ret = 0;
 	int size = 0;
 
-	ret = pp_check(hwmgr);
-
-	if (ret)
-		return ret;
-
-	if (!hwmgr->soft_pp_table)
+	if (!hwmgr || !hwmgr->pm_en ||!hwmgr->soft_pp_table)
 		return -EINVAL;
 
 	mutex_lock(&hwmgr->smu_lock);
@@ -736,10 +606,6 @@ static int amd_powerplay_reset(void *handle)
 	struct pp_hwmgr *hwmgr = handle;
 	int ret;
 
-	ret = pp_check(hwmgr);
-	if (ret)
-		return ret;
-
 	ret = hwmgr_hw_fini(hwmgr);
 	if (ret)
 		return ret;
@@ -756,10 +622,8 @@ static int pp_dpm_set_pp_table(void *handle, const char *buf, size_t size)
 	struct pp_hwmgr *hwmgr = handle;
 	int ret = 0;
 
-	ret = pp_check(hwmgr);
-
-	if (ret)
-		return ret;
+	if (!hwmgr || !hwmgr->pm_en)
+		return -EINVAL;
 
 	mutex_lock(&hwmgr->smu_lock);
 	if (!hwmgr->hardcode_pp_table) {
@@ -796,10 +660,8 @@ static int pp_dpm_force_clock_level(void *handle,
 	struct pp_hwmgr *hwmgr = handle;
 	int ret = 0;
 
-	ret = pp_check(hwmgr);
-
-	if (ret)
-		return ret;
+	if (!hwmgr || !hwmgr->pm_en)
+		return -EINVAL;
 
 	if (hwmgr->hwmgr_func->force_clock_level == NULL) {
 		pr_info("%s was not implemented.\n", __func__); @@ -820,10 +682,8 

@@ static int pp_dpm_print_clock_levels(void *handle,

drivers/gpu/drm/amd/powerplay/amd_powerplay.c +2 -4
 	struct pp_hwmgr *hwmgr = handle;
 	int ret = 0;
 
-	ret = pp_check(hwmgr);
-
-	if (ret)
-		return ret;
+	if (!hwmgr || !hwmgr->pm_en)
+		return -EINVAL;
 
 	if (hwmgr->hwmgr_func->print_clock_levels == NULL) {
 		pr_info("%s was not implemented.\n", __func__); @@ -840,10 +700,8 

@@ static int pp_dpm_get_sclk_od(void *handle)

drivers/gpu/drm/amd/powerplay/amd_powerplay.c +2 -4
 	struct pp_hwmgr *hwmgr = handle;
 	int ret = 0;
 
-	ret = pp_check(hwmgr);
-
-	if (ret)
-		return ret;
+	if (!hwmgr || !hwmgr->pm_en)
+		return -EINVAL;
 
 	if (hwmgr->hwmgr_func->get_sclk_od == NULL) {
 		pr_info("%s was not implemented.\n", __func__); @@ -860,10 +718,8 

@@ static int pp_dpm_set_sclk_od(void *handle, uint32_t value)

drivers/gpu/drm/amd/powerplay/amd_powerplay.c +2 -4
 	struct pp_hwmgr *hwmgr = handle;
 	int ret = 0;
 
-	ret = pp_check(hwmgr);
-
-	if (ret)
-		return ret;
+	if (!hwmgr || !hwmgr->pm_en)
+		return -EINVAL;
 
 	if (hwmgr->hwmgr_func->set_sclk_od == NULL) {
 		pr_info("%s was not implemented.\n", __func__); @@ -881,10 +737,8 

@@ static int pp_dpm_get_mclk_od(void *handle)

drivers/gpu/drm/amd/powerplay/amd_powerplay.c +2 -4
 	struct pp_hwmgr *hwmgr = handle;
 	int ret = 0;
 
-	ret = pp_check(hwmgr);
-
-	if (ret)
-		return ret;
+	if (!hwmgr || !hwmgr->pm_en)
+		return -EINVAL;
 
 	if (hwmgr->hwmgr_func->get_mclk_od == NULL) {
 		pr_info("%s was not implemented.\n", __func__); @@ -901,10 +755,8 

@@ static int pp_dpm_set_mclk_od(void *handle, uint32_t value)

drivers/gpu/drm/amd/powerplay/amd_powerplay.c +2 -4
 	struct pp_hwmgr *hwmgr = handle;
 	int ret = 0;
 
-	ret = pp_check(hwmgr);
-
-	if (ret)
-		return ret;
+	if (!hwmgr || !hwmgr->pm_en)
+		return -EINVAL;
 
 	if (hwmgr->hwmgr_func->set_mclk_od == NULL) {
 		pr_info("%s was not implemented.\n", __func__); @@ -922,11 +774,7 

@@ static int pp_dpm_read_sensor(void *handle, int idx,

drivers/gpu/drm/amd/powerplay/amd_powerplay.c +9 -14
 	struct pp_hwmgr *hwmgr = handle;
 	int ret = 0;
 
-	ret = pp_check(hwmgr);
-	if (ret)
-		return ret;
-
-	if (value == NULL)
+	if (!hwmgr || !hwmgr->pm_en || !value)
 		return -EINVAL;
 
 	switch (idx) {
@@ -948,14 +796,11 @@ static int pp_dpm_read_sensor(void *handle, int 
 idx,  pp_dpm_get_vce_clock_state(void *handle, unsigned idx)  {
 	struct pp_hwmgr *hwmgr = handle;
-	int ret = 0;
-
-	ret = pp_check(hwmgr);
 
-	if (ret)
+	if (!hwmgr || !hwmgr->pm_en)
 		return NULL;
 
-	if (hwmgr && idx < hwmgr->num_vce_state_tables)
+	if (idx < hwmgr->num_vce_state_tables)
 		return &hwmgr->vce_states[idx];
 	return NULL;
 }
@@ -964,7 +809,7 @@ static int pp_get_power_profile_mode(void *handle, 
 char *buf)  {
 	struct pp_hwmgr *hwmgr = handle;
 
-	if (!buf || pp_check(hwmgr))
+	if (!hwmgr || !hwmgr->pm_en || !buf)
 		return -EINVAL;
 
 	if (hwmgr->hwmgr_func->get_power_profile_mode == NULL) { @@ -980,12 
+825,12 @@ static int pp_set_power_profile_mode(void *handle, long *input, uint32_t size)
 	struct pp_hwmgr *hwmgr = handle;
 	int ret = -EINVAL;
 
-	if (pp_check(hwmgr))
-		return -EINVAL;
+	if (!hwmgr || !hwmgr->pm_en)
+		return ret;
 
 	if (hwmgr->hwmgr_func->set_power_profile_mode == NULL) {
 		pr_info("%s was not implemented.\n", __func__);
-		return -EINVAL;
+		return ret;
 	}
 	mutex_lock(&hwmgr->smu_lock);
 	if (hwmgr->dpm_level == AMD_DPM_FORCED_LEVEL_MANUAL) @@ -998,7 
+843,7 @@ static int pp_odn_edit_dpm_table(void *handle, uint32_t 

type, long *input, uint3 {

drivers/gpu/drm/amd/powerplay/amd_powerplay.c +6 -6
 	struct pp_hwmgr *hwmgr = handle;
 
-	if (pp_check(hwmgr))
+	if (!hwmgr || !hwmgr->pm_en)
 		return -EINVAL;
 
 	if (hwmgr->hwmgr_func->odn_edit_dpm_table == NULL) { @@ -1016,7 
+861,7 @@ static int pp_dpm_switch_power_profile(void *handle,
 	long workload;
 	uint32_t index;
 
-	if (pp_check(hwmgr))
+	if (!hwmgr || !hwmgr->pm_en)
 		return -EINVAL;
 
 	if (hwmgr->hwmgr_func->set_power_profile_mode == NULL) { @@ -1058,10 
+903,8 @@ static int pp_dpm_notify_smu_memory_info(void *handle,
 	struct pp_hwmgr *hwmgr = handle;
 	int ret = 0;
 
-	ret = pp_check(hwmgr);
-
-	if (ret)
-		return ret;
+	if (!hwmgr || !hwmgr->pm_en)
+		return -EINVAL;
 
 	if (hwmgr->hwmgr_func->notify_cac_buffer_info == NULL) {
 		pr_info("%s was not implemented.\n", __func__); @@ -1082,12 +925,9 

@@ static int pp_dpm_notify_smu_memory_info(void *handle, static int pp_set_power_limit(void *handle, uint32_t limit) {

drivers/gpu/drm/amd/powerplay/amd_powerplay.c +2 -5
 	struct pp_hwmgr *hwmgr = handle;
-	int ret = 0;
-
-	ret = pp_check(hwmgr);
 
-	if (ret)
-		return ret;
+	if (!hwmgr || !hwmgr->pm_en)
+		return -EINVAL;
 
 	if (hwmgr->hwmgr_func->set_power_limit == NULL) {
 		pr_info("%s was not implemented.\n", __func__); @@ -1104,20 +944,14 

@@ static int pp_set_power_limit(void *handle, uint32_t limit)

drivers/gpu/drm/amd/powerplay/amd_powerplay.c +1 -1
 	hwmgr->hwmgr_func->set_power_limit(hwmgr, limit);
 	hwmgr->power_limit = limit;
 	mutex_unlock(&hwmgr->smu_lock);
-	return ret;
+	return 0;
 }
 
 static int pp_get_power_limit(void *handle, uint32_t *limit, bool 

default_limit) {

drivers/gpu/drm/amd/powerplay/amd_powerplay.c +15 -53
 	struct pp_hwmgr *hwmgr = handle;
-	int ret = 0;
-
-	ret = pp_check(hwmgr);
 
-	if (ret)
-		return ret;
-
-	if (limit == NULL)
+	if (!hwmgr || !hwmgr->pm_en ||!limit)
 		return -EINVAL;
 
 	mutex_lock(&hwmgr->smu_lock);
@@ -1129,19 +963,16 @@ static int pp_get_power_limit(void *handle, 
 uint32_t *limit, bool default_limit)
 
 	mutex_unlock(&hwmgr->smu_lock);
 
-	return ret;
+	return 0;
 }
 
 static int pp_display_configuration_change(void *handle,
 	const struct amd_pp_display_configuration *display_config)  {
 	struct pp_hwmgr *hwmgr = handle;
-	int ret = 0;
-
-	ret = pp_check(hwmgr);
 
-	if (ret)
-		return ret;
+	if (!hwmgr || !hwmgr->pm_en)
+		return -EINVAL;
 
 	mutex_lock(&hwmgr->smu_lock);
 	phm_store_dal_configuration_data(hwmgr, display_config); @@ -1155,12 
+986,7 @@ static int pp_get_display_power_level(void *handle,
 	struct pp_hwmgr *hwmgr = handle;
 	int ret = 0;
 
-	ret = pp_check(hwmgr);
-
-	if (ret)
-		return ret;
-
-	if (output == NULL)
+	if (!hwmgr || !hwmgr->pm_en ||!output)
 		return -EINVAL;
 
 	mutex_lock(&hwmgr->smu_lock);
@@ -1177,10 +1003,8 @@ static int pp_get_current_clocks(void *handle,
 	struct pp_hwmgr *hwmgr = handle;
 	int ret = 0;
 
-	ret = pp_check(hwmgr);
-
-	if (ret)
-		return ret;
+	if (!hwmgr || !hwmgr->pm_en)
+		return -EINVAL;
 
 	mutex_lock(&hwmgr->smu_lock);
 
@@ -1225,10 +1049,8 @@ static int pp_get_clock_by_type(void *handle, enum amd_pp_clock_type type, struc
 	struct pp_hwmgr *hwmgr = handle;
 	int ret = 0;
 
-	ret = pp_check(hwmgr);
-
-	if (ret)
-		return ret;
+	if (!hwmgr || !hwmgr->pm_en)
+		return -EINVAL;
 
 	if (clocks == NULL)
 		return -EINVAL;
@@ -1246,11 +1068,7 @@ static int pp_get_clock_by_type_with_latency(void *handle,
 	struct pp_hwmgr *hwmgr = handle;
 	int ret = 0;
 
-	ret = pp_check(hwmgr);
-	if (ret)
-		return ret;
-
-	if (!clocks)
+	if (!hwmgr || !hwmgr->pm_en ||!clocks)
 		return -EINVAL;
 
 	mutex_lock(&hwmgr->smu_lock);
@@ -1266,11 +1084,7 @@ static int pp_get_clock_by_type_with_voltage(void *handle,
 	struct pp_hwmgr *hwmgr = handle;
 	int ret = 0;
 
-	ret = pp_check(hwmgr);
-	if (ret)
-		return ret;
-
-	if (!clocks)
+	if (!hwmgr || !hwmgr->pm_en ||!clocks)
 		return -EINVAL;
 
 	mutex_lock(&hwmgr->smu_lock);
@@ -1287,11 +1101,7 @@ static int pp_set_watermarks_for_clocks_ranges(void *handle,
 	struct pp_hwmgr *hwmgr = handle;
 	int ret = 0;
 
-	ret = pp_check(hwmgr);
-	if (ret)
-		return ret;
-
-	if (!wm_with_clock_ranges)
+	if (!hwmgr || !hwmgr->pm_en ||!wm_with_clock_ranges)
 		return -EINVAL;
 
 	mutex_lock(&hwmgr->smu_lock);
@@ -1308,11 +1118,7 @@ static int pp_display_clock_voltage_request(void *handle,
 	struct pp_hwmgr *hwmgr = handle;
 	int ret = 0;
 
-	ret = pp_check(hwmgr);
-	if (ret)
-		return ret;
-
-	if (!clock)
+	if (!hwmgr || !hwmgr->pm_en ||!clock)
 		return -EINVAL;
 
 	mutex_lock(&hwmgr->smu_lock);
@@ -1328,12 +1134,7 @@ static int pp_get_display_mode_validation_clocks(void *handle,
 	struct pp_hwmgr *hwmgr = handle;
 	int ret = 0;
 
-	ret = pp_check(hwmgr);
-
-	if (ret)
-		return ret;
-
-	if (clocks == NULL)
+	if (!hwmgr || !hwmgr->pm_en ||!clocks)
 		return -EINVAL;
 
 	mutex_lock(&hwmgr->smu_lock);
@@ -1348,12 +1149,9 @@ static int 

pp_get_display_mode_validation_clocks(void *handle, static int pp_set_mmhub_powergating_by_smu(void *handle) {

drivers/gpu/drm/amd/powerplay/amd_powerplay.c +2 -5
 	struct pp_hwmgr *hwmgr = handle;
-	int ret = 0;
-
-	ret = pp_check(hwmgr);
 
-	if (ret)
-		return ret;
+	if (!hwmgr || !hwmgr->pm_en)
+		return -EINVAL;
 
 	if (hwmgr->hwmgr_func->set_mmhub_powergating_by_smu == NULL) {
 		pr_info("%s was not implemented.\n", __func__); diff --git 

a/drivers/gpu/drm/amd/powerplay/hwmgr/hwmgr.c
b/drivers/gpu/drm/amd/powerplay/hwmgr/hwmgr.c
index 4298205..96a2d01 100644

drivers/gpu/drm/amd/powerplay/hwmgr/hwmgr.c +1 -1
@@ -76,7 +76,7 @@ static void hwmgr_init_workload_prority(struct 
 pp_hwmgr *hwmgr)
 
 int hwmgr_early_init(struct pp_hwmgr *hwmgr)  {
-	if (hwmgr == NULL)
+	if (!hwmgr)
 		return -EINVAL;
 
 	hwmgr->usec_timeout = AMD_MAX_USEC_TIMEOUT; @@ -170,17 +170,51 @@ 

int hwmgr_early_init(struct pp_hwmgr *hwmgr)

drivers/gpu/drm/amd/powerplay/hwmgr/hwmgr.c +54 -16
 	return 0;
 }
 
+int hwmgr_sw_init(struct pp_hwmgr *hwmgr) {
+	if (!hwmgr|| !hwmgr->smumgr_funcs || !hwmgr->smumgr_funcs->smu_init)
+		return -EINVAL;
+
+	phm_register_irq_handlers(hwmgr);
+
+	return hwmgr->smumgr_funcs->smu_init(hwmgr);
+}
+
+
+int hwmgr_sw_fini(struct pp_hwmgr *hwmgr) {
+	if (hwmgr && hwmgr->smumgr_funcs && hwmgr->smumgr_funcs->smu_fini)
+		hwmgr->smumgr_funcs->smu_fini(hwmgr);
+
+	return 0;
+}
+
 int hwmgr_hw_init(struct pp_hwmgr *hwmgr)  {
 	int ret = 0;
 
-	if (hwmgr == NULL)
+	if (!hwmgr || !hwmgr->smumgr_funcs)
 		return -EINVAL;
 
-	if (hwmgr->pptable_func == NULL ||
-	    hwmgr->pptable_func->pptable_init == NULL ||
-	    hwmgr->hwmgr_func->backend_init == NULL)
-		return -EINVAL;
+	if (hwmgr->smumgr_funcs->start_smu) {
+		ret = hwmgr->smumgr_funcs->start_smu(hwmgr);
+		if (ret) {
+			pr_err("smc start failed\n");
+			return -EINVAL;
+		}
+	}
+
+	if (!hwmgr->pm_en)
+		return 0;
+
+	if (!hwmgr->pptable_func ||
+	    !hwmgr->pptable_func->pptable_init ||
+	    !hwmgr->hwmgr_func->backend_init) {
+		hwmgr->pm_en = false;
+		cgs_notify_dpm_enabled(hwmgr->device, false);
+		pr_info("dpm not supported \n");
+		return 0;
+	}
 
 	ret = hwmgr->pptable_func->pptable_init(hwmgr);
 	if (ret)
@@ -214,14 +248,13 @@ int hwmgr_hw_init(struct pp_hwmgr *hwmgr)
 	if (hwmgr->pptable_func->pptable_fini)
 		hwmgr->pptable_func->pptable_fini(hwmgr);
 err:
-	pr_err("amdgpu: powerplay initialization failed\n");
 	return ret;
 }
 
 int hwmgr_hw_fini(struct pp_hwmgr *hwmgr)  {
-	if (hwmgr == NULL)
-		return -EINVAL;
+	if (!hwmgr || !hwmgr->pm_en)
+		return 0;
 
 	phm_stop_thermal_controller(hwmgr);
 	psm_set_boot_states(hwmgr);
@@ -236,12 +269,12 @@ int hwmgr_hw_fini(struct pp_hwmgr *hwmgr)
 	return psm_fini_power_state_table(hwmgr);
 }
 
-int hwmgr_hw_suspend(struct pp_hwmgr *hwmgr)
+int hwmgr_suspend(struct pp_hwmgr *hwmgr)
 {
 	int ret = 0;
 
-	if (hwmgr == NULL)
-		return -EINVAL;
+	if (!hwmgr || !hwmgr->pm_en)
+		return 0;
 
 	phm_disable_smc_firmware_ctf(hwmgr);
 	ret = psm_set_boot_states(hwmgr);
@@ -255,13 +288,23 @@ int hwmgr_hw_suspend(struct pp_hwmgr *hwmgr)
 	return ret;
 }
 
-int hwmgr_hw_resume(struct pp_hwmgr *hwmgr)
+int hwmgr_resume(struct pp_hwmgr *hwmgr)
 {
 	int ret = 0;
 
-	if (hwmgr == NULL)
+	if (!hwmgr)
 		return -EINVAL;
 
+	if (hwmgr->smumgr_funcs && hwmgr->smumgr_funcs->start_smu) {
+		if (hwmgr->smumgr_funcs->start_smu(hwmgr)) {
+			pr_err("smc start failed\n");
+			return -EINVAL;
+		}
+	}
+
+	if (!hwmgr->pm_en)
+		return 0;
+
 	ret = phm_setup_asic(hwmgr);
 	if (ret)
 		return ret;
@@ -270,9 +313,6 @@ int hwmgr_hw_resume(struct pp_hwmgr *hwmgr)
 	if (ret)
 		return ret;
 	ret = phm_start_thermal_controller(hwmgr);
-	if (ret)
-		return ret;
-
 	ret |= psm_set_performance_states(hwmgr);
 	if (ret)
 		return ret;
drivers/gpu/drm/amd/powerplay/inc/hwmgr.h +2 -0
index 17f811d..d6c9a3b 100644
@@ -782,10 +782,13 @@ struct pp_hwmgr {  };
 
 int hwmgr_early_init(struct pp_hwmgr *hwmgr);
+int hwmgr_sw_init(struct pp_hwmgr *hwmgr); int hwmgr_sw_fini(struct 
+pp_hwmgr *hwmgr);
 int hwmgr_hw_init(struct pp_hwmgr *hwmgr);  int hwmgr_hw_fini(struct 

pp_hwmgr *hwmgr); -int hwmgr_hw_suspend(struct pp_hwmgr *hwmgr); -int hwmgr_hw_resume(struct pp_hwmgr *hwmgr);

drivers/gpu/drm/amd/powerplay/inc/hwmgr.h +3 -1
+int hwmgr_suspend(struct pp_hwmgr *hwmgr); int hwmgr_resume(struct 
+pp_hwmgr *hwmgr);
+
 int hwmgr_handle_task(struct pp_hwmgr *hwmgr,
 				enum amd_pp_task task_id,
 				enum amd_pm_state_type *user_state);
--

1.9.1

Quoted 4 lines

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx