From cc0a14575d9fd0aafe73cb4aa445eaf024436114 Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Sat, 14 Jul 2012 09:52:17 +0000 Subject: [PATCH] libdrm: add prime fd->handle and handle->fd interfaces These are just basic ioctl wrappers around the prime ioctls, along with the capability reporting. Reviewed-by: Alex Deucher Signed-off-by: Dave Airlie --- include/drm/drm.h | 10 +++++++--- xf86drm.c | 31 +++++++++++++++++++++++++++++++ xf86drm.h | 3 +++ 3 files changed, 41 insertions(+), 3 deletions(-) diff --git a/include/drm/drm.h b/include/drm/drm.h index 42133bce..a847689f 100644 --- a/include/drm/drm.h +++ b/include/drm/drm.h @@ -685,6 +685,9 @@ struct drm_prime_handle { #define DRM_IOCTL_UNLOCK DRM_IOW( 0x2b, struct drm_lock) #define DRM_IOCTL_FINISH DRM_IOW( 0x2c, struct drm_lock) +#define DRM_IOCTL_PRIME_HANDLE_TO_FD DRM_IOWR(0x2d, struct drm_prime_handle) +#define DRM_IOCTL_PRIME_FD_TO_HANDLE DRM_IOWR(0x2e, struct drm_prime_handle) + #define DRM_IOCTL_AGP_ACQUIRE DRM_IO( 0x30) #define DRM_IOCTL_AGP_RELEASE DRM_IO( 0x31) #define DRM_IOCTL_AGP_ENABLE DRM_IOW( 0x32, struct drm_agp_mode) @@ -697,9 +700,6 @@ struct drm_prime_handle { #define DRM_IOCTL_SG_ALLOC DRM_IOWR(0x38, struct drm_scatter_gather) #define DRM_IOCTL_SG_FREE DRM_IOW( 0x39, struct drm_scatter_gather) -#define DRM_IOCTL_PRIME_HANDLE_TO_FD DRM_IOWR(0x2d, struct drm_prime_handle) -#define DRM_IOCTL_PRIME_FD_TO_HANDLE DRM_IOWR(0x2e, struct drm_prime_handle) - #define DRM_IOCTL_WAIT_VBLANK DRM_IOWR(0x3a, union drm_wait_vblank) #define DRM_IOCTL_UPDATE_DRAW DRM_IOW(0x3f, struct drm_update_draw) @@ -778,6 +778,10 @@ struct drm_event_vblank { #define DRM_CAP_VBLANK_HIGH_CRTC 0x2 #define DRM_CAP_DUMB_PREFERRED_DEPTH 0x3 #define DRM_CAP_DUMB_PREFER_SHADOW 0x4 +#define DRM_CAP_PRIME 0x5 + +#define DRM_PRIME_CAP_IMPORT 0x1 +#define DRM_PRIME_CAP_EXPORT 0x2 /* typedef area */ typedef struct drm_clip_rect drm_clip_rect_t; diff --git a/xf86drm.c b/xf86drm.c index 6ea068f4..2a74c807 100644 --- a/xf86drm.c +++ b/xf86drm.c @@ -2542,3 +2542,34 @@ char *drmGetDeviceNameFromFd(int fd) return strdup(name); } + +int drmPrimeHandleToFD(int fd, uint32_t handle, uint32_t flags, int *prime_fd) +{ + struct drm_prime_handle args; + int ret; + + args.handle = handle; + args.flags = flags; + ret = drmIoctl(fd, DRM_IOCTL_PRIME_HANDLE_TO_FD, &args); + if (ret) + return ret; + + *prime_fd = args.fd; + return 0; +} + +int drmPrimeFDToHandle(int fd, int prime_fd, uint32_t *handle) +{ + struct drm_prime_handle args; + int ret; + + args.fd = prime_fd; + args.flags = 0; + ret = drmIoctl(fd, DRM_IOCTL_PRIME_FD_TO_HANDLE, &args); + if (ret) + return ret; + + *handle = args.handle; + return 0; +} + diff --git a/xf86drm.h b/xf86drm.h index 76eb94e2..5ecb2846 100644 --- a/xf86drm.h +++ b/xf86drm.h @@ -727,6 +727,9 @@ extern int drmHandleEvent(int fd, drmEventContextPtr evctx); extern char *drmGetDeviceNameFromFd(int fd); +extern int drmPrimeHandleToFD(int fd, uint32_t handle, uint32_t flags, int *prime_fd); +extern int drmPrimeFDToHandle(int fd, int prime_fd, uint32_t *handle); + #if defined(__cplusplus) || defined(c_plusplus) } #endif