crocus: Use intel_ioctl() consistently

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 <jose.souza@intel.com>
Reviewed-by: José Roberto de Souza <jose.souza@intel.com>
Acked-by: Alyssa Rosenzweig <alyssa.rosenzweig@intel.com>
Signed-off-by: Dmitry Osipenko <dmitry.osipenko@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/29870>
This commit is contained in:
Dmitry Osipenko 2026-01-18 01:03:56 +03:00 committed by Marge Bot
parent 7aa0917626
commit 335d142dad

View file

@ -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);