Move the syncobj dependency setup out of v3d_job_init() into its own
v3d_job_add_syncobjs() helper and make the queue that the job was
submitted a variable in struct v3d_job, so that v3d_job_add_syncobjs()
can use it. No functional change.

This prepares for the next commit which changes the error handling, and
for a later consolidation that separates job allocation from syncobj
attachment.

Reviewed-by: Tvrtko Ursulin <[email protected]>
Signed-off-by: Maíra Canal <[email protected]>
---
 drivers/gpu/drm/v3d/v3d_drv.h    |  3 ++
 drivers/gpu/drm/v3d/v3d_submit.c | 72 ++++++++++++++++++++++++----------------
 2 files changed, 47 insertions(+), 28 deletions(-)

diff --git a/drivers/gpu/drm/v3d/v3d_drv.h b/drivers/gpu/drm/v3d/v3d_drv.h
index 5a0b9da2c3aa..79672abef70d 100644
--- a/drivers/gpu/drm/v3d/v3d_drv.h
+++ b/drivers/gpu/drm/v3d/v3d_drv.h
@@ -294,6 +294,9 @@ struct v3d_job {
 
        struct v3d_dev *v3d;
 
+       /* The queue that the job was submitted on. */
+       enum v3d_queue queue;
+
        /* This is the array of BOs that were looked up at the start
         * of submission.
         */
diff --git a/drivers/gpu/drm/v3d/v3d_submit.c b/drivers/gpu/drm/v3d/v3d_submit.c
index 1db43c6a078d..8250376d104c 100644
--- a/drivers/gpu/drm/v3d/v3d_submit.c
+++ b/drivers/gpu/drm/v3d/v3d_submit.c
@@ -180,17 +180,56 @@ v3d_job_deallocate(void **container)
        *container = NULL;
 }
 
+static int
+v3d_job_add_syncobjs(struct v3d_job *job, struct drm_file *file_priv,
+                    u32 in_sync, struct v3d_submit_ext *se)
+{
+       bool has_multisync = se && (se->flags & DRM_V3D_EXT_ID_MULTI_SYNC);
+       struct v3d_dev *v3d = job->v3d;
+       int ret = 0;
+
+       if (!has_multisync) {
+               ret = drm_sched_job_add_syncobj_dependency(&job->base, 
file_priv,
+                                                          in_sync, 0);
+               // TODO: Investigate why this was filtered out for the IOCTL.
+               if (ret && ret != -ENOENT)
+                       return ret;
+               return 0;
+       }
+
+       if (se->in_sync_count && se->wait_stage == job->queue) {
+               struct drm_v3d_sem __user *handle = 
u64_to_user_ptr(se->in_syncs);
+
+               for (int i = 0; i < se->in_sync_count; i++) {
+                       struct drm_v3d_sem in;
+
+                       if (copy_from_user(&in, handle++, sizeof(in))) {
+                               drm_dbg(&v3d->drm, "Failed to copy wait dep 
handle.\n");
+                               return -EFAULT;
+                       }
+
+                       ret = drm_sched_job_add_syncobj_dependency(&job->base,
+                                                                  file_priv, 
in.handle, 0);
+                       // TODO: Investigate why this was filtered out for the 
IOCTL.
+                       if (ret && ret != -ENOENT)
+                               return ret;
+               }
+       }
+
+       return 0;
+}
+
 static int
 v3d_job_init(struct v3d_dev *v3d, struct drm_file *file_priv,
             struct v3d_job *job, void (*free)(struct kref *ref),
             u32 in_sync, struct v3d_submit_ext *se, enum v3d_queue queue)
 {
        struct v3d_file_priv *v3d_priv = file_priv->driver_priv;
-       bool has_multisync = se && (se->flags & DRM_V3D_EXT_ID_MULTI_SYNC);
-       int ret, i;
+       int ret;
 
        job->v3d = v3d;
        job->free = free;
+       job->queue = queue;
        job->file_priv = v3d_priv;
 
        ret = drm_sched_job_init(&job->base, &v3d_priv->sched_entity[queue],
@@ -198,32 +237,9 @@ v3d_job_init(struct v3d_dev *v3d, struct drm_file 
*file_priv,
        if (ret)
                return ret;
 
-       if (has_multisync) {
-               if (se->in_sync_count && se->wait_stage == queue) {
-                       struct drm_v3d_sem __user *handle = 
u64_to_user_ptr(se->in_syncs);
-
-                       for (i = 0; i < se->in_sync_count; i++) {
-                               struct drm_v3d_sem in;
-
-                               if (copy_from_user(&in, handle++, sizeof(in))) {
-                                       ret = -EFAULT;
-                                       drm_dbg(&v3d->drm, "Failed to copy wait 
dep handle.\n");
-                                       goto fail_job_init;
-                               }
-                               ret = 
drm_sched_job_add_syncobj_dependency(&job->base, file_priv, in.handle, 0);
-
-                               // TODO: Investigate why this was filtered out 
for the IOCTL.
-                               if (ret && ret != -ENOENT)
-                                       goto fail_job_init;
-                       }
-               }
-       } else {
-               ret = drm_sched_job_add_syncobj_dependency(&job->base, 
file_priv, in_sync, 0);
-
-               // TODO: Investigate why this was filtered out for the IOCTL.
-               if (ret && ret != -ENOENT)
-                       goto fail_job_init;
-       }
+       ret = v3d_job_add_syncobjs(job, file_priv, in_sync, se);
+       if (ret)
+               goto fail_job_init;
 
        /* CPU jobs don't require hardware resources */
        if (queue != V3D_CPU) {

-- 
2.54.0

Reply via email to