From patchwork Fri May 9 12:08:53 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: 4142351 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 88462C0ACC for ; Fri, 9 May 2014 12:14:54 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 927D12026C for ; Fri, 9 May 2014 12:14:53 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id 96C70201B4 for ; Fri, 9 May 2014 12:14:52 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 2FA4F6EF7A; Fri, 9 May 2014 05:14:52 -0700 (PDT) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by gabe.freedesktop.org (Postfix) with ESMTP id A2BC04A05A for ; Fri, 9 May 2014 05:14:50 -0700 (PDT) Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga101.fm.intel.com with ESMTP; 09 May 2014 05:14:50 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos; i="4.97,1018,1389772800"; d="scan'208"; a="529106966" Received: from omateolo-linux2.iwi.intel.com ([172.28.253.145]) by fmsmga001.fm.intel.com with ESMTP; 09 May 2014 05:14:49 -0700 From: oscar.mateo@intel.com To: intel-gfx@lists.freedesktop.org Date: Fri, 9 May 2014 13:08:53 +0100 Message-Id: <1399637360-4277-24-git-send-email-oscar.mateo@intel.com> X-Mailer: git-send-email 1.9.0 In-Reply-To: <1399637360-4277-1-git-send-email-oscar.mateo@intel.com> References: <1399637360-4277-1-git-send-email-oscar.mateo@intel.com> Subject: [Intel-gfx] [PATCH 23/50] drm/i915/bdw: Allocate ringbuffer for user-created LRCs 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.8 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: Oscar Mateo As we said earlier, logical ring contexts created by the user have their own ringbuffer: not only the backing pages, but the whole management struct. Since this is now ready, we use the context ringbuffer or the engine's default ringbuffer depending on whether LRCs are enabled or not. This patch replaces a similar patch in the early series called: "drm/i915/bdw: Prepare for user-created LR contexts" Signed-off-by: Oscar Mateo --- drivers/gpu/drm/i915/i915_gem_context.c | 5 +++- drivers/gpu/drm/i915/intel_lrc.c | 45 +++++++++++++++++++++++---------- drivers/gpu/drm/i915/intel_ringbuffer.c | 8 ++++-- 3 files changed, 42 insertions(+), 16 deletions(-) diff --git a/drivers/gpu/drm/i915/i915_gem_context.c b/drivers/gpu/drm/i915/i915_gem_context.c index 76314e3..e4e616d 100644 --- a/drivers/gpu/drm/i915/i915_gem_context.c +++ b/drivers/gpu/drm/i915/i915_gem_context.c @@ -200,8 +200,11 @@ void i915_gem_context_free(struct kref *ctx_ref) drm_gem_object_unreference(&ctx_obj->base); } - if (ringbuf) + if (ringbuf) { intel_destroy_ring_buffer(ringbuf); + if (ctx->file_priv) + kfree(ringbuf); + } } if (ppgtt) diff --git a/drivers/gpu/drm/i915/intel_lrc.c b/drivers/gpu/drm/i915/intel_lrc.c index 64d40e4..0f2c5cb 100644 --- a/drivers/gpu/drm/i915/intel_lrc.c +++ b/drivers/gpu/drm/i915/intel_lrc.c @@ -74,6 +74,7 @@ int gen8_create_lr_context(struct i915_hw_context *ctx, struct drm_device *dev = ring->dev; struct drm_i915_gem_object *ctx_obj; uint32_t context_size; + struct intel_ringbuffer *ringbuf; int ret; if (ctx->engine[ring->id].obj) @@ -95,25 +96,43 @@ int gen8_create_lr_context(struct i915_hw_context *ctx, return ret; } - if (!file_priv) { - ring->default_ringbuf.size = 32 * PAGE_SIZE; - - /* 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 = intel_allocate_ring_buffer(dev, &ring->default_ringbuf); - if (ret) { - DRM_DEBUG_DRIVER("Failed to allocate ringbuffer %s: %d\n", - ring->name, ret); + if (file_priv) { + ringbuf = kzalloc(sizeof(*ringbuf), GFP_KERNEL); + if (!ringbuf) { + ret = -ENOMEM; + DRM_DEBUG_DRIVER("Failed to allocate ringbuffer %s\n", + ring->name); i915_gem_object_ggtt_unpin(ctx_obj); drm_gem_object_unreference(&ctx_obj->base); return ret; } - ctx->engine[ring->id].ringbuf = &ring->default_ringbuf; + } else + ringbuf = &ring->default_ringbuf; + + ringbuf->size = 32 * PAGE_SIZE; + ringbuf->effective_size = ringbuf->size; + ringbuf->head = 0; + ringbuf->tail = 0; + ringbuf->space = ringbuf->size; + ringbuf->last_retired_head = -1; + + /* 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 = intel_allocate_ring_buffer(dev, ringbuf); + if (ret) { + DRM_DEBUG_DRIVER("Failed to allocate ringbuffer obj %s: %d\n", + ring->name, ret); + if (file_priv) + kfree(ringbuf); + i915_gem_object_ggtt_unpin(ctx_obj); + drm_gem_object_unreference(&ctx_obj->base); + return ret; } + ctx->engine[ring->id].ringbuf = ringbuf; ctx->engine[ring->id].obj = ctx_obj; return 0; diff --git a/drivers/gpu/drm/i915/intel_ringbuffer.c b/drivers/gpu/drm/i915/intel_ringbuffer.c index e7f61d9..8b0260d 100644 --- a/drivers/gpu/drm/i915/intel_ringbuffer.c +++ b/drivers/gpu/drm/i915/intel_ringbuffer.c @@ -1709,8 +1709,12 @@ static int __intel_ring_prepare(struct intel_engine *ring, struct intel_ringbuffer * intel_ringbuffer_get(struct intel_engine *ring, struct i915_hw_context *ctx) { - /* For the time being, the only ringbuffer is in the engine */ - return &ring->default_ringbuf; + struct drm_i915_private *dev_priv = to_i915(ring->dev); + + if (dev_priv->lrc_enabled) + return ctx->engine[ring->id].ringbuf; + else + return &ring->default_ringbuf; } struct intel_ringbuffer *