Skip to contentSkip to conversation

Unified entry point for other blocks to interact with power

PATCH Superseded Evan Quan 4 participants 44 messages Nov 30, 2021 – Dec 2, 2021 Page 1 of 5

Subsystems (5)

v2 of 5 Superseded Latest is v5 →

lore
Share & tools
lore

Evan Quan

author
#0 lore raw

v2 cover Unified entry point for other blocks to interact with power

There are several problems with current power implementations:
1. Too many internal details are exposed to other blocks. Thus to interact with power, they need to know which power framework is used(powerplay vs swsmu) or even whether some API is implemented.
2. A lot of cross callings exist which make it hard to get a whole picture of the code hierarchy. And that makes any code change/increment error-prone.
3. Many different types of lock are used. It is calculated there is totally 13 different locks are used within power. Some of them are even designed for the same purpose.

To ease the problems above, this patch series try to
1. provide unified entry point for other blocks to interact with power.
2. relocate some source code piece/headers to avoid cross callings.
3. enforce a unified lock protection on those entry point APIs above. That makes the future optimization for unnecessary power locks possible.

Evan Quan (17):
drm/amd/pm: do not expose implementation details to other blocks out
of power
drm/amd/pm: do not expose power implementation details to amdgpu_pm.c drm/amd/pm: do not expose power implementation details to display drm/amd/pm: do not expose those APIs used internally only in
amdgpu_dpm.c
drm/amd/pm: do not expose those APIs used internally only in si_dpm.c drm/amd/pm: do not expose the API used internally only in kv_dpm.c drm/amd/pm: create a new holder for those APIs used only by legacy
ASICs(si/kv)
drm/amd/pm: move pp_force_state_enabled member to amdgpu_pm structure drm/amd/pm: optimize the amdgpu_pm_compute_clocks() implementations drm/amd/pm: move those code piece used by Stoney only to smu8_hwmgr.c drm/amd/pm: correct the usage for amdgpu_dpm_dispatch_task() drm/amd/pm: drop redundant or unused APIs and data structures drm/amd/pm: do not expose the smu_context structure used internally in
power
drm/amd/pm: relocate the power related headers
drm/amd/pm: drop unnecessary gfxoff controls
drm/amd/pm: revise the performance level setting APIs drm/amd/pm: unified lock protections in amdgpu_dpm.c

 drivers/gpu/drm/amd/amdgpu/aldebaran.c        |    2 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu.h           |    7 -
 drivers/gpu/drm/amd/amdgpu/amdgpu_atombios.c  |  421 ---
 drivers/gpu/drm/amd/amdgpu/amdgpu_atombios.h  |   30 -
 drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c   |   25 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu_device.c    |    6 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c       |   18 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h       |    7 -
 drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c       |    5 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu_umc.c       |    5 +-
 drivers/gpu/drm/amd/amdkfd/kfd_smi_events.c   |    2 +-
 .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c |    6 +-
 .../amd/display/amdgpu_dm/amdgpu_dm_pp_smu.c  |  246 +-
 .../gpu/drm/amd/include/kgd_pp_interface.h    |   14 +
 drivers/gpu/drm/amd/pm/Makefile               |   12 +-
 drivers/gpu/drm/amd/pm/amdgpu_dpm.c           | 2435 ++++++++---------
 drivers/gpu/drm/amd/pm/amdgpu_dpm_internal.c  |   94 +
 drivers/gpu/drm/amd/pm/amdgpu_pm.c            |  568 ++--
 drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h       |  339 +--
 .../gpu/drm/amd/pm/inc/amdgpu_dpm_internal.h  |   32 +
 drivers/gpu/drm/amd/pm/legacy-dpm/Makefile    |   32 +
 .../pm/{powerplay => legacy-dpm}/cik_dpm.h    |    0
 .../amd/pm/{powerplay => legacy-dpm}/kv_dpm.c |   47 +-
 .../amd/pm/{powerplay => legacy-dpm}/kv_dpm.h |    0
 .../amd/pm/{powerplay => legacy-dpm}/kv_smc.c |    0
 .../gpu/drm/amd/pm/legacy-dpm/legacy_dpm.c    | 1510 ++++++++++
 .../gpu/drm/amd/pm/legacy-dpm/legacy_dpm.h    |   71 +
 .../amd/pm/{powerplay => legacy-dpm}/ppsmc.h  |    0
 .../pm/{powerplay => legacy-dpm}/r600_dpm.h   |    0
 .../amd/pm/{powerplay => legacy-dpm}/si_dpm.c |  111 +-
 .../amd/pm/{powerplay => legacy-dpm}/si_dpm.h |    7 +
 .../amd/pm/{powerplay => legacy-dpm}/si_smc.c |    0
 .../{powerplay => legacy-dpm}/sislands_smc.h  |    0
 drivers/gpu/drm/amd/pm/powerplay/Makefile     |    4 -
 .../gpu/drm/amd/pm/powerplay/amd_powerplay.c  |   51 +-
 .../drm/amd/pm/powerplay/hwmgr/smu8_hwmgr.c   |   10 +-
 .../pm/{ => powerplay}/inc/amd_powerplay.h    |    0
 .../drm/amd/pm/{ => powerplay}/inc/cz_ppsmc.h |    0
 .../amd/pm/{ => powerplay}/inc/fiji_ppsmc.h   |    0
 .../pm/{ => powerplay}/inc/hardwaremanager.h  |    0
 .../drm/amd/pm/{ => powerplay}/inc/hwmgr.h    |    3 -
 .../{ => powerplay}/inc/polaris10_pwrvirus.h  |    0
 .../amd/pm/{ => powerplay}/inc/power_state.h  |    0
 .../drm/amd/pm/{ => powerplay}/inc/pp_debug.h |    0
 .../amd/pm/{ => powerplay}/inc/pp_endian.h    |    0
 .../amd/pm/{ => powerplay}/inc/pp_thermal.h   |    0
 .../amd/pm/{ => powerplay}/inc/ppinterrupt.h  |    0
 .../drm/amd/pm/{ => powerplay}/inc/rv_ppsmc.h |    0
 .../drm/amd/pm/{ => powerplay}/inc/smu10.h    |    0
 .../pm/{ => powerplay}/inc/smu10_driver_if.h  |    0
 .../pm/{ => powerplay}/inc/smu11_driver_if.h  |    0
 .../gpu/drm/amd/pm/{ => powerplay}/inc/smu7.h |    0
 .../drm/amd/pm/{ => powerplay}/inc/smu71.h    |    0
 .../pm/{ => powerplay}/inc/smu71_discrete.h   |    0
 .../drm/amd/pm/{ => powerplay}/inc/smu72.h    |    0
 .../pm/{ => powerplay}/inc/smu72_discrete.h   |    0
 .../drm/amd/pm/{ => powerplay}/inc/smu73.h    |    0
 .../pm/{ => powerplay}/inc/smu73_discrete.h   |    0
 .../drm/amd/pm/{ => powerplay}/inc/smu74.h    |    0
 .../pm/{ => powerplay}/inc/smu74_discrete.h   |    0
 .../drm/amd/pm/{ => powerplay}/inc/smu75.h    |    0
 .../pm/{ => powerplay}/inc/smu75_discrete.h   |    0
 .../amd/pm/{ => powerplay}/inc/smu7_common.h  |    0
 .../pm/{ => powerplay}/inc/smu7_discrete.h    |    0
 .../amd/pm/{ => powerplay}/inc/smu7_fusion.h  |    0
 .../amd/pm/{ => powerplay}/inc/smu7_ppsmc.h   |    0
 .../gpu/drm/amd/pm/{ => powerplay}/inc/smu8.h |    0
 .../amd/pm/{ => powerplay}/inc/smu8_fusion.h  |    0
 .../gpu/drm/amd/pm/{ => powerplay}/inc/smu9.h |    0
 .../pm/{ => powerplay}/inc/smu9_driver_if.h   |    0
 .../{ => powerplay}/inc/smu_ucode_xfer_cz.h   |    0
 .../{ => powerplay}/inc/smu_ucode_xfer_vi.h   |    0
 .../drm/amd/pm/{ => powerplay}/inc/smumgr.h   |    0
 .../amd/pm/{ => powerplay}/inc/tonga_ppsmc.h  |    0
 .../amd/pm/{ => powerplay}/inc/vega10_ppsmc.h |    0
 .../inc/vega12/smu9_driver_if.h               |    0
 .../amd/pm/{ => powerplay}/inc/vega12_ppsmc.h |    0
 .../amd/pm/{ => powerplay}/inc/vega20_ppsmc.h |    0
 drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c     |   95 +-
 .../amd/pm/{ => swsmu}/inc/aldebaran_ppsmc.h  |    0
 .../drm/amd/pm/{ => swsmu}/inc/amdgpu_smu.h   |   20 +-
 .../amd/pm/{ => swsmu}/inc/arcturus_ppsmc.h   |    0
 .../inc/smu11_driver_if_arcturus.h            |    0
 .../inc/smu11_driver_if_cyan_skillfish.h      |    0
 .../{ => swsmu}/inc/smu11_driver_if_navi10.h  |    0
 .../inc/smu11_driver_if_sienna_cichlid.h      |    0
 .../{ => swsmu}/inc/smu11_driver_if_vangogh.h |    0
 .../amd/pm/{ => swsmu}/inc/smu12_driver_if.h  |    0
 .../inc/smu13_driver_if_aldebaran.h           |    0
 .../inc/smu13_driver_if_yellow_carp.h         |    0
 .../pm/{ => swsmu}/inc/smu_11_0_cdr_table.h   |    0
 .../drm/amd/pm/{ => swsmu}/inc/smu_types.h    |    0
 .../drm/amd/pm/{ => swsmu}/inc/smu_v11_0.h    |    0
 .../pm/{ => swsmu}/inc/smu_v11_0_7_ppsmc.h    |    0
 .../pm/{ => swsmu}/inc/smu_v11_0_7_pptable.h  |    0
 .../amd/pm/{ => swsmu}/inc/smu_v11_0_ppsmc.h  |    0
 .../pm/{ => swsmu}/inc/smu_v11_0_pptable.h    |    0
 .../amd/pm/{ => swsmu}/inc/smu_v11_5_pmfw.h   |    0
 .../amd/pm/{ => swsmu}/inc/smu_v11_5_ppsmc.h  |    0
 .../amd/pm/{ => swsmu}/inc/smu_v11_8_pmfw.h   |    0
 .../amd/pm/{ => swsmu}/inc/smu_v11_8_ppsmc.h  |    0
 .../drm/amd/pm/{ => swsmu}/inc/smu_v12_0.h    |    0
 .../amd/pm/{ => swsmu}/inc/smu_v12_0_ppsmc.h  |    0
 .../drm/amd/pm/{ => swsmu}/inc/smu_v13_0.h    |    0
 .../amd/pm/{ => swsmu}/inc/smu_v13_0_1_pmfw.h |    0
 .../pm/{ => swsmu}/inc/smu_v13_0_1_ppsmc.h    |    0
 .../pm/{ => swsmu}/inc/smu_v13_0_pptable.h    |    0
 .../gpu/drm/amd/pm/swsmu/smu11/arcturus_ppt.c |   10 +-
 .../gpu/drm/amd/pm/swsmu/smu11/navi10_ppt.c   |    9 +-
 .../amd/pm/swsmu/smu11/sienna_cichlid_ppt.c   |   34 +-
 .../gpu/drm/amd/pm/swsmu/smu11/smu_v11_0.c    |   11 +-
 .../drm/amd/pm/swsmu/smu13/aldebaran_ppt.c    |   10 +-
 .../gpu/drm/amd/pm/swsmu/smu13/smu_v13_0.c    |   15 +-
 drivers/gpu/drm/amd/pm/swsmu/smu_cmn.h        |    4 +
 114 files changed, 3657 insertions(+), 2671 deletions(-)
 create mode 100644 drivers/gpu/drm/amd/pm/amdgpu_dpm_internal.c
 create mode 100644 drivers/gpu/drm/amd/pm/inc/amdgpu_dpm_internal.h
 create mode 100644 drivers/gpu/drm/amd/pm/legacy-dpm/Makefile
 rename drivers/gpu/drm/amd/pm/{powerplay => legacy-dpm}/cik_dpm.h (100%)
 rename drivers/gpu/drm/amd/pm/{powerplay => legacy-dpm}/kv_dpm.c (99%)
 rename drivers/gpu/drm/amd/pm/{powerplay => legacy-dpm}/kv_dpm.h (100%)
 rename drivers/gpu/drm/amd/pm/{powerplay => legacy-dpm}/kv_smc.c (100%)
 create mode 100644 drivers/gpu/drm/amd/pm/legacy-dpm/legacy_dpm.c
 create mode 100644 drivers/gpu/drm/amd/pm/legacy-dpm/legacy_dpm.h
 rename drivers/gpu/drm/amd/pm/{powerplay => legacy-dpm}/ppsmc.h (100%)
 rename drivers/gpu/drm/amd/pm/{powerplay => legacy-dpm}/r600_dpm.h (100%)
 rename drivers/gpu/drm/amd/pm/{powerplay => legacy-dpm}/si_dpm.c (99%)
 rename drivers/gpu/drm/amd/pm/{powerplay => legacy-dpm}/si_dpm.h (99%)
 rename drivers/gpu/drm/amd/pm/{powerplay => legacy-dpm}/si_smc.c (100%)
 rename drivers/gpu/drm/amd/pm/{powerplay => legacy-dpm}/sislands_smc.h (100%)
 rename drivers/gpu/drm/amd/pm/{ => powerplay}/inc/amd_powerplay.h (100%)
 rename drivers/gpu/drm/amd/pm/{ => powerplay}/inc/cz_ppsmc.h (100%)
 rename drivers/gpu/drm/amd/pm/{ => powerplay}/inc/fiji_ppsmc.h (100%)
 rename drivers/gpu/drm/amd/pm/{ => powerplay}/inc/hardwaremanager.h (100%)
 rename drivers/gpu/drm/amd/pm/{ => powerplay}/inc/hwmgr.h (99%)
 rename drivers/gpu/drm/amd/pm/{ => powerplay}/inc/polaris10_pwrvirus.h (100%)
 rename drivers/gpu/drm/amd/pm/{ => powerplay}/inc/power_state.h (100%)
 rename drivers/gpu/drm/amd/pm/{ => powerplay}/inc/pp_debug.h (100%)
 rename drivers/gpu/drm/amd/pm/{ => powerplay}/inc/pp_endian.h (100%)
 rename drivers/gpu/drm/amd/pm/{ => powerplay}/inc/pp_thermal.h (100%)
 rename drivers/gpu/drm/amd/pm/{ => powerplay}/inc/ppinterrupt.h (100%)
 rename drivers/gpu/drm/amd/pm/{ => powerplay}/inc/rv_ppsmc.h (100%)
 rename drivers/gpu/drm/amd/pm/{ => powerplay}/inc/smu10.h (100%)
 rename drivers/gpu/drm/amd/pm/{ => powerplay}/inc/smu10_driver_if.h (100%)
 rename drivers/gpu/drm/amd/pm/{ => powerplay}/inc/smu11_driver_if.h (100%)
 rename drivers/gpu/drm/amd/pm/{ => powerplay}/inc/smu7.h (100%)
 rename drivers/gpu/drm/amd/pm/{ => powerplay}/inc/smu71.h (100%)
 rename drivers/gpu/drm/amd/pm/{ => powerplay}/inc/smu71_discrete.h (100%)
 rename drivers/gpu/drm/amd/pm/{ => powerplay}/inc/smu72.h (100%)
 rename drivers/gpu/drm/amd/pm/{ => powerplay}/inc/smu72_discrete.h (100%)
 rename drivers/gpu/drm/amd/pm/{ => powerplay}/inc/smu73.h (100%)
 rename drivers/gpu/drm/amd/pm/{ => powerplay}/inc/smu73_discrete.h (100%)
 rename drivers/gpu/drm/amd/pm/{ => powerplay}/inc/smu74.h (100%)
 rename drivers/gpu/drm/amd/pm/{ => powerplay}/inc/smu74_discrete.h (100%)
 rename drivers/gpu/drm/amd/pm/{ => powerplay}/inc/smu75.h (100%)
 rename drivers/gpu/drm/amd/pm/{ => powerplay}/inc/smu75_discrete.h (100%)
 rename drivers/gpu/drm/amd/pm/{ => powerplay}/inc/smu7_common.h (100%)
 rename drivers/gpu/drm/amd/pm/{ => powerplay}/inc/smu7_discrete.h (100%)
 rename drivers/gpu/drm/amd/pm/{ => powerplay}/inc/smu7_fusion.h (100%)
 rename drivers/gpu/drm/amd/pm/{ => powerplay}/inc/smu7_ppsmc.h (100%)
 rename drivers/gpu/drm/amd/pm/{ => powerplay}/inc/smu8.h (100%)
 rename drivers/gpu/drm/amd/pm/{ => powerplay}/inc/smu8_fusion.h (100%)
 rename drivers/gpu/drm/amd/pm/{ => powerplay}/inc/smu9.h (100%)
 rename drivers/gpu/drm/amd/pm/{ => powerplay}/inc/smu9_driver_if.h (100%)
 rename drivers/gpu/drm/amd/pm/{ => powerplay}/inc/smu_ucode_xfer_cz.h (100%)
 rename drivers/gpu/drm/amd/pm/{ => powerplay}/inc/smu_ucode_xfer_vi.h (100%)
 rename drivers/gpu/drm/amd/pm/{ => powerplay}/inc/smumgr.h (100%)
 rename drivers/gpu/drm/amd/pm/{ => powerplay}/inc/tonga_ppsmc.h (100%)
 rename drivers/gpu/drm/amd/pm/{ => powerplay}/inc/vega10_ppsmc.h (100%)
 rename drivers/gpu/drm/amd/pm/{ => powerplay}/inc/vega12/smu9_driver_if.h (100%)
 rename drivers/gpu/drm/amd/pm/{ => powerplay}/inc/vega12_ppsmc.h (100%)
 rename drivers/gpu/drm/amd/pm/{ => powerplay}/inc/vega20_ppsmc.h (100%)
 rename drivers/gpu/drm/amd/pm/{ => swsmu}/inc/aldebaran_ppsmc.h (100%)
 rename drivers/gpu/drm/amd/pm/{ => swsmu}/inc/amdgpu_smu.h (98%)
 rename drivers/gpu/drm/amd/pm/{ => swsmu}/inc/arcturus_ppsmc.h (100%)
 rename drivers/gpu/drm/amd/pm/{ => swsmu}/inc/smu11_driver_if_arcturus.h (100%)
 rename drivers/gpu/drm/amd/pm/{ => swsmu}/inc/smu11_driver_if_cyan_skillfish.h (100%)
 rename drivers/gpu/drm/amd/pm/{ => swsmu}/inc/smu11_driver_if_navi10.h (100%)
 rename drivers/gpu/drm/amd/pm/{ => swsmu}/inc/smu11_driver_if_sienna_cichlid.h (100%)
 rename drivers/gpu/drm/amd/pm/{ => swsmu}/inc/smu11_driver_if_vangogh.h (100%)
 rename drivers/gpu/drm/amd/pm/{ => swsmu}/inc/smu12_driver_if.h (100%)
 rename drivers/gpu/drm/amd/pm/{ => swsmu}/inc/smu13_driver_if_aldebaran.h (100%)
 rename drivers/gpu/drm/amd/pm/{ => swsmu}/inc/smu13_driver_if_yellow_carp.h (100%)
 rename drivers/gpu/drm/amd/pm/{ => swsmu}/inc/smu_11_0_cdr_table.h (100%)
 rename drivers/gpu/drm/amd/pm/{ => swsmu}/inc/smu_types.h (100%)
 rename drivers/gpu/drm/amd/pm/{ => swsmu}/inc/smu_v11_0.h (100%)
 rename drivers/gpu/drm/amd/pm/{ => swsmu}/inc/smu_v11_0_7_ppsmc.h (100%)
 rename drivers/gpu/drm/amd/pm/{ => swsmu}/inc/smu_v11_0_7_pptable.h (100%)
 rename drivers/gpu/drm/amd/pm/{ => swsmu}/inc/smu_v11_0_ppsmc.h (100%)
 rename drivers/gpu/drm/amd/pm/{ => swsmu}/inc/smu_v11_0_pptable.h (100%)
 rename drivers/gpu/drm/amd/pm/{ => swsmu}/inc/smu_v11_5_pmfw.h (100%)
 rename drivers/gpu/drm/amd/pm/{ => swsmu}/inc/smu_v11_5_ppsmc.h (100%)
 rename drivers/gpu/drm/amd/pm/{ => swsmu}/inc/smu_v11_8_pmfw.h (100%)
 rename drivers/gpu/drm/amd/pm/{ => swsmu}/inc/smu_v11_8_ppsmc.h (100%)
 rename drivers/gpu/drm/amd/pm/{ => swsmu}/inc/smu_v12_0.h (100%)
 rename drivers/gpu/drm/amd/pm/{ => swsmu}/inc/smu_v12_0_ppsmc.h (100%)
 rename drivers/gpu/drm/amd/pm/{ => swsmu}/inc/smu_v13_0.h (100%)
 rename drivers/gpu/drm/amd/pm/{ => swsmu}/inc/smu_v13_0_1_pmfw.h (100%)
 rename drivers/gpu/drm/amd/pm/{ => swsmu}/inc/smu_v13_0_1_ppsmc.h (100%)
 rename drivers/gpu/drm/amd/pm/{ => swsmu}/inc/smu_v13_0_pptable.h (100%)
Signature · 1 line
2.29.0
author
#1 lore raw

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

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

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

98 lines not on this page · raw message

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

Re: [PATCH V2 01/17] drm/amd/pm: do not expose implementation details to other blocks out of power

Quoted 328 lines · Evan Quan

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

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

drivers/gpu/drm/amd/pm/amdgpu_dpm.c int amdgpu_pm_load_smu_firmware(struct amdgpu_device *adev, uint32_t *smu_versio · line 1709

Quoted 10 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +10 -0
+			(adev)->powerplay.pp_handle, state));
+	mutex_unlock(&adev->pm.mutex);
+}
+
+int amdgpu_dpm_get_ecc_info(struct amdgpu_device *adev,
+			    void *umc_ecc)
+{
+	if (!is_support_sw_smu(adev))
+		return -EOPNOTSUPP;
+

In general, I don't think we need to keep this check everywhere to make amdgpu_dpm_* backwards compatible. The usage is also inconsistent. For ex: amdgpu_dpm_get_thermal_throttling_counter doesn't have any is_support_sw_smu check whereas amdgpu_dpm_get_ecc_info() has it. There is no reason to keep adding is_support_sw_smu() check for every new public API. For sure, they are not going to work with powerplay subsystem.

I would rather prefer to leave old things and create amdgpu_smu_* for anything which is supported only in smu subsystem. It's easier to read from code perspective also - separate the ones which is supported by smu component and not supported in older powerplay components.

Only for the common ones that are supported in powerplay and smu, keep amdgpu_dpm_*, for others preference would be to keep amdgpu_smu_*.

Thanks,
Lijo

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

RE: [PATCH V2 01/17] drm/amd/pm: do not expose implementation details to other blocks out of power

[AMD Official Use Only]

Quoted 415 lines

-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Lazar, Lijo
Sent: Tuesday, November 30, 2021 4:10 PM
To: Quan, Evan <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>; Feng, Kenneth <[email protected]>; Koenig, Christian <[email protected]>
Subject: Re: [PATCH V2 01/17] drm/amd/pm: do not expose implementation details to other blocks out of power

Quoted 3 lines · Evan Quan

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

implementation details.

Quoted 14 lines
Change-Id Ibca3462ceaa26a27a9145282b60c6ce5deca7752
---
  drivers/gpu/drm/amd/amdgpu/aldebaran.c        |  2 +-
  drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c   | 25 ++---
  drivers/gpu/drm/amd/amdgpu/amdgpu_device.c    |  6 +-
  drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c       | 18 +---
  drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h       |  7 --
  drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c       |  5 +-
  drivers/gpu/drm/amd/amdgpu/amdgpu_umc.c       |  5 +-
  drivers/gpu/drm/amd/amdkfd/kfd_smi_events.c   |  2 +-
  .../gpu/drm/amd/include/kgd_pp_interface.h    |  4 +
  drivers/gpu/drm/amd/pm/amdgpu_dpm.c           | 95

+++++++++++++++++++

drivers/gpu/drm/amd/amdgpu/aldebaran.c static int aldebaran_mode2_restore_ip(struct

Quoted 11 lines
  drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h       | 25 ++++-
  drivers/gpu/drm/amd/pm/inc/amdgpu_smu.h       |  9 +-
  drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c     | 16 ++--
  13 files changed, 155 insertions(+), 64 deletions(-)
drivers/gpu/drm/amd/amdgpu/aldebaran.c +0 -0
index bcfdb63b1d42..a545df4efce1 100644
@@ -260,7 +260,7 @@ static int aldebaran_mode2_restore_ip(struct

amdgpu_device *adev)

drivers/gpu/drm/amd/amdgpu/aldebaran.c static int aldebaran_mode2_restore_ip(struct amdgpu_device *adev)

Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/aldebaran.c +1 -1
  	adev->gfx.rlc.funcs->resume(adev);
 
  	/* Wait for FW reset event complete */
-	r = smu_wait_for_event(adev, SMU_EVENT_RESET_COMPLETE, 0);
+	r = amdgpu_dpm_wait_for_event(adev,

SMU_EVENT_RESET_COMPLETE, 0);

drivers/gpu/drm/amd/amdgpu/aldebaran.c static int aldebaran_mode2_restore_ip(struct amdgpu_device *adev) · line 266

Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/aldebaran.c +0 -0
  	if (r) {
  		dev_err(adev->dev,
  			"Failed to get response from firmware after reset\n");

diff --git

drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c static int amdgpu_debugfs_sclk_set(void *data,

Quoted 6 lines

a/drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c
b/drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c
index 164d6a9e9fbb..0d1f00b24aae 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c +0 -0
@@ -1585,22 +1585,25 @@ static int amdgpu_debugfs_sclk_set(void *data,

u64 val)

drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c static int amdgpu_debugfs_sclk_set(void *data, u64 val)

Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c +0 -2
  		return ret;
  	}
 
-	if (is_support_sw_smu(adev)) {
-		ret = smu_get_dpm_freq_range(&adev->smu, SMU_SCLK,

&min_freq, &max_freq);

drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c static int amdgpu_debugfs_sclk_set(void *data, u64 val)

Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c +0 -3
-		if (ret || val > max_freq || val < min_freq)
-			return -EINVAL;
-		ret = smu_set_soft_freq_range(&adev->smu, SMU_SCLK,

(uint32_t)val, (uint32_t)val);

drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c static int amdgpu_debugfs_sclk_set(void *data, u64 val)

Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c +1 -2
-	} else {
-		return 0;
+	ret = amdgpu_dpm_get_dpm_freq_range(adev, PP_SCLK,

&min_freq, &max_freq);

drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c static int amdgpu_debugfs_sclk_set(void *data, u64 val)

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c +9 -0
+	if (ret == -EOPNOTSUPP) {
+		ret = 0;
+		goto out;
  	}
+	if (ret || val > max_freq || val < min_freq) {
+		ret = -EINVAL;
+		goto out;
+	}
+
+	ret = amdgpu_dpm_set_soft_freq_range(adev, PP_SCLK,

(uint32_t)val, (uint32_t)val);

drivers/gpu/drm/amd/amdgpu/amdgpu_device.c static int amdgpu_device_ip_late_init(struct

Quoted 21 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c +4 -4
+	if (ret)
+		ret = -EINVAL;
 
+out:
  	pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
  	pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
 
-	if (ret)
-		return -EINVAL;
-
-	return 0;
+	return ret;
  }
 
  DEFINE_DEBUGFS_ATTRIBUTE(fops_ib_preempt, NULL, diff --git

a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
index 1989f9e9379e..41cc1ffb5809 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +0 -0
@@ -2617,7 +2617,7 @@ static int amdgpu_device_ip_late_init(struct

amdgpu_device *adev)

drivers/gpu/drm/amd/amdgpu/amdgpu_device.c static int

Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +1 -1
  	if (adev->asic_type == CHIP_ARCTURUS &&
  	    amdgpu_passthrough(adev) &&
  	    adev->gmc.xgmi.num_physical_nodes > 1)
-		smu_set_light_sbr(&adev->smu, true);
+		amdgpu_dpm_set_light_sbr(adev, true);
 
  	if (adev->gmc.xgmi.num_physical_nodes > 1) {
  		mutex_lock(&mgpu_info.mutex);
@@ -2857,7 +2857,7 @@ static int

amdgpu_device_ip_suspend_phase2(struct amdgpu_device *adev)

drivers/gpu/drm/amd/amdgpu/amdgpu_device.c static int amdgpu_device_ip_suspend_phase2(struct amdgpu_device *adev)

Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +0 -1
  	int i, r;
 
  	if (adev->in_s0ix)
-		amdgpu_gfx_state_change_set(adev,

sGpuChangeState_D3Entry);

drivers/gpu/drm/amd/amdgpu/amdgpu_device.c static int · line 2860

Quoted 1 line
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +1 -0
+		amdgpu_dpm_gfx_state_change(adev,

sGpuChangeState_D3Entry);

drivers/gpu/drm/amd/amdgpu/amdgpu_device.c int amdgpu_device_resume(struct drm_device

Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +0 -0
  	for (i = adev->num_ip_blocks - 1; i >= 0; i--) {
  		if (!adev->ip_blocks[i].status.valid)
@@ -3982,7 +3982,7 @@ int amdgpu_device_resume(struct drm_device

*dev, bool fbcon)

drivers/gpu/drm/amd/amdgpu/amdgpu_device.c int amdgpu_device_resume(struct drm_device *dev, bool fbcon)

Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +0 -1
  		return 0;
 
  	if (adev->in_s0ix)
-		amdgpu_gfx_state_change_set(adev,

sGpuChangeState_D0Entry);

drivers/gpu/drm/amd/amdgpu/amdgpu_device.c int amdgpu_device_resume(struct drm_device · line 3985

Quoted 1 line
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +1 -0
+		amdgpu_dpm_gfx_state_change(adev,

sGpuChangeState_D0Entry);

drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c int amdgpu_get_gfx_off_status(struct

Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +0 -0
  	/* post card */
  	if (amdgpu_device_need_post(adev)) { diff --git

a/drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c
b/drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c
index 1916ec84dd71..3d8f82dc8c97 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c +0 -0
@@ -615,7 +615,7 @@ int amdgpu_get_gfx_off_status(struct

amdgpu_device

drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c int amdgpu_gfx_get_num_kcq(struct

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c +1 -1
 *adev, uint32_t *value)
 
  	mutex_lock(&adev->gfx.gfx_off_mutex);
 
-	r = smu_get_status_gfxoff(adev, value);
+	r = amdgpu_dpm_get_status_gfxoff(adev, value);
 
  	mutex_unlock(&adev->gfx.gfx_off_mutex);
@@ -852,19 +852,3 @@ int amdgpu_gfx_get_num_kcq(struct

amdgpu_device *adev)

Quoted 26 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c +0 -9
  	}
  	return amdgpu_num_kcq;
  }
-
-/* amdgpu_gfx_state_change_set - Handle gfx power state change set
- * @adev: amdgpu_device pointer
- * @state: gfx power state(1 -sGpuChangeState_D0Entry and 2
-sGpuChangeState_D3Entry)
- *
- */
-
-void amdgpu_gfx_state_change_set(struct amdgpu_device *adev, enum

gfx_change_state state) -{

drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c +0 -7
-	mutex_lock(&adev->pm.mutex);
-	if (adev->powerplay.pp_funcs &&
-	    adev->powerplay.pp_funcs->gfx_state_change_set)
-		((adev)->powerplay.pp_funcs->gfx_state_change_set(
-			(adev)->powerplay.pp_handle, state));
-	mutex_unlock(&adev->pm.mutex);
-}
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h +0 -0
index f851196c83a5..776c886fd94a 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h enum amdgpu_gfx_pipe_priority { · line 50

Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h +0 -1
@@ -47,12 +47,6 @@ enum amdgpu_gfx_pipe_priority {
  	AMDGPU_GFX_PIPE_PRIO_HIGH = AMDGPU_RING_PRIO_2
  };
 
-/* Argument for PPSMC_MSG_GpuChangeState */ -enum

gfx_change_state {

drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h int amdgpu_gfx_cp_ecc_error_irq(struct

Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h +0 -4
-	sGpuChangeState_D0Entry = 1,
-	sGpuChangeState_D3Entry,
-};
-
  #define AMDGPU_GFX_QUEUE_PRIORITY_MINIMUM  0
  #define AMDGPU_GFX_QUEUE_PRIORITY_MAXIMUM  15
 
@@ -410,5 +404,4 @@ int amdgpu_gfx_cp_ecc_error_irq(struct

amdgpu_device *adev,

drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h int amdgpu_gfx_cp_ecc_error_irq(struct · line 405

Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h +0 -0
  uint32_t amdgpu_kiq_rreg(struct amdgpu_device *adev, uint32_t reg);
  void amdgpu_kiq_wreg(struct amdgpu_device *adev, uint32_t reg,

uint32_t v);

Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h +0 -0
  int amdgpu_gfx_get_num_kcq(struct amdgpu_device *adev); -void

amdgpu_gfx_state_change_set(struct amdgpu_device *adev, enum

gfx_change_state state);

drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c static void amdgpu_ras_get_ecc_info(struct

Quoted 7 lines
  #endif
drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c +0 -0
index 3c623e589b79..35c4aec04a7e 100644
@@ -901,7 +901,7 @@ static void amdgpu_ras_get_ecc_info(struct

amdgpu_device *adev, struct ras_err_d

drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c int amdgpu_ras_recovery_init(struct

Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c +1 -1
  	 * choosing right query method according to
  	 * whether smu support query error information
  	 */
-	ret = smu_get_ecc_info(&adev->smu, (void *)&(ras->umc_ecc));
+	ret = amdgpu_dpm_get_ecc_info(adev, (void *)&(ras->umc_ecc));
  	if (ret == -EOPNOTSUPP) {
  		if (adev->umc.ras_funcs &&
  			adev->umc.ras_funcs->query_ras_error_count)
@@ -2132,8 +2132,7 @@ int amdgpu_ras_recovery_init(struct

amdgpu_device *adev)

drivers/gpu/drm/amd/amdgpu/amdgpu_umc.c int amdgpu_umc_process_ras_data_cb(struct

Quoted 19 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c +0 -2
  		if (ret)
  			goto free;
 
-		if (adev->smu.ppt_funcs && adev->smu.ppt_funcs-
 send_hbm_bad_pages_num)
-			adev->smu.ppt_funcs-

send_hbm_bad_pages_num(&adev->smu, con-
eeprom_control.ras_num_recs);

drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c +2 -0
+		amdgpu_dpm_send_hbm_bad_pages_num(adev,
+con->eeprom_control.ras_num_recs);
  	}
 
  #ifdef CONFIG_X86_MCE_AMD
drivers/gpu/drm/amd/amdgpu/amdgpu_umc.c +0 -0
index 6e4bea012ea4..5fed26c8db44 100644
@@ -97,7 +97,7 @@ int amdgpu_umc_process_ras_data_cb(struct

amdgpu_device *adev,

drivers/gpu/drm/amd/amdgpu/amdgpu_umc.c int amdgpu_umc_process_ras_data_cb(struct

Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_umc.c +1 -1
  	int ret = 0;
 
  	kgd2kfd_set_sram_ecc_flag(adev->kfd.dev);
-	ret = smu_get_ecc_info(&adev->smu, (void *)&(con->umc_ecc));
+	ret = amdgpu_dpm_get_ecc_info(adev, (void *)&(con->umc_ecc));
  	if (ret == -EOPNOTSUPP) {
  		if (adev->umc.ras_funcs &&
  		    adev->umc.ras_funcs->query_ras_error_count)
@@ -160,8 +160,7 @@ int amdgpu_umc_process_ras_data_cb(struct

amdgpu_device *adev,

Quoted 27 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_umc.c +0 -2
  						err_data->err_addr_cnt);
  			amdgpu_ras_save_bad_pages(adev);
 
-			if (adev->smu.ppt_funcs && adev->smu.ppt_funcs-
 send_hbm_bad_pages_num)
-				adev->smu.ppt_funcs-

send_hbm_bad_pages_num(&adev->smu, con-
eeprom_control.ras_num_recs);

drivers/gpu/drm/amd/amdgpu/amdgpu_umc.c +2 -0
+			amdgpu_dpm_send_hbm_bad_pages_num(adev,
+con->eeprom_control.ras_num_recs);
  		}
 
  		amdgpu_ras_reset_gpu(adev);
drivers/gpu/drm/amd/amdkfd/kfd_smi_events.c +1 -1
index deae12dc777d..329a4c89f1e6 100644
@@ -222,7 +222,7 @@ void
 kfd_smi_event_update_thermal_throttling(struct kfd_dev *dev,
 
  	len = snprintf(fifo_in, sizeof(fifo_in), "%x %llx:%llx\n",
  		       KFD_SMI_EVENT_THERMAL_THROTTLE, throttle_bitmask,
-		       atomic64_read(&dev->adev->smu.throttle_int_counter));
+		       amdgpu_dpm_get_thermal_throttling_counter(dev-
 adev));
 
Quoted 1 line

add_event_to_kfifo(dev, KFD_SMI_EVENT_THERMAL_THROTTLE,

	fifo_in, len);
Quoted 27 lines
  }
drivers/gpu/drm/amd/include/kgd_pp_interface.h +4 -0
index 5c0867ebcfce..2e295facd086 100644
@@ -26,6 +26,10 @@
 
  extern const struct amdgpu_ip_block_version pp_smu_ip_block;
 
+enum smu_event_type {
+	SMU_EVENT_RESET_COMPLETE = 0,
+};
+
  struct amd_vce_state {
  	/* vce clocks */
  	u32 evclk;
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +0 -0
index 08362d506534..9b332c8a0079 100644
@@ -1614,3 +1614,98 @@ int amdgpu_pm_load_smu_firmware(struct

amdgpu_device *adev, uint32_t *smu_versio

  	return 0;
  }

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

Quoted 2 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +2 -0
+
+int amdgpu_dpm_set_light_sbr(struct amdgpu_device *adev, bool

enable)

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

Quoted 4 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +4 -0
+{
+	return smu_set_light_sbr(&adev->smu, enable); }
+
+int amdgpu_dpm_send_hbm_bad_pages_num(struct amdgpu_device

*adev,

Quoted 13 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +4 -0
+uint32_t size) {
+	int ret = 0;
+
+	if (adev->smu.ppt_funcs && adev->smu.ppt_funcs-

send_hbm_bad_pages_num)

drivers/gpu/drm/amd/pm/amdgpu_dpm.c +1 -0
+		ret = adev->smu.ppt_funcs-

send_hbm_bad_pages_num(&adev->smu,

drivers/gpu/drm/amd/pm/amdgpu_dpm.c +6 -0
+size);
+
+	return ret;
+}
+
+int amdgpu_dpm_get_dpm_freq_range(struct amdgpu_device *adev,

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

Quoted 10 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +10 -0
+				  enum pp_clock_type type,
+				  uint32_t *min,
+				  uint32_t *max)
+{
+	if (!is_support_sw_smu(adev))
+		return -EOPNOTSUPP;
+
+	switch (type) {
+	case PP_SCLK:
+		return smu_get_dpm_freq_range(&adev->smu, SMU_SCLK,

min, max);

Quoted 6 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +6 -0
+	default:
+		return -EINVAL;
+	}
+}
+
+int amdgpu_dpm_set_soft_freq_range(struct amdgpu_device *adev,

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

Quoted 10 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +10 -0
+				   enum pp_clock_type type,
+				   uint32_t min,
+				   uint32_t max)
+{
+	if (!is_support_sw_smu(adev))
+		return -EOPNOTSUPP;
+
+	switch (type) {
+	case PP_SCLK:
+		return smu_set_soft_freq_range(&adev->smu, SMU_SCLK,

min, max);

Quoted 5 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +5 -0
+	default:
+		return -EINVAL;
+	}
+}
+

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

Quoted 10 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +10 -0
+int amdgpu_dpm_wait_for_event(struct amdgpu_device *adev,
+			      enum smu_event_type event,
+			      uint64_t event_arg)
+{
+	if (!is_support_sw_smu(adev))
+		return -EOPNOTSUPP;
+
+	return smu_wait_for_event(&adev->smu, event, event_arg); }
+
+int amdgpu_dpm_get_status_gfxoff(struct amdgpu_device *adev,

uint32_t

Quoted 24 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +24 -0
+*value) {
+	if (!is_support_sw_smu(adev))
+		return -EOPNOTSUPP;
+
+	return smu_get_status_gfxoff(&adev->smu, value); }
+
+uint64_t amdgpu_dpm_get_thermal_throttling_counter(struct
+amdgpu_device *adev) {
+	return atomic64_read(&adev->smu.throttle_int_counter);
+}
+
+/* amdgpu_dpm_gfx_state_change - Handle gfx power state change set
+ * @adev: amdgpu_device pointer
+ * @state: gfx power state(1 -sGpuChangeState_D0Entry and 2
+-sGpuChangeState_D3Entry)
+ *
+ */
+void amdgpu_dpm_gfx_state_change(struct amdgpu_device *adev,
+				 enum gfx_change_state state)
+{
+	mutex_lock(&adev->pm.mutex);
+	if (adev->powerplay.pp_funcs &&
+	    adev->powerplay.pp_funcs->gfx_state_change_set)
+		((adev)->powerplay.pp_funcs->gfx_state_change_set(

drivers/gpu/drm/amd/pm/amdgpu_dpm.c int amdgpu_pm_load_smu_firmware(struct amdgpu_device *adev, uint32_t *smu_versio · line 1709

Quoted 10 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +10 -0
+			(adev)->powerplay.pp_handle, state));
+	mutex_unlock(&adev->pm.mutex);
+}
+
+int amdgpu_dpm_get_ecc_info(struct amdgpu_device *adev,
+			    void *umc_ecc)
+{
+	if (!is_support_sw_smu(adev))
+		return -EOPNOTSUPP;
+

In general, I don't think we need to keep this check everywhere to make amdgpu_dpm_* backwards compatible. The usage is also inconsistent. For
ex: amdgpu_dpm_get_thermal_throttling_counter doesn't have any is_support_sw_smu check whereas amdgpu_dpm_get_ecc_info() has it. There is no reason to keep adding is_support_sw_smu() check for every new public API. For sure, they are not going to work with powerplay subsystem.

Quoted 7 lines

I would rather prefer to leave old things and create amdgpu_smu_* for anything which is supported only in smu subsystem. It's easier to read from code perspective also - separate the ones which is supported by smu component and not supported in older powerplay components.

Only for the common ones that are supported in powerplay and smu, keep amdgpu_dpm_*, for others preference would be to keep amdgpu_smu_*.

[Quan, Evan] I get your point. However, then it will bring back the problem we are trying to avoid.
That is the caller need to know whether the amdgpu_smu_* can be used. They need to know whether the swsmu framework is supported on some ASIC.

And yes, there is some inconsistent cases existing in current power code. Maybe we can create new patche(s) to fix them? For this patch series, I would like to avoid any real code logic change.

BR
Evan

Quoted 140 lines

Thanks,
Lijo

drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h line 26

Quoted 11 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +1 -0
+	return smu_get_ecc_info(&adev->smu, umc_ecc); }
drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h +1 -0
index 16e3f72d31b9..7289d379a9fb 100644
@@ -23,6 +23,12 @@
  #ifndef __AMDGPU_DPM_H__
  #define __AMDGPU_DPM_H__
 
+/* Argument for PPSMC_MSG_GpuChangeState */ enum

gfx_change_state {

drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h void amdgpu_dpm_enable_vce(struct

Quoted 8 lines
drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h +4 -0
+	sGpuChangeState_D0Entry = 1,
+	sGpuChangeState_D3Entry,
+};
+
  enum amdgpu_int_thermal_type {
  	THERMAL_TYPE_NONE,
  	THERMAL_TYPE_EXTERNAL,
@@ -574,5 +580,22 @@ void amdgpu_dpm_enable_vce(struct

amdgpu_device *adev, bool enable);

drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h void amdgpu_dpm_enable_vce(struct · line 580

Quoted 1 line
drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h +0 -0
  void amdgpu_dpm_enable_jpeg(struct amdgpu_device *adev, bool

enable);

drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h void amdgpu_dpm_enable_vce(struct · line 582

Quoted 2 lines
drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h +0 -0
  void amdgpu_pm_print_power_states(struct amdgpu_device *adev);
  int amdgpu_pm_load_smu_firmware(struct amdgpu_device *adev,

uint32_t

drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h void amdgpu_dpm_enable_vce(struct · line 585

Quoted 4 lines
drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h +2 -1
 *smu_version);
-
+int amdgpu_dpm_set_light_sbr(struct amdgpu_device *adev, bool
+enable); int amdgpu_dpm_send_hbm_bad_pages_num(struct

amdgpu_device

drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h void amdgpu_dpm_enable_vce(struct · line 586

Quoted 1 line
drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h +1 -0
+*adev, uint32_t size); int amdgpu_dpm_get_dpm_freq_range(struct

amdgpu_device *adev,

drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h void amdgpu_dpm_enable_vce(struct amdgpu_device *adev, bool enable);

Quoted 8 lines
drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h +8 -0
+				       enum pp_clock_type type,
+				       uint32_t *min,
+				       uint32_t *max);
+int amdgpu_dpm_set_soft_freq_range(struct amdgpu_device *adev,
+				        enum pp_clock_type type,
+				        uint32_t min,
+				        uint32_t max);
+int amdgpu_dpm_wait_for_event(struct amdgpu_device *adev, enum

smu_event_type event,

drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h void amdgpu_dpm_enable_vce(struct · line 596

Quoted 2 lines
drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h +2 -0
+		       uint64_t event_arg);
+int amdgpu_dpm_get_status_gfxoff(struct amdgpu_device *adev,

uint32_t

drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h void amdgpu_dpm_enable_vce(struct · line 598

Quoted 2 lines
drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h +2 -0
+*value); uint64_t amdgpu_dpm_get_thermal_throttling_counter(struct
+amdgpu_device *adev); void amdgpu_dpm_gfx_state_change(struct

amdgpu_device *adev,

Quoted 24 lines
drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h +3 -0
+				 enum gfx_change_state state);
+int amdgpu_dpm_get_ecc_info(struct amdgpu_device *adev,
+			    void *umc_ecc);
  #endif
drivers/gpu/drm/amd/pm/inc/amdgpu_smu.h +0 -5
index f738f7dc20c9..29791bb21fba 100644
@@ -241,11 +241,6 @@ struct smu_user_dpm_profile {
  	uint32_t clk_dependency;
  };
 
-enum smu_event_type {
-
-	SMU_EVENT_RESET_COMPLETE = 0,
-};
-
  #define SMU_TABLE_INIT(tables, table_id, s, a, d)	\
  	do {						\
  		tables[table_id].size = s;		\
@@ -1412,11 +1407,11 @@ int smu_set_ac_dc(struct smu_context *smu);
 
  int smu_allow_xgmi_power_down(struct smu_context *smu, bool en);

drivers/gpu/drm/amd/pm/inc/amdgpu_smu.h int smu_set_ac_dc(struct smu_context *smu); · line 1416

Quoted 10 lines
drivers/gpu/drm/amd/pm/inc/amdgpu_smu.h +2 -2
 
-int smu_get_status_gfxoff(struct amdgpu_device *adev, uint32_t
 *value);
+int smu_get_status_gfxoff(struct smu_context *smu, uint32_t *value);
 
  int smu_set_light_sbr(struct smu_context *smu, bool enable);
 
-int smu_wait_for_event(struct amdgpu_device *adev, enum
 smu_event_type event,
+int smu_wait_for_event(struct smu_context *smu, enum

smu_event_type

Quoted 5 lines
drivers/gpu/drm/amd/pm/inc/amdgpu_smu.h +1 -0
+event,
  		       uint64_t event_arg);
  int smu_get_ecc_info(struct smu_context *smu, void *umc_ecc);
  int smu_stb_collect_info(struct smu_context *smu, void *buff,

uint32_t size); diff --git

a/drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c static int smu_sys_set_pp_feature_mask(void

Quoted 5 lines

b/drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c
index 5839918cb574..ef7d0e377965 100644

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +0 -0
@@ -100,17 +100,14 @@ static int smu_sys_set_pp_feature_mask(void

*handle,

Quoted 23 lines
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +5 -8
  	return ret;
  }
 
-int smu_get_status_gfxoff(struct amdgpu_device *adev, uint32_t
 *value)
+int smu_get_status_gfxoff(struct smu_context *smu, uint32_t *value)
  {
-	int ret = 0;
-	struct smu_context *smu = &adev->smu;
+	if (!smu->ppt_funcs->get_gfx_off_status)
+		return -EINVAL;
 
-	if (is_support_sw_smu(adev) && smu->ppt_funcs-
 get_gfx_off_status)
-		*value = smu_get_gfx_off_status(smu);
-	else
-		ret = -EINVAL;
+	*value = smu_get_gfx_off_status(smu);
 
-	return ret;
+	return 0;
  }
Quoted 8 lines

int smu_set_soft_freq_range(struct smu_context *smu, @@ -3167,11
+3164,10 @@ static const struct amd_pm_funcs swsmu_pm_funcs = {
.get_smu_prv_buf_details = smu_get_prv_buffer_details,
};

-int smu_wait_for_event(struct amdgpu_device *adev, enum smu_event_type event,
+int smu_wait_for_event(struct smu_context *smu, enum

smu_event_type

Quoted 9 lines
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +1 -1
+event,
  		       uint64_t event_arg)
  {
  	int ret = -EINVAL;
-	struct smu_context *smu = &adev->smu;
 
  	if (smu->ppt_funcs->wait_for_event) {
  		mutex_lock(&smu->mutex);
#4 lore raw

Re: [PATCH V2 01/17] drm/amd/pm: do not expose implementation details to other blocks out of power

Quoted 424 lines · Evan

[AMD Official Use Only]

Quoted 420 lines

-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Lazar, Lijo
Sent: Tuesday, November 30, 2021 4:10 PM
To: Quan, Evan <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>; Feng, Kenneth <[email protected]>; Koenig, Christian <[email protected]>
Subject: Re: [PATCH V2 01/17] drm/amd/pm: do not expose implementation details to other blocks out of power

Quoted 3 lines · Evan Quan

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

implementation details.

Quoted 14 lines
Change-Id Ibca3462ceaa26a27a9145282b60c6ce5deca7752
---
   drivers/gpu/drm/amd/amdgpu/aldebaran.c        |  2 +-
   drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c   | 25 ++---
   drivers/gpu/drm/amd/amdgpu/amdgpu_device.c    |  6 +-
   drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c       | 18 +---
   drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h       |  7 --
   drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c       |  5 +-
   drivers/gpu/drm/amd/amdgpu/amdgpu_umc.c       |  5 +-
   drivers/gpu/drm/amd/amdkfd/kfd_smi_events.c   |  2 +-
   .../gpu/drm/amd/include/kgd_pp_interface.h    |  4 +
   drivers/gpu/drm/amd/pm/amdgpu_dpm.c           | 95

+++++++++++++++++++

drivers/gpu/drm/amd/amdgpu/aldebaran.c static int aldebaran_mode2_restore_ip(struct

Quoted 11 lines
   drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h       | 25 ++++-
   drivers/gpu/drm/amd/pm/inc/amdgpu_smu.h       |  9 +-
   drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c     | 16 ++--
   13 files changed, 155 insertions(+), 64 deletions(-)
drivers/gpu/drm/amd/amdgpu/aldebaran.c +0 -0
index bcfdb63b1d42..a545df4efce1 100644
@@ -260,7 +260,7 @@ static int aldebaran_mode2_restore_ip(struct

amdgpu_device *adev)

drivers/gpu/drm/amd/amdgpu/aldebaran.c static int aldebaran_mode2_restore_ip(struct amdgpu_device *adev)

Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/aldebaran.c +1 -1
   	adev->gfx.rlc.funcs->resume(adev);
 
   	/* Wait for FW reset event complete */
-	r = smu_wait_for_event(adev, SMU_EVENT_RESET_COMPLETE, 0);
+	r = amdgpu_dpm_wait_for_event(adev,

SMU_EVENT_RESET_COMPLETE, 0);

drivers/gpu/drm/amd/amdgpu/aldebaran.c static int aldebaran_mode2_restore_ip(struct amdgpu_device *adev) · line 266

Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/aldebaran.c +0 -0
   	if (r) {
   		dev_err(adev->dev,
   			"Failed to get response from firmware after reset\n");

diff --git

drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c static int amdgpu_debugfs_sclk_set(void *data,

Quoted 6 lines

a/drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c
b/drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c
index 164d6a9e9fbb..0d1f00b24aae 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c +0 -0
@@ -1585,22 +1585,25 @@ static int amdgpu_debugfs_sclk_set(void *data,

u64 val)

drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c static int amdgpu_debugfs_sclk_set(void *data, u64 val)

Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c +0 -2
   		return ret;
   	}
 
-	if (is_support_sw_smu(adev)) {
-		ret = smu_get_dpm_freq_range(&adev->smu, SMU_SCLK,

&min_freq, &max_freq);

drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c static int amdgpu_debugfs_sclk_set(void *data, u64 val)

Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c +0 -3
-		if (ret || val > max_freq || val < min_freq)
-			return -EINVAL;
-		ret = smu_set_soft_freq_range(&adev->smu, SMU_SCLK,

(uint32_t)val, (uint32_t)val);

drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c static int amdgpu_debugfs_sclk_set(void *data, u64 val)

Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c +1 -2
-	} else {
-		return 0;
+	ret = amdgpu_dpm_get_dpm_freq_range(adev, PP_SCLK,

&min_freq, &max_freq);

drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c static int amdgpu_debugfs_sclk_set(void *data, u64 val)

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c +9 -0
+	if (ret == -EOPNOTSUPP) {
+		ret = 0;
+		goto out;
   	}
+	if (ret || val > max_freq || val < min_freq) {
+		ret = -EINVAL;
+		goto out;
+	}
+
+	ret = amdgpu_dpm_set_soft_freq_range(adev, PP_SCLK,

(uint32_t)val, (uint32_t)val);

drivers/gpu/drm/amd/amdgpu/amdgpu_device.c static int amdgpu_device_ip_late_init(struct

Quoted 21 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c +4 -4
+	if (ret)
+		ret = -EINVAL;
 
+out:
   	pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
   	pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
 
-	if (ret)
-		return -EINVAL;
-
-	return 0;
+	return ret;
   }
 
   DEFINE_DEBUGFS_ATTRIBUTE(fops_ib_preempt, NULL, diff --git

a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
index 1989f9e9379e..41cc1ffb5809 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +0 -0
@@ -2617,7 +2617,7 @@ static int amdgpu_device_ip_late_init(struct

amdgpu_device *adev)

drivers/gpu/drm/amd/amdgpu/amdgpu_device.c static int

Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +1 -1
   	if (adev->asic_type == CHIP_ARCTURUS &&
   	    amdgpu_passthrough(adev) &&
   	    adev->gmc.xgmi.num_physical_nodes > 1)
-		smu_set_light_sbr(&adev->smu, true);
+		amdgpu_dpm_set_light_sbr(adev, true);
 
   	if (adev->gmc.xgmi.num_physical_nodes > 1) {
   		mutex_lock(&mgpu_info.mutex);
@@ -2857,7 +2857,7 @@ static int

amdgpu_device_ip_suspend_phase2(struct amdgpu_device *adev)

drivers/gpu/drm/amd/amdgpu/amdgpu_device.c static int amdgpu_device_ip_suspend_phase2(struct amdgpu_device *adev)

Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +0 -1
   	int i, r;
 
   	if (adev->in_s0ix)
-		amdgpu_gfx_state_change_set(adev,

sGpuChangeState_D3Entry);

drivers/gpu/drm/amd/amdgpu/amdgpu_device.c static int · line 2860

Quoted 1 line
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +1 -0
+		amdgpu_dpm_gfx_state_change(adev,

sGpuChangeState_D3Entry);

drivers/gpu/drm/amd/amdgpu/amdgpu_device.c int amdgpu_device_resume(struct drm_device

Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +0 -0
   	for (i = adev->num_ip_blocks - 1; i >= 0; i--) {
   		if (!adev->ip_blocks[i].status.valid)
@@ -3982,7 +3982,7 @@ int amdgpu_device_resume(struct drm_device

*dev, bool fbcon)

drivers/gpu/drm/amd/amdgpu/amdgpu_device.c int amdgpu_device_resume(struct drm_device *dev, bool fbcon)

Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +0 -1
   		return 0;
 
   	if (adev->in_s0ix)
-		amdgpu_gfx_state_change_set(adev,

sGpuChangeState_D0Entry);

drivers/gpu/drm/amd/amdgpu/amdgpu_device.c int amdgpu_device_resume(struct drm_device · line 3985

Quoted 1 line
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +1 -0
+		amdgpu_dpm_gfx_state_change(adev,

sGpuChangeState_D0Entry);

drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c int amdgpu_get_gfx_off_status(struct

Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +0 -0
   	/* post card */
   	if (amdgpu_device_need_post(adev)) { diff --git

a/drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c
b/drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c
index 1916ec84dd71..3d8f82dc8c97 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c +0 -0
@@ -615,7 +615,7 @@ int amdgpu_get_gfx_off_status(struct

amdgpu_device

drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c int amdgpu_gfx_get_num_kcq(struct

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c +1 -1
 *adev, uint32_t *value)
 
   	mutex_lock(&adev->gfx.gfx_off_mutex);
 
-	r = smu_get_status_gfxoff(adev, value);
+	r = amdgpu_dpm_get_status_gfxoff(adev, value);
 
   	mutex_unlock(&adev->gfx.gfx_off_mutex);
@@ -852,19 +852,3 @@ int amdgpu_gfx_get_num_kcq(struct

amdgpu_device *adev)

Quoted 26 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c +0 -9
   	}
   	return amdgpu_num_kcq;
   }
-
-/* amdgpu_gfx_state_change_set - Handle gfx power state change set
- * @adev: amdgpu_device pointer
- * @state: gfx power state(1 -sGpuChangeState_D0Entry and 2
-sGpuChangeState_D3Entry)
- *
- */
-
-void amdgpu_gfx_state_change_set(struct amdgpu_device *adev, enum

gfx_change_state state) -{

drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c +0 -7
-	mutex_lock(&adev->pm.mutex);
-	if (adev->powerplay.pp_funcs &&
-	    adev->powerplay.pp_funcs->gfx_state_change_set)
-		((adev)->powerplay.pp_funcs->gfx_state_change_set(
-			(adev)->powerplay.pp_handle, state));
-	mutex_unlock(&adev->pm.mutex);
-}
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h +0 -0
index f851196c83a5..776c886fd94a 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h enum amdgpu_gfx_pipe_priority { · line 50

Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h +0 -1
@@ -47,12 +47,6 @@ enum amdgpu_gfx_pipe_priority {
   	AMDGPU_GFX_PIPE_PRIO_HIGH = AMDGPU_RING_PRIO_2
   };
 
-/* Argument for PPSMC_MSG_GpuChangeState */ -enum

gfx_change_state {

drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h int amdgpu_gfx_cp_ecc_error_irq(struct

Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h +0 -4
-	sGpuChangeState_D0Entry = 1,
-	sGpuChangeState_D3Entry,
-};
-
   #define AMDGPU_GFX_QUEUE_PRIORITY_MINIMUM  0
   #define AMDGPU_GFX_QUEUE_PRIORITY_MAXIMUM  15
 
@@ -410,5 +404,4 @@ int amdgpu_gfx_cp_ecc_error_irq(struct

amdgpu_device *adev,

drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h int amdgpu_gfx_cp_ecc_error_irq(struct · line 405

Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h +0 -0
   uint32_t amdgpu_kiq_rreg(struct amdgpu_device *adev, uint32_t reg);
   void amdgpu_kiq_wreg(struct amdgpu_device *adev, uint32_t reg,

uint32_t v);

Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h +0 -0
   int amdgpu_gfx_get_num_kcq(struct amdgpu_device *adev); -void

amdgpu_gfx_state_change_set(struct amdgpu_device *adev, enum

gfx_change_state state);

drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c static void amdgpu_ras_get_ecc_info(struct

Quoted 7 lines
   #endif
drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c +0 -0
index 3c623e589b79..35c4aec04a7e 100644
@@ -901,7 +901,7 @@ static void amdgpu_ras_get_ecc_info(struct

amdgpu_device *adev, struct ras_err_d

drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c int amdgpu_ras_recovery_init(struct

Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c +1 -1
   	 * choosing right query method according to
   	 * whether smu support query error information
   	 */
-	ret = smu_get_ecc_info(&adev->smu, (void *)&(ras->umc_ecc));
+	ret = amdgpu_dpm_get_ecc_info(adev, (void *)&(ras->umc_ecc));
   	if (ret == -EOPNOTSUPP) {
   		if (adev->umc.ras_funcs &&
   			adev->umc.ras_funcs->query_ras_error_count)
@@ -2132,8 +2132,7 @@ int amdgpu_ras_recovery_init(struct

amdgpu_device *adev)

drivers/gpu/drm/amd/amdgpu/amdgpu_umc.c int amdgpu_umc_process_ras_data_cb(struct

Quoted 19 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c +0 -2
   		if (ret)
   			goto free;
 
-		if (adev->smu.ppt_funcs && adev->smu.ppt_funcs-
 send_hbm_bad_pages_num)
-			adev->smu.ppt_funcs-

send_hbm_bad_pages_num(&adev->smu, con-
eeprom_control.ras_num_recs);

drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c +2 -0
+		amdgpu_dpm_send_hbm_bad_pages_num(adev,
+con->eeprom_control.ras_num_recs);
   	}
 
   #ifdef CONFIG_X86_MCE_AMD
drivers/gpu/drm/amd/amdgpu/amdgpu_umc.c +0 -0
index 6e4bea012ea4..5fed26c8db44 100644
@@ -97,7 +97,7 @@ int amdgpu_umc_process_ras_data_cb(struct

amdgpu_device *adev,

drivers/gpu/drm/amd/amdgpu/amdgpu_umc.c int amdgpu_umc_process_ras_data_cb(struct

Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_umc.c +1 -1
   	int ret = 0;
 
   	kgd2kfd_set_sram_ecc_flag(adev->kfd.dev);
-	ret = smu_get_ecc_info(&adev->smu, (void *)&(con->umc_ecc));
+	ret = amdgpu_dpm_get_ecc_info(adev, (void *)&(con->umc_ecc));
   	if (ret == -EOPNOTSUPP) {
   		if (adev->umc.ras_funcs &&
   		    adev->umc.ras_funcs->query_ras_error_count)
@@ -160,8 +160,7 @@ int amdgpu_umc_process_ras_data_cb(struct

amdgpu_device *adev,

Quoted 27 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_umc.c +0 -2
   						err_data->err_addr_cnt);
   			amdgpu_ras_save_bad_pages(adev);
 
-			if (adev->smu.ppt_funcs && adev->smu.ppt_funcs-
 send_hbm_bad_pages_num)
-				adev->smu.ppt_funcs-

send_hbm_bad_pages_num(&adev->smu, con-
eeprom_control.ras_num_recs);

drivers/gpu/drm/amd/amdgpu/amdgpu_umc.c +2 -0
+			amdgpu_dpm_send_hbm_bad_pages_num(adev,
+con->eeprom_control.ras_num_recs);
   		}
 
   		amdgpu_ras_reset_gpu(adev);
drivers/gpu/drm/amd/amdkfd/kfd_smi_events.c +1 -1
index deae12dc777d..329a4c89f1e6 100644
@@ -222,7 +222,7 @@ void
 kfd_smi_event_update_thermal_throttling(struct kfd_dev *dev,
 
   	len = snprintf(fifo_in, sizeof(fifo_in), "%x %llx:%llx\n",
   		       KFD_SMI_EVENT_THERMAL_THROTTLE, throttle_bitmask,
-		       atomic64_read(&dev->adev->smu.throttle_int_counter));
+		       amdgpu_dpm_get_thermal_throttling_counter(dev-
 adev));
 
Quoted 1 line

add_event_to_kfifo(dev, KFD_SMI_EVENT_THERMAL_THROTTLE,

	fifo_in, len);
Quoted 27 lines
   }
drivers/gpu/drm/amd/include/kgd_pp_interface.h +4 -0
index 5c0867ebcfce..2e295facd086 100644
@@ -26,6 +26,10 @@
 
   extern const struct amdgpu_ip_block_version pp_smu_ip_block;
 
+enum smu_event_type {
+	SMU_EVENT_RESET_COMPLETE = 0,
+};
+
   struct amd_vce_state {
   	/* vce clocks */
   	u32 evclk;
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +0 -0
index 08362d506534..9b332c8a0079 100644
@@ -1614,3 +1614,98 @@ int amdgpu_pm_load_smu_firmware(struct

amdgpu_device *adev, uint32_t *smu_versio

   	return 0;
   }

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

Quoted 2 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +2 -0
+
+int amdgpu_dpm_set_light_sbr(struct amdgpu_device *adev, bool

enable)

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

Quoted 4 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +4 -0
+{
+	return smu_set_light_sbr(&adev->smu, enable); }
+
+int amdgpu_dpm_send_hbm_bad_pages_num(struct amdgpu_device

*adev,

Quoted 13 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +4 -0
+uint32_t size) {
+	int ret = 0;
+
+	if (adev->smu.ppt_funcs && adev->smu.ppt_funcs-

send_hbm_bad_pages_num)

drivers/gpu/drm/amd/pm/amdgpu_dpm.c +1 -0
+		ret = adev->smu.ppt_funcs-

send_hbm_bad_pages_num(&adev->smu,

drivers/gpu/drm/amd/pm/amdgpu_dpm.c +6 -0
+size);
+
+	return ret;
+}
+
+int amdgpu_dpm_get_dpm_freq_range(struct amdgpu_device *adev,

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

Quoted 10 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +10 -0
+				  enum pp_clock_type type,
+				  uint32_t *min,
+				  uint32_t *max)
+{
+	if (!is_support_sw_smu(adev))
+		return -EOPNOTSUPP;
+
+	switch (type) {
+	case PP_SCLK:
+		return smu_get_dpm_freq_range(&adev->smu, SMU_SCLK,

min, max);

Quoted 6 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +6 -0
+	default:
+		return -EINVAL;
+	}
+}
+
+int amdgpu_dpm_set_soft_freq_range(struct amdgpu_device *adev,

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

Quoted 10 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +10 -0
+				   enum pp_clock_type type,
+				   uint32_t min,
+				   uint32_t max)
+{
+	if (!is_support_sw_smu(adev))
+		return -EOPNOTSUPP;
+
+	switch (type) {
+	case PP_SCLK:
+		return smu_set_soft_freq_range(&adev->smu, SMU_SCLK,

min, max);

Quoted 5 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +5 -0
+	default:
+		return -EINVAL;
+	}
+}
+

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

Quoted 10 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +10 -0
+int amdgpu_dpm_wait_for_event(struct amdgpu_device *adev,
+			      enum smu_event_type event,
+			      uint64_t event_arg)
+{
+	if (!is_support_sw_smu(adev))
+		return -EOPNOTSUPP;
+
+	return smu_wait_for_event(&adev->smu, event, event_arg); }
+
+int amdgpu_dpm_get_status_gfxoff(struct amdgpu_device *adev,

uint32_t

Quoted 24 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +24 -0
+*value) {
+	if (!is_support_sw_smu(adev))
+		return -EOPNOTSUPP;
+
+	return smu_get_status_gfxoff(&adev->smu, value); }
+
+uint64_t amdgpu_dpm_get_thermal_throttling_counter(struct
+amdgpu_device *adev) {
+	return atomic64_read(&adev->smu.throttle_int_counter);
+}
+
+/* amdgpu_dpm_gfx_state_change - Handle gfx power state change set
+ * @adev: amdgpu_device pointer
+ * @state: gfx power state(1 -sGpuChangeState_D0Entry and 2
+-sGpuChangeState_D3Entry)
+ *
+ */
+void amdgpu_dpm_gfx_state_change(struct amdgpu_device *adev,
+				 enum gfx_change_state state)
+{
+	mutex_lock(&adev->pm.mutex);
+	if (adev->powerplay.pp_funcs &&
+	    adev->powerplay.pp_funcs->gfx_state_change_set)
+		((adev)->powerplay.pp_funcs->gfx_state_change_set(

drivers/gpu/drm/amd/pm/amdgpu_dpm.c int amdgpu_pm_load_smu_firmware(struct amdgpu_device *adev, uint32_t *smu_versio · line 1709

Quoted 10 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +10 -0
+			(adev)->powerplay.pp_handle, state));
+	mutex_unlock(&adev->pm.mutex);
+}
+
+int amdgpu_dpm_get_ecc_info(struct amdgpu_device *adev,
+			    void *umc_ecc)
+{
+	if (!is_support_sw_smu(adev))
+		return -EOPNOTSUPP;
+

In general, I don't think we need to keep this check everywhere to make amdgpu_dpm_* backwards compatible. The usage is also inconsistent. For
ex: amdgpu_dpm_get_thermal_throttling_counter doesn't have any is_support_sw_smu check whereas amdgpu_dpm_get_ecc_info() has it. There is no reason to keep adding is_support_sw_smu() check for every new public API. For sure, they are not going to work with powerplay subsystem.

I would rather prefer to leave old things and create amdgpu_smu_* for anything which is supported only in smu subsystem. It's easier to read from code perspective also - separate the ones which is supported by smu component and not supported in older powerplay components.

Quoted 4 lines
Quoted 2 lines

Only for the common ones that are supported in powerplay and smu, keep amdgpu_dpm_*, for others preference would be to keep amdgpu_smu_*.

[Quan, Evan] I get your point. However, then it will bring back the problem we are trying to avoid.
That is the caller need to know whether the amdgpu_smu_* can be used. They need to know whether the swsmu framework is supported on some ASIC. >

swsmu has been for sometime. I'm suggesting to move away from amdgpu_dpm_* which is the legacy interface. There is no need to add new dpm_* APIs which are supported only in swsmu component. We only need to maintain the existing usage of dpm_*.

For the newer ones, let us move to component based APIs like amdgpu_smu_*. All the clients of swsmu are part of this component based architecture and they need to be aware of services of swsmu. It is similar to what is followed in other components like amdgpu_gmc_*, amdgpu_vcn* etc.

Thanks,
Lijo

Quoted 145 lines

And yes, there is some inconsistent cases existing in current power code. Maybe we can create new patche(s) to fix them? For this patch series, I would like to avoid any real code logic change.

BR
Evan

Quoted 140 lines

Thanks,
Lijo

drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h line 26

Quoted 11 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +1 -0
+	return smu_get_ecc_info(&adev->smu, umc_ecc); }
drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h +1 -0
index 16e3f72d31b9..7289d379a9fb 100644
@@ -23,6 +23,12 @@
   #ifndef __AMDGPU_DPM_H__
   #define __AMDGPU_DPM_H__
 
+/* Argument for PPSMC_MSG_GpuChangeState */ enum

gfx_change_state {

drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h void amdgpu_dpm_enable_vce(struct

Quoted 8 lines
drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h +4 -0
+	sGpuChangeState_D0Entry = 1,
+	sGpuChangeState_D3Entry,
+};
+
   enum amdgpu_int_thermal_type {
   	THERMAL_TYPE_NONE,
   	THERMAL_TYPE_EXTERNAL,
@@ -574,5 +580,22 @@ void amdgpu_dpm_enable_vce(struct

amdgpu_device *adev, bool enable);

drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h void amdgpu_dpm_enable_vce(struct · line 580

Quoted 1 line
drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h +0 -0
   void amdgpu_dpm_enable_jpeg(struct amdgpu_device *adev, bool

enable);

drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h void amdgpu_dpm_enable_vce(struct · line 582

Quoted 2 lines
drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h +0 -0
   void amdgpu_pm_print_power_states(struct amdgpu_device *adev);
   int amdgpu_pm_load_smu_firmware(struct amdgpu_device *adev,

uint32_t

drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h void amdgpu_dpm_enable_vce(struct · line 585

Quoted 4 lines
drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h +2 -1
 *smu_version);
-
+int amdgpu_dpm_set_light_sbr(struct amdgpu_device *adev, bool
+enable); int amdgpu_dpm_send_hbm_bad_pages_num(struct

amdgpu_device

drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h void amdgpu_dpm_enable_vce(struct · line 586

Quoted 1 line
drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h +1 -0
+*adev, uint32_t size); int amdgpu_dpm_get_dpm_freq_range(struct

amdgpu_device *adev,

drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h void amdgpu_dpm_enable_vce(struct amdgpu_device *adev, bool enable);

Quoted 8 lines
drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h +8 -0
+				       enum pp_clock_type type,
+				       uint32_t *min,
+				       uint32_t *max);
+int amdgpu_dpm_set_soft_freq_range(struct amdgpu_device *adev,
+				        enum pp_clock_type type,
+				        uint32_t min,
+				        uint32_t max);
+int amdgpu_dpm_wait_for_event(struct amdgpu_device *adev, enum

smu_event_type event,

drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h void amdgpu_dpm_enable_vce(struct · line 596

Quoted 2 lines
drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h +2 -0
+		       uint64_t event_arg);
+int amdgpu_dpm_get_status_gfxoff(struct amdgpu_device *adev,

uint32_t

drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h void amdgpu_dpm_enable_vce(struct · line 598

Quoted 2 lines
drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h +2 -0
+*value); uint64_t amdgpu_dpm_get_thermal_throttling_counter(struct
+amdgpu_device *adev); void amdgpu_dpm_gfx_state_change(struct

amdgpu_device *adev,

Quoted 24 lines
drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h +3 -0
+				 enum gfx_change_state state);
+int amdgpu_dpm_get_ecc_info(struct amdgpu_device *adev,
+			    void *umc_ecc);
   #endif
drivers/gpu/drm/amd/pm/inc/amdgpu_smu.h +0 -5
index f738f7dc20c9..29791bb21fba 100644
@@ -241,11 +241,6 @@ struct smu_user_dpm_profile {
   	uint32_t clk_dependency;
   };
 
-enum smu_event_type {
-
-	SMU_EVENT_RESET_COMPLETE = 0,
-};
-
   #define SMU_TABLE_INIT(tables, table_id, s, a, d)	\
   	do {						\
   		tables[table_id].size = s;		\
@@ -1412,11 +1407,11 @@ int smu_set_ac_dc(struct smu_context *smu);
 
   int smu_allow_xgmi_power_down(struct smu_context *smu, bool en);

drivers/gpu/drm/amd/pm/inc/amdgpu_smu.h int smu_set_ac_dc(struct smu_context *smu); · line 1416

Quoted 10 lines
drivers/gpu/drm/amd/pm/inc/amdgpu_smu.h +2 -2
 
-int smu_get_status_gfxoff(struct amdgpu_device *adev, uint32_t
 *value);
+int smu_get_status_gfxoff(struct smu_context *smu, uint32_t *value);
 
   int smu_set_light_sbr(struct smu_context *smu, bool enable);
 
-int smu_wait_for_event(struct amdgpu_device *adev, enum
 smu_event_type event,
+int smu_wait_for_event(struct smu_context *smu, enum

smu_event_type

Quoted 5 lines
drivers/gpu/drm/amd/pm/inc/amdgpu_smu.h +1 -0
+event,
   		       uint64_t event_arg);
   int smu_get_ecc_info(struct smu_context *smu, void *umc_ecc);
   int smu_stb_collect_info(struct smu_context *smu, void *buff,

uint32_t size); diff --git

a/drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c static int smu_sys_set_pp_feature_mask(void

Quoted 5 lines

b/drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c
index 5839918cb574..ef7d0e377965 100644

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +0 -0
@@ -100,17 +100,14 @@ static int smu_sys_set_pp_feature_mask(void

*handle,

Quoted 23 lines
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +5 -8
   	return ret;
   }
 
-int smu_get_status_gfxoff(struct amdgpu_device *adev, uint32_t
 *value)
+int smu_get_status_gfxoff(struct smu_context *smu, uint32_t *value)
   {
-	int ret = 0;
-	struct smu_context *smu = &adev->smu;
+	if (!smu->ppt_funcs->get_gfx_off_status)
+		return -EINVAL;
 
-	if (is_support_sw_smu(adev) && smu->ppt_funcs-
 get_gfx_off_status)
-		*value = smu_get_gfx_off_status(smu);
-	else
-		ret = -EINVAL;
+	*value = smu_get_gfx_off_status(smu);
 
-	return ret;
+	return 0;
   }
Quoted 8 lines
   int smu_set_soft_freq_range(struct smu_context *smu, @@ -3167,11

+3164,10 @@ static const struct amd_pm_funcs swsmu_pm_funcs = {
.get_smu_prv_buf_details = smu_get_prv_buffer_details,
};

-int smu_wait_for_event(struct amdgpu_device *adev, enum smu_event_type event,
+int smu_wait_for_event(struct smu_context *smu, enum

smu_event_type

Quoted 9 lines
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +1 -1
+event,
   		       uint64_t event_arg)
   {
   	int ret = -EINVAL;
-	struct smu_context *smu = &adev->smu;
 
   	if (smu->ppt_funcs->wait_for_event) {
   		mutex_lock(&smu->mutex);
author
#5 lore raw

RE: [PATCH V2 01/17] drm/amd/pm: do not expose implementation details to other blocks out of power

[AMD Official Use Only]

Quoted 459 lines

-----Original Message-----
From: Lazar, Lijo <[email protected]>
Sent: Wednesday, December 1, 2021 11:33 AM
To: Quan, Evan <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>; Feng, Kenneth <[email protected]>; Koenig, Christian <[email protected]>
Subject: Re: [PATCH V2 01/17] drm/amd/pm: do not expose implementation details to other blocks out of power

Quoted 11 lines · Evan

[AMD Official Use Only]

Quoted 7 lines

-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Lazar, Lijo
Sent: Tuesday, November 30, 2021 4:10 PM
To: Quan, Evan <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>; Feng, Kenneth <[email protected]>; Koenig, Christian

<[email protected]>

Quoted 7 lines
Quoted 7 lines

Subject: Re: [PATCH V2 01/17] drm/amd/pm: do not expose implementation details to other blocks out of power

Quoted 1 line · Evan Quan

Those implementation details(whether swsmu supported, some

ppt_funcs

Quoted 145 lines
Quoted 145 lines
Quoted 2 lines

supported, accessing internal statistics ...)should be kept internally. It's not a good practice and even error prone to expose

implementation details.

Quoted 14 lines
Change-Id Ibca3462ceaa26a27a9145282b60c6ce5deca7752
---
   drivers/gpu/drm/amd/amdgpu/aldebaran.c        |  2 +-
   drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c   | 25 ++---
   drivers/gpu/drm/amd/amdgpu/amdgpu_device.c    |  6 +-
   drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c       | 18 +---
   drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h       |  7 --
   drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c       |  5 +-
   drivers/gpu/drm/amd/amdgpu/amdgpu_umc.c       |  5 +-
   drivers/gpu/drm/amd/amdkfd/kfd_smi_events.c   |  2 +-
   .../gpu/drm/amd/include/kgd_pp_interface.h    |  4 +
   drivers/gpu/drm/amd/pm/amdgpu_dpm.c           | 95

+++++++++++++++++++

drivers/gpu/drm/amd/amdgpu/aldebaran.c static int aldebaran_mode2_restore_ip(struct

Quoted 11 lines
   drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h       | 25 ++++-
   drivers/gpu/drm/amd/pm/inc/amdgpu_smu.h       |  9 +-
   drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c     | 16 ++--
   13 files changed, 155 insertions(+), 64 deletions(-)
drivers/gpu/drm/amd/amdgpu/aldebaran.c +0 -0
index bcfdb63b1d42..a545df4efce1 100644
@@ -260,7 +260,7 @@ static int aldebaran_mode2_restore_ip(struct

amdgpu_device *adev)

drivers/gpu/drm/amd/amdgpu/aldebaran.c static int aldebaran_mode2_restore_ip(struct amdgpu_device *adev)

Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/aldebaran.c +1 -1
   	adev->gfx.rlc.funcs->resume(adev);
 
   	/* Wait for FW reset event complete */
-	r = smu_wait_for_event(adev, SMU_EVENT_RESET_COMPLETE, 0);
+	r = amdgpu_dpm_wait_for_event(adev,

SMU_EVENT_RESET_COMPLETE, 0);

drivers/gpu/drm/amd/amdgpu/aldebaran.c static int aldebaran_mode2_restore_ip(struct amdgpu_device *adev) · line 266

Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/aldebaran.c +0 -0
   	if (r) {
   		dev_err(adev->dev,
   			"Failed to get response from firmware after reset\n");

diff --git

drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c static int amdgpu_debugfs_sclk_set(void · line 1585

Quoted 7 lines

a/drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c
b/drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c
index 164d6a9e9fbb..0d1f00b24aae 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c +0 -0
@@ -1585,22 +1585,25 @@ static int amdgpu_debugfs_sclk_set(void
 *data,

u64 val)

drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c static int amdgpu_debugfs_sclk_set(void *data, u64 val)

Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c +0 -2
   		return ret;
   	}
 
-	if (is_support_sw_smu(adev)) {
-		ret = smu_get_dpm_freq_range(&adev->smu, SMU_SCLK,

&min_freq, &max_freq);

drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c static int amdgpu_debugfs_sclk_set(void *data, u64 val)

Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c +0 -3
-		if (ret || val > max_freq || val < min_freq)
-			return -EINVAL;
-		ret = smu_set_soft_freq_range(&adev->smu, SMU_SCLK,

(uint32_t)val, (uint32_t)val);

drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c static int amdgpu_debugfs_sclk_set(void *data, u64 val)

Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c +1 -2
-	} else {
-		return 0;
+	ret = amdgpu_dpm_get_dpm_freq_range(adev, PP_SCLK,

&min_freq, &max_freq);

drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c static int amdgpu_debugfs_sclk_set(void *data, u64 val)

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c +9 -0
+	if (ret == -EOPNOTSUPP) {
+		ret = 0;
+		goto out;
   	}
+	if (ret || val > max_freq || val < min_freq) {
+		ret = -EINVAL;
+		goto out;
+	}
+
+	ret = amdgpu_dpm_set_soft_freq_range(adev, PP_SCLK,

(uint32_t)val, (uint32_t)val);

drivers/gpu/drm/amd/amdgpu/amdgpu_device.c static int amdgpu_device_ip_late_init(struct

Quoted 21 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c +4 -4
+	if (ret)
+		ret = -EINVAL;
 
+out:
   	pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
   	pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
 
-	if (ret)
-		return -EINVAL;
-
-	return 0;
+	return ret;
   }
 
   DEFINE_DEBUGFS_ATTRIBUTE(fops_ib_preempt, NULL, diff --git

a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
index 1989f9e9379e..41cc1ffb5809 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +0 -0
@@ -2617,7 +2617,7 @@ static int amdgpu_device_ip_late_init(struct

amdgpu_device *adev)

drivers/gpu/drm/amd/amdgpu/amdgpu_device.c static int

Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +1 -1
   	if (adev->asic_type == CHIP_ARCTURUS &&
   	    amdgpu_passthrough(adev) &&
   	    adev->gmc.xgmi.num_physical_nodes > 1)
-		smu_set_light_sbr(&adev->smu, true);
+		amdgpu_dpm_set_light_sbr(adev, true);
 
   	if (adev->gmc.xgmi.num_physical_nodes > 1) {
   		mutex_lock(&mgpu_info.mutex);
@@ -2857,7 +2857,7 @@ static int

amdgpu_device_ip_suspend_phase2(struct amdgpu_device *adev)

drivers/gpu/drm/amd/amdgpu/amdgpu_device.c static int amdgpu_device_ip_suspend_phase2(struct amdgpu_device *adev)

Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +0 -1
   	int i, r;
 
   	if (adev->in_s0ix)
-		amdgpu_gfx_state_change_set(adev,

sGpuChangeState_D3Entry);

drivers/gpu/drm/amd/amdgpu/amdgpu_device.c static int · line 2860

Quoted 1 line
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +1 -0
+		amdgpu_dpm_gfx_state_change(adev,

sGpuChangeState_D3Entry);

drivers/gpu/drm/amd/amdgpu/amdgpu_device.c int amdgpu_device_resume(struct drm_device

Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +0 -0
   	for (i = adev->num_ip_blocks - 1; i >= 0; i--) {
   		if (!adev->ip_blocks[i].status.valid)
@@ -3982,7 +3982,7 @@ int amdgpu_device_resume(struct drm_device

*dev, bool fbcon)

drivers/gpu/drm/amd/amdgpu/amdgpu_device.c int amdgpu_device_resume(struct drm_device *dev, bool fbcon)

Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +0 -1
   		return 0;
 
   	if (adev->in_s0ix)
-		amdgpu_gfx_state_change_set(adev,

sGpuChangeState_D0Entry);

drivers/gpu/drm/amd/amdgpu/amdgpu_device.c int amdgpu_device_resume(struct drm_device · line 3985

Quoted 1 line
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +1 -0
+		amdgpu_dpm_gfx_state_change(adev,

sGpuChangeState_D0Entry);

drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c int amdgpu_get_gfx_off_status(struct

Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +0 -0
   	/* post card */
   	if (amdgpu_device_need_post(adev)) { diff --git

a/drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c
b/drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c
index 1916ec84dd71..3d8f82dc8c97 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c +0 -0
@@ -615,7 +615,7 @@ int amdgpu_get_gfx_off_status(struct

amdgpu_device

drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c int amdgpu_gfx_get_num_kcq(struct

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c +1 -1
 *adev, uint32_t *value)
 
   	mutex_lock(&adev->gfx.gfx_off_mutex);
 
-	r = smu_get_status_gfxoff(adev, value);
+	r = amdgpu_dpm_get_status_gfxoff(adev, value);
 
   	mutex_unlock(&adev->gfx.gfx_off_mutex);
@@ -852,19 +852,3 @@ int amdgpu_gfx_get_num_kcq(struct

amdgpu_device *adev)

Quoted 12 lines
Quoted 4 lines
Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c +0 -1
   	}
   	return amdgpu_num_kcq;
   }
-
Quoted 8 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c int amdgpu_gfx_get_num_kcq(struct amdgpu_device *adev)

Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c +0 -8
-/* amdgpu_gfx_state_change_set - Handle gfx power state change set
- * @adev: amdgpu_device pointer
- * @state: gfx power state(1 -sGpuChangeState_D0Entry and 2
-sGpuChangeState_D3Entry)
- *
- */
-
-void amdgpu_gfx_state_change_set(struct amdgpu_device *adev,

enum

Quoted 203 lines
Quoted 203 lines
Quoted 14 lines

gfx_change_state state) -{

drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c +0 -7
-	mutex_lock(&adev->pm.mutex);
-	if (adev->powerplay.pp_funcs &&
-	    adev->powerplay.pp_funcs->gfx_state_change_set)
-		((adev)->powerplay.pp_funcs->gfx_state_change_set(
-			(adev)->powerplay.pp_handle, state));
-	mutex_unlock(&adev->pm.mutex);
-}
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h +0 -0
index f851196c83a5..776c886fd94a 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h enum amdgpu_gfx_pipe_priority { · line 50

Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h +0 -1
@@ -47,12 +47,6 @@ enum amdgpu_gfx_pipe_priority {
   	AMDGPU_GFX_PIPE_PRIO_HIGH = AMDGPU_RING_PRIO_2
   };
 
-/* Argument for PPSMC_MSG_GpuChangeState */ -enum

gfx_change_state {

drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h int amdgpu_gfx_cp_ecc_error_irq(struct

Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h +0 -4
-	sGpuChangeState_D0Entry = 1,
-	sGpuChangeState_D3Entry,
-};
-
   #define AMDGPU_GFX_QUEUE_PRIORITY_MINIMUM  0
   #define AMDGPU_GFX_QUEUE_PRIORITY_MAXIMUM  15
 
@@ -410,5 +404,4 @@ int amdgpu_gfx_cp_ecc_error_irq(struct

amdgpu_device *adev,

drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h int amdgpu_gfx_cp_ecc_error_irq(struct · line 405

Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h +0 -0
   uint32_t amdgpu_kiq_rreg(struct amdgpu_device *adev, uint32_t reg);
   void amdgpu_kiq_wreg(struct amdgpu_device *adev, uint32_t reg,

uint32_t v);

Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h +0 -0
   int amdgpu_gfx_get_num_kcq(struct amdgpu_device *adev); -void

amdgpu_gfx_state_change_set(struct amdgpu_device *adev, enum

gfx_change_state state);

drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c static void amdgpu_ras_get_ecc_info(struct

Quoted 7 lines
   #endif
drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c +0 -0
index 3c623e589b79..35c4aec04a7e 100644
@@ -901,7 +901,7 @@ static void amdgpu_ras_get_ecc_info(struct

amdgpu_device *adev, struct ras_err_d

drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c int amdgpu_ras_recovery_init(struct

Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c +1 -1
   	 * choosing right query method according to
   	 * whether smu support query error information
   	 */
-	ret = smu_get_ecc_info(&adev->smu, (void *)&(ras->umc_ecc));
+	ret = amdgpu_dpm_get_ecc_info(adev, (void *)&(ras->umc_ecc));
   	if (ret == -EOPNOTSUPP) {
   		if (adev->umc.ras_funcs &&
   			adev->umc.ras_funcs->query_ras_error_count)
@@ -2132,8 +2132,7 @@ int amdgpu_ras_recovery_init(struct

amdgpu_device *adev)

drivers/gpu/drm/amd/amdgpu/amdgpu_umc.c int amdgpu_umc_process_ras_data_cb(struct

Quoted 19 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c +0 -2
   		if (ret)
   			goto free;
 
-		if (adev->smu.ppt_funcs && adev->smu.ppt_funcs-
 send_hbm_bad_pages_num)
-			adev->smu.ppt_funcs-

send_hbm_bad_pages_num(&adev->smu, con-
eeprom_control.ras_num_recs);

drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c +2 -0
+		amdgpu_dpm_send_hbm_bad_pages_num(adev,
+con->eeprom_control.ras_num_recs);
   	}
 
   #ifdef CONFIG_X86_MCE_AMD
drivers/gpu/drm/amd/amdgpu/amdgpu_umc.c +0 -0
index 6e4bea012ea4..5fed26c8db44 100644
@@ -97,7 +97,7 @@ int amdgpu_umc_process_ras_data_cb(struct

amdgpu_device *adev,

drivers/gpu/drm/amd/amdgpu/amdgpu_umc.c int amdgpu_umc_process_ras_data_cb(struct

Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_umc.c +1 -1
   	int ret = 0;
 
   	kgd2kfd_set_sram_ecc_flag(adev->kfd.dev);
-	ret = smu_get_ecc_info(&adev->smu, (void *)&(con->umc_ecc));
+	ret = amdgpu_dpm_get_ecc_info(adev, (void *)&(con->umc_ecc));
   	if (ret == -EOPNOTSUPP) {
   		if (adev->umc.ras_funcs &&
   		    adev->umc.ras_funcs->query_ras_error_count)
@@ -160,8 +160,7 @@ int amdgpu_umc_process_ras_data_cb(struct

amdgpu_device *adev,

Quoted 27 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_umc.c +0 -2
   						err_data->err_addr_cnt);
   			amdgpu_ras_save_bad_pages(adev);
 
-			if (adev->smu.ppt_funcs && adev->smu.ppt_funcs-
 send_hbm_bad_pages_num)
-				adev->smu.ppt_funcs-

send_hbm_bad_pages_num(&adev->smu, con-
eeprom_control.ras_num_recs);

drivers/gpu/drm/amd/amdgpu/amdgpu_umc.c +2 -0
+			amdgpu_dpm_send_hbm_bad_pages_num(adev,
+con->eeprom_control.ras_num_recs);
   		}
 
   		amdgpu_ras_reset_gpu(adev);
drivers/gpu/drm/amd/amdkfd/kfd_smi_events.c +1 -1
index deae12dc777d..329a4c89f1e6 100644
@@ -222,7 +222,7 @@ void
 kfd_smi_event_update_thermal_throttling(struct kfd_dev *dev,
 
   	len = snprintf(fifo_in, sizeof(fifo_in), "%x %llx:%llx\n",
   		       KFD_SMI_EVENT_THERMAL_THROTTLE, throttle_bitmask,
-		       atomic64_read(&dev->adev->smu.throttle_int_counter));
+		       amdgpu_dpm_get_thermal_throttling_counter(dev-
 adev));
 
Quoted 1 line

add_event_to_kfifo(dev, KFD_SMI_EVENT_THERMAL_THROTTLE,

	fifo_in, len);
Quoted 27 lines
   }
drivers/gpu/drm/amd/include/kgd_pp_interface.h +4 -0
index 5c0867ebcfce..2e295facd086 100644
@@ -26,6 +26,10 @@
 
   extern const struct amdgpu_ip_block_version pp_smu_ip_block;
 
+enum smu_event_type {
+	SMU_EVENT_RESET_COMPLETE = 0,
+};
+
   struct amd_vce_state {
   	/* vce clocks */
   	u32 evclk;
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +0 -0
index 08362d506534..9b332c8a0079 100644
@@ -1614,3 +1614,98 @@ int amdgpu_pm_load_smu_firmware(struct

amdgpu_device *adev, uint32_t *smu_versio

   	return 0;
   }

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

Quoted 2 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +2 -0
+
+int amdgpu_dpm_set_light_sbr(struct amdgpu_device *adev, bool

enable)

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

Quoted 4 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +4 -0
+{
+	return smu_set_light_sbr(&adev->smu, enable); }
+
+int amdgpu_dpm_send_hbm_bad_pages_num(struct amdgpu_device

*adev,

Quoted 13 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +4 -0
+uint32_t size) {
+	int ret = 0;
+
+	if (adev->smu.ppt_funcs && adev->smu.ppt_funcs-

send_hbm_bad_pages_num)

drivers/gpu/drm/amd/pm/amdgpu_dpm.c +1 -0
+		ret = adev->smu.ppt_funcs-

send_hbm_bad_pages_num(&adev->smu,

drivers/gpu/drm/amd/pm/amdgpu_dpm.c +6 -0
+size);
+
+	return ret;
+}
+
+int amdgpu_dpm_get_dpm_freq_range(struct amdgpu_device *adev,

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

Quoted 10 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +10 -0
+				  enum pp_clock_type type,
+				  uint32_t *min,
+				  uint32_t *max)
+{
+	if (!is_support_sw_smu(adev))
+		return -EOPNOTSUPP;
+
+	switch (type) {
+	case PP_SCLK:
+		return smu_get_dpm_freq_range(&adev->smu, SMU_SCLK,

min, max);

Quoted 6 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +6 -0
+	default:
+		return -EINVAL;
+	}
+}
+
+int amdgpu_dpm_set_soft_freq_range(struct amdgpu_device *adev,

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

Quoted 10 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +10 -0
+				   enum pp_clock_type type,
+				   uint32_t min,
+				   uint32_t max)
+{
+	if (!is_support_sw_smu(adev))
+		return -EOPNOTSUPP;
+
+	switch (type) {
+	case PP_SCLK:
+		return smu_set_soft_freq_range(&adev->smu, SMU_SCLK,

min, max);

Quoted 5 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +5 -0
+	default:
+		return -EINVAL;
+	}
+}
+

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

Quoted 10 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +10 -0
+int amdgpu_dpm_wait_for_event(struct amdgpu_device *adev,
+			      enum smu_event_type event,
+			      uint64_t event_arg)
+{
+	if (!is_support_sw_smu(adev))
+		return -EOPNOTSUPP;
+
+	return smu_wait_for_event(&adev->smu, event, event_arg); }
+
+int amdgpu_dpm_get_status_gfxoff(struct amdgpu_device *adev,

uint32_t

Quoted 12 lines
Quoted 4 lines
Quoted 4 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +4 -0
+*value) {
+	if (!is_support_sw_smu(adev))
+		return -EOPNOTSUPP;
+
Quoted 8 lines

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

Quoted 8 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +8 -0
+	return smu_get_status_gfxoff(&adev->smu, value); }
+
+uint64_t amdgpu_dpm_get_thermal_throttling_counter(struct
+amdgpu_device *adev) {
+	return atomic64_read(&adev->smu.throttle_int_counter);
+}
+
+/* amdgpu_dpm_gfx_state_change - Handle gfx power state change

set

Quoted 23 lines
Quoted 23 lines
Quoted 22 lines

+ * @adev: amdgpu_device pointer
+ * @state: gfx power state(1 -sGpuChangeState_D0Entry and 2 +-sGpuChangeState_D3Entry)
+ *
+ */

drivers/gpu/drm/amd/pm/amdgpu_dpm.c +17 -0
+void amdgpu_dpm_gfx_state_change(struct amdgpu_device *adev,
+				 enum gfx_change_state state)
+{
+	mutex_lock(&adev->pm.mutex);
+	if (adev->powerplay.pp_funcs &&
+	    adev->powerplay.pp_funcs->gfx_state_change_set)
+		((adev)->powerplay.pp_funcs->gfx_state_change_set(
+			(adev)->powerplay.pp_handle, state));
+	mutex_unlock(&adev->pm.mutex);
+}
+
+int amdgpu_dpm_get_ecc_info(struct amdgpu_device *adev,
+			    void *umc_ecc)
+{
+	if (!is_support_sw_smu(adev))
+		return -EOPNOTSUPP;
+
Quoted 8 lines
Quoted 8 lines

In general, I don't think we need to keep this check everywhere to make
amdgpu_dpm_* backwards compatible. The usage is also inconsistent. For
ex: amdgpu_dpm_get_thermal_throttling_counter doesn't have any is_support_sw_smu check whereas amdgpu_dpm_get_ecc_info() has it. There is no reason to keep adding is_support_sw_smu() check for every new public API. For sure, they are not going to work with powerplay

subsystem.

Quoted 5 lines
Quoted 5 lines

I would rather prefer to leave old things and create amdgpu_smu_* for anything which is supported only in smu subsystem. It's easier to read from code perspective also - separate the ones which is supported by smu component and not supported in older powerplay

components.

Quoted 3 lines
Quoted 3 lines

Only for the common ones that are supported in powerplay and smu, keep amdgpu_dpm_*, for others preference would be to keep

amdgpu_smu_*.

Quoted 1 line

[Quan, Evan] I get your point. However, then it will bring back the problem

we are trying to avoid.

Quoted 3 lines

That is the caller need to know whether the amdgpu_smu_* can be used. They need to know whether the swsmu framework is supported on some ASIC. >

swsmu has been for sometime. I'm suggesting to move away from amdgpu_dpm_* which is the legacy interface. There is no need to add new dpm_* APIs which are supported only in swsmu component. We only need to maintain the existing usage of dpm_*.

Quoted 5 lines

For the newer ones, let us move to component based APIs like amdgpu_smu_*. All the clients of swsmu are part of this component based architecture and they need to be aware of services of swsmu. It is similar to what is followed in other components like amdgpu_gmc_*, amdgpu_vcn* etc.

[Quan, Evan] I'm open to the idea that move all swsmu based APIs to amdgpu_smu_*.
Maybe we can list that as a TODO in the further optimizations.
What I worried is the case below:
1. For gfx v9, Arcturus and Aldebaran support swsmu while other ASICs not.
2. Then for any swsmu API called from gfx_v9_0.c, there will be a "if (adev->asic_type == CHIP_ARCTURUS)" or similar guard needed. That will need the user know the details above.

For this patch, can we just stick to original amdgpu_dpm_* way? As I really do not want to involve too many changes.

BR
Evan

Quoted 153 lines

Thanks,
Lijo

Quoted 1 line

And yes, there is some inconsistent cases existing in current power code.

Maybe we can create new patche(s) to fix them?

Quoted 54 lines

For this patch series, I would like to avoid any real code logic change.

BR
Evan

Quoted 50 lines

Thanks,
Lijo

drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h line 26

Quoted 11 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +1 -0
+	return smu_get_ecc_info(&adev->smu, umc_ecc); }
drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h +1 -0
index 16e3f72d31b9..7289d379a9fb 100644
@@ -23,6 +23,12 @@
   #ifndef __AMDGPU_DPM_H__
   #define __AMDGPU_DPM_H__
 
+/* Argument for PPSMC_MSG_GpuChangeState */ enum

gfx_change_state {

drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h void amdgpu_dpm_enable_vce(struct

Quoted 8 lines
drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h +4 -0
+	sGpuChangeState_D0Entry = 1,
+	sGpuChangeState_D3Entry,
+};
+
   enum amdgpu_int_thermal_type {
   	THERMAL_TYPE_NONE,
   	THERMAL_TYPE_EXTERNAL,
@@ -574,5 +580,22 @@ void amdgpu_dpm_enable_vce(struct

amdgpu_device *adev, bool enable);

drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h void amdgpu_dpm_enable_vce(struct · line 580

Quoted 1 line
drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h +0 -0
   void amdgpu_dpm_enable_jpeg(struct amdgpu_device *adev, bool

enable);

drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h void amdgpu_dpm_enable_vce(struct · line 582

Quoted 2 lines
drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h +0 -0
   void amdgpu_pm_print_power_states(struct amdgpu_device *adev);
   int amdgpu_pm_load_smu_firmware(struct amdgpu_device *adev,

uint32_t

drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h void amdgpu_dpm_enable_vce(struct · line 585

Quoted 4 lines
drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h +2 -1
 *smu_version);
-
+int amdgpu_dpm_set_light_sbr(struct amdgpu_device *adev, bool
+enable); int amdgpu_dpm_send_hbm_bad_pages_num(struct

amdgpu_device

drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h void amdgpu_dpm_enable_vce(struct · line 586

Quoted 1 line
drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h +1 -0
+*adev, uint32_t size); int amdgpu_dpm_get_dpm_freq_range(struct

amdgpu_device *adev,

drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h void amdgpu_dpm_enable_vce(struct amdgpu_device *adev, bool enable);

Quoted 8 lines
drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h +8 -0
+				       enum pp_clock_type type,
+				       uint32_t *min,
+				       uint32_t *max);
+int amdgpu_dpm_set_soft_freq_range(struct amdgpu_device *adev,
+				        enum pp_clock_type type,
+				        uint32_t min,
+				        uint32_t max);
+int amdgpu_dpm_wait_for_event(struct amdgpu_device *adev, enum

smu_event_type event,

drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h void amdgpu_dpm_enable_vce(struct · line 596

Quoted 2 lines
drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h +2 -0
+		       uint64_t event_arg);
+int amdgpu_dpm_get_status_gfxoff(struct amdgpu_device *adev,

uint32_t

Quoted 1 line
drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h +1 -0
+*value); uint64_t

amdgpu_dpm_get_thermal_throttling_counter(struct

Quoted 15 lines
Quoted 15 lines

drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h void amdgpu_dpm_enable_vce(struct · line 598

Quoted 1 line
drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h +1 -0
+amdgpu_device *adev); void amdgpu_dpm_gfx_state_change(struct

amdgpu_device *adev,

Quoted 13 lines
drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h +3 -0
+				 enum gfx_change_state state);
+int amdgpu_dpm_get_ecc_info(struct amdgpu_device *adev,
+			    void *umc_ecc);
   #endif
drivers/gpu/drm/amd/pm/inc/amdgpu_smu.h +0 -0
index f738f7dc20c9..29791bb21fba 100644
@@ -241,11 +241,6 @@ struct smu_user_dpm_profile {
   	uint32_t clk_dependency;
   };
 
Quoted 9 lines
Quoted 9 lines

drivers/gpu/drm/amd/pm/inc/amdgpu_smu.h int smu_set_ac_dc(struct smu_context

Quoted 9 lines
drivers/gpu/drm/amd/pm/inc/amdgpu_smu.h +0 -5
-enum smu_event_type {
-
-	SMU_EVENT_RESET_COMPLETE = 0,
-};
-
   #define SMU_TABLE_INIT(tables, table_id, s, a, d)	\
   	do {						\
   		tables[table_id].size = s;		\
@@ -1412,11 +1407,11 @@ int smu_set_ac_dc(struct smu_context

*smu);

Quoted 67 lines
Quoted 67 lines

drivers/gpu/drm/amd/pm/inc/amdgpu_smu.h int smu_set_ac_dc(struct smu_context · line 1416

Quoted 13 lines
drivers/gpu/drm/amd/pm/inc/amdgpu_smu.h +3 -2
   int smu_allow_xgmi_power_down(struct smu_context *smu, bool en);
 
-int smu_get_status_gfxoff(struct amdgpu_device *adev, uint32_t
 *value);
+int smu_get_status_gfxoff(struct smu_context *smu, uint32_t
+*value);
 
   int smu_set_light_sbr(struct smu_context *smu, bool enable);
 
-int smu_wait_for_event(struct amdgpu_device *adev, enum
 smu_event_type event,
+int smu_wait_for_event(struct smu_context *smu, enum

smu_event_type

Quoted 5 lines
drivers/gpu/drm/amd/pm/inc/amdgpu_smu.h +1 -0
+event,
   		       uint64_t event_arg);
   int smu_get_ecc_info(struct smu_context *smu, void *umc_ecc);
   int smu_stb_collect_info(struct smu_context *smu, void *buff,

uint32_t size); diff --git

a/drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c static int smu_sys_set_pp_feature_mask(void

Quoted 5 lines

b/drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c
index 5839918cb574..ef7d0e377965 100644

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +0 -0
@@ -100,17 +100,14 @@ static int smu_sys_set_pp_feature_mask(void

*handle,

Quoted 23 lines
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +5 -8
   	return ret;
   }
 
-int smu_get_status_gfxoff(struct amdgpu_device *adev, uint32_t
 *value)
+int smu_get_status_gfxoff(struct smu_context *smu, uint32_t *value)
   {
-	int ret = 0;
-	struct smu_context *smu = &adev->smu;
+	if (!smu->ppt_funcs->get_gfx_off_status)
+		return -EINVAL;
 
-	if (is_support_sw_smu(adev) && smu->ppt_funcs-
 get_gfx_off_status)
-		*value = smu_get_gfx_off_status(smu);
-	else
-		ret = -EINVAL;
+	*value = smu_get_gfx_off_status(smu);
 
-	return ret;
+	return 0;
   }
Quoted 8 lines
   int smu_set_soft_freq_range(struct smu_context *smu, @@ -3167,11

+3164,10 @@ static const struct amd_pm_funcs swsmu_pm_funcs = {
.get_smu_prv_buf_details = smu_get_prv_buffer_details,
};

-int smu_wait_for_event(struct amdgpu_device *adev, enum smu_event_type event,
+int smu_wait_for_event(struct smu_context *smu, enum

smu_event_type

Quoted 9 lines
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +1 -1
+event,
   		       uint64_t event_arg)
   {
   	int ret = -EINVAL;
-	struct smu_context *smu = &adev->smu;
 
   	if (smu->ppt_funcs->wait_for_event) {
   		mutex_lock(&smu->mutex);
#6 lore raw

Re: [PATCH V2 01/17] drm/amd/pm: do not expose implementation details to other blocks out of power

In reply to Lazar, Lijo
Quoted 351 lines · Lijo
Quoted 335 lines · Evan Quan

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

Change-Id Ibca3462ceaa26a27a9145282b60c6ce5deca7752

---
  drivers/gpu/drm/amd/amdgpu/aldebaran.c        |  2 +- drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c   | 25 ++--- drivers/gpu/drm/amd/amdgpu/amdgpu_device.c    |  6 +-

  drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c       | 18 +---
  drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h       |  7 --
  drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c       |  5 +-
  drivers/gpu/drm/amd/amdgpu/amdgpu_umc.c       |  5 +-

  drivers/gpu/drm/amd/amdkfd/kfd_smi_events.c   |  2 +- .../gpu/drm/amd/include/kgd_pp_interface.h    |  4 + drivers/gpu/drm/amd/pm/amdgpu_dpm.c           | 95 +++++++++++++++++++ drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h       | 25 ++++- drivers/gpu/drm/amd/pm/inc/amdgpu_smu.h       |  9 +- drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c     | 16 ++--

  13 files changed, 155 insertions(+), 64 deletions(-)
drivers/gpu/drm/amd/amdgpu/aldebaran.c +1 -1
index bcfdb63b1d42..a545df4efce1 100644
@@ -260,7 +260,7 @@ static int aldebaran_mode2_restore_ip(struct 
 amdgpu_device *adev)
       adev->gfx.rlc.funcs->resume(adev);
       /* Wait for FW reset event complete */
-    r = smu_wait_for_event(adev, SMU_EVENT_RESET_COMPLETE, 0);
+    r = amdgpu_dpm_wait_for_event(adev, SMU_EVENT_RESET_COMPLETE, 0);
       if (r) {
           dev_err(adev->dev,
               "Failed to get response from firmware after reset\n");
drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c +14 -11
index 164d6a9e9fbb..0d1f00b24aae 100644
@@ -1585,22 +1585,25 @@ static int amdgpu_debugfs_sclk_set(void *data, 
 u64 val)
           return ret;
       }
-    if (is_support_sw_smu(adev)) {
-        ret = smu_get_dpm_freq_range(&adev->smu, SMU_SCLK, &min_freq, 
 &max_freq);
-        if (ret || val > max_freq || val < min_freq)
-            return -EINVAL;
-        ret = smu_set_soft_freq_range(&adev->smu, SMU_SCLK, 
 (uint32_t)val, (uint32_t)val);
-    } else {
-        return 0;
+    ret = amdgpu_dpm_get_dpm_freq_range(adev, PP_SCLK, &min_freq, 
 &max_freq);
+    if (ret == -EOPNOTSUPP) {
+        ret = 0;
+        goto out;
       }
+    if (ret || val > max_freq || val < min_freq) {
+        ret = -EINVAL;
+        goto out;
+    }
+
+    ret = amdgpu_dpm_set_soft_freq_range(adev, PP_SCLK, 
 (uint32_t)val, (uint32_t)val);
+    if (ret)
+        ret = -EINVAL;
+out:
       pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
       pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
-    if (ret)
-        return -EINVAL;
-
-    return 0;
+    return ret;
   }

  DEFINE_DEBUGFS_ATTRIBUTE(fops_ib_preempt, NULL,

drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +0 -0
index 1989f9e9379e..41cc1ffb5809 100644
@@ -2617,7 +2617,7 @@ static int amdgpu_device_ip_late_init(struct 
 amdgpu_device *adev)

      if (adev->asic_type == CHIP_ARCTURUS && amdgpu_passthrough(adev) && adev->gmc.xgmi.num_physical_nodes > 1) -        smu_set_light_sbr(&adev->smu, true); +        amdgpu_dpm_set_light_sbr(adev, true); if (adev->gmc.xgmi.num_physical_nodes > 1) { mutex_lock(&mgpu_info.mutex);

drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +2 -2
@@ -2857,7 +2857,7 @@ static int 
 amdgpu_device_ip_suspend_phase2(struct amdgpu_device *adev)
       int i, r;
       if (adev->in_s0ix)
-        amdgpu_gfx_state_change_set(adev, sGpuChangeState_D3Entry);
+        amdgpu_dpm_gfx_state_change(adev, sGpuChangeState_D3Entry);
       for (i = adev->num_ip_blocks - 1; i >= 0; i--) {
           if (!adev->ip_blocks[i].status.valid)
@@ -3982,7 +3982,7 @@ int amdgpu_device_resume(struct drm_device *dev, 
 bool fbcon)
           return 0;
       if (adev->in_s0ix)
-        amdgpu_gfx_state_change_set(adev, sGpuChangeState_D0Entry);
+        amdgpu_dpm_gfx_state_change(adev, sGpuChangeState_D0Entry);
       /* post card */
       if (amdgpu_device_need_post(adev)) {
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c +1 -1
index 1916ec84dd71..3d8f82dc8c97 100644
@@ -615,7 +615,7 @@ int amdgpu_get_gfx_off_status(struct amdgpu_device 
 *adev, uint32_t *value)
       mutex_lock(&adev->gfx.gfx_off_mutex);
-    r = smu_get_status_gfxoff(adev, value);
+    r = amdgpu_dpm_get_status_gfxoff(adev, value);
       mutex_unlock(&adev->gfx.gfx_off_mutex);
@@ -852,19 +852,3 @@ int amdgpu_gfx_get_num_kcq(struct amdgpu_device 
 *adev)
       }
       return amdgpu_num_kcq;

  }

drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c +0 -9
-
-/* amdgpu_gfx_state_change_set - Handle gfx power state change set
- * @adev: amdgpu_device pointer
- * @state: gfx power state(1 -sGpuChangeState_D0Entry and 2 
-sGpuChangeState_D3Entry)
- *
- */
-
-void amdgpu_gfx_state_change_set(struct amdgpu_device *adev, enum 

gfx_change_state state)

drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c +0 -8
-{
-    mutex_lock(&adev->pm.mutex);
-    if (adev->powerplay.pp_funcs &&
-        adev->powerplay.pp_funcs->gfx_state_change_set)
-        ((adev)->powerplay.pp_funcs->gfx_state_change_set(
-            (adev)->powerplay.pp_handle, state));
-    mutex_unlock(&adev->pm.mutex);
-}
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h +0 -0
index f851196c83a5..776c886fd94a 100644
@@ -47,12 +47,6 @@ enum amdgpu_gfx_pipe_priority {

      AMDGPU_GFX_PIPE_PRIO_HIGH = AMDGPU_RING_PRIO_2 };

drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h +0 -6
-/* Argument for PPSMC_MSG_GpuChangeState */
-enum gfx_change_state {
-    sGpuChangeState_D0Entry = 1,
-    sGpuChangeState_D3Entry,
-};
-

  #define AMDGPU_GFX_QUEUE_PRIORITY_MINIMUM  0
  #define AMDGPU_GFX_QUEUE_PRIORITY_MAXIMUM  15

drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h +0 -1
@@ -410,5 +404,4 @@ int amdgpu_gfx_cp_ecc_error_irq(struct 
 amdgpu_device *adev,
   uint32_t amdgpu_kiq_rreg(struct amdgpu_device *adev, uint32_t reg);
   void amdgpu_kiq_wreg(struct amdgpu_device *adev, uint32_t reg, uint32_t v);
   int amdgpu_gfx_get_num_kcq(struct amdgpu_device *adev);
-void amdgpu_gfx_state_change_set(struct amdgpu_device *adev, enum 

gfx_change_state state);
  #endif

drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c +0 -0
index 3c623e589b79..35c4aec04a7e 100644
@@ -901,7 +901,7 @@ static void amdgpu_ras_get_ecc_info(struct 

amdgpu_device *adev, struct ras_err_d
       * choosing right query method according to
       * whether smu support query error information
       */
-    ret = smu_get_ecc_info(&adev->smu, (void *)&(ras->umc_ecc)); +    ret = amdgpu_dpm_get_ecc_info(adev, (void *)&(ras->umc_ecc)); if (ret == -EOPNOTSUPP) {
          if (adev->umc.ras_funcs && adev->umc.ras_funcs->query_ras_error_count)

drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c +1 -2
@@ -2132,8 +2132,7 @@ int amdgpu_ras_recovery_init(struct 
 amdgpu_device *adev)
           if (ret)
               goto free;
-        if (adev->smu.ppt_funcs && 
 adev->smu.ppt_funcs->send_hbm_bad_pages_num)
-            adev->smu.ppt_funcs->send_hbm_bad_pages_num(&adev->smu, 
 con->eeprom_control.ras_num_recs);
+        amdgpu_dpm_send_hbm_bad_pages_num(adev, 
 con->eeprom_control.ras_num_recs);

      }
  #ifdef CONFIG_X86_MCE_AMD

drivers/gpu/drm/amd/amdgpu/amdgpu_umc.c +1 -1
index 6e4bea012ea4..5fed26c8db44 100644
@@ -97,7 +97,7 @@ int amdgpu_umc_process_ras_data_cb(struct 
 amdgpu_device *adev,
       int ret = 0;
       kgd2kfd_set_sram_ecc_flag(adev->kfd.dev);
-    ret = smu_get_ecc_info(&adev->smu, (void *)&(con->umc_ecc));
+    ret = amdgpu_dpm_get_ecc_info(adev, (void *)&(con->umc_ecc));
       if (ret == -EOPNOTSUPP) {

          if (adev->umc.ras_funcs && adev->umc.ras_funcs->query_ras_error_count)

drivers/gpu/drm/amd/amdgpu/amdgpu_umc.c +1 -2
@@ -160,8 +160,7 @@ int amdgpu_umc_process_ras_data_cb(struct 
 amdgpu_device *adev,
                           err_data->err_addr_cnt);
               amdgpu_ras_save_bad_pages(adev);
-            if (adev->smu.ppt_funcs && 
 adev->smu.ppt_funcs->send_hbm_bad_pages_num)
-                
 adev->smu.ppt_funcs->send_hbm_bad_pages_num(&adev->smu, con->eeprom_control.ras_num_recs);
+            amdgpu_dpm_send_hbm_bad_pages_num(adev, 
 con->eeprom_control.ras_num_recs);

          }
          amdgpu_ras_reset_gpu(adev);

drivers/gpu/drm/amd/amdkfd/kfd_smi_events.c +1 -1
index deae12dc777d..329a4c89f1e6 100644
@@ -222,7 +222,7 @@ void 
 kfd_smi_event_update_thermal_throttling(struct kfd_dev *dev,
       len = snprintf(fifo_in, sizeof(fifo_in), "%x %llx:%llx\n",
                  KFD_SMI_EVENT_THERMAL_THROTTLE, throttle_bitmask,
-               atomic64_read(&dev->adev->smu.throttle_int_counter));
+               amdgpu_dpm_get_thermal_throttling_counter(dev->adev));
       add_event_to_kfifo(dev, KFD_SMI_EVENT_THERMAL_THROTTLE,    fifo_in, len);
   }
drivers/gpu/drm/amd/include/kgd_pp_interface.h +4 -0
index 5c0867ebcfce..2e295facd086 100644
@@ -26,6 +26,10 @@
   extern const struct amdgpu_ip_block_version pp_smu_ip_block;
+enum smu_event_type {
+    SMU_EVENT_RESET_COMPLETE = 0,
+};
+
   struct amd_vce_state {
       /* vce clocks */
       u32 evclk;
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +0 -0
index 08362d506534..9b332c8a0079 100644
@@ -1614,3 +1614,98 @@ int amdgpu_pm_load_smu_firmware(struct 

amdgpu_device *adev, uint32_t *smu_versio
      return 0;
  }

drivers/gpu/drm/amd/pm/amdgpu_dpm.c +7 -0
+
+int amdgpu_dpm_set_light_sbr(struct amdgpu_device *adev, bool enable)
+{
+    return smu_set_light_sbr(&adev->smu, enable);
+}
+
+int amdgpu_dpm_send_hbm_bad_pages_num(struct amdgpu_device *adev, 

uint32_t size)

drivers/gpu/drm/amd/pm/amdgpu_dpm.c +4 -0
+{
+    int ret = 0;
+
+    if (adev->smu.ppt_funcs && 

adev->smu.ppt_funcs->send_hbm_bad_pages_num)
+        ret = adev->smu.ppt_funcs->send_hbm_bad_pages_num(&adev->smu, size);

drivers/gpu/drm/amd/pm/amdgpu_dpm.c +47 -0
+
+    return ret;
+}
+
+int amdgpu_dpm_get_dpm_freq_range(struct amdgpu_device *adev,
+                  enum pp_clock_type type,
+                  uint32_t *min,
+                  uint32_t *max)
+{
+    if (!is_support_sw_smu(adev))
+        return -EOPNOTSUPP;
+
+    switch (type) {
+    case PP_SCLK:
+        return smu_get_dpm_freq_range(&adev->smu, SMU_SCLK, min, max);
+    default:
+        return -EINVAL;
+    }
+}
+
+int amdgpu_dpm_set_soft_freq_range(struct amdgpu_device *adev,
+                   enum pp_clock_type type,
+                   uint32_t min,
+                   uint32_t max)
+{
+    if (!is_support_sw_smu(adev))
+        return -EOPNOTSUPP;
+
+    switch (type) {
+    case PP_SCLK:
+        return smu_set_soft_freq_range(&adev->smu, SMU_SCLK, min, max);
+    default:
+        return -EINVAL;
+    }
+}
+
+int amdgpu_dpm_wait_for_event(struct amdgpu_device *adev,
+                  enum smu_event_type event,
+                  uint64_t event_arg)
+{
+    if (!is_support_sw_smu(adev))
+        return -EOPNOTSUPP;
+
+    return smu_wait_for_event(&adev->smu, event, event_arg);
+}
+
+int amdgpu_dpm_get_status_gfxoff(struct amdgpu_device *adev, uint32_t 

*value)

drivers/gpu/drm/amd/pm/amdgpu_dpm.c +8 -0
+{
+    if (!is_support_sw_smu(adev))
+        return -EOPNOTSUPP;
+
+    return smu_get_status_gfxoff(&adev->smu, value);
+}
+
+uint64_t amdgpu_dpm_get_thermal_throttling_counter(struct 

amdgpu_device *adev)

drivers/gpu/drm/amd/pm/amdgpu_dpm.c +16 -1
+{
+    return atomic64_read(&adev->smu.throttle_int_counter);
+}
+
+/* amdgpu_dpm_gfx_state_change - Handle gfx power state change set
+ * @adev: amdgpu_device pointer
+ * @state: gfx power state(1 -sGpuChangeState_D0Entry and 2 
-sGpuChangeState_D3Entry)
+ *
+ */
+void amdgpu_dpm_gfx_state_change(struct amdgpu_device *adev,
+                 enum gfx_change_state state)
+{
+    mutex_lock(&adev->pm.mutex);
+    if (adev->powerplay.pp_funcs &&
+        adev->powerplay.pp_funcs->gfx_state_change_set)
+        ((adev)->powerplay.pp_funcs->gfx_state_change_set(

drivers/gpu/drm/amd/pm/amdgpu_dpm.c int amdgpu_pm_load_smu_firmware(struct amdgpu_device *adev, uint32_t *smu_versio · line 1709

Quoted 10 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +10 -0
+            (adev)->powerplay.pp_handle, state));
+    mutex_unlock(&adev->pm.mutex);
+}
+
+int amdgpu_dpm_get_ecc_info(struct amdgpu_device *adev,
+                void *umc_ecc)
+{
+    if (!is_support_sw_smu(adev))
+        return -EOPNOTSUPP;
+

In general, I don't think we need to keep this check everywhere to make amdgpu_dpm_* backwards compatible.  The usage is also inconsistent. For ex: amdgpu_dpm_get_thermal_throttling_counter doesn't have any is_support_sw_smu check whereas amdgpu_dpm_get_ecc_info() has it. There is no reason to keep adding is_support_sw_smu() check for every new public API. For sure, they are not going to work with powerplay subsystem.

Quoted 4 lines

I would rather prefer to leave old things and create amdgpu_smu_* for anything which is supported only in smu subsystem. It's easier to read from code perspective also - separate the ones which is supported by smu component and not supported in older powerplay components.

Only for the common ones that are supported in powerplay and smu, keep amdgpu_dpm_*, for others preference would be to keep amdgpu_smu_*.

To add to the previous point - many of the new services offered by swsmu (ex: reset, i2c transfer, hbm ecc info etc.) are not even related to device power management, so it doesn't make sense to wrap it as dpm_ services.

Thanks,
Lijo

Quoted 116 lines

Thanks,
Lijo

Quoted 113 lines

+    return smu_get_ecc_info(&adev->smu, umc_ecc);

drivers/gpu/drm/amd/pm/amdgpu_dpm.c +1 -0
+}
drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h +8 -1
index 16e3f72d31b9..7289d379a9fb 100644
@@ -23,6 +23,12 @@
   #ifndef __AMDGPU_DPM_H__
   #define __AMDGPU_DPM_H__
+/* Argument for PPSMC_MSG_GpuChangeState */
+enum gfx_change_state {
+    sGpuChangeState_D0Entry = 1,
+    sGpuChangeState_D3Entry,
+};
+
   enum amdgpu_int_thermal_type {
       THERMAL_TYPE_NONE,
       THERMAL_TYPE_EXTERNAL,
@@ -574,5 +580,22 @@ void amdgpu_dpm_enable_vce(struct amdgpu_device 
 *adev, bool enable);
   void amdgpu_dpm_enable_jpeg(struct amdgpu_device *adev, bool enable);
   void amdgpu_pm_print_power_states(struct amdgpu_device *adev);
   int amdgpu_pm_load_smu_firmware(struct amdgpu_device *adev, uint32_t *smu_version);
-
+int amdgpu_dpm_set_light_sbr(struct amdgpu_device *adev, bool enable);
+int amdgpu_dpm_send_hbm_bad_pages_num(struct amdgpu_device *adev, 

uint32_t size);

drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h +9 -0
+int amdgpu_dpm_get_dpm_freq_range(struct amdgpu_device *adev,
+                       enum pp_clock_type type,
+                       uint32_t *min,
+                       uint32_t *max);
+int amdgpu_dpm_set_soft_freq_range(struct amdgpu_device *adev,
+                        enum pp_clock_type type,
+                        uint32_t min,
+                        uint32_t max);
+int amdgpu_dpm_wait_for_event(struct amdgpu_device *adev, enum 

smu_event_type event,
+               uint64_t event_arg);
+int amdgpu_dpm_get_status_gfxoff(struct amdgpu_device *adev, uint32_t *value);
+uint64_t amdgpu_dpm_get_thermal_throttling_counter(struct amdgpu_device *adev);

drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h +4 -0
+void amdgpu_dpm_gfx_state_change(struct amdgpu_device *adev,
+                 enum gfx_change_state state);
+int amdgpu_dpm_get_ecc_info(struct amdgpu_device *adev,
+                void *umc_ecc);

  #endif

drivers/gpu/drm/amd/pm/inc/amdgpu_smu.h +2 -7
index f738f7dc20c9..29791bb21fba 100644
@@ -241,11 +241,6 @@ struct smu_user_dpm_profile {
       uint32_t clk_dependency;
   };
-enum smu_event_type {
-
-    SMU_EVENT_RESET_COMPLETE = 0,
-};
-
   #define SMU_TABLE_INIT(tables, table_id, s, a, d)    \
       do {                        \
           tables[table_id].size = s;        \
@@ -1412,11 +1407,11 @@ int smu_set_ac_dc(struct smu_context *smu);
   int smu_allow_xgmi_power_down(struct smu_context *smu, bool en);
-int smu_get_status_gfxoff(struct amdgpu_device *adev, uint32_t *value);
+int smu_get_status_gfxoff(struct smu_context *smu, uint32_t *value);
   int smu_set_light_sbr(struct smu_context *smu, bool enable);
-int smu_wait_for_event(struct amdgpu_device *adev, enum 
 smu_event_type event,
+int smu_wait_for_event(struct smu_context *smu, enum smu_event_type 
 event,
                  uint64_t event_arg);
   int smu_get_ecc_info(struct smu_context *smu, void *umc_ecc);
   int smu_stb_collect_info(struct smu_context *smu, void *buff, uint32_t size);
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +6 -10
index 5839918cb574..ef7d0e377965 100644
@@ -100,17 +100,14 @@ static int smu_sys_set_pp_feature_mask(void 
 *handle,
       return ret;
   }
-int smu_get_status_gfxoff(struct amdgpu_device *adev, uint32_t *value)
+int smu_get_status_gfxoff(struct smu_context *smu, uint32_t *value)
   {
-    int ret = 0;
-    struct smu_context *smu = &adev->smu;
+    if (!smu->ppt_funcs->get_gfx_off_status)
+        return -EINVAL;
-    if (is_support_sw_smu(adev) && smu->ppt_funcs->get_gfx_off_status)
-        *value = smu_get_gfx_off_status(smu);
-    else
-        ret = -EINVAL;
+    *value = smu_get_gfx_off_status(smu);
-    return ret;
+    return 0;
   }
   int smu_set_soft_freq_range(struct smu_context *smu,
@@ -3167,11 +3164,10 @@ static const struct amd_pm_funcs 
 swsmu_pm_funcs = {
       .get_smu_prv_buf_details = smu_get_prv_buffer_details,
   };
-int smu_wait_for_event(struct amdgpu_device *adev, enum 
 smu_event_type event,
+int smu_wait_for_event(struct smu_context *smu, enum smu_event_type 
 event,
                  uint64_t event_arg)
   {
       int ret = -EINVAL;
-    struct smu_context *smu = &adev->smu;
       if (smu->ppt_funcs->wait_for_event) {

          mutex_lock(&smu->mutex);

author
#7 lore raw

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

In reply to Evan Quan

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

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

922 lines not on this page · raw message

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

183 lines not on this page · raw message

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

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

[Public]

Two nit-picks.

1. It's better to drop "return" in amdgpu_dpm_get_current_power_state.

2. In some functions, when function pointer is NULL, sometimes it returns 0, while in other cases, it returns -EOPNOTSUPP. Is there any cause for this?

Regards,
Guchun

-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Evan Quan
Sent: Tuesday, November 30, 2021 3:43 PM
To: [email protected]
Cc: Deucher, Alexander <[email protected]>; Lazar, Lijo <[email protected]>; Feng, Kenneth <[email protected]>; Koenig, Christian <[email protected]>; Quan, Evan <[email protected]>
Subject: [PATCH V2 02/17] drm/amd/pm: do not expose power implementation details to amdgpu_pm.c

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

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

922 lines not on this page · raw message

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

183 lines not on this page · raw message

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

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

[Public]

Quoted 10 lines

-----Original Message-----
From: Chen, Guchun <[email protected]>
Sent: Tuesday, November 30, 2021 9:05 PM
To: Quan, Evan <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>; Lazar, Lijo <[email protected]>; Feng, Kenneth <[email protected]>; Koenig, Christian <[email protected]>; Quan, Evan <[email protected]>
Subject: RE: [PATCH V2 02/17] drm/amd/pm: do not expose power implementation details to amdgpu_pm.c

Quoted 5 lines

[Public]

Two nit-picks.

1. It's better to drop "return" in amdgpu_dpm_get_current_power_state.

[Quan, Evan] I can do that.

Quoted 3 lines

2. In some functions, when function pointer is NULL, sometimes it returns 0, while in other cases, it returns -EOPNOTSUPP. Is there any cause for this?

[Quan, Evan] It is to stick with original logic. We might update them later(by new patches). For this patch series, I would like to maintain minimum changes(avoid real logic change).

Thanks
Evan

Quoted 1,880 lines

Regards,
Guchun

-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Evan Quan
Sent: Tuesday, November 30, 2021 3:43 PM
To: [email protected]
Cc: Deucher, Alexander <[email protected]>; Lazar, Lijo <[email protected]>; Feng, Kenneth <[email protected]>; Koenig, Christian <[email protected]>; Quan, Evan <[email protected]>
Subject: [PATCH V2 02/17] drm/amd/pm: do not expose power implementation details to amdgpu_pm.c

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

Change-Id I397853ddb13eacfce841366de2a623535422df9a
---
 drivers/gpu/drm/amd/pm/amdgpu_dpm.c       | 458 ++++++++++++++++++-
 drivers/gpu/drm/amd/pm/amdgpu_pm.c        | 519 ++++++++--------------
 drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h   | 160 +++----
 drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c |   3 -
 4 files changed, 709 insertions(+), 431 deletions(-)
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +3 -1
index 9b332c8a0079..3c59f16c7a6f 100644
@@ -1453,7 +1453,9 @@ static void
 amdgpu_dpm_change_power_state_locked(struct amdgpu_device *adev)
 	if (equal)
 		return;
 
-	amdgpu_dpm_set_power_state(adev);
+	if (adev->powerplay.pp_funcs->set_power_state)
+		adev->powerplay.pp_funcs->set_power_state(adev-
 >powerplay.pp_handle);
+
 	amdgpu_dpm_post_set_power_state(adev);

adev->pm.dpm.current_active_crtcs = adev-

Quoted 1 line

pm.dpm.new_active_crtcs;

drivers/gpu/drm/amd/pm/amdgpu_dpm.c +2 -0
@@ -1709,3 +1711,457 @@ int amdgpu_dpm_get_ecc_info(struct
 amdgpu_device *adev,
 
 	return smu_get_ecc_info(&adev->smu, umc_ecc);
 }
+
+struct amd_vce_state *amdgpu_dpm_get_vce_clock_state(struct

amdgpu_device *adev,

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

*adev,

drivers/gpu/drm/amd/pm/amdgpu_dpm.c +10 -0
+					enum amd_pm_state_type *state)
+{
+	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+
+	if (!pp_funcs->get_current_power_state) {
+		*state = adev->pm.dpm.user_state;
+		return;
+	}
+
+	*state = pp_funcs->get_current_power_state(adev-
Quoted 1 line

powerplay.pp_handle);

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

AMD_PP_TASK_ENABLE_USER_STATE, &state);

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

amdgpu_dpm_get_performance_level(struct amdgpu_device *adev)

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

powerplay.pp_handle);

drivers/gpu/drm/amd/pm/amdgpu_dpm.c +16 -0
+	else
+		level = adev->pm.dpm.forced_level;
+
+	return level;
+}
+
+int amdgpu_dpm_force_performance_level(struct amdgpu_device *adev,
+				       enum amd_dpm_forced_level level)
+{
+	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+
+	if (pp_funcs->force_performance_level) {
+		if (adev->pm.dpm.thermal_active)
+			return -EINVAL;
+
+		if (pp_funcs->force_performance_level(adev-
Quoted 1 line

powerplay.pp_handle,

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

states);

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

task_id, user_state);

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

powerplay.pp_handle,

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

powerplay.pp_handle,

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

powerplay.pp_handle,

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

char *buf)

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

powerplay.pp_handle,

drivers/gpu/drm/amd/pm/amdgpu_dpm.c +57 -0
+					      buf);
+}
+
+int amdgpu_dpm_force_clock_level(struct amdgpu_device *adev,
+				 enum pp_clock_type type,
+				 uint32_t mask)
+{
+	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+
+	if (!pp_funcs->force_clock_level)
+		return 0;
+
+	return pp_funcs->force_clock_level(adev->powerplay.pp_handle,
+					   type,
+					   mask);
+}
+
+int amdgpu_dpm_get_sclk_od(struct amdgpu_device *adev)
+{
+	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+
+	if (!pp_funcs->get_sclk_od)
+		return 0;
+
+	return pp_funcs->get_sclk_od(adev->powerplay.pp_handle);
+}
+
+int amdgpu_dpm_set_sclk_od(struct amdgpu_device *adev, uint32_t value)
+{
+	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+
+	if (!pp_funcs->set_sclk_od)
+		return -EOPNOTSUPP;
+
+	pp_funcs->set_sclk_od(adev->powerplay.pp_handle, value);
+
+	if (amdgpu_dpm_dispatch_task(adev,
+				     AMD_PP_TASK_READJUST_POWER_STATE,
+				     NULL) == -EOPNOTSUPP) {
+		adev->pm.dpm.current_ps = adev->pm.dpm.boot_ps;
+		amdgpu_pm_compute_clocks(adev);
+	}
+
+	return 0;
+}
+
+int amdgpu_dpm_get_mclk_od(struct amdgpu_device *adev)
+{
+	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+
+	if (!pp_funcs->get_mclk_od)
+		return 0;
+
+	return pp_funcs->get_mclk_od(adev->powerplay.pp_handle);
+}
+
+int amdgpu_dpm_set_mclk_od(struct amdgpu_device *adev, uint32_t

value)

drivers/gpu/drm/amd/pm/amdgpu_dpm.c +27 -0
+{
+	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+
+	if (!pp_funcs->set_mclk_od)
+		return -EOPNOTSUPP;
+
+	pp_funcs->set_mclk_od(adev->powerplay.pp_handle, value);
+
+	if (amdgpu_dpm_dispatch_task(adev,
+				     AMD_PP_TASK_READJUST_POWER_STATE,
+				     NULL) == -EOPNOTSUPP) {
+		adev->pm.dpm.current_ps = adev->pm.dpm.boot_ps;
+		amdgpu_pm_compute_clocks(adev);
+	}
+
+	return 0;
+}
+
+int amdgpu_dpm_get_power_profile_mode(struct amdgpu_device *adev,
+				      char *buf)
+{
+	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+
+	if (!pp_funcs->get_power_profile_mode)
+		return -EOPNOTSUPP;
+
+	return pp_funcs->get_power_profile_mode(adev-
Quoted 1 line

powerplay.pp_handle,

drivers/gpu/drm/amd/pm/amdgpu_dpm.c +12 -0
+						buf);
+}
+
+int amdgpu_dpm_set_power_profile_mode(struct amdgpu_device *adev,
+				      long *input, uint32_t size)
+{
+	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+
+	if (!pp_funcs->set_power_profile_mode)
+		return 0;
+
+	return pp_funcs->set_power_profile_mode(adev-
Quoted 1 line

powerplay.pp_handle,

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

**table)

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

table);

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

powerplay.pp_handle);

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

powerplay.pp_handle, speed);

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

powerplay.pp_handle, speed);

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

speed);

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

speed);

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

mode);

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

limit);

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

amdgpu_device *adev,

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

powerplay.pp_handle,

drivers/gpu/drm/amd/pm/amdgpu_dpm.c +15 -0
+							  m);
+
+	return 0;
+}
+
+int amdgpu_dpm_get_smu_prv_buf_details(struct amdgpu_device *adev,
+				       void **addr,
+				       size_t *size)
+{
+	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+
+	if (!pp_funcs->get_smu_prv_buf_details)
+		return -ENOSYS;
+
+	return pp_funcs->get_smu_prv_buf_details(adev-
Quoted 1 line

powerplay.pp_handle,

drivers/gpu/drm/amd/pm/amdgpu_dpm.c +42 -0
+						 addr,
+						 size);
+}
+
+int amdgpu_dpm_is_overdrive_supported(struct amdgpu_device *adev)
+{
+	struct pp_hwmgr *hwmgr = adev->powerplay.pp_handle;
+
+	if ((is_support_sw_smu(adev) && adev->smu.od_enabled) ||
+	    (is_support_sw_smu(adev) && adev->smu.is_apu) ||
+		(!is_support_sw_smu(adev) && hwmgr->od_enabled))
+		return true;
+
+	return false;
+}
+
+int amdgpu_dpm_set_pp_table(struct amdgpu_device *adev,
+			    const char *buf,
+			    size_t size)
+{
+	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+
+	if (!pp_funcs->set_pp_table)
+		return -EOPNOTSUPP;
+
+	return pp_funcs->set_pp_table(adev->powerplay.pp_handle,
+				      buf,
+				      size);
+}
+
+int amdgpu_dpm_get_num_cpu_cores(struct amdgpu_device *adev)
+{
+	return adev->smu.cpu_core_num;
+}
+
+void amdgpu_dpm_stb_debug_fs_init(struct amdgpu_device *adev)
+{
+	if (!is_support_sw_smu(adev))
+		return;
+
+	amdgpu_smu_stb_debug_fs_init(adev);
+}
drivers/gpu/drm/amd/pm/amdgpu_pm.c +0 -1
index 082539c70fd4..3382d30b5d90 100644
@@ -34,7 +34,6 @@
 #include <linux/nospec.h>
 #include <linux/pm_runtime.h>
 #include <asm/processor.h>
-#include "hwmgr.h"
 
 static const struct cg_flag_name clocks[] = {
 	{AMD_CG_SUPPORT_GFX_FGCG, "Graphics Fine Grain Clock

Gating"},

drivers/gpu/drm/amd/pm/amdgpu_pm.c +1 -6
@@ -132,7 +131,6 @@ static ssize_t amdgpu_get_power_dpm_state(struct
 device *dev,
 {
 	struct drm_device *ddev = dev_get_drvdata(dev);
 	struct amdgpu_device *adev = drm_to_adev(ddev);
-	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
 	enum amd_pm_state_type pm;
 	int ret;
@@ -147,11 +145,7 @@ static ssize_t amdgpu_get_power_dpm_state(struct
 device *dev,
 		return ret;
 	}
 
-	if (pp_funcs->get_current_power_state) {
-		pm = amdgpu_dpm_get_current_power_state(adev);
-	} else {
-		pm = adev->pm.dpm.user_state;
-	}
+	amdgpu_dpm_get_current_power_state(adev, &pm);
 
 	pm_runtime_mark_last_busy(ddev->dev);
drivers/gpu/drm/amd/pm/amdgpu_pm.c +1 -12
 	pm_runtime_put_autosuspend(ddev->dev);
@@ -191,19 +185,8 @@ static ssize_t amdgpu_set_power_dpm_state(struct
 device *dev,
 		return ret;
 	}
 
-	if (is_support_sw_smu(adev)) {
-		mutex_lock(&adev->pm.mutex);
-		adev->pm.dpm.user_state = state;
-		mutex_unlock(&adev->pm.mutex);
-	} else if (adev->powerplay.pp_funcs->dispatch_tasks) {
-		amdgpu_dpm_dispatch_task(adev,
 AMD_PP_TASK_ENABLE_USER_STATE, &state);
-	} else {
-		mutex_lock(&adev->pm.mutex);
-		adev->pm.dpm.user_state = state;
-		mutex_unlock(&adev->pm.mutex);
+	amdgpu_dpm_set_power_state(adev, state);
 
-		amdgpu_pm_compute_clocks(adev);
-	}
 	pm_runtime_mark_last_busy(ddev->dev);
drivers/gpu/drm/amd/pm/amdgpu_pm.c +1 -4
 	pm_runtime_put_autosuspend(ddev->dev);
@@ -290,10 +273,7 @@ static ssize_t
 amdgpu_get_power_dpm_force_performance_level(struct device *dev,
 		return ret;
 	}
 
-	if (adev->powerplay.pp_funcs->get_performance_level)
-		level = amdgpu_dpm_get_performance_level(adev);
-	else
-		level = adev->pm.dpm.forced_level;
+	level = amdgpu_dpm_get_performance_level(adev);
 
 	pm_runtime_mark_last_busy(ddev->dev);
drivers/gpu/drm/amd/pm/amdgpu_pm.c +0 -1
 	pm_runtime_put_autosuspend(ddev->dev);
@@ -318,7 +298,6 @@ static ssize_t
 amdgpu_set_power_dpm_force_performance_level(struct device *dev,
 {
 	struct drm_device *ddev = dev_get_drvdata(dev);
 	struct amdgpu_device *adev = drm_to_adev(ddev);
-	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
 	enum amd_dpm_forced_level level;
 	enum amd_dpm_forced_level current_level;
drivers/gpu/drm/amd/pm/amdgpu_pm.c +1 -5
 	int ret = 0;
@@ -358,11 +337,7 @@ static ssize_t
 amdgpu_set_power_dpm_force_performance_level(struct device *dev,
 		return ret;
 	}
 
-	if (pp_funcs->get_performance_level)
-		current_level =
 amdgpu_dpm_get_performance_level(adev);
-	else
-		current_level = adev->pm.dpm.forced_level;
-
+	current_level = amdgpu_dpm_get_performance_level(adev);
 	if (current_level == level) {
drivers/gpu/drm/amd/pm/amdgpu_pm.c +5 -19
 		pm_runtime_mark_last_busy(ddev->dev);
 		pm_runtime_put_autosuspend(ddev->dev);
@@ -390,25 +365,12 @@ static ssize_t
 amdgpu_set_power_dpm_force_performance_level(struct device *dev,
 		return -EINVAL;
 	}
 
-	if (pp_funcs->force_performance_level) {
-		mutex_lock(&adev->pm.mutex);
-		if (adev->pm.dpm.thermal_active) {
-			mutex_unlock(&adev->pm.mutex);
-			pm_runtime_mark_last_busy(ddev->dev);
-			pm_runtime_put_autosuspend(ddev->dev);
-			return -EINVAL;
-		}
-		ret = amdgpu_dpm_force_performance_level(adev, level);
-		if (ret) {
-			mutex_unlock(&adev->pm.mutex);
-			pm_runtime_mark_last_busy(ddev->dev);
-			pm_runtime_put_autosuspend(ddev->dev);
-			return -EINVAL;
-		} else {
-			adev->pm.dpm.forced_level = level;
-		}
-		mutex_unlock(&adev->pm.mutex);
+	if (amdgpu_dpm_force_performance_level(adev, level)) {
+		pm_runtime_mark_last_busy(ddev->dev);
+		pm_runtime_put_autosuspend(ddev->dev);
+		return -EINVAL;
 	}
+
 	pm_runtime_mark_last_busy(ddev->dev);
 	pm_runtime_put_autosuspend(ddev->dev);
@@ -421,7 +383,6 @@ static ssize_t amdgpu_get_pp_num_states(struct
 device *dev,
 {
 	struct drm_device *ddev = dev_get_drvdata(dev);
 	struct amdgpu_device *adev = drm_to_adev(ddev);
-	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
 	struct pp_states_info data;
 	uint32_t i;
drivers/gpu/drm/amd/pm/amdgpu_pm.c +1 -4
 	int buf_len, ret;
@@ -437,11 +398,8 @@ static ssize_t amdgpu_get_pp_num_states(struct
 device *dev,
 		return ret;
 	}
 
-	if (pp_funcs->get_pp_num_states) {
-		amdgpu_dpm_get_pp_num_states(adev, &data);
-	} else {
+	if (amdgpu_dpm_get_pp_num_states(adev, &data))
 		memset(&data, 0, sizeof(data));
-	}
 
 	pm_runtime_mark_last_busy(ddev->dev);
drivers/gpu/drm/amd/pm/amdgpu_pm.c +0 -1
 	pm_runtime_put_autosuspend(ddev->dev);
@@ -463,7 +421,6 @@ static ssize_t amdgpu_get_pp_cur_state(struct
 device *dev,
 {
 	struct drm_device *ddev = dev_get_drvdata(dev);
 	struct amdgpu_device *adev = drm_to_adev(ddev);
-	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
 	struct pp_states_info data = {0};
 	enum amd_pm_state_type pm = 0;
drivers/gpu/drm/amd/pm/amdgpu_pm.c +6 -5
 	int i = 0, ret = 0;
@@ -479,15 +436,16 @@ static ssize_t amdgpu_get_pp_cur_state(struct
 device *dev,
 		return ret;
 	}
 
-	if (pp_funcs->get_current_power_state
-		 && pp_funcs->get_pp_num_states) {
-		pm = amdgpu_dpm_get_current_power_state(adev);
-		amdgpu_dpm_get_pp_num_states(adev, &data);
-	}
+	amdgpu_dpm_get_current_power_state(adev, &pm);
+
+	ret = amdgpu_dpm_get_pp_num_states(adev, &data);
 
 	pm_runtime_mark_last_busy(ddev->dev);
 	pm_runtime_put_autosuspend(ddev->dev);
 
+	if (ret)
+		return ret;
+
 	for (i = 0; i < data.nums; i++) {
 		if (pm == data.states[i])
drivers/gpu/drm/amd/pm/amdgpu_pm.c +36 -27
 			break;
@@ -525,6 +483,7 @@ static ssize_t amdgpu_set_pp_force_state(struct
 device *dev,
 	struct drm_device *ddev = dev_get_drvdata(dev);
 	struct amdgpu_device *adev = drm_to_adev(ddev);
 	enum amd_pm_state_type state = 0;
+	struct pp_states_info data;
 	unsigned long idx;
 	int ret;
@@ -533,41 +492,49 @@ static ssize_t amdgpu_set_pp_force_state(struct
 device *dev,
 	if (adev->in_suspend && !adev->in_runpm)
 		return -EPERM;
 
-	if (strlen(buf) == 1)
-		adev->pp_force_state_enabled = false;
-	else if (is_support_sw_smu(adev))
-		adev->pp_force_state_enabled = false;
-	else if (adev->powerplay.pp_funcs->dispatch_tasks &&
-			adev->powerplay.pp_funcs->get_pp_num_states) {
-		struct pp_states_info data;
-
-		ret = kstrtoul(buf, 0, &idx);
-		if (ret || idx >= ARRAY_SIZE(data.states))
-			return -EINVAL;
+	adev->pp_force_state_enabled = false;
 
-		idx = array_index_nospec(idx, ARRAY_SIZE(data.states));
+	if (strlen(buf) == 1)
+		return count;
 
-		amdgpu_dpm_get_pp_num_states(adev, &data);
-		state = data.states[idx];
+	ret = kstrtoul(buf, 0, &idx);
+	if (ret || idx >= ARRAY_SIZE(data.states))
+		return -EINVAL;
 
-		ret = pm_runtime_get_sync(ddev->dev);
-		if (ret < 0) {
-			pm_runtime_put_autosuspend(ddev->dev);
-			return ret;
-		}
+	idx = array_index_nospec(idx, ARRAY_SIZE(data.states));
 
-		/* only set user selected power states */
-		if (state != POWER_STATE_TYPE_INTERNAL_BOOT &&
-		    state != POWER_STATE_TYPE_DEFAULT) {
-			amdgpu_dpm_dispatch_task(adev,
-
 	AMD_PP_TASK_ENABLE_USER_STATE, &state);
-			adev->pp_force_state_enabled = true;
-		}
-		pm_runtime_mark_last_busy(ddev->dev);
+	ret = pm_runtime_get_sync(ddev->dev);
+	if (ret < 0) {
 		pm_runtime_put_autosuspend(ddev->dev);
+		return ret;
+	}
+
+	ret = amdgpu_dpm_get_pp_num_states(adev, &data);
+	if (ret)
+		goto err_out;
+
+	state = data.states[idx];
+
+	/* only set user selected power states */
+	if (state != POWER_STATE_TYPE_INTERNAL_BOOT &&
+	    state != POWER_STATE_TYPE_DEFAULT) {
+		ret = amdgpu_dpm_dispatch_task(adev,
+				AMD_PP_TASK_ENABLE_USER_STATE,
 &state);
+		if (ret)
+			goto err_out;
+
+		adev->pp_force_state_enabled = true;
 	}
 
+	pm_runtime_mark_last_busy(ddev->dev);
+	pm_runtime_put_autosuspend(ddev->dev);
+
 	return count;
+
+err_out:
+	pm_runtime_mark_last_busy(ddev->dev);
+	pm_runtime_put_autosuspend(ddev->dev);
+	return ret;

}

/**

drivers/gpu/drm/amd/pm/amdgpu_pm.c +7 -11
@@ -601,17 +568,13 @@ static ssize_t amdgpu_get_pp_table(struct device
 *dev,
 		return ret;
 	}
 
-	if (adev->powerplay.pp_funcs->get_pp_table) {
-		size = amdgpu_dpm_get_pp_table(adev, &table);
-		pm_runtime_mark_last_busy(ddev->dev);
-		pm_runtime_put_autosuspend(ddev->dev);
-		if (size < 0)
-			return size;
-	} else {
-		pm_runtime_mark_last_busy(ddev->dev);
-		pm_runtime_put_autosuspend(ddev->dev);
-		return 0;
-	}
+	size = amdgpu_dpm_get_pp_table(adev, &table);
+
+	pm_runtime_mark_last_busy(ddev->dev);
+	pm_runtime_put_autosuspend(ddev->dev);
+
+	if (size <= 0)
+		return size;
 
 	if (size >= PAGE_SIZE)
drivers/gpu/drm/amd/pm/amdgpu_pm.c +22 -38
 		size = PAGE_SIZE - 1;
@@ -642,15 +605,13 @@ static ssize_t amdgpu_set_pp_table(struct device
 *dev,
 	}
 
 	ret = amdgpu_dpm_set_pp_table(adev, buf, count);
-	if (ret) {
-		pm_runtime_mark_last_busy(ddev->dev);
-		pm_runtime_put_autosuspend(ddev->dev);
-		return ret;
-	}
 
 	pm_runtime_mark_last_busy(ddev->dev);
 	pm_runtime_put_autosuspend(ddev->dev);
 
+	if (ret)
+		return ret;
+
 	return count;
 }
@@ -866,46 +827,32 @@ static ssize_t
 amdgpu_set_pp_od_clk_voltage(struct device *dev,
 		return ret;
 	}
 
-	if (adev->powerplay.pp_funcs->set_fine_grain_clk_vol) {
-		ret = amdgpu_dpm_set_fine_grain_clk_vol(adev, type,
-							parameter,
-							parameter_size);
-		if (ret) {
-			pm_runtime_mark_last_busy(ddev->dev);
-			pm_runtime_put_autosuspend(ddev->dev);
-			return -EINVAL;
-		}
-	}
+	if (amdgpu_dpm_set_fine_grain_clk_vol(adev,
+					      type,
+					      parameter,
+					      parameter_size))
+		goto err_out;
 
-	if (adev->powerplay.pp_funcs->odn_edit_dpm_table) {
-		ret = amdgpu_dpm_odn_edit_dpm_table(adev, type,
-						    parameter,
 parameter_size);
-		if (ret) {
-			pm_runtime_mark_last_busy(ddev->dev);
-			pm_runtime_put_autosuspend(ddev->dev);
-			return -EINVAL;
-		}
-	}
+	if (amdgpu_dpm_odn_edit_dpm_table(adev, type,
+					  parameter, parameter_size))
+		goto err_out;
 
 	if (type == PP_OD_COMMIT_DPM_TABLE) {
-		if (adev->powerplay.pp_funcs->dispatch_tasks) {
-			amdgpu_dpm_dispatch_task(adev,
-
 AMD_PP_TASK_READJUST_POWER_STATE,
-						 NULL);
-			pm_runtime_mark_last_busy(ddev->dev);
-			pm_runtime_put_autosuspend(ddev->dev);
-			return count;
-		} else {
-			pm_runtime_mark_last_busy(ddev->dev);
-			pm_runtime_put_autosuspend(ddev->dev);
-			return -EINVAL;
-		}
+		if (amdgpu_dpm_dispatch_task(adev,
+
 AMD_PP_TASK_READJUST_POWER_STATE,
+					     NULL))
+			goto err_out;
 	}
 
 	pm_runtime_mark_last_busy(ddev->dev);
 	pm_runtime_put_autosuspend(ddev->dev);
 
 	return count;
+
+err_out:
+	pm_runtime_mark_last_busy(ddev->dev);
+	pm_runtime_put_autosuspend(ddev->dev);
+	return -EINVAL;
 }
 
 static ssize_t amdgpu_get_pp_od_clk_voltage(struct device *dev,
@@ -928,8 +875,8 @@ static ssize_t amdgpu_get_pp_od_clk_voltage(struct
 device *dev,
 		return ret;
 	}
 
-	if (adev->powerplay.pp_funcs->print_clock_levels) {
-		size = amdgpu_dpm_print_clock_levels(adev, OD_SCLK, buf);
+	size = amdgpu_dpm_print_clock_levels(adev, OD_SCLK, buf);
+	if (size > 0) {
 		size += amdgpu_dpm_print_clock_levels(adev, OD_MCLK,
 buf+size);

size += amdgpu_dpm_print_clock_levels(adev,
OD_VDDC_CURVE, buf+size);
size += amdgpu_dpm_print_clock_levels(adev,
OD_VDDGFX_OFFSET, buf+size);

drivers/gpu/drm/amd/pm/amdgpu_pm.c +5 -8
@@ -985,17 +932,14 @@ static ssize_t amdgpu_set_pp_features(struct
 device *dev,
 		return ret;
 	}
 
-	if (adev->powerplay.pp_funcs->set_ppfeature_status) {
-		ret = amdgpu_dpm_set_ppfeature_status(adev,
 featuremask);
-		if (ret) {
-			pm_runtime_mark_last_busy(ddev->dev);
-			pm_runtime_put_autosuspend(ddev->dev);
-			return -EINVAL;
-		}
-	}
+	ret = amdgpu_dpm_set_ppfeature_status(adev, featuremask);
+
 	pm_runtime_mark_last_busy(ddev->dev);
 	pm_runtime_put_autosuspend(ddev->dev);
 
+	if (ret)
+		return -EINVAL;
+
 	return count;

}

drivers/gpu/drm/amd/pm/amdgpu_pm.c +2 -3
@@ -1019,9 +963,8 @@ static ssize_t amdgpu_get_pp_features(struct
 device *dev,
 		return ret;
 	}
 
-	if (adev->powerplay.pp_funcs->get_ppfeature_status)
-		size = amdgpu_dpm_get_ppfeature_status(adev, buf);
-	else
+	size = amdgpu_dpm_get_ppfeature_status(adev, buf);
+	if (size <= 0)
 		size = sysfs_emit(buf, "\n");
 
drivers/gpu/drm/amd/pm/amdgpu_pm.c +2 -3
 	pm_runtime_mark_last_busy(ddev->dev);
@@ -1080,9 +1023,8 @@ static ssize_t amdgpu_get_pp_dpm_clock(struct
 device *dev,
 		return ret;
 	}
 
-	if (adev->powerplay.pp_funcs->print_clock_levels)
-		size = amdgpu_dpm_print_clock_levels(adev, type, buf);
-	else
+	size = amdgpu_dpm_print_clock_levels(adev, type, buf);
+	if (size <= 0)
 		size = sysfs_emit(buf, "\n");
 
drivers/gpu/drm/amd/pm/amdgpu_pm.c +1 -4
 	pm_runtime_mark_last_busy(ddev->dev);
@@ -1151,10 +1093,7 @@ static ssize_t amdgpu_set_pp_dpm_clock(struct
 device *dev,
 		return ret;
 	}
 
-	if (adev->powerplay.pp_funcs->force_clock_level)
-		ret = amdgpu_dpm_force_clock_level(adev, type, mask);
-	else
-		ret = 0;
+	ret = amdgpu_dpm_force_clock_level(adev, type, mask);
 
 	pm_runtime_mark_last_busy(ddev->dev);
drivers/gpu/drm/amd/pm/amdgpu_pm.c +1 -4
 	pm_runtime_put_autosuspend(ddev->dev);
@@ -1305,10 +1244,7 @@ static ssize_t amdgpu_get_pp_sclk_od(struct
 device *dev,
 		return ret;
 	}
 
-	if (is_support_sw_smu(adev))
-		value = 0;
-	else if (adev->powerplay.pp_funcs->get_sclk_od)
-		value = amdgpu_dpm_get_sclk_od(adev);
+	value = amdgpu_dpm_get_sclk_od(adev);
 
 	pm_runtime_mark_last_busy(ddev->dev);
drivers/gpu/drm/amd/pm/amdgpu_pm.c +1 -13
 	pm_runtime_put_autosuspend(ddev->dev);
@@ -1342,19 +1278,7 @@ static ssize_t amdgpu_set_pp_sclk_od(struct
 device *dev,
 		return ret;
 	}
 
-	if (is_support_sw_smu(adev)) {
-		value = 0;
-	} else {
-		if (adev->powerplay.pp_funcs->set_sclk_od)
-			amdgpu_dpm_set_sclk_od(adev, (uint32_t)value);
-
-		if (adev->powerplay.pp_funcs->dispatch_tasks) {
-			amdgpu_dpm_dispatch_task(adev,
 AMD_PP_TASK_READJUST_POWER_STATE, NULL);
-		} else {
-			adev->pm.dpm.current_ps = adev-
 >pm.dpm.boot_ps;
-			amdgpu_pm_compute_clocks(adev);
-		}
-	}
+	amdgpu_dpm_set_sclk_od(adev, (uint32_t)value);
drivers/gpu/drm/amd/pm/amdgpu_pm.c +1 -4
 	pm_runtime_mark_last_busy(ddev->dev);
 	pm_runtime_put_autosuspend(ddev->dev);
@@ -1382,10 +1306,7 @@ static ssize_t amdgpu_get_pp_mclk_od(struct
 device *dev,
 		return ret;
 	}
 
-	if (is_support_sw_smu(adev))
-		value = 0;
-	else if (adev->powerplay.pp_funcs->get_mclk_od)
-		value = amdgpu_dpm_get_mclk_od(adev);
+	value = amdgpu_dpm_get_mclk_od(adev);
 
 	pm_runtime_mark_last_busy(ddev->dev);
drivers/gpu/drm/amd/pm/amdgpu_pm.c +1 -13
 	pm_runtime_put_autosuspend(ddev->dev);
@@ -1419,19 +1340,7 @@ static ssize_t amdgpu_set_pp_mclk_od(struct
 device *dev,
 		return ret;
 	}
 
-	if (is_support_sw_smu(adev)) {
-		value = 0;
-	} else {
-		if (adev->powerplay.pp_funcs->set_mclk_od)
-			amdgpu_dpm_set_mclk_od(adev, (uint32_t)value);
-
-		if (adev->powerplay.pp_funcs->dispatch_tasks) {
-			amdgpu_dpm_dispatch_task(adev,
 AMD_PP_TASK_READJUST_POWER_STATE, NULL);
-		} else {
-			adev->pm.dpm.current_ps = adev-
 >pm.dpm.boot_ps;
-			amdgpu_pm_compute_clocks(adev);
-		}
-	}
+	amdgpu_dpm_set_mclk_od(adev, (uint32_t)value);
drivers/gpu/drm/amd/pm/amdgpu_pm.c +2 -3
 	pm_runtime_mark_last_busy(ddev->dev);
 	pm_runtime_put_autosuspend(ddev->dev);
@@ -1479,9 +1388,8 @@ static ssize_t
 amdgpu_get_pp_power_profile_mode(struct device *dev,
 		return ret;
 	}
 
-	if (adev->powerplay.pp_funcs->get_power_profile_mode)
-		size = amdgpu_dpm_get_power_profile_mode(adev, buf);
-	else
+	size = amdgpu_dpm_get_power_profile_mode(adev, buf);
+	if (size <= 0)
 		size = sysfs_emit(buf, "\n");
 
drivers/gpu/drm/amd/pm/amdgpu_pm.c +1 -2
 	pm_runtime_mark_last_busy(ddev->dev);
@@ -1545,8 +1453,7 @@ static ssize_t
 amdgpu_set_pp_power_profile_mode(struct device *dev,
 		return ret;
 	}
 
-	if (adev->powerplay.pp_funcs->set_power_profile_mode)
-		ret = amdgpu_dpm_set_power_profile_mode(adev,
 parameter, parameter_size);
+	ret = amdgpu_dpm_set_power_profile_mode(adev, parameter,
 parameter_size);
drivers/gpu/drm/amd/pm/amdgpu_pm.c +1 -3
 	pm_runtime_mark_last_busy(ddev->dev);
 	pm_runtime_put_autosuspend(ddev->dev);
@@ -1812,9 +1719,7 @@ static ssize_t amdgpu_get_gpu_metrics(struct
 device *dev,
 		return ret;
 	}
 
-	if (adev->powerplay.pp_funcs->get_gpu_metrics)
-		size = amdgpu_dpm_get_gpu_metrics(adev, &gpu_metrics);
-
+	size = amdgpu_dpm_get_gpu_metrics(adev, &gpu_metrics);
 	if (size <= 0)
 		goto out;
@@ -2053,7 +1958,6 @@ static int default_attr_update(struct

amdgpu_device *adev, struct amdgpu_device_
{

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

amdgpu_device *adev, struct amdgpu_device_

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

||

drivers/gpu/drm/amd/pm/amdgpu_pm.c +0 -2
-		    (is_support_sw_smu(adev) && adev->smu.is_apu) ||
-			(!is_support_sw_smu(adev) && hwmgr-
Quoted 1 line

od_enabled))

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

amdgpu_device *adev, struct amdgpu_device_
if (!(asic_type == CHIP_VANGOGH || asic_type ==
CHIP_SIENNA_CICHLID))

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

||

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

EOPNOTSUPP)

drivers/gpu/drm/amd/pm/amdgpu_pm.c +21 -30
+		if (amdgpu_dpm_get_power_profile_mode(adev, NULL) ==
-EOPNOTSUPP)
 			*states = ATTR_STATE_UNSUPPORTED;
 	}
@@ -2389,17 +2290,14 @@ static ssize_t
 amdgpu_hwmon_get_pwm1_enable(struct device *dev,
 		return ret;
 	}
 
-	if (!adev->powerplay.pp_funcs->get_fan_control_mode) {
-		pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
-		pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
-		return -EINVAL;
-	}
-
-	pwm_mode = amdgpu_dpm_get_fan_control_mode(adev);
+	ret = amdgpu_dpm_get_fan_control_mode(adev, &pwm_mode);
 
 	pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
 	pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
 
+	if (ret)
+		return -EINVAL;
+
 	return sysfs_emit(buf, "%u\n", pwm_mode);
 }
@@ -2427,17 +2325,14 @@ static ssize_t
 amdgpu_hwmon_set_pwm1_enable(struct device *dev,
 		return ret;
 	}
 
-	if (!adev->powerplay.pp_funcs->set_fan_control_mode) {
-		pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
-		pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
-		return -EINVAL;
-	}
-
-	amdgpu_dpm_set_fan_control_mode(adev, value);
+	ret = amdgpu_dpm_set_fan_control_mode(adev, value);
 
 	pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
 	pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
 
+	if (ret)
+		return -EINVAL;
+
 	return count;
 }
@@ -2469,32 +2364,29 @@ static ssize_t amdgpu_hwmon_set_pwm1(struct
 device *dev,
 	if (adev->in_suspend && !adev->in_runpm)
 		return -EPERM;
 
+	err = kstrtou32(buf, 10, &value);
+	if (err)
+		return err;
+
 	err = pm_runtime_get_sync(adev_to_drm(adev)->dev);
 	if (err < 0) {
 		pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
 		return err;
 	}
 
-	pwm_mode = amdgpu_dpm_get_fan_control_mode(adev);
+	err = amdgpu_dpm_get_fan_control_mode(adev, &pwm_mode);
+	if (err)
+		goto out;
+
 	if (pwm_mode != AMD_FAN_CTRL_MANUAL) {
 		pr_info("manual fan speed control should be enabled
 first\n");
-		pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
-		pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
-		return -EINVAL;
+		err = -EINVAL;
+		goto out;
 	}
 
-	err = kstrtou32(buf, 10, &value);
-	if (err) {
-		pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
-		pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
-		return err;
-	}
-
-	if (adev->powerplay.pp_funcs->set_fan_speed_pwm)
-		err = amdgpu_dpm_set_fan_speed_pwm(adev, value);
-	else
-		err = -EINVAL;
+	err = amdgpu_dpm_set_fan_speed_pwm(adev, value);
 
+out:
 	pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
drivers/gpu/drm/amd/pm/amdgpu_pm.c +1 -4
 	pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
@@ -2523,10 +2415,7 @@ static ssize_t amdgpu_hwmon_get_pwm1(struct
 device *dev,
 		return err;
 	}
 
-	if (adev->powerplay.pp_funcs->get_fan_speed_pwm)
-		err = amdgpu_dpm_get_fan_speed_pwm(adev, &speed);
-	else
-		err = -EINVAL;
+	err = amdgpu_dpm_get_fan_speed_pwm(adev, &speed);
 
 	pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
drivers/gpu/drm/amd/pm/amdgpu_pm.c +1 -4
 	pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
@@ -2556,10 +2445,7 @@ static ssize_t
 amdgpu_hwmon_get_fan1_input(struct device *dev,
 		return err;
 	}
 
-	if (adev->powerplay.pp_funcs->get_fan_speed_rpm)
-		err = amdgpu_dpm_get_fan_speed_rpm(adev, &speed);
-	else
-		err = -EINVAL;
+	err = amdgpu_dpm_get_fan_speed_rpm(adev, &speed);
 
 	pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
drivers/gpu/drm/amd/pm/amdgpu_pm.c +1 -4
 	pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
@@ -2653,10 +2539,7 @@ static ssize_t
 amdgpu_hwmon_get_fan1_target(struct device *dev,
 		return err;
 	}
 
-	if (adev->powerplay.pp_funcs->get_fan_speed_rpm)
-		err = amdgpu_dpm_get_fan_speed_rpm(adev, &rpm);
-	else
-		err = -EINVAL;
+	err = amdgpu_dpm_get_fan_speed_rpm(adev, &rpm);
 
 	pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
drivers/gpu/drm/amd/pm/amdgpu_pm.c +15 -22
 	pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
@@ -2681,32 +2564,28 @@ static ssize_t
 amdgpu_hwmon_set_fan1_target(struct device *dev,
 	if (adev->in_suspend && !adev->in_runpm)
 		return -EPERM;
 
+	err = kstrtou32(buf, 10, &value);
+	if (err)
+		return err;
+
 	err = pm_runtime_get_sync(adev_to_drm(adev)->dev);
 	if (err < 0) {
 		pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
 		return err;
 	}
 
-	pwm_mode = amdgpu_dpm_get_fan_control_mode(adev);
+	err = amdgpu_dpm_get_fan_control_mode(adev, &pwm_mode);
+	if (err)
+		goto out;
 
 	if (pwm_mode != AMD_FAN_CTRL_MANUAL) {
-		pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
-		pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
-		return -ENODATA;
-	}
-
-	err = kstrtou32(buf, 10, &value);
-	if (err) {
-		pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
-		pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
-		return err;
+		err = -ENODATA;
+		goto out;
 	}
 
-	if (adev->powerplay.pp_funcs->set_fan_speed_rpm)
-		err = amdgpu_dpm_set_fan_speed_rpm(adev, value);
-	else
-		err = -EINVAL;
+	err = amdgpu_dpm_set_fan_speed_rpm(adev, value);
 
+out:
 	pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
 	pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
@@ -2735,17 +2614,14 @@ static ssize_t
 amdgpu_hwmon_get_fan1_enable(struct device *dev,
 		return ret;
 	}
 
-	if (!adev->powerplay.pp_funcs->get_fan_control_mode) {
-		pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
-		pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
-		return -EINVAL;
-	}
-
-	pwm_mode = amdgpu_dpm_get_fan_control_mode(adev);
+	ret = amdgpu_dpm_get_fan_control_mode(adev, &pwm_mode);
 
 	pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
 	pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
 
+	if (ret)
+		return -EINVAL;
+
 	return sysfs_emit(buf, "%i\n", pwm_mode ==
 AMD_FAN_CTRL_AUTO ? 0 : 1);

}

drivers/gpu/drm/amd/pm/amdgpu_pm.c +4 -7
@@ -2781,16 +2657,14 @@ static ssize_t
 amdgpu_hwmon_set_fan1_enable(struct device *dev,
 		return err;
 	}
 
-	if (!adev->powerplay.pp_funcs->set_fan_control_mode) {
-		pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
-		pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
-		return -EINVAL;
-	}
-	amdgpu_dpm_set_fan_control_mode(adev, pwm_mode);
+	err = amdgpu_dpm_set_fan_control_mode(adev, pwm_mode);
 
 	pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
 	pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
 
+	if (err)
+		return -EINVAL;
+
 	return count;
 }
@@ -2926,7 +2800,6 @@ static ssize_t
 amdgpu_hwmon_show_power_cap_generic(struct device *dev,
 					enum pp_power_limit_level
 pp_limit_level)
 {
 	struct amdgpu_device *adev = dev_get_drvdata(dev);
-	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
 	enum pp_power_type power_type = to_sensor_dev_attr(attr)-
Quoted 1 line

index;

drivers/gpu/drm/amd/pm/amdgpu_pm.c +1 -4
 	uint32_t limit;
 	ssize_t size;
@@ -2937,16 +2810,13 @@ static ssize_t
 amdgpu_hwmon_show_power_cap_generic(struct device *dev,
 	if (adev->in_suspend && !adev->in_runpm)
 		return -EPERM;
 
-	if ( !(pp_funcs && pp_funcs->get_power_limit))
-		return -ENODATA;
-
 	r = pm_runtime_get_sync(adev_to_drm(adev)->dev);
 	if (r < 0) {
 		pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
 		return r;
 	}
 
-	r = pp_funcs->get_power_limit(adev->powerplay.pp_handle, &limit,
+	r = amdgpu_dpm_get_power_limit(adev, &limit,
 				      pp_limit_level, power_type);
 
drivers/gpu/drm/amd/pm/amdgpu_pm.c +0 -1
 	if (!r)
@@ -3001,7 +2871,6 @@ static ssize_t
 amdgpu_hwmon_set_power_cap(struct device *dev,
 		size_t count)
 {
 	struct amdgpu_device *adev = dev_get_drvdata(dev);
-	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
 	int limit_type = to_sensor_dev_attr(attr)->index;
 	int err;
drivers/gpu/drm/amd/pm/amdgpu_pm.c +1 -4
 	u32 value;
@@ -3027,10 +2896,7 @@ static ssize_t
 amdgpu_hwmon_set_power_cap(struct device *dev,
 		return err;
 	}
 
-	if (pp_funcs && pp_funcs->set_power_limit)
-		err = pp_funcs->set_power_limit(adev-
 >powerplay.pp_handle, value);
-	else
-		err = -EINVAL;
+	err = amdgpu_dpm_set_power_limit(adev, value);
 
drivers/gpu/drm/amd/pm/amdgpu_pm.c +1 -0
 	pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
 	pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
@@ -3303,6 +3169,7 @@ static umode_t hwmon_attributes_visible(struct
 kobject *kobj,
 	struct device *dev = kobj_to_dev(kobj);
 	struct amdgpu_device *adev = dev_get_drvdata(dev);
 	umode_t effective_mode = attr->mode;
+	uint32_t speed = 0;
 
 	/* under multi-vf mode, the hwmon attributes are all not supported

*/

drivers/gpu/drm/amd/pm/amdgpu_pm.c +0 -2
 	if (amdgpu_sriov_vf(adev) && !amdgpu_sriov_is_pp_one_vf(adev))
@@ -3367,20 +3234,18 @@ static umode_t hwmon_attributes_visible(struct
 kobject *kobj,
 	     attr == &sensor_dev_attr_fan1_enable.dev_attr.attr))
 		return 0;
 
-	if (!is_support_sw_smu(adev)) {
-		/* mask fan attributes if we have no bindings for this asic to

expose */

drivers/gpu/drm/amd/pm/amdgpu_pm.c +0 -2
-		if ((!adev->powerplay.pp_funcs->get_fan_speed_pwm &&
-		     attr == &sensor_dev_attr_pwm1.dev_attr.attr) || /* can't

query fan */

drivers/gpu/drm/amd/pm/amdgpu_pm.c +0 -2
-		    (!adev->powerplay.pp_funcs->get_fan_control_mode &&
-		     attr == &sensor_dev_attr_pwm1_enable.dev_attr.attr))

/* can't query state */

drivers/gpu/drm/amd/pm/amdgpu_pm.c +1 -1
-			effective_mode &= ~S_IRUGO;
+	/* mask fan attributes if we have no bindings for this asic to expose

*/

drivers/gpu/drm/amd/pm/amdgpu_pm.c +1 -0
+	if (((amdgpu_dpm_get_fan_speed_pwm(adev, &speed) == -EINVAL)

&&

drivers/gpu/drm/amd/pm/amdgpu_pm.c +1 -0
+	      attr == &sensor_dev_attr_pwm1.dev_attr.attr) || /* can't query

fan */

drivers/gpu/drm/amd/pm/amdgpu_pm.c +1 -0
+	    ((amdgpu_dpm_get_fan_control_mode(adev, &speed) == -

EOPNOTSUPP) &&

drivers/gpu/drm/amd/pm/amdgpu_pm.c +1 -0
+	     attr == &sensor_dev_attr_pwm1_enable.dev_attr.attr)) /* can't

query state */

drivers/gpu/drm/amd/pm/amdgpu_pm.c +1 -2
+		effective_mode &= ~S_IRUGO;
 
-		if ((!adev->powerplay.pp_funcs->set_fan_speed_pwm &&
-		     attr == &sensor_dev_attr_pwm1.dev_attr.attr) || /* can't

manage fan */

drivers/gpu/drm/amd/pm/amdgpu_pm.c +0 -2
-		    (!adev->powerplay.pp_funcs->set_fan_control_mode &&
-		     attr == &sensor_dev_attr_pwm1_enable.dev_attr.attr))

/* can't manage state */

drivers/gpu/drm/amd/pm/amdgpu_pm.c +1 -2
-			effective_mode &= ~S_IWUSR;
-	}
+	if (((amdgpu_dpm_set_fan_speed_pwm(adev, speed) == -EINVAL)

&&

drivers/gpu/drm/amd/pm/amdgpu_pm.c +1 -0
+	      attr == &sensor_dev_attr_pwm1.dev_attr.attr) || /* can't

manage fan */

drivers/gpu/drm/amd/pm/amdgpu_pm.c +1 -0
+	      ((amdgpu_dpm_set_fan_control_mode(adev, speed) == -

EOPNOTSUPP) &&

drivers/gpu/drm/amd/pm/amdgpu_pm.c +1 -0
+	      attr == &sensor_dev_attr_pwm1_enable.dev_attr.attr)) /* can't

manage state */

drivers/gpu/drm/amd/pm/amdgpu_pm.c +1 -2
+		effective_mode &= ~S_IWUSR;
 
 	if (((adev->family == AMDGPU_FAMILY_SI) ||
 		 ((adev->flags & AMD_IS_APU) &&
@@ -3397,22 +3262,20 @@ static umode_t hwmon_attributes_visible(struct
 kobject *kobj,
 	    (attr == &sensor_dev_attr_power1_average.dev_attr.attr))
 		return 0;
 
-	if (!is_support_sw_smu(adev)) {
-		/* hide max/min values if we can't both query and manage

the fan */

drivers/gpu/drm/amd/pm/amdgpu_pm.c +2 -7
-		if ((!adev->powerplay.pp_funcs->set_fan_speed_pwm &&
-		     !adev->powerplay.pp_funcs->get_fan_speed_pwm) &&
-		     (!adev->powerplay.pp_funcs->set_fan_speed_rpm &&
-		     !adev->powerplay.pp_funcs->get_fan_speed_rpm) &&
-		    (attr == &sensor_dev_attr_pwm1_max.dev_attr.attr ||
-		     attr == &sensor_dev_attr_pwm1_min.dev_attr.attr))
-			return 0;
+	/* hide max/min values if we can't both query and manage the fan */
+	if (((amdgpu_dpm_set_fan_speed_pwm(adev, speed) == -EINVAL)

&&

drivers/gpu/drm/amd/pm/amdgpu_pm.c +1 -0
+	      (amdgpu_dpm_get_fan_speed_pwm(adev, &speed) == -EINVAL)

&&

drivers/gpu/drm/amd/pm/amdgpu_pm.c +1 -0
+	      (amdgpu_dpm_set_fan_speed_rpm(adev, speed) == -EINVAL)

&&

drivers/gpu/drm/amd/pm/amdgpu_pm.c +1 -0
+	      (amdgpu_dpm_get_fan_speed_rpm(adev, &speed) == -EINVAL))

&&

drivers/gpu/drm/amd/pm/amdgpu_pm.c +4 -6
+	    (attr == &sensor_dev_attr_pwm1_max.dev_attr.attr ||
+	     attr == &sensor_dev_attr_pwm1_min.dev_attr.attr))
+		return 0;
 
-		if ((!adev->powerplay.pp_funcs->set_fan_speed_rpm &&
-		     !adev->powerplay.pp_funcs->get_fan_speed_rpm) &&
-		    (attr == &sensor_dev_attr_fan1_max.dev_attr.attr ||
-		     attr == &sensor_dev_attr_fan1_min.dev_attr.attr))
-			return 0;
-	}
+	if ((amdgpu_dpm_set_fan_speed_rpm(adev, speed) == -EINVAL)

&&

drivers/gpu/drm/amd/pm/amdgpu_pm.c +1 -0
+	     (amdgpu_dpm_get_fan_speed_rpm(adev, &speed) == -EINVAL)

&&

drivers/gpu/drm/amd/pm/amdgpu_pm.c +3 -0
+	     (attr == &sensor_dev_attr_fan1_max.dev_attr.attr ||
+	     attr == &sensor_dev_attr_fan1_min.dev_attr.attr))
+		return 0;
 
 	if ((adev->family == AMDGPU_FAMILY_SI ||	/* not implemented

yet */
adev->family == AMDGPU_FAMILY_KV) && /* not implemented
yet */

drivers/gpu/drm/amd/pm/amdgpu_pm.c +4 -3
@@ -3542,14 +3405,15 @@ static void
 amdgpu_debugfs_prints_cpu_info(struct seq_file *m,
 	uint16_t *p_val;
 	uint32_t size;
 	int i;
+	uint32_t num_cpu_cores =
 amdgpu_dpm_get_num_cpu_cores(adev);
 
-	if (is_support_cclk_dpm(adev)) {
-		p_val = kcalloc(adev->smu.cpu_core_num, sizeof(uint16_t),
+	if (amdgpu_dpm_is_cclk_dpm_supported(adev)) {
+		p_val = kcalloc(num_cpu_cores, sizeof(uint16_t),
 				GFP_KERNEL);
 
 		if (!amdgpu_dpm_read_sensor(adev,
 AMDGPU_PP_SENSOR_CPU_CLK,
 					    (void *)p_val, &size)) {
-			for (i = 0; i < adev->smu.cpu_core_num; i++)
+			for (i = 0; i < num_cpu_cores; i++)
drivers/gpu/drm/amd/pm/amdgpu_pm.c +7 -26
 				seq_printf(m, "\t%u MHz (CPU%d)\n",
 					   *(p_val + i), i);
 		}
@@ -3677,27 +3541,11 @@ static int
 amdgpu_debugfs_pm_info_show(struct seq_file *m, void *unused)
 		return r;
 	}
 
-	if (!adev->pm.dpm_enabled) {
-		seq_printf(m, "dpm not enabled\n");
-		pm_runtime_mark_last_busy(dev->dev);
-		pm_runtime_put_autosuspend(dev->dev);
-		return 0;
-	}
-
-	if (!is_support_sw_smu(adev) &&
-	    adev->powerplay.pp_funcs-
 >debugfs_print_current_performance_level) {
-		mutex_lock(&adev->pm.mutex);
-		if (adev->powerplay.pp_funcs-
 >debugfs_print_current_performance_level)
-			adev->powerplay.pp_funcs-
 >debugfs_print_current_performance_level(adev, m);
-		else
-			seq_printf(m, "Debugfs support not implemented
 for this asic\n");
-		mutex_unlock(&adev->pm.mutex);
-		r = 0;
-	} else {
+	if (amdgpu_dpm_debugfs_print_current_performance_level(adev,
 m)) {
 		r = amdgpu_debugfs_pm_info_pp(m, adev);
+		if (r)
+			goto out;
 	}
-	if (r)
-		goto out;
 
 	amdgpu_device_ip_get_clockgating_state(adev, &flags);
@@ -3723,21 +3571,18 @@ static ssize_t
 amdgpu_pm_prv_buffer_read(struct file *f, char __user *buf,
 					 size_t size, loff_t *pos)
 {
 	struct amdgpu_device *adev = file_inode(f)->i_private;
-	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
-	void *pp_handle = adev->powerplay.pp_handle;
 	size_t smu_prv_buf_size;
 	void *smu_prv_buf;
+	int ret = 0;
 
 	if (amdgpu_in_reset(adev))
 		return -EPERM;
 	if (adev->in_suspend && !adev->in_runpm)
 		return -EPERM;
 
-	if (pp_funcs && pp_funcs->get_smu_prv_buf_details)
-		pp_funcs->get_smu_prv_buf_details(pp_handle,
 &smu_prv_buf,
-						  &smu_prv_buf_size);
-	else
-		return -ENOSYS;
+	ret = amdgpu_dpm_get_smu_prv_buf_details(adev, &smu_prv_buf,
 &smu_prv_buf_size);
+	if (ret)
+		return ret;
drivers/gpu/drm/amd/pm/amdgpu_pm.c +1 -1
 	if (!smu_prv_buf || !smu_prv_buf_size)
 		return -EINVAL;
@@ -3770,6 +3615,6 @@ void amdgpu_debugfs_pm_init(struct
 amdgpu_device *adev)
 
 &amdgpu_debugfs_pm_prv_buffer_fops,
 					 adev->pm.smu_prv_buffer_size);
 
-	amdgpu_smu_stb_debug_fs_init(adev);
+	amdgpu_dpm_stb_debug_fs_init(adev);

#endif
}

drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h +0 -3
index 7289d379a9fb..039c40b1d0cb 100644
@@ -262,9 +262,6 @@ enum amdgpu_pcie_gen {
 #define amdgpu_dpm_pre_set_power_state(adev) \
 		((adev)->powerplay.pp_funcs-
 >pre_set_power_state((adev)->powerplay.pp_handle))
 
-#define amdgpu_dpm_set_power_state(adev) \
-		((adev)->powerplay.pp_funcs->set_power_state((adev)-
 >powerplay.pp_handle))
-
 #define amdgpu_dpm_post_set_power_state(adev) \

((adev)->powerplay.pp_funcs-

Quoted 1 line

post_set_power_state((adev)->powerplay.pp_handle))

drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h +0 -29
@@ -280,100 +277,13 @@ enum amdgpu_pcie_gen {
 #define amdgpu_dpm_enable_bapm(adev, e) \
 		((adev)->powerplay.pp_funcs->enable_bapm((adev)-
 >powerplay.pp_handle, (e)))
 
-#define amdgpu_dpm_set_fan_control_mode(adev, m) \
-		((adev)->powerplay.pp_funcs-
 >set_fan_control_mode((adev)->powerplay.pp_handle, (m)))
-
-#define amdgpu_dpm_get_fan_control_mode(adev) \
-		((adev)->powerplay.pp_funcs-
 >get_fan_control_mode((adev)->powerplay.pp_handle))
-
-#define amdgpu_dpm_set_fan_speed_pwm(adev, s) \
-		((adev)->powerplay.pp_funcs-
 >set_fan_speed_pwm((adev)->powerplay.pp_handle, (s)))
-
-#define amdgpu_dpm_get_fan_speed_pwm(adev, s) \
-		((adev)->powerplay.pp_funcs-
 >get_fan_speed_pwm((adev)->powerplay.pp_handle, (s)))
-
-#define amdgpu_dpm_get_fan_speed_rpm(adev, s) \
-		((adev)->powerplay.pp_funcs-
 >get_fan_speed_rpm)((adev)->powerplay.pp_handle, (s))
-
-#define amdgpu_dpm_set_fan_speed_rpm(adev, s) \
-		((adev)->powerplay.pp_funcs-
 >set_fan_speed_rpm)((adev)->powerplay.pp_handle, (s))
-
-#define amdgpu_dpm_force_performance_level(adev, l) \
-		((adev)->powerplay.pp_funcs-
 >force_performance_level((adev)->powerplay.pp_handle, (l)))
-
-#define amdgpu_dpm_get_current_power_state(adev) \
-		((adev)->powerplay.pp_funcs-
 >get_current_power_state((adev)->powerplay.pp_handle))
-
-#define amdgpu_dpm_get_pp_num_states(adev, data) \
-		((adev)->powerplay.pp_funcs->get_pp_num_states((adev)-
 >powerplay.pp_handle, data))
-
-#define amdgpu_dpm_get_pp_table(adev, table) \
-		((adev)->powerplay.pp_funcs->get_pp_table((adev)-
Quoted 1 line

powerplay.pp_handle, table))

drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h +0 -3
-
-#define amdgpu_dpm_set_pp_table(adev, buf, size) \
-		((adev)->powerplay.pp_funcs->set_pp_table((adev)-
Quoted 1 line

powerplay.pp_handle, buf, size))

drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h +0 -3
-
-#define amdgpu_dpm_print_clock_levels(adev, type, buf) \
-		((adev)->powerplay.pp_funcs->print_clock_levels((adev)-
Quoted 1 line

powerplay.pp_handle, type, buf))

drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h +0 -3
-
-#define amdgpu_dpm_force_clock_level(adev, type, level) \
-		((adev)->powerplay.pp_funcs->force_clock_level((adev)-
Quoted 1 line

powerplay.pp_handle, type, level))

drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h +0 -3
-
-#define amdgpu_dpm_get_sclk_od(adev) \
-		((adev)->powerplay.pp_funcs->get_sclk_od((adev)-
Quoted 1 line

powerplay.pp_handle))

drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h +0 -3
-
-#define amdgpu_dpm_set_sclk_od(adev, value) \
-		((adev)->powerplay.pp_funcs->set_sclk_od((adev)-
Quoted 1 line

powerplay.pp_handle, value))

drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h +0 -3
-
-#define amdgpu_dpm_get_mclk_od(adev) \
-		((adev)->powerplay.pp_funcs->get_mclk_od((adev)-
Quoted 1 line

powerplay.pp_handle))

drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h +0 -3
-
-#define amdgpu_dpm_set_mclk_od(adev, value) \
-		((adev)->powerplay.pp_funcs->set_mclk_od((adev)-
Quoted 1 line

powerplay.pp_handle, value))

drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h +0 -2
-
-#define amdgpu_dpm_dispatch_task(adev, task_id, user_state)
	\
drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h +0 -1
-		((adev)->powerplay.pp_funcs->dispatch_tasks)((adev)-
Quoted 1 line

powerplay.pp_handle, (task_id), (user_state))

drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h +0 -1
-
 #define amdgpu_dpm_check_state_equal(adev, cps, rps, equal) \
 		((adev)->powerplay.pp_funcs->check_state_equal((adev)-
Quoted 1 line

powerplay.pp_handle, (cps), (rps), (equal)))

-#define amdgpu_dpm_get_vce_clock_state(adev, i)

	\
drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h +0 -1
-		((adev)->powerplay.pp_funcs->get_vce_clock_state((adev)-
Quoted 1 line

powerplay.pp_handle, (i)))

drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h +0 -2
-
-#define amdgpu_dpm_get_performance_level(adev)
		\
drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h +0 -1
-		((adev)->powerplay.pp_funcs-
Quoted 1 line

get_performance_level((adev)->powerplay.pp_handle))

drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h +0 -1
-
 #define amdgpu_dpm_reset_power_profile_state(adev, request) \
 		((adev)->powerplay.pp_funcs-
Quoted 1 line

reset_power_profile_state(\

drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h +0 -9
 			(adev)->powerplay.pp_handle, request))
 
-#define amdgpu_dpm_get_power_profile_mode(adev, buf) \
-		((adev)->powerplay.pp_funcs->get_power_profile_mode(\
-			(adev)->powerplay.pp_handle, buf))
-
-#define amdgpu_dpm_set_power_profile_mode(adev, parameter, size) \
-		((adev)->powerplay.pp_funcs->set_power_profile_mode(\
-			(adev)->powerplay.pp_handle, parameter, size))
-
-#define amdgpu_dpm_set_fine_grain_clk_vol(adev, type, parameter, size)

\

drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h +0 -2
-		((adev)->powerplay.pp_funcs->set_fine_grain_clk_vol(\
-			(adev)->powerplay.pp_handle, type, parameter,

size))

drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h +0 -4
-
-#define amdgpu_dpm_odn_edit_dpm_table(adev, type, parameter, size) \
-		((adev)->powerplay.pp_funcs->odn_edit_dpm_table(\
-			(adev)->powerplay.pp_handle, type, parameter,

size))

drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h +0 -11
-
-#define amdgpu_dpm_get_ppfeature_status(adev, buf) \
-		((adev)->powerplay.pp_funcs->get_ppfeature_status(\
-			(adev)->powerplay.pp_handle, (buf)))
-
-#define amdgpu_dpm_set_ppfeature_status(adev, ppfeatures) \
-		((adev)->powerplay.pp_funcs->set_ppfeature_status(\
-			(adev)->powerplay.pp_handle, (ppfeatures)))
-
-#define amdgpu_dpm_get_gpu_metrics(adev, table) \
-		((adev)->powerplay.pp_funcs->get_gpu_metrics((adev)-
Quoted 1 line

powerplay.pp_handle, table))

drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h +1 -1
-
 struct amdgpu_dpm {
 	struct amdgpu_ps        *ps;
 	/* number of valid power states */
@@ -598,4 +508,74 @@ void amdgpu_dpm_gfx_state_change(struct
 amdgpu_device *adev,
 				 enum gfx_change_state state);
 int amdgpu_dpm_get_ecc_info(struct amdgpu_device *adev,
 			    void *umc_ecc);
+struct amd_vce_state *amdgpu_dpm_get_vce_clock_state(struct

amdgpu_device *adev,

drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h +2 -0
+						     uint32_t idx);
+void amdgpu_dpm_get_current_power_state(struct amdgpu_device

*adev, enum amd_pm_state_type *state);

drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h +3 -0
+void amdgpu_dpm_set_power_state(struct amdgpu_device *adev,
+				enum amd_pm_state_type state);
+enum amd_dpm_forced_level

amdgpu_dpm_get_performance_level(struct amdgpu_device *adev);

drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h +8 -0
+int amdgpu_dpm_force_performance_level(struct amdgpu_device *adev,
+				       enum amd_dpm_forced_level level);
+int amdgpu_dpm_get_pp_num_states(struct amdgpu_device *adev,
+				 struct pp_states_info *states);
+int amdgpu_dpm_dispatch_task(struct amdgpu_device *adev,
+			      enum amd_pp_task task_id,
+			      enum amd_pm_state_type *user_state);
+int amdgpu_dpm_get_pp_table(struct amdgpu_device *adev, char

**table);

drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h +14 -0
+int amdgpu_dpm_set_fine_grain_clk_vol(struct amdgpu_device *adev,
+				      uint32_t type,
+				      long *input,
+				      uint32_t size);
+int amdgpu_dpm_odn_edit_dpm_table(struct amdgpu_device *adev,
+				  uint32_t type,
+				  long *input,
+				  uint32_t size);
+int amdgpu_dpm_print_clock_levels(struct amdgpu_device *adev,
+				  enum pp_clock_type type,
+				  char *buf);
+int amdgpu_dpm_set_ppfeature_status(struct amdgpu_device *adev,
+				    uint64_t ppfeature_masks);
+int amdgpu_dpm_get_ppfeature_status(struct amdgpu_device *adev,

char *buf);

drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h +5 -0
+int amdgpu_dpm_force_clock_level(struct amdgpu_device *adev,
+				 enum pp_clock_type type,
+				 uint32_t mask);
+int amdgpu_dpm_get_sclk_od(struct amdgpu_device *adev);
+int amdgpu_dpm_set_sclk_od(struct amdgpu_device *adev, uint32_t

value);

drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h +2 -0
+int amdgpu_dpm_get_mclk_od(struct amdgpu_device *adev);
+int amdgpu_dpm_set_mclk_od(struct amdgpu_device *adev, uint32_t

value);

drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h +5 -0
+int amdgpu_dpm_get_power_profile_mode(struct amdgpu_device *adev,
+				      char *buf);
+int amdgpu_dpm_set_power_profile_mode(struct amdgpu_device *adev,
+				      long *input, uint32_t size);
+int amdgpu_dpm_get_gpu_metrics(struct amdgpu_device *adev, void

**table);

drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h +20 -0
+int amdgpu_dpm_get_fan_control_mode(struct amdgpu_device *adev,
+				    uint32_t *fan_mode);
+int amdgpu_dpm_set_fan_speed_pwm(struct amdgpu_device *adev,
+				 uint32_t speed);
+int amdgpu_dpm_get_fan_speed_pwm(struct amdgpu_device *adev,
+				 uint32_t *speed);
+int amdgpu_dpm_get_fan_speed_rpm(struct amdgpu_device *adev,
+				 uint32_t *speed);
+int amdgpu_dpm_set_fan_speed_rpm(struct amdgpu_device *adev,
+				 uint32_t speed);
+int amdgpu_dpm_set_fan_control_mode(struct amdgpu_device *adev,
+				    uint32_t mode);
+int amdgpu_dpm_get_power_limit(struct amdgpu_device *adev,
+			       uint32_t *limit,
+			       enum pp_power_limit_level pp_limit_level,
+			       enum pp_power_type power_type);
+int amdgpu_dpm_set_power_limit(struct amdgpu_device *adev,
+			       uint32_t limit);
+int amdgpu_dpm_is_cclk_dpm_supported(struct amdgpu_device *adev);
+int amdgpu_dpm_debugfs_print_current_performance_level(struct

amdgpu_device *adev,

drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h +10 -0
+						       struct seq_file *m);
+int amdgpu_dpm_get_smu_prv_buf_details(struct amdgpu_device *adev,
+				       void **addr,
+				       size_t *size);
+int amdgpu_dpm_is_overdrive_supported(struct amdgpu_device *adev);
+int amdgpu_dpm_set_pp_table(struct amdgpu_device *adev,
+			    const char *buf,
+			    size_t size);
+int amdgpu_dpm_get_num_cpu_cores(struct amdgpu_device *adev);
+void amdgpu_dpm_stb_debug_fs_init(struct amdgpu_device *adev);
 #endif
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +0 -4
index ef7d0e377965..eaed5aba7547 100644
@@ -470,9 +470,6 @@ bool is_support_cclk_dpm(struct amdgpu_device
 *adev)
 {
 	struct smu_context *smu = &adev->smu;
 
-	if (!is_support_sw_smu(adev))
-		return false;
-
 	if (!smu_feature_is_enabled(smu, SMU_FEATURE_CCLK_DPM_BIT))
 		return false;
 
--

2.29.0

author
#10 lore raw

PATCH v2 3/17 drm/amd/pm: do not expose power implementation details to display

In reply to Evan Quan

Display is another client of our power APIs. It's not proper to spike into power implementation details there.

Change-Id Ic897131e16473ed29d3d7586d822a55c64e6574a
---
 .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c |   6 +-
 .../amd/display/amdgpu_dm/amdgpu_dm_pp_smu.c  | 246 +++++++-----------
 drivers/gpu/drm/amd/pm/amdgpu_dpm.c           | 218 ++++++++++++++++
 drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h       |  38 +++
 4 files changed, 344 insertions(+), 164 deletions(-)
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +1 -5
index 53f7fdf956eb..92480cc57623 100644
@@ -2139,12 +2139,8 @@ static void s3_handle_mst(struct drm_device *dev, bool suspend)
 
 static int amdgpu_dm_smu_write_watermarks_table(struct amdgpu_device *adev)
 {
-	struct smu_context *smu = &adev->smu;
 	int ret = 0;
 
-	if (!is_support_sw_smu(adev))
-		return 0;
-
 	/* This interface is for dGPU Navi1x.Linux dc-pplib interface depends
 	 * on window driver dc implementation.
 	 * For Navi1x, clock settings of dcn watermarks are fixed. the settings
@@ -2183,7 +2179,7 @@ static int amdgpu_dm_smu_write_watermarks_table(struct amdgpu_device *adev)
 		return 0;
 	}
 
-	ret = smu_write_watermarks_table(smu);
+	ret = amdgpu_dpm_write_watermarks_table(adev);
 	if (ret) {
 		DRM_ERROR("Failed to update WMTABLE!\n");
 		return ret;
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_pp_smu.c +87 -159

461 lines not on this page · raw message

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

227 lines not on this page · raw message

drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h +38 -0
index 039c40b1d0cb..fea203a79cb4 100644
@@ -500,6 +500,7 @@ int amdgpu_dpm_set_soft_freq_range(struct amdgpu_device *adev,
 				        enum pp_clock_type type,
 				        uint32_t min,
 				        uint32_t max);
+int amdgpu_dpm_write_watermarks_table(struct amdgpu_device *adev);
 int amdgpu_dpm_wait_for_event(struct amdgpu_device *adev, enum smu_event_type event,
 		       uint64_t event_arg);
 int amdgpu_dpm_get_status_gfxoff(struct amdgpu_device *adev, uint32_t *value);
@@ -578,4 +579,41 @@ int amdgpu_dpm_set_pp_table(struct amdgpu_device *adev,
 			    size_t size);
 int amdgpu_dpm_get_num_cpu_cores(struct amdgpu_device *adev);
 void amdgpu_dpm_stb_debug_fs_init(struct amdgpu_device *adev);
+int amdgpu_dpm_display_configuration_change(struct amdgpu_device *adev,
+					    const struct amd_pp_display_configuration *input);
+int amdgpu_dpm_get_clock_by_type(struct amdgpu_device *adev,
+				 enum amd_pp_clock_type type,
+				 struct amd_pp_clocks *clocks);
+int amdgpu_dpm_get_display_mode_validation_clks(struct amdgpu_device *adev,
+						struct amd_pp_simple_clock_info *clocks);
+int amdgpu_dpm_get_clock_by_type_with_latency(struct amdgpu_device *adev,
+					      enum amd_pp_clock_type type,
+					      struct pp_clock_levels_with_latency *clocks);
+int amdgpu_dpm_get_clock_by_type_with_voltage(struct amdgpu_device *adev,
+					      enum amd_pp_clock_type type,
+					      struct pp_clock_levels_with_voltage *clocks);
+int amdgpu_dpm_set_watermarks_for_clocks_ranges(struct amdgpu_device *adev,
+					       void *clock_ranges);
+int amdgpu_dpm_display_clock_voltage_request(struct amdgpu_device *adev,
+					     struct pp_display_clock_request *clock);
+int amdgpu_dpm_get_current_clocks(struct amdgpu_device *adev,
+				  struct amd_pp_clock_info *clocks);
+void amdgpu_dpm_notify_smu_enable_pwe(struct amdgpu_device *adev);
+int amdgpu_dpm_set_active_display_count(struct amdgpu_device *adev,
+					uint32_t count);
+int amdgpu_dpm_set_min_deep_sleep_dcefclk(struct amdgpu_device *adev,
+					  uint32_t clock);
+void amdgpu_dpm_set_hard_min_dcefclk_by_freq(struct amdgpu_device *adev,
+					     uint32_t clock);
+void amdgpu_dpm_set_hard_min_fclk_by_freq(struct amdgpu_device *adev,
+					  uint32_t clock);
+int amdgpu_dpm_display_disable_memory_clock_switch(struct amdgpu_device *adev,
+						   bool disable_memory_clock_switch);
+int amdgpu_dpm_get_max_sustainable_clocks_by_dc(struct amdgpu_device *adev,
+						struct pp_smu_nv_clock_table *max_clocks);
+enum pp_smu_status amdgpu_dpm_get_uclk_dpm_states(struct amdgpu_device *adev,
+						  unsigned int *clock_values_in_khz,
+						  unsigned int *num_states);
+int amdgpu_dpm_get_dpm_clock_table(struct amdgpu_device *adev,
+				   struct dpm_clocks *clock_table);
 #endif
Signature · 1 line
2.29.0
author
#11 lore raw

PATCH v2 4/17 drm/amd/pm: do not expose those APIs used internally only in amdgpu_dpm.c

In reply to Evan Quan

Move them to amdgpu_dpm.c instead.

Change-Id I59fe0efcb47c18ec7254f3624db7a2eb78d91b8c
---
 drivers/gpu/drm/amd/pm/amdgpu_dpm.c     | 25 +++++++++++++++++++++++--
 drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h | 23 -----------------------
 2 files changed, 23 insertions(+), 25 deletions(-)
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +23 -2
index 4aa5cca66048..52ac3c883a6e 100644
@@ -34,6 +34,27 @@
 
 #define WIDTH_4K 3840
 
+#define amdgpu_dpm_pre_set_power_state(adev) \
+		((adev)->powerplay.pp_funcs->pre_set_power_state((adev)->powerplay.pp_handle))
+
+#define amdgpu_dpm_post_set_power_state(adev) \
+		((adev)->powerplay.pp_funcs->post_set_power_state((adev)->powerplay.pp_handle))
+
+#define amdgpu_dpm_display_configuration_changed(adev) \
+		((adev)->powerplay.pp_funcs->display_configuration_changed((adev)->powerplay.pp_handle))
+
+#define amdgpu_dpm_print_power_state(adev, ps) \
+		((adev)->powerplay.pp_funcs->print_power_state((adev)->powerplay.pp_handle, (ps)))
+
+#define amdgpu_dpm_vblank_too_short(adev) \
+		((adev)->powerplay.pp_funcs->vblank_too_short((adev)->powerplay.pp_handle))
+
+#define amdgpu_dpm_enable_bapm(adev, e) \
+		((adev)->powerplay.pp_funcs->enable_bapm((adev)->powerplay.pp_handle, (e)))
+
+#define amdgpu_dpm_check_state_equal(adev, cps, rps, equal) \
+		((adev)->powerplay.pp_funcs->check_state_equal((adev)->powerplay.pp_handle, (cps), (rps), (equal)))
+
 void amdgpu_dpm_print_class_info(u32 class, u32 class2)
 {
 	const char *s;
@@ -120,7 +141,7 @@ void amdgpu_dpm_print_ps_status(struct amdgpu_device *adev,
 	pr_cont("\n");
 }
 
-void amdgpu_dpm_get_active_displays(struct amdgpu_device *adev)
+static void amdgpu_dpm_get_active_displays(struct amdgpu_device *adev)
 {
 	struct drm_device *ddev = adev_to_drm(adev);
 	struct drm_crtc *crtc;
@@ -168,7 +189,7 @@ u32 amdgpu_dpm_get_vblank_time(struct amdgpu_device *adev)
 	return vblank_time_us;
 }
 
-u32 amdgpu_dpm_get_vrefresh(struct amdgpu_device *adev)
+static u32 amdgpu_dpm_get_vrefresh(struct amdgpu_device *adev)
 {
 	struct drm_device *dev = adev_to_drm(adev);
 	struct drm_crtc *crtc;
drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h +0 -23
index fea203a79cb4..6681b878e75f 100644
@@ -259,27 +259,6 @@ enum amdgpu_pcie_gen {
 	AMDGPU_PCIE_GEN_INVALID = 0xffff
 };
 
-#define amdgpu_dpm_pre_set_power_state(adev) \
-		((adev)->powerplay.pp_funcs->pre_set_power_state((adev)->powerplay.pp_handle))
-
-#define amdgpu_dpm_post_set_power_state(adev) \
-		((adev)->powerplay.pp_funcs->post_set_power_state((adev)->powerplay.pp_handle))
-
-#define amdgpu_dpm_display_configuration_changed(adev) \
-		((adev)->powerplay.pp_funcs->display_configuration_changed((adev)->powerplay.pp_handle))
-
-#define amdgpu_dpm_print_power_state(adev, ps) \
-		((adev)->powerplay.pp_funcs->print_power_state((adev)->powerplay.pp_handle, (ps)))
-
-#define amdgpu_dpm_vblank_too_short(adev) \
-		((adev)->powerplay.pp_funcs->vblank_too_short((adev)->powerplay.pp_handle))
-
-#define amdgpu_dpm_enable_bapm(adev, e) \
-		((adev)->powerplay.pp_funcs->enable_bapm((adev)->powerplay.pp_handle, (e)))
-
-#define amdgpu_dpm_check_state_equal(adev, cps, rps, equal) \
-		((adev)->powerplay.pp_funcs->check_state_equal((adev)->powerplay.pp_handle, (cps), (rps), (equal)))
-
 #define amdgpu_dpm_reset_power_profile_state(adev, request) \
 		((adev)->powerplay.pp_funcs->reset_power_profile_state(\
 			(adev)->powerplay.pp_handle, request))
@@ -412,8 +391,6 @@ void amdgpu_dpm_print_cap_info(u32 caps);
 void amdgpu_dpm_print_ps_status(struct amdgpu_device *adev,
 				struct amdgpu_ps *rps);
 u32 amdgpu_dpm_get_vblank_time(struct amdgpu_device *adev);
-u32 amdgpu_dpm_get_vrefresh(struct amdgpu_device *adev);
-void amdgpu_dpm_get_active_displays(struct amdgpu_device *adev);
 int amdgpu_dpm_read_sensor(struct amdgpu_device *adev, enum amd_pp_sensors sensor,
 			   void *data, uint32_t *size);
 
Signature · 1 line
2.29.0
author
#12 lore raw

PATCH v2 5/17 drm/amd/pm: do not expose those APIs used internally only in si_dpm.c

In reply to Evan Quan

Move them to si_dpm.c instead.

Change-Id I288205cfd7c6ba09cfb22626ff70360d61ff0c67

--
v1->v2:
- rename the API with "si_" prefix(Alex)

---
 drivers/gpu/drm/amd/pm/amdgpu_dpm.c       | 25 -----------
 drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h   | 25 -----------
 drivers/gpu/drm/amd/pm/powerplay/si_dpm.c | 54 +++++++++++++++++++----
 drivers/gpu/drm/amd/pm/powerplay/si_dpm.h |  7 +++
 4 files changed, 53 insertions(+), 58 deletions(-)
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +0 -25
index 52ac3c883a6e..fbfc07a83122 100644
@@ -894,31 +894,6 @@ void amdgpu_add_thermal_controller(struct amdgpu_device *adev)
 	}
 }
 
-enum amdgpu_pcie_gen amdgpu_get_pcie_gen_support(struct amdgpu_device *adev,
-						 u32 sys_mask,
-						 enum amdgpu_pcie_gen asic_gen,
-						 enum amdgpu_pcie_gen default_gen)
-{
-	switch (asic_gen) {
-	case AMDGPU_PCIE_GEN1:
-		return AMDGPU_PCIE_GEN1;
-	case AMDGPU_PCIE_GEN2:
-		return AMDGPU_PCIE_GEN2;
-	case AMDGPU_PCIE_GEN3:
-		return AMDGPU_PCIE_GEN3;
-	default:
-		if ((sys_mask & CAIL_PCIE_LINK_SPEED_SUPPORT_GEN3) &&
-		    (default_gen == AMDGPU_PCIE_GEN3))
-			return AMDGPU_PCIE_GEN3;
-		else if ((sys_mask & CAIL_PCIE_LINK_SPEED_SUPPORT_GEN2) &&
-			 (default_gen == AMDGPU_PCIE_GEN2))
-			return AMDGPU_PCIE_GEN2;
-		else
-			return AMDGPU_PCIE_GEN1;
-	}
-	return AMDGPU_PCIE_GEN1;
-}
-
 struct amd_vce_state*
 amdgpu_get_vce_clock_state(void *handle, u32 idx)
 {
drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h +0 -25
index 6681b878e75f..f43b96dfe9d8 100644
@@ -45,19 +45,6 @@ enum amdgpu_int_thermal_type {
 	THERMAL_TYPE_KV,
 };
 
-enum amdgpu_dpm_auto_throttle_src {
-	AMDGPU_DPM_AUTO_THROTTLE_SRC_THERMAL,
-	AMDGPU_DPM_AUTO_THROTTLE_SRC_EXTERNAL
-};
-
-enum amdgpu_dpm_event_src {
-	AMDGPU_DPM_EVENT_SRC_ANALOG = 0,
-	AMDGPU_DPM_EVENT_SRC_EXTERNAL = 1,
-	AMDGPU_DPM_EVENT_SRC_DIGITAL = 2,
-	AMDGPU_DPM_EVENT_SRC_ANALOG_OR_EXTERNAL = 3,
-	AMDGPU_DPM_EVENT_SRC_DIGIAL_OR_EXTERNAL = 4
-};
-
 struct amdgpu_ps {
 	u32 caps; /* vbios flags */
 	u32 class; /* vbios flags */
@@ -252,13 +239,6 @@ struct amdgpu_dpm_fan {
 	bool ucode_fan_control;
 };
 
-enum amdgpu_pcie_gen {
-	AMDGPU_PCIE_GEN1 = 0,
-	AMDGPU_PCIE_GEN2 = 1,
-	AMDGPU_PCIE_GEN3 = 2,
-	AMDGPU_PCIE_GEN_INVALID = 0xffff
-};
-
 #define amdgpu_dpm_reset_power_profile_state(adev, request) \
 		((adev)->powerplay.pp_funcs->reset_power_profile_state(\
 			(adev)->powerplay.pp_handle, request))
@@ -403,11 +383,6 @@ void amdgpu_free_extended_power_table(struct amdgpu_device *adev);
 
 void amdgpu_add_thermal_controller(struct amdgpu_device *adev);
 
-enum amdgpu_pcie_gen amdgpu_get_pcie_gen_support(struct amdgpu_device *adev,
-						 u32 sys_mask,
-						 enum amdgpu_pcie_gen asic_gen,
-						 enum amdgpu_pcie_gen default_gen);
-
 struct amd_vce_state*
 amdgpu_get_vce_clock_state(void *handle, u32 idx);
 
drivers/gpu/drm/amd/pm/powerplay/si_dpm.c +46 -8

78 lines not on this page · raw message

drivers/gpu/drm/amd/pm/powerplay/si_dpm.h +7 -0
index bc0be6818e21..8c267682eeef 100644
@@ -595,6 +595,13 @@ struct rv7xx_power_info {
 	RV770_SMC_STATETABLE smc_statetable;
 };
 
+enum amdgpu_pcie_gen {
+	AMDGPU_PCIE_GEN1 = 0,
+	AMDGPU_PCIE_GEN2 = 1,
+	AMDGPU_PCIE_GEN3 = 2,
+	AMDGPU_PCIE_GEN_INVALID = 0xffff
+};
+
 struct rv7xx_pl {
 	u32 sclk;
 	u32 mclk;
Signature · 1 line
2.29.0
#13 lore raw

Re: [PATCH V2 05/17] drm/amd/pm: do not expose those APIs used internally only in si_dpm.c

Quoted 111 lines · Evan Quan

Move them to si_dpm.c instead.

Change-Id I288205cfd7c6ba09cfb22626ff70360d61ff0c67

--
v1->v2:
- rename the API with "si_" prefix(Alex)

---
  drivers/gpu/drm/amd/pm/amdgpu_dpm.c       | 25 -----------
  drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h   | 25 -----------
  drivers/gpu/drm/amd/pm/powerplay/si_dpm.c | 54 +++++++++++++++++++----
  drivers/gpu/drm/amd/pm/powerplay/si_dpm.h |  7 +++
  4 files changed, 53 insertions(+), 58 deletions(-)
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +0 -25
index 52ac3c883a6e..fbfc07a83122 100644
@@ -894,31 +894,6 @@ void amdgpu_add_thermal_controller(struct amdgpu_device *adev)
  	}
  }
 
-enum amdgpu_pcie_gen amdgpu_get_pcie_gen_support(struct amdgpu_device *adev,
-						 u32 sys_mask,
-						 enum amdgpu_pcie_gen asic_gen,
-						 enum amdgpu_pcie_gen default_gen)
-{
-	switch (asic_gen) {
-	case AMDGPU_PCIE_GEN1:
-		return AMDGPU_PCIE_GEN1;
-	case AMDGPU_PCIE_GEN2:
-		return AMDGPU_PCIE_GEN2;
-	case AMDGPU_PCIE_GEN3:
-		return AMDGPU_PCIE_GEN3;
-	default:
-		if ((sys_mask & CAIL_PCIE_LINK_SPEED_SUPPORT_GEN3) &&
-		    (default_gen == AMDGPU_PCIE_GEN3))
-			return AMDGPU_PCIE_GEN3;
-		else if ((sys_mask & CAIL_PCIE_LINK_SPEED_SUPPORT_GEN2) &&
-			 (default_gen == AMDGPU_PCIE_GEN2))
-			return AMDGPU_PCIE_GEN2;
-		else
-			return AMDGPU_PCIE_GEN1;
-	}
-	return AMDGPU_PCIE_GEN1;
-}
-
  struct amd_vce_state*
  amdgpu_get_vce_clock_state(void *handle, u32 idx)
  {
drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h +0 -25
index 6681b878e75f..f43b96dfe9d8 100644
@@ -45,19 +45,6 @@ enum amdgpu_int_thermal_type {
  	THERMAL_TYPE_KV,
  };
 
-enum amdgpu_dpm_auto_throttle_src {
-	AMDGPU_DPM_AUTO_THROTTLE_SRC_THERMAL,
-	AMDGPU_DPM_AUTO_THROTTLE_SRC_EXTERNAL
-};
-
-enum amdgpu_dpm_event_src {
-	AMDGPU_DPM_EVENT_SRC_ANALOG = 0,
-	AMDGPU_DPM_EVENT_SRC_EXTERNAL = 1,
-	AMDGPU_DPM_EVENT_SRC_DIGITAL = 2,
-	AMDGPU_DPM_EVENT_SRC_ANALOG_OR_EXTERNAL = 3,
-	AMDGPU_DPM_EVENT_SRC_DIGIAL_OR_EXTERNAL = 4
-};
-
  struct amdgpu_ps {
  	u32 caps; /* vbios flags */
  	u32 class; /* vbios flags */
@@ -252,13 +239,6 @@ struct amdgpu_dpm_fan {
  	bool ucode_fan_control;
  };
 
-enum amdgpu_pcie_gen {
-	AMDGPU_PCIE_GEN1 = 0,
-	AMDGPU_PCIE_GEN2 = 1,
-	AMDGPU_PCIE_GEN3 = 2,
-	AMDGPU_PCIE_GEN_INVALID = 0xffff
-};
-
  #define amdgpu_dpm_reset_power_profile_state(adev, request) \
  		((adev)->powerplay.pp_funcs->reset_power_profile_state(\
  			(adev)->powerplay.pp_handle, request))
@@ -403,11 +383,6 @@ void amdgpu_free_extended_power_table(struct amdgpu_device *adev);
 
  void amdgpu_add_thermal_controller(struct amdgpu_device *adev);
 
-enum amdgpu_pcie_gen amdgpu_get_pcie_gen_support(struct amdgpu_device *adev,
-						 u32 sys_mask,
-						 enum amdgpu_pcie_gen asic_gen,
-						 enum amdgpu_pcie_gen default_gen);
-
  struct amd_vce_state*
  amdgpu_get_vce_clock_state(void *handle, u32 idx);
 
drivers/gpu/drm/amd/pm/powerplay/si_dpm.c +3 -0
index 81f82aa05ec2..4f84d8b893f1 100644
@@ -96,6 +96,19 @@ union pplib_clock_info {
  	struct _ATOM_PPLIB_SI_CLOCK_INFO si;
  };
 
+enum amdgpu_dpm_auto_throttle_src {
+	AMDGPU_DPM_AUTO_THROTTLE_SRC_THERMAL,
+	AMDGPU_DPM_AUTO_THROTTLE_SRC_EXTERNAL

drivers/gpu/drm/amd/pm/powerplay/si_dpm.c union pplib_clock_info { · line 111

Quoted 10 lines
drivers/gpu/drm/amd/pm/powerplay/si_dpm.c +10 -0
+};
+
+enum amdgpu_dpm_event_src {
+	AMDGPU_DPM_EVENT_SRC_ANALOG = 0,
+	AMDGPU_DPM_EVENT_SRC_EXTERNAL = 1,
+	AMDGPU_DPM_EVENT_SRC_DIGITAL = 2,
+	AMDGPU_DPM_EVENT_SRC_ANALOG_OR_EXTERNAL = 3,
+	AMDGPU_DPM_EVENT_SRC_DIGIAL_OR_EXTERNAL = 4
+};
+

Better to rename the enums also including amdgpu_pcie_gen if they are used only within si_dpm.

Thanks,
Lijo

Quoted 84 lines
drivers/gpu/drm/amd/pm/powerplay/si_dpm.c +33 -8
  static const u32 r600_utc[R600_PM_NUMBER_OF_TC] =
  {
  	R600_UTC_DFLT_00,
@@ -4927,6 +4940,31 @@ static int si_populate_smc_initial_state(struct amdgpu_device *adev,
  	return 0;
  }
 
+static enum amdgpu_pcie_gen si_gen_pcie_gen_support(struct amdgpu_device *adev,
+						    u32 sys_mask,
+						    enum amdgpu_pcie_gen asic_gen,
+						    enum amdgpu_pcie_gen default_gen)
+{
+	switch (asic_gen) {
+	case AMDGPU_PCIE_GEN1:
+		return AMDGPU_PCIE_GEN1;
+	case AMDGPU_PCIE_GEN2:
+		return AMDGPU_PCIE_GEN2;
+	case AMDGPU_PCIE_GEN3:
+		return AMDGPU_PCIE_GEN3;
+	default:
+		if ((sys_mask & CAIL_PCIE_LINK_SPEED_SUPPORT_GEN3) &&
+		    (default_gen == AMDGPU_PCIE_GEN3))
+			return AMDGPU_PCIE_GEN3;
+		else if ((sys_mask & CAIL_PCIE_LINK_SPEED_SUPPORT_GEN2) &&
+			 (default_gen == AMDGPU_PCIE_GEN2))
+			return AMDGPU_PCIE_GEN2;
+		else
+			return AMDGPU_PCIE_GEN1;
+	}
+	return AMDGPU_PCIE_GEN1;
+}
+
  static int si_populate_smc_acpi_state(struct amdgpu_device *adev,
  				      SISLANDS_SMC_STATETABLE *table)
  {
@@ -4989,10 +5027,10 @@ static int si_populate_smc_acpi_state(struct amdgpu_device *adev,
  							      &table->ACPIState.level.std_vddc);
  		}
  		table->ACPIState.level.gen2PCIE =
-			(u8)amdgpu_get_pcie_gen_support(adev,
-							si_pi->sys_pcie_mask,
-							si_pi->boot_pcie_gen,
-							AMDGPU_PCIE_GEN1);
+			(u8)si_gen_pcie_gen_support(adev,
+						    si_pi->sys_pcie_mask,
+						    si_pi->boot_pcie_gen,
+						    AMDGPU_PCIE_GEN1);
 
  		if (si_pi->vddc_phase_shed_control)
  			si_populate_phase_shedding_value(adev,
@@ -7148,10 +7186,10 @@ static void si_parse_pplib_clock_info(struct amdgpu_device *adev,
  	pl->vddc = le16_to_cpu(clock_info->si.usVDDC);
  	pl->vddci = le16_to_cpu(clock_info->si.usVDDCI);
  	pl->flags = le32_to_cpu(clock_info->si.ulFlags);
-	pl->pcie_gen = amdgpu_get_pcie_gen_support(adev,
-						   si_pi->sys_pcie_mask,
-						   si_pi->boot_pcie_gen,
-						   clock_info->si.ucPCIEGen);
+	pl->pcie_gen = si_gen_pcie_gen_support(adev,
+					       si_pi->sys_pcie_mask,
+					       si_pi->boot_pcie_gen,
+					       clock_info->si.ucPCIEGen);
 
  	/* patch up vddc if necessary */
  	ret = si_get_leakage_voltage_from_leakage_index(adev, pl->vddc,
drivers/gpu/drm/amd/pm/powerplay/si_dpm.h +7 -0
index bc0be6818e21..8c267682eeef 100644
@@ -595,6 +595,13 @@ struct rv7xx_power_info {
  	RV770_SMC_STATETABLE smc_statetable;
  };
 
+enum amdgpu_pcie_gen {
+	AMDGPU_PCIE_GEN1 = 0,
+	AMDGPU_PCIE_GEN2 = 1,
+	AMDGPU_PCIE_GEN3 = 2,
+	AMDGPU_PCIE_GEN_INVALID = 0xffff
+};
+
  struct rv7xx_pl {
  	u32 sclk;
  	u32 mclk;
author
#14 lore raw

RE: [PATCH V2 05/17] drm/amd/pm: do not expose those APIs used internally only in si_dpm.c

[AMD Official Use Only]

Quoted 135 lines

-----Original Message-----
From: Lazar, Lijo <[email protected]>
Sent: Tuesday, November 30, 2021 8:22 PM
To: Quan, Evan <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>; Feng, Kenneth <[email protected]>
Subject: Re: [PATCH V2 05/17] drm/amd/pm: do not expose those APIs used internally only in si_dpm.c

Quoted 11 lines · Evan Quan

Move them to si_dpm.c instead.

Change-Id I288205cfd7c6ba09cfb22626ff70360d61ff0c67

--
v1->v2:
- rename the API with "si_" prefix(Alex)

---
  drivers/gpu/drm/amd/pm/amdgpu_dpm.c       | 25 -----------
  drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h   | 25 -----------
  drivers/gpu/drm/amd/pm/powerplay/si_dpm.c | 54

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

drivers/gpu/drm/amd/pm/amdgpu_dpm.c void amdgpu_add_thermal_controller(struct

Quoted 9 lines
  drivers/gpu/drm/amd/pm/powerplay/si_dpm.h |  7 +++
  4 files changed, 53 insertions(+), 58 deletions(-)
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +0 -0
index 52ac3c883a6e..fbfc07a83122 100644
@@ -894,31 +894,6 @@ void amdgpu_add_thermal_controller(struct

amdgpu_device *adev)

drivers/gpu/drm/amd/pm/amdgpu_dpm.c void amdgpu_add_thermal_controller(struct · line 897

Quoted 4 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +0 -1
  	}
  }
 
-enum amdgpu_pcie_gen amdgpu_get_pcie_gen_support(struct

amdgpu_device *adev,

drivers/gpu/drm/amd/pm/amdgpu_dpm.c void amdgpu_add_thermal_controller(struct · line 899

Quoted 2 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +0 -2
-						 u32 sys_mask,
-						 enum amdgpu_pcie_gen

asic_gen,

drivers/gpu/drm/amd/pm/amdgpu_dpm.c void amdgpu_add_thermal_controller(struct · line 900

Quoted 1 line
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +0 -1
-						 enum amdgpu_pcie_gen

default_gen)

drivers/gpu/drm/amd/pm/amdgpu_dpm.c void amdgpu_add_thermal_controller(struct amdgpu_device *adev)

Quoted 10 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +0 -10
-{
-	switch (asic_gen) {
-	case AMDGPU_PCIE_GEN1:
-		return AMDGPU_PCIE_GEN1;
-	case AMDGPU_PCIE_GEN2:
-		return AMDGPU_PCIE_GEN2;
-	case AMDGPU_PCIE_GEN3:
-		return AMDGPU_PCIE_GEN3;
-	default:
-		if ((sys_mask & CAIL_PCIE_LINK_SPEED_SUPPORT_GEN3)

&&

drivers/gpu/drm/amd/pm/amdgpu_dpm.c void amdgpu_add_thermal_controller(struct amdgpu_device *adev)

Quoted 3 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +0 -3
-		    (default_gen == AMDGPU_PCIE_GEN3))
-			return AMDGPU_PCIE_GEN3;
-		else if ((sys_mask &

CAIL_PCIE_LINK_SPEED_SUPPORT_GEN2) &&

Quoted 50 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +0 -8
-			 (default_gen == AMDGPU_PCIE_GEN2))
-			return AMDGPU_PCIE_GEN2;
-		else
-			return AMDGPU_PCIE_GEN1;
-	}
-	return AMDGPU_PCIE_GEN1;
-}
-
  struct amd_vce_state*
  amdgpu_get_vce_clock_state(void *handle, u32 idx)
  {
drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h +0 -20
index 6681b878e75f..f43b96dfe9d8 100644
@@ -45,19 +45,6 @@ enum amdgpu_int_thermal_type {
  	THERMAL_TYPE_KV,
  };
 
-enum amdgpu_dpm_auto_throttle_src {
-	AMDGPU_DPM_AUTO_THROTTLE_SRC_THERMAL,
-	AMDGPU_DPM_AUTO_THROTTLE_SRC_EXTERNAL
-};
-
-enum amdgpu_dpm_event_src {
-	AMDGPU_DPM_EVENT_SRC_ANALOG = 0,
-	AMDGPU_DPM_EVENT_SRC_EXTERNAL = 1,
-	AMDGPU_DPM_EVENT_SRC_DIGITAL = 2,
-	AMDGPU_DPM_EVENT_SRC_ANALOG_OR_EXTERNAL = 3,
-	AMDGPU_DPM_EVENT_SRC_DIGIAL_OR_EXTERNAL = 4
-};
-
  struct amdgpu_ps {
  	u32 caps; /* vbios flags */
  	u32 class; /* vbios flags */
@@ -252,13 +239,6 @@ struct amdgpu_dpm_fan {
  	bool ucode_fan_control;
  };
 
-enum amdgpu_pcie_gen {
-	AMDGPU_PCIE_GEN1 = 0,
-	AMDGPU_PCIE_GEN2 = 1,
-	AMDGPU_PCIE_GEN3 = 2,
-	AMDGPU_PCIE_GEN_INVALID = 0xffff
-};
-
  #define amdgpu_dpm_reset_power_profile_state(adev, request) \
  		((adev)->powerplay.pp_funcs-
 reset_power_profile_state(\
Quoted 1 line

(adev)->powerplay.pp_handle, request)) @@ -

403,11 +383,6 @@ void

Quoted 5 lines

amdgpu_free_extended_power_table(struct amdgpu_device *adev);

  void amdgpu_add_thermal_controller(struct amdgpu_device *adev);

-enum amdgpu_pcie_gen amdgpu_get_pcie_gen_support(struct

amdgpu_device *adev,

drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h

Quoted 2 lines
drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h +0 -2
-						 u32 sys_mask,
-						 enum amdgpu_pcie_gen

asic_gen,

drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h

Quoted 1 line
drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h +0 -1
-						 enum amdgpu_pcie_gen

default_gen);

Quoted 13 lines
drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h +0 -1
-
  struct amd_vce_state*
  amdgpu_get_vce_clock_state(void *handle, u32 idx);
drivers/gpu/drm/amd/pm/powerplay/si_dpm.c +0 -0
index 81f82aa05ec2..4f84d8b893f1 100644
@@ -96,6 +96,19 @@ union pplib_clock_info {
  	struct _ATOM_PPLIB_SI_CLOCK_INFO si;
  };
 
Quoted 15 lines

drivers/gpu/drm/amd/pm/powerplay/si_dpm.c union pplib_clock_info { · line 111

Quoted 12 lines
drivers/gpu/drm/amd/pm/powerplay/si_dpm.c +12 -0
+enum amdgpu_dpm_auto_throttle_src {
+	AMDGPU_DPM_AUTO_THROTTLE_SRC_THERMAL,
+	AMDGPU_DPM_AUTO_THROTTLE_SRC_EXTERNAL
+};
+
+enum amdgpu_dpm_event_src {
+	AMDGPU_DPM_EVENT_SRC_ANALOG = 0,
+	AMDGPU_DPM_EVENT_SRC_EXTERNAL = 1,
+	AMDGPU_DPM_EVENT_SRC_DIGITAL = 2,
+	AMDGPU_DPM_EVENT_SRC_ANALOG_OR_EXTERNAL = 3,
+	AMDGPU_DPM_EVENT_SRC_DIGIAL_OR_EXTERNAL = 4 };
+

Better to rename the enums also including amdgpu_pcie_gen if they are used only within si_dpm.

[Quan, Evan] Sure, will do that.

Thanks
Evan

Quoted 98 lines

Thanks,
Lijo

drivers/gpu/drm/amd/pm/powerplay/si_dpm.c static int si_populate_smc_initial_state(struct

Quoted 4 lines
drivers/gpu/drm/amd/pm/powerplay/si_dpm.c +0 -0
  static const u32 r600_utc[R600_PM_NUMBER_OF_TC] =
  {
  	R600_UTC_DFLT_00,
@@ -4927,6 +4940,31 @@ static int si_populate_smc_initial_state(struct

amdgpu_device *adev,

drivers/gpu/drm/amd/pm/powerplay/si_dpm.c static int si_populate_smc_initial_state(struct amdgpu_device *adev,

Quoted 4 lines
drivers/gpu/drm/amd/pm/powerplay/si_dpm.c +1 -0
  	return 0;
  }
 
+static enum amdgpu_pcie_gen si_gen_pcie_gen_support(struct

amdgpu_device *adev,

drivers/gpu/drm/amd/pm/powerplay/si_dpm.c static int si_populate_smc_initial_state(struct · line 4945

Quoted 2 lines
drivers/gpu/drm/amd/pm/powerplay/si_dpm.c +2 -0
+						    u32 sys_mask,
+						    enum amdgpu_pcie_gen

asic_gen,

drivers/gpu/drm/amd/pm/powerplay/si_dpm.c static int si_populate_smc_initial_state(struct · line 4946

Quoted 1 line
drivers/gpu/drm/amd/pm/powerplay/si_dpm.c +1 -0
+						    enum amdgpu_pcie_gen

default_gen) {

drivers/gpu/drm/amd/pm/powerplay/si_dpm.c static int si_populate_smc_initial_state(struct amdgpu_device *adev,

Quoted 9 lines
drivers/gpu/drm/amd/pm/powerplay/si_dpm.c +9 -0
+	switch (asic_gen) {
+	case AMDGPU_PCIE_GEN1:
+		return AMDGPU_PCIE_GEN1;
+	case AMDGPU_PCIE_GEN2:
+		return AMDGPU_PCIE_GEN2;
+	case AMDGPU_PCIE_GEN3:
+		return AMDGPU_PCIE_GEN3;
+	default:
+		if ((sys_mask & CAIL_PCIE_LINK_SPEED_SUPPORT_GEN3)

&&

drivers/gpu/drm/amd/pm/powerplay/si_dpm.c static int si_populate_smc_initial_state(struct amdgpu_device *adev,

Quoted 3 lines
drivers/gpu/drm/amd/pm/powerplay/si_dpm.c +3 -0
+		    (default_gen == AMDGPU_PCIE_GEN3))
+			return AMDGPU_PCIE_GEN3;
+		else if ((sys_mask &

CAIL_PCIE_LINK_SPEED_SUPPORT_GEN2) &&

drivers/gpu/drm/amd/pm/powerplay/si_dpm.c static int si_populate_smc_acpi_state(struct

Quoted 12 lines
drivers/gpu/drm/amd/pm/powerplay/si_dpm.c +8 -0
+			 (default_gen == AMDGPU_PCIE_GEN2))
+			return AMDGPU_PCIE_GEN2;
+		else
+			return AMDGPU_PCIE_GEN1;
+	}
+	return AMDGPU_PCIE_GEN1;
+}
+
  static int si_populate_smc_acpi_state(struct amdgpu_device *adev,
  				      SISLANDS_SMC_STATETABLE *table)
  {
@@ -4989,10 +5027,10 @@ static int si_populate_smc_acpi_state(struct

amdgpu_device *adev,

drivers/gpu/drm/amd/pm/powerplay/si_dpm.c static int si_populate_smc_acpi_state(struct amdgpu_device *adev,

Quoted 8 lines
drivers/gpu/drm/amd/pm/powerplay/si_dpm.c +0 -4
  							      &table-
 ACPIState.level.std_vddc);
  		}
  		table->ACPIState.level.gen2PCIE =
-			(u8)amdgpu_get_pcie_gen_support(adev,
-							si_pi->sys_pcie_mask,
-							si_pi->boot_pcie_gen,
-
	AMDGPU_PCIE_GEN1);

drivers/gpu/drm/amd/pm/powerplay/si_dpm.c static void si_parse_pplib_clock_info(struct

Quoted 8 lines
drivers/gpu/drm/amd/pm/powerplay/si_dpm.c +4 -0
+			(u8)si_gen_pcie_gen_support(adev,
+						    si_pi->sys_pcie_mask,
+						    si_pi->boot_pcie_gen,
+						    AMDGPU_PCIE_GEN1);
 
  		if (si_pi->vddc_phase_shed_control)

si_populate_phase_shedding_value(adev,

drivers/gpu/drm/amd/pm/powerplay/si_dpm.c +0 -0
@@ -7148,10 +7186,10 @@ static void si_parse_pplib_clock_info(struct

amdgpu_device *adev,

Quoted 34 lines
drivers/gpu/drm/amd/pm/powerplay/si_dpm.c +4 -4
  	pl->vddc = le16_to_cpu(clock_info->si.usVDDC);
  	pl->vddci = le16_to_cpu(clock_info->si.usVDDCI);
  	pl->flags = le32_to_cpu(clock_info->si.ulFlags);
-	pl->pcie_gen = amdgpu_get_pcie_gen_support(adev,
-						   si_pi->sys_pcie_mask,
-						   si_pi->boot_pcie_gen,
-						   clock_info->si.ucPCIEGen);
+	pl->pcie_gen = si_gen_pcie_gen_support(adev,
+					       si_pi->sys_pcie_mask,
+					       si_pi->boot_pcie_gen,
+					       clock_info->si.ucPCIEGen);
 
  	/* patch up vddc if necessary */
  	ret = si_get_leakage_voltage_from_leakage_index(adev, pl->vddc,
drivers/gpu/drm/amd/pm/powerplay/si_dpm.h +7 -0
index bc0be6818e21..8c267682eeef 100644
@@ -595,6 +595,13 @@ struct rv7xx_power_info {
  	RV770_SMC_STATETABLE smc_statetable;
  };
 
+enum amdgpu_pcie_gen {
+	AMDGPU_PCIE_GEN1 = 0,
+	AMDGPU_PCIE_GEN2 = 1,
+	AMDGPU_PCIE_GEN3 = 2,
+	AMDGPU_PCIE_GEN_INVALID = 0xffff
+};
+
  struct rv7xx_pl {
  	u32 sclk;
  	u32 mclk;
author
#15 lore raw

PATCH v2 6/17 drm/amd/pm: do not expose the API used internally only in kv_dpm.c

In reply to Evan Quan

Move it to kv_dpm.c instead.

Change-Id I554332b386491a79b7913f72786f1e2cb1f8165b

--
v1->v2:
- rename the API with "kv_" prefix(Alex)

---
 drivers/gpu/drm/amd/pm/amdgpu_dpm.c       | 23 ---------------------
 drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h   |  2 --
 drivers/gpu/drm/amd/pm/powerplay/kv_dpm.c | 25 ++++++++++++++++++++++-
 3 files changed, 24 insertions(+), 26 deletions(-)
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +0 -23
index fbfc07a83122..ecaf0081bc31 100644
@@ -209,29 +209,6 @@ static u32 amdgpu_dpm_get_vrefresh(struct amdgpu_device *adev)
 	return vrefresh;
 }
 
-bool amdgpu_is_internal_thermal_sensor(enum amdgpu_int_thermal_type sensor)
-{
-	switch (sensor) {
-	case THERMAL_TYPE_RV6XX:
-	case THERMAL_TYPE_RV770:
-	case THERMAL_TYPE_EVERGREEN:
-	case THERMAL_TYPE_SUMO:
-	case THERMAL_TYPE_NI:
-	case THERMAL_TYPE_SI:
-	case THERMAL_TYPE_CI:
-	case THERMAL_TYPE_KV:
-		return true;
-	case THERMAL_TYPE_ADT7473_WITH_INTERNAL:
-	case THERMAL_TYPE_EMC2103_WITH_INTERNAL:
-		return false; /* need special handling */
-	case THERMAL_TYPE_NONE:
-	case THERMAL_TYPE_EXTERNAL:
-	case THERMAL_TYPE_EXTERNAL_GPIO:
-	default:
-		return false;
-	}
-}
-
 union power_info {
 	struct _ATOM_POWERPLAY_INFO info;
 	struct _ATOM_POWERPLAY_INFO_V2 info_2;
drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h +0 -2
index f43b96dfe9d8..01120b302590 100644
@@ -374,8 +374,6 @@ u32 amdgpu_dpm_get_vblank_time(struct amdgpu_device *adev);
 int amdgpu_dpm_read_sensor(struct amdgpu_device *adev, enum amd_pp_sensors sensor,
 			   void *data, uint32_t *size);
 
-bool amdgpu_is_internal_thermal_sensor(enum amdgpu_int_thermal_type sensor);
-
 int amdgpu_get_platform_caps(struct amdgpu_device *adev);
 
 int amdgpu_parse_extended_power_table(struct amdgpu_device *adev);
drivers/gpu/drm/amd/pm/powerplay/kv_dpm.c +24 -1
index bcae42cef374..380a5336c74f 100644
@@ -1256,6 +1256,29 @@ static void kv_dpm_enable_bapm(void *handle, bool enable)
 	}
 }
 
+static bool kv_is_internal_thermal_sensor(enum amdgpu_int_thermal_type sensor)
+{
+	switch (sensor) {
+	case THERMAL_TYPE_RV6XX:
+	case THERMAL_TYPE_RV770:
+	case THERMAL_TYPE_EVERGREEN:
+	case THERMAL_TYPE_SUMO:
+	case THERMAL_TYPE_NI:
+	case THERMAL_TYPE_SI:
+	case THERMAL_TYPE_CI:
+	case THERMAL_TYPE_KV:
+		return true;
+	case THERMAL_TYPE_ADT7473_WITH_INTERNAL:
+	case THERMAL_TYPE_EMC2103_WITH_INTERNAL:
+		return false; /* need special handling */
+	case THERMAL_TYPE_NONE:
+	case THERMAL_TYPE_EXTERNAL:
+	case THERMAL_TYPE_EXTERNAL_GPIO:
+	default:
+		return false;
+	}
+}
+
 static int kv_dpm_enable(struct amdgpu_device *adev)
 {
 	struct kv_power_info *pi = kv_get_pi(adev);
@@ -1352,7 +1375,7 @@ static int kv_dpm_enable(struct amdgpu_device *adev)
 	}
 
 	if (adev->irq.installed &&
-	    amdgpu_is_internal_thermal_sensor(adev->pm.int_thermal_type)) {
+	    kv_is_internal_thermal_sensor(adev->pm.int_thermal_type)) {
 		ret = kv_set_thermal_temperature_range(adev, KV_TEMP_RANGE_MIN, KV_TEMP_RANGE_MAX);
 		if (ret) {
 			DRM_ERROR("kv_set_thermal_temperature_range failed\n");
Signature · 1 line
2.29.0
#16 lore raw

Re: [PATCH V2 06/17] drm/amd/pm: do not expose the API used internally only in kv_dpm.c

Quoted 80 lines · Evan Quan

Move it to kv_dpm.c instead.

Change-Id I554332b386491a79b7913f72786f1e2cb1f8165b

--
v1->v2:
- rename the API with "kv_" prefix(Alex)

---
  drivers/gpu/drm/amd/pm/amdgpu_dpm.c       | 23 ---------------------
  drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h   |  2 --
  drivers/gpu/drm/amd/pm/powerplay/kv_dpm.c | 25 ++++++++++++++++++++++-
  3 files changed, 24 insertions(+), 26 deletions(-)
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +0 -23
index fbfc07a83122..ecaf0081bc31 100644
@@ -209,29 +209,6 @@ static u32 amdgpu_dpm_get_vrefresh(struct amdgpu_device *adev)
  	return vrefresh;
  }
 
-bool amdgpu_is_internal_thermal_sensor(enum amdgpu_int_thermal_type sensor)
-{
-	switch (sensor) {
-	case THERMAL_TYPE_RV6XX:
-	case THERMAL_TYPE_RV770:
-	case THERMAL_TYPE_EVERGREEN:
-	case THERMAL_TYPE_SUMO:
-	case THERMAL_TYPE_NI:
-	case THERMAL_TYPE_SI:
-	case THERMAL_TYPE_CI:
-	case THERMAL_TYPE_KV:
-		return true;
-	case THERMAL_TYPE_ADT7473_WITH_INTERNAL:
-	case THERMAL_TYPE_EMC2103_WITH_INTERNAL:
-		return false; /* need special handling */
-	case THERMAL_TYPE_NONE:
-	case THERMAL_TYPE_EXTERNAL:
-	case THERMAL_TYPE_EXTERNAL_GPIO:
-	default:
-		return false;
-	}
-}
-
  union power_info {
  	struct _ATOM_POWERPLAY_INFO info;
  	struct _ATOM_POWERPLAY_INFO_V2 info_2;
drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h +0 -2
index f43b96dfe9d8..01120b302590 100644
@@ -374,8 +374,6 @@ u32 amdgpu_dpm_get_vblank_time(struct amdgpu_device *adev);
  int amdgpu_dpm_read_sensor(struct amdgpu_device *adev, enum amd_pp_sensors sensor,
  			   void *data, uint32_t *size);
 
-bool amdgpu_is_internal_thermal_sensor(enum amdgpu_int_thermal_type sensor);
-
  int amdgpu_get_platform_caps(struct amdgpu_device *adev);
 
  int amdgpu_parse_extended_power_table(struct amdgpu_device *adev);
drivers/gpu/drm/amd/pm/powerplay/kv_dpm.c +12 -0
index bcae42cef374..380a5336c74f 100644
@@ -1256,6 +1256,29 @@ static void kv_dpm_enable_bapm(void *handle, bool enable)
  	}
  }
 
+static bool kv_is_internal_thermal_sensor(enum amdgpu_int_thermal_type sensor)
+{
+	switch (sensor) {
+	case THERMAL_TYPE_RV6XX:
+	case THERMAL_TYPE_RV770:
+	case THERMAL_TYPE_EVERGREEN:
+	case THERMAL_TYPE_SUMO:
+	case THERMAL_TYPE_NI:
+	case THERMAL_TYPE_SI:
+	case THERMAL_TYPE_CI:
+	case THERMAL_TYPE_KV:
+		return true;

drivers/gpu/drm/amd/pm/powerplay/kv_dpm.c static void kv_dpm_enable_bapm(void *handle, bool enable) · line 1280

Quoted 10 lines
drivers/gpu/drm/amd/pm/powerplay/kv_dpm.c +10 -0
+	case THERMAL_TYPE_ADT7473_WITH_INTERNAL:
+	case THERMAL_TYPE_EMC2103_WITH_INTERNAL:
+		return false; /* need special handling */
+	case THERMAL_TYPE_NONE:
+	case THERMAL_TYPE_EXTERNAL:
+	case THERMAL_TYPE_EXTERNAL_GPIO:
+	default:
+		return false;
+	}
+}

All these names don't look like KV specific. Remove the family specifc ones like RV, SI, NI, CI etc., and keep KV and the generic ones like GPIO/EXTERNAL/NONE. Don't see a chance of external diodes being used for KV.

Thanks,
Lijo

Quoted 14 lines
drivers/gpu/drm/amd/pm/powerplay/kv_dpm.c +2 -1
+
  static int kv_dpm_enable(struct amdgpu_device *adev)
  {
  	struct kv_power_info *pi = kv_get_pi(adev);
@@ -1352,7 +1375,7 @@ static int kv_dpm_enable(struct amdgpu_device *adev)
  	}
 
  	if (adev->irq.installed &&
-	    amdgpu_is_internal_thermal_sensor(adev->pm.int_thermal_type)) {
+	    kv_is_internal_thermal_sensor(adev->pm.int_thermal_type)) {
  		ret = kv_set_thermal_temperature_range(adev, KV_TEMP_RANGE_MIN, KV_TEMP_RANGE_MAX);
  		if (ret) {
  			DRM_ERROR("kv_set_thermal_temperature_range failed\n");
author
#17 lore raw

RE: [PATCH V2 06/17] drm/amd/pm: do not expose the API used internally only in kv_dpm.c

[AMD Official Use Only]

Quoted 111 lines

-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Lazar, Lijo
Sent: Tuesday, November 30, 2021 8:28 PM
To: Quan, Evan <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>; Feng, Kenneth <[email protected]>; Koenig, Christian <[email protected]>
Subject: Re: [PATCH V2 06/17] drm/amd/pm: do not expose the API used internally only in kv_dpm.c

Quoted 11 lines · Evan Quan

Move it to kv_dpm.c instead.

Change-Id I554332b386491a79b7913f72786f1e2cb1f8165b

--
v1->v2:
- rename the API with "kv_" prefix(Alex)

---
  drivers/gpu/drm/amd/pm/amdgpu_dpm.c       | 23 ---------------------
  drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h   |  2 --
  drivers/gpu/drm/amd/pm/powerplay/kv_dpm.c | 25

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

drivers/gpu/drm/amd/pm/amdgpu_dpm.c static u32 amdgpu_dpm_get_vrefresh(struct

Quoted 8 lines
  3 files changed, 24 insertions(+), 26 deletions(-)
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +0 -0
index fbfc07a83122..ecaf0081bc31 100644
@@ -209,29 +209,6 @@ static u32 amdgpu_dpm_get_vrefresh(struct

amdgpu_device *adev)

drivers/gpu/drm/amd/pm/amdgpu_dpm.c static u32 amdgpu_dpm_get_vrefresh(struct amdgpu_device *adev)

Quoted 4 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +0 -1
  	return vrefresh;
  }
 
-bool amdgpu_is_internal_thermal_sensor(enum

amdgpu_int_thermal_type

drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h u32 amdgpu_dpm_get_vblank_time(struct

Quoted 31 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +0 -21
 sensor) -{
-	switch (sensor) {
-	case THERMAL_TYPE_RV6XX:
-	case THERMAL_TYPE_RV770:
-	case THERMAL_TYPE_EVERGREEN:
-	case THERMAL_TYPE_SUMO:
-	case THERMAL_TYPE_NI:
-	case THERMAL_TYPE_SI:
-	case THERMAL_TYPE_CI:
-	case THERMAL_TYPE_KV:
-		return true;
-	case THERMAL_TYPE_ADT7473_WITH_INTERNAL:
-	case THERMAL_TYPE_EMC2103_WITH_INTERNAL:
-		return false; /* need special handling */
-	case THERMAL_TYPE_NONE:
-	case THERMAL_TYPE_EXTERNAL:
-	case THERMAL_TYPE_EXTERNAL_GPIO:
-	default:
-		return false;
-	}
-}
-
  union power_info {
  	struct _ATOM_POWERPLAY_INFO info;
  	struct _ATOM_POWERPLAY_INFO_V2 info_2; diff --git

a/drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h
b/drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h
index f43b96dfe9d8..01120b302590 100644

drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h +0 -0
@@ -374,8 +374,6 @@ u32 amdgpu_dpm_get_vblank_time(struct

amdgpu_device *adev);

drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h u32 amdgpu_dpm_get_vblank_time(struct · line 374

Quoted 1 line
drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h +0 -0
  int amdgpu_dpm_read_sensor(struct amdgpu_device *adev, enum

amd_pp_sensors sensor,

drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h u32 amdgpu_dpm_get_vblank_time(struct amdgpu_device *adev);

Quoted 3 lines
drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h +0 -1
  			   void *data, uint32_t *size);
 
-bool amdgpu_is_internal_thermal_sensor(enum

amdgpu_int_thermal_type

drivers/gpu/drm/amd/pm/powerplay/kv_dpm.c static void kv_dpm_enable_bapm(void *handle,

Quoted 11 lines
drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h +0 -1
 sensor);
-
  int amdgpu_get_platform_caps(struct amdgpu_device *adev);
 
  int amdgpu_parse_extended_power_table(struct amdgpu_device *adev);
drivers/gpu/drm/amd/pm/powerplay/kv_dpm.c +0 -0
index bcae42cef374..380a5336c74f 100644
@@ -1256,6 +1256,29 @@ static void kv_dpm_enable_bapm(void *handle,

bool enable)

Quoted 22 lines
drivers/gpu/drm/amd/pm/powerplay/kv_dpm.c +19 -0
  	}
  }
 
+static bool kv_is_internal_thermal_sensor(enum
+amdgpu_int_thermal_type sensor) {
+	switch (sensor) {
+	case THERMAL_TYPE_RV6XX:
+	case THERMAL_TYPE_RV770:
+	case THERMAL_TYPE_EVERGREEN:
+	case THERMAL_TYPE_SUMO:
+	case THERMAL_TYPE_NI:
+	case THERMAL_TYPE_SI:
+	case THERMAL_TYPE_CI:
+	case THERMAL_TYPE_KV:
+		return true;
+	case THERMAL_TYPE_ADT7473_WITH_INTERNAL:
+	case THERMAL_TYPE_EMC2103_WITH_INTERNAL:
+		return false; /* need special handling */
+	case THERMAL_TYPE_NONE:
+	case THERMAL_TYPE_EXTERNAL:
+	case THERMAL_TYPE_EXTERNAL_GPIO:
+	default:
Quoted 8 lines

drivers/gpu/drm/amd/pm/powerplay/kv_dpm.c static void kv_dpm_enable_bapm(void *handle, bool enable) · line 1280

Quoted 3 lines
drivers/gpu/drm/amd/pm/powerplay/kv_dpm.c +3 -0
+		return false;
+	}
+}

All these names don't look like KV specific. Remove the family specifc ones like RV, SI, NI, CI etc., and keep KV and the generic ones like GPIO/EXTERNAL/NONE. Don't see a chance of external diodes being used for KV.

[Quan, Evan] Make sense. I will create another patch to follow this. Let's keep minimum change here.

Thanks,
Evan

Quoted 22 lines

Thanks,
Lijo

drivers/gpu/drm/amd/pm/powerplay/kv_dpm.c static void kv_dpm_enable_bapm(void *handle, bool enable)

Quoted 4 lines
drivers/gpu/drm/amd/pm/powerplay/kv_dpm.c +1 -0
+
  static int kv_dpm_enable(struct amdgpu_device *adev)
  {
  	struct kv_power_info *pi = kv_get_pi(adev); @@ -1352,7 +1375,7

@@

drivers/gpu/drm/amd/pm/powerplay/kv_dpm.c

Quoted 8 lines

static int kv_dpm_enable(struct amdgpu_device *adev)
}

if (adev->irq.installed &&

drivers/gpu/drm/amd/pm/powerplay/kv_dpm.c +0 -1
-	    amdgpu_is_internal_thermal_sensor(adev-

pm.int_thermal_type)) {

drivers/gpu/drm/amd/pm/powerplay/kv_dpm.c +1 -0
+	    kv_is_internal_thermal_sensor(adev->pm.int_thermal_type)) {
  		ret = kv_set_thermal_temperature_range(adev,

KV_TEMP_RANGE_MIN, KV_TEMP_RANGE_MAX);

Quoted 2 lines
  		if (ret) {
  			DRM_ERROR("kv_set_thermal_temperature_range

failed\n");

Quoted 1 line
author
#18 lore raw

PATCH v2 7/17 drm/amd/pm: create a new holder for those APIs used only by legacy ASICs(si/kv)

In reply to Evan Quan

Those APIs are used only by legacy ASICs(si/kv). They cannot be shared by other ASICs. So, we create a new holder for them.

Change-Id I555dfa37e783a267b1d3b3a7db5c87fcc3f1556f

--
v1->v2:
- move other APIs used by si/kv in amdgpu_atombios.c to the new holder also(Alex)

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_atombios.c  |  421 -----
 drivers/gpu/drm/amd/amdgpu/amdgpu_atombios.h  |   30 -
 .../gpu/drm/amd/include/kgd_pp_interface.h    |    1 +
 drivers/gpu/drm/amd/pm/amdgpu_dpm.c           | 1008 +-----------
 drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h       |   15 -
 drivers/gpu/drm/amd/pm/powerplay/Makefile     |    2 +-
 drivers/gpu/drm/amd/pm/powerplay/kv_dpm.c     |    2 +
 drivers/gpu/drm/amd/pm/powerplay/legacy_dpm.c | 1453 +++++++++++++++++
 drivers/gpu/drm/amd/pm/powerplay/legacy_dpm.h |   70 +
 drivers/gpu/drm/amd/pm/powerplay/si_dpm.c     |    2 +
 10 files changed, 1534 insertions(+), 1470 deletions(-)
 create mode 100644 drivers/gpu/drm/amd/pm/powerplay/legacy_dpm.c
 create mode 100644 drivers/gpu/drm/amd/pm/powerplay/legacy_dpm.h
drivers/gpu/drm/amd/amdgpu/amdgpu_atombios.c +0 -421
index 12a6b1c99c93..f2e447212e62 100644
@@ -1083,427 +1083,6 @@ int amdgpu_atombios_get_clock_dividers(struct amdgpu_device *adev,
 	return 0;
 }
 
-int amdgpu_atombios_get_memory_pll_dividers(struct amdgpu_device *adev,
-					    u32 clock,
-					    bool strobe_mode,
-					    struct atom_mpll_param *mpll_param)
-{
-	COMPUTE_MEMORY_CLOCK_PARAM_PARAMETERS_V2_1 args;
-	int index = GetIndexIntoMasterTable(COMMAND, ComputeMemoryClockParam);
-	u8 frev, crev;
-
-	memset(&args, 0, sizeof(args));
-	memset(mpll_param, 0, sizeof(struct atom_mpll_param));
-
-	if (!amdgpu_atom_parse_cmd_header(adev->mode_info.atom_context, index, &frev, &crev))
-		return -EINVAL;
-
-	switch (frev) {
-	case 2:
-		switch (crev) {
-		case 1:
-			/* SI */
-			args.ulClock = cpu_to_le32(clock);	/* 10 khz */
-			args.ucInputFlag = 0;
-			if (strobe_mode)
-				args.ucInputFlag |= MPLL_INPUT_FLAG_STROBE_MODE_EN;
-
-			amdgpu_atom_execute_table(adev->mode_info.atom_context, index, (uint32_t *)&args);
-
-			mpll_param->clkfrac = le16_to_cpu(args.ulFbDiv.usFbDivFrac);
-			mpll_param->clkf = le16_to_cpu(args.ulFbDiv.usFbDiv);
-			mpll_param->post_div = args.ucPostDiv;
-			mpll_param->dll_speed = args.ucDllSpeed;
-			mpll_param->bwcntl = args.ucBWCntl;
-			mpll_param->vco_mode =
-				(args.ucPllCntlFlag & MPLL_CNTL_FLAG_VCO_MODE_MASK);
-			mpll_param->yclk_sel =
-				(args.ucPllCntlFlag & MPLL_CNTL_FLAG_BYPASS_DQ_PLL) ? 1 : 0;
-			mpll_param->qdr =
-				(args.ucPllCntlFlag & MPLL_CNTL_FLAG_QDR_ENABLE) ? 1 : 0;
-			mpll_param->half_rate =
-				(args.ucPllCntlFlag & MPLL_CNTL_FLAG_AD_HALF_RATE) ? 1 : 0;
-			break;
-		default:
-			return -EINVAL;
-		}
-		break;
-	default:
-		return -EINVAL;
-	}
-	return 0;
-}
-
-void amdgpu_atombios_set_engine_dram_timings(struct amdgpu_device *adev,
-					     u32 eng_clock, u32 mem_clock)
-{
-	SET_ENGINE_CLOCK_PS_ALLOCATION args;
-	int index = GetIndexIntoMasterTable(COMMAND, DynamicMemorySettings);
-	u32 tmp;
-
-	memset(&args, 0, sizeof(args));
-
-	tmp = eng_clock & SET_CLOCK_FREQ_MASK;
-	tmp |= (COMPUTE_ENGINE_PLL_PARAM << 24);
-
-	args.ulTargetEngineClock = cpu_to_le32(tmp);
-	if (mem_clock)
-		args.sReserved.ulClock = cpu_to_le32(mem_clock & SET_CLOCK_FREQ_MASK);
-
-	amdgpu_atom_execute_table(adev->mode_info.atom_context, index, (uint32_t *)&args);
-}
-
-void amdgpu_atombios_get_default_voltages(struct amdgpu_device *adev,
-					  u16 *vddc, u16 *vddci, u16 *mvdd)
-{
-	struct amdgpu_mode_info *mode_info = &adev->mode_info;
-	int index = GetIndexIntoMasterTable(DATA, FirmwareInfo);
-	u8 frev, crev;
-	u16 data_offset;
-	union firmware_info *firmware_info;
-
-	*vddc = 0;
-	*vddci = 0;
-	*mvdd = 0;
-
-	if (amdgpu_atom_parse_data_header(mode_info->atom_context, index, NULL,
-				   &frev, &crev, &data_offset)) {
-		firmware_info =
-			(union firmware_info *)(mode_info->atom_context->bios +
-						data_offset);
-		*vddc = le16_to_cpu(firmware_info->info_14.usBootUpVDDCVoltage);
-		if ((frev == 2) && (crev >= 2)) {
-			*vddci = le16_to_cpu(firmware_info->info_22.usBootUpVDDCIVoltage);
-			*mvdd = le16_to_cpu(firmware_info->info_22.usBootUpMVDDCVoltage);
-		}
-	}
-}
-
-union set_voltage {
-	struct _SET_VOLTAGE_PS_ALLOCATION alloc;
-	struct _SET_VOLTAGE_PARAMETERS v1;
-	struct _SET_VOLTAGE_PARAMETERS_V2 v2;
-	struct _SET_VOLTAGE_PARAMETERS_V1_3 v3;
-};
-
-int amdgpu_atombios_get_max_vddc(struct amdgpu_device *adev, u8 voltage_type,
-			     u16 voltage_id, u16 *voltage)
-{
-	union set_voltage args;
-	int index = GetIndexIntoMasterTable(COMMAND, SetVoltage);
-	u8 frev, crev;
-
-	if (!amdgpu_atom_parse_cmd_header(adev->mode_info.atom_context, index, &frev, &crev))
-		return -EINVAL;
-
-	switch (crev) {
-	case 1:
-		return -EINVAL;
-	case 2:
-		args.v2.ucVoltageType = SET_VOLTAGE_GET_MAX_VOLTAGE;
-		args.v2.ucVoltageMode = 0;
-		args.v2.usVoltageLevel = 0;
-
-		amdgpu_atom_execute_table(adev->mode_info.atom_context, index, (uint32_t *)&args);
-
-		*voltage = le16_to_cpu(args.v2.usVoltageLevel);
-		break;
-	case 3:
-		args.v3.ucVoltageType = voltage_type;
-		args.v3.ucVoltageMode = ATOM_GET_VOLTAGE_LEVEL;
-		args.v3.usVoltageLevel = cpu_to_le16(voltage_id);
-
-		amdgpu_atom_execute_table(adev->mode_info.atom_context, index, (uint32_t *)&args);
-
-		*voltage = le16_to_cpu(args.v3.usVoltageLevel);
-		break;
-	default:
-		DRM_ERROR("Unknown table version %d, %d\n", frev, crev);
-		return -EINVAL;
-	}
-
-	return 0;
-}
-
-int amdgpu_atombios_get_leakage_vddc_based_on_leakage_idx(struct amdgpu_device *adev,
-						      u16 *voltage,
-						      u16 leakage_idx)
-{
-	return amdgpu_atombios_get_max_vddc(adev, VOLTAGE_TYPE_VDDC, leakage_idx, voltage);
-}
-
-union voltage_object_info {
-	struct _ATOM_VOLTAGE_OBJECT_INFO v1;
-	struct _ATOM_VOLTAGE_OBJECT_INFO_V2 v2;
-	struct _ATOM_VOLTAGE_OBJECT_INFO_V3_1 v3;
-};
-
-union voltage_object {
-	struct _ATOM_VOLTAGE_OBJECT v1;
-	struct _ATOM_VOLTAGE_OBJECT_V2 v2;
-	union _ATOM_VOLTAGE_OBJECT_V3 v3;
-};
-
-
-static ATOM_VOLTAGE_OBJECT_V3 *amdgpu_atombios_lookup_voltage_object_v3(ATOM_VOLTAGE_OBJECT_INFO_V3_1 *v3,
-									u8 voltage_type, u8 voltage_mode)
-{
-	u32 size = le16_to_cpu(v3->sHeader.usStructureSize);
-	u32 offset = offsetof(ATOM_VOLTAGE_OBJECT_INFO_V3_1, asVoltageObj[0]);
-	u8 *start = (u8 *)v3;
-
-	while (offset < size) {
-		ATOM_VOLTAGE_OBJECT_V3 *vo = (ATOM_VOLTAGE_OBJECT_V3 *)(start + offset);
-		if ((vo->asGpioVoltageObj.sHeader.ucVoltageType == voltage_type) &&
-		    (vo->asGpioVoltageObj.sHeader.ucVoltageMode == voltage_mode))
-			return vo;
-		offset += le16_to_cpu(vo->asGpioVoltageObj.sHeader.usSize);
-	}
-	return NULL;
-}
-
-int amdgpu_atombios_get_svi2_info(struct amdgpu_device *adev,
-			      u8 voltage_type,
-			      u8 *svd_gpio_id, u8 *svc_gpio_id)
-{
-	int index = GetIndexIntoMasterTable(DATA, VoltageObjectInfo);
-	u8 frev, crev;
-	u16 data_offset, size;
-	union voltage_object_info *voltage_info;
-	union voltage_object *voltage_object = NULL;
-
-	if (amdgpu_atom_parse_data_header(adev->mode_info.atom_context, index, &size,
-				   &frev, &crev, &data_offset)) {
-		voltage_info = (union voltage_object_info *)
-			(adev->mode_info.atom_context->bios + data_offset);
-
-		switch (frev) {
-		case 3:
-			switch (crev) {
-			case 1:
-				voltage_object = (union voltage_object *)
-					amdgpu_atombios_lookup_voltage_object_v3(&voltage_info->v3,
-								      voltage_type,
-								      VOLTAGE_OBJ_SVID2);
-				if (voltage_object) {
-					*svd_gpio_id = voltage_object->v3.asSVID2Obj.ucSVDGpioId;
-					*svc_gpio_id = voltage_object->v3.asSVID2Obj.ucSVCGpioId;
-				} else {
-					return -EINVAL;
-				}
-				break;
-			default:
-				DRM_ERROR("unknown voltage object table\n");
-				return -EINVAL;
-			}
-			break;
-		default:
-			DRM_ERROR("unknown voltage object table\n");
-			return -EINVAL;
-		}
-
-	}
-	return 0;
-}
-
-bool
-amdgpu_atombios_is_voltage_gpio(struct amdgpu_device *adev,
-				u8 voltage_type, u8 voltage_mode)
-{
-	int index = GetIndexIntoMasterTable(DATA, VoltageObjectInfo);
-	u8 frev, crev;
-	u16 data_offset, size;
-	union voltage_object_info *voltage_info;
-
-	if (amdgpu_atom_parse_data_header(adev->mode_info.atom_context, index, &size,
-				   &frev, &crev, &data_offset)) {
-		voltage_info = (union voltage_object_info *)
-			(adev->mode_info.atom_context->bios + data_offset);
-
-		switch (frev) {
-		case 3:
-			switch (crev) {
-			case 1:
-				if (amdgpu_atombios_lookup_voltage_object_v3(&voltage_info->v3,
-								  voltage_type, voltage_mode))
-					return true;
-				break;
-			default:
-				DRM_ERROR("unknown voltage object table\n");
-				return false;
-			}
-			break;
-		default:
-			DRM_ERROR("unknown voltage object table\n");
-			return false;
-		}
-
-	}
-	return false;
-}
-
-int amdgpu_atombios_get_voltage_table(struct amdgpu_device *adev,
-				      u8 voltage_type, u8 voltage_mode,
-				      struct atom_voltage_table *voltage_table)
-{
-	int index = GetIndexIntoMasterTable(DATA, VoltageObjectInfo);
-	u8 frev, crev;
-	u16 data_offset, size;
-	int i;
-	union voltage_object_info *voltage_info;
-	union voltage_object *voltage_object = NULL;
-
-	if (amdgpu_atom_parse_data_header(adev->mode_info.atom_context, index, &size,
-				   &frev, &crev, &data_offset)) {
-		voltage_info = (union voltage_object_info *)
-			(adev->mode_info.atom_context->bios + data_offset);
-
-		switch (frev) {
-		case 3:
-			switch (crev) {
-			case 1:
-				voltage_object = (union voltage_object *)
-					amdgpu_atombios_lookup_voltage_object_v3(&voltage_info->v3,
-								      voltage_type, voltage_mode);
-				if (voltage_object) {
-					ATOM_GPIO_VOLTAGE_OBJECT_V3 *gpio =
-						&voltage_object->v3.asGpioVoltageObj;
-					VOLTAGE_LUT_ENTRY_V2 *lut;
-					if (gpio->ucGpioEntryNum > MAX_VOLTAGE_ENTRIES)
-						return -EINVAL;
-					lut = &gpio->asVolGpioLut[0];
-					for (i = 0; i < gpio->ucGpioEntryNum; i++) {
-						voltage_table->entries[i].value =
-							le16_to_cpu(lut->usVoltageValue);
-						voltage_table->entries[i].smio_low =
-							le32_to_cpu(lut->ulVoltageId);
-						lut = (VOLTAGE_LUT_ENTRY_V2 *)
-							((u8 *)lut + sizeof(VOLTAGE_LUT_ENTRY_V2));
-					}
-					voltage_table->mask_low = le32_to_cpu(gpio->ulGpioMaskVal);
-					voltage_table->count = gpio->ucGpioEntryNum;
-					voltage_table->phase_delay = gpio->ucPhaseDelay;
-					return 0;
-				}
-				break;
-			default:
-				DRM_ERROR("unknown voltage object table\n");
-				return -EINVAL;
-			}
-			break;
-		default:
-			DRM_ERROR("unknown voltage object table\n");
-			return -EINVAL;
-		}
-	}
-	return -EINVAL;
-}
-
-union vram_info {
-	struct _ATOM_VRAM_INFO_V3 v1_3;
-	struct _ATOM_VRAM_INFO_V4 v1_4;
-	struct _ATOM_VRAM_INFO_HEADER_V2_1 v2_1;
-};
-
-#define MEM_ID_MASK           0xff000000
-#define MEM_ID_SHIFT          24
-#define CLOCK_RANGE_MASK      0x00ffffff
-#define CLOCK_RANGE_SHIFT     0
-#define LOW_NIBBLE_MASK       0xf
-#define DATA_EQU_PREV         0
-#define DATA_FROM_TABLE       4
-
-int amdgpu_atombios_init_mc_reg_table(struct amdgpu_device *adev,
-				      u8 module_index,
-				      struct atom_mc_reg_table *reg_table)
-{
-	int index = GetIndexIntoMasterTable(DATA, VRAM_Info);
-	u8 frev, crev, num_entries, t_mem_id, num_ranges = 0;
-	u32 i = 0, j;
-	u16 data_offset, size;
-	union vram_info *vram_info;
-
-	memset(reg_table, 0, sizeof(struct atom_mc_reg_table));
-
-	if (amdgpu_atom_parse_data_header(adev->mode_info.atom_context, index, &size,
-				   &frev, &crev, &data_offset)) {
-		vram_info = (union vram_info *)
-			(adev->mode_info.atom_context->bios + data_offset);
-		switch (frev) {
-		case 1:
-			DRM_ERROR("old table version %d, %d\n", frev, crev);
-			return -EINVAL;
-		case 2:
-			switch (crev) {
-			case 1:
-				if (module_index < vram_info->v2_1.ucNumOfVRAMModule) {
-					ATOM_INIT_REG_BLOCK *reg_block =
-						(ATOM_INIT_REG_BLOCK *)
-						((u8 *)vram_info + le16_to_cpu(vram_info->v2_1.usMemClkPatchTblOffset));
-					ATOM_MEMORY_SETTING_DATA_BLOCK *reg_data =
-						(ATOM_MEMORY_SETTING_DATA_BLOCK *)
-						((u8 *)reg_block + (2 * sizeof(u16)) +
-						 le16_to_cpu(reg_block->usRegIndexTblSize));
-					ATOM_INIT_REG_INDEX_FORMAT *format = &reg_block->asRegIndexBuf[0];
-					num_entries = (u8)((le16_to_cpu(reg_block->usRegIndexTblSize)) /
-							   sizeof(ATOM_INIT_REG_INDEX_FORMAT)) - 1;
-					if (num_entries > VBIOS_MC_REGISTER_ARRAY_SIZE)
-						return -EINVAL;
-					while (i < num_entries) {
-						if (format->ucPreRegDataLength & ACCESS_PLACEHOLDER)
-							break;
-						reg_table->mc_reg_address[i].s1 =
-							(u16)(le16_to_cpu(format->usRegIndex));
-						reg_table->mc_reg_address[i].pre_reg_data =
-							(u8)(format->ucPreRegDataLength);
-						i++;
-						format = (ATOM_INIT_REG_INDEX_FORMAT *)
-							((u8 *)format + sizeof(ATOM_INIT_REG_INDEX_FORMAT));
-					}
-					reg_table->last = i;
-					while ((le32_to_cpu(*(u32 *)reg_data) != END_OF_REG_DATA_BLOCK) &&
-					       (num_ranges < VBIOS_MAX_AC_TIMING_ENTRIES)) {
-						t_mem_id = (u8)((le32_to_cpu(*(u32 *)reg_data) & MEM_ID_MASK)
-								>> MEM_ID_SHIFT);
-						if (module_index == t_mem_id) {
-							reg_table->mc_reg_table_entry[num_ranges].mclk_max =
-								(u32)((le32_to_cpu(*(u32 *)reg_data) & CLOCK_RANGE_MASK)
-								      >> CLOCK_RANGE_SHIFT);
-							for (i = 0, j = 1; i < reg_table->last; i++) {
-								if ((reg_table->mc_reg_address[i].pre_reg_data & LOW_NIBBLE_MASK) == DATA_FROM_TABLE) {
-									reg_table->mc_reg_table_entry[num_ranges].mc_data[i] =
-										(u32)le32_to_cpu(*((u32 *)reg_data + j));
-									j++;
-								} else if ((reg_table->mc_reg_address[i].pre_reg_data & LOW_NIBBLE_MASK) == DATA_EQU_PREV) {
-									reg_table->mc_reg_table_entry[num_ranges].mc_data[i] =
-										reg_table->mc_reg_table_entry[num_ranges].mc_data[i - 1];
-								}
-							}
-							num_ranges++;
-						}
-						reg_data = (ATOM_MEMORY_SETTING_DATA_BLOCK *)
-							((u8 *)reg_data + le16_to_cpu(reg_block->usRegDataBlkSize));
-					}
-					if (le32_to_cpu(*(u32 *)reg_data) != END_OF_REG_DATA_BLOCK)
-						return -EINVAL;
-					reg_table->num_entries = num_ranges;
-				} else
-					return -EINVAL;
-				break;
-			default:
-				DRM_ERROR("Unknown table version %d, %d\n", frev, crev);
-				return -EINVAL;
-			}
-			break;
-		default:
-			DRM_ERROR("Unknown table version %d, %d\n", frev, crev);
-			return -EINVAL;
-		}
-		return 0;
-	}
-	return -EINVAL;
-}
-
 bool amdgpu_atombios_has_gpu_virtualization_table(struct amdgpu_device *adev)
 {
 	int index = GetIndexIntoMasterTable(DATA, GPUVirtualizationInfo);
drivers/gpu/drm/amd/amdgpu/amdgpu_atombios.h +0 -30
index 27e74b1fc260..cb5649298dcb 100644
@@ -160,26 +160,6 @@ int amdgpu_atombios_get_clock_dividers(struct amdgpu_device *adev,
 				       bool strobe_mode,
 				       struct atom_clock_dividers *dividers);
 
-int amdgpu_atombios_get_memory_pll_dividers(struct amdgpu_device *adev,
-					    u32 clock,
-					    bool strobe_mode,
-					    struct atom_mpll_param *mpll_param);
-
-void amdgpu_atombios_set_engine_dram_timings(struct amdgpu_device *adev,
-					     u32 eng_clock, u32 mem_clock);
-
-bool
-amdgpu_atombios_is_voltage_gpio(struct amdgpu_device *adev,
-				u8 voltage_type, u8 voltage_mode);
-
-int amdgpu_atombios_get_voltage_table(struct amdgpu_device *adev,
-				      u8 voltage_type, u8 voltage_mode,
-				      struct atom_voltage_table *voltage_table);
-
-int amdgpu_atombios_init_mc_reg_table(struct amdgpu_device *adev,
-				      u8 module_index,
-				      struct atom_mc_reg_table *reg_table);
-
 bool amdgpu_atombios_has_gpu_virtualization_table(struct amdgpu_device *adev);
 
 void amdgpu_atombios_scratch_regs_lock(struct amdgpu_device *adev, bool lock);
@@ -190,21 +170,11 @@ void amdgpu_atombios_scratch_regs_set_backlight_level(struct amdgpu_device *adev
 bool amdgpu_atombios_scratch_need_asic_init(struct amdgpu_device *adev);
 
 void amdgpu_atombios_copy_swap(u8 *dst, u8 *src, u8 num_bytes, bool to_le);
-int amdgpu_atombios_get_max_vddc(struct amdgpu_device *adev, u8 voltage_type,
-			     u16 voltage_id, u16 *voltage);
-int amdgpu_atombios_get_leakage_vddc_based_on_leakage_idx(struct amdgpu_device *adev,
-						      u16 *voltage,
-						      u16 leakage_idx);
-void amdgpu_atombios_get_default_voltages(struct amdgpu_device *adev,
-					  u16 *vddc, u16 *vddci, u16 *mvdd);
 int amdgpu_atombios_get_clock_dividers(struct amdgpu_device *adev,
 				       u8 clock_type,
 				       u32 clock,
 				       bool strobe_mode,
 				       struct atom_clock_dividers *dividers);
-int amdgpu_atombios_get_svi2_info(struct amdgpu_device *adev,
-			      u8 voltage_type,
-			      u8 *svd_gpio_id, u8 *svc_gpio_id);
 
 int amdgpu_atombios_get_data_table(struct amdgpu_device *adev,
 				   uint32_t table,
drivers/gpu/drm/amd/include/kgd_pp_interface.h +1 -0
index 2e295facd086..cdf724dcf832 100644
@@ -404,6 +404,7 @@ struct amd_pm_funcs {
 	int (*get_dpm_clock_table)(void *handle,
 				   struct dpm_clocks *clock_table);
 	int (*get_smu_prv_buf_details)(void *handle, void **addr, size_t *size);
+	int (*change_power_state)(void *handle);
 };
 
 struct metrics_table_header {
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +5 -1003

1,056 lines not on this page · raw message

drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h +0 -15
index 01120b302590..295d2902aef7 100644
@@ -366,24 +366,10 @@ enum amdgpu_display_gap
     AMDGPU_PM_DISPLAY_GAP_IGNORE       = 3,
 };
 
-void amdgpu_dpm_print_class_info(u32 class, u32 class2);
-void amdgpu_dpm_print_cap_info(u32 caps);
-void amdgpu_dpm_print_ps_status(struct amdgpu_device *adev,
-				struct amdgpu_ps *rps);
 u32 amdgpu_dpm_get_vblank_time(struct amdgpu_device *adev);
 int amdgpu_dpm_read_sensor(struct amdgpu_device *adev, enum amd_pp_sensors sensor,
 			   void *data, uint32_t *size);
 
-int amdgpu_get_platform_caps(struct amdgpu_device *adev);
-
-int amdgpu_parse_extended_power_table(struct amdgpu_device *adev);
-void amdgpu_free_extended_power_table(struct amdgpu_device *adev);
-
-void amdgpu_add_thermal_controller(struct amdgpu_device *adev);
-
-struct amd_vce_state*
-amdgpu_get_vce_clock_state(void *handle, u32 idx);
-
 int amdgpu_dpm_set_powergating_by_smu(struct amdgpu_device *adev,
 				      uint32_t block_type, bool gate);
 
@@ -438,7 +424,6 @@ void amdgpu_pm_compute_clocks(struct amdgpu_device *adev);
 void amdgpu_dpm_enable_uvd(struct amdgpu_device *adev, bool enable);
 void amdgpu_dpm_enable_vce(struct amdgpu_device *adev, bool enable);
 void amdgpu_dpm_enable_jpeg(struct amdgpu_device *adev, bool enable);
-void amdgpu_pm_print_power_states(struct amdgpu_device *adev);
 int amdgpu_pm_load_smu_firmware(struct amdgpu_device *adev, uint32_t *smu_version);
 int amdgpu_dpm_set_light_sbr(struct amdgpu_device *adev, bool enable);
 int amdgpu_dpm_send_hbm_bad_pages_num(struct amdgpu_device *adev, uint32_t size);
drivers/gpu/drm/amd/pm/powerplay/Makefile +1 -1
index 0fb114adc79f..614d8b6a58ad 100644
@@ -28,7 +28,7 @@ AMD_POWERPLAY = $(addsuffix /Makefile,$(addprefix $(FULL_AMD_PATH)/pm/powerplay/
 
 include $(AMD_POWERPLAY)
 
-POWER_MGR-y = amd_powerplay.o
+POWER_MGR-y = amd_powerplay.o legacy_dpm.o
 
 POWER_MGR-$(CONFIG_DRM_AMDGPU_CIK)+= kv_dpm.o kv_smc.o
 
drivers/gpu/drm/amd/pm/powerplay/kv_dpm.c +2 -0
index 380a5336c74f..90f4c65659e2 100644
@@ -36,6 +36,7 @@
 
 #include "gca/gfx_7_2_d.h"
 #include "gca/gfx_7_2_sh_mask.h"
+#include "legacy_dpm.h"
 
 #define KV_MAX_DEEPSLEEP_DIVIDER_ID     5
 #define KV_MINIMUM_ENGINE_CLOCK         800
@@ -3389,6 +3390,7 @@ static const struct amd_pm_funcs kv_dpm_funcs = {
 	.get_vce_clock_state = amdgpu_get_vce_clock_state,
 	.check_state_equal = kv_check_state_equal,
 	.read_sensor = &kv_dpm_read_sensor,
+	.change_power_state = amdgpu_dpm_change_power_state_locked,
 };
 
 static const struct amdgpu_irq_src_funcs kv_dpm_irq_funcs = {
drivers/gpu/drm/amd/pm/powerplay/legacy_dpm.c new file +1453 -0

1,410 lines not on this page · raw message

drivers/gpu/drm/amd/pm/powerplay/legacy_dpm.h new file +70 -0

70 lines not on this page · raw message

drivers/gpu/drm/amd/pm/powerplay/si_dpm.c +2 -0
index 4f84d8b893f1..a2881c90d187 100644

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

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

Signature · 1 line
2.29.0

Part of the diff is not shown here. View the raw message.

#19 lore raw

Re: [PATCH V2 07/17] drm/amd/pm: create a new holder for those APIs used only by legacy ASICs(si/kv)

Quoted 499 lines · Evan Quan

Those APIs are used only by legacy ASICs(si/kv). They cannot be shared by other ASICs. So, we create a new holder for them.

Change-Id I555dfa37e783a267b1d3b3a7db5c87fcc3f1556f

--
v1->v2:
- move other APIs used by si/kv in amdgpu_atombios.c to the new holder also(Alex)

---
  drivers/gpu/drm/amd/amdgpu/amdgpu_atombios.c  |  421 -----
  drivers/gpu/drm/amd/amdgpu/amdgpu_atombios.h  |   30 -
  .../gpu/drm/amd/include/kgd_pp_interface.h    |    1 +
  drivers/gpu/drm/amd/pm/amdgpu_dpm.c           | 1008 +-----------
  drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h       |   15 -
  drivers/gpu/drm/amd/pm/powerplay/Makefile     |    2 +-
  drivers/gpu/drm/amd/pm/powerplay/kv_dpm.c     |    2 +
  drivers/gpu/drm/amd/pm/powerplay/legacy_dpm.c | 1453 +++++++++++++++++
  drivers/gpu/drm/amd/pm/powerplay/legacy_dpm.h |   70 +
  drivers/gpu/drm/amd/pm/powerplay/si_dpm.c     |    2 +
  10 files changed, 1534 insertions(+), 1470 deletions(-)

create mode 100644 drivers/gpu/drm/amd/pm/powerplay/legacy_dpm.c create mode 100644 drivers/gpu/drm/amd/pm/powerplay/legacy_dpm.h

drivers/gpu/drm/amd/amdgpu/amdgpu_atombios.c +0 -421
index 12a6b1c99c93..f2e447212e62 100644
@@ -1083,427 +1083,6 @@ int amdgpu_atombios_get_clock_dividers(struct amdgpu_device *adev,
  	return 0;
  }
 
-int amdgpu_atombios_get_memory_pll_dividers(struct amdgpu_device *adev,
-					    u32 clock,
-					    bool strobe_mode,
-					    struct atom_mpll_param *mpll_param)
-{
-	COMPUTE_MEMORY_CLOCK_PARAM_PARAMETERS_V2_1 args;
-	int index = GetIndexIntoMasterTable(COMMAND, ComputeMemoryClockParam);
-	u8 frev, crev;
-
-	memset(&args, 0, sizeof(args));
-	memset(mpll_param, 0, sizeof(struct atom_mpll_param));
-
-	if (!amdgpu_atom_parse_cmd_header(adev->mode_info.atom_context, index, &frev, &crev))
-		return -EINVAL;
-
-	switch (frev) {
-	case 2:
-		switch (crev) {
-		case 1:
-			/* SI */
-			args.ulClock = cpu_to_le32(clock);	/* 10 khz */
-			args.ucInputFlag = 0;
-			if (strobe_mode)
-				args.ucInputFlag |= MPLL_INPUT_FLAG_STROBE_MODE_EN;
-
-			amdgpu_atom_execute_table(adev->mode_info.atom_context, index, (uint32_t *)&args);
-
-			mpll_param->clkfrac = le16_to_cpu(args.ulFbDiv.usFbDivFrac);
-			mpll_param->clkf = le16_to_cpu(args.ulFbDiv.usFbDiv);
-			mpll_param->post_div = args.ucPostDiv;
-			mpll_param->dll_speed = args.ucDllSpeed;
-			mpll_param->bwcntl = args.ucBWCntl;
-			mpll_param->vco_mode =
-				(args.ucPllCntlFlag & MPLL_CNTL_FLAG_VCO_MODE_MASK);
-			mpll_param->yclk_sel =
-				(args.ucPllCntlFlag & MPLL_CNTL_FLAG_BYPASS_DQ_PLL) ? 1 : 0;
-			mpll_param->qdr =
-				(args.ucPllCntlFlag & MPLL_CNTL_FLAG_QDR_ENABLE) ? 1 : 0;
-			mpll_param->half_rate =
-				(args.ucPllCntlFlag & MPLL_CNTL_FLAG_AD_HALF_RATE) ? 1 : 0;
-			break;
-		default:
-			return -EINVAL;
-		}
-		break;
-	default:
-		return -EINVAL;
-	}
-	return 0;
-}
-
-void amdgpu_atombios_set_engine_dram_timings(struct amdgpu_device *adev,
-					     u32 eng_clock, u32 mem_clock)
-{
-	SET_ENGINE_CLOCK_PS_ALLOCATION args;
-	int index = GetIndexIntoMasterTable(COMMAND, DynamicMemorySettings);
-	u32 tmp;
-
-	memset(&args, 0, sizeof(args));
-
-	tmp = eng_clock & SET_CLOCK_FREQ_MASK;
-	tmp |= (COMPUTE_ENGINE_PLL_PARAM << 24);
-
-	args.ulTargetEngineClock = cpu_to_le32(tmp);
-	if (mem_clock)
-		args.sReserved.ulClock = cpu_to_le32(mem_clock & SET_CLOCK_FREQ_MASK);
-
-	amdgpu_atom_execute_table(adev->mode_info.atom_context, index, (uint32_t *)&args);
-}
-
-void amdgpu_atombios_get_default_voltages(struct amdgpu_device *adev,
-					  u16 *vddc, u16 *vddci, u16 *mvdd)
-{
-	struct amdgpu_mode_info *mode_info = &adev->mode_info;
-	int index = GetIndexIntoMasterTable(DATA, FirmwareInfo);
-	u8 frev, crev;
-	u16 data_offset;
-	union firmware_info *firmware_info;
-
-	*vddc = 0;
-	*vddci = 0;
-	*mvdd = 0;
-
-	if (amdgpu_atom_parse_data_header(mode_info->atom_context, index, NULL,
-				   &frev, &crev, &data_offset)) {
-		firmware_info =
-			(union firmware_info *)(mode_info->atom_context->bios +
-						data_offset);
-		*vddc = le16_to_cpu(firmware_info->info_14.usBootUpVDDCVoltage);
-		if ((frev == 2) && (crev >= 2)) {
-			*vddci = le16_to_cpu(firmware_info->info_22.usBootUpVDDCIVoltage);
-			*mvdd = le16_to_cpu(firmware_info->info_22.usBootUpMVDDCVoltage);
-		}
-	}
-}
-
-union set_voltage {
-	struct _SET_VOLTAGE_PS_ALLOCATION alloc;
-	struct _SET_VOLTAGE_PARAMETERS v1;
-	struct _SET_VOLTAGE_PARAMETERS_V2 v2;
-	struct _SET_VOLTAGE_PARAMETERS_V1_3 v3;
-};
-
-int amdgpu_atombios_get_max_vddc(struct amdgpu_device *adev, u8 voltage_type,
-			     u16 voltage_id, u16 *voltage)
-{
-	union set_voltage args;
-	int index = GetIndexIntoMasterTable(COMMAND, SetVoltage);
-	u8 frev, crev;
-
-	if (!amdgpu_atom_parse_cmd_header(adev->mode_info.atom_context, index, &frev, &crev))
-		return -EINVAL;
-
-	switch (crev) {
-	case 1:
-		return -EINVAL;
-	case 2:
-		args.v2.ucVoltageType = SET_VOLTAGE_GET_MAX_VOLTAGE;
-		args.v2.ucVoltageMode = 0;
-		args.v2.usVoltageLevel = 0;
-
-		amdgpu_atom_execute_table(adev->mode_info.atom_context, index, (uint32_t *)&args);
-
-		*voltage = le16_to_cpu(args.v2.usVoltageLevel);
-		break;
-	case 3:
-		args.v3.ucVoltageType = voltage_type;
-		args.v3.ucVoltageMode = ATOM_GET_VOLTAGE_LEVEL;
-		args.v3.usVoltageLevel = cpu_to_le16(voltage_id);
-
-		amdgpu_atom_execute_table(adev->mode_info.atom_context, index, (uint32_t *)&args);
-
-		*voltage = le16_to_cpu(args.v3.usVoltageLevel);
-		break;
-	default:
-		DRM_ERROR("Unknown table version %d, %d\n", frev, crev);
-		return -EINVAL;
-	}
-
-	return 0;
-}
-
-int amdgpu_atombios_get_leakage_vddc_based_on_leakage_idx(struct amdgpu_device *adev,
-						      u16 *voltage,
-						      u16 leakage_idx)
-{
-	return amdgpu_atombios_get_max_vddc(adev, VOLTAGE_TYPE_VDDC, leakage_idx, voltage);
-}
-
-union voltage_object_info {
-	struct _ATOM_VOLTAGE_OBJECT_INFO v1;
-	struct _ATOM_VOLTAGE_OBJECT_INFO_V2 v2;
-	struct _ATOM_VOLTAGE_OBJECT_INFO_V3_1 v3;
-};
-
-union voltage_object {
-	struct _ATOM_VOLTAGE_OBJECT v1;
-	struct _ATOM_VOLTAGE_OBJECT_V2 v2;
-	union _ATOM_VOLTAGE_OBJECT_V3 v3;
-};
-
-
-static ATOM_VOLTAGE_OBJECT_V3 *amdgpu_atombios_lookup_voltage_object_v3(ATOM_VOLTAGE_OBJECT_INFO_V3_1 *v3,
-									u8 voltage_type, u8 voltage_mode)
-{
-	u32 size = le16_to_cpu(v3->sHeader.usStructureSize);
-	u32 offset = offsetof(ATOM_VOLTAGE_OBJECT_INFO_V3_1, asVoltageObj[0]);
-	u8 *start = (u8 *)v3;
-
-	while (offset < size) {
-		ATOM_VOLTAGE_OBJECT_V3 *vo = (ATOM_VOLTAGE_OBJECT_V3 *)(start + offset);
-		if ((vo->asGpioVoltageObj.sHeader.ucVoltageType == voltage_type) &&
-		    (vo->asGpioVoltageObj.sHeader.ucVoltageMode == voltage_mode))
-			return vo;
-		offset += le16_to_cpu(vo->asGpioVoltageObj.sHeader.usSize);
-	}
-	return NULL;
-}
-
-int amdgpu_atombios_get_svi2_info(struct amdgpu_device *adev,
-			      u8 voltage_type,
-			      u8 *svd_gpio_id, u8 *svc_gpio_id)
-{
-	int index = GetIndexIntoMasterTable(DATA, VoltageObjectInfo);
-	u8 frev, crev;
-	u16 data_offset, size;
-	union voltage_object_info *voltage_info;
-	union voltage_object *voltage_object = NULL;
-
-	if (amdgpu_atom_parse_data_header(adev->mode_info.atom_context, index, &size,
-				   &frev, &crev, &data_offset)) {
-		voltage_info = (union voltage_object_info *)
-			(adev->mode_info.atom_context->bios + data_offset);
-
-		switch (frev) {
-		case 3:
-			switch (crev) {
-			case 1:
-				voltage_object = (union voltage_object *)
-					amdgpu_atombios_lookup_voltage_object_v3(&voltage_info->v3,
-								      voltage_type,
-								      VOLTAGE_OBJ_SVID2);
-				if (voltage_object) {
-					*svd_gpio_id = voltage_object->v3.asSVID2Obj.ucSVDGpioId;
-					*svc_gpio_id = voltage_object->v3.asSVID2Obj.ucSVCGpioId;
-				} else {
-					return -EINVAL;
-				}
-				break;
-			default:
-				DRM_ERROR("unknown voltage object table\n");
-				return -EINVAL;
-			}
-			break;
-		default:
-			DRM_ERROR("unknown voltage object table\n");
-			return -EINVAL;
-		}
-
-	}
-	return 0;
-}
-
-bool
-amdgpu_atombios_is_voltage_gpio(struct amdgpu_device *adev,
-				u8 voltage_type, u8 voltage_mode)
-{
-	int index = GetIndexIntoMasterTable(DATA, VoltageObjectInfo);
-	u8 frev, crev;
-	u16 data_offset, size;
-	union voltage_object_info *voltage_info;
-
-	if (amdgpu_atom_parse_data_header(adev->mode_info.atom_context, index, &size,
-				   &frev, &crev, &data_offset)) {
-		voltage_info = (union voltage_object_info *)
-			(adev->mode_info.atom_context->bios + data_offset);
-
-		switch (frev) {
-		case 3:
-			switch (crev) {
-			case 1:
-				if (amdgpu_atombios_lookup_voltage_object_v3(&voltage_info->v3,
-								  voltage_type, voltage_mode))
-					return true;
-				break;
-			default:
-				DRM_ERROR("unknown voltage object table\n");
-				return false;
-			}
-			break;
-		default:
-			DRM_ERROR("unknown voltage object table\n");
-			return false;
-		}
-
-	}
-	return false;
-}
-
-int amdgpu_atombios_get_voltage_table(struct amdgpu_device *adev,
-				      u8 voltage_type, u8 voltage_mode,
-				      struct atom_voltage_table *voltage_table)
-{
-	int index = GetIndexIntoMasterTable(DATA, VoltageObjectInfo);
-	u8 frev, crev;
-	u16 data_offset, size;
-	int i;
-	union voltage_object_info *voltage_info;
-	union voltage_object *voltage_object = NULL;
-
-	if (amdgpu_atom_parse_data_header(adev->mode_info.atom_context, index, &size,
-				   &frev, &crev, &data_offset)) {
-		voltage_info = (union voltage_object_info *)
-			(adev->mode_info.atom_context->bios + data_offset);
-
-		switch (frev) {
-		case 3:
-			switch (crev) {
-			case 1:
-				voltage_object = (union voltage_object *)
-					amdgpu_atombios_lookup_voltage_object_v3(&voltage_info->v3,
-								      voltage_type, voltage_mode);
-				if (voltage_object) {
-					ATOM_GPIO_VOLTAGE_OBJECT_V3 *gpio =
-						&voltage_object->v3.asGpioVoltageObj;
-					VOLTAGE_LUT_ENTRY_V2 *lut;
-					if (gpio->ucGpioEntryNum > MAX_VOLTAGE_ENTRIES)
-						return -EINVAL;
-					lut = &gpio->asVolGpioLut[0];
-					for (i = 0; i < gpio->ucGpioEntryNum; i++) {
-						voltage_table->entries[i].value =
-							le16_to_cpu(lut->usVoltageValue);
-						voltage_table->entries[i].smio_low =
-							le32_to_cpu(lut->ulVoltageId);
-						lut = (VOLTAGE_LUT_ENTRY_V2 *)
-							((u8 *)lut + sizeof(VOLTAGE_LUT_ENTRY_V2));
-					}
-					voltage_table->mask_low = le32_to_cpu(gpio->ulGpioMaskVal);
-					voltage_table->count = gpio->ucGpioEntryNum;
-					voltage_table->phase_delay = gpio->ucPhaseDelay;
-					return 0;
-				}
-				break;
-			default:
-				DRM_ERROR("unknown voltage object table\n");
-				return -EINVAL;
-			}
-			break;
-		default:
-			DRM_ERROR("unknown voltage object table\n");
-			return -EINVAL;
-		}
-	}
-	return -EINVAL;
-}
-
-union vram_info {
-	struct _ATOM_VRAM_INFO_V3 v1_3;
-	struct _ATOM_VRAM_INFO_V4 v1_4;
-	struct _ATOM_VRAM_INFO_HEADER_V2_1 v2_1;
-};
-
-#define MEM_ID_MASK           0xff000000
-#define MEM_ID_SHIFT          24
-#define CLOCK_RANGE_MASK      0x00ffffff
-#define CLOCK_RANGE_SHIFT     0
-#define LOW_NIBBLE_MASK       0xf
-#define DATA_EQU_PREV         0
-#define DATA_FROM_TABLE       4
-
-int amdgpu_atombios_init_mc_reg_table(struct amdgpu_device *adev,
-				      u8 module_index,
-				      struct atom_mc_reg_table *reg_table)
-{
-	int index = GetIndexIntoMasterTable(DATA, VRAM_Info);
-	u8 frev, crev, num_entries, t_mem_id, num_ranges = 0;
-	u32 i = 0, j;
-	u16 data_offset, size;
-	union vram_info *vram_info;
-
-	memset(reg_table, 0, sizeof(struct atom_mc_reg_table));
-
-	if (amdgpu_atom_parse_data_header(adev->mode_info.atom_context, index, &size,
-				   &frev, &crev, &data_offset)) {
-		vram_info = (union vram_info *)
-			(adev->mode_info.atom_context->bios + data_offset);
-		switch (frev) {
-		case 1:
-			DRM_ERROR("old table version %d, %d\n", frev, crev);
-			return -EINVAL;
-		case 2:
-			switch (crev) {
-			case 1:
-				if (module_index < vram_info->v2_1.ucNumOfVRAMModule) {
-					ATOM_INIT_REG_BLOCK *reg_block =
-						(ATOM_INIT_REG_BLOCK *)
-						((u8 *)vram_info + le16_to_cpu(vram_info->v2_1.usMemClkPatchTblOffset));
-					ATOM_MEMORY_SETTING_DATA_BLOCK *reg_data =
-						(ATOM_MEMORY_SETTING_DATA_BLOCK *)
-						((u8 *)reg_block + (2 * sizeof(u16)) +
-						 le16_to_cpu(reg_block->usRegIndexTblSize));
-					ATOM_INIT_REG_INDEX_FORMAT *format = &reg_block->asRegIndexBuf[0];
-					num_entries = (u8)((le16_to_cpu(reg_block->usRegIndexTblSize)) /
-							   sizeof(ATOM_INIT_REG_INDEX_FORMAT)) - 1;
-					if (num_entries > VBIOS_MC_REGISTER_ARRAY_SIZE)
-						return -EINVAL;
-					while (i < num_entries) {
-						if (format->ucPreRegDataLength & ACCESS_PLACEHOLDER)
-							break;
-						reg_table->mc_reg_address[i].s1 =
-							(u16)(le16_to_cpu(format->usRegIndex));
-						reg_table->mc_reg_address[i].pre_reg_data =
-							(u8)(format->ucPreRegDataLength);
-						i++;
-						format = (ATOM_INIT_REG_INDEX_FORMAT *)
-							((u8 *)format + sizeof(ATOM_INIT_REG_INDEX_FORMAT));
-					}
-					reg_table->last = i;
-					while ((le32_to_cpu(*(u32 *)reg_data) != END_OF_REG_DATA_BLOCK) &&
-					       (num_ranges < VBIOS_MAX_AC_TIMING_ENTRIES)) {
-						t_mem_id = (u8)((le32_to_cpu(*(u32 *)reg_data) & MEM_ID_MASK)
-								>> MEM_ID_SHIFT);
-						if (module_index == t_mem_id) {
-							reg_table->mc_reg_table_entry[num_ranges].mclk_max =
-								(u32)((le32_to_cpu(*(u32 *)reg_data) & CLOCK_RANGE_MASK)
-								      >> CLOCK_RANGE_SHIFT);
-							for (i = 0, j = 1; i < reg_table->last; i++) {
-								if ((reg_table->mc_reg_address[i].pre_reg_data & LOW_NIBBLE_MASK) == DATA_FROM_TABLE) {
-									reg_table->mc_reg_table_entry[num_ranges].mc_data[i] =
-										(u32)le32_to_cpu(*((u32 *)reg_data + j));
-									j++;
-								} else if ((reg_table->mc_reg_address[i].pre_reg_data & LOW_NIBBLE_MASK) == DATA_EQU_PREV) {
-									reg_table->mc_reg_table_entry[num_ranges].mc_data[i] =
-										reg_table->mc_reg_table_entry[num_ranges].mc_data[i - 1];
-								}
-							}
-							num_ranges++;
-						}
-						reg_data = (ATOM_MEMORY_SETTING_DATA_BLOCK *)
-							((u8 *)reg_data + le16_to_cpu(reg_block->usRegDataBlkSize));
-					}
-					if (le32_to_cpu(*(u32 *)reg_data) != END_OF_REG_DATA_BLOCK)
-						return -EINVAL;
-					reg_table->num_entries = num_ranges;
-				} else
-					return -EINVAL;
-				break;
-			default:
-				DRM_ERROR("Unknown table version %d, %d\n", frev, crev);
-				return -EINVAL;
-			}
-			break;
-		default:
-			DRM_ERROR("Unknown table version %d, %d\n", frev, crev);
-			return -EINVAL;
-		}
-		return 0;
-	}
-	return -EINVAL;
-}
-
  bool amdgpu_atombios_has_gpu_virtualization_table(struct amdgpu_device *adev)
  {
  	int index = GetIndexIntoMasterTable(DATA, GPUVirtualizationInfo);
drivers/gpu/drm/amd/amdgpu/amdgpu_atombios.h +0 -27
index 27e74b1fc260..cb5649298dcb 100644
@@ -160,26 +160,6 @@ int amdgpu_atombios_get_clock_dividers(struct amdgpu_device *adev,
  				       bool strobe_mode,
  				       struct atom_clock_dividers *dividers);
 
-int amdgpu_atombios_get_memory_pll_dividers(struct amdgpu_device *adev,
-					    u32 clock,
-					    bool strobe_mode,
-					    struct atom_mpll_param *mpll_param);
-
-void amdgpu_atombios_set_engine_dram_timings(struct amdgpu_device *adev,
-					     u32 eng_clock, u32 mem_clock);
-
-bool
-amdgpu_atombios_is_voltage_gpio(struct amdgpu_device *adev,
-				u8 voltage_type, u8 voltage_mode);
-
-int amdgpu_atombios_get_voltage_table(struct amdgpu_device *adev,
-				      u8 voltage_type, u8 voltage_mode,
-				      struct atom_voltage_table *voltage_table);
-
-int amdgpu_atombios_init_mc_reg_table(struct amdgpu_device *adev,
-				      u8 module_index,
-				      struct atom_mc_reg_table *reg_table);
-
  bool amdgpu_atombios_has_gpu_virtualization_table(struct amdgpu_device *adev);
 
  void amdgpu_atombios_scratch_regs_lock(struct amdgpu_device *adev, bool lock);
@@ -190,21 +170,11 @@ void amdgpu_atombios_scratch_regs_set_backlight_level(struct amdgpu_device *adev
  bool amdgpu_atombios_scratch_need_asic_init(struct amdgpu_device *adev);
 
  void amdgpu_atombios_copy_swap(u8 *dst, u8 *src, u8 num_bytes, bool to_le);
-int amdgpu_atombios_get_max_vddc(struct amdgpu_device *adev, u8 voltage_type,
-			     u16 voltage_id, u16 *voltage);
-int amdgpu_atombios_get_leakage_vddc_based_on_leakage_idx(struct amdgpu_device *adev,
-						      u16 *voltage,
-						      u16 leakage_idx);
-void amdgpu_atombios_get_default_voltages(struct amdgpu_device *adev,
-					  u16 *vddc, u16 *vddci, u16 *mvdd);
  int amdgpu_atombios_get_clock_dividers(struct amdgpu_device *adev,

drivers/gpu/drm/amd/amdgpu/amdgpu_atombios.h void amdgpu_atombios_scratch_regs_set_backlight_level(struct amdgpu_device *adev · line 180

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_atombios.h +0 -3
  				       u8 clock_type,
  				       u32 clock,
  				       bool strobe_mode,
  				       struct atom_clock_dividers *dividers);
-int amdgpu_atombios_get_svi2_info(struct amdgpu_device *adev,
-			      u8 voltage_type,
-			      u8 *svd_gpio_id, u8 *svc_gpio_id);
 
  int amdgpu_atombios_get_data_table(struct amdgpu_device *adev,
  				   uint32_t table,

Whether used in legacy or new logic, atombios table parsing/execution should be kept as separate logic. These shouldn't be moved along with dpm.

Quoted 1,019 lines
drivers/gpu/drm/amd/include/kgd_pp_interface.h +1 -0
index 2e295facd086..cdf724dcf832 100644
@@ -404,6 +404,7 @@ struct amd_pm_funcs {
  	int (*get_dpm_clock_table)(void *handle,
  				   struct dpm_clocks *clock_table);
  	int (*get_smu_prv_buf_details)(void *handle, void **addr, size_t *size);
+	int (*change_power_state)(void *handle);
  };
 
  struct metrics_table_header {
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +0 -975
index ecaf0081bc31..c6801d10cde6 100644
@@ -34,113 +34,9 @@
 
  #define WIDTH_4K 3840
 
-#define amdgpu_dpm_pre_set_power_state(adev) \
-		((adev)->powerplay.pp_funcs->pre_set_power_state((adev)->powerplay.pp_handle))
-
-#define amdgpu_dpm_post_set_power_state(adev) \
-		((adev)->powerplay.pp_funcs->post_set_power_state((adev)->powerplay.pp_handle))
-
-#define amdgpu_dpm_display_configuration_changed(adev) \
-		((adev)->powerplay.pp_funcs->display_configuration_changed((adev)->powerplay.pp_handle))
-
-#define amdgpu_dpm_print_power_state(adev, ps) \
-		((adev)->powerplay.pp_funcs->print_power_state((adev)->powerplay.pp_handle, (ps)))
-
-#define amdgpu_dpm_vblank_too_short(adev) \
-		((adev)->powerplay.pp_funcs->vblank_too_short((adev)->powerplay.pp_handle))
-
  #define amdgpu_dpm_enable_bapm(adev, e) \
  		((adev)->powerplay.pp_funcs->enable_bapm((adev)->powerplay.pp_handle, (e)))
 
-#define amdgpu_dpm_check_state_equal(adev, cps, rps, equal) \
-		((adev)->powerplay.pp_funcs->check_state_equal((adev)->powerplay.pp_handle, (cps), (rps), (equal)))
-
-void amdgpu_dpm_print_class_info(u32 class, u32 class2)
-{
-	const char *s;
-
-	switch (class & ATOM_PPLIB_CLASSIFICATION_UI_MASK) {
-	case ATOM_PPLIB_CLASSIFICATION_UI_NONE:
-	default:
-		s = "none";
-		break;
-	case ATOM_PPLIB_CLASSIFICATION_UI_BATTERY:
-		s = "battery";
-		break;
-	case ATOM_PPLIB_CLASSIFICATION_UI_BALANCED:
-		s = "balanced";
-		break;
-	case ATOM_PPLIB_CLASSIFICATION_UI_PERFORMANCE:
-		s = "performance";
-		break;
-	}
-	printk("\tui class: %s\n", s);
-	printk("\tinternal class:");
-	if (((class & ~ATOM_PPLIB_CLASSIFICATION_UI_MASK) == 0) &&
-	    (class2 == 0))
-		pr_cont(" none");
-	else {
-		if (class & ATOM_PPLIB_CLASSIFICATION_BOOT)
-			pr_cont(" boot");
-		if (class & ATOM_PPLIB_CLASSIFICATION_THERMAL)
-			pr_cont(" thermal");
-		if (class & ATOM_PPLIB_CLASSIFICATION_LIMITEDPOWERSOURCE)
-			pr_cont(" limited_pwr");
-		if (class & ATOM_PPLIB_CLASSIFICATION_REST)
-			pr_cont(" rest");
-		if (class & ATOM_PPLIB_CLASSIFICATION_FORCED)
-			pr_cont(" forced");
-		if (class & ATOM_PPLIB_CLASSIFICATION_3DPERFORMANCE)
-			pr_cont(" 3d_perf");
-		if (class & ATOM_PPLIB_CLASSIFICATION_OVERDRIVETEMPLATE)
-			pr_cont(" ovrdrv");
-		if (class & ATOM_PPLIB_CLASSIFICATION_UVDSTATE)
-			pr_cont(" uvd");
-		if (class & ATOM_PPLIB_CLASSIFICATION_3DLOW)
-			pr_cont(" 3d_low");
-		if (class & ATOM_PPLIB_CLASSIFICATION_ACPI)
-			pr_cont(" acpi");
-		if (class & ATOM_PPLIB_CLASSIFICATION_HD2STATE)
-			pr_cont(" uvd_hd2");
-		if (class & ATOM_PPLIB_CLASSIFICATION_HDSTATE)
-			pr_cont(" uvd_hd");
-		if (class & ATOM_PPLIB_CLASSIFICATION_SDSTATE)
-			pr_cont(" uvd_sd");
-		if (class2 & ATOM_PPLIB_CLASSIFICATION2_LIMITEDPOWERSOURCE_2)
-			pr_cont(" limited_pwr2");
-		if (class2 & ATOM_PPLIB_CLASSIFICATION2_ULV)
-			pr_cont(" ulv");
-		if (class2 & ATOM_PPLIB_CLASSIFICATION2_MVC)
-			pr_cont(" uvd_mvc");
-	}
-	pr_cont("\n");
-}
-
-void amdgpu_dpm_print_cap_info(u32 caps)
-{
-	printk("\tcaps:");
-	if (caps & ATOM_PPLIB_SINGLE_DISPLAY_ONLY)
-		pr_cont(" single_disp");
-	if (caps & ATOM_PPLIB_SUPPORTS_VIDEO_PLAYBACK)
-		pr_cont(" video");
-	if (caps & ATOM_PPLIB_DISALLOW_ON_DC)
-		pr_cont(" no_dc");
-	pr_cont("\n");
-}
-
-void amdgpu_dpm_print_ps_status(struct amdgpu_device *adev,
-				struct amdgpu_ps *rps)
-{
-	printk("\tstatus:");
-	if (rps == adev->pm.dpm.current_ps)
-		pr_cont(" c");
-	if (rps == adev->pm.dpm.requested_ps)
-		pr_cont(" r");
-	if (rps == adev->pm.dpm.boot_ps)
-		pr_cont(" b");
-	pr_cont("\n");
-}
-
  static void amdgpu_dpm_get_active_displays(struct amdgpu_device *adev)
  {
  	struct drm_device *ddev = adev_to_drm(adev);
@@ -161,7 +57,6 @@ static void amdgpu_dpm_get_active_displays(struct amdgpu_device *adev)
  	}
  }
 
-
  u32 amdgpu_dpm_get_vblank_time(struct amdgpu_device *adev)
  {
  	struct drm_device *dev = adev_to_drm(adev);
@@ -209,679 +104,6 @@ static u32 amdgpu_dpm_get_vrefresh(struct amdgpu_device *adev)
  	return vrefresh;
  }
 
-union power_info {
-	struct _ATOM_POWERPLAY_INFO info;
-	struct _ATOM_POWERPLAY_INFO_V2 info_2;
-	struct _ATOM_POWERPLAY_INFO_V3 info_3;
-	struct _ATOM_PPLIB_POWERPLAYTABLE pplib;
-	struct _ATOM_PPLIB_POWERPLAYTABLE2 pplib2;
-	struct _ATOM_PPLIB_POWERPLAYTABLE3 pplib3;
-	struct _ATOM_PPLIB_POWERPLAYTABLE4 pplib4;
-	struct _ATOM_PPLIB_POWERPLAYTABLE5 pplib5;
-};
-
-union fan_info {
-	struct _ATOM_PPLIB_FANTABLE fan;
-	struct _ATOM_PPLIB_FANTABLE2 fan2;
-	struct _ATOM_PPLIB_FANTABLE3 fan3;
-};
-
-static int amdgpu_parse_clk_voltage_dep_table(struct amdgpu_clock_voltage_dependency_table *amdgpu_table,
-					      ATOM_PPLIB_Clock_Voltage_Dependency_Table *atom_table)
-{
-	u32 size = atom_table->ucNumEntries *
-		sizeof(struct amdgpu_clock_voltage_dependency_entry);
-	int i;
-	ATOM_PPLIB_Clock_Voltage_Dependency_Record *entry;
-
-	amdgpu_table->entries = kzalloc(size, GFP_KERNEL);
-	if (!amdgpu_table->entries)
-		return -ENOMEM;
-
-	entry = &atom_table->entries[0];
-	for (i = 0; i < atom_table->ucNumEntries; i++) {
-		amdgpu_table->entries[i].clk = le16_to_cpu(entry->usClockLow) |
-			(entry->ucClockHigh << 16);
-		amdgpu_table->entries[i].v = le16_to_cpu(entry->usVoltage);
-		entry = (ATOM_PPLIB_Clock_Voltage_Dependency_Record *)
-			((u8 *)entry + sizeof(ATOM_PPLIB_Clock_Voltage_Dependency_Record));
-	}
-	amdgpu_table->count = atom_table->ucNumEntries;
-
-	return 0;
-}
-
-int amdgpu_get_platform_caps(struct amdgpu_device *adev)
-{
-	struct amdgpu_mode_info *mode_info = &adev->mode_info;
-	union power_info *power_info;
-	int index = GetIndexIntoMasterTable(DATA, PowerPlayInfo);
-	u16 data_offset;
-	u8 frev, crev;
-
-	if (!amdgpu_atom_parse_data_header(mode_info->atom_context, index, NULL,
-				   &frev, &crev, &data_offset))
-		return -EINVAL;
-	power_info = (union power_info *)(mode_info->atom_context->bios + data_offset);
-
-	adev->pm.dpm.platform_caps = le32_to_cpu(power_info->pplib.ulPlatformCaps);
-	adev->pm.dpm.backbias_response_time = le16_to_cpu(power_info->pplib.usBackbiasTime);
-	adev->pm.dpm.voltage_response_time = le16_to_cpu(power_info->pplib.usVoltageTime);
-
-	return 0;
-}
-
-/* sizeof(ATOM_PPLIB_EXTENDEDHEADER) */
-#define SIZE_OF_ATOM_PPLIB_EXTENDEDHEADER_V2 12
-#define SIZE_OF_ATOM_PPLIB_EXTENDEDHEADER_V3 14
-#define SIZE_OF_ATOM_PPLIB_EXTENDEDHEADER_V4 16
-#define SIZE_OF_ATOM_PPLIB_EXTENDEDHEADER_V5 18
-#define SIZE_OF_ATOM_PPLIB_EXTENDEDHEADER_V6 20
-#define SIZE_OF_ATOM_PPLIB_EXTENDEDHEADER_V7 22
-#define SIZE_OF_ATOM_PPLIB_EXTENDEDHEADER_V8 24
-#define SIZE_OF_ATOM_PPLIB_EXTENDEDHEADER_V9 26
-
-int amdgpu_parse_extended_power_table(struct amdgpu_device *adev)
-{
-	struct amdgpu_mode_info *mode_info = &adev->mode_info;
-	union power_info *power_info;
-	union fan_info *fan_info;
-	ATOM_PPLIB_Clock_Voltage_Dependency_Table *dep_table;
-	int index = GetIndexIntoMasterTable(DATA, PowerPlayInfo);
-	u16 data_offset;
-	u8 frev, crev;
-	int ret, i;
-
-	if (!amdgpu_atom_parse_data_header(mode_info->atom_context, index, NULL,
-				   &frev, &crev, &data_offset))
-		return -EINVAL;
-	power_info = (union power_info *)(mode_info->atom_context->bios + data_offset);
-
-	/* fan table */
-	if (le16_to_cpu(power_info->pplib.usTableSize) >=
-	    sizeof(struct _ATOM_PPLIB_POWERPLAYTABLE3)) {
-		if (power_info->pplib3.usFanTableOffset) {
-			fan_info = (union fan_info *)(mode_info->atom_context->bios + data_offset +
-						      le16_to_cpu(power_info->pplib3.usFanTableOffset));
-			adev->pm.dpm.fan.t_hyst = fan_info->fan.ucTHyst;
-			adev->pm.dpm.fan.t_min = le16_to_cpu(fan_info->fan.usTMin);
-			adev->pm.dpm.fan.t_med = le16_to_cpu(fan_info->fan.usTMed);
-			adev->pm.dpm.fan.t_high = le16_to_cpu(fan_info->fan.usTHigh);
-			adev->pm.dpm.fan.pwm_min = le16_to_cpu(fan_info->fan.usPWMMin);
-			adev->pm.dpm.fan.pwm_med = le16_to_cpu(fan_info->fan.usPWMMed);
-			adev->pm.dpm.fan.pwm_high = le16_to_cpu(fan_info->fan.usPWMHigh);
-			if (fan_info->fan.ucFanTableFormat >= 2)
-				adev->pm.dpm.fan.t_max = le16_to_cpu(fan_info->fan2.usTMax);
-			else
-				adev->pm.dpm.fan.t_max = 10900;
-			adev->pm.dpm.fan.cycle_delay = 100000;
-			if (fan_info->fan.ucFanTableFormat >= 3) {
-				adev->pm.dpm.fan.control_mode = fan_info->fan3.ucFanControlMode;
-				adev->pm.dpm.fan.default_max_fan_pwm =
-					le16_to_cpu(fan_info->fan3.usFanPWMMax);
-				adev->pm.dpm.fan.default_fan_output_sensitivity = 4836;
-				adev->pm.dpm.fan.fan_output_sensitivity =
-					le16_to_cpu(fan_info->fan3.usFanOutputSensitivity);
-			}
-			adev->pm.dpm.fan.ucode_fan_control = true;
-		}
-	}
-
-	/* clock dependancy tables, shedding tables */
-	if (le16_to_cpu(power_info->pplib.usTableSize) >=
-	    sizeof(struct _ATOM_PPLIB_POWERPLAYTABLE4)) {
-		if (power_info->pplib4.usVddcDependencyOnSCLKOffset) {
-			dep_table = (ATOM_PPLIB_Clock_Voltage_Dependency_Table *)
-				(mode_info->atom_context->bios + data_offset +
-				 le16_to_cpu(power_info->pplib4.usVddcDependencyOnSCLKOffset));
-			ret = amdgpu_parse_clk_voltage_dep_table(&adev->pm.dpm.dyn_state.vddc_dependency_on_sclk,
-								 dep_table);
-			if (ret) {
-				amdgpu_free_extended_power_table(adev);
-				return ret;
-			}
-		}
-		if (power_info->pplib4.usVddciDependencyOnMCLKOffset) {
-			dep_table = (ATOM_PPLIB_Clock_Voltage_Dependency_Table *)
-				(mode_info->atom_context->bios + data_offset +
-				 le16_to_cpu(power_info->pplib4.usVddciDependencyOnMCLKOffset));
-			ret = amdgpu_parse_clk_voltage_dep_table(&adev->pm.dpm.dyn_state.vddci_dependency_on_mclk,
-								 dep_table);
-			if (ret) {
-				amdgpu_free_extended_power_table(adev);
-				return ret;
-			}
-		}
-		if (power_info->pplib4.usVddcDependencyOnMCLKOffset) {
-			dep_table = (ATOM_PPLIB_Clock_Voltage_Dependency_Table *)
-				(mode_info->atom_context->bios + data_offset +
-				 le16_to_cpu(power_info->pplib4.usVddcDependencyOnMCLKOffset));
-			ret = amdgpu_parse_clk_voltage_dep_table(&adev->pm.dpm.dyn_state.vddc_dependency_on_mclk,
-								 dep_table);
-			if (ret) {
-				amdgpu_free_extended_power_table(adev);
-				return ret;
-			}
-		}
-		if (power_info->pplib4.usMvddDependencyOnMCLKOffset) {
-			dep_table = (ATOM_PPLIB_Clock_Voltage_Dependency_Table *)
-				(mode_info->atom_context->bios + data_offset +
-				 le16_to_cpu(power_info->pplib4.usMvddDependencyOnMCLKOffset));
-			ret = amdgpu_parse_clk_voltage_dep_table(&adev->pm.dpm.dyn_state.mvdd_dependency_on_mclk,
-								 dep_table);
-			if (ret) {
-				amdgpu_free_extended_power_table(adev);
-				return ret;
-			}
-		}
-		if (power_info->pplib4.usMaxClockVoltageOnDCOffset) {
-			ATOM_PPLIB_Clock_Voltage_Limit_Table *clk_v =
-				(ATOM_PPLIB_Clock_Voltage_Limit_Table *)
-				(mode_info->atom_context->bios + data_offset +
-				 le16_to_cpu(power_info->pplib4.usMaxClockVoltageOnDCOffset));
-			if (clk_v->ucNumEntries) {
-				adev->pm.dpm.dyn_state.max_clock_voltage_on_dc.sclk =
-					le16_to_cpu(clk_v->entries[0].usSclkLow) |
-					(clk_v->entries[0].ucSclkHigh << 16);
-				adev->pm.dpm.dyn_state.max_clock_voltage_on_dc.mclk =
-					le16_to_cpu(clk_v->entries[0].usMclkLow) |
-					(clk_v->entries[0].ucMclkHigh << 16);
-				adev->pm.dpm.dyn_state.max_clock_voltage_on_dc.vddc =
-					le16_to_cpu(clk_v->entries[0].usVddc);
-				adev->pm.dpm.dyn_state.max_clock_voltage_on_dc.vddci =
-					le16_to_cpu(clk_v->entries[0].usVddci);
-			}
-		}
-		if (power_info->pplib4.usVddcPhaseShedLimitsTableOffset) {
-			ATOM_PPLIB_PhaseSheddingLimits_Table *psl =
-				(ATOM_PPLIB_PhaseSheddingLimits_Table *)
-				(mode_info->atom_context->bios + data_offset +
-				 le16_to_cpu(power_info->pplib4.usVddcPhaseShedLimitsTableOffset));
-			ATOM_PPLIB_PhaseSheddingLimits_Record *entry;
-
-			adev->pm.dpm.dyn_state.phase_shedding_limits_table.entries =
-				kcalloc(psl->ucNumEntries,
-					sizeof(struct amdgpu_phase_shedding_limits_entry),
-					GFP_KERNEL);
-			if (!adev->pm.dpm.dyn_state.phase_shedding_limits_table.entries) {
-				amdgpu_free_extended_power_table(adev);
-				return -ENOMEM;
-			}
-
-			entry = &psl->entries[0];
-			for (i = 0; i < psl->ucNumEntries; i++) {
-				adev->pm.dpm.dyn_state.phase_shedding_limits_table.entries[i].sclk =
-					le16_to_cpu(entry->usSclkLow) | (entry->ucSclkHigh << 16);
-				adev->pm.dpm.dyn_state.phase_shedding_limits_table.entries[i].mclk =
-					le16_to_cpu(entry->usMclkLow) | (entry->ucMclkHigh << 16);
-				adev->pm.dpm.dyn_state.phase_shedding_limits_table.entries[i].voltage =
-					le16_to_cpu(entry->usVoltage);
-				entry = (ATOM_PPLIB_PhaseSheddingLimits_Record *)
-					((u8 *)entry + sizeof(ATOM_PPLIB_PhaseSheddingLimits_Record));
-			}
-			adev->pm.dpm.dyn_state.phase_shedding_limits_table.count =
-				psl->ucNumEntries;
-		}
-	}
-
-	/* cac data */
-	if (le16_to_cpu(power_info->pplib.usTableSize) >=
-	    sizeof(struct _ATOM_PPLIB_POWERPLAYTABLE5)) {
-		adev->pm.dpm.tdp_limit = le32_to_cpu(power_info->pplib5.ulTDPLimit);
-		adev->pm.dpm.near_tdp_limit = le32_to_cpu(power_info->pplib5.ulNearTDPLimit);
-		adev->pm.dpm.near_tdp_limit_adjusted = adev->pm.dpm.near_tdp_limit;
-		adev->pm.dpm.tdp_od_limit = le16_to_cpu(power_info->pplib5.usTDPODLimit);
-		if (adev->pm.dpm.tdp_od_limit)
-			adev->pm.dpm.power_control = true;
-		else
-			adev->pm.dpm.power_control = false;
-		adev->pm.dpm.tdp_adjustment = 0;
-		adev->pm.dpm.sq_ramping_threshold = le32_to_cpu(power_info->pplib5.ulSQRampingThreshold);
-		adev->pm.dpm.cac_leakage = le32_to_cpu(power_info->pplib5.ulCACLeakage);
-		adev->pm.dpm.load_line_slope = le16_to_cpu(power_info->pplib5.usLoadLineSlope);
-		if (power_info->pplib5.usCACLeakageTableOffset) {
-			ATOM_PPLIB_CAC_Leakage_Table *cac_table =
-				(ATOM_PPLIB_CAC_Leakage_Table *)
-				(mode_info->atom_context->bios + data_offset +
-				 le16_to_cpu(power_info->pplib5.usCACLeakageTableOffset));
-			ATOM_PPLIB_CAC_Leakage_Record *entry;
-			u32 size = cac_table->ucNumEntries * sizeof(struct amdgpu_cac_leakage_table);
-			adev->pm.dpm.dyn_state.cac_leakage_table.entries = kzalloc(size, GFP_KERNEL);
-			if (!adev->pm.dpm.dyn_state.cac_leakage_table.entries) {
-				amdgpu_free_extended_power_table(adev);
-				return -ENOMEM;
-			}
-			entry = &cac_table->entries[0];
-			for (i = 0; i < cac_table->ucNumEntries; i++) {
-				if (adev->pm.dpm.platform_caps & ATOM_PP_PLATFORM_CAP_EVV) {
-					adev->pm.dpm.dyn_state.cac_leakage_table.entries[i].vddc1 =
-						le16_to_cpu(entry->usVddc1);
-					adev->pm.dpm.dyn_state.cac_leakage_table.entries[i].vddc2 =
-						le16_to_cpu(entry->usVddc2);
-					adev->pm.dpm.dyn_state.cac_leakage_table.entries[i].vddc3 =
-						le16_to_cpu(entry->usVddc3);
-				} else {
-					adev->pm.dpm.dyn_state.cac_leakage_table.entries[i].vddc =
-						le16_to_cpu(entry->usVddc);
-					adev->pm.dpm.dyn_state.cac_leakage_table.entries[i].leakage =
-						le32_to_cpu(entry->ulLeakageValue);
-				}
-				entry = (ATOM_PPLIB_CAC_Leakage_Record *)
-					((u8 *)entry + sizeof(ATOM_PPLIB_CAC_Leakage_Record));
-			}
-			adev->pm.dpm.dyn_state.cac_leakage_table.count = cac_table->ucNumEntries;
-		}
-	}
-
-	/* ext tables */
-	if (le16_to_cpu(power_info->pplib.usTableSize) >=
-	    sizeof(struct _ATOM_PPLIB_POWERPLAYTABLE3)) {
-		ATOM_PPLIB_EXTENDEDHEADER *ext_hdr = (ATOM_PPLIB_EXTENDEDHEADER *)
-			(mode_info->atom_context->bios + data_offset +
-			 le16_to_cpu(power_info->pplib3.usExtendendedHeaderOffset));
-		if ((le16_to_cpu(ext_hdr->usSize) >= SIZE_OF_ATOM_PPLIB_EXTENDEDHEADER_V2) &&
-			ext_hdr->usVCETableOffset) {
-			VCEClockInfoArray *array = (VCEClockInfoArray *)
-				(mode_info->atom_context->bios + data_offset +
-				 le16_to_cpu(ext_hdr->usVCETableOffset) + 1);
-			ATOM_PPLIB_VCE_Clock_Voltage_Limit_Table *limits =
-				(ATOM_PPLIB_VCE_Clock_Voltage_Limit_Table *)
-				(mode_info->atom_context->bios + data_offset +
-				 le16_to_cpu(ext_hdr->usVCETableOffset) + 1 +
-				 1 + array->ucNumEntries * sizeof(VCEClockInfo));
-			ATOM_PPLIB_VCE_State_Table *states =
-				(ATOM_PPLIB_VCE_State_Table *)
-				(mode_info->atom_context->bios + data_offset +
-				 le16_to_cpu(ext_hdr->usVCETableOffset) + 1 +
-				 1 + (array->ucNumEntries * sizeof (VCEClockInfo)) +
-				 1 + (limits->numEntries * sizeof(ATOM_PPLIB_VCE_Clock_Voltage_Limit_Record)));
-			ATOM_PPLIB_VCE_Clock_Voltage_Limit_Record *entry;
-			ATOM_PPLIB_VCE_State_Record *state_entry;
-			VCEClockInfo *vce_clk;
-			u32 size = limits->numEntries *
-				sizeof(struct amdgpu_vce_clock_voltage_dependency_entry);
-			adev->pm.dpm.dyn_state.vce_clock_voltage_dependency_table.entries =
-				kzalloc(size, GFP_KERNEL);
-			if (!adev->pm.dpm.dyn_state.vce_clock_voltage_dependency_table.entries) {
-				amdgpu_free_extended_power_table(adev);
-				return -ENOMEM;
-			}
-			adev->pm.dpm.dyn_state.vce_clock_voltage_dependency_table.count =
-				limits->numEntries;
-			entry = &limits->entries[0];
-			state_entry = &states->entries[0];
-			for (i = 0; i < limits->numEntries; i++) {
-				vce_clk = (VCEClockInfo *)
-					((u8 *)&array->entries[0] +
-					 (entry->ucVCEClockInfoIndex * sizeof(VCEClockInfo)));
-				adev->pm.dpm.dyn_state.vce_clock_voltage_dependency_table.entries[i].evclk =
-					le16_to_cpu(vce_clk->usEVClkLow) | (vce_clk->ucEVClkHigh << 16);
-				adev->pm.dpm.dyn_state.vce_clock_voltage_dependency_table.entries[i].ecclk =
-					le16_to_cpu(vce_clk->usECClkLow) | (vce_clk->ucECClkHigh << 16);
-				adev->pm.dpm.dyn_state.vce_clock_voltage_dependency_table.entries[i].v =
-					le16_to_cpu(entry->usVoltage);
-				entry = (ATOM_PPLIB_VCE_Clock_Voltage_Limit_Record *)
-					((u8 *)entry + sizeof(ATOM_PPLIB_VCE_Clock_Voltage_Limit_Record));
-			}
-			adev->pm.dpm.num_of_vce_states =
-					states->numEntries > AMD_MAX_VCE_LEVELS ?
-					AMD_MAX_VCE_LEVELS : states->numEntries;
-			for (i = 0; i < adev->pm.dpm.num_of_vce_states; i++) {
-				vce_clk = (VCEClockInfo *)
-					((u8 *)&array->entries[0] +
-					 (state_entry->ucVCEClockInfoIndex * sizeof(VCEClockInfo)));
-				adev->pm.dpm.vce_states[i].evclk =
-					le16_to_cpu(vce_clk->usEVClkLow) | (vce_clk->ucEVClkHigh << 16);
-				adev->pm.dpm.vce_states[i].ecclk =
-					le16_to_cpu(vce_clk->usECClkLow) | (vce_clk->ucECClkHigh << 16);
-				adev->pm.dpm.vce_states[i].clk_idx =
-					state_entry->ucClockInfoIndex & 0x3f;
-				adev->pm.dpm.vce_states[i].pstate =
-					(state_entry->ucClockInfoIndex & 0xc0) >> 6;
-				state_entry = (ATOM_PPLIB_VCE_State_Record *)
-					((u8 *)state_entry + sizeof(ATOM_PPLIB_VCE_State_Record));
-			}
-		}
-		if ((le16_to_cpu(ext_hdr->usSize) >= SIZE_OF_ATOM_PPLIB_EXTENDEDHEADER_V3) &&
-			ext_hdr->usUVDTableOffset) {
-			UVDClockInfoArray *array = (UVDClockInfoArray *)
-				(mode_info->atom_context->bios + data_offset +
-				 le16_to_cpu(ext_hdr->usUVDTableOffset) + 1);
-			ATOM_PPLIB_UVD_Clock_Voltage_Limit_Table *limits =
-				(ATOM_PPLIB_UVD_Clock_Voltage_Limit_Table *)
-				(mode_info->atom_context->bios + data_offset +
-				 le16_to_cpu(ext_hdr->usUVDTableOffset) + 1 +
-				 1 + (array->ucNumEntries * sizeof (UVDClockInfo)));
-			ATOM_PPLIB_UVD_Clock_Voltage_Limit_Record *entry;
-			u32 size = limits->numEntries *
-				sizeof(struct amdgpu_uvd_clock_voltage_dependency_entry);
-			adev->pm.dpm.dyn_state.uvd_clock_voltage_dependency_table.entries =
-				kzalloc(size, GFP_KERNEL);
-			if (!adev->pm.dpm.dyn_state.uvd_clock_voltage_dependency_table.entries) {
-				amdgpu_free_extended_power_table(adev);
-				return -ENOMEM;
-			}
-			adev->pm.dpm.dyn_state.uvd_clock_voltage_dependency_table.count =
-				limits->numEntries;
-			entry = &limits->entries[0];
-			for (i = 0; i < limits->numEntries; i++) {
-				UVDClockInfo *uvd_clk = (UVDClockInfo *)
-					((u8 *)&array->entries[0] +
-					 (entry->ucUVDClockInfoIndex * sizeof(UVDClockInfo)));
-				adev->pm.dpm.dyn_state.uvd_clock_voltage_dependency_table.entries[i].vclk =
-					le16_to_cpu(uvd_clk->usVClkLow) | (uvd_clk->ucVClkHigh << 16);
-				adev->pm.dpm.dyn_state.uvd_clock_voltage_dependency_table.entries[i].dclk =
-					le16_to_cpu(uvd_clk->usDClkLow) | (uvd_clk->ucDClkHigh << 16);
-				adev->pm.dpm.dyn_state.uvd_clock_voltage_dependency_table.entries[i].v =
-					le16_to_cpu(entry->usVoltage);
-				entry = (ATOM_PPLIB_UVD_Clock_Voltage_Limit_Record *)
-					((u8 *)entry + sizeof(ATOM_PPLIB_UVD_Clock_Voltage_Limit_Record));
-			}
-		}
-		if ((le16_to_cpu(ext_hdr->usSize) >= SIZE_OF_ATOM_PPLIB_EXTENDEDHEADER_V4) &&
-			ext_hdr->usSAMUTableOffset) {
-			ATOM_PPLIB_SAMClk_Voltage_Limit_Table *limits =
-				(ATOM_PPLIB_SAMClk_Voltage_Limit_Table *)
-				(mode_info->atom_context->bios + data_offset +
-				 le16_to_cpu(ext_hdr->usSAMUTableOffset) + 1);
-			ATOM_PPLIB_SAMClk_Voltage_Limit_Record *entry;
-			u32 size = limits->numEntries *
-				sizeof(struct amdgpu_clock_voltage_dependency_entry);
-			adev->pm.dpm.dyn_state.samu_clock_voltage_dependency_table.entries =
-				kzalloc(size, GFP_KERNEL);
-			if (!adev->pm.dpm.dyn_state.samu_clock_voltage_dependency_table.entries) {
-				amdgpu_free_extended_power_table(adev);
-				return -ENOMEM;
-			}
-			adev->pm.dpm.dyn_state.samu_clock_voltage_dependency_table.count =
-				limits->numEntries;
-			entry = &limits->entries[0];
-			for (i = 0; i < limits->numEntries; i++) {
-				adev->pm.dpm.dyn_state.samu_clock_voltage_dependency_table.entries[i].clk =
-					le16_to_cpu(entry->usSAMClockLow) | (entry->ucSAMClockHigh << 16);
-				adev->pm.dpm.dyn_state.samu_clock_voltage_dependency_table.entries[i].v =
-					le16_to_cpu(entry->usVoltage);
-				entry = (ATOM_PPLIB_SAMClk_Voltage_Limit_Record *)
-					((u8 *)entry + sizeof(ATOM_PPLIB_SAMClk_Voltage_Limit_Record));
-			}
-		}
-		if ((le16_to_cpu(ext_hdr->usSize) >= SIZE_OF_ATOM_PPLIB_EXTENDEDHEADER_V5) &&
-		    ext_hdr->usPPMTableOffset) {
-			ATOM_PPLIB_PPM_Table *ppm = (ATOM_PPLIB_PPM_Table *)
-				(mode_info->atom_context->bios + data_offset +
-				 le16_to_cpu(ext_hdr->usPPMTableOffset));
-			adev->pm.dpm.dyn_state.ppm_table =
-				kzalloc(sizeof(struct amdgpu_ppm_table), GFP_KERNEL);
-			if (!adev->pm.dpm.dyn_state.ppm_table) {
-				amdgpu_free_extended_power_table(adev);
-				return -ENOMEM;
-			}
-			adev->pm.dpm.dyn_state.ppm_table->ppm_design = ppm->ucPpmDesign;
-			adev->pm.dpm.dyn_state.ppm_table->cpu_core_number =
-				le16_to_cpu(ppm->usCpuCoreNumber);
-			adev->pm.dpm.dyn_state.ppm_table->platform_tdp =
-				le32_to_cpu(ppm->ulPlatformTDP);
-			adev->pm.dpm.dyn_state.ppm_table->small_ac_platform_tdp =
-				le32_to_cpu(ppm->ulSmallACPlatformTDP);
-			adev->pm.dpm.dyn_state.ppm_table->platform_tdc =
-				le32_to_cpu(ppm->ulPlatformTDC);
-			adev->pm.dpm.dyn_state.ppm_table->small_ac_platform_tdc =
-				le32_to_cpu(ppm->ulSmallACPlatformTDC);
-			adev->pm.dpm.dyn_state.ppm_table->apu_tdp =
-				le32_to_cpu(ppm->ulApuTDP);
-			adev->pm.dpm.dyn_state.ppm_table->dgpu_tdp =
-				le32_to_cpu(ppm->ulDGpuTDP);
-			adev->pm.dpm.dyn_state.ppm_table->dgpu_ulv_power =
-				le32_to_cpu(ppm->ulDGpuUlvPower);
-			adev->pm.dpm.dyn_state.ppm_table->tj_max =
-				le32_to_cpu(ppm->ulTjmax);
-		}
-		if ((le16_to_cpu(ext_hdr->usSize) >= SIZE_OF_ATOM_PPLIB_EXTENDEDHEADER_V6) &&
-			ext_hdr->usACPTableOffset) {
-			ATOM_PPLIB_ACPClk_Voltage_Limit_Table *limits =
-				(ATOM_PPLIB_ACPClk_Voltage_Limit_Table *)
-				(mode_info->atom_context->bios + data_offset +
-				 le16_to_cpu(ext_hdr->usACPTableOffset) + 1);
-			ATOM_PPLIB_ACPClk_Voltage_Limit_Record *entry;
-			u32 size = limits->numEntries *
-				sizeof(struct amdgpu_clock_voltage_dependency_entry);
-			adev->pm.dpm.dyn_state.acp_clock_voltage_dependency_table.entries =
-				kzalloc(size, GFP_KERNEL);
-			if (!adev->pm.dpm.dyn_state.acp_clock_voltage_dependency_table.entries) {
-				amdgpu_free_extended_power_table(adev);
-				return -ENOMEM;
-			}
-			adev->pm.dpm.dyn_state.acp_clock_voltage_dependency_table.count =
-				limits->numEntries;
-			entry = &limits->entries[0];
-			for (i = 0; i < limits->numEntries; i++) {
-				adev->pm.dpm.dyn_state.acp_clock_voltage_dependency_table.entries[i].clk =
-					le16_to_cpu(entry->usACPClockLow) | (entry->ucACPClockHigh << 16);
-				adev->pm.dpm.dyn_state.acp_clock_voltage_dependency_table.entries[i].v =
-					le16_to_cpu(entry->usVoltage);
-				entry = (ATOM_PPLIB_ACPClk_Voltage_Limit_Record *)
-					((u8 *)entry + sizeof(ATOM_PPLIB_ACPClk_Voltage_Limit_Record));
-			}
-		}
-		if ((le16_to_cpu(ext_hdr->usSize) >= SIZE_OF_ATOM_PPLIB_EXTENDEDHEADER_V7) &&
-			ext_hdr->usPowerTuneTableOffset) {
-			u8 rev = *(u8 *)(mode_info->atom_context->bios + data_offset +
-					 le16_to_cpu(ext_hdr->usPowerTuneTableOffset));
-			ATOM_PowerTune_Table *pt;
-			adev->pm.dpm.dyn_state.cac_tdp_table =
-				kzalloc(sizeof(struct amdgpu_cac_tdp_table), GFP_KERNEL);
-			if (!adev->pm.dpm.dyn_state.cac_tdp_table) {
-				amdgpu_free_extended_power_table(adev);
-				return -ENOMEM;
-			}
-			if (rev > 0) {
-				ATOM_PPLIB_POWERTUNE_Table_V1 *ppt = (ATOM_PPLIB_POWERTUNE_Table_V1 *)
-					(mode_info->atom_context->bios + data_offset +
-					 le16_to_cpu(ext_hdr->usPowerTuneTableOffset));
-				adev->pm.dpm.dyn_state.cac_tdp_table->maximum_power_delivery_limit =
-					ppt->usMaximumPowerDeliveryLimit;
-				pt = &ppt->power_tune_table;
-			} else {
-				ATOM_PPLIB_POWERTUNE_Table *ppt = (ATOM_PPLIB_POWERTUNE_Table *)
-					(mode_info->atom_context->bios + data_offset +
-					 le16_to_cpu(ext_hdr->usPowerTuneTableOffset));
-				adev->pm.dpm.dyn_state.cac_tdp_table->maximum_power_delivery_limit = 255;
-				pt = &ppt->power_tune_table;
-			}
-			adev->pm.dpm.dyn_state.cac_tdp_table->tdp = le16_to_cpu(pt->usTDP);
-			adev->pm.dpm.dyn_state.cac_tdp_table->configurable_tdp =
-				le16_to_cpu(pt->usConfigurableTDP);
-			adev->pm.dpm.dyn_state.cac_tdp_table->tdc = le16_to_cpu(pt->usTDC);
-			adev->pm.dpm.dyn_state.cac_tdp_table->battery_power_limit =
-				le16_to_cpu(pt->usBatteryPowerLimit);
-			adev->pm.dpm.dyn_state.cac_tdp_table->small_power_limit =
-				le16_to_cpu(pt->usSmallPowerLimit);
-			adev->pm.dpm.dyn_state.cac_tdp_table->low_cac_leakage =
-				le16_to_cpu(pt->usLowCACLeakage);
-			adev->pm.dpm.dyn_state.cac_tdp_table->high_cac_leakage =
-				le16_to_cpu(pt->usHighCACLeakage);
-		}
-		if ((le16_to_cpu(ext_hdr->usSize) >= SIZE_OF_ATOM_PPLIB_EXTENDEDHEADER_V8) &&
-				ext_hdr->usSclkVddgfxTableOffset) {
-			dep_table = (ATOM_PPLIB_Clock_Voltage_Dependency_Table *)
-				(mode_info->atom_context->bios + data_offset +
-				 le16_to_cpu(ext_hdr->usSclkVddgfxTableOffset));
-			ret = amdgpu_parse_clk_voltage_dep_table(
-					&adev->pm.dpm.dyn_state.vddgfx_dependency_on_sclk,
-					dep_table);
-			if (ret) {
-				kfree(adev->pm.dpm.dyn_state.vddgfx_dependency_on_sclk.entries);
-				return ret;
-			}
-		}
-	}
-
-	return 0;
-}
-
-void amdgpu_free_extended_power_table(struct amdgpu_device *adev)
-{
-	struct amdgpu_dpm_dynamic_state *dyn_state = &adev->pm.dpm.dyn_state;
-
-	kfree(dyn_state->vddc_dependency_on_sclk.entries);
-	kfree(dyn_state->vddci_dependency_on_mclk.entries);
-	kfree(dyn_state->vddc_dependency_on_mclk.entries);
-	kfree(dyn_state->mvdd_dependency_on_mclk.entries);
-	kfree(dyn_state->cac_leakage_table.entries);
-	kfree(dyn_state->phase_shedding_limits_table.entries);
-	kfree(dyn_state->ppm_table);
-	kfree(dyn_state->cac_tdp_table);
-	kfree(dyn_state->vce_clock_voltage_dependency_table.entries);
-	kfree(dyn_state->uvd_clock_voltage_dependency_table.entries);
-	kfree(dyn_state->samu_clock_voltage_dependency_table.entries);
-	kfree(dyn_state->acp_clock_voltage_dependency_table.entries);
-	kfree(dyn_state->vddgfx_dependency_on_sclk.entries);
-}
-
-static const char *pp_lib_thermal_controller_names[] = {
-	"NONE",
-	"lm63",
-	"adm1032",
-	"adm1030",
-	"max6649",
-	"lm64",
-	"f75375",
-	"RV6xx",
-	"RV770",
-	"adt7473",
-	"NONE",
-	"External GPIO",
-	"Evergreen",
-	"emc2103",
-	"Sumo",
-	"Northern Islands",
-	"Southern Islands",
-	"lm96163",
-	"Sea Islands",
-	"Kaveri/Kabini",
-};
-
-void amdgpu_add_thermal_controller(struct amdgpu_device *adev)
-{
-	struct amdgpu_mode_info *mode_info = &adev->mode_info;
-	ATOM_PPLIB_POWERPLAYTABLE *power_table;
-	int index = GetIndexIntoMasterTable(DATA, PowerPlayInfo);
-	ATOM_PPLIB_THERMALCONTROLLER *controller;
-	struct amdgpu_i2c_bus_rec i2c_bus;
-	u16 data_offset;
-	u8 frev, crev;
-
-	if (!amdgpu_atom_parse_data_header(mode_info->atom_context, index, NULL,
-				   &frev, &crev, &data_offset))
-		return;
-	power_table = (ATOM_PPLIB_POWERPLAYTABLE *)
-		(mode_info->atom_context->bios + data_offset);
-	controller = &power_table->sThermalController;
-
-	/* add the i2c bus for thermal/fan chip */
-	if (controller->ucType > 0) {
-		if (controller->ucFanParameters & ATOM_PP_FANPARAMETERS_NOFAN)
-			adev->pm.no_fan = true;
-		adev->pm.fan_pulses_per_revolution =
-			controller->ucFanParameters & ATOM_PP_FANPARAMETERS_TACHOMETER_PULSES_PER_REVOLUTION_MASK;
-		if (adev->pm.fan_pulses_per_revolution) {
-			adev->pm.fan_min_rpm = controller->ucFanMinRPM;
-			adev->pm.fan_max_rpm = controller->ucFanMaxRPM;
-		}
-		if (controller->ucType == ATOM_PP_THERMALCONTROLLER_RV6xx) {
-			DRM_INFO("Internal thermal controller %s fan control\n",
-				 (controller->ucFanParameters &
-				  ATOM_PP_FANPARAMETERS_NOFAN) ? "without" : "with");
-			adev->pm.int_thermal_type = THERMAL_TYPE_RV6XX;
-		} else if (controller->ucType == ATOM_PP_THERMALCONTROLLER_RV770) {
-			DRM_INFO("Internal thermal controller %s fan control\n",
-				 (controller->ucFanParameters &
-				  ATOM_PP_FANPARAMETERS_NOFAN) ? "without" : "with");
-			adev->pm.int_thermal_type = THERMAL_TYPE_RV770;
-		} else if (controller->ucType == ATOM_PP_THERMALCONTROLLER_EVERGREEN) {
-			DRM_INFO("Internal thermal controller %s fan control\n",
-				 (controller->ucFanParameters &
-				  ATOM_PP_FANPARAMETERS_NOFAN) ? "without" : "with");
-			adev->pm.int_thermal_type = THERMAL_TYPE_EVERGREEN;
-		} else if (controller->ucType == ATOM_PP_THERMALCONTROLLER_SUMO) {
-			DRM_INFO("Internal thermal controller %s fan control\n",
-				 (controller->ucFanParameters &
-				  ATOM_PP_FANPARAMETERS_NOFAN) ? "without" : "with");
-			adev->pm.int_thermal_type = THERMAL_TYPE_SUMO;
-		} else if (controller->ucType == ATOM_PP_THERMALCONTROLLER_NISLANDS) {
-			DRM_INFO("Internal thermal controller %s fan control\n",
-				 (controller->ucFanParameters &
-				  ATOM_PP_FANPARAMETERS_NOFAN) ? "without" : "with");
-			adev->pm.int_thermal_type = THERMAL_TYPE_NI;
-		} else if (controller->ucType == ATOM_PP_THERMALCONTROLLER_SISLANDS) {
-			DRM_INFO("Internal thermal controller %s fan control\n",
-				 (controller->ucFanParameters &
-				  ATOM_PP_FANPARAMETERS_NOFAN) ? "without" : "with");
-			adev->pm.int_thermal_type = THERMAL_TYPE_SI;
-		} else if (controller->ucType == ATOM_PP_THERMALCONTROLLER_CISLANDS) {
-			DRM_INFO("Internal thermal controller %s fan control\n",
-				 (controller->ucFanParameters &
-				  ATOM_PP_FANPARAMETERS_NOFAN) ? "without" : "with");
-			adev->pm.int_thermal_type = THERMAL_TYPE_CI;
-		} else if (controller->ucType == ATOM_PP_THERMALCONTROLLER_KAVERI) {
-			DRM_INFO("Internal thermal controller %s fan control\n",
-				 (controller->ucFanParameters &
-				  ATOM_PP_FANPARAMETERS_NOFAN) ? "without" : "with");
-			adev->pm.int_thermal_type = THERMAL_TYPE_KV;
-		} else if (controller->ucType == ATOM_PP_THERMALCONTROLLER_EXTERNAL_GPIO) {
-			DRM_INFO("External GPIO thermal controller %s fan control\n",
-				 (controller->ucFanParameters &
-				  ATOM_PP_FANPARAMETERS_NOFAN) ? "without" : "with");
-			adev->pm.int_thermal_type = THERMAL_TYPE_EXTERNAL_GPIO;
-		} else if (controller->ucType ==
-			   ATOM_PP_THERMALCONTROLLER_ADT7473_WITH_INTERNAL) {
-			DRM_INFO("ADT7473 with internal thermal controller %s fan control\n",
-				 (controller->ucFanParameters &
-				  ATOM_PP_FANPARAMETERS_NOFAN) ? "without" : "with");
-			adev->pm.int_thermal_type = THERMAL_TYPE_ADT7473_WITH_INTERNAL;
-		} else if (controller->ucType ==
-			   ATOM_PP_THERMALCONTROLLER_EMC2103_WITH_INTERNAL) {
-			DRM_INFO("EMC2103 with internal thermal controller %s fan control\n",
-				 (controller->ucFanParameters &
-				  ATOM_PP_FANPARAMETERS_NOFAN) ? "without" : "with");
-			adev->pm.int_thermal_type = THERMAL_TYPE_EMC2103_WITH_INTERNAL;
-		} else if (controller->ucType < ARRAY_SIZE(pp_lib_thermal_controller_names)) {
-			DRM_INFO("Possible %s thermal controller at 0x%02x %s fan control\n",
-				 pp_lib_thermal_controller_names[controller->ucType],
-				 controller->ucI2cAddress >> 1,
-				 (controller->ucFanParameters &
-				  ATOM_PP_FANPARAMETERS_NOFAN) ? "without" : "with");
-			adev->pm.int_thermal_type = THERMAL_TYPE_EXTERNAL;
-			i2c_bus = amdgpu_atombios_lookup_i2c_gpio(adev, controller->ucI2cLine);
-			adev->pm.i2c_bus = amdgpu_i2c_lookup(adev, &i2c_bus);
-			if (adev->pm.i2c_bus) {
-				struct i2c_board_info info = { };
-				const char *name = pp_lib_thermal_controller_names[controller->ucType];
-				info.addr = controller->ucI2cAddress >> 1;
-				strlcpy(info.type, name, sizeof(info.type));
-				i2c_new_client_device(&adev->pm.i2c_bus->adapter, &info);
-			}
-		} else {
-			DRM_INFO("Unknown thermal controller type %d at 0x%02x %s fan control\n",
-				 controller->ucType,
-				 controller->ucI2cAddress >> 1,
-				 (controller->ucFanParameters &
-				  ATOM_PP_FANPARAMETERS_NOFAN) ? "without" : "with");
-		}
-	}
-}
-
-struct amd_vce_state*
-amdgpu_get_vce_clock_state(void *handle, u32 idx)
-{
-	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
-
-	if (idx < adev->pm.dpm.num_of_vce_states)
-		return &adev->pm.dpm.vce_states[idx];
-
-	return NULL;
-}
-
  int amdgpu_dpm_get_sclk(struct amdgpu_device *adev, bool low)
  {
  	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
@@ -1243,211 +465,6 @@ void amdgpu_dpm_thermal_work_handler(struct work_struct *work)
  	amdgpu_pm_compute_clocks(adev);
  }
 
-static struct amdgpu_ps *amdgpu_dpm_pick_power_state(struct amdgpu_device *adev,
-						     enum amd_pm_state_type dpm_state)
-{
-	int i;
-	struct amdgpu_ps *ps;
-	u32 ui_class;
-	bool single_display = (adev->pm.dpm.new_active_crtc_count < 2) ?
-		true : false;
-
-	/* check if the vblank period is too short to adjust the mclk */
-	if (single_display && adev->powerplay.pp_funcs->vblank_too_short) {
-		if (amdgpu_dpm_vblank_too_short(adev))
-			single_display = false;
-	}
-
-	/* certain older asics have a separare 3D performance state,
-	 * so try that first if the user selected performance
-	 */
-	if (dpm_state == POWER_STATE_TYPE_PERFORMANCE)
-		dpm_state = POWER_STATE_TYPE_INTERNAL_3DPERF;
-	/* balanced states don't exist at the moment */
-	if (dpm_state == POWER_STATE_TYPE_BALANCED)
-		dpm_state = POWER_STATE_TYPE_PERFORMANCE;
-
-restart_search:
-	/* Pick the best power state based on current conditions */
-	for (i = 0; i < adev->pm.dpm.num_ps; i++) {
-		ps = &adev->pm.dpm.ps[i];
-		ui_class = ps->class & ATOM_PPLIB_CLASSIFICATION_UI_MASK;
-		switch (dpm_state) {
-		/* user states */
-		case POWER_STATE_TYPE_BATTERY:
-			if (ui_class == ATOM_PPLIB_CLASSIFICATION_UI_BATTERY) {
-				if (ps->caps & ATOM_PPLIB_SINGLE_DISPLAY_ONLY) {
-					if (single_display)
-						return ps;
-				} else
-					return ps;
-			}
-			break;
-		case POWER_STATE_TYPE_BALANCED:
-			if (ui_class == ATOM_PPLIB_CLASSIFICATION_UI_BALANCED) {
-				if (ps->caps & ATOM_PPLIB_SINGLE_DISPLAY_ONLY) {
-					if (single_display)
-						return ps;
-				} else
-					return ps;
-			}
-			break;
-		case POWER_STATE_TYPE_PERFORMANCE:
-			if (ui_class == ATOM_PPLIB_CLASSIFICATION_UI_PERFORMANCE) {
-				if (ps->caps & ATOM_PPLIB_SINGLE_DISPLAY_ONLY) {
-					if (single_display)
-						return ps;
-				} else
-					return ps;
-			}
-			break;
-		/* internal states */
-		case POWER_STATE_TYPE_INTERNAL_UVD:
-			if (adev->pm.dpm.uvd_ps)
-				return adev->pm.dpm.uvd_ps;
-			else
-				break;
-		case POWER_STATE_TYPE_INTERNAL_UVD_SD:
-			if (ps->class & ATOM_PPLIB_CLASSIFICATION_SDSTATE)
-				return ps;
-			break;
-		case POWER_STATE_TYPE_INTERNAL_UVD_HD:
-			if (ps->class & ATOM_PPLIB_CLASSIFICATION_HDSTATE)
-				return ps;
-			break;
-		case POWER_STATE_TYPE_INTERNAL_UVD_HD2:
-			if (ps->class & ATOM_PPLIB_CLASSIFICATION_HD2STATE)
-				return ps;
-			break;
-		case POWER_STATE_TYPE_INTERNAL_UVD_MVC:
-			if (ps->class2 & ATOM_PPLIB_CLASSIFICATION2_MVC)
-				return ps;
-			break;
-		case POWER_STATE_TYPE_INTERNAL_BOOT:
-			return adev->pm.dpm.boot_ps;
-		case POWER_STATE_TYPE_INTERNAL_THERMAL:
-			if (ps->class & ATOM_PPLIB_CLASSIFICATION_THERMAL)
-				return ps;
-			break;
-		case POWER_STATE_TYPE_INTERNAL_ACPI:
-			if (ps->class & ATOM_PPLIB_CLASSIFICATION_ACPI)
-				return ps;
-			break;
-		case POWER_STATE_TYPE_INTERNAL_ULV:
-			if (ps->class2 & ATOM_PPLIB_CLASSIFICATION2_ULV)
-				return ps;
-			break;
-		case POWER_STATE_TYPE_INTERNAL_3DPERF:
-			if (ps->class & ATOM_PPLIB_CLASSIFICATION_3DPERFORMANCE)
-				return ps;
-			break;
-		default:
-			break;
-		}
-	}
-	/* use a fallback state if we didn't match */
-	switch (dpm_state) {
-	case POWER_STATE_TYPE_INTERNAL_UVD_SD:
-		dpm_state = POWER_STATE_TYPE_INTERNAL_UVD_HD;
-		goto restart_search;
-	case POWER_STATE_TYPE_INTERNAL_UVD_HD:
-	case POWER_STATE_TYPE_INTERNAL_UVD_HD2:
-	case POWER_STATE_TYPE_INTERNAL_UVD_MVC:
-		if (adev->pm.dpm.uvd_ps) {
-			return adev->pm.dpm.uvd_ps;
-		} else {
-			dpm_state = POWER_STATE_TYPE_PERFORMANCE;
-			goto restart_search;
-		}
-	case POWER_STATE_TYPE_INTERNAL_THERMAL:
-		dpm_state = POWER_STATE_TYPE_INTERNAL_ACPI;
-		goto restart_search;
-	case POWER_STATE_TYPE_INTERNAL_ACPI:
-		dpm_state = POWER_STATE_TYPE_BATTERY;
-		goto restart_search;
-	case POWER_STATE_TYPE_BATTERY:
-	case POWER_STATE_TYPE_BALANCED:
-	case POWER_STATE_TYPE_INTERNAL_3DPERF:
-		dpm_state = POWER_STATE_TYPE_PERFORMANCE;
-		goto restart_search;
-	default:
-		break;
-	}
-
-	return NULL;
-}
-
-static void amdgpu_dpm_change_power_state_locked(struct amdgpu_device *adev)
-{
-	struct amdgpu_ps *ps;
-	enum amd_pm_state_type dpm_state;
-	int ret;
-	bool equal = false;
-
-	/* if dpm init failed */
-	if (!adev->pm.dpm_enabled)
-		return;
-
-	if (adev->pm.dpm.user_state != adev->pm.dpm.state) {
-		/* add other state override checks here */
-		if ((!adev->pm.dpm.thermal_active) &&
-		    (!adev->pm.dpm.uvd_active))
-			adev->pm.dpm.state = adev->pm.dpm.user_state;
-	}
-	dpm_state = adev->pm.dpm.state;
-
-	ps = amdgpu_dpm_pick_power_state(adev, dpm_state);
-	if (ps)
-		adev->pm.dpm.requested_ps = ps;
-	else
-		return;
-
-	if (amdgpu_dpm == 1 && adev->powerplay.pp_funcs->print_power_state) {
-		printk("switching from power state:\n");
-		amdgpu_dpm_print_power_state(adev, adev->pm.dpm.current_ps);
-		printk("switching to power state:\n");
-		amdgpu_dpm_print_power_state(adev, adev->pm.dpm.requested_ps);
-	}
-
-	/* update whether vce is active */
-	ps->vce_active = adev->pm.dpm.vce_active;
-	if (adev->powerplay.pp_funcs->display_configuration_changed)
-		amdgpu_dpm_display_configuration_changed(adev);
-
-	ret = amdgpu_dpm_pre_set_power_state(adev);
-	if (ret)
-		return;
-
-	if (adev->powerplay.pp_funcs->check_state_equal) {
-		if (0 != amdgpu_dpm_check_state_equal(adev, adev->pm.dpm.current_ps, adev->pm.dpm.requested_ps, &equal))
-			equal = false;
-	}
-
-	if (equal)
-		return;
-
-	if (adev->powerplay.pp_funcs->set_power_state)
-		adev->powerplay.pp_funcs->set_power_state(adev->powerplay.pp_handle);
-
-	amdgpu_dpm_post_set_power_state(adev);
-
-	adev->pm.dpm.current_active_crtcs = adev->pm.dpm.new_active_crtcs;
-	adev->pm.dpm.current_active_crtc_count = adev->pm.dpm.new_active_crtc_count;
-
-	if (adev->powerplay.pp_funcs->force_performance_level) {
-		if (adev->pm.dpm.thermal_active) {
-			enum amd_dpm_forced_level level = adev->pm.dpm.forced_level;
-			/* force low perf level for thermal */
-			amdgpu_dpm_force_performance_level(adev, AMD_DPM_FORCED_LEVEL_LOW);
-			/* save the user's level */

drivers/gpu/drm/amd/pm/amdgpu_dpm.c void amdgpu_dpm_thermal_work_handler(struct work_struct *work) · line 469

Quoted 10 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +0 -8
-			adev->pm.dpm.forced_level = level;
-		} else {
-			/* otherwise, user selected level */
-			amdgpu_dpm_force_performance_level(adev, adev->pm.dpm.forced_level);
-		}
-	}
-}
-
  void amdgpu_pm_compute_clocks(struct amdgpu_device *adev)
  {

Rename to amdgpu_dpm_compute_clocks?

drivers/gpu/drm/amd/pm/amdgpu_dpm.c void amdgpu_pm_compute_clocks(struct amdgpu_device *adev) · line 487

Quoted 10 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +4 -1
  	int i = 0;
@@ -1464,9 +481,12 @@ void amdgpu_pm_compute_clocks(struct amdgpu_device *adev)
  			amdgpu_fence_wait_empty(ring);
  	}
 
-	if (adev->powerplay.pp_funcs->dispatch_tasks) {
+	if ((adev->family == AMDGPU_FAMILY_SI) ||
+	     (adev->family == AMDGPU_FAMILY_KV)) {
+		amdgpu_dpm_get_active_displays(adev);
+		adev->powerplay.pp_funcs->change_power_state(adev->powerplay.pp_handle);

It would be clearer if the newly added logic in this function is in another patch. This does more than what the patch subject says.

drivers/gpu/drm/amd/pm/powerplay/legacy_dpm.c

Quoted 111 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +1 -19
+	} else {
  		if (!amdgpu_device_has_dc_support(adev)) {
-			mutex_lock(&adev->pm.mutex);
  			amdgpu_dpm_get_active_displays(adev);
  			adev->pm.pm_display_cfg.num_display = adev->pm.dpm.new_active_crtc_count;
  			adev->pm.pm_display_cfg.vrefresh = amdgpu_dpm_get_vrefresh(adev);
@@ -1480,14 +500,8 @@ void amdgpu_pm_compute_clocks(struct amdgpu_device *adev)
  				adev->powerplay.pp_funcs->display_configuration_change(
  							adev->powerplay.pp_handle,
  							&adev->pm.pm_display_cfg);
-			mutex_unlock(&adev->pm.mutex);
  		}
  		amdgpu_dpm_dispatch_task(adev, AMD_PP_TASK_DISPLAY_CONFIG_CHANGE, NULL);
-	} else {
-		mutex_lock(&adev->pm.mutex);
-		amdgpu_dpm_get_active_displays(adev);
-		amdgpu_dpm_change_power_state_locked(adev);
-		mutex_unlock(&adev->pm.mutex);
  	}
  }
 
@@ -1550,18 +564,6 @@ void amdgpu_dpm_enable_vce(struct amdgpu_device *adev, bool enable)
  	}
  }
 
-void amdgpu_pm_print_power_states(struct amdgpu_device *adev)
-{
-	int i;
-
-	if (adev->powerplay.pp_funcs->print_power_state == NULL)
-		return;
-
-	for (i = 0; i < adev->pm.dpm.num_ps; i++)
-		amdgpu_dpm_print_power_state(adev, &adev->pm.dpm.ps[i]);
-
-}
-
  void amdgpu_dpm_enable_jpeg(struct amdgpu_device *adev, bool enable)
  {
  	int ret = 0;
drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h +0 -15
index 01120b302590..295d2902aef7 100644
@@ -366,24 +366,10 @@ enum amdgpu_display_gap
      AMDGPU_PM_DISPLAY_GAP_IGNORE       = 3,
  };
 
-void amdgpu_dpm_print_class_info(u32 class, u32 class2);
-void amdgpu_dpm_print_cap_info(u32 caps);
-void amdgpu_dpm_print_ps_status(struct amdgpu_device *adev,
-				struct amdgpu_ps *rps);
  u32 amdgpu_dpm_get_vblank_time(struct amdgpu_device *adev);
  int amdgpu_dpm_read_sensor(struct amdgpu_device *adev, enum amd_pp_sensors sensor,
  			   void *data, uint32_t *size);
 
-int amdgpu_get_platform_caps(struct amdgpu_device *adev);
-
-int amdgpu_parse_extended_power_table(struct amdgpu_device *adev);
-void amdgpu_free_extended_power_table(struct amdgpu_device *adev);
-
-void amdgpu_add_thermal_controller(struct amdgpu_device *adev);
-
-struct amd_vce_state*
-amdgpu_get_vce_clock_state(void *handle, u32 idx);
-
  int amdgpu_dpm_set_powergating_by_smu(struct amdgpu_device *adev,
  				      uint32_t block_type, bool gate);
 
@@ -438,7 +424,6 @@ void amdgpu_pm_compute_clocks(struct amdgpu_device *adev);
  void amdgpu_dpm_enable_uvd(struct amdgpu_device *adev, bool enable);
  void amdgpu_dpm_enable_vce(struct amdgpu_device *adev, bool enable);
  void amdgpu_dpm_enable_jpeg(struct amdgpu_device *adev, bool enable);
-void amdgpu_pm_print_power_states(struct amdgpu_device *adev);
  int amdgpu_pm_load_smu_firmware(struct amdgpu_device *adev, uint32_t *smu_version);
  int amdgpu_dpm_set_light_sbr(struct amdgpu_device *adev, bool enable);
  int amdgpu_dpm_send_hbm_bad_pages_num(struct amdgpu_device *adev, uint32_t size);
drivers/gpu/drm/amd/pm/powerplay/Makefile +1 -1
index 0fb114adc79f..614d8b6a58ad 100644
@@ -28,7 +28,7 @@ AMD_POWERPLAY = $(addsuffix /Makefile,$(addprefix $(FULL_AMD_PATH)/pm/powerplay/
 
  include $(AMD_POWERPLAY)
 
-POWER_MGR-y = amd_powerplay.o
+POWER_MGR-y = amd_powerplay.o legacy_dpm.o
 
  POWER_MGR-$(CONFIG_DRM_AMDGPU_CIK)+= kv_dpm.o kv_smc.o
 
drivers/gpu/drm/amd/pm/powerplay/kv_dpm.c +2 -0
index 380a5336c74f..90f4c65659e2 100644
@@ -36,6 +36,7 @@
 
  #include "gca/gfx_7_2_d.h"
  #include "gca/gfx_7_2_sh_mask.h"
+#include "legacy_dpm.h"
 
  #define KV_MAX_DEEPSLEEP_DIVIDER_ID     5
  #define KV_MINIMUM_ENGINE_CLOCK         800
@@ -3389,6 +3390,7 @@ static const struct amd_pm_funcs kv_dpm_funcs = {
  	.get_vce_clock_state = amdgpu_get_vce_clock_state,
  	.check_state_equal = kv_check_state_equal,
  	.read_sensor = &kv_dpm_read_sensor,
+	.change_power_state = amdgpu_dpm_change_power_state_locked,
  };
 
  static const struct amdgpu_irq_src_funcs kv_dpm_irq_funcs = {
drivers/gpu/drm/amd/pm/powerplay/legacy_dpm.c +0 -0

This could get confused with all APIs that support legacy dpms. This file has only a subset of APIs to support legacy dpm. Needs a better name - powerplay_ctrl/powerplay_util ?

Thanks,
Lijo

Quoted 1,555 lines

new file mode 100644
index 000000000000..9427c1026e1d

drivers/gpu/drm/amd/pm/powerplay/legacy_dpm.c new file +1453 -0
@@ -0,0 +1,1453 @@
+/*
+ * Copyright 2021 Advanced Micro Devices, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#include "amdgpu.h"
+#include "amdgpu_atombios.h"
+#include "amdgpu_i2c.h"
+#include "atom.h"
+#include "amd_pcie.h"
+#include "legacy_dpm.h"
+
+#define amdgpu_dpm_pre_set_power_state(adev) \
+		((adev)->powerplay.pp_funcs->pre_set_power_state((adev)->powerplay.pp_handle))
+
+#define amdgpu_dpm_post_set_power_state(adev) \
+		((adev)->powerplay.pp_funcs->post_set_power_state((adev)->powerplay.pp_handle))
+
+#define amdgpu_dpm_display_configuration_changed(adev) \
+		((adev)->powerplay.pp_funcs->display_configuration_changed((adev)->powerplay.pp_handle))
+
+#define amdgpu_dpm_print_power_state(adev, ps) \
+		((adev)->powerplay.pp_funcs->print_power_state((adev)->powerplay.pp_handle, (ps)))
+
+#define amdgpu_dpm_vblank_too_short(adev) \
+		((adev)->powerplay.pp_funcs->vblank_too_short((adev)->powerplay.pp_handle))
+
+#define amdgpu_dpm_check_state_equal(adev, cps, rps, equal) \
+		((adev)->powerplay.pp_funcs->check_state_equal((adev)->powerplay.pp_handle, (cps), (rps), (equal)))
+
+int amdgpu_atombios_get_memory_pll_dividers(struct amdgpu_device *adev,
+					    u32 clock,
+					    bool strobe_mode,
+					    struct atom_mpll_param *mpll_param)
+{
+	COMPUTE_MEMORY_CLOCK_PARAM_PARAMETERS_V2_1 args;
+	int index = GetIndexIntoMasterTable(COMMAND, ComputeMemoryClockParam);
+	u8 frev, crev;
+
+	memset(&args, 0, sizeof(args));
+	memset(mpll_param, 0, sizeof(struct atom_mpll_param));
+
+	if (!amdgpu_atom_parse_cmd_header(adev->mode_info.atom_context, index, &frev, &crev))
+		return -EINVAL;
+
+	switch (frev) {
+	case 2:
+		switch (crev) {
+		case 1:
+			/* SI */
+			args.ulClock = cpu_to_le32(clock);	/* 10 khz */
+			args.ucInputFlag = 0;
+			if (strobe_mode)
+				args.ucInputFlag |= MPLL_INPUT_FLAG_STROBE_MODE_EN;
+
+			amdgpu_atom_execute_table(adev->mode_info.atom_context, index, (uint32_t *)&args);
+
+			mpll_param->clkfrac = le16_to_cpu(args.ulFbDiv.usFbDivFrac);
+			mpll_param->clkf = le16_to_cpu(args.ulFbDiv.usFbDiv);
+			mpll_param->post_div = args.ucPostDiv;
+			mpll_param->dll_speed = args.ucDllSpeed;
+			mpll_param->bwcntl = args.ucBWCntl;
+			mpll_param->vco_mode =
+				(args.ucPllCntlFlag & MPLL_CNTL_FLAG_VCO_MODE_MASK);
+			mpll_param->yclk_sel =
+				(args.ucPllCntlFlag & MPLL_CNTL_FLAG_BYPASS_DQ_PLL) ? 1 : 0;
+			mpll_param->qdr =
+				(args.ucPllCntlFlag & MPLL_CNTL_FLAG_QDR_ENABLE) ? 1 : 0;
+			mpll_param->half_rate =
+				(args.ucPllCntlFlag & MPLL_CNTL_FLAG_AD_HALF_RATE) ? 1 : 0;
+			break;
+		default:
+			return -EINVAL;
+		}
+		break;
+	default:
+		return -EINVAL;
+	}
+	return 0;
+}
+
+void amdgpu_atombios_set_engine_dram_timings(struct amdgpu_device *adev,
+					     u32 eng_clock, u32 mem_clock)
+{
+	SET_ENGINE_CLOCK_PS_ALLOCATION args;
+	int index = GetIndexIntoMasterTable(COMMAND, DynamicMemorySettings);
+	u32 tmp;
+
+	memset(&args, 0, sizeof(args));
+
+	tmp = eng_clock & SET_CLOCK_FREQ_MASK;
+	tmp |= (COMPUTE_ENGINE_PLL_PARAM << 24);
+
+	args.ulTargetEngineClock = cpu_to_le32(tmp);
+	if (mem_clock)
+		args.sReserved.ulClock = cpu_to_le32(mem_clock & SET_CLOCK_FREQ_MASK);
+
+	amdgpu_atom_execute_table(adev->mode_info.atom_context, index, (uint32_t *)&args);
+}
+
+union firmware_info {
+	ATOM_FIRMWARE_INFO info;
+	ATOM_FIRMWARE_INFO_V1_2 info_12;
+	ATOM_FIRMWARE_INFO_V1_3 info_13;
+	ATOM_FIRMWARE_INFO_V1_4 info_14;
+	ATOM_FIRMWARE_INFO_V2_1 info_21;
+	ATOM_FIRMWARE_INFO_V2_2 info_22;
+};
+
+void amdgpu_atombios_get_default_voltages(struct amdgpu_device *adev,
+					  u16 *vddc, u16 *vddci, u16 *mvdd)
+{
+	struct amdgpu_mode_info *mode_info = &adev->mode_info;
+	int index = GetIndexIntoMasterTable(DATA, FirmwareInfo);
+	u8 frev, crev;
+	u16 data_offset;
+	union firmware_info *firmware_info;
+
+	*vddc = 0;
+	*vddci = 0;
+	*mvdd = 0;
+
+	if (amdgpu_atom_parse_data_header(mode_info->atom_context, index, NULL,
+				   &frev, &crev, &data_offset)) {
+		firmware_info =
+			(union firmware_info *)(mode_info->atom_context->bios +
+						data_offset);
+		*vddc = le16_to_cpu(firmware_info->info_14.usBootUpVDDCVoltage);
+		if ((frev == 2) && (crev >= 2)) {
+			*vddci = le16_to_cpu(firmware_info->info_22.usBootUpVDDCIVoltage);
+			*mvdd = le16_to_cpu(firmware_info->info_22.usBootUpMVDDCVoltage);
+		}
+	}
+}
+
+union set_voltage {
+	struct _SET_VOLTAGE_PS_ALLOCATION alloc;
+	struct _SET_VOLTAGE_PARAMETERS v1;
+	struct _SET_VOLTAGE_PARAMETERS_V2 v2;
+	struct _SET_VOLTAGE_PARAMETERS_V1_3 v3;
+};
+
+int amdgpu_atombios_get_max_vddc(struct amdgpu_device *adev, u8 voltage_type,
+			     u16 voltage_id, u16 *voltage)
+{
+	union set_voltage args;
+	int index = GetIndexIntoMasterTable(COMMAND, SetVoltage);
+	u8 frev, crev;
+
+	if (!amdgpu_atom_parse_cmd_header(adev->mode_info.atom_context, index, &frev, &crev))
+		return -EINVAL;
+
+	switch (crev) {
+	case 1:
+		return -EINVAL;
+	case 2:
+		args.v2.ucVoltageType = SET_VOLTAGE_GET_MAX_VOLTAGE;
+		args.v2.ucVoltageMode = 0;
+		args.v2.usVoltageLevel = 0;
+
+		amdgpu_atom_execute_table(adev->mode_info.atom_context, index, (uint32_t *)&args);
+
+		*voltage = le16_to_cpu(args.v2.usVoltageLevel);
+		break;
+	case 3:
+		args.v3.ucVoltageType = voltage_type;
+		args.v3.ucVoltageMode = ATOM_GET_VOLTAGE_LEVEL;
+		args.v3.usVoltageLevel = cpu_to_le16(voltage_id);
+
+		amdgpu_atom_execute_table(adev->mode_info.atom_context, index, (uint32_t *)&args);
+
+		*voltage = le16_to_cpu(args.v3.usVoltageLevel);
+		break;
+	default:
+		DRM_ERROR("Unknown table version %d, %d\n", frev, crev);
+		return -EINVAL;
+	}
+
+	return 0;
+}
+
+int amdgpu_atombios_get_leakage_vddc_based_on_leakage_idx(struct amdgpu_device *adev,
+						      u16 *voltage,
+						      u16 leakage_idx)
+{
+	return amdgpu_atombios_get_max_vddc(adev, VOLTAGE_TYPE_VDDC, leakage_idx, voltage);
+}
+
+union voltage_object_info {
+	struct _ATOM_VOLTAGE_OBJECT_INFO v1;
+	struct _ATOM_VOLTAGE_OBJECT_INFO_V2 v2;
+	struct _ATOM_VOLTAGE_OBJECT_INFO_V3_1 v3;
+};
+
+union voltage_object {
+	struct _ATOM_VOLTAGE_OBJECT v1;
+	struct _ATOM_VOLTAGE_OBJECT_V2 v2;
+	union _ATOM_VOLTAGE_OBJECT_V3 v3;
+};
+
+static ATOM_VOLTAGE_OBJECT_V3 *amdgpu_atombios_lookup_voltage_object_v3(ATOM_VOLTAGE_OBJECT_INFO_V3_1 *v3,
+									u8 voltage_type, u8 voltage_mode)
+{
+	u32 size = le16_to_cpu(v3->sHeader.usStructureSize);
+	u32 offset = offsetof(ATOM_VOLTAGE_OBJECT_INFO_V3_1, asVoltageObj[0]);
+	u8 *start = (u8 *)v3;
+
+	while (offset < size) {
+		ATOM_VOLTAGE_OBJECT_V3 *vo = (ATOM_VOLTAGE_OBJECT_V3 *)(start + offset);
+		if ((vo->asGpioVoltageObj.sHeader.ucVoltageType == voltage_type) &&
+		    (vo->asGpioVoltageObj.sHeader.ucVoltageMode == voltage_mode))
+			return vo;
+		offset += le16_to_cpu(vo->asGpioVoltageObj.sHeader.usSize);
+	}
+	return NULL;
+}
+
+int amdgpu_atombios_get_svi2_info(struct amdgpu_device *adev,
+			      u8 voltage_type,
+			      u8 *svd_gpio_id, u8 *svc_gpio_id)
+{
+	int index = GetIndexIntoMasterTable(DATA, VoltageObjectInfo);
+	u8 frev, crev;
+	u16 data_offset, size;
+	union voltage_object_info *voltage_info;
+	union voltage_object *voltage_object = NULL;
+
+	if (amdgpu_atom_parse_data_header(adev->mode_info.atom_context, index, &size,
+				   &frev, &crev, &data_offset)) {
+		voltage_info = (union voltage_object_info *)
+			(adev->mode_info.atom_context->bios + data_offset);
+
+		switch (frev) {
+		case 3:
+			switch (crev) {
+			case 1:
+				voltage_object = (union voltage_object *)
+					amdgpu_atombios_lookup_voltage_object_v3(&voltage_info->v3,
+								      voltage_type,
+								      VOLTAGE_OBJ_SVID2);
+				if (voltage_object) {
+					*svd_gpio_id = voltage_object->v3.asSVID2Obj.ucSVDGpioId;
+					*svc_gpio_id = voltage_object->v3.asSVID2Obj.ucSVCGpioId;
+				} else {
+					return -EINVAL;
+				}
+				break;
+			default:
+				DRM_ERROR("unknown voltage object table\n");
+				return -EINVAL;
+			}
+			break;
+		default:
+			DRM_ERROR("unknown voltage object table\n");
+			return -EINVAL;
+		}
+
+	}
+	return 0;
+}
+
+bool
+amdgpu_atombios_is_voltage_gpio(struct amdgpu_device *adev,
+				u8 voltage_type, u8 voltage_mode)
+{
+	int index = GetIndexIntoMasterTable(DATA, VoltageObjectInfo);
+	u8 frev, crev;
+	u16 data_offset, size;
+	union voltage_object_info *voltage_info;
+
+	if (amdgpu_atom_parse_data_header(adev->mode_info.atom_context, index, &size,
+				   &frev, &crev, &data_offset)) {
+		voltage_info = (union voltage_object_info *)
+			(adev->mode_info.atom_context->bios + data_offset);
+
+		switch (frev) {
+		case 3:
+			switch (crev) {
+			case 1:
+				if (amdgpu_atombios_lookup_voltage_object_v3(&voltage_info->v3,
+								  voltage_type, voltage_mode))
+					return true;
+				break;
+			default:
+				DRM_ERROR("unknown voltage object table\n");
+				return false;
+			}
+			break;
+		default:
+			DRM_ERROR("unknown voltage object table\n");
+			return false;
+		}
+
+	}
+	return false;
+}
+
+int amdgpu_atombios_get_voltage_table(struct amdgpu_device *adev,
+				      u8 voltage_type, u8 voltage_mode,
+				      struct atom_voltage_table *voltage_table)
+{
+	int index = GetIndexIntoMasterTable(DATA, VoltageObjectInfo);
+	u8 frev, crev;
+	u16 data_offset, size;
+	int i;
+	union voltage_object_info *voltage_info;
+	union voltage_object *voltage_object = NULL;
+
+	if (amdgpu_atom_parse_data_header(adev->mode_info.atom_context, index, &size,
+				   &frev, &crev, &data_offset)) {
+		voltage_info = (union voltage_object_info *)
+			(adev->mode_info.atom_context->bios + data_offset);
+
+		switch (frev) {
+		case 3:
+			switch (crev) {
+			case 1:
+				voltage_object = (union voltage_object *)
+					amdgpu_atombios_lookup_voltage_object_v3(&voltage_info->v3,
+								      voltage_type, voltage_mode);
+				if (voltage_object) {
+					ATOM_GPIO_VOLTAGE_OBJECT_V3 *gpio =
+						&voltage_object->v3.asGpioVoltageObj;
+					VOLTAGE_LUT_ENTRY_V2 *lut;
+					if (gpio->ucGpioEntryNum > MAX_VOLTAGE_ENTRIES)
+						return -EINVAL;
+					lut = &gpio->asVolGpioLut[0];
+					for (i = 0; i < gpio->ucGpioEntryNum; i++) {
+						voltage_table->entries[i].value =
+							le16_to_cpu(lut->usVoltageValue);
+						voltage_table->entries[i].smio_low =
+							le32_to_cpu(lut->ulVoltageId);
+						lut = (VOLTAGE_LUT_ENTRY_V2 *)
+							((u8 *)lut + sizeof(VOLTAGE_LUT_ENTRY_V2));
+					}
+					voltage_table->mask_low = le32_to_cpu(gpio->ulGpioMaskVal);
+					voltage_table->count = gpio->ucGpioEntryNum;
+					voltage_table->phase_delay = gpio->ucPhaseDelay;
+					return 0;
+				}
+				break;
+			default:
+				DRM_ERROR("unknown voltage object table\n");
+				return -EINVAL;
+			}
+			break;
+		default:
+			DRM_ERROR("unknown voltage object table\n");
+			return -EINVAL;
+		}
+	}
+	return -EINVAL;
+}
+
+union vram_info {
+	struct _ATOM_VRAM_INFO_V3 v1_3;
+	struct _ATOM_VRAM_INFO_V4 v1_4;
+	struct _ATOM_VRAM_INFO_HEADER_V2_1 v2_1;
+};
+
+#define MEM_ID_MASK           0xff000000
+#define MEM_ID_SHIFT          24
+#define CLOCK_RANGE_MASK      0x00ffffff
+#define CLOCK_RANGE_SHIFT     0
+#define LOW_NIBBLE_MASK       0xf
+#define DATA_EQU_PREV         0
+#define DATA_FROM_TABLE       4
+
+int amdgpu_atombios_init_mc_reg_table(struct amdgpu_device *adev,
+				      u8 module_index,
+				      struct atom_mc_reg_table *reg_table)
+{
+	int index = GetIndexIntoMasterTable(DATA, VRAM_Info);
+	u8 frev, crev, num_entries, t_mem_id, num_ranges = 0;
+	u32 i = 0, j;
+	u16 data_offset, size;
+	union vram_info *vram_info;
+
+	memset(reg_table, 0, sizeof(struct atom_mc_reg_table));
+
+	if (amdgpu_atom_parse_data_header(adev->mode_info.atom_context, index, &size,
+				   &frev, &crev, &data_offset)) {
+		vram_info = (union vram_info *)
+			(adev->mode_info.atom_context->bios + data_offset);
+		switch (frev) {
+		case 1:
+			DRM_ERROR("old table version %d, %d\n", frev, crev);
+			return -EINVAL;
+		case 2:
+			switch (crev) {
+			case 1:
+				if (module_index < vram_info->v2_1.ucNumOfVRAMModule) {
+					ATOM_INIT_REG_BLOCK *reg_block =
+						(ATOM_INIT_REG_BLOCK *)
+						((u8 *)vram_info + le16_to_cpu(vram_info->v2_1.usMemClkPatchTblOffset));
+					ATOM_MEMORY_SETTING_DATA_BLOCK *reg_data =
+						(ATOM_MEMORY_SETTING_DATA_BLOCK *)
+						((u8 *)reg_block + (2 * sizeof(u16)) +
+						 le16_to_cpu(reg_block->usRegIndexTblSize));
+					ATOM_INIT_REG_INDEX_FORMAT *format = &reg_block->asRegIndexBuf[0];
+					num_entries = (u8)((le16_to_cpu(reg_block->usRegIndexTblSize)) /
+							   sizeof(ATOM_INIT_REG_INDEX_FORMAT)) - 1;
+					if (num_entries > VBIOS_MC_REGISTER_ARRAY_SIZE)
+						return -EINVAL;
+					while (i < num_entries) {
+						if (format->ucPreRegDataLength & ACCESS_PLACEHOLDER)
+							break;
+						reg_table->mc_reg_address[i].s1 =
+							(u16)(le16_to_cpu(format->usRegIndex));
+						reg_table->mc_reg_address[i].pre_reg_data =
+							(u8)(format->ucPreRegDataLength);
+						i++;
+						format = (ATOM_INIT_REG_INDEX_FORMAT *)
+							((u8 *)format + sizeof(ATOM_INIT_REG_INDEX_FORMAT));
+					}
+					reg_table->last = i;
+					while ((le32_to_cpu(*(u32 *)reg_data) != END_OF_REG_DATA_BLOCK) &&
+					       (num_ranges < VBIOS_MAX_AC_TIMING_ENTRIES)) {
+						t_mem_id = (u8)((le32_to_cpu(*(u32 *)reg_data) & MEM_ID_MASK)
+								>> MEM_ID_SHIFT);
+						if (module_index == t_mem_id) {
+							reg_table->mc_reg_table_entry[num_ranges].mclk_max =
+								(u32)((le32_to_cpu(*(u32 *)reg_data) & CLOCK_RANGE_MASK)
+								      >> CLOCK_RANGE_SHIFT);
+							for (i = 0, j = 1; i < reg_table->last; i++) {
+								if ((reg_table->mc_reg_address[i].pre_reg_data & LOW_NIBBLE_MASK) == DATA_FROM_TABLE) {
+									reg_table->mc_reg_table_entry[num_ranges].mc_data[i] =
+										(u32)le32_to_cpu(*((u32 *)reg_data + j));
+									j++;
+								} else if ((reg_table->mc_reg_address[i].pre_reg_data & LOW_NIBBLE_MASK) == DATA_EQU_PREV) {
+									reg_table->mc_reg_table_entry[num_ranges].mc_data[i] =
+										reg_table->mc_reg_table_entry[num_ranges].mc_data[i - 1];
+								}
+							}
+							num_ranges++;
+						}
+						reg_data = (ATOM_MEMORY_SETTING_DATA_BLOCK *)
+							((u8 *)reg_data + le16_to_cpu(reg_block->usRegDataBlkSize));
+					}
+					if (le32_to_cpu(*(u32 *)reg_data) != END_OF_REG_DATA_BLOCK)
+						return -EINVAL;
+					reg_table->num_entries = num_ranges;
+				} else
+					return -EINVAL;
+				break;
+			default:
+				DRM_ERROR("Unknown table version %d, %d\n", frev, crev);
+				return -EINVAL;
+			}
+			break;
+		default:
+			DRM_ERROR("Unknown table version %d, %d\n", frev, crev);
+			return -EINVAL;
+		}
+		return 0;
+	}
+	return -EINVAL;
+}
+
+void amdgpu_dpm_print_class_info(u32 class, u32 class2)
+{
+	const char *s;
+
+	switch (class & ATOM_PPLIB_CLASSIFICATION_UI_MASK) {
+	case ATOM_PPLIB_CLASSIFICATION_UI_NONE:
+	default:
+		s = "none";
+		break;
+	case ATOM_PPLIB_CLASSIFICATION_UI_BATTERY:
+		s = "battery";
+		break;
+	case ATOM_PPLIB_CLASSIFICATION_UI_BALANCED:
+		s = "balanced";
+		break;
+	case ATOM_PPLIB_CLASSIFICATION_UI_PERFORMANCE:
+		s = "performance";
+		break;
+	}
+	printk("\tui class: %s\n", s);
+	printk("\tinternal class:");
+	if (((class & ~ATOM_PPLIB_CLASSIFICATION_UI_MASK) == 0) &&
+	    (class2 == 0))
+		pr_cont(" none");
+	else {
+		if (class & ATOM_PPLIB_CLASSIFICATION_BOOT)
+			pr_cont(" boot");
+		if (class & ATOM_PPLIB_CLASSIFICATION_THERMAL)
+			pr_cont(" thermal");
+		if (class & ATOM_PPLIB_CLASSIFICATION_LIMITEDPOWERSOURCE)
+			pr_cont(" limited_pwr");
+		if (class & ATOM_PPLIB_CLASSIFICATION_REST)
+			pr_cont(" rest");
+		if (class & ATOM_PPLIB_CLASSIFICATION_FORCED)
+			pr_cont(" forced");
+		if (class & ATOM_PPLIB_CLASSIFICATION_3DPERFORMANCE)
+			pr_cont(" 3d_perf");
+		if (class & ATOM_PPLIB_CLASSIFICATION_OVERDRIVETEMPLATE)
+			pr_cont(" ovrdrv");
+		if (class & ATOM_PPLIB_CLASSIFICATION_UVDSTATE)
+			pr_cont(" uvd");
+		if (class & ATOM_PPLIB_CLASSIFICATION_3DLOW)
+			pr_cont(" 3d_low");
+		if (class & ATOM_PPLIB_CLASSIFICATION_ACPI)
+			pr_cont(" acpi");
+		if (class & ATOM_PPLIB_CLASSIFICATION_HD2STATE)
+			pr_cont(" uvd_hd2");
+		if (class & ATOM_PPLIB_CLASSIFICATION_HDSTATE)
+			pr_cont(" uvd_hd");
+		if (class & ATOM_PPLIB_CLASSIFICATION_SDSTATE)
+			pr_cont(" uvd_sd");
+		if (class2 & ATOM_PPLIB_CLASSIFICATION2_LIMITEDPOWERSOURCE_2)
+			pr_cont(" limited_pwr2");
+		if (class2 & ATOM_PPLIB_CLASSIFICATION2_ULV)
+			pr_cont(" ulv");
+		if (class2 & ATOM_PPLIB_CLASSIFICATION2_MVC)
+			pr_cont(" uvd_mvc");
+	}
+	pr_cont("\n");
+}
+
+void amdgpu_dpm_print_cap_info(u32 caps)
+{
+	printk("\tcaps:");
+	if (caps & ATOM_PPLIB_SINGLE_DISPLAY_ONLY)
+		pr_cont(" single_disp");
+	if (caps & ATOM_PPLIB_SUPPORTS_VIDEO_PLAYBACK)
+		pr_cont(" video");
+	if (caps & ATOM_PPLIB_DISALLOW_ON_DC)
+		pr_cont(" no_dc");
+	pr_cont("\n");
+}
+
+void amdgpu_dpm_print_ps_status(struct amdgpu_device *adev,
+				struct amdgpu_ps *rps)
+{
+	printk("\tstatus:");
+	if (rps == adev->pm.dpm.current_ps)
+		pr_cont(" c");
+	if (rps == adev->pm.dpm.requested_ps)
+		pr_cont(" r");
+	if (rps == adev->pm.dpm.boot_ps)
+		pr_cont(" b");
+	pr_cont("\n");
+}
+
+void amdgpu_pm_print_power_states(struct amdgpu_device *adev)
+{
+	int i;
+
+	if (adev->powerplay.pp_funcs->print_power_state == NULL)
+		return;
+
+	for (i = 0; i < adev->pm.dpm.num_ps; i++)
+		amdgpu_dpm_print_power_state(adev, &adev->pm.dpm.ps[i]);
+
+}
+
+union power_info {
+	struct _ATOM_POWERPLAY_INFO info;
+	struct _ATOM_POWERPLAY_INFO_V2 info_2;
+	struct _ATOM_POWERPLAY_INFO_V3 info_3;
+	struct _ATOM_PPLIB_POWERPLAYTABLE pplib;
+	struct _ATOM_PPLIB_POWERPLAYTABLE2 pplib2;
+	struct _ATOM_PPLIB_POWERPLAYTABLE3 pplib3;
+	struct _ATOM_PPLIB_POWERPLAYTABLE4 pplib4;
+	struct _ATOM_PPLIB_POWERPLAYTABLE5 pplib5;
+};
+
+int amdgpu_get_platform_caps(struct amdgpu_device *adev)
+{
+	struct amdgpu_mode_info *mode_info = &adev->mode_info;
+	union power_info *power_info;
+	int index = GetIndexIntoMasterTable(DATA, PowerPlayInfo);
+	u16 data_offset;
+	u8 frev, crev;
+
+	if (!amdgpu_atom_parse_data_header(mode_info->atom_context, index, NULL,
+				   &frev, &crev, &data_offset))
+		return -EINVAL;
+	power_info = (union power_info *)(mode_info->atom_context->bios + data_offset);
+
+	adev->pm.dpm.platform_caps = le32_to_cpu(power_info->pplib.ulPlatformCaps);
+	adev->pm.dpm.backbias_response_time = le16_to_cpu(power_info->pplib.usBackbiasTime);
+	adev->pm.dpm.voltage_response_time = le16_to_cpu(power_info->pplib.usVoltageTime);
+
+	return 0;
+}
+
+union fan_info {
+	struct _ATOM_PPLIB_FANTABLE fan;
+	struct _ATOM_PPLIB_FANTABLE2 fan2;
+	struct _ATOM_PPLIB_FANTABLE3 fan3;
+};
+
+static int amdgpu_parse_clk_voltage_dep_table(struct amdgpu_clock_voltage_dependency_table *amdgpu_table,
+					      ATOM_PPLIB_Clock_Voltage_Dependency_Table *atom_table)
+{
+	u32 size = atom_table->ucNumEntries *
+		sizeof(struct amdgpu_clock_voltage_dependency_entry);
+	int i;
+	ATOM_PPLIB_Clock_Voltage_Dependency_Record *entry;
+
+	amdgpu_table->entries = kzalloc(size, GFP_KERNEL);
+	if (!amdgpu_table->entries)
+		return -ENOMEM;
+
+	entry = &atom_table->entries[0];
+	for (i = 0; i < atom_table->ucNumEntries; i++) {
+		amdgpu_table->entries[i].clk = le16_to_cpu(entry->usClockLow) |
+			(entry->ucClockHigh << 16);
+		amdgpu_table->entries[i].v = le16_to_cpu(entry->usVoltage);
+		entry = (ATOM_PPLIB_Clock_Voltage_Dependency_Record *)
+			((u8 *)entry + sizeof(ATOM_PPLIB_Clock_Voltage_Dependency_Record));
+	}
+	amdgpu_table->count = atom_table->ucNumEntries;
+
+	return 0;
+}
+
+/* sizeof(ATOM_PPLIB_EXTENDEDHEADER) */
+#define SIZE_OF_ATOM_PPLIB_EXTENDEDHEADER_V2 12
+#define SIZE_OF_ATOM_PPLIB_EXTENDEDHEADER_V3 14
+#define SIZE_OF_ATOM_PPLIB_EXTENDEDHEADER_V4 16
+#define SIZE_OF_ATOM_PPLIB_EXTENDEDHEADER_V5 18
+#define SIZE_OF_ATOM_PPLIB_EXTENDEDHEADER_V6 20
+#define SIZE_OF_ATOM_PPLIB_EXTENDEDHEADER_V7 22
+#define SIZE_OF_ATOM_PPLIB_EXTENDEDHEADER_V8 24
+#define SIZE_OF_ATOM_PPLIB_EXTENDEDHEADER_V9 26
+
+int amdgpu_parse_extended_power_table(struct amdgpu_device *adev)
+{
+	struct amdgpu_mode_info *mode_info = &adev->mode_info;
+	union power_info *power_info;
+	union fan_info *fan_info;
+	ATOM_PPLIB_Clock_Voltage_Dependency_Table *dep_table;
+	int index = GetIndexIntoMasterTable(DATA, PowerPlayInfo);
+	u16 data_offset;
+	u8 frev, crev;
+	int ret, i;
+
+	if (!amdgpu_atom_parse_data_header(mode_info->atom_context, index, NULL,
+				   &frev, &crev, &data_offset))
+		return -EINVAL;
+	power_info = (union power_info *)(mode_info->atom_context->bios + data_offset);
+
+	/* fan table */
+	if (le16_to_cpu(power_info->pplib.usTableSize) >=
+	    sizeof(struct _ATOM_PPLIB_POWERPLAYTABLE3)) {
+		if (power_info->pplib3.usFanTableOffset) {
+			fan_info = (union fan_info *)(mode_info->atom_context->bios + data_offset +
+						      le16_to_cpu(power_info->pplib3.usFanTableOffset));
+			adev->pm.dpm.fan.t_hyst = fan_info->fan.ucTHyst;
+			adev->pm.dpm.fan.t_min = le16_to_cpu(fan_info->fan.usTMin);
+			adev->pm.dpm.fan.t_med = le16_to_cpu(fan_info->fan.usTMed);
+			adev->pm.dpm.fan.t_high = le16_to_cpu(fan_info->fan.usTHigh);
+			adev->pm.dpm.fan.pwm_min = le16_to_cpu(fan_info->fan.usPWMMin);
+			adev->pm.dpm.fan.pwm_med = le16_to_cpu(fan_info->fan.usPWMMed);
+			adev->pm.dpm.fan.pwm_high = le16_to_cpu(fan_info->fan.usPWMHigh);
+			if (fan_info->fan.ucFanTableFormat >= 2)
+				adev->pm.dpm.fan.t_max = le16_to_cpu(fan_info->fan2.usTMax);
+			else
+				adev->pm.dpm.fan.t_max = 10900;
+			adev->pm.dpm.fan.cycle_delay = 100000;
+			if (fan_info->fan.ucFanTableFormat >= 3) {
+				adev->pm.dpm.fan.control_mode = fan_info->fan3.ucFanControlMode;
+				adev->pm.dpm.fan.default_max_fan_pwm =
+					le16_to_cpu(fan_info->fan3.usFanPWMMax);
+				adev->pm.dpm.fan.default_fan_output_sensitivity = 4836;
+				adev->pm.dpm.fan.fan_output_sensitivity =
+					le16_to_cpu(fan_info->fan3.usFanOutputSensitivity);
+			}
+			adev->pm.dpm.fan.ucode_fan_control = true;
+		}
+	}
+
+	/* clock dependancy tables, shedding tables */
+	if (le16_to_cpu(power_info->pplib.usTableSize) >=
+	    sizeof(struct _ATOM_PPLIB_POWERPLAYTABLE4)) {
+		if (power_info->pplib4.usVddcDependencyOnSCLKOffset) {
+			dep_table = (ATOM_PPLIB_Clock_Voltage_Dependency_Table *)
+				(mode_info->atom_context->bios + data_offset +
+				 le16_to_cpu(power_info->pplib4.usVddcDependencyOnSCLKOffset));
+			ret = amdgpu_parse_clk_voltage_dep_table(&adev->pm.dpm.dyn_state.vddc_dependency_on_sclk,
+								 dep_table);
+			if (ret) {
+				amdgpu_free_extended_power_table(adev);
+				return ret;
+			}
+		}
+		if (power_info->pplib4.usVddciDependencyOnMCLKOffset) {
+			dep_table = (ATOM_PPLIB_Clock_Voltage_Dependency_Table *)
+				(mode_info->atom_context->bios + data_offset +
+				 le16_to_cpu(power_info->pplib4.usVddciDependencyOnMCLKOffset));
+			ret = amdgpu_parse_clk_voltage_dep_table(&adev->pm.dpm.dyn_state.vddci_dependency_on_mclk,
+								 dep_table);
+			if (ret) {
+				amdgpu_free_extended_power_table(adev);
+				return ret;
+			}
+		}
+		if (power_info->pplib4.usVddcDependencyOnMCLKOffset) {
+			dep_table = (ATOM_PPLIB_Clock_Voltage_Dependency_Table *)
+				(mode_info->atom_context->bios + data_offset +
+				 le16_to_cpu(power_info->pplib4.usVddcDependencyOnMCLKOffset));
+			ret = amdgpu_parse_clk_voltage_dep_table(&adev->pm.dpm.dyn_state.vddc_dependency_on_mclk,
+								 dep_table);
+			if (ret) {
+				amdgpu_free_extended_power_table(adev);
+				return ret;
+			}
+		}
+		if (power_info->pplib4.usMvddDependencyOnMCLKOffset) {
+			dep_table = (ATOM_PPLIB_Clock_Voltage_Dependency_Table *)
+				(mode_info->atom_context->bios + data_offset +
+				 le16_to_cpu(power_info->pplib4.usMvddDependencyOnMCLKOffset));
+			ret = amdgpu_parse_clk_voltage_dep_table(&adev->pm.dpm.dyn_state.mvdd_dependency_on_mclk,
+								 dep_table);
+			if (ret) {
+				amdgpu_free_extended_power_table(adev);
+				return ret;
+			}
+		}
+		if (power_info->pplib4.usMaxClockVoltageOnDCOffset) {
+			ATOM_PPLIB_Clock_Voltage_Limit_Table *clk_v =
+				(ATOM_PPLIB_Clock_Voltage_Limit_Table *)
+				(mode_info->atom_context->bios + data_offset +
+				 le16_to_cpu(power_info->pplib4.usMaxClockVoltageOnDCOffset));
+			if (clk_v->ucNumEntries) {
+				adev->pm.dpm.dyn_state.max_clock_voltage_on_dc.sclk =
+					le16_to_cpu(clk_v->entries[0].usSclkLow) |
+					(clk_v->entries[0].ucSclkHigh << 16);
+				adev->pm.dpm.dyn_state.max_clock_voltage_on_dc.mclk =
+					le16_to_cpu(clk_v->entries[0].usMclkLow) |
+					(clk_v->entries[0].ucMclkHigh << 16);
+				adev->pm.dpm.dyn_state.max_clock_voltage_on_dc.vddc =
+					le16_to_cpu(clk_v->entries[0].usVddc);
+				adev->pm.dpm.dyn_state.max_clock_voltage_on_dc.vddci =
+					le16_to_cpu(clk_v->entries[0].usVddci);
+			}
+		}
+		if (power_info->pplib4.usVddcPhaseShedLimitsTableOffset) {
+			ATOM_PPLIB_PhaseSheddingLimits_Table *psl =
+				(ATOM_PPLIB_PhaseSheddingLimits_Table *)
+				(mode_info->atom_context->bios + data_offset +
+				 le16_to_cpu(power_info->pplib4.usVddcPhaseShedLimitsTableOffset));
+			ATOM_PPLIB_PhaseSheddingLimits_Record *entry;
+
+			adev->pm.dpm.dyn_state.phase_shedding_limits_table.entries =
+				kcalloc(psl->ucNumEntries,
+					sizeof(struct amdgpu_phase_shedding_limits_entry),
+					GFP_KERNEL);
+			if (!adev->pm.dpm.dyn_state.phase_shedding_limits_table.entries) {
+				amdgpu_free_extended_power_table(adev);
+				return -ENOMEM;
+			}
+
+			entry = &psl->entries[0];
+			for (i = 0; i < psl->ucNumEntries; i++) {
+				adev->pm.dpm.dyn_state.phase_shedding_limits_table.entries[i].sclk =
+					le16_to_cpu(entry->usSclkLow) | (entry->ucSclkHigh << 16);
+				adev->pm.dpm.dyn_state.phase_shedding_limits_table.entries[i].mclk =
+					le16_to_cpu(entry->usMclkLow) | (entry->ucMclkHigh << 16);
+				adev->pm.dpm.dyn_state.phase_shedding_limits_table.entries[i].voltage =
+					le16_to_cpu(entry->usVoltage);
+				entry = (ATOM_PPLIB_PhaseSheddingLimits_Record *)
+					((u8 *)entry + sizeof(ATOM_PPLIB_PhaseSheddingLimits_Record));
+			}
+			adev->pm.dpm.dyn_state.phase_shedding_limits_table.count =
+				psl->ucNumEntries;
+		}
+	}
+
+	/* cac data */
+	if (le16_to_cpu(power_info->pplib.usTableSize) >=
+	    sizeof(struct _ATOM_PPLIB_POWERPLAYTABLE5)) {
+		adev->pm.dpm.tdp_limit = le32_to_cpu(power_info->pplib5.ulTDPLimit);
+		adev->pm.dpm.near_tdp_limit = le32_to_cpu(power_info->pplib5.ulNearTDPLimit);
+		adev->pm.dpm.near_tdp_limit_adjusted = adev->pm.dpm.near_tdp_limit;
+		adev->pm.dpm.tdp_od_limit = le16_to_cpu(power_info->pplib5.usTDPODLimit);
+		if (adev->pm.dpm.tdp_od_limit)
+			adev->pm.dpm.power_control = true;
+		else
+			adev->pm.dpm.power_control = false;
+		adev->pm.dpm.tdp_adjustment = 0;
+		adev->pm.dpm.sq_ramping_threshold = le32_to_cpu(power_info->pplib5.ulSQRampingThreshold);
+		adev->pm.dpm.cac_leakage = le32_to_cpu(power_info->pplib5.ulCACLeakage);
+		adev->pm.dpm.load_line_slope = le16_to_cpu(power_info->pplib5.usLoadLineSlope);
+		if (power_info->pplib5.usCACLeakageTableOffset) {
+			ATOM_PPLIB_CAC_Leakage_Table *cac_table =
+				(ATOM_PPLIB_CAC_Leakage_Table *)
+				(mode_info->atom_context->bios + data_offset +
+				 le16_to_cpu(power_info->pplib5.usCACLeakageTableOffset));
+			ATOM_PPLIB_CAC_Leakage_Record *entry;
+			u32 size = cac_table->ucNumEntries * sizeof(struct amdgpu_cac_leakage_table);
+			adev->pm.dpm.dyn_state.cac_leakage_table.entries = kzalloc(size, GFP_KERNEL);
+			if (!adev->pm.dpm.dyn_state.cac_leakage_table.entries) {
+				amdgpu_free_extended_power_table(adev);
+				return -ENOMEM;
+			}
+			entry = &cac_table->entries[0];
+			for (i = 0; i < cac_table->ucNumEntries; i++) {
+				if (adev->pm.dpm.platform_caps & ATOM_PP_PLATFORM_CAP_EVV) {
+					adev->pm.dpm.dyn_state.cac_leakage_table.entries[i].vddc1 =
+						le16_to_cpu(entry->usVddc1);
+					adev->pm.dpm.dyn_state.cac_leakage_table.entries[i].vddc2 =
+						le16_to_cpu(entry->usVddc2);
+					adev->pm.dpm.dyn_state.cac_leakage_table.entries[i].vddc3 =
+						le16_to_cpu(entry->usVddc3);
+				} else {
+					adev->pm.dpm.dyn_state.cac_leakage_table.entries[i].vddc =
+						le16_to_cpu(entry->usVddc);
+					adev->pm.dpm.dyn_state.cac_leakage_table.entries[i].leakage =
+						le32_to_cpu(entry->ulLeakageValue);
+				}
+				entry = (ATOM_PPLIB_CAC_Leakage_Record *)
+					((u8 *)entry + sizeof(ATOM_PPLIB_CAC_Leakage_Record));
+			}
+			adev->pm.dpm.dyn_state.cac_leakage_table.count = cac_table->ucNumEntries;
+		}
+	}
+
+	/* ext tables */
+	if (le16_to_cpu(power_info->pplib.usTableSize) >=
+	    sizeof(struct _ATOM_PPLIB_POWERPLAYTABLE3)) {
+		ATOM_PPLIB_EXTENDEDHEADER *ext_hdr = (ATOM_PPLIB_EXTENDEDHEADER *)
+			(mode_info->atom_context->bios + data_offset +
+			 le16_to_cpu(power_info->pplib3.usExtendendedHeaderOffset));
+		if ((le16_to_cpu(ext_hdr->usSize) >= SIZE_OF_ATOM_PPLIB_EXTENDEDHEADER_V2) &&
+			ext_hdr->usVCETableOffset) {
+			VCEClockInfoArray *array = (VCEClockInfoArray *)
+				(mode_info->atom_context->bios + data_offset +
+				 le16_to_cpu(ext_hdr->usVCETableOffset) + 1);
+			ATOM_PPLIB_VCE_Clock_Voltage_Limit_Table *limits =
+				(ATOM_PPLIB_VCE_Clock_Voltage_Limit_Table *)
+				(mode_info->atom_context->bios + data_offset +
+				 le16_to_cpu(ext_hdr->usVCETableOffset) + 1 +
+				 1 + array->ucNumEntries * sizeof(VCEClockInfo));
+			ATOM_PPLIB_VCE_State_Table *states =
+				(ATOM_PPLIB_VCE_State_Table *)
+				(mode_info->atom_context->bios + data_offset +
+				 le16_to_cpu(ext_hdr->usVCETableOffset) + 1 +
+				 1 + (array->ucNumEntries * sizeof (VCEClockInfo)) +
+				 1 + (limits->numEntries * sizeof(ATOM_PPLIB_VCE_Clock_Voltage_Limit_Record)));
+			ATOM_PPLIB_VCE_Clock_Voltage_Limit_Record *entry;
+			ATOM_PPLIB_VCE_State_Record *state_entry;
+			VCEClockInfo *vce_clk;
+			u32 size = limits->numEntries *
+				sizeof(struct amdgpu_vce_clock_voltage_dependency_entry);
+			adev->pm.dpm.dyn_state.vce_clock_voltage_dependency_table.entries =
+				kzalloc(size, GFP_KERNEL);
+			if (!adev->pm.dpm.dyn_state.vce_clock_voltage_dependency_table.entries) {
+				amdgpu_free_extended_power_table(adev);
+				return -ENOMEM;
+			}
+			adev->pm.dpm.dyn_state.vce_clock_voltage_dependency_table.count =
+				limits->numEntries;
+			entry = &limits->entries[0];
+			state_entry = &states->entries[0];
+			for (i = 0; i < limits->numEntries; i++) {
+				vce_clk = (VCEClockInfo *)
+					((u8 *)&array->entries[0] +
+					 (entry->ucVCEClockInfoIndex * sizeof(VCEClockInfo)));
+				adev->pm.dpm.dyn_state.vce_clock_voltage_dependency_table.entries[i].evclk =
+					le16_to_cpu(vce_clk->usEVClkLow) | (vce_clk->ucEVClkHigh << 16);
+				adev->pm.dpm.dyn_state.vce_clock_voltage_dependency_table.entries[i].ecclk =
+					le16_to_cpu(vce_clk->usECClkLow) | (vce_clk->ucECClkHigh << 16);
+				adev->pm.dpm.dyn_state.vce_clock_voltage_dependency_table.entries[i].v =
+					le16_to_cpu(entry->usVoltage);
+				entry = (ATOM_PPLIB_VCE_Clock_Voltage_Limit_Record *)
+					((u8 *)entry + sizeof(ATOM_PPLIB_VCE_Clock_Voltage_Limit_Record));
+			}
+			adev->pm.dpm.num_of_vce_states =
+					states->numEntries > AMD_MAX_VCE_LEVELS ?
+					AMD_MAX_VCE_LEVELS : states->numEntries;
+			for (i = 0; i < adev->pm.dpm.num_of_vce_states; i++) {
+				vce_clk = (VCEClockInfo *)
+					((u8 *)&array->entries[0] +
+					 (state_entry->ucVCEClockInfoIndex * sizeof(VCEClockInfo)));
+				adev->pm.dpm.vce_states[i].evclk =
+					le16_to_cpu(vce_clk->usEVClkLow) | (vce_clk->ucEVClkHigh << 16);
+				adev->pm.dpm.vce_states[i].ecclk =
+					le16_to_cpu(vce_clk->usECClkLow) | (vce_clk->ucECClkHigh << 16);
+				adev->pm.dpm.vce_states[i].clk_idx =
+					state_entry->ucClockInfoIndex & 0x3f;
+				adev->pm.dpm.vce_states[i].pstate =
+					(state_entry->ucClockInfoIndex & 0xc0) >> 6;
+				state_entry = (ATOM_PPLIB_VCE_State_Record *)
+					((u8 *)state_entry + sizeof(ATOM_PPLIB_VCE_State_Record));
+			}
+		}
+		if ((le16_to_cpu(ext_hdr->usSize) >= SIZE_OF_ATOM_PPLIB_EXTENDEDHEADER_V3) &&
+			ext_hdr->usUVDTableOffset) {
+			UVDClockInfoArray *array = (UVDClockInfoArray *)
+				(mode_info->atom_context->bios + data_offset +
+				 le16_to_cpu(ext_hdr->usUVDTableOffset) + 1);
+			ATOM_PPLIB_UVD_Clock_Voltage_Limit_Table *limits =
+				(ATOM_PPLIB_UVD_Clock_Voltage_Limit_Table *)
+				(mode_info->atom_context->bios + data_offset +
+				 le16_to_cpu(ext_hdr->usUVDTableOffset) + 1 +
+				 1 + (array->ucNumEntries * sizeof (UVDClockInfo)));
+			ATOM_PPLIB_UVD_Clock_Voltage_Limit_Record *entry;
+			u32 size = limits->numEntries *
+				sizeof(struct amdgpu_uvd_clock_voltage_dependency_entry);
+			adev->pm.dpm.dyn_state.uvd_clock_voltage_dependency_table.entries =
+				kzalloc(size, GFP_KERNEL);
+			if (!adev->pm.dpm.dyn_state.uvd_clock_voltage_dependency_table.entries) {
+				amdgpu_free_extended_power_table(adev);
+				return -ENOMEM;
+			}
+			adev->pm.dpm.dyn_state.uvd_clock_voltage_dependency_table.count =
+				limits->numEntries;
+			entry = &limits->entries[0];
+			for (i = 0; i < limits->numEntries; i++) {
+				UVDClockInfo *uvd_clk = (UVDClockInfo *)
+					((u8 *)&array->entries[0] +
+					 (entry->ucUVDClockInfoIndex * sizeof(UVDClockInfo)));
+				adev->pm.dpm.dyn_state.uvd_clock_voltage_dependency_table.entries[i].vclk =
+					le16_to_cpu(uvd_clk->usVClkLow) | (uvd_clk->ucVClkHigh << 16);
+				adev->pm.dpm.dyn_state.uvd_clock_voltage_dependency_table.entries[i].dclk =
+					le16_to_cpu(uvd_clk->usDClkLow) | (uvd_clk->ucDClkHigh << 16);
+				adev->pm.dpm.dyn_state.uvd_clock_voltage_dependency_table.entries[i].v =
+					le16_to_cpu(entry->usVoltage);
+				entry = (ATOM_PPLIB_UVD_Clock_Voltage_Limit_Record *)
+					((u8 *)entry + sizeof(ATOM_PPLIB_UVD_Clock_Voltage_Limit_Record));
+			}
+		}
+		if ((le16_to_cpu(ext_hdr->usSize) >= SIZE_OF_ATOM_PPLIB_EXTENDEDHEADER_V4) &&
+			ext_hdr->usSAMUTableOffset) {
+			ATOM_PPLIB_SAMClk_Voltage_Limit_Table *limits =
+				(ATOM_PPLIB_SAMClk_Voltage_Limit_Table *)
+				(mode_info->atom_context->bios + data_offset +
+				 le16_to_cpu(ext_hdr->usSAMUTableOffset) + 1);
+			ATOM_PPLIB_SAMClk_Voltage_Limit_Record *entry;
+			u32 size = limits->numEntries *
+				sizeof(struct amdgpu_clock_voltage_dependency_entry);
+			adev->pm.dpm.dyn_state.samu_clock_voltage_dependency_table.entries =
+				kzalloc(size, GFP_KERNEL);
+			if (!adev->pm.dpm.dyn_state.samu_clock_voltage_dependency_table.entries) {
+				amdgpu_free_extended_power_table(adev);
+				return -ENOMEM;
+			}
+			adev->pm.dpm.dyn_state.samu_clock_voltage_dependency_table.count =
+				limits->numEntries;
+			entry = &limits->entries[0];
+			for (i = 0; i < limits->numEntries; i++) {
+				adev->pm.dpm.dyn_state.samu_clock_voltage_dependency_table.entries[i].clk =
+					le16_to_cpu(entry->usSAMClockLow) | (entry->ucSAMClockHigh << 16);
+				adev->pm.dpm.dyn_state.samu_clock_voltage_dependency_table.entries[i].v =
+					le16_to_cpu(entry->usVoltage);
+				entry = (ATOM_PPLIB_SAMClk_Voltage_Limit_Record *)
+					((u8 *)entry + sizeof(ATOM_PPLIB_SAMClk_Voltage_Limit_Record));
+			}
+		}
+		if ((le16_to_cpu(ext_hdr->usSize) >= SIZE_OF_ATOM_PPLIB_EXTENDEDHEADER_V5) &&
+		    ext_hdr->usPPMTableOffset) {
+			ATOM_PPLIB_PPM_Table *ppm = (ATOM_PPLIB_PPM_Table *)
+				(mode_info->atom_context->bios + data_offset +
+				 le16_to_cpu(ext_hdr->usPPMTableOffset));
+			adev->pm.dpm.dyn_state.ppm_table =
+				kzalloc(sizeof(struct amdgpu_ppm_table), GFP_KERNEL);
+			if (!adev->pm.dpm.dyn_state.ppm_table) {
+				amdgpu_free_extended_power_table(adev);
+				return -ENOMEM;
+			}
+			adev->pm.dpm.dyn_state.ppm_table->ppm_design = ppm->ucPpmDesign;
+			adev->pm.dpm.dyn_state.ppm_table->cpu_core_number =
+				le16_to_cpu(ppm->usCpuCoreNumber);
+			adev->pm.dpm.dyn_state.ppm_table->platform_tdp =
+				le32_to_cpu(ppm->ulPlatformTDP);
+			adev->pm.dpm.dyn_state.ppm_table->small_ac_platform_tdp =
+				le32_to_cpu(ppm->ulSmallACPlatformTDP);
+			adev->pm.dpm.dyn_state.ppm_table->platform_tdc =
+				le32_to_cpu(ppm->ulPlatformTDC);
+			adev->pm.dpm.dyn_state.ppm_table->small_ac_platform_tdc =
+				le32_to_cpu(ppm->ulSmallACPlatformTDC);
+			adev->pm.dpm.dyn_state.ppm_table->apu_tdp =
+				le32_to_cpu(ppm->ulApuTDP);
+			adev->pm.dpm.dyn_state.ppm_table->dgpu_tdp =
+				le32_to_cpu(ppm->ulDGpuTDP);
+			adev->pm.dpm.dyn_state.ppm_table->dgpu_ulv_power =
+				le32_to_cpu(ppm->ulDGpuUlvPower);
+			adev->pm.dpm.dyn_state.ppm_table->tj_max =
+				le32_to_cpu(ppm->ulTjmax);
+		}
+		if ((le16_to_cpu(ext_hdr->usSize) >= SIZE_OF_ATOM_PPLIB_EXTENDEDHEADER_V6) &&
+			ext_hdr->usACPTableOffset) {
+			ATOM_PPLIB_ACPClk_Voltage_Limit_Table *limits =
+				(ATOM_PPLIB_ACPClk_Voltage_Limit_Table *)
+				(mode_info->atom_context->bios + data_offset +
+				 le16_to_cpu(ext_hdr->usACPTableOffset) + 1);
+			ATOM_PPLIB_ACPClk_Voltage_Limit_Record *entry;
+			u32 size = limits->numEntries *
+				sizeof(struct amdgpu_clock_voltage_dependency_entry);
+			adev->pm.dpm.dyn_state.acp_clock_voltage_dependency_table.entries =
+				kzalloc(size, GFP_KERNEL);
+			if (!adev->pm.dpm.dyn_state.acp_clock_voltage_dependency_table.entries) {
+				amdgpu_free_extended_power_table(adev);
+				return -ENOMEM;
+			}
+			adev->pm.dpm.dyn_state.acp_clock_voltage_dependency_table.count =
+				limits->numEntries;
+			entry = &limits->entries[0];
+			for (i = 0; i < limits->numEntries; i++) {
+				adev->pm.dpm.dyn_state.acp_clock_voltage_dependency_table.entries[i].clk =
+					le16_to_cpu(entry->usACPClockLow) | (entry->ucACPClockHigh << 16);
+				adev->pm.dpm.dyn_state.acp_clock_voltage_dependency_table.entries[i].v =
+					le16_to_cpu(entry->usVoltage);
+				entry = (ATOM_PPLIB_ACPClk_Voltage_Limit_Record *)
+					((u8 *)entry + sizeof(ATOM_PPLIB_ACPClk_Voltage_Limit_Record));
+			}
+		}
+		if ((le16_to_cpu(ext_hdr->usSize) >= SIZE_OF_ATOM_PPLIB_EXTENDEDHEADER_V7) &&
+			ext_hdr->usPowerTuneTableOffset) {
+			u8 rev = *(u8 *)(mode_info->atom_context->bios + data_offset +
+					 le16_to_cpu(ext_hdr->usPowerTuneTableOffset));
+			ATOM_PowerTune_Table *pt;
+			adev->pm.dpm.dyn_state.cac_tdp_table =
+				kzalloc(sizeof(struct amdgpu_cac_tdp_table), GFP_KERNEL);
+			if (!adev->pm.dpm.dyn_state.cac_tdp_table) {
+				amdgpu_free_extended_power_table(adev);
+				return -ENOMEM;
+			}
+			if (rev > 0) {
+				ATOM_PPLIB_POWERTUNE_Table_V1 *ppt = (ATOM_PPLIB_POWERTUNE_Table_V1 *)
+					(mode_info->atom_context->bios + data_offset +
+					 le16_to_cpu(ext_hdr->usPowerTuneTableOffset));
+				adev->pm.dpm.dyn_state.cac_tdp_table->maximum_power_delivery_limit =
+					ppt->usMaximumPowerDeliveryLimit;
+				pt = &ppt->power_tune_table;
+			} else {
+				ATOM_PPLIB_POWERTUNE_Table *ppt = (ATOM_PPLIB_POWERTUNE_Table *)
+					(mode_info->atom_context->bios + data_offset +
+					 le16_to_cpu(ext_hdr->usPowerTuneTableOffset));
+				adev->pm.dpm.dyn_state.cac_tdp_table->maximum_power_delivery_limit = 255;
+				pt = &ppt->power_tune_table;
+			}
+			adev->pm.dpm.dyn_state.cac_tdp_table->tdp = le16_to_cpu(pt->usTDP);
+			adev->pm.dpm.dyn_state.cac_tdp_table->configurable_tdp =
+				le16_to_cpu(pt->usConfigurableTDP);
+			adev->pm.dpm.dyn_state.cac_tdp_table->tdc = le16_to_cpu(pt->usTDC);
+			adev->pm.dpm.dyn_state.cac_tdp_table->battery_power_limit =
+				le16_to_cpu(pt->usBatteryPowerLimit);
+			adev->pm.dpm.dyn_state.cac_tdp_table->small_power_limit =
+				le16_to_cpu(pt->usSmallPowerLimit);
+			adev->pm.dpm.dyn_state.cac_tdp_table->low_cac_leakage =
+				le16_to_cpu(pt->usLowCACLeakage);
+			adev->pm.dpm.dyn_state.cac_tdp_table->high_cac_leakage =
+				le16_to_cpu(pt->usHighCACLeakage);
+		}
+		if ((le16_to_cpu(ext_hdr->usSize) >= SIZE_OF_ATOM_PPLIB_EXTENDEDHEADER_V8) &&
+				ext_hdr->usSclkVddgfxTableOffset) {
+			dep_table = (ATOM_PPLIB_Clock_Voltage_Dependency_Table *)
+				(mode_info->atom_context->bios + data_offset +
+				 le16_to_cpu(ext_hdr->usSclkVddgfxTableOffset));
+			ret = amdgpu_parse_clk_voltage_dep_table(
+					&adev->pm.dpm.dyn_state.vddgfx_dependency_on_sclk,
+					dep_table);
+			if (ret) {
+				kfree(adev->pm.dpm.dyn_state.vddgfx_dependency_on_sclk.entries);
+				return ret;
+			}
+		}
+	}
+
+	return 0;
+}
+
+void amdgpu_free_extended_power_table(struct amdgpu_device *adev)
+{
+	struct amdgpu_dpm_dynamic_state *dyn_state = &adev->pm.dpm.dyn_state;
+
+	kfree(dyn_state->vddc_dependency_on_sclk.entries);
+	kfree(dyn_state->vddci_dependency_on_mclk.entries);
+	kfree(dyn_state->vddc_dependency_on_mclk.entries);
+	kfree(dyn_state->mvdd_dependency_on_mclk.entries);
+	kfree(dyn_state->cac_leakage_table.entries);
+	kfree(dyn_state->phase_shedding_limits_table.entries);
+	kfree(dyn_state->ppm_table);
+	kfree(dyn_state->cac_tdp_table);
+	kfree(dyn_state->vce_clock_voltage_dependency_table.entries);
+	kfree(dyn_state->uvd_clock_voltage_dependency_table.entries);
+	kfree(dyn_state->samu_clock_voltage_dependency_table.entries);
+	kfree(dyn_state->acp_clock_voltage_dependency_table.entries);
+	kfree(dyn_state->vddgfx_dependency_on_sclk.entries);
+}
+
+static const char *pp_lib_thermal_controller_names[] = {
+	"NONE",
+	"lm63",
+	"adm1032",
+	"adm1030",
+	"max6649",
+	"lm64",
+	"f75375",
+	"RV6xx",
+	"RV770",
+	"adt7473",
+	"NONE",
+	"External GPIO",
+	"Evergreen",
+	"emc2103",
+	"Sumo",
+	"Northern Islands",
+	"Southern Islands",
+	"lm96163",
+	"Sea Islands",
+	"Kaveri/Kabini",
+};
+
+void amdgpu_add_thermal_controller(struct amdgpu_device *adev)
+{
+	struct amdgpu_mode_info *mode_info = &adev->mode_info;
+	ATOM_PPLIB_POWERPLAYTABLE *power_table;
+	int index = GetIndexIntoMasterTable(DATA, PowerPlayInfo);
+	ATOM_PPLIB_THERMALCONTROLLER *controller;
+	struct amdgpu_i2c_bus_rec i2c_bus;
+	u16 data_offset;
+	u8 frev, crev;
+
+	if (!amdgpu_atom_parse_data_header(mode_info->atom_context, index, NULL,
+				   &frev, &crev, &data_offset))
+		return;
+	power_table = (ATOM_PPLIB_POWERPLAYTABLE *)
+		(mode_info->atom_context->bios + data_offset);
+	controller = &power_table->sThermalController;
+
+	/* add the i2c bus for thermal/fan chip */
+	if (controller->ucType > 0) {
+		if (controller->ucFanParameters & ATOM_PP_FANPARAMETERS_NOFAN)
+			adev->pm.no_fan = true;
+		adev->pm.fan_pulses_per_revolution =
+			controller->ucFanParameters & ATOM_PP_FANPARAMETERS_TACHOMETER_PULSES_PER_REVOLUTION_MASK;
+		if (adev->pm.fan_pulses_per_revolution) {
+			adev->pm.fan_min_rpm = controller->ucFanMinRPM;
+			adev->pm.fan_max_rpm = controller->ucFanMaxRPM;
+		}
+		if (controller->ucType == ATOM_PP_THERMALCONTROLLER_RV6xx) {
+			DRM_INFO("Internal thermal controller %s fan control\n",
+				 (controller->ucFanParameters &
+				  ATOM_PP_FANPARAMETERS_NOFAN) ? "without" : "with");
+			adev->pm.int_thermal_type = THERMAL_TYPE_RV6XX;
+		} else if (controller->ucType == ATOM_PP_THERMALCONTROLLER_RV770) {
+			DRM_INFO("Internal thermal controller %s fan control\n",
+				 (controller->ucFanParameters &
+				  ATOM_PP_FANPARAMETERS_NOFAN) ? "without" : "with");
+			adev->pm.int_thermal_type = THERMAL_TYPE_RV770;
+		} else if (controller->ucType == ATOM_PP_THERMALCONTROLLER_EVERGREEN) {
+			DRM_INFO("Internal thermal controller %s fan control\n",
+				 (controller->ucFanParameters &
+				  ATOM_PP_FANPARAMETERS_NOFAN) ? "without" : "with");
+			adev->pm.int_thermal_type = THERMAL_TYPE_EVERGREEN;
+		} else if (controller->ucType == ATOM_PP_THERMALCONTROLLER_SUMO) {
+			DRM_INFO("Internal thermal controller %s fan control\n",
+				 (controller->ucFanParameters &
+				  ATOM_PP_FANPARAMETERS_NOFAN) ? "without" : "with");
+			adev->pm.int_thermal_type = THERMAL_TYPE_SUMO;
+		} else if (controller->ucType == ATOM_PP_THERMALCONTROLLER_NISLANDS) {
+			DRM_INFO("Internal thermal controller %s fan control\n",
+				 (controller->ucFanParameters &
+				  ATOM_PP_FANPARAMETERS_NOFAN) ? "without" : "with");
+			adev->pm.int_thermal_type = THERMAL_TYPE_NI;
+		} else if (controller->ucType == ATOM_PP_THERMALCONTROLLER_SISLANDS) {
+			DRM_INFO("Internal thermal controller %s fan control\n",
+				 (controller->ucFanParameters &
+				  ATOM_PP_FANPARAMETERS_NOFAN) ? "without" : "with");
+			adev->pm.int_thermal_type = THERMAL_TYPE_SI;
+		} else if (controller->ucType == ATOM_PP_THERMALCONTROLLER_CISLANDS) {
+			DRM_INFO("Internal thermal controller %s fan control\n",
+				 (controller->ucFanParameters &
+				  ATOM_PP_FANPARAMETERS_NOFAN) ? "without" : "with");
+			adev->pm.int_thermal_type = THERMAL_TYPE_CI;
+		} else if (controller->ucType == ATOM_PP_THERMALCONTROLLER_KAVERI) {
+			DRM_INFO("Internal thermal controller %s fan control\n",
+				 (controller->ucFanParameters &
+				  ATOM_PP_FANPARAMETERS_NOFAN) ? "without" : "with");
+			adev->pm.int_thermal_type = THERMAL_TYPE_KV;
+		} else if (controller->ucType == ATOM_PP_THERMALCONTROLLER_EXTERNAL_GPIO) {
+			DRM_INFO("External GPIO thermal controller %s fan control\n",
+				 (controller->ucFanParameters &
+				  ATOM_PP_FANPARAMETERS_NOFAN) ? "without" : "with");
+			adev->pm.int_thermal_type = THERMAL_TYPE_EXTERNAL_GPIO;
+		} else if (controller->ucType ==
+			   ATOM_PP_THERMALCONTROLLER_ADT7473_WITH_INTERNAL) {
+			DRM_INFO("ADT7473 with internal thermal controller %s fan control\n",
+				 (controller->ucFanParameters &
+				  ATOM_PP_FANPARAMETERS_NOFAN) ? "without" : "with");
+			adev->pm.int_thermal_type = THERMAL_TYPE_ADT7473_WITH_INTERNAL;
+		} else if (controller->ucType ==
+			   ATOM_PP_THERMALCONTROLLER_EMC2103_WITH_INTERNAL) {
+			DRM_INFO("EMC2103 with internal thermal controller %s fan control\n",
+				 (controller->ucFanParameters &
+				  ATOM_PP_FANPARAMETERS_NOFAN) ? "without" : "with");
+			adev->pm.int_thermal_type = THERMAL_TYPE_EMC2103_WITH_INTERNAL;
+		} else if (controller->ucType < ARRAY_SIZE(pp_lib_thermal_controller_names)) {
+			DRM_INFO("Possible %s thermal controller at 0x%02x %s fan control\n",
+				 pp_lib_thermal_controller_names[controller->ucType],
+				 controller->ucI2cAddress >> 1,
+				 (controller->ucFanParameters &
+				  ATOM_PP_FANPARAMETERS_NOFAN) ? "without" : "with");
+			adev->pm.int_thermal_type = THERMAL_TYPE_EXTERNAL;
+			i2c_bus = amdgpu_atombios_lookup_i2c_gpio(adev, controller->ucI2cLine);
+			adev->pm.i2c_bus = amdgpu_i2c_lookup(adev, &i2c_bus);
+			if (adev->pm.i2c_bus) {
+				struct i2c_board_info info = { };
+				const char *name = pp_lib_thermal_controller_names[controller->ucType];
+				info.addr = controller->ucI2cAddress >> 1;
+				strlcpy(info.type, name, sizeof(info.type));
+				i2c_new_client_device(&adev->pm.i2c_bus->adapter, &info);
+			}
+		} else {
+			DRM_INFO("Unknown thermal controller type %d at 0x%02x %s fan control\n",
+				 controller->ucType,
+				 controller->ucI2cAddress >> 1,
+				 (controller->ucFanParameters &
+				  ATOM_PP_FANPARAMETERS_NOFAN) ? "without" : "with");
+		}
+	}
+}
+
+struct amd_vce_state* amdgpu_get_vce_clock_state(void *handle, u32 idx)
+{
+	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
+
+	if (idx < adev->pm.dpm.num_of_vce_states)
+		return &adev->pm.dpm.vce_states[idx];
+
+	return NULL;
+}
+
+static struct amdgpu_ps *amdgpu_dpm_pick_power_state(struct amdgpu_device *adev,
+						     enum amd_pm_state_type dpm_state)
+{
+	int i;
+	struct amdgpu_ps *ps;
+	u32 ui_class;
+	bool single_display = (adev->pm.dpm.new_active_crtc_count < 2) ?
+		true : false;
+
+	/* check if the vblank period is too short to adjust the mclk */
+	if (single_display && adev->powerplay.pp_funcs->vblank_too_short) {
+		if (amdgpu_dpm_vblank_too_short(adev))
+			single_display = false;
+	}
+
+	/* certain older asics have a separare 3D performance state,
+	 * so try that first if the user selected performance
+	 */
+	if (dpm_state == POWER_STATE_TYPE_PERFORMANCE)
+		dpm_state = POWER_STATE_TYPE_INTERNAL_3DPERF;
+	/* balanced states don't exist at the moment */
+	if (dpm_state == POWER_STATE_TYPE_BALANCED)
+		dpm_state = POWER_STATE_TYPE_PERFORMANCE;
+
+restart_search:
+	/* Pick the best power state based on current conditions */
+	for (i = 0; i < adev->pm.dpm.num_ps; i++) {
+		ps = &adev->pm.dpm.ps[i];
+		ui_class = ps->class & ATOM_PPLIB_CLASSIFICATION_UI_MASK;
+		switch (dpm_state) {
+		/* user states */
+		case POWER_STATE_TYPE_BATTERY:
+			if (ui_class == ATOM_PPLIB_CLASSIFICATION_UI_BATTERY) {
+				if (ps->caps & ATOM_PPLIB_SINGLE_DISPLAY_ONLY) {
+					if (single_display)
+						return ps;
+				} else
+					return ps;
+			}
+			break;
+		case POWER_STATE_TYPE_BALANCED:
+			if (ui_class == ATOM_PPLIB_CLASSIFICATION_UI_BALANCED) {
+				if (ps->caps & ATOM_PPLIB_SINGLE_DISPLAY_ONLY) {
+					if (single_display)
+						return ps;
+				} else
+					return ps;
+			}
+			break;
+		case POWER_STATE_TYPE_PERFORMANCE:
+			if (ui_class == ATOM_PPLIB_CLASSIFICATION_UI_PERFORMANCE) {
+				if (ps->caps & ATOM_PPLIB_SINGLE_DISPLAY_ONLY) {
+					if (single_display)
+						return ps;
+				} else
+					return ps;
+			}
+			break;
+		/* internal states */
+		case POWER_STATE_TYPE_INTERNAL_UVD:
+			if (adev->pm.dpm.uvd_ps)
+				return adev->pm.dpm.uvd_ps;
+			else
+				break;
+		case POWER_STATE_TYPE_INTERNAL_UVD_SD:
+			if (ps->class & ATOM_PPLIB_CLASSIFICATION_SDSTATE)
+				return ps;
+			break;
+		case POWER_STATE_TYPE_INTERNAL_UVD_HD:
+			if (ps->class & ATOM_PPLIB_CLASSIFICATION_HDSTATE)
+				return ps;
+			break;
+		case POWER_STATE_TYPE_INTERNAL_UVD_HD2:
+			if (ps->class & ATOM_PPLIB_CLASSIFICATION_HD2STATE)
+				return ps;
+			break;
+		case POWER_STATE_TYPE_INTERNAL_UVD_MVC:
+			if (ps->class2 & ATOM_PPLIB_CLASSIFICATION2_MVC)
+				return ps;
+			break;
+		case POWER_STATE_TYPE_INTERNAL_BOOT:
+			return adev->pm.dpm.boot_ps;
+		case POWER_STATE_TYPE_INTERNAL_THERMAL:
+			if (ps->class & ATOM_PPLIB_CLASSIFICATION_THERMAL)
+				return ps;
+			break;
+		case POWER_STATE_TYPE_INTERNAL_ACPI:
+			if (ps->class & ATOM_PPLIB_CLASSIFICATION_ACPI)
+				return ps;
+			break;
+		case POWER_STATE_TYPE_INTERNAL_ULV:
+			if (ps->class2 & ATOM_PPLIB_CLASSIFICATION2_ULV)
+				return ps;
+			break;
+		case POWER_STATE_TYPE_INTERNAL_3DPERF:
+			if (ps->class & ATOM_PPLIB_CLASSIFICATION_3DPERFORMANCE)
+				return ps;
+			break;
+		default:
+			break;
+		}
+	}
+	/* use a fallback state if we didn't match */
+	switch (dpm_state) {
+	case POWER_STATE_TYPE_INTERNAL_UVD_SD:
+		dpm_state = POWER_STATE_TYPE_INTERNAL_UVD_HD;
+		goto restart_search;
+	case POWER_STATE_TYPE_INTERNAL_UVD_HD:
+	case POWER_STATE_TYPE_INTERNAL_UVD_HD2:
+	case POWER_STATE_TYPE_INTERNAL_UVD_MVC:
+		if (adev->pm.dpm.uvd_ps) {
+			return adev->pm.dpm.uvd_ps;
+		} else {
+			dpm_state = POWER_STATE_TYPE_PERFORMANCE;
+			goto restart_search;
+		}
+	case POWER_STATE_TYPE_INTERNAL_THERMAL:
+		dpm_state = POWER_STATE_TYPE_INTERNAL_ACPI;
+		goto restart_search;
+	case POWER_STATE_TYPE_INTERNAL_ACPI:
+		dpm_state = POWER_STATE_TYPE_BATTERY;
+		goto restart_search;
+	case POWER_STATE_TYPE_BATTERY:
+	case POWER_STATE_TYPE_BALANCED:
+	case POWER_STATE_TYPE_INTERNAL_3DPERF:
+		dpm_state = POWER_STATE_TYPE_PERFORMANCE;
+		goto restart_search;
+	default:
+		break;
+	}
+
+	return NULL;
+}
+
+int amdgpu_dpm_change_power_state_locked(void *handle)
+{
+	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
+	struct amdgpu_ps *ps;
+	enum amd_pm_state_type dpm_state;
+	int ret;
+	bool equal = false;
+
+	/* if dpm init failed */
+	if (!adev->pm.dpm_enabled)
+		return 0;
+
+	if (adev->pm.dpm.user_state != adev->pm.dpm.state) {
+		/* add other state override checks here */
+		if ((!adev->pm.dpm.thermal_active) &&
+		    (!adev->pm.dpm.uvd_active))
+			adev->pm.dpm.state = adev->pm.dpm.user_state;
+	}
+	dpm_state = adev->pm.dpm.state;
+
+	ps = amdgpu_dpm_pick_power_state(adev, dpm_state);
+	if (ps)
+		adev->pm.dpm.requested_ps = ps;
+	else
+		return -EINVAL;
+
+	if (amdgpu_dpm == 1 && adev->powerplay.pp_funcs->print_power_state) {
+		printk("switching from power state:\n");
+		amdgpu_dpm_print_power_state(adev, adev->pm.dpm.current_ps);
+		printk("switching to power state:\n");
[… more lines in the raw message]

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

drivers/gpu/drm/amd/pm/powerplay/legacy_dpm.h new file +70 -0
new file mode 100644
index 000000000000..4adc765c8824

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

drivers/gpu/drm/amd/pm/powerplay/si_dpm.c +2 -0
index 4f84d8b893f1..a2881c90d187 100644

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

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

Part of the diff is not shown here. View the raw message.