dri-devel.lists.freedesktop.org archive mirror
 help / color / mirror / Atom feed
From: Thomas Zimmermann <tzimmermann@suse.de>
To: airlied@redhat.com, daniel@ffwll.ch,
	maarten.lankhorst@linux.intel.com, mripard@kernel.org,
	hdegoede@redhat.com, christian.koenig@amd.com
Cc: Thomas Zimmermann <tzimmermann@suse.de>, dri-devel@lists.freedesktop.org
Subject: [PATCH 3/8] drm/vram-helper: Provide drm_gem_vram_vmap_unlocked()
Date: Mon, 30 Nov 2020 13:04:28 +0100	[thread overview]
Message-ID: <20201130120433.7205-4-tzimmermann@suse.de> (raw)
In-Reply-To: <20201130120433.7205-1-tzimmermann@suse.de>

The new interface drm_gem_vram_vmap_unlocked() acquires a GEM object's
reservation lock and vmaps the buffer into the kernel address space. In
contract to the existing vmap implementation, it does not pin the buffer.
The function will be helpful for code that needs to vmap and vunmap
single GEM objects.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/gpu/drm/drm_gem_vram_helper.c | 52 +++++++++++++++++++++++++++
 include/drm/drm_gem_vram_helper.h     |  4 +++
 2 files changed, 56 insertions(+)

diff --git a/drivers/gpu/drm/drm_gem_vram_helper.c b/drivers/gpu/drm/drm_gem_vram_helper.c
index 02ca22e90290..af54cb52423b 100644
--- a/drivers/gpu/drm/drm_gem_vram_helper.c
+++ b/drivers/gpu/drm/drm_gem_vram_helper.c
@@ -486,6 +486,58 @@ void drm_gem_vram_vunmap(struct drm_gem_vram_object *gbo, struct dma_buf_map *ma
 }
 EXPORT_SYMBOL(drm_gem_vram_vunmap);
 
