From patchwork Sat Feb 2 15:41:54 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rob Herring X-Patchwork-Id: 157343 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp1832961jaa; Sat, 2 Feb 2019 07:42:04 -0800 (PST) X-Google-Smtp-Source: AHgI3IYiRU6IylFRlY+rd8D+TynG2wdHRDYJuNMi7u5ZC8VEPeBNmQDH5pVVPK8tusoV5q78fvx4 X-Received: by 2002:a65:590b:: with SMTP id f11mr6579710pgu.60.1549122124251; Sat, 02 Feb 2019 07:42:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549122124; cv=none; d=google.com; s=arc-20160816; b=imHw7XZsYkCVk03p8BLAZHG4WuctZhHEtLVPN2Pr1W8aF2N6uX+NnHKAkhAi+egCUz oO5HcdNM53gipfOuUQKeW2gJwRB6FliTvmw+8gTXjVSR7pDnjTUDfAXqkLqIaBjiX72a mw4OUcqN/XSBpQLk8g0p/l99fJwCy90REsC/+uVJhYG7r1fvyOxJM9jM6xUlBP+2ulOP kIO8XuD/IGNjdP1zhV24RLcurcueysgKdZF6CWpHNz+lZr/BLLu9iHAsX0di3id1p+tz OYKjS65/eyLDprVUyQnv4+zgbH+2YUwV7slfcdvB7IEEzRv4nV9dn/KQZnKX67YvNniz LUuA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=kXO9EnLK/WG9l04J2zoTVZIyTiSdpAPmcoczIKV7sqM=; b=rknFXpHx6QwIyz8kU1ENsGrMHvlU0EsNozccslUJq89t3Q+Zas1+4WcWWcgifHW6zJ vIdXtKZlQApvOmNHjrcSgtO0Zoil1/cbr4nh2vixpxR0JPHRLAZLuTy+byWZVJGA8QZu y8P4OdfDoNji/y5ydSAnBqXVK0F+k8U2AmsXEwCnAgsCFLT3ud5gjH4WOK9qeVX0aI5C QSYK/ssdZxOtXWibk2DExajMhiJhKbTVe9te6HjF/a87Mrl+vNI1LSvVFZ1fZmgwqHMI ayZyHFKIftRzS2tEH2wkOvkxIV9P39XQxqVHJK34ueSGjjvZrhnQAogP3Em6v44RRNSj NxQA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-arm-msm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-arm-msm-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g8si8238222pli.50.2019.02.02.07.42.04; Sat, 02 Feb 2019 07:42:04 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-arm-msm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-arm-msm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-arm-msm-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727770AbfBBPmD (ORCPT + 15 others); Sat, 2 Feb 2019 10:42:03 -0500 Received: from mail-oi1-f193.google.com ([209.85.167.193]:46424 "EHLO mail-oi1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727474AbfBBPmD (ORCPT ); Sat, 2 Feb 2019 10:42:03 -0500 Received: by mail-oi1-f193.google.com with SMTP id x202so8259720oif.13 for ; Sat, 02 Feb 2019 07:42:02 -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=kXO9EnLK/WG9l04J2zoTVZIyTiSdpAPmcoczIKV7sqM=; b=Spz5cINv7S0JaL/vfF4Hm2w7Z+lhIxvjszRP/aTHNx8CrxlQvO4uAW3chhOAgKrF6T Kw99lGDccwkYJ+4DkRaDHPSkADbXCwjm8ayU1NWOT0s90PsckDBEVaskD01LGwEwJaDu sFHC3j3JvzqEGzD7BQ5Y61nwA4Qpc3u97/AGu93WRspzCfjGP6Zm42ogbmQO0dZWEboV 4r+BmmFrCTHsZAvKXGPTBMWHNTH6xX2jasHVOvSgTyhxi7uehUOMtLOVHn0GTVnXODnU DwO/tnhbowoB+TcTk9TO1LsIlIxHdrlwJVscVV84IzXZfMcMqURBd4bQiXJZ1xGooidd QsCg== X-Gm-Message-State: AJcUukeF5nCGPTQzpP56WG72p7CpY3sI4/9NIXV56/yzYlJDjyTF9GeP XA00MpZY/UwWUTw6ElkECA== X-Received: by 2002:aca:f1d7:: with SMTP id p206mr22581205oih.239.1549122120725; Sat, 02 Feb 2019 07:42: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 187sm5215559oic.12.2019.02.02.07.41.59 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 02 Feb 2019 07:42:00 -0800 (PST) From: Rob Herring To: dri-devel@lists.freedesktop.org Cc: Christian Gmeiner , Daniel Vetter , David Airlie , Eric Anholt , etnaviv@lists.freedesktop.org, freedreno@lists.freedesktop.org, linux-arm-msm@vger.kernel.org, Lucas Stach , Maarten Lankhorst , Maxime Ripard , Rob Clark , Russell King , Sean Paul Subject: [PATCH v2 1/5] drm: Add reservation_object to drm_gem_object Date: Sat, 2 Feb 2019 09:41:54 -0600 Message-Id: <20190202154158.10443-2-robh@kernel.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190202154158.10443-1-robh@kernel.org> References: <20190202154158.10443-1-robh@kernel.org> MIME-Version: 1.0 Sender: linux-arm-msm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org 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 --- v2: - Fix missing kerneldoc - Reword todo with what is left todo. - Fix timeout error handling (added to drm_gem_reservation_object_wait) Documentation/gpu/todo.rst | 8 +++---- drivers/gpu/drm/drm_gem.c | 43 +++++++++++++++++++++++++++++++++++++ drivers/gpu/drm/drm_prime.c | 1 + include/drm/drm_gem.h | 21 ++++++++++++++++++ 4 files changed, 69 insertions(+), 4 deletions(-) -- 2.19.1 Reviewed-by: Eric Anholt Reviewed-by: Christian Gmeiner diff --git a/Documentation/gpu/todo.rst b/Documentation/gpu/todo.rst index 14191b64446d..c9ed55605641 100644 --- a/Documentation/gpu/todo.rst +++ b/Documentation/gpu/todo.rst @@ -209,12 +209,12 @@ 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 +Remove the ->gem_prime_res_obj callback -------------------------------------------- -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. +The ->gem_prime_res_obj callback can be removed from drivers by using the +reservation_object in the drm_gem_object. It may also be possible to use the +generic drm_gem_reservation_object_wait helper for waiting for a bo. Contact: Daniel Vetter diff --git a/drivers/gpu/drm/drm_gem.c b/drivers/gpu/drm/drm_gem.c index 8b55ece97967..b09acbc5a655 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; + reservation_object_init(&obj->_resv); + if (!obj->resv) + obj->resv = &obj->_resv; + drm_vma_node_reset(&obj->vma_node); } EXPORT_SYMBOL(drm_gem_private_object_init); @@ -657,6 +661,44 @@ drm_gem_object_lookup(struct drm_file *filp, u32 handle) } EXPORT_SYMBOL(drm_gem_object_lookup); +/** + * drm_gem_reservation_object_wait - Wait on GEM object's reservation's objects + * shared and/or exclusive fences. + * @filep: 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); + if (ret == 0) + ret = -ETIME; + else if (ret > 0) + ret = 0; + + 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 +863,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..25f1ff2df464 100644 --- a/include/drm/drm_gem.h +++ b/include/drm/drm_gem.h @@ -35,6 +35,7 @@ */ #include +#include #include @@ -262,6 +263,24 @@ struct drm_gem_object { */ struct dma_buf_attachment *import_attach; + /** + * @resv: + * + * Pointer to reservation object associated with the this GEM object. + * + * Normally (@resv == &@_resv) except for imported GEM objects. + */ + struct reservation_object *resv; + + /** + * @_resv: + * + * A reservation object for this GEM object. + * + * This is unused for imported GEM objects. + */ + struct reservation_object _resv; + /** * @funcs: * @@ -363,6 +382,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,