mirror of
https://github.com/hardkernel/linux.git
synced 2026-06-07 19:30:30 +09:00
drm/rocckhip: implement rockchip_drm_gem_prime_import
when import dma-buf we should compare dma_buf->ops with rockchip_drm_gem_prime_dmabuf_ops; so we implement rockchip_drm_gem_prime_import to instead of drm_gem_prime_import. Signed-off-by: Sandy Huang <hjc@rock-chips.com> Change-Id: Iab3260b5c3efb5634d411eb1e8620fb575aa063c
This commit is contained in:
@@ -564,6 +564,68 @@ static const struct dma_buf_ops rockchip_drm_gem_prime_dmabuf_ops = {
|
||||
.end_cpu_access = rockchip_drm_gem_dmabuf_end_cpu_access,
|
||||
};
|
||||
|
||||
static struct drm_gem_object *rockchip_drm_gem_prime_import_dev(struct drm_device *dev,
|
||||
struct dma_buf *dma_buf,
|
||||
struct device *attach_dev)
|
||||
{
|
||||
struct dma_buf_attachment *attach;
|
||||
struct sg_table *sgt;
|
||||
struct drm_gem_object *obj;
|
||||
int ret;
|
||||
|
||||
if (dma_buf->ops == &rockchip_drm_gem_prime_dmabuf_ops) {
|
||||
obj = dma_buf->priv;
|
||||
if (obj->dev == dev) {
|
||||
/*
|
||||
* Importing dmabuf exported from out own gem increases
|
||||
* refcount on gem itself instead of f_count of dmabuf.
|
||||
*/
|
||||
drm_gem_object_get(obj);
|
||||
return obj;
|
||||
}
|
||||
}
|
||||
|
||||
if (!dev->driver->gem_prime_import_sg_table)
|
||||
return ERR_PTR(-EINVAL);
|
||||
|
||||
attach = dma_buf_attach(dma_buf, attach_dev);
|
||||
if (IS_ERR(attach))
|
||||
return ERR_CAST(attach);
|
||||
|
||||
get_dma_buf(dma_buf);
|
||||
|
||||
sgt = dma_buf_map_attachment(attach, DMA_BIDIRECTIONAL);
|
||||
if (IS_ERR(sgt)) {
|
||||
ret = PTR_ERR(sgt);
|
||||
goto fail_detach;
|
||||
}
|
||||
|
||||
obj = dev->driver->gem_prime_import_sg_table(dev, attach, sgt);
|
||||
if (IS_ERR(obj)) {
|
||||
ret = PTR_ERR(obj);
|
||||
goto fail_unmap;
|
||||
}
|
||||
|
||||
obj->import_attach = attach;
|
||||
obj->resv = dma_buf->resv;
|
||||
|
||||
return obj;
|
||||
|
||||
fail_unmap:
|
||||
dma_buf_unmap_attachment(attach, sgt, DMA_BIDIRECTIONAL);
|
||||
fail_detach:
|
||||
dma_buf_detach(dma_buf, attach);
|
||||
dma_buf_put(dma_buf);
|
||||
|
||||
return ERR_PTR(ret);
|
||||
}
|
||||
|
||||
static struct drm_gem_object *rockchip_drm_gem_prime_import(struct drm_device *dev,
|
||||
struct dma_buf *dma_buf)
|
||||
{
|
||||
return rockchip_drm_gem_prime_import_dev(dev, dma_buf, dev->dev);
|
||||
}
|
||||
|
||||
static struct dma_buf *rockchip_drm_gem_prime_export(struct drm_gem_object *obj,
|
||||
int flags)
|
||||
{
|
||||
@@ -589,7 +651,7 @@ static struct drm_driver rockchip_drm_driver = {
|
||||
.dumb_create = rockchip_gem_dumb_create,
|
||||
.prime_handle_to_fd = drm_gem_prime_handle_to_fd,
|
||||
.prime_fd_to_handle = drm_gem_prime_fd_to_handle,
|
||||
.gem_prime_import = drm_gem_prime_import,
|
||||
.gem_prime_import = rockchip_drm_gem_prime_import,
|
||||
.gem_prime_export = rockchip_drm_gem_prime_export,
|
||||
.gem_prime_get_sg_table = rockchip_gem_prime_get_sg_table,
|
||||
.gem_prime_import_sg_table = rockchip_gem_prime_import_sg_table,
|
||||
|
||||
Reference in New Issue
Block a user