dri-devel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Thomas Zimmermann <tzimmermann@suse.de>
To: kraxel@redhat.com, airlied@redhat.com, daniel@ffwll.ch,
	maarten.lankhorst@linux.intel.com, maxime.ripard@bootlin.com,
	sean@poorly.run, sam@ravnborg.org,
	dri-devel@lists.freedesktop.org, z.liuxinliang@hisilicon.com,
	zourongrong@gmail.com, kong.kongxinwei@hisilicon.com,
	puck.chen@hisilicon.com
Cc: Thomas Zimmermann <tzimmermann@suse.de>
Subject: [PATCH 1/4] drm/vram: Set GEM object functions for PRIME
Date: Fri, 28 Jun 2019 14:26:56 +0200	[thread overview]
Message-ID: <20190628122659.31887-2-tzimmermann@suse.de> (raw)
In-Reply-To: <20190628122659.31887-1-tzimmermann@suse.de>

PRIME functionality is now provided via the callback functions in
struct drm_gem_object_funcs. The driver-structure functions are obsolete.
As a side effect of this patch, VRAM-based drivers get basic PRIME
support automatically without having to set any flags or additional
fields.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/gpu/drm/drm_gem_vram_helper.c | 70 +++++++++++++++++++++++++++
 include/drm/drm_gem_vram_helper.h     |  3 +-
 2 files changed, 72 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/drm_gem_vram_helper.c b/drivers/gpu/drm/drm_gem_vram_helper.c
index 4de782ca26b2..dd220795e725 100644
--- a/drivers/gpu/drm/drm_gem_vram_helper.c
+++ b/drivers/gpu/drm/drm_gem_vram_helper.c
@@ -14,6 +14,73 @@
  * (VRAM). It can be used for framebuffer devices with dedicated memory.
  */
 
+/*
+ * GEM object funcs
+ */
+
+static void drm_gem_vram_object_free(struct drm_gem_object *gem)
+{
+	struct drm_gem_vram_object *gbo = drm_gem_vram_of_gem(gem);
+
+	drm_gem_vram_put(gbo);
+}
+
+static int drm_gem_vram_object_funcs_pin(struct drm_gem_object *gem)
+{
+	struct drm_gem_vram_object *gbo = drm_gem_vram_of_gem(gem);
+
+	/* Fbdev console emulation is the use case of these PRIME
+	 * helpers. This may involve updating a hardware buffer from
+	 * a shadow FB. We pin the buffer to it's current location
+	 * (either video RAM or system memory) to prevent it from
+	 * being relocated during the update operation. If you require
+	 * the buffer to be pinned to VRAM, implement a callback that
+	 * sets the flags accordingly.
+	 */
+	return drm_gem_vram_pin(gbo, 0);
+}
+
+static void drm_gem_vram_object_funcs_unpin(struct drm_gem_object *gem)
+{
+	struct drm_gem_vram_object *gbo = drm_gem_vram_of_gem(gem);
+
+	drm_gem_vram_unpin(gbo);
+}
+
+static void *drm_gem_vram_object_funcs_vmap(struct drm_gem_object *gem)
+{
+	struct drm_gem_vram_object *gbo = drm_gem_vram_of_gem(gem);
+	int ret;
+	void *base;
+
+	ret = drm_gem_vram_pin(gbo, 0);
+	if (ret)
+		return NULL;
+	base = drm_gem_vram_kmap(gbo, true, NULL);
+	if (IS_ERR(base)) {
+		drm_gem_vram_unpin(gbo);
+		return NULL;
+	}
+	return base;
+}
+
+static void drm_gem_vram_object_funcs_vunmap(struct drm_gem_object *gem,
+					     void *vaddr)
+{
+	struct drm_gem_vram_object *gbo = drm_gem_vram_of_gem(gem);
+
+	drm_gem_vram_kunmap(gbo);
+	drm_gem_vram_unpin(gbo);
+}
+
+static const struct drm_gem_object_funcs drm_gem_vram_object_funcs = {
+	.free	= drm_gem_vram_object_free,
+	.pin	= drm_gem_vram_object_funcs_pin,
+	.unpin	= drm_gem_vram_object_funcs_unpin,
+	.vmap	= drm_gem_vram_object_funcs_vmap,
+	.vunmap	= drm_gem_vram_object_funcs_vunmap
+};
+
 /*
  * Buffer-objects helpers
  */
@@ -80,6 +147,9 @@ static int drm_gem_vram_init(struct drm_device *dev,
 	int ret;
 	size_t acc_size;
 
+	if (!gbo->gem.funcs)
+		gbo->gem.funcs = &drm_gem_vram_object_funcs;
+
 	ret = drm_gem_object_init(dev, &gbo->gem, size);
 	if (ret)
 		return ret;
diff --git a/include/drm/drm_gem_vram_helper.h b/include/drm/drm_gem_vram_helper.h
index 1a0ea18e7a74..bc8fe9feee3b 100644
--- a/include/drm/drm_gem_vram_helper.h
+++ b/include/drm/drm_gem_vram_helper.h
@@ -127,7 +127,8 @@ int drm_gem_vram_driver_dumb_mmap_offset(struct drm_file *file,
 	.gem_free_object_unlocked = \
 		drm_gem_vram_driver_gem_free_object_unlocked, \
 	.dumb_create		  = drm_gem_vram_driver_dumb_create, \
-	.dumb_map_offset	  = drm_gem_vram_driver_dumb_mmap_offset
+	.dumb_map_offset	  = drm_gem_vram_driver_dumb_mmap_offset, \
+	.gem_prime_mmap		  = drm_gem_prime_mmap
 
 /*
  * PRIME helpers for struct drm_driver
-- 
2.21.0

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

  reply	other threads:[~2019-06-28 12:27 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-06-28 12:26 [PATCH 0/4] Convert VRAM helpers to GEM object functions Thomas Zimmermann
2019-06-28 12:26 ` Thomas Zimmermann [this message]
2019-07-01  6:32   ` [PATCH 1/4] drm/vram: Set GEM object functions for PRIME Gerd Hoffmann
2019-07-01  7:28     ` Thomas Zimmermann
2019-07-01  8:48       ` Gerd Hoffmann
2019-07-01 14:45         ` Thomas Zimmermann
2019-07-02  5:44           ` Gerd Hoffmann
2019-06-28 12:26 ` [PATCH 2/4] drm/bochs: Remove PRIME helpers from driver structure Thomas Zimmermann
2019-06-28 12:26 ` [PATCH 3/4] drm/hibmc: Leave struct drm_driver.gem_free_object_unlocked to NULL Thomas Zimmermann
2019-06-28 16:55   ` Daniel Vetter
2019-07-02  8:03     ` Thomas Zimmermann
2019-06-28 12:26 ` [PATCH 4/4] drm/vram: Remove driver callback functions for PRIME 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=20190628122659.31887-2-tzimmermann@suse.de \
    --to=tzimmermann@suse.de \
    --cc=airlied@redhat.com \
    --cc=daniel@ffwll.ch \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=kong.kongxinwei@hisilicon.com \
    --cc=kraxel@redhat.com \
    --cc=maarten.lankhorst@linux.intel.com \
    --cc=maxime.ripard@bootlin.com \
    --cc=puck.chen@hisilicon.com \
    --cc=sam@ravnborg.org \
    --cc=sean@poorly.run \
    --cc=z.liuxinliang@hisilicon.com \
    --cc=zourongrong@gmail.com \
    /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