Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp6778820rwb; Tue, 22 Nov 2022 19:29:52 -0800 (PST) X-Google-Smtp-Source: AA0mqf6CRYN0MOlLhGoalGXaY9bZcVdhwvefLt5oPf7sHFi4Y344sPqA2jonnBLNjxHi3oT/6RG9 X-Received: by 2002:a17:90a:b396:b0:218:8379:89a0 with SMTP id e22-20020a17090ab39600b00218837989a0mr24794407pjr.81.1669174192263; Tue, 22 Nov 2022 19:29:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669174192; cv=none; d=google.com; s=arc-20160816; b=Atd4fY+BPkwqSACBBNID6Yi8Ufa0hS50svQcc1lvyeiUc6Wqp8zuM+2MoZ9iWCrPmA WSRdNSgT+IeIoPCLNlRTA6IQiIrEtCaobZ5XNNvDlpLIt2jDIWN17yDsKVVkew6FKjKR 5QOur1BrsSS0nsi/GRy8sXs2L5MfmFRzdqTps+xRlylAlNUJul0cSu6abAK0CEHNxQTO B6Vlk8oaxFXiO3giJKEEuBheTfXgGcArnEPRVCmHYTn4jS4cJpVxnlHBeDOlNUFMLSs8 JcbuZUIfMtRaV2oEQktKh1QHaUcGJ1wS8AW34MgaGWuoIkcsA1MEDv3i7xMNoFM/L/lx 9yuw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=i5sn0U37JqltrZOfLjt/9ICjQuomGZuIXjkagiwKJ10=; b=Pauy3aLfkq5+iK92XFOndi0Uo26j3SFgHKTLvZkZ+rPR/tHoPkYI/s15qCrubDMcZ1 FuHiPZ6yeeiPEktI8ZCU5kp5HXNSG9GdUeBH2Om/l7tshfRS9CO893nsf/4263Bl5XE4 9jEvQFr+IKJUNf1tB91XrAHaNQX4Ydm7Uq0cFs0mweWsxe99TWVGF7++Q+8Kwswm4tPl enMWS7YtjhiKFf9DNefoWQ9xzy1GZGoFVdmHkArYOs2v3TL5Rp7Wzy6BStgwF0eYusC6 +rPPJSPjcRwBwRvdfwBEnaz5kZ8WgB3WwdDEuhaptviY2JIz8syguTuhim4JkmU3Py0f yUEg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=Hhc+CVgz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=collabora.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a186-20020a6390c3000000b0047730e1a823si13263082pge.858.2022.11.22.19.29.39; Tue, 22 Nov 2022 19:29:52 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=Hhc+CVgz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=collabora.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235423AbiKWDAi (ORCPT + 90 others); Tue, 22 Nov 2022 22:00:38 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59182 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235258AbiKWDAU (ORCPT ); Tue, 22 Nov 2022 22:00:20 -0500 Received: from madras.collabora.co.uk (madras.collabora.co.uk [IPv6:2a00:1098:0:82:1000:25:2eeb:e5ab]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C98208DA4C for ; Tue, 22 Nov 2022 19:00:19 -0800 (PST) Received: from dimapc.. (109-252-117-140.nat.spd-mgts.ru [109.252.117.140]) (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 C28496602AEE; Wed, 23 Nov 2022 03:00:16 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1669172418; bh=RT5S0yzlaNnCWPARh+1Inmti1GJA1337tFu57txKjKk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Hhc+CVgz3ztZzhqdqHOTNzN4wdgJzLzwr4A9Wu6OVixxsAi12YBGiHpRZxyozeHnb 16NoycUMWhhtlKjvjjVZ+Ba4sqjm4j94MjW++DYcWthha17ktWLmGHbsBQSMwetrfC oarSIj2efludtgTL1dme9UDMGJaNjCrB3xE8OrELTLaQMThKz0KtlnXDAkXo5fp0pv kWfQaDrKOuedrLkH2RS/mp97DGfVRPbJT69X00Dpa97H1AWIKRXqDY6JJYJmNUlH+6 F4wQuW4EHv8OCIFQKywWdxsa9IkaAD9X6wj+pcwwW2FBMR0tExzUa+4U0/XRV63tp9 RGzyWE9qLUGWg== 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=20K=C3=B6nig?= , Qiang Yu , Steven Price , Alyssa Rosenzweig , Rob Herring , Sean Paul , Dmitry Baryshkov , Abhinav Kumar Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, kernel@collabora.com, virtualization@lists.linux-foundation.org Subject: [PATCH v9 03/11] drm/gem: Add evict() callback to drm_gem_object_funcs Date: Wed, 23 Nov 2022 05:57:15 +0300 Message-Id: <20221123025723.695075-4-dmitry.osipenko@collabora.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221123025723.695075-1-dmitry.osipenko@collabora.com> References: <20221123025723.695075-1-dmitry.osipenko@collabora.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- drivers/gpu/drm/drm_gem.c | 15 +++++++++++++++ include/drm/drm_gem.h | 12 ++++++++++++ 2 files changed, 27 insertions(+) diff --git a/drivers/gpu/drm/drm_gem.c b/drivers/gpu/drm/drm_gem.c index 299bca1390aa..c0510b8080d2 100644 --- a/drivers/gpu/drm/drm_gem.c +++ b/drivers/gpu/drm/drm_gem.c @@ -1458,3 +1458,18 @@ 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; +} diff --git a/include/drm/drm_gem.h b/include/drm/drm_gem.h index b46ade812443..add1371453f0 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); }; /** @@ -480,4 +490,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__ */ -- 2.38.1