drm/i915/gem: replace IS_GEN and friends with GRAPHICS_VER
[sfrench/cifs-2.6.git] / drivers / gpu / drm / i915 / gem / i915_gem_context.c
index 4d2f40cf237bd455fa90f6d28375e8deb30e8b64..7720b8c22c81601c3110083a2e0e0d069690e2db 100644 (file)
@@ -232,6 +232,8 @@ static void intel_context_set_gem(struct intel_context *ce,
        if (ctx->sched.priority >= I915_PRIORITY_NORMAL &&
            intel_engine_has_timeslices(ce->engine))
                __set_bit(CONTEXT_USE_SEMAPHORES, &ce->flags);
+
+       intel_context_set_watchdog_us(ce, ctx->watchdog.timeout_us);
 }
 
 static void __free_engines(struct i915_gem_engines *e, unsigned int count)
@@ -386,38 +388,6 @@ static bool __cancel_engine(struct intel_engine_cs *engine)
        return intel_engine_pulse(engine) == 0;
 }
 
-static bool
-__active_engine(struct i915_request *rq, struct intel_engine_cs **active)
-{
-       struct intel_engine_cs *engine, *locked;
-       bool ret = false;
-
-       /*
-        * Serialise with __i915_request_submit() so that it sees
-        * is-banned?, or we know the request is already inflight.
-        *
-        * Note that rq->engine is unstable, and so we double
-        * check that we have acquired the lock on the final engine.
-        */
-       locked = READ_ONCE(rq->engine);
-       spin_lock_irq(&locked->active.lock);
-       while (unlikely(locked != (engine = READ_ONCE(rq->engine)))) {
-               spin_unlock(&locked->active.lock);
-               locked = engine;
-               spin_lock(&locked->active.lock);
-       }
-
-       if (i915_request_is_active(rq)) {
-               if (!__i915_request_is_complete(rq))
-                       *active = locked;
-               ret = true;
-       }
-
-       spin_unlock_irq(&locked->active.lock);
-
-       return ret;
-}
-
 static struct intel_engine_cs *active_engine(struct intel_context *ce)
 {
        struct intel_engine_cs *engine = NULL;
@@ -445,7 +415,7 @@ static struct intel_engine_cs *active_engine(struct intel_context *ce)
                /* Check with the backend if the request is inflight */
                found = true;
                if (likely(rcu_access_pointer(rq->timeline) == ce->timeline))
-                       found = __active_engine(rq, &engine);
+                       found = i915_request_active_engine(rq, &engine);
 
                i915_request_put(rq);
                if (found)
@@ -679,7 +649,7 @@ __create_context(struct drm_i915_private *i915)
 
        kref_init(&ctx->ref);
        ctx->i915 = i915;
-       ctx->sched.priority = I915_USER_PRIORITY(I915_PRIORITY_NORMAL);
+       ctx->sched.priority = I915_PRIORITY_NORMAL;
        mutex_init(&ctx->mutex);
        INIT_LIST_HEAD(&ctx->link);
 
@@ -822,6 +792,41 @@ static void __assign_timeline(struct i915_gem_context *ctx,
        context_apply_all(ctx, __apply_timeline, timeline);
 }
 
+static int __apply_watchdog(struct intel_context *ce, void *timeout_us)
+{
+       return intel_context_set_watchdog_us(ce, (uintptr_t)timeout_us);
+}
+
+static int
+__set_watchdog(struct i915_gem_context *ctx, unsigned long timeout_us)
+{
+       int ret;
+
+       ret = context_apply_all(ctx, __apply_watchdog,
+                               (void *)(uintptr_t)timeout_us);
+       if (!ret)
+               ctx->watchdog.timeout_us = timeout_us;
+
+       return ret;
+}
+
+static void __set_default_fence_expiry(struct i915_gem_context *ctx)
+{
+       struct drm_i915_private *i915 = ctx->i915;
+       int ret;
+
+       if (!IS_ACTIVE(CONFIG_DRM_I915_REQUEST_TIMEOUT) ||
+           !i915->params.request_timeout_ms)
+               return;
+
+       /* Default expiry for user fences. */
+       ret = __set_watchdog(ctx, i915->params.request_timeout_ms * 1000);
+       if (ret)
+               drm_notice(&i915->drm,
+                          "Failed to configure default fence expiry! (%d)",
+                          ret);
+}
+
 static struct i915_gem_context *
 i915_gem_create_context(struct drm_i915_private *i915, unsigned int flags)
 {
@@ -866,6 +871,8 @@ i915_gem_create_context(struct drm_i915_private *i915, unsigned int flags)
                intel_timeline_put(timeline);
        }
 
+       __set_default_fence_expiry(ctx);
+
        trace_i915_context_create(ctx);
 
        return ctx;
@@ -1039,7 +1046,6 @@ struct context_barrier_task {
        void *data;
 };
 
-__i915_active_call
 static void cb_retire(struct i915_active *base)
 {
        struct context_barrier_task *cb = container_of(base, typeof(*cb), base);
@@ -1073,7 +1079,7 @@ static int context_barrier_task(struct i915_gem_context *ctx,
        if (!cb)
                return -ENOMEM;
 
-       i915_active_init(&cb->base, NULL, cb_retire);
+       i915_active_init(&cb->base, NULL, cb_retire, 0);
        err = i915_active_acquire(&cb->base);
        if (err) {
                kfree(cb);
@@ -1184,7 +1190,7 @@ static void set_ppgtt_barrier(void *data)
 {
        struct i915_address_space *old = data;
 
-       if (INTEL_GEN(old->i915) < 8)
+       if (GRAPHICS_VER(old->i915) < 8)
                gen6_ppgtt_unpin_all(i915_vm_to_ppgtt(old));
 
        i915_vm_close(old);
@@ -1430,7 +1436,7 @@ i915_gem_user_to_context_sseu(struct intel_gt *gt,
        context->max_eus_per_subslice = user->max_eus_per_subslice;
 
        /* Part specific restrictions. */
-       if (IS_GEN(i915, 11)) {
+       if (GRAPHICS_VER(i915) == 11) {
                unsigned int hw_s = hweight8(device->slice_mask);
                unsigned int hw_ss_per_s = hweight8(device->subslice_mask[0]);
                unsigned int req_s = hweight8(context->slice_mask);
@@ -1497,7 +1503,7 @@ static int set_sseu(struct i915_gem_context *ctx,
        if (args->size < sizeof(user_sseu))
                return -EINVAL;
 
-       if (!IS_GEN(i915, 11))
+       if (GRAPHICS_VER(i915) != 11)
                return -ENODEV;
 
        if (copy_from_user(&user_sseu, u64_to_user_ptr(args->value),
@@ -1959,7 +1965,7 @@ static int set_priority(struct i915_gem_context *ctx,
            !capable(CAP_SYS_NICE))
                return -EPERM;
 
-       ctx->sched.priority = I915_USER_PRIORITY(priority);
+       ctx->sched.priority = priority;
        context_apply_all(ctx, __apply_priority, ctx);
 
        return 0;
@@ -2463,7 +2469,7 @@ int i915_gem_context_getparam_ioctl(struct drm_device *dev, void *data,
 
        case I915_CONTEXT_PARAM_PRIORITY:
                args->size = 0;
-               args->value = ctx->sched.priority >> I915_USER_PRIORITY_SHIFT;
+               args->value = ctx->sched.priority;
                break;
 
        case I915_CONTEXT_PARAM_SSEU: