From patchwork Sat May 10 03:59:50 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ben Widawsky X-Patchwork-Id: 4146521 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 AC2A6BFF02 for ; Sat, 10 May 2014 04:03:18 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id BC291201E7 for ; Sat, 10 May 2014 04:03:17 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id D5D32201DC for ; Sat, 10 May 2014 04:03:16 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 3CFBB6F0B1; Fri, 9 May 2014 21:03:16 -0700 (PDT) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mail.bwidawsk.net (bwidawsk.net [166.78.191.112]) by gabe.freedesktop.org (Postfix) with ESMTP id 0BC556F0B0 for ; Fri, 9 May 2014 21:03:15 -0700 (PDT) Received: by mail.bwidawsk.net (Postfix, from userid 5001) id EE750580A0; Fri, 9 May 2014 21:03:13 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Spam-Level: X-Spam-Status: No, score=-4.8 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 Received: from ironside.intel.com (c-24-21-100-90.hsd1.or.comcast.net [24.21.100.90]) by mail.bwidawsk.net (Postfix) with ESMTPSA id 6C3455809E; Fri, 9 May 2014 21:00:34 -0700 (PDT) From: Ben Widawsky To: Intel GFX Date: Fri, 9 May 2014 20:59:50 -0700 Message-Id: <1399694391-3935-56-git-send-email-benjamin.widawsky@intel.com> X-Mailer: git-send-email 1.9.2 In-Reply-To: <1399694391-3935-1-git-send-email-benjamin.widawsky@intel.com> References: <1399694391-3935-1-git-send-email-benjamin.widawsky@intel.com> Cc: Ben Widawsky , Ben Widawsky Subject: [Intel-gfx] [PATCH 55/56] drm/i915: Track userptr VMAs 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-Virus-Scanned: ClamAV using ClamSMTP This HACK allows users to reuse the userptr ioctl in order to pre-reserve the VMA at a specific location. The vma will follow all the same paths as other userptr objects - only the drm_mm node is actually allocated. Again, this patch is a big HACK to get some other people currently using userptr enabled. Signed-off-by: Ben Widawsky --- drivers/gpu/drm/i915/i915_drv.h | 1 + drivers/gpu/drm/i915/i915_gem.c | 22 +++++++++++++++++++--- drivers/gpu/drm/i915/i915_gem_execbuffer.c | 3 +++ drivers/gpu/drm/i915/i915_gem_gtt.h | 4 ++++ 4 files changed, 27 insertions(+), 3 deletions(-) diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h index 60513e7..71e39ff 100644 --- a/drivers/gpu/drm/i915/i915_drv.h +++ b/drivers/gpu/drm/i915/i915_drv.h @@ -2166,6 +2166,7 @@ void i915_gem_vma_destroy(struct i915_vma *vma); #define PIN_GLOBAL 0x4 #define PIN_ALIASING 0x8 #define PIN_GLOBAL_ALIASED (PIN_ALIASING | PIN_GLOBAL) +#define PIN_BOUND 0x10 int __must_check i915_gem_object_pin(struct drm_i915_gem_object *obj, struct i915_address_space *vm, uint32_t alignment, diff --git a/drivers/gpu/drm/i915/i915_gem.c b/drivers/gpu/drm/i915/i915_gem.c index 287d48e..ff75971 100644 --- a/drivers/gpu/drm/i915/i915_gem.c +++ b/drivers/gpu/drm/i915/i915_gem.c @@ -3279,7 +3279,13 @@ i915_gem_object_bind_to_vm(struct drm_i915_gem_object *obj, if (IS_ERR(vma)) goto err_unpin; + if (flags & PIN_BOUND) { + WARN_ON(!vma->node.allocated && !vma->obj->userptr.ptr); + goto skip_search; + } + search_free: + WARN_ON(vma->node.allocated); ret = drm_mm_insert_node_in_range_generic(&vm->mm, &vma->node, size, alignment, obj->cache_level, 0, gtt_max, @@ -3293,6 +3299,7 @@ search_free: goto err_free_vma; } +skip_search: if (WARN_ON(!i915_gem_valid_gtt_space(dev, &vma->node, obj->cache_level))) { ret = -EINVAL; @@ -3329,10 +3336,13 @@ search_free: i915_gem_vma_bind(vma, obj->cache_level, vma_bind_flags); i915_gem_verify_gtt(dev); + if (flags & PIN_BOUND) + vma->uptr_bind=1; return vma; err_remove_node: - drm_mm_remove_node(&vma->node); + if ((flags & PIN_BOUND) == 0) + drm_mm_remove_node(&vma->node); err_free_vma: i915_gem_vma_destroy(vma); vma = ERR_PTR(ret); @@ -3875,6 +3885,11 @@ i915_gem_object_pin(struct drm_i915_gem_object *obj, if (WARN_ON(flags & (PIN_GLOBAL | PIN_MAPPABLE) && !i915_is_ggtt(vm))) return -EINVAL; + if (flags & PIN_BOUND) { + if (WARN_ON(flags & ~PIN_BOUND)) + return -EINVAL; + } + vma = i915_gem_obj_to_vma(obj, vm); if (vma) { if (WARN_ON(vma->pin_count == DRM_I915_GEM_OBJECT_MAX_PIN_COUNT)) @@ -3898,7 +3913,8 @@ i915_gem_object_pin(struct drm_i915_gem_object *obj, } } - if (vma == NULL || !drm_mm_node_allocated(&vma->node)) { + if (vma == NULL || !drm_mm_node_allocated(&vma->node) || + ((flags & PIN_BOUND) && !vma->uptr_bind)) { vma = i915_gem_object_bind_to_vm(obj, vm, alignment, flags); if (IS_ERR(vma)) return PTR_ERR(vma); @@ -4265,7 +4281,7 @@ struct i915_vma *i915_gem_obj_to_vma(struct drm_i915_gem_object *obj, void i915_gem_vma_destroy(struct i915_vma *vma) { - WARN_ON(vma->node.allocated); + WARN_ON(vma->node.allocated && !vma->uptr); /* Keep the vma as a placeholder in the execbuffer reservation lists */ if (!list_empty(&vma->exec_list)) diff --git a/drivers/gpu/drm/i915/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/i915_gem_execbuffer.c index 08fde7d..596e51e 100644 --- a/drivers/gpu/drm/i915/i915_gem_execbuffer.c +++ b/drivers/gpu/drm/i915/i915_gem_execbuffer.c @@ -566,6 +566,9 @@ i915_gem_execbuffer_reserve_vma(struct i915_vma *vma, if (entry->flags & EXEC_OBJECT_NEEDS_GTT) flags |= PIN_GLOBAL; + if (vma->uptr) + flags |= PIN_BOUND; + ret = i915_gem_object_pin(obj, vma->vm, entry->alignment, flags); if (ret) return ret; diff --git a/drivers/gpu/drm/i915/i915_gem_gtt.h b/drivers/gpu/drm/i915/i915_gem_gtt.h index c265c23..bdb4b05 100644 --- a/drivers/gpu/drm/i915/i915_gem_gtt.h +++ b/drivers/gpu/drm/i915/i915_gem_gtt.h @@ -171,6 +171,10 @@ struct i915_vma { unsigned int pin_count:4; #define DRM_I915_GEM_OBJECT_MAX_PIN_COUNT 0xf + /* FIXME: */ + unsigned int uptr:1; /* Whether this VMA has been userptr'd */ + unsigned int uptr_bind:1; /* Whether we've actually bound it */ + /** Unmap an object from an address space. This usually consists of * setting the valid PTE entries to a reserved scratch page. */ void (*unbind_vma)(struct i915_vma *vma);