+/**
+ * drm_gem_vram_vmap_unlocked() - Locks a GEM VRAM object and maps it into
+ *                                kernel address space
+ * @gbo: The GEM VRAM object to map
+ * @map: Returns the kernel virtual address of the VRAM GEM object's backing
+ *       store.
+ * @ctx: The locking context.
+ *
+ * This vmap function locks a GEM VRAM object and maps its buffer into kernel
+ * address space. Call drm_gem_vram_vunmap_unlocked() with the returned address
+ * to unmap and unlock the GEM VRAM object.
+ *
+ * Returns:
+ * 0 on success, or a negative error code otherwise.
+ */
+int drm_gem_vram_vmap_unlocked(struct drm_gem_vram_object *gbo, struct dma_buf_map *map,
+			       struct ww_acquire_ctx *ctx)
+{
+	int ret;
+
+	ret = ttm_bo_reserve(&gbo->bo, true, false, ctx);
+	if (ret)
+		return ret;
+
+	ret = drm_gem_vram_kmap_locked(gbo, map);
+	if (ret)
+		goto err_ttm_bo_unreserve;
+
+	return 0;
+
+err_ttm_bo_unreserve:
+	ttm_bo_unreserve(&gbo->bo);
+	return ret;
+}
+EXPORT_SYMBOL(drm_gem_vram_vmap_unlocked);
+
+/**
+ * drm_gem_vram_vunmap_unlocked() - Unmaps and unlocks a GEM VRAM object
+ * @gbo: The GEM VRAM object to unmap
+ * @map: Kernel virtual address where the VRAM GEM object was mapped
+ *
+ * A call to drm_gem_vram_vunmap_unlocked() unmaps and unlocks a GEM VRAM
+ * buffer object. See the documentation for drm_gem_vram_vmap_unlocked()
+ * for more information.
+ */
+void drm_gem_vram_vunmap_unlocked(struct drm_gem_vram_object *gbo, struct dma_buf_map *map)
+{
+	drm_gem_vram_kunmap_locked(gbo, map);
+	ttm_bo_unreserve(&gbo->bo);
+}
+EXPORT_SYMBOL(drm_gem_vram_vunmap_unlocked);
+
 /**
  * drm_gem_vram_fill_create_dumb() - \
 	Helper for implementing &struct drm_driver.dumb_create
diff --git a/include/drm/drm_gem_vram_helper.h b/include/drm/drm_gem_vram_helper.h
index a4bac02249c2..2d22888b5754 100644
--- a/include/drm/drm_gem_vram_helper.h
+++ b/include/drm/drm_gem_vram_helper.h
@@ -19,6 +19,7 @@ struct drm_plane_state;
 struct drm_simple_display_pipe;
 struct filp;
 struct vm_area_struct;
+struct ww_acquire_ctx;
 
 #define DRM_GEM_VRAM_PL_FLAG_SYSTEM	(1 << 0)
 #define DRM_GEM_VRAM_PL_FLAG_VRAM	(1 << 1)
@@ -99,6 +100,9 @@ int drm_gem_vram_pin(struct drm_gem_vram_object *gbo, unsigned long pl_flag);
 int drm_gem_vram_unpin(struct drm_gem_vram_object *gbo);
 int drm_gem_vram_vmap(struct drm_gem_vram_object *gbo, struct dma_buf_map *map);
 void drm_gem_vram_vunmap(struct drm_gem_vram_object *gbo, struct dma_buf_map *map);
+int drm_gem_vram_vmap_unlocked(struct drm_gem_vram_object *gbo, struct dma_buf_map *map,
+			       struct ww_acquire_ctx *ctx);
+void drm_gem_vram_vunmap_unlocked(struct drm_gem_vram_object *gbo, struct dma_buf_map *map);
 
 int drm_gem_vram_fill_create_dumb(struct drm_file *file,
 				  struct drm_device *dev,
-- 
2.29.2

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

  parent reply	other threads:[~2020-11-30 12:05 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-30 12:04 [PATCH 0/8] drm/vram-helper: Lock GEM BOs while they are mapped Thomas Zimmermann
2020-11-30 12:04 ` [PATCH 1/8] drm/gem: Write down some rules for vmap usage Thomas Zimmermann
2020-11-30 15:30   ` Daniel Vetter
2020-11-30 15:33     ` Christian König
2020-12-01  8:32       ` Thomas Zimmermann
2020-12-01  9:10         ` Daniel Vetter
2020-12-01  9:40           ` Thomas Zimmermann
2020-12-01 10:00             ` Daniel Vetter
2020-12-01 10:27               ` Thomas Zimmermann
2020-12-01 10:34                 ` Christian König
2020-12-01 11:30                   ` Thomas Zimmermann
2020-12-01 12:14                     ` Christian König
2020-12-01 12:33                       ` Thomas Zimmermann
2020-12-01 12:38                         ` Christian König
2020-12-01 12:51                           ` Thomas Zimmermann
2020-12-01 12:53                             ` Thomas Zimmermann
2020-12-01 13:05                               ` Christian König
2020-12-01 16:54                 ` Daniel Vetter
2020-12-01 12:05               ` Thomas Zimmermann
2020-12-01  9:13         ` Christian König
2020-12-01  9:30           ` Thomas Zimmermann
2020-12-01  8:15     ` Thomas Zimmermann
2020-11-30 12:04 ` [PATCH 2/8] drm/ast: Only map cursor BOs during updates Thomas Zimmermann
2020-11-30 12:04 ` Thomas Zimmermann [this message]
2020-11-30 12:04 ` [PATCH 4/8] drm/ast: Use drm_gem_vram_vmap_unlocked() in ast_cursor_show() Thomas Zimmermann
2020-11-30 12:04 ` [PATCH 5/8] drm/vboxvideo: Use drm_gem_vram_vmap_unlocked() in cursor update Thomas Zimmermann
2020-11-30 12:04 ` [PATCH 6/8] drm/vram-helper: Remove pinning and locking from drm_gem_vram_vmap() Thomas Zimmermann
2020-11-30 12:04 ` [PATCH 7/8] drm/vram-helper: Remove vmap reference counting Thomas Zimmermann
2020-11-30 12:04 ` [PATCH 8/8] drm/vram-helper: Simplify vmap implementation Thomas Zimmermann
2020-11-30 12:27 ` [PATCH 0/8] drm/vram-helper: Lock GEM BOs while they are mapped Christian König
2020-11-30 12:45 ` Thomas Zimmermann

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20201130120433.7205-4-tzimmermann@suse.de \
    --to=tzimmermann@suse.de \
    --cc=airlied@redhat.com \
    --cc=christian.koenig@amd.com \
    --cc=daniel@ffwll.ch \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=hdegoede@redhat.com \
    --cc=maarten.lankhorst@linux.intel.com \
    --cc=mripard@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).