public inbox for intel-gfx@lists.freedesktop.org
 help / color / mirror / Atom feed
From: Tvrtko Ursulin <tvrtko.ursulin@linux.intel.com>
To: Intel-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org
Subject: [Intel-gfx] [PATCH 6/8] drm: Add drm_gem_prime_fd_to_handle_obj
Date: Fri,  9 Jun 2023 13:11:41 +0100	[thread overview]
Message-ID: <20230609121143.1232420-7-tvrtko.ursulin@linux.intel.com> (raw)
In-Reply-To: <20230609121143.1232420-1-tvrtko.ursulin@linux.intel.com>

From: Tvrtko Ursulin <tvrtko.ursulin@intel.com>

I need a new flavour of the drm_gem_prime_fd_to_handle helper, one which
will return a reference to a newly created GEM objects (if created), in
order to enable tracking of imported i915 GEM objects in the following
patch.

Minor code reshuffule and only trivial additions on top of
drm_gem_prime_fd_to_handle.

Signed-off-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
---
 drivers/gpu/drm/drm_prime.c | 41 ++++++++++++++++++++++++++++++++-----
 include/drm/drm_prime.h     |  4 ++++
 2 files changed, 40 insertions(+), 5 deletions(-)

diff --git a/drivers/gpu/drm/drm_prime.c b/drivers/gpu/drm/drm_prime.c
index d29dafce9bb0..ef75f67e3057 100644
--- a/drivers/gpu/drm/drm_prime.c
+++ b/drivers/gpu/drm/drm_prime.c
@@ -284,11 +284,12 @@ void drm_gem_dmabuf_release(struct dma_buf *dma_buf)
 EXPORT_SYMBOL(drm_gem_dmabuf_release);
 
 /**
- * drm_gem_prime_fd_to_handle - PRIME import function for GEM drivers
+ * drm_gem_prime_fd_to_handle_obj - PRIME import function for GEM drivers
  * @dev: drm_device to import into
  * @file_priv: drm file-private structure
  * @prime_fd: fd id of the dma-buf which should be imported
  * @handle: pointer to storage for the handle of the imported buffer object
+ * @objp: optional pointer in which reference to created GEM object can be returned
  *
  * This is the PRIME import function which must be used mandatorily by GEM
  * drivers to ensure correct lifetime management of the underlying GEM object.
@@ -297,9 +298,10 @@ EXPORT_SYMBOL(drm_gem_dmabuf_release);
  *
  * Returns 0 on success or a negative error code on failure.
  */
