From patchwork Fri Feb 1 00:50:53 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rob Herring X-Patchwork-Id: 10791609 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 2EB8213B5 for ; Fri, 1 Feb 2019 00:51:10 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2332931C40 for ; Fri, 1 Feb 2019 00:51:10 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 174DE31C45; Fri, 1 Feb 2019 00:51:10 +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 9B3C531C40 for ; Fri, 1 Feb 2019 00:51:09 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 43FB86E236; Fri, 1 Feb 2019 00:51:03 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-ot1-f68.google.com (mail-ot1-f68.google.com [209.85.210.68]) by gabe.freedesktop.org (Postfix) with ESMTPS id 0A4866E22F; Fri, 1 Feb 2019 00:51:02 +0000 (UTC) Received: by mail-ot1-f68.google.com with SMTP id v23so4582785otk.9; Thu, 31 Jan 2019 16:51:01 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ZuYglknL1Ha67Z8bKmDkd+9e4Ru71S9MI3ZsQ1DGxZ8=; b=OyZJw/B03g2zYR6M2ud5LX6kO6bvaBhqGJtGN1zF3bCBrgs6+nct3S1I1KqIE3Gssr IBbcfypWI6MgKEPoidAqUOpeIs9rOU2IuMFX3lL4EG8s9wlhlpeLybtljyF5CqMDm8ZX iKHyvAu+4xfsIEFQXPPbF63Bs4zzQzcDS1tyXyQVwFTtpovZORALKdG+k3R1ag1+PiVD ZpIQIdr9BqzNMVq3EobQLEpMjnGQwPikmvcLLAdG9R7hVA2TVd1cBQjvslMZUWywNreM b4/64kfxY63wooASj5Oy8AzHl4T8GOlZi/cqPPITpSGXpr66dM1TU8Ovcx2ZFW8spvW3 LYEQ== X-Gm-Message-State: AJcUukc3+uG+8F/SnOuCr0hX0ALKaMkuKeUepUfibEKoHu2AQKWGiCLC 3+pc6d6lLkVojOQOXg3uwOUJXvg= X-Google-Smtp-Source: ALg8bN5zlqXNmi9r0FdbdJPmYS72NytZBXLuw+PdEETwV2269fa9/EjTlKqRIrVjZGINT7K1hThX0A== X-Received: by 2002:a9d:2184:: with SMTP id s4mr28893399otb.46.1548982260844; Thu, 31 Jan 2019 16:51:00 -0800 (PST) Received: from xps15.herring.priv (24-155-109-49.dyn.grandenetworks.net. [24.155.109.49]) by smtp.googlemail.com with ESMTPSA id 31sm3137699otw.55.2019.01.31.16.50.59 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 31 Jan 2019 16:51:00 -0800 (PST) From: Rob Herring To: dri-devel@lists.freedesktop.org Subject: [PATCH 1/5] drm: Add reservation_object to drm_gem_object Date: Thu, 31 Jan 2019 18:50:53 -0600 Message-Id: <20190201005057.13648-2-robh@kernel.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190201005057.13648-1-robh@kernel.org> References: <20190201005057.13648-1-robh@kernel.org> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Sean Paul , Maxime Ripard , David Airlie , linux-arm-msm@vger.kernel.org, etnaviv@lists.freedesktop.org, Russell King , freedreno@lists.freedesktop.org Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP Many users of drm_gem_object embed a struct reservation_object into their subclassed struct, so let's add one to struct drm_gem_object. This will allow removing the reservation object from the subclasses and removing the ->gem_prime_res_obj callback. With the addition, add a drm_gem_reservation_object_wait() helper function for drivers to use in wait ioctls. Cc: Maarten Lankhorst Cc: Maxime Ripard Cc: Sean Paul Cc: David Airlie Cc: Daniel Vetter Signed-off-by: Rob Herring --- Documentation/gpu/todo.rst | 9 --------- drivers/gpu/drm/drm_gem.c | 39 +++++++++++++++++++++++++++++++++++++ drivers/gpu/drm/drm_prime.c | 1 + include/drm/drm_gem.h | 7 +++++++ 4 files changed, 47 insertions(+), 9 deletions(-) diff --git a/Documentation/gpu/todo.rst b/Documentation/gpu/todo.rst index 14191b64446d..6e0a37d0bf6d 100644 --- a/Documentation/gpu/todo.rst +++ b/Documentation/gpu/todo.rst @@ -209,15 +209,6 @@ Would be great to refactor this all into a set of small common helpers. Contact: Daniel Vetter -Put a reservation_object into drm_gem_object --------------------------------------------- - -This would remove the need for the ->gem_prime_res_obj callback. It would also -allow us to implement generic helpers for waiting for a bo, allowing for quite a -bit of refactoring in the various wait ioctl implementations. - -Contact: Daniel Vetter - idr_init_base() --------------- diff --git a/drivers/gpu/drm/drm_gem.c b/drivers/gpu/drm/drm_gem.c index 8b55ece97967..91dd06c1b3a8 100644 --- a/drivers/gpu/drm/drm_gem.c +++ b/drivers/gpu/drm/drm_gem.c @@ -170,6 +170,10 @@ void drm_gem_private_object_init(struct drm_device *dev, kref_init(&obj->refcount); obj->handle_count = 0; obj->size = size; + if (!obj->resv) { + obj->resv = &obj->_resv; + reservation_object_init(obj->resv); + } drm_vma_node_reset(&obj->vma_node); } EXPORT_SYMBOL(drm_gem_private_object_init); @@ -657,6 +661,40 @@ drm_gem_object_lookup(struct drm_file *filp, u32 handle) } EXPORT_SYMBOL(drm_gem_object_lookup); +/** + * drm_gem_object_lookup - Wait on GEM object's reservation's objects + * shared and/or exclusive fences. + * @filp: DRM file private date + * @handle: userspace handle + * @wait_all: if true, wait on all fences, else wait on just exclusive fence + * @timeout: timeout value in jiffies or zero to return immediately + * + * Returns: + * + * Returns -ERESTARTSYS if interrupted, 0 if the wait timed out, or + * greater than 0 on success. + */ +long drm_gem_reservation_object_wait(struct drm_file *filep, u32 handle, + bool wait_all, unsigned long timeout) +{ + long ret; + struct drm_gem_object *obj; + + obj = drm_gem_object_lookup(filep, handle); + if (!obj) { + DRM_DEBUG("Failed to look up GEM BO %d\n", handle); + return -EINVAL; + } + + ret = reservation_object_wait_timeout_rcu(obj->resv, wait_all, + true, timeout); + + drm_gem_object_put_unlocked(obj); + + return ret; +} +EXPORT_SYMBOL(drm_gem_reservation_object_wait); + /** * drm_gem_close_ioctl - implementation of the GEM_CLOSE ioctl * @dev: drm_device @@ -821,6 +859,7 @@ drm_gem_object_release(struct drm_gem_object *obj) if (obj->filp) fput(obj->filp); + reservation_object_fini(&obj->_resv); drm_gem_free_mmap_offset(obj); } EXPORT_SYMBOL(drm_gem_object_release); diff --git a/drivers/gpu/drm/drm_prime.c b/drivers/gpu/drm/drm_prime.c index 231e3f6d5f41..dc079efb3b0f 100644 --- a/drivers/gpu/drm/drm_prime.c +++ b/drivers/gpu/drm/drm_prime.c @@ -504,6 +504,7 @@ struct dma_buf *drm_gem_prime_export(struct drm_device *dev, .size = obj->size, .flags = flags, .priv = obj, + .resv = obj->resv, }; if (dev->driver->gem_prime_res_obj) diff --git a/include/drm/drm_gem.h b/include/drm/drm_gem.h index c95727425284..f450a5b6038e 100644 --- a/include/drm/drm_gem.h +++ b/include/drm/drm_gem.h @@ -35,6 +35,7 @@ */ #include +#include #include @@ -262,6 +263,10 @@ struct drm_gem_object { */ struct dma_buf_attachment *import_attach; + /* normally (resv == &_resv) except for imported bo's */ + struct reservation_object *resv; + struct reservation_object _resv; + /** * @funcs: * @@ -363,6 +368,8 @@ void drm_gem_put_pages(struct drm_gem_object *obj, struct page **pages, bool dirty, bool accessed); struct drm_gem_object *drm_gem_object_lookup(struct drm_file *filp, u32 handle); +long drm_gem_reservation_object_wait(struct drm_file *filep, u32 handle, + bool wait_all, unsigned long timeout); int drm_gem_dumb_map_offset(struct drm_file *file, struct drm_device *dev, u32 handle, u64 *offset); int drm_gem_dumb_destroy(struct drm_file *file,