[PATCH V2 7/7] drm/amd/pm: revise SMU11 pptable setup

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Make the code more readable and scalable.

Signed-off-by: Evan Quan <evan.quan@xxxxxxx>
Change-Id: Ie4e5dd7b409acf91cc41ea59c00dcfe58e291e80
---
 drivers/gpu/drm/amd/pm/swsmu/inc/smu_v11_0.h  |  1 +
 .../gpu/drm/amd/pm/swsmu/smu11/arcturus_ppt.c |  1 +
 .../gpu/drm/amd/pm/swsmu/smu11/navi10_ppt.c   |  1 +
 .../amd/pm/swsmu/smu11/sienna_cichlid_ppt.c   |  1 +
 .../gpu/drm/amd/pm/swsmu/smu11/smu_v11_0.c    | 73 ++++++++++++-------
 5 files changed, 49 insertions(+), 28 deletions(-)

diff --git a/drivers/gpu/drm/amd/pm/swsmu/inc/smu_v11_0.h b/drivers/gpu/drm/amd/pm/swsmu/inc/smu_v11_0.h
index a9215494dcdd..256641c650ab 100644
--- a/drivers/gpu/drm/amd/pm/swsmu/inc/smu_v11_0.h
+++ b/drivers/gpu/drm/amd/pm/swsmu/inc/smu_v11_0.h
@@ -318,5 +318,6 @@ int smu_v11_0_restore_user_od_settings(struct smu_context *smu);
 
 void smu_v11_0_set_smu_mailbox_registers(struct smu_context *smu);
 
+void smu_v11_0_pptable_source_init(struct smu_context *smu);
 #endif
 #endif
diff --git a/drivers/gpu/drm/amd/pm/swsmu/smu11/arcturus_ppt.c b/drivers/gpu/drm/amd/pm/swsmu/smu11/arcturus_ppt.c
index 445005571f76..d691b64577af 100644
--- a/drivers/gpu/drm/amd/pm/swsmu/smu11/arcturus_ppt.c
+++ b/drivers/gpu/drm/amd/pm/swsmu/smu11/arcturus_ppt.c
@@ -2499,6 +2499,7 @@ static const struct pptable_funcs arcturus_ppt_funcs = {
 	.interrupt_work = smu_v11_0_interrupt_work,
 	.smu_handle_passthrough_sbr = smu_v11_0_handle_passthrough_sbr,
 	.set_mp1_state = smu_cmn_set_mp1_state,
+	.pptable_source_init = smu_v11_0_pptable_source_init,
 };
 
 void arcturus_set_ppt_funcs(struct smu_context *smu)
diff --git a/drivers/gpu/drm/amd/pm/swsmu/smu11/navi10_ppt.c b/drivers/gpu/drm/amd/pm/swsmu/smu11/navi10_ppt.c
index 0bcd4fe0ef17..0d48258fc50f 100644
--- a/drivers/gpu/drm/amd/pm/swsmu/smu11/navi10_ppt.c
+++ b/drivers/gpu/drm/amd/pm/swsmu/smu11/navi10_ppt.c
@@ -3569,6 +3569,7 @@ static const struct pptable_funcs navi10_ppt_funcs = {
 	.set_mp1_state = smu_cmn_set_mp1_state,
 	.get_default_config_table_settings = navi10_get_default_config_table_settings,
 	.set_config_table = navi10_set_config_table,
+	.pptable_source_init = smu_v11_0_pptable_source_init,
 };
 
 void navi10_set_ppt_funcs(struct smu_context *smu)
diff --git a/drivers/gpu/drm/amd/pm/swsmu/smu11/sienna_cichlid_ppt.c b/drivers/gpu/drm/amd/pm/swsmu/smu11/sienna_cichlid_ppt.c
index 74996a8fb671..f020e6b17597 100644
--- a/drivers/gpu/drm/amd/pm/swsmu/smu11/sienna_cichlid_ppt.c
+++ b/drivers/gpu/drm/amd/pm/swsmu/smu11/sienna_cichlid_ppt.c
@@ -4414,6 +4414,7 @@ static const struct pptable_funcs sienna_cichlid_ppt_funcs = {
 	.get_unique_id = sienna_cichlid_get_unique_id,
 	.mode2_reset_is_support = sienna_cichlid_is_mode2_reset_supported,
 	.mode2_reset = sienna_cichlid_mode2_reset,
+	.pptable_source_init = smu_v11_0_pptable_source_init,
 };
 
 void sienna_cichlid_set_ppt_funcs(struct smu_context *smu)
