From patchwork Sat May 25 19:26:47 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ben Widawsky X-Patchwork-Id: 2614031 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 51F423FD4E for ; Sat, 25 May 2013 19:31:44 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 3BEE6E5D38 for ; Sat, 25 May 2013 12:31:44 -0700 (PDT) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from shiva.localdomain (unknown [209.20.75.48]) by gabe.freedesktop.org (Postfix) with ESMTP id 43645E5D1E for ; Sat, 25 May 2013 12:24:48 -0700 (PDT) Received: by shiva.localdomain (Postfix, from userid 1005) id DF65988081; Sat, 25 May 2013 19:24:47 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on shiva.chad-versace.us X-Spam-Level: X-Spam-Status: No, score=-2.9 required=5.0 tests=ALL_TRUSTED,BAYES_00, URIBL_BLOCKED autolearn=unavailable version=3.3.2 Received: from lundgren.kumite (c-24-21-100-90.hsd1.or.comcast.net [24.21.100.90]) by shiva.localdomain (Postfix) with ESMTPSA id 33B4788755; Sat, 25 May 2013 19:24:40 +0000 (UTC) From: Ben Widawsky To: Intel GFX Date: Sat, 25 May 2013 12:26:47 -0700 Message-Id: <1369510028-3343-14-git-send-email-ben@bwidawsk.net> X-Mailer: git-send-email 1.8.2.3 In-Reply-To: <1369510028-3343-1-git-send-email-ben@bwidawsk.net> References: <1369510028-3343-1-git-send-email-ben@bwidawsk.net> Cc: Ben Widawsky Subject: [Intel-gfx] [PATCH 13/34] drm/i915: destroy i915_gem_init_global_gtt 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 continuing to make default context/aliasing PPGTT behave like any other context/PPGTT pair this patch sets us up by moving the context/PPGTT init to a common location. The resulting code isn't a huge improvement, but that will change in the next patch (at least a bit). Signed-off-by: Ben Widawsky --- drivers/gpu/drm/i915/i915_drv.h | 4 +-- drivers/gpu/drm/i915/i915_gem.c | 35 +++++++++++++++++++++---- drivers/gpu/drm/i915/i915_gem_gtt.c | 51 +------------------------------------ 3 files changed, 33 insertions(+), 57 deletions(-) diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h index f1b59b1..63f58b8 100644 --- a/drivers/gpu/drm/i915/i915_drv.h +++ b/drivers/gpu/drm/i915/i915_drv.h @@ -1736,20 +1736,20 @@ int i915_gem_context_destroy_ioctl(struct drm_device *dev, void *data, struct drm_file *file); /* i915_gem_gtt.c */ +bool intel_enable_ppgtt(struct drm_device *dev); +int i915_gem_ppgtt_init(struct drm_device *dev, struct i915_hw_ppgtt *ppgtt); void i915_gem_cleanup_aliasing_ppgtt(struct drm_device *dev); void i915_ppgtt_bind_object(struct i915_hw_ppgtt *ppgtt, struct drm_i915_gem_object *obj, enum i915_cache_level cache_level); void i915_ppgtt_unbind_object(struct i915_hw_ppgtt *ppgtt, struct drm_i915_gem_object *obj); - void i915_gem_restore_gtt_mappings(struct drm_device *dev); int __must_check i915_gem_gtt_prepare_object(struct drm_i915_gem_object *obj); void i915_gem_gtt_bind_object(struct drm_i915_gem_object *obj, enum i915_cache_level cache_level); void i915_gem_gtt_unbind_object(struct drm_i915_gem_object *obj); void i915_gem_gtt_finish_object(struct drm_i915_gem_object *obj); -void i915_gem_init_global_gtt(struct drm_device *dev); void i915_gem_setup_global_gtt(struct drm_device *dev, unsigned long start, unsigned long mappable_end, unsigned long end, bool guard_page); diff --git a/drivers/gpu/drm/i915/i915_gem.c b/drivers/gpu/drm/i915/i915_gem.c index 674154f..670694c 100644 --- a/drivers/gpu/drm/i915/i915_gem.c +++ b/drivers/gpu/drm/i915/i915_gem.c @@ -4061,7 +4061,7 @@ i915_gem_init_hw(struct drm_device *dev) int i915_gem_init(struct drm_device *dev) { struct drm_i915_private *dev_priv = dev->dev_private; - int ret; + int ret = -ENODEV; mutex_lock(&dev->struct_mutex); @@ -4072,16 +4072,41 @@ int i915_gem_init(struct drm_device *dev) DRM_DEBUG_DRIVER("allow wake ack timed out\n"); } - i915_gem_init_global_gtt(dev); + if (intel_enable_ppgtt(dev) && HAS_ALIASING_PPGTT(dev)) { + struct i915_hw_ppgtt *ppgtt; + ppgtt = kzalloc(sizeof(*ppgtt), GFP_KERNEL); + if (!ppgtt) + goto ggtt_only; + + + i915_gem_setup_global_gtt(dev, 0, dev_priv->gtt.mappable_end, + dev_priv->gtt.total, false); + i915_gem_context_init(dev); + ret = i915_gem_ppgtt_init(dev, ppgtt); + if (ret) { + kfree(ppgtt); + drm_mm_takedown(&dev_priv->mm.gtt_space); + goto ggtt_only; + } - i915_gem_context_init(dev); + dev_priv->mm.aliasing_ppgtt = ppgtt; + } + +ggtt_only: + if (ret) { + DRM_DEBUG_DRIVER("Aliased PPGTT setup failed %d\n", ret); + i915_gem_setup_global_gtt(dev, 0, dev_priv->gtt.mappable_end, + dev_priv->gtt.total, true); + } ret = i915_gem_init_hw(dev); - mutex_unlock(&dev->struct_mutex); if (ret) { i915_gem_cleanup_aliasing_ppgtt(dev); - return ret; + i915_gem_context_fini(dev); } + mutex_unlock(&dev->struct_mutex); + if (ret) + return ret; /* Allow hardware batchbuffers unless told otherwise, but not for KMS. */ if (!drm_core_check_feature(dev, DRIVER_MODESET)) diff --git a/drivers/gpu/drm/i915/i915_gem_gtt.c b/drivers/gpu/drm/i915/i915_gem_gtt.c index 49467c1..2ca113a 100644 --- a/drivers/gpu/drm/i915/i915_gem_gtt.c +++ b/drivers/gpu/drm/i915/i915_gem_gtt.c @@ -365,10 +365,6 @@ int i915_gem_ppgtt_init(struct drm_device *dev, struct i915_hw_ppgtt *ppgtt) struct drm_i915_private *dev_priv = dev->dev_private; int ret; - ppgtt = kzalloc(sizeof(*ppgtt), GFP_KERNEL); - if (!ppgtt) - return -ENOMEM; - ppgtt->dev = dev; ppgtt->scratch_page_dma_addr = dev_priv->gtt.scratch_page_dma; @@ -377,11 +373,6 @@ int i915_gem_ppgtt_init(struct drm_device *dev, struct i915_hw_ppgtt *ppgtt) else BUG(); - if (ret) - kfree(ppgtt); - else - dev_priv->mm.aliasing_ppgtt = ppgtt; - return ret; } @@ -630,7 +621,7 @@ static void i915_gtt_color_adjust(struct drm_mm_node *node, } } -static bool intel_enable_ppgtt(struct drm_device *dev) +bool intel_enable_ppgtt(struct drm_device *dev) { if (i915_enable_ppgtt >= 0) return i915_enable_ppgtt; @@ -705,46 +696,6 @@ void i915_gem_setup_global_gtt(struct drm_device *dev, dev_priv->gtt.gtt_clear_range(dev, end / PAGE_SIZE - 1, 1); } -void i915_gem_init_global_gtt(struct drm_device *dev) -{ - struct drm_i915_private *dev_priv = dev->dev_private; - unsigned long gtt_size, mappable_size; - int ret = 0; - - gtt_size = dev_priv->gtt.total; - mappable_size = dev_priv->gtt.mappable_end; - - if (intel_enable_ppgtt(dev) && HAS_ALIASING_PPGTT(dev)) { - struct i915_hw_ppgtt *ppgtt; - - i915_gem_setup_global_gtt(dev, 0, mappable_size, gtt_size, - false); - - ppgtt = kzalloc(sizeof(*ppgtt), GFP_KERNEL); - if (!ppgtt) { - ret = -ENOMEM; - goto ggtt_only; - } - - ret = i915_gem_ppgtt_init(dev, ppgtt); - if (ret) - goto ggtt_only; - - return; - } - -/* XXX: We need to takedown the drm_mm and have this fall back because of the - * conditional use of the guard page. - * TODO: It's a bit hackish and could use cleanup. - */ -ggtt_only: - if (ret) { - DRM_ERROR("Aliased PPGTT setup failed %d\n", ret); - drm_mm_takedown(&dev_priv->mm.gtt_space); - } - i915_gem_setup_global_gtt(dev, 0, mappable_size, gtt_size, true); -} - static int setup_scratch_page(struct drm_device *dev) { struct drm_i915_private *dev_priv = dev->dev_private;