drm/exynos: Adding IOMMU mapping to NON-CONTIG gem framework
authorPrathyush K <prathyush.k@samsung.com>
Thu, 10 May 2012 01:33:29 +0000 (18:33 -0700)
committerPrathyush K <prathyush.k@samsung.com>
Tue, 19 Jun 2012 09:44:16 +0000 (15:14 +0530)
The non-contig gem buffers are only used for CPU access currently.
This patch adds IOMMU support for these gem buffers. When a gem buffer
is created with NONCONTIG flag, a SGT is created with the pages
allocated. This patch maps the SGT to create IOMMU mapping by calling
dma_map_sg.

Change-Id: I3df514254c4be714908d13fc9c6a5967e9a07df0
Signed-off-by: Prathyush K <prathyush.k@samsung.com>
drivers/gpu/drm/exynos/exynos_drm_gem.c

index 8991768..5f80ec9 100644 (file)
@@ -206,6 +206,15 @@ static int exynos_drm_gem_get_pages(struct drm_gem_object *obj)
                sgl = sg_next(sgl);
        }
 
+       /* Map the SGT to create a IOMMU mapping for this buffer */
+       ret = dma_map_sg(obj->dev->dev, buf->sgt->sgl, buf->sgt->orig_nents, DMA_BIDIRECTIONAL);
+       if (!ret) {
+               DRM_ERROR("failed to map sg\n");
+               ret = -ENOMEM;
+               goto err1;
+       }
+       buf->dma_addr = buf->sgt->sgl->dma_address;
+
        /* add some codes for UNCACHED type here. TODO */
 
        buf->pages = pages;
@@ -224,6 +233,9 @@ static void exynos_drm_gem_put_pages(struct drm_gem_object *obj)
        struct exynos_drm_gem_obj *exynos_gem_obj = to_exynos_gem_obj(obj);
        struct exynos_drm_gem_buf *buf = exynos_gem_obj->buffer;
 
+       /* Unmap the SGT to remove the IOMMU mapping created for this buffer */
+       dma_unmap_sg(obj->dev->dev, buf->sgt->sgl, buf->sgt->orig_nents, DMA_BIDIRECTIONAL);
+
        /*
         * if buffer typs is EXYNOS_BO_NONCONTIG then release all pages
         * allocated at gem fault handler.