Igt-dev Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH i-g-t v2 1/2] lib/ioct_wrappers: add __prime_fd_to_handle()
@ 2025-11-03 13:12 Matthew Auld
  2025-11-03 13:12 ` [PATCH i-g-t v2 2/2] tests/intel/xe_peer2peer: gracefully handle ENOSUP Matthew Auld
                   ` (5 more replies)
  0 siblings, 6 replies; 8+ messages in thread
From: Matthew Auld @ 2025-11-03 13:12 UTC (permalink / raw)
  To: igt-dev; +Cc: Thomas Hellström, Sanjay Yadav

We want to be able to intercept the error, if there is one, instead of
always asserting a non-zero error. Add a version of prime_fd_to_handle()
which allows to caller to handle the error.

v2:
  - Ensure we use errno.

Signed-off-by: Matthew Auld <matthew.auld@intel.com>
Cc: Thomas Hellström <thomas.hellstrom@linux.intel.com>
Cc: Sanjay Yadav <sanjay.kumar.yadav@intel.com>
---
 lib/ioctl_wrappers.c | 27 +++++++++++++++++++++++++++
 lib/ioctl_wrappers.h |  1 +
 2 files changed, 28 insertions(+)

diff --git a/lib/ioctl_wrappers.c b/lib/ioctl_wrappers.c
index 176cbdacc..e5b60951e 100644
--- a/lib/ioctl_wrappers.c
+++ b/lib/ioctl_wrappers.c
@@ -1139,6 +1139,33 @@ int prime_handle_to_fd_for_mmap(int fd, uint32_t handle)
 	return args.fd;
 }
 
+/**
+ * __prime_fd_to_handle:
+ * @fd: open i915 drm file descriptor
+ * @dma_buf_fd: dma-buf fd handle
+ * @handle: output handle
+ *
+ * This wraps the PRIME_FD_TO_HANDLE ioctl, which is used to import a dma-buf
+ * file-descriptor into a gem buffer object.
+ *
+ * Returns: Zero one succeess, error code otherwise
+ */
+int __prime_fd_to_handle(int fd, int dma_buf_fd, uint32_t *handle)
+{
+	struct drm_prime_handle args;
+
+	memset(&args, 0, sizeof(args));
+	args.fd = dma_buf_fd;
+	args.flags = 0;
+	args.handle = 0;
+
+	if (igt_ioctl(fd, DRM_IOCTL_PRIME_FD_TO_HANDLE, &args))
+		return -errno;
+
+	*handle = args.handle;
+	return 0;
+}
+
 /**
  * prime_fd_to_handle:
  * @fd: open i915 drm file descriptor
diff --git a/lib/ioctl_wrappers.h b/lib/ioctl_wrappers.h
index 7cf05e626..5a899f052 100644
--- a/lib/ioctl_wrappers.h
+++ b/lib/ioctl_wrappers.h
@@ -138,6 +138,7 @@ int prime_handle_to_fd(int fd, uint32_t handle);
 #endif
 int prime_handle_to_fd_for_mmap(int fd, uint32_t handle);
 uint32_t prime_fd_to_handle(int fd, int dma_buf_fd);
+int __prime_fd_to_handle(int fd, int dma_buf_fd, uint32_t *handle);
 off_t prime_get_size(int dma_buf_fd);
 void prime_sync_start(int dma_buf_fd, bool write);
 void prime_sync_end(int dma_buf_fd, bool write);
-- 
2.51.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2025-11-04 14:13 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-11-03 13:12 [PATCH i-g-t v2 1/2] lib/ioct_wrappers: add __prime_fd_to_handle() Matthew Auld
2025-11-03 13:12 ` [PATCH i-g-t v2 2/2] tests/intel/xe_peer2peer: gracefully handle ENOSUP Matthew Auld
2025-11-04 11:39   ` Kamil Konieczny
2025-11-04  0:44 ` ✓ i915.CI.BAT: success for series starting with [i-g-t,v2,1/2] lib/ioct_wrappers: add __prime_fd_to_handle() Patchwork
2025-11-04  1:15 ` ✗ Xe.CI.BAT: failure " Patchwork
2025-11-04 11:00 ` [PATCH i-g-t v2 1/2] " Kamil Konieczny
2025-11-04 12:43 ` ✗ i915.CI.Full: failure for series starting with [i-g-t,v2,1/2] " Patchwork
2025-11-04 14:13 ` ✗ Xe.CI.Full: " Patchwork

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox