From: Jeremy Klarenbeek <[email protected]>

[ Upstream commit e6c5d36756e7d4d260e2365fc4d01226f1973152 ]

VBIOS can contain conflicting values between:
- the maximum allowed clocks and voltages on AC or DC
- the clocks and voltages in power states on AC or DC

Update maximum clock (and voltage) limits for both AC/DC
and take the highest value from the VBIOS limits and
the performance/battery power states. Previously this
was only done for AC, but is also needed for DC.

This commit fixes the behaviour on some laptop GPUs,
where the VBIOS limit was set to the lowest possible
clock frequency, so the GPU was stuck on the lowest
possible power level on battery.

Some affected GPUs are:
FirePro W4170M (Dell Precision M2800)
Radeon HD 8790M (Dell Latitude E6540)
and possibly other laptop GPUs.

Reviewed-by: Alex Deucher <[email protected]>
Co-developed-by: Timur Kristóf <[email protected]>
Signed-off-by: Timur Kristóf <[email protected]>
Signed-off-by: Jeremy Klarenbeek <[email protected]>
Signed-off-by: Alex Deucher <[email protected]>
Signed-off-by: Sasha Levin <[email protected]>
---

LLM Generated explanations, may be completely bogus:

The background git searches finished and match the earlier analysis:

- **History search:** The AC-only `max_clock_voltage_on_ac` assignment
  traces back through the SI DPM code (pickaxe hit `837d542a09cd5`, the
  pm header relocation). No prior fix for DC clock limits was found.
- **Author search:** Jeremy Klarenbeek has no commits in this 6.18.44
  tree.
- **Fix commit search:** `git log --grep="updating clock limits"`
  returned nothing — the patch is not in this tree yet. The only "power
  states" hit in `si_dpm.c` was an unrelated debug-level change.
- **Hardware search:** No existing commits mention the FirePro W4170M or
  Radeon HD 8790M by name.

That supports the **YES** backport recommendation: the bug is present
and unfixed in 6.18.44, and this would be a new, standalone fix.The
hardware-related git search completed: there are no commits in this
6.18.44 tree that mention the FirePro W4170M, Radeon HD 8790M, or author
Jeremy Klarenbeek in connection with this clock-limits issue. That
confirms this would be a new fix rather than something already present
under a different commit.

 drivers/gpu/drm/amd/pm/legacy-dpm/si_dpm.c | 29 ++++++++++++++++++----
 1 file changed, 24 insertions(+), 5 deletions(-)

diff --git a/drivers/gpu/drm/amd/pm/legacy-dpm/si_dpm.c 
b/drivers/gpu/drm/amd/pm/legacy-dpm/si_dpm.c
index 0385b24e7e4a2..ea97276358c0a 100644
--- a/drivers/gpu/drm/amd/pm/legacy-dpm/si_dpm.c
+++ b/drivers/gpu/drm/amd/pm/legacy-dpm/si_dpm.c
@@ -7238,6 +7238,7 @@ static void si_parse_pplib_clock_info(struct 
amdgpu_device *adev,
        struct evergreen_power_info *eg_pi = evergreen_get_pi(adev);
        struct si_power_info *si_pi = si_get_pi(adev);
        struct  si_ps *ps = si_get_ps(rps);
+       struct amdgpu_clock_and_voltage_limits *limits;
        u16 leakage_voltage;
        struct rv7xx_pl *pl = &ps->performance_levels[index];
        int ret;
@@ -7297,12 +7298,30 @@ static void si_parse_pplib_clock_info(struct 
amdgpu_device *adev,
                si_pi->mvdd_bootup_value = mvdd;
        }
 
+       /*
+        * Update maximum allowed clock limits.
+        * VBIOS can contain conflicting values between:
+        * - the maximum allowed clocks and voltages on AC or DC
+        * - the clocks and voltages in power states on AC or DC
+        */
        if ((rps->class & ATOM_PPLIB_CLASSIFICATION_UI_MASK) ==
-           ATOM_PPLIB_CLASSIFICATION_UI_PERFORMANCE) {
-               adev->pm.dpm.dyn_state.max_clock_voltage_on_ac.sclk = pl->sclk;
-               adev->pm.dpm.dyn_state.max_clock_voltage_on_ac.mclk = pl->mclk;
-               adev->pm.dpm.dyn_state.max_clock_voltage_on_ac.vddc = pl->vddc;
-               adev->pm.dpm.dyn_state.max_clock_voltage_on_ac.vddci = 
pl->vddci;
+           ATOM_PPLIB_CLASSIFICATION_UI_PERFORMANCE)
+               limits = &adev->pm.dpm.dyn_state.max_clock_voltage_on_ac;
+       else if ((rps->class & ATOM_PPLIB_CLASSIFICATION_UI_MASK) ==
+                ATOM_PPLIB_CLASSIFICATION_UI_BATTERY)
+               limits = &adev->pm.dpm.dyn_state.max_clock_voltage_on_dc;
+       else
+               limits = NULL;
+
+       if (limits) {
+               if (pl->sclk > limits->sclk)
+                       limits->sclk = pl->sclk;
+               if (pl->mclk > limits->mclk)
+                       limits->mclk = pl->mclk;
+               if (pl->vddc > limits->vddc)
+                       limits->vddc = pl->vddc;
+               if (pl->vddci > limits->vddci)
+                       limits->vddci = pl->vddci;
        }
 }
 
-- 
2.53.0

Reply via email to