Commit 102d6dba authored by Maarten Lankhorst's avatar Maarten Lankhorst Committed by Dave Airlie

drm: add unpin function to prime helpers

Prevents buffers from being pinned forever.
Signed-off-by: default avatarMaarten Lankhorst <maarten.lankhorst@canonical.com>
Reviewed-by: default avatarDaniel Vetter <daniel.vetter@ffwll.ch>
Signed-off-by: default avatarDave Airlie <airlied@redhat.com>
parent 328a4719
...@@ -92,10 +92,13 @@ static void drm_gem_unmap_dma_buf(struct dma_buf_attachment *attach, ...@@ -92,10 +92,13 @@ static void drm_gem_unmap_dma_buf(struct dma_buf_attachment *attach,
static void drm_gem_dmabuf_release(struct dma_buf *dma_buf) static void drm_gem_dmabuf_release(struct dma_buf *dma_buf)
{ {
struct drm_gem_object *obj = dma_buf->priv; struct drm_gem_object *obj = dma_buf->priv;
struct drm_device *dev = obj->dev;
if (obj->export_dma_buf == dma_buf) { if (obj->export_dma_buf == dma_buf) {
/* drop the reference on the export fd holds */ /* drop the reference on the export fd holds */
obj->export_dma_buf = NULL; obj->export_dma_buf = NULL;
if (dev->driver->gem_prime_unpin)
dev->driver->gem_prime_unpin(obj);
drm_gem_object_unreference_unlocked(obj); drm_gem_object_unreference_unlocked(obj);
} }
} }
...@@ -185,13 +188,19 @@ static const struct dma_buf_ops drm_gem_prime_dmabuf_ops = { ...@@ -185,13 +188,19 @@ static const struct dma_buf_ops drm_gem_prime_dmabuf_ops = {
struct dma_buf *drm_gem_prime_export(struct drm_device *dev, struct dma_buf *drm_gem_prime_export(struct drm_device *dev,
struct drm_gem_object *obj, int flags) struct drm_gem_object *obj, int flags)
{ {
struct dma_buf *buf;
if (dev->driver->gem_prime_pin) { if (dev->driver->gem_prime_pin) {
int ret = dev->driver->gem_prime_pin(obj); int ret = dev->driver->gem_prime_pin(obj);
if (ret) if (ret)
return ERR_PTR(ret); return ERR_PTR(ret);
} }
return dma_buf_export(obj, &drm_gem_prime_dmabuf_ops, obj->size, buf = dma_buf_export(obj, &drm_gem_prime_dmabuf_ops, obj->size,
0600); 0600);
if (IS_ERR(buf) && dev->driver->gem_prime_unpin)
dev->driver->gem_prime_unpin(obj);
return buf;
} }
EXPORT_SYMBOL(drm_gem_prime_export); EXPORT_SYMBOL(drm_gem_prime_export);
......
...@@ -930,6 +930,7 @@ struct drm_driver { ...@@ -930,6 +930,7 @@ struct drm_driver {
struct dma_buf *dma_buf); struct dma_buf *dma_buf);
/* low-level interface used by drm_gem_prime_{import,export} */ /* low-level interface used by drm_gem_prime_{import,export} */
int (*gem_prime_pin)(struct drm_gem_object *obj); int (*gem_prime_pin)(struct drm_gem_object *obj);
void (*gem_prime_unpin)(struct drm_gem_object *obj);
struct sg_table *(*gem_prime_get_sg_table)(struct drm_gem_object *obj); struct sg_table *(*gem_prime_get_sg_table)(struct drm_gem_object *obj);
struct drm_gem_object *(*gem_prime_import_sg_table)( struct drm_gem_object *(*gem_prime_import_sg_table)(
struct drm_device *dev, size_t size, struct drm_device *dev, size_t size,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment