From: "Noralf Trønnes" <noralf@tronnes.org>
To: dri-devel@lists.freedesktop.org
Cc: intel-gfx@lists.freedesktop.org, sam@ravnborg.org, david@lechnology.com
Subject: [PATCH v5 2/5] drm/prime: Add drm_gem_prime_mmap()
Date: Wed, 17 Oct 2018 15:04:51 +0200 [thread overview]
Message-ID: <20181017130454.44292-3-noralf@tronnes.org> (raw)
In-Reply-To: <20181017130454.44292-1-noralf@tronnes.org>
Add a generic PRIME GEM mmap function.
Suggested-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Signed-off-by: Noralf Trønnes <noralf@tronnes.org>
---
drivers/gpu/drm/drm_prime.c | 37 +++++++++++++++++++++++++++++++++++++
include/drm/drm_prime.h | 1 +
2 files changed, 38 insertions(+)
diff --git a/drivers/gpu/drm/drm_prime.c b/drivers/gpu/drm/drm_prime.c
index ba6c7e02a2ae..42abf98c1d4a 100644
--- a/drivers/gpu/drm/drm_prime.c
+++ b/drivers/gpu/drm/drm_prime.c
@@ -651,6 +651,43 @@ int drm_gem_prime_handle_to_fd(struct drm_device *dev,
}
EXPORT_SYMBOL(drm_gem_prime_handle_to_fd);
+/**
+ * drm_gem_prime_mmap - PRIME mmap function for GEM drivers
+ * @obj: GEM object
+ * @vma: Virtual address range
+ *
+ * This function sets up a userspace mapping for PRIME exported buffers using
+ * the same codepath that is used for regular GEM buffer mapping on the DRM fd.
+ * The fake GEM offset is added to vma->vm_pgoff and &drm_driver->fops->mmap is
+ * called to set up the mapping.
+ *
+ * Drivers can use this as their &drm_driver->gem_prime_mmap callback.
+ */
+int drm_gem_prime_mmap(struct drm_gem_object *obj, struct vm_area_struct *vma)
+{
+ /* Used by drm_gem_mmap() to lookup the GEM object */
+ struct drm_file priv = {
+ .minor = obj->dev->primary,
+ };
+ struct file fil = {
+ .private_data = &priv,
+ };
+ int ret;
+
+ ret = drm_vma_node_allow(&obj->vma_node, &priv);
+ if (ret)
+ return ret;
+
+ vma->vm_pgoff += drm_vma_node_start(&obj->vma_node);
+
+ ret = obj->dev->driver->fops->mmap(&fil, vma);
+
+ drm_vma_node_revoke(&obj->vma_node, &priv);
+
+ return ret;
+}
+EXPORT_SYMBOL(drm_gem_prime_mmap);
+
/**
* drm_gem_prime_import_dev - core implementation of the import callback
* @dev: drm_device to import into
diff --git a/include/drm/drm_prime.h b/include/drm/drm_prime.h
index e2032fbc0f08..b03731a3f079 100644
--- a/include/drm/drm_prime.h
+++ b/include/drm/drm_prime.h
@@ -70,6 +70,7 @@ struct dma_buf *drm_gem_prime_export(struct drm_device *dev,
int drm_gem_prime_handle_to_fd(struct drm_device *dev,
struct drm_file *file_priv, uint32_t handle, uint32_t flags,
int *prime_fd);
+int drm_gem_prime_mmap(struct drm_gem_object *obj, struct vm_area_struct *vma);
struct drm_gem_object *drm_gem_prime_import(struct drm_device *dev,
struct dma_buf *dma_buf);
--
2.15.1
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel
next prev parent reply other threads:[~2018-10-17 13:04 UTC|newest]
Thread overview: 35+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-10-17 13:04 [PATCH v5 0/5] drm: Add shmem GEM library Noralf Trønnes
2018-10-17 13:04 ` [PATCH v5 1/5] drm/driver: Add defaults for .gem_prime_export/import callbacks Noralf Trønnes
2018-10-17 13:04 ` Noralf Trønnes [this message]
2018-10-17 15:22 ` [PATCH v5 2/5] drm/prime: Add drm_gem_prime_mmap() Daniel Vetter
2018-10-17 13:04 ` [PATCH v5 3/5] drm/gem: Add drm_gem_object_funcs Noralf Trønnes
2018-10-22 12:57 ` Christian König
2018-10-23 13:46 ` Daniel Vetter
2018-10-31 23:37 ` Noralf Trønnes
2018-11-01 8:36 ` [Intel-gfx] " Daniel Vetter
2018-10-17 13:04 ` [PATCH v5 4/5] drm: Add library for shmem backed GEM objects Noralf Trønnes
2018-10-17 15:46 ` Daniel Vetter
2018-10-22 14:15 ` Noralf Trønnes
2018-10-23 13:50 ` Daniel Vetter
2018-11-27 0:36 ` Eric Anholt
2018-11-27 8:58 ` [Intel-gfx] " Daniel Vetter
2018-11-27 20:38 ` Eric Anholt
2018-11-28 8:22 ` [Intel-gfx] " Daniel Vetter
2018-11-28 21:52 ` Eric Anholt
2018-11-29 9:17 ` Daniel Vetter
2018-11-29 23:58 ` Eric Anholt
2018-12-02 15:58 ` Noralf Trønnes
2019-01-28 20:57 ` [Intel-gfx] " Rob Herring
2019-01-28 21:22 ` Noralf Trønnes
2019-01-28 22:01 ` Rob Herring
2019-01-29 0:19 ` Eric Anholt
2019-01-29 8:44 ` [Intel-gfx] " Noralf Trønnes
2018-10-17 13:04 ` [PATCH v5 5/5] drm/tinydrm: Switch from CMA to shmem buffers Noralf Trønnes
2018-10-26 22:38 ` Noralf Trønnes
2018-10-28 20:21 ` David Lechner
2018-10-28 20:46 ` Noralf Trønnes
2018-10-29 9:07 ` Daniel Vetter
2018-10-31 18:41 ` Noralf Trønnes
2018-10-17 13:43 ` ✗ Fi.CI.CHECKPATCH: warning for drm: Add shmem GEM library Patchwork
2018-10-17 14:02 ` ✓ Fi.CI.BAT: success " Patchwork
2018-10-17 17:37 ` ✓ Fi.CI.IGT: " Patchwork
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=20181017130454.44292-3-noralf@tronnes.org \
--to=noralf@tronnes.org \
--cc=david@lechnology.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=intel-gfx@lists.freedesktop.org \
--cc=sam@ravnborg.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