drm/i915: Update i915_switch_context() to take a request structure
authorJohn Harrison <John.C.Harrison@Intel.com>
Fri, 29 May 2015 16:43:41 +0000 (17:43 +0100)
committerDaniel Vetter <daniel.vetter@ffwll.ch>
Tue, 23 Jun 2015 12:02:09 +0000 (14:02 +0200)
Now that the request is guaranteed to specify the context, it is possible to
update the context switch code to use requests rather than ring and context
pairs. This patch updates i915_switch_context() accordingly.

Also removed the warning that the request's context must match the last context
switch's context. As the context switch now gets the context object from the
request structure, there is no longer any scope for the two to become out of
step.

For: VIZ-5115
Signed-off-by: John Harrison <John.C.Harrison@Intel.com>
Reviewed-by: Tomas Elf <tomas.elf@intel.com>
Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
drivers/gpu/drm/i915/i915_drv.h
drivers/gpu/drm/i915/i915_gem.c
drivers/gpu/drm/i915/i915_gem_context.c
drivers/gpu/drm/i915/i915_gem_execbuffer.c

index 714caed86cdc30a72c8d04155730a2ff3e322941..b96d4b1a09780585782136416aa70c2f41d7cbd7 100644 (file)
@@ -3042,8 +3042,7 @@ void i915_gem_context_reset(struct drm_device *dev);
 int i915_gem_context_open(struct drm_device *dev, struct drm_file *file);
 int i915_gem_context_enable(struct drm_i915_gem_request *req);
 void i915_gem_context_close(struct drm_device *dev, struct drm_file *file);
-int i915_switch_context(struct intel_engine_cs *ring,
-                       struct intel_context *to);
+int i915_switch_context(struct drm_i915_gem_request *req);
 struct intel_context *
 i915_gem_context_get(struct drm_i915_file_private *file_priv, u32 id);
 void i915_gem_context_free(struct kref *ctx_ref);
index 8fbdfc3e971c325180e4cead3e47e68271cf8d45..4625a2fdc180f4504a2575fca4d7b1d65ab5ec76 100644 (file)
@@ -2539,8 +2539,6 @@ void __i915_add_request(struct intel_engine_cs *ring,
         */
        request->batch_obj = obj;
 
-       WARN_ON(!i915.enable_execlists && (request->ctx != ring->last_context));
-
        request->emitted_jiffies = jiffies;
        list_add_tail(&request->list, &ring->request_list);
        request->file_priv = NULL;
@@ -3311,7 +3309,7 @@ int i915_gpu_idle(struct drm_device *dev)
                        if (ret)
                                return ret;
 
-                       ret = i915_switch_context(req->ring, ring->default_context);
+                       ret = i915_switch_context(req);
                        if (ret) {
                                i915_gem_request_cancel(req);
                                return ret;
index 4514d5aa5a93302451bfdac44ca885042e6bc503..f8902bcc393976937cdb621f3dcdcfa8505d6a13 100644 (file)
@@ -420,7 +420,7 @@ int i915_gem_context_enable(struct drm_i915_gem_request *req)
 
                ret = ring->init_context(ring, ring->default_context);
        } else
-               ret = i915_switch_context(ring, ring->default_context);
+               ret = i915_switch_context(req);
 
        if (ret) {
                DRM_ERROR("ring init context: %d\n", ret);
@@ -775,8 +775,7 @@ unpin_out:
 
 /**
  * i915_switch_context() - perform a GPU context switch.
- * @ring: ring for which we'll execute the context switch
- * @to: the context to switch to
+ * @req: request for which we'll execute the context switch
  *
  * The context life cycle is simple. The context refcount is incremented and
  * decremented by 1 and create and destroy. If the context is in use by the GPU,
@@ -787,25 +786,25 @@ unpin_out:
  * switched by writing to the ELSP and requests keep a reference to their
  * context.
  */
-int i915_switch_context(struct intel_engine_cs *ring,
-                       struct intel_context *to)
+int i915_switch_context(struct drm_i915_gem_request *req)
 {
+       struct intel_engine_cs *ring = req->ring;
        struct drm_i915_private *dev_priv = ring->dev->dev_private;
 
        WARN_ON(i915.enable_execlists);
        WARN_ON(!mutex_is_locked(&dev_priv->dev->struct_mutex));
 
-       if (to->legacy_hw_ctx.rcs_state == NULL) { /* We have the fake context */
-               if (to != ring->last_context) {
-                       i915_gem_context_reference(to);
+       if (req->ctx->legacy_hw_ctx.rcs_state == NULL) { /* We have the fake context */
+               if (req->ctx != ring->last_context) {
+                       i915_gem_context_reference(req->ctx);
                        if (ring->last_context)
                                i915_gem_context_unreference(ring->last_context);
-                       ring->last_context = to;
+                       ring->last_context = req->ctx;
                }
                return 0;
        }
 
-       return do_switch(ring, to);
+       return do_switch(req->ring, req->ctx);
 }
 
 static bool contexts_enabled(struct drm_device *dev)
index a15517249bb9926376840d85cc5178661778f010..d0ced5b04f4d32345e1ea05cbc3f96cf8f5eb708 100644 (file)
@@ -1250,7 +1250,7 @@ i915_gem_ringbuffer_submission(struct i915_execbuffer_params *params,
        if (ret)
                goto error;
 
-       ret = i915_switch_context(ring, params->ctx);
+       ret = i915_switch_context(params->request);
        if (ret)
                goto error;