drm/i915: Combine all i915_vma bitfields into a single set of flags
[deliverable/linux.git] / drivers / gpu / drm / i915 / i915_gem_context.c
index 3336a5fcd029f611a342355cb1d2949509882a07..dc7c0ae73b62a77ea35bb34affcbb4b4c43f4adc 100644 (file)
@@ -134,21 +134,6 @@ static int get_context_size(struct drm_i915_private *dev_priv)
        return ret;
 }
 
-static void i915_gem_context_clean(struct i915_gem_context *ctx)
-{
-       struct i915_hw_ppgtt *ppgtt = ctx->ppgtt;
-       struct i915_vma *vma, *next;
-
-       if (!ppgtt)
-               return;
-
-       list_for_each_entry_safe(vma, next, &ppgtt->base.inactive_list,
-                                vm_link) {
-               if (WARN_ON(__i915_vma_unbind_no_wait(vma)))
-                       break;
-       }
-}
-
 void i915_gem_context_free(struct kref *ctx_ref)
 {
        struct i915_gem_context *ctx = container_of(ctx_ref, typeof(*ctx), ref);
@@ -156,13 +141,7 @@ void i915_gem_context_free(struct kref *ctx_ref)
 
        lockdep_assert_held(&ctx->i915->drm.struct_mutex);
        trace_i915_context_free(ctx);
-
-       /*
-        * This context is going away and we need to remove all VMAs still
-        * around. This is to handle imported shared objects for which
-        * destructor did not run when their handles were closed.
-        */
-       i915_gem_context_clean(ctx);
+       GEM_BUG_ON(!ctx->closed);
 
        i915_ppgtt_put(ctx->ppgtt);
 
@@ -224,6 +203,37 @@ i915_gem_alloc_context_obj(struct drm_device *dev, size_t size)
        return obj;
 }
 
