From patchwork Mon Aug 15 09:48:50 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Wilson X-Patchwork-Id: 9280699 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 0986B60839 for ; Mon, 15 Aug 2016 09:49:32 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EE33B28D29 for ; Mon, 15 Aug 2016 09:49:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E302C28D38; Mon, 15 Aug 2016 09:49:31 +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=-4.1 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,T_DKIM_INVALID 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 9F2A828D29 for ; Mon, 15 Aug 2016 09:49:31 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id EEE986E3D1; Mon, 15 Aug 2016 09:49:30 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mail-wm0-x242.google.com (mail-wm0-x242.google.com [IPv6:2a00:1450:400c:c09::242]) by gabe.freedesktop.org (Postfix) with ESMTPS id 679076E3D2 for ; Mon, 15 Aug 2016 09:49:29 +0000 (UTC) Received: by mail-wm0-x242.google.com with SMTP id q128so10216650wma.1 for ; Mon, 15 Aug 2016 02:49:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:subject:date:message-id:in-reply-to:references; bh=Obv4NoUC5RBeQprTIM5up1OPZBA9Ur3FlxrUKlBK76g=; b=qmQ1qNxzCWAjSGhU4fW/uoR7V8FQ5fQ5j7nqw4AqVGhDkKYwjG3z2hk0Q5FavRZLbA 4n1CxaIM3HZ47EwDE1bFFXVAC45yi0jwldse5CPz7RS4q7zSugM5rPNU9k8cELw5wuOt F3VDwpZyYn+dLJT+YMfPHDITCrGyETj+xwE2cU4JZv+dcb665VNilOm73uiKCVrMqPqz urd38Zuok3kOiOr8ubW95vfPbnNVXL8fn/84eYxE13KaWiI1D9Hicimwk4fNt+JmEdtB 4WYKUUk7NEL/lMZ2FtQncOWQueE5YvW+HaTYZnhM3FjMjB6r+dPWkXRGZ2p8GN0HZ5cK nizg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:from:to:subject:date:message-id :in-reply-to:references; bh=Obv4NoUC5RBeQprTIM5up1OPZBA9Ur3FlxrUKlBK76g=; b=UgLHD4uKuwklZFTQlLLi0OzSYOzantrv8rtk1h+dmYqjk1mKmqAIOEnYVlt/gW6hX2 AX0j7dfW1xxyuBbYXu0jOQbhy7kVUoqoGgNzCKLKoHisOxvOtODv89bGXzId+s7z/Hqg Zdc+BJ1dAS+xiO6M04gQgLP/96Jh1MzaOYVa3u1Az2kt05gMPyukIOcYNwtf2Si+XtGU YVwebkUWKlpppbVEr0ZJoxDAL5p2DTKiRmrE6e311pIpuyx9nfWqBeAOJdrVfkGSXI8c xEywQ7/fki0NZILZbeiNdH9a95y3H11Za3R9arzkWRYerqxx3JFOk2de4oEr4Aa4/4T0 wuGg== X-Gm-Message-State: AEkoousCO6zRP9Urjs7l6lU6VBtRoT1QqWtGPoIWAvkC8K2zPJ950HWyrwhr/rNEdPseww== X-Received: by 10.195.11.104 with SMTP id eh8mr30017215wjd.128.1471254567863; Mon, 15 Aug 2016 02:49:27 -0700 (PDT) Received: from haswell.alporthouse.com ([78.156.65.138]) by smtp.gmail.com with ESMTPSA id v203sm15675247wmv.2.2016.08.15.02.49.26 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 15 Aug 2016 02:49:26 -0700 (PDT) From: Chris Wilson To: intel-gfx@lists.freedesktop.org Date: Mon, 15 Aug 2016 10:48:50 +0100 Message-Id: <1471254551-25805-11-git-send-email-chris@chris-wilson.co.uk> X-Mailer: git-send-email 2.8.1 In-Reply-To: <1471254551-25805-1-git-send-email-chris@chris-wilson.co.uk> References: <1471254551-25805-1-git-send-email-chris@chris-wilson.co.uk> Subject: [Intel-gfx] [CI 11/32] drm/i915: Add convenience wrappers for vma's object get/put X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.18 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 The VMA are unreferenced, they belong to the object and live until they are closed. However, if we want to use the VMA as a cookie and use it to keep the object alive, we want to hold onto a reference to the object for the lifetime of the VMA cookie. To facilitate this, add a couple of simple wrappers for managing the reference count on the object owning the VMA. Signed-off-by: Chris Wilson Reviewed-by: Joonas Lahtinen --- drivers/gpu/drm/i915/i915_drv.h | 12 ++++++++++++ drivers/gpu/drm/i915/i915_gem_execbuffer.c | 4 ++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h index 855833a6306a..3285c8e2c87a 100644 --- a/drivers/gpu/drm/i915/i915_drv.h +++ b/drivers/gpu/drm/i915/i915_drv.h @@ -2373,6 +2373,18 @@ i915_gem_object_get_stride(struct drm_i915_gem_object *obj) return obj->tiling_and_stride & STRIDE_MASK; } +static inline struct i915_vma *i915_vma_get(struct i915_vma *vma) +{ + i915_gem_object_get(vma->obj); + return vma; +} + +static inline void i915_vma_put(struct i915_vma *vma) +{ + lockdep_assert_held(&vma->vm->dev->struct_mutex); + i915_gem_object_put(vma->obj); +} + /* * Optimised SGL iterator for GEM objects */ diff --git a/drivers/gpu/drm/i915/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/i915_gem_execbuffer.c index c8d13fea4b25..ced05878b405 100644 --- a/drivers/gpu/drm/i915/i915_gem_execbuffer.c +++ b/drivers/gpu/drm/i915/i915_gem_execbuffer.c @@ -271,7 +271,7 @@ static void eb_destroy(struct eb_vmas *eb) exec_list); list_del_init(&vma->exec_list); i915_gem_execbuffer_unreserve_vma(vma); - i915_gem_object_put(vma->obj); + i915_vma_put(vma); } kfree(eb); } @@ -900,7 +900,7 @@ i915_gem_execbuffer_relocate_slow(struct drm_device *dev, vma = list_first_entry(&eb->vmas, struct i915_vma, exec_list); list_del_init(&vma->exec_list); i915_gem_execbuffer_unreserve_vma(vma); - i915_gem_object_put(vma->obj); + i915_vma_put(vma); } mutex_unlock(&dev->struct_mutex);