From mboxrd@z Thu Jan 1 00:00:00 1970 From: Ben Widawsky Subject: [PATCH 6/8] drm/i915/context: enable calling context_switch Date: Wed, 2 Feb 2011 15:00:18 -0800 Message-ID: <1296687620-27019-7-git-send-email-bwidawsk@gmail.com> References: <1296687620-27019-1-git-send-email-bwidawsk@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Received: from mail-yw0-f49.google.com (mail-yw0-f49.google.com [209.85.213.49]) by gabe.freedesktop.org (Postfix) with ESMTP id B2DD49E9CA for ; Wed, 2 Feb 2011 15:00:52 -0800 (PST) Received: by ywf7 with SMTP id 7so239314ywf.36 for ; Wed, 02 Feb 2011 15:00:52 -0800 (PST) In-Reply-To: <1296687620-27019-1-git-send-email-bwidawsk@gmail.com> List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: intel-gfx-bounces+gcfxdi-intel-gfx=m.gmane.org@lists.freedesktop.org Errors-To: intel-gfx-bounces+gcfxdi-intel-gfx=m.gmane.org@lists.freedesktop.org To: intel-gfx@lists.freedesktop.org List-Id: intel-gfx@lists.freedesktop.org Changed context_validation code to return a pointer to the context which was validated. This saved us a context id lookup later when we want to actually context switch. The downside is we can't differentiate a lost context (buffer moved) from a never-existed context. This seems okay to me for now. Added a call from do_execbuffer to actually context_switch for the ringbuffer. Although context_switch is not yet implemented, this can hopefully prove we don't break the existing code. --- drivers/gpu/drm/i915/i915_context.c | 14 ++++++++------ drivers/gpu/drm/i915/i915_gem_execbuffer.c | 13 ++++++++----- drivers/gpu/drm/i915/intel_ringbuffer.h | 2 +- 3 files changed, 17 insertions(+), 12 deletions(-) diff --git a/drivers/gpu/drm/i915/i915_context.c b/drivers/gpu/drm/i915/i915_context.c index 4795caf..1085797 100644 --- a/drivers/gpu/drm/i915/i915_context.c +++ b/drivers/gpu/drm/i915/i915_context.c @@ -73,7 +73,8 @@ static void i915_context_del_id(struct drm_device *dev, idr_remove(&dev_priv->i915_ctx_idr, ctx->ctx_id); } -int i915_context_validate(struct drm_device *dev, struct drm_file *file, +struct drm_i915_gem_context * +i915_context_validate(struct drm_device *dev, struct drm_file *file, uint32_t ctx_id, struct drm_i915_context_flag *ctx_flag, int count) { @@ -85,7 +86,7 @@ int i915_context_validate(struct drm_device *dev, struct drm_file *file, ctx = i915_context_lookup_id(dev, ctx_id); if (ctx == NULL) { DRM_ERROR("Couldn't find context\n"); - return -ENXIO; + return ctx; } if ((!count || !ctx_flag)) @@ -117,7 +118,7 @@ int i915_context_validate(struct drm_device *dev, struct drm_file *file, } obj_priv = to_intel_bo(obj); if (flag->offset && HAS_PPGTT(dev)) { - /* + /* * No need to check for overlaps because this is * in their local GTT so they can only screw up * themselves. But do check serious violations @@ -163,13 +164,14 @@ out: DRM_DEBUG_DRIVER("Context associated buffer has moved" " %p->%p\n", ppgtt_offset, obj_priv->gtt_offset); - ret = -EIO; - break; + mutex_unlock(&ctx->slot_mtx); + ctx = NULL; + return ctx; } } mutex_unlock(&ctx->slot_mtx); - return ret; + return ctx; } void i915_context_bind_ppgtt(struct drm_i915_gem_object *obj) diff --git a/drivers/gpu/drm/i915/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/i915_gem_execbuffer.c index 356388a..b2313f0 100644 --- a/drivers/gpu/drm/i915/i915_gem_execbuffer.c +++ b/drivers/gpu/drm/i915/i915_gem_execbuffer.c @@ -990,6 +990,7 @@ i915_gem_do_execbuffer(struct drm_device *dev, void *data, struct drm_i915_gem_object *batch_obj; struct drm_clip_rect *cliprects = NULL; struct intel_ring_buffer *ring; + struct drm_i915_gem_context *ctx; u32 exec_start, exec_len; u32 seqno; u32 ctx_id; @@ -1006,12 +1007,11 @@ i915_gem_do_execbuffer(struct drm_device *dev, void *data, ctx_id = EXECBUFFER2_CTX_ID(args); if (ctx_id) { - ret = i915_context_validate(dev, file, ctx_id, + ctx = i915_context_validate(dev, file, ctx_id, ctx_flags, flag_count); - if (ret) { - if (ret == -EIO) - DRM_DEBUG_DRIVER("Context resubmission required\n"); - return ret; + if (!ctx) { + DRM_DEBUG_DRIVER("Context resubmission required\n"); + return -EIO; } } #if WATCH_EXEC @@ -1203,6 +1203,9 @@ i915_gem_do_execbuffer(struct drm_device *dev, void *data, } } + if (!dev_priv->ctx_disable) + ring->context_switch(ring, ctx, I915_CONTEXT_NORMAL_SWITCH); + exec_start = batch_obj->gtt_offset + args->batch_start_offset; exec_len = args->batch_len; if (cliprects) { diff --git a/drivers/gpu/drm/i915/intel_ringbuffer.h b/drivers/gpu/drm/i915/intel_ringbuffer.h index 68ebecf..61525ba 100644 --- a/drivers/gpu/drm/i915/intel_ringbuffer.h +++ b/drivers/gpu/drm/i915/intel_ringbuffer.h @@ -82,7 +82,7 @@ struct intel_ring_buffer { struct drm_i915_gem_context *last_context; void (*context_switch)(struct intel_ring_buffer *ring, struct drm_i915_gem_context *ctx, - uint32_t flags); + u32 flags); /** * List of objects currently involved in rendering from the -- 1.7.3.4