[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20250326021433.772196-6-adrian.larumbe@collabora.com>
Date: Wed, 26 Mar 2025 02:14:25 +0000
From: Adrián Larumbe <adrian.larumbe@...labora.com>
To: Andrew Morton <akpm@...ux-foundation.org>,
Maarten Lankhorst <maarten.lankhorst@...ux.intel.com>,
Maxime Ripard <mripard@...nel.org>,
Thomas Zimmermann <tzimmermann@...e.de>,
David Airlie <airlied@...il.com>,
Simona Vetter <simona@...ll.ch>,
Boris Brezillon <boris.brezillon@...labora.com>,
Rob Herring <robh@...nel.org>,
Steven Price <steven.price@....com>,
Liviu Dudau <liviu.dudau@....com>
Cc: kernel@...labora.com,
Adrián Larumbe <adrian.larumbe@...labora.com>,
linux-kernel@...r.kernel.org,
dri-devel@...ts.freedesktop.org
Subject: [RFC PATCH v2 5/6] drm/shmem: Add a helper to check object's page backing status
Provide a helper function that lets shmem API users know whether a given
object is backed by physical pages, or else in the case of a sparse
shmem object, at least one of them is populated.
The obvious user is fdinfo, which needs to know an object's resident
status.
Signed-off-by: Adrián Larumbe <adrian.larumbe@...labora.com>
---
drivers/gpu/drm/drm_gem_shmem_helper.c | 18 ++++++++++++++++++
include/drm/drm_gem_shmem_helper.h | 2 ++
2 files changed, 20 insertions(+)
diff --git a/drivers/gpu/drm/drm_gem_shmem_helper.c b/drivers/gpu/drm/drm_gem_shmem_helper.c
index 1bf33e5a1c4c..79ac7c7c953f 100644
--- a/drivers/gpu/drm/drm_gem_shmem_helper.c
+++ b/drivers/gpu/drm/drm_gem_shmem_helper.c
@@ -1033,6 +1033,24 @@ drm_gem_shmem_prime_import_sg_table(struct drm_device *dev,
}
EXPORT_SYMBOL_GPL(drm_gem_shmem_prime_import_sg_table);
+/**
+ * drm_gem_shmem_is_populated - Tell whether the shem object is backed by
+ * at least one page of physical memory
+ * @shmem: shmem GEM object
+ *
+ * Returns:
+ * A boolean, where the 'true' value depends on at least one page being preset
+ * in a sparse object's xarray, or all the shmem file pages for PRIME buffers
+ * and regular shmem objects.
+ */
+bool drm_gem_shmem_is_populated(struct drm_gem_shmem_object *shmem)
+{
+ return (shmem->base.import_attach ||
+ (!shmem->sparse && shmem->pages) ||
+ (shmem->sparse && !xa_empty(&shmem->xapages)));
+}
+EXPORT_SYMBOL_GPL(drm_gem_shmem_is_populated);
+
MODULE_DESCRIPTION("DRM SHMEM memory-management helpers");
MODULE_IMPORT_NS("DMA_BUF");
MODULE_LICENSE("GPL v2");
diff --git a/include/drm/drm_gem_shmem_helper.h b/include/drm/drm_gem_shmem_helper.h
index cbe4548e3ff6..60d2b8ef230b 100644
--- a/include/drm/drm_gem_shmem_helper.h
+++ b/include/drm/drm_gem_shmem_helper.h
@@ -302,6 +302,8 @@ drm_gem_shmem_prime_import_sg_table(struct drm_device *dev,
int drm_gem_shmem_dumb_create(struct drm_file *file, struct drm_device *dev,
struct drm_mode_create_dumb *args);
+bool drm_gem_shmem_is_populated(struct drm_gem_shmem_object *shmem);
+
/**
* DRM_GEM_SHMEM_DRIVER_OPS - Default shmem GEM operations
*
--
2.48.1
Powered by blists - more mailing lists