From patchwork Thu Mar 14 15:52:02 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mika Kuoppala X-Patchwork-Id: 2272101 Return-Path: X-Original-To: patchwork-intel-gfx@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by patchwork1.kernel.org (Postfix) with ESMTP id 1B4783FCF6 for ; Thu, 14 Mar 2013 15:50:14 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 0CAB2E6980 for ; Thu, 14 Mar 2013 08:50:14 -0700 (PDT) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by gabe.freedesktop.org (Postfix) with ESMTP id 6EFA1E6762 for ; Thu, 14 Mar 2013 08:48:46 -0700 (PDT) Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga102.fm.intel.com with ESMTP; 14 Mar 2013 08:48:45 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="4.84,845,1355126400"; d="scan'208";a="306618191" Received: from unknown (HELO rosetta) ([10.237.72.51]) by fmsmga002.fm.intel.com with ESMTP; 14 Mar 2013 08:48:44 -0700 Received: by rosetta (Postfix, from userid 1000) id 2ED5680091; Thu, 14 Mar 2013 17:52:22 +0200 (EET) From: Mika Kuoppala To: intel-gfx@lists.freedesktop.org Date: Thu, 14 Mar 2013 17:52:02 +0200 Message-Id: <1363276337-12509-2-git-send-email-mika.kuoppala@intel.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1363276337-12509-1-git-send-email-mika.kuoppala@intel.com> References: <1363276337-12509-1-git-send-email-mika.kuoppala@intel.com> Cc: miku@iki.fi Subject: [Intel-gfx] [PATCH v2 01/16] drm/i915: return context from i915_switch_context() X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: intel-gfx-bounces+patchwork-intel-gfx=patchwork.kernel.org@lists.freedesktop.org Errors-To: intel-gfx-bounces+patchwork-intel-gfx=patchwork.kernel.org@lists.freedesktop.org In preparation for the next commit, return context that was switched to from i915_switch_context(). v2: context in return value instead of param. (Ben Widawsky) Signed-off-by: Mika Kuoppala --- drivers/gpu/drm/i915/i915_drv.h | 5 +++-- drivers/gpu/drm/i915/i915_gem.c | 8 ++++--- drivers/gpu/drm/i915/i915_gem_context.c | 32 +++++++++++++++++----------- drivers/gpu/drm/i915/i915_gem_execbuffer.c | 7 ++++-- 4 files changed, 32 insertions(+), 20 deletions(-) diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h index ca6b215..ccac8ea 100644 --- a/drivers/gpu/drm/i915/i915_drv.h +++ b/drivers/gpu/drm/i915/i915_drv.h @@ -1669,8 +1669,9 @@ struct dma_buf *i915_gem_prime_export(struct drm_device *dev, void i915_gem_context_init(struct drm_device *dev); void i915_gem_context_fini(struct drm_device *dev); void i915_gem_context_close(struct drm_device *dev, struct drm_file *file); -int i915_switch_context(struct intel_ring_buffer *ring, - struct drm_file *file, int to_id); +struct i915_hw_context * __must_check +i915_switch_context(struct intel_ring_buffer *ring, + struct drm_file *file, int to_id); int i915_gem_context_create_ioctl(struct drm_device *dev, void *data, struct drm_file *file); int i915_gem_context_destroy_ioctl(struct drm_device *dev, void *data, diff --git a/drivers/gpu/drm/i915/i915_gem.c b/drivers/gpu/drm/i915/i915_gem.c index 1417fc6..93b8e05 100644 --- a/drivers/gpu/drm/i915/i915_gem.c +++ b/drivers/gpu/drm/i915/i915_gem.c @@ -2517,9 +2517,11 @@ int i915_gpu_idle(struct drm_device *dev) /* Flush everything onto the inactive list. */ for_each_ring(ring, dev_priv, i) { - ret = i915_switch_context(ring, NULL, DEFAULT_CONTEXT_ID); - if (ret) - return ret; + struct i915_hw_context *ctx; + + ctx = i915_switch_context(ring, NULL, DEFAULT_CONTEXT_ID); + if (IS_ERR(ctx)) + return PTR_ERR(ctx); ret = intel_ring_idle(ring); if (ret) diff --git a/drivers/gpu/drm/i915/i915_gem_context.c b/drivers/gpu/drm/i915/i915_gem_context.c index 21177d9..258e5e0 100644 --- a/drivers/gpu/drm/i915/i915_gem_context.c +++ b/drivers/gpu/drm/i915/i915_gem_context.c @@ -428,41 +428,47 @@ static int do_switch(struct i915_hw_context *to) /** * i915_switch_context() - perform a GPU context switch. * @ring: ring for which we'll execute the context switch - * @file_priv: file_priv associated with the context, may be NULL - * @id: context id number - * @seqno: sequence number by which the new context will be switched to - * @flags: + * @file: file associated with the context, may be NULL + * @to_id: context id number + * @return: context that was switched to or ERR_PTR on error * * 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, * it will have a refoucnt > 1. This allows us to destroy the context abstract * object while letting the normal object tracking destroy the backing BO. */ -int i915_switch_context(struct intel_ring_buffer *ring, - struct drm_file *file, - int to_id) + +struct i915_hw_context * +i915_switch_context(struct intel_ring_buffer *ring, + struct drm_file *file, + int to_id) { struct drm_i915_private *dev_priv = ring->dev->dev_private; - struct i915_hw_context *to; + struct i915_hw_context *to = NULL; + int ret = 0; if (dev_priv->hw_contexts_disabled) - return 0; + return NULL; if (ring != &dev_priv->ring[RCS]) - return 0; + return NULL; if (to_id == DEFAULT_CONTEXT_ID) { to = ring->default_context; } else { if (file == NULL) - return -EINVAL; + return ERR_PTR(-EINVAL); to = i915_gem_context_get(file->driver_priv, to_id); if (to == NULL) - return -ENOENT; + return ERR_PTR(-ENOENT); } - return do_switch(to); + ret = do_switch(to); + if (ret) + return ERR_PTR(ret); + + return to; } int i915_gem_context_create_ioctl(struct drm_device *dev, void *data, diff --git a/drivers/gpu/drm/i915/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/i915_gem_execbuffer.c index ea963c3..ad7029e 100644 --- a/drivers/gpu/drm/i915/i915_gem_execbuffer.c +++ b/drivers/gpu/drm/i915/i915_gem_execbuffer.c @@ -838,6 +838,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 i915_hw_context *ctx; u32 ctx_id = i915_execbuffer2_get_context_id(*args); u32 exec_start, exec_len; u32 mask, flags; @@ -1020,9 +1021,11 @@ i915_gem_do_execbuffer(struct drm_device *dev, void *data, if (ret) goto err; - ret = i915_switch_context(ring, file, ctx_id); - if (ret) + ctx = i915_switch_context(ring, file, ctx_id); + if (IS_ERR(ctx)) { + ret = PTR_ERR(ctx); goto err; + } if (ring == &dev_priv->ring[RCS] && mode != dev_priv->relative_constants_mode) {