From patchwork Fri Aug 2 20:41:11 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Kumar Valsan, Prathap" X-Patchwork-Id: 11074109 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 3E57F746 for ; Fri, 2 Aug 2019 20:25:13 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 302292875E for ; Fri, 2 Aug 2019 20:25:13 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 243BF288B2; Fri, 2 Aug 2019 20:25:13 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id AC35E2875E for ; Fri, 2 Aug 2019 20:25:12 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id DCD806E422; Fri, 2 Aug 2019 20:25:11 +0000 (UTC) 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 ESMTPS id A865B6E422 for ; Fri, 2 Aug 2019 20:25:10 +0000 (UTC) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 02 Aug 2019 13:25:10 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.64,339,1559545200"; d="scan'208";a="167338436" Received: from pkumarva-server.ra.intel.com ([10.23.184.130]) by orsmga008.jf.intel.com with ESMTP; 02 Aug 2019 13:25:10 -0700 From: Prathap Kumar Valsan To: intel-gfx@lists.freedesktop.org Date: Fri, 2 Aug 2019 16:41:11 -0400 Message-Id: <20190802204111.7344-1-prathap.kumar.valsan@intel.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Subject: [Intel-gfx] [PATCH] drm/i915: Separate pinning of pages from i915_vma_insert() X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" X-Virus-Scanned: ClamAV using ClamSMTP Currently i915_vma_insert() is responsible for allocating drm mm node and also allocating or gathering physical pages. Move the latter to a separate function for better readability. Signed-off-by: Prathap Kumar Valsan --- drivers/gpu/drm/i915/i915_vma.c | 76 +++++++++++++++++++-------------- drivers/gpu/drm/i915/i915_vma.h | 1 + 2 files changed, 45 insertions(+), 32 deletions(-) diff --git a/drivers/gpu/drm/i915/i915_vma.c b/drivers/gpu/drm/i915/i915_vma.c index 7734d6218ce7..8da88a474594 100644 --- a/drivers/gpu/drm/i915/i915_vma.c +++ b/drivers/gpu/drm/i915/i915_vma.c @@ -584,35 +584,22 @@ i915_vma_insert(struct i915_vma *vma, u64 size, u64 alignment, u64 flags) return -ENOSPC; } - if (vma->obj) { - ret = i915_gem_object_pin_pages(vma->obj); - if (ret) - return ret; - + if (vma->obj) cache_level = vma->obj->cache_level; - } else { + else cache_level = 0; - } - - GEM_BUG_ON(vma->pages); - - ret = vma->ops->set_pages(vma); - if (ret) - goto err_unpin; if (flags & PIN_OFFSET_FIXED) { u64 offset = flags & PIN_OFFSET_MASK; if (!IS_ALIGNED(offset, alignment) || - range_overflows(offset, size, end)) { - ret = -EINVAL; - goto err_clear; - } + range_overflows(offset, size, end)) + return -EINVAL; ret = i915_gem_gtt_reserve(vma->vm, &vma->node, size, offset, cache_level, flags); if (ret) - goto err_clear; + return ret; } else { /* * We only support huge gtt pages through the 48b PPGTT, @@ -651,7 +638,7 @@ i915_vma_insert(struct i915_vma *vma, u64 size, u64 alignment, u64 flags) size, alignment, cache_level, start, end, flags); if (ret) - goto err_clear; + return ret; GEM_BUG_ON(vma->node.start < start); GEM_BUG_ON(vma->node.start + vma->node.size > end); @@ -663,28 +650,24 @@ i915_vma_insert(struct i915_vma *vma, u64 size, u64 alignment, u64 flags) list_move_tail(&vma->vm_link, &vma->vm->bound_list); mutex_unlock(&vma->vm->mutex); - if (vma->obj) { + if (vma->obj) atomic_inc(&vma->obj->bind_count); - assert_bind_count(vma->obj); - } return 0; - -err_clear: - vma->ops->clear_pages(vma); -err_unpin: - if (vma->obj) - i915_gem_object_unpin_pages(vma->obj); - return ret; } static void i915_vma_remove(struct i915_vma *vma) { + bool vma_has_pages = false; + GEM_BUG_ON(!drm_mm_node_allocated(&vma->node)); GEM_BUG_ON(vma->flags & (I915_VMA_GLOBAL_BIND | I915_VMA_LOCAL_BIND)); - vma->ops->clear_pages(vma); + if (vma->pages) { + vma_has_pages = true; + vma->ops->clear_pages(vma); + } mutex_lock(&vma->vm->mutex); drm_mm_remove_node(&vma->node); @@ -705,11 +688,37 @@ i915_vma_remove(struct i915_vma *vma) * vma, we can drop its hold on the backing storage and allow * it to be reaped by the shrinker. */ - i915_gem_object_unpin_pages(obj); + if (vma_has_pages) + i915_gem_object_unpin_pages(obj); assert_bind_count(obj); } } +int i915_vma_set_pages(struct i915_vma *vma) +{ + int ret; + + if (vma->obj) { + ret = i915_gem_object_pin_pages(vma->obj); + if (ret) + return ret; + } + + GEM_BUG_ON(vma->pages); + + ret = vma->ops->set_pages(vma); + if (ret) { + if (vma->obj) + i915_gem_object_unpin_pages(vma->obj); + return ret; + } + + if (vma->obj) + assert_bind_count(vma->obj); + + return ret; +} + int __i915_vma_do_pin(struct i915_vma *vma, u64 size, u64 alignment, u64 flags) { @@ -729,6 +738,10 @@ int __i915_vma_do_pin(struct i915_vma *vma, ret = i915_vma_insert(vma, size, alignment, flags); if (ret) goto err_unpin; + ret = i915_vma_set_pages(vma); + if (ret) + goto err_remove; + } GEM_BUG_ON(!drm_mm_node_allocated(&vma->node)); @@ -743,7 +756,6 @@ int __i915_vma_do_pin(struct i915_vma *vma, GEM_BUG_ON(i915_vma_misplaced(vma, size, alignment, flags)); return 0; - err_remove: if ((bound & I915_VMA_BIND_MASK) == 0) { i915_vma_remove(vma); diff --git a/drivers/gpu/drm/i915/i915_vma.h b/drivers/gpu/drm/i915/i915_vma.h index 4b769db649bf..ad374166f3b8 100644 --- a/drivers/gpu/drm/i915/i915_vma.h +++ b/drivers/gpu/drm/i915/i915_vma.h @@ -288,6 +288,7 @@ i915_vma_compare(struct i915_vma *vma, int i915_vma_bind(struct i915_vma *vma, enum i915_cache_level cache_level, u32 flags); +int i915_vma_set_pages(struct i915_vma *vma); bool i915_gem_valid_gtt_space(struct i915_vma *vma, unsigned long cache_level); bool i915_vma_misplaced(const struct i915_vma *vma, u64 size, u64 alignment, u64 flags);