From f00efc7ab442f106d3ac7699e80f1f7aee8451f4 Mon Sep 17 00:00:00 2001 From: Rob Clark Date: Wed, 11 Apr 2012 09:51:36 -0500 Subject: [PATCH] omap: add dmabuf support Signed-off-by: Rob Clark --- omap/omap_drm.c | 21 +++++++++++++++++++++ omap/omap_drmif.h | 1 + 2 files changed, 22 insertions(+) diff --git a/omap/omap_drm.c b/omap/omap_drm.c index 96e18717..336da115 100644 --- a/omap/omap_drm.c +++ b/omap/omap_drm.c @@ -34,6 +34,7 @@ #include #include #include +#include #include @@ -56,6 +57,7 @@ struct omap_bo { uint32_t handle; uint32_t name; /* flink global handle (DRI2 name) */ uint64_t offset; /* offset to mmap() */ + int fd; /* dmabuf handle */ }; struct omap_device * omap_device_new(int fd) @@ -264,6 +266,25 @@ uint32_t omap_bo_handle(struct omap_bo *bo) return bo->handle; } +int omap_bo_dmabuf(struct omap_bo *bo) +{ + if (!bo->fd) { + struct drm_prime_handle req = { + .handle = bo->handle, + .flags = DRM_CLOEXEC, + }; + int ret; + + ret = drmIoctl(bo->dev->fd, DRM_IOCTL_PRIME_HANDLE_TO_FD, &req); + if (ret) { + return ret; + } + + bo->fd = req.fd; + } + return bo->fd; +} + uint32_t omap_bo_size(struct omap_bo *bo) { if (!bo->size) { diff --git a/omap/omap_drmif.h b/omap/omap_drmif.h index eb75a80a..1e03eee1 100644 --- a/omap/omap_drmif.h +++ b/omap/omap_drmif.h @@ -53,6 +53,7 @@ struct omap_bo * omap_bo_from_name(struct omap_device *dev, uint32_t name); void omap_bo_del(struct omap_bo *bo); int omap_bo_get_name(struct omap_bo *bo, uint32_t *name); uint32_t omap_bo_handle(struct omap_bo *bo); +int omap_bo_dmabuf(struct omap_bo *bo); uint32_t omap_bo_size(struct omap_bo *bo); void * omap_bo_map(struct omap_bo *bo); int omap_bo_cpu_prep(struct omap_bo *bo, enum omap_gem_op op);