From patchwork Fri Jul 13 06:16:14 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ben Widawsky X-Patchwork-Id: 1193981 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 7171F40134 for ; Fri, 13 Jul 2012 06:59:50 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 45D3EA0FD0 for ; Thu, 12 Jul 2012 23:59:50 -0700 (PDT) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from cloud01.chad-versace.us (184-106-247-128.static.cloud-ips.com [184.106.247.128]) by gabe.freedesktop.org (Postfix) with ESMTP id 0A52CA0FD0 for ; Thu, 12 Jul 2012 23:18:24 -0700 (PDT) Received: from localhost (localhost [127.0.0.1]) by cloud01.chad-versace.us (Postfix) with ESMTP id C88BC1810C4; Fri, 13 Jul 2012 06:21:00 +0000 (UTC) X-Virus-Scanned: amavisd-new at static.cloud-ips.com X-Spam-Flag: NO X-Spam-Score: -2.9 X-Spam-Level: X-Spam-Status: No, score=-2.9 tagged_above=-100 required=3.5 tests=[ALL_TRUSTED=-1, BAYES_00=-1.9] autolearn=ham Received: from cloud01.chad-versace.us ([127.0.0.1]) by localhost (cloud01.static.cloud-ips.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id zFTFhNTaimal; Fri, 13 Jul 2012 06:20:55 +0000 (UTC) Received: from seagal.kumite (static-50-53-63-81.bvtn.or.frontiernet.net [50.53.63.81]) by cloud01.chad-versace.us (Postfix) with ESMTPSA id 57511181104; Fri, 13 Jul 2012 06:20:51 +0000 (UTC) From: Ben Widawsky To: intel-gfx@lists.freedesktop.org Date: Thu, 12 Jul 2012 23:16:14 -0700 Message-Id: <1342160176-1807-4-git-send-email-ben@bwidawsk.net> X-Mailer: git-send-email 1.7.11.1 In-Reply-To: <1342160176-1807-1-git-send-email-ben@bwidawsk.net> References: <1342160176-1807-1-git-send-email-ben@bwidawsk.net> Cc: Ben Widawsky Subject: [Intel-gfx] [PATCH 3/5] drm/i915: refactor ring object allocation 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 There is duplication here. Even more will be coming. Signed-off-by: Ben Widawsky --- drivers/gpu/drm/i915/intel_ringbuffer.c | 94 +++++++++++++++++++-------------- 1 file changed, 53 insertions(+), 41 deletions(-) diff --git a/drivers/gpu/drm/i915/intel_ringbuffer.c b/drivers/gpu/drm/i915/intel_ringbuffer.c index bf0195a..33d87ad 100644 --- a/drivers/gpu/drm/i915/intel_ringbuffer.c +++ b/drivers/gpu/drm/i915/intel_ringbuffer.c @@ -351,6 +351,43 @@ out: return ret; } +static void ring_destroy_object(struct drm_i915_gem_object *obj) +{ + kunmap(obj->pages[0]); + i915_gem_object_unpin(obj); + drm_gem_object_unreference(&obj->base); +} + +static struct drm_i915_gem_object *ring_alloc_object(struct drm_device *dev) +{ + struct drm_i915_gem_object *obj; + int ret; + + obj = i915_gem_alloc_object(dev, 4096); + if (obj == NULL) + return ERR_PTR(-ENOMEM); + + i915_gem_object_set_cache_level(obj, I915_CACHE_LLC); + + ret = i915_gem_object_pin(obj, 4096, true); + if (ret != 0) { + goto err_unref; + } + + obj->cpu_map = kmap(obj->pages[0]); + if (obj->cpu_map == NULL) { + ret = -ENOMEM; + goto err_unpin; + } + return obj; + +err_unpin: + i915_gem_object_unpin(obj); +err_unref: + drm_gem_object_unreference(&obj->base); + return ERR_PTR(ret); +} + static int init_pipe_control(struct intel_ring_buffer *ring) { @@ -365,32 +402,25 @@ init_pipe_control(struct intel_ring_buffer *ring) if (!pc) return -ENOMEM; - obj = i915_gem_alloc_object(ring->dev, 4096); - if (obj == NULL) { - DRM_ERROR("Failed to allocate seqno page\n"); - ret = -ENOMEM; + obj = ring_alloc_object(ring->dev); + if (IS_ERR(obj)) { + DRM_ERROR("Failed to allocate pipe control page\n"); + ret = PTR_ERR(obj); goto err; } - i915_gem_object_set_cache_level(obj, I915_CACHE_LLC); - - ret = i915_gem_object_pin(obj, 4096, true); - if (ret) - goto err_unref; pc->gtt_offset = obj->gtt_offset; - pc->cpu_page = kmap(obj->pages[0]); - if (pc->cpu_page == NULL) - goto err_unpin; + pc->cpu_page = obj->cpu_map; + if (pc->cpu_page == NULL) { + ret = -ENOMEM; + goto err; + } pc->obj = obj; ring->private = pc; return 0; -err_unpin: - i915_gem_object_unpin(obj); -err_unref: - drm_gem_object_unreference(&obj->base); err: kfree(pc); return ret; @@ -406,9 +436,7 @@ cleanup_pipe_control(struct intel_ring_buffer *ring) return; obj = pc->obj; - kunmap(obj->pages[0]); - i915_gem_object_unpin(obj); - drm_gem_object_unreference(&obj->base); + ring_destroy_object(obj); kfree(pc); ring->private = NULL; @@ -943,9 +971,7 @@ static void cleanup_status_page(struct intel_ring_buffer *ring) if (obj == NULL) return; - kunmap(obj->pages[0]); - i915_gem_object_unpin(obj); - drm_gem_object_unreference(&obj->base); + ring_destroy_object(obj); ring->status_page.obj = NULL; } @@ -955,26 +981,16 @@ static int init_status_page(struct intel_ring_buffer *ring) struct drm_i915_gem_object *obj; int ret; - obj = i915_gem_alloc_object(dev, 4096); - if (obj == NULL) { + obj = ring_alloc_object(dev); + if (IS_ERR(obj)) { DRM_ERROR("Failed to allocate status page\n"); - ret = -ENOMEM; + ret = PTR_ERR(obj); goto err; } - i915_gem_object_set_cache_level(obj, I915_CACHE_LLC); - - ret = i915_gem_object_pin(obj, 4096, true); - if (ret != 0) { - goto err_unref; - } - ring->status_page.gfx_addr = obj->gtt_offset; - ring->status_page.page_addr = kmap(obj->pages[0]); - if (ring->status_page.page_addr == NULL) { - ret = -ENOMEM; - goto err_unpin; - } + ring->status_page.page_addr = obj->cpu_map; + ring->status_page.obj = obj; memset(ring->status_page.page_addr, 0, PAGE_SIZE); @@ -984,10 +1000,6 @@ static int init_status_page(struct intel_ring_buffer *ring) return 0; -err_unpin: - i915_gem_object_unpin(obj); -err_unref: - drm_gem_object_unreference(&obj->base); err: return ret; }