+static void i915_ppgtt_close(struct i915_address_space *vm)
+{
+       struct list_head *phases[] = {
+               &vm->active_list,
+               &vm->inactive_list,
+               &vm->unbound_list,
+               NULL,
+       }, **phase;
+
+       GEM_BUG_ON(vm->closed);
+       vm->closed = true;
+
+       for (phase = phases; *phase; phase++) {
+               struct i915_vma *vma, *vn;
+
+               list_for_each_entry_safe(vma, vn, *phase, vm_link)
+                       if (!i915_vma_is_closed(vma))
+                               i915_vma_close(vma);
+       }
+}
+
+static void context_close(struct i915_gem_context *ctx)
+{
+       GEM_BUG_ON(ctx->closed);
+       ctx->closed = true;
+       if (ctx->ppgtt)
+               i915_ppgtt_close(&ctx->ppgtt->base);
+       ctx->file_priv = ERR_PTR(-EBADF);
+       i915_gem_context_put(ctx);
+}
+
 static int assign_hw_id(struct drm_i915_private *dev_priv, unsigned *out)
 {
        int ret;
@@ -305,7 +315,7 @@ __create_hw_context(struct drm_device *dev,
        return ctx;
 
 err_out:
-       i915_gem_context_put(ctx);
+       context_close(ctx);
        return ERR_PTR(ret);
 }
 
@@ -327,13 +337,14 @@ i915_gem_create_context(struct drm_device *dev,
                return ctx;
 
        if (USES_FULL_PPGTT(dev)) {
-               struct i915_hw_ppgtt *ppgtt = i915_ppgtt_create(dev, file_priv);
+               struct i915_hw_ppgtt *ppgtt =
+                       i915_ppgtt_create(to_i915(dev), file_priv);
 
                if (IS_ERR(ppgtt)) {
                        DRM_DEBUG_DRIVER("PPGTT setup failed (%ld)\n",
                                         PTR_ERR(ppgtt));
                        idr_remove(&file_priv->context_idr, ctx->user_handle);
-                       i915_gem_context_put(ctx);
+                       context_close(ctx);
                        return ERR_CAST(ppgtt);
                }
 
@@ -504,7 +515,7 @@ void i915_gem_context_fini(struct drm_device *dev)
 
        lockdep_assert_held(&dev->struct_mutex);
 
-       i915_gem_context_put(dctx);
+       context_close(dctx);
        dev_priv->kernel_context = NULL;
 
        ida_destroy(&dev_priv->context_hw_ida);
@@ -514,8 +525,7 @@ static int context_idr_cleanup(int id, void *p, void *data)
 {
        struct i915_gem_context *ctx = p;
 
-       ctx->file_priv = ERR_PTR(-EBADF);
-       i915_gem_context_put(ctx);
+       context_close(ctx);
        return 0;
 }
 
@@ -568,7 +578,7 @@ mi_set_context(struct drm_i915_gem_request *req, u32 hw_flags)
         * itlb_before_ctx_switch.
         */
        if (IS_GEN6(dev_priv)) {
-               ret = engine->flush(req, I915_GEM_GPU_DOMAINS, 0);
+               ret = engine->emit_flush(req, EMIT_INVALIDATE);
                if (ret)
                        return ret;
        }
@@ -815,8 +825,8 @@ static int do_rcs_switch(struct drm_i915_gem_request *req)
         * MI_SET_CONTEXT instead of when the next seqno has completed.
         */
        if (from != NULL) {
-               from->engine[RCS].state->base.read_domains = I915_GEM_DOMAIN_INSTRUCTION;
-               i915_vma_move_to_active(i915_gem_obj_to_ggtt(from->engine[RCS].state), req);
+               struct drm_i915_gem_object *obj = from->engine[RCS].state;
+
                /* As long as MI_SET_CONTEXT is serializing, ie. it flushes the
                 * whole damn pipeline, we don't need to explicitly mark the
                 * object dirty. The only exception is that the context must be
@@ -824,10 +834,11 @@ static int do_rcs_switch(struct drm_i915_gem_request *req)
                 * able to defer doing this until we know the object would be
                 * swapped, but there is no way to do that yet.
                 */
-               from->engine[RCS].state->dirty = 1;
+               obj->base.read_domains = I915_GEM_DOMAIN_INSTRUCTION;
+               i915_vma_move_to_active(i915_gem_obj_to_ggtt(obj), req, 0);
 
                /* obj is kept alive until the next request by its active ref */
-               i915_gem_object_ggtt_unpin(from->engine[RCS].state);
+               i915_gem_object_ggtt_unpin(obj);
                i915_gem_context_put(from);
        }
        engine->last_context = i915_gem_context_get(to);
@@ -894,8 +905,9 @@ int i915_switch_context(struct drm_i915_gem_request *req)
 {
        struct intel_engine_cs *engine = req->engine;
 
-       WARN_ON(i915.enable_execlists);
        lockdep_assert_held(&req->i915->drm.struct_mutex);
+       if (i915.enable_execlists)
+               return 0;
 
        if (!req->ctx->engine[engine->id].state) {
                struct i915_gem_context *to = req->ctx;
@@ -943,9 +955,7 @@ int i915_gem_switch_to_kernel_context(struct drm_i915_private *dev_priv)
                if (IS_ERR(req))
                        return PTR_ERR(req);
 
-               ret = 0;
-               if (!i915.enable_execlists)
-                       ret = i915_switch_context(req);
+               ret = i915_switch_context(req);
                i915_add_request_no_flush(req);
                if (ret)
                        return ret;
@@ -1013,7 +1023,7 @@ int i915_gem_context_destroy_ioctl(struct drm_device *dev, void *data,
        }
 
        idr_remove(&file_priv->context_idr, ctx->user_handle);
-       i915_gem_context_put(ctx);
+       context_close(ctx);
        mutex_unlock(&dev->struct_mutex);
 
        DRM_DEBUG_DRIVER("HW context %d destroyed\n", args->ctx_id);
This page took 0.026318 seconds and 5 git commands to generate.