OSDN Git Service

drm/amdgpu/pm: Don't show pp_power_profile_mode for unsupported devices
authorMario Limonciello <mario.limonciello@amd.com>
Fri, 29 Oct 2021 21:09:26 +0000 (16:09 -0500)
committerAlex Deucher <alexander.deucher@amd.com>
Wed, 3 Nov 2021 16:22:07 +0000 (12:22 -0400)
For ASICs not supporting power profile mode, don't show the attribute.
Verify that the function has been implemented by the subsystem.

Suggested-by: Alex Deucher <alexander.deucher@amd.com>
Signed-off-by: Mario Limonciello <mario.limonciello@amd.com>
Reviewed-by: Lijo Lazar <lijo.lazar@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
drivers/gpu/drm/amd/pm/amdgpu_pm.c
drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c

index 49fe415..41472ed 100644 (file)
@@ -2094,6 +2094,10 @@ static int default_attr_update(struct amdgpu_device *adev, struct amdgpu_device_
        } else if (DEVICE_ATTR_IS(pp_dpm_dclk)) {
                if (!(asic_type == CHIP_VANGOGH || asic_type == CHIP_SIENNA_CICHLID))
                        *states = ATTR_STATE_UNSUPPORTED;
+       } else if (DEVICE_ATTR_IS(pp_power_profile_mode)) {
+               if (!adev->powerplay.pp_funcs->get_power_profile_mode ||
+                   amdgpu_dpm_get_power_profile_mode(adev, NULL) == -EOPNOTSUPP)
+                       *states = ATTR_STATE_UNSUPPORTED;
        }
 
        switch (asic_type) {
index 79e5651..8d796ed 100644 (file)
@@ -877,16 +877,11 @@ static int pp_get_power_profile_mode(void *handle, char *buf)
        struct pp_hwmgr *hwmgr = handle;
        int ret;
 
-       if (!hwmgr || !hwmgr->pm_en)
+       if (!hwmgr || !hwmgr->pm_en || !hwmgr->hwmgr_func->get_power_profile_mode)
                return -EOPNOTSUPP;
        if (!buf)
                return -EINVAL;
 
-       if (hwmgr->hwmgr_func->get_power_profile_mode == NULL) {
-               pr_info_ratelimited("%s was not implemented.\n", __func__);
-               return snprintf(buf, PAGE_SIZE, "\n");
-       }
-
        mutex_lock(&hwmgr->smu_lock);
        ret = hwmgr->hwmgr_func->get_power_profile_mode(hwmgr, buf);
        mutex_unlock(&hwmgr->smu_lock);
@@ -898,13 +893,8 @@ static int pp_set_power_profile_mode(void *handle, long *input, uint32_t size)
        struct pp_hwmgr *hwmgr = handle;
        int ret = -EOPNOTSUPP;
 
-       if (!hwmgr || !hwmgr->pm_en)
-               return ret;
-
-       if (hwmgr->hwmgr_func->set_power_profile_mode == NULL) {
-               pr_info_ratelimited("%s was not implemented.\n", __func__);
+       if (!hwmgr || !hwmgr->pm_en || !hwmgr->hwmgr_func->set_power_profile_mode)
                return ret;
-       }
 
        if (hwmgr->dpm_level != AMD_DPM_FORCED_LEVEL_MANUAL) {
                pr_debug("power profile setting is for manual dpm mode only.\n");
index b06c59d..821ae6e 100644 (file)
@@ -2534,13 +2534,15 @@ static int smu_get_power_profile_mode(void *handle, char *buf)
        struct smu_context *smu = handle;
        int ret = 0;
 
-       if (!smu->pm_enabled || !smu->adev->pm.dpm_enabled)
+       if (!smu->pm_enabled || !smu->adev->pm.dpm_enabled ||
+           !smu->ppt_funcs->get_power_profile_mode)
                return -EOPNOTSUPP;
+       if (!buf)
+               return -EINVAL;
 
        mutex_lock(&smu->mutex);
 
-       if (smu->ppt_funcs->get_power_profile_mode)
-               ret = smu->ppt_funcs->get_power_profile_mode(smu, buf);
+       ret = smu->ppt_funcs->get_power_profile_mode(smu, buf);
 
        mutex_unlock(&smu->mutex);
 
@@ -2554,7 +2556,8 @@ static int smu_set_power_profile_mode(void *handle,
        struct smu_context *smu = handle;
        int ret = 0;
 
-       if (!smu->pm_enabled || !smu->adev->pm.dpm_enabled)
+       if (!smu->pm_enabled || !smu->adev->pm.dpm_enabled ||
+           !smu->ppt_funcs->set_power_profile_mode)
                return -EOPNOTSUPP;
 
        mutex_lock(&smu->mutex);