Skip to contentSkip to conversation

drm/amd/pm/smu7: move variables to where they are used

PATCH In review Alex Deucher 2 participants 2 messages Feb 6, 2023 – Feb 7, 2023

Subsystems (3)
lore
Share & tools
lore

Alex Deucher

author maintainer
#0 lore raw

PATCH 1/1 drm/amd/pm/smu7: move variables to where they are used

Move variable declarations to where they are used. Fixes a segfault on smu7 V0 structures where some tables don't exist.

Cc Evan Quan <[email protected]>
Fixes 711d3c39503b ("drm/amd/pm: fulfill powerplay peak profiling mode shader/memory clock settings")
---
 .../gpu/drm/amd/pm/powerplay/hwmgr/smu7_hwmgr.c    | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)
drivers/gpu/drm/amd/pm/powerplay/hwmgr/smu7_hwmgr.c +8 -6
index 89fc32318d80..e10cc5e7928e 100644
@@ -1504,12 +1504,6 @@ static void smu7_populate_umdpstate_clocks(struct pp_hwmgr *hwmgr)
 {
 	struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
 	struct smu7_dpm_table *golden_dpm_table = &data->golden_dpm_table;
-	struct phm_clock_voltage_dependency_table *vddc_dependency_on_sclk =
-			hwmgr->dyn_state.vddc_dependency_on_sclk;
-	struct phm_ppt_v1_information *table_info =
-			(struct phm_ppt_v1_information *)(hwmgr->pptable);
-	struct phm_ppt_v1_clock_voltage_dependency_table *vdd_dep_on_sclk =
-			table_info->vdd_dep_on_sclk;
 	int32_t tmp_sclk, count, percentage;
 
 	if (golden_dpm_table->mclk_table.count == 1) {
@@ -1524,6 +1518,9 @@ static void smu7_populate_umdpstate_clocks(struct pp_hwmgr *hwmgr)
 	tmp_sclk = hwmgr->pstate_mclk * percentage / 100;
 
 	if (hwmgr->pp_table_version == PP_TABLE_V0) {
+		struct phm_clock_voltage_dependency_table *vddc_dependency_on_sclk =
+			hwmgr->dyn_state.vddc_dependency_on_sclk;
+
 		for (count = vddc_dependency_on_sclk->count - 1; count >= 0; count--) {
 			if (tmp_sclk >= vddc_dependency_on_sclk->entries[count].clk) {
 				hwmgr->pstate_sclk = vddc_dependency_on_sclk->entries[count].clk;
@@ -1536,6 +1533,11 @@ static void smu7_populate_umdpstate_clocks(struct pp_hwmgr *hwmgr)
 		hwmgr->pstate_sclk_peak =
 			vddc_dependency_on_sclk->entries[vddc_dependency_on_sclk->count - 1].clk;
 	} else if (hwmgr->pp_table_version == PP_TABLE_V1) {
+		struct phm_ppt_v1_information *table_info =
+			(struct phm_ppt_v1_information *)(hwmgr->pptable);
+		struct phm_ppt_v1_clock_voltage_dependency_table *vdd_dep_on_sclk =
+			table_info->vdd_dep_on_sclk;
+
 		for (count = vdd_dep_on_sclk->count - 1; count >= 0; count--) {
 			if (tmp_sclk >= vdd_dep_on_sclk->entries[count].clk) {
 				hwmgr->pstate_sclk = vdd_dep_on_sclk->entries[count].clk;
Signature · 1 line
2.39.1
Reviewed-by on v1 1/1
#1 lore raw

[AMD Official Use Only - General]

Quoted 83 lines

-----Original Message-----
From: Deucher, Alexander <[email protected]>
Sent: Tuesday, February 7, 2023 1:05 AM
To: [email protected]
Cc: Deucher, Alexander <[email protected]>; Quan, Evan <[email protected]>
Subject: [PATCH] drm/amd/pm/smu7: move variables to where they are used

Move variable declarations to where they are used. Fixes a segfault on smu7 V0 structures where some tables don't exist.

Cc Evan Quan <[email protected]>
Fixes 711d3c39503b ("drm/amd/pm: fulfill powerplay peak profiling mode

shader/memory clock settings")

---
 .../gpu/drm/amd/pm/powerplay/hwmgr/smu7_hwmgr.c    | 14 ++++++++--
----
 1 file changed, 8 insertions(+), 6 deletions(-)
drivers/gpu/drm/amd/pm/powerplay/hwmgr/smu7_hwmgr.c +0 -1
index 89fc32318d80..e10cc5e7928e 100644
@@ -1504,12 +1504,6 @@ static void
 smu7_populate_umdpstate_clocks(struct pp_hwmgr *hwmgr)
 {
 	struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr-
 >backend);
 	struct smu7_dpm_table *golden_dpm_table = &data-
 >golden_dpm_table;
-	struct phm_clock_voltage_dependency_table

*vddc_dependency_on_sclk =

drivers/gpu/drm/amd/pm/powerplay/hwmgr/smu7_hwmgr.c +0 -3
-			hwmgr->dyn_state.vddc_dependency_on_sclk;
-	struct phm_ppt_v1_information *table_info =
-			(struct phm_ppt_v1_information *)(hwmgr-
Quoted 1 line

pptable);

drivers/gpu/drm/amd/pm/powerplay/hwmgr/smu7_hwmgr.c +0 -1
-	struct phm_ppt_v1_clock_voltage_dependency_table

*vdd_dep_on_sclk =

drivers/gpu/drm/amd/pm/powerplay/hwmgr/smu7_hwmgr.c +3 -1
-			table_info->vdd_dep_on_sclk;
 	int32_t tmp_sclk, count, percentage;
 
 	if (golden_dpm_table->mclk_table.count == 1) {
@@ -1524,6 +1518,9 @@ static void
 smu7_populate_umdpstate_clocks(struct pp_hwmgr *hwmgr)
 	tmp_sclk = hwmgr->pstate_mclk * percentage / 100;
 
 	if (hwmgr->pp_table_version == PP_TABLE_V0) {
+		struct phm_clock_voltage_dependency_table
 *vddc_dependency_on_sclk =
+			hwmgr->dyn_state.vddc_dependency_on_sclk;
+
 		for (count = vddc_dependency_on_sclk->count - 1; count >=

0; count--) {
if (tmp_sclk >= vddc_dependency_on_sclk-

Quoted 1 line

entries[count].clk) {

hwmgr->pstate_sclk =
vddc_dependency_on_sclk->entries[count].clk;

drivers/gpu/drm/amd/pm/powerplay/hwmgr/smu7_hwmgr.c +3 -0
@@ -1536,6 +1533,11 @@ static void
 smu7_populate_umdpstate_clocks(struct pp_hwmgr *hwmgr)
 		hwmgr->pstate_sclk_peak =
 			vddc_dependency_on_sclk-
 >entries[vddc_dependency_on_sclk->count - 1].clk;
 	} else if (hwmgr->pp_table_version == PP_TABLE_V1) {
+		struct phm_ppt_v1_information *table_info =
+			(struct phm_ppt_v1_information *)(hwmgr-
 >pptable);
+		struct phm_ppt_v1_clock_voltage_dependency_table

*vdd_dep_on_sclk =

drivers/gpu/drm/amd/pm/powerplay/hwmgr/smu7_hwmgr.c +2 -0
+			table_info->vdd_dep_on_sclk;
+
 		for (count = vdd_dep_on_sclk->count - 1; count >= 0; count--)

{
if (tmp_sclk >= vdd_dep_on_sclk->entries[count].clk)
{
hwmgr->pstate_sclk = vdd_dep_on_sclk-

Quoted 1 line

entries[count].clk;

--
2.39.1