media: platform: tegra: nvavp: replace nvmap_handle_address_user_id
Krishna Reddy [Thu, 26 Sep 2013 20:23:37 +0000 (13:23 -0700)]
replace nvmap_handle_address_user_id with dmabuf API.

Change-Id: Ie1fc8e9ed50431208bdbf65ca869c0ccccaa9e75
Signed-off-by: Krishna Reddy <vdumpa@nvidia.com>
(cherry picked from commit 77c602909a7634930aa63a594948340095ded660)
Signed-off-by: Ajay Nandakumar <anandakumarm@nvidia.com>

drivers/media/platform/tegra/nvavp/nvavp_dev.c

index 785d908..2911e8a 100644 (file)
@@ -1187,8 +1187,8 @@ static int nvavp_pushbuffer_submit_ioctl(struct file *filp, unsigned int cmd,
        struct nvavp_pushbuffer_submit_hdr hdr;
        u32 *cmdbuf_data;
        struct dma_buf *cmdbuf_dmabuf;
-       struct dma_buf_attachment *dmabuf_attach;
-       struct sg_table *sgt;
+       struct dma_buf_attachment *cmdbuf_attach;
+       struct sg_table *cmdbuf_sgt;
        int ret = 0, i;
        phys_addr_t phys_addr;
        unsigned long virt_addr;
@@ -1220,20 +1220,20 @@ static int nvavp_pushbuffer_submit_ioctl(struct file *filp, unsigned int cmd,
                return -EPERM;
        }
 
-       dmabuf_attach = dma_buf_attach(cmdbuf_dmabuf, &nvavp->nvhost_dev->dev);
-       if (!dmabuf_attach) {
+       cmdbuf_attach = dma_buf_attach(cmdbuf_dmabuf, &nvavp->nvhost_dev->dev);
+       if (!cmdbuf_attach) {
                dev_err(&nvavp->nvhost_dev->dev, "cannot attach cmdbuf_dmabuf\n");
                ret = -ENOMEM;
                goto err_dmabuf_attach;
        }
 
-       sgt = dma_buf_map_attachment(dmabuf_attach, DMA_BIDIRECTIONAL);
-       if (!sgt) {
+       cmdbuf_sgt = dma_buf_map_attachment(cmdbuf_attach, DMA_BIDIRECTIONAL);
+       if (!cmdbuf_sgt) {
                dev_err(&nvavp->nvhost_dev->dev, "cannot map cmdbuf_dmabuf\n");
                goto err_dmabuf_map;
        }
 
-       phys_addr = sg_dma_address(sgt->sgl);
+       phys_addr = sg_dma_address(cmdbuf_sgt->sgl);
 
        virt_addr = (unsigned long)dma_buf_vmap(cmdbuf_dmabuf);
        if (!virt_addr) {
@@ -1243,8 +1243,10 @@ static int nvavp_pushbuffer_submit_ioctl(struct file *filp, unsigned int cmd,
        }
 
        cmdbuf_data = (u32 *)(virt_addr + hdr.cmdbuf.offset);
-
        for (i = 0; i < hdr.num_relocs; i++) {
+               struct dma_buf *target_dmabuf;
+               struct dma_buf_attachment *target_attach;
+               struct sg_table *target_sgt;
                u32 *reloc_addr, target_phys_addr;
 
                if (clientctx->relocs[i].cmdbuf_mem != hdr.cmdbuf.mem) {
@@ -1257,10 +1259,37 @@ static int nvavp_pushbuffer_submit_ioctl(struct file *filp, unsigned int cmd,
                reloc_addr = cmdbuf_data +
                             (clientctx->relocs[i].cmdbuf_offset >> 2);
 
-               target_phys_addr = nvmap_handle_address_user_id(
-                       clientctx->nvmap, clientctx->relocs[i].target);
+               target_dmabuf = nvmap_dmabuf_export(clientctx->nvmap,
+                               clientctx->relocs[i].target);
+               if (IS_ERR(target_dmabuf)) {
+                       ret = PTR_ERR(target_dmabuf);
+                       goto target_dmabuf_fail;
+               }
+               target_attach = dma_buf_attach(target_dmabuf,
+                                              &nvavp->nvhost_dev->dev);
+               if (IS_ERR(target_attach)) {
+                       ret = PTR_ERR(target_attach);
+                       goto target_attach_fail;
+               }
+               target_sgt = dma_buf_map_attachment(target_attach,
+                                                   DMA_BIDIRECTIONAL);
+               if (IS_ERR(target_sgt)) {
+                       ret = PTR_ERR(target_sgt);
+                       goto target_map_fail;
+               }
+
+               target_phys_addr = sg_dma_address(target_sgt->sgl);
                target_phys_addr += clientctx->relocs[i].target_offset;
                writel(target_phys_addr, reloc_addr);
+               dma_buf_unmap_attachment(target_attach, target_sgt,
+                                        DMA_BIDIRECTIONAL);
+target_map_fail:
+               dma_buf_detach(target_dmabuf, target_attach);
+target_attach_fail:
+               dma_buf_put(target_dmabuf);
+target_dmabuf_fail:
+               if (ret != 0)
+                       goto err_reloc_info;
        }
 
        if (hdr.syncpt) {
@@ -1287,7 +1316,7 @@ err_reloc_info:
 err_dmabuf_vmap:
        dma_buf_vunmap(cmdbuf_dmabuf, (void *)virt_addr);
 err_dmabuf_map:
-       dma_buf_unmap_attachment(dmabuf_attach, sgt, DMA_BIDIRECTIONAL);
+       dma_buf_unmap_attachment(cmdbuf_attach, cmdbuf_sgt, DMA_BIDIRECTIONAL);
 err_dmabuf_attach:
        dma_buf_put(cmdbuf_dmabuf);
        return ret;