drm/xe: Runtime PM wake on every IOCTL
authorRodrigo Vivi <rodrigo.vivi@intel.com>
Thu, 22 Feb 2024 16:39:26 +0000 (11:39 -0500)
committerRodrigo Vivi <rodrigo.vivi@intel.com>
Mon, 26 Feb 2024 14:05:22 +0000 (09:05 -0500)
Let's ensure our PCI device is awaken on every IOCTL entry.
Let's increase the runtime_pm protection and start moving
that to the outer bounds.

v2: minor typo fix and renaming function to make it clear
    that is intended to be used by ioctl only. (Matt)
v3: Make it NULL if CONFIG_COMPAT is not selected.

Cc: Matthew Auld <matthew.auld@intel.com>
Reviewed-by: Francois Dugast <francois.dugast@intel.com>
Signed-off-by: Rodrigo Vivi <rodrigo.vivi@intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20240222163937.138342-3-rodrigo.vivi@intel.com
drivers/gpu/drm/xe/xe_device.c
drivers/gpu/drm/xe/xe_pm.c
drivers/gpu/drm/xe/xe_pm.h

index 049bbca6ed565fef8d6647ab99e873ed30f495d1..919ad88f0495ab237084ee35172d1ec6cb7f900b 100644 (file)
@@ -136,15 +136,48 @@ static const struct drm_ioctl_desc xe_ioctls[] = {
                          DRM_RENDER_ALLOW),
 };
 
+static long xe_drm_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
+{
+       struct drm_file *file_priv = file->private_data;
+       struct xe_device *xe = to_xe_device(file_priv->minor->dev);
+       long ret;
+
+       ret = xe_pm_runtime_get_ioctl(xe);
+       if (ret >= 0)
+               ret = drm_ioctl(file, cmd, arg);
+       xe_pm_runtime_put(xe);
+
+       return ret;
+}
+
+#ifdef CONFIG_COMPAT
+static long xe_drm_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
+{
+       struct drm_file *file_priv = file->private_data;
+       struct xe_device *xe = to_xe_device(file_priv->minor->dev);
+       long ret;
+
+       ret = xe_pm_runtime_get_ioctl(xe);
+       if (ret >= 0)
+               ret = drm_compat_ioctl(file, cmd, arg);
+       xe_pm_runtime_put(xe);
+
+       return ret;
+}
+#else
+/* similarly to drm_compat_ioctl, let's it be assigned to .compat_ioct unconditionally */
+#define xe_drm_compat_ioctl NULL
+#endif
+
 static const struct file_operations xe_driver_fops = {
        .owner = THIS_MODULE,
        .open = drm_open,
        .release = drm_release_noglobal,
-       .unlocked_ioctl = drm_ioctl,
+       .unlocked_ioctl = xe_drm_ioctl,
        .mmap = drm_gem_mmap,
        .poll = drm_poll,
        .read = drm_read,
-       .compat_ioctl = drm_compat_ioctl,
+       .compat_ioctl = xe_drm_compat_ioctl,
        .llseek = noop_llseek,
 #ifdef CONFIG_PROC_FS
        .show_fdinfo = drm_show_fdinfo,
index 5289d8c0c3b13c880881c0d64d063e9cbaf324d2..b5511e3c3153a9c41183c86b6383ea975494f8a0 100644 (file)
@@ -430,6 +430,21 @@ int xe_pm_runtime_put(struct xe_device *xe)
        return pm_runtime_put(xe->drm.dev);
 }
 
+/**
+ * xe_pm_runtime_get_ioctl - Get a runtime_pm reference before ioctl
+ * @xe: xe device instance
+ *
+ * Returns: Any number greater than or equal to 0 for success, negative error
+ * code otherwise.
+ */
+int xe_pm_runtime_get_ioctl(struct xe_device *xe)
+{
+       if (WARN_ON(xe_pm_read_callback_task(xe) == current))
+               return -ELOOP;
+
+       return pm_runtime_get_sync(xe->drm.dev);
+}
+
 /**
  * xe_pm_runtime_get_if_active - Get a runtime_pm reference if device active
  * @xe: xe device instance
index 75919eba17461eb6beb66cdb6f565c49de494ebc..7f5884babb29e2e141a3744465bce812c20e9ea0 100644 (file)
@@ -27,6 +27,7 @@ bool xe_pm_runtime_suspended(struct xe_device *xe);
 int xe_pm_runtime_suspend(struct xe_device *xe);
 int xe_pm_runtime_resume(struct xe_device *xe);
 int xe_pm_runtime_get(struct xe_device *xe);
+int xe_pm_runtime_get_ioctl(struct xe_device *xe);
 int xe_pm_runtime_put(struct xe_device *xe);
 int xe_pm_runtime_get_if_active(struct xe_device *xe);
 void xe_pm_assert_unbounded_bridge(struct xe_device *xe);