A future patch performs the destination DMA mapping of a defrag move in
two stages when the BO is IOVA mapped: a temporary contiguous mapping of
just that changed pages used for the GPU copy, followed by a post-copy
finalize step that tears that mapping down and links the new backing
into the (transferred) IOVA reservation. The finalize step must run only
after the GPU copy it depends on has completed, so it is dispatched as
an xe_dep_job.

Add a per-device xe_dep_scheduler dedicated to these finalize jobs,
created in xe_bo_defrag_init() (after the migrate contexts are up) and
torn down in xe_bo_defrag_fini(). No users yet; the job itself is added
in a later patch.

v4:
 -Gate dep scheduler creation on use_dma_iommu (Niranjana)

Cc: Carlos Santa <[email protected]>
Cc: Ryan Neph <[email protected]>
Cc: Natalie Vock <[email protected]>
Cc: Arun Pravin <[email protected]>
Cc: Matthew Auld <[email protected]>
Cc: Maarten Lankhorst <[email protected]>
Cc: Maxime Ripard <[email protected]>
Cc: Thomas Zimmermann <[email protected]>
Cc: David Airlie <[email protected]>
Cc: Simona Vetter <[email protected]>
Cc: [email protected]
Cc: [email protected]
Cc: Thomas Hellström <[email protected]>
Signed-off-by: Matthew Brost <[email protected]>
Reviewed-by: Niranjana Vishwanathapura <[email protected]>
---
 drivers/gpu/drm/xe/xe_bo.c           | 19 +++++++++++++++++++
 drivers/gpu/drm/xe/xe_device_types.h | 10 ++++++++++
 2 files changed, 29 insertions(+)

diff --git a/drivers/gpu/drm/xe/xe_bo.c b/drivers/gpu/drm/xe/xe_bo.c
index e2a725c790d8..55253071950c 100644
--- a/drivers/gpu/drm/xe/xe_bo.c
+++ b/drivers/gpu/drm/xe/xe_bo.c
@@ -28,6 +28,7 @@
 #include <trace/events/gpu_mem.h>
 
 #include "xe_device.h"
+#include "xe_dep_scheduler.h"
 #include "xe_dma_buf.h"
 #include "xe_drm_client.h"
 #include "xe_ggtt.h"
@@ -1546,6 +1547,10 @@ static void xe_bo_defrag_fini(void *arg)
        struct xe_device *xe = arg;
 
        disable_delayed_work_sync(&xe->mem.defrag.worker);
+       if (xe->mem.defrag.iova_sched) {
+               xe_dep_scheduler_fini(xe->mem.defrag.iova_sched);
+               xe->mem.defrag.iova_sched = NULL;
+       }
 }
 
 /**
@@ -1585,6 +1590,20 @@ int xe_bo_defrag_init_early(struct xe_device *xe)
  */
 int xe_bo_defrag_init(struct xe_device *xe)
 {
+
+       if (use_dma_iommu(xe->drm.dev)) {
+               struct xe_dep_scheduler *iova_sched;
+
+#define XE_BO_MAX_IOVA_DEFRAG_JOBS     16      /* Picking a reasonable value */
+               iova_sched = xe_dep_scheduler_create(xe, NULL, "xe_iova_defrag",
+                                                    
XE_BO_MAX_IOVA_DEFRAG_JOBS);
+#undef XE_BO_MAX_IOVA_DEFRAG_JOBS
+               if (IS_ERR(iova_sched))
+                       return PTR_ERR(iova_sched);
+
+               xe->mem.defrag.iova_sched = iova_sched;
+       }
+
        return devm_add_action_or_reset(xe->drm.dev, xe_bo_defrag_fini, xe);
 }
 
diff --git a/drivers/gpu/drm/xe/xe_device_types.h 
b/drivers/gpu/drm/xe/xe_device_types.h
index f64f19c85c71..423a868d4605 100644
--- a/drivers/gpu/drm/xe/xe_device_types.h
+++ b/drivers/gpu/drm/xe/xe_device_types.h
@@ -42,6 +42,7 @@
 
 struct drm_pagemap_shrinker;
 struct intel_display;
+struct xe_dep_scheduler;
 struct intel_dg_nvm_dev;
 struct xe_cpu_bind;
 struct xe_ggtt;
@@ -354,6 +355,15 @@ struct xe_device {
                         * not be queued. Protected by @mem.defrag.lock.
                         */
                        bool suspended;
+                       /**
+                        * @mem.defrag.iova_sched: Dependency scheduler used to
+                        * run the post-copy IOVA finalize job for defrag moves
+                        * of IOVA-mapped BOs. The job tears down the temporary
+                        * copy-step IOVA mapping and links the new backing into
+                        * the (transferred) reservation once the GPU copy that
+                        * its dependencies gate has completed.
+                        */
+                       struct xe_dep_scheduler *iova_sched;
                } defrag;
        } mem;
 
-- 
2.34.1

Reply via email to