diff --git a/drivers/gpu/drm/amd/pm/swsmu/smu11/smu_v11_0.c b/drivers/gpu/drm/amd/pm/swsmu/smu11/smu_v11_0.c
index 6008450370e8..b56ef76a35f0 100644
--- a/drivers/gpu/drm/amd/pm/swsmu/smu11/smu_v11_0.c
+++ b/drivers/gpu/drm/amd/pm/swsmu/smu11/smu_v11_0.c
@@ -338,6 +338,15 @@ static int smu_v11_0_set_pptable_v2_1(struct smu_context *smu, void **table,
 	return 0;
 }
 
+void smu_v11_0_pptable_source_init(struct smu_context *smu)
+{
+	smu->pptable_id = smu->smu_table.boot_values.pp_table_id;
+	if (smu->pptable_id && !amdgpu_sriov_vf(smu->adev))
+		smu->pptable_source = PPTABLE_SOURCE_INTERNAL_HARDCOPY;
+	else
+		smu->pptable_source = PPTABLE_SOURCE_VBIOS;
+}
+
 int smu_v11_0_setup_pptable(struct smu_context *smu)
 {
 	struct amdgpu_device *adev = smu->adev;
@@ -349,41 +358,49 @@ int smu_v11_0_setup_pptable(struct smu_context *smu)
 	void *table;
 	uint16_t version_major, version_minor;
 
-	if (!amdgpu_sriov_vf(adev)) {
+	switch (smu->pptable_source) {
+	case PPTABLE_SOURCE_INTERNAL_HARDCOPY:
+		dev_info(adev->dev, "use driver provided pptable %d\n", smu->smu_table.boot_values.pp_table_id);
+
 		hdr = (const struct smc_firmware_header_v1_0 *) adev->pm.fw->data;
 		version_major = le16_to_cpu(hdr->header.header_version_major);
 		version_minor = le16_to_cpu(hdr->header.header_version_minor);
-		if (version_major == 2 && smu->smu_table.boot_values.pp_table_id > 0) {
-			dev_info(adev->dev, "use driver provided pptable %d\n", smu->smu_table.boot_values.pp_table_id);
-			switch (version_minor) {
-			case 0:
-				ret = smu_v11_0_set_pptable_v2_0(smu, &table, &size);
-				break;
-			case 1:
-				ret = smu_v11_0_set_pptable_v2_1(smu, &table, &size,
-								smu->smu_table.boot_values.pp_table_id);
-				break;
-			default:
-				ret = -EINVAL;
-				break;
-			}
-			if (ret)
-				return ret;
-			goto out;
+
+		if (version_major != 2)
+			return -EINVAL;
+
+		switch (version_minor) {
+		case 0:
+			ret = smu_v11_0_set_pptable_v2_0(smu, &table, &size);
+			break;
+		case 1:
+			ret = smu_v11_0_set_pptable_v2_1(smu, &table, &size,
+							smu->smu_table.boot_values.pp_table_id);
+			break;
+		default:
+			ret = -EINVAL;
+			break;
 		}
-	}
+		if (ret)
+			return ret;
+		break;
 
-	dev_info(adev->dev, "use vbios provided pptable\n");
-	index = get_index_into_master_table(atom_master_list_of_data_tables_v2_1,
-						powerplayinfo);
+	case PPTABLE_SOURCE_VBIOS:
+		dev_info(adev->dev, "use vbios provided pptable\n");
 
-	ret = amdgpu_atombios_get_data_table(adev, index, &atom_table_size, &frev, &crev,
-						(uint8_t **)&table);
-	if (ret)
-		return ret;
-	size = atom_table_size;
+		index = get_index_into_master_table(atom_master_list_of_data_tables_v2_1,
+							powerplayinfo);
+		ret = amdgpu_atombios_get_data_table(adev, index, &atom_table_size, &frev, &crev,
+							(uint8_t **)&table);
+		if (ret)
+			return ret;
+		size = atom_table_size;
+		break;
+
+	default:
+		return -EINVAL;
+	}
 
-out:
 	if (!smu->smu_table.power_play_table)
 		smu->smu_table.power_play_table = table;
 	if (!smu->smu_table.power_play_table_size)
-- 
2.34.1




[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux