From patchwork Thu Mar 27 17:59:47 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: oscar.mateo@intel.com X-Patchwork-Id: 3898621 Return-Path: X-Original-To: patchwork-intel-gfx@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id E7DF5BF549 for ; Thu, 27 Mar 2014 17:09:36 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id F1DAD20237 for ; Thu, 27 Mar 2014 17:09:35 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id F29D32024D for ; Thu, 27 Mar 2014 17:09:34 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 7AE716E9EF; Thu, 27 Mar 2014 10:09:34 -0700 (PDT) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by gabe.freedesktop.org (Postfix) with ESMTP id 9DE5B6E9EF for ; Thu, 27 Mar 2014 10:09:31 -0700 (PDT) Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga102.jf.intel.com with ESMTP; 27 Mar 2014 10:02:56 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="4.97,743,1389772800"; d="scan'208";a="501086565" Received: from omateolo-linux2.iwi.intel.com ([172.28.253.148]) by fmsmga001.fm.intel.com with ESMTP; 27 Mar 2014 10:06:01 -0700 From: oscar.mateo@intel.com To: intel-gfx@lists.freedesktop.org Date: Thu, 27 Mar 2014 17:59:47 +0000 Message-Id: <1395943218-7708-19-git-send-email-oscar.mateo@intel.com> X-Mailer: git-send-email 1.9.0 In-Reply-To: <1395943218-7708-1-git-send-email-oscar.mateo@intel.com> References: <1395943218-7708-1-git-send-email-oscar.mateo@intel.com> Cc: Ben Widawsky , Ben Widawsky Subject: [Intel-gfx] [PATCH 18/49] drm/i915/bdw: Allocate ringbuffer for LR contexts X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" X-Spam-Status: No, score=-4.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Ben Widawsky With our setup in previous patches, we've allocated one default context per ring. Now, each of those contexts holds a pointer to the default ringbuffers and makes its own allocation of the backing objects. To reiterate the TODO in the patch: the ringbuffer objects are in the CPU mappable region. This will likely need to change at some point. Signed-off-by: Ben Widawsky v2: Place a ringbuffer pointer inside the context that, in the global default context, just points to the engine's default ringbuffer. Update the ringbuffer backing object early instead of waiting for the alloc & destroy ringbuffer calls during ring initialization. Signed-off-by: Oscar Mateo --- drivers/gpu/drm/i915/i915_drv.h | 4 ++ drivers/gpu/drm/i915/i915_lrc.c | 65 +++++++++++++++++++++++++++++++-- drivers/gpu/drm/i915/intel_ringbuffer.c | 8 ++++ 3 files changed, 73 insertions(+), 4 deletions(-) diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h index ff6a33c..3a36e28 100644 --- a/drivers/gpu/drm/i915/i915_drv.h +++ b/drivers/gpu/drm/i915/i915_drv.h @@ -597,6 +597,7 @@ struct i915_hw_context { struct drm_i915_file_private *file_priv; struct intel_engine *last_ring; struct drm_i915_gem_object *obj; + struct intel_ringbuffer *ringbuf; struct i915_ctx_hang_stats hang_stats; struct i915_address_space *vm; @@ -2317,6 +2318,9 @@ int i915_gem_context_destroy_ioctl(struct drm_device *dev, void *data, /* i915_lrc.c */ int gen8_gem_context_init(struct drm_device *dev); void gen8_gem_context_fini(struct drm_device *dev); +struct i915_hw_context *gen8_gem_create_context(struct drm_device *dev, + struct intel_engine *ring, + struct drm_i915_file_private *file_priv, bool create_vm); /* i915_gem_evict.c */ int __must_check i915_gem_evict_something(struct drm_device *dev, diff --git a/drivers/gpu/drm/i915/i915_lrc.c b/drivers/gpu/drm/i915/i915_lrc.c index 10e6dbc..40dfa95 100644 --- a/drivers/gpu/drm/i915/i915_lrc.c +++ b/drivers/gpu/drm/i915/i915_lrc.c @@ -43,6 +43,56 @@ #define GEN8_LR_CONTEXT_SIZE (21 * PAGE_SIZE) +struct i915_hw_context * +gen8_gem_create_context(struct drm_device *dev, + struct intel_engine *ring, + struct drm_i915_file_private *file_priv, + bool create_vm) +{ + struct i915_hw_context *ctx = NULL; + struct drm_i915_gem_object *ring_obj = NULL; + int ret; + + ctx = i915_gem_create_context(dev, file_priv, create_vm); + if (IS_ERR_OR_NULL(ctx)) + return ctx; + + ring_obj = i915_gem_alloc_object(dev, 32 * PAGE_SIZE); + if (!ring_obj) { + i915_gem_object_ggtt_unpin(ctx->obj); + i915_gem_context_unreference(ctx); + return ERR_PTR(-ENOMEM); + } + + /* TODO: For now we put this in the mappable region so that we can reuse + * the existing ringbuffer code which ioremaps it. When we start + * creating many contexts, this will no longer work and we must switch + * to a kmapish interface. + */ + ret = i915_gem_obj_ggtt_pin(ring_obj, PAGE_SIZE, PIN_MAPPABLE); + if (ret) { + drm_gem_object_unreference(&ring_obj->base); + i915_gem_object_ggtt_unpin(ctx->obj); + i915_gem_context_unreference(ctx); + return ERR_PTR(ret); + } + + /* Failure at this point is almost impossible */ + ret = i915_gem_object_set_to_gtt_domain(ring_obj, true); + if (ret) { + i915_gem_object_ggtt_unpin(ring_obj); + drm_gem_object_unreference(&ring_obj->base); + i915_gem_object_ggtt_unpin(ctx->obj); + i915_gem_context_unreference(ctx); + return ERR_PTR(ret); + } + + ctx->ringbuf = &ring->default_ringbuf; + ctx->ringbuf->obj = ring_obj; + + return ctx; +} + void gen8_gem_context_fini(struct drm_device *dev) { struct drm_i915_private *dev_priv = dev->dev_private; @@ -50,9 +100,16 @@ void gen8_gem_context_fini(struct drm_device *dev) int unused; for_each_ring(ring, dev_priv, unused) { - if (ring->default_context) { - i915_gem_object_ggtt_unpin(ring->default_context->obj); - i915_gem_context_unreference(ring->default_context); + struct i915_hw_context *ctx = ring->default_context; + if (ctx) { + struct drm_i915_gem_object *ring_obj = ctx->ringbuf->obj; + if (ring_obj) { + i915_gem_object_ggtt_unpin(ring_obj); + drm_gem_object_unreference(&ring_obj->base); + ctx->ringbuf->obj = NULL; + } + i915_gem_object_ggtt_unpin(ctx->obj); + i915_gem_context_unreference(ctx); ring->default_context = NULL; } } @@ -69,7 +126,7 @@ int gen8_gem_context_init(struct drm_device *dev) dev_priv->hw_context_size = round_up(GEN8_LR_CONTEXT_SIZE, 4096); for_each_ring(ring, dev_priv, ring_id) { - ring->default_context = i915_gem_create_context(dev, + ring->default_context = gen8_gem_create_context(dev, ring, NULL, (ring_id == RCS)); if (IS_ERR_OR_NULL(ring->default_context)) { ret = PTR_ERR(ring->default_context); diff --git a/drivers/gpu/drm/i915/intel_ringbuffer.c b/drivers/gpu/drm/i915/intel_ringbuffer.c index 240e86a..a552c48 100644 --- a/drivers/gpu/drm/i915/intel_ringbuffer.c +++ b/drivers/gpu/drm/i915/intel_ringbuffer.c @@ -1380,8 +1380,12 @@ static int init_phys_status_page(struct intel_engine *ring) static void destroy_ring_buffer(struct intel_engine *ring) { + struct drm_i915_private *dev_priv = ring->dev->dev_private; struct intel_ringbuffer *ringbuf = __get_ringbuf(ring); + if (dev_priv->lrc_enabled) + return; + i915_gem_object_ggtt_unpin(ringbuf->obj); drm_gem_object_unreference(&ringbuf->obj->base); ringbuf->obj = NULL; @@ -1390,10 +1394,14 @@ static void destroy_ring_buffer(struct intel_engine *ring) static int alloc_ring_buffer(struct intel_engine *ring) { struct drm_device *dev = ring->dev; + struct drm_i915_private *dev_priv = dev->dev_private; struct drm_i915_gem_object *obj = NULL; struct intel_ringbuffer *ringbuf = __get_ringbuf(ring); int ret; + if (dev_priv->lrc_enabled) + return 0; + if (!HAS_LLC(dev)) obj = i915_gem_object_create_stolen(dev, ringbuf->size); if (obj == NULL)