Skip to content

Commit 4f2f203

Browse files
agd5fChristianKoenigAMD
authored andcommitted
drm/radeon/pm: don't allow debugfs/sysfs access when PX card is off (v2)
When the PX card is off don't try and access it. Avoid hw access to the card while it's off (e.g., reading back invalid temperature). v2: be less strict bug: https://bugzilla.kernel.org/show_bug.cgi?id=76321 Signed-off-by: Alex Deucher <alexander.deucher@amd.com> Cc: stable@vger.kernel.org Signed-off-by: Christian König <christian.koenig@amd.com>
1 parent 24f47ac commit 4f2f203

1 file changed

Lines changed: 41 additions & 1 deletion

File tree

‎drivers/gpu/drm/radeon/radeon_pm.c‎

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,11 @@ static ssize_t radeon_set_pm_profile(struct device *dev,
361361
struct drm_device *ddev = dev_get_drvdata(dev);
362362
struct radeon_device *rdev = ddev->dev_private;
363363

364+
/* Can't set profile when the card is off */
365+
if ((rdev->flags & RADEON_IS_PX) &&
366+
(ddev->switch_power_state != DRM_SWITCH_POWER_ON))
367+
return -EINVAL;
368+
364369
mutex_lock(&rdev->pm.mutex);
365370
if (rdev->pm.pm_method == PM_METHOD_PROFILE) {
366371
if (strncmp("default", buf, strlen("default")) == 0)
@@ -409,6 +414,13 @@ static ssize_t radeon_set_pm_method(struct device *dev,
409414
struct drm_device *ddev = dev_get_drvdata(dev);
410415
struct radeon_device *rdev = ddev->dev_private;
411416

417+
/* Can't set method when the card is off */
418+
if ((rdev->flags & RADEON_IS_PX) &&
419+
(ddev->switch_power_state != DRM_SWITCH_POWER_ON)) {
420+
count = -EINVAL;
421+
goto fail;
422+
}
423+
412424
/* we don't support the legacy modes with dpm */
413425
if (rdev->pm.pm_method == PM_METHOD_DPM) {
414426
count = -EINVAL;
@@ -446,6 +458,10 @@ static ssize_t radeon_get_dpm_state(struct device *dev,
446458
struct radeon_device *rdev = ddev->dev_private;
447459
enum radeon_pm_state_type pm = rdev->pm.dpm.user_state;
448460

461+
if ((rdev->flags & RADEON_IS_PX) &&
462+
(ddev->switch_power_state != DRM_SWITCH_POWER_ON))
463+
return snprintf(buf, PAGE_SIZE, "off\n");
464+
449465
return snprintf(buf, PAGE_SIZE, "%s\n",
450466
(pm == POWER_STATE_TYPE_BATTERY) ? "battery" :
451467
(pm == POWER_STATE_TYPE_BALANCED) ? "balanced" : "performance");
@@ -459,6 +475,11 @@ static ssize_t radeon_set_dpm_state(struct device *dev,
459475
struct drm_device *ddev = dev_get_drvdata(dev);
460476
struct radeon_device *rdev = ddev->dev_private;
461477

478+
/* Can't set dpm state when the card is off */
479+
if ((rdev->flags & RADEON_IS_PX) &&
480+
(ddev->switch_power_state != DRM_SWITCH_POWER_ON))
481+
return -EINVAL;
482+
462483
mutex_lock(&rdev->pm.mutex);
463484
if (strncmp("battery", buf, strlen("battery")) == 0)
464485
rdev->pm.dpm.user_state = POWER_STATE_TYPE_BATTERY;
@@ -485,6 +506,10 @@ static ssize_t radeon_get_dpm_forced_performance_level(struct device *dev,
485506
struct radeon_device *rdev = ddev->dev_private;
486507
enum radeon_dpm_forced_level level = rdev->pm.dpm.forced_level;
487508

509+
if ((rdev->flags & RADEON_IS_PX) &&
510+
(ddev->switch_power_state != DRM_SWITCH_POWER_ON))
511+
return snprintf(buf, PAGE_SIZE, "off\n");
512+
488513
return snprintf(buf, PAGE_SIZE, "%s\n",
489514
(level == RADEON_DPM_FORCED_LEVEL_AUTO) ? "auto" :
490515
(level == RADEON_DPM_FORCED_LEVEL_LOW) ? "low" : "high");
@@ -500,6 +525,11 @@ static ssize_t radeon_set_dpm_forced_performance_level(struct device *dev,
500525
enum radeon_dpm_forced_level level;
501526
int ret = 0;
502527

528+
/* Can't force performance level when the card is off */
529+
if ((rdev->flags & RADEON_IS_PX) &&
530+
(ddev->switch_power_state != DRM_SWITCH_POWER_ON))
531+
return -EINVAL;
532+
503533
mutex_lock(&rdev->pm.mutex);
504534
if (strncmp("low", buf, strlen("low")) == 0) {
505535
level = RADEON_DPM_FORCED_LEVEL_LOW;
@@ -538,8 +568,14 @@ static ssize_t radeon_hwmon_show_temp(struct device *dev,
538568
char *buf)
539569
{
540570
struct radeon_device *rdev = dev_get_drvdata(dev);
571+
struct drm_device *ddev = rdev->ddev;
541572
int temp;
542573

574+
/* Can't get temperature when the card is off */
575+
if ((rdev->flags & RADEON_IS_PX) &&
576+
(ddev->switch_power_state != DRM_SWITCH_POWER_ON))
577+
return -EINVAL;
578+
543579
if (rdev->asic->pm.get_temperature)
544580
temp = radeon_get_temperature(rdev);
545581
else
@@ -1614,8 +1650,12 @@ static int radeon_debugfs_pm_info(struct seq_file *m, void *data)
16141650
struct drm_info_node *node = (struct drm_info_node *) m->private;
16151651
struct drm_device *dev = node->minor->dev;
16161652
struct radeon_device *rdev = dev->dev_private;
1653+
struct drm_device *ddev = rdev->ddev;
16171654

1618-
if (rdev->pm.dpm_enabled) {
1655+
if ((rdev->flags & RADEON_IS_PX) &&
1656+
(ddev->switch_power_state != DRM_SWITCH_POWER_ON)) {
1657+
seq_printf(m, "PX asic powered off\n");
1658+
} else if (rdev->pm.dpm_enabled) {
16191659
mutex_lock(&rdev->pm.mutex);
16201660
if (rdev->asic->dpm.debugfs_print_current_performance_level)
16211661
radeon_dpm_debugfs_print_current_performance_level(rdev, m);

0 commit comments

Comments
 (0)