From patchwork Thu Mar 27 17:59:59 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: 3898721 Return-Path: X-Original-To: patchwork-intel-gfx@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 3AC8F9FACF for ; Thu, 27 Mar 2014 17:09:52 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 421512025B for ; Thu, 27 Mar 2014 17:09:51 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id 8BCA32024D for ; Thu, 27 Mar 2014 17:09:49 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 217906EA08; Thu, 27 Mar 2014 10:09:49 -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 8EB866EA01 for ; Thu, 27 Mar 2014 10:09:42 -0700 (PDT) Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga102.jf.intel.com with ESMTP; 27 Mar 2014 10:03:11 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="4.97,743,1389772800"; d="scan'208";a="501086852" Received: from omateolo-linux2.iwi.intel.com ([172.28.253.148]) by fmsmga001.fm.intel.com with ESMTP; 27 Mar 2014 10:06:18 -0700 From: oscar.mateo@intel.com To: intel-gfx@lists.freedesktop.org Date: Thu, 27 Mar 2014 17:59:59 +0000 Message-Id: <1395943218-7708-31-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 30/49] drm/i915/bdw: Extract LR context object populating 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 As a separate function, we can decide wether we want a context with real information about which engine it uses, or a "blank" context for which to make a deferred decision. Signed-off-by: Oscar Mateo --- drivers/gpu/drm/i915/i915_lrc.c | 175 ++++++++++++++++++++++------------------ 1 file changed, 95 insertions(+), 80 deletions(-) diff --git a/drivers/gpu/drm/i915/i915_lrc.c b/drivers/gpu/drm/i915/i915_lrc.c index 74ab558..124e5f2 100644 --- a/drivers/gpu/drm/i915/i915_lrc.c +++ b/drivers/gpu/drm/i915/i915_lrc.c @@ -92,97 +92,24 @@ void gen8_gem_context_free(struct i915_hw_context *ctx) } } -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) +static int +intel_populate_lrc(struct i915_hw_context *ctx, + struct intel_engine *ring) { - 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; + struct i915_hw_ppgtt *ppgtt = NULL; int ret; - ctx = i915_gem_create_context(dev, file_priv, create_vm); - if (IS_ERR_OR_NULL(ctx)) - return ctx; - - if (file_priv) { - ret = i915_gem_obj_ggtt_pin(ctx->obj, GEN8_CONTEXT_ALIGN, 0); - if (ret) { - DRM_DEBUG_DRIVER("Couldn't pin %d\n", ret); - i915_gem_context_unreference(ctx); - return ERR_PTR(ret); - } - } - - 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) - goto destroy_ring_obj; - - 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 unmap_ringbuf; + return ret; ret = i915_gem_object_get_pages(ctx->obj); if (ret) - goto unmap_ringbuf; + return ret; i915_gem_object_pin_pages(ctx->obj); @@ -204,7 +131,7 @@ gen8_gem_create_context(struct drm_device *dev, reg_state[CTX_RING_TAIL] = RING_TAIL(ring->mmio_base); reg_state[CTX_RING_TAIL+1] = 0; reg_state[CTX_RING_BUFFER_START] = RING_START(ring->mmio_base); - reg_state[CTX_RING_BUFFER_START+1] = i915_gem_obj_ggtt_offset(ring_obj); + reg_state[CTX_RING_BUFFER_START+1] = i915_gem_obj_ggtt_offset(ctx->ringbuf->obj); reg_state[CTX_RING_BUFFER_CONTROL] = RING_CTL(ring->mmio_base); reg_state[CTX_RING_BUFFER_CONTROL+1] = (31 * PAGE_SIZE) | RING_VALID; reg_state[CTX_BB_HEAD_U] = ring->mmio_base + 0x168; @@ -265,6 +192,94 @@ gen8_gem_create_context(struct drm_device *dev, set_page_dirty(page); i915_gem_object_unpin_pages(ctx->obj); + return 0; +} + +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 intel_ringbuffer *ringbuf = NULL; + int ret; + + ctx = i915_gem_create_context(dev, file_priv, create_vm); + if (IS_ERR_OR_NULL(ctx)) + return ctx; + + if (file_priv) { + ret = i915_gem_obj_ggtt_pin(ctx->obj, GEN8_CONTEXT_ALIGN, 0); + if (ret) { + DRM_DEBUG_DRIVER("Couldn't pin %d\n", ret); + i915_gem_context_unreference(ctx); + return ERR_PTR(ret); + } + } + + 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) + goto destroy_ring_obj; + + 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; + + if (ring) { + ret = intel_populate_lrc(ctx, ring); + if (ret) + goto unmap_ringbuf; + } + return ctx; unmap_ringbuf: