Cache the xclk rate during amdgpu_device_init() and return the cached
value in the AMDGPU_INFO_DEV_INFO query.
This will allow to avoid waking up the GPU for this query later.

Link: https://gitlab.freedesktop.org/drm/amd/-/issues/2295
Signed-off-by: Philipp Zabel <philipp.za...@gmail.com>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu.h        | 1 +
 drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 2 ++
 drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c    | 2 +-
 3 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu.h 
b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
index e33c90c44697e..35827a0cca780 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
@@ -431,6 +431,7 @@ struct amdgpu_clock {
        struct amdgpu_pll spll;
        struct amdgpu_pll mpll;
        /* 10 Khz units */
+       u32 xclk;
        uint32_t default_mclk;
        uint32_t default_sclk;
        uint32_t default_dispclk;
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
index 79d0ff0bda290..44a8fad60512e 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
@@ -4818,6 +4818,8 @@ int amdgpu_device_init(struct amdgpu_device *adev,
        if (r)
                goto failed;
 
+       adev->clock.xclk = amdgpu_asic_get_xclk(adev);
+
        return 0;
 
 release_ras_con:
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
index 60f36e03def2a..190602bacbcdf 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
@@ -911,7 +911,7 @@ int amdgpu_info_ioctl(struct drm_device *dev, void *data, 
struct drm_file *filp)
                dev_info->num_shader_engines = 
adev->gfx.config.max_shader_engines;
                dev_info->num_shader_arrays_per_engine = 
adev->gfx.config.max_sh_per_se;
                /* return all clocks in KHz */
-               dev_info->gpu_counter_freq = amdgpu_asic_get_xclk(adev) * 10;
+               dev_info->gpu_counter_freq = adev->clock.xclk * 10;
                if (adev->pm.dpm_enabled) {
                        dev_info->max_engine_clock = amdgpu_dpm_get_sclk(adev, 
false) * 10;
                        dev_info->max_memory_clock = amdgpu_dpm_get_mclk(adev, 
false) * 10;

-- 
2.50.1

Reply via email to