From patchwork Thu Mar 27 17:59:56 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: 3898511 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 9B4C7BF540 for ; Thu, 27 Mar 2014 17:08:22 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id BCECA20240 for ; Thu, 27 Mar 2014 17:08:21 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id BD5FF20237 for ; Thu, 27 Mar 2014 17:08:20 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 6F5216E9E2; Thu, 27 Mar 2014 10:08:20 -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 88FBE6E9E1 for ; Thu, 27 Mar 2014 10:08:18 -0700 (PDT) Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga102.fm.intel.com with ESMTP; 27 Mar 2014 10:07:45 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="4.97,743,1389772800"; d="scan'208";a="501086789" Received: from omateolo-linux2.iwi.intel.com ([172.28.253.148]) by fmsmga001.fm.intel.com with ESMTP; 27 Mar 2014 10:06:15 -0700 From: oscar.mateo@intel.com To: intel-gfx@lists.freedesktop.org Date: Thu, 27 Mar 2014 17:59:56 +0000 Message-Id: <1395943218-7708-28-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> Subject: [Intel-gfx] [PATCH 27/49] drm/i915/bdw: Prepare for user-created 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: Oscar Mateo Now that our global default contexts are correctly created and we have finished the refactoring, it's time to allow other kind of contexts. 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. Signed-off-by: Oscar Mateo --- drivers/gpu/drm/i915/i915_drv.h | 1 + drivers/gpu/drm/i915/i915_lrc.c | 69 ++++++++++++++++++++++++++++++++++++----- 2 files changed, 63 insertions(+), 7 deletions(-) diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h index c0f0c3d..91b0886 100644 --- a/drivers/gpu/drm/i915/i915_drv.h +++ b/drivers/gpu/drm/i915/i915_drv.h @@ -2322,6 +2322,7 @@ 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); +void gen8_gem_context_free(struct i915_hw_context *ctx); /* 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 a726b26..d5afb0d 100644 --- a/drivers/gpu/drm/i915/i915_lrc.c +++ b/drivers/gpu/drm/i915/i915_lrc.c @@ -75,15 +75,31 @@ #define CTX_R_PWR_CLK_STATE 0x42 #define CTX_GPGPU_CSR_BASE_ADDRESS 0x44 +void gen8_gem_context_free(struct i915_hw_context *ctx) +{ + /* Global default contexts ringbuffers are take care of + * in the fini cleanup code */ + if (ctx->file_priv) { + iounmap(ctx->ringbuf->virtual_start); + i915_gem_object_ggtt_unpin(ctx->ringbuf->obj); + drm_gem_object_unreference(&ctx->ringbuf->obj->base); + ctx->ringbuf->obj = NULL; + kfree(ctx->ringbuf); + ctx->ringbuf = NULL; + } +} + 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 drm_i915_private *dev_priv = dev->dev_private; struct i915_hw_context *ctx = NULL; struct drm_i915_gem_object *ring_obj = NULL; struct i915_hw_ppgtt *ppgtt = NULL; + struct intel_ringbuffer *ringbuf = NULL; struct page *page; uint32_t *reg_state; int ret; @@ -94,7 +110,8 @@ gen8_gem_create_context(struct drm_device *dev, ring_obj = i915_gem_alloc_object(dev, 32 * PAGE_SIZE); if (!ring_obj) { - i915_gem_object_ggtt_unpin(ctx->obj); + if (!file_priv) + i915_gem_object_ggtt_unpin(ctx->obj); i915_gem_context_unreference(ctx); return ERR_PTR(-ENOMEM); } @@ -107,7 +124,8 @@ gen8_gem_create_context(struct drm_device *dev, 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); + if (!file_priv) + i915_gem_object_ggtt_unpin(ctx->obj); i915_gem_context_unreference(ctx); return ERR_PTR(ret); } @@ -117,18 +135,44 @@ gen8_gem_create_context(struct drm_device *dev, if (ret) goto destroy_ring_obj; - ctx->ringbuf = &ring->default_ringbuf; + if (file_priv) { + ringbuf = kzalloc(sizeof(struct intel_ringbuffer), GFP_KERNEL); + if (!ringbuf) { + DRM_ERROR("Failed to allocate ringbuffer\n"); + ret = -ENOMEM; + goto destroy_ring_obj; + } + + 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; + ringbuf->virtual_start = ioremap_wc(dev_priv->gtt.mappable_base + + i915_gem_obj_ggtt_offset(ring_obj), + ringbuf->size); + if (ringbuf->virtual_start == NULL) { + DRM_ERROR("Failed to map ringbuffer\n"); + ret = -EINVAL; + goto destroy_ringbuf; + } + + ctx->ringbuf = ringbuf; + } else { + ctx->ringbuf = &ring->default_ringbuf; + } ctx->ringbuf->obj = ring_obj; ppgtt = ctx_to_ppgtt(ctx); ret = i915_gem_object_set_to_cpu_domain(ctx->obj, true); if (ret) - goto destroy_ring_obj; + goto unmap_ringbuf; ret = i915_gem_object_get_pages(ctx->obj); if (ret) - goto destroy_ring_obj; + goto unmap_ringbuf; i915_gem_object_pin_pages(ctx->obj); @@ -213,12 +257,23 @@ gen8_gem_create_context(struct drm_device *dev, return ctx; +unmap_ringbuf: + if (ringbuf) + iounmap(ringbuf->virtual_start); + +destroy_ringbuf: + if (ringbuf) { + ringbuf->obj = NULL; + kfree(ringbuf); + } + ctx->ringbuf = NULL; + destroy_ring_obj: i915_gem_object_ggtt_unpin(ring_obj); drm_gem_object_unreference(&ring_obj->base); ctx->ringbuf->obj = NULL; - ctx->ringbuf = NULL; - i915_gem_object_ggtt_unpin(ctx->obj); + if (!file_priv) + i915_gem_object_ggtt_unpin(ctx->obj); i915_gem_context_unreference(ctx); return ERR_PTR(ret);