From: Matthew Auld <matthew.auld@intel.com>
To: igt-dev@lists.freedesktop.org
Cc: "Thomas Hellström" <thomas.hellstrom@linux.intel.com>,
"Sanjay Yadav" <sanjay.kumar.yadav@intel.com>
Subject: [PATCH i-g-t v2 1/2] lib/ioct_wrappers: add __prime_fd_to_handle()
Date: Mon, 3 Nov 2025 13:12:45 +0000 [thread overview]
Message-ID: <20251103131244.28703-3-matthew.auld@intel.com> (raw)
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
next reply other threads:[~2025-11-03 13:13 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-03 13:12 Matthew Auld [this message]
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
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=20251103131244.28703-3-matthew.auld@intel.com \
--to=matthew.auld@intel.com \
--cc=igt-dev@lists.freedesktop.org \
--cc=sanjay.kumar.yadav@intel.com \
--cc=thomas.hellstrom@linux.intel.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