From 335d142dade2f9db35fa3bcab8edd3efc2b72569 Mon Sep 17 00:00:00 2001 From: Dmitry Osipenko Date: Sun, 18 Jan 2026 01:03:56 +0300 Subject: [PATCH] crocus: Use intel_ioctl() consistently MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Prepare Crocus code for addition of virtio native context support by open-coding drm prime ioctls instead of using libdrm helpers and using the intel_ioctl() helper. This is needed by virtio to be able to override the ioctls implementation. Suggested-by: José Roberto de Souza Reviewed-by: José Roberto de Souza Acked-by: Alyssa Rosenzweig Signed-off-by: Dmitry Osipenko Part-of: --- src/gallium/drivers/crocus/crocus_bufmgr.c | 35 ++++++++++++++++++---- 1 file changed, 29 insertions(+), 6 deletions(-) diff --git a/src/gallium/drivers/crocus/crocus_bufmgr.c b/src/gallium/drivers/crocus/crocus_bufmgr.c index 041cb4ffcc3..773308d5744 100644 --- a/src/gallium/drivers/crocus/crocus_bufmgr.c +++ b/src/gallium/drivers/crocus/crocus_bufmgr.c @@ -1196,7 +1196,7 @@ bo_set_tiling_internal(struct crocus_bo *bo, uint32_t tiling_mode, set_tiling.tiling_mode = tiling_mode; set_tiling.stride = stride; - ret = ioctl(bufmgr->fd, DRM_IOCTL_I915_GEM_SET_TILING, &set_tiling); + ret = intel_ioctl(bufmgr->fd, DRM_IOCTL_I915_GEM_SET_TILING, &set_tiling); } while (ret == -1 && (errno == EINTR || errno == EAGAIN)); if (ret == -1) return -errno; @@ -1216,6 +1216,23 @@ crocus_bo_get_tiling(struct crocus_bo *bo, uint32_t *tiling_mode, return 0; } +static int +crocus_bo_prime_fd_to_handle(int fd, int prime_fd, uint32_t *handle) +{ + struct drm_prime_handle prime_arg = { + .fd = prime_fd, + }; + + *handle = 0; + + if (intel_ioctl(fd, DRM_IOCTL_PRIME_FD_TO_HANDLE, &prime_arg)) + return -errno; + + *handle = prime_arg.handle; + + return 0; +} + struct crocus_bo * crocus_bo_import_dmabuf(struct crocus_bufmgr *bufmgr, int prime_fd, uint64_t modifier) @@ -1224,7 +1241,7 @@ crocus_bo_import_dmabuf(struct crocus_bufmgr *bufmgr, int prime_fd, struct crocus_bo *bo; simple_mtx_lock(&bufmgr->lock); - int ret = drmPrimeFDToHandle(bufmgr->fd, prime_fd, &handle); + int ret = crocus_bo_prime_fd_to_handle(bufmgr->fd, prime_fd, &handle); if (ret) { DBG("import_dmabuf: failed to obtain handle from fd: %s\n", strerror(errno)); @@ -1296,7 +1313,7 @@ crocus_bo_import_dmabuf_no_mods(struct crocus_bufmgr *bufmgr, struct crocus_bo *bo; simple_mtx_lock(&bufmgr->lock); - int ret = drmPrimeFDToHandle(bufmgr->fd, prime_fd, &handle); + int ret = crocus_bo_prime_fd_to_handle(bufmgr->fd, prime_fd, &handle); if (ret) { DBG("import_dmabuf: failed to obtain handle from fd: %s\n", strerror(errno)); @@ -1373,10 +1390,16 @@ crocus_bo_export_dmabuf(struct crocus_bo *bo, int *prime_fd) crocus_bo_make_external(bo); - if (drmPrimeHandleToFD(bufmgr->fd, bo->gem_handle, - DRM_CLOEXEC | DRM_RDWR, prime_fd) != 0) + struct drm_prime_handle prime_arg = { + .handle = bo->gem_handle, + .flags = DRM_CLOEXEC | DRM_RDWR, + }; + + if (intel_ioctl(bufmgr->fd, DRM_IOCTL_PRIME_HANDLE_TO_FD, &prime_arg)) return -errno; + *prime_fd = prime_arg.fd; + return 0; } @@ -1444,7 +1467,7 @@ crocus_bo_export_gem_handle_for_device(struct crocus_bo *bo, int drm_fd, } simple_mtx_lock(&bufmgr->lock); - err = drmPrimeFDToHandle(drm_fd, dmabuf_fd, &export->gem_handle); + err = crocus_bo_prime_fd_to_handle(drm_fd, dmabuf_fd, &export->gem_handle); close(dmabuf_fd); if (err) { simple_mtx_unlock(&bufmgr->lock);