drm/amd/pm: Hide irrelevant pm device attributes
authorLijo Lazar <lijo.lazar@amd.com>
Tue, 31 Oct 2023 07:02:03 +0000 (12:32 +0530)
committerAlex Deucher <alexander.deucher@amd.com>
Tue, 7 Nov 2023 17:03:31 +0000 (12:03 -0500)
Change return code to EOPNOTSUPP for unsupported functions. Use the
error code information to hide sysfs nodes not valid for the SOC.

Signed-off-by: Lijo Lazar <lijo.lazar@amd.com>
Reviewed-by: Yang Wang <kevinyang.wang@amd.com>
Reviewed-by: Asad Kamal <asad.kamal@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
drivers/gpu/drm/amd/pm/amdgpu_dpm.c
drivers/gpu/drm/amd/pm/amdgpu_pm.c
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c

index acf3527..08cb794 100644 (file)
@@ -491,7 +491,7 @@ int amdgpu_dpm_read_sensor(struct amdgpu_device *adev, enum amd_pp_sensors senso
 int amdgpu_dpm_get_apu_thermal_limit(struct amdgpu_device *adev, uint32_t *limit)
 {
        const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
-       int ret = -EINVAL;
+       int ret = -EOPNOTSUPP;
 
        if (pp_funcs && pp_funcs->get_apu_thermal_limit) {
                mutex_lock(&adev->pm.mutex);
@@ -505,7 +505,7 @@ int amdgpu_dpm_get_apu_thermal_limit(struct amdgpu_device *adev, uint32_t *limit
 int amdgpu_dpm_set_apu_thermal_limit(struct amdgpu_device *adev, uint32_t limit)
 {
        const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
-       int ret = -EINVAL;
+       int ret = -EOPNOTSUPP;
 
        if (pp_funcs && pp_funcs->set_apu_thermal_limit) {
                mutex_lock(&adev->pm.mutex);
@@ -1182,7 +1182,7 @@ int amdgpu_dpm_get_sclk_od(struct amdgpu_device *adev)
        int ret = 0;
 
        if (!pp_funcs->get_sclk_od)
-               return 0;
+               return -EOPNOTSUPP;
 
        mutex_lock(&adev->pm.mutex);
        ret = pp_funcs->get_sclk_od(adev->powerplay.pp_handle);
@@ -1196,7 +1196,7 @@ 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 (is_support_sw_smu(adev))
-               return 0;
+               return -EOPNOTSUPP;
 
        mutex_lock(&adev->pm.mutex);
        if (pp_funcs->set_sclk_od)
@@ -1219,7 +1219,7 @@ int amdgpu_dpm_get_mclk_od(struct amdgpu_device *adev)
        int ret = 0;
 
        if (!pp_funcs->get_mclk_od)
-               return 0;
+               return -EOPNOTSUPP;
 
        mutex_lock(&adev->pm.mutex);
        ret = pp_funcs->get_mclk_od(adev->powerplay.pp_handle);
@@ -1233,7 +1233,7 @@ 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 (is_support_sw_smu(adev))
-               return 0;
+               return -EOPNOTSUPP;
 
        mutex_lock(&adev->pm.mutex);
        if (pp_funcs->set_mclk_od)
index 4ba9195..1f6d2db 100644 (file)
@@ -2197,6 +2197,18 @@ static int default_attr_update(struct amdgpu_device *adev, struct amdgpu_device_
        } else if (DEVICE_ATTR_IS(xgmi_plpd_policy)) {
                if (amdgpu_dpm_get_xgmi_plpd_mode(adev, NULL) == XGMI_PLPD_NONE)
                        *states = ATTR_STATE_UNSUPPORTED;
+       } else if (DEVICE_ATTR_IS(pp_dpm_mclk_od)) {
+               if (amdgpu_dpm_get_mclk_od(adev) == -EOPNOTSUPP)
+                       *states = ATTR_STATE_UNSUPPORTED;
+       } else if (DEVICE_ATTR_IS(pp_dpm_sclk_od)) {
+               if (amdgpu_dpm_get_sclk_od(adev) == -EOPNOTSUPP)
+                       *states = ATTR_STATE_UNSUPPORTED;
+       } else if (DEVICE_ATTR_IS(apu_thermal_cap)) {
+               u32 limit;
+
+               if (amdgpu_dpm_get_apu_thermal_limit(adev, &limit) ==
+                   -EOPNOTSUPP)
+                       *states = ATTR_STATE_UNSUPPORTED;
        }
 
        switch (gc_ver) {
index 23b00ed..d86750d 100644 (file)
@@ -2747,7 +2747,7 @@ unlock:
 
 static int smu_get_apu_thermal_limit(void *handle, uint32_t *limit)
 {
-       int ret = -EINVAL;
+       int ret = -EOPNOTSUPP;
        struct smu_context *smu = handle;
 
        if (smu->ppt_funcs && smu->ppt_funcs->get_apu_thermal_limit)
@@ -2758,7 +2758,7 @@ static int smu_get_apu_thermal_limit(void *handle, uint32_t *limit)
 
 static int smu_set_apu_thermal_limit(void *handle, uint32_t limit)
 {
-       int ret = -EINVAL;
+       int ret = -EOPNOTSUPP;
        struct smu_context *smu = handle;
 
        if (smu->ppt_funcs && smu->ppt_funcs->set_apu_thermal_limit)