#include "amdgpu_trace.h"
 #include "amdgpu_reset.h"
 
-/*
- * Fences mark an event in the GPUs pipeline and are used
- * for GPU/CPU synchronization.  When the fence is written,
- * it is expected that all buffers associated with that fence
- * are no longer in use by the associated ring on the GPU and
- * that the relevant GPU caches have been flushed.
- */
-
-struct amdgpu_fence {
-       struct dma_fence base;
-
-       /* RB, DMA, etc. */
-       struct amdgpu_ring              *ring;
-       ktime_t                         start_timestamp;
-};
-
 static struct kmem_cache *amdgpu_fence_slab;
 
 int amdgpu_fence_slab_init(void)
                am_fence = kmem_cache_alloc(amdgpu_fence_slab, GFP_ATOMIC);
                if (am_fence == NULL)
                        return -ENOMEM;
-               fence = &am_fence->base;
-               am_fence->ring = ring;
        } else {
                /* take use of job-embedded fence */
-               fence = &job->hw_fence;
+               am_fence = &job->hw_fence;
        }
+       fence = &am_fence->base;
+       am_fence->ring = ring;
 
        seq = ++ring->fence_drv.sync_seq;
        if (job && job->job_run_counter) {
                         * it right here or we won't be able to track them in fence_drv
                         * and they will remain unsignaled during sa_bo free.
                         */
-                       job = container_of(old, struct amdgpu_job, hw_fence);
+                       job = container_of(old, struct amdgpu_job, hw_fence.base);
                        if (!job->base.s_fence && !dma_fence_is_signaled(old))
                                dma_fence_signal(old);
                        RCU_INIT_POINTER(*ptr, NULL);
 
 static const char *amdgpu_job_fence_get_timeline_name(struct dma_fence *f)
 {
-       struct amdgpu_job *job = container_of(f, struct amdgpu_job, hw_fence);
+       struct amdgpu_job *job = container_of(f, struct amdgpu_job, hw_fence.base);
 
        return (const char *)to_amdgpu_ring(job->base.sched)->name;
 }
  */
 static bool amdgpu_job_fence_enable_signaling(struct dma_fence *f)
 {
-       struct amdgpu_job *job = container_of(f, struct amdgpu_job, hw_fence);
+       struct amdgpu_job *job = container_of(f, struct amdgpu_job, hw_fence.base);
 
        if (!timer_pending(&to_amdgpu_ring(job->base.sched)->fence_drv.fallback_timer))
                amdgpu_fence_schedule_fallback(to_amdgpu_ring(job->base.sched));
        struct dma_fence *f = container_of(rcu, struct dma_fence, rcu);
 
        /* free job if fence has a parent job */
-       kfree(container_of(f, struct amdgpu_job, hw_fence));
+       kfree(container_of(f, struct amdgpu_job, hw_fence.base));
 }
 
 /**
 
        /* Check if any fences where initialized */
        if (job->base.s_fence && job->base.s_fence->finished.ops)
                f = &job->base.s_fence->finished;
-       else if (job->hw_fence.ops)
-               f = &job->hw_fence;
+       else if (job->hw_fence.base.ops)
+               f = &job->hw_fence.base;
        else
                f = NULL;
 
        amdgpu_sync_free(&job->explicit_sync);
 
        /* only put the hw fence if has embedded fence */
-       if (!job->hw_fence.ops)
+       if (!job->hw_fence.base.ops)
                kfree(job);
        else
-               dma_fence_put(&job->hw_fence);
+               dma_fence_put(&job->hw_fence.base);
 }
 
 void amdgpu_job_set_gang_leader(struct amdgpu_job *job,
        if (job->gang_submit != &job->base.s_fence->scheduled)
                dma_fence_put(job->gang_submit);
 
-       if (!job->hw_fence.ops)
+       if (!job->hw_fence.base.ops)
                kfree(job);
        else
-               dma_fence_put(&job->hw_fence);
+               dma_fence_put(&job->hw_fence.base);
 }
 
 struct dma_fence *amdgpu_job_submit(struct amdgpu_job *job)
 
        struct dma_fence                **fences;
 };
 
+/*
+ * Fences mark an event in the GPUs pipeline and are used
+ * for GPU/CPU synchronization.  When the fence is written,
+ * it is expected that all buffers associated with that fence
+ * are no longer in use by the associated ring on the GPU and
+ * that the relevant GPU caches have been flushed.
+ */
+
+struct amdgpu_fence {
+       struct dma_fence base;
+
+       /* RB, DMA, etc. */
+       struct amdgpu_ring              *ring;
+       ktime_t                         start_timestamp;
+};
+
 extern const struct drm_sched_backend_ops amdgpu_sched_ops;
 
 void amdgpu_fence_driver_clear_job_fences(struct amdgpu_ring *ring);