From 3080b838158f1b17bd806c3fd7b9086ba3054a04 Mon Sep 17 00:00:00 2001 From: Rob Clark Date: Thu, 17 May 2012 02:37:26 -0600 Subject: staging: drm/omap: initial dmabuf/prime import support This adds support to re-import omapdrm's own buffers. Importing buffers allocated by other drivers can be added later, but for now is not needed (we don't yet have any other exportering drivers to test with). Signed-off-by: Rob Clark Signed-off-by: Greg Kroah-Hartman --- drivers/staging/omapdrm/omap_drv.c | 2 ++ drivers/staging/omapdrm/omap_drv.h | 2 ++ drivers/staging/omapdrm/omap_gem_dmabuf.c | 22 ++++++++++++++++++++++ 3 files changed, 26 insertions(+) (limited to 'drivers/staging') diff --git a/drivers/staging/omapdrm/omap_drv.c b/drivers/staging/omapdrm/omap_drv.c index 1f559f445a3..0d2acca376c 100644 --- a/drivers/staging/omapdrm/omap_drv.c +++ b/drivers/staging/omapdrm/omap_drv.c @@ -767,7 +767,9 @@ static struct drm_driver omap_drm_driver = { .debugfs_cleanup = omap_debugfs_cleanup, #endif .prime_handle_to_fd = drm_gem_prime_handle_to_fd, + .prime_fd_to_handle = drm_gem_prime_fd_to_handle, .gem_prime_export = omap_gem_prime_export, + .gem_prime_import = omap_gem_prime_import, .gem_init_object = omap_gem_init_object, .gem_free_object = omap_gem_free_object, .gem_vm_ops = &omap_gem_vm_ops, diff --git a/drivers/staging/omapdrm/omap_drv.h b/drivers/staging/omapdrm/omap_drv.h index 73a606e72e4..f238d574da0 100644 --- a/drivers/staging/omapdrm/omap_drv.h +++ b/drivers/staging/omapdrm/omap_drv.h @@ -162,6 +162,8 @@ size_t omap_gem_mmap_size(struct drm_gem_object *obj); struct dma_buf * omap_gem_prime_export(struct drm_device *dev, struct drm_gem_object *obj, int flags); +struct drm_gem_object * omap_gem_prime_import(struct drm_device *dev, + struct dma_buf *buffer); static inline int align_pitch(int pitch, int width, int bpp) { diff --git a/drivers/staging/omapdrm/omap_gem_dmabuf.c b/drivers/staging/omapdrm/omap_gem_dmabuf.c index aba4b342493..42728e0cc19 100644 --- a/drivers/staging/omapdrm/omap_gem_dmabuf.c +++ b/drivers/staging/omapdrm/omap_gem_dmabuf.c @@ -196,3 +196,25 @@ struct dma_buf * omap_gem_prime_export(struct drm_device *dev, { return dma_buf_export(obj, &omap_dmabuf_ops, obj->size, 0600); } + +struct drm_gem_object * omap_gem_prime_import(struct drm_device *dev, + struct dma_buf *buffer) +{ + struct drm_gem_object *obj; + + /* is this one of own objects? */ + if (buffer->ops == &omap_dmabuf_ops) { + obj = buffer->priv; + /* is it from our device? */ + if (obj->dev == dev) { + drm_gem_object_reference(obj); + return obj; + } + } + + /* + * TODO add support for importing buffers from other devices.. + * for now we don't need this but would be nice to add eventually + */ + return ERR_PTR(-EINVAL); +} -- cgit v1.2.3-70-g09d2