From patchwork Sun Jan 8 21:04:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Osipenko X-Patchwork-Id: 13092723 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 85325C54EBD for ; Sun, 8 Jan 2023 21:05:29 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id A91D810E201; Sun, 8 Jan 2023 21:05:28 +0000 (UTC) Received: from madras.collabora.co.uk (madras.collabora.co.uk [IPv6:2a00:1098:0:82:1000:25:2eeb:e5ab]) by gabe.freedesktop.org (Postfix) with ESMTPS id 50C8210E201 for ; Sun, 8 Jan 2023 21:05:26 +0000 (UTC) Received: from workpc.. (109-252-117-89.nat.spd-mgts.ru [109.252.117.89]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: dmitry.osipenko) by madras.collabora.co.uk (Postfix) with ESMTPSA id 7F7216602D55; Sun, 8 Jan 2023 21:05:19 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1673211925; bh=4h10hR175c/8QjxQaO3jcxXYg0x94Qq0uCuLNGtgonQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=attNsz6MrhLFYTdz3ETiWvxzQHu2FRqut+47r5QKraKPMZv2u9USyg0pjJY4MrEWM NksY58MTyWJRhxtaLAIBqyyaUwurZNmCJ8ODsGR7EBIT79InyKJeF54aGVWzkhwZSu /Z48WPKVcPnf1CuH0i1T0r9XBVFHMNY692LWgUSzp4GmaeSBAXjYD0QzWQ1FUGqCTb WcwkuL7Q2gdpy+ypdl6SWPsQ6Ika/MozaJVIo3Z4oKWamizzMU7Mx8IBtJgPeAfryL /8rsxn9OfyfU+sQKFFYkLhKQR6pAEUFiP+CZU1jWOo5QyJ34MNDwKSm0vTC3LuZJke L9PO7YVXYtf0Q== From: Dmitry Osipenko To: David Airlie , Gerd Hoffmann , Gurchetan Singh , Chia-I Wu , Daniel Vetter , Daniel Almeida , Gustavo Padovan , Daniel Stone , Tomeu Vizoso , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , Rob Clark , Sumit Semwal , =?utf-8?q?Christian_K=C3=B6nig?= , Qiang Yu , Steven Price , Alyssa Rosenzweig , Rob Herring , Sean Paul , Dmitry Baryshkov , Abhinav Kumar Subject: [PATCH v10 03/11] drm/gem: Add evict() callback to drm_gem_object_funcs Date: Mon, 9 Jan 2023 00:04:37 +0300 Message-Id: <20230108210445.3948344-4-dmitry.osipenko@collabora.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20230108210445.3948344-1-dmitry.osipenko@collabora.com> References: <20230108210445.3948344-1-dmitry.osipenko@collabora.com> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kernel@collabora.com, linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, virtualization@lists.linux-foundation.org Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Add new common evict() callback to drm_gem_object_funcs and corresponding drm_gem_object_evict() helper. This is a first step on a way to providing common GEM-shrinker API for DRM drivers. Suggested-by: Thomas Zimmermann Signed-off-by: Dmitry Osipenko Reviewed-by: Thomas Zimmermann --- drivers/gpu/drm/drm_gem.c | 16 ++++++++++++++++ include/drm/drm_gem.h | 12 ++++++++++++ 2 files changed, 28 insertions(+) diff --git a/drivers/gpu/drm/drm_gem.c b/drivers/gpu/drm/drm_gem.c index c6bca5ac6e0f..dbb48fc9dff3 100644 --- a/drivers/gpu/drm/drm_gem.c +++ b/drivers/gpu/drm/drm_gem.c @@ -1471,3 +1471,19 @@ drm_gem_lru_scan(struct drm_gem_lru *lru, return freed; } EXPORT_SYMBOL(drm_gem_lru_scan); + +/** + * drm_gem_object_evict - helper to evict backing pages for a GEM object + * @obj: obj in question + */ +bool +drm_gem_object_evict(struct drm_gem_object *obj) +{ + dma_resv_assert_held(obj->resv); + + if (obj->funcs->evict) + return obj->funcs->evict(obj); + + return false; +} +EXPORT_SYMBOL(drm_gem_object_evict); diff --git a/include/drm/drm_gem.h b/include/drm/drm_gem.h index f1f00fc2dba6..8e5c22f25691 100644 --- a/include/drm/drm_gem.h +++ b/include/drm/drm_gem.h @@ -172,6 +172,16 @@ struct drm_gem_object_funcs { * This is optional but necessary for mmap support. */ const struct vm_operations_struct *vm_ops; + + /** + * @evict: + * + * Evicts gem object out from memory. Used by the drm_gem_object_evict() + * helper. Returns true on success, false otherwise. + * + * This callback is optional. + */ + bool (*evict)(struct drm_gem_object *obj); }; /** @@ -481,4 +491,6 @@ unsigned long drm_gem_lru_scan(struct drm_gem_lru *lru, unsigned long *remaining, bool (*shrink)(struct drm_gem_object *obj)); +bool drm_gem_object_evict(struct drm_gem_object *obj); + #endif /* __DRM_GEM_H__ */