[PATCH v8 5/7] drm/gem: Add drm_gem_pin_unlocked()
Dmitry Osipenko
dmitry.osipenko at collabora.com
Sat Nov 5 23:27:17 UTC 2022
Add unlocked variants of drm_gem_un/pin() functions. These new helpers
will take care of GEM dma-reservation locking for DRM drivers.
VirtIO-GPU driver will use these helpers to pin shmem framebuffers,
preventing them from eviction during scanout.
Signed-off-by: Dmitry Osipenko <dmitry.osipenko at collabora.com>
---
drivers/gpu/drm/drm_gem.c | 29 +++++++++++++++++++++++++++++
include/drm/drm_gem.h | 3 +++
2 files changed, 32 insertions(+)
diff --git a/drivers/gpu/drm/drm_gem.c b/drivers/gpu/drm/drm_gem.c
index 299bca1390aa..5b8c66f113a9 100644
--- a/drivers/gpu/drm/drm_gem.c
+++ b/drivers/gpu/drm/drm_gem.c
@@ -1154,6 +1154,35 @@ void drm_gem_unpin(struct drm_gem_object *obj)
obj->funcs->unpin(obj);
}
+int drm_gem_pin_unlocked(struct drm_gem_object *obj)
+{
+ int ret;
+
+ if (!obj->funcs->pin)
+ return 0;
+
+ ret = dma_resv_lock_interruptible(obj->resv, NULL);
+ if (ret)
+ return ret;
+
+ ret = obj->funcs->pin(obj);
+ dma_resv_unlock(obj->resv);
+
+ return ret;
+}
+EXPORT_SYMBOL(drm_gem_pin_unlocked);
+
+void drm_gem_unpin_unlocked(struct drm_gem_object *obj)
+{
+ if (!obj->funcs->unpin)
+ return;
+
+ dma_resv_lock(obj->resv, NULL);
+ obj->funcs->unpin(obj);
+ dma_resv_unlock(obj->resv);
+}
+EXPORT_SYMBOL(drm_gem_unpin_unlocked);
+
int drm_gem_vmap(struct drm_gem_object *obj, struct iosys_map *map)
{
int ret;
diff --git a/include/drm/drm_gem.h b/include/drm/drm_gem.h
index b46ade812443..b43da1652356 100644
--- a/include/drm/drm_gem.h
+++ b/include/drm/drm_gem.h
@@ -480,4 +480,7 @@ unsigned long drm_gem_lru_scan(struct drm_gem_lru *lru,
unsigned long *remaining,
bool (*shrink)(struct drm_gem_object *obj));
+int drm_gem_pin_unlocked(struct drm_gem_object *obj);
+void drm_gem_unpin_unlocked(struct drm_gem_object *obj);
+
#endif /* __DRM_GEM_H__ */
--
2.37.3
More information about the dri-devel
mailing list