-int drm_gem_prime_fd_to_handle(struct drm_device *dev,
-			       struct drm_file *file_priv, int prime_fd,
-			       uint32_t *handle)
+int drm_gem_prime_fd_to_handle_obj(struct drm_device *dev,
+				   struct drm_file *file_priv, int prime_fd,
+				   uint32_t *handle,
+				   struct drm_gem_object **objp)
 {
 	struct dma_buf *dma_buf;
 	struct drm_gem_object *obj;
@@ -336,7 +338,8 @@ int drm_gem_prime_fd_to_handle(struct drm_device *dev,
 
 	/* _handle_create_tail unconditionally unlocks dev->object_name_lock. */
 	ret = drm_gem_handle_create_tail(file_priv, obj, handle);
-	drm_gem_object_put(obj);
+	if (!objp)
+		drm_gem_object_put(obj);
 	if (ret)
 		goto out_put;
 
@@ -348,6 +351,9 @@ int drm_gem_prime_fd_to_handle(struct drm_device *dev,
 
 	dma_buf_put(dma_buf);
 
+	if (objp)
+		*objp = obj;
+
 	return 0;
 
 fail:
@@ -356,6 +362,8 @@ int drm_gem_prime_fd_to_handle(struct drm_device *dev,
 	 */
 	drm_gem_handle_delete(file_priv, *handle);
 	dma_buf_put(dma_buf);
+	if (objp)
+		drm_gem_object_put(obj);
 	return ret;
 
 out_unlock:
@@ -365,6 +373,29 @@ int drm_gem_prime_fd_to_handle(struct drm_device *dev,
 	dma_buf_put(dma_buf);
 	return ret;
 }
+EXPORT_SYMBOL(drm_gem_prime_fd_to_handle_obj);
+
+/**
+ * drm_gem_prime_fd_to_handle - PRIME import function for GEM drivers
+ * @dev: drm_device to import into
+ * @file_priv: drm file-private structure
+ * @prime_fd: fd id of the dma-buf which should be imported
+ * @handle: pointer to storage for the handle of the imported buffer object
+ *
+ * This is the PRIME import function which must be used mandatorily by GEM
+ * drivers to ensure correct lifetime management of the underlying GEM object.
+ * The actual importing of GEM object from the dma-buf is done through the
+ * &drm_driver.gem_prime_import driver callback.
+ *
+ * Returns 0 on success or a negative error code on failure.
+ */
+int drm_gem_prime_fd_to_handle(struct drm_device *dev,
+			       struct drm_file *file_priv, int prime_fd,
+			       uint32_t *handle)
+{
+	return drm_gem_prime_fd_to_handle_obj(dev, file_priv, prime_fd, handle,
+					      NULL);
+}
 EXPORT_SYMBOL(drm_gem_prime_fd_to_handle);
 
 int drm_prime_fd_to_handle_ioctl(struct drm_device *dev, void *data,
diff --git a/include/drm/drm_prime.h b/include/drm/drm_prime.h
index 2a1d01e5b56b..10d145ce6586 100644
--- a/include/drm/drm_prime.h
+++ b/include/drm/drm_prime.h
@@ -69,6 +69,10 @@ void drm_gem_dmabuf_release(struct dma_buf *dma_buf);
 
 int drm_gem_prime_fd_to_handle(struct drm_device *dev,
 			       struct drm_file *file_priv, int prime_fd, uint32_t *handle);
+int drm_gem_prime_fd_to_handle_obj(struct drm_device *dev,
+				   struct drm_file *file_priv, int prime_fd,
+				   uint32_t *handle,
+				   struct drm_gem_object **obj);
 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);
-- 
2.39.2


  parent reply	other threads:[~2023-06-09 12:12 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-09 12:11 [Intel-gfx] [PATCH v3 0/8] fdinfo memory stats Tvrtko Ursulin
2023-06-09 12:11 ` [Intel-gfx] [PATCH 1/8] dma-fence: Bypass signaling annotation from dma_fence_is_signaled Tvrtko Ursulin
2023-06-09 12:11 ` [Intel-gfx] [PATCH 2/8] drm/i915: Track buffer objects belonging to clients Tvrtko Ursulin
2023-06-09 12:11 ` [Intel-gfx] [PATCH 3/8] drm/i915: Record which clients own a VM Tvrtko Ursulin
2023-06-09 12:11 ` [Intel-gfx] [PATCH 4/8] drm/i915: Track page table backing store usage Tvrtko Ursulin
2023-06-09 12:11 ` [Intel-gfx] [PATCH 5/8] drm/i915: Account ring buffer and context state storage Tvrtko Ursulin
2023-06-09 12:11 ` Tvrtko Ursulin [this message]
2023-06-09 12:44   ` [Intel-gfx] [PATCH 6/8] drm: Add drm_gem_prime_fd_to_handle_obj Iddamsetty, Aravind
2023-06-09 14:12     ` Tvrtko Ursulin
2023-06-09 17:09       ` Rob Clark
2023-06-12  8:26         ` Tvrtko Ursulin
2023-06-09 12:11 ` [Intel-gfx] [PATCH 7/8] drm/i915: Track imported dma-buf objects in memory stats Tvrtko Ursulin
2023-06-09 12:11 ` [Intel-gfx] [PATCH 8/8] drm/i915: Implement fdinfo memory stats printing Tvrtko Ursulin
2023-06-09 12:48 ` [Intel-gfx] ✗ Fi.CI.CHECKPATCH: warning for fdinfo memory stats (rev2) Patchwork
2023-06-09 12:48 ` [Intel-gfx] ✗ Fi.CI.SPARSE: " Patchwork
2023-06-09 17:47 ` [Intel-gfx] ✗ Fi.CI.BAT: failure " 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=20230609121143.1232420-7-tvrtko.ursulin@linux.intel.com \
    --to=tvrtko.ursulin@linux.intel.com \
    --cc=Intel-gfx@lists.freedesktop.org \
    --cc=dri-devel@lists.freedesktop.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