diff mbox series

[v7,2/5] drm: Expose wedge recovery methods

Message ID 20240930073845.347326-3-raag.jadav@intel.com (mailing list archive)
State New, archived
Headers show
Series Introduce DRM device wedged event | expand

Commit Message

Raag Jadav Sept. 30, 2024, 7:38 a.m. UTC
Now that we have device wedged event in place, add wedge_recovery sysfs
attribute which will expose recovery methods supported by the DRM device.
This is useful for userspace consumers in cases where the device supports
multiple recovery methods which can be used as fallbacks.

  $ cat /sys/class/drm/card<N>/wedge_recovery
  rebind
  bus-reset
  reboot

Signed-off-by: Raag Jadav <raag.jadav@intel.com>
---
 drivers/gpu/drm/drm_sysfs.c | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)

Comments

Andy Shevchenko Sept. 30, 2024, 1:01 p.m. UTC | #1
On Mon, Sep 30, 2024 at 01:08:42PM +0530, Raag Jadav wrote:
> Now that we have device wedged event in place, add wedge_recovery sysfs
> attribute which will expose recovery methods supported by the DRM device.
> This is useful for userspace consumers in cases where the device supports
> multiple recovery methods which can be used as fallbacks.
> 
>   $ cat /sys/class/drm/card<N>/wedge_recovery
>   rebind
>   bus-reset
>   reboot

...

> +static ssize_t wedge_recovery_show(struct device *device,
> +				   struct device_attribute *attr, char *buf)

Looking at the below line it seems you are fine with 100 limit, so, why two
lines above if they perfectly fit 100?

> +{
> +	struct drm_minor *minor = to_drm_minor(device);
> +	struct drm_device *dev = minor->dev;
> +	unsigned int method, count = DRM_WEDGE_RECOVERY_REBIND;
> +
> +	for_each_set_bit(method, &dev->wedge_recovery, DRM_WEDGE_RECOVERY_MAX)
> +		count += sysfs_emit_at(buf, count, "%s\n", drm_wedge_recovery_name(method));
> +
> +	return count;
> +}
Raag Jadav Oct. 1, 2024, 5:23 a.m. UTC | #2
On Mon, Sep 30, 2024 at 04:01:38PM +0300, Andy Shevchenko wrote:
> On Mon, Sep 30, 2024 at 01:08:42PM +0530, Raag Jadav wrote:
> > Now that we have device wedged event in place, add wedge_recovery sysfs
> > attribute which will expose recovery methods supported by the DRM device.
> > This is useful for userspace consumers in cases where the device supports
> > multiple recovery methods which can be used as fallbacks.
> > 
> >   $ cat /sys/class/drm/card<N>/wedge_recovery
> >   rebind
> >   bus-reset
> >   reboot
> 
> ...
> 
> > +static ssize_t wedge_recovery_show(struct device *device,
> > +				   struct device_attribute *attr, char *buf)
> 
> Looking at the below line it seems you are fine with 100 limit, so, why two
> lines above if they perfectly fit 100?

Just trying to avoid another bikeshed about conventions ;)

Raag
diff mbox series

Patch

diff --git a/drivers/gpu/drm/drm_sysfs.c b/drivers/gpu/drm/drm_sysfs.c
index fb3bbb6adcd1..bd77b35ceb8a 100644
--- a/drivers/gpu/drm/drm_sysfs.c
+++ b/drivers/gpu/drm/drm_sysfs.c
@@ -24,6 +24,7 @@ 
 #include <drm/drm_accel.h>
 #include <drm/drm_connector.h>
 #include <drm/drm_device.h>
+#include <drm/drm_drv.h>
 #include <drm/drm_file.h>
 #include <drm/drm_modes.h>
 #include <drm/drm_print.h>
@@ -508,6 +509,26 @@  void drm_sysfs_connector_property_event(struct drm_connector *connector,
 }
 EXPORT_SYMBOL(drm_sysfs_connector_property_event);
 
+static ssize_t wedge_recovery_show(struct device *device,
+				   struct device_attribute *attr, char *buf)
+{
+	struct drm_minor *minor = to_drm_minor(device);
+	struct drm_device *dev = minor->dev;
+	unsigned int method, count = DRM_WEDGE_RECOVERY_REBIND;
+
+	for_each_set_bit(method, &dev->wedge_recovery, DRM_WEDGE_RECOVERY_MAX)
+		count += sysfs_emit_at(buf, count, "%s\n", drm_wedge_recovery_name(method));
+
+	return count;
+}
+static DEVICE_ATTR_RO(wedge_recovery);
+
+static struct attribute *minor_dev_attrs[] = {
+	&dev_attr_wedge_recovery.attr,
+	NULL
+};
+ATTRIBUTE_GROUPS(minor_dev);
+
 struct device *drm_sysfs_minor_alloc(struct drm_minor *minor)
 {
 	const char *minor_str;
@@ -532,6 +553,7 @@  struct device *drm_sysfs_minor_alloc(struct drm_minor *minor)
 		kdev->devt = MKDEV(DRM_MAJOR, minor->index);
 		kdev->class = drm_class;
 		kdev->type = &drm_sysfs_device_minor;
+		kdev->groups = minor_dev_groups;
 	}
 
 	kdev->parent = minor->dev->dev;