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 \(Arm\)" X-Patchwork-Id: 157163 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp7870323jaa; Thu, 31 Jan 2019 16:51:05 -0800 (PST) X-Google-Smtp-Source: ALg8bN6cOswfrse+HB77PN/wWO985viDf8NUYlsV2dx4NDANZu9Qu8k37BMHodL0wIvTWIhoTOU7 X-Received: by 2002:a17:902:7c05:: with SMTP id x5mr36417067pll.273.1548982265541; Thu, 31 Jan 2019 16:51:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548982265; cv=none; d=google.com; s=arc-20160816; b=eivAYd7a3gueVwuPDJ6bQLbxmKjDR7xS8coV3ZgxSu+MOfq0iNamlM/c3yTaOeErAU JmQX5vDFUPMoL+YmZ5IWoqfhBeDXtlAhcKzGjS1nfIVKV/uDraaIDCqeYQakZKv43s5w 4G+Tu6aRyUusL9Dgxu7vvPYBStfmr3GrOrlqoZ7hT6TXh+LFCFTJjRdVSsR/eKvgHRYo GGuA8qwDx3J724Okj+1hLKLEUWCLhbarbc9vsuTRImMGrvgsXj9PUJedBPEs5oatfzdT qRmBLLpfvQ0aje+mRMFQdZza8I6Jzefjjru+B6tuX/ygSEzh2/wwLokYtBezcBzzBry4 wDYA== 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=ZuYglknL1Ha67Z8bKmDkd+9e4Ru71S9MI3ZsQ1DGxZ8=; b=HfZqbVzksw7KqKTfID1naZGfYrJiO6STWtb/O2nQS8wZsUfGn930V41UZiD95X55bG KJaF9S/dJ+CGBjHKpa/QkzmaC2/+al+wp9ozC4z1ZQhfO3/05Q40zch47XLMxWqYYbzC 8Ku1DEghJla0Ijk8V0c90CfQJ5M26grhWj1iATRk9VSA4Pu5Q58TqAcstxsr8Zk2PQq/ m+7SUzNLQ26qV3KLpSBuG1BwO0buUxqsdaPH2oqoQhyzwaMqk/dB6foEQL0JCzU/hmQj bWbZrmdH5Jc80eeOVqn79XOiZJ0vKgbFd+hbyexF3baiqu2Nvntxs8faqXlESWXcdxQD Jk6A== 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 s5si76944pgl.481.2019.01.31.16.51.03; Thu, 31 Jan 2019 16:51:05 -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 S1727784AbfBAAvB (ORCPT + 15 others); Thu, 31 Jan 2019 19:51:01 -0500 Received: from mail-ot1-f65.google.com ([209.85.210.65]:41283 "EHLO mail-ot1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726976AbfBAAvB (ORCPT ); Thu, 31 Jan 2019 19:51:01 -0500 Received: by mail-ot1-f65.google.com with SMTP id u16so4592344otk.8 for ; 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=sKo6ZHL7ZqK8XHF0sA9w5E/n6i/C4m9f99DzOa/F8Uxcq2+2ZqueX2NOgKlgedirAP MZqdJmynjAWVLOOT6cEcXMGlsanajhW4EERerBSYPS1zMEjXG4QVNveh4TR+F6EYnJek tBny6CLZ1y+c2nLhShdqH09EzW7Tj07TJ6XxbmUCuAGRF0ZvCyA3APxmo8Q938j+3ypa ziegg7W/KRZkyYorjd72dNJfsgC8vOwkb28sSTos6ngAHhm0IsKbhvZw2YTEdVTIuzj1 43VmJ0C6EodyqSt3EcbPqAGbjR/aDQ1a09NMuyWKcsoRc2SRndpI6/gJ7OFmbs+BFH1s z9XA== X-Gm-Message-State: AJcUukeGMYa8Y1BXtc0l8YjQEKzDCaavczWjNY3vKzYvuS8ptHQJKFlM aoyWTGA3FbAtJHWNjYmC3A== 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 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 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 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 --- 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(-) -- 2.19.1 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,