summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRob Clark <rob@ti.com>2012-06-11 17:17:17 -0500
committerRob Clark <rob@ti.com>2012-07-13 16:16:46 -0500
commit42f8a68e19ba48a25f5eca2778d997f3d1ad094d (patch)
tree6c824e1d3093ac2afddecdef17285f08145dee78
parent8116a32df613df4433aa1b128c58bf2c18479824 (diff)
downloadlibdrm-42f8a68e19ba48a25f5eca2778d997f3d1ad094d.tar.gz
libdrm-42f8a68e19ba48a25f5eca2778d997f3d1ad094d.tar.bz2
libdrm-42f8a68e19ba48a25f5eca2778d997f3d1ad094d.zip
omap: add API to import bo's from dmabuf fd's
Signed-off-by: Rob Clark <rob@ti.com>
-rw-r--r--omap/omap_drm.c32
-rw-r--r--omap/omap_drmif.h1
2 files changed, 33 insertions, 0 deletions
diff --git a/omap/omap_drm.c b/omap/omap_drm.c
index 464dea9c..1d37e451 100644
--- a/omap/omap_drm.c
+++ b/omap/omap_drm.c
@@ -218,6 +218,38 @@ fail:
return NULL;
}
+/* import a buffer from dmabuf fd, does not take ownership of the
+ * fd so caller should close() the fd when it is otherwise done
+ * with it (even if it is still using the 'struct omap_bo *')
+ */
+struct omap_bo * omap_bo_from_dmabuf(struct omap_device *dev, int fd)
+{
+ struct omap_bo *bo;
+ struct drm_prime_handle req = {
+ .fd = fd,
+ };
+ int ret;
+
+ bo = calloc(sizeof(*bo), 1);
+ if (!bo) {
+ goto fail;
+ }
+
+ ret = drmIoctl(dev->fd, DRM_IOCTL_PRIME_FD_TO_HANDLE, &req);
+ if (ret) {
+ goto fail;
+ }
+
+ bo->dev = dev;
+ bo->handle = req.handle;
+
+ return bo;
+
+fail:
+ free(bo);
+ return NULL;
+}
+
/* destroy a buffer object */
void omap_bo_del(struct omap_bo *bo)
{
diff --git a/omap/omap_drmif.h b/omap/omap_drmif.h
index 1e03eee1..284b9ccc 100644
--- a/omap/omap_drmif.h
+++ b/omap/omap_drmif.h
@@ -50,6 +50,7 @@ struct omap_bo * omap_bo_new(struct omap_device *dev,
struct omap_bo * omap_bo_new_tiled(struct omap_device *dev,
uint32_t width, uint32_t height, uint32_t flags);
struct omap_bo * omap_bo_from_name(struct omap_device *dev, uint32_t name);
+struct omap_bo * omap_bo_from_dmabuf(struct omap_device *dev, int fd);
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);