From patchwork Wed Nov 23 02:57:15 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Osipenko X-Patchwork-Id: 24665 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp2561196wrr; Tue, 22 Nov 2022 19:02:07 -0800 (PST) X-Google-Smtp-Source: AA0mqf6B+K95D4FH/zqOXm3+9jvRudC76g3uczscWEg8rMJ58gpBMI6v+tVayP6hp6TpqPbz1sHg X-Received: by 2002:aa7:cc04:0:b0:463:1a0c:4dd1 with SMTP id q4-20020aa7cc04000000b004631a0c4dd1mr14674993edt.137.1669172527618; Tue, 22 Nov 2022 19:02:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669172527; cv=none; d=google.com; s=arc-20160816; b=ooSpkpmxpl2li33EsjIdaWIMHsN/9Zyz0gS4thpfNk/jwewXgPiLYpUwxWq8aRJQ7v Agqevctb/g27jSYvVJJUDNLLgarwVvraWY62dgciODyQXF7qlnfKPoRn/H6pCrBi2P0m nmykPyIoKLgd21gBKlRG9Rt51qrPOjVOUvliOLcHnQfjFGEFuXQWTq2+54tAqLfEu9vO VZatZDIpCX+J8d2+fGfTy+AuQrmdTUoHMdnBstvDOdC4R5zBkiq+SOE162UDCv56ErTD lW9rQSvQizMHGedL71iAIpVUmf+97ekAy2tENfVca4xtuLwzd68iLSxvtydR5aVkRuOQ Y1JQ== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n9-20020a05640205c900b0044615ee1b6fsi1386020edx.218.2022.11.22.19.01.40; Tue, 22 Nov 2022 19:02:07 -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 + 99 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_K=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 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1750254251823550077?= X-GMAIL-MSGID: =?utf-8?q?1750254251823550077?= 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__ */