]> exis.tech > repos - linux.git/blobdiff - drivers/gpu/drm/xe/xe_module.c
Merge tag 'hwmon-for-v7.2-rc5' of git://git.kernel.org/pub/scm/linux/kernel/git/groec...
[linux.git] / drivers / gpu / drm / xe / xe_module.c
index 4cb5781829122950af0e2bb69a1a70c02277bd74..99347f216ec8932216695324f808d0f2ac41d9b9 100644 (file)
@@ -7,6 +7,7 @@
 
 #include <linux/init.h>
 #include <linux/module.h>
+#include <linux/workqueue.h>
 
 #include <drm/drm_module.h>
 
@@ -91,6 +92,50 @@ static int xe_check_nomodeset(void)
        return 0;
 }
 
+static struct workqueue_struct *xe_destroy_wq;
+
+static int __init xe_destroy_wq_module_init(void)
+{
+       xe_destroy_wq = alloc_workqueue("xe-guc-destroy-wq", WQ_UNBOUND, 0);
+       if (!xe_destroy_wq)
+               return -ENOMEM;
+       return 0;
+}
+
+static void xe_destroy_wq_module_exit(void)
+{
+       if (xe_destroy_wq)
+               destroy_workqueue(xe_destroy_wq);
+       xe_destroy_wq = NULL;
+}
+
+/**
+ * xe_destroy_wq_queue() - Queue work on the destroy workqueue
+ * @work: work item to queue
+ *
+ * The destroy workqueue has module lifetime and is used for GuC exec queue
+ * teardown that can outlive a single xe_device. SVM pagemap destroy uses the
+ * per-device xe->destroy_wq instead.
+ *
+ * Return: %true if @work was queued, %false if it was already pending.
+ */
+bool xe_destroy_wq_queue(struct work_struct *work)
+{
+       return queue_work(xe_destroy_wq, work);
+}
+
+/**
+ * xe_destroy_wq_flush() - Flush the destroy workqueue
+ *
+ * Drains all pending destroy work. Called from PCI remove to ensure
+ * teardown ordering before the device is destroyed.
+ */
+void xe_destroy_wq_flush(void)
+{
+       if (xe_destroy_wq)
+               flush_workqueue(xe_destroy_wq);
+}
+
 struct init_funcs {
        int (*init)(void);
        void (*exit)(void);
@@ -112,6 +157,10 @@ static const struct init_funcs init_funcs[] = {
                .init = xe_sched_job_module_init,
                .exit = xe_sched_job_module_exit,
        },
+       {
+               .init = xe_destroy_wq_module_init,
+               .exit = xe_destroy_wq_module_exit,
+       },
        {
                .init = xe_register_pci_driver,
                .exit = xe_unregister_pci_driver,